From 3b8f635e6b737b3e468211a2de44c00934c23f01 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sat, 24 Feb 2018 05:53:24 +0900 Subject: [PATCH 1/4] GLTFExporter: Add texture cache. --- examples/js/exporters/GLTFExporter.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index f98bd2c1e3533e..370159ebd583a8 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -99,7 +99,8 @@ THREE.GLTFExporter.prototype = { var cachedData = { images: {}, - materials: {} + materials: {}, + textures: {} }; @@ -533,6 +534,12 @@ THREE.GLTFExporter.prototype = { */ function processTexture( map ) { + if ( cachedData.textures[ map.uuid ] !== undefined ) { + + return cachedData.textures[ map.uuid ]; + + } + if ( ! outputJSON.textures ) { outputJSON.textures = []; @@ -548,7 +555,10 @@ THREE.GLTFExporter.prototype = { outputJSON.textures.push( gltfTexture ); - return outputJSON.textures.length - 1; + var index = outputJSON.textures.length - 1; + cachedData.textures[ map.uuid ] = index; + + return index; } From 81aef3919be6927a5f0a86ed64ab2c6d50b2b7b7 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sat, 24 Feb 2018 05:54:52 +0900 Subject: [PATCH 2/4] GLTFExporter: Remove image cache. --- examples/js/exporters/GLTFExporter.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index 370159ebd583a8..cabf051ae76817 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -98,7 +98,6 @@ THREE.GLTFExporter.prototype = { var skins = []; var cachedData = { - images: {}, materials: {}, textures: {} @@ -449,12 +448,6 @@ THREE.GLTFExporter.prototype = { */ function processImage( map ) { - if ( cachedData.images[ map.uuid ] !== undefined ) { - - return cachedData.images[ map.uuid ]; - - } - if ( ! outputJSON.images ) { outputJSON.images = []; @@ -492,10 +485,7 @@ THREE.GLTFExporter.prototype = { outputJSON.images.push( gltfImage ); - var index = outputJSON.images.length - 1; - cachedData.images[ map.uuid ] = index; - - return index; + return outputJSON.images.length - 1; } From 7ae7b5babc68cb3dd7ca43a9ac4a3212c8806c88 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sat, 24 Feb 2018 05:57:40 +0900 Subject: [PATCH 3/4] GLTFExporter: Add a comment for image cache. --- examples/js/exporters/GLTFExporter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index cabf051ae76817..a0b3336db5053d 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -448,6 +448,8 @@ THREE.GLTFExporter.prototype = { */ function processImage( map ) { + // @QUESTION Needs image cache for the case where two different textures share the same image? + if ( ! outputJSON.images ) { outputJSON.images = []; From 91fe0ea7211650e44dcefb3f4ee3fc63137bdbcb Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sat, 24 Feb 2018 10:13:21 +0900 Subject: [PATCH 4/4] GLTFExporter: Replace QUESTION with TODO --- examples/js/exporters/GLTFExporter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index a0b3336db5053d..fcfc3e50b86c81 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -448,7 +448,7 @@ THREE.GLTFExporter.prototype = { */ function processImage( map ) { - // @QUESTION Needs image cache for the case where two different textures share the same image? + // @TODO Cache if ( ! outputJSON.images ) {