glTF exporter: avoid exporting rotation twice when both euler and quaternion are animated
Keeping only the current rotation mode of the object or bone
This commit is contained in:
parent
9189c45958
commit
97b11857d3
|
@ -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": (1, 1, 8),
|
||||
"version": (1, 1, 9),
|
||||
'blender': (2, 81, 6),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
|
|
@ -26,3 +26,14 @@ def get_target_object_path(data_path: str) -> str:
|
|||
return ""
|
||||
return path_split[0]
|
||||
|
||||
def get_rotation_modes(target_property: str) -> str:
|
||||
"""Retrieve rotation modes based on target_property"""
|
||||
if target_property in ["rotation_euler", "delta_rotation_euler"]:
|
||||
return True, ["XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"]
|
||||
elif target_property in ["rotation_quaternion", "delta_rotation_quaternion"]:
|
||||
return True, ["QUATERNION"]
|
||||
elif target_property in ["rotation_axis_angle"]:
|
||||
return True, ["AXIS_ANGLE"]
|
||||
else:
|
||||
return False, []
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import bpy
|
||||
import typing
|
||||
|
||||
from ..com.gltf2_blender_data_path import get_target_object_path, get_target_property_name
|
||||
from ..com.gltf2_blender_data_path import get_target_object_path, get_target_property_name, get_rotation_modes
|
||||
from io_scene_gltf2.io.com import gltf2_io
|
||||
from io_scene_gltf2.io.com import gltf2_io_debug
|
||||
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
|
||||
|
@ -200,6 +200,7 @@ def __gather_target(channels: typing.Tuple[bpy.types.FCurve],
|
|||
|
||||
def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.types.Object, export_settings):
|
||||
targets = {}
|
||||
multiple_rotation_mode_detected = False
|
||||
for fcurve in blender_action.fcurves:
|
||||
# In some invalid files, channel hasn't any keyframes ... this channel need to be ignored
|
||||
if len(fcurve.keyframe_points) == 0:
|
||||
|
@ -239,6 +240,13 @@ def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.t
|
|||
gltf2_io_debug.print_console("WARNING", "Animation target {} not found".format(object_path))
|
||||
continue
|
||||
|
||||
# Detect that object or bone are not multiple keyed for euler and quaternion
|
||||
# Keep only the current rotation mode used by object / bone
|
||||
rotation, rotation_modes = get_rotation_modes(target_property)
|
||||
if rotation and target.rotation_mode not in rotation_modes:
|
||||
multiple_rotation_mode_detected = True
|
||||
continue
|
||||
|
||||
# group channels by target object and affected property of the target
|
||||
target_properties = targets.get(target, {})
|
||||
channels = target_properties.get(target_property, [])
|
||||
|
@ -250,5 +258,9 @@ def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.t
|
|||
for p in targets.values():
|
||||
groups += list(p.values())
|
||||
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue