From a272561c6ec0f3b2944f6d467a70982d890be9e5 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Mon, 28 Jun 2021 22:51:49 +0200 Subject: [PATCH] Fix #941 glTF does not export materials --- lib/GLTFExporter.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/GLTFExporter.js b/lib/GLTFExporter.js index fe85ab77..bbbc4e34 100644 --- a/lib/GLTFExporter.js +++ b/lib/GLTFExporter.js @@ -165,6 +165,8 @@ GLTFExporter.prototype = { var uids = new Map(); var uid = 0; + var cachedMaterials = {}; + /** * Assign and return a temporal unique id for an object * especially which doesn't have .uuid @@ -919,6 +921,22 @@ GLTFExporter.prototype = { } + function getLamberMaterial(original) { + if (cachedMaterials[original.uuid]) { + return cachedMaterials[original.uuid]; + } else { + let material = new THREE.MeshLambertMaterial({ + color: 0xffffff, + map: original.map, + transparent: true, + side: Canvas.getRenderSide(), + alphaTest: 0.05 + }); + cachedMaterials[original.uuid] = material; + return material; + } + } + /** * Process material * @param {THREE.Material} material Material to process @@ -945,8 +963,7 @@ GLTFExporter.prototype = { if ( material.isShaderMaterial && ! material.isGLTFSpecularGlossinessMaterial ) { - console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' ); - return null; + material = getLamberMaterial(material); }