1 
  2 /**
  3  * potree.js 
  4  * http://potree.org
  5  *
  6  * Copyright 2012, Markus Sch�tz
  7  * Licensed under the GPL Version 2 or later.
  8  * - http://potree.org/wp/?page_id=7
  9  * - http://www.gnu.org/licenses/gpl-3.0.html
 10  *
 11  */
 12 
 13 /**
 14  * Create pointclouds using math!
 15  * 
 16  * @class
 17  */
 18 function ProceduralPointcloudGenerator(){
 19 	
 20 }
 21 
 22 ProceduralPointcloudGenerator.generate = function(xStart, xEnd, xStep, zStart, zEnd, zStep, genFunc){
 23 	
 24 	var points = ((xEnd - xStart) / xStep) * ((zEnd - zStart) / zStep);
 25 	var buffer = new ArrayBuffer(points*16);
 26 	var floatView = new Float32Array(buffer);
 27 	var byteView = new Uint8Array(buffer);
 28 	
 29 	var pointAttributes = {
 30 			'numAttributes' : 2,
 31 			'bytesPerPoint' : 16,
 32 			'attributes' : {}
 33 		};
 34 	pointAttributes.attributes[0] = PointAttributes.POSITION_CARTESIAN;
 35 	pointAttributes.attributes[1] = PointAttributes.COLOR_PACKED;
 36 	
 37 	var offset = 0;
 38 	for(var x = xStart; x <= xEnd; x+= xStep){
 39 		for(var z = zStart; z <= zEnd; z += zStep){
 40 			var values = genFunc(x,z);
 41 			var y = values[0];
 42 			var r = values[1];
 43 			var g = values[2];
 44 			var b = values[3];
 45 			var a = 255;
 46 			
 47 			var floatOffset = offset / 4;
 48 			floatView[floatOffset+0] = x + 0.01;
 49 			floatView[floatOffset+1] = y + 0.01;
 50 			floatView[floatOffset+2] = z + 0.01;
 51 			byteView[offset+12] = r;
 52 			byteView[offset+13] = g;
 53 			byteView[offset+14] = b;
 54 			byteView[offset+15] = a;
 55 			offset += 16;
 56 		}
 57 	}
 58 	
 59 	var pointCloud = new PointCloud("test", pointAttributes);
 60 	pointCloud.setVertexBufferData(buffer);
 61 	pointCloud.size = points;
 62 	
 63 	return pointCloud;
 64 	
 65 };
 66 
 67