Convert 3d point on sphere to UV coordinate

2020-06-28 01:11发布

I have a 3d point on a sphere and want to convert from that, to a UV point on the sphere's texture.

Could someone point in the right direction for the please? I can take a pure math solution.

Edit:

I currently have this, which does not return the correct UV coordinate. p is the 3d point on the sphere mesh.position is the position of the sphere

var x = (p.x-mesh.position.x)/500;
var y = (p.y-mesh.position.y)/500;
var z = (p.z-mesh.position.z)/500;                  

var u = Math.atan2(x, z) / (2 * Math.PI) + 0.5;
var v = Math.asin(y) / Math.PI + .5;

2条回答
祖国的老花朵
2楼-- · 2020-06-28 01:38

I found this wiki article - http://en.wikipedia.org/wiki/UV_mapping - they seem to use a sphere as their example.

Hope it helps.

查看更多
萌系小妹纸
3楼-- · 2020-06-28 01:43

The Wikipedia about uv-mapping is correct however you need to compute the uv coordinate for each vertex of the mesh. Then you need to transform the uv coordinate to pixel coordinate: Perfect (3D) texture mapping in opengl. Here is an other example: http://www.cse.msu.edu/~cse872/tutorial4.html. You can also try three.js. You also need to physically copy the uv triangle.

查看更多
登录 后发表回答