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
def edgeloop_bridge(self,eloop1,eloop2): vxs1 = [eloop1[x-1][1] for x in range(len(eloop1))] vxs2 = [eloop2[x-1][1] for x in range(len(eloop2))] vs1 = [self.vs[x] for x in vxs1] vs2 = [self.vs[x] for x in vxs2] vps2 = [v.p for v in vs2] minx1 = 0 minx2 = dpv.find_closest(vs1[minx1].p,vps2,len(vps2),0.0) pbrg = dpr.point_line(vs1[minx1].p,vs2[minx2].p,5) preb = len(self.vs) for pb in pbrg[1:-1]: newv = vertex(pb,dpv.zhat.copy(),dpv.zero2d(),dpv.one(),self) newvrng = list(range(preb,len(self.vs))) newvrng.reverse() brg1 = [(newvrng[x-1],newvrng[x]) for x in range(1,len(newvrng))] brg2 = [(y,x) for x,y in brg1[::-1]] #THIS IS WHERE THE REAL PROBLEM IS!! brg1.append((brg1[-1][1],eloop1[minx1][0])) brg1.insert(0,(eloop2[minx2][0],brg1[0][0])) brg2.append((brg2[-1][1],eloop2[minx2][0])) brg2.insert(0,(eloop1[minx1][0],brg2[0][0])) bridged = brg1+eloop1[:minx1]+eloop1[minx1:]+\ brg2+eloop2[minx2:]+eloop2[:minx2] check = self.checkfront(bridged) #if not check is None:pdb.set_trace() #plot_edges(self.vs,bridged) #pdb.set_trace() return bridged
def advfrontpoint(self,eloop,point): ex,ea = point el1,el2,el3 = eloop[ex-1][0],eloop[ex][0],eloop[ex][1] v1,v2,v3 = self.vs[el1],self.vs[el2],self.vs[el3] e1 = dpv.v1_v2(v2.p,v1.p) e2 = dpv.v1_v2(v2.p,v3.p) e1len,e2len = e1.magnitude(),e2.magnitude() avd = (e1len+e2len)/2.0 e1.normalize() e2.normalize() if ea < numpy.pi/2.0: fs = [(el1,el2,el3)] eloop.pop(ex) eloop.pop(ex-1) eloop.insert((0 if ex == 0 else ex-1),(el1,el3)) elif ea < 2.0*numpy.pi/3.0: mpt = dpv.midpoint(v1.p,v3.p) mdist = avd - dpv.distance(v2.p,mpt) mdelt = dpv.v1_v2(v2.p,mpt).normalize().scale_u(mdist) mpt.translate(mdelt) newv = vertex(mpt,dpv.zhat.copy(),dpv.zero2d(),dpv.one(),self) el4 = len(self.vs)-1 fs = [(el1,el2,el4),(el2,el3,el4)] eloop.pop(ex) eloop.pop(ex-1) eloop.insert((0 if ex == 0 else ex-1),(el4,el3)) eloop.insert((0 if ex == 0 else ex-1),(el1,el4)) else: # shouldnt this always default to e1 and not just use whichever is shorter... mdist = min((e1len,e2len)) mdelt = dpv.v1_v2(v2.p,v1.p).cross(v2.n) mdelt.normalize().scale_u(mdist) mpt = dpv.midpoint(v2.p,v1.p).translate(mdelt) newv = vertex(mpt,dpv.zhat.copy(),dpv.zero2d(),dpv.one(),self) el4 = len(self.vs)-1 fs = [(el1,el2,el4)] eloop.pop(ex-1) eloop.insert((0 if ex == 0 else ex-1),(el4,el2)) eloop.insert((0 if ex == 0 else ex-1),(el1,el4)) check = self.checkfront(eloop) if not check is None:pdb.set_trace() self.fdata(fs) for fx in range(len(fs)): f = fs[fx] [self.vs[f[x]].face(f,x,fx) for x in range(len(f))]
def skeleton(self): s = dmo.model() for v in self.vs: m = dcu.cube().scale(dpv.one().scale_u(0.1)).translate(v.p) s._consume(m) for e in self.es: cq = dpq.q_from_uu(dpv.zhat, dpv.v1_v2(self.vs[e[0]].p,self.vs[e[1]].p)) c = dcy.cylinder().translate_z(0.5) c.scale_x(0.05).scale_y(0.05).rotate(cq) c.translate(self.vs[e[0]].p) s._consume(c) return s
def _topovertex(self,v): vx = self.meshdata.vertices[v] for tdx in range(self.tvcnt): tv = self.tverts[tdx] vrep = self.meshdata.vertices[tv[0]] if vrep[0] == vx[0] and vrep[1] == vx[1]: self.tverts[tdx].append(v) return tdx self.tverts.append([v]) self.twghts.append(dpv.one().scale_u(0.1)) self.vrings.append([]) self.frings.append([]) newtv = self.tvcnt self.tvcnt += 1 return newtv
def test(): import dilap.construct as dlc mdata = meshdata() p = [dpv.vector(0,0,0),dpv.vector(1,0,0),dpv.vector(1,1,0),dpv.vector(0,1,0), dpv.vector(0,0,1),dpv.vector(1,0,1),dpv.vector(1,1,1),dpv.vector(0,1,1)] dpv.scale_coords(p,dpv.one().scale_u(10)) m = mdata._mesh() m._quad(p[3],p[2],p[1],p[0])._quad(p[4],p[5],p[6],p[7]) m._quad(p[0],p[1],p[5],p[4])._quad(p[2],p[3],p[7],p[6]) m._quad(p[1],p[2],p[6],p[5])._quad(p[3],p[0],p[4],p[7]) m._decimate()._decimate()._smooths(100)._triangulate()._calculate_normals()._project_uv_flat() tmodels = [terrain(mesh = msh) for msh in mdata.meshes] dlc.build(*tmodels) pdb.set_trace()
def meshme(ps,ns = None,us = None,ws = None,es = [],fs = []): if ns is None:ns = [dpv.zhat.copy() for p in ps] if us is None:us = [dpv.zero2d() for p in ps] if ws is None:ws = [dpv.one() for p in ps] nvs = [] m = mesh() for vdx in range(len(ps)): newv = vertex(ps[vdx],ns[vdx],us[vdx],ws[vdx],m) nvs.append(newv) for e in es: nvs[e[0]].edge(e[1]) nvs[e[1]].edge(e[0]) m.edata(es) m.fdata(fs) for fx in range(len(fs)): f = fs[fx] [nvs[f[x]].face(f,x,fx) for x in range(len(f))] return m
def _quad(self,p1,p2,p3,p4,ns = None,us = None,ws = None,m = None): if ns is None: #n = dpr.normal(p1,p2,p3) n = dpv.zhat.copy() ns = (n.copy(),n.copy(),n.copy(),n) if us is None: #us = (dpv.vector2d(0,1),dpv.vector2d(0,0), # dpv.vector2d(1,0),dpv.vector2d(1,1)) us = (dpv.vector2d(0,0),dpv.vector2d(0,0), dpv.vector2d(0,0),dpv.vector2d(0,0)) if ws is None: n = dpv.one() ns = (n.copy(),n.copy(),n.copy(),n) n1,n2,n3,n4 = ns u1,u2,u3,u4 = us w1,w2,w3,w4 = ws if m is None:m = 'generic' self._add_quad(p1,p2,p3,p4,n1,n2,n3,n4,u1,u2,u3,u4,w1,w2,w3,w4,m) return self