MeshAttachment.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using System;
  2. namespace Spine
  3. {
  4. public class MeshAttachment : Attachment
  5. {
  6. public MeshAttachment(string name) : base(name)
  7. {
  8. }
  9. public int HullLength { get; set; }
  10. public float[] Vertices
  11. {
  12. get
  13. {
  14. return this.vertices;
  15. }
  16. set
  17. {
  18. this.vertices = value;
  19. }
  20. }
  21. public float[] RegionUVs
  22. {
  23. get
  24. {
  25. return this.regionUVs;
  26. }
  27. set
  28. {
  29. this.regionUVs = value;
  30. }
  31. }
  32. public float[] UVs
  33. {
  34. get
  35. {
  36. return this.uvs;
  37. }
  38. set
  39. {
  40. this.uvs = value;
  41. }
  42. }
  43. public int[] Triangles
  44. {
  45. get
  46. {
  47. return this.triangles;
  48. }
  49. set
  50. {
  51. this.triangles = value;
  52. }
  53. }
  54. public float R
  55. {
  56. get
  57. {
  58. return this.r;
  59. }
  60. set
  61. {
  62. this.r = value;
  63. }
  64. }
  65. public float G
  66. {
  67. get
  68. {
  69. return this.g;
  70. }
  71. set
  72. {
  73. this.g = value;
  74. }
  75. }
  76. public float B
  77. {
  78. get
  79. {
  80. return this.b;
  81. }
  82. set
  83. {
  84. this.b = value;
  85. }
  86. }
  87. public float A
  88. {
  89. get
  90. {
  91. return this.a;
  92. }
  93. set
  94. {
  95. this.a = value;
  96. }
  97. }
  98. public string Path { get; set; }
  99. public object RendererObject { get; set; }
  100. public float RegionU { get; set; }
  101. public float RegionV { get; set; }
  102. public float RegionU2 { get; set; }
  103. public float RegionV2 { get; set; }
  104. public bool RegionRotate { get; set; }
  105. public float RegionOffsetX
  106. {
  107. get
  108. {
  109. return this.regionOffsetX;
  110. }
  111. set
  112. {
  113. this.regionOffsetX = value;
  114. }
  115. }
  116. public float RegionOffsetY
  117. {
  118. get
  119. {
  120. return this.regionOffsetY;
  121. }
  122. set
  123. {
  124. this.regionOffsetY = value;
  125. }
  126. }
  127. public float RegionWidth
  128. {
  129. get
  130. {
  131. return this.regionWidth;
  132. }
  133. set
  134. {
  135. this.regionWidth = value;
  136. }
  137. }
  138. public float RegionHeight
  139. {
  140. get
  141. {
  142. return this.regionHeight;
  143. }
  144. set
  145. {
  146. this.regionHeight = value;
  147. }
  148. }
  149. public float RegionOriginalWidth
  150. {
  151. get
  152. {
  153. return this.regionOriginalWidth;
  154. }
  155. set
  156. {
  157. this.regionOriginalWidth = value;
  158. }
  159. }
  160. public float RegionOriginalHeight
  161. {
  162. get
  163. {
  164. return this.regionOriginalHeight;
  165. }
  166. set
  167. {
  168. this.regionOriginalHeight = value;
  169. }
  170. }
  171. public int[] Edges { get; set; }
  172. public float Width { get; set; }
  173. public float Height { get; set; }
  174. public void UpdateUVs()
  175. {
  176. float regionU = this.RegionU;
  177. float regionV = this.RegionV;
  178. float num = this.RegionU2 - this.RegionU;
  179. float num2 = this.RegionV2 - this.RegionV;
  180. float[] array = this.regionUVs;
  181. if (this.uvs == null || this.uvs.Length != array.Length)
  182. {
  183. this.uvs = new float[array.Length];
  184. }
  185. float[] array2 = this.uvs;
  186. if (this.RegionRotate)
  187. {
  188. int i = 0;
  189. int num3 = array2.Length;
  190. while (i < num3)
  191. {
  192. array2[i] = regionU + array[i + 1] * num;
  193. array2[i + 1] = regionV + num2 - array[i] * num2;
  194. i += 2;
  195. }
  196. }
  197. else
  198. {
  199. int j = 0;
  200. int num4 = array2.Length;
  201. while (j < num4)
  202. {
  203. array2[j] = regionU + array[j] * num;
  204. array2[j + 1] = regionV + array[j + 1] * num2;
  205. j += 2;
  206. }
  207. }
  208. }
  209. public void ComputeWorldVertices(Slot slot, float[] worldVertices)
  210. {
  211. Bone bone = slot.bone;
  212. float num = bone.skeleton.x + bone.worldX;
  213. float num2 = bone.skeleton.y + bone.worldY;
  214. float m = bone.m00;
  215. float m2 = bone.m01;
  216. float m3 = bone.m10;
  217. float m4 = bone.m11;
  218. float[] attachmentVertices = this.vertices;
  219. int num3 = attachmentVertices.Length;
  220. if (slot.attachmentVerticesCount == num3)
  221. {
  222. attachmentVertices = slot.AttachmentVertices;
  223. }
  224. for (int i = 0; i < num3; i += 2)
  225. {
  226. float num4 = attachmentVertices[i];
  227. float num5 = attachmentVertices[i + 1];
  228. worldVertices[i] = num4 * m + num5 * m2 + num;
  229. worldVertices[i + 1] = num4 * m3 + num5 * m4 + num2;
  230. }
  231. }
  232. internal float[] vertices;
  233. internal float[] uvs;
  234. internal float[] regionUVs;
  235. internal int[] triangles;
  236. internal float regionOffsetX;
  237. internal float regionOffsetY;
  238. internal float regionWidth;
  239. internal float regionHeight;
  240. internal float regionOriginalWidth;
  241. internal float regionOriginalHeight;
  242. internal float r = 1f;
  243. internal float g = 1f;
  244. internal float b = 1f;
  245. internal float a = 1f;
  246. }
  247. }