[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60277] branches/soc-2013-rigid_body_sim: rigidbody: Allow triangle mesh shapes to deform during simulation

Sergej Reich sergej.reich at googlemail.com
Sat Sep 21 07:11:54 CEST 2013


Revision: 60277
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60277
Author:   sergof
Date:     2013-09-21 05:11:53 +0000 (Sat, 21 Sep 2013)
Log Message:
-----------
rigidbody: Allow triangle mesh shapes to deform during simulation

Only supported when using the "Deform" mesh source.
TODO: look into deforming active rigid bodies

Modified Paths:
--------------
    branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h
    branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp
    branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
    branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h
    branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c

Modified: branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h
===================================================================
--- branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h	2013-09-21 05:11:51 UTC (rev 60276)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h	2013-09-21 05:11:53 UTC (rev 60277)
@@ -265,6 +265,8 @@
 extern float RB_shape_get_margin(rbCollisionShape *shape);
 extern void RB_shape_set_margin(rbCollisionShape *shape, float value);
 
+extern void RB_shape_trimesh_update(rbCollisionShape *shape, float *vertices, int num_verts, int vert_stride, float min[3], float max[3]);
+
 /* ********************************** */
 /* Constraints */
 

Modified: branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp
===================================================================
--- branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp	2013-09-21 05:11:51 UTC (rev 60276)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp	2013-09-21 05:11:53 UTC (rev 60277)
@@ -949,6 +949,21 @@
 	return shape;
 }
 
+void RB_shape_trimesh_update(rbCollisionShape *shape, float *vertices, int num_verts, int vert_stride, float min[3], float max[3])
+{
+	assert(num_verts == shape->mesh->num_vertices);
+	btScaledBvhTriangleMeshShape *scaled_shape = (btScaledBvhTriangleMeshShape *)shape->cshape;
+	btBvhTriangleMeshShape *mesh_shape = scaled_shape->getChildShape();
+	
+	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];
+	}
+	mesh_shape->refitTree(btVector3(min[0], min[1], min[2]), btVector3(max[0], max[1], max[2]));
+}
+
 rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
 {
 	rbCollisionShape *shape = new rbCollisionShape;

Modified: branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py	2013-09-21 05:11:51 UTC (rev 60276)
+++ branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py	2013-09-21 05:11:53 UTC (rev 60277)
@@ -78,6 +78,9 @@
         if rbo.collision_shape in {'MESH', 'CONVEX_HULL', 'APPROX'}:
             layout.prop(rbo, "mesh_source", text="Source")
 
+        if rbo.type == 'PASSIVE' and rbo.collision_shape == 'MESH' and rbo.mesh_source == 'DEFORM':
+            layout.prop(rbo, "use_deform", text="Deforming")
+
         split = layout.split()
 
         col = split.column()

Modified: branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c	2013-09-21 05:11:51 UTC (rev 60276)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c	2013-09-21 05:11:53 UTC (rev 60277)
@@ -1194,6 +1194,15 @@
 	if (rbo->physics_object == NULL)
 		return;
 
+	if (rbo->type == RBO_TYPE_PASSIVE && rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) {
+		DerivedMesh *dm = ob->derivedDeform;
+		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]);
+	}
+
 	mat4_decompose(loc, rot, scale, ob->obmat);
 
 	/* update scale for all objects */

Modified: branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h	2013-09-21 05:11:51 UTC (rev 60276)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h	2013-09-21 05:11:53 UTC (rev 60277)
@@ -157,7 +157,9 @@
 	/* rigidbdody is used as a collision trigger */
 	RBO_FLAG_TRIGGER			= (1 << 9),
 	/* rigidbdody has no collision response */
-	RBO_FLAG_GHOST				= (1 << 10)
+	RBO_FLAG_GHOST				= (1 << 10),
+	/* collision shape deforms during simulation (only for passive triangle mesh shapes) */
+	RBO_FLAG_USE_DEFORM			= (1 << 11)
 } eRigidBodyOb_Flag;
 
 /* RigidBody Collision Shape */

Modified: branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c	2013-09-21 05:11:51 UTC (rev 60276)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c	2013-09-21 05:11:53 UTC (rev 60277)
@@ -822,6 +822,12 @@
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
 
+	prop = RNA_def_property(srna, "use_deform", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_USE_DEFORM);
+	RNA_def_property_ui_text(prop, "Deforming", "Rigid body deforms during simulation");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
+
 	/* Physics Parameters */
 	prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_UNIT_MASS);
 	RNA_def_property_float_sdna(prop, NULL, "mass");




More information about the Bf-blender-cvs mailing list