Exemplo n.º 1
0
    def test_set_marker_group(self):
        x = marker.Marker().create_node()
        mkr_grp1 = x.get_marker_group()
        self.assertEqual(mkr_grp1, None)

        cam = self.create_camera('myCamera1')
        mkr_grp2 = markergroup.MarkerGroup().create_node(cam=cam)
        mkr_grp3 = markergroup.MarkerGroup().create_node(cam=cam)

        x = marker.Marker().create_node()

        # Set mkr_grp2 as marker group.
        x.set_marker_group(mkr_grp2)
        mkr_grp4 = x.get_marker_group()
        self.assertIsInstance(mkr_grp4, markergroup.MarkerGroup)
        self.assertEqual(mkr_grp2.get_node(), mkr_grp4.get_node())

        # Set mkr_grp3 as marker group.
        x.set_marker_group(mkr_grp3)
        mkr_grp5 = x.get_marker_group()
        self.assertIsInstance(mkr_grp5, markergroup.MarkerGroup)
        self.assertEqual(mkr_grp3.get_node(), mkr_grp5.get_node())

        # Unlink marker from marker group (detach to world).
        x.set_marker_group(None)
        mkr_grp6 = x.get_marker_group()
        self.assertIs(mkr_grp6, None)
        self.assertEqual(mkr_grp6, None)
Exemplo n.º 2
0
    def test_get_marker_list(self):
        x = collection.Collection()
        x.create_node('mySolve')

        self.assertEqual(x.get_marker_list_length(), 0)

        node = maya.cmds.createNode('transform')
        mkr1 = marker.Marker().create_node()
        mkr2 = marker.Marker().create_node()
        attr1 = attribute.Attribute(node=node, attr='translateX')
        attr2 = attribute.Attribute(node=node, attr='translateY')
        attr3 = attribute.Attribute(node=node, attr='translateZ')
        attr4 = attribute.Attribute(node=node, attr='rotateX')
        attr5 = attribute.Attribute(node=node, attr='rotateY')
        attr6 = attribute.Attribute(node=node, attr='rotateZ')
        x.add_marker(mkr1)
        x.add_marker(mkr2)
        x.add_attribute(attr1)
        x.add_attribute(attr2)
        x.add_attribute(attr3)
        x.add_attribute(attr4)
        x.add_attribute(attr5)
        x.add_attribute(attr6)

        self.assertEqual(x.get_marker_list_length(), 2)
Exemplo n.º 3
0
    def test_set_marker_list(self):
        x = collection.Collection()
        x.create_node('mySolve')

        attr_list = []
        mkr_list = []
        mkr1 = marker.Marker().create_node()
        mkr_list.append(mkr1)
        for i in xrange(10):
            mkr = marker.Marker().create_node()
            mkr_list.append(mkr)

            node = maya.cmds.createNode('transform')
            attr = attribute.Attribute(node=node, attr='translateZ')
            attr_list.append(attr)

        x.set_marker_list(mkr_list)
        x.set_attribute_list(mkr_list)
        self.assertEqual(x.get_marker_list_length(), 11)

        mkr_list = [mkr1]
        x.set_marker_list(mkr_list)
        self.assertEqual(x.get_marker_list_length(), 1)

        mkr_list = x.get_marker_list()
        self.assertEqual(mkr1.get_node(), mkr_list[0].get_node())
Exemplo n.º 4
0
    def test_get_node(self):
        name = 'myMarker1'
        x = marker.Marker().create_node(name=name)
        node = x.get_node()
        self.assertIsInstance(node, (str, unicode))
        self.assertIn(name, node)
        self.assertEqual(node, '|myMarker1')

        y = marker.Marker()
        self.assertEqual(y.get_node(), None)
Exemplo n.º 5
0
    def test_init(self):
        x = marker.Marker()
        x.create_node()
        x_node = x.get_node()
        self.assertTrue(maya.cmds.objExists(x_node))

        y = marker.Marker(x_node)
        y_node = y.get_node()
        self.assertEqual(x_node, y_node)

        z = marker.Marker(node=x_node)
        z_node = z.get_node()
        self.assertEqual(x_node, z_node)
Exemplo n.º 6
0
    def test_get_camera(self):
        x = marker.Marker().create_node()
        mkr_cam = x.get_camera()
        self.assertEqual(mkr_cam, None)

        cam = self.create_camera('myCamera1')
        cam_tfm = cam.get_transform_node()
        cam_shp = cam.get_shape_node()

        y = marker.Marker().create_node(cam=cam)
        mkr_cam = y.get_camera()
        self.assertIsInstance(mkr_cam, camera.Camera)
        self.assertEqual(mkr_cam.get_transform_node(), cam_tfm)
        self.assertEqual(mkr_cam.get_shape_node(), cam_shp)
Exemplo n.º 7
0
def get_bundle_nodes_from_marker_nodes(nodes):
    """
    Convert Marker nodes into Bundle nodes.

    :param nodes: Maya nodes to convert into Bundles (expected to be
                  Marker nodes, but other node types will not cause
                  errors).
    :type nodes: [str, ..]

    :returns: All Maya nodes connected to Marker nodes as Bundles.
    :rtype: [str, ..]
    """
    mkr_nodes = nodefilter.filter_marker_nodes(nodes)
    bnd_nodes = []
    for mkr_node in mkr_nodes:
        mkr = marker.Marker(mkr_node)
        bnd = mkr.get_bundle()
        if bnd is None:
            continue
        bnd_node = bnd.get_node()
        if bnd_node is None:
            continue
        if bnd_node not in bnd_nodes:
            bnd_nodes.append(bnd_node)
    return bnd_nodes
Exemplo n.º 8
0
    def test_is_valid(self):
        """
        Collection validation.
        Once all pieces are connected, the collection is valid.
        """
        x = collection.Collection()
        x.create_node('myCollection')
        self.assertFalse(x.is_valid())

        # Solver
        sol = solver.Solver()
        x.add_solver(sol)
        self.assertFalse(x.is_valid())

        # Solver (with frame)
        f = frame.Frame(1)
        sol.add_frame(f)
        self.assertFalse(x.is_valid())

        # Marker / Bundle
        cam_tfm = maya.cmds.createNode('transform', name='camera1')
        cam_shp = maya.cmds.createNode('camera', name='cameraShape1')
        cam = camera.Camera(shape=cam_shp)
        bnd = bundle.Bundle().create_node()
        mkr = marker.Marker().create_node(cam=cam, bnd=bnd)
        x.add_marker(mkr)
        self.assertFalse(x.is_valid())

        # Attribute
        node = bnd.get_node()
        attr = attribute.Attribute(node=node, attr='translateX')
        x.add_attribute(attr)
        self.assertTrue(x.is_valid())
Exemplo n.º 9
0
    def test_get_marker_list_length(self):
        x = collection.Collection()
        x.create_node('mySolve')
        self.assertEqual(x.get_marker_list_length(), 0)

        mkr = marker.Marker().create_node()
        x.add_marker(mkr)
        self.assertEqual(x.get_marker_list_length(), 1)
Exemplo n.º 10
0
 def get_marker_list(self):
     result = []
     members = self._set.get_all_members(flatten=False, full_path=True)
     for member in members:
         object_type = api_utils.get_object_type(member)
         if object_type == const.OBJECT_TYPE_MARKER:
             mkr = marker.Marker(member)
             result.append(mkr)
     return result
Exemplo n.º 11
0
    def test_get_marker_group(self):
        x = marker.Marker().create_node()
        mkr_grp = x.get_marker_group()
        self.assertEqual(mkr_grp, None)

        cam = self.create_camera('myCamera1')
        mkr_grp1 = markergroup.MarkerGroup().create_node(cam=cam)
        mkr_grp2 = markergroup.MarkerGroup().create_node(cam=cam)

        x = marker.Marker().create_node(mkr_grp=mkr_grp1)
        mkr_grp3 = x.get_marker_group()
        self.assertIsInstance(mkr_grp3, markergroup.MarkerGroup)
        self.assertEqual(mkr_grp1.get_node(), mkr_grp3.get_node())

        x.set_marker_group(mkr_grp2)
        mkr_grp4 = x.get_marker_group()
        self.assertIsInstance(mkr_grp4, markergroup.MarkerGroup)
        self.assertEqual(mkr_grp2.get_node(), mkr_grp4.get_node())
Exemplo n.º 12
0
    def test_get_bundle(self):
        x = marker.Marker().create_node()
        bnd0 = x.get_bundle()
        self.assertEqual(bnd0, None)

        bnd1 = bundle.Bundle().create_node()
        x.set_bundle(bnd1)

        bnd2 = x.get_bundle()
        self.assertEqual(bnd1.get_node(), bnd2.get_node())
Exemplo n.º 13
0
    def test_get_marker_list(self):
        x = bundle.Bundle().create_node(name='myBundle1')
        mkr_list1 = x.get_marker_list()
        self.assertEqual(len(mkr_list1), 0)

        for i in xrange(10):
            mkr = marker.Marker().create_node()
            mkr.set_bundle(x)
        mkr_list2 = x.get_marker_list()
        self.assertEqual(len(mkr_list2), 10)
Exemplo n.º 14
0
    def test_set_colour_rgb(self):
        """
        Set wireframe colour of the marker.
        """
        red = (1.0, 0.0, 0.0)
        green = (0.0, 1.0, 0.0)
        blue = (0.0, 0.0, 1.0)

        x = marker.Marker()
        x_rgb = x.get_colour_rgb()
        self.assertEqual(x_rgb, None)

        # Create nodes
        y = marker.Marker().create_node(name='myMarker1')
        y_rgb = y.get_colour_rgb()
        self.assertEqual(y_rgb, red)

        y.set_colour_rgb(blue)
        y_rgb = y.get_colour_rgb()
        self.assertEqual(y_rgb, blue)
        return
Exemplo n.º 15
0
    def test_get_object_type(self):
        """
        Test getting string object types from a given Maya node.

        TODO: Does not provide a 'collection' example.
        """
        # Camera Type
        cam_tfm = maya.cmds.createNode('transform')
        cam_tfm = node_utils.get_long_name(cam_tfm)
        cam_shp = maya.cmds.createNode('camera', parent=cam_tfm)
        cam_shp = node_utils.get_long_name(cam_shp)
        tfm_obj_type = api_utils.get_object_type(cam_tfm)
        shp_obj_type = api_utils.get_object_type(cam_shp)
        self.assertEqual(tfm_obj_type, const.OBJECT_TYPE_CAMERA)
        self.assertEqual(shp_obj_type, const.OBJECT_TYPE_CAMERA)

        # Marker Type
        mkr = marker.Marker().create_node()
        mkr_node = mkr.get_node()
        obj_type = api_utils.get_object_type(mkr_node)
        self.assertEqual(obj_type, const.OBJECT_TYPE_MARKER)

        # Marker shape node must also return as OBJECT_TYPE_MARKER
        mkr_shp_node = maya.cmds.listRelatives(mkr_node, shapes=True)[0]
        obj_type = api_utils.get_object_type(mkr_shp_node)
        self.assertEqual(obj_type, const.OBJECT_TYPE_UNKNOWN)

        # Marker Group
        node = maya.cmds.createNode('mmMarkerGroupTransform')
        obj_type = api_utils.get_object_type(node)
        self.assertEqual(obj_type, const.OBJECT_TYPE_MARKER_GROUP)

        # A Bundle must be more than just a transform and locator.
        # Use mmSolver.api.Bundle.create_node() to create a Bundle.
        #
        # GitHub Issue #6.
        bnd_node = maya.cmds.createNode('transform')
        bnd_shp_node = maya.cmds.createNode('locator', parent=bnd_node)
        obj_type = api_utils.get_object_type(bnd_node)
        self.assertEqual(obj_type, const.OBJECT_TYPE_UNKNOWN)

        # Giving a shape will not work.
        obj_type = api_utils.get_object_type(bnd_shp_node)
        self.assertEqual(obj_type, const.OBJECT_TYPE_UNKNOWN)

        # Attribute Type
        node_attr = node + '.scaleX'
        obj_type = api_utils.get_object_type(node_attr)
        self.assertEqual(obj_type, const.OBJECT_TYPE_ATTRIBUTE)
Exemplo n.º 16
0
    def test_set_bundle(self):
        x = marker.Marker().create_node()
        bnd0 = x.get_bundle()
        self.assertEqual(bnd0, None)

        bnd1 = bundle.Bundle().create_node()
        x.set_bundle(bnd1)  # link marker to bundle

        bnd2 = x.get_bundle()
        self.assertEqual(bnd1.get_node(), bnd2.get_node())

        x.set_bundle(None)  # unlink bundle from marker
        bnd3 = x.get_bundle()
        self.assertEqual(bnd3, None)
        self.assertNotEqual(bnd1.get_node(), bnd3)
Exemplo n.º 17
0
    def test_add_marker(self):
        x = collection.Collection()
        x.create_node('mySolve')

        name = 'myMarker1'
        mkr = marker.Marker().create_node(name=name)
        x.add_marker(mkr)

        mkr_list = x.get_marker_list()
        n2 = len(mkr_list)
        self.assertEqual(n2, 1)
        self.assertIsInstance(mkr_list[0], marker.Marker)
        self.assertIsNot(mkr, mkr_list[0])  # objects are not the same memory.
        self.assertIn(name, mkr.get_node())
        self.assertEqual(mkr.get_node(), mkr_list[0].get_node())  # same node
Exemplo n.º 18
0
    def test_set_camera(self):
        cam = self.create_camera('myCamera1')
        cam_tfm = cam.get_transform_node()
        cam_shp = cam.get_shape_node()

        x = marker.Marker().create_node()
        x.set_camera(cam)

        # Get the camera and test
        mkr_cam = x.get_camera()
        self.assertIsInstance(mkr_cam, camera.Camera)
        self.assertEqual(mkr_cam.get_transform_node(), cam_tfm)
        self.assertEqual(mkr_cam.get_shape_node(), cam_shp)

        # Unlink marker from camera.
        x.set_camera(None)
        mkr_cam = x.get_camera()
        self.assertEqual(mkr_cam, None)
Exemplo n.º 19
0
    def test_delete_node(self):
        x = marker.Marker().create_node()
        node1 = x.get_node()
        self.assertIsInstance(node1, (str, unicode))
        self.assertTrue(maya.cmds.objExists(node1))

        x.delete_node()

        node2 = x.get_node()
        self.assertEqual(node2, None)
        self.assertFalse(maya.cmds.objExists(node1))

        maya.cmds.undo()  # undo delete_node
        node3 = x.get_node()
        self.assertIsInstance(node3, (str, unicode))
        self.assertTrue(maya.cmds.objExists(node1))
        self.assertTrue(maya.cmds.objExists(node3))
        self.assertEqual(node1, node3)
Exemplo n.º 20
0
    def test_remove_marker(self):
        x = collection.Collection()
        x.create_node('mySolve')

        name = 'myMarker1'
        mkr = marker.Marker().create_node(name=name)
        x.add_marker(mkr)

        mkr_list = x.get_marker_list()
        n1 = len(mkr_list)
        self.assertEqual(n1, 1)
        self.assertIsInstance(mkr_list[0], marker.Marker)
        self.assertIn(name, mkr.get_node())
        self.assertEqual(mkr.get_node(), mkr_list[0].get_node())

        x.remove_marker(mkr)
        mkr_list = x.get_marker_list()
        n2 = len(mkr_list)
        self.assertEqual(n2, 0)
Exemplo n.º 21
0
    def test_create_node(self):
        # TODO: Add undo/redo tests.
        x = marker.Marker()
        x.create_node()
        node = x.get_node()
        self.assertIsInstance(node, (str, unicode))
        self.assertTrue(maya.cmds.objExists(node))

        x = marker.Marker().create_node()
        node = x.get_node()
        self.assertIsInstance(node, (str, unicode))
        self.assertTrue(maya.cmds.objExists(node))

        name = 'myMarker1'
        x = marker.Marker().create_node(name=name)
        node = x.get_node()
        self.assertTrue(maya.cmds.objExists(node))
        self.assertEqual(x.get_camera(), None)

        cam = self.create_camera('myCamera1')
        cam_tfm = cam.get_transform_node()
        cam_shp = cam.get_shape_node()

        # Create marker linked to camera
        x = marker.Marker().create_node(name=name, cam=cam)
        node = x.get_node()
        mkr_cam = x.get_camera()
        self.assertTrue(maya.cmds.objExists(node))
        self.assertEqual(mkr_cam.get_shape_node(), cam_shp)

        # Create a Bundle.
        bnd = bundle.Bundle().create_node()
        bnd_node = bnd.get_node()

        # Create marker linked to bundle
        x = marker.Marker().create_node(name=name, bnd=bnd)
        node = x.get_node()
        mkr_bnd = x.get_bundle()
        self.assertTrue(maya.cmds.objExists(node))
        self.assertEqual(mkr_bnd.get_node(), bnd_node)

        # Create marker linked to camera and bundle
        x = marker.Marker().create_node(name=name, cam=cam, bnd=bnd)
        node = x.get_node()
        self.assertTrue(maya.cmds.objExists(node))
        mkr_cam = x.get_camera()
        mkr_bnd = x.get_bundle()
        self.assertEqual(mkr_cam.get_shape_node(), cam_shp)
        self.assertEqual(mkr_bnd.get_node(), bnd_node)
Exemplo n.º 22
0
    def test_remove_marker_list(self):
        x = collection.Collection()
        x.create_node('mySolve')

        name = 'myMarker1'
        mkr_list = []
        for i in xrange(10):
            mkr = marker.Marker().create_node(name=name)
            mkr_list.append(mkr)
        x.add_marker_list(mkr_list)

        self.assertEqual(x.get_marker_list_length(), 10)

        # remove the first half
        x.remove_marker_list(mkr_list[:5])

        self.assertEqual(x.get_marker_list_length(), 5)

        # remove the second half
        x.remove_marker_list(mkr_list[4:])

        self.assertEqual(x.get_marker_list_length(), 0)
Exemplo n.º 23
0
    def test_add_marker_list(self):
        x = collection.Collection()
        x.create_node('mySolve')

        x.add_marker_list([])

        name = 'myMarker1'
        mkr_list = []
        for i in xrange(10):
            mkr = marker.Marker().create_node(name=name)
            mkr_list.append(mkr)
        x.add_marker_list(mkr_list)

        mkr_list2 = x.get_marker_list()
        self.assertEqual(len(mkr_list2), 10)

        node_list = []
        for mkr in mkr_list:
            node_list.append(mkr.get_node())
        for mkr in mkr_list2:
            node = mkr.get_node()
            self.assertIn(node, node_list)
Exemplo n.º 24
0
def get_camera_nodes_from_marker_nodes(nodes):
    """
    Get the list of Camera nodes that are 'connected' to the markers nodes.

    :param nodes: Marker nodes.
    :type nodes: [str, ..]

    :returns: A list of camera transform and shape tuples.
    :rtype: [(str, str), ..]
    """
    mkr_nodes = nodefilter.filter_marker_nodes(nodes)
    cam_nodes = []
    cam_nodes_tmp = {}
    for mkr_node in mkr_nodes:
        mkr = marker.Marker(mkr_node)
        cam = mkr.get_camera()
        cam_tfm_node = cam.get_transform_node()
        cam_shp_node = cam.get_shape_node()
        if cam_shp_node not in cam_nodes_tmp:
            cam_nodes_tmp[cam_shp_node] = (cam_tfm_node, cam_shp_node)
    for key, value in cam_nodes_tmp.iteritems():
        cam_nodes.append(value)
    return cam_nodes
Exemplo n.º 25
0
 def test_set_node(self):
     x = marker.Marker().create_node()
     y = marker.Marker()
     y.set_node(x.get_node())
     self.assertEqual(x.get_node(), y.get_node())
     self.assertRaises(RuntimeError, y.set_node, 'myUnknownNode1')