[Bf-blender-cvs] [50a9322eebb] temp-fracture-modifier-2.8: fix attempt for dynamic fracture

Martin Felke noreply at git.blender.org
Mon Nov 19 13:44:48 CET 2018


Commit: 50a9322eebbab8186d19443a7cc6624d1a5e0510
Author: Martin Felke
Date:   Mon Nov 19 13:44:11 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB50a9322eebbab8186d19443a7cc6624d1a5e0510

fix attempt for dynamic fracture

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

M	source/blender/blenkernel/BKE_fracture.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_prefractured.c
M	source/blender/blenkernel/intern/fracture_rigidbody.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesrna/intern/rna_fracture.c

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

diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index 4dc787385a9..e6c933c0f09 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -105,7 +105,6 @@ void BKE_fracture_do(struct FractureModifierData *fmd, struct MeshIsland *mi, st
 
 void BKE_fracture_animated_loc_rot(struct FractureModifierData *fmd, struct Object *ob, bool do_bind, struct Depsgraph *depsgraph);
 
-
 void BKE_fracture_constraints_refresh(struct FractureModifierData *fmd, struct Object *ob, struct Scene* scene);
 
 
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 21e658702ae..4ff170060f5 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1270,15 +1270,16 @@ void BKE_fracture_clear_cache(FractureModifierData* fmd, Object* ob, Scene *scen
 
 	mi = fmd->shared->mesh_islands.first;
 	while (mi) {
-		if (mi->startframe > startframe ||
-			(!fmd->use_dynamic && mi->id == 0) ||
-			(fmd->use_dynamic && mi->id > 0)) {
+		if ((!fmd->use_dynamic && mi->id == 0) ||
+			(fmd->use_dynamic && mi->id > 0))
+		{
 			next = mi->next;
 			BLI_remlink(&fmd->shared->mesh_islands, mi);
 			BKE_fracture_mesh_island_free(mi, scene);
 			mi = next;
 		}
 		else {
+			/* happens after shard gets created */
 			mi->endframe = endframe;
 			MEM_freeN(mi->locs);
 			MEM_freeN(mi->rots);
@@ -1579,6 +1580,8 @@ void BKE_fracture_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool d
 	float anim_imat[4][4], imat[4][4];
 	Object *ob_eval;
 	bool mesh_free = false;
+	Scene* scene= DEG_get_input_scene(depsgraph);
+	int frame = (int)DEG_get_ctime(depsgraph);
 
 	if (!fmd->anim_mesh_ob)
 		return;
@@ -1770,11 +1773,11 @@ void BKE_fracture_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool d
 			}
 
 			//only let kinematic rbs do this, active ones are being taken care of by bullet
-			if (mi && mi->rigidbody && (mi->rigidbody->flag & RBO_FLAG_KINEMATIC))
+			if (mi && mi->rigidbody && (mi->rigidbody->flag & RBO_FLAG_KINEMATIC_BOUND))
 			{
 				//the 4 rot layers *should* be aligned, caller needs to ensure !
 				bool quats = quatX && quatY && quatZ && quatW;
-				float quat[4], vec[3], no[3], off[3];
+				float quat[4], vec[3], no[3], off[3], size[3] = {1, 1, 1};
 				int v = fmd->shared->anim_bind[i].v;
 				unit_qt(quat);
 
@@ -1841,6 +1844,7 @@ void BKE_fracture_animated_loc_rot(FractureModifierData *fmd, Object *ob, bool d
 				}
 
 				mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
+				BKE_rigidbody_shard_validate(scene->rigidbody_world, mi, ob, fmd, false, true, size, frame);
 				if (mi->rigidbody->shared->physics_object)
 				{
 					RB_body_set_loc_rot(mi->rigidbody->shared->physics_object, mi->rigidbody->pos, mi->rigidbody->orn);
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index f587dfda0ba..174968c1e0e 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -186,6 +186,17 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
 		fmd->shared->refresh_autohide = true;
 	}
 
+	//if (scene->rigidbody_world)
+	//	BKE_rigidbody_modifier_update(scene, ob, scene->rigidbody_world, false, depsgraph);
+
+	if (fmd->use_animated_mesh && fmd->anim_mesh_ob)
+	{
+		/*update bound island positions to follow bind object, after physics ran */
+		BKE_fracture_animated_loc_rot(fmd, ob, false, depsgraph);
+	}
+
+	//BKE_rigidbody_modifier_sync((ModifierData*)fmd, ob, scene, ctime);
+
 	/* assemble mesh from transformed meshislands */
 	if (fmd->shared->mesh_islands.first)
 	{
diff --git a/source/blender/blenkernel/intern/fracture_rigidbody.c b/source/blender/blenkernel/intern/fracture_rigidbody.c
index 8c12a25d12a..9c4cb73bee9 100644
--- a/source/blender/blenkernel/intern/fracture_rigidbody.c
+++ b/source/blender/blenkernel/intern/fracture_rigidbody.c
@@ -586,6 +586,10 @@ void BKE_rigidbody_validate_sim_shard(RigidBodyWorld *rbw, MeshIsland *mi, Objec
 	if (rbo == NULL)
 		return;
 
+	if (!rbw || !rbw->shared || !rbw->shared->physics_world) {
+		return;
+	}
+
 	/* at validation, reset frame count as well */
 
 	/* make sure collision shape exists */
@@ -1068,6 +1072,11 @@ static bool do_activate(Object* ob, Object *ob2, MeshIsland *mi_compare, RigidBo
 	valid = valid && ((ob2->rigidbody_object->flag & RBO_FLAG_IS_TRIGGER) || ((ob2->rigidbody_object->flag & RBO_FLAG_PROPAGATE_TRIGGER) &&
 			((mi_trigger) && (mi_trigger->rigidbody->flag & RBO_FLAG_PROPAGATE_TRIGGER))));
 
+	/*prefer dynamic trigger over trigger, and allow activation after queue is empty only (everything fractured) */
+	if (mi_trigger && mi_trigger->rigidbody->flag & RBO_FLAG_DYNAMIC_TRIGGER) {
+		valid = valid && BLI_listbase_is_empty(&fmd->shared->fracture_ids);
+	}
+
 	if (valid || antiValid)
 	{
 		for (mi = fmd->shared->mesh_islands.first; mi; mi = mi->next)
@@ -2037,6 +2046,7 @@ bool BKE_rigidbody_modifier_update(Scene* scene, Object* ob, RigidBodyWorld *rbw
 		BKE_object_where_is_calc(depsgraph, scene, ob);
 		fmd->constraint_island_count = 1;
 
+#if 0
 		if ((ob->rigidbody_object && (ob->rigidbody_object->flag & RBO_FLAG_KINEMATIC) //&&
 			 /*fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED*/)) {
 
@@ -2045,6 +2055,7 @@ bool BKE_rigidbody_modifier_update(Scene* scene, Object* ob, RigidBodyWorld *rbw
 				BKE_fracture_animated_loc_rot(fmd, ob, false, depsgraph);
 			}
 		}
+#endif
 
 		for (mi = fmd->shared->mesh_islands.first; mi; mi = mi->next) {
 			if (mi->rigidbody == NULL) {
@@ -2313,7 +2324,7 @@ bool BKE_rigidbody_modifier_sync(ModifierData *md, Object *ob, Scene *scene, flo
 						break;
 				}
 				/* otherwise set rigid body transform to current obmat*/
-				else // if (!(ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ))
+				else if (!(ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ))
 				{
 					mat4_to_loc_quat(rbo->pos, rbo->orn, ob->obmat);
 					mat4_to_size(size, ob->obmat);
@@ -2413,6 +2424,10 @@ bool BKE_restoreKinematic(RigidBodyWorld *rbw, bool override_bind)
 						}
 						else
 						{
+							if (fmd->use_animated_mesh) {
+								mi->rigidbody->flag |= RBO_FLAG_KINEMATIC_BOUND;
+							}
+
 							//might happen if being hit by a stop trigger, remove kinematic here in this case
 							mi->rigidbody->flag &= ~RBO_FLAG_KINEMATIC;
 						}
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index a84b0db4aa1..4b9e043e210 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1097,6 +1097,10 @@ void BKE_rigidbody_world_id_loop(RigidBodyWorld *rbw, RigidbodyWorldIDFunc func,
 	if (rbw->objects) {
 		int i;
 		int count = BLI_listbase_count(&rbw->group->gobject);
+		if (count != rbw->numbodies) {
+			rigidbody_update_ob_array(rbw);
+		}
+
 		for (i = 0; i < count; i++) {
 			func(rbw, (ID **)&rbw->objects[i], userdata, IDWALK_CB_NOP);
 		}
@@ -1639,7 +1643,7 @@ void BKE_rigidbody_update_simulation(Scene *scene, RigidBodyWorld *rbw, bool reb
 			did_modifier = BKE_rigidbody_modifier_update(scene, ob, rbw, rebuild, depsgraph);
 		}
 
-		if (!did_modifier && ob->type == OB_MESH) {
+		if ((!did_modifier) && (ob->type == OB_MESH)) {
 			/* validate that we've got valid object set up here... */
 			RigidBodyOb *rbo = ob->rigidbody_object;
 			/* update transformation matrix of the object so we don't get a frame of lag for simple animations */
@@ -1774,7 +1778,7 @@ static void rigidbody_update_simulation_post_step(Depsgraph* depsgraph, RigidBod
 						rbo = mi->rigidbody;
 						if (!rbo) continue;
 						/* reset kinematic state for transformed objects */
-						if (rbo->shared->physics_object && ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) {
+						if (rbo->shared->physics_object && (ob->flag & SELECT) && (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));
@@ -2017,16 +2021,17 @@ void BKE_rigidbody_cache_reset(Scene* scene)
 
 		if (rbw) {
 			rbw->shared->pointcache->flag |= PTCACHE_OUTDATED;
-			if (rbw->objects) {
-				for (i = 0; i < rbw->numbodies; i++) {
-					ob = rbw->objects[i];
-					if (ob) {
+			if (rbw->group) {
+				FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, ob)
+				{
+					if (ob && ob->rigidbody_object) {
 						fmd = (FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
 						if (fmd) {
 							BKE_fracture_clear_cache(fmd, ob, scene);
 						}
 					}
 				}
+				FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
 			}
 		}
 	}
@@ -2041,31 +2046,22 @@ void BKE_rigidbody_rebuild_world(Depsgraph *depsgraph, Scene *scene, float ctime
 	RigidBodyWorld *rbw = scene->rigidbody_world;
 	PointCache *cache;
 	PTCacheID pid;
-	int startframe, endframe;
+	int startframe, endframe, frame = (int)ctime;
 	int shards = 0, objects = 0;
 
 	BKE_ptcache_id_from_rigidbody(&pid, NULL, rbw);
 	BKE_ptcache_id_time(&pid, scene, ctime, &startframe, &endframe, NULL);
 	cache = rbw->shared->pointcache;
 
-	/* flag cache as outdated if we don't have a world or
-	 * number of objects in the simulation has changed */
+	/* flag cache as outdated if we don't have a world and the cache is not baked */
 
-	//rigidbody_group_count_items(&rbw->group->gobject, &shards, &objects);
-	if (rbw->shared->physics_world == NULL /*|| rbw->numbodies != (shards + objects)*/) {
+	if (rbw->shared->physics_world == NULL && !(cache->flag & PTCACHE_BAKED)) {
 		cache->flag |= PTCACHE_OUTDATED;
 	}
 
-	if (ctime == startframe + 1 && rbw->ltime == startframe)
+	if (frame == startframe + 1 && rbw->ltime == startframe)
 	{
 		if (cache->flag & PTCACHE_OUTDATED) {
-
-			//if we destroy the cache, also reset dynamic data (if not baked)
-			if (!(cache->flag & PTCACHE_BAKED))
-			{
-				//resetDynamic(rbw, true, false);
-			}
-
 			BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
 			BKE_rigidbody_update_simul

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list