Skip to content

Commit bf02ed4

Browse files
committed
240613.1547
v0.0.6.2 ・ provide better information for Mesh Information
1 parent 94096de commit bf02ed4

2 files changed

Lines changed: 90 additions & 6 deletions

File tree

src/DecimaterMain.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private void UpdateSelection(GameObject newSelectedGameObject)
9595
originalMesh = meshFilter.sharedMesh;
9696
EnableReadWrite(originalMesh);
9797
decimatedMesh = Instantiate(originalMesh);
98+
meshInfoDisplay.SetOriginalMesh(originalMesh);
9899
Selection.activeObject = originalMesh;
99100
Debug.Log($"Selected Mesh: {AssetDatabase.GetAssetPath(originalMesh)}");
100101
Repaint();
@@ -105,6 +106,7 @@ private void UpdateSelection(GameObject newSelectedGameObject)
105106
originalMesh = skinnedMeshRenderer.sharedMesh;
106107
EnableReadWrite(originalMesh);
107108
decimatedMesh = Instantiate(originalMesh);
109+
meshInfoDisplay.SetOriginalMesh(originalMesh);
108110
Selection.activeObject = originalMesh;
109111
Debug.Log($"Selected Mesh: {AssetDatabase.GetAssetPath(originalMesh)}");
110112
Repaint();

src/MeshInfoDisplay.cs

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,98 @@
33

44
public class MeshInfoDisplay
55
{
6+
private Mesh originalMesh;
7+
private int originalVertexCount;
8+
private int originalTriangleCount;
9+
private int originalSubMeshCount;
10+
private float originalMeshSize;
11+
12+
public void SetOriginalMesh(Mesh mesh)
13+
{
14+
originalMesh = mesh;
15+
originalVertexCount = mesh.vertexCount;
16+
originalTriangleCount = mesh.triangles.Length / 3;
17+
originalSubMeshCount = mesh.subMeshCount;
18+
originalMeshSize = CalculateMeshSize(mesh);
19+
}
20+
621
public void DisplayMeshInfo(Mesh mesh)
722
{
8-
if (mesh == null) return;
23+
if (mesh == null)
24+
{
25+
EditorGUILayout.HelpBox("No mesh selected.", MessageType.Info);
26+
return;
27+
}
928

1029
GUILayout.BeginVertical("box");
1130
GUILayout.Label("Mesh Information", EditorStyles.boldLabel);
12-
GUILayout.Label($"Vertices: {mesh.vertexCount}");
13-
GUILayout.Label($"Triangles: {mesh.triangles.Length / 3}");
14-
GUILayout.Label($"Submeshes: {mesh.subMeshCount}");
15-
GUILayout.Label($"Mesh Size: {MeshUtils.CalculateMeshSize(mesh)} KB");
31+
32+
DisplayMeshDetails(mesh);
33+
1634
GUILayout.EndVertical();
1735
}
18-
}
36+
37+
private void DisplayMeshDetails(Mesh mesh)
38+
{
39+
int newVertexCount = mesh.vertexCount;
40+
int newTriangleCount = mesh.triangles.Length / 3;
41+
int newSubMeshCount = mesh.subMeshCount;
42+
float newMeshSize = CalculateMeshSize(mesh);
43+
44+
GUILayout.Label(GetFormattedLabel("Vertices", originalVertexCount, newVertexCount));
45+
GUILayout.Label(GetFormattedLabel("Triangles", originalTriangleCount, newTriangleCount));
46+
GUILayout.Label(GetFormattedLabel("Submeshes", originalSubMeshCount, newSubMeshCount));
47+
GUILayout.Label(GetFormattedLabel("Mesh Size (KB)", originalMeshSize, newMeshSize));
48+
}
49+
50+
private GUIStyle GetReductionStyle()
51+
{
52+
GUIStyle style = new GUIStyle(GUI.skin.label);
53+
style.normal.textColor = Color.green;
54+
return style;
55+
}
56+
57+
private string GetFormattedLabel(string label, int originalValue, int newValue)
58+
{
59+
if (originalMesh == null || originalValue == newValue)
60+
{
61+
return $"{label}: {newValue}";
62+
}
63+
float reduction = CalculateReduction(originalValue, newValue);
64+
return $"{label}: {newValue} (-{originalValue - newValue}, -{reduction:F2}%)";
65+
}
66+
67+
private string GetFormattedLabel(string label, float originalValue, float newValue)
68+
{
69+
if (originalMesh == null || Mathf.Approximately(originalValue, newValue))
70+
{
71+
return $"{label}: {newValue:F2} KB";
72+
}
73+
float reduction = CalculateReduction(originalValue, newValue);
74+
return $"{label}: {newValue:F2} KB (-{originalValue - newValue:F2} KB, -{reduction:F2}%)";
75+
}
76+
77+
private float CalculateReduction(int original, int newValue)
78+
{
79+
if (original == 0) return 0;
80+
return ((float)(original - newValue) / original) * 100f;
81+
}
82+
83+
private float CalculateReduction(float original, float newValue)
84+
{
85+
if (original == 0) return 0;
86+
return ((original - newValue) / original) * 100f;
87+
}
88+
89+
private float CalculateMeshSize(Mesh mesh)
90+
{
91+
float size = 0;
92+
size += mesh.vertexCount * sizeof(float) * 3;
93+
size += mesh.normals.Length * sizeof(float) * 3;
94+
size += mesh.uv.Length * sizeof(float) * 2;
95+
size += mesh.tangents.Length * sizeof(float) * 4;
96+
size += mesh.triangles.Length * sizeof(int);
97+
98+
return size / 1024;
99+
}
100+
}

0 commit comments

Comments
 (0)