UNPKG

ngx-spine

Version:

[![Build Status](https://travis-ci.org/PoiScript/ngx-spine.svg?branch=master)](https://travis-ci.org/PoiScript/ngx-spine)

1,167 lines 351 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /****************************************************************************** * Spine Runtimes License Agreement * Last updated May 1, 2019. Replaces all prior versions. * * Copyright (c) 2013-2019, Esoteric Software LLC * * Integration of the Spine Runtimes into software or otherwise creating * derivative works of the Spine Runtimes is permitted under the terms and * conditions of Section 2 of the Spine Editor License Agreement: * http://esotericsoftware.com/spine-editor-license * * Otherwise, it is permitted to integrate the Spine Runtimes into software * or otherwise create derivative works of the Spine Runtimes (collectively, * "Products"), provided that each user of the Products must obtain their own * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ import { Animation, AttachmentTimeline, ColorTimeline, TwoColorTimeline, RotateTimeline, ScaleTimeline, ShearTimeline, TranslateTimeline, IkConstraintTimeline, TransformConstraintTimeline, PathConstraintSpacingTimeline, PathConstraintPositionTimeline, PathConstraintMixTimeline, DeformTimeline, DrawOrderTimeline, EventTimeline } from "./Animation"; import { TransformMode, BoneData } from "./BoneData"; import { PositionMode, SpacingMode, RotateMode, PathConstraintData } from "./PathConstraintData"; import { SkeletonData } from "./SkeletonData"; import { Color, Utils } from "./Utils"; import { SlotData } from "./SlotData"; import { IkConstraintData } from "./IkConstraintData"; import { EventData } from "./EventData"; import { Skin } from "./Skin"; import { Event } from "./Event"; import { BlendMode } from "./BlendMode"; import { TransformConstraintData } from "./TransformConstraintData"; import { AttachmentType } from "./attachments/AttachmentType"; export class SkeletonBinary { /** * @param {?} attachmentLoader */ constructor(attachmentLoader) { this.scale = 1; this.linkedMeshes = new Array(); this.attachmentLoader = attachmentLoader; } /** * @param {?} binary * @return {?} */ readSkeletonData(binary) { /** @type {?} */ let scale = this.scale; /** @type {?} */ let input = new BinaryInput(binary); /** @type {?} */ let hash = input.readString(); /** @type {?} */ let version = input.readString(); if (version.startsWith("3.6")) { return new SkeletonBinary36(this.attachmentLoader).readSkeletonData(binary); } else if (version.startsWith("3.7")) { return new SkeletonBinary37(this.attachmentLoader).readSkeletonData(binary); } /** @type {?} */ let skeletonData = new SkeletonData(); skeletonData.name = ""; // BOZO skeletonData.hash = hash; skeletonData.version = version; skeletonData.x = input.readFloat(); skeletonData.y = input.readFloat(); skeletonData.width = input.readFloat(); skeletonData.height = input.readFloat(); /** @type {?} */ let nonessential = input.readBoolean(); if (nonessential) { skeletonData.fps = input.readFloat(); skeletonData.imagesPath = input.readString(); skeletonData.audioPath = input.readString(); } /** @type {?} */ let n = 0; // Strings. n = input.readInt(true); for (let i = 0; i < n; i++) input.strings.push(input.readString()); // Bones. n = input.readInt(true); for (let i = 0; i < n; i++) { /** @type {?} */ let name = input.readString(); /** @type {?} */ let parent = i == 0 ? null : skeletonData.bones[input.readInt(true)]; /** @type {?} */ let data = new BoneData(i, name, parent); data.rotation = input.readFloat(); data.x = input.readFloat() * scale; data.y = input.readFloat() * scale; data.scaleX = input.readFloat(); data.scaleY = input.readFloat(); data.shearX = input.readFloat(); data.shearY = input.readFloat(); data.length = input.readFloat() * scale; data.transformMode = SkeletonBinary.TransformModeValues[input.readInt(true)]; data.skinRequired = input.readBoolean(); if (nonessential) Color.rgba8888ToColor(data.color, input.readInt32()); skeletonData.bones.push(data); } // Slots. n = input.readInt(true); for (let i = 0; i < n; i++) { /** @type {?} */ let slotName = input.readString(); /** @type {?} */ let boneData = skeletonData.bones[input.readInt(true)]; /** @type {?} */ let data = new SlotData(i, slotName, boneData); Color.rgba8888ToColor(data.color, input.readInt32()); /** @type {?} */ let darkColor = input.readInt32(); if (darkColor != -1) Color.rgb888ToColor((data.darkColor = new Color()), darkColor); data.attachmentName = input.readStringRef(); data.blendMode = SkeletonBinary.BlendModeValues[input.readInt(true)]; skeletonData.slots.push(data); } // IK constraints. n = input.readInt(true); for (let i = 0, nn; i < n; i++) { /** @type {?} */ let data = new IkConstraintData(input.readString()); data.order = input.readInt(true); data.skinRequired = input.readBoolean(); nn = input.readInt(true); for (let ii = 0; ii < nn; ii++) data.bones.push(skeletonData.bones[input.readInt(true)]); data.target = skeletonData.bones[input.readInt(true)]; data.mix = input.readFloat(); data.softness = input.readFloat() * scale; data.bendDirection = input.readByte(); data.compress = input.readBoolean(); data.stretch = input.readBoolean(); data.uniform = input.readBoolean(); skeletonData.ikConstraints.push(data); } // Transform constraints. n = input.readInt(true); for (let i = 0, nn; i < n; i++) { /** @type {?} */ let data = new TransformConstraintData(input.readString()); data.order = input.readInt(true); data.skinRequired = input.readBoolean(); nn = input.readInt(true); for (let ii = 0; ii < nn; ii++) data.bones.push(skeletonData.bones[input.readInt(true)]); data.target = skeletonData.bones[input.readInt(true)]; data.local = input.readBoolean(); data.relative = input.readBoolean(); data.offsetRotation = input.readFloat(); data.offsetX = input.readFloat() * scale; data.offsetY = input.readFloat() * scale; data.offsetScaleX = input.readFloat(); data.offsetScaleY = input.readFloat(); data.offsetShearY = input.readFloat(); data.rotateMix = input.readFloat(); data.translateMix = input.readFloat(); data.scaleMix = input.readFloat(); data.shearMix = input.readFloat(); skeletonData.transformConstraints.push(data); } // Path constraints. n = input.readInt(true); for (let i = 0, nn; i < n; i++) { /** @type {?} */ let data = new PathConstraintData(input.readString()); data.order = input.readInt(true); data.skinRequired = input.readBoolean(); nn = input.readInt(true); for (let ii = 0; ii < nn; ii++) data.bones.push(skeletonData.bones[input.readInt(true)]); data.target = skeletonData.slots[input.readInt(true)]; data.positionMode = SkeletonBinary.PositionModeValues[input.readInt(true)]; data.spacingMode = SkeletonBinary.SpacingModeValues[input.readInt(true)]; data.rotateMode = SkeletonBinary.RotateModeValues[input.readInt(true)]; data.offsetRotation = input.readFloat(); data.position = input.readFloat(); if (data.positionMode == PositionMode.Fixed) data.position *= scale; data.spacing = input.readFloat(); if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale; data.rotateMix = input.readFloat(); data.translateMix = input.readFloat(); skeletonData.pathConstraints.push(data); } // Default skin. /** @type {?} */ let defaultSkin = this.readSkin(input, skeletonData, true, nonessential); if (defaultSkin != null) { skeletonData.defaultSkin = defaultSkin; skeletonData.skins.push(defaultSkin); } // Skins. { /** @type {?} */ let i = skeletonData.skins.length; Utils.setArraySize(skeletonData.skins, (n = i + input.readInt(true))); for (; i < n; i++) skeletonData.skins[i] = this.readSkin(input, skeletonData, false, nonessential); } // Linked meshes. n = this.linkedMeshes.length; for (let i = 0; i < n; i++) { /** @type {?} */ let linkedMesh = this.linkedMeshes[i]; /** @type {?} */ let skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin); if (skin == null) throw new Error("Skin not found: " + linkedMesh.skin); /** @type {?} */ let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent); if (parent == null) throw new Error("Parent mesh not found: " + linkedMesh.parent); linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? ((/** @type {?} */ (parent))) : linkedMesh.mesh; linkedMesh.mesh.setParentMesh((/** @type {?} */ (parent))); linkedMesh.mesh.updateUVs(); } this.linkedMeshes.length = 0; // Events. n = input.readInt(true); for (let i = 0; i < n; i++) { /** @type {?} */ let data = new EventData(input.readStringRef()); data.intValue = input.readInt(false); data.floatValue = input.readFloat(); data.stringValue = input.readString(); data.audioPath = input.readString(); if (data.audioPath != null) { data.volume = input.readFloat(); data.balance = input.readFloat(); } skeletonData.events.push(data); } // Animations. n = input.readInt(true); for (let i = 0; i < n; i++) skeletonData.animations.push(this.readAnimation(input, input.readString(), skeletonData)); return skeletonData; } /** * @protected * @param {?} input * @param {?} skeletonData * @param {?} defaultSkin * @param {?} nonessential * @return {?} */ readSkin(input, skeletonData, defaultSkin, nonessential) { /** @type {?} */ let skin = null; /** @type {?} */ let slotCount = 0; if (defaultSkin) { slotCount = input.readInt(true); if (slotCount == 0) return null; skin = new Skin("default"); } else { skin = new Skin(input.readStringRef()); skin.bones.length = input.readInt(true); for (let i = 0, n = skin.bones.length; i < n; i++) skin.bones[i] = skeletonData.bones[input.readInt(true)]; for (let i = 0, n = input.readInt(true); i < n; i++) skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]); for (let i = 0, n = input.readInt(true); i < n; i++) skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]); for (let i = 0, n = input.readInt(true); i < n; i++) skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]); slotCount = input.readInt(true); } for (let i = 0; i < slotCount; i++) { /** @type {?} */ let slotIndex = input.readInt(true); for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { /** @type {?} */ let name = input.readStringRef(); /** @type {?} */ let attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name, nonessential); if (attachment != null) skin.setAttachment(slotIndex, name, attachment); } } return skin; } /** * @protected * @param {?} input * @param {?} skeletonData * @param {?} skin * @param {?} slotIndex * @param {?} attachmentName * @param {?} nonessential * @return {?} */ readAttachment(input, skeletonData, skin, slotIndex, attachmentName, nonessential) { /** @type {?} */ let scale = this.scale; /** @type {?} */ let name = input.readStringRef(); if (name == null) name = attachmentName; /** @type {?} */ let typeIndex = input.readByte(); /** @type {?} */ let type = SkeletonBinary.AttachmentTypeValues[typeIndex]; switch (type) { case AttachmentType.Region: { /** @type {?} */ let path = input.readStringRef(); /** @type {?} */ let rotation = input.readFloat(); /** @type {?} */ let x = input.readFloat(); /** @type {?} */ let y = input.readFloat(); /** @type {?} */ let scaleX = input.readFloat(); /** @type {?} */ let scaleY = input.readFloat(); /** @type {?} */ let width = input.readFloat(); /** @type {?} */ let height = input.readFloat(); /** @type {?} */ let color = input.readInt32(); if (path == null) path = name; /** @type {?} */ let region = this.attachmentLoader.newRegionAttachment(skin, name, path); if (region == null) return null; region.path = path; region.x = x * scale; region.y = y * scale; region.scaleX = scaleX; region.scaleY = scaleY; region.rotation = rotation; region.width = width * scale; region.height = height * scale; Color.rgba8888ToColor(region.color, color); region.updateOffset(); return region; } case AttachmentType.BoundingBox: { /** @type {?} */ let vertexCount = input.readInt(true); /** @type {?} */ let vertices = this.readVertices(input, vertexCount); /** @type {?} */ let color = nonessential ? input.readInt32() : 0; /** @type {?} */ let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name); if (box == null) return null; box.worldVerticesLength = vertexCount << 1; box.vertices = vertices.vertices; box.bones = vertices.bones; if (nonessential) Color.rgba8888ToColor(box.color, color); return box; } case AttachmentType.Mesh: { /** @type {?} */ let path = input.readStringRef(); /** @type {?} */ let color = input.readInt32(); /** @type {?} */ let vertexCount = input.readInt(true); /** @type {?} */ let uvs = this.readFloatArray(input, vertexCount << 1, 1); /** @type {?} */ let triangles = this.readShortArray(input); /** @type {?} */ let vertices = this.readVertices(input, vertexCount); /** @type {?} */ let hullLength = input.readInt(true); /** @type {?} */ let edges = null; /** @type {?} */ let width = 0; /** @type {?} */ let height = 0; if (nonessential) { edges = this.readShortArray(input); width = input.readFloat(); height = input.readFloat(); } if (path == null) path = name; /** @type {?} */ let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.path = path; Color.rgba8888ToColor(mesh.color, color); mesh.bones = vertices.bones; mesh.vertices = vertices.vertices; mesh.worldVerticesLength = vertexCount << 1; mesh.triangles = triangles; mesh.regionUVs = uvs; mesh.updateUVs(); mesh.hullLength = hullLength << 1; if (nonessential) { mesh.edges = edges; mesh.width = width * scale; mesh.height = height * scale; } return mesh; } case AttachmentType.LinkedMesh: { /** @type {?} */ let path = input.readStringRef(); /** @type {?} */ let color = input.readInt32(); /** @type {?} */ let skinName = input.readStringRef(); /** @type {?} */ let parent = input.readStringRef(); /** @type {?} */ let inheritDeform = input.readBoolean(); /** @type {?} */ let width = 0; /** @type {?} */ let height = 0; if (nonessential) { width = input.readFloat(); height = input.readFloat(); } if (path == null) path = name; /** @type {?} */ let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path); if (mesh == null) return null; mesh.path = path; Color.rgba8888ToColor(mesh.color, color); if (nonessential) { mesh.width = width * scale; mesh.height = height * scale; } this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritDeform)); return mesh; } case AttachmentType.Path: { /** @type {?} */ let closed = input.readBoolean(); /** @type {?} */ let constantSpeed = input.readBoolean(); /** @type {?} */ let vertexCount = input.readInt(true); /** @type {?} */ let vertices = this.readVertices(input, vertexCount); /** @type {?} */ let lengths = Utils.newArray(vertexCount / 3, 0); for (let i = 0, n = lengths.length; i < n; i++) lengths[i] = input.readFloat() * scale; /** @type {?} */ let color = nonessential ? input.readInt32() : 0; /** @type {?} */ let path = this.attachmentLoader.newPathAttachment(skin, name); if (path == null) return null; path.closed = closed; path.constantSpeed = constantSpeed; path.worldVerticesLength = vertexCount << 1; path.vertices = vertices.vertices; path.bones = vertices.bones; path.lengths = lengths; if (nonessential) Color.rgba8888ToColor(path.color, color); return path; } case AttachmentType.Point: { /** @type {?} */ let rotation = input.readFloat(); /** @type {?} */ let x = input.readFloat(); /** @type {?} */ let y = input.readFloat(); /** @type {?} */ let color = nonessential ? input.readInt32() : 0; /** @type {?} */ let point = this.attachmentLoader.newPointAttachment(skin, name); if (point == null) return null; point.x = x * scale; point.y = y * scale; point.rotation = rotation; if (nonessential) Color.rgba8888ToColor(point.color, color); return point; } case AttachmentType.Clipping: { /** @type {?} */ let endSlotIndex = input.readInt(true); /** @type {?} */ let vertexCount = input.readInt(true); /** @type {?} */ let vertices = this.readVertices(input, vertexCount); /** @type {?} */ let color = nonessential ? input.readInt32() : 0; /** @type {?} */ let clip = this.attachmentLoader.newClippingAttachment(skin, name); if (clip == null) return null; clip.endSlot = skeletonData.slots[endSlotIndex]; clip.worldVerticesLength = vertexCount << 1; clip.vertices = vertices.vertices; clip.bones = vertices.bones; if (nonessential) Color.rgba8888ToColor(clip.color, color); return clip; } } return null; } /** * @protected * @param {?} input * @param {?} vertexCount * @return {?} */ readVertices(input, vertexCount) { /** @type {?} */ let verticesLength = vertexCount << 1; /** @type {?} */ let vertices = new Vertices(); /** @type {?} */ let scale = this.scale; if (!input.readBoolean()) { vertices.vertices = this.readFloatArray(input, verticesLength, scale); return vertices; } /** @type {?} */ let weights = new Array(); /** @type {?} */ let bonesArray = new Array(); for (let i = 0; i < vertexCount; i++) { /** @type {?} */ let boneCount = input.readInt(true); bonesArray.push(boneCount); for (let ii = 0; ii < boneCount; ii++) { bonesArray.push(input.readInt(true)); weights.push(input.readFloat() * scale); weights.push(input.readFloat() * scale); weights.push(input.readFloat()); } } vertices.vertices = Utils.toFloatArray(weights); vertices.bones = bonesArray; return vertices; } /** * @protected * @param {?} input * @param {?} n * @param {?} scale * @return {?} */ readFloatArray(input, n, scale) { /** @type {?} */ let array = new Array(n); if (scale == 1) { for (let i = 0; i < n; i++) array[i] = input.readFloat(); } else { for (let i = 0; i < n; i++) array[i] = input.readFloat() * scale; } return array; } /** * @protected * @param {?} input * @return {?} */ readShortArray(input) { /** @type {?} */ let n = input.readInt(true); /** @type {?} */ let array = new Array(n); for (let i = 0; i < n; i++) array[i] = input.readShort(); return array; } /** * @protected * @param {?} input * @param {?} name * @param {?} skeletonData * @return {?} */ readAnimation(input, name, skeletonData) { /** @type {?} */ let timelines = new Array(); /** @type {?} */ let scale = this.scale; /** @type {?} */ let duration = 0; /** @type {?} */ let tempColor1 = new Color(); /** @type {?} */ let tempColor2 = new Color(); // Slot timelines. for (let i = 0, n = input.readInt(true); i < n; i++) { /** @type {?} */ let slotIndex = input.readInt(true); for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { /** @type {?} */ let timelineType = input.readByte(); /** @type {?} */ let frameCount = input.readInt(true); switch (timelineType) { case SkeletonBinary.SLOT_ATTACHMENT: { /** @type {?} */ let timeline = new AttachmentTimeline(frameCount); timeline.slotIndex = slotIndex; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) timeline.setFrame(frameIndex, input.readFloat(), input.readStringRef()); timelines.push(timeline); duration = Math.max(duration, timeline.frames[frameCount - 1]); break; } case SkeletonBinary.SLOT_COLOR: { /** @type {?} */ let timeline = new ColorTimeline(frameCount); timeline.slotIndex = slotIndex; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { /** @type {?} */ let time = input.readFloat(); Color.rgba8888ToColor(tempColor1, input.readInt32()); timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * ColorTimeline.ENTRIES]); break; } case SkeletonBinary.SLOT_TWO_COLOR: { /** @type {?} */ let timeline = new TwoColorTimeline(frameCount); timeline.slotIndex = slotIndex; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { /** @type {?} */ let time = input.readFloat(); Color.rgba8888ToColor(tempColor1, input.readInt32()); Color.rgb888ToColor(tempColor2, input.readInt32()); timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a, tempColor2.r, tempColor2.g, tempColor2.b); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * TwoColorTimeline.ENTRIES]); break; } } } } // Bone timelines. for (let i = 0, n = input.readInt(true); i < n; i++) { /** @type {?} */ let boneIndex = input.readInt(true); for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { /** @type {?} */ let timelineType = input.readByte(); /** @type {?} */ let frameCount = input.readInt(true); switch (timelineType) { case SkeletonBinary.BONE_ROTATE: { /** @type {?} */ let timeline = new RotateTimeline(frameCount); timeline.boneIndex = boneIndex; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { timeline.setFrame(frameIndex, input.readFloat(), input.readFloat()); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * RotateTimeline.ENTRIES]); break; } case SkeletonBinary.BONE_TRANSLATE: case SkeletonBinary.BONE_SCALE: case SkeletonBinary.BONE_SHEAR: { /** @type {?} */ let timeline; /** @type {?} */ let timelineScale = 1; if (timelineType == SkeletonBinary.BONE_SCALE) timeline = new ScaleTimeline(frameCount); else if (timelineType == SkeletonBinary.BONE_SHEAR) timeline = new ShearTimeline(frameCount); else { timeline = new TranslateTimeline(frameCount); timelineScale = scale; } timeline.boneIndex = boneIndex; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat() * timelineScale); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * TranslateTimeline.ENTRIES]); break; } } } } // IK constraint timelines. for (let i = 0, n = input.readInt(true); i < n; i++) { /** @type {?} */ let index = input.readInt(true); /** @type {?} */ let frameCount = input.readInt(true); /** @type {?} */ let timeline = new IkConstraintTimeline(frameCount); timeline.ikConstraintIndex = index; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat() * scale, input.readByte(), input.readBoolean(), input.readBoolean()); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * IkConstraintTimeline.ENTRIES]); } // Transform constraint timelines. for (let i = 0, n = input.readInt(true); i < n; i++) { /** @type {?} */ let index = input.readInt(true); /** @type {?} */ let frameCount = input.readInt(true); /** @type {?} */ let timeline = new TransformConstraintTimeline(frameCount); timeline.transformConstraintIndex = index; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat()); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * TransformConstraintTimeline.ENTRIES]); } // Path constraint timelines. for (let i = 0, n = input.readInt(true); i < n; i++) { /** @type {?} */ let index = input.readInt(true); /** @type {?} */ let data = skeletonData.pathConstraints[index]; for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { /** @type {?} */ let timelineType = input.readByte(); /** @type {?} */ let frameCount = input.readInt(true); switch (timelineType) { case SkeletonBinary.PATH_POSITION: case SkeletonBinary.PATH_SPACING: { /** @type {?} */ let timeline; /** @type {?} */ let timelineScale = 1; if (timelineType == SkeletonBinary.PATH_SPACING) { timeline = new PathConstraintSpacingTimeline(frameCount); if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) timelineScale = scale; } else { timeline = new PathConstraintPositionTimeline(frameCount); if (data.positionMode == PositionMode.Fixed) timelineScale = scale; } timeline.pathConstraintIndex = index; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * PathConstraintPositionTimeline.ENTRIES]); break; } case SkeletonBinary.PATH_MIX: { /** @type {?} */ let timeline = new PathConstraintMixTimeline(frameCount); timeline.pathConstraintIndex = index; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat()); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[(frameCount - 1) * PathConstraintMixTimeline.ENTRIES]); break; } } } } // Deform timelines. for (let i = 0, n = input.readInt(true); i < n; i++) { /** @type {?} */ let skin = skeletonData.skins[input.readInt(true)]; for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) { /** @type {?} */ let slotIndex = input.readInt(true); for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) { /** @type {?} */ let attachment = (/** @type {?} */ (skin.getAttachment(slotIndex, input.readStringRef()))); /** @type {?} */ let weighted = attachment.bones != null; /** @type {?} */ let vertices = attachment.vertices; /** @type {?} */ let deformLength = weighted ? (vertices.length / 3) * 2 : vertices.length; /** @type {?} */ let frameCount = input.readInt(true); /** @type {?} */ let timeline = new DeformTimeline(frameCount); timeline.slotIndex = slotIndex; timeline.attachment = attachment; for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) { /** @type {?} */ let time = input.readFloat(); /** @type {?} */ let deform; /** @type {?} */ let end = input.readInt(true); if (end == 0) deform = weighted ? Utils.newFloatArray(deformLength) : vertices; else { deform = Utils.newFloatArray(deformLength); /** @type {?} */ let start = input.readInt(true); end += start; if (scale == 1) { for (let v = start; v < end; v++) deform[v] = input.readFloat(); } else { for (let v = start; v < end; v++) deform[v] = input.readFloat() * scale; } if (!weighted) { for (let v = 0, vn = deform.length; v < vn; v++) deform[v] += vertices[v]; } } timeline.setFrame(frameIndex, time, deform); if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[frameCount - 1]); } } } // Draw order timeline. /** @type {?} */ let drawOrderCount = input.readInt(true); if (drawOrderCount > 0) { /** @type {?} */ let timeline = new DrawOrderTimeline(drawOrderCount); /** @type {?} */ let slotCount = skeletonData.slots.length; for (let i = 0; i < drawOrderCount; i++) { /** @type {?} */ let time = input.readFloat(); /** @type {?} */ let offsetCount = input.readInt(true); /** @type {?} */ let drawOrder = Utils.newArray(slotCount, 0); for (let ii = slotCount - 1; ii >= 0; ii--) drawOrder[ii] = -1; /** @type {?} */ let unchanged = Utils.newArray(slotCount - offsetCount, 0); /** @type {?} */ let originalIndex = 0; /** @type {?} */ let unchangedIndex = 0; for (let ii = 0; ii < offsetCount; ii++) { /** @type {?} */ let slotIndex = input.readInt(true); // Collect unchanged items. while (originalIndex != slotIndex) unchanged[unchangedIndex++] = originalIndex++; // Set changed items. drawOrder[originalIndex + input.readInt(true)] = originalIndex++; } // Collect remaining unchanged items. while (originalIndex < slotCount) unchanged[unchangedIndex++] = originalIndex++; // Fill in unchanged items. for (let ii = slotCount - 1; ii >= 0; ii--) if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex]; timeline.setFrame(i, time, drawOrder); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[drawOrderCount - 1]); } // Event timeline. /** @type {?} */ let eventCount = input.readInt(true); if (eventCount > 0) { /** @type {?} */ let timeline = new EventTimeline(eventCount); for (let i = 0; i < eventCount; i++) { /** @type {?} */ let time = input.readFloat(); /** @type {?} */ let eventData = skeletonData.events[input.readInt(true)]; /** @type {?} */ let event = new Event(time, eventData); event.intValue = input.readInt(false); event.floatValue = input.readFloat(); event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue; if (event.data.audioPath != null) { event.volume = input.readFloat(); event.balance = input.readFloat(); } timeline.setFrame(i, event); } timelines.push(timeline); duration = Math.max(duration, timeline.frames[eventCount - 1]); } return new Animation(name, timelines, duration); } /** * @protected * @param {?} input * @param {?} frameIndex * @param {?} timeline * @return {?} */ readCurve(input, frameIndex, timeline) { switch (input.readByte()) { case SkeletonBinary.CURVE_STEPPED: timeline.setStepped(frameIndex); break; case SkeletonBinary.CURVE_BEZIER: this.setCurve(timeline, frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat()); break; } } /** * @param {?} timeline * @param {?} frameIndex * @param {?} cx1 * @param {?} cy1 * @param {?} cx2 * @param {?} cy2 * @return {?} */ setCurve(timeline, frameIndex, cx1, cy1, cx2, cy2) { timeline.setCurve(frameIndex, cx1, cy1, cx2, cy2); } } SkeletonBinary.AttachmentTypeValues = [ 0 /*AttachmentType.Region*/, 1 /*AttachmentType.BoundingBox*/, 2 /*AttachmentType.Mesh*/, 3 /*AttachmentType.LinkedMesh*/, 4 /*AttachmentType.Path*/, 5 /*AttachmentType.Point*/, 6 /*AttachmentType.Clipping*/ ]; SkeletonBinary.TransformModeValues = [ TransformMode.Normal, TransformMode.OnlyTranslation, TransformMode.NoRotationOrReflection, TransformMode.NoScale, TransformMode.NoScaleOrReflection ]; SkeletonBinary.PositionModeValues = [PositionMode.Fixed, PositionMode.Percent]; SkeletonBinary.SpacingModeValues = [ SpacingMode.Length, SpacingMode.Fixed, SpacingMode.Percent ]; SkeletonBinary.RotateModeValues = [ RotateMode.Tangent, RotateMode.Chain, RotateMode.ChainScale ]; SkeletonBinary.BlendModeValues = [ BlendMode.Normal, BlendMode.Additive, BlendMode.Multiply, BlendMode.Screen ]; SkeletonBinary.BONE_ROTATE = 0; SkeletonBinary.BONE_TRANSLATE = 1; SkeletonBinary.BONE_SCALE = 2; SkeletonBinary.BONE_SHEAR = 3; SkeletonBinary.SLOT_ATTACHMENT = 0; SkeletonBinary.SLOT_COLOR = 1; SkeletonBinary.SLOT_TWO_COLOR = 2; SkeletonBinary.PATH_POSITION = 0; SkeletonBinary.PATH_SPACING = 1; SkeletonBinary.PATH_MIX = 2; SkeletonBinary.CURVE_LINEAR = 0; SkeletonBinary.CURVE_STEPPED = 1; SkeletonBinary.CURVE_BEZIER = 2; if (false) { /** @type {?} */ SkeletonBinary.AttachmentTypeValues; /** @type {?} */ SkeletonBinary.TransformModeValues; /** @type {?} */ SkeletonBinary.PositionModeValues; /** @type {?} */ SkeletonBinary.SpacingModeValues; /** @type {?} */ SkeletonBinary.RotateModeValues; /** @type {?} */ SkeletonBinary.BlendModeValues; /** @type {?} */ SkeletonBinary.BONE_ROTATE; /** @type {?} */ SkeletonBinary.BONE_TRANSLATE; /** @type {?} */ SkeletonBinary.BONE_SCALE; /** @type {?} */ SkeletonBinary.BONE_SHEAR; /** @type {?} */ SkeletonBinary.SLOT_ATTACHMENT; /** @type {?} */ SkeletonBinary.SLOT_COLOR; /** @type {?} */ SkeletonBinary.SLOT_TWO_COLOR; /** @type {?} */ SkeletonBinary.PATH_POSITION; /** @type {?} */ SkeletonBinary.PATH_SPACING; /** @type {?} */ SkeletonBinary.PATH_MIX; /** @type {?} */ SkeletonBinary.CURVE_LINEAR; /** @type {?} */ SkeletonBinary.CURVE_STEPPED; /** @type {?} */ SkeletonBinary.CURVE_BEZIER; /** @type {?} */ SkeletonBinary.prototype.attachmentLoader; /** @type {?} */ SkeletonBinary.prototype.scale; /** * @type {?} * @protected */ SkeletonBinary.prototype.linkedMeshes; } class SkeletonBinary37 extends SkeletonBinary { /** * @param {?} binary * @return {?} */ readSkeletonData(binary) { /** @type {?} */ let scale = this.scale; /** @type {?} */ let input = new BinaryInput(binary); /** @type {?} */ let hash = input.readString(); /** @type {?} */ let version = input.readString(); /** @type {?} */ let skeletonData = new SkeletonData(); skeletonData.name = ""; // BOZO skeletonData.hash = hash; skeletonData.version = version; skeletonData.width = input.readFloat(); skeletonData.height = input.readFloat(); /** @type {?} */ let nonessential = input.readBoolean(); if (nonessential) { skeletonData.fps = input.readFloat(); skeletonData.imagesPath = input.readString(); skeletonData.audioPath = input.readString(); } /** @type {?} */ let n = 0; // Bones. n = input.readInt(true); for (let i = 0; i < n; i++) { /** @type {?} */ let name = input.readString(); /** @type {?} */ let parent = i == 0 ? null : skeletonData.bones[input.readInt(true)]; /** @type {?} */ let data = new BoneData(i, name, parent); data.rotation = input.readFloat(); data.x = input.readFloat() * scale; data.y = input.readFloat() * scale; data.scaleX = input.readFloat(); data.scaleY = input.readFloat(); data.shearX = input.readFloat(); data.shearY = input.readFloat(); data.length = input.readFloat() * scale; data.transformMode = SkeletonBinary.TransformModeValues[input.readInt(true)]; if (nonessential) Color.rgba8888ToColor(data.color, input.readInt32()); skeletonData.bones.push(data); } // Slots. n = input.readInt(true); for (let i = 0; i < n; i++) { /** @type {?} */ let slotName = input.readString(); /** @type {?} */ let boneData = skeletonData.bones[input.readInt(true)]; /** @type {?} */ let data = new SlotData(i, slotName, boneData); Color.rgba8888ToColor(data.color, input.readInt32()); /** @type {?} */ let darkColor = input.readInt32(); if (darkColor != -1) Color.rgb888ToColor((data.darkColor = new Color()), darkColor); data.attachmentName = input.readString(); data.blendMode = SkeletonBinary.BlendModeValues[input.readInt(true)]; skeletonData.slots.push(data); } // IK constraints. n = input.readInt(true); for (let i = 0, nn; i < n; i++) { /** @type {?} */ let data = new IkConstraintData(input.readString()); data.order = input.readInt(true); nn = input.readInt(true); for (let ii = 0; ii < nn; ii++) data.bones.push(skeletonData.bones[input.readInt(true)]); data.t