How to import a gltf without its animation

I have a glTF with an animation called bindpose_offset which has two frames and frame 1 is what need when adding the file. When I use LoadAssetContainerAsync and addToScene() to load the glTF into the Editor scene (or even drag the file into the scene), the animation played automatically which was not I wanted.
I am now using the following code snippet to stop the frame at 1 and it works well when I add the file but after save/reload, the model frame reset to 0 which make the model looks weird.

    const characterAsset = await SceneLoader.LoadAssetContainerAsync(
      this.characterConfig.modelUrl,
      '',
      scene
    );
const bindPoseOffset = characterAsset.animationGroups[0];
    if (bindPoseOffset) {
      bindPoseOffset.goToFrame(1);
      bindPoseOffset.stop();
    }
    characterAsset.addAllToScene();

Can I import the asset without its animation? Is there any way to solve my issue? Thank you.

You can always stop animations after load, but i bet @bghgary has a better answer :blush:

There isn’t an easy way to prevent the loading of animations right now. We could add an option for it or you can add a custom glTF loader extension to block it from loading.

You can also tell the loader to not start any animations by setting the animationStartMode. See here for how to set options.

Hey @bghgary Thank you for the reply. I am now using SceneLoader rather than GLTFFileLoader. I didn’t find the similar method in the SceneLoader. Do you suggest me to use GLTFFileLoader here?

1 Like

GLTFFileLoader is not really meant to be used directly. You should almost always use SceneLoader. What method are you not finding?

animationStartMode. I think this is what we can use to control the animation when loading the assets. However, I didn’t find this one in the SceneLoader class. Did I miss something?

BABYLON.SceneLoader.OnPluginActivatedObservable.add(function (loader) {
    if (loader.name === "gltf") {
        loader.animationStartMode = BABYLON.GLTFLoaderAnimationStartMode.NONE;
    }
});

We are using babylonjs v4 ES6 module in the BabylonJS Editor. The above code cannot recognize the animationStaticMode. Is this only working well with BabylonJS V5?

Property 'animationStartMode' does not exist on type 'ISceneLoaderPlugin | ISceneLoaderPluginAsync'.
  Property 'animationStartMode' does not exist on type 'ISceneLoaderPlugin'.

If you are using TypeScript, you have to cast the plugin into a IGLTFFileLoader and then you will be able to set the options. I know this is clunky, but that’s all we have at the moment. cc @RaananW

ok. This solution works well to stop the animation but the frame is not what I want. If I use goToFrame(1) , I think it can stop at frame 1 but after reloading the Editor, the animation will be reset to the wrong frame. Do you have any clue about it?

What does this mean?

I am using BabylonJS Editor to programmatically import my gltf asset into the scene.

Maybe @julien-moreau can answer this.

1 Like

Cc @julien-moreau