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
2
Question by Lambastard · May 09, 2015 at 11:48 PM · mesh3dproceduralprocedural meshtriangles

Determining where a mesh triangle faces

I'm making procedural meshes from random data, which works pretty well apart from some of the triangle faces being the wrong way around. I can obviously invert the order in which they reference their vertices, but so far I have found no working way of determining whether this is necessary for a given triangle.

As others have found out a while ago, the facing of a triangle depends on whether its vertices are named in a clockwise or anticlockwise order. But if I'm working with a bunch of points in 3D space that will, at some points, result in a continuous mesh, then how can I determine that?

How is their being or not being clockwise even decided? I can't even imagine what the mathematics behind it look like, or what kind of coordinate system is used.

Thanks for any help on the issue.

Comment
Add comment · Show 6
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 AlwaysSunny · May 09, 2015 at 11:48 PM 1
Share

Depending on the nature of the meshes, this might be easy.

A terrain or similar surface requires obvious "up" facing tris.

Certain simple shapes can deter$$anonymous$$e their "out" facing tris by comparing the position of their verts against some simple rule (e.g. a sphere knows all tris face away from the origin).

I have not personally encountered a need for solving face orientation, but certainly some established algorithm exists - take Blender for instance. It can deter$$anonymous$$e the intended face orientation with a fantastic success ratio. It's also open-source if your needs are that dire...

I'd be curious to learn how such a system achieves success, but I don't envy your task of constructing or integrating a solution.

avatar image Eric5h5 · May 10, 2015 at 01:57 AM 0
Share

By definition, the order of the vertices in a triangle is clockwise; that's not something that needs to be decided. I think what you mean is that you want to know if the surface normal of the triangle is pointing the way you want.

avatar image AlwaysSunny · May 10, 2015 at 03:09 AM 1
Share

I read the OP's issue as being unable to deter$$anonymous$$e which of the two given normals should be selected on a face-by-face basis to achieve consistency throughout a complex mesh. The question is pretty nonspecific about the nature of the meshes they're creating.

@Lambastard, if it's just a hull you're after, the best normal of the two would be the one best described as pointing away from the hull's origin, which could serve as your test criteria. Any more complex shapes and I'm fairly clueless.

avatar image Bunny83 · May 10, 2015 at 03:34 AM 2
Share

Well, even most non convex shapes usually have more out facing "surface" area than faces that are pointed against each other. At least if the triangle density is roughly equally distributed.

If you have no clue which side is which, you could raycast from the triangles center along both surface normals against all other triangles. The side which doesn't hit something is most likely "outside". Now for non convex shapes it's possible that a triangle is covered on both sides with other triangles. The direction of those could be deter$$anonymous$$ed by "walking" the surface starting with a triangle which is known to face outwards. Each triangle has 3 neighbor triangles so you can jump from triangle to triangle and carry the ouside information with you. The two edges of two triangles always go in the oposite direction if both triangles are connected and represent the same "side".

This of course only works reliably with closed shapes which form a volume without self intersecting triangles. That's also the reason why a lot physics systems prefer or require closed shapes or even convex shapes. Unity is actually quite tolerant when it comes to generating colliders from mesh data.

avatar image AlwaysSunny · May 10, 2015 at 03:39 AM 0
Share

How perfectly sensible. Thanks for elaborating on this! I feel edified. :)

Show more comments

1 Reply

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

Answer by Eric5h5 · May 10, 2015 at 01:55 AM

You can determine the surface normal of a triangle by using the three vertices in a cross product. In this case i is the index of the first vertex in the triangle:

 var surfaceNormal = Vector3.Cross (vertices[i+1]-vertices[i], vertices[i+2]-vertices[i]);

So if the surface normal is pointing the wrong way, invert the triangle order.

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 Lambastard · May 10, 2015 at 07:39 AM 0
Share

Thanks for the tip, I'll try to solve the issue this way.

Edit: Yep, worked. Don't know whether it'll suffice for the more complex affairs, but for now it's a good solution. 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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Triangulating a 2D polygon with only hull vertices. 1 Answer

Procedural mesh creation issue 1 Answer

What is wrong with this mesh editing code? 0 Answers

How can I implement "3D voxel digging"? 2 Answers

Editor lags when coming out of play mode...? 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