UNPKG

@spearwolf/twopoint5d

Version:

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

27 lines 1.08 kB
import { Texture } from 'three'; import { PowerOf2ImageLoader } from './PowerOf2ImageLoader.js'; import { TextureCoords } from './TextureCoords.js'; import { TextureFactory } from './TextureFactory.js'; export class TextureImageLoader { constructor(textureFactory = new TextureFactory(), imageLoader = new PowerOf2ImageLoader()) { this.textureFactory = textureFactory; this.imageLoader = imageLoader; } load(url, textureClasses, onLoadCallback, onErrorCallback) { this.imageLoader.load(url, (imageData) => { const texture = new Texture(imageData.imgEl); this.textureFactory.update(texture, ...(textureClasses ?? [])); onLoadCallback({ texture, imgEl: imageData.imgEl, texCoords: imageData.texCoords, }); }, onErrorCallback); } loadAsync(url, textureClasses) { return new Promise((resolve, reject) => { this.load(url, textureClasses, resolve, reject); }); } } //# sourceMappingURL=TextureImageLoader.js.map