本文整理匯總了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
示例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()
示例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
示例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
示例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
示例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
示例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]
示例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)
示例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)
示例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
示例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
示例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())
示例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())
示例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
示例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