mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts] Player, simplified config.mipmaps.
This commit is contained in:
parent
66951cb1d8
commit
286552b8fa
@ -154,10 +154,8 @@ module spine {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(imagePath: string, message: string) => {
|
(imagePath: string, message: string) => {
|
||||||
if (!abort) {
|
if (!abort) this.error(error, path, `Couldn't load texture atlas ${path} page ${imagePath}: ${message}`);
|
||||||
abort = true;
|
abort = true;
|
||||||
this.error(error, path, `Couldn't load texture atlas ${path} page ${imagePath}: ${message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ body {
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="container" style="width:100%; height:100px"></div>
|
<div id="container" style="width:640px; height:380px"></div>
|
||||||
<div id="container-raptor" style="width:640px; height:380px"></div>
|
<div id="container-raptor" style="width:640px; height:380px"></div>
|
||||||
<div>
|
<div>
|
||||||
<button id="walk">Walk</button>
|
<button id="walk">Walk</button>
|
||||||
|
|||||||
@ -239,6 +239,7 @@ module spine {
|
|||||||
if (!config.fullScreenBackgroundColor) config.fullScreenBackgroundColor = config.backgroundColor;
|
if (!config.fullScreenBackgroundColor) config.fullScreenBackgroundColor = config.backgroundColor;
|
||||||
if (config.backgroundImage && !config.backgroundImage.url) config.backgroundImage = null;
|
if (config.backgroundImage && !config.backgroundImage.url) config.backgroundImage = null;
|
||||||
if (config.premultipliedAlpha === undefined) config.premultipliedAlpha = true;
|
if (config.premultipliedAlpha === undefined) config.premultipliedAlpha = true;
|
||||||
|
if (config.mipmaps === undefined) config.mipmaps = true;
|
||||||
if (!config.debug) config.debug = {} as any;
|
if (!config.debug) config.debug = {} as any;
|
||||||
if (config.animations && config.animation && config.animations.indexOf(config.animation) < 0)
|
if (config.animations && config.animation && config.animations.indexOf(config.animation) < 0)
|
||||||
throw new Error("Animation '" + config.animation + "' is not in the config animation list: " + toString(config.animations));
|
throw new Error("Animation '" + config.animation + "' is not in the config animation list: " + toString(config.animations));
|
||||||
@ -291,38 +292,7 @@ module spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the assets.
|
// Load the assets.
|
||||||
this.assetManager = new class extends spine.webgl.AssetManager {
|
this.assetManager = new spine.webgl.AssetManager(this.context, "", config.downloader);
|
||||||
protected createTexture (context: spine.webgl.ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap): Texture {
|
|
||||||
return new class extends spine.webgl.GLTexture {
|
|
||||||
setFilters (minFilter: TextureFilter, magFilter: TextureFilter) {
|
|
||||||
if (config.mipmaps) {
|
|
||||||
minFilter = TextureFilter.MipMapLinearLinear;
|
|
||||||
magFilter = TextureFilter.Linear;
|
|
||||||
}
|
|
||||||
var mipmaps = false;
|
|
||||||
switch (minFilter) {
|
|
||||||
case TextureFilter.MipMap:
|
|
||||||
case TextureFilter.MipMapLinearLinear:
|
|
||||||
case TextureFilter.MipMapLinearNearest:
|
|
||||||
case TextureFilter.MipMapNearestLinear:
|
|
||||||
case TextureFilter.MipMapNearestNearest:
|
|
||||||
if (config.mipmaps) {
|
|
||||||
let gl = this.context.gl;
|
|
||||||
let ext = gl.getExtension("EXT_texture_filter_anisotropic");
|
|
||||||
if (ext) {
|
|
||||||
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 8);
|
|
||||||
mipmaps = true;
|
|
||||||
} else
|
|
||||||
minFilter = TextureFilter.Linear; // Don't use mipmaps without anisotropic.
|
|
||||||
} else
|
|
||||||
mipmaps = true;
|
|
||||||
}
|
|
||||||
super.setFilters(minFilter, magFilter);
|
|
||||||
if (mipmaps) this.update(true);
|
|
||||||
}
|
|
||||||
}(context, image);
|
|
||||||
}
|
|
||||||
}(this.context, "", config.downloader);
|
|
||||||
if (config.rawDataURIs) {
|
if (config.rawDataURIs) {
|
||||||
for (let path in config.rawDataURIs)
|
for (let path in config.rawDataURIs)
|
||||||
this.assetManager.setRawDataURI(path, config.rawDataURIs[path]);
|
this.assetManager.setRawDataURI(path, config.rawDataURIs[path]);
|
||||||
@ -418,7 +388,24 @@ module spine {
|
|||||||
this.showError("Error: Assets could not be loaded.\n" + toString(this.assetManager.getErrors()));
|
this.showError("Error: Assets could not be loaded.\n" + toString(this.assetManager.getErrors()));
|
||||||
|
|
||||||
let config = this.config;
|
let config = this.config;
|
||||||
|
|
||||||
|
// Configure filtering.
|
||||||
let atlas = this.assetManager.get(config.atlasUrl);
|
let atlas = this.assetManager.get(config.atlasUrl);
|
||||||
|
let gl = this.context.gl, anisotropic = gl.getExtension("EXT_texture_filter_anisotropic");
|
||||||
|
for (let page of atlas.pages) {
|
||||||
|
var minFilter = page.minFilter;
|
||||||
|
if (config.mipmaps) {
|
||||||
|
if (anisotropic) {
|
||||||
|
gl.texParameterf(gl.TEXTURE_2D, anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, 8);
|
||||||
|
minFilter = TextureFilter.MipMapLinearLinear;
|
||||||
|
} else
|
||||||
|
minFilter = TextureFilter.Linear; // Don't use mipmaps without anisotropic.
|
||||||
|
page.texture.setFilters(minFilter, TextureFilter.Nearest);
|
||||||
|
}
|
||||||
|
if (minFilter != TextureFilter.Nearest && minFilter != TextureFilter.Linear) page.texture.update(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load skeleton data.
|
||||||
let skeletonData: SkeletonData;
|
let skeletonData: SkeletonData;
|
||||||
if (config.jsonUrl) {
|
if (config.jsonUrl) {
|
||||||
try {
|
try {
|
||||||
@ -447,7 +434,7 @@ module spine {
|
|||||||
stateData.defaultMix = config.defaultMix;
|
stateData.defaultMix = config.defaultMix;
|
||||||
this.animationState = new AnimationState(stateData);
|
this.animationState = new AnimationState(stateData);
|
||||||
|
|
||||||
// Check if all controllable bones are in the skeleton
|
// Check if all control bones are in the skeleton
|
||||||
config.controlBones.forEach(bone => {
|
config.controlBones.forEach(bone => {
|
||||||
if (!skeletonData.findBone(bone)) this.showError(`Error: Control bone does not exist in skeleton: ${bone}`);
|
if (!skeletonData.findBone(bone)) this.showError(`Error: Control bone does not exist in skeleton: ${bone}`);
|
||||||
})
|
})
|
||||||
|
|||||||
@ -48,7 +48,7 @@ module spine.threejs {
|
|||||||
geo.setAttribute("color", new THREE.InterleavedBufferAttribute(vertexBuffer, 4, 3, false));
|
geo.setAttribute("color", new THREE.InterleavedBufferAttribute(vertexBuffer, 4, 3, false));
|
||||||
geo.setAttribute("uv", new THREE.InterleavedBufferAttribute(vertexBuffer, 2, 7, false));
|
geo.setAttribute("uv", new THREE.InterleavedBufferAttribute(vertexBuffer, 2, 7, false));
|
||||||
geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||||
geo.getIndex().usage = WebGLRenderingContext.DYNAMIC_DRAW;;
|
geo.getIndex().usage = WebGLRenderingContext.DYNAMIC_DRAW;
|
||||||
geo.drawRange.start = 0;
|
geo.drawRange.start = 0;
|
||||||
geo.drawRange.count = 0;
|
geo.drawRange.count = 0;
|
||||||
this.geometry = geo;
|
this.geometry = geo;
|
||||||
|
|||||||
@ -30,11 +30,9 @@
|
|||||||
module spine.webgl {
|
module spine.webgl {
|
||||||
export class AssetManager extends spine.AssetManager {
|
export class AssetManager extends spine.AssetManager {
|
||||||
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, pathPrefix: string = "", downloader: Downloader = null) {
|
constructor (context: ManagedWebGLRenderingContext | WebGLRenderingContext, pathPrefix: string = "", downloader: Downloader = null) {
|
||||||
super((image: HTMLImageElement | ImageBitmap) => this.createTexture(context, image), pathPrefix, downloader);
|
super((image: HTMLImageElement | ImageBitmap) => {
|
||||||
}
|
return new spine.webgl.GLTexture(context, image);
|
||||||
|
}, pathPrefix, downloader);
|
||||||
protected createTexture (context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap): Texture {
|
|
||||||
return new spine.webgl.GLTexture(context, image);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user