forked from fholm/unityassets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawMesh.cs
60 lines (48 loc) · 1.41 KB
/
DrawMesh.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
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class DrawMesh : MonoBehaviour {
Material material;
void OnPostRender() {
if (material == null) {
material = new Material("Shader \"DrawMesh\" {\n" +
"Properties { _Color (\"Main Color\", Color) = ( 1, 1, 1, 1 ) }\n" +
"SubShader { Pass { ZWrite Off Cull Off Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha\n" +
"Colormask RGBA Lighting Off Color[_Color]\n" +
"} } }");
}
material.color = new Color(1f, 0f, 0f, 0.15f);
material.SetPass(0);
DrawSolid(SphereMesh.Vertices, SphereMesh.Triangles);
material.color = new Color(1f, 0f, 0f, 0.75f);
material.SetPass(0);
DrawWireFrame(SphereMesh.Vertices, SphereMesh.Triangles);
}
void DrawWireFrame(Vector3[] v, int[] t) {
GL.Begin(GL.LINES);
for (int i = 0; i < t.Length; i += 3) {
Vector3 v0 = v[t[i + 0]];
Vector3 v1 = v[t[i + 1]];
Vector3 v2 = v[t[i + 2]];
GL.Vertex(v0);
GL.Vertex(v1);
GL.Vertex(v1);
GL.Vertex(v2);
GL.Vertex(v2);
GL.Vertex(v0);
}
GL.End();
}
void DrawSolid(Vector3[] v, int[] t) {
GL.Begin(GL.TRIANGLES);
for (int i = 0; i < t.Length; i += 3) {
Vector3 v0 = v[t[i + 0]];
Vector3 v1 = v[t[i + 1]];
Vector3 v2 = v[t[i + 2]];
GL.Vertex(v0);
GL.Vertex(v1);
GL.Vertex(v2);
}
GL.End();
}
}