Skip to content
Snippets Groups Projects
Commit e77b55e4 authored by Julien Duroure's avatar Julien Duroure
Browse files

glTF exporter: Reset pose bone between each action

parent 90732ddd
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
bl_info = { bl_info = {
'name': 'glTF 2.0 format', 'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (3, 4, 21), "version": (3, 4, 22),
'blender': (3, 3, 0), 'blender': (3, 3, 0),
'location': 'File > Import-Export', 'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0', 'description': 'Import-Export as glTF 2.0',
...@@ -418,6 +418,15 @@ class ExportGLTF2_Base: ...@@ -418,6 +418,15 @@ class ExportGLTF2_Base:
default=True default=True
) )
export_reset_pose_bones: BoolProperty(
name='Reset pose bones between actions',
description=(
"Reset pose bones between each action exported. "
"This is needed when some bones are not keyed on some animations"
),
default=True
)
export_current_frame: BoolProperty( export_current_frame: BoolProperty(
name='Use Current Frame', name='Use Current Frame',
description='Export the scene in the current animation frame', description='Export the scene in the current animation frame',
...@@ -597,12 +606,14 @@ class ExportGLTF2_Base: ...@@ -597,12 +606,14 @@ class ExportGLTF2_Base:
export_settings['gltf_nla_strips_merged_animation_name'] = self.export_nla_strips_merged_animation_name export_settings['gltf_nla_strips_merged_animation_name'] = self.export_nla_strips_merged_animation_name
export_settings['gltf_optimize_animation'] = self.export_optimize_animation_size export_settings['gltf_optimize_animation'] = self.export_optimize_animation_size
export_settings['gltf_export_anim_single_armature'] = self.export_anim_single_armature export_settings['gltf_export_anim_single_armature'] = self.export_anim_single_armature
export_settings['gltf_export_reset_pose_bones'] = self.export_reset_pose_bones
else: else:
export_settings['gltf_frame_range'] = False export_settings['gltf_frame_range'] = False
export_settings['gltf_move_keyframes'] = False export_settings['gltf_move_keyframes'] = False
export_settings['gltf_force_sampling'] = False export_settings['gltf_force_sampling'] = False
export_settings['gltf_optimize_animation'] = False export_settings['gltf_optimize_animation'] = False
export_settings['gltf_export_anim_single_armature'] = False export_settings['gltf_export_anim_single_armature'] = False
export_settings['gltf_export_reset_pose_bones'] = False
export_settings['gltf_skins'] = self.export_skins export_settings['gltf_skins'] = self.export_skins
if self.export_skins: if self.export_skins:
export_settings['gltf_all_vertex_influences'] = self.export_all_influences export_settings['gltf_all_vertex_influences'] = self.export_all_influences
...@@ -957,6 +968,7 @@ class GLTF_PT_export_animation_export(bpy.types.Panel): ...@@ -957,6 +968,7 @@ class GLTF_PT_export_animation_export(bpy.types.Panel):
layout.prop(operator, 'export_nla_strips_merged_animation_name') layout.prop(operator, 'export_nla_strips_merged_animation_name')
layout.prop(operator, 'export_optimize_animation_size') layout.prop(operator, 'export_optimize_animation_size')
layout.prop(operator, 'export_anim_single_armature') layout.prop(operator, 'export_anim_single_armature')
layout.prop(operator, 'export_reset_pose_bones')
class GLTF_PT_export_animation_shapekeys(bpy.types.Panel): class GLTF_PT_export_animation_shapekeys(bpy.types.Panel):
......
...@@ -11,6 +11,7 @@ from ..com.gltf2_blender_extras import generate_extras ...@@ -11,6 +11,7 @@ from ..com.gltf2_blender_extras import generate_extras
from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
from io_scene_gltf2.blender.exp.gltf2_blender_gather_tree import VExportNode from io_scene_gltf2.blender.exp.gltf2_blender_gather_tree import VExportNode
from ..com.gltf2_blender_data_path import is_bone_anim_channel from ..com.gltf2_blender_data_path import is_bone_anim_channel
from mathutils import Matrix
def gather_animations( obj_uuid: int, def gather_animations( obj_uuid: int,
...@@ -91,6 +92,7 @@ def gather_animations( obj_uuid: int, ...@@ -91,6 +92,7 @@ def gather_animations( obj_uuid: int,
if blender_object.animation_data.is_property_readonly('action'): if blender_object.animation_data.is_property_readonly('action'):
blender_object.animation_data.use_tweak_mode = False blender_object.animation_data.use_tweak_mode = False
try: try:
__reset_bone_matrix(blender_object, export_settings)
blender_object.animation_data.action = blender_action blender_object.animation_data.action = blender_action
except: except:
error = "Action is readonly. Please check NLA editor" error = "Action is readonly. Please check NLA editor"
...@@ -117,9 +119,11 @@ def gather_animations( obj_uuid: int, ...@@ -117,9 +119,11 @@ def gather_animations( obj_uuid: int,
if blender_object.animation_data.action is not None: if blender_object.animation_data.action is not None:
if current_action is None: if current_action is None:
# remove last exported action # remove last exported action
__reset_bone_matrix(blender_object, export_settings)
blender_object.animation_data.action = None blender_object.animation_data.action = None
elif blender_object.animation_data.action.name != current_action.name: elif blender_object.animation_data.action.name != current_action.name:
# Restore action that was active at start of exporting # Restore action that was active at start of exporting
__reset_bone_matrix(blender_object, export_settings)
blender_object.animation_data.action = current_action blender_object.animation_data.action = current_action
if solo_track is not None: if solo_track is not None:
solo_track.is_solo = True solo_track.is_solo = True
...@@ -323,4 +327,20 @@ def __is_armature_action(blender_action) -> bool: ...@@ -323,4 +327,20 @@ def __is_armature_action(blender_action) -> bool:
for fcurve in blender_action.fcurves: for fcurve in blender_action.fcurves:
if is_bone_anim_channel(fcurve.data_path): if is_bone_anim_channel(fcurve.data_path):
return True return True
return False return False
\ No newline at end of file
def __reset_bone_matrix(blender_object, export_settings) -> None:
if export_settings['gltf_export_reset_pose_bones'] is False:
return
# Only for armatures
if blender_object.type != "ARMATURE":
return
# Remove current action if any
if blender_object.animation_data and blender_object.animation_data.action:
blender_object.animation_data.action = None
# Resetting bones TRS to avoid to keep not keyed value on a future action set
for bone in blender_object.pose.bones:
bone.matrix_basis = Matrix()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment