X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffrac.c;fp=src%2Ffrac.c;h=93cb963951ea5d351a2c407aa0eac068db1dc7ad;hb=82bf18c392447827912146ba65145500c9c25385;hp=071b5c23542fb8a7e1695b210bc0f25517c6ca62;hpb=bf7eceb7d1cef825a64a1db7a20628f7d7005654;p=meshfrac 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)