glTF exporter: Export multiple actions (from NLA) when sampled is now fixed

This commit is contained in:
Julien Duroure 2019-05-31 22:18:24 +02:00
parent 178738edd2
commit a5f2de9627
5 changed files with 34 additions and 7 deletions

View File

@ -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, 16),
"version": (0, 9, 17),
'blender': (2, 80, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -59,11 +59,12 @@ def gather_animation_channels(blender_action: bpy.types.Action,
bone.name,
p,
bake_range_start,
bake_range_end)
bake_range_end,
blender_action.name)
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)
channel = __gather_animation_channel(channel_group, blender_object, export_settings, None, None, None, None, blender_action.name)
if channel is not None:
channels.append(channel)
@ -76,7 +77,8 @@ def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve],
bake_bone: typing.Union[str, None],
bake_channel: typing.Union[str, None],
bake_range_start,
bake_range_end
bake_range_end,
action_name: str
) -> typing.Union[gltf2_io.AnimationChannel, None]:
if not __filter_animation_channel(channels, blender_object, export_settings):
return None
@ -84,7 +86,7 @@ def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve],
return gltf2_io.AnimationChannel(
extensions=__gather_extensions(channels, blender_object, export_settings, bake_bone),
extras=__gather_extras(channels, blender_object, export_settings, bake_bone),
sampler=__gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end),
sampler=__gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name),
target=__gather_target(channels, blender_object, export_settings, bake_bone, bake_channel)
)
@ -118,7 +120,8 @@ def __gather_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_bone: typing.Union[str, None],
bake_channel: typing.Union[str, None],
bake_range_start,
bake_range_end
bake_range_end,
action_name
) -> gltf2_io.AnimationSampler:
return gltf2_blender_gather_animation_samplers.gather_animation_sampler(
channels,
@ -127,6 +130,7 @@ def __gather_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_channel,
bake_range_start,
bake_range_end,
action_name,
export_settings
)

View File

@ -114,6 +114,7 @@ def gather_keyframes(blender_object_if_armature: typing.Optional[bpy.types.Objec
bake_channel: typing.Union[str, None],
bake_range_start,
bake_range_end,
action_name: str,
export_settings
) -> typing.List[Keyframe]:
"""Convert the blender action groups' fcurves to keyframes for use in glTF."""

View File

@ -36,6 +36,7 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_channel: typing.Union[str, None],
bake_range_start,
bake_range_end,
action_name: str,
export_settings
) -> gltf2_io.AnimationSampler:
@ -57,7 +58,8 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
return gltf2_io.AnimationSampler(
extensions=__gather_extensions(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel),
extras=__gather_extras(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel),
input=__gather_input(channels, blender_object_if_armature, non_keyed_values, bake_bone, bake_channel, bake_range_start, bake_range_end, export_settings),
input=__gather_input(channels, blender_object_if_armature, non_keyed_values,
bake_bone, bake_channel, bake_range_start, bake_range_end, action_name, export_settings),
interpolation=__gather_interpolation(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel),
output=__gather_output(channels, blender_object.matrix_parent_inverse.copy().freeze(),
blender_object_if_armature,
@ -66,6 +68,7 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve],
bake_channel,
bake_range_start,
bake_range_end,
action_name,
export_settings)
)
@ -166,6 +169,7 @@ def __gather_input(channels: typing.Tuple[bpy.types.FCurve],
bake_channel: typing.Union[str, None],
bake_range_start,
bake_range_end,
action_name,
export_settings
) -> gltf2_io.Accessor:
"""Gather the key time codes."""
@ -176,6 +180,7 @@ def __gather_input(channels: typing.Tuple[bpy.types.FCurve],
bake_channel,
bake_range_start,
bake_range_end,
action_name,
export_settings)
times = [k.seconds for k in keyframes]
@ -225,6 +230,7 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
bake_channel: typing.Union[str, None],
bake_range_start,
bake_range_end,
action_name,
export_settings
) -> gltf2_io.Accessor:
"""Gather the data of the keyframes."""
@ -235,6 +241,7 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve],
bake_channel,
bake_range_start,
bake_range_end,
action_name,
export_settings)
if bake_bone is not None:
target_datapath = "pose.bones['" + bake_bone + "']." + bake_channel

View File

@ -33,12 +33,27 @@ def gather_animations(blender_object: bpy.types.Object, export_settings) -> typi
# Collect all 'actions' affecting this object. There is a direct mapping between blender actions and glTF animations
blender_actions = __get_blender_actions(blender_object)
# save the current active action of the object, if any
# We will restore it after export
current_action = None
if blender_object.animation_data and blender_object.animation_data.action:
current_action = blender_object.animation_data.action
# Export all collected actions.
for blender_action in blender_actions:
# Set action as active, to be able to bake if needed
if blender_object.animation_data: # Not for shapekeys!
blender_object.animation_data.action = blender_action
animation = __gather_animation(blender_action, blender_object, export_settings)
if animation is not None:
animations.append(animation)
# Restore current action
if blender_object.animation_data:
blender_object.animation_data.action = current_action
return animations