[Bf-extensions-cvs] [5a557e72] master: glTF exporter: export armature without skined mesh as skin in glTF files

Julien Duroure noreply at git.blender.org
Sun Mar 13 11:26:33 CET 2022


Commit: 5a557e72fc1e63802837b385a303b5dd6e44f284
Author: Julien Duroure
Date:   Sun Mar 13 11:25:33 2022 +0100
Branches: master
https://developer.blender.org/rBA5a557e72fc1e63802837b385a303b5dd6e44f284

glTF exporter: export armature without skined mesh as skin in glTF files

At import, this will be defined as armature/joints instead of empties

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/exp/gltf2_blender_export.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py

===================================================================

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.



More information about the Bf-extensions-cvs mailing list