6 static void destroy_cell(struct frac_cell *cell);
8 int frac_init(struct fracture *frac)
12 if(!(frac->cells = dynarr_alloc(0, sizeof *frac->cells))) {
18 void frac_destroy(struct fracture *frac)
25 num = dynarr_size(frac->cells);
26 for(i=0; i<num; i++) {
27 destroy_cell(frac->cells + i);
29 dynarr_free(frac->cells);
33 static void destroy_cell(struct frac_cell *cell)
37 cmesh_free(cell->mesh);
38 dynarr_free(cell->planes);
41 void frac_mesh(struct fracture *frac, const struct cmesh *m)
43 frac->mesh = (struct cmesh*)m;
46 int frac_point(struct fracture *frac, float x, float y, float z)
48 struct frac_cell cell;
49 struct frac_cell *tmp;
51 cgm_vcons(&cell.pt, x, y, z);
52 if(!(cell.mesh = cmesh_alloc())) {
55 if(!(cell.planes = dynarr_alloc(0, sizeof *cell.planes))) {
56 cmesh_free(cell.mesh);
59 if(!(tmp = dynarr_push(frac->cells, &cell))) {
60 cmesh_free(cell.mesh);
61 dynarr_free(cell.planes);
68 int frac_num_cells(struct fracture *frac)
70 return dynarr_size(frac->cells);
73 int frac_gen_points(struct fracture *frac, int num)
77 cgm_vec3 bbmin, bbmax, delta;
79 if(!frac || !frac->mesh) return -1;
80 if(!cmesh_poly_count(frac->mesh)) {
84 cmesh_aabbox(frac->mesh, &bbmin, &bbmax);
86 cgm_vsub(&delta, &bbmin);
88 for(i=0; i<num; i++) {
89 x = (float)rand() / RAND_MAX * delta.x + bbmin.x;
90 y = (float)rand() / RAND_MAX * delta.y + bbmin.y;
91 z = (float)rand() / RAND_MAX * delta.z + bbmin.z;
93 if(frac_point(frac, x, y, z) == -1) {
100 int frac_build_cells(struct fracture *frac)
105 int frac_build_shell(struct fracture *frac)
110 int frac_build_walls(struct fracture *frac)
115 int frac_build(struct fracture *frac)
117 if(frac_build_cells(frac) == -1) {
120 if(frac_build_shell(frac) == -1) {
123 if(frac_build_walls(frac) == -1) {