本文整理汇总了Python中maya.OpenMaya.MFnSingleIndexedComponent方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MFnSingleIndexedComponent方法的具体用法?Python OpenMaya.MFnSingleIndexedComponent怎么用?Python OpenMaya.MFnSingleIndexedComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MFnSingleIndexedComponent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: asComponent
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def asComponent(index, t=OpenMaya.MFn.kMeshVertComponent):
"""
index -> OpenMaya.MFn.kComponent
Based on the input type it will create a component type for this tool
the following components are being used.
* OpenMaya.MFn.kMeshVertComponent
* OpenMaya.MFn.kMeshEdgeComponent
:param int/OpenMaya.MIntArray index: indices to create component for
:param OpenMaya.MFn.kComponent t: can be all of OpenMaya component types.
:return: Initialized components
:rtype: OpenMaya.MFnSingleIndexedComponent
"""
# convert input to an MIntArray if it not already is one
array = asMIntArray(index)
# initialize component
component = OpenMaya.MFnSingleIndexedComponent().create(t)
OpenMaya.MFnSingleIndexedComponent(component).addElements(array)
return component
# ----------------------------------------------------------------------------
示例2: asComponent
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def asComponent(index):
"""
index -> OpenMaya.MFn.kMeshVertComponent
:param int/OpenMaya.MIntArray index: indices to create component for
:return: Initialized component(s)
:rtype: OpenMaya.MFn.kMeshVertComponent
"""
# convert input to an MIntArray if it not already is one
indices = asMIntArray(index)
# initialize component(s)
t = OpenMaya.MFn.kMeshVertComponent
component = OpenMaya.MFnSingleIndexedComponent().create(t)
OpenMaya.MFnSingleIndexedComponent(component).addElements(indices)
return component
示例3: set_data
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def set_data(self, data, selected_components=None):
"""Sets the data and stores it in the Maya skinCluster node.
:param data: Data dictionary.
"""
self.data = data
dag_path, components = self.__get_geometry_components()
if selected_components:
fncomp = OpenMaya.MFnSingleIndexedComponent()
components = fncomp.create(OpenMaya.MFn.kMeshVertComponent)
for i in selected_components:
fncomp.addElement(i)
self.set_influence_weights(dag_path, components)
self.set_blend_weights(dag_path, components)
for attr in SkinCluster.attributes:
cmds.setAttr("{0}.{1}".format(self.node, attr), self.data[attr])
示例4: getAveragePosition
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def getAveragePosition(dag, component, space):
"""
Get average position of connected vertices.
:param OpenMaya.MDagPath dag:
:param OpenMaya.MFnSingleIndexedComponent component:
:param OpenMaya.MSpace space:
:return: Average length of the connected edges
:rtype: OpenMaya.MPoint
"""
averagePos = OpenMaya.MPoint()
# get connected vertices
connected = OpenMaya.MIntArray()
iterate = OpenMaya.MItMeshVertex(dag, component)
iterate.getConnectedVertices(connected)
# get original position
originalPos = iterate.position(space)
# ignore if no vertices are connected
if not connected.length():
return averagePos
# get average
component = asComponent(connected)
iterate = OpenMaya.MItMeshVertex(dag, component)
while not iterate.isDone():
averagePos += OpenMaya.MVector(iterate.position(space))
iterate.next()
averagePos = averagePos/connected.length()
return originalPos, averagePos
示例5: getAverageLength
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def getAverageLength(dag, component, space):
"""
Get average length of connected edges.
:param OpenMaya.MDagPath dag:
:param OpenMaya.MFnSingleIndexedComponent component:
:param OpenMaya.MSpace space:
:return: Average length of the connected edges
:rtype: float
"""
total = 0
lengthUtil = OpenMaya.MScriptUtil()
lengthPtr = lengthUtil.asDoublePtr()
# get connected edges
connected = OpenMaya.MIntArray()
iterate = OpenMaya.MItMeshVertex(dag, component)
iterate.getConnectedEdges(connected)
# ignore if no edges are connected
if not connected.length():
return 0
# get average
component = asComponent(connected, OpenMaya.MFn.kMeshEdgeComponent)
iterate = OpenMaya.MItMeshEdge(dag, component)
while not iterate.isDone():
iterate.getLength(lengthPtr, space)
total += lengthUtil.getDouble(lengthPtr)
iterate.next()
return total/connected.length()
# ----------------------------------------------------------------------------
示例6: getSelection
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def getSelection(self):
# variable
indices = OpenMaya.MIntArray()
allIndices = OpenMaya.MIntArray()
# get active selection
selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList(selection)
# loop selection
iter = OpenMaya.MItSelectionList(selection)
while not iter.isDone():
# variables
component = OpenMaya.MObject()
dag = OpenMaya.MDagPath()
iter.getDagPath(dag, component)
if not component.isNull():
objIndices = OpenMaya.MIntArray()
components = OpenMaya.MFnSingleIndexedComponent(component)
components.getElements(indices)
for i in range(indices.length()):
allIndices.append(indices[i])
iter.next()
return allIndices
示例7: set_influence_weights
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def set_influence_weights(self, dag_path, components):
"""Sets all the influence weights.
:param dag_path: MDagPath of the deformed geometry.
:param components: Component MObject of the deformed components.
"""
influence_paths = OpenMaya.MDagPathArray()
influence_count = self.fn.influenceObjects(influence_paths)
elements = OpenMaya.MIntArray()
fncomp = OpenMaya.MFnSingleIndexedComponent(components)
fncomp.getElements(elements)
weights = OpenMaya.MDoubleArray(elements.length() * influence_count)
components_per_influence = elements.length()
for imported_influence, imported_weights in self.data["weights"].items():
imported_influence = imported_influence.split("|")[-1]
for ii in range(influence_paths.length()):
influence_name = influence_paths[ii].partialPathName()
influence_without_namespace = shortcuts.remove_namespace_from_name(
influence_name
)
if influence_without_namespace == imported_influence:
# Store the imported weights into the MDoubleArray
for jj in range(components_per_influence):
weights.set(imported_weights[elements[jj]], jj * influence_count + ii)
break
influence_indices = OpenMaya.MIntArray(influence_count)
for ii in range(influence_count):
influence_indices.set(ii, ii)
self.fn.setWeights(dag_path, components, influence_indices, weights, False)
示例8: set_blend_weights
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def set_blend_weights(self, dag_path, components):
"""Set the blendWeights.
:param dag_path: MDagPath of the deformed geometry.
:param components: Component MObject of the deformed components.
"""
elements = OpenMaya.MIntArray()
fncomp = OpenMaya.MFnSingleIndexedComponent(components)
fncomp.getElements(elements)
blend_weights = OpenMaya.MDoubleArray(elements.length())
for i in range(elements.length()):
blend_weights.set(self.data["blendWeights"][elements[i]], i)
self.fn.setBlendWeights(dag_path, components, blend_weights)
示例9: getSoftSelectionWeights
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def getSoftSelectionWeights():
#get selection
sel = om.MSelectionList()
softSelection = om.MRichSelection()
om.MGlobal.getRichSelection(softSelection)
softSelection.getSelection(sel)
dagPath = om.MDagPath()
component = om.MObject()
iter = om.MItSelectionList(sel, om.MFn.kMeshVertComponent)
weights = {}
while not iter.isDone():
iter.getDagPath( dagPath, component )
dagPath.pop() #Grab the parent of the shape node
node = dagPath.fullPathName()
fnComp = om.MFnSingleIndexedComponent(component)
for i in range(fnComp.elementCount()):
weight = 1.0
if fnComp.hasWeights():
weight = fnComp.weight(i).influence()
weights['{}.vtx[{}]'.format(node, fnComp.element(i))] = weight
iter.next()
return weights
示例10: redoIt
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def redoIt(self, flash=True):
for node, vtxIndices in self.bake_node_id_dict.items():
weights = self.bake_node_weight_dict[node]
infIndices = self.bake_node_inf_dict[node]
skinFn = self.node_skinFn_dict[node]
if MAYA_VER >= 2016:
sList = om2.MSelectionList()
sList.add(node)
meshDag, component = sList.getComponent(0)
# 指定の頂点をコンポーネントとして取得する
singleIdComp = om2.MFnSingleIndexedComponent()
vertexComp = singleIdComp.create(om2.MFn.kMeshVertComponent )
singleIdComp.addElements(vtxIndices)
else:
sList = om.MSelectionList()
sList.add(node)
meshDag = om.MDagPath()
component = om.MObject()
sList.getDagPath(0, meshDag, component)
singleIdComp = om.MFnSingleIndexedComponent()
vertexComp = singleIdComp.create(om.MFn.kMeshVertComponent )
singleIdComp.addElements(vtxIndices)
##引数(dag_path, MIntArray, MIntArray, MDoubleArray, Normalize, old_weight_undo)
#print meshDag, vertexComp , infIndices , weights
#print type(infIndices)
#print type(vertexComp)
skinFn.setWeights(meshDag, vertexComp , infIndices , weights, False)
#アンドゥ用ウェイトデータをアップデートする
siweighteditor.update_dict(self.redo_node_weight_dict, self.bake_node_id_dict)
if flash:
if self.ignore_undo:#スライダー制御中のアンドゥ履歴は全無視する
return
siweighteditor.refresh_window()
示例11: undoIt
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnSingleIndexedComponent [as 别名]
def undoIt(self):
siweighteditor.reverse_dict(self.undo_node_weight_dict, self.bake_node_id_dict)
if self.ignore_undo:#スライダー制御中のアンドゥ履歴は全無視する
return
for node, vtxIndices in self.bake_node_id_dict.items():
weights = self.org_node_weight_dict[node]
infIndices = self.bake_node_inf_dict[node]
skinFn = self.node_skinFn_dict[node]
if MAYA_VER >= 2016:
sList = om2.MSelectionList()
sList.add(node)
meshDag, component = sList.getComponent(0)
singleIdComp = om2.MFnSingleIndexedComponent()
vertexComp = singleIdComp.create(om2.MFn.kMeshVertComponent )
singleIdComp.addElements(vtxIndices)
else:
sList = om.MSelectionList()
sList.add(node)
meshDag = om.MDagPath()
component = om.MObject()
sList.getDagPath(0, meshDag, component)
singleIdComp = om.MFnSingleIndexedComponent()
vertexComp = singleIdComp.create(om.MFn.kMeshVertComponent )
singleIdComp.addElements(vtxIndices)
##引数(dag_path, MIntArray, MIntArray, MDoubleArray, Normalize, old_weight_undo)
skinFn.setWeights(meshDag, vertexComp , infIndices , weights, False)
#アンドゥの度に読み込むと重いからどうしよう。
siweighteditor.refresh_window()