Blitz3D+ Command Reference

MD2AnimLength ( md2 )

Parameters

md2 - md2 entity handle

Description

Returns the total number of animation frames in an md2 file.

An .md2 stores every move it has as one continuous run of frames, so this is the length of the whole file, not of the range you are currently playing. It is what you need when you want to play everything a model has - AnimateMD2 md2,1,1,0,MD2AnimLength(md2)-1 runs the lot - and it is a quick sanity check when a model does not animate as expected: a frame range that runs past this number is not going to work.

It is also useful when stepping through an unfamiliar model frame by frame to find out where each move starts and ends.

See also: MD2AnimTime, MD2Animating, AnimateMD2, LoadMD2.

Example

; MD2AnimLength 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

; Play every frame the file contains, using the length as the last frame
AnimateMD2 gargoyle,1,0.1,1,MD2AnimLength(gargoyle)

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"
    ; The total number of animation frames stored in the md2 file
    Text 0,20,"MD2AnimLength(gargoyle) = "+MD2AnimLength(gargoyle)+" frames"
    Text 0,40,"MD2AnimTime: "+MD2AnimTime(gargoyle)

    Flip

Wend

End

Index