def createChangeLog(self): self.logFile = open(self.logFileName, "w") try: previousModelModiticationTime = os.path.getmtime( self.modelFileName) self.log("Log file started at %s" % time.ctime(previousModelModiticationTime)) previousModel = m3.loadModel(self.modelFileName, checkExpectedValue=False) while True: currentModelModificationTime = os.path.getmtime( self.modelFileName) if currentModelModificationTime > previousModelModiticationTime: self.log("") self.log("File modified at %s" % time.ctime(currentModelModificationTime)) currentModel = m3.loadModel(self.modelFileName) self.changedAnimationIds = 0 self.compareM3Structures(previousModel, currentModel, "model") if self.changedAnimationIds > 0: self.log("%d animation ids have changed!" % self.changedAnimationIds) previousModelModiticationTime = currentModelModificationTime previousModel = currentModel time.sleep(0.1) finally: self.logFile.close()
def processModel(mSrc: str, mDest: Optional[str] = None, outDir: Optional[str] = None, skipExisting: bool = False): if not outDir: outDir = os.path.dirname(mSrc) if not mDest: tmp = os.path.basename(mSrc).split('.') name = ''.join(tmp[:-1]) if len(tmp) > 1 else tmp[0] mDest = os.path.join(outDir, name + '_MD34.m3') print("%s -> %s ... " % (mSrc, mDest), end='') if skipExisting and os.path.isfile(mDest): print("SKIPPED") return try: model = m3.loadModel(mSrc) structureToMD34(model) m3.saveAndInvalidateModel(model, mDest) print("OK") except Exception: print("FAIL") raise
def createChangeLog(self): self.logFile = open(self.logFileName, "w") try: previousModelModiticationTime = os.path.getmtime(self.modelFileName) self.log("Log file started at %s" % time.ctime(previousModelModiticationTime)) previousModel = m3.loadModel(self.modelFileName) while True: currentModelModificationTime = os.path.getmtime(self.modelFileName) if currentModelModificationTime > previousModelModiticationTime: self.log("") self.log("File modified at %s" % time.ctime(currentModelModificationTime)) currentModel = m3.loadModel(self.modelFileName) self.changedAnimationIds = 0 self.compareM3Structures(previousModel, currentModel, "model") if self.changedAnimationIds > 0: self.log("%d animation ids have changed!" % self.changedAnimationIds) previousModelModiticationTime = currentModelModificationTime previousModel = currentModel time.sleep(0.1) finally: self.logFile.close()
def convertFile(inputFilePath, outputFilePath, continueAtErrors): model = None try: model = m3.loadModel(inputFilePath) except Exception as e: if continueAtErrors: sys.stderr.write("\nError: %s\n" % e) sys.stderr.write("\nFile: %s\n" % inputFilePath) sys.stderr.write("Trace: %s\n" % traceback.format_exc()) else: raise e return False printModel(model, outputFilePath) return True
import m3 import argparse if __name__ == "__main__": parser = argparse.ArgumentParser( description= 'Make a model use the same animation ids like another model(works only for bones with the same name yet)' ) parser.add_argument('animIdFile', help="m3 with the wanted animation ids") parser.add_argument('modelToFix', help="m3 which has the wrong animation ids") parser.add_argument('outputFile', help="name of the new m3 file to create") args = parser.parse_args() animIdModel = m3.loadModel(args.animIdFile) modelToFix = m3.loadModel(args.modelToFix) outputFile = args.outputFile boneNameToAnimIdBoneMap = {} for bone in animIdModel.bones: boneNameToAnimIdBoneMap[bone.name] = bone oldAnimIdToNewAnimIdMap = {} for boneToFix in modelToFix.bones: boneWithAnimId = boneNameToAnimIdBoneMap[boneToFix.name] oldAnimId = boneToFix.location.header.animId newAnimId = boneWithAnimId.location.header.animId boneToFix.location.header.animId = newAnimId oldAnimIdToNewAnimIdMap[oldAnimId] = newAnimId
import m3 import sys import argparse if __name__ == "__main__": parser = argparse.ArgumentParser(description='Combines an m3 and m3a file') parser.add_argument('m3File', help="m3 file") parser.add_argument('m3aFile', help="m3a files with extra animations for the m3 file") parser.add_argument('outputFile', help="name of the new m3 file to create") args = parser.parse_args() m3Model = m3.loadModel(args.m3File) m3aModel = m3.loadModel(args.m3aFile) outputFile = args.outputFile sameFormat = True if (len(m3Model.sequences) > 0 and len(m3aModel.sequences) > 0 ): if m3Model.sequences[0].structureDescription != m3aModel.sequences[0].structureDescription: sameFormat = False if (len(m3Model.sequenceTransformationCollections) > 0 and len(m3aModel.sequenceTransformationCollections) > 0 ): if m3Model.sequenceTransformationCollections[0].structureDescription != m3aModel.sequenceTransformationCollections[0].structureDescription: sameFormat = False if (len(m3Model.sequenceTransformationGroups) > 0 and len(m3aModel.sequenceTransformationGroups) > 0 ): if m3Model.sequenceTransformationGroups[0].structureDescription != m3aModel.sequenceTransformationGroups[0].structureDescription: sameFormat = False if (len(m3Model.sts) > 0 and len(m3aModel.sts) > 0 ): if m3Model.sts[0].structureDescription != m3aModel.sts[0].structureDescription:
# ##### END GPL LICENSE BLOCK ##### import m3 import sys import argparse if __name__ == "__main__": parser = argparse.ArgumentParser(description='Make a model use the same animation ids like another model(works only for bones with the same name yet)') parser.add_argument('animIdFile', help="m3 with the wanted animation ids") parser.add_argument('modelToFix', help="m3 which has the wrong animation ids") parser.add_argument('outputFile', help="name of the new m3 file to create") args = parser.parse_args() animIdModel = m3.loadModel(args.animIdFile) modelToFix = m3.loadModel(args.modelToFix) outputFile = args.outputFile boneNameToAnimIdBoneMap = {} for bone in animIdModel.bones: boneNameToAnimIdBoneMap[bone.name] = bone oldAnimIdToNewAnimIdMap = {} for boneToFix in modelToFix.bones: boneWithAnimId = boneNameToAnimIdBoneMap[boneToFix.name] oldAnimId = boneToFix.location.header.animId newAnimId = boneWithAnimId.location.header.animId boneToFix.location.header.animId = newAnimId oldAnimIdToNewAnimIdMap[oldAnimId] = newAnimId
def convert(inputPath, outputPath): model = m3.loadModel(inputPath) recalculateTangentsOfModel(model) m3.saveAndInvalidateModel(model, outputPath)