Prechádzať zdrojové kódy

use DataTextureLoader and custom onLoad

deepkolos 4 rokov pred
rodič
commit
fa43b759e7

+ 11 - 26
examples/js/loaders/TGALoader.js

@@ -1,43 +1,28 @@
 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;
+		function onDataTextureLoad( texture, texData ) {
 
-		var texture = new THREE.DataTexture();
-		texture.flipY = true;
-		texture.generateMipmaps = true;
-		texture.unpackAlignment = 4;
-		texture.magFilter = THREE.LinearFilter;
-		texture.minFilter = THREE.LinearMipmapLinearFilter;
+			texture.flipY = true;
+			texture.generateMipmaps = true;
+			texture.unpackAlignment = 4;
+			texture.magFilter = THREE.LinearFilter;
+			texture.minFilter = THREE.LinearMipmapLinearFilter;
 
-		var loader = new THREE.FileLoader( this.manager );
-		loader.setResponseType( 'arraybuffer' );
-		loader.setPath( this.path );
-		loader.setWithCredentials( this.withCredentials );
+			if ( onLoad ) onLoad( texture, texData );
 
-		loader.load( url, function ( buffer ) {
-
-			texture.image = scope.parse( buffer );
-			texture.needsUpdate = true;
-
-			if ( onLoad !== undefined ) {
-
-				onLoad( texture );
-
-			}
-
-		}, onProgress, onError );
+		}
 
-		return texture;
+		return THREE.DataTextureLoader.prototype.load.call( this, url, onDataTextureLoad, onProgress, onError );
 
 	},
 

+ 13 - 30
examples/jsm/loaders/TGALoader.js

@@ -1,51 +1,34 @@
 import {
-	DataTexture,
-	FileLoader,
+	DataTextureLoader,
 	LinearFilter,
-	LinearMipmapLinearFilter,
-	Loader
+	LinearMipmapLinearFilter
 } 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;
+		function onDataTextureLoad( texture, texData ) {
 
-		var texture = new DataTexture();
-		texture.flipY = true;
-		texture.generateMipmaps = true;
-		texture.unpackAlignment = 4;
-		texture.minFilter = LinearMipmapLinearFilter;
-		texture.magFilter = LinearFilter;
+			texture.flipY = true;
+			texture.generateMipmaps = true;
+			texture.unpackAlignment = 4;
+			texture.magFilter = LinearFilter;
+			texture.minFilter = LinearMipmapLinearFilter;
 
-		var loader = new FileLoader( this.manager );
-		loader.setResponseType( 'arraybuffer' );
-		loader.setPath( this.path );
-		loader.setWithCredentials( this.withCredentials );
+			if ( onLoad ) onLoad( texture, texData );
 
-		loader.load( url, function ( buffer ) {
-
-			texture.image = scope.parse( buffer );
-			texture.needsUpdate = true;
-
-			if ( onLoad !== undefined ) {
-
-				onLoad( texture );
-
-			}
-
-		}, onProgress, onError );
+		}
 
-		return texture;
+		return DataTextureLoader.prototype.load.call( this, url, onDataTextureLoad, onProgress, onError );
 
 	},