Problem rransfering UVs from one face to another


#1

In this video you can see the issue:

Here is the code that I use:

(
	obj = selection[1]
	
	oldFaceIdx = 3
	
	faceVertsArr = polyop.getFaceVerts obj oldFaceIdx
	
	newVertsArr = for v in faceVertsArr collect (polyop.CreateVert obj (polyop.getVert obj v))
	
	newFaceIdx = polyop.CreatePolygon obj newVertsArr
		
	channel1 = 1	
		
	nVV = (polyop.getFaceVerts obj newFaceIdx)
	oVV = (polyop.getFaceVerts obj oldFaceIdx)
		
	polyop.setMapFace obj channel1 newFaceIdx oVV
		
	for v = 1 to nVV.count do
	(
		format "oldIdx: %   newIdx: % \n" oVV[v] nVV[v]
		polyop.setMapVert obj channel1 nVV[v] (polyop.getMapVert obj channel1 oVV[v])
	)
	
	update obj
	
	--	"check uv pos"
	nVV = (polyop.getFaceVerts obj newFaceIdx)
	oVV = (polyop.getFaceVerts obj oldFaceIdx)
	for v = 1 to nVV.count do
	(
		format "old: %   new: % \n" ((polyop.getMapVert obj channel1 nVV[v])) (polyop.getMapVert obj channel1 oVV[v])
	)
	
)

I use Box primitive, flatten mapping, single image applied as texture.
The code will create a new face using the verts of face 3 and will transfer the UV coordinates from verts of face 3 to verts of the new face.
There are two problems:

  1. two verts of the new face have swapped uv coordiantes. The script checks the coordiantes of the face3 verts and newFace verts and what is printed in the Listener shows that each new vert has exactly the same uv coordiante as its corresponding old vert.

  2. the UVs of one of the other faces are also moved on top of the UVs of the face 3, and it also has 2 uv verts with swapped uv coordiantes.

Any ides how the problems to be solved?


#2

you have to go off the map faces not the geo faces…

(
	obj = selection[1]
	
	oldFaceIdx = 3
	
	faceVertsArr = polyop.getFaceVerts obj oldFaceIdx
	
	newVertsArr = for v in faceVertsArr collect (polyop.CreateVert obj (polyop.getVert obj v))
	
	newFaceIdx = polyop.CreatePolygon obj newVertsArr
		
	channel1 = 1	
		
	nVV = (polyop.getmapface obj channel1 newFaceIdx)
	oVV = (polyop.getmapface obj channel1 oldFaceIdx)
		
	polyop.setMapFace obj channel1 newFaceIdx oVV
		
	for v = 1 to nVV.count do
	(
		format "oldIdx: %   newIdx: % \n" oVV[v] nVV[v]
		polyop.setMapVert obj channel1 nVV[v] (polyop.getMapVert obj channel1 oVV[v])
	)
	
	update obj
	
	--	"check uv pos"
	nVV = (polyop.getFaceVerts obj newFaceIdx)
	oVV = (polyop.getFaceVerts obj oldFaceIdx)
	for v = 1 to nVV.count do
	(
		format "old: %   new: % \n" ((polyop.getMapVert obj channel1 nVV[v])) (polyop.getMapVert obj channel1 oVV[v])
	) 
	
)

though they have the same index they may not use the same verts


#3

Thank you. :slight_smile: