Skip to content

Commit

Permalink
Remove dead material images from model loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaer Kazmer committed Nov 7, 2019
1 parent 68b92be commit 83d24fd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion model-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 83d24fd

Please sign in to comment.