當前位置: 首頁>>代碼示例>>Python>>正文


Python OpenMaya.MScriptUtil方法代碼示例

本文整理匯總了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) 
開發者ID:wiremas,項目名稱:spore,代碼行數:24,代碼來源:spore_sampler.py

示例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)) 
開發者ID:wiremas,項目名稱:spore,代碼行數:24,代碼來源:spore_sampler.py

示例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) 
開發者ID:wiremas,項目名稱:spore,代碼行數:20,代碼來源:brush_state.py

示例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) 
開發者ID:wiremas,項目名稱:spore,代碼行數:20,代碼來源:window_utils.py

示例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
###################################### 
開發者ID:mgear-dev,項目名稱:mgear_core,代碼行數:24,代碼來源:skin.py

示例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 
開發者ID:robertjoosten,項目名稱:maya-skinning-tools,代碼行數:26,代碼來源:skin.py

示例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() 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:18,代碼來源:mayascenewrapper.py

示例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 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:24,代碼來源:mayascenewrapper.py

示例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 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:31,代碼來源:sqSpaceSwitcher.py

示例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] 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:17,代碼來源:dpUtils.py

示例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


# ---------------------------------------------------------------------------- 
開發者ID:robertjoosten,項目名稱:maya-spline-ik,代碼行數:28,代碼來源:curve.py

示例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)) 
開發者ID:wiremas,項目名稱:spore,代碼行數:31,代碼來源:spore_context.py

示例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)) 
開發者ID:wiremas,項目名稱:spore,代碼行數:31,代碼來源:spore_context.py

示例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) 
開發者ID:wiremas,項目名稱:spore,代碼行數:32,代碼來源:geo_cache.py

示例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 
開發者ID:wiremas,項目名稱:spore,代碼行數:17,代碼來源:mesh_utils.py


注:本文中的maya.OpenMaya.MScriptUtil方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。