diff --git a/examples/jsm/loaders/TGALoader.js b/examples/jsm/loaders/TGALoader.js index b22ead48b49e8b..5e20132038f53e 100644 --- a/examples/jsm/loaders/TGALoader.js +++ b/examples/jsm/loaders/TGALoader.js @@ -1,47 +1,17 @@ import { - FileLoader, - Loader, - Texture + DataTextureLoader, } from '../../../build/three.module.js'; var TGALoader = function ( manager ) { - Loader.call( this, manager ); + DataTextureLoader.call( this, manager ); }; -TGALoader.prototype = Object.assign( Object.create( Loader.prototype ), { +TGALoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype ), { constructor: TGALoader, - load: function ( url, onLoad, onProgress, onError ) { - - var scope = this; - - var texture = new Texture(); - - var loader = new FileLoader( this.manager ); - loader.setResponseType( 'arraybuffer' ); - loader.setPath( this.path ); - loader.setWithCredentials( this.withCredentials ); - - loader.load( url, function ( buffer ) { - - texture.image = scope.parse( buffer ); - texture.needsUpdate = true; - - if ( onLoad !== undefined ) { - - onLoad( texture ); - - } - - }, onProgress, onError ); - - return texture; - - }, - parse: function ( buffer ) { // reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js @@ -527,21 +497,17 @@ TGALoader.prototype = Object.assign( Object.create( Loader.prototype ), { // - var useOffscreen = typeof OffscreenCanvas !== 'undefined'; - - var canvas = useOffscreen ? new OffscreenCanvas( header.width, header.height ) : document.createElement( 'canvas' ); - canvas.width = header.width; - canvas.height = header.height; - - var context = canvas.getContext( '2d' ); - var imageData = context.createImageData( header.width, header.height ); - + var imageData = new Uint8Array( header.width * header.height * 4 ); var result = tgaParse( use_rle, use_pal, header, offset, content ); - getTgaRGBA( imageData.data, header.width, header.height, result.pixel_data, result.palettes ); + getTgaRGBA( imageData, header.width, header.height, result.pixel_data, result.palettes ); + + return { - context.putImageData( imageData, 0, 0 ); + data: imageData, + width: header.width, + height: header.height, - return canvas; + }; }