From 8f5fa477c3d9a22947cbea4eee2f77285edd35cb Mon Sep 17 00:00:00 2001 From: Antonio Pisano Date: Sun, 28 Apr 2024 23:19:58 +0200 Subject: [PATCH 1/2] Revert "Reuse one array instead of creating many" This reverts commit bdc0d890f3e3d6c460b535ded8c2454036f124e3. Arrays for geometries are processed together after traversin, so they need to be different. --- index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 736e713..ad246bc 100644 --- a/index.js +++ b/index.js @@ -669,7 +669,6 @@ 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(); root.traverse(mesh => { @@ -688,7 +687,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 unInterleavedVertices; + let vertices; if (mesh.geometry.isBufferGeometry) { const verticesAttribute = mesh.geometry.attributes.position; if (verticesAttribute.isInterleavedBufferAttribute) { @@ -698,22 +697,21 @@ export const iterateGeometries = (function() { // regular array here to not carry this logic around in // the shape api. // - vertices.length = 0; + vertices = []; 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 { - unInterleavedVertices = verticesAttribute.array; + vertices = verticesAttribute.array; } } else { - unInterleavedVertices = mesh.geometry.vertices; + vertices = mesh.geometry.vertices; } cb( - unInterleavedVertices, + vertices, transform.elements, mesh.geometry.index ? mesh.geometry.index.array : null ); From 1625050a6293aeb05106075dfcfe367d43f35433 Mon Sep 17 00:00:00 2001 From: Antonio Pisano Date: Sun, 28 Apr 2024 23:22:02 +0200 Subject: [PATCH 2/2] Bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 014a362..b2affc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@c-frame/three-to-ammo", - "version": "1.0.2", + "version": "1.0.3", "description": "Convert THREE.Mesh to Ammo.btCollisionShape", "homepage": "https://github.com/infinitelee/three-to-ammo", "main": "index.js",