當前位置: 首頁>>代碼示例>>Python>>正文


Python OpenMaya.MFnDagNode方法代碼示例

本文整理匯總了Python中maya.OpenMaya.MFnDagNode方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MFnDagNode方法的具體用法?Python OpenMaya.MFnDagNode怎麽用?Python OpenMaya.MFnDagNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在maya.OpenMaya的用法示例。


在下文中一共展示了OpenMaya.MFnDagNode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_instancer

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def get_instancer(spore_node, as_string=True):
    """ return the instancer node connected to a given spore node
    :param spore_node:
    :param as_string: if true return node name else return mObject """

    node_fn = get_dgfn_from_dagpath(spore_node)
    instance_plug = node_fn.findPlug('instanceData')
    plugs = om.MPlugArray()
    instancer_plugs = om.MPlugArray()
    instance_geo = []

    if not instance_plug.isNull():
        if instance_plug.connectedTo(plugs, False, True):
            node = plugs[0].node()
            node_fn = om.MFnDagNode(node)
            if as_string:
                return node_fn.fullPathName()
            else:
                return node 
開發者ID:wiremas,項目名稱:spore,代碼行數:21,代碼來源:node_utils.py

示例2: connect_to_instancer

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def connect_to_instancer(transform_node, spore_node):
    """ connect a transform's matrix attribute to a instancer node
    that is connected to the given spore node """

    # get instancer's inputHierarchy plug
    instancer_node = get_instancer(spore_node, False)
    dg_fn = om.MFnDependencyNode(instancer_node)
    in_plug = dg_fn.findPlug('inputHierarchy')

    # get transform's matrix plug
    transform_node = get_mobject_from_name(transform_node)
    dag_fn = om.MFnDagNode(transform_node)
    matrix_plug = dag_fn.findPlug('matrix')

    # get first free plug and connect
    plug_id = in_plug.numElements() + 1
    dag_mod = om.MDagModifier()
    dag_mod.connect(matrix_plug, in_plug.elementByLogicalIndex(plug_id))
    dag_mod.doIt() 
開發者ID:wiremas,項目名稱:spore,代碼行數:21,代碼來源:node_utils.py

示例3: createCallbacks

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def createCallbacks(self):
        # frame changed callback
        # needed for changing the relative keyframe display
        self.mTimeCallbackId = om.MEventMessage.addEventCallback('timeChanged', self.setRelativeFrames)
        # iterate over all cameras add the callback
        # using old api because new doesn't include iterator over dep nodes
        dgit = oldOm.MItDependencyNodes(oldOm.MFn.kCamera)

        while not dgit.isDone():
            t = oldOm.MFnDagNode(dgit.thisNode()).parent(0)
            if t is not None:
                self.mCameraMovedCallbackIds.append(
                    oldOm.MNodeMessage.addAttributeChangedCallback(t, self.cameraMovedCB))
            dgit.next()


    # removing them when the ui is closed 
開發者ID:Viele,項目名稱:onionSkinRenderer,代碼行數:19,代碼來源:onionSkinRendererCore.py

示例4: getCurveFn

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def getCurveFn(self):
        inputCurvePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputCurveAttr)
        curve = getSingleSourceObjectFromPlug(inputCurvePlug)

        # Get Fn from a DAG path to get the world transformations correctly
        if curve is not None:
            path = OpenMaya.MDagPath()
            trFn = OpenMaya.MFnDagNode(curve)
            trFn.getPath(path)

            path.extendToShape()

            if path.node().hasFn(OpenMaya.MFn.kNurbsCurve):
                return OpenMaya.MFnNurbsCurve(path)

        return None

    # Calculate expected instances by the instancing mode 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:20,代碼來源:instanceAlongCurve.py

示例5: getFnFromPlug

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def getFnFromPlug(plug, fnType):
    node = getSingleSourceObjectFromPlug(plug)

    # Get Fn from a DAG path to get the world transformations correctly
    if node is not None:
        path = OpenMaya.MDagPath()
        trFn = OpenMaya.MFnDagNode(node)
        trFn.getPath(path)

        path.extendToShape()

        if path.node().hasFn(fnType):
            return path

    return None

# TODO: cache this data to prevent recalculating when there is no manipulator being updated 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:19,代碼來源:instanceAlongCurve.py

示例6: voxelize

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def voxelize(self, cell_size):
        """ partition the spatial domain with the given cellsize.
        than assign each point to the cell is spatialy belongs to.
        :return dict: where:
                      key == the cell index
                      value == list of points indexes from the point_data obj """

        partition = {}

        in_mesh = node_utils.get_connected_in_mesh(self.target, False)
        bb = om.MFnDagNode(in_mesh).boundingBox()

        self.w_count = int(math.ceil(bb.width() / cell_size))
        self.h_count = int(math.ceil(bb.height() / cell_size))
        self.d_count = int(math.ceil(bb.depth() / cell_size))

        bb_min = bb.min()
        for i in xrange(self.point_data.position.length()):
            p_normalized = self.point_data.position[i] - bb_min
            p_x = int(p_normalized.x / cell_size)
            p_y = int(p_normalized.y / cell_size)
            p_z = int(p_normalized.z / cell_size)

            index = p_x + p_y * self.w_count + p_z * self.w_count * self.h_count


            partition.setdefault(index, []).append(i)

        return partition 
開發者ID:wiremas,項目名稱:spore,代碼行數:31,代碼來源:spore_sampler.py

示例7: altitude_filter

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def altitude_filter(self, min_altitude, max_altitude, min_fuzziness, max_fuzziness):
        """ filter points based on y position relative to bounding box """

        in_mesh = node_utils.get_connected_in_mesh(self.target, False)
        dag_fn = om.MFnDagNode(in_mesh)

        bb = dag_fn.boundingBox()
        bb_y_min = bb.min().y
        height = bb.height()

        invalid_ids = []
        for i, (position, _, _, _, _) in enumerate(self.point_data):
            y_normalized = position[1] - bb_y_min
            pos_rel = y_normalized / height

            if pos_rel < min_altitude:
                if pos_rel < min_altitude - min_fuzziness:
                    invalid_ids.append(i)

                elif min_altitude - pos_rel > random.uniform(0, min_fuzziness):
                    invalid_ids.append(i)

            elif pos_rel > max_altitude:
                if pos_rel > max_altitude + max_fuzziness:
                    invalid_ids.append(i)

                elif abs(max_altitude - pos_rel) > random.uniform(0, max_fuzziness):
                    invalid_ids.append(i)

        invalid_ids = sorted(invalid_ids, reverse=True)
        [self.point_data.remove(index) for index in invalid_ids] 
開發者ID:wiremas,項目名稱:spore,代碼行數:33,代碼來源:spore_sampler.py

示例8: redoIt

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def redoIt(self):
        """ redo """

        self.dag_mod_transform.doIt()
        self.dag_mod_spore.doIt()
        self.dag_mod_instancer.doIt()

        # get result
        result = []
        dg_fn = om.MFnDependencyNode(self.spore)
        result.append(dg_fn.name())
        dag_fn = om.MFnDagNode(self.instancer)
        result.append(dag_fn.fullPathName())
        self.clearResult()
        self.setResult(result) 
開發者ID:wiremas,項目名稱:spore,代碼行數:17,代碼來源:spore_command.py

示例9: get_dagfn_from_dagpath

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def get_dagfn_from_dagpath(dagpath):
    """ return a dag-node functionset to a given dag-path """

    m_dagpath = get_dagpath_from_name(dagpath)
    return om.MFnDagNode(m_dagpath) 
開發者ID:wiremas,項目名稱:spore,代碼行數:7,代碼來源:node_utils.py

示例10: get_instanced_geo

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def get_instanced_geo(spore_node):
    """ return a list of dag pathes of geometry transformes that
    are connected to the spore node's instancer
    @param spore_node str: the name of the spore node
    @return: list of string or None if no instancer is connected """

    node_fn = get_dgfn_from_dagpath(spore_node)
    instance_plug = node_fn.findPlug('instanceData')
    plugs = om.MPlugArray()
    instancer_plugs = om.MPlugArray()
    instance_geo = []

    if not instance_plug.isNull():
        if instance_plug.connectedTo(plugs, False, True):
            node = plugs[0].node()
            node_fn = om.MFnDagNode(node)
            inst_geo_plug = node_fn.findPlug('inputHierarchy')

            if not inst_geo_plug.isNull():
                for i in xrange(inst_geo_plug.numConnectedElements()):
                    input_plug = inst_geo_plug.elementByPhysicalIndex(i)

                    if input_plug.connectedTo(instancer_plugs, True, True):
                        geo_plug = instancer_plugs[0]
                        geo_node = geo_plug.node()
                        instance_geo.append(om.MFnDagNode(geo_node).fullPathName())

            dg_node_fn = om.MFnDependencyNode(node)
            instancer_node = dg_node_fn.name()

    return instance_geo 
開發者ID:wiremas,項目名稱:spore,代碼行數:33,代碼來源:node_utils.py

示例11: test_createNode_performance

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def test_createNode_performance():
    """createNode cmdx vs cmds > 2x"""

    versions = (
        ("mel", lambda: mel.eval("createNode \"transform\"")),
        ("cmds", lambda: cmds.createNode("transform")),
        ("cmdx", lambda: cmdx.createNode(cmdx.tTransform)),
        # ("PyMEL", lambda: pm.createNode("transform")),
        ("API 1.0", lambda: om1.MFnDagNode().create("transform")),
        ("API 2.0", lambda: om2.MFnDagNode().create("transform")),
    )

    for contender, test in versions:
        Compare(contender, "createNode", test, setup=New)

    cmdx_vs_cmds = (
        timings["createNode"]["cmds"]["percall"] /
        timings["createNode"]["cmdx"]["percall"]
    )

    cmdx_vs_api = (
        timings["createNode"]["API 2.0"]["percall"] /
        timings["createNode"]["cmdx"]["percall"]
    )

    assert_greater(cmdx_vs_cmds, 0.5)  # at most 2x slower than cmds
    assert_greater(cmdx_vs_api, 0.20)  # at most 5x slower than API 2.0 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:29,代碼來源:test_performance.py

示例12: editCurve

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def editCurve(parent, points, degree=1, form=kOpen):
    assert isinstance(parent, DagNode), (
        "parent must be of type cmdx.DagNode"
    )

    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()

    for point in points:
        cvs.append(om1.MPoint(*point))

    mobj = curveFn.createWithEditPoints(cvs,
                                        degree,
                                        form,
                                        False,
                                        False,
                                        True,
                                        _encode1(parent.path()))

    mod = om1.MDagModifier()
    mod.renameNode(mobj, parent.name(namespace=True) + "Shape")
    mod.doIt()

    def undo():
        mod.deleteNode(mobj)
        mod.doIt()

    def redo():
        mod.undoIt()

    commit(undo, redo)

    shapeFn = om1.MFnDagNode(mobj)
    return encode(shapeFn.fullPathName()) 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:38,代碼來源:cmdx.py

示例13: getNodeTransformFn

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def getNodeTransformFn(self):
        dagNode = OpenMaya.MFnDagNode(self.thisMObject())
        dagPath = OpenMaya.MDagPath()
        dagNode.getPath(dagPath)
        return OpenMaya.MFnDagNode(dagPath.transform()) 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:7,代碼來源:instanceAlongCurve.py

示例14: getInputTransformFn

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def getInputTransformFn(self):

        inputTransformPlug = self.getInputTransformPlug()
        transform = getSingleSourceObjectFromPlug(inputTransformPlug)

        # Get Fn from a DAG path to get the world transformations correctly
        if transform is not None and transform.hasFn(OpenMaya.MFn.kTransform):
                path = OpenMaya.MDagPath()
                trFn = OpenMaya.MFnDagNode(transform)
                trFn.getPath(path)
                return OpenMaya.MFnTransform(path)

        return None 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:15,代碼來源:instanceAlongCurve.py

示例15: findShadingGroup

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnDagNode [as 別名]
def findShadingGroup(self, dagPath):

        # Search in children first before extending to shape
        for child in xrange(dagPath.childCount()):
            childDagPath = OpenMaya.MDagPath()
            fnDagNode = OpenMaya.MFnDagNode(dagPath.child(child))
            fnDagNode.getPath(childDagPath)

            fnSet = self.findShadingGroup(childDagPath)

            if fnSet is not None:
                return fnSet

        if self.hasShapeBelow(dagPath):
            dagPath.extendToShape()
            fnDepNode = OpenMaya.MFnDependencyNode(dagPath.node())

            instPlugArray = fnDepNode.findPlug("instObjGroups")
            instPlugArrayElem = instPlugArray.elementByLogicalIndex(dagPath.instanceNumber())

            if instPlugArrayElem.isConnected():
                connectedPlugs = OpenMaya.MPlugArray()      
                instPlugArrayElem.connectedTo(connectedPlugs, False, True)

                if connectedPlugs.length() == 1:
                    sgNode = connectedPlugs[0].node()

                    if sgNode.hasFn(OpenMaya.MFn.kSet):
                        return OpenMaya.MFnSet(sgNode)

        return None 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:33,代碼來源:instanceAlongCurve.py


注:本文中的maya.OpenMaya.MFnDagNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。