mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[ts] Improvements for player, webgl.
* Rendering, added support for separate color/alpha src blend funcs. * LoadingScreen, set camera zoom to fade out and black flash, use PMA to fix ringing artifacts when scaled, fade in to help hide dropped frames as page loads, use separate color/alpha src blend funcs to properly blend quad when loading screen fades out, oxipng PNGs. * Moved some private constants out of their class to avoid class name prefix. * Player, clean up full pass OCD town, showError throws when possible so stacktrace isn't lost, added showLoading to config, don't create UI when !showControls, removed findWithId (id is unique for entire document), use built-in for findWithClass/contains, var->let, don't clear screen twice during loading, other minor stuff.
This commit is contained in:
parent
2911f9da5e
commit
78a730a6d7
114
spine-ts/build/spine-all.d.ts
vendored
114
spine-ts/build/spine-all.d.ts
vendored
@ -362,7 +362,7 @@ declare module spine {
|
||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement | ImageBitmap) => void, error?: (path: string, message: string) => void): void;
|
||||
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, message: string) => void): void;
|
||||
get(path: string): any;
|
||||
remove(path: string): void;
|
||||
remove(path: string): any;
|
||||
removeAll(): void;
|
||||
isLoadingComplete(): boolean;
|
||||
getToLoad(): number;
|
||||
@ -1360,21 +1360,15 @@ declare module spine.webgl {
|
||||
}
|
||||
declare module spine.webgl {
|
||||
class LoadingScreen {
|
||||
static FADE_SECONDS: number;
|
||||
private static loaded;
|
||||
private static spinnerImg;
|
||||
private static logoImg;
|
||||
private renderer;
|
||||
private logo;
|
||||
private spinner;
|
||||
private angle;
|
||||
private fadeOut;
|
||||
private fadeIn;
|
||||
private timeKeeper;
|
||||
backgroundColor: Color;
|
||||
private tempColor;
|
||||
private firstDraw;
|
||||
private static SPINNER_DATA;
|
||||
private static SPINE_LOGO_DATA;
|
||||
constructor(renderer: SceneRenderer);
|
||||
draw(complete?: boolean): void;
|
||||
}
|
||||
@ -1489,11 +1483,12 @@ declare module spine.webgl {
|
||||
private lastTexture;
|
||||
private verticesLength;
|
||||
private indicesLength;
|
||||
private srcBlend;
|
||||
private srcColorBlend;
|
||||
private srcAlphaBlend;
|
||||
private dstBlend;
|
||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint?: boolean, maxVertices?: number);
|
||||
begin(shader: Shader): void;
|
||||
setBlendMode(srcBlend: number, dstBlend: number): void;
|
||||
setBlendMode(srcColorBlend: number, srcAlphaBlend: number, dstBlend: number): void;
|
||||
draw(texture: GLTexture, vertices: ArrayLike<number>, indices: Array<number>): void;
|
||||
private flush;
|
||||
end(): void;
|
||||
@ -1514,17 +1509,14 @@ declare module spine.webgl {
|
||||
private activeRenderer;
|
||||
skeletonRenderer: SkeletonRenderer;
|
||||
skeletonDebugRenderer: SkeletonDebugRenderer;
|
||||
private QUAD;
|
||||
private QUAD_TRIANGLES;
|
||||
private WHITE;
|
||||
constructor(canvas: HTMLCanvasElement, context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint?: boolean);
|
||||
begin(): void;
|
||||
drawSkeleton(skeleton: Skeleton, premultipliedAlpha?: boolean, slotRangeStart?: number, slotRangeEnd?: number): void;
|
||||
drawSkeletonDebug(skeleton: Skeleton, premultipliedAlpha?: boolean, ignoredBones?: Array<string>): void;
|
||||
drawTexture(texture: GLTexture, x: number, y: number, width: number, height: number, color?: Color): void;
|
||||
drawTextureUV(texture: GLTexture, x: number, y: number, width: number, height: number, u: number, v: number, u2: number, v2: number, color?: Color): void;
|
||||
drawTextureRotated(texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color?: Color, premultipliedAlpha?: boolean): void;
|
||||
drawRegion(region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color?: Color, premultipliedAlpha?: boolean): void;
|
||||
drawTextureRotated(texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color?: Color): void;
|
||||
drawRegion(region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color?: Color): void;
|
||||
line(x: number, y: number, x2: number, y2: number, color?: Color, color2?: Color): void;
|
||||
triangle(filled: boolean, x: number, y: number, x2: number, y2: number, x3: number, y3: number, color?: Color, color2?: Color, color3?: Color): void;
|
||||
quad(filled: boolean, x: number, y: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number, color?: Color, color2?: Color, color3?: Color, color4?: Color): void;
|
||||
@ -1601,11 +1593,12 @@ declare module spine.webgl {
|
||||
private shader;
|
||||
private vertexIndex;
|
||||
private tmp;
|
||||
private srcBlend;
|
||||
private srcColorBlend;
|
||||
private srcAlphaBlend;
|
||||
private dstBlend;
|
||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, maxVertices?: number);
|
||||
begin(shader: Shader): void;
|
||||
setBlendMode(srcBlend: number, dstBlend: number): void;
|
||||
setBlendMode(srcColorBlend: number, srcAlphaBlend: number, dstBlend: number): void;
|
||||
setColor(color: Color): void;
|
||||
setColorWith(r: number, g: number, b: number, a: number): void;
|
||||
point(x: number, y: number, color?: Color): void;
|
||||
@ -1712,17 +1705,9 @@ declare module spine.webgl {
|
||||
removeRestorable(restorable: Restorable): void;
|
||||
}
|
||||
class WebGLBlendModeConverter {
|
||||
static ZERO: number;
|
||||
static ONE: number;
|
||||
static SRC_COLOR: number;
|
||||
static ONE_MINUS_SRC_COLOR: number;
|
||||
static SRC_ALPHA: number;
|
||||
static ONE_MINUS_SRC_ALPHA: number;
|
||||
static DST_ALPHA: number;
|
||||
static ONE_MINUS_DST_ALPHA: number;
|
||||
static DST_COLOR: number;
|
||||
static getDestGLBlendMode(blendMode: BlendMode): number;
|
||||
static getSourceGLBlendMode(blendMode: BlendMode, premultipliedAlpha?: boolean): number;
|
||||
static getDestGLBlendMode(blendMode: BlendMode): 1 | 771;
|
||||
static getSourceColorGLBlendMode(blendMode: BlendMode, premultipliedAlpha?: boolean): 1 | 770 | 774;
|
||||
static getSourceAlphaGLBlendMode(blendMode: BlendMode): 1 | 771 | 769;
|
||||
}
|
||||
}
|
||||
declare module spine.threejs {
|
||||
@ -1791,16 +1776,6 @@ declare module spine.threejs {
|
||||
}
|
||||
}
|
||||
declare module spine {
|
||||
interface Viewport {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
padLeft: string | number;
|
||||
padRight: string | number;
|
||||
padTop: string | number;
|
||||
padBottom: string | number;
|
||||
}
|
||||
interface SpinePlayerConfig {
|
||||
jsonUrl: string;
|
||||
jsonField: string;
|
||||
@ -1814,6 +1789,7 @@ declare module spine {
|
||||
skins: string[];
|
||||
premultipliedAlpha: boolean;
|
||||
showControls: boolean;
|
||||
showLoading: boolean;
|
||||
debug: {
|
||||
bones: boolean;
|
||||
regions: boolean;
|
||||
@ -1839,6 +1815,7 @@ declare module spine {
|
||||
};
|
||||
alpha: boolean;
|
||||
backgroundColor: string;
|
||||
fullScreenBackgroundColor: string;
|
||||
backgroundImage: {
|
||||
url: string;
|
||||
x: number;
|
||||
@ -1846,58 +1823,63 @@ declare module spine {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
fullScreenBackgroundColor: string;
|
||||
controlBones: string[];
|
||||
success: (widget: SpinePlayer) => void;
|
||||
error: (widget: SpinePlayer, msg: string) => void;
|
||||
downloader: spine.Downloader;
|
||||
}
|
||||
interface Viewport {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
padLeft: string | number;
|
||||
padRight: string | number;
|
||||
padTop: string | number;
|
||||
padBottom: string | number;
|
||||
}
|
||||
class SpinePlayer {
|
||||
private config;
|
||||
static HOVER_COLOR_INNER: Color;
|
||||
static HOVER_COLOR_OUTER: Color;
|
||||
static NON_HOVER_COLOR_INNER: Color;
|
||||
static NON_HOVER_COLOR_OUTER: Color;
|
||||
private sceneRenderer;
|
||||
private parent;
|
||||
private dom;
|
||||
private playerControls;
|
||||
private canvas;
|
||||
private context;
|
||||
private sceneRenderer;
|
||||
private loadingScreen;
|
||||
private assetManager;
|
||||
private bg;
|
||||
private bgFullscreen;
|
||||
private playerControls;
|
||||
private timelineSlider;
|
||||
private playButton;
|
||||
private skinButton;
|
||||
private animationButton;
|
||||
private context;
|
||||
private loadingScreen;
|
||||
private assetManager;
|
||||
private selectedBones;
|
||||
private cancelId;
|
||||
private lastPopup;
|
||||
error: boolean;
|
||||
loaded: boolean;
|
||||
skeleton: Skeleton;
|
||||
animationState: AnimationState;
|
||||
private paused;
|
||||
private playTime;
|
||||
private speed;
|
||||
private time;
|
||||
private animationViewports;
|
||||
private stopRequestAnimationFrame;
|
||||
private currentViewport;
|
||||
private previousViewport;
|
||||
private viewportTransitionStart;
|
||||
private selectedBones;
|
||||
private parent;
|
||||
private stopRequestAnimationFrame;
|
||||
constructor(parent: HTMLElement | string, config: SpinePlayerConfig);
|
||||
validateConfig(config: SpinePlayerConfig): SpinePlayerConfig;
|
||||
showError(error: string): void;
|
||||
render(): HTMLElement;
|
||||
private lastPopup;
|
||||
showSpeedDialog(speedButton: HTMLElement): void;
|
||||
showAnimationsDialog(animationsButton: HTMLElement): void;
|
||||
showSkinsDialog(skinButton: HTMLElement): void;
|
||||
showSettingsDialog(settingsButton: HTMLElement): void;
|
||||
drawFrame(requestNextFrame?: boolean): void;
|
||||
scale(sourceWidth: number, sourceHeight: number, targetWidth: number, targetHeight: number): Vector2;
|
||||
loadSkeleton(): void;
|
||||
private cancelId;
|
||||
setupInput(): void;
|
||||
private validateConfig;
|
||||
private showError;
|
||||
private render;
|
||||
private showSpeedDialog;
|
||||
private showAnimationsDialog;
|
||||
private showSkinsDialog;
|
||||
private showSettingsDialog;
|
||||
private drawFrame;
|
||||
private scale;
|
||||
private loadSkeleton;
|
||||
private setupInput;
|
||||
private play;
|
||||
private pause;
|
||||
setAnimation(animation: string, loop?: boolean): void;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
spine-ts/build/spine-canvas.d.ts
vendored
2
spine-ts/build/spine-canvas.d.ts
vendored
@ -362,7 +362,7 @@ declare module spine {
|
||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement | ImageBitmap) => void, error?: (path: string, message: string) => void): void;
|
||||
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, message: string) => void): void;
|
||||
get(path: string): any;
|
||||
remove(path: string): void;
|
||||
remove(path: string): any;
|
||||
removeAll(): void;
|
||||
isLoadingComplete(): boolean;
|
||||
getToLoad(): number;
|
||||
|
||||
@ -2918,6 +2918,7 @@ var spine;
|
||||
if (asset.dispose)
|
||||
asset.dispose();
|
||||
delete this.assets[path];
|
||||
return asset;
|
||||
};
|
||||
AssetManager.prototype.removeAll = function () {
|
||||
for (var key in this.assets) {
|
||||
@ -8101,8 +8102,7 @@ var spine;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
};
|
||||
Color.prototype.setFromColor = function (c) {
|
||||
this.r = c.r;
|
||||
@ -8113,10 +8113,10 @@ var spine;
|
||||
};
|
||||
Color.prototype.setFromString = function (hex) {
|
||||
hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
|
||||
this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255;
|
||||
this.a = (hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255);
|
||||
return this;
|
||||
};
|
||||
Color.prototype.add = function (r, g, b, a) {
|
||||
@ -8124,8 +8124,7 @@ var spine;
|
||||
this.g += g;
|
||||
this.b += b;
|
||||
this.a += a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
};
|
||||
Color.prototype.clamp = function () {
|
||||
if (this.r < 0)
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
spine-ts/build/spine-core.d.ts
vendored
2
spine-ts/build/spine-core.d.ts
vendored
@ -362,7 +362,7 @@ declare module spine {
|
||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement | ImageBitmap) => void, error?: (path: string, message: string) => void): void;
|
||||
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, message: string) => void): void;
|
||||
get(path: string): any;
|
||||
remove(path: string): void;
|
||||
remove(path: string): any;
|
||||
removeAll(): void;
|
||||
isLoadingComplete(): boolean;
|
||||
getToLoad(): number;
|
||||
|
||||
@ -2918,6 +2918,7 @@ var spine;
|
||||
if (asset.dispose)
|
||||
asset.dispose();
|
||||
delete this.assets[path];
|
||||
return asset;
|
||||
};
|
||||
AssetManager.prototype.removeAll = function () {
|
||||
for (var key in this.assets) {
|
||||
@ -8101,8 +8102,7 @@ var spine;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
};
|
||||
Color.prototype.setFromColor = function (c) {
|
||||
this.r = c.r;
|
||||
@ -8113,10 +8113,10 @@ var spine;
|
||||
};
|
||||
Color.prototype.setFromString = function (hex) {
|
||||
hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
|
||||
this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255;
|
||||
this.a = (hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255);
|
||||
return this;
|
||||
};
|
||||
Color.prototype.add = function (r, g, b, a) {
|
||||
@ -8124,8 +8124,7 @@ var spine;
|
||||
this.g += g;
|
||||
this.b += b;
|
||||
this.a += a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
};
|
||||
Color.prototype.clamp = function () {
|
||||
if (this.r < 0)
|
||||
|
||||
File diff suppressed because one or more lines are too long
114
spine-ts/build/spine-player.d.ts
vendored
114
spine-ts/build/spine-player.d.ts
vendored
@ -362,7 +362,7 @@ declare module spine {
|
||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement | ImageBitmap) => void, error?: (path: string, message: string) => void): void;
|
||||
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, message: string) => void): void;
|
||||
get(path: string): any;
|
||||
remove(path: string): void;
|
||||
remove(path: string): any;
|
||||
removeAll(): void;
|
||||
isLoadingComplete(): boolean;
|
||||
getToLoad(): number;
|
||||
@ -1329,21 +1329,15 @@ declare module spine.webgl {
|
||||
}
|
||||
declare module spine.webgl {
|
||||
class LoadingScreen {
|
||||
static FADE_SECONDS: number;
|
||||
private static loaded;
|
||||
private static spinnerImg;
|
||||
private static logoImg;
|
||||
private renderer;
|
||||
private logo;
|
||||
private spinner;
|
||||
private angle;
|
||||
private fadeOut;
|
||||
private fadeIn;
|
||||
private timeKeeper;
|
||||
backgroundColor: Color;
|
||||
private tempColor;
|
||||
private firstDraw;
|
||||
private static SPINNER_DATA;
|
||||
private static SPINE_LOGO_DATA;
|
||||
constructor(renderer: SceneRenderer);
|
||||
draw(complete?: boolean): void;
|
||||
}
|
||||
@ -1458,11 +1452,12 @@ declare module spine.webgl {
|
||||
private lastTexture;
|
||||
private verticesLength;
|
||||
private indicesLength;
|
||||
private srcBlend;
|
||||
private srcColorBlend;
|
||||
private srcAlphaBlend;
|
||||
private dstBlend;
|
||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint?: boolean, maxVertices?: number);
|
||||
begin(shader: Shader): void;
|
||||
setBlendMode(srcBlend: number, dstBlend: number): void;
|
||||
setBlendMode(srcColorBlend: number, srcAlphaBlend: number, dstBlend: number): void;
|
||||
draw(texture: GLTexture, vertices: ArrayLike<number>, indices: Array<number>): void;
|
||||
private flush;
|
||||
end(): void;
|
||||
@ -1483,17 +1478,14 @@ declare module spine.webgl {
|
||||
private activeRenderer;
|
||||
skeletonRenderer: SkeletonRenderer;
|
||||
skeletonDebugRenderer: SkeletonDebugRenderer;
|
||||
private QUAD;
|
||||
private QUAD_TRIANGLES;
|
||||
private WHITE;
|
||||
constructor(canvas: HTMLCanvasElement, context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint?: boolean);
|
||||
begin(): void;
|
||||
drawSkeleton(skeleton: Skeleton, premultipliedAlpha?: boolean, slotRangeStart?: number, slotRangeEnd?: number): void;
|
||||
drawSkeletonDebug(skeleton: Skeleton, premultipliedAlpha?: boolean, ignoredBones?: Array<string>): void;
|
||||
drawTexture(texture: GLTexture, x: number, y: number, width: number, height: number, color?: Color): void;
|
||||
drawTextureUV(texture: GLTexture, x: number, y: number, width: number, height: number, u: number, v: number, u2: number, v2: number, color?: Color): void;
|
||||
drawTextureRotated(texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color?: Color, premultipliedAlpha?: boolean): void;
|
||||
drawRegion(region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color?: Color, premultipliedAlpha?: boolean): void;
|
||||
drawTextureRotated(texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color?: Color): void;
|
||||
drawRegion(region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color?: Color): void;
|
||||
line(x: number, y: number, x2: number, y2: number, color?: Color, color2?: Color): void;
|
||||
triangle(filled: boolean, x: number, y: number, x2: number, y2: number, x3: number, y3: number, color?: Color, color2?: Color, color3?: Color): void;
|
||||
quad(filled: boolean, x: number, y: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number, color?: Color, color2?: Color, color3?: Color, color4?: Color): void;
|
||||
@ -1570,11 +1562,12 @@ declare module spine.webgl {
|
||||
private shader;
|
||||
private vertexIndex;
|
||||
private tmp;
|
||||
private srcBlend;
|
||||
private srcColorBlend;
|
||||
private srcAlphaBlend;
|
||||
private dstBlend;
|
||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, maxVertices?: number);
|
||||
begin(shader: Shader): void;
|
||||
setBlendMode(srcBlend: number, dstBlend: number): void;
|
||||
setBlendMode(srcColorBlend: number, srcAlphaBlend: number, dstBlend: number): void;
|
||||
setColor(color: Color): void;
|
||||
setColorWith(r: number, g: number, b: number, a: number): void;
|
||||
point(x: number, y: number, color?: Color): void;
|
||||
@ -1681,30 +1674,12 @@ declare module spine.webgl {
|
||||
removeRestorable(restorable: Restorable): void;
|
||||
}
|
||||
class WebGLBlendModeConverter {
|
||||
static ZERO: number;
|
||||
static ONE: number;
|
||||
static SRC_COLOR: number;
|
||||
static ONE_MINUS_SRC_COLOR: number;
|
||||
static SRC_ALPHA: number;
|
||||
static ONE_MINUS_SRC_ALPHA: number;
|
||||
static DST_ALPHA: number;
|
||||
static ONE_MINUS_DST_ALPHA: number;
|
||||
static DST_COLOR: number;
|
||||
static getDestGLBlendMode(blendMode: BlendMode): number;
|
||||
static getSourceGLBlendMode(blendMode: BlendMode, premultipliedAlpha?: boolean): number;
|
||||
static getDestGLBlendMode(blendMode: BlendMode): 1 | 771;
|
||||
static getSourceColorGLBlendMode(blendMode: BlendMode, premultipliedAlpha?: boolean): 1 | 770 | 774;
|
||||
static getSourceAlphaGLBlendMode(blendMode: BlendMode): 1 | 771 | 769;
|
||||
}
|
||||
}
|
||||
declare module spine {
|
||||
interface Viewport {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
padLeft: string | number;
|
||||
padRight: string | number;
|
||||
padTop: string | number;
|
||||
padBottom: string | number;
|
||||
}
|
||||
interface SpinePlayerConfig {
|
||||
jsonUrl: string;
|
||||
jsonField: string;
|
||||
@ -1718,6 +1693,7 @@ declare module spine {
|
||||
skins: string[];
|
||||
premultipliedAlpha: boolean;
|
||||
showControls: boolean;
|
||||
showLoading: boolean;
|
||||
debug: {
|
||||
bones: boolean;
|
||||
regions: boolean;
|
||||
@ -1743,6 +1719,7 @@ declare module spine {
|
||||
};
|
||||
alpha: boolean;
|
||||
backgroundColor: string;
|
||||
fullScreenBackgroundColor: string;
|
||||
backgroundImage: {
|
||||
url: string;
|
||||
x: number;
|
||||
@ -1750,58 +1727,63 @@ declare module spine {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
fullScreenBackgroundColor: string;
|
||||
controlBones: string[];
|
||||
success: (widget: SpinePlayer) => void;
|
||||
error: (widget: SpinePlayer, msg: string) => void;
|
||||
downloader: spine.Downloader;
|
||||
}
|
||||
interface Viewport {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
padLeft: string | number;
|
||||
padRight: string | number;
|
||||
padTop: string | number;
|
||||
padBottom: string | number;
|
||||
}
|
||||
class SpinePlayer {
|
||||
private config;
|
||||
static HOVER_COLOR_INNER: Color;
|
||||
static HOVER_COLOR_OUTER: Color;
|
||||
static NON_HOVER_COLOR_INNER: Color;
|
||||
static NON_HOVER_COLOR_OUTER: Color;
|
||||
private sceneRenderer;
|
||||
private parent;
|
||||
private dom;
|
||||
private playerControls;
|
||||
private canvas;
|
||||
private context;
|
||||
private sceneRenderer;
|
||||
private loadingScreen;
|
||||
private assetManager;
|
||||
private bg;
|
||||
private bgFullscreen;
|
||||
private playerControls;
|
||||
private timelineSlider;
|
||||
private playButton;
|
||||
private skinButton;
|
||||
private animationButton;
|
||||
private context;
|
||||
private loadingScreen;
|
||||
private assetManager;
|
||||
private selectedBones;
|
||||
private cancelId;
|
||||
private lastPopup;
|
||||
error: boolean;
|
||||
loaded: boolean;
|
||||
skeleton: Skeleton;
|
||||
animationState: AnimationState;
|
||||
private paused;
|
||||
private playTime;
|
||||
private speed;
|
||||
private time;
|
||||
private animationViewports;
|
||||
private stopRequestAnimationFrame;
|
||||
private currentViewport;
|
||||
private previousViewport;
|
||||
private viewportTransitionStart;
|
||||
private selectedBones;
|
||||
private parent;
|
||||
private stopRequestAnimationFrame;
|
||||
constructor(parent: HTMLElement | string, config: SpinePlayerConfig);
|
||||
validateConfig(config: SpinePlayerConfig): SpinePlayerConfig;
|
||||
showError(error: string): void;
|
||||
render(): HTMLElement;
|
||||
private lastPopup;
|
||||
showSpeedDialog(speedButton: HTMLElement): void;
|
||||
showAnimationsDialog(animationsButton: HTMLElement): void;
|
||||
showSkinsDialog(skinButton: HTMLElement): void;
|
||||
showSettingsDialog(settingsButton: HTMLElement): void;
|
||||
drawFrame(requestNextFrame?: boolean): void;
|
||||
scale(sourceWidth: number, sourceHeight: number, targetWidth: number, targetHeight: number): Vector2;
|
||||
loadSkeleton(): void;
|
||||
private cancelId;
|
||||
setupInput(): void;
|
||||
private validateConfig;
|
||||
private showError;
|
||||
private render;
|
||||
private showSpeedDialog;
|
||||
private showAnimationsDialog;
|
||||
private showSkinsDialog;
|
||||
private showSettingsDialog;
|
||||
private drawFrame;
|
||||
private scale;
|
||||
private loadSkeleton;
|
||||
private setupInput;
|
||||
private play;
|
||||
private pause;
|
||||
setAnimation(animation: string, loop?: boolean): void;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
spine-ts/build/spine-threejs.d.ts
vendored
2
spine-ts/build/spine-threejs.d.ts
vendored
@ -362,7 +362,7 @@ declare module spine {
|
||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement | ImageBitmap) => void, error?: (path: string, message: string) => void): void;
|
||||
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, message: string) => void): void;
|
||||
get(path: string): any;
|
||||
remove(path: string): void;
|
||||
remove(path: string): any;
|
||||
removeAll(): void;
|
||||
isLoadingComplete(): boolean;
|
||||
getToLoad(): number;
|
||||
|
||||
@ -2918,6 +2918,7 @@ var spine;
|
||||
if (asset.dispose)
|
||||
asset.dispose();
|
||||
delete this.assets[path];
|
||||
return asset;
|
||||
};
|
||||
AssetManager.prototype.removeAll = function () {
|
||||
for (var key in this.assets) {
|
||||
@ -8101,8 +8102,7 @@ var spine;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
};
|
||||
Color.prototype.setFromColor = function (c) {
|
||||
this.r = c.r;
|
||||
@ -8113,10 +8113,10 @@ var spine;
|
||||
};
|
||||
Color.prototype.setFromString = function (hex) {
|
||||
hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
|
||||
this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255;
|
||||
this.a = (hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255);
|
||||
return this;
|
||||
};
|
||||
Color.prototype.add = function (r, g, b, a) {
|
||||
@ -8124,8 +8124,7 @@ var spine;
|
||||
this.g += g;
|
||||
this.b += b;
|
||||
this.a += a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
};
|
||||
Color.prototype.clamp = function () {
|
||||
if (this.r < 0)
|
||||
|
||||
File diff suppressed because one or more lines are too long
41
spine-ts/build/spine-webgl.d.ts
vendored
41
spine-ts/build/spine-webgl.d.ts
vendored
@ -362,7 +362,7 @@ declare module spine {
|
||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement | ImageBitmap) => void, error?: (path: string, message: string) => void): void;
|
||||
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, message: string) => void): void;
|
||||
get(path: string): any;
|
||||
remove(path: string): void;
|
||||
remove(path: string): any;
|
||||
removeAll(): void;
|
||||
isLoadingComplete(): boolean;
|
||||
getToLoad(): number;
|
||||
@ -1329,21 +1329,15 @@ declare module spine.webgl {
|
||||
}
|
||||
declare module spine.webgl {
|
||||
class LoadingScreen {
|
||||
static FADE_SECONDS: number;
|
||||
private static loaded;
|
||||
private static spinnerImg;
|
||||
private static logoImg;
|
||||
private renderer;
|
||||
private logo;
|
||||
private spinner;
|
||||
private angle;
|
||||
private fadeOut;
|
||||
private fadeIn;
|
||||
private timeKeeper;
|
||||
backgroundColor: Color;
|
||||
private tempColor;
|
||||
private firstDraw;
|
||||
private static SPINNER_DATA;
|
||||
private static SPINE_LOGO_DATA;
|
||||
constructor(renderer: SceneRenderer);
|
||||
draw(complete?: boolean): void;
|
||||
}
|
||||
@ -1458,11 +1452,12 @@ declare module spine.webgl {
|
||||
private lastTexture;
|
||||
private verticesLength;
|
||||
private indicesLength;
|
||||
private srcBlend;
|
||||
private srcColorBlend;
|
||||
private srcAlphaBlend;
|
||||
private dstBlend;
|
||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint?: boolean, maxVertices?: number);
|
||||
begin(shader: Shader): void;
|
||||
setBlendMode(srcBlend: number, dstBlend: number): void;
|
||||
setBlendMode(srcColorBlend: number, srcAlphaBlend: number, dstBlend: number): void;
|
||||
draw(texture: GLTexture, vertices: ArrayLike<number>, indices: Array<number>): void;
|
||||
private flush;
|
||||
end(): void;
|
||||
@ -1483,17 +1478,14 @@ declare module spine.webgl {
|
||||
private activeRenderer;
|
||||
skeletonRenderer: SkeletonRenderer;
|
||||
skeletonDebugRenderer: SkeletonDebugRenderer;
|
||||
private QUAD;
|
||||
private QUAD_TRIANGLES;
|
||||
private WHITE;
|
||||
constructor(canvas: HTMLCanvasElement, context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint?: boolean);
|
||||
begin(): void;
|
||||
drawSkeleton(skeleton: Skeleton, premultipliedAlpha?: boolean, slotRangeStart?: number, slotRangeEnd?: number): void;
|
||||
drawSkeletonDebug(skeleton: Skeleton, premultipliedAlpha?: boolean, ignoredBones?: Array<string>): void;
|
||||
drawTexture(texture: GLTexture, x: number, y: number, width: number, height: number, color?: Color): void;
|
||||
drawTextureUV(texture: GLTexture, x: number, y: number, width: number, height: number, u: number, v: number, u2: number, v2: number, color?: Color): void;
|
||||
drawTextureRotated(texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color?: Color, premultipliedAlpha?: boolean): void;
|
||||
drawRegion(region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color?: Color, premultipliedAlpha?: boolean): void;
|
||||
drawTextureRotated(texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color?: Color): void;
|
||||
drawRegion(region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color?: Color): void;
|
||||
line(x: number, y: number, x2: number, y2: number, color?: Color, color2?: Color): void;
|
||||
triangle(filled: boolean, x: number, y: number, x2: number, y2: number, x3: number, y3: number, color?: Color, color2?: Color, color3?: Color): void;
|
||||
quad(filled: boolean, x: number, y: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number, color?: Color, color2?: Color, color3?: Color, color4?: Color): void;
|
||||
@ -1570,11 +1562,12 @@ declare module spine.webgl {
|
||||
private shader;
|
||||
private vertexIndex;
|
||||
private tmp;
|
||||
private srcBlend;
|
||||
private srcColorBlend;
|
||||
private srcAlphaBlend;
|
||||
private dstBlend;
|
||||
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, maxVertices?: number);
|
||||
begin(shader: Shader): void;
|
||||
setBlendMode(srcBlend: number, dstBlend: number): void;
|
||||
setBlendMode(srcColorBlend: number, srcAlphaBlend: number, dstBlend: number): void;
|
||||
setColor(color: Color): void;
|
||||
setColorWith(r: number, g: number, b: number, a: number): void;
|
||||
point(x: number, y: number, color?: Color): void;
|
||||
@ -1681,16 +1674,8 @@ declare module spine.webgl {
|
||||
removeRestorable(restorable: Restorable): void;
|
||||
}
|
||||
class WebGLBlendModeConverter {
|
||||
static ZERO: number;
|
||||
static ONE: number;
|
||||
static SRC_COLOR: number;
|
||||
static ONE_MINUS_SRC_COLOR: number;
|
||||
static SRC_ALPHA: number;
|
||||
static ONE_MINUS_SRC_ALPHA: number;
|
||||
static DST_ALPHA: number;
|
||||
static ONE_MINUS_DST_ALPHA: number;
|
||||
static DST_COLOR: number;
|
||||
static getDestGLBlendMode(blendMode: BlendMode): number;
|
||||
static getSourceGLBlendMode(blendMode: BlendMode, premultipliedAlpha?: boolean): number;
|
||||
static getDestGLBlendMode(blendMode: BlendMode): 1 | 771;
|
||||
static getSourceColorGLBlendMode(blendMode: BlendMode, premultipliedAlpha?: boolean): 1 | 770 | 774;
|
||||
static getSourceAlphaGLBlendMode(blendMode: BlendMode): 1 | 771 | 769;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -191,6 +191,7 @@ module spine {
|
||||
let asset = this.assets[path];
|
||||
if ((<any>asset).dispose) (<any>asset).dispose();
|
||||
delete this.assets[path];
|
||||
return asset;
|
||||
}
|
||||
|
||||
removeAll () {
|
||||
|
||||
@ -108,8 +108,7 @@ module spine {
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
}
|
||||
|
||||
setFromColor (c: Color) {
|
||||
@ -122,10 +121,10 @@ module spine {
|
||||
|
||||
setFromString (hex: string) {
|
||||
hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
|
||||
this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
|
||||
this.r = parseInt(hex.substr(0, 2), 16) / 255;
|
||||
this.g = parseInt(hex.substr(2, 2), 16) / 255;
|
||||
this.b = parseInt(hex.substr(4, 2), 16) / 255;
|
||||
this.a = (hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -134,8 +133,7 @@ module spine {
|
||||
this.g += g;
|
||||
this.b += b;
|
||||
this.a += a;
|
||||
this.clamp();
|
||||
return this;
|
||||
return this.clamp();
|
||||
}
|
||||
|
||||
clamp () {
|
||||
|
||||
@ -15,8 +15,8 @@ body {
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div id="container" style="width: 640px; height: 380px;"></div>
|
||||
<div id="container-raptor" style="width: 640px; height: 380px;"></div>
|
||||
<div id="container" style="width:640px; height:380px; background:#cccccc"></div>
|
||||
<div id="container-raptor" style="width:640px; height:380px;"></div>
|
||||
<div>
|
||||
<button id="walk">Walk</button>
|
||||
<button id="jump">Jump</button>
|
||||
@ -50,6 +50,7 @@ body {
|
||||
backgroundColor: "#00000000",
|
||||
alpha: true,
|
||||
defaultMix: 1,
|
||||
controlBones: ["root"],
|
||||
success: (player) => {
|
||||
// Register button click event handlers once the
|
||||
// skeleton has been loaded successfully
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -52,7 +52,7 @@ module spine.webgl {
|
||||
}
|
||||
|
||||
static validateMagFilter (magFilter: TextureFilter) {
|
||||
switch(magFilter) {
|
||||
switch (magFilter) {
|
||||
case TextureFilter.MipMap:
|
||||
case TextureFilter.MipMapLinearLinear:
|
||||
case TextureFilter.MipMapLinearNearest:
|
||||
@ -73,9 +73,7 @@ module spine.webgl {
|
||||
|
||||
update (useMipMaps: boolean) {
|
||||
let gl = this.context.gl;
|
||||
if (!this.texture) {
|
||||
this.texture = this.context.gl.createTexture();
|
||||
}
|
||||
if (!this.texture) this.texture = this.context.gl.createTexture();
|
||||
this.bind();
|
||||
if (GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL) gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -37,7 +37,8 @@ module spine.webgl {
|
||||
private lastTexture: GLTexture = null;
|
||||
private verticesLength = 0;
|
||||
private indicesLength = 0;
|
||||
private srcBlend: number;
|
||||
private srcColorBlend: number;
|
||||
private srcAlphaBlend: number;
|
||||
private dstBlend: number;
|
||||
|
||||
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint: boolean = true, maxVertices: number = 10920) {
|
||||
@ -47,29 +48,32 @@ module spine.webgl {
|
||||
[new Position2Attribute(), new ColorAttribute(), new TexCoordAttribute(), new Color2Attribute()] :
|
||||
[new Position2Attribute(), new ColorAttribute(), new TexCoordAttribute()];
|
||||
this.mesh = new Mesh(context, attributes, maxVertices, maxVertices * 3);
|
||||
this.srcBlend = this.context.gl.SRC_ALPHA;
|
||||
this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
|
||||
let gl = this.context.gl;
|
||||
this.srcColorBlend = gl.SRC_ALPHA;
|
||||
this.srcAlphaBlend = gl.ONE;
|
||||
this.dstBlend = gl.ONE_MINUS_SRC_ALPHA;
|
||||
}
|
||||
|
||||
begin (shader: Shader) {
|
||||
let gl = this.context.gl;
|
||||
if (this.isDrawing) throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()");
|
||||
this.drawCalls = 0;
|
||||
this.shader = shader;
|
||||
this.lastTexture = null;
|
||||
this.isDrawing = true;
|
||||
|
||||
let gl = this.context.gl;
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(this.srcBlend, this.dstBlend);
|
||||
gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
|
||||
}
|
||||
|
||||
setBlendMode (srcBlend: number, dstBlend: number) {
|
||||
let gl = this.context.gl;
|
||||
this.srcBlend = srcBlend;
|
||||
setBlendMode (srcColorBlend: number, srcAlphaBlend: number, dstBlend: number) {
|
||||
this.srcColorBlend = srcColorBlend;
|
||||
this.srcAlphaBlend = srcAlphaBlend;
|
||||
this.dstBlend = dstBlend;
|
||||
if (this.isDrawing) {
|
||||
this.flush();
|
||||
gl.blendFunc(this.srcBlend, this.dstBlend);
|
||||
let gl = this.context.gl;
|
||||
gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,11 +99,10 @@ module spine.webgl {
|
||||
}
|
||||
|
||||
private flush () {
|
||||
let gl = this.context.gl;
|
||||
if (this.verticesLength == 0) return;
|
||||
|
||||
this.lastTexture.bind();
|
||||
this.mesh.draw(this.shader, gl.TRIANGLES);
|
||||
this.mesh.draw(this.shader, this.context.gl.TRIANGLES);
|
||||
|
||||
this.verticesLength = 0;
|
||||
this.indicesLength = 0;
|
||||
@ -109,17 +112,19 @@ module spine.webgl {
|
||||
}
|
||||
|
||||
end () {
|
||||
let gl = this.context.gl;
|
||||
if (!this.isDrawing) throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()");
|
||||
if (this.verticesLength > 0 || this.indicesLength > 0) this.flush();
|
||||
this.shader = null;
|
||||
this.lastTexture = null;
|
||||
this.isDrawing = false;
|
||||
|
||||
let gl = this.context.gl;
|
||||
gl.disable(gl.BLEND);
|
||||
}
|
||||
|
||||
getDrawCalls () { return this.drawCalls; }
|
||||
getDrawCalls () {
|
||||
return this.drawCalls;
|
||||
}
|
||||
|
||||
dispose () {
|
||||
this.mesh.dispose();
|
||||
|
||||
@ -28,6 +28,15 @@
|
||||
*****************************************************************************/
|
||||
|
||||
module spine.webgl {
|
||||
const quad = [
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
];
|
||||
const QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
|
||||
const WHITE = new Color(1, 1, 1, 1);
|
||||
|
||||
export class SceneRenderer implements Disposable {
|
||||
context: ManagedWebGLRenderingContext;
|
||||
canvas: HTMLCanvasElement;
|
||||
@ -37,17 +46,9 @@ module spine.webgl {
|
||||
private batcherShader: Shader;
|
||||
private shapes: ShapeRenderer;
|
||||
private shapesShader: Shader;
|
||||
private activeRenderer: PolygonBatcher | ShapeRenderer | SkeletonDebugRenderer = null;
|
||||
private activeRenderer: PolygonBatcher | ShapeRenderer | SkeletonDebugRenderer;
|
||||
skeletonRenderer: SkeletonRenderer;
|
||||
skeletonDebugRenderer: SkeletonDebugRenderer;
|
||||
private QUAD = [
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 1, 1, 1, 1, 0, 0,
|
||||
];
|
||||
private QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
|
||||
private WHITE = new Color(1, 1, 1, 1);
|
||||
|
||||
constructor (canvas: HTMLCanvasElement, context: ManagedWebGLRenderingContext | WebGLRenderingContext, twoColorTint: boolean = true) {
|
||||
this.canvas = canvas;
|
||||
@ -73,7 +74,7 @@ module spine.webgl {
|
||||
this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd);
|
||||
}
|
||||
|
||||
drawSkeletonDebug(skeleton: Skeleton, premultipliedAlpha = false, ignoredBones: Array<string> = null) {
|
||||
drawSkeletonDebug (skeleton: Skeleton, premultipliedAlpha = false, ignoredBones: Array<string> = null) {
|
||||
this.enableRenderer(this.shapes);
|
||||
this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha;
|
||||
this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones);
|
||||
@ -81,8 +82,7 @@ module spine.webgl {
|
||||
|
||||
drawTexture (texture: GLTexture, x: number, y: number, width: number, height: number, color: Color = null) {
|
||||
this.enableRenderer(this.batcher);
|
||||
if (color === null) color = this.WHITE;
|
||||
let quad = this.QUAD;
|
||||
if (color === null) color = WHITE;
|
||||
var i = 0;
|
||||
quad[i++] = x;
|
||||
quad[i++] = y;
|
||||
@ -140,13 +140,12 @@ module spine.webgl {
|
||||
quad[i++] = 0;
|
||||
quad[i] = 0;
|
||||
}
|
||||
this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
|
||||
this.batcher.draw(texture, quad, QUAD_TRIANGLES);
|
||||
}
|
||||
|
||||
drawTextureUV (texture: GLTexture, x: number, y: number, width: number, height: number, u: number, v: number, u2: number, v2: number, color: Color = null) {
|
||||
this.enableRenderer(this.batcher);
|
||||
if (color === null) color = this.WHITE;
|
||||
let quad = this.QUAD;
|
||||
if (color === null) color = WHITE;
|
||||
var i = 0;
|
||||
quad[i++] = x;
|
||||
quad[i++] = y;
|
||||
@ -204,13 +203,12 @@ module spine.webgl {
|
||||
quad[i++] = 0;
|
||||
quad[i] = 0;
|
||||
}
|
||||
this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
|
||||
this.batcher.draw(texture, quad, QUAD_TRIANGLES);
|
||||
}
|
||||
|
||||
drawTextureRotated (texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color: Color = null, premultipliedAlpha: boolean = false) {
|
||||
drawTextureRotated (texture: GLTexture, x: number, y: number, width: number, height: number, pivotX: number, pivotY: number, angle: number, color: Color = null) {
|
||||
this.enableRenderer(this.batcher);
|
||||
if (color === null) color = this.WHITE;
|
||||
let quad = this.QUAD;
|
||||
if (color === null) color = WHITE;
|
||||
|
||||
// bottom left and top right corner points relative to origin
|
||||
let worldOriginX = x + pivotX;
|
||||
@ -335,13 +333,12 @@ module spine.webgl {
|
||||
quad[i++] = 0;
|
||||
quad[i] = 0;
|
||||
}
|
||||
this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
|
||||
this.batcher.draw(texture, quad, QUAD_TRIANGLES);
|
||||
}
|
||||
|
||||
drawRegion (region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color: Color = null, premultipliedAlpha: boolean = false) {
|
||||
drawRegion (region: TextureAtlasRegion, x: number, y: number, width: number, height: number, color: Color = null) {
|
||||
this.enableRenderer(this.batcher);
|
||||
if (color === null) color = this.WHITE;
|
||||
let quad = this.QUAD;
|
||||
if (color === null) color = WHITE;
|
||||
var i = 0;
|
||||
quad[i++] = x;
|
||||
quad[i++] = y;
|
||||
@ -399,7 +396,7 @@ module spine.webgl {
|
||||
quad[i++] = 0;
|
||||
quad[i] = 0;
|
||||
}
|
||||
this.batcher.draw(<GLTexture>region.texture, quad, this.QUAD_TRIANGLES);
|
||||
this.batcher.draw(<GLTexture>region.texture, quad, QUAD_TRIANGLES);
|
||||
}
|
||||
|
||||
line (x: number, y: number, x2: number, y2: number, color: Color = null, color2: Color = null) {
|
||||
@ -458,11 +455,10 @@ module spine.webgl {
|
||||
}
|
||||
this.context.gl.viewport(0, 0, canvas.width, canvas.height);
|
||||
|
||||
if (resizeMode === ResizeMode.Stretch) {
|
||||
// nothing to do, we simply apply the viewport size of the camera
|
||||
} else if (resizeMode === ResizeMode.Expand) {
|
||||
// Nothing to do for stretch, we simply apply the viewport size of the camera.
|
||||
if (resizeMode === ResizeMode.Expand)
|
||||
this.camera.setViewport(w, h);
|
||||
} else if (resizeMode === ResizeMode.Fit) {
|
||||
else if (resizeMode === ResizeMode.Fit) {
|
||||
let sourceWidth = canvas.width, sourceHeight = canvas.height;
|
||||
let targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHeight;
|
||||
let targetRatio = targetHeight / targetWidth;
|
||||
|
||||
@ -37,15 +37,18 @@ module spine.webgl {
|
||||
private shader: Shader;
|
||||
private vertexIndex = 0;
|
||||
private tmp = new Vector2();
|
||||
private srcBlend: number;
|
||||
private srcColorBlend: number;
|
||||
private srcAlphaBlend: number;
|
||||
private dstBlend: number;
|
||||
|
||||
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, maxVertices: number = 10920) {
|
||||
if (maxVertices > 10920) throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
|
||||
this.context = context instanceof ManagedWebGLRenderingContext? context : new ManagedWebGLRenderingContext(context);
|
||||
this.mesh = new Mesh(context, [new Position2Attribute(), new ColorAttribute()], maxVertices, 0);
|
||||
this.srcBlend = this.context.gl.SRC_ALPHA;
|
||||
this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
|
||||
let gl = this.context.gl;
|
||||
this.srcColorBlend = gl.SRC_ALPHA;
|
||||
this.srcAlphaBlend = gl.ONE;
|
||||
this.dstBlend = gl.ONE_MINUS_SRC_ALPHA;
|
||||
}
|
||||
|
||||
begin (shader: Shader) {
|
||||
@ -56,16 +59,17 @@ module spine.webgl {
|
||||
|
||||
let gl = this.context.gl;
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(this.srcBlend, this.dstBlend);
|
||||
gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
|
||||
}
|
||||
|
||||
setBlendMode (srcBlend: number, dstBlend: number) {
|
||||
let gl = this.context.gl;
|
||||
this.srcBlend = srcBlend;
|
||||
setBlendMode (srcColorBlend: number, srcAlphaBlend: number, dstBlend: number) {
|
||||
this.srcColorBlend = srcColorBlend;
|
||||
this.srcAlphaBlend = srcAlphaBlend;
|
||||
this.dstBlend = dstBlend;
|
||||
if (this.isDrawing) {
|
||||
this.flush();
|
||||
gl.blendFunc(this.srcBlend, this.dstBlend);
|
||||
let gl = this.context.gl;
|
||||
gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +313,8 @@ module spine.webgl {
|
||||
end () {
|
||||
if (!this.isDrawing) throw new Error("ShapeRenderer.begin() has not been called");
|
||||
this.flush();
|
||||
this.context.gl.disable(this.context.gl.BLEND);
|
||||
let gl = this.context.gl;
|
||||
gl.disable(gl.BLEND);
|
||||
this.isDrawing = false;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ module spine.webgl {
|
||||
let skeletonY = skeleton.y;
|
||||
let gl = this.context.gl;
|
||||
let srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA;
|
||||
shapes.setBlendMode(srcFunc, gl.ONE_MINUS_SRC_ALPHA);
|
||||
shapes.setBlendMode(srcFunc, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
let bones = skeleton.bones;
|
||||
if (this.drawBones) {
|
||||
|
||||
@ -160,7 +160,10 @@ module spine.webgl {
|
||||
let slotBlendMode = slot.data.blendMode;
|
||||
if (slotBlendMode != blendMode) {
|
||||
blendMode = slotBlendMode;
|
||||
batcher.setBlendMode(WebGLBlendModeConverter.getSourceGLBlendMode(blendMode, premultipliedAlpha), WebGLBlendModeConverter.getDestGLBlendMode(blendMode));
|
||||
batcher.setBlendMode(
|
||||
WebGLBlendModeConverter.getSourceColorGLBlendMode(blendMode, premultipliedAlpha),
|
||||
WebGLBlendModeConverter.getSourceAlphaGLBlendMode(blendMode),
|
||||
WebGLBlendModeConverter.getDestGLBlendMode(blendMode));
|
||||
}
|
||||
|
||||
if (clipper.isClipping()) {
|
||||
|
||||
@ -34,9 +34,9 @@ module spine.webgl {
|
||||
private restorables = new Array<Restorable>();
|
||||
|
||||
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext | EventTarget | WebGL2RenderingContext, contextConfig: any = { alpha: "true" }) {
|
||||
if (!((canvasOrContext instanceof WebGLRenderingContext) || (canvasOrContext instanceof WebGL2RenderingContext))) {
|
||||
if (!((canvasOrContext instanceof WebGLRenderingContext) || (canvasOrContext instanceof WebGL2RenderingContext)))
|
||||
this.setupCanvas(canvasOrContext, contextConfig);
|
||||
} else {
|
||||
else {
|
||||
this.gl = canvasOrContext;
|
||||
this.canvas = this.gl.canvas;
|
||||
}
|
||||
@ -47,15 +47,12 @@ module spine.webgl {
|
||||
this.canvas = canvas;
|
||||
canvas.addEventListener("webglcontextlost", (e: any) => {
|
||||
let event = <WebGLContextEvent>e;
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
if (e) e.preventDefault();
|
||||
});
|
||||
|
||||
canvas.addEventListener("webglcontextrestored", (e: any) => {
|
||||
for (let i = 0, n = this.restorables.length; i < n; i++) {
|
||||
for (let i = 0, n = this.restorables.length; i < n; i++)
|
||||
this.restorables[i].restore();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -69,34 +66,41 @@ module spine.webgl {
|
||||
}
|
||||
}
|
||||
|
||||
export class WebGLBlendModeConverter {
|
||||
static ZERO = 0;
|
||||
static ONE = 1;
|
||||
static SRC_COLOR = 0x0300;
|
||||
static ONE_MINUS_SRC_COLOR = 0x0301;
|
||||
static SRC_ALPHA = 0x0302;
|
||||
static ONE_MINUS_SRC_ALPHA = 0x0303;
|
||||
static DST_ALPHA = 0x0304;
|
||||
static ONE_MINUS_DST_ALPHA = 0x0305;
|
||||
static DST_COLOR = 0x0306
|
||||
const ONE = 1;
|
||||
const ONE_MINUS_SRC_COLOR = 0x0301;
|
||||
const SRC_ALPHA = 0x0302;
|
||||
const ONE_MINUS_SRC_ALPHA = 0x0303;
|
||||
const ONE_MINUS_DST_ALPHA = 0x0305;
|
||||
const DST_COLOR = 0x0306;
|
||||
|
||||
export class WebGLBlendModeConverter {
|
||||
static getDestGLBlendMode (blendMode: 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);
|
||||
switch (blendMode) {
|
||||
case BlendMode.Normal: return ONE_MINUS_SRC_ALPHA;
|
||||
case BlendMode.Additive: return ONE;
|
||||
case BlendMode.Multiply: return ONE_MINUS_SRC_ALPHA;
|
||||
case BlendMode.Screen: return ONE_MINUS_SRC_ALPHA;
|
||||
default: throw new Error("Unknown blend mode: " + blendMode);
|
||||
}
|
||||
}
|
||||
|
||||
static getSourceGLBlendMode (blendMode: BlendMode, premultipliedAlpha: boolean = 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);
|
||||
static getSourceColorGLBlendMode (blendMode: BlendMode, premultipliedAlpha: boolean = false) {
|
||||
switch (blendMode) {
|
||||
case BlendMode.Normal: return premultipliedAlpha ? ONE : SRC_ALPHA;
|
||||
case BlendMode.Additive: return premultipliedAlpha ? ONE : SRC_ALPHA;
|
||||
case BlendMode.Multiply: return DST_COLOR;
|
||||
case BlendMode.Screen: return ONE;
|
||||
default: throw new Error("Unknown blend mode: " + blendMode);
|
||||
}
|
||||
}
|
||||
|
||||
static getSourceAlphaGLBlendMode (blendMode: BlendMode) {
|
||||
switch (blendMode) {
|
||||
case BlendMode.Normal: return ONE;
|
||||
case BlendMode.Additive: return ONE;
|
||||
case BlendMode.Multiply: return ONE_MINUS_SRC_ALPHA;
|
||||
case BlendMode.Screen: return ONE_MINUS_SRC_COLOR;
|
||||
default: throw new Error("Unknown blend mode: " + blendMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user