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
0
Question by Cinkokoko · May 09, 2012 at 08:58 PM · meshnormalsurfacetriangle

Mesh triagnles/surface with normals

Hello,

I'm trying to get every triangle or surface of a mesh, and it's normal.

I'm using:

 Mesh m = go.GetComponent<MeshFilter>();

And then I know that I can use m.triangles to get the complete list of triangles. I know that there are 3 times less triangles than length of m.triangles, and I know why.

But then I need normals for this triangles. Is there any way to use m.normals then to get normal for each triangle correctly? And why for example m.normals length of simple Cube from Unity is 24?

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
2

Answer by ScroodgeM · Jul 20, 2012 at 09:53 AM

m.vertices contains info about each vertex in mesh

m.triangles contains just indexes of vertices, 3 vertices for each triangles

m.normals contains (or contains no if no normals in mesh) normals for each vertex, that's why m.normals.Length == m.vertices.Length

to get normals for triangle you just need first ti get 3 indexes of vertices in trinagle, and then based on that indexes get 3 normals from n.normals

if triangle is { 0, 1, 3 } then vertices of this triangle is { m.vertices[0], m.vertices[1], m.vertices[3] } and normals is { m.normals[0], m.normals[1], m.normals[3] }

cube have 24 normals cause it have 24 vertices. not 8 vertices as it looks like.

cube needs a sharp edges so in one vertex on the corner it have 3 different normals for each side. that's why for each visual vertex (8 vertices total) cube has 3 vertices in same position with 3 different normals

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 AlucardJay · Jul 20, 2012 at 10:07 AM 0
Share

that's a helpful explanation on why the native cube has 24 verts =]

I found this after running a native cube through my mesh-reader after trying to see if I could find the collider verts. $$anonymous$$aybe you could help? (not my question, but am curious and have given a mesh-reader script, but not sure how to read the collider)

http://answers.unity3d.com/questions/287081/box-collider-vertexes-in-world-space.html

avatar image ScroodgeM · Jul 20, 2012 at 10:31 AM 0
Share

i'd answer there

avatar image AlucardJay · Jul 20, 2012 at 10:47 AM 0
Share

Thanks for that. I really was grateful just for the above answer. It actually makes sense when explained why there were 24 verts, regarding normals and tangents.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird triangle indexing problem 1 Answer

Change color of mesh triangle based on Y position in world space 1 Answer

Detect a flat surface on a complex mesh? 1 Answer

Trouble recalculating 3D mesh's triangles after deleting verts 2 Answers

Normal of the edge between two triangles 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