   Computing Texture Coordinates for Polygons
  Hi everybody,I need to compute texture coordinates for an arbitrary polygon.I have the positions in the 3d world of the vertices and the polygon normal.I suppose i should somehow project vertices onto a 2d coordinate system derived from the polygon normal, i guess it's just a fact of math and, since i suppose it's a very well known topic, i'd like someone to direct me to a good resource to understand how all this works.Thanks in advance,Daniele   
Quote:I suppose i should somehow project vertices onto a 2d coordinate system derived from the polygon normalYes, simple planar mapping would be a reasonable choice here. Here's one way to proceed:1. Choose a vertex of the polygon to be the origin of your coordinate system (the origin doesn't actually have to be a vertex, but it's probably the easiest way to go).2. Pick an edge of the polygon and normalize it to yield the first basis vector of your coordinate system.3. Cross this vector with the polygon normal to yield the second basis vector (the normal itself will be the third).4. Create a transform from the origin and basis vectors.5. Invert the transform.6. Transform each vertex of the polygon by this inverted transform.7. Compute the u and v for each vertex as the x and y for that vertex, scaled by some constant.(The above is off the top of my head - I think it's correct, but I don't guarantee it.)This method will orient and position the texture on the polygon somewhat arbitrarily. If you want to be able to adjust the position and orientation of the texture, some additional work will be needed (although something like the above can probably still serve as a basis).   ;  Yes, that's what i had in mind...To remove the arbitrary direction of the polygon edge i could jast 'flatten' it on the XZ plane doing so:BASIS X-VECTOR = [EDGE.X, 0, EDGE.Z]I'm not totally sure about this approach anyway...Another problem with setting Y=0 is for 'vertical' edges. By 'vertical' i mean that edges that looks vertical if the polygon is observed from the 'front'.I can detect them with dot-product i presume and select a different edge.This should make gradeint of U parallel to XZ (i repeat, my geometry-skills are VERY rusty). The last problem is determining the direction of U ('left', 'right') but i think i can check it too by looking at the result of the cross-product of the computed vector and poly-normal...I hope i was clear... any suggestion would be appreciated...Daniele   