Commit: bd5d172bb3c7cd470239a4bafa53594ccf3d3136
Author: Martin Felke
Date: Sun Oct 11 20:53:32 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rBbd5d172bb3c7cd470239a4bafa53594ccf3d3136
allow to update deforming rigidbody mesh even when vertex count changes (by
revalidating it), good for having fluids as deforming rigidbodies for example
===================================================================
M intern/rigidbody/RBI_api.h
M intern/rigidbody/rb_bullet_api.cpp
M source/blender/blenkernel/intern/rigidbody.c
===================================================================
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 68a3d0d..f9f86d0 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -254,6 +254,8 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh);
/* 2b - GImpact Meshes */
rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh);
+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 f372a20..84072b5 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -1065,6 +1065,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/source/blender/blenkernel/intern/rigidbody.c
b/source/blender/blenkernel/intern/rigidbody.c
index 56e1e63..f418771 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -816,9 +816,9 @@ static rbCollisionShape
*rigidbody_get_shape_trimesh_from_mesh_shard(MeshIsland
}
/* cleanup temp data */
- if (dm /*&& ob->rigidbody_object->mesh_source ==
RBO_MESH_BASE*/) {
+ if (dm && ob->rigidbody_object->mesh_source == RBO_MESH_BASE) {
dm->needsFree = 1;
- dm->release(dm);
+ dm->release(dm);
dm = NULL;
}
}
@@ -1115,6 +1115,10 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland
*mi, Object *ob, short re
break;
case RB_SHAPE_TRIMESH:
{
+ new_shape =
rigidbody_get_shape_trimesh_from_mesh_shard(mi, ob);
+ break;
+#if 0
+ //wtf, seems a merge gone wrong....
if (ob->type == OB_MESH) {
DerivedMesh *dm = rigidbody_get_mesh(ob);
MVert *mvert;
@@ -1149,6 +1153,7 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland
*mi, Object *ob, short re
volume = size[0] * size[1] * size[2];
}
break;
+#endif
}
}
/* assign new collision shape if creation was successful */
@@ -2670,7 +2675,7 @@ static void rigidbody_update_sim_world(Scene *scene,
RigidBodyWorld *rbw)
rigidbody_update_ob_array(rbw);
}
-static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object
*ob, RigidBodyOb *rbo, float centroid[3])
+static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object
*ob, RigidBodyOb *rbo, float centroid[3], MeshIsland *mi)
{
float loc[3];
float rot[4];
@@ -2695,7 +2700,25 @@ static void rigidbody_update_sim_ob(Scene *scene,
RigidBodyWorld *rbw, Object *o
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 || rbo->mesh_source == RBO_MESH_FINAL)
+ {
+ if (mi != NULL)
+ {
+ //fracture modifier case
+ rbo->flag |= RBO_FLAG_NEEDS_RESHAPE;
+ validateShard(rbw, mi, ob, false,
false);
+ }
+ else
+ {
+ //regular rigidbody case
+ 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]);
+ }
}
}
@@ -3001,7 +3024,7 @@ static bool do_update_modifier(Scene* scene, Object* ob,
RigidBodyWorld *rbw, bo
}
/* update simulation object... */
- rigidbody_update_sim_ob(scene, rbw, ob, mi->rigidbody,
mi->centroid);
+ rigidbody_update_sim_ob(scene, rbw, ob, mi->rigidbody,
mi->centroid, mi);
}
if (fmd->use_mass_dependent_thresholds) {
@@ -3140,7 +3163,7 @@ static void rigidbody_update_simulation(Scene *scene,
RigidBodyWorld *rbw, bool
}
/* update simulation object... */
- rigidbody_update_sim_ob(scene, rbw, ob, rbo, centroid);
+ rigidbody_update_sim_ob(scene, rbw, ob, rbo, centroid,
NULL);
}
rbw->flag &= ~RBW_FLAG_REFRESH_MODIFIERS;
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs