'''Noesis import plugin. Written by Tsukihime''' from inc_noesis import * import noesis import rapi import os ''' MODE CONFIGURATION 0 = single model 1 = all models ''' MODE = 1 def registerNoesisTypes(): '''Register the plugin. Just change the Game name and extension.''' handle = noesis.register("With Your Destiny", ".msh") noesis.setHandlerTypeCheck(handle, noepyCheckType) noesis.setHandlerLoadModel(handle, noepyLoadModel) return 1 def noepyCheckType(data): '''Verify that the format is supported by this plugin. Default yes''' if len(data) < 4: return 0 bs = NoeBitStream(data) try: idstring = bs.readUInt() if idstring != 0: return 0 return 1 except: return 0 def load_all_models(mdlList): '''Load all models''' #carry over from previous models matList = [] texList = [] dirPath = rapi.getDirForFilePath(rapi.getInputName()) fileList = [file for file in os.listdir(dirPath) if file.lower().endswith(".msh")] for file in fileList: f = open(dirPath + file, 'rb') data2 = f.read() parser = SanaeParser(data2) parser.parse_file() matList.extend(parser.matList) texList.extend(parser.texList) mdl = rapi.rpgConstructModel() mdl.setModelMaterials(NoeModelMaterials(texList, matList)) mdlList.append(mdl) def load_single_model(data, mdlList): '''Loads a single model. For testing purposes''' parser = SanaeParser(data) parser.parse_file() mdl = rapi.rpgConstructModel() mdl.setModelMaterials(NoeModelMaterials(parser.texList, parser.matList)) mdlList.append(mdl) def noepyLoadModel(data, mdlList): '''Load the model''' ctx = rapi.rpgCreateContext() if MODE == 1: load_all_models(mdlList) else: load_single_model(data, mdlList) return 1 class SanaeParser(object): def __init__(self, data): '''Initialize some data. Refer to Sanae.py to see what is already initialized''' self.inFile = NoeBitStream(data) self.animList = [] self.texList = [] self.matList = [] self.boneList = [] def build_mesh(self, idxBuff, numIdx): matName = self.matList[0].name rapi.rpgSetMaterial(matName) rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, numIdx, noesis.RPGEO_TRIANGLE, 1) def parse_vertices(self, numVerts, vertSize): if vertSize == 32: 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) elif vertSize == 36: vertBuff = self.inFile.readBytes(numVerts*36) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 16) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 36, 28) elif vertSize == 40: vertBuff = self.inFile.readBytes(numVerts*40) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 40, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 40, 20) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 40, 32) elif vertSize == 44: vertBuff = self.inFile.readBytes(numVerts*44) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 24) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 44, 36) elif vertSize == 48: vertBuff = self.inFile.readBytes(numVerts*48) rapi.rpgBindPositionBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 48, 0) rapi.rpgBindNormalBufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 48, 28) rapi.rpgBindUV1BufferOfs(vertBuff, noesis.RPGEODATA_FLOAT, 48, 40) else: print("unknown vertsize: ", vertSize) rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, numVerts, noesis.RPGEO_POINTS, 1) def parse_faces(self, numIdx): return self.inFile.readBytes(numIdx * 2) def parse_bones(self, numBones): for i in range(numBones): self.inFile.read('16f') self.inFile.read('%dL' %numBones) def parse_material(self): '''Assume texName is the same as the input name''' matName = rapi.getLocalFileName(rapi.getInputName()).split('.')[0] texName = matName + ".wys" material = NoeMaterial(matName, texName) material.setDefaultBlend(0) self.matList.append(material) def parse_file(self): '''Main parser method''' unk, unk2, unk3, vertSize = self.inFile.read('4L') unk4, numBones, numVerts, numIdx = self.inFile.read('4L') self.parse_bones(numBones) self.parse_vertices(numVerts, vertSize) idxBuff = self.parse_faces(numIdx) self.parse_material() self.build_mesh(idxBuff, numIdx)