Is it possible to update the vertices of a MeshCollider.mesh via script and have the new mesh available to physX for collisions? I’ve been trying but it doesn’t seem to work…
Certainly. Here’s a script I put together to change the mesh collider’s mesh to the current render mesh. You could easily adapt this to use the MeshFilter of another object.
var meshCollider : MeshCollider = GetComponent(MeshCollider);
var meshFilter : MeshFilter = GetComponent(MeshFilter);
meshCollider.sharedMesh = meshFilter.mesh;
That’s pretty much the script I’m using too. The problem I’m having is if I move some vertices and then update the mesh. Updating vertices works fine for a MeshFilter, but if I try and apply that mesh to a MeshCollider the collisions, etc are not updated to the modified mesh. I was wondering if in iPhone physX determines MeshColliders at the start of a scene and then doesn’t update them (to get some extra speed)? Maybe there’s a way to force physX to recalculate?
Colliders are built at load time (potentially even resource build time, I don’t know)
You would lose dozens of ms for each rebuild.
…but is there a way to force a rebuild?
i think you want something like:
mesh.RecalculateBounds();
check out this thread, might help.
http://forum.unity3d.com/viewtopic.php?t=2177&start=15&postdays=0&postorder=asc&highlight=