1 /**
  2  * potree.js 
  3  * http://potree.org
  4  *
  5  * Copyright 2012, Markus Sch�tz
  6  * Licensed under the GPL Version 2 or later.
  7  * - http://potree.org/wp/?page_id=7
  8  * - http://www.gnu.org/licenses/gpl-3.0.html
  9  *
 10  */
 11 
 12 
 13 /**
 14  * @class renders points with a fixed pixel size. 
 15  * @augments Material
 16  * @author Markus Sch�tz
 17  */
 18 function FixedPointSizeMaterial(name){
 19 	Material.call(this, name);
 20 	this.shader = new Shader(name, "fixedPointSize.vs", "colouredPoint.fs");
 21 	
 22 	this.pointSize = 1.0;
 23 }
 24 
 25 FixedPointSizeMaterial.prototype = new Material(inheriting);
 26 
 27 FixedPointSizeMaterial.prototype.render = function(mno, mnoSceneNode, camera){
 28 	var mnoNodes = mno.renderQueue.nodeList;
 29 	for(var i = 0; i < mnoNodes.size(); i++){
 30 		var node = mnoNodes[i];
 31 		var pointCloud = node.pointCloud;
 32 		var pointAttributes = mnoSceneNode.mno.pointAttributes;
 33 
 34 		gl.useProgram(this.shader.program);
 35 		
 36 		{ // uniforms
 37 			gl.uniformMatrix4fv(this.shader.uWorld, false, mnoSceneNode.globalTransformation);
 38 			gl.uniformMatrix4fv(this.shader.uView, false, camera.viewMatrix);
 39 			gl.uniformMatrix4fv(this.shader.uProjection, false, camera.projectionMatrix);
 40 			gl.uniform1f(this.shader.uPointSize, node.opacity * this.pointSize);
 41 			gl.uniform2f(this.shader.uViewportSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight);
 42 		}
 43 		
 44 		gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo);
 45 		var offset = 0;
 46 		for(var j = 0; j < pointAttributes.numAttributes; j++){
 47 			var attribute = pointAttributes.attributes[j];
 48 			
 49 			if(attribute.name == PointAttributeNames.POSITION_CARTESIAN){
 50 				gl.enableVertexAttribArray(this.shader.aVertexPosition);
 51 				gl.vertexAttribPointer(this.shader.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.bytesPerPoint, offset);
 52 			}else if(attribute.name == PointAttributeNames.COLOR_PACKED){
 53 				if(this.shader.aVertexColour != null){
 54 					gl.enableVertexAttribArray(this.shader.aVertexColour);
 55 					gl.vertexAttribPointer(this.shader.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.bytesPerPoint, offset);
 56 				}
 57 			}else if(attribute.name == PointAttributeNames.NORMAL_FLOATS){
 58 				if(this.shader.aNormal != null){
 59 					gl.enableVertexAttribArray(this.shader.aNormal);
 60 					gl.vertexAttribPointer(this.shader.aNormal, 3, gl.FLOAT, false,pointAttributes.bytesPerPoint, offset);
 61 				}
 62 			}
 63 			offset += attribute.type.size * attribute.numElements;
 64 		}
 65 		
 66 		gl.drawArrays(gl.POINTS, 0, node.points);
 67 		Potree.drawnPoints += node.points;
 68 		Potree.drawCalls += 1;
 69 		
 70 		gl.disableVertexAttribArray(this.shader.aVertexPosition);
 71 		gl.disableVertexAttribArray(this.shader.aVertexColour);
 72 		gl.disableVertexAttribArray(this.shader.aNormal);
 73 	}
 74 };