From 5a557e72fc1e63802837b385a303b5dd6e44f284 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Sun, 13 Mar 2022 11:25:33 +0100 Subject: glTF exporter: export armature without skined mesh as skin in glTF files At import, this will be defined as armature/joints instead of empties --- io_scene_gltf2/__init__.py | 2 +- io_scene_gltf2/blender/exp/gltf2_blender_export.py | 3 +++ io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py | 9 +++++++++ io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 7c39ac3f..a9bf80b5 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -4,7 +4,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": (3, 2, 10), + "version": (3, 2, 11), 'blender': (3, 1, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_export.py b/io_scene_gltf2/blender/exp/gltf2_blender_export.py index ddcad91d..539c6b74 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_export.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_export.py @@ -65,6 +65,8 @@ def __export(export_settings): def __gather_gltf(exporter, export_settings): active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings) + unused_skins = export_settings['vtree'].get_unused_skins() + if export_settings['gltf_draco_mesh_compression']: gltf2_io_draco_compression_extension.encode_scene_primitives(scenes, export_settings) exporter.add_draco_extension() @@ -75,6 +77,7 @@ def __gather_gltf(exporter, export_settings): exporter.add_scene(scene, idx==active_scene_idx) for animation in animations: exporter.add_animation(animation) + exporter.traverse_unused_skins(unused_skins) def __create_buffer(exporter, export_settings): diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py index d3edd50a..549c4ed0 100644 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py @@ -372,3 +372,12 @@ class VExportTree: if len(candidates) > 0: n.armature = candidates[0].uuid del n.armature_needed + + def get_unused_skins(self): + from .gltf2_blender_gather_skins import gather_skin + skins = [] + for n in [n for n in self.nodes.values() if n.blender_type == VExportNode.ARMATURE]: + if len([m for m in self.nodes.values() if m.keep_tag is True and m.blender_type == VExportNode.OBJECT and m.armature == n.uuid]) == 0: + skin = gather_skin(n.uuid, self.export_settings) + skins.append(skin) + return skins diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py b/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py index 9761e81c..574693d7 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py @@ -174,6 +174,10 @@ class GlTF2Exporter: if active: self.__gltf.scene = scene_num + def traverse_unused_skins(self, skins): + for s in skins: + self.__traverse(s) + def add_animation(self, animation: gltf2_io.Animation): """ Add an animation to the glTF. -- cgit v1.2.3