瀏覽代碼

addressing PR feedback and updating to colorSpace

Felix Herbst 2 年之前
父節點
當前提交
3f1307e107
共有 2 個文件被更改,包括 15 次插入21 次删除
  1. 4 6
      examples/jsm/exporters/GLTFExporter.js
  2. 11 15
      examples/jsm/utils/TextureUtils.js

+ 4 - 6
examples/jsm/exporters/GLTFExporter.js

@@ -841,8 +841,8 @@ class GLTFWriter {
 
 		}
 
-		const metalness = metalnessMap?.image;
-		const roughness = roughnessMap?.image;
+		const metalness = metalnessMap ? metalnessMap.image : null;
+		const roughness = roughnessMap ? roughnessMap.image : null;
 
 		const width = Math.max( metalness ? metalness.width : 0, roughness ? roughness.width : 0 );
 		const height = Math.max( metalness ? metalness.height : 0, roughness ? roughness.height : 0 );
@@ -1160,7 +1160,7 @@ class GLTFWriter {
 
 		} else {
 
-			throw new Error( 'THREE.GLTFExporter: Unsupported bufferAttribute component type: ' + attribute.array.constructor );
+			throw new Error( 'THREE.GLTFExporter: Unsupported bufferAttribute component type: ' + attribute.array.constructor.name );
 
 		}
 
@@ -1250,7 +1250,7 @@ class GLTFWriter {
 
 				if ( format !== RGBAFormat ) {
 
-					console.error( 'GLTFExporter: Only RGBAFormat is supported.', image );
+					console.error( 'GLTFExporter: Only RGBAFormat is supported.', format );
 
 				}
 
@@ -1371,8 +1371,6 @@ class GLTFWriter {
 		if ( map instanceof CompressedTexture ) {
 
 			map = decompress( map, options.maxTextureSize );
-			// remove from cache, as the underlaying canvas is always the same between decompressed textures
-			cache.images.delete( map.image );
 
 		}
 

+ 11 - 15
examples/jsm/utils/TextureUtils.js

@@ -7,10 +7,10 @@ import {
 	Scene,
 	WebGLRenderer,
 	Texture,
-	sRGBEncoding
+	SRGBColorSpace
 } from 'three';
 
-let temporaryRenderer;
+let _renderer;
 let fullscreenQuadGeometry;
 let fullscreenQuadMaterial;
 let fullscreenQuad;
@@ -47,7 +47,7 @@ export function decompress( texture, maxTextureSize, renderer = null ) {
 	} );
 
 	fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
-	fullscreenQuadMaterial.defines.IS_SRGB = texture.encoding == sRGBEncoding;
+	fullscreenQuadMaterial.defines.IS_SRGB = texture.colorSpace == SRGBColorSpace;
 	fullscreenQuadMaterial.needsUpdate = true;
 
 	if ( ! fullscreenQuad ) {
@@ -57,22 +57,19 @@ export function decompress( texture, maxTextureSize, renderer = null ) {
 
 	}
 
-	const temporaryCam = new PerspectiveCamera();
-	const temporaryScene = new Scene();
-	temporaryScene.add( fullscreenQuad );
+	const _camera = new PerspectiveCamera();
+	const _scene = new Scene();
+	_scene.add( fullscreenQuad );
 
 	if ( ! renderer ) {
 
-		if ( ! temporaryRenderer )
-			temporaryRenderer = new WebGLRenderer( { antialias: false } );
-
-		renderer = temporaryRenderer;
+		renderer = _renderer = new WebGLRenderer( { antialias: false } );
 
 	}
 
 	renderer.setSize( Math.min( texture.image.width, maxTextureSize ), Math.min( texture.image.height, maxTextureSize ) );
 	renderer.clear();
-	renderer.render( temporaryScene, temporaryCam );
+	renderer.render( _scene, _camera );
 
 	const readableTexture = new Texture( renderer.domElement );
 
@@ -82,11 +79,10 @@ export function decompress( texture, maxTextureSize, renderer = null ) {
 	readableTexture.wrapT = texture.wrapT;
 	readableTexture.name = texture.name;
 
-	readableTexture.userData.mimeType = 'image/png';
-
-	if ( temporaryRenderer ) {
+	if ( _renderer ) {
 
-		temporaryRenderer.dispose();
+		_renderer.dispose();
+		_renderer = null;
 
 	}