• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

75 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

Related Questions

Procedural mesh artifacts. 1 Answer

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

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges