Added binary exporter

This commit is contained in:
raccoon
2025-01-28 06:37:44 +05:00
parent 27c93c3e29
commit 0f37a5a02c

View File

@@ -3,8 +3,8 @@ from datetime import datetime
import bpy import bpy
_FUTURE = bpy.app.version >= (2, 80, 0) _FUTURE = bpy.app.version >= (2, 80, 0)
from bpy.props import EnumProperty, StringProperty, BoolProperty, PointerProperty, IntProperty from bpy.props import EnumProperty, StringProperty, BoolProperty, IntProperty
from bpy.types import UIList, Operator, Panel, PropertyGroup, Context, Scene from bpy.types import UIList, Operator, Panel, Context, Scene
if _FUTURE: if _FUTURE:
from bpy.types import Collection as Group from bpy.types import Collection as Group
else: else:
@@ -40,25 +40,9 @@ def fbx_export(context: Context) -> None:
""" """
print("[%s] Batch FBX export begin" % datetime.now()) print("[%s] Batch FBX export begin" % datetime.now())
rootpath = os.path.normpath(bpy.path.abspath(context.scene.fbx_export_dir)) def exporter_ascii(context: Context, filepath: str):
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
}
)
bpy.ops.export_scene.fbx( bpy.ops.export_scene.fbx(
override, context,
version='ASCII6100', version='ASCII6100',
use_selection=True, use_selection=True,
global_scale=1.0, global_scale=1.0,
@@ -82,6 +66,66 @@ def fbx_export(context: Context) -> None:
filepath=filepath, 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()) print("\n[%s] Batch FBX export end." % datetime.now())
@@ -120,12 +164,6 @@ class SCENE_PT_fbx_autoexport(Panel):
col = layout.column() 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() split = col.split()
sub = split.column() sub = split.column()
sub.label(text="Filter groups:") sub.label(text="Filter groups:")
@@ -136,7 +174,13 @@ class SCENE_PT_fbx_autoexport(Panel):
col.separator() 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.prop(scene, "fbx_export_dir")
col.operator(FBX_OT_ManualExport.bl_idname)
def on_save(*args, **kwargs) -> None: 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)"), ('OTHER', "Other", "Other geometry types, like curve, metaball, etc. (converted to meshes)"),
), ),
description="Which kind of object to export", 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_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( Group.fbx_exportable = BoolProperty(
name="Export Group", name="Export Group",
description="Mark group as FBX exportable", description="Mark group as FBX exportable",