Skip to content

Commit 5544a01

Browse files
authored
Merge pull request #2 from zigurous/release/1.5.0
Release/1.5.0
2 parents e35a094 + 04ac8bb commit 5544a01

21 files changed

+569
-12
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.5.0] - 2023/06/18
9+
10+
### Added
11+
12+
- New `ExitApplication` script
13+
- New `PauseApplication` script
14+
- New editor mesh debugger: Window > Analysis > Mesh Debugger
15+
- Behavior help URLs
16+
17+
### Changed
18+
19+
- Refactored the `Compare<T>` class
20+
- Changed the `Compare.Test` function to two distinct functions: `Compare.Equal` and `Compare.NotEqual`
21+
- The generics are now applied to the functions instead of the class, i.e., `Compare.Equal<int>` instead of `Compare<int>.Equal`
22+
823
## [1.4.0] - 2022/05/20
924

1025
### Added

Documentation~/articles/benchmarking.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Benchmark.Run(1000, Foo, Bar, Baz);
2323

2424
## 🎏 Compare Equality
2525

26-
Alternatively, sometimes it is useful to test if the results of two functions are equal. The **Debug Tools** package comes with another static class [Compare](/api/Zigurous.Debug/Compare-1) to handle these tests. The class uses generics to know the type of value you are looking to compare, and it returns the percentage of results that are equal.
26+
Sometimes it is useful to test if multiple functions return the same results. The **Debug Tools** package comes with another static class [Compare](/api/Zigurous.Debug/Compare-1) to handle these tests. The class uses generics to know the type of value you are looking to compare, and it returns the percentage of results that are equal (or not equal) for a given amount of iterations.
2727

2828
```csharp
29-
Compare<bool>.Test(Foo, Bar, 1000);
30-
Compare<float>.Test(Foo, Bar, 1000);
29+
Compare.Equal(Foo, Bar, 1000);
30+
Compare.NotEqual(Foo, Bar, 1000);
3131
```

Documentation~/articles/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ The **Debug Tools** package contains assets and scripts for debugging Unity proj
3030

3131
#### 🎨 [Debug Shaders](/manual/shaders)
3232

33+
#### 🖇️ [Mesh Debugger](/manual/mesh-debugger)
34+
3335
#### ✏️ [Drawing](/manual/drawing)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
slug: "/manual/mesh-debugger"
3+
---
4+
5+
# Mesh Debugger
6+
7+
The **Debug Tools** package includes a custom editor window for debugging and visualizing mesh data. To open this debugger, use the menu `Window > Analysis > Mesh Debugger`.
8+
9+
When a mesh is selected in the hierarchy while the window is open, a wireframe will be drawn around the current face of the mesh, and vertex and UV information will be shown in the editor. The window provides buttons to move to the next or previous face.
10+
11+
![](../images/mesh-debugger.jpg)

Documentation~/data/sidenav.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"name": "Debug Shaders",
4040
"path": "/manual/shaders"
4141
},
42+
{
43+
"name": "Mesh Debugger",
44+
"path": "/manual/mesh-debugger"
45+
},
4246
{
4347
"name": "Drawing",
4448
"path": "/manual/drawing"
96 KB
Loading

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/MeshDebugger.cs

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Zigurous.Debug.Editor
5+
{
6+
public sealed class MeshDebugger : EditorWindow
7+
{
8+
private Mesh currentMesh;
9+
private MeshFilter currentMeshFilter;
10+
private SkinnedMeshRenderer currentSkinnedMeshRenderer;
11+
private int currentFace = 0, numFaces = 0, newFace = 0;
12+
private GUIStyle labelStyle = null;
13+
private Vector3 p1, p2, p3;
14+
15+
[MenuItem("Window/Analysis/Mesh Debugger")]
16+
public static void ShowWindow()
17+
{
18+
EditorWindow.GetWindow(typeof(MeshDebugger), true, "Mesh Debugger");
19+
}
20+
21+
private void OnEnable()
22+
{
23+
SceneView.duringSceneGui -= OnSceneGUI;
24+
SceneView.duringSceneGui += OnSceneGUI;
25+
26+
OnSelectionChange();
27+
}
28+
29+
private void OnDestroy()
30+
{
31+
SceneView.duringSceneGui -= OnSceneGUI;
32+
}
33+
34+
private void OnSelectionChange()
35+
{
36+
currentMesh = null;
37+
currentSkinnedMeshRenderer = null;
38+
numFaces = 0;
39+
40+
if (Selection.activeGameObject)
41+
{
42+
currentMeshFilter = Selection.activeGameObject.GetComponentInChildren<MeshFilter>();
43+
44+
if (currentMeshFilter != null)
45+
{
46+
currentMesh = currentMeshFilter.sharedMesh;
47+
numFaces = currentMesh.triangles.Length / 3;
48+
}
49+
else
50+
{
51+
currentSkinnedMeshRenderer = Selection.activeGameObject.GetComponentInChildren<SkinnedMeshRenderer>();
52+
53+
if (currentSkinnedMeshRenderer != null)
54+
{
55+
currentMesh = currentSkinnedMeshRenderer.sharedMesh;
56+
numFaces = currentMesh.triangles.Length / 3;
57+
}
58+
}
59+
}
60+
61+
currentFace = 0;
62+
newFace = currentFace;
63+
64+
Repaint();
65+
}
66+
67+
private void OnGUI()
68+
{
69+
if (currentMesh == null)
70+
{
71+
EditorGUILayout.LabelField("Current selection contains no mesh");
72+
return;
73+
}
74+
75+
EditorGUILayout.LabelField("Number of faces", numFaces.ToString());
76+
EditorGUILayout.LabelField("Current face", currentFace.ToString());
77+
78+
newFace = EditorGUILayout.IntField("Jump to face", currentFace);
79+
80+
if (newFace != currentFace)
81+
{
82+
if (newFace >= 0 && newFace < numFaces) {
83+
currentFace = newFace;
84+
}
85+
}
86+
87+
EditorGUILayout.BeginHorizontal();
88+
89+
if (GUILayout.Button("Previous Face"))
90+
{
91+
currentFace = (currentFace - 1) % numFaces;
92+
93+
if (currentFace < 0) {
94+
currentFace = currentFace + numFaces;
95+
}
96+
}
97+
98+
if (GUILayout.Button("Next Face")) {
99+
currentFace = (currentFace + 1) % numFaces;
100+
}
101+
102+
EditorGUILayout.EndHorizontal();
103+
104+
EditorGUILayout.Space();
105+
106+
int redIndex = currentMesh.triangles[currentFace * 3];
107+
int greenIndex = currentMesh.triangles[currentFace * 3 + 1];
108+
int blueIndex = currentMesh.triangles[currentFace * 3 + 2];
109+
110+
EditorGUILayout.LabelField("Red vertex", $"Index: {redIndex}, UV: ({currentMesh.uv[redIndex].x}, {currentMesh.uv[redIndex].y})");
111+
EditorGUILayout.LabelField("Green vertex", $"Index: {greenIndex}, UV: ({currentMesh.uv[greenIndex].x}, {currentMesh.uv[greenIndex].y})");
112+
EditorGUILayout.LabelField("Blue vertex", $"Index: {blueIndex}, UV: ({currentMesh.uv[blueIndex].x}, {currentMesh.uv[blueIndex].y})");
113+
}
114+
115+
private void OnSceneGUI(SceneView sceneView)
116+
{
117+
if (currentMesh == null) {
118+
return;
119+
}
120+
121+
int index1 = currentMesh.triangles[currentFace * 3];
122+
int index2 = currentMesh.triangles[currentFace * 3 + 1];
123+
int index3 = currentMesh.triangles[currentFace * 3 + 2];
124+
125+
if (currentMeshFilter != null)
126+
{
127+
p1 = currentMeshFilter.transform.TransformPoint(currentMesh.vertices[index1]);
128+
p2 = currentMeshFilter.transform.TransformPoint(currentMesh.vertices[index2]);
129+
p3 = currentMeshFilter.transform.TransformPoint(currentMesh.vertices[index3]);
130+
}
131+
else if (currentSkinnedMeshRenderer != null)
132+
{
133+
p1 = currentSkinnedMeshRenderer.transform.TransformPoint(currentMesh.vertices[index1]);
134+
p2 = currentSkinnedMeshRenderer.transform.TransformPoint(currentMesh.vertices[index2]);
135+
p3 = currentSkinnedMeshRenderer.transform.TransformPoint(currentMesh.vertices[index3]);
136+
}
137+
138+
Handles.color = Color.red;
139+
Handles.SphereHandleCap(0, p1, Quaternion.identity, 0.2f * HandleUtility.GetHandleSize(p1), EventType.Repaint);
140+
Handles.color = Color.green;
141+
Handles.SphereHandleCap(0, p2, Quaternion.identity, 0.2f * HandleUtility.GetHandleSize(p2), EventType.Repaint);
142+
Handles.color = Color.blue;
143+
Handles.SphereHandleCap(0, p3, Quaternion.identity, 0.2f * HandleUtility.GetHandleSize(p3), EventType.Repaint);
144+
145+
Handles.color = Color.white;
146+
Handles.DrawDottedLine(p1, p2, 5f);
147+
Handles.DrawDottedLine(p2, p3, 5f);
148+
Handles.DrawDottedLine(p3, p1, 5f);
149+
150+
if (labelStyle == null)
151+
{
152+
labelStyle = new GUIStyle(GUI.skin.label);
153+
labelStyle.normal.textColor = Color.white;
154+
labelStyle.fixedWidth = 40;
155+
labelStyle.fixedHeight = 20;
156+
labelStyle.alignment = TextAnchor.MiddleCenter;
157+
labelStyle.fontSize = 12;
158+
labelStyle.clipping = TextClipping.Overflow;
159+
}
160+
161+
Handles.Label(p1, index1.ToString(), labelStyle);
162+
Handles.Label(p2, index2.ToString(), labelStyle);
163+
Handles.Label(p3, index3.ToString(), labelStyle);
164+
165+
sceneView.Repaint();
166+
}
167+
168+
private void OnInspectorUpdate()
169+
{
170+
Repaint();
171+
}
172+
173+
}
174+
175+
}

Editor/MeshDebugger.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Zigurous.Debug.Editor.asmdef

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "Zigurous.Debug.Editor",
3+
"references": [
4+
"GUID:0186cdaa7ccbaeb4f91d3907506784d7"
5+
],
6+
"includePlatforms": [
7+
"Editor"
8+
],
9+
"excludePlatforms": [],
10+
"allowUnsafeCode": false,
11+
"overrideReferences": false,
12+
"precompiledReferences": [],
13+
"autoReferenced": true,
14+
"defineConstraints": [],
15+
"versionDefines": [],
16+
"noEngineReferences": false
17+
}

0 commit comments

Comments
 (0)