From 80016cfd2afab81107e84eb47f852302f2685f28 Mon Sep 17 00:00:00 2001 From: fangzhangmnm <1561797062@qq.com> Date: Wed, 15 May 2019 23:25:35 +0800 Subject: [PATCH 1/2] Fix sphereTrimesh collision error The error of collision of spheres with nonzero shapeOffset with trimesh was fixed. The error is because one forget to add spherePos-sphereBody.position to r.ni in the edge and triangle cases. --- src/world/Narrowphase.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/world/Narrowphase.js b/src/world/Narrowphase.js index 1d4bb462a..3236f8e63 100644 --- a/src/world/Narrowphase.js +++ b/src/world/Narrowphase.js @@ -607,6 +607,8 @@ Narrowphase.prototype.sphereTrimesh = function ( tmp.vsub(localSpherePos, r.ni); r.ni.normalize(); r.ni.scale(sphereShape.radius, r.ri); + r.ri.vadd(spherePos, r.ri); + r.ri.vsub(sphereBody.position, r.ri); Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp); tmp.vsub(trimeshBody.position, r.rj); @@ -645,6 +647,8 @@ Narrowphase.prototype.sphereTrimesh = function ( tmp.vsub(localSpherePos, r.ni); r.ni.normalize(); r.ni.scale(sphereShape.radius, r.ri); + r.ri.vadd(spherePos, r.ri); + r.ri.vsub(sphereBody.position, r.ri); Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp); tmp.vsub(trimeshBody.position, r.rj); From a7b49f1d90889a58222630f68352317e0cb19d81 Mon Sep 17 00:00:00 2001 From: fangzhangmnm <1561797062@qq.com> Date: Thu, 16 May 2019 00:51:20 +0800 Subject: [PATCH 2/2] Fix OctreeNode's removeEmptyNodes method The original method delete the children without triangle belongs to it, but it seems one forgot that, although there may be no triangle belongs to X, there may be triangles belong to X's children! So I write a recursive algorithm for it to check if its children has any triangles in their descendents, then decide whether to delete them. --- src/utils/Octree.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/utils/Octree.js b/src/utils/Octree.js index e0de9d306..2cb4c98ee 100644 --- a/src/utils/Octree.js +++ b/src/utils/Octree.js @@ -220,14 +220,10 @@ OctreeNode.prototype.rayQuery = function(ray, treeTransform, result) { * @method removeEmptyNodes */ OctreeNode.prototype.removeEmptyNodes = function() { - var queue = [this]; - while (queue.length) { - var node = queue.pop(); - for (var i = node.children.length - 1; i >= 0; i--) { - if(!node.children[i].data.length){ - node.children.splice(i, 1); - } + for (var i = this.children.length - 1; i >= 0; i--) { + this.children[i].removeEmptyNodes(); + if(!this.children[i].children.length && !this.children[i].data.length){ + this.children.splice(i, 1); } - Array.prototype.push.apply(queue, node.children); } };