def invert_faces(self): '''Negates the x-coord of all vertices in the mesh''' trans = NoeMat43((NoeVec3((-1, 0, 0)), NoeVec3((0, 1, 0)), NoeVec3((0, 0, 1)), NoeVec3((0, 0, 0)))) rapi.rpgSetTransform(trans)
def parse_coords(self, numVerts): coords = self.inFile.readBytes(numVerts * 12) rapi.rpgBindPositionBuffer(coords, noesis.RPGEODATA_FLOAT, 12) 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)
def parse_vertices(self, numVerts): self.vertList = self.inFile.readBytes(numVerts * 48) rapi.rpgBindPositionBufferOfs(self.vertList, noesis.RPGEODATA_FLOAT, 48, 0) rapi.rpgBindNormalBufferOfs(self.vertList, noesis.RPGEODATA_FLOAT, 48, 28) rapi.rpgBindUV1BufferOfs(self.vertList, noesis.RPGEODATA_FLOAT, 48, 40) trans = NoeMat43((NoeVec3((-1.0, 0.0, 0.0)), NoeVec3((0.0, 1.0, 0.0)), NoeVec3((0.0, 0.0, 1.0)), NoeVec3((0.0, 0.0, 0.0)))) rapi.rpgSetTransform(trans)
def parse_coords(self, numVerts): coords = self.inFile.readBytes(numVerts * 12) rapi.rpgBindPositionBuffer(coords, noesis.RPGEODATA_FLOAT, 12) 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)
def build_mesh(self): for mesh in self.meshList: rapi.rpgBindPositionBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 92, 0) rapi.rpgBindNormalBufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 92, 12) rapi.rpgBindUV1BufferOfs(mesh.vertBuff, noesis.RPGEODATA_FLOAT, 92, 28) trans = NoeMat43((NoeVec3((-1, 0, 0)), NoeVec3((0, 1, 0)), NoeVec3((0, 0, 1)), NoeVec3((0, 0, 0)))) rapi.rpgSetTransform(trans) rapi.rpgSetName(mesh.matName) rapi.rpgSetMaterial(mesh.matName) rapi.rpgCommitTriangles(mesh.idxBuff, noesis.RPGEODATA_UINT, mesh.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)
def parse_submesh(self, numSubmesh, matrix): for i in range(numSubmesh): matName = self.read_name() texName = self.read_name() texMask = self.read_name() numVerts, unk1, texSize, unk3, texOff, unk4, unk5 = self.inFile.read('7L') idxBuff = self.parse_vertices(numVerts) self.invert_faces() rapi.rpgSetMaterial(matName) rapi.rpgSetTransform(matrix) rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numVerts*3, noesis.RPGEO_TRIANGLE, 1) material = NoeMaterial(matName, texName) self.matList.append(material) if texName: self.textures.append([texName, texOff, texSize])
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 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, vertType): if vertType == 1: vertBuff = self.inFile.readBytes(numVerts*36) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 12) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 28) elif vertType == 9: vertBuff = self.inFile.readBytes(numVerts*32) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 12) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 24) else: print("unknown vert type: %d" %vertType) #flip y-z axis? trans = NoeMat43((NoeVec3((1, 0, 0)), NoeVec3((0, 0, 1)), NoeVec3((0, -1, 0)), NoeVec3((0, 0, 0)))) rapi.rpgSetTransform(trans)
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_submesh(self, numSubmesh, matrix): for i in range(numSubmesh): matName = self.read_name() texName = self.read_name() texMask = self.read_name() numVerts, unk1, texSize, unk3, texOff, unk4, unk5 = self.inFile.read( '7L') idxBuff = self.parse_vertices(numVerts) self.invert_faces() rapi.rpgSetMaterial(matName) rapi.rpgSetTransform(matrix) rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_UINT, numVerts * 3, noesis.RPGEO_TRIANGLE, 1) material = NoeMaterial(matName, texName) self.matList.append(material) if texName: self.textures.append([texName, texOff, texSize])
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 parse_vertices(self, numVerts, vertType): if vertType == 1: vertBuff = self.inFile.readBytes(numVerts * 36) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 12) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 28) elif vertType == 9: vertBuff = self.inFile.readBytes(numVerts * 32) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 12) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 32, 24) else: print("unknown vert type: %d" % vertType) #flip y-z axis? trans = NoeMat43((NoeVec3((1, 0, 0)), NoeVec3( (0, 0, 1)), NoeVec3((0, -1, 0)), NoeVec3((0, 0, 0)))) rapi.rpgSetTransform(trans)