示例#1
0
    def test_remove_sparse_four(self):
        """
        Transform node in a hierarchy.
        """
        start = 1
        end = 100
        tfm_a, tfm_b = self.create_hierachy_scene(start, end)

        ctrls = lib.create([tfm_a, tfm_b], sparse=True)
        ctrl_a, ctrl_b = ctrls

        child_a = maya.cmds.createNode('transform', parent=ctrl_a)
        child_b = maya.cmds.createNode('transform', parent=ctrl_b)

        lib.remove(ctrls, sparse=True)

        # save the output
        path = self.get_data_path(
            'controller_remove_sparse_hierarchy_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        # self.assertEqual(maya.cmds.getAttr(ctrl + '.translateX', time=start), 20.0)
        # self.assertEqual(maya.cmds.getAttr(ctrl + '.translateY', time=start), 30.0)
        # self.assertEqual(maya.cmds.getAttr(ctrl + '.translateZ', time=start), 10.0)
        return
示例#2
0
    def test_remove_hierarchy_with_pivot(self):
        name = 'controller_hierarchy_with_pivot_point_changed.ma'
        path = self.get_data_path('scenes', name)
        maya.cmds.file(path, open=True, force=True)

        base_node = 'group'
        node = 'node'
        ctrls = lib.create([node], sparse=True)
        ctrl = ctrls[0]

        maya.cmds.setAttr(ctrl + '.rz', 45.0)

        nodes = lib.remove(ctrls, sparse=True)

        # save the output
        name = 'controller_remove_hierarchy_with_pivot_point_changed_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        node = nodes[0]
        tx = maya.cmds.getAttr(node + '.translateX')
        ty = maya.cmds.getAttr(node + '.translateY')
        tz = maya.cmds.getAttr(node + '.translateZ')
        self.assertTrue(self.approx_equal(tx, 0))
        self.assertTrue(self.approx_equal(ty, 0))
        self.assertTrue(self.approx_equal(tz, 0))

        rx = maya.cmds.getAttr(node + '.rotateX')
        ry = maya.cmds.getAttr(node + '.rotateY')
        rz = maya.cmds.getAttr(node + '.rotateZ')
        self.assertTrue(self.approx_equal(rx, 0.0))
        self.assertTrue(self.approx_equal(ry, 0.0))
        self.assertTrue(self.approx_equal(rz, 45.0))
        return
示例#3
0
    def test_create_dense_three(self):
        """
        Transform node with three keyframes.
        """
        start = 1
        mid = 25
        end = 100
        tfm = self.create_multi_keyframe_scene(start, mid, end)

        ctrls = lib.create([tfm], sparse=False)
        ctrl = ctrls[0]

        # save the output
        path = self.get_data_path(
            'controller_create_dense_three_keyframes_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.assertEqual(maya.cmds.getAttr(tfm + '.translateX', time=mid),
                         20.0)
        self.assertEqual(maya.cmds.getAttr(tfm + '.translateY', time=mid),
                         30.0)
        self.assertEqual(maya.cmds.getAttr(tfm + '.translateZ', time=mid),
                         10.0)

        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateX', time=mid),
                         20.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateY', time=mid),
                         30.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateZ', time=mid),
                         10.0)
        self.approx_equal(maya.cmds.getAttr(ctrl + '.rotateY', time=mid),
                          19.545454545454547)
        return
示例#4
0
def create():
    """
    Create a controller for selected nodes.
    """
    nodes = maya.cmds.ls(selection=True, long=True) or []
    ctrls = lib.create(nodes, sparse=True)
    if len(ctrls) > 0:
        maya.cmds.select(ctrls, replace=True)
    # Trigger Maya to refresh.
    frame = maya.cmds.currentTime(query=True)
    maya.cmds.currentTime(frame, update=True)
    maya.cmds.refresh(currentView=True, force=False)
    return
示例#5
0
    def test_create_dense_two(self):
        """
        Transform node with a single keyframe.
        """
        tfm = self.create_one_keyframe_scene()
        ctrls = lib.create([tfm], sparse=False)
        ctrl = ctrls[0]

        # save the output
        path = self.get_data_path('controller_create_dense_one_keyframe.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateX'), 10.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateY'), 20.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateZ'), 30.0)
        return
示例#6
0
def create():
    """
    Create a controller for selected nodes.
    """
    nodes = maya.cmds.ls(selection=True, long=True) or []
    with tools_utils.tool_context(use_undo_chunk=True,
                                  pre_update_frame=True,
                                  post_update_frame=True,
                                  restore_current_frame=True,
                                  use_dg_evaluation_mode=True,
                                  disable_viewport=True):
        ctrls = lib.create(nodes)
        if len(ctrls) > 0:
            maya.cmds.select(ctrls, replace=True)

    # Trigger Maya to refresh.
    maya.cmds.refresh(currentView=True, force=False)
    return
示例#7
0
    def test_create_dense_one(self):
        """
        Transform node with no keyframes.
        """
        tfm = self.create_no_keyframe_scene()
        ctrls = lib.create([tfm], sparse=False)
        ctrl = ctrls[0]

        maya.cmds.setAttr(ctrl + '.ty', 42.0)

        # save the output
        name = 'controller_create_dense_no_keyframes_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateX'), 10.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateY'), 42.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateZ'), 30.0)
        return
示例#8
0
    def test_create_one_with_pivot(self):
        """
        Transform node with no keyframes, with pivot point changed.
        """
        tfm = self.create_no_keyframe_scene_with_pivot()
        ctrls = lib.create([tfm])
        ctrl = ctrls[0]

        maya.cmds.setAttr(ctrl + '.ty', 42.0)

        # save the output
        name = 'controller_create_no_keyframes_with_pivot_after.ma'
        path = self.get_data_path(name)
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateX'), 0.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateY'), 42.0)
        self.assertEqual(maya.cmds.getAttr(ctrl + '.translateZ'), 00.0)
        return
示例#9
0
    def test_remove_two(self):
        """
        Transform node with a single keyframe.
        """
        tfm = self.create_one_keyframe_scene()
        ctrls = lib.create([tfm])
        ctrl = ctrls[0]

        maya.cmds.setKeyframe(ctrl, attribute='translateY', value=42.0)

        nodes = lib.remove(ctrls)

        # save the output
        path = self.get_data_path('controller_remove_one_keyframe_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        node = nodes[0]
        self.assertEqual(maya.cmds.getAttr(node + '.translateY'), 42.0)
        return
示例#10
0
    def test_remove_four(self):
        """
        Transform node in a hierarchy.
        """
        start = 1
        end = 100
        tfm_a, tfm_b = self.create_hierarchy_scene(start, end)

        ctrls = lib.create([tfm_a, tfm_b])
        ctrl_a, ctrl_b = ctrls

        child_a = maya.cmds.createNode('transform', parent=ctrl_a)
        child_b = maya.cmds.createNode('transform', parent=ctrl_b)

        lib.remove(ctrls)

        # save the output
        path = self.get_data_path('controller_remove_hierarchy_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)
        return
示例#11
0
    def test_remove_seven(self):
        """
        Create and destroy controllers on a hierarchy of transforms.
        """
        path = self.get_data_path('scenes', 'objectHierarchy.ma')
        maya.cmds.file(path, open=True, force=True)

        tfm_a = 'group1'
        tfm_b = 'pSphere1'
        tfm_c = 'pSphere2'

        ctrls = lib.create([tfm_a, tfm_b, tfm_c])
        ctrl_a, ctrl_b, ctrl_c = ctrls

        # save the output
        path = self.get_data_path('controller_remove_hierarchyOfControls_before.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        # Ensure the hierarchy is correct.
        ctrl_a_children = maya.cmds.listRelatives(
            ctrl_a,
            children=True,
            fullPath=True,
            type='transform') or []
        ctrl_b_children = maya.cmds.listRelatives(
            ctrl_b,
            children=True,
            fullPath=True,
            type='transform') or []
        self.assertIn(ctrl_b, ctrl_a_children)
        self.assertIn(ctrl_c, ctrl_b_children)

        lib.remove([ctrl_a, ctrl_b, ctrl_c])

        # save the output
        path = self.get_data_path('controller_remove_hierarchyOfControls_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)
        return
示例#12
0
    def test_remove_one(self):
        """
        Transform node with no keyframes.
        """
        tfm = self.create_no_keyframe_scene()
        ctrls = lib.create([tfm])
        ctrl = ctrls[0]

        maya.cmds.setAttr(ctrl + '.ty', 42.0)

        nodes = lib.remove(ctrls)

        # save the output
        path = self.get_data_path('controller_remove_no_keyframes_after.ma')
        maya.cmds.file(rename=path)
        maya.cmds.file(save=True, type='mayaAscii', force=True)

        node = nodes[0]
        self.assertEqual(maya.cmds.getAttr(node + '.translateX'), 10.0)
        self.assertEqual(maya.cmds.getAttr(node + '.translateY'), 42.0)
        self.assertEqual(maya.cmds.getAttr(node + '.translateZ'), 30.0)
        return
示例#13
0
    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
示例#14
0
    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
示例#15
0
    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