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
0
Question by Huxii · Sep 20, 2021 at 08:07 PM · meshnormalsmesh vertices

How to identify mesh faces

Hello,

I try to create a script to perform an analysis of every face of a mesh. I've read the documentation and as I understood, there is no definition of a face, "just" triangles or vertices. So in order to identify faces I guess first I need to identify the vertices, then their normals and then compare the vertices to each other in order to find out which are neighbors. Vertices with the same normal and neighboring vertices would then form one face. Right?

At the moment I am struggling in finding out the normals of the vertices. I printed out all vertices and normals (of a simple cube), but they seam not to match together - the vertices Index 3,4,5 (they form one triangle) doesn't share the same normal.

alt text
Am I interpreting this correctly? The documentation is not always easy to read for me.

Is there maybe an easier way to identify faces?

Thank you
Huxi

verticesnormals.png (51.2 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
0

Answer by bdubbert · Sep 20, 2021 at 08:38 PM

Mesh.triangles has all your mesh faces for you

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 bdubbert · Sep 20, 2021 at 08:39 PM 0
Share

Each successive 3 integers in the triangles array are the 3 vertices of a mesh face. The int values in the triangles array are the index of the corresponding vertex in the vertices array.

avatar image
0

Answer by Huxii · Sep 20, 2021 at 08:40 PM

Hello @bdubbert , and how do you know which triangles form one face?

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 bdubbert · Sep 20, 2021 at 08:57 PM 0
Share

Ah you are looking for entire faces, which may be a combo of 1 or more triangle. Yeah that is a bit trickier. Will not be an easy answer.


Looking at the vertex normals doesn't seem like the way to go for me, because the vertex normals are not necessarily the same as the normals of the triangles that they form, and you care about the normals of the triangles when trying to find faces. If you have triangles A and B and you want to know if they are part of the same face, then


  1. All of the vertices in B should lie in the plane defined by the 3 vertices of A

  2. A and B should share at least one vertex **

So I would start by separating out all of your triangles and then start comparing the vertices from there.

avatar image Huxii bdubbert · Sep 20, 2021 at 09:07 PM 0
Share

The idea of having a look if they lie on the same plane also crossed my $$anonymous$$d, but also didn't know how to find this out.

avatar image bdubbert Huxii · Sep 20, 2021 at 09:21 PM 0
Share

You can construct a Plane using the 3 vertices of the first triangle.

I'm sure there is a better way to check whether a point is on a plane or not, but you could always feed a point into ClosestPointOnPlane and check if it just gives you back your point.

     Plane myPlane = new Plane(a, b, c);
     bool isOnPlane = myPlane.ClosestPointOnPlane(d) == d;


Not sure how this function works, so you may have to allow for a little bit of variation just because checking if floats are equal is usually a bad idea. Usually you just want to check that your floats are close enough to equal.

 bool isOnPlane = Mathf.Approximately(myPlane.ClosestPointOnPlane(d), d);

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

142 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 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

How to cut a desired shape out of a mesh or a 2D sprite? 0 Answers

Alternative to Mesh.RecalculateNormals 0 Answers

Unity generated mesh average normals on seperate vertices on same position/ smooth shade generated mesh 1 Answer

Creating a mesh out of a linerenderer - how do you convert revolved vertices set to triangles and uv's 1 Answer

How is a polygon determined to be front facing or back facing? 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