Last active
November 12, 2017 05:27
-
-
Save knasa21/68392cb38036ee8fe39366875eb8e9ed to your computer and use it in GitHub Desktop.
メッシュの頂点インデックス可視化
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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