diff --git a/lib/loadObj.js b/lib/loadObj.js index e24e36d..da73003 100644 --- a/lib/loadObj.js +++ b/lib/loadObj.js @@ -96,6 +96,11 @@ function loadObj(objPath, options) { var vertexIndices = []; + function clearVertexCache() { + vertexCache = {}; + vertexCacheCount = 0; + } + function getName(name) { return (name === '' ? undefined : name); } @@ -120,8 +125,7 @@ function loadObj(objPath, options) { mesh.primitives.push(primitive); // Clear the vertex cache for each new primitive - vertexCache = {}; - vertexCacheCount = 0; + clearVertexCache(); vertexCount = 0; } @@ -135,6 +139,7 @@ function loadObj(objPath, options) { for (var i = 0; i < primitivesLength; ++i) { if (primitives[i].material === material) { primitive = primitives[i]; + clearVertexCache(); vertexCount = primitive.positions.length / 3; return; } @@ -196,8 +201,7 @@ function loadObj(objPath, options) { // may be some duplicate vertices. vertexCacheCount++; if (vertexCacheCount > vertexCacheLimit) { - vertexCacheCount = 0; - vertexCache = {}; + clearVertexCache(); } } return index;