SkinnedMeshAttachment.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class SkinnedMeshAttachment : Attachment
  6. {
  7. public SkinnedMeshAttachment(string name) : base(name)
  8. {
  9. }
  10. public int HullLength { get; set; }
  11. public int[] Bones
  12. {
  13. get
  14. {
  15. return this.bones;
  16. }
  17. set
  18. {
  19. this.bones = value;
  20. }
  21. }
  22. public float[] Weights
  23. {
  24. get
  25. {
  26. return this.weights;
  27. }
  28. set
  29. {
  30. this.weights = value;
  31. }
  32. }
  33. public float[] RegionUVs
  34. {
  35. get
  36. {
  37. return this.regionUVs;
  38. }
  39. set
  40. {
  41. this.regionUVs = value;
  42. }
  43. }
  44. public float[] UVs
  45. {
  46. get
  47. {
  48. return this.uvs;
  49. }
  50. set
  51. {
  52. this.uvs = value;
  53. }
  54. }
  55. public int[] Triangles
  56. {
  57. get
  58. {
  59. return this.triangles;
  60. }
  61. set
  62. {
  63. this.triangles = value;
  64. }
  65. }
  66. public float R
  67. {
  68. get
  69. {
  70. return this.r;
  71. }
  72. set
  73. {
  74. this.r = value;
  75. }
  76. }
  77. public float G
  78. {
  79. get
  80. {
  81. return this.g;
  82. }
  83. set
  84. {
  85. this.g = value;
  86. }
  87. }
  88. public float B
  89. {
  90. get
  91. {
  92. return this.b;
  93. }
  94. set
  95. {
  96. this.b = value;
  97. }
  98. }
  99. public float A
  100. {
  101. get
  102. {
  103. return this.a;
  104. }
  105. set
  106. {
  107. this.a = value;
  108. }
  109. }
  110. public string Path { get; set; }
  111. public object RendererObject { get; set; }
  112. public float RegionU { get; set; }
  113. public float RegionV { get; set; }
  114. public float RegionU2 { get; set; }
  115. public float RegionV2 { get; set; }
  116. public bool RegionRotate { get; set; }
  117. public float RegionOffsetX
  118. {
  119. get
  120. {
  121. return this.regionOffsetX;
  122. }
  123. set
  124. {
  125. this.regionOffsetX = value;
  126. }
  127. }
  128. public float RegionOffsetY
  129. {
  130. get
  131. {
  132. return this.regionOffsetY;
  133. }
  134. set
  135. {
  136. this.regionOffsetY = value;
  137. }
  138. }
  139. public float RegionWidth
  140. {
  141. get
  142. {
  143. return this.regionWidth;
  144. }
  145. set
  146. {
  147. this.regionWidth = value;
  148. }
  149. }
  150. public float RegionHeight
  151. {
  152. get
  153. {
  154. return this.regionHeight;
  155. }
  156. set
  157. {
  158. this.regionHeight = value;
  159. }
  160. }
  161. public float RegionOriginalWidth
  162. {
  163. get
  164. {
  165. return this.regionOriginalWidth;
  166. }
  167. set
  168. {
  169. this.regionOriginalWidth = value;
  170. }
  171. }
  172. public float RegionOriginalHeight
  173. {
  174. get
  175. {
  176. return this.regionOriginalHeight;
  177. }
  178. set
  179. {
  180. this.regionOriginalHeight = value;
  181. }
  182. }
  183. public int[] Edges { get; set; }
  184. public float Width { get; set; }
  185. public float Height { get; set; }
  186. public void UpdateUVs()
  187. {
  188. float regionU = this.RegionU;
  189. float regionV = this.RegionV;
  190. float num = this.RegionU2 - this.RegionU;
  191. float num2 = this.RegionV2 - this.RegionV;
  192. float[] array = this.regionUVs;
  193. if (this.uvs == null || this.uvs.Length != array.Length)
  194. {
  195. this.uvs = new float[array.Length];
  196. }
  197. float[] array2 = this.uvs;
  198. if (this.RegionRotate)
  199. {
  200. int i = 0;
  201. int num3 = array2.Length;
  202. while (i < num3)
  203. {
  204. array2[i] = regionU + array[i + 1] * num;
  205. array2[i + 1] = regionV + num2 - array[i] * num2;
  206. i += 2;
  207. }
  208. }
  209. else
  210. {
  211. int j = 0;
  212. int num4 = array2.Length;
  213. while (j < num4)
  214. {
  215. array2[j] = regionU + array[j] * num;
  216. array2[j + 1] = regionV + array[j + 1] * num2;
  217. j += 2;
  218. }
  219. }
  220. }
  221. public void ComputeWorldVertices(Slot slot, float[] worldVertices)
  222. {
  223. Skeleton skeleton = slot.bone.skeleton;
  224. List<Bone> list = skeleton.bones;
  225. float x = skeleton.x;
  226. float y = skeleton.y;
  227. float[] array = this.weights;
  228. int[] array2 = this.bones;
  229. if (slot.attachmentVerticesCount == 0)
  230. {
  231. int num = 0;
  232. int i = 0;
  233. int num2 = 0;
  234. int num3 = array2.Length;
  235. while (i < num3)
  236. {
  237. float num4 = 0f;
  238. float num5 = 0f;
  239. int num6 = array2[i++] + i;
  240. while (i < num6)
  241. {
  242. Bone bone = list[array2[i]];
  243. float num7 = array[num2];
  244. float num8 = array[num2 + 1];
  245. float num9 = array[num2 + 2];
  246. num4 += (num7 * bone.m00 + num8 * bone.m01 + bone.worldX) * num9;
  247. num5 += (num7 * bone.m10 + num8 * bone.m11 + bone.worldY) * num9;
  248. i++;
  249. num2 += 3;
  250. }
  251. worldVertices[num] = num4 + x;
  252. worldVertices[num + 1] = num5 + y;
  253. num += 2;
  254. }
  255. }
  256. else
  257. {
  258. float[] attachmentVertices = slot.AttachmentVertices;
  259. int num10 = 0;
  260. int j = 0;
  261. int num11 = 0;
  262. int num12 = 0;
  263. int num13 = array2.Length;
  264. while (j < num13)
  265. {
  266. float num14 = 0f;
  267. float num15 = 0f;
  268. int num16 = array2[j++] + j;
  269. while (j < num16)
  270. {
  271. Bone bone2 = list[array2[j]];
  272. float num17 = array[num11] + attachmentVertices[num12];
  273. float num18 = array[num11 + 1] + attachmentVertices[num12 + 1];
  274. float num19 = array[num11 + 2];
  275. num14 += (num17 * bone2.m00 + num18 * bone2.m01 + bone2.worldX) * num19;
  276. num15 += (num17 * bone2.m10 + num18 * bone2.m11 + bone2.worldY) * num19;
  277. j++;
  278. num11 += 3;
  279. num12 += 2;
  280. }
  281. worldVertices[num10] = num14 + x;
  282. worldVertices[num10 + 1] = num15 + y;
  283. num10 += 2;
  284. }
  285. }
  286. }
  287. internal int[] bones;
  288. internal float[] weights;
  289. internal float[] uvs;
  290. internal float[] regionUVs;
  291. internal int[] triangles;
  292. internal float regionOffsetX;
  293. internal float regionOffsetY;
  294. internal float regionWidth;
  295. internal float regionHeight;
  296. internal float regionOriginalWidth;
  297. internal float regionOriginalHeight;
  298. internal float r = 1f;
  299. internal float g = 1f;
  300. internal float b = 1f;
  301. internal float a = 1f;
  302. }
  303. }