Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2019-08-23 08:29:41 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-08-23 08:29:41 +0300
commitfc320ea236c7f264a1438e7af338581a37bb74b1 (patch)
tree2619ec51d39be2d0bff04cc017dbe8556e8a04dc /io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
parent3c3c2243dbbd8a35d1472db445a7dbc6c561ab38 (diff)
glTF exporter: fix shapekeys animation export
Animation channels must be sorted in exactly same order than shapekeys
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
index 412f275b..45a75717 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
@@ -64,12 +64,35 @@ def gather_animation_channels(blender_action: bpy.types.Action,
channels.append(channel)
else:
for channel_group in __get_channel_groups(blender_action, blender_object, export_settings):
- channel = __gather_animation_channel(channel_group, blender_object, export_settings, None, None, None, None, blender_action.name)
+ channel_group_sorted = __get_channel_group_sorted(channel_group, blender_object)
+ channel = __gather_animation_channel(channel_group_sorted, blender_object, export_settings, None, None, None, None, blender_action.name)
if channel is not None:
channels.append(channel)
return channels
+def __get_channel_group_sorted(channels: typing.Tuple[bpy.types.FCurve], blender_object: bpy.types.Object):
+ # if this is shapekey animation, we need to sort in same order than shapekeys
+ # else, no need to sort
+ if blender_object.type == "MESH":
+ first_channel = channels[0]
+ object_path = get_target_object_path(first_channel.data_path)
+ if object_path:
+ # This is shapekeys, we need to sort channels
+ shapekeys_idx = {}
+ cpt_sk = 0
+ for sk in blender_object.data.shape_keys.key_blocks:
+ if sk == sk.relative_key:
+ continue
+ if sk.mute is True:
+ continue
+ shapekeys_idx[sk.name] = cpt_sk
+ cpt_sk += 1
+
+ return tuple(sorted(channels, key=lambda x: shapekeys_idx[blender_object.data.shape_keys.path_resolve(get_target_object_path(x.data_path)).name]))
+
+ # if not shapekeys, stay in same order, because order doesn't matter
+ return channels
def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve],
blender_object: bpy.types.Object,
@@ -164,12 +187,17 @@ def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.t
else:
try:
target = gltf2_blender_get.get_object_from_datapath(blender_object, object_path)
+ if blender_object.type == "MESH":
+ shape_key = blender_object.data.shape_keys.path_resolve(object_path)
+ if shape_key.mute is True:
+ continue
except ValueError as e:
# if the object is a mesh and the action target path can not be resolved, we know that this is a morph
# animation.
if blender_object.type == "MESH":
- # if you need the specific shape key for some reason, this is it:
- # shape_key = blender_object.data.shape_keys.path_resolve(object_path)
+ shape_key = blender_object.data.shape_keys.path_resolve(object_path)
+ if shape_key.mute is True:
+ continue
target = blender_object.data.shape_keys
else:
gltf2_io_debug.print_console("WARNING", "Animation target {} not found".format(object_path))