Page MenuHome
Paste P467

Potential fix for T51233 (allowing Final and Deforming meshs)
ActivePublic

Authored by Martin Felke (scorpion81) on Apr 17 2017, 8:21 PM.
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 688ca91..2fe8ea9 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -237,6 +237,8 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh);
/* 2b - GImpact Meshes */
rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh);
+/* for final deforming, to determine whether vertex count might have changed */
+int RB_shape_get_num_verts(rbCollisionShape *shape);
/* Cleanup --------------------------- */
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 17bb381..cf78dbe 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -803,6 +803,17 @@ rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
return shape;
}
+/* needed to rebuild mesh on demand */
+int RB_shape_get_num_verts(rbCollisionShape *shape)
+{
+ if (shape->mesh)
+ {
+ return shape->mesh->num_vertices;
+ }
+
+ return 0;
+}
+
/* Cleanup --------------------------- */
void RB_shape_delete(rbCollisionShape *shape)
diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index 6afdd80..2164f37 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -75,7 +75,7 @@ class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel, Panel):
if rbo.collision_shape in {'MESH', 'CONVEX_HULL'}:
layout.prop(rbo, "mesh_source", text="Source")
- if rbo.collision_shape == 'MESH' and rbo.mesh_source == 'DEFORM':
+ if rbo.collision_shape == 'MESH' and rbo.mesh_source in {'DEFORM', 'FINAL'}:
layout.prop(rbo, "use_deform", text="Deforming")
split = layout.split()
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 5353cc2..fc0ec54 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1238,13 +1238,28 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
return;
if (rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) {
- DerivedMesh *dm = ob->derivedDeform;
+ DerivedMesh *dm = NULL;
+ if (rbo->mesh_source == RBO_MESH_DEFORM) {
+ dm = ob->derivedDeform;
+ }
+ else if (rbo->mesh_source == RBO_MESH_FINAL) {
+ dm = ob->derivedFinal;
+ }
+
if (dm) {
MVert *mvert = dm->getVertArray(dm);
int totvert = dm->getNumVerts(dm);
BoundBox *bb = BKE_object_boundbox_get(ob);
- RB_shape_trimesh_update(rbo->physics_shape, (float *)mvert, totvert, sizeof(MVert), bb->vec[0], bb->vec[6]);
+ if (RB_shape_get_num_verts(rbo->physics_shape) != totvert)
+ {
+ rigidbody_validate_sim_shape(ob, true);
+ RB_body_set_collision_shape(rbo->physics_object, rbo->physics_shape);
+ }
+ else
+ {
+ RB_shape_trimesh_update(rbo->physics_shape, (float *)mvert, totvert, sizeof(MVert), bb->vec[0], bb->vec[6]);
+ }
}
}