Page MenuHome

BGE: Create Individual per Instance physics meshes by replaceMesh()
AbandonedPublic

Authored by Martin Felke (scorpion81) on Feb 27 2015, 7:47 PM.

Details

Summary

This patch allows to replace the physics Mesh on individual instances when replacing its mesh with physics option set to True.
Works with Convex Hulls and Triangle Meshes, other mesh shapes are equal all the time (like Box, Sphere and so on) and dont need to be replaced.
This new behavior is optional, though enabled by default. You can revert to old behavior by checking "Share Physics Mesh" under the BGE Physics settings for Rigidbody.

Here is also a small test file for this, just run BGE and press space multiple times.

Diff Detail

Event Timeline

Martin Felke (scorpion81) retitled this revision from to BGE: Create Individual per Instance physics meshes by replaceMesh().
Martin Felke (scorpion81) updated this object.

crash fix for shared triangle meshes, was using NULL as mesh by accident there

Why only for dynamic and rigid body and no with static ?

added the "Share Physics Mesh" option to static (note: when it is disabled, invidual meshes are used) and disabled new behavior for character, this caused a bullet crash.

Hello, why we can't call SetMesh with a RAS_MeshObject without DerivedMesh ? I think it can cause porblems if the mesh is deformed without deformer (RAS_Deformer) like from python.
What's the real difference between SetMesh and UpdateMesh ?

Using UpdateMesh() for changing triangle mesh shapes now, even in unshared case (instead of SetMesh()), because of possible ignoring the RAS_MeshDeformer. Thanks to @Porteries Tristan (panzergame) for pointing this out.
Also fixed a crash with bvhTriangleMesh (happened even before replaceMesh()), there the new unshared case was not treated correctly.

The problem that I have with this patch is that it is working around a deeper issue, and that is mis-management of shared physics meshes. If we replace the physics mesh of an object, we should decrement the users of the old mesh and increment the users of the new mesh, not create a whole new mesh. Now, on top of this, we may still need a way to force the creation of a duplicate physics mesh.

Porteries Tristan (panzergame) requested changes to this revision.Apr 22 2015, 11:06 AM
Porteries Tristan (panzergame) edited edge metadata.

It seems that the CcdShapeConstructionInfo is used in the function GetHitTriangle to find the polygon and the correct UV. So if we use only one CcdShapeConstructionInfo the raycast is broke.

This revision now requires changes to proceed.Apr 22 2015, 11:06 AM

I'm closing this diff as the BGE is no longer developed.