[Bf-blender-cvs] [2f6f36ef5a2] fracture_modifier: added rectangular alignment feature for fast bisect (works with uniform only)

Martin Felke noreply at git.blender.org
Fri May 12 17:49:02 CEST 2017


Commit: 2f6f36ef5a23e4552aa9bce72815c401d0164158
Author: Martin Felke
Date:   Fri May 12 17:48:34 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rB2f6f36ef5a23e4552aa9bce72815c401d0164158

added rectangular alignment feature for fast bisect (works with uniform only)

the closer the factor is to 1, the more rectangular-ish the shards will look like. default is 0 which means any rotation is allowed.

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

M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/BKE_fracture.h
M	source/blender/blenkernel/BKE_fracture_util.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_util.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_fracture.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 0efbac9c38c..d1639be367f 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -164,6 +164,8 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
             box.label("Inner Vertex Group:")
             box.prop_search(md, "inner_vertex_group", ob, "vertex_groups", text = "")
             box.prop(md, "inner_crease")
+            if (md.frac_algorithm in {'BISECT_FAST', 'BISECT_FAST_FILL'}):
+                box.prop(md, "orthogonality_factor", text="Rectangular Alignment")
 
         layout.context_pointer_set("modifier", md)
         row = layout.row()
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index 7f6a6ae8595..328e4c49a74 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -94,7 +94,7 @@ struct DerivedMesh *BKE_shard_create_dm(struct Shard *s, bool doCustomData);
 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],
                                   int num_cuts, float fractal, bool smooth, int num_levels, int mode, bool reset, int active_setting,
-                                  int num_settings, char uv_layer[], bool threaded, int solver, float thresh, bool shards_to_islands, int override_count);
+                                  int num_settings, char uv_layer[], bool threaded, int solver, float thresh, bool shards_to_islands, int override_count, float factor);
 
 /* create shards from a base mesh and a set of other objects / cutter planes */
 void BKE_fracture_shard_by_planes(struct FractureModifierData *fmd, struct Object *obj, short inner_material_index, float mat[4][4]);
diff --git a/source/blender/blenkernel/BKE_fracture_util.h b/source/blender/blenkernel/BKE_fracture_util.h
index 413e1463080..e9ab0581f98 100644
--- a/source/blender/blenkernel/BKE_fracture_util.h
+++ b/source/blender/blenkernel/BKE_fracture_util.h
@@ -39,6 +39,6 @@ Shard *BKE_fracture_shard_boolean(Object *obj, DerivedMesh *dm_parent, Shard* ch
                                   Shard **other, float mat[4][4], float radius, bool use_smooth_inner, int num_levels, char uv_layer[], int solver, float thresh);
 Shard *BKE_fracture_shard_bisect(struct BMesh *bm_orig, Shard* child, float obmat[4][4], bool use_fill,
                                  bool clear_inner, bool clear_outer, int cutlimit, float centroid[],
-                                 short inner_mat_index, char uv_layer[], struct KDTree *preselect_tree, float quat[]);
+                                 short inner_mat_index, char uv_layer[], struct KDTree *preselect_tree, float normal[]);
 
 #endif /* BKE_FRACTURE_UTIL_H*/
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d60864f57ab..84df17c7843 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -193,8 +193,9 @@ static int shard_sortsize(const void *s1, const void *s2, void* UNUSED(context))
 	shard_boundbox(*sh1, loc, size1);
 	shard_boundbox(*sh2, loc, size2);
 
-	val_a = size1[0] * size1[1] * size1[2];
-	val_b = size2[0] * size2[1] * size2[2];
+	//squared diameter
+	val_a = size1[0]*size1[0] + size1[1]*size1[1] + size1[2]*size1[2];
+	val_b = size2[0]*size2[0] + size2[1]*size2[1] + size2[2]*size2[2];
 
 	/* sort descending */
 	if      (val_a < val_b) return 1;
@@ -470,15 +471,20 @@ FracMesh *BKE_create_fracture_container(void)
 
 static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm, BMesh** bm_parent, float obmat[4][4],
                                float centroid[3], short inner_material_index, int parent_id, Shard **tempshards, Shard ***tempresults,
-                               char uv_layer[64], cell* cells)
+                               char uv_layer[64], cell* cells, float fac, Shard* parent)
 {
 	int i = 0, index = 0;
+	float factor = 1 - fac;
+
+	float dim[3];
+	sub_v3_v3v3(dim, parent->max, parent->min);
 
 	for (i = 0; i < expected_shards; i++) {
 		Shard *s = NULL;
 		Shard *s2 = NULL;
 		Shard *t;
-		float quat[4];
+		float vec[3];
+		int max_axis;
 
 		if (fm->cancel == 1) {
 			break;
@@ -503,20 +509,35 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 			index = 0;
 		}
 
-		//add some random rotation
-		quat[0] = BLI_frand() * 2 - 1;
-		quat[1] = BLI_frand() * 2 - 1;
-		quat[2] = BLI_frand() * 2 - 1;
-		quat[3] = BLI_frand() * 2 - 1;
-		normalize_qt(quat);
+		//make a random vector (interpret as cutter plane)
+		vec[0] = BLI_frand() * 2 - 1;
+		vec[1] = BLI_frand() * 2 - 1;
+		vec[2] = BLI_frand() * 2 - 1;
+
+		//multiply two minor dimensions with a factor to emphasize the max dimension
+		max_axis = axis_dominant_v3_single(dim);
+		switch (max_axis) {
+			case 0:
+				vec[1] *= factor;
+				vec[2] *= factor;
+				break;
+			case 1:
+				vec[0] *= factor;
+				vec[2] *= factor;
+				break;
+			case 2:
+				vec[0] *= factor;
+				vec[1] *= factor;
+				break;
+		}
 
 		printf("Bisecting cell %d...\n", i);
 		printf("Bisecting cell %d...\n", i + 1);
 
 		s = BKE_fracture_shard_bisect(*bm_parent, t, obmat, algorithm == MOD_FRACTURE_BISECT_FAST_FILL,
-		                              false, true, index, centroid, inner_material_index, uv_layer, NULL, quat);
+		                              false, true, index, centroid, inner_material_index, uv_layer, NULL, vec);
 		s2 = BKE_fracture_shard_bisect(*bm_parent, t, obmat, algorithm == MOD_FRACTURE_BISECT_FAST_FILL,
-		                               true, false, index, centroid, inner_material_index, uv_layer, NULL, quat);
+		                               true, false, index, centroid, inner_material_index, uv_layer, NULL, vec);
 
 		index++;
 
@@ -556,6 +577,7 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 			if ((i + 2) < expected_shards) {
 				*bm_parent = shard_to_bmesh((*tempresults)[j]);
 				copy_v3_v3(centroid, (*tempresults)[j]->centroid);
+				sub_v3_v3v3(dim, (*tempresults)[j]->max, (*tempresults)[j]->min);
 
 				BKE_shard_free((*tempresults)[j], true);
 				(*tempresults)[j] = NULL;
@@ -875,7 +897,8 @@ static void do_prepare_cells(FracMesh *fm, cell *cells, int expected_shards, int
 //static ThreadMutex prep_lock = BLI_MUTEX_INITIALIZER;
 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], int num_cuts, float fractal, bool smooth, int num_levels, int mode,
-                        bool reset, int active_setting, int num_settings, char uv_layer[64], bool threaded, int solver, float thresh, int override_count)
+                        bool reset, int active_setting, int num_settings, char uv_layer[64], bool threaded, int solver, float thresh, int override_count,
+                        float factor)
 {
 	/*Parse voronoi raw data*/
 	int i = 0, j = 0, count = 0;
@@ -1038,7 +1061,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 		else
 		{
 			handle_fast_bisect(fm, expected_shards, algorithm, &bm_parent, obmat, centroid, inner_material_index, parent_id,
-			                   tempshards, &tempresults, uv_layer, cells);
+			                   tempshards, &tempresults, uv_layer, cells, factor, p);
 		}
 	}
 
@@ -1678,6 +1701,7 @@ typedef struct FractureData {
 	int solver;
 	float thresh;
 	int override_count;
+	float factor;
 } FractureData;
 
 
@@ -1689,7 +1713,7 @@ static void compute_fracture(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(
 	if (fd->totpoints > 0) {
 		parse_cells(fd->voro_cells, fd->totpoints, fd->id, fd->fmesh, fd->algorithm, fd->obj, fd->dm, fd->inner_material_index, fd->mat,
 	                fd->num_cuts, fd->fractal, fd->smooth, fd->num_levels,fd->mode, fd->reset, fd->active_setting, fd->num_settings, fd->uv_layer,
-		            true, fd->solver, fd->thresh, fd->override_count);
+		            true, fd->solver, fd->thresh, fd->override_count, fd->factor);
 	}
 }
 
@@ -1697,7 +1721,8 @@ static void compute_fracture(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(
 static FractureData segment_cells(cell *voro_cells, int startcell, int totcells, FracMesh *fmesh, ShardID id, FracPointCloud *pointcloud,
                     int algorithm, Object *obj, DerivedMesh *dm, short
                     inner_material_index, float mat[4][4], int num_cuts, float fractal, bool smooth, int num_levels, int mode,
-                    bool reset, int active_setting, int num_settings, char uv_layer[64], int solver, float thresh, int override_count)
+                    bool reset, int active_setting, int num_settings, char uv_layer[64], int solver, float thresh, int override_count,
+                    float factor)
 {
 	FractureData fd;
 	fd.fmesh = fmesh;
@@ -1720,6 +1745,7 @@ static FractureData segment_cells(cell *voro_cells, int startcell, int totcells,
 	fd.solver = solver;
 	fd.thresh = thresh;
 	fd.override_count = override_count;
+	fd.factor = factor;
 
 	//cell start pointer, only take fd.totpoints cells out
 	fd.voro_cells = voro_cells + startcell;
@@ -1730,7 +1756,7 @@ static FractureData segment_cells(cell *voro_cells, int startcell, int totcells,
 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 num_cuts, float fractal, bool smooth, int num_levels, int mode,
                                   bool reset, int active_setting, int num_settings, char uv_layer[64], bool threaded, int solver, float thresh,
-                                  bool shards_to_islands, int override_count)
+                                  bool shards_to_islands, int override_count, float

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list