[Closed] Vertex IDs dont match between Mesh and Poly
I have a Mesh face ID, and im trying to get the Poly face ID that it belongs to.
The way I implemented this originally assumed that mesh vertices and poly vertices always have matching IDs.
I get the mesh vert IDs corresponding to the mesh face with meshop.getVertsUsingFace, then get the poly faces of each of those vertices, and do an & comparison between them to find the face shared by all the vertices.
However I have now run across a mesh where the vertex IDs do not match between the Poly and the Mesh, and due to this the vertex faces returned are not the ones i need and it fails to find a shared one… Is there some better more reliable way to make the conversion I’m after?
https://forums.autodesk.com/t5/3ds-max-programming/get-face-poly-by-face-mesh-in-maxscript/td-p/7552039
Here’s a bit modified version of the last one Denis posted.
Now it has no memory leak when += integer is used and no comparison to zero on each iteration.
fn getPolyFaceByTri node tri =
(
local index = [1,0]
local getFaceDeg = polyop.getFaceDeg
local active = true
for k = 1 to polyop.getNumFaces node while active do
(
index[1] += getFaceDeg node k - 2
if (tri < index[1]) do (active = false; index[2] = k)
)
index[2]
)
Serejah: The problem is that it only works with perfectly valid meshes where the reindexing doesn’t occur (if you already have a mesh converted to poly that gets queried as mesh). There are cases where you have a face index in one level of modifier stack (where it evaluates to mesh) and want to get a matching poly higher in the stack (where it’s evaluated to poly). Try it with a Teapot to see what the issue is – here you have a pair of matching face + poly highlighted:
obj = Teapot segments:2
meshSel = Mesh_Select()
polySel = Poly_Select()
addModifier obj meshSel
setFaceSelection obj meshSel #{194}
addModifier obj polySel
setFaceSelection obj polySel #{97}
You can get around that by creating a copy of the mesh, setting the selection, converting to poly and getting the selection again (plus the neccessary cleanup in the end).
Oh, I see now. Thanks for the explanation.
I thought that the last version Denis posted was somehow free of this issue but it’s clearly not.
unfortunately the scene is NDA and i cant share it or export the mesh seperately. If i export it as FBX it imports as mesh, and when you convert it to epoly the vertex IDs match again.
I’m assuming this is just a one off desync since its taken over half a year to encounter it for the first time. I’ll probably just add error catching to my script which prompts the user to convert from poly to mesh and back again to fix it.