UNPKG

ngx-spine

Version:

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

1,643 lines (1,634 loc) 741 kB
import { EventEmitter, Component, ChangeDetectionStrategy, Input as Input$1, ViewChild, ElementRef, Output, NgModule } from '@angular/core'; /** * @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. * *************************************************************************** * @abstract */ class Texture { /** * @param {?} image */ constructor(image) { this._image = image; } /** * @return {?} */ getImage() { return this._image; } /** * @param {?} text * @return {?} */ static filterFromString(text) { switch (text.toLowerCase()) { case "nearest": return TextureFilter.Nearest; case "linear": return TextureFilter.Linear; case "mipmap": return TextureFilter.MipMap; case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest; case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest; case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear; case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear; default: throw new Error(`Unknown texture filter ${text}`); } } /** * @param {?} text * @return {?} */ static wrapFromString(text) { switch (text.toLowerCase()) { case "mirroredtepeat": return TextureWrap.MirroredRepeat; case "clamptoedge": return TextureWrap.ClampToEdge; case "repeat": return TextureWrap.Repeat; default: throw new Error(`Unknown texture wrap ${text}`); } } } if (false) { /** * @type {?} * @protected */ Texture.prototype._image; /** * @abstract * @param {?} minFilter * @param {?} magFilter * @return {?} */ Texture.prototype.setFilters = function (minFilter, magFilter) { }; /** * @abstract * @param {?} uWrap * @param {?} vWrap * @return {?} */ Texture.prototype.setWraps = function (uWrap, vWrap) { }; /** * @abstract * @return {?} */ Texture.prototype.dispose = function () { }; } /** @enum {number} */ const TextureFilter = { Nearest: 9728, Linear: 9729, MipMap: 9987, MipMapNearestNearest: 9984, MipMapLinearNearest: 9985, MipMapNearestLinear: 9986, MipMapLinearLinear: 9987 // WebGLRenderingContext.LINEAR_MIPMAP_LINEAR , }; TextureFilter[TextureFilter.Nearest] = 'Nearest'; TextureFilter[TextureFilter.Linear] = 'Linear'; TextureFilter[TextureFilter.MipMap] = 'MipMap'; TextureFilter[TextureFilter.MipMapNearestNearest] = 'MipMapNearestNearest'; TextureFilter[TextureFilter.MipMapLinearNearest] = 'MipMapLinearNearest'; TextureFilter[TextureFilter.MipMapNearestLinear] = 'MipMapNearestLinear'; TextureFilter[TextureFilter.MipMapLinearLinear] = 'MipMapLinearLinear'; /** @enum {number} */ const TextureWrap = { MirroredRepeat: 33648, ClampToEdge: 33071, Repeat: 10497 // WebGLRenderingContext.REPEAT , }; TextureWrap[TextureWrap.MirroredRepeat] = 'MirroredRepeat'; TextureWrap[TextureWrap.ClampToEdge] = 'ClampToEdge'; TextureWrap[TextureWrap.Repeat] = 'Repeat'; class TextureRegion { constructor() { this.u = 0; this.v = 0; this.u2 = 0; this.v2 = 0; this.width = 0; this.height = 0; this.rotate = false; this.offsetX = 0; this.offsetY = 0; this.originalWidth = 0; this.originalHeight = 0; } } if (false) { /** @type {?} */ TextureRegion.prototype.renderObject; /** @type {?} */ TextureRegion.prototype.u; /** @type {?} */ TextureRegion.prototype.v; /** @type {?} */ TextureRegion.prototype.u2; /** @type {?} */ TextureRegion.prototype.v2; /** @type {?} */ TextureRegion.prototype.width; /** @type {?} */ TextureRegion.prototype.height; /** @type {?} */ TextureRegion.prototype.rotate; /** @type {?} */ TextureRegion.prototype.offsetX; /** @type {?} */ TextureRegion.prototype.offsetY; /** @type {?} */ TextureRegion.prototype.originalWidth; /** @type {?} */ TextureRegion.prototype.originalHeight; } class FakeTexture extends Texture { /** * @param {?} minFilter * @param {?} magFilter * @return {?} */ setFilters(minFilter, magFilter) { } /** * @param {?} uWrap * @param {?} vWrap * @return {?} */ setWraps(uWrap, vWrap) { } /** * @return {?} */ dispose() { } } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class TextureAtlas { /** * @param {?} atlasText * @param {?} textureLoader */ constructor(atlasText, textureLoader) { this.pages = new Array(); this.regions = new Array(); this.load(atlasText, textureLoader); } /** * @private * @param {?} atlasText * @param {?} textureLoader * @return {?} */ load(atlasText, textureLoader) { if (textureLoader == null) throw new Error("textureLoader cannot be null."); /** @type {?} */ let reader = new TextureAtlasReader(atlasText); /** @type {?} */ let tuple = new Array(4); /** @type {?} */ let page = null; while (true) { /** @type {?} */ let line = reader.readLine(); if (line == null) break; line = line.trim(); if (line.length == 0) page = null; else if (!page) { page = new TextureAtlasPage(); page.name = line; if (reader.readTuple(tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker. page.width = parseInt(tuple[0]); page.height = parseInt(tuple[1]); reader.readTuple(tuple); } // page.format = Format[tuple[0]]; we don't need format in WebGL reader.readTuple(tuple); page.minFilter = Texture.filterFromString(tuple[0]); page.magFilter = Texture.filterFromString(tuple[1]); /** @type {?} */ let direction = reader.readValue(); page.uWrap = TextureWrap.ClampToEdge; page.vWrap = TextureWrap.ClampToEdge; if (direction == "x") page.uWrap = TextureWrap.Repeat; else if (direction == "y") page.vWrap = TextureWrap.Repeat; else if (direction == "xy") page.uWrap = page.vWrap = TextureWrap.Repeat; page.texture = textureLoader(line); page.texture.setFilters(page.minFilter, page.magFilter); page.texture.setWraps(page.uWrap, page.vWrap); page.width = page.texture.getImage().width; page.height = page.texture.getImage().height; this.pages.push(page); } else { /** @type {?} */ let region = new TextureAtlasRegion(); region.name = line; region.page = page; /** @type {?} */ let rotateValue = reader.readValue(); if (rotateValue.toLocaleLowerCase() == "true") { region.degrees = 90; } else if (rotateValue.toLocaleLowerCase() == "false") { region.degrees = 0; } else { region.degrees = parseFloat(rotateValue); } region.rotate = region.degrees == 90; reader.readTuple(tuple); /** @type {?} */ let x = parseInt(tuple[0]); /** @type {?} */ let y = parseInt(tuple[1]); reader.readTuple(tuple); /** @type {?} */ let width = parseInt(tuple[0]); /** @type {?} */ let height = parseInt(tuple[1]); region.u = x / page.width; region.v = y / page.height; if (region.rotate) { region.u2 = (x + height) / page.width; region.v2 = (y + width) / page.height; } else { region.u2 = (x + width) / page.width; region.v2 = (y + height) / page.height; } region.x = x; region.y = y; region.width = Math.abs(width); region.height = Math.abs(height); if (reader.readTuple(tuple) == 4) { // split is optional // region.splits = new Vector.<int>(parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])); if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits //region.pads = Vector.<int>(parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])); reader.readTuple(tuple); } } region.originalWidth = parseInt(tuple[0]); region.originalHeight = parseInt(tuple[1]); reader.readTuple(tuple); region.offsetX = parseInt(tuple[0]); region.offsetY = parseInt(tuple[1]); region.index = parseInt(reader.readValue()); region.texture = page.texture; this.regions.push(region); } } } /** * @param {?} name * @return {?} */ findRegion(name) { for (let i = 0; i < this.regions.length; i++) { if (this.regions[i].name == name) { return this.regions[i]; } } return null; } /** * @return {?} */ dispose() { for (let i = 0; i < this.pages.length; i++) { this.pages[i].texture.dispose(); } } } if (false) { /** @type {?} */ TextureAtlas.prototype.pages; /** @type {?} */ TextureAtlas.prototype.regions; } class TextureAtlasReader { /** * @param {?} text */ constructor(text) { this.index = 0; this.lines = text.split(/\r\n|\r|\n/); } /** * @return {?} */ readLine() { if (this.index >= this.lines.length) return null; return this.lines[this.index++]; } /** * @return {?} */ readValue() { /** @type {?} */ let line = this.readLine(); /** @type {?} */ let colon = line.indexOf(":"); if (colon == -1) throw new Error("Invalid line: " + line); return line.substring(colon + 1).trim(); } /** * @param {?} tuple * @return {?} */ readTuple(tuple) { /** @type {?} */ let line = this.readLine(); /** @type {?} */ let colon = line.indexOf(":"); if (colon == -1) throw new Error("Invalid line: " + line); /** @type {?} */ let i = 0; /** @type {?} */ let lastMatch = colon + 1; for (; i < 3; i++) { /** @type {?} */ let comma = line.indexOf(",", lastMatch); if (comma == -1) break; tuple[i] = line.substr(lastMatch, comma - lastMatch).trim(); lastMatch = comma + 1; } tuple[i] = line.substring(lastMatch).trim(); return i + 1; } } if (false) { /** @type {?} */ TextureAtlasReader.prototype.lines; /** @type {?} */ TextureAtlasReader.prototype.index; } class TextureAtlasPage { } if (false) { /** @type {?} */ TextureAtlasPage.prototype.name; /** @type {?} */ TextureAtlasPage.prototype.minFilter; /** @type {?} */ TextureAtlasPage.prototype.magFilter; /** @type {?} */ TextureAtlasPage.prototype.uWrap; /** @type {?} */ TextureAtlasPage.prototype.vWrap; /** @type {?} */ TextureAtlasPage.prototype.texture; /** @type {?} */ TextureAtlasPage.prototype.width; /** @type {?} */ TextureAtlasPage.prototype.height; } class TextureAtlasRegion extends TextureRegion { } if (false) { /** @type {?} */ TextureAtlasRegion.prototype.page; /** @type {?} */ TextureAtlasRegion.prototype.name; /** @type {?} */ TextureAtlasRegion.prototype.x; /** @type {?} */ TextureAtlasRegion.prototype.y; /** @type {?} */ TextureAtlasRegion.prototype.index; /** @type {?} */ TextureAtlasRegion.prototype.rotate; /** @type {?} */ TextureAtlasRegion.prototype.degrees; /** @type {?} */ TextureAtlasRegion.prototype.texture; /** @type {?} */ TextureAtlasRegion.prototype.u; /** @type {?} */ TextureAtlasRegion.prototype.v; /** @type {?} */ TextureAtlasRegion.prototype.u2; /** @type {?} */ TextureAtlasRegion.prototype.v2; /** @type {?} */ TextureAtlasRegion.prototype.width; /** @type {?} */ TextureAtlasRegion.prototype.height; /** @type {?} */ TextureAtlasRegion.prototype.originalWidth; /** @type {?} */ TextureAtlasRegion.prototype.originalHeight; /** @type {?} */ TextureAtlasRegion.prototype.offsetX; /** @type {?} */ TextureAtlasRegion.prototype.offsetY; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AssetManager { /** * @param {?} textureLoader * @param {?=} pathPrefix */ constructor(textureLoader, pathPrefix = "") { this.assets = {}; this.errors = {}; this.toLoad = 0; this.loaded = 0; this.textureLoader = textureLoader; this.pathPrefix = pathPrefix; } /** * @private * @param {?} url * @param {?} success * @param {?} error * @return {?} */ static downloadText(url, success, error) { /** @type {?} */ let request = new XMLHttpRequest(); request.open("GET", url, true); request.onload = (/** * @return {?} */ () => { if (request.status == 200) { success(request.responseText); } else { error(request.status, request.responseText); } }); request.onerror = (/** * @return {?} */ () => { error(request.status, request.responseText); }); request.send(); } /** * @private * @param {?} url * @param {?} success * @param {?} error * @return {?} */ static downloadBinary(url, success, error) { /** @type {?} */ let request = new XMLHttpRequest(); request.open("GET", url, true); request.responseType = "arraybuffer"; request.onload = (/** * @return {?} */ () => { if (request.status == 200) { success(new Uint8Array((/** @type {?} */ (request.response)))); } else { error(request.status, request.responseText); } }); request.onerror = (/** * @return {?} */ () => { error(request.status, request.responseText); }); request.send(); } /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ loadBinary(path, success = null, error = null) { path = this.pathPrefix + path; this.toLoad++; AssetManager.downloadBinary(path, (/** * @param {?} data * @return {?} */ (data) => { this.assets[path] = data; if (success) success(path, data); this.toLoad--; this.loaded++; }), (/** * @param {?} state * @param {?} responseText * @return {?} */ (state, responseText) => { this.errors[path] = `Couldn't load binary ${path}: status ${status}, ${responseText}`; if (error) error(path, `Couldn't load binary ${path}: status ${status}, ${responseText}`); this.toLoad--; this.loaded++; })); } /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ loadText(path, success = null, error = null) { path = this.pathPrefix + path; this.toLoad++; AssetManager.downloadText(path, (/** * @param {?} data * @return {?} */ (data) => { this.assets[path] = data; if (success) success(path, data); this.toLoad--; this.loaded++; }), (/** * @param {?} state * @param {?} responseText * @return {?} */ (state, responseText) => { this.errors[path] = `Couldn't load text ${path}: status ${status}, ${responseText}`; if (error) error(path, `Couldn't load text ${path}: status ${status}, ${responseText}`); this.toLoad--; this.loaded++; })); } /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ loadTexture(path, success = null, error = null) { path = this.pathPrefix + path; this.toLoad++; /** @type {?} */ let img = new Image(); img.crossOrigin = "anonymous"; img.onload = (/** * @param {?} ev * @return {?} */ ev => { /** @type {?} */ let texture = this.textureLoader(img); this.assets[path] = texture; this.toLoad--; this.loaded++; if (success) success(path, img); }); img.onerror = (/** * @param {?} ev * @return {?} */ ev => { this.errors[path] = `Couldn't load image ${path}`; this.toLoad--; this.loaded++; if (error) error(path, `Couldn't load image ${path}`); }); img.src = path; } /** * @param {?} path * @param {?} data * @param {?=} success * @param {?=} error * @return {?} */ loadTextureData(path, data, success = null, error = null) { path = this.pathPrefix + path; this.toLoad++; /** @type {?} */ let img = new Image(); img.onload = (/** * @param {?} ev * @return {?} */ ev => { /** @type {?} */ let texture = this.textureLoader(img); this.assets[path] = texture; this.toLoad--; this.loaded++; if (success) success(path, img); }); img.onerror = (/** * @param {?} ev * @return {?} */ ev => { this.errors[path] = `Couldn't load image ${path}`; this.toLoad--; this.loaded++; if (error) error(path, `Couldn't load image ${path}`); }); img.src = data; } /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ loadTextureAtlas(path, success = null, error = null) { /** @type {?} */ let parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; path = this.pathPrefix + path; this.toLoad++; AssetManager.downloadText(path, (/** * @param {?} atlasData * @return {?} */ (atlasData) => { /** @type {?} */ let pagesLoaded = { count: 0 }; /** @type {?} */ let atlasPages = new Array(); try { /** @type {?} */ let atlas = new TextureAtlas(atlasData, (/** * @param {?} path * @return {?} */ (path) => { atlasPages.push(parent + "/" + path); /** @type {?} */ let image = (/** @type {?} */ (document.createElement("img"))); image.width = 16; image.height = 16; return new FakeTexture(image); })); } catch (e) { /** @type {?} */ let ex = (/** @type {?} */ (e)); this.errors[path] = `Couldn't load texture atlas ${path}: ${ex.message}`; if (error) error(path, `Couldn't load texture atlas ${path}: ${ex.message}`); this.toLoad--; this.loaded++; return; } for (let atlasPage of atlasPages) { /** @type {?} */ let pageLoadError = false; this.loadTexture(atlasPage, (/** * @param {?} imagePath * @param {?} image * @return {?} */ (imagePath, image) => { pagesLoaded.count++; if (pagesLoaded.count == atlasPages.length) { if (!pageLoadError) { try { /** @type {?} */ let atlas = new TextureAtlas(atlasData, (/** * @param {?} path * @return {?} */ (path) => { return this.get(parent + "/" + path); })); this.assets[path] = atlas; if (success) success(path, atlas); this.toLoad--; this.loaded++; } catch (e) { /** @type {?} */ let ex = (/** @type {?} */ (e)); this.errors[path] = `Couldn't load texture atlas ${path}: ${ex.message}`; if (error) error(path, `Couldn't load texture atlas ${path}: ${ex.message}`); this.toLoad--; this.loaded++; } } else { this.errors[path] = `Couldn't load texture atlas page ${imagePath}} of atlas ${path}`; if (error) error(path, `Couldn't load texture atlas page ${imagePath} of atlas ${path}`); this.toLoad--; this.loaded++; } } }), (/** * @param {?} imagePath * @param {?} errorMessage * @return {?} */ (imagePath, errorMessage) => { pageLoadError = true; pagesLoaded.count++; if (pagesLoaded.count == atlasPages.length) { this.errors[path] = `Couldn't load texture atlas page ${imagePath}} of atlas ${path}`; if (error) error(path, `Couldn't load texture atlas page ${imagePath} of atlas ${path}`); this.toLoad--; this.loaded++; } })); } }), (/** * @param {?} state * @param {?} responseText * @return {?} */ (state, responseText) => { this.errors[path] = `Couldn't load texture atlas ${path}: status ${status}, ${responseText}`; if (error) error(path, `Couldn't load texture atlas ${path}: status ${status}, ${responseText}`); this.toLoad--; this.loaded++; })); } /** * @param {?} path * @return {?} */ get(path) { path = this.pathPrefix + path; return this.assets[path]; } /** * @param {?} path * @return {?} */ remove(path) { path = this.pathPrefix + path; /** @type {?} */ let asset = this.assets[path]; if (((/** @type {?} */ (asset))).dispose) ((/** @type {?} */ (asset))).dispose(); this.assets[path] = null; } /** * @return {?} */ removeAll() { for (let key in this.assets) { /** @type {?} */ let asset = this.assets[key]; if (((/** @type {?} */ (asset))).dispose) ((/** @type {?} */ (asset))).dispose(); } this.assets = {}; } /** * @return {?} */ isLoadingComplete() { return this.toLoad == 0; } /** * @return {?} */ getToLoad() { return this.toLoad; } /** * @return {?} */ getLoaded() { return this.loaded; } /** * @return {?} */ dispose() { this.removeAll(); } /** * @return {?} */ hasErrors() { return Object.keys(this.errors).length > 0; } /** * @return {?} */ getErrors() { return this.errors; } } if (false) { /** * @type {?} * @private */ AssetManager.prototype.pathPrefix; /** * @type {?} * @private */ AssetManager.prototype.textureLoader; /** * @type {?} * @private */ AssetManager.prototype.assets; /** * @type {?} * @private */ AssetManager.prototype.errors; /** * @type {?} * @private */ AssetManager.prototype.toLoad; /** * @type {?} * @private */ AssetManager.prototype.loaded; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ const BlendMode = { Normal: 0, Additive: 1, Multiply: 2, Screen: 3, }; BlendMode[BlendMode.Normal] = 'Normal'; BlendMode[BlendMode.Additive] = 'Additive'; BlendMode[BlendMode.Multiply] = 'Multiply'; BlendMode[BlendMode.Screen] = 'Screen'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class ManagedWebGLRenderingContext { /** * @param {?} canvasOrContext * @param {?=} contextConfig */ constructor(canvasOrContext, contextConfig = { alpha: "true" }) { this.restorables = new Array(); if (canvasOrContext instanceof HTMLCanvasElement) { /** @type {?} */ let canvas = canvasOrContext; this.gl = (/** @type {?} */ (((canvas.getContext("webgl", contextConfig) || canvas.getContext("experimental-webgl", contextConfig))))); this.canvas = canvas; canvas.addEventListener("webglcontextlost", (/** * @param {?} e * @return {?} */ (e) => { /** @type {?} */ let event = (/** @type {?} */ (e)); if (e) { e.preventDefault(); } })); canvas.addEventListener("webglcontextrestored", (/** * @param {?} e * @return {?} */ (e) => { for (let i = 0, n = this.restorables.length; i < n; i++) { this.restorables[i].restore(); } })); } else { this.gl = canvasOrContext; this.canvas = (/** @type {?} */ (this.gl.canvas)); } } /** * @param {?} restorable * @return {?} */ addRestorable(restorable) { this.restorables.push(restorable); } /** * @param {?} restorable * @return {?} */ removeRestorable(restorable) { /** @type {?} */ let index = this.restorables.indexOf(restorable); if (index > -1) this.restorables.splice(index, 1); } } if (false) { /** @type {?} */ ManagedWebGLRenderingContext.prototype.canvas; /** @type {?} */ ManagedWebGLRenderingContext.prototype.gl; /** * @type {?} * @private */ ManagedWebGLRenderingContext.prototype.restorables; } class WebGLBlendModeConverter { /** * @param {?} blendMode * @return {?} */ static getDestGLBlendMode(blendMode) { switch (blendMode) { case BlendMode.Normal: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; case BlendMode.Additive: return WebGLBlendModeConverter.ONE; case BlendMode.Multiply: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; case BlendMode.Screen: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; default: throw new Error("Unknown blend mode: " + blendMode); } } /** * @param {?} blendMode * @param {?=} premultipliedAlpha * @return {?} */ static getSourceGLBlendMode(blendMode, premultipliedAlpha = false) { switch (blendMode) { case BlendMode.Normal: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA; case BlendMode.Additive: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA; case BlendMode.Multiply: return WebGLBlendModeConverter.DST_COLOR; case BlendMode.Screen: return WebGLBlendModeConverter.ONE; default: throw new Error("Unknown blend mode: " + blendMode); } } } WebGLBlendModeConverter.ZERO = 0; WebGLBlendModeConverter.ONE = 1; WebGLBlendModeConverter.SRC_COLOR = 0x0300; WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR = 0x0301; WebGLBlendModeConverter.SRC_ALPHA = 0x0302; WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA = 0x0303; WebGLBlendModeConverter.DST_ALPHA = 0x0304; WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA = 0x0305; WebGLBlendModeConverter.DST_COLOR = 0x0306; if (false) { /** @type {?} */ WebGLBlendModeConverter.ZERO; /** @type {?} */ WebGLBlendModeConverter.ONE; /** @type {?} */ WebGLBlendModeConverter.SRC_COLOR; /** @type {?} */ WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR; /** @type {?} */ WebGLBlendModeConverter.SRC_ALPHA; /** @type {?} */ WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; /** @type {?} */ WebGLBlendModeConverter.DST_ALPHA; /** @type {?} */ WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA; /** @type {?} */ WebGLBlendModeConverter.DST_COLOR; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class GLTexture extends Texture { /** * @param {?} context * @param {?} image * @param {?=} useMipMaps */ constructor(context, image, useMipMaps = false) { super(image); this.texture = null; this.boundUnit = 0; this.useMipMaps = false; this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); this.useMipMaps = useMipMaps; this.restore(); this.context.addRestorable(this); } /** * @param {?} minFilter * @param {?} magFilter * @return {?} */ setFilters(minFilter, magFilter) { /** @type {?} */ let gl = this.context.gl; this.bind(); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); } /** * @param {?} uWrap * @param {?} vWrap * @return {?} */ setWraps(uWrap, vWrap) { /** @type {?} */ let gl = this.context.gl; this.bind(); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap); } /** * @param {?} useMipMaps * @return {?} */ update(useMipMaps) { /** @type {?} */ let gl = this.context.gl; if (!this.texture) { this.texture = this.context.gl.createTexture(); } this.bind(); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); if (useMipMaps) gl.generateMipmap(gl.TEXTURE_2D); } /** * @return {?} */ restore() { this.texture = null; this.update(this.useMipMaps); } /** * @param {?=} unit * @return {?} */ bind(unit = 0) { /** @type {?} */ let gl = this.context.gl; this.boundUnit = unit; gl.activeTexture(gl.TEXTURE0 + unit); gl.bindTexture(gl.TEXTURE_2D, this.texture); } /** * @return {?} */ unbind() { /** @type {?} */ let gl = this.context.gl; gl.activeTexture(gl.TEXTURE0 + this.boundUnit); gl.bindTexture(gl.TEXTURE_2D, null); } /** * @return {?} */ dispose() { this.context.removeRestorable(this); /** @type {?} */ let gl = this.context.gl; gl.deleteTexture(this.texture); } } if (false) { /** * @type {?} * @private */ GLTexture.prototype.context; /** * @type {?} * @private */ GLTexture.prototype.texture; /** * @type {?} * @private */ GLTexture.prototype.boundUnit; /** * @type {?} * @private */ GLTexture.prototype.useMipMaps; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AssetManager$1 extends AssetManager { /** * @param {?} context * @param {?=} pathPrefix */ constructor(context, pathPrefix = "") { super((/** * @param {?} image * @return {?} */ (image) => { return new GLTexture(context, image); }), pathPrefix); } } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const M00 = 0; /** @type {?} */ const M01 = 4; /** @type {?} */ const M02 = 8; /** @type {?} */ const M03 = 12; /** @type {?} */ const M10 = 1; /** @type {?} */ const M11 = 5; /** @type {?} */ const M12 = 9; /** @type {?} */ const M13 = 13; /** @type {?} */ const M20 = 2; /** @type {?} */ const M21 = 6; /** @type {?} */ const M22 = 10; /** @type {?} */ const M23 = 14; /** @type {?} */ const M30 = 3; /** @type {?} */ const M31 = 7; /** @type {?} */ const M32 = 11; /** @type {?} */ const M33 = 15; class Matrix4 { constructor() { this.temp = new Float32Array(16); this.values = new Float32Array(16); /** @type {?} */ let v = this.values; v[M00] = 1; v[M11] = 1; v[M22] = 1; v[M33] = 1; } /** * @param {?} values * @return {?} */ set(values) { this.values.set(values); return this; } /** * @return {?} */ transpose() { /** @type {?} */ let t = this.temp; /** @type {?} */ let v = this.values; t[M00] = v[M00]; t[M01] = v[M10]; t[M02] = v[M20]; t[M03] = v[M30]; t[M10] = v[M01]; t[M11] = v[M11]; t[M12] = v[M21]; t[M13] = v[M31]; t[M20] = v[M02]; t[M21] = v[M12]; t[M22] = v[M22]; t[M23] = v[M32]; t[M30] = v[M03]; t[M31] = v[M13]; t[M32] = v[M23]; t[M33] = v[M33]; return this.set(t); } /** * @return {?} */ identity() { /** @type {?} */ let v = this.values; v[M00] = 1; v[M01] = 0; v[M02] = 0; v[M03] = 0; v[M10] = 0; v[M11] = 1; v[M12] = 0; v[M13] = 0; v[M20] = 0; v[M21] = 0; v[M22] = 1; v[M23] = 0; v[M30] = 0; v[M31] = 0; v[M32] = 0; v[M33] = 1; return this; } /** * @return {?} */ invert() { /** @type {?} */ let v = this.values; /** @type {?} */ let t = this.temp; /** @type {?} */ 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]; if (l_det == 0) throw new Error("non-invertible matrix"); /** @type {?} */ let inv_det = 1.0 / l_det; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; 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]; v[M00] = t[M00] * inv_det; v[M01] = t[M01] * inv_det; v[M02] = t[M02] * inv_det; v[M03] = t[M03] * inv_det; v[M10] = t[M10] * inv_det; v[M11] = t[M11] * inv_det; v[M12] = t[M12] * inv_det; v[M13] = t[M13] * inv_det; v[M20] = t[M20] * inv_det; v[M21] = t[M21] * inv_det; v[M22] = t[M22] * inv_det; v[M23] = t[M23] * inv_det; v[M30] = t[M30] * inv_det; v[M31] = t[M31] * inv_det; v[M32] = t[M32] * inv_det; v[M33] = t[M33] * inv_det; return this; } /** * @return {?} */ determinant() { /** @type {?} */ let v = this.values; 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]); } /** * @param {?} x * @param {?} y * @param {?} z * @return {?} */ translate(x, y, z) { /** @type {?} */ let v = this.values; v[M03] += x; v[M13] += y; v[M23] += z; return this; } /** * @return {?} */ copy() { return new Matrix4().set(this.values); } /** * @param {?} near * @param {?} far * @param {?} fovy * @param {?} aspectRatio * @return {?} */ projection(near, far, fovy, aspectRatio) { this.identity(); /** @type {?} */ let l_fd = 1.0 / Math.tan((fovy * (Math.PI / 180)) / 2.0); /** @type {?} */ let l_a1 = (far + near) / (near - far); /** @type {?} */ let l_a2 = (2 * far * near) / (near - far); /** @type {?} */ let v = this.values; v[M00] = l_fd / aspectRatio; v[M10] = 0; v[M20] = 0; v[M30] = 0; v[M01] = 0; v[M11] = l_fd; v[M21] = 0; v[M31] = 0; v[M02] = 0; v[M12] = 0; v[M22] = l_a1; v[M32] = -1; v[M03] = 0; v[M13] = 0; v[M23] = l_a2; v[M33] = 0; return this; } /** * @param {?} x * @param {?} y * @param {?} width * @param {?} height * @return {?} */ ortho2d(x, y, width, height) { return this.ortho(x, x + width, y, y + height, 0, 1); } /** * @param {?} left * @param {?} right * @param {?} bottom * @param {?} top * @param {?} near * @param {?} far * @return {?} */ ortho(left, right, bottom, top, near, far) { this.identity(); /** @type {?} */ let x_orth = 2 / (right - left); /** @type {?} */ let y_orth = 2 / (top - bottom); /** @type {?} */ let z_orth = -2 / (far - near); /** @type {?} */ let tx = -(right + left) / (right - left); /** @type {?} */ let ty = -(top + bottom) / (top - bottom); /** @type {?} */ let tz = -(far + near) / (far - near); /** @type {?} */ let v = this.values; v[M00] = x_orth; v[M10] = 0; v[M20] = 0; v[M30] = 0; v[M01] = 0; v[M11] = y_orth; v[M21] = 0; v[M31] = 0; v[M02] = 0; v[M12] = 0; v[M22] = z_orth; v[M32] = 0; v[M03] = tx; v[M13] = ty; v[M23] = tz; v[M33] = 1; return this; }