Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Mesh Recalculate Normals giving slightly wrong normals

Discussion in 'Scripting' started by TheGameNewBie, Aug 2, 2020.

  1. TheGameNewBie

    TheGameNewBie

    Joined:
    Jul 27, 2017
    Posts:
    70
    I have this mesh, which is procedurally generated and I'm calling Recalculate Normals() on it. But the normals aren't being calculated how they are supposed to be.

    Aren't they supposed to be straight, pointing upwards? Perpendicular to the faces? Normals.PNG
    The mesh in question is spherical mesh, so I think it just calculates the normals based on the direction from the center and not actually on from the geometry of the mesh.
    I want to generate grass on the surface, and I'm using the normal of the vertices to set the rotation of the grass, but as you can guess, the grass is also pointing obliquely.
    Any help?
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    941
    The mesh normals are per vertex and aren't face normals which is what it looks like you're trying to do? Also, you need to transform the normal by the mesh transform to get the correct orientation. You could try this code here to render them as debug rays to check that it's working correctly: https://answers.unity.com/questions/601547/is-verticesnormals-face-or-vertex-normals.html

    How are you selecting the normals for adding your grass objects? Are you raycasting onto the mesh? It looks a bit like it's using a raycast direction rather than the collision normal.
     
unityunity