[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38099] branches/soc-2011-cucumber: Exposing access to the upper 8 bits of Bullets collision masks in the physics properties panel .

Daniel Stokes kupomail at gmail.com
Tue Jul 5 02:29:38 CEST 2011


Revision: 38099
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38099
Author:   kupoman
Date:     2011-07-05 00:29:37 +0000 (Tue, 05 Jul 2011)
Log Message:
-----------
Exposing access to the upper 8 bits of Bullets collision masks in the physics properties panel.

Collision masks set what collision groups an object can collide with.

Modified Paths:
--------------
    branches/soc-2011-cucumber/release/scripts/startup/bl_ui/properties_game.py
    branches/soc-2011-cucumber/source/blender/blenkernel/intern/object.c
    branches/soc-2011-cucumber/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-cucumber/source/blender/makesdna/DNA_object_types.h
    branches/soc-2011-cucumber/source/blender/makesrna/intern/rna_object.c
    branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    branches/soc-2011-cucumber/source/gameengine/Physics/Bullet/CcdPhysicsController.h

Modified: branches/soc-2011-cucumber/release/scripts/startup/bl_ui/properties_game.py
===================================================================
--- branches/soc-2011-cucumber/release/scripts/startup/bl_ui/properties_game.py	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/release/scripts/startup/bl_ui/properties_game.py	2011-07-05 00:29:37 UTC (rev 38099)
@@ -106,6 +106,12 @@
             col.prop(game, "lock_rotation_x", text="X")
             col.prop(game, "lock_rotation_y", text="Y")
             col.prop(game, "lock_rotation_z", text="Z")
+            
+            layout.separator()
+            
+            col = layout.column()
+            col.prop(game, "collision_group")
+            col.prop(game, "collision_mask")
 
         elif game.physics_type == 'SOFT_BODY':
             col = layout.column()
@@ -141,6 +147,12 @@
             sub = col.column()
             sub.active = (soft.use_cluster_rigid_to_softbody or soft.use_cluster_soft_to_softbody)
             sub.prop(soft, "cluster_iterations", text="Iterations")
+            
+            layout.separator()
+            
+            col = layout.column()
+            col.prop(game, "collision_group")
+            col.prop(game, "collision_mask")
 
         elif game.physics_type == 'STATIC':
             col = layout.column()
@@ -162,9 +174,24 @@
             subsub = sub.column()
             subsub.active = game.use_anisotropic_friction
             subsub.prop(game, "friction_coefficients", text="", slider=True)
+            
+            layout.separator()
+            
+            col = layout.column()
+            col.prop(game, "collision_group")
+            col.prop(game, "collision_mask")
 
-        elif game.physics_type in {'SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'}:
+        elif game.physics_type == 'SENSOR':
             layout.prop(ob, "hide_render", text="Invisible")
+            
+            layout.separator()
+            
+            col = layout.column()
+            col.prop(game, "collision_group")
+            col.prop(game, "collision_mask")
+            
+        elif game.physics_type in {'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'}:
+            layout.prop(ob, "hide_render", text="Invisible")
 
 
 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel, bpy.types.Panel):

Modified: branches/soc-2011-cucumber/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/soc-2011-cucumber/source/blender/blenkernel/intern/object.c	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/blender/blenkernel/intern/object.c	2011-07-05 00:29:37 UTC (rev 38099)
@@ -1078,6 +1078,7 @@
 	ob->state=1;
 	/* ob->pad3 == Contact Processing Threshold */
 	ob->m_contactProcessingThreshold = 1.;
+	ob->col_group = ob->col_mask = 1;
 	
 	/* NT fluid sim defaults */
 	ob->fluidsimFlag = 0;

Modified: branches/soc-2011-cucumber/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-cucumber/source/blender/blenloader/intern/readfile.c	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/blender/blenloader/intern/readfile.c	2011-07-05 00:29:37 UTC (rev 38099)
@@ -11658,6 +11658,13 @@
 		}
 
 		{
+			/* Initialize default values for collision masks */
+			Object *ob;
+			for(ob=main->object.first; ob; ob=ob->id.next)
+				ob->col_group = ob->col_mask = 1;
+		}
+
+		{
 			/* add default value for behind strength of camera actuator */
 			Object *ob;
 			bActuator *act;

Modified: branches/soc-2011-cucumber/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/soc-2011-cucumber/source/blender/makesdna/DNA_object_types.h	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/blender/makesdna/DNA_object_types.h	2011-07-05 00:29:37 UTC (rev 38099)
@@ -229,6 +229,9 @@
 	short recalc;			/* dependency flag */
 	float anisotropicFriction[3];
 
+	/** Collision mask settings */
+	unsigned short col_group, col_mask, col_pad[2];
+
 	ListBase constraints;		/* object constraints */
 	ListBase nlastrips;			// XXX depreceated... old animation system
 	ListBase hooks;
@@ -448,6 +451,9 @@
 /* controller state */
 #define OB_MAX_STATES		30
 
+/* collision masks */
+#define OB_MAX_COL_MASKS	8
+
 /* ob->gameflag */
 #define OB_DYNAMIC		1
 #define OB_CHILD		2

Modified: branches/soc-2011-cucumber/source/blender/makesrna/intern/rna_object.c
===================================================================
--- branches/soc-2011-cucumber/source/blender/makesrna/intern/rna_object.c	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/blender/makesrna/intern/rna_object.c	2011-07-05 00:29:37 UTC (rev 38099)
@@ -1002,6 +1002,64 @@
 	}
 }
 
+static void rna_GameObjectSettings_col_group_get(PointerRNA *ptr, int *values)
+{
+	Object *ob= (Object*)ptr->data;
+	int i;
+
+	memset(values, 0, sizeof(short)*OB_MAX_COL_MASKS);
+	for(i=0; i<OB_MAX_COL_MASKS; i++)
+		values[i] = (ob->col_group & (1<<i));
+}
+
+static void rna_GameObjectSettings_col_group_set(PointerRNA *ptr, const int *values)
+{
+	Object *ob= (Object*)ptr->data;
+	int i, tot= 0;
+
+	/* ensure we always have some group selected */
+	for(i=0; i<OB_MAX_COL_MASKS; i++)
+		if(values[i])
+			tot++;
+	
+	if(tot==0)
+		return;
+
+	for(i=0; i<OB_MAX_COL_MASKS; i++) {
+		if(values[i]) ob->col_group |= (1<<i);
+		else ob->col_group &= ~(1<<i);
+	}
+}
+
+static void rna_GameObjectSettings_col_mask_get(PointerRNA *ptr, int *values)
+{
+	Object *ob= (Object*)ptr->data;
+	int i;
+
+	memset(values, 0, sizeof(short)*OB_MAX_COL_MASKS);
+	for(i=0; i<OB_MAX_COL_MASKS; i++)
+		values[i] = (ob->col_mask & (1<<i));
+}
+
+static void rna_GameObjectSettings_col_mask_set(PointerRNA *ptr, const int *values)
+{
+	Object *ob= (Object*)ptr->data;
+	int i, tot= 0;
+
+	/* ensure we always have some mask selected */
+	for(i=0; i<OB_MAX_COL_MASKS; i++)
+		if(values[i])
+			tot++;
+	
+	if(tot==0)
+		return;
+
+	for(i=0; i<OB_MAX_COL_MASKS; i++) {
+		if(values[i]) ob->col_mask |= (1<<i);
+		else ob->col_mask &= ~(1<<i);
+	}
+}
+
 static void rna_GameObjectSettings_used_state_get(PointerRNA *ptr, int *values)
 {
 	Object *ob= (Object*)ptr->data;
@@ -1322,6 +1380,8 @@
 	StructRNA *srna;
 	PropertyRNA *prop;
 
+	int default_col_mask[8] = {1,0,0,0,  0,0,0,0};
+
 	static EnumPropertyItem body_type_items[] = {
 		{OB_BODY_TYPE_NO_COLLISION, "NO_COLLISION", 0, "No Collision", "Disable collision for this object"},
 		{OB_BODY_TYPE_STATIC, "STATIC", 0, "Static", "Stationary object"},
@@ -1420,6 +1480,18 @@
 	RNA_def_property_range(prop, 0.0, 1000.0);
 	RNA_def_property_ui_text(prop, "Velocity Max", "Clamp velocity to this maximum speed");
 
+	prop= RNA_def_property(srna, "collision_group", PROP_BOOLEAN, PROP_LAYER_MEMBER);
+	RNA_def_property_boolean_sdna(prop, NULL, "col_group", 1);
+	RNA_def_property_array(prop, OB_MAX_COL_MASKS);
+	RNA_def_property_ui_text(prop, "Collision Group", "The collision group of the object");
+	RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_col_group_get", "rna_GameObjectSettings_col_group_set");
+
+	prop= RNA_def_property(srna, "collision_mask", PROP_BOOLEAN, PROP_LAYER_MEMBER);
+	RNA_def_property_boolean_sdna(prop, NULL, "col_mask", 1);
+	RNA_def_property_array(prop, OB_MAX_COL_MASKS);
+	RNA_def_property_ui_text(prop, "Collision Mask", "The groups this object can collide with");
+	RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_col_mask_get", "rna_GameObjectSettings_col_mask_set");
+
 	/* lock position */
 	prop= RNA_def_property(srna, "lock_location_x", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_X_AXIS);

Modified: branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2011-07-05 00:29:37 UTC (rev 38099)
@@ -1594,6 +1594,11 @@
 	objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
 	objprop.m_softbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0;
 	objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
+
+	// Get collision mask information and store it in the upper 8 bits
+	// The lower 8 bits are reserved for internal blender usage
+	objprop.m_col_group = blenderobject->col_group << 8;
+	objprop.m_col_mask = blenderobject->col_mask << 8;
 	
 	///contact processing threshold is only for rigid bodies and static geometry, not 'dynamic'
 	if (objprop.m_angular_rigidbody || !objprop.m_dyna )

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h	2011-07-05 00:29:37 UTC (rev 38099)
@@ -82,6 +82,11 @@
 
 	/////////////////////////
 
+	short	m_col_group;
+	short	m_col_mask;
+
+	/////////////////////////
+
 	int		m_gamesoftFlag;
 	float	m_soft_linStiff;			/* linear stiffness 0..1 */
 	float	m_soft_angStiff;		/* angular stiffness 0..1 */

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2011-07-04 22:37:28 UTC (rev 38098)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2011-07-05 00:29:37 UTC (rev 38099)
@@ -402,12 +402,12 @@
 	////////////////////
 	ci.m_collisionFilterGroup = 
 		(isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) :
-		(isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : 
 		short(CcdConstructionInfo::StaticFilter);
+	ci.m_collisionFilterGroup = objprop->m_col_group;
 	ci.m_collisionFilterMask = 
 		(isbulletsensor) ? short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter) :
-		(isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list