假设我在多平面上方有一个定位器。我想要做的是从定位器以负或正 y 进行查找或跟踪,直到它到达 polyPlane 并返回最近点/顶点/uv/的位置
我想这已经完成了一百万次,但我发现的唯一例子是通过基于所有轴定位最近的点来工作的,在我的例子中,这几乎是无用的。
如果我能得到任何帮助,我将不胜感激!
编辑: 添加了第一个建议的解决方案与我想要实现的目标之间的差异的图像
最佳答案
我们可以做的是使用OpenMaya(Maya的API)循环收集在数组中的faceVerts,检查与当前facevert相比,距定位器位置的最短距离,如果它比最后一个最短距离短,将其保存为closestVertex变量。
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 :)
希望这有帮助
关于python - 查找特定轴上网格上最近的点(maya),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21720904/