Exemplo n.º 1
0
 def flatnormal(self,mesh,f):
     if self.isneedle(mesh,f):
         pdb.set_trace()
     vs = mesh.mask(0,None,None,f)
     ps = [self.pset.ps[v[0]] for v in vs]
     n = pym.bnrm(ps)
     return n
Exemplo n.º 2
0
        def genplatform(shb, shx):
            buff, rw = 6, 6
            fbnd = pym.contract(shb, wwi)
            platform = [p.cp() for p in fbnd]
            r1, r2 = platform[2].cp(), platform[3].cp()
            rtn = r1.tov(r2).nrm().uscl(buff)
            #rnm = vec3(0,0,1).crs(rtn).nrm().uscl(rw)
            rnm = pym.bnrm(fbnd).crs(rtn).nrm().uscl(rw)
            r2, r1 = r2.trn(rtn.flp()), r1.trn(rtn.flp())
            r3, r4 = r2.cp().trn(rnm), r1.cp().trn(rnm)

            belv = self.bgraph.vs[sh[shx - 1]][2]
            rh = max(belv['wheights']) + belv['skirt'] + belv['crown']
            ramp = [r4, r1, r2, r3]

            platform = pym.ebdxy(platform, ramp)
            #print(len(platform))
            platform = platform[len(platform) //
                                2]  # HACK TO GET CORRECT POLYGON...

            ramp[0].ztrn(-rh)
            ramp[1].ztrn(-rh)

            m.asurf((ramp, ()), tm)
            m.asurf((platform, ()), tm)
Exemplo n.º 3
0
 def defroom(self,b,es,**kws):
     def defkw(k,d):
         if not k in kws:kws[k] = d
     wcnt = len(b)
     dwh = self.floorheight-1.0
     if pym.bnrm(b).z < 0:b.reverse()
     defkw('bound',tuple(b));defkw('exits',[]);defkw('rtype','room')
     defkw('floor',None);defkw('ceiling',None);defkw('shaft',False)
     defkw('level',0);defkw('skirt',0.5);defkw('crown',0.5)
     defkw('fholes',[]);defkw('choles',[])
     defkw('wholes',[[] for x in range(wcnt)])
     defkw('wmetas',[{'type':'e'} for x in range(wcnt)])
     #defkw('wtypes',['e' for x in range(wcnt)])
     defkw('wheights',[dwh for x in range(wcnt)])
     defkw('wwidths',[1.0 for x in range(wcnt)])
     return self.av(es,kws)
Exemplo n.º 4
0
    def vgen_terrain(self, w, v, t, r, a):
        m = dmo.model()
        sgv = w.amodel(None, None, None, m, w.sgraph.root)
        tm = m.agfxmesh()
        #vstitch isnt being used!!!
        #vstitch isnt being used!!!
        #vstitch isnt being used!!!
        # need to enforce that refinement is no problem for stitching!!!
        # need to enforce that refinement is no problem for stitching!!!
        # need to enforce that refinement is no problem for stitching!!!
        #  need to stitch from holes to interior regions!!!
        #  need to stitch from holes to interior regions!!!
        #  need to stitch from holes to interior regions!!!

        #vb = [b.cp() for b in v[1]['b'][0]]
        vb = [b.cp() for b in v.loop]
        vibs = [[b.cp() for b in h] for h in v.holes]
        #vibs = []
        vb = self.vstitch(vb, v, a)
        vibs = [self.vstitch(h, v, a) for h in v.holes]
        #v[1]['b'] = vb,vibs
        v.loop = vb
        v.holes = vibs

        print('generating terrain')
        ngvs = m.asurf((vb, vibs),
                       tm,
                       fm='grass2',
                       ref=True,
                       hmin=16,
                       zfunc=t,
                       rv=pym.bnrm(vb).z < 0,
                       uvstacked=None,
                       autoconnect=True)
        lockf = lambda p: p.onpxy((vb, vibs))
        m.subdiv(tm, False, True, lockf)
        #m.subdiv(tm,False,True,lockf)
        #m.subdiv(tm,False,True,lockf)
        m.uvs(tm)
        print('generated terrain')
        return m
Exemplo n.º 5
0
    def defroom(self, b, es, **kws):
        def defkw(k, d):
            if not k in kws: kws[k] = d

        wcnt = len(b)
        dwh = self.floorheight - 1.0
        if pym.bnrm(b).z < 0: b.reverse()
        defkw('bound', tuple(b))
        defkw('exits', [])
        defkw('rtype', 'room')
        defkw('floor', None)
        defkw('ceiling', None)
        defkw('shaft', False)
        defkw('level', 0)
        defkw('skirt', 0.5)
        defkw('crown', 0.5)
        defkw('fholes', [])
        defkw('choles', [])
        defkw('wholes', [[] for x in range(wcnt)])
        defkw('wmetas', [{'type': 'e'} for x in range(wcnt)])
        #defkw('wtypes',['e' for x in range(wcnt)])
        defkw('wheights', [dwh for x in range(wcnt)])
        defkw('wwidths', [1.0 for x in range(wcnt)])
        return self.av(es, kws)
Exemplo n.º 6
0
        def genplatform(shb,shx):
            buff,rw = 6,6
            fbnd = pym.contract(shb,wwi)
            platform = [p.cp() for p in fbnd]
            r1,r2 = platform[2].cp(),platform[3].cp()
            rtn = r1.tov(r2).nrm().uscl(buff)
            #rnm = vec3(0,0,1).crs(rtn).nrm().uscl(rw)
            rnm = pym.bnrm(fbnd).crs(rtn).nrm().uscl(rw)
            r2,r1 = r2.trn(rtn.flp()),r1.trn(rtn.flp())
            r3,r4 = r2.cp().trn(rnm),r1.cp().trn(rnm)

            belv = self.bgraph.vs[sh[shx-1]][2]
            rh = max(belv['wheights'])+belv['skirt']+belv['crown']
            ramp = [r4,r1,r2,r3]

            platform = pym.ebdxy(platform,ramp)
            #print(len(platform))
            platform = platform[len(platform)//2] # HACK TO GET CORRECT POLYGON...

            ramp[0].ztrn(-rh)
            ramp[1].ztrn(-rh)

            m.asurf((ramp,()),tm)
            m.asurf((platform,()),tm)
Exemplo n.º 7
0
    def test_bnrm(self):
        def pl():
            ax = dtl.plot_axes_xy(700)
            ax = dtl.plot_polygon_xy(fp,ax,lw = 2,col = 'g')
            ax = dtl.plot_points_xy(fp,ax,number = True)
            plt.show()

        ebnd = db.persistent_container('/home/cogle/dev/dilapidator/test/','ebnd')
        ebnd.load()
        ebnd = ebnd.data

        ax = dtl.plot_axes_xy(120)
        ax = dtl.plot_polygon_xy(ebnd,ax,lw = 4,col = 'r')
        ax = dtl.plot_points_xy(ebnd,ax,number = True)
        plt.show()

        fp = [
            vec3(-6.9831085205078125, 121.9827880859375, 0.0),
            vec3(-26.983108520507812, 121.9827880859375, 0.0),
            vec3(-46.98310852050781, 121.9827880859375, 0.0),
            vec3(-66.98310852050781, 121.9827880859375, 0.0),
            vec3(-85.984375, 121.9827880859375, 0.0),
            vec3(-85.98310852050781, 102.9827880859375, 0.0),
            vec3(-85.98310852050781, 82.9827880859375, 0.0),
            vec3(-85.98310852050781, 63.9814453125, 0.0),
            vec3(-66.98310852050781, 63.9827880859375, 0.0),
            vec3(-46.98310852050781, 63.9827880859375, 0.0),
            vec3(-26.983108520507812, 63.9827880859375, 0.0),
            vec3(-6.9831085205078125, 63.9827880859375, 0.0),
            vec3(13.016891479492188, 63.9827880859375, 0.0),
            vec3(33.01689147949219, 63.9827880859375, 0.0),
            vec3(53.01689147949219, 63.9827880859375, 0.0),
            vec3(73.01689147949219, 63.9827880859375, 0.0),
            vec3(93.01689147949219, 63.9827880859375, 0.0),
            vec3(112.017578125, 63.9827880859375, 0.0),
            vec3(112.01689147949219, 82.9827880859375, 0.0),
            vec3(112.01689147949219, 102.9827880859375, 0.0),
            vec3(112.01689147949219, 121.9833984375, 0.0),
            vec3(93.01689147949219, 121.9827880859375, 0.0),
            vec3(73.01689147949219, 121.9827880859375, 0.0),
            vec3(53.01689147949219, 121.9827880859375, 0.0),
            vec3(33.01689147949219, 121.9827880859375, 0.0),
            vec3(13.016891479492188, 121.9827880859375, 0.0)]
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(fp,ax,lw = 3,col = 'b')
        ax = dtl.plot_points_xy(fp,ax,number = True)
        plt.show()
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0,0,1)))

        vb = vec3(-100,100,0).sq(400,400)
        dx,dy,xn,yn = 20,20,10,30
        o = vec3(-dx*xn/2.0,-dy*yn,0).com(vb)
        vgrid = [o.cp().trn(vec3(x*dx,y*dy,0)) for y in range(yn) for x in range(xn)]
        boxes = [p.sq(dx,dy) for p in vgrid]
        boxes = [b for b in boxes if pym.binbxy(b,vb)]
        box = pym.bsuxy(boxes)
        self.assertTrue(pym.bnrm(box[0]).isnear(vec3(0,0,1)))

        fp = [vec3(0,0,0),
            vec3(20,0,0),vec3(20,-20,0),vec3(40,-30,0),vec3(60,-30,0),
            vec3(60,40,0),vec3(-60,40,0),vec3(-60,-30,0),vec3(-40,-30,0),
            vec3(-20,-20,0),vec3(-20,0,0)]
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0,0,1)))
        self.assertTrue(pym.bnrm(fp[::-1]).isnear(vec3(0,0,-1)))

        fp = [
            vec3(-282.1204528808594, 127.64604187011719, 0.0),
            vec3(-334.1018981933594, 179.6274871826172, 0.0),
            vec3(-130.43038940429688, 179.62747192382812, 0.0),
            vec3(-130.43038940429688, 336.434326171875, 0.0),
            vec3(-36.91655731201172, 366.8188171386719, 0.0),
            vec3(-36.916534423828125, 461.72088623046875, 0.0),
            vec3(191.35768127441406, 461.841796875, 0.0),
            vec3(275.3216552734375, 373.85748291015625, 0.0),
            vec3(152.47915649414062, 204.779296875, 0.0),
            vec3(332.7578430175781, -43.35302734375, 0.0),
            vec3(454.96630859375, -3.6450958251953125, 0.0),
            vec3(456.61492919921875, -166.4105224609375, 0.0), 
            vec3(316.5687561035156, -120.90676879882812, 0.0),
            vec3(201.97442626953125, -278.63232421875, 0.0), 
            vec3(277.8673400878906, -383.0899963378906, 0.0),
            vec3(195.58241271972656, -472.19598388671875, 0.0),
            vec3(-10.369781494140625, -468.9277038574219, 0.0),
            vec3(-10.369804382324219, -395.02154541015625, 0.0),
            vec3(-78.82841491699219, -326.56292724609375, 0.0),
            vec3(-175.64352416992188, -326.56292724609375, 0.0),
            vec3(-244.10214233398438, -395.0215759277344, 0.0),
            vec3(-244.10214233398438, -414.89117431640625, 0.0),
            vec3(-465.6239929199219, -192.85736083984375, 0.0),
            vec3(-466.0299072265625, -122.715087890625, 0.0),
            vec3(-385.8233947753906, -122.71507263183594, 0.0),
            vec3(-282.1204528808594, -19.01211929321289, 0.0),
                ]
        bn = pym.bnrm(fp)
        print('bnnn',bn)
        fp.reverse()
        pl()
        bn = pym.bnrm(fp)
        print('bnnnrev',bn)
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0,0,1)))
        self.assertTrue(pym.bnrm(fp[::-1]).isnear(vec3(0,0,-1)))
Exemplo n.º 8
0
    def test_bnrm(self):
        def pl():
            ax = dtl.plot_axes_xy(700)
            ax = dtl.plot_polygon_xy(fp, ax, lw=2, col='g')
            ax = dtl.plot_points_xy(fp, ax, number=True)
            plt.show()

        ebnd = db.persistent_container('/home/cogle/dev/dilapidator/test/',
                                       'ebnd')
        ebnd.load()
        ebnd = ebnd.data

        ax = dtl.plot_axes_xy(120)
        ax = dtl.plot_polygon_xy(ebnd, ax, lw=4, col='r')
        ax = dtl.plot_points_xy(ebnd, ax, number=True)
        plt.show()

        fp = [
            vec3(-6.9831085205078125, 121.9827880859375, 0.0),
            vec3(-26.983108520507812, 121.9827880859375, 0.0),
            vec3(-46.98310852050781, 121.9827880859375, 0.0),
            vec3(-66.98310852050781, 121.9827880859375, 0.0),
            vec3(-85.984375, 121.9827880859375, 0.0),
            vec3(-85.98310852050781, 102.9827880859375, 0.0),
            vec3(-85.98310852050781, 82.9827880859375, 0.0),
            vec3(-85.98310852050781, 63.9814453125, 0.0),
            vec3(-66.98310852050781, 63.9827880859375, 0.0),
            vec3(-46.98310852050781, 63.9827880859375, 0.0),
            vec3(-26.983108520507812, 63.9827880859375, 0.0),
            vec3(-6.9831085205078125, 63.9827880859375, 0.0),
            vec3(13.016891479492188, 63.9827880859375, 0.0),
            vec3(33.01689147949219, 63.9827880859375, 0.0),
            vec3(53.01689147949219, 63.9827880859375, 0.0),
            vec3(73.01689147949219, 63.9827880859375, 0.0),
            vec3(93.01689147949219, 63.9827880859375, 0.0),
            vec3(112.017578125, 63.9827880859375, 0.0),
            vec3(112.01689147949219, 82.9827880859375, 0.0),
            vec3(112.01689147949219, 102.9827880859375, 0.0),
            vec3(112.01689147949219, 121.9833984375, 0.0),
            vec3(93.01689147949219, 121.9827880859375, 0.0),
            vec3(73.01689147949219, 121.9827880859375, 0.0),
            vec3(53.01689147949219, 121.9827880859375, 0.0),
            vec3(33.01689147949219, 121.9827880859375, 0.0),
            vec3(13.016891479492188, 121.9827880859375, 0.0)
        ]
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(fp, ax, lw=3, col='b')
        ax = dtl.plot_points_xy(fp, ax, number=True)
        plt.show()
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0, 0, 1)))

        vb = vec3(-100, 100, 0).sq(400, 400)
        dx, dy, xn, yn = 20, 20, 10, 30
        o = vec3(-dx * xn / 2.0, -dy * yn, 0).com(vb)
        vgrid = [
            o.cp().trn(vec3(x * dx, y * dy, 0)) for y in range(yn)
            for x in range(xn)
        ]
        boxes = [p.sq(dx, dy) for p in vgrid]
        boxes = [b for b in boxes if pym.binbxy(b, vb)]
        box = pym.bsuxy(boxes)
        self.assertTrue(pym.bnrm(box[0]).isnear(vec3(0, 0, 1)))

        fp = [
            vec3(0, 0, 0),
            vec3(20, 0, 0),
            vec3(20, -20, 0),
            vec3(40, -30, 0),
            vec3(60, -30, 0),
            vec3(60, 40, 0),
            vec3(-60, 40, 0),
            vec3(-60, -30, 0),
            vec3(-40, -30, 0),
            vec3(-20, -20, 0),
            vec3(-20, 0, 0)
        ]
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0, 0, 1)))
        self.assertTrue(pym.bnrm(fp[::-1]).isnear(vec3(0, 0, -1)))

        fp = [
            vec3(-282.1204528808594, 127.64604187011719, 0.0),
            vec3(-334.1018981933594, 179.6274871826172, 0.0),
            vec3(-130.43038940429688, 179.62747192382812, 0.0),
            vec3(-130.43038940429688, 336.434326171875, 0.0),
            vec3(-36.91655731201172, 366.8188171386719, 0.0),
            vec3(-36.916534423828125, 461.72088623046875, 0.0),
            vec3(191.35768127441406, 461.841796875, 0.0),
            vec3(275.3216552734375, 373.85748291015625, 0.0),
            vec3(152.47915649414062, 204.779296875, 0.0),
            vec3(332.7578430175781, -43.35302734375, 0.0),
            vec3(454.96630859375, -3.6450958251953125, 0.0),
            vec3(456.61492919921875, -166.4105224609375, 0.0),
            vec3(316.5687561035156, -120.90676879882812, 0.0),
            vec3(201.97442626953125, -278.63232421875, 0.0),
            vec3(277.8673400878906, -383.0899963378906, 0.0),
            vec3(195.58241271972656, -472.19598388671875, 0.0),
            vec3(-10.369781494140625, -468.9277038574219, 0.0),
            vec3(-10.369804382324219, -395.02154541015625, 0.0),
            vec3(-78.82841491699219, -326.56292724609375, 0.0),
            vec3(-175.64352416992188, -326.56292724609375, 0.0),
            vec3(-244.10214233398438, -395.0215759277344, 0.0),
            vec3(-244.10214233398438, -414.89117431640625, 0.0),
            vec3(-465.6239929199219, -192.85736083984375, 0.0),
            vec3(-466.0299072265625, -122.715087890625, 0.0),
            vec3(-385.8233947753906, -122.71507263183594, 0.0),
            vec3(-282.1204528808594, -19.01211929321289, 0.0),
        ]
        bn = pym.bnrm(fp)
        print('bnnn', bn)
        fp.reverse()
        pl()
        bn = pym.bnrm(fp)
        print('bnnnrev', bn)
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0, 0, 1)))
        self.assertTrue(pym.bnrm(fp[::-1]).isnear(vec3(0, 0, -1)))