View Full Version : Accesing UV coordinates

05-29-2015, 02:53 AM

I'm trying to extract UV coordinates from vmap, but results aren't as I expected.
If you look at the image you can see that U coordinates should vary from near 0 to near 1.


But this is what I got for first polygon in the mesh:
('point: ', -0.5, -0.5, -0.5, 0)
('ismapped: ', 'TextureBoxNew', ' uv: ', 1, ' val: ', [0.33974358439445496, 0.006410256493836641])
('point: ', -0.5, -0.5, 0.5, 1)
('ismapped: ', 'TextureBoxNew', ' uv: ', 1, ' val: ', [0.006410256493836641, 0.006410256493836641])
('point: ', -0.5, 0.5, -0.5, 2)
('ismapped: ', 'TextureBoxNew', ' uv: ', 1, ' val: ', [0.6730769276618958, 0.32692307233810425])

First two points seems correct, but third from the the same polygon should be [0.006410256493836641, 0.32692307233810425].
It looks like I got correct UV values but in random order.

This is how my code called by scanPolys looks like:

for i in range(0,3):
pointID = mesh.polVertex(polygonID, i)

pos = mesh.pntBasePos(pointID)

print("point: ", pos[0], pos[1], pos[2], self._triangleIndexCounter)


vmap = None
oldVmap = None
for vMapName in self.vMaps:
vmap = mesh.pntVLookup(lwsdk.LWVMAP_TXUV, vMapName)
if vmap:
val = [None, None]
uv = mesh.pntVIDGet(pointID, val, vmap)
if uv > 0:
print("ismapped: ", vMapName, " uv: ", uv, " val: ", val)

self._triangleIndexCounter += 1

I've also tried to use pntVPIDGet to be sure I'm reading data for current polygon but then I got even worse results as not every point seems to return value.
Probably I'm reading vmap values wrong.
So my question is how can I get UV coords for given polygon and point?

05-29-2015, 06:22 PM
You need to call BOTH.
Per-polygon, then if it is not mapped, per-vertex.

If you unwrap object, you can call just per-vertex (because per-polygon vmaps don't exist anymore).

Is it just test code?
pntVLookup() is slow.
Typical route is lookup just once, then reuse stored pointer.

06-01-2015, 04:29 AM

Your suggestions were very helpful. Now it works as I expected and much faster because I'm using pntVLookup() only once per mesh.