How to get correct vertex normals

I need to get the vertex normals in a script but all of the normals look like they are pointing from the object’s origin. What am I missing?

   var mesh : Mesh = GetComponent.<MeshFilter>().mesh;
   var vertices : Vector3[] = mesh.vertices;

   for (var i = 0; i < vertices.Length;i++)
   {
     var vertPosition: Vector3 = transform.TransformPoint(vertices[i]);
     var vertNormal: Vector3 = transform.TransformDirection(vertices[i]);

     Debug.DrawRay (vertPosition, vertNormal, Color.green);
   }

Thanks!

I guess transform.TransformDirection in this case is just taking your objects transform and getting the direction from that transform position to your vertex position.

What you might want is mesh.Normals

That works, thanks!

1 Like