Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ina · May 28, 2011 at 11:47 PM · meshproceduralsphereverticesuv

UV-ing a sphere procedurally

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)...

alt text

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · May 28, 2011 at 11:48 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Wolfram · May 29, 2011 at 12:07 AM

It's more like something in the line of:

 uvs[i] = Vector2(Mathf.Atan2(vertices[i].z,vertices[i].x)/Mathf.Pi/2,Mathf.Acos(vertices[i].y/r)/Mathf.Pi);
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · May 29, 2011 at 02:25 AM 0
Share

why? and why are things scaled by pi by 2?

avatar image Wolfram · May 29, 2011 at 02:53 AM 0
Share

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 deter$$anonymous$$ed 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. $$anonymous$$ore intuitively, real latitude ranges from asin(1)=Pi/2 (=90 deg) to asin(-1)=-Pi/2 (=-90 deg).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Easy way to convert a bunch of vertices to triangles or uv's? 1 Answer

How do I guarantee a generated sphere's mesh is facing outward? 1 Answer

How to texture walls in procedurally generated mesh? 1 Answer

How to split UV in Mesh 1 Answer

Selecting a single polygon / face at runtime 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges