Skip to content

Instantly share code, notes, and snippets.

@pazzaar
Created September 4, 2021 09:19
Show Gist options
  • Save pazzaar/17ab22412c7045fba2e002405d6d6cdd to your computer and use it in GitHub Desktop.
Save pazzaar/17ab22412c7045fba2e002405d6d6cdd to your computer and use it in GitHub Desktop.
Unity mesh info including LOD levels
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MeshInfo : EditorWindow
{
bool showLOD1info = false;
bool showLOD2info = false;
bool showLOD3info = false;
bool showLOD4info = false;
private int vertexCount;
private int submeshCount;
private int triangleCount;
private int LOD1vertexCount;
private int LOD1submeshCount;
private int LOD1triangleCount;
private int LOD2vertexCount;
private int LOD2submeshCount;
private int LOD2triangleCount;
private int LOD3vertexCount;
private int LOD3submeshCount;
private int LOD3triangleCount;
private int LOD4vertexCount;
private int LOD4submeshCount;
private int LOD4triangleCount;
[MenuItem("Tools/Mesh Info")]
static void Init()
{
// Get existing open window or if none, make a new one:
MeshInfo window = (MeshInfo)EditorWindow.GetWindow(typeof(MeshInfo));
window.titleContent.text = "Mesh Info";
}
void OnSelectionChange()
{
Repaint();
}
void OnGUI()
{
vertexCount = 0;
triangleCount = 0;
submeshCount = 0;
LOD1vertexCount = 0;
LOD1triangleCount = 0;
LOD1submeshCount = 0;
LOD2vertexCount = 0;
LOD2triangleCount = 0;
LOD2submeshCount = 0;
LOD3vertexCount = 0;
LOD3triangleCount = 0;
LOD3submeshCount = 0;
LOD4vertexCount = 0;
LOD4triangleCount = 0;
LOD4submeshCount = 0;
foreach (GameObject g in Selection.gameObjects)
{
foreach(var child in g.GetComponentsInChildren<MeshFilter>())
{
if (child.name.Contains("LOD1"))
{
LOD1vertexCount += child.sharedMesh.vertexCount;
LOD1triangleCount += child.sharedMesh.triangles.Length / 3;
LOD1submeshCount += child.sharedMesh.subMeshCount;
}
else if (child.name.Contains("LOD2"))
{
LOD2vertexCount += child.sharedMesh.vertexCount;
LOD2triangleCount += child.sharedMesh.triangles.Length / 3;
LOD2submeshCount += child.sharedMesh.subMeshCount;
}
else if (child.name.Contains("LOD3"))
{
LOD3vertexCount += child.sharedMesh.vertexCount;
LOD3triangleCount += child.sharedMesh.triangles.Length / 3;
LOD3submeshCount += child.sharedMesh.subMeshCount;
}
else if (child.name.Contains("LOD4"))
{
LOD4vertexCount += child.sharedMesh.vertexCount;
LOD4triangleCount += child.sharedMesh.triangles.Length / 3;
LOD4submeshCount += child.sharedMesh.subMeshCount;
}
else
{
vertexCount += child.sharedMesh.vertexCount;
triangleCount += child.sharedMesh.triangles.Length / 3;
submeshCount += child.sharedMesh.subMeshCount;
}
}
}
EditorGUILayout.LabelField("Vertices: ", vertexCount.ToString());
EditorGUILayout.LabelField("Triangles: ", triangleCount.ToString());
EditorGUILayout.LabelField("SubMeshes: ", submeshCount.ToString());
showLOD1info = EditorGUILayout.Foldout(showLOD1info, "LOD1 mesh information");
if(showLOD1info)
{
EditorGUILayout.LabelField("LOD1_Vertices: ", LOD1vertexCount.ToString());
EditorGUILayout.LabelField("LOD1_Triangles: ", LOD1triangleCount.ToString());
EditorGUILayout.LabelField("LOD1_SubMeshes: ", LOD1submeshCount.ToString());
}
showLOD2info = EditorGUILayout.Foldout(showLOD2info, "LOD2 mesh information");
if (showLOD2info)
{
EditorGUILayout.LabelField("LOD2_Vertices: ", LOD2vertexCount.ToString());
EditorGUILayout.LabelField("LOD2_Triangles: ", LOD2triangleCount.ToString());
EditorGUILayout.LabelField("LOD2_SubMeshes: ", LOD2submeshCount.ToString());
}
showLOD3info = EditorGUILayout.Foldout(showLOD3info, "LOD3 mesh information");
if (showLOD3info)
{
EditorGUILayout.LabelField("LOD3_Vertices: ", LOD3vertexCount.ToString());
EditorGUILayout.LabelField("LOD3_Triangles: ", LOD3triangleCount.ToString());
EditorGUILayout.LabelField("LOD3_SubMeshes: ", LOD3submeshCount.ToString());
}
showLOD4info = EditorGUILayout.Foldout(showLOD4info, "LOD4 mesh information");
if (showLOD4info)
{
EditorGUILayout.LabelField("LOD4_Vertices: ", LOD4vertexCount.ToString());
EditorGUILayout.LabelField("LOD4_Triangles: ", LOD4triangleCount.ToString());
EditorGUILayout.LabelField("LOD4_SubMeshes: ", LOD4submeshCount.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment