diff --git a/README.md b/README.md index 470c0cc..ac99ee4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,10 @@ behind this. ## Annoying/boring -- Make branching properly close the final boundaries. +- Fix non-manifold bug at branch. (The edges must be *shared*. It is + not sufficient that the subdivided edges both lie incident on some + other edge and cover it completely. You must subdivide that larger + edge, and thus the triangle it lies on.) - https://en.wikipedia.org/wiki/Polygon_triangulation - do this to fix my wave example! - http://www.polygontriangulation.com/2018/07/triangulation-algorithm.html diff --git a/cage.py b/cage.py index ac218e8..43e87e9 100644 --- a/cage.py +++ b/cage.py @@ -109,7 +109,8 @@ class CageGen(object): # We stop recursing here, so close things off if needed: if close_last: for poly in cage_last.polys(): - meshes.append(meshutil.close_boundary_simple(poly)) + meshes.append(meshutil.close_boundary_simple(poly, reverse=True)) + # TODO: Fix the winding order hack here. break # If it's a fork, then recursively generate all the geometry # from them, depth-first: @@ -119,7 +120,7 @@ class CageGen(object): # (e.g. loop with fork) for gen in cage_cur.gens: m = gen.to_mesh(count=count - i, flip_order=flip_order, loop=loop, - close_first=False, close_last=False, + close_first=False, close_last=close_last, join_fn=join_fn) # TODO: How do I handle closing with CageFork? meshes.append(m) diff --git a/meshutil.py b/meshutil.py index cd57c8d..8dcb7f3 100644 --- a/meshutil.py +++ b/meshutil.py @@ -241,13 +241,17 @@ def join_boundary_optim(bound1, bound2): i = numpy.argmin(errs) return join_boundary_simple(bound1, numpy.roll(bound2, i, axis=0)) -def close_boundary_simple(bound): +def close_boundary_simple(bound, reverse=False): # This will fail for any non-convex boundary! centroid = numpy.mean(bound, axis=0) vs = numpy.concatenate([bound, centroid[numpy.newaxis,:]]) n = bound.shape[0] # note that n is new the index of the centroid fs = numpy.zeros((n+1, 3), dtype=int) - for i in range(n): - fs[i] = [i, n, (i+1) % n] + if reverse: + for i in range(n): + fs[i] = [(i+1) % n, n, i] + else: + for i in range(n): + fs[i] = [i, n, (i+1) % n] return FaceVertexMesh(vs, fs)