glTF exporter: Fix #129548 - Regression - Export ShapeKeys when only Armature modifier

Set a custom property (ignore at export) that can identify and differenciate:
- evaluated mesh
- geometry node with SK
This commit is contained in:
Julien Duroure
2024-10-31 13:27:37 +01:00
committed by Philipp Oeser
parent f7bec191d6
commit acc30d6785
5 changed files with 7 additions and 6 deletions
@@ -5,7 +5,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": (4, 2, 70),
"version": (4, 2, 71),
'blender': (4, 2, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
@@ -8,7 +8,7 @@ from .gltf2_blender_json import is_json_convertible
# Custom properties, which are in most cases present and should not be imported/exported.
BLACK_LIST = ['cycles', 'cycles_visibility', 'cycles_curves', 'glTF2ExportSettings']
BLACK_LIST = ['cycles', 'cycles_visibility', 'cycles_curves', 'glTF2ExportSettings', 'gltf2_mesh_applied']
def generate_extras(blender_element):
@@ -107,7 +107,7 @@ def __gather_extras(blender_mesh: bpy.types.Mesh,
extras = generate_extras(blender_mesh) or {}
# Not for GN Instances
if export_settings['gltf_morph'] and blender_mesh.shape_keys and blender_mesh.users != 0:
if export_settings['gltf_morph'] and blender_mesh.shape_keys and ((blender_mesh.is_evaluated is True and blender_mesh.get('gltf2_mesh_applied') is not None) or blender_mesh.is_evaluated is False):
morph_max = len(blender_mesh.shape_keys.key_blocks) - 1
if morph_max > 0:
extras['targetNames'] = [k.name for k in get_sk_exported(blender_mesh.shape_keys.key_blocks)]
@@ -150,7 +150,7 @@ def __gather_weights(blender_mesh: bpy.types.Mesh,
return None
# Not for GN Instances
if blender_mesh.users == 0:
if blender_mesh.is_evaluated is True and blender_mesh.get('gltf2_mesh_applied') is None:
return None
morph_max = len(blender_mesh.shape_keys.key_blocks) - 1
@@ -307,6 +307,8 @@ def __gather_mesh(vnode, blender_object, export_settings):
# But we need to remove some properties that are not needed
for prop in [p for p in blender_object.data.keys() if p in BLACK_LIST]:
del blender_mesh[prop]
# Store that this evaluated mesh has been created by the exporter, and is not a GN instance mesh
blender_mesh['gltf2_mesh_applied'] = True
if export_settings['gltf_skins']:
# restore Armature modifiers
@@ -151,8 +151,7 @@ class PrimitiveCreator:
# We need to check if we are in a GN Instance, because for GN instances, it seems that shape keys are preserved,
# even if we apply modifiers
# (For classic objects, shape keys are not preserved if we apply modifiers)
# We can check it by checking if the mesh is used by a user
if self.blender_mesh.shape_keys and self.export_settings['gltf_morph'] and self.blender_mesh.users != 0:
if self.blender_mesh.shape_keys and self.export_settings['gltf_morph'] and ((self.blender_mesh.is_evaluated is True and self.blender_mesh.get('gltf2_mesh_applied') is not None) or self.blender_mesh.is_evaluated is False):
self.key_blocks = get_sk_exported(self.blender_mesh.shape_keys.key_blocks)
# Fetch vert positions and bone data (joint,weights)