- Home /
How can I apply the default UV mapping of a Unity Sphere to an imported (eg. blender) sphere?
I have a 360 degree image which wraps around very well on the default Unity Sphere. But I need a lower poly sphere, so I made one in Blender. But it's impossible to apply the same wonderful uv mapping of the default sphere to the one I make in blender. No UV projection I've tried can match it. Is there a way to bypass the imported objects UV mapping and use a unity sphere default one?
Answer by Bunny83 · Jul 08, 2014 at 08:47 AM
The default sphere in Unity has actually three UV maps (two different). See those two pictures:
The first(uv) one is the primary one. As you can see it's some kind of distorted cylinder projection. Only the top and bottom triangles are streched.
The second one is a pretty custom one which is probably used for lightmapping. It has a more well distributed surface which better matches the actual UV-to-world scale.
The third is the same as the second.
The first one could easily be calculated. The second one is way harder.
For the first one all you need to do is to convert the local space cartesian coordinates into spherical coordinates. The two angles can be used as UV coordinates. The polar angle is, after it's normalized between 0 and 1 the u-coordinate. The azimuth angle would become the v-coordinate. Of course it has to be adepted to the 0-1 range. Keep in mind that if the sphere has fully shared vertices you have to split at least those on the left and right edge. This would of course require you to add those duplicated vertices to the mesh and adjust the indices accordingly.
Answer by HenryStrattonFW · Jul 07, 2014 at 08:48 PM
It would be quite difficult to do, as your lower poly sphere can't by its nature have a 1 to 1 matching of UV data to the default sphere as obviously there are fewer polygons.
That being said, from here on out is completely untested theory, I have no idea if it would work, or if the implementation would be fraught with pitfalls, or even how to accomplish certain parts. It's just an idea that might give a spark in the right place.
You could at some point place a scaled down version of the unity sphere inside your sphere, then for each vertex of your sphere, raycast toward the center of the unity sphere and somehow determine the face of contact, or rather the 3 nearest verts, you can then pull the UV data of those verts, and interpolate the uv coordinate that you actually hit. Once you've gone through all of your verts you should have uv data that matches (near enough) the mapping of the default sphere.
Like I said this is just a theory, I'm not sure if there is an easy way to pull back the verts of the face the raycast hit. I know you could do it manually but that would likely be slower than you'd ideally want.
EDIT: Had a quick search, it looks like if for this process you used a mesh collider for the unity sphere instead of just a sphere collider, you can get the triangle index of the face hit by the raycast. http://docs.unity3d.com/ScriptReference/RaycastHit-triangleIndex.html This will allow you to pull back the necessary verts UV data.
This is of course only useful if you're not opposed to doing a bit of coding. Although if you could provide your mesh, I'd actually be interested in trying this, just to see if I could do it (no promises mind) There may even already be a tool somewhere to do this but I haven't really looked for one.
This actually sounds very smart and a quite possible solution, thanks for sharing! I still have quite a way to become accustomed to these levels of coding. I was wondering about all this because I'm trying to use a video texture on a sphere, facing some performance issues. It seems though that using a lower poly sphere won't improve the performance as I expected and that it is more a matter of file size. But that's for another topic!
Your answer
Follow this Question
Related Questions
How can i fix this uv tiling/ distortion problem? 2 Answers
Blender Model Texture not seamless in Unity 0 Answers
Blender UV map texture problem? 1 Answer
[Blender] How to export 2 UVMap applied to the same Mesh 2 Answers
Materials or UV texture? 1 Answer