Skip to content

Commit 5043828

Browse files
committed
⚡ Supercharged!
Graphics powered particle-like quad Internal-Colored get extracted at separated (line-quad) Corrected invalidation at static (including transformation) static config by default delete binormal (tangent debug has it)
1 parent 02f4dce commit 5043828

11 files changed

Lines changed: 207 additions & 86 deletions

Assets/Plugins/MeshDebugger/Editor/IMGizmo.cs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@ private void OnDisable()
1717

1818
private void OnDestroy()
1919
{
20-
if (m_Mesh) DestroyImmediate(m_Mesh);
20+
if (m_Mesh)
21+
{
22+
DestroyImmediate(m_Mesh);
23+
DestroyImmediate(m_LineMaterial);
24+
DestroyImmediate(m_QuadMaterial);
25+
}
2126
}
2227

2328
public Transform m_Camera;
2429
public Mesh m_Mesh;
25-
public Material m_Material;
30+
public Material m_LineMaterial;
31+
public Material m_QuadMaterial;
2632
public Matrix4x4 m_Matrix;
2733
public bool m_EqualSize;
2834
public bool m_Active = true;
29-
public int m_Layer = 0;
30-
35+
3136
public List<Vector3> m_Vertices = new List<Vector3>(16);
3237
public List<Color> m_Color = new List<Color>(16);
3338
public List<int> m_Lines = new List<int>(16);
3439
public List<int> m_Quads = new List<int>(16);
40+
public List<Vector2> m_UV = new List<Vector2>(16);
3541

3642
public void AddLine(Vector3 start, Vector3 end, Color color)
3743
{
@@ -42,6 +48,8 @@ public void AddLine(Vector3 start, Vector3 end, Color color)
4248
m_Lines.Add(m - 1);
4349
m_Color.Add(color);
4450
m_Color.Add(color);
51+
m_UV.Add(default(Vector2));
52+
m_UV.Add(default(Vector2));
4553
}
4654

4755
public void AddRay(Vector3 pos, Vector3 dir, Color color)
@@ -51,12 +59,12 @@ public void AddRay(Vector3 pos, Vector3 dir, Color color)
5159
AddLine(pos, pos + dir, color);
5260
}
5361

54-
public void AddQuad(Vector3 pos, Vector3 up, Vector3 right, Color color)
62+
public void AddQuad(Vector3 pos, Vector2 size, Color color)
5563
{
56-
m_Vertices.Add(pos + up - right);
57-
m_Vertices.Add(pos - up - right);
58-
m_Vertices.Add(pos - up + right);
59-
m_Vertices.Add(pos + up + right);
64+
m_Vertices.Add(pos);
65+
m_Vertices.Add(pos);
66+
m_Vertices.Add(pos);
67+
m_Vertices.Add(pos);
6068
var m = m_Vertices.Count;
6169
m_Quads.Add(m - 4);
6270
m_Quads.Add(m - 3);
@@ -66,20 +74,24 @@ public void AddQuad(Vector3 pos, Vector3 up, Vector3 right, Color color)
6674
m_Color.Add(color);
6775
m_Color.Add(color);
6876
m_Color.Add(color);
77+
m_UV.Add(new Vector2(-size.x, -size.y));
78+
m_UV.Add(new Vector2(size.x, -size.y));
79+
m_UV.Add(new Vector2(size.x, size.y));
80+
m_UV.Add(new Vector2(-size.x, size.y));
6981
}
7082

7183
public void AddQuad(Vector3 pos, float size, Color color)
7284
{
7385
if (m_EqualSize)
7486
size *= GetHandleSize(pos);
75-
AddQuad(pos, m_Camera.up * size, m_Camera.right * size, color);
87+
AddQuad(pos, Vector2.one * size, color);
7688
}
7789

7890
public void AddQuad(Vector3 pos, float size, float colorFactor)
7991
{
8092
if (m_EqualSize)
8193
size *= GetHandleSize(pos);
82-
AddQuad(pos + m_Camera.forward * -size, m_Camera.up * size, m_Camera.right * size, HSVToRGB(colorFactor));
94+
AddQuad(pos, Vector2.one * size, HSVToRGB(colorFactor));
8395
}
8496

8597
private float GetHandleSize(Vector3 position)
@@ -181,32 +193,32 @@ public void Init(Transform transform, Transform camera, bool depth, bool equalSi
181193
m_Color.Clear();
182194
m_Lines.Clear();
183195
m_Quads.Clear();
196+
m_UV.Clear();
184197

185198
m_Matrix = transform.localToWorldMatrix;
186199
m_Camera = camera;
187200
m_EqualSize = equalSize;
188-
m_Layer = transform.gameObject.layer;
201+
}
202+
203+
public void UpdateGO(Transform transform)
204+
{
205+
m_Matrix = transform.localToWorldMatrix;
189206
}
190207

191208
private void InitMaterial(bool writeDepth)
192209
{
193-
if (!m_Material)
210+
if (!m_LineMaterial)
194211
{
195-
// Unity has a built-in shader that is useful for drawing
196-
// simple colored things.
197-
var shader = Shader.Find("Hidden/Internal-Colored");
198-
m_Material = new Material(shader);
199-
m_Material.hideFlags = HideFlags.DontSave;
200-
// Turn on alpha blending
201-
m_Material.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
202-
m_Material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
203-
// Turn backface culling off
204-
m_Material.SetInt("_Cull", (int)CullMode.Off);
205-
// Turn off depth writes
206-
m_Material.SetInt("_ZWrite", 0);
212+
var shader = Shader.Find("Hidden/InternalLineColorful");
213+
m_LineMaterial = new Material(shader);
214+
m_LineMaterial.hideFlags = HideFlags.DontSave;
215+
var shader2 = Shader.Find("Hidden/InternalQuadColorful");
216+
m_QuadMaterial = new Material(shader2);
217+
m_QuadMaterial.hideFlags = HideFlags.DontSave;
207218
}
208219
// Set external depth on/off
209-
m_Material.SetInt("_ZTest", writeDepth ? 4 : 0);
220+
m_LineMaterial.SetInt("_ZTest", writeDepth ? 4 : 0);
221+
m_QuadMaterial.SetInt("_ZTest", writeDepth ? 4 : 0);
210222
}
211223

212224
public void End()
@@ -215,6 +227,7 @@ public void End()
215227

216228
m_Mesh.SetVertices(m_Vertices);
217229
m_Mesh.SetColors(m_Color);
230+
m_Mesh.SetUVs(0, m_UV);
218231
m_Mesh.subMeshCount = 2;
219232
m_Mesh.SetIndices(m_Lines.ToArray(), MeshTopology.Lines, 0);
220233
m_Mesh.SetIndices(m_Quads.ToArray(), MeshTopology.Quads, 1);
@@ -229,13 +242,15 @@ public void Clear()
229242
m_Color.Clear();
230243
m_Lines.Clear();
231244
m_Quads.Clear();
245+
m_UV.Clear();
232246

233247
}
234248

235249
public void Render()
236250
{
237-
m_Material.SetPass(0);
251+
m_LineMaterial.SetPass(0);
238252
Graphics.DrawMeshNow(m_Mesh, m_Matrix, 0);
253+
m_QuadMaterial.SetPass(0);
239254
Graphics.DrawMeshNow(m_Mesh, m_Matrix, 1);
240255
}
241256
}

Assets/Plugins/MeshDebugger/Editor/IMGizmos.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public void AddRay(Vector3 pos, Vector3 dir, Color color)
2323
m_Gizmos[m_CurIter].AddRay(pos, dir, color);
2424
}
2525

26-
public void AddQuad(Vector3 pos, Vector3 up, Vector3 right, Color color)
26+
public void AddQuad(Vector3 pos, Vector2 size, Color color)
2727
{
2828
ValidateCurrentIter(4);
29-
m_Gizmos[m_CurIter].AddQuad(pos, up, right, color);
29+
m_Gizmos[m_CurIter].AddQuad(pos, size, color);
3030
}
3131

3232
public void AddQuad(Vector3 pos, float size, Color color)
3333
{
3434
ValidateCurrentIter(4);
35-
m_Gizmos[m_CurIter].AddQuad(pos, size, color);
35+
m_Gizmos[m_CurIter].AddQuad(pos, Vector2.one * size, color);
3636
}
3737

3838
public void AddQuad(Vector3 pos, float size, float colorFactor)
@@ -52,10 +52,16 @@ private void ValidateCurrentIter(int additional)
5252
else
5353
m_Gizmos[m_CurIter].m_Active = true;
5454
}
55-
55+
56+
private Transform _transform;
57+
private Transform _camera;
58+
private bool _depth;
59+
private bool _equalSize;
60+
5661
private void CreateNewIter()
5762
{
5863
var giz = ScriptableObject.CreateInstance<IMGizmo>();
64+
giz.Init(_transform, _camera, _depth, _equalSize);
5965
m_Gizmos.Add(giz);
6066
}
6167

@@ -70,6 +76,10 @@ public void Init(Transform transform, Transform camera, bool depth, bool equalSi
7076
m_Gizmos[i].m_Active = i == 0;
7177
m_Gizmos[i].Init(transform, camera, depth, equalSize);
7278
}
79+
_transform = transform;
80+
_camera = camera;
81+
_depth = depth;
82+
_equalSize = equalSize;
7383
}
7484

7585
public void End()
@@ -85,7 +95,8 @@ public void Render()
8595
{
8696
for (int i = 0; i < m_Gizmos.Count; i++)
8797
{
88-
m_Gizmos[i].Render();
98+
if (m_Gizmos[i].m_Active)
99+
m_Gizmos[i].Render();
89100
}
90101
}
91102

@@ -104,4 +115,13 @@ public void Clear()
104115
item.Clear();
105116
}
106117
}
118+
119+
internal void UpdateGO(Transform transform)
120+
{
121+
for (int i = 0; i < m_Gizmos.Count; i++)
122+
{
123+
if (m_Gizmos[i].m_Active)
124+
m_Gizmos[i].UpdateGO(transform);
125+
}
126+
}
107127
}

Assets/Plugins/MeshDebugger/Editor/MeshDebugger.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class MeshDebugger : EditorWindow
1010
public Transform m_Transform;
1111
public IMGizmos m_Gizmo = new IMGizmos();
1212

13-
public bool m_Static;
13+
public bool m_Static = true;
1414
public bool m_DepthCulling;
1515
public bool m_EqualizeGizmoSize;
1616

@@ -75,17 +75,10 @@ void OnSelectionChange()
7575
var m = m_Transform.GetComponent<MeshFilter>();
7676
if (m) m_Mesh = m.sharedMesh;
7777
else
78-
{
79-
var m2 = m_Transform.GetComponent<Graphic>();
80-
81-
}
78+
m_Mesh = null;
8279
}
8380
else
8481
{
85-
foreach (var item in m_Gizmo.m_Gizmos)
86-
{
87-
item.Clear();
88-
}
8982
m_Mesh = null;
9083
}
9184
Repaint();
@@ -94,7 +87,13 @@ void OnSelectionChange()
9487
void OnGUI()
9588
{
9689
EditorGUI.BeginChangeCheck();
97-
m_Transform = (Transform)EditorGUILayout.ObjectField("Target", m_Transform, typeof(Transform), true);
90+
{
91+
EditorGUILayout.BeginHorizontal();
92+
EditorGUILayout.PrefixLabel("Target");
93+
m_Transform = (Transform)EditorGUILayout.ObjectField(m_Transform, typeof(Transform), true);
94+
m_Mesh = (Mesh)EditorGUILayout.ObjectField(m_Mesh, typeof(Mesh), true);
95+
EditorGUILayout.EndHorizontal();
96+
}
9897
{
9998
EditorGUILayout.BeginHorizontal();
10099
EditorGUILayout.PrefixLabel("Configuration");
@@ -163,6 +162,7 @@ void OnSceneGUI(SceneView view)
163162
{
164163
if (m_Gizmo != null)
165164
m_Gizmo.Clear();
165+
m_cpu.m_lastMeshId = -1;
166166
return;
167167
}
168168

@@ -175,6 +175,7 @@ void OnSceneGUI(SceneView view)
175175
m_cpu.Update();
176176
else if (m_hasUpdated)
177177
{
178+
m_Gizmo.UpdateGO(m_Transform);
178179
m_Gizmo.Render();
179180
return;
180181
}
@@ -216,6 +217,7 @@ void OnSceneGUI(SceneView view)
216217

217218
if (m_UseHeatmap)
218219
{
220+
// Vector3 fwd = m_Static ? default(Vector3) : m_sceneCam.forward * -m_HeatSize;
219221
float factor;
220222
switch (m_DebugTris)
221223
{
@@ -271,8 +273,8 @@ void OnSceneGUI(SceneView view)
271273
}
272274
else if (m_cpu.m_IndiceCount < 10000 && m_cpu.m_VertCount < 5000)
273275
{
274-
// IMGUI is always slow. Better safe than sorry
275-
276+
// IMGUI is always slow. Better safe than sorry
277+
276278
Handles.BeginGUI();
277279
switch (m_DebugTris)
278280
{

Assets/Plugins/MeshDebugger/Editor/MeshInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class MeshInfo
99
{
1010
public Mesh m_Mesh;
11-
private int m_lastMeshId = -1;
11+
public int m_lastMeshId = -1;
1212
public bool m_MeshReadable;
1313
public Bounds m_MeshBounds;
1414
public int m_VertCount;

Assets/Plugins/MeshDebugger/Shaders/DebugBinormal.shader

Lines changed: 0 additions & 37 deletions
This file was deleted.

Assets/Plugins/MeshDebugger/Shaders/DebugTangent.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
Shader "Debug/Tangents" {
33
Properties{
4-
[Enum(Normal,1,Tangent,2,Bitangent,3,WorldNormal,4,WorldTangent,5,WorldBitangent,6)] Tan_Mode("Visualization Mode", Int) = 1
4+
[Enum(Normal,1,Tangent,2,Bitangent,3,WorldNormal,4,WorldTangent,5,WorldBitangent,6)]
5+
Tan_Mode("Visualization Mode", Int) = 1
56
}SubShader{
67
Pass {
78
Fog { Mode Off }

Assets/Plugins/MeshDebugger/Shaders/DebugUV.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
Shader "Debug/UV" {
33
Properties{
4-
[Enum(UV,1,UV2,2,UV3,3,UV4,4)] UV_Mode("Selected UV", Int) = 1
4+
[Enum(UV,1,UV2,2,UV3,3,UV4,4)]
5+
UV_Mode("Selected UV", Int) = 1
56
}
67
SubShader{
78
Pass {

0 commit comments

Comments
 (0)