diff --git a/index.js b/index.js index 1da52ec..a96d538 100644 --- a/index.js +++ b/index.js @@ -669,6 +669,7 @@ const _finishCollisionShape = function(collisionShape, options, scale) { export const iterateGeometries = (function() { const inverse = new THREE.Matrix4(); + const vertices = []; return function(root, options, cb) { inverse.copy(root.matrixWorld).invert(); const scale = new THREE.Vector3(); @@ -689,7 +690,7 @@ export const iterateGeometries = (function() { // todo: might want to return null xform if this is the root so that callers can avoid multiplying // things by the identity matrix - let vertices; + let unInterleavedVertices; if (mesh.geometry.isBufferGeometry) { const verticesAttribute = mesh.geometry.attributes.position; if (verticesAttribute.isInterleavedBufferAttribute) { @@ -699,21 +700,22 @@ export const iterateGeometries = (function() { // regular array here to not carry this logic around in // the shape api. // - vertices = []; + vertices.length = 0; for (let i = 0; i < verticesAttribute.count; i += 3) { vertices.push(verticesAttribute.getX(i)); vertices.push(verticesAttribute.getY(i)); vertices.push(verticesAttribute.getZ(i)); } + unInterleavedVertices = vertices; } else { - vertices = verticesAttribute.array; + unInterleavedVertices = verticesAttribute.array; } } else { - vertices = mesh.geometry.vertices; + unInterleavedVertices = mesh.geometry.vertices; } cb( - vertices, + unInterleavedVertices, transform.elements, mesh.geometry.index ? mesh.geometry.index.array : null );