From 83d24fdf50b49c63fe39dcf6326dcc60b460be52 Mon Sep 17 00:00:00 2001 From: Avaer Kazmer Date: Wed, 6 Nov 2019 21:38:32 -0500 Subject: [PATCH] Remove dead material images from model loading --- model-loader.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/model-loader.js b/model-loader.js index 2eb2b7c..a743e0c 100644 --- a/model-loader.js +++ b/model-loader.js @@ -34,8 +34,19 @@ const _filename2Ext = filename => { return match ? match[1] : null; }; const _patchModel = model => { - const saved = THREE.SkeletonUtils.clone(model.scene); + model.scene.traverse(o => { + if (o.isMesh) { + const materials = Array.isArray(o.material) ? o.material : [o.material]; + for (let i = 0; i < materials.length; i++) { + const material = materials[i]; + if (material.map && !material.map.image) { + material.map = null; + } + } + } + }); + const saved = THREE.SkeletonUtils.clone(model.scene); model.export = () => new Promise((accept, reject) => { new THREE.GLTFExporter().parse(saved, ab => { accept(ab);