forked from Syomus/ProceduralToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLE.cs
234 lines (200 loc) · 7.79 KB
/
GLE.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace ProceduralToolkit
{
/// <summary>
/// Collection of GL drawing methods similar to Gizmos
/// </summary>
public static class GLE
{
public static readonly Material wireMaterial;
private static readonly Action<Vector3, Vector3> drawLine;
static GLE()
{
var shader = Shader.Find("Hidden/Internal-Colored");
wireMaterial = new Material(shader) {hideFlags = HideFlags.HideAndDontSave};
wireMaterial.SetInt("_SrcBlend", (int) BlendMode.SrcAlpha);
wireMaterial.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha);
wireMaterial.SetInt("_Cull", (int) CullMode.Off);
wireMaterial.SetInt("_ZWrite", 0);
drawLine = DrawLine;
}
/// <summary>
/// Set material and call GL.Begin(GL.LINES)
/// </summary>
public static void BeginLines()
{
wireMaterial.SetPass(0);
GL.Begin(GL.LINES);
}
/// <summary>
/// Draws a line between specified from and to points
/// </summary>
public static void DrawLine(Vector3 from, Vector3 to)
{
GL.Vertex(from);
GL.Vertex(to);
}
/// <summary>
/// Draws a ray starting at ray.origin to ray.origin + ray.direction
/// </summary>
public static void DrawRay(Ray ray)
{
Draw.Ray(drawLine, ray);
}
/// <summary>
/// Draws a segment
/// </summary>
public static void DrawSegment2(Segment2 segment)
{
Draw.Segment2(drawLine, segment);
}
/// <summary>
/// Draws a segment
/// </summary>
public static void DrawSegment3(Segment3 segment)
{
Draw.Segment3(drawLine, segment);
}
#region DrawWireQuad
/// <summary>
/// Draws a wireframe quad with position, rotation and scale
/// </summary>
public static void DrawWireQuadXY(Vector3 position, Quaternion rotation, Vector2 scale)
{
Draw.WireQuadXY(drawLine, position, rotation, scale);
}
/// <summary>
/// Draws a wireframe quad with position, rotation and scale
/// </summary>
public static void DrawWireQuadXZ(Vector3 position, Quaternion rotation, Vector2 scale)
{
Draw.WireQuadXZ(drawLine, position, rotation, scale);
}
/// <summary>
/// Draws a wireframe quad with position, rotation and scale
/// </summary>
public static void DrawWireQuadYZ(Vector3 position, Quaternion rotation, Vector2 scale)
{
Draw.WireQuadYZ(drawLine, position, rotation, scale);
}
#endregion DrawWireQuad
/// <summary>
/// Draws a wireframe cube with position, rotation and scale
/// </summary>
public static void DrawWireCube(Vector3 position, Quaternion rotation, Vector3 scale)
{
Draw.WireCube(drawLine, position, rotation, scale);
}
#region DrawWireCircle
/// <summary>
/// Draws a wireframe circle with position and radius
/// </summary>
public static void DrawWireCircleXY(Vector3 position, float radius)
{
Draw.WireCircleXY(drawLine, position, radius);
}
/// <summary>
/// Draws a wireframe circle with position, rotation and radius
/// </summary>
public static void DrawWireCircleXY(Vector3 position, Quaternion rotation, float radius)
{
Draw.WireCircleXY(drawLine, position, rotation, radius);
}
/// <summary>
/// Draws a wireframe circle with position and radius
/// </summary>
public static void DrawWireCircleXZ(Vector3 position, float radius)
{
Draw.WireCircleXZ(drawLine, position, radius);
}
/// <summary>
/// Draws a wireframe circle with position, rotation and radius
/// </summary>
public static void DrawWireCircleXZ(Vector3 position, Quaternion rotation, float radius)
{
Draw.WireCircleXZ(drawLine, position, rotation, radius);
}
/// <summary>
/// Draws a wireframe circle with position and radius
/// </summary>
public static void DrawWireCircleYZ(Vector3 position, float radius)
{
Draw.WireCircleYZ(drawLine, position, radius);
}
/// <summary>
/// Draws a wireframe circle with position, rotation and radius
/// </summary>
public static void DrawWireCircleYZ(Vector3 position, Quaternion rotation, float radius)
{
Draw.WireCircleYZ(drawLine, position, rotation, radius);
}
#endregion DrawWireCircle
#region DrawWireArc
/// <summary>
/// Draws a wireframe circular arc with position and radius
/// </summary>
public static void DrawWireArcXY(Vector3 position, float radius, float fromAngle, float toAngle)
{
Draw.WireArcXY(drawLine, position, radius, fromAngle, toAngle);
}
/// <summary>
/// Draws a wireframe circular arc with position, rotation and radius
/// </summary>
public static void DrawWireArcXY(Vector3 position, Quaternion rotation, float radius, float fromAngle, float toAngle)
{
Draw.WireArcXY(drawLine, position, rotation, radius, fromAngle, toAngle);
}
/// <summary>
/// Draws a wireframe circular arc with position and radius
/// </summary>
public static void DrawWireArcXZ(Vector3 position, float radius, float fromAngle, float toAngle)
{
Draw.WireArcXZ(drawLine, position, radius, fromAngle, toAngle);
}
/// <summary>
/// Draws a wireframe circular arc with position, rotation and radius
/// </summary>
public static void DrawWireArcXZ(Vector3 position, Quaternion rotation, float radius, float fromAngle, float toAngle)
{
Draw.WireArcXZ(drawLine, position, rotation, radius, fromAngle, toAngle);
}
/// <summary>
/// Draws a wireframe circular arc with position and radius
/// </summary>
public static void DrawWireArcYZ(Vector3 position, float radius, float fromAngle, float toAngle)
{
Draw.WireArcYZ(drawLine, position, radius, fromAngle, toAngle);
}
/// <summary>
/// Draws a wireframe circular arc with position, rotation and radius
/// </summary>
public static void DrawWireArcYZ(Vector3 position, Quaternion rotation, float radius, float fromAngle, float toAngle)
{
Draw.WireArcYZ(drawLine, position, rotation, radius, fromAngle, toAngle);
}
#endregion DrawWireArc
/// <summary>
/// Draws a wireframe sphere with position, rotation and radius
/// </summary>
public static void DrawWireSphere(Vector3 position, Quaternion rotation, float radius)
{
Draw.WireSphere(drawLine, position, rotation, radius);
}
/// <summary>
/// Draws a wireframe hemisphere with position, rotation and radius
/// </summary>
public static void DrawWireHemisphere(Vector3 position, Quaternion rotation, float radius)
{
Draw.WireHemisphere(drawLine, position, rotation, radius);
}
/// <summary>
/// Draws a wireframe cone with position and rotation
/// </summary>
public static void DrawWireCone(Vector3 position, Quaternion rotation, float apexRadius, float angle, float length)
{
Draw.WireCone(drawLine, position, rotation, apexRadius, angle, length);
}
}
}