Skip to content

Commit

Permalink
Merge pull request #1963 from KhronosGroup/fix_1962_basis_sk
Browse files Browse the repository at this point in the history
Fix #1962 - wrong detection of basis SK
  • Loading branch information
julienduroure committed Sep 6, 2023
2 parents 4aa4772 + 146b64c commit 1818194
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
19 changes: 14 additions & 5 deletions addons/io_scene_gltf2/blender/com/gltf2_blender_data_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ def is_bone_anim_channel(data_path: str) -> bool:

def get_sk_exported(key_blocks):
return [
key_block
for key_block in key_blocks
if not skip_sk(key_block)
k
for k in key_blocks
if not skip_sk(key_blocks, k)
]

def skip_sk(k):
return k == k.relative_key or k.mute
def skip_sk(key_blocks, k):
# Do not export:
# - if muted
# - if relative key is SK itself (this avoid exporting Basis too if user didn't change order)
# - the Basis (the first SK of the list)
return k == k.relative_key \
or k.mute \
or is_first_index(key_blocks, k) is True

def is_first_index(key_blocks, k):
return key_blocks[0].name == k.name
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_channel_groups(obj_uuid: str, blender_action: bpy.types.Action, export_s
type_ = "BONE"
if blender_object.type == "MESH" and object_path.startswith("key_blocks"):
shape_key = blender_object.data.shape_keys.path_resolve(object_path)
if skip_sk(shape_key):
if skip_sk(blender_object.data.shape_keys.key_blocks, shape_key):
continue
target = blender_object.data.shape_keys
type_ = "SK"
Expand All @@ -96,7 +96,7 @@ def get_channel_groups(obj_uuid: str, blender_action: bpy.types.Action, export_s
if blender_object.type == "MESH":
try:
shape_key = blender_object.data.shape_keys.path_resolve(object_path)
if skip_sk(shape_key):
if skip_sk(blender_object.data.shape_keys.key_blocks, shape_key):
continue
target = blender_object.data.shape_keys
type_ = "SK"
Expand Down Expand Up @@ -191,7 +191,7 @@ def __get_channel_group_sorted(channels: typing.Tuple[bpy.types.FCurve], blender
shapekeys_idx = {}
cpt_sk = 0
for sk in blender_object.data.shape_keys.key_blocks:
if skip_sk(sk):
if skip_sk(blender_object.data.shape_keys.key_blocks, sk):
continue
shapekeys_idx[sk.name] = cpt_sk
cpt_sk += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import bpy
import typing
from .....blender.com.gltf2_blender_data_path import skip_sk
from .....blender.com.gltf2_blender_data_path import get_sk_exported
from ....com.gltf2_blender_data_path import get_target_object_path
from ...gltf2_blender_gather_cache import cached
from ..gltf2_blender_gather_keyframes import Keyframe
Expand Down Expand Up @@ -175,9 +175,7 @@ def __gather_non_keyed_values(
if object_path:
shapekeys_idx = {}
cpt_sk = 0
for sk in blender_object.data.shape_keys.key_blocks:
if skip_sk(sk):
continue
for sk in get_sk_exported(blender_object.data.shape_keys.key_blocks):
shapekeys_idx[cpt_sk] = sk.name
cpt_sk += 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_sk_drivers(blender_armature_uuid, export_settings):
sk_name = child.data.shape_keys.path_resolve(get_target_object_path(sk_c.data_path)).name
except:
continue
if skip_sk(child.data.shape_keys.key_blocks[sk_name]):
if skip_sk(child.data.shape_keys.key_blocks, child.data.shape_keys.key_blocks[sk_name]):
continue
idx_channel_mapping.append((shapekeys_idx[sk_name], sk_c))
existing_idx = dict(idx_channel_mapping)
Expand Down

0 comments on commit 1818194

Please sign in to comment.