[Bf-blender-cvs] [d4fce19] fracture_modifier: added a cluster group setting, where helper objects can define locations of cluster cores (shards will be added to its clostest core always), converted objects belong to a group now also
Martin Felke
noreply at git.blender.org
Fri Feb 6 16:26:46 CET 2015
Commit: d4fce19d4f83ee1a5e702262b9f7059ba33be9d8
Author: Martin Felke
Date: Fri Feb 6 16:26:21 2015 +0100
Branches: fracture_modifier
https://developer.blender.org/rBd4fce19d4f83ee1a5e702262b9f7059ba33be9d8
added a cluster group setting, where helper objects can define locations of cluster cores (shards will be added to its clostest core always), converted objects belong to a group now also
===================================================================
M release/scripts/startup/bl_ui/properties_physics_fracture.py
M source/blender/editors/object/object_modifier.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 1ab195e..a69b705 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -75,6 +75,7 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
col.prop(md, "shard_count")
col.prop(md, "cluster_count")
col.prop(md, "point_seed")
+ layout.prop(md, "cluster_group")
if md.frac_algorithm == 'BOOLEAN' or md.frac_algorithm == 'BISECT_FILL' or md.frac_algorithm == 'BISECT_FAST_FILL':
layout.prop(md, "inner_material")
if md.frac_algorithm == 'BOOLEAN_FRACTAL':
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 25814a1..feb9950 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2534,12 +2534,17 @@ static void convert_modifier_to_objects(ReportList *reports, Scene* scene, Objec
int i = 0;
RigidBodyWorld *rbw = scene->rigidbody_world;
+ const char *name = BLI_strdupcat(ob->id.name, "_conv");
+ Group *g = BKE_group_add(G.main, name);
+
int count = BLI_listbase_count(&rmd->meshIslands);
KDTree* objtree = BLI_kdtree_new(count);
Object** objs = MEM_callocN(sizeof(Object*) * count, "convert_objs");
float max_con_mass = 0;
rmd->refresh = false;
+ MEM_freeN((void*)name);
+
if (rbw)
rbw->pointcache->flag |= PTCACHE_OUTDATED;
@@ -2556,7 +2561,6 @@ static void convert_modifier_to_objects(ReportList *reports, Scene* scene, Objec
}
else {
-
ob_new = BKE_object_add(G.main, scene, OB_MESH);
if (rbw) {
@@ -2575,6 +2579,8 @@ static void convert_modifier_to_objects(ReportList *reports, Scene* scene, Objec
}
}
+ BKE_group_object_add(g, ob_new, scene, NULL);
+
/* throw away all modifiers before fracture, result is stored inside it */
while (ob_new->modifiers.first != NULL) {
md = ob_new->modifiers.first;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 01e9295..0c9fa6b 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1431,6 +1431,7 @@ typedef struct FractureModifierData {
struct DerivedMesh *dm;
struct Group *extra_group;
struct Group *dm_group;
+ struct Group *cluster_group;
struct BMesh *visible_mesh;
struct DerivedMesh *visible_mesh_cached;
ListBase meshIslands, meshConstraints;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 5040f20..f482d3d 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4171,6 +4171,11 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
RNA_def_property_range(prop, 1, 10);
RNA_def_property_ui_text(prop, "Fractal Iterations", "Number of times the number of cuts will be made to the grid, with the given fractal amount");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "cluster_group", PROP_POINTER, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Cluster Group", "");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 807d1a0..5cec596 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -146,6 +146,8 @@ static void initData(ModifierData *md)
fmd->fractal_amount = 1.0f;
fmd->physics_mesh_scale = 0.75f;
fmd->fractal_iterations = 5;
+
+ fmd->cluster_group = NULL;
}
static void freeMeshIsland(FractureModifierData *rmd, MeshIsland *mi, bool remove_rigidbody)
@@ -416,38 +418,69 @@ static void doClusters(FractureModifierData *fmd)
}
}
- /* zero clusters or one mean no clusters, all shards keep free */
- if (fmd->cluster_count < 2) {
- return;
- }
+ if (fmd->cluster_group)
+ {
+ seed_count = BLI_listbase_count(&fmd->cluster_group->gobject);
+ if (seed_count > 0)
+ {
+ GroupObject* go;
+ int i = 0;
+ tree = BLI_kdtree_new(seed_count);
+ for (i = 0, go = fmd->cluster_group->gobject.first; go; i++, go = go->next)
+ {
+ BLI_kdtree_insert(tree, i, go->ob->loc);
+ }
+
+ BLI_kdtree_balance(tree);
+
+ /* assign each shard to its closest center */
+ for (s = shardlist.first; s; s = s->next ) {
+ KDTreeNearest n;
+ int index;
- seed_count = (fmd->cluster_count > fmd->frac_mesh->shard_count ? fmd->frac_mesh->shard_count : fmd->cluster_count);
- seeds = MEM_mallocN(sizeof(Shard *) * seed_count, "seeds");
- tree = BLI_kdtree_new(seed_count);
+ index = BLI_kdtree_find_nearest(tree, s->centroid, &n);
+ s->cluster_colors[0] = index;
+ }
- /* pick n seed locations, randomly scattered over the object */
- for (k = 0; k < seed_count; k++) {
- int color = k;
- int which_index = k * (int)(fmd->frac_mesh->shard_count / seed_count);
- Shard *which = (Shard *)BLI_findlink(&shardlist, which_index);
- which->cluster_colors[0] = color;
- BLI_kdtree_insert(tree, k, which->centroid);
- seeds[k] = which;
+ BLI_kdtree_free(tree);
+ }
}
+ else
+ {
+ /* zero clusters or one mean no clusters, all shards keep free */
+ if (fmd->cluster_count < 2) {
+ return;
+ }
- BLI_kdtree_balance(tree);
+ seed_count = (fmd->cluster_count > fmd->frac_mesh->shard_count ? fmd->frac_mesh->shard_count : fmd->cluster_count);
+ seeds = MEM_mallocN(sizeof(Shard *) * seed_count, "seeds");
+ tree = BLI_kdtree_new(seed_count);
- /* assign each shard to its closest center */
- for (s = shardlist.first; s; s = s->next ) {
- KDTreeNearest n;
- int index;
+ /* pick n seed locations, randomly scattered over the object */
+ for (k = 0; k < seed_count; k++) {
+ int color = k;
+ int which_index = k * (int)(fmd->frac_mesh->shard_count / seed_count);
+ Shard *which = (Shard *)BLI_findlink(&shardlist, which_index);
+ which->cluster_colors[0] = color;
+ BLI_kdtree_insert(tree, k, which->centroid);
+ seeds[k] = which;
+ }
- index = BLI_kdtree_find_nearest(tree, s->centroid, &n);
- s->cluster_colors[0] = seeds[index]->cluster_colors[0];
- }
+ BLI_kdtree_balance(tree);
- BLI_kdtree_free(tree);
- MEM_freeN(seeds);
+
+ /* assign each shard to its closest center */
+ for (s = shardlist.first; s; s = s->next ) {
+ KDTreeNearest n;
+ int index;
+
+ index = BLI_kdtree_find_nearest(tree, s->centroid, &n);
+ s->cluster_colors[0] = seeds[index]->cluster_colors[0];
+ }
+
+ BLI_kdtree_free(tree);
+ MEM_freeN(seeds);
+ }
}
static KDTree *build_nor_tree(DerivedMesh *dm)
@@ -1106,6 +1139,8 @@ static void copyData(ModifierData *md, ModifierData *target)
/* sub object group XXX Do we keep this ?*/
trmd->dm_group = rmd->dm_group;
+ trmd->cluster_group = rmd->cluster_group;
+
trmd->use_particle_birth_coordinates = rmd->use_particle_birth_coordinates;
trmd->splinter_length = rmd->splinter_length;
trmd->cluster_solver_iterations_override = rmd->cluster_solver_iterations_override;
@@ -2664,6 +2699,7 @@ static void foreachIDLink(ModifierData *md, Object *ob,
walk(userData, ob, (ID **)&fmd->inner_material);
walk(userData, ob, (ID **)&fmd->extra_group);
walk(userData, ob, (ID **)&fmd->dm_group);
+ walk(userData, ob, (ID **)&fmd->cluster_group);
}
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md))
More information about the Bf-blender-cvs
mailing list