4 using System.Collections;
5 using System.Collections.Generic;
10 public enum VertexSortingOrder { Normal, Reverse };
17 private static readonly Color32 s_DefaultColor =
new Color32(
byte.MaxValue,
byte.MaxValue,
byte.MaxValue,
byte.MaxValue);
18 private static readonly Vector3 s_DefaultNormal =
new Vector3(0.0f, 0.0f, -1f);
19 private static readonly Vector4 s_DefaultTangent =
new Vector4(-1f, 0.0f, 0.0f, 1f);
22 public int vertexCount;
24 public Vector3[] vertices;
25 public Vector3[] normals;
26 public Vector4[] tangents;
28 public Vector2[] uvs0;
29 public Vector2[] uvs2;
31 public Color32[] colors32;
32 public int[] triangles;
54 size = Mathf.Min(size, 16383);
56 int sizeX4 = size * 4;
57 int sizeX6 = size * 6;
61 this.vertices =
new Vector3[sizeX4];
62 this.uvs0 =
new Vector2[sizeX4];
63 this.uvs2 =
new Vector2[sizeX4];
65 this.colors32 =
new Color32[sizeX4];
67 this.normals =
new Vector3[sizeX4];
68 this.tangents =
new Vector4[sizeX4];
70 this.triangles =
new int[sizeX6];
74 while (index_X4 / 4 < size)
76 for (
int i = 0; i < 4; i++)
78 this.vertices[index_X4 + i] = Vector3.zero;
79 this.uvs0[index_X4 + i] = Vector2.zero;
80 this.uvs2[index_X4 + i] = Vector2.zero;
82 this.colors32[index_X4 + i] = s_DefaultColor;
83 this.normals[index_X4 + i] = s_DefaultNormal;
84 this.tangents[index_X4 + i] = s_DefaultTangent;
87 this.triangles[index_X6 + 0] = index_X4 + 0;
88 this.triangles[index_X6 + 1] = index_X4 + 1;
89 this.triangles[index_X6 + 2] = index_X4 + 2;
90 this.triangles[index_X6 + 3] = index_X4 + 2;
91 this.triangles[index_X6 + 4] = index_X4 + 3;
92 this.triangles[index_X6 + 5] = index_X4 + 0;
99 this.mesh.vertices = this.vertices;
100 this.mesh.normals = this.normals;
101 this.mesh.tangents = this.tangents;
102 this.mesh.triangles = this.triangles;
103 this.mesh.bounds =
new Bounds(Vector3.zero,
new Vector3(3840, 2160, 0));
126 int s0 = !isVolumetric ? 4 : 8;
127 int s1 = !isVolumetric ? 6 : 36;
130 size = Mathf.Min(size, 65532 / s0);
132 int size_x_s0 = size * s0;
133 int size_x_s1 = size * s1;
135 this.vertexCount = 0;
137 this.vertices =
new Vector3[size_x_s0];
138 this.uvs0 =
new Vector2[size_x_s0];
139 this.uvs2 =
new Vector2[size_x_s0];
141 this.colors32 =
new Color32[size_x_s0];
143 this.normals =
new Vector3[size_x_s0];
144 this.tangents =
new Vector4[size_x_s0];
146 this.triangles =
new int[size_x_s1];
150 while (index_x_s0 / s0 < size)
152 for (
int i = 0; i < s0; i++)
154 this.vertices[index_x_s0 + i] = Vector3.zero;
155 this.uvs0[index_x_s0 + i] = Vector2.zero;
156 this.uvs2[index_x_s0 + i] = Vector2.zero;
158 this.colors32[index_x_s0 + i] = s_DefaultColor;
159 this.normals[index_x_s0 + i] = s_DefaultNormal;
160 this.tangents[index_x_s0 + i] = s_DefaultTangent;
164 this.triangles[index_x_s1 + 0] = index_x_s0 + 0;
165 this.triangles[index_x_s1 + 1] = index_x_s0 + 1;
166 this.triangles[index_x_s1 + 2] = index_x_s0 + 2;
167 this.triangles[index_x_s1 + 3] = index_x_s0 + 2;
168 this.triangles[index_x_s1 + 4] = index_x_s0 + 3;
169 this.triangles[index_x_s1 + 5] = index_x_s0 + 0;
174 this.triangles[index_x_s1 + 6] = index_x_s0 + 4;
175 this.triangles[index_x_s1 + 7] = index_x_s0 + 5;
176 this.triangles[index_x_s1 + 8] = index_x_s0 + 1;
177 this.triangles[index_x_s1 + 9] = index_x_s0 + 1;
178 this.triangles[index_x_s1 + 10] = index_x_s0 + 0;
179 this.triangles[index_x_s1 + 11] = index_x_s0 + 4;
182 this.triangles[index_x_s1 + 12] = index_x_s0 + 3;
183 this.triangles[index_x_s1 + 13] = index_x_s0 + 2;
184 this.triangles[index_x_s1 + 14] = index_x_s0 + 6;
185 this.triangles[index_x_s1 + 15] = index_x_s0 + 6;
186 this.triangles[index_x_s1 + 16] = index_x_s0 + 7;
187 this.triangles[index_x_s1 + 17] = index_x_s0 + 3;
190 this.triangles[index_x_s1 + 18] = index_x_s0 + 1;
191 this.triangles[index_x_s1 + 19] = index_x_s0 + 5;
192 this.triangles[index_x_s1 + 20] = index_x_s0 + 6;
193 this.triangles[index_x_s1 + 21] = index_x_s0 + 6;
194 this.triangles[index_x_s1 + 22] = index_x_s0 + 2;
195 this.triangles[index_x_s1 + 23] = index_x_s0 + 1;
198 this.triangles[index_x_s1 + 24] = index_x_s0 + 4;
199 this.triangles[index_x_s1 + 25] = index_x_s0 + 0;
200 this.triangles[index_x_s1 + 26] = index_x_s0 + 3;
201 this.triangles[index_x_s1 + 27] = index_x_s0 + 3;
202 this.triangles[index_x_s1 + 28] = index_x_s0 + 7;
203 this.triangles[index_x_s1 + 29] = index_x_s0 + 4;
206 this.triangles[index_x_s1 + 30] = index_x_s0 + 7;
207 this.triangles[index_x_s1 + 31] = index_x_s0 + 6;
208 this.triangles[index_x_s1 + 32] = index_x_s0 + 5;
209 this.triangles[index_x_s1 + 33] = index_x_s0 + 5;
210 this.triangles[index_x_s1 + 34] = index_x_s0 + 4;
211 this.triangles[index_x_s1 + 35] = index_x_s0 + 7;
219 this.mesh.vertices = this.vertices;
220 this.mesh.normals = this.normals;
221 this.mesh.tangents = this.tangents;
222 this.mesh.triangles = this.triangles;
223 this.mesh.bounds =
new Bounds(Vector3.zero,
new Vector3(3840, 2160, 64));
235 size = Mathf.Min(size, 16383);
237 int size_X4 = size * 4;
238 int size_X6 = size * 6;
240 int previousSize = this.vertices.Length / 4;
242 Array.Resize(ref this.vertices, size_X4);
243 Array.Resize(ref this.normals, size_X4);
244 Array.Resize(ref this.tangents, size_X4);
246 Array.Resize(ref this.uvs0, size_X4);
247 Array.Resize(ref this.uvs2, size_X4);
250 Array.Resize(ref this.colors32, size_X4);
252 Array.Resize(ref this.triangles, size_X6);
256 if (size <= previousSize)
258 this.mesh.triangles = this.triangles;
259 this.mesh.vertices = this.vertices;
260 this.mesh.normals = this.normals;
261 this.mesh.tangents = this.tangents;
266 for (
int i = previousSize; i < size; i++)
268 int index_X4 = i * 4;
269 int index_X6 = i * 6;
271 this.normals[0 + index_X4] = s_DefaultNormal;
272 this.normals[1 + index_X4] = s_DefaultNormal;
273 this.normals[2 + index_X4] = s_DefaultNormal;
274 this.normals[3 + index_X4] = s_DefaultNormal;
276 this.tangents[0 + index_X4] = s_DefaultTangent;
277 this.tangents[1 + index_X4] = s_DefaultTangent;
278 this.tangents[2 + index_X4] = s_DefaultTangent;
279 this.tangents[3 + index_X4] = s_DefaultTangent;
282 this.triangles[0 + index_X6] = 0 + index_X4;
283 this.triangles[1 + index_X6] = 1 + index_X4;
284 this.triangles[2 + index_X6] = 2 + index_X4;
285 this.triangles[3 + index_X6] = 2 + index_X4;
286 this.triangles[4 + index_X6] = 3 + index_X4;
287 this.triangles[5 + index_X6] = 0 + index_X4;
290 this.mesh.vertices = this.vertices;
291 this.mesh.normals = this.normals;
292 this.mesh.tangents = this.tangents;
293 this.mesh.triangles = this.triangles;
304 int s0 = !isVolumetric ? 4 : 8;
305 int s1 = !isVolumetric ? 6 : 36;
308 size = Mathf.Min(size, 65532 / s0);
310 int size_X4 = size * s0;
311 int size_X6 = size * s1;
313 int previousSize = this.vertices.Length / s0;
315 Array.Resize(ref this.vertices, size_X4);
316 Array.Resize(ref this.normals, size_X4);
317 Array.Resize(ref this.tangents, size_X4);
319 Array.Resize(ref this.uvs0, size_X4);
320 Array.Resize(ref this.uvs2, size_X4);
323 Array.Resize(ref this.colors32, size_X4);
325 Array.Resize(ref this.triangles, size_X6);
329 if (size <= previousSize)
331 this.mesh.triangles = this.triangles;
332 this.mesh.vertices = this.vertices;
333 this.mesh.normals = this.normals;
334 this.mesh.tangents = this.tangents;
339 for (
int i = previousSize; i < size; i++)
341 int index_X4 = i * s0;
342 int index_X6 = i * s1;
344 this.normals[0 + index_X4] = s_DefaultNormal;
345 this.normals[1 + index_X4] = s_DefaultNormal;
346 this.normals[2 + index_X4] = s_DefaultNormal;
347 this.normals[3 + index_X4] = s_DefaultNormal;
349 this.tangents[0 + index_X4] = s_DefaultTangent;
350 this.tangents[1 + index_X4] = s_DefaultTangent;
351 this.tangents[2 + index_X4] = s_DefaultTangent;
352 this.tangents[3 + index_X4] = s_DefaultTangent;
356 this.normals[4 + index_X4] = s_DefaultNormal;
357 this.normals[5 + index_X4] = s_DefaultNormal;
358 this.normals[6 + index_X4] = s_DefaultNormal;
359 this.normals[7 + index_X4] = s_DefaultNormal;
361 this.tangents[4 + index_X4] = s_DefaultTangent;
362 this.tangents[5 + index_X4] = s_DefaultTangent;
363 this.tangents[6 + index_X4] = s_DefaultTangent;
364 this.tangents[7 + index_X4] = s_DefaultTangent;
368 this.triangles[0 + index_X6] = 0 + index_X4;
369 this.triangles[1 + index_X6] = 1 + index_X4;
370 this.triangles[2 + index_X6] = 2 + index_X4;
371 this.triangles[3 + index_X6] = 2 + index_X4;
372 this.triangles[4 + index_X6] = 3 + index_X4;
373 this.triangles[5 + index_X6] = 0 + index_X4;
378 this.triangles[index_X6 + 6] = index_X4 + 4;
379 this.triangles[index_X6 + 7] = index_X4 + 5;
380 this.triangles[index_X6 + 8] = index_X4 + 1;
381 this.triangles[index_X6 + 9] = index_X4 + 1;
382 this.triangles[index_X6 + 10] = index_X4 + 0;
383 this.triangles[index_X6 + 11] = index_X4 + 4;
386 this.triangles[index_X6 + 12] = index_X4 + 3;
387 this.triangles[index_X6 + 13] = index_X4 + 2;
388 this.triangles[index_X6 + 14] = index_X4 + 6;
389 this.triangles[index_X6 + 15] = index_X4 + 6;
390 this.triangles[index_X6 + 16] = index_X4 + 7;
391 this.triangles[index_X6 + 17] = index_X4 + 3;
394 this.triangles[index_X6 + 18] = index_X4 + 1;
395 this.triangles[index_X6 + 19] = index_X4 + 5;
396 this.triangles[index_X6 + 20] = index_X4 + 6;
397 this.triangles[index_X6 + 21] = index_X4 + 6;
398 this.triangles[index_X6 + 22] = index_X4 + 2;
399 this.triangles[index_X6 + 23] = index_X4 + 1;
402 this.triangles[index_X6 + 24] = index_X4 + 4;
403 this.triangles[index_X6 + 25] = index_X4 + 0;
404 this.triangles[index_X6 + 26] = index_X4 + 3;
405 this.triangles[index_X6 + 27] = index_X4 + 3;
406 this.triangles[index_X6 + 28] = index_X4 + 7;
407 this.triangles[index_X6 + 29] = index_X4 + 4;
410 this.triangles[index_X6 + 30] = index_X4 + 7;
411 this.triangles[index_X6 + 31] = index_X4 + 6;
412 this.triangles[index_X6 + 32] = index_X4 + 5;
413 this.triangles[index_X6 + 33] = index_X4 + 5;
414 this.triangles[index_X6 + 34] = index_X4 + 4;
415 this.triangles[index_X6 + 35] = index_X4 + 7;
419 this.mesh.vertices = this.vertices;
420 this.mesh.normals = this.normals;
421 this.mesh.tangents = this.tangents;
422 this.mesh.triangles = this.triangles;
431 if (this.vertices ==
null)
return;
433 Array.Clear(this.vertices, 0, this.vertices.Length);
434 this.vertexCount = 0;
436 if (this.mesh !=
null)
437 this.mesh.vertices = this.vertices;
444 public void Clear(
bool uploadChanges)
446 if (this.vertices ==
null)
return;
448 Array.Clear(this.vertices, 0, this.vertices.Length);
449 this.vertexCount = 0;
451 if (uploadChanges && this.mesh !=
null)
452 this.mesh.vertices = this.vertices;
461 int length = vertices.Length - vertexCount;
464 Array.Clear(vertices, vertexCount, length);
474 int length = this.vertices.Length - startIndex;
477 Array.Clear(this.vertices, startIndex, length);
487 int length = this.vertices.Length - startIndex;
490 Array.Clear(this.vertices, startIndex, length);
492 if (updateMesh && mesh !=
null)
493 this.mesh.vertices = this.vertices;
497 public void SortGeometry (VertexSortingOrder order)
501 case VertexSortingOrder.Normal:
504 case VertexSortingOrder.Reverse:
505 int size = vertexCount / 4;
506 for (
int i = 0; i < size; i++)
509 int dst = (size - i - 1) * 4;
530 int indexCount = sortingOrder.Count;
532 if (indexCount * 4 > vertices.Length)
return;
536 for (
int dst_index = 0; dst_index < indexCount; dst_index++)
538 src_index = sortingOrder[dst_index];
540 while (src_index < dst_index)
542 src_index = sortingOrder[src_index];
546 if (src_index != dst_index)
566 vertex = vertices[dst_Index + 0];
567 vertices[dst_Index + 0] = vertices[src_Index + 0];
568 vertices[src_Index + 0] = vertex;
570 vertex = vertices[dst_Index + 1];
571 vertices[dst_Index + 1] = vertices[src_Index + 1];
572 vertices[src_Index + 1] = vertex;
574 vertex = vertices[dst_Index + 2];
575 vertices[dst_Index + 2] = vertices[src_Index + 2];
576 vertices[src_Index + 2] = vertex;
578 vertex = vertices[dst_Index + 3];
579 vertices[dst_Index + 3] = vertices[src_Index + 3];
580 vertices[src_Index + 3] = vertex;
585 uvs = uvs0[dst_Index + 0];
586 uvs0[dst_Index + 0] = uvs0[src_Index + 0];
587 uvs0[src_Index + 0] = uvs;
589 uvs = uvs0[dst_Index + 1];
590 uvs0[dst_Index + 1] = uvs0[src_Index + 1];
591 uvs0[src_Index + 1] = uvs;
593 uvs = uvs0[dst_Index + 2];
594 uvs0[dst_Index + 2] = uvs0[src_Index + 2];
595 uvs0[src_Index + 2] = uvs;
597 uvs = uvs0[dst_Index + 3];
598 uvs0[dst_Index + 3] = uvs0[src_Index + 3];
599 uvs0[src_Index + 3] = uvs;
602 uvs = uvs2[dst_Index + 0];
603 uvs2[dst_Index + 0] = uvs2[src_Index + 0];
604 uvs2[src_Index + 0] = uvs;
606 uvs = uvs2[dst_Index + 1];
607 uvs2[dst_Index + 1] = uvs2[src_Index + 1];
608 uvs2[src_Index + 1] = uvs;
610 uvs = uvs2[dst_Index + 2];
611 uvs2[dst_Index + 2] = uvs2[src_Index + 2];
612 uvs2[src_Index + 2] = uvs;
614 uvs = uvs2[dst_Index + 3];
615 uvs2[dst_Index + 3] = uvs2[src_Index + 3];
616 uvs2[src_Index + 3] = uvs;
620 color = colors32[dst_Index + 0];
621 colors32[dst_Index + 0] = colors32[src_Index + 0];
622 colors32[src_Index + 0] = color;
624 color = colors32[dst_Index + 1];
625 colors32[dst_Index + 1] = colors32[src_Index + 1];
626 colors32[src_Index + 1] = color;
628 color = colors32[dst_Index + 2];
629 colors32[dst_Index + 2] = colors32[src_Index + 2];
630 colors32[src_Index + 2] = color;
632 color = colors32[dst_Index + 3];
633 colors32[dst_Index + 3] = colors32[src_Index + 3];
634 colors32[src_Index + 3] = color;
void ClearUnusedVertices()
Function to clear the vertices while preserving the Triangles, Normals and Tangents.
TMP_MeshInfo(Mesh mesh, int size)
Function to pre-allocate vertex attributes for a mesh of size X.
void SwapVertexData(int src, int dst)
Method to swap the vertex attributes between src and dst quads.
void SortGeometry(IList< int > sortingOrder)
Function to rearrange the quads of the text object to change their rendering order.
void ResizeMeshInfo(int size)
Function to resized the content of MeshData and re-assign normals, tangents and triangles.
void ClearUnusedVertices(int startIndex, bool updateMesh)
Function used to mark unused vertices as degenerate an upload resulting data to the mesh.
void ClearUnusedVertices(int startIndex)
Function used to mark unused vertices as degenerate.
void Clear()
Function to clear the vertices while preserving the Triangles, Normals and Tangents.
TMP_MeshInfo(Mesh mesh, int size, bool isVolumetric)
Function to pre-allocate vertex attributes for a mesh of size X.
void ResizeMeshInfo(int size, bool isVolumetric)
Function to resized the content of MeshData and re-assign normals, tangents and triangles.
void Clear(bool uploadChanges)
Function to clear the vertices while preserving the Triangles, Normals and Tangents.
Structure which contains the vertex attributes (geometry) of the text object.