コード例 #1
0
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
コード例 #2
0
ファイル: xmlToM3.py プロジェクト: FernandoS27/m3addon
def convertFile(inputFilePath, outputDirectory):
    if outputDirectory != None:
        fileName = os.path.basename(inputFilePath)
        outputFilePath = os.path.join(outputDirectory, fileName[:-4])
    else:
        outputFilePath = inputFilePath[:-4]
    print("Converting %s -> %s" % (inputFilePath, outputFilePath))
    doc = xml.dom.minidom.parse(inputFilePath)
    modelElement = doc.firstChild
    structVersion = int(modelElement.getAttribute("structureVersion"))
    structName = modelElement.getAttribute("structureName")
    modelDescription = m3.structures[structName].getVersion(structVersion)
    model = createSingleStructureElement(modelElement, modelDescription)
    m3.saveAndInvalidateModel(model, outputFilePath)
コード例 #3
0
    def assertModelContainsOneDivisionAndMSec(model):
        if len(model.divisions) != 1 or len(model.divisions[0].msec) != 1:
            raise Exception(
                "Model contains %d divisions and the first division has %d msec"
                % (len(model.divisions), len(model.divisions[0].msec)))

    assertModelContainsOneDivisionAndMSec(modelToFix)
    assertModelContainsOneDivisionAndMSec(animIdModel)
    msecToFix = modelToFix.divisions[0].msec[0]
    msecWithAnimId = animIdModel.divisions[0].msec[0]
    oldAnimId = msecToFix.boundingsAnimation.header.animId
    newAnimId = msecWithAnimId.boundingsAnimation.header.animId
    msecToFix.boundingsAnimation.header.animId = newAnimId
    oldAnimIdToNewAnimIdMap[oldAnimId] = newAnimId

    for stc in modelToFix.sequenceTransformationCollections:
        animIds = stc.animIds
        for i in range(len(animIds)):
            newAnimId = oldAnimIdToNewAnimIdMap.get(animIds[i])
            if newAnimId is not None:
                animIds[i] = newAnimId

    for sts in modelToFix.sts:
        animIds = sts.animIds
        for i in range(len(animIds)):
            newAnimId = oldAnimIdToNewAnimIdMap.get(animIds[i])
            if newAnimId is not None:
                animIds[i] = newAnimId

    m3.saveAndInvalidateModel(modelToFix, outputFile)
コード例 #4
0
    animationNameConflicts = m3AnimationNames.intersection(m3aAnimationNames)
    if len(animationNameConflicts) > 0:
        sys.stderr.write("Animation name conflict detected: %s\n" % animationNameConflicts)
        sys.exit(1)

    numberOfSequences = len(m3aModel.sequences)
    if len(m3aModel.sequenceTransformationGroups) != numberOfSequences:
        raise Exception("Script or model incorrect: The model has not the same amounth of stg elements as it has sequences.")
    for sequenceIndex in range(numberOfSequences):
        sequence = m3aModel.sequences[sequenceIndex]
        stg = m3aModel.sequenceTransformationGroups[sequenceIndex]
        newSTCIndices = []
        for oldSTCIndex in stg.stcIndices:
            stc = m3aModel.sequenceTransformationCollections[oldSTCIndex]
            if stc.stsIndex != stc.stsIndexCopy:
                raise Exception("Script or model incorrect: stsIndex != stsIndexCopy.")
            sts = m3aModel.sts[stc.stsIndex]
            stc.stsIndex = len(m3Model.sts)
            stc.stsIndexCopy = stc.stsIndex
            m3Model.sts.append(sts)
            newSTCIndex = len(m3Model.sequenceTransformationCollections)
            m3Model.sequenceTransformationCollections.append(stc)
            newSTCIndices.append(newSTCIndex)
        stg.stcIndices = newSTCIndices
        m3Model.sequences.append(sequence)
        m3Model.sequenceTransformationGroups.append(stg)
    
    
    m3.saveAndInvalidateModel(m3Model, outputFile)

コード例 #5
0
        oldAnimIdToNewAnimIdMap[oldAnimId] = newAnimId

    def assertModelContainsOneDivisionAndMSec(model):
        if len(model.divisions) != 1 or len(model.divisions[0].msec) != 1:
            raise Exception("Model contains %d divisions and the first division has %d msec" % (en(model.divisions), len(model.divisions[0].msec)))

    assertModelContainsOneDivisionAndMSec(modelToFix)
    assertModelContainsOneDivisionAndMSec(animIdModel)
    msecToFix = modelToFix.divisions[0].msec[0]
    msecWithAnimId = animIdModel.divisions[0].msec[0]
    oldAnimId = msecToFix.boundingsAnimation.header.animId
    newAnimId = msecWithAnimId.boundingsAnimation.header.animId
    msecToFix.boundingsAnimation.header.animId = newAnimId
    oldAnimIdToNewAnimIdMap[oldAnimId] = newAnimId

    for stc in modelToFix.sequenceTransformationCollections:
        animIds = stc.animIds
        for i in range(len(animIds)):
            newAnimId = oldAnimIdToNewAnimIdMap.get(animIds[i])
            if newAnimId != None:
                animIds[i] = newAnimId

    for sts in modelToFix.sts:
        animIds = sts.animIds
        for i in range(len(animIds)):
            newAnimId = oldAnimIdToNewAnimIdMap.get(animIds[i])
            if newAnimId != None:
                animIds[i] = newAnimId

    m3.saveAndInvalidateModel(modelToFix, outputFile)
コード例 #6
0
def convert(inputPath, outputPath):
    model = m3.loadModel(inputPath)
    recalculateTangentsOfModel(model)
    m3.saveAndInvalidateModel(model, outputPath)