Blitz3D+ Command Reference

AnimateMD2 md2[,mode][,speed#][,first_frame][,last_frame][,transition#]

Parameters

md2 - md2 entity handle
mode (optional) - playback mode; 1 (default):
0: stop
1: loop
2: ping-pong
3: one-shot

speed# (optional) - frames advanced per UpdateWorld; 1 (default)
first_frame (optional) - first frame of the range to play; 0 (default)
last_frame (optional) - last frame of the range to play; 9999 (default), which means to the end
transition# (optional) - time spent easing from the current pose into the first frame; 0 (default)

Description

Starts an md2 model animating.

An .md2 file holds all its animations end to end as one long list of frames, so instead of picking a sequence number you pick a frame range. Frames 0 to 39 might be the idle, 40 to 45 the run, and so on; the ranges are a convention of the model, and whoever made it should be able to tell you where each move lives. Keep the ranges in constants and the calls stay readable.

Like Animate, this is a one-off command rather than something to call every frame. The model then advances each time you call UpdateWorld, at speed# frames per update scaled by the elapsed value you pass. A negative speed plays the range backwards, and mode 0 stops the animation.

transition# smooths the jump between the last frame shown and the first frame of the new range, which matters more with md2 than with skeletal models because a straight cut between two unrelated poses is very visible. A small positive value is usually enough.

The default last_frame of 9999 simply means "past the end", so leaving it out plays from first_frame to the last frame in the file.

See also: LoadMD2, MD2Animating, MD2AnimTime, MD2AnimLength, UpdateWorld.

Example

; AnimateMD2 Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()

light=CreateLight()
RotateEntity light,45,45,0

; Load the md2 model and apply its texture
gargoyle=LoadMD2("media/Gargoyle/Gargoyle.md2")
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

; AnimateMD2 mode,speed,first_frame,last_frame - start with a loop of the
; wing-flap frames; the md2 advances each time UpdateWorld is called
AnimateMD2 gargoyle,1,0.1,32,46
info$="AnimateMD2 gargoyle,1,0.1,32,46 (loop)"

While Not KeyDown(1)

    ; Each key restarts the animation with different parameters
    If KeyHit(2) Then AnimateMD2 gargoyle,1,0.1,32,46 : info$="AnimateMD2 gargoyle,1,0.1,32,46 (loop)"
    If KeyHit(3) Then AnimateMD2 gargoyle,2,0.1,32,46 : info$="AnimateMD2 gargoyle,2,0.1,32,46 (ping-pong)"
    If KeyHit(4) Then AnimateMD2 gargoyle,3,0.1,1,48 : info$="AnimateMD2 gargoyle,3,0.1,1,48 (one-shot, all frames)"
    If KeyHit(57) Then AnimateMD2 gargoyle,0 : info$="AnimateMD2 gargoyle,0 (stopped)"

    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,"1: loop flap   2: ping-pong flap   3: one-shot all   Space: stop   Esc: exit"
    Text 0,20,info$
    Text 0,40,"MD2AnimTime: "+MD2AnimTime(gargoyle)

    Flip

Wend

End

Index