No Description
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.

TMP_MeshInfo.cs 25KB

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