PDA

View Full Version : How to read a vertice's uv coordinates?


MrSparkle
04-11-2006, 06:46 AM
Hi,

I want to write a function that returns the uv coordinates of a specified mesh vertice. I read through the section "Understanding Texture Coordinates and Vertex Colors", esp. the paragraph "Finding the corresponding vertices":
In order to find out which texture vertex corresponds to a mesh vertex, you have to do the following:
1. Take the index of the mesh vertex.
2. Find out which faces reference the index of the face.
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.
Same applies to color vertices.


So, my function looks like this:

-- Returns mapping coordinates of the indexed vertice in uv space
fn getUVCoordByVert theMesh mapChannel vertIndex = (
local faces = (meshOp.getFacesUsingVert theMesh vertIndex) as array -- All faces using this vertice
local vertices = (meshOp.getVertsUsingFace theMesh faces[1]) as array -- All vertices using the first face
local mapVertIndices = meshOp.getMapFace theMesh mapChannel faces[1] -- All map vertices using the same face in the same order
local mapVertIndex = -1
for i = 1 to vertices.count do (
if vertices[i] == vertIndex then (
mapVertIndex = mapVertIndices[i] as integer
)
)
return (meshOp.getMapVert theMesh mapChannel mapVertIndex) -- Return UV coordinates
)


But it doesn't work very well because there are sometimes ambigous results in the getMapFace array and I'm not sure if I use them right.
Can somebody help me out?

Christian

arketip
04-11-2006, 09:33 AM
This link can help you to understand the mapping coordinates.
http://forums.cgsociety.org/showthread.php?t=322642
You will probably have ideas by looking the functions of this script...

Bobo
04-11-2006, 06:10 PM
Hi,

I want to write a function that returns the uv coordinates of a specified mesh vertice. I read through the section "Understanding Texture Coordinates and Vertex Colors", esp. the paragraph "Finding the corresponding vertices":


So, my function looks like this:

-- Returns mapping coordinates of the indexed vertice in uv space
fn getUVCoordByVert theMesh mapChannel vertIndex = (
local faces = (meshOp.getFacesUsingVert theMesh vertIndex) as array -- All faces using this vertice
local vertices = (meshOp.getVertsUsingFace theMesh faces[1]) as array -- All vertices using the first face
local mapVertIndices = meshOp.getMapFace theMesh mapChannel faces[1] -- All map vertices using the same face in the same order
local mapVertIndex = -1
for i = 1 to vertices.count do (
if vertices[i] == vertIndex then (
mapVertIndex = mapVertIndices[i] as integer
)
)
return (meshOp.getMapVert theMesh mapChannel mapVertIndex) -- Return UV coordinates
)


But it doesn't work very well because there are sometimes ambigous results in the getMapFace array and I'm not sure if I use them right.
Can somebody help me out?

Christian


When I said "note the number inside the face - .x, .y, .z", I REALLY meant the components of the face.

local faces = (meshOp.getFacesUsingVert theMesh vertIndex) as array
--returns an array of faces.

mapVertices = #() --init. an array to collect all map verts corresponding to vertIndex.

--Now for each face, use

for theFace in faces do
(
theFaceDef = getFace theMesh theFace

--theFaceDef will be a Point3 value where .x, .y and .z point at 3 vertices.

--Get the map face with the same index (theFace)

theMapFace = meshOp.getMapFace theMesh mapChannel theFace

--Now you can check which one of the 3 face's vertices is the one you are looking for:

if theFaceDef.x == vertIndex then theMapVert = theMapFace.x as integer
if theFaceDef.y == vertIndex then theMapVert = theMapFace.y as integer
if theFaceDef.z == vertIndex then theMapVert = theMapFace.z as integer

--So at this point, theMapVert contains the index of a map vertex that corresponds
--to the verIndex parameter you passed to the function.

if findItem mapVertices theMapVert == 0 do
append mapVertices theMapVert --add to the array if not already there

)
--You repeat the same for all other faces and in the end,
--mapVertices will contain all map verts corresponding to your mesh vertex.

...


Here is the whole function:


fn getUVCoordByVert theMesh mapChannel vertIndex = (
local faces = (meshOp.getFacesUsingVert theMesh vertIndex) as array
mapVertices = #()
for theFace in faces do
(
theFaceDef = getFace theMesh theFace
theMapFace = meshOp.getMapFace theMesh mapChannel theFace
if theFaceDef.x == vertIndex then theMapVert = theMapFace.x as integer
if theFaceDef.y == vertIndex then theMapVert = theMapFace.y as integer
if theFaceDef.z == vertIndex then theMapVert = theMapFace.z as integer
if findItem mapVertices theMapVert == 0 do append mapVertices theMapVert
)
return mapVertices
)

getUVCoordByVert $ 1 1

MrSparkle
04-11-2006, 07:21 PM
Thank you both for helping me understand the whole topic better!

When I said "note the number inside the face - .x, .y, .z", I REALLY meant the components of the face.

So you are one of the guys who wrote the 3d max help? You've done a great job, the 3ds max help is by far the best of all 3d applications I know!

Christian

CGTalk Moderation
04-11-2006, 07:21 PM
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.