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
0
Question by BearShark1993 · Jan 12, 2015 at 02:47 AM · meshmeshfiltermesh verticesmesh-deformation

Splitting shared vertices in a plane

So this is my first time working with the mesh class in unity. I am trying to create a tile map so I can take a stab at procedural dungeon making. I have data structures made to create a blue print of a dungeon the challenge I am trying to tackle is drawing it.

My idea was to use a single procedural plane made up of many vertices to create sub planes this is shown in the code below. My hope was was to raise and lower these vertices to create walls and chasms. I wrote a little test to see how raising certain vertices affected the mesh the issue I am having is that there vertices shared between sub planes so instead a vertical cube rising out of it its forming more of a hill. as shown in the image.

I know I would have to increase the number of vertices but I was hoping for a nudge in the right direction of how to go about making sure there are no shared vertices .

 ![using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof (MeshFilter))]
 [RequireComponent(typeof (MeshRenderer))]
 [RequireComponent(typeof (MeshCollider))]
 public class TileMap : MonoBehaviour {
     //number of tiles in the x direction
     public int size_x = 7*35;
     //number of tiles in the z direction
     public int size_z = 7*35;
 
     //size of each tile
     public float tileSize = 10f;
     // Use this for initialization
     void Start () {
         buildMesh();
     }
 
     public void buildMesh(){
         //number of tiles total on the map
         int numTiles = size_x*size_z;
         //number of triangles is double the number of tiles needed as 2 triangles make one square on the map.
         int numTris = numTiles*2;
 
         //number of vertices in the x dirextion
         int vsize_x = size_x + 1;
         //number of vertices in the z direction
         int vsize_z = size_z + 1;
         // number of vertices total in the map needed to make the plane.
         int numVerts = vsize_x * vsize_z;
 
 
         //Create mesh data.
         //array of vector 3's to store vertex data
         Vector3[] vertices = new Vector3[numVerts];
         //array of vector 3's to store normal data
         Vector3[] normals = new Vector3[numVerts];
         //array of vector 2's to store uv data.
         Vector2[] uv = new Vector2[numVerts];
 
         int[] triangles = new int[numTris*3];
         //One nested for loop to set up the vertices normals, and uv
         int x,z;
         for(z=0; z < vsize_z; z++){
             for(x=0; x < vsize_x; x++){
                 vertices[z * vsize_x + x] = new Vector3(x*tileSize,0,z*tileSize);
                 normals [z * vsize_x + x] = Vector3.up;
                 uv[z * vsize_x + x] = new Vector2((float)x/size_x,(float)z/size_z);
 
             }
         }
         // a little test I wrote to see how elevating certain vetices affect the mesh.
         vertices[0] += new Vector3(0,10,0);
         vertices[1] += new Vector3(0,10,0);
         vertices[vsize_x] += new Vector3(0,10,0);
         vertices[vsize_x+1] += new Vector3(0,10,0);
         //end of test
 
         //one nested for loop to set up the triangle data for the mesh.
         for(z=0; z < size_z; z++){
             for(x=0; x < size_x; x++){
                 int squareIndex = z * size_x + x;
                 int triOffset = squareIndex*6;
 
                 triangles[triOffset +0] = z * vsize_x + x + 0;
                 triangles[triOffset +2] = z * vsize_x + x + vsize_x + 1;
                 triangles[triOffset +1] = z * vsize_x + x + vsize_x + 0;
 
                 triangles[triOffset +3] = z * vsize_x + x + 0; 
                 triangles[triOffset +5] = z * vsize_x + x + 1;
                 triangles[triOffset +4] = z * vsize_x + x + vsize_x + 1;
 
             }
         }
 
 
         //Create a new mesh
         Mesh mesh = new Mesh();
         //Populate mesh with data
         mesh.vertices = vertices;
         mesh.triangles = triangles;
         mesh.normals = normals;
         mesh.uv = uv;
         //Assign our mesh to our filter/renderer/collider.
         MeshFilter mesh_filter = GetComponent<MeshFilter>();
         MeshRenderer mesh_renderer = GetComponent<MeshRenderer>();
         MeshCollider mesh_collider = GetComponent<MeshCollider>();
 
         mesh_filter.mesh = mesh;
     }
 
 }][1]
 

 


[1]: /storage/temp/38604-question.png

question.png (77.6 kB)
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to manipulate(flatten) the Mesh of an object 0 Answers

Problem with setting vertices positions and smoothing groups. 1 Answer

Create runtime 3D mesh and Fill area like Paper.io 2 1 Answer

Get plain coordinates for another object 2 Answers

Accessing mesh vertices is extremely inefficient; any workarounds? 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