Ver código fonte

use modularize.js to generate jsm

deepkolos 4 anos atrás
pai
commit
16ffe39a86
2 arquivos alterados com 11 adições e 43 exclusões
  1. 10 42
      examples/js/loaders/TGALoader.js
  2. 1 1
      examples/jsm/loaders/TGALoader.js

+ 10 - 42
examples/js/loaders/TGALoader.js

@@ -1,41 +1,13 @@
 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,
 
-	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 ) {
 
 		// 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 );
-		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;
+		};
 
 	}
 

+ 1 - 1
examples/jsm/loaders/TGALoader.js

@@ -1,5 +1,5 @@
 import {
-	DataTextureLoader,
+	DataTextureLoader
 } from '../../../build/three.module.js';
 
 var TGALoader = function ( manager ) {