Answers for "UV mapping a hexagon, starting from a 3D space"
http://answers.unity.com/questions/1408980/uv-mapping-a-hexagon-starting-from-a-3d-space.html
The latest answers for the question "UV mapping a hexagon, starting from a 3D space"Answer by IgorAherne
http://answers.unity.com/answers/1409012/view.html
Your vertices are part of the mesh, and are specified relative to the mesh's pivot;
You need to project needed vertices onto a bounded rectangle, and the resulting coordinate (expressed in terms of units along the rectangle's horizontal and vertical axis will be your u and v coordinates respectively). If rectangle is 10x10 meters, then if your projected point ends up in, say 2,5 then you can say it's [2/10, 5/10] == [0.2f, 0.5] uv coordinates.
To perform projection you need to specify some "warp mechanism" that will take the points and re-specify them relative to the rectangle. For that we use matrices;
To create such a matrix you will need to know the rectangle's position relative to the world's zero coordinate, the rectangle's orientation and scale.
You first take your prizm vertex out of the local space, by multiplying the prizm's `transform.localToWorldMatrix` - this specifies prism's vertex relative to the world's zero, no longer relative to the prizm's pivot;
Then, you need to take it from world space into rectangle's space (rectangle onto which you will project the point). To do this, use `myRectangleGameObject.transform.worldToLocal`matrix.
Now the point is relative to the axis of the rectangle. For simplicity, you can imagine the rectangle as being the flat ground, and its 3 axis sticking out. Its y axis sticks out from that rectangle, and can act as a normal of that rectangle.
Now, you have the rectangle of which you are now legally allowed to think of as a flat ground, and a vertex that was specified relative to its 3 axis. The vertex is like a star in the sky
Take that star and project it onto the ground, using plane equations - the normal of the rectangle and distance from your vertex to the *current* zero coordinate (after we've done the above transofrmation, the zero coordinate will be the pivot of the rectangle - since our vertex is now a vector from that pivot, - the vertex is no longer relative to the world's zero or it's mesh's pivot)Tue, 19 Sep 2017 05:45:05 GMTIgorAherne