Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

UV issues creating a mesh

Discussion in 'Editor & General Support' started by jzaun, Jun 2, 2010.

  1. jzaun

    jzaun

    Joined:
    Feb 20, 2010
    Posts:
    25
    I'm not sure if this is the correct place to ask this or not. If its not please forgive me...

    I've been working on a script to create a sphere, that I can then deform. So far I can create the mesh of the sphere. The code is attached.

    Much of this code I've gotten, read about or seen on the web in one form or another, but its working in Unity now :) My issue is that the UVs are all messed up and I'm not sure how to correct it. This is my first real stab at creating 3D meshes and I'm just stuck.

    Any ideas how to fix the UVs so a texture (of say a planet like earth) would look correct on the mesh?
     

    Attached Files:

  2. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    Remember that UVs need to be assigned in the 0-1 space. 0,0 is bottom-left and 1,1 is top-right. Your script is very complicated, so try to simplify what you are doing. Maybe begin by drawing only a simple plane with the following points and UVs:
    0,0
    1,0
    0,1
    1,1

    Then expand it to be a 2x2 plane or 10x10 plane and see how that affects the UV mapping. The only way to learn this stuff is by doing!
     
  3. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,406
    Your script is working just fine. There is one simple caveat:
    Code (csharp):
    1. Vector3 vertex = new Vector3(p.x/length, p.y/length, p.z/length);
    2. Vector2 uv = new Vector3(p.x/length, p.z/length);
    here you basically map both top and bottom hemispheres into same uvs. For quick resolve just check p.y sign and move uv-s accordingly (just don't forget to scale them ;-))
    P.S. if you are really into it: that mapping is not that good if you'll have objects viewed from more a single point - uvs gets really skewed near poles.
     
  4. jzaun

    jzaun

    Joined:
    Feb 20, 2010
    Posts:
    25
    So Ive re-factored my code a bit but am still having issues with texture mapping my mesh. You can see some test here:

    http://justinzaun.com/unity/Test.html
    http://justinzaun.com/unity/Test - No SubDivide.html

    The code is online as well:
    http://justinzaun.com/unity/PlanetBuilder.cs
    (It needs to go into an Editor folder and puts a new menu item under GameObject menu.)

    Maybe I'm thinking about this the wrong way? Is there a better texture format I should be using rather than the standard rectangle?

    Are there any examples on the net on how to texturemap a Octahedron?

    It would be nice to be able to map a "standard" planet texture to my sphere, but if I can get anything to map properly I would be ecstatic.

    My ultimate goal would be to automatically generate a texture, so as long as I know the format of the texture to be mapped I think it will work out.
     
unityunity