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
2
Question by bagus123ind · Jul 19, 2020 at 01:46 AM · meshproceduralgeneration

generate procedural floating island

i want make simple lowpoly procedural generation floating island in unity,like this : alt text

so I decided to make a simple sphere then I flattened the top and randomly generated the bottom noise but several times I tried I did not get the results I wanted, like a right curve and no taper

alt text

so how can I get results the right mesh? Is there something wrong with my code? or is there another algorithm that I can use?

the code I've used so far...

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SphereGenerator : MonoBehaviour
 {   
 
     public float minRadius = 1f;
     Vector3[] vertices;
     Vector3[] normales;
     Vector2[] uvs;
     int[] triangles;
     MeshFilter filter;
 
 
     // Start is called before the first frame update
     void Start()
     {
         
        StartCoroutine(createMesh());
     }
 
     // Update is called once per frame
     void Update()
     {
         updateMesh();
     }
 
     IEnumerator createMesh(){
         float radius = minRadius;
         // Longitude |||
         int nbLong = 24;
         // Latitude ---
         int nbLat = 16;
         
         #region Vertices
         vertices = new Vector3[(nbLong+1) * nbLat + 2];
         float _pi = Mathf.PI;
         float _2pi = _pi * 2f;
         
         vertices[0] = Vector3.zero;
 
         float y = 0f;
         for( int lat = 0; lat < nbLat; lat++ )
         {
             float a1 = _pi * (float)(lat+1) / (nbLat+1);
             float sin1 = Mathf.Sin(a1);
             float cos1 = Mathf.Cos(a1);
         
             for( int lon = 0; lon <= nbLong; lon++ )
             {
                 float a2 = _2pi * (float)(lon == nbLong ? 0 : lon) / nbLong;
                 float sin2 = Mathf.Sin(a2);
                 float cos2 = Mathf.Cos(a2);
                 y = cos1 - Mathf.PerlinNoise(Time.time*1f,0f) * 2f;
                 float x = Time.time*(sin1 * cos2) * Random.Range(0f,1f);
                 float z = Time.time*(sin1 * sin2) * Random.Range(0f,1f);
 
                 //check top half
                 if(lat <= nbLat/2){
                     // float height = Random.Range(0f,0.1f);
                     // Debug.Log(height);
                     // y = height;
                     y = 0f;
                 } else {
                     z = (sin1 * sin2) * Random.Range(0f,1f);
                 }
 
                 float newRad = radius;
                 newRad = radius + Mathf.PerlinNoise(x,z) * 2f;
                 vertices[ lon + lat * (nbLong + 1) + 1] = new Vector3( sin1 * cos2, y, sin1 * sin2 ) * newRad;
             }
         }
          vertices[vertices.Length-1] = Vector3.up * (-radius + y - Random.Range(0f,1f));
         #endregion
         
         #region Normales        
         normales = new Vector3[vertices.Length];
         for( int n = 0; n < vertices.Length; n++ )
             normales[n] = vertices[n].normalized;
         #endregion
         
         #region UVs
         uvs = new Vector2[vertices.Length];
         uvs[0] = Vector2.up;
         uvs[uvs.Length-1] = Vector2.zero;
         for( int lat = 0; lat < nbLat; lat++ )
             for( int lon = 0; lon <= nbLong; lon++ )
                 uvs[lon + lat * (nbLong + 1) + 1] = new Vector2( (float)lon / nbLong, 1f - (float)(lat+1) / (nbLat+1) );
         #endregion
         
         #region Triangles
         int nbFaces = vertices.Length;
         int nbTriangles = nbFaces * 2;
         int nbIndexes = nbTriangles * 3;
         triangles = new int[ nbIndexes ];
         
         //Top Cap
         int i = 0;
         for( int lon = 0; lon < nbLong; lon++ )
         {
             triangles[i++] = lon+2;
             triangles[i++] = lon+1;
             triangles[i++] = 0;
         }
         
         //Middle
         for( int lat = 0; lat < nbLat - 1; lat++ )
         {
             for( int lon = 0; lon < nbLong; lon++ )
             {
                 int current = lon + lat * (nbLong + 1) + 1;
                 int next = current + nbLong + 1;
         
                 triangles[i++] = current;
                 triangles[i++] = current + 1;
                 triangles[i++] = next + 1;
         
                 triangles[i++] = current;
                 triangles[i++] = next + 1;
                 triangles[i++] = next;
 
                 yield return new WaitForSeconds(.05f);
             }
         }
         
         //Bottom Cap
         for( int lon = 0; lon < nbLong; lon++ )
         {
             triangles[i++] = vertices.Length - 1;
             triangles[i++] = vertices.Length - (lon+2) - 1;
             triangles[i++] = vertices.Length - (lon+1) - 1;
         }
         #endregion
         
     }
 
     void updateMesh(){
         filter = gameObject.GetComponent< MeshFilter >();
         Mesh mesh = new Mesh();
         mesh.Clear();
         mesh.vertices = vertices;
         mesh.normals = normales;
         mesh.uv = uvs;
         mesh.triangles = triangles;
         mesh.RecalculateNormals();
         mesh.RecalculateBounds();
         mesh.Optimize();
         filter.mesh = mesh;
     }
 }
 

I have taken references from:

  • https://www.youtube.com/watch?v=64NblGkAabk

  • http://wiki.unity3d.com/index.php/ProceduralPrimitives?_ga=2.37158691.2098954095.1595047090-1782919353.1594102055

island-sky-min.png (174.6 kB)
screen-shot-2020-07-19-at-092325.png (67.0 kB)
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 mrHenning · Oct 24, 2021 at 03:46 PM 0
Share

Have you figured it out?,Did you figure it out?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SwirlyMcGee · Oct 22, 2021 at 02:06 PM

This may not be what you're looking for, but couldn't you just model different islands and then choose a random one from the list? If you had about 20 different models, no one would ever be able to tell the difference anyway, but you could get exactly the kind of island you wanted.

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

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

153 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 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

creating a mesh procedurally 4 Answers

Procedurally generated mesh JS - explain the error please 0 Answers

Unity3D question about the Procedural Generation engine for creatures in Spore? 1 Answer

Procedurally Generated Cube Mesh 3 Answers

Mesh.uv is out of range 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