Physics, GLTFs, Instancing, and Parenting

I have a scene where I’m loading a GLTF object and creating a bunch of instances and then attaching physics impostors to each instance.

This kind of works, but I’m bumping up against a couple of strange behaviors (bugs?) that seem to be fighting against each other.

  1. In order to get instanced rendering to work properly, I have to parent the instances of the glTF mesh to the parent of the mesh (i.e., to the _root node) as described as the second option in the “Instancing a glTF object” on this page (Instances | Babylon.js Documentation). If, instead, I try mesh.setParent(null) before creating the instances, I end up in a situation where instanced rendering doesn’t work. i.e., the sign of the determinant of the instance mesh matrix doesn’t match the sign of the determinant of the original mesh (inside InstancedMesh::_activate), and so each instance is rendered as a “regular” mesh.
  2. Because I have to keep the parent of the mesh (as described in point #1), the PhysicsImpostor system warns me that “A physics impostor has been created for an object which has a parent”. This happens despite the fact that I’ve set “ignoreParent: true” in the PhysicsImpostor options parameter.

Is it a bug that PhysicsImpostor constructor isn’t checking “ignoreParent” before warning about parented object?

Am I doing something wrong to cause the “mesh.setParent(null)” version of glTF instancing to not work properly?

Thanks in advance!

Welcome aboard!

For 1, you can set scene.useRightHandedSystem = true to avoid having a transformation on the first node of the hierarchy (in that case, the transformation will be the identity). Thay way, you can remove the parent of the meshes altogether (first option in the doc you linked). If I understand it well, that should also fix 2 but @Cedric will know more about this one.

1 Like

I think @Evgeni_Popov is right.
ignoreParent is not used for the warning. Can you share a PG? Physics and hierarchy is a complex beast.

Awesome, thanks! That worked. :slight_smile:

Here’s a playground – if you look in the console, you’ll see the warning.