Treat alpha of 0 as 1

This commit is contained in:
Sean Lilley 2017-09-19 11:59:51 -04:00
parent 4f2e2add43
commit e36668ab14

View File

@ -118,10 +118,10 @@ function loadMtl(mtlPath, options) {
material.specularShininess = parseFloat(value);
} else if (/^d /i.test(line)) {
value = line.substring(2).trim();
material.alpha = parseFloat(value);
material.alpha = correctAlpha(parseFloat(value));
} else if (/^Tr /i.test(line)) {
value = line.substring(3).trim();
material.alpha = 1.0 - parseFloat(value);
material.alpha = correctAlpha(1.0 - parseFloat(value));
} else if (/^map_Ka /i.test(line)) {
if (!defined(overridingAmbientTexture)) {
texturePath = path.resolve(mtlDirectory, line.substring(7).trim());
@ -164,6 +164,11 @@ function loadMtl(mtlPath, options) {
});
}
function correctAlpha(alpha) {
// An alpha of 0.0 usually implies a problem in the export, change to 1.0 instead
return alpha === 0.0 ? 1.0 : alpha;
}
function Material() {
this.name = undefined;
this.ambientColor = [0.0, 0.0, 0.0, 1.0]; // Ka