Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gis(){
- function cubePackTree(){
- function cubePackTree(max,min,splitOn,root){
- this.root = root;
- this.max=max;
- this.min=min;
- this.bin= new this.bin([],5);
- this.less = null;
- this.morE = null;
- this.splitOn = splitOn; //0=x,1=y,2=z
- this.split = null;
- this.getNewSplit();
- }
- function bin(){
- function bin(objects,max){
- this.objects=objects;
- this.size = objects.length;
- this.maxSize = max;
- }
- function insert(object){
- this.objects.push(object);
- this.size++;
- }
- }
- function getNewSplit(){
- switch(this.splitOn){
- case 0:
- this.split = new THREE.Vector3((this.min.x+this.max.x)/2,0,0);
- break;
- case 1:
- this.split = new THREE.Vector3(0,(this.min.y+this.max.y)/2,0);
- break;
- case 2:
- this.split = new THREE.Vector3(0,0,(this.min.z+this.max.z)/2);
- break;
- }
- }
- function getPosition(vector,Dimention){
- switch(Dimention){
- case 0:
- return vector.x;
- break;
- case 1:
- return vector.y;
- break;
- case 2:
- return vector.z;
- break;
- }
- }
- function insert(object){
- if(this.bin!=null){
- if(this.getPosition(object.asObject,this.splitOn)>=this.getPosition(this.split,this.splitOn)){
- this.morE.insert(object);
- }else{
- this.less.insert(object);
- }
- }else{
- this.bin.insert(object);
- this.pack();
- }
- }
- function pack(){
- if(this.bin.size>this.bin.maxSize){
- toPack = this.bin.objects;
- this.bin = null;
- this.morE = new cubePackTree(this.max,THREE.Vector3.add(this.split,this.min),((this.splitOn+1)%3),this);
- this.less = new cubePackTree(THREE.Vector3.sub(this.max,this.split),this.min,((this.splitOn+1)%3),this);
- //for(object in toPack){
- for(i=0;i<toPack.length;i++){
- this.insert(toPack[i]);
- }
- }
- }
- }
- function targetPackTree(){
- function targetPackTree(max,min,root,target){
- this.root = root;
- this.min = min;
- this.max = max;
- this.split = (max+min)/2;
- this.bin= new this.bin([]);
- this.less = null;
- this.morE = null;
- this.target = target;
- }
- function bin(){
- function bin(objects,max){
- this.objects=objects;
- this.size = objects.length;
- this.maxSize = max;
- }
- function insert(object){
- this.objects.push(object);
- this.size++;
- }
- }
- function getPosition(object){
- return this.target.distanceTo(object.position);
- }
- function insert(object){
- if(this.bin!=null){
- if(this.getPosition(object.asObject,this.splitOn)>=this.split){
- this.morE.insert(object);
- }else{
- this.less.insert(object);
- }
- }else{
- this.bin.insert(object);
- this.pack();
- }
- }
- function pack(){
- if(this.bin.size>this.bin.maxSize){
- toPack = this.bin.objects;
- this.bin = null;
- this.morE = new targetPackTree(this.max,this.split,this,this.target);
- this.less = new targetPackTree(this.split,this.min,this,this.target);
- //for(object in toPack){
- for(i=0;i<toPack.length;i++){
- this.insert(toPack[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment