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

At import, this will be defined as armature/joints instead of empties
This commit is contained in:
Julien Duroure 2022-03-13 11:25:33 +01:00
parent 5838e26036
commit 5a557e72fc
4 changed files with 17 additions and 1 deletions

View File

@ -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',

View File

@ -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):

View File

@ -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

View File

@ -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.