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:
- Take the index of the mesh vertex.
- Find out which faces reference the index of the face.
- Note the number of the vertex (1st, 2nd or 3rd - .x, .y or .z) inside each face.
- For each face referencing the vertex, get the texture face with the same index.
- Get the index of the respective texture vertex from the face - 1st, 2nd or 3rd / .x, .y or .z
- The vertex you got corresonds to the mesh vertex we started with.
- 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