glTF exporter: add new animation hooks

This commit is contained in:
Julien Duroure 2022-02-16 12:03:19 +01:00
parent 3270966bba
commit bfcf35f746
3 changed files with 10 additions and 2 deletions

View File

@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (1, 8, 17),
"version": (1, 8, 18),
'blender': (3, 1, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -64,7 +64,7 @@ def __export(export_settings):
buffer = __create_buffer(exporter, export_settings)
exporter.finalize_images()
export_user_extensions('gather_gltf_hook', export_settings, exporter.glTF)
export_user_extensions('gather_gltf_extensions_hook', export_settings, exporter.glTF)
exporter.traverse_extensions()
# now that addons possibly add some fields in json, we can fix in needed
@ -80,6 +80,8 @@ def __gather_gltf(exporter, export_settings):
gltf2_io_draco_compression_extension.encode_scene_primitives(scenes, export_settings)
exporter.add_draco_extension()
export_user_extensions('gather_gltf_hook', export_settings, active_scene_idx, scenes, animations)
for idx, scene in enumerate(scenes):
exporter.add_scene(scene, idx==active_scene_idx)
for animation in animations:

View File

@ -122,6 +122,8 @@ def __gather_animation(blender_action: bpy.types.Action,
print_console("WARNING", "Animation '{}' could not be exported. Cause: {}".format(name, error))
return None
export_user_extensions('pre_gather_animation_hook', export_settings, animation, blender_action, blender_object)
if not animation.channels:
return None
@ -216,6 +218,8 @@ def __get_blender_actions(blender_object: bpy.types.Object,
blender_tracks = {}
action_on_type = {}
export_user_extensions('pre_gather_actions_hook', export_settings, blender_object)
if blender_object.animation_data is not None:
# Collect active action.
if blender_object.animation_data.action is not None:
@ -258,6 +262,8 @@ def __get_blender_actions(blender_object: bpy.types.Object,
blender_tracks[strip.action.name] = track.name # Always set after possible active action -> None will be overwrite
action_on_type[strip.action.name] = "SHAPEKEY"
export_user_extensions('gather_actions_hook', export_settings, blender_object, blender_actions, blender_tracks, action_on_type)
# Remove duplicate actions.
blender_actions = list(set(blender_actions))
# sort animations alphabetically (case insensitive) so they have a defined order and match Blender's Action list