Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 FineBrisk · Oct 21, 2020 at 08:59 AM · meshesmesh verticesmesh manipulationmaths

can somebody explain to me what is going on in this script ??

in the code below planet.init calls the tile.init().

Context: The Planet class is fed a data object containing information about the planet to spawn, the main one being the radius (how many tiles deep it goes). The same amount of circular strips are then created by spawning a number of tiles depending on the circumference per strip (the farther out it goes, the more tiles are needed to not make the sprites seem stretched), and for every tile, a new mesh is created as shown in the video. It's just a quad-strip where the vertices are snapped to a certain radius from the center of the planet. The sprites are just used as textures on top of that quad-strip by letting the uv-coordinates run from (0,0) to (1,1) for every tile

planet.init() :

 public void Init(Level level, Pickup[] pickupPrefabs)
     {
         float planetScale = (level.RowCount + YOffset - 1) * 2 + 0.5f;
         _planetSphere.localScale = new Vector3(planetScale, planetScale, 1);
         _planetSphereBackground.localScale = new Vector3(planetScale, planetScale, 1);
 
         float totalRadius = level.TotalRadius;//.RowCount + YOffset - 1;
         
         Tiles = new List<Tile>();
         for (int i = 0; i < level.RowCount; i++)
         {
             float rowRadius = i + YOffset;
             float circumference = 2 * Mathf.PI * rowRadius;
 
             int rowTileCount = Mathf.RoundToInt(circumference / TileWidth);
 
             Tile tilePrefab = i == level.RowCount - 1 ? _grassPrefab : _dirtPrefab;
 
             for (int j = 0; j < rowTileCount; j++)
             {
                 Tile tile = Instantiate(tilePrefab, transform);
                 tile.Init(j, rowRadius, rowTileCount, 1f, planetBar);
                 Tiles.Add(tile);
             }
         }
 

Tile.init() :

  public void Init(int xIndex, float rowY, int rowTileCount, float rowHeight, Bar planetBar)
     {
         this.planetBar = planetBar;
         
         mesh = new Mesh();
         
         List<Vector3> vertices = new List<Vector3>();
         List<int> indices = new List<int>();
         List<Vector2> uvs = new List<Vector2>();
 
         float minX = (float)xIndex / rowTileCount;
         float maxX = (xIndex + 1f) / rowTileCount;
         float minY = rowY;
         float maxY = minY + rowHeight;
          
         for(int i = 0; i < HorizontalVertexCount; i++)
         {
             float t = (float)i / (HorizontalVertexCount - 1);
             
             float x = Mathf.Lerp(minX, maxX, t);
             
             Vector3 vertTop = new Vector3(maxY * Mathf.Cos(x * Mathf.PI * 2f), maxY * Mathf.Sin(x * Mathf.PI * 2f)) - transform.position;
             vertices.Add(vertTop);
             uvs.Add(new Vector2(t, 1f));
             center += vertTop;
             
             Vector3 vertBottom = new Vector3(minY * Mathf.Cos(x * Mathf.PI * 2f), minY * Mathf.Sin(x * Mathf.PI * 2f)) - transform.position;
             vertices.Add(vertBottom);
             uvs.Add(new Vector2(t, 0f));
             center += vertBottom;
 
             if(i > 0)
             {
                 int vertexCount = vertices.Count - 1;
                 
                 indices.Add(vertexCount - 3);
                 indices.Add(vertexCount - 2);
                 indices.Add(vertexCount - 1);
                 
                 indices.Add(vertexCount - 1);
                 indices.Add(vertexCount - 2);
                 indices.Add(vertexCount);
             }
         }
         center /= vertices.Count;
         
         mesh.vertices = vertices.ToArray();
         mesh.triangles = indices.ToArray();
         mesh.uv = uvs.ToArray();
 
         up = center.normalized;
         
         _textureFilter.mesh = mesh;
         _colorMeshFilter.mesh = mesh;
         _backgroundMeshFilter.mesh = mesh;
     }

MORE SPECIFICALLY, i want to understand how vertTop and vertBottom are created in Tile.init method ??

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Klarzahs · Oct 21, 2020 at 12:17 PM

Hi @FineBrisk,

this looks like a variant of the cosine sphere representation, similar to this image: alt text
You can find more information at the OpenGL Sphere section of songha.co
Hope this helps

Comment
Add comment · Show 1 · 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 FineBrisk · Oct 21, 2020 at 03:02 PM 0
Share

Hey, thank you for taking your time out to respond. I am not sure i get it all in the first go but i guess i have to come back at it a few more times.

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

136 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Line of Sight using Mesh ,Line of Sight Mesh 2 Answers

Sort a list based on edge connections 1 Answer

delete specific triangles / polygons in a mesh 2 Answers

Ideas/Solutions for finding the outside corner points of a mesh 1 Answer

Animating the Mesh Morpher on function call. 0 Answers


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