From 812cb318c4e0d3f744777bef3744041b5f7c995f Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Wed, 18 Sep 2019 00:35:40 +0200 Subject: glTF exporter: fix sample animation export when sampled is forced by context, not by user --- io_scene_gltf2/__init__.py | 2 +- .../exp/gltf2_blender_gather_animation_channels.py | 35 ++++++++++++---------- ...2_blender_gather_animation_sampler_keyframes.py | 13 ++++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 0b7474e7..6011c526 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -15,7 +15,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (0, 9, 69), + "version": (0, 9, 70), 'blender': (2, 81, 6), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', 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 b2d69ae9..1ac3600e 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 @@ -31,24 +31,27 @@ def gather_animation_channels(blender_action: bpy.types.Action, ) -> typing.List[gltf2_io.AnimationChannel]: channels = [] + + # First calculate range of animation for baking + # This is need if user set 'Force sampling' and in case we need to bake + bake_range_start = None + bake_range_end = None + groups = __get_channel_groups(blender_action, blender_object, export_settings) + for chans in groups: + ranges = [channel.range() for channel in chans] + if bake_range_start is None: + bake_range_start = min([channel.range()[0] for channel in chans]) + else: + bake_range_start = min(bake_range_start, min([channel.range()[0] for channel in chans])) + if bake_range_end is None: + bake_range_end = max([channel.range()[1] for channel in chans]) + else: + bake_range_end = max(bake_range_end, max([channel.range()[1] for channel in chans])) + + if blender_object.type == "ARMATURE" and export_settings['gltf_force_sampling'] is True: # We have to store sampled animation data for every deformation bones - # First calculate range of animation for baking - bake_range_start = None - bake_range_end = None - groups = __get_channel_groups(blender_action, blender_object, export_settings) - for chans in groups: - ranges = [channel.range() for channel in chans] - if bake_range_start is None: - bake_range_start = min([channel.range()[0] for channel in chans]) - else: - bake_range_start = min(bake_range_start, min([channel.range()[0] for channel in chans])) - if bake_range_end is None: - bake_range_end = max([channel.range()[1] for channel in chans]) - else: - bake_range_end = max(bake_range_end, max([channel.range()[1] for channel in chans])) - # Then bake all bones for bone in blender_object.data.bones: for p in ["location", "rotation_quaternion", "scale"]: @@ -65,7 +68,7 @@ def gather_animation_channels(blender_action: bpy.types.Action, else: for channel_group in __get_channel_groups(blender_action, blender_object, export_settings): 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) + channel = __gather_animation_channel(channel_group_sorted, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name) if channel is not None: channels.append(channel) diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py index 20e7dbb6..8a4f011a 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py @@ -126,15 +126,12 @@ def get_bone_matrix(blender_object_if_armature: typing.Optional[bpy.types.Object data = {} - if bake_bone is None: - # Find the start and end of the whole action group - ranges = [channel.range() for channel in channels] + # Always using bake_range, because some bones may need to be baked, + # even if user didn't request it + + start_frame = bake_range_start + end_frame = bake_range_end - start_frame = min([channel.range()[0] for channel in channels]) - end_frame = max([channel.range()[1] for channel in channels]) - else: - start_frame = bake_range_start - end_frame = bake_range_end frame = start_frame while frame <= end_frame: -- cgit v1.2.3