PDA

View Full Version : Texture coordinates and maxscript?

 scorpion00702-28-2006, 04:16 AMOk, 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 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: http://img96.imageshack.us/img96/5753/uvproblem12ig.th.png (http://img96.imageshack.us/my.php?image=uvproblem12ig.png)
arketip
02-28-2006, 02:54 PM
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"%\n" obj.name
format "\narray : mapVerts2Verts\n======================\n"
for i=1 to mapVerts2Verts.count do format "mapVert % => verts %\n" i mapVerts2Verts[i]
format "\narray : verts2MapVerts\n======================\n"
for i=1 to verts2MapVerts.count do format "vert % => mapVerts %\n" i verts2MapVerts[i]
)
)

JHaywood
02-28-2006, 04:47 PM
Also, look up "Understanding Texture Coordinates" in the maxScript reference.

u3dreal
05-31-2006, 11:46 PM
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 "

1. Take the index of the mesh vertex.

2. Find out which faces reference the index of the !! face. !! <----vertex !

3. Note the number of the vertex (1st, 2nd or 3rd - .x, .y or .z) inside each face.

4. For each face referencing the vertex, get the texture face with the same index.

5. Get the index of the respective texture vertex from the face - 1st, 2nd or 3rd / .x, .y or .z

6. The vertex you got corresonds to the mesh vertex we started with.

7. Repeat steps 3 to 6 for all faces found.

Just wanted to let everyone know...or is this correct....sorry if yes...

u3dreal ;)

Bobo
06-01-2006, 04:26 AM
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 "

1. Take the index of the mesh vertex.

2. Find out which faces reference the index of the !! face. !! <----vertex !

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

CGTalk Moderation
06-01-2006, 04:26 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.