Skip to content

Instantly share code, notes, and snippets.

@bugshake
Created September 11, 2016 14:40
Show Gist options
  • Save bugshake/6fed01fc457e5943f7574883c6e034b9 to your computer and use it in GitHub Desktop.
Save bugshake/6fed01fc457e5943f7574883c6e034b9 to your computer and use it in GitHub Desktop.
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