فهرست منبع

GLTFLoader: Ignore redundant 'KHR_texture_transform' extensions and 'textures' entries. (#21821)

* GLTFLoader: Ignore empty 'KHR_texture_transform' extensions.

* GLTFLoader: Ignore redundant texture entries for same image.

* GLTFLoader: Fix cache key for compressed textures.
Don McCurdy 4 سال پیش
والد
کامیت
c4002a6004
1فایلهای تغییر یافته به همراه29 افزوده شده و 7 حذف شده
  1. 29 7
      examples/jsm/loaders/GLTFLoader.js

+ 29 - 7
examples/jsm/loaders/GLTFLoader.js

@@ -1115,6 +1115,19 @@ class GLTFTextureTransformExtension {
 
 	extendTexture( texture, transform ) {
 
+		if ( transform.texCoord !== undefined ) {
+
+			console.warn( 'THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.' );
+
+		}
+
+		if ( transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined ) {
+
+			// See https://github.com/mrdoob/three.js/issues/21819.
+			return texture;
+
+		}
+
 		texture = texture.clone();
 
 		if ( transform.offset !== undefined ) {
@@ -1135,12 +1148,6 @@ class GLTFTextureTransformExtension {
 
 		}
 
-		if ( transform.texCoord !== undefined ) {
-
-			console.warn( 'THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.' );
-
-		}
-
 		texture.needsUpdate = true;
 
 		return texture;
@@ -1964,6 +1971,8 @@ class GLTFParser {
 		this.cameraCache = { refs: {}, uses: {} };
 		this.lightCache = { refs: {}, uses: {} };
 
+		this.textureCache = {};
+
 		// Track node names, to ensure no duplicates
 		this.nodeNamesUsed = {};
 
@@ -2528,6 +2537,15 @@ class GLTFParser {
 
 		const textureDef = json.textures[ textureIndex ];
 
+		const cacheKey = ( source.uri || source.bufferView ) + ':' + textureDef.sampler;
+
+		if ( this.textureCache[ cacheKey ] ) {
+
+			// See https://github.com/mrdoob/three.js/issues/21559.
+			return this.textureCache[ cacheKey ];
+
+		}
+
 		const URL = self.URL || self.webkitURL;
 
 		let sourceURI = source.uri;
@@ -2568,7 +2586,7 @@ class GLTFParser {
 
 		}
 
-		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {
+		const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
 
 			return new Promise( function ( resolve, reject ) {
 
@@ -2622,6 +2640,10 @@ class GLTFParser {
 
 		} );
 
+		this.textureCache[ cacheKey ] = promise;
+
+		return promise;
+
 	}
 
 	/**