@spearwolf/twopoint5d
Version:
Create 2.5D realtime graphics and pixelart with WebGL and three.js
30 lines • 1.25 kB
JavaScript
import { Texture } from 'three/webgpu';
import { PowerOf2ImageLoader } from './PowerOf2ImageLoader.js';
import { TextureFactory } from './TextureFactory.js';
import { TileSet } from './TileSet.js';
export class TileSetLoader {
constructor(textureFactory = new TextureFactory(), imageLoader = new PowerOf2ImageLoader()) {
this.textureFactory = textureFactory;
this.imageLoader = imageLoader;
}
load(url, tileSetOptions, textureClasses, onLoadCallback, onErrorCallback) {
this.imageLoader.load(url, (imageData) => {
const texture = new Texture(imageData.imgEl);
texture.name = url;
this.textureFactory.update(texture, ...(textureClasses ?? []));
const tileSet = new TileSet(imageData.texCoords, tileSetOptions);
onLoadCallback({
texture,
tileSet,
imgEl: imageData.imgEl,
texCoords: imageData.texCoords,
});
}, onErrorCallback);
}
loadAsync(url, tileSetOptions, textureClasses) {
return new Promise((resolve, reject) => {
this.load(url, tileSetOptions, textureClasses, resolve, reject);
});
}
}
//# sourceMappingURL=TileSetLoader.js.map