From dd93ec7bacd186da01581fb15dd3409a1c355fa7 Mon Sep 17 00:00:00 2001 From: AATB Date: Thu, 16 Nov 2023 13:41:06 +0100 Subject: [PATCH 1/2] when using Sample Keyframe Only option, export ANY frame that has either IK tool_CTRL or any of the 6 FK_CTRL keyframed --- mimic3/scripts/mimic_program.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mimic3/scripts/mimic_program.py b/mimic3/scripts/mimic_program.py index 041c65f..9ef28dc 100644 --- a/mimic3/scripts/mimic_program.py +++ b/mimic3/scripts/mimic_program.py @@ -937,6 +937,9 @@ def _get_frames_using_sample_rate(animation_settings, postproc_settings): def _get_frames_using_keyframes_only(robot, animation_settings): """ Get frames from animation using a robot's keyframes only. + Historically Mimic looked for both simultaneous IK and FK keyframes set + on a frame to consider it part of the exported keyframes, + it was removed since general use tends to favorite IK-only keyframes. :param robot: :param animation_settings: :return: @@ -946,7 +949,7 @@ def _get_frames_using_keyframes_only(robot, animation_settings): end_frame = animation_settings['End Frame'] # Get list of keyframes on robots IK attribute for the given range target_ctrl_path = mimic_utils.get_target_ctrl_path(robot) - ik_keyframes = pm.keyframe( + frames = pm.keyframe( target_ctrl_path, attribute='ik', query=True, @@ -955,11 +958,11 @@ def _get_frames_using_keyframes_only(robot, animation_settings): # attributes. If there's not, we remove it from the list # Note: we only need to check one controller as they are all keyframed # together - fk_test_handle_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a1FK_CTRL.rotateY', robot) - frames = [frame for frame in ik_keyframes if pm.keyframe( - fk_test_handle_path, - query=True, - time=frame)] + # fk_test_handle_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a1FK_CTRL.rotateY', robot) + # frames = [frame for frame in ik_keyframes if pm.keyframe( + # fk_test_handle_path, + # query=True, + # time=frame)] return frames From c2b93f7cbcd1c77b544775fc3a05879ddc092d47 Mon Sep 17 00:00:00 2001 From: AATB Date: Thu, 16 Nov 2023 13:41:57 +0100 Subject: [PATCH 2/2] properly sort and dedup final list --- mimic3/scripts/mimic_program.py | 58 +++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/mimic3/scripts/mimic_program.py b/mimic3/scripts/mimic_program.py index 9ef28dc..5ae5be5 100644 --- a/mimic3/scripts/mimic_program.py +++ b/mimic3/scripts/mimic_program.py @@ -8,6 +8,7 @@ try: import pymel.core as pm import maya.mel as mel + import numpy as np MAYA_IS_RUNNING = True except ImportError: # Maya is not running @@ -937,9 +938,7 @@ def _get_frames_using_sample_rate(animation_settings, postproc_settings): def _get_frames_using_keyframes_only(robot, animation_settings): """ Get frames from animation using a robot's keyframes only. - Historically Mimic looked for both simultaneous IK and FK keyframes set - on a frame to consider it part of the exported keyframes, - it was removed since general use tends to favorite IK-only keyframes. + This will include ANY keyframe set on either IK tool_CTRL or any of the 6 FK_CTRL handles. :param robot: :param animation_settings: :return: @@ -947,22 +946,55 @@ def _get_frames_using_keyframes_only(robot, animation_settings): # Get relevant animation parameters. start_frame = animation_settings['Start Frame'] end_frame = animation_settings['End Frame'] + # Get list of keyframes on robots IK attribute for the given range target_ctrl_path = mimic_utils.get_target_ctrl_path(robot) - frames = pm.keyframe( + ik_keyframes = pm.keyframe( target_ctrl_path, attribute='ik', query=True, time='{}:{}'.format(start_frame, end_frame)) - # Verify that there is also a keyframe set on the FK controls' rotate - # attributes. If there's not, we remove it from the list - # Note: we only need to check one controller as they are all keyframed - # together - # fk_test_handle_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a1FK_CTRL.rotateY', robot) - # frames = [frame for frame in ik_keyframes if pm.keyframe( - # fk_test_handle_path, - # query=True, - # time=frame)] + + # Get all FK keyframes set per each individual joints + fk_1_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a1FK_CTRL.rotateY', robot) + fk_1_keyframes = pm.keyframe( + fk_1_path, + query=True, + time='{}:{}'.format(start_frame, end_frame)) + + fk_2_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a2FK_CTRL.rotateX', robot) + fk_2_keyframes = pm.keyframe( + fk_2_path, + query=True, + time='{}:{}'.format(start_frame, end_frame)) + + fk_3_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a3FK_CTRL.rotateX', robot) + fk_3_keyframes = pm.keyframe( + fk_3_path, + query=True, + time='{}:{}'.format(start_frame, end_frame)) + + fk_4_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a4FK_CTRL.rotateY', robot) + fk_4_keyframes = pm.keyframe( + fk_4_path, + query=True, + time='{}:{}'.format(start_frame, end_frame)) + + fk_5_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a5FK_CTRL.rotateX', robot) + fk_5_keyframes = pm.keyframe( + fk_5_path, + query=True, + time='{}:{}'.format(start_frame, end_frame)) + + fk_6_path = mimic_utils.format_path('{0}|{1}robot_GRP|{1}FK_CTRLS|{1}a6FK_CTRL.rotateZ', robot) + fk_6_keyframes = pm.keyframe( + fk_6_path, + query=True, + time='{}:{}'.format(start_frame, end_frame)) + + # combine all keyframe lists as one unique and deduplicated list + frames = list(np.unique(ik_keyframes + fk_1_keyframes + fk_2_keyframes + fk_3_keyframes + fk_4_keyframes + fk_5_keyframes + fk_6_keyframes)) + return frames