[Bf-blender-cvs] [d1b934d] temp_bullet_ghosts: Extension of the C-API for Bullet in Blender, to enable customized collision detection outside of rigid body dynamics.

Lukas Tönne noreply at git.blender.org
Wed Apr 29 09:08:11 CEST 2015


Commit: d1b934d81b9f827dcb67c3d8107f6e143c91a3ca
Author: Lukas Tönne
Date:   Sat Feb 28 14:44:51 2015 +0100
Branches: temp_bullet_ghosts
https://developer.blender.org/rBd1b934d81b9f827dcb67c3d8107f6e143c91a3ca

Extension of the C-API for Bullet in Blender, to enable customized
collision detection outside of rigid body dynamics.

These extensions consist of a few major changes:
* Support for "btGhost" objects.

  These are Bullet collision objects, but not rigid bodies. They can be
  added to a btCollisionWorld, or they can be used for immediate
  individual collision detection. Ghost objects don't have any effect on
  rigid bodies or other collision objects.

  Ghost objects are "one-way" colliders: they register contacts with
  actual collision objects, but don't themselves generate contacts in
  other bodies. This makes them useful for accessing Bullet's advanced
  contact generation algorithms in simulation systems that don't
  actually interact with rigid bodies (e.g. hair or cloth).

* Better low-level access to collision shapes.

  Collision shapes can now be allocated outside of the API using static
  size variables. This allows more efficient allocation schemes, such
  as bulk array allocation and mempools/memarenas. The Bullet engine
  itself expects callers to allocate and manage class instances in fact,
  but due to the optional linking with Bullet and the differences
  between C/C++ the allocation was left to single collision shape
  instances so far.

* Compound shapes can now be constructed explicitly as well. Previously
  only the primitive shapes were supported, with compounds limited to
  special cases.

* Contact callback functions (contact and proximity tests) can now do
  complete reports of all manifold contact points.

Taken together, these API improvements will open up Bullet to a wider
range of features inside Blender, for rigid body simulations as well as
other uses.

Differential Revision: https://developer.blender.org/D1268

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

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 7ab63c4..c4311d1 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -220,7 +220,7 @@ void RB_body_set_linear_factor(rbRigidBody *object, float x, float y, float z);
 void RB_body_set_angular_factor(rbRigidBody *object, float x, float y, float z);
 
 /* Kinematic State */
-void RB_body_set_kinematic_state(rbRigidBody *body, int kinematic);
+void RB_body_set_kinematic_state(rbRigidBody *body, bool kinematic);
 
 /* RigidBody Interface - Rigid Body Activation States */
 int RB_body_get_activation_state(rbRigidBody *body);
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 806e912..7b7946a 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -766,7 +766,7 @@ void RB_body_set_angular_factor(rbRigidBody *object, float x, float y, float z)
 
 /* ............ */
 
-void RB_body_set_kinematic_state(rbRigidBody *object, int kinematic)
+void RB_body_set_kinematic_state(rbRigidBody *object, bool kinematic)
 {
 	btRigidBody *body = object->body;
 	if (kinematic)
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 191f718..9d7cea8 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1302,8 +1302,9 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
  * Updates and validates rigid body objects.
  *
  * \param rebuild Rebuild entire simulation
+ * \param all_kinematic If true all bodies will be kinematic and not collide or react
  */
-static int rigidbody_update_objects(Scene *scene, RigidBodyWorld *rbw, bool rebuild)
+static int rigidbody_update_objects(Scene *scene, RigidBodyWorld *rbw, bool rebuild, bool all_kinematic)
 {
 	int result = 0;
 	GroupObject *go;
@@ -1372,10 +1373,15 @@ static int rigidbody_update_objects(Scene *scene, RigidBodyWorld *rbw, bool rebu
 			/* update simulation object... */
 			rigidbody_update_sim_ob(scene, rbw, ob, rbo);
 
-			/* XXX could avoid some unnecessary updates with lower-level testing,
-			 * but this is safer for now.
-			 */
-			result |= RB_STEP_DYNAMICS;
+			if (all_kinematic) {
+				RB_body_set_kinematic_state(rbo->physics_object, true);
+			}
+			else {
+				/* XXX could avoid some unnecessary updates with lower-level testing,
+				 * but this is safer for now.
+				 */
+				result |= RB_STEP_DYNAMICS;
+			}
 		}
 	}
 	
@@ -1551,11 +1557,13 @@ void BKE_rigidbody_rebuild_world(Scene *scene, float ctime)
 		
 		if (cache->flag & PTCACHE_OUTDATED) {
 			BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
-			rigidbody_update_objects(scene, rbw, true);
+			rigidbody_update_objects(scene, rbw, true, false);
 			BKE_ptcache_validate(cache, (int)ctime);
 			cache->last_exact = 0;
 			cache->flag &= ~PTCACHE_REDO_NEEDED;
 		}
+		else
+			rigidbody_update_objects(scene, rbw, true, true);
 		
 		rigidbody_update_ghosts(scene, rbw, true);
 	}
@@ -1568,7 +1576,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 	PointCache *cache;
 	PTCacheID pid;
 	int startframe, endframe;
-	bool cache_baked, cache_valid;
+	bool has_cache;
 
 	BKE_ptcache_id_from_rigidbody(&pid, NULL, rbw);
 	BKE_ptcache_id_time(&pid, scene, ctime, &startframe, &endframe, NULL);
@@ -1589,14 +1597,18 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 	else if (rbw->objects == NULL)
 		rigidbody_update_ob_array(rbw);
 
-	cache_baked = (cache->flag & PTCACHE_BAKED);
-
-	/* try to read from cache */
-	// RB_TODO deal with interpolated, old and baked results
-	cache_valid = BKE_ptcache_read(&pid, ctime);
-	if (cache_valid) {
-		BKE_ptcache_validate(cache, (int)ctime);
-		rbw->ltime = ctime;
+	{
+		bool cache_baked = (cache->flag & PTCACHE_BAKED);
+		/* try to read from cache */
+		// RB_TODO deal with interpolated, old and baked results
+		bool cache_valid = BKE_ptcache_read(&pid, ctime);
+		
+		if (cache_valid) {
+			BKE_ptcache_validate(cache, (int)ctime);
+			rbw->ltime = ctime;
+		}
+		
+		has_cache = cache_valid || cache_baked;
 	}
 
 	/* advance simulation, we can only step one frame forward */
@@ -1606,16 +1618,16 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 		
 		stepmode |= rigidbody_update_scene(scene, rbw, false);
 		
-		if (!cache_baked && !cache_valid) {
+		if (!has_cache) {
 			/* write cache for first frame when on second frame */
 			if (rbw->ltime == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
 				BKE_ptcache_write(&pid, startframe);
 			}
-			
-			/* update and validate simulation */
-			stepmode |= rigidbody_update_objects(scene, rbw, false);
 		}
 		
+		/* update and validate simulation, only do kinematics if cached */
+		stepmode |= rigidbody_update_objects(scene, rbw, false, has_cache);
+		
 		/* ghosts are not included in the rigidbody point cache */
 		stepmode |= rigidbody_update_ghosts(scene, rbw, false);
 		
@@ -1626,7 +1638,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 			/* step simulation by the requested timestep, steps per second are adjusted to take time scale into account */
 			RB_dworld_step_simulation(rbw->physics_world, timestep, INT_MAX, timesubstep);
 			
-			if (!cache_baked && !cache_valid) {
+			if (!has_cache) {
 				rigidbody_update_objects_post_step(rbw);
 				
 				/* write cache for current frame */




More information about the Bf-blender-cvs mailing list