[Bf-blender-cvs] [fa7a666e2be] fracture_modifier: added grid fracture option, removed rigidbody shape drawing with fm, alembic importer fix

Martin Felke noreply at git.blender.org
Tue Dec 19 23:09:32 CET 2017


Commit: fa7a666e2be387a3d887204909d6c3c378929614
Author: Martin Felke
Date:   Tue Dec 19 23:09:01 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rBfa7a666e2be387a3d887204909d6c3c378929614

added grid fracture option, removed rigidbody shape drawing with fm, alembic importer fix

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

M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/alembic/intern/abc_customdata.cc
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_fracture.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 463a609d384..91e2ab5e2d5 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -144,6 +144,8 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
             box.label("Fracture Point Source:")
             col = box.column()
             col.prop(md, "point_source")
+            if 'GRID' in md.point_source:
+                col.prop(md, "grid_resolution")
             if 'GREASE_PENCIL' in md.point_source:
                 col.prop(md, "use_greasepencil_edges")
                 col.prop(md, "grease_offset")
diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc
index d6e7a80d174..b9d68416bb9 100644
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@ -235,17 +235,18 @@ static void read_uvs(const CDStreamConfig &config, void *data,
 	MPoly *mpolys = config.mpoly;
 	MLoopUV *mloopuvs = static_cast<MLoopUV *>(data);
 
-	unsigned int uv_index, loop_index;
+	unsigned int uv_index, loop_index, rev_loop_index;
 
 	for (int i = 0; i < config.totpoly; ++i) {
 		MPoly &poly = mpolys[i];
 
 		for (int f = 0; f < poly.totloop; ++f) {
+			rev_loop_index = poly.loopstart + poly.totloop - f - 1;
 			loop_index = poly.loopstart + f;
 			uv_index = (*indices)[loop_index];
 			const Imath::V2f &uv = (*uvs)[uv_index];
 
-			MLoopUV &loopuv = mloopuvs[loop_index];
+			MLoopUV &loopuv = mloopuvs[rev_loop_index];
 			loopuv.uv[0] = uv[0];
 			loopuv.uv[1] = uv[1];
 		}
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index fad1258444e..4ac0c3ee556 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1125,7 +1125,6 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 	}
 
 	unit_m4(obmat);
-
 	do_prepare_cells(fm, cells, expected_shards, algorithm, p, &centroid, &dm_parent, &bm_parent, &tempshards, &tempresults, override_count, fmd);
 
 	if (fm->last_shard_tree)
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 59375399aa2..9152f3d7e1f 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -7415,6 +7415,7 @@ static void draw_rigidbody_shape(Object *ob)
 	BoundBox *bb = NULL;
 	float size[3], vec[8][3];
 	DerivedMesh *dm = ob->derivedFinal;
+	FractureModifierData *fmd = modifiers_findByType(ob, eModifierType_Fracture);
 
 	if (ob->type == OB_MESH) {
 		bb = BKE_mesh_boundbox_get(ob);
@@ -7423,6 +7424,9 @@ static void draw_rigidbody_shape(Object *ob)
 	if (bb == NULL)
 		return;
 
+	if (fmd)
+		return;
+
 	switch (ob->rigidbody_object->shape) {
 		case RB_SHAPE_BOX:
 			BKE_boundbox_calc_size_aabb(bb, size);
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 12e14268bbc..ed223015daf 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1534,6 +1534,7 @@ enum {
 	MOD_FRACTURE_EXTRA_PARTICLES = (1 << 3),
 	MOD_FRACTURE_GREASEPENCIL    = (1 << 4),
 	MOD_FRACTURE_UNIFORM         = (1 << 5),
+	MOD_FRACTURE_GRID            = (1 << 6),
 };
 
 enum {
@@ -1729,6 +1730,7 @@ typedef struct FractureModifierData {
 	int boolean_solver;
 	int dynamic_percentage;
 	int constraint_type;
+	int grid_resolution[3];
 
 	float breaking_angle;
 	float breaking_distance;
@@ -1816,7 +1818,7 @@ typedef struct FractureModifierData {
 	short mat_ofs_intersect;
 	short mat_ofs_difference;
 
-	//char pad[4];
+	char pad[4];
 } FractureModifierData;
 
 typedef struct DataTransferModifierData {
diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c
index 27dc9bd1853..d0c777f9109 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -693,6 +693,7 @@ void RNA_def_fracture(BlenderRNA *brna)
 		{MOD_FRACTURE_EXTRA_VERTS, "EXTRA_VERTS", 0, "Extra Vertices", "Use vertices of group objects as point cloud"},
 		{MOD_FRACTURE_GREASEPENCIL, "GREASE_PENCIL", 0, "Grease Pencil", "Use grease pencil points as point cloud"},
 		{MOD_FRACTURE_UNIFORM, "UNIFORM", 0, "Uniform", "Use a random uniform pointcloud generated over the bounding box"},
+		{MOD_FRACTURE_GRID, "GRID", 0, "Grid", "Use a grid pointcloud generated over the bounding box"},
 		{0, NULL, 0, NULL, NULL}
 	};
 
@@ -1403,5 +1404,14 @@ void RNA_def_fracture(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "grid_resolution", PROP_INT, PROP_XYZ);
+	RNA_def_property_int_sdna(prop, NULL, "grid_resolution");
+	RNA_def_property_range(prop, 1, 10000);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_int_default(prop, 10);
+	RNA_def_property_ui_text(prop, "Grid resolution", "How many grid cells per Bounding Box Axis");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	RNA_api_fracture(brna, srna);
 }
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 4c772a1abe5..f5c72969799 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -249,6 +249,10 @@ static void initData(ModifierData *md)
 
 	fmd->deform_weakening = 0.0f;
 	fmd->distortion_cached = false;
+
+	fmd->grid_resolution[0] = 10;
+	fmd->grid_resolution[1] = 10;
+	fmd->grid_resolution[2] = 10;
 }
 
 //XXX TODO, freeing functionality should be in BKE too
@@ -1290,6 +1294,66 @@ static FracPointCloud get_points_global(FractureModifierData *emd, Object *ob, D
 		}
 	}
 
+	if (emd->point_source & MOD_FRACTURE_GRID)
+	{
+		float cent[3], bmin[3], bmax[3];
+		int x, y, z;
+
+		if (emd->grid_resolution[0] < 1)
+		{	//sanity check
+			emd->grid_resolution[0] = 1;
+		}
+
+		if (emd->grid_resolution[1] < 1)
+		{	//sanity check
+			emd->grid_resolution[1] = 1;
+		}
+
+		if (emd->grid_resolution[2] < 1)
+		{	//sanity check
+			emd->grid_resolution[2] = 1;
+		}
+
+		//just draw over bbox
+		INIT_MINMAX(min, max);
+		//for limit impact we need entire container always, because we need to determine secondary impacts on the shards at their original pos
+		if (!BKE_get_shard_minmax(emd->frac_mesh, id, min, max, fracmesh))
+			return points; //id 0 should be entire mesh
+
+		//arrange shards according to their original centroid (parent centroid sum) position in shard-space (else they are centered at 0, 0, 0)
+		arrange_shard(emd, id, false, cent);
+		add_v3_v3v3(bmax, max, cent);
+		add_v3_v3v3(bmin, min, cent);
+
+		//centroid of grid cells is
+		for (x = 0; x < emd->grid_resolution[0]; ++x) {
+			for (y = 0; y < emd->grid_resolution[1]; ++y) {
+				for (z = 0; z < emd->grid_resolution[2]; ++z) {
+					float co[3];
+					co[0] = min[0] + (max[0] - min[0]) * ((float)x + 0.5f)/(float)emd->grid_resolution[0];
+					co[1] = min[1] + (max[1] - min[1]) * ((float)y + 0.5f)/(float)emd->grid_resolution[1];
+					co[2] = min[2] + (max[2] - min[2]) * ((float)z + 0.5f)/(float)emd->grid_resolution[2];
+
+					if (id > 0 && emd->cutter_group == NULL)
+					{
+						if (in_bbox(co, bmin, bmax))
+						{
+							points.points = MEM_reallocN(points.points, sizeof(FracPoint) * (points.totpoints + 1));
+							copy_v3_v3(points.points[points.totpoints].co, co);
+							points.totpoints++;
+						}
+					}
+					else
+					{
+						points.points = MEM_reallocN(points.points, sizeof(FracPoint) * (points.totpoints + 1));
+						copy_v3_v3(points.points[points.totpoints].co, co);
+						points.totpoints++;
+					}
+				}
+			}
+		}
+	}
+
 	MEM_freeN(go);
 	return points;
 }
@@ -1784,6 +1848,8 @@ static void copyData(ModifierData *md, ModifierData *target)
 	trmd->cluster_deform_distance = rmd->cluster_deform_distance;
 	trmd->deform_weakening = rmd->deform_weakening;
 	trmd->distortion_cached = rmd->distortion_cached;
+
+	copy_v3_v3_int(trmd->grid_resolution, rmd->grid_resolution);
 }
 
 //XXXX TODO, is BB really useds still ? aint there exact volume calc now ?



More information about the Bf-blender-cvs mailing list