Merge pull request #70 from AnalyticalGraphicsInc/fix-ambient

Fix ambient of 1,1,1
This commit is contained in:
Rob Taglang 2017-04-23 13:42:55 -04:00 committed by GitHub
commit 2327a882ce
2 changed files with 16 additions and 0 deletions

View File

@ -86,6 +86,13 @@ function createGltf(objData) {
transparent = diffuse[3] < 1.0;
}
if (Array.isArray(ambient)) {
// If ambient color is [1, 1, 1] assume it is a multiplier and instead change to [0, 0, 0]
if (ambient[0] === 1.0 && ambient[1] === 1.0 && ambient[2] === 1.0) {
ambient = [0.0, 0.0, 0.0, 1.0];
}
}
var doubleSided = transparent;
if (!hasNormals) {

View File

@ -359,4 +359,13 @@ describe('createGltf', function() {
var positionAccessor = gltf.accessors[primitive.attributes.POSITION];
expect(positionAccessor.count).toBe(vertexCount);
});
it('ambient of [1, 1, 1] is treated as [0, 0, 0]', function() {
boxObjData.materials.Material.ambientColor = [1.0, 1.0, 1.0, 1.0];
var gltf = createGltf(boxObjData);
var ambient = gltf.materials.Material.extensions.KHR_materials_common.values.ambient;
expect(ambient).toEqual([0.0, 0.0, 0.0, 1.0]);
});
});