def build_mesh_quads(self, vertList, quadBuffs):

        for matNum in quadBuffs:
            numIdx = 0
            idxBuff = bytes()
            vertBuff = bytes()
            idxList = quadBuffs[matNum]["idxList"]
            uvBuff = quadBuffs[matNum]["uvBuff"]
            for index in idxList:
                coords = vertList[index]
                vertBuff += struct.pack("3f", *(map(float, coords)))
                idxBuff += struct.pack("L", numIdx)
                numIdx += 1

            matName = self.matList[matNum].name
            rapi.rpgSetMaterial(matName)
            rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)

            if uvBuff:
                rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
            # RPGEO_QUAD, //ABC_DCB
            # RPGEO_QUAD_ABC_BCD,
            # RPGEO_QUAD_ABC_ACD,
            # RPGEO_QUAD_ABC_DCA
            rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx,
                                    noesis.RPGEO_QUAD_ABC_ACD, 1)
Exemple #2
0
 def parse_file(self):
     
     meshName = self.read_name()
     matName = self.read_name()
     texName = meshName
     
     numIdx = self.inFile.readUInt() * 3
     numVerts, numUV = self.inFile.read('2L')
     vertBuff = self.parse_vertices(numVerts)
     idxBuff = self.parse_faces(numIdx)
     uvBuff = self.parse_uv(numUV)
     self.parse_uv_index(numIdx)
     
     #create material
     material = NoeMaterial(matName, texName)
     self.matList.append(material)        
     
     #build mesh
     rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 24, 0)
     rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 24, 12)
     
     #commit triangles
     rapi.rpgSetMaterial(texName)
     rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
     
     #what to do with these UV's?
     rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)        
     
     
Exemple #3
0
    def __init__(self, data, i):
        data.seek(2, 1)
        self.numVert = data.readUShort()
        self.ptr = data.readUInt()
        data.seek(28, 1)
        self.xyz = data.read('3f')
        current = data.tell()
        data.seek(self.ptr + 2)
        self.headers = data.readUShort()
        pLine = 'SubMesh: \n  numVert: %d\n  Headers: %d' % (self.numVert,
                                                             self.headers)
        print(pLine)
        #if self.headers != 1:    print('Not Header 1',data.tell());data.seek(current);return
        data.seek(4, 1)
        ptrs = data.read('5I')

        data.seek(ptrs[0])
        rapi.rpgBindPositionBuffer(data.readBytes(self.numVert * 12),
                                   noesis.RPGEODATA_FLOAT, 12)
        data.seek(ptrs[1])
        rapi.rpgBindUV1Buffer(data.readBytes(self.numVert * 12),
                              noesis.RPGEODATA_FLOAT, 12)
        data.seek(ptrs[2])
        data.seek(current)
        mat = NoeMaterial(str(i), str(i))
        rapi.rpgSetMaterial(str(i))
        rapi.rpgCommitTriangles(None, noesis.RPGEODATA_UINT, self.numVert,
                                noesis.RPGEO_TRIANGLE_STRIP_FLIPPED, 1)
 def build_model(self):
     
     for mesh in self.meshes:
         
         positions = mesh["pos"]
         rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
         
         if "norms" in mesh:
             normals = mesh["norms"]
             #rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
         if "uv" in mesh:
             uv = mesh["uv"]
             rapi.rpgBindUV1Buffer(uv, noesis.RPGEODATA_FLOAT, 8)
             
         if "matIndexes" in mesh:
             matUsed = mesh["matIndexes"]
             
         idxBuff = mesh["idx"]
         numIdx = mesh["numIdx"]
         #print(numIdx)
         if "materials" in mesh:
             materials = mesh["materials"]
         else:
             materials = self.materials
         #rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx, noesis.RPGEO_TRIANGLE, 1)
         self.build_faces(idxBuff, matUsed, materials)
         rapi.rpgClearBufferBinds()
    def build_vertices(self, mesh, meshName):
        
        vertBuff = bytes()
        normBuff = bytes()
        uvBuff = bytes()
        idxBuff = bytes()
        rapi.rpgSetName(meshName)
        for i in range(mesh.numIdx):
            index = mesh.idxList[i]
            vertBuff += struct.pack('3f', *mesh.vertList[index])
            normBuff += struct.pack('3f', *mesh.normList[index])
            uvBuff += struct.pack('2f', *mesh.uvList[i])
            idxBuff += struct.pack('H', i)
            
        rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
        

        matName = meshName
        material = NoeMaterial(matName, self.basename)
        material.setDefaultBlend(0)
        self.matList.append(material)
        
        rapi.rpgSetMaterial(meshName)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)
    def build_vertices(self, mesh, meshName):

        vertBuff = bytes()
        normBuff = bytes()
        uvBuff = bytes()
        idxBuff = bytes()
        rapi.rpgSetName(meshName)
        for i in range(mesh.numIdx):
            index = mesh.idxList[i]
            vertBuff += struct.pack('3f', *mesh.vertList[index])
            normBuff += struct.pack('3f', *mesh.normList[index])
            uvBuff += struct.pack('2f', *mesh.uvList[i])
            idxBuff += struct.pack('H', i)

        rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)

        matName = meshName
        material = NoeMaterial(matName, self.basename)
        material.setDefaultBlend(0)
        self.matList.append(material)

        rapi.rpgSetMaterial(meshName)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, mesh.numIdx,
                                noesis.RPGEO_TRIANGLE, 1)
 def parse_vertices(self, numVerts, numNorms, numWeights):
     
     vertBuff = self.inFile.readBytes(numVerts*12)
     normBuff = self.inFile.readBytes(numNorms*12)
     uvBuff = self.inFile.readBytes(numVerts*8)
     unkBuff = self.inFile.readBytes(numVerts*4)
     weightBuff = self.inFile.readBytes(numWeights*8)
         
     if numVerts:
         rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
         #rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
    def parse_vertices(self, numVerts, numNorms, numWeights):

        vertBuff = self.inFile.readBytes(numVerts * 12)
        normBuff = self.inFile.readBytes(numNorms * 12)
        uvBuff = self.inFile.readBytes(numVerts * 8)
        unkBuff = self.inFile.readBytes(numVerts * 4)
        weightBuff = self.inFile.readBytes(numWeights * 8)

        if numVerts:
            rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
            #rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
            rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
    def parse_vertices(self, numVerts):

        positions = self.inFile.readBytes(numVerts * 12)
        normals = self.inFile.readBytes(numVerts * 12)
        uv = self.inFile.readBytes(numVerts * 8)

        rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uv, noesis.RPGEODATA_FLOAT, 8)

        if self.hasBones:
            bones = self.inFile.readBytes(numVerts * 8)  # 4 shorts
            weights = self.inFile.readBytes(numVerts * 16)  # 4 floats
    def parse_vertices(self, numVerts):

        positions = self.inFile.readBytes(numVerts * 12)
        normals = self.inFile.readBytes(numVerts * 12)
        uv = self.inFile.readBytes(numVerts * 8)
        
        rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uv, noesis.RPGEODATA_FLOAT, 8)        
        
        if self.hasBones:
            bones = self.inFile.readBytes(numVerts * 8) #4 shorts
            weights = self.inFile.readBytes(numVerts * 16) #4 floats
 def build_meshes(self):
     
     for mesh in self.meshList:
         rapi.rpgBindPositionBuffer(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgBindNormalBuffer(mesh.normBuff, noesis.RPGEODATA_FLOAT, 12)
         
         if mesh.uvBuff:
             rapi.rpgBindUV1Buffer(mesh.uvBuff, noesis.RPGEODATA_FLOAT, 8)
         
         for matNum in mesh.idxDict:
             idxBuff = mesh.idxDict[matNum]
             numIdx = len(idxBuff) // 2
             rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
             ##rapi.rpgSetMaterial(matName)
             rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
 def build_mesh(self):
     
     for mesh in self.meshList:
         
         rapi.rpgBindPositionBuffer(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgBindNormalBuffer(mesh.normBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgBindUV1Buffer(mesh.uvBuff, noesis.RPGEODATA_FLOAT, 8)            
         trans = NoeMat43((NoeVec3((1.0, 0.0, 0.0)), NoeVec3((0.0, 0.0, 1.0)), NoeVec3((0.0, 1.0, 0.0)), NoeVec3((0.0, 0.0, 0.0))))
         rapi.rpgSetTransform(trans)            
         
         matName = ""
         if mesh.matNum != -1:
             matName = self.matList[mesh.matNum].name
             
         rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         rapi.rpgSetMaterial(matName)
         rapi.rpgCommitTriangles(mesh.idxBuff, noesis.RPGEODATA_USHORT, mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)
Exemple #13
0
    def build_meshes(self):

        for mesh in self.meshList:
            rapi.rpgBindPositionBuffer(mesh.vertBuff, noesis.RPGEODATA_FLOAT,
                                       12)
            rapi.rpgBindNormalBuffer(mesh.normBuff, noesis.RPGEODATA_FLOAT, 12)

            if mesh.uvBuff:
                rapi.rpgBindUV1Buffer(mesh.uvBuff, noesis.RPGEODATA_FLOAT, 8)

            for matNum in mesh.idxDict:
                idxBuff = mesh.idxDict[matNum]
                numIdx = len(idxBuff) // 2
                rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
                ##rapi.rpgSetMaterial(matName)
                rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT,
                                        numIdx, noesis.RPGEO_TRIANGLE, 1)
def noepyLoadModel(data, mdlList):
    ctx = rapi.rpgCreateContext()
    model = ShenmueMt5(data)
    model.parse()
    rapi.rpgClearBufferBinds()
    noeMat = NoeModelMaterials(model.noeTextures, model.noeMaterials)
    rapi.rpgBindPositionBuffer(model.vertex_list, noesis.RPGEODATA_FLOAT, 0x0C)
    rapi.rpgBindNormalBuffer(model.normal_list, noesis.RPGEODATA_FLOAT, 0x0C)
    rapi.rpgBindUV1Buffer(model.uv_list, noesis.RPGEODATA_FLOAT, 0x08)

    for strip in model.polygon_list:
        rapi.rpgSetMaterial("material[%s]"%strip['texId'])
        rapi.rpgCommitTriangles(strip['face'], noesis.RPGEODATA_USHORT, int(len(strip['face'])/2), noesis.RPGEO_TRIANGLE, 0)
    mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(noeMat)
    mdlList.append(mdl)
    rapi.setPreviewOption("noTextureLoad", "1")
    rapi.rpgOptimize()
    return 1
 def build_mesh(self, mesh):
     
     vertBuff = bytes()
     normBuff = bytes()
     uvBuff = bytes()
     for i in range(mesh.numVerts):
         posIdx, normIdx, uvIdx = mesh.posList[i], mesh.normList[i], mesh.uvList[i]
         vertBuff = b''.join([vertBuff, mesh.vertBuff[posIdx * 12 : (posIdx+1) * 12]])
         normBuff = b''.join([normBuff, mesh.normBuff[normIdx * 12 : (normIdx+1) * 12]])
         uvBuff = b''.join([uvBuff, mesh.uvBuff[uvIdx * 8 : (uvIdx+1) * 8]])
         
     rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
     #rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, mesh.numVerts, noesis.RPGEO_POINTS, 1)
     
     numIdx = mesh.numFaces * 3
     matName = self.matList[0].name
     rapi.rpgSetMaterial(matName)
     rapi.rpgCommitTriangles(mesh.idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
 def build_mesh(self, vertList, normList, uvList, idxList, matrix1, texName):
     
     #build buffers
     vertBuff = bytes()
     normBuff = bytes()
     uvBuff = bytes()
     idxBuff = bytes()
     count = 0
     for idx in idxList:
         vertBuff += bytes(struct.pack('3f', *vertList[idx]))
         normBuff += struct.pack('3f', *normList[idx])
         uvBuff += struct.pack('2f', *uvList[count])
         idxBuff += struct.pack('L', count)
         count += 1
         
     rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)        
     rapi.rpgSetTransform(matrix1)
     rapi.rpgSetMaterial(texName)
     rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, count, noesis.RPGEO_TRIANGLE, 1)
 def parse_vertices(self, numVerts):
     
     #fields = self.get_fields()
     vertBuff = bytes()
     normBuff = bytes()
     uvBuff = bytes()
     for i in range(numVerts):
         verts = map(float, self.get_data().split(" "))
         norms = map(float, self.get_data().split(" "))
         uvs = map(float, self.get_data().split(" "))
         bones = map(int, self.get_data().split(" "))
         weights = map(float, self.get_data().split(" "))
         self.readline()
         
         vertBuff = b''.join([vertBuff, struct.pack('3f', *verts)])
         normBuff = b''.join([normBuff, struct.pack('3f', *norms)])
         uvBuff = b''.join([uvBuff, struct.pack('2f', *uvs)])
         
     rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)          
    def build_mesh(self):

        for mesh in self.meshList:

            rapi.rpgBindPositionBuffer(mesh.vertBuff, noesis.RPGEODATA_FLOAT,
                                       12)
            rapi.rpgBindNormalBuffer(mesh.normBuff, noesis.RPGEODATA_FLOAT, 12)
            rapi.rpgBindUV1Buffer(mesh.uvBuff, noesis.RPGEODATA_FLOAT, 8)
            trans = NoeMat43((NoeVec3((1.0, 0.0, 0.0)), NoeVec3(
                (0.0, 0.0, 1.0)), NoeVec3(
                    (0.0, 1.0, 0.0)), NoeVec3((0.0, 0.0, 0.0))))
            rapi.rpgSetTransform(trans)

            matName = ""
            if mesh.matNum != -1:
                matName = self.matList[mesh.matNum].name

            rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
            rapi.rpgSetMaterial(matName)
            rapi.rpgCommitTriangles(mesh.idxBuff, noesis.RPGEODATA_USHORT,
                                    mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)
    def parse_vertices(self, numVerts):

        #fields = self.get_fields()
        vertBuff = bytes()
        normBuff = bytes()
        uvBuff = bytes()
        for i in range(numVerts):
            verts = map(float, self.get_data().split(" "))
            norms = map(float, self.get_data().split(" "))
            uvs = map(float, self.get_data().split(" "))
            bones = map(int, self.get_data().split(" "))
            weights = map(float, self.get_data().split(" "))
            self.readline()

            vertBuff = b''.join([vertBuff, struct.pack('3f', *verts)])
            normBuff = b''.join([normBuff, struct.pack('3f', *norms)])
            uvBuff = b''.join([uvBuff, struct.pack('2f', *uvs)])

        rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
    def build_meshes(self):
        '''Build the meshes. For the buffers in each mesh, we have to 
        partition it based on the number of vertices a particular face group
        has'''
        
        for mesh in self.meshes:

            vertStart = 0
            vertEnd = 0
            uvStart = 0
            uvEnd = 0
            
            for i in range(mesh.numFaceGroups):
                idxBuff, numIdx, numVerts, matNum, numBones = mesh.idxBuffs[i]
                
                #partition verts and normals
                vertEnd += numVerts * 12
                vertBuff = mesh.vertBuff[vertStart:vertEnd]
                normBuff = mesh.normBuff[vertStart:vertEnd]
                rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
                rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
                vertStart += numVerts * 12
                
                #partition uv, if any
                if mesh.uvBuff:
                    uvEnd += numVerts * 8
                    uvBuff = mesh.uvBuff[uvStart:uvEnd]
                    rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
                    uvStart += numVerts * 8
                    
                rapi.rpgSetTransform(NoeMat43(((1, 0, 0),
                                              (0, 1, 0),
                                              (0, 0, 1),
                                              (0, 0, 0))))
                
                #commit triangles
                mat = self.matList[matNum]
                rapi.rpgSetMaterial(mat.name)
                rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx, noesis.RPGEO_TRIANGLE, 1)
    def build_meshes(self):
        '''Build the meshes. For the buffers in each mesh, we have to 
        partition it based on the number of vertices a particular face group
        has'''

        for mesh in self.meshes:

            vertStart = 0
            vertEnd = 0
            uvStart = 0
            uvEnd = 0

            for i in range(mesh.numFaceGroups):
                idxBuff, numIdx, numVerts, matNum, numBones = mesh.idxBuffs[i]

                #partition verts and normals
                vertEnd += numVerts * 12
                vertBuff = mesh.vertBuff[vertStart:vertEnd]
                normBuff = mesh.normBuff[vertStart:vertEnd]
                rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT,
                                           12)
                rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
                vertStart += numVerts * 12

                #partition uv, if any
                if mesh.uvBuff:
                    uvEnd += numVerts * 8
                    uvBuff = mesh.uvBuff[uvStart:uvEnd]
                    rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
                    uvStart += numVerts * 8

                rapi.rpgSetTransform(
                    NoeMat43(((1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0))))

                #commit triangles
                mat = self.matList[matNum]
                rapi.rpgSetMaterial(mat.name)
                rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx,
                                        noesis.RPGEO_TRIANGLE, 1)
 def build_mesh_quads(self, vertList, quadBuffs):
     
     for matNum in quadBuffs:
         numIdx = 0 
         idxBuff = bytes()
         vertBuff = bytes()
         idxList = quadBuffs[matNum]["idxList"]
         uvBuff = quadBuffs[matNum]["uvBuff"]
         for index in idxList:
             coords = vertList[index]
             vertBuff += struct.pack("3f", *(map(float, coords)))
             idxBuff += struct.pack("L", numIdx)
             numIdx += 1
         
         matName = self.matList[matNum].name
         rapi.rpgSetMaterial(matName)
         rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
         
         if uvBuff:
             rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
         
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx, noesis.RPGEO_QUAD, 1)        
 def build_mesh_tris(self, vertList, triBuffs):
     
     #iterate over all of the idxBuffs based on matNum
     for matNum in triBuffs:
         numIdx = 0 
         idxBuff = bytes()
         vertBuff = bytes()
         idxList = triBuffs[matNum]["idxList"]
         uvBuff = triBuffs[matNum]["uvBuff"]
         for index in idxList:
             coords = vertList[index]
             vertBuff += struct.pack("3f", *(map(float, coords)))
             idxBuff += struct.pack("L", numIdx)
             numIdx += 1
         
         matName = self.matList[matNum].name
         rapi.rpgSetMaterial(matName)
         rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
         if uvBuff:
             rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
         
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx, noesis.RPGEO_TRIANGLE, 1)
 def build_meshes(self, vertBuff, normBuff, uvBuff, idxBuff):
     
     for i in range(len(self.meshList)):
         mesh = self.meshList[i]
         vertStart = mesh.vertStart * 12
         vertEnd = vertStart + mesh.numVerts * 12
         uvStart = mesh.vertStart * 8
         uvEnd = uvStart + mesh.numVerts * 8
         idxStart = mesh.idxStart * 2
         idxEnd = idxStart + mesh.numIdx*2
         vBuff = vertBuff[vertStart:vertEnd]
         nBuff = normBuff[vertStart:vertEnd]
         uBuff = uvBuff[uvStart:uvEnd]
         iBuff = idxBuff[idxStart:idxEnd]
         
         rapi.rpgBindPositionBuffer(vBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgBindNormalBuffer(nBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgBindUV1Buffer(uBuff, noesis.RPGEODATA_FLOAT, 8)
         
         matName = self.matList[i].name
         rapi.rpgSetMaterial(matName)
         rapi.rpgCommitTriangles(iBuff, noesis.RPGEODATA_USHORT, mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)        
Exemple #25
0
    def build_mesh(self, vertList, normList, uvList, idxList, matrix1,
                   texName):

        #build buffers
        vertBuff = bytes()
        normBuff = bytes()
        uvBuff = bytes()
        idxBuff = bytes()
        count = 0
        for idx in idxList:
            vertBuff += bytes(struct.pack('3f', *vertList[idx]))
            normBuff += struct.pack('3f', *normList[idx])
            uvBuff += struct.pack('2f', *uvList[count])
            idxBuff += struct.pack('L', count)
            count += 1

        rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
        rapi.rpgSetTransform(matrix1)
        rapi.rpgSetMaterial(texName)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, count,
                                noesis.RPGEO_TRIANGLE, 1)
    def build_mesh_tris(self, vertList, triBuffs):

        #iterate over all of the idxBuffs based on matNum
        for matNum in triBuffs:
            numIdx = 0
            idxBuff = bytes()
            vertBuff = bytes()
            idxList = triBuffs[matNum]["idxList"]
            uvBuff = triBuffs[matNum]["uvBuff"]
            for index in idxList:
                coords = vertList[index]
                vertBuff += struct.pack("3f", *(map(float, coords)))
                idxBuff += struct.pack("L", numIdx)
                numIdx += 1

            matName = self.matList[matNum].name
            rapi.rpgSetMaterial(matName)
            rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
            if uvBuff:
                rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)

            rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numIdx,
                                    noesis.RPGEO_TRIANGLE, 1)
Exemple #27
0
    def build_meshes(self, vertBuff, normBuff, uvBuff, idxBuff):

        for i in range(len(self.meshList)):
            mesh = self.meshList[i]
            vertStart = mesh.vertStart * 12
            vertEnd = vertStart + mesh.numVerts * 12
            uvStart = mesh.vertStart * 8
            uvEnd = uvStart + mesh.numVerts * 8
            idxStart = mesh.idxStart * 2
            idxEnd = idxStart + mesh.numIdx * 2
            vBuff = vertBuff[vertStart:vertEnd]
            nBuff = normBuff[vertStart:vertEnd]
            uBuff = uvBuff[uvStart:uvEnd]
            iBuff = idxBuff[idxStart:idxEnd]

            rapi.rpgBindPositionBuffer(vBuff, noesis.RPGEODATA_FLOAT, 12)
            rapi.rpgBindNormalBuffer(nBuff, noesis.RPGEODATA_FLOAT, 12)
            rapi.rpgBindUV1Buffer(uBuff, noesis.RPGEODATA_FLOAT, 8)

            matName = self.matList[i].name
            rapi.rpgSetMaterial(matName)
            rapi.rpgCommitTriangles(iBuff, noesis.RPGEODATA_USHORT,
                                    mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)
 def parse_vertices(self, numVerts, vertType):
     
     positions = bytes()
     normals = bytes()
     uv = bytes()
     
     for i in range(numVerts):
         positions = b''.join([positions,self.inFile.readBytes(12)])
         normals = b''.join([normals, self.inFile.readBytes(12)])
         self.inFile.read('8f')
         uv = b''.join([uv, self.inFile.readBytes(8)])
         
         count = self.inFile.readUInt()
         for i in range(count):
             self.inFile.readUInt()
             self.inFile.read('4f')
     
     rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
     rapi.rpgBindUV1Buffer(uv, noesis.RPGEODATA_FLOAT, 8)
     #vertBuff = self.inFile.readBytes(88*numVerts)
     #rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 88, 0)
     
     self.invert_faces()
Exemple #29
0
    def build_mesh(self, mesh):

        vertBuff = bytes()
        normBuff = bytes()
        uvBuff = bytes()
        for i in range(mesh.numVerts):
            posIdx, normIdx, uvIdx = mesh.posList[i], mesh.normList[
                i], mesh.uvList[i]
            vertBuff = b''.join(
                [vertBuff, mesh.vertBuff[posIdx * 12:(posIdx + 1) * 12]])
            normBuff = b''.join(
                [normBuff, mesh.normBuff[normIdx * 12:(normIdx + 1) * 12]])
            uvBuff = b''.join([uvBuff, mesh.uvBuff[uvIdx * 8:(uvIdx + 1) * 8]])

        rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normBuff, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uvBuff, noesis.RPGEODATA_FLOAT, 8)
        #rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, mesh.numVerts, noesis.RPGEO_POINTS, 1)

        numIdx = mesh.numFaces * 3
        matName = self.matList[0].name
        rapi.rpgSetMaterial(matName)
        rapi.rpgCommitTriangles(mesh.idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                noesis.RPGEO_TRIANGLE, 1)
Exemple #30
0
    def parse_vertices(self, numVerts, vertType):

        positions = bytes()
        normals = bytes()
        uv = bytes()

        for i in range(numVerts):
            positions = b''.join([positions, self.inFile.readBytes(12)])
            normals = b''.join([normals, self.inFile.readBytes(12)])
            self.inFile.read('8f')
            uv = b''.join([uv, self.inFile.readBytes(8)])

            count = self.inFile.readUInt()
            for i in range(count):
                self.inFile.readUInt()
                self.inFile.read('4f')

        rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uv, noesis.RPGEODATA_FLOAT, 8)
        #vertBuff = self.inFile.readBytes(88*numVerts)
        #rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 88, 0)

        self.invert_faces()
 def __init__(self,data,i):
     data.seek(2,1)
     self.numVert        = data.readUShort()
     self.ptr            = data.readUInt()
     data.seek(28,1)
     self.xyz            = data.read('3f')
     current             = data.tell()
     data.seek(self.ptr+2)
     self.headers        = data.readUShort()
     pLine = 'SubMesh: \n  numVert: %d\n  Headers: %d'%(self.numVert,self.headers)
     print(pLine)
     #if self.headers != 1:    print('Not Header 1',data.tell());data.seek(current);return
     data.seek(4,1)
     ptrs                = data.read('5I')
     
     data.seek(ptrs[0])
     rapi.rpgBindPositionBuffer(data.readBytes(self.numVert *12), noesis.RPGEODATA_FLOAT, 12)
     data.seek(ptrs[1])
     rapi.rpgBindUV1Buffer(data.readBytes(self.numVert *12), noesis.RPGEODATA_FLOAT, 12)
     data.seek(ptrs[2])
     data.seek(current)
     mat = NoeMaterial(str(i),str(i))
     rapi.rpgSetMaterial(str(i))
     rapi.rpgCommitTriangles(None,noesis.RPGEODATA_UINT, self.numVert, noesis.RPGEO_TRIANGLE_STRIP_FLIPPED, 1)
 def parse_uv1(self, numVerts):
     
     buff = self.inFile.readBytes(numVerts*8)
     rapi.rpgBindUV1Buffer(buff, noesis.RPGEODATA_FLOAT, 8)
    def parse_uv1(self, numVerts):

        buff = self.inFile.readBytes(numVerts * 8)
        rapi.rpgBindUV1Buffer(buff, noesis.RPGEODATA_FLOAT, 8)
 def parse_uv(self, numUV):
     
     uvs = self.inFile.readBytes(numUV * 8)
     rapi.rpgBindUV1Buffer(uvs, noesis.RPGEODATA_FLOAT, 8)
Exemple #35
0
 def parse_uv(self, numUV):
     
     uvs = self.inFile.readBytes(numUV * 8)
     rapi.rpgBindUV1Buffer(uvs, noesis.RPGEODATA_FLOAT, 8)
Exemple #36
0
 def parse_uv(self, numUV):
     
     buff = self.inFile.readBytes(8*numUV)
     rapi.rpgBindUV1Buffer(buff, noesis.RPGEODATA_FLOAT, 8)
Exemple #37
0
def noepyLoadModel(data, mdlList):
    bs = NoeBitStream(data)
    if bs.readInt() != NOEPY_HEADER:
        return 0
    if bs.readInt() != NOEPY_VERSION:
        return 0

    #no need to explicitly free the context (created contexts are auto-freed after the handler), but DO NOT hold any references to it outside of this method
    ctx = rapi.rpgCreateContext()

    numMeshes = bs.readInt()
    for i in range(0, numMeshes):
        meshName = bs.readString()
        meshMat = bs.readString()
        numIdx = bs.readInt()
        numPos = bs.readInt()
        numNrm = bs.readInt()
        numUVs = bs.readInt()
        numTan = bs.readInt()
        numClr = bs.readInt()
        numWeights = bs.readInt()
        numBoneRefs = bs.readInt()
        if numBoneRefs > 0:
            boneMap = bs.read("i" * numBoneRefs)
            rapi.rpgSetBoneMap(boneMap)  #set the bone map

        rapi.rpgSetName(meshName)
        rapi.rpgSetMaterial(meshMat)

        triangles = bs.readBytes(numIdx * 4)
        positions = bs.readBytes(numPos * 12)
        normals = bs.readBytes(numPos * 12) if numNrm == numPos else None
        uvs = bs.readBytes(numPos * 12) if numUVs == numPos else None
        tans = bs.readBytes(numPos * 48) if numTan == numPos else None
        colors = bs.readBytes(numPos * 16) if numClr == numPos else None

        rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindUV1Buffer(uvs, noesis.RPGEODATA_FLOAT, 12)
        rapi.rpgBindColorBuffer(colors, noesis.RPGEODATA_FLOAT, 16, 4)
        if numWeights > 0:
            vwList = []
            for j in range(0, numWeights):
                vwNum = bs.readInt()
                bidx = []
                bwgt = []
                for k in range(0, vwNum):
                    bidx.append(bs.readInt())
                for k in range(0, vwNum):
                    bwgt.append(bs.readFloat())
                vwList.append(NoeVertWeight(bidx, bwgt))
            fw = NoeFlatWeights(vwList)
            rapi.rpgBindBoneIndexBuffer(fw.flatW[:fw.weightValOfs],
                                        noesis.RPGEODATA_INT,
                                        4 * fw.weightsPerVert,
                                        fw.weightsPerVert)
            rapi.rpgBindBoneWeightBuffer(fw.flatW[fw.weightValOfs:],
                                         noesis.RPGEODATA_FLOAT,
                                         4 * fw.weightsPerVert,
                                         fw.weightsPerVert)
        numMorphFrames = bs.readInt()
        for j in range(0, numMorphFrames):
            numMFPos = bs.readInt()
            numMFNrm = bs.readInt()
            morphPosAr = bs.readBytes(numMFPos * 12)
            rapi.rpgFeedMorphTargetPositions(morphPosAr,
                                             noesis.RPGEODATA_FLOAT, 12)
            if numMFNrm > 0:
                morphNrmAr = bs.readBytes(numMFNrm * 12)
                rapi.rpgFeedMorphTargetNormals(morphNrmAr,
                                               noesis.RPGEODATA_FLOAT, 12)
            rapi.rpgCommitMorphFrame(numMFPos)
        rapi.rpgCommitMorphFrameSet()

        rapi.rpgCommitTriangles(triangles, noesis.RPGEODATA_INT, numIdx,
                                noesis.RPGEO_TRIANGLE, 1)
        rapi.rpgClearBufferBinds(
        )  #reset in case a subsequent mesh doesn't have the same components

    mdl = rapi.rpgConstructModel()

    bones = []
    numBones = bs.readInt()
    for i in range(0, numBones):
        bone = noepyReadBone(bs)
        bones.append(bone)

    anims = []
    numAnims = bs.readInt()
    for i in range(0, numAnims):
        animName = bs.readString()
        numAnimBones = bs.readInt()
        animBones = []
        for j in range(0, numAnimBones):
            animBone = noepyReadBone(bs)
            animBones.append(animBone)
        animNumFrames = bs.readInt()
        animFrameRate = bs.readFloat()
        numFrameMats = bs.readInt()
        animFrameMats = []
        for j in range(0, numFrameMats):
            frameMat = NoeMat43.fromBytes(bs.readBytes(48))
            animFrameMats.append(frameMat)
        anim = NoeAnim(animName, animBones, animNumFrames, animFrameMats,
                       animFrameRate)
        anims.append(anim)

    mdl.setBones(bones)
    mdl.setAnims(anims)
    mdlList.append(
        mdl)  #important, don't forget to put your loaded model in the mdlList
    return 1
def noepyLoadModel(data, mdlList):
	bs = NoeBitStream(data)
	if bs.readInt() != NOEPY_HEADER:
		return 0
	if bs.readInt() != NOEPY_VERSION:
		return 0

	#no need to explicitly free the context (created contexts are auto-freed after the handler), but DO NOT hold any references to it outside of this method
	ctx = rapi.rpgCreateContext()

	numMeshes = bs.readInt()
	for i in range(0, numMeshes):
		meshName = bs.readString()
		meshMat = bs.readString()
		numIdx = bs.readInt()
		numPos = bs.readInt()
		numNrm = bs.readInt()
		numUVs = bs.readInt()
		numTan = bs.readInt()
		numClr = bs.readInt()
		numWeights = bs.readInt()
		numBoneRefs = bs.readInt()
		if numBoneRefs > 0:
			boneMap = bs.read("i"*numBoneRefs)
			rapi.rpgSetBoneMap(boneMap) #set the bone map

		rapi.rpgSetName(meshName)
		rapi.rpgSetMaterial(meshMat)

		triangles = bs.readBytes(numIdx * 4)
		positions = bs.readBytes(numPos * 12)
		normals = bs.readBytes(numPos * 12) if numNrm == numPos else None
		uvs = bs.readBytes(numPos * 12) if numUVs == numPos else None
		tans = bs.readBytes(numPos * 48) if numTan == numPos else None
		colors = bs.readBytes(numPos * 16) if numClr == numPos else None

		rapi.rpgBindPositionBuffer(positions, noesis.RPGEODATA_FLOAT, 12)
		rapi.rpgBindNormalBuffer(normals, noesis.RPGEODATA_FLOAT, 12)
		rapi.rpgBindUV1Buffer(uvs, noesis.RPGEODATA_FLOAT, 12)
		rapi.rpgBindColorBuffer(colors, noesis.RPGEODATA_FLOAT, 16, 4)
		if numWeights > 0:
			vwList = []
			for j in range(0, numWeights):
				vwNum = bs.readInt()
				bidx = []
				bwgt = []
				for k in range(0, vwNum):
					bidx.append(bs.readInt())
				for k in range(0, vwNum):
					bwgt.append(bs.readFloat())
				vwList.append(NoeVertWeight(bidx, bwgt))
			fw = NoeFlatWeights(vwList)
			rapi.rpgBindBoneIndexBuffer(fw.flatW[:fw.weightValOfs], noesis.RPGEODATA_INT, 4*fw.weightsPerVert, fw.weightsPerVert)
			rapi.rpgBindBoneWeightBuffer(fw.flatW[fw.weightValOfs:], noesis.RPGEODATA_FLOAT, 4*fw.weightsPerVert, fw.weightsPerVert)
		numMorphFrames = bs.readInt()
		for j in range(0, numMorphFrames):
			numMFPos = bs.readInt()
			numMFNrm = bs.readInt()
			morphPosAr = bs.readBytes(numMFPos * 12)
			rapi.rpgFeedMorphTargetPositions(morphPosAr, noesis.RPGEODATA_FLOAT, 12)
			if numMFNrm > 0:
				morphNrmAr = bs.readBytes(numMFNrm * 12)
				rapi.rpgFeedMorphTargetNormals(morphNrmAr, noesis.RPGEODATA_FLOAT, 12)
			rapi.rpgCommitMorphFrame(numMFPos)
		rapi.rpgCommitMorphFrameSet()

		rapi.rpgCommitTriangles(triangles, noesis.RPGEODATA_INT, numIdx, noesis.RPGEO_TRIANGLE, 1)
		rapi.rpgClearBufferBinds() #reset in case a subsequent mesh doesn't have the same components

	mdl = rapi.rpgConstructModel()

	bones = []
	numBones = bs.readInt()
	for i in range(0, numBones):
		bone = noepyReadBone(bs)
		bones.append(bone)

	anims = []
	numAnims = bs.readInt()
	for i in range(0, numAnims):
		animName = bs.readString()
		numAnimBones = bs.readInt()
		animBones = []
		for j in range(0, numAnimBones):
			animBone = noepyReadBone(bs)
			animBones.append(animBone)
		animNumFrames = bs.readInt()
		animFrameRate = bs.readFloat()
		numFrameMats = bs.readInt()
		animFrameMats = []
		for j in range(0, numFrameMats):
			frameMat = NoeMat43.fromBytes(bs.readBytes(48))
			animFrameMats.append(frameMat)
		anim = NoeAnim(animName, animBones, animNumFrames, animFrameMats, animFrameRate)
		anims.append(anim)

	mdl.setBones(bones)
	mdl.setAnims(anims)
	mdlList.append(mdl)			#important, don't forget to put your loaded model in the mdlList
	return 1
Exemple #39
0
def noepyLoadModel(data, mdlList):
    LOADANIM = 0
    ExportSkin = 1
    VertexBool = 0  #Vertex Bool = 1 is Vertex Tint Channel Vertex Bool = 0 is Material Layers
    #Remember Vertex Colors are BGRA
    ctx = rapi.rpgCreateContext()
    bs = NoeBitStream(data)
    rapi.rpgSetOption(noesis.RPGOPT_MORPH_RELATIVEPOSITIONS, 1)
    rapi.rpgSetOption(noesis.RPGOPT_MORPH_RELATIVENORMALS, 1)
    #IDSig = bs.readUInt()
    #Blank1 = bs.readUInt()
    #BSphereX = bs.readFloat()
    #BSphereY = bs.readFloat()
    #BSphereZ = bs.readFloat()
    #BSphereThing = bs.readFloat()
    #UNK1 = bs.readFloat()
    #BBoxX1 = bs.readFloat()
    #BBoxY1 = bs.readFloat()
    #BBoxZ1 = bs.readFloat()
    #BBoxX2 = bs.readFloat()
    #BBoxY2 = bs.readFloat()
    #BBoxZ2 = bs.readFloat()
    #BBoxScaleX1 = bs.readFloat()
    #BBoxScaleY1 = bs.readFloat()
    #BBoxScaleZ1 = bs.readFloat()
    #BBoxScaleX2 = bs.readFloat()
    #BBoxScaleY2 = bs.readFloat()
    #BBoxScaleZ2 = bs.readFloat()
    #MipConstantUV0 = bs.readFloat()
    #MipConstantUV1 = bs.readFloat()
    bs.seek(84, NOESEEK_ABS)
    posAli = 0

    #MTRL STUFF
    #MatSig = bs.readUInt()
    MatCount = bs.read("L")
    MatNames = []
    pos = bs.tell()
    print(MatCount, pos)
    #MTRL LOOP
    for i in range(0, MatCount[0]):
        #MatCharCount = bs.readUInt()
        #print(MatCharCount)
        #MatNames.append (bs.readBytes(MatCharCount).decode("ASCII").rstrip("\0"))
        bs.seek(4, NOESEEK_REL)
        MatNames.append(bs.readString())

#STBS LOOP
    print(MatNames)
    subMeshCount = bs.readUInt()
    print(subMeshCount)
    MatID = []
    VertCount = []
    VertBuffType = []
    FaceCount = []
    FaceType = []
    BoneIDS = []
    BIXD = []
    BoneIDLOC = []
    BoneIDS = []

    mdl = []
    VertID = []
    MorphVertPOS = []
    MorphVertNorm = []
    MorphFrameCountID = []
    MDLWritten = rapi.getInputName()
    MDLWrite = NoeBitStream()
    topname = rapi.getExtensionlessName(
        rapi.getExtensionlessName(rapi.getInputName()))
    for i in range(0, subMeshCount):
        BoneIDSPre = []
        print("Sub Mesh", i)
        tsbsSig = bs.readUInt()
        print(tsbsSig)
        MatID.append(bs.readUInt())
        Blank2 = bs.readUInt()
        BVXD = bs.readUInt()
        VertCount.append(bs.readUInt())
        VertBuffType.append(bs.readUShort())
        print(VertBuffType[i])
        MorphFrameCount = bs.readUInt()
        MorphFrameCountID.append(MorphFrameCount)
        if MorphFrameCount is 0:
            print(MorphFrameCount, "Morph Frame Count is 0")

        if MorphFrameCount is not 0:
            print(MorphFrameCount, "Morph Frame Count is not 0")
            n = 0
            MorphVertCountList = []
            FrameLOC = []
            FrameOrder = []
            for m in range(0, MorphFrameCount):
                pos = bs.tell()
                FrameLOC.append(pos)
                MorphVertCount = bs.readUInt()
                MorphVertCountList.append(MorphVertCount)
                #print("MorphVertCount", MorphVertCount)
                #n = 0
                FrameName = ("Frame_" + str(n))
                n = (n + 1)
                Frame = []
                for mv in range(0, MorphVertCount):
                    VertID.append(bs.readUInt())
                    VertX = bs.readUShort()
                    #pos = bs.tell()
                    #VertX = (VertX / 32767)
                    VertY = bs.readUShort()
                    #pos = bs.tell()
                    #VertY = (VertY / 32767)
                    VertZ = bs.readUShort()
                    #pos = bs.tell()
                    #VertZ = (VertZ / 32767)
                    VertNormX = bs.readUShort()
                    VertNormY = bs.readUShort()
                    VertNormZ = bs.readUShort()
                    bs.seek(8, NOESEEK_REL)
                    #pos = bs.tell()
            for mc in range(0, MorphFrameCount):
                FrameOrder.append(bs.readUShort())
            FinalMorphCount = bs.readUShort()
            MorphCharCount = bs.readUInt()
            MorphName = bs.readString()
            print(MorphName)

        if VertBuffType[i] == int(768) or VertBuffType[i] == int(256):
            bs.seek(3, NOESEEK_REL)
        pos = bs.tell()
        BIXD.append(pos)
        BIXDSig = bs.readUInt()
        Blank2 = bs.readUInt()
        FaceCount.append(bs.readUInt())
        FaceType.append(bs.readUInt())
        pos = bs.tell()
        BoneIDLOC.append(pos)
        BoneIDCount = bs.readUByte()
        for bi in range(0, BoneIDCount):
            BoneIDSPre.append(bs.readUByte())
        BoneIDS.append(BoneIDSPre)
        bs.seek(56, NOESEEK_REL)
        if VertBuffType[i] == (1280, ):
            crap = bs.readUShort()
            VertBuffType[i] = (1024, )
    print("MaterialIDS", MatID)
    #RigStuff
    if VertBuffType[0] == int(1024) or VertBuffType[0] == int(768):
        boneReList = RigStuff(VertBuffType, topname)


#MDLSourceStuff
    MeshExists = rapi.checkFileExists(topname + str(".Mesh"))
    if MeshExists:
        MDLFile = rapi.loadIntoByteArray(topname + str(".Mesh"))
    else:
        MDLFile = rapi.loadPairedFile("Brutal Legend", ".Mesh")
    MDL = NoeBitStream(MDLFile)
    MeshStarts = []
    MeshFaceStarts = []
    BONINDBUFF = []

    #print("MeshStarts", MeshStarts, "MeshFaceStarts", MeshFaceStarts)
    print("MDL AT ", MDL.tell())
    for s in range(0, subMeshCount):
        Face = []

        POS, NORM, TAN, UV1, UV2, COL1, COL2, BI, BW = VertStuff(
            MDL, VertCount[s], VertBuffType[s])
        POS = struct.pack('B' * len(POS), *POS)
        NORM = struct.pack('B' * len(NORM), *NORM)
        TAN = struct.pack('B' * len(TAN), *TAN)
        UV1 = struct.pack('B' * len(UV1), *UV1)
        UV2 = struct.pack('B' * len(UV2), *UV2)
        if VertBuffType[s] == int(1024) or VertBuffType[s] == int(512):
            rapi.rpgBindPositionBuffer(POS, noesis.RPGEODATA_HALFFLOAT, 8)
            rapi.rpgBindNormalBuffer(NORM, noesis.RPGEODATA_HALFFLOAT, 8)
            rapi.rpgBindTangentBuffer(TAN, noesis.RPGEODATA_HALFFLOAT, 8)
            rapi.rpgBindUV1Buffer(UV1, noesis.RPGEODATA_HALFFLOAT, 4)
            rapi.rpgBindUV2Buffer(UV2, noesis.RPGEODATA_HALFFLOAT, 4)
        if VertBuffType[s] == int(768) or VertBuffType[s] == int(256):
            rapi.rpgBindPositionBuffer(POS, noesis.RPGEODATA_FLOAT, 12)
            rapi.rpgBindNormalBuffer(NORM, noesis.RPGEODATA_FLOAT, 12)
            #rapi.rpgBindTangentBuffer(TAN, noesis.RPGEODATA_FLOAT, 16)
            rapi.rpgBindUV1Buffer(UV1, noesis.RPGEODATA_FLOAT, 8)
            rapi.rpgBindUV2Buffer(UV2, noesis.RPGEODATA_FLOAT, 8)
        if VertexBool:
            COL = COL2
        else:
            COL = COL1
        COL = struct.pack('B' * len(COL), *COL)
        #VertColor = BGRA
        rapi.rpgBindColorBuffer(COL, noesis.RPGEODATA_UBYTE, 4, 4)
        if VertBuffType[s] == int(1024) or VertBuffType[s] == int(768):
            rapi.rpgSetBoneMap(BoneIDS[s])
            IDS = struct.pack('B' * len(BI), *BI)
            WEIGHTS = struct.pack('B' * len(BW), *BW)
            if ExportSkin:
                print("Bind Skin")
                rapi.rpgBindBoneIndexBuffer(IDS, noesis.RPGEODATA_BYTE, 4, 4)
                rapi.rpgBindBoneWeightBuffer(WEIGHTS, noesis.RPGEODATA_UBYTE,
                                             4, 4)
        FaceBuff = MDL.readBytes(FaceCount[s] * 2)
        # FaceBuff = struct.pack('H'*len(Face), *Face)
        if MorphFrameCountID[s] is not 0:
            ##            RETURN = bs.tell()
            for mf in range(0, MorphFrameCountID[s]):

                bs.seek(FrameLOC[mf], NOESEEK_ABS)
                # print(FrameLOC[mf], FlexNames[FrameOrder[mf]])
                MorphVertCount = bs.readUInt()
                FramePOS = []
                FrameNorm = []
                FrameTan = []
                FrameIDS = []
                MorphPOS = []
                MorphNorm = []
                MorphTan = []
                for mm in range(0, MorphVertCount):
                    FrameIDS.append(bs.readUInt())
                    MPOSX = (((bs.readShort() / 32767) * 2))
                    MPOSY = (((bs.readShort() / 32767) * 2))
                    MPOSZ = (((bs.readShort() / 32767) * 2))
                    MNORMX = (((bs.readShort() / 32767) * 2))
                    MNORMY = (((bs.readShort() / 32767) * 2))
                    MNORMZ = (((bs.readShort() / 32767) * 2))
                    MTANX = (((bs.readShort() / 32767) * 2))
                    MTANY = (((bs.readShort() / 32767) * 2))
                    MTANZ = (((bs.readShort() / 32767) * 2))
                    MTANW = (((bs.readShort() / 32767) * 2))
                    FramePOS.append((float(MPOSX), float(MPOSY), float(MPOSZ)))
                    FrameNorm.append(
                        (float(MNORMX), float(MNORMY), float(MNORMZ)))
                    FrameTan.append((float(MTANX), float(MTANY), float(MTANZ),
                                     float(MTANW)))
                for mv in range(0, VertCount[s]):
                    if mv in FrameIDS:
                        ID = FrameIDS.index(mv)
                        MorphPOS.append(FramePOS[ID])
                        MorphNorm.append(FrameNorm[ID])
                        MorphTan.append(FrameTan[ID])
                    else:
                        MorphPOS.append((float(0.0), float(0.0), float(0.0)))
                        MorphNorm.append((float(0.0), float(0.0), float(0.0)))
                        MorphTan.append(
                            (float(0.0), float(0.0), float(0.0), float(0.0)))
                MPOSBUFF3 = list(itertools.chain.from_iterable(MorphPOS))
                MNORMBUFF = list(itertools.chain.from_iterable(MorphNorm))
                MTANBUFF = list(itertools.chain.from_iterable(MorphTan))
                #rapi.rpgSetName(MeshName)
                MPOS = struct.pack('f' * len(MPOSBUFF3), *MPOSBUFF3)
                MNORM = struct.pack('f' * len(MNORMBUFF), *MNORMBUFF)
                MTAN = struct.pack('f' * len(MTANBUFF), *MTANBUFF)
                rapi.rpgFeedMorphTargetPositions(MPOS, noesis.RPGEODATA_FLOAT,
                                                 12)
                rapi.rpgFeedMorphTargetNormals(MNORM, noesis.RPGEODATA_FLOAT,
                                               12)
                rapi.rpgCommitMorphFrame(VertCount[s])
                MPOSBUFF = []
                MNORMBUFF = []
                MTANBUFF = []
                MPOS = None
                MNORM = None
                MTAN = None
            rapi.rpgCommitMorphFrameSet()
        Mesh = ("Mesh_" + str(s))
        MeshName = str(Mesh)
        rapi.rpgSetName(MeshName)
        print(MatNames[MatID[s]])
        CurrentMaterial = MatNames[MatID[s]]
        CurrentMaterial = CurrentMaterial.replace('/', '_')
        rapi.rpgSetMaterial(CurrentMaterial)
        rapi.rpgSmoothTangents()
        if FaceType[s] == 2:
            rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT,
                                    FaceCount[s], noesis.RPGEO_TRIANGLE, 1)
        else:
            rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT,
                                    FaceCount[s], noesis.RPGEO_TRIANGLE_STRIP,
                                    1)
        rapi.rpgClearBufferBinds()

    mdl = rapi.rpgConstructModel()

    if LOADANIM == (0):
        print("No Anim")
        if VertBuffType[0] == int(1024) or VertBuffType[0] == int(768):
            mdl.setBones(boneReList)
        mdlList.append(
            mdl
        )  #important, don't forget to put your loaded model in the mdlList

    return 1