[Bf-blender-cvs] [608a662] fracture_modifier: triggered objects dont need to be fractured any more and restore kinematic after load

Martin Felke noreply at git.blender.org
Sat Nov 8 12:16:55 CET 2014


Commit: 608a662ecbbcf5969c62596ec840c72f4cbe57bf
Author: Martin Felke
Date:   Sat Nov 8 12:14:36 2014 +0100
Branches: fracture_modifier
https://developer.blender.org/rB608a662ecbbcf5969c62596ec840c72f4cbe57bf

triggered objects dont need to be fractured any more and restore kinematic after load

===================================================================

M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
M	source/blender/blenkernel/intern/rigidbody.c

===================================================================

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 4e21ebf..da24c55 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -84,7 +84,7 @@ typedef struct rbContactCallback rbContactCallback;
 
 /* Create a new dynamics world instance */
 // TODO: add args to set the type of constraint solvers, etc.
-rbDynamicsWorld *RB_dworld_new(const float gravity[3], void* blenderWorld, int (*callback)(void *, void *, void *),
+rbDynamicsWorld *RB_dworld_new(const float gravity[3], void* blenderWorld, int (*callback)(void*, void*, void*, void*, void*),
 							     void (*contactCallback)(rbContactPoint *, void *));
 
 /* Delete the given dynamics world, and free any extra data it may require */
@@ -117,7 +117,7 @@ void RB_dworld_export(rbDynamicsWorld *world, const char *filename);
 /* Setup ---------------------------- */
 
 /* Add RigidBody to dynamics world */
-void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *body, int col_groups, void* meshIsland);
+void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *body, int col_groups, void* meshIsland, void *blenderOb);
 
 /* Remove RigidBody from dynamics world */
 void RB_dworld_remove_body(rbDynamicsWorld *world, rbRigidBody *body);
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index bfe12be..a023cb8 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -87,6 +87,7 @@ struct rbRigidBody {
 	btRigidBody *body;
 	int col_groups;
 	void *meshIsland;
+	void *blenderOb;
 	rbDynamicsWorld *world;
 };
 
@@ -112,9 +113,9 @@ struct rbCollisionShape {
 
 struct rbFilterCallback : public btOverlapFilterCallback
 {
-	int (*callback)(void* world, void* island1, void* island2);
+	int (*callback)(void* world, void* island1, void* island2, void* blenderOb1, void* blenderOb2);
 
-	rbFilterCallback(int (*callback)(void* world, void* island1, void* island2)) {
+	rbFilterCallback(int (*callback)(void* world, void* island1, void* island2, void* blenderOb1, void* blenderOb2)) {
 		this->callback = callback;
 	}
 
@@ -128,7 +129,7 @@ struct rbFilterCallback : public btOverlapFilterCallback
 		collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
 		collides = collides && (rb0->col_groups & rb1->col_groups);
 		if (this->callback != NULL) {
-			int result = this->callback(rb0->world->blenderWorld, rb0->meshIsland, rb1->meshIsland);
+			int result = this->callback(rb0->world->blenderWorld, rb0->meshIsland, rb1->meshIsland, rb0->blenderOb, rb1->blenderOb);
 			collides = collides && (bool)result;
 		}
 		
@@ -203,7 +204,7 @@ bool rbContactCallback::handle_contacts(btManifoldPoint& point, btCollisionObjec
 /* Setup ---------------------------- */
 
 //yuck, but need a handle for the world somewhere for collision callback...
-rbDynamicsWorld *RB_dworld_new(const float gravity[3], void* blenderWorld, int (*callback)(void *, void *, void *),
+rbDynamicsWorld *RB_dworld_new(const float gravity[3], void* blenderWorld, int (*callback)(void *, void *, void *, void *, void *),
 							   void (*contactCallback)(rbContactPoint * cp, void *bworld))
 {
 	rbDynamicsWorld *world = new rbDynamicsWorld;
@@ -320,12 +321,13 @@ void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
 
 /* Setup ---------------------------- */
 
-void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *object, int col_groups, void* meshIsland)
+void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *object, int col_groups, void* meshIsland, void* blenderOb)
 {
 	btRigidBody *body = object->body;
 	object->col_groups = col_groups;
 	object->meshIsland = meshIsland;
 	object->world = world;
+	object->blenderOb = blenderOb;
 	
 	world->dynamicsWorld->addRigidBody(body);
 }
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 6619295..e91f9bd 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1158,7 +1158,7 @@ void BKE_rigidbody_validate_sim_shard(RigidBodyWorld *rbw, MeshIsland *mi, Objec
 	}
 
 	if (rbw && rbw->physics_world && rbo->physics_object)
-		RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, mi);
+		RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, mi, ob);
 
 	rbo->flag &= ~RBO_FLAG_NEEDS_VALIDATE;
 	rbo->flag &= ~RBO_FLAG_KINEMATIC_REBUILD;
@@ -1234,7 +1234,7 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool
 	}
 
 	if (rbw && rbw->physics_world)
-		RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, NULL);
+		RB_dworld_add_body(rbw->physics_world, rbo->physics_object, rbo->col_groups, NULL, ob);
 }
 
 /* --------------------- */
@@ -1621,12 +1621,13 @@ static bool colgroup_check(int group1, int group2)
 }
 
 //this allows partial object activation, only some shards will be activated, called from bullet(!)
-static int filterCallback(void* world, void* island1, void* island2) {
+static int filterCallback(void* world, void* island1, void* island2, void *blenderOb1, void* blenderOb2) {
 	MeshIsland* mi1, *mi2;
 	RigidBodyWorld *rbw = (RigidBodyWorld*)world;
 	Object* ob1, *ob2;
 	int ob_index1, ob_index2;
 	FractureModifierData *fmd1, *fmd2;
+	bool validOb = true;
 
 	mi1 = (MeshIsland*)island1;
 	mi2 = (MeshIsland*)island2;
@@ -1636,20 +1637,50 @@ static int filterCallback(void* world, void* island1, void* island2) {
 		return 1;
 	}
 
-	if ((mi1 == NULL) || (mi2 == NULL)) {
+	/*if ((mi1 == NULL) || (mi2 == NULL)) {
 		return 1;
-	}
+	}*/
 
 	//cache offset map is a dull name for that...
-	ob_index1 = rbw->cache_offset_map[mi1->linear_index];
-	ob_index2 = rbw->cache_offset_map[mi2->linear_index];
+	if (mi1 != NULL)
+	{
+		ob_index1 = rbw->cache_offset_map[mi1->linear_index];
+		ob1 = rbw->objects[ob_index1];
+	}
+	else
+	{
+		ob1 = blenderOb1;
+	}
+
+	if (mi2 != NULL)
+	{
+		ob_index2 = rbw->cache_offset_map[mi2->linear_index];
+		ob2 = rbw->objects[ob_index2];
+	}
+	else
+	{
+		ob2 = blenderOb2;
+	}
 
-	ob1 = rbw->objects[ob_index1];
-	ob2 = rbw->objects[ob_index2];
+	if ((mi1 != NULL) && (mi2 != NULL)) {
+		validOb = (ob_index1 != ob_index2 && colgroup_check(ob1->rigidbody_object->col_groups, ob2->rigidbody_object->col_groups) &&
+				  ((mi1->rigidbody->flag & RBO_FLAG_KINEMATIC) || (mi2->rigidbody->flag & RBO_FLAG_KINEMATIC)));
+	}
+	else if ((mi1 == NULL) && (mi2 != NULL)) {
+		validOb = (colgroup_check(ob1->rigidbody_object->col_groups, ob2->rigidbody_object->col_groups) &&
+		          ((ob1->rigidbody_object->flag & RBO_FLAG_KINEMATIC) || (mi2->rigidbody->flag & RBO_FLAG_KINEMATIC)));
+	}
+	else if ((mi1 != NULL) && (mi2 == NULL)) {
+		validOb = (colgroup_check(ob1->rigidbody_object->col_groups, ob2->rigidbody_object->col_groups) &&
+		          ((mi1->rigidbody->flag & RBO_FLAG_KINEMATIC) || (ob2->rigidbody_object->flag & RBO_FLAG_KINEMATIC)));
+	}
+	else
+	{
+		validOb = (colgroup_check(ob1->rigidbody_object->col_groups, ob2->rigidbody_object->col_groups) &&
+		          ((ob1->rigidbody_object->flag & RBO_FLAG_KINEMATIC) || (ob2->rigidbody_object->flag & RBO_FLAG_KINEMATIC)));
+	}
 
-	if (ob_index1 != ob_index2 && colgroup_check(ob1->rigidbody_object->col_groups, ob2->rigidbody_object->col_groups) &&
-	   ((mi1->rigidbody->flag & RBO_FLAG_KINEMATIC) ||
-	   (mi2->rigidbody->flag & RBO_FLAG_KINEMATIC)))
+	if (validOb)
 	{
 		MeshIsland *mi;
 
@@ -1662,6 +1693,7 @@ static int filterCallback(void* world, void* island1, void* island2) {
 			valid = valid && (ob1->rigidbody_object->flag & RBO_FLAG_USE_KINEMATIC_DEACTIVATION);
 			valid = valid && (ob2->rigidbody_object->flag & RBO_FLAG_USE_KINEMATIC_DEACTIVATION);
 
+			valid2 = valid2 && (fmd1 != NULL);
 			valid2 = valid2 && (fmd1->use_constraints == false);
 
 			if (valid || valid2)
@@ -1706,6 +1738,7 @@ static int filterCallback(void* world, void* island1, void* island2) {
 			valid = valid && (ob2->rigidbody_object->flag & RBO_FLAG_USE_KINEMATIC_DEACTIVATION);
 			valid = valid && (ob1->rigidbody_object->flag & RBO_FLAG_USE_KINEMATIC_DEACTIVATION);
 
+			valid2 = valid2 && (fmd2 != NULL);
 			valid2 = valid2 && (fmd2->use_constraints == false);
 
 			if (valid || valid2)
@@ -3176,17 +3209,19 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 		return;
 	else if ((rbw->objects == NULL) || (rbw->cache_index_map == NULL))
 		rigidbody_update_ob_array(rbw);
-	
+
 	/* try to read from cache */
 	// RB_TODO deal with interpolated, old and baked results
 	if (BKE_ptcache_read(&pid, ctime)) {
 		BKE_ptcache_validate(cache, (int)ctime);
+
 		rbw->ltime = ctime;
 		return;
 	}
 	else if (rbw->ltime == startframe)
 	{
 		restoreKinematic(rbw);
+		rigidbody_update_simulation(scene, rbw, true);
 	}
 
 	/* advance simulation, we can only step one frame forward */




More information about the Bf-blender-cvs mailing list