Jelajahi Sumber

Fixed some more examples.

Mr.doob 11 tahun lalu
induk
melakukan
d1454b25de

+ 39 - 2
examples/js/loaders/DDSLoader.js

@@ -29,12 +29,49 @@ THREE.DDSLoader.prototype = {
 
 		if ( url instanceof Array ) {
 
-			// TODO
+			var loaded = 0;
 
-			if ( onLoad ) onLoad( texture );
+			var loader = new THREE.XHRLoader();
+			loader.setResponseType( 'arraybuffer' );
+
+			var loadNext = function () {
+
+				loader.load( url[ loaded ], function ( buffer ) {
+
+					var dds = scope.parse( buffer, true );
+
+					images[ loaded ] = {
+						width: dds.width,
+						height: dds.height,
+						format: dds.format,
+						mipmaps: dds.mipmaps
+					}
+
+					loaded += 1;
+
+					if ( loaded === url.length ) {
+
+						texture.format = dds.format;
+						texture.needsUpdate = true;
+
+						if ( onLoad ) onLoad( texture );
+
+					} else {
+
+						loadNext();
+
+					}
+
+				} );
+
+			};
+
+			loadNext();
 
 		} else {
 
+			// compressed cubemap texture stored in a single DDS file
+
 			var loader = new THREE.XHRLoader();
 			loader.setResponseType( 'arraybuffer' );
 			loader.load( url, function ( buffer ) {

+ 2 - 0
examples/js/loaders/MTLLoader.js

@@ -369,10 +369,12 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 		if ( loader !== null ) {
 
 			texture = loader.load( url, onLoad );
+			texture.mapping = mapping;
 
 		} else {
 
 			texture = new THREE.Texture( new Image() );
+			texture.mapping = mapping;
 
 			loader = new THREE.ImageLoader();
 			loader.crossOrigin = this.crossOrigin;

+ 1 - 0
examples/js/loaders/SceneLoader.js

@@ -962,6 +962,7 @@ THREE.SceneLoader.prototype = {
 				if ( loader !== null ) {
 
 					texture = loader.load( url_array, generateTextureCallback( count ) );
+					texture.mapping = textureJSON.mapping;
 
 				} else {
 

+ 3 - 0
examples/webgl_loader_utf8.html

@@ -36,6 +36,7 @@
 
 		<script src="js/loaders/UTF8Loader.js"></script>
 		<script src="js/loaders/MTLLoader.js"></script>
+		<script src="js/loaders/DDSLoader.js"></script>
 
 		<script src="js/Detector.js"></script>
 		<script src="js/libs/stats.min.js"></script>
@@ -139,6 +140,8 @@
 
 				var start = Date.now();
 
+				THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
+
 				var loader = new THREE.UTF8Loader();
 
 				loader.load( "models/utf8/hand.js", function ( object ) {

+ 2 - 1
src/renderers/WebGLRenderer.js

@@ -4906,7 +4906,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( !texture ) continue;
 
-				if ( texture instanceof THREE.CubeTexture /* || ( texture.image instanceof Array && texture.image.length === 6 ) */ ) {
+				if ( texture instanceof THREE.CubeTexture ||
+				   ( texture.image instanceof Array && texture.image.length === 6 ) ) { // CompressedTexture can have Array in image :/
 
 					setCubeTexture( texture, textureUnit );