jhylands

gds.js

Jul 16th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function gis(){
  2.     function cubePackTree(){
  3.         function cubePackTree(max,min,splitOn,root){    
  4.             this.root = root;
  5.             this.max=max;
  6.             this.min=min;
  7.             this.bin= new this.bin([],5);
  8.             this.less = null;
  9.             this.morE = null;
  10.             this.splitOn = splitOn; //0=x,1=y,2=z
  11.             this.split = null;
  12.             this.getNewSplit();
  13.         }
  14.        
  15.         function bin(){
  16.             function bin(objects,max){
  17.                 this.objects=objects;
  18.                 this.size = objects.length;
  19.                 this.maxSize = max;
  20.             }
  21.             function insert(object){
  22.                 this.objects.push(object);
  23.                 this.size++;
  24.             }
  25.         }
  26.         function getNewSplit(){
  27.             switch(this.splitOn){
  28.                 case 0:
  29.                     this.split = new THREE.Vector3((this.min.x+this.max.x)/2,0,0);
  30.                     break;
  31.                 case 1:
  32.                     this.split = new THREE.Vector3(0,(this.min.y+this.max.y)/2,0);
  33.                     break;
  34.                 case 2:
  35.                     this.split = new THREE.Vector3(0,0,(this.min.z+this.max.z)/2);
  36.                     break;
  37.             }
  38.         }
  39.  
  40.         function getPosition(vector,Dimention){
  41.             switch(Dimention){
  42.                 case 0:
  43.                     return vector.x;
  44.                     break;
  45.                 case 1:
  46.                     return vector.y;
  47.                     break;
  48.                 case 2:
  49.                     return vector.z;
  50.                     break;
  51.             }
  52.         }
  53.         function insert(object){
  54.             if(this.bin!=null){
  55.                 if(this.getPosition(object.asObject,this.splitOn)>=this.getPosition(this.split,this.splitOn)){
  56.                     this.morE.insert(object);
  57.                 }else{
  58.                     this.less.insert(object);
  59.                 }
  60.             }else{
  61.                 this.bin.insert(object);
  62.                 this.pack();
  63.             }
  64.         }
  65.        
  66.         function pack(){
  67.             if(this.bin.size>this.bin.maxSize){
  68.                 toPack = this.bin.objects;
  69.                 this.bin = null;
  70.                 this.morE = new cubePackTree(this.max,THREE.Vector3.add(this.split,this.min),((this.splitOn+1)%3),this);
  71.                 this.less = new cubePackTree(THREE.Vector3.sub(this.max,this.split),this.min,((this.splitOn+1)%3),this);
  72.                 //for(object in toPack){
  73.                 for(i=0;i<toPack.length;i++){    
  74.                     this.insert(toPack[i]);
  75.                 }
  76.             }
  77.         }
  78.        
  79.        
  80.     }
  81.    
  82.     function targetPackTree(){
  83.         function targetPackTree(max,min,root,target){
  84.             this.root = root;
  85.             this.min = min;
  86.             this.max = max;
  87.             this.split = (max+min)/2;
  88.             this.bin= new this.bin([]);
  89.             this.less = null;
  90.             this.morE = null;
  91.             this.target = target;
  92.         }
  93.         function bin(){
  94.             function bin(objects,max){
  95.                 this.objects=objects;
  96.                 this.size = objects.length;
  97.                 this.maxSize = max;
  98.             }
  99.             function insert(object){
  100.                 this.objects.push(object);
  101.                 this.size++;
  102.             }
  103.         }
  104.        
  105.         function getPosition(object){
  106.             return this.target.distanceTo(object.position);
  107.         }
  108.        
  109.         function insert(object){
  110.             if(this.bin!=null){
  111.                 if(this.getPosition(object.asObject,this.splitOn)>=this.split){
  112.                     this.morE.insert(object);
  113.                 }else{
  114.                     this.less.insert(object);
  115.                 }
  116.             }else{
  117.                 this.bin.insert(object);
  118.                 this.pack();
  119.             }
  120.         }
  121.        
  122.         function pack(){
  123.             if(this.bin.size>this.bin.maxSize){
  124.                 toPack = this.bin.objects;
  125.                 this.bin = null;
  126.                 this.morE = new targetPackTree(this.max,this.split,this,this.target);
  127.                 this.less = new targetPackTree(this.split,this.min,this,this.target);
  128.                 //for(object in toPack){
  129.                 for(i=0;i<toPack.length;i++){    
  130.                     this.insert(toPack[i]);
  131.                 }
  132.             }
  133.         }
  134.                
  135. }
Advertisement
Add Comment
Please, Sign In to add comment