Skip to content

Commit

Permalink
TGALoader use DataTextureLoader instead of cavnas
Browse files Browse the repository at this point in the history
  • Loading branch information
deepkolos committed Feb 28, 2021
1 parent dd55c01 commit db08acd
Showing 1 changed file with 11 additions and 45 deletions.
56 changes: 11 additions & 45 deletions examples/jsm/loaders/TGALoader.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
};

}

Expand Down

0 comments on commit db08acd

Please sign in to comment.