Elin Modding Docs Doc
Loading...
Searching...
No Matches
ProceduralMesh.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5// Token: 0x0200012E RID: 302
6public class ProceduralMesh : ScriptableObject
7{
8 // Token: 0x06000816 RID: 2070 RVA: 0x00034E98 File Offset: 0x00033098
9 public Mesh GetMesh()
10 {
11 if (!this.mesh)
12 {
13 this.Create();
14 }
15 return this.mesh;
16 }
17
18 // Token: 0x06000817 RID: 2071 RVA: 0x00034EB4 File Offset: 0x000330B4
19 public void Create()
20 {
21 this.mesh = new Mesh();
22 this.triOffset = 0;
23 this.triangles.Clear();
24 this.vertices.Clear();
25 this.uv.Clear();
26 if (this.top)
27 {
28 this.vertices.AddRange(new Vector3[]
29 {
30 new Vector3(0f, this.size.y, this.size.z) + this.pos,
31 new Vector3(this.size.x, this.size.y, this.size.z) + this.pos,
32 new Vector3(this.size.x, this.size.y, 0f) + this.pos,
33 new Vector3(0f, this.size.y, 0f) + this.pos
34 });
35 this.uv.AddRange(this.GetUVs(0));
36 this.AddTriangles();
37 }
38 else
39 {
40 this.vertices.AddRange(new Vector3[]
41 {
42 new Vector3(0f, this.size.y, 0f) + this.pos,
43 new Vector3(this.size.x, this.size.y, 0f) + this.pos,
44 new Vector3(this.size.x, this.offset.y, 0f) + this.pos,
45 new Vector3(0f, this.offset.y, 0f) + this.pos
46 });
47 this.uv.AddRange(this.GetUVs(0));
48 this.AddTriangles();
49 }
50 this.mesh.SetVertices(this.vertices);
51 this.mesh.SetUVs(0, this.uv);
52 this.mesh.SetTriangles(this.triangles, 0);
53 if (this.calculateNormal)
54 {
55 this.mesh.RecalculateNormals();
56 }
57 }
58
59 // Token: 0x06000818 RID: 2072 RVA: 0x00035124 File Offset: 0x00033324
60 public void AddTriangles()
61 {
62 this.triangles.AddRange(new int[]
63 {
64 this.triOffset,
65 1 + this.triOffset,
66 2 + this.triOffset,
67 2 + this.triOffset,
68 3 + this.triOffset,
69 this.triOffset
70 });
71 this.triOffset += 4;
72 }
73
74 // Token: 0x06000819 RID: 2073 RVA: 0x00035190 File Offset: 0x00033390
75 private Vector2[] GetUVs(int id)
76 {
77 Vector2[] array = new Vector2[4];
78 Vector2 vector = new Vector2(1f / this.tiling.x, 1f / this.tiling.y);
79 int num = id % (int)this.tiling.x;
80 int num2 = id / (int)this.tiling.x;
81 float num3 = this.UVPadding / this.tiling.x;
82 array[0] = new Vector2((float)num / this.tiling.x + num3, 1f - (float)num2 / this.tiling.y - num3);
83 array[1] = new Vector2((float)num / this.tiling.x + vector.x - num3, 1f - (float)num2 / this.tiling.y - num3);
84 array[2] = new Vector2((float)num / this.tiling.x + vector.x - num3, 1f - ((float)num2 / this.tiling.y + vector.y) + num3);
85 array[3] = new Vector2((float)num / this.tiling.x + num3, 1f - ((float)num2 / this.tiling.y + vector.y) + num3);
86 return array;
87 }
88
89 // Token: 0x04000872 RID: 2162
90 public Vector2 tiling = Vector2.one;
91
92 // Token: 0x04000873 RID: 2163
93 public float UVPadding = 0.02f;
94
95 // Token: 0x04000874 RID: 2164
96 public Vector3 pos = new Vector3(0f, 0f, -1f);
97
98 // Token: 0x04000875 RID: 2165
99 public Vector3 offset;
100
101 // Token: 0x04000876 RID: 2166
102 public Vector3 size = Vector3.one;
103
104 // Token: 0x04000877 RID: 2167
105 public bool top;
106
107 // Token: 0x04000878 RID: 2168
108 public bool calculateNormal = true;
109
110 // Token: 0x04000879 RID: 2169
111 private Mesh mesh;
112
113 // Token: 0x0400087A RID: 2170
114 private List<int> triangles = new List<int>();
115
116 // Token: 0x0400087B RID: 2171
117 private List<Vector3> vertices = new List<Vector3>();
118
119 // Token: 0x0400087C RID: 2172
120 private List<Vector2> uv = new List<Vector2>();
121
122 // Token: 0x0400087D RID: 2173
123 private int triOffset;
124}