Skip to content

Commit

Permalink
only use one temp render context, clean up renderer after writing fil…
Browse files Browse the repository at this point in the history
…e, make metalnessMap and roughnessMap readable
  • Loading branch information
hybridherbst committed Nov 24, 2022
1 parent b9beed1 commit 22a8e81
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ class GLTFWriter {

}

// Clean up in case we had to create a temporary renderer for blitting compressed textures.
if (this.temporaryRenderer) {

this.temporaryRenderer.dispose();

}

}

Expand Down Expand Up @@ -751,12 +757,19 @@ class GLTFWriter {
const temporaryScene = new Scene();
temporaryScene.add( fullscreenQuad );

const temporaryRenderer = new WebGLRenderer( { antialias: false } );
temporaryRenderer.setSize( Math.min(map.image.width, maxTextureSize), Math.min(map.image.height, maxTextureSize) );
temporaryRenderer.clear();
temporaryRenderer.render( temporaryScene, temporaryCam );
if (!this.temporaryRenderer) {

this.temporaryRenderer = new WebGLRenderer( { antialias: false } );

}

this.temporaryRenderer.setSize( Math.min(map.image.width, maxTextureSize), Math.min(map.image.height, maxTextureSize) );
this.temporaryRenderer.clear();
this.temporaryRenderer.render( temporaryScene, temporaryCam );

return new Texture( temporaryRenderer.domElement );
const readableTexture = new Texture( this.temporaryRenderer.domElement );
readableTexture.userData.mimeType = 'image/png';
return readableTexture;

}

Expand Down Expand Up @@ -788,6 +801,22 @@ class GLTFWriter {

console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );

if ( typeof CompressedTexture !== 'undefined') {

if ( metalnessMap instanceof CompressedTexture ) {

metalnessMap = this.buildReadableTexture( metalnessMap );

}

if ( roughnessMap instanceof CompressedTexture ) {

roughnessMap = this.buildReadableTexture( roughnessMap );

}

}

const metalness = metalnessMap?.image;
const roughness = roughnessMap?.image;

Expand Down Expand Up @@ -1180,7 +1209,6 @@ class GLTFWriter {
console.error( 'GLTFExporter: Only RGBAFormat is supported.', image );

}

if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {

console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
Expand Down Expand Up @@ -1311,7 +1339,6 @@ class GLTFWriter {
if ( typeof CompressedTexture !== 'undefined' && map instanceof CompressedTexture ) {

modifiedMap = this.buildReadableTexture( map, options.maxTextureSize );
modifiedMap.userData.mimeType = 'image/png';

}

Expand Down

0 comments on commit 22a8e81

Please sign in to comment.