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