Skip to content

Commit 8c6a969

Browse files
committed
safer undo_transforms; UI improvements.
1 parent a32cbab commit 8c6a969

File tree

2 files changed

+63
-61
lines changed

2 files changed

+63
-61
lines changed

__init__.py

Lines changed: 63 additions & 61 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, 1),
9+
"version": (1, 0, 2),
1010
"blender": (4, 1, 0),
1111
"category": "Import-Export",
1212
"location": "Set in preferences below. Default: Top Bar (After File, Edit, ...Help)",
@@ -154,11 +154,12 @@ def draw_settings(self, context):
154154

155155
self.layout.separator()
156156

157-
col = self.layout.column(align=True)
158-
col.label(text="TEXTURE")
159-
col.prop(settings, 'texture_directory')
157+
if settings.gltf_format == 'GLTF_SEPARATE':
158+
col = self.layout.column(align=True)
159+
col.label(text="TEXTURE")
160+
col.prop(settings, 'texture_directory')
160161

161-
self.layout.separator()
162+
self.layout.separator()
162163

163164

164165
col = self.layout.column(align=True)
@@ -281,12 +282,14 @@ class EXPORT_MESH_OT_batch(Operator):
281282
old_locations = []
282283
old_rotations = []
283284
old_scales = []
285+
objects_to_undo = []
286+
284287
file_count = 0
285288

286289
def execute(self, context):
287290
settings = context.scene.batch_export
288291

289-
print('\n\nStart:\n')
292+
print('\n\n\n\n ============================= STARTING =============================\n')
290293

291294
# Verificação das texturas.
292295
dir = settings.directory
@@ -358,76 +361,73 @@ def execute(self, context):
358361
objects_to_export = self.intersection(objects_to_export, active_scene.objects)
359362
objects_to_export = self.intersection(objects_to_export, objects_by_type)
360363

361-
362364
print('Objects to export:', objects_to_export)
363365

364-
# Chamada da exportação Normal ou Batch.
365-
export_config = self.get_config_export(context, tex_dir)
366366

367367
self.clear_objects_transform(context, objects_to_export)
368368

369+
try:
370+
# Get export configurations, based on the user choices.
371+
export_config = self.get_config_export(context, tex_dir)
369372

370-
if settings.export_mode == 'NORMAL_EXPORT':
371-
bpy.ops.object.select_all(action='DESELECT')
372-
for obj in objects_to_export:
373-
obj.select_set(True)
374-
self.export_selection(context, export_config, dir, active_scene.name)
375-
elif settings.export_mode == 'BATCH_EXPORT':
376-
if settings.batch_export_mode == 'OBJECTS':
377-
for obj in objects_to_export:
378-
bpy.ops.object.select_all(action='DESELECT')
379-
obj.select_set(True)
380-
self.export_selection(context, export_config, dir, obj.name)
381-
elif settings.batch_export_mode == 'PARENTS':
373+
# Processo de exportação.
374+
if settings.export_mode == 'NORMAL_EXPORT':
375+
bpy.ops.object.select_all(action='DESELECT')
382376
for obj in objects_to_export:
383-
# Apenas itere pelos pais ignorando os filhos, uma vez que eles serão exportados junto com seu respectivo pai.
384-
if obj.parent:
385-
continue
386-
bpy.ops.object.select_all(action='DESELECT')
387377
obj.select_set(True)
388-
self.select_children_recursive(obj, context)
389-
self.export_selection(context, export_config, dir, obj.name)
390-
elif settings.batch_export_mode == 'COLLECTIONS':
391-
unique_collections = []
392-
for obj in objects_to_export:
393-
if not obj.users_collection in unique_collections:
394-
unique_collections.append(obj.users_collection[0])
395-
for col in unique_collections:
396-
bpy.ops.object.select_all(action='DESELECT')
397-
for obj in col.objects:
378+
self.export_selection(context, export_config, dir, active_scene.name)
379+
elif settings.export_mode == 'BATCH_EXPORT':
380+
if settings.batch_export_mode == 'OBJECTS':
381+
for obj in objects_to_export:
382+
bpy.ops.object.select_all(action='DESELECT')
383+
obj.select_set(True)
384+
self.export_selection(context, export_config, dir, obj.name)
385+
elif settings.batch_export_mode == 'PARENTS':
386+
for obj in objects_to_export:
387+
# Apenas itere pelos pais ignorando os filhos, uma vez que eles serão exportados junto com seu respectivo pai.
388+
if obj.parent:
389+
continue
390+
bpy.ops.object.select_all(action='DESELECT')
398391
obj.select_set(True)
399-
self.export_selection(context, export_config, dir, col.name)
392+
self.select_children_recursive(obj, context)
393+
self.export_selection(context, export_config, dir, obj.name)
394+
elif settings.batch_export_mode == 'COLLECTIONS':
395+
unique_collections = []
396+
for obj in objects_to_export:
397+
if not obj.users_collection in unique_collections:
398+
unique_collections.append(obj.users_collection[0])
399+
for col in unique_collections:
400+
bpy.ops.object.select_all(action='DESELECT')
401+
for obj in col.objects:
402+
obj.select_set(True)
403+
self.export_selection(context, export_config, dir, col.name)
404+
405+
# Verifica se nada foi exportado, ou quantos arquivos foram exportados.
406+
self.file_count = len(objects_to_export)
407+
if self.file_count == 0:
408+
self.report({'ERROR'}, "NOTHING TO EXPORT")
409+
elif settings.export_mode == 'NORMAL_EXPORT':
410+
self.report({'INFO'}, f"Exported 1 file [ {str(self.file_count)} object(s) ]")
411+
elif settings.export_mode == 'BATCH_EXPORT':
412+
self.report({'INFO'}, f"Exported {str(self.file_count)} file(s)")
400413

414+
except (NameError, IndexError):
415+
self.report({'INFO'}, "EXPORT ERROR")
401416

402-
self.undo_objects_transform(context, objects_to_export)
403417

418+
# Return transform to how it was.
419+
self.undo_objects_transform(context)
404420

405421
# Return selection to how it was.
406422
bpy.ops.object.select_all(action='DESELECT')
407423
for obj in selected:
408424
obj.select_set(True)
409425
context.view_layer.objects.active = active_object
410426

411-
# Return to whatever mode the user was in
427+
# Return to whatever mode the user was in.
412428
if active_object:
413429
bpy.ops.object.mode_set(mode=tab_mode)
414430

415-
self.file_count = len(objects_to_export)
416-
417-
# Verifica se nada foi exportado, ou quantos arquivos foram exportados.
418-
if settings.export_mode == 'NORMAL_EXPORT':
419-
if self.file_count == 0:
420-
self.report({'ERROR'}, "NOTHING TO EXPORT")
421-
else:
422-
self.report({'INFO'}, "Exported 1 file [" +
423-
str(self.file_count) + " object(s)]")
424-
elif settings.export_mode == 'BATCH_EXPORT':
425-
if self.file_count == 0:
426-
self.report({'ERROR'}, "NOTHING TO EXPORT")
427-
else:
428-
self.report({'INFO'}, "Exported " +
429-
str(self.file_count) + " file(s)")
430-
431431
return {'FINISHED'}
432432

433433

@@ -452,10 +452,16 @@ def clear_objects_transform(self, context, objects_to_export):
452452
self.old_locations = []
453453
self.old_rotations = []
454454
self.old_scales = []
455+
456+
self.objects_to_undo = []
457+
455458
for obj in objects_to_export:
456459
# Apenas itere pelos pais ignorando os filhos.
457460
if obj.parent:
458461
continue
462+
463+
self.objects_to_undo.append(obj)
464+
459465
if settings.clear_location:
460466
self.old_locations.append(obj.location.copy())
461467
obj.location = (0.0, 0.0, 0.0)
@@ -465,17 +471,13 @@ def clear_objects_transform(self, context, objects_to_export):
465471
if settings.clear_scale:
466472
self.old_scales.append(obj.scale.copy())
467473
obj.scale = (0.0, 0.0, 0.0)
468-
469-
# If exporting by parent, don't set child (object that has a parent) transform.
470-
#if settings.export_mode != "OBJECT_PARENTS" or not obj.parent:
474+
471475

472476

473-
def undo_objects_transform(self, context, objects_to_export):
477+
def undo_objects_transform(self, context):
474478
settings = context.scene.batch_export
475479

476-
for i, obj in enumerate(objects_to_export):
477-
if obj.parent:
478-
continue
480+
for i, obj in enumerate(self.objects_to_undo):
479481
if settings.clear_location:
480482
obj.location = self.old_locations[i]
481483
if settings.clear_rotation:
283 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)