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 24KB

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