2016-12-11 12 views
4

maya.api.OpenMaya.MFnMesh.subdivideEdges()関数を使用します。エッジは頂点で分割されますが、対応する新しいエッジは移動しません。分割エッジ間にエッジを追加するにはどうすればよいですか?またはどのようにして頂点を別の頂点から作成することができますか。 Maya Python API 2.0を使用していますか?

enter image description here #この2.0コードMaya Python API 2.0を使用してメッシュにエッジを追加する方法

import maya.api.OpenMaya as om 
verticePos  = [(-0.5, -0.5, 0.5, 1), (0.5, -0.5, 0.5, 1), (-0.5, 0.910894, 0.5, 1), (0.5, 0.910894, 0.5, 1), (-0.5, 0.910894, -0.383361, 1), (0.5, 0.910894, -0.383361, 1), (-0.5, -0.5, -0.383361, 1), (0.5, -0.5, -0.383361, 1), -0.5, -0.5, 1.06715, 1), (0.5, -0.5, 1.06715, 1), (0.5, 0.910894, 1.06715, 1), (-0.5, 0.910894, 1.06715, 1), (-0.5, -1.12433, -0.383361, 1), (0.5, -1.12433, -0.383361, 1), (0.5, -1.12433, 0.5, 1), (-0.5, -1.12433, 0.5, 1), (0, 0.910894, 1.06715, 1), (0, 0.910894, 0.5, 1), (0, 0.910894, -0.383361, 1), (0, -0.5, -0.383361, 1), (0, -1.12433, -0.383361, 1), (0, -1.12433, 0.5, 1), (0, -0.5, 0.5, 1), (0, -0.5, 1.06715, 1)] 

polygonCounts = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4] 
polygonConnects = [8, 23, 16, 11, 2, 17, 18, 4, 4, 18, 19, 6, 12, 20, 21, 15, 1, 7, 5, 3, 6, 0, 2, 4, 0, 22, 23, 8, 1, 3, 10, 9, 17, 2, 11, 16, 2, 0, 8, 11, 6, 19, 20, 12, 7, 1, 14, 13, 22, 0, 15, 21, 0, 6, 12, 15, 3, 17, 16, 10, 18, 17, 3, 5, 19, 18, 5, 7, 20, 19, 7, 13, 21, 20, 13, 14, 1, 22, 21, 14, 23, 22, 1, 9, 16, 23, 9, 10] 

uValues   = [0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625] 
vValues   = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 

#Convert to MPointArray 
vertices  = om.MPointArray() 
for eachPos in verticePos :    
    mPoint  = om.MPoint()    
    mPoint.x = eachPos[0]  
    mPoint.y = eachPos[1]  
    mPoint.z = eachPos[2]    
    vertices.append (mPoint) 

mfnMesh = om.MFnMesh() 
mfnMesh.create(vertices, polygonCounts, polygonConnects, uValues, vValues) 
mfnMesh.updateSurface() 
cmds.sets (mfnMesh.fullPathName(), e=1, fe='initialShadingGroup') 
mfnMesh.updateSurface() 

#Spliting Edges################################ 
edgeIDs  = [5,7,19,14,12,32,15,17] 
mfnMesh.subdivideEdges (edgeIDs, 1) 

答えて

4

はOpenMaya.MFnMesh.split()を使用し、私のMaya PythonのAPIです。 MFnMesh.split、必要な情報:

[in] placements array that contains elements of the SplitPlacement enumeration. They represent where to place the new vertices for the split. 
[in] edgeList array of edge IDs to be split, in order of their appearance in the split. There must be as many elements in this array as there are SplitPlacement::kOnEdge elements in the placements array. 
[in] edgeFactors  array of factors in the range [0,1] that represent how far along each edge must the split be done. This array must have the same number of elements as the edgeList array. 
[in] internalPoints array of positions for the vertices that will be added inside existing faces. There must be as many elements in this array as there are SplitPlacement::kInternalPoint elements in the placements array. This array can be empty. Internal points should be specified on the face between the previous edge id and the next edge id. 

作業例:Github、収集属性とクリーンsplitingのための正確な方法:ここでの分割方法を確認してください。

import maya.api.OpenMaya as om 
verticePos  = [(-0.5, -0.5, 0.5, 1), (0.5, -0.5, 0.5, 1), (-0.5, 0.910894, 0.5, 1), (0.5, 0.910894, 0.5, 1), (-0.5, 0.910894, -0.383361, 1), (0.5, 0.910894, -0.383361, 1), (-0.5, -0.5, -0.383361, 1), (0.5, -0.5, -0.383361, 1), -0.5, -0.5, 1.06715, 1), (0.5, -0.5, 1.06715, 1), (0.5, 0.910894, 1.06715, 1), (-0.5, 0.910894, 1.06715, 1), (-0.5, -1.12433, -0.383361, 1), (0.5, -1.12433, -0.383361, 1), (0.5, -1.12433, 0.5, 1), (-0.5, -1.12433, 0.5, 1), (0, 0.910894, 1.06715, 1), (0, 0.910894, 0.5, 1), (0, 0.910894, -0.383361, 1), (0, -0.5, -0.383361, 1), (0, -1.12433, -0.383361, 1), (0, -1.12433, 0.5, 1), (0, -0.5, 0.5, 1), (0, -0.5, 1.06715, 1)] 

polygonCounts = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4] 
polygonConnects = [8, 23, 16, 11, 2, 17, 18, 4, 4, 18, 19, 6, 12, 20, 21, 15, 1, 7, 5, 3, 6, 0, 2, 4, 0, 22, 23, 8, 1, 3, 10, 9, 17, 2, 11, 16, 2, 0, 8, 11, 6, 19, 20, 12, 7, 1, 14, 13, 22, 0, 15, 21, 0, 6, 12, 15, 3, 17, 16, 10, 18, 17, 3, 5, 19, 18, 5, 7, 20, 19, 7, 13, 21, 20, 13, 14, 1, 22, 21, 14, 23, 22, 1, 9, 16, 23, 9, 10] 

uValues   = [0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625, 0.625] 
vValues   = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 

#Convert to MPointArray 
vertices  = om.MPointArray() 
for eachPos in verticePos :    
    mPoint  = om.MPoint()    
    mPoint.x = eachPos[0]  
    mPoint.y = eachPos[1]  
    mPoint.z = eachPos[2]    
    vertices.append (mPoint) 

mfnMesh = om.MFnMesh() 
mfnMesh.create(vertices, polygonCounts, polygonConnects, uValues, vValues) 
mfnMesh.updateSurface() 
cmds.sets (mfnMesh.fullPathName(), e=1, fe='initialShadingGroup') 
mfnMesh.updateSurface() 

# OpenMaya.MFnMesh.subdivideEdges() dividing the selected 
# edges(we will get new Vertices/Edges) 
# The real challenge is connect the new vertices with each other, in order.... 
# my solution is hacking the right info and connect the Vertices, 
# its based on the correct edge flow/selection... 

#find all connected edges per Vertex 
def ver_coll(rr): 
    dict = {} 
    for vertexid in range(rr): 
    vIdArray = om1.MIntArray() 
    vIdArray.append(vertexid) 
    vtxCom = om1.MFnSingleIndexedComponent() 
    vtxCom.create(om1.MFn.kMeshVertComponent) 
    vtxCom.addElements(vIdArray) 
    sel = om1.MSelectionList() 
    sel.clear() 
    sel.add(mfnMesh.fullPathName()) 
    meshdag = om1.MDagPath() 
    sel.getDagPath(0,meshdag) 
    vtxIter = om1.MItMeshVertex(meshdag,vtxCom.object()) 
    vtxIter.getConnectedEdges(vIdArray) 
    util = om1.MScriptUtil(vIdArray) 
    data = util.asIntPtr() 
    numCE = vIdArray.length() 
    dict[vertexid] = [util.getIntArrayItem(data, i) for i in range(numCE)] 
    return dict 

pre = ver_coll(cmds.polyEvaluate(mfnMesh.fullPathName(), v=True)) 
edgeIDs = [0, 21, 13, 11, 9, 6, 4, 2] # or [5,7,19,14,12,32,15,17] 
mfnMesh.subdivideEdges(edgeIDs, 1) 
post = ver_coll(cmds.polyEvaluate(mfnMesh.fullPathName(), v=True)) 

object_id = mfnMesh.fullPathName().split("|")[1] 

for e in range(0,len(edgeIDs),1): 
    con = edgeIDs[e:e+2] 
    vtx_ids = [] 
    for c in con: 
    for v in set(post.keys())-set(pre.keys()): 
     if c in post[v]: 
     vtx_ids.append(v) 
    if len(vtx_ids) == 2: 
    print vtx_ids 
    cmds.polyConnectComponents("{0}.vtx[{1}]".format(object_id, vtx_ids[0]), "{0}.vtx[{1}]".format(object_id, vtx_ids[1]), adjustEdgeFlow=True, ch=True) 
    else: 
    vtx = [] 
    for i in [edgeIDs[0], con[0]]: 
     for v in set(post.keys())-set(pre.keys()): 
     if i in post[v]: 
      vtx.append(v) 
    cmds.polyConnectComponents("{0}.vtx[{1}]".format(object_id, vtx[0]), "{0}.vtx[{1}]".format(object_id, vtx[1]), adjustEdgeFlow=True, ch=True) 

enter image description here

+0

こんにちは、アリゴールド。ご協力ありがとうございました。私はこれを試してみる。私とあなたの知識を共有してくれてありがとう! –

関連する問題