예제 #1
0
 def rvag(self,vx,og,connect_all = False):
     vc = self.vcnt
     v = self.vs[vx]
     nvs = []
     for ox in range(og.vcnt):
         ov = og.vs[ox]
         if ov is None:
             self.av(None,null = True)
             continue
         okws = ov[1]
         newring = [ovx+vc for ovx in okws['edges']]
         okws['edges'] = newring
         if 'terrainmesh' in v[1]['info']:
             okws['info']['terrainmesh'] = v[1]['info']['terrainmesh']
         new = self.av(okws)
         nvs.append(new)
     for res in v[1]['edges']:
         ringv = self.vs[res]
         if ringv is None:continue
         for nvx in nvs:
             nv = self.vs[nvx]
             for ep in nv[1]['exits']:
                 if ep.onbxy(ringv[1]['fp']):
                     self.ae(nvx,res)
             if connect_all:
                 aws = pym.badjbxy(nv[1]['fp'],ringv[1]['fp'],0)
                 if aws:self.ae(nvx,res)
     self.vs[vx] = None
     for vx in range(self.vcnt):self.vve(vx)
     return nvs
예제 #2
0
 def verifyedges(self, rx):
     dw, dh, dz = 1.5, 3.0, 0.0
     rv = self.vs[rx]
     if rv is None: return
     rb = rv[2]['bound']
     for adj in self.vs[rx][1]:
         ov = self.vs[adj]
         if ov is None: continue
         if ov[2]['level'] != rv[2]['level']:
             if not self.shafts:
                 self.shafts.append(
                     [adj if ov[2]['level'] < rv[2]['level'] else rx])
             for sh in self.shafts:
                 if adj in sh and not rx in sh:
                     sh.append(rx)
                     break
             continue
         ob = ov[2]['bound']
         aws = pym.badjbxy(rb, ob)
         if not aws:
             if adj in rv[1]: rv[1].remove(adj)
             if rx in ov[1]: ov[1].remove(rx)
     if rv[2]['shaft']:
         #print('found shaft',rx)
         if not self.shafts:
             self.shafts.append([rx])
         else:
             #print('need to id correct shaft...')
             self.shafts[-1].append(rx)
예제 #3
0
 def rvag(self, vx, og, connect_all=False):
     vc = self.vcnt
     v = self.vs[vx]
     nvs = []
     for ox in range(og.vcnt):
         ov = og.vs[ox]
         if ov is None:
             self.av(None, null=True)
             continue
         okws = ov[1]
         newring = [ovx + vc for ovx in okws['edges']]
         okws['edges'] = newring
         if 'terrainmesh' in v[1]['info']:
             okws['info']['terrainmesh'] = v[1]['info']['terrainmesh']
         new = self.av(okws)
         nvs.append(new)
     for res in v[1]['edges']:
         ringv = self.vs[res]
         if ringv is None: continue
         for nvx in nvs:
             nv = self.vs[nvx]
             for ep in nv[1]['exits']:
                 if ep.onbxy(ringv[1]['fp']):
                     self.ae(nvx, res)
             if connect_all:
                 aws = pym.badjbxy(nv[1]['fp'], ringv[1]['fp'], 0)
                 if aws: self.ae(nvx, res)
     self.vs[vx] = None
     for vx in range(self.vcnt):
         self.vve(vx)
     return nvs
예제 #4
0
 def vstitch(self, vb, v, a, l=10):
     #vb = [b.cp() for b in v[1]['b'][0]]
     if not pym.bccw(vb): vb.reverse()
     fnd = True
     while fnd:
         fnd = False
         for o, depth in a.enum():
             if o.ix == v.ix: continue
             #if ox == v.ix:continue
             ob = o.loop
             adjs = pym.badjbxy(vb, ob, 0.1)
             for adj in adjs:
                 vbx, obx = adj
                 vb1, vb2, ob1, ob2 = vb[vbx - 1], vb[vbx], ob[obx -
                                                               1], ob[obx]
                 ips = pym.sintsxyp(vb1, vb2, ob1, ob2, ieb=0, skew=0, ie=0)
                 if ips is None: continue
                 ip1, ip2 = ips
                 if not ip1 in vb or not ip2 in vb:
                     if ip1.onsxy(vb1, vb2, 0):
                         vb.insert(vbx, ip1)
                         fnd = True
                     if ip2.onsxy(vb1, vb2, 0):
                         vb.insert(vbx, ip2)
                         fnd = True
             if fnd: break
     vbx = 0
     while vbx < len(vb):
         vb1, vb2 = vb[vbx - 1], vb[vbx]
         if vb1.d(vb2) < l: vbx += 1
         else: vb.insert(vbx, vb1.mid(vb2))
     return vb
예제 #5
0
 def verifyedges(self,rx):
     dw,dh,dz = 1.5,3.0,0.0
     rv = self.vs[rx]
     if rv is None:return
     rb = rv[2]['bound']
     for adj in self.vs[rx][1]:
         ov = self.vs[adj]
         if ov is None:continue
         if ov[2]['level'] != rv[2]['level']:
             if not self.shafts:
                 self.shafts.append([adj if ov[2]['level'] < rv[2]['level'] else rx])
             for sh in self.shafts:
                 if adj in sh and not rx in sh:
                     sh.append(rx)
                     break
             continue
         ob = ov[2]['bound']
         aws = pym.badjbxy(rb,ob)
         if not aws:
             if adj in rv[1]:rv[1].remove(adj)
             if rx in ov[1]:ov[1].remove(rx)
     if rv[2]['shaft']:
         #print('found shaft',rx)
         if not self.shafts:
             self.shafts.append([rx])
         else:
             #print('need to id correct shaft...')
             self.shafts[-1].append(rx)
예제 #6
0
 def geoadj(self,rx,minovlp = 0):
     rv = self.vs[rx]
     bd = rv[2]['bound']
     fnd = []
     for ra in range(self.vcnt):
         av = self.vs[ra]
         if av is None or av is rv:continue
         ab = av[2]['bound']
         adjwalls = pym.badjbxy(bd,ab)
         for adjw in adjwalls:fnd.append((ra,adjw))
     return fnd
예제 #7
0
 def anyadj(self, rx, minovlp=0):
     rv = self.vs[rx]
     bd = rv[2]['bound']
     es = rv[1]
     fnd = []
     if not es: return fnd
     for ra in rv[1]:
         av = self.vs[ra]
         adjwalls = pym.badjbxy(rv[2]['bound'], av[2]['bound'])
         for adjw in adjwalls:
             fnd.append((ra, adjw))
     return fnd
예제 #8
0
 def geoadj(self, rx, minovlp=0):
     rv = self.vs[rx]
     bd = rv[2]['bound']
     fnd = []
     for ra in range(self.vcnt):
         av = self.vs[ra]
         if av is None or av is rv: continue
         ab = av[2]['bound']
         adjwalls = pym.badjbxy(bd, ab)
         for adjw in adjwalls:
             fnd.append((ra, adjw))
     return fnd
예제 #9
0
 def anyadj(self,rx,minovlp = 0):
     rv = self.vs[rx]
     bd = rv[2]['bound']
     es = rv[1]
     fnd = []
     if not es:return fnd
     for ra in rv[1]:
         av = self.vs[ra]
         adjwalls = pym.badjbxy(rv[2]['bound'],av[2]['bound'])
         for adjw in adjwalls:
             fnd.append((ra,adjw))
     return fnd
예제 #10
0
 def vve(self,vx):
     v = self.vs[vx]
     if v is None:return
     vb = v[1]['b']
     rem = []
     for adj in self.orings[vx]:
         ov = self.vs[adj]
         if ov is None:
             print('vverem')
             rem.append(adj)
             continue
         ob = ov[1]['b']
         aws = pym.badjbxy(vb[0],ob[0])
         if not aws:self.re(adj,vx)
     for rm in rem:self.orings[vx].remove(rm)
예제 #11
0
 def vve(self,vx):
     v = self.vs[vx]
     if v is None:return
     vb = v[1]['fp']
     rem = []
     for adj in v[1]['edges']:
         ov = self.vs[adj]
         if ov is None:
             rem.append(adj)
             continue
         ob = ov[1]['fp']
         aws = pym.badjbxy(vb,ob)
         if not aws:self.re(adj,vx)
     for rm in rem:v[1]['edges'].remove(rm)
     for vexit in v[1]['exits']:
         for ox in range(self.vcnt):
             ov = self.vs[ox]
             if ov is None:continue
             if vexit.onbxy(ov[1]['fp']):
                 self.ae(ox,vx)
예제 #12
0
 def vve(self, vx):
     v = self.vs[vx]
     if v is None: return
     vb = v[1]['fp']
     rem = []
     for adj in v[1]['edges']:
         ov = self.vs[adj]
         if ov is None:
             rem.append(adj)
             continue
         ob = ov[1]['fp']
         aws = pym.badjbxy(vb, ob)
         if not aws: self.re(adj, vx)
     for rm in rem:
         v[1]['edges'].remove(rm)
     for vexit in v[1]['exits']:
         for ox in range(self.vcnt):
             ov = self.vs[ox]
             if ov is None: continue
             if vexit.onbxy(ov[1]['fp']):
                 self.ae(ox, vx)
예제 #13
0
    def plotxy(self,ax = None,scale = 250):
        if ax is None:ax = dtl.plot_axes_xy(scale)
        ax = pgr.planargraph.plotxy(self,ax)
        ekeys = []
        for vx in range(self.vcnt):
            v = self.vs[vx]
            if v is None:continue
            vb = v[1]['b']
            vrtls = '-'
            if 't' in v[1]:vrtls = '--' if 'developed' in v[1]['t'] else '-'
            conr = 1 if pym.bccw(vb[0]) else -1
            ax = dtl.plot_polygon_xy(pym.contract(vb[0],conr),
                ax,lw = 2,ls = vrtls,col = 'b')
            for ib in vb[1]:
                conr = 1 if pym.bccw(ib) else -1
                ax = dtl.plot_polygon_xy(pym.contract(ib,conr),ax,lw = 2,col = 'r')
            vbc = vec3(0,0,0).com(vb[0])
            rs = str(vx)+','+str(self.orings[vx])#+',\n'+str(v[1]['type'])
            ax = dtl.plot_point_xy_annotate(vbc,ax,rs)
            for ve in self.orings[vx]:
                ov = self.vs[ve]
                if ov is None:continue

                if not (vx,ve) in ekeys and not (ve,vx) in ekeys:
                    ekeys.append((vx,ve))
                    aws = pym.badjbxy(vb[0],ov[1]['b'][0],0)
                    for awx in range(len(aws)):
                        vwx,owx = aws[awx]
                        ex,ekws = self.es[self.elook[ekeys[-1]]]
                        door = vb[0][vwx-1].lerp(vb[0][vwx],ekws['p'])
                        ax = dtl.plot_point_xy(door,ax,col = 'r')

                ovbc = vec3(0,0,0).com(self.vs[ve][1]['b'][0])
                ax = dtl.plot_edges_xy((vbc,ovbc),ax,lw = 3,col = 'c')

            #for ep in v[1]['exits']:
            #    ax = dtl.plot_point_xy(ep,ax,mk = 's',col = 'r')

        return ax
예제 #14
0
 def holes(self, rx):
     dw, dh, dz = 1.5, 3, 0.0
     rv = self.bgraph.vs[rx]
     rb = rv[2]['bound']
     rexits = rv[2]['exits']
     for adj in self.bgraph.vs[rx][1]:
         ov = self.bgraph.vs[adj]
         if ov is None: continue
         elif ov[2]['level'] > rv[2]['level']: rv[2]['shaft'] = True
         elif ov[2]['level'] < rv[2]['level']: rv[2]['shaft'] = True
         else:
             ob = ov[2]['bound']
             aws = pym.badjbxy(rb, ob, minovlp=dw + 2)
             for aw in aws:
                 rwx, owx = aw
                 ips = pym.sintsxyp(rb[rwx - 1], rb[rwx], ob[owx - 1],
                                    ob[owx])
                 imp = ips[0].mid(ips[1])
                 ridp = 1 - rb[rwx - 1].d(imp) / rb[rwx - 1].d(rb[rwx])
                 if rv[2]['rtype'] == 'open' and ov[2]['rtype'] == 'open':
                     tdh = dh * 100
                     tww = max(rv[2]['wwidths'][rwx - 1],
                               ov[2]['wwidths'][rwx - 1])
                     tdw = ips[0].d(ips[1]) - 2 * tww
                     # hack door that consumes the wall
                     self.wallhole(rx, rwx - 1, (adj, ridp, tdw, tdh, dz))
                 else:
                     # typical door that does not consume the wall
                     self.wallhole(rx, rwx - 1, (adj, ridp, dw, dh, dz))
                 #rv[2]['wtypes'][rwx-1] = 'i'
                 rv[2]['wmetas'][rwx - 1]['type'] = 'i'
     gadjs = self.bgraph.geoadj(rx)
     for adj in gadjs:
         ov = self.bgraph.vs[adj[0]]
         if ov is None: continue
         ob = ov[2]['bound']
         aws = pym.badjbxy(rb, ob, minovlp=0)
         for aw in aws:
             rwx, owx = aw
             #if rv[2]['wtypes'][rwx-1] == 'e':
             #    rv[2]['wtypes'][rwx-1] = 'i'
             if rv[2]['wmetas'][rwx - 1]['type'] == 'e':
                 rv[2]['wmetas'][rwx - 1]['type'] = 'i'
     hasexit = False
     for wx in range(len(rb)):
         wp1, wp2 = rb[wx - 1], rb[wx]
         #wt = rv[2]['wtypes'][wx-1]
         wt = rv[2]['wmetas'][wx - 1]['type']
         if wt == 'e':
             isexit = False
             if rv[2]['level'] == 0:
                 for rex in rexits:
                     if rex is True:
                         if not hasexit:
                             self.wallhole(rx, wx - 1,
                                           ('exit', 0.5, dw, dh, dz))
                             hasexit = True
                             isexit = True
                             break
                     elif rex.onsxy(wp1, wp2) and not wp2.isnear(rex):
                         #elif gtl.onseg_xy(rex,wp1,wp2) and not wp2.isnear(rex):
                         print('external exit!', rex)
                         self.wallhole(rx, wx - 1,
                                       ('exit', 0.5, dw, dh, dz))
                         isexit = True
                         break
             wpd = wp1.d(wp2)
             #if not isexit and wpd > dw+2 and not rv[2]['rtype'] == 'closed':
             if wpd > dw + 2 and not rv[2]['rtype'] == 'closed':
                 self.windowholes(rx, wx - 1, wp1, wp2,
                                  **rv[2]['wmetas'][wx])
예제 #15
0
 def holes(self,rx):
     dw,dh,dz = 1.5,3,0.0
     rv = self.bgraph.vs[rx]
     rb = rv[2]['bound']
     rexits = rv[2]['exits']
     for adj in self.bgraph.vs[rx][1]:
         ov = self.bgraph.vs[adj]
         if ov is None:continue
         elif ov[2]['level'] > rv[2]['level']:rv[2]['shaft'] = True
         elif ov[2]['level'] < rv[2]['level']:rv[2]['shaft'] = True
         else:
             ob = ov[2]['bound']
             aws = pym.badjbxy(rb,ob,minovlp = dw+2)
             for aw in aws:
                 rwx,owx = aw
                 ips = pym.sintsxyp(rb[rwx-1],rb[rwx],ob[owx-1],ob[owx])
                 imp = ips[0].mid(ips[1])
                 ridp = 1-rb[rwx-1].d(imp)/rb[rwx-1].d(rb[rwx])
                 if rv[2]['rtype'] == 'open' and ov[2]['rtype'] == 'open':
                     tdh = dh*100
                     tww = max(rv[2]['wwidths'][rwx-1],ov[2]['wwidths'][rwx-1])
                     tdw = ips[0].d(ips[1])-2*tww
                     # hack door that consumes the wall
                     self.wallhole(rx,rwx-1,(adj,ridp,tdw,tdh,dz)) 
                 else:
                     # typical door that does not consume the wall
                     self.wallhole(rx,rwx-1,(adj,ridp,dw,dh,dz))
                 #rv[2]['wtypes'][rwx-1] = 'i'
                 rv[2]['wmetas'][rwx-1]['type'] = 'i'
     gadjs = self.bgraph.geoadj(rx)
     for adj in gadjs:
         ov = self.bgraph.vs[adj[0]]
         if ov is None:continue
         ob = ov[2]['bound']
         aws = pym.badjbxy(rb,ob,minovlp = 0)
         for aw in aws:
             rwx,owx = aw
             #if rv[2]['wtypes'][rwx-1] == 'e':
             #    rv[2]['wtypes'][rwx-1] = 'i'
             if rv[2]['wmetas'][rwx-1]['type'] == 'e':
                 rv[2]['wmetas'][rwx-1]['type'] = 'i'
     hasexit = False
     for wx in range(len(rb)):
         wp1,wp2 = rb[wx-1],rb[wx]
         #wt = rv[2]['wtypes'][wx-1]
         wt = rv[2]['wmetas'][wx-1]['type']
         if wt == 'e':
             isexit = False
             if rv[2]['level'] == 0:
                 for rex in rexits:
                     if rex is True:
                         if not hasexit:
                             self.wallhole(rx,wx-1,('exit',0.5,dw,dh,dz))
                             hasexit = True
                             isexit = True
                             break
                     elif rex.onsxy(wp1,wp2) and not wp2.isnear(rex):
                     #elif gtl.onseg_xy(rex,wp1,wp2) and not wp2.isnear(rex):
                         print('external exit!',rex)
                         self.wallhole(rx,wx-1,('exit',0.5,dw,dh,dz))
                         isexit = True
                         break
             wpd = wp1.d(wp2)
             #if not isexit and wpd > dw+2 and not rv[2]['rtype'] == 'closed':
             if wpd > dw+2 and not rv[2]['rtype'] == 'closed':
                 self.windowholes(rx,wx-1,wp1,wp2,**rv[2]['wmetas'][wx])