X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffrac.c;h=4263c6573e466b4879793c7b79a6c08f303fab30;hb=59a8deae3d561aa3797a6bf25c76803fe098cdf0;hp=a6ce0a8f56ce4d8de9caa24cf94b24419b378606;hpb=f1410762198ad4b0ca8c0b47bd484ff2d3e09ddd;p=meshfrac diff --git a/src/frac.c b/src/frac.c index a6ce0a8..4263c65 100644 --- a/src/frac.c +++ b/src/frac.c @@ -132,17 +132,19 @@ static int build_cell(struct fracture *frac, int cellidx) } cmesh_bsphere(frac->mesh, 0, &bsize); - bsize *= 2; + bsize *= 8; num = dynarr_size(frac->cells); for(i=0; ipt, &frac->cells[i].pt); - plane_poly(&plane, &poly, bsize); - if(!(pptr = dynarr_push(polys, &poly))) { - return -1; + midplane(&plane, &frac->cells[i].pt, &cell->pt, frac->cell_gap); + if(plane_sdist(&plane, &cell->pt) > 0.0f) { + plane_poly(&plane, &poly, bsize); + if(!(pptr = dynarr_push(polys, &poly))) { + return -1; + } + polys = pptr; } - polys = pptr; } num = dynarr_size(polys); @@ -191,7 +193,7 @@ static int build_cell(struct fracture *frac, int cellidx) static int mesh_poly(struct poly *poly, const struct cmesh *mesh, int faceidx) { int i, vsz, nsz, uvsz; - struct vertex vert, *tmpvert; + struct vertex *tmpvert, vert = {0}; const float *varr, *narr, *uvarr; unsigned int vidx; @@ -215,11 +217,15 @@ static int mesh_poly(struct poly *poly, const struct cmesh *mesh, int faceidx) vert.pos.x = varr[vidx * vsz]; vert.pos.y = varr[vidx * vsz + 1]; vert.pos.z = varr[vidx * vsz + 2]; - vert.norm.x = narr[vidx * nsz]; - vert.norm.y = narr[vidx * nsz + 1]; - vert.norm.z = narr[vidx * nsz + 2]; - vert.uv.x = uvarr[vidx * uvsz]; - vert.uv.y = uvarr[vidx * uvsz + 1]; + if(narr) { + vert.norm.x = narr[vidx * nsz]; + vert.norm.y = narr[vidx * nsz + 1]; + vert.norm.z = narr[vidx * nsz + 2]; + } + if(uvarr) { + vert.uv.x = uvarr[vidx * uvsz]; + vert.uv.y = uvarr[vidx * uvsz + 1]; + } if(!(tmpvert = dynarr_push(poly->verts, &vert))) { destroy_poly(poly); @@ -258,6 +264,10 @@ static int build_cell_shell(struct cmesh *mesh, const struct cmesh *orig, cplanes = alloca(cell->num_polys * sizeof *cplanes); for(i=0; inum_polys; i++) { poly_plane(cell->polys + i, cplanes + i); + /* flip the plane normal towards the inside of the cell, to clip everything + * outside the cell + */ + cgm_vcons(&cplanes[i].norm, -cplanes[i].norm.x, -cplanes[i].norm.y, -cplanes[i].norm.z); } nfaces = cmesh_poly_count(orig); @@ -290,6 +300,7 @@ static int build_cell_shell(struct cmesh *mesh, const struct cmesh *orig, if((clipres = clip_poly(&wallclipped, cell->polys + j, &plane)) < 0) { /* mark for deletion */ delwall[j] = 1; + destroy_poly(&wallclipped); } else if(clipres == 0) { destroy_poly(cell->polys + j); cell->polys[j] = wallclipped;