[Bf-blender-cvs] [868280331ed] temp-fracture-modifier-2.8: further rewrite to make more readable / maintainable code

Martin Felke noreply at git.blender.org
Wed Aug 15 14:36:53 CEST 2018


Commit: 868280331ed012f67e04b1d86cfaf320f6479127
Author: Martin Felke
Date:   Wed Aug 15 14:36:06 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB868280331ed012f67e04b1d86cfaf320f6479127

further rewrite to make more readable / maintainable code

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

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_fracture_types.h

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

diff --git a/source/blender/blenkernel/BKE_fracture_util.h b/source/blender/blenkernel/BKE_fracture_util.h
index 0cefbb54363..38f215243aa 100644
--- a/source/blender/blenkernel/BKE_fracture_util.h
+++ b/source/blender/blenkernel/BKE_fracture_util.h
@@ -68,7 +68,7 @@ typedef struct BooleanContext {
 } BooleanContext;
 
 Mesh* BKE_fracture_mesh_boolean(Mesh* geometry, Mesh* shard, Object* obj, BooleanContext *ctx);
-Mesh* BKE_fracture_mesh_bisect(Mesh* geometry, Mesh* raw_shard, BisectContext* ctx);
+Mesh* BKE_fracture_mesh_bisect(Mesh* geometry, MeshIsland *raw_shard, BisectContext* ctx);
 void BKE_fracture_mesh_boolean_fractal(Mesh* geometry, Mesh **outputA, Mesh** outputB, Object *obj, BooleanContext *ctx);
 void BKE_fracture_mesh_bisect_fast(Mesh* geometry, Mesh **outputA, Mesh** outputB, BisectContext *ctx);
 
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 26521f59852..d9ca207abc5 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -120,28 +120,28 @@ static void fracture_meshisland_add(FractureModifierData *fmd, MeshIsland *mi,
 }
 
 
-static int shard_sortsize(const void *s1, const void *s2, void* UNUSED(context))
+static int mesh_sortsize(const void *s1, const void *s2, void* UNUSED(context))
 {
-	Mesh **sh1 = (Mesh **)s1;
-	Mesh **sh2 = (Mesh **)s2;
+	Mesh **me1 = (Mesh **)s1;
+	Mesh **me2 = (Mesh **)s2;
 
 	float size1[3], size2[3], loc[3];
 	float val_a,  val_b;
 
-	if ((*sh1 == NULL) || (*sh2 == NULL)) {
+	if ((*me1 == NULL) || (*me2 == NULL)) {
 		return -1;
 	}
 
-	BKE_fracture_mesh_boundbox_calc(*sh1, loc, size1);
-	BKE_fracture_mesh_boundbox_calc(*sh2, loc, size2);
+	BKE_fracture_mesh_boundbox_calc(*me1, loc, size1);
+	BKE_fracture_mesh_boundbox_calc(*me2, loc, size2);
 
 	//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;
-	else if (val_a > val_b) return -1;
+	/* sort */
+	if      (val_a < val_b) return -1;
+	else if (val_a > val_b) return 1;
 	return 0;
 }
 
@@ -266,751 +266,128 @@ bool BKE_fracture_mesh_center_centroid_area(Mesh *shard, float cent[3])
 	return (shard->totpoly != 0);
 }
 
-#if 0
-static Shard* fracture_initial_shard_create(Mesh *dm)
-{
-	/* create temporary shard covering the entire mesh */
-	Shard *s = BKE_fracture_shard_create(dm->mvert, dm->mpoly, dm->mloop, dm->medge,
-										 dm->totvert, dm->totpoly, dm->totloop, dm->totedge, true);
-	BKE_fracture_custom_data_mesh_to_shard(s, dm);
-	s->flag = SHARD_INTACT;
-	s->shard_id = -2;
-	return s;
-}
-
-
-/*access shard directly by index / id*/
-Shard *BKE_shard_by_id(FracMesh *mesh, ShardID id, Mesh *dm) {
-	if ((id >= 0)) {
-		Shard *s = mesh->shard_map.first;
-		while (s)
-		{
-			if (s->shard_id == id)
-			{
-				return s;
-			}
-			s = s->next;
-		}
-
-		return NULL;
-	}
-	else if (id == -1 && dm != NULL)
-	{
-		/* create temporary shard covering the entire mesh */
-		return fracture_initial_shard_create(dm);
-	}
-
-	return NULL;
-}
-
-bool BKE_get_shard_minmax(FracMesh *mesh, ShardID id, float min_r[3], float max_r[3], Mesh *dm)
-{
-	Shard *shard = BKE_shard_by_id(mesh, id, dm);
-	if (shard != NULL) {
-		BKE_shard_calc_minmax(shard);
-		copy_v3_v3(min_r, shard->min);
-		copy_v3_v3(max_r, shard->max);
-
-		if (shard->shard_id == -2)
-		{
-			BKE_fracture_shard_free(shard, true);
-		}
-
-		return true;
-	}
-	return false;
-}
-
-Shard *BKE_fracture_shard_create(MVert *mvert, MPoly *mpoly, MLoop *mloop, MEdge* medge,  int totvert, int totpoly,
-								 int totloop, int totedge, bool copy)
-{
-	Shard *shard = MEM_mallocN(sizeof(Shard), __func__);
-	shard->totvert = totvert;
-	shard->totpoly = totpoly;
-	shard->totloop = totloop;
-	shard->totedge = totedge;
-	shard->cluster_colors = NULL;
-	shard->neighbor_ids = NULL;
-	shard->neighbor_count = 0;
-
-	if (copy) {
-		shard->mvert = MEM_mallocN(sizeof(MVert) * totvert, "shard vertices");
-		shard->mpoly = MEM_mallocN(sizeof(MPoly) * totpoly, "shard polys");
-		shard->mloop = MEM_mallocN(sizeof(MLoop) * totloop, "shard loops");
-		shard->medge = MEM_mallocN(sizeof(MEdge) * totedge, "shard edges");
-		memcpy(shard->mvert, mvert, sizeof(MVert) * totvert);
-		memcpy(shard->mpoly, mpoly, sizeof(MPoly) * totpoly);
-		memcpy(shard->mloop, mloop, sizeof(MLoop) * totloop);
-		memcpy(shard->medge, medge, sizeof(MEdge) * totedge);
-	}
-	else {
-		shard->mvert = mvert;
-		shard->mpoly = mpoly;
-		shard->mloop = mloop;
-		shard->medge = medge;
-	}
-
-	shard->shard_id = -1;
-	shard->setting_id = -1;
-	shard->parent_id = -1;
-
-	shard->flag = SHARD_INTACT;
-	BKE_shard_calc_minmax(shard);
-
-	BKE_fracture_mesh_center_centroid_area(shard, shard->centroid);
-	copy_v3_v3(shard->raw_centroid, shard->centroid);
-	zero_v3(shard->impact_loc);
-	shard->impact_size[0] = 1.0f;
-	shard->impact_size[1] = 1.0f;
-	shard->impact_size[2] = 1.0f;
-
-	return shard;
-}
-
-FracMesh *BKE_fracture_fracmesh_create(void)
-{
-	FracMesh *fmesh;
-
-	fmesh = MEM_mallocN(sizeof(FracMesh), __func__);
-	fmesh->shard_map.first = NULL;
-	fmesh->shard_map.last = NULL;
-	fmesh->shard_count = 0;
-	fmesh->cancel = 0;
-	fmesh->running = 0;
-	fmesh->progress_counter = 0;
-	fmesh->last_shards = NULL;
-	fmesh->last_shard_tree = NULL;
-	fmesh->last_expected_shards = 0;
-
-	return fmesh;
-}
-
-#endif
-
-#if 0
-static void handle_fast_bisect(FractureModifierData *fmd, int expected_shards, BMesh** bm_parent, float obmat[4][4],
-							   float centroid[3], short inner_material_index, MeshIsland **tempshards, MeshIsland ***tempresults,
-							   cell* cells, MeshIsland* parent)
-{
-	int i = 0, index = 0;
-	float factor = 1 - fmd->orthogonality_factor;
-	int algorithm = fmd->frac_algorithm;
-	char *uv_layer = fmd->uvlayer_name;
-
-	float dim[3], loc[3];
-	BKE_fracture_mesh_boundbox_calc(parent->mesh, loc, dim);
-
-	for (i = 0; i < expected_shards; i++) {
-		MeshIsland *s = NULL;
-		MeshIsland *s2 = NULL;
-		MeshIsland *t;
-		float vec[3];
-		int max_axis;
-
-		printf("Processing shard: %d\n", i);
-		t = tempshards[i];
-
-		if (t != NULL) {
-			t->parent = parent;
-			t->flag = SHARD_INTACT;
-		}
-
-		if (t == NULL) {
-			/* invalid shard, stop parsing*/
-			continue;
-		}
-
-		if (index > (t->mesh->totpoly - 1)){
-			index = 0;
-		}
-
-		//make a random vector (interpret as cutter plane)
-		vec[0] = BLI_thread_frand(0) * 2 - 1;
-		vec[1] = BLI_thread_frand(0) * 2 - 1;
-		vec[2] = BLI_thread_frand(0) * 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_mesh_bisect(*bm_parent, t, obmat, algorithm == MOD_FRACTURE_BISECT_FAST_FILL,
-									  false, true, index, centroid, inner_material_index, uv_layer, NULL, vec);
-		s2 = BKE_fracture_mesh_bisect(*bm_parent, t, obmat, algorithm == MOD_FRACTURE_BISECT_FAST_FILL,
-									   true, false, index, centroid, inner_material_index, uv_layer, NULL, vec);
-
-		index++;
-
-		if (s == NULL || s2 == NULL) {
-			printf("Shard missed....\n");
-			continue;
-		}
-
-		if (s != NULL && s2 != NULL && tempresults != NULL) {
-			int j = 0;
-
-			s->parent = parent;
-			s->flag = SHARD_INTACT;
-
-			s2->parent = parent;
-			s2->flag = SHARD_INTACT;
-
-			if (*bm_parent != NULL) {
-				BM_mesh_free(*bm_parent);
-				*bm_parent = NULL;
-			}
-
-			(*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(Mesh *), shard_sortsize, &(cells[i]));
-
-			while ((*tempresults)[j] == NULL && j < (i + 1)) {
-				/* ignore invalid shards */
-				j++;
-			}
-
-			/* continue splitting if not all expected shards exist yet */
-			if ((i + 2) < expected_shards) {
-				*bm_parent = BKE_fracture_mesh_to_bmesh((*tempresults)[j]);
-				copy_v3_v3(centroid, (*tempresults)[j]->centroid);
-
-				BKE_fracture_mesh_boundbox_calc((*tempresults)[j], loc, dim);
-				BKE_mesh_free((*tempresults)[j]);
-				(*tempresults)[j] = NULL;
-			}
-			i++;
-		}
-	}
-}
-
-static void handle_boolean_fractal(FractureModifierData *fmd, MeshIsland* parent, int expected_shards, MeshIsland* child,
-                                   Object *obj, short inner_material_index, int* i, MeshIsland ***tempresults, MeshIsland **dm_p,
-                                   Scene* scene)
+static void calculate_fast_bisect(FractureModifierData *fmd, Mesh* me, BisectContext *ctx)
 {
-	/* physics shard and fractalized shard, so we need to booleanize twice */
-	/* and we need both halves, so twice again */
-	MeshIsland *s2 = NULL;
-	MeshIsland *s = NULL;
-	int index = 0;
-	int max_retries = 3;
 	float factor = 1 - fmd->orthogonality_factor;
-
-	/*continue with "halves", randomly*/
-	if ((*i) == 0) {
-		*dm_p = parent; //BKE_fracture_mesh_island_copy(dm_parent, obj);
-	}
-
-	while (s == NULL || s2 == NULL) {
-
-		float radius;
-		float size[3];
-		float quat[4];
-		float loc[3], vec[3];
-		float min[3], max[3];
-		float one[3] = {1.0f, 1.0f, 1.0f};
-		float matrix[4][4];
-		int max_axis;
-
-		/*make a plane as cutter*/
-//		shard_boundbox(p, loc, size);
-		INIT_MINMAX(min, max);
-		BKE_mesh_minmax(*dm_p, min, max);
-
-		mid_v3_v3v3(loc, min, max);
-		size[0] = (max[0] - min[0]) / 2.0f;
-		size[1] = (max[1] - min[1]) / 2.0f;
-		size[2] = (max[2] - min[2]) / 2.0f;
-
-		radius = sqrt(size[0]*size[0] + size[1]*size[1] + size[2]*size[2]);
-
-		vec[0] = BLI_thread_frand(0) * 2 - 1;
-		vec[1] = BLI_thread_frand(0) * 2 - 1;
-		vec[2] = BLI_thread_frand(0) * 2 - 1;
-
-		//multiply two minor dimensions with a factor to emphasize the max dimension
-		max_axis = axis_dominant_v3_single(size);
-		switch (max_axis) {
-			case 0:
-				vec[1] *= factor;
-				vec[2] *= factor;
-				break;
-			case 1:


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list