[Bf-blender-cvs] [c77878ababf] fracture_modifier: added final solid mesh source for mesh, some sphere margin fixes
Martin Felke
noreply at git.blender.org
Tue Dec 26 17:41:05 CET 2017
Commit: c77878ababf65159351900a0299c0d9aad71d62a
Author: Martin Felke
Date: Tue Dec 26 17:40:40 2017 +0100
Branches: fracture_modifier
https://developer.blender.org/rBc77878ababf65159351900a0299c0d9aad71d62a
added final solid mesh source for mesh, some sphere margin fixes
===================================================================
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/makesdna/DNA_rigidbody_types.h
M source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 11cb0430e90..2bcb8b365be 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -78,6 +78,7 @@
#include "BKE_depsgraph.h"
#include "BKE_scene.h"
#include "PIL_time.h"
+#include "bmesh.h"
#ifdef WITH_BULLET
@@ -278,6 +279,36 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(const Object *ob)
return rbcN;
}
+/* although this may be slow, it also may help to correct the mesh bounding problem */
+static DerivedMesh* dm_solidify(DerivedMesh *dm, float thickness)
+{
+ DerivedMesh *result = NULL;
+ BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default, &((struct BMeshCreateParams){.use_toolflags = true,}));
+ BMOperator bmop;
+
+ DM_to_bmesh_ex(dm, bm, true);
+
+ BMO_op_initf(bm, &bmop, BMO_FLAG_DEFAULTS, "solidify geom=%af thickness=%f", thickness);
+
+ /* deselect only the faces in the region to be solidified (leave wire
+ * edges and loose verts selected, as there will be no corresponding
+ * geometry selected below) */
+ BMO_slot_buffer_hflag_disable(bm, bmop.slots_in, "geom", BM_FACE, BM_ELEM_SELECT, true);
+
+ /* run the solidify operator */
+ BMO_op_exec(bm, &bmop);
+
+ /* select the newly generated faces */
+ BMO_slot_buffer_hflag_enable(bm, bmop.slots_out, "geom.out", BM_FACE, BM_ELEM_SELECT, true);
+
+ BMO_op_finish(bm, &bmop);
+
+ result = CDDM_from_bmesh(bm, true);
+ BM_mesh_free(bm);
+
+ return result;
+}
+
/* ************************************** */
/* Setup Utilities - Validate Sim Instances */
@@ -290,6 +321,10 @@ static DerivedMesh *rigidbody_get_mesh(Object *ob)
else if (ob->rigidbody_object->mesh_source == RBO_MESH_FINAL) {
return ob->derivedFinal;
}
+ else if (ob->rigidbody_object->mesh_source == RBO_MESH_FINAL_SOLID)
+ {
+ return dm_solidify(ob->derivedFinal, ob->rigidbody_object->margin);
+ }
else {
return CDDM_from_mesh(ob->data);
}
@@ -3269,7 +3304,7 @@ static rbCollisionShape *rigidbody_get_shape_trimesh_from_mesh(Object *ob)
}
/* cleanup temp data */
- if (ob->rigidbody_object->mesh_source == RBO_MESH_BASE) {
+ if (ob->rigidbody_object->mesh_source == RBO_MESH_BASE || ob->rigidbody_object->mesh_source == RBO_MESH_FINAL_SOLID) {
dm->release(dm);
}
}
@@ -3334,10 +3369,8 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
else if (rbo->shape == RB_SHAPE_SPHERE) {
/* 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;
+ radius = (rbo->flag & RBO_FLAG_USE_MARGIN) ? min_fff(size[0], size[1], size[2]) :
+ max_fff(size[0], size[1], size[2]);
}
/* create new shape */
@@ -3347,7 +3380,9 @@ void BKE_rigidbody_validate_sim_shard_shape(MeshIsland *mi, Object *ob, short re
break;
case RB_SHAPE_SPHERE:
- margin = RBO_GET_MARGIN(rbo);
+ margin = (rbo->flag & RBO_FLAG_USE_MARGIN) ? rbo->margin : 0.0f;
+ margin = (rbo->flag & RBO_FLAG_RANDOM_MARGIN) ? BLI_frand() * margin : margin;
+
new_shape = RB_shape_new_sphere(radius + margin);
break;
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index f09b3356a79..5cf0fc4c16e 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -222,7 +222,9 @@ typedef enum eRigidBody_MeshSource {
/* only deformations */
RBO_MESH_DEFORM,
/* final derived mesh */
- RBO_MESH_FINAL
+ RBO_MESH_FINAL,
+ /* solidifed final mesh (physics only) */
+ RBO_MESH_FINAL_SOLID
} eRigidBody_MeshSource;
/* ******************************** */
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index 8273af26aa3..a2c5c0374e1 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -83,6 +83,7 @@ static EnumPropertyItem rigidbody_mesh_source_items[] = {
{RBO_MESH_BASE, "BASE", 0, "Base", "Base mesh"},
{RBO_MESH_DEFORM, "DEFORM", 0, "Deform", "Deformations (shape keys, deform modifiers)"},
{RBO_MESH_FINAL, "FINAL", 0, "Final", "All modifiers"},
+ {RBO_MESH_FINAL_SOLID, "FINAL_SOLID", 0, "Final Solid", "All modifiers and solidified by margin"},
{0, NULL, 0, NULL, NULL}};
#endif
More information about the Bf-blender-cvs
mailing list