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 /
  • Help Room /
avatar image
0
Question by Fakhri12 · Dec 31, 2021 at 09:37 AM · terrainmeshgenerationmesh-generation

Weird vertices appear when generating grid full of quads

I am trying to generate a grid full of quads that are made up of triangles. Everything works fine at first but when I increase width and height to 300 or more it starts generating weird triangles that aren't supposed to be there. I have no idea what might cause this issue. My guesses are I am drawing triangles wrong.

This is 100x100 grid and it works just fine

alt text


This is 300x300 grid which does some weird stuff

alt text

From underneath it generates this weird looking spaghetti shapes. I tried changing triangles order but it doesn't help. It only gets wilder. One last thing I should probably mention is those weird triangles are rows that should be generated in their own coordinates, the issue is again in my opinion is triangles array. I will stop talking now and put my code here.


Code is a little bit too long but I hope you will take a look at it:

 using UnityEngine;
 
 [RequireComponent(typeof(MeshFilter))]
 public class MeshGeneration : MonoBehaviour
 {
     Vector3[] vertices;
     int[] triangles;
 
     public int width, height;
     [Range(0f, 1f)]
     public float resolution;
 
     Mesh mesh;
    
     private void Start()
     {
         mesh = new Mesh();
         GetComponent<MeshFilter>().mesh = mesh;
 
         GenerateMesh();
         UpdateMesh();
     }
 
     void GenerateMesh()
     {
 
         vertices = new Vector3[(width + 1) * (height + 1)];
 
         for (int x = 0, i = 0; x < width+1; x++)
         {
             for (int z = 0; z < height+1; z++)
             {
                 vertices[i] = new Vector3(x * resolution, 0, z * resolution);
 
                 i++;
             }
         }
 
         triangles = new int[width * height * 6];
 
         int quad = 0;
         int vertice = 0;
 
         for (int x = 0; x < height; x++)
         {
             for (int z = 0; z < width; z++)
             {
                 triangles[quad + 0] = vertice + 0;
                 triangles[quad + 1] = vertice + 1;
                 triangles[quad + 2] = vertice + width + 2;
                 triangles[quad + 3] = vertice + width + 2;
                 triangles[quad + 4] = vertice + width + 1;
                 triangles[quad + 5] = vertice + 0;
 
                 vertice++;
                 quad += 6;
             }
 
             vertice++;
         }
     }
     public void UpdateMesh()
     {
         mesh.name = "ShittyTerrain";
         mesh.vertices = vertices;
         mesh.triangles = triangles;
 
         mesh.RecalculateNormals();
     }
 }




I hope I made everything clear for you. If you have ever encountered an issue like this I would greatly appreciate even a small hint. Thank you if you have read so far!

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

0 Replies

· Add your reply
  • Sort: 

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

128 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

Related Questions

Creating mesh from random points 1 Answer

Why does my Chunk generator reset the vertex positions? 1 Answer

Procedural sphere defects 1 Answer

[Help] Modelled Detail Mesh Completely Invisible 0 Answers

How to spawn in loop like snail but in square 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