|
So, I am trying to learn more about how to UV something procedurally. The first toy problem I'm trying to solve is how do you UV the default UV on the default Unity sphere. From left to right - default, planar, and Wikipedia spherical
for(var i=0;i<uvs.Length;i++){
var r = Mathf.Sqrt(vertices[i].x*vertices[i].x + vertices[i].y*vertices[i].y + vertices[i].z*vertices[i].z);
uvs[i] = Vector2(vertices[i].z/r,vertices[i].x/r);
}
If I am conveying the UV coordinates right, it's not planar or the Wikipedia sphere UV (code snippet above)...
(comments are locked)
|
|
It's more like something in the line of: why? and why are things scaled by pi by 2?
May 29 '11 at 02:25 AM
ina
If you cut the sphere anywhere horizontally (=the X-Z-plane, if Y is up), you will get a circle. The position, or more precisely, the angle of a point on that circle is determined by the x and z coordinates. To compute this "longitude" for a given point on that circle, you can use the http://en.wikipedia.org/wiki/Atan2 function. However, since it returns a value in radians, where 2*Pi is a full circle, you need to divide by 2*Pi to map to the 0..1 range. Similarly, for the height, you can compute the "latitude" angle using the ratio height:radius, so that the "north pole" results in acos(1/1)=0, and the "south pole" in acos(-1/1)=Pi - again, the angle is in radians, so here divide by Pi (since we only have a half circle) to map to the 0..1 range. More intuitively, real latitude ranges from asin(1)=Pi/2 (=90 deg) to asin(-1)=-Pi/2 (=-90 deg).
May 29 '11 at 02:53 AM
Wolfram
(comments are locked)
|


For some reason the other part of my question got truncated, and edit mode deletes half the post o.O -- the question is how do you loop thru the uv coordinates to get the uv mapping of the unity default sphere