FBX: Enable the Collection exporter feature #105273

Merged
Jesse Yurkovich merged 6 commits from deadpin/blender-addons:fbx-collectionexport into main 2024-04-16 05:13:36 +02:00
2 changed files with 21 additions and 5 deletions
Showing only changes of commit 04729b0a5c - Show all commits

View File

@ -315,6 +315,11 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
description="Export only objects from the active collection (and its children)", description="Export only objects from the active collection (and its children)",
default=False, default=False,
) )
collection: StringProperty(
name="Source Collection",
description="Export only objects from this collection (and its children)",
default="",
)
global_scale: FloatProperty( global_scale: FloatProperty(
name="Scale", name="Scale",
description="Scale all data (Some importers do not support scaled armatures!)", description="Scale all data (Some importers do not support scaled armatures!)",
@ -681,6 +686,7 @@ class IO_FH_fbx(bpy.types.FileHandler):
bl_idname = "IO_FH_fbx" bl_idname = "IO_FH_fbx"
bl_label = "FBX" bl_label = "FBX"
bl_import_operator = "import_scene.fbx" bl_import_operator = "import_scene.fbx"
bl_export_operator = "export_scene.fbx"
bl_file_extensions = ".fbx" bl_file_extensions = ".fbx"
@classmethod @classmethod

View File

@ -3586,6 +3586,7 @@ def save(operator, context,
use_selection=False, use_selection=False,
use_visible=False, use_visible=False,
use_active_collection=False, use_active_collection=False,
collection="",
batch_mode='OFF', batch_mode='OFF',
use_batch_own_dir=False, use_batch_own_dir=False,
**kwargs **kwargs
@ -3606,13 +3607,22 @@ def save(operator, context,
if batch_mode == 'OFF': if batch_mode == 'OFF':
kwargs_mod = kwargs.copy() kwargs_mod = kwargs.copy()
source_collection = None
if use_active_collection: if use_active_collection:
if use_selection: source_collection = context.view_layer.active_layer_collection.collection
ctx_objects = tuple(obj elif collection:
for obj in context.view_layer.active_layer_collection.collection.all_objects if collection in bpy.data.collections:
if obj.select_get()) source_collection = bpy.data.collections[collection]
else: else:
ctx_objects = context.view_layer.active_layer_collection.collection.all_objects operator.report({'ERROR'}, "Collection %s was not found" % collection)
return {'CANCELLED'}
if source_collection:
if use_selection:
ctx_objects = tuple(obj for obj in source_collection.all_objects if obj.select_get())
else:
ctx_objects = source_collection.all_objects
else: else:
if use_selection: if use_selection:
ctx_objects = context.selected_objects ctx_objects = context.selected_objects