本文主要是介绍Maya FBX导出导入,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题描述:
Maya 导出导入 FBX,设置 FBX 的 导入和导出设置
解决方案:
获取FBX设置
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
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 settingsgetFBXSettings()# export selected as FBX# Geometrymel.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))# Constraintsmel.eval("FBXExportConstraints -v {}".format(constraints))# Camerasmel.eval("FBXExportCameras -v {}".format(cameras))# Lightsmel.eval("FBXExportLights -v {}".format(lights))# Embed Mediamel.eval("FBXExportEmbeddedTextures -v {}".format(embed_media))# Connectionsmel.eval("FBXExportInputConnections -v {}".format(connections))# Axis Conversionmel.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 settingssetFBXSettings()
导入FBX
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 settingsgetFBXSettings()# optionsmel.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 settingssetFBXSettings()
这篇关于Maya FBX导出导入的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!