|
@@ -1,41 +1,13 @@
|
|
THREE.TGALoader = function ( manager ) {
|
|
THREE.TGALoader = function ( manager ) {
|
|
|
|
|
|
- THREE.Loader.call( this, manager );
|
|
|
|
|
|
+ THREE.DataTextureLoader.call( this, manager );
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
-THREE.TGALoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
|
|
|
|
|
|
+THREE.TGALoader.prototype = Object.assign( Object.create( THREE.DataTextureLoader.prototype ), {
|
|
|
|
|
|
constructor: THREE.TGALoader,
|
|
constructor: THREE.TGALoader,
|
|
|
|
|
|
- load: function ( url, onLoad, onProgress, onError ) {
|
|
|
|
-
|
|
|
|
- var scope = this;
|
|
|
|
-
|
|
|
|
- var texture = new THREE.Texture();
|
|
|
|
-
|
|
|
|
- var loader = new THREE.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 ) {
|
|
parse: function ( buffer ) {
|
|
|
|
|
|
// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
|
|
// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
|
|
@@ -521,21 +493,17 @@ THREE.TGALoader.prototype = Object.assign( Object.create( THREE.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 );
|
|
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;
|
|
|
|
|
|
+ };
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|