I added debug for imposters here. Just the floor and wall https://playground.babylonjs.com/#S7E00P#138 .
I am looking into the same topic. Right now I create glb model with additional boxes/spheres invisible meshes just for physics imposters. I optimised my model mesh to low poly that its getting close face count to the imposter mesh so wondering whats the point. Especially that sphere imposters around the corners need to be detailed enough for the collisions to work properly. Now I am thinking just to optimize my mesh so its more dense around the corners and just use it as an imposter without extra shapes. I am not sure if there is any extra penalty when you use mesh imposter vs ie. sphere with the same amount of faces.
Has there been any performance testing on this subject with low poly models? If you put a mesh impostor for a simple box mesh, is it the same as putting a box impostor in the same box mesh? Just as @kri100s said here:
Also kind of curious if the mesh impostor simplifies the impostor mesh or is it the same as the actual mesh? For some reason the mesh impostors don’t show up in the debug view in the playground, as seen in the example that kri100s made: https://playground.babylonjs.com/#S7E00P#138
no, a box collision detection is faster and uses less memory. It’s basically just a matrix. As a mesh impostor, even with a few triangles is a matrix, all the geometry and spatial partioning datas.
Is it the same case for spheres? Boxes arent good enough for fast moving objects so I use sphere as you can make them more dense.
If this is a case, is there a solution to give a box/sphere/cylinder impostor easily for any glb/gltf mesh, if you just want to use it generically? Like just give the
boxImpostor for the root mesh, that it would use the bounding box of the child meshes? Doesn’t work straight out of the box at least… https://playground.babylonjs.com/#S7E00P#139
And there is still the case that why can’t we see mesh impostors in playground?
If you add bounding box information to the root at least something works https://playground.babylonjs.com/#S7E00P#140
I’m pretty sure BabylonJS automatically creates a Convex Hull shape if you have a dynamic, non-zero-mass physics impostor. So barrels and palm trees are in fact Convex Hulls, where as your static ground and wall are both MeshImpostors/TriangleShapes. Static physics bodies usually benefit from using triangles, as smaller shapes are usually quicker to run through the narrowphase.
AmmoJS/Bullet uses GJK as its narrowphase(And EPA in case of inter-penetration), and only needs the three vertices of the triangle as support points. If you used a box instead, you would have to test 8 vertices. Using SAT gets even worse with bigger convex shapes, as with a triangle you have three vertices, three edges and a face to test, but with a box, you now have 8 vertices, 12 edges and 6 faces.
With dynamic physics bodies, the same thing more or less applies, and as you are already using a convex hull, I don’t see any need to manually decompose your meshes into a compound selection of primitives. But if are going that route, spheres are certainly the quickest to test against.
I’m not sure whether Bullet uses bodies or shapes in it’s broadphase, but if it’s the latter, having a single convex hull might prove faster in updating the dynamic AABB tree, than having a lot of smaller shapes.
In other words, I think what you’re doing now is good enough. Only think about changing something in case you actually encounter performance issues.
I’ve managed to create a physics object with box impostors pretty easily using a collider mesh generated in Blender. I’ve created a “collider-cube” and “collider-cylinder” meshes that will be used as reference when creating the impostors. I also hide these from view after importing.
https://playground.babylonjs.com/#S7E00P#161 ← with box colliders
Experiencing a bit, uhm, erratic behaviour with cylinders though… They seem to roll into infinity and beyond… https://playground.babylonjs.com/#S7E00P#164
Anyone got an idea why the cylinder impostors are so… Unstable?
Updated my playground with a gizmo! Now you can push the physics objects
I’ve never seen that before. Cans are really unstable. Sometimes they accelerate for no apparent reason
I tried to tweak gravity/friction/… anything I could without a better result. I have no idea on what’s happening.
Can it have something to do with the NoImpostor?
Right now the there is the parent/child hierarchy of:
__ root __ ← NoImpostor
Cylinder ← CylinderImpostor using the collider-cylinder mesh as a collider (has a parent of __root __ )
collider-cylinder ← the collider that is hidden when loaded (has a parent of __root __ )
@RaananW is it smthg you already experienced ?
Seems to be related to their size. double their size and everything seems much better - Physics yo | Babylon.js Playground (babylonjs.com)
Might be an ammo limitation on impostor sizes
Or maybe turn off the gas!
I stupidly laughed alone in my room
The similar problem can be reproduced with a simple playground and a createcylinder function as well… https://playground.babylonjs.com/#BEFOO#1432
Seems that the cylinder gets a bit speedy and… Wait a minute, does this have something to do with the plane width/height and its subdivisions? https://playground.babylonjs.com/#BEFOO#1434 At least when increased I can see the erratic behavior at once
Still seems to me like it is related to the size. changing the height to 1 makes it much more stable. @Cedric , do you know of this kind of limitation with ammo?
bingo | Babylon.js Playground (babylonjs.com)
Nop, the only limitation I know (which is also the case with other physics engine) is when mixing high values with small ones. Like bodies with very high speed & collision detection.
It makes it more stable yes, but if you look close enough you can see small vibrations in the mesh no matter how big it is Even when the cylinder happens to stand on its top and bottom ends