Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Visualize mesh normals in Unity3D

Visualize the normals of a mesh

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.

How to use

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]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.