Maya FBX导出导入

问题描述:

Maya 导出导入 FBX,设置 FBX 的 导入和导出设置

解决方案:

获取FBX设置

python 复制代码
def getFBXSettings():
    """ get current user settings for FBX export and store them """
    mel.eval('FBXPushSettings;')


def setFBXSettings():
    """ set user-defined FBX settings back after export """
    mel.eval('FBXPopSettings;')

导出 FBX

python 复制代码
def exportFBX(export_file_path, selected=True, **kwargs):
    """

    """
    smoothing_groups = kwargs.get('smoothing_groups', 'true')
    hard_edges = kwargs.get('hard_edges', 'false')
    tangents = kwargs.get('tangents', 'false')
    smooth_mesh = kwargs.get('smooth_mesh', 'true')
    instances = kwargs.get('instances', 'false')
    referenced_assets_content = kwargs.get('referenced_assets_content',
                                           'false')
    animation_only = kwargs.get('animation_only', 'false')
    bake_complex_animation = kwargs.get('bake_complex_animation', 'false')
    bake_complex_step = kwargs.get('bake_complex_step', '1')
    use_scene_name = kwargs.get('use_scene_name', 'false')
    quaternion = kwargs.get('quaternion', 'euler')
    shapes = kwargs.get('shapes', 'false')
    skins = kwargs.get('skins', 'false')
    skeleton = kwargs.get('skeleton', 'false')

    constraints = kwargs.get('constraints', 'false')
    cameras = kwargs.get('cameras', 'false')
    lights = kwargs.get('lights', 'false')
    embed_media = kwargs.get('embed_media', 'false')
    connections = kwargs.get('connections', 'false')
    up_axis = kwargs.get('up_axis', 'y')
    in_ascii = kwargs.get('in_ascii', 'false')

    # store current user FBX settings
    getFBXSettings()

    # export selected as FBX
    # Geometry
    mel.eval("FBXExportSmoothingGroups -v {}".format(smoothing_groups))
    mel.eval("FBXExportHardEdges -v {}".format(hard_edges))
    mel.eval("FBXExportTangents -v {}".format(tangents))
    mel.eval("FBXExportSmoothMesh -v {}".format(smooth_mesh))
    mel.eval("FBXExportInstances -v {}".format(instances))
    mel.eval("FBXExportReferencedAssetsContent -v {}".format(
        referenced_assets_content))
    mel.eval("FBXExportAnimationOnly -v {}".format(animation_only))
    mel.eval(
        "FBXExportBakeComplexAnimation -v {}".format(bake_complex_animation))
    mel.eval("FBXExportBakeComplexStep -v {}".format(bake_complex_step))
    mel.eval("FBXExportUseSceneName -v {}".format(use_scene_name))
    mel.eval("FBXExportQuaternion -v {}".format(quaternion))
    mel.eval("FBXExportShapes -v {}".format(shapes))
    mel.eval("FBXExportSkins -v {}".format(skins))
    mel.eval('FBXExportSkeletonDefinitions -v {}'.format(skeleton))
    # Constraints
    mel.eval("FBXExportConstraints -v {}".format(constraints))
    # Cameras
    mel.eval("FBXExportCameras -v {}".format(cameras))
    # Lights
    mel.eval("FBXExportLights -v {}".format(lights))
    # Embed Media
    mel.eval("FBXExportEmbeddedTextures -v {}".format(embed_media))
    # Connections
    mel.eval("FBXExportInputConnections -v {}".format(connections))
    # Axis Conversion
    mel.eval("FBXExportUpAxis {}".format(up_axis))
    # Version
    # mel.eval("FBXExportFileVersion -v FBX201600")
    mel.eval("FBXExportInAscii -v {}".format(in_ascii))
    try:
        # cmds.file(r'{}'.format(export_file_path), exportSelected=selected,
        #           type="FBX export",
        #           force=True, prompt=False)
        if selected:
            cmds.FBXExport('-file', export_file_path, '-s')
        else:
            cmds.FBXExport('-file', export_file_path)
    except Exception as e:
        print(e)
        print(export_file_path)

    # restore current user FBX settings
    setFBXSettings()

导入FBX

python 复制代码
def import_fbx(fbx_file, **kwargs):
    log = kwargs.get('log', 'false')
    axis_conversion = kwargs.get('axis_conversion', 'true')
    cache_file = kwargs.get('cache_file', 'true')
    import_camera = kwargs.get('import_camera', 'false')
    import_constraints = kwargs.get('import_constraints', 'false')
    convert_joint = kwargs.get('convert_joint', 'true')
    convert_unit = kwargs.get('convert_unit', 'cm')
    fit_timeline = kwargs.get('fit_timeline', 'true')
    force_axis = kwargs.get('force_axis', 'y')
    hard_edge = kwargs.get('hard_edge', 'false')
    import_light = kwargs.get('import_light', 'false')
    merge_pivots = kwargs.get('merge_pivots', 'true')
    merge_ani_layer = kwargs.get('merge_ani_layer', 'true')
    import_mode = kwargs.get('import_mode', 'merge')
    import_driven_key = kwargs.get('import_driven_key', 'false')
    quaternion = kwargs.get('quaternion', 'resample')
    resample_rate = kwargs.get('resample_rate', 'File')
    # scale_factor_enable = kwargs.get('scale_factor_enable', 'false')
    scale_factor = kwargs.get('scale_factor_enable', 1.0)
    frame_rate = kwargs.get('frame_rate', 'true')
    lock_attr = kwargs.get('lock_attr', 'false')
    set_take = kwargs.get('set_take', 0)
    import_shape = kwargs.get('import_shape', 'true')
    skeleton_type = kwargs.get('skeleton_type', 'humanik')
    import_skin = kwargs.get('import_skin', 'true')
    lock_normal = kwargs.get('lock_normal', 'false')
    up_axis = kwargs.get('up_axis', 'y')

    # store current user FBX settings
    getFBXSettings()

    # options
    mel.eval("FBXImportGenerateLog -v {}".format(log))
    mel.eval("FBXImportAxisConversionEnable -v {}".format(axis_conversion))
    mel.eval("FBXImportCacheFile -v {}".format(cache_file))
    mel.eval("FBXImportCameras -v {}".format(import_camera))
    mel.eval("FBXImportConstraints -v {}".format(import_constraints))
    mel.eval("FBXImportConvertDeformingNullsToJoint -v {}".format(convert_joint))
    mel.eval("FBXImportConvertUnitString {}".format(convert_unit))
    mel.eval("FBXImportFillTimeline -v {}".format(fit_timeline))
    mel.eval("FBXImportForcedFileAxis -v {}".format(force_axis))
    mel.eval("FBXImportHardEdges -v {}".format(hard_edge))
    mel.eval("FBXImportLights -v {}".format(import_light))
    mel.eval("FBXImportMergeBackNullPivots -v {}".format(merge_pivots))
    mel.eval("FBXImportMergeAnimationLayers -v {}".format(merge_ani_layer))
    mel.eval("FBXImportMode -v {}".format(import_mode))
    mel.eval("FBXImportProtectDrivenKeys -v {}".format(import_driven_key))
    mel.eval("FBXImportQuaternion -v {}".format(quaternion))
    mel.eval("FBXImportResamplingRateSource -v {}".format(resample_rate))
    # mel.eval("FBXImportScaleFactorEnable {}".format(scale_factor_enable))
    mel.eval("FBXImportScaleFactor {}".format(scale_factor))
    mel.eval("FBXImportSetMayaFrameRate -v {}".format(frame_rate))
    mel.eval("FBXImportSetLockedAttribute -v {}".format(lock_attr))
    mel.eval("FBXImportSetTake -ti {}".format(set_take))
    mel.eval("FBXImportShapes -v {}".format(import_shape))
    # mel.eval("FBXImportSkeletonType -v {}".format(skeleton_type))
    mel.eval("FBXImportSkins -v {}".format(import_skin))
    mel.eval("FBXImportUnlockNormals -v {}".format(lock_normal))
    mel.eval("FBXImportUpAxis {}".format(up_axis))

    try:
        cmds.FBXImport('-file', fbx_file)
    except Exception as e:
        traceback.print_exc()
        print(fbx_file)

    # restore current user FBX settings
    setFBXSettings()
相关推荐
成都渲染101云渲染666618 天前
Autodesk Maya运动设计概述
maya
Maya动画技术18 天前
局部放大maya的视图HUD文字大小的方法
maya·修改视图hud文字大小
成都渲染101云渲染66661 个月前
【无标题】
maya
成都渲染101云渲染66661 个月前
blender云渲染指南2025版
前端·javascript·网络·blender·maya
渲染101专业云渲染2 个月前
川翔云电脑32G大显存集群机器上线!
云计算·电脑·blender·maya·houdini
子燕若水2 个月前
修改maya小部件操作器(manipulator,那个带有箭头和圆环的小部件坐标轴)
maya
子燕若水2 个月前
Maya软件中的约束基础:提高角色动画制作效率的关键技术
maya
子燕若水2 个月前
maya调整全局关节显示大小
maya
渲染101专业云渲染2 个月前
分布式渲染与云渲染:技术与应用的黄金搭档
服务器·分布式·电脑·blender·maya·houdini
渲染101专业云渲染2 个月前
3ds Max 2026 新功能全面解析
3d·云计算·blender·maya·houdini