Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show mesh vertices and normals in sceneview [Unity3D]
// author: Stijn Raaijmakers (@bugshake)
// date: 11 sep 2016
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
/// <summary>Add this component to any GameObject with a MeshFilter, then select it in the editor</summary>
public class MeshInspector : MonoBehaviour
{
#if UNITY_EDITOR
void OnDrawGizmosSelected()
{
Mesh mesh = GetComponent<MeshFilter>().sharedMesh;
if (mesh != null)
{
var verts = mesh.vertices;
var norms = mesh.normals;
for (int i = 0; i < verts.Length && i < norms.Length; ++i)
{
Vector3 p1 = transform.TransformPoint(verts[i]);
Vector3 p2 = transform.TransformPoint(verts[i] + norms[i]);
Gizmos.color = Color.blue;
Gizmos.DrawSphere(p1, .1f);
Gizmos.color = Color.yellow;
Gizmos.DrawLine(p1, p2);
Handles.Label(p1, i.ToString());
}
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment