About editing the collision mesh at runtime

Post Reply
Nkp
Posts: 7
Joined: Sun Jul 11, 2021 6:51 am

About editing the collision mesh at runtime

Post by Nkp »

I want to edit to a collision mesh at runtime.
By watching the tutorial of ConcavePhysicsDemo,
I learned that I can move the vertices.
But erase or increase the vertices was difficult.
I would like to use the edited mesh as a static collision.

Is there any way?
At first, I thought it would be effective to increase or decrease the mesh with btBvhTriangleMeshShape.
The btBvhTriangleMeshShape can increase or decrease the mesh at run time.
However, I couldn't find a way to increase or decrease the mesh on the already created btBvhTriangleMeshShape and Rigid Body.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: About editing the collision mesh at runtime

Post by drleviathan »

The btBvhTriangleMeshShape has an internal Boundary Volume Hierarchy (hence the "Bvh" in the name) data structure that is used to optimize queries into the triangle soup. If you were to dynamically change the triangles in the soup then you'd have to recompute the BVH which is expensive. As such, the btBvhTriangleMeshShape is not a good shape to use for a dynamic mesh... for real-time simulations.

The btHeightfieldTerrainShape, on the other hand, builds its triangles on the fly as needed, so the heightfield values can be dynamic. The width and height of the heightfield are not dynamic in principle however with care it might be possible to dynamically adjust them... but I can't imagine an inexpensive way to do it.

A btCompoundShape could be used to produce an effectively dynamic concave shape (by moving the convex decomposed parts) however Bullet doesn't support local velocities of sub-shapes and so the collisions against such a dynamic shape would not use the correct velocities in the contacts and the physics would suffer glitches.

Dynamic concave objects can be done in Bullet using constraints, soft bodies, or multi-body.

What do you really want to do? That is, rather than asking about a particular solution (dynamic mesh) maybe you could explain what kind of simulation/game/feature you're trying to achieve.
Nkp
Posts: 7
Joined: Sun Jul 11, 2021 6:51 am

Re: About editing the collision mesh at runtime

Post by Nkp »

Thank you for answer.
Sorry I didn't write it specifically.
I'm making a game.

In the game, there will be a wall that disappears (or appear )when Player press the switch.
The wall appears and disappears, but doesn't transformation or rotation ,scaling.
If it doesn't transform, I wondered if I could use the optimization of BVH of btBvhTriangleMeshShape, so I tried various things.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: About editing the collision mesh at runtime

Post by drleviathan »

If a known wall should be removable then the the most run-time performative thing to do would be to separate the wall from the rest of the mesh in pre-production and load the scene with two mesh instead of one. Then you could easily remove (or move) the wall body and leave the rest in place.

If all walls, or arbitrary parts of a mesh should be deleted on the whim of the player then... you have a different problem and you have to write a much more sophisticated content management system.
Nkp
Posts: 7
Joined: Sun Jul 11, 2021 6:51 am

Re: About editing the collision mesh at runtime

Post by Nkp »

By looking at the SDK and asking questions here, I found it difficult to show or hide parts of the btBvhTriangleMeshShape.
I will generate btBvhTriangleMeshShape etc. as many as the number of walls that can be erased and turn it on and off.

Thank you for the advice!
Post Reply