[Bf-blender-cvs] [7babce30529] fracture_modifier: added "self collision" option for constraint islands, and randomize option for sphere shape radius and margin

Martin Felke noreply at git.blender.org
Sun Dec 24 16:05:36 CET 2017


Commit: 7babce30529a0fd9e21b963e836a888d44cf947d
Author: Martin Felke
Date:   Sun Dec 24 16:05:08 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rB7babce30529a0fd9e21b963e836a888d44cf947d

added "self collision" option for constraint islands, and randomize option for sphere shape radius and margin

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	release/scripts/startup/bl_ui/properties_physics_rigidbody.py
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_fracture.c
M	source/blender/makesrna/intern/rna_rigidbody.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 679e0a7c1df..87ae6fcfe71 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -699,6 +699,10 @@ class AddPresetFracture(AddPresetBase, Operator):
         "fracture.deform_angle_weighted",
         "fracture.cluster_deform_angle",
         "fracture.deform_weakening"
+        "fracture.use_centroids",
+        "fracture.use_vertices",
+        "fracture.use_self_collision",
+        "fracture.grid_resolution"
     ]
 
     preset_subdir = "fracture"
diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index 1266d81552e..d73bc99c8c3 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -195,9 +195,12 @@ class PHYSICS_PT_fracture_simulation(PhysicButtonsPanel, Panel):
         row = layout.row()
         row.prop(md, "use_constraints")
         row.prop(md, "use_breaking")
-        row = layout.row();
+        row = layout.row()
         row.prop(md, "use_constraint_collision")
+        row.prop(md, "use_self_collision")
+        row = layout.row()
         row.prop(md, "use_compounds")
+
         layout.prop(md, "constraint_target")
         col = layout.column(align=True)
         col.prop(md, "constraint_limit", text="Constraint limit, per MeshIsland")
diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index 610746d7213..9837e566154 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -118,11 +118,13 @@ class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel, Panel):
         col.label(text="Sensitivity:")
         if rbo.collision_shape in {'MESH', 'CONE'}:
             col.prop(rbo, "collision_margin", text="Margin")
+            col.prop(rbo, "use_random_margin", text="Randomize")
         else:
             col.prop(rbo, "use_margin")
             sub = col.column()
             sub.active = rbo.use_margin
             sub.prop(rbo, "collision_margin", text="Margin")
+            sub.prop(rbo, "use_random_margin", text="Randomize")
 
         layout.prop(rbo, "collision_groups")
 
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 2cc9dbc2f55..9db060c975d 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -43,6 +43,7 @@
 #include "BLI_callbacks.h"
 #include "BLI_math.h"
 #include "BLI_kdtree.h"
+#include "BLI_rand.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
@@ -3283,7 +3284,7 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
 	float hull_margin = 0.0f;
 	bool can_embed = true;
 	bool has_volume;
-	float min[3], max[3];
+	float min[3], max[3], margin;
 
 	/* sanity check */
 	if (rbo == NULL)
@@ -3322,6 +3323,9 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
 
 		/* take radius to the largest dimension to try and encompass everything */
 		radius = max_fff(size[0], size[1], size[2]) * 0.5f;
+
+		if (rbo->flag & RBO_FLAG_RANDOM_MARGIN)
+			radius = (BLI_frand() * radius) + 0.001f;
 	}
 
 	/* create new shape */
@@ -3331,7 +3335,8 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
 			break;
 
 		case RB_SHAPE_SPHERE:
-			new_shape = RB_shape_new_sphere(radius + RBO_GET_MARGIN(rbo));
+			margin = RBO_GET_MARGIN(rbo);
+			new_shape = RB_shape_new_sphere(radius + margin);
 			break;
 
 		case RB_SHAPE_CAPSULE:
@@ -3364,10 +3369,15 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
 	}
 	/* assign new collision shape if creation was successful */
 	if (new_shape) {
+		margin = RBO_GET_MARGIN(rbo);
 		if (rbo->physics_shape)
 			RB_shape_delete(rbo->physics_shape);
 		rbo->physics_shape = new_shape;
-		RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo));
+
+		if ((rbo->flag & RBO_FLAG_RANDOM_MARGIN) && (rbo->shape != RB_SHAPE_SPHERE))
+			margin = (BLI_frand() * 0.5 - 1) * margin;
+
+		RB_shape_set_margin(rbo->physics_shape, margin);
 	}
 	else { /* otherwise fall back to box shape */
 		rbo->shape = RB_SHAPE_BOX;
@@ -4020,9 +4030,24 @@ static void fake_dynamic_collide(Object *ob1, Object *ob2, MeshIsland *mi1, Mesh
 }
 
 static bool check_constraint_island(FractureModifierData* fmd, MeshIsland *mi1, MeshIsland *mi2)
-{
-	if (mi1 && mi2 && !fmd->use_compounds && !fmd->use_constraint_collision) {
-		return mi1->constraint_index != mi2->constraint_index;
+{	
+	if (mi1 && mi2 && !fmd->use_compounds && (!fmd->use_constraint_collision || fmd->use_self_collision)) {
+
+		float dist_sq = len_squared_v3v3(mi1->centroid, mi2->centroid);
+		bool is_near = len_squared_v3v3(mi1->rigidbody->pos, mi2->rigidbody->pos) < dist_sq;
+
+		if (mi1->rigidbody->physics_shape)
+		{
+			RB_shape_set_margin(mi1->rigidbody->physics_shape, is_near ? 0.0f : RBO_GET_MARGIN(mi1->rigidbody));
+		}
+
+		if (mi2->rigidbody->physics_shape)
+		{
+			RB_shape_set_margin(mi2->rigidbody->physics_shape, is_near ? 0.0f : RBO_GET_MARGIN(mi2->rigidbody));
+		}
+
+		return ((mi1->constraint_index != mi2->constraint_index) ||
+		       (fmd->use_self_collision && is_near));
 	}
 
 	return true;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 1eb417e6e8f..25b03ce9e84 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1778,6 +1778,7 @@ typedef struct FractureModifierData {
 	int use_smooth;
 	int use_greasepencil_edges;
 	int use_constraint_collision;
+	int use_self_collision;
 
 	int shards_to_islands;
 	int execute_threaded;
@@ -1820,7 +1821,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/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index eab44334eed..f09b3356a79 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -189,6 +189,8 @@ typedef enum eRigidBodyOb_Flag {
 	RBO_FLAG_PLASTIC_DISSOLVE = (1 << 15),
 	/* anti (stop) trigger flag, make simulated objects kinematic again */
 	RBO_FLAG_ANTI_TRIGGER = (1 << 16),
+	/* randomize margin for better packing (especially for spheres */
+	RBO_FLAG_RANDOM_MARGIN = (1 << 17)
 
 } eRigidBodyOb_Flag;
 
diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c
index f320a8800c5..3137b2b66cc 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -1416,12 +1416,17 @@ void RNA_def_fracture(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "use_centroids", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "use_centroids", false);
 	RNA_def_property_ui_text(prop, "Use Centroids", "Only output the meshisland centroids as vertices");
-	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
 	prop = RNA_def_property(srna, "use_vertices", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "use_vertices", false);
 	RNA_def_property_ui_text(prop, "Use Vertices", "Only output the meshisland vertices");
-	//RNA_def_property_update(prop, 0, "rna_Modifier_update");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "use_self_collision", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "use_self_collision", false);
+	RNA_def_property_ui_text(prop, "Self Collision", "Allow collisions between constraint islands");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
 	RNA_api_fracture(brna, srna);
 }
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index 2079608cfb1..8273af26aa3 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -1280,8 +1280,8 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
 	
 	prop = RNA_def_property(srna, "collision_margin", PROP_FLOAT, PROP_UNIT_LENGTH);
 	RNA_def_property_float_sdna(prop, NULL, "margin");
-	RNA_def_property_range(prop, -1.0f, 1.0f);
-	RNA_def_property_ui_range(prop, -1.0f, 1.0f, 0.01, 3);
+	RNA_def_property_range(prop, -1.0f, 10.0f);
+	RNA_def_property_ui_range(prop, -1.0f, 10.0f, 0.01, 3);
 	RNA_def_property_float_default(prop, 0.04f);
 	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_collision_margin_set", NULL);
 	RNA_def_property_ui_text(prop, "Collision Margin",
@@ -1313,6 +1313,13 @@ static void rna_def_rigidbody_object(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_QUATERNION);
 	RNA_def_property_float_sdna(prop, NULL, "orn");
 	RNA_def_property_ui_text(prop, "Rotation", "Quaternion rotation of the rigidbody object");
+
+	prop = RNA_def_property(srna, "use_random_margin", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", RBO_FLAG_RANDOM_MARGIN);
+	RNA_def_property_boolean_default(prop, false);
+	RNA_def_property_ui_text(prop, "Randomize Margin",
+	                         "Randomize the custom collision margin for better packing when shapes stack up");
+	RNA_def_property_update(prop, NC_OBJECT | ND_POINTCACHE, "rna_RigidBodyOb_shape_reset");
 }
 
 static void rna_def_rigidbody_constraint(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 8ad43b0a7de..c1934670ef5 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -256,6 +256,7 @@ static void initData(ModifierData *md)
 
 	fmd->use_centroids = fa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list