Example #1
0
def get_all_tag_children(node):
    """Gets all child tag controls from the given tag node

    Args:
        node (str): Name of controller object with tag

    Returns:
        list: List of child controls (Maya transform nodes)
    """

    # store child nodes
    children = []

    # gets first child control
    child = cmds.controller(node, query=True, children=True)

    # loop on child controller nodes to get all children
    while child is not None:
        children.extend(child)
        tags = []
        for c in child:
            tag = cmds.ls(cmds.listConnections(c, type="controller"))
            tags.extend(tag)
            if cmds.listConnections("{}.parent".format(tag[0])) == node:
                return children
        child = cmds.controller(tags, query=True, children=True)

    return children
Example #2
0
    def create(self, transform=None, as_controller=True):
        """Create a curve.

        :param transform: Name of the transform to create the curve shape under.
            If the transform does not exist, it will be created.
        :param as_controller: True to mark the curve transform as a controller.
        :return: The transform of the new curve shapes.
        """
        transform = transform or self.transform
        if not cmds.objExists(transform):
            transform = cmds.createNode("transform", name=transform)
        periodic = self.form == 2
        points = self._get_transformed_points()
        points = points + points[:self.degree] if periodic else points
        curve = cmds.curve(degree=self.degree,
                           p=points,
                           per=periodic,
                           k=self.knots)
        shape = shortcuts.get_shape(curve)
        if self.color is not None:
            cmds.setAttr("{}.overrideEnabled".format(shape), True)
            if isinstance(self.color, int):
                cmds.setAttr("{}.overrideColor".format(shape), self.color)
            else:
                cmds.setAttr("{}.overrideRGBColors".format(shape), True)
                cmds.setAttr("{}.overrideColorRGB".format(shape), *self.color)
        cmds.parent(shape, transform, r=True, s=True)
        shape = cmds.rename(shape, "{}Shape".format(transform))
        cmds.delete(curve)
        if as_controller:
            cmds.controller(transform)
        logger.info("Created curve {} for transform {}".format(
            shape, transform))
        return transform
Example #3
0
def mirror_curve(source, destination):
    """Mirrors the curve on source across the YZ plane to destination.

    The cvs will be mirrored in world space no matter the transform of destination.

    :param source: Source transform
    :param destination: Destination transform
    :return: The mirrored CurveShape object
    """
    source_curve = CurveShape(source)

    path_source = shortcuts.get_dag_path2(source)
    matrix = path_source.inclusiveMatrix()

    path_destination = shortcuts.get_dag_path2(destination)
    inverse_matrix = path_destination.inclusiveMatrixInverse()

    world_cvs = [OpenMaya.MPoint(*x) * matrix for x in source_curve.cvs]
    for cv in world_cvs:
        cv.x *= -1
    local_cvs = [p * inverse_matrix for p in world_cvs]
    source_curve.cvs = [(p.x, p.y, p.z) for p in local_cvs]
    is_controller = cmds.controller(source, q=True, isController=True)
    source_curve.transform = destination
    source_curve.create(destination, as_controller=is_controller)
    return source_curve
Example #4
0
def setUp(params, spec):
    """Special method used to intialize a `TaskSpec` instance of this `TaskFactory`.

    Args:
        params: These are the parameters for this `RigSpec` instance, get/set just like dictionary calls
        spec: The `TaskSpec` object that this method runs from, this gives you access to the entire class instance

    Returns:
        None
    """

    if not params['fkSkeleton']:
        joints = []

        for x in range(params['numberOfSegments']):
            jnt = cmds.createNode('joint')
            jnt = cmds.rename(
                jnt, '{baseName}{index}_{JNT}'.format(baseName=spec.name,
                                                      index=x,
                                                      JNT=JNT)).split('|')[-1]
            if x > 0:
                cmds.parent(jnt, joints[x - 1])
                cmds.setAttr('{node}.translateY'.format(node=jnt), 1.0)
            joints.append(jnt)

        spec.params()['fkSkeleton'] = dragonfly.node.dfNode.fromList(joints)

    if not params['fkControls']:
        controls = []

        for x in range(params['fkNumberOfSegments']):
            ctl = cmds.curve(**CONTROL_SHAPE_DATA)
            cmds.controller(ctl)
            ctl = cmds.rename(
                ctl, '{baseName}{index}_{CTL}'.format(baseName=spec.name,
                                                      index=x,
                                                      CTL=CTL))
            match_nodes(params['fkSkeleton'][x].name(), ctl)
            if x > 0:
                cmds.parent(ctl, controls[x - 1])
            controls.append(ctl)

        spec.params()['fkControls'] = dragonfly.node.dfNode.fromList(controls)
Example #5
0
 def select_by_type(self):
     ls = list()
     for item in string_to_list(self.select_by_type_line_edit.text()):
         if item == 'controller':
             ls += cmds.controller(q=True, allControllers=True) or list()
         else:
             ls += cmds.ls(type=item) or list()
     if not ls:
         return
     self.select(ls)
Example #6
0
def setUp(params, spec):
    """Special method used to intialize a `TaskSpec` instance of this `TaskFactory`.

    Args:
        params: These are the parameters for this `RigSpec` instance, get/set just like dictionary calls
        spec: The `TaskSpec` object that this method runs from, this gives you access to the entire class instance

    Returns:
        None
    """
    baseName = params['baseName']

    if not params['sineControl']:
        sineCtl = create_curve(SINE_CONTROL_SHAPE_DATA)
        sineCtl = cmds.rename(sineCtl, "{}_{}".format(baseName, CTL))
        spec.params()['sineControl'] = dragonfly.node.dfNode.fromName(sineCtl)

    if not params['skeleton']:
        joints = []

        for x in range(params['numberOfSegments']):
            jnt = cmds.createNode('joint')
            jnt = cmds.rename(jnt, '{}{index}_jnt'.format(baseName, index=x)).split('|')[-1]
            if x > 0:
                cmds.parent(jnt, joints[x - 1])
                cmds.setAttr('{node}.translateZ'.format(node=jnt), -2.0)
            joints.append(jnt)

        spec.params()['skeleton'] = [[x, dragonfly.modules.get_uuid(x)] for x in joints]

    if not params['controls']:
        controls = []

        for x in range(params['numberOfSegments']):
            ctl = cmds.curve(**CONTROL_SHAPE_DATA)
            cmds.controller(ctl)
            ctl = cmds.rename(ctl, '{}{index}_ctl'.format(baseName, index=x))
            match_nodes((params['skeleton'][x])[0], ctl)
            if x > 0:
                cmds.parent(ctl, controls[x-1])
            controls.append(ctl)

        spec.params()['controls'] = [[x, dragonfly.modules.get_uuid(x)] for x in controls]
Example #7
0
    def __init__(self, 
                 name,
                 role=None, 
                 descriptor=None, 
                 region=None, 
                 side=None):
  
        super(Control, self).__init__(name,
                                      node_type=self.NODETYPE, 
                                      role=role, 
                                      descriptor=descriptor, 
                                      region=region, 
                                      side=side)
        
        # Try to populate naming properties
        if not any([role, descriptor, region, side]):
            self.decompose_name()

        # Tag object as controller
        if not cmds.controller(query=True, isController=True):
            cmds.controller(name)
Example #8
0
def get_all_tag_children(node):
    """Gets all child tag controls from the given tag node

    Args:
        node (dagNode): Controller object with tag

    Returns:
        list: List of child controls (Maya transform nodes)
    """

    # store child nodes
    children = []

    # gets first child control
    child = cmds.controller(node, query=True, children=True)

    # loop on child controller nodes to get all children
    while child is not None:
        children.extend(child)
        tag = cmds.ls(cmds.listConnections(child[0], type="controller"))
        child = cmds.controller(tag, query=True, children=True)

    return children
Example #9
0
def controller(*args, **kwargs):
    res = cmds.controller(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res