[Bf-blender-cvs] [97a677e7886] fracture_modifier: first attempt of brickify fracture
Martin Felke
noreply at git.blender.org
Mon Feb 12 22:19:30 CET 2018
Commit: 97a677e78861dba623b49fb72ef4e46e665d057f
Author: Martin Felke
Date: Mon Feb 12 22:19:07 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rB97a677e78861dba623b49fb72ef4e46e665d057f
first attempt of brickify fracture
===================================================================
M release/scripts/startup/bl_operators/presets.py
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/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_fracture.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 cf9a74bac82..41e3a6f42c6 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -710,6 +710,8 @@ class AddPresetFracture(AddPresetBase, Operator):
"fracture.use_animated_mesh",
"fracture.animated_mesh_input",
"fracture.use_animated_mesh_rotation",
+ "fracture.grid_offset",
+ "fracture.grid_spacing",
]
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 854d97dcd35..7be6be4b345 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -152,7 +152,10 @@ class PHYSICS_PT_fracture(PhysicButtonsPanel, Panel):
col = box.column()
col.prop(md, "point_source")
if 'GRID' in md.point_source:
- col.prop(md, "grid_resolution")
+ sub = col.split(0.33)
+ sub.prop(md, "grid_resolution")
+ sub.prop(md, "grid_offset")
+ sub.prop(md, "grid_spacing")
if 'GREASE_PENCIL' in md.point_source:
col.prop(md, "use_greasepencil_edges")
col.prop(md, "grease_offset")
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index de9024a5c19..62397cbf7bc 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -59,6 +59,7 @@ typedef int ShardID;
typedef struct FracPoint {
float co[3];
+ float offset[3];
} FracPoint;
typedef struct FracPointCloud {
@@ -97,7 +98,8 @@ struct DerivedMesh *BKE_shard_create_dm(struct Shard *s, bool doCustomData);
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, int mode, bool reset, int active_setting,
- int num_settings, char uv_layer[], bool threaded, int solver, float thresh, bool shards_to_islands, int override_count, float factor);
+ int num_settings, char uv_layer[], bool threaded, int solver, float thresh, bool shards_to_islands,
+ int override_count, float factor, int point_source, int resolution[], float spacing[]);
/* 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]);
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 814ca0fdfb4..61c1d68b5fc 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -1937,15 +1937,16 @@ static FractureData segment_cells(cell *voro_cells, int startcell, int totcells,
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 mode,
- bool reset, int active_setting, int num_settings, char uv_layer[64], bool threaded, int solver, float thresh,
- bool shards_to_islands, int override_count, float factor)
+ bool reset, int active_setting, int num_settings, char uv_layer[64], bool threaded, int solver,
+ float thresh, bool shards_to_islands, int override_count, float factor, int point_source,
+ int resolution[3], float spacing[3])
{
int n_size = 8;
Shard *shard;
float min[3], max[3];
- float theta = 0.1f; /* TODO, container enlargement, because boundbox exact container and boolean might create artifacts */
+ float theta = 0.001f; /* TODO, container enlargement, because boundbox exact container and boolean might create artifacts */
int p, i = 0, num = 0, totcell = 0, remainder_start = 0;
container *voro_container;
@@ -1990,9 +1991,42 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
mul_m4_v3(mat, max);
- voro_container = container_new(min[0], max[0], min[1], max[1], min[2], max[2],
- n_size, n_size, n_size, false, false, false,
- pointcloud->totpoints);
+ if (point_source & MOD_FRACTURE_GRID)
+ {
+ float off[3] = {0, 0, 0};
+ for (p = 0; p < pointcloud->totpoints; p++)
+ {
+ //find "max" offset (where atleast 1 axis is > 0)
+ if (pointcloud->points[p].offset[0] > 0 ||
+ pointcloud->points[p].offset[1] > 0 ||
+ pointcloud->points[p].offset[2] > 0)
+ {
+ copy_v3_v3(off, pointcloud->points[p].offset);
+ break;
+ }
+ }
+
+ if (off[0] > 0 || off[1] > 0 || off[2] > 0)
+ {
+ sub_v3_v3(min, off);
+
+ //special treatment for grid pointsource... with offsets
+ voro_container = container_new(min[0], max[0], min[1], max[1], min[2], max[2],
+ resolution[0] * 2, resolution[1] * 2, resolution[2] * 2, false, false, false,
+ pointcloud->totpoints);
+
+ }
+ else {
+ voro_container = container_new(min[0], max[0], min[1], max[1], min[2], max[2],
+ n_size, n_size, n_size, false, false, false,
+ pointcloud->totpoints);
+ }
+ }
+ else {
+ voro_container = container_new(min[0], max[0], min[1], max[1], min[2], max[2],
+ n_size, n_size, n_size, false, false, false,
+ pointcloud->totpoints);
+ }
voro_particle_order = particle_order_new();
for (p = 0; p < pointcloud->totpoints; p++) {
@@ -2010,6 +2044,31 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
/*Compute directly...*/
container_compute_cells(voro_container, voro_cells);
+ /*Apply offsets (if any, grid only */
+ if (point_source & MOD_FRACTURE_GRID)
+ {
+ int v = 0;
+ float fact[3] = {1 - spacing[0], 1 - spacing[1], 1 - spacing[2]};
+ for (p = 0; p < pointcloud->totpoints; p++)
+ {
+ //adjust centroid and...
+ float off[3], cent[3];
+ copy_v3_v3(off, pointcloud->points[p].offset);
+ add_v3_v3(voro_cells[p].centroid, off);
+ copy_v3_v3(cent, voro_cells[p].centroid);
+ mul_v3_v3(cent, fact);
+
+ //vertex coordinates
+ for (v = 0; v < voro_cells[p].totvert; v++)
+ {
+ add_v3_v3(voro_cells[p].verts[v], off);
+ //print_v3("Vert", voro_cells[p].verts[v]);
+ sub_v3_v3(voro_cells[p].verts[v], cent);
+ add_v3_v3(voro_cells[p].verts[v], voro_cells[p].centroid);
+ }
+ }
+ }
+
/*Disable for fast bisect/fill, dynamic and mousebased for now -> errors and crashes */
if (mode != MOD_FRACTURE_DYNAMIC && reset == true && algorithm != MOD_FRACTURE_BISECT_FAST && algorithm != MOD_FRACTURE_BISECT_FAST_FILL && threaded == true) {
/*segment cells, give each thread a chunk to work on */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index a7f70143b6f..450ffa30ddf 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1811,6 +1811,8 @@ typedef struct FractureModifierData {
float max_acceleration;
float acceleration_fade;
float anim_bind_limit;
+ float grid_offset[3];
+ float grid_spacing[3];
/* flags */
int refresh;
diff --git a/source/blender/makesrna/intern/rna_fracture.c b/source/blender/makesrna/intern/rna_fracture.c
index 9b65cbd0911..5a44f2d3c0e 100644
--- a/source/blender/makesrna/intern/rna_fracture.c
+++ b/source/blender/makesrna/intern/rna_fracture.c
@@ -1451,7 +1451,7 @@ void RNA_def_fracture(BlenderRNA *brna)
RNA_def_property_range(prop, 1, 10000);
RNA_def_property_array(prop, 3);
RNA_def_property_int_default(prop, 10);
- RNA_def_property_ui_text(prop, "Grid resolution", "How many grid cells per Bounding Box Axis");
+ RNA_def_property_ui_text(prop, "Grid Resolution", "How many grid cells per Bounding Box Axis");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, 0, "rna_Modifier_update");
@@ -1530,5 +1530,23 @@ void RNA_def_fracture(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+ prop = RNA_def_property(srna, "grid_offset", PROP_FLOAT, PROP_XYZ);
+ RNA_def_property_float_sdna(prop, NULL, "grid_offset");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_default(prop, 0.0f);
+ RNA_def_property_ui_text(prop, "Grid Offset", "How far odd rows are relatively offset compared to even ones");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "grid_spacing", PROP_FLOAT, PROP_XYZ);
+ RNA_def_property_float_sdna(prop, NULL, "grid_spacing");
+ RNA_def_property_range(prop, 0.0f, 0.99f);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_default(prop, 0.0f);
+ RNA_def_property_ui_text(prop, "Grid Spacing", "How much space inbetween the bricks, in each direction");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
RNA_api_fracture(brna, srna);
}
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 7d054d20757..f5d5e3e627d 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -268,6 +268,8 @@ static void initData(ModifierData *md)
fmd->anim_bind_len = 0;
fmd->anim_mesh_rot = false;
fmd->anim_bind_limit = 0.0f;
+ zero_v3(fmd->grid_offset);
+ zero_v3(fmd->grid_spacing);
}
//XXX
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list