MeshInfo
From Unify Community Wiki
(Difference between revisions)
(Fixed bug where meshes could be counted twice if a parent and child were both selected.) |
(Fixed divide by zero error and altered menu shortcut to not conflict with other scripts on the wiki.) |
||
Line 19: | Line 19: | ||
public class MeshInfo : ScriptableObject | public class MeshInfo : ScriptableObject | ||
{ | { | ||
− | [MenuItem ("Custom/Show Mesh Info %i")] | + | [MenuItem ("Custom/Show Mesh Info %#i")] |
public static void ShowCount() | public static void ShowCount() | ||
{ | { | ||
Line 43: | Line 43: | ||
EditorUtility.DisplayDialog("Vertex and Triangle Count", vertices | EditorUtility.DisplayDialog("Vertex and Triangle Count", vertices | ||
+ " vertices in selection. " + triangles + " triangles in selection. " | + " vertices in selection. " + triangles + " triangles in selection. " | ||
− | + meshCount + " meshes in selection. Average of " + vertices / meshCount | + | + meshCount + " meshes in selection." + (meshCount > 0 ? (" Average of " + vertices / meshCount |
− | + " vertices and " + triangles / meshCount + " triangles per mesh.", "OK", ""); | + | + " vertices and " + triangles / meshCount + " triangles per mesh.") : ""), "OK", ""); |
} | } | ||
Revision as of 12:05, 15 October 2006
Author: Jonathan Czeck (aarku)
Description
This script will show statistics of the meshes in the current selection. If a parent object is selected, the script will show statistics of the parent's entire hierarchy.
Usage
Place this script in YourProject/Assets/Editor and a menu item will automatically appear in the Custom menu after it is compiled. Then select any number of objects and select the menu item to see triangle and vertex info.
C# - MeshInfo.cs
<csharp>using UnityEngine; using UnityEditor; using System.Collections;
public class MeshInfo : ScriptableObject {
[MenuItem ("Custom/Show Mesh Info %#i")] public static void ShowCount() { int triangles = 0; int vertices = 0; int meshCount = 0; foreach (GameObject go in Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel)) { Component[] meshes = go.GetComponentsInChildren(typeof(MeshFilter));
foreach (MeshFilter mesh in meshes) { if (mesh.sharedMesh) { vertices += mesh.sharedMesh.vertexCount; triangles += mesh.sharedMesh.triangles.Length / 3; meshCount++; } } }
EditorUtility.DisplayDialog("Vertex and Triangle Count", vertices + " vertices in selection. " + triangles + " triangles in selection. " + meshCount + " meshes in selection." + (meshCount > 0 ? (" Average of " + vertices / meshCount + " vertices and " + triangles / meshCount + " triangles per mesh.") : ""), "OK", ""); } [MenuItem ("Custom/Show Mesh Info %i", true)] public static bool ValidateShowCount() { return Selection.activeGameObject; }
} </csharp>