Backedvertex and glb

Hi,

The PG:
https://playground.babylonjs.com/#CP2RN9#81

Ok, I decided to test the backedvertex feature and pointed the mesh to one of your public models to see how it behaves.
The model is a GLB.

Just open the console, you will see that the object has a skeleton :the gltf loader sees the skeleton just fine.

The issue is that “Meshes” doesn’t point to an animation and replacing mesh with skeletons won’t help either.

How can I get through this?

Thanks

That one seems to work, so that’s a typo because the method search for “skeleton” whereas the glb has “skeletons” set.
Defining skeleton will enable the method to proceed.

So, at https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/BakedVertexAnimation/vertexAnimationBaker.ts#L34 the check should be

if (!this._mesh.skeleton) {

      if (!this._mesh.skeletons) {
            throw new Error("No skeleton in this mesh.");
      }
      else{
            throw new Error("Please select one of the skeletons of your mesh, and assign it to the skeleton key");
      }
}

It is possible to add a control for length 1 and assign it directly but…

if (!this._mesh.skeleton) {

      if (!this._mesh.skeletons) {
            throw new Error("No skeleton in this mesh.");
      }
      else{

           if (this._mesh.skeletons.length == 1){
                 this._mesh.skeleton = this._mesh.skeletons[0];
           }
           else{
                 throw new Error("Please select one of the skeletons of your mesh, and assign it to the skeleton key");
          }
     }
}

I may have missed something in the proper process though…

Final working PG
https://playground.babylonjs.com/#CP2RN9#84

the method https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/BakedVertexAnimation/vertexAnimationBaker.ts#L70 is not await friendly though

1 Like

Note that importResult is not a mesh, loaded meshes are in importResult.meshes instead (note that it is an array as multiple meshes may have been loaded).

But for some reasons, it didn’t work otherwise, with error “Error: No skeleton in this mesh.”
And locally, The code will never resolve here
https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/BakedVertexAnimation/vertexAnimationBaker.ts#L74

This code:

    for (let i = 0; i < importResult.meshes.length; ++i) {
        const mesh = importResult.meshes[i];
        console.log(i, mesh.name, mesh.skeleton);
    }

is producing:

The first mesh in importResult.meshes is a root mesh and has no skeleton, you should not use it for baking purpose. Use the other meshes instead.

I’ve been running for hours in a wall, and a mere

      if (!mesh.skeleton) {
        continue
      }

did the trick…
Sorry for the bump, time to sleep.

Thanks Evgeni !

Is it expected to have the exact same CPU usage between baked and non baked animation?
I was hoping to see it decrease, but not at all:

        let importResult = await SceneLoader.ImportMeshAsync("", "/", my_obj, scene, undefined);

        for (let x = 0; x < importResult.meshes.length; ++ x ) {

            const mesh = importResult.meshes[x];

            if (! mesh.skeleton) {
                continue;
            }
            let response = await fetch("/BV_" + (x) + ".json");

            if (! response.ok) {
                throw new Error("HTTP error " + response.status);
            }

            const json = await response.json()
            const baker = new VertexAnimationBaker(scene, mesh);
            
            // vertex related
            const vertexData = json["vertexData"]
            const vertexTexture = baker.textureFromBakedVertexData(vertexData);
             
            //Bake management
            const manager = new BakedVertexAnimationManager(scene);
            // store the texture
            manager.texture = vertexTexture;

            // set the animation parameters.
            manager.setAnimationParameters(
                     1, // first frame
                    10, // last frame
                    0, // offset
                    30 // frames per second
            );

            // associate the manager with the mesh
            mesh.bakedVertexAnimationManager = manager;

            // update the time to play the animation
            globalThis.scene.registerBeforeRender(() => {
                manager.time += engine.getDeltaTime() / 1000.0;
            });

        }

    };

With or without the part after ImportMeshAsync, the animation runs the same.
CPU usage is the same.

Is that expected?

Are you using baked animation for a single mesh?

You will probably need to display hundreds (or more) of mesh instances to be able to see a difference.

1 Like

hmmmm, I tried to see if it worked properly.

Then for my needs, I will keep using instances / thin instances and consider it done. The maximum is about 20-30 animated characters / objects simultaneously on screen.

Thanks Evgeni, :+1: