假设我在 polyPlane 上方有一个定位器。我想要做的是从定位器以负或正 y 查找或跟踪,直到它碰到 polyPlane 并返回最近点/顶点/uv/的位置
我想这已经完成了一百万次,但我发现的唯一例子是通过基于所有轴定位最近点来工作,在我的情况下这几乎是无用的。
我会很感激我能得到的任何帮助!
编辑:添加了第一个建议的解决方案和我想要实现的区别的图像
我们可以做的是使用 OpenMaya(Maya 的 API)循环遍历数组中收集的 faceVerts,检查与当前 facevert 相比,哪个距离定位器位置最近,如果它比上一个最短距离短,则保存它作为最接近的顶点变量。
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 :)
我希望这有帮助