|
entity - an animated model, such as one from LoadAnimMesh asset - a ready animation set asset, from FindWorldAsset |
|
Gives an existing animated model an animation set's clip names, settings and events. Use it when the model comes from somewhere else - LoadAnimMesh, a world file, a copy - and you want to play its clips by the set's names with PlayAnimationSet. The set's clips and root-motion bone are matched to the model by name, so the model must have each of them exactly once. Nothing is re-targeted from one skeleton to another. It replaces the model's clip events and root-motion settings in one go, and clears any events still waiting to be read. It does not start, stop or move playback: whatever is playing carries on from where it is. Returns True, or False with the reason in AnimationSetError(); a failure leaves the model as it was. For the full story - clip modes, speeds, events and root motion - see the Animation sets guide and its complete AnimationSets.bb sample. See also: CreateAnimationSet, PlayAnimationSet, AnimationSetError, 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