[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20239] trunk/blender/source: BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.

Benoit Bolsee benoit.bolsee at online.be
Sun May 17 14:51:51 CEST 2009


Revision: 20239
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20239
Author:   ben2610
Date:     2009-05-17 14:51:51 +0200 (Sun, 17 May 2009)

Log Message:
-----------
BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.

A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
  * Actor option: the collisioning object must have the Actor flag set to be detected
  * property/material: as specified in the collision sensors attached to it
  Broadphase filtering is important for performance reason: the collision points
  will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it

Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it

Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.

The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
  to the suface by increasing the margin in the Advanced Settings panel.
  The margin applies on both sides of the surface.

Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
  because of the Scenegraph optimizations and they can have multiple collision sensors
  on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
  on the sensor object, it is removed from the simulation and consume no CPU.

Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
  "warning btCollisionDispatcher::needsCollision: static-static collision!"
  In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.

Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
  sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.

Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
  several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects 

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/python/api2_2x/Object.c
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_ClientObjectInfo.h
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_MotionState.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MotionState.h
    trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_NearSensor.h
    trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.h
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.h
    trunk/blender/source/gameengine/Physics/BlOde/OdePhysicsController.cpp
    trunk/blender/source/gameengine/Physics/BlOde/OdePhysicsController.h
    trunk/blender/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsController.h
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/common/PHY_IMotionState.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsController.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
    trunk/blender/source/gameengine/SceneGraph/SG_IObject.h
    trunk/blender/source/gameengine/SceneGraph/SG_Spatial.h

Modified: trunk/blender/source/blender/makesdna/DNA_object_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_types.h	2009-05-17 12:25:06 UTC (rev 20238)
+++ trunk/blender/source/blender/makesdna/DNA_object_types.h	2009-05-17 12:51:51 UTC (rev 20239)
@@ -440,6 +440,7 @@
 #define OB_COLLISION	65536
 #define OB_SOFT_BODY	0x20000
 #define OB_OCCLUDER		0x40000
+#define OB_SENSOR		0x80000
 
 /* ob->gameflag2 */
 #define OB_NEVER_DO_ACTIVITY_CULLING	1
@@ -459,6 +460,7 @@
 #define OB_BODY_TYPE_RIGID			3
 #define OB_BODY_TYPE_SOFT			4
 #define OB_BODY_TYPE_OCCLUDER		5
+#define OB_BODY_TYPE_SENSOR			6
 
 /* ob->scavisflag */
 #define OB_VIS_SENS		1

Modified: trunk/blender/source/blender/python/api2_2x/Object.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Object.c	2009-05-17 12:25:06 UTC (rev 20238)
+++ trunk/blender/source/blender/python/api2_2x/Object.c	2009-05-17 12:51:51 UTC (rev 20239)
@@ -3562,7 +3562,7 @@
 /* this is too low level, possible to add helper methods */
 
 #define GAMEFLAG_MASK ( OB_OCCLUDER | OB_COLLISION | OB_DYNAMIC | OB_CHILD | OB_ACTOR | OB_DO_FH | \
-		OB_ROT_FH | OB_ANISOTROPIC_FRICTION | OB_GHOST | OB_RIGID_BODY | OB_SOFT_BODY | \
+		OB_ROT_FH | OB_ANISOTROPIC_FRICTION | OB_GHOST | OB_RIGID_BODY | OB_SOFT_BODY | OB_SENSOR | \
 		OB_BOUNDS | OB_COLLISION_RESPONSE | OB_SECTOR | OB_PROP | \
 		OB_MAINACTOR )
 
@@ -5544,6 +5544,7 @@
 		BPy_constant *d = ( BPy_constant * ) M;
 		PyConstant_Insert( d, "OCCLUDER", PyInt_FromLong( OB_OCCLUDER ) );
 		PyConstant_Insert( d, "COLLISION", PyInt_FromLong( OB_COLLISION ) );
+		PyConstant_Insert( d, "SENSOR", PyInt_FromLong( OB_SENSOR ) );
 		PyConstant_Insert( d, "DYNAMIC", PyInt_FromLong( OB_DYNAMIC ) );
 		PyConstant_Insert( d, "CHILD", PyInt_FromLong( OB_CHILD ) );
 		PyConstant_Insert( d, "ACTOR", PyInt_FromLong( OB_ACTOR ) );

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c	2009-05-17 12:25:06 UTC (rev 20238)
+++ trunk/blender/source/blender/src/buttons_logic.c	2009-05-17 12:51:51 UTC (rev 20239)
@@ -3064,29 +3064,33 @@
 	Object *ob = arg2_object;
 
 	switch (ob->body_type) {
+	case OB_BODY_TYPE_SENSOR:
+		ob->gameflag |= OB_SENSOR|OB_COLLISION|OB_GHOST;
+		ob->gameflag &= ~(OB_OCCLUDER|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR|OB_ANISOTROPIC_FRICTION|OB_DO_FH|OB_ROT_FH|OB_COLLISION_RESPONSE);
+		break;
 	case OB_BODY_TYPE_OCCLUDER:
 		ob->gameflag |= OB_OCCLUDER;
-		ob->gameflag &= ~(OB_COLLISION|OB_DYNAMIC);
+		ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC);
 		break;
 	case OB_BODY_TYPE_NO_COLLISION:
-		ob->gameflag &= ~(OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
+		ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
 		break;
 	case OB_BODY_TYPE_STATIC:
 		ob->gameflag |= OB_COLLISION;
-		ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER);
+		ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
 		break;
 	case OB_BODY_TYPE_DYNAMIC:
 		ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_ACTOR;
-		ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER);
+		ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
 		break;
 	case OB_BODY_TYPE_RIGID:
 		ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR;
-		ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER);
+		ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
 		break;
 	default:
 	case OB_BODY_TYPE_SOFT:
 		ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_SOFT_BODY|OB_ACTOR;
-		ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER);
+		ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR);
 		
 		/* assume triangle mesh, if no bounds chosen for soft body */
 		if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH))
@@ -3271,17 +3275,31 @@
 static void buttons_bullet(uiBlock *block, Object *ob)
 {
 	uiBut *but;
+	char *tip;
 
 	/* determine the body_type setting based on flags */
-	if (!(ob->gameflag & OB_COLLISION))
-		ob->body_type = (ob->gameflag & OB_OCCLUDER) ? OB_BODY_TYPE_OCCLUDER : OB_BODY_TYPE_NO_COLLISION;
-	else if (!(ob->gameflag & OB_DYNAMIC))
+	if (!(ob->gameflag & OB_COLLISION)) {
+		if (ob->gameflag & OB_OCCLUDER) {
+			tip = "Occluder";
+			ob->body_type = OB_BODY_TYPE_OCCLUDER;
+		} else {
+			tip = "Disable colision for this object";
+			ob->body_type = OB_BODY_TYPE_NO_COLLISION;
+		}
+	} else if (ob->gameflag & OB_SENSOR) {
+		tip = "Collision Sensor, detects static and dynamic objects but not the other collision sensor objects";
+		ob->body_type = OB_BODY_TYPE_SENSOR;
+	} else if (!(ob->gameflag & OB_DYNAMIC)) {
+		tip = "Static";
 		ob->body_type = OB_BODY_TYPE_STATIC;
-	else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY)))
+	} else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY))) {
+		tip = "Dynamic";
 		ob->body_type = OB_BODY_TYPE_DYNAMIC;
-	else if (ob->gameflag & OB_RIGID_BODY)
+	} else if (ob->gameflag & OB_RIGID_BODY) {
+		tip = "Rigid body";
 		ob->body_type = OB_BODY_TYPE_RIGID;
-	else {
+	} else {
+		tip = "Soft body";
 		ob->body_type = OB_BODY_TYPE_SOFT;
 		/* create the structure here because we display soft body buttons in the main panel */
 		if (!ob->bsoft)
@@ -3292,28 +3310,36 @@
 
 	//only enable game soft body if Blender Soft Body exists
 	but = uiDefButS(block, MENU, REDRAWVIEW3D, 
-			"Object type%t|Occluder%x5|No collision%x0|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4", 
-			10, 205, 100, 19, &ob->body_type, 0, 0, 0, 0, "Selects the type of physical representation");
+			"Object type%t|Occluder%x5|No collision%x0|Sensor%x6|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4", 
+			10, 205, 100, 19, &ob->body_type, 0, 0, 0, 0, tip);
 	uiButSetFunc(but, check_body_type, but, ob);
 
 	if (ob->gameflag & OB_COLLISION) {
 
-		uiDefButBitI(block, TOG, OB_ACTOR, 0, "Actor",
-					110, 205, 50, 19, &ob->gameflag, 0, 0, 0, 0,
-					"Objects that are detected by the Near and Radar sensor");
+		if (ob->gameflag & OB_SENSOR) {
+			uiBlockEndAlign(block);
+			uiDefBlockBut(block, advanced_bullet_menu, ob, 
+						  "Advanced Settings", 
+						  210, 205, 140, 19, "Display collision advanced settings");
+			uiBlockBeginAlign(block);
+		} else {
+			uiDefButBitI(block, TOG, OB_ACTOR, 0, "Actor",
+						110, 205, 50, 19, &ob->gameflag, 0, 0, 0, 0,
+						"Objects that are detected by the Near and Radar sensor and the collision sensor objects");
 
-			
+				
 
-		uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 
-					160,205,50,19, 
-					&ob->gameflag, 0, 0, 0, 0, 
-					"Objects that don't restitute collisions (like a ghost)");
+			uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 
+						160,205,50,19, 
+						&ob->gameflag, 0, 0, 0, 0, 
+						"Objects that don't restitute collisions (like a ghost)");
 
-		//uiBlockSetCol(block, TH_BUT_SETTING1);
-		uiDefBlockBut(block, advanced_bullet_menu, ob, 
-					  "Advanced Settings", 
-					  210, 205, 140, 19, "Display collision advanced settings");
-		//uiBlockSetCol(block, TH_BUT_SETTING2);
+			//uiBlockSetCol(block, TH_BUT_SETTING1);
+			uiDefBlockBut(block, advanced_bullet_menu, ob, 
+						  "Advanced Settings", 
+						  210, 205, 140, 19, "Display collision advanced settings");
+			//uiBlockSetCol(block, TH_BUT_SETTING2);
+		}
 
 
 		if(ob->gameflag & OB_DYNAMIC) {
@@ -3394,7 +3420,7 @@
 
 		/* In Bullet, anisotripic friction can be applied to static objects as well, just not soft bodies */
 
-		if (!(ob->gameflag & OB_SOFT_BODY))
+		if (!(ob->gameflag & (OB_SOFT_BODY|OB_SENSOR)))
 		{
 			uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic", 
 				230, 145, 120, 19,

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2009-05-17 12:25:06 UTC (rev 20238)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2009-05-17 12:51:51 UTC (rev 20239)
@@ -1413,6 +1413,7 @@
 	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;
+	objprop.m_sensor = (blenderobject->gameflag & OB_SENSOR) != 0;
 	
 	if (objprop.m_softbody)
 	{

Modified: trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h	2009-05-17 12:25:06 UTC (rev 20238)
+++ trunk/blender/source/gameengine/GameLogic/SCA_ISensor.h	2009-05-17 12:51:51 UTC (rev 20239)
@@ -91,6 +91,15 @@
 	std::vector<class SCA_IController*>		m_linkedcontrollers;
 
 public:
+
+	enum sensortype {
+		NONE = 0,
+		TOUCH,
+		NEAR,
+		RADAR,
+		// to be updated as needed
+	};
+
 	SCA_ISensor(SCA_IObject* gameobj,
 				class SCA_EventManager* eventmgr,
 				PyTypeObject* T );;
@@ -138,6 +147,8 @@
 
 	virtual double GetNumber();
 
+	virtual sensortype GetSensorType() { return NONE; }
+
 	/** Stop sensing for a while. */
 	void Suspend();
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp	2009-05-17 12:25:06 UTC (rev 20238)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp	2009-05-17 12:51:51 UTC (rev 20239)
@@ -17,8 +17,8 @@
 #include "BulletSoftBody/btSoftBody.h"
 
 
-KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound)
-: KX_IPhysicsController(dyna,compound,(PHY_IPhysicsController*)this),
+KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool sensor, bool compound)
+: KX_IPhysicsController(dyna,sensor,compound,(PHY_IPhysicsController*)this),
 CcdPhysicsController(ci),
 m_savedCollisionFlags(0),
 m_savedCollisionFilterGroup(0),
@@ -174,6 +174,20 @@
 {
 	CcdPhysicsController::setScaling(scaling.x(),scaling.y(),scaling.z());
 }
+void KX_BulletPhysicsController::SetTransform()
+{
+	btVector3 pos;
+	btVector3 scale;
+	float ori[12];
+	m_MotionState->getWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list