[Bf-blender-cvs] [8f53838] fracture_modifier: attempt to make fast bisect usable with mousebased fracture... now the user has a bit control how the halving is performed via the helpers

Martin Felke noreply at git.blender.org
Mon Jul 11 16:50:33 CEST 2016


Commit: 8f53838675f81bb8ddbf5b8b615b07fac217ffa6
Author: Martin Felke
Date:   Mon Jul 11 16:42:58 2016 +0200
Branches: fracture_modifier
https://developer.blender.org/rB8f53838675f81bb8ddbf5b8b615b07fac217ffa6

attempt to make fast bisect usable with mousebased fracture... now the user has a bit control how the halving is performed via the helpers

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_util.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 168bed6..bd69896 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -154,6 +154,27 @@ static void shard_boundbox(Shard *s, float r_loc[3], float r_size[3])
 	r_size[2] = (max[2] - min[2]) / 2.0f;
 }
 
+static int shard_sortdist(const void *s1, const void *s2, void* context)
+{
+	Shard **sh1 = (Shard **)s1;
+	Shard **sh2 = (Shard **)s2;
+	cell *sh = (cell*)context;
+
+	float val_a,  val_b;
+
+	if ((*sh1 == NULL) || (*sh2 == NULL)) {
+		return -1;
+	}
+
+	val_a = len_squared_v3v3(sh->centroid, (*sh1)->centroid);
+	val_b = len_squared_v3v3(sh->centroid, (*sh2)->centroid);
+
+	/* sort descending */
+	if      (val_a < val_b) return -1;
+	else if (val_a > val_b) return 1;
+	return 0;
+}
+
 static int shard_sortsize(const void *s1, const void *s2, void* UNUSED(context))
 {
 	Shard **sh1 = (Shard **)s1;
@@ -401,15 +422,14 @@ 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])
+                               char uv_layer[64], cell* cells)
 {
-	int i = 0;
+	int i = 0, index = 0;
 
 	for (i = 0; i < expected_shards; i++) {
 		Shard *s = NULL;
 		Shard *s2 = NULL;
 		Shard *t;
-		int index = 0;
 
 		if (fm->cancel == 1) {
 			break;
@@ -425,12 +445,13 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 
 		if (t == NULL || t->totvert == 0 || t->totloop == 0 || t->totpoly == 0) {
 			/* invalid shard, stop parsing*/
-			break;
+			continue;
 		}
 
-		index = (int)(BLI_frand() * (t->totpoly - 1));
-		if (index == 0) {
-			index = 1;
+		//index = (int)(BLI_frand() * (t->totpoly - 1));
+
+		if (index > (t->totpoly - 1)){
+			index = 0;
 		}
 
 		printf("Bisecting cell %d...\n", i);
@@ -441,6 +462,13 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 		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);
 
+		index++;
+
+		if (s == NULL || s2 == NULL) {
+			printf("Shard missed....\n");
+			continue;
+		}
+
 		if (s != NULL && s2 != NULL && tempresults != NULL) {
 			int j = 0;
 
@@ -460,7 +488,7 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 			(*tempresults)[i] = s;
 			(*tempresults)[i + 1] = s2;
 
-			BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortsize, &i);
+			BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortdist, &(cells[i]));
 
 			while ((*tempresults)[j] == NULL && j < (i + 1)) {
 				/* ignore invalid shards */
@@ -605,7 +633,7 @@ static bool handle_boolean_bisect(FracMesh *fm, Object *obj, int expected_shards
 	else if (algorithm == MOD_FRACTURE_BISECT || algorithm == MOD_FRACTURE_BISECT_FILL) {
 		float co[3] = {0, 0, 0};
 		printf("Bisecting cell %d...\n", *i);
-		s = BKE_fracture_shard_bisect(bm_parent, t, obmat, algorithm == MOD_FRACTURE_BISECT_FILL, false, true, 0, co, inner_material_index, uv_layer,
+		s = BKE_fracture_shard_bisect(bm_parent, t, obmat, algorithm == MOD_FRACTURE_BISECT_FILL, false, true, -1, co, inner_material_index, uv_layer,
 		                              preselect_tree);
 	}
 	else {
@@ -929,7 +957,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);
+			                   tempshards, &tempresults, uv_layer, cells);
 		}
 	}
 
diff --git a/source/blender/blenkernel/intern/fracture_util.c b/source/blender/blenkernel/intern/fracture_util.c
index 430a1db..97c7779 100644
--- a/source/blender/blenkernel/intern/fracture_util.c
+++ b/source/blender/blenkernel/intern/fracture_util.c
@@ -756,7 +756,7 @@ static void do_bisect(BMesh* bm_parent, BMesh* bm_child, float obmat[4][4], bool
 			break;
 		}
 
-		if (cutlimit > 0) {
+		if (cutlimit > -1) {
 			f = BM_face_at_index_find(bm_child, cutlimit);
 			copy_v3_v3(plane_co, centroid);
 			copy_v3_v3(plane_no, f->no /*normal*/);




More information about the Bf-blender-cvs mailing list