Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 tapticc · Jan 03, 2017 at 10:48 PM · meshvector3verticesnormals

How to calculate normal direction for shared vertex position

Hi all, I've tried searching for the answer and this is as close as I can get to the answer but can't figure this one out. Please see the screenshot below:

The debug lines are the vertex normals in the direction the normal points. Where there are more than one line coming out of a single point, this is where more than one of the triangle vertices share a Vector3 position. So in the example screenshot, there are 6 triangles that share the central vertex position but each have different normals, and I need to figure out how to calculate a single normal direction.

This is so you can calculate an extruded position for the vector for further information.

I am using https://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html as my starting point, here is some code in brief:

         var side1 = SelectedTriangles[j].P1 - SelectedTriangles[j].P0;
         var side2 = SelectedTriangles[j].P2 - SelectedTriangles[j].P0;
         var perp = Vector3.Cross(side1, side2);
         Debug.DrawLine(SelectedTriangles[j].P0, SelectedTriangles[j].P0 + (perp * 50), Color.yellow, 10, false);

         var side3 = SelectedTriangles[j].P0 - SelectedTriangles[j].P1;
         var side4 = SelectedTriangles[j].P2 - SelectedTriangles[j].P1;
         var perp2 = Vector3.Cross(side3, side4);
         Debug.DrawLine(SelectedTriangles[j].P1, SelectedTriangles[j].P1 + (perp2 * 50), Color.yellow, 10, false);

         var side5 = SelectedTriangles[j].P0 - SelectedTriangles[j].P2;
         var side6 = SelectedTriangles[j].P1 - SelectedTriangles[j].P2;
         var perp3 = Vector3.Cross(side5, side6);
         Debug.DrawLine(SelectedTriangles[j].P2, SelectedTriangles[j].P2 + (perp3 * 50), Color.yellow, 10, false);

The P0 / P1 / P2 refer to position for each vertex that makes up a triangle. Any ideas please?

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
1
Best Answer

Answer by Bunny83 · Jan 03, 2017 at 11:59 PM

Well, first of all you should normalize each normal vector of each triangle. Then just take the arithmetic mean of them. That is, add up all normals and divide by the number of vectors. So in case of 7 normals it would be something like

 nAvr = (n0 + n1 + n2 + n3 + n4 + n5 + n6) / 7;

This will give you the average of all normals. However the resulting vector won't be a normalized vector, so you need to normalize the result again. Since normalizing will adjust the length of the vector to be 1.0f you could omit the division by the number of vectors. So this would be enough:

 nAvr = (n0 + n1 + n2 + n3 + n4 + n5 + n6).normalized;

However keep in mind if you actually use a shared vertex that the shading at that point will be equal for all triangles that use that vertex and you get a smooth transition to the other vertices.

Comment
Add comment · Show 2 · 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 tapticc · Jan 04, 2017 at 06:51 AM 0
Share

Thanks for this @Bunny83, will give it a try after work. So as long as I get all of the vertex normals that are in the same location, sum them then normalize the sum, I can use this single value for the extrusion normal value I should be ok?

avatar image tapticc · Jan 04, 2017 at 07:59 PM 0
Share

Thanks for your help, I now have calculated normals that go in the same direction when multiple vertices share the same position:

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

72 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

Related Questions

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

Why does the default Unity sphere have duplicate vertices? 1 Answer

Unity is welding vertices when I enter Play mode 0 Answers

Assigning new Mesh Vertices 2 Answers

Why the cube in unity has more than 8 vertices even without normals? 2 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