Just wanted to say I managed to get this working by updating the BvhTriangleMeshShape.

I'll post up the source to the project soon if anyone is interested.
Here are some pics of the work so far:
http://goo.gl/fIixl
Cheers,
John
Code: Select all
private void RebuildTerrainPhysicsMesh()
{
// If our ground has not been created yet, or destroyed.
if (GroundBody == null)
{
// Ensure our groundMesh and groundShape are destroyed and properly disposed of.
if (GroundMesh != null)
{
GroundMesh = null;
}
if (GroundShape != null)
{
Physics.CollisionShapes.Remove(GroundShape);
GroundShape.Dispose();
GroundShape = null;
}
// Create the mesh container.
GroundMesh = new IndexedMesh();
int iTotalTriangles = 2 * (iTerrainWidth - 1) * (iTerrainHeight - 1);
GroundMesh.Allocate(this.tTerrainVB.Length, sizeof(float) * 3, iTotalTriangles, sizeof(uint) * 3);
// Write the verts.
BulletSharp.DataStream pData = GroundMesh.LockVerts();
for (int i = 0, n = tTerrainVB.Length; i < n; ++i)
{
pData.Write(tTerrainVB[i].Position.x);
pData.Write(tTerrainVB[i].Position.y + 1.0f);
pData.Write(tTerrainVB[i].Position.z);
}
pData.Close();
// And write the indicies.
IntArray tIndexData = GroundMesh.TriangleIndices;
for (int i = 0, n = tTerrainIB.Length; i < n; ++i)
tIndexData[i] = (int)tTerrainIB[i];
// Setup the shape.
TriangleIndexVertexArray vertexArray = new TriangleIndexVertexArray();
vertexArray.AddIndexedMesh(GroundMesh);
GroundShape = new BvhTriangleMeshShape(vertexArray, true);
// And the rigid body in the world.
Physics.CollisionShapes.Add(GroundShape);
GroundBody = Physics.LocalCreateRigidBody(0, Matrix4.IDENTITY, GroundShape);
GroundBody.UserObject = "Ground";
}
// Otherwise we have a valid shape already, just push the updates and refit it.
else
{
BulletSharp.DataStream pData = GroundMesh.LockVerts();
for (int i = 0, n = tTerrainVB.Length; i < n; ++i)
{
pData.Write(tTerrainVB[i].Position.x);
pData.Write(tTerrainVB[i].Position.y + 1.0f);
pData.Write(tTerrainVB[i].Position.z);
}
pData.Close();
GroundShape.RecalcLocalAabb();
GroundShape.RefitTree(GroundShape.LocalAabbMin, GroundShape.LocalAabbMax);
}
}