Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ebil · Feb 13, 2012 at 11:52 PM · mathsphereplanetformula

Creating a sphere out of six planes

Hello,

I want to create a sphere from six planes (to use normal maps on them). But I have problems with the math. I got the math from here http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html

Converted it to a formular I want to use in unity

      var mesh : Mesh = GetComponent(MeshFilter).mesh;
     var vertices : Vector3[] = mesh.vertices;
     var normals : Vector3[] = mesh.normals;
 
    for (var i = 0; i < vertices.Length; i++)
    {
         vertices[i] +=     Vector3(Mathf.Sqrt(
                                     1-(Mathf.Pow(vertices[i].y,2) / 2)
                                     - (Mathf.Pow(vertices[i].z,2) / 2)
                                     + ((Mathf.Pow(vertices[i].y,2) * Mathf.Pow(vertices[i].z,2)) / 3)),
                                 Mathf.Sqrt(
                                     1-(Mathf.Pow(vertices[i].z,2) / 2)
                                     - (Mathf.Pow(vertices[i].x,2) / 2)
                                     + ((Mathf.Pow(vertices[i].z,2) * Mathf.Pow(vertices[i].x,2)) / 3)),
                                 Mathf.Sqrt(
                                     1-(Mathf.Pow(vertices[i].x,2) / 2)
                                     - (Mathf.Pow(vertices[i].y,2) / 2)
                                     + ((Mathf.Pow(vertices[i].x,2) * Mathf.Pow(vertices[i].y,2)) / 3)));
    }
     mesh.vertices = vertices;


Im fairly sure I did something wrong with the formular , im really not good in mathematics.

Thats how it looks like that: alt text

You see its just wrong :)

Its like its shrinked, it is not flat, its a little "rounded", but its not like I want it, also much much too low poly (I tried it with a from 3ds max imported high poly cube, same result) I used that formular from the website: alt text

Comment
Add comment · Show 6
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 Owen-Reynolds · Feb 14, 2012 at 01:56 AM 0
Share

Looks like you forgot the x* at the start (and the y* and 'z*') -- right in front of all the square roots.

Plus, there are probably easier ways to do whatever normal map thing it is.

avatar image Ebil · Feb 14, 2012 at 10:31 AM 0
Share

I also had this x* ... it doesnt worked and looked even more crappy, so i removed it. Easier ways? What do you have in $$anonymous$$d? afaik thats the easiest way.

avatar image Owen-Reynolds · Feb 14, 2012 at 07:31 PM 0
Share

Turning a cube into a sphere, leaving normals alone, will give the new sphere a "flat-sided" shading -- the exact opposite of what most people want. But, if you really wanted that, you could start with a sphere and assign normals (1,0,0), (0,1,0) ... to each vert based on the largest axis.

You might also check your original model has (0,0,0) in the exact center (the formula seems to assume that.)

avatar image Ebil · Feb 15, 2012 at 10:48 AM 0
Share

Well what I have to do with the normals? I just changed vertices, I tried to change normals but nothing happens (I never worked with them). Whats the difference between normals and vertices? The position of the object is $$anonymous$$or. Please see my comment below for actual state. Still dont know how to go on :/

avatar image MountDoomTeam · Feb 18, 2013 at 01:27 AM 0
Share

making round things from 6 planes?I have done something related, UV mapping any procedural shaped with 6 planes, called box projection, you can map spheres also, although I haven't figured the normals yet.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Feb 14, 2012 at 12:11 AM

Some thoughts: You should only need to deform one plane (Unity's default plane has 10 x 10 cells, if you need more, use Blender to make one, or generate it from scratch). Make sure you are deforming in the correct direction for that plane. Also you probably want to use = instead of += to assign the new values

Comment
Add comment · Show 5 · 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 Ebil · Feb 14, 2012 at 10:30 AM 0
Share

Yes I tried also = , its nearly the same result. What do you mean by one plane? Its common to use six planes to create a sphere out of it, never heard of just one plane. The cube you see there is made of 6 planes, so there is every direction included, but you see the result :/

avatar image Owen-Reynolds · Feb 14, 2012 at 07:24 PM 0
Share

If you tried it on just one plane, you'd get just one of those shallow bowl shaped meshes. It would be easier to see any problems. Once that worked, you could copy it, rotated to make the other 5 "faces."

avatar image Ebil · Feb 15, 2012 at 10:46 AM 0
Share

I tried it with just one plane, with 6 seperated and with a high poly cube. All is the same result, it has nothing to do with orientation or position :/ I make no progress, yesterday tried the whole day how to create the sphere. But its always nearly the same result as you see above.

I used this code now :

    for (var i = 0; i < vertices.Length; i++)
    {

         vertices[i] =     Vector3(vertices[i].x*($$anonymous$$athf.Sqrt(
                                     1-($$anonymous$$athf.Pow(vertices[i].y,2) / 2)
                                     - ($$anonymous$$athf.Pow(vertices[i].z,2) / 2)
                                     + (($$anonymous$$athf.Pow(vertices[i].y,2) * $$anonymous$$athf.Pow(vertices[i].z,2)) / 3))),
                                 vertices[i].y*($$anonymous$$athf.Sqrt(
                                     1-($$anonymous$$athf.Pow(vertices[i].z,2) / 2)
                                     - ($$anonymous$$athf.Pow(vertices[i].x,2) / 2)
                                     + (($$anonymous$$athf.Pow(vertices[i].z,2) * $$anonymous$$athf.Pow(vertices[i].x,2)) / 3))),
                                 vertices[i].z*($$anonymous$$athf.Sqrt(
                                     1-($$anonymous$$athf.Pow(vertices[i].x,2) / 2)
                                     - ($$anonymous$$athf.Pow(vertices[i].y,2) / 2)
                                     + (($$anonymous$$athf.Pow(vertices[i].x,2) * $$anonymous$$athf.Pow(vertices[i].y,2)) / 3))));
                                     
 
    }

And the result is that:

http://imageshack.us/photo/my-images/263/crapcube.png/ out of that plane: http://imageshack.us/photo/my-images/836/planei.png/

avatar image Owen-Reynolds · Feb 15, 2012 at 05:31 PM 0
Share

Your code above works perfectly -- I tried it on a high-poly cube, with (0,0,0) in the center. It deforms it into a perfect sphere, keeping the same lighting as when it was a cube.

I can't think of a use for it. Normal mapping works fine on regular spheres.

avatar image Ebil · Feb 15, 2012 at 06:50 PM 0
Share

Bump maps work perfectly on a sphere. But if you want to create a Planet, you need mountains, hills, craters, canyons and so on. I want to do that with a highmap. That cant be used on a sphere, but on 6 pla nes that are then formed to a sphere. Thats the usual way how to do it. Also normal spheres got too much disortion.

I wonder why this is working for you ... Its not working for me o.o.

I try that for days now and want to know what i do wrong, if my code is correct --

avatar image
0

Answer by Xete · Feb 08, 2013 at 07:38 AM

okay i may have found out the problem although i am not sure, simply have:

var amount : float = 1.0f; var refresh:boolean = false; function Start () { tryu(); }

at top then this function Update () { if(refresh){ tryu(); refresh=false; } }

//you be able to see once u keep pressing refresh it begins to turn into a sphere, although not perfectly atm, and thanks for sharing, p.s first time postin so sorry if its already anwsered

Comment
Add comment · Show 4 · 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 Xete · Feb 08, 2013 at 02:38 AM 0
Share

okay improvement, now time to sleep ,lucid dream timeeeeeeee, anyways so before starting on the inspector mode, simple change the amount to 0.5f, and with one refresh on a high poly cube will make it nicely perfect sphere, well like 80%perfect, it kinda expands the cube making it more suitable rather than shrinking it to sphere which isnt good

avatar image Xete · Feb 08, 2013 at 02:41 AM 0
Share

doesnt seem to work on planes tho, it has the same issue in blender,works fine with cubes..sorry

avatar image Ebil · Feb 08, 2013 at 07:54 AM 0
Share

But whats the tryu() function? o.o

avatar image Xete · Feb 08, 2013 at 11:26 AM 0
Share

(meant to be try kinda hurried cuz it was sleep time) and wohoo atm i managed to get the spherical thing working with both a cube and a plane, it just applies your code to the object many times u want, once u have it working just once then you can just put it in start function, of course u gotta change the amount too, where it goes is Vector3(vertices[i].x/ amount *.... <-- each time u calculating a vertice position, then change ur amount to 0.5 in inspector and it shud work once (for plane into spherical form) and for cube well u have to run it and then refresh it again in the inspector to make it a sphere,, plane =1 refresh, cube = 2 refresh, atm im trying to apply random heights for each plane and sorry if i dnt make sense

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I make a sphere with equidistant vertices? 1 Answer

Find position of pixel on sphere given position of pixel on texture 1 Answer

Rotation Script Changes the Object Axis Inclination Too 2 Answers

calculus help angels of a triangle 1 Answer

how to make gravity in the center of a sphere 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