Skip to content

Commit cb5ed75

Browse files
committed
selection of the animation_mode; automatic name detection for the output file
1 parent 195cf27 commit cb5ed75

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

__init__.py

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
bl_info = {
77
"name": "Better glTF Exporter",
88
"author": "Caio Raphael (inspired by MrTriPie's Super Batch Exporter)",
9-
"version": (1, 0, 2),
9+
"version": (1, 0, 3),
1010
"blender": (4, 1, 0),
1111
"category": "Import-Export",
1212
"location": "Set in preferences below. Default: Top Bar (After File, Edit, ...Help)",
@@ -175,10 +175,15 @@ def draw_settings(self, context):
175175

176176
self.layout.separator()
177177

178-
179178
col = self.layout.column(align=True)
180179
col.label(text="MESH")
181-
col.prop(settings, 'apply_mods')
180+
col.prop(settings, 'apply_modifiers')
181+
182+
self.layout.separator()
183+
184+
col = self.layout.column(align=True)
185+
col.label(text="ANIMATION")
186+
col.prop(settings, 'animation_mode')
182187

183188

184189
self.layout.separator()
@@ -364,6 +369,7 @@ def execute(self, context):
364369
print('Objects to export:', objects_to_export)
365370

366371

372+
367373
self.clear_objects_transform(context, objects_to_export)
368374

369375
try:
@@ -372,10 +378,25 @@ def execute(self, context):
372378

373379
# Processo de exportação.
374380
if settings.export_mode == 'NORMAL_EXPORT':
381+
# Decisão do nome do arquivo de exportação.
382+
file_name = "object"
383+
if settings.limit_active_collection:
384+
file_name = active_collection.name
385+
elif settings.limit_active_scene:
386+
file_name = active_scene.name
387+
else:
388+
solo_object = self.get_solo_object(objects_to_export)
389+
solo_parent = self.get_solo_parent(objects_to_export)
390+
if solo_object:
391+
file_name = solo_object.name
392+
elif solo_parent:
393+
file_name = solo_parent.name
394+
395+
# Export
375396
bpy.ops.object.select_all(action='DESELECT')
376397
for obj in objects_to_export:
377398
obj.select_set(True)
378-
self.export_selection(context, export_config, dir, active_scene.name)
399+
self.export_selection(context, export_config, dir, file_name)
379400
elif settings.export_mode == 'BATCH_EXPORT':
380401
if settings.batch_export_mode == 'OBJECTS':
381402
for obj in objects_to_export:
@@ -439,6 +460,24 @@ def union(self, a, b):
439460
return list(set(a) | set(b))
440461

441462

463+
def get_solo_object(self, objects_to_export) -> object:
464+
if len(objects_to_export) == 1:
465+
return objects_to_export[0]
466+
else:
467+
return None
468+
469+
470+
def get_solo_parent(self, objects_to_export) -> object:
471+
objs_without_parent : list = []
472+
for obj in objects_to_export:
473+
if obj.parent:
474+
continue
475+
objs_without_parent.append(obj)
476+
if len(objs_without_parent) == 1:
477+
return objs_without_parent[0]
478+
else:
479+
return None
480+
442481

443482
def select_children_recursive(self, obj, context):
444483
for c in obj.children:
@@ -495,7 +534,9 @@ def get_config_export(self, context, tex_dir):
495534
'export_scene.gltf', settings.gltf_preset)
496535
else:
497536
export_config["export_texture_dir"] = tex_dir
498-
export_config["export_apply"] = settings.apply_mods
537+
export_config["export_format"] = settings.gltf_format
538+
export_config["export_apply"] = settings.apply_modifiers
539+
export_config["export_animation_mode"] = settings.animation_mode
499540

500541
# Definição forçada do 'Limit To'.
501542
export_config["use_selection"] = True
@@ -505,7 +546,6 @@ def get_config_export(self, context, tex_dir):
505546
export_config["use_active_collection_with_nested"] = False
506547
export_config["use_active_scene"] = False
507548

508-
export_config["export_format"] = settings.gltf_format
509549

510550
return export_config
511551

@@ -555,8 +595,8 @@ class BatchExportSettings(PropertyGroup):
555595
name="Mode",
556596
description="How to export",
557597
items=[
558-
("NORMAL_EXPORT", "Normal Export", "Keep the export into a single file.", 1),
559-
("BATCH_EXPORT", "Batch Export", "Separate the exports into different files.", 2),
598+
("NORMAL_EXPORT", "Normal Export", "Keep the export into a single file", 1),
599+
("BATCH_EXPORT", "Batch Export", "Separate the exports into different files", 2),
560600
],
561601
default="NORMAL_EXPORT",
562602
) # type: ignore
@@ -565,7 +605,7 @@ class BatchExportSettings(PropertyGroup):
565605
# NORMAL EXPORT
566606
name: StringProperty(
567607
name="Name",
568-
description="Name of the file",
608+
description="Name of the file. If left blank, than the name will be automatically decided",
569609
default="",
570610
) # type: ignore
571611

@@ -640,7 +680,7 @@ class BatchExportSettings(PropertyGroup):
640680
description="Format to export",
641681
items=[
642682
("GLTF_SEPARATE", ".glTF", "", 1),
643-
("GLB", ".glb", "Binary file.", 2),
683+
("GLB", ".glb", "Binary file", 2),
644684
],
645685
default="GLTF_SEPARATE",
646686
) # type: ignore
@@ -686,12 +726,21 @@ class BatchExportSettings(PropertyGroup):
686726
) # type: ignore
687727

688728
# Mesh
689-
apply_mods: BoolProperty(
729+
apply_modifiers: BoolProperty(
690730
name="Apply Modifiers",
691-
description="Should the modifiers by applied onto the exported mesh?\nCan't export Shape Keys with this on",
731+
description="Apply the modifiers onto the exported mesh. Can't export Shape Keys with this on",
692732
default=True,
693733
) # type: ignore
694734

735+
animation_mode: EnumProperty(
736+
name="Mode",
737+
description="How to export the animations; they are exported separately",
738+
items=[
739+
("NLA_TRACKS", "Designated Actions by the NLA", "All NLA Tracks from the object that is getting exported", 1),
740+
("ACTIONS", "All Actions", "Loose Actions + Actions inside NLA Editor", 2),
741+
],
742+
default="NLA_TRACKS",
743+
) # type: ignore
695744

696745

697746

1.81 KB
Binary file not shown.

0 commit comments

Comments
 (0)