[Bf-blender-cvs] [fc4fc38b22b] fracture_modifier-master: added comments to most functions

Martin Felke noreply at git.blender.org
Wed Jun 13 12:49:31 CEST 2018


Commit: fc4fc38b22b7602d9567c02e2a272f9291bff1dc
Author: Martin Felke
Date:   Wed Jun 13 12:48:39 2018 +0200
Branches: fracture_modifier-master
https://developer.blender.org/rBfc4fc38b22b7602d9567c02e2a272f9291bff1dc

added comments to most functions

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

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 0e19eb09f12..4e73eba81c8 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -95,6 +95,9 @@ static void parse_cell_neighbors(cell c, int *neighbors, int totpoly);
 static void fracture_collect_layers(Shard *shard, DerivedMesh *result, int vertstart, int polystart, int loopstart, int edgestart);
 static void remove_participants(RigidBodyShardCon *con, MeshIsland *mi);
 
+/* Append the given shard to the end of the shardmap. Shard Map should contain a list of the resulting shards of a fracture
+ * operation. Transform all vertices and centroid with the matrix parameter, e.g. to get to local space or world space
+ * (TODO need to check callers where what applies */
 static void add_shard(FracMesh *fm, Shard *s, float mat[4][4])
 {
 	MVert *mv;
@@ -112,6 +115,8 @@ static void add_shard(FracMesh *fm, Shard *s, float mat[4][4])
 	fm->shard_count++;
 }
 
+/* Convert the given Shard via DerivedMesh to BMesh. Used for splitting loose islands via the faster recursive halving
+ * mechanism. This executes split_loose in each recursion step only on smaller mesh portions TODO, check callers */
 static BMesh *shard_to_bmesh(Shard *s)
 {
 	DerivedMesh *dm_parent;
@@ -136,6 +141,7 @@ static BMesh *shard_to_bmesh(Shard *s)
 	return bm_parent;
 }
 
+/* Copied from mesh boundbox calculation, perform operation on shard */
 static void shard_boundbox(Shard *s, float r_loc[3], float r_size[3])
 {
 	float min[3], max[3];
@@ -159,6 +165,8 @@ static void shard_boundbox(Shard *s, float r_loc[3], float r_size[3])
 	r_size[2] = (max[2] - min[2]) / 2.0f;
 }
 
+/* Sort shards by distance of their centroids. Shards closer to each other will be processed first / earlier
+ * Again, TODO Check Caller for context */
 static int shard_sortdist(const void *s1, const void *s2, void* context)
 {
 	Shard **sh1 = (Shard **)s1;
@@ -180,6 +188,7 @@ static int shard_sortdist(const void *s1, const void *s2, void* context)
 	return 0;
 }
 
+/* Sort shards by squared diameter of their bbox as size approximation */
 static int shard_sortsize(const void *s1, const void *s2, void* UNUSED(context))
 {
 	Shard **sh1 = (Shard **)s1;
@@ -205,6 +214,7 @@ static int shard_sortsize(const void *s1, const void *s2, void* UNUSED(context))
 	return 0;
 }
 
+/* Checks for missing custom data layers and adds them, if missing */
 void* check_add_layer(CustomData *src, CustomData *dst, int type, int totelem, const char* name)
 {
 	void *layer =  CustomData_get_layer_named(dst, type, name);
@@ -228,6 +238,7 @@ void* check_add_layer(CustomData *src, CustomData *dst, int type, int totelem, c
 	}
 }
 
+/* Copy over customdata layers from DerivedMesh to Shard, additionally add velocity vertex (float) layers (for motionblur (TODO, check Caller ))*/
 Shard *BKE_custom_data_to_shard(Shard *s, DerivedMesh *dm)
 {
 	CustomData_reset(&s->vertData);
@@ -467,6 +478,9 @@ float BKE_shard_calc_minmax(Shard *shard)
 	return len_v3(diff);
 }
 
+/* Turns the entire initial mesh into the first shard, covering everything of the mesh.
+ * flag marks this as intact shard (still valid in sim, FRACTURED would be a shard if replaced by its children, about to be
+ * deleted or already deleted, TODO check caller */
 Shard* BKE_create_initial_shard(DerivedMesh *dm)
 {
 	/* create temporary shard covering the entire mesh */
@@ -478,6 +492,7 @@ Shard* BKE_create_initial_shard(DerivedMesh *dm)
 	return s;
 }
 
+/* Deep copy of shard, including customdata layers */
 Shard* BKE_fracture_shard_copy(Shard *s)
 {
 	Shard *t = BKE_create_fracture_shard(s->mvert, s->mpoly, s->mloop, s->medge, s->totvert, s->totpoly, s->totloop, s->totedge, true);
@@ -537,6 +552,7 @@ Shard *BKE_shard_by_id(FracMesh *mesh, ShardID id, DerivedMesh *dm) {
 	return NULL;
 }
 
+/* gets the min and max if shard exists, if it was the intial shard, delete it here (why, check caller, TODO */
 bool BKE_get_shard_minmax(FracMesh *mesh, ShardID id, float min_r[3], float max_r[3], DerivedMesh *dm)
 {
 	Shard *shard = BKE_shard_by_id(mesh, id, dm);
@@ -555,6 +571,8 @@ bool BKE_get_shard_minmax(FracMesh *mesh, ShardID id, float min_r[3], float max_
 	return false;
 }
 
+/* Create a shard from Mesh / DerivedMesh elements, in most cases copy is true, means it will duplicate everything
+ * TODO is there a case with copy = false still at all ? */
 Shard *BKE_create_fracture_shard(MVert *mvert, MPoly *mpoly, MLoop *mloop, MEdge* medge,  int totvert, int totpoly,
                                  int totloop, int totedge, bool copy)
 {
@@ -601,6 +619,7 @@ Shard *BKE_create_fracture_shard(MVert *mvert, MPoly *mpoly, MLoop *mloop, MEdge
 	return shard;
 }
 
+/* create the FracMesh container where the shards live */
 FracMesh *BKE_create_fracture_container(void)
 {
 	FracMesh *fmesh;
@@ -609,8 +628,8 @@ FracMesh *BKE_create_fracture_container(void)
 	fmesh->shard_map.first = NULL;
 	fmesh->shard_map.last = NULL;
 	fmesh->shard_count = 0;
-	fmesh->cancel = 0;
-	fmesh->running = 0;
+	fmesh->cancel = 0; // remainder of threading attempt with Job system, to be able to cancel long running fractures
+	fmesh->running = 0; // remainder of threading attempt with Job system
 	fmesh->progress_counter = 0;
 	fmesh->last_shards = NULL;
 	fmesh->last_shard_tree = NULL;
@@ -619,6 +638,8 @@ FracMesh *BKE_create_fracture_container(void)
 	return fmesh;
 }
 
+/* Fast bisect is a method which just uses one random face of a voronoi cell as cutter plane; this will cut the mesh in two halves;
+ * and keep both halves if the cut was successful; eg the mesh was not missed etc */
 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, float fac, Shard* parent)
@@ -665,6 +686,7 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 		vec[2] = BLI_frand() * 2 - 1;
 
 		//multiply two minor dimensions with a factor to emphasize the max dimension
+		/* This is an attempt to actually get axial cuts, means 90 degree "straight" cuts, not angled */
 		max_axis = axis_dominant_v3_single(dim);
 		switch (max_axis) {
 			case 0:
@@ -716,6 +738,8 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 			(*tempresults)[i + 1] = s2;
 
 			//BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortdist, &(cells[i]));
+
+			/*prefer bigger shards for cutting here, so sort bigger ones to the front of the array */
 			BLI_qsort_r(*tempresults, i + 1, sizeof(Shard *), shard_sortsize, &(cells[i]));
 
 			while ((*tempresults)[j] == NULL && j < (i + 1)) {
@@ -737,6 +761,10 @@ static void handle_fast_bisect(FracMesh *fm, int expected_shards, int algorithm,
 	}
 }
 
+/* Fractal boolean, this works with Quad Grids as cutter planes, the higher the num_cuts, the more smaller quads (the slower)
+ * Grid subdivision is supposed to subdivide the inner faces of resulting geometry. Cutting happens plane-based, so halve, halve the halves and so on.
+ * Actually the cutter planes are already subdivided, and can have fractal displacement on them. They will cut the geometry into 2 matching displaced halves.
+ * (using boolean cuts). Note: has still issues with proper autohide etc, TODO */
 static void handle_boolean_fractal(Shard* p, Shard* t, int expected_shards, DerivedMesh* dm_parent, Object *obj, short inner_material_index,
                                    int num_cuts, float fractal, int num_levels, bool smooth,int parent_id, int* i, Shard ***tempresults,
                                    DerivedMesh **dm_p, char uv_layer[64], int thresh, float fac)
@@ -782,6 +810,7 @@ static void handle_boolean_fractal(Shard* p, Shard* t, int expected_shards, Deri
 		vec[2] = BLI_frand() * 2 - 1;
 
 		//multiply two minor dimensions with a factor to emphasize the max dimension
+		/* same idea as with fast bisect, try to get 90 degree angles between the cutter planes */
 		max_axis = axis_dominant_v3_single(size);
 		switch (max_axis) {
 			case 0:
@@ -829,6 +858,7 @@ static void handle_boolean_fractal(Shard* p, Shard* t, int expected_shards, Deri
 		s2->flag = SHARD_INTACT;
 		(*tempresults)[*i] = s2;
 
+		/* and also prefer bigger shards first */
 		BLI_qsort_r(*tempresults, (*i) + 1, sizeof(Shard *), shard_sortsize, i);
 		while ((*tempresults)[j] == NULL && j < ((*i) + 1)) {
 			/* ignore invalid shards */
@@ -856,6 +886,8 @@ static void handle_boolean_fractal(Shard* p, Shard* t, int expected_shards, Deri
 	}
 }
 
+/* Use bisect instead of boolean cuts for intersecting with the original geometry, to allow also nonmanifold geometry. Note, filling methods
+ * might be less reliable than with boolean cuts. This method also handles boolean cuts, should better be properly split up TODO*/
 static bool handle_boolean_bisect(FracMesh *fm, Object *obj, int expected_shards, int algorithm, int parent_id, Shard **tempshards,
                                   DerivedMesh *dm_parent, BMesh* bm_parent, float obmat[4][4], short inner_material_index, int num_cuts,
                                   int num_levels, float fractal, int *i, bool smooth, Shard*** tempresults, DerivedMesh **dm_p, char uv_layer[64],
@@ -909,6 +941,12 @@ static bool handle_boolean_bisect(FracMesh *fm, Object *obj, int expected_shards
 	return false;
 }
 
+/* Here attempts are made to keep track of unchanged raw cells which potentially will lead to unchanged intersected cells, avoiding expensive
+ * boolean or bisect cuts. Mainly should be used together with "Mouse based" fracture, which interactively fractures on mouse click / drag (done via the addon)
+ * TODO, better comment ?)
+ * To determine shards being the same, their centroid positions and volumes are compared as approximation. Then skip and deletemaps to determine which shards dont
+ * refractures respectively which shards need to be removed are created */
+
 static void do_prepare_cells(FracMesh *fm, cell *cells, int expected_shards, int algorith

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list