当前位置: 首页>>代码示例>>Python>>正文


Python OpenMaya.MPoint方法代码示例

本文整理汇总了Python中maya.api.OpenMaya.MPoint方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MPoint方法的具体用法?Python OpenMaya.MPoint怎么用?Python OpenMaya.MPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在maya.api.OpenMaya的用法示例。


在下文中一共展示了OpenMaya.MPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _drawArrow

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [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) 
开发者ID:yamahigashi,项目名称:MayaManipulatorDrawer,代码行数:26,代码来源:sceneRenderOverride.py

示例2: _zoomRatio

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def _zoomRatio(self, basePoint):
        # type: (om.MPoint) -> float
        """Calculate zoom factor as distance from the current view's camera position."""
        # FIXME: all views share this value from current one.

        # camera distance
        cameraPath = omui.M3dView.active3dView().getCamera()
        camNode = om.MFnDependencyNode(cameraPath.node())
        isOrtho = camNode.findPlug("orthographic", False)

        camMat = cameraPath.inclusiveMatrix().homogenize()
        camPos = om.MPoint(
            camMat.getElement(3, 0),
            camMat.getElement(3, 1),
            camMat.getElement(3, 2),
        )

        if isOrtho.asBool():
            orthoWidth = camNode.findPlug("orthographicWidth", False).asFloat()
            return math.ldexp(orthoWidth, 3) * 0.01
        else:
            return basePoint.distanceTo(camPos) * 0.1 
开发者ID:yamahigashi,项目名称:MayaManipulatorDrawer,代码行数:24,代码来源:sceneRenderOverride.py

示例3: distance

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def distance(node1=None, node2=None):
    """Calculate the distance between two nodes

    :param node1: First node
    :param node2: Second node
    :return: The distance
    """
    if node1 is None or node2 is None:
        # Default to selection
        selection = cmds.ls(sl=True, type='transform')
        if len(selection) != 2:
            raise RuntimeError('Select 2 transforms.')
        node1, node2 = selection

    pos1 = cmds.xform(node1, query=True, worldSpace=True, translation=True)
    pos2 = cmds.xform(node2, query=True, worldSpace=True, translation=True)

    pos1 = OpenMaya.MPoint(pos1[0], pos1[1], pos1[2])
    pos2 = OpenMaya.MPoint(pos2[0], pos2[1], pos2[2])
    return pos1.distanceTo(pos2) 
开发者ID:chadmv,项目名称:cmt,代码行数:22,代码来源:shortcuts.py

示例4: vector_to

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def vector_to(source=None, target=None):
    """Calculate the distance between two nodes

    :param source: First node
    :param target: Second node
    :return: MVector (API2)
    """
    if source is None or target is None:
        # Default to selection
        selection = cmds.ls(sl=True, type='transform')
        if len(selection) != 2:
            raise RuntimeError('Select 2 transforms.')
        source, target = selection

    pos1 = cmds.xform(source, query=True, worldSpace=True, translation=True)
    pos2 = cmds.xform(target, query=True, worldSpace=True, translation=True)

    source = OpenMaya2.MPoint(pos1[0], pos1[1], pos1[2])
    target = OpenMaya2.MPoint(pos2[0], pos2[1], pos2[2])
    return target - source 
开发者ID:chadmv,项目名称:cmt,代码行数:22,代码来源:shortcuts.py

示例5: check_last_edge

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def check_last_edge(self):
        try:
            if len(self.sub_edges) == 1:
                #print 'check last edge'
                self.last_edge = self.sub_edges[0]
            else:
                #print 'check last edge'
                dist = float('inf')
                pos_a = om.MPoint(cmds.pointPosition(self.mesh[0]+'.vtx['+str(self.num_list[0])+']', w=True))
                for e in self.sub_edges:
                    e_vtx = common.conv_comp(e, mode='vtx')
                    #print 'checking last :', e, e_vtx
                    pos_b = om.MPoint(cmds.pointPosition(e_vtx[0], w=True))
                    pos_c = om.MPoint(cmds.pointPosition(e_vtx[1], w=True))
                    l = (pos_a-pos_b).length() + (pos_a-pos_c).length()
                    if dist < l:
                        continue
                    self.last_edge = e
                    dist = l
            self.uv_edge = self.edge+[self.last_edge]
            #print 'get last edge:', self.last_edge
            last_num = self.vtx2num(common.conv_comp(self.last_edge, mode='vtx'))
            for num in self.num_list[:]:
                if num in last_num:
                    continue
                else:
                    last_num.append(num)
            self.num_list = last_num
            #print 'new num_list :',self.num_list
        except Exception as e:
            print e.message, common.location()
            print (traceback.format_exc())
            #print 'check edge error'
        
        
    #初期値リセット 
开发者ID:ShikouYamaue,项目名称:SISideBar,代码行数:38,代码来源:append_polygon.py

示例6: editCurve

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def editCurve(parent, points, degree=1, form=kOpen):
    assert isinstance(parent, DagNode), (
        "parent must be of type cmdx.DagNode"
    )

    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()

    for point in points:
        cvs.append(om1.MPoint(*point))

    mobj = curveFn.createWithEditPoints(cvs,
                                        degree,
                                        form,
                                        False,
                                        False,
                                        True,
                                        _encode1(parent.path()))

    mod = om1.MDagModifier()
    mod.renameNode(mobj, parent.name(namespace=True) + "Shape")
    mod.doIt()

    def undo():
        mod.deleteNode(mobj)
        mod.doIt()

    def redo():
        mod.undoIt()

    commit(undo, redo)

    shapeFn = om1.MFnDagNode(mobj)
    return encode(shapeFn.fullPathName()) 
开发者ID:mottosso,项目名称:cmdx,代码行数:38,代码来源:cmdx.py

示例7: _draw

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [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() 
开发者ID:yamahigashi,项目名称:MayaManipulatorDrawer,代码行数:39,代码来源:sceneRenderOverride.py

示例8: _drawCircle

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [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) 
开发者ID:yamahigashi,项目名称:MayaManipulatorDrawer,代码行数:29,代码来源:sceneRenderOverride.py

示例9: create_orient_manipulator

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def create_orient_manipulator(joint, material):
    joint_scale = cmds.jointDisplayScale(query=True)
    joint_radius = cmds.getAttr("{0}.radius".format(joint))
    radius = joint_scale * joint_radius
    children = cmds.listRelatives(joint, children=True, path=True)
    if children:
        p1 = cmds.xform(joint, q=True, ws=True, t=True)
        p1 = OpenMaya.MPoint(*p1)
        p2 = cmds.xform(children[0], q=True, ws=True, t=True)
        p2 = OpenMaya.MPoint(*p2)
        radius = p1.distanceTo(p2)
    arrow_cvs = [
        [-1, 0, 0],
        [-1, 2, 0],
        [-2, 2, 0],
        [0, 4, 0],
        [2, 2, 0],
        [1, 2, 0],
        [1, 0, 0],
        [-1, 0, 0],
    ]
    arrow_cvs = [[x[0] * radius, x[1] * radius, x[2] * radius] for x in arrow_cvs]
    shape = cmds.curve(name="{0}_zForward".format(joint), degree=1, point=arrow_cvs)
    # shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0]
    # cmds.setAttr('{0}.sz'.format(shape), 0)
    # cmds.select(shape)
    # cmds.hyperShade(assign=material)
    group = cmds.createNode("transform", name="{0}_grp".format(shape))
    cmds.parent(shape, group)
    cmds.makeIdentity(shape, apply=True)
    cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType="message")
    cmds.connectAttr(
        "{0}.message".format(joint), "{0}.{1}".format(shape, MESSAGE_ATTRIBUTE)
    )
    for attr in ["tx", "ty", "tz", "ry", "rz", "v"]:
        cmds.setAttr("{0}.{1}".format(shape, attr), lock=True, keyable=False)
    return group, shape 
开发者ID:chadmv,项目名称:cmt,代码行数:39,代码来源:orientjoints.py

示例10: get_position

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def get_position(node):
    p = cmds.xform(node, q=True, ws=True, t=True)
    return OpenMaya.MPoint(p) 
开发者ID:chadmv,项目名称:cmt,代码行数:5,代码来源:orientjoints.py

示例11: mirror_curve

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def mirror_curve(source, destination):
    """Mirrors the curve on source across the YZ plane to destination.

    The cvs will be mirrored in world space no matter the transform of destination.

    :param source: Source transform
    :param destination: Destination transform
    :return: The mirrored CurveShape object
    """
    source_curve = CurveShape(source)

    path_source = shortcuts.get_dag_path2(source)
    matrix = path_source.inclusiveMatrix()

    path_destination = shortcuts.get_dag_path2(destination)
    inverse_matrix = path_destination.inclusiveMatrixInverse()

    world_cvs = [OpenMaya.MPoint(*x) * matrix for x in source_curve.cvs]
    for cv in world_cvs:
        cv.x *= -1
    local_cvs = [p * inverse_matrix for p in world_cvs]
    source_curve.cvs = [(p.x, p.y, p.z) for p in local_cvs]
    is_controller = cmds.controller(source, q=True, isController=True)
    source_curve.transform = destination
    source_curve.create(destination, as_controller=is_controller)
    return source_curve 
开发者ID:chadmv,项目名称:cmt,代码行数:28,代码来源:control.py

示例12: retarget

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def retarget(source, target, shapes, rbf=None, radius=0.5, stride=1):
    """Run the mesh retarget.

    :param source: Source mesh
    :param target: Modified source mesh
    :param shapes: List of meshes to retarget
    :param rbf: One of the RBF functions. See class RBF
    :param radius: Smoothing parameter for the rbf
    :param stride: Vertex stride to sample on the source mesh.  Increase to speed up
    the calculation but less accurate.
    """
    start_time = time.time()
    source_points = points_to_np_array(source, stride)
    target_points = points_to_np_array(target, stride)

    if rbf is None:
        rbf = RBF.linear
    weights = get_weight_matrix(source_points, target_points, rbf, radius)

    for shape in shapes:
        points = points_to_np_array(shape)
        n_points = points.shape[0]
        dist = get_distance_matrix(points, source_points, rbf, radius)
        identity = np.ones((n_points, 1))
        h = np.bmat([[dist, identity, points]])
        deformed = np.asarray(np.dot(h, weights))
        points = [OpenMaya.MPoint(*p) for p in deformed]
        dupe = cmds.duplicate(
            shape, name="{}_{}_{}".format(shape, radius, rbf.__name__)
        )[0]
        set_points(dupe, points)

    end_time = time.time()
    print("Transferred in {} seconds".format(end_time - start_time)) 
开发者ID:chadmv,项目名称:cmt,代码行数:36,代码来源:meshretarget.py

示例13: points_to_np_array

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def points_to_np_array(mesh, stride=1):
    points = get_points(mesh)
    sparse_points = [OpenMaya.MPoint(p) for p in points][::stride]
    np_points = np.array([[p.x, p.y, p.z] for p in sparse_points])
    return np_points 
开发者ID:chadmv,项目名称:cmt,代码行数:7,代码来源:meshretarget.py

示例14: to_maya_mesh

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def to_maya_mesh(self, mesh):

        points = OpenMaya.MPointArray()
        for p in self.points:
            points.append(OpenMaya.MPoint(p[0], p[1], p[2]))
        shortcuts.set_points(mesh, points) 
开发者ID:chadmv,项目名称:cmt,代码行数:8,代码来源:np_mesh.py

示例15: NurbsCurveData

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MPoint [as 别名]
def NurbsCurveData(points, degree=1, form=om1.MFnNurbsCurve.kOpen):
    """Tuple of points to MObject suitable for nurbsCurve-typed data

    Arguments:
        points (tuple): (x, y, z) tuples per point
        degree (int, optional): Defaults to 1 for linear
        form (int, optional): Defaults to MFnNurbsCurve.kOpen,
            also available kClosed

    Example:
        Create a new nurbs curve like this.

        >>> data = NurbsCurveData(
        ...     points=(
        ...         (0, 0, 0),
        ...         (0, 1, 0),
        ...         (0, 2, 0),
        ...     ))
        ...
        >>> parent = createNode("transform")
        >>> shape = createNode("nurbsCurve", parent=parent)
        >>> shape["cached"] = data

    """

    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()
    data = om1.MFnNurbsCurveData()
    mobj = data.create()

    for point in points:
        cvs.append(om1.MPoint(*point))

    curveFn.createWithEditPoints(cvs,
                                 degree,
                                 form,
                                 False,
                                 False,
                                 True,
                                 mobj)

    return mobj 
开发者ID:mottosso,项目名称:cmdx,代码行数:46,代码来源:cmdx.py


注:本文中的maya.api.OpenMaya.MPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。