コード例 #1
0
def getCurveData(shape, space=om2.MSpace.kObject):
    """From a given NurbsCurve shape node serialize the cvs positions, knots, degree, form rgb colours

    :param shape: MObject that represents the NurbsCurve shape
    :return: dict
    :param space:
    :type space: om2.MSpace

    Example::
        >>>nurbsCurve = cmds.circle()[1]
        # requires an MObject of the shape node
        >>>data = curve_utils.getCurveData(api.asMObject(nurbsCurve))
    """
    if isinstance(shape, om2.MObject):
        shape = om2.MFnDagNode(shape).getPath()
    data = nodes.getNodeColourData(shape.node())
    curve = om2.MFnNurbsCurve(shape)
    # so we can deserialize in world which maya does in to steps
    if space == om2.MSpace.kWorld:
        data["matrix"] = list(nodes.getWorldMatrix(curve.object()))
    data.update({
        "knots": tuple(curve.knots()),
        "cvs": map(tuple, curve.cvPositions(space)),
        "degree": curve.degree,
        "form": curve.form
    })
    return data
コード例 #2
0
 def test_getWorldMatrix(self):
     node = nodes.asMObject(self.node)
     matrix = nodes.getWorldMatrix(node)
     self.assertIsInstance(matrix, om2.MMatrix)
     parentPlug = om2.MFnDagNode(node).findPlug("worldMatrix", False)
     parentPlug.evaluateNumElements()
     matPl = parentPlug.elementByPhysicalIndex(0)
     self.assertEquals(matrix, om2.MFnMatrixData(matPl.asMObject()).matrix())
コード例 #3
0
def convertToNode(node, parent, prefix, nodeType="joint"):
    """Converts a node into a joint but does not delete the node ,
    transfers matrix over as well

    :param node: mobject, the node that will be converted
    :param parent: mobject to the transform to parent to
    :param prefix: str, the str value to give to the start of the node name
    :param nodeType: str, the node type to convert to. must be a dag type node
    :return: mObject, the mobject of the joint
    """
    mod = om2.DagModifier("createJoint")
    jnt = mod.createNode(nodeType)
    mod.doIt()
    nodes.rename(jnt, prefix + nodes.nameFromMObject(node, partialName=True))
    nodes.setParent(jnt, parent)
    plugs.setPlugValue(
        om2.MFnDagNode(jnt).findPlug("worldMatrix", False),
        nodes.getWorldMatrix(node))

    return jnt
コード例 #4
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