javascriptanimationbabylonjs

BabylonJS Dynamically generated Animation not playing


I’m developing a custom AnimationSequencer Class that, once provided with a group of keyframes, is able to dynamically generate an Animation instance for each keyframe group, append these animations to an an AnimationGroup and finally play the animation group on a call to the “playAll()” method. Here is the playground: https://playground.babylonjs.com/#7QN6ZM#54 On running the application, if you navigate the the developer tools, console window you will note the following error trace; its seems there is an issue with passing the Babylon scene to a JS class and then attempting to play animation from within the context of a JS class. Console Error StackTrace

Curiously, as noted in the playground, everything works as expected when I attempt the process directly, (i.e non-dynamically and without use of the custom AnimationSequencer class) from a first class function.


Solution

  • I've found the source of the error. It was an oversight on my part; where an animation has been declared to update the position attribute then the data type must be also specified as a Vector3:

     let meshPositionAnim = new BABYLON.Animation(
        meshAnimSequence.objectId+"MeshPositionAnimation",
        "position",
        this.defaultFPS,
        BABYLON.Animation.ANIMATIONTYPE_VECTOR3,   //Must be ANIMATIONTYPE_VECTOR3
        BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT,
        true
        );
    

    I had been erroneously using BABYLON.Animation.ANIMATIONTYPE_FLOAT before now as I had been animating each axis independently prior, using position.x,position.y and position.z respectively (which are float values), rather than just position.