Skip to content

Commit

Permalink
Merge pull request #2203 from jessey-git/gltf-collectionexporter
Browse files Browse the repository at this point in the history
Enable the Collection export feature
  • Loading branch information
julienduroure authored Apr 20, 2024
2 parents c8387a6 + 6230e2d commit 1b3fde7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
40 changes: 27 additions & 13 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ class ExportGLTF2_Base(ConvertGLTF2_Base):
default=False
)

collection: StringProperty(
name="Source Collection",
description="Export only objects from this collection (and its children)",
default="",
)

export_extras: BoolProperty(
name='Custom Properties',
description='Export custom properties as glTF extras',
Expand Down Expand Up @@ -968,6 +974,7 @@ def save_settings(self, context):
'use_mesh_edges',
'use_mesh_vertices',
'use_active_scene',
'collection',
]
all_props = self.properties
export_props = {
Expand Down Expand Up @@ -1050,6 +1057,7 @@ def execute(self, context):
else:
export_settings['gltf_active_collection_with_nested'] = False
export_settings['gltf_active_scene'] = self.use_active_scene
export_settings['gltf_collection'] = self.collection

export_settings['gltf_selected'] = self.use_selection
export_settings['gltf_layers'] = True # self.export_layers
Expand Down Expand Up @@ -1203,8 +1211,11 @@ def draw(self, context):
layout.use_property_split = True
layout.use_property_decorate = False # No animation.

export_main(layout, operator)
export_panel_include(layout, operator)
# Are we inside the File browser
is_file_browser = context.space_data.type == 'FILE_BROWSER'

export_main(layout, operator, is_file_browser)
export_panel_include(layout, operator, is_file_browser)
export_panel_transform(layout, operator)
export_panel_data(layout, operator)
export_panel_animation(layout, operator)
Expand All @@ -1214,7 +1225,7 @@ def draw(self, context):
if gltfpack_path != '':
export_panel_gltfpack(layout, operator)

def export_main(layout, operator):
def export_main(layout, operator, is_file_browser):
layout.prop(operator, 'export_format')
if operator.export_format == 'GLTF_SEPARATE':
layout.prop(operator, 'export_keep_originals')
Expand All @@ -1224,21 +1235,23 @@ def export_main(layout, operator):
layout.label(text="This is the least efficient of the available forms, and should only be used when required.", icon='ERROR')

layout.prop(operator, 'export_copyright')
layout.prop(operator, 'will_save_settings')
if is_file_browser:
layout.prop(operator, 'will_save_settings')


def export_panel_include(layout, operator):
def export_panel_include(layout, operator, is_file_browser):
header, body = layout.panel("GLTF_export_include", default_closed=True)
header.label(text="Include")
if body:
col = body.column(heading = "Limit to", align = True)
col.prop(operator, 'use_selection')
col.prop(operator, 'use_visible')
col.prop(operator, 'use_renderable')
col.prop(operator, 'use_active_collection')
if operator.use_active_collection:
col.prop(operator, 'use_active_collection_with_nested')
col.prop(operator, 'use_active_scene')
if is_file_browser:
col = body.column(heading = "Limit to", align = True)
col.prop(operator, 'use_selection')
col.prop(operator, 'use_visible')
col.prop(operator, 'use_renderable')
col.prop(operator, 'use_active_collection')
if operator.use_active_collection:
col.prop(operator, 'use_active_collection_with_nested')
col.prop(operator, 'use_active_scene')

col = body.column(heading = "Data", align = True)
col.prop(operator, 'export_extras')
Expand Down Expand Up @@ -1830,6 +1843,7 @@ class IO_FH_gltf2(bpy.types.FileHandler):
bl_idname = "IO_FH_gltf2"
bl_label = "glTF 2.0"
bl_import_operator = "import_scene.gltf"
bl_export_operator = "export_scene.gltf"
bl_file_extensions = ".glb;.gltf"

@classmethod
Expand Down
21 changes: 15 additions & 6 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,24 @@ def node_filter_inheritable_is_kept(self, uuid):
if all([c.hide_render for c in self.nodes[uuid].blender_object.users_collection]):
return False

if self.export_settings['gltf_active_collection'] and not self.export_settings['gltf_active_collection_with_nested']:
found = any(x == self.nodes[uuid].blender_object for x in bpy.context.collection.objects)
if not found:
# If we are given a collection, use all objects from it
if self.export_settings['gltf_collection']:
local_collection = bpy.data.collections.get((self.export_settings['gltf_collection'], None))
if not local_collection:
return False

if self.export_settings['gltf_active_collection'] and self.export_settings['gltf_active_collection_with_nested']:
found = any(x == self.nodes[uuid].blender_object for x in bpy.context.collection.all_objects)
found = any(x == self.nodes[uuid].blender_object for x in local_collection.all_objects)
if not found:
return False
else:
if self.export_settings['gltf_active_collection'] and not self.export_settings['gltf_active_collection_with_nested']:
found = any(x == self.nodes[uuid].blender_object for x in bpy.context.collection.objects)
if not found:
return False

if self.export_settings['gltf_active_collection'] and self.export_settings['gltf_active_collection_with_nested']:
found = any(x == self.nodes[uuid].blender_object for x in bpy.context.collection.all_objects)
if not found:
return False

if BLENDER_GLTF_SPECIAL_COLLECTION in bpy.data.collections and self.nodes[uuid].blender_object.name in \
bpy.data.collections[BLENDER_GLTF_SPECIAL_COLLECTION].objects:
Expand Down

0 comments on commit 1b3fde7

Please sign in to comment.