処理内容はどちらも
①選択頂点の座標を取得
②openMayaのMVectorクラスを使って閾値以上近接している頂点を検索
③エラーがあればリストに格納して返す
以下ソース
mayaPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as mc | |
import maya.api.OpenMaya as om2 | |
def checkNearVtx(): | |
errorList=[] | |
vtxList = mc.ls(sl=True,fl=True) | |
vtxList2 = vtxList[:] | |
for vtx1 in vtxList: | |
pos1 = mc.pointPosition(vtx1) | |
vec1 = om2.MVector(pos1) | |
for vtx2 in vtxList2: | |
if vtx1 == vtx2: | |
continue | |
pos2 = mc.pointPosition(vtx2) | |
vec2 = om2.MVector(pos2) | |
vec3 = vec1-vec2 | |
if vec3.length()<0.001: | |
errorList.extend([vtx1,vtx2]) | |
vtxList2.remove(vtx1) | |
return errorList | |
start = time.time() | |
print checkNearVtx() | |
elapsed_time = time.time() - start | |
print ("elapsed_time:{0}".format(elapsed_time) + "[sec]") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#_ Import required modules | |
import maya.cmds as mc | |
import maya.api.OpenMaya as om2 | |
import time | |
def retunrnSelectVtxPos(): | |
orgSelection = mc.ls(sl=True) | |
#getVtx IndxList | |
tmp = mc.polyListComponentConversion(orgSelection,tv=True) | |
selVtxList = mc.ls(tmp,fl=True) | |
selVtxList = sorted(selVtxList) | |
selDict = {} | |
for vtx in selVtxList: | |
shape = vtx.split('.')[0] | |
if not shape in selDict.keys(): | |
selDict[shape] = [] | |
indx = int(vtx.split('[')[-1].split(']')[0]) | |
selDict[shape].append(indx) | |
returnDict={} | |
for shape in selDict.keys(): | |
mc.select(shape) | |
selection = om2.MGlobal.getActiveSelectionList() | |
selObj = selection.getDagPath(0) | |
mfnObject = om2.MFnMesh(selObj) | |
posList = mfnObject.getPoints(om2.MSpace.kWorld) | |
returnDict[shape]=[] | |
for vtx in selDict[shape]: | |
returnDict[shape].append([vtx,posList[vtx]]) | |
mc.select(orgSelection) | |
return returnDict | |
def checkNearVtxList(vtxDict): | |
errorList=[] | |
for key in vtxDict.keys(): | |
MposList = vtxDict[key] | |
MposList2 = MposList[:] | |
for vtxInfo1 in MposList: | |
indx1 = vtxInfo1[0] | |
vec1 = om2.MVector(vtxInfo1[1]) | |
for vtxInfo2 in MposList2: | |
indx2 = vtxInfo2[0] | |
if vtxInfo1==vtxInfo2: | |
continue | |
vec2 = om2.MVector(vtxInfo2[1]) | |
vec3 = vec1-vec2 | |
if vec3.length()<0.001: | |
vtx1 = '%s.vtx[%s]'%(key,indx1) | |
vtx2 = '%s.vtx[%s]'%(key,indx2) | |
errorList.extend([vtx1,vtx2]) | |
MposList2.remove(vtxInfo1) | |
errorList = list(set(errorList)) | |
return errorList | |
start = time.time() | |
dict = retunrnSelectVtxPos() | |
print checkNearVtxList(dict) | |
elapsed_time = time.time() - start | |
print ("elapsed_time:{0}".format(elapsed_time) + "[sec]") |
で、結果。
mayaPythonの結果: elapsed_time:1.26999998093[sec]
openMayaの結果: elapsed_time:0.103000164032[sec]
うーん! これだけで10倍以上の処理速度の差が。
ソースはもっと洗練できると思う。 もっと早くなるんじゃないだろか。
参考;
http://jensvhansen.com/fastest-way-to-query-vertex-position-in-maya/
https://boomrigs.com/blog/2016/1/12/how-to-get-mesh-vertex-position-through-maya-api
0 件のコメント:
コメントを投稿