Skip to content
Snippets Groups Projects
Commit 1bffd880 authored by Julien Duroure's avatar Julien Duroure
Browse files

glTF exporter: fix active scene export + option to use only active scene

parent 2cbb9e2b
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
bl_info = { bl_info = {
'name': 'glTF 2.0 format', 'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (3, 2, 26), "version": (3, 2, 27),
'blender': (3, 1, 0), 'blender': (3, 1, 0),
'location': 'File > Import-Export', 'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0', 'description': 'Import-Export as glTF 2.0',
...@@ -311,6 +311,12 @@ class ExportGLTF2_Base: ...@@ -311,6 +311,12 @@ class ExportGLTF2_Base:
default=False default=False
) )
use_active_scene: BoolProperty(
name='Active Scene',
description='Export active scene only',
default=False
)
export_extras: BoolProperty( export_extras: BoolProperty(
name='Custom Properties', name='Custom Properties',
description='Export custom properties as glTF extras', description='Export custom properties as glTF extras',
...@@ -485,6 +491,7 @@ class ExportGLTF2_Base: ...@@ -485,6 +491,7 @@ class ExportGLTF2_Base:
'use_active_collection', 'use_active_collection',
'use_mesh_edges', 'use_mesh_edges',
'use_mesh_vertices', 'use_mesh_vertices',
'use_active_scene',
] ]
all_props = self.properties all_props = self.properties
export_props = { export_props = {
...@@ -544,6 +551,7 @@ class ExportGLTF2_Base: ...@@ -544,6 +551,7 @@ class ExportGLTF2_Base:
export_settings['gltf_visible'] = self.use_visible export_settings['gltf_visible'] = self.use_visible
export_settings['gltf_renderable'] = self.use_renderable export_settings['gltf_renderable'] = self.use_renderable
export_settings['gltf_active_collection'] = self.use_active_collection export_settings['gltf_active_collection'] = self.use_active_collection
export_settings['gltf_active_scene'] = self.use_active_scene
export_settings['gltf_selected'] = self.use_selection export_settings['gltf_selected'] = self.use_selection
export_settings['gltf_layers'] = True # self.export_layers export_settings['gltf_layers'] = True # self.export_layers
...@@ -682,6 +690,7 @@ class GLTF_PT_export_include(bpy.types.Panel): ...@@ -682,6 +690,7 @@ class GLTF_PT_export_include(bpy.types.Panel):
col.prop(operator, 'use_visible') col.prop(operator, 'use_visible')
col.prop(operator, 'use_renderable') col.prop(operator, 'use_renderable')
col.prop(operator, 'use_active_collection') col.prop(operator, 'use_active_collection')
col.prop(operator, 'use_active_scene')
col = layout.column(heading = "Data", align = True) col = layout.column(heading = "Data", align = True)
col.prop(operator, 'export_extras') col.prop(operator, 'export_extras')
......
...@@ -25,13 +25,14 @@ def gather_gltf2(export_settings): ...@@ -25,13 +25,14 @@ def gather_gltf2(export_settings):
animations = [] # unfortunately animations in gltf2 are just as 'root' as scenes. animations = [] # unfortunately animations in gltf2 are just as 'root' as scenes.
active_scene = None active_scene = None
store_user_scene = bpy.context.scene store_user_scene = bpy.context.scene
for blender_scene in bpy.data.scenes: scenes_to_export = bpy.data.scenes if export_settings['gltf_active_scene'] is False else [scene for scene in bpy.data.scenes if scene.name == store_user_scene.name]
for blender_scene in scenes_to_export:
scenes.append(__gather_scene(blender_scene, export_settings)) scenes.append(__gather_scene(blender_scene, export_settings))
if export_settings[gltf2_blender_export_keys.ANIMATIONS]: if export_settings[gltf2_blender_export_keys.ANIMATIONS]:
# resetting object cache # resetting object cache
gltf2_blender_gather_animation_sampler_keyframes.get_object_matrix.reset_cache() gltf2_blender_gather_animation_sampler_keyframes.get_object_matrix.reset_cache()
animations += __gather_animations(blender_scene, export_settings) animations += __gather_animations(blender_scene, export_settings)
if bpy.context.scene.name == blender_scene.name: if bpy.context.scene.name == store_user_scene.name:
active_scene = len(scenes) -1 active_scene = len(scenes) -1
# restore user scene # restore user scene
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment