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 laucha54321 · Oct 22, 2020 at 03:45 PM · procedural meshprocedural generationprocedural-generationmesh renderermesh manipulation

Why do I get this weird mesh error when I have a mesh over 250 by 250?

alt textI am trying to generate a mesh that is over 250 by 250, but for some reason it breaks and it does not work, it gets weird artifacts on the mesh. If try doing it the mesh for some reason stays rectangular though it should be a square because I only use square sizes so I am sure the error has to do with the rest of the mesh.

 using System.Collections;
     using System.Collections.Generic;
     using System.Security.Cryptography;
     using UnityEngine;
     using UnityEngine.AI;
     using UnityEngine.UIElements;
     
 public class MeshGenerator : MonoBehaviour
 {   //Resolucion del terreno
     public int xSize;
     public int zSize;
     float minTerrainHeight;
     float maxTerrainHeight;
     public int offsetX;
     public int offsetZ;
     //Modificador de aleatoriedad
     public float RandomModifier;
     //Color del terreno generado
     Color[] TerrainColor;
     //Mesh
     Mesh mesh;
     //Vertices y cordenadas de vertices
     Vector3[] vertices;
     int[] triangles;
     //Color del terreno
     public Gradient TerrainHeightColor;
 
     void Start()
     {
         mesh = new Mesh();
         GetComponent<MeshFilter>().mesh = mesh;
         CreateShape();
         UpdateMesh();
         Debug.Log("RandomModifier = " + RandomModifier);
 
     }
     void Update()
     {
     }
     void CreateShape()
     {
         vertices = new Vector3[(xSize + 1) * (zSize + 1)];
         //Generador de las cordenadas de cada vertice del triangulo
         for(int i = 0,z = 0; z <= zSize; z++)
         {
             for(int x = 0; x <= xSize; x++)
             {
 
                 int y = Mathf.RoundToInt(Mathf.PerlinNoise((x+ offsetX) * 0.009f + RandomModifier,(z+offsetZ)*0.009f + RandomModifier)*40f);
                 vertices[i] = new Vector3(x,y,z);
                 i++;
 
                 if (y > maxTerrainHeight)
                     maxTerrainHeight = y;
                 if (y < minTerrainHeight)
                     minTerrainHeight = y;
                 //Debug.Log("y = " + y);
 
             }
         }
 
 
         triangles = new int[xSize * zSize * 6];
         int vert = 0;
         int tris = 0;
 
         //Generador de vertices de los triangulos
         for(int z = 0;z < zSize; z++)
         {
             for(int x = 0;x < xSize; x++)
             {
                 triangles[tris + 0] = vert;
                 triangles[tris + 1] = vert + xSize +1;
                 triangles[tris + 2] = vert + 1;
                 triangles[tris + 3] = vert + 1;
                 triangles[tris + 4] = vert +xSize+ 1;
                 triangles[tris + 5] = vert + xSize + 2;
 
                 vert++;
                 tris += 6;
             }
             vert++;
         }
         TerrainColor = new Color[vertices.Length];
 
         for(int i= 0,z = 0;z <= zSize;z++)
         {
             for(int x = 0; x <= xSize; x++)
             {
                 float height = Mathf.InverseLerp(minTerrainHeight,maxTerrainHeight, vertices[i].y);
                 TerrainColor[i] = TerrainHeightColor.Evaluate(height);
                 i++;
             }
         }
         Debug.Log("MAX:" + maxTerrainHeight);
         Debug.Log("MIN:" + minTerrainHeight);
     }
     void UpdateMesh()
     {
         mesh.Clear();
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.RecalculateNormals();
 
         for (int i = 0, z = 0; z <= zSize; z++)
         {
             for (int x = 0; x <= xSize; x++)
             {
                 float height = Mathf.InverseLerp(-1, 40, vertices[i].y);
                 TerrainColor[i] = TerrainHeightColor.Evaluate(height);
                 i++;
             }
         }
         mesh.colors = TerrainColor;
     }
     private void OnDrawGizmos()
     {   if (vertices == null) return;
         for(int i = 0; i < vertices.Length; i++)
         {
             Gizmos.DrawSphere(vertices[i], .1f);
         }
     }
 }


error-en-la-mesh.jpg (228.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 Klarzahs · Oct 24, 2020 at 12:06 AM 0
Share

Did you check that you are below the maximum amount of vertices in your mesh (see here)?

avatar image laucha54321 Klarzahs · Oct 26, 2020 at 10:45 PM 0
Share

Yes that was the problem, I fixed it. Thank you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Physi3 · Nov 23, 2021 at 04:28 PM

Hi Laucha,

The problem here is you have reached Unity's vertex limit of 65535.

250x250 (62500 vertices) is the largest square Unity can make without passing its limits.

You'll need to split your mesh into multiple objects.

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

144 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

Related Questions

Procedurally generate 3D mesh from 2D image 1 Answer

Procedural Mesh From Random List Of Veritces 2 Answers

How to render procedurally generated mesh to be rendered as 2 sided? 1 Answer

UV problem on procedural mesh generation 1 Answer

C# Proceducal Mesh terrain 2 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