[Bf-blender-cvs] [9703c6f481d] temp-fracture-modifier-2.8: fixes for fractal boolean, autohide and convert to objects

Martin Felke noreply at git.blender.org
Fri Aug 17 22:32:04 CEST 2018


Commit: 9703c6f481d61ee08eb3ea62ab989a60fc2cb68f
Author: Martin Felke
Date:   Fri Aug 17 22:31:25 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB9703c6f481d61ee08eb3ea62ab989a60fc2cb68f

fixes for fractal boolean, autohide and convert to objects

works all partially only still, because other blender things dont work as expected any more...

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_automerge.c
M	source/blender/blenkernel/intern/fracture_constraints.c
M	source/blender/blenkernel/intern/fracture_prefractured.c
M	source/blender/blenkernel/intern/fracture_util.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesrna/intern/rna_fracture.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d135288733d..923b4ebf532 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -310,7 +310,7 @@ static void calculate_fractal(FractureModifierData* fmd, Mesh* me, BooleanContex
 	int max_axis;
 
 	BKE_fracture_mesh_boundbox_calc(me, loc, size);
-	radius = sqrt(size[0]*size[0] + size[1]*size[1] + size[2]*size[2]);
+	radius = sqrt(size[0]*size[0] + size[1]*size[1] + size[2]*size[2]) * 1.5f;
 
 	vec[0] = BLI_thread_frand(0) * 2 - 1;
 	vec[1] = BLI_thread_frand(0) * 2 - 1;
@@ -420,7 +420,7 @@ static void prepare_bisect(FractureModifierData *fmd, Object* ob, BisectContext*
 	ctx->inner_mat_index = BKE_object_material_slot_find_index(ob, fmd->inner_material) - 1;
 	ctx->use_fill = false;
 	BLI_strncpy(ctx->uv_layer, fmd->uvlayer_name, 64);
-	copy_m4_m4(ctx->obmat, ob->obmat);
+	unit_m4(ctx->obmat); // hmm, why necessary ?
 }
 
 static void prepare_bisect_fill(FractureModifierData *fmd, Object* ob, BisectContext* ctx)
@@ -545,11 +545,17 @@ static void process_cells(FractureModifierData* fmd, Mesh* mesh, Main* bmain, Ob
 	{
 		if (temp_meshs[i])
 		{
-			MeshIsland *result = BKE_fracture_mesh_island_create(temp_meshs[i], bmain, scene, ob);
-			fracture_meshisland_add(fmd, result);
-			result->id = j;
-			result->rigidbody->mesh_island_index = j;
-			j++;
+			if (temp_meshs[i]->totvert > 0)
+			{	/* skip invalid cells, e.g. those which are eliminated by bisect */
+				MeshIsland *result = BKE_fracture_mesh_island_create(temp_meshs[i], bmain, scene, ob);
+				fracture_meshisland_add(fmd, result);
+				result->id = j;
+				result->rigidbody->mesh_island_index = j;
+				j++;
+			}
+			else {
+				BKE_fracture_mesh_free(temp_meshs[i]);
+			}
 		}
 	}
 
@@ -1914,6 +1920,7 @@ void BKE_fracture_dynamic_free(FractureModifierData *fmd, Scene *scene)
 
 void BKE_fracture_modifier_free(FractureModifierData *fmd, Scene *scene)
 {
+	BKE_fracture_constraints_free(fmd, scene);
 	BKE_fracture_dynamic_free(fmd, scene);
 
 	if (fmd->shared->material_index_map)
@@ -2692,11 +2699,11 @@ FracPointCloud BKE_fracture_points_get(Depsgraph *depsgraph, FractureModifierDat
 	return points;
 }
 
-static Material* find_material(const char* name)
+static Material* find_material(Main* bmain, const char* name)
 {
 	ID* mat;
 
-	for (mat = G.main->mat.first; mat; mat = mat->next)
+	for (mat = bmain->mat.first; mat; mat = mat->next)
 	{
 		char *cmp = BLI_strdupcat("MA", name);
 		if (strcmp(cmp, mat->name) == 0)
@@ -2712,7 +2719,7 @@ static Material* find_material(const char* name)
 		}
 	}
 
-	return BKE_material_add(G.main, name);
+	return BKE_material_add(bmain, name);
 }
 
 //splinter handling is a case for BKE too
@@ -2765,6 +2772,7 @@ static MeshIsland* do_splinters(FractureModifierData *fmd, FracPointCloud points
 static short do_materials(Main* bmain, FractureModifierData *fmd, Object* obj)
 {
 	short mat_index = 0;
+	//Object *obj = DEG_get_original_object(ob);
 
 	if (fmd->inner_material) {
 		/* assign inner material as secondary mat to ob if not there already */
@@ -2790,14 +2798,14 @@ static short do_materials(Main* bmain, FractureModifierData *fmd, Object* obj)
 			/*create both materials if no material is present*/
 			Material* mat_inner;
 			char *matname = BLI_strdupcat(name, "_Outer");
-			Material* mat_outer = find_material(matname);
+			Material* mat_outer = find_material(bmain, matname);
 			BKE_object_material_slot_add(bmain, obj);
 			assign_material(bmain, obj, mat_outer, obj->totcol, BKE_MAT_ASSIGN_OBDATA);
 
 			MEM_freeN(matname);
 			matname = NULL;
 			matname = BLI_strdupcat(name, "_Inner");
-			mat_inner = find_material(matname);
+			mat_inner = find_material(bmain, matname);
 			BKE_object_material_slot_add(bmain, obj);
 			assign_material(bmain, obj, mat_inner, obj->totcol, BKE_MAT_ASSIGN_OBDATA);
 
@@ -2811,7 +2819,7 @@ static short do_materials(Main* bmain, FractureModifierData *fmd, Object* obj)
 		{
 			/* append inner material to the stack if materials are present */
 			char* matname = BLI_strdupcat(name, "_Inner");
-			Material* mat_inner = find_material(matname);
+			Material* mat_inner = find_material(bmain, matname);
 			BKE_object_material_slot_add(bmain, obj);
 			assign_material(bmain, obj, mat_inner, obj->totcol, BKE_MAT_ASSIGN_OBDATA);
 			MEM_freeN(matname);
@@ -4237,7 +4245,6 @@ static void do_island_index_map(FractureModifierData *fmd, Object* ob)
 	else {
 		int i,j = 0;
 		for (mi = fmd->shared->mesh_islands.first; mi; mi = mi->next){
-			int i;
 			for (i = 0; i < mi->mesh->totvert; i++)
 			{
 				if (!BLI_ghash_haskey(fmd->shared->vertex_island_map, SET_INT_IN_POINTER(i+j)))
@@ -4299,12 +4306,16 @@ Mesh* BKE_fracture_bmesh_to_mesh(BMesh* bm)
 
 BMesh* BKE_fracture_mesh_to_bmesh(Mesh* me)
 {
-	struct BMeshFromMeshParams bmf = {.calc_face_normal = true};
-	struct BMeshCreateParams bmc = {.use_toolflags = true};
+	struct BMeshFromMeshParams bmf = {.calc_face_normal = true, };
+	struct BMeshCreateParams bmc = {.use_toolflags = true, };
 	BMesh* bm;
 
-	bm = BM_mesh_create(&bm_mesh_allocsize_default, &bmc);
+	const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me);
+	bm = BM_mesh_create(&allocsize, &bmc);
+
 	BM_mesh_bm_from_me(bm, me, &bmf);
+
+	BM_mesh_elem_toolflags_ensure(bm);
 	BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE | BM_FACE);
 	BM_mesh_elem_table_ensure(bm, BM_VERT | BM_EDGE | BM_FACE);
 
diff --git a/source/blender/blenkernel/intern/fracture_automerge.c b/source/blender/blenkernel/intern/fracture_automerge.c
index f57f379e28d..8792a719bba 100644
--- a/source/blender/blenkernel/intern/fracture_automerge.c
+++ b/source/blender/blenkernel/intern/fracture_automerge.c
@@ -111,25 +111,45 @@ void BKE_fracture_face_pairs(FractureModifierData *fmd, Mesh *dm, Object *ob)
 
 	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;
 
 			BKE_fracture_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->shared->vertex_island_map, SET_INT_IN_POINTER(v1));
+				mi2 = BLI_ghash_lookup(fmd->shared->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->shared->face_pairs, SET_INT_IN_POINTER(index))) {
+			val = GET_INT_FROM_POINTER(BLI_ghash_lookup(fmd->shared->face_pairs, SET_INT_IN_POINTER(index)));
+			if (val != i && index != i) {
 				BLI_ghash_insert(fmd->shared->face_pairs, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(index));
 				pairs++;
 				/*match normals...*/
@@ -160,7 +180,7 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, Object*
 	int other = GET_INT_FROM_POINTER(BLI_ghash_lookup(fmd->shared->face_pairs, SET_INT_IN_POINTER(i)));
 	int inner_index = BKE_object_material_slot_find_index(ob, fmd->inner_material) - 1;
 
-	if ((other == i) && (fmd->fracture_mode != MOD_FRACTURE_DYNAMIC))
+	if ((other == i))
 	{
 		//printf("other == i %d \n", i);
 		f1 = BM_face_at_index(bm, i);
@@ -187,6 +207,7 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, Object*
 		return;
 	}
 
+
 	BM_face_calc_center_mean(f1, f_centr);
 	BM_face_calc_center_mean(f2, f_centr_other);
 
@@ -195,6 +216,8 @@ static void find_other_face(FractureModifierData *fmd, int i, BMesh* bm, Object*
 		(f1->mat_nr == inner_index) && (f2->mat_nr == inner_index))
 	{
 		bool in_filter = false;
+		int v1, v2;
+		MeshIsland *mi, *mi_other;
 
 		/*filter out face pairs, if we have an autohide filter group */
 		if (fmd->autohide_filter_group){
@@ -476,7 +499,7 @@ Mesh *BKE_fracture_autohide_do(FractureModifierData *fmd, Mesh *dm, Object *ob,
 	//struct BMeshToMeshParams bmt = {.calc_object_remap = 0};
 
 	//just before we mess up this mesh, ensure velocity precalculation.
-	BKE_update_velocity_layer(fmd);
+//	BKE_update_velocity_layer(fmd);
 
 	if (fmd->use_centroids && !fmd->use_vertices)
 	{
@@ -490,9 +513,9 @@ Mesh *BKE_fracture_autohide_do(FractureModifierData *fmd, Mesh *dm, Object *ob,
 	   bm = BKE_fracture_mesh_to_bmesh(dm);
 	}
 
-	BM_mesh_elem_index_ensure(bm, BM_FACE | BM_VERT);
-	BM_mesh_elem_table_ensure(bm, BM_FACE | BM_VERT);
-	BM_mesh_elem_toolflags_ensure(bm);
+//	BM_mesh_elem_index_ensure(bm, BM_FACE | BM_VERT);
+//	BM_mesh_elem_table_ensure(bm, BM_FACE | BM_VERT);
+//	BM_mesh_elem_toolflags_ensure(bm);
 
 	if (!fmd->use_centroids)
 	{
diff --git a/source/blender/blenkernel/intern/fracture_constraints.c b/source/blender/blenkernel/intern/fracture_constraints.c
index 605915b268d..e22a7f72a71 100644
--- a/source/blender/blenkernel/intern/fracture_constraints.c
+++ b/source/blender/blenkernel/intern/fracture_constraints.c
@@ -675,14 +675,12 @@ void BKE_fracture_constraints_free(FractureModifierData *fmd, Scene *scene)
 	RigidBodyShardCon *rbsc = NULL;
 
 	//hmm after loading the pointers might be out of sync...
-	if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC) {
-		if (fmd->shared->current_mi_entry) {
-			fmd->shared->mesh_islands = fmd->shared->current_mi_entry->meshIslands;
-		}
-		else {
-			fmd->shared->mesh_islands.first = NUL

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list