From d6ee34f2c4bc35160cc1a02682cd3ceb56647fe9 Mon Sep 17 00:00:00 2001 From: Federico Russo Date: Wed, 22 Apr 2015 17:21:48 +0200 Subject: [PATCH] If CLIP_OUTSIDE, only visible pages are loaded. --- src/PointCloudOctree.js | 18 +++ src/materials/PointCloudMaterial.js | 165 ++++++++++++++-------------- 2 files changed, 101 insertions(+), 82 deletions(-) diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index d4e09102..1863ac47 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -391,6 +391,24 @@ Potree.PointCloudOctree.prototype.getVisibleGeometry = function(camera){ var visible = insideFrustum; // && node.level <= 3; //visible = visible && "r0".indexOf(node.name) === 0; //visible = visible && node.level === 0; + + if (this.material.numClipBoxes > 0 && visible && this.material.clipMode == Potree.ClipMode.CLIP_OUTSIDE) { + var box2 = box.clone(); // node's Box3 expressed in world coordinates + this.updateMatrixWorld(true); + box2.applyMatrix4(this.matrixWorld); + var intersectsClipBoxes = false; + for (var i = 0; i < this.material.numClipBoxes; i++) { + var clipMatrixWorld = new THREE.Matrix4().copy(this.material.clipBoxes[i]); // Matrix4, inverse of clip matrixWorld + clipMatrixWorld.getInverse(clipMatrixWorld); // clip matrixWorld + var clipBox = new THREE.Box3(new THREE.Vector3(-0.5, -0.5, -0.5), new THREE.Vector3(0.5, 0.5, 0.5)); // in world coords + clipBox.applyMatrix4(clipMatrixWorld); + if (box2.isIntersectionBox(clipBox)) { + intersectsClipBoxes = true; + break; + } + } + visible = intersectsClipBoxes; + } if(!visible){ continue; diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js index 46698945..b2056325 100644 --- a/src/materials/PointCloudMaterial.js +++ b/src/materials/PointCloudMaterial.js @@ -240,6 +240,7 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){ Potree.PointCloudMaterial.prototype.setClipBoxes = function(clipBoxes){ var numBoxes = clipBoxes.length; this.numClipBoxes = numBoxes; + this.clipBoxes = clipBoxes; // an array THREE.Matrix4 if(this.uniforms.clipBoxes.value.length / 16 !== numBoxes){ this.uniforms.clipBoxes.value = new Float32Array(numBoxes * 16); @@ -818,86 +819,86 @@ Potree.PointCloudMaterial.vs_points = [ "} "]; Potree.PointCloudMaterial.fs_points_rgb = [ - "#if defined use_interpolation ", - " #extension GL_EXT_frag_depth : enable ", - "#endif ", - " ", - "precision mediump float; ", - "precision mediump int; ", - " ", - "//uniform float opacity; ", - "uniform mat4 modelMatrix; ", - "uniform mat4 modelViewMatrix; ", - "uniform mat4 projectionMatrix; ", - "uniform mat4 viewMatrix; ", - "uniform mat3 normalMatrix; ", - "uniform vec3 cameraPosition; ", - "uniform float fov; ", - "uniform float spacing; ", - "uniform float near; ", - "uniform float far; ", - " ", - "uniform float pcIndex; ", - "uniform float screenWidth; ", - "uniform float screenHeight; ", - "uniform float blendDepth; ", - " ", - "uniform sampler2D depthMap; ", - " ", - "varying vec3 vColor; ", - "varying float vOpacity; ", - "varying float vLinearDepth; ", - "varying float vDepth; ", - "varying vec3 viewPos; ", - "varying float vRadius; ", - " ", - " ", - "void main() { ", - " ", - " #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats) ", - " float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0); ", - " float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0); ", - " float c = 1.0 - (a + b); ", - " ", - " if(c < 0.0){ ", - " discard; ", - " } ", - " #endif ", - " ", - " #if defined weighted_splats ", - " vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight); ", - " ", - " float depth = texture2D(depthMap, uv).r; ", - " if(vLinearDepth > depth + vRadius){ ", - " discard; ", - " } ", - " #endif ", - " ", - " #if defined use_interpolation ", - " vec4 cPos = vec4(viewPos, 1.0); ", - " cPos.z = cPos.z + c * vRadius; ", - " vec4 pos = projectionMatrix * cPos; ", - " pos = pos / pos.w; ", - " ", - " gl_FragDepthEXT = (pos.z + 1.0) / 2.0; ", - " ", - " //gl_FragDepthEXT = gl_FragCoord.z + 0.002*(1.0-pow(c, 1.0)) * gl_FragCoord.w; ", - " #endif ", - " ", - " ", - " #if defined color_type_point_index ", - " gl_FragColor = vec4(vColor, pcIndex / 255.0); ", - " #else ", - " gl_FragColor = vec4(vColor, vOpacity); ", - " #endif ", - " ", - " ", - " #if defined weighted_splats ", - " float w = pow(c, 2.0); ", - " gl_FragColor.rgb = gl_FragColor.rgb * w; ", - " gl_FragColor.a = w; ", - " #endif ", - " ", - " ", - "} "]; + "#if defined use_interpolation", + " #extension GL_EXT_frag_depth : enable", + "#endif", + "", + "precision mediump float;", + "precision mediump int;", + "", + "//uniform float opacity;", + "uniform mat4 modelMatrix;", + "uniform mat4 modelViewMatrix;", + "uniform mat4 projectionMatrix;", + "uniform mat4 viewMatrix;", + "uniform mat3 normalMatrix;", + "uniform vec3 cameraPosition;", + "uniform float fov;", + "uniform float spacing;", + "uniform float near;", + "uniform float far;", + "", + "uniform float pcIndex;", + "uniform float screenWidth;", + "uniform float screenHeight;", + "uniform float blendDepth;", + "", + "uniform sampler2D depthMap;", + "", + "varying vec3 vColor;", + "varying float vOpacity;", + "varying float vLinearDepth;", + "varying float vDepth;", + "varying vec3 viewPos;", + "varying float vRadius;", + "", + "", + "void main() {", + " ", + " #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats)", + " float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0);", + " float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0);", + " float c = 1.0 - (a + b);", + " ", + " if(c < 0.0){", + " discard;", + " }", + " #endif", + " ", + " #if defined weighted_splats", + " vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);", + " ", + " float depth = texture2D(depthMap, uv).r;", + " if(vLinearDepth > depth + vRadius){", + " discard;", + " }", + " #endif", + " ", + " #if defined use_interpolation", + " vec4 cPos = vec4(viewPos, 1.0);", + " cPos.z = cPos.z + c * vRadius;", + " vec4 pos = projectionMatrix * cPos;", + " pos = pos / pos.w;", + " ", + " gl_FragDepthEXT = (pos.z + 1.0) / 2.0;", + " ", + " //gl_FragDepthEXT = gl_FragCoord.z + 0.002*(1.0-pow(c, 1.0)) * gl_FragCoord.w;", + " #endif", + " ", + " ", + " #if defined color_type_point_index", + " gl_FragColor = vec4(vColor, pcIndex / 255.0);", + " #else", + " gl_FragColor = vec4(vColor, vOpacity);", + " #endif", + " ", + " ", + " #if defined weighted_splats", + " float w = pow(c, 2.0);", + " gl_FragColor.rgb = gl_FragColor.rgb * w;", + " gl_FragColor.a = w;", + " #endif", + " ", + " ", + "}"];