UNPKG

@spearwolf/twopoint5d

Version:

a library to create 2.5d realtime graphics and pixelart with three.js

31 lines 1.36 kB
import { FileLoader } from 'three'; import { TextureAtlas } from './TextureAtlas.js'; 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