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
0
Question by willbrindle · Aug 05, 2017 at 07:40 PM · meshnormalsprocedural mesh

Custom Mesh Normals Problem

I am creating a very simple mesh procedurally but I am having problems with setting the normals so I feel like I am miss understanding something. At the moment I am simply making a plane:

 List<Vector3> vertices = new List<Vector3> {
             new Vector3(-width/2,0,-length/2),new Vector3(width/2,0,-length/2),new Vector3(-width/2,0,length/2),new Vector3(width/2,0,length/2)
         };
 
         List<Vector2> UV_MaterialDisplay = new List<Vector2> {
             new Vector2 (0.1f, 0.1f),
             new Vector2 (0.9f, 0.1f),
             new Vector2 (0.1f, 0.9f),
             new Vector2 (0.9f, 0.9f)
         };

 
 triangles.AddRange(new int[]{0, 3, 1});
 triangles.AddRange(new int[]{0, 2, 3});

  List<Vector3> normals = new List<Vector3>();
     for (int i = 0; i < vertices.Count; i++) {
         normals.Add(new Vector3 (0.0f, -1.0f, 0.0f));
     }

 Mesh mesh = new Mesh ();
     transform.GetComponent<MeshFilter> ();

     if(!transform.GetComponent<MeshFilter> () ||  !transform.GetComponent<MeshRenderer> () ) //If you havent got any meshrenderer or filter
     {
         transform.gameObject.AddComponent<MeshFilter>();
         transform.gameObject.AddComponent<MeshRenderer>();
     }

     GetComponent<MeshFilter> ().mesh = mesh;

     mesh.name = "Thing";

     mesh.vertices = vertices.ToArray();
     mesh.SetNormals (normals);

     mesh.triangles = triangles.ToArray();
     mesh.uv = UV_MaterialDisplay.ToArray();

This is correct and draws how I want it to draw except for I can only ever see it from 'above', when i want to see it from below instead, despite having set the normal to be -1.0f for all vertices. I get the same regardless of whether I set it to be -1.0f or 1.0f.

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

Answer by FlaSh-G · Aug 06, 2017 at 12:39 AM

There's two things called "normal" here. One is the information about which side of the face is "front", influencing which side backface culling is culling. The other is the vector that fakes the normal direction of a vertex for light calculation. That's the vector that, for example, makes the difference between these two spheres: Flat shaded and smooth shaded spheres

You are setting the latter value, while it's the first thing you are looking for.

To change a face's normal, you have to change the order of vertices forming the face in the triangles array. Clockwise means front face, counterclockwise means backface: Vertex order

Comment
Add comment · 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

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

74 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

Related Questions

How do I combine normals on procedural mesh with multiple tiles? 2 Answers

Procedural mesh's normals are reversed (Solved) 2 Answers

Are normals from Mesh.RecalculateNormals() normalized? 1 Answer

Holes in procedural mesh 0 Answers

Unity Mesh Rendering Issue 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