Close CageFork properly

This commit is contained in:
Chris Hodapp 2019-12-08 19:40:51 +01:00
parent 43971714cb
commit 46abe2ece7
3 changed files with 14 additions and 6 deletions

View File

@ -5,7 +5,10 @@
behind this. behind this.
## Annoying/boring ## 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 - https://en.wikipedia.org/wiki/Polygon_triangulation - do this to
fix my wave example! fix my wave example!
- http://www.polygontriangulation.com/2018/07/triangulation-algorithm.html - http://www.polygontriangulation.com/2018/07/triangulation-algorithm.html

View File

@ -109,7 +109,8 @@ class CageGen(object):
# We stop recursing here, so close things off if needed: # We stop recursing here, so close things off if needed:
if close_last: if close_last:
for poly in cage_last.polys(): 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 break
# If it's a fork, then recursively generate all the geometry # If it's a fork, then recursively generate all the geometry
# from them, depth-first: # from them, depth-first:
@ -119,7 +120,7 @@ class CageGen(object):
# (e.g. loop with fork) # (e.g. loop with fork)
for gen in cage_cur.gens: for gen in cage_cur.gens:
m = gen.to_mesh(count=count - i, flip_order=flip_order, loop=loop, 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) join_fn=join_fn)
# TODO: How do I handle closing with CageFork? # TODO: How do I handle closing with CageFork?
meshes.append(m) meshes.append(m)

View File

@ -241,13 +241,17 @@ def join_boundary_optim(bound1, bound2):
i = numpy.argmin(errs) i = numpy.argmin(errs)
return join_boundary_simple(bound1, numpy.roll(bound2, i, axis=0)) 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! # This will fail for any non-convex boundary!
centroid = numpy.mean(bound, axis=0) centroid = numpy.mean(bound, axis=0)
vs = numpy.concatenate([bound, centroid[numpy.newaxis,:]]) vs = numpy.concatenate([bound, centroid[numpy.newaxis,:]])
n = bound.shape[0] n = bound.shape[0]
# note that n is new the index of the centroid # note that n is new the index of the centroid
fs = numpy.zeros((n+1, 3), dtype=int) fs = numpy.zeros((n+1, 3), dtype=int)
for i in range(n): if reverse:
fs[i] = [i, n, (i+1) % n] 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) return FaceVertexMesh(vs, fs)