|
asset - a ready animation set asset, from FindWorldAsset parent (optional) - parent entity for the new model; 0 for none (default) |
|
Creates an animated model from an animation set, ready to play its clips by name. An animation set (.animset file) gives a model's clips your game's names - "walk", "run", "jump" - and saves how each one plays: loop, ping-pong or once, its speed, its cross-fade time and its events, such as a footstep at the moment a foot lands. It also says how root motion is handled. Load the set with LoadResourceDocument and LoadResourceDocumentAsync, wait for WorldReady, and pass FindWorldAsset(world,"resource"). Each call creates a new copy of the model with that set-up, so a whole crowd can share one set. The model starts still: play a clip by name with PlayAnimationSet. It goes into the selected world, or the parent's world, keeps working after you free the world that loaded the set, and is freed with FreeEntity. Returns 0 when the asset is not a ready animation set, and AnimationSetError() says why. A world file can also place animation sets as models, and the World Editor's Animation Set tab edits them. For the full story - clip modes, speeds, events and root motion - see the Animation sets guide and its complete AnimationSets.bb sample. See also: PlayAnimationSet, ApplyAnimationSet, AnimationSetError, FindWorldAsset, LoadAnimMesh. |
; CreateAnimationSet Example
; --------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,2,-7
light=CreateLight()
RotateEntity light,45,45,0
; The robot's animation set: clip names, speeds, blends and step events
document=LoadResourceDocument("../../../samples/animation-sets/robot.animset")
If document=0 Then RuntimeError ResourceDocumentError()
library=LoadResourceDocumentAsync(document)
FreeResourceDocument document
While Not WorldReady(library)
If WorldLoadState(library)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(library)
UpdateAsyncLoads 2
Wend
asset=FindWorldAsset(library,"resource")
; A robot made from the set, ready to play its clips by name
robot=CreateAnimationSet(asset)
If robot=0 Then RuntimeError AnimationSetError()
PositionEntity robot,-1.5,0,0
; An ordinary animated model, given the same settings
twin=LoadAnimMesh("../../../samples/animation-sets/robot.gltf")
If Not ApplyAnimationSet(twin,asset) Then RuntimeError AnimationSetError()
PositionEntity twin,1.5,0,0
; Both robots keep their settings when the loader world goes
FreeWorld library
PlayAnimationSet robot,"walk"
PlayAnimationSet twin,"walk"
report$="PlayAnimationSet robot,"+Chr(34)+"walk"+Chr(34)+" returned True"
problem$=""
step_event$=""
While Not KeyDown(1)
; 1 / 2 cross-fade both robots, 3 asks for a clip the set lacks
clip$=""
If KeyHit(2) Then clip="walk"
If KeyHit(3) Then clip="run"
If KeyHit(4) Then clip="fly"
If clip<>"" Then
If PlayAnimationSet(robot,clip) Then
PlayAnimationSet twin,clip
report="PlayAnimationSet robot,"+Chr(34)+clip+Chr(34)+" returned True"
problem=""
Else
report="PlayAnimationSet robot,"+Chr(34)+clip+Chr(34)+" returned False"
problem=AnimationSetError()
EndIf
EndIf
; The set's step events arrive like any animation event
While PendingAnimEvents(robot)>0
step_event=PollAnimEvent(robot)
Wend
; 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
UpdateWorld
RenderWorld
Text 0,0,"Arrow keys: move camera 1 / 2: walk / run 3: unknown clip Esc: exit"
Text 0,20,"Left: CreateAnimationSet Right: LoadAnimMesh + ApplyAnimationSet"
Text 0,40,report
Text 0,60,problem
Text 0,80,"Latest step event: "+step_event
Flip
Wend
End