glTF exporter: Various hooks and fixed to better animation filtering / management

This commit is contained in:
Julien Duroure 2022-10-04 09:29:10 +02:00
parent 70ee1a5b66
commit eb3dcfc70c
3 changed files with 26 additions and 2 deletions

View File

@ -4,7 +4,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": (3, 4, 30),
"version": (3, 4, 31),
'blender': (3, 3, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -82,6 +82,8 @@ def gather_animations( obj_uuid: int,
current_use_nla = blender_object.animation_data.use_nla
blender_object.animation_data.use_nla = False
export_user_extensions('animation_switch_loop_hook', export_settings, blender_object, False)
# Export all collected actions.
for blender_action, track_name, on_type in blender_actions:
@ -93,7 +95,9 @@ def gather_animations( obj_uuid: int,
blender_object.animation_data.use_tweak_mode = False
try:
__reset_bone_matrix(blender_object, export_settings)
export_user_extensions('pre_animation_switch_hook', export_settings, blender_object, blender_action, track_name, on_type)
blender_object.animation_data.action = blender_action
export_user_extensions('post_animation_switch_hook', export_settings, blender_object, blender_action, track_name, on_type)
except:
error = "Action is readonly. Please check NLA editor"
print_console("WARNING", "Animation '{}' could not be exported. Cause: {}".format(blender_action.name, error))
@ -130,6 +134,8 @@ def gather_animations( obj_uuid: int,
blender_object.animation_data.use_tweak_mode = restore_tweak_mode
blender_object.animation_data.use_nla = current_use_nla
export_user_extensions('animation_switch_loop_hook', export_settings, blender_object, True)
return animations, tracks
@ -313,7 +319,21 @@ def __get_blender_actions(blender_object: bpy.types.Object,
blender_tracks[act.name] = None
action_on_type[act.name] = "OBJECT"
export_user_extensions('gather_actions_hook', export_settings, blender_object, blender_actions, blender_tracks, action_on_type)
# Use a class to get parameters, to be able to modify them
class GatherActionHookParameters:
def __init__(self, blender_actions, blender_tracks, action_on_type):
self.blender_actions = blender_actions
self.blender_tracks = blender_tracks
self.action_on_type = action_on_type
gatheractionhookparams = GatherActionHookParameters(blender_actions, blender_tracks, action_on_type)
export_user_extensions('gather_actions_hook', export_settings, blender_object, gatheractionhookparams)
# Get params back from hooks
blender_actions = gatheractionhookparams.blender_actions
blender_tracks = gatheractionhookparams.blender_tracks
action_on_type = gatheractionhookparams.action_on_type
# Remove duplicate actions.
blender_actions = list(set(blender_actions))

View File

@ -289,6 +289,7 @@ class VExportTree:
self.filter_tag()
export_user_extensions('gather_tree_filter_tag_hook', self.export_settings, self)
self.filter_perform()
self.remove_filtered_nodes()
def recursive_filter_tag(self, uuid, parent_keep_tag):
@ -404,6 +405,9 @@ class VExportTree:
return True
def remove_filtered_nodes(self):
self.nodes = {k:n for (k, n) in self.nodes.items() if n.keep_tag is True}
def search_missing_armature(self):
for n in [n for n in self.nodes.values() if hasattr(n, "armature_needed") is True]:
candidates = [i for i in self.nodes.values() if i.blender_type == VExportNode.ARMATURE and i.blender_object.name == n.armature_needed]