Normal Gizmo

Does anyone have any script to show mesh normals using Gizmo.DrawLine or Debug.DrawLine?

I’m sure I’ve found this before on the forum/Wiki but I’ve been searching on and off all day and can’t find a thing.

This was posted almost 9 years ago, but still encase sombody googles it like I did, heres the solution

var vert = _mesh.vertices[i];
var normal = _mesh.normals[i];
Gizmos.DrawSphere(vert, 0.1f);
Gizmos.DrawLine(vert, vert + normal);

3 Likes

Here is a complete script that you can add to a gameobject with a meshfilter / meshrenderer.

using UnityEngine;

public class MeshNormalsGizmo : MonoBehaviour
{
    private Mesh _mesh = null;

    void Start()
    {
        MeshFilter filter = GetComponent<MeshFilter>();
       
        if (filter != null)
        {
            _mesh = filter.sharedMesh;
        }
    }

    private void OnDrawGizmos()
    {
        if (_mesh == null)
        {
            return;
        }

        for (int count = 0; count < _mesh.vertexCount; count++)
        {
            var vert = transform.TransformPoint(_mesh.vertices[count]);
            var normal = transform.TransformDirection(_mesh.normals[count]);
            Gizmos.color = Color.green;
            Gizmos.DrawSphere(vert, 0.05f);
            Gizmos.color = Color.blue;
            Gizmos.DrawLine(vert, vert + normal);
        }
    }
}
2 Likes