# UVs on procedural generated geometry [SOLVED]

I’m still working on my app that creates a race track.

I’ve got it making all the geometry for the track now, and it’s working pretty well. Here’s the thing: I want to put a striped texture on the track.

I created the texture image. My intention is to have it repeat over each rectangular section of track.

Each rectangle of the track is made of two GeomTriangles objects. When I’m creating the vertices, I alternate setting the V coordinate of the texture coordinates between 0 and 1 as shown in this crappy drawing:

This causes the texture to flip direction every track section.(Going from V 0 to V 1 on one section, then from V 1 to V 0 on the next section). This is kind of annoying, but tolerable. The real problem is that if I end up with an odd (not even) number of track sections, the vertices for the last section (where the end of the track re-unites with the start of the track) all have a V coordinate of 0, so the texture doesn’t show (It’s going from V 0 to V 0).

I know that if I create a model in Lightwave, export an OBJ, and convert the OBJ to an egg, I can do this kind of texture tiling without either of these problems.

How do I prevent these two problems (texture flipping, and V 0 on all verts for the final track section) when I’m generating the geometry in code?

Are the verts marked “V1” two verts shared between the two triangles, or are they actually four verts (two per triangle) sitting at the same location?
If they are separate, you can always set the bottom verts of each texture repeat to V0 and the top verts to V1. That should solve both problems.

It’s two verts. I could do four, but that could result in graphical errors where there seems to be a thin separation between the track segments.

Why not just let the V coordinate continually increase, from 0, to 1, to 2, to 3, and so on? There’s no reason it should be constrained between 0 and 1. And then when you stitch together track pieces, a track that ends on V=3 will blend seamlessly with a track that begins on V=0.

David

Y’know, I should have thought of that.

That didn’t actually solve the problem, unfortunately. The last track segment is defined by the last group of generated verts, and the first group of generated verts. So it’s using a V coordinate of N, where N is the number of generated vert groups, on one end, and a V coordinate of 0 on the other end. This results in the texture iterating over the last section of track as many times as there are track segments.

Is there a way I could create two sets of verts that exist on the same points in space, set UVs on them, and then have them get merged or something? Or make two UV coordinates on each vert, and have some polys use one set of UVs and some use another?

Just have two sets of verts where the track connects sitting at the same position, one set with V=0 and one set with V=n. It should not be possible to see it as long as all the verts are part of the same geom.