From 22aa2fbfa8ce931fb392471acbc4a44f2d5a1aae Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Wed, 26 Feb 2025 16:40:37 +0100 Subject: [PATCH] Fix #135129 glTF Collection Exporter: Avoid to export multiple scene info when Collection Export --- .../addons_core/io_scene_gltf2/__init__.py | 2 +- .../io_scene_gltf2/blender/exp/gather.py | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/addons_core/io_scene_gltf2/__init__.py b/scripts/addons_core/io_scene_gltf2/__init__.py index 12779ddb2a7..31e971bbecd 100755 --- a/scripts/addons_core/io_scene_gltf2/__init__.py +++ b/scripts/addons_core/io_scene_gltf2/__init__.py @@ -5,7 +5,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (4, 4, 49), + "version": (4, 4, 50), 'blender': (4, 4, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/scripts/addons_core/io_scene_gltf2/blender/exp/gather.py b/scripts/addons_core/io_scene_gltf2/blender/exp/gather.py index 47a916e92ce..e486743b149 100644 --- a/scripts/addons_core/io_scene_gltf2/blender/exp/gather.py +++ b/scripts/addons_core/io_scene_gltf2/blender/exp/gather.py @@ -25,8 +25,21 @@ def gather_gltf2(export_settings): animations = [] # unfortunately animations in gltf2 are just as 'root' as scenes. active_scene = None store_user_scene = bpy.context.scene - scenes_to_export = bpy.data.scenes if export_settings['gltf_active_scene'] is False else [ + if export_settings['gltf_collection'] is None and export_settings['gltf_active_scene'] is False: + # If no collection export and no active scene export, we need to export all scenes + scenes_to_export = bpy.data.scenes + elif export_settings['gltf_collection'] is None and export_settings['gltf_active_scene'] is True: + # If no collection export and active scene export, we need to export only the active scene + scenes_to_export = [ scene for scene in bpy.data.scenes if scene.name == store_user_scene.name] + elif export_settings['gltf_collection'] is not None: + # If collection export, we need to export only the collection, so keeping only the active scene + scenes_to_export = [ + scene for scene in bpy.data.scenes if scene.name == store_user_scene.name] + else: + # This should never happen + raise Exception("Unknown export settings") + for blender_scene in scenes_to_export: scenes.append(__gather_scene(blender_scene, export_settings)) if export_settings['gltf_animations']: @@ -46,7 +59,7 @@ def __gather_scene(blender_scene, export_settings): scene = gltf2_io.Scene( extensions=None, extras=__gather_extras(blender_scene, export_settings), - name=blender_scene.name, + name=__gather_name(blender_scene, export_settings), nodes=[] ) @@ -135,3 +148,8 @@ def __gather_extras(blender_object, export_settings): return generate_extras(bpy.data.collections[export_settings['gltf_collection']]) return generate_extras(blender_object) return None + +def __gather_name(blender_scene, export_settings): + if export_settings['gltf_collection']: + return export_settings['gltf_collection'] + return blender_scene.name