简体   繁体   English

使用 python/API 在 Maya 中查找特定半径内的顶点

[英]Finding vertices within a certain radius in maya using python/API

I'm trying to find the closest vertex on a mesh but within a radius.我试图在网格上但在半径内找到最近的顶点。 This is to avoid having to loop through all the vertices as that's time consuming.这是为了避免循环遍历所有顶点,因为这很耗时。 Example, I have 2 shirts with different vertex count and I'm trying to find the closest vertex of vertex1 that's on mesh2's right sleeve on mesh1's right sleeve.例如,我有 2 件具有不同顶点数的衬衫,我试图在网格 1 的右袖上的网格 2 的右袖上找到与顶点 1 最接近的顶点。 I don't want to loop through verts beyond the sleeve as logically no vertices will be close enough.我不想遍历袖子之外的顶点,因为从逻辑上讲,没有顶点足够接近。 I understand that there is an assumption that there could be other vertices closer, but for the usage I'm looking for, I don't foresee that being an issue.我知道假设可能有其他顶点更近,但对于我正在寻找的用法,我不认为这是一个问题。

I have the code to loop through vertices and get the closest point, but if the mesh has a high vert count, it takes a long time, even if it's using the API.我有代码来循环遍历顶点并获得最近的点,但是如果网格的顶点数很高,则即使使用 API 也需要很长时间。

Is there a function in maya that lets you limit vertices based of a radius? Maya 中是否有一个函数可以让您根据半径限制顶点? Or any tips on how I can write a function that could do that?或者关于如何编写可以做到这一点的函数的任何提示?

You can use the node nearestPointOnMesh.您可以使用节点nearestPointOnMesh。 In maya API, you can look for MFnMesh::closestIntersection class that can raycast ( Querying of a point is within a mesh maya python api )在 Maya API 中,您可以查找可以进行光线投射的 MFnMesh::closestIntersection 类( 点的查询位于网格内Maya python api

vtx = 'shirt1.vtx[0]'
pos = cmds.pointPosition(vtx)
m = 'shirts2'
objShape = cmds.listRelatives(m, ni=True, type='mesh')[0]
node = cmds.createNode('nearestPointOnMesh')
cmds.connectAttr(objShape + ".worldMesh", node + ".inMesh")
cmds.setAttr(node + ".inPosition", type = 'double3', *pos)
target_pos = cmds.getAttr(node + '.position')[0]
face = cmds.getAttr(node + ".nearestFaceIndex")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM