Skip to content

Commit

Permalink
Merge pull request #5 from Elettrotecnica/fix-regression-with-interle…
Browse files Browse the repository at this point in the history
…aved-vertices

Fix regression with interleaved vertices
  • Loading branch information
diarmidmackenzie authored Apr 29, 2024
2 parents de7c1ca + 1625050 commit 0403bd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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) {
Expand All @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0403bd0

Please # to comment.