From 20bbd17cd95bf58d2db49ddd90759901b3255298 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sun, 23 Apr 2017 13:34:09 -0400 Subject: [PATCH] Fix ambient of 1,1,1 --- lib/createGltf.js | 7 +++++++ specs/lib/createGltfSpec.js | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/createGltf.js b/lib/createGltf.js index eb6aa7c..33191c8 100644 --- a/lib/createGltf.js +++ b/lib/createGltf.js @@ -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) { diff --git a/specs/lib/createGltfSpec.js b/specs/lib/createGltfSpec.js index c509492..dd00f24 100644 --- a/specs/lib/createGltfSpec.js +++ b/specs/lib/createGltfSpec.js @@ -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]); + }); });