Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by NeverEndingPrjct · Aug 25, 2014 at 02:48 PM · c#terraindesign

Flat Low Poly Terrain / Script a terrain

i want to build design an low poly terrain in unity like http://i.ytimg.com/vi/-Yrb7mYhV9U/maxresdefault.jpg or this or other nice looking pictures ...

I dont find an solution,datwhy i set up my own Script (its not finised)

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(MeshFilter),typeof(MeshRenderer))]
 public class Map : MonoBehaviour {
 
     public Vector3[] vertices;
     public int[] triangles;
     public Vector2[] uv;
     public Vector3[] normals;
 
     int numberOfVertices = 0;
     int numberOfTriangles = 0;
 
     public float segmentWidth = 50f;
     public float segmentHeight = 50f;
 
     public int numberOfSegmentsAtXAxis = 10;
     public int numberOfSegmentsAtZAxis = 10;
 
     // Use this for initialization
     void Start () {
 
         MeshFilter meshfilter = GetComponent<MeshFilter>();
         Mesh mesh = new Mesh ();
         meshfilter.mesh = mesh;
 
         SetUpMesh ();
 
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.normals = normals;
 //        mesh.uv = uv;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void SetUpMesh(){
 
         numberOfVertices    = (1 + numberOfSegmentsAtXAxis)
                                         * (1 + numberOfSegmentsAtZAxis);
 
         numberOfTriangles    = numberOfSegmentsAtXAxis
                                         * numberOfSegmentsAtZAxis * 2;
 
         vertices = new Vector3[numberOfVertices];
         SetVertices ();
         
         triangles = new int[numberOfTriangles * 3];
         SetTriangles ();
         
         normals = new Vector3[numberOfVertices];
         SetNormals (Vector3.down);
 //
 //        uv = new Vector2[numberOfVertices];
 //        SetUv (uv);
     
     }
 
     void SetVertices (){
 
         for (int sz = 0; sz <= numberOfSegmentsAtZAxis; sz ++) {
                 
             for (int sx = 0; sx <= numberOfSegmentsAtXAxis; sx++){
 
                 int vertex = sx + sz * (numberOfSegmentsAtXAxis + 1);
 
                 vertices[vertex] = new Vector3(sx * segmentWidth,0,sz * segmentHeight);
 
             }
 
         }
 
     }
 
     void SetTriangles (){
 
         int trianglesIndex = 0;
 
         for (int sz = 0; sz < numberOfSegmentsAtZAxis; sz ++) {
             
             for (int sx = 0; sx < numberOfSegmentsAtXAxis; sx++){
 
                 int vertex = sx + sz * (numberOfSegmentsAtXAxis + 1);
 
                 triangles[trianglesIndex+0] = vertex;
                 triangles[trianglesIndex+1] = vertex + numberOfSegmentsAtXAxis + 1;
                 triangles[trianglesIndex+2] = vertex + 1;
 
                 triangles[trianglesIndex+3] = vertex + numberOfSegmentsAtXAxis + 1;
                 triangles[trianglesIndex+4] = vertex + numberOfSegmentsAtXAxis + 2;
                 triangles[trianglesIndex+5] = vertex + 1;
 
                 trianglesIndex += 6;
                 
             }
             
         }
 
     }
 
     void SetNormals (Vector3 direction){
 
         for (int n = 0; n < numberOfVertices; n++) {
         
             normals[n] = direction;
 
         }
 
     }
 
     void SetUv (ref Vector2[] uv){
 
 
 
     }
 }


till now i build an plane ... i want to move the vertecies to positions where they can build an cool terrain.And how to apply other colors to the mesh(for example for mountens or rivers - now its only grren). Is there an algorithem or something simular. Is the code accurate ?

pls help me

thx a guy how want to become an developer

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Josh1231 · Aug 25, 2014 at 04:49 PM

You can have a premade mesh and move the vertices around, you may also recalculate normals after that, that way there is a lower chance of the triangles joining with vertices you don't want it to since it's preset

Comment
Add comment · Show 4 · 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 NeverEndingPrjct · Aug 25, 2014 at 06:13 PM 0
Share

how should i calculate the normals ?

avatar image Josh1231 · Aug 25, 2014 at 06:35 PM 0
Share
 mesh.RecalculateNormals();

You don't have to do it though.

avatar image NeverEndingPrjct · Aug 25, 2014 at 08:46 PM 0
Share

I cant use this method because it makes the mesh smoother :(

avatar image Josh1231 · Dec 30, 2014 at 11:34 PM 0
Share

$$anonymous$$ake the shading flat?

avatar image
0

Answer by NeverEndingPrjct · Aug 25, 2014 at 06:23 PM

I saw an other problem ... if i use 100 segments at the x axis adn 100 at the z axis the performece goes down,everything is lagging and so on ... How can i solve this ?

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 Josh1231 · Aug 25, 2014 at 07:11 PM 0
Share

That's because the object is beco$$anonymous$$g too high poly, try reducing it to something like 20.

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

23 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

Related Questions

Distribute terrain in zones 3 Answers

How would you go about shaping terrain with scripting? (C#) 1 Answer

How to make a voxel terrain generate all around the start point 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Instantiating a object in a certain position.. 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