One mesh in the model is missing when using thin instance

Hi babylon team,

It is me again on the baked instanced model topic. I am doing another iteration of performance optimization on my scene. This time I want to convert my animated instances to thin instance. The whole conversion process was surprisingly smooth. The model animation worked fine, and I gained about 200 Absolute FPS boot after using thin instance. I was very happy until… I noticed the hand of my testing model is empty. The weapon is missing. :frowning:

I am able to reproduce the issue in the following PG. It is a very basic setup that doesn’t have animation baking or custom material, no animation involved. But the weapon is missing already. No error in the console. The weapon exists in standard loading / regular instancing. Only missing when I change to thin instance. It is a large model that can take quite some time to load.

https://www.babylonjs-playground.com/#7DS5D4#50

Could you help to check why only the mace is missing? The other 6 meshes loads fine. I would expect the weapon is on the left side of the troll model in the static pose. The model used in the PG is from: GitHub - slin-debug/babylon-thin-instance-asset. Original model from: Troll - Download Free 3D model by SJunior3d (@sjunior3d) [bceb1cb] - Sketchfab

The mace has a very big parent hierarchy with animations + rotations on all nodes. If you stop the animations + set the rotation to (0,0,0) on all nodes, remove the skeleton and set the scale to 1 you will see the mace is near the mesh and at the same location for each mesh (of course, it is not in the hand anymore!):
https://www.babylonjs-playground.com/#7DS5D4#51

So it’s a problem with the hierarchy: I think you should simplify the node hierarchy of the model because it is very complicated:

3 Likes

Hi @Evgeni_Popov,

Thanks for looking into this. Actually, if the scaling is set to 1.0, the mace is placed correctly in the hand. See https://www.babylonjs-playground.com/#7DS5D4#54.

Now I see how it is different compared to regular instancing. When I used regular instancing, I created instances for each mesh, and then attach mesh instances to a TransformNode. And finally scaling is applied to the TransformNode.

It is not if you set a translation on the model:
https://www.babylonjs-playground.com/#7DS5D4#60

A simple question, why is it scaled in the first place? scaling + rotation + parenting + transform nodes or pivot when instanciating an object group or prefab, doesn’t sound like a good idea to me. Just saying.

Hi @mawa,

A simple question, why is it scaled in the first place? scaling + rotation + parenting + transform nodes or pivot when instanciating an object group or prefab, doesn’t sound like a good idea to me.

Definitely not a good idea. But is there a way to group thin instances and apply scaling/rotation/transform on the group? I tried to merge mesh but I got an error indicating the meshes have different attributes. I am not able to build/modify 3D models myself. :frowning:

I gave up using the original mace weapon. Since it is a testing model, I am fine with something else. And actually it is good to have flexibility to use different weapons.

Based on my understanding of @Evgeni_Popov investigation, there is too much hierarchical local matrix applied to the original weapon. If I change the transition or scaling, the original mace is not located correctly in the world.

I used an external mesh as weapon solves the problem. I used an external mesh before by added the world matrix of the mace’s parent joint as an additional row in the baked animation texture. So this part is straightforward.

First, I tried to use a box mesh with stretched height (look like a bar), but the model holds the middle of the bar. Then I tried to use this tube. It allows one edge of the tube to be hold on the hand nicely.

  const myPath = [
    new BABYLON.Vector3(0.0, 0, 0.0),
    new BABYLON.Vector3(0, -200, 0.0),
  ];

  // Create ribbon with updatable parameter set to true for later changes
  let externalWeaponMesh = BABYLON.MeshBuilder.CreateTube(
    "trollbar",
    {
      path: myPath,
      radius: 15,
      sideOrientation: BABYLON.Mesh.DOUBLESIDE,
      updatable: true,
    },
    GlobalContext.scene
  );

Now my trolls carry steel pipes around and look like some really bad ass. :sweat_smile:

2 Likes

LoL. Shouldn’t be a problem. Trolls are known for using anything they find as a weapon :grinning: