[Bf-blender-cvs] [f64eef7] fracture_modifier: simplified wood splinter settings, can set scale factor and direction now directly

Martin Felke noreply at git.blender.org
Thu Oct 30 12:10:58 CET 2014


Commit: f64eef7a5fb369bf02a33987e225d596f7c37a31
Author: Martin Felke
Date:   Thu Oct 30 12:10:37 2014 +0100
Branches: fracture_modifier
https://developer.blender.org/rBf64eef7a5fb369bf02a33987e225d596f7c37a31

simplified wood splinter settings, can set scale factor and direction now directly

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/BKE_fracture.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 9fcdf42..7555091 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -556,6 +556,8 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.extra_group",
         "fracture.dm_group",
         "fracture.use_particle_birth_coordinates",
+        "fracture.splinter_axis",
+        "fracture.splinter_length",
         "fracture.percentage",
         "fracture.breaking_percentage",
         "fracture.breaking_percentage_weighted",
diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 9df9fc3..d8b9958 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -122,6 +122,10 @@ class PHYSICS_PT_fracture_simulation(PhysicButtonsPanel, Panel):
             box.prop(md, "dm_group")
             box.prop(md, "use_particle_birth_coordinates")
 
+            row = box.row(align=True)
+            row.prop(md, "splinter_axis")
+            box.prop(md, "splinter_length")
+
             box.prop(md, "percentage")
             box.label("Constraint Breaking Settings")
             col = box.column(align=True)
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index d0c1897..abadde3 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -82,8 +82,8 @@ void BKE_fracture_create_dm(struct FractureModifierData *fmd, bool doCustomData)
 struct DerivedMesh *BKE_shard_create_dm(struct Shard *s, bool doCustomData);
 
 /* create shards from base mesh and a liste of points */
-void BKE_fracture_shard_by_points(struct FracMesh *fmesh, ShardID id, struct FracPointCloud *points, int algorithm, struct Object *obj, struct DerivedMesh *dm,
-                                  short inner_material_index);
+void BKE_fracture_shard_by_points(struct FracMesh *fmesh, ShardID id, struct FracPointCloud *points, int algorithm,
+                                  struct Object *obj, struct DerivedMesh *dm,short inner_material_index, float mat[4][4]);
 
 
 #endif /* BKE_FRACTURE_H */
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index ec08dda..c2fa149 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -72,15 +72,24 @@
 #endif
 
 /* prototypes */
-static void add_shard(FracMesh *fm, Shard *s);
+static void add_shard(FracMesh *fm, Shard *s, float mat[4][4]);
 static Shard *parse_cell(cell c);
 static void parse_cell_verts(cell c, MVert *mvert, int totvert);
 static void parse_cell_polys(cell c, MPoly *mpoly, int totpoly, int *r_totloop);
 static void parse_cell_loops(cell c, MLoop *mloop, int totloop, MPoly *mpoly, int totpoly);
 static void parse_cell_neighbors(cell c, int *neighbors, int totpoly);
 
-static void add_shard(FracMesh *fm, Shard *s)
+static void add_shard(FracMesh *fm, Shard *s, float mat[4][4])
 {
+	MVert *mv;
+	int i = 0;
+
+	for (i = 0, mv = s->mvert; i < s->totvert; i++, mv++ )
+	{
+		mul_m4_v3(mat, mv->co);
+		//mul_m4_v3(obj->obmat, mv->co);
+	}
+
 	BLI_addtail(&fm->shard_map, s);
 	s->shard_id = fm->shard_count;
 	fm->shard_count++;
@@ -362,7 +371,7 @@ FracMesh *BKE_create_fracture_container(void)
 
 
 /* parse the voro++ cell data */
-static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, FracMesh *fm, int algorithm, Object *obj, DerivedMesh *dm, short inner_material_index)
+static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, FracMesh *fm, int algorithm, Object *obj, DerivedMesh *dm, short inner_material_index, float mat[4][4])
 {
 	/*Parse voronoi raw data*/
 	int i = 0;
@@ -557,7 +566,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 			for (i = 0; i < expected_shards; i++) {
 				Shard *s = tempresults[i];
 				if (s != NULL) {
-					add_shard(fm, s);
+					add_shard(fm, s, mat);
 				}
 
 				{
@@ -682,7 +691,7 @@ static void parse_cell_neighbors(cell c, int *neighbors, int totpoly)
 	}
 }
 
-void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *pointcloud, int algorithm, Object *obj, DerivedMesh *dm, short inner_material_index) {
+void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *pointcloud, int algorithm, Object *obj, DerivedMesh *dm, short inner_material_index, float mat[4][4]) {
 	int n_size = 8;
 	
 	Shard *shard;
@@ -714,6 +723,10 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
 
 	add_v3_fl(min, -theta);
 	add_v3_fl(max, theta);
+
+	mul_m4_v3(mat, min);
+	mul_m4_v3(mat, max);
+
 	
 	voro_container = container_new(min[0], max[0], min[1], max[1], min[2], max[2],
 	                               n_size, n_size, n_size, false, false, false,
@@ -738,7 +751,7 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
 	container_compute_cells(voro_container, voro_cells);
 
 	/*Evaluate result*/
-	parse_cells(voro_cells, pointcloud->totpoints, id, fmesh, algorithm, obj, dm, inner_material_index);
+	parse_cells(voro_cells, pointcloud->totpoints, id, fmesh, algorithm, obj, dm, inner_material_index, mat);
 
 	/*Free structs in C++ area of memory */
 	cells_free(voro_cells, pointcloud->totpoints);
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index ffc238e..886de7a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1412,6 +1412,12 @@ enum {
 	MOD_FRACTURE_UNIFORM         = (1 << 5),
 };
 
+enum {
+	MOD_FRACTURE_SPLINTER_X      = (1 << 0),
+	MOD_FRACTURE_SPLINTER_Y      = (1 << 1),
+	MOD_FRACTURE_SPLINTER_Z      = (1 << 2),
+};
+
 typedef struct FractureModifierData {
 	ModifierData modifier;
 	struct FracMesh *frac_mesh; /* store only the current fracmesh here first, later maybe an entire history...*/
@@ -1441,6 +1447,7 @@ typedef struct FractureModifierData {
 	int constraint_limit;
 	int solver_iterations_override;
 	int breaking_percentage;
+	int splinter_axis;
 
 	float breaking_angle;
 	float breaking_distance;
@@ -1448,6 +1455,7 @@ typedef struct FractureModifierData {
 	float breaking_threshold;
 	float cluster_breaking_threshold;
 	float contact_dist, autohide_dist;
+	float splinter_length;
 
 	/* flags */
 	int refresh;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index c52aeec..c196d97 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3804,6 +3804,13 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem prop_splinter_axises[] = {
+		{MOD_FRACTURE_SPLINTER_X, "SPLINTER_X", 0, "Splinter X", "Splinters in X Direction"},
+		{MOD_FRACTURE_SPLINTER_Y, "SPLINTER_Y", 0, "Splinter Y", "Splinters in Y Direction"},
+		{MOD_FRACTURE_SPLINTER_Z, "SPLINTER_Z", 0, "Splinter Z", "Splinters in Z Direction"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "FractureModifier", "Modifier");
 	RNA_def_struct_ui_text(srna, "Fracture Modifier", "Add a fracture container to this object");
 	RNA_def_struct_sdna(srna, "FractureModifierData");
@@ -3998,6 +4005,18 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "use_particle_birth_coordinates", false);
 	RNA_def_property_ui_text(prop, "Use Initial Particle Coordinates", "Use initial or simulated state particle coordinates");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "splinter_axis", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, prop_splinter_axises);
+	RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+	RNA_def_property_enum_default(prop, MOD_FRACTURE_SPLINTER_Z);
+	RNA_def_property_ui_text(prop, "Splinter Axis", "Global direction of splinters");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "splinter_length", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 1.0f, 1000.0f);
+	RNA_def_property_ui_text(prop, "Splinter length", "Length of splinters");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 86890d6..a9d3fa0 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -124,6 +124,7 @@ static void initData(ModifierData *md)
 	/* XXX needed because of messy particle cache, shows incorrect positions when start/end on frame 1
 	 * default use case is with this flag being enabled, disable at own risk */
 	fmd->use_particle_birth_coordinates = true;
+	fmd->splinter_length = 1.0f;
 }
 
 static void freeMeshIsland(FractureModifierData *rmd, MeshIsland *mi, bool remove_rigidbody)
@@ -811,6 +812,44 @@ static void do_fracture(FractureModifierData *fracmd, ShardID id, Object *obj, D
 	if (points.totpoints > 0) {
 		bool temp = fracmd->shards_to_islands;
 		short mat_index = 0;
+		float mat[4][4], imat[4][4];
+		float mat2[4][4];
+
+		unit_m4(mat);
+		unit_m4(mat2);
+
+		/*splinters... just global axises and a length, for rotation rotate the object */
+		if (fracmd->splinter_axis & MOD_FRACTURE_SPLINTER_X)
+		{
+			mat[0][0] *= fracmd->splinter_length;
+		}
+		if (fracmd->splinter_axis & MOD_FRACTURE_SPLINTER_Y)
+		{
+			mat[1][1] *= fracmd->splinter_length;
+		}
+		if (fracmd->splinter_axis & MOD_FRACTURE_SPLINTER_Z)
+		{
+			mat[2][2] *= fracmd->splinter_length;
+		}
+
+
+		if ((fracmd->splinter_axis & MOD_FRACTURE_SPLINTER_X) ||
+			(fracmd->splinter_axis & MOD_FRACTURE_SPLINTER_Y) ||
+			(fracmd->splinter_axis & MOD_FRACTURE_SPLINTER_Z))
+		{
+			int i = 0;
+			MVert* mvert = dm->getVertArray(dm), *mv;
+			invert_m4_m4(imat, mat);
+			invert_m4_m4(obj->imat, obj-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list