Commit: 61ca70df405827cc1493e6e67fdd5003605314e8
Author: Martin Felke
Date: Tue Feb 17 21:37:55 2015 +0100
Branches: fracture_modifier
https://developer.blender.org/rB61ca70df405827cc1493e6e67fdd5003605314e8
added cutter groups, this is intended to define custom sets of objects to make
boolean cuts against, but its still WIP, as it still fails too often
===================================================================
M release/scripts/startup/bl_ui/properties_physics_fracture.py
M source/blender/blenkernel/BKE_fracture.h
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/fracture_util.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.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 a69b705..25ab354 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -71,6 +71,8 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
sub.operator("fracture.preset_add", text="",
icon='ZOOMOUT').remove_active = True
layout.prop(md, "frac_algorithm")
+ if md.frac_algorithm == 'BOOLEAN':
+ layout.prop(md, "cutter_group")
col = layout.column(align=True)
col.prop(md, "shard_count")
col.prop(md, "cluster_count")
diff --git a/source/blender/blenkernel/BKE_fracture.h
b/source/blender/blenkernel/BKE_fracture.h
index e88166b..c513d1e 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -40,6 +40,7 @@ struct Shard;
struct FractureModifierData;
struct DerivedMesh;
struct Object;
+struct Group;
struct BoundBox;
struct MVert;
@@ -81,9 +82,11 @@ void BKE_shard_free(struct Shard *s, bool doCustomData);
void BKE_fracture_create_dm(struct FractureModifierData *fmd, bool
doCustomData);
struct DerivedMesh *BKE_shard_create_dm(struct Shard *s, bool doCustomData);
-/* create shards from base mesh and a liste of points */
+/* create shards from base mesh and a list of points */
void BKE_fracture_shard_by_points(struct FracMesh *fmesh, ShardID id, struct
FracPointCloud *points, int algorithm,
struct Object *obj, struct DerivedMesh *dm,
short inner_material_index, float mat[4][4], int num_cuts, float fractal, bool
smooth, int num_levels);
+/* create shards from a base mesh and a set of other objects / cutter planes */
+void BKE_fracture_shard_by_planes(struct FractureModifierData *fmd, struct
Object *obj, short inner_material_index, float mat[4][4]);
#endif /* BKE_FRACTURE_H */
diff --git a/source/blender/blenkernel/intern/fracture.c
b/source/blender/blenkernel/intern/fracture.c
index e7f37f9..97cb54b 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -817,7 +817,148 @@ static void parse_cell_neighbors(cell c, int *neighbors,
int totpoly)
}
}
-void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud
*pointcloud, int algorithm, Object *obj, DerivedMesh *dm, short
inner_material_index, float mat[4][4], int num_cuts, float fractal, bool
smooth, int num_levels) {
+void BKE_fracture_shard_by_planes(FractureModifierData *fmd, Object *obj,
short inner_material_index, float mat[4][4])
+{
+ DerivedMesh *dm_parent = NULL;
+ int shards = 0;
+
+ if (fmd->frac_algorithm == MOD_FRACTURE_BOOLEAN && fmd->cutter_group !=
NULL && obj->type == OB_MESH)
+ {
+ GroupObject* go;
+ float imat[4][4];
+
+ invert_m4_m4(imat, obj->obmat);
+
+ for (go = fmd->cutter_group->gobject.first; go; go = go->next)
+ {
+ Object* ob = go->ob;
+ Shard *s2 = NULL;
+ Shard *t = NULL;
+ Shard *s = NULL;
+
+ /*simple case....one cutter object per object*/
+ if (ob->type == OB_MESH)
+ {
+ int i = 0, j = 0, k = 0, count = 0;
+ DerivedMesh *d;
+ MVert *mv;
+
+ d = ob->derivedFinal;
+ if (d == NULL)
+ {
+ d = CDDM_from_mesh(ob->data);
+ }
+
+ t =
BKE_create_fracture_shard(d->getVertArray(d), d->getPolyArray(d),
d->getLoopArray(d),
+
d->getNumVerts(d), d->getNumPolys(d), d->getNumLoops(d), true);
+ t = BKE_custom_data_to_shard(t, d);
+
+ /*complicated cases, self intersecting planes
which could be separated by loose first */
+ /*omit for now */
+
+ for (i = 0, mv = t->mvert; i < t->totvert;
mv++, i++){
+ mul_m4_v3(ob->obmat, mv->co);
+ mul_m4_v3(imat, mv->co);
+ }
+
+ count = fmd->frac_mesh->shard_count;
+
+ if (count == 0)
+ {
+ if (obj->derivedFinal != NULL)
+ {
+ dm_parent =
CDDM_copy(obj->derivedFinal);
+ }
+
+ if (dm_parent == NULL) {
+ dm_parent =
CDDM_from_mesh(obj->data);
+ }
+
+ count = 1;
+ }
+
+ for (k = 0; k < count; k++)
+ {
+ /*just keep appending items at the end
here */
+
+ MPoly *mpoly, *mp;
+ int totpoly, totvert;
+ Shard *parent = NULL;
+
+ if (count > 1)
+ {
+ parent =
BLI_findlink(&fmd->frac_mesh->shard_map, k);
+ dm_parent =
BKE_shard_create_dm(parent, true);
+ }
+
+ totvert =
dm_parent->getNumVerts(dm_parent);
+ mpoly =
dm_parent->getPolyArray(dm_parent);
+ totpoly =
dm_parent->getNumPolys(dm_parent);
+ for (i = 0, mp = mpoly; i < totpoly;
i++, mp++) {
+ mp->flag &= ~ME_FACE_SEL;
+ }
+
+ s = BKE_fracture_shard_boolean(obj,
dm_parent, t, inner_material_index, 0, 0.0f, &s2, NULL, 0.0f, false, 0);
+ if (s != NULL)
+ {
+ add_shard(fmd->frac_mesh, s,
mat);
+ shards++;
+ s = NULL;
+ }
+
+ if (s2 != NULL)
+ {
+ add_shard(fmd->frac_mesh, s2,
mat);
+ shards++;
+ s2 = NULL;
+ }
+
+ if ((count == 1 && ob->derivedFinal ==
NULL) || (count > 1))
+ {
+ if (count == 1)
+ {
+ count = 0;
+ }
+
+ dm_parent->needsFree = 1;
+ dm_parent->release(dm_parent);
+ dm_parent = NULL;
+ }
+
+ //shards--;
+ }
+
+ count = fmd->frac_mesh->shard_count;
+
+ /*new count - shards = shards to remove*/
+ for (k = 0; k < count-shards; k++)
+ {
+ /*clean up old entries here to avoid
unnecessary shards*/
+ Shard *first =
fmd->frac_mesh->shard_map.first;
+
BLI_remlink_safe(&fmd->frac_mesh->shard_map,first);
+ BKE_shard_free(first, true);
+ first = NULL;
+ fmd->frac_mesh->shard_count--;
+ }
+
+ shards = 0;
+
+ BKE_shard_free(t, true);
+ if (ob->derivedFinal == NULL)
+ { /*was copied before */
+ d->needsFree = 1;
+ d->release(d);
+ d = NULL;
+ }
+
+ j++;
+ }
+ }
+ }
+}
+
+void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud
*pointcloud, int algorithm, Object *obj, DerivedMesh *dm, short
+ inner_material_index, float mat[4][4], int
num_cuts, float fractal, bool smooth, int num_levels) {
int n_size = 8;
Shard *shard;
diff --git a/source/blender/blenkernel/intern/fracture_util.c
b/source/blender/blenkernel/intern/fracture_util.c
index e4dbe08..a9551e4 100644
--- a/source/blender/blenkernel/intern/fracture_util.c
+++ b/source/blender/blenkernel/intern/fracture_util.c
@@ -212,7 +212,7 @@ static bool check_non_manifold(DerivedMesh* dm)
/*check for watertightness*/
bm = DM_to_bmesh(dm, true);
- if (bm->totface < 4) {
+ if (bm->totface == 0) {
BM_mesh_free(bm);
printf("Empty mesh...\n");
return true;
@@ -274,12 +274,12 @@ static bool compare_dm_size(DerivedMesh *dmOld,
DerivedMesh *dmNew)
v2 = size[0] * size[1] * size[2];
- if (v2 >= v1)
+ if (v2 > (v1 + 0.000001))
{
printf("Size mismatch !\n");
}
- return v2 < v1;
+ return v2 <= (v1 + 0.000001);
}
Shard *BKE_fracture_shard_boolean(Object *obj, DerivedMesh *dm_parent, Shard
*child, short inner_material_index, int num_cuts, float fractal, Shard** other,
float mat[4][4], float radius, bool use_smooth_inner, int num_levels)
@@ -292,7 +292,7 @@ Shard *BKE_fracture_shard_boolean(Object *obj, DerivedMesh
*dm_parent, Shard *ch
BMFace* f;
BMIter iter;
- if (other != NULL)
+ if (other != NULL && mat != NULL)
{
/*create a grid plane */
@@ -343,7 +343,7 @@ Shard *BKE_fracture_shard_boolean(Object *obj, DerivedMesh
*dm_parent, Shard *ch
}
/* set inner material on child shard */
- if (other == NULL)
+ if (other == NULL || mat == NULL)
{
mpoly = left_dm->getPolyArray(left_dm);
totpoly = left_dm->getNumPolys(left_dm);
@@ -360,15 +360,18 @@ Shard *BKE_fracture_shard_boolean(Object *obj,
DerivedMesh *dm_parent, Shard *ch
/*check for watertightness*/
if (!output_dm || check_non_manifold(output_dm) ||
!compare_dm_size(right_dm, output_dm)) {
- if (other != NULL)
- *other = NULL;
- if (bm != NULL)
- BM_mesh_free(bm);
+ if (mat != NULL)
+ {
+ if (other != NULL)
+ *other = NULL;
+ if (bm != NULL)
+ BM_mesh_free(bm);
- if (left_dm != NULL) {
- left_dm->needsFree = 1;
- left_dm->release(left_dm);
- left_dm = NULL;
+ if (left_dm != NULL) {
+ left_dm->needsFree = 1;
+ left_dm->release(left_dm);
+ left_dm = NULL;
+ }
}
if (output_dm != NULL) {
@@ -376,13 +379,22 @@ Shard *BKE_fracture_shard_boolean(Object *obj,
DerivedMesh *dm_parent, Shard *ch
output_dm->release(output_dm);
output_dm = NULL;
}
- return NULL;
+
+ if (mat != NULL)
+ {
+ return NULL;
+ }
}
- if (other != NULL && bm != NULL)
+ if (other != NULL)
{
+ if (bm == NULL)
+ {
+ bm = DM_to_bmesh(left_dm, true);
+ }
+
BMO_op_callf(bm, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE),
- "reverse_faces faces=af");
+ "reverse_faces faces=af");
left_dm->needsFree = 1;
left_dm->release(left_dm);
@@ -408,12 +420,17 @@ Shard *BKE_fracture_shard_boolean(Object *obj,
DerivedMesh *dm_parent, Shard *ch
other_dm->release(other_dm);
other_dm = NULL;
}
- if (output_dm != NULL) {
- output_dm->needsFree = 1;
- output_dm->release(output_dm);
- output_dm = NULL;
+
+ /*discard only at fractal boolean */
+ if (mat != NULL)
+ {
+ if (output_dm != NULL) {
+ output_dm->needsFree = 1;
+ output_dm->release(output_dm);
+ output_dm = NULL;
+ }
+ return NULL;
}
- return NULL;
}
if (other_dm)
@@ -456,18 +473,26 @@ Shard *BKE_fracture_shard_boolean(Object *obj,
DerivedMesh *dm_parent, Shard *ch
other_dm->release(other_dm);
other_dm = NULL;
}
- if (output_dm != NULL) {
- output_dm->needsFree = 1;
- output_dm->release(output_dm);
- output_dm = NULL;
+
+ /*discard only at fractal boolean */
+ if (mat != NULL)
+ {
+ if (output_dm != NULL) {
+ output_dm->needsFree = 1;
+ output_dm->release(output_dm);
+ output_dm = NULL;
+ }
+ return NULL;
}
- return NULL;
}
}
- left_dm->needsFree = 1;
- left_dm->release(left_dm);
- left_dm = NULL;
+ if (left_dm)
+ {
+ left_dm->needsFree =
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs