Branching example working a little more...

This commit is contained in:
Chris Hodapp 2019-11-30 06:01:08 +01:00
parent c62f1ebe49
commit 4e8490d501
2 changed files with 15 additions and 6 deletions

View File

@ -153,12 +153,14 @@ def ram_horn_branch():
.translate(0,0,0.8) .translate(0,0,0.8)
def recur(xf, cage0, count): def recur(xf, cage0, count):
for i in range(count): for i in range(count):
if i > 0:
yield cage0.transform(xf) yield cage0.transform(xf)
xf0 = xf xf0 = xf
xf = incr.compose(xf) xf = incr.compose(xf)
# .compose(opening_boundary(i)) # .compose(opening_boundary(i))
def xf_sub(i): def xf_sub(i):
# yes, I can do this in a one-liner # yes, I can do this in a one-liner
# yes, it should be normalized, but I reused from something else
if i == 0: if i == 0:
dx, dy = 0.25, 0.25 dx, dy = 0.25, 0.25
elif i == 1: elif i == 1:
@ -167,11 +169,13 @@ def ram_horn_branch():
dx, dy = -0.25, -0.25 dx, dy = -0.25, -0.25
elif i == 3: elif i == 3:
dx, dy = 0.25, -0.25 dx, dy = 0.25, -0.25
return meshutil.Transform() \ return meshutil.Transform().rotate([-dy,dx,0], -numpy.pi/4)
.translate(dx, dy, 0) \ # this has to begin with cage_sub, prior to xf_sub(i) being
.rotate([0,0,1], i*numpy.pi/2) \ # composed in, because only this lines up with where the last
.translate(-dx, -dy, 0) # frame finished
gens = [cage.CageGen(recur(xf_sub(i).compose(xf0), cage_sub, 8)) gens = [cage.CageGen(itertools.chain(
[cage_sub.transform(xf0)],
recur(xf_sub(i).compose(xf0), cage_sub, 8)))
for i,cage_sub in for i,cage_sub in
enumerate(cage0.subdivide_deprecated())] enumerate(cage0.subdivide_deprecated())]
yield cage.CageFork(gens) yield cage.CageFork(gens)

View File

@ -79,6 +79,8 @@ class Transform(object):
return self._compose(mtx_rotate(*a, **kw)) return self._compose(mtx_rotate(*a, **kw))
def reflect(self, *a, **kw): def reflect(self, *a, **kw):
return self._compose(mtx_reflect(*a, **kw)) return self._compose(mtx_reflect(*a, **kw))
def identity(self, *a, **kw):
return self._compose(mtx_identity(*a, **kw))
def apply_to(self, vs): def apply_to(self, vs):
# Homogeneous coords, so append a column of ones. vh is then shape (N,4): # Homogeneous coords, so append a column of ones. vh is then shape (N,4):
vh = numpy.hstack([vs, numpy.ones((vs.shape[0], 1), dtype=vs.dtype)]) vh = numpy.hstack([vs, numpy.ones((vs.shape[0], 1), dtype=vs.dtype)])
@ -122,6 +124,9 @@ def mtx_reflect(axis):
[0, 0, 0, 1], [0, 0, 0, 1],
]) ])
def mtx_identity():
return numpy.eye(4)
def cube(open_xz=False): def cube(open_xz=False):
verts = numpy.array([ verts = numpy.array([
lbf, rbf, ltf, rtf, lbf, rbf, ltf, rtf,