[英]Find closest point on mesh in specific axis (maya)
假設我在polyPlane上方有一個定位器。 我想做的是從定位器以負y或正y查找或跟蹤,直到它碰到polyPlane並返回最近點/頂點/ uv /
我想這已經完成了一百萬次了,但是我發現的唯一示例是通過基於所有軸來定位最接近的點來工作的,在我看來,這幾乎是無用的。
我將不勝感激!
編輯:添加圖像的第一個建議的解決方案和我想要實現之間的差異
我們可以做的是使用OpenMaya(Maya的API)循環遍歷數組中收集的faceVerts,檢查與當前facevert相比,距定位器位置最短的距離,如果比最近的最短距離短,請保存它作為最近的Vertex變量。
import maya.OpenMaya as OpenMaya
from pymel.core import *
geo = PyNode('pSphere1')
pos = PyNode('locator1').getRotatePivot(space='world')
nodeDagPath = OpenMaya.MObject()
try:
selectionList = OpenMaya.MSelectionList()
selectionList.add(geo.name())
nodeDagPath = OpenMaya.MDagPath()
selectionList.getDagPath(0, nodeDagPath)
except:
warning('OpenMaya.MDagPath() failed on %s' % geo.name())
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()
faceVerts = [geo.vtx[i] for i in geo.f[idx].getVertices()]
closestVertex = None
minLength = None
for v in faceVerts:
thisLength = (pos - v.getPosition(space='world')).length()
if minLength is None or thisLength < minLength:
minLength = thisLength
closestVertex = v
select(closestVertex)
這可能是在沒有API的情況下使用python來完成的,但是如果您擁有maya,就可以訪問API了:)
我希望這有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.