UNPKG

@spearwolf/twopoint5d

Version:

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

31 lines 1.3 kB
import { Texture } from 'three'; import { PowerOf2ImageLoader } from './PowerOf2ImageLoader.js'; import { TextureCoords } from './TextureCoords.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