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
2
Question by kkrac · Nov 15, 2017 at 04:34 PM · meshtriangles

clarification about mesh triangles - vertices order

Hi,

I've looked up for this over and over again, and wasn't able to find a post that explains it clearly enough for me.

I understand that for a triangle face to be visible, the order of the vertices has to be in clockwise order. What I'm not understanding is how does Unity interpret whether you're specifying the triangles in a clockwise or counter-clockwise order.

Let's say I have this code:

void Awake () {

 Mesh myMesh = gameObject.GetComponent<MeshFilter>().mesh;

 myMesh.Clear();

 myMesh.vertices = new Vector3[] { new Vector3(-1,0,1), new Vector3(-1,0,-1), new Vector3(1,0,-1), new Vector3(1,0,1) };

 myMesh.normals = new Vector3[] { Vector3.up,Vector3.up,Vector3.up,Vector3.up};

 myMesh.triangles = new int[] {0,1,2,0,2,3};

 myMesh.RecalculateNormals();

 myMesh.RecalculateBounds();


}

How does Unity know that the triangles vertices are in a CW or a CCW order?

I mean, when I just say: myMesh.triangles = new int[] {0,1,2,0,2,3}; I am specifying a certain order, but relative to what? What is my starting point? Where am I saying 1 is to the right or to the left of 0? And how does it know which vertex each number corresponds to?

I would get different results for the two images below, wouldn't I? For the first image, both triangles would be visible, for the second, both would be invisible.

But again, how is the order established?

alt text

alt text

ccw.png (1.2 kB)
cw.png (1.3 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

1 Reply

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

Answer by MarshallN · Nov 15, 2017 at 05:18 PM

The order that the vertices is in is the order in which they're listed in the myMesh.vertices array. You're setting the vertices in the order 'Upper-left, lower-left, lower-right, upper-right',

 0                3
 
 
 1                2

which means that both triangles will be invisible from above and visible from below. The clockwise/counterclockwise visibility is dependent on which side it's viewed from, so you could flip it and make it visible from above either by flipping the order of the vertices or the order of the triangle indices (e.g., having the triangle array be {0,2,1,0,3,2} with the current vertex order, or having the vertex order be flipped such that the current triangle array makes them clockwise from above.

 3                0
 
 
 2                1

So long story short, Unity doesn't know whether you're listing the triangles in clockwise/ccw order, that's for you to figure out based on the order of the vertices and where you're viewing from.

Comment
Add comment · Show 3 · 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 kkrac · Nov 15, 2017 at 05:51 PM 0
Share

Thanks for clarifying "that the order that the vertices is in is the order in which they're listed in the my$$anonymous$$esh.vertices array". Didn't know that.

Very clear your explanation.

The only part I am confused about is when you said: "(...) which means that both triangles will be invisible from above and visible from below (...) "

With the vertices configuration: 'Upper-left, lower-left, lower-right, upper-right' aren't both triangles invisible from above AND from below with {0,1,2,0,2,3} ?

From above (both triangles CCW => invisible)

  0                3
  
  
  1                2

From below (both triangles CCW => invisible)

  1                2
  
  
  0                3


Thanks.

avatar image MarshallN kkrac · Nov 15, 2017 at 05:59 PM 0
Share

Alright, so if the Camera in the scene is looking down at the mesh that the code you posted made, the triangles won't be visible, because the triangles are counter-clockwise when viewed from above. However, if you put the camera underneath the mesh and look up, the triangles will be visible, because from underneath the triangles are clockwise. Flipping which side of the triangle you're viewing it from changes whether it's clockwise or counter-clockwise.

When you assign a triangle array to vertices, the triangle will always be visible on one side and invisible on the other.

From above (both triangles CCW => invisible)

   0                3
   
   
   1                2

From below (both triangles clockwise => visible)

   1                2
   
   
   0                3

because in this case, {0,1,2} and {0,2,3} are both clockwise.

avatar image kkrac MarshallN · Nov 15, 2017 at 06:08 PM 0
Share

D'oh! You're right, my bad.

Thanks!

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

80 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

Related Questions

contains two different ids for the same vertex 0 Answers

Object odd light problem with mesh? 1 Answer

How to find the center of quad polygons in a mesh 1 Answer

Problem drawing a mesh with Graphics.DrawMeshNow 1 Answer

Having trouble implementing edge collapse operation with half-edge data structure 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