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 /
avatar image
0
Question by MakakWasTaken · Sep 24, 2015 at 12:11 PM · terrainmeshheightmap

Terrain Clone

I have been trying to clone my project for an system that I wanted to implement, but the problem is it turns out looking like this: Problem Why is it ending up being this clunky?

Here is my code for the mesh generation:

             int ChunkWidth = 250;
             int ChunkCount = (int)Chunk.terrainData.size.x / ChunkWidth;
             //Chunk is my terrain instance.
             int hw = Chunk.terrainData.heightmapWidth;
             float[,] heightmap = Chunk.terrainData.GetHeights(0,0,aw,aw);
             Vector2 uvScale = new Vector2(1.0f / (hw- 1), 1.0f / (hw- 1));
 
             for (int cx = 0; cx < ChunkCount; cx++)
             {
                 for (int cy = 0; cy < ChunkCount; cy++)
                 {
                     GameObject water = new GameObject();
                     Vector3 p = new Vector3(cx * ChunkWidth, -1f, cy * ChunkWidth);
                     water.transform.position = p;
                     water.AddComponent<MeshRenderer>();
                     Mesh w = new Mesh();
                     MeshFilter mf = water.AddComponent<MeshFilter>();
 
                     Vector3[] vertices = new Vector3[ChunkWidth * ChunkWidth];
                     Vector2[] UV = new Vector2[ChunkWidth * ChunkWidth];
                     int[] triangles = new int[ChunkWidth * ChunkWidth * 6];
 
                     for (int y = (int)p.z; y < p.z + ChunkWidth; y++)
                     {
                         for (int x = (int)p.x; x < p.x + ChunkWidth; x++)
                         {
                             Vector2 curPos = new Vector2((x / Chunk.terrainData.size.x) * (hw-1), (y / Chunk.terrainData.size.z) * (hw- 1));
                             vertices[(y - Mathf.RoundToInt(p.z)) * ChunkWidth + (x - Mathf.RoundToInt(p.x))] = new Vector3((x - p.x), heightmap[Mathf.RoundToInt(curPos.y), Mathf.RoundToInt(curPos.x)] * Chunk.terrainData.size.y, (y - p.z));
                             UV[(y - (int)p.z) * ChunkWidth + (x - (int)p.x)] = Vector2.Scale(new Vector2(x, y), uvScale);
                         }
                     }
 
                     int index = 0;
 
                     for (int y = 0; y < ChunkWidth - 1; y++)
                     {
                         for (int x = 0; x < ChunkWidth - 1; x++)
                         {
                             triangles[index] = (y * ChunkWidth) + x;
                             triangles[index + 1] = ((y + 1) * ChunkWidth) + x;
                             triangles[index + 2] = ((y + 1) * ChunkWidth) + x + 1;
 
                             triangles[index + 3] = (y * ChunkWidth) + x;
                             triangles[index + 4] = ((y + 1) * ChunkWidth) + x + 1;
                             triangles[index + 5] = (y * ChunkWidth) + x + 1;
                             index += 6;
                         }
                     }
 
                     w.vertices = vertices;
                     w.uv = UV;
                     w.triangles = triangles;
                     w.RecalculateNormals();
                     w.Optimize();
                     mf.mesh = w;
 
                     yield return null;
                 }
             }

EDIT: Another screenshot with wireframe turned on, where you can clearly see that the problem is the difference between the heightmap width and the actual terrain size. How can I make some interpolation to fix this? alt text

problem.png (338.7 kB)
untitled.png (306.2 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 getyour411 · Sep 28, 2015 at 03:39 PM 0
Share

What is the heightmap resolution? If you select the wireframe with texture option and set opacity to 1 on your brush and use lower/raise on the vert here that is showing the issue, are you able to move it up or down in smaller increment?

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

30 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

Related Questions

The most efficient method of turning a voronoi graph into unity terrain object? 0 Answers

Mesh based on noise 1 Answer

how can i correctly create big terrain? 0 Answers

Import a 513x513 Texture2D (heightmap) 0 Answers

heightmapWidth and heightmapHeight always equal 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