diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-01-26 11:30:39 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-01-26 11:30:39 +0300 |
commit | 171648da578dc2783e17a9fd456893f5bb4ff9d6 (patch) | |
tree | 6d5dc4c9cf7bc99bcf006099e8eae95a26b0966d /io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py | |
parent | 5c1b4497dacca6e183ffe50e03cb4e2e60e7325e (diff) |
glTF exporter: export animation on armature itself when sampled animation export
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py')
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py | 52 |
1 files changed, 52 insertions, 0 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 199d73a9..36b850df 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 @@ -83,6 +83,18 @@ def gather_animation_channels(blender_action: bpy.types.Action, channels.append(channel) + # Retrieve animation on armature object itself, if any + fcurves_armature = __gather_armature_object_channel_groups(blender_action, blender_object, export_settings) + for channel_group in fcurves_armature: + # No need to sort on armature, that can't have SK + if len(channel_group) == 0: + # Only errors on channels, ignoring + continue + channel = __gather_animation_channel(channel_group, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name, None) + if channel is not None: + channels.append(channel) + + # Retrieve channels for drivers, if needed drivers_to_manage = gltf2_blender_gather_drivers.get_sk_drivers(blender_object) for obj, fcurves in drivers_to_manage: @@ -316,6 +328,46 @@ def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.t if multiple_rotation_mode_detected is True: gltf2_io_debug.print_console("WARNING", "Multiple rotation mode detected for {}".format(blender_object.name)) + return map(tuple, groups) + +def __gather_armature_object_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.types.Object, export_settings): + + targets = {} + + if blender_object.type != "ARMATURE": + return tuple() + + for fcurve in blender_action.fcurves: + object_path = get_target_object_path(fcurve.data_path) + if object_path != "": + continue + + # In some invalid files, channel hasn't any keyframes ... this channel need to be ignored + if len(fcurve.keyframe_points) == 0: + continue + try: + target_property = get_target_property_name(fcurve.data_path) + except: + gltf2_io_debug.print_console("WARNING", "Invalid animation fcurve name on action {}".format(blender_action.name)) + continue + target = gltf2_blender_get.get_object_from_datapath(blender_object, object_path) + + # Detect that armature is not multiple keyed for euler and quaternion + # Keep only the current rotation mode used by object + rotation, rotation_modes = get_rotation_modes(target_property) + if rotation and target.rotation_mode not in rotation_modes: + continue + + # group channels by target object and affected property of the target + target_properties = targets.get(target, {}) + channels = target_properties.get(target_property, []) + channels.append(fcurve) + target_properties[target_property] = channels + targets[target] = target_properties + + groups = [] + for p in targets.values(): + groups += list(p.values()) return map(tuple, groups) |