[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60284] branches/soc-2013-rigid_body_sim: rigidbody: Add activation based on time

Sergej Reich sergej.reich at googlemail.com
Sat Sep 21 07:12:06 CEST 2013


Revision: 60284
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60284
Author:   sergof
Date:     2013-09-21 05:12:05 +0000 (Sat, 21 Sep 2013)
Log Message:
-----------
rigidbody: Add activation based on time

Time is specified in seconds.

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:12:03 UTC (rev 60283)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/RBI_api.h	2013-09-21 05:12:05 UTC (rev 60284)
@@ -187,6 +187,8 @@
 extern void RB_body_set_trigger(rbRigidBody *object, int trigger);
 extern void RB_body_set_ghost(rbRigidBody *object, int ghost);
 extern void RB_body_set_activation_type(rbRigidBody *object, int type);
+extern void RB_body_set_activation_time(rbRigidBody *object, double time);
+extern void RB_body_try_activation(rbRigidBody *object);
 
 /* RigidBody Interface - Rigid Body Activation States */
 extern int RB_body_get_activation_state(rbRigidBody *body);

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:12:03 UTC (rev 60283)
+++ branches/soc-2013-rigid_body_sim/intern/rigidbody/rb_bullet_api.cpp	2013-09-21 05:12:05 UTC (rev 60284)
@@ -86,6 +86,7 @@
 	btBroadphaseInterface *pairCache;
 	btConstraintSolver *constraintSolver;
 	btOverlapFilterCallback *filterCallback;
+	double elapsed_time;
 };
 
 enum ActivationType {
@@ -96,11 +97,12 @@
 
 struct rbRigidBody {
 	btRigidBody *body;
-	btDiscreteDynamicsWorld *world;
+	rbDynamicsWorld *world;
 	int col_groups;
 	bool is_trigger;
 	bool suspended;
 	float saved_mass;
+	double activation_time;
 	int activation_type;
 };
 
@@ -142,20 +144,24 @@
 	}
 };
 
+static void activate(rbRigidBody *rb)
+{
+	btRigidBody *body = rb->body;
+	rb->suspended = false;
+	rb->world->dynamicsWorld->removeRigidBody(body);
+	RB_body_set_mass(rb, rb->saved_mass);
+	rb->world->dynamicsWorld->addRigidBody(body);
+	body->activate();
+}
+
 static void nearCallback(btBroadphasePair &collisionPair, btCollisionDispatcher &dispatcher, const btDispatcherInfo &dispatchInfo)
 {
 	rbRigidBody *rb0 = (rbRigidBody *)((btRigidBody *)collisionPair.m_pProxy0->m_clientObject)->getUserPointer();
 	rbRigidBody *rb1 = (rbRigidBody *)((btRigidBody *)collisionPair.m_pProxy1->m_clientObject)->getUserPointer();
 	
 	if (rb1->suspended && !(rb1->activation_type == ACTIVATION_TRIGGER && !rb0->is_trigger)) {
-		btRigidBody *body = rb1->body;
-		rb1->suspended = false;
-		rb1->world->removeRigidBody(body);
-		RB_body_set_mass(rb1, rb1->saved_mass);
-		rb1->world->addRigidBody(body);
-		body->activate();
+		activate(rb1);
 	}
-	
 	dispatcher.defaultNearCallback(collisionPair, dispatcher, dispatchInfo);
 }
 
@@ -256,6 +262,8 @@
 	
 //	gContactAddedCallback = contactAddedCallback;
 	
+	world->elapsed_time = 0.0;
+	
 	// HACK set debug drawer, this is only temporary
 	btIDebugDraw *debugDrawer = new rbDebugDraw();
 	debugDrawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe |
@@ -316,6 +324,7 @@
 
 void RB_dworld_step_simulation(rbDynamicsWorld *world, float timeStep, int maxSubSteps, float timeSubStep)
 {
+	world->elapsed_time += timeStep;
 	world->dynamicsWorld->stepSimulation(timeStep, maxSubSteps, timeSubStep);
 	
 	// draw debug information
@@ -357,7 +366,7 @@
 {
 	btRigidBody *body = object->body;
 	object->col_groups = col_groups;
-	object->world = world->dynamicsWorld;
+	object->world = world;
 	
 	world->dynamicsWorld->addRigidBody(body);
 }
@@ -684,6 +693,17 @@
 	object->activation_type = type;
 }
 
+void RB_body_set_activation_time(rbRigidBody *object, double time)
+{
+	object->activation_time = time;
+}
+
+void RB_body_try_activation(rbRigidBody *object)
+{
+	if (object->suspended && object->activation_time <= object->world->elapsed_time)
+		activate(object);
+}
+
 /* ............ */
 
 void RB_body_set_activation_state(rbRigidBody *object, int use_deactivation)

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:12:03 UTC (rev 60283)
+++ branches/soc-2013-rigid_body_sim/release/scripts/startup/bl_ui/properties_physics_rigidbody.py	2013-09-21 05:12:05 UTC (rev 60284)
@@ -125,7 +125,9 @@
         col.prop(rbo, "use_start_deactivated")
         sub = col.column()
         sub.active = rbo.use_start_deactivated
-        sub.prop(rbo, "activation_type")
+        sub.prop(rbo, "activation_type", text="Type")
+        if rbo.activation_type == 'TIME':
+            sub.prop(rbo, "activation_time", text="Time")
 
         col = split.column()
         col.label(text="Deactivation:")

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:12:03 UTC (rev 60283)
+++ branches/soc-2013-rigid_body_sim/source/blender/blenkernel/intern/rigidbody.c	2013-09-21 05:12:05 UTC (rev 60284)
@@ -679,6 +679,7 @@
 		RB_body_set_trigger(rbo->physics_object, rbo->flag & RBO_FLAG_TRIGGER);
 		RB_body_set_ghost(rbo->physics_object, rbo->flag & RBO_FLAG_GHOST);
 		RB_body_set_activation_type(rbo->physics_object, rbo->activation_type);
+		RB_body_set_activation_time(rbo->physics_object, rbo->activation_time);
 	}
 
 	if (rbw && rbw->physics_world && (rbo->flag & RBO_FLAG_COMPOUND_CHILD) == 0) // RB_TODO find better solution for compound shapes
@@ -982,6 +983,8 @@
 
 	rbo->col_groups = 1;
 
+	rbo->activation_time = 1.0f;
+
 	/* use triangle meshes for passive objects
 	 * use convex hulls for active objects since dynamic triangle meshes are very unstable
 	 */
@@ -1203,6 +1206,9 @@
 		RB_shape_trimesh_update(rbo->physics_shape, (float*)mvert, totvert, sizeof(MVert), bb->vec[0], bb->vec[6]);
 	}
 
+	if (rbo->type == RBO_TYPE_ACTIVE && rbo->activation_type == RBO_ACTIVATION_TIME)
+		RB_body_try_activation(rbo->physics_object);
+
 	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:12:03 UTC (rev 60283)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesdna/DNA_rigidbody_types.h	2013-09-21 05:12:05 UTC (rev 60284)
@@ -122,7 +122,7 @@
 	
 	float orn[4];			/* rigid body orientation */
 	float pos[3];			/* rigid body position */
-	float pad1;
+	float activation_time;	/* time until body is activated */
 	struct EffectorWeights *effector_weights;
 } RigidBodyOb;
 

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:12:03 UTC (rev 60283)
+++ branches/soc-2013-rigid_body_sim/source/blender/makesrna/intern/rna_rigidbody.c	2013-09-21 05:12:05 UTC (rev 60284)
@@ -838,7 +838,13 @@
 	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
 	
 	/* Dynamics Parameters - Activation */
-	// TODO: define and figure out how to implement these
+	prop = RNA_def_property(srna, "activation_time", PROP_FLOAT, PROP_UNIT_TIME);
+	RNA_def_property_float_sdna(prop, NULL, "activation_time");
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_ui_text(prop, "Time", "Time until activation");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_reset");
 	
 	/* Dynamics Parameters - Deactivation */
 	prop = RNA_def_property(srna, "use_deactivation", PROP_BOOLEAN, PROP_NONE);




More information about the Bf-blender-cvs mailing list