From 0c0c88b8b4617e851d18bbdd4a45ce60562608fb Mon Sep 17 00:00:00 2001 From: mschuetz Date: Tue, 29 Nov 2016 15:14:28 +0100 Subject: [PATCH] build --- build/potree/potree.js | 2690 +++++++++++++++++------------------ build/potree/potree.min.js | 2705 ++++++++++++++++++------------------ build/potree/sidebar.html | 43 +- build/shaders/shaders.js | 9 +- src/viewer/sidebar.html | 10 - 5 files changed, 2645 insertions(+), 2812 deletions(-) diff --git a/build/potree/potree.js b/build/potree/potree.js index a818cef8..c0740024 100644 --- a/build/potree/potree.js +++ b/build/potree/potree.js @@ -936,10 +936,8 @@ Potree.Shaders["pointcloud.vs"] = [ "}", "", "void main() {", - " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", - " vViewPosition = -mvPosition.xyz;", - " vWorldPosition = worldPosition.xyz;", + " vViewPosition = mvPosition.xyz;", " gl_Position = projectionMatrix * mvPosition;", " vOpacity = opacity;", " vLinearDepth = gl_Position.w;", @@ -1004,7 +1002,7 @@ Potree.Shaders["pointcloud.vs"] = [ " float pointSize = 1.0;", " ", " float slope = tan(fov / 2.0);", - " float projFactor = 0.5 * screenHeight / (slope * vViewPosition.z);", + " float projFactor = -0.5 * screenHeight / (slope * vViewPosition.z);", " ", " float r = spacing * 1.5;", " vRadius = r;", @@ -1095,7 +1093,6 @@ Potree.Shaders["pointcloud.fs"] = [ "varying float vLogDepth;", "varying vec3 vViewPosition;", "varying float vRadius;", - "varying vec3 vWorldPosition;", "varying vec3 vNormal;", "", "float specularStrength = 1.0;", @@ -1268,7 +1265,7 @@ Potree.Shaders["pointcloud.fs"] = [ " ", " #if defined use_interpolation", " float wi = 0.0 - ( u*u + v*v);", - " vec4 pos = vec4(-vViewPosition, 1.0);", + " vec4 pos = vec4(vViewPosition, 1.0);", " pos.z += wi * vRadius;", " float linearDepth = -pos.z;", " pos = projectionMatrix * pos;", @@ -4290,6 +4287,8 @@ Potree.OrbitControls = function ( object, domElement ) { var progression = Math.min(1, this.fadeFactor * delta); + let oldTheta = theta; + theta += progression * thetaDelta; phi += progression * phiDelta; @@ -5209,7 +5208,7 @@ Potree.Annotation = function(viewer, args){ this.view = args.view || null; this.keepOpen = false; this.descriptionVisible = false; - this.callback = args.callback || null; + this.actions = args.actions || null; this.domElement = document.createElement("div"); this.domElement.style.position = "absolute"; @@ -5262,29 +5261,31 @@ Potree.Annotation = function(viewer, args){ this.elOrdinalText.userSelect = "none"; this.elOrdinal.appendChild(this.elOrdinalText); - if(this.callback != null){ + if(this.actions != null){ this.elOrdinalText.style.padding = "1px 3px 0px 8px"; - let elLink = document.createElement("img"); + for(let action of this.actions){ + let elButton = document.createElement("img"); - elLink.src = Potree.scriptPath + "/resources/icons/goto.svg"; - elLink.style.width = "24px"; - elLink.style.height = "24px"; - elLink.style.filter = "invert(1)"; - elLink.style.display = "inline-block"; - elLink.style.verticalAlign = "middle"; - elLink.style.lineHeight = "1.5em"; - elLink.style.textAlign = "center"; - elLink.style.fontFamily = "Arial"; - elLink.style.fontWeight = "bold"; - elLink.style.padding = "1px 3px 0px 3px"; - elLink.style.cursor = "default"; - - this.elOrdinal.appendChild(elLink); - - elLink.onclick = function(){ - scope.callback(); - }; + elButton.src = Potree.scriptPath + action.icon; + elButton.style.width = "24px"; + elButton.style.height = "24px"; + elButton.style.filter = "invert(1)"; + elButton.style.display = "inline-block"; + elButton.style.verticalAlign = "middle"; + elButton.style.lineHeight = "1.5em"; + elButton.style.textAlign = "center"; + elButton.style.fontFamily = "Arial"; + elButton.style.fontWeight = "bold"; + elButton.style.padding = "1px 3px 0px 3px"; + elButton.style.cursor = "default"; + + this.elOrdinal.appendChild(elButton); + + elButton.onclick = function(){ + action.onclick(); + }; + } } this.elOrdinal.onmouseenter = function(){ @@ -6466,8 +6467,8 @@ Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params) let uniforms = glstate.uniforms; gl.useProgram(program); - gl.uniformMatrix4fv(uniforms["projectionMatrix"], false, camera.projectionMatrix.elements); - gl.uniformMatrix4fv(uniforms["viewMatrix"], false, camera.matrixWorldInverse.elements); + gl.uniformMatrix4fv(uniforms["projectionMatrix"], false, new Float32Array(camera.projectionMatrix.elements)); + gl.uniformMatrix4fv(uniforms["viewMatrix"], false, new Float32Array(camera.matrixWorldInverse.elements)); { if(glstate.textures.visibleNodes === undefined){ @@ -6527,8 +6528,8 @@ Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params) pickMaterial.pcIndex = i + 1; let modelView = new THREE.Matrix4().multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld); - gl.uniformMatrix4fv(uniforms["modelMatrix"], false, object.matrixWorld.elements); - gl.uniformMatrix4fv(uniforms["modelViewMatrix"], false, modelView.elements); + gl.uniformMatrix4fv(uniforms["modelMatrix"], false, new Float32Array(object.matrixWorld.elements)); + gl.uniformMatrix4fv(uniforms["modelViewMatrix"], false, new Float32Array(modelView.elements)); let apPosition = gl.getAttribLocation(program, "position"); let apNormal = gl.getAttribLocation(program, "normal"); @@ -8256,11 +8257,10 @@ Object.defineProperty(Potree.Measure.prototype, "showDistances", { -Potree.MeasuringTool = function(scene, camera, renderer, toGeo){ +Potree.MeasuringTool = function(scene, camera, renderer){ var scope = this; this.enabled = false; - this.toGeo = toGeo; this.scene = scene; this.camera = camera; @@ -8634,10 +8634,10 @@ Potree.MeasuringTool = function(scene, camera, renderer, toGeo){ var scale = (70 / pr); label.scale.set(scale, scale, scale); - var geoCoord = scope.toGeo(point.position); + var geoCoord = point.position; var txt = geoCoord.x.toFixed(2) + " / "; - txt += geoCoord.y.toFixed(2) + " / "; - txt += geoCoord.z.toFixed(2); + txt += (-geoCoord.z).toFixed(2) + " / "; + txt += geoCoord.y.toFixed(2); label.setText(txt); } @@ -11509,187 +11509,205 @@ Object.defineProperty(ProgressBar.prototype, "message", { } }); -Potree.Viewer = function(domElement, args){ - var scope = this; - var arguments = args || {}; - var pointCloudLoadedCallback = arguments.onPointCloudLoaded || function(){}; - - this.renderArea = domElement; - - +Potree.Scene = class{ + constructor(){ + this.scene = new THREE.Scene(); + this.scenePointCloud = new THREE.Scene(); + this.sceneBG = new THREE.Scene(); + this.cameraBG; + this.pointclouds = []; + this.referenceFrame; + + this.referenceFrame = new THREE.Object3D(); + this.referenceFrame.matrixAutoUpdate = false; + this.scenePointCloud.add(this.referenceFrame); + } +}; - //if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { - // defaultSettings.navigation = "Orbit"; - //} +Potree.Viewer = class{ - this.annotations = []; - this.fov = 60; - this.pointSize = 1; - this.minPointSize = 1; - this.maxPointSize = 50; - this.opacity = 1; - this.sizeType = "Fixed"; - this.pointSizeType = Potree.PointSizeType.FIXED; - this.pointColorType = null; - this.clipMode = Potree.ClipMode.HIGHLIGHT_INSIDE; - this.quality = "Squares"; - this.isFlipYZ = false; - this.useDEMCollisions = false; - this.minNodeSize = 100; - this.directionalLight; - this.edlStrength = 1.0; - this.edlRadius = 1.4; - this.useEDL = false; - this.minimumJumpDistance = 0.2; - this.jumpDistance = null; - this.intensityMax = null; - this.heightMin = null; - this.heightMax = null; - this.materialTransition = 0.5; - this.weightRGB = 1.0; - this.weightIntensity = 0.0; - this.weightElevation = 0.0; - this.weightClassification = 0.0; - this.weightReturnNumber = 0.0; - this.weightSourceID = 0.0; - this.intensityRange = [0, 65000]; - this.intensityGamma = 1; - this.intensityContrast = 0; - this.intensityBrightness = 0; - this.rgbGamma = 1; - this.rgbContrast = 0; - this.rgbBrightness = 0; - - this.moveSpeed = 10; + constructor(domElement, args){ + var a = args || {}; + this.pointCloudLoadedCallback = a.onPointCloudLoaded || function(){}; + + this.renderArea = domElement; + + //if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { + // defaultSettings.navigation = "Orbit"; + //} + + this.annotations = []; + this.fov = 60; + this.pointSize = 1; + this.minPointSize = 1; + this.maxPointSize = 50; + this.opacity = 1; + this.sizeType = "Fixed"; + this.pointSizeType = Potree.PointSizeType.FIXED; + this.pointColorType = null; + this.clipMode = Potree.ClipMode.HIGHLIGHT_INSIDE; + this.quality = "Squares"; + this.isFlipYZ = false; + this.useDEMCollisions = false; + this.minNodeSize = 100; + this.directionalLight; + this.edlStrength = 1.0; + this.edlRadius = 1.4; + this.useEDL = false; + this.minimumJumpDistance = 0.2; + this.jumpDistance = null; + this.intensityMax = null; + this.heightMin = null; + this.heightMax = null; + this.materialTransition = 0.5; + this.weightRGB = 1.0; + this.weightIntensity = 0.0; + this.weightElevation = 0.0; + this.weightClassification = 0.0; + this.weightReturnNumber = 0.0; + this.weightSourceID = 0.0; + this.intensityRange = [0, 65000]; + this.intensityGamma = 1; + this.intensityContrast = 0; + this.intensityBrightness = 0; + this.rgbGamma = 1; + this.rgbContrast = 0; + this.rgbBrightness = 0; + + this.moveSpeed = 10; - this.showDebugInfos = false; - this.showStats = true; - this.showBoundingBox = false; - this.freeze = false; + this.showDebugInfos = false; + this.showStats = true; + this.showBoundingBox = false; + this.freeze = false; - this.fpControls; - this.orbitControls; - this.earthControls; - this.geoControls; - this.controls; + this.fpControls; + this.orbitControls; + this.earthControls; + this.geoControls; + this.controls; + this.mapView; - this.progressBar = new ProgressBar(); + this.progressBar = new ProgressBar(); + + this.stats = new Stats(); + //this.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom + //document.body.appendChild( this.stats.dom ); + //this.stats.dom.style.left = "100px"; + + this.potreeRenderer = null; + this.highQualityRenderer = null; + this.edlRenderer = null; + this.renderer; + this.camera; + + this.scene = new Potree.Scene(); + + this.measuringTool; + this.volumeTool; + this.transformationTool; + + this.dispatcher = new THREE.EventDispatcher(); + this.skybox; + this.stats; + this.clock = new THREE.Clock(); + this.showSkybox = false; + + this.initThree(); + + {// set defaults + this.setPointSize(1); + this.setFOV(60); + this.setOpacity(1); + this.setEDLEnabled(false); + this.setEDLRadius(1.4); + this.setEDLStrength(1.0); + this.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); + this.setPointBudget(1*1000*1000); + this.setShowBoundingBox(false); + this.setFreeze(false); + this.setNavigationMode("Orbit"); + + this.scaleFactor = 1; + + this.loadSettingsFromURL(); + } + + // start rendering! + requestAnimationFrame(this.loop.bind(this)); + + } - var gui; - - this.renderer; - this.camera; - this.scene; - this.scenePointCloud; - this.sceneBG; - this.cameraBG; - this.pointclouds = []; - this.measuringTool; - this.volumeTool; - this.transformationTool; - - var skybox; - this.stats; - var clock = new THREE.Clock(); - this.showSkybox = false; - this.referenceFrame; - - - - - - - - - - - - - - - - - - - - - - - - - - - //------------------------------------------------------------------------------------ // Viewer API //------------------------------------------------------------------------------------ - this.addPointCloud = function(path, callback){ + addEventListener(type, callback){ + this.dispatcher.addEventListener(type, callback); + } + + addPointCloud(path, callback){ callback = callback || function(){}; var initPointcloud = function(pointcloud){ - if(!scope.mapView){ + if(!this.mapView){ if(pointcloud.projection){ - scope.mapView = new Potree.Viewer.MapView(viewer); - scope.mapView.init(viewer); + this.mapView = new Potree.MapView(this); + this.mapView.init(this); } } - scope.pointclouds.push(pointcloud); - - scope.referenceFrame.add(pointcloud); + this.scene.pointclouds.push(pointcloud); + this.scene.referenceFrame.add(pointcloud); var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld); - scope.referenceFrame.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); if(sg.radius > 50*1000){ - scope.camera.near = 10; + this.camera.near = 10; }else if(sg.radius > 10*1000){ - scope.camera.near = 2; + this.camera.near = 2; }else if(sg.radius > 1000){ - scope.camera.near = 1; + this.camera.near = 1; }else if(sg.radius > 100){ - scope.camera.near = 0.5; + this.camera.near = 0.5; }else{ - scope.camera.near = 0.1; + this.camera.near = 0.1; } - if(scope.pointclouds.length === 1){ - scope.referenceFrame.position.sub(sg.center); - scope.referenceFrame.updateMatrixWorld(true); - var moveSpeed = sg.radius / 6; - scope.setMoveSpeed(moveSpeed); - } + //if(this.scene.pointclouds.length === 1){ + // this.scene.referenceFrame.position.sub(sg.center); + // this.scene.referenceFrame.updateMatrixWorld(true); + // var moveSpeed = sg.radius / 6; + // this.setMoveSpeed(moveSpeed); + //} - //scope.flipYZ(); + //this.flipYZ(); - scope.zoomTo(pointcloud, 1); + this.zoomTo(pointcloud, 1); - - var hr = scope.getHeightRange(); + var hr = this.getHeightRange(); if(hr.min === null || hr.max === null){ - var bbWorld = scope.getBoundingBox(); + var bbWorld = this.getBoundingBox(); - scope.setHeightRange(bbWorld.min.y, bbWorld.max.y); + this.setHeightRange(bbWorld.min.y, bbWorld.max.y); } - scope.earthControls.pointclouds.push(pointcloud); + this.earthControls.pointclouds.push(pointcloud); - if(scope.pointclouds.length === 1){ - scope.setNavigationMode("Orbit"); - scope.flipYZ(); - scope.zoomTo(pointcloud, 1); + if(this.scene.pointclouds.length === 1){ + this.setNavigationMode("Orbit"); + this.flipYZ(); + this.zoomTo(pointcloud, 1); } - - - scope.dispatchEvent({"type": "pointcloud_loaded", "pointcloud": pointcloud}); + this.dispatcher.dispatchEvent({"type": "pointcloud_loaded", "pointcloud": pointcloud}); callback({type: "pointcloud_loaded", pointcloud: pointcloud}); - }; - this.addEventListener("pointcloud_loaded", pointCloudLoadedCallback); + }.bind(this); + this.dispatcher.addEventListener("pointcloud_loaded", this.pointCloudLoadedCallback); // load pointcloud if(!path){ @@ -11699,16 +11717,16 @@ Potree.Viewer = function(domElement, args){ if(!geometry){ callback({type: "loading_failed"}); }else{ - pointcloud = new Potree.PointCloudOctree(geometry); + let pointcloud = new Potree.PointCloudOctree(geometry); initPointcloud(pointcloud); } - }); + }.bind(this)); }else if(path.indexOf(".vpc") > 0){ Potree.PointCloudArena4DGeometry.load(path, function(geometry){ if(!geometry){ callback({type: "loading_failed"}); }else{ - pointcloud = new Potree.PointCloudArena4D(geometry); + let pointcloud = new Potree.PointCloudArena4D(geometry); initPointcloud(pointcloud); } }); @@ -11717,451 +11735,451 @@ Potree.Viewer = function(domElement, args){ } }; - this.toLocal = (function(viewer){ - return function(position){ - var scenePos = position.clone().applyMatrix4(viewer.referenceFrame.matrixWorld); - - return scenePos; - } - })(this); - - - this.toGeo = (function(viewer){ - return function(position){ - var inverse = new THREE.Matrix4().getInverse(viewer.referenceFrame.matrixWorld); - var geoPos = position.clone().applyMatrix4(inverse); + //toLocal(position){ + // var scenePos = position.clone().applyMatrix4(this.scene.referenceFrame.matrixWorld); + // + // return scenePos; + //}; + // + // + //toGeo(position){ + // var inverse = new THREE.Matrix4().getInverse(this.scene.referenceFrame.matrixWorld); + // var geoPos = position.clone().applyMatrix4(inverse); + // + // return geoPos; + //}; - return geoPos; - } - })(this); - - this.getMinNodeSize = function(){ - return scope.minNodeSize; + getMinNodeSize(){ + return this.minNodeSize; }; - this.setMinNodeSize = function(value){ - if(scope.minNodeSize !== value){ - scope.minNodeSize = value; - scope.dispatchEvent({"type": "minnodesize_changed", "viewer": scope}); + setMinNodeSize(value){ + if(this.minNodeSize !== value){ + this.minNodeSize = value; + this.dispatcher.dispatchEvent({"type": "minnodesize_changed", "viewer": this}); } }; - this.setDescription = function(value){ + setDescription(value){ $('#potree_description')[0].innerHTML = value; }; - this.setNavigationMode = function(value){ + setNavigationMode(value){ if(value === "Orbit"){ - scope.useOrbitControls(); + this.useOrbitControls(); }else if(value === "Flight"){ - scope.useFPSControls(); + this.useFPSControls(); }else if(value === "Earth"){ - scope.useEarthControls(); + this.useEarthControls(); } }; - this.setShowBoundingBox = function(value){ - if(scope.showBoundingBox !== value){ - scope.showBoundingBox = value; - scope.dispatchEvent({"type": "show_boundingbox_changed", "viewer": scope}); + setShowBoundingBox(value){ + if(this.showBoundingBox !== value){ + this.showBoundingBox = value; + this.dispatcher.dispatchEvent({"type": "show_boundingbox_changed", "viewer": this}); } }; - this.getShowBoundingBox = function(){ - return scope.showBoundingBox; + getShowBoundingBox(){ + return showBoundingBox; }; - this.setMoveSpeed = function(value){ - if(scope.moveSpeed !== value){ - scope.moveSpeed = value; - scope.fpControls.setMoveSpeed(value); - scope.geoControls.setMoveSpeed(value); - scope.dispatchEvent({"type": "move_speed_changed", "viewer": scope, "speed": value}); + setMoveSpeed(value){ + if(this.moveSpeed !== value){ + this.moveSpeed = value; + this.fpControls.setMoveSpeed(value); + this.geoControls.setMoveSpeed(value); + this.dispatcher.dispatchEvent({"type": "move_speed_changed", "viewer": this, "speed": value}); } }; - this.getMoveSpeed = function(){ - return scope.fpControls.moveSpeed; + getMoveSpeed(){ + return this.fpControls.moveSpeed; }; - this.setShowSkybox = function(value){ - if(scope.showSkybox !== value){ - scope.showSkybox = value; - scope.dispatchEvent({"type": "show_skybox_changed", "viewer": scope}); + setShowSkybox(value){ + if(this.showSkybox !== value){ + this.showSkybox = value; + this.dispatcher.dispatchEvent({"type": "show_skybox_changed", "viewer": this}); } }; - this.getShowSkybox = function(){ - return scope.showSkybox; + getShowSkybox(){ + return this.showSkybox; }; - this.setHeightRange = function(min, max){ - if(scope.heightMin !== min || scope.heightMax !== max){ - scope.heightMin = min || scope.heightMin; - scope.heightMax = max || scope.heightMax; - scope.dispatchEvent({"type": "height_range_changed", "viewer": scope}); + setHeightRange(min, max){ + if(this.heightMin !== min || this.heightMax !== max){ + this.heightMin = min || this.heightMin; + this.heightMax = max || this.heightMax; + this.dispatcher.dispatchEvent({"type": "height_range_changed", "viewer": this}); } }; - this.getHeightRange = function(){ - return {min: scope.heightMin, max: scope.heightMax}; + getHeightRange(){ + return {min: this.heightMin, max: this.heightMax}; }; - this.setIntensityRange = function(min, max){ - if(scope.intensityRange[0] !== min || scope.intensityRange[1] !== max){ - scope.intensityRange[0] = min || scope.intensityRange[0]; - scope.intensityRange[1] = max || scope.intensityRange[1]; - scope.dispatchEvent({"type": "intensity_range_changed", "viewer": scope}); + getElevationRange(){ + return getHeightRange(); + }; + + setIntensityRange(min, max){ + if(this.intensityRange[0] !== min || this.intensityRange[1] !== max){ + this.intensityRange[0] = min || this.intensityRange[0]; + this.intensityRange[1] = max || this.intensityRange[1]; + this.dispatcher.dispatchEvent({"type": "intensity_range_changed", "viewer": this}); } }; - this.getIntensityRange = function(){ - return scope.intensityRange; + getIntensityRange(){ + return this.intensityRange; }; - this.setIntensityGamma = function(value){ - if(scope.intensityGamma !== value){ - scope.intensityGamma = value; - scope.dispatchEvent({"type": "intensity_gamma_changed", "viewer": scope}); + setIntensityGamma(value){ + if(this.intensityGamma !== value){ + this.intensityGamma = value; + this.dispatcher.dispatchEvent({"type": "intensity_gamma_changed", "viewer": this}); } }; - this.getIntensityGamma = function(){ - return scope.intensityGamma; + getIntensityGamma(){ + return this.intensityGamma; }; - this.setIntensityContrast = function(value){ - if(scope.intensityContrast !== value){ - scope.intensityContrast = value; - scope.dispatchEvent({"type": "intensity_contrast_changed", "viewer": scope}); + setIntensityContrast(value){ + if(this.intensityContrast !== value){ + this.intensityContrast = value; + this.dispatcher.dispatchEvent({"type": "intensity_contrast_changed", "viewer": this}); } }; - this.getIntensityContrast = function(){ - return scope.intensityContrast; + getIntensityContrast(){ + return this.intensityContrast; }; - this.setIntensityBrightness = function(value){ - if(scope.intensityBrightness !== value){ - scope.intensityBrightness = value; - scope.dispatchEvent({"type": "intensity_brightness_changed", "viewer": scope}); + setIntensityBrightness(value){ + if(this.intensityBrightness !== value){ + this.intensityBrightness = value; + this.dispatcher.dispatchEvent({"type": "intensity_brightness_changed", "viewer": this}); } }; - this.getIntensityBrightness = function(){ - return scope.intensityBrightness; + getIntensityBrightness(){ + return this.intensityBrightness; }; - this.setRGBGamma = function(value){ - if(scope.rgbGamma !== value){ - scope.rgbGamma = value; - scope.dispatchEvent({"type": "rgb_gamma_changed", "viewer": scope}); + setRGBGamma(value){ + if(this.rgbGamma !== value){ + this.rgbGamma = value; + this.dispatcher.dispatchEvent({"type": "rgb_gamma_changed", "viewer": this}); } }; - this.getRGBGamma = function(){ - return scope.rgbGamma; + getRGBGamma(){ + return this.rgbGamma; }; - this.setRGBContrast = function(value){ - if(scope.rgbContrast !== value){ - scope.rgbContrast = value; - scope.dispatchEvent({"type": "rgb_contrast_changed", "viewer": scope}); + setRGBContrast(value){ + if(this.rgbContrast !== value){ + this.rgbContrast = value; + this.dispatcher.dispatchEvent({"type": "rgb_contrast_changed", "viewer": this}); } }; - this.getRGBContrast = function(){ - return scope.rgbContrast; + getRGBContrast(){ + return this.rgbContrast; }; - this.setRGBBrightness = function(value){ - if(scope.rgbBrightness !== value){ - scope.rgbBrightness = value; - scope.dispatchEvent({"type": "rgb_brightness_changed", "viewer": scope}); + setRGBBrightness(value){ + if(this.rgbBrightness !== value){ + this.rgbBrightness = value; + this.dispatcher.dispatchEvent({"type": "rgb_brightness_changed", "viewer": this}); } }; - this.getRGBBrightness = function(){ - return scope.rgbBrightness; + getRGBBrightness(){ + return this.rgbBrightness; }; - this.setMaterialTransition = function(t){ - if(scope.materialTransition !== t){ - scope.materialTransition = t; - scope.dispatchEvent({"type": "material_transition_changed", "viewer": scope}); + setMaterialTransition(t){ + if(this.materialTransition !== t){ + this.materialTransition = t; + this.dispatcher.dispatchEvent({"type": "material_transition_changed", "viewer": this}); } }; - this.getMaterialTransition = function(){ - return scope.materialTransition; + getMaterialTransition(){ + return this.materialTransition; }; - this.setWeightRGB = function(w){ - if(scope.weightRGB !== w){ - scope.weightRGB = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightRGB(w){ + if(this.weightRGB !== w){ + this.weightRGB = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightRGB = function(){ - return scope.weightRGB; + getWeightRGB(){ + return this.weightRGB; }; - this.setWeightIntensity = function(w){ - if(scope.weightIntensity !== w){ - scope.weightIntensity = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightIntensity(w){ + if(this.weightIntensity !== w){ + this.weightIntensity = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightIntensity = function(){ - return scope.weightIntensity; + getWeightIntensity(){ + return this.weightIntensity; }; - this.setWeightElevation = function(w){ - if(scope.weightElevation !== w){ - scope.weightElevation = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightElevation(w){ + if(this.weightElevation !== w){ + this.weightElevation = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightElevation = function(){ - return scope.weightElevation; + getWeightElevation(){ + return this.weightElevation; }; - this.setWeightClassification = function(w){ - if(scope.weightClassification !== w){ - scope.weightClassification = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightClassification(w){ + if(this.weightClassification !== w){ + this.weightClassification = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightClassification = function(){ - return scope.weightClassification; + getWeightClassification(){ + return this.weightClassification; }; - this.setWeightReturnNumber = function(w){ - if(scope.weightReturnNumber !== w){ - scope.weightReturnNumber = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightReturnNumber(w){ + if(this.weightReturnNumber !== w){ + this.weightReturnNumber = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightReturnNumber = function(){ - return scope.weightReturnNumber; + getWeightReturnNumber(){ + return this.weightReturnNumber; }; - this.setWeightSourceID = function(w){ - if(scope.weightSourceID !== w){ - scope.weightSourceID = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightSourceID(w){ + if(this.weightSourceID !== w){ + this.weightSourceID = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightSourceID = function(){ - return scope.weightSourceID; + getWeightSourceID(){ + return this.weightSourceID; }; - this.setIntensityMax = function(max){ - if(scope.intensityMax !== max){ - scope.intensityMax = max; - scope.dispatchEvent({"type": "intensity_max_changed", "viewer": scope}); + setIntensityMax(max){ + if(this.intensityMax !== max){ + this.intensityMax = max; + this.dispatcher.dispatchEvent({"type": "intensity_max_changed", "viewer": this}); } }; - this.getIntensityMax = function(){ - return scope.intensityMax; + getIntensityMax(){ + return this.intensityMax; }; - this.setFreeze = function(value){ - if(scope.freeze != value){ - scope.freeze = value; - scope.dispatchEvent({"type": "freeze_changed", "viewer": scope}); + setFreeze(value){ + if(this.freeze != value){ + this.freeze = value; + this.dispatcher.dispatchEvent({"type": "freeze_changed", "viewer": this}); } }; - this.getFreeze = function(){ - return scope.freeze; + getFreeze(){ + return this.freeze; }; - this.setPointBudget = function(value){ + setPointBudget(value){ if(Potree.pointBudget != value){ Potree.pointBudget = parseInt(value); - scope.dispatchEvent({"type": "point_budget_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "point_budget_changed", "viewer": this}); } }; - this.getPointBudget = function(){ + getPointBudget(){ return Potree.pointBudget; }; - this.setClipMode = function(clipMode){ - if(scope.clipMode != clipMode){ - scope.clipMode = clipMode; - scope.dispatchEvent({"type": "clip_mode_changed", "viewer": scope}); + setClipMode(clipMode){ + if(this.clipMode != clipMode){ + this.clipMode = clipMode; + this.dispatcher.dispatchEvent({"type": "clip_mode_changed", "viewer": this}); } }; - this.getClipMode = function(){ - return scope.clipMode; + getClipMode(){ + return this.clipMode; }; - this.setDEMCollisionsEnabled = function(value){ - if(scope.useDEMCollisions !== value){ - scope.useDEMCollisions = value; - scope.dispatchEvent({"type": "use_demcollisions_changed", "viewer": scope}); + setDEMCollisionsEnabled(value){ + if(this.useDEMCollisions !== value){ + this.useDEMCollisions = value; + this.dispatcher.dispatchEvent({"type": "use_demcollisions_changed", "viewer": this}); }; }; - this.getDEMCollisionsEnabled = function(){ - return scope.useDEMCollisions; + getDEMCollisionsEnabled(){ + return this.useDEMCollisions; }; - this.setEDLEnabled = function(value){ - if(scope.useEDL != value){ - scope.useEDL = value; - scope.dispatchEvent({"type": "use_edl_changed", "viewer": scope}); + setEDLEnabled(value){ + if(this.useEDL != value){ + this.useEDL = value; + this.dispatcher.dispatchEvent({"type": "use_edl_changed", "viewer": this}); } }; - this.getEDLEnabled = function(){ - return scope.useEDL; + getEDLEnabled(){ + return this.useEDL; }; - this.setEDLRadius = function(value){ - if(scope.edlRadius !== value){ - scope.edlRadius = value; - scope.dispatchEvent({"type": "edl_radius_changed", "viewer": scope}); + setEDLRadius(value){ + if(this.edlRadius !== value){ + this.edlRadius = value; + this.dispatcher.dispatchEvent({"type": "edl_radius_changed", "viewer": this}); } }; - this.getEDLRadius = function(){ - return scope.edlRadius; + getEDLRadius(){ + return this.edlRadius; }; - this.setEDLStrength = function(value){ - if(scope.edlStrength !== value){ - scope.edlStrength = value; - scope.dispatchEvent({"type": "edl_strength_changed", "viewer": scope}); + setEDLStrength(value){ + if(this.edlStrength !== value){ + this.edlStrength = value; + this.dispatcher.dispatchEvent({"type": "edl_strength_changed", "viewer": this}); } }; - this.getEDLStrength = function(){ - return scope.edlStrength; + getEDLStrength(){ + return this.edlStrength; }; - this.setPointSize = function(value){ - if(scope.pointSize !== value){ - scope.pointSize = value; - scope.dispatchEvent({"type": "point_size_changed", "viewer": scope}); + setPointSize(value){ + if(this.pointSize !== value){ + this.pointSize = value; + this.dispatcher.dispatchEvent({"type": "point_size_changed", "viewer": this}); } }; - this.getPointSize = function(){ - return scope.pointSize; + getPointSize(){ + return this.pointSize; }; - this.setMinPointSize = function(value){ - if(scope.minPointSize !== value){ - scope.minPointSize = value; - scope.dispatchEvent({"type": "min_point_size_changed", "viewer": scope}); + setMinPointSize(value){ + if(this.minPointSize !== value){ + this.minPointSize = value; + this.dispatcher.dispatchEvent({"type": "min_point_size_changed", "viewer": this}); } } - this.getMinPointSize = function(){ - return scope.minPointSize; + getMinPointSize(){ + return this.minPointSize; } - this.setMaxPointSize = function(value){ - if(scope.maxPointSize !== value){ - scope.maxPointSize = value; - scope.dispatchEvent({"type": "max_point_size_changed", "viewer": scope}); + setMaxPointSize(value){ + if(this.maxPointSize !== value){ + this.maxPointSize = value; + this.dispatcher.dispatchEvent({"type": "max_point_size_changed", "viewer": this}); } } - this.getMaxPointSize = function(){ - return scope.maxPointSize; + getMaxPointSize(){ + return this.maxPointSize; } - this.setFOV = function(value){ - if(scope.fov !== value){ - scope.fov = value; - scope.dispatchEvent({"type": "fov_changed", "viewer": scope}); + setFOV(value){ + if(this.fov !== value){ + this.fov = value; + this.dispatcher.dispatchEvent({"type": "fov_changed", "viewer": this}); } }; - this.getFOV = function(){ - return scope.fov; + getFOV(){ + return this.fov; }; - this.setOpacity = function(value){ - if(scope.opacity !== value){ - scope.opacity = value; - scope.dispatchEvent({"type": "opacity_changed", "viewer": scope}); + setOpacity(value){ + if(this.opacity !== value){ + this.opacity = value; + this.dispatcher.dispatchEvent({"type": "opacity_changed", "viewer": this}); } }; - this.getOpacity = function(){ - return scope.opacity; + getOpacity(){ + return this.opacity; }; - this.setPointSizing = function(value){ - if(scope.sizeType !== value){ - scope.sizeType = value; + setPointSizing(value){ + if(this.sizeType !== value){ + this.sizeType = value; if(value === "Fixed"){ - scope.pointSizeType = Potree.PointSizeType.FIXED; + this.pointSizeType = Potree.PointSizeType.FIXED; }else if(value === "Attenuated"){ - scope.pointSizeType = Potree.PointSizeType.ATTENUATED; + this.pointSizeType = Potree.PointSizeType.ATTENUATED; }else if(value === "Adaptive"){ - scope.pointSizeType = Potree.PointSizeType.ADAPTIVE; + this.pointSizeType = Potree.PointSizeType.ADAPTIVE; } - scope.dispatchEvent({"type": "point_sizing_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "point_sizing_changed", "viewer": this}); } }; - this.getPointSizing = function(){ - return scope.sizeType; + getPointSizing(){ + return this.sizeType; }; - this.setQuality = function(value){ - var oldQuality = scope.quality; + setQuality(value){ + var oldQuality = this.quality; if(value == "Interpolation" && !Potree.Features.SHADER_INTERPOLATION.isSupported()){ - scope.quality = "Squares"; + this.quality = "Squares"; }else if(value == "Splats" && !Potree.Features.SHADER_SPLATS.isSupported()){ - scope.quality = "Squares"; + this.quality = "Squares"; }else{ - scope.quality = value; + this.quality = value; } - if(oldQuality !== scope.quality){ - scope.dispatchEvent({"type": "quality_changed", "viewer": scope}); + if(oldQuality !== this.quality){ + this.dispatcher.dispatchEvent({"type": "quality_changed", "viewer": this}); } }; - this.getQuality = function(){ - return scope.quality; + getQuality(){ + return this.quality; }; - this.disableAnnotations = function(){ - for(var i = 0; i < scope.annotations.length; i++){ - var annotation = scope.annotations[i]; + disableAnnotations(){ + for(var i = 0; i < this.annotations.length; i++){ + var annotation = this.annotations[i]; annotation.domElement.style.pointerEvents = "none"; }; }; - this.enableAnnotations = function(){ - for(var i = 0; i < scope.annotations.length; i++){ - var annotation = scope.annotations[i]; + enableAnnotations(){ + for(var i = 0; i < this.annotations.length; i++){ + var annotation = this.annotations[i]; annotation.domElement.style.pointerEvents = "auto"; }; }; - this.setClassificationVisibility = function(key, value){ + setClassificationVisibility(key, value){ var changed = false; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; var newClass = pointcloud.material.classification; var oldValue = newClass[key].w; newClass[key].w = value ? 1 : 0; @@ -12174,35 +12192,35 @@ Potree.Viewer = function(domElement, args){ } if(changed){ - scope.dispatchEvent({"type": "classification_visibility_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "classification_visibility_changed", "viewer": this}); } }; - this.setMaterial = function(value){ - if(scope.pointColorType !== scope.toMaterialID(value)){ - scope.pointColorType = scope.toMaterialID(value); + setMaterial(value){ + if(this.pointColorType !== this.toMaterialID(value)){ + this.pointColorType = this.toMaterialID(value); - scope.dispatchEvent({"type": "material_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "material_changed", "viewer": this}); } }; - this.setMaterialID = function(value){ - if(scope.pointColorType !== value){ - scope.pointColorType = value; + setMaterialID(value){ + if(this.pointColorType !== value){ + this.pointColorType = value; - scope.dispatchEvent({"type": "material_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "material_changed", "viewer": this}); } } - this.getMaterial = function(){ - return scope.pointColorType; + getMaterial(){ + return this.pointColorType; }; - this.getMaterialName = function(){ - return scope.toMaterialName(scope.pointColorType); + getMaterialName(){ + return this.toMaterialName(this.pointColorType); }; - this.toMaterialID = function(materialName){ + toMaterialID(materialName){ if(materialName === "RGB"){ return Potree.PointColorType.RGB; }else if(materialName === "Color"){ @@ -12234,7 +12252,7 @@ Potree.Viewer = function(domElement, args){ } }; - this.toMaterialName = function(materialID){ + toMaterialName(materialID){ if(materialID === Potree.PointColorType.RGB){ return "RGB"; }else if(materialID === Potree.PointColorType.COLOR){ @@ -12266,8 +12284,8 @@ Potree.Viewer = function(domElement, args){ } }; - this.zoomTo = function(node, factor){ - scope.camera.zoomTo(node, factor); + zoomTo(node, factor){ + this.camera.zoomTo(node, factor); var bs; if(node.boundingSphere){ @@ -12280,31 +12298,30 @@ Potree.Viewer = function(domElement, args){ bs = bs.clone().applyMatrix4(node.matrixWorld); - scope.orbitControls.target.copy(bs.center); + this.orbitControls.target.copy(bs.center); - scope.dispatchEvent({"type": "zoom_to", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "zoom_to", "viewer": this}); }; - this.showAbout = function(){ + showAbout(){ $(function() { $( "#about-panel" ).dialog(); }); }; - this.getBoundingBox = function(pointclouds){ - pointclouds = pointclouds || scope.pointclouds; + getBoundingBox(pointclouds){ + pointclouds = pointclouds || this.scene.pointclouds; var box = new THREE.Box3(); - scope.scenePointCloud.updateMatrixWorld(true); - scope.referenceFrame.updateMatrixWorld(true); + this.scene.scenePointCloud.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; pointcloud.updateMatrixWorld(true); - //var boxWorld = pointcloud.boundingBox.clone().applyMatrix4(pointcloud.matrixWorld); var boxWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld) box.union(boxWorld); } @@ -12312,16 +12329,16 @@ Potree.Viewer = function(domElement, args){ return box; }; - this.getBoundingBoxGeo = function(pointclouds){ - pointclouds = pointclouds || scope.pointclouds; + getBoundingBoxGeo(pointclouds){ + pointclouds = pointclouds || this.scene.pointclouds; var box = new THREE.Box3(); - scope.scenePointCloud.updateMatrixWorld(true); - scope.referenceFrame.updateMatrixWorld(true); + this.scene.scenePointCloud.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; pointcloud.updateMatrixWorld(true); @@ -12332,94 +12349,92 @@ Potree.Viewer = function(domElement, args){ return box; }; - this.fitToScreen = function(){ - var box = this.getBoundingBox(scope.pointclouds); + fitToScreen(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - //scope.camera.zoomTo(node, 1); - scope.zoomTo(node, 1); + //this.camera.zoomTo(node, 1); + this.zoomTo(node, 1); }; - this.setTopView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setTopView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(0, 1, 0); - scope.camera.rotation.set(-Math.PI / 2, 0, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(0, 1, 0); + this.camera.rotation.set(-Math.PI / 2, 0, 0); + this.camera.zoomTo(node, 1); }; - this.setFrontView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setFrontView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(0, 0, 1); - scope.camera.rotation.set(0, 0, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(0, 0, 1); + this.camera.rotation.set(0, 0, 0); + this.camera.zoomTo(node, 1); }; - this.setLeftView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setLeftView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(-1, 0, 0); - scope.camera.rotation.set(0, -Math.PI / 2, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(-1, 0, 0); + this.camera.rotation.set(0, -Math.PI / 2, 0); + this.camera.zoomTo(node, 1); }; - this.setRightView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setRightView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(1, 0, 0); - scope.camera.rotation.set(0, Math.PI / 2, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(1, 0, 0); + this.camera.rotation.set(0, Math.PI / 2, 0); + this.camera.zoomTo(node, 1); }; - this.flipYZ = function(){ - scope.isFlipYZ = !scope.isFlipYZ; + flipYZ(){ + this.isFlipYZ = !this.isFlipYZ; - scope.referenceFrame.matrix.copy(new THREE.Matrix4()); - if(scope.isFlipYZ){ - scope.referenceFrame.applyMatrix(new THREE.Matrix4().set( + if(this.isFlipYZ){ + this.scene.referenceFrame.matrix.copy(new THREE.Matrix4().set( 1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1 )); - }else{ - scope.referenceFrame.applyMatrix(new THREE.Matrix4().set( + this.scene.referenceFrame.matrix.copy(new THREE.Matrix4().set( 1,0,0,0, 0,1,0,0, 0,0,1,0, @@ -12427,164 +12442,184 @@ Potree.Viewer = function(domElement, args){ )); } - scope.referenceFrame.updateMatrixWorld(true); - var box = scope.getBoundingBox(); - scope.referenceFrame.position.copy(box.getCenter()).multiplyScalar(-1); - scope.referenceFrame.position.y = -box.min.y; - scope.referenceFrame.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); + var box = this.getBoundingBox(); + //this.scene.referenceFrame.position.copy(box.getCenter()).multiplyScalar(-1); + //this.scene.referenceFrame.position.y = -box.min.y; + this.scene.referenceFrame.updateMatrixWorld(true); - scope.updateHeightRange(); + this.updateHeightRange(); - //scope.referenceFrame.updateMatrixWorld(true); - //scope.pointclouds[0].updateMatrixWorld(); - //var sg = scope.pointclouds[0].boundingSphere.clone().applyMatrix4(scope.pointclouds[0].matrixWorld); - //scope.referenceFrame.position.copy(sg.center).multiplyScalar(-1); - //scope.referenceFrame.updateMatrixWorld(true); - //scope.referenceFrame.position.y -= scope.pointclouds[0].getWorldPosition().y; - //scope.referenceFrame.updateMatrixWorld(true); + //this.isFlipYZ = !this.isFlipYZ; + // + //this.scene.referenceFrame.matrix.copy(new THREE.Matrix4()); + //if(this.isFlipYZ){ + // this.scene.referenceFrame.applyMatrix(new THREE.Matrix4().set( + // 1,0,0,0, + // 0,0,1,0, + // 0,-1,0,0, + // 0,0,0,1 + // )); + // + //}else{ + // this.scene.referenceFrame.applyMatrix(new THREE.Matrix4().set( + // 1,0,0,0, + // 0,1,0,0, + // 0,0,1,0, + // 0,0,0,1 + // )); + //} + // + //this.scene.referenceFrame.updateMatrixWorld(true); + //var box = this.getBoundingBox(); + //this.scene.referenceFrame.position.copy(box.getCenter()).multiplyScalar(-1); + //this.scene.referenceFrame.position.y = -box.min.y; + //this.scene.referenceFrame.updateMatrixWorld(true); + // + //this.updateHeightRange(); } - this.updateHeightRange = function(){ - var bbWorld = scope.getBoundingBox(); - scope.setHeightRange(bbWorld.min.y, bbWorld.max.y); + updateHeightRange(){ + var bbWorld = this.getBoundingBox(); + this.setHeightRange(bbWorld.min.y, bbWorld.max.y); }; - this.useEarthControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useEarthControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.earthControls; - scope.controls.enabled = true; + this.controls = this.earthControls; + this.controls.enabled = true; } - this.useGeoControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useGeoControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.geoControls; - scope.controls.enabled = true; + this.controls = this.geoControls; + this.controls.enabled = true; - //scope.controls.moveSpeed = scope.pointclouds[0].boundingSphere.radius / 6; + //this.controls.moveSpeed = this.scene.pointclouds[0].boundingSphere.radius / 6; } - this.useFPSControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useFPSControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.fpControls; - scope.controls.enabled = true; + this.controls = this.fpControls; + this.controls.enabled = true; - //scope.controls.moveSpeed = scope.pointclouds[0].boundingSphere.radius / 6; + //this.controls.moveSpeed = this.scene.pointclouds[0].boundingSphere.radius / 6; } - this.useOrbitControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useOrbitControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.orbitControls; - scope.controls.enabled = true; + this.controls = this.orbitControls; + this.controls.enabled = true; - if(scope.pointclouds.length > 0){ - scope.controls.target.copy(scope.pointclouds[0].boundingSphere.center.clone().applyMatrix4(scope.pointclouds[0].matrixWorld)); + if(this.scene.pointclouds.length > 0){ + this.controls.target.copy(this.scene.pointclouds[0].boundingSphere.center.clone().applyMatrix4(this.scene.pointclouds[0].matrixWorld)); } }; - this.addAnnotation = function(position, args){ + addAnnotation(position, args){ var cameraPosition = args.cameraPosition; var cameraTarget = args.cameraTarget || position; var description = args.description || null; var title = args.title || null; - var callback = args.callback || null; + var actions = args.actions || null; - var annotation = new Potree.Annotation(scope, { + var annotation = new Potree.Annotation(this, { "position": position, "cameraPosition": cameraPosition, "cameraTarget": cameraTarget, "title": title, "description": description, - "callback": callback + "actions": actions }); - scope.annotations.push(annotation); - scope.renderArea.appendChild(annotation.domElement); + this.annotations.push(annotation); + this.renderArea.appendChild(annotation.domElement); - scope.dispatchEvent({"type": "annotation_added", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "annotation_added", "viewer": this}); return annotation; } - this.getAnnotations = function(){ - return scope.annotations; + getAnnotations(){ + return this.annotations; }; - this.loadSettingsFromURL = function(){ + loadSettingsFromURL(){ if(Potree.utils.getParameterByName("pointSize")){ - scope.setPointSize(parseFloat(Potree.utils.getParameterByName("pointSize"))); + this.setPointSize(parseFloat(Potree.utils.getParameterByName("pointSize"))); } if(Potree.utils.getParameterByName("FOV")){ - scope.setFOV(parseFloat(Potree.utils.getParameterByName("FOV"))); + this.setFOV(parseFloat(Potree.utils.getParameterByName("FOV"))); } if(Potree.utils.getParameterByName("opacity")){ - scope.setOpacity(parseFloat(Potree.utils.getParameterByName("opacity"))); + this.setOpacity(parseFloat(Potree.utils.getParameterByName("opacity"))); } if(Potree.utils.getParameterByName("edlEnabled")){ var enabled = Potree.utils.getParameterByName("edlEnabled") === "true"; - scope.setEDLEnabled(enabled); + this.setEDLEnabled(enabled); } if(Potree.utils.getParameterByName("edlRadius")){ - scope.setEDLRadius(parseFloat(Potree.utils.getParameterByName("edlRadius"))); + this.setEDLRadius(parseFloat(Potree.utils.getParameterByName("edlRadius"))); } if(Potree.utils.getParameterByName("edlStrength")){ - scope.setEDLStrength(parseFloat(Potree.utils.getParameterByName("edlStrength"))); + this.setEDLStrength(parseFloat(Potree.utils.getParameterByName("edlStrength"))); } if(Potree.utils.getParameterByName("clipMode")){ var clipMode = Potree.utils.getParameterByName("clipMode"); if(clipMode === "HIGHLIGHT_INSIDE"){ - scope.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); + this.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); }else if(clipMode === "CLIP_OUTSIDE"){ - scope.setClipMode(Potree.ClipMode.CLIP_OUTSIDE); + this.setClipMode(Potree.ClipMode.CLIP_OUTSIDE); }else if(clipMode === "DISABLED"){ - scope.setClipMode(Potree.ClipMode.DISABLED); + this.setClipMode(Potree.ClipMode.DISABLED); } } if(Potree.utils.getParameterByName("pointBudget")){ - scope.setPointBudget(parseFloat(Potree.utils.getParameterByName("pointBudget"))); + this.setPointBudget(parseFloat(Potree.utils.getParameterByName("pointBudget"))); } if(Potree.utils.getParameterByName("showBoundingBox")){ var enabled = Potree.utils.getParameterByName("showBoundingBox") === "true"; if(enabled){ - scope.setShowBoundingBox(true); + this.setShowBoundingBox(true); }else{ - scope.setShowBoundingBox(false); + this.setShowBoundingBox(false); } } if(Potree.utils.getParameterByName("material")){ var material = Potree.utils.getParameterByName("material"); - scope.setMaterial(material); + this.setMaterial(material); } if(Potree.utils.getParameterByName("pointSizing")){ var sizing = Potree.utils.getParameterByName("pointSizing"); - scope.setPointSizing(sizing); + this.setPointSizing(sizing); } if(Potree.utils.getParameterByName("quality")){ var quality = Potree.utils.getParameterByName("quality"); - scope.setQuality(quality); + this.setQuality(quality); } }; @@ -12602,7 +12637,7 @@ Potree.Viewer = function(domElement, args){ // Viewer Internals //------------------------------------------------------------------------------------ - this.toggleSidebar = function(){ + toggleSidebar(){ var renderArea = $('#potree_render_area'); var sidebar = $('#potree_sidebar_container'); @@ -12615,13 +12650,13 @@ Potree.Viewer = function(domElement, args){ } }; - this.toggleMap = function(){ + toggleMap(){ var map = $('#potree_map'); map.toggle(100); }; - this.loadGUI = function(){ + loadGUI(){ var sidebarContainer = $('#potree_sidebar_container'); sidebarContainer.load(new URL(Potree.scriptPath + "/sidebar.html").href); sidebarContainer.css("width", "300px"); @@ -12629,26 +12664,23 @@ Potree.Viewer = function(domElement, args){ var imgMenuToggle = document.createElement("img"); imgMenuToggle.src = new URL(Potree.resourcePath + "/icons/menu_button.svg").href; - imgMenuToggle.onclick = scope.toggleSidebar; + imgMenuToggle.onclick = this.toggleSidebar; imgMenuToggle.classList.add("potree_menu_toggle"); - //viewer.renderArea.appendChild(imgMenuToggle); var imgMapToggle = document.createElement("img"); imgMapToggle.src = new URL(Potree.resourcePath + "/icons/map_icon.png").href; imgMapToggle.style.display = "none"; - imgMapToggle.onclick = scope.toggleMap; + imgMapToggle.onclick = this.toggleMap; imgMapToggle.id = "potree_map_toggle"; - //viewer.renderArea.appendChild(imgMapToggle); viewer.renderArea.insertBefore(imgMapToggle, viewer.renderArea.children[0]); viewer.renderArea.insertBefore(imgMenuToggle, viewer.renderArea.children[0]); - //var elProfile = $('
'); var elProfile = $('
').load(new URL(Potree.scriptPath + "/profile.html").href, function(){ $('#potree_render_area').append(elProfile.children()); - scope._2dprofile = new Potree.Viewer.Profile(scope, document.getElementById("profile_draw_container")); - }); + this._2dprofile = new Potree.Viewer.Profile(this, document.getElementById("profile_draw_container")); + }.bind(this)); i18n.init({ lng: 'en', @@ -12662,24 +12694,24 @@ Potree.Viewer = function(domElement, args){ }); } - this.setLanguage = function(lang) { + setLanguage(lang){ i18n.setLng(lang); $("body").i18n(); console.log("ici"); } - this.createControls = function(){ + createControls(){ var demCollisionHandler = function(event){ - if(!scope.useDEMCollisions){ + if(!this.useDEMCollisions){ return } var demHeight = null; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; pointcloud.generateDEM = true; var height = pointcloud.getDEMHeight(event.newPosition); @@ -12700,60 +12732,60 @@ Potree.Viewer = function(domElement, args){ }; { // create FIRST PERSON CONTROLS - scope.fpControls = new THREE.FirstPersonControls(scope.camera, scope.renderer.domElement); - scope.fpControls.enabled = false; - scope.fpControls.addEventListener("start", scope.disableAnnotations); - scope.fpControls.addEventListener("end", scope.enableAnnotations); - scope.fpControls.addEventListener("proposeTransform", demCollisionHandler); - scope.fpControls.addEventListener("move_speed_changed", function(event){ - scope.setMoveSpeed(scope.fpControls.moveSpeed); - }); + this.fpControls = new THREE.FirstPersonControls(this.camera, this.renderer.domElement); + this.fpControls.enabled = false; + this.fpControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.fpControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.fpControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); + this.fpControls.addEventListener("move_speed_changed", function(event){ + this.setMoveSpeed(this.fpControls.moveSpeed); + }.bind(this)); } { // create GEO CONTROLS - scope.geoControls = new Potree.GeoControls(scope.camera, scope.renderer.domElement); - scope.geoControls.enabled = false; - scope.geoControls.addEventListener("start", scope.disableAnnotations); - scope.geoControls.addEventListener("end", scope.enableAnnotations); - scope.geoControls.addEventListener("proposeTransform", demCollisionHandler); - scope.geoControls.addEventListener("move_speed_changed", function(event){ - scope.setMoveSpeed(scope.geoControls.moveSpeed); - }); + this.geoControls = new Potree.GeoControls(this.camera, this.renderer.domElement); + this.geoControls.enabled = false; + this.geoControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.geoControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.geoControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); + this.geoControls.addEventListener("move_speed_changed", function(event){ + this.setMoveSpeed(this.geoControls.moveSpeed); + }.bind(this)); } { // create ORBIT CONTROLS - scope.orbitControls = new Potree.OrbitControls(scope.camera, scope.renderer.domElement); - scope.orbitControls.enabled = false; - scope.orbitControls.addEventListener("start", scope.disableAnnotations); - scope.orbitControls.addEventListener("end", scope.enableAnnotations); - scope.orbitControls.addEventListener("proposeTransform", demCollisionHandler); - scope.renderArea.addEventListener("dblclick", function(event){ - if(scope.pointclouds.length === 0){ + this.orbitControls = new Potree.OrbitControls(this.camera, this.renderer.domElement); + this.orbitControls.enabled = false; + this.orbitControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.orbitControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.orbitControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); + this.renderArea.addEventListener("dblclick", function(event){ + if(this.scene.pointclouds.length === 0){ return; } event.preventDefault(); - var rect = scope.renderArea.getBoundingClientRect(); + var rect = this.renderArea.getBoundingClientRect(); var mouse = { - x: ( (event.clientX - rect.left) / scope.renderArea.clientWidth ) * 2 - 1, - y: - ( (event.clientY - rect.top) / scope.renderArea.clientHeight ) * 2 + 1 + x: ( (event.clientX - rect.left) / this.renderArea.clientWidth ) * 2 - 1, + y: - ( (event.clientY - rect.top) / this.renderArea.clientHeight ) * 2 + 1 }; var pointcloud = null; var distance = Number.POSITIVE_INFINITY; var I = null; - for(var i = 0; i < scope.pointclouds.length; i++){ - intersection = getMousePointCloudIntersection(mouse, scope.camera, scope.renderer, [scope.pointclouds[i]]); + for(var i = 0; i < this.scene.pointclouds.length; i++){ + let intersection = getMousePointCloudIntersection(mouse, this.camera, this.renderer, [this.scene.pointclouds[i]]); if(!intersection){ continue; } - var tDist = scope.camera.position.distanceTo(intersection); + var tDist = this.camera.position.distanceTo(intersection); if(tDist < distance){ - pointcloud = scope.pointclouds[i]; + pointcloud = this.scene.pointclouds[i]; distance = tDist; I = intersection; } @@ -12762,25 +12794,25 @@ Potree.Viewer = function(domElement, args){ if(I != null){ var targetRadius = 0; - if(!scope.jumpDistance){ - var camTargetDistance = scope.camera.position.distanceTo(scope.orbitControls.target); + if(!this.jumpDistance){ + var camTargetDistance = this.camera.position.distanceTo(this.orbitControls.target); var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 ); - vector.unproject(scope.camera); + vector.unproject(this.camera); - var direction = vector.sub(scope.camera.position).normalize(); - var ray = new THREE.Ray(scope.camera.position, direction); + var direction = vector.sub(this.camera.position).normalize(); + var ray = new THREE.Ray(this.camera.position, direction); var nodes = pointcloud.nodesOnRay(pointcloud.visibleNodes, ray); var lastNode = nodes[nodes.length - 1]; var radius = lastNode.getBoundingSphere().radius; var targetRadius = Math.min(camTargetDistance, radius); - var targetRadius = Math.max(scope.minimumJumpDistance, targetRadius); + var targetRadius = Math.max(this.minimumJumpDistance, targetRadius); }else{ - targetRadius = scope.jumpDistance; + targetRadius = this.jumpDistance; } - var d = scope.camera.getWorldDirection().multiplyScalar(-1); + var d = this.camera.getWorldDirection().multiplyScalar(-1); var cameraTargetPosition = new THREE.Vector3().addVectors(I, d.multiplyScalar(targetRadius)); var controlsTargetPosition = I; @@ -12788,125 +12820,76 @@ Potree.Viewer = function(domElement, args){ var easing = TWEEN.Easing.Quartic.Out; - scope.controls.enabled = false; + this.controls.enabled = false; // animate position - var tween = new TWEEN.Tween(scope.camera.position).to(cameraTargetPosition, animationDuration); + var tween = new TWEEN.Tween(this.camera.position).to(cameraTargetPosition, animationDuration); tween.easing(easing); tween.start(); // animate target - var tween = new TWEEN.Tween(scope.orbitControls.target).to(I, animationDuration); + var tween = new TWEEN.Tween(this.orbitControls.target).to(I, animationDuration); tween.easing(easing); tween.onComplete(function(){ - scope.controls.enabled = true; - scope.fpControls.moveSpeed = radius / 2; - scope.geoControls.moveSpeed = radius / 2; - }); + this.controls.enabled = true; + this.fpControls.moveSpeed = radius / 2; + this.geoControls.moveSpeed = radius / 2; + }.bind(this)); tween.start(); } - }); + }.bind(this)); } { // create EARTH CONTROLS - scope.earthControls = new THREE.EarthControls(scope.camera, scope.renderer, scope.scenePointCloud); - scope.earthControls.enabled = false; - scope.earthControls.addEventListener("start", scope.disableAnnotations); - scope.earthControls.addEventListener("end", scope.enableAnnotations); - scope.earthControls.addEventListener("proposeTransform", demCollisionHandler); + this.earthControls = new THREE.EarthControls(this.camera, this.renderer, this.scene.scenePointCloud); + this.earthControls.enabled = false; + this.earthControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.earthControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.earthControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); } }; - this.initThree = function(){ - var width = scope.renderArea.clientWidth; - var height = scope.renderArea.clientHeight; - var aspect = width / height; - var near = 0.1; - var far = 1000*1000; + initThree(){ + let width = this.renderArea.clientWidth; + let height = this.renderArea.clientHeight; + let aspect = width / height; + let near = 0.1; + let far = 1000*1000; + + this.camera = new THREE.PerspectiveCamera(this.fov, aspect, near, far); + this.cameraBG = new THREE.Camera(); + this.camera.rotation.order = 'ZYX'; + + - scope.scene = new THREE.Scene(); - scope.scenePointCloud = new THREE.Scene(); - scope.sceneBG = new THREE.Scene(); + this.renderer = new THREE.WebGLRenderer(); + this.renderer.setSize(width, height); + this.renderer.autoClear = false; + this.renderArea.appendChild(this.renderer.domElement); + this.renderer.domElement.tabIndex = "2222"; + this.renderer.domElement.addEventListener("mousedown", + function(){this.renderer.domElement.focus();}.bind(this)); - scope.camera = new THREE.PerspectiveCamera(scope.fov, aspect, near, far); - //camera = new THREE.OrthographicCamera(-50, 50, 50, -50, 1, 100000); - scope.cameraBG = new THREE.Camera(); - scope.camera.rotation.order = 'ZYX'; - - scope.referenceFrame = new THREE.Object3D(); - scope.scenePointCloud.add(scope.referenceFrame); - - scope.renderer = new THREE.WebGLRenderer(); - scope.renderer.setSize(width, height); - scope.renderer.autoClear = false; - scope.renderArea.appendChild(scope.renderer.domElement); - scope.renderer.domElement.tabIndex = "2222"; - scope.renderer.domElement.addEventListener("mousedown", function(){scope.renderer.domElement.focus();}); - - skybox = Potree.utils.loadSkybox(new URL(Potree.resourcePath + "/textures/skybox/").href); + this.skybox = Potree.utils.loadSkybox(new URL(Potree.resourcePath + "/textures/skybox/").href); // camera and controls - scope.camera.position.set(-304, 372, 318); - scope.camera.rotation.y = -Math.PI / 4; - scope.camera.rotation.x = -Math.PI / 6; + this.camera.position.set(-304, 372, 318); + this.camera.rotation.y = -Math.PI / 4; + this.camera.rotation.x = -Math.PI / 6; this.createControls(); - //scope.useEarthControls(); - // enable frag_depth extension for the interpolation shader, if available - scope.renderer.context.getExtension("EXT_frag_depth"); + this.renderer.context.getExtension("EXT_frag_depth"); - //this.addPointCloud(pointcloudPath); - - var grid = Potree.utils.createGrid(5, 5, 2); - scope.scene.add(grid); - - scope.measuringTool = new Potree.MeasuringTool(scope.scenePointCloud, scope.camera, scope.renderer, scope.toGeo); - scope.profileTool = new Potree.ProfileTool(scope.scenePointCloud, scope.camera, scope.renderer); - scope.transformationTool = new Potree.TransformationTool(scope.scenePointCloud, scope.camera, scope.renderer); - scope.volumeTool = new Potree.VolumeTool(scope.scenePointCloud, scope.camera, scope.renderer, scope.transformationTool); - - scope.profileTool.addEventListener("profile_added", function(profileEvent){ - - //var poSelect = document.getElementById("profile_selection"); - //var po = document.createElement("option"); - //po.innerHTML = "profile " + scope.profileTool.profiles.length; - //poSelect.appendChild(po); - - - var profileButton = document.createElement("button"); - profileButton.type = "button"; - profileButton.classList.add("btn"); - profileButton.classList.add("btn-primary"); - profileButton.id = "btn_rofile_" + scope.profileTool.profiles.length; - //profileButton.style.width = "100%"; - profileButton.value = "profile " + scope.profileTool.profiles.length; - profileButton.innerHTML = "profile " + scope.profileTool.profiles.length; - - //type="button" class="btn btn-primary" - - profileButton.onclick = function(clickEvent){ - scope.profileTool.draw( - profileEvent.profile, - $("#profile_draw_container")[0], - scope.toGeo); - profileEvent.profile.addEventListener("marker_moved", function(){ - scope.profileTool.draw( - profileEvent.profile, - $("#profile_draw_container")[0], - scope.toGeo); - }); - profileEvent.profile.addEventListener("width_changed", function(){ - scope.profileTool.draw( - profileEvent.profile, - $("#profile_draw_container")[0], - scope.toGeo); - }); - }; - }); + let grid = Potree.utils.createGrid(5, 5, 2); + this.scene.scene.add(grid); + this.measuringTool = new Potree.MeasuringTool(this.scene.scenePointCloud, this.camera, this.renderer); + this.profileTool = new Potree.ProfileTool(this.scene.scenePointCloud, this.camera, this.renderer); + this.transformationTool = new Potree.TransformationTool(this.scene.scenePointCloud, this.camera, this.renderer); + this.volumeTool = new Potree.VolumeTool(this.scene.scenePointCloud, this.camera, this.renderer, this.transformationTool); // background // var texture = THREE.ImageUtils.loadTexture( Potree.resourcePath + '/textures/background.gif' ); @@ -12921,56 +12904,52 @@ Potree.Viewer = function(domElement, args){ map: texture }) ); - //bg.position.z = -1; bg.material.depthTest = false; bg.material.depthWrite = false; - scope.sceneBG.add(bg); + this.scene.sceneBG.add(bg); + + let onKeyDown = function(event){ + //console.log(event.keyCode); + + if(event.keyCode === 69){ + // e pressed + this.transformationTool.translate(); + }else if(event.keyCode === 82){ + // r pressed + this.transformationTool.scale(); + }else if(event.keyCode === 84){ + // t pressed + this.transformationTool.rotate(); + } + }.bind(this); window.addEventListener( 'keydown', onKeyDown, false ); - scope.directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 ); - scope.directionalLight.position.set( 10, 10, 10 ); - scope.directionalLight.lookAt( new THREE.Vector3(0, 0, 0)); - scope.scenePointCloud.add( scope.directionalLight ); + this.directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 ); + this.directionalLight.position.set( 10, 10, 10 ); + this.directionalLight.lookAt( new THREE.Vector3(0, 0, 0)); + this.scene.scenePointCloud.add( this.directionalLight ); var light = new THREE.AmbientLight( 0x555555 ); // soft white light - scope.scenePointCloud.add( light ); + this.scene.scenePointCloud.add( light ); } - function onKeyDown(event){ - //console.log(event.keyCode); - - if(event.keyCode === 69){ - // e pressed - - scope.transformationTool.translate(); - }else if(event.keyCode === 82){ - // r pressed - - scope.transformationTool.scale(); - }else if(event.keyCode === 84){ - // r pressed - - scope.transformationTool.rotate(); - } - }; - - this.update = function(delta, timestamp){ + update(delta, timestamp){ Potree.pointLoadLimit = Potree.pointBudget * 2; - scope.directionalLight.position.copy(scope.camera.position); - scope.directionalLight.lookAt(new THREE.Vector3().addVectors(scope.camera.position, scope.camera.getWorldDirection())); + this.directionalLight.position.copy(this.camera.position); + this.directionalLight.lookAt(new THREE.Vector3().addVectors(this.camera.position, this.camera.getWorldDirection())); var visibleNodes = 0; var visiblePoints = 0; var progress = 0; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; var bbWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld); - if(!scope.intensityMax){ + if(!this.intensityMax){ var root = pointcloud.pcoGeometry.root; if(root != null && root.loaded){ var attributes = pointcloud.pcoGeometry.root.geometry.attributes; @@ -12987,46 +12966,46 @@ Potree.Viewer = function(domElement, args){ var cap = ordered[capIndex]; if(cap <= 1){ - scope.intensityMax = 1; + this.intensityMax = 1; }else if(cap <= 256){ - scope.intensityMax = 255; + this.intensityMax = 255; }else{ - scope.intensityMax = cap; + this.intensityMax = cap; } } } } - //if(scope.heightMin === null){ - // scope.setHeightRange(bbWorld.min.y, bbWorld.max.y); + //if(this.heightMin === null){ + // this.setHeightRange(bbWorld.min.y, bbWorld.max.y); //} - pointcloud.material.clipMode = scope.clipMode; - pointcloud.material.heightMin = scope.heightMin; - pointcloud.material.heightMax = scope.heightMax; + pointcloud.material.clipMode = this.clipMode; + pointcloud.material.heightMin = this.heightMin; + pointcloud.material.heightMax = this.heightMax; //pointcloud.material.intensityMin = 0; - //pointcloud.material.intensityMax = scope.intensityMax; - pointcloud.material.uniforms.intensityRange.value = scope.getIntensityRange(); - pointcloud.material.uniforms.intensityGamma.value = scope.getIntensityGamma(); - pointcloud.material.uniforms.intensityContrast.value = scope.getIntensityContrast(); - pointcloud.material.uniforms.intensityBrightness.value = scope.getIntensityBrightness(); - pointcloud.material.uniforms.rgbGamma.value = scope.getRGBGamma(); - pointcloud.material.uniforms.rgbContrast.value = scope.getRGBContrast(); - pointcloud.material.uniforms.rgbBrightness.value = scope.getRGBBrightness(); - pointcloud.showBoundingBox = scope.showBoundingBox; - pointcloud.generateDEM = scope.useDEMCollisions; - pointcloud.minimumNodePixelSize = scope.minNodeSize; - pointcloud.material.uniforms.transition.value = scope.materialTransition; + //pointcloud.material.intensityMax = this.intensityMax; + pointcloud.material.uniforms.intensityRange.value = this.getIntensityRange(); + pointcloud.material.uniforms.intensityGamma.value = this.getIntensityGamma(); + pointcloud.material.uniforms.intensityContrast.value = this.getIntensityContrast(); + pointcloud.material.uniforms.intensityBrightness.value = this.getIntensityBrightness(); + pointcloud.material.uniforms.rgbGamma.value = this.getRGBGamma(); + pointcloud.material.uniforms.rgbContrast.value = this.getRGBContrast(); + pointcloud.material.uniforms.rgbBrightness.value = this.getRGBBrightness(); + pointcloud.showBoundingBox = this.showBoundingBox; + pointcloud.generateDEM = this.useDEMCollisions; + pointcloud.minimumNodePixelSize = this.minNodeSize; + pointcloud.material.uniforms.transition.value = this.materialTransition; - pointcloud.material.uniforms.wRGB.value = scope.getWeightRGB(); - pointcloud.material.uniforms.wIntensity.value = scope.getWeightIntensity(); - pointcloud.material.uniforms.wElevation.value = scope.getWeightElevation(); - pointcloud.material.uniforms.wClassification.value = scope.getWeightClassification(); - pointcloud.material.uniforms.wReturnNumber.value = scope.getWeightReturnNumber(); - pointcloud.material.uniforms.wSourceID.value = scope.getWeightSourceID(); + pointcloud.material.uniforms.wRGB.value = this.getWeightRGB(); + pointcloud.material.uniforms.wIntensity.value = this.getWeightIntensity(); + pointcloud.material.uniforms.wElevation.value = this.getWeightElevation(); + pointcloud.material.uniforms.wClassification.value = this.getWeightClassification(); + pointcloud.material.uniforms.wReturnNumber.value = this.getWeightReturnNumber(); + pointcloud.material.uniforms.wSourceID.value = this.getWeightSourceID(); - //if(!scope.freeze){ - // pointcloud.update(scope.camera, scope.renderer); + //if(!this.freeze){ + // pointcloud.update(this.camera, this.renderer); //} visibleNodes += pointcloud.numVisibleNodes; @@ -13035,14 +13014,14 @@ Potree.Viewer = function(domElement, args){ progress += pointcloud.progress; } - if(!scope.freeze){ - var result = Potree.updatePointClouds(scope.pointclouds, scope.camera, scope.renderer); + if(!this.freeze){ + var result = Potree.updatePointClouds(this.scene.pointclouds, this.camera, this.renderer); visibleNodes = result.visibleNodes.length; visiblePoints = result.numVisiblePoints; } - //if(stats && scope.showStats){ + //if(stats && this.showStats){ // document.getElementById("lblNumVisibleNodes").style.display = ""; // document.getElementById("lblNumVisiblePoints").style.display = ""; // stats.domElement.style.display = ""; @@ -13057,40 +13036,40 @@ Potree.Viewer = function(domElement, args){ // stats.domElement.style.display = "none"; //} - scope.camera.fov = scope.fov; + this.camera.fov = this.fov; - if(scope.controls){ - scope.controls.update(delta); + if(this.controls){ + this.controls.update(delta); } // update progress bar - if(scope.pointclouds.length > 0){ - scope.progressBar.progress = progress / scope.pointclouds.length; + if(this.scene.pointclouds.length > 0){ + this.progressBar.progress = progress / this.scene.pointclouds.length; var message; if(progress === 0){ message = "loading"; }else{ - message = "loading: " + parseInt(progress*100 / scope.pointclouds.length) + "%"; + message = "loading: " + parseInt(progress*100 / this.scene.pointclouds.length) + "%"; } - scope.progressBar.message = message; + this.progressBar.message = message; if(progress >= 0.999){ - scope.progressBar.hide(); + this.progressBar.hide(); }else if(progress < 1){ - scope.progressBar.show(); + this.progressBar.show(); } } - scope.volumeTool.update(); - scope.transformationTool.update(); - scope.profileTool.update(); + this.volumeTool.update(); + this.transformationTool.update(); + this.profileTool.update(); var clipBoxes = []; - for(var i = 0; i < scope.profileTool.profiles.length; i++){ - var profile = scope.profileTool.profiles[i]; + for(var i = 0; i < this.profileTool.profiles.length; i++){ + var profile = this.profileTool.profiles[i]; for(var j = 0; j < profile.boxes.length; j++){ var box = profile.boxes[j]; @@ -13101,8 +13080,8 @@ Potree.Viewer = function(domElement, args){ } } - for(var i = 0; i < scope.volumeTool.volumes.length; i++){ - var volume = scope.volumeTool.volumes[i]; + for(var i = 0; i < this.volumeTool.volumes.length; i++){ + var volume = this.volumeTool.volumes[i]; if(volume.clip){ volume.updateMatrixWorld(); @@ -13114,18 +13093,18 @@ Potree.Viewer = function(domElement, args){ } - for(var i = 0; i < scope.pointclouds.length; i++){ - scope.pointclouds[i].material.setClipBoxes(clipBoxes); + for(var i = 0; i < this.scene.pointclouds.length; i++){ + this.scene.pointclouds[i].material.setClipBoxes(clipBoxes); } {// update annotations var distances = []; - for(var i = 0; i < scope.annotations.length; i++){ - var ann = scope.annotations[i]; - var screenPos = ann.position.clone().project(scope.camera); + for(var i = 0; i < this.annotations.length; i++){ + var ann = this.annotations[i]; + var screenPos = ann.position.clone().project(this.camera); - screenPos.x = scope.renderArea.clientWidth * (screenPos.x + 1) / 2; - screenPos.y = scope.renderArea.clientHeight * (1 - (screenPos.y + 1) / 2); + screenPos.x = this.renderArea.clientWidth * (screenPos.x + 1) / 2; + screenPos.y = this.renderArea.clientHeight * (1 - (screenPos.y + 1) / 2); ann.domElement.style.left = Math.floor(screenPos.x - ann.domElement.clientWidth / 2) + "px"; ann.domElement.style.top = Math.floor(screenPos.y) + "px"; @@ -13151,536 +13130,32 @@ Potree.Viewer = function(domElement, args){ } } - if(scope.showDebugInfos){ - scope.infos.set("camera.position", "camera.position: " + - scope.camera.position.x.toFixed(2) - + ", " + scope.camera.position.y.toFixed(2) - + ", " + scope.camera.position.z.toFixed(2) + if(this.showDebugInfos){ + this.infos.set("camera.position", "camera.position: " + + this.camera.position.x.toFixed(2) + + ", " + this.camera.position.y.toFixed(2) + + ", " + this.camera.position.z.toFixed(2) ); } - if(scope.mapView){ - scope.mapView.update(delta, scope.camera); + if(this.mapView){ + this.mapView.update(delta, this.camera); } TWEEN.update(timestamp); - scope.dispatchEvent({"type": "update", "delta": delta, "timestamp": timestamp}); + this.dispatcher.dispatchEvent({"type": "update", "delta": delta, "timestamp": timestamp}); } - - - - - - - - - - - - - - - - - - -//------------------------------------------------------------------------------------ -// Renderers -//------------------------------------------------------------------------------------ - - var PotreeRenderer = function(){ - - this.render = function(){ - {// resize - var width = scaleFactor * scope.renderArea.clientWidth; - var height = scaleFactor * scope.renderArea.clientHeight; - var aspect = width / height; - - scope.camera.aspect = aspect; - scope.camera.updateProjectionMatrix(); - - scope.renderer.setSize(width, height); - } - - - //var queryAll = Potree.startQuery("All", viewer.renderer.getContext()); - - // render skybox - if(scope.showSkybox){ - skybox.camera.rotation.copy(scope.camera.rotation); - scope.renderer.render(skybox.scene, skybox.camera); - }else{ - scope.renderer.render(scope.sceneBG, scope.cameraBG); - } - - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - if(pointcloud.originalMaterial){ - pointcloud.material = pointcloud.originalMaterial; - } - - var bbWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld); - - pointcloud.material.useEDL = false; - pointcloud.material.size = scope.pointSize; - pointcloud.material.minSize = scope.minPointSize; - pointcloud.material.maxSize = scope.maxPointSize; - pointcloud.material.opacity = scope.opacity; - pointcloud.material.pointColorType = scope.pointColorType; - pointcloud.material.pointSizeType = scope.pointSizeType; - pointcloud.material.pointShape = (scope.quality === "Circles") ? Potree.PointShape.CIRCLE : Potree.PointShape.SQUARE; - pointcloud.material.interpolate = (scope.quality === "Interpolation"); - pointcloud.material.weighted = false; - } - - // render scene - scope.renderer.render(scope.scene, scope.camera); - - //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); - scope.renderer.render(scope.scenePointCloud, scope.camera); - //Potree.endQuery(queryPC, viewer.renderer.getContext()); - - scope.profileTool.render(); - scope.volumeTool.render(); - - scope.renderer.clearDepth(); - scope.measuringTool.render(); - scope.transformationTool.render(); - - //Potree.endQuery(queryAll, viewer.renderer.getContext()); - - //Potree.resolveQueries(viewer.renderer.getContext()); - }; - }; - var potreeRenderer = new PotreeRenderer(); - - // high quality rendering using splats - var highQualityRenderer = null; - var HighQualityRenderer = function(){ - - var depthMaterial = null; - var attributeMaterial = null; - var normalizationMaterial = null; + loop(timestamp) { - var rtDepth; - var rtNormalize; + requestAnimationFrame(this.loop.bind(this)); - var initHQSPlats = function(){ - if(depthMaterial != null){ - return; - } - - depthMaterial = new Potree.PointCloudMaterial(); - attributeMaterial = new Potree.PointCloudMaterial(); - - depthMaterial.pointColorType = Potree.PointColorType.DEPTH; - depthMaterial.pointShape = Potree.PointShape.CIRCLE; - depthMaterial.interpolate = false; - depthMaterial.weighted = false; - depthMaterial.minSize = scope.minPointSize; - depthMaterial.maxSize = scope.maxPointSize; - - attributeMaterial.pointShape = Potree.PointShape.CIRCLE; - attributeMaterial.interpolate = false; - attributeMaterial.weighted = true; - attributeMaterial.minSize = scope.minPointSize; - attributeMaterial.maxSize = scope.maxPointSize; - - rtDepth = new THREE.WebGLRenderTarget( 1024, 1024, { - minFilter: THREE.NearestFilter, - magFilter: THREE.NearestFilter, - format: THREE.RGBAFormat, - type: THREE.FloatType - } ); - - rtNormalize = new THREE.WebGLRenderTarget( 1024, 1024, { - minFilter: THREE.LinearFilter, - magFilter: THREE.NearestFilter, - format: THREE.RGBAFormat, - type: THREE.FloatType - } ); - - var uniformsNormalize = { - depthMap: { type: "t", value: rtDepth }, - texture: { type: "t", value: rtNormalize } - }; - - normalizationMaterial = new THREE.ShaderMaterial({ - uniforms: uniformsNormalize, - vertexShader: Potree.Shaders["normalize.vs"], - fragmentShader: Potree.Shaders["normalize.fs"] - }); - } - - var resize = function(width, height){ - if(rtDepth.width == width && rtDepth.height == height){ - return; - } - - rtDepth.dispose(); - rtNormalize.dispose(); - - scope.camera.aspect = width / height; - scope.camera.updateProjectionMatrix(); - - scope.renderer.setSize(width, height); - rtDepth.setSize(width, height); - rtNormalize.setSize(width, height); - }; - - // render with splats - this.render = function(renderer){ - - var width = scope.renderArea.clientWidth; - var height = scope.renderArea.clientHeight; - - initHQSPlats(); - - resize(width, height); - - - scope.renderer.clear(); - if(scope.showSkybox){ - skybox.camera.rotation.copy(scope.camera.rotation); - scope.renderer.render(skybox.scene, skybox.camera); - }else{ - scope.renderer.render(scope.sceneBG, scope.cameraBG); - } - scope.renderer.render(scope.scene, scope.camera); - - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - - depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - - var originalMaterial = pointcloud.material; - - {// DEPTH PASS - depthMaterial.size = scope.pointSize; - depthMaterial.pointSizeType = scope.pointSizeType; - depthMaterial.screenWidth = width; - depthMaterial.screenHeight = height; - depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - depthMaterial.fov = scope.camera.fov * (Math.PI / 180); - depthMaterial.spacing = pointcloud.pcoGeometry.spacing; - depthMaterial.near = scope.camera.near; - depthMaterial.far = scope.camera.far; - depthMaterial.heightMin = scope.heightMin; - depthMaterial.heightMax = scope.heightMax; - depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - depthMaterial.bbSize = pointcloud.material.bbSize; - depthMaterial.treeType = pointcloud.material.treeType; - depthMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; - - scope.scenePointCloud.overrideMaterial = depthMaterial; - scope.renderer.clearTarget( rtDepth, true, true, true ); - scope.renderer.render(scope.scenePointCloud, scope.camera, rtDepth); - scope.scenePointCloud.overrideMaterial = null; - } - - {// ATTRIBUTE PASS - attributeMaterial.size = scope.pointSize; - attributeMaterial.pointSizeType = scope.pointSizeType; - attributeMaterial.screenWidth = width; - attributeMaterial.screenHeight = height; - attributeMaterial.pointColorType = scope.pointColorType; - attributeMaterial.depthMap = rtDepth; - attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - attributeMaterial.fov = scope.camera.fov * (Math.PI / 180); - attributeMaterial.uniforms.blendHardness.value = pointcloud.material.uniforms.blendHardness.value; - attributeMaterial.uniforms.blendDepthSupplement.value = pointcloud.material.uniforms.blendDepthSupplement.value; - attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; - attributeMaterial.near = scope.camera.near; - attributeMaterial.far = scope.camera.far; - attributeMaterial.heightMin = scope.heightMin; - attributeMaterial.heightMax = scope.heightMax; - attributeMaterial.intensityMin = pointcloud.material.intensityMin; - attributeMaterial.intensityMax = pointcloud.material.intensityMax; - attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); - attributeMaterial.clipMode = pointcloud.material.clipMode; - attributeMaterial.bbSize = pointcloud.material.bbSize; - attributeMaterial.treeType = pointcloud.material.treeType; - attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; - - scope.scenePointCloud.overrideMaterial = attributeMaterial; - scope.renderer.clearTarget( rtNormalize, true, true, true ); - scope.renderer.render(scope.scenePointCloud, scope.camera, rtNormalize); - scope.scenePointCloud.overrideMaterial = null; - - pointcloud.material = originalMaterial; - } - } - - if(scope.pointclouds.length > 0){ - {// NORMALIZATION PASS - normalizationMaterial.uniforms.depthMap.value = rtDepth; - normalizationMaterial.uniforms.texture.value = rtNormalize; - Potree.utils.screenPass.render(scope.renderer, normalizationMaterial); - } - - scope.volumeTool.render(); - scope.renderer.clearDepth(); - scope.profileTool.render(); - scope.measuringTool.render(); - scope.transformationTool.render(); - } - - } - }; - - - - this.edlRenderer = null; - var EDLRenderer = function(){ - - _this = this; - - _this.edlMaterial = null; - var attributeMaterials = []; - - //var depthTexture = null; - - var rtColor = null; - var gl = scope.renderer.context; - - var initEDL = function(){ - if(_this.edlMaterial != null){ - return; - } - - //var depthTextureExt = gl.getExtension("WEBGL_depth_texture"); - - _this.edlMaterial = new Potree.EyeDomeLightingMaterial(); - - - rtColor = new THREE.WebGLRenderTarget( 1024, 1024, { - minFilter: THREE.NearestFilter, - magFilter: THREE.NearestFilter, - format: THREE.RGBAFormat, - type: THREE.FloatType, - //type: THREE.UnsignedByteType, - //depthBuffer: false, - //stencilBuffer: false - } ); - - }; - - var resize = function(){ - var width = this.scaleFactor * scope.renderArea.clientWidth; - var height = this.scaleFactor * scope.renderArea.clientHeight; - var aspect = width / height; - - var needsResize = (rtColor.width != width || rtColor.height != height); - - // disposal will be unnecessary once this fix made it into three.js master: - // https://github.com/mrdoob/three.js/pull/6355 - if(needsResize){ - rtColor.dispose(); - } - - scope.camera.aspect = aspect; - scope.camera.updateProjectionMatrix(); - - scope.renderer.setSize(width, height); - rtColor.setSize(width, height); - } - - this.render = function(){ - - initEDL(); - - resize(); - - scope.renderer.clear(); - if(scope.showSkybox){ - skybox.camera.rotation.copy(scope.camera.rotation); - scope.renderer.render(skybox.scene, skybox.camera); - }else{ - scope.renderer.render(scope.sceneBG, scope.cameraBG); - } - scope.renderer.render(scope.scene, scope.camera); - - var originalMaterials = []; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - var width = scope.renderArea.clientWidth; - var height = scope.renderArea.clientHeight; - - if(attributeMaterials.length <= i ){ - var attributeMaterial = new Potree.PointCloudMaterial(); - - attributeMaterial.pointShape = Potree.PointShape.CIRCLE; - attributeMaterial.interpolate = (scope.quality === "Interpolation"); - attributeMaterial.weighted = false; - attributeMaterial.minSize = scope.minPointSize; - attributeMaterial.maxSize = scope.maxPointSize; - attributeMaterial.useLogarithmicDepthBuffer = false; - attributeMaterial.useEDL = true; - attributeMaterials.push(attributeMaterial); - } - var attributeMaterial = attributeMaterials[i]; - - var octreeSize = pointcloud.pcoGeometry.boundingBox.getSize().x; - - originalMaterials.push(pointcloud.material); - - scope.renderer.clearTarget( rtColor, true, true, true ); - - {// COLOR & DEPTH PASS - attributeMaterial = pointcloud.material; - attributeMaterial.pointShape = Potree.PointShape.CIRCLE; - attributeMaterial.interpolate = (scope.quality === "Interpolation"); - attributeMaterial.weighted = false; - attributeMaterial.minSize = scope.minPointSize; - attributeMaterial.maxSize = scope.maxPointSize; - attributeMaterial.useLogarithmicDepthBuffer = false; - attributeMaterial.useEDL = true; - - attributeMaterial.size = scope.pointSize; - attributeMaterial.pointSizeType = scope.pointSizeType; - attributeMaterial.screenWidth = width; - attributeMaterial.screenHeight = height; - attributeMaterial.pointColorType = scope.pointColorType; - attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - attributeMaterial.uniforms.octreeSize.value = octreeSize; - attributeMaterial.fov = scope.camera.fov * (Math.PI / 180); - attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; - attributeMaterial.near = scope.camera.near; - attributeMaterial.far = scope.camera.far; - attributeMaterial.heightMin = scope.heightMin; - attributeMaterial.heightMax = scope.heightMax; - attributeMaterial.intensityMin = pointcloud.material.intensityMin; - attributeMaterial.intensityMax = pointcloud.material.intensityMax; - attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); - attributeMaterial.clipMode = pointcloud.material.clipMode; - attributeMaterial.bbSize = pointcloud.material.bbSize; - attributeMaterial.treeType = pointcloud.material.treeType; - attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; - - pointcloud.material = attributeMaterial; - for(var j = 0; j < pointcloud.visibleNodes.length; j++){ - var node = pointcloud.visibleNodes[j]; - if(pointcloud instanceof Potree.PointCloudOctree){ - node.sceneNode.material = attributeMaterial; - }else if(pointcloud instanceof Potree.PointCloudArena4D){ - node.material = attributeMaterial; - } - } - } - - } - - //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); - scope.renderer.render(scope.scenePointCloud, scope.camera, rtColor); - //Potree.endQuery(queryPC, viewer.renderer.getContext()); - - - // bit of a hack here. The EDL pass will mess up the text of the volume tool - // so volume tool is rendered again afterwards - scope.volumeTool.render(rtColor); - - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - var originalMaterial = originalMaterials[i]; - pointcloud.material = originalMaterial; - for(var j = 0; j < pointcloud.visibleNodes.length; j++){ - var node = pointcloud.visibleNodes[j]; - if(pointcloud instanceof Potree.PointCloudOctree){ - node.sceneNode.material = originalMaterial; - }else if(pointcloud instanceof Potree.PointCloudArena4D){ - node.material = originalMaterial; - } - } - } - - if(scope.pointclouds.length > 0){ - - //var ext = viewer.renderer.getContext().getExtension("EXT_disjoint_timer_query"); - //if(window.timerQuery == null){ - // window.timerQuery = ext.createQueryEXT(); - // ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, window.timerQuery); - //} - - //var query = Potree.startQuery("EDL", viewer.renderer.getContext()); - - { // EDL OCCLUSION PASS - _this.edlMaterial.uniforms.screenWidth.value = width; - _this.edlMaterial.uniforms.screenHeight.value = height; - _this.edlMaterial.uniforms.colorMap.value = rtColor; - _this.edlMaterial.uniforms.edlStrength.value = scope.edlStrength; - _this.edlMaterial.uniforms.radius.value = scope.edlRadius; - _this.edlMaterial.uniforms.opacity.value = scope.opacity; - _this.edlMaterial.depthTest = true; - _this.edlMaterial.depthWrite = true; - _this.edlMaterial.transparent = true; - - Potree.utils.screenPass.render(scope.renderer, _this.edlMaterial); - } - - scope.renderer.render(scope.scene, scope.camera); - - //Potree.endQuery(query, viewer.renderer.getContext()); - //Potree.resolveQueries(viewer.renderer.getContext()); - - //if(window.endedQuery == null){ - // ext.endQueryEXT(ext.TIME_ELAPSED_EXT); - // window.endedQuery = window.timerQuery; - //} - // - // - //if(window.endedQuery != null){ - // var available = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_AVAILABLE_EXT); - // var disjoint = viewer.renderer.getContext().getParameter(ext.GPU_DISJOINT_EXT); - // - // if (available && !disjoint) { - // // See how much time the rendering of the object took in nanoseconds. - // var timeElapsed = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_EXT); - // var miliseconds = timeElapsed / (1000 * 1000); - // - // console.log(miliseconds + "ms"); - // - // window.endedQuery = null; - // window.timerQuery = null; - // } - //} - - - - scope.profileTool.render(); - scope.volumeTool.render(); - scope.renderer.clearDepth(); - scope.measuringTool.render(); - scope.transformationTool.render(); - } - - - - } - }; - - //var toggleMessage = 0; - - scope.stats = new Stats(); - //scope.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom - //document.body.appendChild( scope.stats.dom ); - //scope.stats.dom.style.left = "100px"; - - - function loop(timestamp) { - - requestAnimationFrame(loop); - - scope.stats.begin(); + this.stats.begin(); //var start = new Date().getTime(); - scope.update(clock.getDelta(), timestamp); + this.update(this.clock.getDelta(), timestamp); //var end = new Date().getTime(); //var duration = end - start; //toggleMessage++; @@ -13689,79 +13164,531 @@ Potree.Viewer = function(domElement, args){ // toggleMessage = 0; //} - if(scope.useEDL && Potree.Features.SHADER_EDL.isSupported()){ - if(!scope.edlRenderer){ - scope.edlRenderer = new EDLRenderer(); + if(this.useEDL && Potree.Features.SHADER_EDL.isSupported()){ + if(!this.edlRenderer){ + this.edlRenderer = new EDLRenderer(this); } - scope.edlRenderer.render(scope.renderer); - }else if(scope.quality === "Splats"){ - if(!highQualityRenderer){ - highQualityRenderer = new HighQualityRenderer(); + this.edlRenderer.render(this.renderer); + }else if(this.quality === "Splats"){ + if(!this.highQualityRenderer){ + this.highQualityRenderer = new HighQualityRenderer(this); } - highQualityRenderer.render(scope.renderer); + this.highQualityRenderer.render(this.renderer); }else{ - potreeRenderer.render(); + if(!this.potreeRenderer){ + this.potreeRenderer = new PotreeRenderer(this); + } + + this.potreeRenderer.render(); } //if(this.takeScreenshot == true){ // this.takeScreenshot = false; // - // var screenshot = scope.renderer.domElement.toDataURL(); + // var screenshot = this.renderer.domElement.toDataURL(); // // //document.body.appendChild(screenshot); // var w = this.open(); // w.document.write(''); //} - scope.stats.end(); + this.stats.end(); Potree.framenumber++; }; - scope.initThree(); - //scope.initGUI(); - // set defaults - scope.setPointSize(1); - scope.setFOV(60); - scope.setOpacity(1); - scope.setEDLEnabled(false); - scope.setEDLRadius(1.4); - scope.setEDLStrength(1.0); - scope.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); - scope.setPointBudget(1*1000*1000); - scope.setShowBoundingBox(false); - scope.setFreeze(false); - scope.setNavigationMode("Orbit"); - - scaleFactor = 1; - - scope.loadSettingsFromURL(); - - // start rendering! - requestAnimationFrame(loop); - - - //document.body.addEventListener('keydown', function(e) { - // if(e.which === 75){ - // window.takeScreenshot = true; - // } - //}); }; -Potree.Viewer.prototype = Object.create( THREE.EventDispatcher.prototype ); +//------------------------------------------------------------------------------------ +// Renderers +//------------------------------------------------------------------------------------ + +class PotreeRenderer{ + + constructor(viewer){ + this.viewer = viewer; + }; + + render(){ + {// resize + let width = viewer.scaleFactor * viewer.renderArea.clientWidth; + let height = viewer.scaleFactor * viewer.renderArea.clientHeight; + let aspect = width / height; + + viewer.camera.aspect = aspect; + viewer.camera.updateProjectionMatrix(); + + viewer.renderer.setSize(width, height); + } + + + //var queryAll = Potree.startQuery("All", viewer.renderer.getContext()); + + // render skybox + if(viewer.showSkybox){ + viewer.skybox.camera.rotation.copy(viewer.camera.rotation); + viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera); + }else{ + viewer.renderer.render(viewer.scene.sceneBG, viewer.cameraBG); + } + + for(let i = 0; i < viewer.scene.pointclouds.length; i++){ + let pointcloud = viewer.scene.pointclouds[i]; + if(pointcloud.originalMaterial){ + pointcloud.material = pointcloud.originalMaterial; + } + + let bbWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld); + + pointcloud.material.useEDL = false; + pointcloud.material.size = viewer.pointSize; + pointcloud.material.minSize = viewer.minPointSize; + pointcloud.material.maxSize = viewer.maxPointSize; + pointcloud.material.opacity = viewer.opacity; + pointcloud.material.pointColorType = viewer.pointColorType; + pointcloud.material.pointSizeType = viewer.pointSizeType; + pointcloud.material.pointShape = (viewer.quality === "Circles") ? Potree.PointShape.CIRCLE : Potree.PointShape.SQUARE; + pointcloud.material.interpolate = (viewer.quality === "Interpolation"); + pointcloud.material.weighted = false; + } + + // render scene + viewer.renderer.render(viewer.scene.scene, viewer.camera); + + //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); + viewer.renderer.render(viewer.scene.scenePointCloud, viewer.camera); + //Potree.endQuery(queryPC, viewer.renderer.getContext()); + + viewer.profileTool.render(); + viewer.volumeTool.render(); + + viewer.renderer.clearDepth(); + viewer.measuringTool.render(); + viewer.transformationTool.render(); + + //Potree.endQuery(queryAll, viewer.renderer.getContext()); + + //Potree.resolveQueries(viewer.renderer.getContext()); + }; +}; + +// high quality rendering using splats +class HighQualityRenderer{ + + constructor(viewer){ + this.viewer = viewer; + + this.depthMaterial = null; + this.attributeMaterial = null; + this.normalizationMaterial = null; + + this.rtDepth; + this.rtNormalize; + }; + + + + initHQSPlats(){ + if(depthMaterial != null){ + return; + } + + depthMaterial = new Potree.PointCloudMaterial(); + attributeMaterial = new Potree.PointCloudMaterial(); + + depthMaterial.pointColorType = Potree.PointColorType.DEPTH; + depthMaterial.pointShape = Potree.PointShape.CIRCLE; + depthMaterial.interpolate = false; + depthMaterial.weighted = false; + depthMaterial.minSize = viewer.minPointSize; + depthMaterial.maxSize = viewer.maxPointSize; + + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = false; + attributeMaterial.weighted = true; + attributeMaterial.minSize = viewer.minPointSize; + attributeMaterial.maxSize = viewer.maxPointSize; + + rtDepth = new THREE.WebGLRenderTarget( 1024, 1024, { + minFilter: THREE.NearestFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat, + type: THREE.FloatType + } ); + + rtNormalize = new THREE.WebGLRenderTarget( 1024, 1024, { + minFilter: THREE.LinearFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat, + type: THREE.FloatType + } ); + + var uniformsNormalize = { + depthMap: { type: "t", value: rtDepth }, + texture: { type: "t", value: rtNormalize } + }; + + normalizationMaterial = new THREE.ShaderMaterial({ + uniforms: uniformsNormalize, + vertexShader: Potree.Shaders["normalize.vs"], + fragmentShader: Potree.Shaders["normalize.fs"] + }); + }; + + resize(width, height){ + if(rtDepth.width == width && rtDepth.height == height){ + return; + } + + rtDepth.dispose(); + rtNormalize.dispose(); + + viewer.camera.aspect = width / height; + viewer.camera.updateProjectionMatrix(); + + viewer.renderer.setSize(width, height); + rtDepth.setSize(width, height); + rtNormalize.setSize(width, height); + }; + + // render with splats + render(renderer){ + + var width = viewer.renderArea.clientWidth; + var height = viewer.renderArea.clientHeight; + + initHQSPlats(); + + resize(width, height); + + + viewer.renderer.clear(); + if(viewer.showSkybox){ + skybox.camera.rotation.copy(viewer.camera.rotation); + viewer.renderer.render(skybox.scene, skybox.camera); + }else{ + viewer.renderer.render(viewer.sceneBG, viewer.cameraBG); + } + viewer.renderer.render(viewer.scene, viewer.camera); + + for(var i = 0; i < viewer.pointclouds.length; i++){ + var pointcloud = viewer.pointclouds[i]; + + depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + + var originalMaterial = pointcloud.material; + + {// DEPTH PASS + depthMaterial.size = viewer.pointSize; + depthMaterial.pointSizeType = viewer.pointSizeType; + depthMaterial.screenWidth = width; + depthMaterial.screenHeight = height; + depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + depthMaterial.fov = viewer.camera.fov * (Math.PI / 180); + depthMaterial.spacing = pointcloud.pcoGeometry.spacing; + depthMaterial.near = viewer.camera.near; + depthMaterial.far = viewer.camera.far; + depthMaterial.heightMin = viewer.heightMin; + depthMaterial.heightMax = viewer.heightMax; + depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + depthMaterial.bbSize = pointcloud.material.bbSize; + depthMaterial.treeType = pointcloud.material.treeType; + depthMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; + + viewer.scenePointCloud.overrideMaterial = depthMaterial; + viewer.renderer.clearTarget( rtDepth, true, true, true ); + viewer.renderer.render(viewer.scenePointCloud, viewer.camera, rtDepth); + viewer.scenePointCloud.overrideMaterial = null; + } + + {// ATTRIBUTE PASS + attributeMaterial.size = viewer.pointSize; + attributeMaterial.pointSizeType = viewer.pointSizeType; + attributeMaterial.screenWidth = width; + attributeMaterial.screenHeight = height; + attributeMaterial.pointColorType = viewer.pointColorType; + attributeMaterial.depthMap = rtDepth; + attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + attributeMaterial.fov = viewer.camera.fov * (Math.PI / 180); + attributeMaterial.uniforms.blendHardness.value = pointcloud.material.uniforms.blendHardness.value; + attributeMaterial.uniforms.blendDepthSupplement.value = pointcloud.material.uniforms.blendDepthSupplement.value; + attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; + attributeMaterial.near = viewer.camera.near; + attributeMaterial.far = viewer.camera.far; + attributeMaterial.heightMin = viewer.heightMin; + attributeMaterial.heightMax = viewer.heightMax; + attributeMaterial.intensityMin = pointcloud.material.intensityMin; + attributeMaterial.intensityMax = pointcloud.material.intensityMax; + attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); + attributeMaterial.clipMode = pointcloud.material.clipMode; + attributeMaterial.bbSize = pointcloud.material.bbSize; + attributeMaterial.treeType = pointcloud.material.treeType; + attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; + + viewer.scenePointCloud.overrideMaterial = attributeMaterial; + viewer.renderer.clearTarget( rtNormalize, true, true, true ); + viewer.renderer.render(viewer.scenePointCloud, viewer.camera, rtNormalize); + viewer.scenePointCloud.overrideMaterial = null; + + pointcloud.material = originalMaterial; + } + } + + if(viewer.pointclouds.length > 0){ + {// NORMALIZATION PASS + normalizationMaterial.uniforms.depthMap.value = rtDepth; + normalizationMaterial.uniforms.texture.value = rtNormalize; + Potree.utils.screenPass.render(viewer.renderer, normalizationMaterial); + } + + viewer.volumeTool.render(); + viewer.renderer.clearDepth(); + viewer.profileTool.render(); + viewer.measuringTool.render(); + viewer.transformationTool.render(); + } + + } +}; +class EDLRenderer{ + + constructor(viewer){ + this.viewer = viewer; + + this.edlMaterial = null; + this.attributeMaterials = []; + + this.rtColor = null; + this.gl = viewer.renderer.context; + } + + initEDL(){ + if(this.edlMaterial != null){ + return; + } + + //var depthTextureExt = gl.getExtension("WEBGL_depth_texture"); + + this.edlMaterial = new Potree.EyeDomeLightingMaterial(); + + this.rtColor = new THREE.WebGLRenderTarget( 1024, 1024, { + minFilter: THREE.NearestFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat, + type: THREE.FloatType, + //type: THREE.UnsignedByteType, + //depthBuffer: false, + //stencilBuffer: false + } ); + + }; + + resize(){ + let width = viewer.scaleFactor * viewer.renderArea.clientWidth; + let height = viewer.scaleFactor * viewer.renderArea.clientHeight; + let aspect = width / height; + + var needsResize = (this.rtColor.width != width || this.rtColor.height != height); + + // disposal will be unnecessary once this fix made it into three.js master: + // https://github.com/mrdoob/three.js/pull/6355 + if(needsResize){ + this.rtColor.dispose(); + } + + viewer.camera.aspect = aspect; + viewer.camera.updateProjectionMatrix(); + + viewer.renderer.setSize(width, height); + this.rtColor.setSize(width, height); + } + render(){ + + this.initEDL(); + + this.resize(); + + viewer.renderer.clear(); + if(viewer.showSkybox){ + viewer.skybox.camera.rotation.copy(viewer.camera.rotation); + viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera); + }else{ + viewer.renderer.render(viewer.scene.sceneBG, viewer.cameraBG); + } + viewer.renderer.render(viewer.scene.scene, viewer.camera); + + var originalMaterials = []; + for(var i = 0; i < viewer.scene.pointclouds.length; i++){ + var pointcloud = viewer.scene.pointclouds[i]; + var width = viewer.renderArea.clientWidth; + var height = viewer.renderArea.clientHeight; + + if(this.attributeMaterials.length <= i ){ + var attributeMaterial = new Potree.PointCloudMaterial(); + + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = (viewer.quality === "Interpolation"); + attributeMaterial.weighted = false; + attributeMaterial.minSize = viewer.minPointSize; + attributeMaterial.maxSize = viewer.maxPointSize; + attributeMaterial.useLogarithmicDepthBuffer = false; + attributeMaterial.useEDL = true; + this.attributeMaterials.push(attributeMaterial); + } + var attributeMaterial = this.attributeMaterials[i]; + + var octreeSize = pointcloud.pcoGeometry.boundingBox.getSize().x; + + originalMaterials.push(pointcloud.material); + + viewer.renderer.clearTarget( this.rtColor, true, true, true ); + + {// COLOR & DEPTH PASS + attributeMaterial = pointcloud.material; + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = (viewer.quality === "Interpolation"); + attributeMaterial.weighted = false; + attributeMaterial.minSize = viewer.minPointSize; + attributeMaterial.maxSize = viewer.maxPointSize; + attributeMaterial.useLogarithmicDepthBuffer = false; + attributeMaterial.useEDL = true; + + attributeMaterial.size = viewer.pointSize; + attributeMaterial.pointSizeType = viewer.pointSizeType; + attributeMaterial.screenWidth = width; + attributeMaterial.screenHeight = height; + attributeMaterial.pointColorType = viewer.pointColorType; + attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + attributeMaterial.uniforms.octreeSize.value = octreeSize; + attributeMaterial.fov = viewer.camera.fov * (Math.PI / 180); + attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; + attributeMaterial.near = viewer.camera.near; + attributeMaterial.far = viewer.camera.far; + attributeMaterial.heightMin = viewer.heightMin; + attributeMaterial.heightMax = viewer.heightMax; + attributeMaterial.intensityMin = pointcloud.material.intensityMin; + attributeMaterial.intensityMax = pointcloud.material.intensityMax; + attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); + attributeMaterial.clipMode = pointcloud.material.clipMode; + attributeMaterial.bbSize = pointcloud.material.bbSize; + attributeMaterial.treeType = pointcloud.material.treeType; + attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; + + pointcloud.material = attributeMaterial; + for(var j = 0; j < pointcloud.visibleNodes.length; j++){ + var node = pointcloud.visibleNodes[j]; + if(pointcloud instanceof Potree.PointCloudOctree){ + node.sceneNode.material = attributeMaterial; + }else if(pointcloud instanceof Potree.PointCloudArena4D){ + node.material = attributeMaterial; + } + } + } + + } + + //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); + viewer.renderer.render(viewer.scene.scenePointCloud, viewer.camera, this.rtColor); + //Potree.endQuery(queryPC, viewer.renderer.getContext()); + + + // bit of a hack here. The EDL pass will mess up the text of the volume tool + // so volume tool is rendered again afterwards + viewer.volumeTool.render(this.rtColor); + + for(var i = 0; i < viewer.scene.pointclouds.length; i++){ + var pointcloud = viewer.scene.pointclouds[i]; + var originalMaterial = originalMaterials[i]; + pointcloud.material = originalMaterial; + for(var j = 0; j < pointcloud.visibleNodes.length; j++){ + var node = pointcloud.visibleNodes[j]; + if(pointcloud instanceof Potree.PointCloudOctree){ + node.sceneNode.material = originalMaterial; + }else if(pointcloud instanceof Potree.PointCloudArena4D){ + node.material = originalMaterial; + } + } + } + + if(viewer.scene.pointclouds.length > 0){ + + //var ext = viewer.renderer.getContext().getExtension("EXT_disjoint_timer_query"); + //if(window.timerQuery == null){ + // window.timerQuery = ext.createQueryEXT(); + // ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, window.timerQuery); + //} + + //var query = Potree.startQuery("EDL", viewer.renderer.getContext()); + + { // EDL OCCLUSION PASS + this.edlMaterial.uniforms.screenWidth.value = width; + this.edlMaterial.uniforms.screenHeight.value = height; + this.edlMaterial.uniforms.colorMap.value = this.rtColor; + this.edlMaterial.uniforms.edlStrength.value = viewer.edlStrength; + this.edlMaterial.uniforms.radius.value = viewer.edlRadius; + this.edlMaterial.uniforms.opacity.value = viewer.opacity; + this.edlMaterial.depthTest = true; + this.edlMaterial.depthWrite = true; + this.edlMaterial.transparent = true; + + Potree.utils.screenPass.render(viewer.renderer, this.edlMaterial); + } + + viewer.renderer.render(viewer.scene.scene, viewer.camera); + + //Potree.endQuery(query, viewer.renderer.getContext()); + //Potree.resolveQueries(viewer.renderer.getContext()); + + //if(window.endedQuery == null){ + // ext.endQueryEXT(ext.TIME_ELAPSED_EXT); + // window.endedQuery = window.timerQuery; + //} + // + // + //if(window.endedQuery != null){ + // var available = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_AVAILABLE_EXT); + // var disjoint = viewer.renderer.getContext().getParameter(ext.GPU_DISJOINT_EXT); + // + // if (available && !disjoint) { + // // See how much time the rendering of the object took in nanoseconds. + // var timeElapsed = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_EXT); + // var miliseconds = timeElapsed / (1000 * 1000); + // + // console.log(miliseconds + "ms"); + // + // window.endedQuery = null; + // window.timerQuery = null; + // } + //} + + + viewer.profileTool.render(); + viewer.volumeTool.render(); + viewer.renderer.clearDepth(); + viewer.measuringTool.render(); + viewer.transformationTool.render(); + } + + + } +}; Potree.Viewer.Profile = function(viewer, element){ var scope = this; @@ -13964,21 +13891,15 @@ Potree.Viewer.Profile = function(viewer, element){ // Get the same color map as Three var hr = scope.viewer.getHeightRange(); - var hrGeo = { - min: scope.viewer.toGeo(new THREE.Vector3(0, hr.min, 0)).z, - max: scope.viewer.toGeo(new THREE.Vector3(0, hr.max, 0)).z, - }; - //var minRange = scope.viewer.toGeo(new THREE.Vector3(0, args.heightMin, 0)); - //var maxRange = scope.viewer.toGeo(new THREE.Vector3(0, args.heightMax, 0)); - var heightRange = hrGeo.max - hrGeo.min; + var heightRange = hr.max - hr.min; var colorRange = []; var colorDomain = []; // Read the altitude gradient used in 3D scene - var gradient = viewer.pointclouds[0].material.gradient; + var gradient = viewer.scene.pointclouds[0].material.gradient; for (var c = 0; c < gradient.length; c++){ - colorDomain.push(hrGeo.min + heightRange * gradient[c][0]); + colorDomain.push(hr.min + heightRange * gradient[c][0]); colorRange.push('#' + gradient[c][1].getHexString()); } @@ -13991,8 +13912,8 @@ Potree.Viewer.Profile = function(viewer, element){ // Iterate the profile's segments for(var i = 0; i < segments.length; i++){ var segment = segments[i]; - var segStartGeo = scope.viewer.toGeo(segment.start); - var segEndGeo = scope.viewer.toGeo(segment.end); + var segStartGeo = new THREE.Vector3(segment.start.x, -segment.start.z, segment.start.y); + var segEndGeo = new THREE.Vector3(segment.end.x, -segment.end.z, segment.end.y); var xOA = segEndGeo.x - segStartGeo.x; var yOA = segEndGeo.y - segStartGeo.y; var segmentLength = Math.sqrt(xOA * xOA + yOA * yOA); @@ -14000,19 +13921,15 @@ Potree.Viewer.Profile = function(viewer, element){ // Iterate the segments' points for(var j = 0; j < points.numPoints; j++){ - var p = scope.viewer.toGeo(points.position[j]); - // get min/max values - if (p.x < minX) { minX = p.x;} - - if (p.y < minY) { minY = p.y;} - - if (p.z < minZ) { minZ = p.z;} - - if (p.x > maxX) { maxX = p.x;} - - if (p.y < maxY) { maxY = p.y;} - - if (p.z < maxZ) { maxZ = p.z;} + var p = points.position[j]; + p.set(p.x, -p.z, p.y); + + minX = Math.min(minX, p.x); + minY = Math.min(minY, p.y); + minZ = Math.min(minZ, p.z); + maxX = Math.min(maxX, p.x); + maxY = Math.min(maxY, p.y); + maxZ = Math.min(maxZ, p.z); var xOB = p.x - segStartGeo.x; var yOB = p.y - segStartGeo.y; @@ -14145,7 +14062,7 @@ Potree.Viewer.Profile = function(viewer, element){ //return d.intensity; return 'rgb(' + d.intensity + '%,' + d.intensity + '%,' + d.intensity + '%)'; } else if (material === Potree.PointColorType.CLASSIFICATION) { - var classif = scope.viewer.pointclouds[0].material.classification; + var classif = scope.viewer.scene.pointclouds[0].material.classification; if (typeof classif[d.classification] != 'undefined'){ var color = 'rgb(' + classif[d.classification].x * 100 + '%,'; color += classif[d.classification].y * 100 + '%,'; @@ -14193,7 +14110,7 @@ Potree.Viewer.Profile = function(viewer, element){ }else{ return; } - if(scope.viewer.pointclouds.length === 0){ + if(scope.viewer.scene.pointclouds.length === 0){ return; } @@ -14220,12 +14137,11 @@ Potree.Viewer.Profile = function(viewer, element){ var mileage = 0; for(var i = 0; i < profile.points.length; i++){ var point = profile.points[i]; - var pointGeo = scope.viewer.toGeo(point); if(i > 0){ - var previousGeo = scope.viewer.toGeo(profile.points[i-1]); - var dx = pointGeo.x - previousGeo.x; - var dy = pointGeo.y - previousGeo.y; + var previous = profile.points[i-1]; + var dx = point.x - previous.x; + var dy = point.y - previous.y; var distance = Math.sqrt(dx * dx + dy * dy); mileage += distance; } @@ -14409,8 +14325,8 @@ Potree.Viewer.Profile = function(viewer, element){ }; - for(var i = 0; i < scope.viewer.pointclouds.length; i++){ - var pointcloud = scope.viewer.pointclouds[i]; + for(var i = 0; i < scope.viewer.scene.pointclouds.length; i++){ + var pointcloud = scope.viewer.scene.pointclouds[i]; if(!pointcloud.visible){ continue; @@ -14507,7 +14423,7 @@ Potree.Viewer.Profile = function(viewer, element){ // http://epsg.io/ proj4.defs("UTM10N", "+proj=utm +zone=10 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"); -Potree.Viewer.MapView = function(viewer){ +Potree.MapView = function(viewer){ var scope = this; this.viewer = viewer; @@ -14780,11 +14696,11 @@ Potree.Viewer.MapView = function(viewer){ // adding pointclouds to map - scope.viewer.addEventListener("pointcloud_loaded", function(event){ + scope.viewer.dispatcher.addEventListener("pointcloud_loaded", function(event){ scope.load(event.pointcloud); }); - for(var i = 0; i < scope.viewer.pointclouds.length; i++){ - scope.load(scope.viewer.pointclouds[i]); + for(var i = 0; i < scope.viewer.scene.pointclouds.length; i++){ + scope.load(scope.viewer.scene.pointclouds[i]); } scope.viewer.profileTool.addEventListener("profile_added", scope.updateToolDrawings); @@ -14845,8 +14761,7 @@ Potree.Viewer.MapView = function(viewer){ for(var j = 0; j < profile.points.length; j++){ var point = profile.points[j]; - var pointGeo = scope.viewer.toGeo(point); - var pointMap = scope.toMap.forward([pointGeo.x, pointGeo.y]); + var pointMap = scope.toMap.forward([point.x, point.y]); coordinates.push(pointMap); } @@ -14862,8 +14777,7 @@ Potree.Viewer.MapView = function(viewer){ for(var j = 0; j < measurement.points.length; j++){ var point = measurement.points[j].position; - var pointGeo = scope.viewer.toGeo(point); - var pointMap = scope.toMap.forward([pointGeo.x, pointGeo.y]); + var pointMap = scope.toMap.forward([point.x, point.y]); coordinates.push(pointMap); } @@ -15004,8 +14918,8 @@ Potree.Viewer.MapView = function(viewer){ var campos = camera.position; var camdir = camera.getWorldDirection(); var sceneLookAt = camdir.clone().multiplyScalar(30 * scale).add(campos); - var geoPos = scope.viewer.toGeo(camera.position); - var geoLookAt = scope.viewer.toGeo(sceneLookAt); + var geoPos = camera.position; + var geoLookAt = sceneLookAt; var mapPos = new THREE.Vector2().fromArray(scope.toMap.forward([geoPos.x, geoPos.y])); var mapLookAt = new THREE.Vector2().fromArray(scope.toMap.forward([geoLookAt.x, geoLookAt.y])); var mapDir = new THREE.Vector2().subVectors(mapLookAt, mapPos).normalize(); diff --git a/build/potree/potree.min.js b/build/potree/potree.min.js index c6e2e054..c0740024 100644 --- a/build/potree/potree.min.js +++ b/build/potree/potree.min.js @@ -936,10 +936,8 @@ Potree.Shaders["pointcloud.vs"] = [ "}", "", "void main() {", - " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", - " vViewPosition = -mvPosition.xyz;", - " vWorldPosition = worldPosition.xyz;", + " vViewPosition = mvPosition.xyz;", " gl_Position = projectionMatrix * mvPosition;", " vOpacity = opacity;", " vLinearDepth = gl_Position.w;", @@ -1004,7 +1002,7 @@ Potree.Shaders["pointcloud.vs"] = [ " float pointSize = 1.0;", " ", " float slope = tan(fov / 2.0);", - " float projFactor = 0.5 * screenHeight / (slope * vViewPosition.z);", + " float projFactor = -0.5 * screenHeight / (slope * vViewPosition.z);", " ", " float r = spacing * 1.5;", " vRadius = r;", @@ -1095,7 +1093,6 @@ Potree.Shaders["pointcloud.fs"] = [ "varying float vLogDepth;", "varying vec3 vViewPosition;", "varying float vRadius;", - "varying vec3 vWorldPosition;", "varying vec3 vNormal;", "", "float specularStrength = 1.0;", @@ -1268,7 +1265,7 @@ Potree.Shaders["pointcloud.fs"] = [ " ", " #if defined use_interpolation", " float wi = 0.0 - ( u*u + v*v);", - " vec4 pos = vec4(-vViewPosition, 1.0);", + " vec4 pos = vec4(vViewPosition, 1.0);", " pos.z += wi * vRadius;", " float linearDepth = -pos.z;", " pos = projectionMatrix * pos;", @@ -4290,6 +4287,8 @@ Potree.OrbitControls = function ( object, domElement ) { var progression = Math.min(1, this.fadeFactor * delta); + let oldTheta = theta; + theta += progression * thetaDelta; phi += progression * phiDelta; @@ -5209,6 +5208,7 @@ Potree.Annotation = function(viewer, args){ this.view = args.view || null; this.keepOpen = false; this.descriptionVisible = false; + this.actions = args.actions || null; this.domElement = document.createElement("div"); this.domElement.style.position = "absolute"; @@ -5245,19 +5245,7 @@ Potree.Annotation = function(viewer, args){ //this.domDescription.style.left = "-100"; this.domElement.appendChild(this.domDescription); - this.elOrdinal.onmouseenter = function(){ - - }; - this.elOrdinal.onmouseleave = function(){ - - }; - this.elOrdinal.onclick = function(){ - scope.moveHere(scope.viewer.camera); - scope.dispatchEvent({type: "click", target: scope}); - if(scope.viewer.geoControls){ - scope.viewer.geoControls.setTrack(null); - } - }; + this.elOrdinalText = document.createElement("span"); @@ -5265,7 +5253,6 @@ Potree.Annotation = function(viewer, args){ this.elOrdinalText.style.verticalAlign = "middle"; this.elOrdinalText.style.lineHeight = "1.5em"; this.elOrdinalText.style.textAlign = "center"; - //this.elOrdinalText.style.width = "100%"; this.elOrdinalText.style.fontFamily = "Arial"; this.elOrdinalText.style.fontWeight = "bold"; this.elOrdinalText.style.padding = "1px 8px 0px 8px"; @@ -5274,6 +5261,47 @@ Potree.Annotation = function(viewer, args){ this.elOrdinalText.userSelect = "none"; this.elOrdinal.appendChild(this.elOrdinalText); + if(this.actions != null){ + this.elOrdinalText.style.padding = "1px 3px 0px 8px"; + + for(let action of this.actions){ + let elButton = document.createElement("img"); + + elButton.src = Potree.scriptPath + action.icon; + elButton.style.width = "24px"; + elButton.style.height = "24px"; + elButton.style.filter = "invert(1)"; + elButton.style.display = "inline-block"; + elButton.style.verticalAlign = "middle"; + elButton.style.lineHeight = "1.5em"; + elButton.style.textAlign = "center"; + elButton.style.fontFamily = "Arial"; + elButton.style.fontWeight = "bold"; + elButton.style.padding = "1px 3px 0px 3px"; + elButton.style.cursor = "default"; + + this.elOrdinal.appendChild(elButton); + + elButton.onclick = function(){ + action.onclick(); + }; + } + } + + this.elOrdinal.onmouseenter = function(){ + + }; + this.elOrdinal.onmouseleave = function(){ + + }; + this.elOrdinalText.onclick = function(){ + scope.moveHere(scope.viewer.camera); + scope.dispatchEvent({type: "click", target: scope}); + if(scope.viewer.geoControls){ + scope.viewer.geoControls.setTrack(null); + } + }; + this.elDescriptionText = document.createElement("span"); this.elDescriptionText.style.color = "#ffffff"; this.elDescriptionText.innerHTML = this.description; @@ -6439,8 +6467,8 @@ Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params) let uniforms = glstate.uniforms; gl.useProgram(program); - gl.uniformMatrix4fv(uniforms["projectionMatrix"], false, camera.projectionMatrix.elements); - gl.uniformMatrix4fv(uniforms["viewMatrix"], false, camera.matrixWorldInverse.elements); + gl.uniformMatrix4fv(uniforms["projectionMatrix"], false, new Float32Array(camera.projectionMatrix.elements)); + gl.uniformMatrix4fv(uniforms["viewMatrix"], false, new Float32Array(camera.matrixWorldInverse.elements)); { if(glstate.textures.visibleNodes === undefined){ @@ -6500,8 +6528,8 @@ Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params) pickMaterial.pcIndex = i + 1; let modelView = new THREE.Matrix4().multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld); - gl.uniformMatrix4fv(uniforms["modelMatrix"], false, object.matrixWorld.elements); - gl.uniformMatrix4fv(uniforms["modelViewMatrix"], false, modelView.elements); + gl.uniformMatrix4fv(uniforms["modelMatrix"], false, new Float32Array(object.matrixWorld.elements)); + gl.uniformMatrix4fv(uniforms["modelViewMatrix"], false, new Float32Array(modelView.elements)); let apPosition = gl.getAttribLocation(program, "position"); let apNormal = gl.getAttribLocation(program, "normal"); @@ -8229,11 +8257,10 @@ Object.defineProperty(Potree.Measure.prototype, "showDistances", { -Potree.MeasuringTool = function(scene, camera, renderer, toGeo){ +Potree.MeasuringTool = function(scene, camera, renderer){ var scope = this; this.enabled = false; - this.toGeo = toGeo; this.scene = scene; this.camera = camera; @@ -8607,10 +8634,10 @@ Potree.MeasuringTool = function(scene, camera, renderer, toGeo){ var scale = (70 / pr); label.scale.set(scale, scale, scale); - var geoCoord = scope.toGeo(point.position); + var geoCoord = point.position; var txt = geoCoord.x.toFixed(2) + " / "; - txt += geoCoord.y.toFixed(2) + " / "; - txt += geoCoord.z.toFixed(2); + txt += (-geoCoord.z).toFixed(2) + " / "; + txt += geoCoord.y.toFixed(2); label.setText(txt); } @@ -11482,187 +11509,205 @@ Object.defineProperty(ProgressBar.prototype, "message", { } }); -Potree.Viewer = function(domElement, args){ - var scope = this; - var arguments = args || {}; - var pointCloudLoadedCallback = arguments.onPointCloudLoaded || function(){}; - - this.renderArea = domElement; - - +Potree.Scene = class{ + constructor(){ + this.scene = new THREE.Scene(); + this.scenePointCloud = new THREE.Scene(); + this.sceneBG = new THREE.Scene(); + this.cameraBG; + this.pointclouds = []; + this.referenceFrame; + + this.referenceFrame = new THREE.Object3D(); + this.referenceFrame.matrixAutoUpdate = false; + this.scenePointCloud.add(this.referenceFrame); + } +}; - //if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { - // defaultSettings.navigation = "Orbit"; - //} +Potree.Viewer = class{ - this.annotations = []; - this.fov = 60; - this.pointSize = 1; - this.minPointSize = 1; - this.maxPointSize = 50; - this.opacity = 1; - this.sizeType = "Fixed"; - this.pointSizeType = Potree.PointSizeType.FIXED; - this.pointColorType = null; - this.clipMode = Potree.ClipMode.HIGHLIGHT_INSIDE; - this.quality = "Squares"; - this.isFlipYZ = false; - this.useDEMCollisions = false; - this.minNodeSize = 100; - this.directionalLight; - this.edlStrength = 1.0; - this.edlRadius = 1.4; - this.useEDL = false; - this.minimumJumpDistance = 0.2; - this.jumpDistance = null; - this.intensityMax = null; - this.heightMin = null; - this.heightMax = null; - this.materialTransition = 0.5; - this.weightRGB = 1.0; - this.weightIntensity = 0.0; - this.weightElevation = 0.0; - this.weightClassification = 0.0; - this.weightReturnNumber = 0.0; - this.weightSourceID = 0.0; - this.intensityRange = [0, 65000]; - this.intensityGamma = 1; - this.intensityContrast = 0; - this.intensityBrightness = 0; - this.rgbGamma = 1; - this.rgbContrast = 0; - this.rgbBrightness = 0; - - this.moveSpeed = 10; + constructor(domElement, args){ + var a = args || {}; + this.pointCloudLoadedCallback = a.onPointCloudLoaded || function(){}; + + this.renderArea = domElement; + + //if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { + // defaultSettings.navigation = "Orbit"; + //} + + this.annotations = []; + this.fov = 60; + this.pointSize = 1; + this.minPointSize = 1; + this.maxPointSize = 50; + this.opacity = 1; + this.sizeType = "Fixed"; + this.pointSizeType = Potree.PointSizeType.FIXED; + this.pointColorType = null; + this.clipMode = Potree.ClipMode.HIGHLIGHT_INSIDE; + this.quality = "Squares"; + this.isFlipYZ = false; + this.useDEMCollisions = false; + this.minNodeSize = 100; + this.directionalLight; + this.edlStrength = 1.0; + this.edlRadius = 1.4; + this.useEDL = false; + this.minimumJumpDistance = 0.2; + this.jumpDistance = null; + this.intensityMax = null; + this.heightMin = null; + this.heightMax = null; + this.materialTransition = 0.5; + this.weightRGB = 1.0; + this.weightIntensity = 0.0; + this.weightElevation = 0.0; + this.weightClassification = 0.0; + this.weightReturnNumber = 0.0; + this.weightSourceID = 0.0; + this.intensityRange = [0, 65000]; + this.intensityGamma = 1; + this.intensityContrast = 0; + this.intensityBrightness = 0; + this.rgbGamma = 1; + this.rgbContrast = 0; + this.rgbBrightness = 0; + + this.moveSpeed = 10; - this.showDebugInfos = false; - this.showStats = true; - this.showBoundingBox = false; - this.freeze = false; + this.showDebugInfos = false; + this.showStats = true; + this.showBoundingBox = false; + this.freeze = false; - this.fpControls; - this.orbitControls; - this.earthControls; - this.geoControls; - this.controls; + this.fpControls; + this.orbitControls; + this.earthControls; + this.geoControls; + this.controls; + this.mapView; - this.progressBar = new ProgressBar(); + this.progressBar = new ProgressBar(); + + this.stats = new Stats(); + //this.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom + //document.body.appendChild( this.stats.dom ); + //this.stats.dom.style.left = "100px"; + + this.potreeRenderer = null; + this.highQualityRenderer = null; + this.edlRenderer = null; + this.renderer; + this.camera; + + this.scene = new Potree.Scene(); + + this.measuringTool; + this.volumeTool; + this.transformationTool; + + this.dispatcher = new THREE.EventDispatcher(); + this.skybox; + this.stats; + this.clock = new THREE.Clock(); + this.showSkybox = false; + + this.initThree(); + + {// set defaults + this.setPointSize(1); + this.setFOV(60); + this.setOpacity(1); + this.setEDLEnabled(false); + this.setEDLRadius(1.4); + this.setEDLStrength(1.0); + this.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); + this.setPointBudget(1*1000*1000); + this.setShowBoundingBox(false); + this.setFreeze(false); + this.setNavigationMode("Orbit"); + + this.scaleFactor = 1; + + this.loadSettingsFromURL(); + } + + // start rendering! + requestAnimationFrame(this.loop.bind(this)); + + } - var gui; - - this.renderer; - this.camera; - this.scene; - this.scenePointCloud; - this.sceneBG; - this.cameraBG; - this.pointclouds = []; - this.measuringTool; - this.volumeTool; - this.transformationTool; - - var skybox; - this.stats; - var clock = new THREE.Clock(); - this.showSkybox = false; - this.referenceFrame; - - - - - - - - - - - - - - - - - - - - - - - - - - - //------------------------------------------------------------------------------------ // Viewer API //------------------------------------------------------------------------------------ - this.addPointCloud = function(path, callback){ + addEventListener(type, callback){ + this.dispatcher.addEventListener(type, callback); + } + + addPointCloud(path, callback){ callback = callback || function(){}; var initPointcloud = function(pointcloud){ - if(!scope.mapView){ + if(!this.mapView){ if(pointcloud.projection){ - scope.mapView = new Potree.Viewer.MapView(viewer); - scope.mapView.init(viewer); + this.mapView = new Potree.MapView(this); + this.mapView.init(this); } } - scope.pointclouds.push(pointcloud); - - scope.referenceFrame.add(pointcloud); + this.scene.pointclouds.push(pointcloud); + this.scene.referenceFrame.add(pointcloud); var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld); - scope.referenceFrame.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); if(sg.radius > 50*1000){ - scope.camera.near = 10; + this.camera.near = 10; }else if(sg.radius > 10*1000){ - scope.camera.near = 2; + this.camera.near = 2; }else if(sg.radius > 1000){ - scope.camera.near = 1; + this.camera.near = 1; }else if(sg.radius > 100){ - scope.camera.near = 0.5; + this.camera.near = 0.5; }else{ - scope.camera.near = 0.1; + this.camera.near = 0.1; } - if(scope.pointclouds.length === 1){ - scope.referenceFrame.position.sub(sg.center); - scope.referenceFrame.updateMatrixWorld(true); - var moveSpeed = sg.radius / 6; - scope.setMoveSpeed(moveSpeed); - } + //if(this.scene.pointclouds.length === 1){ + // this.scene.referenceFrame.position.sub(sg.center); + // this.scene.referenceFrame.updateMatrixWorld(true); + // var moveSpeed = sg.radius / 6; + // this.setMoveSpeed(moveSpeed); + //} - //scope.flipYZ(); + //this.flipYZ(); - scope.zoomTo(pointcloud, 1); + this.zoomTo(pointcloud, 1); - - var hr = scope.getHeightRange(); + var hr = this.getHeightRange(); if(hr.min === null || hr.max === null){ - var bbWorld = scope.getBoundingBox(); + var bbWorld = this.getBoundingBox(); - scope.setHeightRange(bbWorld.min.y, bbWorld.max.y); + this.setHeightRange(bbWorld.min.y, bbWorld.max.y); } - scope.earthControls.pointclouds.push(pointcloud); + this.earthControls.pointclouds.push(pointcloud); - if(scope.pointclouds.length === 1){ - scope.setNavigationMode("Orbit"); - scope.flipYZ(); - scope.zoomTo(pointcloud, 1); + if(this.scene.pointclouds.length === 1){ + this.setNavigationMode("Orbit"); + this.flipYZ(); + this.zoomTo(pointcloud, 1); } + this.dispatcher.dispatchEvent({"type": "pointcloud_loaded", "pointcloud": pointcloud}); - - scope.dispatchEvent({"type": "pointcloud_loaded", "pointcloud": pointcloud}); - - callback({type: "pointclouad_loaded", pointcloud: pointcloud}); - }; - this.addEventListener("pointcloud_loaded", pointCloudLoadedCallback); + callback({type: "pointcloud_loaded", pointcloud: pointcloud}); + }.bind(this); + this.dispatcher.addEventListener("pointcloud_loaded", this.pointCloudLoadedCallback); // load pointcloud if(!path){ @@ -11672,16 +11717,16 @@ Potree.Viewer = function(domElement, args){ if(!geometry){ callback({type: "loading_failed"}); }else{ - pointcloud = new Potree.PointCloudOctree(geometry); + let pointcloud = new Potree.PointCloudOctree(geometry); initPointcloud(pointcloud); } - }); + }.bind(this)); }else if(path.indexOf(".vpc") > 0){ Potree.PointCloudArena4DGeometry.load(path, function(geometry){ if(!geometry){ callback({type: "loading_failed"}); }else{ - pointcloud = new Potree.PointCloudArena4D(geometry); + let pointcloud = new Potree.PointCloudArena4D(geometry); initPointcloud(pointcloud); } }); @@ -11690,451 +11735,451 @@ Potree.Viewer = function(domElement, args){ } }; - this.toLocal = (function(viewer){ - return function(position){ - var scenePos = position.clone().applyMatrix4(viewer.referenceFrame.matrixWorld); - - return scenePos; - } - })(this); - - - this.toGeo = (function(viewer){ - return function(position){ - var inverse = new THREE.Matrix4().getInverse(viewer.referenceFrame.matrixWorld); - var geoPos = position.clone().applyMatrix4(inverse); + //toLocal(position){ + // var scenePos = position.clone().applyMatrix4(this.scene.referenceFrame.matrixWorld); + // + // return scenePos; + //}; + // + // + //toGeo(position){ + // var inverse = new THREE.Matrix4().getInverse(this.scene.referenceFrame.matrixWorld); + // var geoPos = position.clone().applyMatrix4(inverse); + // + // return geoPos; + //}; - return geoPos; - } - })(this); - - this.getMinNodeSize = function(){ - return scope.minNodeSize; + getMinNodeSize(){ + return this.minNodeSize; }; - this.setMinNodeSize = function(value){ - if(scope.minNodeSize !== value){ - scope.minNodeSize = value; - scope.dispatchEvent({"type": "minnodesize_changed", "viewer": scope}); + setMinNodeSize(value){ + if(this.minNodeSize !== value){ + this.minNodeSize = value; + this.dispatcher.dispatchEvent({"type": "minnodesize_changed", "viewer": this}); } }; - this.setDescription = function(value){ + setDescription(value){ $('#potree_description')[0].innerHTML = value; }; - this.setNavigationMode = function(value){ + setNavigationMode(value){ if(value === "Orbit"){ - scope.useOrbitControls(); + this.useOrbitControls(); }else if(value === "Flight"){ - scope.useFPSControls(); + this.useFPSControls(); }else if(value === "Earth"){ - scope.useEarthControls(); + this.useEarthControls(); } }; - this.setShowBoundingBox = function(value){ - if(scope.showBoundingBox !== value){ - scope.showBoundingBox = value; - scope.dispatchEvent({"type": "show_boundingbox_changed", "viewer": scope}); + setShowBoundingBox(value){ + if(this.showBoundingBox !== value){ + this.showBoundingBox = value; + this.dispatcher.dispatchEvent({"type": "show_boundingbox_changed", "viewer": this}); } }; - this.getShowBoundingBox = function(){ - return scope.showBoundingBox; + getShowBoundingBox(){ + return showBoundingBox; }; - this.setMoveSpeed = function(value){ - if(scope.moveSpeed !== value){ - scope.moveSpeed = value; - scope.fpControls.setMoveSpeed(value); - scope.geoControls.setMoveSpeed(value); - scope.dispatchEvent({"type": "move_speed_changed", "viewer": scope, "speed": value}); + setMoveSpeed(value){ + if(this.moveSpeed !== value){ + this.moveSpeed = value; + this.fpControls.setMoveSpeed(value); + this.geoControls.setMoveSpeed(value); + this.dispatcher.dispatchEvent({"type": "move_speed_changed", "viewer": this, "speed": value}); } }; - this.getMoveSpeed = function(){ - return scope.fpControls.moveSpeed; + getMoveSpeed(){ + return this.fpControls.moveSpeed; }; - this.setShowSkybox = function(value){ - if(scope.showSkybox !== value){ - scope.showSkybox = value; - scope.dispatchEvent({"type": "show_skybox_changed", "viewer": scope}); + setShowSkybox(value){ + if(this.showSkybox !== value){ + this.showSkybox = value; + this.dispatcher.dispatchEvent({"type": "show_skybox_changed", "viewer": this}); } }; - this.getShowSkybox = function(){ - return scope.showSkybox; + getShowSkybox(){ + return this.showSkybox; }; - this.setHeightRange = function(min, max){ - if(scope.heightMin !== min || scope.heightMax !== max){ - scope.heightMin = min || scope.heightMin; - scope.heightMax = max || scope.heightMax; - scope.dispatchEvent({"type": "height_range_changed", "viewer": scope}); + setHeightRange(min, max){ + if(this.heightMin !== min || this.heightMax !== max){ + this.heightMin = min || this.heightMin; + this.heightMax = max || this.heightMax; + this.dispatcher.dispatchEvent({"type": "height_range_changed", "viewer": this}); } }; - this.getHeightRange = function(){ - return {min: scope.heightMin, max: scope.heightMax}; + getHeightRange(){ + return {min: this.heightMin, max: this.heightMax}; }; - this.setIntensityRange = function(min, max){ - if(scope.intensityRange[0] !== min || scope.intensityRange[1] !== max){ - scope.intensityRange[0] = min || scope.intensityRange[0]; - scope.intensityRange[1] = max || scope.intensityRange[1]; - scope.dispatchEvent({"type": "intensity_range_changed", "viewer": scope}); + getElevationRange(){ + return getHeightRange(); + }; + + setIntensityRange(min, max){ + if(this.intensityRange[0] !== min || this.intensityRange[1] !== max){ + this.intensityRange[0] = min || this.intensityRange[0]; + this.intensityRange[1] = max || this.intensityRange[1]; + this.dispatcher.dispatchEvent({"type": "intensity_range_changed", "viewer": this}); } }; - this.getIntensityRange = function(){ - return scope.intensityRange; + getIntensityRange(){ + return this.intensityRange; }; - this.setIntensityGamma = function(value){ - if(scope.intensityGamma !== value){ - scope.intensityGamma = value; - scope.dispatchEvent({"type": "intensity_gamma_changed", "viewer": scope}); + setIntensityGamma(value){ + if(this.intensityGamma !== value){ + this.intensityGamma = value; + this.dispatcher.dispatchEvent({"type": "intensity_gamma_changed", "viewer": this}); } }; - this.getIntensityGamma = function(){ - return scope.intensityGamma; + getIntensityGamma(){ + return this.intensityGamma; }; - this.setIntensityContrast = function(value){ - if(scope.intensityContrast !== value){ - scope.intensityContrast = value; - scope.dispatchEvent({"type": "intensity_contrast_changed", "viewer": scope}); + setIntensityContrast(value){ + if(this.intensityContrast !== value){ + this.intensityContrast = value; + this.dispatcher.dispatchEvent({"type": "intensity_contrast_changed", "viewer": this}); } }; - this.getIntensityContrast = function(){ - return scope.intensityContrast; + getIntensityContrast(){ + return this.intensityContrast; }; - this.setIntensityBrightness = function(value){ - if(scope.intensityBrightness !== value){ - scope.intensityBrightness = value; - scope.dispatchEvent({"type": "intensity_brightness_changed", "viewer": scope}); + setIntensityBrightness(value){ + if(this.intensityBrightness !== value){ + this.intensityBrightness = value; + this.dispatcher.dispatchEvent({"type": "intensity_brightness_changed", "viewer": this}); } }; - this.getIntensityBrightness = function(){ - return scope.intensityBrightness; + getIntensityBrightness(){ + return this.intensityBrightness; }; - this.setRGBGamma = function(value){ - if(scope.rgbGamma !== value){ - scope.rgbGamma = value; - scope.dispatchEvent({"type": "rgb_gamma_changed", "viewer": scope}); + setRGBGamma(value){ + if(this.rgbGamma !== value){ + this.rgbGamma = value; + this.dispatcher.dispatchEvent({"type": "rgb_gamma_changed", "viewer": this}); } }; - this.getRGBGamma = function(){ - return scope.rgbGamma; + getRGBGamma(){ + return this.rgbGamma; }; - this.setRGBContrast = function(value){ - if(scope.rgbContrast !== value){ - scope.rgbContrast = value; - scope.dispatchEvent({"type": "rgb_contrast_changed", "viewer": scope}); + setRGBContrast(value){ + if(this.rgbContrast !== value){ + this.rgbContrast = value; + this.dispatcher.dispatchEvent({"type": "rgb_contrast_changed", "viewer": this}); } }; - this.getRGBContrast = function(){ - return scope.rgbContrast; + getRGBContrast(){ + return this.rgbContrast; }; - this.setRGBBrightness = function(value){ - if(scope.rgbBrightness !== value){ - scope.rgbBrightness = value; - scope.dispatchEvent({"type": "rgb_brightness_changed", "viewer": scope}); + setRGBBrightness(value){ + if(this.rgbBrightness !== value){ + this.rgbBrightness = value; + this.dispatcher.dispatchEvent({"type": "rgb_brightness_changed", "viewer": this}); } }; - this.getRGBBrightness = function(){ - return scope.rgbBrightness; + getRGBBrightness(){ + return this.rgbBrightness; }; - this.setMaterialTransition = function(t){ - if(scope.materialTransition !== t){ - scope.materialTransition = t; - scope.dispatchEvent({"type": "material_transition_changed", "viewer": scope}); + setMaterialTransition(t){ + if(this.materialTransition !== t){ + this.materialTransition = t; + this.dispatcher.dispatchEvent({"type": "material_transition_changed", "viewer": this}); } }; - this.getMaterialTransition = function(){ - return scope.materialTransition; + getMaterialTransition(){ + return this.materialTransition; }; - this.setWeightRGB = function(w){ - if(scope.weightRGB !== w){ - scope.weightRGB = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightRGB(w){ + if(this.weightRGB !== w){ + this.weightRGB = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightRGB = function(){ - return scope.weightRGB; + getWeightRGB(){ + return this.weightRGB; }; - this.setWeightIntensity = function(w){ - if(scope.weightIntensity !== w){ - scope.weightIntensity = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightIntensity(w){ + if(this.weightIntensity !== w){ + this.weightIntensity = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightIntensity = function(){ - return scope.weightIntensity; + getWeightIntensity(){ + return this.weightIntensity; }; - this.setWeightElevation = function(w){ - if(scope.weightElevation !== w){ - scope.weightElevation = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightElevation(w){ + if(this.weightElevation !== w){ + this.weightElevation = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightElevation = function(){ - return scope.weightElevation; + getWeightElevation(){ + return this.weightElevation; }; - this.setWeightClassification = function(w){ - if(scope.weightClassification !== w){ - scope.weightClassification = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightClassification(w){ + if(this.weightClassification !== w){ + this.weightClassification = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightClassification = function(){ - return scope.weightClassification; + getWeightClassification(){ + return this.weightClassification; }; - this.setWeightReturnNumber = function(w){ - if(scope.weightReturnNumber !== w){ - scope.weightReturnNumber = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightReturnNumber(w){ + if(this.weightReturnNumber !== w){ + this.weightReturnNumber = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightReturnNumber = function(){ - return scope.weightReturnNumber; + getWeightReturnNumber(){ + return this.weightReturnNumber; }; - this.setWeightSourceID = function(w){ - if(scope.weightSourceID !== w){ - scope.weightSourceID = w; - scope.dispatchEvent({"type": "attribute_weights_changed", "viewer": scope}); + setWeightSourceID(w){ + if(this.weightSourceID !== w){ + this.weightSourceID = w; + this.dispatcher.dispatchEvent({"type": "attribute_weights_changed", "viewer": this}); } }; - this.getWeightSourceID = function(){ - return scope.weightSourceID; + getWeightSourceID(){ + return this.weightSourceID; }; - this.setIntensityMax = function(max){ - if(scope.intensityMax !== max){ - scope.intensityMax = max; - scope.dispatchEvent({"type": "intensity_max_changed", "viewer": scope}); + setIntensityMax(max){ + if(this.intensityMax !== max){ + this.intensityMax = max; + this.dispatcher.dispatchEvent({"type": "intensity_max_changed", "viewer": this}); } }; - this.getIntensityMax = function(){ - return scope.intensityMax; + getIntensityMax(){ + return this.intensityMax; }; - this.setFreeze = function(value){ - if(scope.freeze != value){ - scope.freeze = value; - scope.dispatchEvent({"type": "freeze_changed", "viewer": scope}); + setFreeze(value){ + if(this.freeze != value){ + this.freeze = value; + this.dispatcher.dispatchEvent({"type": "freeze_changed", "viewer": this}); } }; - this.getFreeze = function(){ - return scope.freeze; + getFreeze(){ + return this.freeze; }; - this.setPointBudget = function(value){ + setPointBudget(value){ if(Potree.pointBudget != value){ Potree.pointBudget = parseInt(value); - scope.dispatchEvent({"type": "point_budget_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "point_budget_changed", "viewer": this}); } }; - this.getPointBudget = function(){ + getPointBudget(){ return Potree.pointBudget; }; - this.setClipMode = function(clipMode){ - if(scope.clipMode != clipMode){ - scope.clipMode = clipMode; - scope.dispatchEvent({"type": "clip_mode_changed", "viewer": scope}); + setClipMode(clipMode){ + if(this.clipMode != clipMode){ + this.clipMode = clipMode; + this.dispatcher.dispatchEvent({"type": "clip_mode_changed", "viewer": this}); } }; - this.getClipMode = function(){ - return scope.clipMode; + getClipMode(){ + return this.clipMode; }; - this.setDEMCollisionsEnabled = function(value){ - if(scope.useDEMCollisions !== value){ - scope.useDEMCollisions = value; - scope.dispatchEvent({"type": "use_demcollisions_changed", "viewer": scope}); + setDEMCollisionsEnabled(value){ + if(this.useDEMCollisions !== value){ + this.useDEMCollisions = value; + this.dispatcher.dispatchEvent({"type": "use_demcollisions_changed", "viewer": this}); }; }; - this.getDEMCollisionsEnabled = function(){ - return scope.useDEMCollisions; + getDEMCollisionsEnabled(){ + return this.useDEMCollisions; }; - this.setEDLEnabled = function(value){ - if(scope.useEDL != value){ - scope.useEDL = value; - scope.dispatchEvent({"type": "use_edl_changed", "viewer": scope}); + setEDLEnabled(value){ + if(this.useEDL != value){ + this.useEDL = value; + this.dispatcher.dispatchEvent({"type": "use_edl_changed", "viewer": this}); } }; - this.getEDLEnabled = function(){ - return scope.useEDL; + getEDLEnabled(){ + return this.useEDL; }; - this.setEDLRadius = function(value){ - if(scope.edlRadius !== value){ - scope.edlRadius = value; - scope.dispatchEvent({"type": "edl_radius_changed", "viewer": scope}); + setEDLRadius(value){ + if(this.edlRadius !== value){ + this.edlRadius = value; + this.dispatcher.dispatchEvent({"type": "edl_radius_changed", "viewer": this}); } }; - this.getEDLRadius = function(){ - return scope.edlRadius; + getEDLRadius(){ + return this.edlRadius; }; - this.setEDLStrength = function(value){ - if(scope.edlStrength !== value){ - scope.edlStrength = value; - scope.dispatchEvent({"type": "edl_strength_changed", "viewer": scope}); + setEDLStrength(value){ + if(this.edlStrength !== value){ + this.edlStrength = value; + this.dispatcher.dispatchEvent({"type": "edl_strength_changed", "viewer": this}); } }; - this.getEDLStrength = function(){ - return scope.edlStrength; + getEDLStrength(){ + return this.edlStrength; }; - this.setPointSize = function(value){ - if(scope.pointSize !== value){ - scope.pointSize = value; - scope.dispatchEvent({"type": "point_size_changed", "viewer": scope}); + setPointSize(value){ + if(this.pointSize !== value){ + this.pointSize = value; + this.dispatcher.dispatchEvent({"type": "point_size_changed", "viewer": this}); } }; - this.getPointSize = function(){ - return scope.pointSize; + getPointSize(){ + return this.pointSize; }; - this.setMinPointSize = function(value){ - if(scope.minPointSize !== value){ - scope.minPointSize = value; - scope.dispatchEvent({"type": "min_point_size_changed", "viewer": scope}); + setMinPointSize(value){ + if(this.minPointSize !== value){ + this.minPointSize = value; + this.dispatcher.dispatchEvent({"type": "min_point_size_changed", "viewer": this}); } } - this.getMinPointSize = function(){ - return scope.minPointSize; + getMinPointSize(){ + return this.minPointSize; } - this.setMaxPointSize = function(value){ - if(scope.maxPointSize !== value){ - scope.maxPointSize = value; - scope.dispatchEvent({"type": "max_point_size_changed", "viewer": scope}); + setMaxPointSize(value){ + if(this.maxPointSize !== value){ + this.maxPointSize = value; + this.dispatcher.dispatchEvent({"type": "max_point_size_changed", "viewer": this}); } } - this.getMaxPointSize = function(){ - return scope.maxPointSize; + getMaxPointSize(){ + return this.maxPointSize; } - this.setFOV = function(value){ - if(scope.fov !== value){ - scope.fov = value; - scope.dispatchEvent({"type": "fov_changed", "viewer": scope}); + setFOV(value){ + if(this.fov !== value){ + this.fov = value; + this.dispatcher.dispatchEvent({"type": "fov_changed", "viewer": this}); } }; - this.getFOV = function(){ - return scope.fov; + getFOV(){ + return this.fov; }; - this.setOpacity = function(value){ - if(scope.opacity !== value){ - scope.opacity = value; - scope.dispatchEvent({"type": "opacity_changed", "viewer": scope}); + setOpacity(value){ + if(this.opacity !== value){ + this.opacity = value; + this.dispatcher.dispatchEvent({"type": "opacity_changed", "viewer": this}); } }; - this.getOpacity = function(){ - return scope.opacity; + getOpacity(){ + return this.opacity; }; - this.setPointSizing = function(value){ - if(scope.sizeType !== value){ - scope.sizeType = value; + setPointSizing(value){ + if(this.sizeType !== value){ + this.sizeType = value; if(value === "Fixed"){ - scope.pointSizeType = Potree.PointSizeType.FIXED; + this.pointSizeType = Potree.PointSizeType.FIXED; }else if(value === "Attenuated"){ - scope.pointSizeType = Potree.PointSizeType.ATTENUATED; + this.pointSizeType = Potree.PointSizeType.ATTENUATED; }else if(value === "Adaptive"){ - scope.pointSizeType = Potree.PointSizeType.ADAPTIVE; + this.pointSizeType = Potree.PointSizeType.ADAPTIVE; } - scope.dispatchEvent({"type": "point_sizing_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "point_sizing_changed", "viewer": this}); } }; - this.getPointSizing = function(){ - return scope.sizeType; + getPointSizing(){ + return this.sizeType; }; - this.setQuality = function(value){ - var oldQuality = scope.quality; + setQuality(value){ + var oldQuality = this.quality; if(value == "Interpolation" && !Potree.Features.SHADER_INTERPOLATION.isSupported()){ - scope.quality = "Squares"; + this.quality = "Squares"; }else if(value == "Splats" && !Potree.Features.SHADER_SPLATS.isSupported()){ - scope.quality = "Squares"; + this.quality = "Squares"; }else{ - scope.quality = value; + this.quality = value; } - if(oldQuality !== scope.quality){ - scope.dispatchEvent({"type": "quality_changed", "viewer": scope}); + if(oldQuality !== this.quality){ + this.dispatcher.dispatchEvent({"type": "quality_changed", "viewer": this}); } }; - this.getQuality = function(){ - return scope.quality; + getQuality(){ + return this.quality; }; - this.disableAnnotations = function(){ - for(var i = 0; i < scope.annotations.length; i++){ - var annotation = scope.annotations[i]; + disableAnnotations(){ + for(var i = 0; i < this.annotations.length; i++){ + var annotation = this.annotations[i]; annotation.domElement.style.pointerEvents = "none"; }; }; - this.enableAnnotations = function(){ - for(var i = 0; i < scope.annotations.length; i++){ - var annotation = scope.annotations[i]; + enableAnnotations(){ + for(var i = 0; i < this.annotations.length; i++){ + var annotation = this.annotations[i]; annotation.domElement.style.pointerEvents = "auto"; }; }; - this.setClassificationVisibility = function(key, value){ + setClassificationVisibility(key, value){ var changed = false; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; var newClass = pointcloud.material.classification; var oldValue = newClass[key].w; newClass[key].w = value ? 1 : 0; @@ -12147,35 +12192,35 @@ Potree.Viewer = function(domElement, args){ } if(changed){ - scope.dispatchEvent({"type": "classification_visibility_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "classification_visibility_changed", "viewer": this}); } }; - this.setMaterial = function(value){ - if(scope.pointColorType !== scope.toMaterialID(value)){ - scope.pointColorType = scope.toMaterialID(value); + setMaterial(value){ + if(this.pointColorType !== this.toMaterialID(value)){ + this.pointColorType = this.toMaterialID(value); - scope.dispatchEvent({"type": "material_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "material_changed", "viewer": this}); } }; - this.setMaterialID = function(value){ - if(scope.pointColorType !== value){ - scope.pointColorType = value; + setMaterialID(value){ + if(this.pointColorType !== value){ + this.pointColorType = value; - scope.dispatchEvent({"type": "material_changed", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "material_changed", "viewer": this}); } } - this.getMaterial = function(){ - return scope.pointColorType; + getMaterial(){ + return this.pointColorType; }; - this.getMaterialName = function(){ - return scope.toMaterialName(scope.pointColorType); + getMaterialName(){ + return this.toMaterialName(this.pointColorType); }; - this.toMaterialID = function(materialName){ + toMaterialID(materialName){ if(materialName === "RGB"){ return Potree.PointColorType.RGB; }else if(materialName === "Color"){ @@ -12207,7 +12252,7 @@ Potree.Viewer = function(domElement, args){ } }; - this.toMaterialName = function(materialID){ + toMaterialName(materialID){ if(materialID === Potree.PointColorType.RGB){ return "RGB"; }else if(materialID === Potree.PointColorType.COLOR){ @@ -12239,8 +12284,8 @@ Potree.Viewer = function(domElement, args){ } }; - this.zoomTo = function(node, factor){ - scope.camera.zoomTo(node, factor); + zoomTo(node, factor){ + this.camera.zoomTo(node, factor); var bs; if(node.boundingSphere){ @@ -12253,31 +12298,30 @@ Potree.Viewer = function(domElement, args){ bs = bs.clone().applyMatrix4(node.matrixWorld); - scope.orbitControls.target.copy(bs.center); + this.orbitControls.target.copy(bs.center); - scope.dispatchEvent({"type": "zoom_to", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "zoom_to", "viewer": this}); }; - this.showAbout = function(){ + showAbout(){ $(function() { $( "#about-panel" ).dialog(); }); }; - this.getBoundingBox = function(pointclouds){ - pointclouds = pointclouds || scope.pointclouds; + getBoundingBox(pointclouds){ + pointclouds = pointclouds || this.scene.pointclouds; var box = new THREE.Box3(); - scope.scenePointCloud.updateMatrixWorld(true); - scope.referenceFrame.updateMatrixWorld(true); + this.scene.scenePointCloud.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; pointcloud.updateMatrixWorld(true); - //var boxWorld = pointcloud.boundingBox.clone().applyMatrix4(pointcloud.matrixWorld); var boxWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld) box.union(boxWorld); } @@ -12285,16 +12329,16 @@ Potree.Viewer = function(domElement, args){ return box; }; - this.getBoundingBoxGeo = function(pointclouds){ - pointclouds = pointclouds || scope.pointclouds; + getBoundingBoxGeo(pointclouds){ + pointclouds = pointclouds || this.scene.pointclouds; var box = new THREE.Box3(); - scope.scenePointCloud.updateMatrixWorld(true); - scope.referenceFrame.updateMatrixWorld(true); + this.scene.scenePointCloud.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; pointcloud.updateMatrixWorld(true); @@ -12305,94 +12349,92 @@ Potree.Viewer = function(domElement, args){ return box; }; - this.fitToScreen = function(){ - var box = this.getBoundingBox(scope.pointclouds); + fitToScreen(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - //scope.camera.zoomTo(node, 1); - scope.zoomTo(node, 1); + //this.camera.zoomTo(node, 1); + this.zoomTo(node, 1); }; - this.setTopView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setTopView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(0, 1, 0); - scope.camera.rotation.set(-Math.PI / 2, 0, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(0, 1, 0); + this.camera.rotation.set(-Math.PI / 2, 0, 0); + this.camera.zoomTo(node, 1); }; - this.setFrontView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setFrontView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(0, 0, 1); - scope.camera.rotation.set(0, 0, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(0, 0, 1); + this.camera.rotation.set(0, 0, 0); + this.camera.zoomTo(node, 1); }; - this.setLeftView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setLeftView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(-1, 0, 0); - scope.camera.rotation.set(0, -Math.PI / 2, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(-1, 0, 0); + this.camera.rotation.set(0, -Math.PI / 2, 0); + this.camera.zoomTo(node, 1); }; - this.setRightView = function(){ - var box = this.getBoundingBox(scope.pointclouds); + setRightView(){ + var box = this.getBoundingBox(this.scene.pointclouds); - if(scope.transformationTool.targets.length > 0){ - box = scope.transformationTool.getBoundingBox(); + if(this.transformationTool.targets.length > 0){ + box = this.transformationTool.getBoundingBox(); } var node = new THREE.Object3D(); node.boundingBox = box; - scope.camera.position.set(1, 0, 0); - scope.camera.rotation.set(0, Math.PI / 2, 0); - scope.camera.zoomTo(node, 1); + this.camera.position.set(1, 0, 0); + this.camera.rotation.set(0, Math.PI / 2, 0); + this.camera.zoomTo(node, 1); }; - this.flipYZ = function(){ - scope.isFlipYZ = !scope.isFlipYZ; + flipYZ(){ + this.isFlipYZ = !this.isFlipYZ; - scope.referenceFrame.matrix.copy(new THREE.Matrix4()); - if(scope.isFlipYZ){ - scope.referenceFrame.applyMatrix(new THREE.Matrix4().set( + if(this.isFlipYZ){ + this.scene.referenceFrame.matrix.copy(new THREE.Matrix4().set( 1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1 )); - }else{ - scope.referenceFrame.applyMatrix(new THREE.Matrix4().set( + this.scene.referenceFrame.matrix.copy(new THREE.Matrix4().set( 1,0,0,0, 0,1,0,0, 0,0,1,0, @@ -12400,162 +12442,184 @@ Potree.Viewer = function(domElement, args){ )); } - scope.referenceFrame.updateMatrixWorld(true); - var box = scope.getBoundingBox(); - scope.referenceFrame.position.copy(box.getCenter()).multiplyScalar(-1); - scope.referenceFrame.position.y = -box.min.y; - scope.referenceFrame.updateMatrixWorld(true); + this.scene.referenceFrame.updateMatrixWorld(true); + var box = this.getBoundingBox(); + //this.scene.referenceFrame.position.copy(box.getCenter()).multiplyScalar(-1); + //this.scene.referenceFrame.position.y = -box.min.y; + this.scene.referenceFrame.updateMatrixWorld(true); - scope.updateHeightRange(); + this.updateHeightRange(); - //scope.referenceFrame.updateMatrixWorld(true); - //scope.pointclouds[0].updateMatrixWorld(); - //var sg = scope.pointclouds[0].boundingSphere.clone().applyMatrix4(scope.pointclouds[0].matrixWorld); - //scope.referenceFrame.position.copy(sg.center).multiplyScalar(-1); - //scope.referenceFrame.updateMatrixWorld(true); - //scope.referenceFrame.position.y -= scope.pointclouds[0].getWorldPosition().y; - //scope.referenceFrame.updateMatrixWorld(true); + //this.isFlipYZ = !this.isFlipYZ; + // + //this.scene.referenceFrame.matrix.copy(new THREE.Matrix4()); + //if(this.isFlipYZ){ + // this.scene.referenceFrame.applyMatrix(new THREE.Matrix4().set( + // 1,0,0,0, + // 0,0,1,0, + // 0,-1,0,0, + // 0,0,0,1 + // )); + // + //}else{ + // this.scene.referenceFrame.applyMatrix(new THREE.Matrix4().set( + // 1,0,0,0, + // 0,1,0,0, + // 0,0,1,0, + // 0,0,0,1 + // )); + //} + // + //this.scene.referenceFrame.updateMatrixWorld(true); + //var box = this.getBoundingBox(); + //this.scene.referenceFrame.position.copy(box.getCenter()).multiplyScalar(-1); + //this.scene.referenceFrame.position.y = -box.min.y; + //this.scene.referenceFrame.updateMatrixWorld(true); + // + //this.updateHeightRange(); } - this.updateHeightRange = function(){ - var bbWorld = scope.getBoundingBox(); - scope.setHeightRange(bbWorld.min.y, bbWorld.max.y); + updateHeightRange(){ + var bbWorld = this.getBoundingBox(); + this.setHeightRange(bbWorld.min.y, bbWorld.max.y); }; - this.useEarthControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useEarthControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.earthControls; - scope.controls.enabled = true; + this.controls = this.earthControls; + this.controls.enabled = true; } - this.useGeoControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useGeoControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.geoControls; - scope.controls.enabled = true; + this.controls = this.geoControls; + this.controls.enabled = true; - //scope.controls.moveSpeed = scope.pointclouds[0].boundingSphere.radius / 6; + //this.controls.moveSpeed = this.scene.pointclouds[0].boundingSphere.radius / 6; } - this.useFPSControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useFPSControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.fpControls; - scope.controls.enabled = true; + this.controls = this.fpControls; + this.controls.enabled = true; - //scope.controls.moveSpeed = scope.pointclouds[0].boundingSphere.radius / 6; + //this.controls.moveSpeed = this.scene.pointclouds[0].boundingSphere.radius / 6; } - this.useOrbitControls = function(){ - if(scope.controls){ - scope.controls.enabled = false; + useOrbitControls(){ + if(this.controls){ + this.controls.enabled = false; } - scope.controls = scope.orbitControls; - scope.controls.enabled = true; + this.controls = this.orbitControls; + this.controls.enabled = true; - if(scope.pointclouds.length > 0){ - scope.controls.target.copy(scope.pointclouds[0].boundingSphere.center.clone().applyMatrix4(scope.pointclouds[0].matrixWorld)); + if(this.scene.pointclouds.length > 0){ + this.controls.target.copy(this.scene.pointclouds[0].boundingSphere.center.clone().applyMatrix4(this.scene.pointclouds[0].matrixWorld)); } }; - this.addAnnotation = function(position, args){ + addAnnotation(position, args){ var cameraPosition = args.cameraPosition; var cameraTarget = args.cameraTarget || position; var description = args.description || null; var title = args.title || null; + var actions = args.actions || null; - var annotation = new Potree.Annotation(scope, { + var annotation = new Potree.Annotation(this, { "position": position, "cameraPosition": cameraPosition, "cameraTarget": cameraTarget, "title": title, - "description": description + "description": description, + "actions": actions }); - scope.annotations.push(annotation); - scope.renderArea.appendChild(annotation.domElement); + this.annotations.push(annotation); + this.renderArea.appendChild(annotation.domElement); - scope.dispatchEvent({"type": "annotation_added", "viewer": scope}); + this.dispatcher.dispatchEvent({"type": "annotation_added", "viewer": this}); return annotation; } - this.getAnnotations = function(){ - return scope.annotations; + getAnnotations(){ + return this.annotations; }; - this.loadSettingsFromURL = function(){ + loadSettingsFromURL(){ if(Potree.utils.getParameterByName("pointSize")){ - scope.setPointSize(parseFloat(Potree.utils.getParameterByName("pointSize"))); + this.setPointSize(parseFloat(Potree.utils.getParameterByName("pointSize"))); } if(Potree.utils.getParameterByName("FOV")){ - scope.setFOV(parseFloat(Potree.utils.getParameterByName("FOV"))); + this.setFOV(parseFloat(Potree.utils.getParameterByName("FOV"))); } if(Potree.utils.getParameterByName("opacity")){ - scope.setOpacity(parseFloat(Potree.utils.getParameterByName("opacity"))); + this.setOpacity(parseFloat(Potree.utils.getParameterByName("opacity"))); } if(Potree.utils.getParameterByName("edlEnabled")){ var enabled = Potree.utils.getParameterByName("edlEnabled") === "true"; - scope.setEDLEnabled(enabled); + this.setEDLEnabled(enabled); } if(Potree.utils.getParameterByName("edlRadius")){ - scope.setEDLRadius(parseFloat(Potree.utils.getParameterByName("edlRadius"))); + this.setEDLRadius(parseFloat(Potree.utils.getParameterByName("edlRadius"))); } if(Potree.utils.getParameterByName("edlStrength")){ - scope.setEDLStrength(parseFloat(Potree.utils.getParameterByName("edlStrength"))); + this.setEDLStrength(parseFloat(Potree.utils.getParameterByName("edlStrength"))); } if(Potree.utils.getParameterByName("clipMode")){ var clipMode = Potree.utils.getParameterByName("clipMode"); if(clipMode === "HIGHLIGHT_INSIDE"){ - scope.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); + this.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); }else if(clipMode === "CLIP_OUTSIDE"){ - scope.setClipMode(Potree.ClipMode.CLIP_OUTSIDE); + this.setClipMode(Potree.ClipMode.CLIP_OUTSIDE); }else if(clipMode === "DISABLED"){ - scope.setClipMode(Potree.ClipMode.DISABLED); + this.setClipMode(Potree.ClipMode.DISABLED); } } if(Potree.utils.getParameterByName("pointBudget")){ - scope.setPointBudget(parseFloat(Potree.utils.getParameterByName("pointBudget"))); + this.setPointBudget(parseFloat(Potree.utils.getParameterByName("pointBudget"))); } if(Potree.utils.getParameterByName("showBoundingBox")){ var enabled = Potree.utils.getParameterByName("showBoundingBox") === "true"; if(enabled){ - scope.setShowBoundingBox(true); + this.setShowBoundingBox(true); }else{ - scope.setShowBoundingBox(false); + this.setShowBoundingBox(false); } } if(Potree.utils.getParameterByName("material")){ var material = Potree.utils.getParameterByName("material"); - scope.setMaterial(material); + this.setMaterial(material); } if(Potree.utils.getParameterByName("pointSizing")){ var sizing = Potree.utils.getParameterByName("pointSizing"); - scope.setPointSizing(sizing); + this.setPointSizing(sizing); } if(Potree.utils.getParameterByName("quality")){ var quality = Potree.utils.getParameterByName("quality"); - scope.setQuality(quality); + this.setQuality(quality); } }; @@ -12573,7 +12637,7 @@ Potree.Viewer = function(domElement, args){ // Viewer Internals //------------------------------------------------------------------------------------ - this.toggleSidebar = function(){ + toggleSidebar(){ var renderArea = $('#potree_render_area'); var sidebar = $('#potree_sidebar_container'); @@ -12586,13 +12650,13 @@ Potree.Viewer = function(domElement, args){ } }; - this.toggleMap = function(){ + toggleMap(){ var map = $('#potree_map'); map.toggle(100); }; - this.loadGUI = function(){ + loadGUI(){ var sidebarContainer = $('#potree_sidebar_container'); sidebarContainer.load(new URL(Potree.scriptPath + "/sidebar.html").href); sidebarContainer.css("width", "300px"); @@ -12600,26 +12664,23 @@ Potree.Viewer = function(domElement, args){ var imgMenuToggle = document.createElement("img"); imgMenuToggle.src = new URL(Potree.resourcePath + "/icons/menu_button.svg").href; - imgMenuToggle.onclick = scope.toggleSidebar; + imgMenuToggle.onclick = this.toggleSidebar; imgMenuToggle.classList.add("potree_menu_toggle"); - //viewer.renderArea.appendChild(imgMenuToggle); var imgMapToggle = document.createElement("img"); imgMapToggle.src = new URL(Potree.resourcePath + "/icons/map_icon.png").href; imgMapToggle.style.display = "none"; - imgMapToggle.onclick = scope.toggleMap; + imgMapToggle.onclick = this.toggleMap; imgMapToggle.id = "potree_map_toggle"; - //viewer.renderArea.appendChild(imgMapToggle); viewer.renderArea.insertBefore(imgMapToggle, viewer.renderArea.children[0]); viewer.renderArea.insertBefore(imgMenuToggle, viewer.renderArea.children[0]); - //var elProfile = $('
'); var elProfile = $('
').load(new URL(Potree.scriptPath + "/profile.html").href, function(){ $('#potree_render_area').append(elProfile.children()); - scope._2dprofile = new Potree.Viewer.Profile(scope, document.getElementById("profile_draw_container")); - }); + this._2dprofile = new Potree.Viewer.Profile(this, document.getElementById("profile_draw_container")); + }.bind(this)); i18n.init({ lng: 'en', @@ -12633,24 +12694,24 @@ Potree.Viewer = function(domElement, args){ }); } - this.setLanguage = function(lang) { + setLanguage(lang){ i18n.setLng(lang); $("body").i18n(); console.log("ici"); } - this.createControls = function(){ + createControls(){ var demCollisionHandler = function(event){ - if(!scope.useDEMCollisions){ + if(!this.useDEMCollisions){ return } var demHeight = null; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; pointcloud.generateDEM = true; var height = pointcloud.getDEMHeight(event.newPosition); @@ -12671,60 +12732,60 @@ Potree.Viewer = function(domElement, args){ }; { // create FIRST PERSON CONTROLS - scope.fpControls = new THREE.FirstPersonControls(scope.camera, scope.renderer.domElement); - scope.fpControls.enabled = false; - scope.fpControls.addEventListener("start", scope.disableAnnotations); - scope.fpControls.addEventListener("end", scope.enableAnnotations); - scope.fpControls.addEventListener("proposeTransform", demCollisionHandler); - scope.fpControls.addEventListener("move_speed_changed", function(event){ - scope.setMoveSpeed(scope.fpControls.moveSpeed); - }); + this.fpControls = new THREE.FirstPersonControls(this.camera, this.renderer.domElement); + this.fpControls.enabled = false; + this.fpControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.fpControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.fpControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); + this.fpControls.addEventListener("move_speed_changed", function(event){ + this.setMoveSpeed(this.fpControls.moveSpeed); + }.bind(this)); } { // create GEO CONTROLS - scope.geoControls = new Potree.GeoControls(scope.camera, scope.renderer.domElement); - scope.geoControls.enabled = false; - scope.geoControls.addEventListener("start", scope.disableAnnotations); - scope.geoControls.addEventListener("end", scope.enableAnnotations); - scope.geoControls.addEventListener("proposeTransform", demCollisionHandler); - scope.geoControls.addEventListener("move_speed_changed", function(event){ - scope.setMoveSpeed(scope.geoControls.moveSpeed); - }); + this.geoControls = new Potree.GeoControls(this.camera, this.renderer.domElement); + this.geoControls.enabled = false; + this.geoControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.geoControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.geoControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); + this.geoControls.addEventListener("move_speed_changed", function(event){ + this.setMoveSpeed(this.geoControls.moveSpeed); + }.bind(this)); } { // create ORBIT CONTROLS - scope.orbitControls = new Potree.OrbitControls(scope.camera, scope.renderer.domElement); - scope.orbitControls.enabled = false; - scope.orbitControls.addEventListener("start", scope.disableAnnotations); - scope.orbitControls.addEventListener("end", scope.enableAnnotations); - scope.orbitControls.addEventListener("proposeTransform", demCollisionHandler); - scope.renderArea.addEventListener("dblclick", function(event){ - if(scope.pointclouds.length === 0){ + this.orbitControls = new Potree.OrbitControls(this.camera, this.renderer.domElement); + this.orbitControls.enabled = false; + this.orbitControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.orbitControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.orbitControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); + this.renderArea.addEventListener("dblclick", function(event){ + if(this.scene.pointclouds.length === 0){ return; } event.preventDefault(); - var rect = scope.renderArea.getBoundingClientRect(); + var rect = this.renderArea.getBoundingClientRect(); var mouse = { - x: ( (event.clientX - rect.left) / scope.renderArea.clientWidth ) * 2 - 1, - y: - ( (event.clientY - rect.top) / scope.renderArea.clientHeight ) * 2 + 1 + x: ( (event.clientX - rect.left) / this.renderArea.clientWidth ) * 2 - 1, + y: - ( (event.clientY - rect.top) / this.renderArea.clientHeight ) * 2 + 1 }; var pointcloud = null; var distance = Number.POSITIVE_INFINITY; var I = null; - for(var i = 0; i < scope.pointclouds.length; i++){ - intersection = getMousePointCloudIntersection(mouse, scope.camera, scope.renderer, [scope.pointclouds[i]]); + for(var i = 0; i < this.scene.pointclouds.length; i++){ + let intersection = getMousePointCloudIntersection(mouse, this.camera, this.renderer, [this.scene.pointclouds[i]]); if(!intersection){ continue; } - var tDist = scope.camera.position.distanceTo(intersection); + var tDist = this.camera.position.distanceTo(intersection); if(tDist < distance){ - pointcloud = scope.pointclouds[i]; + pointcloud = this.scene.pointclouds[i]; distance = tDist; I = intersection; } @@ -12733,25 +12794,25 @@ Potree.Viewer = function(domElement, args){ if(I != null){ var targetRadius = 0; - if(!scope.jumpDistance){ - var camTargetDistance = scope.camera.position.distanceTo(scope.orbitControls.target); + if(!this.jumpDistance){ + var camTargetDistance = this.camera.position.distanceTo(this.orbitControls.target); var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 ); - vector.unproject(scope.camera); + vector.unproject(this.camera); - var direction = vector.sub(scope.camera.position).normalize(); - var ray = new THREE.Ray(scope.camera.position, direction); + var direction = vector.sub(this.camera.position).normalize(); + var ray = new THREE.Ray(this.camera.position, direction); var nodes = pointcloud.nodesOnRay(pointcloud.visibleNodes, ray); var lastNode = nodes[nodes.length - 1]; var radius = lastNode.getBoundingSphere().radius; var targetRadius = Math.min(camTargetDistance, radius); - var targetRadius = Math.max(scope.minimumJumpDistance, targetRadius); + var targetRadius = Math.max(this.minimumJumpDistance, targetRadius); }else{ - targetRadius = scope.jumpDistance; + targetRadius = this.jumpDistance; } - var d = scope.camera.getWorldDirection().multiplyScalar(-1); + var d = this.camera.getWorldDirection().multiplyScalar(-1); var cameraTargetPosition = new THREE.Vector3().addVectors(I, d.multiplyScalar(targetRadius)); var controlsTargetPosition = I; @@ -12759,125 +12820,76 @@ Potree.Viewer = function(domElement, args){ var easing = TWEEN.Easing.Quartic.Out; - scope.controls.enabled = false; + this.controls.enabled = false; // animate position - var tween = new TWEEN.Tween(scope.camera.position).to(cameraTargetPosition, animationDuration); + var tween = new TWEEN.Tween(this.camera.position).to(cameraTargetPosition, animationDuration); tween.easing(easing); tween.start(); // animate target - var tween = new TWEEN.Tween(scope.orbitControls.target).to(I, animationDuration); + var tween = new TWEEN.Tween(this.orbitControls.target).to(I, animationDuration); tween.easing(easing); tween.onComplete(function(){ - scope.controls.enabled = true; - scope.fpControls.moveSpeed = radius / 2; - scope.geoControls.moveSpeed = radius / 2; - }); + this.controls.enabled = true; + this.fpControls.moveSpeed = radius / 2; + this.geoControls.moveSpeed = radius / 2; + }.bind(this)); tween.start(); } - }); + }.bind(this)); } { // create EARTH CONTROLS - scope.earthControls = new THREE.EarthControls(scope.camera, scope.renderer, scope.scenePointCloud); - scope.earthControls.enabled = false; - scope.earthControls.addEventListener("start", scope.disableAnnotations); - scope.earthControls.addEventListener("end", scope.enableAnnotations); - scope.earthControls.addEventListener("proposeTransform", demCollisionHandler); + this.earthControls = new THREE.EarthControls(this.camera, this.renderer, this.scene.scenePointCloud); + this.earthControls.enabled = false; + this.earthControls.addEventListener("start", this.disableAnnotations.bind(this)); + this.earthControls.addEventListener("end", this.enableAnnotations.bind(this)); + this.earthControls.addEventListener("proposeTransform", demCollisionHandler.bind(this)); } }; - this.initThree = function(){ - var width = scope.renderArea.clientWidth; - var height = scope.renderArea.clientHeight; - var aspect = width / height; - var near = 0.1; - var far = 1000*1000; + initThree(){ + let width = this.renderArea.clientWidth; + let height = this.renderArea.clientHeight; + let aspect = width / height; + let near = 0.1; + let far = 1000*1000; + + this.camera = new THREE.PerspectiveCamera(this.fov, aspect, near, far); + this.cameraBG = new THREE.Camera(); + this.camera.rotation.order = 'ZYX'; + + - scope.scene = new THREE.Scene(); - scope.scenePointCloud = new THREE.Scene(); - scope.sceneBG = new THREE.Scene(); + this.renderer = new THREE.WebGLRenderer(); + this.renderer.setSize(width, height); + this.renderer.autoClear = false; + this.renderArea.appendChild(this.renderer.domElement); + this.renderer.domElement.tabIndex = "2222"; + this.renderer.domElement.addEventListener("mousedown", + function(){this.renderer.domElement.focus();}.bind(this)); - scope.camera = new THREE.PerspectiveCamera(scope.fov, aspect, near, far); - //camera = new THREE.OrthographicCamera(-50, 50, 50, -50, 1, 100000); - scope.cameraBG = new THREE.Camera(); - scope.camera.rotation.order = 'ZYX'; - - scope.referenceFrame = new THREE.Object3D(); - scope.scenePointCloud.add(scope.referenceFrame); - - scope.renderer = new THREE.WebGLRenderer(); - scope.renderer.setSize(width, height); - scope.renderer.autoClear = false; - scope.renderArea.appendChild(scope.renderer.domElement); - scope.renderer.domElement.tabIndex = "2222"; - scope.renderer.domElement.addEventListener("mousedown", function(){scope.renderer.domElement.focus();}); - - skybox = Potree.utils.loadSkybox(new URL(Potree.resourcePath + "/textures/skybox/").href); + this.skybox = Potree.utils.loadSkybox(new URL(Potree.resourcePath + "/textures/skybox/").href); // camera and controls - scope.camera.position.set(-304, 372, 318); - scope.camera.rotation.y = -Math.PI / 4; - scope.camera.rotation.x = -Math.PI / 6; + this.camera.position.set(-304, 372, 318); + this.camera.rotation.y = -Math.PI / 4; + this.camera.rotation.x = -Math.PI / 6; this.createControls(); - //scope.useEarthControls(); - // enable frag_depth extension for the interpolation shader, if available - scope.renderer.context.getExtension("EXT_frag_depth"); + this.renderer.context.getExtension("EXT_frag_depth"); - //this.addPointCloud(pointcloudPath); - - var grid = Potree.utils.createGrid(5, 5, 2); - scope.scene.add(grid); - - scope.measuringTool = new Potree.MeasuringTool(scope.scenePointCloud, scope.camera, scope.renderer, scope.toGeo); - scope.profileTool = new Potree.ProfileTool(scope.scenePointCloud, scope.camera, scope.renderer); - scope.transformationTool = new Potree.TransformationTool(scope.scenePointCloud, scope.camera, scope.renderer); - scope.volumeTool = new Potree.VolumeTool(scope.scenePointCloud, scope.camera, scope.renderer, scope.transformationTool); - - scope.profileTool.addEventListener("profile_added", function(profileEvent){ - - //var poSelect = document.getElementById("profile_selection"); - //var po = document.createElement("option"); - //po.innerHTML = "profile " + scope.profileTool.profiles.length; - //poSelect.appendChild(po); - - - var profileButton = document.createElement("button"); - profileButton.type = "button"; - profileButton.classList.add("btn"); - profileButton.classList.add("btn-primary"); - profileButton.id = "btn_rofile_" + scope.profileTool.profiles.length; - //profileButton.style.width = "100%"; - profileButton.value = "profile " + scope.profileTool.profiles.length; - profileButton.innerHTML = "profile " + scope.profileTool.profiles.length; - - //type="button" class="btn btn-primary" - - profileButton.onclick = function(clickEvent){ - scope.profileTool.draw( - profileEvent.profile, - $("#profile_draw_container")[0], - scope.toGeo); - profileEvent.profile.addEventListener("marker_moved", function(){ - scope.profileTool.draw( - profileEvent.profile, - $("#profile_draw_container")[0], - scope.toGeo); - }); - profileEvent.profile.addEventListener("width_changed", function(){ - scope.profileTool.draw( - profileEvent.profile, - $("#profile_draw_container")[0], - scope.toGeo); - }); - }; - }); + let grid = Potree.utils.createGrid(5, 5, 2); + this.scene.scene.add(grid); + this.measuringTool = new Potree.MeasuringTool(this.scene.scenePointCloud, this.camera, this.renderer); + this.profileTool = new Potree.ProfileTool(this.scene.scenePointCloud, this.camera, this.renderer); + this.transformationTool = new Potree.TransformationTool(this.scene.scenePointCloud, this.camera, this.renderer); + this.volumeTool = new Potree.VolumeTool(this.scene.scenePointCloud, this.camera, this.renderer, this.transformationTool); // background // var texture = THREE.ImageUtils.loadTexture( Potree.resourcePath + '/textures/background.gif' ); @@ -12892,56 +12904,52 @@ Potree.Viewer = function(domElement, args){ map: texture }) ); - //bg.position.z = -1; bg.material.depthTest = false; bg.material.depthWrite = false; - scope.sceneBG.add(bg); + this.scene.sceneBG.add(bg); + + let onKeyDown = function(event){ + //console.log(event.keyCode); + + if(event.keyCode === 69){ + // e pressed + this.transformationTool.translate(); + }else if(event.keyCode === 82){ + // r pressed + this.transformationTool.scale(); + }else if(event.keyCode === 84){ + // t pressed + this.transformationTool.rotate(); + } + }.bind(this); window.addEventListener( 'keydown', onKeyDown, false ); - scope.directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 ); - scope.directionalLight.position.set( 10, 10, 10 ); - scope.directionalLight.lookAt( new THREE.Vector3(0, 0, 0)); - scope.scenePointCloud.add( scope.directionalLight ); + this.directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 ); + this.directionalLight.position.set( 10, 10, 10 ); + this.directionalLight.lookAt( new THREE.Vector3(0, 0, 0)); + this.scene.scenePointCloud.add( this.directionalLight ); var light = new THREE.AmbientLight( 0x555555 ); // soft white light - scope.scenePointCloud.add( light ); + this.scene.scenePointCloud.add( light ); } - function onKeyDown(event){ - //console.log(event.keyCode); - - if(event.keyCode === 69){ - // e pressed - - scope.transformationTool.translate(); - }else if(event.keyCode === 82){ - // r pressed - - scope.transformationTool.scale(); - }else if(event.keyCode === 84){ - // r pressed - - scope.transformationTool.rotate(); - } - }; - - this.update = function(delta, timestamp){ + update(delta, timestamp){ Potree.pointLoadLimit = Potree.pointBudget * 2; - scope.directionalLight.position.copy(scope.camera.position); - scope.directionalLight.lookAt(new THREE.Vector3().addVectors(scope.camera.position, scope.camera.getWorldDirection())); + this.directionalLight.position.copy(this.camera.position); + this.directionalLight.lookAt(new THREE.Vector3().addVectors(this.camera.position, this.camera.getWorldDirection())); var visibleNodes = 0; var visiblePoints = 0; var progress = 0; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; + for(var i = 0; i < this.scene.pointclouds.length; i++){ + var pointcloud = this.scene.pointclouds[i]; var bbWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld); - if(!scope.intensityMax){ + if(!this.intensityMax){ var root = pointcloud.pcoGeometry.root; if(root != null && root.loaded){ var attributes = pointcloud.pcoGeometry.root.geometry.attributes; @@ -12958,46 +12966,46 @@ Potree.Viewer = function(domElement, args){ var cap = ordered[capIndex]; if(cap <= 1){ - scope.intensityMax = 1; + this.intensityMax = 1; }else if(cap <= 256){ - scope.intensityMax = 255; + this.intensityMax = 255; }else{ - scope.intensityMax = cap; + this.intensityMax = cap; } } } } - //if(scope.heightMin === null){ - // scope.setHeightRange(bbWorld.min.y, bbWorld.max.y); + //if(this.heightMin === null){ + // this.setHeightRange(bbWorld.min.y, bbWorld.max.y); //} - pointcloud.material.clipMode = scope.clipMode; - pointcloud.material.heightMin = scope.heightMin; - pointcloud.material.heightMax = scope.heightMax; + pointcloud.material.clipMode = this.clipMode; + pointcloud.material.heightMin = this.heightMin; + pointcloud.material.heightMax = this.heightMax; //pointcloud.material.intensityMin = 0; - //pointcloud.material.intensityMax = scope.intensityMax; - pointcloud.material.uniforms.intensityRange.value = scope.getIntensityRange(); - pointcloud.material.uniforms.intensityGamma.value = scope.getIntensityGamma(); - pointcloud.material.uniforms.intensityContrast.value = scope.getIntensityContrast(); - pointcloud.material.uniforms.intensityBrightness.value = scope.getIntensityBrightness(); - pointcloud.material.uniforms.rgbGamma.value = scope.getRGBGamma(); - pointcloud.material.uniforms.rgbContrast.value = scope.getRGBContrast(); - pointcloud.material.uniforms.rgbBrightness.value = scope.getRGBBrightness(); - pointcloud.showBoundingBox = scope.showBoundingBox; - pointcloud.generateDEM = scope.useDEMCollisions; - pointcloud.minimumNodePixelSize = scope.minNodeSize; - pointcloud.material.uniforms.transition.value = scope.materialTransition; + //pointcloud.material.intensityMax = this.intensityMax; + pointcloud.material.uniforms.intensityRange.value = this.getIntensityRange(); + pointcloud.material.uniforms.intensityGamma.value = this.getIntensityGamma(); + pointcloud.material.uniforms.intensityContrast.value = this.getIntensityContrast(); + pointcloud.material.uniforms.intensityBrightness.value = this.getIntensityBrightness(); + pointcloud.material.uniforms.rgbGamma.value = this.getRGBGamma(); + pointcloud.material.uniforms.rgbContrast.value = this.getRGBContrast(); + pointcloud.material.uniforms.rgbBrightness.value = this.getRGBBrightness(); + pointcloud.showBoundingBox = this.showBoundingBox; + pointcloud.generateDEM = this.useDEMCollisions; + pointcloud.minimumNodePixelSize = this.minNodeSize; + pointcloud.material.uniforms.transition.value = this.materialTransition; - pointcloud.material.uniforms.wRGB.value = scope.getWeightRGB(); - pointcloud.material.uniforms.wIntensity.value = scope.getWeightIntensity(); - pointcloud.material.uniforms.wElevation.value = scope.getWeightElevation(); - pointcloud.material.uniforms.wClassification.value = scope.getWeightClassification(); - pointcloud.material.uniforms.wReturnNumber.value = scope.getWeightReturnNumber(); - pointcloud.material.uniforms.wSourceID.value = scope.getWeightSourceID(); + pointcloud.material.uniforms.wRGB.value = this.getWeightRGB(); + pointcloud.material.uniforms.wIntensity.value = this.getWeightIntensity(); + pointcloud.material.uniforms.wElevation.value = this.getWeightElevation(); + pointcloud.material.uniforms.wClassification.value = this.getWeightClassification(); + pointcloud.material.uniforms.wReturnNumber.value = this.getWeightReturnNumber(); + pointcloud.material.uniforms.wSourceID.value = this.getWeightSourceID(); - //if(!scope.freeze){ - // pointcloud.update(scope.camera, scope.renderer); + //if(!this.freeze){ + // pointcloud.update(this.camera, this.renderer); //} visibleNodes += pointcloud.numVisibleNodes; @@ -13006,14 +13014,14 @@ Potree.Viewer = function(domElement, args){ progress += pointcloud.progress; } - if(!scope.freeze){ - var result = Potree.updatePointClouds(scope.pointclouds, scope.camera, scope.renderer); + if(!this.freeze){ + var result = Potree.updatePointClouds(this.scene.pointclouds, this.camera, this.renderer); visibleNodes = result.visibleNodes.length; visiblePoints = result.numVisiblePoints; } - //if(stats && scope.showStats){ + //if(stats && this.showStats){ // document.getElementById("lblNumVisibleNodes").style.display = ""; // document.getElementById("lblNumVisiblePoints").style.display = ""; // stats.domElement.style.display = ""; @@ -13028,40 +13036,40 @@ Potree.Viewer = function(domElement, args){ // stats.domElement.style.display = "none"; //} - scope.camera.fov = scope.fov; + this.camera.fov = this.fov; - if(scope.controls){ - scope.controls.update(delta); + if(this.controls){ + this.controls.update(delta); } // update progress bar - if(scope.pointclouds.length > 0){ - scope.progressBar.progress = progress / scope.pointclouds.length; + if(this.scene.pointclouds.length > 0){ + this.progressBar.progress = progress / this.scene.pointclouds.length; var message; if(progress === 0){ message = "loading"; }else{ - message = "loading: " + parseInt(progress*100 / scope.pointclouds.length) + "%"; + message = "loading: " + parseInt(progress*100 / this.scene.pointclouds.length) + "%"; } - scope.progressBar.message = message; + this.progressBar.message = message; if(progress >= 0.999){ - scope.progressBar.hide(); + this.progressBar.hide(); }else if(progress < 1){ - scope.progressBar.show(); + this.progressBar.show(); } } - scope.volumeTool.update(); - scope.transformationTool.update(); - scope.profileTool.update(); + this.volumeTool.update(); + this.transformationTool.update(); + this.profileTool.update(); var clipBoxes = []; - for(var i = 0; i < scope.profileTool.profiles.length; i++){ - var profile = scope.profileTool.profiles[i]; + for(var i = 0; i < this.profileTool.profiles.length; i++){ + var profile = this.profileTool.profiles[i]; for(var j = 0; j < profile.boxes.length; j++){ var box = profile.boxes[j]; @@ -13072,8 +13080,8 @@ Potree.Viewer = function(domElement, args){ } } - for(var i = 0; i < scope.volumeTool.volumes.length; i++){ - var volume = scope.volumeTool.volumes[i]; + for(var i = 0; i < this.volumeTool.volumes.length; i++){ + var volume = this.volumeTool.volumes[i]; if(volume.clip){ volume.updateMatrixWorld(); @@ -13085,18 +13093,18 @@ Potree.Viewer = function(domElement, args){ } - for(var i = 0; i < scope.pointclouds.length; i++){ - scope.pointclouds[i].material.setClipBoxes(clipBoxes); + for(var i = 0; i < this.scene.pointclouds.length; i++){ + this.scene.pointclouds[i].material.setClipBoxes(clipBoxes); } {// update annotations var distances = []; - for(var i = 0; i < scope.annotations.length; i++){ - var ann = scope.annotations[i]; - var screenPos = ann.position.clone().project(scope.camera); + for(var i = 0; i < this.annotations.length; i++){ + var ann = this.annotations[i]; + var screenPos = ann.position.clone().project(this.camera); - screenPos.x = scope.renderArea.clientWidth * (screenPos.x + 1) / 2; - screenPos.y = scope.renderArea.clientHeight * (1 - (screenPos.y + 1) / 2); + screenPos.x = this.renderArea.clientWidth * (screenPos.x + 1) / 2; + screenPos.y = this.renderArea.clientHeight * (1 - (screenPos.y + 1) / 2); ann.domElement.style.left = Math.floor(screenPos.x - ann.domElement.clientWidth / 2) + "px"; ann.domElement.style.top = Math.floor(screenPos.y) + "px"; @@ -13122,536 +13130,32 @@ Potree.Viewer = function(domElement, args){ } } - if(scope.showDebugInfos){ - scope.infos.set("camera.position", "camera.position: " + - scope.camera.position.x.toFixed(2) - + ", " + scope.camera.position.y.toFixed(2) - + ", " + scope.camera.position.z.toFixed(2) + if(this.showDebugInfos){ + this.infos.set("camera.position", "camera.position: " + + this.camera.position.x.toFixed(2) + + ", " + this.camera.position.y.toFixed(2) + + ", " + this.camera.position.z.toFixed(2) ); } - if(scope.mapView){ - scope.mapView.update(delta, scope.camera); + if(this.mapView){ + this.mapView.update(delta, this.camera); } TWEEN.update(timestamp); - scope.dispatchEvent({"type": "update", "delta": delta, "timestamp": timestamp}); + this.dispatcher.dispatchEvent({"type": "update", "delta": delta, "timestamp": timestamp}); } - - - - - - - - - - - - - - - - - - -//------------------------------------------------------------------------------------ -// Renderers -//------------------------------------------------------------------------------------ - - var PotreeRenderer = function(){ - - this.render = function(){ - {// resize - var width = scaleFactor * scope.renderArea.clientWidth; - var height = scaleFactor * scope.renderArea.clientHeight; - var aspect = width / height; - - scope.camera.aspect = aspect; - scope.camera.updateProjectionMatrix(); - - scope.renderer.setSize(width, height); - } - - - //var queryAll = Potree.startQuery("All", viewer.renderer.getContext()); - - // render skybox - if(scope.showSkybox){ - skybox.camera.rotation.copy(scope.camera.rotation); - scope.renderer.render(skybox.scene, skybox.camera); - }else{ - scope.renderer.render(scope.sceneBG, scope.cameraBG); - } - - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - if(pointcloud.originalMaterial){ - pointcloud.material = pointcloud.originalMaterial; - } - - var bbWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld); - - pointcloud.material.useEDL = false; - pointcloud.material.size = scope.pointSize; - pointcloud.material.minSize = scope.minPointSize; - pointcloud.material.maxSize = scope.maxPointSize; - pointcloud.material.opacity = scope.opacity; - pointcloud.material.pointColorType = scope.pointColorType; - pointcloud.material.pointSizeType = scope.pointSizeType; - pointcloud.material.pointShape = (scope.quality === "Circles") ? Potree.PointShape.CIRCLE : Potree.PointShape.SQUARE; - pointcloud.material.interpolate = (scope.quality === "Interpolation"); - pointcloud.material.weighted = false; - } - - // render scene - scope.renderer.render(scope.scene, scope.camera); - - //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); - scope.renderer.render(scope.scenePointCloud, scope.camera); - //Potree.endQuery(queryPC, viewer.renderer.getContext()); - - scope.profileTool.render(); - scope.volumeTool.render(); - - scope.renderer.clearDepth(); - scope.measuringTool.render(); - scope.transformationTool.render(); - - //Potree.endQuery(queryAll, viewer.renderer.getContext()); - - //Potree.resolveQueries(viewer.renderer.getContext()); - }; - }; - var potreeRenderer = new PotreeRenderer(); - - // high quality rendering using splats - var highQualityRenderer = null; - var HighQualityRenderer = function(){ - - var depthMaterial = null; - var attributeMaterial = null; - var normalizationMaterial = null; + loop(timestamp) { - var rtDepth; - var rtNormalize; + requestAnimationFrame(this.loop.bind(this)); - var initHQSPlats = function(){ - if(depthMaterial != null){ - return; - } - - depthMaterial = new Potree.PointCloudMaterial(); - attributeMaterial = new Potree.PointCloudMaterial(); - - depthMaterial.pointColorType = Potree.PointColorType.DEPTH; - depthMaterial.pointShape = Potree.PointShape.CIRCLE; - depthMaterial.interpolate = false; - depthMaterial.weighted = false; - depthMaterial.minSize = scope.minPointSize; - depthMaterial.maxSize = scope.maxPointSize; - - attributeMaterial.pointShape = Potree.PointShape.CIRCLE; - attributeMaterial.interpolate = false; - attributeMaterial.weighted = true; - attributeMaterial.minSize = scope.minPointSize; - attributeMaterial.maxSize = scope.maxPointSize; - - rtDepth = new THREE.WebGLRenderTarget( 1024, 1024, { - minFilter: THREE.NearestFilter, - magFilter: THREE.NearestFilter, - format: THREE.RGBAFormat, - type: THREE.FloatType - } ); - - rtNormalize = new THREE.WebGLRenderTarget( 1024, 1024, { - minFilter: THREE.LinearFilter, - magFilter: THREE.NearestFilter, - format: THREE.RGBAFormat, - type: THREE.FloatType - } ); - - var uniformsNormalize = { - depthMap: { type: "t", value: rtDepth }, - texture: { type: "t", value: rtNormalize } - }; - - normalizationMaterial = new THREE.ShaderMaterial({ - uniforms: uniformsNormalize, - vertexShader: Potree.Shaders["normalize.vs"], - fragmentShader: Potree.Shaders["normalize.fs"] - }); - } - - var resize = function(width, height){ - if(rtDepth.width == width && rtDepth.height == height){ - return; - } - - rtDepth.dispose(); - rtNormalize.dispose(); - - scope.camera.aspect = width / height; - scope.camera.updateProjectionMatrix(); - - scope.renderer.setSize(width, height); - rtDepth.setSize(width, height); - rtNormalize.setSize(width, height); - }; - - // render with splats - this.render = function(renderer){ - - var width = scope.renderArea.clientWidth; - var height = scope.renderArea.clientHeight; - - initHQSPlats(); - - resize(width, height); - - - scope.renderer.clear(); - if(scope.showSkybox){ - skybox.camera.rotation.copy(scope.camera.rotation); - scope.renderer.render(skybox.scene, skybox.camera); - }else{ - scope.renderer.render(scope.sceneBG, scope.cameraBG); - } - scope.renderer.render(scope.scene, scope.camera); - - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - - depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - - var originalMaterial = pointcloud.material; - - {// DEPTH PASS - depthMaterial.size = scope.pointSize; - depthMaterial.pointSizeType = scope.pointSizeType; - depthMaterial.screenWidth = width; - depthMaterial.screenHeight = height; - depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - depthMaterial.fov = scope.camera.fov * (Math.PI / 180); - depthMaterial.spacing = pointcloud.pcoGeometry.spacing; - depthMaterial.near = scope.camera.near; - depthMaterial.far = scope.camera.far; - depthMaterial.heightMin = scope.heightMin; - depthMaterial.heightMax = scope.heightMax; - depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - depthMaterial.bbSize = pointcloud.material.bbSize; - depthMaterial.treeType = pointcloud.material.treeType; - depthMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; - - scope.scenePointCloud.overrideMaterial = depthMaterial; - scope.renderer.clearTarget( rtDepth, true, true, true ); - scope.renderer.render(scope.scenePointCloud, scope.camera, rtDepth); - scope.scenePointCloud.overrideMaterial = null; - } - - {// ATTRIBUTE PASS - attributeMaterial.size = scope.pointSize; - attributeMaterial.pointSizeType = scope.pointSizeType; - attributeMaterial.screenWidth = width; - attributeMaterial.screenHeight = height; - attributeMaterial.pointColorType = scope.pointColorType; - attributeMaterial.depthMap = rtDepth; - attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; - attributeMaterial.fov = scope.camera.fov * (Math.PI / 180); - attributeMaterial.uniforms.blendHardness.value = pointcloud.material.uniforms.blendHardness.value; - attributeMaterial.uniforms.blendDepthSupplement.value = pointcloud.material.uniforms.blendDepthSupplement.value; - attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; - attributeMaterial.near = scope.camera.near; - attributeMaterial.far = scope.camera.far; - attributeMaterial.heightMin = scope.heightMin; - attributeMaterial.heightMax = scope.heightMax; - attributeMaterial.intensityMin = pointcloud.material.intensityMin; - attributeMaterial.intensityMax = pointcloud.material.intensityMax; - attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); - attributeMaterial.clipMode = pointcloud.material.clipMode; - attributeMaterial.bbSize = pointcloud.material.bbSize; - attributeMaterial.treeType = pointcloud.material.treeType; - attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; - - scope.scenePointCloud.overrideMaterial = attributeMaterial; - scope.renderer.clearTarget( rtNormalize, true, true, true ); - scope.renderer.render(scope.scenePointCloud, scope.camera, rtNormalize); - scope.scenePointCloud.overrideMaterial = null; - - pointcloud.material = originalMaterial; - } - } - - if(scope.pointclouds.length > 0){ - {// NORMALIZATION PASS - normalizationMaterial.uniforms.depthMap.value = rtDepth; - normalizationMaterial.uniforms.texture.value = rtNormalize; - Potree.utils.screenPass.render(scope.renderer, normalizationMaterial); - } - - scope.volumeTool.render(); - scope.renderer.clearDepth(); - scope.profileTool.render(); - scope.measuringTool.render(); - scope.transformationTool.render(); - } - - } - }; - - - - this.edlRenderer = null; - var EDLRenderer = function(){ - - _this = this; - - _this.edlMaterial = null; - var attributeMaterials = []; - - //var depthTexture = null; - - var rtColor = null; - var gl = scope.renderer.context; - - var initEDL = function(){ - if(_this.edlMaterial != null){ - return; - } - - //var depthTextureExt = gl.getExtension("WEBGL_depth_texture"); - - _this.edlMaterial = new Potree.EyeDomeLightingMaterial(); - - - rtColor = new THREE.WebGLRenderTarget( 1024, 1024, { - minFilter: THREE.NearestFilter, - magFilter: THREE.NearestFilter, - format: THREE.RGBAFormat, - type: THREE.FloatType, - //type: THREE.UnsignedByteType, - //depthBuffer: false, - //stencilBuffer: false - } ); - - }; - - var resize = function(){ - var width = this.scaleFactor * scope.renderArea.clientWidth; - var height = this.scaleFactor * scope.renderArea.clientHeight; - var aspect = width / height; - - var needsResize = (rtColor.width != width || rtColor.height != height); - - // disposal will be unnecessary once this fix made it into three.js master: - // https://github.com/mrdoob/three.js/pull/6355 - if(needsResize){ - rtColor.dispose(); - } - - scope.camera.aspect = aspect; - scope.camera.updateProjectionMatrix(); - - scope.renderer.setSize(width, height); - rtColor.setSize(width, height); - } - - this.render = function(){ - - initEDL(); - - resize(); - - scope.renderer.clear(); - if(scope.showSkybox){ - skybox.camera.rotation.copy(scope.camera.rotation); - scope.renderer.render(skybox.scene, skybox.camera); - }else{ - scope.renderer.render(scope.sceneBG, scope.cameraBG); - } - scope.renderer.render(scope.scene, scope.camera); - - var originalMaterials = []; - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - var width = scope.renderArea.clientWidth; - var height = scope.renderArea.clientHeight; - - if(attributeMaterials.length <= i ){ - var attributeMaterial = new Potree.PointCloudMaterial(); - - attributeMaterial.pointShape = Potree.PointShape.CIRCLE; - attributeMaterial.interpolate = (scope.quality === "Interpolation"); - attributeMaterial.weighted = false; - attributeMaterial.minSize = scope.minPointSize; - attributeMaterial.maxSize = scope.maxPointSize; - attributeMaterial.useLogarithmicDepthBuffer = false; - attributeMaterial.useEDL = true; - attributeMaterials.push(attributeMaterial); - } - var attributeMaterial = attributeMaterials[i]; - - var octreeSize = pointcloud.pcoGeometry.boundingBox.getSize().x; - - originalMaterials.push(pointcloud.material); - - scope.renderer.clearTarget( rtColor, true, true, true ); - - {// COLOR & DEPTH PASS - attributeMaterial = pointcloud.material; - attributeMaterial.pointShape = Potree.PointShape.CIRCLE; - attributeMaterial.interpolate = (scope.quality === "Interpolation"); - attributeMaterial.weighted = false; - attributeMaterial.minSize = scope.minPointSize; - attributeMaterial.maxSize = scope.maxPointSize; - attributeMaterial.useLogarithmicDepthBuffer = false; - attributeMaterial.useEDL = true; - - attributeMaterial.size = scope.pointSize; - attributeMaterial.pointSizeType = scope.pointSizeType; - attributeMaterial.screenWidth = width; - attributeMaterial.screenHeight = height; - attributeMaterial.pointColorType = scope.pointColorType; - attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; - attributeMaterial.uniforms.octreeSize.value = octreeSize; - attributeMaterial.fov = scope.camera.fov * (Math.PI / 180); - attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; - attributeMaterial.near = scope.camera.near; - attributeMaterial.far = scope.camera.far; - attributeMaterial.heightMin = scope.heightMin; - attributeMaterial.heightMax = scope.heightMax; - attributeMaterial.intensityMin = pointcloud.material.intensityMin; - attributeMaterial.intensityMax = pointcloud.material.intensityMax; - attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); - attributeMaterial.clipMode = pointcloud.material.clipMode; - attributeMaterial.bbSize = pointcloud.material.bbSize; - attributeMaterial.treeType = pointcloud.material.treeType; - attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; - - pointcloud.material = attributeMaterial; - for(var j = 0; j < pointcloud.visibleNodes.length; j++){ - var node = pointcloud.visibleNodes[j]; - if(pointcloud instanceof Potree.PointCloudOctree){ - node.sceneNode.material = attributeMaterial; - }else if(pointcloud instanceof Potree.PointCloudArena4D){ - node.material = attributeMaterial; - } - } - } - - } - - //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); - scope.renderer.render(scope.scenePointCloud, scope.camera, rtColor); - //Potree.endQuery(queryPC, viewer.renderer.getContext()); - - - // bit of a hack here. The EDL pass will mess up the text of the volume tool - // so volume tool is rendered again afterwards - scope.volumeTool.render(rtColor); - - for(var i = 0; i < scope.pointclouds.length; i++){ - var pointcloud = scope.pointclouds[i]; - var originalMaterial = originalMaterials[i]; - pointcloud.material = originalMaterial; - for(var j = 0; j < pointcloud.visibleNodes.length; j++){ - var node = pointcloud.visibleNodes[j]; - if(pointcloud instanceof Potree.PointCloudOctree){ - node.sceneNode.material = originalMaterial; - }else if(pointcloud instanceof Potree.PointCloudArena4D){ - node.material = originalMaterial; - } - } - } - - if(scope.pointclouds.length > 0){ - - //var ext = viewer.renderer.getContext().getExtension("EXT_disjoint_timer_query"); - //if(window.timerQuery == null){ - // window.timerQuery = ext.createQueryEXT(); - // ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, window.timerQuery); - //} - - //var query = Potree.startQuery("EDL", viewer.renderer.getContext()); - - { // EDL OCCLUSION PASS - _this.edlMaterial.uniforms.screenWidth.value = width; - _this.edlMaterial.uniforms.screenHeight.value = height; - _this.edlMaterial.uniforms.colorMap.value = rtColor; - _this.edlMaterial.uniforms.edlStrength.value = scope.edlStrength; - _this.edlMaterial.uniforms.radius.value = scope.edlRadius; - _this.edlMaterial.uniforms.opacity.value = scope.opacity; - _this.edlMaterial.depthTest = true; - _this.edlMaterial.depthWrite = true; - _this.edlMaterial.transparent = true; - - Potree.utils.screenPass.render(scope.renderer, _this.edlMaterial); - } - - scope.renderer.render(scope.scene, scope.camera); - - //Potree.endQuery(query, viewer.renderer.getContext()); - //Potree.resolveQueries(viewer.renderer.getContext()); - - //if(window.endedQuery == null){ - // ext.endQueryEXT(ext.TIME_ELAPSED_EXT); - // window.endedQuery = window.timerQuery; - //} - // - // - //if(window.endedQuery != null){ - // var available = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_AVAILABLE_EXT); - // var disjoint = viewer.renderer.getContext().getParameter(ext.GPU_DISJOINT_EXT); - // - // if (available && !disjoint) { - // // See how much time the rendering of the object took in nanoseconds. - // var timeElapsed = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_EXT); - // var miliseconds = timeElapsed / (1000 * 1000); - // - // console.log(miliseconds + "ms"); - // - // window.endedQuery = null; - // window.timerQuery = null; - // } - //} - - - - scope.profileTool.render(); - scope.volumeTool.render(); - scope.renderer.clearDepth(); - scope.measuringTool.render(); - scope.transformationTool.render(); - } - - - - } - }; - - //var toggleMessage = 0; - - scope.stats = new Stats(); - //scope.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom - //document.body.appendChild( scope.stats.dom ); - //scope.stats.dom.style.left = "100px"; - - - function loop(timestamp) { - - requestAnimationFrame(loop); - - scope.stats.begin(); + this.stats.begin(); //var start = new Date().getTime(); - scope.update(clock.getDelta(), timestamp); + this.update(this.clock.getDelta(), timestamp); //var end = new Date().getTime(); //var duration = end - start; //toggleMessage++; @@ -13660,79 +13164,531 @@ Potree.Viewer = function(domElement, args){ // toggleMessage = 0; //} - if(scope.useEDL && Potree.Features.SHADER_EDL.isSupported()){ - if(!scope.edlRenderer){ - scope.edlRenderer = new EDLRenderer(); + if(this.useEDL && Potree.Features.SHADER_EDL.isSupported()){ + if(!this.edlRenderer){ + this.edlRenderer = new EDLRenderer(this); } - scope.edlRenderer.render(scope.renderer); - }else if(scope.quality === "Splats"){ - if(!highQualityRenderer){ - highQualityRenderer = new HighQualityRenderer(); + this.edlRenderer.render(this.renderer); + }else if(this.quality === "Splats"){ + if(!this.highQualityRenderer){ + this.highQualityRenderer = new HighQualityRenderer(this); } - highQualityRenderer.render(scope.renderer); + this.highQualityRenderer.render(this.renderer); }else{ - potreeRenderer.render(); + if(!this.potreeRenderer){ + this.potreeRenderer = new PotreeRenderer(this); + } + + this.potreeRenderer.render(); } //if(this.takeScreenshot == true){ // this.takeScreenshot = false; // - // var screenshot = scope.renderer.domElement.toDataURL(); + // var screenshot = this.renderer.domElement.toDataURL(); // // //document.body.appendChild(screenshot); // var w = this.open(); // w.document.write(''); //} - scope.stats.end(); + this.stats.end(); Potree.framenumber++; }; - scope.initThree(); - //scope.initGUI(); - // set defaults - scope.setPointSize(1); - scope.setFOV(60); - scope.setOpacity(1); - scope.setEDLEnabled(false); - scope.setEDLRadius(1.4); - scope.setEDLStrength(1.0); - scope.setClipMode(Potree.ClipMode.HIGHLIGHT_INSIDE); - scope.setPointBudget(1*1000*1000); - scope.setShowBoundingBox(false); - scope.setFreeze(false); - scope.setNavigationMode("Orbit"); - - scaleFactor = 1; - - scope.loadSettingsFromURL(); - - // start rendering! - requestAnimationFrame(loop); - - - //document.body.addEventListener('keydown', function(e) { - // if(e.which === 75){ - // window.takeScreenshot = true; - // } - //}); }; -Potree.Viewer.prototype = Object.create( THREE.EventDispatcher.prototype ); +//------------------------------------------------------------------------------------ +// Renderers +//------------------------------------------------------------------------------------ + +class PotreeRenderer{ + + constructor(viewer){ + this.viewer = viewer; + }; + + render(){ + {// resize + let width = viewer.scaleFactor * viewer.renderArea.clientWidth; + let height = viewer.scaleFactor * viewer.renderArea.clientHeight; + let aspect = width / height; + + viewer.camera.aspect = aspect; + viewer.camera.updateProjectionMatrix(); + + viewer.renderer.setSize(width, height); + } + + + //var queryAll = Potree.startQuery("All", viewer.renderer.getContext()); + + // render skybox + if(viewer.showSkybox){ + viewer.skybox.camera.rotation.copy(viewer.camera.rotation); + viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera); + }else{ + viewer.renderer.render(viewer.scene.sceneBG, viewer.cameraBG); + } + + for(let i = 0; i < viewer.scene.pointclouds.length; i++){ + let pointcloud = viewer.scene.pointclouds[i]; + if(pointcloud.originalMaterial){ + pointcloud.material = pointcloud.originalMaterial; + } + + let bbWorld = Potree.utils.computeTransformedBoundingBox(pointcloud.boundingBox, pointcloud.matrixWorld); + + pointcloud.material.useEDL = false; + pointcloud.material.size = viewer.pointSize; + pointcloud.material.minSize = viewer.minPointSize; + pointcloud.material.maxSize = viewer.maxPointSize; + pointcloud.material.opacity = viewer.opacity; + pointcloud.material.pointColorType = viewer.pointColorType; + pointcloud.material.pointSizeType = viewer.pointSizeType; + pointcloud.material.pointShape = (viewer.quality === "Circles") ? Potree.PointShape.CIRCLE : Potree.PointShape.SQUARE; + pointcloud.material.interpolate = (viewer.quality === "Interpolation"); + pointcloud.material.weighted = false; + } + + // render scene + viewer.renderer.render(viewer.scene.scene, viewer.camera); + + //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); + viewer.renderer.render(viewer.scene.scenePointCloud, viewer.camera); + //Potree.endQuery(queryPC, viewer.renderer.getContext()); + + viewer.profileTool.render(); + viewer.volumeTool.render(); + + viewer.renderer.clearDepth(); + viewer.measuringTool.render(); + viewer.transformationTool.render(); + + //Potree.endQuery(queryAll, viewer.renderer.getContext()); + + //Potree.resolveQueries(viewer.renderer.getContext()); + }; +}; + +// high quality rendering using splats +class HighQualityRenderer{ + + constructor(viewer){ + this.viewer = viewer; + + this.depthMaterial = null; + this.attributeMaterial = null; + this.normalizationMaterial = null; + + this.rtDepth; + this.rtNormalize; + }; + + + + initHQSPlats(){ + if(depthMaterial != null){ + return; + } + + depthMaterial = new Potree.PointCloudMaterial(); + attributeMaterial = new Potree.PointCloudMaterial(); + + depthMaterial.pointColorType = Potree.PointColorType.DEPTH; + depthMaterial.pointShape = Potree.PointShape.CIRCLE; + depthMaterial.interpolate = false; + depthMaterial.weighted = false; + depthMaterial.minSize = viewer.minPointSize; + depthMaterial.maxSize = viewer.maxPointSize; + + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = false; + attributeMaterial.weighted = true; + attributeMaterial.minSize = viewer.minPointSize; + attributeMaterial.maxSize = viewer.maxPointSize; + + rtDepth = new THREE.WebGLRenderTarget( 1024, 1024, { + minFilter: THREE.NearestFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat, + type: THREE.FloatType + } ); + + rtNormalize = new THREE.WebGLRenderTarget( 1024, 1024, { + minFilter: THREE.LinearFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat, + type: THREE.FloatType + } ); + + var uniformsNormalize = { + depthMap: { type: "t", value: rtDepth }, + texture: { type: "t", value: rtNormalize } + }; + + normalizationMaterial = new THREE.ShaderMaterial({ + uniforms: uniformsNormalize, + vertexShader: Potree.Shaders["normalize.vs"], + fragmentShader: Potree.Shaders["normalize.fs"] + }); + }; + + resize(width, height){ + if(rtDepth.width == width && rtDepth.height == height){ + return; + } + + rtDepth.dispose(); + rtNormalize.dispose(); + + viewer.camera.aspect = width / height; + viewer.camera.updateProjectionMatrix(); + + viewer.renderer.setSize(width, height); + rtDepth.setSize(width, height); + rtNormalize.setSize(width, height); + }; + + // render with splats + render(renderer){ + + var width = viewer.renderArea.clientWidth; + var height = viewer.renderArea.clientHeight; + + initHQSPlats(); + + resize(width, height); + + + viewer.renderer.clear(); + if(viewer.showSkybox){ + skybox.camera.rotation.copy(viewer.camera.rotation); + viewer.renderer.render(skybox.scene, skybox.camera); + }else{ + viewer.renderer.render(viewer.sceneBG, viewer.cameraBG); + } + viewer.renderer.render(viewer.scene, viewer.camera); + + for(var i = 0; i < viewer.pointclouds.length; i++){ + var pointcloud = viewer.pointclouds[i]; + + depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + + var originalMaterial = pointcloud.material; + + {// DEPTH PASS + depthMaterial.size = viewer.pointSize; + depthMaterial.pointSizeType = viewer.pointSizeType; + depthMaterial.screenWidth = width; + depthMaterial.screenHeight = height; + depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + depthMaterial.fov = viewer.camera.fov * (Math.PI / 180); + depthMaterial.spacing = pointcloud.pcoGeometry.spacing; + depthMaterial.near = viewer.camera.near; + depthMaterial.far = viewer.camera.far; + depthMaterial.heightMin = viewer.heightMin; + depthMaterial.heightMax = viewer.heightMax; + depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + depthMaterial.bbSize = pointcloud.material.bbSize; + depthMaterial.treeType = pointcloud.material.treeType; + depthMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; + + viewer.scenePointCloud.overrideMaterial = depthMaterial; + viewer.renderer.clearTarget( rtDepth, true, true, true ); + viewer.renderer.render(viewer.scenePointCloud, viewer.camera, rtDepth); + viewer.scenePointCloud.overrideMaterial = null; + } + + {// ATTRIBUTE PASS + attributeMaterial.size = viewer.pointSize; + attributeMaterial.pointSizeType = viewer.pointSizeType; + attributeMaterial.screenWidth = width; + attributeMaterial.screenHeight = height; + attributeMaterial.pointColorType = viewer.pointColorType; + attributeMaterial.depthMap = rtDepth; + attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + attributeMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.getSize().x; + attributeMaterial.fov = viewer.camera.fov * (Math.PI / 180); + attributeMaterial.uniforms.blendHardness.value = pointcloud.material.uniforms.blendHardness.value; + attributeMaterial.uniforms.blendDepthSupplement.value = pointcloud.material.uniforms.blendDepthSupplement.value; + attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; + attributeMaterial.near = viewer.camera.near; + attributeMaterial.far = viewer.camera.far; + attributeMaterial.heightMin = viewer.heightMin; + attributeMaterial.heightMax = viewer.heightMax; + attributeMaterial.intensityMin = pointcloud.material.intensityMin; + attributeMaterial.intensityMax = pointcloud.material.intensityMax; + attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); + attributeMaterial.clipMode = pointcloud.material.clipMode; + attributeMaterial.bbSize = pointcloud.material.bbSize; + attributeMaterial.treeType = pointcloud.material.treeType; + attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; + + viewer.scenePointCloud.overrideMaterial = attributeMaterial; + viewer.renderer.clearTarget( rtNormalize, true, true, true ); + viewer.renderer.render(viewer.scenePointCloud, viewer.camera, rtNormalize); + viewer.scenePointCloud.overrideMaterial = null; + + pointcloud.material = originalMaterial; + } + } + + if(viewer.pointclouds.length > 0){ + {// NORMALIZATION PASS + normalizationMaterial.uniforms.depthMap.value = rtDepth; + normalizationMaterial.uniforms.texture.value = rtNormalize; + Potree.utils.screenPass.render(viewer.renderer, normalizationMaterial); + } + + viewer.volumeTool.render(); + viewer.renderer.clearDepth(); + viewer.profileTool.render(); + viewer.measuringTool.render(); + viewer.transformationTool.render(); + } + + } +}; +class EDLRenderer{ + + constructor(viewer){ + this.viewer = viewer; + + this.edlMaterial = null; + this.attributeMaterials = []; + + this.rtColor = null; + this.gl = viewer.renderer.context; + } + + initEDL(){ + if(this.edlMaterial != null){ + return; + } + + //var depthTextureExt = gl.getExtension("WEBGL_depth_texture"); + + this.edlMaterial = new Potree.EyeDomeLightingMaterial(); + + this.rtColor = new THREE.WebGLRenderTarget( 1024, 1024, { + minFilter: THREE.NearestFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat, + type: THREE.FloatType, + //type: THREE.UnsignedByteType, + //depthBuffer: false, + //stencilBuffer: false + } ); + + }; + + resize(){ + let width = viewer.scaleFactor * viewer.renderArea.clientWidth; + let height = viewer.scaleFactor * viewer.renderArea.clientHeight; + let aspect = width / height; + + var needsResize = (this.rtColor.width != width || this.rtColor.height != height); + + // disposal will be unnecessary once this fix made it into three.js master: + // https://github.com/mrdoob/three.js/pull/6355 + if(needsResize){ + this.rtColor.dispose(); + } + + viewer.camera.aspect = aspect; + viewer.camera.updateProjectionMatrix(); + + viewer.renderer.setSize(width, height); + this.rtColor.setSize(width, height); + } + render(){ + + this.initEDL(); + + this.resize(); + + viewer.renderer.clear(); + if(viewer.showSkybox){ + viewer.skybox.camera.rotation.copy(viewer.camera.rotation); + viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera); + }else{ + viewer.renderer.render(viewer.scene.sceneBG, viewer.cameraBG); + } + viewer.renderer.render(viewer.scene.scene, viewer.camera); + + var originalMaterials = []; + for(var i = 0; i < viewer.scene.pointclouds.length; i++){ + var pointcloud = viewer.scene.pointclouds[i]; + var width = viewer.renderArea.clientWidth; + var height = viewer.renderArea.clientHeight; + + if(this.attributeMaterials.length <= i ){ + var attributeMaterial = new Potree.PointCloudMaterial(); + + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = (viewer.quality === "Interpolation"); + attributeMaterial.weighted = false; + attributeMaterial.minSize = viewer.minPointSize; + attributeMaterial.maxSize = viewer.maxPointSize; + attributeMaterial.useLogarithmicDepthBuffer = false; + attributeMaterial.useEDL = true; + this.attributeMaterials.push(attributeMaterial); + } + var attributeMaterial = this.attributeMaterials[i]; + + var octreeSize = pointcloud.pcoGeometry.boundingBox.getSize().x; + + originalMaterials.push(pointcloud.material); + + viewer.renderer.clearTarget( this.rtColor, true, true, true ); + + {// COLOR & DEPTH PASS + attributeMaterial = pointcloud.material; + attributeMaterial.pointShape = Potree.PointShape.CIRCLE; + attributeMaterial.interpolate = (viewer.quality === "Interpolation"); + attributeMaterial.weighted = false; + attributeMaterial.minSize = viewer.minPointSize; + attributeMaterial.maxSize = viewer.maxPointSize; + attributeMaterial.useLogarithmicDepthBuffer = false; + attributeMaterial.useEDL = true; + + attributeMaterial.size = viewer.pointSize; + attributeMaterial.pointSizeType = viewer.pointSizeType; + attributeMaterial.screenWidth = width; + attributeMaterial.screenHeight = height; + attributeMaterial.pointColorType = viewer.pointColorType; + attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture; + attributeMaterial.uniforms.octreeSize.value = octreeSize; + attributeMaterial.fov = viewer.camera.fov * (Math.PI / 180); + attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; + attributeMaterial.near = viewer.camera.near; + attributeMaterial.far = viewer.camera.far; + attributeMaterial.heightMin = viewer.heightMin; + attributeMaterial.heightMax = viewer.heightMax; + attributeMaterial.intensityMin = pointcloud.material.intensityMin; + attributeMaterial.intensityMax = pointcloud.material.intensityMax; + attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes); + attributeMaterial.clipMode = pointcloud.material.clipMode; + attributeMaterial.bbSize = pointcloud.material.bbSize; + attributeMaterial.treeType = pointcloud.material.treeType; + attributeMaterial.uniforms.classificationLUT.value = pointcloud.material.uniforms.classificationLUT.value; + + pointcloud.material = attributeMaterial; + for(var j = 0; j < pointcloud.visibleNodes.length; j++){ + var node = pointcloud.visibleNodes[j]; + if(pointcloud instanceof Potree.PointCloudOctree){ + node.sceneNode.material = attributeMaterial; + }else if(pointcloud instanceof Potree.PointCloudArena4D){ + node.material = attributeMaterial; + } + } + } + + } + + //var queryPC = Potree.startQuery("PointCloud", viewer.renderer.getContext()); + viewer.renderer.render(viewer.scene.scenePointCloud, viewer.camera, this.rtColor); + //Potree.endQuery(queryPC, viewer.renderer.getContext()); + + + // bit of a hack here. The EDL pass will mess up the text of the volume tool + // so volume tool is rendered again afterwards + viewer.volumeTool.render(this.rtColor); + + for(var i = 0; i < viewer.scene.pointclouds.length; i++){ + var pointcloud = viewer.scene.pointclouds[i]; + var originalMaterial = originalMaterials[i]; + pointcloud.material = originalMaterial; + for(var j = 0; j < pointcloud.visibleNodes.length; j++){ + var node = pointcloud.visibleNodes[j]; + if(pointcloud instanceof Potree.PointCloudOctree){ + node.sceneNode.material = originalMaterial; + }else if(pointcloud instanceof Potree.PointCloudArena4D){ + node.material = originalMaterial; + } + } + } + + if(viewer.scene.pointclouds.length > 0){ + + //var ext = viewer.renderer.getContext().getExtension("EXT_disjoint_timer_query"); + //if(window.timerQuery == null){ + // window.timerQuery = ext.createQueryEXT(); + // ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, window.timerQuery); + //} + + //var query = Potree.startQuery("EDL", viewer.renderer.getContext()); + + { // EDL OCCLUSION PASS + this.edlMaterial.uniforms.screenWidth.value = width; + this.edlMaterial.uniforms.screenHeight.value = height; + this.edlMaterial.uniforms.colorMap.value = this.rtColor; + this.edlMaterial.uniforms.edlStrength.value = viewer.edlStrength; + this.edlMaterial.uniforms.radius.value = viewer.edlRadius; + this.edlMaterial.uniforms.opacity.value = viewer.opacity; + this.edlMaterial.depthTest = true; + this.edlMaterial.depthWrite = true; + this.edlMaterial.transparent = true; + + Potree.utils.screenPass.render(viewer.renderer, this.edlMaterial); + } + + viewer.renderer.render(viewer.scene.scene, viewer.camera); + + //Potree.endQuery(query, viewer.renderer.getContext()); + //Potree.resolveQueries(viewer.renderer.getContext()); + + //if(window.endedQuery == null){ + // ext.endQueryEXT(ext.TIME_ELAPSED_EXT); + // window.endedQuery = window.timerQuery; + //} + // + // + //if(window.endedQuery != null){ + // var available = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_AVAILABLE_EXT); + // var disjoint = viewer.renderer.getContext().getParameter(ext.GPU_DISJOINT_EXT); + // + // if (available && !disjoint) { + // // See how much time the rendering of the object took in nanoseconds. + // var timeElapsed = ext.getQueryObjectEXT(window.endedQuery, ext.QUERY_RESULT_EXT); + // var miliseconds = timeElapsed / (1000 * 1000); + // + // console.log(miliseconds + "ms"); + // + // window.endedQuery = null; + // window.timerQuery = null; + // } + //} + + + viewer.profileTool.render(); + viewer.volumeTool.render(); + viewer.renderer.clearDepth(); + viewer.measuringTool.render(); + viewer.transformationTool.render(); + } + + + } +}; Potree.Viewer.Profile = function(viewer, element){ var scope = this; @@ -13935,21 +13891,15 @@ Potree.Viewer.Profile = function(viewer, element){ // Get the same color map as Three var hr = scope.viewer.getHeightRange(); - var hrGeo = { - min: scope.viewer.toGeo(new THREE.Vector3(0, hr.min, 0)).z, - max: scope.viewer.toGeo(new THREE.Vector3(0, hr.max, 0)).z, - }; - //var minRange = scope.viewer.toGeo(new THREE.Vector3(0, args.heightMin, 0)); - //var maxRange = scope.viewer.toGeo(new THREE.Vector3(0, args.heightMax, 0)); - var heightRange = hrGeo.max - hrGeo.min; + var heightRange = hr.max - hr.min; var colorRange = []; var colorDomain = []; // Read the altitude gradient used in 3D scene - var gradient = viewer.pointclouds[0].material.gradient; + var gradient = viewer.scene.pointclouds[0].material.gradient; for (var c = 0; c < gradient.length; c++){ - colorDomain.push(hrGeo.min + heightRange * gradient[c][0]); + colorDomain.push(hr.min + heightRange * gradient[c][0]); colorRange.push('#' + gradient[c][1].getHexString()); } @@ -13962,8 +13912,8 @@ Potree.Viewer.Profile = function(viewer, element){ // Iterate the profile's segments for(var i = 0; i < segments.length; i++){ var segment = segments[i]; - var segStartGeo = scope.viewer.toGeo(segment.start); - var segEndGeo = scope.viewer.toGeo(segment.end); + var segStartGeo = new THREE.Vector3(segment.start.x, -segment.start.z, segment.start.y); + var segEndGeo = new THREE.Vector3(segment.end.x, -segment.end.z, segment.end.y); var xOA = segEndGeo.x - segStartGeo.x; var yOA = segEndGeo.y - segStartGeo.y; var segmentLength = Math.sqrt(xOA * xOA + yOA * yOA); @@ -13971,19 +13921,15 @@ Potree.Viewer.Profile = function(viewer, element){ // Iterate the segments' points for(var j = 0; j < points.numPoints; j++){ - var p = scope.viewer.toGeo(points.position[j]); - // get min/max values - if (p.x < minX) { minX = p.x;} - - if (p.y < minY) { minY = p.y;} - - if (p.z < minZ) { minZ = p.z;} - - if (p.x > maxX) { maxX = p.x;} - - if (p.y < maxY) { maxY = p.y;} - - if (p.z < maxZ) { maxZ = p.z;} + var p = points.position[j]; + p.set(p.x, -p.z, p.y); + + minX = Math.min(minX, p.x); + minY = Math.min(minY, p.y); + minZ = Math.min(minZ, p.z); + maxX = Math.min(maxX, p.x); + maxY = Math.min(maxY, p.y); + maxZ = Math.min(maxZ, p.z); var xOB = p.x - segStartGeo.x; var yOB = p.y - segStartGeo.y; @@ -14116,7 +14062,7 @@ Potree.Viewer.Profile = function(viewer, element){ //return d.intensity; return 'rgb(' + d.intensity + '%,' + d.intensity + '%,' + d.intensity + '%)'; } else if (material === Potree.PointColorType.CLASSIFICATION) { - var classif = scope.viewer.pointclouds[0].material.classification; + var classif = scope.viewer.scene.pointclouds[0].material.classification; if (typeof classif[d.classification] != 'undefined'){ var color = 'rgb(' + classif[d.classification].x * 100 + '%,'; color += classif[d.classification].y * 100 + '%,'; @@ -14164,7 +14110,7 @@ Potree.Viewer.Profile = function(viewer, element){ }else{ return; } - if(scope.viewer.pointclouds.length === 0){ + if(scope.viewer.scene.pointclouds.length === 0){ return; } @@ -14191,12 +14137,11 @@ Potree.Viewer.Profile = function(viewer, element){ var mileage = 0; for(var i = 0; i < profile.points.length; i++){ var point = profile.points[i]; - var pointGeo = scope.viewer.toGeo(point); if(i > 0){ - var previousGeo = scope.viewer.toGeo(profile.points[i-1]); - var dx = pointGeo.x - previousGeo.x; - var dy = pointGeo.y - previousGeo.y; + var previous = profile.points[i-1]; + var dx = point.x - previous.x; + var dy = point.y - previous.y; var distance = Math.sqrt(dx * dx + dy * dy); mileage += distance; } @@ -14380,8 +14325,8 @@ Potree.Viewer.Profile = function(viewer, element){ }; - for(var i = 0; i < scope.viewer.pointclouds.length; i++){ - var pointcloud = scope.viewer.pointclouds[i]; + for(var i = 0; i < scope.viewer.scene.pointclouds.length; i++){ + var pointcloud = scope.viewer.scene.pointclouds[i]; if(!pointcloud.visible){ continue; @@ -14478,7 +14423,7 @@ Potree.Viewer.Profile = function(viewer, element){ // http://epsg.io/ proj4.defs("UTM10N", "+proj=utm +zone=10 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"); -Potree.Viewer.MapView = function(viewer){ +Potree.MapView = function(viewer){ var scope = this; this.viewer = viewer; @@ -14751,11 +14696,11 @@ Potree.Viewer.MapView = function(viewer){ // adding pointclouds to map - scope.viewer.addEventListener("pointcloud_loaded", function(event){ + scope.viewer.dispatcher.addEventListener("pointcloud_loaded", function(event){ scope.load(event.pointcloud); }); - for(var i = 0; i < scope.viewer.pointclouds.length; i++){ - scope.load(scope.viewer.pointclouds[i]); + for(var i = 0; i < scope.viewer.scene.pointclouds.length; i++){ + scope.load(scope.viewer.scene.pointclouds[i]); } scope.viewer.profileTool.addEventListener("profile_added", scope.updateToolDrawings); @@ -14816,8 +14761,7 @@ Potree.Viewer.MapView = function(viewer){ for(var j = 0; j < profile.points.length; j++){ var point = profile.points[j]; - var pointGeo = scope.viewer.toGeo(point); - var pointMap = scope.toMap.forward([pointGeo.x, pointGeo.y]); + var pointMap = scope.toMap.forward([point.x, point.y]); coordinates.push(pointMap); } @@ -14833,8 +14777,7 @@ Potree.Viewer.MapView = function(viewer){ for(var j = 0; j < measurement.points.length; j++){ var point = measurement.points[j].position; - var pointGeo = scope.viewer.toGeo(point); - var pointMap = scope.toMap.forward([pointGeo.x, pointGeo.y]); + var pointMap = scope.toMap.forward([point.x, point.y]); coordinates.push(pointMap); } @@ -14975,8 +14918,8 @@ Potree.Viewer.MapView = function(viewer){ var campos = camera.position; var camdir = camera.getWorldDirection(); var sceneLookAt = camdir.clone().multiplyScalar(30 * scale).add(campos); - var geoPos = scope.viewer.toGeo(camera.position); - var geoLookAt = scope.viewer.toGeo(sceneLookAt); + var geoPos = camera.position; + var geoLookAt = sceneLookAt; var mapPos = new THREE.Vector2().fromArray(scope.toMap.forward([geoPos.x, geoPos.y])); var mapLookAt = new THREE.Vector2().fromArray(scope.toMap.forward([geoLookAt.x, geoLookAt.y])); var mapDir = new THREE.Vector2().subVectors(mapLookAt, mapPos).normalize(); diff --git a/build/potree/sidebar.html b/build/potree/sidebar.html index 4202e939..cfbf549b 100644 --- a/build/potree/sidebar.html +++ b/build/potree/sidebar.html @@ -318,11 +318,7 @@ function initMaterials(){ values: [0, 1000], step: 0.01, slide: function( event, ui ) { - var local = { - min: viewer.toLocal(new THREE.Vector3(0, 0, ui.values[0])).y, - max: viewer.toLocal(new THREE.Vector3(0, 0, ui.values[1])).y, - }; - viewer.setHeightRange(local.min, local.max); + viewer.setHeightRange(ui.values[0], ui.values[1]); } }); @@ -445,26 +441,18 @@ function initMaterials(){ var updateHeightRange = function(){ let box = viewer.getBoundingBox(); - let geoMin = viewer.toGeo(box.min).z; - let geoMax = viewer.toGeo(box.max).z; - let width = geoMax - geoMin; - geoMin = geoMin - 0.2 * width; - geoMax = geoMax + 0.2 * width; + let bWidth = box.max.y - box.min.y; + bMin = box.min.y - 0.2 * bWidth; + bMax = box.max.y + 0.2 * bWidth; let hr = viewer.getHeightRange(); - let hrGeo = { - min: viewer.toGeo(new THREE.Vector3(0, hr.min, 0)).z, - max: viewer.toGeo(new THREE.Vector3(0, hr.max, 0)).z, - }; + let hrWidth = hr.max - hr.min; - let vMin = hr.min ? hrGeo.min : geoMin; - let vMax = hr.max ? hrGeo.max : geoMax; - - $( '#lblHeightRange')[0].innerHTML = hrGeo.min.toFixed(2) + " to " + hrGeo.max.toFixed(2); + $( '#lblHeightRange')[0].innerHTML = hr.min.toFixed(2) + " to " + hr.max.toFixed(2); $( "#sldHeightRange" ).slider({ - min: geoMin, - max: geoMax, - values: [vMin, vMax] + min: bMin, + max: bMax, + values: [hr.min, hr.max] }); }; @@ -1024,12 +1012,13 @@ function initMeasurementDetails(){ } for(var i = 0; i < positions.length; i++){ + // TODO clean this up from the toGeo legacy var point = positions[i]; - var geoCoord = viewer.toGeo(point); + var geoCoord = point; var txt = geoCoord.x.toFixed(2) + ", "; - txt += geoCoord.y.toFixed(2) + ", "; - txt += geoCoord.z.toFixed(2); + txt += (-geoCoord.z).toFixed(2) + ", "; + txt += geoCoord.y.toFixed(2); var elNodeMarker = $('
').addClass("measurement-detail-node-marker"); elNodeMarker.html(txt); @@ -1043,7 +1032,7 @@ function initMeasurementDetails(){ $(elPanelBody).append(elEdge); var nextPoint = positions[i+1]; - var nextGeo = viewer.toGeo(nextPoint); + var nextGeo = nextPoint; var distance = nextGeo.distanceTo(geoCoord); var txt = Potree.utils.addCommas(distance.toFixed(2)); @@ -1305,8 +1294,8 @@ function initSceneList(){ })(pointcloud); }; - for(var i = 0; i < viewer.pointclouds.length; i++){ - var pointcloud = viewer.pointclouds[i]; + for(var i = 0; i < viewer.scene.pointclouds.length; i++){ + var pointcloud = viewer.scene.pointclouds[i]; addPointcloud(pointcloud); } diff --git a/build/shaders/shaders.js b/build/shaders/shaders.js index 585fa108..3ae28762 100644 --- a/build/shaders/shaders.js +++ b/build/shaders/shaders.js @@ -316,10 +316,8 @@ Potree.Shaders["pointcloud.vs"] = [ "}", "", "void main() {", - " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", - " vViewPosition = -mvPosition.xyz;", - " vWorldPosition = worldPosition.xyz;", + " vViewPosition = mvPosition.xyz;", " gl_Position = projectionMatrix * mvPosition;", " vOpacity = opacity;", " vLinearDepth = gl_Position.w;", @@ -384,7 +382,7 @@ Potree.Shaders["pointcloud.vs"] = [ " float pointSize = 1.0;", " ", " float slope = tan(fov / 2.0);", - " float projFactor = 0.5 * screenHeight / (slope * vViewPosition.z);", + " float projFactor = -0.5 * screenHeight / (slope * vViewPosition.z);", " ", " float r = spacing * 1.5;", " vRadius = r;", @@ -475,7 +473,6 @@ Potree.Shaders["pointcloud.fs"] = [ "varying float vLogDepth;", "varying vec3 vViewPosition;", "varying float vRadius;", - "varying vec3 vWorldPosition;", "varying vec3 vNormal;", "", "float specularStrength = 1.0;", @@ -648,7 +645,7 @@ Potree.Shaders["pointcloud.fs"] = [ " ", " #if defined use_interpolation", " float wi = 0.0 - ( u*u + v*v);", - " vec4 pos = vec4(-vViewPosition, 1.0);", + " vec4 pos = vec4(vViewPosition, 1.0);", " pos.z += wi * vRadius;", " float linearDepth = -pos.z;", " pos = projectionMatrix * pos;", diff --git a/src/viewer/sidebar.html b/src/viewer/sidebar.html index cfbf549b..cabf54a1 100644 --- a/src/viewer/sidebar.html +++ b/src/viewer/sidebar.html @@ -1364,21 +1364,11 @@ $(document).ready( function() { initSettings() $('#potree_version_number').html(Potree.version.major + "." + Potree.version.minor + Potree.version.suffix); - //$('#potree_sidebar_container').perfectScrollbar(); - //$('#sidebar_root').perfectScrollbar(); $('.perfect_scrollbar').perfectScrollbar(); }); - - - - - - - - \ No newline at end of file