Havok disablePreStep issue with instances

Hey everyone!

I am fiddling around with instances and havok and I found a weird behavior when using disablePreStep:

The meshes are attached to their parents but the physics body does not cooperate xD

The doc says “It is also not supported to have transformations at the mesh level, i.e, the instanced mesh’s position, rotation and scale values have to be the default.” (https://doc.babylonjs.com/features/featuresDeepDive/physics/rigidBodies)

Are those 2 related?

To rephrase that: a mesh that is used for instances and that will be physicalized must be set at origin.

This is to simplify transformation and increase performance. Otherwise, each body would need an extra transformation that can be costly because done on CPU.

Do you have a use case in mind?

Ah that explains it!

My use cases are asteroid fields in Cosmos Journeyer:

My idea was thin instancing for rendering performance, and then havok instances for physics collisions with the spaceship for example.

To save performance and stabilize the physics simulation, the field does not move in world space. But it is very large so I need to shift the origin from time to time (and then the world position of the field changes).

A solution could be to rewrite the instance buffer every time I shift the origin? But then I need to send them back to the GPU, which is laggy.

Could we have some kind of mechanism to inject parent matrices in havok instances?

1 Like

You can use individual physics body or multiply each instance world matrix by inverse parent…with a huge performance impact.
Did you try to not physicalize everything but proceed by chunks/quadtree?

Looks like instances was not the way to go in the end. The quadtree approach sounds promising, I will see what I can get out of it! Thanks for the insights :wink:

1 Like