[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59885] branches/soc-2013-rigid_body_sim: rigidbody: Add option to choose mesh source for collision shapes

Sergej Reich sergej.reich at googlemail.com
Fri Sep 6 19:58:45 CEST 2013


Revision: 59885
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59885
Author:   sergof
Date:     2013-09-06 17:58:45 +0000 (Fri, 06 Sep 2013)
Log Message:
-----------
rigidbody: Add option to choose mesh source for collision shapes

The options are:
Base: Base mesh
Deform: shape keys and deform modifiers
Final: All deformations and modifiers

It would be nice to have a way of specifying where exactly in the
modifier stack the collision shape is generated. However this is not
staight forward since the rigid body simulation is not part of the
modifier system and would require hacks to make it work.

Modified Paths:
--------------
    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/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-06 17:45:58 UTC (rev 59884)
+++ branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py	2013-09-06 17:58:45 UTC (rev 59885)
@@ -69,6 +69,9 @@
         rbo = ob.rigid_body
 
         layout.prop(rbo, "collision_shape", text="Shape")
+        
+        if rbo.collision_shape in {'MESH', 'CONVEX_HULL', 'APPROX'}:
+            layout.prop(rbo, "mesh_source", text="Source")
 
         split = layout.split()
 

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-06 17:45:58 UTC (rev 59884)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c	2013-09-06 17:58:45 UTC (rev 59885)
@@ -234,8 +234,17 @@
 	int totvert = 0;
 
 	if (ob->type == OB_MESH && ob->data) {
-		BLI_assert(ob->derivedDeform != NULL); // RB_TODO need to make sure there's no case where deform derived mesh doesn't exist
-		dm = ob->derivedDeform;
+		if (ob->rigidbody_object->mesh_source == RBO_MESH_DEFORM) {
+			dm = ob->derivedDeform;
+		}
+		else if (ob->rigidbody_object->mesh_source == RBO_MESH_FINAL) {
+			dm = ob->derivedFinal;
+		}
+		else {
+			dm = CDDM_from_mesh(ob->data, ob);
+		}
+
+		BLI_assert(dm != NULL); // RB_TODO need to make sure there's no case where deform derived mesh doesn't exist
 		mvert   = (dm) ? dm->getVertArray(dm) : NULL;
 		totvert = (dm) ? dm->getNumVerts(dm) : 0;
 	}
@@ -250,6 +259,9 @@
 		printf("ERROR: no vertices to define Convex Hull collision shape with\n");
 	}
 
+	if (dm && ob->rigidbody_object->mesh_source == RBO_MESH_BASE)
+		dm->release(dm);
+
 	return shape;
 }
 
@@ -261,14 +273,23 @@
 	rbCollisionShape *shape = NULL;
 
 	if (ob->type == OB_MESH) {
-		DerivedMesh *dm = ob->derivedDeform;
-
+		DerivedMesh *dm = NULL;
 		MVert *mvert;
 		MFace *mface;
 		int totvert;
 		int totface;
 		int tottris = 0;
 
+		if (ob->rigidbody_object->mesh_source == RBO_MESH_DEFORM) {
+			dm = ob->derivedDeform;
+		}
+		else if (ob->rigidbody_object->mesh_source == RBO_MESH_FINAL) {
+			dm = ob->derivedFinal;
+		}
+		else {
+			dm = CDDM_from_mesh(ob->data, ob);
+		}
+
 		/* ensure mesh validity, then grab data */
 		BLI_assert(dm!= NULL); // RB_TODO need to make sure there's no case where deform derived mesh doesn't exist
 		DM_ensure_tessface(dm);
@@ -333,11 +354,14 @@
 				shape = RB_shape_new_gimpact_mesh(mdata);
 			}
 		}
+
+		if (dm && ob->rigidbody_object->mesh_source == RBO_MESH_BASE)
+			dm->release(dm);
 	}
 	else {
 		printf("ERROR: cannot make Triangular Mesh collision shape for non-Mesh object\n");
 	}
-
+	
 	return shape;
 }
 
@@ -349,13 +373,23 @@
 	rbCollisionShape *shape = NULL;
 
 	if (ob->type == OB_MESH) {
-		DerivedMesh *dm = ob->derivedDeform;
+		DerivedMesh *dm = NULL;
 
 		MVert *mvert;
 		MFace *mface;
 		int totvert;
 		int totface;
 		int tottris = 0;
+		
+		if (ob->rigidbody_object->mesh_source == RBO_MESH_DEFORM) {
+			dm = ob->derivedDeform;
+		}
+		else if (ob->rigidbody_object->mesh_source == RBO_MESH_FINAL) {
+			dm = ob->derivedFinal;
+		}
+		else {
+			dm = CDDM_from_mesh(ob->data, ob);
+		}
 
 		/* ensure mesh validity, then grab data */
 		BLI_assert(dm!= NULL); // RB_TODO need to make sure there's no case where deform derived mesh doesn't exist
@@ -406,6 +440,9 @@
 			}
 			shape = RB_shape_new_convex_decomp(mdata);
 		}
+
+		if (dm && ob->rigidbody_object->mesh_source == RBO_MESH_BASE)
+			dm->release(dm);
 	}
 	else {
 		printf("ERROR: cannot make Triangular Mesh collision shape for non-Mesh object\n");

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-06 17:45:58 UTC (rev 59884)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h	2013-09-06 17:58:45 UTC (rev 59885)
@@ -103,7 +103,8 @@
 	
 	int flag;				/* (eRigidBodyOb_Flag) */
 	int col_groups;			/* Collision groups that determines wich rigid bodies can collide with each other */
-	int pad;
+	short mesh_source;		/* mesh source for mesh based collision shapes */
+	short pad;
 	
 	/* Physics Parameters */
 	float mass;				/* how much object 'weighs' (i.e. absolute 'amount of stuff' it holds) */
@@ -175,6 +176,16 @@
 	RB_SHAPE_APPROX
 } eRigidBody_Shape;
 
+/* RigidBody Collision Shape */
+typedef enum eRigidBody_MeshSource {
+	/* base mesh */
+	RBO_MESH_BASE = 0,
+	/* only deformations */
+	RBO_MESH_DEFORM,
+	/* final derived mesh */
+	RBO_MESH_FINAL
+} eRigidBody_MeshSource;
+
 /* ******************************** */
 /* RigidBody Constraint */
 

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-06 17:45:58 UTC (rev 59884)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c	2013-09-06 17:58:45 UTC (rev 59885)
@@ -77,7 +77,14 @@
 	{RBC_TYPE_MOTOR, "MOTOR", ICON_NONE, "Motor", "Drive rigid body around or along an axis"},
 	{0, NULL, 0, NULL, NULL}};
 
+/* roles of objects in RigidBody Sims */
+EnumPropertyItem rigidbody_mesh_source_items[] = {
+	{RBO_MESH_BASE, "BASE", 0, "Base", "Base mesh"},
+	{RBO_MESH_DEFORM, "DEFORM", 0, "Deform", "Deformations (shaps keys, deform modifiers"},
+    {RBO_MESH_FINAL, "FINAL", 0, "Final", "All modifiers"},
+	{0, NULL, 0, NULL, NULL}};
 
+
 #ifdef RNA_RUNTIME
 
 #ifdef WITH_BULLET
@@ -755,6 +762,13 @@
 	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, "mesh_source", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "mesh_source");
+	RNA_def_property_enum_items(prop, rigidbody_mesh_source_items);
+	RNA_def_property_ui_text(prop, "Mesh Source", "Source of the mesh used to create collision shape");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
+
 	/* booleans */
 	prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", RBO_FLAG_DISABLED);




More information about the Bf-blender-cvs mailing list