Пример #1
0
 def __init__(self, width, height, texture, border):
     
     module3d.Object3D.__init__(self, '9slice_' + texture + '_' + str(border))
     
     t = module3d.getTexture(texture)
     
     # Make sure fractions are calculated correctly
     textureWidth = float(t.width)
     textureHeight = float(t.height)
     
     # Make up some dimesnions when the texture is missing
     if not textureWidth or not textureHeight:
         textureWidth = border[0] + border[2] + 1
         textureHeight = border[1] + border[3] + 1
         
     outer=[[0, 0], [width, height]]
     inner=[[border[0], border[1]], [width - border[2], height - border[3]]]
         
     self.uvValues = []
     self.indexBuffer = []
     
     # create group
     fg = self.createFaceGroup('9slice')
     
     xc = [outer[0][0], inner[0][0], inner[1][0], outer[1][0]]
     yc = [outer[0][1], inner[0][1], inner[1][1], outer[1][1]]
     xuv = [0.0, border[0] / textureWidth, (textureWidth - border[2]) / textureWidth, 1.0]
     yuv = [1.0, 1.0 - border[1] / textureHeight, 1.0 - (textureHeight - border[3]) / textureHeight, 0.0]
     
     # The 16 vertices
     v = []
     for y in yc:
         for x in xc:  
             v.append(self.createVertex([x, y, 0.0]))
     
     # The 16 uv values
     uv = []
     for y in yuv:
         for x in xuv:  
             uv.append([x, y])
     
     # The 18 faces (9 quads)
     for y in xrange(3):
         for x in xrange(3):
             o = x + y * 4
             fg.createFace((v[o+4], v[o+5], v[o+1], v[o]), (uv[o+4], uv[o+5], uv[o+1], uv[o]))
             
     self.border = border
     self.texture = texture
     self.setCameraProjection(1)
     self.setShadeless(1)
     self.updateIndexBuffer()
Пример #2
0
    def __init__(self, width, height, texture, border):

        module3d.Object3D.__init__(self,
                                   '9slice_' + texture + '_' + str(border))

        t = module3d.getTexture(texture)

        # Make sure fractions are calculated correctly
        textureWidth = float(t.width)
        textureHeight = float(t.height)

        # Make up some dimesnions when the texture is missing
        if not textureWidth or not textureHeight:
            textureWidth = border[0] + border[2] + 1
            textureHeight = border[1] + border[3] + 1

        # create group
        fg = self.createFaceGroup('9slice')

        xc = [0, border[0], width - border[2], width]
        yc = [0, border[1], height - border[3], height]

        xuv = [
            0.0, border[0] / textureWidth,
            (textureWidth - border[2]) / textureWidth, 1.0
        ]
        yuv = [
            1.0, 1.0 - border[1] / textureHeight,
            1.0 - (textureHeight - border[3]) / textureHeight, 0.0
        ]

        # The 16 vertices
        v = [(x, y, 0.0) for y in yc for x in xc]

        # The 16 uv values
        uv = [(x, y) for y in yuv for x in xuv]

        # The 18 faces (9 quads)
        f = [[o + 4, o + 5, o + 1, o] for y in xrange(3) for x in xrange(3)
             for o in [x + y * 4]]

        self.setCoords(v)
        self.setUVs(uv)
        self.setFaces(f, f, fg.idx)

        self.border = border
        self.texture = texture
        self.setCameraProjection(1)
        self.setShadeless(1)
        self.updateIndexBuffer()
Пример #3
0
    def __init__(self, width, height, texture, border):
        
        module3d.Object3D.__init__(self, '9slice_' + texture + '_' + str(border))
        
        t = module3d.getTexture(texture)
        
        # Make sure fractions are calculated correctly
        textureWidth = float(t.width)
        textureHeight = float(t.height)
        
        # Make up some dimesnions when the texture is missing
        if not textureWidth or not textureHeight:
            textureWidth = border[0] + border[2] + 1
            textureHeight = border[1] + border[3] + 1
        
        # create group
        fg = self.createFaceGroup('9slice')
        
        xc = [0, border[0], width  - border[2], width]
        yc = [0, border[1], height - border[3], height]

        xuv = [0.0, border[0] / textureWidth, (textureWidth - border[2]) / textureWidth, 1.0]
        yuv = [1.0, 1.0 - border[1] / textureHeight, 1.0 - (textureHeight - border[3]) / textureHeight, 0.0]
        
        # The 16 vertices
        v = [(x, y, 0.0) for y in yc for x in xc]

        # The 16 uv values
        uv = [(x, y) for y in yuv for x in xuv]

        # The 18 faces (9 quads)
        f = [[o+4, o+5, o+1, o] for y in xrange(3) for x in xrange(3) for o in [x + y * 4]]

        self.setCoords(v)
        self.setUVs(uv)
        self.setFaces(f, f, fg.idx)

        self.border = border
        self.texture = texture
        self.setCameraProjection(1)
        self.setShadeless(1)
        self.updateIndexBuffer()
 def setEyes(self, human, mhstx):
     
     f = open(mhstx, 'rU')
     try:
         subTextures = eval(f.read(), {"__builtins__":None}, {'True':True, 'False':False})
     except:
         import traceback
         exc_type, exc_value, exc_traceback = sys.exc_info()
         print ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
         f.close()
         return
     f.close()
     
     texture = module3d.getTexture(human.getTexture())
     img = mh.Image(human.getTexture())
     
     for subTexture in subTextures:
         path = os.path.join('data/eyes', subTexture['txt'])
         subImg = mh.Image(path)
         x, y = subTexture['dst']
         img.blit(subImg, x, y)
         
     texture.loadSubImage(img, 0, 0)