How to add impostor or physics to all submesh of an imported mesh?

Hi all,

I have a room object, which I want to assign impostor and physical functions to all submeshes contained in my object. Is there a more effective way than declaring importers one by one? thank you

There is sadly no simpler way to add impostors apart from defining them one by one.

Having said that - if you can filter your meshes (for example using their id/name) and use this name to create the right impostor, you can use it to create impostors of specific kind (something like

[all,box, meshes,as,array].forEach(m => {
  m.physicsImpostor = new PhysicsIMpostor(m, PhysicsImpostor.BoxImpostor, { mass: anyValueThat MakesSense });
});

But the mass (and friction, and restitution) value will be the same for all.

The .babylon file has the ability to store physics impostor information, but if I see correctly you are using gltf, right?

2 Likes

Thank you for the reply…

Yes, I’m using glb, should I convert the model into babylon file?

no, not at all. I am just saying that in case you are using .babylon, you can configure it in the file itself.

Hi. What benefits with physics you can get in interior? Maybe just use checkCollisions without any physics engine?

Thank you

I want to use impostor to provide more interaction between the user and the 3D object. So, the user cannot walk through the room.

Maybe collisions are a better candidate then:
https://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity

3 Likes

My understanding is that impostors simplify the geometery of a mesh into a simple shape (cylinder, cube) to reduce the cost of collision detection. If collisions are simple between meshes (without a physics engine), why do we need impostors?

1 Like

Wow, thank you so much

Yes, I would like to try using collision. Thank you for the reply

If @Deltakosh gives you an initial approach, you take it :smiley:

My post was more a question as to when physics impostors are appropriate, since collisions are baked into all meshes.

1 Like