Example #1
0
 def _def_normals(self,vs,ns):
     if ns is None:
         if len(vs) == 3:
             n = dpr.normal(*vs)
             nns = [n,n,n]
         elif len(vs) == 4:
             n = dpr.normal(*vs[:-1])
             nns = [n,n,n,n]
         else:
             print('_def_normals requires 3 or 4 vertices only')
             raise ValueError
     else:nns = ns
     return nns
Example #2
0
 def _triangle(self,p1,p2,p3,ns = None,us = None,ws = None,m = None):
     if ns is None:
         n = dpr.normal(p1,p2,p3)
         ns = (n.copy(),n.copy(),n)
     if us is None:
         us = (dpv.vector2d(0,1),dpv.vector2d(0,0),dpv.vector2d(1,0))
     if ws is None:
         ws = (dpv.one(),dpv.one(),dpv.one())
     n1,n2,n3 = ns
     u1,u2,u3 = us
     w1,w2,w3 = ws
     if m is None:m = 'generic'
     self._add_triangle(p1,p2,p3,n1,n2,n3,u1,u2,u3,w1,w2,w3,m)
     return self
Example #3
0
    def grow(self,seed,pfaces,nfaces,years):
        gface,seedposition = seed
        gpt = seedposition.copy()
        pactive = pfaces[gface]
        tactive = dpr.tangent(*pactive)
        nactive = dpr.normal(*pactive)
        ctrlpts = [gpt.copy()]
        ctrlpts.append(ctrlpts[-1].copy().translate_z(0.25))
        pi2 = numpy.pi/2.0
        while years:
            years -= 1

            r = 1.0
            t = -pi2/3.0 if years % 2 == 0 else pi2/3.0

            q = dq.q_from_av(t,nactive)
            #dgpt is where to go from the last point
            # it must be aware of structures to creep on
            dgpt = tactive.copy().rotate(q).scale_u(r)

            ctrlpts.append(ctrlpts[-1].copy().translate(dgpt))
            tactive = dpv.v1_v2(ctrlpts[-2],ctrlpts[-1]).normalize()
            # consider if the active face should change

        ctrlpts.append(ctrlpts[-1].copy().translate_z(-0.25))

        #splined = []
        #splined.append(ctrlpts[0])
        #for x in range(3,len(ctrlpts)):
        #    v1,v2,v3,v4 = ctrlpts[x-3],ctrlpts[x-2],ctrlpts[x-1],ctrlpts[x]
        #    splined.extend(dpv.vector_spline(v1,v2,v3,v4,5))
        ##splined.append(ctrlpts[-1])
        #splined = ctrlpts[:]

        loop = dpr.point_ring(0.1,8)
        ctrl = dpv.zero()

        loop.append(loop[0].copy())
        nfs = self._extrude(loop,ctrlpts,dpv.zero())
        return self
Example #4
0
    def grow(self, seed, pfaces, nfaces, years):
        gface, seedposition = seed
        gpt = seedposition.copy()
        pactive = pfaces[gface]
        tactive = dpr.tangent(*pactive)
        nactive = dpr.normal(*pactive)
        ctrlpts = [gpt.copy()]
        ctrlpts.append(ctrlpts[-1].copy().translate_z(0.25))
        pi2 = numpy.pi / 2.0
        while years:
            years -= 1

            r = 1.0
            t = -pi2 / 3.0 if years % 2 == 0 else pi2 / 3.0

            q = dq.q_from_av(t, nactive)
            #dgpt is where to go from the last point
            # it must be aware of structures to creep on
            dgpt = tactive.copy().rotate(q).scale_u(r)

            ctrlpts.append(ctrlpts[-1].copy().translate(dgpt))
            tactive = dpv.v1_v2(ctrlpts[-2], ctrlpts[-1]).normalize()
            # consider if the active face should change

        ctrlpts.append(ctrlpts[-1].copy().translate_z(-0.25))

        #splined = []
        #splined.append(ctrlpts[0])
        #for x in range(3,len(ctrlpts)):
        #    v1,v2,v3,v4 = ctrlpts[x-3],ctrlpts[x-2],ctrlpts[x-1],ctrlpts[x]
        #    splined.extend(dpv.vector_spline(v1,v2,v3,v4,5))
        ##splined.append(ctrlpts[-1])
        #splined = ctrlpts[:]

        loop = dpr.point_ring(0.1, 8)
        ctrl = dpv.zero()

        loop.append(loop[0].copy())
        nfs = self._extrude(loop, ctrlpts, dpv.zero())
        return self
Example #5
0
 def _project_uv_flat(self,rng = None):
     if rng is None:rng = range(len(self.faces))
     pcs = self.meshdata.pcoords
     ucs = self.meshdata.ucoords
     #vcs = self.vertices
     vcs = self.meshdata.vertices
     for nf in rng:
         face = self.faces[nf]
         #v1,v2,v3 = face
         #p1,p2,p3 = pcs[vcs[v1][0]],pcs[vcs[v2][0]],pcs[vcs[v3][0]]
         ps = [pcs[vcs[vx][0]] for vx in face]
         #n = dpr.normal(p1,p2,p3)
         n = dpr.normal(ps[0],ps[1],ps[2])
         if   dpv.near(n,dpv.nxhat) or dpv.near(n,dpv.xhat):natt = 'yz2d'
         elif dpv.near(n,dpv.nyhat) or dpv.near(n,dpv.yhat):natt = 'xz2d'
         elif dpv.near(n,dpv.nzhat) or dpv.near(n,dpv.zhat):natt = 'xy2d'
         else:continue
         for v in face:
             px,nx,ux = vcs[v]
             ucs[ux] = pcs[px].__getattribute__(natt)()
             print('projected uv coord',ucs[ux])
     return self
Example #6
0
 def _calculate_normals(self):
     pcs = self.meshdata.pcoords
     ncs = self.meshdata.ncoords
     vcs = self.meshdata.vertices
     for vdx in range(self.tvcnt):
         v = vcs[self.vertices[self.tverts[vdx][0]]]
         fring = self.frings[vdx]
         if not fring:continue
         fnorms = []
         for vf in fring:
             aface = self.faces[vf]
             p1 = pcs[vcs[aface[0]][0]]
             p2 = pcs[vcs[aface[1]][0]]
             p3 = pcs[vcs[aface[2]][0]]
             fnorm = dpr.normal(p1,p2,p3)
             skip = False
             for fn in fnorms:
                 if fnorm.near(fn):
                     skip = True
                     break
             if not skip:fnorms.append(fnorm)
         ncs[v[1]] = dpv.center_of_mass(fnorms).normalize()
     return self