scene.beginAnimation() problem on gltf file

iam trying to bring a character with a skeleton animation into my scene. the character has two simple animation in one action, one from frame 1-24, the other from frame 25-61. After checking the examples scene.beginAnimation() is what iam looking for but no animation starts.

i tested my code with the .babylon file from this example:
https://www.babylonjs-playground.com/#BCU1XR#0

and it works… but i cant figure out why? is there an issue regarding frameranges an gltf file?
thats my code:

class SkeletonObject extends BABYLON.Mesh{
constructor(name, scene){
super()
this.name = name
this.scene = scene
this.checkCollisions = true
this.ellipsoid = new BABYLON.Vector3(0.5,0.5,0.5)
this.mesh
this.importobject
this.skeleton

    BABYLON.SceneLoader.ImportMesh("", "assets/", "Dummy.glb", this.scene, (meshes, particlesystems, skeletons)=>{
        this.skeleton = skeletons[0]
        this.importobject = this.scene.getNodeByName("__root__")
        this.importobject.name = this.name + "_root"
        this.mesh = meshes[1]
        this.init()
    })
}
init(){
    this.importobject.parent = this
    // this.scene.beginAnimation(this.skeleton, 25, 59, true, 1.0) //idle animaton 
    this.scene.beginAnimation(this.skeleton, 1, 24, true, 1.0) //walk animaton 
}
update(dt){
    this.rotation.y+= (Math.PI/ 5.3) *dt
}

}

and here is my gltf file
Dummy.zip (333.5 KB)

Hey! glTF relies on AnimationGroup actually:)

Doc: Group Animations - Babylon.js Documentation
Example with gltf: Babylon.js Playground

The relevant code should be:

scene.animationGroups[0].play(true)

You can also call scene.debugLayer.show() to see the inspector and get a cleaner view of your scene:

thanks for the fast answer

i just wonder what happens when i have a object multible times in my scene and call the play() on the animation group? is every every oject starts playing the same animation?

It is entirely dependent on your animation. Animation group will animate one or several objects. It is up to the model creator

If you have multiple times the same model because you duplicated it (like in my example) then they will all have independent animation groups

i see, is there a whay to get the UID when a model gets loadet/dublicated an the new group gets created?

yep scene.onNewMeshAddedObservable maybe?

could you maybe give me a little example? i tried to implement it last night but didn’t really make it.

Please create a repro in the PG of what you have and I can fix it easily :wink:

ok, while prepering an PG example i found a solution for what i was looking for. I simply have to take care of the naming doing the mesh import so that I don’t have the same name multiple time later.
playground example

1 Like