forked from collinhover/threeoctree
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththreeoctree.min.js
10 lines (10 loc) · 18.7 KB
/
threeoctree.min.js
1
2
3
4
5
6
7
8
9
10
/*!
*
* threeoctree.js (r60) / https://github.com/collinhover/threeoctree
* (sparse) dynamic 3D spatial representation structure for fast searches.
*
* @author Collin Hover / http://collinhover.com/
* based on Dynamic Octree by Piko3D @ http://www.piko3d.com/ and Octree by Marek Pawlowski @ pawlowski.it
*
*/
(function(f){function d(g){return !isNaN(g)&&isFinite(g)}function b(g){return Object.prototype.toString.call(g)==="[object Array]"}function e(g){return g?(b(g)!==true?[g]:g):[]}function a(k,j){for(var h=0,g=k.length;h<g;h++){if(k[h]===j){return h}}return -1}function c(l,k,j){for(var h=0,g=l.length;h<g;h++){if(l[h][k]===j){return h}}return -1}f.Octree=function(g){g=g||{};g.tree=this;this.nodeCount=0;this.INDEX_INSIDE_CROSS=-1;this.INDEX_OUTSIDE_OFFSET=2;this.INDEX_OUTSIDE_POS_X=d(g.INDEX_OUTSIDE_POS_X)?g.INDEX_OUTSIDE_POS_X:0;this.INDEX_OUTSIDE_NEG_X=d(g.INDEX_OUTSIDE_NEG_X)?g.INDEX_OUTSIDE_NEG_X:1;this.INDEX_OUTSIDE_POS_Y=d(g.INDEX_OUTSIDE_POS_Y)?g.INDEX_OUTSIDE_POS_Y:2;this.INDEX_OUTSIDE_NEG_Y=d(g.INDEX_OUTSIDE_NEG_Y)?g.INDEX_OUTSIDE_NEG_Y:3;this.INDEX_OUTSIDE_POS_Z=d(g.INDEX_OUTSIDE_POS_Z)?g.INDEX_OUTSIDE_POS_Z:4;this.INDEX_OUTSIDE_NEG_Z=d(g.INDEX_OUTSIDE_NEG_Z)?g.INDEX_OUTSIDE_NEG_Z:5;this.INDEX_OUTSIDE_MAP=[];this.INDEX_OUTSIDE_MAP[this.INDEX_OUTSIDE_POS_X]={index:this.INDEX_OUTSIDE_POS_X,count:0,x:1,y:0,z:0};this.INDEX_OUTSIDE_MAP[this.INDEX_OUTSIDE_NEG_X]={index:this.INDEX_OUTSIDE_NEG_X,count:0,x:-1,y:0,z:0};this.INDEX_OUTSIDE_MAP[this.INDEX_OUTSIDE_POS_Y]={index:this.INDEX_OUTSIDE_POS_Y,count:0,x:0,y:1,z:0};this.INDEX_OUTSIDE_MAP[this.INDEX_OUTSIDE_NEG_Y]={index:this.INDEX_OUTSIDE_NEG_Y,count:0,x:0,y:-1,z:0};this.INDEX_OUTSIDE_MAP[this.INDEX_OUTSIDE_POS_Z]={index:this.INDEX_OUTSIDE_POS_Z,count:0,x:0,y:0,z:1};this.INDEX_OUTSIDE_MAP[this.INDEX_OUTSIDE_NEG_Z]={index:this.INDEX_OUTSIDE_NEG_Z,count:0,x:0,y:0,z:-1};this.FLAG_POS_X=1<<(this.INDEX_OUTSIDE_POS_X+1);this.FLAG_NEG_X=1<<(this.INDEX_OUTSIDE_NEG_X+1);this.FLAG_POS_Y=1<<(this.INDEX_OUTSIDE_POS_Y+1);this.FLAG_NEG_Y=1<<(this.INDEX_OUTSIDE_NEG_Y+1);this.FLAG_POS_Z=1<<(this.INDEX_OUTSIDE_POS_Z+1);this.FLAG_NEG_Z=1<<(this.INDEX_OUTSIDE_NEG_Z+1);this.utilVec31Search=new f.Vector3();this.utilVec32Search=new f.Vector3();this.scene=g.scene;if(this.scene){this.visualGeometry=new f.CubeGeometry(1,1,1);this.visualMaterial=new f.MeshBasicMaterial({color:16711782,wireframe:true,wireframeLinewidth:1})}this.objects=[];this.objectsMap={};this.objectsData=[];this.objectsDeferred=[];this.depthMax=d(g.depthMax)?g.depthMax:Infinity;this.objectsThreshold=d(g.objectsThreshold)?g.objectsThreshold:8;this.overlapPct=d(g.overlapPct)?g.overlapPct:0.15;this.undeferred=g.undeferred||false;this.root=g.root instanceof f.OctreeNode?g.root:new f.OctreeNode(g)};f.Octree.prototype={update:function(){if(this.objectsDeferred.length>0){for(var j=0,h=this.objectsDeferred.length;j<h;j++){var g=this.objectsDeferred[j];this.addDeferred(g.object,g.options)}this.objectsDeferred.length=0}},add:function(h,g){if(this.undeferred){this.updateObject(h);this.addDeferred(h,g)}else{this.objectsDeferred.push({object:h,options:g})}},addDeferred:function(k,r){var m,j,p,g,h,o,n,q;if(k instanceof f.OctreeObjectData){k=k.object}if(!k.uuid){k.uuid=f.Math.generateUUID()}if(!this.objectsMap[k.uuid]){this.objects.push(k);this.objectsMap[k.uuid]=k;if(r){h=r.useFaces;n=r.useVertices}if(n===true){p=k.geometry;o=p.vertices;for(m=0,j=o.length;m<j;m++){this.addObjectData(k,o[m])}}else{if(h===true){p=k.geometry;g=p.faces;for(m=0,j=g.length;m<j;m++){this.addObjectData(k,g[m])}}else{this.addObjectData(k)}}}},addObjectData:function(i,h){var g=new f.OctreeObjectData(i,h);this.objectsData.push(g);this.root.addObject(g)},remove:function(k){var m,g,j=k,h,n;if(k instanceof f.OctreeObjectData){k=k.object}if(this.objectsMap[k.uuid]){this.objectsMap[k.uuid]=undefined;h=a(this.objects,k);if(h!==-1){this.objects.splice(h,1);n=this.root.removeObject(j);for(m=0,g=n.length;m<g;m++){j=n[m];h=a(this.objectsData,j);if(h!==-1){this.objectsData.splice(h,1)}}}}else{if(this.objectsDeferred.length>0){h=c(this.objectsDeferred,"object",k);if(h!==-1){this.objectsDeferred.splice(h,1)}}}},extend:function(j){var m,h,g,k;if(j instanceof f.Octree){g=j.objectsData;for(m=0,h=g.length;m<h;m++){k=g[m];this.add(k,{useFaces:k.faces,useVertices:k.vertices})}}},rebuild:function(){var m,g,o,j,h,n,p,k=[];for(m=0,g=this.objectsData.length;m<g;m++){h=this.objectsData[m];o=h.node;h.update();if(o instanceof f.OctreeNode&&!h.positionLast.equals(h.position)){p=h.indexOctant;n=o.getOctantIndex(h);if(n!==p){k.push(h)}}}for(m=0,g=k.length;m<g;m++){h=k[m];h.node.removeObject(h);this.root.addObject(h)}},updateObject:function(j){var k,g,n=[j],m,h;m=j.parent;while(m){n.push(m);m=m.parent}for(k=0,g=n.length;k<g;k++){m=n[k];if(m.matrixWorldNeedsUpdate===true){h=m}}if(typeof h!=="undefined"){h.updateMatrixWorld()}},search:function(p,s,r,u){var o,k,j,w,v,m,n,h,g,t,q;w=[].concat(this.root.objects);if(!(s>0)){s=Number.MAX_VALUE}if(u instanceof f.Vector3){u=this.utilVec31Search.copy(u).normalize();q=this.utilVec32Search.set(1,1,1).divide(u)}for(o=0,k=this.root.nodesIndices.length;o<k;o++){j=this.root.nodesByIndex[this.root.nodesIndices[o]];w=j.search(p,s,w,u,q)}if(r===true){n=[];g=[];for(o=0,k=w.length;o<k;o++){v=w[o];m=v.object;t=a(g,m);if(t===-1){h={object:m,faces:[],vertices:[]};n.push(h);g.push(m)}else{h=n[t]}if(v.faces){h.faces.push(v.faces)}else{if(v.vertices){h.vertices.push(v.vertices)}}}}else{n=w}return n},setRoot:function(g){if(g instanceof f.OctreeNode){this.root=g;this.root.updateProperties()}},getDepthEnd:function(){return this.root.getDepthEnd()},getNodeCountEnd:function(){return this.root.getNodeCountEnd()},getObjectCountEnd:function(){return this.root.getObjectCountEnd()},toConsole:function(){this.root.toConsole()}};f.OctreeObjectData=function(h,g){this.object=h;if(g instanceof f.Face3){this.faces=g;this.face3=true;this.utilVec31FaceBounds=new f.Vector3()}else{if(g instanceof f.Face4){this.face4=true;this.faces=g;this.utilVec31FaceBounds=new f.Vector3()}else{if(g instanceof f.Vector3){this.vertices=g}}}this.radius=0;this.position=new f.Vector3();if(this.object instanceof f.Object3D){this.update()}this.positionLast=this.position.clone()};f.OctreeObjectData.prototype={update:function(){if(this.face3){this.radius=this.getFace3BoundingRadius(this.object,this.faces);this.position.copy(this.faces.centroid).applyMatrix4(this.object.matrixWorld)}else{if(this.face4){this.radius=this.getFace4BoundingRadius(this.object,this.faces);this.position.copy(this.faces.centroid).applyMatrix4(this.object.matrixWorld)}else{if(this.vertices){this.radius=this.object.material.size||1;this.position.copy(this.vertices).applyMatrix4(this.object.matrixWorld)}else{if(this.object.geometry){if(this.object.geometry.boundingSphere===null){this.object.geometry.computeBoundingSphere()}this.radius=this.object.geometry.boundingSphere.radius;this.position.copy(this.object.geometry.boundingSphere.center).applyMatrix4(this.object.matrixWorld)}else{this.radius=this.object.boundRadius;this.position.getPositionFromMatrix(this.object.matrixWorld)}}}}this.radius=this.radius*Math.max(this.object.scale.x,this.object.scale.y,this.object.scale.z)},getFace3BoundingRadius:function(i,l){var o=i.geometry||i,k=o.vertices,g=l.centroid,p=k[l.a],n=k[l.b],m=k[l.c],h=this.utilVec31FaceBounds,j;g.addVectors(p,n).add(m).divideScalar(3);j=Math.max(h.subVectors(g,p).length(),h.subVectors(g,n).length(),h.subVectors(g,m).length());return j},getFace4BoundingRadius:function(i,m){var p=i.geometry||i,l=p.vertices,g=m.centroid,q=l[m.a],o=l[m.b],n=l[m.c],k=l[m.d],h=this.utilVec31FaceBounds,j;g.addVectors(q,o).add(n).add(k).divideScalar(4);j=Math.max(h.subVectors(g,q).length(),h.subVectors(g,o).length(),h.subVectors(g,n).length(),h.subVectors(g,k).length());return j}};f.OctreeNode=function(g){this.utilVec31Branch=new f.Vector3();this.utilVec31Expand=new f.Vector3();this.utilVec31Ray=new f.Vector3();g=g||{};if(g.tree instanceof f.Octree){this.tree=g.tree}else{if(g.parent instanceof f.OctreeNode!==true){g.root=this;this.tree=new f.Octree(g)}}this.id=this.tree.nodeCount++;this.position=g.position instanceof f.Vector3?g.position:new f.Vector3();this.radius=g.radius>0?g.radius:1;this.indexOctant=g.indexOctant;this.depth=0;this.reset();this.setParent(g.parent);this.overlap=this.radius*this.tree.overlapPct;this.radiusOverlap=this.radius+this.overlap;this.left=this.position.x-this.radiusOverlap;this.right=this.position.x+this.radiusOverlap;this.bottom=this.position.y-this.radiusOverlap;this.top=this.position.y+this.radiusOverlap;this.back=this.position.z-this.radiusOverlap;this.front=this.position.z+this.radiusOverlap;if(this.tree.scene){this.visual=new f.Mesh(this.tree.visualGeometry,this.tree.visualMaterial);this.visual.scale.set(this.radiusOverlap*2,this.radiusOverlap*2,this.radiusOverlap*2);this.visual.position.copy(this.position);this.tree.scene.add(this.visual)}};f.OctreeNode.prototype={setParent:function(g){if(g!==this&&this.parent!==g){this.parent=g;this.updateProperties()}},updateProperties:function(){var h,g;if(this.parent instanceof f.OctreeNode){this.tree=this.parent.tree;this.depth=this.parent.depth+1}else{this.depth=0}for(h=0,g=this.nodesIndices.length;h<g;h++){this.nodesByIndex[this.nodesIndices[h]].updateProperties()}},reset:function(h,n){var j,g,k,m=this.nodesIndices||[],o=this.nodesByIndex;this.objects=[];this.nodesIndices=[];this.nodesByIndex={};for(j=0,g=m.length;j<g;j++){k=o[m[j]];k.setParent(undefined);if(h===true){k.reset(h,n)}}if(n===true&&this.visual&&this.visual.parent){this.visual.parent.remove(this.visual)}},addNode:function(h,g){h.indexOctant=g;if(a(this.nodesIndices,g)===-1){this.nodesIndices.push(g)}this.nodesByIndex[g]=h;if(h.parent!==this){h.setParent(this)}},removeNode:function(h){var g,i;g=a(this.nodesIndices,h);this.nodesIndices.splice(g,1);i=i||this.nodesByIndex[h];delete this.nodesByIndex[h];if(i.parent===this){i.setParent(undefined)}},addObject:function(h){var g,i,j;i=this.getOctantIndex(h);if(i>-1&&this.nodesIndices.length>0){j=this.branch(i);j.addObject(h)}else{if(i<-1&&this.parent instanceof f.OctreeNode){this.parent.addObject(h)}else{g=a(this.objects,h);if(g===-1){this.objects.push(h)}h.node=this;this.checkGrow()}}},addObjectWithoutCheck:function(k){var j,g,h;for(j=0,g=k.length;j<g;j++){h=k[j];this.objects.push(h);h.node=this}},removeObject:function(h){var j,g,k,m;m=this.removeObjectRecursive(h,{searchComplete:false,nodesRemovedFrom:[],objectsDataRemoved:[]});k=m.nodesRemovedFrom;if(k.length>0){for(j=0,g=k.length;j<g;j++){k[j].shrink()}}return m.objectsDataRemoved},removeObjectRecursive:function(k,p){var m,g,j=-1,h,o,n;if(k instanceof f.OctreeObjectData){j=a(this.objects,k);if(j!==-1){this.objects.splice(j,1);k.node=undefined;p.objectsDataRemoved.push(k);p.searchComplete=n=true}}else{for(m=this.objects.length-1;m>=0;m--){h=this.objects[m];if(h.object===k){this.objects.splice(m,1);h.node=undefined;p.objectsDataRemoved.push(h);n=true;if(!h.faces&&!h.vertices){p.searchComplete=true;break}}}}if(n===true){p.nodesRemovedFrom.push(this)}if(p.searchComplete!==true){for(m=0,g=this.nodesIndices.length;m<g;m++){o=this.nodesByIndex[this.nodesIndices[m]];p=o.removeObjectRecursive(k,p);if(p.searchComplete===true){break}}}return p},checkGrow:function(){if(this.objects.length>this.tree.objectsThreshold&&this.tree.objectsThreshold>0){this.grow()}},grow:function(){var g,m,h=[],j=[],o=[],q=[],p=[],n,k;for(n=0,k=this.objects.length;n<k;n++){m=this.objects[n];g=this.getOctantIndex(m);if(g>-1){o.push(m);q.push(g)}else{if(g<-1){h.push(m);j.push(g)}else{p.push(m)}}}if(o.length>0){p=p.concat(this.split(o,q))}if(h.length>0){p=p.concat(this.expand(h,j))}this.objects=p;this.checkMerge()},split:function(p,h){var k,g,n,j,o,m;if(this.depth<this.tree.depthMax){p=p||this.objects;h=h||[];m=[];for(k=0,g=p.length;k<g;k++){j=p[k];n=h[k];if(n>-1){o=this.branch(n);o.addObject(j)}else{m.push(j)}}if(p===this.objects){this.objects=m}}else{m=this.objects}return m},branch:function(k){var l,j,h,i,m,g;if(this.nodesByIndex[k] instanceof f.OctreeNode){l=this.nodesByIndex[k]}else{h=(this.radiusOverlap)*0.5;j=h*this.tree.overlapPct;i=h-j;m=this.utilVec31Branch.set(k&1?i:-i,k&2?i:-i,k&4?i:-i);g=new f.Vector3().addVectors(this.position,m);l=new f.OctreeNode({tree:this.tree,parent:this,position:g,radius:h,indexOctant:k});this.addNode(l,k)}return l},expand:function(h,L){var H,G,P,J,M,j,u,y,q,A=this.tree.INDEX_OUTSIDE_MAP,w,D,B,z,o,m,F,E,C,K,I,t,s,r,g,n,N,k,x,p=this.utilVec31Expand,O,v;if(this.tree.root.getDepthEnd()<this.tree.depthMax){h=h||this.objects;L=L||[];J=[];M=[];for(H=0,G=A.length;H<G;H++){A[H].count=0}for(H=0,G=h.length;H<G;H++){P=h[H];j=L[H];if(j<-1){u=-j-this.tree.INDEX_OUTSIDE_OFFSET;if(u&this.tree.FLAG_POS_X){A[this.tree.INDEX_OUTSIDE_POS_X].count++}else{if(u&this.tree.FLAG_NEG_X){A[this.tree.INDEX_OUTSIDE_NEG_X].count++}}if(u&this.tree.FLAG_POS_Y){A[this.tree.INDEX_OUTSIDE_POS_Y].count++}else{if(u&this.tree.FLAG_NEG_Y){A[this.tree.INDEX_OUTSIDE_NEG_Y].count++}}if(u&this.tree.FLAG_POS_Z){A[this.tree.INDEX_OUTSIDE_POS_Z].count++}else{if(u&this.tree.FLAG_NEG_Z){A[this.tree.INDEX_OUTSIDE_NEG_Z].count++}}M.push(P)}else{J.push(P)}}if(M.length>0){w=A.slice(0);w.sort(function(l,i){return i.count-l.count});D=w[0];o=D.index|1;F=w[1];E=w[2];B=(F.index|1)!==o?F:E;m=B.index|1;F=w[2];E=w[3];C=w[4];K=F.index|1;I=E.index|1;z=K!==o&&K!==m?F:I!==o&&I!==m?E:C;t=D.x+B.x+z.x;s=D.y+B.y+z.y;r=D.z+B.z+z.z;j=this.getOctantIndexFromPosition(t,s,r);q=this.getOctantIndexFromPosition(-t,-s,-r);g=this.overlap;n=this.radius;k=this.tree.overlapPct>0?g/((0.5*this.tree.overlapPct)*(1+this.tree.overlapPct)):n*2;x=k*this.tree.overlapPct;N=(k+x)-(n+g);p.set(j&1?N:-N,j&2?N:-N,j&4?N:-N);O=new f.Vector3().addVectors(this.position,p);v=new f.OctreeNode({tree:this.tree,position:O,radius:k});v.addNode(this,q);this.tree.setRoot(v);for(H=0,G=M.length;H<G;H++){this.tree.root.addObject(M[H])}}if(h===this.objects){this.objects=J}}else{J=h}return J},shrink:function(){this.checkMerge();this.tree.root.checkContract()},checkMerge:function(){var g=this,h;while(g.parent instanceof f.OctreeNode&&g.getObjectCountEnd()<this.tree.objectsThreshold){h=g;g=g.parent}if(g!==this){g.merge(h)}},merge:function(m){var o,g,n,h,p;m=e(m);for(o=0,g=m.length;o<g;o++){p=m[o];this.addObjectWithoutCheck(p.getObjectsEnd());p.reset(true,true);this.removeNode(p.indexOctant,p)}this.checkMerge()},checkContract:function(){var m,j,o,n,h,g,k;if(this.nodesIndices.length>0){g=0;k=this.objects.length;for(m=0,j=this.nodesIndices.length;m<j;m++){o=this.nodesByIndex[this.nodesIndices[m]];n=o.getObjectCountEnd();k+=n;if(h instanceof f.OctreeNode===false||n>g){h=o;g=n}}k-=g;if(k<this.tree.objectsThreshold&&h instanceof f.OctreeNode){this.contract(h)}}},contract:function(k){var h,g,j;for(h=0,g=this.nodesIndices.length;h<g;h++){j=this.nodesByIndex[this.nodesIndices[h]];if(j!==k){k.addObjectWithoutCheck(j.getObjectsEnd());j.reset(true,true)}}k.addObjectWithoutCheck(this.objects);this.reset(false,true);this.tree.setRoot(k);k.checkContract()},getOctantIndex:function(x){var p,k,n,s,q=this.position,v=this.radiusOverlap,w=this.overlap,o,m,j,u,t,r,h,g=0;if(x instanceof f.OctreeObjectData){s=x.radius;n=x.position;x.positionLast.copy(n)}else{if(x instanceof f.OctreeNode){n=x.position;s=0}}o=n.x-q.x;m=n.y-q.y;j=n.z-q.z;u=Math.abs(o);t=Math.abs(m);r=Math.abs(j);h=Math.max(u,t,r);if(h+s>v){if(u+s>v){g=g^(o>0?this.tree.FLAG_POS_X:this.tree.FLAG_NEG_X)}if(t+s>v){g=g^(m>0?this.tree.FLAG_POS_Y:this.tree.FLAG_NEG_Y)}if(r+s>v){g=g^(j>0?this.tree.FLAG_POS_Z:this.tree.FLAG_NEG_Z)}x.indexOctant=-g-this.tree.INDEX_OUTSIDE_OFFSET;return x.indexOctant}if(o-s>-w){g=g|1}else{if(!(o+s<w)){x.indexOctant=this.tree.INDEX_INSIDE_CROSS;return x.indexOctant}}if(m-s>-w){g=g|2}else{if(!(m+s<w)){x.indexOctant=this.tree.INDEX_INSIDE_CROSS;return x.indexOctant}}if(j-s>-w){g=g|4}else{if(!(j+s<w)){x.indexOctant=this.tree.INDEX_INSIDE_CROSS;return x.indexOctant}}x.indexOctant=g;return x.indexOctant},getOctantIndexFromPosition:function(g,j,i){var h=0;if(g>0){h=h|1}if(j>0){h=h|2}if(i>0){h=h|4}return h},search:function(k,o,q,p,m){var j,h,g,n;if(p){n=this.intersectRay(k,p,o,m)}else{n=this.intersectSphere(k,o)}if(n===true){q=q.concat(this.objects);for(j=0,h=this.nodesIndices.length;j<h;j++){g=this.nodesByIndex[this.nodesIndices[j]];q=g.search(k,o,q,p)}}return q},intersectSphere:function(h,g){var l=g*g,k=h.x,j=h.y,i=h.z;if(k<this.left){l-=Math.pow(k-this.left,2)}else{if(k>this.right){l-=Math.pow(k-this.right,2)}}if(j<this.bottom){l-=Math.pow(j-this.bottom,2)}else{if(j>this.top){l-=Math.pow(j-this.top,2)}}if(i<this.back){l-=Math.pow(i-this.back,2)}else{if(i>this.front){l-=Math.pow(i-this.front,2)}}return l>=0},intersectRay:function(r,q,g,p){if(typeof p==="undefined"){p=this.utilVec31Ray.set(1,1,1).divide(q)}var o=(this.left-r.x)*p.x,n=(this.right-r.x)*p.x,l=(this.bottom-r.y)*p.y,k=(this.top-r.y)*p.y,j=(this.back-r.z)*p.z,i=(this.front-r.z)*p.z,m=Math.min(Math.min(Math.max(o,n),Math.max(l,k)),Math.max(j,i)),h;if(m<0){return false}h=Math.max(Math.max(Math.min(o,n),Math.min(l,k)),Math.min(j,i));if(h>m||h>g){return false}return true},getDepthEnd:function(k){var h,g,j;if(this.nodesIndices.length>0){for(h=0,g=this.nodesIndices.length;h<g;h++){j=this.nodesByIndex[this.nodesIndices[h]];k=j.getDepthEnd(k)}}else{k=!k||this.depth>k?this.depth:k}return k},getNodeCountEnd:function(){return this.tree.root.getNodeCountRecursive()+1},getNodeCountRecursive:function(){var h,g,j=this.nodesIndices.length;for(h=0,g=this.nodesIndices.length;h<g;h++){j+=this.nodesByIndex[this.nodesIndices[h]].getNodeCountRecursive()}return j},getObjectsEnd:function(k){var h,g,j;k=(k||[]).concat(this.objects);for(h=0,g=this.nodesIndices.length;h<g;h++){j=this.nodesByIndex[this.nodesIndices[h]];k=j.getObjectsEnd(k)}return k},getObjectCountEnd:function(){var h,g,j=this.objects.length;for(h=0,g=this.nodesIndices.length;h<g;h++){j+=this.nodesByIndex[this.nodesIndices[h]].getObjectCountEnd()}return j},getObjectCountStart:function(){var h=this.objects.length,g=this.parent;while(g instanceof f.OctreeNode){h+=g.objects.length;g=g.parent}return h},toConsole:function(k){var h,g,j,m=" ";k=typeof k==="string"?k:m;console.log((this.parent?k+" octree NODE > ":" octree ROOT > "),this," // id: ",this.id," // indexOctant: ",this.indexOctant," // position: ",this.position.x,this.position.y,this.position.z," // radius: ",this.radius," // depth: ",this.depth);console.log((this.parent?k+" ":" "),"+ objects ( ",this.objects.length," ) ",this.objects);console.log((this.parent?k+" ":" "),"+ children ( ",this.nodesIndices.length," )",this.nodesIndices,this.nodesByIndex);for(h=0,g=this.nodesIndices.length;h<g;h++){j=this.nodesByIndex[this.nodesIndices[h]];j.toConsole(k+m)}}};f.Raycaster.prototype.intersectOctreeObject=function(i,h){var k,l,j,g;if(i.object instanceof f.Object3D){l=i;i=l.object;g=l.faces;j=i.geometry.faces;if(g.length>0){i.geometry.faces=g}k=this.intersectObject(i,h);if(g.length>0){i.geometry.faces=j}}else{k=this.intersectObject(i,h)}return k};f.Raycaster.prototype.intersectOctreeObjects=function(l,h){var j,g,k=[];for(j=0,g=l.length;j<g;j++){k=k.concat(this.intersectOctreeObject(l[j],h))}return k}}(THREE));