mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-02 05:39:07 +08:00
Merge branch '3.8' of https://github.com/MikalDev/spine-runtimes into MikalDev-3.8
This commit is contained in:
commit
e45c8ca5db
12
spine-ts/build/spine-webgl.d.ts
vendored
12
spine-ts/build/spine-webgl.d.ts
vendored
@ -636,7 +636,7 @@ declare module spine {
|
|||||||
private queueAsset;
|
private queueAsset;
|
||||||
loadText(clientId: string, path: string): void;
|
loadText(clientId: string, path: string): void;
|
||||||
loadJson(clientId: string, path: string): void;
|
loadJson(clientId: string, path: string): void;
|
||||||
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement) => any, path: string): void;
|
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement | ImageBitmap) => any, path: string): void;
|
||||||
get(clientId: string, path: string): any;
|
get(clientId: string, path: string): any;
|
||||||
private updateClientAssets;
|
private updateClientAssets;
|
||||||
isLoadingComplete(clientId: string): boolean;
|
isLoadingComplete(clientId: string): boolean;
|
||||||
@ -881,9 +881,9 @@ declare module spine {
|
|||||||
}
|
}
|
||||||
declare module spine {
|
declare module spine {
|
||||||
abstract class Texture {
|
abstract class Texture {
|
||||||
protected _image: HTMLImageElement;
|
protected _image: HTMLImageElement | ImageBitmap;
|
||||||
constructor(image: HTMLImageElement);
|
constructor(image: HTMLImageElement | ImageBitmap);
|
||||||
getImage(): HTMLImageElement;
|
getImage(): HTMLImageElement | ImageBitmap;
|
||||||
abstract setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
|
abstract setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
|
||||||
abstract setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
|
abstract setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
|
||||||
abstract dispose(): void;
|
abstract dispose(): void;
|
||||||
@ -1369,7 +1369,7 @@ declare module spine.webgl {
|
|||||||
private boundUnit;
|
private boundUnit;
|
||||||
private useMipMaps;
|
private useMipMaps;
|
||||||
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
|
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
|
||||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement, useMipMaps?: boolean);
|
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean);
|
||||||
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
|
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
|
||||||
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear;
|
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear;
|
||||||
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
|
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
|
||||||
@ -1755,7 +1755,7 @@ declare module spine.webgl {
|
|||||||
canvas: HTMLCanvasElement | OffscreenCanvas;
|
canvas: HTMLCanvasElement | OffscreenCanvas;
|
||||||
gl: WebGLRenderingContext;
|
gl: WebGLRenderingContext;
|
||||||
private restorables;
|
private restorables;
|
||||||
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext, contextConfig?: any);
|
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext | OffscreenCanvas | WebGL2RenderingContext, contextConfig?: any);
|
||||||
addRestorable(restorable: Restorable): void;
|
addRestorable(restorable: Restorable): void;
|
||||||
removeRestorable(restorable: Restorable): void;
|
removeRestorable(restorable: Restorable): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ var __extends = (this && this.__extends) || (function () {
|
|||||||
var extendStatics = function (d, b) {
|
var extendStatics = function (d, b) {
|
||||||
extendStatics = Object.setPrototypeOf ||
|
extendStatics = Object.setPrototypeOf ||
|
||||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||||
return extendStatics(d, b);
|
return extendStatics(d, b);
|
||||||
};
|
};
|
||||||
return function (d, b) {
|
return function (d, b) {
|
||||||
@ -3572,15 +3572,35 @@ var spine;
|
|||||||
path = this.pathPrefix + path;
|
path = this.pathPrefix + path;
|
||||||
if (!this.queueAsset(clientId, textureLoader, path))
|
if (!this.queueAsset(clientId, textureLoader, path))
|
||||||
return;
|
return;
|
||||||
var img = new Image();
|
var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
|
||||||
img.crossOrigin = "anonymous";
|
var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
|
||||||
img.onload = function (ev) {
|
if (isWebWorker) {
|
||||||
_this.rawAssets[path] = img;
|
var options = { mode: "cors" };
|
||||||
|
fetch(path, options).then(function (response) {
|
||||||
|
if (!response.ok) {
|
||||||
|
_this.errors[path] = "Couldn't load image " + path;
|
||||||
|
}
|
||||||
|
return response.blob();
|
||||||
|
}).then(function (blob) {
|
||||||
|
return createImageBitmap(blob, {
|
||||||
|
premultiplyAlpha: 'none',
|
||||||
|
colorSpaceConversion: 'none'
|
||||||
|
});
|
||||||
|
}).then(function (bitmap) {
|
||||||
|
_this.rawAssets[path] = bitmap;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var img_1 = new Image();
|
||||||
|
img_1.crossOrigin = "anonymous";
|
||||||
|
img_1.onload = function (ev) {
|
||||||
|
_this.rawAssets[path] = img_1;
|
||||||
};
|
};
|
||||||
img.onerror = function (ev) {
|
img_1.onerror = function (ev) {
|
||||||
_this.errors[path] = "Couldn't load image " + path;
|
_this.errors[path] = "Couldn't load image " + path;
|
||||||
};
|
};
|
||||||
img.src = path;
|
img_1.src = path;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
SharedAssetManager.prototype.get = function (clientId, path) {
|
SharedAssetManager.prototype.get = function (clientId, path) {
|
||||||
path = this.pathPrefix + path;
|
path = this.pathPrefix + path;
|
||||||
@ -3590,6 +3610,8 @@ var spine;
|
|||||||
return clientAssets.assets[path];
|
return clientAssets.assets[path];
|
||||||
};
|
};
|
||||||
SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
|
SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
|
||||||
|
var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
|
||||||
|
var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
|
||||||
for (var i = 0; i < clientAssets.toLoad.length; i++) {
|
for (var i = 0; i < clientAssets.toLoad.length; i++) {
|
||||||
var path = clientAssets.toLoad[i];
|
var path = clientAssets.toLoad[i];
|
||||||
var asset = clientAssets.assets[path];
|
var asset = clientAssets.assets[path];
|
||||||
@ -3597,6 +3619,15 @@ var spine;
|
|||||||
var rawAsset = this.rawAssets[path];
|
var rawAsset = this.rawAssets[path];
|
||||||
if (rawAsset === null || rawAsset === undefined)
|
if (rawAsset === null || rawAsset === undefined)
|
||||||
continue;
|
continue;
|
||||||
|
if (isWebWorker) {
|
||||||
|
if (rawAsset instanceof ImageBitmap) {
|
||||||
|
clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
clientAssets.assets[path] = rawAsset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (rawAsset instanceof HTMLImageElement) {
|
if (rawAsset instanceof HTMLImageElement) {
|
||||||
clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
|
clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
|
||||||
}
|
}
|
||||||
@ -3605,6 +3636,7 @@ var spine;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
SharedAssetManager.prototype.isLoadingComplete = function (clientId) {
|
SharedAssetManager.prototype.isLoadingComplete = function (clientId) {
|
||||||
var clientAssets = this.clientAssets[clientId];
|
var clientAssets = this.clientAssets[clientId];
|
||||||
@ -10732,7 +10764,7 @@ var spine;
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
|
if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
|
||||||
this.restorables = new Array();
|
this.restorables = new Array();
|
||||||
if (canvasOrContext instanceof HTMLCanvasElement) {
|
if (!((canvasOrContext instanceof WebGLRenderingContext) || (canvasOrContext instanceof WebGL2RenderingContext))) {
|
||||||
var canvas = canvasOrContext;
|
var canvas = canvasOrContext;
|
||||||
this.gl = (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
|
this.gl = (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -32,7 +32,7 @@ module spine {
|
|||||||
clientId: string;
|
clientId: string;
|
||||||
toLoad = new Array<string>();
|
toLoad = new Array<string>();
|
||||||
assets: Map<any> = {};
|
assets: Map<any> = {};
|
||||||
textureLoader: (image: HTMLImageElement) => any;
|
textureLoader: (image: HTMLImageElement | ImageBitmap) => any;
|
||||||
|
|
||||||
constructor(clientId: string) {
|
constructor(clientId: string) {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
@ -56,7 +56,7 @@ module spine {
|
|||||||
this.pathPrefix = pathPrefix;
|
this.pathPrefix = pathPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
private queueAsset(clientId: string, textureLoader: (image: HTMLImageElement) => any, path: string): boolean {
|
private queueAsset(clientId: string, textureLoader: (image: HTMLImageElement | ImageBitmap) => any, path: string): boolean {
|
||||||
let clientAssets = this.clientAssets[clientId];
|
let clientAssets = this.clientAssets[clientId];
|
||||||
if (clientAssets === null || clientAssets === undefined) {
|
if (clientAssets === null || clientAssets === undefined) {
|
||||||
clientAssets = new Assets(clientId);
|
clientAssets = new Assets(clientId);
|
||||||
@ -111,10 +111,30 @@ module spine {
|
|||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTexture (clientId: string, textureLoader: (image: HTMLImageElement) => any, path: string) {
|
loadTexture (clientId: string, textureLoader: (image: HTMLImageElement | ImageBitmap) => any, path: string) {
|
||||||
path = this.pathPrefix + path;
|
path = this.pathPrefix + path;
|
||||||
if (!this.queueAsset(clientId, textureLoader, path)) return;
|
if (!this.queueAsset(clientId, textureLoader, path)) return;
|
||||||
|
|
||||||
|
let isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
|
||||||
|
let isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
|
||||||
|
|
||||||
|
if (isWebWorker) {
|
||||||
|
// For webworker use fetch instead of Image()
|
||||||
|
const options = {mode: <RequestMode>"cors"};
|
||||||
|
fetch(path, options).then( (response) => {
|
||||||
|
if (!response.ok) {
|
||||||
|
this.errors[path] = "Couldn't load image " + path;
|
||||||
|
}
|
||||||
|
return response.blob();
|
||||||
|
}).then( (blob) => {
|
||||||
|
return createImageBitmap(blob, {
|
||||||
|
premultiplyAlpha: 'none',
|
||||||
|
colorSpaceConversion: 'none',
|
||||||
|
});
|
||||||
|
}).then( (bitmap) => {
|
||||||
|
this.rawAssets[path] = bitmap;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
let img = new Image();
|
let img = new Image();
|
||||||
img.crossOrigin = "anonymous";
|
img.crossOrigin = "anonymous";
|
||||||
img.onload = (ev) => {
|
img.onload = (ev) => {
|
||||||
@ -125,6 +145,7 @@ module spine {
|
|||||||
}
|
}
|
||||||
img.src = path;
|
img.src = path;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get (clientId: string, path: string) {
|
get (clientId: string, path: string) {
|
||||||
path = this.pathPrefix + path;
|
path = this.pathPrefix + path;
|
||||||
@ -134,12 +155,24 @@ module spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateClientAssets(clientAssets: Assets): void {
|
private updateClientAssets(clientAssets: Assets): void {
|
||||||
|
let isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
|
||||||
|
let isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
|
||||||
|
|
||||||
for (let i = 0; i < clientAssets.toLoad.length; i++) {
|
for (let i = 0; i < clientAssets.toLoad.length; i++) {
|
||||||
let path = clientAssets.toLoad[i];
|
let path = clientAssets.toLoad[i];
|
||||||
let asset = clientAssets.assets[path];
|
let asset = clientAssets.assets[path];
|
||||||
if (asset === null || asset === undefined) {
|
if (asset === null || asset === undefined) {
|
||||||
let rawAsset = this.rawAssets[path];
|
let rawAsset = this.rawAssets[path];
|
||||||
if (rawAsset === null || rawAsset === undefined) continue;
|
if (rawAsset === null || rawAsset === undefined) continue;
|
||||||
|
|
||||||
|
if (isWebWorker)
|
||||||
|
{
|
||||||
|
if (rawAsset instanceof ImageBitmap) {
|
||||||
|
clientAssets.assets[path] = clientAssets.textureLoader(<ImageBitmap>rawAsset);
|
||||||
|
} else {
|
||||||
|
clientAssets.assets[path] = rawAsset;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (rawAsset instanceof HTMLImageElement) {
|
if (rawAsset instanceof HTMLImageElement) {
|
||||||
clientAssets.assets[path] = clientAssets.textureLoader(<HTMLImageElement>rawAsset);
|
clientAssets.assets[path] = clientAssets.textureLoader(<HTMLImageElement>rawAsset);
|
||||||
} else {
|
} else {
|
||||||
@ -148,6 +181,7 @@ module spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isLoadingComplete (clientId: string): boolean {
|
isLoadingComplete (clientId: string): boolean {
|
||||||
let clientAssets = this.clientAssets[clientId];
|
let clientAssets = this.clientAssets[clientId];
|
||||||
|
|||||||
@ -29,13 +29,13 @@
|
|||||||
|
|
||||||
module spine {
|
module spine {
|
||||||
export abstract class Texture {
|
export abstract class Texture {
|
||||||
protected _image: HTMLImageElement;
|
protected _image: HTMLImageElement | ImageBitmap;
|
||||||
|
|
||||||
constructor (image: HTMLImageElement) {
|
constructor (image: HTMLImageElement | ImageBitmap) {
|
||||||
this._image = image;
|
this._image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
getImage (): HTMLImageElement {
|
getImage (): HTMLImageElement | ImageBitmap {
|
||||||
return this._image;
|
return this._image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
module spine.webgl {
|
module spine.webgl {
|
||||||
export class AssetManager extends spine.AssetManager {
|
export class AssetManager extends spine.AssetManager {
|
||||||
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, pathPrefix: string = "") {
|
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, pathPrefix: string = "") {
|
||||||
super((image: HTMLImageElement) => {
|
super((image: HTMLImageElement | ImageBitmap) => {
|
||||||
return new spine.webgl.GLTexture(context, image);
|
return new spine.webgl.GLTexture(context, image);
|
||||||
}, pathPrefix);
|
}, pathPrefix);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ module spine.webgl {
|
|||||||
|
|
||||||
public static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL = false;
|
public static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL = false;
|
||||||
|
|
||||||
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement, useMipMaps: boolean = false) {
|
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps: boolean = false) {
|
||||||
super(image);
|
super(image);
|
||||||
this.context = context instanceof ManagedWebGLRenderingContext? context : new ManagedWebGLRenderingContext(context);
|
this.context = context instanceof ManagedWebGLRenderingContext? context : new ManagedWebGLRenderingContext(context);
|
||||||
this.useMipMaps = useMipMaps;
|
this.useMipMaps = useMipMaps;
|
||||||
|
|||||||
@ -33,8 +33,8 @@ module spine.webgl {
|
|||||||
public gl: WebGLRenderingContext;
|
public gl: WebGLRenderingContext;
|
||||||
private restorables = new Array<Restorable>();
|
private restorables = new Array<Restorable>();
|
||||||
|
|
||||||
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext, contextConfig: any = { alpha: "true" }) {
|
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext | OffscreenCanvas | WebGL2RenderingContext, contextConfig: any = { alpha: "true" }) {
|
||||||
if (canvasOrContext instanceof HTMLCanvasElement) {
|
if (!((canvasOrContext instanceof WebGLRenderingContext) || (canvasOrContext instanceof WebGL2RenderingContext))) {
|
||||||
let canvas = canvasOrContext;
|
let canvas = canvasOrContext;
|
||||||
this.gl = <WebGLRenderingContext> (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
|
this.gl = <WebGLRenderingContext> (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user