本文整理匯總了Python中maya.OpenMaya.MObject方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MObject方法的具體用法?Python OpenMaya.MObject怎麽用?Python OpenMaya.MObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getComponent
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def getComponent(name):
"""
Args:
name (str)
Returns:
MOBject
"""
selList = om.MSelectionList()
selList.add (name)
dagPath = om.MDagPath()
component = om.MObject()
selList.getDagPath(0, dagPath, component)
return component
#----------------------------------------------------------------------
示例2: getGeometryComponents
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def getGeometryComponents(skinCls):
"""Get the geometry components from skincluster
Arguments:
skinCls (PyNode): The skincluster node
Returns:
dagPath: The dagpath for the components
componets: The skincluster componets
"""
fnSet = OpenMaya.MFnSet(skinCls.__apimfn__().deformerSet())
members = OpenMaya.MSelectionList()
fnSet.getMembers(members, False)
dagPath = OpenMaya.MDagPath()
components = OpenMaya.MObject()
members.getDagPath(0, dagPath, components)
return dagPath, components
示例3: getCurrentWeights
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def getCurrentWeights(skinCls, dagPath, components):
"""Get the skincluster weights
Arguments:
skinCls (PyNode): The skincluster node
dagPath (MDagPath): The skincluster dagpath
components (MObject): The skincluster components
Returns:
MDoubleArray: The skincluster weights
"""
weights = OpenMaya.MDoubleArray()
util = OpenMaya.MScriptUtil()
util.createFromInt(0)
pUInt = util.asUintPtr()
skinCls.__apimfn__().getWeights(dagPath, components, weights, pUInt)
return weights
######################################
# Skin Collectors
######################################
示例4: getDagPathComponents
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def getDagPathComponents(compList):
"""
Args:
compList (list)
Returns:
MObject
"""
currSel = cmds.ls(sl=1, l=1)
cmds.select(compList, r=1)
selList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(selList)
dagPath = om.MDagPath()
components = om.MObject()
selList.getDagPath(0, dagPath, components)
cmds.select(cl=1)
try:
cmds.select(currSel, r=1)
except:
pass
return dagPath, components
#----------------------------------------------------------------------
示例5: _selectionIter
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _selectionIter(cls):
""" A Maya Helper that returns a iterator of maya objects currently
selected.
"""
# Create object named selection and type - SelectionList
selection = om.MSelectionList()
# Fill variable "selection" with list of selected objects
om.MGlobal.getActiveSelectionList(selection)
# Create iterator through list of selected object
selection_iter = om.MItSelectionList(selection)
# Loop though iterator objects
while not selection_iter.isDone():
obj = om.MObject()
selection_iter.getDependNode(obj)
yield obj
selection_iter.next()
示例6: _objectsOfMTypeIter
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _objectsOfMTypeIter(cls, objectType):
""" Maya Helper that returns a iterator of maya objects filtered by objectType.
:param objectType: A enum value used to identify objects.
.. seeAlso.. SceneObject._abstractToNativeObjectType
"""
if not isinstance(objectType, (tuple, list)):
objectType = [objectType]
for oType in objectType:
# Create iterator traverse all camera nodes
oIter = om.MItDependencyNodes(oType)
# Loop though iterator objects
while not oIter.isDone():
# oIter.thisNode() points to current MObject in iterator
yield oIter.thisNode()
oIter.next()
#--------------------------------------------------------------------------------
# cross3d private methods
#--------------------------------------------------------------------------------
示例7: _getchildShapeNodes
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _getchildShapeNodes(cls, nativeObject):
""" A Maya helper that returns a generator of all shape nodes for the provided transform node.
Args:
nativeObject (OpenMaya.MObject): The object to get the shape nodes of.
"""
if nativeObject.apiType() == om.MFn.kTransform:
path = om.MDagPath.getAPathTo(nativeObject)
numShapes = om.MScriptUtil()
numShapes.createFromInt(0)
numShapesPtr = numShapes.asUintPtr()
path.numberOfShapesDirectlyBelow(numShapesPtr)
for index in range(om.MScriptUtil(numShapesPtr).asUint()):
p = om.MDagPath.getAPathTo(nativeObject)
p.extendToShapeDirectlyBelow(index)
yield p.node()
示例8: _getShapeNode
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _getShapeNode(cls, nativeObject):
""" A Maya Helper that returns the first shape node of the provided transform node.
If no shape node exists the nativeObject is returned.
Args:
nativeObject (OpenMaya.MObject): The MObject to get the first shape node from.
Returns:
OpenMaya.MObject: The first shape node of the transform or the passed in object.
"""
if nativeObject.apiType() == om.MFn.kTransform:
path = om.MDagPath.getAPathTo(nativeObject)
numShapes = om.MScriptUtil()
numShapes.createFromInt(0)
numShapesPtr = numShapes.asUintPtr()
path.numberOfShapesDirectlyBelow(numShapesPtr)
if om.MScriptUtil(numShapesPtr).asUint():
# TODO: Should this return the last shape, instead of the first?
path.extendToShapeDirectlyBelow(0)
return path.node()
return nativeObject
示例9: _getTransformNode
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _getTransformNode(cls, nativeObject):
""" A Maya Helper that returns the first transform node of the provided shape node.
The nativeObject is returned if the nativeObject is a transform node.
:param nativeObject: The OpenMaya.MObject to get the transform node of
:return: OpenMaya.MObject
"""
with ExceptionRouter():
# If its not a dag object, there is no transform to return use the nativeObject
if not cls._isDagNode(nativeObject):
# The world node doesn't play well with the getting transform code.
return nativeObject
path = om.MDagPath.getAPathTo(nativeObject)
newPointer = path.transform()
if newPointer != nativeObject:
return newPointer
return nativeObject
示例10: _mObjName
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _mObjName(cls, nativeObject, fullName=True):
""" A Maya Helper that returns the name of a object, because OpenMaya can't
expose the name in a single call.
:param nativeObject: The OpenMaya.MObject to get the name of
:param fullName: If True return the Name(Full Path), else return the displayName. Defaults to True
:return: nativeObject's name as a string
"""
with ExceptionRouter():
if cls._isDagNode(nativeObject):
dagPath = om.MDagPath.getAPathTo(nativeObject)
if fullName:
return dagPath.fullPathName()
return dagPath.partialPathName().split("|")[-1]
return om.MFnDependencyNode(nativeObject).name()
#--------------------------------------------------------------------------------
# cross3d private methods
#--------------------------------------------------------------------------------
示例11: _get_rotation_quaternion
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _get_rotation_quaternion(self):
obj=OpenMaya.MObject()
#make a object of type MSelectionList
sel_list=OpenMaya.MSelectionList()
#add something to it
#you could retrieve this from function or the user selection
sel_list.add(self.maya_node)
#fill in the MObject
sel_list.getDependNode(0,obj)
#check if its a transform
if (obj.hasFn(OpenMaya.MFn.kTransform)):
quat = OpenMaya.MQuaternion()
#then we can add it to transfrom Fn
#Fn is basically the collection of functions for given objects
xform=OpenMaya.MFnTransform(obj)
xform.getRotation(quat)
# glTF requires normalize quat
quat.normalizeIt()
py_quat = [quat[x] for x in range(4)]
return py_quat
示例12: _encode1
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def _encode1(path):
"""Convert `path` to Maya API 1.0 MObject
Arguments:
path (str): Absolute or relative path to DAG or DG node
Raises:
ExistError on `path` not existing
"""
selectionList = om1.MSelectionList()
try:
selectionList.add(path)
except RuntimeError:
raise ExistError("'%s' does not exist" % path)
mobject = om1.MObject()
selectionList.getDependNode(0, mobject)
return mobject
示例13: createNode
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def createNode(self, type, name=None, parent=None):
parent = parent._mobject if parent else om.MObject.kNullObj
try:
mobj = self._modifier.createNode(type, parent)
except TypeError:
raise TypeError("'%s' is not a valid node type" % type)
template = self._opts["template"]
if name or template:
name = (template or "{name}").format(
name=name or "",
type=type,
index=self._index,
)
self._modifier.renameNode(mobj, name)
return DagNode(mobj, exists=False, modifier=self)
示例14: __init__
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def __init__(self, skin_cluster):
"""Constructor"""
self.node = skin_cluster
self.shape = cmds.listRelatives(
cmds.deformer(skin_cluster, q=True, g=True)[0], parent=True, path=True
)[0]
# Get the skinCluster MObject
self.mobject = shortcuts.get_mobject(self.node)
self.fn = OpenMayaAnim.MFnSkinCluster(self.mobject)
self.data = {
"weights": {},
"blendWeights": [],
"name": self.node,
"shape": self.shape,
}
示例15: gather_influence_weights
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MObject [as 別名]
def gather_influence_weights(self, dag_path, components):
"""Gathers all the influence weights
:param dag_path: MDagPath of the deformed geometry.
:param components: Component MObject of the deformed components.
"""
weights = self.__get_current_weights(dag_path, components)
influence_paths = OpenMaya.MDagPathArray()
influence_count = self.fn.influenceObjects(influence_paths)
components_per_influence = weights.length() // influence_count
for ii in range(influence_paths.length()):
influence_name = influence_paths[ii].partialPathName()
# We want to store the weights by influence without the namespace so it is easier
# to import if the namespace is different
influence_without_namespace = shortcuts.remove_namespace_from_name(
influence_name
)
self.data["weights"][influence_without_namespace] = [
weights[jj * influence_count + ii]
for jj in range(components_per_influence)
]