It's meant to be simple and easy to use, and therefore it has been made as a custom editor of MeshFilter. It needs no preparations.
Drop the file in an Editor folder.
using UnityEditor; | |
using UnityEngine; | |
[CustomEditor(typeof(MeshFilter))] | |
public class NormalsVisualizer : Editor { | |
private Mesh mesh; | |
void OnEnable() { | |
MeshFilter mf = target as MeshFilter; | |
if (mf != null) { | |
mesh = mf.sharedMesh; | |
} | |
} | |
void OnSceneGUI() { | |
if (mesh == null) { | |
return; | |
} | |
for (int i = 0; i < mesh.vertexCount; i++) { | |
Handles.matrix = (target as MeshFilter).transform.localToWorldMatrix; | |
Handles.color = Color.yellow; | |
Handles.DrawLine( | |
mesh.vertices[i], | |
mesh.vertices[i] + mesh.normals[i]); | |
} | |
} | |
} |