I’m trying to build a temporary pivot tool, and I made a very simple version just to test the core logic.
The idea is: I compute the relative matrix and apply it to the selected object. The problem is that while I’m working on the current frame, everything behaves correctly. But after I close the tool and scrub or check other frames, the character gets completely broken What could be causing this issue? I’ve uploaded the code and a screen recording of the problem to Google Drive https://drive.google.com/drive/folders/1Bs1oB_2rrRAreBJ0REZZpn2ZW4zbyz0P?usp=sharing Also This is another test. The problem is that the translation is always wrong. I’m doing the test on frame 7, and I uploaded the scene I’m testing on to Drive. import maya.cmds as cmds import maya.mel import maya.api.OpenMaya as om import maya.api.OpenMayaAnim as oma import math def get_dag_path(nodeName): selection_list = om.MSelectionList().add(nodeName) return selection_list.getDagPath(0) # pivot_name_1 repesent point a pivot_name_1 = "locator3" pivot_1 = get_dag_path(pivot_name_1) pivot_matrix_1 = pivot_1.inclusiveMatrix() # pivot_name_2 repesent point b ( after locator3 moved ) pivot_name_2 = "locator4" pivot_2 = get_dag_path(pivot_name_2) pivot_matrix_2 = pivot_2.inclusiveMatrix() # obj_name = "Char_Norman_A1_v011:ctrl_Root" obj_name = "Char_Norman_A1_v011:ctrlIK_Lf_ArmIK" obj = get_dag_path(obj_name) obj_matrix = obj.inclusiveMatrix() # parent_name = "Char_Norman_A1_v011:grAll_Ctrl" parent_name = "Char_Norman_A1_v011:grCon_Lf_ArmIK" parent = get_dag_path(parent_name) parent_matrix = parent.inclusiveMatrix() relative_matrix = obj_matrix * pivot_matrix_1.inverse() new_obj_matrix = relative_matrix * pivot_matrix_2 local_matrix = new_obj_matrix * parent_matrix.inverse() transform_matrix = om.MTransformationMatrix(new_obj_matrix) translation = transform_matrix.translation(om.MSpace.kTransform) rotation = transform_matrix.rotation(False) cmds.xform(obj_name, translation=translation) cmds.xform(obj_name, rotation=[ math.degrees(rotation.x), math.degrees(rotation.y), math.degrees(rotation.z) ]) -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/python_inside_maya/ec2724c9-1ce8-4295-8ec1-9f567595a2c9n%40googlegroups.com.
