PDA

View Full Version : How to get mesh vert from map vert?


stuh505
11-06-2005, 06:28 PM
My thought:

1) get one texture face that corresponds with the texture vert
2) note which vertex index within the texture face corresponds to the texture vert (1, 2, or 3)

3) get the mesh face with the same index as the texture face

4) get the vert index from within this face with the same index as recorded (1 2 or 3)

this is the mesh vert that corresponds to the texture vert


---

Example:

The map vert index is 207

The index of the first map face using this vert is 305

the map verts used by map face 305 are [207, 174, 173]

therefore i use position 1

the vertices associated with mesh face 305 are [138, 139, 171]

so i get 138 from position 1

...the correct answer should be 171 from position 3

prettyPixel
11-06-2005, 08:37 PM
The best way to do what you need is to create an link array between mapVertices and geomVertices.


Could you print here the data of your object by using this utility?

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]
)
)

That shows the real structure of your object : the link between mapverts and geomverts.
The result will be in the listener.

stuh505
11-06-2005, 09:55 PM
Thanks. It was just a sample object, a sphere. I could use this function, but I'm not clear on what's wrong with the way I tried to do it.



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.

Basically, just reversing this alg..should work

prettyPixel
11-06-2005, 10:14 PM
and this algo ?

1. Take the index of the mapvert.
2. Find out which mapFaces reference the index of this mapVert + Note the number of the mapVert (1st, 2nd or 3rd) inside each mapFace.
3. For each mapFace referencing the mapVert, get the index of the respective the geomVert of the geomFace with the same number (1st, 2nd or 3rd).

prettyPixel
11-07-2005, 06:10 PM
Here is the method in script

theObj=selection[1]
theMapChannel=1
mapVertToFind=3
-- cerate an array to store vertices
theVerts=#{}
-- search the faces where there are this mapVert
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 (
if theMapFace[mv]==mapVertToFind do theVerts[meshFace[mv]]=true
)
)
format "theVerts=%\n" theVerts

Because it is necessary to go through all the faces, it is interesting to store these values once for all in an array.

stuh505
11-07-2005, 06:51 PM
But the relationship of mapverts to meshverts is many to 1, so why do you go through each map face instead of just picking the first one?

prettyPixel
11-07-2005, 07:34 PM
Because I don't know how much map faces include this map vertex * AND * because It is possible that there is more of one mesh vertex by map vertex.

In an standart planar mapping, there are just one mesh vertex for one map vertex but It's not always the case. (for example if you apply a break on this vertex: you have X vertices and one map vertex )

prettyPixel
11-07-2005, 07:50 PM
The inverse is also possible:

-create a plane with 16 faces
-apply an UVW map, use the FACE mode
-collapse to poly
-add an unwrap
-weld the mapVertices of the 4 corners "one" by "one"
-collapse to poly


Now run my utility :

Plane01

array : mapVerts2Verts
======================
mapVert 1 => verts #(2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20)
mapVert 2 => verts #(6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24)
mapVert 3 => verts #(1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19)
mapVert 4 => verts #(7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 25)

array : verts2MapVerts
======================
vert 1 => mapVerts #(3)
vert 2 => mapVerts #(1, 3)
vert 3 => mapVerts #(1, 3)
vert 4 => mapVerts #(1, 3)
vert 5 => mapVerts #(1)
vert 6 => mapVerts #(2, 3)
vert 7 => mapVerts #(1, 2, 3, 4)
vert 8 => mapVerts #(1, 2, 3, 4)
vert 9 => mapVerts #(1, 2, 3, 4)
vert 10 => mapVerts #(1, 4)
vert 11 => mapVerts #(2, 3)
vert 12 => mapVerts #(1, 2, 3, 4)
vert 13 => mapVerts #(1, 2, 3, 4)
vert 14 => mapVerts #(1, 2, 3, 4)
vert 15 => mapVerts #(1, 4)
vert 16 => mapVerts #(2, 3)
vert 17 => mapVerts #(1, 2, 3, 4)
vert 18 => mapVerts #(1, 2, 3, 4)
vert 19 => mapVerts #(1, 2, 3, 4)
vert 20 => mapVerts #(1, 4)
vert 21 => mapVerts #(2)
vert 22 => mapVerts #(2, 4)
vert 23 => mapVerts #(2, 4)
vert 24 => mapVerts #(2, 4)
vert 25 => mapVerts #(4)

In this object there are just 4 map vertices and 25 geom vertices.
Off course It is a particular case.

CGTalk Moderation
11-07-2005, 07:50 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.