Hello all,
I am writing a program to calculate lightmaps given a triangle soup and a list of light sources. What I’m having trouble is computing the correct worldspace position of each lumel. I found a few tutorials about generating lightmap coordinates on the internet, Polygone’s tutorial comes to mind, and I’m currently stuck on planar mapping. Here’s what I currently have:

Find the largest component of a tri’s normal. Let’s say Y for example.

For every vertex, assign X to the u lightmap coordinate and Z to the v lightmap coordinate

Calculate the max and min lightmap V and U and the delta V and U

For every vertex, subtract the min U from the lightmap’s U and the min V from the lightmap’s V and divide both by their respective deltas
Now, up to this point everything is roses. Following is the part I’m having trouble with.
 Calculate the zero vector and the two edge vectors. The zero vector is the vertex with lightmap coordinates 0,0. The edge vectors are the vectors from 0,0 to 1,0 and 0,0 to 0,1 respectively along the xz plane of the triangle. This is how I would calculate all 3 vectors for the above example:
aZeroVect.x = minU;
aZeroVect.z = minV;
aZeroVect.y =  ( norm.x * minU + norm.z * minV + d ) / norm.y;
lVect1.x = maxU;
lVect1.z = minV;
lVect1.y =  ( norm.x * maxU + norm.z * minV + d ) / norm.y;
lVect2.x = minU;
lVect2.z = maxV;
lVect2.y =  ( norm.x * minU + norm.z * maxV + d ) / norm.y;
aEdge1 = lVect1  aZeroVect;
aEdge2 = lVect2  aZeroVect;
This makes sense to me, although I’m not 100% sure I’m doing it correctly.
 For each lumel, calculate its worldspace coordinate as follows. My lightmaps right now are all 16 by 16.
x /= 16;
y /= 16;
pos = zeroVect + ( edge1 * x ) + ( edge2 * y );
Where x and y are the lumel coordinates and pos is the final lumel position.
Can anyone see if and what I’m doing incorrectly.
By the way, I apologize in advance for the potential off topic post. I thought about going to the beginner’s forum. I also did a search on ‘planar mapping’ in this forum but didn’t find anything useful.
I thank you all in advance
–Marcos