[Bf-blender-cvs] [8e79bae] fracture_modifier: added names for meshislands, can now convert back to named objects, added load / save support (was missing)

Martin Felke noreply at git.blender.org
Fri Jan 22 00:00:42 CET 2016


Commit: 8e79bae2eb07422d7500d4e307f91643b74b278f
Author: Martin Felke
Date:   Fri Jan 22 00:00:29 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB8e79bae2eb07422d7500d4e307f91643b74b278f

added names for meshislands, can now convert back to named objects, added load / save support (was missing)

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

M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesdna/DNA_modifier_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 3ea1084..bc7bd0e 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -87,7 +87,9 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
         row.prop(md, "fracture_mode")
 
         if md.fracture_mode == 'EXTERNAL':
-           return
+            layout.context_pointer_set("modifier", md)
+            layout.operator("object.rigidbody_convert_to_objects", text = "Convert To Objects")
+            return
 
         if md.fracture_mode == 'DYNAMIC':
             layout.prop(md, "dynamic_force")
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d923438..1168466 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -53,6 +53,7 @@
 #include "BLI_mempool.h"
 #include "BLI_path_util.h"
 #include "BLI_rand.h"
+#include "BLI_string.h"
 #include "BLI_sort.h"
 #include "BLI_utildefines.h"
 
@@ -2455,6 +2456,8 @@ MeshIsland* BKE_fracture_mesh_island_add(FractureModifierData *fmd, Object* own,
 		copy_qt_qt(mi->rigidbody->orn, rot);
 	}
 
+	BLI_strncpy(mi->name, target->id.name + 2, MAX_ID_NAME - 2);
+
 	//handle materials
 	if (!fmd->material_index_map)
 	{
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 0bd83db..8664b6b 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1705,18 +1705,31 @@ static void rigidbody_create_shard_physics_constraint(FractureModifierData* fmd,
 			case RBC_TYPE_6DOF_SPRING:
 				rbc->physics_constraint = RB_constraint_new_6dof_spring(loc, rot, rb1, rb2);
 
-				if (rbc->flag & RBC_FLAG_USE_PLASTIC)
-				{	/* set to inactive plastic here, needs to be activated */
-					rbc->flag &= ~RBC_FLAG_PLASTIC_ACTIVE;
-					rigidbody_set_springs_active(rbc, false);
+				if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+				{
+					if ((rbc->plastic_angle < 0.0f) && (rbc->plastic_dist < 0.0f))
+					{
+						/* no plastic mode */
+						rigidbody_set_springs_active(rbc, true);
+					}
+					else
+					{
+						/*plastic mode, activate depending on flag */
+						rigidbody_set_springs_active(rbc, rbc->flag & RBC_FLAG_USE_PLASTIC);
+
+						/* mark immediate activation, so we dont activate again */
+						if (rbc->flag & RBC_FLAG_USE_PLASTIC)
+							rbc->flag |= RBC_FLAG_PLASTIC_ACTIVE;
+					}
 				}
 				else
 				{
-					/* not plastic springs, activate now */
+					/* no plastic mode available in other fracture modes */
 					rigidbody_set_springs_active(rbc, true);
-					RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint);
 				}
 
+				RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint);
+
 			/* fall through */
 			case RBC_TYPE_6DOF:
 				if (rbc->type == RBC_TYPE_6DOF)     /* a litte awkward but avoids duplicate code for limits */
@@ -3149,7 +3162,7 @@ static void handle_breaking_distance(FractureModifierData *fmd, Object *ob, Rigi
 static void handle_plastic_breaking(RigidBodyShardCon *rbsc)
 {
 	float dist, angle, distdiff, anglediff;
-	bool exceededAngle = false, exceededDist = false, broken = false;
+	bool exceededAngle = false, exceededDist = false;
 
 	calc_dist_angle(rbsc, &dist, &angle, true);
 
@@ -3159,33 +3172,25 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc)
 	/* TODO, ensure rigidbody orn is equal to quaternion of object !!! */
 	// The construct "asin(sin(x))" is a triangle function to achieve a seamless rotation loop from input
 	anglediff = asin(sin(fabs(rbsc->start_angle - angle) * 0.5f));
-	//if (anglediff > 0.0f)
-	//	printf("Angles %f %f\n", anglediff, rbsc->breaking_angle);
 
 	exceededAngle = ((rbsc->breaking_angle >= 0.0f) && (anglediff > rbsc->breaking_angle));
 	exceededDist = ((rbsc->breaking_dist >= 0.0f) && (distdiff > (rbsc->breaking_dist + (anglediff / M_PI))));
-	broken = rbsc->physics_constraint && !(RB_constraint_is_enabled(rbsc->physics_constraint));
 
-	if (exceededDist || exceededAngle || broken)
+	if (exceededDist || exceededAngle)
 	{
-		if (rbsc->type == RBC_TYPE_6DOF_SPRING && rbsc->flag & RBC_FLAG_USE_PLASTIC)
+		if (rbsc->type == RBC_TYPE_6DOF_SPRING)
 		{
-			if (!(rbsc->flag & RBC_FLAG_PLASTIC_ACTIVE) && !(rbsc->flag & RBC_FLAG_NEEDS_VALIDATE))
+			if (!(rbsc->flag & RBC_FLAG_PLASTIC_ACTIVE) /*&& !(rbsc->flag & RBC_FLAG_NEEDS_VALIDATE)*/)
 			{
 				/* activate only once */
 				rbsc->flag |= RBC_FLAG_PLASTIC_ACTIVE;
 				rigidbody_set_springs_active(rbsc, true);
 				RB_constraint_set_equilibrium_6dof_spring(rbsc->physics_constraint);
 			}
-			else if (rbsc->physics_constraint && RB_constraint_is_enabled(rbsc->physics_constraint))
-			{
-				rigidbody_set_springs_active(rbsc, false);
-				RB_constraint_set_enabled(rbsc->physics_constraint, false);
-			}
 		}
 		else if (rbsc->physics_constraint && RB_constraint_is_enabled(rbsc->physics_constraint))
 		{
-			rigidbody_set_springs_active(rbsc, false);
+			/* break regular connections */
 			RB_constraint_set_enabled(rbsc->physics_constraint, false);
 		}
 	}
@@ -3196,7 +3201,7 @@ static void handle_plastic_breaking(RigidBodyShardCon *rbsc)
 	/* break plastic connections */
 	if (exceededDist || exceededAngle)
 	{
-		if (rbsc->type == RBC_TYPE_6DOF_SPRING && rbsc->flag & RBC_FLAG_USE_PLASTIC)
+		if (rbsc->type == RBC_TYPE_6DOF_SPRING && rbsc->flag & RBC_FLAG_PLASTIC_ACTIVE)
 		{
 			if (rbsc->physics_constraint && RB_constraint_is_enabled(rbsc->physics_constraint))
 			{
@@ -3362,11 +3367,17 @@ static bool do_update_modifier(Scene* scene, Object* ob, RigidBodyWorld *rbw, bo
 			if (rbsc->physics_constraint && rbw && (rbw->flag & RBW_FLAG_REBUILD_CONSTRAINTS)) {
 				//printf("Rebuilding constraints\n");
 				RB_constraint_set_enabled(rbsc->physics_constraint, rbsc->flag & RBC_FLAG_ENABLED);
-				if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL && rbsc->flag & RBC_FLAG_USE_PLASTIC)
+				if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL && rbsc->type == RBC_TYPE_6DOF_SPRING)
 				{
-					/*reset plastic constraints, by deactivating them*/
-					rbsc->flag &= ~RBC_FLAG_PLASTIC_ACTIVE;
-					rigidbody_set_springs_active(rbsc, false);
+					if (rbsc->plastic_angle >= 0.0f || rbsc->plastic_dist >= 0.0f)
+					{
+						/*reset plastic constraints with immediate activation*/
+						if (rbsc->flag & RBC_FLAG_USE_PLASTIC)
+						{
+							rbsc->flag |= RBC_FLAG_PLASTIC_ACTIVE;
+							rigidbody_set_springs_active(rbsc, true);
+						}
+					}
 				}
 			}
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 108a905..8b183ba 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5131,6 +5131,7 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 	fmd->face_pairs = NULL;
 	fmd->vert_index_map = NULL;
 	fmd->vertex_island_map = NULL;
+	fmd->material_index_map = NULL;
 
 	/*HARDCODING this for now, until we can version it properly, say with 2.75 ? */
 	if (fd->fileversion < 275) {
@@ -5179,7 +5180,8 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 		fm->last_shard_tree = NULL;
 		fm->last_shards = NULL;
 
-		if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
+		if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED ||
+		    fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
 		{
 			link_list(fd, &fmd->frac_mesh->shard_map);
 			for (s = fmd->frac_mesh->shard_map.first; s; s = s->next) {
@@ -5229,6 +5231,20 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 				read_meshIsland(fd, &mi);
 				vertstart += initialize_meshisland(fmd, &mi, mverts, vertstart, ob, -1, -1);
 			}
+
+			if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+			{
+				RigidBodyShardCon *con;
+				link_list(fd, &fmd->meshConstraints);
+
+				for (con = fmd->meshConstraints.first; con; con = con->next)
+				{
+					con->mi1 = newdataadr(fd, con->mi1);
+					con->mi2 = newdataadr(fd, con->mi2);
+					con->physics_constraint = NULL;
+					con->flag |= RBC_FLAG_NEEDS_VALIDATE;
+				}
+			}
 		}
 		else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
 		{
@@ -5299,9 +5315,12 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 			}
 		}
 
-		fmd->refresh_constraints = true;
-		fmd->meshConstraints.first = NULL;
-		fmd->meshConstraints.last = NULL;
+		if (fmd->fracture_mode != MOD_FRACTURE_EXTERNAL)
+		{
+			fmd->refresh_constraints = true;
+			fmd->meshConstraints.first = NULL;
+			fmd->meshConstraints.last = NULL;
+		}
 
 		fmd->refresh_images = true;
 	}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 2874377..10afc3a 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1725,12 +1725,14 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 			FracMesh* fm = fmd->frac_mesh;
 			MeshIsland *mi;
 			Shard *s;
+			bool mode = fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED ||
+			            fmd->fracture_mode == MOD_FRACTURE_EXTERNAL;
 
-			if (fm && fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
+			if (fm && mode)
 			{
 				if (fm->running == 0 && !fmd->dm_group)
 				{
-					if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
+					if (mode)
 					{
 						writestruct(wd, DATA, "FracMesh", 1, fm);
 
@@ -1745,6 +1747,15 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 						for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
 							write_meshIsland(wd, mi);
 						}
+
+						if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+						{
+							RigidBodyShardCon *con;
+							for (con = fmd->meshConstraints.first; con; con = con->next)
+							{
+								writestruct(wd, DATA, "RigidBodyShardCon", 1, con);
+							}
+						}
 					}
 				}
 			}
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index caf8fd0..6070b9a 100644
--

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list