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


Python OpenMaya.MFnMesh方法代码示例

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


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

示例1: get_mesh_fn

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def get_mesh_fn(target):
    """ get mesh function set for the given target
    :param target: dag path of the mesh
    :return MFnMesh """

    if isinstance(target, str) or isinstance(target, unicode):
        slls = om.MSelectionList()
        slls.add(target)
        ground_path = om.MDagPath()
        slls.getDagPath(0, ground_path)
        ground_path.extendToShapeDirectlyBelow(0)
        ground_node = ground_path.node()
    elif isinstance(target, om.MObject):
        ground_node = target
        ground_path = target
    elif isinstance(target, om.MDagPath):
        ground_node = target.node()
        ground_path = target
    else:
        raise TypeError('Must be of type str, MObject or MDagPath, is type: {}'.format(type(target)))

    if ground_node.hasFn(om.MFn.kMesh):
        return om.MFnMesh(ground_path)
    else:
        raise TypeError('Target must be of type kMesh') 
开发者ID:wiremas,项目名称:spore,代码行数:27,代码来源:mesh_utils.py

示例2: getNormals

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def getNormals(dag):
    """
    Get the average normal in world space of each vertex on the provided mesh.
    The reason why OpenMaya.MItMeshVertex function has to be used is that the
    MFnMesh class returns incorrect normal results.

    :param OpenMaya.MDagPath dag:
    :return: Normals
    :rtype: list
    """
    # variables
    normals = []

    iter = OpenMaya.MItMeshVertex(dag)
    while not iter.isDone():
        # get normal data
        normal = OpenMaya.MVector()
        iter.getNormal(normal, OpenMaya.MSpace.kWorld)
        normals.append(normal)

        iter.next()

    return normals 
开发者ID:robertjoosten,项目名称:maya-skinning-tools,代码行数:25,代码来源:mesh.py

示例3: asMFnMesh

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def asMFnMesh(dag):
    """
    OpenMaya.MDagPath -> OpenMaya.MfnMesh

    :param OpenMaya.MDagPath dag:
    :rtype: OpenMaya.MfnMesh
    """
    
    return OpenMaya.MFnMesh(dag) 
开发者ID:robertjoosten,项目名称:maya-retarget-blendshape,代码行数:11,代码来源:utils.py

示例4: create_uv_lookup

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [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

示例5: get_meshfn_from_dagpath

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def get_meshfn_from_dagpath(dagpath):
    """ return a functionset for a specified dagpath
    :param dagpath : input dagpath """

    m_dagpath = get_dagpath_from_name(dagpath)
    return om.MFnMesh(m_dagpath) 
开发者ID:wiremas,项目名称:spore,代码行数:8,代码来源:node_utils.py

示例6: getClosestPolygonFromTransform

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def getClosestPolygonFromTransform(geo, loc):
    """Get closest polygon from transform

    Arguments:
        geo (dagNode): Mesh object
        loc (matrix): location transform

    Returns:
        Closest Polygon

    """
    if isinstance(loc, pm.nodetypes.Transform):
        pos = loc.getTranslation(space='world')
    else:
        pos = datatypes.Vector(loc[0], loc[1], loc[2])

    nodeDagPath = OpenMaya.MObject()
    try:
        selectionList = OpenMaya.MSelectionList()
        selectionList.add(geo.name())
        nodeDagPath = OpenMaya.MDagPath()
        selectionList.getDagPath(0, nodeDagPath)
    except Exception as e:
        raise RuntimeError("OpenMaya.MDagPath() failed "
                           "on {}. \n {}".format(geo.name(), e))

    mfnMesh = OpenMaya.MFnMesh(nodeDagPath)

    pointA = OpenMaya.MPoint(pos.x, pos.y, pos.z)
    pointB = OpenMaya.MPoint()
    space = OpenMaya.MSpace.kWorld

    util = OpenMaya.MScriptUtil()
    util.createFromInt(0)
    idPointer = util.asIntPtr()

    mfnMesh.getClosestPoint(pointA, pointB, space, idPointer)
    idx = OpenMaya.MScriptUtil(idPointer).asInt()

    return geo.f[idx], pos 
开发者ID:mgear-dev,项目名称:mgear_core,代码行数:42,代码来源:meshNavigation.py

示例7: getPoints

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def getPoints(dag):
    """
    Get the position in world space of each vertex on the provided mesh.

    :param OpenMaya.MDagPath dag:
    :return: Points
    :rtype: list
    """
    points = OpenMaya.MPointArray()
    mesh = OpenMaya.MFnMesh(dag)
    mesh.getPoints(points, OpenMaya.MSpace.kWorld)

    return [OpenMaya.MVector(points[i]) for i in range(points.length())] 
开发者ID:robertjoosten,项目名称:maya-skinning-tools,代码行数:15,代码来源:mesh.py

示例8: test

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def test(self, node):
        mesh = None
        try:
            mesh = OpenMaya.MFnMesh(node.object())
        except:
            return None

        if mesh.currentUVSetName() != CurrentUVSet.__DefaultSetName:
            return medic.PyReport(node)

        return None 
开发者ID:sol-ansano-kim,项目名称:medic,代码行数:13,代码来源:currentUVSet.py

示例9: fn_createObject_openMaya

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def fn_createObject_openMaya():
    global importedObj

    cmds.select( all = True, hierarchy = True)
    currentObjs = cmds.ls(selection = True )

    newMesh = om.MFnMesh()

    mergeVertices = True
    pointTolerance = 0.0001

    for p in range(0, len(importedObj.polys), 1):
        polylist = []
        vCount = len(importedObj.polys[p])
        polylist = om.MPointArray()
        polylist.setLength(vCount)
        for i in range(vCount):
            polylist.set(importedObj.omVertices[int(importedObj.polys[p][i])], i)

        newMesh.addPolygon(polylist, mergeVertices, pointTolerance)


    if len(importedObj.weightMap) > 0:
        for v in range(0, importedObj.vertexCount , 1):
            c = importedObj.weightMap[v]
            vColor = om.MColor(c,c,c,c )
            newMesh.setVertexColor(vColor,v)

    newMesh.updateSurface()

    cmds.select( all = True, hierarchy = True)
    cmds.select(currentObjs, deselect = True)
    newObjs = cmds.ls(selection = True, transforms = True )
    cmds.select(newObjs, replace = True)
    cmds.sets( newObjs, e=True,forceElement='initialShadingGroup')
    cmds.rename (newObjs, importObjectName) 
开发者ID:heimlich1024,项目名称:OD_CopyPasteExternal,代码行数:38,代码来源:maya_PasteFromExternal.py

示例10: intersect

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def intersect(mesh, point, ray):
    fnMesh = OpenMaya.MFnMesh( core.capi.asMObject(mesh.getShape()).object() )

    p = spaceLocator()
    p.t.set(point)
    p.setParent( mesh )
    
    objSpacePos = p.t.get()

    p.setTranslation( ray, space='world' )

    objSpaceRay = p.t.get() - objSpacePos
    
    point = OpenMaya.MFloatPoint(objSpacePos)
    ray = OpenMaya.MFloatVector(objSpaceRay)
    res = fnMesh.allIntersections(point, ray, OpenMaya.MSpace.kObject, 50, False )

    # -> (hitPoints, hitRayParams, hitFaces, hitTriangles, hitBary1s, hitBary2s)

    if not len(res[0]):
        hits = []
    
    else:
        hits = []
        for hit in res[0]:
            p.t.set( hit.x, hit.y, hit.z)
            hits.append( p.getTranslation(space='world') )
    
    delete(p)
    
    return hits 
开发者ID:patcorwin,项目名称:fossil,代码行数:33,代码来源:rig.py

示例11: validate_cache

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def validate_cache(self):
        """ check if the current cache is valid """

        points = om.MPointArray()
        mesh_fn = om.MFnMesh(self.mesh)
        mesh_fn.getPoints(points)

        if points.length() != self.poly_verts.length():
            self.logger.debug('Validate GeoCache succeded')
            return False

        for i in xrange(points.length()):
            if points[i] != self.poly_verts[i]:
                self.logger.debug('Validate GeoCache failed')
                return False

        return True


        """
        index = 0
        tri_points = om.MPointArray()
        tri_ids = om.MIntArray()
        poly_iter = om.MItMeshPolygon(self.mesh)
        while not poly_iter.isDone():

            # get face triangles
            poly_index = poly_iter.index()
            poly_iter.getTriangles(tri_points, tri_ids, om.MSpace.kWorld)

            # get triangle data
            for i in xrange(tri_points.length() / 3):
                #  assert self.p0[i * 3] == tri_points[i * 3]
                #  assert self.p1[i * 3 + 1] == tri_points[i * 3 + 1]
                #  assert self.p2[i * 3 + 2] == tri_points[i * 3 + 2]
                print self.p0[i*3].x, tri_points[i*3].x
                print self.p0[i*3].y, tri_points[i*3].y
                print self.p0[i*3].z, tri_points[i*3].z
                print '-'
                print self.p0[i*3+1].x, tri_points[i*3+1].x
                print self.p0[i*3+1].y, tri_points[i*3+1].y
                print self.p0[i*3+1].z, tri_points[i*3+1].z
                print '-'
                print self.p0[i*3+2].x, tri_points[i*3+2].x
                print self.p0[i*3+2].y, tri_points[i*3+2].y
                print self.p0[i*3+2].z, tri_points[i*3+2].z
                #  except AssertionError:
                #      return False

                index += 1

            poly_iter.next()

        return True
        """



    ################################################################################################
    # cache property
    ################################################################################################ 
开发者ID:wiremas,项目名称:spore,代码行数:63,代码来源:geo_cache.py

示例12: getMouseIntersect

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def getMouseIntersect(self):

        sourcePnt = OpenMaya.MPoint(0,0,0)
        rayDir = OpenMaya.MVector(0,0,0)
        maximumDistance = 9999999999
        viewHeight = self.view3D.portHeight()
        
        hitNormal = OpenMaya.MVector()
        
        intersectedObject = None
        intersectedPoint = OpenMaya.MFloatPoint()
        intersectedFace = 0

        hitFace = OpenMaya.MScriptUtil()
        hitFace.createFromInt(0)
        hitFacePtr = hitFace.asIntPtr()

        hitDistance = OpenMaya.MScriptUtil(0.0)
        hitDistancePtr = hitDistance.asFloatPtr()

        self.view3D.viewToWorld(int(self.userMouseEvents.M_posX), int(viewHeight - self.userMouseEvents.M_posY), sourcePnt, rayDir)

        
        direction = OpenMaya.MFloatVector(rayDir.x, rayDir.y, rayDir.z).normal()

        iter = OpenMaya.MItDependencyNodes(OpenMaya.MFn.kMesh)

        while not iter.isDone():

            node =iter.thisNode()
            dagPath = OpenMaya.MDagPath.getAPathTo(node)

            hitPoint = OpenMaya.MFloatPoint()
            source = OpenMaya.MFloatPoint(sourcePnt.x, sourcePnt.y, sourcePnt.z)
            direction = OpenMaya.MFloatVector(direction.x,direction.y,direction.z)

            if dagPath.isVisible():
                mesh = OpenMaya.MFnMesh(dagPath)
                intersected = mesh.closestIntersection(source, direction, None, None, False, OpenMaya.MSpace.kWorld, 9999999999, True, None, hitPoint, hitDistancePtr, hitFacePtr, None, None, None, 0.0001)
                
                if intersected:
                    intersectionDistance = hitDistance.getFloat(hitDistancePtr)
                    if intersectionDistance < maximumDistance:
                        maximumDistance = intersectionDistance
                        intersectedPoint = hitPoint
                        intersectedFace =  OpenMaya.MScriptUtil(hitFacePtr).asInt()
                        mesh.getClosestNormal(OpenMaya.MPoint(intersectedPoint),hitNormal,OpenMaya.MSpace.kWorld)
                        intersectedObject = dagPath.fullPathName()

            iter.next()

        if intersectedPoint.x + intersectedPoint.y + intersectedPoint.z == 0:
            return None, None, None
        else:
            return intersectedPoint, intersectedFace, intersectedObject 
开发者ID:volodinroman,项目名称:mViewportDrawOpenGL,代码行数:57,代码来源:ViewportPainter.py

示例13: compute

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def compute(self, plug, dataBlock):
        
        if plug == oyCenterOfMass.aCOMPos:
            
            # get the mesh vertices for time from start to end
            
            # get the meshes
            arrayDataHandle = dataBlock.inputArrayValue( oyCenterOfMass.aObjectList )
            numOfConnections = arrayDataHandle.elementCount()
            
            inputDataHandle = OpenMaya.MDataHandle()
            inputGeometryDataHandle = OpenMaya.MDataHandle()
            
            mesh = OpenMaya.MObject()
            meshList = OpenMaya.MObjectArray()
            
            for i in range(numOfConnections):
                arrayDataHandle.jumpToElement(i)
                
                inputDataHandle = arrayDataHandle.inputValue()
                inputGeometryDataHandle = inputDataHandle.child( oyCenterOfMass.aObjectList )
                
                mesh = inputGeometryDataHandle.asMesh()
                
                if mesh.hasFn( OpenMaya.MFn.kMesh ):
                    meshList.append( mesh )
            
            
            numOfMesh = meshList.length()
            
            # return if no mesh
            if numOfMesh == 0:
                return OpenMaya.MStatus.kSuccess
            
            # read the mesh vertices in to one big array
            verticesOfOneMesh = OpenMaya.MPointArray()
            allVertices = OpenMaya.MPointArray()
            
            meshFn = OpenMaya.MFnMesh()
            
            for i in range(numOfMesh):
                meshFn.getPoints ( verticesOfOneMesh, OpenMaya.MSpace.kWorld )
                
                for j in range(verticesOfOneMesh.length()):
                    allVertices.append( verticesOfOneMesh[j] )
                
            
            
            
            
            
            
            
            # set the time
            
            return OpenMaya.MStatus.kSuccess
        else:
            return OpenMaya.kUnknownParameter 
开发者ID:eoyilmaz,项目名称:anima,代码行数:60,代码来源:oyCenterOfMass.py

示例14: deform

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def deform(self, data_block, geometry_iterator, local_to_world_matrix, geometry_index):
        """do deformation
        """
        envelope_attribute = OpenMayaMPx.cvar.MPxDeformerNode_envelope
        envelope_value = data_block.inputValue(envelope_attribute).asFloat()

        input_geometry_object = \
            self.get_deformer_input_geometry(data_block, geometry_index)

        # Obtain the list of normals for each vertex in the mesh.
        mesh_fn = OpenMaya.MFnMesh(input_geometry_object)

        uv_shell_array = OpenMaya.MIntArray()
        u_array = OpenMaya.MFloatArray()
        v_array = OpenMaya.MFloatArray()
        script_util = OpenMaya.MScriptUtil(0)
        shells_ptr = script_util.asUintPtr()

        mesh_fn.getUvShellsIds(uv_shell_array, shells_ptr)
        mesh_fn.getUVs(u_array, v_array)

        max_offset_attr_handle = \
            data_block.inputValue(RandomizeDeformer.aMaxOffset)
        max_offset = max_offset_attr_handle.asInt()

        # compute and write the new uvs
        for uv_id in xrange(len(u_array)):
            shell_id = uv_shell_array[uv_id]
            offset_u = shell_id % max_offset
            u_array[uv_id] += offset_u

        mesh_fn.setUVs(u_array, v_array)

        uv_shell_array.clear()
        u_array.clear()
        v_array.clear()

        # # Iterate over the vertices to move them.
        # while not geometry_iterator.isDone():
        #     # Obtain the vertex normal of the geometry.
        #     # This normal is the vertex's averaged normal value if that
        #     # vertex is shared among several polygons.
        #     vertex_index = geometry_iterator.index()
        #     normal = OpenMaya.MVector(normals[vertex_index])
        #  Cast the MFloatVector into a simple vector.
        #
        #     # Increment the point along the vertex normal.
        #     point = geometry_iterator.position()
        #     newPoint = \
        #         point + (normal * vertexIncrement * meshInflation * envelopeValue)
        #
        #     # Clamp the new point within the bounding box.
        #     self.clampPointInBoundingBox(newPoint, boundingBox)
        #
        #     # Set the position of the current vertex to the new point.
        #     geometry_iterator.setPosition(newPoint)
        #
        #     # Jump to the next vertex.
        #     geometry_iterator.next() 
开发者ID:eoyilmaz,项目名称:anima,代码行数:61,代码来源:randomizeUVDeformer.py

示例15: flatten

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MFnMesh [as 别名]
def flatten(mesh=None, uvset=None):
    """Creates a mesh from the UV layout of another mesh.

    I use this to generate flattened versions of meshes from Marvelous Designer to easily use Quad
    Draw to create clean meshes and then Transfer Attributes vertex positions through UVs.

    :param mesh: Mesh to sample.
    :param uvset: UV set name
    """
    if mesh is None:
        mesh = cmds.ls(sl=True)
        if not mesh:
            raise RuntimeError("No mesh selected.")
        mesh = mesh[0]
    o_mesh = shortcuts.get_mobject(shortcuts.get_shape(mesh))
    fn_mesh = OpenMaya.MFnMesh(o_mesh)
    if uvset is None:
        uvset = fn_mesh.currentUVSetName()

    vertex_count = fn_mesh.numUVs(uvset)
    polygon_count = fn_mesh.numPolygons()
    u_array = OpenMaya.MFloatArray()
    v_array = OpenMaya.MFloatArray()
    fn_mesh.getUVs(u_array, v_array, uvset)
    vertex_array = OpenMaya.MPointArray(u_array.length())
    for i in range(u_array.length()):
        vertex_array.set(i, u_array[i], 0, -v_array[i])
    polygon_counts = OpenMaya.MIntArray(polygon_count)

    it_poly = OpenMaya.MItMeshPolygon(o_mesh)
    polygon_connects = OpenMaya.MIntArray(fn_mesh.numFaceVertices())
    face_vertex_index = 0
    while not it_poly.isDone():
        face_index = it_poly.index()
        polygon_counts[face_index] = it_poly.polygonVertexCount()

        for i in range(polygon_counts[face_index]):
            int_ptr = shortcuts.get_int_ptr()
            it_poly.getUVIndex(i, int_ptr)
            uv_index = shortcuts.ptr_to_int(int_ptr)
            polygon_connects[face_vertex_index] = uv_index
            face_vertex_index += 1
        it_poly.next()

    new_mesh = OpenMaya.MFnMesh()
    new_mesh.create(
        vertex_count,
        polygon_count,
        vertex_array,
        polygon_counts,
        polygon_connects,
        u_array,
        v_array,
    )
    new_mesh.assignUVs(polygon_counts, polygon_connects) 
开发者ID:chadmv,项目名称:cmt,代码行数:57,代码来源:flatten.py


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