Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
Last active May 25, 2020 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuqunaga/98191826d0c1e4236f35cbee4a57fa8a to your computer and use it in GitHub Desktop.
Save fuqunaga/98191826d0c1e4236f35cbee4a57fa8a to your computer and use it in GitHub Desktop.
Visualize normals of Skinned Mesh Renderer in Unity3D
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(SkinnedMeshRenderer))]
public class SkinNormalsVisualizer : Editor
{
private Mesh mesh;
void OnEnable()
{
var smr = target as SkinnedMeshRenderer;
if (smr != null)
{
mesh = smr.sharedMesh;
}
}
void OnSceneGUI()
{
if (mesh == null)
{
return;
}
var vertices = mesh.vertices;
var normals = mesh.normals;
Handles.zTest = UnityEngine.Rendering.CompareFunction.Less;
Handles.matrix = (target as SkinnedMeshRenderer).transform.localToWorldMatrix;
Handles.color = Color.yellow;
for (int i = 0; i < mesh.vertexCount; i++)
{
Handles.DrawLine(
vertices[i],
vertices[i] + normals[i] * 0.02f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment