Переглянути джерело

enhance DataTextureLoader

deepkolos 4 роки тому
батько
коміт
39b6fa02a5

+ 3 - 18
examples/js/loaders/TGALoader.js

@@ -8,24 +8,6 @@ THREE.TGALoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
 
 	constructor: THREE.TGALoader,
 
-	load: function ( url, onLoad, onProgress, onError ) {
-
-		function onDataTextureLoad( texture, texData ) {
-
-			texture.flipY = true;
-			texture.generateMipmaps = true;
-			texture.unpackAlignment = 4;
-			texture.magFilter = THREE.LinearFilter;
-			texture.minFilter = THREE.LinearMipmapLinearFilter;
-
-			if ( onLoad ) onLoad( texture, texData );
-
-		}
-
-		return THREE.DataTextureLoader.prototype.load.call( this, url, onDataTextureLoad, onProgress, onError );
-
-	},
-
 	parse: function ( buffer ) {
 
 		// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
@@ -520,6 +502,9 @@ THREE.TGALoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
 			data: imageData,
 			width: header.width,
 			height: header.height,
+			flipY: true,
+			generateMipmaps: true,
+			minFilter: THREE.LinearMipmapLinearFilter,
 
 		};
 

+ 3 - 19
examples/jsm/loaders/TGALoader.js

@@ -1,6 +1,5 @@
 import {
 	DataTextureLoader,
-	LinearFilter,
 	LinearMipmapLinearFilter
 } from '../../../build/three.module.js';
 
@@ -14,24 +13,6 @@ TGALoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
 
 	constructor: TGALoader,
 
-	load: function ( url, onLoad, onProgress, onError ) {
-
-		function onDataTextureLoad( texture, texData ) {
-
-			texture.flipY = true;
-			texture.generateMipmaps = true;
-			texture.unpackAlignment = 4;
-			texture.magFilter = LinearFilter;
-			texture.minFilter = LinearMipmapLinearFilter;
-
-			if ( onLoad ) onLoad( texture, texData );
-
-		}
-
-		return DataTextureLoader.prototype.load.call( this, url, onDataTextureLoad, onProgress, onError );
-
-	},
-
 	parse: function ( buffer ) {
 
 		// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
@@ -526,6 +507,9 @@ TGALoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
 			data: imageData,
 			width: header.width,
 			height: header.height,
+			flipY: true,
+			generateMipmaps: true,
+			minFilter: LinearMipmapLinearFilter,
 
 		};
 

+ 6 - 0
src/loaders/DataTextureLoader.js

@@ -93,6 +93,12 @@ DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 			}
 
+			if ( texData.generateMipmaps !== undefined ) {
+
+				texture.generateMipmaps = texData.generateMipmaps;
+
+			}
+
 			texture.needsUpdate = true;
 
 			if ( onLoad ) onLoad( texture, texData );