TMP_MeshInfo.cs 24 KB

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