Notifications
Clear all

[Closed] Correlation between mesh and poly faces ?

Let’s say i have 2 copies of the same object.
One as mesh (snapshotasmesh to be exact), the other as poly.
I have some faces selected on the .mesh, and i want to select the equivalent faces on the poly object.
Is there a fast way to do it, without assigning the .mesh to a new editable_mesh and convert to poly?
This is more by curiosity, i can still convert, even if it’s not elegant and time consumming.
Thanks !

8 Replies

coincidentally I also needed something like this today
Martijn’s technique is pretty good but I couldn’t rely on 4 cornered faces so I wrote this little function to do the work for me. It expect an editable mesh or a trimesh in m, an editable poly in p and the face index of the mesh object in f. It will return the corresponding face index in the editable poly.
Haven’t tried to optimize / thoroughly tested it yet but it works for my scenario so…


fn convertMeshFaceToPolyFace m p f =
(
	local verts = (meshop.getVertsUsingFace m f) as array
	local facesPerVert = #()
	
	for v in verts do (
		local faces = polyop.getFacesUsingVert p v
		append facesPerVert faces
	)
	
	local deltaFaces = facesPerVert[1]
	for i = 2 to facesPerVert.count do
		deltaFaces = deltaFaces * facesPerVert[i]
	
	(deltaFaces as array)[1]
)

2 Replies
(@denist)
Joined: 10 months ago

Posts: 0

you were lucky with your scenario …
but there are another where your algorithm doesn’t work. for example:

delete objects
a = plane widthsegs:3 lengthsegs:3 isselected:on
converttomesh a 
ee = #{7, 13, 24, 36, 42..43, 49, 54}
ee += meshop.getEdgesReverseEdge a ee
for f=1 to a.numfaces do for k=1 to 3 where ee[(f-1)*3+k] do 
(
	setEdgeVis a f k off
)
update a
converttopoly a 
(@matanh)
Joined: 10 months ago

Posts: 0

I tried your scenario and could find an issue with it. Here is my test code:

(
	fn convertMeshFaceToPolyFace m p f =
	(
		local verts = (meshop.getVertsUsingFace m f) as array
		local facesPerVert = #()
		
		for v in verts do (
			local faces = polyop.getFacesUsingVert p v
			append facesPerVert faces
		)
		
		local deltaFaces = facesPerVert[1]
		for i = 2 to facesPerVert.count do
			deltaFaces = deltaFaces * facesPerVert[i]
		
		(deltaFaces as array)[1]
	)
	
	delete objects
	local a = plane widthsegs:3 lengthsegs:3 isselected:on
	converttomesh a 
	local ee = #{7, 13, 24, 36, 42..43, 49, 54}
	ee += meshop.getEdgesReverseEdge a ee
	for f = 1 to a.numfaces do for k=1 to 3 where ee[(f-1)*3+k] do
		setEdgeVis a f k off
	update a
	converttopoly a 
	
	local b = copy a
	convertToMesh b
	
	for i = 1 to b.numFaces do
		format "% -> %
" i (convertMeshFaceToPolyFace b a i)
)

and here is the result:

1 -> 1
2 -> 1
3 -> 2
4 -> 2
5 -> 2
6 -> 2
7 -> 2
8 -> 2
9 -> 2
10 -> 2
11 -> 2
12 -> 2
13 -> 2
14 -> 2
15 -> 2
16 -> 2
17 -> 2
18 -> 2
OK

looks ok to me, can you be more specific?

Thanks guys ! I actually have to check if it’s faster than mesh to poly conversion, as i have several faces selected.

2 Replies
(@matanh)
Joined: 10 months ago

Posts: 0

it probably isn’t, but in my case I couldn’t just convert to poly because I needed to use intersectRayEx function that works only with trimesh/editable_mesh and then I wanted to know what face was hit in the poly object

(@denist)
Joined: 10 months ago

Posts: 0

selection and conversion is not a solution. it’s very slow for any node that is bigger than small

Matan,
i’ve found a time to look at your function more closely. it works for all cases. i was wrong… as i see you search for a poly which is shared by all three vertices that make a mesh triangle. and there can be only one that matches this condition.