![見出し画像](https://assets.st-note.com/production/uploads/images/107265806/rectangle_large_type_2_da40033a0424618f10c79fc12133c4c8.png?width=800)
【MAYA】近接頂点選択ツール「ProximityVertexSelector」
スカートとか薄いものを作っている際にミラーリングしていると重なっている頂点を選択されずに不便することがありますよね
![](https://assets.st-note.com/production/uploads/images/107265948/picture_pc_3c29a4c59c275b5851065eb85bd95d29.gif?width=800)
なので頂点同士が繋がっていなくても近接頂点を選択できるスクリプトを作りました。
![](https://assets.st-note.com/production/uploads/images/107266087/picture_pc_3958b394b7e83e1f4761b8439b3d479a.gif?width=800)
近接頂点なので範囲を変えるとこのような動作になります。
![](https://assets.st-note.com/production/uploads/images/107266235/picture_pc_cc5a2e3677fa8ebd38bc6f9eb97b1a45.gif?width=800)
あまり範囲を広げすぎて大量の頂点を選択すると結構重くなる気がするので気をつけてくださいね。
import maya.OpenMaya as om
import maya.cmds as cmds
# 選択する範囲を設定するにはこの数値を変更してください
Distance = 0.5
# 選択されている頂点を取得
selected = cmds.ls(sl=True, fl=True)
if not selected or not all('.vtx[' in s for s in selected):
raise ValueError('One or more vertices must be selected')
# 選択されている各頂点の位置を取得
mPoints = []
for s in selected:
pos = cmds.xform(s, query=True, worldSpace=True, translation=True)
mPoints.append(om.MPoint(pos[0], pos[1], pos[2]))
# 結果を保存するためのリスト
result = []
# MItDagオブジェクトを作成
dagIt = om.MItDag(om.MItDag.kBreadthFirst)
while not dagIt.isDone():
# 現在のノードがメッシュであるかを確認
dagPath = om.MDagPath()
try:
dagIt.getPath(dagPath)
if dagPath.hasFn(om.MFn.kMesh):
# MItMeshVertexオブジェクトを作成
vtxIt = om.MItMeshVertex(dagPath)
while not vtxIt.isDone():
# 頂点の位置を取得
point = vtxIt.position(om.MSpace.kWorld)
# 選択された各頂点からの距離を確認
for mPoint in mPoints:
# 半径内にある場合、頂点をリストに追加
if mPoint.distanceTo(point) <= Distance:
result.append('%s.vtx[%i]' % (dagPath.fullPathName(), vtxIt.index()))
break # 一つでも範囲内にあったら次の頂点へ
# 次の頂点へ
vtxIt.next()
except:
pass
# 次のノードへ
dagIt.next()
# 頂点を選択
cmds.select(result)
このツールはChatGPTを使用して作成しています。
AI生成のリスクを理解した上でご利用ください。
この記事が気に入ったらサポートをしてみませんか?