LoadMD2 ( file$[,parent] )
Parameters
|
file$ - .md2 file to load parent (optional) - entity to parent the model to; 0 (default) for none |
Description
|
Loads a Quake II .md2 model and returns its entity handle, or 0 if the file could not be loaded. MD2 is a morph-animated format: instead of a skeleton it stores a complete copy of the mesh for each frame and blends between them. That makes it wonderfully cheap and simple - a whole character in one small file - and it is still a fine choice for crowds, low-detail enemies and retro-styled games. The trade-off is that it has no bones, so the skeletal commands do not apply. CountBones, GetBone, FindBone and AttachToBone have nothing to work with, and neither do Animate, PlayAnim or CrossFadeAnim. MD2 models use their own small family instead: AnimateMD2, MD2AnimTime, MD2AnimLength and MD2Animating. Going the other way, LoadAnimMesh does not read .md2 files - use .b3d, .gltf or .glb if you want a skeleton, named clips and bone attachments. Textures are not applied automatically. Load the skin yourself with LoadTexture and put it on with EntityTexture, or the model will appear untextured. The optional parent makes the model a child of another entity, so moving the parent moves the model; the relationship is one way, and the model still starts at 0,0,0 in the parent local space rather than at the parent position. See also: AnimateMD2, MD2AnimTime, MD2AnimLength, MD2Animating, LoadAnimMesh, EntityTexture. |
Example
; LoadMD2 Example ; --------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() RotateEntity light,45,45,0 ; Load the md2 model gargoyle=LoadMD2("media/Gargoyle/Gargoyle.md2") ; An md2's texture must be loaded and applied separately garg_tex=LoadTexture("media/Gargoyle/Gargoyle.bmp") EntityTexture gargoyle,garg_tex ; Face the gargoyle towards the camera PositionEntity gargoyle,0,-45,100 RotateEntity gargoyle,0,180,0 ; Md2s use their own animation commands - play the whole frame range AnimateMD2 gargoyle,1,0.1 While Not KeyDown(1) UpdateWorld ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,1 If KeyDown(208) Then MoveEntity camera,0,0,-1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrows: camera Esc: exit" Text 0,20,"LoadMD2 loaded a morph-animated model with "+MD2AnimLength(gargoyle)+" frames" Flip Wend End
Index