@spearwolf/twopoint5d
Version:
Create 2.5D realtime graphics and pixelart with WebGL and three.js
30 lines • 1.31 kB
JavaScript
import { FileLoader } from 'three/webgpu';
import { TextureImageLoader } from './TextureImageLoader.js';
import { TexturePackerJson } from './TexturePackerJson.js';
const makeFileLoader = () => {
const loader = new FileLoader();
loader.setResponseType('json');
return loader;
};
export class TextureAtlasLoader {
constructor(defaults) {
this.fileLoader = defaults?.fileLoader ?? makeFileLoader();
this.textureImageLoader = defaults?.textureImageLoader ?? new TextureImageLoader();
}
load(url, textureClasses, options, onLoadCallback, onErrorCallback) {
this.fileLoader.load(url, (jsonData) => {
const imageUrl = options?.overrideImageUrl ?? jsonData.meta.image;
this.textureImageLoader.load(imageUrl, textureClasses ?? [], ({ texture, imgEl, texCoords }) => {
const [atlas, meta] = TexturePackerJson.parse(jsonData, texCoords);
onLoadCallback({ atlas, meta, texture, imgEl, texCoords });
}, onErrorCallback);
}, (_xhr) => {
}, onErrorCallback);
}
loadAsync(url, textureClasses, options) {
return new Promise((resolve, reject) => {
this.load(url, textureClasses, options, resolve, reject);
});
}
}
//# sourceMappingURL=TextureAtlasLoader.js.map