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
1
Question by Ellpower · Oct 11, 2013 at 02:34 PM · meshplaneverticestriangles

Plane: vertices and triangles

I want to create a plane with n x 1 quads (ex: 10 x 1 quads). I'm able to do so but half of the triangles are showing on one side and the other half on the other side.

First side:

alt text

Other side:

alt text

How can i make it so all triangles are showing on the same side?

Here is the code i drop on the plane showed above:

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
     
     public int rectanglesCount = 200;
     
     private Vector3[] _vertices;
     private int[] _triangles;
     
     private Mesh _mesh;
     private Vector3 _size;
     
     void Start ()
     {
         _vertices = new Vector3[(rectanglesCount * 2) + 2];
         _triangles = new int[(rectanglesCount * 6)];
         
         _mesh = ((MeshFilter) GetComponent(typeof(MeshFilter))).mesh;
         _size = collider.bounds.size;
         
         InitiateRectangles();
     }
     
     private void InitiateRectangles()
     {
         _mesh.Clear();
         
         // vertices
         
         /* 
            order
            0 --- 2
            |     |
            |     |
            |     |
            1 --- 3
         */
         
         float xSpace = _size.x / rectanglesCount;
         float x = 0;
         bool top = true;
         
         x -= _size.y / 2;
         
         for(int i = 0; i < _vertices.Length; i++)
         {
             _vertices[i].x = x;
             _vertices[i].z = 0.01f;
             
             if (top)
                 _vertices[i].z = _size.y / 2;
             else
             {
                 _vertices[i].z = - _size.y / 2;
                 
                 x += xSpace;
             }
                 
             top = !top;
         }
         
         top = false;
         
         // triangles
         
         /*
          triangles[0] = 0;
         _triangles[1] = 1;
         _triangles[2] = 2;
         
         _triangles[3] = 1;
         _triangles[4] = 2;
         _triangles[5] = 3;
         
         _triangles[6] = 2;
         _triangles[7] = 3;
         _triangles[8] = 4;
         */
         
         int index = 0;
         
         for(int i = 0; i < (_triangles.Length / 3); i ++)
         {
             index = i * 3;
             
             _triangles[index] = i;
             _triangles[index + 1] = i + 1;
             _triangles[index + 2] = i + 2;
         }
         
         _mesh.vertices = _vertices;
         _mesh.triangles = _triangles;
         
         _mesh.RecalculateNormals();
         _mesh.RecalculateBounds();
     }
 }
 

capture.png (31.3 kB)
capture2.png (40.7 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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Graham-Dunnett · Oct 11, 2013 at 02:50 PM

The order of the vertices in the _triangle array needs to be consistent. Either they all need to be clockwise or they all need to be anti-clockwise. So, use 012 and 132. (Also, I don't understand why you have 9 indices in your comment.)

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
avatar image
1

Answer by DaveA · Oct 11, 2013 at 02:52 PM

Your triangle 'winding' is wrong for half the faces. Either change your vertex order to be continuously clockwise or counterclockwise (currently cuts through the center), or change your triangle indices to make sure they are always going clockwise or counterclockwise

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

17 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

Related Questions

Mesh extrusion overlapping triangles problem 0 Answers

Problem drawing a mesh with Graphics.DrawMeshNow 1 Answer

Ways of modificating mesh triangles 3 Answers

Easy way to convert a bunch of vertices to triangles or uv's? 1 Answer

Holes in procedural mesh 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