Notifications
Clear all

[Closed] Need to find the UV coordinates of a Editable Poly Vertex

I need to write a function that takes as arguments an editable poly object and the index of a vertex, and then returns the position of the vert’s corresponding UV coordinate in a Point3 value.

 This is all I have so far:
 
 fn getUVpos epolyobj vertindex = 
 (
 
    return uvpos = [-1,-1,0]  -- insert wisdom here
 )
 
 Does anyone have any ideas how to do this? Any thoughts would be greatly appreciated. Thank you.
4 Replies

I found something that works, but I had to use editable mesh. But I won’t argue with results.

fn getUVpos epolyobj vertindex =
(

   local obj = copy editpolyobj
   converttomesh obj
   UVcoords = getTVert obj vertindex
   delete obj
   if true then return UVcoords 

     )

One more thing: Anyone know what the & symbol represents in Maxscript?

Hi,

It is used for referencing variables:

fn getVal obj &vert &edge &face = vert = …; edge = …; face = …

So later you can call this fn like this:

getVal &v &e &f
format “%
” #(v, e, f)

Light

Keep in mind that one vertex could has more than one texture coordinate.

Said that. Say you want to take the texture coordinates for the four vertices that form the face #3 (map channel #1) of a box (previously converted to an editable poly object). What you’ll do is something like this:

for v in (polyOp.getMapFace $Box01 1 3) do
	format "Vert #% UVW = %
" v (polyOp.getMapVert $Box01 1 v)

That will print the texture coordinates for that face.

Take a look to the Editable_Poly mapping methods in the MAXScript reference for more info.

Greets.

Here is the code:

fn getUVpos obj channel theVertex = (
	local vertexFaces = polyOp.getFacesUsingVert obj #{theVertex}
	local mapVertsArray = #() , mapVertsPosArray = #() , optimizedMapVertsArray = #() , optimizedMapVertsPosArray = #()
	for currentFace in vertexFaces do (
		local polyFace = polyOp.getFaceVerts obj currentFace
		local mapFace = polyOp.getMapFace obj channel currentFace
		local mapVertex = mapFace[findItem polyFace theVertex]
		append mapVertsArray mapVertex
		local mapVertexPos = polyOp.getMapVert obj channel mapVertex
		append mapVertsPosArray mapVertexPos
		if findItem optimizedMapVertsArray mapVertex == 0 do (
			append optimizedMapVertsArray mapVertex
			append optimizedMapVertsPosArray mapVertexPos
			)
		)
	format "mapVertsArray=% 
" mapVertsArray
	format "mapVertsPosArray=% 
" mapVertsPosArray
	format "optimizedMapVertsArray=% 
" optimizedMapVertsArray
	format "optimizedMapVertsPosArray=% 
" optimizedMapVertsPosArray
	optimizedMapVertsPosArray
	)

clearListener()
if selection.count!=0 and classof selection[1]==Editable_Poly 
	do (
		local obj=selection[1]
		local channel=1
		local theVertex=5
		getUVpos obj channel theVertex
		)

It returns an array.
In many cases this array will contain only one point3 value.
In fact the function calculates an optimized array but I left the unoptimized array in the code if you need some.

I Hope this helps