Skip to content

Instantly share code, notes, and snippets.

@knasa21
Last active November 12, 2017 05:27
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 knasa21/68392cb38036ee8fe39366875eb8e9ed to your computer and use it in GitHub Desktop.
Save knasa21/68392cb38036ee8fe39366875eb8e9ed to your computer and use it in GitHub Desktop.
メッシュの頂点インデックス可視化
using UnityEngine;
[ExecuteInEditMode]
public class ShowMeshIndex : MonoBehaviour
{
[Range(0.0f, 10.0f)]
public float vertexSize = 1;
public Color vertexColor;
[Range(0, 50)]
public int fontSize = 10;
MeshFilter meshFilter;
void Start()
{
meshFilter = GetComponent<MeshFilter>();
Mesh mesh = Mesh.Instantiate(meshFilter.sharedMesh);
meshFilter.mesh = mesh;
int[] triangles = mesh.triangles;
int length = triangles.Length;
for (int i = 0; i < length; i+=3) {
print(i/3 + ":" + triangles[i] + "," + triangles[i+1] + "," + triangles[i+2]);
}
print("uv");
Vector2[] uv = mesh.uv;
length = uv.Length;
for(int i = 0; i < length; i++) {
print(i + ":" + uv[i]);
}
}
void Update()
{
}
#if UNITY_EDITOR
private void OnDrawGizmos()
{
GUIStyle style = new GUIStyle();
Matrix4x4 matrix = meshFilter.transform.localToWorldMatrix;
Mesh mesh = meshFilter.sharedMesh;
meshFilter.mesh = mesh;
Vector3[] vertices = mesh.vertices;
style.fontSize = fontSize;
Gizmos.color = vertexColor;
int length = vertices.Length;
for (int i = 0; i < length; i++) {
Vector3 position = matrix.MultiplyPoint(vertices[i]);
Gizmos.DrawSphere(position, vertexSize);
UnityEditor.Handles.Label(position, i.ToString(), style);
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment