[Bf-blender-cvs] [b389f1e9572] interactive_physics: Fix bug with transformed object interfering with rigid body simulation.

Benoit Bolsee noreply at git.blender.org
Thu Oct 11 10:20:54 CEST 2018


Commit: b389f1e9572b9ee606c2e4ae347f5520f2d38a9c
Author: Benoit Bolsee
Date:   Wed Oct 10 18:13:34 2018 +0200
Branches: interactive_physics
https://developer.blender.org/rBb389f1e9572b9ee606c2e4ae347f5520f2d38a9c

Fix bug with transformed object interfering with rigid body simulation.

Note: bug was caused by use of legacy ob->flag & SELECT. New OB_PHYS_MOVING
      flag to mark that an active object is being transformed.

Make active object position update independent of cache write in preparation
of interactive physics.

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

M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/makesdna/DNA_object_types.h
M	source/tools

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

diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 8f8926545c6..f5ea13e1bd2 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1295,8 +1295,11 @@ static int  ptcache_rigidbody_write(int index, void *rb_v, void **data, int UNUS
 
 		if (rbo->type == RBO_TYPE_ACTIVE) {
 #ifdef WITH_BULLET
-			RB_body_get_position(rbo->shared->physics_object, rbo->pos);
-			RB_body_get_orientation(rbo->shared->physics_object, rbo->orn);
+			/* retrieving physics sim position should not be dependent on caching,
+			 * moved to rigidbody_update_simulation_post_step()
+			 */
+			/*RB_body_get_position(rbo->shared->physics_object, rbo->pos);*/
+			/*RB_body_get_orientation(rbo->shared->physics_object, rbo->orn);*/
 #endif
 			PTCACHE_DATA_FROM(data, BPHYS_DATA_LOCATION, rbo->pos);
 			PTCACHE_DATA_FROM(data, BPHYS_DATA_ROTATION, rbo->orn);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 3f9f6f15892..95b558f5b43 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1313,13 +1313,13 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Scene *scene, RigidBod
 		RB_shape_set_margin(rbo->shared->physics_shape, RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2]));
 
 	/* make transformed objects temporarily kinmatic so that they can be moved by the user during simulation */
-	if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) {
+	if (ob->transflag & OB_PHYS_MOVING) {
 		RB_body_set_kinematic_state(rbo->shared->physics_object, true);
 		RB_body_set_mass(rbo->shared->physics_object, 0.0f);
 	}
 
 	/* update rigid body location and rotation for kinematic bodies */
-	if (rbo->flag & RBO_FLAG_KINEMATIC || (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) {
+	if (rbo->flag & RBO_FLAG_KINEMATIC || (ob->transflag & OB_PHYS_MOVING)) {
 		RB_body_activate(rbo->shared->physics_object);
 		RB_body_set_loc_rot(rbo->shared->physics_object, loc, rot);
 	}
@@ -1484,19 +1484,22 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, Scene *scene, Rigi
 
 static void rigidbody_update_simulation_post_step(Depsgraph *depsgraph, RigidBodyWorld *rbw)
 {
-	ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
-
 	FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, ob)
 	{
-		Base *base = BKE_view_layer_base_find(view_layer, ob);
 		RigidBodyOb *rbo = ob->rigidbody_object;
 		/* Reset kinematic state for transformed objects. */
-		if (rbo && base && (base->flag & BASE_SELECTED) && (G.moving & G_TRANSFORM_OBJ)) {
-			RB_body_set_kinematic_state(rbo->shared->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
-			RB_body_set_mass(rbo->shared->physics_object, RBO_GET_MASS(rbo));
-			/* Deactivate passive objects so they don't interfere with deactivation of active objects. */
-			if (rbo->type == RBO_TYPE_PASSIVE)
-				RB_body_deactivate(rbo->shared->physics_object);
+		if (rbo) {
+			if (ob->transflag & OB_PHYS_MOVING) {
+				RB_body_set_kinematic_state(rbo->shared->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
+				RB_body_set_mass(rbo->shared->physics_object, RBO_GET_MASS(rbo));
+				/* Deactivate passive objects so they don't interfere with deactivation of active objects. */
+				if (rbo->type == RBO_TYPE_PASSIVE)
+					RB_body_deactivate(rbo->shared->physics_object);
+			}
+			else if (rbo->type == RBO_TYPE_ACTIVE) {
+				RB_body_get_position(rbo->shared->physics_object, rbo->pos);
+				RB_body_get_orientation(rbo->shared->physics_object, rbo->orn);
+			}
 		}
 	}
 	FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
@@ -1517,7 +1520,7 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
 		return;
 
 	/* use rigid body transform after cache start frame if objects is not being transformed */
-	if (BKE_rigidbody_check_sim_running(rbw, ctime) && !(ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) {
+	if (BKE_rigidbody_check_sim_running(rbw, ctime) && !(ob->transflag & OB_PHYS_MOVING)) {
 		float mat[4][4], size_mat[4][4], size[3];
 
 		normalize_qt(rbo->orn); // RB_TODO investigate why quaternion isn't normalized at this point
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 571608ac21d..4b754907a5b 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -5650,7 +5650,8 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
 
 		/* only use rigid body transform if simulation is running, avoids problems with initial setup of rigid bodies */
 		if (BKE_rigidbody_check_sim_running(scene->rigidbody_world, ctime)) {
-
+			/* remember that this object is moving to make it static in simulation */
+			ob->transflag |= OB_PHYS_MOVING;
 			/* save original object transform */
 			copy_v3_v3(td->ext->oloc, ob->loc);
 
@@ -6784,6 +6785,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
 			ListBase pidlist;
 			PTCacheID *pid;
 			ob = td->ob;
+			/* reset this temp flag when the transformation ends */
+			ob->transflag &= ~OB_PHYS_MOVING;
 
 			if (td->flag & TD_NOACTION)
 				break;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index b988ca9801a..bf45613d42c 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -419,6 +419,7 @@ enum {
 	OB_RENDER_DUPLI     = 1 << 12,
 	OB_NO_CONSTRAINTS   = 1 << 13,  /* runtime constraints disable */
 	OB_NO_PSYS_UPDATE   = 1 << 14,  /* hack to work around particle issue */
+	OB_PHYS_MOVING      = 1 << 15,  /* hack to set object static when moving by transform */
 
 	OB_DUPLI            = OB_DUPLIFRAMES | OB_DUPLIVERTS | OB_DUPLICOLLECTION | OB_DUPLIFACES | OB_DUPLIPARTS,
 };
diff --git a/source/tools b/source/tools
index 11656ebaf7f..870f46b6e3a 160000
--- a/source/tools
+++ b/source/tools
@@ -1 +1 @@
-Subproject commit 11656ebaf7f912cdb1b5eb39c5d0a3b5d492c1aa
+Subproject commit 870f46b6e3abe03c0b9907d08f79af47f4b58ee8



More information about the Bf-blender-cvs mailing list