def test_remove_six(self): """ Open a rigged character and create a controller, set some values and remove the controller. """ path = self.get_data_path('scenes', 'rigHierachy.ma') maya.cmds.file(path, open=True, force=True) tfm_a = 'rig:FKShoulder_L' tfm_b = 'rig:FKElbow_L' ctrls = lib.create([tfm_a]) ctrl_a = ctrls[0] plug = ctrl_a + '.rotateY' maya.cmds.setAttr(plug, 0.0) # save the output path = self.get_data_path( 'controller_remove_riggedCharacterArmModify_before.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) real_matrix = maya.cmds.xform(tfm_a, query=True, matrix=True, worldSpace=True) test_matrix = [ -0.7216083162924442, 0.5093866470512706, -0.46883545265204635, 0.0, 0.6923015512459766, 0.53095019079326, -0.48868236825060146, 0.0, 4.163336342344337e-16, -0.677212772105242, -0.7357872391510578, 0.0, 14.328976267123226, 128.14777525332602, -4.9690466428543845, 1.0 ] self.assertGreater(closeness.compare_floats(real_matrix, test_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) lib.remove(ctrls) # save the output path = self.get_data_path( 'controller_remove_riggedCharacterArmModify_after.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Should be the exact same matrix as before. real_matrix = maya.cmds.xform(tfm_a, query=True, matrix=True, worldSpace=True) self.assertGreater(closeness.compare_floats(real_matrix, test_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) # Test elbow control matrix. real_matrix = maya.cmds.xform(tfm_b, query=True, matrix=True, worldSpace=True) test_matrix = [ -0.37141467173729487, 0.6831542385392256, -0.6287697734339405, 0.0, 0.928467092372303, 0.27328217589778103, -0.25152675944777053, 0.0, 1.5091078635869547e-15, -0.6772127721052421, -0.7357872391510579, 0.0, 34.97402889955959, 113.57433714126877, 8.444230861601302, 1.0 ] self.assertGreater(closeness.compare_floats(real_matrix, test_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) return
def test_remove_five(self): """ Open a rigged character and create a controller. """ path = self.get_data_path('scenes', 'rigHierachy.ma') maya.cmds.file(path, open=True, force=True) tfm_a = 'rig:FKShoulder_L' tfm_b = 'rig:FKElbow_L' matrix_a1 = maya.cmds.xform(tfm_a, query=True, matrix=True, worldSpace=True) matrix_b1 = maya.cmds.xform(tfm_b, query=True, matrix=True, worldSpace=True) ctrls = lib.create([tfm_a, tfm_b]) ctrl_a, ctrl_b = ctrls child_a = maya.cmds.createNode('transform', parent=ctrl_a, name='childA') child_b = maya.cmds.createNode('transform', parent=ctrl_b, name='childB') # save the output path = self.get_data_path( 'controller_remove_riggedCharacter_before.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Test created control matrixes. matrix_a2 = maya.cmds.xform(ctrl_a, query=True, matrix=True, worldSpace=True) matrix_b2 = maya.cmds.xform(ctrl_b, query=True, matrix=True, worldSpace=True) self.assertGreater(closeness.compare_floats(matrix_a1, matrix_a2), closeness.DEFAULT_SIGNIFICANT_DIGITS) self.assertGreater(closeness.compare_floats(matrix_b1, matrix_b2), closeness.DEFAULT_SIGNIFICANT_DIGITS) lib.remove(ctrls) # save the output path = self.get_data_path('controller_remove_riggedCharacter_after.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Make sure child objects are parented under the original rig # controls self.assertEqual(maya.cmds.objExists('childA'), True) self.assertEqual(maya.cmds.objExists('childB'), True) self.assertEqual(maya.cmds.objExists('|childA'), False) self.assertEqual(maya.cmds.objExists('|childB'), False) self.assertIn('childA', maya.cmds.listRelatives(tfm_a)) self.assertIn('childB', maya.cmds.listRelatives(tfm_b)) # Test shoulder control matrix. real_matrix = maya.cmds.xform(tfm_a, query=True, matrix=True, worldSpace=True) test_matrix = [ -0.16512703574001636, 0.9851022889880628, 0.04802647497156621, 0.0, 0.15842071164425758, 0.07455484524495984, -0.9845529204530482, 0.0, -0.9734659419773467, -0.1549679169408274, -0.1683716262592317, 0.0, 14.328976267123226, 128.14777525332602, -4.969046642854377, 1.0 ] self.assertGreater(closeness.compare_floats(real_matrix, test_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) # Test elbow control matrix. real_matrix = maya.cmds.xform(tfm_b, query=True, matrix=True, worldSpace=True) test_matrix = [ -0.08499154235006842, 0.9280069723575602, -0.3627388826479886, 0.0, 0.21246293215315154, -0.3388037838849731, -0.9165541437831752, 0.0, -0.9734659419773467, -0.1549679169408281, -0.16837162625923255, 0.0, 19.05322384980939, 99.96421895926306, -6.34307335672691, 1.0 ] self.assertGreater(closeness.compare_floats(real_matrix, test_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) return
def test_set_transform_values_with_rotate_pivot(self): path = self.get_data_path('scenes', 'bookHierarchy.ma') maya.cmds.file(path, open=True, force=True) book_node = 'book_GRP' spine_node = 'spine_GRP' cover_node = 'front_cover_GRP' maya.cmds.setAttr(book_node + '.ty', 10.0) maya.cmds.setAttr(book_node + '.rz', 90.0) maya.cmds.setAttr(spine_node + '.rz', 90.0) maya.cmds.setAttr(cover_node + '.rz', 90.0) book_tfm = mod.TransformNode(book_node) spine_tfm = mod.TransformNode(spine_node) cover_tfm = mod.TransformNode(cover_node) tfm_nodes = [book_tfm, spine_tfm, cover_tfm] current_frame = maya.cmds.currentTime(query=True) frame_range = [current_frame] # Query the transform matrix for the nodes cache = mod.TransformMatrixCache() for tfm_node in tfm_nodes: cache.add_node(tfm_node, frame_range) cache.process() book_dst_node = maya.cmds.createNode('transform', name='book_CTRL') book_dst_tfm_node = mod.TransformNode(node=book_dst_node) mod.set_transform_values(cache, frame_range, book_tfm, book_dst_tfm_node, delete_static_anim_curves=False) spine_dst_node = maya.cmds.createNode('transform', name='spine_CTRL') spine_dst_tfm_node = mod.TransformNode(node=spine_dst_node) mod.set_transform_values(cache, frame_range, spine_tfm, spine_dst_tfm_node, delete_static_anim_curves=False) cover_dst_node = maya.cmds.createNode('transform', name='cover_CTRL') cover_dst_tfm_node = mod.TransformNode(node=cover_dst_node) mod.set_transform_values(cache, frame_range, cover_tfm, cover_dst_tfm_node, delete_static_anim_curves=False) # save the output scene file path = 'test_transform_set_transforms_with_rotate_pivot.ma' path = self.get_data_path(path) maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Expected Matrices expected_book_matrix = [ 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 10.0, 0.0, 1.0 ] expected_spine_matrix = [ -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3518918752670288, 8.476484298706055, 0.0029969215393066406, 1.0 ] expected_cover_matrix = [ 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3488234877586365, 7.9185943603515625, 0.0029969215393066406, 1.0 ] expected_spine_par_inv_matrix = [ 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -10.0, 0.0, 0.0, 1.0 ] expected_front_cover_par_inv_matrix = [ -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.1716232898755894, 8.124592860140336, 0.0, 1.0 ] # Confirm attributes in the cache are correct book_attrs = cache.get_attrs_for_node(book_tfm) self.assertItemsEqual(book_attrs, ["worldMatrix[0]"]) attr_names_with_pivot = [ "worldMatrix[0]", "matrix", "parentInverseMatrix[0]", "rotatePivotX", "rotatePivotY", "rotatePivotZ", ] spine_attrs = cache.get_attrs_for_node(spine_tfm) self.assertItemsEqual(spine_attrs, attr_names_with_pivot) cover_attrs = cache.get_attrs_for_node(cover_tfm) self.assertItemsEqual(cover_attrs, attr_names_with_pivot) # Confirm matrix values in the cache are correct book_world_matrix = list( cache.get_node_attr(book_tfm, "worldMatrix[0]", frame_range)[0]) self.assertGreater( closeness.compare_floats(book_world_matrix, expected_book_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) spine_par_inv_matrix = list( cache.get_node_attr(spine_tfm, "parentInverseMatrix[0]", frame_range)[0]) self.assertGreater( closeness.compare_floats(spine_par_inv_matrix, expected_spine_par_inv_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) cover_par_inv_matrix = list( cache.get_node_attr(cover_tfm, "parentInverseMatrix[0]", frame_range)[0]) self.assertGreater( closeness.compare_floats(cover_par_inv_matrix, expected_front_cover_par_inv_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) # Compare destination node matrices with the original book_matrix = maya.cmds.xform(book_dst_node, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(book_matrix, expected_book_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) spine_matrix = maya.cmds.xform(spine_dst_node, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(spine_matrix, expected_spine_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) cover_matrix = maya.cmds.xform(cover_dst_node, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(cover_matrix, expected_cover_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) return
def test_get_transform_matrix_list_45degrees(self): path = self.get_data_path('scenes', 'bookHierarchy.ma') maya.cmds.file(path, open=True, force=True) book_node = 'book_GRP' spine_node = 'spine_GRP' cover_node = 'front_cover_GRP' latch_node = 'latch_GRP' maya.cmds.setAttr(book_node + '.ty', 10.0) maya.cmds.setAttr(book_node + '.rz', 45.0) # <<< 45 degrees maya.cmds.setAttr(spine_node + '.rz', 90.0) maya.cmds.setAttr(cover_node + '.rz', 90.0) book_tfm = mod.TransformNode(book_node) spine_tfm = mod.TransformNode(spine_node) cover_tfm = mod.TransformNode(cover_node) latch_tfm = mod.TransformNode(latch_node) tfm_nodes = [book_tfm, spine_tfm, cover_tfm, latch_tfm] current_frame = maya.cmds.currentTime(query=True) frame_range = [current_frame] # Query the transform matrix for the nodes cache = mod.TransformMatrixCache() for tfm_node in tfm_nodes: cache.add_node(tfm_node, frame_range) cache.process() book_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, book_tfm) self.assertEqual(len(book_world_matrix_list), 1) book_world_matrix = list(book_world_matrix_list[0].asMatrix()) spine_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, spine_tfm) self.assertEqual(len(spine_world_matrix_list), 1) spine_world_matrix = list(spine_world_matrix_list[0].asMatrix()) cover_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, cover_tfm) self.assertEqual(len(cover_world_matrix_list), 1) cover_world_matrix = list(cover_world_matrix_list[0].asMatrix()) latch_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, latch_tfm) self.assertEqual(len(latch_world_matrix_list), 1) latch_world_matrix = list(latch_world_matrix_list[0].asMatrix()) # Expected Matrices expected_book_matrix = [ 0.7071067811865475, 0.7071067811865476, 0.0, 0.0, -0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 10.0, 0.0, 1.0 ] expected_spine_matrix = [ -0.7071067811865475, 0.7071067811865477, 0.0, 0.0, -0.7071067811865477, -0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.8284631523833599, 8.673886585125107, 0.0029969215393066406, 1.0 ] expected_cover_matrix = [ -0.7071067811865479, -0.7071067811865474, 0.0, 0.0, 0.7071067811865474, -0.7071067811865479, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.2251205885640575, 8.281568504173393, 0.0029969215393066406, 1.0 ] expected_latch_matrix = [ 0.7071067811865475, 0.7071067811865476, 0.0, 0.0, -0.7071067811865476, 0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.417462229728698, 10.932249069213867, 0.0001980811357498169, 1.0 ] # Confirm matrix values in the cache are correct self.assertGreater( closeness.compare_floats(book_world_matrix, expected_book_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) tol = 0.000001 mat_a = OpenMaya2.MMatrix(book_world_matrix) mat_b = OpenMaya2.MMatrix(expected_book_matrix) self.assertTrue(mat_a.isEquivalent(mat_b, tol)) self.assertGreater( closeness.compare_floats(spine_world_matrix, expected_spine_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) mat_a = OpenMaya2.MMatrix(spine_world_matrix) mat_b = OpenMaya2.MMatrix(expected_spine_matrix) self.assertTrue(mat_a.isEquivalent(mat_b, tol)) self.assertGreater( closeness.compare_floats(cover_world_matrix, expected_cover_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) mat_a = OpenMaya2.MMatrix(cover_world_matrix) mat_b = OpenMaya2.MMatrix(expected_cover_matrix) self.assertTrue(mat_a.isEquivalent(mat_b, tol)) self.assertGreater( closeness.compare_floats(latch_world_matrix, expected_latch_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) mat_a = OpenMaya2.MMatrix(latch_world_matrix) mat_b = OpenMaya2.MMatrix(expected_latch_matrix) self.assertTrue(mat_a.isEquivalent(mat_b, tol)) return
def test_get_transform_matrix_list_90degrees(self): path = self.get_data_path('scenes', 'bookHierarchy.ma') maya.cmds.file(path, open=True, force=True) book_node = 'book_GRP' spine_node = 'spine_GRP' cover_node = 'front_cover_GRP' latch_node = 'latch_GRP' maya.cmds.setAttr(book_node + '.ty', 10.0) maya.cmds.setAttr(book_node + '.rz', 90.0) # <<< 90 degrees maya.cmds.setAttr(spine_node + '.rz', 90.0) maya.cmds.setAttr(cover_node + '.rz', 90.0) book_tfm = mod.TransformNode(book_node) spine_tfm = mod.TransformNode(spine_node) cover_tfm = mod.TransformNode(cover_node) latch_tfm = mod.TransformNode(latch_node) tfm_nodes = [book_tfm, spine_tfm, cover_tfm, latch_tfm] current_frame = maya.cmds.currentTime(query=True) frame_range = [current_frame] # Query the transform matrix for the nodes cache = mod.TransformMatrixCache() for tfm_node in tfm_nodes: cache.add_node(tfm_node, frame_range) cache.process() book_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, book_tfm) self.assertEqual(len(book_world_matrix_list), 1) book_world_matrix = list(book_world_matrix_list[0].asMatrix()) spine_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, spine_tfm) self.assertEqual(len(spine_world_matrix_list), 1) spine_world_matrix = list(spine_world_matrix_list[0].asMatrix()) cover_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, cover_tfm) self.assertEqual(len(cover_world_matrix_list), 1) cover_world_matrix = list(cover_world_matrix_list[0].asMatrix()) latch_world_matrix_list = mod.get_transform_matrix_list( cache, frame_range, latch_tfm) self.assertEqual(len(latch_world_matrix_list), 1) latch_world_matrix = list(latch_world_matrix_list[0].asMatrix()) # Expected Matrices expected_book_matrix = [ 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 10.0, 0.0, 1.0 ] expected_spine_matrix = [ -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3518918752670288, 8.476484298706055, 0.0029969215393066406, 1.0 ] expected_cover_matrix = [ 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3488234877586365, 7.9185943603515625, 0.0029969215393066406, 1.0 ] expected_latch_matrix = [ 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3430972993373871, 11.661497116088867, 0.0001980811357498169, 1.0 ] # Confirm matrix values in the cache are correct self.assertGreater( closeness.compare_floats(book_world_matrix, expected_book_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) self.assertGreater( closeness.compare_floats(spine_world_matrix, expected_spine_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) self.assertGreater( closeness.compare_floats(cover_world_matrix, expected_cover_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) self.assertGreater( closeness.compare_floats(latch_world_matrix, expected_latch_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS) return
def test_create_book(self): path = self.get_data_path('scenes', 'bookHierarchy.ma') maya.cmds.file(path, open=True, force=True) tfm_a = 'book_GRP' tfm_b = 'spine_GRP' tfm_c = 'front_cover_GRP' tfm_d = 'latch_GRP' maya.cmds.setAttr(tfm_a + '.ty', 10.0) maya.cmds.setAttr(tfm_a + '.rz', 90.0) maya.cmds.setAttr(tfm_b + '.rz', 90.0) maya.cmds.setAttr(tfm_c + '.rz', 90.0) # save the output path = self.get_data_path('controller_create_bookHierarchy_before.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) ctrls = lib.create([tfm_a, tfm_b, tfm_c, tfm_d]) # Note: the controls get re-ordered a little bit; they are not # in the same order as the input ctrl_a, ctrl_d, ctrl_b, ctrl_c = ctrls # save the output path = self.get_data_path('controller_create_bookHierarchy_after.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Expected Matrices expected_book_matrix = [ 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 10.0, 0.0, 1.0] expected_spine_matrix = [ -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3518918752670288, 8.476484298706055, 0.0029969215393066406, 1.0] expected_cover_matrix = [ 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3488234877586365, 7.9185943603515625, 0.0029969215393066406, 1.0] expected_latch_matrix = [ 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.3430972993373871, 11.661497116088867, 0.0001980811357498169, 1.0] book_matrix = maya.cmds.xform(ctrl_a, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(book_matrix, expected_book_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS ) spine_matrix = maya.cmds.xform(ctrl_b, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(spine_matrix, expected_spine_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS ) cover_matrix = maya.cmds.xform(ctrl_c, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(cover_matrix, expected_cover_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS ) latch_matrix = maya.cmds.xform(ctrl_d, query=True, matrix=True, worldSpace=True) self.assertGreater( closeness.compare_floats(latch_matrix, expected_latch_matrix), closeness.DEFAULT_SIGNIFICANT_DIGITS ) return