TMP_MeshInfo.cs 24 KB

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