spine-webgl

spine webgl

目前为 2022-09-06 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/450822/1090441/spine-webgl.js

  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. var spine;
  12. (function (spine) {
  13. var Animation = (function () {
  14. function Animation(name, timelines, duration) {
  15. if (name == null)
  16. throw new Error("name cannot be null.");
  17. if (timelines == null)
  18. throw new Error("timelines cannot be null.");
  19. this.name = name;
  20. this.timelines = timelines;
  21. this.duration = duration;
  22. }
  23. Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
  24. if (skeleton == null)
  25. throw new Error("skeleton cannot be null.");
  26. if (loop && this.duration != 0) {
  27. time %= this.duration;
  28. if (lastTime > 0)
  29. lastTime %= this.duration;
  30. }
  31. var timelines = this.timelines;
  32. for (var i = 0, n = timelines.length; i < n; i++)
  33. timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
  34. };
  35. Animation.binarySearch = function (values, target, step) {
  36. if (step === void 0) { step = 1; }
  37. var low = 0;
  38. var high = values.length / step - 2;
  39. if (high == 0)
  40. return step;
  41. var current = high >>> 1;
  42. while (true) {
  43. if (values[(current + 1) * step] <= target)
  44. low = current + 1;
  45. else
  46. high = current;
  47. if (low == high)
  48. return (low + 1) * step;
  49. current = (low + high) >>> 1;
  50. }
  51. };
  52. Animation.linearSearch = function (values, target, step) {
  53. for (var i = 0, last = values.length - step; i <= last; i += step)
  54. if (values[i] > target)
  55. return i;
  56. return -1;
  57. };
  58. return Animation;
  59. }());
  60. spine.Animation = Animation;
  61. var MixPose;
  62. (function (MixPose) {
  63. MixPose[MixPose["setup"] = 0] = "setup";
  64. MixPose[MixPose["current"] = 1] = "current";
  65. MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
  66. })(MixPose = spine.MixPose || (spine.MixPose = {}));
  67. var MixDirection;
  68. (function (MixDirection) {
  69. MixDirection[MixDirection["in"] = 0] = "in";
  70. MixDirection[MixDirection["out"] = 1] = "out";
  71. })(MixDirection = spine.MixDirection || (spine.MixDirection = {}));
  72. var TimelineType;
  73. (function (TimelineType) {
  74. TimelineType[TimelineType["rotate"] = 0] = "rotate";
  75. TimelineType[TimelineType["translate"] = 1] = "translate";
  76. TimelineType[TimelineType["scale"] = 2] = "scale";
  77. TimelineType[TimelineType["shear"] = 3] = "shear";
  78. TimelineType[TimelineType["attachment"] = 4] = "attachment";
  79. TimelineType[TimelineType["color"] = 5] = "color";
  80. TimelineType[TimelineType["deform"] = 6] = "deform";
  81. TimelineType[TimelineType["event"] = 7] = "event";
  82. TimelineType[TimelineType["drawOrder"] = 8] = "drawOrder";
  83. TimelineType[TimelineType["ikConstraint"] = 9] = "ikConstraint";
  84. TimelineType[TimelineType["transformConstraint"] = 10] = "transformConstraint";
  85. TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition";
  86. TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing";
  87. TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix";
  88. TimelineType[TimelineType["twoColor"] = 14] = "twoColor";
  89. })(TimelineType = spine.TimelineType || (spine.TimelineType = {}));
  90. var CurveTimeline = (function () {
  91. function CurveTimeline(frameCount) {
  92. if (frameCount <= 0)
  93. throw new Error("frameCount must be > 0: " + frameCount);
  94. this.curves = spine.Utils.newFloatArray((frameCount - 1) * CurveTimeline.BEZIER_SIZE);
  95. }
  96. CurveTimeline.prototype.getFrameCount = function () {
  97. return this.curves.length / CurveTimeline.BEZIER_SIZE + 1;
  98. };
  99. CurveTimeline.prototype.setLinear = function (frameIndex) {
  100. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.LINEAR;
  101. };
  102. CurveTimeline.prototype.setStepped = function (frameIndex) {
  103. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.STEPPED;
  104. };
  105. CurveTimeline.prototype.getCurveType = function (frameIndex) {
  106. var index = frameIndex * CurveTimeline.BEZIER_SIZE;
  107. if (index == this.curves.length)
  108. return CurveTimeline.LINEAR;
  109. var type = this.curves[index];
  110. if (type == CurveTimeline.LINEAR)
  111. return CurveTimeline.LINEAR;
  112. if (type == CurveTimeline.STEPPED)
  113. return CurveTimeline.STEPPED;
  114. return CurveTimeline.BEZIER;
  115. };
  116. CurveTimeline.prototype.setCurve = function (frameIndex, cx1, cy1, cx2, cy2) {
  117. var tmpx = (-cx1 * 2 + cx2) * 0.03, tmpy = (-cy1 * 2 + cy2) * 0.03;
  118. var dddfx = ((cx1 - cx2) * 3 + 1) * 0.006, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006;
  119. var ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
  120. var dfx = cx1 * 0.3 + tmpx + dddfx * 0.16666667, dfy = cy1 * 0.3 + tmpy + dddfy * 0.16666667;
  121. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  122. var curves = this.curves;
  123. curves[i++] = CurveTimeline.BEZIER;
  124. var x = dfx, y = dfy;
  125. for (var n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  126. curves[i] = x;
  127. curves[i + 1] = y;
  128. dfx += ddfx;
  129. dfy += ddfy;
  130. ddfx += dddfx;
  131. ddfy += dddfy;
  132. x += dfx;
  133. y += dfy;
  134. }
  135. };
  136. CurveTimeline.prototype.getCurvePercent = function (frameIndex, percent) {
  137. percent = spine.MathUtils.clamp(percent, 0, 1);
  138. var curves = this.curves;
  139. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  140. var type = curves[i];
  141. if (type == CurveTimeline.LINEAR)
  142. return percent;
  143. if (type == CurveTimeline.STEPPED)
  144. return 0;
  145. i++;
  146. var x = 0;
  147. for (var start = i, n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  148. x = curves[i];
  149. if (x >= percent) {
  150. var prevX = void 0, prevY = void 0;
  151. if (i == start) {
  152. prevX = 0;
  153. prevY = 0;
  154. }
  155. else {
  156. prevX = curves[i - 2];
  157. prevY = curves[i - 1];
  158. }
  159. return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
  160. }
  161. }
  162. var y = curves[i - 1];
  163. return y + (1 - y) * (percent - x) / (1 - x);
  164. };
  165. CurveTimeline.LINEAR = 0;
  166. CurveTimeline.STEPPED = 1;
  167. CurveTimeline.BEZIER = 2;
  168. CurveTimeline.BEZIER_SIZE = 10 * 2 - 1;
  169. return CurveTimeline;
  170. }());
  171. spine.CurveTimeline = CurveTimeline;
  172. var RotateTimeline = (function (_super) {
  173. __extends(RotateTimeline, _super);
  174. function RotateTimeline(frameCount) {
  175. var _this = _super.call(this, frameCount) || this;
  176. _this.frames = spine.Utils.newFloatArray(frameCount << 1);
  177. return _this;
  178. }
  179. RotateTimeline.prototype.getPropertyId = function () {
  180. return (TimelineType.rotate << 24) + this.boneIndex;
  181. };
  182. RotateTimeline.prototype.setFrame = function (frameIndex, time, degrees) {
  183. frameIndex <<= 1;
  184. this.frames[frameIndex] = time;
  185. this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
  186. };
  187. RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  188. var frames = this.frames;
  189. var bone = skeleton.bones[this.boneIndex];
  190. if (time < frames[0]) {
  191. switch (pose) {
  192. case MixPose.setup:
  193. bone.rotation = bone.data.rotation;
  194. return;
  195. case MixPose.current:
  196. var r_1 = bone.data.rotation - bone.rotation;
  197. r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
  198. bone.rotation += r_1 * alpha;
  199. }
  200. return;
  201. }
  202. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
  203. if (pose == MixPose.setup)
  204. bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
  205. else {
  206. var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
  207. r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
  208. bone.rotation += r_2 * alpha;
  209. }
  210. return;
  211. }
  212. var frame = Animation.binarySearch(frames, time, RotateTimeline.ENTRIES);
  213. var prevRotation = frames[frame + RotateTimeline.PREV_ROTATION];
  214. var frameTime = frames[frame];
  215. var percent = this.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
  216. var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
  217. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  218. r = prevRotation + r * percent;
  219. if (pose == MixPose.setup) {
  220. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  221. bone.rotation = bone.data.rotation + r * alpha;
  222. }
  223. else {
  224. r = bone.data.rotation + r - bone.rotation;
  225. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  226. bone.rotation += r * alpha;
  227. }
  228. };
  229. RotateTimeline.ENTRIES = 2;
  230. RotateTimeline.PREV_TIME = -2;
  231. RotateTimeline.PREV_ROTATION = -1;
  232. RotateTimeline.ROTATION = 1;
  233. return RotateTimeline;
  234. }(CurveTimeline));
  235. spine.RotateTimeline = RotateTimeline;
  236. var TranslateTimeline = (function (_super) {
  237. __extends(TranslateTimeline, _super);
  238. function TranslateTimeline(frameCount) {
  239. var _this = _super.call(this, frameCount) || this;
  240. _this.frames = spine.Utils.newFloatArray(frameCount * TranslateTimeline.ENTRIES);
  241. return _this;
  242. }
  243. TranslateTimeline.prototype.getPropertyId = function () {
  244. return (TimelineType.translate << 24) + this.boneIndex;
  245. };
  246. TranslateTimeline.prototype.setFrame = function (frameIndex, time, x, y) {
  247. frameIndex *= TranslateTimeline.ENTRIES;
  248. this.frames[frameIndex] = time;
  249. this.frames[frameIndex + TranslateTimeline.X] = x;
  250. this.frames[frameIndex + TranslateTimeline.Y] = y;
  251. };
  252. TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  253. var frames = this.frames;
  254. var bone = skeleton.bones[this.boneIndex];
  255. if (time < frames[0]) {
  256. switch (pose) {
  257. case MixPose.setup:
  258. bone.x = bone.data.x;
  259. bone.y = bone.data.y;
  260. return;
  261. case MixPose.current:
  262. bone.x += (bone.data.x - bone.x) * alpha;
  263. bone.y += (bone.data.y - bone.y) * alpha;
  264. }
  265. return;
  266. }
  267. var x = 0, y = 0;
  268. if (time >= frames[frames.length - TranslateTimeline.ENTRIES]) {
  269. x = frames[frames.length + TranslateTimeline.PREV_X];
  270. y = frames[frames.length + TranslateTimeline.PREV_Y];
  271. }
  272. else {
  273. var frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
  274. x = frames[frame + TranslateTimeline.PREV_X];
  275. y = frames[frame + TranslateTimeline.PREV_Y];
  276. var frameTime = frames[frame];
  277. var percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
  278. x += (frames[frame + TranslateTimeline.X] - x) * percent;
  279. y += (frames[frame + TranslateTimeline.Y] - y) * percent;
  280. }
  281. if (pose == MixPose.setup) {
  282. bone.x = bone.data.x + x * alpha;
  283. bone.y = bone.data.y + y * alpha;
  284. }
  285. else {
  286. bone.x += (bone.data.x + x - bone.x) * alpha;
  287. bone.y += (bone.data.y + y - bone.y) * alpha;
  288. }
  289. };
  290. TranslateTimeline.ENTRIES = 3;
  291. TranslateTimeline.PREV_TIME = -3;
  292. TranslateTimeline.PREV_X = -2;
  293. TranslateTimeline.PREV_Y = -1;
  294. TranslateTimeline.X = 1;
  295. TranslateTimeline.Y = 2;
  296. return TranslateTimeline;
  297. }(CurveTimeline));
  298. spine.TranslateTimeline = TranslateTimeline;
  299. var ScaleTimeline = (function (_super) {
  300. __extends(ScaleTimeline, _super);
  301. function ScaleTimeline(frameCount) {
  302. return _super.call(this, frameCount) || this;
  303. }
  304. ScaleTimeline.prototype.getPropertyId = function () {
  305. return (TimelineType.scale << 24) + this.boneIndex;
  306. };
  307. ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  308. var frames = this.frames;
  309. var bone = skeleton.bones[this.boneIndex];
  310. if (time < frames[0]) {
  311. switch (pose) {
  312. case MixPose.setup:
  313. bone.scaleX = bone.data.scaleX;
  314. bone.scaleY = bone.data.scaleY;
  315. return;
  316. case MixPose.current:
  317. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  318. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  319. }
  320. return;
  321. }
  322. var x = 0, y = 0;
  323. if (time >= frames[frames.length - ScaleTimeline.ENTRIES]) {
  324. x = frames[frames.length + ScaleTimeline.PREV_X] * bone.data.scaleX;
  325. y = frames[frames.length + ScaleTimeline.PREV_Y] * bone.data.scaleY;
  326. }
  327. else {
  328. var frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
  329. x = frames[frame + ScaleTimeline.PREV_X];
  330. y = frames[frame + ScaleTimeline.PREV_Y];
  331. var frameTime = frames[frame];
  332. var percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
  333. x = (x + (frames[frame + ScaleTimeline.X] - x) * percent) * bone.data.scaleX;
  334. y = (y + (frames[frame + ScaleTimeline.Y] - y) * percent) * bone.data.scaleY;
  335. }
  336. if (alpha == 1) {
  337. bone.scaleX = x;
  338. bone.scaleY = y;
  339. }
  340. else {
  341. var bx = 0, by = 0;
  342. if (pose == MixPose.setup) {
  343. bx = bone.data.scaleX;
  344. by = bone.data.scaleY;
  345. }
  346. else {
  347. bx = bone.scaleX;
  348. by = bone.scaleY;
  349. }
  350. if (direction == MixDirection.out) {
  351. x = Math.abs(x) * spine.MathUtils.signum(bx);
  352. y = Math.abs(y) * spine.MathUtils.signum(by);
  353. }
  354. else {
  355. bx = Math.abs(bx) * spine.MathUtils.signum(x);
  356. by = Math.abs(by) * spine.MathUtils.signum(y);
  357. }
  358. bone.scaleX = bx + (x - bx) * alpha;
  359. bone.scaleY = by + (y - by) * alpha;
  360. }
  361. };
  362. return ScaleTimeline;
  363. }(TranslateTimeline));
  364. spine.ScaleTimeline = ScaleTimeline;
  365. var ShearTimeline = (function (_super) {
  366. __extends(ShearTimeline, _super);
  367. function ShearTimeline(frameCount) {
  368. return _super.call(this, frameCount) || this;
  369. }
  370. ShearTimeline.prototype.getPropertyId = function () {
  371. return (TimelineType.shear << 24) + this.boneIndex;
  372. };
  373. ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  374. var frames = this.frames;
  375. var bone = skeleton.bones[this.boneIndex];
  376. if (time < frames[0]) {
  377. switch (pose) {
  378. case MixPose.setup:
  379. bone.shearX = bone.data.shearX;
  380. bone.shearY = bone.data.shearY;
  381. return;
  382. case MixPose.current:
  383. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  384. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  385. }
  386. return;
  387. }
  388. var x = 0, y = 0;
  389. if (time >= frames[frames.length - ShearTimeline.ENTRIES]) {
  390. x = frames[frames.length + ShearTimeline.PREV_X];
  391. y = frames[frames.length + ShearTimeline.PREV_Y];
  392. }
  393. else {
  394. var frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
  395. x = frames[frame + ShearTimeline.PREV_X];
  396. y = frames[frame + ShearTimeline.PREV_Y];
  397. var frameTime = frames[frame];
  398. var percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
  399. x = x + (frames[frame + ShearTimeline.X] - x) * percent;
  400. y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
  401. }
  402. if (pose == MixPose.setup) {
  403. bone.shearX = bone.data.shearX + x * alpha;
  404. bone.shearY = bone.data.shearY + y * alpha;
  405. }
  406. else {
  407. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  408. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  409. }
  410. };
  411. return ShearTimeline;
  412. }(TranslateTimeline));
  413. spine.ShearTimeline = ShearTimeline;
  414. var ColorTimeline = (function (_super) {
  415. __extends(ColorTimeline, _super);
  416. function ColorTimeline(frameCount) {
  417. var _this = _super.call(this, frameCount) || this;
  418. _this.frames = spine.Utils.newFloatArray(frameCount * ColorTimeline.ENTRIES);
  419. return _this;
  420. }
  421. ColorTimeline.prototype.getPropertyId = function () {
  422. return (TimelineType.color << 24) + this.slotIndex;
  423. };
  424. ColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a) {
  425. frameIndex *= ColorTimeline.ENTRIES;
  426. this.frames[frameIndex] = time;
  427. this.frames[frameIndex + ColorTimeline.R] = r;
  428. this.frames[frameIndex + ColorTimeline.G] = g;
  429. this.frames[frameIndex + ColorTimeline.B] = b;
  430. this.frames[frameIndex + ColorTimeline.A] = a;
  431. };
  432. ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  433. var slot = skeleton.slots[this.slotIndex];
  434. var frames = this.frames;
  435. if (time < frames[0]) {
  436. switch (pose) {
  437. case MixPose.setup:
  438. slot.color.setFromColor(slot.data.color);
  439. return;
  440. case MixPose.current:
  441. var color = slot.color, setup = slot.data.color;
  442. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
  443. }
  444. return;
  445. }
  446. var r = 0, g = 0, b = 0, a = 0;
  447. if (time >= frames[frames.length - ColorTimeline.ENTRIES]) {
  448. var i = frames.length;
  449. r = frames[i + ColorTimeline.PREV_R];
  450. g = frames[i + ColorTimeline.PREV_G];
  451. b = frames[i + ColorTimeline.PREV_B];
  452. a = frames[i + ColorTimeline.PREV_A];
  453. }
  454. else {
  455. var frame = Animation.binarySearch(frames, time, ColorTimeline.ENTRIES);
  456. r = frames[frame + ColorTimeline.PREV_R];
  457. g = frames[frame + ColorTimeline.PREV_G];
  458. b = frames[frame + ColorTimeline.PREV_B];
  459. a = frames[frame + ColorTimeline.PREV_A];
  460. var frameTime = frames[frame];
  461. var percent = this.getCurvePercent(frame / ColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ColorTimeline.PREV_TIME] - frameTime));
  462. r += (frames[frame + ColorTimeline.R] - r) * percent;
  463. g += (frames[frame + ColorTimeline.G] - g) * percent;
  464. b += (frames[frame + ColorTimeline.B] - b) * percent;
  465. a += (frames[frame + ColorTimeline.A] - a) * percent;
  466. }
  467. if (alpha == 1)
  468. slot.color.set(r, g, b, a);
  469. else {
  470. var color = slot.color;
  471. if (pose == MixPose.setup)
  472. color.setFromColor(slot.data.color);
  473. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  474. }
  475. };
  476. ColorTimeline.ENTRIES = 5;
  477. ColorTimeline.PREV_TIME = -5;
  478. ColorTimeline.PREV_R = -4;
  479. ColorTimeline.PREV_G = -3;
  480. ColorTimeline.PREV_B = -2;
  481. ColorTimeline.PREV_A = -1;
  482. ColorTimeline.R = 1;
  483. ColorTimeline.G = 2;
  484. ColorTimeline.B = 3;
  485. ColorTimeline.A = 4;
  486. return ColorTimeline;
  487. }(CurveTimeline));
  488. spine.ColorTimeline = ColorTimeline;
  489. var TwoColorTimeline = (function (_super) {
  490. __extends(TwoColorTimeline, _super);
  491. function TwoColorTimeline(frameCount) {
  492. var _this = _super.call(this, frameCount) || this;
  493. _this.frames = spine.Utils.newFloatArray(frameCount * TwoColorTimeline.ENTRIES);
  494. return _this;
  495. }
  496. TwoColorTimeline.prototype.getPropertyId = function () {
  497. return (TimelineType.twoColor << 24) + this.slotIndex;
  498. };
  499. TwoColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a, r2, g2, b2) {
  500. frameIndex *= TwoColorTimeline.ENTRIES;
  501. this.frames[frameIndex] = time;
  502. this.frames[frameIndex + TwoColorTimeline.R] = r;
  503. this.frames[frameIndex + TwoColorTimeline.G] = g;
  504. this.frames[frameIndex + TwoColorTimeline.B] = b;
  505. this.frames[frameIndex + TwoColorTimeline.A] = a;
  506. this.frames[frameIndex + TwoColorTimeline.R2] = r2;
  507. this.frames[frameIndex + TwoColorTimeline.G2] = g2;
  508. this.frames[frameIndex + TwoColorTimeline.B2] = b2;
  509. };
  510. TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  511. var slot = skeleton.slots[this.slotIndex];
  512. var frames = this.frames;
  513. if (time < frames[0]) {
  514. switch (pose) {
  515. case MixPose.setup:
  516. slot.color.setFromColor(slot.data.color);
  517. slot.darkColor.setFromColor(slot.data.darkColor);
  518. return;
  519. case MixPose.current:
  520. var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  521. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
  522. dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
  523. }
  524. return;
  525. }
  526. var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  527. if (time >= frames[frames.length - TwoColorTimeline.ENTRIES]) {
  528. var i = frames.length;
  529. r = frames[i + TwoColorTimeline.PREV_R];
  530. g = frames[i + TwoColorTimeline.PREV_G];
  531. b = frames[i + TwoColorTimeline.PREV_B];
  532. a = frames[i + TwoColorTimeline.PREV_A];
  533. r2 = frames[i + TwoColorTimeline.PREV_R2];
  534. g2 = frames[i + TwoColorTimeline.PREV_G2];
  535. b2 = frames[i + TwoColorTimeline.PREV_B2];
  536. }
  537. else {
  538. var frame = Animation.binarySearch(frames, time, TwoColorTimeline.ENTRIES);
  539. r = frames[frame + TwoColorTimeline.PREV_R];
  540. g = frames[frame + TwoColorTimeline.PREV_G];
  541. b = frames[frame + TwoColorTimeline.PREV_B];
  542. a = frames[frame + TwoColorTimeline.PREV_A];
  543. r2 = frames[frame + TwoColorTimeline.PREV_R2];
  544. g2 = frames[frame + TwoColorTimeline.PREV_G2];
  545. b2 = frames[frame + TwoColorTimeline.PREV_B2];
  546. var frameTime = frames[frame];
  547. var percent = this.getCurvePercent(frame / TwoColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TwoColorTimeline.PREV_TIME] - frameTime));
  548. r += (frames[frame + TwoColorTimeline.R] - r) * percent;
  549. g += (frames[frame + TwoColorTimeline.G] - g) * percent;
  550. b += (frames[frame + TwoColorTimeline.B] - b) * percent;
  551. a += (frames[frame + TwoColorTimeline.A] - a) * percent;
  552. r2 += (frames[frame + TwoColorTimeline.R2] - r2) * percent;
  553. g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
  554. b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
  555. }
  556. if (alpha == 1) {
  557. slot.color.set(r, g, b, a);
  558. slot.darkColor.set(r2, g2, b2, 1);
  559. }
  560. else {
  561. var light = slot.color, dark = slot.darkColor;
  562. if (pose == MixPose.setup) {
  563. light.setFromColor(slot.data.color);
  564. dark.setFromColor(slot.data.darkColor);
  565. }
  566. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  567. dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
  568. }
  569. };
  570. TwoColorTimeline.ENTRIES = 8;
  571. TwoColorTimeline.PREV_TIME = -8;
  572. TwoColorTimeline.PREV_R = -7;
  573. TwoColorTimeline.PREV_G = -6;
  574. TwoColorTimeline.PREV_B = -5;
  575. TwoColorTimeline.PREV_A = -4;
  576. TwoColorTimeline.PREV_R2 = -3;
  577. TwoColorTimeline.PREV_G2 = -2;
  578. TwoColorTimeline.PREV_B2 = -1;
  579. TwoColorTimeline.R = 1;
  580. TwoColorTimeline.G = 2;
  581. TwoColorTimeline.B = 3;
  582. TwoColorTimeline.A = 4;
  583. TwoColorTimeline.R2 = 5;
  584. TwoColorTimeline.G2 = 6;
  585. TwoColorTimeline.B2 = 7;
  586. return TwoColorTimeline;
  587. }(CurveTimeline));
  588. spine.TwoColorTimeline = TwoColorTimeline;
  589. var AttachmentTimeline = (function () {
  590. function AttachmentTimeline(frameCount) {
  591. this.frames = spine.Utils.newFloatArray(frameCount);
  592. this.attachmentNames = new Array(frameCount);
  593. }
  594. AttachmentTimeline.prototype.getPropertyId = function () {
  595. return (TimelineType.attachment << 24) + this.slotIndex;
  596. };
  597. AttachmentTimeline.prototype.getFrameCount = function () {
  598. return this.frames.length;
  599. };
  600. AttachmentTimeline.prototype.setFrame = function (frameIndex, time, attachmentName) {
  601. this.frames[frameIndex] = time;
  602. this.attachmentNames[frameIndex] = attachmentName;
  603. };
  604. AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  605. var slot = skeleton.slots[this.slotIndex];
  606. if (direction == MixDirection.out && pose == MixPose.setup) {
  607. var attachmentName_1 = slot.data.attachmentName;
  608. slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
  609. return;
  610. }
  611. var frames = this.frames;
  612. if (time < frames[0]) {
  613. if (pose == MixPose.setup) {
  614. var attachmentName_2 = slot.data.attachmentName;
  615. slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
  616. }
  617. return;
  618. }
  619. var frameIndex = 0;
  620. if (time >= frames[frames.length - 1])
  621. frameIndex = frames.length - 1;
  622. else
  623. frameIndex = Animation.binarySearch(frames, time, 1) - 1;
  624. var attachmentName = this.attachmentNames[frameIndex];
  625. skeleton.slots[this.slotIndex]
  626. .setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  627. };
  628. return AttachmentTimeline;
  629. }());
  630. spine.AttachmentTimeline = AttachmentTimeline;
  631. var zeros = null;
  632. var DeformTimeline = (function (_super) {
  633. __extends(DeformTimeline, _super);
  634. function DeformTimeline(frameCount) {
  635. var _this = _super.call(this, frameCount) || this;
  636. _this.frames = spine.Utils.newFloatArray(frameCount);
  637. _this.frameVertices = new Array(frameCount);
  638. if (zeros == null)
  639. zeros = spine.Utils.newFloatArray(64);
  640. return _this;
  641. }
  642. DeformTimeline.prototype.getPropertyId = function () {
  643. return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
  644. };
  645. DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
  646. this.frames[frameIndex] = time;
  647. this.frameVertices[frameIndex] = vertices;
  648. };
  649. DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  650. var slot = skeleton.slots[this.slotIndex];
  651. var slotAttachment = slot.getAttachment();
  652. if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
  653. return;
  654. var verticesArray = slot.attachmentVertices;
  655. if (verticesArray.length == 0)
  656. alpha = 1;
  657. var frameVertices = this.frameVertices;
  658. var vertexCount = frameVertices[0].length;
  659. var frames = this.frames;
  660. if (time < frames[0]) {
  661. var vertexAttachment = slotAttachment;
  662. switch (pose) {
  663. case MixPose.setup:
  664. verticesArray.length = 0;
  665. return;
  666. case MixPose.current:
  667. if (alpha == 1) {
  668. verticesArray.length = 0;
  669. break;
  670. }
  671. var vertices_1 = spine.Utils.setArraySize(verticesArray, vertexCount);
  672. if (vertexAttachment.bones == null) {
  673. var setupVertices = vertexAttachment.vertices;
  674. for (var i = 0; i < vertexCount; i++)
  675. vertices_1[i] += (setupVertices[i] - vertices_1[i]) * alpha;
  676. }
  677. else {
  678. alpha = 1 - alpha;
  679. for (var i = 0; i < vertexCount; i++)
  680. vertices_1[i] *= alpha;
  681. }
  682. }
  683. return;
  684. }
  685. var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
  686. if (time >= frames[frames.length - 1]) {
  687. var lastVertices = frameVertices[frames.length - 1];
  688. if (alpha == 1) {
  689. spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
  690. }
  691. else if (pose == MixPose.setup) {
  692. var vertexAttachment = slotAttachment;
  693. if (vertexAttachment.bones == null) {
  694. var setupVertices_1 = vertexAttachment.vertices;
  695. for (var i_1 = 0; i_1 < vertexCount; i_1++) {
  696. var setup = setupVertices_1[i_1];
  697. vertices[i_1] = setup + (lastVertices[i_1] - setup) * alpha;
  698. }
  699. }
  700. else {
  701. for (var i_2 = 0; i_2 < vertexCount; i_2++)
  702. vertices[i_2] = lastVertices[i_2] * alpha;
  703. }
  704. }
  705. else {
  706. for (var i_3 = 0; i_3 < vertexCount; i_3++)
  707. vertices[i_3] += (lastVertices[i_3] - vertices[i_3]) * alpha;
  708. }
  709. return;
  710. }
  711. var frame = Animation.binarySearch(frames, time);
  712. var prevVertices = frameVertices[frame - 1];
  713. var nextVertices = frameVertices[frame];
  714. var frameTime = frames[frame];
  715. var percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
  716. if (alpha == 1) {
  717. for (var i_4 = 0; i_4 < vertexCount; i_4++) {
  718. var prev = prevVertices[i_4];
  719. vertices[i_4] = prev + (nextVertices[i_4] - prev) * percent;
  720. }
  721. }
  722. else if (pose == MixPose.setup) {
  723. var vertexAttachment = slotAttachment;
  724. if (vertexAttachment.bones == null) {
  725. var setupVertices_2 = vertexAttachment.vertices;
  726. for (var i_5 = 0; i_5 < vertexCount; i_5++) {
  727. var prev = prevVertices[i_5], setup = setupVertices_2[i_5];
  728. vertices[i_5] = setup + (prev + (nextVertices[i_5] - prev) * percent - setup) * alpha;
  729. }
  730. }
  731. else {
  732. for (var i_6 = 0; i_6 < vertexCount; i_6++) {
  733. var prev = prevVertices[i_6];
  734. vertices[i_6] = (prev + (nextVertices[i_6] - prev) * percent) * alpha;
  735. }
  736. }
  737. }
  738. else {
  739. for (var i_7 = 0; i_7 < vertexCount; i_7++) {
  740. var prev = prevVertices[i_7];
  741. vertices[i_7] += (prev + (nextVertices[i_7] - prev) * percent - vertices[i_7]) * alpha;
  742. }
  743. }
  744. };
  745. return DeformTimeline;
  746. }(CurveTimeline));
  747. spine.DeformTimeline = DeformTimeline;
  748. var EventTimeline = (function () {
  749. function EventTimeline(frameCount) {
  750. this.frames = spine.Utils.newFloatArray(frameCount);
  751. this.events = new Array(frameCount);
  752. }
  753. EventTimeline.prototype.getPropertyId = function () {
  754. return TimelineType.event << 24;
  755. };
  756. EventTimeline.prototype.getFrameCount = function () {
  757. return this.frames.length;
  758. };
  759. EventTimeline.prototype.setFrame = function (frameIndex, event) {
  760. this.frames[frameIndex] = event.time;
  761. this.events[frameIndex] = event;
  762. };
  763. EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  764. if (firedEvents == null)
  765. return;
  766. var frames = this.frames;
  767. var frameCount = this.frames.length;
  768. if (lastTime > time) {
  769. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
  770. lastTime = -1;
  771. }
  772. else if (lastTime >= frames[frameCount - 1])
  773. return;
  774. if (time < frames[0])
  775. return;
  776. var frame = 0;
  777. if (lastTime < frames[0])
  778. frame = 0;
  779. else {
  780. frame = Animation.binarySearch(frames, lastTime);
  781. var frameTime = frames[frame];
  782. while (frame > 0) {
  783. if (frames[frame - 1] != frameTime)
  784. break;
  785. frame--;
  786. }
  787. }
  788. for (; frame < frameCount && time >= frames[frame]; frame++)
  789. firedEvents.push(this.events[frame]);
  790. };
  791. return EventTimeline;
  792. }());
  793. spine.EventTimeline = EventTimeline;
  794. var DrawOrderTimeline = (function () {
  795. function DrawOrderTimeline(frameCount) {
  796. this.frames = spine.Utils.newFloatArray(frameCount);
  797. this.drawOrders = new Array(frameCount);
  798. }
  799. DrawOrderTimeline.prototype.getPropertyId = function () {
  800. return TimelineType.drawOrder << 24;
  801. };
  802. DrawOrderTimeline.prototype.getFrameCount = function () {
  803. return this.frames.length;
  804. };
  805. DrawOrderTimeline.prototype.setFrame = function (frameIndex, time, drawOrder) {
  806. this.frames[frameIndex] = time;
  807. this.drawOrders[frameIndex] = drawOrder;
  808. };
  809. DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  810. var drawOrder = skeleton.drawOrder;
  811. var slots = skeleton.slots;
  812. if (direction == MixDirection.out && pose == MixPose.setup) {
  813. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  814. return;
  815. }
  816. var frames = this.frames;
  817. if (time < frames[0]) {
  818. if (pose == MixPose.setup)
  819. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  820. return;
  821. }
  822. var frame = 0;
  823. if (time >= frames[frames.length - 1])
  824. frame = frames.length - 1;
  825. else
  826. frame = Animation.binarySearch(frames, time) - 1;
  827. var drawOrderToSetupIndex = this.drawOrders[frame];
  828. if (drawOrderToSetupIndex == null)
  829. spine.Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  830. else {
  831. for (var i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  832. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  833. }
  834. };
  835. return DrawOrderTimeline;
  836. }());
  837. spine.DrawOrderTimeline = DrawOrderTimeline;
  838. var IkConstraintTimeline = (function (_super) {
  839. __extends(IkConstraintTimeline, _super);
  840. function IkConstraintTimeline(frameCount) {
  841. var _this = _super.call(this, frameCount) || this;
  842. _this.frames = spine.Utils.newFloatArray(frameCount * IkConstraintTimeline.ENTRIES);
  843. return _this;
  844. }
  845. IkConstraintTimeline.prototype.getPropertyId = function () {
  846. return (TimelineType.ikConstraint << 24) + this.ikConstraintIndex;
  847. };
  848. IkConstraintTimeline.prototype.setFrame = function (frameIndex, time, mix, bendDirection) {
  849. frameIndex *= IkConstraintTimeline.ENTRIES;
  850. this.frames[frameIndex] = time;
  851. this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
  852. this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
  853. };
  854. IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  855. var frames = this.frames;
  856. var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  857. if (time < frames[0]) {
  858. switch (pose) {
  859. case MixPose.setup:
  860. constraint.mix = constraint.data.mix;
  861. constraint.bendDirection = constraint.data.bendDirection;
  862. return;
  863. case MixPose.current:
  864. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  865. constraint.bendDirection = constraint.data.bendDirection;
  866. }
  867. return;
  868. }
  869. if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
  870. if (pose == MixPose.setup) {
  871. constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
  872. constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
  873. : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  874. }
  875. else {
  876. constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
  877. if (direction == MixDirection["in"])
  878. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  879. }
  880. return;
  881. }
  882. var frame = Animation.binarySearch(frames, time, IkConstraintTimeline.ENTRIES);
  883. var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
  884. var frameTime = frames[frame];
  885. var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
  886. if (pose == MixPose.setup) {
  887. constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha;
  888. constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  889. }
  890. else {
  891. constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
  892. if (direction == MixDirection["in"])
  893. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  894. }
  895. };
  896. IkConstraintTimeline.ENTRIES = 3;
  897. IkConstraintTimeline.PREV_TIME = -3;
  898. IkConstraintTimeline.PREV_MIX = -2;
  899. IkConstraintTimeline.PREV_BEND_DIRECTION = -1;
  900. IkConstraintTimeline.MIX = 1;
  901. IkConstraintTimeline.BEND_DIRECTION = 2;
  902. return IkConstraintTimeline;
  903. }(CurveTimeline));
  904. spine.IkConstraintTimeline = IkConstraintTimeline;
  905. var TransformConstraintTimeline = (function (_super) {
  906. __extends(TransformConstraintTimeline, _super);
  907. function TransformConstraintTimeline(frameCount) {
  908. var _this = _super.call(this, frameCount) || this;
  909. _this.frames = spine.Utils.newFloatArray(frameCount * TransformConstraintTimeline.ENTRIES);
  910. return _this;
  911. }
  912. TransformConstraintTimeline.prototype.getPropertyId = function () {
  913. return (TimelineType.transformConstraint << 24) + this.transformConstraintIndex;
  914. };
  915. TransformConstraintTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix, scaleMix, shearMix) {
  916. frameIndex *= TransformConstraintTimeline.ENTRIES;
  917. this.frames[frameIndex] = time;
  918. this.frames[frameIndex + TransformConstraintTimeline.ROTATE] = rotateMix;
  919. this.frames[frameIndex + TransformConstraintTimeline.TRANSLATE] = translateMix;
  920. this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
  921. this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
  922. };
  923. TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  924. var frames = this.frames;
  925. var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  926. if (time < frames[0]) {
  927. var data = constraint.data;
  928. switch (pose) {
  929. case MixPose.setup:
  930. constraint.rotateMix = data.rotateMix;
  931. constraint.translateMix = data.translateMix;
  932. constraint.scaleMix = data.scaleMix;
  933. constraint.shearMix = data.shearMix;
  934. return;
  935. case MixPose.current:
  936. constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
  937. constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
  938. constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
  939. constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
  940. }
  941. return;
  942. }
  943. var rotate = 0, translate = 0, scale = 0, shear = 0;
  944. if (time >= frames[frames.length - TransformConstraintTimeline.ENTRIES]) {
  945. var i = frames.length;
  946. rotate = frames[i + TransformConstraintTimeline.PREV_ROTATE];
  947. translate = frames[i + TransformConstraintTimeline.PREV_TRANSLATE];
  948. scale = frames[i + TransformConstraintTimeline.PREV_SCALE];
  949. shear = frames[i + TransformConstraintTimeline.PREV_SHEAR];
  950. }
  951. else {
  952. var frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
  953. rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
  954. translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
  955. scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
  956. shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
  957. var frameTime = frames[frame];
  958. var percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
  959. rotate += (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent;
  960. translate += (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent;
  961. scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
  962. shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
  963. }
  964. if (pose == MixPose.setup) {
  965. var data = constraint.data;
  966. constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
  967. constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
  968. constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
  969. constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
  970. }
  971. else {
  972. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  973. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  974. constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
  975. constraint.shearMix += (shear - constraint.shearMix) * alpha;
  976. }
  977. };
  978. TransformConstraintTimeline.ENTRIES = 5;
  979. TransformConstraintTimeline.PREV_TIME = -5;
  980. TransformConstraintTimeline.PREV_ROTATE = -4;
  981. TransformConstraintTimeline.PREV_TRANSLATE = -3;
  982. TransformConstraintTimeline.PREV_SCALE = -2;
  983. TransformConstraintTimeline.PREV_SHEAR = -1;
  984. TransformConstraintTimeline.ROTATE = 1;
  985. TransformConstraintTimeline.TRANSLATE = 2;
  986. TransformConstraintTimeline.SCALE = 3;
  987. TransformConstraintTimeline.SHEAR = 4;
  988. return TransformConstraintTimeline;
  989. }(CurveTimeline));
  990. spine.TransformConstraintTimeline = TransformConstraintTimeline;
  991. var PathConstraintPositionTimeline = (function (_super) {
  992. __extends(PathConstraintPositionTimeline, _super);
  993. function PathConstraintPositionTimeline(frameCount) {
  994. var _this = _super.call(this, frameCount) || this;
  995. _this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintPositionTimeline.ENTRIES);
  996. return _this;
  997. }
  998. PathConstraintPositionTimeline.prototype.getPropertyId = function () {
  999. return (TimelineType.pathConstraintPosition << 24) + this.pathConstraintIndex;
  1000. };
  1001. PathConstraintPositionTimeline.prototype.setFrame = function (frameIndex, time, value) {
  1002. frameIndex *= PathConstraintPositionTimeline.ENTRIES;
  1003. this.frames[frameIndex] = time;
  1004. this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
  1005. };
  1006. PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1007. var frames = this.frames;
  1008. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1009. if (time < frames[0]) {
  1010. switch (pose) {
  1011. case MixPose.setup:
  1012. constraint.position = constraint.data.position;
  1013. return;
  1014. case MixPose.current:
  1015. constraint.position += (constraint.data.position - constraint.position) * alpha;
  1016. }
  1017. return;
  1018. }
  1019. var position = 0;
  1020. if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES])
  1021. position = frames[frames.length + PathConstraintPositionTimeline.PREV_VALUE];
  1022. else {
  1023. var frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
  1024. position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
  1025. var frameTime = frames[frame];
  1026. var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
  1027. position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
  1028. }
  1029. if (pose == MixPose.setup)
  1030. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  1031. else
  1032. constraint.position += (position - constraint.position) * alpha;
  1033. };
  1034. PathConstraintPositionTimeline.ENTRIES = 2;
  1035. PathConstraintPositionTimeline.PREV_TIME = -2;
  1036. PathConstraintPositionTimeline.PREV_VALUE = -1;
  1037. PathConstraintPositionTimeline.VALUE = 1;
  1038. return PathConstraintPositionTimeline;
  1039. }(CurveTimeline));
  1040. spine.PathConstraintPositionTimeline = PathConstraintPositionTimeline;
  1041. var PathConstraintSpacingTimeline = (function (_super) {
  1042. __extends(PathConstraintSpacingTimeline, _super);
  1043. function PathConstraintSpacingTimeline(frameCount) {
  1044. return _super.call(this, frameCount) || this;
  1045. }
  1046. PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
  1047. return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
  1048. };
  1049. PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1050. var frames = this.frames;
  1051. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1052. if (time < frames[0]) {
  1053. switch (pose) {
  1054. case MixPose.setup:
  1055. constraint.spacing = constraint.data.spacing;
  1056. return;
  1057. case MixPose.current:
  1058. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  1059. }
  1060. return;
  1061. }
  1062. var spacing = 0;
  1063. if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES])
  1064. spacing = frames[frames.length + PathConstraintSpacingTimeline.PREV_VALUE];
  1065. else {
  1066. var frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
  1067. spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
  1068. var frameTime = frames[frame];
  1069. var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
  1070. spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
  1071. }
  1072. if (pose == MixPose.setup)
  1073. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  1074. else
  1075. constraint.spacing += (spacing - constraint.spacing) * alpha;
  1076. };
  1077. return PathConstraintSpacingTimeline;
  1078. }(PathConstraintPositionTimeline));
  1079. spine.PathConstraintSpacingTimeline = PathConstraintSpacingTimeline;
  1080. var PathConstraintMixTimeline = (function (_super) {
  1081. __extends(PathConstraintMixTimeline, _super);
  1082. function PathConstraintMixTimeline(frameCount) {
  1083. var _this = _super.call(this, frameCount) || this;
  1084. _this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintMixTimeline.ENTRIES);
  1085. return _this;
  1086. }
  1087. PathConstraintMixTimeline.prototype.getPropertyId = function () {
  1088. return (TimelineType.pathConstraintMix << 24) + this.pathConstraintIndex;
  1089. };
  1090. PathConstraintMixTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix) {
  1091. frameIndex *= PathConstraintMixTimeline.ENTRIES;
  1092. this.frames[frameIndex] = time;
  1093. this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
  1094. this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
  1095. };
  1096. PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1097. var frames = this.frames;
  1098. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1099. if (time < frames[0]) {
  1100. switch (pose) {
  1101. case MixPose.setup:
  1102. constraint.rotateMix = constraint.data.rotateMix;
  1103. constraint.translateMix = constraint.data.translateMix;
  1104. return;
  1105. case MixPose.current:
  1106. constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
  1107. constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
  1108. }
  1109. return;
  1110. }
  1111. var rotate = 0, translate = 0;
  1112. if (time >= frames[frames.length - PathConstraintMixTimeline.ENTRIES]) {
  1113. rotate = frames[frames.length + PathConstraintMixTimeline.PREV_ROTATE];
  1114. translate = frames[frames.length + PathConstraintMixTimeline.PREV_TRANSLATE];
  1115. }
  1116. else {
  1117. var frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
  1118. rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
  1119. translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
  1120. var frameTime = frames[frame];
  1121. var percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
  1122. rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
  1123. translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
  1124. }
  1125. if (pose == MixPose.setup) {
  1126. constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
  1127. constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
  1128. }
  1129. else {
  1130. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  1131. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  1132. }
  1133. };
  1134. PathConstraintMixTimeline.ENTRIES = 3;
  1135. PathConstraintMixTimeline.PREV_TIME = -3;
  1136. PathConstraintMixTimeline.PREV_ROTATE = -2;
  1137. PathConstraintMixTimeline.PREV_TRANSLATE = -1;
  1138. PathConstraintMixTimeline.ROTATE = 1;
  1139. PathConstraintMixTimeline.TRANSLATE = 2;
  1140. return PathConstraintMixTimeline;
  1141. }(CurveTimeline));
  1142. spine.PathConstraintMixTimeline = PathConstraintMixTimeline;
  1143. })(spine || (spine = {}));
  1144. var spine;
  1145. (function (spine) {
  1146. var AnimationState = (function () {
  1147. function AnimationState(data) {
  1148. this.tracks = new Array();
  1149. this.events = new Array();
  1150. this.listeners = new Array();
  1151. this.queue = new EventQueue(this);
  1152. this.propertyIDs = new spine.IntSet();
  1153. this.mixingTo = new Array();
  1154. this.animationsChanged = false;
  1155. this.timeScale = 1;
  1156. this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
  1157. this.data = data;
  1158. }
  1159. AnimationState.prototype.update = function (delta) {
  1160. delta *= this.timeScale;
  1161. var tracks = this.tracks;
  1162. for (var i = 0, n = tracks.length; i < n; i++) {
  1163. var current = tracks[i];
  1164. if (current == null)
  1165. continue;
  1166. current.animationLast = current.nextAnimationLast;
  1167. current.trackLast = current.nextTrackLast;
  1168. var currentDelta = delta * current.timeScale;
  1169. if (current.delay > 0) {
  1170. current.delay -= currentDelta;
  1171. if (current.delay > 0)
  1172. continue;
  1173. currentDelta = -current.delay;
  1174. current.delay = 0;
  1175. }
  1176. var next = current.next;
  1177. if (next != null) {
  1178. var nextTime = current.trackLast - next.delay;
  1179. if (nextTime >= 0) {
  1180. next.delay = 0;
  1181. next.trackTime = nextTime + delta * next.timeScale;
  1182. current.trackTime += currentDelta;
  1183. this.setCurrent(i, next, true);
  1184. while (next.mixingFrom != null) {
  1185. next.mixTime += currentDelta;
  1186. next = next.mixingFrom;
  1187. }
  1188. continue;
  1189. }
  1190. }
  1191. else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  1192. tracks[i] = null;
  1193. this.queue.end(current);
  1194. this.disposeNext(current);
  1195. continue;
  1196. }
  1197. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  1198. var from = current.mixingFrom;
  1199. current.mixingFrom = null;
  1200. while (from != null) {
  1201. this.queue.end(from);
  1202. from = from.mixingFrom;
  1203. }
  1204. }
  1205. current.trackTime += currentDelta;
  1206. }
  1207. this.queue.drain();
  1208. };
  1209. AnimationState.prototype.updateMixingFrom = function (to, delta) {
  1210. var from = to.mixingFrom;
  1211. if (from == null)
  1212. return true;
  1213. var finished = this.updateMixingFrom(from, delta);
  1214. from.animationLast = from.nextAnimationLast;
  1215. from.trackLast = from.nextTrackLast;
  1216. if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
  1217. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  1218. to.mixingFrom = from.mixingFrom;
  1219. to.interruptAlpha = from.interruptAlpha;
  1220. this.queue.end(from);
  1221. }
  1222. return finished;
  1223. }
  1224. from.trackTime += delta * from.timeScale;
  1225. to.mixTime += delta * to.timeScale;
  1226. return false;
  1227. };
  1228. AnimationState.prototype.apply = function (skeleton) {
  1229. if (skeleton == null)
  1230. throw new Error("skeleton cannot be null.");
  1231. if (this.animationsChanged)
  1232. this._animationsChanged();
  1233. var events = this.events;
  1234. var tracks = this.tracks;
  1235. var applied = false;
  1236. for (var i = 0, n = tracks.length; i < n; i++) {
  1237. var current = tracks[i];
  1238. if (current == null || current.delay > 0)
  1239. continue;
  1240. applied = true;
  1241. var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
  1242. var mix = current.alpha;
  1243. if (current.mixingFrom != null)
  1244. mix *= this.applyMixingFrom(current, skeleton, currentPose);
  1245. else if (current.trackTime >= current.trackEnd && current.next == null)
  1246. mix = 0;
  1247. var animationLast = current.animationLast, animationTime = current.getAnimationTime();
  1248. var timelineCount = current.animation.timelines.length;
  1249. var timelines = current.animation.timelines;
  1250. if (mix == 1) {
  1251. for (var ii = 0; ii < timelineCount; ii++)
  1252. timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection["in"]);
  1253. }
  1254. else {
  1255. var timelineData = current.timelineData;
  1256. var firstFrame = current.timelinesRotation.length == 0;
  1257. if (firstFrame)
  1258. spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  1259. var timelinesRotation = current.timelinesRotation;
  1260. for (var ii = 0; ii < timelineCount; ii++) {
  1261. var timeline = timelines[ii];
  1262. var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
  1263. if (timeline instanceof spine.RotateTimeline) {
  1264. this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
  1265. }
  1266. else {
  1267. spine.Utils.webkit602BugfixHelper(mix, pose);
  1268. timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection["in"]);
  1269. }
  1270. }
  1271. }
  1272. this.queueEvents(current, animationTime);
  1273. events.length = 0;
  1274. current.nextAnimationLast = animationTime;
  1275. current.nextTrackLast = current.trackTime;
  1276. }
  1277. this.queue.drain();
  1278. return applied;
  1279. };
  1280. AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
  1281. var from = to.mixingFrom;
  1282. if (from.mixingFrom != null)
  1283. this.applyMixingFrom(from, skeleton, currentPose);
  1284. var mix = 0;
  1285. if (to.mixDuration == 0) {
  1286. mix = 1;
  1287. currentPose = spine.MixPose.setup;
  1288. }
  1289. else {
  1290. mix = to.mixTime / to.mixDuration;
  1291. if (mix > 1)
  1292. mix = 1;
  1293. }
  1294. var events = mix < from.eventThreshold ? this.events : null;
  1295. var attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  1296. var animationLast = from.animationLast, animationTime = from.getAnimationTime();
  1297. var timelineCount = from.animation.timelines.length;
  1298. var timelines = from.animation.timelines;
  1299. var timelineData = from.timelineData;
  1300. var timelineDipMix = from.timelineDipMix;
  1301. var firstFrame = from.timelinesRotation.length == 0;
  1302. if (firstFrame)
  1303. spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  1304. var timelinesRotation = from.timelinesRotation;
  1305. var pose;
  1306. var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
  1307. from.totalAlpha = 0;
  1308. for (var i = 0; i < timelineCount; i++) {
  1309. var timeline = timelines[i];
  1310. switch (timelineData[i]) {
  1311. case AnimationState.SUBSEQUENT:
  1312. if (!attachments && timeline instanceof spine.AttachmentTimeline)
  1313. continue;
  1314. if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
  1315. continue;
  1316. pose = currentPose;
  1317. alpha = alphaMix;
  1318. break;
  1319. case AnimationState.FIRST:
  1320. pose = spine.MixPose.setup;
  1321. alpha = alphaMix;
  1322. break;
  1323. case AnimationState.DIP:
  1324. pose = spine.MixPose.setup;
  1325. alpha = alphaDip;
  1326. break;
  1327. default:
  1328. pose = spine.MixPose.setup;
  1329. alpha = alphaDip;
  1330. var dipMix = timelineDipMix[i];
  1331. alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
  1332. break;
  1333. }
  1334. from.totalAlpha += alpha;
  1335. if (timeline instanceof spine.RotateTimeline)
  1336. this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
  1337. else {
  1338. spine.Utils.webkit602BugfixHelper(alpha, pose);
  1339. timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
  1340. }
  1341. }
  1342. if (to.mixDuration > 0)
  1343. this.queueEvents(from, animationTime);
  1344. this.events.length = 0;
  1345. from.nextAnimationLast = animationTime;
  1346. from.nextTrackLast = from.trackTime;
  1347. return mix;
  1348. };
  1349. AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
  1350. if (firstFrame)
  1351. timelinesRotation[i] = 0;
  1352. if (alpha == 1) {
  1353. timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection["in"]);
  1354. return;
  1355. }
  1356. var rotateTimeline = timeline;
  1357. var frames = rotateTimeline.frames;
  1358. var bone = skeleton.bones[rotateTimeline.boneIndex];
  1359. if (time < frames[0]) {
  1360. if (pose == spine.MixPose.setup)
  1361. bone.rotation = bone.data.rotation;
  1362. return;
  1363. }
  1364. var r2 = 0;
  1365. if (time >= frames[frames.length - spine.RotateTimeline.ENTRIES])
  1366. r2 = bone.data.rotation + frames[frames.length + spine.RotateTimeline.PREV_ROTATION];
  1367. else {
  1368. var frame = spine.Animation.binarySearch(frames, time, spine.RotateTimeline.ENTRIES);
  1369. var prevRotation = frames[frame + spine.RotateTimeline.PREV_ROTATION];
  1370. var frameTime = frames[frame];
  1371. var percent = rotateTimeline.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + spine.RotateTimeline.PREV_TIME] - frameTime));
  1372. r2 = frames[frame + spine.RotateTimeline.ROTATION] - prevRotation;
  1373. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1374. r2 = prevRotation + r2 * percent + bone.data.rotation;
  1375. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1376. }
  1377. var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
  1378. var total = 0, diff = r2 - r1;
  1379. if (diff == 0) {
  1380. total = timelinesRotation[i];
  1381. }
  1382. else {
  1383. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  1384. var lastTotal = 0, lastDiff = 0;
  1385. if (firstFrame) {
  1386. lastTotal = 0;
  1387. lastDiff = diff;
  1388. }
  1389. else {
  1390. lastTotal = timelinesRotation[i];
  1391. lastDiff = timelinesRotation[i + 1];
  1392. }
  1393. var current = diff > 0, dir = lastTotal >= 0;
  1394. if (spine.MathUtils.signum(lastDiff) != spine.MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  1395. if (Math.abs(lastTotal) > 180)
  1396. lastTotal += 360 * spine.MathUtils.signum(lastTotal);
  1397. dir = current;
  1398. }
  1399. total = diff + lastTotal - lastTotal % 360;
  1400. if (dir != current)
  1401. total += 360 * spine.MathUtils.signum(lastTotal);
  1402. timelinesRotation[i] = total;
  1403. }
  1404. timelinesRotation[i + 1] = diff;
  1405. r1 += total * alpha;
  1406. bone.rotation = r1 - (16384 - ((16384.499999999996 - r1 / 360) | 0)) * 360;
  1407. };
  1408. AnimationState.prototype.queueEvents = function (entry, animationTime) {
  1409. var animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  1410. var duration = animationEnd - animationStart;
  1411. var trackLastWrapped = entry.trackLast % duration;
  1412. var events = this.events;
  1413. var i = 0, n = events.length;
  1414. for (; i < n; i++) {
  1415. var event_1 = events[i];
  1416. if (event_1.time < trackLastWrapped)
  1417. break;
  1418. if (event_1.time > animationEnd)
  1419. continue;
  1420. this.queue.event(entry, event_1);
  1421. }
  1422. var complete = false;
  1423. if (entry.loop)
  1424. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  1425. else
  1426. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  1427. if (complete)
  1428. this.queue.complete(entry);
  1429. for (; i < n; i++) {
  1430. var event_2 = events[i];
  1431. if (event_2.time < animationStart)
  1432. continue;
  1433. this.queue.event(entry, events[i]);
  1434. }
  1435. };
  1436. AnimationState.prototype.clearTracks = function () {
  1437. var oldDrainDisabled = this.queue.drainDisabled;
  1438. this.queue.drainDisabled = true;
  1439. for (var i = 0, n = this.tracks.length; i < n; i++)
  1440. this.clearTrack(i);
  1441. this.tracks.length = 0;
  1442. this.queue.drainDisabled = oldDrainDisabled;
  1443. this.queue.drain();
  1444. };
  1445. AnimationState.prototype.clearTrack = function (trackIndex) {
  1446. if (trackIndex >= this.tracks.length)
  1447. return;
  1448. var current = this.tracks[trackIndex];
  1449. if (current == null)
  1450. return;
  1451. this.queue.end(current);
  1452. this.disposeNext(current);
  1453. var entry = current;
  1454. while (true) {
  1455. var from = entry.mixingFrom;
  1456. if (from == null)
  1457. break;
  1458. this.queue.end(from);
  1459. entry.mixingFrom = null;
  1460. entry = from;
  1461. }
  1462. this.tracks[current.trackIndex] = null;
  1463. this.queue.drain();
  1464. };
  1465. AnimationState.prototype.setCurrent = function (index, current, interrupt) {
  1466. var from = this.expandToIndex(index);
  1467. this.tracks[index] = current;
  1468. if (from != null) {
  1469. if (interrupt)
  1470. this.queue.interrupt(from);
  1471. current.mixingFrom = from;
  1472. current.mixTime = 0;
  1473. if (from.mixingFrom != null && from.mixDuration > 0)
  1474. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  1475. from.timelinesRotation.length = 0;
  1476. }
  1477. this.queue.start(current);
  1478. };
  1479. AnimationState.prototype.setAnimation = function (trackIndex, animationName, loop) {
  1480. var animation = this.data.skeletonData.findAnimation(animationName);
  1481. if (animation == null)
  1482. throw new Error("Animation not found: " + animationName);
  1483. return this.setAnimationWith(trackIndex, animation, loop);
  1484. };
  1485. AnimationState.prototype.setAnimationWith = function (trackIndex, animation, loop) {
  1486. if (animation == null)
  1487. throw new Error("animation cannot be null.");
  1488. var interrupt = true;
  1489. var current = this.expandToIndex(trackIndex);
  1490. if (current != null) {
  1491. if (current.nextTrackLast == -1) {
  1492. this.tracks[trackIndex] = current.mixingFrom;
  1493. this.queue.interrupt(current);
  1494. this.queue.end(current);
  1495. this.disposeNext(current);
  1496. current = current.mixingFrom;
  1497. interrupt = false;
  1498. }
  1499. else
  1500. this.disposeNext(current);
  1501. }
  1502. var entry = this.trackEntry(trackIndex, animation, loop, current);
  1503. this.setCurrent(trackIndex, entry, interrupt);
  1504. this.queue.drain();
  1505. return entry;
  1506. };
  1507. AnimationState.prototype.addAnimation = function (trackIndex, animationName, loop, delay) {
  1508. var animation = this.data.skeletonData.findAnimation(animationName);
  1509. if (animation == null)
  1510. throw new Error("Animation not found: " + animationName);
  1511. return this.addAnimationWith(trackIndex, animation, loop, delay);
  1512. };
  1513. AnimationState.prototype.addAnimationWith = function (trackIndex, animation, loop, delay) {
  1514. if (animation == null)
  1515. throw new Error("animation cannot be null.");
  1516. var last = this.expandToIndex(trackIndex);
  1517. if (last != null) {
  1518. while (last.next != null)
  1519. last = last.next;
  1520. }
  1521. var entry = this.trackEntry(trackIndex, animation, loop, last);
  1522. if (last == null) {
  1523. this.setCurrent(trackIndex, entry, true);
  1524. this.queue.drain();
  1525. }
  1526. else {
  1527. last.next = entry;
  1528. if (delay <= 0) {
  1529. var duration = last.animationEnd - last.animationStart;
  1530. if (duration != 0) {
  1531. if (last.loop)
  1532. delay += duration * (1 + ((last.trackTime / duration) | 0));
  1533. else
  1534. delay += duration;
  1535. delay -= this.data.getMix(last.animation, animation);
  1536. }
  1537. else
  1538. delay = 0;
  1539. }
  1540. }
  1541. entry.delay = delay;
  1542. return entry;
  1543. };
  1544. AnimationState.prototype.setEmptyAnimation = function (trackIndex, mixDuration) {
  1545. var entry = this.setAnimationWith(trackIndex, AnimationState.emptyAnimation, false);
  1546. entry.mixDuration = mixDuration;
  1547. entry.trackEnd = mixDuration;
  1548. return entry;
  1549. };
  1550. AnimationState.prototype.addEmptyAnimation = function (trackIndex, mixDuration, delay) {
  1551. if (delay <= 0)
  1552. delay -= mixDuration;
  1553. var entry = this.addAnimationWith(trackIndex, AnimationState.emptyAnimation, false, delay);
  1554. entry.mixDuration = mixDuration;
  1555. entry.trackEnd = mixDuration;
  1556. return entry;
  1557. };
  1558. AnimationState.prototype.setEmptyAnimations = function (mixDuration) {
  1559. var oldDrainDisabled = this.queue.drainDisabled;
  1560. this.queue.drainDisabled = true;
  1561. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1562. var current = this.tracks[i];
  1563. if (current != null)
  1564. this.setEmptyAnimation(current.trackIndex, mixDuration);
  1565. }
  1566. this.queue.drainDisabled = oldDrainDisabled;
  1567. this.queue.drain();
  1568. };
  1569. AnimationState.prototype.expandToIndex = function (index) {
  1570. if (index < this.tracks.length)
  1571. return this.tracks[index];
  1572. spine.Utils.ensureArrayCapacity(this.tracks, index - this.tracks.length + 1, null);
  1573. this.tracks.length = index + 1;
  1574. return null;
  1575. };
  1576. AnimationState.prototype.trackEntry = function (trackIndex, animation, loop, last) {
  1577. var entry = this.trackEntryPool.obtain();
  1578. entry.trackIndex = trackIndex;
  1579. entry.animation = animation;
  1580. entry.loop = loop;
  1581. entry.eventThreshold = 0;
  1582. entry.attachmentThreshold = 0;
  1583. entry.drawOrderThreshold = 0;
  1584. entry.animationStart = 0;
  1585. entry.animationEnd = animation.duration;
  1586. entry.animationLast = -1;
  1587. entry.nextAnimationLast = -1;
  1588. entry.delay = 0;
  1589. entry.trackTime = 0;
  1590. entry.trackLast = -1;
  1591. entry.nextTrackLast = -1;
  1592. entry.trackEnd = Number.MAX_VALUE;
  1593. entry.timeScale = 1;
  1594. entry.alpha = 1;
  1595. entry.interruptAlpha = 1;
  1596. entry.mixTime = 0;
  1597. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  1598. return entry;
  1599. };
  1600. AnimationState.prototype.disposeNext = function (entry) {
  1601. var next = entry.next;
  1602. while (next != null) {
  1603. this.queue.dispose(next);
  1604. next = next.next;
  1605. }
  1606. entry.next = null;
  1607. };
  1608. AnimationState.prototype._animationsChanged = function () {
  1609. this.animationsChanged = false;
  1610. var propertyIDs = this.propertyIDs;
  1611. propertyIDs.clear();
  1612. var mixingTo = this.mixingTo;
  1613. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1614. var entry = this.tracks[i];
  1615. if (entry != null)
  1616. entry.setTimelineData(null, mixingTo, propertyIDs);
  1617. }
  1618. };
  1619. AnimationState.prototype.getCurrent = function (trackIndex) {
  1620. if (trackIndex >= this.tracks.length)
  1621. return null;
  1622. return this.tracks[trackIndex];
  1623. };
  1624. AnimationState.prototype.addListener = function (listener) {
  1625. if (listener == null)
  1626. throw new Error("listener cannot be null.");
  1627. this.listeners.push(listener);
  1628. };
  1629. AnimationState.prototype.removeListener = function (listener) {
  1630. var index = this.listeners.indexOf(listener);
  1631. if (index >= 0)
  1632. this.listeners.splice(index, 1);
  1633. };
  1634. AnimationState.prototype.clearListeners = function () {
  1635. this.listeners.length = 0;
  1636. };
  1637. AnimationState.prototype.clearListenerNotifications = function () {
  1638. this.queue.clear();
  1639. };
  1640. AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
  1641. AnimationState.SUBSEQUENT = 0;
  1642. AnimationState.FIRST = 1;
  1643. AnimationState.DIP = 2;
  1644. AnimationState.DIP_MIX = 3;
  1645. return AnimationState;
  1646. }());
  1647. spine.AnimationState = AnimationState;
  1648. var TrackEntry = (function () {
  1649. function TrackEntry() {
  1650. this.timelineData = new Array();
  1651. this.timelineDipMix = new Array();
  1652. this.timelinesRotation = new Array();
  1653. }
  1654. TrackEntry.prototype.reset = function () {
  1655. this.next = null;
  1656. this.mixingFrom = null;
  1657. this.animation = null;
  1658. this.listener = null;
  1659. this.timelineData.length = 0;
  1660. this.timelineDipMix.length = 0;
  1661. this.timelinesRotation.length = 0;
  1662. };
  1663. TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
  1664. if (to != null)
  1665. mixingToArray.push(to);
  1666. var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
  1667. if (to != null)
  1668. mixingToArray.pop();
  1669. var mixingTo = mixingToArray;
  1670. var mixingToLast = mixingToArray.length - 1;
  1671. var timelines = this.animation.timelines;
  1672. var timelinesCount = this.animation.timelines.length;
  1673. var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
  1674. this.timelineDipMix.length = 0;
  1675. var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
  1676. outer: for (var i = 0; i < timelinesCount; i++) {
  1677. var id = timelines[i].getPropertyId();
  1678. if (!propertyIDs.add(id))
  1679. timelineData[i] = AnimationState.SUBSEQUENT;
  1680. else if (to == null || !to.hasTimeline(id))
  1681. timelineData[i] = AnimationState.FIRST;
  1682. else {
  1683. for (var ii = mixingToLast; ii >= 0; ii--) {
  1684. var entry = mixingTo[ii];
  1685. if (!entry.hasTimeline(id)) {
  1686. if (entry.mixDuration > 0) {
  1687. timelineData[i] = AnimationState.DIP_MIX;
  1688. timelineDipMix[i] = entry;
  1689. continue outer;
  1690. }
  1691. }
  1692. }
  1693. timelineData[i] = AnimationState.DIP;
  1694. }
  1695. }
  1696. return lastEntry;
  1697. };
  1698. TrackEntry.prototype.hasTimeline = function (id) {
  1699. var timelines = this.animation.timelines;
  1700. for (var i = 0, n = timelines.length; i < n; i++)
  1701. if (timelines[i].getPropertyId() == id)
  1702. return true;
  1703. return false;
  1704. };
  1705. TrackEntry.prototype.getAnimationTime = function () {
  1706. if (this.loop) {
  1707. var duration = this.animationEnd - this.animationStart;
  1708. if (duration == 0)
  1709. return this.animationStart;
  1710. return (this.trackTime % duration) + this.animationStart;
  1711. }
  1712. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  1713. };
  1714. TrackEntry.prototype.setAnimationLast = function (animationLast) {
  1715. this.animationLast = animationLast;
  1716. this.nextAnimationLast = animationLast;
  1717. };
  1718. TrackEntry.prototype.isComplete = function () {
  1719. return this.trackTime >= this.animationEnd - this.animationStart;
  1720. };
  1721. TrackEntry.prototype.resetRotationDirections = function () {
  1722. this.timelinesRotation.length = 0;
  1723. };
  1724. return TrackEntry;
  1725. }());
  1726. spine.TrackEntry = TrackEntry;
  1727. var EventQueue = (function () {
  1728. function EventQueue(animState) {
  1729. this.objects = [];
  1730. this.drainDisabled = false;
  1731. this.animState = animState;
  1732. }
  1733. EventQueue.prototype.start = function (entry) {
  1734. this.objects.push(EventType.start);
  1735. this.objects.push(entry);
  1736. this.animState.animationsChanged = true;
  1737. };
  1738. EventQueue.prototype.interrupt = function (entry) {
  1739. this.objects.push(EventType.interrupt);
  1740. this.objects.push(entry);
  1741. };
  1742. EventQueue.prototype.end = function (entry) {
  1743. this.objects.push(EventType.end);
  1744. this.objects.push(entry);
  1745. this.animState.animationsChanged = true;
  1746. };
  1747. EventQueue.prototype.dispose = function (entry) {
  1748. this.objects.push(EventType.dispose);
  1749. this.objects.push(entry);
  1750. };
  1751. EventQueue.prototype.complete = function (entry) {
  1752. this.objects.push(EventType.complete);
  1753. this.objects.push(entry);
  1754. };
  1755. EventQueue.prototype.event = function (entry, event) {
  1756. this.objects.push(EventType.event);
  1757. this.objects.push(entry);
  1758. this.objects.push(event);
  1759. };
  1760. EventQueue.prototype.drain = function () {
  1761. if (this.drainDisabled)
  1762. return;
  1763. this.drainDisabled = true;
  1764. var objects = this.objects;
  1765. var listeners = this.animState.listeners;
  1766. for (var i = 0; i < objects.length; i += 2) {
  1767. var type = objects[i];
  1768. var entry = objects[i + 1];
  1769. switch (type) {
  1770. case EventType.start:
  1771. if (entry.listener != null && entry.listener.start)
  1772. entry.listener.start(entry);
  1773. for (var ii = 0; ii < listeners.length; ii++)
  1774. if (listeners[ii].start)
  1775. listeners[ii].start(entry);
  1776. break;
  1777. case EventType.interrupt:
  1778. if (entry.listener != null && entry.listener.interrupt)
  1779. entry.listener.interrupt(entry);
  1780. for (var ii = 0; ii < listeners.length; ii++)
  1781. if (listeners[ii].interrupt)
  1782. listeners[ii].interrupt(entry);
  1783. break;
  1784. case EventType.end:
  1785. if (entry.listener != null && entry.listener.end)
  1786. entry.listener.end(entry);
  1787. for (var ii = 0; ii < listeners.length; ii++)
  1788. if (listeners[ii].end)
  1789. listeners[ii].end(entry);
  1790. case EventType.dispose:
  1791. if (entry.listener != null && entry.listener.dispose)
  1792. entry.listener.dispose(entry);
  1793. for (var ii = 0; ii < listeners.length; ii++)
  1794. if (listeners[ii].dispose)
  1795. listeners[ii].dispose(entry);
  1796. this.animState.trackEntryPool.free(entry);
  1797. break;
  1798. case EventType.complete:
  1799. if (entry.listener != null && entry.listener.complete)
  1800. entry.listener.complete(entry);
  1801. for (var ii = 0; ii < listeners.length; ii++)
  1802. if (listeners[ii].complete)
  1803. listeners[ii].complete(entry);
  1804. break;
  1805. case EventType.event:
  1806. var event_3 = objects[i++ + 2];
  1807. if (entry.listener != null && entry.listener.event)
  1808. entry.listener.event(entry, event_3);
  1809. for (var ii = 0; ii < listeners.length; ii++)
  1810. if (listeners[ii].event)
  1811. listeners[ii].event(entry, event_3);
  1812. break;
  1813. }
  1814. }
  1815. this.clear();
  1816. this.drainDisabled = false;
  1817. };
  1818. EventQueue.prototype.clear = function () {
  1819. this.objects.length = 0;
  1820. };
  1821. return EventQueue;
  1822. }());
  1823. spine.EventQueue = EventQueue;
  1824. var EventType;
  1825. (function (EventType) {
  1826. EventType[EventType["start"] = 0] = "start";
  1827. EventType[EventType["interrupt"] = 1] = "interrupt";
  1828. EventType[EventType["end"] = 2] = "end";
  1829. EventType[EventType["dispose"] = 3] = "dispose";
  1830. EventType[EventType["complete"] = 4] = "complete";
  1831. EventType[EventType["event"] = 5] = "event";
  1832. })(EventType = spine.EventType || (spine.EventType = {}));
  1833. var AnimationStateAdapter2 = (function () {
  1834. function AnimationStateAdapter2() {
  1835. }
  1836. AnimationStateAdapter2.prototype.start = function (entry) {
  1837. };
  1838. AnimationStateAdapter2.prototype.interrupt = function (entry) {
  1839. };
  1840. AnimationStateAdapter2.prototype.end = function (entry) {
  1841. };
  1842. AnimationStateAdapter2.prototype.dispose = function (entry) {
  1843. };
  1844. AnimationStateAdapter2.prototype.complete = function (entry) {
  1845. };
  1846. AnimationStateAdapter2.prototype.event = function (entry, event) {
  1847. };
  1848. return AnimationStateAdapter2;
  1849. }());
  1850. spine.AnimationStateAdapter2 = AnimationStateAdapter2;
  1851. })(spine || (spine = {}));
  1852. var spine;
  1853. (function (spine) {
  1854. var AnimationStateData = (function () {
  1855. function AnimationStateData(skeletonData) {
  1856. this.animationToMixTime = {};
  1857. this.defaultMix = 0;
  1858. if (skeletonData == null)
  1859. throw new Error("skeletonData cannot be null.");
  1860. this.skeletonData = skeletonData;
  1861. }
  1862. AnimationStateData.prototype.setMix = function (fromName, toName, duration) {
  1863. var from = this.skeletonData.findAnimation(fromName);
  1864. if (from == null)
  1865. throw new Error("Animation not found: " + fromName);
  1866. var to = this.skeletonData.findAnimation(toName);
  1867. if (to == null)
  1868. throw new Error("Animation not found: " + toName);
  1869. this.setMixWith(from, to, duration);
  1870. };
  1871. AnimationStateData.prototype.setMixWith = function (from, to, duration) {
  1872. if (from == null)
  1873. throw new Error("from cannot be null.");
  1874. if (to == null)
  1875. throw new Error("to cannot be null.");
  1876. var key = from.name + "." + to.name;
  1877. this.animationToMixTime[key] = duration;
  1878. };
  1879. AnimationStateData.prototype.getMix = function (from, to) {
  1880. var key = from.name + "." + to.name;
  1881. var value = this.animationToMixTime[key];
  1882. return value === undefined ? this.defaultMix : value;
  1883. };
  1884. return AnimationStateData;
  1885. }());
  1886. spine.AnimationStateData = AnimationStateData;
  1887. })(spine || (spine = {}));
  1888. var spine;
  1889. (function (spine) {
  1890. var AssetManager = (function () {
  1891. function AssetManager(textureLoader, pathPrefix) {
  1892. if (pathPrefix === void 0) { pathPrefix = ""; }
  1893. this.assets = {};
  1894. this.errors = {};
  1895. this.toLoad = 0;
  1896. this.loaded = 0;
  1897. this.textureLoader = textureLoader;
  1898. this.pathPrefix = pathPrefix;
  1899. }
  1900. AssetManager.downloadText = function (url, success, error) {
  1901. var request = new XMLHttpRequest();
  1902. request.open("GET", url, true);
  1903. request.onload = function () {
  1904. if (request.status == 200) {
  1905. success(request.responseText);
  1906. }
  1907. else {
  1908. error(request.status, request.responseText);
  1909. }
  1910. };
  1911. request.onerror = function () {
  1912. error(request.status, request.responseText);
  1913. };
  1914. request.send();
  1915. };
  1916. AssetManager.downloadBinary = function (url, success, error) {
  1917. var request = new XMLHttpRequest();
  1918. request.open("GET", url, true);
  1919. request.responseType = "arraybuffer";
  1920. request.onload = function () {
  1921. if (request.status == 200) {
  1922. success(new Uint8Array(request.response));
  1923. }
  1924. else {
  1925. error(request.status, request.responseText);
  1926. }
  1927. };
  1928. request.onerror = function () {
  1929. error(request.status, request.responseText);
  1930. };
  1931. request.send();
  1932. };
  1933. AssetManager.prototype.loadText = function (path, success, error) {
  1934. var _this = this;
  1935. if (success === void 0) { success = null; }
  1936. if (error === void 0) { error = null; }
  1937. path = this.pathPrefix + path;
  1938. this.toLoad++;
  1939. AssetManager.downloadText(path, function (data) {
  1940. _this.assets[path] = data;
  1941. if (success)
  1942. success(path, data);
  1943. _this.toLoad--;
  1944. _this.loaded++;
  1945. }, function (state, responseText) {
  1946. _this.errors[path] = "Couldn't load text " + path + ": status " + status + ", " + responseText;
  1947. if (error)
  1948. error(path, "Couldn't load text " + path + ": status " + status + ", " + responseText);
  1949. _this.toLoad--;
  1950. _this.loaded++;
  1951. });
  1952. };
  1953. AssetManager.prototype.loadData = function (path, success, error) {
  1954. var _this = this;
  1955. if (success === void 0) { success = null; }
  1956. if (error === void 0) { error = null; }
  1957. path = this.pathPrefix + path;
  1958. this.toLoad++;
  1959. var request = new XMLHttpRequest();
  1960. request.onreadystatechange = function () {
  1961. if (request.readyState == XMLHttpRequest.DONE) {
  1962. if (request.status >= 200 && request.status < 300) {
  1963. _this.assets[path] = request.response;
  1964. if (success)
  1965. success(path, request.response);
  1966. }
  1967. else {
  1968. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.response;
  1969. if (error)
  1970. error(path, "Couldn't load text " + path + ": status " + request.status + ", " + request.response);
  1971. }
  1972. _this.toLoad--;
  1973. _this.loaded++;
  1974. }
  1975. };
  1976. request.open("GET", path, true);
  1977. request.responseType = 'arraybuffer';
  1978. request.send();
  1979. };
  1980. AssetManager.prototype.loadTexture = function (path, success, error) {
  1981. var _this = this;
  1982. if (success === void 0) { success = null; }
  1983. if (error === void 0) { error = null; }
  1984. path = this.pathPrefix + path;
  1985. this.toLoad++;
  1986. var img = new Image();
  1987. img.crossOrigin = "anonymous";
  1988. img.onload = function (ev) {
  1989. var texture = _this.textureLoader(img);
  1990. _this.assets[path] = texture;
  1991. _this.toLoad--;
  1992. _this.loaded++;
  1993. if (success)
  1994. success(path, img);
  1995. };
  1996. img.onerror = function (ev) {
  1997. _this.errors[path] = "Couldn't load image " + path;
  1998. _this.toLoad--;
  1999. _this.loaded++;
  2000. if (error)
  2001. error(path, "Couldn't load image " + path);
  2002. };
  2003. img.src = path;
  2004. };
  2005. AssetManager.prototype.loadTextureData = function (path, data, success, error) {
  2006. var _this = this;
  2007. if (success === void 0) { success = null; }
  2008. if (error === void 0) { error = null; }
  2009. path = this.pathPrefix + path;
  2010. this.toLoad++;
  2011. var img = new Image();
  2012. img.onload = function (ev) {
  2013. var texture = _this.textureLoader(img);
  2014. _this.assets[path] = texture;
  2015. _this.toLoad--;
  2016. _this.loaded++;
  2017. if (success)
  2018. success(path, img);
  2019. };
  2020. img.onerror = function (ev) {
  2021. _this.errors[path] = "Couldn't load image " + path;
  2022. _this.toLoad--;
  2023. _this.loaded++;
  2024. if (error)
  2025. error(path, "Couldn't load image " + path);
  2026. };
  2027. img.src = data;
  2028. };
  2029. AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
  2030. var _this = this;
  2031. if (success === void 0) { success = null; }
  2032. if (error === void 0) { error = null; }
  2033. var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
  2034. path = this.pathPrefix + path;
  2035. this.toLoad++;
  2036. AssetManager.downloadText(path, function (atlasData) {
  2037. var pagesLoaded = { count: 0 };
  2038. var atlasPages = new Array();
  2039. try {
  2040. var atlas = new spine.TextureAtlas(atlasData, function (path) {
  2041. atlasPages.push(parent + "/" + path);
  2042. var image = document.createElement("img");
  2043. image.width = 16;
  2044. image.height = 16;
  2045. return new spine.FakeTexture(image);
  2046. });
  2047. }
  2048. catch (e) {
  2049. var ex = e;
  2050. _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message;
  2051. if (error)
  2052. error(path, "Couldn't load texture atlas " + path + ": " + ex.message);
  2053. _this.toLoad--;
  2054. _this.loaded++;
  2055. return;
  2056. }
  2057. var _loop_1 = function (atlasPage) {
  2058. var pageLoadError = false;
  2059. _this.loadTexture(atlasPage, function (imagePath, image) {
  2060. pagesLoaded.count++;
  2061. if (pagesLoaded.count == atlasPages.length) {
  2062. if (!pageLoadError) {
  2063. try {
  2064. var atlas = new spine.TextureAtlas(atlasData, function (path) {
  2065. return _this.get(parent + "/" + path);
  2066. });
  2067. _this.assets[path] = atlas;
  2068. if (success)
  2069. success(path, atlas);
  2070. _this.toLoad--;
  2071. _this.loaded++;
  2072. }
  2073. catch (e) {
  2074. var ex = e;
  2075. _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message;
  2076. if (error)
  2077. error(path, "Couldn't load texture atlas " + path + ": " + ex.message);
  2078. _this.toLoad--;
  2079. _this.loaded++;
  2080. }
  2081. }
  2082. else {
  2083. _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path;
  2084. if (error)
  2085. error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path);
  2086. _this.toLoad--;
  2087. _this.loaded++;
  2088. }
  2089. }
  2090. }, function (imagePath, errorMessage) {
  2091. pageLoadError = true;
  2092. pagesLoaded.count++;
  2093. if (pagesLoaded.count == atlasPages.length) {
  2094. _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path;
  2095. if (error)
  2096. error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path);
  2097. _this.toLoad--;
  2098. _this.loaded++;
  2099. }
  2100. });
  2101. };
  2102. for (var _i = 0, atlasPages_1 = atlasPages; _i < atlasPages_1.length; _i++) {
  2103. var atlasPage = atlasPages_1[_i];
  2104. _loop_1(atlasPage);
  2105. }
  2106. }, function (state, responseText) {
  2107. _this.errors[path] = "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText;
  2108. if (error)
  2109. error(path, "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText);
  2110. _this.toLoad--;
  2111. _this.loaded++;
  2112. });
  2113. };
  2114. AssetManager.prototype.get = function (path) {
  2115. path = this.pathPrefix + path;
  2116. return this.assets[path];
  2117. };
  2118. AssetManager.prototype.remove = function (path) {
  2119. path = this.pathPrefix + path;
  2120. var asset = this.assets[path];
  2121. if (asset.dispose)
  2122. asset.dispose();
  2123. this.assets[path] = null;
  2124. };
  2125. AssetManager.prototype.removeAll = function () {
  2126. for (var key in this.assets) {
  2127. var asset = this.assets[key];
  2128. if (asset.dispose)
  2129. asset.dispose();
  2130. }
  2131. this.assets = {};
  2132. };
  2133. AssetManager.prototype.isLoadingComplete = function () {
  2134. return this.toLoad == 0;
  2135. };
  2136. AssetManager.prototype.getToLoad = function () {
  2137. return this.toLoad;
  2138. };
  2139. AssetManager.prototype.getLoaded = function () {
  2140. return this.loaded;
  2141. };
  2142. AssetManager.prototype.dispose = function () {
  2143. this.removeAll();
  2144. };
  2145. AssetManager.prototype.hasErrors = function () {
  2146. return Object.keys(this.errors).length > 0;
  2147. };
  2148. AssetManager.prototype.getErrors = function () {
  2149. return this.errors;
  2150. };
  2151. return AssetManager;
  2152. }());
  2153. spine.AssetManager = AssetManager;
  2154. })(spine || (spine = {}));
  2155. var spine;
  2156. (function (spine) {
  2157. var AtlasAttachmentLoader = (function () {
  2158. function AtlasAttachmentLoader(atlas) {
  2159. this.atlas = atlas;
  2160. }
  2161. AtlasAttachmentLoader.prototype.newRegionAttachment = function (skin, name, path) {
  2162. var region = this.atlas.findRegion(path);
  2163. if (region == null)
  2164. throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  2165. region.renderObject = region;
  2166. var attachment = new spine.RegionAttachment(name);
  2167. attachment.setRegion(region);
  2168. return attachment;
  2169. };
  2170. AtlasAttachmentLoader.prototype.newMeshAttachment = function (skin, name, path) {
  2171. var region = this.atlas.findRegion(path);
  2172. if (region == null)
  2173. throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  2174. region.renderObject = region;
  2175. var attachment = new spine.MeshAttachment(name);
  2176. attachment.region = region;
  2177. return attachment;
  2178. };
  2179. AtlasAttachmentLoader.prototype.newBoundingBoxAttachment = function (skin, name) {
  2180. return new spine.BoundingBoxAttachment(name);
  2181. };
  2182. AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) {
  2183. return new spine.PathAttachment(name);
  2184. };
  2185. AtlasAttachmentLoader.prototype.newPointAttachment = function (skin, name) {
  2186. return new spine.PointAttachment(name);
  2187. };
  2188. AtlasAttachmentLoader.prototype.newClippingAttachment = function (skin, name) {
  2189. return new spine.ClippingAttachment(name);
  2190. };
  2191. return AtlasAttachmentLoader;
  2192. }());
  2193. spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
  2194. })(spine || (spine = {}));
  2195. var spine;
  2196. (function (spine) {
  2197. var BlendMode;
  2198. (function (BlendMode) {
  2199. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  2200. BlendMode[BlendMode["Additive"] = 1] = "Additive";
  2201. BlendMode[BlendMode["Multiply"] = 2] = "Multiply";
  2202. BlendMode[BlendMode["Screen"] = 3] = "Screen";
  2203. })(BlendMode = spine.BlendMode || (spine.BlendMode = {}));
  2204. })(spine || (spine = {}));
  2205. var spine;
  2206. (function (spine) {
  2207. var Bone = (function () {
  2208. function Bone(data, skeleton, parent) {
  2209. this.children = new Array();
  2210. this.x = 0;
  2211. this.y = 0;
  2212. this.rotation = 0;
  2213. this.scaleX = 0;
  2214. this.scaleY = 0;
  2215. this.shearX = 0;
  2216. this.shearY = 0;
  2217. this.ax = 0;
  2218. this.ay = 0;
  2219. this.arotation = 0;
  2220. this.ascaleX = 0;
  2221. this.ascaleY = 0;
  2222. this.ashearX = 0;
  2223. this.ashearY = 0;
  2224. this.appliedValid = false;
  2225. this.a = 0;
  2226. this.b = 0;
  2227. this.worldX = 0;
  2228. this.c = 0;
  2229. this.d = 0;
  2230. this.worldY = 0;
  2231. this.sorted = false;
  2232. if (data == null)
  2233. throw new Error("data cannot be null.");
  2234. if (skeleton == null)
  2235. throw new Error("skeleton cannot be null.");
  2236. this.data = data;
  2237. this.skeleton = skeleton;
  2238. this.parent = parent;
  2239. this.setToSetupPose();
  2240. }
  2241. Bone.prototype.update = function () {
  2242. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2243. };
  2244. Bone.prototype.updateWorldTransform = function () {
  2245. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2246. };
  2247. Bone.prototype.updateWorldTransformWith = function (x, y, rotation, scaleX, scaleY, shearX, shearY) {
  2248. this.ax = x;
  2249. this.ay = y;
  2250. this.arotation = rotation;
  2251. this.ascaleX = scaleX;
  2252. this.ascaleY = scaleY;
  2253. this.ashearX = shearX;
  2254. this.ashearY = shearY;
  2255. this.appliedValid = true;
  2256. var parent = this.parent;
  2257. if (parent == null) {
  2258. var rotationY = rotation + 90 + shearY;
  2259. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2260. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2261. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2262. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2263. var skeleton = this.skeleton;
  2264. if (skeleton.flipX) {
  2265. x = -x;
  2266. la = -la;
  2267. lb = -lb;
  2268. }
  2269. if (skeleton.flipY) {
  2270. y = -y;
  2271. lc = -lc;
  2272. ld = -ld;
  2273. }
  2274. this.a = la;
  2275. this.b = lb;
  2276. this.c = lc;
  2277. this.d = ld;
  2278. this.worldX = x + skeleton.x;
  2279. this.worldY = y + skeleton.y;
  2280. return;
  2281. }
  2282. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2283. this.worldX = pa * x + pb * y + parent.worldX;
  2284. this.worldY = pc * x + pd * y + parent.worldY;
  2285. switch (this.data.transformMode) {
  2286. case spine.TransformMode.Normal: {
  2287. var rotationY = rotation + 90 + shearY;
  2288. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2289. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2290. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2291. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2292. this.a = pa * la + pb * lc;
  2293. this.b = pa * lb + pb * ld;
  2294. this.c = pc * la + pd * lc;
  2295. this.d = pc * lb + pd * ld;
  2296. return;
  2297. }
  2298. case spine.TransformMode.OnlyTranslation: {
  2299. var rotationY = rotation + 90 + shearY;
  2300. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2301. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2302. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2303. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2304. break;
  2305. }
  2306. case spine.TransformMode.NoRotationOrReflection: {
  2307. var s = pa * pa + pc * pc;
  2308. var prx = 0;
  2309. if (s > 0.0001) {
  2310. s = Math.abs(pa * pd - pb * pc) / s;
  2311. pb = pc * s;
  2312. pd = pa * s;
  2313. prx = Math.atan2(pc, pa) * spine.MathUtils.radDeg;
  2314. }
  2315. else {
  2316. pa = 0;
  2317. pc = 0;
  2318. prx = 90 - Math.atan2(pd, pb) * spine.MathUtils.radDeg;
  2319. }
  2320. var rx = rotation + shearX - prx;
  2321. var ry = rotation + shearY - prx + 90;
  2322. var la = spine.MathUtils.cosDeg(rx) * scaleX;
  2323. var lb = spine.MathUtils.cosDeg(ry) * scaleY;
  2324. var lc = spine.MathUtils.sinDeg(rx) * scaleX;
  2325. var ld = spine.MathUtils.sinDeg(ry) * scaleY;
  2326. this.a = pa * la - pb * lc;
  2327. this.b = pa * lb - pb * ld;
  2328. this.c = pc * la + pd * lc;
  2329. this.d = pc * lb + pd * ld;
  2330. break;
  2331. }
  2332. case spine.TransformMode.NoScale:
  2333. case spine.TransformMode.NoScaleOrReflection: {
  2334. var cos = spine.MathUtils.cosDeg(rotation);
  2335. var sin = spine.MathUtils.sinDeg(rotation);
  2336. var za = pa * cos + pb * sin;
  2337. var zc = pc * cos + pd * sin;
  2338. var s = Math.sqrt(za * za + zc * zc);
  2339. if (s > 0.00001)
  2340. s = 1 / s;
  2341. za *= s;
  2342. zc *= s;
  2343. s = Math.sqrt(za * za + zc * zc);
  2344. var r = Math.PI / 2 + Math.atan2(zc, za);
  2345. var zb = Math.cos(r) * s;
  2346. var zd = Math.sin(r) * s;
  2347. var la = spine.MathUtils.cosDeg(shearX) * scaleX;
  2348. var lb = spine.MathUtils.cosDeg(90 + shearY) * scaleY;
  2349. var lc = spine.MathUtils.sinDeg(shearX) * scaleX;
  2350. var ld = spine.MathUtils.sinDeg(90 + shearY) * scaleY;
  2351. if (this.data.transformMode != spine.TransformMode.NoScaleOrReflection ? pa * pd - pb * pc < 0 : this.skeleton.flipX != this.skeleton.flipY) {
  2352. zb = -zb;
  2353. zd = -zd;
  2354. }
  2355. this.a = za * la + zb * lc;
  2356. this.b = za * lb + zb * ld;
  2357. this.c = zc * la + zd * lc;
  2358. this.d = zc * lb + zd * ld;
  2359. return;
  2360. }
  2361. }
  2362. if (this.skeleton.flipX) {
  2363. this.a = -this.a;
  2364. this.b = -this.b;
  2365. }
  2366. if (this.skeleton.flipY) {
  2367. this.c = -this.c;
  2368. this.d = -this.d;
  2369. }
  2370. };
  2371. Bone.prototype.setToSetupPose = function () {
  2372. var data = this.data;
  2373. this.x = data.x;
  2374. this.y = data.y;
  2375. this.rotation = data.rotation;
  2376. this.scaleX = data.scaleX;
  2377. this.scaleY = data.scaleY;
  2378. this.shearX = data.shearX;
  2379. this.shearY = data.shearY;
  2380. };
  2381. Bone.prototype.getWorldRotationX = function () {
  2382. return Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2383. };
  2384. Bone.prototype.getWorldRotationY = function () {
  2385. return Math.atan2(this.d, this.b) * spine.MathUtils.radDeg;
  2386. };
  2387. Bone.prototype.getWorldScaleX = function () {
  2388. return Math.sqrt(this.a * this.a + this.c * this.c);
  2389. };
  2390. Bone.prototype.getWorldScaleY = function () {
  2391. return Math.sqrt(this.b * this.b + this.d * this.d);
  2392. };
  2393. Bone.prototype.updateAppliedTransform = function () {
  2394. this.appliedValid = true;
  2395. var parent = this.parent;
  2396. if (parent == null) {
  2397. this.ax = this.worldX;
  2398. this.ay = this.worldY;
  2399. this.arotation = Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2400. this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c);
  2401. this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d);
  2402. this.ashearX = 0;
  2403. this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * spine.MathUtils.radDeg;
  2404. return;
  2405. }
  2406. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2407. var pid = 1 / (pa * pd - pb * pc);
  2408. var dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY;
  2409. this.ax = (dx * pd * pid - dy * pb * pid);
  2410. this.ay = (dy * pa * pid - dx * pc * pid);
  2411. var ia = pid * pd;
  2412. var id = pid * pa;
  2413. var ib = pid * pb;
  2414. var ic = pid * pc;
  2415. var ra = ia * this.a - ib * this.c;
  2416. var rb = ia * this.b - ib * this.d;
  2417. var rc = id * this.c - ic * this.a;
  2418. var rd = id * this.d - ic * this.b;
  2419. this.ashearX = 0;
  2420. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  2421. if (this.ascaleX > 0.0001) {
  2422. var det = ra * rd - rb * rc;
  2423. this.ascaleY = det / this.ascaleX;
  2424. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * spine.MathUtils.radDeg;
  2425. this.arotation = Math.atan2(rc, ra) * spine.MathUtils.radDeg;
  2426. }
  2427. else {
  2428. this.ascaleX = 0;
  2429. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  2430. this.ashearY = 0;
  2431. this.arotation = 90 - Math.atan2(rd, rb) * spine.MathUtils.radDeg;
  2432. }
  2433. };
  2434. Bone.prototype.worldToLocal = function (world) {
  2435. var a = this.a, b = this.b, c = this.c, d = this.d;
  2436. var invDet = 1 / (a * d - b * c);
  2437. var x = world.x - this.worldX, y = world.y - this.worldY;
  2438. world.x = (x * d * invDet - y * b * invDet);
  2439. world.y = (y * a * invDet - x * c * invDet);
  2440. return world;
  2441. };
  2442. Bone.prototype.localToWorld = function (local) {
  2443. var x = local.x, y = local.y;
  2444. local.x = x * this.a + y * this.b + this.worldX;
  2445. local.y = x * this.c + y * this.d + this.worldY;
  2446. return local;
  2447. };
  2448. Bone.prototype.worldToLocalRotation = function (worldRotation) {
  2449. var sin = spine.MathUtils.sinDeg(worldRotation), cos = spine.MathUtils.cosDeg(worldRotation);
  2450. return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * spine.MathUtils.radDeg;
  2451. };
  2452. Bone.prototype.localToWorldRotation = function (localRotation) {
  2453. var sin = spine.MathUtils.sinDeg(localRotation), cos = spine.MathUtils.cosDeg(localRotation);
  2454. return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * spine.MathUtils.radDeg;
  2455. };
  2456. Bone.prototype.rotateWorld = function (degrees) {
  2457. var a = this.a, b = this.b, c = this.c, d = this.d;
  2458. var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
  2459. this.a = cos * a - sin * c;
  2460. this.b = cos * b - sin * d;
  2461. this.c = sin * a + cos * c;
  2462. this.d = sin * b + cos * d;
  2463. this.appliedValid = false;
  2464. };
  2465. return Bone;
  2466. }());
  2467. spine.Bone = Bone;
  2468. })(spine || (spine = {}));
  2469. var spine;
  2470. (function (spine) {
  2471. var BoneData = (function () {
  2472. function BoneData(index, name, parent) {
  2473. this.x = 0;
  2474. this.y = 0;
  2475. this.rotation = 0;
  2476. this.scaleX = 1;
  2477. this.scaleY = 1;
  2478. this.shearX = 0;
  2479. this.shearY = 0;
  2480. this.transformMode = TransformMode.Normal;
  2481. if (index < 0)
  2482. throw new Error("index must be >= 0.");
  2483. if (name == null)
  2484. throw new Error("name cannot be null.");
  2485. this.index = index;
  2486. this.name = name;
  2487. this.parent = parent;
  2488. }
  2489. return BoneData;
  2490. }());
  2491. spine.BoneData = BoneData;
  2492. var TransformMode;
  2493. (function (TransformMode) {
  2494. TransformMode[TransformMode["Normal"] = 0] = "Normal";
  2495. TransformMode[TransformMode["OnlyTranslation"] = 1] = "OnlyTranslation";
  2496. TransformMode[TransformMode["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
  2497. TransformMode[TransformMode["NoScale"] = 3] = "NoScale";
  2498. TransformMode[TransformMode["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
  2499. })(TransformMode = spine.TransformMode || (spine.TransformMode = {}));
  2500. })(spine || (spine = {}));
  2501. var spine;
  2502. (function (spine) {
  2503. var Event = (function () {
  2504. function Event(time, data) {
  2505. if (data == null)
  2506. throw new Error("data cannot be null.");
  2507. this.time = time;
  2508. this.data = data;
  2509. }
  2510. return Event;
  2511. }());
  2512. spine.Event = Event;
  2513. })(spine || (spine = {}));
  2514. var spine;
  2515. (function (spine) {
  2516. var EventData = (function () {
  2517. function EventData(name) {
  2518. this.name = name;
  2519. }
  2520. return EventData;
  2521. }());
  2522. spine.EventData = EventData;
  2523. })(spine || (spine = {}));
  2524. var spine;
  2525. (function (spine) {
  2526. var IkConstraint = (function () {
  2527. function IkConstraint(data, skeleton) {
  2528. this.mix = 1;
  2529. this.bendDirection = 0;
  2530. if (data == null)
  2531. throw new Error("data cannot be null.");
  2532. if (skeleton == null)
  2533. throw new Error("skeleton cannot be null.");
  2534. this.data = data;
  2535. this.mix = data.mix;
  2536. this.bendDirection = data.bendDirection;
  2537. this.bones = new Array();
  2538. for (var i = 0; i < data.bones.length; i++)
  2539. this.bones.push(skeleton.findBone(data.bones[i].name));
  2540. this.target = skeleton.findBone(data.target.name);
  2541. }
  2542. IkConstraint.prototype.getOrder = function () {
  2543. return this.data.order;
  2544. };
  2545. IkConstraint.prototype.apply = function () {
  2546. this.update();
  2547. };
  2548. IkConstraint.prototype.update = function () {
  2549. var target = this.target;
  2550. var bones = this.bones;
  2551. switch (bones.length) {
  2552. case 1:
  2553. this.apply1(bones[0], target.worldX, target.worldY, this.mix);
  2554. break;
  2555. case 2:
  2556. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.mix);
  2557. break;
  2558. }
  2559. };
  2560. IkConstraint.prototype.apply1 = function (bone, targetX, targetY, alpha) {
  2561. if (!bone.appliedValid)
  2562. bone.updateAppliedTransform();
  2563. var p = bone.parent;
  2564. var id = 1 / (p.a * p.d - p.b * p.c);
  2565. var x = targetX - p.worldX, y = targetY - p.worldY;
  2566. var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
  2567. var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
  2568. if (bone.ascaleX < 0)
  2569. rotationIK += 180;
  2570. if (rotationIK > 180)
  2571. rotationIK -= 360;
  2572. else if (rotationIK < -180)
  2573. rotationIK += 360;
  2574. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, bone.ascaleX, bone.ascaleY, bone.ashearX, bone.ashearY);
  2575. };
  2576. IkConstraint.prototype.apply2 = function (parent, child, targetX, targetY, bendDir, alpha) {
  2577. if (alpha == 0) {
  2578. child.updateWorldTransform();
  2579. return;
  2580. }
  2581. if (!parent.appliedValid)
  2582. parent.updateAppliedTransform();
  2583. if (!child.appliedValid)
  2584. child.updateAppliedTransform();
  2585. var px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, csx = child.ascaleX;
  2586. var os1 = 0, os2 = 0, s2 = 0;
  2587. if (psx < 0) {
  2588. psx = -psx;
  2589. os1 = 180;
  2590. s2 = -1;
  2591. }
  2592. else {
  2593. os1 = 0;
  2594. s2 = 1;
  2595. }
  2596. if (psy < 0) {
  2597. psy = -psy;
  2598. s2 = -s2;
  2599. }
  2600. if (csx < 0) {
  2601. csx = -csx;
  2602. os2 = 180;
  2603. }
  2604. else
  2605. os2 = 0;
  2606. var cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
  2607. var u = Math.abs(psx - psy) <= 0.0001;
  2608. if (!u) {
  2609. cy = 0;
  2610. cwx = a * cx + parent.worldX;
  2611. cwy = c * cx + parent.worldY;
  2612. }
  2613. else {
  2614. cy = child.ay;
  2615. cwx = a * cx + b * cy + parent.worldX;
  2616. cwy = c * cx + d * cy + parent.worldY;
  2617. }
  2618. var pp = parent.parent;
  2619. a = pp.a;
  2620. b = pp.b;
  2621. c = pp.c;
  2622. d = pp.d;
  2623. var id = 1 / (a * d - b * c), x = targetX - pp.worldX, y = targetY - pp.worldY;
  2624. var tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  2625. x = cwx - pp.worldX;
  2626. y = cwy - pp.worldY;
  2627. var dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  2628. var l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1 = 0, a2 = 0;
  2629. outer: if (u) {
  2630. l2 *= psx;
  2631. var cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  2632. if (cos < -1)
  2633. cos = -1;
  2634. else if (cos > 1)
  2635. cos = 1;
  2636. a2 = Math.acos(cos) * bendDir;
  2637. a = l1 + l2 * cos;
  2638. b = l2 * Math.sin(a2);
  2639. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  2640. }
  2641. else {
  2642. a = psx * l2;
  2643. b = psy * l2;
  2644. var aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = Math.atan2(ty, tx);
  2645. c = bb * l1 * l1 + aa * dd - aa * bb;
  2646. var c1 = -2 * bb * l1, c2 = bb - aa;
  2647. d = c1 * c1 - 4 * c2 * c;
  2648. if (d >= 0) {
  2649. var q = Math.sqrt(d);
  2650. if (c1 < 0)
  2651. q = -q;
  2652. q = -(c1 + q) / 2;
  2653. var r0 = q / c2, r1 = c / q;
  2654. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  2655. if (r * r <= dd) {
  2656. y = Math.sqrt(dd - r * r) * bendDir;
  2657. a1 = ta - Math.atan2(y, r);
  2658. a2 = Math.atan2(y / psy, (r - l1) / psx);
  2659. break outer;
  2660. }
  2661. }
  2662. var minAngle = spine.MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  2663. var maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  2664. c = -a * l1 / (aa - bb);
  2665. if (c >= -1 && c <= 1) {
  2666. c = Math.acos(c);
  2667. x = a * Math.cos(c) + l1;
  2668. y = b * Math.sin(c);
  2669. d = x * x + y * y;
  2670. if (d < minDist) {
  2671. minAngle = c;
  2672. minDist = d;
  2673. minX = x;
  2674. minY = y;
  2675. }
  2676. if (d > maxDist) {
  2677. maxAngle = c;
  2678. maxDist = d;
  2679. maxX = x;
  2680. maxY = y;
  2681. }
  2682. }
  2683. if (dd <= (minDist + maxDist) / 2) {
  2684. a1 = ta - Math.atan2(minY * bendDir, minX);
  2685. a2 = minAngle * bendDir;
  2686. }
  2687. else {
  2688. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  2689. a2 = maxAngle * bendDir;
  2690. }
  2691. }
  2692. var os = Math.atan2(cy, cx) * s2;
  2693. var rotation = parent.arotation;
  2694. a1 = (a1 - os) * spine.MathUtils.radDeg + os1 - rotation;
  2695. if (a1 > 180)
  2696. a1 -= 360;
  2697. else if (a1 < -180)
  2698. a1 += 360;
  2699. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, parent.ascaleX, parent.ascaleY, 0, 0);
  2700. rotation = child.arotation;
  2701. a2 = ((a2 + os) * spine.MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  2702. if (a2 > 180)
  2703. a2 -= 360;
  2704. else if (a2 < -180)
  2705. a2 += 360;
  2706. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  2707. };
  2708. return IkConstraint;
  2709. }());
  2710. spine.IkConstraint = IkConstraint;
  2711. })(spine || (spine = {}));
  2712. var spine;
  2713. (function (spine) {
  2714. var IkConstraintData = (function () {
  2715. function IkConstraintData(name) {
  2716. this.order = 0;
  2717. this.bones = new Array();
  2718. this.bendDirection = 1;
  2719. this.mix = 1;
  2720. this.name = name;
  2721. }
  2722. return IkConstraintData;
  2723. }());
  2724. spine.IkConstraintData = IkConstraintData;
  2725. })(spine || (spine = {}));
  2726. var spine;
  2727. (function (spine) {
  2728. var PathConstraint = (function () {
  2729. function PathConstraint(data, skeleton) {
  2730. this.position = 0;
  2731. this.spacing = 0;
  2732. this.rotateMix = 0;
  2733. this.translateMix = 0;
  2734. this.spaces = new Array();
  2735. this.positions = new Array();
  2736. this.world = new Array();
  2737. this.curves = new Array();
  2738. this.lengths = new Array();
  2739. this.segments = new Array();
  2740. if (data == null)
  2741. throw new Error("data cannot be null.");
  2742. if (skeleton == null)
  2743. throw new Error("skeleton cannot be null.");
  2744. this.data = data;
  2745. this.bones = new Array();
  2746. for (var i = 0, n = data.bones.length; i < n; i++)
  2747. this.bones.push(skeleton.findBone(data.bones[i].name));
  2748. this.target = skeleton.findSlot(data.target.name);
  2749. this.position = data.position;
  2750. this.spacing = data.spacing;
  2751. this.rotateMix = data.rotateMix;
  2752. this.translateMix = data.translateMix;
  2753. }
  2754. PathConstraint.prototype.apply = function () {
  2755. this.update();
  2756. };
  2757. PathConstraint.prototype.update = function () {
  2758. var attachment = this.target.getAttachment();
  2759. if (!(attachment instanceof spine.PathAttachment))
  2760. return;
  2761. var rotateMix = this.rotateMix, translateMix = this.translateMix;
  2762. var translate = translateMix > 0, rotate = rotateMix > 0;
  2763. if (!translate && !rotate)
  2764. return;
  2765. var data = this.data;
  2766. var spacingMode = data.spacingMode;
  2767. var lengthSpacing = spacingMode == spine.SpacingMode.Length;
  2768. var rotateMode = data.rotateMode;
  2769. var tangents = rotateMode == spine.RotateMode.Tangent, scale = rotateMode == spine.RotateMode.ChainScale;
  2770. var boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  2771. var bones = this.bones;
  2772. var spaces = spine.Utils.setArraySize(this.spaces, spacesCount), lengths = null;
  2773. var spacing = this.spacing;
  2774. if (scale || lengthSpacing) {
  2775. if (scale)
  2776. lengths = spine.Utils.setArraySize(this.lengths, boneCount);
  2777. for (var i = 0, n = spacesCount - 1; i < n;) {
  2778. var bone = bones[i];
  2779. var setupLength = bone.data.length;
  2780. if (setupLength < PathConstraint.epsilon) {
  2781. if (scale)
  2782. lengths[i] = 0;
  2783. spaces[++i] = 0;
  2784. }
  2785. else {
  2786. var x = setupLength * bone.a, y = setupLength * bone.c;
  2787. var length_1 = Math.sqrt(x * x + y * y);
  2788. if (scale)
  2789. lengths[i] = length_1;
  2790. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length_1 / setupLength;
  2791. }
  2792. }
  2793. }
  2794. else {
  2795. for (var i = 1; i < spacesCount; i++)
  2796. spaces[i] = spacing;
  2797. }
  2798. var positions = this.computeWorldPositions(attachment, spacesCount, tangents, data.positionMode == spine.PositionMode.Percent, spacingMode == spine.SpacingMode.Percent);
  2799. var boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  2800. var tip = false;
  2801. if (offsetRotation == 0)
  2802. tip = rotateMode == spine.RotateMode.Chain;
  2803. else {
  2804. tip = false;
  2805. var p = this.target.bone;
  2806. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  2807. }
  2808. for (var i = 0, p = 3; i < boneCount; i++, p += 3) {
  2809. var bone = bones[i];
  2810. bone.worldX += (boneX - bone.worldX) * translateMix;
  2811. bone.worldY += (boneY - bone.worldY) * translateMix;
  2812. var x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  2813. if (scale) {
  2814. var length_2 = lengths[i];
  2815. if (length_2 != 0) {
  2816. var s = (Math.sqrt(dx * dx + dy * dy) / length_2 - 1) * rotateMix + 1;
  2817. bone.a *= s;
  2818. bone.c *= s;
  2819. }
  2820. }
  2821. boneX = x;
  2822. boneY = y;
  2823. if (rotate) {
  2824. var a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
  2825. if (tangents)
  2826. r = positions[p - 1];
  2827. else if (spaces[i + 1] == 0)
  2828. r = positions[p + 2];
  2829. else
  2830. r = Math.atan2(dy, dx);
  2831. r -= Math.atan2(c, a);
  2832. if (tip) {
  2833. cos = Math.cos(r);
  2834. sin = Math.sin(r);
  2835. var length_3 = bone.data.length;
  2836. boneX += (length_3 * (cos * a - sin * c) - dx) * rotateMix;
  2837. boneY += (length_3 * (sin * a + cos * c) - dy) * rotateMix;
  2838. }
  2839. else {
  2840. r += offsetRotation;
  2841. }
  2842. if (r > spine.MathUtils.PI)
  2843. r -= spine.MathUtils.PI2;
  2844. else if (r < -spine.MathUtils.PI)
  2845. r += spine.MathUtils.PI2;
  2846. r *= rotateMix;
  2847. cos = Math.cos(r);
  2848. sin = Math.sin(r);
  2849. bone.a = cos * a - sin * c;
  2850. bone.b = cos * b - sin * d;
  2851. bone.c = sin * a + cos * c;
  2852. bone.d = sin * b + cos * d;
  2853. }
  2854. bone.appliedValid = false;
  2855. }
  2856. };
  2857. PathConstraint.prototype.computeWorldPositions = function (path, spacesCount, tangents, percentPosition, percentSpacing) {
  2858. var target = this.target;
  2859. var position = this.position;
  2860. var spaces = this.spaces, out = spine.Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  2861. var closed = path.closed;
  2862. var verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint.NONE;
  2863. if (!path.constantSpeed) {
  2864. var lengths = path.lengths;
  2865. curveCount -= closed ? 1 : 2;
  2866. var pathLength_1 = lengths[curveCount];
  2867. if (percentPosition)
  2868. position *= pathLength_1;
  2869. if (percentSpacing) {
  2870. for (var i = 0; i < spacesCount; i++)
  2871. spaces[i] *= pathLength_1;
  2872. }
  2873. world = spine.Utils.setArraySize(this.world, 8);
  2874. for (var i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  2875. var space = spaces[i];
  2876. position += space;
  2877. var p = position;
  2878. if (closed) {
  2879. p %= pathLength_1;
  2880. if (p < 0)
  2881. p += pathLength_1;
  2882. curve = 0;
  2883. }
  2884. else if (p < 0) {
  2885. if (prevCurve != PathConstraint.BEFORE) {
  2886. prevCurve = PathConstraint.BEFORE;
  2887. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  2888. }
  2889. this.addBeforePosition(p, world, 0, out, o);
  2890. continue;
  2891. }
  2892. else if (p > pathLength_1) {
  2893. if (prevCurve != PathConstraint.AFTER) {
  2894. prevCurve = PathConstraint.AFTER;
  2895. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  2896. }
  2897. this.addAfterPosition(p - pathLength_1, world, 0, out, o);
  2898. continue;
  2899. }
  2900. for (;; curve++) {
  2901. var length_4 = lengths[curve];
  2902. if (p > length_4)
  2903. continue;
  2904. if (curve == 0)
  2905. p /= length_4;
  2906. else {
  2907. var prev = lengths[curve - 1];
  2908. p = (p - prev) / (length_4 - prev);
  2909. }
  2910. break;
  2911. }
  2912. if (curve != prevCurve) {
  2913. prevCurve = curve;
  2914. if (closed && curve == curveCount) {
  2915. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  2916. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  2917. }
  2918. else
  2919. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  2920. }
  2921. this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o, tangents || (i > 0 && space == 0));
  2922. }
  2923. return out;
  2924. }
  2925. if (closed) {
  2926. verticesLength += 2;
  2927. world = spine.Utils.setArraySize(this.world, verticesLength);
  2928. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  2929. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  2930. world[verticesLength - 2] = world[0];
  2931. world[verticesLength - 1] = world[1];
  2932. }
  2933. else {
  2934. curveCount--;
  2935. verticesLength -= 4;
  2936. world = spine.Utils.setArraySize(this.world, verticesLength);
  2937. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  2938. }
  2939. var curves = spine.Utils.setArraySize(this.curves, curveCount);
  2940. var pathLength = 0;
  2941. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  2942. var tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  2943. for (var i = 0, w = 2; i < curveCount; i++, w += 6) {
  2944. cx1 = world[w];
  2945. cy1 = world[w + 1];
  2946. cx2 = world[w + 2];
  2947. cy2 = world[w + 3];
  2948. x2 = world[w + 4];
  2949. y2 = world[w + 5];
  2950. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  2951. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  2952. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  2953. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  2954. ddfx = tmpx * 2 + dddfx;
  2955. ddfy = tmpy * 2 + dddfy;
  2956. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  2957. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  2958. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2959. dfx += ddfx;
  2960. dfy += ddfy;
  2961. ddfx += dddfx;
  2962. ddfy += dddfy;
  2963. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2964. dfx += ddfx;
  2965. dfy += ddfy;
  2966. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2967. dfx += ddfx + dddfx;
  2968. dfy += ddfy + dddfy;
  2969. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2970. curves[i] = pathLength;
  2971. x1 = x2;
  2972. y1 = y2;
  2973. }
  2974. if (percentPosition)
  2975. position *= pathLength;
  2976. if (percentSpacing) {
  2977. for (var i = 0; i < spacesCount; i++)
  2978. spaces[i] *= pathLength;
  2979. }
  2980. var segments = this.segments;
  2981. var curveLength = 0;
  2982. for (var i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  2983. var space = spaces[i];
  2984. position += space;
  2985. var p = position;
  2986. if (closed) {
  2987. p %= pathLength;
  2988. if (p < 0)
  2989. p += pathLength;
  2990. curve = 0;
  2991. }
  2992. else if (p < 0) {
  2993. this.addBeforePosition(p, world, 0, out, o);
  2994. continue;
  2995. }
  2996. else if (p > pathLength) {
  2997. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  2998. continue;
  2999. }
  3000. for (;; curve++) {
  3001. var length_5 = curves[curve];
  3002. if (p > length_5)
  3003. continue;
  3004. if (curve == 0)
  3005. p /= length_5;
  3006. else {
  3007. var prev = curves[curve - 1];
  3008. p = (p - prev) / (length_5 - prev);
  3009. }
  3010. break;
  3011. }
  3012. if (curve != prevCurve) {
  3013. prevCurve = curve;
  3014. var ii = curve * 6;
  3015. x1 = world[ii];
  3016. y1 = world[ii + 1];
  3017. cx1 = world[ii + 2];
  3018. cy1 = world[ii + 3];
  3019. cx2 = world[ii + 4];
  3020. cy2 = world[ii + 5];
  3021. x2 = world[ii + 6];
  3022. y2 = world[ii + 7];
  3023. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  3024. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  3025. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  3026. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  3027. ddfx = tmpx * 2 + dddfx;
  3028. ddfy = tmpy * 2 + dddfy;
  3029. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  3030. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  3031. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  3032. segments[0] = curveLength;
  3033. for (ii = 1; ii < 8; ii++) {
  3034. dfx += ddfx;
  3035. dfy += ddfy;
  3036. ddfx += dddfx;
  3037. ddfy += dddfy;
  3038. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3039. segments[ii] = curveLength;
  3040. }
  3041. dfx += ddfx;
  3042. dfy += ddfy;
  3043. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3044. segments[8] = curveLength;
  3045. dfx += ddfx + dddfx;
  3046. dfy += ddfy + dddfy;
  3047. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3048. segments[9] = curveLength;
  3049. segment = 0;
  3050. }
  3051. p *= curveLength;
  3052. for (;; segment++) {
  3053. var length_6 = segments[segment];
  3054. if (p > length_6)
  3055. continue;
  3056. if (segment == 0)
  3057. p /= length_6;
  3058. else {
  3059. var prev = segments[segment - 1];
  3060. p = segment + (p - prev) / (length_6 - prev);
  3061. }
  3062. break;
  3063. }
  3064. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  3065. }
  3066. return out;
  3067. };
  3068. PathConstraint.prototype.addBeforePosition = function (p, temp, i, out, o) {
  3069. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  3070. out[o] = x1 + p * Math.cos(r);
  3071. out[o + 1] = y1 + p * Math.sin(r);
  3072. out[o + 2] = r;
  3073. };
  3074. PathConstraint.prototype.addAfterPosition = function (p, temp, i, out, o) {
  3075. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  3076. out[o] = x1 + p * Math.cos(r);
  3077. out[o + 1] = y1 + p * Math.sin(r);
  3078. out[o + 2] = r;
  3079. };
  3080. PathConstraint.prototype.addCurvePosition = function (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  3081. if (p == 0 || isNaN(p))
  3082. p = 0.0001;
  3083. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  3084. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  3085. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  3086. out[o] = x;
  3087. out[o + 1] = y;
  3088. if (tangents)
  3089. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  3090. };
  3091. PathConstraint.prototype.getOrder = function () {
  3092. return this.data.order;
  3093. };
  3094. PathConstraint.NONE = -1;
  3095. PathConstraint.BEFORE = -2;
  3096. PathConstraint.AFTER = -3;
  3097. PathConstraint.epsilon = 0.00001;
  3098. return PathConstraint;
  3099. }());
  3100. spine.PathConstraint = PathConstraint;
  3101. })(spine || (spine = {}));
  3102. var spine;
  3103. (function (spine) {
  3104. var PathConstraintData = (function () {
  3105. function PathConstraintData(name) {
  3106. this.order = 0;
  3107. this.bones = new Array();
  3108. this.name = name;
  3109. }
  3110. return PathConstraintData;
  3111. }());
  3112. spine.PathConstraintData = PathConstraintData;
  3113. var PositionMode;
  3114. (function (PositionMode) {
  3115. PositionMode[PositionMode["Fixed"] = 0] = "Fixed";
  3116. PositionMode[PositionMode["Percent"] = 1] = "Percent";
  3117. })(PositionMode = spine.PositionMode || (spine.PositionMode = {}));
  3118. var SpacingMode;
  3119. (function (SpacingMode) {
  3120. SpacingMode[SpacingMode["Length"] = 0] = "Length";
  3121. SpacingMode[SpacingMode["Fixed"] = 1] = "Fixed";
  3122. SpacingMode[SpacingMode["Percent"] = 2] = "Percent";
  3123. })(SpacingMode = spine.SpacingMode || (spine.SpacingMode = {}));
  3124. var RotateMode;
  3125. (function (RotateMode) {
  3126. RotateMode[RotateMode["Tangent"] = 0] = "Tangent";
  3127. RotateMode[RotateMode["Chain"] = 1] = "Chain";
  3128. RotateMode[RotateMode["ChainScale"] = 2] = "ChainScale";
  3129. })(RotateMode = spine.RotateMode || (spine.RotateMode = {}));
  3130. })(spine || (spine = {}));
  3131. var spine;
  3132. (function (spine) {
  3133. var Assets = (function () {
  3134. function Assets(clientId) {
  3135. this.toLoad = new Array();
  3136. this.assets = {};
  3137. this.clientId = clientId;
  3138. }
  3139. Assets.prototype.loaded = function () {
  3140. var i = 0;
  3141. for (var v in this.assets)
  3142. i++;
  3143. return i;
  3144. };
  3145. return Assets;
  3146. }());
  3147. var SharedAssetManager = (function () {
  3148. function SharedAssetManager(pathPrefix) {
  3149. if (pathPrefix === void 0) { pathPrefix = ""; }
  3150. this.clientAssets = {};
  3151. this.queuedAssets = {};
  3152. this.rawAssets = {};
  3153. this.errors = {};
  3154. this.pathPrefix = pathPrefix;
  3155. }
  3156. SharedAssetManager.prototype.queueAsset = function (clientId, textureLoader, path) {
  3157. var clientAssets = this.clientAssets[clientId];
  3158. if (clientAssets === null || clientAssets === undefined) {
  3159. clientAssets = new Assets(clientId);
  3160. this.clientAssets[clientId] = clientAssets;
  3161. }
  3162. if (textureLoader !== null)
  3163. clientAssets.textureLoader = textureLoader;
  3164. clientAssets.toLoad.push(path);
  3165. if (this.queuedAssets[path] === path) {
  3166. return false;
  3167. }
  3168. else {
  3169. this.queuedAssets[path] = path;
  3170. return true;
  3171. }
  3172. };
  3173. SharedAssetManager.prototype.loadText = function (clientId, path) {
  3174. var _this = this;
  3175. path = this.pathPrefix + path;
  3176. if (!this.queueAsset(clientId, null, path))
  3177. return;
  3178. var request = new XMLHttpRequest();
  3179. request.onreadystatechange = function () {
  3180. if (request.readyState == XMLHttpRequest.DONE) {
  3181. if (request.status >= 200 && request.status < 300) {
  3182. _this.rawAssets[path] = request.responseText;
  3183. }
  3184. else {
  3185. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3186. }
  3187. }
  3188. };
  3189. request.open("GET", path, true);
  3190. request.send();
  3191. };
  3192. SharedAssetManager.prototype.loadJson = function (clientId, path) {
  3193. var _this = this;
  3194. path = this.pathPrefix + path;
  3195. if (!this.queueAsset(clientId, null, path))
  3196. return;
  3197. var request = new XMLHttpRequest();
  3198. request.onreadystatechange = function () {
  3199. if (request.readyState == XMLHttpRequest.DONE) {
  3200. if (request.status >= 200 && request.status < 300) {
  3201. _this.rawAssets[path] = JSON.parse(request.responseText);
  3202. }
  3203. else {
  3204. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3205. }
  3206. }
  3207. };
  3208. request.open("GET", path, true);
  3209. request.send();
  3210. };
  3211. SharedAssetManager.prototype.loadTexture = function (clientId, textureLoader, path) {
  3212. var _this = this;
  3213. path = this.pathPrefix + path;
  3214. if (!this.queueAsset(clientId, textureLoader, path))
  3215. return;
  3216. var img = new Image();
  3217. img.src = path;
  3218. img.crossOrigin = "anonymous";
  3219. img.onload = function (ev) {
  3220. _this.rawAssets[path] = img;
  3221. };
  3222. img.onerror = function (ev) {
  3223. _this.errors[path] = "Couldn't load image " + path;
  3224. };
  3225. };
  3226. SharedAssetManager.prototype.get = function (clientId, path) {
  3227. path = this.pathPrefix + path;
  3228. var clientAssets = this.clientAssets[clientId];
  3229. if (clientAssets === null || clientAssets === undefined)
  3230. return true;
  3231. return clientAssets.assets[path];
  3232. };
  3233. SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
  3234. for (var i = 0; i < clientAssets.toLoad.length; i++) {
  3235. var path = clientAssets.toLoad[i];
  3236. var asset = clientAssets.assets[path];
  3237. if (asset === null || asset === undefined) {
  3238. var rawAsset = this.rawAssets[path];
  3239. if (rawAsset === null || rawAsset === undefined)
  3240. continue;
  3241. if (rawAsset instanceof HTMLImageElement) {
  3242. clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
  3243. }
  3244. else {
  3245. clientAssets.assets[path] = rawAsset;
  3246. }
  3247. }
  3248. }
  3249. };
  3250. SharedAssetManager.prototype.isLoadingComplete = function (clientId) {
  3251. var clientAssets = this.clientAssets[clientId];
  3252. if (clientAssets === null || clientAssets === undefined)
  3253. return true;
  3254. this.updateClientAssets(clientAssets);
  3255. return clientAssets.toLoad.length == clientAssets.loaded();
  3256. };
  3257. SharedAssetManager.prototype.dispose = function () {
  3258. };
  3259. SharedAssetManager.prototype.hasErrors = function () {
  3260. return Object.keys(this.errors).length > 0;
  3261. };
  3262. SharedAssetManager.prototype.getErrors = function () {
  3263. return this.errors;
  3264. };
  3265. return SharedAssetManager;
  3266. }());
  3267. spine.SharedAssetManager = SharedAssetManager;
  3268. })(spine || (spine = {}));
  3269. var spine;
  3270. (function (spine) {
  3271. var Skeleton = (function () {
  3272. function Skeleton(data) {
  3273. this._updateCache = new Array();
  3274. this.updateCacheReset = new Array();
  3275. this.time = 0;
  3276. this.flipX = false;
  3277. this.flipY = false;
  3278. this.x = 0;
  3279. this.y = 0;
  3280. if (data == null)
  3281. throw new Error("data cannot be null.");
  3282. this.data = data;
  3283. this.bones = new Array();
  3284. for (var i = 0; i < data.bones.length; i++) {
  3285. var boneData = data.bones[i];
  3286. var bone = void 0;
  3287. if (boneData.parent == null)
  3288. bone = new spine.Bone(boneData, this, null);
  3289. else {
  3290. var parent_1 = this.bones[boneData.parent.index];
  3291. bone = new spine.Bone(boneData, this, parent_1);
  3292. parent_1.children.push(bone);
  3293. }
  3294. this.bones.push(bone);
  3295. }
  3296. this.slots = new Array();
  3297. this.drawOrder = new Array();
  3298. for (var i = 0; i < data.slots.length; i++) {
  3299. var slotData = data.slots[i];
  3300. var bone = this.bones[slotData.boneData.index];
  3301. var slot = new spine.Slot(slotData, bone);
  3302. this.slots.push(slot);
  3303. this.drawOrder.push(slot);
  3304. }
  3305. this.ikConstraints = new Array();
  3306. for (var i = 0; i < data.ikConstraints.length; i++) {
  3307. var ikConstraintData = data.ikConstraints[i];
  3308. this.ikConstraints.push(new spine.IkConstraint(ikConstraintData, this));
  3309. }
  3310. this.transformConstraints = new Array();
  3311. for (var i = 0; i < data.transformConstraints.length; i++) {
  3312. var transformConstraintData = data.transformConstraints[i];
  3313. this.transformConstraints.push(new spine.TransformConstraint(transformConstraintData, this));
  3314. }
  3315. this.pathConstraints = new Array();
  3316. for (var i = 0; i < data.pathConstraints.length; i++) {
  3317. var pathConstraintData = data.pathConstraints[i];
  3318. this.pathConstraints.push(new spine.PathConstraint(pathConstraintData, this));
  3319. }
  3320. this.color = new spine.Color(1, 1, 1, 1);
  3321. this.updateCache();
  3322. }
  3323. Skeleton.prototype.updateCache = function () {
  3324. var updateCache = this._updateCache;
  3325. updateCache.length = 0;
  3326. this.updateCacheReset.length = 0;
  3327. var bones = this.bones;
  3328. for (var i = 0, n = bones.length; i < n; i++)
  3329. bones[i].sorted = false;
  3330. var ikConstraints = this.ikConstraints;
  3331. var transformConstraints = this.transformConstraints;
  3332. var pathConstraints = this.pathConstraints;
  3333. var ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  3334. var constraintCount = ikCount + transformCount + pathCount;
  3335. outer: for (var i = 0; i < constraintCount; i++) {
  3336. for (var ii = 0; ii < ikCount; ii++) {
  3337. var constraint = ikConstraints[ii];
  3338. if (constraint.data.order == i) {
  3339. this.sortIkConstraint(constraint);
  3340. continue outer;
  3341. }
  3342. }
  3343. for (var ii = 0; ii < transformCount; ii++) {
  3344. var constraint = transformConstraints[ii];
  3345. if (constraint.data.order == i) {
  3346. this.sortTransformConstraint(constraint);
  3347. continue outer;
  3348. }
  3349. }
  3350. for (var ii = 0; ii < pathCount; ii++) {
  3351. var constraint = pathConstraints[ii];
  3352. if (constraint.data.order == i) {
  3353. this.sortPathConstraint(constraint);
  3354. continue outer;
  3355. }
  3356. }
  3357. }
  3358. for (var i = 0, n = bones.length; i < n; i++)
  3359. this.sortBone(bones[i]);
  3360. };
  3361. Skeleton.prototype.sortIkConstraint = function (constraint) {
  3362. var target = constraint.target;
  3363. this.sortBone(target);
  3364. var constrained = constraint.bones;
  3365. var parent = constrained[0];
  3366. this.sortBone(parent);
  3367. if (constrained.length > 1) {
  3368. var child = constrained[constrained.length - 1];
  3369. if (!(this._updateCache.indexOf(child) > -1))
  3370. this.updateCacheReset.push(child);
  3371. }
  3372. this._updateCache.push(constraint);
  3373. this.sortReset(parent.children);
  3374. constrained[constrained.length - 1].sorted = true;
  3375. };
  3376. Skeleton.prototype.sortPathConstraint = function (constraint) {
  3377. var slot = constraint.target;
  3378. var slotIndex = slot.data.index;
  3379. var slotBone = slot.bone;
  3380. if (this.skin != null)
  3381. this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  3382. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  3383. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  3384. for (var i = 0, n = this.data.skins.length; i < n; i++)
  3385. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  3386. var attachment = slot.getAttachment();
  3387. if (attachment instanceof spine.PathAttachment)
  3388. this.sortPathConstraintAttachmentWith(attachment, slotBone);
  3389. var constrained = constraint.bones;
  3390. var boneCount = constrained.length;
  3391. for (var i = 0; i < boneCount; i++)
  3392. this.sortBone(constrained[i]);
  3393. this._updateCache.push(constraint);
  3394. for (var i = 0; i < boneCount; i++)
  3395. this.sortReset(constrained[i].children);
  3396. for (var i = 0; i < boneCount; i++)
  3397. constrained[i].sorted = true;
  3398. };
  3399. Skeleton.prototype.sortTransformConstraint = function (constraint) {
  3400. this.sortBone(constraint.target);
  3401. var constrained = constraint.bones;
  3402. var boneCount = constrained.length;
  3403. if (constraint.data.local) {
  3404. for (var i = 0; i < boneCount; i++) {
  3405. var child = constrained[i];
  3406. this.sortBone(child.parent);
  3407. if (!(this._updateCache.indexOf(child) > -1))
  3408. this.updateCacheReset.push(child);
  3409. }
  3410. }
  3411. else {
  3412. for (var i = 0; i < boneCount; i++) {
  3413. this.sortBone(constrained[i]);
  3414. }
  3415. }
  3416. this._updateCache.push(constraint);
  3417. for (var ii = 0; ii < boneCount; ii++)
  3418. this.sortReset(constrained[ii].children);
  3419. for (var ii = 0; ii < boneCount; ii++)
  3420. constrained[ii].sorted = true;
  3421. };
  3422. Skeleton.prototype.sortPathConstraintAttachment = function (skin, slotIndex, slotBone) {
  3423. var attachments = skin.attachments[slotIndex];
  3424. if (!attachments)
  3425. return;
  3426. for (var key in attachments) {
  3427. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  3428. }
  3429. };
  3430. Skeleton.prototype.sortPathConstraintAttachmentWith = function (attachment, slotBone) {
  3431. if (!(attachment instanceof spine.PathAttachment))
  3432. return;
  3433. var pathBones = attachment.bones;
  3434. if (pathBones == null)
  3435. this.sortBone(slotBone);
  3436. else {
  3437. var bones = this.bones;
  3438. var i = 0;
  3439. while (i < pathBones.length) {
  3440. var boneCount = pathBones[i++];
  3441. for (var n = i + boneCount; i < n; i++) {
  3442. var boneIndex = pathBones[i];
  3443. this.sortBone(bones[boneIndex]);
  3444. }
  3445. }
  3446. }
  3447. };
  3448. Skeleton.prototype.sortBone = function (bone) {
  3449. if (bone.sorted)
  3450. return;
  3451. var parent = bone.parent;
  3452. if (parent != null)
  3453. this.sortBone(parent);
  3454. bone.sorted = true;
  3455. this._updateCache.push(bone);
  3456. };
  3457. Skeleton.prototype.sortReset = function (bones) {
  3458. for (var i = 0, n = bones.length; i < n; i++) {
  3459. var bone = bones[i];
  3460. if (bone.sorted)
  3461. this.sortReset(bone.children);
  3462. bone.sorted = false;
  3463. }
  3464. };
  3465. Skeleton.prototype.updateWorldTransform = function () {
  3466. var updateCacheReset = this.updateCacheReset;
  3467. for (var i = 0, n = updateCacheReset.length; i < n; i++) {
  3468. var bone = updateCacheReset[i];
  3469. bone.ax = bone.x;
  3470. bone.ay = bone.y;
  3471. bone.arotation = bone.rotation;
  3472. bone.ascaleX = bone.scaleX;
  3473. bone.ascaleY = bone.scaleY;
  3474. bone.ashearX = bone.shearX;
  3475. bone.ashearY = bone.shearY;
  3476. bone.appliedValid = true;
  3477. }
  3478. var updateCache = this._updateCache;
  3479. for (var i = 0, n = updateCache.length; i < n; i++)
  3480. updateCache[i].update();
  3481. };
  3482. Skeleton.prototype.setToSetupPose = function () {
  3483. this.setBonesToSetupPose();
  3484. this.setSlotsToSetupPose();
  3485. };
  3486. Skeleton.prototype.setBonesToSetupPose = function () {
  3487. var bones = this.bones;
  3488. for (var i = 0, n = bones.length; i < n; i++)
  3489. bones[i].setToSetupPose();
  3490. var ikConstraints = this.ikConstraints;
  3491. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  3492. var constraint = ikConstraints[i];
  3493. constraint.bendDirection = constraint.data.bendDirection;
  3494. constraint.mix = constraint.data.mix;
  3495. }
  3496. var transformConstraints = this.transformConstraints;
  3497. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  3498. var constraint = transformConstraints[i];
  3499. var data = constraint.data;
  3500. constraint.rotateMix = data.rotateMix;
  3501. constraint.translateMix = data.translateMix;
  3502. constraint.scaleMix = data.scaleMix;
  3503. constraint.shearMix = data.shearMix;
  3504. }
  3505. var pathConstraints = this.pathConstraints;
  3506. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  3507. var constraint = pathConstraints[i];
  3508. var data = constraint.data;
  3509. constraint.position = data.position;
  3510. constraint.spacing = data.spacing;
  3511. constraint.rotateMix = data.rotateMix;
  3512. constraint.translateMix = data.translateMix;
  3513. }
  3514. };
  3515. Skeleton.prototype.setSlotsToSetupPose = function () {
  3516. var slots = this.slots;
  3517. spine.Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  3518. for (var i = 0, n = slots.length; i < n; i++)
  3519. slots[i].setToSetupPose();
  3520. };
  3521. Skeleton.prototype.getRootBone = function () {
  3522. if (this.bones.length == 0)
  3523. return null;
  3524. return this.bones[0];
  3525. };
  3526. Skeleton.prototype.findBone = function (boneName) {
  3527. if (boneName == null)
  3528. throw new Error("boneName cannot be null.");
  3529. var bones = this.bones;
  3530. for (var i = 0, n = bones.length; i < n; i++) {
  3531. var bone = bones[i];
  3532. if (bone.data.name == boneName)
  3533. return bone;
  3534. }
  3535. return null;
  3536. };
  3537. Skeleton.prototype.findBoneIndex = function (boneName) {
  3538. if (boneName == null)
  3539. throw new Error("boneName cannot be null.");
  3540. var bones = this.bones;
  3541. for (var i = 0, n = bones.length; i < n; i++)
  3542. if (bones[i].data.name == boneName)
  3543. return i;
  3544. return -1;
  3545. };
  3546. Skeleton.prototype.findSlot = function (slotName) {
  3547. if (slotName == null)
  3548. throw new Error("slotName cannot be null.");
  3549. var slots = this.slots;
  3550. for (var i = 0, n = slots.length; i < n; i++) {
  3551. var slot = slots[i];
  3552. if (slot.data.name == slotName)
  3553. return slot;
  3554. }
  3555. return null;
  3556. };
  3557. Skeleton.prototype.findSlotIndex = function (slotName) {
  3558. if (slotName == null)
  3559. throw new Error("slotName cannot be null.");
  3560. var slots = this.slots;
  3561. for (var i = 0, n = slots.length; i < n; i++)
  3562. if (slots[i].data.name == slotName)
  3563. return i;
  3564. return -1;
  3565. };
  3566. Skeleton.prototype.setSkinByName = function (skinName) {
  3567. var skin = this.data.findSkin(skinName);
  3568. if (skin == null)
  3569. throw new Error("Skin not found: " + skinName);
  3570. this.setSkin(skin);
  3571. };
  3572. Skeleton.prototype.setSkin = function (newSkin) {
  3573. if (newSkin != null) {
  3574. if (this.skin != null)
  3575. newSkin.attachAll(this, this.skin);
  3576. else {
  3577. var slots = this.slots;
  3578. for (var i = 0, n = slots.length; i < n; i++) {
  3579. var slot = slots[i];
  3580. var name_1 = slot.data.attachmentName;
  3581. if (name_1 != null) {
  3582. var attachment = newSkin.getAttachment(i, name_1);
  3583. if (attachment != null)
  3584. slot.setAttachment(attachment);
  3585. }
  3586. }
  3587. }
  3588. }
  3589. this.skin = newSkin;
  3590. };
  3591. Skeleton.prototype.getAttachmentByName = function (slotName, attachmentName) {
  3592. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  3593. };
  3594. Skeleton.prototype.getAttachment = function (slotIndex, attachmentName) {
  3595. if (attachmentName == null)
  3596. throw new Error("attachmentName cannot be null.");
  3597. if (this.skin != null) {
  3598. var attachment = this.skin.getAttachment(slotIndex, attachmentName);
  3599. if (attachment != null)
  3600. return attachment;
  3601. }
  3602. if (this.data.defaultSkin != null)
  3603. return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  3604. return null;
  3605. };
  3606. Skeleton.prototype.setAttachment = function (slotName, attachmentName) {
  3607. if (slotName == null)
  3608. throw new Error("slotName cannot be null.");
  3609. var slots = this.slots;
  3610. for (var i = 0, n = slots.length; i < n; i++) {
  3611. var slot = slots[i];
  3612. if (slot.data.name == slotName) {
  3613. var attachment = null;
  3614. if (attachmentName != null) {
  3615. attachment = this.getAttachment(i, attachmentName);
  3616. if (attachment == null)
  3617. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  3618. }
  3619. slot.setAttachment(attachment);
  3620. return;
  3621. }
  3622. }
  3623. throw new Error("Slot not found: " + slotName);
  3624. };
  3625. Skeleton.prototype.findIkConstraint = function (constraintName) {
  3626. if (constraintName == null)
  3627. throw new Error("constraintName cannot be null.");
  3628. var ikConstraints = this.ikConstraints;
  3629. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  3630. var ikConstraint = ikConstraints[i];
  3631. if (ikConstraint.data.name == constraintName)
  3632. return ikConstraint;
  3633. }
  3634. return null;
  3635. };
  3636. Skeleton.prototype.findTransformConstraint = function (constraintName) {
  3637. if (constraintName == null)
  3638. throw new Error("constraintName cannot be null.");
  3639. var transformConstraints = this.transformConstraints;
  3640. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  3641. var constraint = transformConstraints[i];
  3642. if (constraint.data.name == constraintName)
  3643. return constraint;
  3644. }
  3645. return null;
  3646. };
  3647. Skeleton.prototype.findPathConstraint = function (constraintName) {
  3648. if (constraintName == null)
  3649. throw new Error("constraintName cannot be null.");
  3650. var pathConstraints = this.pathConstraints;
  3651. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  3652. var constraint = pathConstraints[i];
  3653. if (constraint.data.name == constraintName)
  3654. return constraint;
  3655. }
  3656. return null;
  3657. };
  3658. Skeleton.prototype.getBounds = function (offset, size, temp) {
  3659. if (offset == null)
  3660. throw new Error("offset cannot be null.");
  3661. if (size == null)
  3662. throw new Error("size cannot be null.");
  3663. var drawOrder = this.drawOrder;
  3664. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  3665. for (var i = 0, n = drawOrder.length; i < n; i++) {
  3666. var slot = drawOrder[i];
  3667. var verticesLength = 0;
  3668. var vertices = null;
  3669. var attachment = slot.getAttachment();
  3670. if (attachment instanceof spine.RegionAttachment) {
  3671. verticesLength = 8;
  3672. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  3673. attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  3674. }
  3675. else if (attachment instanceof spine.MeshAttachment) {
  3676. var mesh = attachment;
  3677. verticesLength = mesh.worldVerticesLength;
  3678. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  3679. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  3680. }
  3681. if (vertices != null) {
  3682. for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  3683. var x = vertices[ii], y = vertices[ii + 1];
  3684. minX = Math.min(minX, x);
  3685. minY = Math.min(minY, y);
  3686. maxX = Math.max(maxX, x);
  3687. maxY = Math.max(maxY, y);
  3688. }
  3689. }
  3690. }
  3691. offset.set(minX, minY);
  3692. size.set(maxX - minX, maxY - minY);
  3693. };
  3694. Skeleton.prototype.update = function (delta) {
  3695. this.time += delta;
  3696. };
  3697. return Skeleton;
  3698. }());
  3699. spine.Skeleton = Skeleton;
  3700. })(spine || (spine = {}));
  3701. var spine;
  3702. (function (spine) {
  3703. var BinaryReader = (function () {
  3704. function BinaryReader(data) {
  3705. this.offset = 0;
  3706. this.size = data.byteLength;
  3707. this.buffer = new Uint8Array(data);
  3708. this.floatBuf = new ArrayBuffer(4);
  3709. this.floatBufIn = new Uint8Array(this.floatBuf);
  3710. this.floatBufOut = new Float32Array(this.floatBuf);
  3711. this.doubleBuf = new ArrayBuffer(8);
  3712. this.doubleBufIn = new Uint8Array(this.doubleBuf);
  3713. this.doubleBufOut = new Float64Array(this.doubleBuf);
  3714. }
  3715. BinaryReader.prototype.readByte = function () {
  3716. return this.buffer[this.offset++];
  3717. };
  3718. BinaryReader.prototype.readSByte = function () {
  3719. var byte = this.readByte();
  3720. if (byte > 127)
  3721. byte -= 256;
  3722. return byte;
  3723. };
  3724. BinaryReader.prototype.readBool = function () {
  3725. return this.readByte() != 0;
  3726. };
  3727. BinaryReader.prototype.readShort = function () {
  3728. var result = this.readByte();
  3729. result <<= 8;
  3730. result |= this.readByte();
  3731. return result;
  3732. };
  3733. BinaryReader.prototype.readInt = function () {
  3734. var result = this.readByte();
  3735. result <<= 8;
  3736. result |= this.readByte();
  3737. result <<= 8;
  3738. result |= this.readByte();
  3739. result <<= 8;
  3740. result |= this.readByte();
  3741. return result;
  3742. };
  3743. BinaryReader.prototype.readVarInt = function (optimizePositive) {
  3744. if (optimizePositive === void 0) { optimizePositive = true; }
  3745. var b = this.readByte();
  3746. var value = b & 0x7f;
  3747. if (b & 0x80) {
  3748. b = this.readByte();
  3749. value |= (b & 0x7f) << 7;
  3750. if (b & 0x80) {
  3751. b = this.readByte();
  3752. value |= (b & 0x7f) << 14;
  3753. if (b & 0x80) {
  3754. b = this.readByte();
  3755. value |= (b & 0x7f) << 21;
  3756. if (b & 0x80) {
  3757. b = this.readByte();
  3758. value |= (b & 0x7f) << 28;
  3759. }
  3760. }
  3761. }
  3762. }
  3763. if (!optimizePositive)
  3764. value = ((value >>> 1) ^ -(value & 1));
  3765. return value;
  3766. };
  3767. BinaryReader.prototype.readFloat = function () {
  3768. this.floatBufIn[3] = this.readByte();
  3769. this.floatBufIn[2] = this.readByte();
  3770. this.floatBufIn[1] = this.readByte();
  3771. this.floatBufIn[0] = this.readByte();
  3772. return this.floatBufOut[0];
  3773. };
  3774. BinaryReader.prototype.readString = function () {
  3775. var length = this.readVarInt();
  3776. if (length == 0)
  3777. return null;
  3778. var strBuf = new Uint8Array(this.buffer.buffer.slice(this.offset, this.offset + length - 1));
  3779. this.offset += length - 1;
  3780. return decodeURIComponent(escape(String.fromCharCode.apply(null, strBuf)));
  3781. };
  3782. BinaryReader.prototype.readColor = function () {
  3783. var color = [
  3784. this.readByte() / 255,
  3785. this.readByte() / 255,
  3786. this.readByte() / 255,
  3787. this.readByte() / 255
  3788. ];
  3789. if (color[0] == 1 &&
  3790. color[1] == 1 &&
  3791. color[2] == 1 &&
  3792. color[3] == 1)
  3793. color = null;
  3794. return color;
  3795. };
  3796. return BinaryReader;
  3797. }());
  3798. var SkeletonBinary = (function () {
  3799. function SkeletonBinary(attachmentLoader) {
  3800. this.scale = 1;
  3801. this.linkedMeshes = new Array();
  3802. this.attachmentLoader = attachmentLoader;
  3803. }
  3804. SkeletonBinary.prototype.readSkeletonData = function (buf) {
  3805. var scale = this.scale;
  3806. var skeletonData = new spine.SkeletonData();
  3807. var reader = new BinaryReader(buf);
  3808. skeletonData.hash = reader.readString();
  3809. skeletonData.version = reader.readString();
  3810. skeletonData.width = reader.readFloat();
  3811. skeletonData.height = reader.readFloat();
  3812. var nonessential = reader.readBool();
  3813. if (nonessential) {
  3814. skeletonData.fps = reader.readFloat();
  3815. skeletonData.imagesPath = reader.readString();
  3816. }
  3817. for (var i = 0, boneCount = reader.readVarInt(); i < boneCount; i++) {
  3818. var boneName = reader.readString();
  3819. var parent_2 = null;
  3820. if (i > 0) {
  3821. var parentIndex = reader.readVarInt();
  3822. parent_2 = skeletonData.bones[parentIndex];
  3823. if (parent_2 == null)
  3824. throw new Error("Parent bone not found: " + parentIndex);
  3825. }
  3826. var data = new spine.BoneData(i, boneName, parent_2);
  3827. data.rotation = reader.readFloat();
  3828. data.x = reader.readFloat() * scale;
  3829. data.y = reader.readFloat() * scale;
  3830. data.scaleX = reader.readFloat();
  3831. data.scaleY = reader.readFloat();
  3832. data.shearX = reader.readFloat();
  3833. data.shearY = reader.readFloat();
  3834. data.length = reader.readFloat() * scale;
  3835. data.transformMode = reader.readByte();
  3836. if (nonessential)
  3837. reader.readColor();
  3838. skeletonData.bones.push(data);
  3839. }
  3840. for (var i = 0, slotCount = reader.readVarInt(); i < slotCount; i++) {
  3841. var slotName = reader.readString();
  3842. var boneIndex = reader.readVarInt();
  3843. var boneData = skeletonData.bones[boneIndex];
  3844. if (boneData == null)
  3845. throw new Error("Slot bone not found: " + boneIndex);
  3846. var data = new spine.SlotData(i, slotName, boneData);
  3847. var color = reader.readColor();
  3848. if (color != null)
  3849. data.color.set(color[0], color[1], color[2], color[3]);
  3850. var dark = reader.readColor();
  3851. if (dark != null) {
  3852. data.darkColor = new spine.Color(1, 1, 1, 1);
  3853. data.darkColor.set(dark[0], dark[1], dark[2], dark[3]);
  3854. }
  3855. data.attachmentName = reader.readString();
  3856. data.blendMode = reader.readByte();
  3857. skeletonData.slots.push(data);
  3858. }
  3859. for (var i = 0, ikCount = reader.readVarInt(); i < ikCount; i++) {
  3860. var data = new spine.IkConstraintData(reader.readString());
  3861. data.order = reader.readVarInt();
  3862. for (var j = 0, boneCount = reader.readVarInt(); j < boneCount; j++) {
  3863. var boneIndex = reader.readVarInt();
  3864. var bone = skeletonData.bones[boneIndex];
  3865. if (bone == null)
  3866. throw new Error("IK bone not found: " + boneIndex);
  3867. data.bones.push(bone);
  3868. }
  3869. var targetIndex = reader.readVarInt();
  3870. data.target = skeletonData.bones[targetIndex];
  3871. if (data.target == null)
  3872. throw new Error("IK target bone not found: " + targetIndex);
  3873. data.mix = reader.readFloat();
  3874. data.bendDirection = reader.readSByte();
  3875. skeletonData.ikConstraints.push(data);
  3876. }
  3877. for (var i = 0, transformCount = reader.readVarInt(); i < transformCount; i++) {
  3878. var data = new spine.TransformConstraintData(reader.readString());
  3879. data.order = reader.readVarInt();
  3880. for (var j = 0, boneCount = reader.readVarInt(); j < boneCount; j++) {
  3881. var boneIndex = reader.readVarInt();
  3882. var bone = skeletonData.bones[boneIndex];
  3883. if (bone == null)
  3884. throw new Error("Transform constraint bone not found: " + boneIndex);
  3885. data.bones.push(bone);
  3886. }
  3887. var targetIndex = reader.readVarInt();
  3888. data.target = skeletonData.bones[targetIndex];
  3889. if (data.target == null)
  3890. throw new Error("Transform constraint target bone not found: " + targetIndex);
  3891. data.local = reader.readBool();
  3892. data.relative = reader.readBool();
  3893. data.offsetRotation = reader.readFloat();
  3894. data.offsetX = reader.readFloat();
  3895. data.offsetY = reader.readFloat();
  3896. data.offsetScaleX = reader.readFloat();
  3897. data.offsetScaleY = reader.readFloat();
  3898. data.offsetShearY = reader.readFloat();
  3899. data.rotateMix = reader.readFloat();
  3900. data.translateMix = reader.readFloat();
  3901. data.scaleMix = reader.readFloat();
  3902. data.shearMix = reader.readFloat();
  3903. skeletonData.transformConstraints.push(data);
  3904. }
  3905. for (var i = 0, pathCount = reader.readVarInt(); i < pathCount; i++) {
  3906. var data = new spine.PathConstraintData(reader.readString());
  3907. data.order = reader.readVarInt();
  3908. for (var j = 0, boneCount = reader.readVarInt(); j < boneCount; j++) {
  3909. var boneIndex = reader.readVarInt();
  3910. var bone = skeletonData.bones[boneIndex];
  3911. if (bone == null)
  3912. throw new Error("Transform constraint bone not found: " + boneIndex);
  3913. data.bones.push(bone);
  3914. }
  3915. var targetIndex = reader.readVarInt();
  3916. data.target = skeletonData.slots[targetIndex];
  3917. if (data.target == null)
  3918. throw new Error("Path target slot not found: " + targetIndex);
  3919. data.positionMode = reader.readByte();
  3920. data.spacingMode = reader.readByte();
  3921. data.rotateMode = reader.readByte();
  3922. data.offsetRotation = reader.readFloat();
  3923. data.position = reader.readFloat();
  3924. if (data.positionMode == spine.PositionMode.Fixed)
  3925. data.position *= scale;
  3926. data.spacing = reader.readFloat();
  3927. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  3928. data.spacing *= scale;
  3929. data.rotateMix = reader.readFloat();
  3930. data.translateMix = reader.readFloat();
  3931. skeletonData.pathConstraints.push(data);
  3932. }
  3933. var defaultSkin = new spine.Skin('default');
  3934. for (var i = 0, slotCount = reader.readVarInt(); i < slotCount; i++) {
  3935. var slotIndex = reader.readVarInt();
  3936. for (var j = 0, attachmentCount = reader.readVarInt(); j < attachmentCount; j++) {
  3937. var placeholderName = reader.readString();
  3938. var attachment = this.readAttachment(reader, defaultSkin, slotIndex, placeholderName, skeletonData, nonessential);
  3939. if (attachment != null)
  3940. defaultSkin.addAttachment(slotIndex, placeholderName, attachment);
  3941. }
  3942. }
  3943. skeletonData.skins.push(defaultSkin);
  3944. skeletonData.defaultSkin = defaultSkin;
  3945. for (var i = 0, skinCount = reader.readVarInt(); i < skinCount; i++) {
  3946. var skin = new spine.Skin(reader.readString());
  3947. for (var j = 0, slotCount = reader.readVarInt(); j < slotCount; j++) {
  3948. var slotIndex = reader.readVarInt();
  3949. for (var k = 0, attachmentCount = reader.readVarInt(); k < attachmentCount; k++) {
  3950. var placeholderName = reader.readString();
  3951. var attachment = this.readAttachment(reader, skin, slotIndex, placeholderName, skeletonData, nonessential);
  3952. if (attachment != null)
  3953. skin.addAttachment(slotIndex, placeholderName, attachment);
  3954. }
  3955. }
  3956. skeletonData.skins.push(skin);
  3957. }
  3958. for (var i = 0, n = this.linkedMeshes.length; i < n; i++) {
  3959. var linkedMesh = this.linkedMeshes[i];
  3960. var skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  3961. if (skin == null)
  3962. throw new Error("Skin not found: " + linkedMesh.skin);
  3963. var parent_3 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  3964. if (parent_3 == null)
  3965. throw new Error("Parent mesh not found: " + linkedMesh.parent);
  3966. linkedMesh.mesh.setParentMesh(parent_3);
  3967. linkedMesh.mesh.updateUVs();
  3968. }
  3969. this.linkedMeshes.length = 0;
  3970. for (var i = 0, eventCount = reader.readVarInt(); i < eventCount; i++) {
  3971. var data = new spine.EventData(reader.readString());
  3972. data.intValue = reader.readVarInt(false);
  3973. data.floatValue = reader.readFloat();
  3974. data.stringValue = reader.readString();
  3975. skeletonData.events.push(data);
  3976. }
  3977. for (var i = 0, animationCount = reader.readVarInt(); i < animationCount; i++) {
  3978. var animationName = reader.readString();
  3979. this.readAnimation(reader, animationName, skeletonData);
  3980. }
  3981. return skeletonData;
  3982. };
  3983. SkeletonBinary.prototype.readAttachment = function (reader, skin, slotIndex, placeholderName, skeletonData, nonessential) {
  3984. var scale = this.scale;
  3985. var name = reader.readString();
  3986. if (!name) {
  3987. name = placeholderName;
  3988. }
  3989. var type = reader.readByte();
  3990. switch (type) {
  3991. case spine.AttachmentType.Region: {
  3992. var path = reader.readString();
  3993. if (!path)
  3994. path = name;
  3995. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  3996. if (region == null)
  3997. return null;
  3998. region.path = path;
  3999. region.rotation = reader.readFloat();
  4000. region.x = reader.readFloat() * scale;
  4001. region.y = reader.readFloat() * scale;
  4002. region.scaleX = reader.readFloat();
  4003. region.scaleY = reader.readFloat();
  4004. region.width = reader.readFloat() * scale;
  4005. region.height = reader.readFloat() * scale;
  4006. var color = reader.readColor();
  4007. if (color != null)
  4008. region.color.set(color[0], color[1], color[2], color[3]);
  4009. region.updateOffset();
  4010. return region;
  4011. }
  4012. case spine.AttachmentType.BoundingBox: {
  4013. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  4014. if (box == null)
  4015. return null;
  4016. var vertexCount = reader.readVarInt();
  4017. this.readVertices(reader, box, vertexCount);
  4018. if (nonessential) {
  4019. var color = reader.readColor();
  4020. if (color != null)
  4021. box.color.set(color[0], color[1], color[2], color[3]);
  4022. }
  4023. return box;
  4024. }
  4025. case spine.AttachmentType.Mesh: {
  4026. var path = reader.readString();
  4027. if (!path)
  4028. path = name;
  4029. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4030. if (mesh == null)
  4031. return null;
  4032. mesh.path = path;
  4033. var color = reader.readColor();
  4034. if (color != null)
  4035. mesh.color.set(color[0], color[1], color[2], color[3]);
  4036. var uvs = [];
  4037. for (var i = 0, uvCount = reader.readVarInt(); i < uvCount; i++) {
  4038. uvs.push(reader.readFloat());
  4039. uvs.push(reader.readFloat());
  4040. }
  4041. var triangles = [];
  4042. for (var i = 0, triangleCount = reader.readVarInt(); i < triangleCount; i++) {
  4043. triangles.push(reader.readShort());
  4044. }
  4045. mesh.triangles = triangles;
  4046. mesh.regionUVs = uvs;
  4047. this.readVertices(reader, mesh, uvs.length / 2);
  4048. mesh.updateUVs();
  4049. mesh.hullLength = reader.readVarInt() * 2;
  4050. if (nonessential) {
  4051. var edges = [];
  4052. for (var i = 0, edgeCount = reader.readVarInt(); i < edgeCount; i++) {
  4053. edges.push(reader.readShort());
  4054. }
  4055. var width = reader.readFloat();
  4056. var height = reader.readFloat();
  4057. }
  4058. return mesh;
  4059. }
  4060. case spine.AttachmentType.LinkedMesh: {
  4061. var path = reader.readString();
  4062. if (!path)
  4063. path = name;
  4064. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4065. if (mesh == null)
  4066. return null;
  4067. mesh.path = path;
  4068. var color = reader.readColor();
  4069. if (color != null)
  4070. mesh.color.set(color[0], color[1], color[2], color[3]);
  4071. var skinName = reader.readString();
  4072. var parent_4 = reader.readString();
  4073. var inheritDeform = reader.readBool();
  4074. mesh.inheritDeform = inheritDeform;
  4075. this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent_4));
  4076. if (nonessential) {
  4077. var width = reader.readFloat();
  4078. var height = reader.readFloat();
  4079. }
  4080. return mesh;
  4081. }
  4082. case spine.AttachmentType.Path: {
  4083. var path = this.attachmentLoader.newPathAttachment(skin, name);
  4084. if (path == null)
  4085. return null;
  4086. path.closed = reader.readBool();
  4087. path.constantSpeed = reader.readBool();
  4088. var vertexCount = reader.readVarInt();
  4089. this.readVertices(reader, path, vertexCount);
  4090. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  4091. for (var i = 0; i < lengths.length; i++)
  4092. lengths[i] = reader.readFloat() * scale;
  4093. path.lengths = lengths;
  4094. if (nonessential) {
  4095. var color = reader.readColor();
  4096. if (color != null)
  4097. path.color.set(color[0], color[1], color[2], color[3]);
  4098. }
  4099. return path;
  4100. }
  4101. case spine.AttachmentType.Point: {
  4102. var point = this.attachmentLoader.newPointAttachment(skin, name);
  4103. if (point == null)
  4104. return null;
  4105. point.x = reader.readFloat() * scale;
  4106. point.y = reader.readFloat() * scale;
  4107. point.rotation = reader.readFloat();
  4108. if (nonessential) {
  4109. var color = reader.readColor();
  4110. if (color != null)
  4111. point.color.set(color[0], color[1], color[2], color[3]);
  4112. }
  4113. return point;
  4114. }
  4115. case spine.AttachmentType.Clipping: {
  4116. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  4117. if (clip == null)
  4118. return null;
  4119. var end = reader.readVarInt();
  4120. var slot = skeletonData.slots[end];
  4121. if (slot == null)
  4122. throw new Error("Clipping end slot not found: " + end);
  4123. clip.endSlot = slot;
  4124. var vertexCount = reader.readVarInt();
  4125. this.readVertices(reader, clip, vertexCount);
  4126. if (nonessential) {
  4127. var color = reader.readColor();
  4128. if (color != null)
  4129. clip.color.set(color[0], color[1], color[2], color[3]);
  4130. }
  4131. return clip;
  4132. }
  4133. }
  4134. return null;
  4135. };
  4136. SkeletonBinary.prototype.readVertices = function (reader, attachment, verticesLength) {
  4137. var scale = this.scale;
  4138. attachment.worldVerticesLength = verticesLength * 2;
  4139. var weighted = reader.readBool();
  4140. if (!weighted) {
  4141. var vertices = new Array();
  4142. for (var i = 0; i < verticesLength; i++) {
  4143. vertices.push(reader.readFloat());
  4144. vertices.push(reader.readFloat());
  4145. }
  4146. var scaledVertices = spine.Utils.toFloatArray(vertices);
  4147. if (scale != 1) {
  4148. for (var i = 0, n = vertices.length; i < n; i++)
  4149. scaledVertices[i] *= scale;
  4150. }
  4151. attachment.vertices = scaledVertices;
  4152. return;
  4153. }
  4154. var weights = new Array();
  4155. var bones = new Array();
  4156. for (var i = 0, n = verticesLength; i < n; i++) {
  4157. var boneCount = reader.readVarInt();
  4158. bones.push(boneCount);
  4159. for (var j = 0; j < boneCount; j++) {
  4160. bones.push(reader.readVarInt());
  4161. weights.push(reader.readFloat() * scale);
  4162. weights.push(reader.readFloat() * scale);
  4163. weights.push(reader.readFloat());
  4164. }
  4165. }
  4166. attachment.bones = bones;
  4167. attachment.vertices = spine.Utils.toFloatArray(weights);
  4168. };
  4169. SkeletonBinary.prototype.readAnimation = function (reader, name, skeletonData) {
  4170. var scale = this.scale;
  4171. var timelines = new Array();
  4172. var duration = 0;
  4173. for (var i = 0, slotCount = reader.readVarInt(); i < slotCount; i++) {
  4174. var slotIndex = reader.readVarInt();
  4175. for (var ii = 0, timelineCount = reader.readVarInt(); ii < timelineCount; ii++) {
  4176. var timelineName = reader.readByte() + 4;
  4177. var frameCount = reader.readVarInt();
  4178. if (timelineName == spine.TimelineType.attachment) {
  4179. var timeline = new spine.AttachmentTimeline(frameCount);
  4180. timeline.slotIndex = slotIndex;
  4181. var frameIndex = 0;
  4182. for (var i_8 = 0; i_8 < frameCount; i_8++) {
  4183. timeline.setFrame(frameIndex++, reader.readFloat(), reader.readString());
  4184. }
  4185. timelines.push(timeline);
  4186. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4187. }
  4188. else if (timelineName == spine.TimelineType.color) {
  4189. var timeline = new spine.ColorTimeline(frameCount);
  4190. timeline.slotIndex = slotIndex;
  4191. var frameIndex = 0;
  4192. for (var i_9 = 0; i_9 < frameCount; i_9++) {
  4193. var time = reader.readFloat();
  4194. var color = reader.readColor();
  4195. if (!color)
  4196. color = [1, 1, 1, 1];
  4197. timeline.setFrame(frameIndex, time, color[0], color[1], color[2], color[3]);
  4198. if (frameIndex < frameCount - 1)
  4199. this.readCurve(reader, timeline, frameIndex);
  4200. frameIndex++;
  4201. }
  4202. timelines.push(timeline);
  4203. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]);
  4204. }
  4205. else if (timelineName == spine.TimelineType.deform) {
  4206. var timeline = new spine.TwoColorTimeline(frameCount);
  4207. timeline.slotIndex = slotIndex;
  4208. var frameIndex = 0;
  4209. for (var i_10 = 0; i_10 < frameCount; i_10++) {
  4210. var time = reader.readFloat();
  4211. var light = reader.readColor();
  4212. var dark = reader.readColor();
  4213. if (!light)
  4214. light = [1, 1, 1, 1];
  4215. if (!dark)
  4216. dark = [1, 1, 1, 1];
  4217. timeline.setFrame(frameIndex, time, light[0], light[1], light[2], light[3], dark[0], dark[1], dark[2]);
  4218. if (frameIndex < frameCount - 1)
  4219. this.readCurve(reader, timeline, frameIndex);
  4220. frameIndex++;
  4221. }
  4222. timelines.push(timeline);
  4223. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TwoColorTimeline.ENTRIES]);
  4224. }
  4225. else
  4226. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotIndex + ")");
  4227. }
  4228. }
  4229. for (var i = 0, boneCount = reader.readVarInt(); i < boneCount; i++) {
  4230. var boneIndex = reader.readVarInt();
  4231. for (var ii = 0, timelineCount = reader.readVarInt(); ii < timelineCount; ii++) {
  4232. var timelineName = reader.readByte();
  4233. var frameCount = reader.readVarInt();
  4234. if (timelineName === spine.TimelineType.rotate) {
  4235. var timeline = new spine.RotateTimeline(frameCount);
  4236. timeline.boneIndex = boneIndex;
  4237. var frameIndex = 0;
  4238. for (var i_11 = 0; i_11 < frameCount; i_11++) {
  4239. timeline.setFrame(frameIndex, reader.readFloat(), reader.readFloat());
  4240. if (frameIndex < frameCount - 1)
  4241. this.readCurve(reader, timeline, frameIndex);
  4242. frameIndex++;
  4243. }
  4244. timelines.push(timeline);
  4245. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.RotateTimeline.ENTRIES]);
  4246. }
  4247. else if (timelineName === spine.TimelineType.translate || timelineName === spine.TimelineType.scale || timelineName === spine.TimelineType.shear) {
  4248. var timeline = null;
  4249. var timelineScale = 1;
  4250. if (timelineName === spine.TimelineType.scale)
  4251. timeline = new spine.ScaleTimeline(frameCount);
  4252. else if (timelineName === spine.TimelineType.shear)
  4253. timeline = new spine.ShearTimeline(frameCount);
  4254. else {
  4255. timeline = new spine.TranslateTimeline(frameCount);
  4256. timelineScale = scale;
  4257. }
  4258. timeline.boneIndex = boneIndex;
  4259. var frameIndex = 0;
  4260. for (var i_12 = 0; i_12 < frameCount; i_12++) {
  4261. var time = reader.readFloat();
  4262. var x = reader.readFloat(), y = reader.readFloat();
  4263. timeline.setFrame(frameIndex, time, x * timelineScale, y * timelineScale);
  4264. if (frameIndex < frameCount - 1)
  4265. this.readCurve(reader, timeline, frameIndex);
  4266. frameIndex++;
  4267. }
  4268. timelines.push(timeline);
  4269. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TranslateTimeline.ENTRIES]);
  4270. }
  4271. else
  4272. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneIndex + ")");
  4273. }
  4274. }
  4275. for (var i = 0, count = reader.readVarInt(); i < count; i++) {
  4276. var ikConstraintIndex = reader.readVarInt();
  4277. var frameCount = reader.readVarInt();
  4278. var timeline = new spine.IkConstraintTimeline(frameCount);
  4279. timeline.ikConstraintIndex = ikConstraintIndex;
  4280. var frameIndex = 0;
  4281. for (var i_13 = 0; i_13 < frameCount; i_13++) {
  4282. timeline.setFrame(frameIndex, reader.readFloat(), reader.readFloat(), reader.readSByte());
  4283. if (frameIndex < frameCount - 1)
  4284. this.readCurve(reader, timeline, frameIndex);
  4285. frameIndex++;
  4286. }
  4287. timelines.push(timeline);
  4288. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.IkConstraintTimeline.ENTRIES]);
  4289. }
  4290. for (var i = 0, count = reader.readVarInt(); i < count; i++) {
  4291. var transformConstraintIndex = reader.readVarInt();
  4292. var frameCount = reader.readVarInt();
  4293. var timeline = new spine.TransformConstraintTimeline(frameCount);
  4294. timeline.transformConstraintIndex = transformConstraintIndex;
  4295. var frameIndex = 0;
  4296. for (var i_14 = 0; i_14 < frameCount; i_14++) {
  4297. timeline.setFrame(frameIndex, reader.readFloat(), reader.readFloat(), reader.readFloat(), reader.readFloat(), reader.readFloat());
  4298. if (frameIndex < frameCount - 1)
  4299. this.readCurve(reader, timeline, frameIndex);
  4300. frameIndex++;
  4301. }
  4302. timelines.push(timeline);
  4303. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TransformConstraintTimeline.ENTRIES]);
  4304. }
  4305. for (var i = 0, count = reader.readVarInt(); i < count; i++) {
  4306. var index = reader.readVarInt();
  4307. var data = skeletonData.pathConstraints[index];
  4308. for (var ii = 0, nn = reader.readVarInt(); ii < nn; ii++) {
  4309. var timelineName = reader.readByte() + 11;
  4310. var frameCount = reader.readVarInt();
  4311. if (timelineName === spine.TimelineType.pathConstraintPosition || timelineName === spine.TimelineType.pathConstraintSpacing) {
  4312. var timeline = null;
  4313. var timelineScale = 1;
  4314. if (timelineName === spine.TimelineType.pathConstraintSpacing) {
  4315. timeline = new spine.PathConstraintSpacingTimeline(frameCount);
  4316. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4317. timelineScale = scale;
  4318. }
  4319. else {
  4320. timeline = new spine.PathConstraintPositionTimeline(frameCount);
  4321. if (data.positionMode == spine.PositionMode.Fixed)
  4322. timelineScale = scale;
  4323. }
  4324. timeline.pathConstraintIndex = index;
  4325. var frameIndex = 0;
  4326. for (var i_15 = 0; i_15 < frameCount; i_15++) {
  4327. timeline.setFrame(frameIndex, reader.readFloat(), reader.readFloat() * timelineScale);
  4328. if (frameIndex < frameCount - 1)
  4329. this.readCurve(reader, timeline, frameIndex);
  4330. frameIndex++;
  4331. }
  4332. timelines.push(timeline);
  4333. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintPositionTimeline.ENTRIES]);
  4334. }
  4335. else if (timelineName === spine.TimelineType.pathConstraintMix) {
  4336. var timeline = new spine.PathConstraintMixTimeline(frameCount);
  4337. timeline.pathConstraintIndex = index;
  4338. var frameIndex = 0;
  4339. for (var i_16 = 0; i_16 < frameCount; i_16++) {
  4340. timeline.setFrame(frameIndex, reader.readFloat(), reader.readFloat(), reader.readFloat());
  4341. if (frameIndex < frameCount - 1)
  4342. this.readCurve(reader, timeline, frameIndex);
  4343. frameIndex++;
  4344. }
  4345. timelines.push(timeline);
  4346. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintMixTimeline.ENTRIES]);
  4347. }
  4348. }
  4349. }
  4350. for (var i = 0, count = reader.readVarInt(); i < count; i++) {
  4351. var skinIndex = reader.readVarInt();
  4352. var skin = skeletonData.skins[skinIndex];
  4353. if (skin == null)
  4354. throw new Error("Skin not found: " + skinIndex);
  4355. for (var ii = 0, nn = reader.readVarInt(); ii < nn; ii++) {
  4356. var slotIndex = reader.readVarInt();
  4357. for (var iii = 0, nnn = reader.readVarInt(); iii < nnn; iii++) {
  4358. var attachmentName = reader.readString();
  4359. var attachment = skin.getAttachment(slotIndex, attachmentName);
  4360. if (attachment == null)
  4361. throw new Error("Deform attachment not found: " + attachmentName);
  4362. var weighted = attachment.bones != null;
  4363. var vertices = attachment.vertices;
  4364. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  4365. var frameCount = reader.readVarInt();
  4366. var timeline = new spine.DeformTimeline(frameCount);
  4367. timeline.slotIndex = slotIndex;
  4368. timeline.attachment = attachment;
  4369. var frameIndex = 0;
  4370. for (var j = 0; j < frameCount; j++) {
  4371. var time = reader.readFloat();
  4372. var end = reader.readVarInt();
  4373. var deform = void 0;
  4374. if (end == 0)
  4375. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  4376. else {
  4377. deform = spine.Utils.newFloatArray(deformLength);
  4378. var start = reader.readVarInt();
  4379. end += start;
  4380. if (scale == 1) {
  4381. for (var v = start; v < end; v++)
  4382. deform[v] = reader.readFloat();
  4383. }
  4384. else {
  4385. for (var v = start; v < end; v++)
  4386. deform[v] = reader.readFloat() * scale;
  4387. }
  4388. if (!weighted) {
  4389. for (var v = 0, vn = deform.length; v < vn; v++)
  4390. deform[v] += vertices[v];
  4391. }
  4392. }
  4393. timeline.setFrame(frameIndex, time, deform);
  4394. if (frameIndex < frameCount - 1)
  4395. this.readCurve(reader, timeline, frameIndex);
  4396. frameIndex++;
  4397. }
  4398. timelines.push(timeline);
  4399. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4400. }
  4401. }
  4402. }
  4403. var drawOrderCount = reader.readVarInt();
  4404. if (drawOrderCount > 0) {
  4405. var timeline = new spine.DrawOrderTimeline(drawOrderCount);
  4406. var slotCount = skeletonData.slots.length;
  4407. for (var i = 0; i < drawOrderCount; i++) {
  4408. var time = reader.readFloat();
  4409. var offsetCount = reader.readVarInt();
  4410. var drawOrder = spine.Utils.newArray(slotCount, -1);
  4411. var unchanged = new Array(slotCount - offsetCount);
  4412. var originalIndex = 0, unchangedIndex = 0;
  4413. for (var ii = 0; ii < offsetCount; ii++) {
  4414. var slotIndex = reader.readVarInt();
  4415. while (originalIndex != slotIndex)
  4416. unchanged[unchangedIndex++] = originalIndex++;
  4417. drawOrder[originalIndex + reader.readVarInt()] = originalIndex++;
  4418. }
  4419. while (originalIndex < slotCount)
  4420. unchanged[unchangedIndex++] = originalIndex++;
  4421. for (var ii = slotCount - 1; ii >= 0; ii--)
  4422. if (drawOrder[ii] == -1)
  4423. drawOrder[ii] = unchanged[--unchangedIndex];
  4424. timeline.setFrame(i, time, drawOrder);
  4425. }
  4426. timelines.push(timeline);
  4427. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4428. }
  4429. var eventCount = reader.readVarInt();
  4430. if (eventCount > 0) {
  4431. var timeline = new spine.EventTimeline(eventCount);
  4432. for (var i = 0; i < eventCount; i++) {
  4433. var time = reader.readFloat();
  4434. var eventIndex = reader.readVarInt();
  4435. var eventData = skeletonData.events[eventIndex];
  4436. if (eventData == null)
  4437. throw new Error("Event not found: " + eventIndex);
  4438. var event_4 = new spine.Event(spine.Utils.toSinglePrecision(time), eventData);
  4439. event_4.intValue = reader.readVarInt(false);
  4440. event_4.floatValue = reader.readFloat();
  4441. event_4.stringValue = reader.readBool() ? reader.readString() : eventData.stringValue;
  4442. timeline.setFrame(i, event_4);
  4443. }
  4444. timelines.push(timeline);
  4445. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4446. }
  4447. if (isNaN(duration)) {
  4448. throw new Error("Error while parsing animation, duration is NaN");
  4449. }
  4450. skeletonData.animations.push(new spine.Animation(name, timelines, duration));
  4451. };
  4452. SkeletonBinary.prototype.readCurve = function (reader, timeline, frameIndex) {
  4453. var type = reader.readByte();
  4454. if (type === spine.CurveTimeline.STEPPED)
  4455. timeline.setStepped(frameIndex);
  4456. else if (type === spine.CurveTimeline.BEZIER) {
  4457. timeline.setCurve(frameIndex, reader.readFloat(), reader.readFloat(), reader.readFloat(), reader.readFloat());
  4458. }
  4459. };
  4460. return SkeletonBinary;
  4461. }());
  4462. spine.SkeletonBinary = SkeletonBinary;
  4463. var LinkedMesh = (function () {
  4464. function LinkedMesh(mesh, skin, slotIndex, parent) {
  4465. this.mesh = mesh;
  4466. this.skin = skin;
  4467. this.slotIndex = slotIndex;
  4468. this.parent = parent;
  4469. }
  4470. return LinkedMesh;
  4471. }());
  4472. })(spine || (spine = {}));
  4473. var spine;
  4474. (function (spine) {
  4475. var SkeletonBounds = (function () {
  4476. function SkeletonBounds() {
  4477. this.minX = 0;
  4478. this.minY = 0;
  4479. this.maxX = 0;
  4480. this.maxY = 0;
  4481. this.boundingBoxes = new Array();
  4482. this.polygons = new Array();
  4483. this.polygonPool = new spine.Pool(function () {
  4484. return spine.Utils.newFloatArray(16);
  4485. });
  4486. }
  4487. SkeletonBounds.prototype.update = function (skeleton, updateAabb) {
  4488. if (skeleton == null)
  4489. throw new Error("skeleton cannot be null.");
  4490. var boundingBoxes = this.boundingBoxes;
  4491. var polygons = this.polygons;
  4492. var polygonPool = this.polygonPool;
  4493. var slots = skeleton.slots;
  4494. var slotCount = slots.length;
  4495. boundingBoxes.length = 0;
  4496. polygonPool.freeAll(polygons);
  4497. polygons.length = 0;
  4498. for (var i = 0; i < slotCount; i++) {
  4499. var slot = slots[i];
  4500. var attachment = slot.getAttachment();
  4501. if (attachment instanceof spine.BoundingBoxAttachment) {
  4502. var boundingBox = attachment;
  4503. boundingBoxes.push(boundingBox);
  4504. var polygon = polygonPool.obtain();
  4505. if (polygon.length != boundingBox.worldVerticesLength) {
  4506. polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength);
  4507. }
  4508. polygons.push(polygon);
  4509. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  4510. }
  4511. }
  4512. if (updateAabb) {
  4513. this.aabbCompute();
  4514. }
  4515. else {
  4516. this.minX = Number.POSITIVE_INFINITY;
  4517. this.minY = Number.POSITIVE_INFINITY;
  4518. this.maxX = Number.NEGATIVE_INFINITY;
  4519. this.maxY = Number.NEGATIVE_INFINITY;
  4520. }
  4521. };
  4522. SkeletonBounds.prototype.aabbCompute = function () {
  4523. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  4524. var polygons = this.polygons;
  4525. for (var i = 0, n = polygons.length; i < n; i++) {
  4526. var polygon = polygons[i];
  4527. var vertices = polygon;
  4528. for (var ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  4529. var x = vertices[ii];
  4530. var y = vertices[ii + 1];
  4531. minX = Math.min(minX, x);
  4532. minY = Math.min(minY, y);
  4533. maxX = Math.max(maxX, x);
  4534. maxY = Math.max(maxY, y);
  4535. }
  4536. }
  4537. this.minX = minX;
  4538. this.minY = minY;
  4539. this.maxX = maxX;
  4540. this.maxY = maxY;
  4541. };
  4542. SkeletonBounds.prototype.aabbContainsPoint = function (x, y) {
  4543. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  4544. };
  4545. SkeletonBounds.prototype.aabbIntersectsSegment = function (x1, y1, x2, y2) {
  4546. var minX = this.minX;
  4547. var minY = this.minY;
  4548. var maxX = this.maxX;
  4549. var maxY = this.maxY;
  4550. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  4551. return false;
  4552. var m = (y2 - y1) / (x2 - x1);
  4553. var y = m * (minX - x1) + y1;
  4554. if (y > minY && y < maxY)
  4555. return true;
  4556. y = m * (maxX - x1) + y1;
  4557. if (y > minY && y < maxY)
  4558. return true;
  4559. var x = (minY - y1) / m + x1;
  4560. if (x > minX && x < maxX)
  4561. return true;
  4562. x = (maxY - y1) / m + x1;
  4563. if (x > minX && x < maxX)
  4564. return true;
  4565. return false;
  4566. };
  4567. SkeletonBounds.prototype.aabbIntersectsSkeleton = function (bounds) {
  4568. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  4569. };
  4570. SkeletonBounds.prototype.containsPoint = function (x, y) {
  4571. var polygons = this.polygons;
  4572. for (var i = 0, n = polygons.length; i < n; i++)
  4573. if (this.containsPointPolygon(polygons[i], x, y))
  4574. return this.boundingBoxes[i];
  4575. return null;
  4576. };
  4577. SkeletonBounds.prototype.containsPointPolygon = function (polygon, x, y) {
  4578. var vertices = polygon;
  4579. var nn = polygon.length;
  4580. var prevIndex = nn - 2;
  4581. var inside = false;
  4582. for (var ii = 0; ii < nn; ii += 2) {
  4583. var vertexY = vertices[ii + 1];
  4584. var prevY = vertices[prevIndex + 1];
  4585. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  4586. var vertexX = vertices[ii];
  4587. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x)
  4588. inside = !inside;
  4589. }
  4590. prevIndex = ii;
  4591. }
  4592. return inside;
  4593. };
  4594. SkeletonBounds.prototype.intersectsSegment = function (x1, y1, x2, y2) {
  4595. var polygons = this.polygons;
  4596. for (var i = 0, n = polygons.length; i < n; i++)
  4597. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2))
  4598. return this.boundingBoxes[i];
  4599. return null;
  4600. };
  4601. SkeletonBounds.prototype.intersectsSegmentPolygon = function (polygon, x1, y1, x2, y2) {
  4602. var vertices = polygon;
  4603. var nn = polygon.length;
  4604. var width12 = x1 - x2, height12 = y1 - y2;
  4605. var det1 = x1 * y2 - y1 * x2;
  4606. var x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  4607. for (var ii = 0; ii < nn; ii += 2) {
  4608. var x4 = vertices[ii], y4 = vertices[ii + 1];
  4609. var det2 = x3 * y4 - y3 * x4;
  4610. var width34 = x3 - x4, height34 = y3 - y4;
  4611. var det3 = width12 * height34 - height12 * width34;
  4612. var x = (det1 * width34 - width12 * det2) / det3;
  4613. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  4614. var y = (det1 * height34 - height12 * det2) / det3;
  4615. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1)))
  4616. return true;
  4617. }
  4618. x3 = x4;
  4619. y3 = y4;
  4620. }
  4621. return false;
  4622. };
  4623. SkeletonBounds.prototype.getPolygon = function (boundingBox) {
  4624. if (boundingBox == null)
  4625. throw new Error("boundingBox cannot be null.");
  4626. var index = this.boundingBoxes.indexOf(boundingBox);
  4627. return index == -1 ? null : this.polygons[index];
  4628. };
  4629. SkeletonBounds.prototype.getWidth = function () {
  4630. return this.maxX - this.minX;
  4631. };
  4632. SkeletonBounds.prototype.getHeight = function () {
  4633. return this.maxY - this.minY;
  4634. };
  4635. return SkeletonBounds;
  4636. }());
  4637. spine.SkeletonBounds = SkeletonBounds;
  4638. })(spine || (spine = {}));
  4639. var spine;
  4640. (function (spine) {
  4641. var SkeletonClipping = (function () {
  4642. function SkeletonClipping() {
  4643. this.triangulator = new spine.Triangulator();
  4644. this.clippingPolygon = new Array();
  4645. this.clipOutput = new Array();
  4646. this.clippedVertices = new Array();
  4647. this.clippedTriangles = new Array();
  4648. this.scratch = new Array();
  4649. }
  4650. SkeletonClipping.prototype.clipStart = function (slot, clip) {
  4651. if (this.clipAttachment != null)
  4652. return 0;
  4653. this.clipAttachment = clip;
  4654. var n = clip.worldVerticesLength;
  4655. var vertices = spine.Utils.setArraySize(this.clippingPolygon, n);
  4656. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  4657. var clippingPolygon = this.clippingPolygon;
  4658. SkeletonClipping.makeClockwise(clippingPolygon);
  4659. var clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon));
  4660. for (var i = 0, n_1 = clippingPolygons.length; i < n_1; i++) {
  4661. var polygon = clippingPolygons[i];
  4662. SkeletonClipping.makeClockwise(polygon);
  4663. polygon.push(polygon[0]);
  4664. polygon.push(polygon[1]);
  4665. }
  4666. return clippingPolygons.length;
  4667. };
  4668. SkeletonClipping.prototype.clipEndWithSlot = function (slot) {
  4669. if (this.clipAttachment != null && this.clipAttachment.endSlot == slot.data)
  4670. this.clipEnd();
  4671. };
  4672. SkeletonClipping.prototype.clipEnd = function () {
  4673. if (this.clipAttachment == null)
  4674. return;
  4675. this.clipAttachment = null;
  4676. this.clippingPolygons = null;
  4677. this.clippedVertices.length = 0;
  4678. this.clippedTriangles.length = 0;
  4679. this.clippingPolygon.length = 0;
  4680. };
  4681. SkeletonClipping.prototype.isClipping = function () {
  4682. return this.clipAttachment != null;
  4683. };
  4684. SkeletonClipping.prototype.clipTriangles = function (vertices, verticesLength, triangles, trianglesLength, uvs, light, dark, twoColor) {
  4685. var clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
  4686. var clippedTriangles = this.clippedTriangles;
  4687. var polygons = this.clippingPolygons;
  4688. var polygonsCount = this.clippingPolygons.length;
  4689. var vertexSize = twoColor ? 12 : 8;
  4690. var index = 0;
  4691. clippedVertices.length = 0;
  4692. clippedTriangles.length = 0;
  4693. outer: for (var i = 0; i < trianglesLength; i += 3) {
  4694. var vertexOffset = triangles[i] << 1;
  4695. var x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
  4696. var u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
  4697. vertexOffset = triangles[i + 1] << 1;
  4698. var x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
  4699. var u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
  4700. vertexOffset = triangles[i + 2] << 1;
  4701. var x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
  4702. var u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
  4703. for (var p = 0; p < polygonsCount; p++) {
  4704. var s = clippedVertices.length;
  4705. if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
  4706. var clipOutputLength = clipOutput.length;
  4707. if (clipOutputLength == 0)
  4708. continue;
  4709. var d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
  4710. var d = 1 / (d0 * d2 + d1 * (y1 - y3));
  4711. var clipOutputCount = clipOutputLength >> 1;
  4712. var clipOutputItems = this.clipOutput;
  4713. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize);
  4714. for (var ii = 0; ii < clipOutputLength; ii += 2) {
  4715. var x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
  4716. clippedVerticesItems[s] = x;
  4717. clippedVerticesItems[s + 1] = y;
  4718. clippedVerticesItems[s + 2] = light.r;
  4719. clippedVerticesItems[s + 3] = light.g;
  4720. clippedVerticesItems[s + 4] = light.b;
  4721. clippedVerticesItems[s + 5] = light.a;
  4722. var c0 = x - x3, c1 = y - y3;
  4723. var a = (d0 * c0 + d1 * c1) * d;
  4724. var b = (d4 * c0 + d2 * c1) * d;
  4725. var c = 1 - a - b;
  4726. clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
  4727. clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c;
  4728. if (twoColor) {
  4729. clippedVerticesItems[s + 8] = dark.r;
  4730. clippedVerticesItems[s + 9] = dark.g;
  4731. clippedVerticesItems[s + 10] = dark.b;
  4732. clippedVerticesItems[s + 11] = dark.a;
  4733. }
  4734. s += vertexSize;
  4735. }
  4736. s = clippedTriangles.length;
  4737. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2));
  4738. clipOutputCount--;
  4739. for (var ii = 1; ii < clipOutputCount; ii++) {
  4740. clippedTrianglesItems[s] = index;
  4741. clippedTrianglesItems[s + 1] = (index + ii);
  4742. clippedTrianglesItems[s + 2] = (index + ii + 1);
  4743. s += 3;
  4744. }
  4745. index += clipOutputCount + 1;
  4746. }
  4747. else {
  4748. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + 3 * vertexSize);
  4749. clippedVerticesItems[s] = x1;
  4750. clippedVerticesItems[s + 1] = y1;
  4751. clippedVerticesItems[s + 2] = light.r;
  4752. clippedVerticesItems[s + 3] = light.g;
  4753. clippedVerticesItems[s + 4] = light.b;
  4754. clippedVerticesItems[s + 5] = light.a;
  4755. if (!twoColor) {
  4756. clippedVerticesItems[s + 6] = u1;
  4757. clippedVerticesItems[s + 7] = v1;
  4758. clippedVerticesItems[s + 8] = x2;
  4759. clippedVerticesItems[s + 9] = y2;
  4760. clippedVerticesItems[s + 10] = light.r;
  4761. clippedVerticesItems[s + 11] = light.g;
  4762. clippedVerticesItems[s + 12] = light.b;
  4763. clippedVerticesItems[s + 13] = light.a;
  4764. clippedVerticesItems[s + 14] = u2;
  4765. clippedVerticesItems[s + 15] = v2;
  4766. clippedVerticesItems[s + 16] = x3;
  4767. clippedVerticesItems[s + 17] = y3;
  4768. clippedVerticesItems[s + 18] = light.r;
  4769. clippedVerticesItems[s + 19] = light.g;
  4770. clippedVerticesItems[s + 20] = light.b;
  4771. clippedVerticesItems[s + 21] = light.a;
  4772. clippedVerticesItems[s + 22] = u3;
  4773. clippedVerticesItems[s + 23] = v3;
  4774. }
  4775. else {
  4776. clippedVerticesItems[s + 6] = u1;
  4777. clippedVerticesItems[s + 7] = v1;
  4778. clippedVerticesItems[s + 8] = dark.r;
  4779. clippedVerticesItems[s + 9] = dark.g;
  4780. clippedVerticesItems[s + 10] = dark.b;
  4781. clippedVerticesItems[s + 11] = dark.a;
  4782. clippedVerticesItems[s + 12] = x2;
  4783. clippedVerticesItems[s + 13] = y2;
  4784. clippedVerticesItems[s + 14] = light.r;
  4785. clippedVerticesItems[s + 15] = light.g;
  4786. clippedVerticesItems[s + 16] = light.b;
  4787. clippedVerticesItems[s + 17] = light.a;
  4788. clippedVerticesItems[s + 18] = u2;
  4789. clippedVerticesItems[s + 19] = v2;
  4790. clippedVerticesItems[s + 20] = dark.r;
  4791. clippedVerticesItems[s + 21] = dark.g;
  4792. clippedVerticesItems[s + 22] = dark.b;
  4793. clippedVerticesItems[s + 23] = dark.a;
  4794. clippedVerticesItems[s + 24] = x3;
  4795. clippedVerticesItems[s + 25] = y3;
  4796. clippedVerticesItems[s + 26] = light.r;
  4797. clippedVerticesItems[s + 27] = light.g;
  4798. clippedVerticesItems[s + 28] = light.b;
  4799. clippedVerticesItems[s + 29] = light.a;
  4800. clippedVerticesItems[s + 30] = u3;
  4801. clippedVerticesItems[s + 31] = v3;
  4802. clippedVerticesItems[s + 32] = dark.r;
  4803. clippedVerticesItems[s + 33] = dark.g;
  4804. clippedVerticesItems[s + 34] = dark.b;
  4805. clippedVerticesItems[s + 35] = dark.a;
  4806. }
  4807. s = clippedTriangles.length;
  4808. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3);
  4809. clippedTrianglesItems[s] = index;
  4810. clippedTrianglesItems[s + 1] = (index + 1);
  4811. clippedTrianglesItems[s + 2] = (index + 2);
  4812. index += 3;
  4813. continue outer;
  4814. }
  4815. }
  4816. }
  4817. };
  4818. SkeletonClipping.prototype.clip = function (x1, y1, x2, y2, x3, y3, clippingArea, output) {
  4819. var originalOutput = output;
  4820. var clipped = false;
  4821. var input = null;
  4822. if (clippingArea.length % 4 >= 2) {
  4823. input = output;
  4824. output = this.scratch;
  4825. }
  4826. else
  4827. input = this.scratch;
  4828. input.length = 0;
  4829. input.push(x1);
  4830. input.push(y1);
  4831. input.push(x2);
  4832. input.push(y2);
  4833. input.push(x3);
  4834. input.push(y3);
  4835. input.push(x1);
  4836. input.push(y1);
  4837. output.length = 0;
  4838. var clippingVertices = clippingArea;
  4839. var clippingVerticesLast = clippingArea.length - 4;
  4840. for (var i = 0;; i += 2) {
  4841. var edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
  4842. var edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
  4843. var deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
  4844. var inputVertices = input;
  4845. var inputVerticesLength = input.length - 2, outputStart = output.length;
  4846. for (var ii = 0; ii < inputVerticesLength; ii += 2) {
  4847. var inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
  4848. var inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
  4849. var side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
  4850. if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
  4851. if (side2) {
  4852. output.push(inputX2);
  4853. output.push(inputY2);
  4854. continue;
  4855. }
  4856. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  4857. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
  4858. output.push(edgeX + (edgeX2 - edgeX) * ua);
  4859. output.push(edgeY + (edgeY2 - edgeY) * ua);
  4860. }
  4861. else if (side2) {
  4862. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  4863. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
  4864. output.push(edgeX + (edgeX2 - edgeX) * ua);
  4865. output.push(edgeY + (edgeY2 - edgeY) * ua);
  4866. output.push(inputX2);
  4867. output.push(inputY2);
  4868. }
  4869. clipped = true;
  4870. }
  4871. if (outputStart == output.length) {
  4872. originalOutput.length = 0;
  4873. return true;
  4874. }
  4875. output.push(output[0]);
  4876. output.push(output[1]);
  4877. if (i == clippingVerticesLast)
  4878. break;
  4879. var temp = output;
  4880. output = input;
  4881. output.length = 0;
  4882. input = temp;
  4883. }
  4884. if (originalOutput != output) {
  4885. originalOutput.length = 0;
  4886. for (var i = 0, n = output.length - 2; i < n; i++)
  4887. originalOutput[i] = output[i];
  4888. }
  4889. else
  4890. originalOutput.length = originalOutput.length - 2;
  4891. return clipped;
  4892. };
  4893. SkeletonClipping.makeClockwise = function (polygon) {
  4894. var vertices = polygon;
  4895. var verticeslength = polygon.length;
  4896. var area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0;
  4897. for (var i = 0, n = verticeslength - 3; i < n; i += 2) {
  4898. p1x = vertices[i];
  4899. p1y = vertices[i + 1];
  4900. p2x = vertices[i + 2];
  4901. p2y = vertices[i + 3];
  4902. area += p1x * p2y - p2x * p1y;
  4903. }
  4904. if (area < 0)
  4905. return;
  4906. for (var i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
  4907. var x = vertices[i], y = vertices[i + 1];
  4908. var other = lastX - i;
  4909. vertices[i] = vertices[other];
  4910. vertices[i + 1] = vertices[other + 1];
  4911. vertices[other] = x;
  4912. vertices[other + 1] = y;
  4913. }
  4914. };
  4915. return SkeletonClipping;
  4916. }());
  4917. spine.SkeletonClipping = SkeletonClipping;
  4918. })(spine || (spine = {}));
  4919. var spine;
  4920. (function (spine) {
  4921. var SkeletonData = (function () {
  4922. function SkeletonData() {
  4923. this.bones = new Array();
  4924. this.slots = new Array();
  4925. this.skins = new Array();
  4926. this.events = new Array();
  4927. this.animations = new Array();
  4928. this.ikConstraints = new Array();
  4929. this.transformConstraints = new Array();
  4930. this.pathConstraints = new Array();
  4931. this.fps = 0;
  4932. }
  4933. SkeletonData.prototype.findBone = function (boneName) {
  4934. if (boneName == null)
  4935. throw new Error("boneName cannot be null.");
  4936. var bones = this.bones;
  4937. for (var i = 0, n = bones.length; i < n; i++) {
  4938. var bone = bones[i];
  4939. if (bone.name == boneName)
  4940. return bone;
  4941. }
  4942. return null;
  4943. };
  4944. SkeletonData.prototype.findBoneIndex = function (boneName) {
  4945. if (boneName == null)
  4946. throw new Error("boneName cannot be null.");
  4947. var bones = this.bones;
  4948. for (var i = 0, n = bones.length; i < n; i++)
  4949. if (bones[i].name == boneName)
  4950. return i;
  4951. return -1;
  4952. };
  4953. SkeletonData.prototype.findSlot = function (slotName) {
  4954. if (slotName == null)
  4955. throw new Error("slotName cannot be null.");
  4956. var slots = this.slots;
  4957. for (var i = 0, n = slots.length; i < n; i++) {
  4958. var slot = slots[i];
  4959. if (slot.name == slotName)
  4960. return slot;
  4961. }
  4962. return null;
  4963. };
  4964. SkeletonData.prototype.findSlotIndex = function (slotName) {
  4965. if (slotName == null)
  4966. throw new Error("slotName cannot be null.");
  4967. var slots = this.slots;
  4968. for (var i = 0, n = slots.length; i < n; i++)
  4969. if (slots[i].name == slotName)
  4970. return i;
  4971. return -1;
  4972. };
  4973. SkeletonData.prototype.findSkin = function (skinName) {
  4974. if (skinName == null)
  4975. throw new Error("skinName cannot be null.");
  4976. var skins = this.skins;
  4977. for (var i = 0, n = skins.length; i < n; i++) {
  4978. var skin = skins[i];
  4979. if (skin.name == skinName)
  4980. return skin;
  4981. }
  4982. return null;
  4983. };
  4984. SkeletonData.prototype.findEvent = function (eventDataName) {
  4985. if (eventDataName == null)
  4986. throw new Error("eventDataName cannot be null.");
  4987. var events = this.events;
  4988. for (var i = 0, n = events.length; i < n; i++) {
  4989. var event_5 = events[i];
  4990. if (event_5.name == eventDataName)
  4991. return event_5;
  4992. }
  4993. return null;
  4994. };
  4995. SkeletonData.prototype.findAnimation = function (animationName) {
  4996. if (animationName == null)
  4997. throw new Error("animationName cannot be null.");
  4998. var animations = this.animations;
  4999. for (var i = 0, n = animations.length; i < n; i++) {
  5000. var animation = animations[i];
  5001. if (animation.name == animationName)
  5002. return animation;
  5003. }
  5004. return null;
  5005. };
  5006. SkeletonData.prototype.findIkConstraint = function (constraintName) {
  5007. if (constraintName == null)
  5008. throw new Error("constraintName cannot be null.");
  5009. var ikConstraints = this.ikConstraints;
  5010. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  5011. var constraint = ikConstraints[i];
  5012. if (constraint.name == constraintName)
  5013. return constraint;
  5014. }
  5015. return null;
  5016. };
  5017. SkeletonData.prototype.findTransformConstraint = function (constraintName) {
  5018. if (constraintName == null)
  5019. throw new Error("constraintName cannot be null.");
  5020. var transformConstraints = this.transformConstraints;
  5021. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  5022. var constraint = transformConstraints[i];
  5023. if (constraint.name == constraintName)
  5024. return constraint;
  5025. }
  5026. return null;
  5027. };
  5028. SkeletonData.prototype.findPathConstraint = function (constraintName) {
  5029. if (constraintName == null)
  5030. throw new Error("constraintName cannot be null.");
  5031. var pathConstraints = this.pathConstraints;
  5032. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  5033. var constraint = pathConstraints[i];
  5034. if (constraint.name == constraintName)
  5035. return constraint;
  5036. }
  5037. return null;
  5038. };
  5039. SkeletonData.prototype.findPathConstraintIndex = function (pathConstraintName) {
  5040. if (pathConstraintName == null)
  5041. throw new Error("pathConstraintName cannot be null.");
  5042. var pathConstraints = this.pathConstraints;
  5043. for (var i = 0, n = pathConstraints.length; i < n; i++)
  5044. if (pathConstraints[i].name == pathConstraintName)
  5045. return i;
  5046. return -1;
  5047. };
  5048. return SkeletonData;
  5049. }());
  5050. spine.SkeletonData = SkeletonData;
  5051. })(spine || (spine = {}));
  5052. var spine;
  5053. (function (spine) {
  5054. var SkeletonJson = (function () {
  5055. function SkeletonJson(attachmentLoader) {
  5056. this.scale = 1;
  5057. this.linkedMeshes = new Array();
  5058. this.attachmentLoader = attachmentLoader;
  5059. }
  5060. SkeletonJson.prototype.readSkeletonData = function (json) {
  5061. var scale = this.scale;
  5062. var skeletonData = new spine.SkeletonData();
  5063. var root = typeof (json) === "string" ? JSON.parse(json) : json;
  5064. var skeletonMap = root.skeleton;
  5065. if (skeletonMap != null) {
  5066. skeletonData.hash = skeletonMap.hash;
  5067. skeletonData.version = skeletonMap.spine;
  5068. skeletonData.width = skeletonMap.width;
  5069. skeletonData.height = skeletonMap.height;
  5070. skeletonData.fps = skeletonMap.fps;
  5071. skeletonData.imagesPath = skeletonMap.images;
  5072. }
  5073. if (root.bones) {
  5074. for (var i = 0; i < root.bones.length; i++) {
  5075. var boneMap = root.bones[i];
  5076. var parent_5 = null;
  5077. var parentName = this.getValue(boneMap, "parent", null);
  5078. if (parentName != null) {
  5079. parent_5 = skeletonData.findBone(parentName);
  5080. if (parent_5 == null)
  5081. throw new Error("Parent bone not found: " + parentName);
  5082. }
  5083. var data = new spine.BoneData(skeletonData.bones.length, boneMap.name, parent_5);
  5084. data.length = this.getValue(boneMap, "length", 0) * scale;
  5085. data.x = this.getValue(boneMap, "x", 0) * scale;
  5086. data.y = this.getValue(boneMap, "y", 0) * scale;
  5087. data.rotation = this.getValue(boneMap, "rotation", 0);
  5088. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  5089. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  5090. data.shearX = this.getValue(boneMap, "shearX", 0);
  5091. data.shearY = this.getValue(boneMap, "shearY", 0);
  5092. data.transformMode = SkeletonJson.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  5093. skeletonData.bones.push(data);
  5094. }
  5095. }
  5096. if (root.slots) {
  5097. for (var i = 0; i < root.slots.length; i++) {
  5098. var slotMap = root.slots[i];
  5099. var slotName = slotMap.name;
  5100. var boneName = slotMap.bone;
  5101. var boneData = skeletonData.findBone(boneName);
  5102. if (boneData == null)
  5103. throw new Error("Slot bone not found: " + boneName);
  5104. var data = new spine.SlotData(skeletonData.slots.length, slotName, boneData);
  5105. var color = this.getValue(slotMap, "color", null);
  5106. if (color != null)
  5107. data.color.setFromString(color);
  5108. var dark = this.getValue(slotMap, "dark", null);
  5109. if (dark != null) {
  5110. data.darkColor = new spine.Color(1, 1, 1, 1);
  5111. data.darkColor.setFromString(dark);
  5112. }
  5113. data.attachmentName = this.getValue(slotMap, "attachment", null);
  5114. data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  5115. skeletonData.slots.push(data);
  5116. }
  5117. }
  5118. if (root.ik) {
  5119. for (var i = 0; i < root.ik.length; i++) {
  5120. var constraintMap = root.ik[i];
  5121. var data = new spine.IkConstraintData(constraintMap.name);
  5122. data.order = this.getValue(constraintMap, "order", 0);
  5123. for (var j = 0; j < constraintMap.bones.length; j++) {
  5124. var boneName = constraintMap.bones[j];
  5125. var bone = skeletonData.findBone(boneName);
  5126. if (bone == null)
  5127. throw new Error("IK bone not found: " + boneName);
  5128. data.bones.push(bone);
  5129. }
  5130. var targetName = constraintMap.target;
  5131. data.target = skeletonData.findBone(targetName);
  5132. if (data.target == null)
  5133. throw new Error("IK target bone not found: " + targetName);
  5134. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  5135. data.mix = this.getValue(constraintMap, "mix", 1);
  5136. skeletonData.ikConstraints.push(data);
  5137. }
  5138. }
  5139. if (root.transform) {
  5140. for (var i = 0; i < root.transform.length; i++) {
  5141. var constraintMap = root.transform[i];
  5142. var data = new spine.TransformConstraintData(constraintMap.name);
  5143. data.order = this.getValue(constraintMap, "order", 0);
  5144. for (var j = 0; j < constraintMap.bones.length; j++) {
  5145. var boneName = constraintMap.bones[j];
  5146. var bone = skeletonData.findBone(boneName);
  5147. if (bone == null)
  5148. throw new Error("Transform constraint bone not found: " + boneName);
  5149. data.bones.push(bone);
  5150. }
  5151. var targetName = constraintMap.target;
  5152. data.target = skeletonData.findBone(targetName);
  5153. if (data.target == null)
  5154. throw new Error("Transform constraint target bone not found: " + targetName);
  5155. data.local = this.getValue(constraintMap, "local", false);
  5156. data.relative = this.getValue(constraintMap, "relative", false);
  5157. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  5158. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  5159. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  5160. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  5161. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  5162. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  5163. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  5164. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  5165. data.scaleMix = this.getValue(constraintMap, "scaleMix", 1);
  5166. data.shearMix = this.getValue(constraintMap, "shearMix", 1);
  5167. skeletonData.transformConstraints.push(data);
  5168. }
  5169. }
  5170. if (root.path) {
  5171. for (var i = 0; i < root.path.length; i++) {
  5172. var constraintMap = root.path[i];
  5173. var data = new spine.PathConstraintData(constraintMap.name);
  5174. data.order = this.getValue(constraintMap, "order", 0);
  5175. for (var j = 0; j < constraintMap.bones.length; j++) {
  5176. var boneName = constraintMap.bones[j];
  5177. var bone = skeletonData.findBone(boneName);
  5178. if (bone == null)
  5179. throw new Error("Transform constraint bone not found: " + boneName);
  5180. data.bones.push(bone);
  5181. }
  5182. var targetName = constraintMap.target;
  5183. data.target = skeletonData.findSlot(targetName);
  5184. if (data.target == null)
  5185. throw new Error("Path target slot not found: " + targetName);
  5186. data.positionMode = SkeletonJson.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  5187. data.spacingMode = SkeletonJson.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  5188. data.rotateMode = SkeletonJson.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  5189. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  5190. data.position = this.getValue(constraintMap, "position", 0);
  5191. if (data.positionMode == spine.PositionMode.Fixed)
  5192. data.position *= scale;
  5193. data.spacing = this.getValue(constraintMap, "spacing", 0);
  5194. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  5195. data.spacing *= scale;
  5196. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  5197. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  5198. skeletonData.pathConstraints.push(data);
  5199. }
  5200. }
  5201. if (root.skins) {
  5202. for (var skinName in root.skins) {
  5203. var skinMap = root.skins[skinName];
  5204. var skin = new spine.Skin(skinName);
  5205. for (var slotName in skinMap) {
  5206. var slotIndex = skeletonData.findSlotIndex(slotName);
  5207. if (slotIndex == -1)
  5208. throw new Error("Slot not found: " + slotName);
  5209. var slotMap = skinMap[slotName];
  5210. for (var entryName in slotMap) {
  5211. var attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
  5212. if (attachment != null)
  5213. skin.addAttachment(slotIndex, entryName, attachment);
  5214. }
  5215. }
  5216. skeletonData.skins.push(skin);
  5217. if (skin.name == "default")
  5218. skeletonData.defaultSkin = skin;
  5219. }
  5220. }
  5221. for (var i = 0, n = this.linkedMeshes.length; i < n; i++) {
  5222. var linkedMesh = this.linkedMeshes[i];
  5223. var skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  5224. if (skin == null)
  5225. throw new Error("Skin not found: " + linkedMesh.skin);
  5226. var parent_6 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  5227. if (parent_6 == null)
  5228. throw new Error("Parent mesh not found: " + linkedMesh.parent);
  5229. linkedMesh.mesh.setParentMesh(parent_6);
  5230. linkedMesh.mesh.updateUVs();
  5231. }
  5232. this.linkedMeshes.length = 0;
  5233. if (root.events) {
  5234. for (var eventName in root.events) {
  5235. var eventMap = root.events[eventName];
  5236. var data = new spine.EventData(eventName);
  5237. data.intValue = this.getValue(eventMap, "int", 0);
  5238. data.floatValue = this.getValue(eventMap, "float", 0);
  5239. data.stringValue = this.getValue(eventMap, "string", "");
  5240. skeletonData.events.push(data);
  5241. }
  5242. }
  5243. if (root.animations) {
  5244. for (var animationName in root.animations) {
  5245. var animationMap = root.animations[animationName];
  5246. this.readAnimation(animationMap, animationName, skeletonData);
  5247. }
  5248. }
  5249. return skeletonData;
  5250. };
  5251. SkeletonJson.prototype.readAttachment = function (map, skin, slotIndex, name, skeletonData) {
  5252. var scale = this.scale;
  5253. name = this.getValue(map, "name", name);
  5254. var type = this.getValue(map, "type", "region");
  5255. switch (type) {
  5256. case "region": {
  5257. var path = this.getValue(map, "path", name);
  5258. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  5259. if (region == null)
  5260. return null;
  5261. region.path = path;
  5262. region.x = this.getValue(map, "x", 0) * scale;
  5263. region.y = this.getValue(map, "y", 0) * scale;
  5264. region.scaleX = this.getValue(map, "scaleX", 1);
  5265. region.scaleY = this.getValue(map, "scaleY", 1);
  5266. region.rotation = this.getValue(map, "rotation", 0);
  5267. region.width = map.width * scale;
  5268. region.height = map.height * scale;
  5269. var color = this.getValue(map, "color", null);
  5270. if (color != null)
  5271. region.color.setFromString(color);
  5272. region.updateOffset();
  5273. return region;
  5274. }
  5275. case "boundingbox": {
  5276. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  5277. if (box == null)
  5278. return null;
  5279. this.readVertices(map, box, map.vertexCount << 1);
  5280. var color = this.getValue(map, "color", null);
  5281. if (color != null)
  5282. box.color.setFromString(color);
  5283. return box;
  5284. }
  5285. case "mesh":
  5286. case "linkedmesh": {
  5287. var path = this.getValue(map, "path", name);
  5288. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  5289. if (mesh == null)
  5290. return null;
  5291. mesh.path = path;
  5292. var color = this.getValue(map, "color", null);
  5293. if (color != null)
  5294. mesh.color.setFromString(color);
  5295. var parent_7 = this.getValue(map, "parent", null);
  5296. if (parent_7 != null) {
  5297. mesh.inheritDeform = this.getValue(map, "deform", true);
  5298. this.linkedMeshes.push(new LinkedMesh(mesh, this.getValue(map, "skin", null), slotIndex, parent_7));
  5299. return mesh;
  5300. }
  5301. var uvs = map.uvs;
  5302. this.readVertices(map, mesh, uvs.length);
  5303. mesh.triangles = map.triangles;
  5304. mesh.regionUVs = uvs;
  5305. mesh.updateUVs();
  5306. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  5307. return mesh;
  5308. }
  5309. case "path": {
  5310. var path = this.attachmentLoader.newPathAttachment(skin, name);
  5311. if (path == null)
  5312. return null;
  5313. path.closed = this.getValue(map, "closed", false);
  5314. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  5315. var vertexCount = map.vertexCount;
  5316. this.readVertices(map, path, vertexCount << 1);
  5317. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  5318. for (var i = 0; i < map.lengths.length; i++)
  5319. lengths[i] = map.lengths[i] * scale;
  5320. path.lengths = lengths;
  5321. var color = this.getValue(map, "color", null);
  5322. if (color != null)
  5323. path.color.setFromString(color);
  5324. return path;
  5325. }
  5326. case "point": {
  5327. var point = this.attachmentLoader.newPointAttachment(skin, name);
  5328. if (point == null)
  5329. return null;
  5330. point.x = this.getValue(map, "x", 0) * scale;
  5331. point.y = this.getValue(map, "y", 0) * scale;
  5332. point.rotation = this.getValue(map, "rotation", 0);
  5333. var color = this.getValue(map, "color", null);
  5334. if (color != null)
  5335. point.color.setFromString(color);
  5336. return point;
  5337. }
  5338. case "clipping": {
  5339. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  5340. if (clip == null)
  5341. return null;
  5342. var end = this.getValue(map, "end", null);
  5343. if (end != null) {
  5344. var slot = skeletonData.findSlot(end);
  5345. if (slot == null)
  5346. throw new Error("Clipping end slot not found: " + end);
  5347. clip.endSlot = slot;
  5348. }
  5349. var vertexCount = map.vertexCount;
  5350. this.readVertices(map, clip, vertexCount << 1);
  5351. var color = this.getValue(map, "color", null);
  5352. if (color != null)
  5353. clip.color.setFromString(color);
  5354. return clip;
  5355. }
  5356. }
  5357. return null;
  5358. };
  5359. SkeletonJson.prototype.readVertices = function (map, attachment, verticesLength) {
  5360. var scale = this.scale;
  5361. attachment.worldVerticesLength = verticesLength;
  5362. var vertices = map.vertices;
  5363. if (verticesLength == vertices.length) {
  5364. var scaledVertices = spine.Utils.toFloatArray(vertices);
  5365. if (scale != 1) {
  5366. for (var i = 0, n = vertices.length; i < n; i++)
  5367. scaledVertices[i] *= scale;
  5368. }
  5369. attachment.vertices = scaledVertices;
  5370. return;
  5371. }
  5372. var weights = new Array();
  5373. var bones = new Array();
  5374. for (var i = 0, n = vertices.length; i < n;) {
  5375. var boneCount = vertices[i++];
  5376. bones.push(boneCount);
  5377. for (var nn = i + boneCount * 4; i < nn; i += 4) {
  5378. bones.push(vertices[i]);
  5379. weights.push(vertices[i + 1] * scale);
  5380. weights.push(vertices[i + 2] * scale);
  5381. weights.push(vertices[i + 3]);
  5382. }
  5383. }
  5384. attachment.bones = bones;
  5385. attachment.vertices = spine.Utils.toFloatArray(weights);
  5386. };
  5387. SkeletonJson.prototype.readAnimation = function (map, name, skeletonData) {
  5388. var scale = this.scale;
  5389. var timelines = new Array();
  5390. var duration = 0;
  5391. if (map.slots) {
  5392. for (var slotName in map.slots) {
  5393. var slotMap = map.slots[slotName];
  5394. var slotIndex = skeletonData.findSlotIndex(slotName);
  5395. if (slotIndex == -1)
  5396. throw new Error("Slot not found: " + slotName);
  5397. for (var timelineName in slotMap) {
  5398. var timelineMap = slotMap[timelineName];
  5399. if (timelineName == "attachment") {
  5400. var timeline = new spine.AttachmentTimeline(timelineMap.length);
  5401. timeline.slotIndex = slotIndex;
  5402. var frameIndex = 0;
  5403. for (var i = 0; i < timelineMap.length; i++) {
  5404. var valueMap = timelineMap[i];
  5405. timeline.setFrame(frameIndex++, valueMap.time, valueMap.name);
  5406. }
  5407. timelines.push(timeline);
  5408. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5409. }
  5410. else if (timelineName == "color") {
  5411. var timeline = new spine.ColorTimeline(timelineMap.length);
  5412. timeline.slotIndex = slotIndex;
  5413. var frameIndex = 0;
  5414. for (var i = 0; i < timelineMap.length; i++) {
  5415. var valueMap = timelineMap[i];
  5416. var color = new spine.Color();
  5417. color.setFromString(valueMap.color);
  5418. timeline.setFrame(frameIndex, valueMap.time, color.r, color.g, color.b, color.a);
  5419. this.readCurve(valueMap, timeline, frameIndex);
  5420. frameIndex++;
  5421. }
  5422. timelines.push(timeline);
  5423. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]);
  5424. }
  5425. else if (timelineName == "twoColor") {
  5426. var timeline = new spine.TwoColorTimeline(timelineMap.length);
  5427. timeline.slotIndex = slotIndex;
  5428. var frameIndex = 0;
  5429. for (var i = 0; i < timelineMap.length; i++) {
  5430. var valueMap = timelineMap[i];
  5431. var light = new spine.Color();
  5432. var dark = new spine.Color();
  5433. light.setFromString(valueMap.light);
  5434. dark.setFromString(valueMap.dark);
  5435. timeline.setFrame(frameIndex, valueMap.time, light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
  5436. this.readCurve(valueMap, timeline, frameIndex);
  5437. frameIndex++;
  5438. }
  5439. timelines.push(timeline);
  5440. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TwoColorTimeline.ENTRIES]);
  5441. }
  5442. else
  5443. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  5444. }
  5445. }
  5446. }
  5447. if (map.bones) {
  5448. for (var boneName in map.bones) {
  5449. var boneMap = map.bones[boneName];
  5450. var boneIndex = skeletonData.findBoneIndex(boneName);
  5451. if (boneIndex == -1)
  5452. throw new Error("Bone not found: " + boneName);
  5453. for (var timelineName in boneMap) {
  5454. var timelineMap = boneMap[timelineName];
  5455. if (timelineName === "rotate") {
  5456. var timeline = new spine.RotateTimeline(timelineMap.length);
  5457. timeline.boneIndex = boneIndex;
  5458. var frameIndex = 0;
  5459. for (var i = 0; i < timelineMap.length; i++) {
  5460. var valueMap = timelineMap[i];
  5461. timeline.setFrame(frameIndex, valueMap.time, valueMap.angle);
  5462. this.readCurve(valueMap, timeline, frameIndex);
  5463. frameIndex++;
  5464. }
  5465. timelines.push(timeline);
  5466. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.RotateTimeline.ENTRIES]);
  5467. }
  5468. else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
  5469. var timeline = null;
  5470. var timelineScale = 1;
  5471. if (timelineName === "scale")
  5472. timeline = new spine.ScaleTimeline(timelineMap.length);
  5473. else if (timelineName === "shear")
  5474. timeline = new spine.ShearTimeline(timelineMap.length);
  5475. else {
  5476. timeline = new spine.TranslateTimeline(timelineMap.length);
  5477. timelineScale = scale;
  5478. }
  5479. timeline.boneIndex = boneIndex;
  5480. var frameIndex = 0;
  5481. for (var i = 0; i < timelineMap.length; i++) {
  5482. var valueMap = timelineMap[i];
  5483. var x = this.getValue(valueMap, "x", 0), y = this.getValue(valueMap, "y", 0);
  5484. timeline.setFrame(frameIndex, valueMap.time, x * timelineScale, y * timelineScale);
  5485. this.readCurve(valueMap, timeline, frameIndex);
  5486. frameIndex++;
  5487. }
  5488. timelines.push(timeline);
  5489. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TranslateTimeline.ENTRIES]);
  5490. }
  5491. else
  5492. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  5493. }
  5494. }
  5495. }
  5496. if (map.ik) {
  5497. for (var constraintName in map.ik) {
  5498. var constraintMap = map.ik[constraintName];
  5499. var constraint = skeletonData.findIkConstraint(constraintName);
  5500. var timeline = new spine.IkConstraintTimeline(constraintMap.length);
  5501. timeline.ikConstraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  5502. var frameIndex = 0;
  5503. for (var i = 0; i < constraintMap.length; i++) {
  5504. var valueMap = constraintMap[i];
  5505. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "mix", 1), this.getValue(valueMap, "bendPositive", true) ? 1 : -1);
  5506. this.readCurve(valueMap, timeline, frameIndex);
  5507. frameIndex++;
  5508. }
  5509. timelines.push(timeline);
  5510. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.IkConstraintTimeline.ENTRIES]);
  5511. }
  5512. }
  5513. if (map.transform) {
  5514. for (var constraintName in map.transform) {
  5515. var constraintMap = map.transform[constraintName];
  5516. var constraint = skeletonData.findTransformConstraint(constraintName);
  5517. var timeline = new spine.TransformConstraintTimeline(constraintMap.length);
  5518. timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  5519. var frameIndex = 0;
  5520. for (var i = 0; i < constraintMap.length; i++) {
  5521. var valueMap = constraintMap[i];
  5522. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1), this.getValue(valueMap, "scaleMix", 1), this.getValue(valueMap, "shearMix", 1));
  5523. this.readCurve(valueMap, timeline, frameIndex);
  5524. frameIndex++;
  5525. }
  5526. timelines.push(timeline);
  5527. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TransformConstraintTimeline.ENTRIES]);
  5528. }
  5529. }
  5530. if (map.paths) {
  5531. for (var constraintName in map.paths) {
  5532. var constraintMap = map.paths[constraintName];
  5533. var index = skeletonData.findPathConstraintIndex(constraintName);
  5534. if (index == -1)
  5535. throw new Error("Path constraint not found: " + constraintName);
  5536. var data = skeletonData.pathConstraints[index];
  5537. for (var timelineName in constraintMap) {
  5538. var timelineMap = constraintMap[timelineName];
  5539. if (timelineName === "position" || timelineName === "spacing") {
  5540. var timeline = null;
  5541. var timelineScale = 1;
  5542. if (timelineName === "spacing") {
  5543. timeline = new spine.PathConstraintSpacingTimeline(timelineMap.length);
  5544. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  5545. timelineScale = scale;
  5546. }
  5547. else {
  5548. timeline = new spine.PathConstraintPositionTimeline(timelineMap.length);
  5549. if (data.positionMode == spine.PositionMode.Fixed)
  5550. timelineScale = scale;
  5551. }
  5552. timeline.pathConstraintIndex = index;
  5553. var frameIndex = 0;
  5554. for (var i = 0; i < timelineMap.length; i++) {
  5555. var valueMap = timelineMap[i];
  5556. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, timelineName, 0) * timelineScale);
  5557. this.readCurve(valueMap, timeline, frameIndex);
  5558. frameIndex++;
  5559. }
  5560. timelines.push(timeline);
  5561. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintPositionTimeline.ENTRIES]);
  5562. }
  5563. else if (timelineName === "mix") {
  5564. var timeline = new spine.PathConstraintMixTimeline(timelineMap.length);
  5565. timeline.pathConstraintIndex = index;
  5566. var frameIndex = 0;
  5567. for (var i = 0; i < timelineMap.length; i++) {
  5568. var valueMap = timelineMap[i];
  5569. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1));
  5570. this.readCurve(valueMap, timeline, frameIndex);
  5571. frameIndex++;
  5572. }
  5573. timelines.push(timeline);
  5574. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintMixTimeline.ENTRIES]);
  5575. }
  5576. }
  5577. }
  5578. }
  5579. if (map.deform) {
  5580. for (var deformName in map.deform) {
  5581. var deformMap = map.deform[deformName];
  5582. var skin = skeletonData.findSkin(deformName);
  5583. if (skin == null)
  5584. throw new Error("Skin not found: " + deformName);
  5585. for (var slotName in deformMap) {
  5586. var slotMap = deformMap[slotName];
  5587. var slotIndex = skeletonData.findSlotIndex(slotName);
  5588. if (slotIndex == -1)
  5589. throw new Error("Slot not found: " + slotMap.name);
  5590. for (var timelineName in slotMap) {
  5591. var timelineMap = slotMap[timelineName];
  5592. var attachment = skin.getAttachment(slotIndex, timelineName);
  5593. if (attachment == null)
  5594. throw new Error("Deform attachment not found: " + timelineMap.name);
  5595. var weighted = attachment.bones != null;
  5596. var vertices = attachment.vertices;
  5597. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  5598. var timeline = new spine.DeformTimeline(timelineMap.length);
  5599. timeline.slotIndex = slotIndex;
  5600. timeline.attachment = attachment;
  5601. var frameIndex = 0;
  5602. for (var j = 0; j < timelineMap.length; j++) {
  5603. var valueMap = timelineMap[j];
  5604. var deform = void 0;
  5605. var verticesValue = this.getValue(valueMap, "vertices", null);
  5606. if (verticesValue == null)
  5607. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  5608. else {
  5609. deform = spine.Utils.newFloatArray(deformLength);
  5610. var start = this.getValue(valueMap, "offset", 0);
  5611. spine.Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  5612. if (scale != 1) {
  5613. for (var i = start, n = i + verticesValue.length; i < n; i++)
  5614. deform[i] *= scale;
  5615. }
  5616. if (!weighted) {
  5617. for (var i = 0; i < deformLength; i++)
  5618. deform[i] += vertices[i];
  5619. }
  5620. }
  5621. timeline.setFrame(frameIndex, valueMap.time, deform);
  5622. this.readCurve(valueMap, timeline, frameIndex);
  5623. frameIndex++;
  5624. }
  5625. timelines.push(timeline);
  5626. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5627. }
  5628. }
  5629. }
  5630. }
  5631. var drawOrderNode = map.drawOrder;
  5632. if (drawOrderNode == null)
  5633. drawOrderNode = map.draworder;
  5634. if (drawOrderNode != null) {
  5635. var timeline = new spine.DrawOrderTimeline(drawOrderNode.length);
  5636. var slotCount = skeletonData.slots.length;
  5637. var frameIndex = 0;
  5638. for (var j = 0; j < drawOrderNode.length; j++) {
  5639. var drawOrderMap = drawOrderNode[j];
  5640. var drawOrder = null;
  5641. var offsets = this.getValue(drawOrderMap, "offsets", null);
  5642. if (offsets != null) {
  5643. drawOrder = spine.Utils.newArray(slotCount, -1);
  5644. var unchanged = spine.Utils.newArray(slotCount - offsets.length, 0);
  5645. var originalIndex = 0, unchangedIndex = 0;
  5646. for (var i = 0; i < offsets.length; i++) {
  5647. var offsetMap = offsets[i];
  5648. var slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  5649. if (slotIndex == -1)
  5650. throw new Error("Slot not found: " + offsetMap.slot);
  5651. while (originalIndex != slotIndex)
  5652. unchanged[unchangedIndex++] = originalIndex++;
  5653. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  5654. }
  5655. while (originalIndex < slotCount)
  5656. unchanged[unchangedIndex++] = originalIndex++;
  5657. for (var i = slotCount - 1; i >= 0; i--)
  5658. if (drawOrder[i] == -1)
  5659. drawOrder[i] = unchanged[--unchangedIndex];
  5660. }
  5661. timeline.setFrame(frameIndex++, drawOrderMap.time, drawOrder);
  5662. }
  5663. timelines.push(timeline);
  5664. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5665. }
  5666. if (map.events) {
  5667. var timeline = new spine.EventTimeline(map.events.length);
  5668. var frameIndex = 0;
  5669. for (var i = 0; i < map.events.length; i++) {
  5670. var eventMap = map.events[i];
  5671. var eventData = skeletonData.findEvent(eventMap.name);
  5672. if (eventData == null)
  5673. throw new Error("Event not found: " + eventMap.name);
  5674. var event_6 = new spine.Event(spine.Utils.toSinglePrecision(eventMap.time), eventData);
  5675. event_6.intValue = this.getValue(eventMap, "int", eventData.intValue);
  5676. event_6.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  5677. event_6.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  5678. timeline.setFrame(frameIndex++, event_6);
  5679. }
  5680. timelines.push(timeline);
  5681. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5682. }
  5683. if (isNaN(duration)) {
  5684. throw new Error("Error while parsing animation, duration is NaN");
  5685. }
  5686. skeletonData.animations.push(new spine.Animation(name, timelines, duration));
  5687. };
  5688. SkeletonJson.prototype.readCurve = function (map, timeline, frameIndex) {
  5689. if (!map.curve)
  5690. return;
  5691. if (map.curve === "stepped")
  5692. timeline.setStepped(frameIndex);
  5693. else if (Object.prototype.toString.call(map.curve) === '[object Array]') {
  5694. var curve = map.curve;
  5695. timeline.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]);
  5696. }
  5697. };
  5698. SkeletonJson.prototype.getValue = function (map, prop, defaultValue) {
  5699. return map[prop] !== undefined ? map[prop] : defaultValue;
  5700. };
  5701. SkeletonJson.blendModeFromString = function (str) {
  5702. str = str.toLowerCase();
  5703. if (str == "normal")
  5704. return spine.BlendMode.Normal;
  5705. if (str == "additive")
  5706. return spine.BlendMode.Additive;
  5707. if (str == "multiply")
  5708. return spine.BlendMode.Multiply;
  5709. if (str == "screen")
  5710. return spine.BlendMode.Screen;
  5711. throw new Error("Unknown blend mode: " + str);
  5712. };
  5713. SkeletonJson.positionModeFromString = function (str) {
  5714. str = str.toLowerCase();
  5715. if (str == "fixed")
  5716. return spine.PositionMode.Fixed;
  5717. if (str == "percent")
  5718. return spine.PositionMode.Percent;
  5719. throw new Error("Unknown position mode: " + str);
  5720. };
  5721. SkeletonJson.spacingModeFromString = function (str) {
  5722. str = str.toLowerCase();
  5723. if (str == "length")
  5724. return spine.SpacingMode.Length;
  5725. if (str == "fixed")
  5726. return spine.SpacingMode.Fixed;
  5727. if (str == "percent")
  5728. return spine.SpacingMode.Percent;
  5729. throw new Error("Unknown position mode: " + str);
  5730. };
  5731. SkeletonJson.rotateModeFromString = function (str) {
  5732. str = str.toLowerCase();
  5733. if (str == "tangent")
  5734. return spine.RotateMode.Tangent;
  5735. if (str == "chain")
  5736. return spine.RotateMode.Chain;
  5737. if (str == "chainscale")
  5738. return spine.RotateMode.ChainScale;
  5739. throw new Error("Unknown rotate mode: " + str);
  5740. };
  5741. SkeletonJson.transformModeFromString = function (str) {
  5742. str = str.toLowerCase();
  5743. if (str == "normal")
  5744. return spine.TransformMode.Normal;
  5745. if (str == "onlytranslation")
  5746. return spine.TransformMode.OnlyTranslation;
  5747. if (str == "norotationorreflection")
  5748. return spine.TransformMode.NoRotationOrReflection;
  5749. if (str == "noscale")
  5750. return spine.TransformMode.NoScale;
  5751. if (str == "noscaleorreflection")
  5752. return spine.TransformMode.NoScaleOrReflection;
  5753. throw new Error("Unknown transform mode: " + str);
  5754. };
  5755. return SkeletonJson;
  5756. }());
  5757. spine.SkeletonJson = SkeletonJson;
  5758. var LinkedMesh = (function () {
  5759. function LinkedMesh(mesh, skin, slotIndex, parent) {
  5760. this.mesh = mesh;
  5761. this.skin = skin;
  5762. this.slotIndex = slotIndex;
  5763. this.parent = parent;
  5764. }
  5765. return LinkedMesh;
  5766. }());
  5767. })(spine || (spine = {}));
  5768. var spine;
  5769. (function (spine) {
  5770. var Skin = (function () {
  5771. function Skin(name) {
  5772. this.attachments = new Array();
  5773. if (name == null)
  5774. throw new Error("name cannot be null.");
  5775. this.name = name;
  5776. }
  5777. Skin.prototype.addAttachment = function (slotIndex, name, attachment) {
  5778. if (attachment == null)
  5779. throw new Error("attachment cannot be null.");
  5780. var attachments = this.attachments;
  5781. if (slotIndex >= attachments.length)
  5782. attachments.length = slotIndex + 1;
  5783. if (!attachments[slotIndex])
  5784. attachments[slotIndex] = {};
  5785. attachments[slotIndex][name] = attachment;
  5786. };
  5787. Skin.prototype.getAttachment = function (slotIndex, name) {
  5788. var dictionary = this.attachments[slotIndex];
  5789. return dictionary ? dictionary[name] : null;
  5790. };
  5791. Skin.prototype.attachAll = function (skeleton, oldSkin) {
  5792. var slotIndex = 0;
  5793. for (var i = 0; i < skeleton.slots.length; i++) {
  5794. var slot = skeleton.slots[i];
  5795. var slotAttachment = slot.getAttachment();
  5796. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  5797. var dictionary = oldSkin.attachments[slotIndex];
  5798. for (var key in dictionary) {
  5799. var skinAttachment = dictionary[key];
  5800. if (slotAttachment == skinAttachment) {
  5801. var attachment = this.getAttachment(slotIndex, key);
  5802. if (attachment != null)
  5803. slot.setAttachment(attachment);
  5804. break;
  5805. }
  5806. }
  5807. }
  5808. slotIndex++;
  5809. }
  5810. };
  5811. return Skin;
  5812. }());
  5813. spine.Skin = Skin;
  5814. })(spine || (spine = {}));
  5815. var spine;
  5816. (function (spine) {
  5817. var Slot = (function () {
  5818. function Slot(data, bone) {
  5819. this.attachmentVertices = new Array();
  5820. if (data == null)
  5821. throw new Error("data cannot be null.");
  5822. if (bone == null)
  5823. throw new Error("bone cannot be null.");
  5824. this.data = data;
  5825. this.bone = bone;
  5826. this.color = new spine.Color();
  5827. this.darkColor = data.darkColor == null ? null : new spine.Color();
  5828. this.setToSetupPose();
  5829. }
  5830. Slot.prototype.getAttachment = function () {
  5831. return this.attachment;
  5832. };
  5833. Slot.prototype.setAttachment = function (attachment) {
  5834. if (this.attachment == attachment)
  5835. return;
  5836. this.attachment = attachment;
  5837. this.attachmentTime = this.bone.skeleton.time;
  5838. this.attachmentVertices.length = 0;
  5839. };
  5840. Slot.prototype.setAttachmentTime = function (time) {
  5841. this.attachmentTime = this.bone.skeleton.time - time;
  5842. };
  5843. Slot.prototype.getAttachmentTime = function () {
  5844. return this.bone.skeleton.time - this.attachmentTime;
  5845. };
  5846. Slot.prototype.setToSetupPose = function () {
  5847. this.color.setFromColor(this.data.color);
  5848. if (this.darkColor != null)
  5849. this.darkColor.setFromColor(this.data.darkColor);
  5850. if (this.data.attachmentName == null)
  5851. this.attachment = null;
  5852. else {
  5853. this.attachment = null;
  5854. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  5855. }
  5856. };
  5857. return Slot;
  5858. }());
  5859. spine.Slot = Slot;
  5860. })(spine || (spine = {}));
  5861. var spine;
  5862. (function (spine) {
  5863. var SlotData = (function () {
  5864. function SlotData(index, name, boneData) {
  5865. this.color = new spine.Color(1, 1, 1, 1);
  5866. if (index < 0)
  5867. throw new Error("index must be >= 0.");
  5868. if (name == null)
  5869. throw new Error("name cannot be null.");
  5870. if (boneData == null)
  5871. throw new Error("boneData cannot be null.");
  5872. this.index = index;
  5873. this.name = name;
  5874. this.boneData = boneData;
  5875. }
  5876. return SlotData;
  5877. }());
  5878. spine.SlotData = SlotData;
  5879. })(spine || (spine = {}));
  5880. var spine;
  5881. (function (spine) {
  5882. var Texture = (function () {
  5883. function Texture(image) {
  5884. this._image = image;
  5885. }
  5886. Texture.prototype.getImage = function () {
  5887. return this._image;
  5888. };
  5889. Texture.filterFromString = function (text) {
  5890. switch (text.toLowerCase()) {
  5891. case "nearest": return TextureFilter.Nearest;
  5892. case "linear": return TextureFilter.Linear;
  5893. case "mipmap": return TextureFilter.MipMap;
  5894. case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest;
  5895. case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest;
  5896. case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear;
  5897. case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear;
  5898. default: throw new Error("Unknown texture filter " + text);
  5899. }
  5900. };
  5901. Texture.wrapFromString = function (text) {
  5902. switch (text.toLowerCase()) {
  5903. case "mirroredtepeat": return TextureWrap.MirroredRepeat;
  5904. case "clamptoedge": return TextureWrap.ClampToEdge;
  5905. case "repeat": return TextureWrap.Repeat;
  5906. default: throw new Error("Unknown texture wrap " + text);
  5907. }
  5908. };
  5909. return Texture;
  5910. }());
  5911. spine.Texture = Texture;
  5912. var TextureFilter;
  5913. (function (TextureFilter) {
  5914. TextureFilter[TextureFilter["Nearest"] = 9728] = "Nearest";
  5915. TextureFilter[TextureFilter["Linear"] = 9729] = "Linear";
  5916. TextureFilter[TextureFilter["MipMap"] = 9987] = "MipMap";
  5917. TextureFilter[TextureFilter["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
  5918. TextureFilter[TextureFilter["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
  5919. TextureFilter[TextureFilter["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
  5920. TextureFilter[TextureFilter["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
  5921. })(TextureFilter = spine.TextureFilter || (spine.TextureFilter = {}));
  5922. var TextureWrap;
  5923. (function (TextureWrap) {
  5924. TextureWrap[TextureWrap["MirroredRepeat"] = 33648] = "MirroredRepeat";
  5925. TextureWrap[TextureWrap["ClampToEdge"] = 33071] = "ClampToEdge";
  5926. TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat";
  5927. })(TextureWrap = spine.TextureWrap || (spine.TextureWrap = {}));
  5928. var TextureRegion = (function () {
  5929. function TextureRegion() {
  5930. this.u = 0;
  5931. this.v = 0;
  5932. this.u2 = 0;
  5933. this.v2 = 0;
  5934. this.width = 0;
  5935. this.height = 0;
  5936. this.rotate = false;
  5937. this.offsetX = 0;
  5938. this.offsetY = 0;
  5939. this.originalWidth = 0;
  5940. this.originalHeight = 0;
  5941. }
  5942. return TextureRegion;
  5943. }());
  5944. spine.TextureRegion = TextureRegion;
  5945. var FakeTexture = (function (_super) {
  5946. __extends(FakeTexture, _super);
  5947. function FakeTexture() {
  5948. return _super !== null && _super.apply(this, arguments) || this;
  5949. }
  5950. FakeTexture.prototype.setFilters = function (minFilter, magFilter) { };
  5951. FakeTexture.prototype.setWraps = function (uWrap, vWrap) { };
  5952. FakeTexture.prototype.dispose = function () { };
  5953. return FakeTexture;
  5954. }(spine.Texture));
  5955. spine.FakeTexture = FakeTexture;
  5956. })(spine || (spine = {}));
  5957. var spine;
  5958. (function (spine) {
  5959. var TextureAtlas = (function () {
  5960. function TextureAtlas(atlasText, textureLoader) {
  5961. this.pages = new Array();
  5962. this.regions = new Array();
  5963. this.load(atlasText, textureLoader);
  5964. }
  5965. TextureAtlas.prototype.load = function (atlasText, textureLoader) {
  5966. if (textureLoader == null)
  5967. throw new Error("textureLoader cannot be null.");
  5968. var reader = new TextureAtlasReader(atlasText);
  5969. var tuple = new Array(4);
  5970. var page = null;
  5971. while (true) {
  5972. var line = reader.readLine();
  5973. if (line == null)
  5974. break;
  5975. line = line.trim();
  5976. if (line.length == 0)
  5977. page = null;
  5978. else if (!page) {
  5979. page = new TextureAtlasPage();
  5980. page.name = line;
  5981. if (reader.readTuple(tuple) == 2) {
  5982. page.width = parseInt(tuple[0]);
  5983. page.height = parseInt(tuple[1]);
  5984. reader.readTuple(tuple);
  5985. }
  5986. reader.readTuple(tuple);
  5987. page.minFilter = spine.Texture.filterFromString(tuple[0]);
  5988. page.magFilter = spine.Texture.filterFromString(tuple[1]);
  5989. var direction = reader.readValue();
  5990. page.uWrap = spine.TextureWrap.ClampToEdge;
  5991. page.vWrap = spine.TextureWrap.ClampToEdge;
  5992. if (direction == "x")
  5993. page.uWrap = spine.TextureWrap.Repeat;
  5994. else if (direction == "y")
  5995. page.vWrap = spine.TextureWrap.Repeat;
  5996. else if (direction == "xy")
  5997. page.uWrap = page.vWrap = spine.TextureWrap.Repeat;
  5998. page.texture = textureLoader(line);
  5999. page.texture.setFilters(page.minFilter, page.magFilter);
  6000. page.texture.setWraps(page.uWrap, page.vWrap);
  6001. page.width = page.texture.getImage().width;
  6002. page.height = page.texture.getImage().height;
  6003. this.pages.push(page);
  6004. }
  6005. else {
  6006. var region = new TextureAtlasRegion();
  6007. region.name = line;
  6008. region.page = page;
  6009. region.rotate = reader.readValue() == "true";
  6010. reader.readTuple(tuple);
  6011. var x = parseInt(tuple[0]);
  6012. var y = parseInt(tuple[1]);
  6013. reader.readTuple(tuple);
  6014. var width = parseInt(tuple[0]);
  6015. var height = parseInt(tuple[1]);
  6016. region.u = x / page.width;
  6017. region.v = y / page.height;
  6018. if (region.rotate) {
  6019. region.u2 = (x + height) / page.width;
  6020. region.v2 = (y + width) / page.height;
  6021. }
  6022. else {
  6023. region.u2 = (x + width) / page.width;
  6024. region.v2 = (y + height) / page.height;
  6025. }
  6026. region.x = x;
  6027. region.y = y;
  6028. region.width = Math.abs(width);
  6029. region.height = Math.abs(height);
  6030. if (reader.readTuple(tuple) == 4) {
  6031. if (reader.readTuple(tuple) == 4) {
  6032. reader.readTuple(tuple);
  6033. }
  6034. }
  6035. region.originalWidth = parseInt(tuple[0]);
  6036. region.originalHeight = parseInt(tuple[1]);
  6037. reader.readTuple(tuple);
  6038. region.offsetX = parseInt(tuple[0]);
  6039. region.offsetY = parseInt(tuple[1]);
  6040. region.index = parseInt(reader.readValue());
  6041. region.texture = page.texture;
  6042. this.regions.push(region);
  6043. }
  6044. }
  6045. };
  6046. TextureAtlas.prototype.findRegion = function (name) {
  6047. for (var i = 0; i < this.regions.length; i++) {
  6048. if (this.regions[i].name == name) {
  6049. return this.regions[i];
  6050. }
  6051. }
  6052. return null;
  6053. };
  6054. TextureAtlas.prototype.dispose = function () {
  6055. for (var i = 0; i < this.pages.length; i++) {
  6056. this.pages[i].texture.dispose();
  6057. }
  6058. };
  6059. return TextureAtlas;
  6060. }());
  6061. spine.TextureAtlas = TextureAtlas;
  6062. var TextureAtlasReader = (function () {
  6063. function TextureAtlasReader(text) {
  6064. this.index = 0;
  6065. this.lines = text.split(/\r\n|\r|\n/);
  6066. }
  6067. TextureAtlasReader.prototype.readLine = function () {
  6068. if (this.index >= this.lines.length)
  6069. return null;
  6070. return this.lines[this.index++];
  6071. };
  6072. TextureAtlasReader.prototype.readValue = function () {
  6073. var line = this.readLine();
  6074. var colon = line.indexOf(":");
  6075. if (colon == -1)
  6076. throw new Error("Invalid line: " + line);
  6077. return line.substring(colon + 1).trim();
  6078. };
  6079. TextureAtlasReader.prototype.readTuple = function (tuple) {
  6080. var line = this.readLine();
  6081. var colon = line.indexOf(":");
  6082. if (colon == -1)
  6083. throw new Error("Invalid line: " + line);
  6084. var i = 0, lastMatch = colon + 1;
  6085. for (; i < 3; i++) {
  6086. var comma = line.indexOf(",", lastMatch);
  6087. if (comma == -1)
  6088. break;
  6089. tuple[i] = line.substr(lastMatch, comma - lastMatch).trim();
  6090. lastMatch = comma + 1;
  6091. }
  6092. tuple[i] = line.substring(lastMatch).trim();
  6093. return i + 1;
  6094. };
  6095. return TextureAtlasReader;
  6096. }());
  6097. var TextureAtlasPage = (function () {
  6098. function TextureAtlasPage() {
  6099. }
  6100. return TextureAtlasPage;
  6101. }());
  6102. spine.TextureAtlasPage = TextureAtlasPage;
  6103. var TextureAtlasRegion = (function (_super) {
  6104. __extends(TextureAtlasRegion, _super);
  6105. function TextureAtlasRegion() {
  6106. return _super !== null && _super.apply(this, arguments) || this;
  6107. }
  6108. return TextureAtlasRegion;
  6109. }(spine.TextureRegion));
  6110. spine.TextureAtlasRegion = TextureAtlasRegion;
  6111. })(spine || (spine = {}));
  6112. var spine;
  6113. (function (spine) {
  6114. var TransformConstraint = (function () {
  6115. function TransformConstraint(data, skeleton) {
  6116. this.rotateMix = 0;
  6117. this.translateMix = 0;
  6118. this.scaleMix = 0;
  6119. this.shearMix = 0;
  6120. this.temp = new spine.Vector2();
  6121. if (data == null)
  6122. throw new Error("data cannot be null.");
  6123. if (skeleton == null)
  6124. throw new Error("skeleton cannot be null.");
  6125. this.data = data;
  6126. this.rotateMix = data.rotateMix;
  6127. this.translateMix = data.translateMix;
  6128. this.scaleMix = data.scaleMix;
  6129. this.shearMix = data.shearMix;
  6130. this.bones = new Array();
  6131. for (var i = 0; i < data.bones.length; i++)
  6132. this.bones.push(skeleton.findBone(data.bones[i].name));
  6133. this.target = skeleton.findBone(data.target.name);
  6134. }
  6135. TransformConstraint.prototype.apply = function () {
  6136. this.update();
  6137. };
  6138. TransformConstraint.prototype.update = function () {
  6139. if (this.data.local) {
  6140. if (this.data.relative)
  6141. this.applyRelativeLocal();
  6142. else
  6143. this.applyAbsoluteLocal();
  6144. }
  6145. else {
  6146. if (this.data.relative)
  6147. this.applyRelativeWorld();
  6148. else
  6149. this.applyAbsoluteWorld();
  6150. }
  6151. };
  6152. TransformConstraint.prototype.applyAbsoluteWorld = function () {
  6153. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6154. var target = this.target;
  6155. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  6156. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  6157. var offsetRotation = this.data.offsetRotation * degRadReflect;
  6158. var offsetShearY = this.data.offsetShearY * degRadReflect;
  6159. var bones = this.bones;
  6160. for (var i = 0, n = bones.length; i < n; i++) {
  6161. var bone = bones[i];
  6162. var modified = false;
  6163. if (rotateMix != 0) {
  6164. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6165. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  6166. if (r > spine.MathUtils.PI)
  6167. r -= spine.MathUtils.PI2;
  6168. else if (r < -spine.MathUtils.PI)
  6169. r += spine.MathUtils.PI2;
  6170. r *= rotateMix;
  6171. var cos = Math.cos(r), sin = Math.sin(r);
  6172. bone.a = cos * a - sin * c;
  6173. bone.b = cos * b - sin * d;
  6174. bone.c = sin * a + cos * c;
  6175. bone.d = sin * b + cos * d;
  6176. modified = true;
  6177. }
  6178. if (translateMix != 0) {
  6179. var temp = this.temp;
  6180. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  6181. bone.worldX += (temp.x - bone.worldX) * translateMix;
  6182. bone.worldY += (temp.y - bone.worldY) * translateMix;
  6183. modified = true;
  6184. }
  6185. if (scaleMix > 0) {
  6186. var s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
  6187. var ts = Math.sqrt(ta * ta + tc * tc);
  6188. if (s > 0.00001)
  6189. s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
  6190. bone.a *= s;
  6191. bone.c *= s;
  6192. s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
  6193. ts = Math.sqrt(tb * tb + td * td);
  6194. if (s > 0.00001)
  6195. s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
  6196. bone.b *= s;
  6197. bone.d *= s;
  6198. modified = true;
  6199. }
  6200. if (shearMix > 0) {
  6201. var b = bone.b, d = bone.d;
  6202. var by = Math.atan2(d, b);
  6203. var r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
  6204. if (r > spine.MathUtils.PI)
  6205. r -= spine.MathUtils.PI2;
  6206. else if (r < -spine.MathUtils.PI)
  6207. r += spine.MathUtils.PI2;
  6208. r = by + (r + offsetShearY) * shearMix;
  6209. var s = Math.sqrt(b * b + d * d);
  6210. bone.b = Math.cos(r) * s;
  6211. bone.d = Math.sin(r) * s;
  6212. modified = true;
  6213. }
  6214. if (modified)
  6215. bone.appliedValid = false;
  6216. }
  6217. };
  6218. TransformConstraint.prototype.applyRelativeWorld = function () {
  6219. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6220. var target = this.target;
  6221. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  6222. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  6223. var offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  6224. var bones = this.bones;
  6225. for (var i = 0, n = bones.length; i < n; i++) {
  6226. var bone = bones[i];
  6227. var modified = false;
  6228. if (rotateMix != 0) {
  6229. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6230. var r = Math.atan2(tc, ta) + offsetRotation;
  6231. if (r > spine.MathUtils.PI)
  6232. r -= spine.MathUtils.PI2;
  6233. else if (r < -spine.MathUtils.PI)
  6234. r += spine.MathUtils.PI2;
  6235. r *= rotateMix;
  6236. var cos = Math.cos(r), sin = Math.sin(r);
  6237. bone.a = cos * a - sin * c;
  6238. bone.b = cos * b - sin * d;
  6239. bone.c = sin * a + cos * c;
  6240. bone.d = sin * b + cos * d;
  6241. modified = true;
  6242. }
  6243. if (translateMix != 0) {
  6244. var temp = this.temp;
  6245. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  6246. bone.worldX += temp.x * translateMix;
  6247. bone.worldY += temp.y * translateMix;
  6248. modified = true;
  6249. }
  6250. if (scaleMix > 0) {
  6251. var s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
  6252. bone.a *= s;
  6253. bone.c *= s;
  6254. s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
  6255. bone.b *= s;
  6256. bone.d *= s;
  6257. modified = true;
  6258. }
  6259. if (shearMix > 0) {
  6260. var r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  6261. if (r > spine.MathUtils.PI)
  6262. r -= spine.MathUtils.PI2;
  6263. else if (r < -spine.MathUtils.PI)
  6264. r += spine.MathUtils.PI2;
  6265. var b = bone.b, d = bone.d;
  6266. r = Math.atan2(d, b) + (r - spine.MathUtils.PI / 2 + offsetShearY) * shearMix;
  6267. var s = Math.sqrt(b * b + d * d);
  6268. bone.b = Math.cos(r) * s;
  6269. bone.d = Math.sin(r) * s;
  6270. modified = true;
  6271. }
  6272. if (modified)
  6273. bone.appliedValid = false;
  6274. }
  6275. };
  6276. TransformConstraint.prototype.applyAbsoluteLocal = function () {
  6277. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6278. var target = this.target;
  6279. if (!target.appliedValid)
  6280. target.updateAppliedTransform();
  6281. var bones = this.bones;
  6282. for (var i = 0, n = bones.length; i < n; i++) {
  6283. var bone = bones[i];
  6284. if (!bone.appliedValid)
  6285. bone.updateAppliedTransform();
  6286. var rotation = bone.arotation;
  6287. if (rotateMix != 0) {
  6288. var r = target.arotation - rotation + this.data.offsetRotation;
  6289. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  6290. rotation += r * rotateMix;
  6291. }
  6292. var x = bone.ax, y = bone.ay;
  6293. if (translateMix != 0) {
  6294. x += (target.ax - x + this.data.offsetX) * translateMix;
  6295. y += (target.ay - y + this.data.offsetY) * translateMix;
  6296. }
  6297. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  6298. if (scaleMix > 0) {
  6299. if (scaleX > 0.00001)
  6300. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
  6301. if (scaleY > 0.00001)
  6302. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
  6303. }
  6304. var shearY = bone.ashearY;
  6305. if (shearMix > 0) {
  6306. var r = target.ashearY - shearY + this.data.offsetShearY;
  6307. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  6308. bone.shearY += r * shearMix;
  6309. }
  6310. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  6311. }
  6312. };
  6313. TransformConstraint.prototype.applyRelativeLocal = function () {
  6314. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6315. var target = this.target;
  6316. if (!target.appliedValid)
  6317. target.updateAppliedTransform();
  6318. var bones = this.bones;
  6319. for (var i = 0, n = bones.length; i < n; i++) {
  6320. var bone = bones[i];
  6321. if (!bone.appliedValid)
  6322. bone.updateAppliedTransform();
  6323. var rotation = bone.arotation;
  6324. if (rotateMix != 0)
  6325. rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
  6326. var x = bone.ax, y = bone.ay;
  6327. if (translateMix != 0) {
  6328. x += (target.ax + this.data.offsetX) * translateMix;
  6329. y += (target.ay + this.data.offsetY) * translateMix;
  6330. }
  6331. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  6332. if (scaleMix > 0) {
  6333. if (scaleX > 0.00001)
  6334. scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
  6335. if (scaleY > 0.00001)
  6336. scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
  6337. }
  6338. var shearY = bone.ashearY;
  6339. if (shearMix > 0)
  6340. shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
  6341. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  6342. }
  6343. };
  6344. TransformConstraint.prototype.getOrder = function () {
  6345. return this.data.order;
  6346. };
  6347. return TransformConstraint;
  6348. }());
  6349. spine.TransformConstraint = TransformConstraint;
  6350. })(spine || (spine = {}));
  6351. var spine;
  6352. (function (spine) {
  6353. var TransformConstraintData = (function () {
  6354. function TransformConstraintData(name) {
  6355. this.order = 0;
  6356. this.bones = new Array();
  6357. this.rotateMix = 0;
  6358. this.translateMix = 0;
  6359. this.scaleMix = 0;
  6360. this.shearMix = 0;
  6361. this.offsetRotation = 0;
  6362. this.offsetX = 0;
  6363. this.offsetY = 0;
  6364. this.offsetScaleX = 0;
  6365. this.offsetScaleY = 0;
  6366. this.offsetShearY = 0;
  6367. this.relative = false;
  6368. this.local = false;
  6369. if (name == null)
  6370. throw new Error("name cannot be null.");
  6371. this.name = name;
  6372. }
  6373. return TransformConstraintData;
  6374. }());
  6375. spine.TransformConstraintData = TransformConstraintData;
  6376. })(spine || (spine = {}));
  6377. var spine;
  6378. (function (spine) {
  6379. var Triangulator = (function () {
  6380. function Triangulator() {
  6381. this.convexPolygons = new Array();
  6382. this.convexPolygonsIndices = new Array();
  6383. this.indicesArray = new Array();
  6384. this.isConcaveArray = new Array();
  6385. this.triangles = new Array();
  6386. this.polygonPool = new spine.Pool(function () {
  6387. return new Array();
  6388. });
  6389. this.polygonIndicesPool = new spine.Pool(function () {
  6390. return new Array();
  6391. });
  6392. }
  6393. Triangulator.prototype.triangulate = function (verticesArray) {
  6394. var vertices = verticesArray;
  6395. var vertexCount = verticesArray.length >> 1;
  6396. var indices = this.indicesArray;
  6397. indices.length = 0;
  6398. for (var i = 0; i < vertexCount; i++)
  6399. indices[i] = i;
  6400. var isConcave = this.isConcaveArray;
  6401. isConcave.length = 0;
  6402. for (var i = 0, n = vertexCount; i < n; ++i)
  6403. isConcave[i] = Triangulator.isConcave(i, vertexCount, vertices, indices);
  6404. var triangles = this.triangles;
  6405. triangles.length = 0;
  6406. while (vertexCount > 3) {
  6407. var previous = vertexCount - 1, i = 0, next = 1;
  6408. while (true) {
  6409. outer: if (!isConcave[i]) {
  6410. var p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1;
  6411. var p1x = vertices[p1], p1y = vertices[p1 + 1];
  6412. var p2x = vertices[p2], p2y = vertices[p2 + 1];
  6413. var p3x = vertices[p3], p3y = vertices[p3 + 1];
  6414. for (var ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
  6415. if (!isConcave[ii])
  6416. continue;
  6417. var v = indices[ii] << 1;
  6418. var vx = vertices[v], vy = vertices[v + 1];
  6419. if (Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
  6420. if (Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
  6421. if (Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy))
  6422. break outer;
  6423. }
  6424. }
  6425. }
  6426. break;
  6427. }
  6428. if (next == 0) {
  6429. do {
  6430. if (!isConcave[i])
  6431. break;
  6432. i--;
  6433. } while (i > 0);
  6434. break;
  6435. }
  6436. previous = i;
  6437. i = next;
  6438. next = (next + 1) % vertexCount;
  6439. }
  6440. triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
  6441. triangles.push(indices[i]);
  6442. triangles.push(indices[(i + 1) % vertexCount]);
  6443. indices.splice(i, 1);
  6444. isConcave.splice(i, 1);
  6445. vertexCount--;
  6446. var previousIndex = (vertexCount + i - 1) % vertexCount;
  6447. var nextIndex = i == vertexCount ? 0 : i;
  6448. isConcave[previousIndex] = Triangulator.isConcave(previousIndex, vertexCount, vertices, indices);
  6449. isConcave[nextIndex] = Triangulator.isConcave(nextIndex, vertexCount, vertices, indices);
  6450. }
  6451. if (vertexCount == 3) {
  6452. triangles.push(indices[2]);
  6453. triangles.push(indices[0]);
  6454. triangles.push(indices[1]);
  6455. }
  6456. return triangles;
  6457. };
  6458. Triangulator.prototype.decompose = function (verticesArray, triangles) {
  6459. var vertices = verticesArray;
  6460. var convexPolygons = this.convexPolygons;
  6461. this.polygonPool.freeAll(convexPolygons);
  6462. convexPolygons.length = 0;
  6463. var convexPolygonsIndices = this.convexPolygonsIndices;
  6464. this.polygonIndicesPool.freeAll(convexPolygonsIndices);
  6465. convexPolygonsIndices.length = 0;
  6466. var polygonIndices = this.polygonIndicesPool.obtain();
  6467. polygonIndices.length = 0;
  6468. var polygon = this.polygonPool.obtain();
  6469. polygon.length = 0;
  6470. var fanBaseIndex = -1, lastWinding = 0;
  6471. for (var i = 0, n = triangles.length; i < n; i += 3) {
  6472. var t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1;
  6473. var x1 = vertices[t1], y1 = vertices[t1 + 1];
  6474. var x2 = vertices[t2], y2 = vertices[t2 + 1];
  6475. var x3 = vertices[t3], y3 = vertices[t3 + 1];
  6476. var merged = false;
  6477. if (fanBaseIndex == t1) {
  6478. var o = polygon.length - 4;
  6479. var winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
  6480. var winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
  6481. if (winding1 == lastWinding && winding2 == lastWinding) {
  6482. polygon.push(x3);
  6483. polygon.push(y3);
  6484. polygonIndices.push(t3);
  6485. merged = true;
  6486. }
  6487. }
  6488. if (!merged) {
  6489. if (polygon.length > 0) {
  6490. convexPolygons.push(polygon);
  6491. convexPolygonsIndices.push(polygonIndices);
  6492. }
  6493. else {
  6494. this.polygonPool.free(polygon);
  6495. this.polygonIndicesPool.free(polygonIndices);
  6496. }
  6497. polygon = this.polygonPool.obtain();
  6498. polygon.length = 0;
  6499. polygon.push(x1);
  6500. polygon.push(y1);
  6501. polygon.push(x2);
  6502. polygon.push(y2);
  6503. polygon.push(x3);
  6504. polygon.push(y3);
  6505. polygonIndices = this.polygonIndicesPool.obtain();
  6506. polygonIndices.length = 0;
  6507. polygonIndices.push(t1);
  6508. polygonIndices.push(t2);
  6509. polygonIndices.push(t3);
  6510. lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
  6511. fanBaseIndex = t1;
  6512. }
  6513. }
  6514. if (polygon.length > 0) {
  6515. convexPolygons.push(polygon);
  6516. convexPolygonsIndices.push(polygonIndices);
  6517. }
  6518. for (var i = 0, n = convexPolygons.length; i < n; i++) {
  6519. polygonIndices = convexPolygonsIndices[i];
  6520. if (polygonIndices.length == 0)
  6521. continue;
  6522. var firstIndex = polygonIndices[0];
  6523. var lastIndex = polygonIndices[polygonIndices.length - 1];
  6524. polygon = convexPolygons[i];
  6525. var o = polygon.length - 4;
  6526. var prevPrevX = polygon[o], prevPrevY = polygon[o + 1];
  6527. var prevX = polygon[o + 2], prevY = polygon[o + 3];
  6528. var firstX = polygon[0], firstY = polygon[1];
  6529. var secondX = polygon[2], secondY = polygon[3];
  6530. var winding = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
  6531. for (var ii = 0; ii < n; ii++) {
  6532. if (ii == i)
  6533. continue;
  6534. var otherIndices = convexPolygonsIndices[ii];
  6535. if (otherIndices.length != 3)
  6536. continue;
  6537. var otherFirstIndex = otherIndices[0];
  6538. var otherSecondIndex = otherIndices[1];
  6539. var otherLastIndex = otherIndices[2];
  6540. var otherPoly = convexPolygons[ii];
  6541. var x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1];
  6542. if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex)
  6543. continue;
  6544. var winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
  6545. var winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
  6546. if (winding1 == winding && winding2 == winding) {
  6547. otherPoly.length = 0;
  6548. otherIndices.length = 0;
  6549. polygon.push(x3);
  6550. polygon.push(y3);
  6551. polygonIndices.push(otherLastIndex);
  6552. prevPrevX = prevX;
  6553. prevPrevY = prevY;
  6554. prevX = x3;
  6555. prevY = y3;
  6556. ii = 0;
  6557. }
  6558. }
  6559. }
  6560. for (var i = convexPolygons.length - 1; i >= 0; i--) {
  6561. polygon = convexPolygons[i];
  6562. if (polygon.length == 0) {
  6563. convexPolygons.splice(i, 1);
  6564. this.polygonPool.free(polygon);
  6565. polygonIndices = convexPolygonsIndices[i];
  6566. convexPolygonsIndices.splice(i, 1);
  6567. this.polygonIndicesPool.free(polygonIndices);
  6568. }
  6569. }
  6570. return convexPolygons;
  6571. };
  6572. Triangulator.isConcave = function (index, vertexCount, vertices, indices) {
  6573. var previous = indices[(vertexCount + index - 1) % vertexCount] << 1;
  6574. var current = indices[index] << 1;
  6575. var next = indices[(index + 1) % vertexCount] << 1;
  6576. return !this.positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]);
  6577. };
  6578. Triangulator.positiveArea = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  6579. return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
  6580. };
  6581. Triangulator.winding = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  6582. var px = p2x - p1x, py = p2y - p1y;
  6583. return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
  6584. };
  6585. return Triangulator;
  6586. }());
  6587. spine.Triangulator = Triangulator;
  6588. })(spine || (spine = {}));
  6589. var spine;
  6590. (function (spine) {
  6591. var IntSet = (function () {
  6592. function IntSet() {
  6593. this.array = new Array();
  6594. }
  6595. IntSet.prototype.add = function (value) {
  6596. var contains = this.contains(value);
  6597. this.array[value | 0] = value | 0;
  6598. return !contains;
  6599. };
  6600. IntSet.prototype.contains = function (value) {
  6601. return this.array[value | 0] != undefined;
  6602. };
  6603. IntSet.prototype.remove = function (value) {
  6604. this.array[value | 0] = undefined;
  6605. };
  6606. IntSet.prototype.clear = function () {
  6607. this.array.length = 0;
  6608. };
  6609. return IntSet;
  6610. }());
  6611. spine.IntSet = IntSet;
  6612. var Color = (function () {
  6613. function Color(r, g, b, a) {
  6614. if (r === void 0) { r = 0; }
  6615. if (g === void 0) { g = 0; }
  6616. if (b === void 0) { b = 0; }
  6617. if (a === void 0) { a = 0; }
  6618. this.r = r;
  6619. this.g = g;
  6620. this.b = b;
  6621. this.a = a;
  6622. }
  6623. Color.prototype.set = function (r, g, b, a) {
  6624. this.r = r;
  6625. this.g = g;
  6626. this.b = b;
  6627. this.a = a;
  6628. this.clamp();
  6629. return this;
  6630. };
  6631. Color.prototype.setFromColor = function (c) {
  6632. this.r = c.r;
  6633. this.g = c.g;
  6634. this.b = c.b;
  6635. this.a = c.a;
  6636. return this;
  6637. };
  6638. Color.prototype.setFromString = function (hex) {
  6639. hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
  6640. this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
  6641. this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
  6642. this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
  6643. this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
  6644. return this;
  6645. };
  6646. Color.prototype.add = function (r, g, b, a) {
  6647. this.r += r;
  6648. this.g += g;
  6649. this.b += b;
  6650. this.a += a;
  6651. this.clamp();
  6652. return this;
  6653. };
  6654. Color.prototype.clamp = function () {
  6655. if (this.r < 0)
  6656. this.r = 0;
  6657. else if (this.r > 1)
  6658. this.r = 1;
  6659. if (this.g < 0)
  6660. this.g = 0;
  6661. else if (this.g > 1)
  6662. this.g = 1;
  6663. if (this.b < 0)
  6664. this.b = 0;
  6665. else if (this.b > 1)
  6666. this.b = 1;
  6667. if (this.a < 0)
  6668. this.a = 0;
  6669. else if (this.a > 1)
  6670. this.a = 1;
  6671. return this;
  6672. };
  6673. Color.WHITE = new Color(1, 1, 1, 1);
  6674. Color.RED = new Color(1, 0, 0, 1);
  6675. Color.GREEN = new Color(0, 1, 0, 1);
  6676. Color.BLUE = new Color(0, 0, 1, 1);
  6677. Color.MAGENTA = new Color(1, 0, 1, 1);
  6678. return Color;
  6679. }());
  6680. spine.Color = Color;
  6681. var MathUtils = (function () {
  6682. function MathUtils() {
  6683. }
  6684. MathUtils.clamp = function (value, min, max) {
  6685. if (value < min)
  6686. return min;
  6687. if (value > max)
  6688. return max;
  6689. return value;
  6690. };
  6691. MathUtils.cosDeg = function (degrees) {
  6692. return Math.cos(degrees * MathUtils.degRad);
  6693. };
  6694. MathUtils.sinDeg = function (degrees) {
  6695. return Math.sin(degrees * MathUtils.degRad);
  6696. };
  6697. MathUtils.signum = function (value) {
  6698. return value > 0 ? 1 : value < 0 ? -1 : 0;
  6699. };
  6700. MathUtils.toInt = function (x) {
  6701. return x > 0 ? Math.floor(x) : Math.ceil(x);
  6702. };
  6703. MathUtils.cbrt = function (x) {
  6704. var y = Math.pow(Math.abs(x), 1 / 3);
  6705. return x < 0 ? -y : y;
  6706. };
  6707. MathUtils.randomTriangular = function (min, max) {
  6708. return MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
  6709. };
  6710. MathUtils.randomTriangularWith = function (min, max, mode) {
  6711. var u = Math.random();
  6712. var d = max - min;
  6713. if (u <= (mode - min) / d)
  6714. return min + Math.sqrt(u * d * (mode - min));
  6715. return max - Math.sqrt((1 - u) * d * (max - mode));
  6716. };
  6717. MathUtils.PI = 3.1415927;
  6718. MathUtils.PI2 = MathUtils.PI * 2;
  6719. MathUtils.radiansToDegrees = 180 / MathUtils.PI;
  6720. MathUtils.radDeg = MathUtils.radiansToDegrees;
  6721. MathUtils.degreesToRadians = MathUtils.PI / 180;
  6722. MathUtils.degRad = MathUtils.degreesToRadians;
  6723. return MathUtils;
  6724. }());
  6725. spine.MathUtils = MathUtils;
  6726. var Interpolation = (function () {
  6727. function Interpolation() {
  6728. }
  6729. Interpolation.prototype.apply = function (start, end, a) {
  6730. return start + (end - start) * this.applyInternal(a);
  6731. };
  6732. return Interpolation;
  6733. }());
  6734. spine.Interpolation = Interpolation;
  6735. var Pow = (function (_super) {
  6736. __extends(Pow, _super);
  6737. function Pow(power) {
  6738. var _this = _super.call(this) || this;
  6739. _this.power = 2;
  6740. _this.power = power;
  6741. return _this;
  6742. }
  6743. Pow.prototype.applyInternal = function (a) {
  6744. if (a <= 0.5)
  6745. return Math.pow(a * 2, this.power) / 2;
  6746. return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
  6747. };
  6748. return Pow;
  6749. }(Interpolation));
  6750. spine.Pow = Pow;
  6751. var PowOut = (function (_super) {
  6752. __extends(PowOut, _super);
  6753. function PowOut(power) {
  6754. return _super.call(this, power) || this;
  6755. }
  6756. PowOut.prototype.applyInternal = function (a) {
  6757. return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
  6758. };
  6759. return PowOut;
  6760. }(Pow));
  6761. spine.PowOut = PowOut;
  6762. var Utils = (function () {
  6763. function Utils() {
  6764. }
  6765. Utils.arrayCopy = function (source, sourceStart, dest, destStart, numElements) {
  6766. for (var i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  6767. dest[j] = source[i];
  6768. }
  6769. };
  6770. Utils.setArraySize = function (array, size, value) {
  6771. if (value === void 0) { value = 0; }
  6772. var oldSize = array.length;
  6773. if (oldSize == size)
  6774. return array;
  6775. array.length = size;
  6776. if (oldSize < size) {
  6777. for (var i = oldSize; i < size; i++)
  6778. array[i] = value;
  6779. }
  6780. return array;
  6781. };
  6782. Utils.ensureArrayCapacity = function (array, size, value) {
  6783. if (value === void 0) { value = 0; }
  6784. if (array.length >= size)
  6785. return array;
  6786. return Utils.setArraySize(array, size, value);
  6787. };
  6788. Utils.newArray = function (size, defaultValue) {
  6789. var array = new Array(size);
  6790. for (var i = 0; i < size; i++)
  6791. array[i] = defaultValue;
  6792. return array;
  6793. };
  6794. Utils.newFloatArray = function (size) {
  6795. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  6796. return new Float32Array(size);
  6797. }
  6798. else {
  6799. var array = new Array(size);
  6800. for (var i = 0; i < array.length; i++)
  6801. array[i] = 0;
  6802. return array;
  6803. }
  6804. };
  6805. Utils.newShortArray = function (size) {
  6806. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  6807. return new Int16Array(size);
  6808. }
  6809. else {
  6810. var array = new Array(size);
  6811. for (var i = 0; i < array.length; i++)
  6812. array[i] = 0;
  6813. return array;
  6814. }
  6815. };
  6816. Utils.toFloatArray = function (array) {
  6817. return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  6818. };
  6819. Utils.toSinglePrecision = function (value) {
  6820. return Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
  6821. };
  6822. Utils.webkit602BugfixHelper = function (alpha, pose) {
  6823. };
  6824. Utils.SUPPORTS_TYPED_ARRAYS = typeof (Float32Array) !== "undefined";
  6825. return Utils;
  6826. }());
  6827. spine.Utils = Utils;
  6828. var DebugUtils = (function () {
  6829. function DebugUtils() {
  6830. }
  6831. DebugUtils.logBones = function (skeleton) {
  6832. for (var i = 0; i < skeleton.bones.length; i++) {
  6833. var bone = skeleton.bones[i];
  6834. console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
  6835. }
  6836. };
  6837. return DebugUtils;
  6838. }());
  6839. spine.DebugUtils = DebugUtils;
  6840. var Pool = (function () {
  6841. function Pool(instantiator) {
  6842. this.items = new Array();
  6843. this.instantiator = instantiator;
  6844. }
  6845. Pool.prototype.obtain = function () {
  6846. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  6847. };
  6848. Pool.prototype.free = function (item) {
  6849. if (item.reset)
  6850. item.reset();
  6851. this.items.push(item);
  6852. };
  6853. Pool.prototype.freeAll = function (items) {
  6854. for (var i = 0; i < items.length; i++) {
  6855. if (items[i].reset)
  6856. items[i].reset();
  6857. this.items[i] = items[i];
  6858. }
  6859. };
  6860. Pool.prototype.clear = function () {
  6861. this.items.length = 0;
  6862. };
  6863. return Pool;
  6864. }());
  6865. spine.Pool = Pool;
  6866. var Vector2 = (function () {
  6867. function Vector2(x, y) {
  6868. if (x === void 0) { x = 0; }
  6869. if (y === void 0) { y = 0; }
  6870. this.x = x;
  6871. this.y = y;
  6872. }
  6873. Vector2.prototype.set = function (x, y) {
  6874. this.x = x;
  6875. this.y = y;
  6876. return this;
  6877. };
  6878. Vector2.prototype.length = function () {
  6879. var x = this.x;
  6880. var y = this.y;
  6881. return Math.sqrt(x * x + y * y);
  6882. };
  6883. Vector2.prototype.normalize = function () {
  6884. var len = this.length();
  6885. if (len != 0) {
  6886. this.x /= len;
  6887. this.y /= len;
  6888. }
  6889. return this;
  6890. };
  6891. return Vector2;
  6892. }());
  6893. spine.Vector2 = Vector2;
  6894. var TimeKeeper = (function () {
  6895. function TimeKeeper() {
  6896. this.maxDelta = 0.064;
  6897. this.framesPerSecond = 0;
  6898. this.delta = 0;
  6899. this.totalTime = 0;
  6900. this.lastTime = Date.now() / 1000;
  6901. this.frameCount = 0;
  6902. this.frameTime = 0;
  6903. }
  6904. TimeKeeper.prototype.update = function () {
  6905. var now = Date.now() / 1000;
  6906. this.delta = now - this.lastTime;
  6907. this.frameTime += this.delta;
  6908. this.totalTime += this.delta;
  6909. if (this.delta > this.maxDelta)
  6910. this.delta = this.maxDelta;
  6911. this.lastTime = now;
  6912. this.frameCount++;
  6913. if (this.frameTime > 1) {
  6914. this.framesPerSecond = this.frameCount / this.frameTime;
  6915. this.frameTime = 0;
  6916. this.frameCount = 0;
  6917. }
  6918. };
  6919. return TimeKeeper;
  6920. }());
  6921. spine.TimeKeeper = TimeKeeper;
  6922. var WindowedMean = (function () {
  6923. function WindowedMean(windowSize) {
  6924. if (windowSize === void 0) { windowSize = 32; }
  6925. this.addedValues = 0;
  6926. this.lastValue = 0;
  6927. this.mean = 0;
  6928. this.dirty = true;
  6929. this.values = new Array(windowSize);
  6930. }
  6931. WindowedMean.prototype.hasEnoughData = function () {
  6932. return this.addedValues >= this.values.length;
  6933. };
  6934. WindowedMean.prototype.addValue = function (value) {
  6935. if (this.addedValues < this.values.length)
  6936. this.addedValues++;
  6937. this.values[this.lastValue++] = value;
  6938. if (this.lastValue > this.values.length - 1)
  6939. this.lastValue = 0;
  6940. this.dirty = true;
  6941. };
  6942. WindowedMean.prototype.getMean = function () {
  6943. if (this.hasEnoughData()) {
  6944. if (this.dirty) {
  6945. var mean = 0;
  6946. for (var i = 0; i < this.values.length; i++) {
  6947. mean += this.values[i];
  6948. }
  6949. this.mean = mean / this.values.length;
  6950. this.dirty = false;
  6951. }
  6952. return this.mean;
  6953. }
  6954. else {
  6955. return 0;
  6956. }
  6957. };
  6958. return WindowedMean;
  6959. }());
  6960. spine.WindowedMean = WindowedMean;
  6961. })(spine || (spine = {}));
  6962. (function () {
  6963. if (!Math.fround) {
  6964. Math.fround = (function (array) {
  6965. return function (x) {
  6966. return array[0] = x, array[0];
  6967. };
  6968. })(new Float32Array(1));
  6969. }
  6970. })();
  6971. var spine;
  6972. (function (spine) {
  6973. var Attachment = (function () {
  6974. function Attachment(name) {
  6975. if (name == null)
  6976. throw new Error("name cannot be null.");
  6977. this.name = name;
  6978. }
  6979. return Attachment;
  6980. }());
  6981. spine.Attachment = Attachment;
  6982. var VertexAttachment = (function (_super) {
  6983. __extends(VertexAttachment, _super);
  6984. function VertexAttachment(name) {
  6985. var _this = _super.call(this, name) || this;
  6986. _this.id = (VertexAttachment.nextID++ & 65535) << 11;
  6987. _this.worldVerticesLength = 0;
  6988. return _this;
  6989. }
  6990. VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
  6991. count = offset + (count >> 1) * stride;
  6992. var skeleton = slot.bone.skeleton;
  6993. var deformArray = slot.attachmentVertices;
  6994. var vertices = this.vertices;
  6995. var bones = this.bones;
  6996. if (bones == null) {
  6997. if (deformArray.length > 0)
  6998. vertices = deformArray;
  6999. var bone = slot.bone;
  7000. var x = bone.worldX;
  7001. var y = bone.worldY;
  7002. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  7003. for (var v_1 = start, w = offset; w < count; v_1 += 2, w += stride) {
  7004. var vx = vertices[v_1], vy = vertices[v_1 + 1];
  7005. worldVertices[w] = vx * a + vy * b + x;
  7006. worldVertices[w + 1] = vx * c + vy * d + y;
  7007. }
  7008. return;
  7009. }
  7010. var v = 0, skip = 0;
  7011. for (var i = 0; i < start; i += 2) {
  7012. var n = bones[v];
  7013. v += n + 1;
  7014. skip += n;
  7015. }
  7016. var skeletonBones = skeleton.bones;
  7017. if (deformArray.length == 0) {
  7018. for (var w = offset, b = skip * 3; w < count; w += stride) {
  7019. var wx = 0, wy = 0;
  7020. var n = bones[v++];
  7021. n += v;
  7022. for (; v < n; v++, b += 3) {
  7023. var bone = skeletonBones[bones[v]];
  7024. var vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  7025. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  7026. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  7027. }
  7028. worldVertices[w] = wx;
  7029. worldVertices[w + 1] = wy;
  7030. }
  7031. }
  7032. else {
  7033. var deform = deformArray;
  7034. for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  7035. var wx = 0, wy = 0;
  7036. var n = bones[v++];
  7037. n += v;
  7038. for (; v < n; v++, b += 3, f += 2) {
  7039. var bone = skeletonBones[bones[v]];
  7040. var vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  7041. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  7042. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  7043. }
  7044. worldVertices[w] = wx;
  7045. worldVertices[w + 1] = wy;
  7046. }
  7047. }
  7048. };
  7049. VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
  7050. return this == sourceAttachment;
  7051. };
  7052. VertexAttachment.nextID = 0;
  7053. return VertexAttachment;
  7054. }(Attachment));
  7055. spine.VertexAttachment = VertexAttachment;
  7056. })(spine || (spine = {}));
  7057. var spine;
  7058. (function (spine) {
  7059. var AttachmentType;
  7060. (function (AttachmentType) {
  7061. AttachmentType[AttachmentType["Region"] = 0] = "Region";
  7062. AttachmentType[AttachmentType["BoundingBox"] = 1] = "BoundingBox";
  7063. AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
  7064. AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
  7065. AttachmentType[AttachmentType["Path"] = 4] = "Path";
  7066. AttachmentType[AttachmentType["Point"] = 5] = "Point";
  7067. AttachmentType[AttachmentType["Clipping"] = 6] = "Clipping";
  7068. })(AttachmentType = spine.AttachmentType || (spine.AttachmentType = {}));
  7069. })(spine || (spine = {}));
  7070. var spine;
  7071. (function (spine) {
  7072. var BoundingBoxAttachment = (function (_super) {
  7073. __extends(BoundingBoxAttachment, _super);
  7074. function BoundingBoxAttachment(name) {
  7075. var _this = _super.call(this, name) || this;
  7076. _this.color = new spine.Color(1, 1, 1, 1);
  7077. return _this;
  7078. }
  7079. return BoundingBoxAttachment;
  7080. }(spine.VertexAttachment));
  7081. spine.BoundingBoxAttachment = BoundingBoxAttachment;
  7082. })(spine || (spine = {}));
  7083. var spine;
  7084. (function (spine) {
  7085. var ClippingAttachment = (function (_super) {
  7086. __extends(ClippingAttachment, _super);
  7087. function ClippingAttachment(name) {
  7088. var _this = _super.call(this, name) || this;
  7089. _this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1);
  7090. return _this;
  7091. }
  7092. return ClippingAttachment;
  7093. }(spine.VertexAttachment));
  7094. spine.ClippingAttachment = ClippingAttachment;
  7095. })(spine || (spine = {}));
  7096. var spine;
  7097. (function (spine) {
  7098. var MeshAttachment = (function (_super) {
  7099. __extends(MeshAttachment, _super);
  7100. function MeshAttachment(name) {
  7101. var _this = _super.call(this, name) || this;
  7102. _this.color = new spine.Color(1, 1, 1, 1);
  7103. _this.inheritDeform = false;
  7104. _this.tempColor = new spine.Color(0, 0, 0, 0);
  7105. return _this;
  7106. }
  7107. MeshAttachment.prototype.updateUVs = function () {
  7108. var u = 0, v = 0, width = 0, height = 0;
  7109. if (this.region == null) {
  7110. u = v = 0;
  7111. width = height = 1;
  7112. }
  7113. else {
  7114. u = this.region.u;
  7115. v = this.region.v;
  7116. width = this.region.u2 - u;
  7117. height = this.region.v2 - v;
  7118. }
  7119. var regionUVs = this.regionUVs;
  7120. if (this.uvs == null || this.uvs.length != regionUVs.length)
  7121. this.uvs = spine.Utils.newFloatArray(regionUVs.length);
  7122. var uvs = this.uvs;
  7123. if (this.region.rotate) {
  7124. for (var i = 0, n = uvs.length; i < n; i += 2) {
  7125. uvs[i] = u + regionUVs[i + 1] * width;
  7126. uvs[i + 1] = v + height - regionUVs[i] * height;
  7127. }
  7128. }
  7129. else {
  7130. for (var i = 0, n = uvs.length; i < n; i += 2) {
  7131. uvs[i] = u + regionUVs[i] * width;
  7132. uvs[i + 1] = v + regionUVs[i + 1] * height;
  7133. }
  7134. }
  7135. };
  7136. MeshAttachment.prototype.applyDeform = function (sourceAttachment) {
  7137. return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
  7138. };
  7139. MeshAttachment.prototype.getParentMesh = function () {
  7140. return this.parentMesh;
  7141. };
  7142. MeshAttachment.prototype.setParentMesh = function (parentMesh) {
  7143. this.parentMesh = parentMesh;
  7144. if (parentMesh != null) {
  7145. this.bones = parentMesh.bones;
  7146. this.vertices = parentMesh.vertices;
  7147. this.worldVerticesLength = parentMesh.worldVerticesLength;
  7148. this.regionUVs = parentMesh.regionUVs;
  7149. this.triangles = parentMesh.triangles;
  7150. this.hullLength = parentMesh.hullLength;
  7151. this.worldVerticesLength = parentMesh.worldVerticesLength;
  7152. }
  7153. };
  7154. return MeshAttachment;
  7155. }(spine.VertexAttachment));
  7156. spine.MeshAttachment = MeshAttachment;
  7157. })(spine || (spine = {}));
  7158. var spine;
  7159. (function (spine) {
  7160. var PathAttachment = (function (_super) {
  7161. __extends(PathAttachment, _super);
  7162. function PathAttachment(name) {
  7163. var _this = _super.call(this, name) || this;
  7164. _this.closed = false;
  7165. _this.constantSpeed = false;
  7166. _this.color = new spine.Color(1, 1, 1, 1);
  7167. return _this;
  7168. }
  7169. return PathAttachment;
  7170. }(spine.VertexAttachment));
  7171. spine.PathAttachment = PathAttachment;
  7172. })(spine || (spine = {}));
  7173. var spine;
  7174. (function (spine) {
  7175. var PointAttachment = (function (_super) {
  7176. __extends(PointAttachment, _super);
  7177. function PointAttachment(name) {
  7178. var _this = _super.call(this, name) || this;
  7179. _this.color = new spine.Color(0.38, 0.94, 0, 1);
  7180. return _this;
  7181. }
  7182. PointAttachment.prototype.computeWorldPosition = function (bone, point) {
  7183. point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
  7184. point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
  7185. return point;
  7186. };
  7187. PointAttachment.prototype.computeWorldRotation = function (bone) {
  7188. var cos = spine.MathUtils.cosDeg(this.rotation), sin = spine.MathUtils.sinDeg(this.rotation);
  7189. var x = cos * bone.a + sin * bone.b;
  7190. var y = cos * bone.c + sin * bone.d;
  7191. return Math.atan2(y, x) * spine.MathUtils.radDeg;
  7192. };
  7193. return PointAttachment;
  7194. }(spine.VertexAttachment));
  7195. spine.PointAttachment = PointAttachment;
  7196. })(spine || (spine = {}));
  7197. var spine;
  7198. (function (spine) {
  7199. var RegionAttachment = (function (_super) {
  7200. __extends(RegionAttachment, _super);
  7201. function RegionAttachment(name) {
  7202. var _this = _super.call(this, name) || this;
  7203. _this.x = 0;
  7204. _this.y = 0;
  7205. _this.scaleX = 1;
  7206. _this.scaleY = 1;
  7207. _this.rotation = 0;
  7208. _this.width = 0;
  7209. _this.height = 0;
  7210. _this.color = new spine.Color(1, 1, 1, 1);
  7211. _this.offset = spine.Utils.newFloatArray(8);
  7212. _this.uvs = spine.Utils.newFloatArray(8);
  7213. _this.tempColor = new spine.Color(1, 1, 1, 1);
  7214. return _this;
  7215. }
  7216. RegionAttachment.prototype.updateOffset = function () {
  7217. var regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  7218. var regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  7219. var localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  7220. var localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  7221. var localX2 = localX + this.region.width * regionScaleX;
  7222. var localY2 = localY + this.region.height * regionScaleY;
  7223. var radians = this.rotation * Math.PI / 180;
  7224. var cos = Math.cos(radians);
  7225. var sin = Math.sin(radians);
  7226. var localXCos = localX * cos + this.x;
  7227. var localXSin = localX * sin;
  7228. var localYCos = localY * cos + this.y;
  7229. var localYSin = localY * sin;
  7230. var localX2Cos = localX2 * cos + this.x;
  7231. var localX2Sin = localX2 * sin;
  7232. var localY2Cos = localY2 * cos + this.y;
  7233. var localY2Sin = localY2 * sin;
  7234. var offset = this.offset;
  7235. offset[RegionAttachment.OX1] = localXCos - localYSin;
  7236. offset[RegionAttachment.OY1] = localYCos + localXSin;
  7237. offset[RegionAttachment.OX2] = localXCos - localY2Sin;
  7238. offset[RegionAttachment.OY2] = localY2Cos + localXSin;
  7239. offset[RegionAttachment.OX3] = localX2Cos - localY2Sin;
  7240. offset[RegionAttachment.OY3] = localY2Cos + localX2Sin;
  7241. offset[RegionAttachment.OX4] = localX2Cos - localYSin;
  7242. offset[RegionAttachment.OY4] = localYCos + localX2Sin;
  7243. };
  7244. RegionAttachment.prototype.setRegion = function (region) {
  7245. this.region = region;
  7246. var uvs = this.uvs;
  7247. if (region.rotate) {
  7248. uvs[2] = region.u;
  7249. uvs[3] = region.v2;
  7250. uvs[4] = region.u;
  7251. uvs[5] = region.v;
  7252. uvs[6] = region.u2;
  7253. uvs[7] = region.v;
  7254. uvs[0] = region.u2;
  7255. uvs[1] = region.v2;
  7256. }
  7257. else {
  7258. uvs[0] = region.u;
  7259. uvs[1] = region.v2;
  7260. uvs[2] = region.u;
  7261. uvs[3] = region.v;
  7262. uvs[4] = region.u2;
  7263. uvs[5] = region.v;
  7264. uvs[6] = region.u2;
  7265. uvs[7] = region.v2;
  7266. }
  7267. };
  7268. RegionAttachment.prototype.computeWorldVertices = function (bone, worldVertices, offset, stride) {
  7269. var vertexOffset = this.offset;
  7270. var x = bone.worldX, y = bone.worldY;
  7271. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  7272. var offsetX = 0, offsetY = 0;
  7273. offsetX = vertexOffset[RegionAttachment.OX1];
  7274. offsetY = vertexOffset[RegionAttachment.OY1];
  7275. worldVertices[offset] = offsetX * a + offsetY * b + x;
  7276. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  7277. offset += stride;
  7278. offsetX = vertexOffset[RegionAttachment.OX2];
  7279. offsetY = vertexOffset[RegionAttachment.OY2];
  7280. worldVertices[offset] = offsetX * a + offsetY * b + x;
  7281. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  7282. offset += stride;
  7283. offsetX = vertexOffset[RegionAttachment.OX3];
  7284. offsetY = vertexOffset[RegionAttachment.OY3];
  7285. worldVertices[offset] = offsetX * a + offsetY * b + x;
  7286. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  7287. offset += stride;
  7288. offsetX = vertexOffset[RegionAttachment.OX4];
  7289. offsetY = vertexOffset[RegionAttachment.OY4];
  7290. worldVertices[offset] = offsetX * a + offsetY * b + x;
  7291. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  7292. };
  7293. RegionAttachment.OX1 = 0;
  7294. RegionAttachment.OY1 = 1;
  7295. RegionAttachment.OX2 = 2;
  7296. RegionAttachment.OY2 = 3;
  7297. RegionAttachment.OX3 = 4;
  7298. RegionAttachment.OY3 = 5;
  7299. RegionAttachment.OX4 = 6;
  7300. RegionAttachment.OY4 = 7;
  7301. RegionAttachment.X1 = 0;
  7302. RegionAttachment.Y1 = 1;
  7303. RegionAttachment.C1R = 2;
  7304. RegionAttachment.C1G = 3;
  7305. RegionAttachment.C1B = 4;
  7306. RegionAttachment.C1A = 5;
  7307. RegionAttachment.U1 = 6;
  7308. RegionAttachment.V1 = 7;
  7309. RegionAttachment.X2 = 8;
  7310. RegionAttachment.Y2 = 9;
  7311. RegionAttachment.C2R = 10;
  7312. RegionAttachment.C2G = 11;
  7313. RegionAttachment.C2B = 12;
  7314. RegionAttachment.C2A = 13;
  7315. RegionAttachment.U2 = 14;
  7316. RegionAttachment.V2 = 15;
  7317. RegionAttachment.X3 = 16;
  7318. RegionAttachment.Y3 = 17;
  7319. RegionAttachment.C3R = 18;
  7320. RegionAttachment.C3G = 19;
  7321. RegionAttachment.C3B = 20;
  7322. RegionAttachment.C3A = 21;
  7323. RegionAttachment.U3 = 22;
  7324. RegionAttachment.V3 = 23;
  7325. RegionAttachment.X4 = 24;
  7326. RegionAttachment.Y4 = 25;
  7327. RegionAttachment.C4R = 26;
  7328. RegionAttachment.C4G = 27;
  7329. RegionAttachment.C4B = 28;
  7330. RegionAttachment.C4A = 29;
  7331. RegionAttachment.U4 = 30;
  7332. RegionAttachment.V4 = 31;
  7333. return RegionAttachment;
  7334. }(spine.Attachment));
  7335. spine.RegionAttachment = RegionAttachment;
  7336. })(spine || (spine = {}));
  7337. var spine;
  7338. (function (spine) {
  7339. var JitterEffect = (function () {
  7340. function JitterEffect(jitterX, jitterY) {
  7341. this.jitterX = 0;
  7342. this.jitterY = 0;
  7343. this.jitterX = jitterX;
  7344. this.jitterY = jitterY;
  7345. }
  7346. JitterEffect.prototype.begin = function (skeleton) {
  7347. };
  7348. JitterEffect.prototype.transform = function (position, uv, light, dark) {
  7349. position.x += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  7350. position.y += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  7351. };
  7352. JitterEffect.prototype.end = function () {
  7353. };
  7354. return JitterEffect;
  7355. }());
  7356. spine.JitterEffect = JitterEffect;
  7357. })(spine || (spine = {}));
  7358. var spine;
  7359. (function (spine) {
  7360. var SwirlEffect = (function () {
  7361. function SwirlEffect(radius) {
  7362. this.centerX = 0;
  7363. this.centerY = 0;
  7364. this.radius = 0;
  7365. this.angle = 0;
  7366. this.worldX = 0;
  7367. this.worldY = 0;
  7368. this.radius = radius;
  7369. }
  7370. SwirlEffect.prototype.begin = function (skeleton) {
  7371. this.worldX = skeleton.x + this.centerX;
  7372. this.worldY = skeleton.y + this.centerY;
  7373. };
  7374. SwirlEffect.prototype.transform = function (position, uv, light, dark) {
  7375. var radAngle = this.angle * spine.MathUtils.degreesToRadians;
  7376. var x = position.x - this.worldX;
  7377. var y = position.y - this.worldY;
  7378. var dist = Math.sqrt(x * x + y * y);
  7379. if (dist < this.radius) {
  7380. var theta = SwirlEffect.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  7381. var cos = Math.cos(theta);
  7382. var sin = Math.sin(theta);
  7383. position.x = cos * x - sin * y + this.worldX;
  7384. position.y = sin * x + cos * y + this.worldY;
  7385. }
  7386. };
  7387. SwirlEffect.prototype.end = function () {
  7388. };
  7389. SwirlEffect.interpolation = new spine.PowOut(2);
  7390. return SwirlEffect;
  7391. }());
  7392. spine.SwirlEffect = SwirlEffect;
  7393. })(spine || (spine = {}));
  7394. var spine;
  7395. (function (spine) {
  7396. var webgl;
  7397. (function (webgl) {
  7398. var AssetManager = (function (_super) {
  7399. __extends(AssetManager, _super);
  7400. function AssetManager(context, pathPrefix) {
  7401. if (pathPrefix === void 0) { pathPrefix = ""; }
  7402. return _super.call(this, function (image) {
  7403. return new spine.webgl.GLTexture(context, image);
  7404. }, pathPrefix) || this;
  7405. }
  7406. return AssetManager;
  7407. }(spine.AssetManager));
  7408. webgl.AssetManager = AssetManager;
  7409. })(webgl = spine.webgl || (spine.webgl = {}));
  7410. })(spine || (spine = {}));
  7411. var spine;
  7412. (function (spine) {
  7413. var webgl;
  7414. (function (webgl) {
  7415. var OrthoCamera = (function () {
  7416. function OrthoCamera(viewportWidth, viewportHeight) {
  7417. this.position = new webgl.Vector3(0, 0, 0);
  7418. this.direction = new webgl.Vector3(0, 0, -1);
  7419. this.up = new webgl.Vector3(0, 1, 0);
  7420. this.near = 0;
  7421. this.far = 100;
  7422. this.zoom = 1;
  7423. this.viewportWidth = 0;
  7424. this.viewportHeight = 0;
  7425. this.projectionView = new webgl.Matrix4();
  7426. this.inverseProjectionView = new webgl.Matrix4();
  7427. this.projection = new webgl.Matrix4();
  7428. this.view = new webgl.Matrix4();
  7429. this.tmp = new webgl.Vector3();
  7430. this.viewportWidth = viewportWidth;
  7431. this.viewportHeight = viewportHeight;
  7432. this.update();
  7433. }
  7434. OrthoCamera.prototype.update = function () {
  7435. var projection = this.projection;
  7436. var view = this.view;
  7437. var projectionView = this.projectionView;
  7438. var inverseProjectionView = this.inverseProjectionView;
  7439. var zoom = this.zoom, viewportWidth = this.viewportWidth, viewportHeight = this.viewportHeight;
  7440. projection.ortho(zoom * (-viewportWidth / 2), zoom * (viewportWidth / 2), zoom * (-viewportHeight / 2), zoom * (viewportHeight / 2), this.near, this.far);
  7441. view.lookAt(this.position, this.direction, this.up);
  7442. projectionView.set(projection.values);
  7443. projectionView.multiply(view);
  7444. inverseProjectionView.set(projectionView.values).invert();
  7445. };
  7446. OrthoCamera.prototype.screenToWorld = function (screenCoords, screenWidth, screenHeight) {
  7447. var x = screenCoords.x, y = screenHeight - screenCoords.y - 1;
  7448. var tmp = this.tmp;
  7449. tmp.x = (2 * x) / screenWidth - 1;
  7450. tmp.y = (2 * y) / screenHeight - 1;
  7451. tmp.z = (2 * screenCoords.z) - 1;
  7452. tmp.project(this.inverseProjectionView);
  7453. screenCoords.set(tmp.x, tmp.y, tmp.z);
  7454. return screenCoords;
  7455. };
  7456. OrthoCamera.prototype.setViewport = function (viewportWidth, viewportHeight) {
  7457. this.viewportWidth = viewportWidth;
  7458. this.viewportHeight = viewportHeight;
  7459. };
  7460. return OrthoCamera;
  7461. }());
  7462. webgl.OrthoCamera = OrthoCamera;
  7463. })(webgl = spine.webgl || (spine.webgl = {}));
  7464. })(spine || (spine = {}));
  7465. var spine;
  7466. (function (spine) {
  7467. var webgl;
  7468. (function (webgl) {
  7469. var GLTexture = (function (_super) {
  7470. __extends(GLTexture, _super);
  7471. function GLTexture(context, image, useMipMaps) {
  7472. if (useMipMaps === void 0) { useMipMaps = false; }
  7473. var _this = _super.call(this, image) || this;
  7474. _this.texture = null;
  7475. _this.boundUnit = 0;
  7476. _this.useMipMaps = false;
  7477. _this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7478. _this.useMipMaps = useMipMaps;
  7479. _this.restore();
  7480. _this.context.addRestorable(_this);
  7481. return _this;
  7482. }
  7483. GLTexture.prototype.setFilters = function (minFilter, magFilter) {
  7484. var gl = this.context.gl;
  7485. this.bind();
  7486. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  7487. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
  7488. };
  7489. GLTexture.prototype.setWraps = function (uWrap, vWrap) {
  7490. var gl = this.context.gl;
  7491. this.bind();
  7492. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap);
  7493. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap);
  7494. };
  7495. GLTexture.prototype.update = function (useMipMaps) {
  7496. var gl = this.context.gl;
  7497. if (!this.texture) {
  7498. this.texture = this.context.gl.createTexture();
  7499. }
  7500. this.bind();
  7501. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image);
  7502. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  7503. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  7504. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  7505. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  7506. if (useMipMaps)
  7507. gl.generateMipmap(gl.TEXTURE_2D);
  7508. };
  7509. GLTexture.prototype.restore = function () {
  7510. this.texture = null;
  7511. this.update(this.useMipMaps);
  7512. };
  7513. GLTexture.prototype.bind = function (unit) {
  7514. if (unit === void 0) { unit = 0; }
  7515. var gl = this.context.gl;
  7516. this.boundUnit = unit;
  7517. gl.activeTexture(gl.TEXTURE0 + unit);
  7518. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  7519. };
  7520. GLTexture.prototype.unbind = function () {
  7521. var gl = this.context.gl;
  7522. gl.activeTexture(gl.TEXTURE0 + this.boundUnit);
  7523. gl.bindTexture(gl.TEXTURE_2D, null);
  7524. };
  7525. GLTexture.prototype.dispose = function () {
  7526. this.context.removeRestorable(this);
  7527. var gl = this.context.gl;
  7528. gl.deleteTexture(this.texture);
  7529. };
  7530. return GLTexture;
  7531. }(spine.Texture));
  7532. webgl.GLTexture = GLTexture;
  7533. })(webgl = spine.webgl || (spine.webgl = {}));
  7534. })(spine || (spine = {}));
  7535. var spine;
  7536. (function (spine) {
  7537. var webgl;
  7538. (function (webgl) {
  7539. var Input = (function () {
  7540. function Input(element) {
  7541. this.lastX = 0;
  7542. this.lastY = 0;
  7543. this.buttonDown = false;
  7544. this.currTouch = null;
  7545. this.touchesPool = new spine.Pool(function () {
  7546. return new spine.webgl.Touch(0, 0, 0);
  7547. });
  7548. this.listeners = new Array();
  7549. this.element = element;
  7550. this.setupCallbacks(element);
  7551. }
  7552. Input.prototype.setupCallbacks = function (element) {
  7553. var _this = this;
  7554. element.addEventListener("mousedown", function (ev) {
  7555. if (ev instanceof MouseEvent) {
  7556. var rect = element.getBoundingClientRect();
  7557. var x = ev.clientX - rect.left;
  7558. var y = ev.clientY - rect.top;
  7559. var listeners = _this.listeners;
  7560. for (var i = 0; i < listeners.length; i++) {
  7561. listeners[i].down(x, y);
  7562. }
  7563. _this.lastX = x;
  7564. _this.lastY = y;
  7565. _this.buttonDown = true;
  7566. }
  7567. }, true);
  7568. element.addEventListener("mousemove", function (ev) {
  7569. if (ev instanceof MouseEvent) {
  7570. var rect = element.getBoundingClientRect();
  7571. var x = ev.clientX - rect.left;
  7572. var y = ev.clientY - rect.top;
  7573. var listeners = _this.listeners;
  7574. for (var i = 0; i < listeners.length; i++) {
  7575. if (_this.buttonDown) {
  7576. listeners[i].dragged(x, y);
  7577. }
  7578. else {
  7579. listeners[i].moved(x, y);
  7580. }
  7581. }
  7582. _this.lastX = x;
  7583. _this.lastY = y;
  7584. }
  7585. }, true);
  7586. element.addEventListener("mouseup", function (ev) {
  7587. if (ev instanceof MouseEvent) {
  7588. var rect = element.getBoundingClientRect();
  7589. var x = ev.clientX - rect.left;
  7590. var y = ev.clientY - rect.top;
  7591. var listeners = _this.listeners;
  7592. for (var i = 0; i < listeners.length; i++) {
  7593. listeners[i].up(x, y);
  7594. }
  7595. _this.lastX = x;
  7596. _this.lastY = y;
  7597. _this.buttonDown = false;
  7598. }
  7599. }, true);
  7600. element.addEventListener("touchstart", function (ev) {
  7601. if (_this.currTouch != null)
  7602. return;
  7603. var touches = ev.changedTouches;
  7604. for (var i = 0; i < touches.length; i++) {
  7605. var touch = touches[i];
  7606. var rect = element.getBoundingClientRect();
  7607. var x = touch.clientX - rect.left;
  7608. var y = touch.clientY - rect.top;
  7609. _this.currTouch = _this.touchesPool.obtain();
  7610. _this.currTouch.identifier = touch.identifier;
  7611. _this.currTouch.x = x;
  7612. _this.currTouch.y = y;
  7613. break;
  7614. }
  7615. var listeners = _this.listeners;
  7616. for (var i_17 = 0; i_17 < listeners.length; i_17++) {
  7617. listeners[i_17].down(_this.currTouch.x, _this.currTouch.y);
  7618. }
  7619. console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y);
  7620. _this.lastX = _this.currTouch.x;
  7621. _this.lastY = _this.currTouch.y;
  7622. _this.buttonDown = true;
  7623. ev.preventDefault();
  7624. }, false);
  7625. element.addEventListener("touchend", function (ev) {
  7626. var touches = ev.changedTouches;
  7627. for (var i = 0; i < touches.length; i++) {
  7628. var touch = touches[i];
  7629. if (_this.currTouch.identifier === touch.identifier) {
  7630. var rect = element.getBoundingClientRect();
  7631. var x = _this.currTouch.x = touch.clientX - rect.left;
  7632. var y = _this.currTouch.y = touch.clientY - rect.top;
  7633. _this.touchesPool.free(_this.currTouch);
  7634. var listeners = _this.listeners;
  7635. for (var i_18 = 0; i_18 < listeners.length; i_18++) {
  7636. listeners[i_18].up(x, y);
  7637. }
  7638. console.log("End " + x + ", " + y);
  7639. _this.lastX = x;
  7640. _this.lastY = y;
  7641. _this.buttonDown = false;
  7642. _this.currTouch = null;
  7643. break;
  7644. }
  7645. }
  7646. ev.preventDefault();
  7647. }, false);
  7648. element.addEventListener("touchcancel", function (ev) {
  7649. var touches = ev.changedTouches;
  7650. for (var i = 0; i < touches.length; i++) {
  7651. var touch = touches[i];
  7652. if (_this.currTouch.identifier === touch.identifier) {
  7653. var rect = element.getBoundingClientRect();
  7654. var x = _this.currTouch.x = touch.clientX - rect.left;
  7655. var y = _this.currTouch.y = touch.clientY - rect.top;
  7656. _this.touchesPool.free(_this.currTouch);
  7657. var listeners = _this.listeners;
  7658. for (var i_19 = 0; i_19 < listeners.length; i_19++) {
  7659. listeners[i_19].up(x, y);
  7660. }
  7661. console.log("End " + x + ", " + y);
  7662. _this.lastX = x;
  7663. _this.lastY = y;
  7664. _this.buttonDown = false;
  7665. _this.currTouch = null;
  7666. break;
  7667. }
  7668. }
  7669. ev.preventDefault();
  7670. }, false);
  7671. element.addEventListener("touchmove", function (ev) {
  7672. if (_this.currTouch == null)
  7673. return;
  7674. var touches = ev.changedTouches;
  7675. for (var i = 0; i < touches.length; i++) {
  7676. var touch = touches[i];
  7677. if (_this.currTouch.identifier === touch.identifier) {
  7678. var rect = element.getBoundingClientRect();
  7679. var x = touch.clientX - rect.left;
  7680. var y = touch.clientY - rect.top;
  7681. var listeners = _this.listeners;
  7682. for (var i_20 = 0; i_20 < listeners.length; i_20++) {
  7683. listeners[i_20].dragged(x, y);
  7684. }
  7685. console.log("Drag " + x + ", " + y);
  7686. _this.lastX = _this.currTouch.x = x;
  7687. _this.lastY = _this.currTouch.y = y;
  7688. break;
  7689. }
  7690. }
  7691. ev.preventDefault();
  7692. }, false);
  7693. };
  7694. Input.prototype.addListener = function (listener) {
  7695. this.listeners.push(listener);
  7696. };
  7697. Input.prototype.removeListener = function (listener) {
  7698. var idx = this.listeners.indexOf(listener);
  7699. if (idx > -1) {
  7700. this.listeners.splice(idx, 1);
  7701. }
  7702. };
  7703. return Input;
  7704. }());
  7705. webgl.Input = Input;
  7706. var Touch = (function () {
  7707. function Touch(identifier, x, y) {
  7708. this.identifier = identifier;
  7709. this.x = x;
  7710. this.y = y;
  7711. }
  7712. return Touch;
  7713. }());
  7714. webgl.Touch = Touch;
  7715. })(webgl = spine.webgl || (spine.webgl = {}));
  7716. })(spine || (spine = {}));
  7717. var spine;
  7718. (function (spine) {
  7719. var webgl;
  7720. (function (webgl) {
  7721. var LoadingScreen = (function () {
  7722. function LoadingScreen(renderer) {
  7723. this.logo = null;
  7724. this.spinner = null;
  7725. this.angle = 0;
  7726. this.fadeOut = 0;
  7727. this.timeKeeper = new spine.TimeKeeper();
  7728. this.backgroundColor = new spine.Color(0.135, 0.135, 0.135, 1);
  7729. this.tempColor = new spine.Color();
  7730. this.firstDraw = 0;
  7731. this.renderer = renderer;
  7732. this.timeKeeper.maxDelta = 9;
  7733. if (LoadingScreen.logoImg === null) {
  7734. var isSafari = navigator.userAgent.indexOf("Safari") > -1;
  7735. LoadingScreen.logoImg = new Image();
  7736. LoadingScreen.logoImg.src = LoadingScreen.SPINE_LOGO_DATA;
  7737. if (!isSafari)
  7738. LoadingScreen.logoImg.crossOrigin = "anonymous";
  7739. LoadingScreen.logoImg.onload = function (ev) {
  7740. LoadingScreen.loaded++;
  7741. };
  7742. LoadingScreen.spinnerImg = new Image();
  7743. LoadingScreen.spinnerImg.src = LoadingScreen.SPINNER_DATA;
  7744. if (!isSafari)
  7745. LoadingScreen.spinnerImg.crossOrigin = "anonymous";
  7746. LoadingScreen.spinnerImg.onload = function (ev) {
  7747. LoadingScreen.loaded++;
  7748. };
  7749. }
  7750. }
  7751. LoadingScreen.prototype.draw = function (complete) {
  7752. if (complete === void 0) { complete = false; }
  7753. if (complete && this.fadeOut > LoadingScreen.FADE_SECONDS)
  7754. return;
  7755. this.timeKeeper.update();
  7756. var a = Math.abs(Math.sin(this.timeKeeper.totalTime + 0.75));
  7757. this.angle -= this.timeKeeper.delta * 360 * (1 + 1.5 * Math.pow(a, 5));
  7758. var renderer = this.renderer;
  7759. var canvas = renderer.canvas;
  7760. var gl = renderer.context.gl;
  7761. var oldX = renderer.camera.position.x, oldY = renderer.camera.position.y;
  7762. renderer.camera.position.set(canvas.width / 2, canvas.height / 2, 0);
  7763. renderer.camera.viewportWidth = canvas.width;
  7764. renderer.camera.viewportHeight = canvas.height;
  7765. renderer.resize(webgl.ResizeMode.Stretch);
  7766. if (!complete) {
  7767. gl.clearColor(this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a);
  7768. gl.clear(gl.COLOR_BUFFER_BIT);
  7769. this.tempColor.a = 1;
  7770. }
  7771. else {
  7772. this.fadeOut += this.timeKeeper.delta * (this.timeKeeper.totalTime < 1 ? 2 : 1);
  7773. if (this.fadeOut > LoadingScreen.FADE_SECONDS) {
  7774. renderer.camera.position.set(oldX, oldY, 0);
  7775. return;
  7776. }
  7777. a = 1 - this.fadeOut / LoadingScreen.FADE_SECONDS;
  7778. this.tempColor.setFromColor(this.backgroundColor);
  7779. this.tempColor.a = 1 - (a - 1) * (a - 1);
  7780. renderer.begin();
  7781. renderer.quad(true, 0, 0, canvas.width, 0, canvas.width, canvas.height, 0, canvas.height, this.tempColor, this.tempColor, this.tempColor, this.tempColor);
  7782. renderer.end();
  7783. }
  7784. this.tempColor.set(1, 1, 1, this.tempColor.a);
  7785. if (LoadingScreen.loaded != 2)
  7786. return;
  7787. if (this.logo === null) {
  7788. this.logo = new webgl.GLTexture(renderer.context, LoadingScreen.logoImg);
  7789. this.spinner = new webgl.GLTexture(renderer.context, LoadingScreen.spinnerImg);
  7790. }
  7791. this.logo.update(false);
  7792. this.spinner.update(false);
  7793. var logoWidth = this.logo.getImage().width;
  7794. var logoHeight = this.logo.getImage().height;
  7795. var spinnerWidth = this.spinner.getImage().width;
  7796. var spinnerHeight = this.spinner.getImage().height;
  7797. renderer.batcher.setBlendMode(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  7798. renderer.begin();
  7799. renderer.drawTexture(this.logo, (canvas.width - logoWidth) / 2, (canvas.height - logoHeight) / 2, logoWidth, logoHeight, this.tempColor);
  7800. renderer.drawTextureRotated(this.spinner, (canvas.width - spinnerWidth) / 2, (canvas.height - spinnerHeight) / 2, spinnerWidth, spinnerHeight, spinnerWidth / 2, spinnerHeight / 2, this.angle, this.tempColor);
  7801. renderer.end();
  7802. renderer.camera.position.set(oldX, oldY, 0);
  7803. };
  7804. LoadingScreen.FADE_SECONDS = 1;
  7805. LoadingScreen.loaded = 0;
  7806. LoadingScreen.spinnerImg = null;
  7807. LoadingScreen.logoImg = null;
  7808. LoadingScreen.SPINNER_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAChCAMAAAB3TUS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAYNQTFRFAAAA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AAkTDRyAAAAIB0Uk5TAAABAgMEBQYHCAkKCwwODxAREhMUFRYXGBkaHB0eICEiIyQlJicoKSorLC0uLzAxMjM0Nzg5Ojs8PT4/QEFDRUlKS0xNTk9QUlRWWFlbXF1eYWJjZmhscHF0d3h5e3x+f4CIiYuMj5GSlJWXm56io6arr7rAxcjO0dXe6Onr8fmb5sOOAAADuElEQVQYGe3B+3vTVBwH4M/3nCRt13br2Lozhug2q25gYQubcxqVKYoMCYoKjEsUdSpeiBc0Kl7yp9t2za39pely7PF5zvuiQKc+/e2f8K+f9g2oyQ77Ag4VGX+HketQ0XYYe0JQ0CdhogwF+WFiBgr6JkxUoKCDMMGgoP0w9gdUtB3GfoCKVsPYAVQ0H8YuQUWVMHYGKuJhrAklPQkjJpT0bdj3O9S0FfZ9ADXxP8MjVSiqFfa8B2VVV8+df14QtB4iwn+BpuZEgyM38WMQHDYhnbkgukrIh5ygZ48glyn6KshlL+jbhVRcxCzk0ApiC5CI5kVsgTAy9jiI/WxBGmqIFBMjqwYphwRZaiLNwsjqQdoVSFISGRwjM4OMFUjBRcYCYWT0XZD2SwUS0LzIKCGH2SDja0LxKiJjCrm0gowVFI6aIs1CTouPg5QvUTgSKXMMuVUeBSmEopFITBPGwO8HCYbCTYtImTAWejuI3CMUjmZFT5NjbM/9GvQcMkhADdFRIxxD7aug4wGDFGSVTcLx0MzutQ2CpmmapmmapmmapmmapmmaphWBmGFV6rNNcaLC0GUuv3LROftUo8wJk0a10207sVED6IIf+9673LIwQeW2PaCEJX/A+xYmhTbtQUu46g96SJgQZg9Zwxf+EAMTwuwhm3jkD7EwIdweBn+YhQlh9pA2HvpDTEwIs4es4GN/CMekNOxBJ9D2B10nTAyfW7fT1hjYgZ/xYIUwUcycaiwuv2h3tOcZADr7ud/12c0ru2cWSwQ1UAcixIgImqZpmqZpmqZpmqZpmqZp2v8HMSIcF186t8oghbnlOJt1wnHwl7yOGxwSlHacrjWG8dVuej03OApn7jhHtiyMiZa9yD6haLYTebWOsbDXvQRHwchJWSTkV/rQS+EoWttJaTHkJe56KXcJRZt20jY48nnBy9hE4WjLSbvAkIfwMm5zFG/KyWgRRke3vYwGZDjpZHCMruJltCAFrTtpVYxu1ktzCHKwbSdlGqOreynXGGQpOylljI5uebFbBuSZc2IbhBxmvcj9GiSiZ52+HQO5nPb6TkIqajs9L5eQk7jnddxZgGT0jNOxYSI36+Kdj9oG5OPV6QpB6yJuGAYnqIrecLveYlDUKffIOtREl90+BiWV3cgMlNR0I09DSS030oaSttzILpT0phu5BBWRmyAoiLkJgoIMN8GgoJKb4FBQzU0YUFDdTRhQUNVNcCjIdBMEBdE7buQ8lFRz+97lUFN5fe+qu//aMkeB/gU2ae9y2HgbngAAAABJRU5ErkJggg==";
  7809. LoadingScreen.SPINE_LOGO_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFIAAAAZCAYAAACis3k0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAtNJREFUaN7tmT2I1EAUxwN+oWgRT0HFKo0WCkJ6ObmAWFwZbCxsXGysLNJaiCyIoDaSwk4ETzvhmnBaCRbBWoQ01ho4PwotjP8cE337mMy8TLK757mBH3fLTWbe/PbN53neNniqZW8FvAVvQAqugwvgDDgO9niLRyTyJagM/ACPF6bsIl9ZRDac/Cc6tLn5xQdRQ496QlKPLxD5QCDxO9jtGM8QfYoIgUlgCipGCRJL5VvlyOdCU09iEXkCfLSIfCrs7Fab6nOsiafu06iDwES9w/uU1QnDC+ekkVS9vEaDsgVeB0d+z1VDtOGxRaYPboP3Gokb4GgXkZp4chZPJKgvZ3U0XkriK/TIt9YUDllFgTAjGwoaoHqfBhMI58yD4BQ4V6/aHYdfxToftvw9F2SiVroawU2/Cv5C4Thv0KB9S5nxlOd4STxjwUjzSdYlgrYijw2BsEfgsaFcM09lhiys94xXQQwugcvgJrgFLjrEE7WUiTuWCQzt/ZXN7FfqGwuGClyVy2xZAFmfDQvNtwFFSspMDGsD+UTWqu1KoVmVooFEJgKRXw0if85RpISEzwsjzeqWzkjkC4PIJ3MUmQgITAHlQwTFhnZhELkEntfZRwR+AvfAgXmJHOqU02XligWT8ppg67NXbdCXeq7afUQ6L8C2DalEZNt2YyQ94Qy8/ekjMpBMbfyl5iTjG7YAI8cNecROAb4kJmTjaXAF3AGvwQewOiuRxEtlSaT4j2h2lMsUueQEoMlIKpTvAmKhxPMtC876jEX6rE8l8TNx/KVbn6xlWU9NWcSDUsO4NGWpQOTZFpHPOooMXcswmW2XFk3ixb2v0Nq+XVKP00QNaffBLyWwBI/AkTlfMYZDXMf12kc6yjwEjoFdO/5me5oi/6tnyhlZX6OtgmX1c2Uh0k3khmbB2b9TRfpd/jfTUeRDJvHdYg5wE7kPXAN3wQ1weDvH+xufEgpi5qIl3QAAAABJRU5ErkJggg==";
  7810. return LoadingScreen;
  7811. }());
  7812. webgl.LoadingScreen = LoadingScreen;
  7813. })(webgl = spine.webgl || (spine.webgl = {}));
  7814. })(spine || (spine = {}));
  7815. var spine;
  7816. (function (spine) {
  7817. var webgl;
  7818. (function (webgl) {
  7819. webgl.M00 = 0;
  7820. webgl.M01 = 4;
  7821. webgl.M02 = 8;
  7822. webgl.M03 = 12;
  7823. webgl.M10 = 1;
  7824. webgl.M11 = 5;
  7825. webgl.M12 = 9;
  7826. webgl.M13 = 13;
  7827. webgl.M20 = 2;
  7828. webgl.M21 = 6;
  7829. webgl.M22 = 10;
  7830. webgl.M23 = 14;
  7831. webgl.M30 = 3;
  7832. webgl.M31 = 7;
  7833. webgl.M32 = 11;
  7834. webgl.M33 = 15;
  7835. var Matrix4 = (function () {
  7836. function Matrix4() {
  7837. this.temp = new Float32Array(16);
  7838. this.values = new Float32Array(16);
  7839. var v = this.values;
  7840. v[webgl.M00] = 1;
  7841. v[webgl.M11] = 1;
  7842. v[webgl.M22] = 1;
  7843. v[webgl.M33] = 1;
  7844. }
  7845. Matrix4.prototype.set = function (values) {
  7846. this.values.set(values);
  7847. return this;
  7848. };
  7849. Matrix4.prototype.transpose = function () {
  7850. var t = this.temp;
  7851. var v = this.values;
  7852. t[webgl.M00] = v[webgl.M00];
  7853. t[webgl.M01] = v[webgl.M10];
  7854. t[webgl.M02] = v[webgl.M20];
  7855. t[webgl.M03] = v[webgl.M30];
  7856. t[webgl.M10] = v[webgl.M01];
  7857. t[webgl.M11] = v[webgl.M11];
  7858. t[webgl.M12] = v[webgl.M21];
  7859. t[webgl.M13] = v[webgl.M31];
  7860. t[webgl.M20] = v[webgl.M02];
  7861. t[webgl.M21] = v[webgl.M12];
  7862. t[webgl.M22] = v[webgl.M22];
  7863. t[webgl.M23] = v[webgl.M32];
  7864. t[webgl.M30] = v[webgl.M03];
  7865. t[webgl.M31] = v[webgl.M13];
  7866. t[webgl.M32] = v[webgl.M23];
  7867. t[webgl.M33] = v[webgl.M33];
  7868. return this.set(t);
  7869. };
  7870. Matrix4.prototype.identity = function () {
  7871. var v = this.values;
  7872. v[webgl.M00] = 1;
  7873. v[webgl.M01] = 0;
  7874. v[webgl.M02] = 0;
  7875. v[webgl.M03] = 0;
  7876. v[webgl.M10] = 0;
  7877. v[webgl.M11] = 1;
  7878. v[webgl.M12] = 0;
  7879. v[webgl.M13] = 0;
  7880. v[webgl.M20] = 0;
  7881. v[webgl.M21] = 0;
  7882. v[webgl.M22] = 1;
  7883. v[webgl.M23] = 0;
  7884. v[webgl.M30] = 0;
  7885. v[webgl.M31] = 0;
  7886. v[webgl.M32] = 0;
  7887. v[webgl.M33] = 1;
  7888. return this;
  7889. };
  7890. Matrix4.prototype.invert = function () {
  7891. var v = this.values;
  7892. var t = this.temp;
  7893. var l_det = v[webgl.M30] * v[webgl.M21] * v[webgl.M12] * v[webgl.M03] - v[webgl.M20] * v[webgl.M31] * v[webgl.M12] * v[webgl.M03] - v[webgl.M30] * v[webgl.M11] * v[webgl.M22] * v[webgl.M03]
  7894. + v[webgl.M10] * v[webgl.M31] * v[webgl.M22] * v[webgl.M03] + v[webgl.M20] * v[webgl.M11] * v[webgl.M32] * v[webgl.M03] - v[webgl.M10] * v[webgl.M21] * v[webgl.M32] * v[webgl.M03]
  7895. - v[webgl.M30] * v[webgl.M21] * v[webgl.M02] * v[webgl.M13] + v[webgl.M20] * v[webgl.M31] * v[webgl.M02] * v[webgl.M13] + v[webgl.M30] * v[webgl.M01] * v[webgl.M22] * v[webgl.M13]
  7896. - v[webgl.M00] * v[webgl.M31] * v[webgl.M22] * v[webgl.M13] - v[webgl.M20] * v[webgl.M01] * v[webgl.M32] * v[webgl.M13] + v[webgl.M00] * v[webgl.M21] * v[webgl.M32] * v[webgl.M13]
  7897. + v[webgl.M30] * v[webgl.M11] * v[webgl.M02] * v[webgl.M23] - v[webgl.M10] * v[webgl.M31] * v[webgl.M02] * v[webgl.M23] - v[webgl.M30] * v[webgl.M01] * v[webgl.M12] * v[webgl.M23]
  7898. + v[webgl.M00] * v[webgl.M31] * v[webgl.M12] * v[webgl.M23] + v[webgl.M10] * v[webgl.M01] * v[webgl.M32] * v[webgl.M23] - v[webgl.M00] * v[webgl.M11] * v[webgl.M32] * v[webgl.M23]
  7899. - v[webgl.M20] * v[webgl.M11] * v[webgl.M02] * v[webgl.M33] + v[webgl.M10] * v[webgl.M21] * v[webgl.M02] * v[webgl.M33] + v[webgl.M20] * v[webgl.M01] * v[webgl.M12] * v[webgl.M33]
  7900. - v[webgl.M00] * v[webgl.M21] * v[webgl.M12] * v[webgl.M33] - v[webgl.M10] * v[webgl.M01] * v[webgl.M22] * v[webgl.M33] + v[webgl.M00] * v[webgl.M11] * v[webgl.M22] * v[webgl.M33];
  7901. if (l_det == 0)
  7902. throw new Error("non-invertible matrix");
  7903. var inv_det = 1.0 / l_det;
  7904. t[webgl.M00] = v[webgl.M12] * v[webgl.M23] * v[webgl.M31] - v[webgl.M13] * v[webgl.M22] * v[webgl.M31] + v[webgl.M13] * v[webgl.M21] * v[webgl.M32]
  7905. - v[webgl.M11] * v[webgl.M23] * v[webgl.M32] - v[webgl.M12] * v[webgl.M21] * v[webgl.M33] + v[webgl.M11] * v[webgl.M22] * v[webgl.M33];
  7906. t[webgl.M01] = v[webgl.M03] * v[webgl.M22] * v[webgl.M31] - v[webgl.M02] * v[webgl.M23] * v[webgl.M31] - v[webgl.M03] * v[webgl.M21] * v[webgl.M32]
  7907. + v[webgl.M01] * v[webgl.M23] * v[webgl.M32] + v[webgl.M02] * v[webgl.M21] * v[webgl.M33] - v[webgl.M01] * v[webgl.M22] * v[webgl.M33];
  7908. t[webgl.M02] = v[webgl.M02] * v[webgl.M13] * v[webgl.M31] - v[webgl.M03] * v[webgl.M12] * v[webgl.M31] + v[webgl.M03] * v[webgl.M11] * v[webgl.M32]
  7909. - v[webgl.M01] * v[webgl.M13] * v[webgl.M32] - v[webgl.M02] * v[webgl.M11] * v[webgl.M33] + v[webgl.M01] * v[webgl.M12] * v[webgl.M33];
  7910. t[webgl.M03] = v[webgl.M03] * v[webgl.M12] * v[webgl.M21] - v[webgl.M02] * v[webgl.M13] * v[webgl.M21] - v[webgl.M03] * v[webgl.M11] * v[webgl.M22]
  7911. + v[webgl.M01] * v[webgl.M13] * v[webgl.M22] + v[webgl.M02] * v[webgl.M11] * v[webgl.M23] - v[webgl.M01] * v[webgl.M12] * v[webgl.M23];
  7912. t[webgl.M10] = v[webgl.M13] * v[webgl.M22] * v[webgl.M30] - v[webgl.M12] * v[webgl.M23] * v[webgl.M30] - v[webgl.M13] * v[webgl.M20] * v[webgl.M32]
  7913. + v[webgl.M10] * v[webgl.M23] * v[webgl.M32] + v[webgl.M12] * v[webgl.M20] * v[webgl.M33] - v[webgl.M10] * v[webgl.M22] * v[webgl.M33];
  7914. t[webgl.M11] = v[webgl.M02] * v[webgl.M23] * v[webgl.M30] - v[webgl.M03] * v[webgl.M22] * v[webgl.M30] + v[webgl.M03] * v[webgl.M20] * v[webgl.M32]
  7915. - v[webgl.M00] * v[webgl.M23] * v[webgl.M32] - v[webgl.M02] * v[webgl.M20] * v[webgl.M33] + v[webgl.M00] * v[webgl.M22] * v[webgl.M33];
  7916. t[webgl.M12] = v[webgl.M03] * v[webgl.M12] * v[webgl.M30] - v[webgl.M02] * v[webgl.M13] * v[webgl.M30] - v[webgl.M03] * v[webgl.M10] * v[webgl.M32]
  7917. + v[webgl.M00] * v[webgl.M13] * v[webgl.M32] + v[webgl.M02] * v[webgl.M10] * v[webgl.M33] - v[webgl.M00] * v[webgl.M12] * v[webgl.M33];
  7918. t[webgl.M13] = v[webgl.M02] * v[webgl.M13] * v[webgl.M20] - v[webgl.M03] * v[webgl.M12] * v[webgl.M20] + v[webgl.M03] * v[webgl.M10] * v[webgl.M22]
  7919. - v[webgl.M00] * v[webgl.M13] * v[webgl.M22] - v[webgl.M02] * v[webgl.M10] * v[webgl.M23] + v[webgl.M00] * v[webgl.M12] * v[webgl.M23];
  7920. t[webgl.M20] = v[webgl.M11] * v[webgl.M23] * v[webgl.M30] - v[webgl.M13] * v[webgl.M21] * v[webgl.M30] + v[webgl.M13] * v[webgl.M20] * v[webgl.M31]
  7921. - v[webgl.M10] * v[webgl.M23] * v[webgl.M31] - v[webgl.M11] * v[webgl.M20] * v[webgl.M33] + v[webgl.M10] * v[webgl.M21] * v[webgl.M33];
  7922. t[webgl.M21] = v[webgl.M03] * v[webgl.M21] * v[webgl.M30] - v[webgl.M01] * v[webgl.M23] * v[webgl.M30] - v[webgl.M03] * v[webgl.M20] * v[webgl.M31]
  7923. + v[webgl.M00] * v[webgl.M23] * v[webgl.M31] + v[webgl.M01] * v[webgl.M20] * v[webgl.M33] - v[webgl.M00] * v[webgl.M21] * v[webgl.M33];
  7924. t[webgl.M22] = v[webgl.M01] * v[webgl.M13] * v[webgl.M30] - v[webgl.M03] * v[webgl.M11] * v[webgl.M30] + v[webgl.M03] * v[webgl.M10] * v[webgl.M31]
  7925. - v[webgl.M00] * v[webgl.M13] * v[webgl.M31] - v[webgl.M01] * v[webgl.M10] * v[webgl.M33] + v[webgl.M00] * v[webgl.M11] * v[webgl.M33];
  7926. t[webgl.M23] = v[webgl.M03] * v[webgl.M11] * v[webgl.M20] - v[webgl.M01] * v[webgl.M13] * v[webgl.M20] - v[webgl.M03] * v[webgl.M10] * v[webgl.M21]
  7927. + v[webgl.M00] * v[webgl.M13] * v[webgl.M21] + v[webgl.M01] * v[webgl.M10] * v[webgl.M23] - v[webgl.M00] * v[webgl.M11] * v[webgl.M23];
  7928. t[webgl.M30] = v[webgl.M12] * v[webgl.M21] * v[webgl.M30] - v[webgl.M11] * v[webgl.M22] * v[webgl.M30] - v[webgl.M12] * v[webgl.M20] * v[webgl.M31]
  7929. + v[webgl.M10] * v[webgl.M22] * v[webgl.M31] + v[webgl.M11] * v[webgl.M20] * v[webgl.M32] - v[webgl.M10] * v[webgl.M21] * v[webgl.M32];
  7930. t[webgl.M31] = v[webgl.M01] * v[webgl.M22] * v[webgl.M30] - v[webgl.M02] * v[webgl.M21] * v[webgl.M30] + v[webgl.M02] * v[webgl.M20] * v[webgl.M31]
  7931. - v[webgl.M00] * v[webgl.M22] * v[webgl.M31] - v[webgl.M01] * v[webgl.M20] * v[webgl.M32] + v[webgl.M00] * v[webgl.M21] * v[webgl.M32];
  7932. t[webgl.M32] = v[webgl.M02] * v[webgl.M11] * v[webgl.M30] - v[webgl.M01] * v[webgl.M12] * v[webgl.M30] - v[webgl.M02] * v[webgl.M10] * v[webgl.M31]
  7933. + v[webgl.M00] * v[webgl.M12] * v[webgl.M31] + v[webgl.M01] * v[webgl.M10] * v[webgl.M32] - v[webgl.M00] * v[webgl.M11] * v[webgl.M32];
  7934. t[webgl.M33] = v[webgl.M01] * v[webgl.M12] * v[webgl.M20] - v[webgl.M02] * v[webgl.M11] * v[webgl.M20] + v[webgl.M02] * v[webgl.M10] * v[webgl.M21]
  7935. - v[webgl.M00] * v[webgl.M12] * v[webgl.M21] - v[webgl.M01] * v[webgl.M10] * v[webgl.M22] + v[webgl.M00] * v[webgl.M11] * v[webgl.M22];
  7936. v[webgl.M00] = t[webgl.M00] * inv_det;
  7937. v[webgl.M01] = t[webgl.M01] * inv_det;
  7938. v[webgl.M02] = t[webgl.M02] * inv_det;
  7939. v[webgl.M03] = t[webgl.M03] * inv_det;
  7940. v[webgl.M10] = t[webgl.M10] * inv_det;
  7941. v[webgl.M11] = t[webgl.M11] * inv_det;
  7942. v[webgl.M12] = t[webgl.M12] * inv_det;
  7943. v[webgl.M13] = t[webgl.M13] * inv_det;
  7944. v[webgl.M20] = t[webgl.M20] * inv_det;
  7945. v[webgl.M21] = t[webgl.M21] * inv_det;
  7946. v[webgl.M22] = t[webgl.M22] * inv_det;
  7947. v[webgl.M23] = t[webgl.M23] * inv_det;
  7948. v[webgl.M30] = t[webgl.M30] * inv_det;
  7949. v[webgl.M31] = t[webgl.M31] * inv_det;
  7950. v[webgl.M32] = t[webgl.M32] * inv_det;
  7951. v[webgl.M33] = t[webgl.M33] * inv_det;
  7952. return this;
  7953. };
  7954. Matrix4.prototype.determinant = function () {
  7955. var v = this.values;
  7956. return v[webgl.M30] * v[webgl.M21] * v[webgl.M12] * v[webgl.M03] - v[webgl.M20] * v[webgl.M31] * v[webgl.M12] * v[webgl.M03] - v[webgl.M30] * v[webgl.M11] * v[webgl.M22] * v[webgl.M03]
  7957. + v[webgl.M10] * v[webgl.M31] * v[webgl.M22] * v[webgl.M03] + v[webgl.M20] * v[webgl.M11] * v[webgl.M32] * v[webgl.M03] - v[webgl.M10] * v[webgl.M21] * v[webgl.M32] * v[webgl.M03]
  7958. - v[webgl.M30] * v[webgl.M21] * v[webgl.M02] * v[webgl.M13] + v[webgl.M20] * v[webgl.M31] * v[webgl.M02] * v[webgl.M13] + v[webgl.M30] * v[webgl.M01] * v[webgl.M22] * v[webgl.M13]
  7959. - v[webgl.M00] * v[webgl.M31] * v[webgl.M22] * v[webgl.M13] - v[webgl.M20] * v[webgl.M01] * v[webgl.M32] * v[webgl.M13] + v[webgl.M00] * v[webgl.M21] * v[webgl.M32] * v[webgl.M13]
  7960. + v[webgl.M30] * v[webgl.M11] * v[webgl.M02] * v[webgl.M23] - v[webgl.M10] * v[webgl.M31] * v[webgl.M02] * v[webgl.M23] - v[webgl.M30] * v[webgl.M01] * v[webgl.M12] * v[webgl.M23]
  7961. + v[webgl.M00] * v[webgl.M31] * v[webgl.M12] * v[webgl.M23] + v[webgl.M10] * v[webgl.M01] * v[webgl.M32] * v[webgl.M23] - v[webgl.M00] * v[webgl.M11] * v[webgl.M32] * v[webgl.M23]
  7962. - v[webgl.M20] * v[webgl.M11] * v[webgl.M02] * v[webgl.M33] + v[webgl.M10] * v[webgl.M21] * v[webgl.M02] * v[webgl.M33] + v[webgl.M20] * v[webgl.M01] * v[webgl.M12] * v[webgl.M33]
  7963. - v[webgl.M00] * v[webgl.M21] * v[webgl.M12] * v[webgl.M33] - v[webgl.M10] * v[webgl.M01] * v[webgl.M22] * v[webgl.M33] + v[webgl.M00] * v[webgl.M11] * v[webgl.M22] * v[webgl.M33];
  7964. };
  7965. Matrix4.prototype.translate = function (x, y, z) {
  7966. var v = this.values;
  7967. v[webgl.M03] += x;
  7968. v[webgl.M13] += y;
  7969. v[webgl.M23] += z;
  7970. return this;
  7971. };
  7972. Matrix4.prototype.copy = function () {
  7973. return new Matrix4().set(this.values);
  7974. };
  7975. Matrix4.prototype.projection = function (near, far, fovy, aspectRatio) {
  7976. this.identity();
  7977. var l_fd = (1.0 / Math.tan((fovy * (Math.PI / 180)) / 2.0));
  7978. var l_a1 = (far + near) / (near - far);
  7979. var l_a2 = (2 * far * near) / (near - far);
  7980. var v = this.values;
  7981. v[webgl.M00] = l_fd / aspectRatio;
  7982. v[webgl.M10] = 0;
  7983. v[webgl.M20] = 0;
  7984. v[webgl.M30] = 0;
  7985. v[webgl.M01] = 0;
  7986. v[webgl.M11] = l_fd;
  7987. v[webgl.M21] = 0;
  7988. v[webgl.M31] = 0;
  7989. v[webgl.M02] = 0;
  7990. v[webgl.M12] = 0;
  7991. v[webgl.M22] = l_a1;
  7992. v[webgl.M32] = -1;
  7993. v[webgl.M03] = 0;
  7994. v[webgl.M13] = 0;
  7995. v[webgl.M23] = l_a2;
  7996. v[webgl.M33] = 0;
  7997. return this;
  7998. };
  7999. Matrix4.prototype.ortho2d = function (x, y, width, height) {
  8000. return this.ortho(x, x + width, y, y + height, 0, 1);
  8001. };
  8002. Matrix4.prototype.ortho = function (left, right, bottom, top, near, far) {
  8003. this.identity();
  8004. var x_orth = 2 / (right - left);
  8005. var y_orth = 2 / (top - bottom);
  8006. var z_orth = -2 / (far - near);
  8007. var tx = -(right + left) / (right - left);
  8008. var ty = -(top + bottom) / (top - bottom);
  8009. var tz = -(far + near) / (far - near);
  8010. var v = this.values;
  8011. v[webgl.M00] = x_orth;
  8012. v[webgl.M10] = 0;
  8013. v[webgl.M20] = 0;
  8014. v[webgl.M30] = 0;
  8015. v[webgl.M01] = 0;
  8016. v[webgl.M11] = y_orth;
  8017. v[webgl.M21] = 0;
  8018. v[webgl.M31] = 0;
  8019. v[webgl.M02] = 0;
  8020. v[webgl.M12] = 0;
  8021. v[webgl.M22] = z_orth;
  8022. v[webgl.M32] = 0;
  8023. v[webgl.M03] = tx;
  8024. v[webgl.M13] = ty;
  8025. v[webgl.M23] = tz;
  8026. v[webgl.M33] = 1;
  8027. return this;
  8028. };
  8029. Matrix4.prototype.multiply = function (matrix) {
  8030. var t = this.temp;
  8031. var v = this.values;
  8032. var m = matrix.values;
  8033. t[webgl.M00] = v[webgl.M00] * m[webgl.M00] + v[webgl.M01] * m[webgl.M10] + v[webgl.M02] * m[webgl.M20] + v[webgl.M03] * m[webgl.M30];
  8034. t[webgl.M01] = v[webgl.M00] * m[webgl.M01] + v[webgl.M01] * m[webgl.M11] + v[webgl.M02] * m[webgl.M21] + v[webgl.M03] * m[webgl.M31];
  8035. t[webgl.M02] = v[webgl.M00] * m[webgl.M02] + v[webgl.M01] * m[webgl.M12] + v[webgl.M02] * m[webgl.M22] + v[webgl.M03] * m[webgl.M32];
  8036. t[webgl.M03] = v[webgl.M00] * m[webgl.M03] + v[webgl.M01] * m[webgl.M13] + v[webgl.M02] * m[webgl.M23] + v[webgl.M03] * m[webgl.M33];
  8037. t[webgl.M10] = v[webgl.M10] * m[webgl.M00] + v[webgl.M11] * m[webgl.M10] + v[webgl.M12] * m[webgl.M20] + v[webgl.M13] * m[webgl.M30];
  8038. t[webgl.M11] = v[webgl.M10] * m[webgl.M01] + v[webgl.M11] * m[webgl.M11] + v[webgl.M12] * m[webgl.M21] + v[webgl.M13] * m[webgl.M31];
  8039. t[webgl.M12] = v[webgl.M10] * m[webgl.M02] + v[webgl.M11] * m[webgl.M12] + v[webgl.M12] * m[webgl.M22] + v[webgl.M13] * m[webgl.M32];
  8040. t[webgl.M13] = v[webgl.M10] * m[webgl.M03] + v[webgl.M11] * m[webgl.M13] + v[webgl.M12] * m[webgl.M23] + v[webgl.M13] * m[webgl.M33];
  8041. t[webgl.M20] = v[webgl.M20] * m[webgl.M00] + v[webgl.M21] * m[webgl.M10] + v[webgl.M22] * m[webgl.M20] + v[webgl.M23] * m[webgl.M30];
  8042. t[webgl.M21] = v[webgl.M20] * m[webgl.M01] + v[webgl.M21] * m[webgl.M11] + v[webgl.M22] * m[webgl.M21] + v[webgl.M23] * m[webgl.M31];
  8043. t[webgl.M22] = v[webgl.M20] * m[webgl.M02] + v[webgl.M21] * m[webgl.M12] + v[webgl.M22] * m[webgl.M22] + v[webgl.M23] * m[webgl.M32];
  8044. t[webgl.M23] = v[webgl.M20] * m[webgl.M03] + v[webgl.M21] * m[webgl.M13] + v[webgl.M22] * m[webgl.M23] + v[webgl.M23] * m[webgl.M33];
  8045. t[webgl.M30] = v[webgl.M30] * m[webgl.M00] + v[webgl.M31] * m[webgl.M10] + v[webgl.M32] * m[webgl.M20] + v[webgl.M33] * m[webgl.M30];
  8046. t[webgl.M31] = v[webgl.M30] * m[webgl.M01] + v[webgl.M31] * m[webgl.M11] + v[webgl.M32] * m[webgl.M21] + v[webgl.M33] * m[webgl.M31];
  8047. t[webgl.M32] = v[webgl.M30] * m[webgl.M02] + v[webgl.M31] * m[webgl.M12] + v[webgl.M32] * m[webgl.M22] + v[webgl.M33] * m[webgl.M32];
  8048. t[webgl.M33] = v[webgl.M30] * m[webgl.M03] + v[webgl.M31] * m[webgl.M13] + v[webgl.M32] * m[webgl.M23] + v[webgl.M33] * m[webgl.M33];
  8049. return this.set(this.temp);
  8050. };
  8051. Matrix4.prototype.multiplyLeft = function (matrix) {
  8052. var t = this.temp;
  8053. var v = this.values;
  8054. var m = matrix.values;
  8055. t[webgl.M00] = m[webgl.M00] * v[webgl.M00] + m[webgl.M01] * v[webgl.M10] + m[webgl.M02] * v[webgl.M20] + m[webgl.M03] * v[webgl.M30];
  8056. t[webgl.M01] = m[webgl.M00] * v[webgl.M01] + m[webgl.M01] * v[webgl.M11] + m[webgl.M02] * v[webgl.M21] + m[webgl.M03] * v[webgl.M31];
  8057. t[webgl.M02] = m[webgl.M00] * v[webgl.M02] + m[webgl.M01] * v[webgl.M12] + m[webgl.M02] * v[webgl.M22] + m[webgl.M03] * v[webgl.M32];
  8058. t[webgl.M03] = m[webgl.M00] * v[webgl.M03] + m[webgl.M01] * v[webgl.M13] + m[webgl.M02] * v[webgl.M23] + m[webgl.M03] * v[webgl.M33];
  8059. t[webgl.M10] = m[webgl.M10] * v[webgl.M00] + m[webgl.M11] * v[webgl.M10] + m[webgl.M12] * v[webgl.M20] + m[webgl.M13] * v[webgl.M30];
  8060. t[webgl.M11] = m[webgl.M10] * v[webgl.M01] + m[webgl.M11] * v[webgl.M11] + m[webgl.M12] * v[webgl.M21] + m[webgl.M13] * v[webgl.M31];
  8061. t[webgl.M12] = m[webgl.M10] * v[webgl.M02] + m[webgl.M11] * v[webgl.M12] + m[webgl.M12] * v[webgl.M22] + m[webgl.M13] * v[webgl.M32];
  8062. t[webgl.M13] = m[webgl.M10] * v[webgl.M03] + m[webgl.M11] * v[webgl.M13] + m[webgl.M12] * v[webgl.M23] + m[webgl.M13] * v[webgl.M33];
  8063. t[webgl.M20] = m[webgl.M20] * v[webgl.M00] + m[webgl.M21] * v[webgl.M10] + m[webgl.M22] * v[webgl.M20] + m[webgl.M23] * v[webgl.M30];
  8064. t[webgl.M21] = m[webgl.M20] * v[webgl.M01] + m[webgl.M21] * v[webgl.M11] + m[webgl.M22] * v[webgl.M21] + m[webgl.M23] * v[webgl.M31];
  8065. t[webgl.M22] = m[webgl.M20] * v[webgl.M02] + m[webgl.M21] * v[webgl.M12] + m[webgl.M22] * v[webgl.M22] + m[webgl.M23] * v[webgl.M32];
  8066. t[webgl.M23] = m[webgl.M20] * v[webgl.M03] + m[webgl.M21] * v[webgl.M13] + m[webgl.M22] * v[webgl.M23] + m[webgl.M23] * v[webgl.M33];
  8067. t[webgl.M30] = m[webgl.M30] * v[webgl.M00] + m[webgl.M31] * v[webgl.M10] + m[webgl.M32] * v[webgl.M20] + m[webgl.M33] * v[webgl.M30];
  8068. t[webgl.M31] = m[webgl.M30] * v[webgl.M01] + m[webgl.M31] * v[webgl.M11] + m[webgl.M32] * v[webgl.M21] + m[webgl.M33] * v[webgl.M31];
  8069. t[webgl.M32] = m[webgl.M30] * v[webgl.M02] + m[webgl.M31] * v[webgl.M12] + m[webgl.M32] * v[webgl.M22] + m[webgl.M33] * v[webgl.M32];
  8070. t[webgl.M33] = m[webgl.M30] * v[webgl.M03] + m[webgl.M31] * v[webgl.M13] + m[webgl.M32] * v[webgl.M23] + m[webgl.M33] * v[webgl.M33];
  8071. return this.set(this.temp);
  8072. };
  8073. Matrix4.prototype.lookAt = function (position, direction, up) {
  8074. Matrix4.initTemps();
  8075. var xAxis = Matrix4.xAxis, yAxis = Matrix4.yAxis, zAxis = Matrix4.zAxis;
  8076. zAxis.setFrom(direction).normalize();
  8077. xAxis.setFrom(direction).normalize();
  8078. xAxis.cross(up).normalize();
  8079. yAxis.setFrom(xAxis).cross(zAxis).normalize();
  8080. this.identity();
  8081. var val = this.values;
  8082. val[webgl.M00] = xAxis.x;
  8083. val[webgl.M01] = xAxis.y;
  8084. val[webgl.M02] = xAxis.z;
  8085. val[webgl.M10] = yAxis.x;
  8086. val[webgl.M11] = yAxis.y;
  8087. val[webgl.M12] = yAxis.z;
  8088. val[webgl.M20] = -zAxis.x;
  8089. val[webgl.M21] = -zAxis.y;
  8090. val[webgl.M22] = -zAxis.z;
  8091. Matrix4.tmpMatrix.identity();
  8092. Matrix4.tmpMatrix.values[webgl.M03] = -position.x;
  8093. Matrix4.tmpMatrix.values[webgl.M13] = -position.y;
  8094. Matrix4.tmpMatrix.values[webgl.M23] = -position.z;
  8095. this.multiply(Matrix4.tmpMatrix);
  8096. return this;
  8097. };
  8098. Matrix4.initTemps = function () {
  8099. if (Matrix4.xAxis === null)
  8100. Matrix4.xAxis = new webgl.Vector3();
  8101. if (Matrix4.yAxis === null)
  8102. Matrix4.yAxis = new webgl.Vector3();
  8103. if (Matrix4.zAxis === null)
  8104. Matrix4.zAxis = new webgl.Vector3();
  8105. };
  8106. Matrix4.xAxis = null;
  8107. Matrix4.yAxis = null;
  8108. Matrix4.zAxis = null;
  8109. Matrix4.tmpMatrix = new Matrix4();
  8110. return Matrix4;
  8111. }());
  8112. webgl.Matrix4 = Matrix4;
  8113. })(webgl = spine.webgl || (spine.webgl = {}));
  8114. })(spine || (spine = {}));
  8115. var spine;
  8116. (function (spine) {
  8117. var webgl;
  8118. (function (webgl) {
  8119. var Mesh = (function () {
  8120. function Mesh(context, attributes, maxVertices, maxIndices) {
  8121. this.attributes = attributes;
  8122. this.verticesLength = 0;
  8123. this.dirtyVertices = false;
  8124. this.indicesLength = 0;
  8125. this.dirtyIndices = false;
  8126. this.elementsPerVertex = 0;
  8127. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8128. this.elementsPerVertex = 0;
  8129. for (var i = 0; i < attributes.length; i++) {
  8130. this.elementsPerVertex += attributes[i].numElements;
  8131. }
  8132. this.vertices = new Float32Array(maxVertices * this.elementsPerVertex);
  8133. this.indices = new Uint16Array(maxIndices);
  8134. this.context.addRestorable(this);
  8135. }
  8136. Mesh.prototype.getAttributes = function () { return this.attributes; };
  8137. Mesh.prototype.maxVertices = function () { return this.vertices.length / this.elementsPerVertex; };
  8138. Mesh.prototype.numVertices = function () { return this.verticesLength / this.elementsPerVertex; };
  8139. Mesh.prototype.setVerticesLength = function (length) {
  8140. this.dirtyVertices = true;
  8141. this.verticesLength = length;
  8142. };
  8143. Mesh.prototype.getVertices = function () { return this.vertices; };
  8144. Mesh.prototype.maxIndices = function () { return this.indices.length; };
  8145. Mesh.prototype.numIndices = function () { return this.indicesLength; };
  8146. Mesh.prototype.setIndicesLength = function (length) {
  8147. this.dirtyIndices = true;
  8148. this.indicesLength = length;
  8149. };
  8150. Mesh.prototype.getIndices = function () { return this.indices; };
  8151. ;
  8152. Mesh.prototype.getVertexSizeInFloats = function () {
  8153. var size = 0;
  8154. for (var i = 0; i < this.attributes.length; i++) {
  8155. var attribute = this.attributes[i];
  8156. size += attribute.numElements;
  8157. }
  8158. return size;
  8159. };
  8160. Mesh.prototype.setVertices = function (vertices) {
  8161. this.dirtyVertices = true;
  8162. if (vertices.length > this.vertices.length)
  8163. throw Error("Mesh can't store more than " + this.maxVertices() + " vertices");
  8164. this.vertices.set(vertices, 0);
  8165. this.verticesLength = vertices.length;
  8166. };
  8167. Mesh.prototype.setIndices = function (indices) {
  8168. this.dirtyIndices = true;
  8169. if (indices.length > this.indices.length)
  8170. throw Error("Mesh can't store more than " + this.maxIndices() + " indices");
  8171. this.indices.set(indices, 0);
  8172. this.indicesLength = indices.length;
  8173. };
  8174. Mesh.prototype.draw = function (shader, primitiveType) {
  8175. this.drawWithOffset(shader, primitiveType, 0, this.indicesLength > 0 ? this.indicesLength : this.verticesLength / this.elementsPerVertex);
  8176. };
  8177. Mesh.prototype.drawWithOffset = function (shader, primitiveType, offset, count) {
  8178. var gl = this.context.gl;
  8179. if (this.dirtyVertices || this.dirtyIndices)
  8180. this.update();
  8181. this.bind(shader);
  8182. if (this.indicesLength > 0) {
  8183. gl.drawElements(primitiveType, count, gl.UNSIGNED_SHORT, offset * 2);
  8184. }
  8185. else {
  8186. gl.drawArrays(primitiveType, offset, count);
  8187. }
  8188. this.unbind(shader);
  8189. };
  8190. Mesh.prototype.bind = function (shader) {
  8191. var gl = this.context.gl;
  8192. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  8193. var offset = 0;
  8194. for (var i = 0; i < this.attributes.length; i++) {
  8195. var attrib = this.attributes[i];
  8196. var location_1 = shader.getAttributeLocation(attrib.name);
  8197. gl.enableVertexAttribArray(location_1);
  8198. gl.vertexAttribPointer(location_1, attrib.numElements, gl.FLOAT, false, this.elementsPerVertex * 4, offset * 4);
  8199. offset += attrib.numElements;
  8200. }
  8201. if (this.indicesLength > 0)
  8202. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  8203. };
  8204. Mesh.prototype.unbind = function (shader) {
  8205. var gl = this.context.gl;
  8206. for (var i = 0; i < this.attributes.length; i++) {
  8207. var attrib = this.attributes[i];
  8208. var location_2 = shader.getAttributeLocation(attrib.name);
  8209. gl.disableVertexAttribArray(location_2);
  8210. }
  8211. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  8212. if (this.indicesLength > 0)
  8213. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  8214. };
  8215. Mesh.prototype.update = function () {
  8216. var gl = this.context.gl;
  8217. if (this.dirtyVertices) {
  8218. if (!this.verticesBuffer) {
  8219. this.verticesBuffer = gl.createBuffer();
  8220. }
  8221. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  8222. gl.bufferData(gl.ARRAY_BUFFER, this.vertices.subarray(0, this.verticesLength), gl.DYNAMIC_DRAW);
  8223. this.dirtyVertices = false;
  8224. }
  8225. if (this.dirtyIndices) {
  8226. if (!this.indicesBuffer) {
  8227. this.indicesBuffer = gl.createBuffer();
  8228. }
  8229. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  8230. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices.subarray(0, this.indicesLength), gl.DYNAMIC_DRAW);
  8231. this.dirtyIndices = false;
  8232. }
  8233. };
  8234. Mesh.prototype.restore = function () {
  8235. this.verticesBuffer = null;
  8236. this.indicesBuffer = null;
  8237. this.update();
  8238. };
  8239. Mesh.prototype.dispose = function () {
  8240. this.context.removeRestorable(this);
  8241. var gl = this.context.gl;
  8242. gl.deleteBuffer(this.verticesBuffer);
  8243. gl.deleteBuffer(this.indicesBuffer);
  8244. };
  8245. return Mesh;
  8246. }());
  8247. webgl.Mesh = Mesh;
  8248. var VertexAttribute = (function () {
  8249. function VertexAttribute(name, type, numElements) {
  8250. this.name = name;
  8251. this.type = type;
  8252. this.numElements = numElements;
  8253. }
  8254. return VertexAttribute;
  8255. }());
  8256. webgl.VertexAttribute = VertexAttribute;
  8257. var Position2Attribute = (function (_super) {
  8258. __extends(Position2Attribute, _super);
  8259. function Position2Attribute() {
  8260. return _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 2) || this;
  8261. }
  8262. return Position2Attribute;
  8263. }(VertexAttribute));
  8264. webgl.Position2Attribute = Position2Attribute;
  8265. var Position3Attribute = (function (_super) {
  8266. __extends(Position3Attribute, _super);
  8267. function Position3Attribute() {
  8268. return _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 3) || this;
  8269. }
  8270. return Position3Attribute;
  8271. }(VertexAttribute));
  8272. webgl.Position3Attribute = Position3Attribute;
  8273. var TexCoordAttribute = (function (_super) {
  8274. __extends(TexCoordAttribute, _super);
  8275. function TexCoordAttribute(unit) {
  8276. if (unit === void 0) { unit = 0; }
  8277. return _super.call(this, webgl.Shader.TEXCOORDS + (unit == 0 ? "" : unit), VertexAttributeType.Float, 2) || this;
  8278. }
  8279. return TexCoordAttribute;
  8280. }(VertexAttribute));
  8281. webgl.TexCoordAttribute = TexCoordAttribute;
  8282. var ColorAttribute = (function (_super) {
  8283. __extends(ColorAttribute, _super);
  8284. function ColorAttribute() {
  8285. return _super.call(this, webgl.Shader.COLOR, VertexAttributeType.Float, 4) || this;
  8286. }
  8287. return ColorAttribute;
  8288. }(VertexAttribute));
  8289. webgl.ColorAttribute = ColorAttribute;
  8290. var Color2Attribute = (function (_super) {
  8291. __extends(Color2Attribute, _super);
  8292. function Color2Attribute() {
  8293. return _super.call(this, webgl.Shader.COLOR2, VertexAttributeType.Float, 4) || this;
  8294. }
  8295. return Color2Attribute;
  8296. }(VertexAttribute));
  8297. webgl.Color2Attribute = Color2Attribute;
  8298. var VertexAttributeType;
  8299. (function (VertexAttributeType) {
  8300. VertexAttributeType[VertexAttributeType["Float"] = 0] = "Float";
  8301. })(VertexAttributeType = webgl.VertexAttributeType || (webgl.VertexAttributeType = {}));
  8302. })(webgl = spine.webgl || (spine.webgl = {}));
  8303. })(spine || (spine = {}));
  8304. var spine;
  8305. (function (spine) {
  8306. var webgl;
  8307. (function (webgl) {
  8308. var PolygonBatcher = (function () {
  8309. function PolygonBatcher(context, twoColorTint, maxVertices) {
  8310. if (twoColorTint === void 0) { twoColorTint = true; }
  8311. if (maxVertices === void 0) { maxVertices = 10920; }
  8312. this.isDrawing = false;
  8313. this.shader = null;
  8314. this.lastTexture = null;
  8315. this.verticesLength = 0;
  8316. this.indicesLength = 0;
  8317. if (maxVertices > 10920)
  8318. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  8319. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8320. var attributes = twoColorTint ?
  8321. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute(), new webgl.Color2Attribute()] :
  8322. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute()];
  8323. this.mesh = new webgl.Mesh(context, attributes, maxVertices, maxVertices * 3);
  8324. this.srcBlend = this.context.gl.SRC_ALPHA;
  8325. this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
  8326. }
  8327. PolygonBatcher.prototype.begin = function (shader) {
  8328. var gl = this.context.gl;
  8329. if (this.isDrawing)
  8330. throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()");
  8331. this.drawCalls = 0;
  8332. this.shader = shader;
  8333. this.lastTexture = null;
  8334. this.isDrawing = true;
  8335. gl.enable(gl.BLEND);
  8336. gl.blendFunc(this.srcBlend, this.dstBlend);
  8337. };
  8338. PolygonBatcher.prototype.setBlendMode = function (srcBlend, dstBlend) {
  8339. var gl = this.context.gl;
  8340. this.srcBlend = srcBlend;
  8341. this.dstBlend = dstBlend;
  8342. if (this.isDrawing) {
  8343. this.flush();
  8344. gl.blendFunc(this.srcBlend, this.dstBlend);
  8345. }
  8346. };
  8347. PolygonBatcher.prototype.draw = function (texture, vertices, indices) {
  8348. if (texture != this.lastTexture) {
  8349. this.flush();
  8350. this.lastTexture = texture;
  8351. }
  8352. else if (this.verticesLength + vertices.length > this.mesh.getVertices().length ||
  8353. this.indicesLength + indices.length > this.mesh.getIndices().length) {
  8354. this.flush();
  8355. }
  8356. var indexStart = this.mesh.numVertices();
  8357. this.mesh.getVertices().set(vertices, this.verticesLength);
  8358. this.verticesLength += vertices.length;
  8359. this.mesh.setVerticesLength(this.verticesLength);
  8360. var indicesArray = this.mesh.getIndices();
  8361. for (var i = this.indicesLength, j = 0; j < indices.length; i++, j++)
  8362. indicesArray[i] = indices[j] + indexStart;
  8363. this.indicesLength += indices.length;
  8364. this.mesh.setIndicesLength(this.indicesLength);
  8365. };
  8366. PolygonBatcher.prototype.flush = function () {
  8367. var gl = this.context.gl;
  8368. if (this.verticesLength == 0)
  8369. return;
  8370. this.lastTexture.bind();
  8371. this.mesh.draw(this.shader, gl.TRIANGLES);
  8372. this.verticesLength = 0;
  8373. this.indicesLength = 0;
  8374. this.mesh.setVerticesLength(0);
  8375. this.mesh.setIndicesLength(0);
  8376. this.drawCalls++;
  8377. };
  8378. PolygonBatcher.prototype.end = function () {
  8379. var gl = this.context.gl;
  8380. if (!this.isDrawing)
  8381. throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()");
  8382. if (this.verticesLength > 0 || this.indicesLength > 0)
  8383. this.flush();
  8384. this.shader = null;
  8385. this.lastTexture = null;
  8386. this.isDrawing = false;
  8387. gl.disable(gl.BLEND);
  8388. };
  8389. PolygonBatcher.prototype.getDrawCalls = function () { return this.drawCalls; };
  8390. PolygonBatcher.prototype.dispose = function () {
  8391. this.mesh.dispose();
  8392. };
  8393. return PolygonBatcher;
  8394. }());
  8395. webgl.PolygonBatcher = PolygonBatcher;
  8396. })(webgl = spine.webgl || (spine.webgl = {}));
  8397. })(spine || (spine = {}));
  8398. var spine;
  8399. (function (spine) {
  8400. var webgl;
  8401. (function (webgl) {
  8402. var SceneRenderer = (function () {
  8403. function SceneRenderer(canvas, context, twoColorTint) {
  8404. if (twoColorTint === void 0) { twoColorTint = true; }
  8405. this.twoColorTint = false;
  8406. this.activeRenderer = null;
  8407. this.QUAD = [
  8408. 0, 0, 1, 1, 1, 1, 0, 0,
  8409. 0, 0, 1, 1, 1, 1, 0, 0,
  8410. 0, 0, 1, 1, 1, 1, 0, 0,
  8411. 0, 0, 1, 1, 1, 1, 0, 0,
  8412. ];
  8413. this.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  8414. this.WHITE = new spine.Color(1, 1, 1, 1);
  8415. this.canvas = canvas;
  8416. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8417. this.twoColorTint = twoColorTint;
  8418. this.camera = new webgl.OrthoCamera(canvas.width, canvas.height);
  8419. this.batcherShader = twoColorTint ? webgl.Shader.newTwoColoredTextured(this.context) : webgl.Shader.newColoredTextured(this.context);
  8420. this.batcher = new webgl.PolygonBatcher(this.context, twoColorTint);
  8421. this.shapesShader = webgl.Shader.newColored(this.context);
  8422. this.shapes = new webgl.ShapeRenderer(this.context);
  8423. this.skeletonRenderer = new webgl.SkeletonRenderer(this.context, twoColorTint);
  8424. this.skeletonDebugRenderer = new webgl.SkeletonDebugRenderer(this.context);
  8425. }
  8426. SceneRenderer.prototype.begin = function () {
  8427. this.camera.update();
  8428. this.enableRenderer(this.batcher);
  8429. };
  8430. SceneRenderer.prototype.drawSkeleton = function (skeleton, premultipliedAlpha, slotRangeStart, slotRangeEnd) {
  8431. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  8432. if (slotRangeStart === void 0) { slotRangeStart = -1; }
  8433. if (slotRangeEnd === void 0) { slotRangeEnd = -1; }
  8434. this.enableRenderer(this.batcher);
  8435. this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
  8436. this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd);
  8437. };
  8438. SceneRenderer.prototype.drawSkeletonDebug = function (skeleton, premultipliedAlpha, ignoredBones) {
  8439. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  8440. if (ignoredBones === void 0) { ignoredBones = null; }
  8441. this.enableRenderer(this.shapes);
  8442. this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha;
  8443. this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones);
  8444. };
  8445. SceneRenderer.prototype.drawTexture = function (texture, x, y, width, height, color) {
  8446. if (color === void 0) { color = null; }
  8447. this.enableRenderer(this.batcher);
  8448. if (color === null)
  8449. color = this.WHITE;
  8450. var quad = this.QUAD;
  8451. var i = 0;
  8452. quad[i++] = x;
  8453. quad[i++] = y;
  8454. quad[i++] = color.r;
  8455. quad[i++] = color.g;
  8456. quad[i++] = color.b;
  8457. quad[i++] = color.a;
  8458. quad[i++] = 0;
  8459. quad[i++] = 1;
  8460. if (this.twoColorTint) {
  8461. quad[i++] = 0;
  8462. quad[i++] = 0;
  8463. quad[i++] = 0;
  8464. quad[i++] = 0;
  8465. }
  8466. quad[i++] = x + width;
  8467. quad[i++] = y;
  8468. quad[i++] = color.r;
  8469. quad[i++] = color.g;
  8470. quad[i++] = color.b;
  8471. quad[i++] = color.a;
  8472. quad[i++] = 1;
  8473. quad[i++] = 1;
  8474. if (this.twoColorTint) {
  8475. quad[i++] = 0;
  8476. quad[i++] = 0;
  8477. quad[i++] = 0;
  8478. quad[i++] = 0;
  8479. }
  8480. quad[i++] = x + width;
  8481. quad[i++] = y + height;
  8482. quad[i++] = color.r;
  8483. quad[i++] = color.g;
  8484. quad[i++] = color.b;
  8485. quad[i++] = color.a;
  8486. quad[i++] = 1;
  8487. quad[i++] = 0;
  8488. if (this.twoColorTint) {
  8489. quad[i++] = 0;
  8490. quad[i++] = 0;
  8491. quad[i++] = 0;
  8492. quad[i++] = 0;
  8493. }
  8494. quad[i++] = x;
  8495. quad[i++] = y + height;
  8496. quad[i++] = color.r;
  8497. quad[i++] = color.g;
  8498. quad[i++] = color.b;
  8499. quad[i++] = color.a;
  8500. quad[i++] = 0;
  8501. quad[i++] = 0;
  8502. if (this.twoColorTint) {
  8503. quad[i++] = 0;
  8504. quad[i++] = 0;
  8505. quad[i++] = 0;
  8506. quad[i++] = 0;
  8507. }
  8508. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  8509. };
  8510. SceneRenderer.prototype.drawTextureUV = function (texture, x, y, width, height, u, v, u2, v2, color) {
  8511. if (color === void 0) { color = null; }
  8512. this.enableRenderer(this.batcher);
  8513. if (color === null)
  8514. color = this.WHITE;
  8515. var quad = this.QUAD;
  8516. var i = 0;
  8517. quad[i++] = x;
  8518. quad[i++] = y;
  8519. quad[i++] = color.r;
  8520. quad[i++] = color.g;
  8521. quad[i++] = color.b;
  8522. quad[i++] = color.a;
  8523. quad[i++] = u;
  8524. quad[i++] = v;
  8525. if (this.twoColorTint) {
  8526. quad[i++] = 0;
  8527. quad[i++] = 0;
  8528. quad[i++] = 0;
  8529. quad[i++] = 0;
  8530. }
  8531. quad[i++] = x + width;
  8532. quad[i++] = y;
  8533. quad[i++] = color.r;
  8534. quad[i++] = color.g;
  8535. quad[i++] = color.b;
  8536. quad[i++] = color.a;
  8537. quad[i++] = u2;
  8538. quad[i++] = v;
  8539. if (this.twoColorTint) {
  8540. quad[i++] = 0;
  8541. quad[i++] = 0;
  8542. quad[i++] = 0;
  8543. quad[i++] = 0;
  8544. }
  8545. quad[i++] = x + width;
  8546. quad[i++] = y + height;
  8547. quad[i++] = color.r;
  8548. quad[i++] = color.g;
  8549. quad[i++] = color.b;
  8550. quad[i++] = color.a;
  8551. quad[i++] = u2;
  8552. quad[i++] = v2;
  8553. if (this.twoColorTint) {
  8554. quad[i++] = 0;
  8555. quad[i++] = 0;
  8556. quad[i++] = 0;
  8557. quad[i++] = 0;
  8558. }
  8559. quad[i++] = x;
  8560. quad[i++] = y + height;
  8561. quad[i++] = color.r;
  8562. quad[i++] = color.g;
  8563. quad[i++] = color.b;
  8564. quad[i++] = color.a;
  8565. quad[i++] = u;
  8566. quad[i++] = v2;
  8567. if (this.twoColorTint) {
  8568. quad[i++] = 0;
  8569. quad[i++] = 0;
  8570. quad[i++] = 0;
  8571. quad[i++] = 0;
  8572. }
  8573. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  8574. };
  8575. SceneRenderer.prototype.drawTextureRotated = function (texture, x, y, width, height, pivotX, pivotY, angle, color, premultipliedAlpha) {
  8576. if (color === void 0) { color = null; }
  8577. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  8578. this.enableRenderer(this.batcher);
  8579. if (color === null)
  8580. color = this.WHITE;
  8581. var quad = this.QUAD;
  8582. var worldOriginX = x + pivotX;
  8583. var worldOriginY = y + pivotY;
  8584. var fx = -pivotX;
  8585. var fy = -pivotY;
  8586. var fx2 = width - pivotX;
  8587. var fy2 = height - pivotY;
  8588. var p1x = fx;
  8589. var p1y = fy;
  8590. var p2x = fx;
  8591. var p2y = fy2;
  8592. var p3x = fx2;
  8593. var p3y = fy2;
  8594. var p4x = fx2;
  8595. var p4y = fy;
  8596. var x1 = 0;
  8597. var y1 = 0;
  8598. var x2 = 0;
  8599. var y2 = 0;
  8600. var x3 = 0;
  8601. var y3 = 0;
  8602. var x4 = 0;
  8603. var y4 = 0;
  8604. if (angle != 0) {
  8605. var cos = spine.MathUtils.cosDeg(angle);
  8606. var sin = spine.MathUtils.sinDeg(angle);
  8607. x1 = cos * p1x - sin * p1y;
  8608. y1 = sin * p1x + cos * p1y;
  8609. x4 = cos * p2x - sin * p2y;
  8610. y4 = sin * p2x + cos * p2y;
  8611. x3 = cos * p3x - sin * p3y;
  8612. y3 = sin * p3x + cos * p3y;
  8613. x2 = x3 + (x1 - x4);
  8614. y2 = y3 + (y1 - y4);
  8615. }
  8616. else {
  8617. x1 = p1x;
  8618. y1 = p1y;
  8619. x4 = p2x;
  8620. y4 = p2y;
  8621. x3 = p3x;
  8622. y3 = p3y;
  8623. x2 = p4x;
  8624. y2 = p4y;
  8625. }
  8626. x1 += worldOriginX;
  8627. y1 += worldOriginY;
  8628. x2 += worldOriginX;
  8629. y2 += worldOriginY;
  8630. x3 += worldOriginX;
  8631. y3 += worldOriginY;
  8632. x4 += worldOriginX;
  8633. y4 += worldOriginY;
  8634. var i = 0;
  8635. quad[i++] = x1;
  8636. quad[i++] = y1;
  8637. quad[i++] = color.r;
  8638. quad[i++] = color.g;
  8639. quad[i++] = color.b;
  8640. quad[i++] = color.a;
  8641. quad[i++] = 0;
  8642. quad[i++] = 1;
  8643. if (this.twoColorTint) {
  8644. quad[i++] = 0;
  8645. quad[i++] = 0;
  8646. quad[i++] = 0;
  8647. quad[i++] = 0;
  8648. }
  8649. quad[i++] = x2;
  8650. quad[i++] = y2;
  8651. quad[i++] = color.r;
  8652. quad[i++] = color.g;
  8653. quad[i++] = color.b;
  8654. quad[i++] = color.a;
  8655. quad[i++] = 1;
  8656. quad[i++] = 1;
  8657. if (this.twoColorTint) {
  8658. quad[i++] = 0;
  8659. quad[i++] = 0;
  8660. quad[i++] = 0;
  8661. quad[i++] = 0;
  8662. }
  8663. quad[i++] = x3;
  8664. quad[i++] = y3;
  8665. quad[i++] = color.r;
  8666. quad[i++] = color.g;
  8667. quad[i++] = color.b;
  8668. quad[i++] = color.a;
  8669. quad[i++] = 1;
  8670. quad[i++] = 0;
  8671. if (this.twoColorTint) {
  8672. quad[i++] = 0;
  8673. quad[i++] = 0;
  8674. quad[i++] = 0;
  8675. quad[i++] = 0;
  8676. }
  8677. quad[i++] = x4;
  8678. quad[i++] = y4;
  8679. quad[i++] = color.r;
  8680. quad[i++] = color.g;
  8681. quad[i++] = color.b;
  8682. quad[i++] = color.a;
  8683. quad[i++] = 0;
  8684. quad[i++] = 0;
  8685. if (this.twoColorTint) {
  8686. quad[i++] = 0;
  8687. quad[i++] = 0;
  8688. quad[i++] = 0;
  8689. quad[i++] = 0;
  8690. }
  8691. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  8692. };
  8693. SceneRenderer.prototype.drawRegion = function (region, x, y, width, height, color, premultipliedAlpha) {
  8694. if (color === void 0) { color = null; }
  8695. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  8696. this.enableRenderer(this.batcher);
  8697. if (color === null)
  8698. color = this.WHITE;
  8699. var quad = this.QUAD;
  8700. var i = 0;
  8701. quad[i++] = x;
  8702. quad[i++] = y;
  8703. quad[i++] = color.r;
  8704. quad[i++] = color.g;
  8705. quad[i++] = color.b;
  8706. quad[i++] = color.a;
  8707. quad[i++] = region.u;
  8708. quad[i++] = region.v2;
  8709. if (this.twoColorTint) {
  8710. quad[i++] = 0;
  8711. quad[i++] = 0;
  8712. quad[i++] = 0;
  8713. quad[i++] = 0;
  8714. }
  8715. quad[i++] = x + width;
  8716. quad[i++] = y;
  8717. quad[i++] = color.r;
  8718. quad[i++] = color.g;
  8719. quad[i++] = color.b;
  8720. quad[i++] = color.a;
  8721. quad[i++] = region.u2;
  8722. quad[i++] = region.v2;
  8723. if (this.twoColorTint) {
  8724. quad[i++] = 0;
  8725. quad[i++] = 0;
  8726. quad[i++] = 0;
  8727. quad[i++] = 0;
  8728. }
  8729. quad[i++] = x + width;
  8730. quad[i++] = y + height;
  8731. quad[i++] = color.r;
  8732. quad[i++] = color.g;
  8733. quad[i++] = color.b;
  8734. quad[i++] = color.a;
  8735. quad[i++] = region.u2;
  8736. quad[i++] = region.v;
  8737. if (this.twoColorTint) {
  8738. quad[i++] = 0;
  8739. quad[i++] = 0;
  8740. quad[i++] = 0;
  8741. quad[i++] = 0;
  8742. }
  8743. quad[i++] = x;
  8744. quad[i++] = y + height;
  8745. quad[i++] = color.r;
  8746. quad[i++] = color.g;
  8747. quad[i++] = color.b;
  8748. quad[i++] = color.a;
  8749. quad[i++] = region.u;
  8750. quad[i++] = region.v;
  8751. if (this.twoColorTint) {
  8752. quad[i++] = 0;
  8753. quad[i++] = 0;
  8754. quad[i++] = 0;
  8755. quad[i++] = 0;
  8756. }
  8757. this.batcher.draw(region.texture, quad, this.QUAD_TRIANGLES);
  8758. };
  8759. SceneRenderer.prototype.line = function (x, y, x2, y2, color, color2) {
  8760. if (color === void 0) { color = null; }
  8761. if (color2 === void 0) { color2 = null; }
  8762. this.enableRenderer(this.shapes);
  8763. this.shapes.line(x, y, x2, y2, color);
  8764. };
  8765. SceneRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  8766. if (color === void 0) { color = null; }
  8767. if (color2 === void 0) { color2 = null; }
  8768. if (color3 === void 0) { color3 = null; }
  8769. this.enableRenderer(this.shapes);
  8770. this.shapes.triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3);
  8771. };
  8772. SceneRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  8773. if (color === void 0) { color = null; }
  8774. if (color2 === void 0) { color2 = null; }
  8775. if (color3 === void 0) { color3 = null; }
  8776. if (color4 === void 0) { color4 = null; }
  8777. this.enableRenderer(this.shapes);
  8778. this.shapes.quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4);
  8779. };
  8780. SceneRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  8781. if (color === void 0) { color = null; }
  8782. this.enableRenderer(this.shapes);
  8783. this.shapes.rect(filled, x, y, width, height, color);
  8784. };
  8785. SceneRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  8786. if (color === void 0) { color = null; }
  8787. this.enableRenderer(this.shapes);
  8788. this.shapes.rectLine(filled, x1, y1, x2, y2, width, color);
  8789. };
  8790. SceneRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  8791. if (color === void 0) { color = null; }
  8792. this.enableRenderer(this.shapes);
  8793. this.shapes.polygon(polygonVertices, offset, count, color);
  8794. };
  8795. SceneRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  8796. if (color === void 0) { color = null; }
  8797. if (segments === void 0) { segments = 0; }
  8798. this.enableRenderer(this.shapes);
  8799. this.shapes.circle(filled, x, y, radius, color, segments);
  8800. };
  8801. SceneRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  8802. if (color === void 0) { color = null; }
  8803. this.enableRenderer(this.shapes);
  8804. this.shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color);
  8805. };
  8806. SceneRenderer.prototype.end = function () {
  8807. if (this.activeRenderer === this.batcher)
  8808. this.batcher.end();
  8809. else if (this.activeRenderer === this.shapes)
  8810. this.shapes.end();
  8811. this.activeRenderer = null;
  8812. };
  8813. SceneRenderer.prototype.resize = function (resizeMode) {
  8814. var canvas = this.canvas;
  8815. var w = canvas.clientWidth;
  8816. var h = canvas.clientHeight;
  8817. if (canvas.width != w || canvas.height != h) {
  8818. canvas.width = w;
  8819. canvas.height = h;
  8820. }
  8821. this.context.gl.viewport(0, 0, canvas.width, canvas.height);
  8822. if (resizeMode === ResizeMode.Stretch) {
  8823. }
  8824. else if (resizeMode === ResizeMode.Expand) {
  8825. this.camera.setViewport(w, h);
  8826. }
  8827. else if (resizeMode === ResizeMode.Fit) {
  8828. var sourceWidth = canvas.width, sourceHeight = canvas.height;
  8829. var targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHeight;
  8830. var targetRatio = targetHeight / targetWidth;
  8831. var sourceRatio = sourceHeight / sourceWidth;
  8832. var scale = targetRatio < sourceRatio ? targetWidth / sourceWidth : targetHeight / sourceHeight;
  8833. this.camera.viewportWidth = sourceWidth * scale;
  8834. this.camera.viewportHeight = sourceHeight * scale;
  8835. }
  8836. this.camera.update();
  8837. };
  8838. SceneRenderer.prototype.enableRenderer = function (renderer) {
  8839. if (this.activeRenderer === renderer)
  8840. return;
  8841. this.end();
  8842. if (renderer instanceof webgl.PolygonBatcher) {
  8843. this.batcherShader.bind();
  8844. this.batcherShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  8845. this.batcherShader.setUniformi("u_texture", 0);
  8846. this.batcher.begin(this.batcherShader);
  8847. this.activeRenderer = this.batcher;
  8848. }
  8849. else if (renderer instanceof webgl.ShapeRenderer) {
  8850. this.shapesShader.bind();
  8851. this.shapesShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  8852. this.shapes.begin(this.shapesShader);
  8853. this.activeRenderer = this.shapes;
  8854. }
  8855. else {
  8856. this.activeRenderer = this.skeletonDebugRenderer;
  8857. }
  8858. };
  8859. SceneRenderer.prototype.dispose = function () {
  8860. this.batcher.dispose();
  8861. this.batcherShader.dispose();
  8862. this.shapes.dispose();
  8863. this.shapesShader.dispose();
  8864. this.skeletonDebugRenderer.dispose();
  8865. };
  8866. return SceneRenderer;
  8867. }());
  8868. webgl.SceneRenderer = SceneRenderer;
  8869. var ResizeMode;
  8870. (function (ResizeMode) {
  8871. ResizeMode[ResizeMode["Stretch"] = 0] = "Stretch";
  8872. ResizeMode[ResizeMode["Expand"] = 1] = "Expand";
  8873. ResizeMode[ResizeMode["Fit"] = 2] = "Fit";
  8874. })(ResizeMode = webgl.ResizeMode || (webgl.ResizeMode = {}));
  8875. })(webgl = spine.webgl || (spine.webgl = {}));
  8876. })(spine || (spine = {}));
  8877. var spine;
  8878. (function (spine) {
  8879. var webgl;
  8880. (function (webgl) {
  8881. var Shader = (function () {
  8882. function Shader(context, vertexShader, fragmentShader) {
  8883. this.vertexShader = vertexShader;
  8884. this.fragmentShader = fragmentShader;
  8885. this.vs = null;
  8886. this.fs = null;
  8887. this.program = null;
  8888. this.tmp2x2 = new Float32Array(2 * 2);
  8889. this.tmp3x3 = new Float32Array(3 * 3);
  8890. this.tmp4x4 = new Float32Array(4 * 4);
  8891. this.vsSource = vertexShader;
  8892. this.fsSource = fragmentShader;
  8893. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8894. this.context.addRestorable(this);
  8895. this.compile();
  8896. }
  8897. Shader.prototype.getProgram = function () { return this.program; };
  8898. Shader.prototype.getVertexShader = function () { return this.vertexShader; };
  8899. Shader.prototype.getFragmentShader = function () { return this.fragmentShader; };
  8900. Shader.prototype.getVertexShaderSource = function () { return this.vsSource; };
  8901. Shader.prototype.getFragmentSource = function () { return this.fsSource; };
  8902. Shader.prototype.compile = function () {
  8903. var gl = this.context.gl;
  8904. try {
  8905. this.vs = this.compileShader(gl.VERTEX_SHADER, this.vertexShader);
  8906. this.fs = this.compileShader(gl.FRAGMENT_SHADER, this.fragmentShader);
  8907. this.program = this.compileProgram(this.vs, this.fs);
  8908. }
  8909. catch (e) {
  8910. this.dispose();
  8911. throw e;
  8912. }
  8913. };
  8914. Shader.prototype.compileShader = function (type, source) {
  8915. var gl = this.context.gl;
  8916. var shader = gl.createShader(type);
  8917. gl.shaderSource(shader, source);
  8918. gl.compileShader(shader);
  8919. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  8920. var error = "Couldn't compile shader: " + gl.getShaderInfoLog(shader);
  8921. gl.deleteShader(shader);
  8922. if (!gl.isContextLost())
  8923. throw new Error(error);
  8924. }
  8925. return shader;
  8926. };
  8927. Shader.prototype.compileProgram = function (vs, fs) {
  8928. var gl = this.context.gl;
  8929. var program = gl.createProgram();
  8930. gl.attachShader(program, vs);
  8931. gl.attachShader(program, fs);
  8932. gl.linkProgram(program);
  8933. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  8934. var error = "Couldn't compile shader program: " + gl.getProgramInfoLog(program);
  8935. gl.deleteProgram(program);
  8936. if (!gl.isContextLost())
  8937. throw new Error(error);
  8938. }
  8939. return program;
  8940. };
  8941. Shader.prototype.restore = function () {
  8942. this.compile();
  8943. };
  8944. Shader.prototype.bind = function () {
  8945. this.context.gl.useProgram(this.program);
  8946. };
  8947. Shader.prototype.unbind = function () {
  8948. this.context.gl.useProgram(null);
  8949. };
  8950. Shader.prototype.setUniformi = function (uniform, value) {
  8951. this.context.gl.uniform1i(this.getUniformLocation(uniform), value);
  8952. };
  8953. Shader.prototype.setUniformf = function (uniform, value) {
  8954. this.context.gl.uniform1f(this.getUniformLocation(uniform), value);
  8955. };
  8956. Shader.prototype.setUniform2f = function (uniform, value, value2) {
  8957. this.context.gl.uniform2f(this.getUniformLocation(uniform), value, value2);
  8958. };
  8959. Shader.prototype.setUniform3f = function (uniform, value, value2, value3) {
  8960. this.context.gl.uniform3f(this.getUniformLocation(uniform), value, value2, value3);
  8961. };
  8962. Shader.prototype.setUniform4f = function (uniform, value, value2, value3, value4) {
  8963. this.context.gl.uniform4f(this.getUniformLocation(uniform), value, value2, value3, value4);
  8964. };
  8965. Shader.prototype.setUniform2x2f = function (uniform, value) {
  8966. var gl = this.context.gl;
  8967. this.tmp2x2.set(value);
  8968. gl.uniformMatrix2fv(this.getUniformLocation(uniform), false, this.tmp2x2);
  8969. };
  8970. Shader.prototype.setUniform3x3f = function (uniform, value) {
  8971. var gl = this.context.gl;
  8972. this.tmp3x3.set(value);
  8973. gl.uniformMatrix3fv(this.getUniformLocation(uniform), false, this.tmp3x3);
  8974. };
  8975. Shader.prototype.setUniform4x4f = function (uniform, value) {
  8976. var gl = this.context.gl;
  8977. this.tmp4x4.set(value);
  8978. gl.uniformMatrix4fv(this.getUniformLocation(uniform), false, this.tmp4x4);
  8979. };
  8980. Shader.prototype.getUniformLocation = function (uniform) {
  8981. var gl = this.context.gl;
  8982. var location = gl.getUniformLocation(this.program, uniform);
  8983. if (!location && !gl.isContextLost())
  8984. throw new Error("Couldn't find location for uniform " + uniform);
  8985. return location;
  8986. };
  8987. Shader.prototype.getAttributeLocation = function (attribute) {
  8988. var gl = this.context.gl;
  8989. var location = gl.getAttribLocation(this.program, attribute);
  8990. if (location == -1 && !gl.isContextLost())
  8991. throw new Error("Couldn't find location for attribute " + attribute);
  8992. return location;
  8993. };
  8994. Shader.prototype.dispose = function () {
  8995. this.context.removeRestorable(this);
  8996. var gl = this.context.gl;
  8997. if (this.vs) {
  8998. gl.deleteShader(this.vs);
  8999. this.vs = null;
  9000. }
  9001. if (this.fs) {
  9002. gl.deleteShader(this.fs);
  9003. this.fs = null;
  9004. }
  9005. if (this.program) {
  9006. gl.deleteProgram(this.program);
  9007. this.program = null;
  9008. }
  9009. };
  9010. Shader.newColoredTextured = function (context) {
  9011. var vs = "\n\t\t\t\tattribute vec4 " + Shader.POSITION + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR + ";\n\t\t\t\tattribute vec2 " + Shader.TEXCOORDS + ";\n\t\t\t\tuniform mat4 " + Shader.MVP_MATRIX + ";\n\t\t\t\tvarying vec4 v_color;\n\t\t\t\tvarying vec2 v_texCoords;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tv_color = " + Shader.COLOR + ";\n\t\t\t\t\tv_texCoords = " + Shader.TEXCOORDS + ";\n\t\t\t\t\tgl_Position = " + Shader.MVP_MATRIX + " * " + Shader.POSITION + ";\n\t\t\t\t}\n\t\t\t";
  9012. var fs = "\n\t\t\t\t#ifdef GL_ES\n\t\t\t\t\t#define LOWP lowp\n\t\t\t\t\tprecision mediump float;\n\t\t\t\t#else\n\t\t\t\t\t#define LOWP\n\t\t\t\t#endif\n\t\t\t\tvarying LOWP vec4 v_color;\n\t\t\t\tvarying vec2 v_texCoords;\n\t\t\t\tuniform sampler2D u_texture;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tgl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n\t\t\t\t}\n\t\t\t";
  9013. return new Shader(context, vs, fs);
  9014. };
  9015. Shader.newTwoColoredTextured = function (context) {
  9016. var vs = "\n\t\t\t\tattribute vec4 " + Shader.POSITION + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR2 + ";\n\t\t\t\tattribute vec2 " + Shader.TEXCOORDS + ";\n\t\t\t\tuniform mat4 " + Shader.MVP_MATRIX + ";\n\t\t\t\tvarying vec4 v_light;\n\t\t\t\tvarying vec4 v_dark;\n\t\t\t\tvarying vec2 v_texCoords;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tv_light = " + Shader.COLOR + ";\n\t\t\t\t\tv_dark = " + Shader.COLOR2 + ";\n\t\t\t\t\tv_texCoords = " + Shader.TEXCOORDS + ";\n\t\t\t\t\tgl_Position = " + Shader.MVP_MATRIX + " * " + Shader.POSITION + ";\n\t\t\t\t}\n\t\t\t";
  9017. var fs = "\n\t\t\t\t#ifdef GL_ES\n\t\t\t\t\t#define LOWP lowp\n\t\t\t\t\tprecision mediump float;\n\t\t\t\t#else\n\t\t\t\t\t#define LOWP\n\t\t\t\t#endif\n\t\t\t\tvarying LOWP vec4 v_light;\n\t\t\t\tvarying LOWP vec4 v_dark;\n\t\t\t\tvarying vec2 v_texCoords;\n\t\t\t\tuniform sampler2D u_texture;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tvec4 texColor = texture2D(u_texture, v_texCoords);\n\t\t\t\t\tgl_FragColor.a = texColor.a * v_light.a;\n\t\t\t\t\tgl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;\n\t\t\t\t}\n\t\t\t";
  9018. return new Shader(context, vs, fs);
  9019. };
  9020. Shader.newColored = function (context) {
  9021. var vs = "\n\t\t\t\tattribute vec4 " + Shader.POSITION + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR + ";\n\t\t\t\tuniform mat4 " + Shader.MVP_MATRIX + ";\n\t\t\t\tvarying vec4 v_color;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tv_color = " + Shader.COLOR + ";\n\t\t\t\t\tgl_Position = " + Shader.MVP_MATRIX + " * " + Shader.POSITION + ";\n\t\t\t\t}\n\t\t\t";
  9022. var fs = "\n\t\t\t\t#ifdef GL_ES\n\t\t\t\t\t#define LOWP lowp\n\t\t\t\t\tprecision mediump float;\n\t\t\t\t#else\n\t\t\t\t\t#define LOWP\n\t\t\t\t#endif\n\t\t\t\tvarying LOWP vec4 v_color;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tgl_FragColor = v_color;\n\t\t\t\t}\n\t\t\t";
  9023. return new Shader(context, vs, fs);
  9024. };
  9025. Shader.MVP_MATRIX = "u_projTrans";
  9026. Shader.POSITION = "a_position";
  9027. Shader.COLOR = "a_color";
  9028. Shader.COLOR2 = "a_color2";
  9029. Shader.TEXCOORDS = "a_texCoords";
  9030. Shader.SAMPLER = "u_texture";
  9031. return Shader;
  9032. }());
  9033. webgl.Shader = Shader;
  9034. })(webgl = spine.webgl || (spine.webgl = {}));
  9035. })(spine || (spine = {}));
  9036. var spine;
  9037. (function (spine) {
  9038. var webgl;
  9039. (function (webgl) {
  9040. var ShapeRenderer = (function () {
  9041. function ShapeRenderer(context, maxVertices) {
  9042. if (maxVertices === void 0) { maxVertices = 10920; }
  9043. this.isDrawing = false;
  9044. this.shapeType = ShapeType.Filled;
  9045. this.color = new spine.Color(1, 1, 1, 1);
  9046. this.vertexIndex = 0;
  9047. this.tmp = new spine.Vector2();
  9048. if (maxVertices > 10920)
  9049. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  9050. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  9051. this.mesh = new webgl.Mesh(context, [new webgl.Position2Attribute(), new webgl.ColorAttribute()], maxVertices, 0);
  9052. this.srcBlend = this.context.gl.SRC_ALPHA;
  9053. this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
  9054. }
  9055. ShapeRenderer.prototype.begin = function (shader) {
  9056. if (this.isDrawing)
  9057. throw new Error("ShapeRenderer.begin() has already been called");
  9058. this.shader = shader;
  9059. this.vertexIndex = 0;
  9060. this.isDrawing = true;
  9061. var gl = this.context.gl;
  9062. gl.enable(gl.BLEND);
  9063. gl.blendFunc(this.srcBlend, this.dstBlend);
  9064. };
  9065. ShapeRenderer.prototype.setBlendMode = function (srcBlend, dstBlend) {
  9066. var gl = this.context.gl;
  9067. this.srcBlend = srcBlend;
  9068. this.dstBlend = dstBlend;
  9069. if (this.isDrawing) {
  9070. this.flush();
  9071. gl.blendFunc(this.srcBlend, this.dstBlend);
  9072. }
  9073. };
  9074. ShapeRenderer.prototype.setColor = function (color) {
  9075. this.color.setFromColor(color);
  9076. };
  9077. ShapeRenderer.prototype.setColorWith = function (r, g, b, a) {
  9078. this.color.set(r, g, b, a);
  9079. };
  9080. ShapeRenderer.prototype.point = function (x, y, color) {
  9081. if (color === void 0) { color = null; }
  9082. this.check(ShapeType.Point, 1);
  9083. if (color === null)
  9084. color = this.color;
  9085. this.vertex(x, y, color);
  9086. };
  9087. ShapeRenderer.prototype.line = function (x, y, x2, y2, color) {
  9088. if (color === void 0) { color = null; }
  9089. this.check(ShapeType.Line, 2);
  9090. var vertices = this.mesh.getVertices();
  9091. var idx = this.vertexIndex;
  9092. if (color === null)
  9093. color = this.color;
  9094. this.vertex(x, y, color);
  9095. this.vertex(x2, y2, color);
  9096. };
  9097. ShapeRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  9098. if (color === void 0) { color = null; }
  9099. if (color2 === void 0) { color2 = null; }
  9100. if (color3 === void 0) { color3 = null; }
  9101. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  9102. var vertices = this.mesh.getVertices();
  9103. var idx = this.vertexIndex;
  9104. if (color === null)
  9105. color = this.color;
  9106. if (color2 === null)
  9107. color2 = this.color;
  9108. if (color3 === null)
  9109. color3 = this.color;
  9110. if (filled) {
  9111. this.vertex(x, y, color);
  9112. this.vertex(x2, y2, color2);
  9113. this.vertex(x3, y3, color3);
  9114. }
  9115. else {
  9116. this.vertex(x, y, color);
  9117. this.vertex(x2, y2, color2);
  9118. this.vertex(x2, y2, color);
  9119. this.vertex(x3, y3, color2);
  9120. this.vertex(x3, y3, color);
  9121. this.vertex(x, y, color2);
  9122. }
  9123. };
  9124. ShapeRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  9125. if (color === void 0) { color = null; }
  9126. if (color2 === void 0) { color2 = null; }
  9127. if (color3 === void 0) { color3 = null; }
  9128. if (color4 === void 0) { color4 = null; }
  9129. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  9130. var vertices = this.mesh.getVertices();
  9131. var idx = this.vertexIndex;
  9132. if (color === null)
  9133. color = this.color;
  9134. if (color2 === null)
  9135. color2 = this.color;
  9136. if (color3 === null)
  9137. color3 = this.color;
  9138. if (color4 === null)
  9139. color4 = this.color;
  9140. if (filled) {
  9141. this.vertex(x, y, color);
  9142. this.vertex(x2, y2, color2);
  9143. this.vertex(x3, y3, color3);
  9144. this.vertex(x3, y3, color3);
  9145. this.vertex(x4, y4, color4);
  9146. this.vertex(x, y, color);
  9147. }
  9148. else {
  9149. this.vertex(x, y, color);
  9150. this.vertex(x2, y2, color2);
  9151. this.vertex(x2, y2, color2);
  9152. this.vertex(x3, y3, color3);
  9153. this.vertex(x3, y3, color3);
  9154. this.vertex(x4, y4, color4);
  9155. this.vertex(x4, y4, color4);
  9156. this.vertex(x, y, color);
  9157. }
  9158. };
  9159. ShapeRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  9160. if (color === void 0) { color = null; }
  9161. this.quad(filled, x, y, x + width, y, x + width, y + height, x, y + height, color, color, color, color);
  9162. };
  9163. ShapeRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  9164. if (color === void 0) { color = null; }
  9165. this.check(filled ? ShapeType.Filled : ShapeType.Line, 8);
  9166. if (color === null)
  9167. color = this.color;
  9168. var t = this.tmp.set(y2 - y1, x1 - x2);
  9169. t.normalize();
  9170. width *= 0.5;
  9171. var tx = t.x * width;
  9172. var ty = t.y * width;
  9173. if (!filled) {
  9174. this.vertex(x1 + tx, y1 + ty, color);
  9175. this.vertex(x1 - tx, y1 - ty, color);
  9176. this.vertex(x2 + tx, y2 + ty, color);
  9177. this.vertex(x2 - tx, y2 - ty, color);
  9178. this.vertex(x2 + tx, y2 + ty, color);
  9179. this.vertex(x1 + tx, y1 + ty, color);
  9180. this.vertex(x2 - tx, y2 - ty, color);
  9181. this.vertex(x1 - tx, y1 - ty, color);
  9182. }
  9183. else {
  9184. this.vertex(x1 + tx, y1 + ty, color);
  9185. this.vertex(x1 - tx, y1 - ty, color);
  9186. this.vertex(x2 + tx, y2 + ty, color);
  9187. this.vertex(x2 - tx, y2 - ty, color);
  9188. this.vertex(x2 + tx, y2 + ty, color);
  9189. this.vertex(x1 - tx, y1 - ty, color);
  9190. }
  9191. };
  9192. ShapeRenderer.prototype.x = function (x, y, size) {
  9193. this.line(x - size, y - size, x + size, y + size);
  9194. this.line(x - size, y + size, x + size, y - size);
  9195. };
  9196. ShapeRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  9197. if (color === void 0) { color = null; }
  9198. if (count < 3)
  9199. throw new Error("Polygon must contain at least 3 vertices");
  9200. this.check(ShapeType.Line, count * 2);
  9201. if (color === null)
  9202. color = this.color;
  9203. var vertices = this.mesh.getVertices();
  9204. var idx = this.vertexIndex;
  9205. offset <<= 1;
  9206. count <<= 1;
  9207. var firstX = polygonVertices[offset];
  9208. var firstY = polygonVertices[offset + 1];
  9209. var last = offset + count;
  9210. for (var i = offset, n = offset + count - 2; i < n; i += 2) {
  9211. var x1 = polygonVertices[i];
  9212. var y1 = polygonVertices[i + 1];
  9213. var x2 = 0;
  9214. var y2 = 0;
  9215. if (i + 2 >= last) {
  9216. x2 = firstX;
  9217. y2 = firstY;
  9218. }
  9219. else {
  9220. x2 = polygonVertices[i + 2];
  9221. y2 = polygonVertices[i + 3];
  9222. }
  9223. this.vertex(x1, y1, color);
  9224. this.vertex(x2, y2, color);
  9225. }
  9226. };
  9227. ShapeRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  9228. if (color === void 0) { color = null; }
  9229. if (segments === void 0) { segments = 0; }
  9230. if (segments === 0)
  9231. segments = Math.max(1, (6 * spine.MathUtils.cbrt(radius)) | 0);
  9232. if (segments <= 0)
  9233. throw new Error("segments must be > 0.");
  9234. if (color === null)
  9235. color = this.color;
  9236. var angle = 2 * spine.MathUtils.PI / segments;
  9237. var cos = Math.cos(angle);
  9238. var sin = Math.sin(angle);
  9239. var cx = radius, cy = 0;
  9240. if (!filled) {
  9241. this.check(ShapeType.Line, segments * 2 + 2);
  9242. for (var i = 0; i < segments; i++) {
  9243. this.vertex(x + cx, y + cy, color);
  9244. var temp_1 = cx;
  9245. cx = cos * cx - sin * cy;
  9246. cy = sin * temp_1 + cos * cy;
  9247. this.vertex(x + cx, y + cy, color);
  9248. }
  9249. this.vertex(x + cx, y + cy, color);
  9250. }
  9251. else {
  9252. this.check(ShapeType.Filled, segments * 3 + 3);
  9253. segments--;
  9254. for (var i = 0; i < segments; i++) {
  9255. this.vertex(x, y, color);
  9256. this.vertex(x + cx, y + cy, color);
  9257. var temp_2 = cx;
  9258. cx = cos * cx - sin * cy;
  9259. cy = sin * temp_2 + cos * cy;
  9260. this.vertex(x + cx, y + cy, color);
  9261. }
  9262. this.vertex(x, y, color);
  9263. this.vertex(x + cx, y + cy, color);
  9264. }
  9265. var temp = cx;
  9266. cx = radius;
  9267. cy = 0;
  9268. this.vertex(x + cx, y + cy, color);
  9269. };
  9270. ShapeRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  9271. if (color === void 0) { color = null; }
  9272. this.check(ShapeType.Line, segments * 2 + 2);
  9273. if (color === null)
  9274. color = this.color;
  9275. var subdiv_step = 1 / segments;
  9276. var subdiv_step2 = subdiv_step * subdiv_step;
  9277. var subdiv_step3 = subdiv_step * subdiv_step * subdiv_step;
  9278. var pre1 = 3 * subdiv_step;
  9279. var pre2 = 3 * subdiv_step2;
  9280. var pre4 = 6 * subdiv_step2;
  9281. var pre5 = 6 * subdiv_step3;
  9282. var tmp1x = x1 - cx1 * 2 + cx2;
  9283. var tmp1y = y1 - cy1 * 2 + cy2;
  9284. var tmp2x = (cx1 - cx2) * 3 - x1 + x2;
  9285. var tmp2y = (cy1 - cy2) * 3 - y1 + y2;
  9286. var fx = x1;
  9287. var fy = y1;
  9288. var dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
  9289. var dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
  9290. var ddfx = tmp1x * pre4 + tmp2x * pre5;
  9291. var ddfy = tmp1y * pre4 + tmp2y * pre5;
  9292. var dddfx = tmp2x * pre5;
  9293. var dddfy = tmp2y * pre5;
  9294. while (segments-- > 0) {
  9295. this.vertex(fx, fy, color);
  9296. fx += dfx;
  9297. fy += dfy;
  9298. dfx += ddfx;
  9299. dfy += ddfy;
  9300. ddfx += dddfx;
  9301. ddfy += dddfy;
  9302. this.vertex(fx, fy, color);
  9303. }
  9304. this.vertex(fx, fy, color);
  9305. this.vertex(x2, y2, color);
  9306. };
  9307. ShapeRenderer.prototype.vertex = function (x, y, color) {
  9308. var idx = this.vertexIndex;
  9309. var vertices = this.mesh.getVertices();
  9310. vertices[idx++] = x;
  9311. vertices[idx++] = y;
  9312. vertices[idx++] = color.r;
  9313. vertices[idx++] = color.g;
  9314. vertices[idx++] = color.b;
  9315. vertices[idx++] = color.a;
  9316. this.vertexIndex = idx;
  9317. };
  9318. ShapeRenderer.prototype.end = function () {
  9319. if (!this.isDrawing)
  9320. throw new Error("ShapeRenderer.begin() has not been called");
  9321. this.flush();
  9322. this.context.gl.disable(this.context.gl.BLEND);
  9323. this.isDrawing = false;
  9324. };
  9325. ShapeRenderer.prototype.flush = function () {
  9326. if (this.vertexIndex == 0)
  9327. return;
  9328. this.mesh.setVerticesLength(this.vertexIndex);
  9329. this.mesh.draw(this.shader, this.shapeType);
  9330. this.vertexIndex = 0;
  9331. };
  9332. ShapeRenderer.prototype.check = function (shapeType, numVertices) {
  9333. if (!this.isDrawing)
  9334. throw new Error("ShapeRenderer.begin() has not been called");
  9335. if (this.shapeType == shapeType) {
  9336. if (this.mesh.maxVertices() - this.mesh.numVertices() < numVertices)
  9337. this.flush();
  9338. else
  9339. return;
  9340. }
  9341. else {
  9342. this.flush();
  9343. this.shapeType = shapeType;
  9344. }
  9345. };
  9346. ShapeRenderer.prototype.dispose = function () {
  9347. this.mesh.dispose();
  9348. };
  9349. return ShapeRenderer;
  9350. }());
  9351. webgl.ShapeRenderer = ShapeRenderer;
  9352. var ShapeType;
  9353. (function (ShapeType) {
  9354. ShapeType[ShapeType["Point"] = 0] = "Point";
  9355. ShapeType[ShapeType["Line"] = 1] = "Line";
  9356. ShapeType[ShapeType["Filled"] = 4] = "Filled";
  9357. })(ShapeType = webgl.ShapeType || (webgl.ShapeType = {}));
  9358. })(webgl = spine.webgl || (spine.webgl = {}));
  9359. })(spine || (spine = {}));
  9360. var spine;
  9361. (function (spine) {
  9362. var webgl;
  9363. (function (webgl) {
  9364. var SkeletonDebugRenderer = (function () {
  9365. function SkeletonDebugRenderer(context) {
  9366. this.boneLineColor = new spine.Color(1, 0, 0, 1);
  9367. this.boneOriginColor = new spine.Color(0, 1, 0, 1);
  9368. this.attachmentLineColor = new spine.Color(0, 0, 1, 0.5);
  9369. this.triangleLineColor = new spine.Color(1, 0.64, 0, 0.5);
  9370. this.pathColor = new spine.Color().setFromString("FF7F00");
  9371. this.clipColor = new spine.Color(0.8, 0, 0, 2);
  9372. this.aabbColor = new spine.Color(0, 1, 0, 0.5);
  9373. this.drawBones = true;
  9374. this.drawRegionAttachments = true;
  9375. this.drawBoundingBoxes = true;
  9376. this.drawMeshHull = true;
  9377. this.drawMeshTriangles = true;
  9378. this.drawPaths = true;
  9379. this.drawSkeletonXY = false;
  9380. this.drawClipping = true;
  9381. this.premultipliedAlpha = false;
  9382. this.scale = 1;
  9383. this.boneWidth = 2;
  9384. this.bounds = new spine.SkeletonBounds();
  9385. this.temp = new Array();
  9386. this.vertices = spine.Utils.newFloatArray(2 * 1024);
  9387. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  9388. }
  9389. SkeletonDebugRenderer.prototype.draw = function (shapes, skeleton, ignoredBones) {
  9390. if (ignoredBones === void 0) { ignoredBones = null; }
  9391. var skeletonX = skeleton.x;
  9392. var skeletonY = skeleton.y;
  9393. var gl = this.context.gl;
  9394. var srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA;
  9395. shapes.setBlendMode(srcFunc, gl.ONE_MINUS_SRC_ALPHA);
  9396. var bones = skeleton.bones;
  9397. if (this.drawBones) {
  9398. shapes.setColor(this.boneLineColor);
  9399. for (var i = 0, n = bones.length; i < n; i++) {
  9400. var bone = bones[i];
  9401. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  9402. continue;
  9403. if (bone.parent == null)
  9404. continue;
  9405. var x = skeletonX + bone.data.length * bone.a + bone.worldX;
  9406. var y = skeletonY + bone.data.length * bone.c + bone.worldY;
  9407. shapes.rectLine(true, skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, this.boneWidth * this.scale);
  9408. }
  9409. if (this.drawSkeletonXY)
  9410. shapes.x(skeletonX, skeletonY, 4 * this.scale);
  9411. }
  9412. if (this.drawRegionAttachments) {
  9413. shapes.setColor(this.attachmentLineColor);
  9414. var slots = skeleton.slots;
  9415. for (var i = 0, n = slots.length; i < n; i++) {
  9416. var slot = slots[i];
  9417. var attachment = slot.getAttachment();
  9418. if (attachment instanceof spine.RegionAttachment) {
  9419. var regionAttachment = attachment;
  9420. var vertices = this.vertices;
  9421. regionAttachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  9422. shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]);
  9423. shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]);
  9424. shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]);
  9425. shapes.line(vertices[6], vertices[7], vertices[0], vertices[1]);
  9426. }
  9427. }
  9428. }
  9429. if (this.drawMeshHull || this.drawMeshTriangles) {
  9430. var slots = skeleton.slots;
  9431. for (var i = 0, n = slots.length; i < n; i++) {
  9432. var slot = slots[i];
  9433. var attachment = slot.getAttachment();
  9434. if (!(attachment instanceof spine.MeshAttachment))
  9435. continue;
  9436. var mesh = attachment;
  9437. var vertices = this.vertices;
  9438. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 2);
  9439. var triangles = mesh.triangles;
  9440. var hullLength = mesh.hullLength;
  9441. if (this.drawMeshTriangles) {
  9442. shapes.setColor(this.triangleLineColor);
  9443. for (var ii = 0, nn = triangles.length; ii < nn; ii += 3) {
  9444. var v1 = triangles[ii] * 2, v2 = triangles[ii + 1] * 2, v3 = triangles[ii + 2] * 2;
  9445. shapes.triangle(false, vertices[v1], vertices[v1 + 1], vertices[v2], vertices[v2 + 1], vertices[v3], vertices[v3 + 1]);
  9446. }
  9447. }
  9448. if (this.drawMeshHull && hullLength > 0) {
  9449. shapes.setColor(this.attachmentLineColor);
  9450. hullLength = (hullLength >> 1) * 2;
  9451. var lastX = vertices[hullLength - 2], lastY = vertices[hullLength - 1];
  9452. for (var ii = 0, nn = hullLength; ii < nn; ii += 2) {
  9453. var x = vertices[ii], y = vertices[ii + 1];
  9454. shapes.line(x, y, lastX, lastY);
  9455. lastX = x;
  9456. lastY = y;
  9457. }
  9458. }
  9459. }
  9460. }
  9461. if (this.drawBoundingBoxes) {
  9462. var bounds = this.bounds;
  9463. bounds.update(skeleton, true);
  9464. shapes.setColor(this.aabbColor);
  9465. shapes.rect(false, bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight());
  9466. var polygons = bounds.polygons;
  9467. var boxes = bounds.boundingBoxes;
  9468. for (var i = 0, n = polygons.length; i < n; i++) {
  9469. var polygon = polygons[i];
  9470. shapes.setColor(boxes[i].color);
  9471. shapes.polygon(polygon, 0, polygon.length);
  9472. }
  9473. }
  9474. if (this.drawPaths) {
  9475. var slots = skeleton.slots;
  9476. for (var i = 0, n = slots.length; i < n; i++) {
  9477. var slot = slots[i];
  9478. var attachment = slot.getAttachment();
  9479. if (!(attachment instanceof spine.PathAttachment))
  9480. continue;
  9481. var path = attachment;
  9482. var nn = path.worldVerticesLength;
  9483. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  9484. path.computeWorldVertices(slot, 0, nn, world, 0, 2);
  9485. var color = this.pathColor;
  9486. var x1 = world[2], y1 = world[3], x2 = 0, y2 = 0;
  9487. if (path.closed) {
  9488. shapes.setColor(color);
  9489. var cx1 = world[0], cy1 = world[1], cx2 = world[nn - 2], cy2 = world[nn - 1];
  9490. x2 = world[nn - 4];
  9491. y2 = world[nn - 3];
  9492. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  9493. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  9494. shapes.line(x1, y1, cx1, cy1);
  9495. shapes.line(x2, y2, cx2, cy2);
  9496. }
  9497. nn -= 4;
  9498. for (var ii = 4; ii < nn; ii += 6) {
  9499. var cx1 = world[ii], cy1 = world[ii + 1], cx2 = world[ii + 2], cy2 = world[ii + 3];
  9500. x2 = world[ii + 4];
  9501. y2 = world[ii + 5];
  9502. shapes.setColor(color);
  9503. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  9504. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  9505. shapes.line(x1, y1, cx1, cy1);
  9506. shapes.line(x2, y2, cx2, cy2);
  9507. x1 = x2;
  9508. y1 = y2;
  9509. }
  9510. }
  9511. }
  9512. if (this.drawBones) {
  9513. shapes.setColor(this.boneOriginColor);
  9514. for (var i = 0, n = bones.length; i < n; i++) {
  9515. var bone = bones[i];
  9516. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  9517. continue;
  9518. shapes.circle(true, skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * this.scale, SkeletonDebugRenderer.GREEN, 8);
  9519. }
  9520. }
  9521. if (this.drawClipping) {
  9522. var slots = skeleton.slots;
  9523. shapes.setColor(this.clipColor);
  9524. for (var i = 0, n = slots.length; i < n; i++) {
  9525. var slot = slots[i];
  9526. var attachment = slot.getAttachment();
  9527. if (!(attachment instanceof spine.ClippingAttachment))
  9528. continue;
  9529. var clip = attachment;
  9530. var nn = clip.worldVerticesLength;
  9531. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  9532. clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
  9533. for (var i_21 = 0, n_2 = world.length; i_21 < n_2; i_21 += 2) {
  9534. var x = world[i_21];
  9535. var y = world[i_21 + 1];
  9536. var x2 = world[(i_21 + 2) % world.length];
  9537. var y2 = world[(i_21 + 3) % world.length];
  9538. shapes.line(x, y, x2, y2);
  9539. }
  9540. }
  9541. }
  9542. };
  9543. SkeletonDebugRenderer.prototype.dispose = function () {
  9544. };
  9545. SkeletonDebugRenderer.LIGHT_GRAY = new spine.Color(192 / 255, 192 / 255, 192 / 255, 1);
  9546. SkeletonDebugRenderer.GREEN = new spine.Color(0, 1, 0, 1);
  9547. return SkeletonDebugRenderer;
  9548. }());
  9549. webgl.SkeletonDebugRenderer = SkeletonDebugRenderer;
  9550. })(webgl = spine.webgl || (spine.webgl = {}));
  9551. })(spine || (spine = {}));
  9552. var spine;
  9553. (function (spine) {
  9554. var webgl;
  9555. (function (webgl) {
  9556. var Renderable = (function () {
  9557. function Renderable(vertices, numVertices, numFloats) {
  9558. this.vertices = vertices;
  9559. this.numVertices = numVertices;
  9560. this.numFloats = numFloats;
  9561. }
  9562. return Renderable;
  9563. }());
  9564. ;
  9565. var SkeletonRenderer = (function () {
  9566. function SkeletonRenderer(context, twoColorTint) {
  9567. if (twoColorTint === void 0) { twoColorTint = true; }
  9568. this.premultipliedAlpha = false;
  9569. this.vertexEffect = null;
  9570. this.tempColor = new spine.Color();
  9571. this.tempColor2 = new spine.Color();
  9572. this.vertexSize = 2 + 2 + 4;
  9573. this.twoColorTint = false;
  9574. this.renderable = new Renderable(null, 0, 0);
  9575. this.clipper = new spine.SkeletonClipping();
  9576. this.temp = new spine.Vector2();
  9577. this.temp2 = new spine.Vector2();
  9578. this.temp3 = new spine.Color();
  9579. this.temp4 = new spine.Color();
  9580. this.twoColorTint = twoColorTint;
  9581. if (twoColorTint)
  9582. this.vertexSize += 4;
  9583. this.vertices = spine.Utils.newFloatArray(this.vertexSize * 1024);
  9584. }
  9585. SkeletonRenderer.prototype.draw = function (batcher, skeleton, slotRangeStart, slotRangeEnd) {
  9586. if (slotRangeStart === void 0) { slotRangeStart = -1; }
  9587. if (slotRangeEnd === void 0) { slotRangeEnd = -1; }
  9588. var clipper = this.clipper;
  9589. var premultipliedAlpha = this.premultipliedAlpha;
  9590. var twoColorTint = this.twoColorTint;
  9591. var blendMode = null;
  9592. var tempPos = this.temp;
  9593. var tempUv = this.temp2;
  9594. var tempLight = this.temp3;
  9595. var tempDark = this.temp4;
  9596. var renderable = this.renderable;
  9597. var uvs = null;
  9598. var triangles = null;
  9599. var drawOrder = skeleton.drawOrder;
  9600. var attachmentColor = null;
  9601. var skeletonColor = skeleton.color;
  9602. var vertexSize = twoColorTint ? 12 : 8;
  9603. var inRange = false;
  9604. if (slotRangeStart == -1)
  9605. inRange = true;
  9606. for (var i = 0, n = drawOrder.length; i < n; i++) {
  9607. var clippedVertexSize = clipper.isClipping() ? 2 : vertexSize;
  9608. var slot = drawOrder[i];
  9609. if (slotRangeStart >= 0 && slotRangeStart == slot.data.index) {
  9610. inRange = true;
  9611. }
  9612. if (!inRange) {
  9613. clipper.clipEndWithSlot(slot);
  9614. continue;
  9615. }
  9616. if (slotRangeEnd >= 0 && slotRangeEnd == slot.data.index) {
  9617. inRange = false;
  9618. }
  9619. var attachment = slot.getAttachment();
  9620. var texture = null;
  9621. if (attachment instanceof spine.RegionAttachment) {
  9622. var region = attachment;
  9623. renderable.vertices = this.vertices;
  9624. renderable.numVertices = 4;
  9625. renderable.numFloats = clippedVertexSize << 2;
  9626. region.computeWorldVertices(slot.bone, renderable.vertices, 0, clippedVertexSize);
  9627. triangles = SkeletonRenderer.QUAD_TRIANGLES;
  9628. uvs = region.uvs;
  9629. texture = region.region.renderObject.texture;
  9630. attachmentColor = region.color;
  9631. }
  9632. else if (attachment instanceof spine.MeshAttachment) {
  9633. var mesh = attachment;
  9634. renderable.vertices = this.vertices;
  9635. renderable.numVertices = (mesh.worldVerticesLength >> 1);
  9636. renderable.numFloats = renderable.numVertices * clippedVertexSize;
  9637. if (renderable.numFloats > renderable.vertices.length) {
  9638. renderable.vertices = this.vertices = spine.Utils.newFloatArray(renderable.numFloats);
  9639. }
  9640. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, renderable.vertices, 0, clippedVertexSize);
  9641. triangles = mesh.triangles;
  9642. texture = mesh.region.renderObject.texture;
  9643. uvs = mesh.uvs;
  9644. attachmentColor = mesh.color;
  9645. }
  9646. else if (attachment instanceof spine.ClippingAttachment) {
  9647. var clip = (attachment);
  9648. clipper.clipStart(slot, clip);
  9649. continue;
  9650. }
  9651. else
  9652. continue;
  9653. if (texture != null) {
  9654. var slotColor = slot.color;
  9655. var finalColor = this.tempColor;
  9656. finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
  9657. finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
  9658. finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
  9659. finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
  9660. if (premultipliedAlpha) {
  9661. finalColor.r *= finalColor.a;
  9662. finalColor.g *= finalColor.a;
  9663. finalColor.b *= finalColor.a;
  9664. }
  9665. var darkColor = this.tempColor2;
  9666. if (slot.darkColor == null)
  9667. darkColor.set(0, 0, 0, 1.0);
  9668. else {
  9669. if (premultipliedAlpha) {
  9670. darkColor.r = slot.darkColor.r * finalColor.a;
  9671. darkColor.g = slot.darkColor.g * finalColor.a;
  9672. darkColor.b = slot.darkColor.b * finalColor.a;
  9673. }
  9674. else {
  9675. darkColor.setFromColor(slot.darkColor);
  9676. }
  9677. darkColor.a = premultipliedAlpha ? 1.0 : 0.0;
  9678. }
  9679. var slotBlendMode = slot.data.blendMode;
  9680. if (slotBlendMode != blendMode) {
  9681. blendMode = slotBlendMode;
  9682. batcher.setBlendMode(webgl.WebGLBlendModeConverter.getSourceGLBlendMode(blendMode, premultipliedAlpha), webgl.WebGLBlendModeConverter.getDestGLBlendMode(blendMode));
  9683. }
  9684. if (clipper.isClipping()) {
  9685. clipper.clipTriangles(renderable.vertices, renderable.numFloats, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint);
  9686. var clippedVertices = new Float32Array(clipper.clippedVertices);
  9687. var clippedTriangles = clipper.clippedTriangles;
  9688. if (this.vertexEffect != null) {
  9689. var vertexEffect = this.vertexEffect;
  9690. var verts = clippedVertices;
  9691. if (!twoColorTint) {
  9692. for (var v = 0, n_3 = clippedVertices.length; v < n_3; v += vertexSize) {
  9693. tempPos.x = verts[v];
  9694. tempPos.y = verts[v + 1];
  9695. tempLight.set(verts[v + 2], verts[v + 3], verts[v + 4], verts[v + 5]);
  9696. tempUv.x = verts[v + 6];
  9697. tempUv.y = verts[v + 7];
  9698. tempDark.set(0, 0, 0, 0);
  9699. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  9700. verts[v] = tempPos.x;
  9701. verts[v + 1] = tempPos.y;
  9702. verts[v + 2] = tempLight.r;
  9703. verts[v + 3] = tempLight.g;
  9704. verts[v + 4] = tempLight.b;
  9705. verts[v + 5] = tempLight.a;
  9706. verts[v + 6] = tempUv.x;
  9707. verts[v + 7] = tempUv.y;
  9708. }
  9709. }
  9710. else {
  9711. for (var v = 0, n_4 = clippedVertices.length; v < n_4; v += vertexSize) {
  9712. tempPos.x = verts[v];
  9713. tempPos.y = verts[v + 1];
  9714. tempLight.set(verts[v + 2], verts[v + 3], verts[v + 4], verts[v + 5]);
  9715. tempUv.x = verts[v + 6];
  9716. tempUv.y = verts[v + 7];
  9717. tempDark.set(verts[v + 8], verts[v + 9], verts[v + 10], verts[v + 11]);
  9718. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  9719. verts[v] = tempPos.x;
  9720. verts[v + 1] = tempPos.y;
  9721. verts[v + 2] = tempLight.r;
  9722. verts[v + 3] = tempLight.g;
  9723. verts[v + 4] = tempLight.b;
  9724. verts[v + 5] = tempLight.a;
  9725. verts[v + 6] = tempUv.x;
  9726. verts[v + 7] = tempUv.y;
  9727. verts[v + 8] = tempDark.r;
  9728. verts[v + 9] = tempDark.g;
  9729. verts[v + 10] = tempDark.b;
  9730. verts[v + 11] = tempDark.a;
  9731. }
  9732. }
  9733. }
  9734. batcher.draw(texture, clippedVertices, clippedTriangles);
  9735. }
  9736. else {
  9737. var verts = renderable.vertices;
  9738. if (this.vertexEffect != null) {
  9739. var vertexEffect = this.vertexEffect;
  9740. if (!twoColorTint) {
  9741. for (var v = 0, u = 0, n_5 = renderable.numFloats; v < n_5; v += vertexSize, u += 2) {
  9742. tempPos.x = verts[v];
  9743. tempPos.y = verts[v + 1];
  9744. tempUv.x = uvs[u];
  9745. tempUv.y = uvs[u + 1];
  9746. tempLight.setFromColor(finalColor);
  9747. tempDark.set(0, 0, 0, 0);
  9748. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  9749. verts[v] = tempPos.x;
  9750. verts[v + 1] = tempPos.y;
  9751. verts[v + 2] = tempLight.r;
  9752. verts[v + 3] = tempLight.g;
  9753. verts[v + 4] = tempLight.b;
  9754. verts[v + 5] = tempLight.a;
  9755. verts[v + 6] = tempUv.x;
  9756. verts[v + 7] = tempUv.y;
  9757. }
  9758. }
  9759. else {
  9760. for (var v = 0, u = 0, n_6 = renderable.numFloats; v < n_6; v += vertexSize, u += 2) {
  9761. tempPos.x = verts[v];
  9762. tempPos.y = verts[v + 1];
  9763. tempUv.x = uvs[u];
  9764. tempUv.y = uvs[u + 1];
  9765. tempLight.setFromColor(finalColor);
  9766. tempDark.setFromColor(darkColor);
  9767. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  9768. verts[v] = tempPos.x;
  9769. verts[v + 1] = tempPos.y;
  9770. verts[v + 2] = tempLight.r;
  9771. verts[v + 3] = tempLight.g;
  9772. verts[v + 4] = tempLight.b;
  9773. verts[v + 5] = tempLight.a;
  9774. verts[v + 6] = tempUv.x;
  9775. verts[v + 7] = tempUv.y;
  9776. verts[v + 8] = tempDark.r;
  9777. verts[v + 9] = tempDark.g;
  9778. verts[v + 10] = tempDark.b;
  9779. verts[v + 11] = tempDark.a;
  9780. }
  9781. }
  9782. }
  9783. else {
  9784. if (!twoColorTint) {
  9785. for (var v = 2, u = 0, n_7 = renderable.numFloats; v < n_7; v += vertexSize, u += 2) {
  9786. verts[v] = finalColor.r;
  9787. verts[v + 1] = finalColor.g;
  9788. verts[v + 2] = finalColor.b;
  9789. verts[v + 3] = finalColor.a;
  9790. verts[v + 4] = uvs[u];
  9791. verts[v + 5] = uvs[u + 1];
  9792. }
  9793. }
  9794. else {
  9795. for (var v = 2, u = 0, n_8 = renderable.numFloats; v < n_8; v += vertexSize, u += 2) {
  9796. verts[v] = finalColor.r;
  9797. verts[v + 1] = finalColor.g;
  9798. verts[v + 2] = finalColor.b;
  9799. verts[v + 3] = finalColor.a;
  9800. verts[v + 4] = uvs[u];
  9801. verts[v + 5] = uvs[u + 1];
  9802. verts[v + 6] = darkColor.r;
  9803. verts[v + 7] = darkColor.g;
  9804. verts[v + 8] = darkColor.b;
  9805. verts[v + 9] = darkColor.a;
  9806. }
  9807. }
  9808. }
  9809. var view = renderable.vertices.subarray(0, renderable.numFloats);
  9810. batcher.draw(texture, view, triangles);
  9811. }
  9812. }
  9813. clipper.clipEndWithSlot(slot);
  9814. }
  9815. clipper.clipEnd();
  9816. };
  9817. SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  9818. return SkeletonRenderer;
  9819. }());
  9820. webgl.SkeletonRenderer = SkeletonRenderer;
  9821. })(webgl = spine.webgl || (spine.webgl = {}));
  9822. })(spine || (spine = {}));
  9823. var spine;
  9824. (function (spine) {
  9825. var webgl;
  9826. (function (webgl) {
  9827. var Vector3 = (function () {
  9828. function Vector3(x, y, z) {
  9829. if (x === void 0) { x = 0; }
  9830. if (y === void 0) { y = 0; }
  9831. if (z === void 0) { z = 0; }
  9832. this.x = 0;
  9833. this.y = 0;
  9834. this.z = 0;
  9835. this.x = x;
  9836. this.y = y;
  9837. this.z = z;
  9838. }
  9839. Vector3.prototype.setFrom = function (v) {
  9840. this.x = v.x;
  9841. this.y = v.y;
  9842. this.z = v.z;
  9843. return this;
  9844. };
  9845. Vector3.prototype.set = function (x, y, z) {
  9846. this.x = x;
  9847. this.y = y;
  9848. this.z = z;
  9849. return this;
  9850. };
  9851. Vector3.prototype.add = function (v) {
  9852. this.x += v.x;
  9853. this.y += v.y;
  9854. this.z += v.z;
  9855. return this;
  9856. };
  9857. Vector3.prototype.sub = function (v) {
  9858. this.x -= v.x;
  9859. this.y -= v.y;
  9860. this.z -= v.z;
  9861. return this;
  9862. };
  9863. Vector3.prototype.scale = function (s) {
  9864. this.x *= s;
  9865. this.y *= s;
  9866. this.z *= s;
  9867. return this;
  9868. };
  9869. Vector3.prototype.normalize = function () {
  9870. var len = this.length();
  9871. if (len == 0)
  9872. return this;
  9873. len = 1 / len;
  9874. this.x *= len;
  9875. this.y *= len;
  9876. this.z *= len;
  9877. return this;
  9878. };
  9879. Vector3.prototype.cross = function (v) {
  9880. return this.set(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
  9881. };
  9882. Vector3.prototype.multiply = function (matrix) {
  9883. var l_mat = matrix.values;
  9884. return this.set(this.x * l_mat[webgl.M00] + this.y * l_mat[webgl.M01] + this.z * l_mat[webgl.M02] + l_mat[webgl.M03], this.x * l_mat[webgl.M10] + this.y * l_mat[webgl.M11] + this.z * l_mat[webgl.M12] + l_mat[webgl.M13], this.x * l_mat[webgl.M20] + this.y * l_mat[webgl.M21] + this.z * l_mat[webgl.M22] + l_mat[webgl.M23]);
  9885. };
  9886. Vector3.prototype.project = function (matrix) {
  9887. var l_mat = matrix.values;
  9888. var l_w = 1 / (this.x * l_mat[webgl.M30] + this.y * l_mat[webgl.M31] + this.z * l_mat[webgl.M32] + l_mat[webgl.M33]);
  9889. return this.set((this.x * l_mat[webgl.M00] + this.y * l_mat[webgl.M01] + this.z * l_mat[webgl.M02] + l_mat[webgl.M03]) * l_w, (this.x * l_mat[webgl.M10] + this.y * l_mat[webgl.M11] + this.z * l_mat[webgl.M12] + l_mat[webgl.M13]) * l_w, (this.x * l_mat[webgl.M20] + this.y * l_mat[webgl.M21] + this.z * l_mat[webgl.M22] + l_mat[webgl.M23]) * l_w);
  9890. };
  9891. Vector3.prototype.dot = function (v) {
  9892. return this.x * v.x + this.y * v.y + this.z * v.z;
  9893. };
  9894. Vector3.prototype.length = function () {
  9895. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  9896. };
  9897. Vector3.prototype.distance = function (v) {
  9898. var a = v.x - this.x;
  9899. var b = v.y - this.y;
  9900. var c = v.z - this.z;
  9901. return Math.sqrt(a * a + b * b + c * c);
  9902. };
  9903. return Vector3;
  9904. }());
  9905. webgl.Vector3 = Vector3;
  9906. })(webgl = spine.webgl || (spine.webgl = {}));
  9907. })(spine || (spine = {}));
  9908. var spine;
  9909. (function (spine) {
  9910. var webgl;
  9911. (function (webgl) {
  9912. var ManagedWebGLRenderingContext = (function () {
  9913. function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) {
  9914. if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
  9915. var _this = this;
  9916. this.restorables = new Array();
  9917. if (canvasOrContext instanceof HTMLCanvasElement) {
  9918. var canvas = canvasOrContext;
  9919. this.gl = (canvas.getContext("webgl", contextConfig) || canvas.getContext("experimental-webgl", contextConfig));
  9920. this.canvas = canvas;
  9921. canvas.addEventListener("webglcontextlost", function (e) {
  9922. var event = e;
  9923. if (e) {
  9924. e.preventDefault();
  9925. }
  9926. });
  9927. canvas.addEventListener("webglcontextrestored", function (e) {
  9928. for (var i = 0, n = _this.restorables.length; i < n; i++) {
  9929. _this.restorables[i].restore();
  9930. }
  9931. });
  9932. }
  9933. else {
  9934. this.gl = canvasOrContext;
  9935. this.canvas = this.gl.canvas;
  9936. }
  9937. }
  9938. ManagedWebGLRenderingContext.prototype.addRestorable = function (restorable) {
  9939. this.restorables.push(restorable);
  9940. };
  9941. ManagedWebGLRenderingContext.prototype.removeRestorable = function (restorable) {
  9942. var index = this.restorables.indexOf(restorable);
  9943. if (index > -1)
  9944. this.restorables.splice(index, 1);
  9945. };
  9946. return ManagedWebGLRenderingContext;
  9947. }());
  9948. webgl.ManagedWebGLRenderingContext = ManagedWebGLRenderingContext;
  9949. var WebGLBlendModeConverter = (function () {
  9950. function WebGLBlendModeConverter() {
  9951. }
  9952. WebGLBlendModeConverter.getDestGLBlendMode = function (blendMode) {
  9953. switch (blendMode) {
  9954. case spine.BlendMode.Normal: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9955. case spine.BlendMode.Additive: return WebGLBlendModeConverter.ONE;
  9956. case spine.BlendMode.Multiply: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9957. case spine.BlendMode.Screen: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9958. default: throw new Error("Unknown blend mode: " + blendMode);
  9959. }
  9960. };
  9961. WebGLBlendModeConverter.getSourceGLBlendMode = function (blendMode, premultipliedAlpha) {
  9962. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  9963. switch (blendMode) {
  9964. case spine.BlendMode.Normal: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA;
  9965. case spine.BlendMode.Additive: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA;
  9966. case spine.BlendMode.Multiply: return WebGLBlendModeConverter.DST_COLOR;
  9967. case spine.BlendMode.Screen: return WebGLBlendModeConverter.ONE;
  9968. default: throw new Error("Unknown blend mode: " + blendMode);
  9969. }
  9970. };
  9971. WebGLBlendModeConverter.ZERO = 0;
  9972. WebGLBlendModeConverter.ONE = 1;
  9973. WebGLBlendModeConverter.SRC_COLOR = 0x0300;
  9974. WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR = 0x0301;
  9975. WebGLBlendModeConverter.SRC_ALPHA = 0x0302;
  9976. WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA = 0x0303;
  9977. WebGLBlendModeConverter.DST_ALPHA = 0x0304;
  9978. WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA = 0x0305;
  9979. WebGLBlendModeConverter.DST_COLOR = 0x0306;
  9980. return WebGLBlendModeConverter;
  9981. }());
  9982. webgl.WebGLBlendModeConverter = WebGLBlendModeConverter;
  9983. })(webgl = spine.webgl || (spine.webgl = {}));
  9984. })(spine || (spine = {}));
  9985. //# sourceMappingURL=spine-webgl.js.map