Fix #941 glTF does not export materials

This commit is contained in:
JannisX11 2021-06-28 22:51:49 +02:00
parent 5ed2019e74
commit a272561c6e

View File

@ -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);
}