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-05-26 23:34:29 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-05-26 23:34:29 +0300
commit295984b200890cf6d5bdea6af5a3bd3d4260b765 (patch)
tree5f98e7b7c5630e847cb9d670387b243bf72b30d0 /io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
parente66bf5191ff2ae470b0551c16436de6f0923c07f (diff)
glTF exporter: fix animation when a property is single keyframed (not all property index)
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py70
1 files changed, 69 insertions, 1 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
index 827ec91e..cdd4be7b 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
@@ -34,17 +34,81 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
blender_object: bpy.types.Object,
export_settings
) -> gltf2_io.AnimationSampler:
+
blender_object_if_armature = blender_object if blender_object.type == "ARMATURE" else None
+ if blender_object_if_armature is not None:
+ pose_bone_if_armature = gltf2_blender_get.get_object_from_datapath(blender_object_if_armature,
+ channels[0].data_path)
+ else:
+ pose_bone_if_armature = None
+ non_keyed_values = __gather_non_keyed_values(channels, blender_object,
+ blender_object_if_armature, pose_bone_if_armature,
+ export_settings)
+
+
return gltf2_io.AnimationSampler(
extensions=__gather_extensions(channels, blender_object_if_armature, export_settings),
extras=__gather_extras(channels, blender_object_if_armature, export_settings),
- input=__gather_input(channels, blender_object_if_armature, export_settings),
+ input=__gather_input(channels, blender_object_if_armature, non_keyed_values, export_settings),
interpolation=__gather_interpolation(channels, blender_object_if_armature, export_settings),
output=__gather_output(channels, blender_object.matrix_parent_inverse.copy().freeze(),
blender_object_if_armature,
+ non_keyed_values,
export_settings)
)
+def __gather_non_keyed_values(channels: typing.Tuple[bpy.types.FCurve],
+ blender_object: bpy.types.Object,
+ blender_object_if_armature: typing.Optional[bpy.types.Object],
+ pose_bone_if_armature: typing.Optional[bpy.types.PoseBone],
+ export_settings
+ ) -> typing.Tuple[typing.Optional[float]]:
+
+ non_keyed_values = []
+
+ target = channels[0].data_path.split('.')[-1]
+ if target == "value":
+ return ()
+
+ indices = [c.array_index for c in channels]
+ indices.sort()
+ length = {
+ "delta_location": 3,
+ "delta_rotation_euler": 3,
+ "location": 3,
+ "rotation_axis_angle": 4,
+ "rotation_euler": 3,
+ "rotation_quaternion": 4,
+ "scale": 3,
+ "value": 1
+ }.get(target)
+
+ for i in range(0, length):
+ if i in indices:
+ non_keyed_values.append(None)
+ else:
+ if blender_object_if_armature is None:
+ non_keyed_values.append({
+ "delta_location" : blender_object.delta_location,
+ "delta_rotation_euler" : blender_object.delta_rotation_euler,
+ "location" : blender_object.location,
+ "rotation_axis_angle" : blender_object.rotation_axis_angle,
+ "rotation_euler" : blender_object.rotation_euler,
+ "rotation_quaternion" : blender_object.rotation_quaternion,
+ "scale" : blender_object.scale
+ }[target][i])
+ else:
+ # TODO, this is not working if the action is not active (NLA case for example)
+ trans, rot, scale = pose_bone_if_armature.matrix_basis.decompose()
+ non_keyed_values.append({
+ "location": trans,
+ "rotation_axis_angle": rot,
+ "rotation_euler": rot,
+ "rotation_quaternion": rot,
+ "scale": scale
+ }[target][i])
+
+ return tuple(non_keyed_values)
def __gather_extensions(channels: typing.Tuple[bpy.types.FCurve],
blender_object_if_armature: typing.Optional[bpy.types.Object],
@@ -63,11 +127,13 @@ def __gather_extras(channels: typing.Tuple[bpy.types.FCurve],
@cached
def __gather_input(channels: typing.Tuple[bpy.types.FCurve],
blender_object_if_armature: typing.Optional[bpy.types.Object],
+ non_keyed_values: typing.Tuple[typing.Optional[float]],
export_settings
) -> gltf2_io.Accessor:
"""Gather the key time codes."""
keyframes = gltf2_blender_gather_animation_sampler_keyframes.gather_keyframes(blender_object_if_armature,
channels,
+ non_keyed_values,
export_settings)
times = [k.seconds for k in keyframes]
@@ -107,11 +173,13 @@ def __gather_interpolation(channels: typing.Tuple[bpy.types.FCurve],
def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
parent_inverse,
blender_object_if_armature: typing.Optional[bpy.types.Object],
+ non_keyed_values: typing.Tuple[typing.Optional[float]],
export_settings
) -> gltf2_io.Accessor:
"""Gather the data of the keyframes."""
keyframes = gltf2_blender_gather_animation_sampler_keyframes.gather_keyframes(blender_object_if_armature,
channels,
+ non_keyed_values,
export_settings)
target_datapath = channels[0].data_path