Ejemplo n.º 1
0
def export_asset():
    continueDialog = cmds.confirmDialog(title='Make Model FBX',
                                        message='Are you sure your model is ready to be exported?',
                                        button=['Model', 'Character Animation', 'Tile Animation', 'No'], cancelButton='No', defaultButton='No',
                                        dismissString='No')
    if continueDialog == "Model":
        top_node = get_top_node()
        file_dir = os.path.dirname(cmds.file(q=1, sceneName=1))
        export_dir = os.path.join(os.path.dirname(file_dir), "export")

        if not os.path.exists(export_dir):
            os.mkdir(export_dir)

        scene_fbx = os.path.join(export_dir, str(top_node) + ".fbx")

        if cmds.objExists(str(top_node)) == 0:
            cmds.warning(">>>>> Top node named incorrectly or non-existent <<<<<")

        else:
            cmds.select(top_node)
            # Not pretty but there is not exporting allowed in Python...
            preset_file = "{0}{1}{2}".format(os.path.dirname(os.path.realpath(__file__)), os.path.sep,
                                             "UnityExport.fbxexportpreset").replace("\\", "/")
            mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(preset_file))
            mel.eval('FBXExport -f "{0}" -s;'.format(scene_fbx.replace("\\", "/")))
            sys.stdout.write(">>>>> FBX Model Exported! <<<<<")

    if continueDialog == "Character Animation":
        exportAnimFBX.exportAnimFBX()


    if continueDialog == "Tile Animation":
        top_node = get_top_node()
        file_dir = os.path.dirname(cmds.file(q=1, sceneName=1))
        export_dir = os.path.join(os.path.dirname(file_dir), "export")

        if not os.path.exists(export_dir):
            os.mkdir(export_dir)

        scene_fbx = os.path.join(export_dir, str(top_node) + ".fbx")

        if cmds.objExists(str(top_node)) == 0:
            cmds.warning(">>>>> Top node named incorrectly or non-existent <<<<<")

        else:
            cmds.select(top_node)
            cmds.select(hi=True, add=True)
            # Not pretty but there is not exporting allowed in Python...
            preset_file = "{0}{1}{2}".format(os.path.dirname(os.path.realpath(__file__)), os.path.sep,
                                             "UnityModelAnimExport.fbxexportpreset").replace("\\", "/")
            mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(preset_file))
            mel.eval('FBXExport -f "{0}" -s;'.format(scene_fbx.replace("\\", "/")))
            sys.stdout.write(">>>>> FBX Model Exported! <<<<<")
def check_transforms():

    top_node = get_top_node()

    # Our top node is not correct and we can't check the transforms
    # until this is correct`
    if top_node is None:
        return True

    select(top_node)
    select(hi=1)
    select(("*Shape*"), deselect=1)
    objects = ls(sl=1)

    problems = False
    for obj in objects:
        if not (getAttr(obj + '.translateX') == 0 and getAttr(obj + '.translateY') == 0 and getAttr(
                    obj + '.translateZ') == 0 and getAttr(obj + '.rotateX') == 0 and getAttr(
                    obj + '.rotateY') == 0 and getAttr(obj + '.rotateZ') == 0 and getAttr(
                    obj + '.scaleX') == 1 and getAttr(obj + '.scaleX') == 1 and getAttr(obj + '.scaleX') == 1):
            cmds.warning("%s has a none zero transform" % obj)
            problems = True
            return False

    if problems is False:
        return True
Ejemplo n.º 3
0
    def moveToReference(filePath):
        top_node = get_top_node()

        scene_file = top_node
        file_dir = os.path.dirname(cmds.file(q=1, sceneName=1))
        export_dir = os.path.join(os.path.dirname(file_dir), "export")

        if not os.path.exists(export_dir):
            os.mkdir(export_dir)

        try:
            if "export" not in filePath and "scenes" not in filePath:
                print "Folder structure incorrect"
                return False
            filename = top_node

            if top_node is not None:
                filepath = cmds.file(query=True, sceneName=True)
                newFile = os.path.join(export_dir, scene_file + "_REF.ma")
                messageBox("Copying {0} to {1}".format(filename, newFile))
                shutil.copy(filepath, newFile)
                return True
            else:
                messageBox("Naming convention is incorrect for {0}".format(filePath))
                return False
        except IOError:
            messageBox("Unable to copy file {0} to {1}".format(filename, newFile))
            return False
Ejemplo n.º 4
0
def detect_history():

    top_node = get_top_node()
    if top_node is None:
        return True
    # if the top node is not named correctly or non existent we cannot check the history.

    # select the hierarchy
    select(top_node)
    select(hi=1)

    # Deselect the shapes
    select("*Shape*", deselect=1)

    # Some props have been rigged with constraints, we don't want to check the history on them.
    if cmds.objExists("*orientConstraint*") == 1:
        select("*orientConstraint*", deselect=1)

    # Make a list of the selection
    select(top_node, deselect=1)
    objects = cmds.ls(sl=1)

    # Check all elements in the selection for construction history.
    for obj in objects:
        history = cmds.listHistory(obj)
        if len(history) > 1:
            cmds.warning(">> %s has construction history! <<" % obj)
            return False

    return True
Ejemplo n.º 5
0
def check_pivot():
    origin = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

    top_node=get_top_node()

    if xform(top_node,q=1,pivots=1) == origin:
        return True
    else:
        return False
Ejemplo n.º 6
0
def fixAllBelow():
    # Fix face assignment
    hfFixBadShading()
    # delete unused nodes
    mel.deleteUnusedNodes()
    # select top node
    cmds.select(get_top_node())
    # freeze transforms on top node
    mel.FreezeTransformations()
    # set pivot to origin
    mel.xform(zeroTransformPivots=1)
    # select hierarchy and freeze transforms
    cmds.select(hi=1)
    mel.FreezeTransformations()
    # delete history for all
    mel.DeleteHistory()
    # delete all display layers
    deleteDPLayers()
Ejemplo n.º 7
0
 def select_top_node(self):
     cmds.select(get_top_node())