-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeshViewer.cs
63 lines (56 loc) · 1.53 KB
/
MeshViewer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class WireframeViewer : MonoBehaviour
{
public Color wireframeBackgroundColor = Color.black;
public bool isInWireframeMode;
private Camera cam;
private CameraClearFlags origCameraClearFlags;
private Color origBackgroundColor;
private bool previousMode;
private void Start()
{
cam = GetComponent<Camera>();
origCameraClearFlags = cam.clearFlags;
origBackgroundColor = cam.backgroundColor;
previousMode = isInWireframeMode;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Z))
{
isInWireframeMode = !isInWireframeMode;
}
if (isInWireframeMode == previousMode)
{
return;
}
previousMode = isInWireframeMode;
if (isInWireframeMode)
{
origCameraClearFlags = cam.clearFlags;
origBackgroundColor = cam.backgroundColor;
cam.clearFlags = CameraClearFlags.Color;
cam.backgroundColor = wireframeBackgroundColor;
}
else
{
cam.clearFlags = origCameraClearFlags;
cam.backgroundColor = origBackgroundColor;
}
}
private void OnPreRender()
{
if (isInWireframeMode)
{
GL.wireframe = true;
}
}
private void OnPostRender()
{
if (isInWireframeMode)
{
GL.wireframe = false;
}
}
}