Blitz3D+ Command Reference

CountAnimSeqs ( entity )

Parameters

entity - handle of an animated entity

Description

Returns how many animation sequences an entity has.

When you load a character with LoadAnimMesh you get every clip the artist put in the file. Each clip has a sequence number from 0 up to CountAnimSeqs-1, and that number is what Animate, SetAnimTime and AnimSeq talk in. This command is how you find out how many there are without hard-coding a magic number that breaks the day the artist adds a "Die" animation.

It is the natural loop bound for anything that walks the whole list - an animation picker in your level editor, a debug overlay that prints every clip name, or a random idle chooser. Pair it with AnimSeqName to turn the numbers into readable names.

An entity with no animation at all returns 0 rather than raising an error, so this doubles as a cheap "is this model animated?" test before you start asking for clips. Note the count can grow while your game runs: LoadAnimSeq appends clips from another file, and AddAnimSeq and ExtractAnimSeq each add one more.

The count belongs to the entity you ask, so query the handle LoadAnimMesh gave you rather than one of its child bones or meshes - those have no animator of their own and report 0. Copies made with CopyEntity get their own playback state but share the same clip list, so they report the same count.

See also: AnimSeqName, FindAnimSeq, AnimSeq, Animate, AddAnimSeq, LoadAnimMesh.

Example

; CountAnimSeqs Example
; ---------------------

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

camera=CreateCamera()
PositionEntity camera,0,2,-6
RotateEntity camera,12,0,0

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

; A grassy paddock for the fox to roam
ground=CreatePlane()
EntityTexture ground,LoadTexture("media/MossyGround.BMP")

; The bundled fox arrives with three named clips baked into the file
fox=LoadAnimMesh("../../../samples/glTF/assets/Fox/Fox.glb")
If fox=0 Then RuntimeError "Could not load Fox.glb: "+ModelLoadError()

; Shrink the fox to game scale (the file is modelled about 100 units tall)
FitMesh fox,-0.8,0,-0.8,1.6,1.6,1.6,True

; Ask the model how many clips it brought with it - never hard-code this
total=CountAnimSeqs(fox)

seq=0
Animate fox,1,0.6,seq

While Not KeyDown(1)

    ; [ / ] step through every sequence the model reported
    If KeyHit(26)
        seq=seq-1
        If seq<0 Then seq=total-1
        Animate fox,1,0.6,seq
    EndIf
    If KeyHit(27)
        seq=seq+1
        If seq>total-1 Then seq=0
        Animate fox,1,0.6,seq
    EndIf

    UpdateWorld

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,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,"[ / ] : previous / next clip   Arrows: camera   Esc: exit"
    Text 0,20,"CountAnimSeqs(fox) = "+total+"   now playing sequence "+seq

    ; Every clip the file provided, listed by number and name
    For i=0 To total-1
        Text 0,60+i*20,"  sequence "+i+": "+AnimSeqName$(fox,i)
    Next

    Flip

Wend

End

Index