本文整理汇总了Python中maya.api.OpenMaya.MMatrix方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MMatrix方法的具体用法?Python OpenMaya.MMatrix怎么用?Python OpenMaya.MMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.api.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MMatrix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bakeJointMotion
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def bakeJointMotion(skinJoints, skinMatrix):
asl = om.MSelectionList()
for sj in skinJoints:
asl.add(sj.path)
om.MGlobal.setActiveSelectionList(asl)
startTime = oma.MAnimControl.animationStartTime()
endTime = oma.MAnimControl.animationEndTime()
frame = 0
ctime = startTime
oma.MAnimControl.setCurrentTime(ctime)
while ctime <= endTime:
oma.MAnimControl.setCurrentTime(ctime)
for jid, sj in enumerate(skinJoints):
m = om.MMatrix(np.dot(sj.bindPose, skinMatrix[jid, frame]).tolist())
m = om.MTransformationMatrix(m)
om.MFnTransform(sj.path).setTransformation(m)
cmds.setKeyframe()
frame = frame + 1
ctime = ctime + 1
oma.MAnimControl.setCurrentTime(startTime)
示例2: asMatrix
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def asMatrix(self, time=None):
"""Return plug as MMatrix
Example:
>>> node1 = createNode("transform")
>>> node2 = createNode("transform", parent=node1)
>>> node1["translate"] = (0, 5, 0)
>>> node2["translate"] = (0, 5, 0)
>>> plug1 = node1["matrix"]
>>> plug2 = node2["worldMatrix"][0]
>>> mat1 = plug1.asMatrix()
>>> mat2 = plug2.asMatrix()
>>> mat = mat1 * mat2
>>> tm = TransformationMatrix(mat)
>>> list(tm.translation())
[0.0, 15.0, 0.0]
"""
context = om.MDGContext.kNormal
if time is not None:
context = om.MDGContext(om.MTime(time, om.MTime.uiUnit()))
return om.MFnMatrixData(self._mplug.asMObject(context)).matrix()
示例3: __mul__
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def __mul__(self, other):
if isinstance(other, (tuple, list)):
other = Vector(*other)
if isinstance(other, om.MVector):
p = self.translation()
q = self.quaternion()
return p + q * other
elif isinstance(other, om.MMatrix):
return type(self)(self.asMatrix() * other)
elif isinstance(other, om.MTransformationMatrix):
return type(self)(self.asMatrix() * other.asMatrix())
else:
raise TypeError(
"unsupported operand type(s) for *: '%s' and '%s'"
% (type(self).__name__, type(other).__name__)
)
示例4: _drawArrow
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def _drawArrow(self, manager, basePoint, worldMat, rotMat, distanceMat, color):
# type: (omui.MUIDrawManager, om.MPoint, om.MMatrix, om.MMatrix, om.MMatrix, om.MColor) -> None
manager.setColor(color)
camZoom = self._zoomRatio(basePoint)
# draw line
endMat = worldMat + (distanceMat * camZoom * rotMat)
posx = endMat.getElement(3, 0)
posy = endMat.getElement(3, 1)
posz = endMat.getElement(3, 2)
endPoint = om.MPoint(posx, posy, posz)
manager.line(basePoint, endPoint)
# draw cone(base, direction, radius, height, filled=False) -> self
direction = om.MVector()
direction.x = posx - basePoint.x
direction.y = posy - basePoint.y
direction.z = posz - basePoint.z
w = self.coneRadius * camZoom
h = self.coneHeight * camZoom
manager.cone(endPoint, direction, w, h, True)
示例5: get_center_matrix
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def get_center_matrix(matrices):
"""
Get a matrix that can be used to transform other matrices to make sure on
the start frame the center point between the ankles is at 0, 0, 0 in world
space.
:param dict matrices:
:return: Center matrix
:rtype: OpenMaya.MMatrix
"""
# get ankle matrices
l_ankle = OpenMaya.MVector(matrices.get("l_ankle")[12:15])
r_ankle = OpenMaya.MVector(matrices.get("r_ankle")[12:15])
center = (l_ankle + r_ankle) * -0.5
# compile matrix
return OpenMaya.MMatrix(
[
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
center.x, center.y, center.z, 1.0
]
)
示例6: get_scale_matrix
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def get_scale_matrix():
"""
The scale matrix is used to scale the character to be 170 cm tall. The
uniform scale can be adjusted in maya to make it work for different sized
characters.
:return: Scale matrix
:rtype: OpenMaya.MMatrix
"""
scale = 170 / 1.5
return OpenMaya.MMatrix(
[
1.0 * scale, 0.0, 0.0, 0.0,
0.0, -1.0 * scale, 0.0, 0.0,
0.0, 0.0, -1.0 * scale, 0.0,
0.0, 0.0, 0.0, 1.0
]
)
# ----------------------------------------------------------------------------
示例7: _connect_driver_matrix_network
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def _connect_driver_matrix_network(blend, node, driver, index, to_parent_local):
# The multMatrix node will calculate the transformation to blend to when driven
# by this driver transform: driverWorld * nodeOffsetToDriver * nodeParentInverse
mult = cmds.createNode(
"multMatrix", name="spaceswitch_{}_to_{}".format(node, driver)
)
offset = (
OpenMaya.MMatrix(cmds.getAttr("{}.worldMatrix[0]".format(node)))
* OpenMaya.MMatrix(cmds.getAttr("{}.matrix".format(node))).inverse()
* OpenMaya.MMatrix(cmds.getAttr("{}.worldInverseMatrix[0]".format(driver)))
)
cmds.setAttr("{}.matrixIn[0]".format(mult), list(offset), type="matrix")
cmds.connectAttr("{}.worldMatrix[0]".format(driver), "{}.matrixIn[1]".format(mult))
if to_parent_local:
cmds.connectAttr(to_parent_local, "{}.matrixIn[2]".format(mult))
cmds.connectAttr(
"{}.matrixSum".format(mult), "{}.target[{}].targetMatrix".format(blend, index)
)
示例8: local_offset
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def local_offset(node):
"""Get the local matrix relative to the node's parent.
This takes in to account the offsetParentMatrix
:param node: Node name
:return: MMatrix
"""
offset = OpenMaya.MMatrix(cmds.getAttr("{}.worldMatrix[0]".format(node)))
parent = cmds.listRelatives(node, parent=True, path=True)
if parent:
pinv = OpenMaya.MMatrix(
cmds.getAttr("{}.worldInverseMatrix[0]".format(parent[0]))
)
offset *= pinv
return offset
示例9: bindToSkin
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def bindToSkin(meshPaths, skinIndex, skinWeight,
skinJnts, numMaxInfluences):
asl = om.MSelectionList()
asl.clear()
jntNames = [sj.name for sj in skinJnts]
for sj in skinJnts:
m = om.MMatrix(sj.bindPose.tolist())
m = om.MTransformationMatrix(m)
om.MFnTransform(sj.path).setTransformation(m)
asl.add(sj.path)
offset = 0
for meshPath in meshPaths:
mesh = om.MFnMesh(meshPath)
sl = om.MSelectionList(asl)
sl.add(meshPath)
om.MGlobal.setActiveSelectionList(sl)
meshName = om.MFnDagNode(mesh.parent(0)).name()
skinName = cmds.skinCluster(maximumInfluences = numMaxInfluences,
name = meshName + 'Cluster',
toSelectedBones = True)[0]
skinObj = om.MGlobal.getSelectionListByName(skinName).getDependNode(0)
skin = oma.MFnSkinCluster(skinObj)
vertexIndices = om.MIntArray(mesh.numVertices, 0)
for i in xrange(mesh.numVertices):
vertexIndices[i] = i
singleIndexedComp = om.MFnSingleIndexedComponent()
vertexComp = singleIndexedComp.create(om.MFn.kMeshVertComponent)
singleIndexedComp.addElements(vertexIndices)
infDags = skin.influenceObjects()
numInfDags = len(infDags)
infIndices = om.MIntArray(numInfDags, 0)
for i in xrange(numInfDags):
infIndices[i] = i
weights = om.MDoubleArray(mesh.numVertices * numInfDags, 0)
for v in xrange(mesh.numVertices):
for j, w in zip(skinIndex[offset + v], skinWeight[offset + v]):
if j >= 0:
weights[v * numInfDags + j] = w
skin.setWeights(meshPath, vertexComp, infIndices, weights)
offset += mesh.numVertices
skin.findPlug('deformUserNormals', True).setBool(False)
示例10: _initializeTemporalyVariables
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def _initializeTemporalyVariables(self):
# type: () -> None
self.hiColor = om.MColor(om.MVector(1, 1, 0))
self.xcolor = om.MColor(om.MVector(1, 0, 0))
self.xmat = om.MMatrix((
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(1, 0, 0, 1)
))
self.ycolor = om.MColor(om.MVector(0, 1, 0))
self.ymat = om.MMatrix((
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(0, 1, 0, 1)
))
self.zcolor = om.MColor(om.MVector(0, 0, 1))
self.zmat = om.MMatrix((
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(0, 0, 1, 1)
))
self.grayColor = om.MColor(om.MVector(0.3, 0.3, 0.3))
self.coneRadius = 0.1
self.coneHeight = 0.6
# ------------------------------------------------------------------------
示例11: _draw
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def _draw(self, manager, dagPath, tool, activeAxis):
# type: (omui.MUIDrawManager, om.MDagPath, Text, int) -> None
"""Draw manipulator shape using MUIDrawManager.
Depending the tool context, draw arrow gizmo or spherical gizmo.
"""
worldMat = dagPath.inclusiveMatrix().homogenize()
rotMat = om.MMatrix(worldMat)
rotMat.setElement(3, 0, 0.0)
rotMat.setElement(3, 1, 0.0)
rotMat.setElement(3, 2, 0.0)
# start point position
posx = worldMat.getElement(3, 0)
posy = worldMat.getElement(3, 1)
posz = worldMat.getElement(3, 2)
point = om.MPoint(posx, posy, posz)
xcol = self.hiColor if activeAxis == 0 else self.xcolor
ycol = self.hiColor if activeAxis == 1 else self.ycolor
zcol = self.hiColor if activeAxis == 2 else self.zcolor
manager.beginDrawInXray()
if "move" == tool:
self._drawArrow(manager, point, worldMat, rotMat, self.xmat, xcol)
self._drawArrow(manager, point, worldMat, rotMat, self.ymat, ycol)
self._drawArrow(manager, point, worldMat, rotMat, self.zmat, zcol)
elif "rotate" == tool:
self._drawCircle(manager, point, worldMat, rotMat, self.xmat, xcol)
self._drawCircle(manager, point, worldMat, rotMat, self.ymat, ycol)
self._drawCircle(manager, point, worldMat, rotMat, self.zmat, zcol)
manager.endDrawInXray()
示例12: _drawCircle
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def _drawCircle(self, manager, basePoint, worldMat, rotMat, distanceMat, color):
# type: (omui.MUIDrawManager, om.MPoint, om.MMatrix, om.MMatrix, om.MMatrix, om.MColor) -> None
# TODO(implement later): draw gray color half side not facing camera
camZoom = self._zoomRatio(basePoint)
endMat = worldMat + (distanceMat * camZoom * rotMat)
posx = endMat.getElement(3, 0)
posy = endMat.getElement(3, 1)
posz = endMat.getElement(3, 2)
# startVec = om.MVector(posx * -1, posy, posz)
# endVec = om.MVector(posx, posy, posz)
direction = om.MVector()
direction.x = basePoint.x - posx
direction.y = basePoint.y - posy
direction.z = basePoint.z - posz
manager.setColor(color)
manager.circle(basePoint, direction, 0.84 * camZoom, False)
# color arc
# arc(center, start, end, normal, radius, filled=False) -> self
# arc2d(center, start, end, radius, filled=False) -> self
# gray circle
# manager.setColor(self.grayColor)
# manager.arc(basePoint, startVec, endVec, direction, 0.84 * camZoom, False)
示例13: local_matrix
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def local_matrix(self):
m = OpenMaya.MMatrix(cmds.getAttr("{}.worldMatrix[0]".format(self.twist_joint)))
pinv = OpenMaya.MMatrix(
cmds.getAttr("{}.worldInverseMatrix[0]".format(self.start_joint))
)
return m * pinv
示例14: create_space_switch
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def create_space_switch(
node, drivers, switch_attribute=None, use_translate=True, use_rotate=True
):
"""Creates a space switch network.
The network uses the offsetParentMatrix attribute and does not create any
constraints or new dag nodes.
:param node: Transform to drive
:param drivers: List of tuples: [(driver1, "spaceName1"), (driver2, "spaceName2")]
:param switch_attribute: Name of the switch attribute to create on the target node.
"""
if switch_attribute is None:
switch_attribute = "space"
if cmds.objExists("{}.{}".format(node, switch_attribute)):
cmds.deleteAttr(node, at=switch_attribute)
names = [d[1] for d in drivers]
cmds.addAttr(node, ln=switch_attribute, at="enum", en=":".join(names), keyable=True)
# Create attribute to toggle translation in the matrices
enable_translate_attr = _create_bool_attribute(
node, "{}UseTranslate".format(switch_attribute), use_translate
)
# Create attribute to toggle rotation in the matrices
enable_rotate_attr = _create_bool_attribute(
node, "{}UseRotate".format(switch_attribute), use_rotate
)
blend = cmds.createNode("blendMatrix", name="{}_spaceswitch".format(node))
# Get the current offset parent matrix. This is used as the starting blend point
m = OpenMaya.MMatrix(cmds.getAttr("{}.offsetParentMatrix".format(node)))
cmds.setAttr("{}.inputMatrix".format(blend), list(m), type="matrix")
parent = cmds.listRelatives(node, parent=True, path=True)
to_parent_local = "{}.worldInverseMatrix[0]".format(parent[0]) if parent else None
for i, driver in enumerate(drivers):
driver = driver[0]
_connect_driver_matrix_network(blend, node, driver, i, to_parent_local)
target_attr = "{}.target[{}]".format(blend, i)
# Hook up the weight toggle when switching spaces
dge(
"x = switch == {} ? 1 : 0".format(i),
x="{}.weight".format(target_attr),
switch="{}.{}".format(node, switch_attribute),
)
# Connect the translation, rotation toggles
cmds.connectAttr(enable_translate_attr, "{}.useTranslate".format(target_attr))
cmds.connectAttr(enable_rotate_attr, "{}.useRotate".format(target_attr, i))
cmds.connectAttr(
"{}.outputMatrix".format(blend), "{}.offsetParentMatrix".format(node)
)
示例15: _create_twist_decomposition_network
# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MMatrix [as 别名]
def _create_twist_decomposition_network(driver, twist_axis):
"""Create the twist decomposition network for driver.
:param driver: Driver transform
:param twist_axis: Local twist axis on driver
"""
# Connect message attributes to the decomposed twist nodes so we can reuse them
# if the network is driving multiple nodes
mult = cmds.createNode("multMatrix", name="{}_local_matrix".format(driver))
parent_inverse = "{}.parentInverseMatrix[0]".format(driver)
world_matrix = "{}.worldMatrix[0]".format(driver)
cmds.connectAttr(world_matrix, "{}.matrixIn[0]".format(mult))
cmds.connectAttr(parent_inverse, "{}.matrixIn[1]".format(mult))
pinv = OpenMaya.MMatrix(cmds.getAttr(parent_inverse))
m = OpenMaya.MMatrix(cmds.getAttr(world_matrix))
inv_local_rest_matrix = (m * pinv).inverse()
cmds.setAttr(
"{}.matrixIn[2]".format(mult), list(inv_local_rest_matrix), type="matrix"
)
rotation = cmds.createNode("decomposeMatrix", name="{}_rotation".format(driver))
cmds.connectAttr("{}.matrixSum".format(mult), "{}.inputMatrix".format(rotation))
twist = cmds.createNode("quatNormalize", name="{}_twist".format(driver))
cmds.connectAttr(
"{}.outputQuat.outputQuatW".format(rotation),
"{}.inputQuat.inputQuatW".format(twist),
)
axis = "XYZ"[twist_axis]
cmds.connectAttr(
"{}.outputQuat.outputQuat{}".format(rotation, axis),
"{}.inputQuat.inputQuat{}".format(twist, axis),
)
# swing = twist.inverse() * rotation
inv_twist = cmds.createNode("quatInvert", name="{}_inverse_twist".format(driver))
cmds.connectAttr("{}.outputQuat".format(twist), "{}.inputQuat".format(inv_twist))
swing = cmds.createNode("quatProd", name="{}_swing".format(driver))
cmds.connectAttr("{}.outputQuat".format(inv_twist), "{}.input1Quat".format(swing))
cmds.connectAttr("{}.outputQuat".format(rotation), "{}.input2Quat".format(swing))
inv_swing = cmds.createNode("quatInvert", name="{}_inverse_swing".format(driver))
cmds.connectAttr("{}.outputQuat".format(swing), "{}.inputQuat".format(inv_swing))
# Connect the nodes to the driver so we can find and reuse them for multiple setups
for node, attr in [
(twist, TWIST_OUTPUT),
(inv_twist, INV_TWIST_OUTPUT),
(swing, SWING_OUTPUT),
(inv_swing, INV_SWING_OUTPUT),
]:
cmds.connectAttr("{}.message".format(node), "{}.{}".format(driver, attr))