vendor: 866 bytes, lines 1-21
1"use strict"; 2var spine = (() => { 3 var __defProp = Object.defineProperty; 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor; 5 var __getOwnPropNames = Object.getOwnPropertyNames; 6 var __hasOwnProp = Object.prototype.hasOwnProperty; 7 var __export = (target, all) => { 8 for (var name in all) 9 __defProp(target, name, { get: all[name], enumerable: true }); 10 }; 11 var __copyProps = (to, from, except, desc) => { 12 if (from && typeof from === "object" || typeof from === "function") { 13 for (let key of __getOwnPropNames(from)) 14 if (!__hasOwnProp.call(to, key) && key !== except) 15 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); 16 } 17 return to; 18 }; 19 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); 20 21 // spine-
21webgl/src/index.ts 22 var index_exports = {}; 23 __export(index_exports, { 24 AlphaTimeline: () => AlphaTimeline, 25 Animation: () => Animation, 26 AnimationState: () => AnimationState, 27 AnimationStateAdapter: () => AnimationStateAdapter, 28 AnimationStateData: () => AnimationStateData, 29 AssetCache: () => AssetCache, 30 AssetManager: () => AssetManager, 31 AssetManagerBase: () => AssetManagerBase, 32 AtlasAttachmentLoader: () => AtlasAttachmentLoader, 33 Attachment: () => Attachment, 34 AttachmentTimeline: () => AttachmentTimeline, 35 BinaryInput: () => BinaryInput, 36 BlendMode: () => BlendMode, 37 Bone: () => Bone, 38 BoneData: () => BoneData, 39 BoundingBoxAttachment: () => BoundingBoxAttachment, 40 CURRENT: () => CURRENT, 41 CameraController: () => CameraController, 42 ClippingAttachment: () => ClippingAttachment, 43 Color: () => Color, 44 Color2Attribute: () => Color2Attribute, 45 ColorAttribute: () => ColorAttribute, 46 ConstraintData: () => ConstraintData, 47 CurveTimeline: () => CurveTimeline, 48 CurveTimeline1: () => CurveTimeline1, 49 CurveTimeline2: () => CurveTimeline2, 50 DebugUtils: () => DebugUtils, 51 DeformTimeline: () => DeformTimeline, 52 Downloader: () => Downloader, 53 DrawOrderTimeline: () => DrawOrderTimeline, 54 Event: () => Event, 55 EventData: () => EventData, 56 EventQueue: () => EventQueue, 57 EventTimeline: () => EventTimeline, 58 EventType: () => EventType, 59 FIRST: () => FIRST, 60 FakeTexture: () => FakeTexture, 61 GLTexture: () => GLTexture, 62 HOLD_FIRST: () => HOLD_FIRST, 63 HOLD_MIX: () => HOLD_MIX, 64 HOLD_SUBSEQUENT: () => HOLD_SUBSEQUENT, 65 IkConstraint: () => IkConstraint, 66 IkConstraintData: () => IkConstraintData, 67 IkConstraintTimeline: () => IkConstraintTimeline, 68 Inherit: () => Inherit, 69 InheritTimeline: () => InheritTimeline, 70 Input: () => Input, 71 IntSet: () => IntSet, 72 Interpolation: () => Interpolation, 73 LoadingScreen: () => LoadingScreen, 74 M00: () => M00, 75 M01: () => M01, 76 M02: () => M02, 77 M03: () => M03, 78 M10: () => M10, 79 M11: () => M11, 80 M12: () => M12, 81 M13: () => M13, 82 M20: () => M20, 83 M21: () => M21, 84 M22: () => M22, 85 M23: () => M23, 86 M30: () => M30, 87 M31: () => M31, 88 M32: () => M32, 89 M33: () => M33, 90 ManagedWebGLRenderingContext: () => ManagedWebGLRenderingContext, 91 MathUtils: () => MathUtils, 92 Matrix4: () => Matrix42, 93 Mesh: () => Mesh, 94 MeshAttachment: () => MeshAttachment, 95 MixBlend: () => MixBlend, 96 MixDirection: () => MixDirection, 97 OrthoCamera: () => OrthoCamera, 98 PathAttachment: () => PathAttachment, 99 PathConstraint: () => PathConstraint, 100 PathConstraintData: () => PathConstraintData, 101 PathConstraintMixTimeline: () => PathConstraintMixTimeline, 102 PathConstraintPositionTimeline: () => PathConstraintPositionTimeline, 103 PathConstraintSpacingTimeline: () => PathConstraintSpacingTimeline, 104 Physics: () => Physics, 105 PhysicsConstraintDampingTimeline: () => PhysicsConstraintDampingTimeline, 106 PhysicsConstraintGravityTimeline: () => PhysicsConstraintGravityTimeline, 107 PhysicsConstraintInertiaTimeline: () => PhysicsConstraintInertiaTimeline, 108 PhysicsConstraintMassTimeline: () => PhysicsConstraintMassTimeline, 109 PhysicsConstraintMixTimeline: () => PhysicsConstraintMixTimeline, 110 PhysicsConstraintResetTimeline: () => PhysicsConstraintResetTimeline, 111 PhysicsConstraintStrengthTimeline: () => PhysicsConstraintStrengthTimeline, 112 PhysicsConstraintTimeline: () => PhysicsConstraintTimeline, 113 PhysicsConstraintWindTimeline: () => PhysicsConstraintWindTimeline, 114 PointAttachment: () => PointAttachment, 115 PolygonBatcher: () => PolygonBatcher, 116 Pool: () => Pool, 117 Position2Attribute: () => Position2Attribute, 118 Position3Attribute: () => Position3Attribute, 119 PositionMode: () => PositionMode, 120 Pow: () => Pow, 121 PowOut: () => PowOut, 122 RGB2Timeline: () => RGB2Timeline, 123 RGBA2Timeline: () => RGBA2Timeline, 124 RGBATimeline: () => RGBATimeline, 125 RGBTimeline: () => RGBTimeline, 126 RegionAttachment: () => RegionAttachment, 127 ResizeMode: () => ResizeMode, 128 RotateMode: () => RotateMode, 129 RotateTimeline: () => RotateTimeline, 130 SETUP: () => SETUP, 131 SUBSEQUENT: () => SUBSEQUENT, 132 ScaleTimeline: () => ScaleTimeline, 133 ScaleXTimeline: () => ScaleXTimeline, 134 ScaleYTimeline: () => ScaleYTimeline, 135 SceneRenderer: () =>
135 SceneRenderer, 136 SequenceTimeline: () => SequenceTimeline, 137 Shader: () => Shader, 138 ShapeRenderer: () => ShapeRenderer, 139 ShapeType: () => ShapeType, 140 ShearTimeline: () => ShearTimeline, 141 ShearXTimeline: () => ShearXTimeline, 142 ShearYTimeline: () => ShearYTimeline, 143 Skeleton: () => Skeleton, 144 SkeletonBinary: () => SkeletonBinary, 145 SkeletonBounds: () => SkeletonBounds, 146 SkeletonClipping: () => SkeletonClipping, 147 SkeletonData: () => SkeletonData, 148 SkeletonDebugRenderer: () => SkeletonDebugRenderer, 149 SkeletonJson: () => SkeletonJson, 150 SkeletonRenderer: () => SkeletonRenderer, 151 Skin: () => Skin, 152 SkinEntry: () => SkinEntry, 153 Slot: () => Slot, 154 SlotData: () => SlotData, 155 SpacingMode: () => SpacingMode, 156 SpineCanvas: () => SpineCanvas, 157 StringSet: () => StringSet, 158 TexCoordAttribute: () => TexCoordAttribute, 159 Texture: () => Texture, 160 TextureAtlas: () => TextureAtlas, 161 TextureAtlasPage: () => TextureAtlasPage, 162 TextureAtlasRegion: () => TextureAtlasRegion, 163 TextureFilter: () => TextureFilter, 164 TextureRegion: () => TextureRegion, 165 TextureWrap: () => TextureWrap, 166 TimeKeeper: () => TimeKeeper, 167 Timeline: () => Timeline, 168 Touch: () => Touch, 169 TrackEntry: () => TrackEntry, 170 TransformConstraint: () => TransformConstraint, 171 TransformConstraintData: () => TransformConstraintData, 172 TransformConstraintTimeline: () => TransformConstraintTimeline, 173 TranslateTimeline: () => TranslateTimeline, 174 TranslateXTimeline: () => TranslateXTimeline, 175 TranslateYTimeline: () => TranslateYTimeline, 176 Triangulator: () => Triangulator, 177 Utils: () => Utils, 178 Vector2: () => Vector2, 179 Vector3: () => Vector3, 180 VertexAttachment: () => VertexAttachment, 181 VertexAttribute: () => VertexAttribute, 182 VertexAttributeType: () => VertexAttributeType, 183 WindowedMean: () => WindowedMean 184 }); 185 186
186// spine-core/src/Utils.ts 187 var IntSet = class { 188 array = new Array(); 189 add(value) { 190 let contains = this.contains(value); 191 this.array[value | 0] = value | 0; 192 return !contains; 193 } 194 contains(value) { 195 return this.array[value | 0] != void 0; 196 } 197 remove(value) { 198 this.array[value | 0] = void 0; 199 } 200 clear() { 201 this.array.length = 0; 202 } 203 }; 204 var StringSet = class { 205 entries = {}; 206 size = 0; 207 add(value) { 208 let contains = this.entries[value]; 209 this.entries[value] = true; 210 if (!contains) { 211 this.size++; 212 return true; 213 } 214 return false; 215 } 216 addAll(values) { 217 let oldSize = this.size; 218 for (var i = 0, n = values.length; i < n; i++) 219 this.add(values[i]); 220 return oldSize != this.size; 221 } 222 contains(value) { 223 return this.entries[value]; 224 } 225 clear() { 226 this.entries = {}; 227 this.size = 0; 228 } 229 }; 230 var Color = class _Color { 231 constructor(r = 0, g = 0, b = 0, a = 0) { 232 this.r = r; 233 this.g = g; 234 this.b = b; 235 this.a = a; 236 } 237 static WHITE = new _Color(1, 1, 1, 1); 238 static RED = new _Color(1, 0, 0, 1); 239 static GREEN = new _Color(0, 1, 0, 1); 240 static BLUE = new _Color(0, 0, 1, 1); 241 static MAGENTA = new _Color(1, 0, 1, 1); 242 set(r, g, b, a) { 243 this.r = r; 244 this.g = g; 245 this.b = b; 246 this.a = a; 247 return this.clamp(); 248 } 249 setFromColor(c) { 250 this.r = c.r; 251 this.g = c.g; 252 this.b = c.b; 253 this.a = c.a; 254 return this; 255 } 256 setFromString(hex) { 257 hex = hex.charAt(0) == "#" ? hex.substr(1) : hex; 258 this.r = parseInt(hex.substr(0, 2), 16) / 255; 259 this.g = parseInt(hex.substr(2, 2), 16) / 255; 260 this.b = parseInt(hex.substr(4, 2), 16) / 255; 261 this.a = hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255; 262 return this; 263 } 264 add(r, g, b, a) { 265 this.r += r; 266 this.g += g; 267 this.b += b; 268 this.a += a; 269 return this.clamp(); 270 } 271 clamp() { 272 if (this.r < 0) this.r = 0; 273 else if (this.r > 1) this.r = 1; 274 if (this.g < 0) this.g = 0; 275 else if (this.g > 1) this.g = 1; 276 if (this.b < 0) this.b = 0; 277 else if (this.b > 1) this.b = 1; 278 if (this.a < 0) this.a = 0; 279 else if (this.a > 1) this.a = 1; 280 return this; 281 } 282 static rgba8888ToColor(color, value) { 283 color.r = ((value & 4278190080) >>> 24) / 255; 284 color.g = ((value & 16711680) >>> 16) / 255; 285 color.b = ((value & 65280) >>> 8) / 255; 286 color.a = (value & 255) / 255; 287 } 288 static rgb888ToColor(color, value) { 289 color.r = ((value & 16711680) >>> 16) / 255; 290 color.g = ((value & 65280) >>> 8) / 255; 291 color.b = (value & 255) / 255; 292 } 293 toRgb888() { 294 const hex = (x) => ("0" + (x * 255).toString(16)).slice(-2); 295 return Number("0x" + hex(this.r) + hex(this.g) + hex(this.b)); 296 } 297 static fromString(hex, color = new _Color()) { 298 return color.setFromString(hex); 299 } 300 }; 301 var MathUtils = class _MathUtils { 302 static PI = 3.1415927; 303 static PI2 = _MathUtils.PI * 2; 304 static invPI2 = 1 / _MathUtils.PI2; 305 static radiansToDegrees = 180 / _MathUtils.PI; 306 static radDeg = _MathUtils.radiansToDegrees; 307 static degreesToRadians = _MathUtils.PI / 180; 308 static degRad = _MathUtils.degreesToRadians; 309 static clamp(value, min, max) { 310 if (value < min) return min; 311 if (value > max) return max; 312 return value; 313 } 314 static cosDeg(degrees) { 315 return Math.cos(degrees * _MathUtils.degRad); 316 } 317 static sinDeg(degrees) { 318 return Math.sin(degrees * _MathUtils.degRad); 319 } 320 static atan2Deg(y, x) { 321 return Math.atan2(y, x) * _MathUtils.degRad; 322 } 323 static signum(value) { 324 return value > 0 ? 1 : value < 0 ? -1 : 0; 325 } 326 static toInt(x) { 327 return x > 0 ? Math.floor(x) : Math.ceil(x); 328 } 329 static cbrt(x) { 330 let y = Math.pow(Math.abs(x), 1 / 3); 331 return x < 0 ? -y : y; 332 } 333 static randomTriangular(min, max) { 334 return _MathUtils.randomTriangularWith(min, max, (min + max) * 0.5); 335 } 336 static randomTriangularWith(min, max, mode) { 337 let u = Math.random(); 338 let d = max - min; 339 if (u <= (mode - min) / d) return min + Math.sqrt(u * d * (mode - min)); 340 return max - Math.sqrt((1 - u) * d * (max - mode)); 341 } 342 static isPowerOfTwo(value) { 343 return value && (value & value - 1) === 0; 344 } 345 }; 346 var Interpolation = class { 347 apply(start, end, a) { 348 return start + (end - start) * this.applyInternal(a); 349 } 350 }; 351 var Pow = class extends Interpolation { 352 power = 2; 353 constructor(power) { 354 super(); 355 this.power = power; 356 } 357 applyInternal(a) { 358 if (a <= 0.5) return Math.pow(a * 2, this.power) / 2; 359 return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1; 360 } 361 }; 362 var PowOut = class extends Pow { 363 constructor(power) { 364 super(power); 365 } 366 applyInternal(a) { 367 return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1; 368 } 369 }; 370 var Utils = class _Utils { 371 static SUPPORTS_TYPED_ARRAYS = typeof Float32Array !== "undefined"; 372 static arrayCopy(source, sourceStart, dest, destStart, numElements) { 373 for (let i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) { 374 dest[j] = source[i]; 375 } 376 } 377 static arrayFill(array, fromIndex, toIndex, value) { 378 for (let i = fromIndex; i < toIndex; i++) 379 array[i] = value; 380 } 381 static setArraySize(array, size, value = 0) { 382 let oldSize = array.length; 383 if (oldSize == size) return array; 384 array.length = size; 385 if (oldSize < size) { 386 for (let i = oldSize; i < size; i++) array[i] = value; 387 } 388 return array; 389 } 390 static ensureArrayCapacity(array, size, value = 0) { 391 if (array.length >= size) return array; 392 return _Utils.setArraySize(array, size, value); 393 } 394 static newArray(size, defaultValue) { 395 let array = new Array(size); 396 for (let i = 0; i < size; i++) array[i] = defaultValue; 397 return array; 398 } 399 static newFloatArray(size) { 400 if (_Utils.SUPPORTS_TYPED_ARRAYS) 401 return new Float32Array(size); 402 else { 403 let array = new Array(size); 404 for (let i = 0; i < array.length; i++) array[i] = 0; 405 return array; 406 } 407 } 408 static newShortArray(size) { 409 if (_Utils.SUPPORTS_TYPED_ARRAYS) 410 return new Int16Array(size); 411 else { 412 let array = new Array(size); 413 for (let i = 0; i < array.length; i++) array[i] = 0; 414 return array; 415 } 416 } 417 static toFloatArray(array) { 418 return _Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array; 419 } 420 static toSinglePrecision(value) { 421 return _Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value; 422 } 423 // This function is used to fix WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109 424 static webkit602BugfixHelper(alpha, blend) { 425 } 426 static contains(array, element, identity = true) { 427 for (var i = 0; i < array.length; i++) 428 if (array[i] == element) return true; 429 return false;
430 } 431 static enumValue(type, name) { 432 return type[name[0].toUpperCase() + name.slice(1)]; 433 } 434 }; 435 var DebugUtils = class { 436 static logBones(skeleton) { 437 for (let i = 0; i < skeleton.bones.length; i++) { 438 let bone = skeleton.bones[i]; 439 console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY); 440 } 441 } 442 }; 443 var Pool = class { 444 items = new Array(); 445 instantiator; 446 constructor(instantiator) { 447 this.instantiator = instantiator; 448 } 449 obtain() { 450 return this.items.length > 0 ? this.items.pop() : this.instantiator(); 451 } 452 free(item) { 453 if (item.reset) item.reset(); 454 this.items.push(item); 455 } 456 freeAll(items) { 457 for (let i = 0; i < items.length; i++) 458 this.free(items[i]); 459 } 460 clear() { 461 this.items.length = 0; 462 } 463 }; 464 var Vector2 = class { 465 constructor(x = 0, y = 0) { 466 this.x = x; 467 this.y = y; 468 } 469 set(x, y) { 470 this.x = x; 471 this.y = y; 472 return this; 473 } 474 length() { 475 let x = this.x; 476 let y = this.y; 477 return Math.sqrt(x * x + y * y); 478 } 479 normalize() { 480 let len = this.length(); 481 if (len != 0) { 482 this.x /= len; 483 this.y /= len; 484 } 485 return this; 486 } 487 }; 488 var TimeKeeper = class { 489 maxDelta = 0.064; 490 framesPerSecond = 0; 491 delta = 0; 492 totalTime = 0; 493 lastTime = Date.now() / 1e3; 494 frameCount = 0; 495 frameTime = 0; 496 update() { 497 let now = Date.now() / 1e3; 498 this.delta = now - this.lastTime; 499 this.frameTime += this.delta; 500 this.totalTime += this.delta; 501 if (this.delta > this.maxDelta) this.delta = this.maxDelta; 502 this.lastTime = now; 503 this.frameCount++; 504 if (this.frameTime > 1) { 505 this.framesPerSecond = this.frameCount / this.frameTime; 506 this.frameTime = 0; 507 this.frameCount = 0; 508 } 509 } 510 }; 511 var WindowedMean = class { 512 values; 513 addedValues = 0; 514 lastValue = 0; 515 mean = 0; 516 dirty = true; 517 constructor(windowSize = 32) { 518 this.values = new Array(windowSize); 519 } 520 hasEnoughData() { 521 return this.addedValues >= this.values.length; 522 } 523 addValue(value) { 524 if (this.addedValues < this.values.length) this.addedValues++; 525 this.values[this.lastValue++] = value; 526 if (this.lastValue > this.values.length - 1) this.lastValue = 0; 527 this.dirty = true; 528 } 529 getMean() { 530 if (this.hasEnoughData()) { 531 if (this.dirty) { 532 let mean = 0; 533 for (let i = 0; i < this.values.length; i++) 534 mean += this.values[i]; 535 this.mean = mean / this.values.length; 536 this.dirty = false; 537 } 538 return this.mean; 539 } 540 return 0; 541 } 542 }; 543 544
544// spine-core/src/attachments/Attachment.ts 545 var Attachment = class { 546 name; 547 constructor(name) { 548 if (!name) throw new Error("name cannot be null."); 549 this.name = name; 550 } 551 }; 552 var VertexAttachment = class _VertexAttachment extends Attachment { 553 static nextID = 0; 554 /** The unique ID for this attachment. */ 555 id = _VertexAttachment.nextID++; 556 /** The bones which affect the {@link #getVertices()}. The array entries are, for each vertex, the number of bones affecting 557 * the vertex followed by that many bone indices, which is the index of the bone in {@link Skeleton#bones}. Will be null 558 * if this attachment has no weights. */ 559 bones = null; 560 /** The vertex positions in the bone's coordinate system. For a non-weighted attachment, the values are `x,y` 561 * entries for each vertex. For a weighted attachment, the values are `x,y,weight` entries for each bone affecting 562 * each vertex. */ 563 vertices = []; 564 /** The maximum number of world vertex values that can be output by 565 * {@link #computeWorldVertices()} using the `count` parameter. */ 566 worldVerticesLength = 0; 567 /** Timelines for the timeline attachment are also applied to this attachment. 568 * May be null if no attachment-specific timelines should be applied. */ 569 timelineAttachment = this; 570 constructor(name) { 571 super(name); 572 } 573 /** Transforms the attachment's local {@link #vertices} to world coordinates. If the slot's {@link Slot#deform} is 574 * not empty, it is used to deform the vertices. 575 * 576 * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine 577 * Runtimes Guide. 578 * @param start The index of the first {@link #vertices} value to transform. Each vertex has 2 values, x and y. 579 * @param count The number of world vertex values to output. Must be <= {@link #worldVerticesLength} - `start`. 580 * @param worldVertices The output world vertices. Must have a length >= `offset` + `count` * 581 * `stride` / 2. 582 * @param offset The `worldVertices` index to begin writing values. 583 * @param stride The number of `worldVertices` entries between the value pairs written. */ 584 computeWorldVertices(slot, start, count, worldVertices, offset, stride) { 585 count = offset + (count >> 1) * stride; 586 let skeleton = slot.bone.skeleton; 587 let deformArray = slot.deform; 588 let vertices = this.vertices; 589 let bones = this.bones; 590 if (!bones) { 591 if (deformArray.length > 0) vertices = deformArray; 592 let bone = slot.bone; 593 let x = bone.worldX; 594 let y = bone.worldY; 595 let a = bone.a, b = bone.b, c = bone.c, d = bone.d; 596 for (let v2 = start, w = offset; w < count; v2 += 2, w += stride) { 597 let vx = vertices[v2], vy = vertices[v2 + 1]; 598 worldVertices[w] = vx * a + vy * b + x; 599 worldVertices[w + 1] = vx * c + vy * d + y; 600 } 601 return; 602 } 603 let v = 0, skip = 0; 604 for (let i = 0; i < start; i += 2) { 605 let n = bones[v]; 606 v += n + 1; 607 skip += n; 608 } 609 let skeletonBones = skeleton.bones; 610 if (deformArray.length == 0) { 611 for (let w = offset, b = skip * 3; w < count; w += stride) { 612 let wx = 0, wy = 0; 613 let n = bones[v++]; 614 n += v; 615 for (; v < n; v++, b += 3) { 616 let bone = skeletonBones[bones[v]]; 617 let vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2]; 618 wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight; 619 wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight; 620 } 621 worldVertices[w] = wx; 622 worldVertices[w + 1] = wy; 623 } 624 } else { 625 let deform = deformArray; 626 for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) { 627 let wx = 0, wy = 0; 628 let n = bones[v++]; 629 n += v; 630 for (; v < n; v++, b += 3, f += 2) { 631 let bone = skeletonBones[bones[v]]; 632 let vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2]; 633 wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight; 634 wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight; 635 } 636 worldVertices[w] = wx; 637 worldVertices[w + 1] = wy; 638 } 639 } 640 } 641 /** Does not copy id (generated) or name (set on construction). **/ 642 copyTo(attachment) { 643 if (this.bones) { 644 attachment.bones = new Array(this.bones.length); 645 Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length); 646 } else 647 attachment.bones = null; 648 if (this.vertices) { 649 attachment.vertices = Utils.newFloatArray(this.vertices.length); 650 Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length); 651 } 652 attachment.worldVerticesLength = this.worldVerticesLength; 653 attachment.timelineAttachment = this.timelineAttachment; 654 } 655 }; 656 657
657// spine-core/src/attachments/Sequence.ts 658 var Sequence = class _Sequence { 659 static _nextID = 0; 660 id = _Sequence.nextID(); 661 regions; 662 start = 0; 663 digits = 0; 664 /** The index of the region to show for the setup pose. */ 665 setupIndex = 0; 666 constructor(count) { 667 this.regions = new Array(count); 668 } 669 copy() { 670 let copy = new _Sequence(this.regions.length); 671 Utils.arrayCopy(this.regions, 0, copy.regions, 0, this.regions.length); 672 copy.start = this.start; 673 copy.digits = this.digits; 674 copy.setupIndex = this.setupIndex; 675 return copy; 676 } 677 apply(slot, attachment) { 678 let index = slot.sequenceIndex; 679 if (index == -1) index = this.setupIndex; 680 if (index >= this.regions.length) index = this.regions.length - 1; 681 let region = this.regions[index]; 682 if (attachment.region != region) { 683 attachment.region = region; 684 attachment.updateRegion(); 685 } 686 } 687 getPath(basePath, index) { 688 let result = basePath; 689 let frame = (this.start + index).toString(); 690 for (let i = this.digits - frame.length; i > 0; i--) 691 result += "0"; 692 result += frame; 693 return result; 694 } 695 static nextID() { 696 return _Sequence._nextID++; 697 } 698 }; 699 var SequenceMode = /* @__PURE__ */ ((SequenceMode2) => { 700 SequenceMode2[SequenceMode2["hold"] = 0] = "hold"; 701 SequenceMode2[SequenceMode2["once"] = 1] = "once"; 702 SequenceMode2[SequenceMode2["loop"] = 2] = "loop"; 703 SequenceMode2[SequenceMode2["pingpong"] = 3] = "pingpong"; 704 SequenceMode2[SequenceMode2["onceReverse"] = 4] = "onceReverse"; 705 SequenceMode2[SequenceMode2["loopReverse"] = 5] = "loopReverse"; 706 SequenceMode2[SequenceMode2["pingpongReverse"] = 6] = "pingpongReverse"; 707 return SequenceMode2; 708 })(SequenceMode || {}); 709 var SequenceModeValues = [ 710 0 /* hold */, 711 1 /* once */, 712 2 /* loop */, 713 3 /* pingpong */, 714 4 /* onceReverse */, 715 5 /* loopReverse */, 716 6 /* pingpongReverse */ 717 ]; 718 719
719// spine-core/src/Animation.ts 720 var Animation = class { 721 /** The animation's name, which is unique across all animations in the skeleton. */ 722 name; 723 timelines = []; 724 timelineIds = new StringSet(); 725 /** The duration of the animation in seconds, which is the highest time of all keys in the timeline. */ 726 duration; 727 constructor(name, timelines, duration) { 728 if (!name) throw new Error("name cannot be null."); 729 this.name = name; 730 this.setTimelines(timelines); 731 this.duration = duration; 732 } 733 setTimelines(timelines) { 734 if (!timelines) throw new Error("timelines cannot be null."); 735 this.timelines = timelines; 736 this.timelineIds.clear(); 737 for (var i = 0; i < timelines.length; i++) 738 this.timelineIds.addAll(timelines[i].getPropertyIds()); 739 } 740 hasTimeline(ids) { 741 for (let i = 0; i < ids.length; i++) 742 if (this.timelineIds.contains(ids[i])) return true; 743 return false; 744 } 745 /** Applies all the animation's timelines to the specified skeleton. 746 * 747 * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}. 748 * @param loop If true, the animation repeats after {@link #getDuration()}. 749 * @param events May be null to ignore fired events. */ 750 apply(skeleton, lastTime, time, loop, events, alpha, blend, direction) { 751 if (!skeleton) throw new Error("skeleton cannot be null."); 752 if (loop && this.duration != 0) { 753 time %= this.duration; 754 if (lastTime > 0) lastTime %= this.duration; 755 } 756 let timelines = this.timelines; 757 for (let i = 0, n = timelines.length; i < n; i++) 758 timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction); 759 } 760 }; 761 var MixBlend = /* @__PURE__ */ ((MixBlend2) => { 762 MixBlend2[MixBlend2["setup"] = 0] = "setup"; 763 MixBlend2[MixBlend2["first"] = 1] = "first"; 764 MixBlend2[MixBlend2["replace"] = 2] = "replace"; 765 MixBlend2[MixBlend2["add"] = 3] = "add"; 766 return MixBlend2; 767 })(MixBlend || {}); 768 var MixDirection = /* @__PURE__ */ ((MixDirection2) => { 769 MixDirection2[MixDirection2["mixIn"] = 0] = "mixIn"; 770 MixDirection2[MixDirection2["mixOut"] = 1] = "mixOut"; 771 return MixDirection2; 772 })(MixDirection || {}); 773 var Property = { 774 rotate: 0, 775 x: 1, 776 y: 2, 777 scaleX: 3, 778 scaleY: 4, 779 shearX: 5, 780 shearY: 6, 781 inherit: 7, 782 rgb: 8, 783 alpha: 9, 784 rgb2: 10, 785 attachment: 11, 786 deform: 12, 787 event: 13, 788 drawOrder: 14, 789 ikConstraint: 15, 790 transformConstraint: 16, 791 pathConstraintPosition: 17, 792 pathConstraintSpacing: 18, 793 pathConstraintMix: 19, 794 physicsConstraintInertia: 20, 795 physicsConstraintStrength: 21, 796 physicsConstraintDamping: 22, 797 physicsConstraintMass: 23, 798 physicsConstraintWind: 24, 799 physicsConstraintGravity: 25, 800 physicsConstraintMix: 26, 801 physicsConstraintReset: 27, 802 sequence: 28 803 }; 804 var Timeline = class { 805 propertyIds; 806 frames; 807 constructor(frameCount, propertyIds) { 808 this.propertyIds = propertyIds; 809 this.frames = Utils.newFloatArray(frameCount * this.getFrameEntries()); 810 } 811 getPropertyIds() { 812 return this.propertyIds; 813 } 814 getFrameEntries() { 815 return 1; 816 } 817 getFrameCount() { 818 return this.frames.length / this.getFrameEntries(); 819 } 820 getDuration() { 821 return this.frames[this.frames.length - this.getFrameEntries()]; 822 } 823 static search1(frames, time) { 824 let n = frames.length; 825 for (let i = 1; i < n; i++) 826 if (frames[i] > time) return i - 1; 827 return n - 1; 828 } 829 static search(frames, time, step) { 830 let n = frames.length; 831 for (let i = step; i < n; i += step) 832 if (frames[i] > time) return i - step; 833 return n - step; 834 } 835 }; 836 var CurveTimeline = class extends Timeline { 837 curves; 838 // type, x, y, ... 839 constructor(frameCount, bezierCount, propertyIds) { 840 super(frameCount, propertyIds); 841 this.curves = Utils.newFloatArray( 842 frameCount + bezierCount * 18 843 /*BEZIER_SIZE*/ 844 ); 845 this.curves[frameCount - 1] = 1; 846 } 847 /** Sets the specified key frame to linear interpolation. */ 848 setLinear(frame) { 849 this.curves[frame] = 0; 850 } 851 /** Sets the specified key frame to stepped interpolation. */ 852 setStepped(frame) { 853 this.curves[frame] = 1; 854 } 855 /** Shrinks the storage for Bezier curves, for use when <code>bezierCount</code> (specified in the constructor) was larger 856 * than the actual number of Bezier curves. */ 857 shrink(bezierCount) { 858 let size = this.getFrameCount() + bezierCount * 18; 859 if (this.curves.length > size) { 860 let newCurves = Utils.newFloatArray(size); 861 Utils.arrayCopy(this.curves, 0, newCurves, 0, size); 862 this.curves = newCurves; 863 } 864 } 865 /** Stores the segments for the specified Bezier curve. For timelines that modify multiple values, there may be more than 866 * one curve per frame. 867 * @param bezier The ordinal of this Bezier curve for this timeline, between 0 and <code>bezierCount - 1</code> (specified 868 * in the constructor), inclusive. 869 * @param frame Between 0 and <code>frameCount - 1</code>, inclusive. 870 * @param value The index of the value for this frame that this curve is used for. 871 * @param time1 The time for the first key. 872 * @param value1 The value for the first key. 873 * @param cx1 The time for the first Bezier handle. 874 * @param cy1 The value for the first Bezier handle. 875 * @param cx2 The time of the second Bezier handle. 876 * @param cy2 The value for the second Bezier handle. 877 * @param time2 The time for the second key. 878 * @param value2 The value for the second key. */ 879 setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) { 880 let curves = this.curves; 881 let i = this.getFrameCount() + bezier * 18; 882 if (value == 0) curves[frame] = 2 + i; 883 let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03; 884 let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 6e-3, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 6e-3; 885 let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; 886 let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667; 887 let x = time1 + dx, y = value1 + dy; 888 for (let n = i + 18; i < n; i += 2) { 889 curves[i] = x; 890 curves[i + 1] = y; 891 dx += ddx; 892 dy += ddy; 893 ddx += dddx; 894 ddy += dddy; 895 x += dx; 896 y += dy; 897 } 898 } 899 /** Returns the Bezier interpolated value for the specified time. 900 * @param frameIndex The index into {@link #getFrames()} for the values of the frame before <code>
900time</code>. 901 * @param valueOffset The offset from <code>frameIndex</code> to the value this curve is used for. 902 * @param i The index of the Bezier segments. See {@link #getCurveType(int)}. */ 903 getBezierValue(time, frameIndex, valueOffset, i) { 904 let curves = this.curves; 905 if (curves[i] > time) { 906 let x2 = this.frames[frameIndex], y2 = this.frames[frameIndex + valueOffset]; 907 return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2); 908 } 909 let n = i + 18; 910 for (i += 2; i < n; i += 2) { 911 if (curves[i] >= time) { 912 let x2 = curves[i - 2], y2 = curves[i - 1]; 913 return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2); 914 } 915 } 916 frameIndex += this.getFrameEntries(); 917 let x = curves[n - 2], y = curves[n - 1]; 918 return y + (time - x) / (this.frames[frameIndex] - x) * (this.frames[frameIndex + valueOffset] - y); 919 } 920 }; 921 var CurveTimeline1 = class extends CurveTimeline { 922 constructor(frameCount, bezierCount, propertyId) { 923 super(frameCount, bezierCount, [propertyId]); 924 } 925 getFrameEntries() { 926 return 2; 927 } 928 /** Sets the time and value for the specified frame. 929 * @param frame Between 0 and <code>frameCount</code>, inclusive. 930 * @param time The frame time in seconds. */ 931 setFrame(frame, time, value) { 932 frame <<= 1; 933 this.frames[frame] = time; 934 this.frames[ 935 frame + 1 936 /*VALUE*/ 937 ] = value; 938 } 939 /** Returns the interpolated value for the specified time. */ 940 getCurveValue(time) { 941 let frames = this.frames; 942 let i = frames.length - 2; 943 for (let ii = 2; ii <= i; ii += 2) { 944 if (frames[ii] > time) { 945 i = ii - 2; 946 break; 947 } 948 } 949 let curveType = this.curves[i >> 1]; 950 switch (curveType) { 951 case 0: 952 let before = frames[i], value = frames[ 953 i + 1 954 /*VALUE*/ 955 ]; 956 return value + (time - before) / (frames[ 957 i + 2 958 /*ENTRIES*/ 959 ] - before) * (frames[ 960 i + 2 + 1 961 /*VALUE*/ 962 ] - value); 963 case 1: 964 return frames[ 965 i + 1 966 /*VALUE*/ 967 ]; 968 } 969 return this.getBezierValue( 970 time, 971 i, 972 1, 973 curveType - 2 974 /*BEZIER*/ 975 ); 976 } 977 getRelativeValue(time, alpha, blend, current, setup) { 978 if (time < this.frames[0]) { 979 switch (blend) { 980 case 0 /* setup */: 981 return setup; 982 case 1 /* first */: 983 return current + (setup - current) * alpha; 984 } 985 return current; 986 } 987 let value = this.getCurveValue(time); 988 switch (blend) { 989 case 0 /* setup */: 990 return setup + value * alpha; 991 case 1 /* first */: 992 case 2 /* replace */: 993 value += setup - current; 994 } 995 return current + value * alpha; 996 } 997 getAbsoluteValue(time, alpha, blend, current, setup) { 998 if (time < this.frames[0]) { 999 switch (blend) { 1000 case 0 /* setup */: 1001 return setup; 1002 case 1 /* first */: 1003 return current + (setup - current) * alpha; 1004 } 1005 return current; 1006 } 1007 let value = this.getCurveValue(time); 1008 if (blend == 0 /* setup */) return setup + (value - setup) * alpha; 1009 return current + (value - current) * alpha; 1010 } 1011 getAbsoluteValue2(time, alpha, blend, current, setup, value) { 1012 if (time < this.frames[0]) { 1013 switch (blend) { 1014 case 0 /* setup */: 1015 return setup; 1016 case 1 /* first */: 1017 return current + (setup - current) * alpha; 1018 } 1019 return current; 1020 } 1021 if (blend == 0 /* setup */) return setup + (value - setup) * alpha; 1022 return current + (value - current) * alpha; 1023 } 1024 getScaleValue(time, alpha, blend, direction, current, setup) { 1025 const frames = this.frames; 1026 if (time < frames[0]) { 1027 switch (blend) { 1028 case 0 /* setup */: 1029 return setup;
1030 case 1 /* first */: 1031 return current + (setup - current) * alpha; 1032 } 1033 return current; 1034 } 1035 let value = this.getCurveValue(time) * setup; 1036 if (alpha == 1) { 1037 if (blend == 3 /* add */) return current + value - setup; 1038 return value; 1039 } 1040 if (direction == 1 /* mixOut */) { 1041 switch (blend) { 1042 case 0 /* setup */: 1043 return setup + (Math.abs(value) * MathUtils.signum(setup) - setup) * alpha; 1044 case 1 /* first */: 1045 case 2 /* replace */: 1046 return current + (Math.abs(value) * MathUtils.signum(current) - current) * alpha; 1047 } 1048 } else { 1049 let s = 0; 1050 switch (blend) { 1051 case 0 /* setup */: 1052 s = Math.abs(setup) * MathUtils.signum(value); 1053 return s + (value - s) * alpha; 1054 case 1 /* first */: 1055 case 2 /* replace */: 1056 s = Math.abs(current) * MathUtils.signum(value); 1057 return s + (value - s) * alpha; 1058 } 1059 } 1060 return current + (value - setup) * alpha; 1061 } 1062 }; 1063 var CurveTimeline2 = class extends CurveTimeline { 1064 /** @param bezierCount The maximum number of Bezier curves. See {@link #shrink(int)}. 1065 * @param propertyIds Unique identifiers for the properties the timeline modifies. */ 1066 constructor(frameCount, bezierCount, propertyId1, propertyId2) { 1067 super(frameCount, bezierCount, [propertyId1, propertyId2]); 1068 } 1069 getFrameEntries() { 1070 return 3; 1071 } 1072 /** Sets the time and values for the specified frame. 1073 * @param frame Between 0 and <code>frameCount</code>, inclusive. 1074 * @param time The frame time in seconds. */ 1075 setFrame(frame, time, value1, value2) { 1076 frame *= 3; 1077 this.frames[frame] = time; 1078 this.frames[ 1079 frame + 1 1080 /*VALUE1*/ 1081 ] = value1; 1082 this.frames[ 1083 frame + 2 1084 /*VALUE2*/ 1085 ] = value2; 1086 } 1087 }; 1088 var RotateTimeline = class extends CurveTimeline1 { 1089 boneIndex = 0; 1090 constructor(frameCount, bezierCount, boneIndex) { 1091 super(frameCount, bezierCount, Property.rotate + "|" + boneIndex); 1092 this.boneIndex = boneIndex; 1093 } 1094 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1095 let bone = skeleton.bones[this.boneIndex]; 1096 if (bone.active) bone.rotation = this.getRelativeValue(time, alpha, blend, bone.rotation, bone.data.rotation); 1097 } 1098 }; 1099 var TranslateTimeline = class extends CurveTimeline2 { 1100 boneIndex = 0; 1101 constructor(frameCount, bezierCount, boneIndex) { 1102 super( 1103 frameCount, 1104 bezierCount, 1105 Property.x + "|" + boneIndex, 1106 Property.y + "|" + boneIndex 1107 ); 1108 this.boneIndex = boneIndex; 1109 } 1110 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1111 let bone = skeleton.bones[this.boneIndex]; 1112 if (!bone.active) return; 1113 let frames = this.frames; 1114 if (time < frames[0]) { 1115 switch (blend) { 1116 case 0 /* setup */: 1117 bone.x = bone.data.x; 1118 bone.y = bone.data.y; 1119 return; 1120 case 1 /* first */: 1121 bone.x += (bone.data.x - bone.x) * alpha; 1122 bone.y += (bone.data.y - bone.y) * alpha; 1123 } 1124 return; 1125 } 1126 let x = 0, y = 0; 1127 let i = Timeline.search( 1128 frames, 1129 time, 1130 3 1131 /*ENTRIES*/ 1132 ); 1133 let curveType = this.curves[ 1134 i / 3 1135 /*ENTRIES*/ 1136 ]; 1137 switch (curveType) { 1138 case 0: 1139 let before = frames[i]; 1140 x = frames[ 1141 i + 1 1142 /*VALUE1*/ 1143 ]; 1144 y = frames[ 1145 i + 2 1146 /*VALUE2*/ 1147 ]; 1148 let t = (time - before) / (frames[ 1149 i + 3 1150 /*ENTRIES*/ 1151 ] - before); 1152 x += (frames[ 1153 i + 3 + 1 1154 /*VALUE1*/ 1155 ] - x) * t; 1156 y += (frames[ 1157 i + 3 + 2 1158 /*VALUE2*/ 1159 ] - y) * t; 1160 break; 1161 case 1: 1162 x = frames[ 1163 i + 1 1164 /*VALUE1*/ 1165 ]; 1166 y = frames[ 1167 i + 2 1168 /*VALUE2*/ 1169 ]; 1170 break; 1171 default: 1172 x = this.getBezierValue( 1173 time, 1174 i, 1175 1, 1176 curveType - 2 1177 /*BEZIER*/ 1178 ); 1179 y = this.getBezierValue( 1180 time, 1181 i, 1182 2, 1183 curveType + 18 - 2 1184 /*BEZIER*/ 1185 ); 1186 } 1187 switch (blend) { 1188 case 0 /* setup */: 1189 bone.x = bone.data.x + x * alpha; 1190 bone.y = bone.data.y + y * alpha; 1191 break;
1192 case 1 /* first */: 1193 case 2 /* replace */: 1194 bone.x += (bone.data.x + x - bone.x) * alpha; 1195 bone.y += (bone.data.y + y - bone.y) * alpha; 1196 break; 1197 case 3 /* add */: 1198 bone.x += x * alpha; 1199 bone.y += y * alpha; 1200 } 1201 } 1202 }; 1203 var TranslateXTimeline = class extends CurveTimeline1 { 1204 boneIndex = 0; 1205 constructor(frameCount, bezierCount, boneIndex) { 1206 super(frameCount, bezierCount, Property.x + "|" + boneIndex); 1207 this.boneIndex = boneIndex; 1208 } 1209 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1210 let bone = skeleton.bones[this.boneIndex]; 1211 if (bone.active) bone.x = this.getRelativeValue(time, alpha, blend, bone.x, bone.data.x); 1212 } 1213 }; 1214 var TranslateYTimeline = class extends CurveTimeline1 { 1215 boneIndex = 0; 1216 constructor(frameCount, bezierCount, boneIndex) { 1217 super(frameCount, bezierCount, Property.y + "|" + boneIndex); 1218 this.boneIndex = boneIndex; 1219 } 1220 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1221 let bone = skeleton.bones[this.boneIndex]; 1222 if (bone.active) bone.y = this.getRelativeValue(time, alpha, blend, bone.y, bone.data.y); 1223 } 1224 }; 1225 var ScaleTimeline = class extends CurveTimeline2 { 1226 boneIndex = 0; 1227 constructor(frameCount, bezierCount, boneIndex) { 1228 super( 1229 frameCount, 1230 bezierCount, 1231 Property.scaleX + "|" + boneIndex, 1232 Property.scaleY + "|" + boneIndex 1233 ); 1234 this.boneIndex = boneIndex; 1235 } 1236 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1237 let bone = skeleton.bones[this.boneIndex]; 1238 if (!bone.active) return; 1239 let frames = this.frames; 1240 if (time < frames[0]) { 1241 switch (blend) { 1242 case 0 /* setup */: 1243 bone.scaleX = bone.data.scaleX; 1244 bone.scaleY = bone.data.scaleY; 1245 return; 1246 case 1 /* first */: 1247 bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha; 1248 bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha; 1249 } 1250 return; 1251 } 1252 let x, y; 1253 let i = Timeline.search( 1254 frames, 1255 time, 1256 3 1257 /*ENTRIES*/ 1258 ); 1259 let curveType = this.curves[ 1260 i / 3 1261 /*ENTRIES*/ 1262 ]; 1263 switch (curveType) { 1264 case 0: 1265 let before = frames[i]; 1266 x = frames[ 1267 i + 1 1268 /*VALUE1*/ 1269 ]; 1270 y = frames[ 1271 i + 2 1272 /*VALUE2*/ 1273 ]; 1274 let t = (time - before) / (frames[ 1275 i + 3 1276 /*ENTRIES*/ 1277 ] - before); 1278 x += (frames[ 1279 i + 3 + 1 1280 /*VALUE1*/ 1281 ] - x) * t; 1282 y += (frames[ 1283 i + 3 + 2 1284 /*VALUE2*/ 1285 ] - y) * t; 1286 break; 1287 case 1: 1288 x = frames[ 1289 i + 1 1290 /*VALUE1*/ 1291 ]; 1292 y = frames[ 1293 i + 2 1294 /*VALUE2*/ 1295 ]; 1296 break; 1297 default: 1298 x = this.getBezierValue( 1299 time, 1300 i, 1301 1, 1302 curveType - 2 1303 /*BEZIER*/ 1304 ); 1305 y = this.getBezierValue( 1306 time, 1307 i, 1308 2, 1309 curveType + 18 - 2 1310 /*BEZIER*/ 1311 ); 1312 } 1313 x *= bone.data.scaleX; 1314 y *= bone.data.scaleY; 1315 if (alpha == 1) { 1316 if (blend == 3 /* add */) { 1317 bone.scaleX += x - bone.data.scaleX; 1318 bone.scaleY += y - bone.data.scaleY; 1319 } else { 1320 bone.scaleX = x; 1321 bone.scaleY = y; 1322 } 1323 } else { 1324 let bx = 0, by = 0; 1325 if (direction == 1 /* mixOut */) { 1326 switch (blend) { 1327 case 0 /* setup */: 1328 bx = bone.data.scaleX; 1329 by = bone.data.scaleY; 1330 bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha; 1331 bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha; 1332 break; 1333 case 1 /* first */: 1334 case 2 /* replace */: 1335 bx = bone.scaleX; 1336 by = bone.scaleY; 1337 bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha; 1338 bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha; 1339 break; 1340 case 3 /* add */: 1341 bone.scaleX += (x - bone.data.scaleX) * alpha; 1342 bone.scaleY += (y - bone.data.scaleY) * alpha; 1343 } 1344 } else { 1345 switch (blend) { 1346 case 0 /* setup */: 1347 bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x); 1348 by = Math.abs(bone.data.scaleY) * MathUtils.signum(y); 1349 bone.scaleX = bx + (x - bx) * alpha; 1350 bone.scaleY = by + (y - by) * alpha; 1351 break;
1352 case 1 /* first */: 1353 case 2 /* replace */: 1354 bx = Math.abs(bone.scaleX) * MathUtils.signum(x); 1355 by = Math.abs(bone.scaleY) * MathUtils.signum(y); 1356 bone.scaleX = bx + (x - bx) * alpha; 1357 bone.scaleY = by + (y - by) * alpha; 1358 break; 1359 case 3 /* add */: 1360 bone.scaleX += (x - bone.data.scaleX) * alpha; 1361 bone.scaleY += (y - bone.data.scaleY) * alpha; 1362 } 1363 } 1364 } 1365 } 1366 }; 1367 var ScaleXTimeline = class extends CurveTimeline1 { 1368 boneIndex = 0; 1369 constructor(frameCount, bezierCount, boneIndex) { 1370 super(frameCount, bezierCount, Property.scaleX + "|" + boneIndex); 1371 this.boneIndex = boneIndex; 1372 } 1373 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1374 let bone = skeleton.bones[this.boneIndex]; 1375 if (bone.active) bone.scaleX = this.getScaleValue(time, alpha, blend, direction, bone.scaleX, bone.data.scaleX); 1376 } 1377 }; 1378 var ScaleYTimeline = class extends CurveTimeline1 { 1379 boneIndex = 0; 1380 constructor(frameCount, bezierCount, boneIndex) { 1381 super(frameCount, bezierCount, Property.scaleY + "|" + boneIndex); 1382 this.boneIndex = boneIndex; 1383 } 1384 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1385 let bone = skeleton.bones[this.boneIndex]; 1386 if (bone.active) bone.scaleY = this.getScaleValue(time, alpha, blend, direction, bone.scaleY, bone.data.scaleY); 1387 } 1388 }; 1389 var ShearTimeline = class extends CurveTimeline2 { 1390 boneIndex = 0; 1391 constructor(frameCount, bezierCount, boneIndex) { 1392 super( 1393 frameCount, 1394 bezierCount, 1395 Property.shearX + "|" + boneIndex, 1396 Property.shearY + "|" + boneIndex 1397 ); 1398 this.boneIndex = boneIndex; 1399 } 1400 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1401 let bone = skeleton.bones[this.boneIndex]; 1402 if (!bone.active) return; 1403 let frames = this.frames; 1404 if (time < frames[0]) { 1405 switch (blend) { 1406 case 0 /* setup */: 1407 bone.shearX = bone.data.shearX; 1408 bone.shearY = bone.data.shearY; 1409 return; 1410 case 1 /* first */: 1411 bone.shearX += (bone.data.shearX - bone.shearX) * alpha; 1412 bone.shearY += (bone.data.shearY - bone.shearY) * alpha; 1413 } 1414 return; 1415 } 1416 let x = 0, y = 0; 1417 let i = Timeline.search( 1418 frames, 1419 time, 1420 3 1421 /*ENTRIES*/ 1422 ); 1423 let curveType = this.curves[ 1424 i / 3 1425 /*ENTRIES*/ 1426 ]; 1427 switch (curveType) { 1428 case 0: 1429 let before = frames[i]; 1430 x = frames[ 1431 i + 1 1432 /*VALUE1*/ 1433 ]; 1434 y = frames[ 1435 i + 2 1436 /*VALUE2*/ 1437 ]; 1438 let t = (time - before) / (frames[ 1439 i + 3 1440 /*ENTRIES*/ 1441 ] - before); 1442 x += (frames[ 1443 i + 3 + 1 1444 /*VALUE1*/ 1445 ] - x) * t; 1446 y += (frames[ 1447 i + 3 + 2 1448 /*VALUE2*/ 1449 ] - y) * t; 1450 break; 1451 case 1: 1452 x = frames[ 1453 i + 1 1454 /*VALUE1*/ 1455 ]; 1456 y = frames[ 1457 i + 2 1458 /*VALUE2*/ 1459 ]; 1460 break; 1461 default: 1462 x = this.getBezierValue( 1463 time, 1464 i, 1465 1, 1466 curveType - 2 1467 /*BEZIER*/ 1468 ); 1469 y = this.getBezierValue( 1470 time, 1471 i, 1472 2, 1473 curveType + 18 - 2 1474 /*BEZIER*/ 1475 ); 1476 } 1477 switch (blend) { 1478 case 0 /* setup */: 1479 bone.shearX = bone.data.shearX + x * alpha; 1480 bone.shearY = bone.data.shearY + y * alpha; 1481 break; 1482 case 1 /* first */: 1483 case 2 /* replace */: 1484 bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha; 1485 bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha; 1486 break; 1487 case 3 /* add */: 1488 bone.shearX += x * alpha; 1489 bone.shearY += y * alpha; 1490 } 1491 } 1492 }; 1493 var ShearXTimeline = class extends CurveTimeline1 { 1494 boneIndex = 0; 1495 constructor(frameCount, bezierCount, boneIndex) {
1496 super(frameCount, bezierCount, Property.shearX + "|" + boneIndex); 1497 this.boneIndex = boneIndex; 1498 } 1499 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1500 let bone = skeleton.bones[this.boneIndex]; 1501 if (bone.active) bone.shearX = this.getRelativeValue(time, alpha, blend, bone.shearX, bone.data.shearX); 1502 } 1503 }; 1504 var ShearYTimeline = class extends CurveTimeline1 { 1505 boneIndex = 0; 1506 constructor(frameCount, bezierCount, boneIndex) { 1507 super(frameCount, bezierCount, Property.shearY + "|" + boneIndex); 1508 this.boneIndex = boneIndex; 1509 } 1510 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1511 let bone = skeleton.bones[this.boneIndex]; 1512 if (bone.active) bone.shearY = this.getRelativeValue(time, alpha, blend, bone.shearY, bone.data.shearY); 1513 } 1514 }; 1515 var InheritTimeline = class extends Timeline { 1516 boneIndex = 0; 1517 constructor(frameCount, boneIndex) { 1518 super(frameCount, [Property.inherit + "|" + boneIndex]); 1519 this.boneIndex = boneIndex; 1520 } 1521 getFrameEntries() { 1522 return 2; 1523 } 1524 /** Sets the transform mode for the specified frame. 1525 * @param frame Between 0 and <code>frameCount</code>, inclusive. 1526 * @param time The frame time in seconds. */ 1527 setFrame(frame, time, inherit) { 1528 frame *= 2; 1529 this.frames[frame] = time; 1530 this.frames[ 1531 frame + 1 1532 /*INHERIT*/ 1533 ] = inherit; 1534 } 1535 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1536 let bone = skeleton.bones[this.boneIndex]; 1537 if (!bone.active) return; 1538 if (direction == 1 /* mixOut */) { 1539 if (blend == 0 /* setup */) bone.inherit = bone.data.inherit; 1540 return; 1541 } 1542 let frames = this.frames; 1543 if (time < frames[0]) { 1544 if (blend == 0 /* setup */ || blend == 1 /* first */) bone.inherit = bone.data.inherit; 1545 return; 1546 } 1547 bone.inherit = this.frames[ 1548 Timeline.search( 1549 frames, 1550 time, 1551 2 1552 /*ENTRIES*/ 1553 ) + 1 1554 /*INHERIT*/ 1555 ]; 1556 } 1557 }; 1558 var RGBATimeline = class extends CurveTimeline { 1559 slotIndex = 0; 1560 constructor(frameCount, bezierCount, slotIndex) { 1561 super(frameCount, bezierCount, [ 1562 Property.rgb + "|" + slotIndex, 1563 Property.alpha + "|" + slotIndex 1564 ]); 1565 this.slotIndex = slotIndex; 1566 } 1567 getFrameEntries() { 1568 return 5; 1569 } 1570 /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */ 1571 setFrame(frame, time, r, g, b, a) { 1572 frame *= 5; 1573 this.frames[frame] = time; 1574 this.frames[ 1575 frame + 1 1576 /*R*/ 1577 ] = r; 1578 this.frames[ 1579 frame + 2 1580 /*G*/ 1581 ] = g; 1582 this.frames[ 1583 frame + 3 1584 /*B*/ 1585 ] = b; 1586 this.frames[ 1587 frame + 4 1588 /*A*/ 1589 ] = a; 1590 } 1591 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1592 let slot = skeleton.slots[this.slotIndex]; 1593 if (!slot.bone.active) return; 1594 let frames = this.frames; 1595 let color = slot.color; 1596 if (time < frames[0]) { 1597 let setup = slot.data.color; 1598 switch (blend) { 1599 case 0 /* setup */: 1600 color.setFromColor(setup); 1601 return; 1602 case 1 /* first */: 1603 color.add( 1604 (setup.r - color.r) * alpha, 1605 (setup.g - color.g) * alpha, 1606 (setup.b - color.b) * alpha, 1607 (setup.a - color.a) * alpha 1608 ); 1609 } 1610 return; 1611 } 1612 let r = 0, g = 0, b = 0, a = 0; 1613 let i = Timeline.search( 1614 frames, 1615 time, 1616 5 1617 /*ENTRIES*/ 1618 ); 1619 let curveType = this.curves[ 1620 i / 5 1621 /*ENTRIES*/ 1622 ]; 1623 switch (curveType) { 1624 case 0: 1625 let before = frames[i]; 1626 r = frames[ 1627 i + 1 1628 /*R*/ 1629 ]; 1630 g = frames[ 1631 i + 2 1632 /*G*/ 1633 ]; 1634 b = frames[ 1635 i + 3 1636 /*B*/ 1637 ]; 1638 a = frames[ 1639 i + 4 1640 /*A*/ 1641 ]; 1642 let t = (time - before) / (frames[ 1643 i + 5 1644 /*ENTRIES*/ 1645 ] - before); 1646 r += (frames[ 1647 i + 5 + 1 1648 /*R*/ 1649 ] - r) * t; 1650 g += (frames[ 1651 i + 5 + 2 1652 /*G*/ 1653 ] - g) * t; 1654 b += (frames[ 1655 i + 5 + 3 1656 /*B*/ 1657 ] - b) * t; 1658 a += (frames[ 1659 i + 5 + 4 1660 /*A*/ 1661 ] - a) * t; 1662 break; 1663 case 1: 1664 r = frames[ 1665 i + 1 1666 /*R*/ 1667 ]; 1668 g = frames[ 1669 i + 2 1670 /*G*/ 1671 ]; 1672 b = frames[ 1673 i + 3 1674 /*B*/ 1675 ]; 1676 a = frames[ 1677 i + 4 1678 /*A*/ 1679 ]; 1680 break; 1681 default: 1682 r = this.getBezierValue( 1683 time, 1684 i, 1685 1, 1686 curveType - 2 1687 /*BEZIER*/ 1688 ); 1689 g = this.getBezierValue( 1690 time, 1691 i, 1692 2, 1693 curveType + 18 - 2 1694 /*BEZIER*/ 1695 ); 1696 b = this.getBezierValue( 1697 time, 1698 i, 1699 3, 1700 curveType + 18 * 2 - 2 1701 /*BEZIER*/ 1702 ); 1703 a = this.getBezierValue( 1704 time, 1705 i, 1706 4, 1707 curveType + 18 * 3 - 2 1708 /*BEZIER*/ 1709 ); 1710 } 1711 if (alpha == 1) 1712 color.set(r, g, b, a); 1713 else { 1714 if (blend == 0 /* setup */) color.setFromColor(slot.data.color); 1715 color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha); 1716 } 1717 } 1718 }; 1719 var RGBTimeline = class extends CurveTimeline { 1720 slotIndex = 0; 1721 constructor(frameCount, bezierCount, slotIndex) {
1722 super(frameCount, bezierCount, [ 1723 Property.rgb + "|" + slotIndex 1724 ]); 1725 this.slotIndex = slotIndex; 1726 } 1727 getFrameEntries() { 1728 return 4; 1729 } 1730 /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */ 1731 setFrame(frame, time, r, g, b) { 1732 frame <<= 2; 1733 this.frames[frame] = time; 1734 this.frames[ 1735 frame + 1 1736 /*R*/ 1737 ] = r; 1738 this.frames[ 1739 frame + 2 1740 /*G*/ 1741 ] = g; 1742 this.frames[ 1743 frame + 3 1744 /*B*/ 1745 ] = b; 1746 } 1747 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1748 let slot = skeleton.slots[this.slotIndex]; 1749 if (!slot.bone.active) return; 1750 let frames = this.frames; 1751 let color = slot.color; 1752 if (time < frames[0]) { 1753 let setup = slot.data.color; 1754 switch (blend) { 1755 case 0 /* setup */: 1756 color.r = setup.r; 1757 color.g = setup.g; 1758 color.b = setup.b; 1759 return; 1760 case 1 /* first */: 1761 color.r += (setup.r - color.r) * alpha; 1762 color.g += (setup.g - color.g) * alpha; 1763 color.b += (setup.b - color.b) * alpha; 1764 } 1765 return; 1766 } 1767 let r = 0, g = 0, b = 0; 1768 let i = Timeline.search( 1769 frames, 1770 time, 1771 4 1772 /*ENTRIES*/ 1773 ); 1774 let curveType = this.curves[i >> 2]; 1775 switch (curveType) { 1776 case 0: 1777 let before = frames[i]; 1778 r = frames[ 1779 i + 1 1780 /*R*/ 1781 ]; 1782 g = frames[ 1783 i + 2 1784 /*G*/ 1785 ]; 1786 b = frames[ 1787 i + 3 1788 /*B*/ 1789 ]; 1790 let t = (time - before) / (frames[ 1791 i + 4 1792 /*ENTRIES*/ 1793 ] - before); 1794 r += (frames[ 1795 i + 4 + 1 1796 /*R*/ 1797 ] - r) * t; 1798 g += (frames[ 1799 i + 4 + 2 1800 /*G*/ 1801 ] - g) * t; 1802 b += (frames[ 1803 i + 4 + 3 1804 /*B*/ 1805 ] - b) * t; 1806 break; 1807 case 1: 1808 r = frames[ 1809 i + 1 1810 /*R*/ 1811 ]; 1812 g = frames[ 1813 i + 2 1814 /*G*/ 1815 ]; 1816 b = frames[ 1817 i + 3 1818 /*B*/ 1819 ]; 1820 break; 1821 default: 1822 r = this.getBezierValue( 1823 time, 1824 i, 1825 1, 1826 curveType - 2 1827 /*BEZIER*/ 1828 ); 1829 g = this.getBezierValue( 1830 time, 1831 i, 1832 2, 1833 curveType + 18 - 2 1834 /*BEZIER*/ 1835 ); 1836 b = this.getBezierValue( 1837 time, 1838 i, 1839 3, 1840 curveType + 18 * 2 - 2 1841 /*BEZIER*/ 1842 ); 1843 } 1844 if (alpha == 1) { 1845 color.r = r; 1846 color.g = g; 1847 color.b = b; 1848 } else { 1849 if (blend == 0 /* setup */) { 1850 let setup = slot.data.color; 1851 color.r = setup.r; 1852 color.g = setup.g; 1853 color.b = setup.b; 1854 } 1855 color.r += (r - color.r) * alpha; 1856 color.g += (g - color.g) * alpha; 1857 color.b += (b - color.b) * alpha; 1858 } 1859 } 1860 }; 1861 var AlphaTimeline = class extends CurveTimeline1 { 1862 slotIndex = 0; 1863 constructor(frameCount, bezierCount, slotIndex) { 1864 super(frameCount, bezierCount, Property.alpha + "|" + slotIndex); 1865 this.slotIndex = slotIndex; 1866 } 1867 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1868 let slot = skeleton.slots[this.slotIndex]; 1869 if (!slot.bone.active) return; 1870 let color = slot.color; 1871 if (time < this.frames[0]) { 1872 let setup = slot.data.color; 1873 switch (blend) { 1874 case 0 /* setup */: 1875 color.a = setup.a; 1876 return; 1877 case 1 /* first */: 1878 color.a += (setup.a - color.a) * alpha; 1879 } 1880 return; 1881 } 1882 let a = this.getCurveValue(time); 1883 if (alpha == 1) 1884 color.a = a; 1885 else { 1886 if (blend == 0 /* setup */) color.a = slot.data.color.a; 1887 color.a += (a - color.a) * alpha; 1888 } 1889 } 1890 }; 1891 var RGBA2Timeline = class extends CurveTimeline { 1892 slotIndex = 0; 1893 constructor(frameCount, bezierCount, slotIndex) {
1894 super(frameCount, bezierCount, [ 1895 Property.rgb + "|" + slotIndex, 1896 Property.alpha + "|" + slotIndex, 1897 Property.rgb2 + "|" + slotIndex 1898 ]); 1899 this.slotIndex = slotIndex; 1900 } 1901 getFrameEntries() { 1902 return 8; 1903 } 1904 /** Sets the time in seconds, light, and dark colors for the specified key frame. */ 1905 setFrame(frame, time, r, g, b, a, r2, g2, b2) { 1906 frame <<= 3; 1907 this.frames[frame] = time; 1908 this.frames[ 1909 frame + 1 1910 /*R*/ 1911 ] = r; 1912 this.frames[ 1913 frame + 2 1914 /*G*/ 1915 ] = g; 1916 this.frames[ 1917 frame + 3 1918 /*B*/ 1919 ] = b; 1920 this.frames[ 1921 frame + 4 1922 /*A*/ 1923 ] = a; 1924 this.frames[ 1925 frame + 5 1926 /*R2*/ 1927 ] = r2; 1928 this.frames[ 1929 frame + 6 1930 /*G2*/ 1931 ] = g2; 1932 this.frames[ 1933 frame + 7 1934 /*B2*/ 1935 ] = b2; 1936 } 1937 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 1938 let slot = skeleton.slots[this.slotIndex]; 1939 if (!slot.bone.active) return; 1940 let frames = this.frames; 1941 let light = slot.color, dark = slot.darkColor; 1942 if (time < frames[0]) { 1943 let setupLight = slot.data.color, setupDark = slot.data.darkColor; 1944 switch (blend) { 1945 case 0 /* setup */: 1946 light.setFromColor(setupLight); 1947 dark.r = setupDark.r; 1948 dark.g = setupDark.g; 1949 dark.b = setupDark.b; 1950 return; 1951 case 1 /* first */: 1952 light.add( 1953 (setupLight.r - light.r) * alpha, 1954 (setupLight.g - light.g) * alpha, 1955 (setupLight.b - light.b) * alpha, 1956 (setupLight.a - light.a) * alpha 1957 ); 1958 dark.r += (setupDark.r - dark.r) * alpha; 1959 dark.g += (setupDark.g - dark.g) * alpha; 1960 dark.b += (setupDark.b - dark.b) * alpha; 1961 } 1962 return; 1963 } 1964 let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0; 1965 let i = Timeline.search( 1966 frames, 1967 time, 1968 8 1969 /*ENTRIES*/ 1970 ); 1971 let curveType = this.curves[i >> 3]; 1972 switch (curveType) { 1973 case 0: 1974 let before = frames[i]; 1975 r = frames[ 1976 i + 1 1977 /*R*/ 1978 ]; 1979 g = frames[ 1980 i + 2 1981 /*G*/ 1982 ]; 1983 b = frames[ 1984 i + 3 1985 /*B*/ 1986 ]; 1987 a = frames[ 1988 i + 4 1989 /*A*/ 1990 ]; 1991 r2 = frames[ 1992 i + 5 1993 /*R2*/ 1994 ]; 1995 g2 = frames[ 1996 i + 6 1997 /*G2*/ 1998 ]; 1999 b2 = frames[ 2000 i + 7 2001 /*B2*/ 2002 ]; 2003 let t = (time - before) / (frames[ 2004 i + 8 2005 /*ENTRIES*/ 2006 ] - before); 2007 r += (frames[ 2008 i + 8 + 1 2009 /*R*/ 2010 ] - r) * t; 2011 g += (frames[ 2012 i + 8 + 2 2013 /*G*/ 2014 ] - g) * t; 2015 b += (frames[ 2016 i + 8 + 3 2017 /*B*/ 2018 ] - b) * t; 2019 a += (frames[ 2020 i + 8 + 4 2021 /*A*/ 2022 ] - a) * t; 2023 r2 += (frames[ 2024 i + 8 + 5 2025 /*R2*/ 2026 ] - r2) * t; 2027 g2 += (frames[ 2028 i + 8 + 6 2029 /*G2*/ 2030 ] - g2) * t; 2031 b2 += (frames[ 2032 i + 8 + 7 2033 /*B2*/ 2034 ] - b2) * t; 2035 break; 2036 case 1: 2037 r = frames[ 2038 i + 1 2039 /*R*/ 2040 ]; 2041 g = frames[ 2042 i + 2 2043 /*G*/ 2044 ]; 2045 b = frames[ 2046 i + 3 2047 /*B*/ 2048 ]; 2049 a = frames[ 2050 i + 4 2051 /*A*/ 2052 ]; 2053 r2 = frames[ 2054 i + 5 2055 /*R2*/ 2056 ]; 2057 g2 = frames[ 2058 i + 6 2059 /*G2*/ 2060 ]; 2061 b2 = frames[ 2062 i + 7 2063 /*B2*/ 2064 ]; 2065 break; 2066 default: 2067 r = this.getBezierValue( 2068 time, 2069 i, 2070 1, 2071 curveType - 2 2072 /*BEZIER*/ 2073 ); 2074 g = this.getBezierValue( 2075 time, 2076 i, 2077 2, 2078 curveType + 18 - 2 2079 /*BEZIER*/ 2080 ); 2081 b = this.getBezierValue( 2082 time, 2083 i, 2084 3, 2085 curveType + 18 * 2 - 2 2086 /*BEZIER*/ 2087 ); 2088 a = this.getBezierValue( 2089 time, 2090 i, 2091 4, 2092 curveType + 18 * 3 - 2 2093 /*BEZIER*/ 2094 ); 2095 r2 = this.getBezierValue( 2096 time, 2097 i, 2098 5, 2099 curveType + 18 * 4 - 2 2100 /*BEZIER*/ 2101 ); 2102 g2 = this.getBezierValue( 2103 time, 2104 i, 2105 6, 2106 curveType + 18 * 5 - 2 2107 /*BEZIER*/ 2108 ); 2109 b2 = this.getBezierValue( 2110 time, 2111 i, 2112 7, 2113 curveType + 18 * 6 - 2 2114 /*BEZIER*/ 2115 ); 2116 } 2117 if (alpha == 1) { 2118 light.set(r, g, b, a); 2119 dark.r = r2; 2120 dark.g = g2; 2121 dark.b = b2; 2122 } else { 2123 if (blend == 0 /* setup */) { 2124 light.setFromColor(slot.data.color); 2125 let setupDark = slot.data.darkColor; 2126 dark.r = setupDark.r; 2127 dark.g = setupDark.g; 2128 dark.b = setupDark.b; 2129 } 2130 light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha); 2131 dark.r += (r2 - dark.r) * alpha; 2132 dark.g += (g2 - dark.g) * alpha; 2133 dark.b += (b2 - dark.b) * alpha; 2134 } 2135 } 2136 }; 2137 var RGB2Timeline = class extends CurveTimeline { 2138 slotIndex = 0; 2139 constructor(frameCount, bezierCount, slotIndex) {
2140 super(frameCount, bezierCount, [ 2141 Property.rgb + "|" + slotIndex, 2142 Property.rgb2 + "|" + slotIndex 2143 ]); 2144 this.slotIndex = slotIndex; 2145 } 2146 getFrameEntries() { 2147 return 7; 2148 } 2149 /** Sets the time in seconds, light, and dark colors for the specified key frame. */ 2150 setFrame(frame, time, r, g, b, r2, g2, b2) { 2151 frame *= 7; 2152 this.frames[frame] = time; 2153 this.frames[ 2154 frame + 1 2155 /*R*/ 2156 ] = r; 2157 this.frames[ 2158 frame + 2 2159 /*G*/ 2160 ] = g; 2161 this.frames[ 2162 frame + 3 2163 /*B*/ 2164 ] = b; 2165 this.frames[ 2166 frame + 4 2167 /*R2*/ 2168 ] = r2; 2169 this.frames[ 2170 frame + 5 2171 /*G2*/ 2172 ] = g2; 2173 this.frames[ 2174 frame + 6 2175 /*B2*/ 2176 ] = b2; 2177 } 2178 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 2179 let slot = skeleton.slots[this.slotIndex]; 2180 if (!slot.bone.active) return; 2181 let frames = this.frames; 2182 let light = slot.color, dark = slot.darkColor; 2183 if (time < frames[0]) { 2184 let setupLight = slot.data.color, setupDark = slot.data.darkColor; 2185 switch (blend) { 2186 case 0 /* setup */: 2187 light.r = setupLight.r; 2188 light.g = setupLight.g; 2189 light.b = setupLight.b; 2190 dark.r = setupDark.r; 2191 dark.g = setupDark.g; 2192 dark.b = setupDark.b; 2193 return; 2194 case 1 /* first */: 2195 light.r += (setupLight.r - light.r) * alpha; 2196 light.g += (setupLight.g - light.g) * alpha; 2197 light.b += (setupLight.b - light.b) * alpha; 2198 dark.r += (setupDark.r - dark.r) * alpha; 2199 dark.g += (setupDark.g - dark.g) * alpha; 2200 dark.b += (setupDark.b - dark.b) * alpha; 2201 } 2202 return; 2203 } 2204 let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0; 2205 let i = Timeline.search( 2206 frames, 2207 time, 2208 7 2209 /*ENTRIES*/ 2210 ); 2211 let curveType = this.curves[ 2212 i / 7 2213 /*ENTRIES*/ 2214 ]; 2215 switch (curveType) { 2216 case 0: 2217 let before = frames[i]; 2218 r = frames[ 2219 i + 1 2220 /*R*/ 2221 ]; 2222 g = frames[ 2223 i + 2 2224 /*G*/ 2225 ]; 2226 b = frames[ 2227 i + 3 2228 /*B*/ 2229 ]; 2230 r2 = frames[ 2231 i + 4 2232 /*R2*/ 2233 ]; 2234 g2 = frames[ 2235 i + 5 2236 /*G2*/ 2237 ]; 2238 b2 = frames[ 2239 i + 6 2240 /*B2*/ 2241 ]; 2242 let t = (time - before) / (frames[ 2243 i + 7 2244 /*ENTRIES*/ 2245 ] - before); 2246 r += (frames[ 2247 i + 7 + 1 2248 /*R*/ 2249 ] - r) * t; 2250 g += (frames[ 2251 i + 7 + 2 2252 /*G*/ 2253 ] - g) * t; 2254 b += (frames[ 2255 i + 7 + 3 2256 /*B*/ 2257 ] - b) * t; 2258 r2 += (frames[ 2259 i + 7 + 4 2260 /*R2*/ 2261 ] - r2) * t; 2262 g2 += (frames[ 2263 i + 7 + 5 2264 /*G2*/ 2265 ] - g2) * t; 2266 b2 += (frames[ 2267 i + 7 + 6 2268 /*B2*/ 2269 ] - b2) * t; 2270 break; 2271 case 1: 2272 r = frames[ 2273 i + 1 2274 /*R*/ 2275 ]; 2276 g = frames[ 2277 i + 2 2278 /*G*/ 2279 ]; 2280 b = frames[ 2281 i + 3 2282 /*B*/ 2283 ]; 2284 r2 = frames[ 2285 i + 4 2286 /*R2*/ 2287 ]; 2288 g2 = frames[ 2289 i + 5 2290 /*G2*/ 2291 ]; 2292 b2 = frames[ 2293 i + 6 2294 /*B2*/ 2295 ]; 2296 break; 2297 default: 2298 r = this.getBezierValue( 2299 time, 2300 i, 2301 1, 2302 curveType - 2 2303 /*BEZIER*/ 2304 ); 2305 g = this.getBezierValue( 2306 time, 2307 i, 2308 2, 2309 curveType + 18 - 2 2310 /*BEZIER*/ 2311 ); 2312 b = this.getBezierValue( 2313 time, 2314 i, 2315 3, 2316 curveType + 18 * 2 - 2 2317 /*BEZIER*/ 2318 ); 2319 r2 = this.getBezierValue( 2320 time, 2321 i, 2322 4, 2323 curveType + 18 * 3 - 2 2324 /*BEZIER*/ 2325 ); 2326 g2 = this.getBezierValue( 2327 time, 2328 i, 2329 5, 2330 curveType + 18 * 4 - 2 2331 /*BEZIER*/ 2332 ); 2333 b2 = this.getBezierValue( 2334 time, 2335 i, 2336 6, 2337 curveType + 18 * 5 - 2 2338 /*BEZIER*/ 2339 ); 2340 } 2341 if (alpha == 1) { 2342 light.r = r; 2343 light.g = g; 2344 light.b = b; 2345 dark.r = r2; 2346 dark.g = g2; 2347 dark.b = b2; 2348 } else { 2349 if (blend == 0 /* setup */) { 2350 let setupLight = slot.data.color, setupDark = slot.data.darkColor; 2351 light.r = setupLight.r; 2352 light.g = setupLight.g; 2353 light.b = setupLight.b; 2354 dark.r = setupDark.r; 2355 dark.g = setupDark.g; 2356 dark.b = setupDark.b; 2357 } 2358 light.r += (r - light.r) * alpha; 2359 light.g += (g - light.g) * alpha; 2360 light.b += (b - light.b) * alpha; 2361 dark.r += (r2 - dark.r) * alpha; 2362 dark.g += (g2 - dark.g) * alpha; 2363 dark.b += (b2 - dark.b) * alpha; 2364 } 2365 } 2366 }; 2367 var AttachmentTimeline = class extends Timeline { 2368 slotIndex = 0; 2369 /** The attachment name for each key frame. May contain null values to clear the attachment. */ 2370 attachmentNames; 2371 constructor(frameCount, slotIndex) {
2372 super(frameCount, [ 2373 Property.attachment + "|" + slotIndex 2374 ]); 2375 this.slotIndex = slotIndex; 2376 this.attachmentNames = new Array(frameCount); 2377 } 2378 getFrameCount() { 2379 return this.frames.length; 2380 } 2381 /** Sets the time in seconds and the attachment name for the specified key frame. */ 2382 setFrame(frame, time, attachmentName) { 2383 this.frames[frame] = time; 2384 this.attachmentNames[frame] = attachmentName; 2385 } 2386 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 2387 let slot = skeleton.slots[this.slotIndex]; 2388 if (!slot.bone.active) return; 2389 if (direction == 1 /* mixOut */) { 2390 if (blend == 0 /* setup */) this.setAttachment(skeleton, slot, slot.data.attachmentName); 2391 return; 2392 } 2393 if (time < this.frames[0]) { 2394 if (blend == 0 /* setup */ || blend == 1 /* first */) this.setAttachment(skeleton, slot, slot.data.attachmentName); 2395 return; 2396 } 2397 this.setAttachment(skeleton, slot, this.attachmentNames[Timeline.search1(this.frames, time)]); 2398 } 2399 setAttachment(skeleton, slot, attachmentName) { 2400 slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(this.slotIndex, attachmentName)); 2401 } 2402 }; 2403 var DeformTimeline = class extends CurveTimeline { 2404 slotIndex = 0; 2405 /** The attachment that will be deformed. */ 2406 attachment; 2407 /** The vertices for each key frame. */ 2408 vertices; 2409 constructor(frameCount, bezierCount, slotIndex, attachment) { 2410 super(frameCount, bezierCount, [ 2411 Property.deform + "|" + slotIndex + "|" + attachment.id 2412 ]); 2413 this.slotIndex = slotIndex; 2414 this.attachment = attachment; 2415 this.vertices = new Array(frameCount); 2416 } 2417 getFrameCount() { 2418 return this.frames.length; 2419 } 2420 /** Sets the time in seconds and the vertices for the specified key frame. 2421 * @param vertices Vertex positions for an unweighted VertexAttachment, or deform offsets if it has weights. */ 2422 setFrame(frame, time, vertices) { 2423 this.frames[frame] = time; 2424 this.vertices[frame] = vertices; 2425 } 2426 /** @param value1 Ignored (0 is used for a deform timeline). 2427 * @param value2 Ignored (1 is used for a deform timeline). */ 2428 setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) { 2429 let curves = this.curves; 2430 let i = this.getFrameCount() + bezier * 18; 2431 if (value == 0) curves[frame] = 2 + i; 2432 let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06; 2433 let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 6e-3, dddy = (cy1 - cy2 + 0.33333333) * 0.018; 2434 let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy; 2435 let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667; 2436 let x = time1 + dx, y = dy; 2437 for (let n = i + 18; i < n; i += 2) { 2438 curves[i] = x; 2439 curves[i + 1] = y; 2440 dx += ddx; 2441 dy += ddy; 2442 ddx += dddx; 2443 ddy += dddy; 2444 x += dx; 2445 y += dy; 2446 } 2447 } 2448 getCurvePercent(time, frame) { 2449 let curves = this.curves; 2450 let i = curves[frame]; 2451 switch (i) { 2452 case 0: 2453 let x2 = this.frames[frame]; 2454 return (time - x2) / (this.frames[frame + this.getFrameEntries()] - x2); 2455 case 1: 2456 return 0; 2457 } 2458 i -= 2; 2459 if (curves[i] > time) { 2460 let x2 = this.frames[frame]; 2461 return curves[i + 1] * (time - x2) / (curves[i] - x2); 2462 } 2463 let n = i + 18; 2464 for (i += 2; i < n; i += 2) { 2465 if (curves[i] >= time) { 2466 let x2 = curves[i - 2], y2 = curves[i - 1]; 2467 return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2); 2468 } 2469 } 2470 let x = curves[n - 2], y = curves[n - 1]; 2471 return y + (1 - y) * (time - x) / (this.frames[frame + this.getFrameEntries()] - x); 2472 } 2473 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 2474 let slot = skeleton.slots[this.slotIndex]; 2475 if (!slot.bone.active) return; 2476 let slotAttachment = slot.getAttachment(); 2477 if (!slotAttachment) return; 2478 if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.timelineAttachment != this.attachment) return; 2479 let deform = slot.deform; 2480 if (deform.length == 0) blend = 0 /* setup */; 2481 let vertices = this.vertices; 2482 let vertexCount = vertices[0].length; 2483 let frames = this.frames; 2484 if (time < frames[0]) { 2485 switch (blend) { 2486 case 0 /* setup */: 2487 deform.length = 0; 2488 return;
2489 case 1 /* first */: 2490 if (alpha == 1) { 2491 deform.length = 0; 2492 return; 2493 } 2494 deform.length = vertexCount; 2495 let vertexAttachment = slotAttachment; 2496 if (!vertexAttachment.bones) { 2497 let setupVertices = vertexAttachment.vertices; 2498 for (var i = 0; i < vertexCount; i++) 2499 deform[i] += (setupVertices[i] - deform[i]) * alpha; 2500 } else { 2501 alpha = 1 - alpha; 2502 for (var i = 0; i < vertexCount; i++) 2503 deform[i] *= alpha; 2504 } 2505 } 2506 return; 2507 } 2508 deform.length = vertexCount; 2509 if (time >= frames[frames.length - 1]) { 2510 let lastVertices = vertices[frames.length - 1]; 2511 if (alpha == 1) { 2512 if (blend == 3 /* add */) { 2513 let vertexAttachment = slotAttachment; 2514 if (!vertexAttachment.bones) { 2515 let setupVertices = vertexAttachment.vertices; 2516 for (let i2 = 0; i2 < vertexCount; i2++) 2517 deform[i2] += lastVertices[i2] - setupVertices[i2]; 2518 } else { 2519 for (let i2 = 0; i2 < vertexCount; i2++) 2520 deform[i2] += lastVertices[i2]; 2521 } 2522 } else 2523 Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount); 2524 } else { 2525 switch (blend) { 2526 case 0 /* setup */: { 2527 let vertexAttachment2 = slotAttachment; 2528 if (!vertexAttachment2.bones) { 2529 let setupVertices = vertexAttachment2.vertices; 2530 for (let i2 = 0; i2 < vertexCount; i2++) { 2531 let setup = setupVertices[i2]; 2532 deform[i2] = setup + (lastVertices[i2] - setup) * alpha; 2533 } 2534 } else { 2535 for (let i2 = 0; i2 < vertexCount; i2++) 2536 deform[i2] = lastVertices[i2] * alpha; 2537 } 2538 break; 2539 } 2540 case 1 /* first */: 2541 case 2 /* replace */: 2542 for (let i2 = 0; i2 < vertexCount; i2++) 2543 deform[i2] += (lastVertices[i2] - deform[i2]) * alpha; 2544 break; 2545 case 3 /* add */: 2546 let vertexAttachment = slotAttachment; 2547 if (!vertexAttachment.bones) { 2548 let setupVertices = vertexAttachment.vertices; 2549 for (let i2 = 0; i2 < vertexCount; i2++) 2550 deform[i2] += (lastVertices[i2] - setupVertices[i2]) * alpha; 2551 } else { 2552 for (let i2 = 0; i2 < vertexCount; i2++) 2553 deform[i2] += lastVertices[i2] * alpha; 2554 } 2555 } 2556 } 2557 return; 2558 } 2559 let frame = Timeline.search1(frames, time); 2560 let percent = this.getCurvePercent(time, frame); 2561 let prevVertices = vertices[frame]; 2562 let nextVertices = vertices[frame + 1]; 2563 if (alpha == 1) { 2564 if (blend == 3 /* add */) { 2565 let vertexAttachment = slotAttachment; 2566 if (!vertexAttachment.bones) { 2567 let setupVertices = vertexAttachment.vertices; 2568 for (let i2 = 0; i2 < vertexCount; i2++) { 2569 let prev = prevVertices[i2]; 2570 deform[i2] += prev + (nextVertices[i2] - prev) * percent - setupVertices[i2]; 2571 } 2572 } else { 2573 for (let i2 = 0; i2 < vertexCount; i2++) { 2574 let prev = prevVertices[i2]; 2575 deform[i2] += prev + (nextVertices[i2] - prev) * percent; 2576 } 2577 } 2578 } else { 2579 for (let i2 = 0; i2 < vertexCount; i2++) { 2580 let prev = prevVertices[i2]; 2581 deform[i2] = prev + (nextVertices[i2] - prev) * percent; 2582 } 2583 } 2584 } else { 2585 switch (blend) { 2586 case 0 /* setup */: { 2587 let vertexAttachment2 = slotAttachment; 2588 if (!vertexAttachment2.bones) { 2589 let setupVertices = vertexAttachment2.vertices; 2590 for (let i2 = 0; i2 < vertexCount; i2++) { 2591 let prev = prevVertices[i2], setup = setupVertices[i2]; 2592 deform[i2] = setup + (prev + (nextVertices[i2] - prev) * percent - setup) * alpha; 2593 } 2594 } else { 2595 for (let i2 = 0; i2 < vertexCount; i2++) { 2596 let prev = prevVertices[i2]; 2597 deform[i2] = (prev + (nextVertices[i2] - prev) * percent) * alpha; 2598 } 2599 } 2600 break; 2601 }
2602 case 1 /* first */: 2603 case 2 /* replace */: 2604 for (let i2 = 0; i2 < vertexCount; i2++) { 2605 let prev = prevVertices[i2]; 2606 deform[i2] += (prev + (nextVertices[i2] - prev) * percent - deform[i2]) * alpha; 2607 } 2608 break; 2609 case 3 /* add */: 2610 let vertexAttachment = slotAttachment; 2611 if (!vertexAttachment.bones) { 2612 let setupVertices = vertexAttachment.vertices; 2613 for (let i2 = 0; i2 < vertexCount; i2++) { 2614 let prev = prevVertices[i2]; 2615 deform[i2] += (prev + (nextVertices[i2] - prev) * percent - setupVertices[i2]) * alpha; 2616 } 2617 } else { 2618 for (let i2 = 0; i2 < vertexCount; i2++) { 2619 let prev = prevVertices[i2]; 2620 deform[i2] += (prev + (nextVertices[i2] - prev) * percent) * alpha; 2621 } 2622 } 2623 } 2624 } 2625 } 2626 }; 2627 var EventTimeline = class _EventTimeline extends Timeline { 2628 static propertyIds = ["" + Property.event]; 2629 /** The event for each key frame. */ 2630 events; 2631 constructor(frameCount) { 2632 super(frameCount, _EventTimeline.propertyIds); 2633 this.events = new Array(frameCount); 2634 } 2635 getFrameCount() { 2636 return this.frames.length; 2637 } 2638 /** Sets the time in seconds and the event for the specified key frame. */ 2639 setFrame(frame, event) { 2640 this.frames[frame] = event.time; 2641 this.events[frame] = event; 2642 } 2643 /** Fires events for frames > `lastTime` and <= `time`. */ 2644 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 2645 if (!firedEvents) return; 2646 let frames = this.frames; 2647 let frameCount = this.frames.length; 2648 if (lastTime > time) { 2649 this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction); 2650 lastTime = -1; 2651 } else if (lastTime >= frames[frameCount - 1]) 2652 return; 2653 if (time < frames[0]) return; 2654 let i = 0; 2655 if (lastTime < frames[0]) 2656 i = 0; 2657 else { 2658 i = Timeline.search1(frames, lastTime) + 1; 2659 let frameTime = frames[i]; 2660 while (i > 0) { 2661 if (frames[i - 1] != frameTime) break; 2662 i--; 2663 } 2664 } 2665 for (; i < frameCount && time >= frames[i]; i++) 2666 firedEvents.push(this.events[i]); 2667 } 2668 }; 2669 var DrawOrderTimeline = class _DrawOrderTimeline extends Timeline { 2670 static propertyIds = ["" + Property.drawOrder]; 2671 /** The draw order for each key frame. See {@link #setFrame(int, float, int[])}. */ 2672 drawOrders; 2673 constructor(frameCount) { 2674 super(frameCount, _DrawOrderTimeline.propertyIds); 2675 this.drawOrders = new Array(frameCount); 2676 } 2677 getFrameCount() { 2678 return this.frames.length; 2679 } 2680 /** Sets the time in seconds and the draw order for the specified key frame. 2681 * @param drawOrder For each slot in {@link Skeleton#slots}, the index of the new draw order. May be null to use setup pose 2682 * draw order. */ 2683 setFrame(frame, time, drawOrder) { 2684 this.frames[frame] = time; 2685 this.drawOrders[frame] = drawOrder; 2686 } 2687 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 2688 if (direction == 1 /* mixOut */) { 2689 if (blend == 0 /* setup */) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); 2690 return; 2691 } 2692 if (time < this.frames[0]) { 2693 if (blend == 0 /* setup */ || blend == 1 /* first */) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); 2694 return; 2695 } 2696 let idx = Timeline.search1(this.frames, time); 2697 let drawOrderToSetupIndex = this.drawOrders[idx]; 2698 if (!drawOrderToSetupIndex) 2699 Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length); 2700 else { 2701 let drawOrder = skeleton.drawOrder; 2702 let slots = skeleton.slots; 2703 for (let i = 0, n = drawOrderToSetupIndex.length; i < n; i++) 2704 drawOrder[i] = slots[drawOrderToSetupIndex[i]]; 2705 } 2706 } 2707 }; 2708 var IkConstraintTimeline = class extends CurveTimeline { 2709 /** The index of the IK constraint in {@link Skeleton#getIkConstraints()} that will be changed when this timeline is applied */ 2710 constraintIndex = 0; 2711 constructor(frameCount, bezierCount, ikConstraintIndex) {
2712 super(frameCount, bezierCount, [ 2713 Property.ikConstraint + "|" + ikConstraintIndex 2714 ]); 2715 this.constraintIndex = ikConstraintIndex; 2716 } 2717 getFrameEntries() { 2718 return 6; 2719 } 2720 /** Sets the time in seconds, mix, softness, bend direction, compress, and stretch for the specified key frame. */ 2721 setFrame(frame, time, mix, softness, bendDirection, compress, stretch) { 2722 frame *= 6; 2723 this.frames[frame] = time; 2724 this.frames[ 2725 frame + 1 2726 /*MIX*/ 2727 ] = mix; 2728 this.frames[ 2729 frame + 2 2730 /*SOFTNESS*/ 2731 ] = softness; 2732 this.frames[ 2733 frame + 3 2734 /*BEND_DIRECTION*/ 2735 ] = bendDirection; 2736 this.frames[ 2737 frame + 4 2738 /*COMPRESS*/ 2739 ] = compress ? 1 : 0; 2740 this.frames[ 2741 frame + 5 2742 /*STRETCH*/ 2743 ] = stretch ? 1 : 0; 2744 } 2745 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 2746 let constraint = skeleton.ikConstraints[this.constraintIndex]; 2747 if (!constraint.active) return; 2748 let frames = this.frames; 2749 if (time < frames[0]) { 2750 switch (blend) { 2751 case 0 /* setup */: 2752 constraint.mix = constraint.data.mix; 2753 constraint.softness = constraint.data.softness; 2754 constraint.bendDirection = constraint.data.bendDirection; 2755 constraint.compress = constraint.data.compress; 2756 constraint.stretch = constraint.data.stretch; 2757 return; 2758 case 1 /* first */: 2759 constraint.mix += (constraint.data.mix - constraint.mix) * alpha; 2760 constraint.softness += (constraint.data.softness - constraint.softness) * alpha; 2761 constraint.bendDirection = constraint.data.bendDirection; 2762 constraint.compress = constraint.data.compress; 2763 constraint.stretch = constraint.data.stretch; 2764 } 2765 return; 2766 } 2767 let mix = 0, softness = 0; 2768 let i = Timeline.search( 2769 frames, 2770 time, 2771 6 2772 /*ENTRIES*/ 2773 ); 2774 let curveType = this.curves[ 2775 i / 6 2776 /*ENTRIES*/ 2777 ]; 2778 switch (curveType) { 2779 case 0: 2780 let before = frames[i]; 2781 mix = frames[ 2782 i + 1 2783 /*MIX*/ 2784 ]; 2785 softness = frames[ 2786 i + 2 2787 /*SOFTNESS*/ 2788 ]; 2789 let t = (time - before) / (frames[ 2790 i + 6 2791 /*ENTRIES*/ 2792 ] - before); 2793 mix += (frames[ 2794 i + 6 + 1 2795 /*MIX*/ 2796 ] - mix) * t; 2797 softness += (frames[ 2798 i + 6 + 2 2799 /*SOFTNESS*/ 2800 ] - softness) * t; 2801 break; 2802 case 1: 2803 mix = frames[ 2804 i + 1 2805 /*MIX*/ 2806 ]; 2807 softness = frames[ 2808 i + 2 2809 /*SOFTNESS*/ 2810 ]; 2811 break; 2812 default: 2813 mix = this.getBezierValue( 2814 time, 2815 i, 2816 1, 2817 curveType - 2 2818 /*BEZIER*/ 2819 ); 2820 softness = this.getBezierValue( 2821 time, 2822 i, 2823 2, 2824 curveType + 18 - 2 2825 /*BEZIER*/ 2826 ); 2827 } 2828 if (blend == 0 /* setup */) { 2829 constraint.mix = constraint.data.mix + (mix - constraint.data.mix) * alpha; 2830 constraint.softness = constraint.data.softness + (softness - constraint.data.softness) * alpha; 2831 if (direction == 1 /* mixOut */) { 2832 constraint.bendDirection = constraint.data.bendDirection; 2833 constraint.compress = constraint.data.compress; 2834 constraint.stretch = constraint.data.stretch; 2835 } else { 2836 constraint.bendDirection = frames[ 2837 i + 3 2838 /*BEND_DIRECTION*/ 2839 ]; 2840 constraint.compress = frames[ 2841 i + 4 2842 /*COMPRESS*/ 2843 ] != 0; 2844 constraint.stretch = frames[ 2845 i + 5 2846 /*STRETCH*/ 2847 ] != 0; 2848 } 2849 } else { 2850 constraint.mix += (mix - constraint.mix) * alpha; 2851 constraint.softness += (softness - constraint.softness) * alpha; 2852 if (direction == 0 /* mixIn */) { 2853 constraint.bendDirection = frames[ 2854 i + 3 2855 /*BEND_DIRECTION*/ 2856 ]; 2857 constraint.compress = frames[ 2858 i + 4 2859 /*COMPRESS*/ 2860 ] != 0; 2861 constraint.stretch = frames[ 2862 i + 5 2863 /*STRETCH*/ 2864 ] != 0; 2865 } 2866 } 2867 } 2868 }; 2869 var TransformConstraintTimeline = class extends CurveTimeline { 2870 /** The index of the transform constraint slot in {@link Skeleton#transformConstraints} that will be changed. */ 2871 constraintIndex = 0; 2872 constructor(frameCount, bezierCount, transformConstraintIndex) {
2873 super(frameCount, bezierCount, [ 2874 Property.transformConstraint + "|" + transformConstraintIndex 2875 ]); 2876 this.constraintIndex = transformConstraintIndex; 2877 } 2878 getFrameEntries() { 2879 return 7; 2880 } 2881 /** The time in seconds, rotate mix, translate mix, scale mix, and shear mix for the specified key frame. */ 2882 setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY) { 2883 let frames = this.frames; 2884 frame *= 7; 2885 frames[frame] = time; 2886 frames[ 2887 frame + 1 2888 /*ROTATE*/ 2889 ] = mixRotate; 2890 frames[ 2891 frame + 2 2892 /*X*/ 2893 ] = mixX; 2894 frames[ 2895 frame + 3 2896 /*Y*/ 2897 ] = mixY; 2898 frames[ 2899 frame + 4 2900 /*SCALEX*/ 2901 ] = mixScaleX; 2902 frames[ 2903 frame + 5 2904 /*SCALEY*/ 2905 ] = mixScaleY; 2906 frames[ 2907 frame + 6 2908 /*SHEARY*/ 2909 ] = mixShearY; 2910 } 2911 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 2912 let constraint = skeleton.transformConstraints[this.constraintIndex]; 2913 if (!constraint.active) return; 2914 let frames = this.frames; 2915 if (time < frames[0]) { 2916 let data = constraint.data; 2917 switch (blend) { 2918 case 0 /* setup */: 2919 constraint.mixRotate = data.mixRotate; 2920 constraint.mixX = data.mixX; 2921 constraint.mixY = data.mixY; 2922 constraint.mixScaleX = data.mixScaleX; 2923 constraint.mixScaleY = data.mixScaleY; 2924 constraint.mixShearY = data.mixShearY; 2925 return; 2926 case 1 /* first */: 2927 constraint.mixRotate += (data.mixRotate - constraint.mixRotate) * alpha; 2928 constraint.mixX += (data.mixX - constraint.mixX) * alpha; 2929 constraint.mixY += (data.mixY - constraint.mixY) * alpha; 2930 constraint.mixScaleX += (data.mixScaleX - constraint.mixScaleX) * alpha; 2931 constraint.mixScaleY += (data.mixScaleY - constraint.mixScaleY) * alpha; 2932 constraint.mixShearY += (data.mixShearY - constraint.mixShearY) * alpha; 2933 } 2934 return; 2935 } 2936 let rotate, x, y, scaleX, scaleY, shearY; 2937 let i = Timeline.search( 2938 frames, 2939 time, 2940 7 2941 /*ENTRIES*/ 2942 ); 2943 let curveType = this.curves[ 2944 i / 7 2945 /*ENTRIES*/ 2946 ]; 2947 switch (curveType) { 2948 case 0: 2949 let before = frames[i]; 2950 rotate = frames[ 2951 i + 1 2952 /*ROTATE*/ 2953 ]; 2954 x = frames[ 2955 i + 2 2956 /*X*/ 2957 ]; 2958 y = frames[ 2959 i + 3 2960 /*Y*/ 2961 ]; 2962 scaleX = frames[ 2963 i + 4 2964 /*SCALEX*/ 2965 ]; 2966 scaleY = frames[ 2967 i + 5 2968 /*SCALEY*/ 2969 ]; 2970 shearY = frames[ 2971 i + 6 2972 /*SHEARY*/ 2973 ]; 2974 let t = (time - before) / (frames[ 2975 i + 7 2976 /*ENTRIES*/ 2977 ] - before); 2978 rotate += (frames[ 2979 i + 7 + 1 2980 /*ROTATE*/ 2981 ] - rotate) * t; 2982 x += (frames[ 2983 i + 7 + 2 2984 /*X*/ 2985 ] - x) * t; 2986 y += (frames[ 2987 i + 7 + 3 2988 /*Y*/ 2989 ] - y) * t; 2990 scaleX += (frames[ 2991 i + 7 + 4 2992 /*SCALEX*/ 2993 ] - scaleX) * t; 2994 scaleY += (frames[ 2995 i + 7 + 5 2996 /*SCALEY*/ 2997 ] - scaleY) * t; 2998 shearY += (frames[ 2999 i + 7 + 6 3000 /*SHEARY*/ 3001 ] - shearY) * t; 3002 break; 3003 case 1: 3004 rotate = frames[ 3005 i + 1 3006 /*ROTATE*/ 3007 ]; 3008 x = frames[ 3009 i + 2 3010 /*X*/ 3011 ]; 3012 y = frames[ 3013 i + 3 3014 /*Y*/ 3015 ]; 3016 scaleX = frames[ 3017 i + 4 3018 /*SCALEX*/ 3019 ]; 3020 scaleY = frames[ 3021 i + 5 3022 /*SCALEY*/ 3023 ]; 3024 shearY = frames[ 3025 i + 6 3026 /*SHEARY*/ 3027 ]; 3028 break; 3029 default: 3030 rotate = this.getBezierValue( 3031 time, 3032 i, 3033 1, 3034 curveType - 2 3035 /*BEZIER*/ 3036 ); 3037 x = this.getBezierValue( 3038 time, 3039 i, 3040 2, 3041 curveType + 18 - 2 3042 /*BEZIER*/ 3043 ); 3044 y = this.getBezierValue( 3045 time, 3046 i, 3047 3, 3048 curveType + 18 * 2 - 2 3049 /*BEZIER*/ 3050 ); 3051 scaleX = this.getBezierValue( 3052 time, 3053 i, 3054 4, 3055 curveType + 18 * 3 - 2 3056 /*BEZIER*/ 3057 ); 3058 scaleY = this.getBezierValue( 3059 time, 3060 i, 3061 5, 3062 curveType + 18 * 4 - 2 3063 /*BEZIER*/ 3064 ); 3065 shearY = this.getBezierValue( 3066 time, 3067 i, 3068 6, 3069 curveType + 18 * 5 - 2 3070 /*BEZIER*/ 3071 ); 3072 } 3073 if (blend == 0 /* setup */) { 3074 let data = constraint.data; 3075 constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha; 3076 constraint.mixX = data.mixX + (x - data.mixX) * alpha; 3077 constraint.mixY = data.mixY + (y - data.mixY) * alpha; 3078 constraint.mixScaleX = data.mixScaleX + (scaleX - data.mixScaleX) * alpha; 3079 constraint.mixScaleY = data.mixScaleY + (scaleY - data.mixScaleY) * alpha; 3080 constraint.mixShearY = data.mixShearY + (shearY - data.mixShearY) * alpha; 3081 } else { 3082 constraint.mixRotate += (rotate - constraint.mixRotate) * alpha; 3083 constraint.mixX += (x - constraint.mixX) * alpha; 3084 constraint.mixY += (y - constraint.mixY) * alpha;
3085 constraint.mixScaleX += (scaleX - constraint.mixScaleX) * alpha; 3086 constraint.mixScaleY += (scaleY - constraint.mixScaleY) * alpha; 3087 constraint.mixShearY += (shearY - constraint.mixShearY) * alpha; 3088 } 3089 } 3090 }; 3091 var PathConstraintPositionTimeline = class extends CurveTimeline1 { 3092 /** The index of the path constraint in {@link Skeleton#getPathConstraints()} that will be changed when this timeline is 3093 * applied. */ 3094 constraintIndex = 0; 3095 constructor(frameCount, bezierCount, pathConstraintIndex) { 3096 super(frameCount, bezierCount, Property.pathConstraintPosition + "|" + pathConstraintIndex); 3097 this.constraintIndex = pathConstraintIndex; 3098 } 3099 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 3100 let constraint = skeleton.pathConstraints[this.constraintIndex]; 3101 if (constraint.active) 3102 constraint.position = this.getAbsoluteValue(time, alpha, blend, constraint.position, constraint.data.position); 3103 } 3104 }; 3105 var PathConstraintSpacingTimeline = class extends CurveTimeline1 { 3106 /** The index of the path constraint in {@link Skeleton#getPathConstraints()} that will be changed when this timeline is 3107 * applied. */ 3108 constraintIndex = 0; 3109 constructor(frameCount, bezierCount, pathConstraintIndex) { 3110 super(frameCount, bezierCount, Property.pathConstraintSpacing + "|" + pathConstraintIndex); 3111 this.constraintIndex = pathConstraintIndex; 3112 } 3113 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 3114 let constraint = skeleton.pathConstraints[this.constraintIndex]; 3115 if (constraint.active) 3116 constraint.spacing = this.getAbsoluteValue(time, alpha, blend, constraint.spacing, constraint.data.spacing); 3117 } 3118 }; 3119 var PathConstraintMixTimeline = class extends CurveTimeline { 3120 /** The index of the path constraint in {@link Skeleton#getPathConstraints()} that will be changed when this timeline is 3121 * applied. */ 3122 constraintIndex = 0; 3123 constructor(frameCount, bezierCount, pathConstraintIndex) { 3124 super(frameCount, bezierCount, [ 3125 Property.pathConstraintMix + "|" + pathConstraintIndex 3126 ]); 3127 this.constraintIndex = pathConstraintIndex; 3128 } 3129 getFrameEntries() { 3130 return 4; 3131 } 3132 setFrame(frame, time, mixRotate, mixX, mixY) { 3133 let frames = this.frames; 3134 frame <<= 2; 3135 frames[frame] = time; 3136 frames[ 3137 frame + 1 3138 /*ROTATE*/ 3139 ] = mixRotate; 3140 frames[ 3141 frame + 2 3142 /*X*/ 3143 ] = mixX; 3144 frames[ 3145 frame + 3 3146 /*Y*/ 3147 ] = mixY; 3148 } 3149 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 3150 let constraint = skeleton.pathConstraints[this.constraintIndex]; 3151 if (!constraint.active) return; 3152 let frames = this.frames; 3153 if (time < frames[0]) { 3154 switch (blend) { 3155 case 0 /* setup */: 3156 constraint.mixRotate = constraint.data.mixRotate; 3157 constraint.mixX = constraint.data.mixX; 3158 constraint.mixY = constraint.data.mixY; 3159 return; 3160 case 1 /* first */: 3161 constraint.mixRotate += (constraint.data.mixRotate - constraint.mixRotate) * alpha; 3162 constraint.mixX += (constraint.data.mixX - constraint.mixX) * alpha; 3163 constraint.mixY += (constraint.data.mixY - constraint.mixY) * alpha; 3164 } 3165 return; 3166 } 3167 let rotate, x, y; 3168 let i = Timeline.search( 3169 frames, 3170 time, 3171 4 3172 /*ENTRIES*/ 3173 ); 3174 let curveType = this.curves[i >> 2]; 3175 switch (curveType) { 3176 case 0: 3177 let before = frames[i]; 3178 rotate = frames[ 3179 i + 1 3180 /*ROTATE*/ 3181 ]; 3182 x = frames[ 3183 i + 2 3184 /*X*/ 3185 ]; 3186 y = frames[ 3187 i + 3 3188 /*Y*/ 3189 ]; 3190 let t = (time - before) / (frames[ 3191 i + 4 3192 /*ENTRIES*/ 3193 ] - before); 3194 rotate += (frames[ 3195 i + 4 + 1 3196 /*ROTATE*/ 3197 ] - rotate) * t; 3198 x += (frames[ 3199 i + 4 + 2 3200 /*X*/ 3201 ] - x) * t; 3202 y += (frames[ 3203 i + 4 + 3
3204 /*Y*/ 3205 ] - y) * t; 3206 break; 3207 case 1: 3208 rotate = frames[ 3209 i + 1 3210 /*ROTATE*/ 3211 ]; 3212 x = frames[ 3213 i + 2 3214 /*X*/ 3215 ]; 3216 y = frames[ 3217 i + 3 3218 /*Y*/ 3219 ]; 3220 break; 3221 default: 3222 rotate = this.getBezierValue( 3223 time, 3224 i, 3225 1, 3226 curveType - 2 3227 /*BEZIER*/ 3228 ); 3229 x = this.getBezierValue( 3230 time, 3231 i, 3232 2, 3233 curveType + 18 - 2 3234 /*BEZIER*/ 3235 ); 3236 y = this.getBezierValue( 3237 time, 3238 i, 3239 3, 3240 curveType + 18 * 2 - 2 3241 /*BEZIER*/ 3242 ); 3243 } 3244 if (blend == 0 /* setup */) { 3245 let data = constraint.data; 3246 constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha; 3247 constraint.mixX = data.mixX + (x - data.mixX) * alpha; 3248 constraint.mixY = data.mixY + (y - data.mixY) * alpha; 3249 } else { 3250 constraint.mixRotate += (rotate - constraint.mixRotate) * alpha; 3251 constraint.mixX += (x - constraint.mixX) * alpha; 3252 constraint.mixY += (y - constraint.mixY) * alpha; 3253 } 3254 } 3255 }; 3256 var PhysicsConstraintTimeline = class extends CurveTimeline1 { 3257 /** The index of the physics constraint in {@link Skeleton#getPhysicsConstraints()} that will be changed when this timeline 3258 * is applied, or -1 if all physics constraints in the skeleton will be changed. */ 3259 constraintIndex = 0; 3260 /** @param physicsConstraintIndex -1 for all physics constraints in the skeleton. */ 3261 constructor(frameCount, bezierCount, physicsConstraintIndex, property) { 3262 super(frameCount, bezierCount, property + "|" + physicsConstraintIndex); 3263 this.constraintIndex = physicsConstraintIndex; 3264 } 3265 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 3266 let constraint; 3267 if (this.constraintIndex == -1) { 3268 const value = time >= this.frames[0] ? this.getCurveValue(time) : 0; 3269 for (const constraint2 of skeleton.physicsConstraints) { 3270 if (constraint2.active && this.global(constraint2.data)) 3271 this.set(constraint2, this.getAbsoluteValue2(time, alpha, blend, this.get(constraint2), this.setup(constraint2), value)); 3272 } 3273 } else { 3274 constraint = skeleton.physicsConstraints[this.constraintIndex]; 3275 if (constraint.active) this.set(constraint, this.getAbsoluteValue(time, alpha, blend, this.get(constraint), this.setup(constraint))); 3276 } 3277 } 3278 }; 3279 var PhysicsConstraintInertiaTimeline = class extends PhysicsConstraintTimeline { 3280 constructor(frameCount, bezierCount, physicsConstraintIndex) { 3281 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintInertia); 3282 } 3283 setup(constraint) { 3284 return constraint.data.inertia; 3285 } 3286 get(constraint) { 3287 return constraint.inertia; 3288 } 3289 set(constraint, value) { 3290 constraint.inertia = value; 3291 } 3292 global(constraint) { 3293 return constraint.inertiaGlobal; 3294 } 3295 }; 3296 var PhysicsConstraintStrengthTimeline = class extends PhysicsConstraintTimeline { 3297 constructor(frameCount, bezierCount, physicsConstraintIndex) { 3298 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintStrength); 3299 } 3300 setup(constraint) { 3301 return constraint.data.strength; 3302 } 3303 get(constraint) { 3304 return constraint.strength; 3305 } 3306 set(constraint, value) { 3307 constraint.strength = value; 3308 } 3309 global(constraint) { 3310 return constraint.strengthGlobal; 3311 } 3312 }; 3313 var PhysicsConstraintDampingTimeline = class extends PhysicsConstraintTimeline { 3314 constructor(frameCount, bezierCount, physicsConstraintIndex) { 3315 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintDamping); 3316 } 3317 setup(constraint) { 3318 return constraint.data.damping; 3319 } 3320 get(constraint) { 3321 return constraint.damping; 3322 } 3323 set(constraint, value) { 3324 constraint.damping = value; 3325 } 3326 global(constraint) { 3327 return constraint.dampingGlobal; 3328 } 3329 }; 3330 var PhysicsConstraintMassTimeline = class extends PhysicsConstraintTimeline { 3331 constructor(frameCount, bezierCount, physicsConstraintIndex) {
3332 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintMass); 3333 } 3334 setup(constraint) { 3335 return 1 / constraint.data.massInverse; 3336 } 3337 get(constraint) { 3338 return 1 / constraint.massInverse; 3339 } 3340 set(constraint, value) { 3341 constraint.massInverse = 1 / value; 3342 } 3343 global(constraint) { 3344 return constraint.massGlobal; 3345 } 3346 }; 3347 var PhysicsConstraintWindTimeline = class extends PhysicsConstraintTimeline { 3348 constructor(frameCount, bezierCount, physicsConstraintIndex) { 3349 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintWind); 3350 } 3351 setup(constraint) { 3352 return constraint.data.wind; 3353 } 3354 get(constraint) { 3355 return constraint.wind; 3356 } 3357 set(constraint, value) { 3358 constraint.wind = value; 3359 } 3360 global(constraint) { 3361 return constraint.windGlobal; 3362 } 3363 }; 3364 var PhysicsConstraintGravityTimeline = class extends PhysicsConstraintTimeline { 3365 constructor(frameCount, bezierCount, physicsConstraintIndex) { 3366 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintGravity); 3367 } 3368 setup(constraint) { 3369 return constraint.data.gravity; 3370 } 3371 get(constraint) { 3372 return constraint.gravity; 3373 } 3374 set(constraint, value) { 3375 constraint.gravity = value; 3376 } 3377 global(constraint) { 3378 return constraint.gravityGlobal; 3379 } 3380 }; 3381 var PhysicsConstraintMixTimeline = class extends PhysicsConstraintTimeline { 3382 constructor(frameCount, bezierCount, physicsConstraintIndex) { 3383 super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintMix); 3384 } 3385 setup(constraint) { 3386 return constraint.data.mix; 3387 } 3388 get(constraint) { 3389 return constraint.mix; 3390 } 3391 set(constraint, value) { 3392 constraint.mix = value; 3393 } 3394 global(constraint) { 3395 return constraint.mixGlobal; 3396 } 3397 }; 3398 var PhysicsConstraintResetTimeline = class _PhysicsConstraintResetTimeline extends Timeline { 3399 static propertyIds = [Property.physicsConstraintReset.toString()]; 3400 /** The index of the physics constraint in {@link Skeleton#getPhysicsConstraints()} that will be reset when this timeline is 3401 * applied, or -1 if all physics constraints in the skeleton will be reset. */ 3402 constraintIndex; 3403 /** @param physicsConstraintIndex -1 for all physics constraints in the skeleton. */ 3404 constructor(frameCount, physicsConstraintIndex) { 3405 super(frameCount, _PhysicsConstraintResetTimeline.propertyIds); 3406 this.constraintIndex = physicsConstraintIndex; 3407 } 3408 getFrameCount() { 3409 return this.frames.length; 3410 } 3411 /** Sets the time for the specified frame. 3412 * @param frame Between 0 and <code>frameCount</code>, inclusive. */ 3413 setFrame(frame, time) { 3414 this.frames[frame] = time; 3415 } 3416 /** Resets the physics constraint when frames > <code>lastTime</code> and <= <code>time</code>. */ 3417 apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) { 3418 let constraint; 3419 if (this.constraintIndex != -1) { 3420 constraint = skeleton.physicsConstraints[this.constraintIndex]; 3421 if (!constraint.active) return; 3422 } 3423 const frames = this.frames; 3424 if (lastTime > time) { 3425 this.apply(skeleton, lastTime, Number.MAX_VALUE, [], alpha, blend, direction); 3426 lastTime = -1; 3427 } else if (lastTime >= frames[frames.length - 1]) 3428 return; 3429 if (time < frames[0]) return; 3430 if (lastTime < frames[0] || time >= frames[Timeline.search1(frames, lastTime) + 1]) { 3431 if (constraint != null) 3432 constraint.reset(); 3433 else { 3434 for (const constraint2 of skeleton.physicsConstraints) { 3435 if (constraint2.active) constraint2.reset(); 3436 } 3437 } 3438 } 3439 } 3440 }; 3441 var SequenceTimeline = class _SequenceTimeline extends Timeline { 3442 static ENTRIES = 3; 3443 static MODE = 1; 3444 static DELAY = 2; 3445 slotIndex; 3446 attachment; 3447 constructor(frameCount, slotIndex, attachment) { 3448 super(frameCount, [ 3449 Property.sequence + "|" + slotIndex + "|" + attachment.sequence.id 3450 ]); 3451 this.slotIndex = slotIndex; 3452 this.attachment = attachment; 3453 } 3454 getFrameEntries() { 3455 return _SequenceTimeline.ENTRIES; 3456 } 3457 getSlotIndex() { 3458 return this.slotIndex; 3459 } 3460 getAttachment() { 3461 return this.attachment; 3462 } 3463 /** Sets the time, mode, index, and frame time for the specified frame. 3464 * @param frame Between 0 and <code>frameCount</code>, inclusive. 3465 * @param time Seconds between frames. */
3466 setFrame(frame, time, mode, index, delay) { 3467 let frames = this.frames; 3468 frame *= _SequenceTimeline.ENTRIES; 3469 frames[frame] = time; 3470 frames[frame + _SequenceTimeline.MODE] = mode | index << 4; 3471 frames[frame + _SequenceTimeline.DELAY] = delay; 3472 } 3473 apply(skeleton, lastTime, time, events, alpha, blend, direction) { 3474 let slot = skeleton.slots[this.slotIndex]; 3475 if (!slot.bone.active) return; 3476 let slotAttachment = slot.attachment; 3477 let attachment = this.attachment; 3478 if (slotAttachment != attachment) { 3479 if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.timelineAttachment != attachment) return; 3480 } 3481 if (direction == 1 /* mixOut */) { 3482 if (blend == 0 /* setup */) slot.sequenceIndex = -1; 3483 return; 3484 } 3485 let frames = this.frames; 3486 if (time < frames[0]) { 3487 if (blend == 0 /* setup */ || blend == 1 /* first */) slot.sequenceIndex = -1; 3488 return; 3489 } 3490 let i = Timeline.search(frames, time, _SequenceTimeline.ENTRIES); 3491 let before = frames[i]; 3492 let modeAndIndex = frames[i + _SequenceTimeline.MODE]; 3493 let delay = frames[i + _SequenceTimeline.DELAY]; 3494 if (!this.attachment.sequence) return; 3495 let index = modeAndIndex >> 4, count = this.attachment.sequence.regions.length; 3496 let mode = SequenceModeValues[modeAndIndex & 15]; 3497 if (mode != 0 /* hold */) { 3498 index += (time - before) / delay + 1e-5 | 0; 3499 switch (mode) { 3500 case 1 /* once */: 3501 index = Math.min(count - 1, index); 3502 break; 3503 case 2 /* loop */: 3504 index %= count; 3505 break; 3506 case 3 /* pingpong */: { 3507 let n = (count << 1) - 2; 3508 index = n == 0 ? 0 : index % n; 3509 if (index >= count) index = n - index; 3510 break; 3511 } 3512 case 4 /* onceReverse */: 3513 index = Math.max(count - 1 - index, 0); 3514 break; 3515 case 5 /* loopReverse */: 3516 index = count - 1 - index % count; 3517 break; 3518 case 6 /* pingpongReverse */: { 3519 let n = (count << 1) - 2; 3520 index = n == 0 ? 0 : (index + count - 1) % n; 3521 if (index >= count) index = n - index; 3522 } 3523 } 3524 } 3525 slot.sequenceIndex = index; 3526 } 3527 }; 3528 3529
3529// spine-core/src/AnimationState.ts 3530 var AnimationState = class _AnimationState { 3531 static _emptyAnimation = new Animation("<empty>", [], 0); 3532 static emptyAnimation() { 3533 return _AnimationState._emptyAnimation; 3534 } 3535 /** The AnimationStateData to look up mix durations. */ 3536 data; 3537 /** The list of tracks that currently have animations, which may contain null entries. */ 3538 tracks = new Array(); 3539 /** Multiplier for the delta time when the animation state is updated, causing time for all animations and mixes to play slower 3540 * or faster. Defaults to 1. 3541 * 3542 * See TrackEntry {@link TrackEntry#timeScale} for affecting a single animation. */ 3543 timeScale = 1; 3544 unkeyedState = 0; 3545 events = new Array(); 3546 listeners = new Array(); 3547 queue = new EventQueue(this); 3548 propertyIDs = new StringSet(); 3549 animationsChanged = false; 3550 trackEntryPool = new Pool(() => new TrackEntry()); 3551 constructor(data) { 3552 this.data = data; 3553 } 3554 /** Increments each track entry {@link TrackEntry#trackTime()}, setting queued animations as current if needed. */ 3555 update(delta) { 3556 delta *= this.timeScale; 3557 let tracks = this.tracks; 3558 for (let i = 0, n = tracks.length; i < n; i++) { 3559 let current = tracks[i]; 3560 if (!current) continue; 3561 current.animationLast = current.nextAnimationLast; 3562 current.trackLast = current.nextTrackLast; 3563 let currentDelta = delta * current.timeScale; 3564 if (current.delay > 0) { 3565 current.delay -= currentDelta; 3566 if (current.delay > 0) continue; 3567 currentDelta = -current.delay; 3568 current.delay = 0; 3569 } 3570 let next = current.next; 3571 if (next) { 3572 let nextTime = current.trackLast - next.delay; 3573 if (nextTime >= 0) { 3574 next.delay = 0; 3575 next.trackTime += current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale; 3576 current.trackTime += currentDelta; 3577 this.setCurrent(i, next, true); 3578 while (next.mixingFrom) { 3579 next.mixTime += delta; 3580 next = next.mixingFrom; 3581 } 3582 continue; 3583 } 3584 } else if (current.trackLast >= current.trackEnd && !current.mixingFrom) { 3585 tracks[i] = null; 3586 this.queue.end(current); 3587 this.clearNext(current); 3588 continue; 3589 } 3590 if (current.mixingFrom && this.updateMixingFrom(current, delta)) { 3591 let from = current.mixingFrom; 3592 current.mixingFrom = null; 3593 if (from) from.mixingTo = null; 3594 while (from) { 3595 this.queue.end(from); 3596 from = from.mixingFrom; 3597 } 3598 } 3599 current.trackTime += currentDelta; 3600 } 3601 this.queue.drain(); 3602 } 3603 /** Returns true when all mixing from entries are complete. */ 3604 updateMixingFrom(to, delta) { 3605 let from = to.mixingFrom; 3606 if (!from) return true; 3607 let finished = this.updateMixingFrom(from, delta); 3608 from.animationLast = from.nextAnimationLast; 3609 from.trackLast = from.nextTrackLast; 3610 if (to.nextTrackLast != -1 && to.mixTime >= to.mixDuration) { 3611 if (from.totalAlpha == 0 || to.mixDuration == 0) { 3612 to.mixingFrom = from.mixingFrom; 3613 if (from.mixingFrom != null) from.mixingFrom.mixingTo = to; 3614 to.interruptAlpha = from.interruptAlpha; 3615 this.queue.end(from); 3616 } 3617 return finished; 3618 } 3619 from.trackTime += delta * from.timeScale; 3620 to.mixTime += delta; 3621 return false; 3622 } 3623 /** Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the 3624 * animation state can be applied to multiple skeletons to pose them identically. 3625 * @returns True if any animations were applied. */ 3626 apply(skeleton) { 3627 if (!skeleton) throw new Error("skeleton cannot be null."); 3628 if (this.animationsChanged) this._animationsChanged(); 3629 let events = this.events; 3630 let tracks = this.tracks; 3631 let applied = false; 3632 for (let i2 = 0, n2 = tracks.length; i2 < n2; i2++) { 3633 let current = tracks[i2]; 3634 if (!current || current.delay > 0) continue; 3635 applied = true; 3636 let blend = i2 == 0 ? 1 /* first */ : current.mixBlend; 3637 let alpha = current.alpha; 3638 if (current.mixingFrom) 3639 alpha *= this.applyMixingFrom(current, skeleton, blend); 3640 else if (current.trackTime >= current.trackEnd && !current.next) 3641 alpha = 0; 3642 let attachments = alpha >= current.alphaAttachmentThreshold; 3643 let animationLast = current.animationLast, animationTime = current.getAnimationTime(), applyTime = animationTime; 3644 let applyEvents = events; 3645 if (current.reverse) { 3646 applyTime = current.animation.duration - applyTime; 3647 applyEvents = null; 3648 } 3649 let timelines = current.animation.timelines; 3650 let timelineCount = timelines.length; 3651 if (i2 == 0 && alpha == 1 || blend == 3 /* add */) { 3652 if (i2 == 0) attachments = true; 3653 for (let ii = 0; ii < timelineCount; ii++) { 3654 Utils.webkit602BugfixHelper(alpha, blend); 3655 var timeline = timelines[ii]; 3656 if (timeline instanceof AttachmentTimeline) 3657 this.applyAttachmentTimeline(timeline, skeleton, applyTime, blend, attachments); 3658 else 3659 timeline.apply(skeleton, animationLast, applyTime, applyEvents, alpha, blend, 0 /* mixIn */); 3660 } 3661 } else { 3662 let timelineMode = current.timelineMode; 3663 let shortestRotation = current.shortestRotation; 3664 let firstFrame = !shortestRotation && current.timelinesRotation.length != t
3664imelineCount << 1; 3665 if (firstFrame) current.timelinesRotation.length = timelineCount << 1; 3666 for (let ii = 0; ii < timelineCount; ii++) { 3667 let timeline2 = timelines[ii]; 3668 let timelineBlend = timelineMode[ii] == SUBSEQUENT ? blend : 0 /* setup */; 3669 if (!shortestRotation && timeline2 instanceof RotateTimeline) { 3670 this.applyRotateTimeline(timeline2, skeleton, applyTime, alpha, timelineBlend, current.timelinesRotation, ii << 1, firstFrame); 3671 } else if (timeline2 instanceof AttachmentTimeline) { 3672 this.applyAttachmentTimeline(timeline2, skeleton, applyTime, blend, attachments); 3673 } else { 3674 Utils.webkit602BugfixHelper(alpha, blend); 3675 timeline2.apply(skeleton, animationLast, applyTime, applyEvents, alpha, timelineBlend, 0 /* mixIn */); 3676 } 3677 } 3678 } 3679 this.queueEvents(current, animationTime); 3680 events.length = 0; 3681 current.nextAnimationLast = animationTime; 3682 current.nextTrackLast = current.trackTime; 3683 } 3684 var setupState = this.unkeyedState + SETUP; 3685 var slots = skeleton.slots; 3686 for (var i = 0, n = skeleton.slots.length; i < n; i++) { 3687 var slot = slots[i]; 3688 if (slot.attachmentState == setupState) { 3689 var attachmentName = slot.data.attachmentName; 3690 slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(slot.data.index, attachmentName)); 3691 } 3692 } 3693 this.unkeyedState += 2; 3694 this.queue.drain(); 3695 return applied; 3696 } 3697 applyMixingFrom(to, skeleton, blend) { 3698 let from = to.mixingFrom; 3699 if (from.mixingFrom) this.applyMixingFrom(from, skeleton, blend); 3700 let mix = 0; 3701 if (to.mixDuration == 0) { 3702 mix = 1; 3703 if (blend == 1 /* first */) blend = 0 /* setup */; 3704 } else { 3705 mix = to.mixTime / to.mixDuration; 3706 if (mix > 1) mix = 1; 3707 if (blend != 1 /* first */) blend = from.mixBlend; 3708 } 3709 let attachments = mix < from.mixAttachmentThreshold, drawOrder = mix < from.mixDrawOrderThreshold; 3710 let timelines = from.animation.timelines; 3711 let timelineCount = timelines.length; 3712 let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix); 3713 let animationLast = from.animationLast, animationTime = from.getAnimationTime(), applyTime = animationTime; 3714 let events = null; 3715 if (from.reverse) 3716 applyTime = from.animation.duration - applyTime; 3717 else if (mix < from.eventThreshold) 3718 events = this.events; 3719 if (blend == 3 /* add */) { 3720 for (let i = 0; i < timelineCount; i++) 3721 timelines[i].apply(skeleton, animationLast, applyTime, events, alphaMix, blend, 1 /* mixOut */); 3722 } else { 3723 let timelineMode = from.timelineMode; 3724 let timelineHoldMix = from.timelineHoldMix; 3725 let shortestRotation = from.shortestRotation; 3726 let firstFrame = !shortestRotation && from.timelinesRotation.length != timelineCount << 1; 3727 if (firstFrame) from.timelinesRotation.length = timelineCount << 1; 3728 from.totalAlpha = 0; 3729 for (let i = 0; i < timelineCount; i++) { 3730 let timeline = timelines[i]; 3731 let direction = 1 /* mixOut */; 3732 let timelineBlend; 3733 let alpha = 0; 3734 switch (timelineMode[i]) { 3735 case SUBSEQUENT: 3736 if (!drawOrder && timeline instanceof DrawOrderTimeline) continue; 3737 timelineBlend = blend; 3738 alpha = alphaMix; 3739 break; 3740 case FIRST: 3741 timelineBlend = 0 /* setup */; 3742 alpha = alphaMix; 3743 break; 3744 case HOLD_SUBSEQUENT: 3745 timelineBlend = blend; 3746 alpha = alphaHold; 3747 break; 3748 case HOLD_FIRST: 3749 timelineBlend = 0 /* setup */; 3750 alpha = alphaHold; 3751 break; 3752 default: 3753 timelineBlend = 0 /* setup */; 3754 let holdMix = timelineHoldMix[i]; 3755 alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration); 3756 break; 3757 } 3758 from.totalAlpha += alpha; 3759 if (!shortestRotation && timeline instanceof RotateTimeline) 3760 this.applyRotateTimeline(timeline, skeleton, applyTime, alpha, timelineBlend, from.timelinesRotation, i << 1, firstFrame); 3761 else if (timeline instanceof AttachmentTimeline) 3762 this.applyAttachmentTimeline(timeline, skeleton, applyTime, timelineBlend, attachments && alpha >= from.alphaAttachmentThreshold); 3763 else { 3764 Utils.webkit602BugfixHelper(alpha, blend); 3765 if (drawOrder && timeline instanceof DrawOrderTimeline && timelineBlend == 0 /* setup */) 3766 direction = 0 /* mixIn */; 3767 timeline.apply(skeleton, animationLast, applyTime, events, alpha, timelineBlend, direction); 3768 } 3769 } 3770 } 3771 if (to.mixDuration > 0) this.queueEvents(from, animationTime); 3772 this.events.length = 0; 3773 from.nextAnimationLast = animationTime; 3774 from.nextTrackLast = from.trackTime; 3775 return mix; 3776 } 3777 applyAttachmentTimeline(timeline, skeleton, time, blend, attachments) { 3778 var slot = skeleton.slots[timeline.slotIndex]; 3779 if (!slot.bone.active) return; 3780 if (time < timeline.frames[0]) { 3781 if (blend == 0 /* setup */ || blend == 1 /* first */) 3782 this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments); 3783 } else 3784 this.setAttachment(skeleton, slot, timeline.attachmentNames[Timeline.search1(timeline.frames, time)], attachments); 3785 if (slot.attachmentState <= this.unkeyedState) slot.attachmentState = this.unkeyedState + SETUP; 3786 } 3787 setAttachment(skeleton, slot, attachmentName, attachments) { 3788 slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(slot.data.index, attachmentName)); 3789 if (attachments) slot.attachmentState = this.unkeyedState + CURRENT; 3790 } 3791 applyRotateTimeline(timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame) { 3792 if (firstFrame) timelinesRotation[i] = 0; 3793 if (alpha == 1) { 3794 timeline.apply(skeleton, 0, time, null, 1, blend, 0 /* mixIn */); 3795 return; 3796 } 3797 let bone = skeleton.bones[timeline.boneIndex]; 3798 if (!bone.active) return; 3799 let frames = timeline.frames; 3800 let r1 = 0, r2 = 0; 3801 if (time < frames[0]) { 3802 switch (blend) { 3803 case 0 /* setup */: 3804 bone.rotation = bone.data.rotation; 3805 default: 3806 return;
3807 case 1 /* first */: 3808 r1 = bone.rotation; 3809 r2 = bone.data.rotation; 3810 } 3811 } else { 3812 r1 = blend == 0 /* setup */ ? bone.data.rotation : bone.rotation; 3813 r2 = bone.data.rotation + timeline.getCurveValue(time); 3814 } 3815 let total = 0, diff = r2 - r1; 3816 diff -= Math.ceil(diff / 360 - 0.5) * 360; 3817 if (diff == 0) { 3818 total = timelinesRotation[i]; 3819 } else { 3820 let lastTotal = 0, lastDiff = 0; 3821 if (firstFrame) { 3822 lastTotal = 0; 3823 lastDiff = diff; 3824 } else { 3825 lastTotal = timelinesRotation[i]; 3826 lastDiff = timelinesRotation[i + 1]; 3827 } 3828 let loops = lastTotal - lastTotal % 360; 3829 total = diff + loops; 3830 let current = diff >= 0, dir = lastTotal >= 0; 3831 if (Math.abs(lastDiff) <= 90 && MathUtils.signum(lastDiff) != MathUtils.signum(diff)) { 3832 if (Math.abs(lastTotal - loops) > 180) { 3833 total += 360 * MathUtils.signum(lastTotal); 3834 dir = current; 3835 } else if (loops != 0) 3836 total -= 360 * MathUtils.signum(lastTotal); 3837 else 3838 dir = current; 3839 } 3840 if (dir != current) total += 360 * MathUtils.signum(lastTotal); 3841 timelinesRotation[i] = total; 3842 } 3843 timelinesRotation[i + 1] = diff; 3844 bone.rotation = r1 + total * alpha; 3845 } 3846 queueEvents(entry, animationTime) { 3847 let animationStart = entry.animationStart, animationEnd = entry.animationEnd; 3848 let duration = animationEnd - animationStart; 3849 let trackLastWrapped = entry.trackLast % duration; 3850 let events = this.events; 3851 let i = 0, n = events.length; 3852 for (; i < n; i++) { 3853 let event = events[i]; 3854 if (event.time < trackLastWrapped) break; 3855 if (event.time > animationEnd) continue; 3856 this.queue.event(entry, event); 3857 } 3858 let complete = false; 3859 if (entry.loop) { 3860 if (duration == 0) 3861 complete = true; 3862 else { 3863 const cycles = Math.floor(entry.trackTime / duration); 3864 complete = cycles > 0 && cycles > Math.floor(entry.trackLast / duration); 3865 } 3866 } else 3867 complete = animationTime >= animationEnd && entry.animationLast < animationEnd; 3868 if (complete) this.queue.complete(entry); 3869 for (; i < n; i++) { 3870 let event = events[i]; 3871 if (event.time < animationStart) continue; 3872 this.queue.event(entry, event); 3873 } 3874 } 3875 /** Removes all animations from all tracks, leaving skeletons in their current pose. 3876 * 3877 * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose, 3878 * rather than leaving them in their current pose. */ 3879 clearTracks() { 3880 let oldDrainDisabled = this.queue.drainDisabled; 3881 this.queue.drainDisabled = true; 3882 for (let i = 0, n = this.tracks.length; i < n; i++) 3883 this.clearTrack(i); 3884 this.tracks.length = 0; 3885 this.queue.drainDisabled = oldDrainDisabled; 3886 this.queue.drain(); 3887 } 3888 /** Removes all animations from the track, leaving skeletons in their current pose. 3889 * 3890 * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose, 3891 * rather than leaving them in their current pose. */ 3892 clearTrack(trackIndex) { 3893 if (trackIndex >= this.tracks.length) return; 3894 let current = this.tracks[trackIndex]; 3895 if (!current) return; 3896 this.queue.end(current); 3897 this.clearNext(current); 3898 let entry = current; 3899 while (true) { 3900 let from = entry.mixingFrom; 3901 if (!from) break; 3902 this.queue.end(from); 3903 entry.mixingFrom = null; 3904 entry.mixingTo = null; 3905 entry = from; 3906 } 3907 this.tracks[current.trackIndex] = null; 3908 this.queue.drain(); 3909 } 3910 setCurrent(index, current, interrupt) { 3911 let from = this.expandToIndex(index); 3912 this.tracks[index] = current; 3913 current.previous = null; 3914 if (from) { 3915 if (interrupt) this.queue.interrupt(from); 3916 current.mixingFrom = from; 3917 from.mixingTo = current; 3918 current.mixTime = 0; 3919 if (from.mixingFrom && from.mixDuration > 0) 3920 current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); 3921 from.timelinesRotation.length = 0; 3922 } 3923 this.queue.start(current); 3924 } 3925 /** Sets an animation by name. 3926 * 3927 * See {@link #setAnimationWith()}. */ 3928 setAnimation(trackIndex, animationName, loop = false) { 3929 let animation = this.data.skeletonData.findAnimation(animationName); 3930 if (!animation) throw new Error("Animation not found: " + animationName); 3931 return this.setAnimationWith(trackIndex, animation, loop); 3932 } 3933 /** Sets the current animation for a track, discarding any queued animations. If the formerly current track entry was never 3934 * applied to a skeleton, it is replaced (not mixed from). 3935 * @param loop If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its 3936 * duration. In either case {@link TrackEntry#trackEnd} determines when the track is cleared. 3937 * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept 3938 * after the {@link AnimationStateListener#dispose()} event occurs. */ 3939 setAnimationWith(trackIndex, animation, loop = false) { 3940 if (!animation) throw new Error("animation cannot be null."); 3941 let interrupt = true; 3942 let current = this.expandToIndex(trackIndex); 3943 if (current) { 3944 if (current.nextTrackLast == -1) { 3945 this.tracks[trackIndex] = current.mixingFrom; 3946 this.queue.interrupt(current); 3947 this.queue.end(current); 3948 this.clearNext(current); 3949 current = current.mixingFrom; 3950 interrupt = false;
3951 } else 3952 this.clearNext(current); 3953 } 3954 let entry = this.trackEntry(trackIndex, animation, loop, current); 3955 this.setCurrent(trackIndex, entry, interrupt); 3956 this.queue.drain(); 3957 return entry; 3958 } 3959 /** Queues an animation by name. 3960 * 3961 * See {@link #addAnimationWith()}. */ 3962 addAnimation(trackIndex, animationName, loop = false, delay = 0) { 3963 let animation = this.data.skeletonData.findAnimation(animationName); 3964 if (!animation) throw new Error("Animation not found: " + animationName); 3965 return this.addAnimationWith(trackIndex, animation, loop, delay); 3966 } 3967 /** Adds an animation to be played after the current or last queued animation for a track. If the track is empty, it is 3968 * equivalent to calling {@link #setAnimationWith()}. 3969 * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry 3970 * minus any mix duration (from the {@link AnimationStateData}) plus the specified `delay` (ie the mix 3971 * ends at (`delay` = 0) or before (`delay` < 0) the previous track entry duration). If the 3972 * previous entry is looping, its next loop completion is used instead of its duration. 3973 * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept 3974 * after the {@link AnimationStateListener#dispose()} event occurs. */ 3975 addAnimationWith(trackIndex, animation, loop = false, delay = 0) { 3976 if (!animation) throw new Error("animation cannot be null."); 3977 let last = this.expandToIndex(trackIndex); 3978 if (last) { 3979 while (last.next) 3980 last = last.next; 3981 } 3982 let entry = this.trackEntry(trackIndex, animation, loop, last); 3983 if (!last) { 3984 this.setCurrent(trackIndex, entry, true); 3985 this.queue.drain(); 3986 if (delay < 0) delay = 0; 3987 } else { 3988 last.next = entry; 3989 entry.previous = last; 3990 if (delay <= 0) delay = Math.max(delay + last.getTrackComplete() - entry.mixDuration, 0); 3991 }
3992 entry.delay = delay; 3993 return entry; 3994 } 3995 /** Sets an empty animation for a track, discarding any queued animations, and sets the track entry's 3996 * {@link TrackEntry#mixduration}. An empty animation has no timelines and serves as a placeholder for mixing in or out. 3997 * 3998 * Mixing out is done by setting an empty animation with a mix duration using either {@link #setEmptyAnimation()}, 3999 * {@link #setEmptyAnimations()}, or {@link #addEmptyAnimation()}. Mixing to an empty animation causes 4000 * the previous animation to be applied less and less over the mix duration. Properties keyed in the previous animation 4001 * transition to the value from lower tracks or to the setup pose value if no lower tracks key the property. A mix duration of 4002 * 0 still mixes out over one frame. 4003 * 4004 * Mixing in is done by first setting an empty animation, then adding an animation using 4005 * {@link #addAnimation()} and on the returned track entry, set the 4006 * {@link TrackEntry#setMixDuration()}. Mixing from an empty animation causes the new animation to be applied more and 4007 * more over the mix duration. Properties keyed in the new animation transition from the value from lower tracks or from the 4008 * setup pose value if no lower tracks key the property to the value keyed in the new animation. */ 4009 setEmptyAnimation(trackIndex, mixDuration = 0) { 4010 let entry = this.setAnimationWith(trackIndex, _AnimationState.emptyAnimation(), false); 4011 entry.mixDuration = mixDuration; 4012 entry.trackEnd = mixDuration; 4013 return entry; 4014 } 4015 /** Adds an empty animation to be played after the current or last queued animation for a track, and sets the track entry's 4016 * {@link TrackEntry#mixDuration}. If the track is empty, it is equivalent to calling 4017 * {@link #setEmptyAnimation()}. 4018 * 4019 * See {@link #setEmptyAnimation()}. 4020 * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry 4021 * minus any mix duration plus the specified `delay` (ie the mix ends at (`delay` = 0) or 4022 * before (`delay` < 0) the previous track entry duration). If the previous entry is looping, its next 4023 * loop completion is used instead of its duration. 4024 * @return A track entry to allow further customization of animation playback. References to the track entry must not be kept 4025 * after the {@link AnimationStateListener#dispose()} event occurs. */ 4026 addEmptyAnimation(trackIndex, mixDuration = 0, delay = 0) { 4027 let entry = this.addAnimationWith(trackIndex, _AnimationState.emptyAnimation(), false, delay);
4028 if (delay <= 0) entry.delay = Math.max(entry.delay + entry.mixDuration - mixDuration, 0); 4029 entry.mixDuration = mixDuration; 4030 entry.trackEnd = mixDuration; 4031 return entry; 4032 } 4033 /** Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix 4034 * duration. */ 4035 setEmptyAnimations(mixDuration = 0) { 4036 let oldDrainDisabled = this.queue.drainDisabled; 4037 this.queue.drainDisabled = true; 4038 for (let i = 0, n = this.tracks.length; i < n; i++) { 4039 let current = this.tracks[i]; 4040 if (current) this.setEmptyAnimation(current.trackIndex, mixDuration); 4041 } 4042 this.queue.drainDisabled = oldDrainDisabled; 4043 this.queue.drain(); 4044 } 4045 expandToIndex(index) { 4046 if (index < this.tracks.length) return this.tracks[index]; 4047 Utils.ensureArrayCapacity(this.tracks, index + 1, null); 4048 this.tracks.length = index + 1; 4049 return null; 4050 } 4051 /** @param last May be null. */ 4052 trackEntry(trackIndex, animation, loop, last) { 4053 let entry = this.trackEntryPool.obtain(); 4054 entry.reset(); 4055 entry.trackIndex = trackIndex; 4056 entry.animation = animation; 4057 entry.loop = loop; 4058 entry.holdPrevious = false; 4059 entry.reverse = false; 4060 entry.shortestRotation = false; 4061 entry.eventThreshold = 0; 4062 entry.alphaAttachmentThreshold = 0; 4063 entry.mixAttachmentThreshold = 0; 4064 entry.mixDrawOrderThreshold = 0; 4065 entry.animationStart = 0; 4066 entry.animationEnd = animation.duration; 4067 entry.animationLast = -1; 4068 entry.nextAnimationLast = -1;
4069 entry.delay = 0; 4070 entry.trackTime = 0; 4071 entry.trackLast = -1; 4072 entry.nextTrackLast = -1; 4073 entry.trackEnd = Number.MAX_VALUE; 4074 entry.timeScale = 1; 4075 entry.alpha = 1; 4076 entry.mixTime = 0; 4077 entry.mixDuration = !last ? 0 : this.data.getMix(last.animation, animation); 4078 entry.interruptAlpha = 1; 4079 entry.totalAlpha = 0; 4080 entry.mixBlend = 2 /* replace */; 4081 return entry; 4082 } 4083 /** Removes the {@link TrackEntry#getNext() next entry} and all entries after it for the specified entry. */ 4084 clearNext(entry) { 4085 let next = entry.next; 4086 while (next) { 4087 this.queue.dispose(next); 4088 next = next.next; 4089 } 4090 entry.next = null; 4091 } 4092 _animationsChanged() { 4093 this.animationsChanged = false; 4094 this.propertyIDs.clear(); 4095 let tracks = this.tracks; 4096 for (let i = 0, n = tracks.length; i < n; i++) { 4097 let entry = tracks[i]; 4098 if (!entry) continue; 4099 while (entry.mixingFrom) 4100 entry = entry.mixingFrom; 4101 do { 4102 if (!entry.mixingTo || entry.mixBlend != 3 /* add */) this.computeHold(entry); 4103 entry = entry.mixingTo; 4104 } while (entry); 4105 } 4106 } 4107 computeHold(entry) { 4108 let to = entry.mixingTo; 4109 let timelines = entry.animation.timelines; 4110 let timelinesCount = entry.animation.timelines.length; 4111 let timelineMode = entry.timelineMode; 4112 timelineMode.length = timelinesCount; 4113 let timelineHoldMix = entry.timelineHoldMix; 4114 timelineHoldMix.length = 0; 4115 let propertyIDs = this.propertyIDs; 4116 if (to && to.holdPrevious) { 4117 for (let i = 0; i < timelinesCount; i++) 4118 timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? HOLD_FIRST : HOLD_SUBSEQUENT; 4119 return; 4120 } 4121 outer: 4122 for (let i = 0; i < timelinesCount; i++) { 4123 let timeline = timelines[i]; 4124 let ids = timeline.getPropertyIds(); 4125 if (!propertyIDs.addAll(ids)) 4126 timelineMode[i] = SUBSEQUENT; 4127 else if (!to || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline || timeline instanceof EventTimeline || !to.animation.hasTimeline(ids)) { 4128 timelineMode[i] = FIRST; 4129 } else { 4130 for (let next = to.mixingTo; next; next = next.mixingTo) { 4131 if (next.animation.hasTimeline(ids)) continue; 4132 if (entry.mixDuration > 0) { 4133 timelineMode[i] = HOLD_MIX; 4134 timelineHoldMix[i] = next; 4135 continue outer; 4136 } 4137 break; 4138 } 4139 timelineMode[i] = HOLD_FIRST; 4140 } 4141 } 4142 } 4143 /** Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing. */ 4144 getCurrent(trackIndex) { 4145 if (trackIndex >= this.tracks.length) return null; 4146 return this.tracks[trackIndex]; 4147 } 4148 /** Adds a listener to receive events for all track entries. */ 4149 addListener(listener) { 4150 if (!listener) throw new Error("listener cannot be null."); 4151 this.listeners.push(listener); 4152 } 4153 /** Removes the listener added with {@link #addListener()}. */ 4154 removeListener(listener) { 4155 let index = this.listeners.indexOf(listener); 4156 if (index >= 0) this.listeners.splice(index, 1); 4157 } 4158 /** Removes all listeners added with {@link #addListener()}. */ 4159 clearListeners() { 4160 this.listeners.length = 0; 4161 } 4162 /** Discards all listener notifications that have not yet been delivered. This can be useful to call from an 4163 * {@link AnimationStateListener} when it is known that further notifications that may have been already queued for delivery 4164 * are not wanted because new animations are being set. */ 4165 clearListenerNotifications() { 4166 this.queue.clear(); 4167 } 4168 }; 4169 var TrackEntry = class { 4170 /** The animation to apply for this track entry. */ 4171 animation = null; 4172 previous = null; 4173 /** The animation queued to start after this animation, or null. `next` makes up a linked list. */ 4174 next = null; 4175 /** The track entry for the previous animation when mixing from the previous animation to this animation, or null if no 4176 * mixing is currently occuring. When mixing from multiple animations, `mixingFrom` makes up a linked list. */ 4177 mixingFrom = null; 4178 /** The track entry for the next animation when mixing from this animation to the next animation, or null if no mixing is 4179 * currently occuring. When mixing to multiple animations, `mixingTo` makes up a linked list. */ 4180 mixingTo = null; 4181 /** The listener for events generated by this track entry, or null. 4182 * 4183 * A track entry returned from {@link AnimationState#setAnimation()} is already the current animation 4184 * for the track, so the track entry listener {@link AnimationStateListener#start()} will not be called. */ 4185 listener = null; 4186 /** The index of the track where this track entry is either current or queued. 4187 * 4188 * See {@link AnimationState#getCurrent()}. */ 4189 trackIndex = 0; 4190 /** If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its 4191 * duration. */ 4192 loop = false;
4193 /** If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead 4194 * of being mixed out. 4195 * 4196 * When mixing between animations that key the same property, if a lower track also keys that property then the value will 4197 * briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0% 4198 * while the second animation mixes from 0% to 100%. Setting `holdPrevious` to true applies the first animation 4199 * at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which 4200 * keys the property, only when a higher track also keys the property. 4201 * 4202 * Snapping will occur if `holdPrevious` is true and this animation does not key all the same properties as the 4203 * previous animation. */ 4204 holdPrevious = false; 4205 reverse = false; 4206 shortestRotation = false; 4207 /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the 4208 * `eventThreshold`, event timelines are applied while this animation is being mixed out. Defaults to 0, so event 4209 * timelines are not applied while this animation is being mixed out. */ 4210 eventThreshold = 0; 4211 /** When the mix percentage ({@link #mixtime} / {@link #mixDuration}) is less than the 4212 * `attachmentThreshold`, attachment timelines are applied while this animation is being mixed out. Defaults to 4213 * 0, so attachment timelines are not applied while this animation is being mixed out. */ 4214 mixAttachmentThreshold = 0; 4215 /** When {@link #getAlpha()} is greater than <code>alphaAttachmentThreshold</code>, attachment timelines are applied. 4216 * Defaults to 0, so attachment timelines are always applied. */ 4217 alphaAttachmentThreshold = 0; 4218 /** When the mix percentage ({@link #getMixTime()} / {@link #getMixDuration()}) is less than the 4219 * <code>mixDrawOrderThreshold</code>, draw order timelines are applied while this animation is being mixed out. Defaults to 4220 * 0, so draw order timelines are not applied while this animation is being mixed out. */ 4221 mixDrawOrderThreshold = 0; 4222 /** Seconds when this animation starts, both initially and after looping. Defaults to 0. 4223 * 4224 * When changing the `animationStart` time, it often makes sense to set {@link #animationLast} to the same 4225 * value to prevent timeline keys before the start time from triggering. */ 4226 animationStart = 0; 4227 /** Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will 4228 * loop back to {@link #animationStart} at this time. Defaults to the animation {@link Animation#duration}. */ 4229 animationEnd = 0; 4230 /** The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this 4231 * animation is applied, event timelines will fire all events between the `animationLast` time (exclusive) and 4232 * `animationTime` (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation 4233 * is applied. */ 4234 animationLast = 0; 4235 nextAnimationLast = 0; 4236 /** Seconds to postpone playing the animation. When this track entry is the current track entry, `delay` 4237 * postpones incrementing the {@link #trackTime}. When this track entry is queued, `delay` is the time from 4238 * the start of the previous animation to when this track entry will become the current track entry (ie when the previous 4239 * track entry {@link TrackEntry#trackTime} >= this track entry's `delay`). 4240 * 4241 * {@link #timeScale} affects the delay. */ 4242 delay = 0; 4243 /** Current time in seconds this track entry has been the current track entry. The track time determines 4244 * {@link #animationTime}. The track time can be set to start the animation at a time other than 0, without affecting 4245 * looping. */ 4246 trackTime = 0; 4247 trackLast = 0; 4248 nextTrackLast = 0; 4249 /** The track time in seconds when this animation will be removed from the track. Defaults to the highest possible float 4250 * value, meaning the animation will be applied until a new animation is set or the track is cleared. If the track end time 4251 * is reached, no other animations are queued for playback, and mixing from any previous animations is complete, then the 4252 * properties keyed by the animation are set to the setup pose and the track is cleared. 4253 * 4254 * It may be desired to use {@link AnimationState#addEmptyAnimation()} rather than have the animation 4255 * abruptly cease being applied. */ 4256 trackEnd = 0; 4257 /** Multiplier for the delta time when this track entry is updated, causing time for this animation to pass slower or 4258 * faster. Defaults to 1. 4259 * 4260 * {@link #mixTime} is not affected by track entry time scale, so {@link #mixDuration}
4260 may need to be adjusted to 4261 * match the animation speed. 4262 * 4263 * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the 4264 * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, assuming time scale to be 1. If 4265 * the time scale is not 1, the delay may need to be adjusted. 4266 * 4267 * See AnimationState {@link AnimationState#timeScale} for affecting all animations. */ 4268 timeScale = 0; 4269 /** Values < 1 mix this animation with the skeleton's current pose (usually the pose resulting from lower tracks). Defaults 4270 * to 1, which overwrites the skeleton's current pose with this animation. 4271 * 4272 * Typically track 0 is used to completely pose the skeleton, then alpha is used on higher tracks. It doesn't make sense to 4273 * use alpha on track 0 if the skeleton pose is from the last frame render. */ 4274 alpha = 0; 4275 /** Seconds from 0 to the {@link #getMixDuration()} when mixing from the previous animation to this animation. May be 4276 * slightly more than `mixDuration` when the mix is complete. */ 4277 mixTime = 0; 4278 /** Seconds for mixing from the previous animation to this animation. Defaults to the value provided by AnimationStateData 4279 * {@link AnimationStateData#getMix()} based on the animation before this animation (if any). 4280 * 4281 * A mix duration of 0 still mixes out over one frame to provide the track entry being mixed out a chance to revert the 4282 * properties it was animating. 4283 * 4284 * The `mixDuration` can be set manually rather than use the value from 4285 * {@link AnimationStateData#getMix()}. In that case, the `mixDuration` can be set for a new 4286 * track entry only before {@link AnimationState#update(float)} is first called. 4287 * 4288 * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the 4289 * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, not a mix duration set 4290 * afterward. */ 4291 _mixDuration = 0; 4292 interruptAlpha = 0; 4293 totalAlpha = 0; 4294 get mixDuration() { 4295 return this._mixDuration; 4296 } 4297 set mixDuration(mixDuration) { 4298 this._mixDuration = mixDuration; 4299 } 4300 setMixDurationWithDelay(mixDuration, delay) { 4301 this._mixDuration = mixDuration; 4302 if (delay <= 0) { 4303 if (this.previous != null) 4304 delay = Math.max(delay + this.previous.getTrackComplete() - mixDuration, 0); 4305 else 4306 delay = 0; 4307 } 4308 this.delay = delay; 4309 } 4310 /** Controls how properties keyed in the animation are mixed with lower tracks. Defaults to {@link MixBlend#replace}, which 4311 * replaces the values from the lower tracks with the animation values. {@link MixBlend#add} adds the animation values to 4312 * the values from the lower tracks. 4313 * 4314 * The `mixBlend` can be set for a new track entry only before {@link AnimationState#apply()} is first 4315 * called. */ 4316 mixBlend = 2 /* replace */; 4317 timelineMode = new Array(); 4318 timelineHoldMix = new Array(); 4319 timelinesRotation = new Array(); 4320 reset() { 4321 this.next = null; 4322 this.previous = null; 4323 this.mixingFrom = null; 4324 this.mixingTo = null; 4325 this.animation = null; 4326 this.listener = null; 4327 this.timelineMode.length = 0; 4328 this.timelineHoldMix.length = 0; 4329 this.timelinesRotation.length = 0; 4330 } 4331 /** Uses {@link #trackTime} to compute the `animationTime`, which is between {@link #animationStart} 4332 * and {@link #animationEnd}. When the `trackTime` is 0, the `animationTime` is equal to the 4333 * `animationStart` time. */ 4334 getAnimationTime() { 4335 if (this.loop) { 4336 let duration = this.animationEnd - this.animationStart; 4337 if (duration == 0) return this.animationStart; 4338 return this.trackTime % duration + this.animationStart; 4339 } 4340 return Math.min(this.trackTime + this.animationStart, this.animationEnd); 4341 } 4342 setAnimationLast(animationLast) { 4343 this.animationLast = animationLast; 4344 this.nextAnimationLast = animationLast; 4345 } 4346 /** Returns true if at least one loop has been completed. 4347 * 4348 * See {@link AnimationStateListener#complete()}. */ 4349 isComplete() { 4350 return this.trackTime >= this.animationEnd - this.animationStart; 4351 } 4352 /** Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the 4353 * long way around when using {@link #alpha} and starting animations on other tracks. 4354 * 4355 * Mixing with {@link MixBlend#replace} involves finding a rotation between two others, which has two possible solutions: 4356 * the short way or the long way around. The two rotations likely change over time, so which direction is the short or long 4357 * way also changes. If the short way was always chosen, bones would flip to the other side when that direction became the 4358 * long way. TrackEntry chooses the short way the first time it is applied and remembers that direction. */ 4359 resetRotationDirections() { 4360 this.timelinesRotation.length = 0; 4361 } 4362 getTrackComplete() { 4363 let duration = this.animationEnd - this.animationStart; 4364 if (duration != 0) { 4365 if (this.loop) return duration * (1 + (this.trackTime / duration | 0)); 4366 if (this.trackTime < duration) return duration; 4367 } 4368 return this.trackTime; 4369 } 4370 /** Returns true if this track entry has been applied at least once. 4371 * <p> 4372 * See {@link AnimationState#apply(Skeleton)}. */ 4373 wasApplied() { 4374 return this.nextTrackLast != -1; 4375 } 4376 /** Returns true if there is a {@link #getNext()} track entry and it will become the current track entry during the next 4377 * {@link AnimationState#update(float)}. */ 4378 isNextReady() { 4379 return this.next != null && this.nextTrackLast - this.next.delay >= 0; 4380 } 4381 }; 4382 var EventQueue = class { 4383 objects = []; 4384 drainDisabled = false;
4385 animState; 4386 constructor(animState) { 4387 this.animState = animState; 4388 } 4389 start(entry) { 4390 this.objects.push(0 /* start */); 4391 this.objects.push(entry); 4392 this.animState.animationsChanged = true; 4393 } 4394 interrupt(entry) { 4395 this.objects.push(1 /* interrupt */); 4396 this.objects.push(entry); 4397 } 4398 end(entry) { 4399 this.objects.push(2 /* end */); 4400 this.objects.push(entry); 4401 this.animState.animationsChanged = true; 4402 } 4403 dispose(entry) { 4404 this.objects.push(3 /* dispose */); 4405 this.objects.push(entry); 4406 } 4407 complete(entry) { 4408 this.objects.push(4 /* complete */); 4409 this.objects.push(entry); 4410 } 4411 event(entry, event) { 4412 this.objects.push(5 /* event */); 4413 this.objects.push(entry); 4414 this.objects.push(event); 4415 } 4416 drain() { 4417 if (this.drainDisabled) return; 4418 this.drainDisabled = true; 4419 let objects = this.objects; 4420 let listeners = this.animState.listeners; 4421 for (let i = 0; i < objects.length; i += 2) { 4422 let type = objects[i]; 4423 let entry = objects[i + 1]; 4424 switch (type) { 4425 case 0 /* start */: 4426 if (entry.listener && entry.listener.start) entry.listener.start(entry); 4427 for (let ii = 0; ii < listeners.length; ii++) { 4428 let listener = listeners[ii]; 4429 if (listener.start) listener.start(entry); 4430 } 4431 break; 4432 case 1 /* interrupt */: 4433 if (entry.listener && entry.listener.interrupt) entry.listener.interrupt(entry); 4434 for (let ii = 0; ii < listeners.length; ii++) { 4435 let listener = listeners[ii]; 4436 if (listener.interrupt) listener.interrupt(entry); 4437 } 4438 break; 4439 case 2 /* end */: 4440 if (entry.listener && entry.listener.end) entry.listener.end(entry); 4441 for (let ii = 0; ii < listeners.length; ii++) { 4442 let listener = listeners[ii]; 4443 if (listener.end) listener.end(entry); 4444 } 4445 // Fall through. 4446 case 3 /* dispose */: 4447 if (entry.listener && entry.listener.dispose) entry.listener.dispose(entry); 4448 for (let ii = 0; ii < listeners.length; ii++) { 4449 let listener = listeners[ii]; 4450 if (listener.dispose) listener.dispose(entry); 4451 } 4452 this.animState.trackEntryPool.free(entry); 4453 break; 4454 case 4 /* complete */: 4455 if (entry.listener && entry.listener.complete) entry.listener.complete(entry); 4456 for (let ii = 0; ii < listeners.length; ii++) { 4457 let listener = listeners[ii]; 4458 if (listener.complete) listener.complete(entry); 4459 } 4460 break; 4461 case 5 /* event */: 4462 let event = objects[i++ + 2]; 4463 if (entry.listener && entry.listener.event) entry.listener.event(entry, event); 4464 for (let ii = 0; ii < listeners.length; ii++) { 4465 let listener = listeners[ii]; 4466 if (listener.event) listener.event(entry, event); 4467 } 4468 break; 4469 } 4470 } 4471 this.clear(); 4472 this.drainDisabled = false; 4473 } 4474 clear() { 4475 this.objects.length = 0; 4476 } 4477 }; 4478 var EventType = /* @__PURE__ */ ((EventType2) => { 4479 EventType2[EventType2["start"] = 0] = "start"; 4480 EventType2[EventType2["interrupt"] = 1] = "interrupt"; 4481 EventType2[EventType2["end"] = 2] = "end"; 4482 EventType2[EventType2["dispose"] = 3] = "dispose"; 4483 EventType2[EventType2["complete"] = 4] = "complete"; 4484 EventType2[EventType2["event"] = 5] = "event"; 4485 return EventType2; 4486 })(EventType || {}); 4487 var AnimationStateAdapter = class { 4488 start(entry) { 4489 } 4490 interrupt(entry) { 4491 } 4492 end(entry) { 4493 } 4494 dispose(entry) { 4495 } 4496 complete(entry) { 4497 } 4498 event(entry, event) { 4499 } 4500 }; 4501 var SUBSEQUENT = 0; 4502 var FIRST = 1; 4503 var HOLD_SUBSEQUENT = 2; 4504 var HOLD_FIRST = 3; 4505 var HOLD_MIX = 4; 4506 var SETUP = 1; 4507 var CURRENT = 2; 4508 4509
4509// spine-core/src/AnimationStateData.ts 4510 var AnimationStateData = class { 4511 /** The SkeletonData to look up animations when they are specified by name. */ 4512 skeletonData; 4513 animationToMixTime = {}; 4514 /** The mix duration to use when no mix duration has been defined between two animations. */ 4515 defaultMix = 0; 4516 constructor(skeletonData) { 4517 if (!skeletonData) throw new Error("skeletonData cannot be null."); 4518 this.skeletonData = skeletonData; 4519 } 4520 /** Sets a mix duration by animation name. 4521 * 4522 * See {@link #setMixWith()}. */ 4523 setMix(fromName, toName, duration) { 4524 let from = this.skeletonData.findAnimation(fromName); 4525 if (!from) throw new Error("Animation not found: " + fromName); 4526 let to = this.skeletonData.findAnimation(toName); 4527 if (!to) throw new Error("Animation not found: " + toName); 4528 this.setMixWith(from, to, duration); 4529 } 4530 /** Sets the mix duration when changing from the specified animation to the other. 4531 * 4532 * See {@link TrackEntry#mixDuration}. */ 4533 setMixWith(from, to, duration) { 4534 if (!from) throw new Error("from cannot be null."); 4535 if (!to) throw new Error("to cannot be null."); 4536 let key = from.name + "." + to.name; 4537 this.animationToMixTime[key] = duration; 4538 } 4539 /** Returns the mix duration to use when changing from the specified animation to the other, or the {@link #defaultMix} if 4540 * no mix duration has been set. */ 4541 getMix(from, to) { 4542 let key = from.name + "." + to.name; 4543 let value = this.animationToMixTime[key]; 4544 return value === void 0 ? this.defaultMix : value; 4545 } 4546 }; 4547 4548
4548// spine-core/src/attachments/BoundingBoxAttachment.ts 4549 var BoundingBoxAttachment = class _BoundingBoxAttachment extends VertexAttachment { 4550 color = new Color(1, 1, 1, 1); 4551 constructor(name) { 4552 super(name); 4553 } 4554 copy() { 4555 let copy = new _BoundingBoxAttachment(this.name); 4556 this.copyTo(copy); 4557 copy.color.setFromColor(this.color); 4558 return copy; 4559 } 4560 }; 4561 4562
4562// spine-core/src/attachments/ClippingAttachment.ts 4563 var ClippingAttachment = class _ClippingAttachment extends VertexAttachment { 4564 /** Clipping is performed between the clipping polygon's slot and the end slot. Returns null if clipping is done until the end of 4565 * the skeleton's rendering. */ 4566 endSlot = null; 4567 // Nonessential. 4568 /** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons 4569 * are not usually rendered at runtime. */ 4570 color = new Color(0.2275, 0.2275, 0.8078, 1); 4571 // ce3a3aff 4572 constructor(name) { 4573 super(name); 4574 } 4575 copy() { 4576 let copy = new _ClippingAttachment(this.name); 4577 this.copyTo(copy); 4578 copy.endSlot = this.endSlot; 4579 copy.color.setFromColor(this.color); 4580 return copy; 4581 } 4582 }; 4583 4584
4584// spine-core/src/Texture.ts 4585 var Texture = class { 4586 _image; 4587 constructor(image) { 4588 this._image = image; 4589 } 4590 getImage() { 4591 return this._image; 4592 } 4593 }; 4594 var TextureFilter = /* @__PURE__ */ ((TextureFilter2) => { 4595 TextureFilter2[TextureFilter2["Nearest"] = 9728] = "Nearest"; 4596 TextureFilter2[TextureFilter2["Linear"] = 9729] = "Linear"; 4597 TextureFilter2[TextureFilter2["MipMap"] = 9987] = "MipMap"; 4598 TextureFilter2[TextureFilter2["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest"; 4599 TextureFilter2[TextureFilter2["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest"; 4600 TextureFilter2[TextureFilter2["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear"; 4601 TextureFilter2[TextureFilter2["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear"; 4602 return TextureFilter2; 4603 })(TextureFilter || {}); 4604 var TextureWrap = /* @__PURE__ */ ((TextureWrap3) => { 4605 TextureWrap3[TextureWrap3["MirroredRepeat"] = 33648] = "MirroredRepeat"; 4606 TextureWrap3[TextureWrap3["ClampToEdge"] = 33071] = "ClampToEdge"; 4607 TextureWrap3[TextureWrap3["Repeat"] = 10497] = "Repeat"; 4608 return TextureWrap3; 4609 })(TextureWrap || {}); 4610 var TextureRegion = class { 4611 texture; 4612 u = 0; 4613 v = 0; 4614 u2 = 0; 4615 v2 = 0; 4616 width = 0; 4617 height = 0; 4618 degrees = 0; 4619 offsetX = 0; 4620 offsetY = 0; 4621 originalWidth = 0; 4622 originalHeight = 0; 4623 }; 4624 var FakeTexture = class extends Texture { 4625 setFilters(minFilter, magFilter) { 4626 } 4627 setWraps(uWrap, vWrap) { 4628 } 4629 dispose() { 4630 } 4631 }; 4632 4633
4633// spine-core/src/TextureAtlas.ts 4634 var TextureAtlas = class { 4635 pages = new Array(); 4636 regions = new Array(); 4637 constructor(atlasText) { 4638 let reader = new TextureAtlasReader(atlasText); 4639 let entry = new Array(4); 4640 let pageFields = {}; 4641 pageFields["size"] = (page2) => { 4642 page2.width = parseInt(entry[1]); 4643 page2.height = parseInt(entry[2]); 4644 }; 4645 pageFields["format"] = () => { 4646 }; 4647 pageFields["filter"] = (page2) => { 4648 page2.minFilter = Utils.enumValue(TextureFilter, entry[1]); 4649 page2.magFilter = Utils.enumValue(TextureFilter, entry[2]); 4650 }; 4651 pageFields["repeat"] = (page2) => { 4652 if (entry[1].indexOf("x") != -1) page2.uWrap = 10497 /* Repeat */; 4653 if (entry[1].indexOf("y") != -1) page2.vWrap = 10497 /* Repeat */; 4654 }; 4655 pageFields["pma"] = (page2) => { 4656 page2.pma = entry[1] == "true"; 4657 }; 4658 var regionFields = {}; 4659 regionFields["xy"] = (region) => { 4660 region.x = parseInt(entry[1]); 4661 region.y = parseInt(entry[2]); 4662 }; 4663 regionFields["size"] = (region) => { 4664 region.width = parseInt(entry[1]); 4665 region.height = parseInt(entry[2]); 4666 }; 4667 regionFields["bounds"] = (region) => { 4668 region.x = parseInt(entry[1]); 4669 region.y = parseInt(entry[2]); 4670 region.width = parseInt(entry[3]); 4671 region.height = parseInt(entry[4]); 4672 }; 4673 regionFields["offset"] = (region) => { 4674 region.offsetX = parseInt(entry[1]); 4675 region.offsetY = parseInt(entry[2]); 4676 }; 4677 regionFields["orig"] = (region) => { 4678 region.originalWidth = parseInt(entry[1]); 4679 region.originalHeight = parseInt(entry[2]); 4680 }; 4681 regionFields["offsets"] = (region) => { 4682 region.offsetX = parseInt(entry[1]); 4683 region.offsetY = parseInt(entry[2]); 4684 region.originalWidth = parseInt(entry[3]); 4685 region.originalHeight = parseInt(entry[4]); 4686 }; 4687 regionFields["rotate"] = (region) => { 4688 let value = entry[1]; 4689 if (value == "true") 4690 region.degrees = 90; 4691 else if (value != "false") 4692 region.degrees = parseInt(value); 4693 }; 4694 regionFields["index"] = (region) => { 4695 region.index = parseInt(entry[1]); 4696 }; 4697 let line = reader.readLine(); 4698 while (line && line.trim().length == 0) 4699 line = reader.readLine(); 4700 while (true) { 4701 if (!line || line.trim().length == 0) break; 4702 if (reader.readEntry(entry, line) == 0) break; 4703 line = reader.readLine(); 4704 } 4705 let page = null; 4706 let names = null; 4707 let values = null; 4708 while (true) { 4709 if (line === null) break; 4710 if (line.trim().length == 0) { 4711 page = null; 4712 line = reader.readLine(); 4713 } else if (!page) { 4714 page = new TextureAtlasPage(line.trim()); 4715 while (true) { 4716 if (reader.readEntry(entry, line = reader.readLine()) == 0) break; 4717 let field = pageFields[entry[0]]; 4718 if (field) field(page); 4719 } 4720 this.pages.push(page); 4721 } else { 4722 let region = new TextureAtlasRegion(page, line); 4723 while (true) { 4724 let count = reader.readEntry(entry, line = reader.readLine()); 4725 if (count == 0) break; 4726 let field = regionFields[entry[0]]; 4727 if (field) 4728 field(region); 4729 else { 4730 if (!names) names = []; 4731 if (!values) values = []; 4732 names.push(entry[0]); 4733 let entryValues = []; 4734 for (let i = 0; i < count; i++) 4735 entryValues.push(parseInt(entry[i + 1])); 4736 values.push(entryValues); 4737 } 4738 } 4739 if (region.originalWidth == 0 && region.originalHeight == 0) { 4740 region.originalWidth = region.width; 4741 region.originalHeight = region.height; 4742 } 4743 if (names && names.length > 0 && values && values.length > 0) { 4744 region.names = names; 4745 region.values = values; 4746 names = null; 4747 values = null; 4748 } 4749 region.u = region.x / page.width; 4750 region.v = region.y / page.height; 4751 if (region.degrees == 90) { 4752 region.u2 = (region.x + region.height) / page.width; 4753 region.v2 = (region.y + region.width) / page.height; 4754 } else { 4755 region.u2 = (region.x + region.width) / page.width; 4756 region.v2 = (region.y + region.height) / page.height; 4757 } 4758 this.regions.push(region); 4759 } 4760 } 4761 } 4762 findRegion(name) { 4763 for (let i = 0; i < this.regions.length; i++) { 4764 if (this.regions[i].name == name) { 4765 return this.regions[i]; 4766 } 4767 } 4768 return null; 4769 } 4770 setTextures(assetManager, pathPrefix = "") { 4771 for (let page of this.pages) 4772 page.setTexture(assetManager.get(pathPrefix + page.name)); 4773 } 4774 dispose() { 4775 for (let i = 0; i < this.pages.length; i++) { 4776 this.pages[i].texture?.dispose(); 4777 } 4778 } 4779 }; 4780 var TextureAtlasReader = class { 4781 lines; 4782 index = 0; 4783 constructor(text) { 4784 this.lines = text.split(/\r\n|\r|\n/); 4785 } 4786 readLine() { 4787 if (this.index >= this.lines.length) 4788 return null; 4789 return this.lines[this.index++]; 4790 } 4791 readEntry(entry, line) { 4792 if (!line) return 0; 4793 line = line.trim(); 4794 if (line.length == 0) return 0; 4795 let colon = line.indexOf(":"); 4796 if (colon == -1) return 0; 4797 entry[0] = line.substr(0, colon).trim(); 4798 for (let i = 1, lastMatch = colon + 1; ; i++) { 4799 let comma = line.indexOf(",", lastMatch); 4800 if (comma == -1) { 4801 entry[i] = line.substr(lastMatch).trim(); 4802 return i; 4803 } 4804 entry[i] = line.substr(lastMatch, comma - lastMatch).trim(); 4805 lastMatch = comma + 1; 4806 if (i == 4) return 4; 4807 } 4808 } 4809 }; 4810 var TextureAtlasPage = class { 4811 name; 4812 minFilter = 9728 /* Nearest */; 4813 magFilter = 9728 /* Nearest */; 4814 uWrap = 33071 /* ClampToEdge */; 4815 vWrap = 33071 /* ClampToEdge */; 4816 texture = null; 4817 width = 0; 4818 height = 0; 4819 pma = false;
4820 regions = new Array(); 4821 constructor(name) { 4822 this.name = name; 4823 } 4824 setTexture(texture) { 4825 this.texture = texture; 4826 texture.setFilters(this.minFilter, this.magFilter); 4827 texture.setWraps(this.uWrap, this.vWrap); 4828 for (let region of this.regions) 4829 region.texture = texture; 4830 } 4831 }; 4832 var TextureAtlasRegion = class extends TextureRegion { 4833 page; 4834 name; 4835 x = 0; 4836 y = 0; 4837 offsetX = 0; 4838 offsetY = 0; 4839 originalWidth = 0; 4840 originalHeight = 0; 4841 index = 0; 4842 degrees = 0; 4843 names = null; 4844 values = null; 4845 constructor(page, name) { 4846 super(); 4847 this.page = page; 4848 this.name = name; 4849 page.regions.push(this); 4850 } 4851 }; 4852 4853
4853// spine-core/src/attachments/MeshAttachment.ts 4854 var MeshAttachment = class _MeshAttachment extends VertexAttachment { 4855 region = null; 4856 /** The name of the texture region for this attachment. */ 4857 path; 4858 /** The UV pair for each vertex, normalized within the texture region. */ 4859 regionUVs = []; 4860 /** The UV pair for each vertex, normalized within the entire texture. 4861 * 4862 * See {@link #updateUVs}. */ 4863 uvs = []; 4864 /** Triplets of vertex indices which describe the mesh's triangulation. */ 4865 triangles = []; 4866 /** The color to tint the mesh. */ 4867 color = new Color(1, 1, 1, 1); 4868 /** The width of the mesh's image. Available only when nonessential data was exported. */ 4869 width = 0; 4870 /** The height of the mesh's image. Available only when nonessential data was exported. */ 4871 height = 0; 4872 /** The number of entries at the beginning of {@link #vertices} that make up the mesh hull. */ 4873 hullLength = 0; 4874 /** Vertex index pairs describing edges for controling triangulation. Mesh triangles will never cross edges. Only available if 4875 * nonessential data was exported. Triangulation is not performed at runtime. */ 4876 edges = []; 4877 parentMesh = null; 4878 sequence = null; 4879 tempColor = new Color(0, 0, 0, 0); 4880 constructor(name, path) { 4881 super(name); 4882 this.path = path; 4883 } 4884 /** Calculates {@link #uvs} using the {@link #regionUVs} and region. Must be called if the region, the region's properties, or 4885 * the {@link #regionUVs} are changed. */ 4886 updateRegion() { 4887 if (!this.region) throw new Error("Region not set."); 4888 let regionUVs = this.regionUVs; 4889 if (!this.uvs || this.uvs.length != regionUVs.length) this.uvs = Utils.newFloatArray(regionUVs.length); 4890 let uvs = this.uvs; 4891 let n = this.uvs.length; 4892 let u = this.region.u, v = this.region.v, width = 0, height = 0; 4893 if (this.region instanceof TextureAtlasRegion) { 4894 let region = this.region, page = region.page; 4895 let textureWidth = page.width, textureHeight = page.height; 4896 switch (region.degrees) { 4897 case 90: 4898 u -= (region.originalHeight - region.offsetY - region.height) / textureWidth; 4899 v -= (region.originalWidth - region.offsetX - region.width) / textureHeight; 4900 width = region.originalHeight / textureWidth; 4901 height = region.originalWidth / textureHeight; 4902 for (let i = 0; i < n; i += 2) { 4903 uvs[i] = u + regionUVs[i + 1] * width; 4904 uvs[i + 1] = v + (1 - regionUVs[i]) * height; 4905 } 4906 return; 4907 case 180: 4908 u -= (region.originalWidth - region.offsetX - region.width) / textureWidth; 4909 v -= region.offsetY / textureHeight; 4910 width = region.originalWidth / textureWidth; 4911 height = region.originalHeight / textureHeight; 4912 for (let i = 0; i < n; i += 2) { 4913 uvs[i] = u + (1 - regionUVs[i]) * width; 4914 uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height; 4915 } 4916 return; 4917 case 270: 4918 u -= region.offsetY / textureWidth; 4919 v -= region.offsetX / textureHeight; 4920 width = region.originalHeight / textureWidth; 4921 height = region.originalWidth / textureHeight; 4922 for (let i = 0; i < n; i += 2) { 4923 uvs[i] = u + (1 - regionUVs[i + 1]) * width; 4924 uvs[i + 1] = v + regionUVs[i] * height; 4925 } 4926 return; 4927 } 4928 u -= region.offsetX / textureWidth; 4929 v -= (region.originalHeight - region.offsetY - region.height) / textureHeight; 4930 width = region.originalWidth / textureWidth; 4931 height = region.originalHeight / textureHeight; 4932 } else if (!this.region) { 4933 u = v = 0; 4934 width = height = 1; 4935 } else { 4936 width = this.region.u2 - u; 4937 height = this.region.v2 - v; 4938 } 4939 for (let i = 0; i < n; i += 2) { 4940 uvs[i] = u + regionUVs[i] * width; 4941 uvs[i + 1] = v + regionUVs[i + 1] * height; 4942 } 4943 } 4944 /** The parent mesh if this is a linked mesh, else null. A linked mesh shares the {@link #bone
4944s}, {@link #vertices}, 4945 * {@link #regionUVs}, {@link #triangles}, {@link #hullLength}, {@link #edges}, {@link #width}, and {@link #height} with the 4946 * parent mesh, but may have a different {@link #name} or {@link #path} (and therefore a different texture). */ 4947 getParentMesh() { 4948 return this.parentMesh; 4949 } 4950 /** @param parentMesh May be null. */ 4951 setParentMesh(parentMesh) { 4952 this.parentMesh = parentMesh; 4953 if (parentMesh) { 4954 this.bones = parentMesh.bones; 4955 this.vertices = parentMesh.vertices; 4956 this.worldVerticesLength = parentMesh.worldVerticesLength; 4957 this.regionUVs = parentMesh.regionUVs; 4958 this.triangles = parentMesh.triangles; 4959 this.hullLength = parentMesh.hullLength; 4960 this.worldVerticesLength = parentMesh.worldVerticesLength; 4961 } 4962 } 4963 copy() { 4964 if (this.parentMesh) return this.newLinkedMesh(); 4965 let copy = new _MeshAttachment(this.name, this.path); 4966 copy.region = this.region; 4967 copy.color.setFromColor(this.color); 4968 this.copyTo(copy); 4969 copy.regionUVs = new Array(this.regionUVs.length); 4970 Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length); 4971 copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array(this.uvs.length); 4972 Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length); 4973 copy.triangles = new Array(this.triangles.length); 4974 Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length); 4975 copy.hullLength = this.hullLength; 4976 copy.sequence = this.sequence != null ? this.sequence.copy() : null; 4977 if (this.edges) { 4978 copy.edges = new Array(this.edges.length); 4979 Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length); 4980 } 4981 copy.width = this.width; 4982 copy.height = this.height; 4983 return copy; 4984 } 4985 computeWorldVertices(slot, start, count, worldVertices, offset, stride) { 4986 if (this.sequence != null) this.sequence.apply(slot, this); 4987 super.computeWorldVertices(slot, start, count, worldVertices, offset, stride); 4988 } 4989 /** Returns a new mesh with the {@link #parentMesh} set to this mesh's parent mesh, if any, else to this mesh. **/ 4990 newLinkedMesh() { 4991 let copy = new _MeshAttachment(this.name, this.path); 4992 copy.region = this.region; 4993 copy.color.setFromColor(this.color); 4994 copy.timelineAttachment = this.timelineAttachment; 4995 copy.setParentMesh(this.parentMesh ? this.parentMesh : this); 4996 if (copy.region != null) copy.updateRegion(); 4997 return copy; 4998 } 4999 }; 5000 5001
5001// spine-core/src/attachments/PathAttachment.ts 5002 var PathAttachment = class _PathAttachment extends VertexAttachment { 5003 /** The lengths along the path in the setup pose from the start of the path to the end of each Bezier curve. */ 5004 lengths = []; 5005 /** If true, the start and end knots are connected. */ 5006 closed = false; 5007 /** If true, additional calculations are performed to make calculating positions along the path more accurate. If false, fewer 5008 * calculations are performed but calculating positions along the path is less accurate. */ 5009 constantSpeed = false; 5010 /** The color of the path as it was in Spine. Available only when nonessential data was exported. Paths are not usually 5011 * rendered at runtime. */ 5012 color = new Color(1, 1, 1, 1); 5013 constructor(name) { 5014 super(name); 5015 } 5016 copy() { 5017 let copy = new _PathAttachment(this.name); 5018 this.copyTo(copy); 5019 copy.lengths = new Array(this.lengths.length); 5020 Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length); 5021 copy.closed = closed; 5022 copy.constantSpeed = this.constantSpeed; 5023 copy.color.setFromColor(this.color); 5024 return copy; 5025 } 5026 }; 5027 5028
5028// spine-core/src/attachments/PointAttachment.ts 5029 var PointAttachment = class _PointAttachment extends VertexAttachment { 5030 x = 0; 5031 y = 0; 5032 rotation = 0; 5033 /** The color of the point attachment as it was in Spine. Available only when nonessential data was exported. Point attachments 5034 * are not usually rendered at runtime. */ 5035 color = new Color(0.38, 0.94, 0, 1); 5036 constructor(name) { 5037 super(name); 5038 } 5039 computeWorldPosition(bone, point) { 5040 point.x = this.x * bone.a + this.y * bone.b + bone.worldX; 5041 point.y = this.x * bone.c + this.y * bone.d + bone.worldY; 5042 return point; 5043 } 5044 computeWorldRotation(bone) { 5045 const r = this.rotation * MathUtils.degRad, cos = Math.cos(r), sin = Math.sin(r); 5046 const x = cos * bone.a + sin * bone.b; 5047 const y = cos * bone.c + sin * bone.d; 5048 return MathUtils.atan2Deg(y, x); 5049 } 5050 copy() { 5051 let copy = new _PointAttachment(this.name); 5052 copy.x = this.x; 5053 copy.y = this.y; 5054 copy.rotation = this.rotation; 5055 copy.color.setFromColor(this.color); 5056 return copy; 5057 } 5058 }; 5059 5060
5060// spine-core/src/attachments/RegionAttachment.ts 5061 var RegionAttachment = class _RegionAttachment extends Attachment { 5062 /** The local x translation. */ 5063 x = 0; 5064 /** The local y translation. */ 5065 y = 0; 5066 /** The local scaleX. */ 5067 scaleX = 1; 5068 /** The local scaleY. */ 5069 scaleY = 1; 5070 /** The local rotation. */ 5071 rotation = 0; 5072 /** The width of the region attachment in Spine. */ 5073 width = 0; 5074 /** The height of the region attachment in Spine. */ 5075 height = 0; 5076 /** The color to tint the region attachment. */ 5077 color = new Color(1, 1, 1, 1); 5078 /** The name of the texture region for this attachment. */ 5079 path; 5080 region = null; 5081 sequence = null; 5082 /** For each of the 4 vertices, a pair of <code>x,y</code> values that is the local position of the vertex. 5083 * 5084 * See {@link #updateOffset()}. */ 5085 offset = Utils.newFloatArray(8); 5086 uvs = Utils.newFloatArray(8); 5087 tempColor = new Color(1, 1, 1, 1); 5088 constructor(name, path) { 5089 super(name); 5090 this.path = path; 5091 } 5092 /** Calculates the {@link #offset} using the region settings. Must be called after changing region settings. */ 5093 updateRegion() { 5094 if (!this.region) throw new Error("Region not set."); 5095 let region = this.region; 5096 let uvs = this.uvs; 5097 if (region == null) { 5098 uvs[0] = 0; 5099 uvs[1] = 0; 5100 uvs[2] = 0; 5101 uvs[3] = 1; 5102 uvs[4] = 1; 5103 uvs[5] = 1; 5104 uvs[6] = 1; 5105 uvs[7] = 0; 5106 return; 5107 } 5108 let regionScaleX = this.width / this.region.originalWidth * this.scaleX; 5109 let regionScaleY = this.height / this.region.originalHeight * this.scaleY; 5110 let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX; 5111 let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY; 5112 let localX2 = localX + this.region.width * regionScaleX; 5113 let localY2 = localY + this.region.height * regionScaleY; 5114 let radians = this.rotation * MathUtils.degRad; 5115 let cos = Math.cos(radians); 5116 let sin = Math.sin(radians); 5117 let x = this.x, y = this.y; 5118 let localXCos = localX * cos + x; 5119 let localXSin = localX * sin; 5120 let localYCos = localY * cos + y; 5121 let localYSin = localY * sin; 5122 let localX2Cos = localX2 * cos + x; 5123 let localX2Sin = localX2 * sin; 5124 let localY2Cos = localY2 * cos + y; 5125 let localY2Sin = localY2 * sin; 5126 let offset = this.offset; 5127 offset[0] = localXCos - localYSin; 5128 offset[1] = localYCos + localXSin; 5129 offset[2] = localXCos - localY2Sin; 5130 offset[3] = localY2Cos + localXSin; 5131 offset[4] = localX2Cos - localY2Sin; 5132 offset[5] = localY2Cos + localX2Sin; 5133 offset[6] = localX2Cos - localYSin; 5134 offset[7] = localYCos + localX2Sin; 5135 if (region.degrees == 90) { 5136 uvs[0] = region.u2; 5137 uvs[1] = region.v2; 5138 uvs[2] = region.u; 5139 uvs[3] = region.v2; 5140 uvs[4] = region.u; 5141 uvs[5] = region.v; 5142 uvs[6] = region.u2; 5143 uvs[7] = region.v; 5144 } else { 5145 uvs[0] = region.u; 5146 uvs[1] = region.v2; 5147 uvs[2] = region.u; 5148 uvs[3] = region.v; 5149 uvs[4] = region.u2; 5150 uvs[5] = region.v; 5151 uvs[6] = region.u2; 5152 uvs[7] = region.v2; 5153 } 5154 } 5155 /** Transforms the attachment's four vertices to world coordinates. If the attachment has a {@link #sequence}, the region may 5156 * be changed. 5157 * <p> 5158 * See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine 5159 * Runtimes Guide. 5160 * @param worldVertices The output world vertices. Must have a length >= <code>offset</code> + 8. 5161 * @param offset The <code>worldVertices</code> index to begin writing values. 5162 * @param stride The number of <code>worldVertices</code> entries between the value pairs written. */ 5163 computeWorldVertices(slot, worldVertices, offset, stride) { 5164 if (this.sequence != null) 5165 this.sequence.apply(slot, this); 5166 let bone = slot.bone; 5167 let vertexOffset = this.offset; 5168 let x = bone.worldX, y = bone.worldY; 5169 let a = bone.a, b = bone.b, c = bone.c, d = bone.d; 5170 let offsetX = 0, offsetY = 0; 5171 offsetX = vertexOffset[0]; 5172 offsetY = vertexOffset[1]; 5173 worldVertices[offset] = offsetX * a + offsetY * b + x; 5174 worldVertices[offset + 1] = offsetX * c + offsetY * d + y; 5175 offset += stride; 5176 offsetX = vertexOffset[2]; 5177 offsetY = vertexOffset[3]; 5178 worldVertices[offset] = offsetX * a + offsetY * b + x; 5179 worldVertices[offset + 1] = offsetX * c + offsetY * d + y; 5180 offset += stride; 5181 offsetX = vertexOffset[4]; 5182 offsetY = vertexOffset[5]; 5183 worldVertices[offset] = offsetX * a + offsetY * b + x; 5184 worldVertices[offset + 1] = offsetX * c + offsetY * d + y; 5185 offset += stride; 5186 offsetX = vertexOffset[6]; 5187 offsetY = vertexOffset[7]; 5188 worldVertices[offset] = offsetX * a + offsetY * b + x; 5189 worldVertices[offset + 1] = offsetX * c + offsetY * d + y; 5190 } 5191 copy() { 5192 let copy = new _RegionAttachment(this.name, this.path); 5193 copy.region = this.region; 5194 copy.x = this.x; 5195 copy.y = this.y; 5196 copy.scaleX = this.scaleX; 5197 copy.scaleY = this.scaleY; 5198 copy.rotation = this.rotation; 5199 copy.width = this.width; 5200 copy.height = this.height; 5201 Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8); 5202 Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8); 5203 copy.color.setFromColor(this.color); 5204 copy.sequence = this.sequence != null ? this.sequence.copy() : null; 5205 return copy; 5206 } 5207 static X1 = 0; 5208 static Y1 = 1; 5209 static C1R = 2; 5210 static C1G = 3; 5211 static C1B = 4; 5212 static C1A = 5; 5213 static U1 = 6; 5214 static V1 = 7; 5215 static X2 = 8; 5216 static Y2 = 9; 5217 static C2R = 10; 5218 static C2G = 11; 5219 static C2B = 12; 5220 static C2A = 13; 5221 static U2 = 14; 5222 static V2 = 15; 5223 static X3 = 16; 5224 static Y3 = 17; 5225 static C3R = 18; 5226 static C3G = 19; 5227 static C3B = 20; 5228 static C3A = 21; 5229 static U3 = 22; 5230 static V3 = 23; 5231 static X4 = 24; 5232 static Y4 = 25; 5233 static C4R = 26; 5234 static C4G = 27; 5235 static C4B = 28; 5236 static C4A = 29; 5237 static U4 = 30; 5238 static V4 = 31; 5239 }; 5240 5241
5241// spine-core/src/AtlasAttachmentLoader.ts 5242 var AtlasAttachmentLoader = class { 5243 atlas; 5244 constructor(atlas) { 5245 this.atlas = atlas; 5246 } 5247 loadSequence(name, basePath, sequence) { 5248 let regions = sequence.regions; 5249 for (let i = 0, n = regions.length; i < n; i++) { 5250 let path = sequence.getPath(basePath, i); 5251 let region = this.atlas.findRegion(path); 5252 if (region == null) throw new Error("Region not found in atlas: " + path + " (sequence: " + name + ")"); 5253 regions[i] = region; 5254 } 5255 } 5256 newRegionAttachment(skin, name, path, sequence) { 5257 let attachment = new RegionAttachment(name, path); 5258 if (sequence != null) { 5259 this.loadSequence(name, path, sequence); 5260 } else { 5261 let region = this.atlas.findRegion(path); 5262 if (!region) throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")"); 5263 attachment.region = region; 5264 } 5265 return attachment; 5266 } 5267 newMeshAttachment(skin, name, path, sequence) { 5268 let attachment = new MeshAttachment(name, path); 5269 if (sequence != null) { 5270 this.loadSequence(name, path, sequence); 5271 } else { 5272 let region = this.atlas.findRegion(path); 5273 if (!region) throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")"); 5274 attachment.region = region; 5275 } 5276 return attachment; 5277 } 5278 newBoundingBoxAttachment(skin, name) { 5279 return new BoundingBoxAttachment(name); 5280 } 5281 newPathAttachment(skin, name) { 5282 return new PathAttachment(name); 5283 } 5284 newPointAttachment(skin, name) { 5285 return new PointAttachment(name); 5286 } 5287 newClippingAttachment(skin, name) { 5288 return new ClippingAttachment(name); 5289 } 5290 }; 5291 5292
5292// spine-core/src/BoneData.ts 5293 var BoneData = class { 5294 /** The index of the bone in {@link Skeleton#getBones()}. */ 5295 index = 0; 5296 /** The name of the bone, which is unique across all bones in the skeleton. */ 5297 name; 5298 /** @returns May be null. */ 5299 parent = null; 5300 /** The bone's length. */ 5301 length = 0; 5302 /** The local x translation. */ 5303 x = 0; 5304 /** The local y translation. */ 5305 y = 0; 5306 /** The local rotation in degrees, counter clockwise. */ 5307 rotation = 0; 5308 /** The local scaleX. */ 5309 scaleX = 1; 5310 /** The local scaleY. */ 5311 scaleY = 1; 5312 /** The local shearX. */ 5313 shearX = 0; 5314 /** The local shearX. */ 5315 shearY = 0; 5316 /** The transform mode for how parent world transforms affect this bone. */ 5317 inherit = 0 /* Normal */; 5318 /** When true, {@link Skeleton#updateWorldTransform()} only updates this bone if the {@link Skeleton#skin} contains this 5319 * bone. 5320 * @see Skin#bones */ 5321 skinRequired = false; 5322 /** The color of the bone as it was in Spine. Available only when nonessential data was exported. Bones are not usually 5323 * rendered at runtime. */ 5324 color = new Color(); 5325 /** The bone icon as it was in Spine, or null if nonessential data was not exported. */ 5326 icon; 5327 /** False if the bone was hidden in Spine and nonessential data was exported. Does not affect runtime rendering. */ 5328 visible = false; 5329 constructor(index, name, parent) { 5330 if (index < 0) throw new Error("index must be >= 0."); 5331 if (!name) throw new Error("name cannot be null."); 5332 this.index = index; 5333 this.name = name; 5334 this.parent = parent; 5335 } 5336 }; 5337 var Inherit = /* @__PURE__ */ ((Inherit2) => { 5338 Inherit2[Inherit2["Normal"] = 0] = "Normal"; 5339 Inherit2[Inherit2["OnlyTranslation"] = 1] = "OnlyTranslation"; 5340 Inherit2[Inherit2["NoRotationOrReflection"] = 2] = "NoRotationOrReflection"; 5341 Inherit2[Inherit2["NoScale"] = 3] = "NoScale"; 5342 Inherit2[Inherit2["NoScaleOrReflection"] = 4] = "NoScaleOrReflection"; 5343 return Inherit2; 5344 })(Inherit || {}); 5345 5346
5346// spine-core/src/Bone.ts 5347 var Bone = class { 5348 /** The bone's setup pose data. */ 5349 data; 5350 /** The skeleton this bone belongs to. */ 5351 skeleton; 5352 /** The parent bone, or null if this is the root bone. */ 5353 parent = null; 5354 /** The immediate children of this bone. */ 5355 children = new Array(); 5356 /** The local x translation. */ 5357 x = 0; 5358 /** The local y translation. */ 5359 y = 0; 5360 /** The local rotation in degrees, counter clockwise. */ 5361 rotation = 0; 5362 /** The local scaleX. */ 5363 scaleX = 0; 5364 /** The local scaleY. */ 5365 scaleY = 0; 5366 /** The local shearX. */ 5367 shearX = 0; 5368 /** The local shearY. */ 5369 shearY = 0; 5370 /** The applied local x translation. */ 5371 ax = 0; 5372 /** The applied local y translation. */ 5373 ay = 0; 5374 /** The applied local rotation in degrees, counter clockwise. */ 5375 arotation = 0; 5376 /** The applied local scaleX. */ 5377 ascaleX = 0; 5378 /** The applied local scaleY. */ 5379 ascaleY = 0; 5380 /** The applied local shearX. */ 5381 ashearX = 0; 5382 /** The applied local shearY. */ 5383 ashearY = 0; 5384 /** Part of the world transform matrix for the X axis. If changed, {@link #updateAppliedTransform()} should be called. */ 5385 a = 0; 5386 /** Part of the world transform matrix for the Y axis. If changed, {@link #updateAppliedTransform()} should be called. */ 5387 b = 0; 5388 /** Part of the world transform matrix for the X axis. If changed, {@link #updateAppliedTransform()} should be called. */ 5389 c = 0; 5390 /** Part of the world transform matrix for the Y axis. If changed, {@link #updateAppliedTransform()} should be called. */ 5391 d = 0; 5392 /** The world X position. If changed, {@link #updateAppliedTransform()} should be called. */ 5393 worldY = 0; 5394 /** The world Y position. If changed, {@link #updateAppliedTransform()} should be called. */ 5395 worldX = 0; 5396 inherit = 0 /* Normal */; 5397 sorted = false; 5398 active = false; 5399 /** @param parent May be null. */ 5400 constructor(data, skeleton, parent) { 5401 if (!data) throw new Error("data cannot be null."); 5402 if (!skeleton) throw new Error("skeleton cannot be null."); 5403 this.data = data; 5404 this.skeleton = skeleton; 5405 this.parent = parent; 5406 this.setToSetupPose(); 5407 } 5408 /** Returns false when the bone has not been computed because {@link BoneData#skinRequired} is true and the 5409 * {@link Skeleton#skin active skin} does not {@link Skin#bones contain} this bone. */ 5410 isActive() { 5411 return this.active; 5412 } 5413 /** Computes the world transform using the parent bone and this bone's local applied transform. */ 5414 update(physics) { 5415 this.updateWorldTransformWith(this.ax, this.ay, this.arotation, this.ascaleX, this.ascaleY, this.ashearX, this.ashearY); 5416 } 5417 /** Computes the world transform using the parent bone and this bone's local transform. 5418 * 5419 * See {@link #updateWorldTransformWith()}. */ 5420 updateWorldTransform() { 5421 this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY); 5422 } 5423 /** Computes the world transform using the parent bone and the specified local transform. The applied transform is set to the 5424 * specified local transform. Child bones are not updated. 5425 * 5426 * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine 5427 * Runtimes Guide. */ 5428 updateWorldTransformWith(x, y, rotation, scaleX, scaleY, shearX, shearY) { 5429 this.ax = x; 5430 this.ay = y; 5431 this.arotation = rotation; 5432 this.ascaleX = scaleX; 5433 this.ascaleY = scaleY; 5434 this.ashearX = shearX; 5435 this.ashearY = shearY; 5436 let parent = this.parent; 5437 if (!parent) { 5438 let skeleton = this.skeleton; 5439 const sx = skeleton.scaleX, sy = skeleton.scaleY; 5440 const rx = (rotation + shearX) * MathUtils.degRad; 5441 const ry = (rotation + 90 + shearY) * MathUtils.degRad; 5442 this.a = Math.cos(rx) * scaleX * sx; 5443 this.b = Math.cos(ry) * scaleY * sx; 5444 this.c = Math.sin(rx) * scaleX * sy; 5445 this.d = Math.sin(ry) * scaleY * sy; 5446 this.worldX = x * sx + skeleton.x; 5447 this.worldY = y * sy + skeleton.y; 5448 return; 5449 } 5450 let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d; 5451 this.worldX = pa * x + pb * y + parent.worldX; 5452 this.worldY = pc * x + pd * y + parent.worldY; 5453 switch (this.inherit) { 5454 case 0 /* Normal */: { 5455 const rx = (rotation + shearX) * MathUtils.degRad; 5456 const ry = (rotation + 90 + shearY) * MathUtils.degRad; 5457 const la = Math.cos(rx) * scaleX;
5458 const lb = Math.cos(ry) * scaleY; 5459 const lc = Math.sin(rx) * scaleX; 5460 const ld = Math.sin(ry) * scaleY; 5461 this.a = pa * la + pb * lc; 5462 this.b = pa * lb + pb * ld; 5463 this.c = pc * la + pd * lc; 5464 this.d = pc * lb + pd * ld; 5465 return; 5466 } 5467 case 1 /* OnlyTranslation */: { 5468 const rx = (rotation + shearX) * MathUtils.degRad; 5469 const ry = (rotation + 90 + shearY) * MathUtils.degRad; 5470 this.a = Math.cos(rx) * scaleX; 5471 this.b = Math.cos(ry) * scaleY; 5472 this.c = Math.sin(rx) * scaleX; 5473 this.d = Math.sin(ry) * scaleY; 5474 break; 5475 } 5476 case 2 /* NoRotationOrReflection */: { 5477 let sx = 1 / this.skeleton.scaleX, sy = 1 / this.skeleton.scaleY; 5478 pa *= sx; 5479 pc *= sy; 5480 let s = pa * pa + pc * pc; 5481 let prx = 0; 5482 if (s > 1e-4) { 5483 s = Math.abs(pa * pd * sy - pb * sx * pc) / s; 5484 pb = pc * s; 5485 pd = pa * s; 5486 prx = Math.atan2(pc, pa) * MathUtils.radDeg; 5487 } else { 5488 pa = 0; 5489 pc = 0; 5490 prx = 90 - Math.atan2(pd, pb) * MathUtils.radDeg; 5491 } 5492 const rx = (rotation + shearX - prx) * MathUtils.degRad; 5493 const ry = (rotation + shearY - prx + 90) * MathUtils.degRad; 5494 const la = Math.cos(rx) * scaleX; 5495 const lb = Math.cos(ry) * scaleY; 5496 const lc = Math.sin(rx) * scaleX; 5497 const ld = Math.sin(ry) * scaleY; 5498 this.a = pa * la - pb * lc; 5499 this.b = pa * lb - pb * ld; 5500 this.c = pc * la + pd * lc; 5501 this.d = pc * lb + pd * ld; 5502 break; 5503 } 5504 case 3 /* NoScale */: 5505 case 4 /* NoScaleOrReflection */: { 5506 rotation *= MathUtils.degRad; 5507 const cos = Math.cos(rotation), sin = Math.sin(rotation); 5508 let za = (pa * cos + pb * sin) / this.skeleton.scaleX; 5509 let zc = (pc * cos + pd * sin) / this.skeleton.scaleY; 5510 let s = Math.sqrt(za * za + zc * zc); 5511 if (s > 1e-5) s = 1 / s; 5512 za *= s; 5513 zc *= s; 5514 s = Math.sqrt(za * za + zc * zc); 5515 if (this.inherit == 3 /* NoScale */ && pa * pd - pb * pc < 0 != (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0)) s = -s; 5516 rotation = Math.PI / 2 + Math.atan2(zc, za); 5517 const zb = Math.cos(rotation) * s; 5518 const zd = Math.sin(rotation) * s; 5519 shearX *= MathUtils.degRad; 5520 shearY = (90 + shearY) * MathUtils.degRad; 5521 const la = Math.cos(shearX) * scaleX; 5522 const lb = Math.cos(shearY) * scaleY; 5523 const lc = Math.sin(shearX) * scaleX; 5524 const ld = Math.sin(shearY) * scaleY; 5525 this.a = za * la + zb * lc; 5526 this.b = za * lb + zb * ld; 5527 this.c = zc * la + zd * lc; 5528 this.d = zc * lb + zd * ld; 5529 break; 5530 } 5531 } 5532 this.a *= this.skeleton.scaleX; 5533 this.b *= this.skeleton.scaleX; 5534 this.c *= this.skeleton.scaleY; 5535 this.d *= this.skeleton.scaleY; 5536 } 5537 /** Sets this bone's local transform to the setup pose. */ 5538 setToSetupPose() { 5539 let data = this.data; 5540 this.x = data.x; 5541 this.y = data.y; 5542 this.rotation = data.rotation; 5543 this.scaleX = data.scaleX; 5544 this.scaleY = data.scaleY; 5545 this.shearX = data.shearX; 5546 this.shearY = data.shearY; 5547 this.inherit = data.inherit; 5548 } 5549 /** Computes the applied transform values from the world transform. 5550 * 5551 * If the world transform is modified (by a constraint, {@link #rotateWorld(float)}, etc) then this method should be called so 5552 * the applied transform matches the world transform. The applied transform may be needed by other code (eg to apply other 5553 * constraints). 5554 * 5555 * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after 5556 * calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. */ 5557 updateAppliedTransform() { 5558 let parent = this.parent; 5559 if (!parent) { 5560 this.ax = this.worldX - this.skeleton.x; 5561 this.ay = this.worldY - this.skeleton.y; 5562 this.arotation = Math.atan2(this.c, this.a) * MathUtils.radDeg; 5563 this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c); 5564 this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d); 5565 this.ashearX = 0; 5566 this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * MathUtils.radDeg; 5567 return; 5568 } 5569 let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d; 5570 let pid = 1 / (pa * pd - pb * pc); 5571 let ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid; 5572 let dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY; 5573 this.ax = dx * ia - dy * ib; 5574 this.ay = dy * id - dx * ic; 5575 let ra, rb, rc, rd; 5576 if (this.inherit == 1 /* OnlyTranslation */) { 5577 ra = this.a; 5578 rb = this.b; 5579 rc = this.c; 5580 rd = this.d; 5581 } else { 5582 switch (this.inherit) { 5583 case 2 /* NoRotationOrReflection */: { 5584 let s2 = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc); 5585 pb = -pc * this.skeleton.scaleX * s2 / this.skeleton.scaleY; 5586 pd = pa * this.skeleton.scaleY * s2 / this.skeleton.scaleX; 5587 pid = 1 / (pa * pd - pb * pc); 5588 ia = pd * pid; 5589 ib = pb * pid; 5590 break; 5591 } 5592 case 3 /* NoScale */: 5593 case 4 /* NoScaleOrReflection */: 5594 let cos = MathUtils.cosDeg(this.rotation), sin = MathUtils.sinDeg(this.rotation); 5595 pa = (pa * cos + pb * sin) / this.skeleton.scaleX;
5596 pc = (pc * cos + pd * sin) / this.skeleton.scaleY; 5597 let s = Math.sqrt(pa * pa + pc * pc); 5598 if (s > 1e-5) s = 1 / s; 5599 pa *= s; 5600 pc *= s; 5601 s = Math.sqrt(pa * pa + pc * pc); 5602 if (this.inherit == 3 /* NoScale */ && pid < 0 != (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0)) s = -s; 5603 let r = MathUtils.PI / 2 + Math.atan2(pc, pa); 5604 pb = Math.cos(r) * s; 5605 pd = Math.sin(r) * s; 5606 pid = 1 / (pa * pd - pb * pc); 5607 ia = pd * pid; 5608 ib = pb * pid; 5609 ic = pc * pid; 5610 id = pa * pid; 5611 } 5612 ra = ia * this.a - ib * this.c; 5613 rb = ia * this.b - ib * this.d; 5614 rc = id * this.c - ic * this.a; 5615 rd = id * this.d - ic * this.b; 5616 } 5617 this.ashearX = 0; 5618 this.ascaleX = Math.sqrt(ra * ra + rc * rc); 5619 if (this.ascaleX > 1e-4) { 5620 let det = ra * rd - rb * rc; 5621 this.ascaleY = det / this.ascaleX; 5622 this.ashearY = -Math.atan2(ra * rb + rc * rd, det) * MathUtils.radDeg; 5623 this.arotation = Math.atan2(rc, ra) * MathUtils.radDeg; 5624 } else { 5625 this.ascaleX = 0; 5626 this.ascaleY = Math.sqrt(rb * rb + rd * rd); 5627 this.ashearY = 0; 5628 this.arotation = 90 - Math.atan2(rd, rb) * MathUtils.radDeg; 5629 } 5630 } 5631 /** The world rotation for the X axis, calculated using {@link #a} and {@link #c}. */ 5632 getWorldRotationX() { 5633 return Math.atan2(this.c, this.a) * MathUtils.radDeg; 5634 } 5635 /** The world rotation for the Y axis, calculated using {@link #b} and {@link #d}. */ 5636 getWorldRotationY() { 5637 return Math.atan2(this.d, this.b) * MathUtils.radDeg; 5638 } 5639 /** The magnitude (always positive) of the world scale X, calculated using {@link #a} and {@link #c}. */ 5640 getWorldScaleX() { 5641 return Math.sqrt(this.a * this.a + this.c * this.c); 5642 } 5643 /** The magnitude (always positive) of the world scale Y, calculated using {@link #b} and {@link #d}. */ 5644 getWorldScaleY() { 5645 return Math.sqrt(this.b * this.b + this.d * this.d); 5646 } 5647 /** Transforms a point from world coordinates to the bone's local coordinates. */ 5648 worldToLocal(world) { 5649 let invDet = 1 / (this.a * this.d - this.b * this.c); 5650 let x = world.x - this.worldX, y = world.y - this.worldY; 5651 world.x = x * this.d * invDet - y * this.b * invDet; 5652 world.y = y * this.a * invDet - x * this.c * invDet; 5653 return world; 5654 } 5655 /** Transforms a point from the bone's local coordinates to world coordinates. */ 5656 localToWorld(local) { 5657 let x = local.x, y = local.y; 5658 local.x = x * this.a + y * this.b + this.worldX; 5659 local.y = x * this.c + y * this.d + this.worldY; 5660 return local; 5661 } 5662 /** Transforms a point from world coordinates to the parent bone's local coordinates. */ 5663 worldToParent(world) { 5664 if (world == null) throw new Error("world cannot be null."); 5665 return this.parent == null ? world : this.parent.worldToLocal(world); 5666 } 5667 /** Transforms a point from the parent bone's coordinates to world coordinates. */ 5668 parentToWorld(world) { 5669 if (world == null) throw new Error("world cannot be null."); 5670 return this.parent == null ? world : this.parent.localToWorld(world); 5671 } 5672 /** Transforms a world rotation to a local rotation. */ 5673 worldToLocalRotation(worldRotation) { 5674 let sin = MathUtils.sinDeg(worldRotation), cos = MathUtils.cosDeg(worldRotation); 5675 return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * MathUtils.radDeg + this.rotation - this.shearX; 5676 } 5677 /** Transforms a local rotation to a world rotation. */ 5678 localToWorldRotation(localRotation) { 5679 localRotation -= this.rotation - this.shearX; 5680 let sin = MathUtils.sinDeg(localRotation), cos = MathUtils.cosDeg(localRotation); 5681 return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * MathUtils.radDeg; 5682 } 5683 /** Rotates the world transform the specified amount. 5684 * <p> 5685 * After changes are made to the world transform, {@link #updateAppliedTransform()} should be called and 5686 * {@link #update(Physics)} will need to be called on any child bones, recursively. */ 5687 rotateWorld(degrees) { 5688 degrees *= MathUtils.degRad; 5689 const sin = Math.sin(degrees), cos = Math.cos(degrees); 5690 const ra = this.a, rb = this.b; 5691 this.a = cos * ra - sin * this.c; 5692 this.b = cos * rb - sin * this.d; 5693 this.c = sin * ra + cos * this.c; 5694 this.d = sin * rb + cos * this.d; 5695 } 5696 }; 5697 5698
5698// spine-core/src/ConstraintData.ts 5699 var ConstraintData = class { 5700 constructor(name, order, skinRequired) { 5701 this.name = name; 5702 this.order = order; 5703 this.skinRequired = skinRequired; 5704 } 5705 }; 5706 5707
5707// spine-core/src/AssetManagerBase.ts 5708 var AssetManagerBase = class { 5709 pathPrefix = ""; 5710 textureLoader; 5711 downloader; 5712 cache; 5713 errors = {}; 5714 toLoad = 0; 5715 loaded = 0; 5716 constructor(textureLoader, pathPrefix = "", downloader = new Downloader(), cache = new AssetCache()) { 5717 this.textureLoader = textureLoader; 5718 this.pathPrefix = pathPrefix; 5719 this.downloader = downloader; 5720 this.cache = cache; 5721 } 5722 start(path) { 5723 this.toLoad++; 5724 return this.pathPrefix + path; 5725 } 5726 success(callback, path, asset) { 5727 this.toLoad--; 5728 this.loaded++; 5729 this.cache.assets[path] = asset; 5730 this.cache.assetsRefCount[path] = (this.cache.assetsRefCount[path] || 0) + 1; 5731 if (callback) callback(path, asset); 5732 } 5733 error(callback, path, message) { 5734 this.toLoad--; 5735 this.loaded++; 5736 this.errors[path] = message; 5737 if (callback) callback(path, message); 5738 } 5739 loadAll() { 5740 let promise = new Promise((resolve, reject) => { 5741 let check = () => { 5742 if (this.isLoadingComplete()) { 5743 if (this.hasErrors()) reject(this.errors); 5744 else resolve(this); 5745 return; 5746 } 5747 requestAnimationFrame(check); 5748 }; 5749 requestAnimationFrame(check); 5750 }); 5751 return promise; 5752 } 5753 setRawDataURI(path, data) { 5754 this.downloader.rawDataUris[this.pathPrefix + path] = data; 5755 } 5756 loadBinary(path, success = () => { 5757 }, error = () => { 5758 }) { 5759 path = this.start(path); 5760 if (this.reuseAssets(path, success, error)) return; 5761 this.cache.assetsLoaded[path] = new Promise((resolve, reject) => { 5762 this.downloader.downloadBinary(path, (data) => { 5763 this.success(success, path, data); 5764 resolve(data); 5765 }, (status, responseText) => { 5766 const errorMsg = `Couldn't load binary ${path}: status ${status}, ${responseText}`; 5767 this.error(error, path, errorMsg); 5768 reject(errorMsg); 5769 }); 5770 }); 5771 } 5772 loadText(path, success = () => { 5773 }, error = () => { 5774 }) { 5775 path = this.start(path); 5776 this.downloader.downloadText(path, (data) => { 5777 this.success(success, path, data); 5778 }, (status, responseText) => { 5779 this.error(error, path, `Couldn't load text ${path}: status ${status}, ${responseText}`); 5780 }); 5781 } 5782 loadJson(path, success = () => { 5783 }, error = () => { 5784 }) { 5785 path = this.start(path); 5786 if (this.reuseAssets(path, success, error)) return; 5787 this.cache.assetsLoaded[path] = new Promise((resolve, reject) => { 5788 this.downloader.downloadJson(path, (data) => { 5789 this.success(success, path, data); 5790 resolve(data); 5791 }, (status, responseText) => { 5792 const errorMsg = `Couldn't load JSON ${path}: status ${status}, ${responseText}`; 5793 this.error(error, path, errorMsg); 5794 reject(errorMsg); 5795 }); 5796 }); 5797 } 5798 reuseAssets(path, success = () => { 5799 }, error = () => { 5800 }) { 5801 const loadedStatus = this.cache.assetsLoaded[path]; 5802 const alreadyExistsOrLoading = loadedStatus !== void 0; 5803 if (alreadyExistsOrLoading) { 5804 this.cache.assetsLoaded[path] = loadedStatus.then((data) => { 5805 data = data instanceof Image || data instanceof ImageBitmap ? this.textureLoader(data) : data; 5806 this.success(success, path, data); 5807 return data; 5808 }).catch((errorMsg) => this.error(error, path, errorMsg)); 5809 } 5810 return alreadyExistsOrLoading; 5811 } 5812 loadTexture(path, success = () => { 5813 }, error = () => { 5814 }) { 5815 path = this.start(path); 5816 if (this.reuseAssets(path, success, error)) return; 5817 this.cache.assetsLoaded[path] = new Promise((resolve, reject) => { 5818 let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document); 5819 let isWebWorker = !isBrowser; 5820 if (isWebWorker) { 5821 fetch(path, { mode: "cors" }).then((response) => { 5822 if (response.ok) return response.blob(); 5823 const errorMsg = `Couldn't load image: ${path}`;
5824 this.error(error, path, `Couldn't load image: ${path}`); 5825 reject(errorMsg); 5826 }).then((blob) => { 5827 return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null; 5828 }).then((bitmap) => { 5829 if (bitmap) { 5830 const texture = this.textureLoader(bitmap); 5831 this.success(success, path, texture); 5832 resolve(texture); 5833 } 5834 ; 5835 }); 5836 } else { 5837 let image = new Image(); 5838 image.crossOrigin = "anonymous"; 5839 image.onload = () => { 5840 const texture = this.textureLoader(image); 5841 this.success(success, path, texture); 5842 resolve(texture); 5843 }; 5844 image.onerror = () => { 5845 const errorMsg = `Couldn't load image: ${path}`; 5846 this.error(error, path, errorMsg); 5847 reject(errorMsg); 5848 }; 5849 if (this.downloader.rawDataUris[path]) path = this.downloader.rawDataUris[path]; 5850 image.src = path; 5851 } 5852 }); 5853 } 5854 loadTextureAtlas(path, success = () => { 5855 }, error = () => { 5856 }, fileAlias) { 5857 let index = path.lastIndexOf("/"); 5858 let parent = index >= 0 ? path.substring(0, index + 1) : ""; 5859 path = this.start(path); 5860 if (this.reuseAssets(path, success, error)) return; 5861 this.cache.assetsLoaded[path] = new Promise((resolve, reject) => { 5862 this.downloader.downloadText(path, (atlasText) => { 5863 try { 5864 let atlas = new TextureAtlas(atlasText); 5865 let toLoad = atlas.pages.length, abort = false;
5866 for (let page of atlas.pages) { 5867 this.loadTexture( 5868 !fileAlias ? parent + page.name : fileAlias[page.name], 5869 (imagePath, texture) => { 5870 if (!abort) { 5871 page.setTexture(texture); 5872 if (--toLoad == 0) { 5873 this.success(success, path, atlas); 5874 resolve(atlas); 5875 } 5876 } 5877 }, 5878 (imagePath, message) => { 5879 if (!abort) { 5880 const errorMsg = `Couldn't load texture ${path} page image: ${imagePath}`; 5881 this.error(error, path, errorMsg); 5882 reject(errorMsg); 5883 } 5884 abort = true; 5885 } 5886 ); 5887 } 5888 } catch (e) { 5889 const errorMsg = `Couldn't parse texture atlas ${path}: ${e.message}`; 5890 this.error(error, path, errorMsg); 5891 reject(errorMsg); 5892 } 5893 }, (status, responseText) => { 5894 const errorMsg = `Couldn't load texture atlas ${path}: status ${status}, ${responseText}`; 5895 this.error(error, path, errorMsg); 5896 reject(errorMsg); 5897 }); 5898 }); 5899 } 5900 loadTextureAtlasButNoTextures(path, success = () => { 5901 }, error = () => { 5902 }, fileAlias) { 5903 path = this.start(path); 5904 if (this.reuseAssets(path, success, error)) return; 5905 this.cache.assetsLoaded[path] = new Promise((resolve, reject) => { 5906 this.downloader.downloadText(path, (atlasText) => { 5907 try { 5908 const atlas = new TextureAtlas(atlasText); 5909 this.success(success, path, atlas); 5910 resolve(atlas); 5911 } catch (e) { 5912 const errorMsg = `Couldn't parse texture atlas ${path}: ${e.message}`; 5913 this.error(error, path, errorMsg); 5914 reject(errorMsg); 5915 } 5916 }, (status, responseText) => { 5917 const errorMsg = `Couldn't load texture atlas ${path}: status ${status}, ${responseText}`; 5918 this.error(error, path, errorMsg); 5919 reject(errorMsg); 5920 }); 5921 }); 5922 } 5923 // Promisified versions of load function 5924 async loadBinaryAsync(path) { 5925 return new Promise((resolve, reject) => { 5926 this.loadBinary( 5927 path, 5928 (_, binary) => resolve(binary), 5929 (_, message) => reject(message) 5930 ); 5931 }); 5932 } 5933 async loadJsonAsync(path) { 5934 return new Promise((resolve, reject) => { 5935 this.loadJson( 5936 path, 5937 (_, object) => resolve(object), 5938 (_, message) => reject(message) 5939 ); 5940 }); 5941 } 5942 async loadTextureAsync(path) { 5943 return new Promise((resolve, reject) => { 5944 this.loadTexture( 5945 path, 5946 (_, texture) => resolve(texture), 5947 (_, message) => reject(message) 5948 ); 5949 }); 5950 } 5951 async loadTextureAtlasAsync(path) { 5952 return new Promise((resolve, reject) => { 5953 this.loadTextureAtlas( 5954 path, 5955 (_, atlas) => resolve(atlas), 5956 (_, message) => reject(message) 5957 ); 5958 }); 5959 } 5960 async loadTextureAtlasButNoTexturesAsync(path) { 5961 return new Promise((resolve, reject) => { 5962 this.loadTextureAtlasButNoTextures( 5963 path, 5964 (_, atlas) => resolve(atlas), 5965 (_, message) => reject(message) 5966 ); 5967 }); 5968 } 5969 setCache(cache) { 5970 this.cache = cache; 5971 } 5972 get(path) { 5973 return this.cache.assets[this.pathPrefix + path]; 5974 } 5975 require(path) { 5976 path = this.pathPrefix + path; 5977 let asset = this.cache.assets[path]; 5978 if (asset) return asset; 5979 let error = this.errors[path]; 5980 throw Error("Asset not found: " + path + (error ? "\n" + error : "")); 5981 } 5982 remove(path) { 5983 path = this.pathPrefix + path; 5984 let asset = this.cache.assets[path]; 5985 if (asset.dispose) asset.dispose(); 5986 delete this.cache.assets[path]; 5987 delete this.cache.assetsRefCount[path]; 5988 delete this.cache.assetsLoaded[path]; 5989 return asset; 5990 } 5991 removeAll() { 5992 for (let path in this.cache.assets) { 5993 let asset = this.cache.assets[path]; 5994 if (asset.dispose) asset.dispose(); 5995 } 5996 this.cache.assets = {}; 5997 this.cache.assetsLoaded = {};
5998 this.cache.assetsRefCount = {}; 5999 } 6000 isLoadingComplete() { 6001 return this.toLoad == 0; 6002 } 6003 getToLoad() { 6004 return this.toLoad; 6005 } 6006 getLoaded() { 6007 return this.loaded; 6008 } 6009 dispose() { 6010 this.removeAll(); 6011 } 6012 // dispose asset only if it's not used by others 6013 disposeAsset(path) { 6014 if (--this.cache.assetsRefCount[path] === 0) { 6015 this.remove(path); 6016 } 6017 } 6018 hasErrors() { 6019 return Object.keys(this.errors).length > 0; 6020 } 6021 getErrors() { 6022 return this.errors; 6023 } 6024 }; 6025 var AssetCache = class _AssetCache { 6026 assets = {}; 6027 assetsRefCount = {}; 6028 assetsLoaded = {}; 6029 static AVAILABLE_CACHES = /* @__PURE__ */ new Map(); 6030 static getCache(id) { 6031 const cache = _AssetCache.AVAILABLE_CACHES.get(id); 6032 if (cache) return cache; 6033 const newCache = new _AssetCache(); 6034 _AssetCache.AVAILABLE_CACHES.set(id, newCache); 6035 return newCache; 6036 } 6037 async addAsset(path, asset) { 6038 this.assetsLoaded[path] = Promise.resolve(asset); 6039 this.assets[path] = await asset; 6040 } 6041 }; 6042 var Downloader = class { 6043 callbacks = {}; 6044 rawDataUris = {}; 6045 dataUriToString(dataUri) { 6046 if (!dataUri.startsWith("data:")) { 6047 throw new Error("Not a data URI."); 6048 } 6049 let base64Idx = dataUri.indexOf("base64,"); 6050 if (base64Idx != -1) { 6051 base64Idx += "base64,".length; 6052 return atob(dataUri.substr(base64Idx)); 6053 } else { 6054 return dataUri.substr(dataUri.indexOf(",") + 1); 6055 } 6056 } 6057 base64ToUint8Array(base64) { 6058 var binary_string = window.atob(base64); 6059 var len = binary_string.length; 6060 var bytes = new Uint8Array(len); 6061 for (var i = 0; i < len; i++) { 6062 bytes[i] = binary_string.charCodeAt(i); 6063 } 6064 return bytes; 6065 } 6066 dataUriToUint8Array(dataUri) { 6067 if (!dataUri.startsWith("data:")) { 6068 throw new Error("Not a data URI."); 6069 } 6070 let base64Idx = dataUri.indexOf("base64,"); 6071 if (base64Idx == -1) throw new Error("Not a binary data URI."); 6072 base64Idx += "base64,".length; 6073 return this.base64ToUint8Array(dataUri.substr(base64Idx)); 6074 } 6075 downloadText(url, success, error) { 6076 if (this.start(url, success, error)) return; 6077 const rawDataUri = this.rawDataUris[url]; 6078 if (rawDataUri && !rawDataUri.includes(".")) { 6079 try { 6080 this.finish(url, 200, this.dataUriToString(rawDataUri)); 6081 } catch (e) { 6082 this.finish(url, 400, JSON.stringify(e)); 6083 } 6084 return; 6085 } 6086 let request = new XMLHttpRequest(); 6087 request.overrideMimeType("text/html"); 6088 request.open("GET", rawDataUri ? rawDataUri : url, true); 6089 let done = () => { 6090 this.finish(url, request.status, request.responseText); 6091 }; 6092 request.onload = done; 6093 request.onerror = done; 6094 request.send(); 6095 } 6096 downloadJson(url, success, error) { 6097 this.downloadText(url, (data) => { 6098 success(JSON.parse(data)); 6099 }, error); 6100 } 6101 downloadBinary(url, success, error) { 6102 if (this.start(url, success, error)) return; 6103 const rawDataUri = this.rawDataUris[url]; 6104 if (rawDataUri && !rawDataUri.includes(".")) { 6105 try { 6106 this.finish(url, 200, this.dataUriToUint8Array(rawDataUri)); 6107 } catch (e) { 6108 this.finish(url, 400, JSON.stringify(e)); 6109 } 6110 return; 6111 } 6112 let request = new XMLHttpRequest(); 6113 request.open("GET", rawDataUri ? rawDataUri : url, true); 6114 request.responseType = "arraybuffer"; 6115 let onerror = () => { 6116 this.finish(url, request.status, request.response); 6117 }; 6118 request.onload = () => { 6119 if (request.status == 200 || request.status == 0) 6120 this.finish(url, 200, new Uint8Array(request.response)); 6121 else 6122 onerror(); 6123 }; 6124 request.onerror = onerror; 6125 request.send(); 6126 } 6127 start(url, success, error) { 6128 let callbacks = this.callbacks[url]; 6129 try { 6130 if (callbacks) return true; 6131 this.callbacks[url] = callbacks = []; 6132 } finally { 6133 callbacks.push(success, error); 6134 } 6135 } 6136 finish(url, status, data) { 6137 let callbacks = this.callbacks[url]; 6138 delete this.callbacks[url]; 6139 let args = status == 200 || status == 0 ? [data] : [status, data]; 6140 for (let i = args.length - 1, n = callbacks.length; i < n; i += 2)
6141 callbacks[i].apply(null, args); 6142 } 6143 }; 6144 6145
6145// spine-core/src/Event.ts 6146 var Event = class { 6147 data; 6148 intValue = 0; 6149 floatValue = 0; 6150 stringValue = null; 6151 time = 0; 6152 volume = 0; 6153 balance = 0; 6154 constructor(time, data) { 6155 if (!data) throw new Error("data cannot be null."); 6156 this.time = time; 6157 this.data = data; 6158 } 6159 }; 6160 6161
6161// spine-core/src/EventData.ts 6162 var EventData = class { 6163 name; 6164 intValue = 0; 6165 floatValue = 0; 6166 stringValue = null; 6167 audioPath = null; 6168 volume = 0; 6169 balance = 0; 6170 constructor(name) { 6171 this.name = name; 6172 } 6173 }; 6174 6175
6175// spine-core/src/IkConstraint.ts 6176 var IkConstraint = class { 6177 /** The IK constraint's setup pose data. */ 6178 data; 6179 /** The bones that will be modified by this IK constraint. */ 6180 bones; 6181 /** The bone that is the IK target. */ 6182 target; 6183 /** Controls the bend direction of the IK bones, either 1 or -1. */ 6184 bendDirection = 0; 6185 /** When true and only a single bone is being constrained, if the target is too close, the bone is scaled to reach it. */ 6186 compress = false; 6187 /** When true, if the target is out of range, the parent bone is scaled to reach it. If more than one bone is being constrained 6188 * and the parent bone has local nonuniform scale, stretch is not applied. */ 6189 stretch = false; 6190 /** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */ 6191 mix = 1; 6192 /** For two bone IK, the distance from the maximum reach of the bones that rotation will slow. */ 6193 softness = 0; 6194 active = false; 6195 constructor(data, skeleton) { 6196 if (!data) throw new Error("data cannot be null."); 6197 if (!skeleton) throw new Error("skeleton cannot be null."); 6198 this.data = data; 6199 this.bones = new Array(); 6200 for (let i = 0; i < data.bones.length; i++) { 6201 let bone = skeleton.findBone(data.bones[i].name); 6202 if (!bone) throw new Error(`Couldn't find bone ${data.bones[i].name}`); 6203 this.bones.push(bone); 6204 } 6205 let target = skeleton.findBone(data.target.name); 6206 if (!target) throw new Error(`Couldn't find bone ${data.target.name}`); 6207 this.target = target; 6208 this.mix = data.mix; 6209 this.softness = data.softness; 6210 this.bendDirection = data.bendDirection; 6211 this.compress = data.compress; 6212 this.stretch = data.stretch; 6213 } 6214 isActive() { 6215 return this.active; 6216 } 6217 setToSetupPose() { 6218 const data = this.data; 6219 this.mix = data.mix; 6220 this.softness = data.softness; 6221 this.bendDirection = data.bendDirection; 6222 this.compress = data.compress; 6223 this.stretch = data.stretch; 6224 } 6225 update(physics) { 6226 if (this.mix == 0) return; 6227 let target = this.target; 6228 let bones = this.bones; 6229 switch (bones.length) { 6230 case 1: 6231 this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix); 6232 break; 6233 case 2: 6234 this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.data.uniform, this.softness, this.mix); 6235 break; 6236 } 6237 } 6238 /** Applies 1 bone IK. The target is specified in the world coordinate system. */ 6239 apply1(bone, targetX, targetY, compress, stretch, uniform, alpha) { 6240 let p = bone.parent; 6241 if (!p) throw new Error("IK bone must have parent."); 6242 let pa = p.a, pb = p.b, pc = p.c, pd = p.d; 6243 let rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0; 6244 switch (bone.inherit) { 6245 case 1 /* OnlyTranslation */: 6246 tx = (targetX - bone.worldX) * MathUtils.signum(bone.skeleton.scaleX); 6247 ty = (targetY - bone.worldY) * MathUtils.signum(bone.skeleton.scaleY); 6248 break; 6249 case 2 /* NoRotationOrReflection */: 6250 let s = Math.abs(pa * pd - pb * pc) / Math.max(1e-4, pa * pa + pc * pc); 6251 let sa = pa / bone.skeleton.scaleX; 6252 let sc = pc / bone.skeleton.scaleY; 6253 pb = -sc * s * bone.skeleton.scaleX; 6254 pd = sa * s * bone.skeleton.scaleY; 6255 rotationIK += Math.atan2(sc, sa) * MathUtils.radDeg; 6256 // Fall through 6257 default: 6258 let x = targetX - p.worldX, y = targetY - p.worldY; 6259 let d = pa * pd - pb * pc; 6260 if (Math.abs(d) <= 1e-4) { 6261 tx = 0; 6262 ty = 0; 6263 } else { 6264 tx = (x * pd - y * pb) / d - bone.ax; 6265 ty = (y * pa - x * pc) / d - bone.ay; 6266 } 6267 } 6268 rotationIK += Math.atan2(ty, tx) * MathUtils.radDeg; 6269 if (bone.ascaleX < 0) rotationIK += 180; 6270 if (rotationIK > 180) 6271 rotationIK -= 360; 6272 else if (rotationIK < -180) 6273 rotationIK += 360; 6274 let sx = bone.ascaleX, sy = bone.ascaleY; 6275 if (compress || stretch) { 6276 switch (bone.inherit) { 6277 case 3 /* NoScale */: 6278 case 4 /* NoScaleOrReflection */: 6279 tx = targetX - bone.worldX; 6280 ty = targetY - bone.worldY; 6281 } 6282 const b = bone.data.length * sx; 6283 if (b > 1e-4) { 6284 const dd = tx * tx + ty * ty; 6285 if (compress && dd < b * b || stretch && dd > b * b) { 6286 const s = (Math.sqrt(dd) / b - 1) * alpha + 1; 6287 sx *= s; 6288 if (uniform) sy *= s; 6289 } 6290 } 6291 } 6292 bone.updateWorldTransformWith( 6293 bone.ax, 6294 bone.ay, 6295 bone.arotation + rotationIK * alpha, 6296 sx, 6297 sy, 6298 bone.ashearX, 6299 bone.ashearY 6300 ); 6301 } 6302 /** Applies 2 bone IK. The target is specified in the world coordinate system. 6303 * @param child A direct descendant of the parent bone. */ 6304 apply2(parent, child, targetX, targetY, bendDir, stretch, uniform, softness, alpha) { 6305 if (parent.inherit != 0 /* Normal */ || child.inherit != 0 /* Normal */) return; 6306 let px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, sx = psx, sy = psy, csx = child.ascaleX; 6307 let os1 = 0, os2 = 0, s2 = 0; 6308 if (psx < 0) { 6309 psx = -psx; 6310 os1 = 180; 6311 s2 = -1; 6312 } else { 6313 os1 = 0; 6314 s2 = 1; 6315 } 6316 if (psy < 0) { 6317 psy = -psy; 6318 s2 = -s2; 6319 } 6320 if (csx < 0) { 6321 csx = -csx; 6322 os2 = 180; 6323 } else 6324 os2 = 0; 6325 let cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d; 6326 let u = Math.abs(psx - psy) <= 1e-4; 6327 if (!u || stretch) { 6328 cy = 0; 6329 cwx = a * cx + parent.worldX; 6330 cwy = c * cx + parent.worldY; 6331 } else { 6332 cy = child.ay; 6333 cwx = a * cx + b * cy + parent.worldX; 6334 cwy = c * cx + d * cy + parent.worldY; 6335 } 6336 let pp = parent.parent; 6337 if (!pp) throw new Error("IK parent must itself have a parent."); 6338 a = pp.a; 6339 b = pp.b; 6340 c = pp.c; 6341 d = pp.d; 6342 let id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; 6343 id = Math.abs(id) <= 1e-4 ? 0 : 1 / id; 6344 let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; 6345 let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; 6346 if (l1 < 1e-4) { 6347 this.apply1(parent, targetX, targetY, false, stretch, false, alpha); 6348 child.updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY); 6349 return; 6350 } 6351 x = targetX - pp.worldX; 6352 y = targetY - pp.worldY; 6353 let tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py; 6354 let dd = tx * tx + ty * ty; 6355 if (softness != 0) { 6356 softness *= psx * (csx + 1) * 0.5; 6357 let td = Math.sqrt(dd), sd = td - l1 - l2 * psx + softness; 6358 if (sd > 0) { 6359 let p = Math.min(1, sd / (softness * 2)) - 1; 6360 p = (sd - softness * (1 - p * p)) / td; 6361 tx -= p * tx; 6362 ty -= p * ty; 6363 dd = tx * tx + ty * ty; 6364 } 6365 } 6366 outer: 6367 if (u) { 6368 l2 *= psx; 6369 let cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2); 6370 if (cos < -1) { 6371 cos = -1; 6372 a2 = Math.PI * bendDir; 6373 } else if (cos > 1) { 6374 cos = 1; 6375 a2 = 0; 6376 if (stretch) { 6377 a = (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1; 6378 sx *= a; 6379 if (uniform) sy *= a; 6380 } 6381 } else 6382 a2 = Math.acos(cos) * bendDir; 6383 a = l1 + l2 * cos; 6384 b = l2 * Math.sin(a2); 6385 a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b); 6386 } else { 6387 a = psx * l2; 6388 b = psy * l2; 6389 let aa = a * a, bb = b * b, ta = Math.atan2(ty, tx); 6390 c = bb * l1 * l1 + aa * dd - aa * bb; 6391 let c1 = -2 * bb * l1, c2 = bb - aa; 6392 d = c1 * c1 - 4 * c2 * c; 6393 if (d >= 0) { 6394 let q = Math.sqrt(d); 6395 if (c1 < 0) q = -q; 6396 q = -(c1 + q) * 0.5; 6397 let r0 = q / c2, r1 = c / q; 6398 let r = Math.abs(r0) < Math.abs(r1) ? r0 : r1; 6399 r0 = dd - r * r; 6400 if (r0 >= 0) { 6401 y = Math.sqrt(r0) * bendDir; 6402 a1 = ta - Math.atan2(y, r); 6403 a2 = Math.atan2(y / psy, (r - l1) / psx); 6404 break outer; 6405 } 6406 }
6407 let minAngle = MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0; 6408 let maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0; 6409 c = -a * l1 / (aa - bb); 6410 if (c >= -1 && c <= 1) { 6411 c = Math.acos(c); 6412 x = a * Math.cos(c) + l1; 6413 y = b * Math.sin(c); 6414 d = x * x + y * y; 6415 if (d < minDist) { 6416 minAngle = c; 6417 minDist = d; 6418 minX = x; 6419 minY = y; 6420 } 6421 if (d > maxDist) { 6422 maxAngle = c; 6423 maxDist = d; 6424 maxX = x; 6425 maxY = y; 6426 } 6427 } 6428 if (dd <= (minDist + maxDist) * 0.5) { 6429 a1 = ta - Math.atan2(minY * bendDir, minX); 6430 a2 = minAngle * bendDir; 6431 } else { 6432 a1 = ta - Math.atan2(maxY * bendDir, maxX); 6433 a2 = maxAngle * bendDir; 6434 } 6435 } 6436 let os = Math.atan2(cy, cx) * s2; 6437 let rotation = parent.arotation; 6438 a1 = (a1 - os) * MathUtils.radDeg + os1 - rotation; 6439 if (a1 > 180) 6440 a1 -= 360; 6441 else if (a1 < -180) 6442 a1 += 360; 6443 parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, sy, 0, 0); 6444 rotation = child.arotation; 6445 a2 = ((a2 + os) * MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation; 6446 if (a2 > 180) 6447 a2 -= 360; 6448 else if (a2 < -180) 6449 a2 += 360; 6450 child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY); 6451 } 6452 }; 6453 6454
6454// spine-core/src/IkConstraintData.ts 6455 var IkConstraintData = class extends ConstraintData { 6456 /** The bones that are constrained by this IK constraint. */ 6457 bones = new Array(); 6458 /** The bone that is the IK target. */ 6459 _target = null; 6460 set target(boneData) { 6461 this._target = boneData; 6462 } 6463 get target() { 6464 if (!this._target) throw new Error("BoneData not set."); 6465 else return this._target; 6466 } 6467 /** Controls the bend direction of the IK bones, either 1 or -1. */ 6468 bendDirection = 0; 6469 /** When true and only a single bone is being constrained, if the target is too close, the bone is scaled to reach it. */ 6470 compress = false; 6471 /** When true, if the target is out of range, the parent bone is scaled to reach it. If more than one bone is being constrained 6472 * and the parent bone has local nonuniform scale, stretch is not applied. */ 6473 stretch = false; 6474 /** When true, only a single bone is being constrained, and {@link #getCompress()} or {@link #getStretch()} is used, the bone 6475 * is scaled on both the X and Y axes. */ 6476 uniform = false; 6477 /** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */ 6478 mix = 0; 6479 /** For two bone IK, the distance from the maximum reach of the bones that rotation will slow. */ 6480 softness = 0; 6481 constructor(name) { 6482 super(name, 0, false); 6483 } 6484 }; 6485 6486
6486// spine-core/src/PathConstraintData.ts 6487 var PathConstraintData = class extends ConstraintData { 6488 /** The bones that will be modified by this path constraint. */ 6489 bones = new Array(); 6490 /** The slot whose path attachment will be used to constrained the bones. */ 6491 _target = null; 6492 set target(slotData) { 6493 this._target = slotData; 6494 } 6495 get target() { 6496 if (!this._target) throw new Error("SlotData not set."); 6497 else return this._target; 6498 } 6499 /** The mode for positioning the first bone on the path. */ 6500 positionMode = 0 /* Fixed */; 6501 /** The mode for positioning the bones after the first bone on the path. */ 6502 spacingMode = 1 /* Fixed */; 6503 /** The mode for adjusting the rotation of the bones. */ 6504 rotateMode = 1 /* Chain */; 6505 /** An offset added to the constrained bone rotation. */ 6506 offsetRotation = 0; 6507 /** The position along the path. */ 6508 position = 0; 6509 /** The spacing between bones. */ 6510 spacing = 0; 6511 mixRotate = 0; 6512 mixX = 0; 6513 mixY = 0; 6514 constructor(name) { 6515 super(name, 0, false); 6516 } 6517 }; 6518 var PositionMode = /* @__PURE__ */ ((PositionMode2) => { 6519 PositionMode2[PositionMode2["Fixed"] = 0] = "Fixed"; 6520 PositionMode2[PositionMode2["Percent"] = 1] = "Percent"; 6521 return PositionMode2; 6522 })(PositionMode || {}); 6523 var SpacingMode = /* @__PURE__ */ ((SpacingMode2) => { 6524 SpacingMode2[SpacingMode2["Length"] = 0] = "Length"; 6525 SpacingMode2[SpacingMode2["Fixed"] = 1] = "Fixed"; 6526 SpacingMode2[SpacingMode2["Percent"] = 2] = "Percent"; 6527 SpacingMode2[SpacingMode2["Proportional"] = 3] = "Proportional"; 6528 return SpacingMode2; 6529 })(SpacingMode || {}); 6530 var RotateMode = /* @__PURE__ */ ((RotateMode2) => { 6531 RotateMode2[RotateMode2["Tangent"] = 0] = "Tangent"; 6532 RotateMode2[RotateMode2["Chain"] = 1] = "Chain"; 6533 RotateMode2[RotateMode2["ChainScale"] = 2] = "ChainScale"; 6534 return RotateMode2; 6535 })(RotateMode || {}); 6536 6537
6537// spine-core/src/PathConstraint.ts 6538 var PathConstraint = class _PathConstraint { 6539 static NONE = -1; 6540 static BEFORE = -2; 6541 static AFTER = -3; 6542 static epsilon = 1e-5; 6543 /** The path constraint's setup pose data. */ 6544 data; 6545 /** The bones that will be modified by this path constraint. */ 6546 bones; 6547 /** The slot whose path attachment will be used to constrained the bones. */ 6548 target; 6549 /** The position along the path. */ 6550 position = 0; 6551 /** The spacing between bones. */ 6552 spacing = 0; 6553 mixRotate = 0; 6554 mixX = 0; 6555 mixY = 0; 6556 spaces = new Array(); 6557 positions = new Array(); 6558 world = new Array(); 6559 curves = new Array(); 6560 lengths = new Array(); 6561 segments = new Array(); 6562 active = false; 6563 constructor(data, skeleton) { 6564 if (!data) throw new Error("data cannot be null."); 6565 if (!skeleton) throw new Error("skeleton cannot be null."); 6566 this.data = data; 6567 this.bones = new Array(); 6568 for (let i = 0, n = data.bones.length; i < n; i++) { 6569 let bone = skeleton.findBone(data.bones[i].name); 6570 if (!bone) throw new Error(`Couldn't find bone ${data.bones[i].name}.`); 6571 this.bones.push(bone); 6572 } 6573 let target = skeleton.findSlot(data.target.name); 6574 if (!target) throw new Error(`Couldn't find target bone ${data.target.name}`); 6575 this.target = target; 6576 this.position = data.position; 6577 this.spacing = data.spacing; 6578 this.mixRotate = data.mixRotate; 6579 this.mixX = data.mixX; 6580 this.mixY = data.mixY; 6581 } 6582 isActive() { 6583 return this.active; 6584 } 6585 setToSetupPose() { 6586 const data = this.data; 6587 this.position = data.position; 6588 this.spacing = data.spacing; 6589 this.mixRotate = data.mixRotate; 6590 this.mixX = data.mixX; 6591 this.mixY = data.mixY; 6592 } 6593 update(physics) { 6594 let attachment = this.target.getAttachment(); 6595 if (!(attachment instanceof PathAttachment)) return; 6596 let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY; 6597 if (mixRotate == 0 && mixX == 0 && mixY == 0) return; 6598 let data = this.data; 6599 let tangents = data.rotateMode == 0 /* Tangent */, scale = data.rotateMode == 2 /* ChainScale */; 6600 let bones = this.bones; 6601 let boneCount = bones.length, spacesCount = tangents ? boneCount : boneCount + 1; 6602 let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths = scale ? this.lengths = Utils.setArraySize(this.lengths, boneCount) : []; 6603 let spacing = this.spacing; 6604 switch (data.spacingMode) { 6605 case 2 /* Percent */: 6606 if (scale) { 6607 for (let i = 0, n = spacesCount - 1; i < n; i++) { 6608 let bone = bones[i]; 6609 let setupLength = bone.data.length; 6610 let x = setupLength * bone.a, y = setupLength * bone.c; 6611 lengths[i] = Math.sqrt(x * x + y * y); 6612 } 6613 } 6614 Utils.arrayFill(spaces, 1, spacesCount, spacing); 6615 break; 6616 case 3 /* Proportional */: 6617 let sum = 0; 6618 for (let i = 0, n = spacesCount - 1; i < n; ) { 6619 let bone = bones[i]; 6620 let setupLength = bone.data.length; 6621 if (setupLength < _PathConstraint.epsilon) { 6622 if (scale) lengths[i] = 0; 6623 spaces[++i] = spacing; 6624 } else { 6625 let x = setupLength * bone.a, y = setupLength * bone.c; 6626 let length = Math.sqrt(x * x + y * y); 6627 if (scale) lengths[i] = length; 6628 spaces[++i] = length; 6629 sum += length; 6630 } 6631 } 6632 if (sum > 0) { 6633 sum = spacesCount / sum * spacing; 6634 for (let i = 1; i < spacesCount; i++) 6635 spaces[i] *= sum; 6636 } 6637 break; 6638 default: 6639 let lengthSpacing = data.spacingMode == 0 /* Length */; 6640 for (let i = 0, n = spacesCount - 1; i < n; ) { 6641 let bone = bones[i]; 6642 let setupLength = bone.data.length; 6643 if (setupLength < _PathConstraint.epsilon) { 6644 if (scale) lengths[i] = 0;
6645 spaces[++i] = spacing; 6646 } else { 6647 let x = setupLength * bone.a, y = setupLength * bone.c; 6648 let length = Math.sqrt(x * x + y * y); 6649 if (scale) lengths[i] = length; 6650 spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength; 6651 } 6652 } 6653 } 6654 let positions = this.computeWorldPositions(attachment, spacesCount, tangents); 6655 let boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation; 6656 let tip = false; 6657 if (offsetRotation == 0) 6658 tip = data.rotateMode == 1 /* Chain */; 6659 else { 6660 tip = false; 6661 let p = this.target.bone; 6662 offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.degRad : -MathUtils.degRad; 6663 } 6664 for (let i = 0, p = 3; i < boneCount; i++, p += 3) { 6665 let bone = bones[i]; 6666 bone.worldX += (boneX - bone.worldX) * mixX; 6667 bone.worldY += (boneY - bone.worldY) * mixY; 6668 let x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY; 6669 if (scale) { 6670 let length = lengths[i]; 6671 if (length != 0) { 6672 let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1; 6673 bone.a *= s; 6674 bone.c *= s; 6675 } 6676 } 6677 boneX = x; 6678 boneY = y; 6679 if (mixRotate > 0) { 6680 let a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0; 6681 if (tangents) 6682 r = positions[p - 1]; 6683 else if (spaces[i + 1] == 0) 6684 r = positions[p + 2]; 6685 else 6686 r = Math.atan2(dy, dx); 6687 r -= Math.atan2(c, a); 6688 if (tip) { 6689 cos = Math.cos(r); 6690 sin = Math.sin(r); 6691 let length = bone.data.length; 6692 boneX += (length * (cos * a - sin * c) - dx) * mixRotate; 6693 boneY += (length * (sin * a + cos * c) - dy) * mixRotate; 6694 } else { 6695 r += offsetRotation; 6696 } 6697 if (r > MathUtils.PI) 6698 r -= MathUtils.PI2; 6699 else if (r < -MathUtils.PI) 6700 r += MathUtils.PI2; 6701 r *= mixRotate; 6702 cos = Math.cos(r); 6703 sin = Math.sin(r); 6704 bone.a = cos * a - sin * c; 6705 bone.b = cos * b - sin * d; 6706 bone.c = sin * a + cos * c; 6707 bone.d = sin * b + cos * d; 6708 } 6709 bone.updateAppliedTransform(); 6710 } 6711 } 6712 computeWorldPositions(path, spacesCount, tangents) { 6713 let target = this.target; 6714 let position = this.position; 6715 let spaces = this.spaces, out = Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = this.world; 6716 let closed2 = path.closed; 6717 let verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = _PathConstraint.NONE; 6718 if (!path.constantSpeed) { 6719 let lengths = path.lengths; 6720 curveCount -= closed2 ? 1 : 2; 6721 let pathLength2 = lengths[curveCount]; 6722 if (this.data.positionMode == 1 /* Percent */) position *= pathLength2; 6723 let multiplier2; 6724 switch (this.data.spacingMode) { 6725 case 2 /* Percent */: 6726 multiplier2 = pathLength2; 6727 break; 6728 case 3 /* Proportional */: 6729 multiplier2 = pathLength2 / spacesCount; 6730 break; 6731 default: 6732 multiplier2 = 1; 6733 } 6734 world = Utils.setArraySize(this.world, 8); 6735 for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) { 6736 let space = spaces[i] * multiplier2; 6737 position += space; 6738 let p = position; 6739 if (closed2) { 6740 p %= pathLength2; 6741 if (p < 0) p += pathLength2; 6742 curve = 0; 6743 } else if (p < 0) { 6744 if (prevCurve != _PathConstraint.BEFORE) { 6745 prevCurve = _PathConstraint.BEFORE; 6746 path.computeWorldVertices(target, 2, 4, world, 0, 2); 6747 } 6748 this.addBeforePosition(p, world, 0, out, o); 6749 continue; 6750 } else if (p > pathLength2) { 6751 if (prevCurve != _PathConstraint.AFTER) { 6752 prevCurve = _PathConstraint.AFTER;
6753 path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2); 6754 } 6755 this.addAfterPosition(p - pathLength2, world, 0, out, o); 6756 continue; 6757 } 6758 for (; ; curve++) { 6759 let length = lengths[curve]; 6760 if (p > length) continue; 6761 if (curve == 0) 6762 p /= length; 6763 else { 6764 let prev = lengths[curve - 1]; 6765 p = (p - prev) / (length - prev); 6766 } 6767 break; 6768 } 6769 if (curve != prevCurve) { 6770 prevCurve = curve; 6771 if (closed2 && curve == curveCount) { 6772 path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2); 6773 path.computeWorldVertices(target, 0, 4, world, 4, 2); 6774 } else 6775 path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2); 6776 } 6777 this.addCurvePosition( 6778 p, 6779 world[0], 6780 world[1], 6781 world[2], 6782 world[3], 6783 world[4], 6784 world[5], 6785 world[6], 6786 world[7], 6787 out, 6788 o, 6789 tangents || i > 0 && space == 0 6790 ); 6791 } 6792 return out; 6793 } 6794 if (closed2) { 6795 verticesLength += 2; 6796 world = Utils.setArraySize(this.world, verticesLength); 6797 path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2); 6798 path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2); 6799 world[verticesLength - 2] = world[0]; 6800 world[verticesLength - 1] = world[1]; 6801 } else { 6802 curveCount--; 6803 verticesLength -= 4; 6804 world = Utils.setArraySize(this.world, verticesLength); 6805 path.computeWorldVertices(target, 2, verticesLength, world, 0, 2); 6806 } 6807 let curves = Utils.setArraySize(this.curves, curveCount); 6808 let pathLength = 0; 6809 let x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0; 6810 let tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0; 6811 for (let i = 0, w = 2; i < curveCount; i++, w += 6) { 6812 cx1 = world[w]; 6813 cy1 = world[w + 1]; 6814 cx2 = world[w + 2]; 6815 cy2 = world[w + 3]; 6816 x2 = world[w + 4]; 6817 y2 = world[w + 5]; 6818 tmpx = (x1 - cx1 * 2 + cx2) * 0.1875; 6819 tmpy = (y1 - cy1 * 2 + cy2) * 0.1875; 6820 dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375; 6821 dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375; 6822 ddfx = tmpx * 2 + dddfx; 6823 ddfy = tmpy * 2 + dddfy; 6824 dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667; 6825 dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667; 6826 pathLength += Math.sqrt(dfx * dfx + dfy * dfy); 6827 dfx += ddfx; 6828 dfy += ddfy; 6829 ddfx += dddfx; 6830 ddfy += dddfy; 6831 pathLength += Math.sqrt(dfx * dfx + dfy * dfy); 6832 dfx += ddfx; 6833 dfy += ddfy; 6834 pathLength += Math.sqrt(dfx * dfx + dfy * dfy); 6835 dfx += ddfx + dddfx; 6836 dfy += ddfy + dddfy; 6837 pathLength += Math.sqrt(dfx * dfx + dfy * dfy); 6838 curves[i] = pathLength; 6839 x1 = x2; 6840 y1 = y2; 6841 } 6842 if (this.data.positionMode == 1 /* Percent */) position *= pathLength; 6843 let multiplier; 6844 switch (this.data.spacingMode) { 6845 case 2 /* Percent */: 6846 multiplier = pathLength; 6847 break; 6848 case 3 /* Proportional */: 6849 multiplier = pathLength / spacesCount; 6850 break; 6851 default: 6852 multiplier = 1; 6853 } 6854 let segments = this.segments; 6855 let curveLength = 0; 6856 for (let i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) { 6857 let space = spaces[i] * multiplier; 6858 position += space; 6859 let p = position; 6860 if (closed2) { 6861 p %= pathLength; 6862 if (p < 0) p += pathLength; 6863 curve = 0; 6864 } else if (p < 0) { 6865 this.addBeforePosition(p, world, 0, out, o); 6866 continue; 6867 } else if (p > pathLength) { 6868 this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o); 6869 continue; 6870 } 6871 for (; ; curve++) { 6872 let length = curves[curve]; 6873 if (p > length) continue; 6874 if (curve == 0) 6875 p /= length; 6876 else { 6877 let prev = curves[curve - 1]; 6878 p = (p - prev) / (length - prev); 6879 } 6880 break; 6881 } 6882 if (curve != prevCurve) { 6883 prevCurve = curve; 6884 let ii = curve * 6; 6885 x1 = world[ii]; 6886 y1 = world[ii + 1]; 6887 cx1 = world[ii + 2]; 6888 cy1 = world[ii + 3]; 6889 cx2 = world[ii + 4]; 6890 cy2 = world[ii + 5]; 6891 x2 = world[ii + 6]; 6892 y2 = world[ii + 7]; 6893 tmpx = (x1 - cx1 * 2 + cx2) * 0.03; 6894 tmpy = (y1 - cy1 * 2 + cy2) * 0.03; 6895 dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 6e-3; 6896 dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 6e-3; 6897 ddfx = tmpx * 2 + dddfx; 6898 ddfy = tmpy * 2 + dddfy; 6899 dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667; 6900 dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667; 6901 curveLength = Math.sqrt(dfx * dfx + dfy * dfy); 6902 segments[0] = curveLength; 6903 for (ii = 1; ii < 8; ii++) { 6904 dfx += ddfx; 6905 dfy += ddfy; 6906 ddfx += dddfx; 6907 ddfy += dddfy; 6908 curveLength += Math.sqrt(dfx * dfx + dfy * dfy); 6909 segments[ii] = curveLength; 6910 } 6911 dfx += ddfx; 6912 dfy += ddfy; 6913 curveLength += Math.sqrt(dfx * dfx + dfy * dfy); 6914 segments[8] = curveLength; 6915 dfx += ddfx + dddfx; 6916 dfy += ddfy + dddfy; 6917 curveLength += Math.sqrt(dfx * dfx + dfy * dfy); 6918 segments[9] = curveLength; 6919 segment = 0; 6920 } 6921 p *= curveLength; 6922 for (; ; segment++) { 6923 let length = segments[segment]; 6924 if (p > length) continue; 6925 if (segment == 0) 6926 p /= length; 6927 else { 6928 let prev = segments[segment - 1]; 6929 p = segment + (p - prev) / (length - prev); 6930 } 6931 break; 6932 } 6933 this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || i > 0 && space == 0); 6934 } 6935 return out; 6936 } 6937 addBeforePosition(p, temp, i, out, o) { 6938 let x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx); 6939 out[o] = x1 + p * Math.cos(r); 6940 out[o + 1] = y1 + p * Math.sin(r); 6941 out[o + 2] = r; 6942 } 6943 addAfterPosition(p, temp, i, out, o) { 6944 let x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx); 6945 out[o] = x1 + p * Math.cos(r); 6946 out[o + 1] = y1 + p * Math.sin(r); 6947 out[o + 2] = r; 6948 } 6949 addCurvePosition(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) { 6950 if (p == 0 || isNaN(p)) { 6951 out[o] = x1; 6952 out[o + 1] = y1; 6953 out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1); 6954 return; 6955 } 6956 let tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u; 6957 let ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p; 6958 let x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt; 6959 out[o] = x; 6960 out[o + 1] = y; 6961 if (tangents) { 6962 if (p < 1e-3) 6963 out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1); 6964 else 6965 out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); 6966 } 6967 } 6968 }; 6969 6970
6970// spine-core/src/PhysicsConstraint.ts 6971 var PhysicsConstraint = class { 6972 data; 6973 _bone = null; 6974 /** The bone constrained by this physics constraint. */ 6975 set bone(bone) { 6976 this._bone = bone; 6977 } 6978 get bone() { 6979 if (!this._bone) throw new Error("Bone not set."); 6980 else return this._bone; 6981 } 6982 inertia = 0; 6983 strength = 0; 6984 damping = 0; 6985 massInverse = 0; 6986 wind = 0; 6987 gravity = 0; 6988 mix = 0; 6989 _reset = true; 6990 ux = 0; 6991 uy = 0; 6992 cx = 0; 6993 cy = 0; 6994 tx = 0; 6995 ty = 0; 6996 xOffset = 0; 6997 xVelocity = 0; 6998 yOffset = 0; 6999 yVelocity = 0; 7000 rotateOffset = 0; 7001 rotateVelocity = 0; 7002 scaleOffset = 0; 7003 scaleVelocity = 0; 7004 active = false; 7005 skeleton; 7006 remaining = 0; 7007 lastTime = 0; 7008 constructor(data, skeleton) { 7009 this.data = data; 7010 this.skeleton = skeleton; 7011 this.bone = skeleton.bones[data.bone.index]; 7012 this.inertia = data.inertia; 7013 this.strength = data.strength; 7014 this.damping = data.damping; 7015 this.massInverse = data.massInverse; 7016 this.wind = data.wind; 7017 this.gravity = data.gravity; 7018 this.mix = data.mix; 7019 } 7020 reset() { 7021 this.remaining = 0; 7022 this.lastTime = this.skeleton.time; 7023 this._reset = true; 7024 this.xOffset = 0; 7025 this.xVelocity = 0; 7026 this.yOffset = 0; 7027 this.yVelocity = 0; 7028 this.rotateOffset = 0; 7029 this.rotateVelocity = 0; 7030 this.scaleOffset = 0; 7031 this.scaleVelocity = 0; 7032 } 7033 setToSetupPose() { 7034 const data = this.data; 7035 this.inertia = data.inertia; 7036 this.strength = data.strength; 7037 this.damping = data.damping; 7038 this.massInverse = data.massInverse; 7039 this.wind = data.wind; 7040 this.gravity = data.gravity; 7041 this.mix = data.mix; 7042 } 7043 isActive() { 7044 return this.active; 7045 } 7046 /** Applies the constraint to the constrained bones. */ 7047 update(physics) { 7048 const mix = this.mix; 7049 if (mix == 0) return; 7050 const x = this.data.x > 0, y = this.data.y > 0, rotateOrShearX = this.data.rotate > 0 || this.data.shearX > 0, scaleX = this.data.scaleX > 0; 7051 const bone = this.bone; 7052 const l = bone.data.length; 7053 switch (physics) { 7054 case 0 /* none */: 7055 return; 7056 case 1 /* reset */: 7057 this.reset(); 7058 // Fall through. 7059 case 2 /* update */: 7060 const skeleton = this.skeleton; 7061 const delta = Math.max(this.skeleton.time - this.lastTime, 0); 7062 this.remaining += delta; 7063 this.lastTime = skeleton.time; 7064 const bx = bone.worldX, by = bone.worldY; 7065 if (this._reset) { 7066 this._reset = false; 7067 this.ux = bx; 7068 this.uy = by; 7069 } else { 7070 let a = this.remaining, i = this.inertia, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1; 7071 let qx = this.data.limit * delta, qy = qx * Math.abs(skeleton.scaleY); 7072 qx *= Math.abs(skeleton.scaleX); 7073 if (x || y) { 7074 if (x) { 7075 const u = (this.ux - bx) * i; 7076 this.xOffset += u > qx ? qx : u < -qx ? -qx : u; 7077 this.ux = bx; 7078 } 7079 if (y) { 7080 const u = (this.uy - by) * i; 7081 this.yOffset += u > qy ? qy : u < -qy ? -qy : u; 7082 this.uy = by; 7083 } 7084 if (a >= t) { 7085 d = Math.pow(this.damping, 60 * t); 7086 const m = this.massInverse * t, e = this.strength, w = this.wind * f * skeleton.scaleX, g = this.gravity * f * skeleton.scaleY; 7087 do { 7088 if (x) { 7089 this.xVelocity += (w - this.xOffset * e) * m; 7090 this.xOffset += this.xVelocity * t; 7091 this.xVelocity *= d; 7092 } 7093 if (y) { 7094 this.yVelocity -= (g + this.yOffset * e) * m; 7095 this.yOffset += this.yVelocity * t; 7096 this.yVelocity *= d; 7097 } 7098 a -= t; 7099 } while (a >= t); 7100 } 7101 if (x) bone.worldX += this.xOffset * mix * this.data.x; 7102 if (y) bone.worldY += this.yOffset * mix * this.data.y; 7103 } 7104 if (rotateOrShearX || scaleX) { 7105 let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0; 7106 let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY; 7107 if (dx > qx) 7108 dx = qx; 7109 else if (dx < -qx) 7110 dx = -qx; 7111 if (dy > qy) 7112 dy = qy; 7113 else if (dy < -qy) 7114 dy = -qy; 7115 if (rotateOrShearX) { 7116 mr = (this.data.rotate + this.data.shearX) * mix; 7117 let r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr;
7118 this.rotateOffset += (r - Math.ceil(r * MathUtils.invPI2 - 0.5) * MathUtils.PI2) * i; 7119 r = this.rotateOffset * mr + ca; 7120 c = Math.cos(r); 7121 s = Math.sin(r); 7122 if (scaleX) { 7123 r = l * bone.getWorldScaleX(); 7124 if (r > 0) this.scaleOffset += (dx * c + dy * s) * i / r; 7125 } 7126 } else { 7127 c = Math.cos(ca); 7128 s = Math.sin(ca); 7129 const r = l * bone.getWorldScaleX(); 7130 if (r > 0) this.scaleOffset += (dx * c + dy * s) * i / r; 7131 } 7132 a = this.remaining; 7133 if (a >= t) { 7134 if (d == -1) d = Math.pow(this.damping, 60 * t); 7135 const m = this.massInverse * t, e = this.strength, w = this.wind, g = Skeleton.yDown ? -this.gravity : this.gravity, h = l / f; 7136 while (true) { 7137 a -= t; 7138 if (scaleX) { 7139 this.scaleVelocity += (w * c - g * s - this.scaleOffset * e) * m; 7140 this.scaleOffset += this.scaleVelocity * t; 7141 this.scaleVelocity *= d; 7142 } 7143 if (rotateOrShearX) { 7144 this.rotateVelocity -= ((w * s + g * c) * h + this.rotateOffset * e) * m; 7145 this.rotateOffset += this.rotateVelocity * t; 7146 this.rotateVelocity *= d; 7147 if (a < t) break; 7148 const r = this.rotateOffset * mr + ca; 7149 c = Math.cos(r); 7150 s = Math.sin(r); 7151 } else if (a < t) 7152 break; 7153 } 7154 } 7155 } 7156 this.remaining = a; 7157 } 7158 this.cx = bone.worldX; 7159 this.cy = bone.worldY; 7160 break; 7161 case 3 /* pose */: 7162 if (x) bone.worldX += this.xOffset * mix * this.data.x; 7163 if (y) bone.worldY += this.yOffset * mix * this.data.y; 7164 } 7165 if (rotateOrShearX) { 7166 let o = this.rotateOffset * mix, s = 0, c = 0, a = 0; 7167 if (this.data.shearX > 0) { 7168 let r = 0; 7169 if (this.data.rotate > 0) { 7170 r = o * this.data.rotate; 7171 s = Math.sin(r); 7172 c = Math.cos(r); 7173 a = bone.b; 7174 bone.b = c * a - s * bone.d; 7175 bone.d = s * a + c * bone.d; 7176 } 7177 r += o * this.data.shearX; 7178 s = Math.sin(r); 7179 c = Math.cos(r); 7180 a = bone.a; 7181 bone.a = c * a - s * bone.c; 7182 bone.c = s * a + c * bone.c; 7183 } else { 7184 o *= this.data.rotate; 7185 s = Math.sin(o); 7186 c = Math.cos(o); 7187 a = bone.a; 7188 bone.a = c * a - s * bone.c; 7189 bone.c = s * a + c * bone.c; 7190 a = bone.b; 7191 bone.b = c * a - s * bone.d; 7192 bone.d = s * a + c * bone.d; 7193 } 7194 } 7195 if (scaleX) { 7196 const s = 1 + this.scaleOffset * mix * this.data.scaleX; 7197 bone.a *= s; 7198 bone.c *= s; 7199 } 7200 if (physics != 3 /* pose */) { 7201 this.tx = l * bone.a; 7202 this.ty = l * bone.c; 7203 } 7204 bone.updateAppliedTransform(); 7205 } 7206 /** Translates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone moved an additional 7207 * amount in world space. */ 7208 translate(x, y) { 7209 this.ux -= x; 7210 this.uy -= y; 7211 this.cx -= x; 7212 this.cy -= y; 7213 } 7214 /** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the 7215 * specified point in world space. */ 7216 rotate(x, y, degrees) { 7217 const r = degrees * MathUtils.degRad, cos = Math.cos(r), sin = Math.sin(r); 7218 const dx = this.cx - x, dy = this.cy - y; 7219 this.translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy); 7220 } 7221 }; 7222 7223
7223// spine-core/src/Slot.ts 7224 var Slot = class { 7225 /** The slot's setup pose data. */ 7226 data; 7227 /** The bone this slot belongs to. */ 7228 bone; 7229 /** The color used to tint the slot's attachment. If {@link #getDarkColor()} is set, this is used as the light color for two 7230 * color tinting. */ 7231 color; 7232 /** The dark color used to tint the slot's attachment for two color tinting, or null if two color tinting is not used. The dark 7233 * color's alpha is not used. */ 7234 darkColor = null; 7235 attachment = null; 7236 attachmentState = 0; 7237 /** The index of the texture region to display when the slot's attachment has a {@link Sequence}. -1 represents the 7238 * {@link Sequence#getSetupIndex()}. */ 7239 sequenceIndex = -1; 7240 /** Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a 7241 * weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions. 7242 * 7243 * See {@link VertexAttachment#computeWorldVertices()} and {@link DeformTimeline}. */ 7244 deform = new Array(); 7245 constructor(data, bone) { 7246 if (!data) throw new Error("data cannot be null."); 7247 if (!bone) throw new Error("bone cannot be null."); 7248 this.data = data; 7249 this.bone = bone; 7250 this.color = new Color(); 7251 this.darkColor = !data.darkColor ? null : new Color(); 7252 this.setToSetupPose(); 7253 } 7254 /** The skeleton this slot belongs to. */ 7255 getSkeleton() { 7256 return this.bone.skeleton; 7257 } 7258 /** The current attachment for the slot, or null if the slot has no attachment. */ 7259 getAttachment() { 7260 return this.attachment; 7261 } 7262 /** Sets the slot's attachment and, if the attachment changed, resets {@link #sequenceIndex} and clears the {@link #deform}. 7263 * The deform is not cleared if the old attachment has the same {@link VertexAttachment#getTimelineAttachment()} as the 7264 * specified attachment. */ 7265 setAttachment(attachment) { 7266 if (this.attachment == attachment) return; 7267 if (!(attachment instanceof VertexAttachment) || !(this.attachment instanceof VertexAttachment) || attachment.timelineAttachment != this.attachment.timelineAttachment) { 7268 this.deform.length = 0; 7269 } 7270 this.attachment = attachment; 7271 this.sequenceIndex = -1; 7272 } 7273 /** Sets this slot to the setup pose. */ 7274 setToSetupPose() { 7275 this.color.setFromColor(this.data.color); 7276 if (this.darkColor) this.darkColor.setFromColor(this.data.darkColor); 7277 if (!this.data.attachmentName) 7278 this.attachment = null; 7279 else { 7280 this.attachment = null; 7281 this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName)); 7282 } 7283 } 7284 }; 7285 7286
7286// spine-core/src/TransformConstraint.ts 7287 var TransformConstraint = class { 7288 /** The transform constraint's setup pose data. */ 7289 data; 7290 /** The bones that will be modified by this transform constraint. */ 7291 bones; 7292 /** The target bone whose world transform will be copied to the constrained bones. */ 7293 target; 7294 mixRotate = 0; 7295 mixX = 0; 7296 mixY = 0; 7297 mixScaleX = 0; 7298 mixScaleY = 0; 7299 mixShearY = 0; 7300 temp = new Vector2(); 7301 active = false; 7302 constructor(data, skeleton) { 7303 if (!data) throw new Error("data cannot be null."); 7304 if (!skeleton) throw new Error("skeleton cannot be null."); 7305 this.data = data; 7306 this.bones = new Array(); 7307 for (let i = 0; i < data.bones.length; i++) { 7308 let bone = skeleton.findBone(data.bones[i].name); 7309 if (!bone) throw new Error(`Couldn't find bone ${data.bones[i].name}.`); 7310 this.bones.push(bone); 7311 } 7312 let target = skeleton.findBone(data.target.name); 7313 if (!target) throw new Error(`Couldn't find target bone ${data.target.name}.`); 7314 this.target = target; 7315 this.mixRotate = data.mixRotate; 7316 this.mixX = data.mixX; 7317 this.mixY = data.mixY; 7318 this.mixScaleX = data.mixScaleX; 7319 this.mixScaleY = data.mixScaleY; 7320 this.mixShearY = data.mixShearY; 7321 } 7322 isActive() { 7323 return this.active; 7324 } 7325 setToSetupPose() { 7326 const data = this.data; 7327 this.mixRotate = data.mixRotate; 7328 this.mixX = data.mixX; 7329 this.mixY = data.mixY; 7330 this.mixScaleX = data.mixScaleX; 7331 this.mixScaleY = data.mixScaleY; 7332 this.mixShearY = data.mixShearY; 7333 } 7334 update(physics) { 7335 if (this.mixRotate == 0 && this.mixX == 0 && this.mixY == 0 && this.mixScaleX == 0 && this.mixScaleY == 0 && this.mixShearY == 0) return; 7336 if (this.data.local) { 7337 if (this.data.relative) 7338 this.applyRelativeLocal(); 7339 else 7340 this.applyAbsoluteLocal(); 7341 } else { 7342 if (this.data.relative) 7343 this.applyRelativeWorld(); 7344 else 7345 this.applyAbsoluteWorld(); 7346 } 7347 } 7348 applyAbsoluteWorld() { 7349 let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; 7350 let translate = mixX != 0 || mixY != 0; 7351 let target = this.target; 7352 let ta = target.a, tb = target.b, tc = target.c, td = target.d; 7353 let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad; 7354 let offsetRotation = this.data.offsetRotation * degRadReflect; 7355 let offsetShearY = this.data.offsetShearY * degRadReflect; 7356 let bones = this.bones; 7357 for (let i = 0, n = bones.length; i < n; i++) { 7358 let bone = bones[i]; 7359 if (mixRotate != 0) { 7360 let a = bone.a, b = bone.b, c = bone.c, d = bone.d; 7361 let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation; 7362 if (r > MathUtils.PI) 7363 r -= MathUtils.PI2; 7364 else if (r < -MathUtils.PI) 7365 r += MathUtils.PI2; 7366 r *= mixRotate; 7367 let cos = Math.cos(r), sin = Math.sin(r); 7368 bone.a = cos * a - sin * c; 7369 bone.b = cos * b - sin * d; 7370 bone.c = sin * a + cos * c; 7371 bone.d = sin * b + cos * d; 7372 } 7373 if (translate) { 7374 let temp = this.temp; 7375 target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY)); 7376 bone.worldX += (temp.x - bone.worldX) * mixX; 7377 bone.worldY += (temp.y - bone.worldY) * mixY; 7378 } 7379 if (mixScaleX != 0) { 7380 let s = Math.sqrt(bone.a * bone.a + bone.c * bone.c); 7381 if (s != 0) s = (s + (Math.sqrt(ta * ta + tc * tc) - s + this.data.offsetScaleX) * mixScaleX) / s; 7382 bone.a *= s; 7383 bone.c *= s; 7384 } 7385 if (mixScaleY != 0) { 7386 let s = Math.sqrt(bone.b * bone.b + bone.d * bone.d); 7387 if (s != 0) s = (s + (Math.sqrt(tb * tb + td * td) - s + this.data.offsetScaleY) * mixScaleY) / s; 7388 bone.b *= s; 7389 bone.d *= s; 7390 } 7391 if (mixShearY > 0) { 7392 let b = bone.b, d = bone.d; 7393 let by = Math.atan2(d, b); 7394 let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a)); 7395 if (r > MathUtils.PI) 7396 r -= MathUtils.PI2; 7397 else if (r < -MathUtils.PI) 7398 r += MathUtils.PI2;
7399 r = by + (r + offsetShearY) * mixShearY; 7400 let s = Math.sqrt(b * b + d * d); 7401 bone.b = Math.cos(r) * s; 7402 bone.d = Math.sin(r) * s; 7403 } 7404 bone.updateAppliedTransform(); 7405 } 7406 } 7407 applyRelativeWorld() { 7408 let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; 7409 let translate = mixX != 0 || mixY != 0; 7410 let target = this.target; 7411 let ta = target.a, tb = target.b, tc = target.c, td = target.d; 7412 let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad; 7413 let offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect; 7414 let bones = this.bones; 7415 for (let i = 0, n = bones.length; i < n; i++) { 7416 let bone = bones[i]; 7417 if (mixRotate != 0) { 7418 let a = bone.a, b = bone.b, c = bone.c, d = bone.d; 7419 let r = Math.atan2(tc, ta) + offsetRotation; 7420 if (r > MathUtils.PI) 7421 r -= MathUtils.PI2; 7422 else if (r < -MathUtils.PI) 7423 r += MathUtils.PI2; 7424 r *= mixRotate; 7425 let cos = Math.cos(r), sin = Math.sin(r); 7426 bone.a = cos * a - sin * c; 7427 bone.b = cos * b - sin * d; 7428 bone.c = sin * a + cos * c; 7429 bone.d = sin * b + cos * d; 7430 } 7431 if (translate) { 7432 let temp = this.temp; 7433 target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY)); 7434 bone.worldX += temp.x * mixX; 7435 bone.worldY += temp.y * mixY; 7436 } 7437 if (mixScaleX != 0) { 7438 let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * mixScaleX + 1; 7439 bone.a *= s; 7440 bone.c *= s; 7441 } 7442 if (mixScaleY != 0) { 7443 let s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * mixScaleY + 1; 7444 bone.b *= s; 7445 bone.d *= s; 7446 } 7447 if (mixShearY > 0) { 7448 let r = Math.atan2(td, tb) - Math.atan2(tc, ta); 7449 if (r > MathUtils.PI) 7450 r -= MathUtils.PI2; 7451 else if (r < -MathUtils.PI) 7452 r += MathUtils.PI2; 7453 let b = bone.b, d = bone.d; 7454 r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * mixShearY; 7455 let s = Math.sqrt(b * b + d * d); 7456 bone.b = Math.cos(r) * s; 7457 bone.d = Math.sin(r) * s; 7458 } 7459 bone.updateAppliedTransform(); 7460 } 7461 } 7462 applyAbsoluteLocal() { 7463 let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; 7464 let target = this.target; 7465 let bones = this.bones; 7466 for (let i = 0, n = bones.length; i < n; i++) { 7467 let bone = bones[i]; 7468 let rotation = bone.arotation; 7469 if (mixRotate != 0) rotation += (target.arotation - rotation + this.data.offsetRotation) * mixRotate; 7470 let x = bone.ax, y = bone.ay; 7471 x += (target.ax - x + this.data.offsetX) * mixX; 7472 y += (target.ay - y + this.data.offsetY) * mixY; 7473 let scaleX = bone.ascaleX, scaleY = bone.ascaleY; 7474 if (mixScaleX != 0 && scaleX != 0) 7475 scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * mixScaleX) / scaleX; 7476 if (mixScaleY != 0 && scaleY != 0) 7477 scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * mixScaleY) / scaleY; 7478 let shearY = bone.ashearY; 7479 if (mixShearY != 0) shearY += (target.ashearY - shearY + this.data.offsetShearY) * mixShearY; 7480 bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY); 7481 } 7482 } 7483 applyRelativeLocal() { 7484 let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; 7485 let target = this.target; 7486 let bones = this.bones; 7487 for (let i = 0, n = bones.length; i < n; i++) { 7488 let bone = bones[i]; 7489 let rotation = bone.arotation + (target.arotation + this.data.offsetRotation) * mixRotate; 7490 let x = bone.ax + (target.ax + this.data.offsetX) * mixX; 7491 let y = bone.ay + (target.ay + this.data.offsetY) * mixY; 7492 let scaleX = bone.ascaleX * ((target.ascaleX - 1 + this.data.offsetScaleX) * mixScaleX + 1); 7493 let scaleY = bone.ascaleY * ((target.ascaleY - 1 + this.data.offsetScaleY) * mixScaleY + 1); 7494 let shearY = bone.ashearY + (target.ashearY + this.data.offsetShearY) * mixShearY; 7495 bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY); 7496 } 7497 } 7498 }; 7499 7500
7500// spine-core/src/Skeleton.ts 7501 var Skeleton = class _Skeleton { 7502 static quadTriangles = [0, 1, 2, 2, 3, 0]; 7503 static yDown = false; 7504 /** The skeleton's setup pose data. */ 7505 data; 7506 /** The skeleton's bones, sorted parent first. The root bone is always the first bone. */ 7507 bones; 7508 /** The skeleton's slots in the setup pose draw order. */ 7509 slots; 7510 /** The skeleton's slots in the order they should be drawn. The returned array may be modified to change the draw order. */ 7511 drawOrder; 7512 /** The skeleton's IK constraints. */ 7513 ikConstraints; 7514 /** The skeleton's transform constraints. */ 7515 transformConstraints; 7516 /** The skeleton's path constraints. */ 7517 pathConstraints; 7518 /** The skeleton's physics constraints. */ 7519 physicsConstraints; 7520 /** The list of bones and constraints, sorted in the order they should be updated, as computed by {@link #updateCache()}. */ 7521 _updateCache = new Array(); 7522 /** The skeleton's current skin. May be null. */ 7523 skin = null; 7524 /** The color to tint all the skeleton's attachments. */ 7525 color; 7526 /** Scales the entire skeleton on the X axis. This affects all bones, even if the bone's transform mode disallows scale 7527 * inheritance. */ 7528 scaleX = 1; 7529 /** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale 7530 * inheritance. */ 7531 _scaleY = 1; 7532 get scaleY() { 7533 return _Skeleton.yDown ? -this._scaleY : this._scaleY; 7534 } 7535 set scaleY(scaleY) { 7536 this._scaleY = scaleY; 7537 } 7538 /** Sets the skeleton X position, which is added to the root bone worldX position. */ 7539 x = 0; 7540 /** Sets the skeleton Y position, which is added to the root bone worldY position. */ 7541 y = 0; 7542 /** Returns the skeleton's time. This is used for time-based manipulations, such as {@link PhysicsConstraint}. 7543 * <p> 7544 * See {@link #update(float)}. */ 7545 time = 0; 7546 constructor(data) { 7547 if (!data) throw new Error("data cannot be null."); 7548 this.data = data; 7549 this.bones = new Array(); 7550 for (let i = 0; i < data.bones.length; i++) { 7551 let boneData = data.bones[i]; 7552 let bone; 7553 if (!boneData.parent) 7554 bone = new Bone(boneData, this, null); 7555 else { 7556 let parent = this.bones[boneData.parent.index]; 7557 bone = new Bone(boneData, this, parent); 7558 parent.children.push(bone); 7559 } 7560 this.bones.push(bone); 7561 } 7562 this.slots = new Array(); 7563 this.drawOrder = new Array(); 7564 for (let i = 0; i < data.slots.length; i++) { 7565 let slotData = data.slots[i]; 7566 let bone = this.bones[slotData.boneData.index]; 7567 let slot = new Slot(slotData, bone); 7568 this.slots.push(slot); 7569 this.drawOrder.push(slot); 7570 } 7571 this.ikConstraints = new Array(); 7572 for (let i = 0; i < data.ikConstraints.length; i++) { 7573 let ikConstraintData = data.ikConstraints[i]; 7574 this.ikConstraints.push(new IkConstraint(ikConstraintData, this)); 7575 } 7576 this.transformConstraints = new Array(); 7577 for (let i = 0; i < data.transformConstraints.length; i++) { 7578 let transformConstraintData = data.transformConstraints[i]; 7579 this.transformConstraints.push(new TransformConstraint(transformConstraintData, this)); 7580 } 7581 this.pathConstraints = new Array(); 7582 for (let i = 0; i < data.pathConstraints.length; i++) { 7583 let pathConstraintData = data.pathConstraints[i]; 7584 this.pathConstraints.push(new PathConstraint(pathConstraintData, this)); 7585 } 7586 this.physicsConstraints = new Array(); 7587 for (let i = 0; i < data.physicsConstraints.length; i++) { 7588 let physicsConstraintData = data.physicsConstraints[i]; 7589 this.physicsConstraints.push(new PhysicsConstraint(physicsConstraintData, this)); 7590 } 7591 this.color = new Color(1, 1, 1, 1); 7592 this.updateCache(); 7593 } 7594 /** Caches information about bones and constraints. Must be called if the {@link #getSkin()} is modified or if bones, 7595 * constraints, or weighted path attachments are added or removed. */ 7596 updateCache() { 7597 let updateCache = this._updateCache; 7598 updateCache.length = 0; 7599 let bones = this.bones; 7600 for (let i = 0, n = bones.length; i < n; i++) { 7601 let bone = bones[i]; 7602 bone.sorted = bone.data.skinRequired; 7603 bone.active = !bone.sorted; 7604 } 7605 if (this.skin) { 7606 let skinBones = this.skin.bones; 7607 for (let i = 0, n = this.skin.bones.length; i < n; i++) { 7608 let bone = this.bones[skinBones[i].index]; 7609 do { 7610 bone.sorted = false;
7611 bone.active = true; 7612 bone = bone.parent; 7613 } while (bone); 7614 } 7615 } 7616 let ikConstraints = this.ikConstraints; 7617 let transformConstraints = this.transformConstraints; 7618 let pathConstraints = this.pathConstraints; 7619 let physicsConstraints = this.physicsConstraints; 7620 let ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length, physicsCount = this.physicsConstraints.length; 7621 let constraintCount = ikCount + transformCount + pathCount + physicsCount; 7622 outer: 7623 for (let i = 0; i < constraintCount; i++) { 7624 for (let ii = 0; ii < ikCount; ii++) { 7625 let constraint = ikConstraints[ii]; 7626 if (constraint.data.order == i) { 7627 this.sortIkConstraint(constraint); 7628 continue outer; 7629 } 7630 } 7631 for (let ii = 0; ii < transformCount; ii++) { 7632 let constraint = transformConstraints[ii]; 7633 if (constraint.data.order == i) { 7634 this.sortTransformConstraint(constraint); 7635 continue outer; 7636 } 7637 } 7638 for (let ii = 0; ii < pathCount; ii++) { 7639 let constraint = pathConstraints[ii]; 7640 if (constraint.data.order == i) { 7641 this.sortPathConstraint(constraint); 7642 continue outer; 7643 } 7644 } 7645 for (let ii = 0; ii < physicsCount; ii++) { 7646 const constraint = physicsConstraints[ii]; 7647 if (constraint.data.order == i) { 7648 this.sortPhysicsConstraint(constraint); 7649 continue outer; 7650 } 7651 } 7652 } 7653 for (let i = 0, n = bones.length; i < n; i++) 7654 this.sortBone(bones[i]); 7655 } 7656 sortIkConstraint(constraint) { 7657 constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || this.skin && Utils.contains(this.skin.constraints, constraint.data, true)); 7658 if (!constraint.active) return; 7659 let target = constraint.target; 7660 this.sortBone(target); 7661 let constrained = constraint.bones; 7662 let parent = constrained[0]; 7663 this.sortBone(parent); 7664 if (constrained.length == 1) { 7665 this._updateCache.push(constraint); 7666 this.sortReset(parent.children); 7667 } else { 7668 let child = constrained[constrained.length - 1]; 7669 this.sortBone(child); 7670 this._updateCache.push(constraint); 7671 this.sortReset(parent.children); 7672 child.sorted = true; 7673 } 7674 } 7675 sortPathConstraint(constraint) { 7676 constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || this.skin && Utils.contains(this.skin.constraints, constraint.data, true)); 7677 if (!constraint.active) return; 7678 let slot = constraint.target; 7679 let slotIndex = slot.data.index; 7680 let slotBone = slot.bone; 7681 if (this.skin) this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone); 7682 if (this.data.defaultSkin && this.data.defaultSkin != this.skin) 7683 this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone); 7684 for (let i = 0, n = this.data.skins.length; i < n; i++) 7685 this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone); 7686 let attachment = slot.getAttachment(); 7687 if (attachment instanceof PathAttachment) this.sortPathConstraintAttachmentWith(attachment, slotBone); 7688 let constrained = constraint.bones; 7689 let boneCount = constrained.length; 7690 for (let i = 0; i < boneCount; i++) 7691 this.sortBone(constrained[i]); 7692 this._updateCache.push(constraint); 7693 for (let i = 0; i < boneCount; i++) 7694 this.sortReset(constrained[i].children); 7695 for (let i = 0; i < boneCount; i++) 7696 constrained[i].sorted = true; 7697 } 7698 sortTransformConstraint(constraint) { 7699 constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || this.skin && Utils.contains(this.skin.constraints, constraint.data, true)); 7700 if (!constraint.active) return; 7701 this.sortBone(constraint.target); 7702 let constrained = constraint.bones; 7703 let boneCount = constrained.length; 7704 if (constraint.data.local) { 7705 for (let i = 0; i < boneCount; i++) { 7706 let child = constrained[i]; 7707 this.sortBone(child.parent); 7708 this.sortBone(child); 7709 } 7710 } else { 7711 for (let i = 0; i < boneCount; i++) { 7712 this.sortBone(constrained[i]); 7713 } 7714 } 7715 this._updateCache.push(constraint); 7716 for (let i = 0; i < boneCount; i++) 7717 this.sortReset(constrained[i].children); 7718 for (let i = 0; i < boneCount; i++) 7719 constrained[i].sorted = true; 7720 } 7721 sortPathConstraintAttachment(skin, slotIndex, slotBone) { 7722 let attachments = skin.attachments[slotIndex]; 7723 if (!attachments) return; 7724 for (let key in attachments) { 7725 this.sortPathConstraintAttachmentWith(attachments[key], slotBone); 7726 } 7727 } 7728 sortPathConstraintAttachmentWith(attachment, slotBone) { 7729 if (!(attachment instanceof PathAttachment)) return; 7730 let pathBones = attachment.bones; 7731 if (!pathBones) 7732 this.sortBone(slotBone); 7733 else { 7734 let bones = this.bones; 7735 for (let i = 0, n = pathBones.length; i < n; ) { 7736 let nn = pathBones[i++]; 7737 nn += i; 7738 while (i < nn) 7739 this.sortBone(bones[pathBones[i++]]); 7740 } 7741 } 7742 } 7743 sortPhysicsConstraint(constraint) { 7744 const bone = constraint.bone; 7745 constraint.active = bone.active && (!constraint.data.skinRequired || this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)); 7746 if (!constraint.active) return; 7747 this.sortBone(bone); 7748 this._updateCache.push(constraint); 7749 this.sortReset(bone.children); 7750 bone.sorted = true; 7751 } 7752 sortBone(bone) { 7753 if (!bone) return; 7754 if (bone.sorted) return; 7755 let parent = bone.parent; 7756 if (parent) this.sortBone(parent); 7757 bone.sorted = true; 7758 this._updateCache.push(bone); 7759 } 7760 sortReset(bones) { 7761 for (let i = 0, n = bones.length; i < n; i++) { 7762 let bone = bones[i]; 7763 if (!bone.active) continue; 7764 if (bone.sorted) this.sortReset(bone.children); 7765 bone.sorted = false;
7766 } 7767 } 7768 /** Updates the world transform for each bone and applies all constraints. 7769 * 7770 * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine 7771 * Runtimes Guide. */ 7772 updateWorldTransform(physics) { 7773 if (physics === void 0 || physics === null) throw new Error("physics is undefined"); 7774 let bones = this.bones; 7775 for (let i = 0, n = bones.length; i < n; i++) { 7776 let bone = bones[i]; 7777 bone.ax = bone.x; 7778 bone.ay = bone.y; 7779 bone.arotation = bone.rotation; 7780 bone.ascaleX = bone.scaleX; 7781 bone.ascaleY = bone.scaleY; 7782 bone.ashearX = bone.shearX; 7783 bone.ashearY = bone.shearY; 7784 } 7785 let updateCache = this._updateCache; 7786 for (let i = 0, n = updateCache.length; i < n; i++) 7787 updateCache[i].update(physics); 7788 } 7789 updateWorldTransformWith(physics, parent) { 7790 if (!parent) throw new Error("parent cannot be null."); 7791 let bones = this.bones; 7792 for (let i = 1, n = bones.length; i < n; i++) { 7793 let bone = bones[i]; 7794 bone.ax = bone.x; 7795 bone.ay = bone.y; 7796 bone.arotation = bone.rotation; 7797 bone.ascaleX = bone.scaleX; 7798 bone.ascaleY = bone.scaleY; 7799 bone.ashearX = bone.shearX; 7800 bone.ashearY = bone.shearY; 7801 } 7802 let rootBone = this.getRootBone(); 7803 if (!rootBone) throw new Error("Root bone must not be null."); 7804 let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d; 7805 rootBone.worldX = pa * this.x + pb * this.y + parent.worldX; 7806 rootBone.worldY = pc * this.x + pd * this.y + parent.worldY; 7807 const rx = (rootBone.rotation + rootBone.shearX) * MathUtils.degRad; 7808 const ry = (rootBone.rotation + 90 + rootBone.shearY) * MathUtils.degRad; 7809 const la = Math.cos(rx) * rootBone.scaleX; 7810 const lb = Math.cos(ry) * rootBone.scaleY; 7811 const lc = Math.sin(rx) * rootBone.scaleX; 7812 const ld = Math.sin(ry) * rootBone.scaleY; 7813 rootBone.a = (pa * la + pb * lc) * this.scaleX; 7814 rootBone.b = (pa * lb + pb * ld) * this.scaleX; 7815 rootBone.c = (pc * la + pd * lc) * this.scaleY; 7816 rootBone.d = (pc * lb + pd * ld) * this.scaleY; 7817 let updateCache = this._updateCache; 7818 for (let i = 0, n = updateCache.length; i < n; i++) { 7819 let updatable = updateCache[i]; 7820 if (updatable != rootBone) updatable.update(physics); 7821 } 7822 } 7823 /** Sets the bones, constraints, and slots to their setup pose values. */ 7824 setToSetupPose() { 7825 this.setBonesToSetupPose(); 7826 this.setSlotsToSetupPose(); 7827 } 7828 /** Sets the bones and constraints to their setup pose values. */ 7829 setBonesToSetupPose() { 7830 for (const bone of this.bones) bone.setToSetupPose(); 7831 for (const constraint of this.ikConstraints) constraint.setToSetupPose(); 7832 for (const constraint of this.transformConstraints) constraint.setToSetupPose(); 7833 for (const constraint of this.pathConstraints) constraint.setToSetupPose(); 7834 for (const constraint of this.physicsConstraints) constraint.setToSetupPose(); 7835 } 7836 /** Sets the slots and draw order to their setup pose values. */ 7837 setSlotsToSetupPose() { 7838 let slots = this.slots; 7839 Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length); 7840 for (let i = 0, n = slots.length; i < n; i++) 7841 slots[i].setToSetupPose(); 7842 } 7843 /** @returns May return null. */ 7844 getRootBone() { 7845 if (this.bones.length == 0) return null; 7846 return this.bones[0]; 7847 } 7848 /** @returns May be null. */ 7849 findBone(boneName) { 7850 if (!boneName) throw new Error("boneName cannot be null."); 7851 let bones = this.bones; 7852 for (let i = 0, n = bones.length; i < n; i++) { 7853 let bone = bones[i]; 7854 if (bone.data.name == boneName) return bone; 7855 } 7856 return null; 7857 } 7858 /** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it 7859 * repeatedly. 7860 * @returns May be null. */ 7861 findSlot(slotName) { 7862 if (!slotName) throw new Error("slotName cannot be null."); 7863 let slots = this.slots; 7864 for (let i = 0, n = slots.length; i < n; i++) { 7865 let slot = slots[i]; 7866 if (slot.data.name == slotName) return slot; 7867 } 7868 return null; 7869 } 7870 /** Sets a skin by name. 7871 * 7872 * See {@link #setSkin()}. */ 7873 setSkinByName(skinName) { 7874 let skin = this.data.findSkin(skinName); 7875 if (!skin) throw new Error("Skin not found: " + skinName); 7876 this.setSkin(skin); 7877 } 7878 /** Sets the skin used to look up attachments before looking in the {@link SkeletonData#defaultSkin default skin}. If the 7879 * skin is changed, {@link #updateCache()} is called. 7880 * 7881 * Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. If there was no 7882 * old skin, each slot's setup mode attachment is attached from the new skin. 7883 * 7884 * After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling 7885 * {@link #setSlotsToSetupPose()}. Also, often {@link AnimationState#apply()} is called before the next time the 7886 * skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin. 7887 * @param newSkin May be null. */ 7888 setSkin(newSkin) { 7889 if (newSkin == this.skin) return; 7890 if (newSkin) { 7891 if (this.skin) 7892 newSkin.attachAll(this, this.skin); 7893 else { 7894 let slots = this.slots; 7895 for (let i = 0, n = slots.length; i < n; i++) { 7896 let slot = slots[i]; 7897 let name = slot.data.attachmentName; 7898 if (name) { 7899 let attachment = newSkin.getAttachment(i, name); 7900 if (attachment) slot.setAttachment(attachment); 7901 } 7902 } 7903 } 7904 } 7905 this.skin = newSkin; 7906 this.updateCache(); 7907 } 7908 /** Finds an attachment by looking in the {@link #skin} and {@link SkeletonData#defaultSkin} using the slot name and attachment 7909 * name. 7910 * 7911 * See {@link #getAttachment()}. 7912 * @returns May be null. */ 7913 getAttachmentByName(slotName, attachmentName) { 7914 let slot = this.data.findSlot(slotName); 7915 if (!slot) throw new Error(`Can't find slot with name ${slotName}`); 7916 return this.getAttachment(slot.index, attachmentName); 7917 } 7918 /** Finds an attachment by looking in the {@link #skin} and {@link SkeletonData#defaultSkin} using the slot index and 7919 * attachment name. First the skin is checked and if the attachment was not found, the default skin is checked. 7920 * 7921 * See [Runtime skins](http://esotericsoftware.com/spine-runtime-skins) in the Spine Runtimes Guide. 7922 * @returns May be null. */ 7923 getAttachment(slotIndex, attachmentName) { 7924 if (!attachmentName) throw new Error("attachmentName cannot be null."); 7925 if (this.skin) { 7926 let attachment = this.skin.getAttachment(slotIndex, attachmentName); 7927 if (attachment) return attachment; 7928 } 7929 if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName); 7930 return null; 7931 } 7932 /** A convenience method to set an attachment by finding the slot with {@link #findSlot()}, finding the attachment with 7933 * {@link #getAttachment()}, then setting the slot's {@link Slot#attachment}. 7934 * @param attachmentName May be null to clear the slot's attachment. */ 7935 setAttachment(slotName, attachmentName) { 7936 if (!slotName) throw new Error("slotName cannot be null."); 7937 let slots = this.slots; 7938 for (let i = 0, n = slots.length; i < n; i++) { 7939 let slot = slots[i]; 7940 if (slot.data.name == slotName) { 7941 let attachment = null; 7942 if (attachmentName) { 7943 attachment = this.getAttachment(i, attachmentName); 7944 if (!attachment) throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName); 7945 } 7946 slot.setAttachment(attachment); 7947 return; 7948 } 7949 } 7950 throw new Error("Slot not found: " + slotName); 7951 } 7952 /** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method 7953 * than to call it repeatedly. 7954 * @return May be null. */ 7955 findIkConstraint(constraintName) { 7956 if (!constraintName) throw new Error("constraintName cannot be null."); 7957 return this.ikConstraints.find((constraint) => constraint.data.name == constraintName) ?? null; 7958 } 7959 /** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of 7960 * this method than to call it repeatedly. 7961 * @return May be null. */ 7962 findTransformConstraint(constraintName) { 7963 if (!constraintName) throw new Error("constraintName cannot be null."); 7964 return this.transformConstraints.find((constraint) => constraint.data.name == constraintName) ?? null; 7965 } 7966 /** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method 7967 * than to call it repeatedly. 7968 * @return May be null. */ 7969 findPathConstraint(constraintName) { 7970 if (!constraintName) throw new Error("constraintName cannot be null."); 7971 return this.pathConstraints.find((constraint) => constraint.data.name == constraintName) ?? null; 7972 } 7973 /** Finds a physics constraint by comparing each physics constraint's name. It is more efficient to cache the results of this 7974 * method than to call it repeatedly. */ 7975 findPhysicsConstraint(constraintName) { 7976 if (constraintName == null) throw new Error("constraintName cannot be null."); 7977 return this.physicsConstraints.find((constraint) => constraint.data.name == constraintName) ?? null; 7978 }
7979 /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose as `{ x: number, y: number, width: number, height: number }`. 7980 * Note that this method will create temporary objects which can add to garbage collection pressure. Use `getBounds()` if garbage collection is a concern. */ 7981 getBoundsRect(clipper) { 7982 let offset = new Vector2(); 7983 let size = new Vector2(); 7984 this.getBounds(offset, size, void 0, clipper); 7985 return { x: offset.x, y: offset.y, width: size.x, height: size.y }; 7986 } 7987 /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose. 7988 * @param offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB. 7989 * @param size An output value, the width and height of the AABB. 7990 * @param temp Working memory to temporarily store attachments' computed world vertices. 7991 * @param clipper {@link SkeletonClipping} to use. If <code>null</code>, no clipping is applied. */ 7992 getBounds(offset, size, temp = new Array(2), clipper = null) { 7993 if (!offset) throw new Error("offset cannot be null."); 7994 if (!size) throw new Error("size cannot be null."); 7995 let drawOrder = this.drawOrder; 7996 let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY; 7997 for (let i = 0, n = drawOrder.length; i < n; i++) { 7998 let slot = drawOrder[i]; 7999 if (!slot.bone.active) continue; 8000 let verticesLength = 0; 8001 let vertices = null; 8002 let triangles = null; 8003 let attachment = slot.getAttachment(); 8004 if (attachment instanceof RegionAttachment) { 8005 verticesLength = 8; 8006 vertices = Utils.setArraySize(temp, verticesLength, 0); 8007 attachment.computeWorldVertices(slot, vertices, 0, 2); 8008 triangles = _Skeleton.quadTriangles; 8009 } else if (attachment instanceof MeshAttachment) { 8010 let mesh = attachment; 8011 verticesLength = mesh.worldVerticesLength; 8012 vertices = Utils.setArraySize(temp, verticesLength, 0); 8013 mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2); 8014 triangles = mesh.triangles; 8015 } else if (attachment instanceof ClippingAttachment && clipper != null) { 8016 clipper.clipStart(slot, attachment); 8017 continue; 8018 } 8019 if (vertices && triangles) { 8020 if (clipper != null && clipper.isClipping()) { 8021 clipper.clipTriangles(vertices, triangles, triangles.length); 8022 vertices = clipper.clippedVertices; 8023 verticesLength = clipper.clippedVertices.length; 8024 } 8025 for (let ii = 0, nn = vertices.length; ii < nn; ii += 2) { 8026 let x = vertices[ii], y = vertices[ii + 1]; 8027 minX = Math.min(minX, x); 8028 minY = Math.min(minY, y); 8029 maxX = Math.max(maxX, x); 8030 maxY = Math.max(maxY, y); 8031 } 8032 } 8033 if (clipper != null) clipper.clipEndWithSlot(slot); 8034 } 8035 if (clipper != null) clipper.clipEnd(); 8036 offset.set(minX, minY); 8037 size.set(maxX - minX, maxY - minY); 8038 } 8039 /** Increments the skeleton's {@link #time}. */ 8040 update(delta) { 8041 this.time += delta; 8042 } 8043 physicsTranslate(x, y) { 8044 const physicsConstraints = this.physicsConstraints; 8045 for (let i = 0, n = physicsConstraints.length; i < n; i++) 8046 physicsConstraints[i].translate(x, y); 8047 } 8048 /** Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */ 8049 physicsRotate(x, y, degrees) { 8050 const physicsConstraints = this.physicsConstraints; 8051 for (let i = 0, n = physicsConstraints.length; i < n; i++) 8052 physicsConstraints[i].rotate(x, y, degrees); 8053 } 8054 }; 8055 var Physics = /* @__PURE__ */ ((Physics2) => { 8056 Physics2[Physics2["none"] = 0] = "none"; 8057 Physics2[Physics2["reset"] = 1] = "reset"; 8058 Physics2[Physics2["update"] = 2] = "update"; 8059 Physics2[Physics2["pose"] = 3] = "pose"; 8060 return Physics2; 8061 })(Physics || {}); 8062 8063
8063// spine-core/src/PhysicsConstraintData.ts 8064 var PhysicsConstraintData = class extends ConstraintData { 8065 _bone = null; 8066 /** The bone constrained by this physics constraint. */ 8067 set bone(boneData) { 8068 this._bone = boneData; 8069 } 8070 get bone() { 8071 if (!this._bone) throw new Error("BoneData not set."); 8072 else return this._bone; 8073 } 8074 x = 0; 8075 y = 0; 8076 rotate = 0; 8077 scaleX = 0; 8078 shearX = 0; 8079 limit = 0; 8080 step = 0; 8081 inertia = 0; 8082 strength = 0; 8083 damping = 0; 8084 massInverse = 0; 8085 wind = 0; 8086 gravity = 0; 8087 /** A percentage (0-1) that controls the mix between the constrained and unconstrained poses. */ 8088 mix = 0; 8089 inertiaGlobal = false; 8090 strengthGlobal = false; 8091 dampingGlobal = false; 8092 massGlobal = false; 8093 windGlobal = false; 8094 gravityGlobal = false; 8095 mixGlobal = false; 8096 constructor(name) { 8097 super(name, 0, false); 8098 } 8099 }; 8100 8101
8101// spine-core/src/SkeletonData.ts 8102 var SkeletonData = class { 8103 /** The skeleton's name, which by default is the name of the skeleton data file, if possible. May be null. */ 8104 name = null; 8105 /** The skeleton's bones, sorted parent first. The root bone is always the first bone. */ 8106 bones = new Array(); 8107 // Ordered parents first. 8108 /** The skeleton's slots in the setup pose draw order. */ 8109 slots = new Array(); 8110 // Setup pose draw order. 8111 skins = new Array(); 8112 /** The skeleton's default skin. By default this skin contains all attachments that were not in a skin in Spine. 8113 * 8114 * See {@link Skeleton#getAttachmentByName()}. 8115 * May be null. */ 8116 defaultSkin = null; 8117 /** The skeleton's events. */ 8118 events = new Array(); 8119 /** The skeleton's animations. */ 8120 animations = new Array(); 8121 /** The skeleton's IK constraints. */ 8122 ikConstraints = new Array(); 8123 /** The skeleton's transform constraints. */ 8124 transformConstraints = new Array(); 8125 /** The skeleton's path constraints. */ 8126 pathConstraints = new Array(); 8127 /** The skeleton's physics constraints. */ 8128 physicsConstraints = new Array(); 8129 /** The X coordinate of the skeleton's axis aligned bounding box in the setup pose. */ 8130 x = 0; 8131 /** The Y coordinate of the skeleton's axis aligned bounding box in the setup pose. */ 8132 y = 0; 8133 /** The width of the skeleton's axis aligned bounding box in the setup pose. */ 8134 width = 0; 8135 /** The height of the skeleton's axis aligned bounding box in the setup pose. */ 8136 height = 0; 8137 /** Baseline scale factor for applying distance-dependent effects on non-scalable properties, such as angle or scale. Default 8138 * is 100. */ 8139 referenceScale = 100; 8140 /** The Spine version used to export the skeleton data, or null. */ 8141 version = null; 8142 /** The skeleton data hash. This value will change if any of the skeleton data has changed. May be null. */ 8143 hash = null; 8144 // Nonessential 8145 /** The dopesheet FPS in Spine. Available only when nonessential data was exported. */ 8146 fps = 0; 8147 /** The path to the images directory as defined in Spine. Available only when nonessential data was exported. May be null. */ 8148 imagesPath = null; 8149 /** The path to the audio directory as defined in Spine. Available only when nonessential data was exported. May be null. */ 8150 audioPath = null; 8151 /** Finds a bone by comparing each bone's name. It is more efficient to cache the results of this method than to call it 8152 * multiple times. 8153 * @returns May be null. */ 8154 findBone(boneName) { 8155 if (!boneName) throw new Error("boneName cannot be null."); 8156 let bones = this.bones; 8157 for (let i = 0, n = bones.length; i < n; i++) { 8158 let bone = bones[i]; 8159 if (bone.name == boneName) return bone; 8160 } 8161 return null; 8162 } 8163 /** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it 8164 * multiple times. 8165 * @returns May be null. */ 8166 findSlot(slotName) { 8167 if (!slotName) throw new Error("slotName cannot be null."); 8168 let slots = this.slots; 8169 for (let i = 0, n = slots.length; i < n; i++) { 8170 let slot = slots[i]; 8171 if (slot.name == slotName) return slot; 8172 } 8173 return null; 8174 } 8175 /** Finds a skin by comparing each skin's name. It is more efficient to cache the results of this method than to call it 8176 * multiple times. 8177 * @returns May be null. */ 8178 findSkin(skinName) { 8179 if (!skinName) throw new Error("skinName cannot be null."); 8180 let skins = this.skins; 8181 for (let i = 0, n = skins.length; i < n; i++) { 8182 let skin = skins[i]; 8183 if (skin.name == skinName) return skin; 8184 } 8185 return null; 8186 } 8187 /** Finds an event by comparing each events's name. It is more efficient to cache the results of this method than to call it 8188 * multiple times. 8189 * @returns May be null. */ 8190 findEvent(eventDataName) { 8191 if (!eventDataName) throw new Error("eventDataName cannot be null."); 8192 let events = this.events; 8193 for (let i = 0, n = events.length; i < n; i++) { 8194 let event = events[i]; 8195 if (event.name == eventDataName) return event; 8196 } 8197 return null; 8198 } 8199 /** Finds an animation by comparing each animation's name. It is more efficient to cache the results of this method than to 8200 * call it multiple times. 8201 * @returns May be null. */ 8202 findAnimation(animationName) { 8203 if (!animationName) throw new Error("animationName cannot be null."); 8204 let animations = this.animations; 8205 for (let i = 0, n = animations.length; i < n; i++) { 8206 let animation = animations[i]; 8207 if (animation.name == animationName) return animation; 8208 } 8209 return null; 8210 } 8211 /** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method 8212 * than to call it multiple times. 8213 * @return May be null. */ 8214 findIkConstraint(constraintName) { 8215 if (!constraintName) throw new Error("constraintName cannot be null."); 8216 const ikConstraints = this.ikConstraints; 8217 for (let i = 0, n = ikConstraints.length; i < n; i++) { 8218 const constraint = ikConstraints[i]; 8219 if (constraint.name == constraintName) return constraint; 8220 } 8221 return null; 8222 } 8223 /** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of 8224 * this method than to call it multiple times. 8225 * @return May be null. */ 8226 findTransformConstraint(constraintName) { 8227 if (!constraintName) throw new Error("constraintName cannot be null."); 8228 const transformConstraints = this.transformConstraints; 8229 for (let i = 0, n = transformConstraints.length; i < n; i++) { 8230 const constraint = transformConstraints[i]; 8231 if (constraint.name == constraintName) return constraint; 8232 } 8233 return null; 8234 } 8235 /** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method 8236 * than to call it multiple times. 8237 * @return May be null. */ 8238 findPathConstraint(constraintName) { 8239 if (!constraintName) throw new Error("constraintName cannot be null."); 8240 const pathConstraints = this.pathConstraints; 8241 for (let i = 0, n = pathConstraints.length; i < n; i++) { 8242 const constraint = pathConstraints[i]; 8243 if (constraint.name == constraintName) return constraint; 8244 } 8245 return null; 8246 } 8247 /** Finds a physics constraint by comparing each physics constraint's name. It is more efficient to cache the results of this method 8248 * than to call it multiple times. 8249 * @return May be null. */ 8250 findPhysicsConstraint(constraintName) { 8251 if (!constraintName) throw new Error("constraintName cannot be null."); 8252 const physicsConstraints = this.physicsConstraints; 8253 for (let i = 0, n = physicsConstraints.length; i < n; i++) { 8254 const constraint = physicsConstraints[i]; 8255 if (constraint.name == constraintName) return constraint; 8256 } 8257 return null; 8258 } 8259 }; 8260 8261
8261// spine-core/src/Skin.ts 8262 var SkinEntry = class { 8263 constructor(slotIndex = 0, name, attachment) { 8264 this.slotIndex = slotIndex; 8265 this.name = name; 8266 this.attachment = attachment; 8267 } 8268 }; 8269 var Skin = class { 8270 /** The skin's name, which is unique across all skins in the skeleton. */ 8271 name; 8272 attachments = new Array(); 8273 bones = Array(); 8274 constraints = new Array(); 8275 /** The color of the skin as it was in Spine, or a default color if nonessential data was not exported. */ 8276 color = new Color(0.99607843, 0.61960787, 0.30980393, 1); 8277 // fe9e4fff 8278 constructor(name) { 8279 if (!name) throw new Error("name cannot be null."); 8280 this.name = name; 8281 } 8282 /** Adds an attachment to the skin for the specified slot index and name. */ 8283 setAttachment(slotIndex, name, attachment) { 8284 if (!attachment) throw new Error("attachment cannot be null."); 8285 let attachments = this.attachments; 8286 if (slotIndex >= attachments.length) attachments.length = slotIndex + 1; 8287 if (!attachments[slotIndex]) attachments[slotIndex] = {}; 8288 attachments[slotIndex][name] = attachment; 8289 } 8290 /** Adds all attachments, bones, and constraints from the specified skin to this skin. */ 8291 addSkin(skin) { 8292 for (let i = 0; i < skin.bones.length; i++) { 8293 let bone = skin.bones[i]; 8294 let contained = false; 8295 for (let ii = 0; ii < this.bones.length; ii++) { 8296 if (this.bones[ii] == bone) { 8297 contained = true; 8298 break; 8299 } 8300 } 8301 if (!contained) this.bones.push(bone); 8302 } 8303 for (let i = 0; i < skin.constraints.length; i++) { 8304 let constraint = skin.constraints[i]; 8305 let contained = false; 8306 for (let ii = 0; ii < this.constraints.length; ii++) { 8307 if (this.constraints[ii] == constraint) { 8308 contained = true; 8309 break; 8310 } 8311 } 8312 if (!contained) this.constraints.push(constraint); 8313 } 8314 let attachments = skin.getAttachments(); 8315 for (let i = 0; i < attachments.length; i++) { 8316 var attachment = attachments[i]; 8317 this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment); 8318 } 8319 } 8320 /** Adds all bones and constraints and copies of all attachments from the specified skin to this skin. Mesh attachments are not 8321 * copied, instead a new linked mesh is created. The attachment copies can be modified without affecting the originals. */ 8322 copySkin(skin) { 8323 for (let i = 0; i < skin.bones.length; i++) { 8324 let bone = skin.bones[i]; 8325 let contained = false; 8326 for (let ii = 0; ii < this.bones.length; ii++) { 8327 if (this.bones[ii] == bone) { 8328 contained = true; 8329 break; 8330 } 8331 } 8332 if (!contained) this.bones.push(bone); 8333 } 8334 for (let i = 0; i < skin.constraints.length; i++) { 8335 let constraint = skin.constraints[i]; 8336 let contained = false; 8337 for (let ii = 0; ii < this.constraints.length; ii++) { 8338 if (this.constraints[ii] == constraint) { 8339 contained = true; 8340 break; 8341 } 8342 } 8343 if (!contained) this.constraints.push(constraint); 8344 } 8345 let attachments = skin.getAttachments(); 8346 for (let i = 0; i < attachments.length; i++) { 8347 var attachment = attachments[i]; 8348 if (!attachment.attachment) continue; 8349 if (attachment.attachment instanceof MeshAttachment) { 8350 attachment.attachment = attachment.attachment.newLinkedMesh(); 8351 this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment); 8352 } else { 8353 attachment.attachment = attachment.attachment.copy(); 8354 this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment); 8355 } 8356 } 8357 } 8358 /** Returns the attachment for the specified slot index and name, or null. */ 8359 getAttachment(slotIndex, name) { 8360 let dictionary = this.attachments[slotIndex]; 8361 return dictionary ? dictionary[name] : null; 8362 } 8363 /** Removes the attachment in the skin for the specified slot index and name, if any. */ 8364 removeAttachment(slotIndex, name) { 8365 let dictionary = this.attachments[slotIndex]; 8366 if (dictionary) delete dictionary[name]; 8367 } 8368 /** Returns all attachments in this skin. */ 8369 getAttachments() { 8370 let entries = new Array(); 8371 for (var i = 0; i < this.attachments.length; i++) { 8372 let slotAttachments = this.attachments[i]; 8373 if (slotAttachments) { 8374 for (let name in slotAttachments) { 8375 let attachment = slotAttachments[name]; 8376 if (attachment) entries.push(new SkinEntry(i, name, attachment)); 8377 } 8378 } 8379 } 8380 return entries; 8381 } 8382 /** Returns all attachments in this skin for the specified slot index. */ 8383 getAttachmentsForSlot(slotIndex, attachments) { 8384 let slotAttachments = this.attachments[slotIndex]; 8385 if (slotAttachments) { 8386 for (let name in slotAttachments) { 8387 let attachment = slotAttachments[name]; 8388 if (attachment) attachments.push(new SkinEntry(slotIndex, name, attachment)); 8389 } 8390 } 8391 } 8392 /** Clears all attachments, bones, and constraints. */ 8393 clear() { 8394 this.attachments.length = 0; 8395 this.bones.length = 0; 8396 this.constraints.length = 0; 8397 } 8398 /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ 8399 attachAll(skeleton, oldSkin) { 8400 let slotIndex = 0; 8401 for (let i = 0; i < skeleton.slots.length; i++) { 8402 let slot = skeleton.slots[i]; 8403 let slotAttachment = slot.getAttachment(); 8404 if (slotAttachment && slotIndex < oldSkin.attachments.length) { 8405 let dictionary = oldSkin.attachments[slotIndex]; 8406 for (let key in dictionary) { 8407 let skinAttachment = dictionary[key]; 8408 if (slotAttachment == skinAttachment) { 8409 let attachment = this.getAttachment(slotIndex, key); 8410 if (attachment) slot.setAttachment(attachment); 8411 break; 8412 } 8413 } 8414 } 8415 slotIndex++; 8416 } 8417 } 8418 }; 8419 8420
8420// spine-core/src/SlotData.ts 8421 var SlotData = class { 8422 /** The index of the slot in {@link Skeleton#getSlots()}. */ 8423 index = 0; 8424 /** The name of the slot, which is unique across all slots in the skeleton. */ 8425 name; 8426 /** The bone this slot belongs to. */ 8427 boneData; 8428 /** The color used to tint the slot's attachment. If {@link #getDarkColor()} is set, this is used as the light color for two 8429 * color tinting. */ 8430 color = new Color(1, 1, 1, 1); 8431 /** The dark color used to tint the slot's attachment for two color tinting, or null if two color tinting is not used. The dark 8432 * color's alpha is not used. */ 8433 darkColor = null; 8434 /** The name of the attachment that is visible for this slot in the setup pose, or null if no attachment is visible. */ 8435 attachmentName = null; 8436 /** The blend mode for drawing the slot's attachment. */ 8437 blendMode = 0 /* Normal */; 8438 /** False if the slot was hidden in Spine and nonessential data was exported. Does not affect runtime rendering. */ 8439 visible = true; 8440 constructor(index, name, boneData) { 8441 if (index < 0) throw new Error("index must be >= 0."); 8442 if (!name) throw new Error("name cannot be null."); 8443 if (!boneData) throw new Error("boneData cannot be null."); 8444 this.index = index; 8445 this.name = name; 8446 this.boneData = boneData; 8447 } 8448 }; 8449 var BlendMode = /* @__PURE__ */ ((BlendMode3) => { 8450 BlendMode3[BlendMode3["Normal"] = 0] = "Normal"; 8451 BlendMode3[BlendMode3["Additive"] = 1] = "Additive"; 8452 BlendMode3[BlendMode3["Multiply"] = 2] = "Multiply"; 8453 BlendMode3[BlendMode3["Screen"] = 3] = "Screen"; 8454 return BlendMode3; 8455 })(BlendMode || {}); 8456 8457
8457// spine-core/src/TransformConstraintData.ts 8458 var TransformConstraintData = class extends ConstraintData { 8459 /** The bones that will be modified by this transform constraint. */ 8460 bones = new Array(); 8461 /** The target bone whose world transform will be copied to the constrained bones. */ 8462 _target = null; 8463 set target(boneData) { 8464 this._target = boneData; 8465 } 8466 get target() { 8467 if (!this._target) throw new Error("BoneData not set."); 8468 else return this._target; 8469 } 8470 mixRotate = 0; 8471 mixX = 0; 8472 mixY = 0; 8473 mixScaleX = 0; 8474 mixScaleY = 0; 8475 mixShearY = 0; 8476 /** An offset added to the constrained bone rotation. */ 8477 offsetRotation = 0; 8478 /** An offset added to the constrained bone X translation. */ 8479 offsetX = 0; 8480 /** An offset added to the constrained bone Y translation. */ 8481 offsetY = 0; 8482 /** An offset added to the constrained bone scaleX. */ 8483 offsetScaleX = 0; 8484 /** An offset added to the constrained bone scaleY. */ 8485 offsetScaleY = 0; 8486 /** An offset added to the constrained bone shearY. */ 8487 offsetShearY = 0; 8488 relative = false; 8489 local = false;
8490 constructor(name) { 8491 super(name, 0, false); 8492 } 8493 }; 8494 8495
8495// spine-core/src/SkeletonBinary.ts 8496 var SkeletonBinary = class { 8497 /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at 8498 * runtime than were used in Spine. 8499 * 8500 * See [Scaling](http://esotericsoftware.com/spine-loading-skeleton-data#Scaling) in the Spine Runtimes Guide. */ 8501 scale = 1; 8502 attachmentLoader; 8503 linkedMeshes = new Array(); 8504 constructor(attachmentLoader) { 8505 this.attachmentLoader = attachmentLoader; 8506 } 8507 readSkeletonData(binary) { 8508 let scale = this.scale; 8509 let skeletonData = new SkeletonData(); 8510 skeletonData.name = ""; 8511 let input = new BinaryInput(binary); 8512 let lowHash = input.readInt32(); 8513 let highHash = input.readInt32(); 8514 skeletonData.hash = highHash == 0 && lowHash == 0 ? null : highHash.toString(16) + lowHash.toString(16); 8515 skeletonData.version = input.readString(); 8516 skeletonData.x = input.readFloat(); 8517 skeletonData.y = input.readFloat(); 8518 skeletonData.width = input.readFloat(); 8519 skeletonData.height = input.readFloat(); 8520 skeletonData.referenceScale = input.readFloat() * scale; 8521 let nonessential = input.readBoolean(); 8522 if (nonessential) { 8523 skeletonData.fps = input.readFloat(); 8524 skeletonData.imagesPath = input.readString(); 8525 skeletonData.audioPath = input.readString(); 8526 } 8527 let n = 0; 8528 n = input.readInt(true); 8529 for (let i = 0; i < n; i++) { 8530 let str = input.readString(); 8531 if (!str) throw new Error("String in string table must not be null."); 8532 input.strings.push(str); 8533 } 8534 n = input.readInt(true); 8535 for (let i = 0; i < n; i++) { 8536 let name = input.readString(); 8537 if (!name) throw new Error("Bone name must not be null."); 8538 let parent = i == 0 ? null : skeletonData.bones[input.readInt(true)]; 8539 let data = new BoneData(i, name, parent); 8540 data.rotation = input.readFloat(); 8541 data.x = input.readFloat() * scale; 8542 data.y = input.readFloat() * scale; 8543 data.scaleX = input.readFloat(); 8544 data.scaleY = input.readFloat(); 8545 data.shearX = input.readFloat(); 8546 data.shearY = input.readFloat(); 8547 data.length = input.readFloat() * scale; 8548 data.inherit = input.readByte(); 8549 data.skinRequired = input.readBoolean(); 8550 if (nonessential) { 8551 Color.rgba8888ToColor(data.color, input.readInt32()); 8552 data.icon = input.readString() ?? void 0; 8553 data.visible = input.readBoolean(); 8554 } 8555 skeletonData.bones.push(data); 8556 } 8557 n = input.readInt(true); 8558 for (let i = 0; i < n; i++) { 8559 let slotName = input.readString(); 8560 if (!slotName) throw new Error("Slot name must not be null."); 8561 let boneData = skeletonData.bones[input.readInt(true)]; 8562 let data = new SlotData(i, slotName, boneData); 8563 Color.rgba8888ToColor(data.color, input.readInt32()); 8564 let darkColor = input.readInt32(); 8565 if (darkColor != -1) Color.rgb888ToColor(data.darkColor = new Color(), darkColor); 8566 data.attachmentName = input.readStringRef(); 8567 data.blendMode = input.readInt(true); 8568 if (nonessential) data.visible = input.readBoolean(); 8569 skeletonData.slots.push(data); 8570 } 8571 n = input.readInt(true); 8572 for (let i = 0, nn; i < n; i++) { 8573 let name = input.readString(); 8574 if (!name) throw new Error("IK constraint data name must not be null."); 8575 let data = new IkConstraintData(name); 8576 data.order = input.readInt(true); 8577 nn = input.readInt(true); 8578 for (let ii = 0; ii < nn; ii++) 8579 data.bones.push(skeletonData.bones[input.readInt(true)]); 8580 data.target = skeletonData.bones[input.readInt(true)]; 8581 let flags = input.readByte(); 8582 data.skinRequired = (flags & 1) != 0; 8583 data.bendDirection = (flags & 2) != 0 ? 1 : -1; 8584 data.compress = (flags & 4) != 0; 8585 data.stretch = (flags & 8) != 0; 8586 data.uniform = (flags & 16) != 0; 8587 if ((flags & 32) != 0) data.mix = (flags & 64) != 0 ? input.readFloat() : 1; 8588 if ((flags & 128) != 0) data.softness = input.readFloat() * scale; 8589 skeletonData.ikConstraints.push(data); 8590 } 8591 n = input.readInt(true); 8592 for (let i = 0, nn; i < n; i++) { 8593 let name = input.readString(); 8594 if (!name) throw new Error("Transform constraint data name must not be null."); 8595 let data = new TransformConstraintData(name); 8596 data.order = input.readInt(true); 8597 nn = input.readInt(true); 8598 for (let ii = 0; ii < nn; ii++) 8599 data.bones.push(skeletonData.bones[input.readInt(true)]); 8600 data.target = skeletonData.bones[input.readInt(true)]; 8601 let flags = input.readByte(); 8602 data.skinRequired = (flags & 1) != 0; 8603 data.local = (flags & 2) != 0; 8604 data.relative = (flags & 4) != 0; 8605 if ((flags & 8) != 0) data.offsetRotation = input.readFloat(); 8606 if ((flags & 16) != 0) data.offsetX = input.readFloat() * scale; 8607 if ((flags & 32) != 0) data.offsetY = input.readFloat() * scale; 8608 if ((flags & 64) != 0) data.offsetScaleX = input.readFloat(); 8609 if ((flags & 128) != 0) data.offsetScaleY = input.readFloat(); 8610 flags = input.readByte(); 8611 if ((flags & 1) != 0) data.offsetShearY = input.readFloat(); 8612 if ((flags & 2) != 0) data.mixRotate = input.readFloat(); 8613 if ((flags & 4) != 0) data.mixX = input.readFloat(); 8614 if ((flags & 8) != 0) data.mixY = input.readFloat(); 8615 if ((flags & 16) != 0) data.mixScaleX = input.readFloat(); 8616 if ((flags & 32) != 0) data.mixScaleY = input.readFloat(); 8617 if ((flags & 64) != 0) data.mixShearY = input.readFloat(); 8618 skeletonData.transformConstraints.push(data); 8619 } 8620 n = input.readInt(true); 8621 for (let i = 0, nn; i < n; i++) { 8622 let name = input.readString(); 8623 if (!name) throw new Error("Path constraint data name must not be null."); 8624 let data = new PathConstraintData(name); 8625 data.order = input.readInt(true); 8626 data.skinRequired = input.readBoolean(); 8627 nn = input.readInt(true); 8628 for (let ii = 0; ii < nn; ii++) 8629 data.bones.push(skeletonData.bones[input.readInt(true)]); 8630 data.target = skeletonData.slots[input.readInt(true)]; 8631 const flags = input.readByte(); 8632 data.positionMode = flags & 1; 8633 data.spacingMode = flags >> 1 & 3; 8634 data.rotateMode = flags >> 3 & 3; 8635 if ((flags & 128) != 0) data.offsetRotation = input.readFloat(); 8636 data.position = input.readFloat(); 8637 if (data.positionMode == 0 /* Fixed */) data.position *= scale; 8638 data.spacing = input.readFloat(); 8639 if (data.spacingMode == 0 /* Length */ || data.spacingMode == 1 /* Fixed */) data.spacing *= scale; 8640 data.mixRotate = input.readFloat(); 8641 data.mixX = input.readFloat(); 8642 data.mixY = input.readFloat(); 8643 skeletonData.pathConstraints.push(data); 8644 } 8645 n = input.readInt(true); 8646 for (let i = 0, nn; i < n; i++) { 8647 const name = input.readString(); 8648 if (!name) throw new Error("Physics constraint data name must not be null."); 8649 const data = new PhysicsConstraintData(name); 8650 data.order = input.readInt(true); 8651 data.bone = skeletonData.bones[input.readInt(true)]; 8652 let flags = input.readByte(); 8653 data.skinRequired = (flags & 1) != 0; 8654 if ((flags & 2) != 0) data.x = input.readFloat(); 8655 if ((flags & 4) != 0) data.y = input.readFloat(); 8656 if ((flags & 8) != 0) data.rotate = input.readFloat(); 8657 if ((flags & 16) != 0) data.scaleX = input.readFloat(); 8658 if ((flags & 32) != 0) data.shearX = input.readFloat(); 8659 data.limit = ((flags & 64) != 0 ? input.readFloat() : 5e3) * scale; 8660 data.step = 1 / input.readUnsignedByte(); 8661 data.inertia = input.readFloat(); 8662 data.strength = input.readFloat(); 8663 data.damping = input.readFloat(); 8664 data.massInverse = (flags & 128) != 0 ? input.readFloat() : 1; 8665 data.wind = input.readFloat(); 8666 data.gravity = input.readFloat(); 8667 flags = input.readByte(); 8668 if ((flags & 1) != 0) data.inertiaGlobal = true; 8669 if ((flags & 2) != 0) data.strengthGlobal = true; 8670 if ((flags & 4) != 0) data.dampingGlobal = true; 8671 if ((flags & 8) != 0) data.massGlobal = true; 8672 if ((flags & 16) != 0) data.windGlobal = true; 8673 if ((flags & 32) != 0) data.gravityGlobal = true; 8674 if ((flags & 64) != 0) data.mixGlobal = true; 8675 data.mix = (flags & 128) != 0 ? input.readFloat() : 1; 8676 skeletonData.physicsConstraints.push(data); 8677 } 8678 let defaultSkin = this.readSkin(input, skeletonData, true, nonessential); 8679 if (defaultSkin) { 8680 skeletonData.defaultSkin = defaultSkin; 8681 skeletonData.skins.push(defaultSkin); 8682 } 8683 { 8684 let i = skeletonData.skins.length; 8685 Utils.setArraySize(skeletonData.skins, n = i + input.readInt(true)); 8686 for (; i < n; i++) { 8687 let skin = this.readSkin(input, skeletonData, false, nonessential); 8688 if (!skin) throw new Error("readSkin() should not have returned null."); 8689 skeletonData.skins[i] = skin; 8690 } 8691 } 8692 n = this.linkedMeshes.length; 8693 for (let i = 0; i < n; i++) { 8694 let linkedMesh = this.linkedMeshes[i]; 8695 const skin = skeletonData.skins[linkedMesh.skinIndex]; 8696 if (!linkedMesh.parent) throw new Error("Linked mesh parent must not be null"); 8697 let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); 8698 if (!parent) throw new Error(`Parent mesh not found: ${linkedMesh.parent}`); 8699 linkedMesh.mesh.timelineAttachment = linkedMesh.inheritTimeline ? parent : linkedMesh.mesh; 8700 linkedMesh.mesh.setParentMesh(parent); 8701 if (linkedMesh.mesh.region != null) linkedMesh.mesh.updateRegion(); 8702 } 8703 this.linkedMeshes.length = 0; 8704 n = input.readInt(true); 8705 for (let i = 0; i < n; i++) { 8706 let eventName = input.readString(); 8707 if (!eventName) throw new Error("Event data name must not be null"); 8708 let data = new EventData(eventName); 8709 data.intValue = input.readInt(false); 8710 data.floatValue = input.readFloat(); 8711 data.stringValue = input.readString(); 8712 data.audioPath = input.readString(); 8713 if (data.audioPath) { 8714 data.volume = input.readFloat(); 8715 data.balance = input.readFloat(); 8716 } 8717 skeletonData.events.push(data); 8718 } 8719 n = input.readInt(true); 8720 for (let i = 0; i < n; i++) { 8721 let animationName = input.readString(); 8722 if (!animationName) throw new Error("Animatio name must not be null."); 8723 skeletonData.animations.push(this.readAnimation(input, animationName, skeletonData)); 8724 } 8725 return skeletonData; 8726 } 8727 readSkin(input, skeletonData, defaultSkin, nonessential) { 8728 let skin = null; 8729 let slotCount = 0; 8730 if (defaultSkin) {
8731 slotCount = input.readInt(true); 8732 if (slotCount == 0) return null; 8733 skin = new Skin("default"); 8734 } else { 8735 let skinName = input.readString(); 8736 if (!skinName) throw new Error("Skin name must not be null."); 8737 skin = new Skin(skinName); 8738 if (nonessential) Color.rgba8888ToColor(skin.color, input.readInt32()); 8739 skin.bones.length = input.readInt(true); 8740 for (let i = 0, n = skin.bones.length; i < n; i++) 8741 skin.bones[i] = skeletonData.bones[input.readInt(true)]; 8742 for (let i = 0, n = input.readInt(true); i < n; i++) 8743 skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]); 8744 for (let i = 0, n = input.readInt(true); i < n; i++) 8745 skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]); 8746 for (let i = 0, n = input.readInt(true); i < n; i++) 8747 skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]); 8748 for (let i = 0, n = input.readInt(true); i < n; i++) 8749 skin.constraints.push(skeletonData.physicsConstraints[input.readInt(true)]); 8750 slotCount = input.readInt(true); 8751 } 8752 for (let i = 0; i < slotCount; i++) { 8753 let slotIndex = input.readInt(true); 8754 for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { 8755 let name = input.readStringRef(); 8756 if (!name) 8757 throw new Error("Attachment name must not be null"); 8758 let attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name, nonessential); 8759 if (attachment) skin.setAttachment(slotIndex, name, attachment); 8760 } 8761 } 8762 return skin; 8763 } 8764 readAttachment(input, skeletonData, skin, slotIndex, attachmentName, nonessential) { 8765 let scale = this.scale; 8766 let flags = input.readByte(); 8767 const name = (flags & 8) != 0 ? input.readStringRef() : attachmentName; 8768 if (!name) throw new Error("Attachment name must not be null"); 8769 switch (flags & 7) { 8770 // BUG? 8771 case 0 /* Region */: { 8772 let path = (flags & 16) != 0 ? input.readStringRef() : null; 8773 const color = (flags & 32) != 0 ? input.readInt32() : 4294967295; 8774 const sequence = (flags & 64) != 0 ? this.readSequence(input) : null; 8775 let rotation = (flags & 128) != 0 ? input.readFloat() : 0; 8776 let x = input.readFloat(); 8777 let y = input.readFloat(); 8778 let scaleX = input.readFloat(); 8779 let scaleY = input.readFloat(); 8780 let width = input.readFloat(); 8781 let height = input.readFloat(); 8782 if (!path) path = name; 8783 let region = this.attachmentLoader.newRegionAttachment(skin, name, path, sequence); 8784 if (!region) return null; 8785 region.path = path; 8786 region.x = x * scale; 8787 region.y = y * scale; 8788 region.scaleX = scaleX; 8789 region.scaleY = scaleY; 8790 region.rotation = rotation; 8791 region.width = width * scale; 8792 region.height = height * scale; 8793 Color.rgba8888ToColor(region.color, color); 8794 region.sequence = sequence; 8795 if (sequence == null) region.updateRegion(); 8796 return region; 8797 } 8798 case 1 /* BoundingBox */: { 8799 let vertices = this.readVertices(input, (flags & 16) != 0); 8800 let color = nonessential ? input.readInt32() : 0; 8801 let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name); 8802 if (!box) return null; 8803 box.worldVerticesLength = vertices.length; 8804 box.vertices = vertices.vertices; 8805 box.bones = vertices.bones; 8806 if (nonessential) Color.rgba8888ToColor(box.color, color); 8807 return box; 8808 } 8809 case 2 /* Mesh */: { 8810 let path = (flags & 16) != 0 ? input.readStringRef() : name; 8811 const color = (flags & 32) != 0 ? input.readInt32() : 4294967295; 8812 const sequence = (flags & 64) != 0 ? this.readSequence(input) : null; 8813 const hullLength = input.readInt(true); 8814 const vertices = this.readVertices(input, (flags & 128) != 0); 8815 const uvs = this.readFloatArray(input, vertices.length, 1); 8816 const triangles = this.readShortArray(input, (vertices.length - hullLength - 2) * 3); 8817 let edges = []; 8818 let width = 0, height = 0; 8819 if (nonessential) { 8820 edges = this.readShortArray(input, input.readInt(true)); 8821 width = input.readFloat(); 8822 height = input.readFloat(); 8823 } 8824 if (!path) path = name; 8825 let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence); 8826 if (!mesh) return null; 8827 mesh.path = path; 8828 Color.rgba8888ToColor(mesh.color, color); 8829 mesh.bones = vertices.bones; 8830 mesh.vertices = vertices.vertices; 8831 mesh.worldVerticesLength = vertices.length; 8832 mesh.triangles = triangles; 8833 mesh.regionUVs = uvs; 8834 if (sequence == null) mesh.updateRegion(); 8835 mesh.hullLength = hullLength << 1; 8836 mesh.sequence = sequence; 8837 if (nonessential) { 8838 mesh.edges = edges; 8839 mesh.width = width * scale; 8840 mesh.height = height * scale; 8841 } 8842 return mesh; 8843 } 8844 case 3 /* LinkedMesh */: { 8845 const path = (flags & 16) != 0 ? input.readStringRef() : name; 8846 if (path == null) throw new Error("Path of linked mesh must not be null"); 8847 const color = (flags & 32) != 0 ? input.readInt32() : 4294967295; 8848 const sequence = (flags & 64) != 0 ? this.readSequence(input) : null; 8849 const inheritTimelines = (flags & 128) != 0; 8850 const skinIndex = input.readInt(true); 8851 const parent = input.readStringRef(); 8852 let width = 0, height = 0; 8853 if (nonessential) { 8854 width = input.readFloat(); 8855 height = input.readFloat(); 8856 } 8857 let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence); 8858 if (!mesh) return null; 8859 mesh.path = path; 8860 Color.rgba8888ToColor(mesh.color, color); 8861 mesh.sequence = sequence; 8862 if (nonessential) { 8863 mesh.width = width * scale; 8864 mesh.height = height * scale; 8865 } 8866 this.linkedMeshes.push(new LinkedMesh(mesh, skinIndex, slotIndex, parent, inheritTimelines)); 8867 return mesh; 8868 } 8869 case 4 /* Path */: { 8870 const closed2 = (flags & 16) != 0; 8871 const constantSpeed = (flags & 32) != 0; 8872 const vertices = this.readVertices(input, (flags & 64) != 0); 8873 const lengths = Utils.newArray(vertices.length / 6, 0); 8874 for (let i = 0, n = lengths.length; i < n; i++) 8875 lengths[i] = input.readFloat() * scale; 8876 const color = nonessential ? input.readInt32() : 0; 8877 const path = this.attachmentLoader.newPathAttachment(skin, name); 8878 if (!path) return null;
8879 path.closed = closed2; 8880 path.constantSpeed = constantSpeed; 8881 path.worldVerticesLength = vertices.length; 8882 path.vertices = vertices.vertices; 8883 path.bones = vertices.bones; 8884 path.lengths = lengths; 8885 if (nonessential) Color.rgba8888ToColor(path.color, color); 8886 return path; 8887 } 8888 case 5 /* Point */: { 8889 const rotation = input.readFloat(); 8890 const x = input.readFloat(); 8891 const y = input.readFloat(); 8892 const color = nonessential ? input.readInt32() : 0; 8893 const point = this.attachmentLoader.newPointAttachment(skin, name); 8894 if (!point) return null; 8895 point.x = x * scale; 8896 point.y = y * scale; 8897 point.rotation = rotation; 8898 if (nonessential) Color.rgba8888ToColor(point.color, color); 8899 return point; 8900 } 8901 case 6 /* Clipping */: { 8902 const endSlotIndex = input.readInt(true); 8903 const vertices = this.readVertices(input, (flags & 16) != 0); 8904 let color = nonessential ? input.readInt32() : 0; 8905 let clip = this.attachmentLoader.newClippingAttachment(skin, name); 8906 if (!clip) return null; 8907 clip.endSlot = skeletonData.slots[endSlotIndex]; 8908 clip.worldVerticesLength = vertices.length; 8909 clip.vertices = vertices.vertices; 8910 clip.bones = vertices.bones; 8911 if (nonessential) Color.rgba8888ToColor(clip.color, color); 8912 return clip; 8913 } 8914 } 8915 return null; 8916 } 8917 readSequence(input) { 8918 let sequence = new Sequence(input.readInt(true)); 8919 sequence.start = input.readInt(true); 8920 sequence.digits = input.readInt(true); 8921 sequence.setupIndex = input.readInt(true); 8922 return sequence; 8923 } 8924 readVertices(input, weighted) { 8925 const scale = this.scale; 8926 const vertexCount = input.readInt(true); 8927 const vertices = new Vertices(); 8928 vertices.length = vertexCount << 1; 8929 if (!weighted) { 8930 vertices.vertices = this.readFloatArray(input, vertices.length, scale); 8931 return vertices; 8932 } 8933 let weights = new Array(); 8934 let bonesArray = new Array(); 8935 for (let i = 0; i < vertexCount; i++) { 8936 let boneCount = input.readInt(true); 8937 bonesArray.push(boneCount); 8938 for (let ii = 0; ii < boneCount; ii++) { 8939 bonesArray.push(input.readInt(true)); 8940 weights.push(input.readFloat() * scale); 8941 weights.push(input.readFloat() * scale); 8942 weights.push(input.readFloat()); 8943 } 8944 } 8945 vertices.vertices = Utils.toFloatArray(weights); 8946 vertices.bones = bonesArray; 8947 return vertices; 8948 } 8949 readFloatArray(input, n, scale) { 8950 let array = new Array(n); 8951 if (scale == 1) { 8952 for (let i = 0; i < n; i++) 8953 array[i] = input.readFloat(); 8954 } else { 8955 for (let i = 0; i < n; i++) 8956 array[i] = input.readFloat() * scale; 8957 } 8958 return array; 8959 } 8960 readShortArray(input, n) { 8961 let array = new Array(n); 8962 for (let i = 0; i < n; i++) 8963 array[i] = input.readInt(true); 8964 return array; 8965 } 8966 readAnimation(input, name, skeletonData) { 8967 input.readInt(true); 8968 let timelines = new Array(); 8969 let scale = this.scale; 8970 for (let i = 0, n = input.readInt(true); i < n; i++) { 8971 let slotIndex = input.readInt(true); 8972 for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { 8973 let timelineType = input.readByte(); 8974 let frameCount = input.readInt(true); 8975 let frameLast = frameCount - 1; 8976 switch (timelineType) { 8977 case SLOT_ATTACHMENT: { 8978 let timeline = new AttachmentTimeline(frameCount, slotIndex); 8979 for (let frame = 0; frame < frameCount; frame++) 8980 timeline.setFrame(frame, input.readFloat(), input.readStringRef()); 8981 timelines.push(timeline); 8982 break; 8983 } 8984 case SLOT_RGBA: { 8985 let bezierCount = input.readInt(true);
8986 let timeline = new RGBATimeline(frameCount, bezierCount, slotIndex); 8987 let time = input.readFloat(); 8988 let r = input.readUnsignedByte() / 255; 8989 let g = input.readUnsignedByte() / 255; 8990 let b = input.readUnsignedByte() / 255; 8991 let a = input.readUnsignedByte() / 255; 8992 for (let frame = 0, bezier = 0; ; frame++) { 8993 timeline.setFrame(frame, time, r, g, b, a); 8994 if (frame == frameLast) break; 8995 let time2 = input.readFloat(); 8996 let r2 = input.readUnsignedByte() / 255; 8997 let g2 = input.readUnsignedByte() / 255; 8998 let b2 = input.readUnsignedByte() / 255; 8999 let a2 = input.readUnsignedByte() / 255; 9000 switch (input.readByte()) { 9001 case CURVE_STEPPED: 9002 timeline.setStepped(frame); 9003 break; 9004 case CURVE_BEZIER: 9005 setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1); 9006 setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1); 9007 setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1); 9008 setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1); 9009 } 9010 time = time2; 9011 r = r2; 9012 g = g2; 9013 b = b2; 9014 a = a2; 9015 } 9016 timelines.push(timeline); 9017 break; 9018 } 9019 case SLOT_RGB: { 9020 let bezierCount = input.readInt(true); 9021 let timeline = new RGBTimeline(frameCount, bezierCount, slotIndex); 9022 let time = input.readFloat(); 9023 let r = input.readUnsignedByte() / 255; 9024 let g = input.readUnsignedByte() / 255; 9025 let b = input.readUnsignedByte() / 255; 9026 for (let frame = 0, bezier = 0; ; frame++) { 9027 timeline.setFrame(frame, time, r, g, b); 9028 if (frame == frameLast) break; 9029 let time2 = input.readFloat(); 9030 let r2 = input.readUnsignedByte() / 255; 9031 let g2 = input.readUnsignedByte() / 255; 9032 let b2 = input.readUnsignedByte() / 255; 9033 switch (input.readByte()) { 9034 case CURVE_STEPPED: 9035 timeline.setStepped(frame); 9036 break; 9037 case CURVE_BEZIER: 9038 setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1); 9039 setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1); 9040 setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1); 9041 } 9042 time = time2; 9043 r = r2; 9044 g = g2; 9045 b = b2; 9046 } 9047 timelines.push(timeline); 9048 break; 9049 } 9050 case SLOT_RGBA2: { 9051 let bezierCount = input.readInt(true); 9052 let timeline = new RGBA2Timeline(frameCount, bezierCount, slotIndex); 9053 let time = input.readFloat(); 9054 let r = input.readUnsignedByte() / 255; 9055 let g = input.readUnsignedByte() / 255; 9056 let b = input.readUnsignedByte() / 255; 9057 let a = input.readUnsignedByte() / 255; 9058 let r2 = input.readUnsignedByte() / 255; 9059 let g2 = input.readUnsignedByte() / 255; 9060 let b2 = input.readUnsignedByte() / 255; 9061 for (let frame = 0, bezier = 0; ; frame++) { 9062 timeline.setFrame(frame, time, r, g, b, a, r2, g2, b2); 9063 if (frame == frameLast) break; 9064 let time2 = input.readFloat(); 9065 let nr = input.readUnsignedByte() / 255; 9066 let ng = input.readUnsignedByte() / 255; 9067 let nb = input.readUnsignedByte() / 255; 9068 let na = input.readUnsignedByte() / 255; 9069 let nr2 = input.readUnsignedByte() / 255; 9070 let ng2 = input.readUnsignedByte() / 255; 9071 let nb2 = input.readUnsignedByte() / 255; 9072 switch (input.readByte()) { 9073 case CURVE_STEPPED: 9074 timeline.setStepped(frame); 9075 break; 9076 case CURVE_BEZIER: 9077 setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1); 9078 setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1); 9079 setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1); 9080 setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1); 9081 setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1); 9082 setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1); 9083 setBezier(input, timeline, bezier++, frame,
90836, time, time2, b2, nb2, 1); 9084 } 9085 time = time2; 9086 r = nr; 9087 g = ng; 9088 b = nb; 9089 a = na; 9090 r2 = nr2; 9091 g2 = ng2; 9092 b2 = nb2; 9093 } 9094 timelines.push(timeline); 9095 break; 9096 } 9097 case SLOT_RGB2: { 9098 let bezierCount = input.readInt(true); 9099 let timeline = new RGB2Timeline(frameCount, bezierCount, slotIndex); 9100 let time = input.readFloat(); 9101 let r = input.readUnsignedByte() / 255; 9102 let g = input.readUnsignedByte() / 255; 9103 let b = input.readUnsignedByte() / 255; 9104 let r2 = input.readUnsignedByte() / 255; 9105 let g2 = input.readUnsignedByte() / 255; 9106 let b2 = input.readUnsignedByte() / 255; 9107 for (let frame = 0, bezier = 0; ; frame++) { 9108 timeline.setFrame(frame, time, r, g, b, r2, g2, b2); 9109 if (frame == frameLast) break; 9110 let time2 = input.readFloat(); 9111 let nr = input.readUnsignedByte() / 255; 9112 let ng = input.readUnsignedByte() / 255; 9113 let nb = input.readUnsignedByte() / 255; 9114 let nr2 = input.readUnsignedByte() / 255; 9115 let ng2 = input.readUnsignedByte() / 255; 9116 let nb2 = input.readUnsignedByte() / 255; 9117 switch (input.readByte()) { 9118 case CURVE_STEPPED: 9119 timeline.setStepped(frame); 9120 break; 9121 case CURVE_BEZIER: 9122 setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1); 9123 setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1); 9124 setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1); 9125 setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1); 9126 setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1); 9127 setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1); 9128 } 9129 time = time2; 9130 r = nr; 9131 g = ng; 9132 b = nb; 9133 r2 = nr2; 9134 g2 = ng2; 9135 b2 = nb2; 9136 } 9137 timelines.push(timeline); 9138 break; 9139 } 9140 case SLOT_ALPHA: { 9141 let timeline = new AlphaTimeline(frameCount, input.readInt(true), slotIndex); 9142 let time = input.readFloat(), a = input.readUnsignedByte() / 255; 9143 for (let frame = 0, bezier = 0; ; frame++) { 9144 timeline.setFrame(frame, time, a); 9145 if (frame == frameLast) break; 9146 let time2 = input.readFloat(); 9147 let a2 = input.readUnsignedByte() / 255; 9148 switch (input.readByte()) { 9149 case CURVE_STEPPED: 9150 timeline.setStepped(frame); 9151 break; 9152 case CURVE_BEZIER: 9153 setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1); 9154 } 9155 time = time2; 9156 a = a2; 9157 } 9158 timelines.push(timeline); 9159 } 9160 } 9161 } 9162 } 9163 for (let i = 0, n = input.readInt(true); i < n; i++) { 9164 let boneIndex = input.readInt(true); 9165 for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { 9166 let type = input.readByte(), frameCount = input.readInt(true); 9167 if (type == BONE_INHERIT) { 9168 let timeline = new InheritTimeline(frameCount, boneIndex); 9169 for (let frame = 0; frame < frameCount; frame++) { 9170 timeline.setFrame(frame, input.readFloat(), input.readByte()); 9171 } 9172 timelines.push(timeline); 9173 continue; 9174 } 9175 let bezierCount = input.readInt(true); 9176 switch (type) { 9177 case BONE_ROTATE: 9178 timelines.push(readTimeline1(input, new RotateTimeline(frameC
9178ount, bezierCount, boneIndex), 1)); 9179 break; 9180 case BONE_TRANSLATE: 9181 timelines.push(readTimeline2(input, new TranslateTimeline(frameCount, bezierCount, boneIndex), scale)); 9182 break; 9183 case BONE_TRANSLATEX: 9184 timelines.push(readTimeline1(input, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale)); 9185 break; 9186 case BONE_TRANSLATEY: 9187 timelines.push(readTimeline1(input, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale)); 9188 break; 9189 case BONE_SCALE: 9190 timelines.push(readTimeline2(input, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1)); 9191 break; 9192 case BONE_SCALEX: 9193 timelines.push(readTimeline1(input, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1)); 9194 break; 9195 case BONE_SCALEY: 9196 timelines.push(readTimeline1(input, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1)); 9197 break; 9198 case BONE_SHEAR: 9199 timelines.push(readTimeline2(input, new ShearTimeline(frameCount, bezierCount, boneIndex), 1)); 9200 break; 9201 case BONE_SHEARX: 9202 timelines.push(readTimeline1(input, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1)); 9203 break; 9204 case BONE_SHEARY: 9205 timelines.push(readTimeline1(input, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1)); 9206 } 9207 } 9208 } 9209 for (let i = 0, n = input.readInt(true); i < n; i++) { 9210 let index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1; 9211 let timeline = new IkConstraintTimeline(frameCount, input.readInt(true), index); 9212 let flags = input.readByte(); 9213 let time = input.readFloat(), mix = (flags & 1) != 0 ? (flags & 2) != 0 ? input.readFloat() : 1 : 0; 9214 let softness = (flags & 4) != 0 ? input.readFloat() * scale : 0; 9215 for (let frame = 0, bezier = 0; ; frame++) { 9216 timeline.setFrame(frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0); 9217 if (frame == frameLast) break; 9218 flags = input.readByte(); 9219 const time2 = input.readFloat(), mix2 = (flags & 1) != 0 ? (flags & 2) != 0 ? input.readFloat() : 1 : 0; 9220 const softness2 = (flags & 4) != 0 ? input.readFloat() * scale : 0; 9221 if ((flags & 64) != 0) { 9222 timeline.setStepped(frame); 9223 } else if ((flags & 128) != 0) { 9224 setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1); 9225 setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale); 9226 } 9227 time = time2; 9228 mix = mix2; 9229 softness = softness2; 9230 } 9231 timelines.push(timeline); 9232 } 9233 for (let i = 0, n = input.readInt(true); i < n; i++) { 9234 let index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1; 9235 let timeline = new TransformConstraintTimeline(frameCount, input.readInt(true), index); 9236 let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(), mixScaleX = input.readFloat(), mixScaleY = input.readFloat(), mixShearY = input.readFloat(); 9237 for (let frame = 0, bezier = 0; ; frame++) { 9238 timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY); 9239 if (frame == frameLast) break; 9240 let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(), mixScaleX2 = input.readFloat(), mixScaleY2 = input.readFloat(), mixShearY2 = input.readFloat(); 9241 switch (input.readByte()) { 9242 case CURVE_STEPPED: 9243 timeline.setStepped(frame); 9244 break; 9245 case CURVE_BEZIER: 9246 setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); 9247 setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); 9248 setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); 9249 setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); 9250 setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); 9251 setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1); 9252 } 9253 time = time2; 9254 mixRotate = mixRotate2; 9255 mixX = mixX2; 9256 mixY = mixY2; 9257 mixScaleX = mixScaleX2; 9258 mixScaleY = mixScaleY2; 9259 mixShearY = mixShearY2; 9260 } 9261 timelines.push(timeline); 9262 } 9263 for (let i = 0, n = input.readInt(true); i < n; i++) { 9264 let index = input.readInt(true); 9265 let data = skeletonData.pathConstraints[index]; 9266 for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { 9267 const type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true); 9268 switch (type) { 9269 case PATH_POSITION: 9270 timelines.push(readTimeline1( 9271 input,
9272 new PathConstraintPositionTimeline(frameCount, bezierCount, index), 9273 data.positionMode == 0 /* Fixed */ ? scale : 1 9274 )); 9275 break; 9276 case PATH_SPACING: 9277 timelines.push(readTimeline1( 9278 input, 9279 new PathConstraintSpacingTimeline(frameCount, bezierCount, index), 9280 data.spacingMode == 0 /* Length */ || data.spacingMode == 1 /* Fixed */ ? scale : 1 9281 )); 9282 break; 9283 case PATH_MIX: 9284 let timeline = new PathConstraintMixTimeline(frameCount, bezierCount, index); 9285 let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(); 9286 for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1; ; frame++) { 9287 timeline.setFrame(frame, time, mixRotate, mixX, mixY); 9288 if (frame == frameLast) break; 9289 let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(); 9290 switch (input.readByte()) { 9291 case CURVE_STEPPED: 9292 timeline.setStepped(frame); 9293 break; 9294 case CURVE_BEZIER: 9295 setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1); 9296 setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1); 9297 setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1); 9298 } 9299 time = time2; 9300 mixRotate = mixRotate2; 9301 mixX = mixX2; 9302 mixY = mixY2; 9303 } 9304 timelines.push(timeline); 9305 } 9306 } 9307 } 9308 for (let i = 0, n = input.readInt(true); i < n; i++) { 9309 const index = input.readInt(true) - 1; 9310 for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { 9311 const type = input.readByte(), frameCount = input.readInt(true); 9312 if (type == PHYSICS_RESET) { 9313 const timeline = new PhysicsConstraintResetTimeline(frameCount, index); 9314 for (let frame = 0; frame < frameCount; frame++) 9315 timeline.setFrame(frame, input.readFloat()); 9316 timelines.push(timeline); 9317 continue; 9318 } 9319 const bezierCount = input.readInt(true); 9320 switch (type) { 9321 case PHYSICS_INERTIA: 9322 timelines.push(readTimeline1(input, new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, index), 1)); 9323 break; 9324 case PHYSICS_STRENGTH: 9325 timelines.push(readTimeline1(input, new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, index), 1)); 9326 break; 9327 case PHYSICS_DAMPING: 9328 timelines.push(readTimeline1(input, new PhysicsConstraintDampingTimeline(frameCount, bezierCount, index), 1)); 9329 break; 9330 case PHYSICS_MASS: 9331 timelines.push(readTimeline1(input, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1)); 9332 break; 9333 case PHYSICS_WIND: 9334 timelines.push(readTimeline1(input, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1)); 9335 break; 9336 case PHYSICS_GRAVITY: 9337 timelines.push(readTimeline1(input, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1)); 9338 break; 9339 case PHYSICS_MIX: 9340 timelines.push(readTimeline1(input, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1)); 9341 } 9342 } 9343 } 9344 for (let i = 0, n = input.readInt(true); i < n; i++) { 9345 let skin = skeletonData.skins[input.readInt(true)]; 9346 for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { 9347 let slotIndex = input.readInt(true); 9348 for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) { 9349 let attachmentName = input.readStringRef(); 9350 if (!attachmentName) throw new Error("attachmentName must not be null."); 9351 let attachment = skin.getAttachment(slotIndex, attachmentName); 9352 let timelineType = input.readByte(); 9353 let frameCount = input.readInt(true); 9354 let frameLast = frameCount - 1; 9355 switch (timelineType) { 9356 case ATTACHMENT_DEFORM: { 9357 let vertexAttachment = attachment; 9358 let weighted = vertexAttachment.bones; 9359 let vertices = vertexAttachment.vertices; 9360 let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length; 9361 let bezierCount = input.readInt(true);
9362 let timeline = new DeformTimeline(frameCount, bezierCount, slotIndex, vertexAttachment); 9363 let time = input.readFloat(); 9364 for (let frame = 0, bezier = 0; ; frame++) { 9365 let deform; 9366 let end = input.readInt(true); 9367 if (end == 0) 9368 deform = weighted ? Utils.newFloatArray(deformLength) : vertices; 9369 else { 9370 deform = Utils.newFloatArray(deformLength); 9371 let start = input.readInt(true); 9372 end += start; 9373 if (scale == 1) { 9374 for (let v = start; v < end; v++) 9375 deform[v] = input.readFloat(); 9376 } else { 9377 for (let v = start; v < end; v++) 9378 deform[v] = input.readFloat() * scale; 9379 } 9380 if (!weighted) { 9381 for (let v = 0, vn = deform.length; v < vn; v++) 9382 deform[v] += vertices[v]; 9383 } 9384 } 9385 timeline.setFrame(frame, time, deform); 9386 if (frame == frameLast) break; 9387 let time2 = input.readFloat(); 9388 switch (input.readByte()) { 9389 case CURVE_STEPPED: 9390 timeline.setStepped(frame); 9391 break; 9392 case CURVE_BEZIER: 9393 setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1); 9394 } 9395 time = time2; 9396 } 9397 timelines.push(timeline); 9398 break; 9399 } 9400 case ATTACHMENT_SEQUENCE: { 9401 let timeline = new SequenceTimeline(frameCount, slotIndex, attachment); 9402 for (let frame = 0; frame < frameCount; frame++) { 9403 let time = input.readFloat(); 9404 let modeAndIndex = input.readInt32(); 9405 timeline.setFrame( 9406 frame, 9407 time, 9408 SequenceModeValues[modeAndIndex & 15], 9409 modeAndIndex >> 4, 9410 input.readFloat() 9411 ); 9412 } 9413 timelines.push(timeline); 9414 break; 9415 } 9416 } 9417 } 9418 } 9419 } 9420 let drawOrderCount = input.readInt(true); 9421 if (drawOrderCount > 0) { 9422 let timeline = new DrawOrderTimeline(drawOrderCount); 9423 let slotCount = skeletonData.slots.length; 9424 for (let i = 0; i < drawOrderCount; i++) { 9425 let time = input.readFloat(); 9426 let offsetCount = input.readInt(true); 9427 let drawOrder = Utils.newArray(slotCount, 0); 9428 for (let ii = slotCount - 1; ii >= 0; ii--) 9429 drawOrder[ii] = -1; 9430 let unchanged = Utils.newArray(slotCount - offsetCount, 0); 9431 let originalIndex = 0, unchangedIndex = 0; 9432 for (let ii = 0; ii < offsetCount; ii++) { 9433 let slotIndex = input.readInt(true); 9434 while (originalIndex != slotIndex) 9435 unchanged[unchangedIndex++] = originalIndex++; 9436 drawOrder[originalIndex + input.readInt(true)] = originalIndex++; 9437 } 9438 while (originalIndex < slotCount) 9439 unchanged[unchangedIndex++] = originalIndex++; 9440 for (let ii = slotCount - 1; ii >= 0; ii--) 9441 if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex]; 9442 timeline.setFrame(i, time, drawOrder); 9443 } 9444 timelines.push(timeline); 9445 } 9446 let eventCount = input.readInt(true); 9447 if (eventCount > 0) { 9448 let timeline = new EventTimeline(eventCount); 9449 for (let i = 0; i < eventCount; i++) { 9450 let time = input.readFloat(); 9451 let eventData = skeletonData.events[input.readInt(true)]; 9452 let event = new Event(time, eventData); 9453 event.intValue = input.readInt(false); 9454 event.floatValue = input.readFloat(); 9455 event.stringValue = input.readString(); 9456 if (event.stringValue == null) event.stringValue = eventData.stringValue; 9457 if (event.data.audioPath) { 9458 event.volume = input.readFloat(); 9459 event.balance = input.readFloat(); 9460 }
9461 timeline.setFrame(i, event); 9462 } 9463 timelines.push(timeline); 9464 } 9465 let duration = 0; 9466 for (let i = 0, n = timelines.length; i < n; i++) 9467 duration = Math.max(duration, timelines[i].getDuration()); 9468 return new Animation(name, timelines, duration); 9469 } 9470 }; 9471 var BinaryInput = class { 9472 constructor(data, strings = new Array(), index = 0, buffer = new DataView(data instanceof ArrayBuffer ? data : data.buffer)) { 9473 this.strings = strings; 9474 this.index = index; 9475 this.buffer = buffer; 9476 } 9477 readByte() { 9478 return this.buffer.getInt8(this.index++); 9479 } 9480 readUnsignedByte() { 9481 return this.buffer.getUint8(this.index++); 9482 } 9483 readShort() { 9484 let value = this.buffer.getInt16(this.index); 9485 this.index += 2; 9486 return value; 9487 } 9488 readInt32() { 9489 let value = this.buffer.getInt32(this.index); 9490 this.index += 4; 9491 return value; 9492 } 9493 readInt(optimizePositive) { 9494 let b = this.readByte(); 9495 let result = b & 127; 9496 if ((b & 128) != 0) { 9497 b = this.readByte(); 9498 result |= (b & 127) << 7; 9499 if ((b & 128) != 0) { 9500 b = this.readByte(); 9501 result |= (b & 127) << 14; 9502 if ((b & 128) != 0) { 9503 b = this.readByte(); 9504 result |= (b & 127) << 21; 9505 if ((b & 128) != 0) { 9506 b = this.readByte(); 9507 result |= (b & 127) << 28; 9508 } 9509 } 9510 } 9511 } 9512 return optimizePositive ? result : result >>> 1 ^ -(result & 1); 9513 } 9514 readStringRef() { 9515 let index = this.readInt(true); 9516 return index == 0 ? null : this.strings[index - 1]; 9517 } 9518 readString() { 9519 let byteCount = this.readInt(true); 9520 switch (byteCount) { 9521 case 0: 9522 return null; 9523 case 1: 9524 return ""; 9525 } 9526 byteCount--; 9527 let chars = ""; 9528 let charCount = 0; 9529 for (let i = 0; i < byteCount; ) { 9530 let b = this.readUnsignedByte(); 9531 switch (b >> 4) { 9532 case 12: 9533 case 13: 9534 chars += String.fromCharCode((b & 31) << 6 | this.readByte() & 63); 9535 i += 2; 9536 break; 9537 case 14: 9538 chars += String.fromCharCode((b & 15) << 12 | (this.readByte() & 63) << 6 | this.readByte() & 63); 9539 i += 3; 9540 break; 9541 default: 9542 chars += String.fromCharCode(b); 9543 i++; 9544 } 9545 } 9546 return chars; 9547 } 9548 readFloat() { 9549 let value = this.buffer.getFloat32(this.index); 9550 this.index += 4; 9551 return value; 9552 } 9553 readBoolean() { 9554 return this.readByte() != 0; 9555 } 9556 }; 9557 var LinkedMesh = class { 9558 parent; 9559 skinIndex; 9560 slotIndex; 9561 mesh; 9562 inheritTimeline; 9563 constructor(mesh, skinIndex, slotIndex, parent, inheritDeform) { 9564 this.mesh = mesh; 9565 this.skinIndex = skinIndex; 9566 this.slotIndex = slotIndex; 9567 this.parent = parent; 9568 this.inheritTimeline = inheritDeform; 9569 } 9570 }; 9571 var Vertices = class { 9572 constructor(bones = null, vertices = null, length = 0) { 9573 this.bones = bones; 9574 this.vertices = vertices; 9575 this.length = length; 9576 } 9577 }; 9578 function readTimeline1(input, timeline, scale) { 9579 let time = input.readFloat(), value = input.readFloat() * scale; 9580 for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1; ; frame++) { 9581 timeline.setFrame(frame, time, value); 9582 if (frame == frameLast) break; 9583 let time2 = input.readFloat(), value2 = input.readFloat() * scale; 9584 switch (input.readByte()) { 9585 case CURVE_STEPPED: 9586 timeline.setStepped(frame); 9587 break; 9588 case CURVE_BEZIER: 9589 setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, scale); 9590 } 9591 time = time2; 9592 value = value2; 9593 } 9594 return timeline; 9595 } 9596 function readTimeline2(input, timeline, scale) { 9597 let time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale; 9598 for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1; ; frame++) {
9599 timeline.setFrame(frame, time, value1, value2); 9600 if (frame == frameLast) break; 9601 let time2 = input.readFloat(), nvalue1 = input.readFloat() * scale, nvalue2 = input.readFloat() * scale; 9602 switch (input.readByte()) { 9603 case CURVE_STEPPED: 9604 timeline.setStepped(frame); 9605 break; 9606 case CURVE_BEZIER: 9607 setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale); 9608 setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale); 9609 } 9610 time = time2; 9611 value1 = nvalue1; 9612 value2 = nvalue2; 9613 } 9614 return timeline; 9615 } 9616 function setBezier(input, timeline, bezier, frame, value, time1, time2, value1, value2, scale) { 9617 timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2); 9618 } 9619 var BONE_ROTATE = 0; 9620 var BONE_TRANSLATE = 1; 9621 var BONE_TRANSLATEX = 2; 9622 var BONE_TRANSLATEY = 3; 9623 var BONE_SCALE = 4; 9624 var BONE_SCALEX = 5; 9625 var BONE_SCALEY = 6; 9626 var BONE_SHEAR = 7; 9627 var BONE_SHEARX = 8; 9628 var BONE_SHEARY = 9; 9629 var BONE_INHERIT = 10; 9630 var SLOT_ATTACHMENT = 0; 9631 var SLOT_RGBA = 1; 9632 var SLOT_RGB = 2; 9633 var SLOT_RGBA2 = 3; 9634 var SLOT_RGB2 = 4; 9635 var SLOT_ALPHA = 5; 9636 var ATTACHMENT_DEFORM = 0; 9637 var ATTACHMENT_SEQUENCE = 1; 9638 var PATH_POSITION = 0; 9639 var PATH_SPACING = 1; 9640 var PATH_MIX = 2; 9641 var PHYSICS_INERTIA = 0; 9642 var PHYSICS_STRENGTH = 1; 9643 var PHYSICS_DAMPING = 2; 9644 var PHYSICS_MASS = 4; 9645 var PHYSICS_WIND = 5; 9646 var PHYSICS_GRAVITY = 6; 9647 var PHYSICS_MIX = 7; 9648 var PHYSICS_RESET = 8; 9649 var CURVE_STEPPED = 1; 9650 var CURVE_BEZIER = 2; 9651 9652
9652// spine-core/src/SkeletonBounds.ts 9653 var SkeletonBounds = class { 9654 /** The left edge of the axis aligned bounding box. */ 9655 minX = 0; 9656 /** The bottom edge of the axis aligned bounding box. */ 9657 minY = 0; 9658 /** The right edge of the axis aligned bounding box. */ 9659 maxX = 0; 9660 /** The top edge of the axis aligned bounding box. */ 9661 maxY = 0; 9662 /** The visible bounding boxes. */ 9663 boundingBoxes = new Array(); 9664 /** The world vertices for the bounding box polygons. */ 9665 polygons = new Array(); 9666 polygonPool = new Pool(() => { 9667 return Utils.newFloatArray(16); 9668 }); 9669 /** Clears any previous polygons, finds all visible bounding box attachments, and computes the world vertices for each bounding 9670 * box's polygon. 9671 * @param updateAabb If true, the axis aligned bounding box containing all the polygons is computed. If false, the 9672 * SkeletonBounds AABB methods will always return true. */ 9673 update(skeleton, updateAabb) { 9674 if (!skeleton) throw new Error("skeleton cannot be null."); 9675 let boundingBoxes = this.boundingBoxes; 9676 let polygons = this.polygons; 9677 let polygonPool = this.polygonPool; 9678 let slots = skeleton.slots; 9679 let slotCount = slots.length; 9680 boundingBoxes.length = 0; 9681 polygonPool.freeAll(polygons); 9682 polygons.length = 0; 9683 for (let i = 0; i < slotCount; i++) { 9684 let slot = slots[i]; 9685 if (!slot.bone.active) continue; 9686 let attachment = slot.getAttachment(); 9687 if (attachment instanceof BoundingBoxAttachment) { 9688 let boundingBox = attachment; 9689 boundingBoxes.push(boundingBox); 9690 let polygon = polygonPool.obtain(); 9691 if (polygon.length != boundingBox.worldVerticesLength) { 9692 polygon = Utils.newFloatArray(boundingBox.worldVerticesLength); 9693 } 9694 polygons.push(polygon); 9695 boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2); 9696 } 9697 } 9698 if (updateAabb) { 9699 this.aabbCompute(); 9700 } else { 9701 this.minX = Number.POSITIVE_INFINITY; 9702 this.minY = Number.POSITIVE_INFINITY; 9703 this.maxX = Number.NEGATIVE_INFINITY; 9704 this.maxY = Number.NEGATIVE_INFINITY; 9705 } 9706 } 9707 aabbCompute() { 9708 let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY; 9709 let polygons = this.polygons; 9710 for (let i = 0, n = polygons.length; i < n; i++) { 9711 let polygon = polygons[i]; 9712 let vertices = polygon; 9713 for (let ii = 0, nn = polygon.length; ii < nn; ii += 2) { 9714 let x = vertices[ii]; 9715 let y = vertices[ii + 1]; 9716 minX = Math.min(minX, x); 9717 minY = Math.min(minY, y); 9718 maxX = Math.max(maxX, x); 9719 maxY = Math.max(maxY, y); 9720 } 9721 } 9722 this.minX = minX; 9723 this.minY = minY; 9724 this.maxX = maxX; 9725 this.maxY = maxY; 9726 } 9727 /** Returns true if the axis aligned bounding box contains the point. */ 9728 aabbContainsPoint(x, y) { 9729 return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY; 9730 } 9731 /** Returns true if the axis aligned bounding box intersects the line segment. */ 9732 aabbIntersectsSegment(x1, y1, x2, y2) { 9733 let minX = this.minX; 9734 let minY = this.minY; 9735 let maxX = this.maxX; 9736 let maxY = this.maxY; 9737 if (x1 <= minX && x2 <= minX || y1 <= minY && y2 <= minY || x1 >= maxX && x2 >= maxX || y1 >= maxY && y2 >= maxY) 9738 return false; 9739 let m = (y2 - y1) / (x2 - x1); 9740 let y = m * (minX - x1) + y1; 9741 if (y > minY && y < maxY) return true; 9742 y = m * (maxX - x1) + y1; 9743 if (y > minY && y < maxY) return true; 9744 let x = (minY - y1) / m + x1; 9745 if (x > minX && x < maxX) return true; 9746 x = (maxY - y1) / m + x1; 9747 if (x > minX && x < maxX) return true; 9748 return false; 9749 } 9750 /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */ 9751 aabbIntersectsSkeleton(bounds) { 9752 return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY >
9752 bounds.minY; 9753 } 9754 /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more 9755 * efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */ 9756 containsPoint(x, y) { 9757 let polygons = this.polygons; 9758 for (let i = 0, n = polygons.length; i < n; i++) 9759 if (this.containsPointPolygon(polygons[i], x, y)) return this.boundingBoxes[i]; 9760 return null; 9761 } 9762 /** Returns true if the polygon contains the point. */ 9763 containsPointPolygon(polygon, x, y) { 9764 let vertices = polygon; 9765 let nn = polygon.length; 9766 let prevIndex = nn - 2; 9767 let inside = false; 9768 for (let ii = 0; ii < nn; ii += 2) { 9769 let vertexY = vertices[ii + 1]; 9770 let prevY = vertices[prevIndex + 1]; 9771 if (vertexY < y && prevY >= y || prevY < y && vertexY >= y) { 9772 let vertexX = vertices[ii]; 9773 if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) inside = !inside; 9774 } 9775 prevIndex = ii; 9776 } 9777 return inside; 9778 } 9779 /** Returns the first bounding box attachment that contains any part of the line segment, or null. When doing many checks, it 9780 * is usually more efficient to only call this method if {@link #aabbIntersectsSegment()} returns 9781 * true. */ 9782 intersectsSegment(x1, y1, x2, y2) { 9783 let polygons = this.polygons; 9784 for (let i = 0, n = polygons.length; i < n; i++) 9785 if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2)) return this.boundingBoxes[i]; 9786 return null; 9787 } 9788 /** Returns true if the polygon contains any part of the line segment. */ 9789 intersectsSegmentPolygon(polygon, x1, y1, x2, y2) { 9790 let vertices = polygon; 9791 let nn = polygon.length; 9792 let width12 = x1 - x2, height12 = y1 - y2; 9793 let det1 = x1 * y2 - y1 * x2; 9794 let x3 = vertices[nn - 2], y3 = vertices[nn - 1]; 9795 for (let ii = 0; ii < nn; ii += 2) { 9796 let x4 = vertices[ii], y4 = vertices[ii + 1]; 9797 let det2 = x3 * y4 - y3 * x4; 9798 let width34 = x3 - x4, height34 = y3 - y4; 9799 let det3 = width12 * height34 - height12 * width34; 9800 let x = (det1 * width34 - width12 * det2) / det3; 9801 if ((x >= x3 && x <= x4 || x >= x4 && x <= x3) && (x >= x1 && x <= x2 || x >= x2 && x <= x1)) { 9802 let y = (det1 * height34 - height12 * det2) / det3; 9803 if ((y >= y3 && y <= y4 || y >= y4 && y <= y3) && (y >= y1 && y <= y2 || y >= y2 && y <= y1)) return true; 9804 } 9805 x3 = x4; 9806 y3 = y4; 9807 } 9808 return false; 9809 } 9810 /** Returns the polygon for the specified bounding box, or null. */ 9811 getPolygon(boundingBox) { 9812 if (!boundingBox) throw new Error("boundingBox cannot be null."); 9813 let index = this.boundingBoxes.indexOf(boundingBox); 9814 return index == -1 ? null : this.polygons[index]; 9815 } 9816 /** The width of the axis aligned bounding box. */ 9817 getWidth() { 9818 return this.maxX - this.minX; 9819 } 9820 /** The height of the axis aligned bounding box. */ 9821 getHeight() { 9822 return this.maxY - this.minY; 9823 } 9824 }; 9825 9826
9826// spine-core/src/Triangulator.ts 9827 var Triangulator = class _Triangulator { 9828 convexPolygons = new Array(); 9829 convexPolygonsIndices = new Array(); 9830 indicesArray = new Array(); 9831 isConcaveArray = new Array(); 9832 triangles = new Array(); 9833 polygonPool = new Pool(() => { 9834 return new Array(); 9835 }); 9836 polygonIndicesPool = new Pool(() => { 9837 return new Array(); 9838 }); 9839 triangulate(verticesArray) { 9840 let vertices = verticesArray; 9841 let vertexCount = verticesArray.length >> 1; 9842 let indices = this.indicesArray; 9843 indices.length = 0; 9844 for (let i = 0; i < vertexCount; i++) 9845 indices[i] = i; 9846 let isConcave = this.isConcaveArray; 9847 isConcave.length = 0; 9848 for (let i = 0, n = vertexCount; i < n; ++i) 9849 isConcave[i] = _Triangulator.isConcave(i, vertexCount, vertices, indices); 9850 let triangles = this.triangles; 9851 triangles.length = 0; 9852 while (vertexCount > 3) { 9853 let previous = vertexCount - 1, i = 0, next = 1; 9854 while (true) { 9855 outer: 9856 if (!isConcave[i]) { 9857 let p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1; 9858 let p1x = vertices[p1], p1y = vertices[p1 + 1]; 9859 let p2x = vertices[p2], p2y = vertices[p2 + 1]; 9860 let p3x = vertices[p3], p3y = vertices[p3 + 1]; 9861 for (let ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { 9862 if (!isConcave[ii]) continue; 9863 let v = indices[ii] << 1; 9864 let vx = vertices[v], vy = vertices[v + 1]; 9865 if (_Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) { 9866 if (_Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) { 9867 if (_Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy)) break outer; 9868 } 9869 } 9870 } 9871 break; 9872 } 9873 if (next == 0) { 9874 do { 9875 if (!isConcave[i]) break; 9876 i--; 9877 } while (i > 0); 9878 break; 9879 } 9880 previous = i; 9881 i = next; 9882 next = (next + 1) % vertexCount; 9883 } 9884 triangles.push(indices[(vertexCount + i - 1) % vertexCount]); 9885 triangles.push(indices[i]); 9886 triangles.push(indices[(i + 1) % vertexCount]); 9887 indices.splice(i, 1); 9888 isConcave.splice(i, 1); 9889 vertexCount--; 9890 let previousIndex = (vertexCount + i - 1) % vertexCount; 9891 let nextIndex = i == vertexCount ? 0 : i; 9892 isConcave[previousIndex] = _Triangulator.isConcave(previousIndex, vertexCount, vertices, indices); 9893 isConcave[nextIndex] = _Triangulator.isConcave(nextIndex, vertexCount, vertices, indices); 9894 } 9895 if (vertexCount == 3) { 9896 triangles.push(indices[2]); 9897 triangles.push(indices[0]); 9898 triangles.push(indices[1]); 9899 } 9900 return triangles; 9901 } 9902 decompose(verticesArray, triangles) { 9903 let vertices = verticesArray; 9904 let convexPolygons = this.convexPolygons; 9905 this.polygonPool.freeAll(convexPolygons); 9906 convexPolygons.length = 0; 9907 let convexPolygonsIndices = this.convexPolygonsIndices; 9908 this.polygonIndicesPool.freeAll(convexPolygonsIndices); 9909 convexPolygonsIndices.length = 0; 9910 let polygonIndices = this.polygonIndicesPool.obtain(); 9911 polygonIndices.length = 0; 9912 let polygon = this.polygonPool.obtain(); 9913 polygon.length = 0; 9914 let fanBaseIndex = -1, lastWinding = 0; 9915 for (let i = 0, n = triangles.length; i < n; i += 3) { 9916 let t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1; 9917 let x1 = vertices[t1], y1 = vertices[t1 + 1]; 9918 let x2 = vertices[t2], y2 = vertices[t2 + 1]; 9919 let x3 = vertices[t3], y3 = vertices[t3 + 1]; 9920 let merged = false; 9921 if (fanBaseIndex == t1) { 9922 let o = polygon.length - 4; 9923 let winding1 = _Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3); 9924 let winding2 = _Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]); 9925 if (winding1 == lastWinding && winding2 == lastWinding) { 9926 polygon.push(x3); 9927 polygon.push(y3); 9928 polygonIndices.push(t3); 9929 merged = true; 9930 } 9931 } 9932 if (!merged) { 9933 if (polygon.length > 0) { 9934 convexPolygons.push(polygon); 9935 convexPolygonsIndices.push(polygonIndices); 9936 } else { 9937 this.polygonPool.free(polygon); 9938 this.polygonIndicesPool.free(polygonIndices); 9939 } 9940 polygon = this.polygonPool.obtain(); 9941 polygon.length = 0; 9942 polygon.push(x1); 9943 polygon.push(y1); 9944 polygon.push(x2); 9945 polygon.push(y2); 9946 polygon.push(x3); 9947 polygon.push(y3); 9948 polygonIndices = this.polygonIndicesPool.obtain(); 9949 polygonIndices.length = 0; 9950 polygonIndices.push(t1); 9951 polygonIndices.push(t2); 9952 polygonIndices.push(t3); 9953 lastWinding = _Triangulator.winding(x1, y1, x2, y2, x3, y3); 9954 fanBaseIndex = t1; 9955 } 9956 } 9957 if (polygon.length > 0) { 9958 convexPolygons.push(polygon); 9959 convexPolygonsIndices.push(polygonIndices); 9960 } 9961 for (let i = 0, n = convexPolygons.length; i < n; i++) { 9962 polygonIndices = convexPolygonsIndices[i]; 9963 if (polygonIndices.length == 0) continue;
9964 let firstIndex = polygonIndices[0]; 9965 let lastIndex = polygonIndices[polygonIndices.length - 1]; 9966 polygon = convexPolygons[i]; 9967 let o = polygon.length - 4; 9968 let prevPrevX = polygon[o], prevPrevY = polygon[o + 1]; 9969 let prevX = polygon[o + 2], prevY = polygon[o + 3]; 9970 let firstX = polygon[0], firstY = polygon[1]; 9971 let secondX = polygon[2], secondY = polygon[3]; 9972 let winding = _Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); 9973 for (let ii = 0; ii < n; ii++) { 9974 if (ii == i) continue; 9975 let otherIndices = convexPolygonsIndices[ii]; 9976 if (otherIndices.length != 3) continue; 9977 let otherFirstIndex = otherIndices[0]; 9978 let otherSecondIndex = otherIndices[1]; 9979 let otherLastIndex = otherIndices[2]; 9980 let otherPoly = convexPolygons[ii]; 9981 let x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1]; 9982 if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; 9983 let winding1 = _Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); 9984 let winding2 = _Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY); 9985 if (winding1 == winding && winding2 == winding) { 9986 otherPoly.length = 0; 9987 otherIndices.length = 0; 9988 polygon.push(x3); 9989 polygon.push(y3); 9990 polygonIndices.push(otherLastIndex); 9991 prevPrevX = prevX; 9992 prevPrevY = prevY; 9993 prevX = x3; 9994 prevY = y3; 9995 ii = 0; 9996 } 9997 } 9998 } 9999 for (let i = convexPolygons.length - 1; i >= 0; i--) { 10000 polygon = convexPolygons[i]; 10001 if (polygon.length == 0) { 10002 convexPolygons.splice(i, 1); 10003 this.polygonPool.free(polygon); 10004 polygonIndices = convexPolygonsIndices[i]; 10005 convexPolygonsIndices.splice(i, 1); 10006 this.polygonIndicesPool.free(polygonIndices); 10007 } 10008 } 10009 return convexPolygons; 10010 } 10011 static isConcave(index, vertexCount, vertices, indices) { 10012 let previous = indices[(vertexCount + index - 1) % vertexCount] << 1; 10013 let current = indices[index] << 1; 10014 let next = indices[(index + 1) % vertexCount] << 1; 10015 return !this.positiveArea( 10016 vertices[previous], 10017 vertices[previous + 1], 10018 vertices[current], 10019 vertices[current + 1], 10020 vertices[next], 10021 vertices[next + 1] 10022 ); 10023 } 10024 static positiveArea(p1x, p1y, p2x, p2y, p3x, p3y) { 10025 return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0; 10026 } 10027 static winding(p1x, p1y, p2x, p2y, p3x, p3y) { 10028 let px = p2x - p1x, py = p2y - p1y; 10029 return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1; 10030 } 10031 }; 10032 10033
10033// spine-core/src/SkeletonClipping.ts 10034 var SkeletonClipping = class _SkeletonClipping { 10035 triangulator = new Triangulator(); 10036 clippingPolygon = new Array(); 10037 clipOutput = new Array(); 10038 clippedVertices = new Array(); 10039 clippedUVs = new Array(); 10040 clippedTriangles = new Array(); 10041 scratch = new Array(); 10042 clipAttachment = null; 10043 clippingPolygons = null; 10044 clipStart(slot, clip) { 10045 if (this.clipAttachment) return 0; 10046 this.clipAttachment = clip; 10047 let n = clip.worldVerticesLength; 10048 let vertices = Utils.setArraySize(this.clippingPolygon, n); 10049 clip.computeWorldVertices(slot, 0, n, vertices, 0, 2); 10050 let clippingPolygon = this.clippingPolygon; 10051 _SkeletonClipping.makeClockwise(clippingPolygon); 10052 let clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon)); 10053 for (let i = 0, n2 = clippingPolygons.length; i < n2; i++) { 10054 let polygon = clippingPolygons[i]; 10055 _SkeletonClipping.makeClockwise(polygon); 10056 polygon.push(polygon[0]); 10057 polygon.push(polygon[1]); 10058 } 10059 return clippingPolygons.length; 10060 } 10061 clipEndWithSlot(slot) { 10062 if (this.clipAttachment && this.clipAttachment.endSlot == slot.data) this.clipEnd(); 10063 } 10064 clipEnd() { 10065 if (!this.clipAttachment) return; 10066 this.clipAttachment = null; 10067 this.clippingPolygons = null; 10068 this.clippedVertices.length = 0; 10069 this.clippedTriangles.length = 0; 10070 this.clippingPolygon.length = 0; 10071 } 10072 isClipping() { 10073 return this.clipAttachment != null; 10074 } 10075 clipTriangles(vertices, verticesLengthOrTriangles, trianglesOrTrianglesLength, trianglesLengthOrUvs, uvsOrLight, lightOrDark, darkOrTwoColor, twoColorParam) { 10076 let triangles; 10077 let trianglesLength; 10078 let uvs; 10079 let light; 10080 let dark; 10081 let twoColor;
10082 if (typeof verticesLengthOrTriangles === "number") { 10083 triangles = trianglesOrTrianglesLength; 10084 trianglesLength = trianglesLengthOrUvs; 10085 uvs = uvsOrLight; 10086 light = lightOrDark; 10087 dark = darkOrTwoColor; 10088 twoColor = twoColorParam; 10089 } else { 10090 triangles = verticesLengthOrTriangles; 10091 trianglesLength = trianglesOrTrianglesLength; 10092 uvs = trianglesLengthOrUvs; 10093 light = uvsOrLight; 10094 dark = lightOrDark; 10095 twoColor = darkOrTwoColor; 10096 } 10097 if (uvs && light && dark && typeof twoColor === "boolean") 10098 this.clipTrianglesRender(vertices, triangles, trianglesLength, uvs, light, dark, twoColor); 10099 else 10100 this.clipTrianglesNoRender(vertices, triangles, trianglesLength); 10101 } 10102 clipTrianglesNoRender(vertices, triangles, trianglesLength) { 10103 let clipOutput = this.clipOutput, clippedVertices = this.clippedVertices; 10104 let clippedTriangles = this.clippedTriangles; 10105 let polygons = this.clippingPolygons; 10106 let polygonsCount = polygons.length; 10107 let index = 0; 10108 clippedVertices.length = 0; 10109 clippedTriangles.length = 0; 10110 for (let i = 0; i < trianglesLength; i += 3) { 10111 let vertexOffset = triangles[i] << 1; 10112 let x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; 10113 vertexOffset = triangles[i + 1] << 1; 10114 let x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1]; 10115 vertexOffset = triangles[i + 2] << 1; 10116 let x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; 10117 for (let p = 0; p < polygonsCount; p++) { 10118 let s = clippedVertices.length; 10119 if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) { 10120 let clipOutputLength = clipOutput.length; 10121 if (clipOutputLength == 0) continue; 10122 let clipOutputCount = clipOutputLength >> 1; 10123 let clipOutputItems = this.clipOutput; 10124 let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + clipOutputCount * 2); 10125 for (let ii = 0; ii < clipOutputLength; ii += 2, s += 2) { 10126 let x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; 10127 clippedVerticesItems[s] = x; 10128 clippedVerticesItems[s + 1] = y; 10129 } 10130 s = clippedTriangles.length; 10131 let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2)); 10132 clipOutputCount--; 10133 for (let ii = 1; ii < clipOutputCount; ii++, s += 3) { 10134 clippedTrianglesItems[s] = index; 10135 clippedTrianglesItems[s + 1] = index + ii; 10136 clippedTrianglesItems[s + 2] = index + ii + 1; 10137 } 10138 index += clipOutputCount + 1; 10139 } else { 10140 let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + 3 * 2); 10141 clippedVerticesItems[s] = x1; 10142 clippedVerticesItems[s + 1] = y1; 10143 clippedVerticesItems[s + 2] = x2; 10144 clippedVerticesItems[s + 3] = y2; 10145 clippedVerticesItems[s + 4] = x3; 10146 clippedVerticesItems[s + 5] = y3; 10147 s = clippedTriangles.length; 10148 let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3); 10149 clippedTrianglesItems[s] = index; 10150 clippedTrianglesItems[s + 1] = index + 1; 10151 clippedTrianglesItems[s + 2] = index + 2; 10152 index += 3; 10153 break; 10154 } 10155 } 10156 } 10157 } 10158 clipTrianglesRender(vertices, triangles, trianglesLength, uvs, light, dark, twoColor) { 10159 let clipOutput = this.clipOutput, clippedVertices = this.clippedVertices; 10160 let clippedTriangles = this.clippedTriangles; 10161 let polygons = this.clippingPolygons; 10162 let polygonsCount = polygons.length; 10163 let vertexSize = twoColor ? 12 : 8; 10164 let index = 0; 10165 clippedVertices.length = 0; 10166 clippedTriangles.length = 0; 10167 for (let i = 0; i < trianglesLength; i += 3) { 10168 let vertexOffset = triangles[i] << 1; 10169 let x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; 10170 let u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1]; 10171 vertexOffset = triangles[i + 1] << 1; 10172 let x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1]; 10173 let u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1]; 10174 vertexOffset = triangles[i + 2] << 1; 10175 let x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; 10176 let u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1]; 10177 for (let p = 0; p < polygonsCount; p++) { 10178 let s = clippedVertices.length; 10179 if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) { 10180 let clipOutputLength = clipOutput.length; 10181 if (clipOutputLength == 0) continue; 10182 let d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1; 10183 let d = 1 / (d0 * d2 + d1 * (y1 - y3)); 10184 let clipOutputCount = clipOutputLength >> 1; 10185 let clipOutputItems = this.clipOutput; 10186 let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize); 10187 for (let ii = 0; ii < clipOutputLength; ii += 2, s += vertexSize) { 10188 let x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; 10189 clippedVerticesItems[s] = x; 10190 clippedVerticesItems[s + 1] = y; 10191 clippedVerticesItems[s + 2] = light.r; 10192 clippedVerticesItems[s + 3] = light.g; 10193 clippedVerticesItems[s + 4] = light.b; 10194 clippedVerticesItems[s + 5] = light.a; 10195 let c0 = x - x3, c1 = y - y3; 10196 let a = (d0 * c0 + d1 * c1) * d; 10197 let b = (d4 * c0 + d2 * c1) * d; 10198 let c = 1 - a - b; 10199 clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
10200 clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c; 10201 if (twoColor) { 10202 clippedVerticesItems[s + 8] = dark.r; 10203 clippedVerticesItems[s + 9] = dark.g; 10204 clippedVerticesItems[s + 10] = dark.b; 10205 clippedVerticesItems[s + 11] = dark.a; 10206 } 10207 } 10208 s = clippedTriangles.length; 10209 let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2)); 10210 clipOutputCount--; 10211 for (let ii = 1; ii < clipOutputCount; ii++, s += 3) { 10212 clippedTrianglesItems[s] = index; 10213 clippedTrianglesItems[s + 1] = index + ii; 10214 clippedTrianglesItems[s + 2] = index + ii + 1; 10215 } 10216 index += clipOutputCount + 1; 10217 } else { 10218 let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + 3 * vertexSize); 10219 clippedVerticesItems[s] = x1; 10220 clippedVerticesItems[s + 1] = y1; 10221 clippedVerticesItems[s + 2] = light.r; 10222 clippedVerticesItems[s + 3] = light.g; 10223 clippedVerticesItems[s + 4] = light.b; 10224 clippedVerticesItems[s + 5] = light.a; 10225 if (!twoColor) { 10226 clippedVerticesItems[s + 6] = u1; 10227 clippedVerticesItems[s + 7] = v1; 10228 clippedVerticesItems[s + 8] = x2; 10229 clippedVerticesItems[s + 9] = y2; 10230 clippedVerticesItems[s + 10] = light.r; 10231 clippedVerticesItems[s + 11] = light.g; 10232 clippedVerticesItems[s + 12] = light.b; 10233 clippedVerticesItems[s + 13] = light.a; 10234 clippedVerticesItems[s + 14] = u2; 10235 clippedVerticesItems[s + 15] = v2; 10236 clippedVerticesItems[s + 16] = x3; 10237 clippedVerticesItems[s + 17] = y3; 10238 clippedVerticesItems[s + 18] = light.r; 10239 clippedVerticesItems[s + 19] = light.g; 10240 clippedVerticesItems[s + 20] = light.b; 10241 clippedVerticesItems[s + 21] = light.a; 10242 clippedVerticesItems[s + 22] = u3; 10243 clippedVerticesItems[s + 23] = v3; 10244 } else { 10245 clippedVerticesItems[s + 6] = u1; 10246 clippedVerticesItems[s + 7] = v1; 10247 clippedVerticesItems[s + 8] = dark.r; 10248 clippedVerticesItems[s + 9] = dark.g; 10249 clippedVerticesItems[s + 10] = dark.b; 10250 clippedVerticesItems[s + 11] = dark.a; 10251 clippedVerticesItems[s + 12] = x2; 10252 clippedVerticesItems[s + 13] = y2; 10253 clippedVerticesItems[s + 14] = light.r; 10254 clippedVerticesItems[s + 15] = light.g; 10255 clippedVerticesItems[s + 16] = light.b; 10256 clippedVerticesItems[s + 17] = light.a; 10257 clippedVerticesItems[s + 18] = u2; 10258 clippedVerticesItems[s + 19] = v2; 10259 clippedVerticesItems[s + 20] = dark.r; 10260 clippedVerticesItems[s + 21] = dark.g; 10261 clippedVerticesItems[s + 22] = dark.b; 10262 clippedVerticesItems[s + 23] = dark.a; 10263 clippedVerticesItems[s + 24] = x3; 10264 clippedVerticesItems[s + 25] = y3; 10265 clippedVerticesItems[s + 26] = light.r; 10266 clippedVerticesItems[s + 27] = light.g; 10267 clippedVerticesItems[s + 28] = light.b; 10268 clippedVerticesItems[s + 29] = light.a; 10269 clippedVerticesItems[s + 30] = u3; 10270 clippedVerticesItems[s + 31] = v3; 10271 clippedVerticesItems[s + 32] = dark.r; 10272 clippedVerticesItems[s + 33] = dark.g; 10273 clippedVerticesItems[s + 34] = dark.b; 10274 clippedVerticesItems[s + 35] = dark.a; 10275 } 10276 s = clippedTriangles.length; 10277 let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3); 10278 clippedTrianglesItems[s] = index; 10279 clippedTrianglesItems[s + 1] = index + 1; 10280 clippedTrianglesItems[s + 2] = index + 2; 10281 index += 3; 10282 break; 10283 } 10284 } 10285 } 10286 } 10287 clipTrianglesUnpacked(vertices, triangles, trianglesLength, uvs) { 10288 let clipOutput = this.clipOutput, clippedVertices = this.clippedVertices, clippedUVs = this.clippedUVs; 10289 let clippedTriangles = this.clippedTriangles; 10290 let polygons = this.clippingPolygons; 10291 let polygonsCount = polygons.length; 10292 let index = 0; 10293 clippedVertices.length = 0; 10294 clippedUVs.length = 0; 10295 clippedTriangles.length = 0; 10296 for (let i = 0; i < trianglesLength; i += 3) { 10297 let vertexOffset = triangles[i] << 1; 10298 let x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; 10299 let u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1]; 10300 vertexOffset = triangles[i + 1] << 1; 10301 let x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1]; 10302 let u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1]; 10303 vertexOffset = triangles[i + 2] << 1; 10304 let x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; 10305 let u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1]; 10306 for (let p = 0; p < polygonsCount; p++) { 10307 let s = clippedVertices.length; 10308 if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) { 10309 let clipOutputLength = clipOutput.length; 10310 if (clipOutputLength == 0) continue; 10311 let d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1; 10312 let d = 1 / (d0 * d2 + d1 * (y1 - y3)); 10313 let clipOutputCount = clipOutputLength >> 1; 10314 let clipOutputItems = this.clipOutput; 10315 let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + clipOutputCount * 2); 10316 let clippedUVsItems = Utils.setArraySize(clippedUVs, s + clipOutputCount * 2); 10317 for (let ii = 0; ii < clipOutputLength; ii += 2, s += 2) { 10318 let x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; 10319 clippedVerticesItems[s] = x; 10320 clippedVerticesItems[s + 1] = y; 10321 let c0 = x - x3, c1 = y - y3; 10322 let a = (d0 * c0 + d1 * c1) * d; 10323 let b = (d4 * c0 + d2 * c1) * d; 10324 let c = 1 - a - b; 10325 clippedUVsItems[s] = u1 * a + u2 * b + u3 * c; 10326 clippedUVsItems[s + 1] = v1 * a + v2 * b + v3 * c; 10327 } 10328 s = clippedTriangles.length; 10329 let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2)); 10330 clipOutputCount--; 10331 for (let ii = 1; ii < clipOutputCount; ii++, s += 3) { 10332 clippedTrianglesItems[s] = index; 10333 clippedTrianglesItems[s + 1] = index + ii; 10334 clippedTrianglesItems[s + 2] = index + ii + 1; 10335 } 10336 index += clipOutputCount + 1; 10337 } else { 10338 let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + 3 * 2); 10339 clippedVerticesItems[s] = x1; 10340 clippedVerticesItems[s + 1] = y1; 10341 clippedVerticesItems[s + 2] = x2; 10342 clippedVerticesItems[s + 3] = y2; 10343 clippedVerticesItems[s + 4] = x3; 10344 clippedVerticesItems[s + 5] = y3; 10345 let clippedUVSItems = Utils.setArraySize(clippedUVs, s + 3 * 2); 10346 clippedUVSItems[s] = u1; 10347 clippedUVSItems[s + 1] = v1; 10348 clippedUVSItems[s + 2] = u2; 10349 clippedUVSItems[s + 3] = v2; 10350 clippedUVSItems[s + 4] = u3; 10351 clippedUVSItems[s + 5] = v3; 10352 s = clippedTriangles.length; 10353 let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3); 10354 clippedTrianglesItems[s] = index; 10355 clippedTrianglesItems[s + 1] = index + 1; 10356 clippedTrianglesItems[s + 2] = index + 2; 10357 index += 3; 10358 break; 10359 } 10360 } 10361 } 10362 } 10363 /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping 10364 * area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */ 10365 clip(x1, y1, x2, y2, x3, y3, clippingArea, output) { 10366 let originalOutput = output; 10367 let clipped = false;
10368 let input; 10369 if (clippingArea.length % 4 >= 2) { 10370 input = output; 10371 output = this.scratch; 10372 } else 10373 input = this.scratch; 10374 input.length = 0; 10375 input.push(x1); 10376 input.push(y1); 10377 input.push(x2); 10378 input.push(y2); 10379 input.push(x3); 10380 input.push(y3); 10381 input.push(x1); 10382 input.push(y1); 10383 output.length = 0; 10384 let clippingVerticesLast = clippingArea.length - 4; 10385 let clippingVertices = clippingArea; 10386 for (let i = 0; ; i += 2) { 10387 let edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1]; 10388 let ex = edgeX - clippingVertices[i + 2], ey = edgeY - clippingVertices[i + 3]; 10389 let outputStart = output.length; 10390 let inputVertices = input; 10391 for (let ii = 0, nn = input.length - 2; ii < nn; ) { 10392 let inputX = inputVertices[ii], inputY = inputVertices[ii + 1]; 10393 ii += 2; 10394 let inputX2 = inputVertices[ii], inputY2 = inputVertices[ii + 1]; 10395 let s2 = ey * (edgeX - inputX2) > ex * (edgeY - inputY2); 10396 let s1 = ey * (edgeX - inputX) - ex * (edgeY - inputY); 10397 if (s1 > 0) { 10398 if (s2) { 10399 output.push(inputX2); 10400 output.push(inputY2); 10401 continue; 10402 } 10403 let ix = inputX2 - inputX, iy = inputY2 - inputY, t = s1 / (ix * ey - iy * ex); 10404 if (t >= 0 && t <= 1) { 10405 output.push(inputX + ix * t); 10406 output.push(inputY + iy * t); 10407 } else { 10408 output.push(inputX2); 10409 output.push(inputY2); 10410 continue; 10411 } 10412 } else if (s2) { 10413 let ix = inputX2 - inputX, iy = inputY2 - inputY, t = s1 / (ix * ey - iy * ex); 10414 if (t >= 0 && t <= 1) { 10415 output.push(inputX + ix * t); 10416 output.push(inputY + iy * t); 10417 output.push(inputX2); 10418 output.push(inputY2); 10419 } else { 10420 output.push(inputX2); 10421 output.push(inputY2); 10422 continue; 10423 } 10424 } 10425 clipped = true; 10426 } 10427 if (outputStart == output.length) { 10428 originalOutput.length = 0; 10429 return true; 10430 } 10431 output.push(output[0]); 10432 output.push(output[1]); 10433 if (i == clippingVerticesLast) break; 10434 let temp = output; 10435 output = input; 10436 output.length = 0; 10437 input = temp; 10438 } 10439 if (originalOutput != output) { 10440 originalOutput.length = 0; 10441 for (let i = 0, n = output.length - 2; i < n; i++) 10442 originalOutput[i] = output[i]; 10443 } else 10444 originalOutput.length = originalOutput.length - 2; 10445 return clipped; 10446 } 10447 static makeClockwise(polygon) { 10448 let vertices = polygon; 10449 let verticeslength = polygon.length; 10450 let area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0; 10451 for (let i = 0, n = verticeslength - 3; i < n; i += 2) { 10452 p1x = vertices[i]; 10453 p1y = vertices[i + 1]; 10454 p2x = vertices[i + 2]; 10455 p2y = vertices[i + 3]; 10456 area += p1x * p2y - p2x * p1y; 10457 } 10458 if (area < 0) return; 10459 for (let i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) { 10460 let x = vertices[i], y = vertices[i + 1]; 10461 let other = lastX - i; 10462 vertices[i] = vertices[other]; 10463 vertices[i + 1] = vertices[other + 1]; 10464 vertices[other] = x; 10465 vertices[other + 1] = y; 10466 } 10467 } 10468 }; 10469 10470
10470// spine-core/src/SkeletonJson.ts 10471 var SkeletonJson = class { 10472 attachmentLoader; 10473 /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at 10474 * runtime than were used in Spine. 10475 * 10476 * See [Scaling](http://esotericsoftware.com/spine-loading-skeleton-data#Scaling) in the Spine Runtimes Guide. */ 10477 scale = 1; 10478 linkedMeshes = new Array(); 10479 constructor(attachmentLoader) { 10480 this.attachmentLoader = attachmentLoader; 10481 } 10482 readSkeletonData(json) { 10483 let scale = this.scale; 10484 let skeletonData = new SkeletonData(); 10485 let root = typeof json === "string" ? JSON.parse(json) : json; 10486 let skeletonMap = root.skeleton; 10487 if (skeletonMap) { 10488 skeletonData.hash = skeletonMap.hash; 10489 skeletonData.version = skeletonMap.spine; 10490 skeletonData.x = skeletonMap.x; 10491 skeletonData.y = skeletonMap.y; 10492 skeletonData.width = skeletonMap.width; 10493 skeletonData.height = skeletonMap.height; 10494 skeletonData.referenceScale = getValue(skeletonMap, "referenceScale", 100) * scale; 10495 skeletonData.fps = skeletonMap.fps; 10496 skeletonData.imagesPath = skeletonMap.images ?? null; 10497 skeletonData.audioPath = skeletonMap.audio ?? null; 10498 } 10499 if (root.bones) { 10500 for (let i = 0; i < root.bones.length; i++) { 10501 let boneMap = root.bones[i]; 10502 let parent = null; 10503 let parentName = getValue(boneMap, "parent", null); 10504 if (parentName) parent = skeletonData.findBone(parentName); 10505 let data = new BoneData(skeletonData.bones.length, boneMap.name, parent); 10506 data.length = getValue(boneMap, "length", 0) * scale; 10507 data.x = getValue(boneMap, "x", 0) * scale; 10508 data.y = getValue(boneMap, "y", 0) * scale; 10509 data.rotation = getValue(boneMap, "rotation", 0); 10510 data.scaleX = getValue(boneMap, "scaleX", 1); 10511 data.scaleY = getValue(boneMap, "scaleY", 1); 10512 data.shearX = getValue(boneMap, "shearX", 0); 10513 data.shearY = getValue(boneMap, "shearY", 0); 10514 data.inherit = Utils.enumValue(Inherit, getValue(boneMap, "inherit", "Normal")); 10515 data.skinRequired = getValue(boneMap, "skin", false); 10516 let color = getValue(boneMap, "color", null); 10517 if (color) data.color.setFromString(color); 10518 skeletonData.bones.push(data); 10519 } 10520 } 10521 if (root.slots) { 10522 for (let i = 0; i < root.slots.length; i++) { 10523 let slotMap = root.slots[i]; 10524 let slotName = slotMap.name; 10525 let boneData = skeletonData.findBone(slotMap.bone); 10526 if (!boneData) throw new Error(`Couldn't find bone ${slotMap.bone} for slot ${slotName}`); 10527 let data = new SlotData(skeletonData.slots.length, slotName, boneData); 10528 let color = getValue(slotMap, "color", null); 10529 if (color) data.color.setFromString(color); 10530 let dark = getValue(slotMap, "dark", null); 10531 if (dark) data.darkColor = Color.fromString(dark); 10532 data.attachmentName = getValue(slotMap, "attachment", null); 10533 data.blendMode = Utils.enumValue(BlendMode, getValue(slotMap, "blend", "normal")); 10534 data.visible = getValue(slotMap, "visible", true); 10535 skeletonData.slots.push(data); 10536 } 10537 } 10538 if (root.ik) { 10539 for (let i = 0; i < root.ik.length; i++) { 10540 let constraintMap = root.ik[i]; 10541 let data = new IkConstraintData(constraintMap.name); 10542 data.order = getValue(constraintMap, "order", 0); 10543 data.skinRequired = getValue(constraintMap, "skin", false); 10544 for (let ii = 0; ii < constraintMap.bones.length; ii++) { 10545 let bone = skeletonData.findBone(constraintMap.bones[ii]); 10546 if (!bone) throw new Error(`Couldn't find bone ${constraintMap.bones[ii]} for IK constraint ${constraintMap.name}.`); 10547 data.bones.push(bone); 10548 } 10549 let target = skeletonData.findBone(constraintMap.target); 10550 ; 10551 if (!target) throw new Error(`Couldn't find target bone ${constraintMap.target} for IK constraint ${constraintMap.name}.`); 10552 data.target = target; 10553 data.mix = getValue(constraintMap, "mix", 1); 10554 data.softness = getValue(constraintMap, "softness", 0) * scale; 10555 data.bendDirection = getValue(constraintMap, "bendPositive", true) ? 1 : -1; 10556 data.compress = getValue(constraintMap, "compress", false); 10557 data.stretch = getValue(constraintMap, "stretch", false); 10558 data.uniform = getValue(constraintMap, "uniform", false); 10559 skeletonData.ikConstraints.push(data); 10560 } 10561 } 10562 if (root.transform) { 10563 for (let i = 0; i < root.transform.length; i++) { 10564 let constraintMap = root.transform[i]; 10565 let data = new TransformConstraintData(constraintMap.name); 10566 data.order = getValue(constraintMap, "order", 0); 10567 data.skinRequired = getValue(constraintMap, "skin", false); 10568 for (let ii = 0; ii < constraintMap.bones.length; ii++) { 10569 let boneName = constraintMap.bones[ii]; 10570 let bone = skeletonData.findBone(boneName); 10571 if (!bone) throw new Error(`Couldn't find bone ${boneName} for transform constraint ${constraintMap.name}.`); 10572 data.bones.push(bone); 10573 } 10574 let targetName = constraintMap.target; 10575 let target = skeletonData.findBone(targetName); 10576 if (!target) throw new Error(`Couldn't find target bone ${targetName} for transform constraint ${constraintMap.name}.`); 10577 data.target = target; 10578 data.local = getValue(constraintMap, "local", false); 10579 data.relative = getValue(constraintMap, "relative", false); 10580 data.offsetRotation = getValue(constraintMap, "rotation", 0); 10581 data.offsetX = getValue(constraintMap, "x", 0) * scale; 10582 data.offsetY = getValue(constraintMap, "y", 0) * scale; 10583 data.offsetScaleX = getValue(constraintMap, "scaleX", 0); 10584 data.offsetScaleY = getValue(constraintMap, "scaleY",
105840); 10585 data.offsetShearY = getValue(constraintMap, "shearY", 0); 10586 data.mixRotate = getValue(constraintMap, "mixRotate", 1); 10587 data.mixX = getValue(constraintMap, "mixX", 1); 10588 data.mixY = getValue(constraintMap, "mixY", data.mixX); 10589 data.mixScaleX = getValue(constraintMap, "mixScaleX", 1); 10590 data.mixScaleY = getValue(constraintMap, "mixScaleY", data.mixScaleX); 10591 data.mixShearY = getValue(constraintMap, "mixShearY", 1); 10592 skeletonData.transformConstraints.push(data); 10593 } 10594 } 10595 if (root.path) { 10596 for (let i = 0; i < root.path.length; i++) { 10597 let constraintMap = root.path[i]; 10598 let data = new PathConstraintData(constraintMap.name); 10599 data.order = getValue(constraintMap, "order", 0); 10600 data.skinRequired = getValue(constraintMap, "skin", false); 10601 for (let ii = 0; ii < constraintMap.bones.length; ii++) { 10602 let boneName = constraintMap.bones[ii]; 10603 let bone = skeletonData.findBone(boneName); 10604 if (!bone) throw new Error(`Couldn't find bone ${boneName} for path constraint ${constraintMap.name}.`); 10605 data.bones.push(bone); 10606 } 10607 let targetName = constraintMap.target; 10608 let target = skeletonData.findSlot(targetName); 10609 if (!target) throw new Error(`Couldn't find target slot ${targetName} for path constraint ${constraintMap.name}.`); 10610 data.target = target; 10611 data.positionMode = Utils.enumValue(PositionMode, getValue(constraintMap, "positionMode", "Percent")); 10612 data.spacingMode = Utils.enumValue(SpacingMode, getValue(constraintMap, "spacingMode", "Length")); 10613 data.rotateMode = Utils.enumValue(RotateMode, getValue(constraintMap, "rotateMode", "Tangent")); 10614 data.offsetRotation = getValue(constraintMap, "rotation", 0); 10615 data.position = getValue(constraintMap, "position", 0); 10616 if (data.positionMode == 0 /* Fixed */) data.position *= scale; 10617 data.spacing = getValue(constraintMap, "spacing", 0); 10618 if (data.spacingMode == 0 /* Length */ || data.spacingMode == 1 /* Fixed */) data.spacing *= scale; 10619 data.mixRotate = getValue(constraintMap, "mixRotate", 1); 10620 data.mixX = getValue(constraintMap, "mixX", 1); 10621 data.mixY = getValue(constraintMap, "mixY", data.mixX); 10622 skeletonData.pathConstraints.push(data); 10623 } 10624 } 10625 if (root.physics) { 10626 for (let i = 0; i < root.physics.length; i++) { 10627 const constraintMap = root.physics[i]; 10628 const data = new PhysicsConstraintData(constraintMap.name); 10629 data.order = getValue(constraintMap, "order", 0); 10630 data.skinRequired = getValue(constraintMap, "skin", false); 10631 const boneName = constraintMap.bone; 10632 const bone = skeletonData.findBone(boneName); 10633 if (bone == null) throw new Error("Physics bone not found: " + boneName); 10634 data.bone = bone; 10635 data.x = getValue(constraintMap, "x", 0); 10636 data.y = getValue(constraintMap, "y", 0); 10637 data.rotate = getValue(constraintMap, "rotate", 0); 10638 data.scaleX = getValue(constraintMap, "scaleX", 0); 10639 data.shearX = getValue(constraintMap, "shearX", 0); 10640 data.limit = getValue(constraintMap, "limit", 5e3) * scale; 10641 data.step = 1 / getValue(constraintMap, "fps", 60); 10642 data.inertia = getValue(constraintMap, "inertia", 1); 10643 data.strength = getValue(constraintMap, "strength", 100); 10644 data.damping = getValue(constraintMap, "damping", 1); 10645 data.massInverse = 1 / getValue(constraintMap, "mass", 1); 10646 data.wind = getValue(constraintMap, "wind", 0); 10647 data.gravity = getValue(constraintMap, "gravity", 0); 10648 data.mix = getValue(constraintMap, "mix", 1); 10649 data.inertiaGlobal = getValue(constraintMap, "inertiaGlobal", false); 10650 data.strengthGlobal = getValue(constraintMap, "strengthGlobal", false); 10651 data.dampingGlobal = getValue(constraintMap, "dampingGlobal", false); 10652 data.massGlobal = getValue(constraintMap, "massGlobal", false); 10653 data.windGlobal = getValue(constraintMap, "windGlobal", false); 10654 data.gravityGlobal = getValue(constraintMap, "gravityGlobal", false); 10655 data.mixGlobal = getValue(constraintMap, "mixGlobal", false); 10656 skeletonData.physicsConstraints.push(data); 10657 } 10658 } 10659 if (root.skins) { 10660 for (let i = 0; i < root.skins.length; i++) { 10661 let skinMap = root.skins[i]; 10662 let skin = new Skin(skinMap.name); 10663 if (skinMap.bones) { 10664 for (let ii = 0; ii < skinMap.bones.length; ii++) { 10665 let boneName = skinMap.bones[ii]; 10666 let bone = skeletonData.findBone(boneName); 10667 if (!bone) throw new Error(`Couldn't find bone ${boneName} for skin ${skinMap.name}.`); 10668 skin.bones.push(bone); 10669 } 10670 } 10671 if (skinMap.ik) { 10672 for (let ii = 0; ii < skinMap.ik.length; ii++) { 10673 let constraintName = skinMap.ik[ii]; 10674 let constraint = skeletonData.findIkConstraint(constraintName); 10675 if (!constraint) throw new Error(`Couldn't find IK constraint ${constraintName} for skin ${skinMap.name}.`); 10676 skin.constraints.push(constraint); 10677 } 10678 } 10679 if (skinMap.transform) { 10680 for (let ii = 0; ii < skinMap.transform.length; ii++) { 10681 let constraintName = skinMap.transform[ii]; 10682 let constraint = skeletonData.findTransformConstraint(constraintName); 10683 if (!constraint) throw new Error(`Couldn't find transform constraint ${constraintName} for skin ${skinMap.name}.`); 10684 skin.constraints.push(constraint); 10685 } 10686 } 10687 if (skinMap.path) { 10688 for (let ii = 0; ii < skinMap.path.length; ii++) { 10689 let constraintName = skinMap.path[ii]; 10690 let constraint = skeletonData.findPathConstraint(constraintName); 10691 if (!constraint) throw new Error(`Couldn't find path constraint ${constraintName} for skin ${skinMap.name}.`); 10692 skin.constraints.push(constraint); 10693 } 10694 } 10695 if (skinMap.physics) { 10696 for (let ii = 0; ii < skinMap.physics.length; ii++) { 10697 let constraintName = skinMap.physics[ii]; 10698 let constraint = skeletonData.findPhysicsConstraint(constraintName); 10699 if (!constraint) throw new Error(`Couldn't find physics constraint ${constraintName} for skin ${skinMap.name}.`); 10700 skin.constraints.push(constraint); 10701 } 10702 } 10703 for (let slotName in skinMap.attachments) { 10704 let slot = skeletonData.findSlot(slotName); 10705 if (!slot) throw new Error(`Couldn't find slot ${slotName} for skin ${skinMap.name}.`); 10706 let slotMap = skinMap.attachments[slotName]; 10707 for (let entryName in slotMap) { 10708 let attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData); 10709 if (attachment) skin.setAttachment(slot.index, entryName, attachment); 10710 } 10711 } 10712 skeletonData.skins.push(skin); 10713 if (skin.name == "default") skeletonData.defaultSkin = skin; 10714 } 10715 } 10716 for (let i = 0, n = this.linkedMeshes.length; i < n; i++) { 10717 let linkedMesh = this.linkedMeshes[i]; 10718 let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin); 10719 if (!skin) throw new Error(`Skin not found: ${linkedMesh.skin}`); 10720 let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); 10721 if (!parent) throw new Error(`Parent mesh not found: ${linkedMesh.parent}`); 10722 linkedMesh.mesh.timelineAttachment = linkedMesh.inheritTimeline ? parent : linkedMesh.mesh; 10723 linkedMesh.mesh.setParentMesh(parent); 10724 if (linkedMesh.mesh.region != null) linkedMesh.mesh.updateRegion(); 10725 } 10726 this.linkedMeshes.length = 0; 10727 if (root.events) { 10728 for (let eventName in root.events) { 10729 let eventMap = root.events[eventName]; 10730 let data = new EventData(eventName); 10731 data.intValue = getValue(eventMap, "int", 0); 10732 data.floatValue = getValue(eventMap, "float", 0); 10733 data.stringValue = getValue(eventMap, "string", ""); 10734 data.audioPath = getValue(eventMap, "audio", null); 10735 if (data.audioPath) { 10736 data.volume = getValue(eventMap, "volume", 1); 10737 data.balance = getValue(eventMap, "balance", 0); 10738 } 10739 skeletonData.events.push(data); 10740 } 10741 } 10742 if (root.animations) { 10743 for (let animationName in root.animations) { 10744 let animationMap = root.animations[animationName]; 10745 this.readAnimation(animationMap, animationName, skeletonData); 10746 } 10747 } 10748 return skeletonData; 10749 } 10750 readAttachment(map, skin, slotIndex, name, skeletonData) { 10751 let scale = this.scale; 10752 name = getValue(map, "name", name); 10753 switch (getValue(map, "type", "region")) { 10754 case "region": { 10755 let path = getValue(map, "path", name); 10756 let sequence = this.readSequence(getValue(map, "sequence", null)); 10757 let region = this.attachmentLoader.newRegionAttachment(skin, name, path, sequence); 10758 if (!region) return null; 10759 region.path = path; 10760 region.x = getValue(map, "x", 0) * scale; 10761 region.y = getValue(map, "y", 0) * scale; 10762 region.scaleX = getValue(map, "scaleX", 1); 10763 region.scaleY = getValue(map, "scaleY", 1); 10764 region.rotation = getValue(map, "rotation", 0); 10765 region.width = map.width * scale; 10766 region.height = map.height * scale; 10767 region.sequence = sequence; 10768 let color = getValue(map, "color", null); 10769 if (color) region.color.setFromString(color);
10770 if (region.region != null) region.updateRegion(); 10771 return region; 10772 } 10773 case "boundingbox": { 10774 let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name); 10775 if (!box) return null; 10776 this.readVertices(map, box, map.vertexCount << 1); 10777 let color = getValue(map, "color", null); 10778 if (color) box.color.setFromString(color); 10779 return box; 10780 } 10781 case "mesh": 10782 case "linkedmesh": { 10783 let path = getValue(map, "path", name); 10784 let sequence = this.readSequence(getValue(map, "sequence", null)); 10785 let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence); 10786 if (!mesh) return null; 10787 mesh.path = path; 10788 let color = getValue(map, "color", null); 10789 if (color) mesh.color.setFromString(color); 10790 mesh.width = getValue(map, "width", 0) * scale; 10791 mesh.height = getValue(map, "height", 0) * scale; 10792 mesh.sequence = sequence; 10793 let parent = getValue(map, "parent", null); 10794 if (parent) { 10795 this.linkedMeshes.push(new LinkedMesh2(mesh, getValue(map, "skin", null), slotIndex, parent, getValue(map, "timelines", true))); 10796 return mesh; 10797 } 10798 let uvs = map.uvs; 10799 this.readVertices(map, mesh, uvs.length); 10800 mesh.triangles = map.triangles; 10801 mesh.regionUVs = uvs; 10802 if (mesh.region != null) mesh.updateRegion(); 10803 mesh.edges = getValue(map, "edges", null); 10804 mesh.hullLength = getValue(map, "hull", 0) * 2; 10805 return mesh; 10806 } 10807 case "path": { 10808 let path = this.attachmentLoader.newPathAttachment(skin, name); 10809 if (!path) return null; 10810 path.closed = getValue(map, "closed", false); 10811 path.constantSpeed = getValue(map, "constantSpeed", true); 10812 let vertexCount = map.vertexCount; 10813 this.readVertices(map, path, vertexCount << 1); 10814 let lengths = Utils.newArray(vertexCount / 3, 0); 10815 for (let i = 0; i < map.lengths.length; i++) 10816 lengths[i] = map.lengths[i] * scale; 10817 path.lengths = lengths; 10818 let color = getValue(map, "color", null); 10819 if (color) path.color.setFromString(color); 10820 return path; 10821 } 10822 case "point": { 10823 let point = this.attachmentLoader.newPointAttachment(skin, name); 10824 if (!point) return null; 10825 point.x = getValue(map, "x", 0) * scale; 10826 point.y = getValue(map, "y", 0) * scale; 10827 point.rotation = getValue(map, "rotation", 0); 10828 let color = getValue(map, "color", null); 10829 if (color) point.color.setFromString(color); 10830 return point; 10831 } 10832 case "clipping": { 10833 let clip = this.attachmentLoader.newClippingAttachment(skin, name); 10834 if (!clip) return null; 10835 let end = getValue(map, "end", null); 10836 if (end) clip.endSlot = skeletonData.findSlot(end); 10837 let vertexCount = map.vertexCount; 10838 this.readVertices(map, clip, vertexCount << 1); 10839 let color = getValue(map, "color", null); 10840 if (color) clip.color.setFromString(color); 10841 return clip; 10842 } 10843 } 10844 return null; 10845 } 10846 readSequence(map) { 10847 if (map == null) return null; 10848 let sequence = new Sequence(getValue(map, "count", 0)); 10849 sequence.start = getValue(map, "start", 1); 10850 sequence.digits = getValue(map, "digits", 0); 10851 sequence.setupIndex = getValue(map, "setup", 0); 10852 return sequence; 10853 } 10854 readVertices(map, attachment, verticesLength) { 10855 let scale = this.scale; 10856 attachment.worldVerticesLength = verticesLength; 10857 let vertices = map.vertices; 10858 if (verticesLength == vertices.length) { 10859 let scaledVertices = Utils.toFloatArray(vertices); 10860 if (scale != 1) { 10861 for (let i = 0, n = vertices.length; i < n; i++) 10862 scaledVertices[i] *= scale; 10863 } 10864 attachment.vertices = scaledVertices; 10865 return; 10866 } 10867 let weights = new Array(); 10868 let bones = new Array(); 10869 for (let i = 0, n = vertices.length; i < n; ) { 10870 let boneCount = vertices[i++]; 10871 bones.push(boneCount); 10872 for (let nn = i + boneCount * 4; i < nn; i += 4) { 10873 bones.push(vertices[i]); 10874 weights.push(vertices[i + 1] * scale); 10875 weights.push(vertices[i + 2] * scale); 10876 weights.push(vertices[i + 3]); 10877 } 10878 } 10879 attachment.bones = bones; 10880 attachment.vertices = Utils.toFloatArray(weights); 10881 } 10882 readAnimation(map, name, skeletonData) { 10883 let scale = this.scale; 10884 let timelines = new Array(); 10885 if (map.slots) { 10886 for (let slotName in map.slots) { 10887 let slotMap = map.slots[slotName]; 10888 let slot = skeletonData.findSlot(slotName); 10889 if (!slot) throw new Error("Slot not found: " + slotName); 10890 let slotIndex = slot.index; 10891 for (let timelineName in slotMap) { 10892 let timelineMap = slotMap[timelineName]; 10893 if (!timelineMap) continue; 10894 let frames = timelineMap.length; 10895 if (timelineName == "attachment") { 10896 let timeline = new AttachmentTimeline(frames, slotIndex); 10897 for (let frame = 0; frame < frames; frame++) { 10898 let keyMap = timelineMap[frame];
10899 timeline.setFrame(frame, getValue(keyMap, "time", 0), getValue(keyMap, "name", null)); 10900 } 10901 timelines.push(timeline); 10902 } else if (timelineName == "rgba") { 10903 let timeline = new RGBATimeline(frames, frames << 2, slotIndex); 10904 let keyMap = timelineMap[0]; 10905 let time = getValue(keyMap, "time", 0); 10906 let color = Color.fromString(keyMap.color); 10907 for (let frame = 0, bezier = 0; ; frame++) { 10908 timeline.setFrame(frame, time, color.r, color.g, color.b, color.a); 10909 let nextMap = timelineMap[frame + 1]; 10910 if (!nextMap) { 10911 timeline.shrink(bezier); 10912 break; 10913 } 10914 let time2 = getValue(nextMap, "time", 0); 10915 let newColor = Color.fromString(nextMap.color); 10916 let curve = keyMap.curve; 10917 if (curve) { 10918 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); 10919 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); 10920 bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); 10921 bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); 10922 } 10923 time = time2; 10924 color = newColor; 10925 keyMap = nextMap; 10926 } 10927 timelines.push(timeline); 10928 } else if (timelineName == "rgb") { 10929 let timeline = new RGBTimeline(frames, frames * 3, slotIndex); 10930 let keyMap = timelineMap[0]; 10931 let time = getValue(keyMap, "time", 0); 10932 let color = Color.fromString(keyMap.color); 10933 for (let frame = 0, bezier = 0; ; frame++) { 10934 timeline.setFrame(frame, time, color.r, color.g, color.b); 10935 let nextMap = timelineMap[frame + 1]; 10936 if (!nextMap) { 10937 timeline.shrink(bezier); 10938 break; 10939 } 10940 let time2 = getValue(nextMap, "time", 0); 10941 let newColor = Color.fromString(nextMap.color); 10942 let curve = keyMap.curve; 10943 if (curve) { 10944 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); 10945 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); 10946 bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); 10947 } 10948 time = time2; 10949 color = newColor; 10950 keyMap = nextMap; 10951 } 10952 timelines.push(timeline); 10953 } else if (timelineName == "alpha") { 10954 timelines.push(readTimeline12(timelineMap, new AlphaTimeline(frames, frames, slotIndex), 0, 1)); 10955 } else if (timelineName == "rgba2") { 10956 let timeline = new RGBA2Timeline(frames, frames * 7, slotIndex); 10957 let keyMap = timelineMap[0]; 10958 let time = getValue(keyMap, "time", 0); 10959 let color = Color.fromString(keyMap.light); 10960 let color2 = Color.fromString(keyMap.dark); 10961 for (let frame = 0, bezier = 0; ; frame++) { 10962 timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b); 10963 let nextMap = timelineMap[frame + 1]; 10964 if (!nextMap) { 10965 timeline.shrink(bezier); 10966 break; 10967 } 10968 let time2 = getValue(nextMap, "time", 0); 10969 let newColor = Color.fromString(nextMap.light); 10970 let newColor2 = Color.fromString(nextMap.dark); 10971 let curve = keyMap.curve; 10972 if (curve) { 10973 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); 10974 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g,
109741); 10975 bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); 10976 bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1); 10977 bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1); 10978 bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1); 10979 bezier = readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1); 10980 } 10981 time = time2; 10982 color = newColor; 10983 color2 = newColor2; 10984 keyMap = nextMap; 10985 } 10986 timelines.push(timeline); 10987 } else if (timelineName == "rgb2") { 10988 let timeline = new RGB2Timeline(frames, frames * 6, slotIndex); 10989 let keyMap = timelineMap[0]; 10990 let time = getValue(keyMap, "time", 0); 10991 let color = Color.fromString(keyMap.light); 10992 let color2 = Color.fromString(keyMap.dark); 10993 for (let frame = 0, bezier = 0; ; frame++) { 10994 timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b); 10995 let nextMap = timelineMap[frame + 1]; 10996 if (!nextMap) { 10997 timeline.shrink(bezier); 10998 break; 10999 } 11000 let time2 = getValue(nextMap, "time", 0); 11001 let newColor = Color.fromString(nextMap.light); 11002 let newColor2 = Color.fromString(nextMap.dark); 11003 let curve = keyMap.curve; 11004 if (curve) { 11005 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1); 11006 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1); 11007 bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1); 11008 bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1); 11009 bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1); 11010 bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1); 11011 } 11012 time = time2; 11013 color = newColor; 11014 color2 = newColor2; 11015 keyMap = nextMap; 11016 } 11017 timelines.push(timeline); 11018 } 11019 } 11020 } 11021 } 11022 if (map.bones) { 11023 for (let boneName in map.bones) { 11024 let boneMap = map.bones[boneName]; 11025 let bone = skeletonData.findBone(boneName); 11026 if (!bone) throw new Error("Bone not found: " + boneName); 11027 let boneIndex = bone.index; 11028 for (let timelineName in boneMap) { 11029 let timelineMap = boneMap[timelineName]; 11030 let frames = timelineMap.length; 11031 if (frames == 0) continue; 11032 if (timelineName === "rotate") { 11033 timelines.push(readTimeline12(timelineMap, new RotateTimeline(frames, frames, boneIndex), 0, 1)); 11034 } else if (timelineName === "translate") { 11035 let timeline = new TranslateTimeline(frames, frames << 1, boneIndex); 11036 timelines.push(readTimeline22(timelineMap, timeline, "x", "y", 0, scale)); 11037 } else if (timelineName === "translatex") { 11038 let timeline = new TranslateXTimeline(frames, frames, boneIndex); 11039 timelines.push(readTimeline12(timelineMap, timeline, 0, scale)); 11040 } else if (timelineName === "translatey") { 11041 let timeline = new TranslateYTimeline(frames, frames, boneIndex); 11042 timelines.push(readTimeline12(timelineMap, timeline, 0, scale)); 11043 } else if (timelineName === "scale") { 11044 let timeline = new ScaleTimeline(frames, frames << 1, boneIndex); 11045 timelines.push(readTimeline22(timelineMap, timeline, "x", "y", 1, 1)); 11046 } else if (timelineName === "scalex") { 11047 let timeline = new ScaleXTimeline(frames, frames, boneIndex); 11048 timelines.push(readTimeline12(timelineMap, timeline, 1, 1)); 11049 } else if (timelineName === "scaley") { 11050 let timeline = new ScaleYTimeline(frames, frames, boneIndex); 11051 timelines.push(readTimeline12(timelineMap, timeline, 1, 1)); 11052 } else if (timelineName === "shear") { 11053 let timeline = new ShearTimeline(frames, frames << 1, boneIndex); 11054 timelines.push(readTimeline22(timelineMap, timeline, "x", "y", 0, 1)); 11055 } else if (timelineName === "shearx") { 11056 let timeline = new ShearXTimeline(frames, frames, boneIndex); 11057 timelines.push(readTimeline12(timelineMap, timeline, 0, 1)); 11058 } else if (timelineName === "sheary") { 11059 let timeline = new ShearYTimeline(frames, frames, boneIndex); 11060 timelines.push(readTimeline12(timelineMap, timeline, 0, 1)); 11061 } else if (timelineName === "inherit") { 11062 let timeline = new InheritTimeline(frames, bone.index); 11063 for (let frame = 0; frame < timelineMap.length; frame++) { 11064 let aFrame = timelineMap[frame];
11065 timeline.setFrame(frame, getValue(aFrame, "time", 0), Utils.enumValue(Inherit, getValue(aFrame, "inherit", "Normal"))); 11066 } 11067 timelines.push(timeline); 11068 } 11069 } 11070 } 11071 } 11072 if (map.ik) { 11073 for (let constraintName in map.ik) { 11074 let constraintMap = map.ik[constraintName]; 11075 let keyMap = constraintMap[0]; 11076 if (!keyMap) continue; 11077 let constraint = skeletonData.findIkConstraint(constraintName); 11078 if (!constraint) throw new Error("IK Constraint not found: " + constraintName); 11079 let constraintIndex = skeletonData.ikConstraints.indexOf(constraint); 11080 let timeline = new IkConstraintTimeline(constraintMap.length, constraintMap.length << 1, constraintIndex); 11081 let time = getValue(keyMap, "time", 0); 11082 let mix = getValue(keyMap, "mix", 1); 11083 let softness = getValue(keyMap, "softness", 0) * scale; 11084 for (let frame = 0, bezier = 0; ; frame++) { 11085 timeline.setFrame(frame, time, mix, softness, getValue(keyMap, "bendPositive", true) ? 1 : -1, getValue(keyMap, "compress", false), getValue(keyMap, "stretch", false)); 11086 let nextMap = constraintMap[frame + 1]; 11087 if (!nextMap) { 11088 timeline.shrink(bezier); 11089 break; 11090 } 11091 let time2 = getValue(nextMap, "time", 0); 11092 let mix2 = getValue(nextMap, "mix", 1); 11093 let softness2 = getValue(nextMap, "softness", 0) * scale; 11094 let curve = keyMap.curve; 11095 if (curve) { 11096 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1); 11097 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, scale); 11098 } 11099 time = time2; 11100 mix = mix2; 11101 softness = softness2; 11102 keyMap = nextMap; 11103 } 11104 timelines.push(timeline); 11105 } 11106 } 11107 if (map.transform) { 11108 for (let constraintName in map.transform) { 11109 let timelineMap = map.transform[constraintName]; 11110 let keyMap = timelineMap[0]; 11111 if (!keyMap) continue; 11112 let constraint = skeletonData.findTransformConstraint(constraintName); 11113 if (!constraint) throw new Error("Transform constraint not found: " + constraintName); 11114 let constraintIndex = skeletonData.transformConstraints.indexOf(constraint); 11115 let timeline = new TransformConstraintTimeline(timelineMap.length, timelineMap.length * 6, constraintIndex); 11116 let time = getValue(keyMap, "time", 0); 11117 let mixRotate = getValue(keyMap, "mixRotate", 1); 11118 let mixX = getValue(keyMap, "mixX", 1); 11119 let mixY = getValue(keyMap, "mixY", mixX); 11120 let mixScaleX = getValue(keyMap, "mixScaleX", 1); 11121 let mixScaleY = getValue(keyMap, "mixScaleY", mixScaleX); 11122 let mixShearY = getValue(keyMap, "mixShearY", 1); 11123 for (let frame = 0, bezier = 0; ; frame++) { 11124 timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY); 11125 let nextMap = timelineMap[frame + 1]; 11126 if (!nextMap) { 11127 timeline.shrink(bezier); 11128 break; 11129 } 11130 let time2 = getValue(nextMap, "time", 0); 11131 let mixRotate2 = getValue(nextMap, "mixRotate", 1); 11132 let mixX2 = getValue(nextMap, "mixX", 1); 11133 let mixY2 = getValue(nextMap, "mixY", mixX2); 11134 let mixScaleX2 = getValue(nextMap, "mixScaleX", 1); 11135 let mixScaleY2 = getValue(nextMap, "mixScaleY", mixScaleX2); 11136 let mixShearY2 = getValue(nextMap, "mixShearY", 1); 11137 let curve = keyMap.curve; 11138 if (curve) { 11139 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); 11140 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); 11141 bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); 11142 bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1); 11143 bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1); 11144 bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1); 11145 } 11146 time = time2; 11147 mixRotate = mixRotate2; 11148 mixX = mixX2; 11149 mixY = mixY2; 11150 mixScaleX = mixScaleX2; 11151 mixScaleY = mixScaleY2; 11152 mixScaleX = mixScaleX2; 11153 keyMap = nextMap; 11154 } 11155 timelines.push(timeline); 11156 } 11157 } 11158 if (map.path) { 11159 for (let constraintName in map.path) { 11160 let constraintMap = map.path[constraintName]; 11161 let constraint = skeletonData.findPathConstraint(constraintName); 11162 if (!constraint) throw new Error("Path constraint not found: " + constraintName); 11163 let constraintIndex = skeletonData.pathConstraints.indexOf(constraint); 11164 for (let timelineName in constraintMap) { 11165 let timelineMap = constraintMap[timelineName]; 11166 let keyMap = timelineMap[0]; 11167 if (!keyMap) continue; 11168 let frames = timelineMap.length; 11169 if (timelineName === "position") { 11170 let timeline = new PathConstraintPositionTimeline(frames, frames, constraintIndex); 11171 timelines.push(readTimeline12(timelineMap, timeline, 0, constraint.positionMode == 0 /* Fixed */ ? scale : 1)); 11172 } else if (timelineName === "spacing") { 11173 let timeline = new PathConstraintSpacingTimeline(frames, frames, constraintIndex); 11174 timelines.push(readTimeline12(timelineMap, timeline, 0, constraint.spacingMode == 0 /* Length */ || constraint.spacingMode == 1 /* Fixed */ ? scale : 1)); 11175 } else if (timelineName === "mix") { 11176 let timeline = new PathConstraintMixTimeline(frames, frames * 3, constraintIndex); 11177 let time = getValue(keyMap, "time", 0); 11178 let mixRotate = getValue(keyMap, "mixRotate", 1); 11179 let mixX = getValue(keyMap, "mixX", 1); 11180 let mixY = getValue(keyMap, "mixY", mixX); 11181 for (let frame = 0, bezier = 0; ; frame++) {
11182 timeline.setFrame(frame, time, mixRotate, mixX, mixY); 11183 let nextMap = timelineMap[frame + 1]; 11184 if (!nextMap) { 11185 timeline.shrink(bezier); 11186 break; 11187 } 11188 let time2 = getValue(nextMap, "time", 0); 11189 let mixRotate2 = getValue(nextMap, "mixRotate", 1); 11190 let mixX2 = getValue(nextMap, "mixX", 1); 11191 let mixY2 = getValue(nextMap, "mixY", mixX2); 11192 let curve = keyMap.curve; 11193 if (curve) { 11194 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1); 11195 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1); 11196 bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1); 11197 } 11198 time = time2; 11199 mixRotate = mixRotate2; 11200 mixX = mixX2; 11201 mixY = mixY2; 11202 keyMap = nextMap; 11203 } 11204 timelines.push(timeline); 11205 } 11206 } 11207 } 11208 } 11209 if (map.physics) { 11210 for (let constraintName in map.physics) { 11211 let constraintMap = map.physics[constraintName]; 11212 let constraintIndex = -1; 11213 if (constraintName.length > 0) { 11214 let constraint = skeletonData.findPhysicsConstraint(constraintName); 11215 if (!constraint) throw new Error("Physics constraint not found: " + constraintName); 11216 constraintIndex = skeletonData.physicsConstraints.indexOf(constraint); 11217 } 11218 for (let timelineName in constraintMap) { 11219 let timelineMap = constraintMap[timelineName]; 11220 let keyMap = timelineMap[0]; 11221 if (!keyMap) continue; 11222 let frames = timelineMap.length; 11223 if (timelineName == "reset") { 11224 const timeline2 = new PhysicsConstraintResetTimeline(frames, constraintIndex); 11225 for (let frame = 0; keyMap != null; keyMap = timelineMap[frame + 1], frame++) 11226 timeline2.setFrame(frame, getValue(keyMap, "time", 0)); 11227 timelines.push(timeline2); 11228 continue; 11229 } 11230 let timeline; 11231 if (timelineName == "inertia") 11232 timeline = new PhysicsConstraintInertiaTimeline(frames, frames, constraintIndex); 11233 else if (timelineName == "strength") 11234 timeline = new PhysicsConstraintStrengthTimeline(frames, frames, constraintIndex); 11235 else if (timelineName == "damping") 11236 timeline = new PhysicsConstraintDampingTimeline(frames, frames, constraintIndex); 11237 else if (timelineName == "mass") 11238 timeline = new PhysicsConstraintMassTimeline(frames, frames, constraintIndex); 11239 else if (timelineName == "wind") 11240 timeline = new PhysicsConstraintWindTimeline(frames, frames, constraintIndex); 11241 else if (timelineName == "gravity") 11242 timeline = new PhysicsConstraintGravityTimeline(frames, frames, constraintIndex); 11243 else if (timelineName == "mix") 11244 timeline = new PhysicsConstraintMixTimeline(frames, frames, constraintIndex); 11245 else 11246 continue; 11247 timelines.push(readTimeline12(timelineMap, timeline, 0, 1)); 11248 } 11249 } 11250 } 11251 if (map.attachments) { 11252 for (let attachmentsName in map.attachments) { 11253 let attachmentsMap = map.attachments[attachmentsName]; 11254 let skin = skeletonData.findSkin(attachmentsName); 11255 if (!skin) throw new Error("Skin not found: " + attachmentsName); 11256 for (let slotMapName in attachmentsMap) { 11257 let slotMap = attachmentsMap[slotMapName]; 11258 let slot = skeletonData.findSlot(slotMapName); 11259 if (!slot) throw new Error("Slot not found: " + slotMapName); 11260 let slotIndex = slot.index; 11261 for (let attachmentMapName in slotMap) { 11262 let attachmentMap = slotMap[attachmentMapName]; 11263 let attachment = skin.getAttachment(slotIndex, attachmentMapName); 11264 for (let timelineMapName in attachmentMap) { 11265 let timelineMap = attachmentMap[timelineMapName]; 11266 let keyMap = timelineMap[0]; 11267 if (!keyMap) continue; 11268 if (timelineMapName == "deform") { 11269 let weighted = attachment.bones; 11270 let vertices = attachment.vertices; 11271 let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length; 11272 let timeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment); 11273 let time = getValue(keyMap, "time", 0); 11274 for (let frame = 0, bezier = 0; ; frame++) { 11275 let deform; 11276 let verticesValue = getValue(keyMap, "vertices", null); 11277 if (!verticesValue) 11278 deform = weighted ? Utils.newFloatArray(deformLength) : vertices; 11279 else { 11280 deform = Utils.newFloatArray(deformLength); 11281 let start = getValue(keyMap, "offset", 0); 11282 Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length); 11283 if (scale != 1) { 11284 for (let i = start, n = i + verticesValue.length; i < n; i++) 11285 deform[i] *= scale; 11286 } 11287 if (!weighted) { 11288 for (let i = 0; i < deformLength; i++) 11289 deform[i] += vertices[i]; 11290 } 11291 }
11292 timeline.setFrame(frame, time, deform); 11293 let nextMap = timelineMap[frame + 1]; 11294 if (!nextMap) { 11295 timeline.shrink(bezier); 11296 break; 11297 } 11298 let time2 = getValue(nextMap, "time", 0); 11299 let curve = keyMap.curve; 11300 if (curve) bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1); 11301 time = time2; 11302 keyMap = nextMap; 11303 } 11304 timelines.push(timeline); 11305 } else if (timelineMapName == "sequence") { 11306 let timeline = new SequenceTimeline(timelineMap.length, slotIndex, attachment); 11307 let lastDelay = 0; 11308 for (let frame = 0; frame < timelineMap.length; frame++) { 11309 let delay = getValue(keyMap, "delay", lastDelay); 11310 let time = getValue(keyMap, "time", 0); 11311 let mode = SequenceMode[getValue(keyMap, "mode", "hold")]; 11312 let index = getValue(keyMap, "index", 0); 11313 timeline.setFrame(frame, time, mode, index, delay); 11314 lastDelay = delay; 11315 keyMap = timelineMap[frame + 1]; 11316 } 11317 timelines.push(timeline); 11318 } 11319 } 11320 } 11321 } 11322 } 11323 } 11324 if (map.drawOrder) { 11325 let timeline = new DrawOrderTimeline(map.drawOrder.length); 11326 let slotCount = skeletonData.slots.length; 11327 let frame = 0; 11328 for (let i = 0; i < map.drawOrder.length; i++, frame++) { 11329 let drawOrderMap = map.drawOrder[i]; 11330 let drawOrder = null; 11331 let offsets = getValue(drawOrderMap, "offsets", null); 11332 if (offsets) { 11333 drawOrder = Utils.newArray(slotCount, -1); 11334 let unchanged = Utils.newArray(slotCount - offsets.length, 0); 11335 let originalIndex = 0, unchangedIndex = 0; 11336 for (let ii = 0; ii < offsets.length; ii++) { 11337 let offsetMap = offsets[ii]; 11338 let slot = skeletonData.findSlot(offsetMap.slot); 11339 if (!slot) throw new Error("Slot not found: " + slot); 11340 let slotIndex = slot.index; 11341 while (originalIndex != slotIndex) 11342 unchanged[unchangedIndex++] = originalIndex++; 11343 drawOrder[originalIndex + offsetMap.offset] = originalIndex++; 11344 } 11345 while (originalIndex < slotCount) 11346 unchanged[unchangedIndex++] = originalIndex++; 11347 for (let ii = slotCount - 1; ii >= 0; ii--) 11348 if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex]; 11349 } 11350 timeline.setFrame(frame, getValue(drawOrderMap, "time", 0), drawOrder); 11351 } 11352 timelines.push(timeline); 11353 } 11354 if (map.events) { 11355 let timeline = new EventTimeline(map.events.length); 11356 let frame = 0; 11357 for (let i = 0; i < map.events.length; i++, frame++) { 11358 let eventMap = map.events[i]; 11359 let eventData = skeletonData.findEvent(eventMap.name); 11360 if (!eventData) throw new Error("Event not found: " + eventMap.name); 11361 let event = new Event(Utils.toSinglePrecision(getValue(eventMap, "time", 0)), eventData); 11362 event.intValue = getValue(eventMap, "int", eventData.intValue); 11363 event.floatValue = getValue(eventMap, "float", eventData.floatValue); 11364 event.stringValue = getValue(eventMap, "string", eventData.stringValue); 11365 if (event.data.audioPath) { 11366 event.volume = getValue(eventMap, "volume", 1); 11367 event.balance = getValue(eventMap, "balance", 0); 11368 } 11369 timeline.setFrame(frame, event); 11370 } 11371 timelines.push(timeline); 11372 } 11373 let duration = 0; 11374 for (let i = 0, n = timelines.length; i < n; i++) 11375 duration = Math.max(duration, timelines[i].getDuration()); 11376 skeletonData.animations.push(new Animation(name, timelines, duration)); 11377 } 11378 }; 11379 var LinkedMesh2 = class { 11380 parent; 11381 skin; 11382 slotIndex; 11383 mesh; 11384 inheritTimeline; 11385 constructor(mesh, skin, slotIndex, parent, inheritDeform) { 11386 this.mesh = mesh; 11387 this.skin = skin; 11388 this.slotIndex = slotIndex; 11389 this.parent = parent; 11390 this.inheritTimeline = inheritDeform; 11391 } 11392 }; 11393 function readTimeline12(keys, timeline, defaultValue, scale) { 11394 let keyMap = keys[0]; 11395 let time = getValue(keyMap, "time", 0); 11396 let value = getValue(keyMap, "value", defaultValue) * scale; 11397 let bezier = 0; 11398 for (let frame = 0; ; frame++) {
11399 timeline.setFrame(frame, time, value); 11400 let nextMap = keys[frame + 1]; 11401 if (!nextMap) { 11402 timeline.shrink(bezier); 11403 return timeline; 11404 } 11405 let time2 = getValue(nextMap, "time", 0); 11406 let value2 = getValue(nextMap, "value", defaultValue) * scale; 11407 if (keyMap.curve) bezier = readCurve(keyMap.curve, timeline, bezier, frame, 0, time, time2, value, value2, scale); 11408 time = time2; 11409 value = value2; 11410 keyMap = nextMap; 11411 } 11412 } 11413 function readTimeline22(keys, timeline, name1, name2, defaultValue, scale) { 11414 let keyMap = keys[0]; 11415 let time = getValue(keyMap, "time", 0); 11416 let value1 = getValue(keyMap, name1, defaultValue) * scale; 11417 let value2 = getValue(keyMap, name2, defaultValue) * scale; 11418 let bezier = 0; 11419 for (let frame = 0; ; frame++) { 11420 timeline.setFrame(frame, time, value1, value2); 11421 let nextMap = keys[frame + 1]; 11422 if (!nextMap) { 11423 timeline.shrink(bezier); 11424 return timeline; 11425 } 11426 let time2 = getValue(nextMap, "time", 0); 11427 let nvalue1 = getValue(nextMap, name1, defaultValue) * scale; 11428 let nvalue2 = getValue(nextMap, name2, defaultValue) * scale; 11429 let curve = keyMap.curve; 11430 if (curve) { 11431 bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale); 11432 bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale); 11433 } 11434 time = time2; 11435 value1 = nvalue1; 11436 value2 = nvalue2; 11437 keyMap = nextMap; 11438 } 11439 } 11440 function readCurve(curve, timeline, bezier, frame, value, time1, time2, value1, value2, scale) { 11441 if (curve == "stepped") { 11442 timeline.setStepped(frame); 11443 return bezier; 11444 } 11445 let i = value << 2; 11446 let cx1 = curve[i]; 11447 let cy1 = curve[i + 1] * scale;
11448 let cx2 = curve[i + 2]; 11449 let cy2 = curve[i + 3] * scale; 11450 timeline.setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2); 11451 return bezier + 1; 11452 } 11453 function getValue(map, property, defaultValue) { 11454 return map[property] !== void 0 ? map[property] : defaultValue; 11455 } 11456 11457
11457// spine-core/src/polyfills.ts 11458 (() => { 11459 if (typeof Math.fround === "undefined") { 11460 Math.fround = /* @__PURE__ */ function(array) { 11461 return function(x) { 11462 return array[0] = x, array[0]; 11463 }; 11464 }(new Float32Array(1)); 11465 } 11466 })(); 11467 11468
11468// spine-webgl/src/WebGL.ts 11469 var ManagedWebGLRenderingContext = class { 11470 canvas; 11471 gl; 11472 restorables = new Array(); 11473 constructor(canvasOrContext, contextConfig = { alpha: "true" }) { 11474 if (!(canvasOrContext instanceof WebGLRenderingContext || typeof WebGL2RenderingContext !== "undefined" && canvasOrContext instanceof WebGL2RenderingContext)) { 11475 let canvas = canvasOrContext; 11476 this.gl = canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig); 11477 this.canvas = canvas; 11478 canvas.addEventListener("webglcontextlost", this.contextLostHandler); 11479 canvas.addEventListener("webglcontextrestored", this.contextRestoredHandler); 11480 } else { 11481 this.gl = canvasOrContext; 11482 this.canvas = this.gl.canvas; 11483 } 11484 } 11485 contextLostHandler(e) { 11486 if (e) e.preventDefault(); 11487 } 11488 contextRestoredHandler(e) { 11489 for (let i = 0, n = this.restorables.length; i < n; i++) 11490 this.restorables[i].restore(); 11491 } 11492 dispose() { 11493 this.canvas.removeEventListener("webglcontextlost", this.contextLostHandler); 11494 this.canvas.removeEventListener("webglcontextrestored", this.contextRestoredHandler); 11495 } 11496 addRestorable(restorable) { 11497 this.restorables.push(restorable); 11498 } 11499 removeRestorable(restorable) { 11500 let index = this.restorables.indexOf(restorable); 11501 if (index > -1) this.restorables.splice(index, 1); 11502 } 11503 }; 11504 11505
11505// spine-webgl/src/GLTexture.ts 11506 var GLTexture = class _GLTexture extends Texture { 11507 context; 11508 texture = null; 11509 boundUnit = 0; 11510 useMipMaps = false; 11511 static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL = false; 11512 constructor(context, image, useMipMaps = false) { 11513 super(image); 11514 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 11515 this.useMipMaps = useMipMaps; 11516 this.restore(); 11517 this.context.addRestorable(this); 11518 } 11519 setFilters(minFilter, magFilter) { 11520 let gl = this.context.gl; 11521 this.bind(); 11522 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); 11523 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, _GLTexture.validateMagFilter(magFilter)); 11524 this.useMipMaps = _GLTexture.usesMipMaps(minFilter); 11525 if (this.useMipMaps) gl.generateMipmap(gl.TEXTURE_2D); 11526 } 11527 static validateMagFilter(magFilter) { 11528 switch (magFilter) { 11529 case 9987 /* MipMapLinearLinear */: 11530 case 9985 /* MipMapLinearNearest */: 11531 case 9986 /* MipMapNearestLinear */: 11532 case 9984 /* MipMapNearestNearest */: 11533 return 9729 /* Linear */; 11534 default: 11535 return magFilter; 11536 } 11537 } 11538 static usesMipMaps(filter) { 11539 switch (filter) { 11540 case 9987 /* MipMapLinearLinear */: 11541 case 9985 /* MipMapLinearNearest */: 11542 case 9986 /* MipMapNearestLinear */: 11543 case 9984 /* MipMapNearestNearest */: 11544 return true; 11545 default: 11546 return false; 11547 } 11548 } 11549 setWraps(uWrap, vWrap) { 11550 let gl = this.context.gl; 11551 this.bind(); 11552 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap); 11553 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap); 11554 } 11555 update(useMipMaps) { 11556 let gl = this.context.gl; 11557 if (!this.texture) this.texture = this.context.gl.createTexture(); 11558 this.bind(); 11559 if (_GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL) gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); 11560 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image); 11561 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 11562 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR); 11563 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 11564 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 11565 if (useMipMaps) gl.generateMipmap(gl.TEXTURE_2D); 11566 } 11567 restore() { 11568 this.texture = null; 11569 this.update(this.useMipMaps); 11570 } 11571 bind(unit = 0) { 11572 let gl = this.context.gl; 11573 this.boundUnit = unit; 11574 gl.activeTexture(gl.TEXTURE0 + unit); 11575 gl.bindTexture(gl.TEXTURE_2D, this.texture); 11576 } 11577 unbind() { 11578 let gl = this.context.gl; 11579 gl.activeTexture(gl.TEXTURE0 + this.boundUnit); 11580 gl.bindTexture(gl.TEXTURE_2D, null); 11581 } 11582 dispose() { 11583 this.context.removeRestorable(this); 11584 let gl = this.context.gl; 11585 gl.deleteTexture(this.texture); 11586 } 11587 }; 11588 11589
11589// spine-webgl/src/AssetManager.ts 11590 var AssetManager = class extends AssetManagerBase { 11591 constructor(context, pathPrefix = "", downloader = new Downloader()) { 11592 super((image) => { 11593 return new GLTexture(context, image); 11594 }, pathPrefix, downloader); 11595 } 11596 }; 11597 11598
11598// spine-webgl/src/Vector3.ts 11599 var Vector3 = class { 11600 x = 0; 11601 y = 0; 11602 z = 0; 11603 constructor(x = 0, y = 0, z = 0) { 11604 this.x = x; 11605 this.y = y; 11606 this.z = z; 11607 } 11608 setFrom(v) { 11609 this.x = v.x; 11610 this.y = v.y; 11611 this.z = v.z; 11612 return this; 11613 } 11614 set(x, y, z) { 11615 this.x = x; 11616 this.y = y; 11617 this.z = z; 11618 return this; 11619 } 11620 add(v) { 11621 this.x += v.x; 11622 this.y += v.y; 11623 this.z += v.z; 11624 return this; 11625 } 11626 sub(v) { 11627 this.x -= v.x; 11628 this.y -= v.y; 11629 this.z -= v.z; 11630 return this; 11631 } 11632 scale(s) { 11633 this.x *= s; 11634 this.y *= s; 11635 this.z *= s; 11636 return this; 11637 } 11638 normalize() { 11639 let len = this.length(); 11640 if (len == 0) return this; 11641 len = 1 / len; 11642 this.x *= len; 11643 this.y *= len; 11644 this.z *= len; 11645 return this; 11646 } 11647 cross(v) { 11648 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); 11649 } 11650 multiply(matrix) { 11651 let l_mat = matrix.values; 11652 return this.set( 11653 this.x * l_mat[M00] + this.y * l_mat[M01] + this.z * l_mat[M02] + l_mat[M03], 11654 this.x * l_mat[M10] + this.y * l_mat[M11] + this.z * l_mat[M12] + l_mat[M13], 11655 this.x * l_mat[M20] + this.y * l_mat[M21] + this.z * l_mat[M22] + l_mat[M23] 11656 ); 11657 } 11658 project(matrix) { 11659 let l_mat = matrix.values; 11660 let l_w = 1 / (this.x * l_mat[M30] + this.y * l_mat[M31] + this.z * l_mat[M32] + l_mat[M33]); 11661 return this.set( 11662 (this.x * l_mat[M00] + this.y * l_mat[M01] + this.z * l_mat[M02] + l_mat[M03]) * l_w, 11663 (this.x * l_mat[M10] + this.y * l_mat[M11] + this.z * l_mat[M12] + l_mat[M13]) * l_w, 11664 (this.x * l_mat[M20] + this.y * l_mat[M21] + this.z * l_mat[M22] + l_mat[M23]) * l_w 11665 ); 11666 } 11667 dot(v) { 11668 return this.x * v.x + this.y * v.y + this.z * v.z; 11669 } 11670 length() { 11671 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); 11672 } 11673 distance(v) { 11674 let a = v.x - this.x; 11675 let b = v.y - this.y; 11676 let c = v.z - this.z; 11677 return Math.sqrt(a * a + b * b + c * c); 11678 } 11679 }; 11680 11681
11681// spine-webgl/src/Matrix4.ts 11682 var M00 = 0; 11683 var M01 = 4; 11684 var M02 = 8; 11685 var M03 = 12; 11686 var M10 = 1; 11687 var M11 = 5; 11688 var M12 = 9; 11689 var M13 = 13; 11690 var M20 = 2; 11691 var M21 = 6; 11692 var M22 = 10; 11693 var M23 = 14; 11694 var M30 = 3; 11695 var M31 = 7; 11696 var M32 = 11; 11697 var M33 = 15; 11698 var Matrix42 = class _Matrix4 { 11699 temp = new Float32Array(16); 11700 values = new Float32Array(16); 11701 static xAxis = new Vector3(); 11702 static yAxis = new Vector3(); 11703 static zAxis = new Vector3(); 11704 static tmpMatrix = new _Matrix4(); 11705 constructor() { 11706 let v = this.values; 11707 v[M00] = 1; 11708 v[M11] = 1; 11709 v[M22] = 1; 11710 v[M33] = 1; 11711 } 11712 set(values) { 11713 this.values.set(values); 11714 return this; 11715 } 11716 transpose() { 11717 let t = this.temp; 11718 let v = this.values; 11719 t[M00] = v[M00]; 11720 t[M01] = v[M10]; 11721 t[M02] = v[M20]; 11722 t[M03] = v[M30]; 11723 t[M10] = v[M01]; 11724 t[M11] = v[M11]; 11725 t[M12] = v[M21]; 11726 t[M13] = v[M31]; 11727 t[M20] = v[M02]; 11728 t[M21] = v[M12]; 11729 t[M22] = v[M22]; 11730 t[M23] = v[M32]; 11731 t[M30] = v[M03]; 11732 t[M31] = v[M13]; 11733 t[M32] = v[M23]; 11734 t[M33] = v[M33]; 11735 return this.set(t); 11736 } 11737 identity() { 11738 let v = this.values; 11739 v[M00] = 1; 11740 v[M01] = 0; 11741 v[M02] = 0; 11742 v[M03] = 0; 11743 v[M10] = 0; 11744 v[M11] = 1; 11745 v[M12] = 0; 11746 v[M13] = 0; 11747 v[M20] = 0; 11748 v[M21] = 0; 11749 v[M22] = 1; 11750 v[M23] = 0; 11751 v[M30] = 0; 11752 v[M31] = 0; 11753 v[M32] = 0; 11754 v[M33] = 1; 11755 return this; 11756 } 11757 invert() { 11758 let v = this.values; 11759 let t = this.temp; 11760 let l_det = v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; 11761 if (l_det == 0) throw new Error("non-invertible matrix"); 11762 let inv_det = 1 / l_det; 11763 t[M00] = v[M12] * v[M23] * v[M31] - v[M13] * v[M22] * v[M31] + v[M13] * v[M21] * v[M32] - v[M11] * v[M23] * v[M32] - v[M12] * v[M21] * v[M33] + v[M11] * v[M22] * v[M33]; 11764 t[M01] = v[M03] * v[M22] * v[M31] - v[M02] * v[M23] * v[M31] - v[M03] * v[M21] * v[M32] + v[M01] * v[M23] * v[M32] + v[M02] * v[M21] * v[M33] - v[M01] * v[M22] * v[M33]; 11765 t[M02] = v[M02] * v[M13] * v[M31] - v[M03] * v[M12] * v[M31] + v[M03] * v[M11] * v[M32] - v[M01] * v[M13] * v[M32] - v[M02] * v[M11] * v[M33] + v[M01] * v[M12] * v[M33]; 11766 t[M03] = v[M03] * v[M12] * v[M21] - v[M02] * v[M13] * v[M21] - v[M03] * v[M11] * v[M22] + v[M01] * v[M13] * v[M22] + v[M02] * v[M11] * v[M23] - v[M01] * v[M12] * v[M23]; 11767 t[M10] = v[M13] * v[M22] * v[M30] - v[M12] * v[M23] * v[M30] - v[M13] * v[M20] * v[M32] + v[M10] * v[M23] * v[M32] + v[M12] * v[M20] * v[M33] - v[M10] * v[M22] * v[M33]; 11768 t[M11] = v[M02] * v[M23] * v[M30] - v[M03] * v[M22] * v[M30] + v[M03] * v[M20] * v[M32] - v[M00] * v[M23] * v[M32] - v[M02] * v[M20] * v[M33] + v[M00] * v[M22] * v[M33]; 11769 t[M12] = v[M03] * v[M12] * v[M30] - v[M02] * v[M13] * v[M30] - v[M03] * v[M10] * v[M32] + v[M00] * v[M13] * v[M32] + v[M02] * v[M10] * v[M33] - v[M00] * v[M12] * v[M33]; 11770 t[M13] = v[M02] * v[M13] * v[M20] - v[M03] * v[M12] * v[M20] + v[M03] * v[M10] * v[M22] - v[M00] * v[M13] * v[M22] - v[M02] * v[M10] * v[M23] + v[M00] * v[M12] * v[M23]; 11771 t[M20] = v[M11] * v[M23] * v[M30] - v[M13] * v[M21] * v[M30] + v[M13] * v[M20] * v[M31] - v[M10] * v[M23] * v[M31] - v[M11] * v[M20] * v[M33] + v[M10] * v[M21] * v[M33]; 11772 t[M21] = v[M03] * v[M21] * v[M30] - v[M01] * v[M23] * v[M30] - v[M03] * v[M20] * v[M31] + v[M00] * v[M23] * v[M31] + v[M01] * v[M20] * v[M33] - v[M00] * v[M21] * v[M33]; 11773 t[M22] = v[M01] * v[M13] * v[M30] - v[M03] * v[M11] * v[M30] + v[M03] * v[M10] * v[M31] - v[M00] * v[M13] * v[M31] - v[M01] * v[M10] * v[M33] + v[M00] * v[M11] * v[M33];
11774 t[M23] = v[M03] * v[M11] * v[M20] - v[M01] * v[M13] * v[M20] - v[M03] * v[M10] * v[M21] + v[M00] * v[M13] * v[M21] + v[M01] * v[M10] * v[M23] - v[M00] * v[M11] * v[M23]; 11775 t[M30] = v[M12] * v[M21] * v[M30] - v[M11] * v[M22] * v[M30] - v[M12] * v[M20] * v[M31] + v[M10] * v[M22] * v[M31] + v[M11] * v[M20] * v[M32] - v[M10] * v[M21] * v[M32]; 11776 t[M31] = v[M01] * v[M22] * v[M30] - v[M02] * v[M21] * v[M30] + v[M02] * v[M20] * v[M31] - v[M00] * v[M22] * v[M31] - v[M01] * v[M20] * v[M32] + v[M00] * v[M21] * v[M32]; 11777 t[M32] = v[M02] * v[M11] * v[M30] - v[M01] * v[M12] * v[M30] - v[M02] * v[M10] * v[M31] + v[M00] * v[M12] * v[M31] + v[M01] * v[M10] * v[M32] - v[M00] * v[M11] * v[M32]; 11778 t[M33] = v[M01] * v[M12] * v[M20] - v[M02] * v[M11] * v[M20] + v[M02] * v[M10] * v[M21] - v[M00] * v[M12] * v[M21] - v[M01] * v[M10] * v[M22] + v[M00] * v[M11] * v[M22]; 11779 v[M00] = t[M00] * inv_det; 11780 v[M01] = t[M01] * inv_det; 11781 v[M02] = t[M02] * inv_det; 11782 v[M03] = t[M03] * inv_det; 11783 v[M10] = t[M10] * inv_det; 11784 v[M11] = t[M11] * inv_det; 11785 v[M12] = t[M12] * inv_det; 11786 v[M13] = t[M13] * inv_det; 11787 v[M20] = t[M20] * inv_det; 11788 v[M21] = t[M21] * inv_det; 11789 v[M22] = t[M22] * inv_det; 11790 v[M23] = t[M23] * inv_det; 11791 v[M30] = t[M30] * inv_det; 11792 v[M31] = t[M31] * inv_det; 11793 v[M32] = t[M32] * inv_det; 11794 v[M33] = t[M33] * inv_det; 11795 return this; 11796 } 11797 determinant() { 11798 let v = this.values; 11799 return v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; 11800 } 11801 translate(x, y, z) { 11802 let v = this.values; 11803 v[M03] += x; 11804 v[M13] += y; 11805 v[M23] += z; 11806 return this; 11807 } 11808 copy() { 11809 return new _Matrix4().set(this.values); 11810 } 11811 projection(near, far, fovy, aspectRatio) { 11812 this.identity(); 11813 let l_fd = 1 / Math.tan(fovy * (Math.PI / 180) / 2); 11814 let l_a1 = (far + near) / (near - far); 11815 let l_a2 = 2 * far * near / (near - far); 11816 let v = this.values; 11817 v[M00] = l_fd / aspectRatio; 11818 v[M10] = 0; 11819 v[M20] = 0; 11820 v[M30] = 0; 11821 v[M01] = 0; 11822 v[M11] = l_fd; 11823 v[M21] = 0; 11824 v[M31] = 0; 11825 v[M02] = 0; 11826 v[M12] = 0; 11827 v[M22] = l_a1; 11828 v[M32] = -1; 11829 v[M03] = 0; 11830 v[M13] = 0; 11831 v[M23] = l_a2; 11832 v[M33] = 0; 11833 return this; 11834 } 11835 ortho2d(x, y, width, height) { 11836 return this.ortho(x, x + width, y, y + height, 0, 1); 11837 } 11838 ortho(left, right, bottom, top, near, far) { 11839 this.identity(); 11840 let x_orth = 2 / (right - left); 11841 let y_orth = 2 / (top - bottom); 11842 let z_orth = -2 / (far - near); 11843 let tx = -(right + left) / (right - left); 11844 let ty = -(top + bottom) / (top - bottom); 11845 let tz = -(far + near) / (far - near); 11846 let v = this.values; 11847 v[M00] = x_orth; 11848 v[M10] = 0; 11849 v[M20] = 0; 11850 v[M30] = 0; 11851 v[M01] = 0; 11852 v[M11] = y_orth; 11853 v[M21] = 0; 11854 v[M31] = 0; 11855 v[M02] = 0; 11856 v[M12] = 0; 11857 v[M22] = z_orth; 11858 v[M32] = 0; 11859 v[M03] = tx; 11860 v[M13] = ty; 11861 v[M23] = tz; 11862 v[M33] = 1; 11863 return this; 11864 } 11865 multiply(matrix) { 11866 let t = this.temp; 11867 let v = this.values; 11868 let m = matrix.values; 11869 t[M00] = v[M00] * m[M00] + v[M01] * m[M10] + v[M02] * m[M20] + v[M03] * m[M30]; 11870 t[M01] = v[M00] * m[M01] + v[M01] * m[M11] + v[M02] * m[M21] + v[M03] * m[M31]; 11871 t[M02] = v[M00] * m[M02] + v[M01] * m[M12] + v[M02] * m[M22] + v[M03] * m[M32]; 11872 t[M03] = v[M00] * m[M03] + v[M01] * m[M13] + v[M02] * m[M23] + v[M03] * m[M33]; 11873 t[M10] = v[M10] * m[M00] + v[M11] * m[M10] + v[M12] * m[M20] + v[M13] * m[M30]; 11874 t[M11] = v[M10] * m[M01] + v[M11] * m[M11] + v[M12] * m[M21] + v[M13] * m[M31];
11875 t[M12] = v[M10] * m[M02] + v[M11] * m[M12] + v[M12] * m[M22] + v[M13] * m[M32]; 11876 t[M13] = v[M10] * m[M03] + v[M11] * m[M13] + v[M12] * m[M23] + v[M13] * m[M33]; 11877 t[M20] = v[M20] * m[M00] + v[M21] * m[M10] + v[M22] * m[M20] + v[M23] * m[M30]; 11878 t[M21] = v[M20] * m[M01] + v[M21] * m[M11] + v[M22] * m[M21] + v[M23] * m[M31]; 11879 t[M22] = v[M20] * m[M02] + v[M21] * m[M12] + v[M22] * m[M22] + v[M23] * m[M32]; 11880 t[M23] = v[M20] * m[M03] + v[M21] * m[M13] + v[M22] * m[M23] + v[M23] * m[M33]; 11881 t[M30] = v[M30] * m[M00] + v[M31] * m[M10] + v[M32] * m[M20] + v[M33] * m[M30]; 11882 t[M31] = v[M30] * m[M01] + v[M31] * m[M11] + v[M32] * m[M21] + v[M33] * m[M31]; 11883 t[M32] = v[M30] * m[M02] + v[M31] * m[M12] + v[M32] * m[M22] + v[M33] * m[M32]; 11884 t[M33] = v[M30] * m[M03] + v[M31] * m[M13] + v[M32] * m[M23] + v[M33] * m[M33]; 11885 return this.set(this.temp); 11886 } 11887 multiplyLeft(matrix) { 11888 let t = this.temp; 11889 let v = this.values; 11890 let m = matrix.values; 11891 t[M00] = m[M00] * v[M00] + m[M01] * v[M10] + m[M02] * v[M20] + m[M03] * v[M30]; 11892 t[M01] = m[M00] * v[M01] + m[M01] * v[M11] + m[M02] * v[M21] + m[M03] * v[M31]; 11893 t[M02] = m[M00] * v[M02] + m[M01] * v[M12] + m[M02] * v[M22] + m[M03] * v[M32]; 11894 t[M03] = m[M00] * v[M03] + m[M01] * v[M13] + m[M02] * v[M23] + m[M03] * v[M33]; 11895 t[M10] = m[M10] * v[M00] + m[M11] * v[M10] + m[M12] * v[M20] + m[M13] * v[M30]; 11896 t[M11] = m[M10] * v[M01] + m[M11] * v[M11] + m[M12] * v[M21] + m[M13] * v[M31]; 11897 t[M12] = m[M10] * v[M02] + m[M11] * v[M12] + m[M12] * v[M22] + m[M13] * v[M32]; 11898 t[M13] = m[M10] * v[M03] + m[M11] * v[M13] + m[M12] * v[M23] + m[M13] * v[M33]; 11899 t[M20] = m[M20] * v[M00] + m[M21] * v[M10] + m[M22] * v[M20] + m[M23] * v[M30]; 11900 t[M21] = m[M20] * v[M01] + m[M21] * v[M11] + m[M22] * v[M21] + m[M23] * v[M31]; 11901 t[M22] = m[M20] * v[M02] + m[M21] * v[M12] + m[M22] * v[M22] + m[M23] * v[M32]; 11902 t[M23] = m[M20] * v[M03] + m[M21] * v[M13] + m[M22] * v[M23] + m[M23] * v[M33]; 11903 t[M30] = m[M30] * v[M00] + m[M31] * v[M10] + m[M32] * v[M20] + m[M33] * v[M30]; 11904 t[M31] = m[M30] * v[M01] + m[M31] * v[M11] + m[M32] * v[M21] + m[M33] * v[M31]; 11905 t[M32] = m[M30] * v[M02] + m[M31] * v[M12] + m[M32] * v[M22] + m[M33] * v[M32]; 11906 t[M33] = m[M30] * v[M03] + m[M31] * v[M13] + m[M32] * v[M23] + m[M33] * v[M33]; 11907 return this.set(this.temp); 11908 } 11909 lookAt(position, direction, up) { 11910 let xAxis = _Matrix4.xAxis, yAxis = _Matrix4.yAxis, zAxis = _Matrix4.zAxis; 11911 zAxis.setFrom(direction).normalize(); 11912 xAxis.setFrom(direction).normalize(); 11913 xAxis.cross(up).normalize(); 11914 yAxis.setFrom(xAxis).cross(zAxis).normalize(); 11915 this.identity(); 11916 let val = this.values; 11917 val[M00] = xAxis.x; 11918 val[M01] = xAxis.y; 11919 val[M02] = xAxis.z; 11920 val[M10] = yAxis.x; 11921 val[M11] = yAxis.y; 11922 val[M12] = yAxis.z; 11923 val[M20] = -zAxis.x; 11924 val[M21] = -zAxis.y; 11925 val[M22] = -zAxis.z; 11926 _Matrix4.tmpMatrix.identity(); 11927 _Matrix4.tmpMatrix.values[M03] = -position.x; 11928 _Matrix4.tmpMatrix.values[M13] = -position.y; 11929 _Matrix4.tmpMatrix.values[M23] = -position.z; 11930 this.multiply(_Matrix4.tmpMatrix); 11931 return this; 11932 } 11933 }; 11934 11935
vendor: 2,103 bytes, lines 11935-11994
11935// spine-webgl/src/Camera.ts 11936 var OrthoCamera = class { 11937 position = new Vector3(0, 0, 0); 11938 direction = new Vector3(0, 0, -1); 11939 up = new Vector3(0, 1, 0); 11940 near = 0; 11941 far = 100; 11942 zoom = 1; 11943 viewportWidth = 0; 11944 viewportHeight = 0; 11945 projectionView = new Matrix42(); 11946 inverseProjectionView = new Matrix42(); 11947 projection = new Matrix42(); 11948 view = new Matrix42(); 11949 constructor(viewportWidth, viewportHeight) { 11950 this.viewportWidth = viewportWidth; 11951 this.viewportHeight = viewportHeight; 11952 this.update(); 11953 } 11954 update() { 11955 let projection = this.projection; 11956 let view = this.view; 11957 let projectionView = this.projectionView; 11958 let inverseProjectionView = this.inverseProjectionView; 11959 let zoom = this.zoom, viewportWidth = this.viewportWidth, viewportHeight = this.viewportHeight; 11960 projection.ortho( 11961 zoom * (-viewportWidth / 2), 11962 zoom * (viewportWidth / 2), 11963 zoom * (-viewportHeight / 2), 11964 zoom * (viewportHeight / 2), 11965 this.near, 11966 this.far 11967 ); 11968 view.lookAt(this.position, this.direction, this.up); 11969 projectionView.set(projection.values); 11970 projectionView.multiply(view); 11971 inverseProjectionView.set(projectionView.values).invert(); 11972 } 11973 screenToWorld(screenCoords, screenWidth, screenHeight) { 11974 let x = screenCoords.x, y = screenHeight - screenCoords.y - 1; 11975 screenCoords.x = 2 * x / screenWidth - 1; 11976 screenCoords.y = 2 * y / screenHeight - 1; 11977 screenCoords.z = 2 * screenCoords.z - 1; 11978 screenCoords.project(this.inverseProjectionView); 11979 return screenCoords; 11980 } 11981 worldToScreen(worldCoords, screenWidth, screenHeight) { 11982 worldCoords.project(this.projectionView); 11983 worldCoords.x = screenWidth * (worldCoords.x + 1) / 2; 11984 worldCoords.y = screenHeight * (worldCoords.y + 1) / 2; 11985 worldCoords.z = (worldCoords.z + 1) / 2; 11986 return worldCoords; 11987 } 11988 setViewport(viewportWidth, viewportHeight) { 11989 this.viewportWidth = viewportWidth; 11990 this.viewportHeight = viewportHeight; 11991 } 11992 }; 11993 11994
11994// spine-webgl/src/Input.ts 11995 var Input = class { 11996 element; 11997 mouseX = 0; 11998 mouseY = 0; 11999 buttonDown = false; 12000 touch0 = null; 12001 touch1 = null; 12002 initialPinchDistance = 0; 12003 listeners = new Array(); 12004 autoPreventDefault; 12005 // this is needed because browsers sends mousedown-mousemove-mousesup after a touch sequence, unless touch end preventDefault 12006 // but preventing default will result in preventing interaction with the page. 12007 isTouch = false; 12008 callbacks; 12009 constructor(element, autoPreventDefault = true) { 12010 this.element = element; 12011 this.autoPreventDefault = autoPreventDefault; 12012 this.callbacks = this.setupCallbacks(element); 12013 } 12014 setupCallbacks(element) { 12015 const mouseDown = (ev) => { 12016 if (ev instanceof MouseEvent && !this.isTouch) { 12017 let rect = element.getBoundingClientRect(); 12018 this.mouseX = ev.clientX - rect.left; 12019 this.mouseY = ev.clientY - rect.top; 12020 this.buttonDown = true; 12021 this.listeners.map((listener) => { 12022 if (listener.down) listener.down(this.mouseX, this.mouseY, ev); 12023 }); 12024 } 12025 }; 12026 const mouseMove = (ev) => { 12027 if (ev instanceof MouseEvent && !this.isTouch) { 12028 let rect = element.getBoundingClientRect(); 12029 this.mouseX = ev.clientX - rect.left; 12030 this.mouseY = ev.clientY - rect.top; 12031 this.listeners.map((listener) => { 12032 if (this.buttonDown) { 12033 if (listener.dragged) listener.dragged(this.mouseX, this.mouseY, ev); 12034 } else { 12035 if (listener.moved) listener.moved(this.mouseX, this.mouseY, ev); 12036 } 12037 }); 12038 } 12039 }; 12040 const mouseUp = (ev) => { 12041 if (ev instanceof MouseEvent && !this.isTouch) { 12042 let rect = element.getBoundingClientRect(); 12043 this.mouseX = ev.clientX - rect.left; 12044 ; 12045 this.mouseY = ev.clientY - rect.top; 12046 this.buttonDown = false; 12047 this.listeners.map((listener) => { 12048 if (listener.up) listener.up(this.mouseX, this.mouseY, ev); 12049 }); 12050 } 12051 }; 12052 const mouseWheel = (ev) => { 12053 if (this.autoPreventDefault) ev.preventDefault(); 12054 let deltaY = ev.deltaY; 12055 if (ev.deltaMode == WheelEvent.DOM_DELTA_LINE) deltaY *= 8; 12056 if (ev.deltaMode == WheelEvent.DOM_DELTA_PAGE) deltaY *= 24; 12057 this.listeners.map((listener) => { 12058 if (listener.wheel) listener.wheel(ev.deltaY, ev); 12059 }); 12060 }; 12061 const touchStart = (ev) => { 12062 this.isTouch = true; 12063 if (!this.touch0 || !this.touch1) { 12064 var touches = ev.changedTouches; 12065 let nativeTouch = touches.item(0); 12066 if (!nativeTouch) return; 12067 let rect = element.getBoundingClientRect(); 12068 let x = nativeTouch.clientX - rect.left; 12069 let y = nativeTouch.clientY - rect.top; 12070 let touch = new Touch(nativeTouch.identifier, x, y); 12071 this.mouseX = x; 12072 this.mouseY = y; 12073 this.buttonDown = true; 12074 if (!this.touch0) { 12075 this.touch0 = touch; 12076 this.listeners.map((listener) => { 12077 if (listener.down) listener.down(touch.x, touch.y, ev); 12078 }); 12079 } else if (!this.touch1) { 12080 this.touch1 = touch; 12081 let dx = this.touch1.x - this.touch0.x; 12082 let dy = this.touch1.x - this.touch0.x; 12083 this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy); 12084 this.listeners.map((listener) => { 12085 if (listener.zoom) listener.zoom(this.initialPinchDistance, this.initialPinchDistance, ev); 12086 }); 12087 } 12088 } 12089 if (this.autoPreventDefault) ev.preventDefault(); 12090 }; 12091 const touchMove = (ev) => { 12092 this.isTouch = true; 12093 if (this.touch0) { 12094 var touches = ev.changedTouches; 12095 let rect = element.getBoundingClientRect(); 12096 for (var i = 0; i < touches.length; i++) { 12097 var nativeTouch = touches[i]; 12098 let x = nativeTouch.clientX - rect.left; 12099 let y = nativeTouch.clientY - rect.top; 12100 if (this.touch0.identifier === nativeTouch.identifier) { 12101 this.touch0.x = this.mouseX = x; 12102 this.touch0.y = this.mouseY = y; 12103 this.listeners.map((listener) => { 12104 if (listener.dragged) listener.dragged(x, y, ev); 12105 }); 12106 } 12107 if (this.touch1 && this.touch1.identifier === nativeTouch.identifier) { 12108 this.touch1.x = this.mouseX = x; 12109 this.touch1.y = this.mouseY = y; 12110 } 12111 } 12112 if (this.touch0 && this.touch1) { 12113 let dx = this.touch1.x - this.touch0.x; 12114 let dy = this.touch1.x - this.touch0.x; 12115 let distance = Math.sqrt(dx * dx + dy * dy); 12116 this.listeners.map((listener) => { 12117 if (listener.zoom) listener.zoom(this.initialPinchDistance, distance, ev); 12118 }); 12119 } 12120 } 12121 if (this.autoPreventDefault) ev.preventDefault(); 12122 }; 12123 const touchEnd = (ev) => { 12124 this.isTouch = true; 12125 if (this.touch0) { 12126 var touches = ev.changedTouches; 12127 let rect = element.getBoundingClientRect(); 12128 for (var i = 0; i < touches.length; i++) { 12129 var nativeTouch = touches[i]; 12130 let x = nativeTouch.clientX - rect.left; 12131 let y = nativeTouch.clientY - rect.top; 12132 if (this.touch0.identifier === nativeTouch.identifier) { 12133 this.touch0 = null; 12134 this.mouseX = x; 12135 this.mouseY = y; 12136 this.listeners.map((listener) => { 12137 if (listener.up) listener.up(x, y, ev); 12138 }); 12139 if (!this.touch1) { 12140 this.buttonDown = false;
vendor: 2,508 bytes, lines 12141-12208
12141 break; 12142 } else { 12143 this.touch0 = this.touch1; 12144 this.touch1 = null; 12145 this.mouseX = this.touch0.x; 12146 this.mouseX = this.touch0.x; 12147 this.buttonDown = true; 12148 this.listeners.map((listener) => { 12149 if (listener.down) listener.down(this.touch0.x, this.touch0.y, ev); 12150 }); 12151 } 12152 } 12153 if (this.touch1 && this.touch1.identifier) { 12154 this.touch1 = null; 12155 } 12156 } 12157 } 12158 if (this.autoPreventDefault) ev.preventDefault(); 12159 }; 12160 element.addEventListener("mousedown", mouseDown, true); 12161 element.addEventListener("mousemove", mouseMove, true); 12162 element.addEventListener("mouseup", mouseUp, true); 12163 element.addEventListener("wheel", mouseWheel, true); 12164 element.addEventListener("touchstart", touchStart, { passive: false, capture: false }); 12165 element.addEventListener("touchmove", touchMove, { passive: false, capture: false }); 12166 element.addEventListener("touchend", touchEnd, { passive: false, capture: false }); 12167 element.addEventListener("touchcancel", touchEnd); 12168 return { 12169 mouseDown, 12170 mouseMove, 12171 mouseUp, 12172 mouseWheel, 12173 touchStart, 12174 touchMove, 12175 touchEnd 12176 }; 12177 } 12178 dispose() { 12179 const element = this.element; 12180 element.removeEventListener("mousedown", this.callbacks.mouseDown, true); 12181 element.removeEventListener("mousemove", this.callbacks.mouseMove, true); 12182 element.removeEventListener("mouseup", this.callbacks.mouseUp, true); 12183 element.removeEventListener("wheel", this.callbacks.mouseWheel, true); 12184 element.removeEventListener("touchstart", this.callbacks.touchStart, { capture: false }); 12185 element.removeEventListener("touchmove", this.callbacks.touchMove, { capture: false }); 12186 element.removeEventListener("touchend", this.callbacks.touchEnd, { capture: false }); 12187 element.removeEventListener("touchcancel", this.callbacks.touchEnd); 12188 this.listeners.length = 0; 12189 } 12190 addListener(listener) { 12191 this.listeners.push(listener); 12192 } 12193 removeListener(listener) { 12194 let idx = this.listeners.indexOf(listener); 12195 if (idx > -1) { 12196 this.listeners.splice(idx, 1); 12197 } 12198 } 12199 }; 12200 var Touch = class { 12201 constructor(identifier, x, y) { 12202 this.identifier = identifier; 12203 this.x = x; 12204 this.y = y; 12205 } 12206 }; 12207 12208
12208// spine-webgl/src/CameraController.ts 12209 var CameraController = class { 12210 constructor(canvas, camera) { 12211 this.canvas = canvas; 12212 this.camera = camera; 12213 let cameraX = 0, cameraY = 0, cameraZoom = 0; 12214 let mouseX = 0, mouseY = 0; 12215 let lastX = 0, lastY = 0; 12216 let initialZoom = 0; 12217 new Input(canvas).addListener({ 12218 down: (x, y) => { 12219 cameraX = camera.position.x; 12220 cameraY = camera.position.y; 12221 mouseX = lastX = x; 12222 mouseY = lastY = y; 12223 initialZoom = camera.zoom; 12224 }, 12225 dragged: (x, y) => { 12226 let deltaX = x - mouseX; 12227 let deltaY = y - mouseY; 12228 let originWorld = camera.screenToWorld(new Vector3(0, 0), canvas.clientWidth, canvas.clientHeight); 12229 let deltaWorld = camera.screenToWorld(new Vector3(deltaX, deltaY), canvas.clientWidth, canvas.clientHeight).sub(originWorld); 12230 camera.position.set(cameraX - deltaWorld.x, cameraY - deltaWorld.y, 0); 12231 camera.update(); 12232 lastX = x; 12233 lastY = y; 12234 }, 12235 wheel: (delta) => { 12236 let zoomAmount = delta / 200 * camera.zoom; 12237 let newZoom = camera.zoom + zoomAmount; 12238 if (newZoom > 0) { 12239 let x = 0, y = 0; 12240 if (delta < 0) { 12241 x = lastX; 12242 y = lastY; 12243 } else { 12244 let viewCenter = new Vector3(canvas.clientWidth / 2 + 15, canvas.clientHeight / 2); 12245 let mouseToCenterX = lastX - viewCenter.x; 12246 let mouseToCenterY = canvas.clientHeight - 1 - lastY - viewCenter.y; 12247 x = viewCenter.x - mouseToCenterX; 12248 y = canvas.clientHeight - 1 - viewCenter.y + mouseToCenterY; 12249 } 12250 let oldDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight); 12251 camera.zoom = newZoom; 12252 camera.update(); 12253 let newDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight); 12254 camera.position.add(oldDistance.sub(newDistance)); 12255 camera.update(); 12256 } 12257 }, 12258 zoom: (initialDistance, distance) => { 12259 let newZoom = initialDistance / distance; 12260 camera.zoom = initialZoom * newZoom; 12261 }, 12262 up: (x, y) => { 12263 lastX = x; 12264 lastY = y; 12265 }, 12266 moved: (x, y) => { 12267 lastX = x; 12268 lastY = y; 12269 } 12270 }); 12271 } 12272 }; 12273 12274
12274// spine-webgl/src/Shader.ts 12275 var Shader = class _Shader { 12276 constructor(context, vertexShader, fragmentShader) { 12277 this.vertexShader = vertexShader; 12278 this.fragmentShader = fragmentShader; 12279 this.vsSource = vertexShader; 12280 this.fsSource = fragmentShader; 12281 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 12282 this.context.addRestorable(this); 12283 this.compile(); 12284 } 12285 static MVP_MATRIX = "u_projTrans"; 12286 static POSITION = "a_position"; 12287 static COLOR = "a_color"; 12288 static COLOR2 = "a_color2"; 12289 static TEXCOORDS = "a_texCoords"; 12290 static SAMPLER = "u_texture"; 12291 context; 12292 vs = null; 12293 vsSource; 12294 fs = null; 12295 fsSource; 12296 program = null; 12297 tmp2x2 = new Float32Array(2 * 2); 12298 tmp3x3 = new Float32Array(3 * 3); 12299 tmp4x4 = new Float32Array(4 * 4); 12300 getProgram() { 12301 return this.program; 12302 } 12303 getVertexShader() { 12304 return this.vertexShader; 12305 } 12306 getFragmentShader() { 12307 return this.fragmentShader; 12308 } 12309 getVertexShaderSource() { 12310 return this.vsSource; 12311 } 12312 getFragmentSource() { 12313 return this.fsSource; 12314 } 12315 compile() { 12316 let gl = this.context.gl; 12317 try { 12318 this.vs = this.compileShader(gl.VERTEX_SHADER, this.vertexShader); 12319 if (!this.vs) throw new Error("Couldn't compile vertex shader."); 12320 this.fs = this.compileShader(gl.FRAGMENT_SHADER, this.fragmentShader); 12321 if (!this.fs) throw new Error("Couldn#t compile fragment shader."); 12322 this.program = this.compileProgram(this.vs, this.fs); 12323 } catch (e) { 12324 this.dispose(); 12325 throw e; 12326 } 12327 } 12328 compileShader(type, source) { 12329 let gl = this.context.gl; 12330 let shader = gl.createShader(type); 12331 if (!shader) throw new Error("Couldn't create shader."); 12332 gl.shaderSource(shader, source); 12333 gl.compileShader(shader); 12334 if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { 12335 let error = "Couldn't compile shader: " + gl.getShaderInfoLog(shader); 12336 gl.deleteShader(shader); 12337 if (!gl.isContextLost()) throw new Error(error); 12338 } 12339 return shader; 12340 } 12341 compileProgram(vs, fs) { 12342 let gl = this.context.gl; 12343 let program = gl.createProgram(); 12344 if (!program) throw new Error("Couldn't compile program."); 12345 gl.attachShader(program, vs); 12346 gl.attachShader(program, fs); 12347 gl.linkProgram(program); 12348 if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { 12349 let error = "Couldn't compile shader program: " + gl.getProgramInfoLog(program); 12350 gl.deleteProgram(program); 12351 if (!gl.isContextLost()) throw new Error(error); 12352 } 12353 return program; 12354 } 12355 restore() { 12356 this.compile(); 12357 } 12358 bind() { 12359 this.context.gl.useProgram(this.program); 12360 } 12361 unbind() { 12362 this.context.gl.useProgram(null); 12363 } 12364 setUniformi(uniform, value) { 12365 this.context.gl.uniform1i(this.getUniformLocation(uniform), value); 12366 } 12367 setUniformf(uniform, value) { 12368 this.context.gl.uniform1f(this.getUniformLocation(uniform), value); 12369 } 12370 setUniform2f(uniform, value, value2) { 12371 this.context.gl.uniform2f(this.getUniformLocation(uniform), value, value2); 12372 } 12373 setUniform3f(uniform, value, value2, value3) { 12374 this.context.gl.uniform3f(this.getUniformLocation(uniform), value, value2, value3); 12375 } 12376 setUniform4f(uniform, value, value2, value3, value4) { 12377 this.context.gl.uniform4f(this.getUniformLocation(uniform), value, value2, value3, value4); 12378 } 12379 setUniform2x2f(uniform, value) { 12380 let gl = this.context.gl; 12381 this.tmp2x2.set(value); 12382 gl.uniformMatrix2fv(this.getUniformLocation(uniform), false, this.tmp2x2); 12383 } 12384 setUniform3x3f(uniform, value) { 12385 let gl = this.context.gl; 12386 this.tmp3x3.set(value); 12387 gl.uniformMatrix3fv(this.getUniformLocation(uniform), false, this.tmp3x3); 12388 } 12389 setUniform4x4f(uniform, value) { 12390 let gl = this.context.gl; 12391 this.tmp4x4.set(value); 12392 gl.uniformMatrix4fv(this.getUniformLocation(uniform), false, this.tmp4x4); 12393 } 12394 getUniformLocation(uniform) { 12395 let gl = this.context.gl; 12396 if (!this.program) throw new Error("Shader not compiled."); 12397 let location = gl.getUniformLocation(this.program, uniform); 12398 if (!location && !gl.isContextLost()) throw new Error(`Couldn't find location for uniform ${uniform}`); 12399 return location; 12400 } 12401 getAttributeLocation(attribute) { 12402 let gl = this.context.gl; 12403 if (!this.program) throw new Error("Shader not compiled."); 12404 let location = gl.getAttribLocation(this.program, attribute); 12405 if (location == -1 && !gl.isContextLost()) throw new Error(`Couldn't find location for attribute ${attribute}`); 12406 return location; 12407 } 12408 dispose() { 12409 this.context.removeRestorable(this); 12410 let gl = this.context.gl; 12411 if (this.vs) { 12412 gl.deleteShader(this.vs); 12413 this.vs = null; 12414 } 12415 if (this.fs) { 12416 gl.deleteShader(this.fs); 12417 this.fs = null; 12418 } 12419 if (this.program) { 12420 gl.deleteProgram(this.program); 12421 this.program = null; 12422 } 12423 } 12424 static newColoredTextured(context) { 12425 let vs = ` 12426attribute vec4 ${_Shader.POSITION}; 12427attribute vec4 ${_Shader.COLOR}; 12428attribute vec2 ${_Shader.TEXCOORDS}; 12429uniform mat4 ${_Shader.MVP_MATRIX}; 12430varying vec4 v_color; 12431varying vec2 v_texCoords; 12432 12433void main () { 12434 v_color = ${_Shader.COLOR}; 12435 v_texCoords = ${_Shader.TEXCOORDS}; 12436 gl_Position = ${_Shader.MVP_MATRIX} * ${_Shader.POSITION}; 12437} 12438`; 12439 let fs = ` 12440#ifdef GL_ES 12441 #define LOWP lowp 12442 precision mediump float; 12443#else 12444 #define LOWP 12445#endif 12446varying LOWP vec4 v_color; 12447varying vec2 v_texCoords; 12448uniform sampler2D u_texture; 12449 12450void main () { 12451 gl_FragColor = v_color * texture2D(u_texture, v_texCoords); 12452} 12453`; 12454 return new _Shader(context, vs, fs); 12455 } 12456 static newTwoColoredTextured(context) { 12457 let vs = ` 12458attribute vec4 ${_Shader.POSITION}; 12459attribute vec4 ${_Shader.COLOR}; 12460attribute vec4 ${_Shader.COLOR2}; 12461attribute vec2 ${_Shader.TEXCOORDS}; 12462uniform mat4 ${_Shader.MVP_MATRIX}; 12463varying vec4 v_light; 12464varying vec4 v_dark; 12465varying vec2 v_texCoords; 12466 12467void main () { 12468 v_light = ${_Shader.COLOR}; 12469 v_dark = ${_Shader.COLOR2}; 12470 v_texCoords = ${_Shader.TEXCOORDS}; 12471 gl_Position = ${_Shader.MVP_MATRIX} * ${_Shader.POSITION}; 12472} 12473`; 12474 let fs = ` 12475#ifdef GL_ES 12476 #define LOWP lowp 12477 precision mediump float; 12478#else 12479 #define LOWP 12480#endif 12481varying LOWP vec4 v_light; 12482varying LOWP vec4 v_dark; 12483varying vec2 v_texCoords; 12484uniform sampler2D u_texture; 12485 12486void main () { 12487 vec4 texColor = texture2D(u_texture, v_texCoords); 12488 gl_FragColor.a = texColor.a * v_light.a; 12489 gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb; 12490} 12491`; 12492 return new _Shader(context, vs, fs); 12493 } 12494 static newColored(context) { 12495 let vs = ` 12496attribute vec4 ${_Shader.POSITION}; 12497attribute vec4 ${_Shader.COLOR}; 12498uniform mat4 ${_Shader.MVP_MATRIX}; 12499varying vec4 v_color; 12500 12501void main () { 12502 v_color = ${_Shader.COLOR}; 12503 gl_Position = ${_Shader.MVP_MATRIX} * ${_Shader.POSITION}; 12504} 12505`; 12506 let fs = ` 12507#ifdef GL_ES 12508 #define LOWP lowp 12509 precision mediump float; 12510#else 12511 #define LOWP 12512#endif 12513varying LOWP vec4 v_color; 12514 12515void main () { 12516 gl_FragColor = v_color; 12517} 12518`; 12519 return new _Shader(context, vs, fs); 12520 } 12521 }; 12522 12523
vendor: 4,229 bytes, lines 12523-12640
12523// spine-webgl/src/Mesh.ts 12524 var Mesh = class { 12525 constructor(context, attributes, maxVertices, maxIndices) { 12526 this.attributes = attributes; 12527 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 12528 this.elementsPerVertex = 0; 12529 for (let i = 0; i < attributes.length; i++) { 12530 this.elementsPerVertex += attributes[i].numElements; 12531 } 12532 this.vertices = new Float32Array(maxVertices * this.elementsPerVertex); 12533 this.indices = new Uint16Array(maxIndices); 12534 this.context.addRestorable(this); 12535 } 12536 context; 12537 vertices; 12538 verticesBuffer = null; 12539 verticesLength = 0; 12540 dirtyVertices = false; 12541 indices; 12542 indicesBuffer = null; 12543 indicesLength = 0; 12544 dirtyIndices = false; 12545 elementsPerVertex = 0; 12546 getAttributes() { 12547 return this.attributes; 12548 } 12549 maxVertices() { 12550 return this.vertices.length / this.elementsPerVertex; 12551 } 12552 numVertices() { 12553 return this.verticesLength / this.elementsPerVertex; 12554 } 12555 setVerticesLength(length) { 12556 this.dirtyVertices = true; 12557 this.verticesLength = length; 12558 } 12559 getVertices() { 12560 return this.vertices; 12561 } 12562 maxIndices() { 12563 return this.indices.length; 12564 } 12565 numIndices() { 12566 return this.indicesLength; 12567 } 12568 setIndicesLength(length) { 12569 this.dirtyIndices = true; 12570 this.indicesLength = length; 12571 } 12572 getIndices() { 12573 return this.indices; 12574 } 12575 getVertexSizeInFloats() { 12576 let size = 0; 12577 for (var i = 0; i < this.attributes.length; i++) { 12578 let attribute = this.attributes[i]; 12579 size += attribute.numElements; 12580 } 12581 return size; 12582 } 12583 setVertices(vertices) { 12584 this.dirtyVertices = true; 12585 if (vertices.length > this.vertices.length) throw Error("Mesh can't store more than " + this.maxVertices() + " vertices"); 12586 this.vertices.set(vertices, 0); 12587 this.verticesLength = vertices.length; 12588 } 12589 setIndices(indices) { 12590 this.dirtyIndices = true; 12591 if (indices.length > this.indices.length) throw Error("Mesh can't store more than " + this.maxIndices() + " indices"); 12592 this.indices.set(indices, 0); 12593 this.indicesLength = indices.length; 12594 } 12595 draw(shader, primitiveType) { 12596 this.drawWithOffset(shader, primitiveType, 0, this.indicesLength > 0 ? this.indicesLength : this.verticesLength / this.elementsPerVertex); 12597 } 12598 drawWithOffset(shader, primitiveType, offset, count) { 12599 let gl = this.context.gl; 12600 if (this.dirtyVertices || this.dirtyIndices) this.update(); 12601 this.bind(shader); 12602 if (this.indicesLength > 0) { 12603 gl.drawElements(primitiveType, count, gl.UNSIGNED_SHORT, offset * 2); 12604 } else { 12605 gl.drawArrays(primitiveType, offset, count); 12606 } 12607 this.unbind(shader); 12608 } 12609 bind(shader) { 12610 let gl = this.context.gl; 12611 gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer); 12612 let offset = 0; 12613 for (let i = 0; i < this.attributes.length; i++) { 12614 let attrib = this.attributes[i]; 12615 let location = shader.getAttributeLocation(attrib.name); 12616 gl.enableVertexAttribArray(location); 12617 gl.vertexAttribPointer(location, attrib.numElements, gl.FLOAT, false, this.elementsPerVertex * 4, offset * 4); 12618 offset += attrib.numElements; 12619 } 12620 if (this.indicesLength > 0) gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer); 12621 } 12622 unbind(shader) { 12623 let gl = this.context.gl; 12624 for (let i = 0; i < this.attributes.length; i++) { 12625 let attrib = this.attributes[i]; 12626 let location = shader.getAttributeLocation(attrib.name); 12627 gl.disableVertexAttribArray(location); 12628 } 12629 gl.bindBuffer(gl.ARRAY_BUFFER, null); 12630 if (this.indicesLength > 0) gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); 12631 } 12632 update() { 12633 let gl = this.context.gl; 12634 if (this.dirtyVertices) { 12635 if (!this.verticesBuffer) { 12636 this.verticesBuffer = gl.createBuffer(); 12637 } 12638 gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer); 12639 gl.bufferData(gl.ARRAY_BUFFER, this.vertices.subarray(0, this.verticesLength), gl.DYNAMIC_DRAW); 12640 this.dirtyVertices = false;
12641 } 12642 if (this.dirtyIndices) { 12643 if (!this.indicesBuffer) { 12644 this.indicesBuffer = gl.createBuffer(); 12645 } 12646 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer); 12647 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices.subarray(0, this.indicesLength), gl.DYNAMIC_DRAW); 12648 this.dirtyIndices = false; 12649 } 12650 } 12651 restore() { 12652 this.verticesBuffer = null; 12653 this.indicesBuffer = null; 12654 this.update(); 12655 } 12656 dispose() { 12657 this.context.removeRestorable(this); 12658 let gl = this.context.gl; 12659 gl.deleteBuffer(this.verticesBuffer); 12660 gl.deleteBuffer(this.indicesBuffer); 12661 } 12662 }; 12663 var VertexAttribute = class { 12664 constructor(name, type, numElements) { 12665 this.name = name; 12666 this.type = type; 12667 this.numElements = numElements; 12668 } 12669 }; 12670 var Position2Attribute = class extends VertexAttribute { 12671 constructor() { 12672 super(Shader.POSITION, 0 /* Float */, 2); 12673 } 12674 }; 12675 var Position3Attribute = class extends VertexAttribute { 12676 constructor() { 12677 super(Shader.POSITION, 0 /* Float */, 3); 12678 } 12679 }; 12680 var TexCoordAttribute = class extends VertexAttribute { 12681 constructor(unit = 0) { 12682 super(Shader.TEXCOORDS + (unit == 0 ? "" : unit), 0 /* Float */, 2); 12683 } 12684 }; 12685 var ColorAttribute = class extends VertexAttribute { 12686 constructor() { 12687 super(Shader.COLOR, 0 /* Float */, 4); 12688 } 12689 }; 12690 var Color2Attribute = class extends VertexAttribute { 12691 constructor() { 12692 super(Shader.COLOR2, 0 /* Float */, 4); 12693 } 12694 }; 12695 var VertexAttributeType = /* @__PURE__ */ ((VertexAttributeType2) => { 12696 VertexAttributeType2[VertexAttributeType2["Float"] = 0] = "Float"; 12697 return VertexAttributeType2; 12698 })(VertexAttributeType || {}); 12699 12700
12700// spine-webgl/src/PolygonBatcher.ts 12701 var GL_ONE = 1; 12702 var GL_ONE_MINUS_SRC_COLOR = 769; 12703 var GL_SRC_ALPHA = 770; 12704 var GL_ONE_MINUS_SRC_ALPHA = 771; 12705 var GL_DST_COLOR = 774; 12706 var PolygonBatcher = class _PolygonBatcher { 12707 static disableCulling = false; 12708 context; 12709 drawCalls = 0; 12710 static globalDrawCalls = 0; 12711 isDrawing = false; 12712 mesh; 12713 shader = null; 12714 lastTexture = null; 12715 verticesLength = 0; 12716 indicesLength = 0; 12717 srcColorBlend; 12718 srcAlphaBlend; 12719 dstBlend; 12720 cullWasEnabled = false; 12721 constructor(context, twoColorTint = true, maxVertices = 10920) { 12722 if (maxVertices > 10920) throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices); 12723 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 12724 let attributes = twoColorTint ? [new Position2Attribute(), new ColorAttribute(), new TexCoordAttribute(), new Color2Attribute()] : [new Position2Attribute(), new ColorAttribute(), new TexCoordAttribute()]; 12725 this.mesh = new Mesh(context, attributes, maxVertices, maxVertices * 3); 12726 let gl = this.context.gl; 12727 this.srcColorBlend = gl.SRC_ALPHA; 12728 this.srcAlphaBlend = gl.ONE; 12729 this.dstBlend = gl.ONE_MINUS_SRC_ALPHA; 12730 } 12731 begin(shader) { 12732 if (this.isDrawing) throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()"); 12733 this.drawCalls = 0; 12734 this.shader = shader; 12735 this.lastTexture = null; 12736 this.isDrawing = true; 12737 let gl = this.context.gl; 12738 gl.enable(gl.BLEND); 12739 gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend); 12740 if (_PolygonBatcher.disableCulling) { 12741 this.cullWasEnabled = gl.isEnabled(gl.CULL_FACE); 12742 if (this.cullWasEnabled) gl.disable(gl.CULL_FACE); 12743 } 12744 } 12745 static blendModesGL = [ 12746 { srcRgb: GL_SRC_ALPHA, srcRgbPma: GL_ONE, dstRgb: GL_ONE_MINUS_SRC_ALPHA, srcAlpha: GL_ONE }, 12747 { srcRgb: GL_SRC_ALPHA, srcRgbPma: GL_ONE, dstRgb: GL_ONE, srcAlpha: GL_ONE }, 12748 { srcRgb: GL_DST_COLOR, srcRgbPma: GL_DST_COLOR, dstRgb: GL_ONE_MINUS_SRC_ALPHA, srcAlpha: GL_ONE }, 12749 { srcRgb: GL_ONE, srcRgbPma: GL_ONE, dstRgb: GL_ONE_MINUS_SRC_COLOR, srcAlpha: GL_ONE } 12750 ]; 12751 setBlendMode(blendMode, premultipliedAlpha) { 12752 const blendModeGL = _PolygonBatcher.blendModesGL[blendMode]; 12753 const srcColorBlend = premultipliedAlpha ? blendModeGL.srcRgbPma : blendModeGL.srcRgb; 12754 const srcAlphaBlend = blendModeGL.srcAlpha; 12755 const dstBlend = blendModeGL.dstRgb; 12756 if (this.srcColorBlend == srcColorBlend && this.srcAlphaBlend == srcAlphaBlend && this.dstBlend == dstBlend) return; 12757 this.srcColorBlend = srcColorBlend; 12758 this.srcAlphaBlend = srcAlphaBlend; 12759 this.dstBlend = dstBlend; 12760 if (this.isDrawing) { 12761 this.flush(); 12762 } 12763 let gl = this.context.gl; 12764 gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend); 12765 } 12766 draw(texture, vertices, indices) { 12767 if (texture != this.lastTexture) { 12768 this.flush(); 12769 this.lastTexture = texture; 12770 } else if (this.verticesLength + vertices.length > this.mesh.getVertices().length || this.indicesLength + indices.length > this.mesh.getIndices().length) { 12771 this.flush(); 12772 } 12773 let indexStart = this.mesh.numVertices(); 12774 this.mesh.getVertices().set(vertices, this.verticesLength); 12775 this.verticesLength += vertices.length; 12776 this.mesh.setVerticesLength(this.verticesLength); 12777 let indicesArray = this.mesh.getIndices(); 12778 for (let i = this.indicesLength, j = 0; j < indices.length; i++, j++) 12779 indicesArray[i] = indices[j] + indexStart; 12780 this.indicesLength += indices.length; 12781 this.mesh.setIndicesLength(this.indicesLength); 12782 } 12783 flush() { 12784 if (this.verticesLength == 0) return; 12785 if (!this.lastTexture) throw new Error("No texture set."); 12786 if (!this.shader) throw new Error("No shader set."); 12787 this.lastTexture.bind(); 12788 this.mesh.draw(this.shader, this.context.gl.TRIANGLES); 12789 this.verticesLength = 0; 12790 this.indicesLength = 0; 12791 this.mesh.setVerticesLength(0); 12792 this.mesh.setIndicesLength(0); 12793 this.drawCalls++; 12794 _PolygonBatcher.globalDrawCalls++; 12795 } 12796 end() { 12797 if (!this.isDrawing) throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()"); 12798 if (this.verticesLength > 0 || this.indicesLength > 0) this.flush(); 12799 this.shader = null; 12800 this.lastTexture = null; 12801 this.isDrawing = false;
12802 let gl = this.context.gl; 12803 gl.disable(gl.BLEND); 12804 if (_PolygonBatcher.disableCulling) { 12805 if (this.cullWasEnabled) gl.enable(gl.CULL_FACE); 12806 } 12807 } 12808 getDrawCalls() { 12809 return this.drawCalls; 12810 } 12811 static getAndResetGlobalDrawCalls() { 12812 let result = _PolygonBatcher.globalDrawCalls; 12813 _PolygonBatcher.globalDrawCalls = 0; 12814 return result; 12815 } 12816 dispose() { 12817 this.mesh.dispose(); 12818 } 12819 }; 12820 12821
12821// spine-webgl/src/ShapeRenderer.ts 12822 var ShapeRenderer = class { 12823 context; 12824 isDrawing = false; 12825 mesh; 12826 shapeType = 4 /* Filled */; 12827 color = new Color(1, 1, 1, 1); 12828 shader = null; 12829 vertexIndex = 0; 12830 tmp = new Vector2(); 12831 srcColorBlend; 12832 srcAlphaBlend; 12833 dstBlend; 12834 constructor(context, maxVertices = 10920) { 12835 if (maxVertices > 10920) throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices); 12836 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 12837 this.mesh = new Mesh(context, [new Position2Attribute(), new ColorAttribute()], maxVertices, 0); 12838 let gl = this.context.gl; 12839 this.srcColorBlend = gl.SRC_ALPHA; 12840 this.srcAlphaBlend = gl.ONE; 12841 this.dstBlend = gl.ONE_MINUS_SRC_ALPHA; 12842 } 12843 begin(shader) { 12844 if (this.isDrawing) throw new Error("ShapeRenderer.begin() has already been called"); 12845 this.shader = shader; 12846 this.vertexIndex = 0; 12847 this.isDrawing = true; 12848 let gl = this.context.gl; 12849 gl.enable(gl.BLEND); 12850 gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend); 12851 } 12852 setBlendMode(srcColorBlend, srcAlphaBlend, dstBlend) { 12853 this.srcColorBlend = srcColorBlend; 12854 this.srcAlphaBlend = srcAlphaBlend; 12855 this.dstBlend = dstBlend; 12856 if (this.isDrawing) { 12857 this.flush(); 12858 let gl = this.context.gl; 12859 gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend); 12860 } 12861 } 12862 setColor(color) { 12863 this.color.setFromColor(color); 12864 } 12865 setColorWith(r, g, b, a) { 12866 this.color.set(r, g, b, a); 12867 } 12868 point(x, y, color) { 12869 this.check(0 /* Point */, 1); 12870 if (!color) color = this.color; 12871 this.vertex(x, y, color); 12872 } 12873 line(x, y, x2, y2, color) { 12874 this.check(1 /* Line */, 2); 12875 let vertices = this.mesh.getVertices(); 12876 let idx = this.vertexIndex; 12877 if (!color) color = this.color; 12878 this.vertex(x, y, color); 12879 this.vertex(x2, y2, color); 12880 } 12881 triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3) { 12882 this.check(filled ? 4 /* Filled */ : 1 /* Line */, 3); 12883 let vertices = this.mesh.getVertices(); 12884 let idx = this.vertexIndex; 12885 if (!color) color = this.color; 12886 if (!color2) color2 = this.color; 12887 if (!color3) color3 = this.color; 12888 if (filled) { 12889 this.vertex(x, y, color); 12890 this.vertex(x2, y2, color2); 12891 this.vertex(x3, y3, color3); 12892 } else { 12893 this.vertex(x, y, color); 12894 this.vertex(x2, y2, color2); 12895 this.vertex(x2, y2, color); 12896 this.vertex(x3, y3, color2); 12897 this.vertex(x3, y3, color); 12898 this.vertex(x, y, color2); 12899 } 12900 } 12901 quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) { 12902 this.check(filled ? 4 /* Filled */ : 1 /* Line */, 3); 12903 let vertices = this.mesh.getVertices(); 12904 let idx = this.vertexIndex; 12905 if (!color) color = this.color; 12906 if (!color2) color2 = this.color; 12907 if (!color3) color3 = this.color; 12908 if (!color4) color4 = this.color; 12909 if (filled) { 12910 this.vertex(x, y, color); 12911 this.vertex(x2, y2, color2); 12912 this.vertex(x3, y3, color3); 12913 this.vertex(x3, y3, color3); 12914 this.vertex(x4, y4, color4); 12915 this.vertex(x, y, color); 12916 } else { 12917 this.vertex(x, y, color); 12918 this.vertex(x2, y2, color2); 12919 this.vertex(x2, y2, color2); 12920 this.vertex(x3, y3, color3); 12921 this.vertex(x3, y3, color3); 12922 this.vertex(x4, y4, color4); 12923 this.vertex(x4, y4, color4); 12924 this.vertex(x, y, color); 12925 } 12926 } 12927 rect(filled, x, y, width, height, color) { 12928 this.quad(filled, x, y, x + width, y, x + width, y + height, x, y + height, color, color, color, color); 12929 } 12930 rectLine(filled, x1, y1, x2, y2, width, color) { 12931 this.check(filled ? 4 /* Filled */ : 1 /* Line */, 8); 12932 if (!color) color = this.color; 12933 let t = this.tmp.set(y2 - y1, x1 - x2); 12934 t.normalize(); 12935 width *= 0.5; 12936 let tx = t.x * width; 12937 let ty = t.y * width; 12938 if (!filled) { 12939 this.vertex(x1 + tx, y1 + ty, color); 12940 this.vertex(x1 - tx, y1 - ty, color); 12941 this.vertex(x2 + tx, y2 + ty, color); 12942 this.vertex(x2 - tx, y2 - ty, color); 12943 this.vertex(x2 + tx, y2 + ty, color); 12944 this.vertex(x1 + tx, y1 + ty, color); 12945 this.vertex(x2 - tx, y2 - ty, color); 12946 this.vertex(x1 - tx, y1 - ty, color); 12947 } else { 12948 this.vertex(x1 + tx, y1 + ty, color); 12949 this.vertex(x1 - tx, y1 - ty, color); 12950 this.vertex(x2 + tx, y2 + ty, color); 12951 this.vertex(x2 - tx, y2 - ty, color); 12952 this.vertex(x2 + tx, y2 + ty, color); 12953 this.vertex(x1 - tx, y1 - ty, color); 12954 } 12955 } 12956 x(x, y, size) { 12957 this.line(x - size, y - size, x + size, y + size); 12958 this.line(x - size, y + size, x + size, y - size); 12959 } 12960 polygon(polygonVertices, offset, count, color) { 12961 if (count < 3) throw new Error("Polygon must contain at least 3 vertices"); 12962 this.check(1 /* Line */, count * 2); 12963 if (!color) color = this.color; 12964 let vertices = this.mesh.getVertices(); 12965 let idx = this.vertexIndex; 12966 offset <<= 1; 12967 count <<= 1; 12968 let firstX = polygonVertices[offset]; 12969 let firstY = polygonVertices[offset + 1]; 12970 let last = offset + count; 12971 for (let i = offset, n = offset + count - 2; i < n; i += 2) { 12972 let x1 = polygonVertices[i]; 12973 let y1 = polygonVertices[i + 1]; 12974 let x2 = 0; 12975 let y2 = 0; 12976 if (i + 2 >= last) { 12977 x2 = firstX; 12978 y2 = firstY; 12979 } else { 12980 x2 = polygonVertices[i + 2]; 12981 y2 = polygonVertices[i + 3]; 12982 } 12983 this.vertex(x1, y1, color); 12984 this.vertex(x2, y2, color); 12985 } 12986 } 12987 circle(filled, x, y, radius, color, segments = 0) { 12988 if (segments == 0) segments = Math.max(1, 6 * MathUtils.cbrt(radius) | 0); 12989 if (segments <= 0) throw new Error("segments must be > 0."); 12990 if (!color) color = this.color; 12991 let angle = 2 * MathUtils.PI / segments; 12992 let cos = Math.cos(angle); 12993 let sin = Math.sin(angle);
12994 let cx = radius, cy = 0; 12995 if (!filled) { 12996 this.check(1 /* Line */, segments * 2 + 2); 12997 for (let i = 0; i < segments; i++) { 12998 this.vertex(x + cx, y + cy, color); 12999 let temp2 = cx; 13000 cx = cos * cx - sin * cy; 13001 cy = sin * temp2 + cos * cy; 13002 this.vertex(x + cx, y + cy, color); 13003 } 13004 this.vertex(x + cx, y + cy, color); 13005 } else { 13006 this.check(4 /* Filled */, segments * 3 + 3); 13007 segments--; 13008 for (let i = 0; i < segments; i++) { 13009 this.vertex(x, y, color); 13010 this.vertex(x + cx, y + cy, color); 13011 let temp2 = cx; 13012 cx = cos * cx - sin * cy; 13013 cy = sin * temp2 + cos * cy; 13014 this.vertex(x + cx, y + cy, color); 13015 } 13016 this.vertex(x, y, color); 13017 this.vertex(x + cx, y + cy, color); 13018 } 13019 let temp = cx; 13020 cx = radius; 13021 cy = 0; 13022 this.vertex(x + cx, y + cy, color); 13023 } 13024 curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) { 13025 this.check(1 /* Line */, segments * 2 + 2); 13026 if (!color) color = this.color; 13027 let subdiv_step = 1 / segments; 13028 let subdiv_step2 = subdiv_step * subdiv_step; 13029 let subdiv_step3 = subdiv_step * subdiv_step * subdiv_step; 13030 let pre1 = 3 * subdiv_step; 13031 let pre2 = 3 * subdiv_step2; 13032 let pre4 = 6 * subdiv_step2; 13033 let pre5 = 6 * subdiv_step3; 13034 let tmp1x = x1 - cx1 * 2 + cx2; 13035 let tmp1y = y1 - cy1 * 2 + cy2; 13036 let tmp2x = (cx1 - cx2) * 3 - x1 + x2; 13037 let tmp2y = (cy1 - cy2) * 3 - y1 + y2; 13038 let fx = x1; 13039 let fy = y1; 13040 let dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; 13041 let dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; 13042 let ddfx = tmp1x * pre4 + tmp2x * pre5; 13043 let ddfy = tmp1y * pre4 + tmp2y * pre5; 13044 let dddfx = tmp2x * pre5; 13045 let dddfy = tmp2y * pre5; 13046 while (segments-- > 0) { 13047 this.vertex(fx, fy, color); 13048 fx += dfx; 13049 fy += dfy; 13050 dfx += ddfx; 13051 dfy += ddfy; 13052 ddfx += dddfx; 13053 ddfy += dddfy; 13054 this.vertex(fx, fy, color); 13055 } 13056 this.vertex(fx, fy, color); 13057 this.vertex(x2, y2, color); 13058 } 13059 vertex(x, y, color) { 13060 let idx = this.vertexIndex; 13061 let vertices = this.mesh.getVertices(); 13062 vertices[idx++] = x; 13063 vertices[idx++] = y; 13064 vertices[idx++] = color.r; 13065 vertices[idx++] = color.g; 13066 vertices[idx++] = color.b; 13067 vertices[idx++] = color.a; 13068 this.vertexIndex = idx; 13069 } 13070 end() { 13071 if (!this.isDrawing) throw new Error("ShapeRenderer.begin() has not been called"); 13072 this.flush(); 13073 let gl = this.context.gl; 13074 gl.disable(gl.BLEND); 13075 this.isDrawing = false; 13076 } 13077 flush() { 13078 if (this.vertexIndex == 0) return; 13079 if (!this.shader) throw new Error("No shader set."); 13080 this.mesh.setVerticesLength(this.vertexIndex); 13081 this.mesh.draw(this.shader, this.shapeType); 13082 this.vertexIndex = 0; 13083 } 13084 check(shapeType, numVertices) { 13085 if (!this.isDrawing) throw new Error("ShapeRenderer.begin() has not been called"); 13086 if (this.shapeType == shapeType) { 13087 if (this.mesh.maxVertices() - this.mesh.numVertices() < numVertices) this.flush(); 13088 else return; 13089 } else { 13090 this.flush(); 13091 this.shapeType = shapeType; 13092 } 13093 } 13094 dispose() { 13095 this.mesh.dispose(); 13096 } 13097 }; 13098 var ShapeType = /* @__PURE__ */ ((ShapeType2) => { 13099 ShapeType2[ShapeType2["Point"] = 0] = "Point"; 13100 ShapeType2[ShapeType2["Line"] = 1] = "Line"; 13101 ShapeType2[ShapeType2["Filled"] = 4] = "Filled"; 13102 return ShapeType2; 13103 })(ShapeType || {}); 13104 13105
13105// spine-webgl/src/SkeletonDebugRenderer.ts 13106 var SkeletonDebugRenderer = class _SkeletonDebugRenderer { 13107 boneLineColor = new Color(1, 0, 0, 1); 13108 boneOriginColor = new Color(0, 1, 0, 1); 13109 attachmentLineColor = new Color(0, 0, 1, 0.5); 13110 triangleLineColor = new Color(1, 0.64, 0, 0.5); 13111 pathColor = new Color().setFromString("FF7F00"); 13112 clipColor = new Color(0.8, 0, 0, 2); 13113 aabbColor = new Color(0, 1, 0, 0.5); 13114 drawBones = true; 13115 drawRegionAttachments = true; 13116 drawBoundingBoxes = true; 13117 drawMeshHull = true; 13118 drawMeshTriangles = true; 13119 drawPaths = true; 13120 drawSkeletonXY = false; 13121 drawClipping = true; 13122 premultipliedAlpha = false; 13123 scale = 1; 13124 boneWidth = 2; 13125 context; 13126 bounds = new SkeletonBounds(); 13127 temp = new Array(); 13128 vertices = Utils.newFloatArray(2 * 1024); 13129 static LIGHT_GRAY = new Color(192 / 255, 192 / 255, 192 / 255, 1); 13130 static GREEN = new Color(0, 1, 0, 1); 13131 constructor(context) { 13132 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 13133 } 13134 draw(shapes, skeleton, ignoredBones) { 13135 let skeletonX = skeleton.x; 13136 let skeletonY = skeleton.y; 13137 let gl = this.context.gl; 13138 let srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA; 13139 shapes.setBlendMode(srcFunc, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); 13140 let bones = skeleton.bones; 13141 if (this.drawBones) { 13142 shapes.setColor(this.boneLineColor); 13143 for (let i = 0, n = bones.length; i < n; i++) { 13144 let bone = bones[i]; 13145 if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1) continue; 13146 if (!bone.parent) continue; 13147 let x = bone.data.length * bone.a + bone.worldX; 13148 let y = bone.data.length * bone.c + bone.worldY; 13149 shapes.rectLine(true, bone.worldX, bone.worldY, x, y, this.boneWidth * this.scale); 13150 } 13151 if (this.drawSkeletonXY) shapes.x(skeletonX, skeletonY, 4 * this.scale); 13152 } 13153 if (this.drawRegionAttachments) { 13154 shapes.setColor(this.attachmentLineColor); 13155 let slots = skeleton.slots; 13156 for (let i = 0, n = slots.length; i < n; i++) { 13157 let slot = slots[i]; 13158 let attachment = slot.getAttachment(); 13159 if (attachment instanceof RegionAttachment) { 13160 let regionAttachment = attachment; 13161 let vertices = this.vertices; 13162 regionAttachment.computeWorldVertices(slot, vertices, 0, 2); 13163 shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]); 13164 shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]); 13165 shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]); 13166 shapes.line(vertices[6], vertices[7], vertices[0], vertices[1]); 13167 } 13168 } 13169 } 13170 if (this.drawMeshHull || this.drawMeshTriangles) { 13171 let slots = skeleton.slots; 13172 for (let i = 0, n = slots.length; i < n; i++) { 13173 let slot = slots[i]; 13174 if (!slot.bone.active) continue; 13175 let attachment = slot.getAttachment(); 13176 if (!(attachment instanceof MeshAttachment)) continue; 13177 let mesh = attachment; 13178 let vertices = this.vertices; 13179 mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 2); 13180 let triangles = mesh.triangles; 13181 let hullLength = mesh.hullLength; 13182 if (this.drawMeshTriangles) { 13183 shapes.setColor(this.triangleLineColor); 13184 for (let ii = 0, nn = triangles.length; ii < nn; ii += 3) { 13185 let v1 = triangles[ii] * 2, v2 = triangles[ii + 1] * 2, v3 = triangles[ii + 2] * 2; 13186 shapes.triangle( 13187 false, 13188 vertices[v1], 13189 vertices[v1 + 1], 13190 // 13191 vertices[v2], 13192 vertices[v2 + 1], 13193 // 13194 vertices[v3], 13195 vertices[v3 + 1] 13196 // 13197 ); 13198 } 13199 } 13200 if (this.drawMeshHull && hullLength > 0) { 13201 shapes.setColor(this.attachmentLineColor); 13202 hullLength = (hullLength >> 1) * 2; 13203 let lastX = vertices[hullLength - 2], lastY = vertices[hullLength - 1]; 13204 for (let ii = 0, nn = hullLength; ii < nn; ii += 2) { 13205 let x = vertices[ii], y = vertices[ii + 1]; 13206 shapes.line(x, y, lastX, lastY); 13207 lastX = x; 13208 lastY = y; 13209 } 13210 } 13211 } 13212 } 13213 if (this.drawBoundingBoxes) { 13214 let bounds = this.bounds; 13215 bounds.update(skeleton, true); 13216 shapes.setColor(this.aabbColor); 13217 shapes.rect(false, bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight()); 13218 let polygons = bounds.polygons; 13219 let boxes = bounds.boundingBoxes; 13220 for (let i = 0, n = polygons.length; i < n; i++) { 13221 let polygon = polygons[i]; 13222 shapes.setColor(boxes[i].color); 13223 shapes.polygon(polygon, 0, polygon.length); 13224 } 13225 } 13226 if (this.drawPaths) { 13227 let slots = skeleton.slots; 13228 for (let i = 0, n = slots.length; i < n; i++) { 13229 let slot = slots[i]; 13230 if (!slot.bone.active) continue; 13231 let attachment = slot.getAttachment(); 13232 if (!(attachment instanceof PathAttachment)) continue; 13233 let path = attachment; 13234 let nn = path.worldVerticesLength; 13235 let world = this.temp = Utils.setArraySize(this.temp, nn, 0);
13236 path.computeWorldVertices(slot, 0, nn, world, 0, 2); 13237 let color = this.pathColor; 13238 let x1 = world[2], y1 = world[3], x2 = 0, y2 = 0; 13239 if (path.closed) { 13240 shapes.setColor(color); 13241 let cx1 = world[0], cy1 = world[1], cx2 = world[nn - 2], cy2 = world[nn - 1]; 13242 x2 = world[nn - 4]; 13243 y2 = world[nn - 3]; 13244 shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32); 13245 shapes.setColor(_SkeletonDebugRenderer.LIGHT_GRAY); 13246 shapes.line(x1, y1, cx1, cy1); 13247 shapes.line(x2, y2, cx2, cy2); 13248 } 13249 nn -= 4; 13250 for (let ii = 4; ii < nn; ii += 6) { 13251 let cx1 = world[ii], cy1 = world[ii + 1], cx2 = world[ii + 2], cy2 = world[ii + 3]; 13252 x2 = world[ii + 4]; 13253 y2 = world[ii + 5]; 13254 shapes.setColor(color); 13255 shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32); 13256 shapes.setColor(_SkeletonDebugRenderer.LIGHT_GRAY); 13257 shapes.line(x1, y1, cx1, cy1); 13258 shapes.line(x2, y2, cx2, cy2); 13259 x1 = x2; 13260 y1 = y2; 13261 } 13262 } 13263 } 13264 if (this.drawBones) { 13265 shapes.setColor(this.boneOriginColor); 13266 for (let i = 0, n = bones.length; i < n; i++) { 13267 let bone = bones[i]; 13268 if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1) continue; 13269 shapes.circle(true, bone.worldX, bone.worldY, 3 * this.scale, this.boneOriginColor, 8); 13270 } 13271 } 13272 if (this.drawClipping) { 13273 let slots = skeleton.slots; 13274 shapes.setColor(this.clipColor); 13275 for (let i = 0, n = slots.length; i < n; i++) { 13276 let slot = slots[i]; 13277 if (!slot.bone.active) continue; 13278 let attachment = slot.getAttachment(); 13279 if (!(attachment instanceof ClippingAttachment)) continue; 13280 let clip = attachment; 13281 let nn = clip.worldVerticesLength; 13282 let world = this.temp = Utils.setArraySize(this.temp, nn, 0); 13283 clip.computeWorldVertices(slot, 0, nn, world, 0, 2); 13284 for (let i2 = 0, n2 = world.length; i2 < n2; i2 += 2) { 13285 let x = world[i2]; 13286 let y = world[i2 + 1]; 13287 let x2 = world[(i2 + 2) % world.length]; 13288 let y2 = world[(i2 + 3) % world.length]; 13289 shapes.line(x, y, x2, y2); 13290 } 13291 } 13292 } 13293 } 13294 dispose() { 13295 } 13296 }; 13297 13298
13298// spine-webgl/src/SkeletonRenderer.ts 13299 var Renderable = class { 13300 constructor(vertices, numVertices, numFloats) { 13301 this.vertices = vertices; 13302 this.numVertices = numVertices; 13303 this.numFloats = numFloats; 13304 } 13305 }; 13306 var SkeletonRenderer = class _SkeletonRenderer { 13307 static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; 13308 premultipliedAlpha = false; 13309 tempColor = new Color(); 13310 tempColor2 = new Color(); 13311 vertices; 13312 vertexSize = 2 + 2 + 4; 13313 twoColorTint = false; 13314 renderable = new Renderable([], 0, 0); 13315 clipper = new SkeletonClipping(); 13316 temp = new Vector2(); 13317 temp2 = new Vector2(); 13318 temp3 = new Color(); 13319 temp4 = new Color(); 13320 constructor(context, twoColorTint = true) { 13321 this.twoColorTint = twoColorTint; 13322 if (twoColorTint) 13323 this.vertexSize += 4; 13324 this.vertices = Utils.newFloatArray(this.vertexSize * 1024); 13325 } 13326 draw(batcher, skeleton, slotRangeStart = -1, slotRangeEnd = -1, transformer = null) { 13327 let clipper = this.clipper; 13328 let premultipliedAlpha = this.premultipliedAlpha; 13329 let twoColorTint = this.twoColorTint; 13330 let blendMode = null; 13331 let renderable = this.renderable; 13332 let uvs; 13333 let triangles; 13334 let drawOrder = skeleton.drawOrder; 13335 let attachmentColor; 13336 let skeletonColor = skeleton.color; 13337 let vertexSize = twoColorTint ? 12 : 8; 13338 let inRange = false; 13339 if (slotRangeStart == -1) inRange = true; 13340 for (let i = 0, n = drawOrder.length; i < n; i++) { 13341 let clippedVertexSize = clipper.isClipping() ? 2 : vertexSize; 13342 let slot = drawOrder[i]; 13343 if (!slot.bone.active) { 13344 clipper.clipEndWithSlot(slot); 13345 continue; 13346 } 13347 if (slotRangeStart >= 0 && slotRangeStart == slot.data.index) { 13348 inRange = true; 13349 } 13350 if (!inRange) { 13351 clipper.clipEndWithSlot(slot); 13352 continue; 13353 } 13354 if (slotRangeEnd >= 0 && slotRangeEnd == slot.data.index) { 13355 inRange = false; 13356 } 13357 let attachment = slot.getAttachment(); 13358 let texture; 13359 if (attachment instanceof RegionAttachment) { 13360 let region = attachment; 13361 renderable.vertices = this.vertices; 13362 renderable.numVertices = 4; 13363 renderable.numFloats = clippedVertexSize << 2; 13364 region.computeWorldVertices(slot, renderable.vertices, 0, clippedVertexSize); 13365 triangles = _SkeletonRenderer.QUAD_TRIANGLES; 13366 uvs = region.uvs; 13367 texture = region.region.texture; 13368 attachmentColor = region.color; 13369 } else if (attachment instanceof MeshAttachment) { 13370 let mesh = attachment; 13371 renderable.vertices = this.vertices; 13372 renderable.numVertices = mesh.worldVerticesLength >> 1; 13373 renderable.numFloats = renderable.numVertices * clippedVertexSize; 13374 if (renderable.numFloats > renderable.vertices.length) { 13375 renderable.vertices = this.vertices = Utils.newFloatArray(renderable.numFloats); 13376 } 13377 mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, renderable.vertices, 0, clippedVertexSize); 13378 triangles = mesh.triangles; 13379 texture = mesh.region.texture; 13380 uvs = mesh.uvs; 13381 attachmentColor = mesh.color; 13382 } else if (attachment instanceof ClippingAttachment) { 13383 let clip = attachment; 13384 clipper.clipStart(slot, clip); 13385 continue; 13386 } else { 13387 clipper.clipEndWithSlot(slot); 13388 continue; 13389 } 13390 if (texture) { 13391 let slotColor = slot.color; 13392 let finalColor = this.tempColor; 13393 finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r; 13394 finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g; 13395 finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b; 13396 finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a; 13397 if (premultipliedAlpha) { 13398 finalColor.r *= finalColor.a; 13399 finalColor.g *= finalColor.a; 13400 finalColor.b *= finalColor.a; 13401 } 13402 let darkColor = this.tempColor2;
13403 if (!slot.darkColor) 13404 darkColor.set(0, 0, 0, 1); 13405 else { 13406 if (premultipliedAlpha) { 13407 darkColor.r = slot.darkColor.r * finalColor.a; 13408 darkColor.g = slot.darkColor.g * finalColor.a; 13409 darkColor.b = slot.darkColor.b * finalColor.a; 13410 } else { 13411 darkColor.setFromColor(slot.darkColor); 13412 } 13413 darkColor.a = premultipliedAlpha ? 1 : 0; 13414 } 13415 let slotBlendMode = slot.data.blendMode; 13416 if (slotBlendMode != blendMode) { 13417 blendMode = slotBlendMode; 13418 batcher.setBlendMode(blendMode, premultipliedAlpha); 13419 } 13420 if (clipper.isClipping()) { 13421 clipper.clipTriangles(renderable.vertices, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint); 13422 let clippedVertices = new Float32Array(clipper.clippedVertices); 13423 let clippedTriangles = clipper.clippedTriangles; 13424 if (transformer) transformer(clippedVertices, clippedVertices.length, vertexSize); 13425 batcher.draw(texture, clippedVertices, clippedTriangles); 13426 } else { 13427 let verts = renderable.vertices; 13428 if (!twoColorTint) { 13429 for (let v = 2, u = 0, n2 = renderable.numFloats; v < n2; v += vertexSize, u += 2) { 13430 verts[v] = finalColor.r; 13431 verts[v + 1] = finalColor.g; 13432 verts[v + 2] = finalColor.b; 13433 verts[v + 3] = finalColor.a; 13434 verts[v + 4] = uvs[u]; 13435 verts[v + 5] = uvs[u + 1]; 13436 } 13437 } else { 13438 for (let v = 2, u = 0, n2 = renderable.numFloats; v < n2; v += vertexSize, u += 2) { 13439 verts[v] = finalColor.r; 13440 verts[v + 1] = finalColor.g; 13441 verts[v + 2] = finalColor.b; 13442 verts[v + 3] = finalColor.a; 13443 verts[v + 4] = uvs[u]; 13444 verts[v + 5] = uvs[u + 1]; 13445 verts[v + 6] = darkColor.r; 13446 verts[v + 7] = darkColor.g; 13447 verts[v + 8] = darkColor.b; 13448 verts[v + 9] = darkColor.a; 13449 } 13450 } 13451 let view = renderable.vertices.subarray(0, renderable.numFloats); 13452 if (transformer) transformer(renderable.vertices, renderable.numFloats, vertexSize); 13453 batcher.draw(texture, view, triangles); 13454 } 13455 } 13456 clipper.clipEndWithSlot(slot); 13457 } 13458 clipper.clipEnd(); 13459 } 13460 /** Returns the {@link SkeletonClipping} used by this renderer for use with e.g. {@link Skeleton.getBounds} **/ 13461 getSkeletonClipping() { 13462 return this.clipper; 13463 } 13464 }; 13465 13466
13466// spine-webgl/src/SceneRenderer.ts 13467 var quad = [ 13468 0, 13469 0, 13470 1, 13471 1, 13472 1, 13473 1, 13474 0, 13475 0, 13476 0, 13477 0, 13478 1, 13479 1, 13480 1, 13481 1, 13482 0, 13483 0, 13484 0, 13485 0, 13486 1, 13487 1, 13488 1, 13489 1, 13490 0, 13491 0, 13492 0, 13493 0, 13494 1, 13495 1, 13496 1, 13497 1, 13498 0, 13499 0 13500 ]; 13501 var QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0]; 13502 var WHITE = new Color(1, 1, 1, 1); 13503 var SceneRenderer = class { 13504 context; 13505 canvas; 13506 camera; 13507 batcher; 13508 twoColorTint = false; 13509 batcherShader; 13510 shapes; 13511 shapesShader; 13512 activeRenderer = null; 13513 skeletonRenderer; 13514 skeletonDebugRenderer; 13515 constructor(canvas, context, twoColorTint = true) { 13516 this.canvas = canvas; 13517 this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); 13518 this.twoColorTint = twoColorTint; 13519 this.camera = new OrthoCamera(canvas.width, canvas.height); 13520 this.batcherShader = twoColorTint ? Shader.newTwoColoredTextured(this.context) : Shader.newColoredTextured(this.context); 13521 this.batcher = new PolygonBatcher(this.context, twoColorTint); 13522 this.shapesShader = Shader.newColored(this.context); 13523 this.shapes = new ShapeRenderer(this.context); 13524 this.skeletonRenderer = new SkeletonRenderer(this.context, twoColorTint); 13525 this.skeletonDebugRenderer = new SkeletonDebugRenderer(this.context); 13526 } 13527 dispose() { 13528 this.batcher.dispose(); 13529 this.batcherShader.dispose(); 13530 this.shapes.dispose(); 13531 this.shapesShader.dispose(); 13532 this.skeletonDebugRenderer.dispose(); 13533 } 13534 begin() { 13535 this.camera.update(); 13536 this.enableRenderer(this.batcher); 13537 } 13538 drawSkeleton(skeleton, premultipliedAlpha = false, slotRangeStart = -1, slotRangeEnd = -1, transform = null) { 13539 this.enableRenderer(this.batcher); 13540 this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha; 13541 this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd, transform); 13542 } 13543 drawSkeletonDebug(skeleton, premultipliedAlpha = false, ignoredBones) { 13544 this.enableRenderer(this.shapes); 13545 this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha; 13546 this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones); 13547 } 13548 drawTexture(texture, x, y, width, height, color) { 13549 this.enableRenderer(this.batcher); 13550 if (!color) color = WHITE; 13551 var i = 0; 13552 quad[i++] = x; 13553 quad[i++] = y; 13554 quad[i++] = color.r; 13555 quad[i++] = color.g; 13556 quad[i++] = color.b; 13557 quad[i++] = color.a; 13558 quad[i++] = 0; 13559 quad[i++] = 1; 13560 if (this.twoColorTint) { 13561 quad[i++] = 0; 13562 quad[i++] = 0; 13563 quad[i++] = 0; 13564 quad[i++] = 0; 13565 } 13566 quad[i++] = x + width; 13567 quad[i++] = y; 13568 quad[i++] = color.r; 13569 quad[i++] = color.g; 13570 quad[i++] = color.b; 13571 quad[i++] = color.a; 13572 quad[i++] = 1; 13573 quad[i++] = 1; 13574 if (this.twoColorTint) { 13575 quad[i++] = 0; 13576 quad[i++] = 0; 13577 quad[i++] = 0; 13578 quad[i++] = 0; 13579 } 13580 quad[i++] = x + width; 13581 quad[i++] = y + height; 13582 quad[i++] = color.r; 13583 quad[i++] = color.g; 13584 quad[i++] = color.b; 13585 quad[i++] = color.a; 13586 quad[i++] = 1; 13587 quad[i++] = 0; 13588 if (this.twoColorTint) { 13589 quad[i++] = 0; 13590 quad[i++] = 0; 13591 quad[i++] = 0; 13592 quad[i++] = 0; 13593 } 13594 quad[i++] = x; 13595 quad[i++] = y + height; 13596 quad[i++] = color.r; 13597 quad[i++] = color.g; 13598 quad[i++] = color.b; 13599 quad[i++] = color.a; 13600 quad[i++] = 0; 13601 quad[i++] = 0; 13602 if (this.twoColorTint) { 13603 quad[i++] = 0; 13604 quad[i++] = 0; 13605 quad[i++] = 0; 13606 quad[i] = 0; 13607 } 13608 this.batcher.draw(texture, quad, QUAD_TRIANGLES); 13609 } 13610 drawTextureUV(texture, x, y, width, height, u, v, u2, v2, color) { 13611 this.enableRenderer(this.batcher); 13612 if (!color) color = WHITE; 13613 var i = 0; 13614 quad[i++] = x; 13615 quad[i++] = y; 13616 quad[i++] = color.r; 13617 quad[i++] = color.g; 13618 quad[i++] = color.b; 13619 quad[i++] = color.a; 13620 quad[i++] = u; 13621 quad[i++] = v; 13622 if (this.twoColorTint) { 13623 quad[i++] = 0; 13624 quad[i++] = 0; 13625 quad[i++] = 0; 13626 quad[i++] = 0; 13627 } 13628 quad[i++] = x + width; 13629 quad[i++] = y; 13630 quad[i++] = color.r; 13631 quad[i++] = color.g; 13632 quad[i++] = color.b; 13633 quad[i++] = color.a; 13634 quad[i++] = u2; 13635 quad[i++] = v; 13636 if (this.twoColorTint) { 13637 quad[i++] = 0; 13638 quad[i++] = 0; 13639 quad[i++] = 0; 13640 quad[i++] = 0; 13641 } 13642 quad[i++] = x + width; 13643 quad[i++] = y + height; 13644 quad[i++] = color.r; 13645 quad[i++] = color.g; 13646 quad[i++] = color.b; 13647 quad[i++] = color.a; 13648 quad[i++] = u2; 13649 quad[i++] = v2; 13650 if (this.twoColorTint) { 13651 quad[i++] = 0; 13652 quad[i++] = 0; 13653 quad[i++] = 0; 13654 quad[i++] = 0; 13655 } 13656 quad[i++] = x; 13657 quad[i++] = y + height; 13658 quad[i++] = color.r; 13659 quad[i++] = color.g; 13660 quad[i++] = color.b; 13661 quad[i++] = color.a; 13662 quad[i++] = u; 13663 quad[i++] = v2; 13664 if (this.twoColorTint) { 13665 quad[i++] = 0; 13666 quad[i++] = 0; 13667 quad[i++] = 0; 13668 quad[i] = 0; 13669 } 13670 this.batcher.draw(texture, quad, QUAD_TRIANGLES); 13671 } 13672 drawTextureRotated(texture, x, y, width, height, pivotX, pivotY, angle, color) { 13673 this.enableRenderer(this.batcher); 13674 if (!color) color = WHITE; 13675 let worldOriginX = x + pivotX; 13676 let worldOriginY = y + pivotY; 13677 let fx = -pivotX; 13678 let fy = -pivotY; 13679 let fx2 = width - pivotX; 13680 let fy2 = height - pivotY; 13681 let p1x = fx; 13682 let p1y = fy; 13683 let p2x = fx; 13684 let p2y = fy2; 13685 let p3x = fx2; 13686 let p3y = fy2; 13687 let p4x = fx2; 13688 let p4y = fy; 13689 let x1 = 0; 13690 let y1 = 0; 13691 let x2 = 0; 13692 let y2 = 0; 13693 let x3 = 0; 13694 let y3 = 0; 13695 let x4 = 0; 13696 let y4 = 0; 13697 if (angle != 0) { 13698 let cos = MathUtils.cosDeg(angle); 13699 let sin = MathUtils.sinDeg(angle); 13700 x1 = cos * p1x - sin * p1y; 13701 y1 = sin * p1x + cos * p1y; 13702 x4 = cos * p2x - sin * p2y; 13703 y4 = sin * p2x + cos * p2y; 13704 x3 = cos * p3x - sin * p3y; 13705 y3 = sin * p3x + cos * p3y; 13706 x2 = x3 + (x1 - x4); 13707 y2 = y3 + (y1 - y4); 13708 } else { 13709 x1 = p1x; 13710 y1 = p1y; 13711 x4 = p2x; 13712 y4 = p2y; 13713 x3 = p3x; 13714 y3 = p3y; 13715 x2 = p4x; 13716 y2 = p4y; 13717 } 13718 x1 += worldOriginX; 13719 y1 += worldOriginY; 13720 x2 += worldOriginX; 13721 y2 += worldOriginY; 13722 x3 += worldOriginX; 13723 y3 += worldOriginY; 13724 x4 += worldOriginX; 13725 y4 += worldOriginY; 13726 var i = 0; 13727 quad[i++] = x1; 13728 quad[i++] = y1; 13729 quad[i++] = color.r; 13730 quad[i++] = color.g; 13731 quad[i++] = color.b; 13732 quad[i++] = color.a; 13733 quad[i++] = 0; 13734 quad[i++] = 1; 13735 if (this.twoColorTint) { 13736 quad[i++] = 0; 13737 quad[i++] = 0; 13738 quad[i++] = 0; 13739 quad[i++] = 0; 13740 } 13741 quad[i++] = x2; 13742 quad[i++] = y2; 13743 quad[i++] = color.r; 13744 quad[i++] = color.g; 13745 quad[i++] = color.b; 13746 quad[i++] = color.a; 13747 quad[i++] = 1; 13748 quad[i++] = 1; 13749 if (this.twoColorTint) { 13750 quad[i++] = 0; 13751 quad[i++] = 0; 13752 quad[i++] = 0; 13753 quad[i++] = 0; 13754 } 13755 quad[i++] = x3; 13756 quad[i++] = y3; 13757 quad[i++] = color.r; 13758 quad[i++] = color.g; 13759 quad[i++] = color.b; 13760 quad[i++] = color.a; 13761 quad[i++] = 1; 13762 quad[i++] = 0; 13763 if (this.twoColorTint) { 13764 quad[i++] = 0; 13765 quad[i++] = 0; 13766 quad[i++] = 0; 13767 quad[i++] = 0; 13768 } 13769 quad[i++] = x4; 13770 quad[i++] = y4; 13771 quad[i++] = color.r; 13772 quad[i++] = color.g; 13773 quad[i++] = color.b; 13774 quad[i++] = color.a; 13775 quad[i++] = 0; 13776 quad[i++] = 0; 13777 if (this.twoColorTint) { 13778 quad[i++] = 0; 13779 quad[i++] = 0; 13780 quad[i++] = 0; 13781 quad[i] = 0; 13782 } 13783 this.batcher.draw(texture, quad, QUAD_TRIANGLES); 13784 } 13785 drawRegion(region, x, y, width, height, color) { 13786 this.enableRenderer(this.batcher); 13787 if (!color) color = WHITE; 13788 var i = 0; 13789 quad[i++] = x; 13790 quad[i++] = y; 13791 quad[i++] = color.r; 13792 quad[i++] = color.g; 13793 quad[i++] = color.b; 13794 quad[i++] = color.a; 13795 quad[i++] = region.u; 13796 quad[i++] = region.v2; 13797 if (this.twoColorTint) { 13798 quad[i++] = 0; 13799 quad[i++] = 0; 13800 quad[i++] = 0; 13801 quad[i++] = 0; 13802 } 13803 quad[i++] = x + width; 13804 quad[i++] = y; 13805 quad[i++] = color.r; 13806 quad[i++] = color.g; 13807 quad[i++] = color.b; 13808 quad[i++] = color.a; 13809 quad[i++] = region.u2; 13810 quad[i++] = region.v2; 13811 if (this.twoColorTint) { 13812 quad[i++] = 0; 13813 quad[i++] = 0; 13814 quad[i++] = 0; 13815 quad[i++] = 0; 13816 } 13817 quad[i++] = x + width; 13818 quad[i++] = y + height; 13819 quad[i++] = color.r; 13820 quad[i++] = color.g; 13821 quad[i++] = color.b; 13822 quad[i++] = color.a; 13823 quad[i++] = region.u2; 13824 quad[i++] = region.v; 13825 if (this.twoColorTint) { 13826 quad[i++] = 0; 13827 quad[i++] = 0; 13828 quad[i++] = 0; 13829 quad[i++] = 0; 13830 } 13831 quad[i++] = x; 13832 quad[i++] = y + height; 13833 quad[i++] = color.r; 13834 quad[i++] = color.g; 13835 quad[i++] = color.b; 13836 quad[i++] = color.a; 13837 quad[i++] = region.u; 13838 quad[i++] = region.v; 13839 if (this.twoColorTint) { 13840 quad[i++] = 0; 13841 quad[i++] = 0; 13842 quad[i++] = 0; 13843 quad[i] = 0; 13844 } 13845 this.batcher.draw(region.page.texture, quad, QUAD_TRIANGLES); 13846 } 13847 line(x, y, x2, y2, color, color2) { 13848 this.enableRenderer(this.shapes); 13849 this.shapes.line(x, y, x2, y2, color); 13850 } 13851 triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3) { 13852 this.enableRenderer(this.shapes); 13853 this.shapes.triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3); 13854 } 13855 quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) { 13856 this.enableRenderer(this.shapes); 13857 this.shapes.quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4); 13858 } 13859 rect(filled, x, y, width, height, color) { 13860 this.enableRenderer(this.shapes); 13861 this.shapes.rect(filled, x, y, width, height, color); 13862 } 13863 rectLine(filled, x1, y1, x2, y2, width, color) { 13864 this.enableRenderer(this.shapes); 13865 this.shapes.rectLine(filled, x1, y1, x2, y2, width, color); 13866 } 13867 polygon(polygonVertices, offset, count, color) { 13868 this.enableRenderer(this.shapes); 13869 this.shapes.polygon(polygonVertices, offset, count, color); 13870 } 13871 circle(filled, x, y, radius, color, segments = 0) { 13872 this.enableRenderer(this.shapes); 13873 this.shapes.circle(filled, x, y, radius, color, segments); 13874 } 13875 curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) { 13876 this.enableRenderer(this.shapes); 13877 this.shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color); 13878 } 13879 end() { 13880 if (this.activeRenderer === this.batcher) this.batcher.end(); 13881 else if (this.activeRenderer === this.shapes) this.shapes.end(); 13882 this.activeRenderer = null; 13883 } 13884 resize(resizeMode) { 13885 let canvas = this.canvas; 13886 var dpr = window.devicePixelRatio || 1; 13887 var w = Math.round(canvas.clientWidth * dpr); 13888 var h = Math.round(canvas.clientHeight * dpr); 13889 if (canvas.width != w || canvas.height != h) { 13890 canvas.width = w; 13891 canvas.height = h; 13892 } 13893 this.context.gl.viewport(0, 0, canvas.width, canvas.height); 13894 if (resizeMode === 1 /* Expand */) 13895 this.camera.setViewport(w, h); 13896 else if (resizeMode === 2 /* Fit */) { 13897 let sourceWidth = canvas.width, sourceHeight = canvas.height; 13898 let targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHe
13898ight; 13899 let targetRatio = targetHeight / targetWidth; 13900 let sourceRatio = sourceHeight / sourceWidth; 13901 let scale = targetRatio < sourceRatio ? targetWidth / sourceWidth : targetHeight / sourceHeight; 13902 this.camera.setViewport(sourceWidth * scale, sourceHeight * scale); 13903 } 13904 this.camera.update(); 13905 } 13906 enableRenderer(renderer) { 13907 if (this.activeRenderer === renderer) return; 13908 this.end(); 13909 if (renderer instanceof PolygonBatcher) { 13910 this.batcherShader.bind(); 13911 this.batcherShader.setUniform4x4f(Shader.MVP_MATRIX, this.camera.projectionView.values); 13912 this.batcherShader.setUniformi("u_texture", 0); 13913 this.batcher.begin(this.batcherShader); 13914 this.activeRenderer = this.batcher; 13915 } else if (renderer instanceof ShapeRenderer) { 13916 this.shapesShader.bind(); 13917 this.shapesShader.setUniform4x4f(Shader.MVP_MATRIX, this.camera.projectionView.values); 13918 this.shapes.begin(this.shapesShader); 13919 this.activeRenderer = this.shapes; 13920 } else 13921 this.activeRenderer = this.skeletonDebugRenderer; 13922 } 13923 }; 13924 var ResizeMode = /* @__PURE__ */ ((ResizeMode2) => { 13925 ResizeMode2[ResizeMode2["Stretch"] = 0] = "Stretch"; 13926 ResizeMode2[ResizeMode2["Expand"] = 1] = "Expand"; 13927 ResizeMode2[ResizeMode2["Fit"] = 2] = "Fit"; 13928 return ResizeMode2; 13929 })(ResizeMode || {}); 13930 13931
13931// spine-webgl/src/LoadingScreen.ts 13932 var spinnerImage; 13933 var logoImage; 13934 var loaded = 0; 13935 var FADE_IN = 1; 13936 var FADE_OUT = 1; 13937 var logoWidth = 165; 13938 var logoHeight = 108; 13939 var spinnerSize = 163; 13940 var LoadingScreen = class { 13941 renderer; 13942 logo = null; 13943 spinner = null; 13944 angle = 0; 13945 fadeOut = 0; 13946 fadeIn = 0; 13947 timeKeeper = new TimeKeeper(); 13948 backgroundColor = new Color(0.135, 0.135, 0.135, 1); 13949 tempColor = new Color(); 13950 constructor(renderer) { 13951 this.renderer = renderer; 13952 this.timeKeeper.maxDelta = 9; 13953 if (!logoImage) { 13954 let isSafari = navigator.userAgent.indexOf("Safari") > -1; 13955 let onload = () => loaded++; 13956 logoImage = new Image(); 13957 logoImage.src = SPINE_LOGO_DATA; 13958 if (!isSafari) logoImage.crossOrigin = "anonymous"; 13959 logoImage.onload = onload; 13960 spinnerImage = new Image(); 13961 spinnerImage.src = SPINNER_DATA; 13962 if (!isSafari) spinnerImage.crossOrigin = "anonymous"; 13963 spinnerImage.onload = onload; 13964 } 13965 } 13966 dispose() { 13967 this.logo?.dispose(); 13968 this.spinner?.dispose(); 13969 } 13970 draw(complete = false) { 13971 if (loaded < 2 || complete && this.fadeOut > FADE_OUT) return; 13972 this.timeKeeper.update(); 13973 let a = Math.abs(Math.sin(this.timeKeeper.totalTime + 0.25)); 13974 this.angle -= this.timeKeeper.delta * 200 * (1 + 1.5 * Math.pow(a, 5)); 13975 let tempColor = this.tempColor; 13976 let renderer = this.renderer; 13977 let canvas = renderer.canvas; 13978 let gl = renderer.context.gl; 13979 renderer.resize(1 /* Expand */); 13980 renderer.camera.position.set(canvas.width / 2, canvas.height / 2, 0); 13981 renderer.batcher.setBlendMode(0 /* Normal */, true); 13982 if (complete) { 13983 this.fadeOut += this.timeKeeper.delta * (this.timeKeeper.totalTime < 1 ? 2 : 1); 13984 if (this.fadeOut > FADE_OUT) return; 13985 tempColor.setFromColor(this.backgroundColor); 13986 a = 1 - this.fadeOut / FADE_OUT; 13987 a = 1 - (a - 1) * (a - 1); 13988 tempColor.a *= a; 13989 if (tempColor.a > 0) { 13990 renderer.camera.zoom = 1; 13991 renderer.begin(); 13992 renderer.quad( 13993 true, 13994 0, 13995 0, 13996 canvas.width, 13997 0, 13998 canvas.width, 13999 canvas.height, 14000 0, 14001 canvas.height, 14002 tempColor, 14003 tempColor, 14004 tempColor, 14005 tempColor 14006 ); 14007 renderer.end(); 14008 } 14009 } else { 14010 this.fadeIn += this.timeKeeper.delta; 14011 if (this.backgroundColor.a > 0) { 14012 gl.clearColor(this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a); 14013 gl.clear(gl.COLOR_BUFFER_BIT); 14014 } 14015 a = 1; 14016 } 14017 a *= Math.min(this.fadeIn / FADE_IN, 1); 14018 tempColor.set(a, a, a, a); 14019 if (!this.logo) { 14020 this.logo = new GLTexture(renderer.context, logoImage); 14021 this.spinner = new GLTexture(renderer.context, spinnerImage); 14022 } 14023 renderer.camera.zoom = Math.max(1, spinnerSize / canvas.height); 14024 renderer.begin(); 14025 renderer.drawTexture(this.logo, (canvas.width - logoWidth) / 2, (canvas.height - logoHeight) / 2, logoWidth, logoHeight, tempColor); 14026 if (this.spinner) renderer.drawTextureRotated(this.spinner, (canvas.width - spinnerSize) / 2, (canvas.height - spinnerSize) / 2, spinnerSize, spinnerSize, spinnerSize / 2, spinnerSize / 2, this.angle, tempColor); 14027 renderer.end(); 14028 } 14029 drawInCoordinates(x, y) { 14030 if (loaded < 2) return; 14031 this.timeKeeper.update(); 14032 let renderer = this.renderer; 14033 renderer.batcher.setBlendMode(0 /* Normal */, true); 14034 if (!this.logo) { 14035 this.logo = new GLTexture(renderer.context, logoImage); 14036 this.spinner = new GLTexture(renderer.context, spinnerImag
vendor: 11,229 bytes, lines 14036-14076
14036e); 14037 } 14038 const shiftedX = x - logoWidth / 2; 14039 const shiftedY = y - logoHeight / 2; 14040 renderer.drawTexture(this.logo, shiftedX, shiftedY, logoWidth, logoHeight); 14041 this.angle -= this.timeKeeper.delta * 500; 14042 if (this.spinner) renderer.drawTextureRotated(this.spinner, shiftedX, shiftedY - 25, spinnerSize, spinnerSize, spinnerSize / 2, spinnerSize / 2, this.angle); 14043 } 14044 }; 14045 var SPINNER_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKMAAACjCAYAAADmbK6AAAALKElEQVR42u2de2iW5R/GPzuqcwfnnKfNmafl5tTNHWzqNi3DEMQykcAoJSsySkspjSIk0iD/07Kf4R+FnVBDUTshZGpWUEJaaiWFgZlUFmXmIe3HNXthyebeZ77P9H13ffBG8Y8H7ut7vff93N/7fu4vGGPiFZiez/Qtw9lytJajfzfw9z/j+efPOv7cV8W+lUNY2a8T/ayTCRsWFLJA5rtUO1LLkV5p9LJeJizQiHeqnlOtmVFtdTGrrZkJCxYXsTgaI6r9MY4/UpNItW4mFDaXsTlaM6qVZlBq3UwofFrJp0HMWJ9DvXUzobCznJ1BzFjWlTLrZkJh/TDWBzFjTgo51s2EgnKI0Rrx+FiOWzNzVaym91Syx5qZsGBWb2ZFa0ZN6dbMhAWTcpkUrRmXD2K5NTNhgVbH0Zpxbl/mWjMTFvRIo0e0ZpzcncnWzISKtvmiMWNRJ4qslwmVXRXsas2Ix8ZwzFqZsGFREYtaM+Oaa1ljrUzYkJ9G/ok6TlzKjJWZVFor0y7c1Zu7WjLiqiGsskamXdHopyT4vALmzS9k/t19uHtKHlOSIMn6xAtARjIZ1sFcUSZ0Y4La+G6M18hS2IlCn4a+WoC0JNL0d/dUupdnUj40g6EJ2VEdMnhrOG/p5f/jUXz8SgmvaGU6KpNRNsLVQV0OdXf24s63h/P2gWoOrBjMCr2GJFQnnxnIM3q5P1PPmaYv+4ev4/C6UtbpV2gzXCkgL5W8Bwt48OIc6ul6Tp+s4+SyASxLiI4+PYCn1bHzDZxvaQW6vZzto7MYnQIpNkf7kp5EuozYUroqEjcNKHHd0Tl9mBPN1pk+hFeieGBnBtog7UXjsj9pWg+m6duecw2cay1OC/uxMC47KmP9OIYfoz1YoC20J/rzRG4quTZK2EAyJGs20qwUbYw0aNRmUxtvfUW/uEtNzc1NB1/X8LVyd15hh82F43AvD+VlXcsSJEZa1CQ3ejleAO7oxR3RDP0XN91X4+NXYb8nkv7UNTwV7e0YTdu7I3g33t7tuaEbNwSZpps2fSyvs4M2Tjhot+jb0Xzbltj8r5j/xVt/6Z1Ob93U1ZYO691EhhzchcHeXosVjcNZysyezLw4xRZt05R+fTeuj8vOj+zKyG0j2aZcVVs6v+QalnjrMFZASQYl2nBoSyz06e3j/Xk8rgWYmMvEICu2pm1HOTuc7okV8FgRj0XukwzanhvCc/F+72TjoQjdObN1OFuDLmh0xP+WHtxiI10ukJlCprb4guiv1fP+avZrS1C7NAkliHZjDtZwMMgqbukAltpMlwuMy2FcEBPqvfLLar5Uqi0hBdEwryy+Mv5n6zkbjTBa+dlMlwvUZFETZKGiFM7tvbhdJ3gSVRO0wzIjnxmvl/J6a6JsGMYGrahtpssFeqbR841S3mhN80OjOaSDEdqd6SjaMKgzgzRK7q1ib3PT9sYyNo7JZoyNFNvRcVMZmy7WOvIuryv/Zvdmdt90+nY0bRp3AvROohFwdwW7dTG7RFlbwlqdrbOBYg005NAQmZU0HWt1rXMBH1Xw0dQ8pmqzoaPmdhun7bHZjNVe9qP9eFQfO1VkUmHjhAVUZ1GtnKFSbjrkrPfy4i4UW5t/6ZxM54J0CqxFe81KpGsQyE4h23oYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjLna+bdOy+IiFquIpGq16Pb79cNYv3IIK/X/ugx+Ui6TVKvYVU9Nc8gX8od8Ir/IN/KPfCQ/yVfyl/6/pfJvLChkQdD6wyqntquCXYuKWJSfRr6D0dEAxV3xlw/khyD+kd/ku/88cHo+09tS3LBpO1HHCVUqcIA6CqB4K+6X6x35L/JM2loXurlWmUmlA5XogOIcK8/If5HncrSWo7F6cKIWPjT/RXGOlWfkv8hzaWsN4uaaysE6WIkOKM6x8oz8F3kusXqo2vxC5jtYiQ4ozrH0TeS5qIZcrB7qkrwdA8U5Vp6R/yLPZV8V+2L14Cl5THGwEh1QnGPlGfkv8lyUlIzFQ1cNYVVHrcjZ0VCcFe9Y+Eb+izy3ceclUl43aFN52DXXssYpnY6a4qFS8ZcP2uIf+e7inRh6pdFrdTGrm8uiHx/L8T2V7NGWzvJBLJ/bl7mTuzO5qBNFDoiJID/IF/KHfCK/yDfyT3O7d/KbfNfS80hNIrU0g9L6HOq1x5iTQo6FNpeLfCQ/yVfyl3xmXYwxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHNk9z4JwJ0SqKTdQkbyEwhU393T6V7zzR6pieR3tE1ITeVXImhe6BXDGZFdRbVeank2TBhcaEMr0rwbixj49IBLL2/L/ffmMuNHfqO9tFZjJYBd1ewO3Lx+IcVfKhqna5nHZYR6XFPH+5R3eeI5t9fx/fvjeC9Jdew5OKZKqFR/RDVKL6vL/f9PJafmyvHsL+a/ff24V6NmjZQbGchVbY6UM2BluqHv1rCqzVZ1KQlkZboepCdQvacPsz5bjTfXao+yMEaDt7Wk9tSIMVGig3TejCtJSM2bSpkPjWPqd1S6Zao+lORSYWmgkOjORRNwZqd5ezMSiHLRooNr5XwWjS6/1XHX9vL2T67N7M1iyXa9JCrYjVrS1gbpJyw6hBfsmiNCYT0P9/A+Wj1/6qGr5YNYFlJBiWJogEzezLz/ZG8/9s4fgtSyuvNYbyp1IONFBtu7sHNv4/j9yAxUHWrdaWsG9+N8XHd+YxkMpSy+aySz841cC5oXbmHCnnI74yxAgZ3YbDeB4PEQCOpBpFNZWwa2ZWRcdnxLsl00crtRB0n2lLg8JNRfDKoM4NsolgBSmw/UMADba1+qpmqfyf6x1u/0a/og3I+aEunP6/i86osqmygcGarF4p54dex/Bo0LqfqOfVwIQ/HW5/RSkwV1oN2WLlHTc82TljAwM4M1O5LWwYKZTjibYXNS0N5KcjKTe10PadfLObFuJwK4ozp+UzXDBTUjL+M5ZcBnRkQV53dMIwNQTu6bSTbVEzbi5awuVByd2E/FgaN0Tc1fKOzBHHV2aAdVSdv6s5NNkp7cSH/++xAng2yyHx+CM/H21YhfdPp+0U1X0TbSZnXx8faG9Aop0MS0cToh1p+iLcpOkLj9t/JOk5eqoPHxnDsyf486an5yqCDK7XZ1O4oZ4dWyy3FSXHUAYq47uyYbMZoGmhpG3DlEFb6uNiVBhpyaHhnBO8oJmfqOROJjzIiP43hJ8UxITqqX56S2Hur2KsOnq3nrE6PPNKPRwrSKbAZrjTQNZmuE7oxYXMZmxWbw9dxWFu4W4ezVedOE6qzI7oyYkY+M7TPeWsPbk2UX1qioSN+E3OZqOR2cReKE+qQRFN0Pi7y73g/UawU1KzezJpXwLz5hczX1ueUPKYkNb6GJQZ+j7/aAfRZREsv+quGsMoamXZBW2Gt5eU0alorEzYsKmJRa/m4NdeyxlqZsCGa84DKnVorEzboC7podis69DfIJmwufHMc7famvvmxZiYsKOtKWbRm1OcW1syEBboSJFozLh/EcmtmwgIluaM14/phrLdmJixYXMTiaM24p5I91syEBTphFOR7Y2tmwgJNvUFOr+tov3UzoaAv44KYUatv62ZCoemdhtG0+hzqrZsJBR08DWLG0gxKrZu50qvpxos3U5NItW4mFPp1ot+lPlpq2lYXs9qamVBZUMiC1ox4pJYjvlfStAu6GmTLcLboMtPIV4/6im5fFfuUi9QIap2MiWP+D96R1vPmsD/fAAAAAElFTkSuQmCC"; 14046 var SPINE_LOGO_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKUAAABsCAYAAAALzHKmAAAQ7klEQVR42u3da4xdVRUA4D0zd2Y6nZY59DVtZ1puS9+lzC0YAi2UQ8AAQczFpPgA9VIeIQbirRqJ0cBUBVGjDr/QCKSNRSMmpuODxAdxqhgwxkhFjf6Sxh/+UUNVNGJCzR7uTvas7LXX2q9zzp3em6y0gTN3Zu75utZe5+yztxC9V+/Ve5X9En1Vjd7J6SFbLNF7naPw+l2jh7YHMBWssqMHtlsRdim4qsLtIawaPiHEQOLoNrA9iIkQDnRrVA1qD2LZ8ISoxYqKo13sQAtBWBayQWZUAXGRQM9JjCngDVY0UqJNDbQrMcaGmArdUKpIjbYiQLsCZCyIMQBy8QwnilR4Q5AuCpxFYvRFmBLbEiwKwpsSaWycVQGZBKMrwBjA9BhxDe57u2L2hOoKNCbOrgAZitEVYUxoKSMErQvSxYIzCkguRg5EF4AUhqUlhy/YUKSxcRaKsioYOQhD4I0yYxkR3PcJBcuFysmgsXAWBTMJyBCMIQh9kGGxXIXvexCQXbHGAMrBWTbM2CCpMSMLIxehC77lSJwXGth7M0FzoVJIXXDWQnGmhOkL0ic7YhhtWdGGkAuPAjUWGoF4faCmwBkbZmyUqUCyMqMLRA4+E6IsdTjidUHKBYrh9CnpRcH0ypKxsyOGEYNIIeTCOz91OIJ1QYoB5eAMyZo+MFNnyVTZ0YiRC9EGEMOyAgshxErHsL2XK1gOUgwohtM1a5YNM7Rsu4K0ZkcbRm4mpPBRwFZ5hg9eCqkrUB+csWGGogzNkqEgrdnRhpGLkINudaLgwvVB6oqzCjCTZElb2Y4B0gUjBtEG0ARnDRLjjoG9DwcshtQGlIPTljVjwUySLWNkyRCQVHa0ZUUTRAwgF91a33BEy0VKAcVwwqwZC2bqbOlUurllOxQkJzNyINoAYqjWhYYjWg5SCiiG05Q1U8FMjTIoS8YE6YORi1BHtJ4KIcQEEtTXUWAxpK44YVlPBdO1jCdFWTZIE8bVGEYMIRPcZGBw4HKQcoBiOE1ZMzbMgVQwU6JMAdKEEcuIJogUvg1YCCE2gsCO42DlIIVAKZwpYJaSLVNnSU6XjYHUmxhTmXaFaMO3EYkLqMC+FsLlIoVAKZzMrEnBhJeLfLNlKMrYWRIDCbOkFSSVHbHM6AKRC6/ODUewNqQ+OLlZkxpjUmV8MBbMUJSxyzY3Q1IgTRgxiBRCHdem0KDAUkBh9sRwwjEnAXMMgTnKhFlUtiwkS5rGka4g9SaGgxFmRC7AzTCEEBcyA36dDSsXqAtOLkysjGMwY5XxVChjZ0kuSCo7YlkRQsQQYtDEFsegsLoCxUp7Kpgps2UslFGzJGccSYHUmxhOZqwzEZqAbfUMCisHKIZzgsCpl3MTzMwTpi1bYp2477gyFKUxS7qWbdjY2EBS2dGE0QQRA7gNCyHEdhjE8RhUDlBT9tzgmjWZMFNlSy+Urk1OzCyJlW0XkK4YOQh1cDtcgwBrQmoDWkdgboBZE8mYsJSHlnFbJ+5bwmOPJ7lZkirbC8aRsMvmgtTHjBhGE0QbwJ2egUE1ITVlUC5OmDVdYNrKuN70xM6WoShjlW4464dbtiFIWK6x7GjESEHUUe0iYncnbMdQSE0Z1ITTNOb0hRmjjLtmS9dmJ2rp1jtuKktyyrb6YLEMCUHq2dGG0QQRQ7f72kzc+cJecerne8Wvv7JNPHPvenEkz8Sh3UtFc92QyGt9Yko/HgOLAIUZlItTz5ouMF3KuE+2jFLCQ1D6lm6fLMkBacuOJowYRBUXyfjuHjF3NhdnsfjvAfH6E9vFt9XxKgikEKgJZyyYalzOLeMu2bLbULI6bh+QGwmQ+rgRlumdGEQAao+K56bEL2woVUwOiev0r8OAUjiJrMmFCbvykGxZRAmPitK1dHM7bohyMsuyi/I8f0+e57fJYIKEZXpXo9E4mOf5XTKyLLvCBLETF8uY2SKepkC+dpX4T02Ivepr4HvZcOZ5fmee54fyPL+DmTUhzAs6n4n8bN5dr9f3YdkSg8nsxG0lPBVKVpNjG0/aGhzfLDmRZdnumZmZp8+c+cdZPV555fSr7Xb7s0jJ3i5Pcue4MxKkPPkvvXTqz/B92u32l0wYOzG1fkhcd/py8Rcbyq/vFM/KY1WA95h/3zzP71bfU6JsNpsfgj+P/FlbrdaDGExYyuXvLz8H+DudODH700ajcSM3W6Yu4alQ1spCOTd38jcKocTZbh9+9NixY99XJ8AEUkcpo9W64yH197m5k7+bnZ19QT+J09NHntQhwji/Jg58qi6++ofLxJ8gSFneVw2Ka4QQDfh1Ok4dZavVmtZ/nrm5k7/Vf55O1tRhboUw5+ZOvqyOl5+R/FyOHj32PYVU/tloNG5IXcKrhJIzngwp3fNjomazea/64BuNxts646f50lWv169utw9/DmtqdJQyZFaSJVuV6nq9fqMEof5/vV6/CYBqgJDlee+yAbF/+4i4ZWqZeNfaIfHWzn+Hx0KcEuU9+s8jv3ej0bhVlXOZydX/k0iRMeb8P0D5e6tj8zy/Xb9UJIc56h/yqVOnXul8lmuZ2bJslKmbHG7XrbpCmCXFRLvdfqQD6jTS3Jiy5I4OykM6ADV+1Eu1DmV6evopBORexzDi1L+X/HnGxsb2w3Hm9PSRJ9QxWPOTZdmlKht2hi+w6dkox5bqffI8fye3hDteGqKaHVsHXihKl0tB+h0cY+lute54AGRKDCW89LNTRynHb7ChUWVVjetOnJh9EYBUyPZeNCoOtsbFQwdXi4/esELcd+tq8cCHJ8UXp+viy9efLz7AgamjlKXc1AA1m83DoIRDlFubzeb96hhZLVTlgJ24gttutx+ONa50bHZKRenaeTs1OfpAfnr6yOOdE7EZdNwmlKocntXLNkA5JTGq47Ds+Lf94lWsyfnXleLfnIwJUN4DOnNYwuUxh2A3Ln9XULrfK8t3J27Tu3BVwiOjXJqoAy8UZej1yclGo3GTLN+gu3w+z/P3YaWbQqk3Ne12e4ZC+c8rxWsYytcPiP9RpZxCqWDKnxOiBNlyAUpOnGsoh4tA2Rm8X9xqtT6md5wyZmYe+0YRKL+1S/wYQ3n8zctBl5SBUv5djivfjMOPduIzcizeiYfr9foVvUwZG+XCuzibZKnSceZ5/v4QlKp8y7ElhnJlTeTP7BI/kllRYfzrfvHqFy4UX1vaL/aVlSmROzwbwdS29T2UcEwZF+V8ozM2lu1VY812u/15akypGh3TmFJesJbHHD167IdUxz3YJy5bNySuX1mbvy55CbMLtzU6tjGlsdFptVqfUMc0Go23F4wy1l2dSnbfvpMwVPe9WWVLDsrOJaF9MFu2Wq1PqmNkGce67xiXhTjdNwdlvV6/BgxfbPfBfVCetxi6b9/rlCup65QzM48dl2OjLMv26CibzeZ96sTIzEFdpwQXz9U1yrtVlpR/Zll2Fec65Y6l4pbbx8XHH9kknvzJlPjlHy8Tp29eKT5ou0aJoIT3w3dBlLDzVpfAJEZ1XOdaJZxnOSlvPMjPzxFljIvng914RwebsjYO7uhMyHu46sOfnf3Oz2TXDW6vvYxdFoIXz3Wc8J5zs9n8iOn2IrxTc2BM3Glqdp7dI553uaOjxrhwcob+MyuUpjs6WZZdon8OcigjPx8V+u+GTWFTSWEx3WYcdJ225jNDSE4q0GHCzlueHOyujn6bUWYgeb9ZZUaQPe+GzQ+Gc8+oOGhC+c1d4gfI16n3XDAhQ7+9qE9l01E2Go132GYKyXE1NiFDTcpoNpv3LOYJGWXNErJNW9sEp63p2RKiVPMn1bS1DgxsyhoGdGpmizj+xtXiDYnx7/vFmce3iWdW1cTVGEY4hQ2ZW0nNq8Qm/M6XbXm3S100lwGedFybuvNOibLI+ZS2ceU4eAxiEuvCkfmU8ycToDxETe6FgCBQHeqyAbFvfEhcO7BwDuXFCEbTZF840XeHK0jYcbs2OIGle0mVJ/mmnClEPQqxyTY5I8/zFhif7fSZee4bnrPOU4AssnRXHaVTCTd14dRDY3UbTIiSeFhsN/aMjgnqthFx880rxX3yATL5p3y4LPXzOaBkUyBjZMlYpbtQlIOBD475ZEusjMNSvkXe6VEoJVDkeZ2dzIfIFsRzU+JF2OyM9M9fTC/6SUYOyFQPjQ2nWiUjxnPfw5EeHqMWIqAeIFsAU847lJM2JM6xsewt1OIDLs99P7ZFHNdB/upS8XtPiD7PfLuCXJNolYyyFiNI/Zit65ItrOVafFbHcFohY7hPTN21Tjz4uc3iqfsnxKdX1MTl1OoYRFaMsToGB6Trw2JFP/OdZC2hJZ7ZkrMoAbbSGmelDJ91hFKuJeS7jlBMkJnrAqqJlgMUZS/dArPlGHNdSg5M3xXXtvquuEatvIYtDRhpxbUJuIgqsU5lGWtUploK0KuEU9mSW8YpmFQ556xNuYW7NiW13B+FkMiKHIy+C6eGgBxJvMR0oSv5hi6+z4HJyZoU0M2RVvDlrOQbcxVfX5AhZbuqy0v7ZstYMLHlAVlLTF9ALLbvu9Y5Zylpn/XOsd0ibIvxr2KCLHpp6SCUIdnSZSF+WzfOhem6GD+1KwR3Z4jNjrtDpNoZwmWd8yrupZN6Hx3fbMmFSe0Swdq2ZIPjxk1112Duo8OBGLrBkw/IoncdK2XHsdC9dHz204m50xh3tzFq1zFqtzHXrfCw7OgDsqyNnZLszVijsmXgrmNcmGtS78lIoMX2aJz03fKO2sDJddPQSCDPiQ1DfWBycY6XtXstc2PQKuxgG2McmXTPb9/9vmuJYXKyJrWjbeg+3xPM4O73nWqvbyw7xgZZSJbEUBa157cNJjdr2vb+5iA1YV3HxYscj30PDCEHIgcjtfm8K8hSsmRotkwFk5s1TTghUAopB6xrjHMBBkI0YYTZ0dZlxwLpkiWDULpmy5gwqayZgZNkA7oKQQCxctByYg0XIIEQQuRitGVHblMTA2ShKGPDpC6wu+DEgJqg2rDGDBtAF4Q6RAojp1xXGmSMbImVcR+YWNY04eQCtUG1ofUJ2/uvcETIgUhhdAE5GAlkKShjwHTNmhhODKgJqQ2sC14uOgyfD0IbRF+MlQaZAiZWyn2yJsTJATqGnHQO2Jhh+xlsACFCG0QbRtdyzQFZCZSxYPpmTS7Q5cjJHYNBYIkZpu99HoUQ/o4QIYSIZUZfjJ4ZMjZI32wZBDMU5yhy8pZTULl4XYP5fagMyEVoy4oupTpGduwnkloSlKEwY+AcQU4MhRTD6ovXBRwFzwWgCSEF0QVjJUGmgEllTS5OLlCIlIN1mS9mx/cZ5eLDALpCTI2RAhkTZQqYoTgpoCPECbaBHQ2ETL3PUl98ECAXYijG0OyYAmQoTG7W5ODkAF1CnVgm2JQx4okPA+gCMTbGskBGgRmaOblAh5GTORIrfKFx4VH4EIAxIXIxlg2SBbMvECY3e7oApbDaIgQu5/2HmeEKEINYiwSRi7EQkLFgumZOCuggctKGI4ULZN/vMeSLj0AYMytWEqMLzFg4fYDaoKaC6wvOFR4FkIPQFaILxrJAOsHsc/zlfYDWXE8qF22s8Pz5KHxcgEVALBtjJXBSSEOwFhk1Zgy4hitCT4hVw+gFs8/zwxqIBbUgyK7fcyA0PD9XX4iVxhiC0xdof6STWCsoBmKF7+cVCWFXQYyBMxRpf+STX1b0x45AhN0OMSrOGEirhrY/dfQAdjvS7oy+WCF6r1RIFxXWvlTRg1YVqFWBmxZbD99ig9pt0YPQw9rD1nstVri9V+/Ve3XrS/wfim4P5fIFxLoAAAAASUVORK5CYII="; 14047 14048 // spine-webgl/src/SpineCanvas.ts 14049 var SpineCanvas = class { 14050 /** Constructs a new spine canvas, rendering to the provided HTML canvas. */ 14051 constructor(canvas, config) { 14052 this.config = config; 14053 if (!config.pathPrefix) config.pathPrefix = ""; 14054 if (!config.app) config.app = { 14055 loadAssets: () => { 14056 }, 14057 initialize: () => { 14058 }, 14059 update: () => { 14060 }, 14061 render: () => { 14062 }, 14063 error: () => { 14064 }, 14065 dispose: () => { 14066 } 14067 }; 14068 if (!config.webglConfig) config.webglConfig = { alpha: true }; 14069 this.htmlCanvas = canvas; 14070 this.context = new ManagedWebGLRenderingContext(canvas, config.webglConfig); 14071 this.renderer = new SceneRenderer(canvas, this.context); 14072 this.gl = this.context.gl; 14073 this.assetManager = new AssetManager(this.context, config.pathPrefix); 14074 this.input = new Input(canvas); 14075 if (config.app.loadAssets) config.app.loadAssets(this); 14076
14076let loop = () => { 14077 if (this.disposed) return; 14078 requestAnimationFrame(loop); 14079 this.time.update(); 14080 if (config.app.update) config.app.update(this, this.time.delta); 14081 if (config.app.render) config.app.render(this); 14082 }; 14083 let waitForAssets = () => { 14084 if (this.disposed) return; 14085 if (this.assetManager.isLoadingComplete()) { 14086 if (this.assetManager.hasErrors()) { 14087 if (config.app.error) config.app.error(this, this.assetManager.getErrors()); 14088 } else { 14089 if (config.app.initialize) config.app.initialize(this); 14090 loop(); 14091 } 14092 return; 14093 } 14094 requestAnimationFrame(waitForAssets); 14095 }; 14096 requestAnimationFrame(waitForAssets); 14097 } 14098 context; 14099 /** Tracks the current time, delta, and other time related statistics. */ 14100 time = new TimeKeeper(); 14101 /** The HTML canvas to render to. */ 14102 htmlCanvas; 14103 /** The WebGL rendering context. */ 14104 gl; 14105 /** The scene renderer for easy drawing of skeletons, shapes, and images. */ 14106 renderer; 14107 /** The asset manager to load assets with. */ 14108 assetManager; 14109 /** The input processor used to listen to mouse, touch, and keyboard events. */ 14110 input; 14111 disposed = false; 14112 /** Clears the canvas with the given color. The color values are given in the range [0,1]. */ 14113 clear(r, g, b, a) { 14114 this.gl.clearColor(r, g, b, a); 14115 this.gl.clear(this.gl.COLOR_BUFFER_BIT); 14116 } 14117 /** Disposes the app, so the update() and render() functions are no longer called. Calls the dispose() callback.*/ 14118 dispose() { 14119 if (this.config.app.dispose) this.config.app.dispose(this); 14120 this.disposed = true; 14121 } 14122 }; 14123 return __toCommonJS(index_exports); 14124})(); 14125//# sourceMappingURL=spine-webgl.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.