Exemple #1
0
def fbxExport(objs, start, end, filepath):
    '''
    Convenience function to export fbx animations.
    
    :param node/list objs: An object, or list, to export.  Most likely Rig:b_root.
    :param int start: The beginning of the range to export.
    :param int end: The end of the range to export.
    :param string filepath: The full name to export.
    '''
    assert os.path.exists(
        FBX_ANIM_PRESETS_FILE
    ), 'FBX presets file "%s" does not exist' % FBX_ANIM_PRESETS_FILE

    # Ensure directories exist
    filepath = filepath.replace('\\', '/')
    if not os.path.exists(os.path.dirname(filepath)):
        os.makedirs(os.path.dirname(filepath))

    select(objs)

    mel.FBXPushSettings()
    mel.FBXResetExport()

    # Preset path MUST use forward slashes.
    mel.eval('FBXLoadExportPresetFile -f "{0}"'.format(
        FBX_ANIM_PRESETS_FILE.replace('\\', '/')))
    mel.eval('FBXExportBakeComplexStart -v {0}'.format(start))
    mel.eval('FBXExportBakeComplexEnd -v {0}'.format(end))

    try:
        preFbxExport(objs, start, end, filepath)
        mel.eval('FBXExport -f "%s" -s' % filepath)
        postFbxExport(objs, start, end, filepath)
    finally:
        mel.FBXPopSettings()
Exemple #2
0
def export(filepath, objs, start, end):
    '''
    :param node/list objs: An object, or list, to export.  Most likely Rig:b_root.
    :param int start: The beginning of the range to export.
    :param int end: The end of the range to export.
    :param string filepath: The full name to export.
    '''
    filepath = filepath.replace('\\', '/')
    if not os.path.exists(os.path.dirname(filepath)):
        os.makedirs(os.path.dirname(filepath))

    select(objs)

    mel.FBXPushSettings()
    mel.FBXResetExport()

    if version() >= 2016:
        fbxPreset = os.path.expandvars(
            '%RxArtToolRoot%/Maya/FBXPresets/Motiga_Anim.fbxexportpreset'
        ).replace('\\', '/')
        mel.FBXPushSettings()
        mel.FBXResetExport()

        mel.eval('FBXLoadExportPresetFile -f "{0}"'.format(fbxPreset))
        mel.eval('FBXExportBakeComplexStart -v {0}'.format(start))
        mel.eval('FBXExportBakeComplexEnd -v {0}'.format(end))
    else:

        mel.eval('FBXExportConvertUnitString cm')
        mel.eval('FBXExportAnimationOnly -v 0')
        mel.eval('FBXExportBakeComplexAnimation -v 1')
        mel.eval('FBXExportBakeComplexStep -v 1')
        mel.eval('FBXExportBakeResampleAnimation -v 1')

        mel.eval('FBXExportBakeComplexStart -v {0}'.format(start))
        mel.eval('FBXExportBakeComplexEnd -v {0}'.format(end))
        mel.eval('FBXExportUpAxis z')

        # Turning off input connections prevents the controllers from coming in.
        mel.FBXExportInputConnections(v=0)

    try:
        mel.eval('FBXExport -f "%s" -s' % filepath)
    finally:
        mel.FBXPopSettings()
Exemple #3
0
def fbx_export_settings(reset=False, **kwargs):
    """
    """
    from pymel.core import mel as pymel

    if reset:
        pymel.FBXResetExport()

    fbx_export_cmd_map = {
        "log": pymel.FBXExportGenerateLog,
        "ascii": pymel.FBXExportInAscii,
        "version": pymel.FBXExportFileVersion,

        "cameras": pymel.FBXExportCameras,
        "lights": pymel.FBXExportLights,
        "instances": pymel.FBXExportInstances,
        "referenced": pymel.FBXExportReferencedAssetsContent,

        "smoothing_groups": pymel.FBXExportSmoothingGroups,
        "smooth_mesh": pymel.FBXExportSmoothMesh,
        "tangents": pymel.FBXExportTangents,
        "triangulate": pymel.FBXExportTriangulate,
        "hardEdges": pymel.FBXExportHardEdges,

        "constraints": pymel.FBXExportConstraints,
        "input_conns": pymel.FBXExportInputConnections,

        "shapes": pymel.FBXExportShapes,
        "skins": pymel.FBXExportSkins,
        "skeleton": pymel.FBXExportSkeletonDefinitions,

        "anim_only": pymel.FBXExportAnimationOnly,
        "cache_file": pymel.FBXExportCacheFile,
        "cache_set": pymel.FBXExportQuickSelectSetAsCache,

        "bake_anim": pymel.FBXExportBakeComplexAnimation,
        "bake_start": pymel.FBXExportBakeComplexStart,
        "bake_end": pymel.FBXExportBakeComplexEnd,
        "bake_step": pymel.FBXExportBakeComplexStep,
        "bake_resample_all": pymel.FBXExportBakeResampleAll,

        "key_reduce": pymel.FBXExportApplyConstantKeyReducer,
    }

    for key in kwargs:
        fbx_export_cmd_map[key](v=kwargs[key])
Exemple #4
0
def export_fbx(out_path, selected=True):
    from pymel.core import mel as pymel
    try:
        pymel.FBXExport(f=out_path, s=selected)
    finally:
        pymel.FBXResetExport()