[Bf-blender-cvs] [785ac13] fracture_modifier: partial solution for FM autoexecute, auto disables when sim runs and is enabled again on startframe

Martin Felke noreply at git.blender.org
Thu Jun 2 10:49:07 CEST 2016


Commit: 785ac13c394f995e5e5256c54ebbf0575064d4ac
Author: Martin Felke
Date:   Thu Jun 2 10:48:29 2016 +0200
Branches: fracture_modifier
https://developer.blender.org/rB785ac13c394f995e5e5256c54ebbf0575064d4ac

partial solution for FM autoexecute, auto disables when sim runs and is enabled again on startframe

note: cache will always be overwritten in autoexec sim mode, because keeping it may lead to incorrect sim results
furthermore a couple of changes for external mode (attempt to be more BCB compatible)

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index c9a02c8..1c80164 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -2202,7 +2202,7 @@ static Shard* fracture_object_to_shard( Object *own, Object* target)
 	MPoly* mpoly;
 	MLoop* mloop;
 	SpaceTransform trans;
-	float mat[4][4], size[3];
+	float mat[4][4], size[3] = {1.0f, 1.0f, 1.0f};
 
 	int totvert, totpoly, totloop, v;
 	bool do_free = false;
@@ -2237,7 +2237,7 @@ static Shard* fracture_object_to_shard( Object *own, Object* target)
 
 	for (v = 0, mv = s->mvert; v < s->totvert; v++, mv++)
 	{
-		mul_v3_v3(mv->co, size);
+		//mul_v3_v3(mv->co, size);
 
 		//shrink the shard ? (and take centroid diff into account here, too)
 		BLI_space_transform_apply(&trans, mv->co);
@@ -2246,7 +2246,7 @@ static Shard* fracture_object_to_shard( Object *own, Object* target)
 		//sub_v3_v3(mv->co, s->raw_centroid);
 	}
 
-	//BLI_space_transform_apply(&trans, s->raw_centroid);
+//	BLI_space_transform_apply(&trans, s->raw_centroid);
 	BLI_space_transform_apply(&trans, s->centroid);
 
 	s = BKE_custom_data_to_shard(s, dm);
@@ -2317,8 +2317,10 @@ static MeshIsland* fracture_shard_to_island(FractureModifierData *fmd, Shard *s,
 	mi->locs = MEM_mallocN(sizeof(float)*3, "mi->locs");
 	mi->rots = MEM_mallocN(sizeof(float)*4, "mi->rots");
 	mi->frame_count = 0;
-	if (fmd->modifier.scene->rigidbody_world)
+	if (fmd->modifier.scene && fmd->modifier.scene->rigidbody_world)
 	{
+		/*modifier might have no linked scene yet after creation on an inactive layer */
+		/*so just try a fallback here */
 		mi->start_frame = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
 	}
 	else
@@ -2393,7 +2395,7 @@ int BKE_fracture_update_visual_mesh(FractureModifierData *fmd, Object *ob, bool
 	//update existing island's vert refs, if any...should have used indexes instead :S
 	for (mi = fmd->meshIslands.first; mi; mi = mi->next)
 	{
-		//MVert *pvert = mi->physics_mesh->getVertArray(mi->physics_mesh);
+		MVert *pvert = mi->physics_mesh->getVertArray(mi->physics_mesh);
 		float inv_size[3] = {1.0f, 1.0f, 1.0f};
 		Shard *s = BLI_findlink(&fmd->frac_mesh->shard_map, mi->id);
 		if (!s)
@@ -2406,7 +2408,7 @@ int BKE_fracture_update_visual_mesh(FractureModifierData *fmd, Object *ob, bool
 		for (i = 0; i < mi->vertex_count; i++)
 		{
 			//just update pointers, dont need to reallocate something
-			MVert *v = NULL;
+			MVert *v = NULL, *pv = NULL;
 			int index;
 
 			//also correct indexes
@@ -2421,6 +2423,9 @@ int BKE_fracture_update_visual_mesh(FractureModifierData *fmd, Object *ob, bool
 			v = mv + index;
 			mi->vertices_cached[i] = v;
 
+			pv = pvert + i;
+			mul_v3_v3(pv->co, inv_size);
+
 			//transform vertex properly ? compensate for shrunken shard ?
 			//sub_v3_v3v3(loc, mi->centroid, s->raw_centroid);
 			//loc_quat_size_to_mat4(mat, loc , rot, s->impact_size);
@@ -2783,6 +2788,21 @@ RigidBodyShardCon *BKE_fracture_mesh_islands_connect(FractureModifierData *fmd,
 	rbsc->mi1 = mi1;
 	rbsc->mi2 = mi2;
 
+	if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+	{
+		/* disable breaking flag here by default, only enable later via python if necessary */
+		rbsc->flag &= ~RBC_FLAG_USE_BREAKING;
+
+		/* also delete all other "default" flags here, let them being overriden from python too */
+		rbsc->flag &= ~RBC_FLAG_ENABLED;
+		rbsc->flag &= ~RBC_FLAG_DISABLE_COLLISIONS;
+
+#if 0
+		/* and dont allow to let constrained objects collide per default, as with regular constraints */
+		rbsc->flag |= RBC_FLAG_DISABLE_COLLISIONS;
+#endif
+	}
+
 	/* moved default meshconstraint pos calculation here to creation, so you can override it later on*/
 	/* do this for all constraints */
 	/* location for fixed constraints doesnt matter, so keep old setting */
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index e003d9e..ac42878 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1945,20 +1945,18 @@ static int filterCallback(void* world, void* island1, void* island2, void *blend
 	mi1 = (MeshIsland*)island1;
 	mi2 = (MeshIsland*)island2;
 
-#if 0
 	FractureModifierData *fmd1 = (FractureModifierData*)modifiers_findByType((Object*)blenderOb1, eModifierType_Fracture);
 	FractureModifierData *fmd2 = (FractureModifierData*)modifiers_findByType((Object*)blenderOb2, eModifierType_Fracture);
 
-	if ((fmd1 && fmd1->fracture_mode == MOD_FRACTURE_DYNAMIC) ||
-	   (fmd2 && fmd2->fracture_mode == MOD_FRACTURE_DYNAMIC))
+	if ((fmd1 && fmd1->fracture_mode == MOD_FRACTURE_EXTERNAL) ||
+	   (fmd2 && fmd2->fracture_mode == MOD_FRACTURE_EXTERNAL))
 	{
-		/*dynamic doesnt need triggering, maybe the prefractured object... later TODO */
-		/* XXXX remove this in case of dynamic, it interferes */
+		/*external doesnt need triggering, maybe the prefractured object (and dynamic ?)... later TODO */
+		/* XXXX remove this in case of external, it interferes */
 		ob1 = blenderOb1;
 		ob2 = blenderOb2;
 		return check_colgroup_ghost(ob1, ob2);
 	}
-#endif
 
 	if (rbw == NULL)
 	{
@@ -2705,11 +2703,17 @@ void BKE_rigidbody_remove_shard(Scene *scene, MeshIsland *mi)
 		/* need to check whether we didnt create the rigidbody world manually already, prior to fracture, in this
 		 * case cache_index_map might be not initialized ! checking numbodies here, they should be 0 in a fresh
 		 * rigidbody world */
-
+#if 0
 		if ((rbw->cache_index_map != NULL) && (rbw->numbodies > 0) && mi->linear_index < rbw->numbodies) {
 			//mi->rigidbody = NULL;
 			rbw->cache_index_map[mi->linear_index] = NULL;
 		}
+#endif
+
+		if (rbw->cache_index_map != NULL) {
+			MEM_freeN(rbw->cache_index_map);
+			rbw->cache_index_map = NULL;
+		}
 
 		//BKE_rigidbody_update_ob_array(rbw);
 	}
@@ -2749,10 +2753,16 @@ static bool do_remove_modifier(RigidBodyWorld* rbw, ModifierData *md)
 				}
 
 				/* this SHOULD be the correct global index*/
-				if ((rbw->cache_index_map != NULL) && (rbw->numbodies > 0))
+				/*if ((rbw->cache_index_map != NULL) && (rbw->numbodies > 0))
 				{
 					rbw->cache_index_map[mi->linear_index] = NULL;
+				}*/
+
+				if (rbw->cache_index_map != NULL) {
+					MEM_freeN(rbw->cache_index_map);
+					rbw->cache_index_map = NULL;
 				}
+
 				MEM_freeN(mi->rigidbody);
 				mi->rigidbody = NULL;
 			}
@@ -2790,9 +2800,13 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob)
 						rbw->objects[index] = NULL;
 					}
 					
-					if (rbo == rbw->cache_index_map[i]) {
+					/*if (rbo == rbw->cache_index_map[i]) {
 						rbw->cache_index_map[i] = NULL;
 						break;
+					}*/
+					if (rbw->cache_index_map != NULL) {
+						MEM_freeN(rbw->cache_index_map);
+						rbw->cache_index_map = NULL;
 					}
 				}
 			}
@@ -3349,6 +3363,14 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc, RigidBodyWorld* rbw
 	{
 		float step_ratio = (float)rbw->steps_per_second / (float)laststeps;
 		float time_ratio = lastscale / rbw->time_scale;
+
+		/*in case of generic without linear locks, ignore time ratio*/
+		if ((rbsc->type == RBC_TYPE_6DOF || rbsc->type == RBC_TYPE_6DOF_SPRING) &&
+		    ((rbsc->flag & (RBC_FLAG_USE_LIMIT_LIN_X | RBC_FLAG_USE_LIMIT_LIN_Y | RBC_FLAG_USE_LIMIT_LIN_Z)) == 0))
+		{
+			time_ratio = 1.0f;
+		}
+
 		RB_constraint_set_breaking_threshold(rbsc->physics_constraint, (rbsc->breaking_threshold / step_ratio) * time_ratio);
 	}
 
@@ -3363,8 +3385,8 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc, RigidBodyWorld* rbw
 
 	//printf("Dist, Angle: %f %f %f %f %f %f\n", rbsc->start_dist, rbsc->start_angle, dist, angle, distdiff, anglediff);
 
-	exceededAngle = ((rbsc->breaking_angle >= 0.0f) && (anglediff > rbsc->breaking_angle));
-	exceededDist = ((rbsc->breaking_dist >= 0.0f) && (distdiff > (rbsc->breaking_dist + (anglediff / M_PI))));
+	exceededAngle = ((rbsc->breaking_angle > 0.0f) && (anglediff > rbsc->breaking_angle));
+	exceededDist = ((rbsc->breaking_dist > 0.0f) && (distdiff > (rbsc->breaking_dist + (anglediff / M_PI))));
 
 	if (exceededDist || exceededAngle) //|| regularBroken)
 	{
@@ -3379,8 +3401,8 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc, RigidBodyWorld* rbw
 		}
 	}
 
-	exceededAngle = ((rbsc->plastic_angle >= 0.0f) && (anglediff > rbsc->plastic_angle));
-	exceededDist = ((rbsc->plastic_dist >= 0.0f) && (distdiff > (rbsc->plastic_dist + (anglediff / M_PI))));
+	exceededAngle = ((rbsc->plastic_angle > 0.0f) && (anglediff > rbsc->plastic_angle));
+	exceededDist = ((rbsc->plastic_dist > 0.0f) && (distdiff > (rbsc->plastic_dist + (anglediff / M_PI))));
 
 	/* break plastic connections */
 	if ((exceededDist || exceededAngle) /*&& !regularBroken*/)
@@ -3441,7 +3463,8 @@ static void handle_solver_iterations(RigidBodyWorld *rbw, FractureModifierData *
 		}
 	}
 
-	if (iterations > 0) {
+	/* dont automatically enable in External mode */
+	if ((iterations > 0) && (fmd->fracture_mode != MOD_FRACTURE_EXTERNAL)) {
 		rbsc->flag |= RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS;
 		rbsc->num_solver_iterations = iterations;
 	}
@@ -3475,8 +3498,8 @@ static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bo
 
 		if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
 		{
-			int frame = (int)BKE_scene_frame_get(scene);
-			if (BKE_lookup_mesh_state(fmd, frame, true))
+			int fr = (int)BKE_scene_frame_get(scene);
+			if (BKE_lookup_mesh_state(fmd, fr, true))
 			{
 				BKE_rigidbody_update_ob_array(rbw);
 			}
@@ -3532,7 +3555,8 @@ static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bo
 			if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
 			{
 				Shard *s = BLI_findlink(&fmd->frac_mesh->shard_map, mi->id);
-				copy_v3_v3(size, s->impact_size);
+				if (s)
+					copy_v3_v3(size, s->impact_size);
 			}
 
 			rigidbody_update_sim_ob(scene, rbw, ob, mi->rigidbody, mi->centroid, mi, size);
@@ -4319,6 +4343,7 @@ void BKE_rigidbody_rebuild_world(Scene *scene, float ctime)
 
 	if (ctime == -1)
 	{
+		/*hack to be able to update the simulation data after loading from FM*/
 		rigidbody_update_simulation(scene, rbw, true);
 		return;
 	}
@@ -4361,15 +4386,18 @@ void BKE_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list