Skip to content

Commit

Permalink
addressing PR feedback and updating to colorSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed May 23, 2023
1 parent 706e9cf commit 3f1307e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
10 changes: 4 additions & 6 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

}

Expand Down Expand Up @@ -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 );

}

Expand Down Expand Up @@ -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 );

}

Expand Down
26 changes: 11 additions & 15 deletions examples/jsm/utils/TextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
Scene,
WebGLRenderer,
Texture,
sRGBEncoding
SRGBColorSpace
} from 'three';

let temporaryRenderer;
let _renderer;
let fullscreenQuadGeometry;
let fullscreenQuadMaterial;
let fullscreenQuad;
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );

Expand All @@ -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;

}

Expand Down

0 comments on commit 3f1307e

Please sign in to comment.