[Bf-blender-cvs] [289a8a59c8d] temp-fracture-modifier-2.8: complete rewrite of ugly code pieces, work in progress
Martin Felke
noreply at git.blender.org
Tue Aug 14 23:21:54 CEST 2018
Commit: 289a8a59c8d3edd67d1b326b2f327a09ff471617
Author: Martin Felke
Date: Tue Aug 14 23:21:44 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB289a8a59c8d3edd67d1b326b2f327a09ff471617
complete rewrite of ugly code pieces, work in progress
===================================================================
M source/blender/blenkernel/BKE_fracture.h
M source/blender/blenkernel/BKE_fracture_util.h
M source/blender/blenkernel/intern/fracture.c
M source/blender/blenkernel/intern/fracture_automerge.c
M source/blender/blenkernel/intern/fracture_prefractured.c
M source/blender/blenkernel/intern/fracture_util.c
M source/blender/makesdna/DNA_fracture_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index 1a9453be3d7..899ebe7d4e9 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -204,7 +204,7 @@ void BKE_fracture_dynamic_free(struct FractureModifierData *fmd, struct Scene *s
void BKE_fracture_external_constraints_setup(struct FractureModifierData *fmd, struct Scene *scene, struct Object *ob);
void BKE_fracture_dynamic_new_entries_add(struct FractureModifierData* fmd, struct Scene *scene, bool is_new);
-struct Mesh* BKE_fracture_apply(struct FractureModifierData *fmd, struct Object *ob, struct Mesh *me, struct Depsgraph* depsgraph);
+struct Mesh* BKE_fracture_apply(struct FractureModifierData *fmd, struct Object *obj, struct Mesh *me, struct Depsgraph* depsgraph);
struct MeshIsland *BKE_fracture_mesh_island_create(struct Mesh* me, struct Main* bmain, struct Scene *scene, struct Object *ob);
void BKE_fracture_mesh_boundbox_calc(struct Mesh *me, float r_loc[], float r_size[]);
diff --git a/source/blender/blenkernel/BKE_fracture_util.h b/source/blender/blenkernel/BKE_fracture_util.h
index 96625022509..0cefbb54363 100644
--- a/source/blender/blenkernel/BKE_fracture_util.h
+++ b/source/blender/blenkernel/BKE_fracture_util.h
@@ -35,12 +35,41 @@
#include "DNA_fracture_types.h"
-MeshIsland *BKE_fracture_shard_boolean(Object *obj, MeshIsland *dm_parent, MeshIsland *child, short inner_material_index, int num_cuts, float fractal,
- MeshIsland **other, float mat[4][4], float radius, bool use_smooth_inner, int num_levels, char uv_layer[],
- float thresh);
+typedef struct BisectContext {
+ bool clear_inner;
+ bool clear_outer;
+ bool use_fill;
+ bool do_fast_bisect;
-MeshIsland *BKE_fracture_mesh_bisect(MeshIsland *parent, MeshIsland *child, float obmat[4][4], bool use_fill, bool clear_inner,
- bool clear_outer, int cutlimit, float centroid[3], short inner_mat_index, char uv_layer[64],
- struct KDTree *preselect_tree, float normal[3]);
+ char uv_layer[64];
+ float normal[3];
+ float centroid[3];
+ float obmat[4][4];
+ short inner_mat_index;
+ struct KDTree *geometry_limitation_tree;
+
+} BisectContext;
+
+typedef struct BooleanContext {
+ short inner_material_index;
+ int operation; /*0 == intersection, 2 == difference*/
+
+ //fractal stuff
+ bool use_fractal;
+ bool use_smooth_inner;
+ int num_cuts;
+ int num_iterations;
+ float fractal_amount;
+ float cutter_plane_matrix[4][4];
+ float cutter_plane_radius;
+
+ char uv_layer[64];
+ float thresh;
+} BooleanContext;
+
+Mesh* BKE_fracture_mesh_boolean(Mesh* geometry, Mesh* shard, Object* obj, BooleanContext *ctx);
+Mesh* BKE_fracture_mesh_bisect(Mesh* geometry, Mesh* raw_shard, BisectContext* ctx);
+void BKE_fracture_mesh_boolean_fractal(Mesh* geometry, Mesh **outputA, Mesh** outputB, Object *obj, BooleanContext *ctx);
+void BKE_fracture_mesh_bisect_fast(Mesh* geometry, Mesh **outputA, Mesh** outputB, BisectContext *ctx);
#endif /* BKE_FRACTURE_UTIL_H*/
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d50440ee4e9..26521f59852 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -102,31 +102,21 @@ static void do_island_index_map(FractureModifierData *fmd, Object *ob);
static void do_rigidbody(Main* bmain, Scene* scene, MeshIsland* mi, Object* ob, short rb_type, int i);
-static void fracture_meshisland_add(FractureModifierData *fmd, MeshIsland *mi, float mat[4][4],
- Object* ob, Scene *scene)
+static void fracture_meshisland_add(FractureModifierData *fmd, MeshIsland *mi,
+ Object* ob, Scene *scene, Main *bmain)
{
MVert *mv;
- int i = 0;
- //float imat[4][4];
-
- //invert_m4_m4(imat, ob->obmat);
+ int i;
for (i = 0, mv = mi->mesh->mvert; i < mi->mesh->totvert; i++, mv++ )
{
- mul_m4_v3(mat, mv->co);
- //mul_m4_v3(imat, mv->co);
+ mul_m4_v3(fmd->shared->splinter_matrix, mv->co);
}
- mul_m4_v3(mat, mi->centroid);
- //mul_m4_v3(imat, mi->centroid);
-
- //mi = MEM_dupallocN(s);
- //mi->mesh = BKE_mesh_
- do_rigidbody(G.main, scene, mi, ob, RBO_TYPE_ACTIVE, 0); //id and island_index set by caller
+ mul_m4_v3(fmd->shared->splinter_matrix, mi->centroid);
+ do_rigidbody(bmain, scene, mi, ob, RBO_TYPE_ACTIVE, 0); //id and island_index set by caller
BLI_addtail(&fmd->shared->mesh_islands, mi);
-
- return mi;
}
@@ -397,6 +387,7 @@ FracMesh *BKE_fracture_fracmesh_create(void)
#endif
+#if 0
static void handle_fast_bisect(FractureModifierData *fmd, int expected_shards, BMesh** bm_parent, float obmat[4][4],
float centroid[3], short inner_material_index, MeshIsland **tempshards, MeshIsland ***tempresults,
cell* cells, MeshIsland* parent)
@@ -678,7 +669,9 @@ static bool handle_boolean_bisect(FractureModifierData *fmd, Object *obj, int ex
return false;
}
+#endif
+#if 0
static void do_prepare_cells(cell *cells, int expected_shards, MeshIsland *mi, float (*centroid)[3],
BMesh** bm_parent, MeshIsland ***tempshards, MeshIsland ***tempresults, int override_count,
FractureModifierData *fmd, Scene* scene)
@@ -813,10 +806,11 @@ static void do_prepare_cells(cell *cells, int expected_shards, MeshIsland *mi, f
MEM_freeN(skipmap);
MEM_freeN(deletemap);
}
+#endif
/* parse the voro++ cell data */
-
+#if 0
static void parse_cells(FractureModifierData *fmd, cell *cells, int expected_shards, MeshIsland *mi, Object *obj,
short inner_material_index, float splinter_mat[4][4], int override_count, Scene* scene)
{
@@ -885,29 +879,12 @@ static void parse_cells(FractureModifierData *fmd, cell *cells, int expected_sha
{
BLI_kdtree_balance(fmd->shared->last_island_tree);
}
-
- //p->flag |= SHARD_DELETE;
}
}
temp_islands = MEM_callocN(sizeof(MeshIsland *) * expected_shards, "tempshards");
temp_results = MEM_callocN(sizeof(MeshIsland *) * expected_shards, "tempresults");
-// p->flag = 0;
-// p->flag |= SHARD_FRACTURED;
-
-#if 0
- if (mode == MOD_FRACTURE_DYNAMIC)
- {
- copy_v3_v3(pcentroid, p->centroid);
- parent_id = p->shard_id;
- //remove parent shard from map as well
- BLI_remlink(&fm->shard_map, p);
- fm->shard_count--;
- p->shard_id = -2;
- }
-#endif
-
unit_m4(obmat);
do_prepare_cells(cells, expected_shards, mi, ¢roid, &bm_parent, &temp_islands, &temp_results, override_count, fmd, scene);
@@ -1029,6 +1006,201 @@ static void parse_cells(FractureModifierData *fmd, cell *cells, int expected_sha
MEM_freeN(temp_islands);
MEM_freeN(temp_results);
}
+#endif
+
+static bool needs_process(FractureModifierData *fmd, MeshIsland* mi)
+{
+ //check against tree ? TODO
+ return true;
+}
+
+static void prepare_boolean(FractureModifierData* fmd, Object* ob, BooleanContext* ctx)
+{
+ ctx->use_fractal = false;
+ ctx->operation = 0;
+ ctx->thresh = fmd->boolean_double_threshold;
+ BLI_strncpy(ctx->uv_layer, fmd->uvlayer_name, 64);
+ ctx->inner_material_index = BKE_object_material_slot_find_index(ob, fmd->inner_material) - 1;
+}
+
+
+static void prepare_boolean_fractal(FractureModifierData* fmd, Object* ob, BooleanContext* ctx)
+{
+ prepare_boolean(fmd, ob, ctx);
+ ctx->use_fractal = true;
+ ctx->cutter_plane_radius = 1.0f; //TODO
+ unit_m4(ctx->cutter_plane_matrix); //TODO
+ ctx->fractal_amount = fmd->fractal_amount;
+ ctx->num_cuts = fmd->fractal_cuts;
+ ctx->num_iterations = fmd->fractal_iterations;
+ ctx->use_smooth_inner = fmd->use_smooth;
+}
+
+
+static void prepare_bisect(FractureModifierData *fmd, Object* ob, BisectContext* ctx)
+{
+ ctx->clear_inner = false;
+ ctx->clear_outer = true;
+ ctx->do_fast_bisect = false;
+ ctx->geometry_limitation_tree = fmd->shared->last_island_tree;
+ ctx->inner_mat_index = BKE_object_material_slot_find_index(ob, fmd->inner_material) - 1;
+ ctx->use_fill = false;
+ BLI_strncpy(ctx->uv_layer, fmd->uvlayer_name, 64);
+}
+
+static void prepare_bisect_fill(FractureModifierData *fmd, Object* ob, BisectContext* ctx)
+{
+ prepare_bisect(fmd, ob, ctx);
+ ctx->use_fill = true;
+}
+
+static void prepare_fast_bisect(FractureModifierData *fmd, Object *ob, BisectContext* ctx)
+{
+ prepare_bisect(fmd, ob, ctx);
+ ctx->do_fast_bisect = true;
+ ctx->normal[0] = 1.0f; //TODO
+ ctx->normal[1] = 0.0f;
+ ctx->normal[2] = 0.0f;
+
+ unit_m4(ctx->obmat); //TODO
+ ctx->use_fill = false;
+}
+
+static void prepare_fast_bisect_fill(FractureModifierData *fmd, Object* ob, BisectContext *ctx)
+{
+ prepare_fast_bisect(fmd, ob, ctx);
+ ctx->use_fill = true;
+}
+
+static void process_cells(FractureModifierData* fmd, Mesh* me, Main* bmain, Object* ob, Scene* scene, cell *c, int count)
+{
+ int i;
+ BisectContext bictx = {};
+ BooleanContext boctx = {};
+ MeshIsland** islands = NULL;
+ KDTree *tree = NULL;
+
+ /*global preparations */
+ if (fmd->shared->reset_shards)
+ {
+ if (fmd->shared->last_island_tree)
+ {
+ BLI_kdtree_free(fmd->shared->last_island_tree);
+ fmd->shared->last_island_tree = NULL;
+ }
+
+ if (fmd->shared->last_islands)
+ {
+ int j;
+ for (j = 0; j < fmd->shared->last_expected_islands; j++)
+ {
+ BKE_fracture_mesh_island_free(fmd->shared->last_islands[i], scene);
+ }
+
+ MEM_freeN(fmd->shared->last_islands);
+ fmd->shared->last_islands = NULL;
+ }
+ }
+
+ islands = MEM_callocN(sizeof(MeshIsland*) * count, "islands");
+ tree = BLI_kdtree_new(count);
+
+ /*for each cell...*/
+ for (i = 0; i < count * 2; i += 2)
+ {
+ /* parse to raw meshisland*/
+ MeshIsland *mi = parse_cell(c[i/2]);
+ BLI_kdtree_insert(tree, count, mi->centroid);
+ islands[i] = mi;
+
+ /* check whether it needs to be processed */
+ if (needs_process(fmd, mi))
+ {
+ /* resultB is for "halving" algorithms like fractal and bisectfast/bisectfastfill*/
+ MeshIsland *resultA = NULL, *resultB = NULL;
+ Mesh *meshA = NULL, *meshB = NULL;
+
+ /* process according to algorithm */
+ switch (fmd->frac_algorithm) {
+ case MOD_FRACTURE_BOOLEAN:
+ prepare_boolean(fmd, ob, &boctx);
+ meshA = BKE_fracture_mesh_boolean(me, mi->mesh, ob, &boctx);
+ break;
+
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list