I want to create a 3D game world where the players can modify the environment. I would like to bring it to the point where a power-user could even create "game objects" inside the application using some kind of very simple 3D modeling UI. So I decided to write this UI first, as I can then use it to create the game content. I spent some time in the last two months trying to learn Blender, and decided that this was a total overkill for what I want to create.
Anyway, I have the classes representing the 3D "concepts" mostly worked out, but I have problems with the "unwrapping" code, that is, mapping the graphic primitives, triangles and rectangles, to a texture file.
The 3 points representing a triangle are in 3D, but I need to work in 2D for the texture mapping. How should I best choose which of the 3 points to use as the "origin" of that triangle in the texture file, and how do I define some "reliable" concept of width and height that make sense, when I am in 3D?
I can think of several methods, but if one is most commonly used, I would like to know, so that my code also make sense to other people.
[EDIT] It seems I did a very bad job of explaining what I want. I understand how unwrapping works. I sweated blood going through a Blender unwrapping tutorial. But now I'm trying to write code that can automatically create a basic unwrapping of simple objects (boxes, wedges, pyramids, ... and composition thereof). My idea was to group primitives that are 1) in the same plane, and 2) touch each other in (flat) "boxes" and map those boxes to the first free spot on the texture file that is big enough (under the assumption that all primitives have the same scale). Far from optimal, but good enough to get going. Later, the user could have refined the unwrapping as necessary, for example, by mapping several "boxes" to the same coordinates, if they look the same. The box would have a width and a height, and the unwrapping would map the "origin" of the box (say top left corner) to the coordinate in the texture file where it should be mapped.
But, for me, width is the length is along the X axis, and height is the length along the Y axis. So how do I decide what is the width and the length when the box is in the X-Z plane, instead of the X-Y plane, for example? And which vertices is the "top left" when all vertices have the same "Y" or "X" coordinate (but vary in Z)? Unlike the real world, there is no "obvious" "up and down", "left and right" ... in computer 3D. Anything can be in any direction. Things don't "fall down" because there is no down.
Hopefully I now made clear my problem. How can I consistently define "top", "left", "width", and "height" when I am in 3D, instead of in 2D, and when a primitive might, for example look like an horizontal line from user point of view because it stretches in Z (which traditionally "comes out of the monitor") instead of Y?
My code can only make sense if I can define all concepts clearly, and unequivocally. I first need a way of defining those concepts that always apply, for any 3 points in 3D space. Only then can I look at any piece of my code, and decide whether it is correct or not. What I cannot define clearly, I cannot program correctly.
What I really want to know is what I asked in the title. I only talked about unwrapping to explain why I need to know this.