[Bf-blender-cvs] [aeaf5d2] fracture_modifier: crash fix for fracturing with particles, missed proper initialization of voro++ interface struct (in case no computation takes place we need to zeroize the structs in the array though) and usage of particle_state instead of particle_birth coordinates, to be able to use particles not directly at birth position (after particle simulation has run a while)
Martin Felke
noreply at git.blender.org
Tue Oct 7 23:21:19 CEST 2014
Commit: aeaf5d29670336aa931e7c997a60a068b8dc8803
Author: Martin Felke
Date: Tue Oct 7 23:20:45 2014 +0200
Branches: fracture_modifier
https://developer.blender.org/rBaeaf5d29670336aa931e7c997a60a068b8dc8803
crash fix for fracturing with particles, missed proper initialization of voro++ interface struct (in case no computation takes place we need to zeroize the structs in the array though) and usage of particle_state instead of particle_birth coordinates, to be able to use particles not directly at birth position (after particle simulation has run a while)
===================================================================
M extern/voro++/src/c_interface.cc
M extern/voro++/src/c_interface.hh
M source/blender/blenkernel/intern/fracture.c
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
diff --git a/extern/voro++/src/c_interface.cc b/extern/voro++/src/c_interface.cc
index 0522f19..75c4b22 100644
--- a/extern/voro++/src/c_interface.cc
+++ b/extern/voro++/src/c_interface.cc
@@ -114,6 +114,7 @@ void container_compute_cells(container* con, cell* cells)
c.poly_totvert = NULL;
c.poly_indices = NULL;
c.verts = NULL;
+ cells[i] = c;
}
i++;
}
@@ -135,12 +136,46 @@ void particle_order_free(particle_order* p_order)
cell* cells_new(int totcells)
{
- return new cell[totcells];
+ int i = 0;
+ cell c;
+ cell *cl;
+
+ //need to initalize properly in case we dont compute....
+ c.centroid[0] = 0.0f;
+ c.centroid[1] = 0.0f;
+ c.centroid[2] = 0.0f;
+ c.index = 0;
+ c.neighbors = NULL;
+ c.totpoly = 0;
+ c.totvert = 0;
+ c.poly_totvert = NULL;
+ c.poly_indices = NULL;
+ c.verts = NULL;
+
+ cl = new cell[totcells];
+ for (i = 0; i < totcells; i++)
+ {
+ cl[i] = c;
+ }
+
+ return cl;
}
-void cells_free(cell *cells)
+void cells_free(cell *cells, int totcells)
{
- if (cells) delete [] cells;
+ // XXX TODO free properly !
+ if (cells) {
+ int i = 0;
+ for (i = 0; i < totcells; i++) {
+ cell c = cells[i];
+ if (c.verts) delete [] c.verts;
+ if (c.neighbors) delete [] c.neighbors;
+ if (c.poly_indices) delete [] c.poly_indices;
+ if (c.poly_totvert) delete [] c.poly_totvert;
+ }
+ delete [] cells;
+ }
+
}
diff --git a/extern/voro++/src/c_interface.hh b/extern/voro++/src/c_interface.hh
index f0f584c..dce8080 100644
--- a/extern/voro++/src/c_interface.hh
+++ b/extern/voro++/src/c_interface.hh
@@ -54,7 +54,7 @@ void particle_order_free(particle_order* po);
// cell array for direct access
cell* cells_new(int totcell);
-void cells_free(cell* cells);
+void cells_free(cell* cells, int totcells);
void container_compute_cells(container* con, cell* cells);
#ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d52db19..8d52637 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -402,11 +402,6 @@ FracMesh *BKE_create_fracture_container(DerivedMesh* dm)
}
-
-
-
-#if 1
-
/* parse the voro++ cell data */
static void parse_cells(cell* cells, int expected_shards, ShardID parent_id, FracMesh *fm, int algorithm, Object* obj, DerivedMesh *dm, short inner_material_index)
{
@@ -631,20 +626,14 @@ static Shard* parse_cell(cell c)
float centr[3];
int shard_id;
- //fscanf(fp, "%d ", &shard_id);
shard_id = c.index;
- //fscanf(fp, "%d ", &totvert);
totvert = c.totvert;
if (totvert > 0) {
mvert = MEM_callocN(sizeof(MVert) * totvert, __func__);
parse_cell_verts(c, mvert, totvert);
}
- /* skip "v "*/
- //fseek(fp, 2*sizeof(char), SEEK_CUR);
-
- //fscanf(fp, "%d ", &totpoly);
totpoly = c.totpoly;
if (totpoly > 0) {
mpoly = MEM_callocN(sizeof(MPoly) * totpoly, __func__);
@@ -663,35 +652,14 @@ static Shard* parse_cell(cell c)
parse_cell_neighbors(c, neighbors, totpoly);
}
- /* skip "f "*/
- //fseek(fp, 2*sizeof(char), SEEK_CUR);
-
- /* parse centroid */
- //fscanf(fp, "%f %f %f ", ¢r[0], ¢r[1], ¢r[2]);
copy_v3_v3(centr, c.centroid);
- /* skip "c"*/
- //fseek(fp, sizeof(char), SEEK_CUR);
-
s = BKE_create_fracture_shard(mvert, mpoly, mloop, totvert, totpoly, totloop, false);
s->neighbor_ids = neighbors;
s->neighbor_count = totpoly;
copy_v3_v3(s->centroid, centr);
-#if 0
- /* if not at end of file yet, skip newlines */
- if (feof(fp) == 0) {
-#ifdef _WIN32
- //skip \r\n
- fseek(fp, 2*sizeof(char), SEEK_CUR);
-#else
- //skip \n
- fseek(fp, sizeof(char), SEEK_CUR);
-#endif
- }
-#endif
-
return s;
}
@@ -756,9 +724,6 @@ static void parse_cell_neighbors(cell c, int *neighbors, int totpoly)
}
}
-#endif
-
-
void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *pointcloud, int algorithm, Object* obj, DerivedMesh* dm, short inner_material_index) {
int n_size = 8;
@@ -770,18 +735,8 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
container *voro_container;
particle_order *voro_particle_order;
- loop_order *voro_loop_order;
cell *voro_cells;
-#if defined(_WIN32) || defined(__APPLE__)
- const char *filename = "test.out";
- char *path, *fullpath;
-#else
- char *bp;
- size_t size;
-#endif
-
- FILE *stream;
#ifdef USE_DEBUG_TIMER
double time_start;
#endif
@@ -812,7 +767,6 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
container_put(voro_container, voro_particle_order, p, co[0], co[1], co[2]);
}
- //voro_loop_order = loop_order_new(voro_container, voro_particle_order);
#ifdef USE_DEBUG_TIMER
@@ -829,8 +783,7 @@ void BKE_fracture_shard_by_points(FracMesh *fmesh, ShardID id, FracPointCloud *p
parse_cells(voro_cells, pointcloud->totpoints, id, fmesh, algorithm, obj, dm, inner_material_index);
/*Free structs in C++ area of memory */
- cells_free(voro_cells);
- //loop_order_free(voro_loop_order);
+ cells_free(voro_cells, pointcloud->totpoints);
particle_order_free(voro_particle_order);
container_free(voro_container);
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 8d3a805..7c10087 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -752,7 +752,11 @@ static void points_from_particles(Object** ob, int totobj, Scene* scene, FracPoi
if ((BLI_frand() < thresh) && particle_mask) {
float co[3];
- psys_get_birth_coordinates(&sim, pa, &birth, 0, 0);
+ //psys_get_birth_coordinates(&sim, pa, &birth, 0, 0);
+
+ /* birth coordinates are not sufficient in case we did pre-simulate the particles, so they are not
+ * aligned with the emitter any more */
+ psys_get_particle_state(&sim, p, &birth, 1);
points->points = MEM_reallocN(points->points, (pt+1) * sizeof(FracPoint));
copy_v3_v3(co, birth.co);
More information about the Bf-blender-cvs
mailing list