예제 #1
0
    def setPosition(self, position, cvs=False, space=None, useParent=True):
        """Sets the translation component of this control, if cvs is True then translate the cvs instead

        :param position: The MVector that represent the position based on the space given.
        :type position: MVector
        :param cvs: If true then the MVector will be applied to all cvs
        :type cvs: bool
        :param space: the space to work on eg.MSpace.kObject or MSpace.kWorld
        :type space: int
        """
        space = space or om2.MSpace.kTransform
        if self.dagPath is None:
            return
        if cvs:
            shapes = nodes.childPaths(self.dagPath)
            for i in shapes:
                cvsPositions = nodes.cvPositions(i, space=space)
                newPositions = om2.MPointArray()
                for pnt in cvsPositions:
                    newPositions.append(
                        om2.MPoint(pnt.x * position.x, pnt.y * position.y,
                                   pnt.z * position.z))
                nodes.setCurvePositions(i, newPositions, space=space)
        if useParent:
            parent = nodes.getParent(self.dagPath.node())
            if parent:
                nodes.setTranslation(parent, position, space)
                return
        nodes.setTranslation(self.dagPath.node(), position, space)
예제 #2
0
def jointRoot(node, depthLimit=256):
    parent = node
    while parent is not None or parent.apiType(
    ) == om2.MFn.kJoint or depthLimit > 1:
        parent = nodes.getParent(parent)
        depthLimit -= 1
    return parent
예제 #3
0
 def test_getParent(self):
     obj = nodes.asMObject(self.node)
     self.assertFalse(nodes.hasParent(obj))
     transform = nodes.asMObject(cmds.createNode("transform"))
     nodes.setParent(transform, obj)
     parent = nodes.getParent(transform)
     self.assertEquals(parent, obj)
예제 #4
0
def convertToSkeleton(rootNode, prefix="skel_", parentObj=None):
    """Converts a hierarchy of nodes into joints that have the same transform,
    with their name prefixed with the "prefix" arg.

    :param rootNode: PyNode , anything under this node gets converted.
    :param prefix: string, the name to add to the node name .
    :param parentObj:PyNode ,  the node to parent to skeleton to.
    :return:MObject
    """
    if parentObj is None:
        parentObj = nodes.getParent(rootNode)
    j = convertToNode(rootNode, parentObj, prefix)
    for c in nodes.getChildren(rootNode):
        convertToSkeleton(c, prefix, j)
    return j
예제 #5
0
def createAnnotation(rootObj, endObj, text=None, name=None):
    name = name or "annotation"
    rootDag = om2.MFnDagNode(rootObj)
    boundingBox = rootDag.boundingBox
    center = om2.MVector(boundingBox.center)
    transform = nodes.createDagNode("_".join([name, "loc"]),
                                    "transform",
                                    parent=rootObj)
    nodes.setTranslation(transform,
                         nodes.getTranslation(rootObj, om2.MSpace.kWorld),
                         om2.MSpace.kWorld)
    annotationNode = nodes.asMObject(
        cmds.annotate(nodes.nameFromMObject(transform), tx=text))
    annParent = nodes.getParent(annotationNode)
    nodes.rename(annParent, name)
    plugs.setPlugValue(
        om2.MFnDagNode(annotationNode).findPlug("position", False), center)
    nodes.setParent(annParent, endObj, False)
    return annotationNode, transform
예제 #6
0
    def addSrtBuffer(self, suffix="", parent=None):
        """Adds a parent transform to the curve transform

        :param suffix: the suffix that this transform will get, eg name: self.name_suffix
        :type suffix: str
        :return: the newly created node
        :rtype: mobject
        """

        if self.dagPath is None:
            return
        ctrlPat = nodes.getParent(self.mobject())
        newSrt = nodes.createDagNode("_".join([self.name, suffix]),
                                     "transform", ctrlPat)
        nodes.setMatrix(newSrt, nodes.getWorldMatrix(self.mobject()))

        if parent is not None:
            nodes.setParent(newSrt, parent, True)
        nodes.setParent(self.mobject(), newSrt, True)
        self.srt = om2.MObjectHandle(newSrt)
        return newSrt
예제 #7
0
def createAnnotation(rootObj, endObj, text=None, name=None):
    newparent = nodes.createDagNode("_".join([name, "ann_hrc"]), "transform")
    name = name or "annotation"
    locator = nodes.createDagNode("_".join([name, "loc"]), "locator",
                                  newparent)

    annotationNode = nodes.asMObject(
        cmds.annotate(nodes.nameFromMObject(locator), tx=text))
    annParent = nodes.getParent(annotationNode)
    nodes.rename(annParent, name)
    nodes.setParent(annParent, newparent, False)
    extras = [newparent]
    constraint = constraints.MatrixConstraint(
        name="_".join([name, "startMtx"]))

    extras.extend(
        constraint.create(endObj, locator, (True, True, True),
                          (True, True, True), (True, True, True)))
    extras.extend(
        constraint.create(rootObj, annParent, (True, True, True),
                          (True, True, True), (True, True, True)))

    return annParent, locator, extras