Rigidbody: Allow triangle mesh shapes to deform during simulation
[blender.git] / intern / rigidbody / rb_bullet_api.cpp
index 31f7f38666390f5cae563dfaa8095c4370d3e899..ef35d3b257b9bf7d271a9e7c9f7232a659fa1c32 100644 (file)
@@ -763,6 +763,29 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh)
        return shape;
 }
 
+void RB_shape_trimesh_update(rbCollisionShape *shape, float *vertices, int num_verts, int vert_stride, float min[3], float max[3])
+{
+       if (shape->mesh == NULL || num_verts != shape->mesh->num_vertices)
+               return;
+       
+       for (int i = 0; i < num_verts; i++) {
+               float *vert = (float*)(((char*)vertices + i * vert_stride));
+               shape->mesh->vertices[i].x = vert[0];
+               shape->mesh->vertices[i].y = vert[1];
+               shape->mesh->vertices[i].z = vert[2];
+       }
+       
+       if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) {
+               btScaledBvhTriangleMeshShape *scaled_shape = (btScaledBvhTriangleMeshShape *)shape->cshape;
+               btBvhTriangleMeshShape *mesh_shape = scaled_shape->getChildShape();
+               mesh_shape->refitTree(btVector3(min[0], min[1], min[2]), btVector3(max[0], max[1], max[2]));
+       }
+       else if (shape->cshape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) {
+               btGImpactMeshShape *mesh_shape = (btGImpactMeshShape*)shape->cshape;
+               mesh_shape->updateBound();
+       }
+}
+
 rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
 {
        rbCollisionShape *shape = new rbCollisionShape;