コード例 #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_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
コード例 #4
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
コード例 #5
0
ファイル: tool.py プロジェクト: whigg/mayaMatchMoveSolver
def remove():
    """
    Remove selected controllers and bake data on controlled nodes.
    """
    nodes = maya.cmds.ls(selection=True, long=True) or []
    orig_nodes = lib.remove(nodes)
    if len(orig_nodes) > 0:
        maya.cmds.select(orig_nodes, 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
コード例 #6
0
def remove():
    """
    Remove selected controllers and bake data on controlled 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):
        orig_nodes = lib.remove(nodes)
        if len(orig_nodes) > 0:
            maya.cmds.select(orig_nodes, replace=True)

    # Trigger Maya to refresh.
    maya.cmds.refresh(currentView=True, force=False)
    return
コード例 #7
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
コード例 #8
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
コード例 #9
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
コード例 #10
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