You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

664 lines
24 KiB

  1. using UnityEngine;
  2. using System;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. namespace TMPro
  7. {
  8. public enum VertexSortingOrder { Normal, Reverse };
  9. /// <summary>
  10. /// Structure which contains the vertex attributes (geometry) of the text object.
  11. /// </summary>
  12. public struct TMP_MeshInfo
  13. {
  14. private static readonly Color32 s_DefaultColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
  15. private static readonly Vector3 s_DefaultNormal = new Vector3(0.0f, 0.0f, -1f);
  16. private static readonly Vector4 s_DefaultTangent = new Vector4(-1f, 0.0f, 0.0f, 1f);
  17. public Mesh mesh;
  18. public int vertexCount;
  19. public Vector3[] vertices;
  20. public Vector3[] normals;
  21. public Vector4[] tangents;
  22. public Vector2[] uvs0;
  23. public Vector2[] uvs2;
  24. //public Vector2[] uvs4;
  25. public Color32[] colors32;
  26. public int[] triangles;
  27. /// <summary>
  28. /// Function to pre-allocate vertex attributes for a mesh of size X.
  29. /// </summary>
  30. /// <param name="mesh"></param>
  31. /// <param name="size"></param>
  32. public TMP_MeshInfo(Mesh mesh, int size)
  33. {
  34. // Reference to the TMP Text Component.
  35. //this.textComponent = null;
  36. // Clear existing mesh data
  37. if (mesh == null)
  38. mesh = new Mesh();
  39. else
  40. mesh.Clear();
  41. this.mesh = mesh;
  42. // Limit the mesh to less than 65535 vertices which is the limit for Unity's Mesh.
  43. size = Mathf.Min(size, 16383);
  44. int sizeX4 = size * 4;
  45. int sizeX6 = size * 6;
  46. this.vertexCount = 0;
  47. this.vertices = new Vector3[sizeX4];
  48. this.uvs0 = new Vector2[sizeX4];
  49. this.uvs2 = new Vector2[sizeX4];
  50. //this.uvs4 = new Vector2[sizeX4]; // SDF scale data
  51. this.colors32 = new Color32[sizeX4];
  52. this.normals = new Vector3[sizeX4];
  53. this.tangents = new Vector4[sizeX4];
  54. this.triangles = new int[sizeX6];
  55. int index_X6 = 0;
  56. int index_X4 = 0;
  57. while (index_X4 / 4 < size)
  58. {
  59. for (int i = 0; i < 4; i++)
  60. {
  61. this.vertices[index_X4 + i] = Vector3.zero;
  62. this.uvs0[index_X4 + i] = Vector2.zero;
  63. this.uvs2[index_X4 + i] = Vector2.zero;
  64. //this.uvs4[index_X4 + i] = Vector2.zero;
  65. this.colors32[index_X4 + i] = s_DefaultColor;
  66. this.normals[index_X4 + i] = s_DefaultNormal;
  67. this.tangents[index_X4 + i] = s_DefaultTangent;
  68. }
  69. this.triangles[index_X6 + 0] = index_X4 + 0;
  70. this.triangles[index_X6 + 1] = index_X4 + 1;
  71. this.triangles[index_X6 + 2] = index_X4 + 2;
  72. this.triangles[index_X6 + 3] = index_X4 + 2;
  73. this.triangles[index_X6 + 4] = index_X4 + 3;
  74. this.triangles[index_X6 + 5] = index_X4 + 0;
  75. index_X4 += 4;
  76. index_X6 += 6;
  77. }
  78. // Pre-assign base vertex attributes.
  79. this.mesh.vertices = this.vertices;
  80. this.mesh.normals = this.normals;
  81. this.mesh.tangents = this.tangents;
  82. this.mesh.triangles = this.triangles;
  83. this.mesh.bounds = new Bounds(Vector3.zero, new Vector3(3840, 2160, 0));
  84. }
  85. /// <summary>
  86. /// Function to pre-allocate vertex attributes for a mesh of size X.
  87. /// </summary>
  88. /// <param name="mesh"></param>
  89. /// <param name="size"></param>
  90. /// <param name="isVolumetric"></param>
  91. public TMP_MeshInfo(Mesh mesh, int size, bool isVolumetric)
  92. {
  93. // Reference to the TMP Text Component.
  94. //this.textComponent = null;
  95. // Clear existing mesh data
  96. if (mesh == null)
  97. mesh = new Mesh();
  98. else
  99. mesh.Clear();
  100. this.mesh = mesh;
  101. int s0 = !isVolumetric ? 4 : 8;
  102. int s1 = !isVolumetric ? 6 : 36;
  103. // Limit the mesh to less than 65535 vertices which is the limit for Unity's Mesh.
  104. size = Mathf.Min(size, 65532 / s0);
  105. int size_x_s0 = size * s0;
  106. int size_x_s1 = size * s1;
  107. this.vertexCount = 0;
  108. this.vertices = new Vector3[size_x_s0];
  109. this.uvs0 = new Vector2[size_x_s0];
  110. this.uvs2 = new Vector2[size_x_s0];
  111. //this.uvs4 = new Vector2[sizeX8]; // SDF scale data
  112. this.colors32 = new Color32[size_x_s0];
  113. this.normals = new Vector3[size_x_s0];
  114. this.tangents = new Vector4[size_x_s0];
  115. this.triangles = new int[size_x_s1];
  116. int index_x_s0 = 0;
  117. int index_x_s1 = 0;
  118. while (index_x_s0 / s0 < size)
  119. {
  120. for (int i = 0; i < s0; i++)
  121. {
  122. this.vertices[index_x_s0 + i] = Vector3.zero;
  123. this.uvs0[index_x_s0 + i] = Vector2.zero;
  124. this.uvs2[index_x_s0 + i] = Vector2.zero;
  125. //this.uvs4[index_X4 + i] = Vector2.zero;
  126. this.colors32[index_x_s0 + i] = s_DefaultColor;
  127. this.normals[index_x_s0 + i] = s_DefaultNormal;
  128. this.tangents[index_x_s0 + i] = s_DefaultTangent;
  129. }
  130. // Front Face
  131. this.triangles[index_x_s1 + 0] = index_x_s0 + 0;
  132. this.triangles[index_x_s1 + 1] = index_x_s0 + 1;
  133. this.triangles[index_x_s1 + 2] = index_x_s0 + 2;
  134. this.triangles[index_x_s1 + 3] = index_x_s0 + 2;
  135. this.triangles[index_x_s1 + 4] = index_x_s0 + 3;
  136. this.triangles[index_x_s1 + 5] = index_x_s0 + 0;
  137. if (isVolumetric)
  138. {
  139. // Left Face
  140. this.triangles[index_x_s1 + 6] = index_x_s0 + 4;
  141. this.triangles[index_x_s1 + 7] = index_x_s0 + 5;
  142. this.triangles[index_x_s1 + 8] = index_x_s0 + 1;
  143. this.triangles[index_x_s1 + 9] = index_x_s0 + 1;
  144. this.triangles[index_x_s1 + 10] = index_x_s0 + 0;
  145. this.triangles[index_x_s1 + 11] = index_x_s0 + 4;
  146. // Right Face
  147. this.triangles[index_x_s1 + 12] = index_x_s0 + 3;
  148. this.triangles[index_x_s1 + 13] = index_x_s0 + 2;
  149. this.triangles[index_x_s1 + 14] = index_x_s0 + 6;
  150. this.triangles[index_x_s1 + 15] = index_x_s0 + 6;
  151. this.triangles[index_x_s1 + 16] = index_x_s0 + 7;
  152. this.triangles[index_x_s1 + 17] = index_x_s0 + 3;
  153. // Top Face
  154. this.triangles[index_x_s1 + 18] = index_x_s0 + 1;
  155. this.triangles[index_x_s1 + 19] = index_x_s0 + 5;
  156. this.triangles[index_x_s1 + 20] = index_x_s0 + 6;
  157. this.triangles[index_x_s1 + 21] = index_x_s0 + 6;
  158. this.triangles[index_x_s1 + 22] = index_x_s0 + 2;
  159. this.triangles[index_x_s1 + 23] = index_x_s0 + 1;
  160. // Bottom Face
  161. this.triangles[index_x_s1 + 24] = index_x_s0 + 4;
  162. this.triangles[index_x_s1 + 25] = index_x_s0 + 0;
  163. this.triangles[index_x_s1 + 26] = index_x_s0 + 3;
  164. this.triangles[index_x_s1 + 27] = index_x_s0 + 3;
  165. this.triangles[index_x_s1 + 28] = index_x_s0 + 7;
  166. this.triangles[index_x_s1 + 29] = index_x_s0 + 4;
  167. // Back Face
  168. this.triangles[index_x_s1 + 30] = index_x_s0 + 7;
  169. this.triangles[index_x_s1 + 31] = index_x_s0 + 6;
  170. this.triangles[index_x_s1 + 32] = index_x_s0 + 5;
  171. this.triangles[index_x_s1 + 33] = index_x_s0 + 5;
  172. this.triangles[index_x_s1 + 34] = index_x_s0 + 4;
  173. this.triangles[index_x_s1 + 35] = index_x_s0 + 7;
  174. }
  175. index_x_s0 += s0;
  176. index_x_s1 += s1;
  177. }
  178. // Pre-assign base vertex attributes.
  179. this.mesh.vertices = this.vertices;
  180. this.mesh.normals = this.normals;
  181. this.mesh.tangents = this.tangents;
  182. this.mesh.triangles = this.triangles;
  183. this.mesh.bounds = new Bounds(Vector3.zero, new Vector3(3840, 2160, 64));
  184. }
  185. /// <summary>
  186. /// Function to resized the content of MeshData and re-assign normals, tangents and triangles.
  187. /// </summary>
  188. /// <param name="meshData"></param>
  189. /// <param name="size"></param>
  190. public void ResizeMeshInfo(int size)
  191. {
  192. // Limit the mesh to less than 65535 vertices which is the limit for Unity's Mesh.
  193. size = Mathf.Min(size, 16383);
  194. int size_X4 = size * 4;
  195. int size_X6 = size * 6;
  196. int previousSize = this.vertices.Length / 4;
  197. Array.Resize(ref this.vertices, size_X4);
  198. Array.Resize(ref this.normals, size_X4);
  199. Array.Resize(ref this.tangents, size_X4);
  200. Array.Resize(ref this.uvs0, size_X4);
  201. Array.Resize(ref this.uvs2, size_X4);
  202. //Array.Resize(ref this.uvs4, size_X4);
  203. Array.Resize(ref this.colors32, size_X4);
  204. Array.Resize(ref this.triangles, size_X6);
  205. // Re-assign Normals, Tangents and Triangles
  206. if (size <= previousSize)
  207. {
  208. this.mesh.triangles = this.triangles;
  209. this.mesh.vertices = this.vertices;
  210. this.mesh.normals = this.normals;
  211. this.mesh.tangents = this.tangents;
  212. return;
  213. }
  214. for (int i = previousSize; i < size; i++)
  215. {
  216. int index_X4 = i * 4;
  217. int index_X6 = i * 6;
  218. this.normals[0 + index_X4] = s_DefaultNormal;
  219. this.normals[1 + index_X4] = s_DefaultNormal;
  220. this.normals[2 + index_X4] = s_DefaultNormal;
  221. this.normals[3 + index_X4] = s_DefaultNormal;
  222. this.tangents[0 + index_X4] = s_DefaultTangent;
  223. this.tangents[1 + index_X4] = s_DefaultTangent;
  224. this.tangents[2 + index_X4] = s_DefaultTangent;
  225. this.tangents[3 + index_X4] = s_DefaultTangent;
  226. // Setup Triangles
  227. this.triangles[0 + index_X6] = 0 + index_X4;
  228. this.triangles[1 + index_X6] = 1 + index_X4;
  229. this.triangles[2 + index_X6] = 2 + index_X4;
  230. this.triangles[3 + index_X6] = 2 + index_X4;
  231. this.triangles[4 + index_X6] = 3 + index_X4;
  232. this.triangles[5 + index_X6] = 0 + index_X4;
  233. }
  234. this.mesh.vertices = this.vertices;
  235. this.mesh.normals = this.normals;
  236. this.mesh.tangents = this.tangents;
  237. this.mesh.triangles = this.triangles;
  238. }
  239. /// <summary>
  240. /// Function to resized the content of MeshData and re-assign normals, tangents and triangles.
  241. /// </summary>
  242. /// <param name="size"></param>
  243. /// <param name="isVolumetric"></param>
  244. public void ResizeMeshInfo(int size, bool isVolumetric)
  245. {
  246. int s0 = !isVolumetric ? 4 : 8;
  247. int s1 = !isVolumetric ? 6 : 36;
  248. // Limit the mesh to less than 65535 vertices which is the limit for Unity's Mesh.
  249. size = Mathf.Min(size, 65532 / s0);
  250. int size_X4 = size * s0;
  251. int size_X6 = size * s1;
  252. int previousSize = this.vertices.Length / s0;
  253. Array.Resize(ref this.vertices, size_X4);
  254. Array.Resize(ref this.normals, size_X4);
  255. Array.Resize(ref this.tangents, size_X4);
  256. Array.Resize(ref this.uvs0, size_X4);
  257. Array.Resize(ref this.uvs2, size_X4);
  258. //Array.Resize(ref this.uvs4, size_X4);
  259. Array.Resize(ref this.colors32, size_X4);
  260. Array.Resize(ref this.triangles, size_X6);
  261. // Re-assign Normals, Tangents and Triangles
  262. if (size <= previousSize)
  263. {
  264. this.mesh.triangles = this.triangles;
  265. this.mesh.vertices = this.vertices;
  266. this.mesh.normals = this.normals;
  267. this.mesh.tangents = this.tangents;
  268. return;
  269. }
  270. for (int i = previousSize; i < size; i++)
  271. {
  272. int index_X4 = i * s0;
  273. int index_X6 = i * s1;
  274. this.normals[0 + index_X4] = s_DefaultNormal;
  275. this.normals[1 + index_X4] = s_DefaultNormal;
  276. this.normals[2 + index_X4] = s_DefaultNormal;
  277. this.normals[3 + index_X4] = s_DefaultNormal;
  278. this.tangents[0 + index_X4] = s_DefaultTangent;
  279. this.tangents[1 + index_X4] = s_DefaultTangent;
  280. this.tangents[2 + index_X4] = s_DefaultTangent;
  281. this.tangents[3 + index_X4] = s_DefaultTangent;
  282. if (isVolumetric)
  283. {
  284. this.normals[4 + index_X4] = s_DefaultNormal;
  285. this.normals[5 + index_X4] = s_DefaultNormal;
  286. this.normals[6 + index_X4] = s_DefaultNormal;
  287. this.normals[7 + index_X4] = s_DefaultNormal;
  288. this.tangents[4 + index_X4] = s_DefaultTangent;
  289. this.tangents[5 + index_X4] = s_DefaultTangent;
  290. this.tangents[6 + index_X4] = s_DefaultTangent;
  291. this.tangents[7 + index_X4] = s_DefaultTangent;
  292. }
  293. // Setup Triangles
  294. this.triangles[0 + index_X6] = 0 + index_X4;
  295. this.triangles[1 + index_X6] = 1 + index_X4;
  296. this.triangles[2 + index_X6] = 2 + index_X4;
  297. this.triangles[3 + index_X6] = 2 + index_X4;
  298. this.triangles[4 + index_X6] = 3 + index_X4;
  299. this.triangles[5 + index_X6] = 0 + index_X4;
  300. if (isVolumetric)
  301. {
  302. // Left Face
  303. this.triangles[index_X6 + 6] = index_X4 + 4;
  304. this.triangles[index_X6 + 7] = index_X4 + 5;
  305. this.triangles[index_X6 + 8] = index_X4 + 1;
  306. this.triangles[index_X6 + 9] = index_X4 + 1;
  307. this.triangles[index_X6 + 10] = index_X4 + 0;
  308. this.triangles[index_X6 + 11] = index_X4 + 4;
  309. // Right Face
  310. this.triangles[index_X6 + 12] = index_X4 + 3;
  311. this.triangles[index_X6 + 13] = index_X4 + 2;
  312. this.triangles[index_X6 + 14] = index_X4 + 6;
  313. this.triangles[index_X6 + 15] = index_X4 + 6;
  314. this.triangles[index_X6 + 16] = index_X4 + 7;
  315. this.triangles[index_X6 + 17] = index_X4 + 3;
  316. // Top Face
  317. this.triangles[index_X6 + 18] = index_X4 + 1;
  318. this.triangles[index_X6 + 19] = index_X4 + 5;
  319. this.triangles[index_X6 + 20] = index_X4 + 6;
  320. this.triangles[index_X6 + 21] = index_X4 + 6;
  321. this.triangles[index_X6 + 22] = index_X4 + 2;
  322. this.triangles[index_X6 + 23] = index_X4 + 1;
  323. // Bottom Face
  324. this.triangles[index_X6 + 24] = index_X4 + 4;
  325. this.triangles[index_X6 + 25] = index_X4 + 0;
  326. this.triangles[index_X6 + 26] = index_X4 + 3;
  327. this.triangles[index_X6 + 27] = index_X4 + 3;
  328. this.triangles[index_X6 + 28] = index_X4 + 7;
  329. this.triangles[index_X6 + 29] = index_X4 + 4;
  330. // Back Face
  331. this.triangles[index_X6 + 30] = index_X4 + 7;
  332. this.triangles[index_X6 + 31] = index_X4 + 6;
  333. this.triangles[index_X6 + 32] = index_X4 + 5;
  334. this.triangles[index_X6 + 33] = index_X4 + 5;
  335. this.triangles[index_X6 + 34] = index_X4 + 4;
  336. this.triangles[index_X6 + 35] = index_X4 + 7;
  337. }
  338. }
  339. this.mesh.vertices = this.vertices;
  340. this.mesh.normals = this.normals;
  341. this.mesh.tangents = this.tangents;
  342. this.mesh.triangles = this.triangles;
  343. }
  344. /// <summary>
  345. /// Function to clear the vertices while preserving the Triangles, Normals and Tangents.
  346. /// </summary>
  347. public void Clear()
  348. {
  349. if (this.vertices == null) return;
  350. Array.Clear(this.vertices, 0, this.vertices.Length);
  351. this.vertexCount = 0;
  352. if (this.mesh != null)
  353. this.mesh.vertices = this.vertices;
  354. }
  355. /// <summary>
  356. /// Function to clear the vertices while preserving the Triangles, Normals and Tangents.
  357. /// </summary>
  358. public void Clear(bool uploadChanges)
  359. {
  360. if (this.vertices == null) return;
  361. Array.Clear(this.vertices, 0, this.vertices.Length);
  362. this.vertexCount = 0;
  363. if (uploadChanges && this.mesh != null)
  364. this.mesh.vertices = this.vertices;
  365. }
  366. /// <summary>
  367. /// Function to clear the vertices while preserving the Triangles, Normals and Tangents.
  368. /// </summary>
  369. public void ClearUnusedVertices()
  370. {
  371. int length = vertices.Length - vertexCount;
  372. if (length > 0)
  373. Array.Clear(vertices, vertexCount, length);
  374. }
  375. /// <summary>
  376. /// Function used to mark unused vertices as degenerate.
  377. /// </summary>
  378. /// <param name="startIndex"></param>
  379. public void ClearUnusedVertices(int startIndex)
  380. {
  381. int length = this.vertices.Length - startIndex;
  382. if (length > 0)
  383. Array.Clear(this.vertices, startIndex, length);
  384. }
  385. /// <summary>
  386. /// Function used to mark unused vertices as degenerate an upload resulting data to the mesh.
  387. /// </summary>
  388. /// <param name="startIndex"></param>
  389. public void ClearUnusedVertices(int startIndex, bool updateMesh)
  390. {
  391. int length = this.vertices.Length - startIndex;
  392. if (length > 0)
  393. Array.Clear(this.vertices, startIndex, length);
  394. if (updateMesh && mesh != null)
  395. this.mesh.vertices = this.vertices;
  396. }
  397. public void SortGeometry (VertexSortingOrder order)
  398. {
  399. switch (order)
  400. {
  401. case VertexSortingOrder.Normal:
  402. // Do nothing
  403. break;
  404. case VertexSortingOrder.Reverse:
  405. int size = vertexCount / 4;
  406. for (int i = 0; i < size; i++)
  407. {
  408. int src = i * 4;
  409. int dst = (size - i - 1) * 4;
  410. if (src < dst)
  411. SwapVertexData(src, dst);
  412. }
  413. break;
  414. //case VertexSortingOrder.Depth:
  415. // break;
  416. }
  417. }
  418. /// <summary>
  419. /// Function to rearrange the quads of the text object to change their rendering order.
  420. /// </summary>
  421. /// <param name="sortingOrder"></param>
  422. public void SortGeometry(IList<int> sortingOrder)
  423. {
  424. // Make sure the sorting order array is not larger than the vertices array.
  425. int indexCount = sortingOrder.Count;
  426. if (indexCount * 4 > vertices.Length) return;
  427. int src_index;
  428. for (int dst_index = 0; dst_index < indexCount; dst_index++)
  429. {
  430. src_index = sortingOrder[dst_index];
  431. while (src_index < dst_index)
  432. {
  433. src_index = sortingOrder[src_index];
  434. }
  435. // Swap items
  436. if (src_index != dst_index)
  437. SwapVertexData(src_index * 4, dst_index * 4);
  438. //Debug.Log("Swap element [" + dst_index + "] with [" + src_index + "]. Vertex[" + dst_index + "] is " + vertices[dst_index * 4].z);
  439. }
  440. }
  441. /// <summary>
  442. /// Method to swap the vertex attributes between src and dst quads.
  443. /// </summary>
  444. /// <param name="src">Index of the first vertex attribute of the source character / quad.</param>
  445. /// <param name="dst">Index of the first vertex attribute of the destination character / quad.</param>
  446. public void SwapVertexData(int src, int dst)
  447. {
  448. int src_Index = src; // * 4;
  449. int dst_Index = dst; // * 4;
  450. // Swap vertices
  451. Vector3 vertex;
  452. vertex = vertices[dst_Index + 0];
  453. vertices[dst_Index + 0] = vertices[src_Index + 0];
  454. vertices[src_Index + 0] = vertex;
  455. vertex = vertices[dst_Index + 1];
  456. vertices[dst_Index + 1] = vertices[src_Index + 1];
  457. vertices[src_Index + 1] = vertex;
  458. vertex = vertices[dst_Index + 2];
  459. vertices[dst_Index + 2] = vertices[src_Index + 2];
  460. vertices[src_Index + 2] = vertex;
  461. vertex = vertices[dst_Index + 3];
  462. vertices[dst_Index + 3] = vertices[src_Index + 3];
  463. vertices[src_Index + 3] = vertex;
  464. //Swap UVs0
  465. Vector2 uvs;
  466. uvs = uvs0[dst_Index + 0];
  467. uvs0[dst_Index + 0] = uvs0[src_Index + 0];
  468. uvs0[src_Index + 0] = uvs;
  469. uvs = uvs0[dst_Index + 1];
  470. uvs0[dst_Index + 1] = uvs0[src_Index + 1];
  471. uvs0[src_Index + 1] = uvs;
  472. uvs = uvs0[dst_Index + 2];
  473. uvs0[dst_Index + 2] = uvs0[src_Index + 2];
  474. uvs0[src_Index + 2] = uvs;
  475. uvs = uvs0[dst_Index + 3];
  476. uvs0[dst_Index + 3] = uvs0[src_Index + 3];
  477. uvs0[src_Index + 3] = uvs;
  478. // Swap UVs2
  479. uvs = uvs2[dst_Index + 0];
  480. uvs2[dst_Index + 0] = uvs2[src_Index + 0];
  481. uvs2[src_Index + 0] = uvs;
  482. uvs = uvs2[dst_Index + 1];
  483. uvs2[dst_Index + 1] = uvs2[src_Index + 1];
  484. uvs2[src_Index + 1] = uvs;
  485. uvs = uvs2[dst_Index + 2];
  486. uvs2[dst_Index + 2] = uvs2[src_Index + 2];
  487. uvs2[src_Index + 2] = uvs;
  488. uvs = uvs2[dst_Index + 3];
  489. uvs2[dst_Index + 3] = uvs2[src_Index + 3];
  490. uvs2[src_Index + 3] = uvs;
  491. // Vertex Colors
  492. Color32 color;
  493. color = colors32[dst_Index + 0];
  494. colors32[dst_Index + 0] = colors32[src_Index + 0];
  495. colors32[src_Index + 0] = color;
  496. color = colors32[dst_Index + 1];
  497. colors32[dst_Index + 1] = colors32[src_Index + 1];
  498. colors32[src_Index + 1] = color;
  499. color = colors32[dst_Index + 2];
  500. colors32[dst_Index + 2] = colors32[src_Index + 2];
  501. colors32[src_Index + 2] = color;
  502. color = colors32[dst_Index + 3];
  503. colors32[dst_Index + 3] = colors32[src_Index + 3];
  504. colors32[src_Index + 3] = color;
  505. }
  506. //int Partition (int start, int end)
  507. //{
  508. // float pivot = vertices[end].z;
  509. // int partitionIndex = start;
  510. // for (int i = start; i < end; i++)
  511. // {
  512. // if (vertices[i].z <= pivot)
  513. // {
  514. // Swap(vertices[i], vertices[partitionIndex]);
  515. // partitionIndex += 1;
  516. // }
  517. // }
  518. // Swap(vertices[partitionIndex], vertices[end]);
  519. // return partitionIndex;
  520. //}
  521. //void Swap(Vector3 a, Vector3 b)
  522. //{
  523. // Vector3 temp = a;
  524. // a = b;
  525. // b = a;
  526. //}
  527. }
  528. }