Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix regression with interleaved vertices #5

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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