def parse_meshes(self, numMesh):
     
     for i in range(numMesh):
         meshNum = self.inFile.readUInt()
         print(meshNum, self.inFile.tell())
         self.inFile.seek(28, 1)
         unk, numMat, unk, unk = self.inFile.read('4L')
         unk, numVerts, unk1, numIdx = self.inFile.read('4L')
         self.inFile.read('12f')
         self.inFile.seek(16, 1)
         
         self.parse_material(numMat)
         self.read_name()
         self.inFile.read('8L')
         self.inFile.read('16f')
         self.inFile.read('16f')
         self.inFile.seek(116, 1)
         
         count1, count2 = self.inFile.read('2L')
         self.inFile.seek(52, 1)
         self.parse_vertices(numVerts)
         idxBuff = self.parse_faces(numIdx)
         rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
         
         
         count = self.inFile.readUInt()
         while count > abs(meshNum + 2) or count == 0:
             count = self.inFile.readUInt()
             if self.inFile.tell() == self.inFile.dataSize:
                 break
         self.inFile.seek(-4, 1)
 def build_meshes(self):
         
     rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
     for i in range(len(self.meshList)):
         mesh = self.meshList[i]        
         rapi.rpgSetName(mesh.name)
         if mesh.vertSize == 32:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 32, 0)
             rapi.rpgBindNormalBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 32, 12)
             rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 32, 24)
         elif mesh.vertSize == 40:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 40, 0)
             rapi.rpgBindNormalBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 40, 20)
             rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 40, 32)
         elif mesh.vertSize == 48:
             rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 48, 0)
             rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 48, 28)
             rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 48, 40)
                         
         for sub in mesh.submeshes:            
             idxStart = sub.idxOfs
             idxEnd = idxStart + sub.numIdx * 2
             idxBuff = mesh.idxBuff[idxStart:idxEnd]
         
             rapi.rpgSetMaterial(self.tex)
             rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, sub.numIdx, noesis.RPGEO_TRIANGLE, 1)
 def build_meshes(self):
     
     rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
     for mesh in self.meshList:
         
         print(mesh.vertSize)
         if mesh.vertSize == 28:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 28, 0)
         elif mesh.vertSize == 32:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 32, 0)
             #rapi.rpgBindNormalBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 32, 20)
             rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_HALFFLOAT, 32, 16)
         elif mesh.vertSize == 36:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 36, 0)
         elif mesh.vertSize == 40:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 40, 0)
         elif mesh.vertSize == 44:
             rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 44, 0)
         
         
         #for j in range(mesh.numFaceGroups): # Not sure
         for j in range(1):
             numIdx = mesh.numIndices[j]
             idxBuff = mesh.idxBuffs[j]
             rapi.rpgSetMaterial("WP_A_1550small.tga")
             rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE_STRIP, 1)
def noepyLoadModel(data, mdlList):
    '''Build the model, set materials, bones, and animations. You do not
    need all of them as long as they are empty lists (they are by default)'''

    ctx = rapi.rpgCreateContext()
    parser = SanaeParser(data)
    parser.parse_file()

    #build meshes
    for pose in parser.vertGroups.keys():
        print(pose, len(parser.vertGroups[pose]))
    vertBuffs = parser.vertGroups["walk"]
    for i in range(len(vertBuffs)):
        idxBuff, numIdx, matNum = parser.idxBuffs[i % len(parser.idxBuffs)]
        vertBuff = vertBuffs[i]
        rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 0)
        rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 12)
        rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 24)

        matName = parser.matList[matNum].name
        rapi.rpgSetMaterial(matName)
        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                noesis.RPGEO_TRIANGLE, 1)

    mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(parser.texList, parser.matList))
    mdl.setBones(parser.boneList)
    mdl.setAnims(parser.animList)
    mdlList.append(mdl)
    return 1
Beispiel #5
0
    def build_meshes(self):

        for i in range(len(self.idxBuffs)):
            idxBuff, numIdx, matNum = self.idxBuffs[i]
            vertBuff, vertType = self.vertBuffs[i]
            if matNum != -1:
                matName = self.matList[matNum].name
                rapi.rpgSetMaterial(matName)

            if vertType == 0.125:
                rapi.rpgBindPositionBufferOfs(vertBuff,
                                              noesis.RPGEODATA_HALFFLOAT, 16,
                                              0)
                rapi.rpgBindNormalBufferOfs(vertBuff,
                                            noesis.RPGEODATA_HALFFLOAT, 16, 6)
                rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT,
                                         16, 12)

            elif vertType in [0.0333, 0.0335]:
                rapi.rpgBindPositionBufferOfs(vertBuff,
                                              noesis.RPGEODATA_HALFFLOAT, 22,
                                              0)
                rapi.rpgBindNormalBufferOfs(vertBuff,
                                            noesis.RPGEODATA_HALFFLOAT, 22, 6)
                rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT,
                                         22, 18)

            rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)

            rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                    noesis.RPGEO_TRIANGLE, 1)
Beispiel #6
0
    def CreateModel(self):

        for n in range(self.numMesh):
            rapi.rpgBindPositionBufferOfs(self.vertBuff[n],
                                          noesis.RPGEODATA_HALFFLOAT, 64, 0)
            rapi.rpgBindUV1BufferOfs(self.vertBuff[n], noesis.RPGEODATA_SHORT,
                                     64, 16)
            rapi.rpgBindUV2BufferOfs(self.vertBuff[n], noesis.RPGEODATA_SHORT,
                                     64, 16)

            idxBuffer = self.idxBuff[n][:]
            for i in range(self.numDrawCall[n]):
                numDrawFace = self.drawCallFace[n][i]
                idxBuff = idxBuffer[:numDrawFace * 6]
                idxBuffer = idxBuffer[numDrawFace * 6:]
                rapi.rpgSetMaterial(self.matList[self.matID[n][i]].name)
                if self.matID[n][i] in self.matEmis:
                    #rapi.rpgSetLightmap(self.matEmis[self.matID[n][i]].name)
                    self.matList[self.matID[n][i]].setNextPass(
                        self.matEmis[self.matID[n][i]])
                rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
                if SKIPTOID:
                    rapi.rpgBindBoneIndexBufferOfs(self.boneBuff[n],
                                                   noesis.RPGEODATA_UBYTE, 4,
                                                   0, 4)
                else:
                    rapi.rpgBindBoneIndexBufferOfs(self.vertBuff[n],
                                                   noesis.RPGEODATA_UBYTE, 64,
                                                   44, 4)
                rapi.rpgBindBoneWeightBufferOfs(self.vertBuff[n],
                                                noesis.RPGEODATA_FLOAT, 64, 28,
                                                4)
                rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT,
                                        numDrawFace * 3, noesis.RPGEO_TRIANGLE,
                                        1)
    def parse_faces(self, numIdx):

        idxBuff = self.inFile.readBytes(numIdx * 2)
        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)

        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                noesis.RPGEO_TRIANGLE, 1)
def noepyLoadModel(data, mdlList):
    '''Build the model, set materials, bones, and animations. You do not
    need all of them as long as they are empty lists (they are by default)'''
    
    ctx = rapi.rpgCreateContext()
    parser = SanaeParser(data)
    parser.parse_file()
    
    #build meshes
    for pose in parser.vertGroups.keys():
        print(pose, len(parser.vertGroups[pose]))
    vertBuffs = parser.vertGroups["walk"]
    for i in range(len(vertBuffs)):
        idxBuff, numIdx, matNum = parser.idxBuffs[i%len(parser.idxBuffs)]
        vertBuff = vertBuffs[i]
        rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 0)
        rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 12)
        rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 24)
        
        matName = parser.matList[matNum].name
        rapi.rpgSetMaterial(matName)
        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)    
    
    mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(parser.texList, parser.matList))
    mdl.setBones(parser.boneList)
    mdl.setAnims(parser.animList)
    mdlList.append(mdl)
    return 1
 def build_mesh(self, meshType):
     
     for i in range(len(self.idxBuffs)):
         idxBuff, numIdx = self.idxBuffs[i]
         
         if meshType == 0:
             rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
 def __init__(self, data):    
     '''Initialize some data. Refer to Sanae.py to see what is already
     initialized'''
     
     self.inFile = NoeBitStream(data, NOE_BIGENDIAN)
     self.animList = []
     self.texList = []
     self.matList = []
     self.boneList = []      
     self.meshList = []
     rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
Beispiel #11
0
    def __init__(self, data):
        '''Initialize some data. Refer to Sanae.py to see what is already
        initialized'''

        self.inFile = NoeBitStream(data, NOE_BIGENDIAN)
        self.animList = []
        self.texList = []
        self.matList = []
        self.boneList = []
        self.meshList = []
        rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
    def __init__(self, data):
        '''Initialize some data. Refer to Sanae.py to see what is already
        initialized'''

        #self.inFile = NoeBitStream(data)
        self.inFile = data
        self.animList = []
        self.texList = []
        self.matList = []
        self.boneList = []
        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
 def __init__(self, data, endian=0):
     
     self.inFile = NoeBitStream(data, endian)
     self.animList = []
     self.texList = []
     self.matList = []
     self.boneList = []
     self.meshList = []
     self.dataOfs = 0 #offset to mesh data        
     if endian:
         rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
 def __init__(self, data):    
     '''Initialize some data. Refer to Sanae.py to see what is already
     initialized'''
     
     #self.inFile = NoeBitStream(data)
     self.inFile = data
     self.animList = []
     self.texList = []
     self.matList = []
     self.boneList = []
     rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
 def parse_static_meshes(self, numMesh):
     
     for i in range(numMesh):
         mesh = self.meshList[i]
         dataSize, structSize = self.inFile.read('2L')
         idxBuff = self.parse_faces(mesh.numIdx)
         vertBuff = self.inFile.readBytes(mesh.numVerts * 12)
         self.inFile.readBytes(mesh.numVerts * 20)
         self.inFile.readBytes(mesh.count3 * 16)
         
         rapi.rpgBindPositionBuffer(vertBuff, noesis.RPGEODATA_FLOAT, 12)
         rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)                    
 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 psaLoadModel(data, mdlList):
	ctx = rapi.rpgCreateContext()
	bs = NoeBitStream(data)
	bs.setEndian(NOE_BIGENDIAN)
	rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
	rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
	IdMagic = bs.readBytes(4).decode("ASCII")
	version = bs.readUInt()
	modelCount = bs.readUInt()
	fvfTableOffset = bs.readUInt()
	bs.seek(fvfTableOffset, NOESEEK_ABS)
	for i in range(0, modelCount):
		bs.seek(fvfTableOffset + (0x80 * i), NOESEEK_ABS)
		bs.seek(0x08, NOESEEK_REL)
		vertexCount = bs.readUShort()
		indexCount = bs.readUShort()
		#print('Index Count: ' + str(indexCount))
		bs.seek(0x04, NOESEEK_REL)
		indexOffset = bs.readUInt()
		#print('Index Offset: ' + str(indexOffset))
		indexSize = bs.readUShort()
		unk01 = bs.readUShort()
		vertexOffset = bs.readUInt()
		unkown01Offset = bs.readUInt()
		vertexSize = bs.readUShort()
		bs.seek(0x5E, NOESEEK_REL)
		bs.seek(indexOffset, NOESEEK_ABS)
		edgeData = bs.readBytes(indexSize)
		edgeDecomp = rapi.decompressEdgeIndices(edgeData, indexCount)
		for i in range(0, indexCount): #decompressEdgeIndices returns indices in little-endian, so swap back to big because rpg is in bigendian mode
			t = edgeDecomp[i*2]
			edgeDecomp[i*2] = edgeDecomp[i*2 + 1]
			edgeDecomp[i*2 + 1] = t
			
		bs.seek(vertexOffset, NOESEEK_ABS)
		vertexSize = 16 * vertexCount
		vertbuff = bs.readBytes(vertexSize)
		rapi.rpgBindPositionBufferOfs(vertbuff, noesis.RPGEODATA_FLOAT, 16, 0)
		#print(outputIndices[len(outputIndices) - 1])
		#print(outputIndices)
		rapi.rpgSetName(str(i))
		#rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, (vertexSize // 16), noesis.RPGEO_POINTS, 1)
		rapi.rpgCommitTriangles(edgeDecomp, noesis.RPGEODATA_USHORT, indexCount, noesis.RPGEO_TRIANGLE, 1)
	mdl = rapi.rpgConstructModel()
	mdlList.append(mdl)
	rapi.rpgClearBufferBinds()	
	return 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)
Beispiel #19
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 parse_skinned_meshes(self, numMesh):
        
        for i in range(numMesh):
            mesh = self.meshList[i]
            
            dataSize, structSize = self.inFile.read('2L')
            idxBuff = self.parse_faces(mesh.numIdx)
            self.parse_unk3(mesh.numVerts)
            vertBuff = self.parse_vertices(mesh.numVerts)
            normBuff = self.parse_unk1(mesh.numVerts)
            self.parse_unk2(mesh.numVerts)

            rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 52, 4)
            #rapi.rpgBindNormalBufferOfs(normBuff, noesis.RPGEODATA_HALFFLOAT, 16, 6)
            #rapi.rpgSetMaterial("mat")
            #rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, mesh.numVerts, noesis.RPGEO_POINTS, 1)        
            rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
            rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, mesh.numIdx, noesis.RPGEO_TRIANGLE, 1)        
Beispiel #21
0
 def Textures(self):
     self.data.seek(4,1)
     numShader = self.data.readUInt()
     for i in range( numShader):
         name    = noeStrFromBytes(self.data.readBytes(self.data.readUInt()))
         numTex  = self.data.readUInt()
         material = NoeMaterial(name, "")
         for n in range( numTex):
             typeName    = noeStrFromBytes(self.data.readBytes(self.data.readUInt()))
             typeID      = self.data.readUInt()
             if typeID ==7: #BaseTexture, Bump
                 if MODPATH == None:texName = noeStrFromBytes(self.data.readBytes(self.data.readUInt())).split('\\')[-1]
                 else: texName = noeStrFromBytes(self.data.readBytes(self.data.readUInt()))
                 if typeName == 'baseTexture':
                     tex = LoadTexture(texName, self)
                     if tex != None: material.setTexture(tex.name)
                 elif typeName == 'bumpTexture':
                     tex = LoadTexture(texName, self)
                     if tex != None: material.setNormalTexture(tex.name)
                     
             elif typeID ==8:
                 self.data.read('2f')
             elif typeID ==9: #Color (specular, ..)
                 temp = self.data.read('3f')
                 if typeName == 'specularColor':
                     material.setSpecularColor((temp[0], temp[1], temp[2], 8.0))
                     
             elif typeID ==10: #Power, Effects, ...
                 self.data.read('f')
         self.matList.append(material)
         
     for draw in self.drawCallInfo:
         idxBuff = self.idxBuffer[ draw['faceStart'] * 6 : ]
         numIdx  = draw['faceCount']
         rapi.rpgSetMaterial(self.matList[draw['matID']].name)
         if len(self.boneList) >0:
                 rapi.rpgSetBoneMap( draw['boneMap'])
                 rapi.rpgBindBoneIndexBufferOfs  (self.vertBuff, noesis.RPGEODATA_UBYTE, self.vertLength, self.boneIndexOffset, 4)
                 rapi.rpgBindBoneWeightBufferOfs (self.vertBuff, noesis.RPGEODATA_FLOAT, self.vertLength, self.boneWeightOffset, 4)
         rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx*3, noesis.RPGEO_TRIANGLE, 1)
         
     return
 def parse_static_mesh(self):
     
     len1, unk1, unk2, unk3 = self.inFile.read('4L')
     name1 = self.read_name(len1)
     numMesh = self.inFile.readUInt()
     
     for i in range(numMesh):
         len2 = self.inFile.readUInt()
         name2 = self.read_name(len2)
         numVerts = self.inFile.readUInt()
         numIdx = self.inFile.readUInt() * 3
         matNum = self.inFile.readUInt()
         self.inFile.seek(51, 1)
         self.parse_vertices(numVerts)
         idxBuff = self.parse_faces(numIdx)
         
         matName = self.matList[matNum].name
         rapi.rpgSetMaterial(matName)
         rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
Beispiel #23
0
    def parse_file(self):
        '''Main parser method'''

        meshName = self.read_name()
        numVerts, numIdx, unk1, unk2, unk3, unk4, unk5, unk6 = self.inFile.read(
            '8L')
        idxBuff = self.parse_faces(numIdx)

        numVerts = self.inFile.readUInt()
        self.parse_vertices(numVerts)
        numNorms = self.inFile.readUInt()
        self.parse_normals(numNorms)
        numUV = self.inFile.readUInt()
        self.parse_uv(numUV)
        numWeights = self.inFile.readUInt()
        self.parse_weights(numWeights)

        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                noesis.RPGEO_TRIANGLE, 1)
Beispiel #24
0
    def parse_matrix(self, options):

        trans = NoeMat43((NoeVec3((1, 0, 0)), NoeVec3(
            (0, 1, 0)), NoeVec3((0, 0, 1)), NoeVec3((0, 0, 0))))

        if 'rotate' in options:
            if options['rotate'] == 'ZY':
                trans = NoeMat43((NoeVec3((1, 0, 0)), NoeVec3(
                    (0, 0, -1)), NoeVec3((0, 1, 0)), NoeVec3((0, 0, 0))))

            elif options['rotate'] == 'YZ':
                trans = NoeMat43((NoeVec3((1, 0, 0)), NoeVec3(
                    (0, 0, 1)), NoeVec3((0, -1, 0)), NoeVec3((0, 0, 0))))

        if 'swap' in options:
            if options['swap'] == 'X':
                self.swapNormals = 1
                rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)

        rapi.rpgSetTransform(trans)
 def parse_file(self):
     '''Main parser method'''
     
     meshName = self.read_name()
     numVerts, numIdx, unk1, unk2, unk3, unk4, unk5, unk6 = self.inFile.read('8L')
     idxBuff = self.parse_faces(numIdx)
     
     numVerts = self.inFile.readUInt()
     self.parse_vertices(numVerts)
     numNorms = self.inFile.readUInt()
     self.parse_normals(numNorms)
     numUV = self.inFile.readUInt()
     self.parse_uv(numUV)
     numWeights = self.inFile.readUInt()
     self.parse_weights(numWeights)
     
     rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
     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)
Beispiel #27
0
    def parse_static_mesh(self):

        len1, unk1, unk2, unk3 = self.inFile.read('4L')
        name1 = self.read_name(len1)
        numMesh = self.inFile.readUInt()

        for i in range(numMesh):
            len2 = self.inFile.readUInt()
            name2 = self.read_name(len2)
            numVerts = self.inFile.readUInt()
            numIdx = self.inFile.readUInt() * 3
            matNum = self.inFile.readUInt()
            self.inFile.seek(51, 1)
            self.parse_vertices(numVerts)
            idxBuff = self.parse_faces(numIdx)

            matName = self.matList[matNum].name
            rapi.rpgSetMaterial(matName)
            rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
            rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                    noesis.RPGEO_TRIANGLE, 1)
 def parse_skinned_mesh(self):
     
     len1, len2, unk1, unk2 = self.inFile.read('4L')
     meshName = self.read_name(len1)
     name = self.read_name(len2)
     
     matNum = self.inFile.readUInt() - 1
     matName = self.read_name(self.inFile.readUInt())
     numVerts = self.inFile.readUInt()
     numIdx = self.inFile.readUInt() * 3
     self.inFile.seek(0xF, 1)
     meshType = self.inFile.readUInt()
     
     self.parse_vertices(numVerts)
     idxBuff = self.parse_faces(numIdx)
     try:
         matName = self.matList[matNum].name
         rapi.rpgSetMaterial(matName)
     except:
         pass
     rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
     rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
 def build_meshes(self):
         
     for i in range(len(self.idxBuffs)):
         idxBuff, numIdx, matNum = self.idxBuffs[i]
         vertBuff, vertType = self.vertBuffs[i]
         if matNum != -1:
             matName = self.matList[matNum].name
             rapi.rpgSetMaterial(matName)
         
         if vertType == 0.125:
             rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, 16, 0)
             rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, 16, 6)
             rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, 16, 12)
             
         elif vertType in [0.0333, 0.0335]:
             rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, 22, 0)
             rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, 22, 6)
             rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_HALFFLOAT, 22, 18)
         
         rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
         
         rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)    
Beispiel #30
0
    def parse_skinned_mesh(self):

        len1, len2, unk1, unk2 = self.inFile.read('4L')
        meshName = self.read_name(len1)
        name = self.read_name(len2)

        matNum = self.inFile.readUInt() - 1
        matName = self.read_name(self.inFile.readUInt())
        numVerts = self.inFile.readUInt()
        numIdx = self.inFile.readUInt() * 3
        self.inFile.seek(0xF, 1)
        meshType = self.inFile.readUInt()

        self.parse_vertices(numVerts)
        idxBuff = self.parse_faces(numIdx)
        try:
            matName = self.matList[matNum].name
            rapi.rpgSetMaterial(matName)
        except:
            pass
        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx,
                                noesis.RPGEO_TRIANGLE, 1)
    def build_meshes(self):

        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
        for i in range(len(self.meshList)):
            mesh = self.meshList[i]
            rapi.rpgSetName(mesh.name)
            if mesh.vertSize == 32:
                rapi.rpgBindPositionBufferOfs(mesh.vertBuff,
                                              noesis.RPGEODATA_FLOAT, 32, 0)
                rapi.rpgBindNormalBufferOfs(mesh.vertBuff,
                                            noesis.RPGEODATA_FLOAT, 32, 12)
                rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT,
                                         32, 24)
            elif mesh.vertSize == 40:
                rapi.rpgBindPositionBufferOfs(mesh.vertBuff,
                                              noesis.RPGEODATA_FLOAT, 40, 0)
                rapi.rpgBindNormalBufferOfs(mesh.vertBuff,
                                            noesis.RPGEODATA_FLOAT, 40, 20)
                rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 40,
                                         32)
            elif mesh.vertSize == 48:
                rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT,
                                              48, 0)
                rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT,
                                            48, 28)
                rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT,
                                         48, 40)

            for sub in mesh.submeshes:
                idxStart = sub.idxOfs
                idxEnd = idxStart + sub.numIdx * 2
                idxBuff = mesh.idxBuff[idxStart:idxEnd]

                rapi.rpgSetMaterial(self.tex)
                rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT,
                                        sub.numIdx, noesis.RPGEO_TRIANGLE, 1)
 def CreateModel(self):
         
     
     for n in range(self.numMesh):
         rapi.rpgBindPositionBufferOfs   (self.vertBuff[n], noesis.RPGEODATA_HALFFLOAT, 64, 0)
         rapi.rpgBindUV1BufferOfs        (self.vertBuff[n], noesis.RPGEODATA_SHORT,     64, 16)
         rapi.rpgBindUV2BufferOfs        (self.vertBuff[n], noesis.RPGEODATA_SHORT,     64, 16)
         
         idxBuffer = self.idxBuff[n][:]
         for i in range(self.numDrawCall[n]):
             numDrawFace = self.drawCallFace[n][i]
             idxBuff = idxBuffer[:numDrawFace*6]
             idxBuffer=idxBuffer[numDrawFace*6:]
             rapi.rpgSetMaterial(self.matList[self.matID[n][i]].name)
             if self.matID[n][i] in self.matEmis:
                 #rapi.rpgSetLightmap(self.matEmis[self.matID[n][i]].name)
                 self.matList[self.matID[n][i]].setNextPass(self.matEmis[self.matID[n][i]])
             rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
             if SKIPTOID:
                 rapi.rpgBindBoneIndexBufferOfs(self.boneBuff[n], noesis.RPGEODATA_UBYTE, 4, 0, 4)
             else:
                 rapi.rpgBindBoneIndexBufferOfs(self.vertBuff[n], noesis.RPGEODATA_UBYTE, 64, 44, 4)
             rapi.rpgBindBoneWeightBufferOfs(self.vertBuff[n], noesis.RPGEODATA_FLOAT, 64, 28, 4)
             rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numDrawFace*3, noesis.RPGEO_TRIANGLE, 1)
def noepyLoadModel(data, mdlList):
	ctx = rapi.rpgCreateContext()
	bs = NoeBitStream(data)
	bs.setEndian(NOE_BIGENDIAN)
	rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
	fvfInto = []
	texList = []
	matList = []

	header = bs.readBytes(4).decode("ASCII")
	version1 = bs.readInt()
	version2 = bs.readInt()
	modelSize = bs.readInt()
	unk01 = bs.readUShort()
	sceneName = bs.readBytes(30).decode("ASCII").rstrip("\0")
	offset00 = bs.readInt()#Bone Matrix / Parent / 0x80
	count00  = bs.readInt()
	offset01 = bs.readInt()#info related to section before last? / 0x40
	count01  = bs.readInt()
	faceInfoOff = bs.readInt()#Face Info /0x40
	faceInfoSize = bs.readInt()
	materialOff = bs.readInt()
	materialCount  = bs.readInt()
	offset04 = bs.readInt()#? / 0x10
	count04  = bs.readInt()
	offset05 = bs.readInt()#Some Matrix / 0x40
	count05  = bs.readInt()
	vertInfoOff = bs.readInt()#Vertex Info / 0x20
	vertInfoSize  = bs.readInt()
	vertOff = bs.readInt()#Vertex Start / 1
	vertOffSize  = bs.readInt()
	texOff = bs.readInt()#Some Names / 0x20
	texCount  = bs.readInt()
	offset09 = bs.readInt()#Some Names / 0x20
	count09  = bs.readInt()
	offset10 = bs.readInt()#Bone Names / 0x20
	count10  = bs.readInt()
	faceOff = bs.readInt()#Some Face Info / 2
	faceOffSize  = bs.readInt()
	offset12 = bs.readInt()#? / 1
	count12  = bs.readInt()
	offset13 = bs.readInt()#? / 1
	count13  = bs.readInt()

	texName = []
	bs.seek(texOff, NOESEEK_ABS)
	for i in range(0, texCount):
		id = bs.readUShort()
		tmp = bs.readBytes(30).decode("ASCII").rstrip("\0")
		texName.append(tmp)

	bs.seek(materialOff, NOESEEK_ABS)
	for i in range(0, materialCount):
		matInfo = bs.read(">" + "h"*32)
		matInfo2 = bs.read(">" + "f"*16)
		material = NoeMaterial((str(i)), "")
		if matInfo[17] != -1:
			material.setTexture(texName[matInfo[17]] + ".dds")
		matList.append(material)
		#print(matInfo)

	faceInfo = []
	bs.seek(faceInfoOff, NOESEEK_ABS)
	for i in range(0, faceInfoSize):
		faceInfoTmp = bs.read(">iiiiiiiiiiiiiiii")
		#print(faceInfoTmp)
		faceInfo.append(faceInfoTmp)
	#for i in range(0, faceInfoSize):
	#	print(faceInfo[i])
	from operator import itemgetter
	faceInfo = sorted(faceInfo, key=itemgetter(2,1))
	#for i in range(0, faceInfoSize):
		#print(faceInfo[i])
	faceInfo2 = []
	for i in range(0, vertInfoSize):
		tmp = []
		for a in range(0, faceInfoSize):
			if faceInfo[a][2] == i:
				tmp.append(faceInfo[a])
		faceInfo2.append(tmp)
	#print(faceInfo2)

	bs.seek(vertInfoOff, NOESEEK_ABS)
	for i in range(0, vertInfoSize):
		meshID = bs.readInt()
		vertCount = bs.readInt()
		fvf00 = bs.readUByte()	
		fvf01 = bs.readUByte()
		fvf02 = bs.readUByte()
		fvf03 = bs.readUByte()
		fvf04 = bs.readUByte()
		fvf05 = bs.readUByte()
		fvf06 = bs.readUByte()
		fvf07 = bs.readUByte()
		vertStart = bs.readInt()
		vertDataSize = bs.readInt()
		vertSize = bs.readInt()
		null = bs.readInt()
		fvfInto.append([meshID,vertCount,vertStart,vertDataSize,vertSize,fvf00,fvf01,fvf02,fvf03,fvf04,fvf05,fvf06,fvf07])
	print(fvfInto)
	for i in range(0, vertInfoSize):
		bs.seek((vertOff + fvfInto[i][2]), NOESEEK_ABS)
		VertBuff = bs.readBytes(fvfInto[i][3])
		rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, fvfInto[i][4], 0)
		if fvfInto[i][8] == 4:
			rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT, fvfInto[i][4], (fvfInto[i][4] - 4))
		if fvfInto[i][8] == 0x44:
			rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT, fvfInto[i][4], (fvfInto[i][4] - 8))
		for a in range(0, len(faceInfo2[i])):
			rapi.rpgSetName(str(faceInfo2[i][a][1]))
			rapi.rpgSetMaterial(str(faceInfo2[i][a][1]))
			bs.seek(faceOff + (2 * faceInfo2[i][a][5]), NOESEEK_ABS)
			FaceBuff = bs.readBytes(faceInfo2[i][a][4] * 2)
			rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, faceInfo2[i][a][4], noesis.RPGEO_TRIANGLE, 1)
			bs.seek(faceOff + (2 * faceInfo2[i][a][7]), NOESEEK_ABS)
			FaceBuff = bs.readBytes(faceInfo2[i][a][6] * 2)
			rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, faceInfo2[i][a][6], noesis.RPGEO_TRIANGLE_STRIP, 1)
			bs.seek(faceOff + (2 * faceInfo2[i][a][9]), NOESEEK_ABS)
			FaceBuff = bs.readBytes(faceInfo2[i][a][8] * 2)
			rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT, faceInfo2[i][a][8], noesis.RPGEO_TRIANGLE_STRIP, 1)

	mdl = rapi.rpgConstructModel()	
	mdl.setModelMaterials(NoeModelMaterials(texList, matList))
	mdlList.append(mdl)
	rapi.rpgClearBufferBinds()	
	return 1
    def parse_faces(self, numIdx):

        idxBuff = self.inFile.readBytes(numIdx * 2)
        rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)

        rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1)
def psaLoadModel(data, mdlList):
	ctx = rapi.rpgCreateContext()
	bs = NoeBitStream(data)
	bs.setEndian(NOE_BIGENDIAN)
	rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
	rapi.rpgSetOption(noesis.RPGOPT_TRIWINDBACKWARD, 1)
	IdMagic = bs.readBytes(4).decode("ASCII")
	version = bs.readUInt()
	modelCount = bs.readUInt()
	fvfTableOffset = bs.readUInt()
	bs.seek(fvfTableOffset, NOESEEK_ABS)
	for i in range(0, modelCount):
		bs.seek(fvfTableOffset + (0x80 * i), NOESEEK_ABS)
		bs.seek(0x08, NOESEEK_REL)
		vertexCount = bs.readUShort()
		indexCount = bs.readUShort()
		#print('Index Count: ' + str(indexCount))
		bs.seek(0x04, NOESEEK_REL)
		indexOffset = bs.readUInt()
		#print('Index Offset: ' + str(indexOffset))
		indexSize = bs.readUShort()
		unk01 = bs.readUShort()
		vertexOffset = bs.readUInt()
		unkown01Offset = bs.readUInt()
		vertexSize = bs.readUShort()
		bs.seek(0x5E, NOESEEK_REL)
		bs.seek(indexOffset, NOESEEK_ABS)
		# read EDGE indices header
		numIndices = bs.readUShort()
		#print('Num Indices: ' + str(numIndices))
		indexBase = bs.readUShort()
		#print('Base Index: ' + str(indexBase))
		sequenceSize = bs.readUShort()
		#print('Sequence Size: ' + str(sequenceSize))
		indexBitSize = bs.readUByte()
		#print('Index Bit Size: ' + str(indexBitSize))
		bs.readUByte() # padding
		# setup sequence bit stream
		sequenceCount = sequenceSize * 8
		#print('Sequence Count: ' + str(sequenceCount))
		sequenceBytes = bs.readBytes(sequenceSize)
		spec = ['data', {"count" : sequenceCount, "spec" : ["value", 1]}]
		reader = BitReader(spec, BitReader.BIG_ENDIAN)
		sequenceStream = reader.read(sequenceBytes)
		# setup triangle bit stream
		triangleCount = indexCount // 3
		#print('Triangle Count: ' + str(triangleCount))
		triangleSize = ((triangleCount * 2) + 7) // 8
		#print('Trangle Size: ' + str(triangleSize))
		triangleBytes = bs.readBytes(triangleSize)
		spec = ['data', {"count" : triangleCount, "spec" : ["value", 2]}]
		reader = BitReader(spec, BitReader.BIG_ENDIAN)
		triangleStream = reader.read(triangleBytes)
		# setup indices bit stream
		indicesSize = ((numIndices * indexBitSize) + 7) // 8
		#print('Indices Size: ' + str(indicesSize))
		#print('Indices Offset: ' + str(bs.getOffset()))
		indicesBytes = bs.readBytes(indicesSize)
		spec = ['data', {"count" : numIndices, "spec" : ["value", indexBitSize]}]
		reader = BitReader(spec, BitReader.BIG_ENDIAN)
		indicesStream = reader.read(indicesBytes)
		# indicesStream = NoeBitStream(indicesBytes)
		# indicesStream.setEndian(NOE_BIGENDIAN)
		# read delta compressed indices
		deltaIndices = array('H')
		for i in range(0, numIndices):
			value = indicesStream.data[i].value
			if i == 1:
				pass
				#print('Index Bit Value: ' + str(value) + ' Index: ' + str(i))
			value -= indexBase
			if i > 7:
				value += deltaIndices[i - 8]
			deltaIndices.append(value)
		# create sequence indices
		inputIndices = array('H')
		sequencedIndex = 0
		unorderedIndex = 0
		for i in range(0, sequenceCount):
			value = sequenceStream.data[i].value
			if value == 0:
				inputIndices.append(sequencedIndex)
				sequencedIndex += 1
			else:
				inputIndices.append(deltaIndices[unorderedIndex])
				unorderedIndex += 1
		# create triangle indices
		outputIndices = array('H')
		currentIndex = 0
		triangleIndices = [0, 0, 0]
		# triangleIndices = {0:0, 1:0, 2:0}
		for i in range(0, triangleCount):
			value = triangleStream.data[i].value
			if value == 0:
				triangleIndices[1] = triangleIndices[2]
				triangleIndices[2] = inputIndices[currentIndex]
				currentIndex += 1
			elif value == 1:
				triangleIndices[0] = triangleIndices[2]
				triangleIndices[2] = inputIndices[currentIndex]
				currentIndex += 1
			elif value == 2:
				tempIndex = triangleIndices[0]
				triangleIndices[0] = triangleIndices[1]
				triangleIndices[1] = tempIndex
				triangleIndices[2] = inputIndices[currentIndex]
				currentIndex += 1
			else: # value == 3:
				triangleIndices[0] = inputIndices[currentIndex]
				currentIndex += 1
				triangleIndices[1] = inputIndices[currentIndex]
				currentIndex += 1
				triangleIndices[2] = inputIndices[currentIndex]
				currentIndex += 1
			outputIndices.append(triangleIndices[0])
			outputIndices.append(triangleIndices[1])
			outputIndices.append(triangleIndices[2])
		bs.seek(vertexOffset, NOESEEK_ABS)
		vertexSize = 16 * vertexCount
		vertbuff = bs.readBytes(vertexSize)
		rapi.rpgBindPositionBufferOfs(vertbuff, noesis.RPGEODATA_FLOAT, 16, 0)
		faceBuff = struct.pack(">" + 'h'*len(outputIndices), *outputIndices)
		#print(outputIndices[len(outputIndices) - 1])
		#print(outputIndices)
		rapi.rpgSetName(str(i))
		#rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, (vertexSize // 16), noesis.RPGEO_POINTS, 1)
		rapi.rpgCommitTriangles(faceBuff, noesis.RPGEODATA_USHORT, len(outputIndices), noesis.RPGEO_TRIANGLE, 1)
	mdl = rapi.rpgConstructModel()
	mdlList.append(mdl)
	rapi.rpgClearBufferBinds()	
	return 1
Beispiel #36
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
Beispiel #37
0
def noepyLoadModel(data, mdlList):
    ctx = rapi.rpgCreateContext()
    bs = NoeBitStream(data)
    bs.setEndian(NOE_BIGENDIAN)
    rapi.rpgSetOption(noesis.RPGOPT_BIGENDIAN, 1)
    fvfInto = []
    texList = []
    matList = []

    header = bs.readBytes(4).decode("ASCII")
    version1 = bs.readInt()
    version2 = bs.readInt()
    modelSize = bs.readInt()
    unk01 = bs.readUShort()
    sceneName = bs.readBytes(30).decode("ASCII").rstrip("\0")
    offset00 = bs.readInt()  #Bone Matrix / Parent / 0x80
    count00 = bs.readInt()
    offset01 = bs.readInt()  #info related to section before last? / 0x40
    count01 = bs.readInt()
    faceInfoOff = bs.readInt()  #Face Info /0x40
    faceInfoSize = bs.readInt()
    materialOff = bs.readInt()
    materialCount = bs.readInt()
    offset04 = bs.readInt()  #? / 0x10
    count04 = bs.readInt()
    offset05 = bs.readInt()  #Some Matrix / 0x40
    count05 = bs.readInt()
    vertInfoOff = bs.readInt()  #Vertex Info / 0x20
    vertInfoSize = bs.readInt()
    vertOff = bs.readInt()  #Vertex Start / 1
    vertOffSize = bs.readInt()
    texOff = bs.readInt()  #Some Names / 0x20
    texCount = bs.readInt()
    offset09 = bs.readInt()  #Some Names / 0x20
    count09 = bs.readInt()
    offset10 = bs.readInt()  #Bone Names / 0x20
    count10 = bs.readInt()
    faceOff = bs.readInt()  #Some Face Info / 2
    faceOffSize = bs.readInt()
    offset12 = bs.readInt()  #? / 1
    count12 = bs.readInt()
    offset13 = bs.readInt()  #? / 1
    count13 = bs.readInt()

    texName = []
    bs.seek(texOff, NOESEEK_ABS)
    for i in range(0, texCount):
        id = bs.readUShort()
        tmp = bs.readBytes(30).decode("ASCII").rstrip("\0")
        texName.append(tmp)

    bs.seek(materialOff, NOESEEK_ABS)
    for i in range(0, materialCount):
        matInfo = bs.read(">" + "h" * 32)
        matInfo2 = bs.read(">" + "f" * 16)
        material = NoeMaterial((str(i)), "")
        if matInfo[17] != -1:
            material.setTexture(texName[matInfo[17]] + ".dds")
        matList.append(material)
        #print(matInfo)

    faceInfo = []
    bs.seek(faceInfoOff, NOESEEK_ABS)
    for i in range(0, faceInfoSize):
        faceInfoTmp = bs.read(">iiiiiiiiiiiiiiii")
        #print(faceInfoTmp)
        faceInfo.append(faceInfoTmp)
    #for i in range(0, faceInfoSize):
    #	print(faceInfo[i])
    from operator import itemgetter
    faceInfo = sorted(faceInfo, key=itemgetter(2, 1))
    #for i in range(0, faceInfoSize):
    #print(faceInfo[i])
    faceInfo2 = []
    for i in range(0, vertInfoSize):
        tmp = []
        for a in range(0, faceInfoSize):
            if faceInfo[a][2] == i:
                tmp.append(faceInfo[a])
        faceInfo2.append(tmp)
    #print(faceInfo2)

    bs.seek(vertInfoOff, NOESEEK_ABS)
    for i in range(0, vertInfoSize):
        meshID = bs.readInt()
        vertCount = bs.readInt()
        fvf00 = bs.readUByte()
        fvf01 = bs.readUByte()
        fvf02 = bs.readUByte()
        fvf03 = bs.readUByte()
        fvf04 = bs.readUByte()
        fvf05 = bs.readUByte()
        fvf06 = bs.readUByte()
        fvf07 = bs.readUByte()
        vertStart = bs.readInt()
        vertDataSize = bs.readInt()
        vertSize = bs.readInt()
        null = bs.readInt()
        fvfInto.append([
            meshID, vertCount, vertStart, vertDataSize, vertSize, fvf00, fvf01,
            fvf02, fvf03, fvf04, fvf05, fvf06, fvf07
        ])
    print(fvfInto)
    for i in range(0, vertInfoSize):
        bs.seek((vertOff + fvfInto[i][2]), NOESEEK_ABS)
        VertBuff = bs.readBytes(fvfInto[i][3])
        rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT,
                                      fvfInto[i][4], 0)
        if fvfInto[i][8] == 4:
            rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT,
                                     fvfInto[i][4], (fvfInto[i][4] - 4))
        if fvfInto[i][8] == 0x44:
            rapi.rpgBindUV1BufferOfs(VertBuff, noesis.RPGEODATA_HALFFLOAT,
                                     fvfInto[i][4], (fvfInto[i][4] - 8))
        for a in range(0, len(faceInfo2[i])):
            rapi.rpgSetName(str(faceInfo2[i][a][1]))
            rapi.rpgSetMaterial(str(faceInfo2[i][a][1]))
            bs.seek(faceOff + (2 * faceInfo2[i][a][5]), NOESEEK_ABS)
            FaceBuff = bs.readBytes(faceInfo2[i][a][4] * 2)
            rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT,
                                    faceInfo2[i][a][4], noesis.RPGEO_TRIANGLE,
                                    1)
            bs.seek(faceOff + (2 * faceInfo2[i][a][7]), NOESEEK_ABS)
            FaceBuff = bs.readBytes(faceInfo2[i][a][6] * 2)
            rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT,
                                    faceInfo2[i][a][6],
                                    noesis.RPGEO_TRIANGLE_STRIP, 1)
            bs.seek(faceOff + (2 * faceInfo2[i][a][9]), NOESEEK_ABS)
            FaceBuff = bs.readBytes(faceInfo2[i][a][8] * 2)
            rapi.rpgCommitTriangles(FaceBuff, noesis.RPGEODATA_USHORT,
                                    faceInfo2[i][a][8],
                                    noesis.RPGEO_TRIANGLE_STRIP, 1)

    mdl = rapi.rpgConstructModel()
    mdl.setModelMaterials(NoeModelMaterials(texList, matList))
    mdlList.append(mdl)
    rapi.rpgClearBufferBinds()
    return 1