View Full Version : Accessing UV data

11-17-2003, 11:59 AM
I'm working on a rudimentary LScript exporter that exports UV-mapped meshes into a custom XML format. I've run into a brick wall, however, in dealing with discontinous UV maps. Dealing with objects where each
geometry vertex has more than one UV vertex--such as with mappings created using New UV Map->Atlas--results in exported gibberish as there doesn't seem to be a way to get the right UV coordinate for each polygon.

I'm currently reading UV data using code along these lines:

/* Get active UV map for color channel */
currSurf = nextsurface();
surf = Surface(currSurf);
texObj = surf.getTexture(SURFCOLR);
UVMap = texLayerObj.getValue(TXLRVMAP);

Loop over every polygon
Loop over every point in the polygon
UV[3] = 1;
UV = UVMap.getValue(PointNumber);
// U in UV[1], V in UV[2]
Export poly UVs

When this code encounters an object that has been wrapped in atlas mode--or indeed any non-continous mapping--the UVs come out badly mangled because the UVMap data doesn't always match the correct UV coords for the polygon vertexes in question.

What's the right way to do this? Modeler is obviously storing poly-to-UV mapping somewhere but LScript has no obvious means to access it.

11-19-2003, 06:48 AM
If you're lazy like me, you might want to try using LScript to copy the object to another layer, do an Unweld on the entire mesh, and then read the UVs from that. That way, you'll be able to get hold of your per polygon UVs easily without the need to understand how Lightwave handles them.

11-19-2003, 10:24 AM
Originally posted by fxnut
If you're lazy like me, you might want to try using LScript to copy the object to another layer, do an Unweld on the entire mesh, and then read the UVs from that.

At the expense of exploding the point count. This isn't desirable given that the result will be used in real-time rendering.

I'd settle for a solution where only points with multiple UV maps were unwelded but unwelding the entire mesh is not acceptable for performance reasons.

11-20-2003, 02:27 AM
Sure, I understand that you need it for real time purposes, but what I'm suggesting here is just a way to access the UVs on a per polygon basis. Providing LW keeps the point order the same in the polygon definition (which I'd be surprised if it didn't - but a quick test should tell), then you should then be able to match up the UVs to the original welded vertices.

Otherwise if you can't figure out how to do it with LScript, I guess you'll have use the SDK.

12-02-2003, 04:49 AM
I'm trying to create an XML exporter too. I'd like a copy of what you have done. Lscript exporters are hard to find, and I haven't found one that does UV.

Lightwave does support discontinuous UV maps. I think the suggested idea of unwelding just complicates the issue. Here is the description of the key functions:


In order to be able to process discontinuous UV values, several of the VMap Object Agent's
methods have had their argument lists augmented.


isMapped() now accepts an optional second argument which should be the
polygon for which the discontinuous UV values for the indicated point
should be checked.


getValue() processes a second argument that indicates the polygon for
which discontinuous UV values should be retrieved. an <index> value can
also be specified to limit the retrieval to a specific value index.

setValue(<point>,<value>|<array>[,<polygon>][,<index>]) (MODELER ONLY)

a <polygon> can now be included in the setValue() argument list to allow
values to be assigned to a polygon's per-vertex (discontinuous) UV.

01-14-2004, 06:54 AM
hey guys I'm having the same problem of mangled uvs
one way was to unweld the model before exporting but i don't like that idea

now trying to use the new getValue function and giving it a point and poly id there are times i get a nil value back

not sure what i should do from there set it to 0 or do i need to test that point against every poly in the model or something

right now i have a loop setup to go through every poly find all the points on the poly then get the UV data for each point

what I'm not real clear on is how to use the updated getValue method to correctly export the UV data with out it getting mangled

any ideas or has any body else had success with this

01-14-2004, 07:52 AM
I solved that issue. You use the old way for continuous
and the new way for discontinuous:

uv = UVMap.getValue(points[pointIndex]);
else if(UVMap.isMapped(points[pointIndex],polygons[polyIndex]))
uv = UVMap.getValue(points[pointIndex],polygons[polyIndex]);

You can get my XML and OBJ exporter lscript at:

01-14-2004, 08:44 AM
:) yea i just figured out that about an hour ago
mine is a little different but basiclly the same

hit your site but could not find anywhere to download that xml and obj exporter

also the terrian thing looks very cool
i would be very interested in talking to you more about that

01-15-2004, 01:14 AM

follow the links:
projects -> arch using lightwave

The arch used the xml exporter. Direct links are:


and then there was my old lightwave page: