示例#1
0
 def _createVertexBuffer(self):
     self.vertexbuffer = VertexBuffer.MakeStandardVertexBuffer(
         vertices=[vec3(*x) for x in self.vertexArray],
         tex_coords=ListFunctions.flattenListOfLists(self.texCoords),
         tex_coords_2=ListFunctions.flattenListOfLists(self.worldTexCoords))
     self.indexbuffer = VertexBuffer.IndexBufferObject(self.indexArray,
                                                       element_type='I')
示例#2
0
 def onInit(self):
     self.points = [
         vec3(-0.5, -0.5, 0),
         vec3(0.5, -0.5, 0),
         vec3(0.0, 0.5, 0)
     ]
     self.normals = [vec3(0, 0, 1), vec3(0, 0, 1), vec3(0, 0, 1)]
     self.colors = [vec4(0, 0, 1, 1), vec4(0, 1, 0, 1), vec4(1, 0, 0, 1)]
     self.vbo = VertexBuffer.MakeStandardVertexBuffer(self.points,
                                                      colors=self.colors)
     self.indexbuffer = VertexBuffer.IndexBufferObject([0, 1, 2])
示例#3
0
文件: Mesh.py 项目: rosedu/hfall
 def createBuffers(self, vertices, texCoords, normals, colors, triangles, triSize):
     buffSize = (len(vertices) + len(normals) + len(texCoords) + len(colors)) * sizeof(GLfloat)
     self.vertBuff = VertexBuffer(buffSize)
     self.vertices = VBOArray(len(vertices), GLfloat, vertices, self.vertBuff)
     self.normals = VBOArray(len(normals), GLfloat, normals, self.vertBuff)
     self.texCoords = VBOArray(len(texCoords), GLfloat, texCoords, self.vertBuff)
     self.colors = VBOArray(len(colors), GLfloat, colors, self.vertBuff)
     buffSize = triSize*sizeof(GLuint)
     self.facesBuffer = VertexBuffer(buffSize, target = VertexBuffer.ELEMENT_ARRAY_BUFFER)
     for triangle in triangles:
         vbo = VBOArray(len(triangle.faces), GLuint, triangle.faces, self.facesBuffer)
         triangle.faces = vbo
示例#4
0
 def makeVertexBuffer(self):
     self.vertexbuffer = VertexBuffer.MakeStandardVertexBuffer(
         vertices=[vec3(*x) for x in self.vertices_gl],
         normals=[vec3(*x) for x in self.normals_gl],
         tex_coords=ListFunctions.flattenListOfLists(self.texcoord_gl))
     self.indexbuffer = VertexBuffer.IndexBufferObject(self.indices_gl)
示例#5
0
文件: Mesh.py 项目: rosedu/hfall
class Mesh:

    class Triangles:
    
        def __init__(self, faces, material):
            self.start = min(faces)
            self.end = max(faces)
            self.material = material
            self.faces = faces
            self.size = len(faces)

    class Geometry:
        
        def __init__(self, vertices, texCoords, faces, tangents = None,
                     binormal = None, normals = None):
            
            self.vertices = vertices
            self.texCoords = texCoords
            self.faces = faces
            self.tangents = None
            self.binormals = None
            self.normals = None

        def computeTangentSpace(self):
            if not self.faces:
                return
            tbn = MathBase.computeTangentSpace(self.vertices, self.texCoords, self.faces)
            self.tangents = tbn[0]
            self.binormals = tbn[1]
            self.normals = tbn[2]

        def toList(self, data):
            p = []
            if(data):
                for i in range(len(data)):
                    p.extend(data[i])
            return p
            

    
    def __init__(self, geometry, triangles, matrix = Coordinate(), draw_mode = GL_TRIANGLES):

        self.vertices = None
        self.normals = None
        self.texCoords = None
        self.colors = None
        self.facesBuffer = None
        self.triangles = triangles
        self.matrix = matrix
        self.mode = draw_mode
        self.geometry = geometry
        self.name = "None"

    def init(self):
        self.geometry.computeTangentSpace()
        vertices = self.geometry.toList(self.geometry.vertices)
        texCoords = self.geometry.toList(self.geometry.texCoords)
        normals = self.geometry.toList(self.geometry.normals)
        colors = (len(vertices))*[1, 1, 1]
        #self.matrix4 = (GLfloat *len(self.matrix4))(*self.matrix4)
        triSize = len(self.geometry.faces)*3
        self.createBuffers(vertices, texCoords, normals, colors, self.triangles, triSize)

    def createBuffers(self, vertices, texCoords, normals, colors, triangles, triSize):
        buffSize = (len(vertices) + len(normals) + len(texCoords) + len(colors)) * sizeof(GLfloat)
        self.vertBuff = VertexBuffer(buffSize)
        self.vertices = VBOArray(len(vertices), GLfloat, vertices, self.vertBuff)
        self.normals = VBOArray(len(normals), GLfloat, normals, self.vertBuff)
        self.texCoords = VBOArray(len(texCoords), GLfloat, texCoords, self.vertBuff)
        self.colors = VBOArray(len(colors), GLfloat, colors, self.vertBuff)
        buffSize = triSize*sizeof(GLuint)
        self.facesBuffer = VertexBuffer(buffSize, target = VertexBuffer.ELEMENT_ARRAY_BUFFER)
        for triangle in triangles:
            vbo = VBOArray(len(triangle.faces), GLuint, triangle.faces, self.facesBuffer)
            triangle.faces = vbo

    def renderNonTextured(self, renderDevice):
        self.vertices.buffer.enable()
        renderDevice.texCoordPointer(self.texCoords.pointer(), [0])
        renderDevice.colorPointer(self.colors.pointer())
        renderDevice.normalPointer(self.normals.pointer())
        renderDevice.vertexPointer(self.vertices.pointer())
        self.facesBuffer.enable()
        for triangle in self.triangles:
            renderDevice.drawRangeElements(self.mode, triangle)
        self.vertices.buffer.disable()
        self.facesBuffer.disable()

    def render(self, renderDevice):
        self.vertices.buffer.enable()
        renderDevice.texCoordPointer(self.texCoords.pointer(), [0, 1])
        renderDevice.colorPointer(self.colors.pointer())
        renderDevice.normalPointer(self.normals.pointer())
        renderDevice.vertexPointer(self.vertices.pointer())
        self.facesBuffer.enable()
        
        for triangle in self.triangles:
            renderDevice.configureMaterial(triangle.material)
            renderDevice.drawRangeElements(self.mode, triangle)
            glDisable(GL_TEXTURE_2D)
        
        self.vertices.buffer.disable()
        self.facesBuffer.disable()
示例#6
0
 def onInit(self):
     self.points = [-0.5, -0.5, 0, 0.5, -0.5, 0, 0.0, 0.5, 0]
     datablock = VertexBuffer.DataBlock('vertex', self.points)
     self.vb = VertexBuffer.VertexBufferObject([datablock])