From: John Tsiombikas Date: Fri, 3 Feb 2023 16:18:42 +0000 (+0200) Subject: foo X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=meshfrac;a=commitdiff_plain;h=82bf18c392447827912146ba65145500c9c25385 foo --- diff --git a/src/frac.c b/src/frac.c index 071b5c2..93cb963 100644 --- a/src/frac.c +++ b/src/frac.c @@ -118,29 +118,68 @@ int frac_build_cells(struct fracture *frac) static int build_cell(struct fracture *frac, int cellidx) { - int i, j, num; - struct plane plane, *pptr; + int i, j, num, clipres; + struct plane plane; struct frac_cell *cell = frac->cells + cellidx; + struct poly poly, clipped, *polys, *pptr; + float bsize; + + if(!(polys = dynarr_alloc(0, sizeof *polys))) { + return -1; + } + + cmesh_bsphere(frac->mesh, 0, &bsize); + size *= 2; num = dynarr_size(frac->cells); for(i=0; ipt, &frac->cells[i].pt); - if(!(pptr = dynarr_push(cell->planes, &plane))) { + plane_poly(&plane, &poly, bsize); + if(!(pptr = dynarr_push(polys, &poly))) { return -1; } - cell->planes = pptr; + polys = pptr; } + num = dynarr_size(polys); + valid_planes = alloca(num * sizeof *valid_planes); + memset(valid_planes, 0xff, num * sizeof *valid_planes); + /* clip all planes against each other to end up with a convex cell */ - num = dynarr_size(cell->planes); + cell->num_polys = num; for(i=0; inum_polys--; + break; + } + } + } - clip_poly... + if(!(cell->polys = malloc(cell->num_polys * sizeof *cell->polys))) { + return -1; + } + pptr = cell->polys; + for(i=0; ipolys < cell->num_polys); + *pptr++ = polys[i]; + } else { + destroy_poly(polys + i); } } + darr_free(polys); + return 0; } int frac_build_shell(struct fracture *frac) diff --git a/src/frac.h b/src/frac.h index 72192b7..8a7e022 100644 --- a/src/frac.h +++ b/src/frac.h @@ -7,8 +7,8 @@ struct frac_cell { cgm_vec3 pt; - struct cmesh *mesh; - struct plane *planes; /* dynarr */ + struct poly *polys; + int num_polys; }; struct fracture { diff --git a/src/geom.c b/src/geom.c index 81e9df4..4e30628 100644 --- a/src/geom.c +++ b/src/geom.c @@ -1,4 +1,5 @@ #include +#include #include "geom.h" #include "dynarr.h" @@ -130,6 +131,12 @@ float ray_poly(const cgm_ray *ray, const struct poly *poly) return t; } +int init_poly(struct poly *p) +{ + p->verts = dynarr_alloc(0, sizeof *p->verts); + assert(p->verts); + return p->verts ? 0 : -1; +} /* returns: * 1 -> both inside diff --git a/src/geom.h b/src/geom.h index ebb6659..19c10ff 100644 --- a/src/geom.h +++ b/src/geom.h @@ -27,6 +27,8 @@ int plane_poly(const struct plane *plane, struct poly *poly, float size); float ray_plane(const cgm_ray *ray, const struct plane *plane); float ray_poly(const cgm_ray *ray, const struct poly *poly); +int init_poly(struct poly *p); +void destroy_poly(struct poly *p); int clip_poly(struct poly *pout, const struct poly *pin, const struct plane *plane); #endif /* GEOM_H_ */