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 point size depends on distance from eye. 15 * this may change so that point size depends on more factors like child node visibility, density of a node, etc. 16 * 17 * @augments Material 18 * @author Markus Sch�tz 19 */ 20 function WeightedPointSizeMaterial(name){ 21 Material.call(this, name); 22 this.shader = new Shader(name, "pointSize.vs", "colouredPoint.fs"); 23 24 this.pointSize = 0.3; 25 } 26 27 WeightedPointSizeMaterial.prototype = new Material(inheriting); 28 29 WeightedPointSizeMaterial.prototype.render = function(sceneNode, camera, lights){ 30 var transform = sceneNode.globalTransformation; 31 var pointClouds = new Array(); 32 33 if(sceneNode instanceof PointCloudSceneNode){ 34 pointClouds.push(sceneNode.pointCloud); 35 }else if(sceneNode instanceof PointcloudOctreeSceneNode){ 36 var renderQueue = sceneNode.mno.renderQueue; 37 for(var i = 0; i < renderQueue.length; i++){ 38 var node = renderQueue.get(i); 39 pointClouds.push(node.pointCloud); 40 } 41 } 42 this.renderPointClouds(transform, pointClouds, camera, lights); 43 }; 44 45 WeightedPointSizeMaterial.prototype.renderPointClouds = function renderPointClouds(transform, pointClouds, camera, lights){ 46 gl.enable(gl.DEPTH_TEST); 47 gl.disable(gl.BLEND); 48 49 for(var i = 0; i < pointClouds.length; i++){ 50 var pointCloud = pointClouds[i]; 51 var pointAttributes = pointCloud.pointAttributes; 52 gl.useProgram(this.shader.program); 53 54 { // uniforms 55 gl.uniformMatrix4fv(this.shader.uniforms.uWorld, false, transform); 56 gl.uniformMatrix4fv(this.shader.uniforms.uView, false, camera.viewMatrix); 57 gl.uniformMatrix4fv(this.shader.uniforms.uProj, false, camera.projectionMatrix); 58 gl.uniform1f(this.shader.uniforms.uPointSizeMultiplicator, this.pointSize); 59 gl.uniform2f(this.shader.uniforms.uViewportSize, Potree.canvas.clientWidth, Potree.canvas.clientHeight); 60 } 61 62 gl.bindBuffer(gl.ARRAY_BUFFER, pointCloud.vbo); 63 var offset = 0; 64 for(var j = 0; j < pointAttributes.size; j++){ 65 var attribute = pointAttributes.attributes[j]; 66 67 if(attribute == PointAttribute.POSITION_CARTESIAN){ 68 gl.enableVertexAttribArray(this.shader.attributes.aVertexPosition); 69 gl.vertexAttribPointer(this.shader.attributes.aVertexPosition, 3, gl.FLOAT, false,pointAttributes.byteSize, offset); 70 }else if(attribute == PointAttribute.RGBA_PACKED){ 71 if(this.shader.attributes.aVertexColour != null){ 72 gl.enableVertexAttribArray(this.shader.attributes.aVertexColour); 73 gl.vertexAttribPointer(this.shader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset); 74 } 75 }else if(attribute == PointAttribute.RGB_PACKED){ 76 if(this.shader.attributes.aVertexColour != null){ 77 gl.enableVertexAttribArray(this.shader.attributes.aVertexColour); 78 gl.vertexAttribPointer(this.shader.attributes.aVertexColour, 3, gl.UNSIGNED_BYTE, false,pointAttributes.byteSize, offset); 79 } 80 }else if(attribute == PointAttribute.NORMAL_FLOATS){ 81 if(this.shader.attributes.aNormal != null){ 82 gl.enableVertexAttribArray(this.shader.attributes.aNormal); 83 gl.vertexAttribPointer(this.shader.attributes.aNormal, 3, gl.FLOAT, false,pointAttributes.byteSize, offset); 84 } 85 }/*else if(attribute.name == PointAttributeNames.FILLER){ 86 87 }*/ 88 offset += attribute.byteSize; 89 } 90 91 gl.drawArrays(gl.POINTS, 0, pointCloud.size); 92 93 gl.disableVertexAttribArray(this.shader.attributes.aVertexPosition); 94 gl.disableVertexAttribArray(this.shader.attributes.aVertexColour); 95 gl.disableVertexAttribArray(this.shader.attributes.aNormal); 96 } 97 };