Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RecalculateNormals() on Edges & Averaging Normals

Discussion in 'Scripting' started by razzraziel, Apr 18, 2019.

  1. razzraziel

    razzraziel

    Joined:
    Sep 13, 2018
    Posts:
    395
    Hi!

    Ok i spend all day researching and figuring out to code for this but still have same issue. Because i guess i dont know how those normals are calculated.

    I have this usual issue on edges after plane mesh construction and RecalculateNormals()



    Lets say our planes are 7x7 vertices big, so these are the vertex & normal indexes of them.



    I tried to get avarages on edge vertices with different methods but no luck. For blue planes' edges, which neighbours' normals do i need to sum? Or am i doing it completely wrong?

    These planes are getting position of their vertices from terrain like this.
    Code (CSharp):
    1. vertices[i] = matrx.inverse.MultiplyPoint(hit.point + hit.normal * 0.1f);
    2. normals[i] = hit.normal;
    Vertices are good but this code also returns wrong normals, so thats why i call RecalculateNormals().
     
    Last edited: Apr 18, 2019
    unity_ZF434Vod7AO8Gw likes this.
  2. razzraziel

    razzraziel

    Joined:
    Sep 13, 2018
    Posts:
    395
    Oh damn! I figured it out now. It was because of a stupid mistake.

    I also instantiating these planes AT THE SAME TIME. So its interpolating their edge vertices before the neighbour plane instantiated. So calculation was wrong because missing plane normals return (0,1,0) all the time.

    Anyways, thanks for reading.