diff --git a/lib/obj.js b/lib/obj.js index abe024d..794b9a9 100644 --- a/lib/obj.js +++ b/lib/obj.js @@ -113,8 +113,8 @@ function loadObj(objPath) { var primitives = mesh.primitives; var primitivesLength = primitives.length; for (var i = 0; i < primitivesLength; ++i) { - primitive = primitives[i]; // Sets the active primitive in case of returning early - if (primitive.material === material) { + if (primitives[i].material === material) { + primitive = primitives[i]; return; } } @@ -331,25 +331,25 @@ function loadImages(imagePaths) { } function getImagePaths(materials) { - var imagePaths = []; + var imagePaths = {}; for (var name in materials) { if (materials.hasOwnProperty(name)) { var material = materials[name]; - if (defined(material.ambientColorMap) && imagePaths.indexOf(material.ambientColorMap) === -1) { - imagePaths.push(material.ambientColorMap); + if (defined(material.ambientColorMap)) { + imagePaths[material.ambientColorMap] = true; } - if (defined(material.diffuseColorMap) && imagePaths.indexOf(material.diffuseColorMap) === -1) { - imagePaths.push(material.diffuseColorMap); + if (defined(material.diffuseColorMap)) { + imagePaths[material.diffuseColorMap] = true; } - if (defined(material.emissionColorMap) && imagePaths.indexOf(material.emissionColorMap) === -1) { - imagePaths.push(material.emissionColorMap); + if (defined(material.emissionColorMap)) { + imagePaths[material.emissionColorMap] = true; } - if (defined(material.specularColorMap) && imagePaths.indexOf(material.specularColorMap) === -1) { - imagePaths.push(material.specularColorMap); + if (defined(material.specularColorMap)) { + imagePaths[material.specularColorMap] = true; } } } - return imagePaths; + return Object.keys(imagePaths); } function removeEmptyPrimitives(primitives) { diff --git a/specs/lib/objSpec.js b/specs/lib/objSpec.js index 89f0f91..b064bdc 100644 --- a/specs/lib/objSpec.js +++ b/specs/lib/objSpec.js @@ -128,16 +128,6 @@ describe('obj', function() { }), done).toResolve(); }); - it('loads obj with triangle faces', function(done) { - expect(loadObj(objTrianglesUrl) - .then(function(data) { - var mesh = getMeshes(data)[0]; - var primitive = getPrimitives(data)[0]; - expect(mesh.positions.length / 3).toBe(24); - expect(primitive.indices.length).toBe(36); - }), done).toResolve(); - }); - it('loads obj with objects', function(done) { expect(loadObj(objObjectsUrl) .then(function(data) {