Notifications
Clear all

[Closed] Texture coordinates and maxscript?

Ok, i have this little problem: Each physical vertex of a mesh can possible relate to 2 or more places on the UV plane. AFAIK there is no function that will give me the position of the UV vertex in relation to a certain face, and that is what I need.
The closest function I’m looking at is this:

polyOp.getMapVert <Poly poly> <int mapChannel> <int index>

This function asks for the poly object, the map channel, and the vertex index, from what i understand. It returns 1 value, the UV position of that vertex. But there can be multiple values right? So which one does it give me? I would like to somehow get the UV position of a vertex in relation to a certain texture face.
Here is a picture demonstrating the problem:

4 Replies

To understand how works mapping coordinates in maxscript (and 3dsmax), here is a script which print in the listener (F11) the uvw structure of your object. It shows the report between vertices and mapVertices in 2 directions.

fn getArrayOfMapVerts2VertsPOLY theObj theMapChannel =
	(
	numMapVerts = polyOp.getNumMapVerts theObj theMapChannel
	mapVerts2Verts = for mv=1 to numMapVerts collect #()
	numMapFaces = polyOp.getNumMapFaces theObj theMapChannel
	for f = 1 to numMapFaces do (
    	theMapFace = polyOp.getMapFace theObj theMapChannel f
		polyFace = polyOp.getFaceVerts theObj f
		for mv=1 to theMapFace.count do (
			mapVert = theMapFace[mv]
			if findItem mapVerts2Verts[mapVert] polyFace[mv] == 0 do append mapVerts2Verts[mapVert] polyFace[mv]
			)
		)
	mapVerts2Verts
	)

fn getArrayOfMapVerts2VertsMESH theObj theMapChannel =
	(
	numMapVerts = meshOp.getNumMapVerts theObj theMapChannel
	mapVerts2Verts = for mv=1 to numMapVerts collect #()
	numMapFaces = meshOp.getNumMapFaces theObj theMapChannel
	for f = 1 to numMapFaces do (
    	theMapFace = meshOp.getMapFace theObj theMapChannel f
		theMapFace = #(theMapFace.x as integer,theMapFace.y as integer,theMapFace.z as integer)
		meshFace = getFace theObj f
		meshFace = #(meshFace.x as integer,meshFace.y as integer,meshFace.z as integer)
		for mv=1 to theMapFace.count do (
			mapVert = theMapFace[mv]
			if findItem mapVerts2Verts[mapVert] meshFace[mv] == 0 do append mapVerts2Verts[mapVert] meshFace[mv]
			)
		)
	mapVerts2Verts
	)

fn getArrayOfMapVerts2Verts theObj theMapChannel =
	(
	array=false
	case classOf theObj of
		(
		Editable_mesh: array=getArrayOfMapVerts2VertsMESH theObj theMapChannel
		Editable_Poly: array=getArrayOfMapVerts2VertsPOLY theObj theMapChannel
		)
	array
	)

fn getArrayOfVerts2MapVerts mapVerts2Verts =
	(
	verts2MapVerts=#()
	for mv=1 to mapVerts2Verts.count do
		(
		currentVerts=mapVerts2Verts[mv]
		if currentVerts!=undefined do
			(
			for v=1 to currentVerts.count do
				(
			if verts2MapVerts[currentVerts[v]] == undefined
				then verts2MapVerts[currentVerts[v]]=#(mv)
				else append verts2MapVerts[currentVerts[v]] mv
				)
			)
		)
	verts2MapVerts
	)

clearListener()
if selection.count!=0 then
	(
	obj=selection[1]
	channel=1
	mapVerts2Verts=getArrayOfMapVerts2Verts obj channel -- create the array mapVerts ==> verts
	if mapVerts2Verts!=false do (
		verts2MapVerts=getArrayOfVerts2MapVerts mapVerts2Verts -- create the array verts ==> mapVerts
		format"%
" obj.name
		format "
array : mapVerts2Verts
======================
"
		for i=1 to mapVerts2Verts.count do format "mapVert % => verts %
" i mapVerts2Verts[i]
		format "
array : verts2MapVerts
======================
"
		for i=1 to verts2MapVerts.count do format "vert % => mapVerts %
" i verts2MapVerts[i]
		)
	)

Also, look up “Understanding Texture Coordinates” in the maxScript reference.

Hi all i finally managed to get the right mapvert …as discribed in the reference…
but i think there is a typo in there…

at least it works for me when replacing “face” by “vertex” in the “Understanding …section “

[left]1. Take the index of the mesh vertex.
[/left]
[left]2. Find out which faces reference the index of the !! face. !! <—-vertex !

[/left]
[left]3. Note the number of the vertex (1st, 2nd or 3rd – .x, .y or .z) inside each face.
[/left]
[left]4. For each face referencing the vertex, get the texture face with the same index.
[/left]
[left]5. Get the index of the respective texture vertex from the face – 1st, 2nd or 3rd / .x, .y or .z
[/left]
[left]6. The vertex you got corresonds to the mesh vertex we started with.
[/left]
[left]7. Repeat steps 3 to 6 for all faces found.

[/left]
[left]
Just wanted to let everyone know…or is this correct…sorry if yes…

[/left]
[left]
u3dreal

[/left]

Ouch! This typo survived 4 releases, thanks for finding it!
I promise it will not be there in the next release…