[Bf-blender-cvs] [982720cffef] fracture_modifier: fix for autohide with fractal (could leave holes near inner edges before); fractal/fast bisect should now also take extra objects / helper better into account

Martin Felke noreply at git.blender.org
Mon Oct 1 17:17:32 CEST 2018


Commit: 982720cffef2dc79d713d7a282e345fc91b9b27e
Author: Martin Felke
Date:   Mon Oct 1 17:17:12 2018 +0200
Branches: fracture_modifier
https://developer.blender.org/rB982720cffef2dc79d713d7a282e345fc91b9b27e

fix for autohide with fractal (could leave holes near inner edges before); fractal/fast bisect should now also take extra objects / helper better into account

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

M	source/blender/blenkernel/intern/fracture.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 f346026b96d..aa708bc1048 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -163,7 +163,7 @@ static int shard_sortdist(const void *s1, const void *s2, void* context)
 {
 	Shard **sh1 = (Shard **)s1;
 	Shard **sh2 = (Shard **)s2;
-	cell *sh = (cell*)context;
+	Shard *sh = (Shard*)context; //representing raw cell
 
 	float val_a,  val_b;
 
@@ -687,8 +687,8 @@ 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_sortdist, &(cells[i]));
-			BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortsize, &(cells[i]));
+			BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortsize, i);
+			BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortdist, t);
 
 			while ((*tempresults)[j] == NULL && j < (i + 1)) {
 				/* ignore invalid shards */
@@ -802,6 +802,8 @@ static void handle_boolean_fractal(Shard* p, Shard* t, int expected_shards, Deri
 		(*tempresults)[*i] = s2;
 
 		BLI_qsort_r(*tempresults, (*i) + 1, sizeof(Shard *), shard_sortsize, i);
+		BLI_qsort_r(*tempresults, (*i) + 1, sizeof(Shard *), shard_sortdist, t);
+
 		while ((*tempresults)[j] == NULL && j < ((*i) + 1)) {
 			/* ignore invalid shards */
 			j++;
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 2734622c557..982e91aba5c 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -3280,6 +3280,8 @@ static void make_face_pairs(FractureModifierData *fmd, DerivedMesh *dm, Object *
 	int i = 0;
 	int inner_index = BKE_object_material_slot_find_index(ob, fmd->inner_material) - 1;
 
+	do_island_index_map(fmd, ob);
+
 	//printf("Make Face Pairs\n");
 	int faces = 0, pairs = 0;
 
@@ -3299,25 +3301,45 @@ static void make_face_pairs(FractureModifierData *fmd, DerivedMesh *dm, Object *
 
 	for (i = 0, mp = mpoly; i < totpoly; mp++, i++) {
 		if (mp->mat_nr == inner_index) { /* treat only inner faces ( with inner material) */
-			int index = -1, j = 0, r = 0;
+			int index = -1, j = 0, r = 0, val = -1;
 			KDTreeNearest *n;
-			float co[3];
+			float co[3], dist = fmd->autohide_dist;
 
 			DM_face_calc_center_mean(dm, mp, co);
-			r = BLI_kdtree_range_search(tree, co, &n, fmd->autohide_dist);
-			//r = BLI_kdtree_find_nearest_n(tree, co, n, 2);
+			if (fmd->frac_algorithm == MOD_FRACTURE_BOOLEAN_FRACTAL)
+			{
+				/*just as precaution, rather search a wider radius*/
+				dist = fmd->autohide_dist * 10;
+			}
+
+			r = BLI_kdtree_range_search(tree, co, &n, dist);
+			//r = BLI_kdtree_find_nearest_n(tree, co, &n, 2);
 			/*2nd nearest means not ourselves...*/
 			if (r == 0)
 				continue;
 
 			index = n[0].index;
-			while ((j < r) && i == index) {
+			while (j < r) {
+				int v1, v2;
+				MeshIsland *mi1, *mi2;
 				index = n[j].index;
 				//printf("I, INDEX %d %d %f\n", i, index, n[j].dist);
+				v1 = mloop[mp->loopstart].v;
+				v2 = mloop[(mpoly+index)->loopstart].v;
+				mi1 = BLI_ghash_lookup(fmd->vertex_island_map, SET_INT_IN_POINTER(v1));
+				mi2 = BLI_ghash_lookup(fmd->vertex_island_map, SET_INT_IN_POINTER(v2));
+
+				if (mi1 != mi2) {
+					/*dont delete faces on own meshisland if they are closer than faces on adjacent island
+					like with boolean fractal*/
+					break;
+				}
+
 				j++;
 			}
 
-			if (!BLI_ghash_haskey(fmd->face_pairs, SET_INT_IN_POINTER(index))) {
+			val = GET_INT_FROM_POINTER(BLI_ghash_lookup(fmd->face_pairs, SET_INT_IN_POINTER(index)));
+			if (val != i && index != i) {
 				BLI_ghash_insert(fmd->face_pairs, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(index));
 				pairs++;
 				/*match normals...*/
@@ -4822,7 +4844,6 @@ static DerivedMesh *doSimulate(FractureModifierData *fmd, Object *ob, DerivedMes
 			}
 		}
 
-
 		do_island_index_map(fmd, ob);
 		do_refresh_constraints(fmd, ob);



More information about the Bf-blender-cvs mailing list