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 /
  • Help Room /
avatar image
0
Question by WSFMigo · Mar 22, 2020 at 01:28 PM · meshproceduralprocedural meshprocedural generation

Problem with Procedural Mesh Generation

Hi All,

I am currently having an issue with mesh generation, I followed brackeys tutorial on Mesh Generation for procedural maps and seem to be having an issue that I cannot solve.

The problem I am having is, it isn't generating a grid with Perlin noise. It is instead generating what is being shown in the image below. It is just meant to be a grid like mesh.

Here is an image: alt text

Image 2: alt text

Here is my code:

 using UnityEngine;
 
 public class MeshGenerator : MonoBehaviour
 {
     public int xSize = 20;
     public int zSize = 20;
 
     Mesh mesh;
     Vector3[] vertices;
     int[] triangles;
 
     void Start()
     {
         mesh = new Mesh();
         GetComponent<MeshFilter>().mesh = mesh;
 
         CreateShape();
         UpdateMesh();
     }
 
     private void CreateShape()
     {
         vertices = new Vector3[(xSize + 1) * (zSize + 1)];
 
         for (int i = 0, z = 0; z <= zSize; i++, z++)
         {
             for (int x = 0; x <= xSize; x++)
             {
                 var y = Mathf.PerlinNoise(x * .3f, z * .3f) * 2f;
                 vertices[i] = new Vector3(x, y, z);
             }
         }
 
         triangles = new int[xSize * zSize * 6];
         var vert = 0;
         var tris = 0;
 
         for (var z = 0; z < zSize; z++)
         {
             for (var x = 0; x < xSize; x++)
             {
                 triangles[vert + 0] = vert + 0;
                 triangles[vert + 1] = vert + xSize + 1;
                 triangles[vert + 2] = vert + 1;
                 triangles[vert + 3] = vert + 1;
                 triangles[vert + 4] = vert + xSize + 1;
                 triangles[vert + 5] = vert + xSize + 2;
 
                 vert++;
                 tris += 6;
             }
 
             vert++;
         }
     }
 
     private void UpdateMesh()
     {
         mesh.Clear();
 
         mesh.vertices = vertices;
         mesh.triangles = triangles;
 
         mesh.RecalculateNormals();
     }
 }
 

Regards,

Migo

uhoh2.png (71.4 kB)
Comment
Add comment · Show 2
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 streeetwalker · Mar 22, 2020 at 01:37 PM 0
Share

@WSF$$anonymous$$igo, you don't describe what the problem is. You should edit your post to include that! And please be more specific than "it doesn't work."

avatar image WSFMigo streeetwalker · Mar 22, 2020 at 01:40 PM 0
Share

Updated to have more details

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by streeetwalker · Mar 22, 2020 at 02:38 PM

You have two problems:

  1. Your not incrementing i to match the full number of vertices your creating in the vertex generation loops - you increment i in the outer loop. But you should increase the value of I for every vertex you create, not for each row. So increment i in the inner loop, not as part of the loop declaration.

  2. you need to increase the triangle array index by 'tris' not 'vert' (should be triangles[tris+ 0] and so on)

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 WSFMigo · Mar 22, 2020 at 02:41 PM 0
Share

Cheers the i++ solved it and Ill change the tris now, in the comments of the youtube someone wrote that as a 'clean up' and forgot I did it!

EDIT: The tris worked too, thank you!

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

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

Shared or Non-shared Vertices for mesh generation? 0 Answers

Mesh per Chunk Vs. Mesh per Voxel 1 Answer

How can I identify the location of mesh triangles at run time? (Procedural Generation) 1 Answer

Weird Artifacts in Mesh generated by Script 1 Answer

Mesh wont render although there are no errors! 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