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); } }; 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);