diff --git a/Assets/avatar-example/mesh/blend~/fbx_export.py b/Assets/avatar-example/mesh/blend~/fbx_export.py index a22aed4..cb73c85 100644 --- a/Assets/avatar-example/mesh/blend~/fbx_export.py +++ b/Assets/avatar-example/mesh/blend~/fbx_export.py @@ -3,8 +3,8 @@ from datetime import datetime import bpy _FUTURE = bpy.app.version >= (2, 80, 0) -from bpy.props import EnumProperty, StringProperty, BoolProperty, PointerProperty, IntProperty -from bpy.types import UIList, Operator, Panel, PropertyGroup, Context, Scene +from bpy.props import EnumProperty, StringProperty, BoolProperty, IntProperty +from bpy.types import UIList, Operator, Panel, Context, Scene if _FUTURE: from bpy.types import Collection as Group else: @@ -40,25 +40,9 @@ def fbx_export(context: Context) -> None: """ print("[%s] Batch FBX export begin" % datetime.now()) - rootpath = os.path.normpath(bpy.path.abspath(context.scene.fbx_export_dir)) - groups = bpy.data.collections if _FUTURE else bpy.data.groups - - for group in [g for g in groups if g.fbx_exportable]: - filepath = os.path.join(rootpath, name_as_path(group.name)) - basepath = os.path.dirname(filepath) - - if not os.path.exists(basepath): - os.makedirs(basepath) - - override = context.copy() - override.update( - { - "selected_objects": group.objects - } - ) - + def exporter_ascii(context: Context, filepath: str): bpy.ops.export_scene.fbx( - override, + context, version='ASCII6100', use_selection=True, global_scale=1.0, @@ -82,6 +66,66 @@ def fbx_export(context: Context) -> None: filepath=filepath, ) + def exporter_binary(context: Context, filepath: str): + bpy.ops.export_scene.fbx( + context, + # Common + version = 'BIN7400', + axis_forward = '-Z', + axis_up = 'Y', + apply_scale_options = 'FBX_SCALE_ALL', + apply_unit_scale = True, + bake_space_transform = True, + global_scale = 1.0, + object_types = context.scene.fbx_object_types, + use_custom_props = False, + use_selection = True, + # Mesh + mesh_smooth_type = 'FACE', + use_mesh_modifiers = False, + use_mesh_edges = False, + use_tspace = False, + # Armature + add_leaf_bones = False, + primary_bone_axis = 'Y', + secondary_bone_axis = 'X', + use_armature_deform_only = False, + armature_nodetype = 'NULL', + # Animation + bake_anim = False, + bake_anim_use_all_bones = True, + bake_anim_use_all_actions = True, + bake_anim_use_nla_strips = True, + bake_anim_force_startend_keying = True, + bake_anim_step = 1.0, + bake_anim_simplify_factor = 1.0, + # File + filepath=filepath, + path_mode = 'RELATIVE', + embed_textures = False, + batch_mode = 'OFF', + ) + + exporter = exporter_binary if _FUTURE else exporter_ascii + rootpath = os.path.normpath(bpy.path.abspath(context.scene.fbx_export_dir)) + groups = bpy.data.collections if _FUTURE else bpy.data.groups + override = context.copy() + + for group in [g for g in groups if g.fbx_exportable]: + filepath = os.path.join(rootpath, name_as_path(group.name)) + basepath = os.path.dirname(filepath) + + if not os.path.exists(basepath): + os.makedirs(basepath) + + override.update( + { + "selected_objects": group.objects + } + ) + + exporter(override, filepath) + print("\n[%s] Batch FBX export end." % datetime.now()) @@ -120,12 +164,6 @@ class SCENE_PT_fbx_autoexport(Panel): col = layout.column() - sub = col.column(align=True) - sub.prop(scene, "fbx_on_save", icon='FILE_REFRESH') - sub.operator(FBX_OT_ManualExport.bl_idname, icon="PASTEDOWN") - - col.separator() - split = col.split() sub = split.column() sub.label(text="Filter groups:") @@ -136,7 +174,13 @@ class SCENE_PT_fbx_autoexport(Panel): col.separator() + sub = col.row() + sub.alignment = 'CENTER' + sub.prop(scene, "fbx_on_save") + sub.prop(scene, "fbx_force_binary") + col.prop(scene, "fbx_export_dir") + col.operator(FBX_OT_ManualExport.bl_idname) def on_save(*args, **kwargs) -> None: @@ -185,9 +229,14 @@ def register() -> None: ('OTHER', "Other", "Other geometry types, like curve, metaball, etc. (converted to meshes)"), ), description="Which kind of object to export", - default={'EMPTY', 'CAMERA', 'LAMP', 'ARMATURE', 'MESH', 'OTHER'}, + default={'ARMATURE', 'EMPTY', 'MESH', 'OTHER'}, ) Scene.fbx_group_index = IntProperty(default=0) + Scene.fbx_force_binary = BoolProperty( + name="Binary format", + description="Force export FBX file as binary", + default=False + ) Group.fbx_exportable = BoolProperty( name="Export Group", description="Mark group as FBX exportable",