本文整理汇总了Python中maya.OpenMaya.MScriptUtil方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MScriptUtil方法的具体用法?Python OpenMaya.MScriptUtil怎么用?Python OpenMaya.MScriptUtil使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MScriptUtil方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample_triangle
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def sample_triangle(self,triangle_id, point_id):
""" sample a random point on a the given triangle """
r = random.random()
s = random.random()
if r + s >= 1:
r = 1 - r
s = 1 - s
r = om.MScriptUtil(r).asFloat()
s = om.MScriptUtil(s).asFloat()
r = self.geo_cache.AB[triangle_id] * r
s = self.geo_cache.AC[triangle_id] * s
p = om.MPoint(r + s + om.MVector(self.geo_cache.p0[triangle_id]))
u = 0
v = 0
self.point_data.set(point_id, p, self.geo_cache.normals[triangle_id],
self.geo_cache.poly_id[triangle_id], u, v)
示例2: get_rotation
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def get_rotation(self, direction, weight, min_rot, max_rot):
""" get rotation from a matrix pointing towards the given direction
slerped by the given weight into the world up vector and added a random
rotation between min and max rotation """
r_x = math.radians(random.uniform(min_rot[0], max_rot[0]))
r_y = math.radians(random.uniform(min_rot[1], max_rot[1]))
r_z = math.radians(random.uniform(min_rot[2], max_rot[2]))
util = om.MScriptUtil()
util.createFromDouble(r_x, r_y, r_z)
rotation_ptr = util.asDoublePtr()
matrix = om.MTransformationMatrix()
matrix.setRotation(rotation_ptr, om.MTransformationMatrix.kXYZ)
world_up = om.MVector(0, 1, 0)
rotation = om.MQuaternion(world_up, direction, weight)
matrix = matrix.asMatrix() * rotation.asMatrix()
rotation = om.MTransformationMatrix(matrix).rotation().asEulerRotation()
return om.MVector(math.degrees(rotation.x),
math.degrees(rotation.y),
math.degrees(rotation.z))
示例3: world_to_view
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def world_to_view(self, position, invert_y=True):
""" convert the given 3d position to 2d viewpor coordinates
:param invert_y bool: convert between qt and maya coordinane space """
view = window_utils.active_view()
x_util = om.MScriptUtil()
y_util = om.MScriptUtil()
x_ptr = x_util.asShortPtr()
y_ptr = y_util.asShortPtr()
view.worldToView(position, x_ptr, y_ptr)
x_pos = x_util.getShort(x_ptr)
y_pos = y_util.getShort(y_ptr)
if invert_y:
y_pos = view.portHeight() - y_pos
return (x_pos, y_pos)
示例4: world_to_view
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def world_to_view(position, invert_y=True):
""" convert the given 3d position to 2d viewpor coordinates
:param invert_y bool: convert between qt and maya coordinane space """
view = active_view()
x_util = om.MScriptUtil()
y_util = om.MScriptUtil()
x_ptr = x_util.asShortPtr()
y_ptr = y_util.asShortPtr()
view.worldToView(position, x_ptr, y_ptr)
x_pos = x_util.getShort(x_ptr)
y_pos = y_util.getShort(y_ptr)
if invert_y:
y_pos = view.portHeight() - y_pos
return (x_pos, y_pos)
示例5: getCurrentWeights
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [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
######################################
示例6: getSkinWeights
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def getSkinWeights(dag, skinCluster, component):
"""
Get the skin weights of the original vertex and of its connected vertices.
:param OpenMaya.MDagPath dag:
:param OpenMayaAnim.MFnSkinCluster skinCluster:
:param OpenMaya.MFn.kMeshVertComponent component:
:return: skin weights and number of influences
:rtype: tuple(OpenMaya.MDoubleArray, int)
"""
# weights variables
weights = OpenMaya.MDoubleArray()
# influences variables
influenceMSU = OpenMaya.MScriptUtil()
influencePTR = influenceMSU.asUintPtr()
# get weights
skinCluster.getWeights(dag, component, weights, influencePTR)
# get num influences
num = OpenMaya.MScriptUtil.getUint(influencePTR)
return weights, num
示例7: _getchildShapeNodes
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [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 MScriptUtil [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: _get_tm_offset
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def _get_tm_offset(self, _nParent, _nDriven=None, _type="t"):
"""
Get the offset between the driven and a driver node
"""
if _nDriven is None:
_nDriven = self.nSwConstRecept
mStart = om.MMatrix()
mEnd = om.MMatrix()
wmStart = _nParent.worldMatrix.get().__melobject__()
wmEnd = _nDriven.worldMatrix.get().__melobject__()
om.MScriptUtil().createMatrixFromList(wmStart, mStart)
om.MScriptUtil().createMatrixFromList(wmEnd, mEnd)
mOut = om.MTransformationMatrix(mEnd * mStart.inverse())
if _type == "t":
# Extract Translation
vTran = om.MVector(mOut.getTranslation(om.MSpace.kTransform))
vTranPymel = [vTran.x, vTran.y, vTran.z]
return vTranPymel
if _type == "r":
# Extract Rotation
ro = _nDriven.rotateOrder.get()
vRot = om.MEulerRotation(mOut.eulerRotation().reorder(ro))
vRotDeg = [math.degrees(vRot.x), math.degrees(vRot.y), math.degrees(vRot.z)]
return vRotDeg
示例10: extract_world_scale_from_matrix
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def extract_world_scale_from_matrix(obj):
world_matrix = cmds.getAttr(obj + ".worldMatrix")
mMat = om.MMatrix()
om.MScriptUtil.createMatrixFromList(world_matrix, mMat)
mTransform = om.MTransformationMatrix(mMat)
scale_util = om.MScriptUtil()
scale_util.createFromDouble(0.0, 0.0, 0.0)
ptr = scale_util.asDoublePtr()
mTransform.getScale(ptr, om.MSpace.kWorld)
x_scale = om.MScriptUtil.getDoubleArrayItem(ptr, 0)
y_scale = om.MScriptUtil.getDoubleArrayItem(ptr, 1)
z_scale = om.MScriptUtil.getDoubleArrayItem(ptr, 2)
return [x_scale, y_scale, z_scale]
示例11: nearestPointOnCurve
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def nearestPointOnCurve(curve, pos):
"""
Find the nearest point on a curve, the function will return
the parameter and point. The point is of type OpenMaya.MPoint.
:param str curve:
:param list pos:
:return: parameter, point
:rtype: float, OpenMaya.MPoint
"""
mFnCurve = api.asMFnNurbsCurve(curve)
pUtil = OpenMaya.MScriptUtil()
pPtr = pUtil.asDoublePtr()
point = mFnCurve.closestPoint(
OpenMaya.MPoint(*pos),
pPtr,
0.001,
OpenMaya.MSpace.kWorld
)
return pUtil.getDouble(pPtr), point
# ----------------------------------------------------------------------------
示例12: randomize_rotation
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def randomize_rotation(self, rotation, random_weight):
""" randomize the given rotation values by 10 degrees multiply
by the random_weight """
factor = 5 * random_weight
rand_x = np.radians(random.uniform(-factor, factor))
rand_y = np.radians(random.uniform(-factor, factor))
rand_z = np.radians(random.uniform(-factor, factor))
util = om.MScriptUtil()
util.createFromDouble(rand_x, rand_y, rand_z)
rand_rot_ptr = util.asDoublePtr()
rand_mat = om.MTransformationMatrix()
rand_mat.setRotation(rand_rot_ptr, om.MTransformationMatrix.kXYZ)
util.createFromDouble(np.radians(rotation.x),
np.radians(rotation.y),
np.radians(rotation.z))
rot_ptr = util.asDoublePtr()
rot_mat = om.MTransformationMatrix()
rot_mat.setRotation(rot_ptr, om.MTransformationMatrix.kXYZ)
result_mat = rot_mat.asMatrix() * rand_mat.asMatrix()
rotation = om.MTransformationMatrix(result_mat).rotation()
return om.MVector(math.degrees(rotation.asEulerRotation().x),
math.degrees(rotation.asEulerRotation().y),
math.degrees(rotation.asEulerRotation().z))
示例13: rotate_into
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def rotate_into(self, direction, rotation):
""" slerp the given rotation values into the direction given
by the brush_state
@param direction MVector: the target direction
@param rotation MVector: current euler rotation """
vector_weight = self.brush_state.settings['strength']
up_vector = om.MVector(0, 1, 0)
local_up = up_vector.rotateBy(om.MEulerRotation(math.radians(rotation.x),
math.radians(rotation.y),
math.radians(rotation.z)))
target_rotation = om.MQuaternion(local_up, direction, vector_weight)
util = om.MScriptUtil()
x_rot = np.radians(rotation.x)
y_rot = np.radians(rotation.y)
z_rot = np.radians(rotation.z)
util.createFromDouble(x_rot, y_rot, z_rot)
rotation_ptr = util.asDoublePtr()
mat = om.MTransformationMatrix()
mat.setRotation(rotation_ptr, om.MTransformationMatrix.kXYZ)
mat = mat.asMatrix() * target_rotation.asMatrix()
rotation = om.MTransformationMatrix(mat).rotation()
return om.MVector(math.degrees(rotation.asEulerRotation().x),
math.degrees(rotation.asEulerRotation().y),
math.degrees(rotation.asEulerRotation().z))
示例14: create_uv_lookup
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def create_uv_lookup(self):
""" create a dict with an entry for every vertex and a list of
neighbouring faces as well as a kd tree tro look up close face ids """
self.logger.debug('Create UV lookup for the current GeoCache')
util = om.MScriptUtil()
connected_faces = om.MIntArray()
mesh_fn = om.MFnMesh(self.mesh)
num_verts = mesh_fn.numVertices()
points = np.zeros(shape=(num_verts, 2))
vert_iter = om.MItMeshVertex(self.mesh)
while not vert_iter.isDone():
index = vert_iter.index()
vert_iter.getConnectedFaces(connected_faces)
self.neighbor_lookup[index] = [connected_faces[i] for i in xrange(connected_faces.length())]
util.createFromDouble(0.0, 0.0)
uv_ptr = util.asFloat2Ptr()
vert_iter.getUV(uv_ptr)
u_coord = util.getFloat2ArrayItem(uv_ptr, 0, 0)
v_coord = util.getFloat2ArrayItem(uv_ptr, 0, 1)
points[index] = (u_coord, v_coord)
vert_iter.next()
self.uv_kd_tree = kd_tree(points)
示例15: get_uv_at_point
# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MScriptUtil [as 别名]
def get_uv_at_point(target, point, uv_set=None, poly_id=None):
""" get closest UV coords of the target at the given point
:param target str: name of the target object
:param point MPoint: """
util = om.MScriptUtil()
uv_coords_ptr = util.asFloat2Ptr()
mesh_fn = get_mesh_fn(target)
mesh_fn.getUVAtPoint(point, uv_coords_ptr, om.MSpace.kObject, uv_set, poly_id)
u_coord = util.getFloat2ArrayItem(uv_coords_ptr, 0, 0)
v_coord = util.getFloat2ArrayItem(uv_coords_ptr, 0, 1)
return u_coord, v_coord