glTF exporter: Reset pose bone between each action
This commit is contained in:
parent
90732dddff
commit
e77b55e45a
|
@ -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, 21),
|
||||
"version": (3, 4, 22),
|
||||
'blender': (3, 3, 0),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
@ -418,6 +418,15 @@ class ExportGLTF2_Base:
|
|||
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(
|
||||
name='Use Current Frame',
|
||||
description='Export the scene in the current animation frame',
|
||||
|
@ -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_optimize_animation'] = self.export_optimize_animation_size
|
||||
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:
|
||||
export_settings['gltf_frame_range'] = False
|
||||
export_settings['gltf_move_keyframes'] = False
|
||||
export_settings['gltf_force_sampling'] = False
|
||||
export_settings['gltf_optimize_animation'] = False
|
||||
export_settings['gltf_export_anim_single_armature'] = False
|
||||
export_settings['gltf_export_reset_pose_bones'] = False
|
||||
export_settings['gltf_skins'] = self.export_skins
|
||||
if self.export_skins:
|
||||
export_settings['gltf_all_vertex_influences'] = self.export_all_influences
|
||||
|
@ -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_optimize_animation_size')
|
||||
layout.prop(operator, 'export_anim_single_armature')
|
||||
layout.prop(operator, 'export_reset_pose_bones')
|
||||
|
||||
|
||||
class GLTF_PT_export_animation_shapekeys(bpy.types.Panel):
|
||||
|
|
|
@ -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.blender.exp.gltf2_blender_gather_tree import VExportNode
|
||||
from ..com.gltf2_blender_data_path import is_bone_anim_channel
|
||||
from mathutils import Matrix
|
||||
|
||||
|
||||
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'):
|
||||
blender_object.animation_data.use_tweak_mode = False
|
||||
try:
|
||||
__reset_bone_matrix(blender_object, export_settings)
|
||||
blender_object.animation_data.action = blender_action
|
||||
except:
|
||||
error = "Action is readonly. Please check NLA editor"
|
||||
|
@ -117,9 +119,11 @@ def gather_animations( obj_uuid: int,
|
|||
if blender_object.animation_data.action is not None:
|
||||
if current_action is None:
|
||||
# remove last exported action
|
||||
__reset_bone_matrix(blender_object, export_settings)
|
||||
blender_object.animation_data.action = None
|
||||
elif blender_object.animation_data.action.name != current_action.name:
|
||||
# Restore action that was active at start of exporting
|
||||
__reset_bone_matrix(blender_object, export_settings)
|
||||
blender_object.animation_data.action = current_action
|
||||
if solo_track is not None:
|
||||
solo_track.is_solo = True
|
||||
|
@ -323,4 +327,20 @@ def __is_armature_action(blender_action) -> bool:
|
|||
for fcurve in blender_action.fcurves:
|
||||
if is_bone_anim_channel(fcurve.data_path):
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue