diff --git a/build/js/potree.js b/build/js/potree.js index e6f5c43c..8db4fb3c 100644 --- a/build/js/potree.js +++ b/build/js/potree.js @@ -594,7 +594,6 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ pointAttributes: pointAttributes, version: this.version.version, min: [ node.boundingBox.min.x, node.boundingBox.min.y, node.boundingBox.min.z ], - max: [ node.boundingBox.max.x, node.boundingBox.max.y, node.boundingBox.max.z ], offset: [node.pcoGeometry.offset.x, node.pcoGeometry.offset.y, node.pcoGeometry.offset.z], scale: this.scale }; @@ -1944,14 +1943,28 @@ THREE.FirstPersonControls = function ( object, domElement ) { this.object.rotation.x += phiDelta; this.object.updateMatrixWorld(); + // send transformation proposal to listeners var proposeTransformEvent = { type: "proposeTransform", oldPosition: object.position, newPosition: this.object.position, - objections: 0 + objections: 0, + counterProposals: [] }; this.dispatchEvent(proposeTransformEvent); + // check some counter proposals if transformation wasn't accepted + if(proposeTransformEvent.objections > 0 ){ + if(proposeTransformEvent.counterProposals.length > 0){ + var cp = proposeTransformEvent.counterProposals; + this.object.position.copy(cp[0]); + + proposeTransformEvent.objections = 0; + proposeTransformEvent.counterProposals = []; + } + } + + // apply transformation, if accepted if(proposeTransformEvent.objections > 0){ }else{ @@ -2094,136 +2107,472 @@ THREE.FirstPersonControls = function ( object, domElement ) { }; THREE.FirstPersonControls.prototype = Object.create( THREE.EventDispatcher.prototype ); +/** + * @author mschuetz / http://mschuetz.at/ + * @author qiao / https://github.com/qiao + * @author mrdoob / http://mrdoob.com + * @author alteredq / http://alteredqualia.com/ + * @author WestLangley / http://github.com/WestLangley + * @author erich666 / http://erichaines.com + */ +/*global THREE, console */ + +// +// Adapted from THREE.OrbitControls +// - Smooth movements +// - creates "proposeTransform" events +// +// +// This set of controls performs orbiting, dollying (zooming), and panning. It maintains +// the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is +// supported. // +// Orbit - left mouse / touch: one finger move +// Zoom - middle mouse, or mousewheel / touch: two finger spread or squish +// Pan - right mouse, or arrow keys / touch: three finter swipe // -// adapted from THREE.OrbitControls -// +// This is a drop-in replacement for (most) TrackballControls used in examples. +// That is, include this js file and wherever you see: +// controls = new THREE.TrackballControls( camera ); +// controls.target.z = 150; +// Simple substitute "OrbitControls" and the control should work as-is. Potree.OrbitControls = function ( object, domElement ) { - var scope = this; this.object = object; this.domElement = ( domElement !== undefined ) ? domElement : document; - - this.speed = {phi: 0, theta: 0}; - this.zoomSpeed = 0; - this.panSpeed = new THREE.Vector2(); + + // API + + // Set to false to disable this control + this.enabled = true; + + // "target" sets the location of focus, where the control orbits around + // and where it pans with respect to. this.target = new THREE.Vector3(); - this.mouse = new THREE.Vector2(); - this.dollyStart = new THREE.Vector2(); + + // center is old, deprecated; use "target" instead + this.center = this.target; + + // This option actually enables dollying in and out; left as "zoom" for + // backwards compatibility + this.noZoom = false; + this.zoomSpeed = 1.0; + + // Limits to how far you can dolly in and out + this.minDistance = 0; + this.maxDistance = Infinity; + + // Set to true to disable this control + this.noRotate = false; + this.rotateSpeed = 1.0; + + // Set to true to disable this control + this.noPan = false; + this.keyPanSpeed = 7.0; // pixels moved per arrow key push + + // Set to true to automatically rotate around the target + this.autoRotate = false; + this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60 + this.fadeFactor = 10; + + // How far you can orbit vertically, upper and lower limits. + // Range is 0 to Math.PI radians. + this.minPolarAngle = 0; // radians + this.maxPolarAngle = Math.PI; // radians + + // Set to true to disable use of the keys + this.noKeys = false; + + // The four arrow keys + this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 }; + + //////////// + // internals + + var scope = this; + + var EPS = 0.000001; + + var rotateStart = new THREE.Vector2(); + var rotateEnd = new THREE.Vector2(); + var rotateDelta = new THREE.Vector2(); + + var panStart = new THREE.Vector2(); + var panEnd = new THREE.Vector2(); + var panDelta = new THREE.Vector2(); + var panOffset = new THREE.Vector3(); + + var offset = new THREE.Vector3(); + + var dollyStart = new THREE.Vector2(); + var dollyEnd = new THREE.Vector2(); + var dollyDelta = new THREE.Vector2(); + + var phiDelta = 0; + var thetaDelta = 0; + var scale = 1; + var pan = new THREE.Vector3(); + + var lastPosition = new THREE.Vector3(); + var STATE = { NONE : -1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 }; var state = STATE.NONE; - this.update = function( delta ) { - - var up = new THREE.Vector3(0,1,0); - var dir = new THREE.Vector3().subVectors(this.target, object.position).normalize(); - var right = new THREE.Vector3().crossVectors(dir, up).normalize(); - var tilt = new THREE.Vector3().crossVectors(right, dir).normalize(); - var radius = object.position.distanceTo(this.target); - - var p = new THREE.Vector3().subVectors(object.position, this.target); - - // apply rotation - var angle = Math.acos(-dir.dot(up, dir)); - if(angle + this.speed.theta > 0){ - p.applyAxisAngle(right, this.speed.theta); - } - - p.applyAxisAngle(up, this.speed.phi); - - - // apply zoom - var radius = radius + radius * 0.05 * this.zoomSpeed; - p.normalize().multiplyScalar(radius); - - // apply pan - var panX = right.clone().multiplyScalar( -500 * radius * delta * this.panSpeed.x); - var panY = tilt.clone().multiplyScalar( 500 * radius * delta * this.panSpeed.y); - - - var pos = new THREE.Vector3().addVectors(this.target, p); - pos.add(panX); - pos.add(panY); + // for reset + this.target0 = this.target.clone(); + this.position0 = this.object.position.clone(); + + // events + + var changeEvent = { type: 'change' }; + var startEvent = { type: 'start'}; + var endEvent = { type: 'end'}; + + this.rotateLeft = function ( angle ) { + + if ( angle === undefined ) { + + angle = getAutoRotationAngle(); + + } + + thetaDelta -= angle; + + }; + + this.rotateUp = function ( angle ) { + + if ( angle === undefined ) { + + angle = getAutoRotationAngle(); + + } + + phiDelta -= angle; + + }; + + // pass in distance in world space to move left + this.panLeft = function ( distance ) { + + var te = this.object.matrix.elements; + + // get X column of matrix + panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] ); + panOffset.multiplyScalar( - distance ); + pan.add( panOffset ); + + }; + + // pass in distance in world space to move up + this.panUp = function ( distance ) { + + var te = this.object.matrix.elements; + + // get Y column of matrix + panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] ); + panOffset.multiplyScalar( distance ); + + pan.add( panOffset ); + + }; + + // pass in x,y of change desired in pixel space, + // right and down are positive + this.pan = function ( deltaX, deltaY ) { + + var element = scope.domElement === document ? scope.domElement.body : scope.domElement; + + if ( scope.object.fov !== undefined ) { + + // perspective + var position = scope.object.position; + var offset = position.clone().sub( scope.target ); + var targetDistance = offset.length(); + + // half of the fov is center to top of screen + targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 ); + + // we actually don't use screenWidth, since perspective camera is fixed to screen height + scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight ); + scope.panUp( 2 * deltaY * targetDistance / element.clientHeight ); + + } else if ( scope.object.top !== undefined ) { + + // orthographic + scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth ); + scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight ); + + } else { + + // camera neither orthographic or perspective + console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' ); + + } + + }; + + this.dollyIn = function ( dollyScale ) { + + if ( dollyScale === undefined ) { + + dollyScale = getZoomScale(); + + } + + scale /= dollyScale; + + }; + + this.dollyOut = function ( dollyScale ) { + + if ( dollyScale === undefined ) { + + dollyScale = getZoomScale(); + + } + + scale *= dollyScale; + + }; + + this.update = function ( delta ) { + + var position = this.object.position.clone(); + + offset.copy( position ).sub( this.target ); + + // angle from z-axis around y-axis + + var theta = Math.atan2( offset.x, offset.z ); + + // angle from y-axis + + var phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y ); + + if ( this.autoRotate ) { + + this.rotateLeft( getAutoRotationAngle() ); + + } + + var progression = Math.min(1, this.fadeFactor * delta); + + theta += progression * thetaDelta; + phi += progression * phiDelta; + + // restrict phi to be between desired limits + phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) ); + + // restrict phi to be betwee EPS and PI-EPS + phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) ); + + //var radius = offset.length() * scale; + var radius = offset.length(); + radius += (scale-1) * radius * progression; + + // restrict radius to be between desired limits + radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) ); + + // move target to panned location + this.target.add( pan.clone().multiplyScalar( progression ) ); + + offset.x = radius * Math.sin( phi ) * Math.sin( theta ); + offset.y = radius * Math.cos( phi ); + offset.z = radius * Math.sin( phi ) * Math.cos( theta ); + + position.copy( this.target ).add( offset ); + + // send transformation proposal to listeners var proposeTransformEvent = { type: "proposeTransform", - oldPosition: object.position, - newPosition: pos, - objections: 0 + oldPosition: this.object.position, + newPosition: position, + objections: 0, + counterProposals: [] }; this.dispatchEvent(proposeTransformEvent); - if(proposeTransformEvent.objections > 0){ - this.speed.phi = 0; - this.speed.theta = 0; - this.zoomSpeed = 0; - this.panSpeed.multiplyScalar(0); - }else{ - this.target.add(panX); - this.target.add(panY); + // check some counter proposals if transformation wasn't accepted + while(proposeTransformEvent.objections > 0 ){ - object.position.copy(pos); - object.lookAt(this.target); - - var attenuation = (1 - delta) * 0.85; - this.speed.phi *= attenuation; - this.speed.theta *= attenuation; - this.zoomSpeed *= attenuation; - this.panSpeed.multiplyScalar(attenuation); + if(proposeTransformEvent.counterProposals.length > 0){ + var cp = proposeTransformEvent.counterProposals; + position.copy(cp[0]); + + proposeTransformEvent.objections = 0; + proposeTransformEvent.counterProposals = []; + } } + + // apply transformation, if accepted + if(proposeTransformEvent.objections > 0){ + thetaDelta = 0; + phiDelta = 0; + scale = 1; + pan.set(0,0,0); + }else{ + this.object.position.copy(position); + this.object.lookAt( this.target ); + + var attenuation = Math.max(0, 1 - this.fadeFactor * delta); + + thetaDelta *= attenuation; + phiDelta *= attenuation; + scale = 1 + (scale-1) * attenuation; + pan.multiplyScalar( attenuation ); + } + + if ( lastPosition.distanceTo( this.object.position ) > 0 ) { + + this.dispatchEvent( changeEvent ); + + lastPosition.copy( this.object.position ); + + } + }; + + this.reset = function () { + + state = STATE.NONE; + + this.target.copy( this.target0 ); + this.object.position.copy( this.position0 ); + + this.update(); + + }; + + function getAutoRotationAngle() { + + return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed; + + } + + function getZoomScale() { + + return Math.pow( 0.95, scope.zoomSpeed ); + + } + function onMouseDown( event ) { + + if ( scope.enabled === false ) return; + event.preventDefault(); + if ( event.button === 0 ) { + if ( scope.noRotate === true ) return; + state = STATE.ROTATE; + + rotateStart.set( event.clientX, event.clientY ); + } else if ( event.button === 1 ) { + if ( scope.noZoom === true ) return; + state = STATE.DOLLY; + + dollyStart.set( event.clientX, event.clientY ); + } else if ( event.button === 2 ) { + if ( scope.noPan === true ) return; + state = STATE.PAN; + + panStart.set( event.clientX, event.clientY ); + } - - scope.mouse.set(event.clientX, event.clientY); - + scope.domElement.addEventListener( 'mousemove', onMouseMove, false ); scope.domElement.addEventListener( 'mouseup', onMouseUp, false ); + scope.dispatchEvent( startEvent ); + } function onMouseMove( event ) { + + if ( scope.enabled === false ) return; + event.preventDefault(); - + var element = scope.domElement === document ? scope.domElement.body : scope.domElement; - - var newMouse = new THREE.Vector2(event.clientX, event.clientY); - var diff = new THREE.Vector2().subVectors(newMouse, scope.mouse); - + if ( state === STATE.ROTATE ) { - scope.speed.phi -= diff.x / element.clientWidth; - scope.speed.theta -= diff.y / element.clientHeight; + + if ( scope.noRotate === true ) return; + + rotateEnd.set( event.clientX, event.clientY ); + rotateDelta.subVectors( rotateEnd, rotateStart ); + + // rotating across whole screen goes 360 degrees around + scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed ); + + // rotating up and down along whole screen attempts to go 360, but limited to 180 + scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed ); + + rotateStart.copy( rotateEnd ); + } else if ( state === STATE.DOLLY ) { - scope.zoomSpeed = 20 * diff.y / element.clientHeight; + + if ( scope.noZoom === true ) return; + + dollyEnd.set( event.clientX, event.clientY ); + dollyDelta.subVectors( dollyEnd, dollyStart ); + + if ( dollyDelta.y > 0 ) { + + scope.dollyIn(); + + } else { + + scope.dollyOut(); + + } + + dollyStart.copy( dollyEnd ); + } else if ( state === STATE.PAN ) { - scope.panSpeed.x = diff.x / element.clientWidth; - scope.panSpeed.y = diff.y / element.clientHeight; + + if ( scope.noPan === true ) return; + + panEnd.set( event.clientX, event.clientY ); + panDelta.subVectors( panEnd, panStart ); + + scope.pan( panDelta.x, panDelta.y ); + + panStart.copy( panEnd ); + } - - scope.mouse.copy(newMouse); + + //scope.update(); + } function onMouseUp( /* event */ ) { + + if ( scope.enabled === false ) return; + scope.domElement.removeEventListener( 'mousemove', onMouseMove, false ); scope.domElement.removeEventListener( 'mouseup', onMouseUp, false ); + scope.dispatchEvent( endEvent ); state = STATE.NONE; + } function onMouseWheel( event ) { - + + if ( scope.enabled === false || scope.noZoom === true ) return; + event.preventDefault(); - + var delta = 0; if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9 @@ -2235,90 +2584,196 @@ Potree.OrbitControls = function ( object, domElement ) { delta = - event.detail; } - - scope.zoomSpeed = -Math.sign(delta); - + + if ( delta > 0 ) { + + scope.dollyOut(); + + } else { + + scope.dollyIn(); + + } + + //scope.update(); + scope.dispatchEvent( startEvent ); + scope.dispatchEvent( endEvent ); + } function onKeyDown( event ) { + + if ( scope.enabled === false || scope.noKeys === true || scope.noPan === true ) return; + switch ( event.keyCode ) { + + case scope.keys.UP: + scope.pan( 0, scope.keyPanSpeed ); + //scope.update(); + break; + + case scope.keys.BOTTOM: + scope.pan( 0, - scope.keyPanSpeed ); + //scope.update(); + break; + + case scope.keys.LEFT: + scope.pan( scope.keyPanSpeed, 0 ); + //scope.update(); + break; + + case scope.keys.RIGHT: + scope.pan( - scope.keyPanSpeed, 0 ); + //scope.update(); + break; + + } + } function touchstart( event ) { - if(event.touches.length === 1){ - state = STATE.TOUCH_ROTATE; - - scope.mouse.set(event.touches[ 0 ].pageX, event.touches[ 0 ].pageY); - }else if(event.touches.length === 2){ - state = STATE.TOUCH_DOLLY; - - var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; - var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; - var distance = Math.sqrt( dx * dx + dy * dy ); - scope.dollyStart.set( 0, distance ); - }else if(event.touches.length === 3){ - state = STATE.TOUCH_PAN; - - scope.mouse.set(event.touches[ 0 ].pageX, event.touches[ 0 ].pageY); - }else{ - state = STATE.NONE; + + if ( scope.enabled === false ) return; + + switch ( event.touches.length ) { + + case 1: // one-fingered touch: rotate + + if ( scope.noRotate === true ) return; + + state = STATE.TOUCH_ROTATE; + + rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: // two-fingered touch: dolly + + if ( scope.noZoom === true ) return; + + state = STATE.TOUCH_DOLLY; + + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + var distance = Math.sqrt( dx * dx + dy * dy ); + dollyStart.set( 0, distance ); + break; + + case 3: // three-fingered touch: pan + + if ( scope.noPan === true ) return; + + state = STATE.TOUCH_PAN; + + panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + default: + + state = STATE.NONE; + } + + scope.dispatchEvent( startEvent ); + } function touchmove( event ) { + + if ( scope.enabled === false ) return; + event.preventDefault(); event.stopPropagation(); - - var newMouse = new THREE.Vector2(event.touches[ 0 ].pageX, event.touches[ 0 ].pageY); - var diff = new THREE.Vector2().subVectors(newMouse, scope.mouse); - + var element = scope.domElement === document ? scope.domElement.body : scope.domElement; - - if(event.touches.length === 1){ - - if ( state !== STATE.TOUCH_ROTATE ) return; - - scope.speed.phi -= diff.x / element.clientWidth; - scope.speed.theta -= diff.y / element.clientHeight; - }else if(event.touches.length === 2){ - - if ( state !== STATE.TOUCH_DOLLY ) return; - - var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; - var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; - var distance = Math.sqrt( dx * dx + dy * dy ); - - var dollyEnd = new THREE.Vector2( 0, distance ); - var diff = new THREE.Vector2().subVectors( dollyEnd, scope.dollyStart ); - - scope.zoomSpeed = -20 * diff.y / element.clientHeight; - //scope.zoomSpeed = distance; - - document.getElementById("lblMessage").innerHTML = scope.zoomSpeed; - - scope.dollyStart.copy( dollyEnd ); - - //scope.zoomSpeed = 1; - }else if(event.touches.length === 3){ - - if ( state !== STATE.TOUCH_PAN ) return; - - scope.panSpeed.x = 0.5 * diff.x / element.clientWidth; - scope.panSpeed.y = 0.5 * diff.y / element.clientHeight; - }else{ - state = STATE.NONE; + + switch ( event.touches.length ) { + + case 1: // one-fingered touch: rotate + + if ( scope.noRotate === true ) return; + if ( state !== STATE.TOUCH_ROTATE ) return; + + rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + rotateDelta.subVectors( rotateEnd, rotateStart ); + + // rotating across whole screen goes 360 degrees around + scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed ); + // rotating up and down along whole screen attempts to go 360, but limited to 180 + scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed ); + + rotateStart.copy( rotateEnd ); + + //scope.update(); + break; + + case 2: // two-fingered touch: dolly + + if ( scope.noZoom === true ) return; + if ( state !== STATE.TOUCH_DOLLY ) return; + + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + var distance = Math.sqrt( dx * dx + dy * dy ); + + dollyEnd.set( 0, distance ); + dollyDelta.subVectors( dollyEnd, dollyStart ); + + var ew = element.clientWidth; + var eh = element.clientHeight; + var diagonal = Math.sqrt(ew * ew + eh * eh); + var delta = dollyDelta.y / diagonal; + + if ( dollyDelta.y > 0 ) { + + scope.dollyOut(1 - delta); + + } else { + + scope.dollyIn(1 + delta); + + } + + dollyStart.copy( dollyEnd ); + + //scope.update(); + break; + + case 3: // three-fingered touch: pan + + if ( scope.noPan === true ) return; + if ( state !== STATE.TOUCH_PAN ) return; + + panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + panDelta.subVectors( panEnd, panStart ); + + scope.pan( panDelta.x, panDelta.y ); + + panStart.copy( panEnd ); + + //scope.update(); + break; + + default: + + state = STATE.NONE; + } - - scope.mouse.copy(newMouse); + } - function touchend( event ) { + function touchend( /* event */ ) { + + if ( scope.enabled === false ) return; + + scope.dispatchEvent( endEvent ); state = STATE.NONE; + } this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false ); this.domElement.addEventListener( 'mousedown', onMouseDown, false ); this.domElement.addEventListener( 'mousewheel', onMouseWheel, false ); + this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox this.domElement.addEventListener( 'touchstart', touchstart, false ); this.domElement.addEventListener( 'touchend', touchend, false ); @@ -4120,7 +4575,7 @@ Potree.PointCloudOctree.prototype.createDEM = function(node){ // var end = new Date().getTime(); var duration = end - start; - console.log(node.numPoints + " - " + duration); + //console.log(node.numPoints + " - " + duration); demTime += duration; @@ -4192,8 +4647,8 @@ Potree.PointCloudOctree.prototype.getDEMHeight = function(position){ var stack = []; var chosenNode = null; - if(pointcloud.children[0].dem){ - stack.push(pointcloud.children[0]); + if(this.children[0].dem){ + stack.push(this.children[0]); } while(stack.length > 0){ var node = stack.shift(); @@ -4711,7 +5166,7 @@ function projectedRadius(radius, fov, distance, screenHeight){ }; -function topView(){ +Potree.utils.topView = function(camera, controls, pointcloud){ camera.position.set(0, 1, 0); camera.rotation.set(-Math.PI / 2, 0, 0); camera.zoomTo(pointcloud, 1); @@ -4723,7 +5178,7 @@ function topView(){ } } -function frontView(){ +Potree.utils.frontView = function(camera, controls, pointcloud){ camera.position.set(0, 0, 1); camera.rotation.set(0, 0, 0); camera.zoomTo(pointcloud, 1); @@ -4736,7 +5191,7 @@ function frontView(){ } -function leftView(){ +Potree.utils.leftView = function(camera, controls, pointcloud){ camera.position.set(-1, 0, 0); camera.rotation.set(0, -Math.PI / 2, 0); camera.zoomTo(pointcloud, 1); @@ -4748,7 +5203,7 @@ function leftView(){ } } -function rightView(){ +Potree.utils.rightView = function(camera, controls, pointcloud){ camera.position.set(1, 0, 0); camera.rotation.set(0, Math.PI / 2, 0); camera.zoomTo(pointcloud, 1); @@ -5440,17 +5895,20 @@ Potree.AngleTool = function(scene, camera, renderer){ var measurement = measurements[i]; for(j = 0; j < measurement.spheres.length; j++){ var sphere = measurement.spheres[j]; - wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - w = Math.abs((wp.z / 60)); - sphere.scale.set(w, w, w); + + var distance = scope.camera.position.distanceTo(sphere.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (15 / pr); + sphere.scale.set(scale, scale, scale); } for(j = 0; j < measurement.angleLabels.length; j++){ var label = measurement.angleLabels[j]; - wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - w = Math.abs(wp.z / 5); - var l = label.scale.length(); - label.scale.multiplyScalar(w / l); + + var distance = scope.camera.position.distanceTo(label.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (70 / pr); + label.scale.set(scale, scale, scale); } } @@ -5519,7 +5977,6 @@ Potree.Measure = function(){ }; var dragEvent = function(event){ - var tool = event.tool; var dragstart = tool.dragstart; var mouse = tool.mouse; @@ -5531,7 +5988,7 @@ Potree.Measure = function(){ scope.setPosition(index, I); } - event.event.stopImmediatePropagation(); + //event.event.stopImmediatePropagation(); }; var dropEvent = function(event){ @@ -5543,9 +6000,9 @@ Potree.Measure = function(){ // sphere var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - sphere.addEventListener("mousemove", moveEvent); - sphere.addEventListener("mouseleave", leaveEvent); - sphere.addEventListener("mousedrag", dragEvent); + sphere.addEventListener("move", moveEvent); + sphere.addEventListener("leave", leaveEvent); + sphere.addEventListener("drag", dragEvent); sphere.addEventListener("drop", dropEvent); this.add(sphere); @@ -5674,7 +6131,7 @@ Potree.Measure = function(){ edgeLabel.position.copy(center); edgeLabel.setText(distance.toFixed(2)); - edgeLabel.visible = this.showDistances && (index < lastIndex || this.closed) && this.points.length >= 2; + edgeLabel.visible = this.showDistances && (index < lastIndex || this.closed) && this.points.length >= 2 && distance > 0; } } @@ -5786,14 +6243,15 @@ Potree.MeasuringTool = function(scene, camera, renderer){ } }; - function onMouseMove(event){ + function onMouseMove(event){ + var rect = scope.domElement.getBoundingClientRect(); scope.mouse.x = ((event.clientX - rect.left) / scope.domElement.clientWidth) * 2 - 1; scope.mouse.y = -((event.clientY - rect.top) / scope.domElement.clientHeight) * 2 + 1; if(scope.dragstart){ var arg = { - type: "mousedrag", + type: "drag", event: event, tool: scope }; @@ -5813,10 +6271,10 @@ Potree.MeasuringTool = function(scene, camera, renderer){ if(I){ - I.object.dispatchEvent({type: "mousemove", target: I.object, event: event}); + I.object.dispatchEvent({type: "move", target: I.object, event: event}); if(scope.hoveredElement && scope.hoveredElement !== I.object){ - scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event}); + scope.hoveredElement.dispatchEvent({type: "leave", target: scope.hoveredElement, event: event}); } scope.hoveredElement = I.object; @@ -5824,7 +6282,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ }else{ if(scope.hoveredElement){ - scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event}); + scope.hoveredElement.dispatchEvent({type: "leave", target: scope.hoveredElement, event: event}); } scope.hoveredElement = null; @@ -5839,7 +6297,14 @@ Potree.MeasuringTool = function(scene, camera, renderer){ } } + this.getState = function(){ + // TODO remove + + return state; + } + function onMouseDown(event){ + if(event.which === 1){ if(state !== STATE.DEFAULT){ @@ -5866,8 +6331,25 @@ Potree.MeasuringTool = function(scene, camera, renderer){ } } - function onMouseUp(event){ + function onDoubleClick(event){ + // fix move event after double click + // see: http://stackoverflow.com/questions/8125165/event-listener-for-dblclick-causes-event-for-mousemove-to-not-work-and-show-a-ci + if (window.getSelection){ + window.getSelection().removeAllRanges(); + }else if (document.selection){ + document.selection.empty(); + } + + + if(scope.activeMeasurement && state === STATE.INSERT){ + scope.activeMeasurement.removeMarker(scope.activeMeasurement.points.length-1); + scope.finishInsertion(); + } + } + + function onMouseUp(event){ + if(scope.dragstart){ scope.dragstart.object.dispatchEvent({type: "drop", event: event}); scope.dragstart = null; @@ -6024,6 +6506,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ }; this.domElement.addEventListener( 'click', onClick, false); + this.domElement.addEventListener( 'dblclick', onDoubleClick, false); this.domElement.addEventListener( 'mousemove', onMouseMove, false ); this.domElement.addEventListener( 'mousedown', onMouseDown, false ); this.domElement.addEventListener( 'mouseup', onMouseUp, true ); @@ -6047,9 +6530,6 @@ Potree.HeightProfile = function(){ this.height = 20; this._modifiable = true; - this.camera = camera; - this.renderer = renderer; - var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); var lineColor = new THREE.Color( 0xff0000 ); @@ -6153,6 +6633,12 @@ Potree.HeightProfile = function(){ } this.setPosition(this.points.length-1, point); + + var event = { + "type": "marker_added", + "profile": this + }; + this.dispatchEvent(event); }; this.removeMarker = function(index){ @@ -6169,6 +6655,12 @@ Potree.HeightProfile = function(){ this.spheres.splice(index, 1); this.update(); + + var event = { + "type": "marker_removed", + "profile": this + }; + this.dispatchEvent(event); }; /** @@ -6490,6 +6982,22 @@ Potree.ProfileTool = function(scene, camera, renderer){ } } + function onDoubleClick(event){ + + // fix move event after double click + // see: http://stackoverflow.com/questions/8125165/event-listener-for-dblclick-causes-event-for-mousemove-to-not-work-and-show-a-ci + if (window.getSelection){ + window.getSelection().removeAllRanges(); + }else if (document.selection){ + document.selection.empty(); + } + + if(scope.activeProfile && state === STATE.INSERT){ + scope.activeProfile.removeMarker(scope.activeProfile.points.length-1); + scope.finishInsertion(); + } + } + function onMouseUp(event){ if(scope.dragstart){ @@ -6562,9 +7070,10 @@ Potree.ProfileTool = function(scene, camera, renderer){ this.activeProfile = new Potree.HeightProfile(); this.activeProfile.clip = clip; this.activeProfile.setWidth(width); - this.sceneProfile.add(this.activeProfile); - this.profiles.push(this.activeProfile); + this.addProfile(this.activeProfile); this.activeProfile.addMarker(new THREE.Vector3(0,0,0)); + + return this.activeProfile; }; this.finishInsertion = function(){ @@ -6577,6 +7086,14 @@ Potree.ProfileTool = function(scene, camera, renderer){ this.profiles.push(profile); this.sceneProfile.add(profile); profile.update(); + + this.dispatchEvent({"type": "profile_added", profile: profile}); + profile.addEventListener("marker_added", function(event){ + scope.dispatchEvent(event); + }); + profile.addEventListener("marker_removed", function(event){ + scope.dispatchEvent(event); + }); }; this.removeProfile = function(profile){ @@ -6585,6 +7102,8 @@ Potree.ProfileTool = function(scene, camera, renderer){ if(index >= 0){ this.profiles.splice(index, 1); } + + this.dispatchEvent({"type": "profile_removed", profile: profile}); } this.update = function(){ @@ -6593,10 +7112,11 @@ Potree.ProfileTool = function(scene, camera, renderer){ var profile = this.profiles[i]; for(var j = 0; j < profile.spheres.length; j++){ var sphere = profile.spheres[j]; - var wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix); - var w = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w); - sphere.scale.set(w, w, w); + + var distance = scope.camera.position.distanceTo(sphere.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (15 / pr); + sphere.scale.set(scale, scale, scale); } } @@ -6611,6 +7131,7 @@ Potree.ProfileTool = function(scene, camera, renderer){ }; this.domElement.addEventListener( 'click', onClick, false); + this.domElement.addEventListener( 'dblclick', onDoubleClick, false); this.domElement.addEventListener( 'mousemove', onMouseMove, false ); this.domElement.addEventListener( 'mousedown', onMouseDown, false ); this.domElement.addEventListener( 'mouseup', onMouseUp, true ); @@ -7671,13 +8192,12 @@ Potree.VolumeTool = function(scene, camera, renderer){ var capacity = volume.volume(); var msg = Potree.utils.addCommas(capacity.toFixed(1)) + "³"; - - var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(this.camera.projectionMatrix); - var w = Math.abs(wp.z / 5); label.setText(msg); - var l = label.scale.length(); - label.scale.multiplyScalar(w / l); + + var distance = scope.camera.position.distanceTo(label.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (70 / pr); + label.scale.set(scale, scale, scale); } }; diff --git a/build/js/potree.min.js b/build/js/potree.min.js index 24454e88..39f8e997 100644 --- a/build/js/potree.min.js +++ b/build/js/potree.min.js @@ -1,5 +1,5 @@ -function Potree(){}function POCLoader(){}function PointAttribute(e,t,o){this.name=e,this.type=t,this.numElements=o,this.byteSize=this.numElements*this.type.size}function PointAttributes(e){if(this.attributes=new Array,this.byteSize=0,this.size=0,null!=e)for(var t=0;tu)&&(a=h,l=u)}}return a?a.position:null}function pixelsArrayToImage(e,t,o){var i=document.createElement("canvas");i.width=t,i.height=o;var n=i.getContext("2d");e=new e.constructor(e);for(var r=0;r=n?o.pointsCount:o.pointsCount/n,a=function(){var e=t.readData(1e6,0,n);return e.then(function(e){return i.push(new LASDecoder(e.buffer,o.pointsFormatId,o.pointsStructSize,e.count,o.scale,o.offset,o.mins,o.maxs)),r+=e.count,Potree.LasLazLoader.progressCB(r/s),e.hasMoreData?a():(o.totalRead=r,o.versionAsString=t.versionAsString,o.isCompressed=t.isCompressed,[t,o,i])})};return a()}).then(function(e){var t=e[0];return Potree.LasLazLoader.progressCB(1),t.close().then(function(){return t.isOpen=!1,Promise.delay(200).cancellable()}).then(function(){return e.slice(1)})})["catch"](Promise.CancellationError,function(e){if(o.isOpen)return o.close().then(function(){throw o.isOpen=!1,e});throw e})},Potree.LasLazLoader.prototype.handle=function(){},Potree.LasLazBatcher=function(e){this.push=function(t){var o=Potree.workers.lasdecoder.getWorker(),i=new THREE.Vector3(t.mins[0],t.mins[1],t.mins[2]),n=new THREE.Vector3(t.maxs[0],t.maxs[1],t.maxs[2]);i.add(e.pcoGeometry.offset),n.add(e.pcoGeometry.offset),o.onmessage=function(r){for(var s=new THREE.BufferGeometry,a=t.pointsCount,l=r.data.position,c=r.data.color,d=r.data.intensity,h=new Uint8Array(r.data.classification),u=new Float32Array(h.byteLength),p=new Uint8Array(r.data.returnNumber),m=new Float32Array(p.byteLength),v=new Uint16Array(r.data.pointSourceID),E=new Float32Array(v.length),f=new ArrayBuffer(4*a),g=new Uint32Array(f),y=new THREE.Box3,b=new Float32Array(l),T=0;a>T;T++)u[T]=h[T],m[T]=p[T],E[T]=v[T],g[T]=T,y.expandByPoint(new THREE.Vector3(b[3*T+0],b[3*T+1],b[3*T+2]));s.addAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),s.addAttribute("color",new THREE.BufferAttribute(new Float32Array(c),3)),s.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(d),1)),s.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(u),1)),s.addAttribute("returnNumber",new THREE.BufferAttribute(new Float32Array(m),1)),s.addAttribute("pointSourceID",new THREE.BufferAttribute(new Float32Array(E),1)),s.addAttribute("indices",new THREE.BufferAttribute(f,1)),s.boundingBox=new THREE.Box3(i,n),e.boundingBox=s.boundingBox,e.geometry=s,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(o)};var r={buffer:t.arrayb,numPoints:t.pointsCount,pointSize:t.pointSize,pointFormatID:2,scale:t.scale,offset:t.offset,mins:[e.pcoGeometry.boundingBox.min.x,e.pcoGeometry.boundingBox.min.y,e.pcoGeometry.boundingBox.min.z],maxs:[e.pcoGeometry.boundingBox.max.x,e.pcoGeometry.boundingBox.max.y,e.pcoGeometry.boundingBox.max.z],bbOffset:[e.pcoGeometry.offset.x,e.pcoGeometry.offset.y,e.pcoGeometry.offset.z]};o.postMessage(r,[r.buffer])}},Potree.PointSizeType={FIXED:0,ATTENUATED:1,ADAPTIVE:2},Potree.PointShape={SQUARE:0,CIRCLE:1},Potree.PointColorType={RGB:0,COLOR:1,DEPTH:2,HEIGHT:3,INTENSITY:4,INTENSITY_GRADIENT:5,OCTREE_DEPTH:6,POINT_INDEX:7,CLASSIFICATION:8,RETURN_NUMBER:9,SOURCE:10},Potree.ClipMode={DISABLED:0,CLIP_OUTSIDE:1,HIGHLIGHT_INSIDE:2},Potree.PointCloudMaterial=function(e){e=e||{};var t=new THREE.Color(0),o=THREE.ImageUtils.generateDataTexture(2048,1,t);o.magFilter=THREE.NearestFilter,this.visibleNodesTexture=o;var i=e.size||1,n=e.minSize||1,r=1;this._pointSizeType=Potree.PointSizeType.ATTENUATED,this._pointShape=Potree.PointShape.SQUARE,this._interpolate=!1,this._pointColorType=Potree.PointColorType.RGB,this._octreeLevels=6,this._useClipBox=!1,this.numClipBoxes=0,this._clipMode=Potree.ClipMode.DISABLED,this._weighted=!1,this._blendDepth=.1,this._depthMap,this.gradientTexture=Potree.PointCloudMaterial.generateGradient();var s={},a={spacing:{type:"f",value:1},fov:{type:"f",value:1},screenWidth:{type:"f",value:1},screenHeight:{type:"f",value:1},near:{type:"f",value:.1},far:{type:"f",value:1},uColor:{type:"c",value:new THREE.Color(16711680)},opacity:{type:"f",value:1},size:{type:"f",value:10},minSize:{type:"f",value:2},nodeSize:{type:"f",value:r},heightMin:{type:"f",value:0},heightMax:{type:"f",value:1},intensityMin:{type:"f",value:0},intensityMax:{type:"f",value:1},visibleNodes:{type:"t",value:this.visibleNodesTexture},pcIndex:{type:"f",value:0},gradient:{type:"t",value:this.gradientTexture},clipBoxes:{type:"Matrix4fv",value:[]},blendDepth:{type:"f",value:this._blendDepth},depthMap:{type:"t",value:null}};this.setValues({uniforms:a,attributes:s,vertexShader:this.getDefines()+Potree.PointCloudMaterial.vs_points.join("\n"),fragmentShader:this.getDefines()+Potree.PointCloudMaterial.fs_points_rgb.join("\n"),vertexColors:THREE.VertexColors,size:i,minSize:n,nodeSize:r,pcIndex:0,alphaTest:.9})},Potree.PointCloudMaterial.prototype=new THREE.RawShaderMaterial,Potree.PointCloudMaterial.prototype.updateShaderSource=function(){var e={};this.pointColorType===Potree.PointColorType.INTENSITY||this.pointColorType===Potree.PointColorType.INTENSITY_GRADIENT?e.intensity={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.CLASSIFICATION?e.classification={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.RETURN_NUMBER?e.returnNumber={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.SOURCE&&(e.pointSourceID={type:"f",value:[]}),this.setValues({attributes:e,vertexShader:this.getDefines()+Potree.PointCloudMaterial.vs_points.join("\n"),fragmentShader:this.getDefines()+Potree.PointCloudMaterial.fs_points_rgb.join("\n")}),this.depthMap&&(this.uniforms.depthMap.value=this.depthMap,this.setValues({depthMap:this.depthMap})),this.setValues(1===this.opacity?{blending:THREE.NoBlending,transparent:!1,depthTest:!0,depthWrite:!0}:{blending:THREE.AdditiveBlending,transparent:!0,depthTest:!1,depthWrite:!0}),this.weighted&&this.setValues({blending:THREE.AdditiveBlending,transparent:!0,depthTest:!0,depthWrite:!1}),this.needsUpdate=!0},Potree.PointCloudMaterial.prototype.getDefines=function(){var e="";return this.pointSizeType===Potree.PointSizeType.FIXED?e+="#define fixed_point_size\n":this.pointSizeType===Potree.PointSizeType.ATTENUATED?e+="#define attenuated_point_size\n":this.pointSizeType===Potree.PointSizeType.ADAPTIVE&&(e+="#define adaptive_point_size\n",e+="#define octreeLevels "+Math.max(0,this._octreeLevels-2).toFixed(1)+"\n"),this.pointShape===Potree.PointShape.SQUARE?e+="#define square_point_shape\n":this.pointShape===Potree.PointShape.CIRCLE&&(e+="#define circle_point_shape\n"),this._interpolate&&(e+="#define use_interpolation\n"),this._pointColorType===Potree.PointColorType.RGB?e+="#define color_type_rgb\n":this._pointColorType===Potree.PointColorType.COLOR?e+="#define color_type_color\n":this._pointColorType===Potree.PointColorType.DEPTH?e+="#define color_type_depth\n":this._pointColorType===Potree.PointColorType.HEIGHT?e+="#define color_type_height\n":this._pointColorType===Potree.PointColorType.INTENSITY?e+="#define color_type_intensity\n":this._pointColorType===Potree.PointColorType.INTENSITY_GRADIENT?e+="#define color_type_intensity_gradient\n":this._pointColorType===Potree.PointColorType.OCTREE_DEPTH?e+="#define color_type_octree_depth\n":this._pointColorType===Potree.PointColorType.POINT_INDEX?e+="#define color_type_point_index\n":this._pointColorType===Potree.PointColorType.CLASSIFICATION?e+="#define color_type_classification\n":this._pointColorType===Potree.PointColorType.RETURN_NUMBER?e+="#define color_type_return_number\n":this._pointColorType===Potree.PointColorType.SOURCE&&(e+="#define color_type_source\n"),this.clipMode===Potree.ClipMode.DISABLED?e+="#define clip_disabled\n":this.clipMode===Potree.ClipMode.CLIP_OUTSIDE?e+="#define clip_outside\n":this.clipMode===Potree.ClipMode.HIGHLIGHT_INSIDE&&(e+="#define clip_highlight_inside\n"),this.weighted&&(e+="#define weighted_splats\n"),this.numClipBoxes>0&&(e+="#define use_clip_box\n",e+="#define clip_box_count "+this.numClipBoxes+"\n"),e},Potree.PointCloudMaterial.prototype.setClipBoxes=function(e){var t=e.length;this.numClipBoxes=t,this.uniforms.clipBoxes.value.length/16!==t&&(this.uniforms.clipBoxes.value=new Float32Array(16*t),this.updateShaderSource()); -for(var o=0;t>o;o++){var i=e[o];this.uniforms.clipBoxes.value.set(i.elements,16*o)}},Object.defineProperty(Potree.PointCloudMaterial.prototype,"spacing",{get:function(){return this.uniforms.spacing.value},set:function(e){this.uniforms.spacing.value!==e&&(this.uniforms.spacing.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"blendDepth",{get:function(){return this.uniforms.blendDepth.value},set:function(e){this.uniforms.blendDepth.value!==e&&(this.uniforms.blendDepth.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"useClipBox",{get:function(){return this._useClipBox},set:function(e){this._useClipBox!==e&&(this._useClipBox=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"weighted",{get:function(){return this._weighted},set:function(e){this._weighted!==e&&(this._weighted=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"fov",{get:function(){return this.uniforms.fov.value},set:function(e){this.uniforms.fov.value!==e&&(this.uniforms.fov.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"screenWidth",{get:function(){return this.uniforms.screenWidth.value},set:function(e){this.uniforms.screenWidth.value!==e&&(this.uniforms.screenWidth.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"screenHeight",{get:function(){return this.uniforms.screenHeight.value},set:function(e){this.uniforms.screenHeight.value!==e&&(this.uniforms.screenHeight.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"near",{get:function(){return this.uniforms.near.value},set:function(e){this.uniforms.near.value!==e&&(this.uniforms.near.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"far",{get:function(){return this.uniforms.far.value},set:function(e){this.uniforms.far.value!==e&&(this.uniforms.far.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"opacity",{get:function(){return this.uniforms.opacity.value},set:function(e){this.uniforms.opacity.value!==e&&(this.uniforms.opacity.value=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"octreeLevels",{get:function(){return this._octreeLevels},set:function(e){this._octreeLevels!==e&&(this._octreeLevels=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointColorType",{get:function(){return this._pointColorType},set:function(e){this._pointColorType!==e&&(this._pointColorType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"depthMap",{get:function(){return this._depthMap},set:function(e){this._depthMap!==e&&(this._depthMap=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointSizeType",{get:function(){return this._pointSizeType},set:function(e){this._pointSizeType!==e&&(this._pointSizeType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"clipMode",{get:function(){return this._clipMode},set:function(e){this._clipMode!==e&&(this._clipMode=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"interpolate",{get:function(){return this._interpolate},set:function(e){this._interpolate!==e&&(this._interpolate=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"color",{get:function(){return this.uniforms.uColor.value},set:function(e){this.uniforms.uColor.value!==e&&(this.uniforms.uColor.value.copy(e),this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointShape",{get:function(){return this._pointShape},set:function(e){this._pointShape!==e&&(this._pointShape=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"size",{get:function(){return this.uniforms.size.value},set:function(e){this.uniforms.size.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"minSize",{get:function(){return this.uniforms.minSize.value},set:function(e){this.uniforms.minSize.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"heightMin",{get:function(){return this.uniforms.heightMin.value},set:function(e){this.uniforms.heightMin.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"heightMax",{get:function(){return this.uniforms.heightMax.value},set:function(e){this.uniforms.heightMax.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"intensityMin",{get:function(){return this.uniforms.intensityMin.value},set:function(e){this.uniforms.intensityMin.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"intensityMax",{get:function(){return this.uniforms.intensityMax.value},set:function(e){this.uniforms.intensityMax.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pcIndex",{get:function(){return this.uniforms.pcIndex.value},set:function(e){this.uniforms.pcIndex.value=e}}),Potree.PointCloudMaterial.generateGradient=function(){var e=64;canvas=document.createElement("canvas"),canvas.width=e,canvas.height=e;var t=canvas.getContext("2d");t.rect(0,0,e,e);var o=t.createLinearGradient(0,0,e,e);o.addColorStop(0,"#4700b6"),o.addColorStop(1/6,"blue"),o.addColorStop(2/6,"aqua"),o.addColorStop(.5,"green"),o.addColorStop(4/6,"yellow"),o.addColorStop(5/6,"orange"),o.addColorStop(1,"red"),t.fillStyle=o,t.fill();var i=new THREE.Texture(canvas);return i.needsUpdate=!0,textureImage=i.image,i},Potree.PointCloudMaterial.vs_points=["precision mediump float; ","precision mediump int; "," ","attribute vec3 position; ","attribute vec3 color; ","attribute float intensity; ","attribute float classification; ","attribute float returnNumber; ","attribute float pointSourceID; ","attribute vec4 indices; "," ","uniform mat4 modelMatrix; ","uniform mat4 modelViewMatrix; ","uniform mat4 projectionMatrix; ","uniform mat4 viewMatrix; ","uniform mat3 normalMatrix; ","uniform vec3 cameraPosition; ","uniform float screenWidth; ","uniform float screenHeight; ","uniform float fov; ","uniform float spacing; ","uniform float blendDepth; ","uniform float near; ","uniform float far; "," ","#if defined use_clip_box "," uniform mat4 clipBoxes[clip_box_count]; ","#endif "," "," ","uniform float heightMin; ","uniform float heightMax; ","uniform float intensityMin; ","uniform float intensityMax; ","uniform float size; ","uniform float minSize; ","uniform float nodeSize; ","uniform vec3 uColor; ","uniform float opacity; "," "," ","uniform sampler2D visibleNodes; ","uniform sampler2D gradient; ","uniform sampler2D depthMap; "," ","varying float vOpacity; ","varying vec3 vColor; ","varying float vDepth; ","varying float vLinearDepth; ","varying vec3 vViewPos; ","varying float vRadius; "," "," ","#if defined(adaptive_point_size) || defined(color_type_octree_depth) ","/** "," * number of 1-bits up to inclusive index position "," * number is treated as if it were an integer in the range 0-255 "," * "," */ ","float numberOfOnes(float number, float index){ "," float tmp = mod(number, pow(2.0, index + 1.0)); "," float numOnes = 0.0; "," for(float i = 0.0; i < 8.0; i++){ "," if(mod(tmp, 2.0) != 0.0){ "," numOnes++; "," } "," tmp = floor(tmp / 2.0); "," } "," return numOnes; ","} "," "," ","/** "," * checks whether the bit at index is 1 "," * number is treated as if it were an integer in the range 0-255 "," * "," */ ","bool isBitSet(float number, float index){ "," return mod(floor(number / pow(2.0, index)), 2.0) != 0.0; ","} "," "," ","/** "," * find the octree depth at the point position "," */ ","float getOctreeDepth(){ "," vec3 offset = vec3(0.0, 0.0, 0.0); "," float iOffset = 0.0; "," float depth = 0.0; "," for(float i = 0.0; i <= octreeLevels + 1.0; i++){ "," "," float nodeSizeAtLevel = nodeSize / pow(2.0, i); "," vec3 index3d = (position - offset) / nodeSizeAtLevel; "," index3d = floor(index3d + 0.5); "," float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z; "," "," vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0)); "," float mask = value.r * 255.0; "," if(isBitSet(mask, index)){ "," // there are more visible child nodes at this position "," iOffset = iOffset + value.g * 255.0 + numberOfOnes(mask, index - 1.0); "," depth++; "," }else{ "," // no more visible child nodes at this position "," return depth; "," } "," offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; "," } "," "," return depth; ","} "," ","#endif "," ","vec3 classificationColor(float classification){ "," vec3 color = vec3(0.0, 0.0, 0.0); "," float c = mod(classification, 16.0); "," if(c == 0.0){ "," color = vec3(0.5, 0.5, 0.5); "," }else if(c == 1.0){ "," color = vec3(0.5, 0.5, 0.5); "," }else if(c == 2.0){ "," color = vec3(0.63, 0.32, 0.18); "," }else if(c == 3.0){ "," color = vec3(0.0, 1.0, 0.0); "," }else if(c == 4.0){ "," color = vec3(0.0, 0.8, 0.0); "," }else if(c == 5.0){ "," color = vec3(0.0, 0.6, 0.0); "," }else if(c == 6.0){ "," color = vec3(1.0, 0.66, 0.0); "," }else if(c == 7.0){ "," color = vec3(1.0, 0, 1.0); "," }else if(c == 8.0){ "," color = vec3(1.0, 0, 0.0); "," }else if(c == 9.0){ "," color = vec3(0.0, 0.0, 1.0); "," }else if(c == 12.0){ "," color = vec3(1.0, 1.0, 0.0); "," }else{ "," color = vec3(0.3, 0.6, 0.6); "," } "," "," return color; ","} "," ","void main() { "," "," vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); "," vViewPos = mvPosition.xyz; "," gl_Position = projectionMatrix * mvPosition; "," //float pw = gl_Position.w; "," //float pd = gl_Position.z; "," //gl_Position = gl_Position / pw; "," //gl_Position.z = 2.0*((pw - near) / far)-1.0; "," vOpacity = opacity; "," vLinearDepth = -mvPosition.z; "," vDepth = mvPosition.z / gl_Position.w; "," "," // COLOR TYPES "," "," #ifdef color_type_rgb "," vColor = color; "," #elif defined color_type_height "," vec4 world = modelMatrix * vec4( position, 1.0 ); "," float w = (world.y - heightMin) / (heightMax-heightMin); "," "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_depth "," float d = -mvPosition.z ; "," vColor = vec3(d, vDepth, 0.0); "," #elif defined color_type_intensity "," float w = (intensity - intensityMin) / (intensityMax - intensityMin); "," vColor = vec3(w, w, w); "," #elif defined color_type_intensity_gradient "," float w = (intensity - intensityMin) / intensityMax; "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_color "," vColor = uColor; "," #elif defined color_type_octree_depth "," float depth = getOctreeDepth(); "," float w = depth / 10.0; "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_point_index "," vColor = indices.rgb; "," #elif defined color_type_classification "," vColor = classificationColor(classification); "," #elif defined color_type_return_number "," float w = (returnNumber - 1.0) / 4.0 + 0.1; "," vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb; "," #elif defined color_type_source "," float w = mod(pointSourceID, 10.0) / 10.0; "," vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb; "," #endif "," "," "," "," // "," // POINT SIZE TYPES "," // "," float projFactor = 1.0 / tan(fov / 2.0); "," projFactor /= -vViewPos.z; "," projFactor *= screenHeight / 2.0; "," float r = spacing * 1.5; "," vRadius = r; "," #if defined fixed_point_size "," gl_PointSize = size; "," #elif defined attenuated_point_size "," gl_PointSize = size * projFactor; "," #elif defined adaptive_point_size "," float worldSpaceSize = size * r / pow(1.9, getOctreeDepth()); "," gl_PointSize = worldSpaceSize * projFactor; "," #endif "," "," gl_PointSize = max(minSize, gl_PointSize); "," gl_PointSize = min(50.0, gl_PointSize); "," "," vRadius = gl_PointSize / projFactor; "," "," "," // clip box "," #if defined use_clip_box "," bool insideAny = false; "," for(int i = 0; i < clip_box_count; i++){ "," vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 ); "," bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5; "," inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5; "," inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5; "," insideAny = insideAny || inside; "," } "," if(!insideAny){ "," "," #if defined clip_outside "," gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0); "," #elif defined clip_highlight_inside && !defined(color_type_depth) "," float c = (vColor.r + vColor.g + vColor.b) / 6.0; "," //vColor = vec3(c, c, c); "," #endif "," }else{ "," #if defined clip_highlight_inside "," vColor.r += 0.5; "," #endif "," } "," "," #endif "," "," ","} "],Potree.PointCloudMaterial.fs_points_rgb=["#if defined use_interpolation "," #extension GL_EXT_frag_depth : enable ","#endif "," ","precision mediump float; ","precision mediump int; "," ","//uniform float opacity; ","uniform mat4 modelMatrix; ","uniform mat4 modelViewMatrix; ","uniform mat4 projectionMatrix; ","uniform mat4 viewMatrix; ","uniform mat3 normalMatrix; ","uniform vec3 cameraPosition; ","uniform float fov; ","uniform float spacing; ","uniform float near; ","uniform float far; "," ","uniform float pcIndex; ","uniform float screenWidth; ","uniform float screenHeight; ","uniform float blendDepth; "," ","uniform sampler2D depthMap; "," ","varying vec3 vColor; ","varying float vOpacity; ","varying float vLinearDepth; ","varying float vDepth; ","varying vec3 vViewPos; ","varying float vRadius; "," "," ","void main() { "," "," #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats) "," float u = 2.0 * gl_PointCoord.x - 1.0; "," float v = 2.0 * gl_PointCoord.y - 1.0; "," #endif "," "," #if defined(circle_point_shape) || defined (weighted_splats) "," float cc = u*u + v*v; "," if(cc > 1.0){ "," discard; "," } "," #endif "," "," #if defined weighted_splats "," vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight); "," "," float depth = texture2D(depthMap, uv).r; "," if(vLinearDepth > depth + vRadius * 0.5){ "," discard; "," } "," #endif "," "," #if defined use_interpolation "," float w = 1.0 - ( u*u + v*v); "," vec4 pos = vec4(vViewPos, 1.0); "," pos.z += w * vRadius; "," pos = projectionMatrix * pos; "," pos = pos / pos.w; "," "," gl_FragDepthEXT = (pos.z + 1.0) / 2.0; "," #endif "," "," "," #if defined color_type_point_index "," gl_FragColor = vec4(vColor, pcIndex / 255.0); "," #else "," gl_FragColor = vec4(vColor, vOpacity); "," #endif "," "," "," #if defined weighted_splats "," float w = pow(1.0 - (u*u + v*v), 2.0); "," gl_FragColor.rgb = gl_FragColor.rgb * w; "," gl_FragColor.a = w; "," #endif "," "," "," ","} "],THREE.FirstPersonControls=function(e,t){function o(e){l.enabled!==!1&&(e.preventDefault(),0===e.button?(R=T.ROTATE,c.set(e.clientX,e.clientY)):2===e.button&&(R=T.PAN,u.set(e.clientX,e.clientY)),l.domElement.addEventListener("mousemove",i,!1),l.domElement.addEventListener("mouseup",n,!1),l.dispatchEvent(w)) -}function i(e){if(l.enabled!==!1){e.preventDefault();var t=l.domElement===document?l.domElement.body:l.domElement;R===T.ROTATE?(d.set(e.clientX,e.clientY),h.subVectors(d,c),l.rotateLeft(2*Math.PI*h.x/t.clientWidth*l.rotateSpeed),l.rotateUp(2*Math.PI*h.y/t.clientHeight*l.rotateSpeed),c.copy(d)):R===T.PAN&&(p.set(e.clientX,e.clientY),m.subVectors(p,u),m.multiplyScalar(5e-4).multiplyScalar(l.moveSpeed),l.pan(m.x,m.y),u.copy(p))}}function n(){l.enabled!==!1&&(l.domElement.removeEventListener("mousemove",i,!1),l.domElement.removeEventListener("mouseup",n,!1),l.dispatchEvent(C),R=T.NONE)}function r(e){if(l.enabled!==!1&&l.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1;l.moveSpeed+=.1*l.moveSpeed*t,l.moveSpeed=Math.max(.1,l.moveSpeed),l.dispatchEvent(w),l.dispatchEvent(C)}}function s(e){if(l.enabled!==!1)switch(e.keyCode){case l.keys.UP:l.moveForward=!0;break;case l.keys.BOTTOM:l.moveBackward=!0;break;case l.keys.LEFT:l.moveLeft=!0;break;case l.keys.RIGHT:l.moveRight=!0;break;case l.keys.W:l.moveForward=!0;break;case l.keys.S:l.moveBackward=!0;break;case l.keys.A:l.moveLeft=!0;break;case l.keys.D:l.moveRight=!0}}function a(e){switch(e.keyCode){case l.keys.W:l.moveForward=!1;break;case l.keys.S:l.moveBackward=!1;break;case l.keys.A:l.moveLeft=!1;break;case l.keys.D:l.moveRight=!1;break;case l.keys.UP:l.moveForward=!1;break;case l.keys.BOTTOM:l.moveBackward=!1;break;case l.keys.LEFT:l.moveLeft=!1;break;case l.keys.RIGHT:l.moveRight=!1}}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.rotateSpeed=1,this.moveSpeed=10,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40,A:"A".charCodeAt(0),S:"S".charCodeAt(0),D:"D".charCodeAt(0),W:"W".charCodeAt(0)};var l=this,c=new THREE.Vector2,d=new THREE.Vector2,h=new THREE.Vector2,u=new THREE.Vector2,p=new THREE.Vector2,m=new THREE.Vector2,v=new THREE.Vector3,E=(new THREE.Vector3,0),f=0,g=1,y=new THREE.Vector3,b=new THREE.Vector3,T={NONE:-1,ROTATE:0,SPEEDCHANGE:1,PAN:2},R=T.NONE;this.position0=this.object.position.clone();var P={type:"change"},w={type:"start"},C={type:"end"};this.rotateLeft=function(e){f-=e},this.rotateUp=function(e){E-=e},this.panLeft=function(e){var t=this.object.matrix.elements;v.set(t[0],t[1],t[2]),v.multiplyScalar(-e),y.add(v)},this.panUp=function(e){var t=this.object.matrix.elements;v.set(t[4],t[5],t[6]),v.multiplyScalar(e),y.add(v)},this.panForward=function(e){var t=this.object.matrix.elements;v.set(t[8],t[9],t[10]),v.multiplyScalar(e),y.add(v)},this.pan=function(e,t){var o=l.domElement===document?l.domElement.body:l.domElement;if(void 0!==l.object.fov){var i=l.object.position,n=i.clone(),r=n.length();r*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*r/o.clientHeight),l.panUp(2*t*r/o.clientHeight)}else void 0!==l.object.top?(l.panLeft(e*(l.object.right-l.object.left)/o.clientWidth),l.panUp(t*(l.object.top-l.object.bottom)/o.clientHeight)):console.warn("WARNING: FirstPersonControls.js encountered an unknown camera type - pan disabled.")},this.update=function(e){this.object.rotation.order="ZYX";var t=this.object;this.object=new THREE.Object3D,this.object.position.copy(t.position),this.object.rotation.copy(t.rotation),this.object.updateMatrix(),this.object.updateMatrixWorld();var o=this.object.position;if(void 0!==e&&(this.moveRight&&this.panLeft(-e*this.moveSpeed),this.moveLeft&&this.panLeft(e*this.moveSpeed),this.moveForward&&this.panForward(-e*this.moveSpeed),this.moveBackward&&this.panForward(e*this.moveSpeed)),!y.equals(new THREE.Vector3(0,0,0))){var i={type:"move",translation:y.clone()};this.dispatchEvent(i)}if(o.add(y),0!==f||0!==E){var i={type:"rotate",thetaDelta:f,phiDelta:E};this.dispatchEvent(i)}this.object.updateMatrix();var n=(new THREE.Matrix4).makeRotationY(f),r=(new THREE.Matrix4).multiplyMatrices(n,this.object.matrix);this.object.quaternion.setFromRotationMatrix(r),this.object.rotation.x+=E,this.object.updateMatrixWorld();var s={type:"proposeTransform",oldPosition:t.position,newPosition:this.object.position,objections:0};this.dispatchEvent(s),s.objections>0||t.position.copy(this.object.position),t.rotation.copy(this.object.rotation),this.object=t,f=0,E=0,g=1,y.set(0,0,0),b.distanceTo(this.object.position)>0&&(this.dispatchEvent(P),b.copy(this.object.position))},this.reset=function(){R=T.NONE,this.object.position.copy(this.position0)},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",r,!1),this.domElement.addEventListener("DOMMouseScroll",r,!1),window.addEventListener("keydown",s,!1),window.addEventListener("keyup",a,!1)},THREE.FirstPersonControls.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.OrbitControls=function(e,t){function o(e){0===e.button?u=h.ROTATE:1===e.button?u=h.DOLLY:2===e.button&&(u=h.PAN),d.mouse.set(e.clientX,e.clientY),d.domElement.addEventListener("mousemove",i,!1),d.domElement.addEventListener("mouseup",n,!1)}function i(e){e.preventDefault();var t=d.domElement===document?d.domElement.body:d.domElement,o=new THREE.Vector2(e.clientX,e.clientY),i=(new THREE.Vector2).subVectors(o,d.mouse);u===h.ROTATE?(d.speed.phi-=i.x/t.clientWidth,d.speed.theta-=i.y/t.clientHeight):u===h.DOLLY?d.zoomSpeed=20*i.y/t.clientHeight:u===h.PAN&&(d.panSpeed.x=i.x/t.clientWidth,d.panSpeed.y=i.y/t.clientHeight),d.mouse.copy(o)}function n(){d.domElement.removeEventListener("mousemove",i,!1),d.domElement.removeEventListener("mouseup",n,!1),u=h.NONE}function r(e){e.preventDefault();var t=0;void 0!==e.wheelDelta?t=e.wheelDelta:void 0!==e.detail&&(t=-e.detail),d.zoomSpeed=-Math.sign(t)}function s(){}function a(e){if(1===e.touches.length)u=h.TOUCH_ROTATE,d.mouse.set(e.touches[0].pageX,e.touches[0].pageY);else if(2===e.touches.length){u=h.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,o=e.touches[0].pageY-e.touches[1].pageY,i=Math.sqrt(t*t+o*o);d.dollyStart.set(0,i)}else 3===e.touches.length?(u=h.TOUCH_PAN,d.mouse.set(e.touches[0].pageX,e.touches[0].pageY)):u=h.NONE}function l(e){e.preventDefault(),e.stopPropagation();var t=new THREE.Vector2(e.touches[0].pageX,e.touches[0].pageY),o=(new THREE.Vector2).subVectors(t,d.mouse),i=d.domElement===document?d.domElement.body:d.domElement;if(1===e.touches.length){if(u!==h.TOUCH_ROTATE)return;d.speed.phi-=o.x/i.clientWidth,d.speed.theta-=o.y/i.clientHeight}else if(2===e.touches.length){if(u!==h.TOUCH_DOLLY)return;var n=e.touches[0].pageX-e.touches[1].pageX,r=e.touches[0].pageY-e.touches[1].pageY,s=Math.sqrt(n*n+r*r),a=new THREE.Vector2(0,s),o=(new THREE.Vector2).subVectors(a,d.dollyStart);d.zoomSpeed=-20*o.y/i.clientHeight,document.getElementById("lblMessage").innerHTML=d.zoomSpeed,d.dollyStart.copy(a)}else if(3===e.touches.length){if(u!==h.TOUCH_PAN)return;d.panSpeed.x=.5*o.x/i.clientWidth,d.panSpeed.y=.5*o.y/i.clientHeight}else u=h.NONE;d.mouse.copy(t)}function c(){u=h.NONE}var d=this;this.object=e,this.domElement=void 0!==t?t:document,this.speed={phi:0,theta:0},this.zoomSpeed=0,this.panSpeed=new THREE.Vector2,this.target=new THREE.Vector3,this.mouse=new THREE.Vector2,this.dollyStart=new THREE.Vector2;var h={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},u=h.NONE;this.update=function(t){var o=new THREE.Vector3(0,1,0),i=(new THREE.Vector3).subVectors(this.target,e.position).normalize(),n=(new THREE.Vector3).crossVectors(i,o).normalize(),r=(new THREE.Vector3).crossVectors(n,i).normalize(),s=e.position.distanceTo(this.target),a=(new THREE.Vector3).subVectors(e.position,this.target),l=Math.acos(-i.dot(o,i));l+this.speed.theta>0&&a.applyAxisAngle(n,this.speed.theta),a.applyAxisAngle(o,this.speed.phi);var s=s+.05*s*this.zoomSpeed;a.normalize().multiplyScalar(s);var c=n.clone().multiplyScalar(-500*s*t*this.panSpeed.x),d=r.clone().multiplyScalar(500*s*t*this.panSpeed.y),h=(new THREE.Vector3).addVectors(this.target,a);h.add(c),h.add(d);var u={type:"proposeTransform",oldPosition:e.position,newPosition:h,objections:0};if(this.dispatchEvent(u),u.objections>0)this.speed.phi=0,this.speed.theta=0,this.zoomSpeed=0,this.panSpeed.multiplyScalar(0);else{this.target.add(c),this.target.add(d),e.position.copy(h),e.lookAt(this.target);var p=.85*(1-t);this.speed.phi*=p,this.speed.theta*=p,this.zoomSpeed*=p,this.panSpeed.multiplyScalar(p)}},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",r,!1),this.domElement.addEventListener("touchstart",a,!1),this.domElement.addEventListener("touchend",c,!1),this.domElement.addEventListener("touchmove",l,!1),window.addEventListener("keydown",s,!1)},Potree.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype),THREE.EarthControls=function(e,t,o){function i(e){if(a.enabled!==!1){e.preventDefault();var t=a.domElement.getBoundingClientRect(),o={x:(e.clientX-t.left)/a.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/a.domElement.clientHeight)+1},i=getMousePointCloudIntersection(o,a.camera,a.renderer,a.pointclouds);if(i){var s=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),i),u=new THREE.Vector3(o.x,o.y,.5);u.unproject(a.camera);var p=u.sub(a.camera.position).normalize(),m=new THREE.Ray(a.camera.position,p);E=m.intersectPlane(s),v=a.camera.clone(),v.rotation.copy(a.camera.rotation),d.set(e.clientX-t.left,e.clientY-t.top),h.set(e.clientX-t.left,e.clientY-t.top),a.scene.add(a.pivotNode),a.pivotNode.position.copy(E),0===e.button?c=l.DRAG:2===e.button&&(c=l.ROTATE),a.domElement.addEventListener("mousemove",n,!1),a.domElement.addEventListener("mouseup",r,!1)}}}function n(e){if(a.enabled!==!1){e.preventDefault();{var t=a.domElement.getBoundingClientRect();a.domElement===document?a.domElement.body:a.domElement}m.set(e.clientX-t.left-h.x,e.clientY-t.top-h.y),h.set(e.clientX-t.left,e.clientY-t.top)}}function r(){a.enabled!==!1&&(a.domElement.removeEventListener("mousemove",n,!1),a.domElement.removeEventListener("mouseup",r,!1),c=l.NONE,a.scene.remove(a.pivotNode))}function s(e){if(a.enabled!==!1&&a.noZoom!==!0){e.preventDefault();var t=a.domElement.getBoundingClientRect(),o=e.detail<0||e.wheelDelta>0?1:-1,i={x:(e.clientX-t.left)/a.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/a.domElement.clientHeight)+1},n=getMousePointCloudIntersection(i,a.camera,a.renderer,a.pointclouds);if(n){var r=n.distanceTo(a.camera.position),s=(new THREE.Vector3).subVectors(n,a.camera.position).normalize();a.camera.position.add(s.multiplyScalar(.1*r*o))}}}this.camera=e,this.renderer=t,this.pointclouds=[],this.domElement=t.domElement,this.scene=o,this.enabled=!0;var a=this,l={NONE:-1,DRAG:0,ROTATE:1},c=l.NONE,d=new THREE.Vector2,h=new THREE.Vector2,u=new THREE.SphereGeometry(1,32,32),p=new THREE.MeshNormalMaterial({shading:THREE.SmoothShading,transparent:!0,opacity:.5});this.pivotNode=new THREE.Mesh(u,p);var m=new THREE.Vector2,v=null,E=null;this.minAngle=10/180*Math.PI,this.maxAngle=70/180*Math.PI,this.update=function(e){this.camera.position;this.camera.updateMatrixWorld();var t=new THREE.Object3D;if(t.position.copy(this.camera.position),t.rotation.copy(this.camera.rotation),t.updateMatrix(),t.updateMatrixWorld(),E){if(c===l.DRAG){var o=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),E),i={x:h.x/this.domElement.clientWidth*2-1,y:2*-(h.y/this.domElement.clientHeight)+1},n=new THREE.Vector3(i.x,i.y,.5);n.unproject(v);var r=n.sub(v.position).normalize(),s=new THREE.Ray(v.position,r),a=s.distanceToPlane(o);if(a>0){var d=(new THREE.Vector3).subVectors(E,r.clone().multiplyScalar(a));t.position.copy(d)}}else if(c===l.ROTATE){var u=m.clone().multiplyScalar(e);u.x*=.3,u.y*=.2;var p=new THREE.Object3D,f=new THREE.Object3D;p.add(f),p.position.copy(E),f.position.copy(this.camera.position).sub(E),f.rotation.copy(this.camera.rotation),p.rotation.y+=-u.x;var r=this.camera.getWorldDirection(),g=new THREE.Vector3(0,1,0),y=(new THREE.Vector3).crossVectors(g,r),b=f.position.clone();b.y=0,b.normalize();var T=b.dot(f.position.clone().normalize()),R=Math.acos(T);f.position.y<0&&(R=-R);var P=0;P=u.y>0?u.y-Math.max(0,this.minAngle-(R-u.y)):u.y+Math.max(0,R-u.y-this.maxAngle),p.rotateOnAxis(y,-P),p.updateMatrixWorld(),t.position.copy(f.getWorldPosition()),t.quaternion.copy(f.getWorldQuaternion())}var w={type:"proposeTransform",oldPosition:this.camera.position,newPosition:t.position,objections:0};this.dispatchEvent(w),w.objections>0||(this.camera.position.copy(t.position),this.camera.rotation.copy(t.rotation));var C=this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),x=Math.abs(C.z/30),H=this.pivotNode.scale.length();this.pivotNode.scale.multiplyScalar(x/H)}m.set(0,0)},this.reset=function(){c=l.NONE,this.camera.position.copy(this.position0)},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",i,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1)},THREE.EarthControls.prototype=Object.create(THREE.EventDispatcher.prototype),LRU.prototype.size=function(){return this.elements},LRU.prototype.contains=function(e){return null==this.items[e.id]},LRU.prototype.touch=function(e){if(e.loaded){var t;null==this.items[e.id]?(t=new LRUItem(e),t.previous=this.last,this.last=t,null!==t.previous&&(t.previous.next=t),this.items[e.id]=t,this.elements++,null===this.first&&(this.first=t),this.numPoints+=e.numPoints):(t=this.items[e.id],null===t.previous?null!==t.next&&(this.first=t.next,this.first.previous=null,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t):null===t.next||(t.previous.next=t.next,t.next.previous=t.previous,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t))}},LRU.prototype.remove=function(e){var t=this.items[e.id];t&&(1===this.elements?(this.first=null,this.last=null):(t.previous||(this.first=t.next,this.first.previous=null),t.next||(this.last=t.previous,this.last.next=null),t.previous&&t.next&&(t.previous.next=t.next,t.next.previous=t.previous)),delete this.items[e.id],this.elements--,this.numPoints-=e.numPoints)},LRU.prototype.getLRUItem=function(){if(null===this.first)return null;var e=this.first;return e.node},LRU.prototype.toString=function(){for(var e="{ ",t=this.first;null!==t;)e+=t.node.id,null!==t.next&&(e+=", "),t=t.next;return e+="}",e+="("+this.size()+")"},LRU.prototype.freeMemory=function(){if(!(this.elements<=1))for(;this.numPoints>Potree.pointLoadLimit;){var e=this.first,t=e.node;this.disposeDescendants(t)}},LRU.prototype.disposeDescendants=function(e){var t=[];for(t.push(e);t.length>0;){var o=t.pop();o.dispose(),this.remove(o);for(var i in o.children)if(o.children.hasOwnProperty(i)){var n=o.children[i];n.loaded&&t.push(o.children[i])}}},Potree.PointCloudOctreeProxyNode=function(e){THREE.Object3D.call(this),this.geometryNode=e,this.boundingBox=e.boundingBox,this.boundingSphere=this.boundingBox.getBoundingSphere(),this.name=e.name,this.level=e.level,this.numPoints=e.numPoints},Potree.PointCloudOctreeProxyNode.prototype=Object.create(THREE.Object3D.prototype),Potree.ProfileRequest=function(e,t,o,i,n){this.start=e,this.end=t,this.width=o,this.depth=i,this.callback=n,this.loadQueue=[];var r=((new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),(new THREE.Vector3).subVectors(t,e).length(),(new THREE.Vector3).subVectors(t,e).normalize()),s=new THREE.Vector3(0,1,0),a=(new THREE.Vector3).crossVectors(r,s).normalize(),l=a;this.plane=(new THREE.Plane).setFromNormalAndCoplanarPoint(l,e)},Potree.PointCloudOctree=function(e,t){THREE.Object3D.call(this),Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.pcoGeometry=e,this.boundingBox=this.pcoGeometry.tightBoundingBox,this.boundingSphere=this.boundingBox.getBoundingSphere(),this.material=t||new Potree.PointCloudMaterial,this.visiblePointsTarget=2e6,this.level=0,this.position.sub(e.offset),this.updateMatrix(),this.LODDistance=20,this.LODFalloff=1.3,this.LOD=4,this.showBoundingBox=!1,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleBounds=new THREE.Box3,this.profileRequests=[],this.visibleNodes=[],this.visibleGeometry=[],this.pickTarget,this.pickMaterial,this.maxLevel=0,this.generateDEM=!1;var o=new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);this.add(o)},Potree.PointCloudOctree.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudOctree.prototype.updateVisibleBounds=function(){for(var e=[],t=0;t0;){var r=n.shift();if(r instanceof Potree.PointCloudOctreeProxyNode){var s=Potree.utils.computeTransformedBoundingBox(r.boundingBox,r.matrixWorld),a=s.getBoundingSphere();Math.abs(o.distanceToPoint(a.center))0){var r=d.loadQueue[0],h=r.geometryNode;if(h.loaded===!0&&void 0!==r.parent){var u=this.replaceProxy(r);u.updateMatrixWorld(),u.matrixWorld.multiplyMatrices(u.parent.matrixWorld,u.matrix)}else r.geometryNode.load()}else{var p=this.getProfile(d.start,d.end,d.width,d.depth);d.callback({type:"finished",points:p}),c.push(d)}}for(var e=0;e-1&&this.profileRequests.splice(m,1)}},Potree.PointCloudOctree.prototype.updatePointCloud=function(e,t,o,i){if(this.numVisibleNodes++,this.numVisiblePoints+=e.numPoints,e.material=this.material,this.visibleNodes.push(t),e.level&&(this.maxLevel=Math.max(e.level,this.maxLevel)),this.showBoundingBox&&!e.boundingBoxNode){var n=new THREE.BoxHelper(e);this.add(n),this.boundingBoxNodes.push(n),e.boundingBoxNode=n,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)}else this.showBoundingBox?(e.boundingBoxNode.visible=!0,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)):!this.showBoundingBox&&e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);this.generateDEM&&e.level<=2&&(e.dem||(e.dem=this.createDEM(e)));for(var r=0;r=0;if(a)for(var l=0;l0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0;){{var s=r.shift(),a=s.node;s.weight}if(a.visible=!0,a.matrixWorld.multiplyMatrices(a.parent.matrixWorld,a.matrix),a instanceof Potree.PointCloudOctreeProxyNode){var l=a.geometryNode;l.loaded===!0?this.replaceProxy(a):this.loadQueue.push(s)}else if(a instanceof THREE.PointCloud)if(a.pcoGeometry.loaded)Potree.PointCloudOctree.lru.touch(a.pcoGeometry),this.updatePointCloud(a,s,r,o);else{var c=new Potree.PointCloudOctreeProxyNode(a.pcoGeometry),d=a.parent;d.remove(a),d.add(c)}}this.updateProfileRequests(),this.updateVisibleBounds(),this.updateLoadQueue(),this.hideDescendants(this.children[0]);for(var h=[],i=0;i0;){g++;var y=p.shift(),b=y.node,T=b.boundingBox,v=b.boundingSphere,R=i.intersectsBox(T),P=R;if(P){if(m+b.numPoints>this.visiblePointsTarget)break;m+=b.numPoints,t.push(y);for(var w=0;8>w;w++)if(b.children[w]){var C=b.children[w],v=C.boundingSphere,E=v.center.distanceTo(h),x=v.radius,f=v.radius/E,H=e.fov/2*Math.PI/180,V=1/Math.tan(H)*x/Math.sqrt(E*E-x*x);if(!(.1>V))if(f=V,0>E-x&&(f=Number.MAX_VALUE),0===p.length)p.push({node:C,weight:f});else{for(var M=0,S=0;Sp[S].weight){var M=S;break}if(S==p.length-1){M=p.length;break}}p.splice(M,0,{node:C,weight:f})}}}}return t},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(e,t){if(e){var o=e.visibleNodesTexture,i=o.image.data;t=t.slice();var n=function(e,t){var o=e.name,i=t.name;return o.length!=i.length?o.length-i.length:i>o?-1:o>i?1:0};t.sort(n);for(var r={},s=0;st.name?1:0}),i[3*s+0]=0,i[3*s+1]=0,i[3*s+2]=0;for(var c=0;cr;r++)if(void 0!==t.children[r]){var s=t.children[r],a=new Potree.PointCloudOctreeProxyNode(s);i.add(a)}return i}},Potree.PointCloudOctree.prototype.hideDescendants=function(e){for(var t=[],o=0;o0;){var e=t.shift();e.visible=!1;for(var o=0;o0&&(l=-l),function(e){var t=(new THREE.Matrix4).makeTranslation(-i.x,-i.y,-i.z),o=(new THREE.Matrix4).makeRotationY(-l),n=(new THREE.Matrix4).makeTranslation(r,0,0),s=e.clone();return s.applyMatrix4(t),s.applyMatrix4(o),s.applyMatrix4(n),s}}(r,s,i),c={start:r,end:s,points:a,project:l};o.push(c),i+=r.distanceTo(s)}return o},Potree.PointCloudOctree.prototype.getProfile=function(e,t,o,i,n){if(void 0===n){var r=[];r.push(this);for(var s=(new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),a=(new THREE.Vector3).subVectors(t,e).length(),l=(new THREE.Vector3).subVectors(t,e).normalize(),c=new THREE.Vector3(0,1,0),d=(new THREE.Vector3).crossVectors(l,c).normalize(),h=d,u=(new THREE.Plane).setFromNormalAndCoplanarPoint(h,e),p=(new THREE.Plane).setFromNormalAndCoplanarPoint(l,s),m=null;r.length>0;){var v=r.shift(),E=0;if(v instanceof THREE.PointCloud){var f=v.geometry,g=f.attributes.position,y=g.array,b=v.numPoints;if(!m){m={};for(var T in f.attributes)f.attributes.hasOwnProperty(T)&&("indices"===T||(m[T]=[]))}for(var R=0;b>R;R++){var P=new THREE.Vector3(y[3*R],y[3*R+1],y[3*R+2]);P.applyMatrix4(this.matrixWorld);var w=Math.abs(u.distanceToPoint(P)),C=Math.abs(p.distanceToPoint(P));if(o/2>w&&a/2>C){for(var T in f.attributes)if(f.attributes.hasOwnProperty(T))if("position"===T)m[T].push(P);else if("indices"===T);else{var x=f.attributes[T];if(1===x.itemSize)m[T].push(x.array[R+V]);else{for(var H=[],V=0;V0&&(s=-s),function(e){var t=(new THREE.Matrix4).makeTranslation(-o.x,-o.y,-o.z),i=(new THREE.Matrix4).makeRotationY(-s),n=e.clone();return n.applyMatrix4(t),n.applyMatrix4(i),n}}(e,t);return m.project=A,m}this.profileRequests.push(new Potree.ProfileRequest(e,t,o,i,n))},Potree.PointCloudOctree.prototype.getVisibleExtent=function(){return this.visibleBounds.applyMatrix4(this.matrixWorld)},Potree.PointCloudOctree.prototype.pick=function(e,t,o,i){var i=i||{},n=i.pickWindowSize||17,r=this.nodesOnRay(this.visibleNodes,o);if(0===r.length)return null;var s=Math.ceil(e.domElement.clientWidth),a=Math.ceil(e.domElement.clientHeight),l=(new THREE.Vector3).addVectors(t.position,o.direction).project(t);l.addScalar(1).multiplyScalar(.5),l.x*=s,l.y*=a,this.pickTarget?(this.pickTarget.width!=s||this.pickTarget.height!=a)&&(this.pickTarget.dispose(),this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat})):this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat}),this.pickTarget.setSize(s,a),this.pickMaterial||(this.pickMaterial=new Potree.PointCloudMaterial,this.pickMaterial.pointColorType=Potree.PointColorType.POINT_INDEX,this.pickMaterial.pointSizeType=Potree.PointSizeType.FIXED),this.pickMaterial.pointSizeType=this.material.pointSizeType,this.pickMaterial.size=this.material.size,this.pickMaterial.pointSizeType===Potree.PointSizeType.ADAPTIVE&&this.updateVisibilityTexture(this.pickMaterial,r),this.pickMaterial.fov=this.material.fov,this.pickMaterial.screenWidth=this.material.screenWidth,this.pickMaterial.screenHeight=this.material.screenHeight,this.pickMaterial.spacing=this.material.spacing,this.pickMaterial.near=this.material.near,this.pickMaterial.far=this.material.far,this.pickMaterial.octreeLevels=this.material.octreeLevels,this.pickMaterial.pointShape=this.material.pointShape;var c=e.context;c.enable(c.SCISSOR_TEST),c.scissor(l.x-(n-1)/2,l.y-(n-1)/2,n,n),c.disable(c.SCISSOR_TEST);var d=this.pickMaterial;e.setRenderTarget(this.pickTarget),e.setDepthTest(d.depthTest),e.setDepthWrite(d.depthWrite),e.setBlending(THREE.NoBlending),e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),r.length>0&&r.push(r[0]);for(var h=0;hP;P++)for(var w=0;n>w;w++){var C=P+w*n,x=Math.pow(P-(n-1)/2,2)+Math.pow(w-(n-1)/2,2),H=y[4*C+3];y[4*C+3]=0;var V=b[C];(0!==V||0!==H)&&T>x&&(R={pIndex:V,pcIndex:H},T=x)}if(R){var M={},S=r[R.pcIndex],A=S.geometry.attributes;for(var B in A)if(A.hasOwnProperty(B)){var I=p.attributes[B];if("position"===B){var L=S.geometry.attributes.position.array,W=L[3*R.pIndex+0],G=L[3*R.pIndex+1],O=L[3*R.pIndex+2],z=new THREE.Vector3(W,G,O);z.applyMatrix4(this.matrixWorld),M[B]=z}else if("indices"===B);else if(1===I.itemSize)M[B]=I.array[h+X];else{for(var N=[],X=0;Xd;d++){var h=r[3*d+0],u=r[3*d+1],p=r[3*d+2],m=new THREE.Vector3(h,u,p).applyMatrix4(o),v=parseInt(s*(m.x-i.min.x)/n.x),E=parseInt(s*(m.z-i.min.z)/n.z);v=Math.min(v,s-1),E=Math.min(E,s-1);var f=v+E*s;a[f]||(a[f]=[]),a[f].push(m.y)}for(var d=0;d.5&&r.x.5&&r.y0;){{var r=n.shift(),s=r.dem,a=(s.demSize,s.boundingBox2D);a.containsPoint(t)}if(a.containsPoint(t)){var l=o(s);if(i?null!=l&&l>0&&(i=l):i=l,r.level<=2)for(var c=0;cs;s++)for(var a=0;o>a;a++){var l=s/t,c=a/o,d=l*e.size().x+e.min.x,h=c*e.size().z+e.min.z,u=this.getDEMHeight(new THREE.Vector3(d,0,h));u||(u=0),n[r+0]=d,n[r+1]=u,n[r+2]=h,r+=3}i.addAttribute("position",new THREE.BufferAttribute(n,3));var p=new THREE.PointCloudMaterial({size:20,color:65280}),m=new THREE.PointCloud(i,p);scene.add(m)};var nodesLoadTimes={};Potree.PointCloudOctreeGeometry=function(){Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.url=null,this.octreeDir=null,this.spacing=0,this.boundingBox=null,this.root=null,this.numNodesLoading=0,this.nodes=null,this.pointAttributes=null,this.hierarchyStepSize=-1,this.loader=null},Potree.PointCloudOctreeGeometryNode=function(e,t,o){this.id=Potree.PointCloudOctreeGeometryNode.IDCount++,this.name=e,this.index=parseInt(e.charAt(e.length-1)),this.pcoGeometry=t,this.geometry=null,this.boundingBox=o,this.boundingSphere=o.getBoundingSphere(),this.children={},this.numPoints=0,this.level=null},Potree.PointCloudOctreeGeometryNode.IDCount=0,Potree.PointCloudOctreeGeometryNode.prototype.getURL=function(){var e="",t=this.pcoGeometry.loader.version;return t.equalOrHigher("1.5")?e=this.pcoGeometry.octreeDir+"/"+this.getHierarchyPath()+"/"+this.name:t.equalOrHigher("1.4")?e=this.pcoGeometry.octreeDir+"/"+this.name:t.upTo("1.3")&&(e=this.pcoGeometry.octreeDir+"/"+this.name),e},Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath=function(){for(var e="r/",t=this.pcoGeometry.hierarchyStepSize,o=this.name.substr(1),i=Math.floor(o.length/t),n=0;i>n;n++)e+=o.substr(n*t,t)+"/";return e=e.slice(0,-1)},Potree.PointCloudOctreeGeometryNode.prototype.addChild=function(e){this.children[e.index]=e,e.parent=this},Potree.PointCloudOctreeGeometryNode.prototype.load=function(){this.loading===!0||this.pcoGeometry.numNodesLoading>3||(this.loading=!0,this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.version.equalOrHigher("1.5")&&this.level%this.pcoGeometry.hierarchyStepSize===0&&this.hasChildren?this.loadHierachyThenPoints():this.loadPoints())},Potree.PointCloudOctreeGeometryNode.prototype.loadPoints=function(){this.pcoGeometry.loader.load(this)},Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints=function(){var e=this,t=function(e,t){var o=(t.byteLength/5,new DataView(t)),i=[],n=o.getUint8(0),r=o.getUint32(1,!0);e.numPoints=r,i.push({children:n,numPoints:r,name:e.name});for(var s=[],a=5;i.length>0;){for(var l=i.shift(),c=1,d=0;8>d;d++){if(0!==(l.children&c)){var h=l.name+d,u=o.getUint8(a),p=o.getUint32(a+1,!0);i.push({children:u,numPoints:p,name:h}),s.push({children:u,numPoints:p,name:h}),a+=5}c=2*c}if(a===t.byteLength)break}var m={};m[e.name]=e;for(var v=e.pcoGeometry,d=0;d0,y.addChild(R),m[E]=R}e.loadPoints()};if(e.level%e.pcoGeometry.hierarchyStepSize===0){var o=e.pcoGeometry.octreeDir+"/"+e.getHierarchyPath()+"/"+e.name+".hrc",i=new XMLHttpRequest;i.open("GET",o,!0),i.responseType="arraybuffer",i.overrideMimeType("text/plain; charset=x-user-defined"),i.onreadystatechange=function(){if(4===i.readyState)if(200===i.status||0===i.status){var o=i.response;t(e,o)}else console.log("Failed to load file! HTTP status: "+i.status+", file: "+url)};try{i.send(null)}catch(n){console.log("fehler beim laden der punktwolke: "+n)}}},Potree.PointCloudOctreeGeometryNode.prototype.dispose=function(){this.geometry&&(this.geometry.dispose(),this.geometry=null,this.loaded=!1)},Potree.utils=function(){},Potree.utils.pathExists=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),200!==t.status?!1:!0},Potree.utils.computeTransformedBoundingBox=function(e,t){var o=[new THREE.Vector3(e.min.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.max.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.min.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.max.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.max.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.min.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.max.y,e.max.z).applyMatrix4(t)],i=new THREE.Box3;return i.setFromPoints(o),i},Potree.utils.addCommas=function(e){e+="",x=e.split("."),x1=x[0],x2=x.length>1?"."+x[1]:"";for(var t=/(\d+)(\d{3})/;t.test(x1);)x1=x1.replace(t,"$1,$2");return x1+x2},Potree.utils.createWorker=function(e){var t=new Blob([e],{type:"application/javascript"}),o=new Worker(URL.createObjectURL(t));return o},Potree.utils.loadSkybox=function(e){var t=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,1,1e5),o=new THREE.Scene,i=".jpg",n=[e+"px"+i,e+"nx"+i,e+"py"+i,e+"ny"+i,e+"pz"+i,e+"nz"+i],r=THREE.ImageUtils.loadTextureCube(n,THREE.CubeRefractionMapping),s={uniforms:{tCube:{type:"t",value:r},tFlip:{type:"f",value:-1}},vertexShader:THREE.ShaderLib.cube.vertexShader,fragmentShader:THREE.ShaderLib.cube.fragmentShader},a=new THREE.ShaderMaterial({fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,uniforms:s.uniforms,depthWrite:!1,side:THREE.BackSide}),l=new THREE.Mesh(new THREE.BoxGeometry(100,100,100),a);return o.add(l),{camera:t,scene:o}},Potree.utils.createGrid=function(e,t,o,i){for(var n=new THREE.LineBasicMaterial({color:i||8947848}),r=new THREE.Geometry,s=0;t>=s;s++)r.vertices.push(new THREE.Vector3(-(o*e)/2,0,s*o-o*t/2)),r.vertices.push(new THREE.Vector3(+(o*e)/2,0,s*o-o*t/2));for(var s=0;e>=s;s++)r.vertices.push(new THREE.Vector3(s*o-o*e/2,0,-(o*t)/2)),r.vertices.push(new THREE.Vector3(s*o-o*e/2,0,+(o*t)/2));var a=new THREE.Line(r,n,THREE.LinePieces);return a.receiveShadow=!0,a},Potree.utils.createBackgroundTexture=function(e,t){function o(e,t){return 1/(2*Math.PI)*Math.exp(-(e*e+t*t)/2)}var i=THREE.ImageUtils.generateDataTexture(e,t,new THREE.Color);i.magFilter=THREE.NearestFilter;for(var n=i.image.data,r=[1,1.5,1.7],s=o(0,0),a=0;e>a;a++)for(var l=0;t>l;l++){var c=2*(a/e)-1,d=2*(l/t)-1,h=a+e*l,u=o(2*c,2*d)/s,p=(Math.random()+Math.random()+Math.random())/3;p=(.5*u+.5)*p*.03,p=.4*p,n[3*h+0]=255*(u/15+.05+p)*r[0],n[3*h+1]=255*(u/15+.05+p)*r[1],n[3*h+2]=255*(u/15+.05+p)*r[2]}return i},Potree.Features=function(){var e=document.createElement("canvas").getContext("webgl");return{SHADER_INTERPOLATION:{isSupported:function(){var t=!0;return t=t&&e.getExtension("EXT_frag_depth"),t=t&&e.getParameter(e.MAX_VARYING_VECTORS)>=8}},SHADER_SPLATS:{isSupported:function(){var t=!0;return t=t&&e.getExtension("EXT_frag_depth"),t=t&&e.getExtension("OES_texture_float"),t=t&&e.getParameter(e.MAX_VARYING_VECTORS)>=8}}}}(),Potree.TextSprite=function(e){THREE.Object3D.call(this);var t=new THREE.Texture;t.minFilter=THREE.LinearFilter,t.magFilter=THREE.LinearFilter;var o=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});this.material=o,this.sprite=new THREE.Sprite(o),this.add(this.sprite),this.borderThickness=4,this.fontface="Arial",this.fontsize=28,this.borderColor={r:0,g:0,b:0,a:1},this.backgroundColor={r:255,g:255,b:255,a:1},this.textColor={r:255,g:255,b:255,a:1},this.text="",this.setText(e)},Potree.TextSprite.prototype=new THREE.Object3D,Potree.TextSprite.prototype.setText=function(e){this.text=e,this.update()},Potree.TextSprite.prototype.setTextColor=function(e){this.textColor=e,this.update()},Potree.TextSprite.prototype.setBorderColor=function(e){this.borderColor=e,this.update()},Potree.TextSprite.prototype.setBackgroundColor=function(e){this.backgroundColor=e,this.update()},Potree.TextSprite.prototype.update=function(){var e=document.createElement("canvas"),t=e.getContext("2d");t.font="Bold "+this.fontsize+"px "+this.fontface;var o=t.measureText(this.text),i=o.width,n=i+2*this.borderThickness,r=1.4*this.fontsize+2*this.borderThickness,e=document.createElement("canvas"),t=e.getContext("2d");t.canvas.width=n,t.canvas.height=r,t.font="Bold "+this.fontsize+"px "+this.fontface,t.fillStyle="rgba("+this.backgroundColor.r+","+this.backgroundColor.g+","+this.backgroundColor.b+","+this.backgroundColor.a+")",t.strokeStyle="rgba("+this.borderColor.r+","+this.borderColor.g+","+this.borderColor.b+","+this.borderColor.a+")",t.lineWidth=this.borderThickness,this.roundRect(t,this.borderThickness/2,this.borderThickness/2,i+this.borderThickness,1.4*this.fontsize+this.borderThickness,6),t.strokeStyle="rgba(0, 0, 0, 1.0)",t.strokeText(this.text,this.borderThickness,this.fontsize+this.borderThickness),t.fillStyle="rgba("+this.textColor.r+","+this.textColor.g+","+this.textColor.b+","+this.textColor.a+")",t.fillText(this.text,this.borderThickness,this.fontsize+this.borderThickness);var s=new THREE.Texture(e);s.minFilter=THREE.LinearFilter,s.magFilter=THREE.LinearFilter,s.needsUpdate=!0,this.sprite.material.map=s,this.sprite.scale.set(.01*n,.01*r,1)},Potree.TextSprite.prototype.roundRect=function(e,t,o,i,n,r){e.beginPath(),e.moveTo(t+r,o),e.lineTo(t+i-r,o),e.quadraticCurveTo(t+i,o,t+i,o+r),e.lineTo(t+i,o+n-r),e.quadraticCurveTo(t+i,o+n,t+i-r,o+n),e.lineTo(t+r,o+n),e.quadraticCurveTo(t,o+n,t,o+n-r),e.lineTo(t,o+r),e.quadraticCurveTo(t,o,t+r,o),e.closePath(),e.fill(),e.stroke()},Potree.Version=function(e){this.version=e;var t=-1===e.indexOf(".")?e.length:e.indexOf(".");this.versionMajor=parseInt(e.substr(0,t)),this.versionMinor=parseInt(e.substr(t+1)),0===this.versionMinor.length&&(this.versionMinor=0)},Potree.Version.prototype.newerThan=function(e){var t=new Potree.Version(e);return this.versionMajor>t.versionMajor?!0:this.versionMajor===t.versionMajor&&this.versionMinor>t.versionMinor?!0:!1},Potree.Version.prototype.equalOrHigher=function(e){var t=new Potree.Version(e);return this.versionMajor>t.versionMajor?!0:this.versionMajor===t.versionMajor&&this.versionMinor>=t.versionMinor?!0:!1},Potree.Version.prototype.upTo=function(e){return!this.newerThan(e)},Potree.AngleTool=function(e,t,o){"use strict";function i(e){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.angleLabels=[],this.root=e,this.closed=!0;var t=new THREE.SphereGeometry(.4,10,10),o=new THREE.Color(16711680),i=function(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e};this.add=function(e){this.points.push(e);var n=new THREE.Mesh(t,i());n.addEventListener("mousemove",m),n.addEventListener("mouseleave",v),n.addEventListener("mousedrag",E),n.addEventListener("drop",f);var r=new THREE.Geometry;r.vertices.push(new THREE.Vector3,new THREE.Vector3),r.colors.push(o,o,o);var s=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2});s.depthTest=!1;var a=new THREE.Line(r,s),l=new Potree.TextSprite;l.setBorderColor({r:0,g:255,b:0,a:0}),l.setBackgroundColor({r:0,g:255,b:0,a:0}),l.material.depthTest=!1,l.material.opacity=1,this.root.add(n),this.root.add(a),this.root.add(l),this.spheres.push(n),this.edges.push(a),this.angleLabels.push(l),this.setPosition(this.points.length-1,e)},this.remove=function(e){this.points.splice(e,1),this.root.remove(this.spheres[e]),this.root.remove(this.edges[e]),this.root.remove(this.angleLabels[e]),this.spheres.splice(e,1),this.edges.splice(e,1),this.angleLabels.splice(e,1),this.update()},this.removeAll=function(){for(;this.points.length>1;)this.remove(0);this.sceneRoot.visible=!1,this.update()},this.getAngleBetweenLines=function(e,t,o){var i=(new THREE.Vector3).subVectors(t,e),n=(new THREE.Vector3).subVectors(o,e);return i.angleTo(n)},this.getAngle=function(e){var t=0,o=this.points[0],i=this.points[1],n=this.points[2];return 0===e?t=this.getAngleBetweenLines(o,i,n):1===e?t=this.getAngleBetweenLines(i,o,n):2===e&&(t=this.getAngleBetweenLines(n,o,i)),t},this.setPosition=function(e,t){var o=this.points[e];o.copy(t),this.update()},this.setClosed=function(e){this.closed=e,this.update()},this.update=function(){var e,t;if(1===this.points.length)return e=this.points[0],this.spheres[0].position.copy(e),this.edges[0].visible=!1,void(this.angleLabels[0].visible=!1);var o=this.points.length-1,i=new THREE.Vector3;for(t=0;o>=t;t++){e=this.points[t];var n=this.spheres[t],r=0===t?o:t-1,s=this.edges[r],a=this.edges[t];n.position.copy(e),s.geometry.vertices[1].copy(e),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere(),a.geometry.vertices[0].copy(e),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere(),a.visible=t!==o||this.closed?!0:!1,i.add(e)}if(i.multiplyScalar(1/this.points.length),this.points.length>=3)for(t=0;o>=t;t++){this.angleLabels[t].visible=!0,this.angleLabels[t].setText(Potree.utils.addCommas((this.getAngle(t)*(180/Math.PI)).toFixed(1))+"°");var l=(new THREE.Vector3).addVectors(this.points[t],i).multiplyScalar(.5);this.angleLabels[t].position.copy(l)}else for(t=0;o>=t;t++)this.angleLabels[t].visible=!1}}function n(e){if(h.enabled&&void 0!==e){var t=d();if(t){var o=t.clone();if(p===u.DEFAULT&&(p=u.PICKING,h.activeMeasurement=new i),p===u.PICKING&&h.activeMeasurement&&h.activeMeasurement.points.length>2)h.measurements.push(h.activeMeasurement),h.activeMeasurement=void 0,p=u.DEFAULT,h.setEnabled(!1);else{h.activeMeasurement.add(o);var n={type:"newpoint",position:o.clone()};h.dispatchEvent(n)}}}}function r(e){if(void 0!==e){var t=h.domElement.getBoundingClientRect();h.mouse.x=(e.clientX-t.left)/h.domElement.clientWidth*2-1,h.mouse.y=2*-((e.clientY-t.top)/h.domElement.clientHeight)+1;var o;if(h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(p===u.PICKING&&h.activeMeasurement){if(o=d()){var i=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(i,o)}}else o=c(),o?(o.object.dispatchEvent({type:"mousemove",target:o.object,event:e}),h.hoveredElement&&h.hoveredElement!==o.object&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=o.object):(h.hoveredElement&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=null)}}function s(e){void 0!==e&&p===u.PICKING&&(h.activeMeasurement.removeAll(),h.activeMeasurement=void 0,p=u.DEFAULT,h.setEnabled(!1))}function a(e){if(1===e.which){p!==u.DEFAULT&&e.stopImmediatePropagation();var t=c();t&&(h.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:h.sceneRoot.position.clone(),mousePos:{x:h.mouse.x,y:h.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&s(e)}function l(e){h.dragstart&&(h.dragstart.object.dispatchEvent({type:"drop",event:e}),h.dragstart=null)}function c(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=new THREE.Raycaster;t.ray.set(h.camera.position,e.sub(h.camera.position).normalize());for(var o=[],i=0;i0?s[0]:!1}function d(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sc)&&(n=l,r=c)}}return n?n.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.accuracy=.5;var u={DEFAULT:0,PICKING:1},p=u.DEFAULT;this.activeMeasurement=null,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){var t=d();if(t)for(var o=0;o=0){h.measurements[o].setPosition(n,t);break}}e.event.stopImmediatePropagation()},f=function(e){};this.setEnabled=function(e){this.enabled!==e&&(this.enabled=e,e&&(p=u.PICKING,h.activeMeasurement=new i(h.sceneRoot),h.activeMeasurement.add(new THREE.Vector3(0,0,0))))},this.update=function(){var e,t,o,i,n=[];for(e=0;e=n;n++){var t=this.points[n];i.add(t)}i.divideScalar(this.points.length);for(var n=0;o>=n;n++){var r=n,s=n+1>o?0:n+1,t=this.points[r],a=this.points[s],l=this.spheres[r];l.position.copy(t),l.material.color=e.color;var c=this.edges[r];c.material.color=this.color,c.geometry.vertices[0].copy(t),c.geometry.vertices[1].copy(a),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),c.visible=o>r||this.closed;var d=this.edgeLabels[n],h=(new THREE.Vector3).add(t);h.add(a),h=h.multiplyScalar(.5);var u=t.distanceTo(a);d.position.copy(h),d.setText(u.toFixed(2)),d.visible=this.showDistances&&(o>r||this.closed)&&this.points.length>=2}this.areaLabel.position.copy(i),this.areaLabel.visible=this.showArea&&this.points.length>=3;var p=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(p)}},this.raycast=function(e,t){for(var o=0;o0?s[0]:!1}var c=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};var d={DEFAULT:0,INSERT:1},h=d.DEFAULT;this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null,this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),o=new THREE.Ray(c.camera.position,t),i=[];c.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null},this.startInsertion=function(e){h=d.INSERT;var e=e||{},t=e.showDistances||!0,o=e.showArea||!1,i=e.closed||!1;this.activeMeasurement=new Potree.Measure,this.activeMeasurement.showDistances=t,this.activeMeasurement.showArea=o,this.activeMeasurement.closed=i,this.sceneMeasurement.add(this.activeMeasurement),this.measurements.push(this.activeMeasurement),this.activeMeasurement.addMarker(new THREE.Vector3(0,0,0))},this.finishInsertion=function(){this.activeMeasurement.removeMarker(this.activeMeasurement.points.length-1),this.activeMeasurement=null,h=d.DEFAULT},this.addMeasurement=function(e){this.sceneMeasurement.add(e),this.measurements.push(e)},this.removeMeasurement=function(e){this.sceneMeasurement.remove(e);var t=this.measurements.indexOf(e);t>=0&&this.measurements.splice(t,1)},this.update=function(){for(var e=[],t=0;t1){var c=new THREE.Geometry;c.vertices.push(new THREE.Vector3,new THREE.Vector3),c.colors.push(o,o,o);var d=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2,transparent:!0,opacity:.4});d.depthTest=!1;var h=new THREE.Line(c,d);h.visible=!1,this.add(h),this.edges.push(h);var u=new THREE.BoxGeometry(1,1,1),p=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),m=new THREE.Mesh(u,p);m.visible=!1,this.add(m),this.boxes.push(m)}this.setPosition(this.points.length-1,e)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]);var t=0==e?0:e-1;this.remove(this.edges[t]),this.edges.splice(t,1),this.remove(this.boxes[t]),this.boxes.splice(t,1),this.spheres.splice(e,1),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,o=0;o=r;r++){{var e=this.points[r],s=this.spheres[r],a=0===r?n:r-1,l=r===n?0:r+1,c=this.points[a],d=this.points[l],h=this.edges[a],u=this.edges[r],p=this.boxes[a];this.boxes[r],e.distanceTo(c),e.distanceTo(d),(new THREE.Vector3).addVectors(c,e).multiplyScalar(.5),(new THREE.Vector3).addVectors(e,d).multiplyScalar(.5)}if(s.position.copy(e),s.visible=this._modifiable?!0:!1,h&&(h.geometry.vertices[1].copy(e),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere()),u&&(u.geometry.vertices[0].copy(e),u.geometry.verticesNeedUpdate=!0,u.geometry.computeBoundingSphere()),p){var m=c,v=e,E=m.clone().setY(0).distanceTo(v.clone().setY(0));p.scale.set(E,this.height,this.width);var f=(new THREE.Vector3).addVectors(m,v).multiplyScalar(.5),g=(new THREE.Vector3).subVectors(v,m),y=new THREE.Vector3(g.z,0,-g.x);p.position.set(0,0,0),p.lookAt(y),p.position.copy(f)}i.add(e),t.min(e),o.max(e)}i.multiplyScalar(1/this.points.length);for(var r=0;r0?o[0]:!1}var c=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};{var d={DEFAULT:0,INSERT:1},h=d.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeProfile,this.profiles=[],this.sceneProfile=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneProfile.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneProfile.add(this.light),this.hoveredElement=null,this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),o=new THREE.Ray(c.camera.position,t),i=[];c.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null},this.startInsertion=function(e){h=d.INSERT;var e=e||{},t=e.clip||!1,o=e.width||1;this.activeProfile=new Potree.HeightProfile,this.activeProfile.clip=t,this.activeProfile.setWidth(o),this.sceneProfile.add(this.activeProfile),this.profiles.push(this.activeProfile),this.activeProfile.addMarker(new THREE.Vector3(0,0,0))},this.finishInsertion=function(){this.activeProfile.removeMarker(this.activeProfile.points.length-1),this.activeProfile=null,h=d.DEFAULT},this.addProfile=function(e){this.profiles.push(e),this.sceneProfile.add(e),e.update()},this.removeProfile=function(e){this.sceneProfile.remove(e);var t=this.profiles.indexOf(e);t>=0&&this.profiles.splice(t,1)},this.update=function(){for(var e=0;e0?i[0]:!1}}var a=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.dragstart=null,this.sceneTransformation=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneTransformation.add(this.sceneRoot),this.sceneRotation=new THREE.Scene,this.translationNode=new THREE.Object3D,this.rotationNode=new THREE.Object3D,this.scaleNode=new THREE.Object3D,this.sceneRoot.add(this.translationNode),this.sceneRoot.add(this.rotationNode),this.sceneRoot.add(this.scaleNode),this.sceneRoot.visible=!1,this.hoveredElement=null,this.STATE={DEFAULT:0,TRANSLATE_X:1,TRANSLATE_Y:2,TRANSLATE_Z:3,SCALE_X:1,SCALE_Y:2,SCALE_Z:3},this.parts={ARROW_X:{name:"arrow_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.TRANSLATE_X},ARROW_Z:{name:"arrow_z",object:void 0,color:new THREE.Color(255),state:this.STATE.TRANSLATE_Z},ARROW_Y:{name:"arrow_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.TRANSLATE_Y},SCALE_X:{name:"scale_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.SCALE_X},SCALE_Z:{name:"scale_z",object:void 0,color:new THREE.Color(255),state:this.STATE.SCALE_Z},SCALE_Y:{name:"scale_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.SCALE_Y},ROTATE_X:{name:"rotate_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.ROTATE_X},ROTATE_Z:{name:"rotate_z",object:void 0,color:new THREE.Color(255),state:this.STATE.ROTATE_Z},ROTATE_Y:{name:"rotate_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.ROTATE_Y}},this.buildTranslationNode=function(){var e=a.createArrow(a.parts.ARROW_X,a.parts.ARROW_X.color);e.rotation.z=-Math.PI/2;var t=a.createArrow(a.parts.ARROW_Y,a.parts.ARROW_Y.color),o=a.createArrow(a.parts.ARROW_Z,a.parts.ARROW_Z.color);o.rotation.x=-Math.PI/2,this.translationNode.add(e),this.translationNode.add(t),this.translationNode.add(o)},this.buildScaleNode=function(){var e=this.createScaleHandle(a.parts.SCALE_X,16711680);e.rotation.z=-Math.PI/2;var t=this.createScaleHandle(a.parts.SCALE_Y,65280),o=this.createScaleHandle(a.parts.SCALE_Z,255);o.rotation.x=-Math.PI/2,this.scaleNode.add(e),this.scaleNode.add(t),this.scaleNode.add(o)},this.buildRotationNode=function(){var e=this.createRotationCircle(a.parts.ROTATE_X,16711680);e.rotation.y=-Math.PI/2;var t=this.createRotationCircle(a.parts.ROTATE_Y,65280),o=this.createRotationCircle(a.parts.ROTATE_Z,255);t.rotation.x=-Math.PI/2,this.rotationNode.add(e),this.rotationNode.add(t),this.rotationNode.add(o);var i=new THREE.SphereGeometry(2.9,24,24),n=new THREE.Mesh(i,new THREE.MeshBasicMaterial({color:11184810,transparent:!0,opacity:.4}));this.sceneRotation.add(n);var r=function(){n.material.color.setHex(5592405)},s=function(){n.material.color.setHex(11184810)},l=function(e){e.event.stopImmediatePropagation();for(var t=new THREE.Vector3(a.dragstart.mousePos.x,a.dragstart.mousePos.y,.1),o=new THREE.Vector3(a.mouse.x,a.mouse.y,.1),i=(new THREE.Vector3).subVectors(o,t),n=t.clone().unproject(a.camera),r=o.clone().unproject(a.camera),s=(new THREE.Vector3).subVectors(r,n),l=s.clone().normalize(),c=(new THREE.Vector3).subVectors(a.camera.position,n).normalize(),d=c.clone().cross(l),h=6*i.length(),u=0;u=n;n++){var r=2*Math.PI*n/i,s=3*Math.cos(r),l=3*Math.sin(r);o.push(new THREE.Vector3(s,l,0))}for(var c=new THREE.Geometry,n=0;nt;t++)n.label.children[t].updateMatrixWorld(!0)},this.setDimension=function(e,t,o){this.dimension.set(e,t,o),this.box.scale.set(e,t,o),this.frame.scale.set(e,t,o)},this.volume=function(){return Math.abs(this.scale.x*this.scale.y*this.scale.z)},this.update=function(){this.boundingBox=this.box.geometry.boundingBox,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)},this.raycast=function(e,t){var o=[];if(this.box.raycast(e,o),o.length>0){var i=o[0];t.push({distance:i.distance,object:this,point:i.point.clone()})}},this.update()},Potree.Volume.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(Potree.Volume.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this.update()}}),Object.defineProperty(Potree.Volume.prototype,"modifiable",{get:function(){return this._modifiable},set:function(e){this._modifiable=e,this.update()}}),Potree.VolumeTool=function(e,t,o){function i(e){var t=c.domElement.getBoundingClientRect();c.mouse.x=(e.clientX-t.left)/c.domElement.clientWidth*2-1,c.mouse.y=2*-((e.clientY-t.top)/c.domElement.clientHeight)+1}function n(){}function r(e){if(h!==d.DEFAULT&&e.stopImmediatePropagation(),h===d.INSERT_VOLUME)c.finishInsertion();else if(1===e.which){var t=a();t&&t.object.modifiable&&transformationTool.setTargets([t.object])}3===e.which}function s(e){return e.preventDefault(),!1}function a(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=new THREE.Raycaster;t.ray.set(c.camera.position,e.sub(c.camera.position).normalize());for(var o=[],i=0;i0?r[0]:!1}function l(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),o=new THREE.Ray(c.camera.position,t),i=[];c.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var c=this;this.enabled=!1,this.scene=e,this.sceneVolume=new THREE.Scene,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.volumes=[];var d={DEFAULT:0,INSERT_VOLUME:1},h=d.DEFAULT;this.update=function(){if(h===d.INSERT_VOLUME){var e=l();if(e){this.activeVolume.position.copy(e);var t=this.activeVolume.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),o=(new THREE.Vector4(t.x,t.y,t.z).applyMatrix4(this.camera.projectionMatrix),Math.abs(t.z/10));this.activeVolume.scale.set(o,o,o)}}for(var i=[],n=0;n=0&&this.volumes.splice(t,1)},this.render=function(){o.render(this.sceneVolume,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousedown",r,!1),this.domElement.addEventListener("mousemove",i,!1),this.domElement.addEventListener("contextmenu",s,!1)}; \ No newline at end of file +function Potree(){}function POCLoader(){}function PointAttribute(e,t,o){this.name=e,this.type=t,this.numElements=o,this.byteSize=this.numElements*this.type.size}function PointAttributes(e){if(this.attributes=new Array,this.byteSize=0,this.size=0,null!=e)for(var t=0;tu)&&(a=h,l=u)}}return a?a.position:null}function pixelsArrayToImage(e,t,o){var i=document.createElement("canvas");i.width=t,i.height=o;var n=i.getContext("2d");e=new e.constructor(e);for(var r=0;r=n?o.pointsCount:o.pointsCount/n,a=function(){var e=t.readData(1e6,0,n);return e.then(function(e){return i.push(new LASDecoder(e.buffer,o.pointsFormatId,o.pointsStructSize,e.count,o.scale,o.offset,o.mins,o.maxs)),r+=e.count,Potree.LasLazLoader.progressCB(r/s),e.hasMoreData?a():(o.totalRead=r,o.versionAsString=t.versionAsString,o.isCompressed=t.isCompressed,[t,o,i])})};return a()}).then(function(e){var t=e[0];return Potree.LasLazLoader.progressCB(1),t.close().then(function(){return t.isOpen=!1,Promise.delay(200).cancellable()}).then(function(){return e.slice(1)})})["catch"](Promise.CancellationError,function(e){if(o.isOpen)return o.close().then(function(){throw o.isOpen=!1,e});throw e})},Potree.LasLazLoader.prototype.handle=function(){},Potree.LasLazBatcher=function(e){this.push=function(t){var o=Potree.workers.lasdecoder.getWorker(),i=new THREE.Vector3(t.mins[0],t.mins[1],t.mins[2]),n=new THREE.Vector3(t.maxs[0],t.maxs[1],t.maxs[2]);i.add(e.pcoGeometry.offset),n.add(e.pcoGeometry.offset),o.onmessage=function(r){for(var s=new THREE.BufferGeometry,a=t.pointsCount,l=r.data.position,c=r.data.color,d=r.data.intensity,h=new Uint8Array(r.data.classification),u=new Float32Array(h.byteLength),p=new Uint8Array(r.data.returnNumber),m=new Float32Array(p.byteLength),v=new Uint16Array(r.data.pointSourceID),E=new Float32Array(v.length),f=new ArrayBuffer(4*a),g=new Uint32Array(f),y=new THREE.Box3,b=new Float32Array(l),T=0;a>T;T++)u[T]=h[T],m[T]=p[T],E[T]=v[T],g[T]=T,y.expandByPoint(new THREE.Vector3(b[3*T+0],b[3*T+1],b[3*T+2]));s.addAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),s.addAttribute("color",new THREE.BufferAttribute(new Float32Array(c),3)),s.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(d),1)),s.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(u),1)),s.addAttribute("returnNumber",new THREE.BufferAttribute(new Float32Array(m),1)),s.addAttribute("pointSourceID",new THREE.BufferAttribute(new Float32Array(E),1)),s.addAttribute("indices",new THREE.BufferAttribute(f,1)),s.boundingBox=new THREE.Box3(i,n),e.boundingBox=s.boundingBox,e.geometry=s,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(o)};var r={buffer:t.arrayb,numPoints:t.pointsCount,pointSize:t.pointSize,pointFormatID:2,scale:t.scale,offset:t.offset,mins:[e.pcoGeometry.boundingBox.min.x,e.pcoGeometry.boundingBox.min.y,e.pcoGeometry.boundingBox.min.z],maxs:[e.pcoGeometry.boundingBox.max.x,e.pcoGeometry.boundingBox.max.y,e.pcoGeometry.boundingBox.max.z],bbOffset:[e.pcoGeometry.offset.x,e.pcoGeometry.offset.y,e.pcoGeometry.offset.z]};o.postMessage(r,[r.buffer])}},Potree.PointSizeType={FIXED:0,ATTENUATED:1,ADAPTIVE:2},Potree.PointShape={SQUARE:0,CIRCLE:1},Potree.PointColorType={RGB:0,COLOR:1,DEPTH:2,HEIGHT:3,INTENSITY:4,INTENSITY_GRADIENT:5,OCTREE_DEPTH:6,POINT_INDEX:7,CLASSIFICATION:8,RETURN_NUMBER:9,SOURCE:10},Potree.ClipMode={DISABLED:0,CLIP_OUTSIDE:1,HIGHLIGHT_INSIDE:2},Potree.PointCloudMaterial=function(e){e=e||{};var t=new THREE.Color(0),o=THREE.ImageUtils.generateDataTexture(2048,1,t);o.magFilter=THREE.NearestFilter,this.visibleNodesTexture=o;var i=e.size||1,n=e.minSize||1,r=1;this._pointSizeType=Potree.PointSizeType.ATTENUATED,this._pointShape=Potree.PointShape.SQUARE,this._interpolate=!1,this._pointColorType=Potree.PointColorType.RGB,this._octreeLevels=6,this._useClipBox=!1,this.numClipBoxes=0,this._clipMode=Potree.ClipMode.DISABLED,this._weighted=!1,this._blendDepth=.1,this._depthMap,this.gradientTexture=Potree.PointCloudMaterial.generateGradient();var s={},a={spacing:{type:"f",value:1},fov:{type:"f",value:1},screenWidth:{type:"f",value:1},screenHeight:{type:"f",value:1},near:{type:"f",value:.1},far:{type:"f",value:1},uColor:{type:"c",value:new THREE.Color(16711680)},opacity:{type:"f",value:1},size:{type:"f",value:10},minSize:{type:"f",value:2},nodeSize:{type:"f",value:r},heightMin:{type:"f",value:0},heightMax:{type:"f",value:1},intensityMin:{type:"f",value:0},intensityMax:{type:"f",value:1},visibleNodes:{type:"t",value:this.visibleNodesTexture},pcIndex:{type:"f",value:0},gradient:{type:"t",value:this.gradientTexture},clipBoxes:{type:"Matrix4fv",value:[]},blendDepth:{type:"f",value:this._blendDepth},depthMap:{type:"t",value:null}};this.setValues({uniforms:a,attributes:s,vertexShader:this.getDefines()+Potree.PointCloudMaterial.vs_points.join("\n"),fragmentShader:this.getDefines()+Potree.PointCloudMaterial.fs_points_rgb.join("\n"),vertexColors:THREE.VertexColors,size:i,minSize:n,nodeSize:r,pcIndex:0,alphaTest:.9})},Potree.PointCloudMaterial.prototype=new THREE.RawShaderMaterial,Potree.PointCloudMaterial.prototype.updateShaderSource=function(){var e={};this.pointColorType===Potree.PointColorType.INTENSITY||this.pointColorType===Potree.PointColorType.INTENSITY_GRADIENT?e.intensity={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.CLASSIFICATION?e.classification={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.RETURN_NUMBER?e.returnNumber={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.SOURCE&&(e.pointSourceID={type:"f",value:[]}),this.setValues({attributes:e,vertexShader:this.getDefines()+Potree.PointCloudMaterial.vs_points.join("\n"),fragmentShader:this.getDefines()+Potree.PointCloudMaterial.fs_points_rgb.join("\n")}),this.depthMap&&(this.uniforms.depthMap.value=this.depthMap,this.setValues({depthMap:this.depthMap})),this.setValues(1===this.opacity?{blending:THREE.NoBlending,transparent:!1,depthTest:!0,depthWrite:!0}:{blending:THREE.AdditiveBlending,transparent:!0,depthTest:!1,depthWrite:!0}),this.weighted&&this.setValues({blending:THREE.AdditiveBlending,transparent:!0,depthTest:!0,depthWrite:!1}),this.needsUpdate=!0},Potree.PointCloudMaterial.prototype.getDefines=function(){var e="";return this.pointSizeType===Potree.PointSizeType.FIXED?e+="#define fixed_point_size\n":this.pointSizeType===Potree.PointSizeType.ATTENUATED?e+="#define attenuated_point_size\n":this.pointSizeType===Potree.PointSizeType.ADAPTIVE&&(e+="#define adaptive_point_size\n",e+="#define octreeLevels "+Math.max(0,this._octreeLevels-2).toFixed(1)+"\n"),this.pointShape===Potree.PointShape.SQUARE?e+="#define square_point_shape\n":this.pointShape===Potree.PointShape.CIRCLE&&(e+="#define circle_point_shape\n"),this._interpolate&&(e+="#define use_interpolation\n"),this._pointColorType===Potree.PointColorType.RGB?e+="#define color_type_rgb\n":this._pointColorType===Potree.PointColorType.COLOR?e+="#define color_type_color\n":this._pointColorType===Potree.PointColorType.DEPTH?e+="#define color_type_depth\n":this._pointColorType===Potree.PointColorType.HEIGHT?e+="#define color_type_height\n":this._pointColorType===Potree.PointColorType.INTENSITY?e+="#define color_type_intensity\n":this._pointColorType===Potree.PointColorType.INTENSITY_GRADIENT?e+="#define color_type_intensity_gradient\n":this._pointColorType===Potree.PointColorType.OCTREE_DEPTH?e+="#define color_type_octree_depth\n":this._pointColorType===Potree.PointColorType.POINT_INDEX?e+="#define color_type_point_index\n":this._pointColorType===Potree.PointColorType.CLASSIFICATION?e+="#define color_type_classification\n":this._pointColorType===Potree.PointColorType.RETURN_NUMBER?e+="#define color_type_return_number\n":this._pointColorType===Potree.PointColorType.SOURCE&&(e+="#define color_type_source\n"),this.clipMode===Potree.ClipMode.DISABLED?e+="#define clip_disabled\n":this.clipMode===Potree.ClipMode.CLIP_OUTSIDE?e+="#define clip_outside\n":this.clipMode===Potree.ClipMode.HIGHLIGHT_INSIDE&&(e+="#define clip_highlight_inside\n"),this.weighted&&(e+="#define weighted_splats\n"),this.numClipBoxes>0&&(e+="#define use_clip_box\n",e+="#define clip_box_count "+this.numClipBoxes+"\n"),e},Potree.PointCloudMaterial.prototype.setClipBoxes=function(e){var t=e.length;this.numClipBoxes=t,this.uniforms.clipBoxes.value.length/16!==t&&(this.uniforms.clipBoxes.value=new Float32Array(16*t),this.updateShaderSource());for(var o=0;t>o;o++){var i=e[o];this.uniforms.clipBoxes.value.set(i.elements,16*o)}},Object.defineProperty(Potree.PointCloudMaterial.prototype,"spacing",{get:function(){return this.uniforms.spacing.value},set:function(e){this.uniforms.spacing.value!==e&&(this.uniforms.spacing.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"blendDepth",{get:function(){return this.uniforms.blendDepth.value},set:function(e){this.uniforms.blendDepth.value!==e&&(this.uniforms.blendDepth.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"useClipBox",{get:function(){return this._useClipBox},set:function(e){this._useClipBox!==e&&(this._useClipBox=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"weighted",{get:function(){return this._weighted},set:function(e){this._weighted!==e&&(this._weighted=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"fov",{get:function(){return this.uniforms.fov.value},set:function(e){this.uniforms.fov.value!==e&&(this.uniforms.fov.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"screenWidth",{get:function(){return this.uniforms.screenWidth.value +},set:function(e){this.uniforms.screenWidth.value!==e&&(this.uniforms.screenWidth.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"screenHeight",{get:function(){return this.uniforms.screenHeight.value},set:function(e){this.uniforms.screenHeight.value!==e&&(this.uniforms.screenHeight.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"near",{get:function(){return this.uniforms.near.value},set:function(e){this.uniforms.near.value!==e&&(this.uniforms.near.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"far",{get:function(){return this.uniforms.far.value},set:function(e){this.uniforms.far.value!==e&&(this.uniforms.far.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"opacity",{get:function(){return this.uniforms.opacity.value},set:function(e){this.uniforms.opacity.value!==e&&(this.uniforms.opacity.value=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"octreeLevels",{get:function(){return this._octreeLevels},set:function(e){this._octreeLevels!==e&&(this._octreeLevels=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointColorType",{get:function(){return this._pointColorType},set:function(e){this._pointColorType!==e&&(this._pointColorType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"depthMap",{get:function(){return this._depthMap},set:function(e){this._depthMap!==e&&(this._depthMap=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointSizeType",{get:function(){return this._pointSizeType},set:function(e){this._pointSizeType!==e&&(this._pointSizeType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"clipMode",{get:function(){return this._clipMode},set:function(e){this._clipMode!==e&&(this._clipMode=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"interpolate",{get:function(){return this._interpolate},set:function(e){this._interpolate!==e&&(this._interpolate=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"color",{get:function(){return this.uniforms.uColor.value},set:function(e){this.uniforms.uColor.value!==e&&(this.uniforms.uColor.value.copy(e),this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointShape",{get:function(){return this._pointShape},set:function(e){this._pointShape!==e&&(this._pointShape=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"size",{get:function(){return this.uniforms.size.value},set:function(e){this.uniforms.size.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"minSize",{get:function(){return this.uniforms.minSize.value},set:function(e){this.uniforms.minSize.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"heightMin",{get:function(){return this.uniforms.heightMin.value},set:function(e){this.uniforms.heightMin.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"heightMax",{get:function(){return this.uniforms.heightMax.value},set:function(e){this.uniforms.heightMax.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"intensityMin",{get:function(){return this.uniforms.intensityMin.value},set:function(e){this.uniforms.intensityMin.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"intensityMax",{get:function(){return this.uniforms.intensityMax.value},set:function(e){this.uniforms.intensityMax.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pcIndex",{get:function(){return this.uniforms.pcIndex.value},set:function(e){this.uniforms.pcIndex.value=e}}),Potree.PointCloudMaterial.generateGradient=function(){var e=64;canvas=document.createElement("canvas"),canvas.width=e,canvas.height=e;var t=canvas.getContext("2d");t.rect(0,0,e,e);var o=t.createLinearGradient(0,0,e,e);o.addColorStop(0,"#4700b6"),o.addColorStop(1/6,"blue"),o.addColorStop(2/6,"aqua"),o.addColorStop(.5,"green"),o.addColorStop(4/6,"yellow"),o.addColorStop(5/6,"orange"),o.addColorStop(1,"red"),t.fillStyle=o,t.fill();var i=new THREE.Texture(canvas);return i.needsUpdate=!0,textureImage=i.image,i},Potree.PointCloudMaterial.vs_points=["precision mediump float; ","precision mediump int; "," ","attribute vec3 position; ","attribute vec3 color; ","attribute float intensity; ","attribute float classification; ","attribute float returnNumber; ","attribute float pointSourceID; ","attribute vec4 indices; "," ","uniform mat4 modelMatrix; ","uniform mat4 modelViewMatrix; ","uniform mat4 projectionMatrix; ","uniform mat4 viewMatrix; ","uniform mat3 normalMatrix; ","uniform vec3 cameraPosition; ","uniform float screenWidth; ","uniform float screenHeight; ","uniform float fov; ","uniform float spacing; ","uniform float blendDepth; ","uniform float near; ","uniform float far; "," ","#if defined use_clip_box "," uniform mat4 clipBoxes[clip_box_count]; ","#endif "," "," ","uniform float heightMin; ","uniform float heightMax; ","uniform float intensityMin; ","uniform float intensityMax; ","uniform float size; ","uniform float minSize; ","uniform float nodeSize; ","uniform vec3 uColor; ","uniform float opacity; "," "," ","uniform sampler2D visibleNodes; ","uniform sampler2D gradient; ","uniform sampler2D depthMap; "," ","varying float vOpacity; ","varying vec3 vColor; ","varying float vDepth; ","varying float vLinearDepth; ","varying vec3 vViewPos; ","varying float vRadius; "," "," ","#if defined(adaptive_point_size) || defined(color_type_octree_depth) ","/** "," * number of 1-bits up to inclusive index position "," * number is treated as if it were an integer in the range 0-255 "," * "," */ ","float numberOfOnes(float number, float index){ "," float tmp = mod(number, pow(2.0, index + 1.0)); "," float numOnes = 0.0; "," for(float i = 0.0; i < 8.0; i++){ "," if(mod(tmp, 2.0) != 0.0){ "," numOnes++; "," } "," tmp = floor(tmp / 2.0); "," } "," return numOnes; ","} "," "," ","/** "," * checks whether the bit at index is 1 "," * number is treated as if it were an integer in the range 0-255 "," * "," */ ","bool isBitSet(float number, float index){ "," return mod(floor(number / pow(2.0, index)), 2.0) != 0.0; ","} "," "," ","/** "," * find the octree depth at the point position "," */ ","float getOctreeDepth(){ "," vec3 offset = vec3(0.0, 0.0, 0.0); "," float iOffset = 0.0; "," float depth = 0.0; "," for(float i = 0.0; i <= octreeLevels + 1.0; i++){ "," "," float nodeSizeAtLevel = nodeSize / pow(2.0, i); "," vec3 index3d = (position - offset) / nodeSizeAtLevel; "," index3d = floor(index3d + 0.5); "," float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z; "," "," vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0)); "," float mask = value.r * 255.0; "," if(isBitSet(mask, index)){ "," // there are more visible child nodes at this position "," iOffset = iOffset + value.g * 255.0 + numberOfOnes(mask, index - 1.0); "," depth++; "," }else{ "," // no more visible child nodes at this position "," return depth; "," } "," offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; "," } "," "," return depth; ","} "," ","#endif "," ","vec3 classificationColor(float classification){ "," vec3 color = vec3(0.0, 0.0, 0.0); "," float c = mod(classification, 16.0); "," if(c == 0.0){ "," color = vec3(0.5, 0.5, 0.5); "," }else if(c == 1.0){ "," color = vec3(0.5, 0.5, 0.5); "," }else if(c == 2.0){ "," color = vec3(0.63, 0.32, 0.18); "," }else if(c == 3.0){ "," color = vec3(0.0, 1.0, 0.0); "," }else if(c == 4.0){ "," color = vec3(0.0, 0.8, 0.0); "," }else if(c == 5.0){ "," color = vec3(0.0, 0.6, 0.0); "," }else if(c == 6.0){ "," color = vec3(1.0, 0.66, 0.0); "," }else if(c == 7.0){ "," color = vec3(1.0, 0, 1.0); "," }else if(c == 8.0){ "," color = vec3(1.0, 0, 0.0); "," }else if(c == 9.0){ "," color = vec3(0.0, 0.0, 1.0); "," }else if(c == 12.0){ "," color = vec3(1.0, 1.0, 0.0); "," }else{ "," color = vec3(0.3, 0.6, 0.6); "," } "," "," return color; ","} "," ","void main() { "," "," vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); "," vViewPos = mvPosition.xyz; "," gl_Position = projectionMatrix * mvPosition; "," //float pw = gl_Position.w; "," //float pd = gl_Position.z; "," //gl_Position = gl_Position / pw; "," //gl_Position.z = 2.0*((pw - near) / far)-1.0; "," vOpacity = opacity; "," vLinearDepth = -mvPosition.z; "," vDepth = mvPosition.z / gl_Position.w; "," "," // COLOR TYPES "," "," #ifdef color_type_rgb "," vColor = color; "," #elif defined color_type_height "," vec4 world = modelMatrix * vec4( position, 1.0 ); "," float w = (world.y - heightMin) / (heightMax-heightMin); "," "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_depth "," float d = -mvPosition.z ; "," vColor = vec3(d, vDepth, 0.0); "," #elif defined color_type_intensity "," float w = (intensity - intensityMin) / (intensityMax - intensityMin); "," vColor = vec3(w, w, w); "," #elif defined color_type_intensity_gradient "," float w = (intensity - intensityMin) / intensityMax; "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_color "," vColor = uColor; "," #elif defined color_type_octree_depth "," float depth = getOctreeDepth(); "," float w = depth / 10.0; "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_point_index "," vColor = indices.rgb; "," #elif defined color_type_classification "," vColor = classificationColor(classification); "," #elif defined color_type_return_number "," float w = (returnNumber - 1.0) / 4.0 + 0.1; "," vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb; "," #elif defined color_type_source "," float w = mod(pointSourceID, 10.0) / 10.0; "," vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb; "," #endif "," "," "," "," // "," // POINT SIZE TYPES "," // "," float projFactor = 1.0 / tan(fov / 2.0); "," projFactor /= -vViewPos.z; "," projFactor *= screenHeight / 2.0; "," float r = spacing * 1.5; "," vRadius = r; "," #if defined fixed_point_size "," gl_PointSize = size; "," #elif defined attenuated_point_size "," gl_PointSize = size * projFactor; "," #elif defined adaptive_point_size "," float worldSpaceSize = size * r / pow(1.9, getOctreeDepth()); "," gl_PointSize = worldSpaceSize * projFactor; "," #endif "," "," gl_PointSize = max(minSize, gl_PointSize); "," gl_PointSize = min(50.0, gl_PointSize); "," "," vRadius = gl_PointSize / projFactor; "," "," "," // clip box "," #if defined use_clip_box "," bool insideAny = false; "," for(int i = 0; i < clip_box_count; i++){ "," vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 ); "," bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5; "," inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5; "," inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5; "," insideAny = insideAny || inside; "," } "," if(!insideAny){ "," "," #if defined clip_outside "," gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0); "," #elif defined clip_highlight_inside && !defined(color_type_depth) "," float c = (vColor.r + vColor.g + vColor.b) / 6.0; "," //vColor = vec3(c, c, c); "," #endif "," }else{ "," #if defined clip_highlight_inside "," vColor.r += 0.5; "," #endif "," } "," "," #endif "," "," ","} "],Potree.PointCloudMaterial.fs_points_rgb=["#if defined use_interpolation "," #extension GL_EXT_frag_depth : enable ","#endif "," ","precision mediump float; ","precision mediump int; "," ","//uniform float opacity; ","uniform mat4 modelMatrix; ","uniform mat4 modelViewMatrix; ","uniform mat4 projectionMatrix; ","uniform mat4 viewMatrix; ","uniform mat3 normalMatrix; ","uniform vec3 cameraPosition; ","uniform float fov; ","uniform float spacing; ","uniform float near; ","uniform float far; "," ","uniform float pcIndex; ","uniform float screenWidth; ","uniform float screenHeight; ","uniform float blendDepth; "," ","uniform sampler2D depthMap; "," ","varying vec3 vColor; ","varying float vOpacity; ","varying float vLinearDepth; ","varying float vDepth; ","varying vec3 vViewPos; ","varying float vRadius; "," "," ","void main() { "," "," #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats) "," float u = 2.0 * gl_PointCoord.x - 1.0; "," float v = 2.0 * gl_PointCoord.y - 1.0; "," #endif "," "," #if defined(circle_point_shape) || defined (weighted_splats) "," float cc = u*u + v*v; "," if(cc > 1.0){ "," discard; "," } "," #endif "," "," #if defined weighted_splats "," vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight); "," "," float depth = texture2D(depthMap, uv).r; "," if(vLinearDepth > depth + vRadius * 0.5){ "," discard; "," } "," #endif "," "," #if defined use_interpolation "," float w = 1.0 - ( u*u + v*v); "," vec4 pos = vec4(vViewPos, 1.0); "," pos.z += w * vRadius; "," pos = projectionMatrix * pos; "," pos = pos / pos.w; "," "," gl_FragDepthEXT = (pos.z + 1.0) / 2.0; "," #endif "," "," "," #if defined color_type_point_index "," gl_FragColor = vec4(vColor, pcIndex / 255.0); "," #else "," gl_FragColor = vec4(vColor, vOpacity); "," #endif "," "," "," #if defined weighted_splats "," float w = pow(1.0 - (u*u + v*v), 2.0); "," gl_FragColor.rgb = gl_FragColor.rgb * w; "," gl_FragColor.a = w; "," #endif "," "," "," ","} "],THREE.FirstPersonControls=function(e,t){function o(e){l.enabled!==!1&&(e.preventDefault(),0===e.button?(R=T.ROTATE,c.set(e.clientX,e.clientY)):2===e.button&&(R=T.PAN,u.set(e.clientX,e.clientY)),l.domElement.addEventListener("mousemove",i,!1),l.domElement.addEventListener("mouseup",n,!1),l.dispatchEvent(w)) +}function i(e){if(l.enabled!==!1){e.preventDefault();var t=l.domElement===document?l.domElement.body:l.domElement;R===T.ROTATE?(d.set(e.clientX,e.clientY),h.subVectors(d,c),l.rotateLeft(2*Math.PI*h.x/t.clientWidth*l.rotateSpeed),l.rotateUp(2*Math.PI*h.y/t.clientHeight*l.rotateSpeed),c.copy(d)):R===T.PAN&&(p.set(e.clientX,e.clientY),m.subVectors(p,u),m.multiplyScalar(5e-4).multiplyScalar(l.moveSpeed),l.pan(m.x,m.y),u.copy(p))}}function n(){l.enabled!==!1&&(l.domElement.removeEventListener("mousemove",i,!1),l.domElement.removeEventListener("mouseup",n,!1),l.dispatchEvent(C),R=T.NONE)}function r(e){if(l.enabled!==!1&&l.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1;l.moveSpeed+=.1*l.moveSpeed*t,l.moveSpeed=Math.max(.1,l.moveSpeed),l.dispatchEvent(w),l.dispatchEvent(C)}}function s(e){if(l.enabled!==!1)switch(e.keyCode){case l.keys.UP:l.moveForward=!0;break;case l.keys.BOTTOM:l.moveBackward=!0;break;case l.keys.LEFT:l.moveLeft=!0;break;case l.keys.RIGHT:l.moveRight=!0;break;case l.keys.W:l.moveForward=!0;break;case l.keys.S:l.moveBackward=!0;break;case l.keys.A:l.moveLeft=!0;break;case l.keys.D:l.moveRight=!0}}function a(e){switch(e.keyCode){case l.keys.W:l.moveForward=!1;break;case l.keys.S:l.moveBackward=!1;break;case l.keys.A:l.moveLeft=!1;break;case l.keys.D:l.moveRight=!1;break;case l.keys.UP:l.moveForward=!1;break;case l.keys.BOTTOM:l.moveBackward=!1;break;case l.keys.LEFT:l.moveLeft=!1;break;case l.keys.RIGHT:l.moveRight=!1}}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.rotateSpeed=1,this.moveSpeed=10,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40,A:"A".charCodeAt(0),S:"S".charCodeAt(0),D:"D".charCodeAt(0),W:"W".charCodeAt(0)};var l=this,c=new THREE.Vector2,d=new THREE.Vector2,h=new THREE.Vector2,u=new THREE.Vector2,p=new THREE.Vector2,m=new THREE.Vector2,v=new THREE.Vector3,E=(new THREE.Vector3,0),f=0,g=1,y=new THREE.Vector3,b=new THREE.Vector3,T={NONE:-1,ROTATE:0,SPEEDCHANGE:1,PAN:2},R=T.NONE;this.position0=this.object.position.clone();var P={type:"change"},w={type:"start"},C={type:"end"};this.rotateLeft=function(e){f-=e},this.rotateUp=function(e){E-=e},this.panLeft=function(e){var t=this.object.matrix.elements;v.set(t[0],t[1],t[2]),v.multiplyScalar(-e),y.add(v)},this.panUp=function(e){var t=this.object.matrix.elements;v.set(t[4],t[5],t[6]),v.multiplyScalar(e),y.add(v)},this.panForward=function(e){var t=this.object.matrix.elements;v.set(t[8],t[9],t[10]),v.multiplyScalar(e),y.add(v)},this.pan=function(e,t){var o=l.domElement===document?l.domElement.body:l.domElement;if(void 0!==l.object.fov){var i=l.object.position,n=i.clone(),r=n.length();r*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*r/o.clientHeight),l.panUp(2*t*r/o.clientHeight)}else void 0!==l.object.top?(l.panLeft(e*(l.object.right-l.object.left)/o.clientWidth),l.panUp(t*(l.object.top-l.object.bottom)/o.clientHeight)):console.warn("WARNING: FirstPersonControls.js encountered an unknown camera type - pan disabled.")},this.update=function(e){this.object.rotation.order="ZYX";var t=this.object;this.object=new THREE.Object3D,this.object.position.copy(t.position),this.object.rotation.copy(t.rotation),this.object.updateMatrix(),this.object.updateMatrixWorld();var o=this.object.position;if(void 0!==e&&(this.moveRight&&this.panLeft(-e*this.moveSpeed),this.moveLeft&&this.panLeft(e*this.moveSpeed),this.moveForward&&this.panForward(-e*this.moveSpeed),this.moveBackward&&this.panForward(e*this.moveSpeed)),!y.equals(new THREE.Vector3(0,0,0))){var i={type:"move",translation:y.clone()};this.dispatchEvent(i)}if(o.add(y),0!==f||0!==E){var i={type:"rotate",thetaDelta:f,phiDelta:E};this.dispatchEvent(i)}this.object.updateMatrix();var n=(new THREE.Matrix4).makeRotationY(f),r=(new THREE.Matrix4).multiplyMatrices(n,this.object.matrix);this.object.quaternion.setFromRotationMatrix(r),this.object.rotation.x+=E,this.object.updateMatrixWorld();var s={type:"proposeTransform",oldPosition:t.position,newPosition:this.object.position,objections:0,counterProposals:[]};if(this.dispatchEvent(s),s.objections>0&&s.counterProposals.length>0){var a=s.counterProposals;this.object.position.copy(a[0]),s.objections=0,s.counterProposals=[]}s.objections>0||t.position.copy(this.object.position),t.rotation.copy(this.object.rotation),this.object=t,f=0,E=0,g=1,y.set(0,0,0),b.distanceTo(this.object.position)>0&&(this.dispatchEvent(P),b.copy(this.object.position))},this.reset=function(){R=T.NONE,this.object.position.copy(this.position0)},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",r,!1),this.domElement.addEventListener("DOMMouseScroll",r,!1),window.addEventListener("keydown",s,!1),window.addEventListener("keyup",a,!1)},THREE.FirstPersonControls.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.OrbitControls=function(e,t){function o(){return 2*Math.PI/60/60*u.autoRotateSpeed}function i(){return Math.pow(.95,u.zoomSpeed)}function n(e){if(u.enabled!==!1){if(e.preventDefault(),0===e.button){if(u.noRotate===!0)return;A=S.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(u.noZoom===!0)return;A=S.DOLLY,R.set(e.clientX,e.clientY)}else if(2===e.button){if(u.noPan===!0)return;A=S.PAN,f.set(e.clientX,e.clientY)}u.domElement.addEventListener("mousemove",r,!1),u.domElement.addEventListener("mouseup",s,!1),u.dispatchEvent(I)}}function r(e){if(u.enabled!==!1){e.preventDefault();var t=u.domElement===document?u.domElement.body:u.domElement;if(A===S.ROTATE){if(u.noRotate===!0)return;v.set(e.clientX,e.clientY),E.subVectors(v,m),u.rotateLeft(2*Math.PI*E.x/t.clientWidth*u.rotateSpeed),u.rotateUp(2*Math.PI*E.y/t.clientHeight*u.rotateSpeed),m.copy(v)}else if(A===S.DOLLY){if(u.noZoom===!0)return;P.set(e.clientX,e.clientY),w.subVectors(P,R),w.y>0?u.dollyIn():u.dollyOut(),R.copy(P)}else if(A===S.PAN){if(u.noPan===!0)return;g.set(e.clientX,e.clientY),y.subVectors(g,f),u.pan(y.x,y.y),f.copy(g)}}}function s(){u.enabled!==!1&&(u.domElement.removeEventListener("mousemove",r,!1),u.domElement.removeEventListener("mouseup",s,!1),u.dispatchEvent(L),A=S.NONE)}function a(e){if(u.enabled!==!1&&u.noZoom!==!0){e.preventDefault();var t=0;void 0!==e.wheelDelta?t=e.wheelDelta:void 0!==e.detail&&(t=-e.detail),t>0?u.dollyOut():u.dollyIn(),u.dispatchEvent(I),u.dispatchEvent(L)}}function l(e){if(u.enabled!==!1&&u.noKeys!==!0&&u.noPan!==!0)switch(e.keyCode){case u.keys.UP:u.pan(0,u.keyPanSpeed);break;case u.keys.BOTTOM:u.pan(0,-u.keyPanSpeed);break;case u.keys.LEFT:u.pan(u.keyPanSpeed,0);break;case u.keys.RIGHT:u.pan(-u.keyPanSpeed,0)}}function c(e){if(u.enabled!==!1){switch(e.touches.length){case 1:if(u.noRotate===!0)return;A=S.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(u.noZoom===!0)return;A=S.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,o=e.touches[0].pageY-e.touches[1].pageY,i=Math.sqrt(t*t+o*o);R.set(0,i);break;case 3:if(u.noPan===!0)return;A=S.TOUCH_PAN,f.set(e.touches[0].pageX,e.touches[0].pageY);break;default:A=S.NONE}u.dispatchEvent(I)}}function d(e){if(u.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=u.domElement===document?u.domElement.body:u.domElement;switch(e.touches.length){case 1:if(u.noRotate===!0)return;if(A!==S.TOUCH_ROTATE)return;v.set(e.touches[0].pageX,e.touches[0].pageY),E.subVectors(v,m),u.rotateLeft(2*Math.PI*E.x/t.clientWidth*u.rotateSpeed),u.rotateUp(2*Math.PI*E.y/t.clientHeight*u.rotateSpeed),m.copy(v);break;case 2:if(u.noZoom===!0)return;if(A!==S.TOUCH_DOLLY)return;var o=e.touches[0].pageX-e.touches[1].pageX,i=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(o*o+i*i);P.set(0,n),w.subVectors(P,R);var r=t.clientWidth,s=t.clientHeight,a=Math.sqrt(r*r+s*s),l=w.y/a;w.y>0?u.dollyOut(1-l):u.dollyIn(1+l),R.copy(P);break;case 3:if(u.noPan===!0)return;if(A!==S.TOUCH_PAN)return;g.set(e.touches[0].pageX,e.touches[0].pageY),y.subVectors(g,f),u.pan(y.x,y.y),f.copy(g);break;default:A=S.NONE}}}function h(){u.enabled!==!1&&(u.dispatchEvent(L),A=S.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.fadeFactor=10,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var u=this,p=1e-6,m=new THREE.Vector2,v=new THREE.Vector2,E=new THREE.Vector2,f=new THREE.Vector2,g=new THREE.Vector2,y=new THREE.Vector2,b=new THREE.Vector3,T=new THREE.Vector3,R=new THREE.Vector2,P=new THREE.Vector2,w=new THREE.Vector2,C=0,x=0,H=1,V=new THREE.Vector3,M=new THREE.Vector3,S={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},A=S.NONE;this.target0=this.target.clone(),this.position0=this.object.position.clone();var B={type:"change"},I={type:"start"},L={type:"end"};this.rotateLeft=function(e){void 0===e&&(e=o()),x-=e},this.rotateUp=function(e){void 0===e&&(e=o()),C-=e},this.panLeft=function(e){var t=this.object.matrix.elements;b.set(t[0],t[1],t[2]),b.multiplyScalar(-e),V.add(b)},this.panUp=function(e){var t=this.object.matrix.elements;b.set(t[4],t[5],t[6]),b.multiplyScalar(e),V.add(b)},this.pan=function(e,t){var o=u.domElement===document?u.domElement.body:u.domElement;if(void 0!==u.object.fov){var i=u.object.position,n=i.clone().sub(u.target),r=n.length();r*=Math.tan(u.object.fov/2*Math.PI/180),u.panLeft(2*e*r/o.clientHeight),u.panUp(2*t*r/o.clientHeight)}else void 0!==u.object.top?(u.panLeft(e*(u.object.right-u.object.left)/o.clientWidth),u.panUp(t*(u.object.top-u.object.bottom)/o.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=i()),H/=e},this.dollyOut=function(e){void 0===e&&(e=i()),H*=e},this.update=function(e){var t=this.object.position.clone();T.copy(t).sub(this.target);var i=Math.atan2(T.x,T.z),n=Math.atan2(Math.sqrt(T.x*T.x+T.z*T.z),T.y);this.autoRotate&&this.rotateLeft(o());var r=Math.min(1,this.fadeFactor*e);i+=r*x,n+=r*C,n=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,n)),n=Math.max(p,Math.min(Math.PI-p,n));var s=T.length();s+=(H-1)*s*r,s=Math.max(this.minDistance,Math.min(this.maxDistance,s)),this.target.add(V.clone().multiplyScalar(r)),T.x=s*Math.sin(n)*Math.sin(i),T.y=s*Math.cos(n),T.z=s*Math.sin(n)*Math.cos(i),t.copy(this.target).add(T);var a={type:"proposeTransform",oldPosition:this.object.position,newPosition:t,objections:0,counterProposals:[]};for(this.dispatchEvent(a);a.objections>0;)if(a.counterProposals.length>0){var l=a.counterProposals;t.copy(l[0]),a.objections=0,a.counterProposals=[]}if(a.objections>0)x=0,C=0,H=1,V.set(0,0,0);else{this.object.position.copy(t),this.object.lookAt(this.target);var c=Math.max(0,1-this.fadeFactor*e);x*=c,C*=c,H=1+(H-1)*c,V.multiplyScalar(c)}M.distanceTo(this.object.position)>0&&(this.dispatchEvent(B),M.copy(this.object.position))},this.reset=function(){A=S.NONE,this.target.copy(this.target0),this.object.position.copy(this.position0),this.update()},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",n,!1),this.domElement.addEventListener("mousewheel",a,!1),this.domElement.addEventListener("DOMMouseScroll",a,!1),this.domElement.addEventListener("touchstart",c,!1),this.domElement.addEventListener("touchend",h,!1),this.domElement.addEventListener("touchmove",d,!1),window.addEventListener("keydown",l,!1)},Potree.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype),THREE.EarthControls=function(e,t,o){function i(e){if(a.enabled!==!1){e.preventDefault();var t=a.domElement.getBoundingClientRect(),o={x:(e.clientX-t.left)/a.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/a.domElement.clientHeight)+1},i=getMousePointCloudIntersection(o,a.camera,a.renderer,a.pointclouds);if(i){var s=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),i),u=new THREE.Vector3(o.x,o.y,.5);u.unproject(a.camera);var p=u.sub(a.camera.position).normalize(),m=new THREE.Ray(a.camera.position,p);E=m.intersectPlane(s),v=a.camera.clone(),v.rotation.copy(a.camera.rotation),d.set(e.clientX-t.left,e.clientY-t.top),h.set(e.clientX-t.left,e.clientY-t.top),a.scene.add(a.pivotNode),a.pivotNode.position.copy(E),0===e.button?c=l.DRAG:2===e.button&&(c=l.ROTATE),a.domElement.addEventListener("mousemove",n,!1),a.domElement.addEventListener("mouseup",r,!1)}}}function n(e){if(a.enabled!==!1){e.preventDefault();{var t=a.domElement.getBoundingClientRect();a.domElement===document?a.domElement.body:a.domElement}m.set(e.clientX-t.left-h.x,e.clientY-t.top-h.y),h.set(e.clientX-t.left,e.clientY-t.top)}}function r(){a.enabled!==!1&&(a.domElement.removeEventListener("mousemove",n,!1),a.domElement.removeEventListener("mouseup",r,!1),c=l.NONE,a.scene.remove(a.pivotNode))}function s(e){if(a.enabled!==!1&&a.noZoom!==!0){e.preventDefault();var t=a.domElement.getBoundingClientRect(),o=e.detail<0||e.wheelDelta>0?1:-1,i={x:(e.clientX-t.left)/a.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/a.domElement.clientHeight)+1},n=getMousePointCloudIntersection(i,a.camera,a.renderer,a.pointclouds);if(n){var r=n.distanceTo(a.camera.position),s=(new THREE.Vector3).subVectors(n,a.camera.position).normalize();a.camera.position.add(s.multiplyScalar(.1*r*o))}}}this.camera=e,this.renderer=t,this.pointclouds=[],this.domElement=t.domElement,this.scene=o,this.enabled=!0;var a=this,l={NONE:-1,DRAG:0,ROTATE:1},c=l.NONE,d=new THREE.Vector2,h=new THREE.Vector2,u=new THREE.SphereGeometry(1,32,32),p=new THREE.MeshNormalMaterial({shading:THREE.SmoothShading,transparent:!0,opacity:.5});this.pivotNode=new THREE.Mesh(u,p);var m=new THREE.Vector2,v=null,E=null;this.minAngle=10/180*Math.PI,this.maxAngle=70/180*Math.PI,this.update=function(e){this.camera.position;this.camera.updateMatrixWorld();var t=new THREE.Object3D;if(t.position.copy(this.camera.position),t.rotation.copy(this.camera.rotation),t.updateMatrix(),t.updateMatrixWorld(),E){if(c===l.DRAG){var o=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),E),i={x:h.x/this.domElement.clientWidth*2-1,y:2*-(h.y/this.domElement.clientHeight)+1},n=new THREE.Vector3(i.x,i.y,.5);n.unproject(v);var r=n.sub(v.position).normalize(),s=new THREE.Ray(v.position,r),a=s.distanceToPlane(o);if(a>0){var d=(new THREE.Vector3).subVectors(E,r.clone().multiplyScalar(a));t.position.copy(d)}}else if(c===l.ROTATE){var u=m.clone().multiplyScalar(e);u.x*=.3,u.y*=.2;var p=new THREE.Object3D,f=new THREE.Object3D;p.add(f),p.position.copy(E),f.position.copy(this.camera.position).sub(E),f.rotation.copy(this.camera.rotation),p.rotation.y+=-u.x;var r=this.camera.getWorldDirection(),g=new THREE.Vector3(0,1,0),y=(new THREE.Vector3).crossVectors(g,r),b=f.position.clone();b.y=0,b.normalize();var T=b.dot(f.position.clone().normalize()),R=Math.acos(T);f.position.y<0&&(R=-R);var P=0;P=u.y>0?u.y-Math.max(0,this.minAngle-(R-u.y)):u.y+Math.max(0,R-u.y-this.maxAngle),p.rotateOnAxis(y,-P),p.updateMatrixWorld(),t.position.copy(f.getWorldPosition()),t.quaternion.copy(f.getWorldQuaternion())}var w={type:"proposeTransform",oldPosition:this.camera.position,newPosition:t.position,objections:0};this.dispatchEvent(w),w.objections>0||(this.camera.position.copy(t.position),this.camera.rotation.copy(t.rotation));var C=this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),x=Math.abs(C.z/30),H=this.pivotNode.scale.length();this.pivotNode.scale.multiplyScalar(x/H)}m.set(0,0)},this.reset=function(){c=l.NONE,this.camera.position.copy(this.position0)},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",i,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1)},THREE.EarthControls.prototype=Object.create(THREE.EventDispatcher.prototype),LRU.prototype.size=function(){return this.elements},LRU.prototype.contains=function(e){return null==this.items[e.id]},LRU.prototype.touch=function(e){if(e.loaded){var t;null==this.items[e.id]?(t=new LRUItem(e),t.previous=this.last,this.last=t,null!==t.previous&&(t.previous.next=t),this.items[e.id]=t,this.elements++,null===this.first&&(this.first=t),this.numPoints+=e.numPoints):(t=this.items[e.id],null===t.previous?null!==t.next&&(this.first=t.next,this.first.previous=null,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t):null===t.next||(t.previous.next=t.next,t.next.previous=t.previous,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t))}},LRU.prototype.remove=function(e){var t=this.items[e.id];t&&(1===this.elements?(this.first=null,this.last=null):(t.previous||(this.first=t.next,this.first.previous=null),t.next||(this.last=t.previous,this.last.next=null),t.previous&&t.next&&(t.previous.next=t.next,t.next.previous=t.previous)),delete this.items[e.id],this.elements--,this.numPoints-=e.numPoints)},LRU.prototype.getLRUItem=function(){if(null===this.first)return null;var e=this.first;return e.node},LRU.prototype.toString=function(){for(var e="{ ",t=this.first;null!==t;)e+=t.node.id,null!==t.next&&(e+=", "),t=t.next;return e+="}",e+="("+this.size()+")"},LRU.prototype.freeMemory=function(){if(!(this.elements<=1))for(;this.numPoints>Potree.pointLoadLimit;){var e=this.first,t=e.node;this.disposeDescendants(t)}},LRU.prototype.disposeDescendants=function(e){var t=[];for(t.push(e);t.length>0;){var o=t.pop();o.dispose(),this.remove(o);for(var i in o.children)if(o.children.hasOwnProperty(i)){var n=o.children[i];n.loaded&&t.push(o.children[i])}}},Potree.PointCloudOctreeProxyNode=function(e){THREE.Object3D.call(this),this.geometryNode=e,this.boundingBox=e.boundingBox,this.boundingSphere=this.boundingBox.getBoundingSphere(),this.name=e.name,this.level=e.level,this.numPoints=e.numPoints},Potree.PointCloudOctreeProxyNode.prototype=Object.create(THREE.Object3D.prototype),Potree.ProfileRequest=function(e,t,o,i,n){this.start=e,this.end=t,this.width=o,this.depth=i,this.callback=n,this.loadQueue=[];var r=((new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),(new THREE.Vector3).subVectors(t,e).length(),(new THREE.Vector3).subVectors(t,e).normalize()),s=new THREE.Vector3(0,1,0),a=(new THREE.Vector3).crossVectors(r,s).normalize(),l=a;this.plane=(new THREE.Plane).setFromNormalAndCoplanarPoint(l,e)},Potree.PointCloudOctree=function(e,t){THREE.Object3D.call(this),Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.pcoGeometry=e,this.boundingBox=this.pcoGeometry.tightBoundingBox,this.boundingSphere=this.boundingBox.getBoundingSphere(),this.material=t||new Potree.PointCloudMaterial,this.visiblePointsTarget=2e6,this.level=0,this.position.sub(e.offset),this.updateMatrix(),this.LODDistance=20,this.LODFalloff=1.3,this.LOD=4,this.showBoundingBox=!1,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleBounds=new THREE.Box3,this.profileRequests=[],this.visibleNodes=[],this.visibleGeometry=[],this.pickTarget,this.pickMaterial,this.maxLevel=0,this.generateDEM=!1;var o=new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);this.add(o)},Potree.PointCloudOctree.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudOctree.prototype.updateVisibleBounds=function(){for(var e=[],t=0;t0;){var r=n.shift();if(r instanceof Potree.PointCloudOctreeProxyNode){var s=Potree.utils.computeTransformedBoundingBox(r.boundingBox,r.matrixWorld),a=s.getBoundingSphere();Math.abs(o.distanceToPoint(a.center))0){var r=d.loadQueue[0],h=r.geometryNode;if(h.loaded===!0&&void 0!==r.parent){var u=this.replaceProxy(r);u.updateMatrixWorld(),u.matrixWorld.multiplyMatrices(u.parent.matrixWorld,u.matrix)}else r.geometryNode.load()}else{var p=this.getProfile(d.start,d.end,d.width,d.depth);d.callback({type:"finished",points:p}),c.push(d)}}for(var e=0;e-1&&this.profileRequests.splice(m,1)}},Potree.PointCloudOctree.prototype.updatePointCloud=function(e,t,o,i){if(this.numVisibleNodes++,this.numVisiblePoints+=e.numPoints,e.material=this.material,this.visibleNodes.push(t),e.level&&(this.maxLevel=Math.max(e.level,this.maxLevel)),this.showBoundingBox&&!e.boundingBoxNode){var n=new THREE.BoxHelper(e);this.add(n),this.boundingBoxNodes.push(n),e.boundingBoxNode=n,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)}else this.showBoundingBox?(e.boundingBoxNode.visible=!0,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)):!this.showBoundingBox&&e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);this.generateDEM&&e.level<=2&&(e.dem||(e.dem=this.createDEM(e)));for(var r=0;r=0;if(a)for(var l=0;l0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0;){{var s=r.shift(),a=s.node;s.weight}if(a.visible=!0,a.matrixWorld.multiplyMatrices(a.parent.matrixWorld,a.matrix),a instanceof Potree.PointCloudOctreeProxyNode){var l=a.geometryNode;l.loaded===!0?this.replaceProxy(a):this.loadQueue.push(s)}else if(a instanceof THREE.PointCloud)if(a.pcoGeometry.loaded)Potree.PointCloudOctree.lru.touch(a.pcoGeometry),this.updatePointCloud(a,s,r,o);else{var c=new Potree.PointCloudOctreeProxyNode(a.pcoGeometry),d=a.parent;d.remove(a),d.add(c)}}this.updateProfileRequests(),this.updateVisibleBounds(),this.updateLoadQueue(),this.hideDescendants(this.children[0]);for(var h=[],i=0;i0;){g++;var y=p.shift(),b=y.node,T=b.boundingBox,v=b.boundingSphere,R=i.intersectsBox(T),P=R;if(P){if(m+b.numPoints>this.visiblePointsTarget)break;m+=b.numPoints,t.push(y);for(var w=0;8>w;w++)if(b.children[w]){var C=b.children[w],v=C.boundingSphere,E=v.center.distanceTo(h),x=v.radius,f=v.radius/E,H=e.fov/2*Math.PI/180,V=1/Math.tan(H)*x/Math.sqrt(E*E-x*x);if(!(.1>V))if(f=V,0>E-x&&(f=Number.MAX_VALUE),0===p.length)p.push({node:C,weight:f});else{for(var M=0,S=0;Sp[S].weight){var M=S;break}if(S==p.length-1){M=p.length;break}}p.splice(M,0,{node:C,weight:f})}}}}return t},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(e,t){if(e){var o=e.visibleNodesTexture,i=o.image.data;t=t.slice();var n=function(e,t){var o=e.name,i=t.name;return o.length!=i.length?o.length-i.length:i>o?-1:o>i?1:0};t.sort(n);for(var r={},s=0;st.name?1:0}),i[3*s+0]=0,i[3*s+1]=0,i[3*s+2]=0;for(var c=0;cr;r++)if(void 0!==t.children[r]){var s=t.children[r],a=new Potree.PointCloudOctreeProxyNode(s);i.add(a)}return i}},Potree.PointCloudOctree.prototype.hideDescendants=function(e){for(var t=[],o=0;o0;){var e=t.shift();e.visible=!1;for(var o=0;o0&&(l=-l),function(e){var t=(new THREE.Matrix4).makeTranslation(-i.x,-i.y,-i.z),o=(new THREE.Matrix4).makeRotationY(-l),n=(new THREE.Matrix4).makeTranslation(r,0,0),s=e.clone();return s.applyMatrix4(t),s.applyMatrix4(o),s.applyMatrix4(n),s}}(r,s,i),c={start:r,end:s,points:a,project:l};o.push(c),i+=r.distanceTo(s)}return o},Potree.PointCloudOctree.prototype.getProfile=function(e,t,o,i,n){if(void 0===n){var r=[];r.push(this);for(var s=(new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),a=(new THREE.Vector3).subVectors(t,e).length(),l=(new THREE.Vector3).subVectors(t,e).normalize(),c=new THREE.Vector3(0,1,0),d=(new THREE.Vector3).crossVectors(l,c).normalize(),h=d,u=(new THREE.Plane).setFromNormalAndCoplanarPoint(h,e),p=(new THREE.Plane).setFromNormalAndCoplanarPoint(l,s),m=null;r.length>0;){var v=r.shift(),E=0;if(v instanceof THREE.PointCloud){var f=v.geometry,g=f.attributes.position,y=g.array,b=v.numPoints;if(!m){m={};for(var T in f.attributes)f.attributes.hasOwnProperty(T)&&("indices"===T||(m[T]=[]))}for(var R=0;b>R;R++){var P=new THREE.Vector3(y[3*R],y[3*R+1],y[3*R+2]);P.applyMatrix4(this.matrixWorld);var w=Math.abs(u.distanceToPoint(P)),C=Math.abs(p.distanceToPoint(P));if(o/2>w&&a/2>C){for(var T in f.attributes)if(f.attributes.hasOwnProperty(T))if("position"===T)m[T].push(P);else if("indices"===T);else{var x=f.attributes[T];if(1===x.itemSize)m[T].push(x.array[R+V]);else{for(var H=[],V=0;V0&&(s=-s),function(e){var t=(new THREE.Matrix4).makeTranslation(-o.x,-o.y,-o.z),i=(new THREE.Matrix4).makeRotationY(-s),n=e.clone();return n.applyMatrix4(t),n.applyMatrix4(i),n}}(e,t);return m.project=A,m}this.profileRequests.push(new Potree.ProfileRequest(e,t,o,i,n))},Potree.PointCloudOctree.prototype.getVisibleExtent=function(){return this.visibleBounds.applyMatrix4(this.matrixWorld)},Potree.PointCloudOctree.prototype.pick=function(e,t,o,i){var i=i||{},n=i.pickWindowSize||17,r=this.nodesOnRay(this.visibleNodes,o);if(0===r.length)return null;var s=Math.ceil(e.domElement.clientWidth),a=Math.ceil(e.domElement.clientHeight),l=(new THREE.Vector3).addVectors(t.position,o.direction).project(t);l.addScalar(1).multiplyScalar(.5),l.x*=s,l.y*=a,this.pickTarget?(this.pickTarget.width!=s||this.pickTarget.height!=a)&&(this.pickTarget.dispose(),this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat})):this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat}),this.pickTarget.setSize(s,a),this.pickMaterial||(this.pickMaterial=new Potree.PointCloudMaterial,this.pickMaterial.pointColorType=Potree.PointColorType.POINT_INDEX,this.pickMaterial.pointSizeType=Potree.PointSizeType.FIXED),this.pickMaterial.pointSizeType=this.material.pointSizeType,this.pickMaterial.size=this.material.size,this.pickMaterial.pointSizeType===Potree.PointSizeType.ADAPTIVE&&this.updateVisibilityTexture(this.pickMaterial,r),this.pickMaterial.fov=this.material.fov,this.pickMaterial.screenWidth=this.material.screenWidth,this.pickMaterial.screenHeight=this.material.screenHeight,this.pickMaterial.spacing=this.material.spacing,this.pickMaterial.near=this.material.near,this.pickMaterial.far=this.material.far,this.pickMaterial.octreeLevels=this.material.octreeLevels,this.pickMaterial.pointShape=this.material.pointShape; +var c=e.context;c.enable(c.SCISSOR_TEST),c.scissor(l.x-(n-1)/2,l.y-(n-1)/2,n,n),c.disable(c.SCISSOR_TEST);var d=this.pickMaterial;e.setRenderTarget(this.pickTarget),e.setDepthTest(d.depthTest),e.setDepthWrite(d.depthWrite),e.setBlending(THREE.NoBlending),e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),r.length>0&&r.push(r[0]);for(var h=0;hP;P++)for(var w=0;n>w;w++){var C=P+w*n,x=Math.pow(P-(n-1)/2,2)+Math.pow(w-(n-1)/2,2),H=y[4*C+3];y[4*C+3]=0;var V=b[C];(0!==V||0!==H)&&T>x&&(R={pIndex:V,pcIndex:H},T=x)}if(R){var M={},S=r[R.pcIndex],A=S.geometry.attributes;for(var B in A)if(A.hasOwnProperty(B)){var I=p.attributes[B];if("position"===B){var L=S.geometry.attributes.position.array,W=L[3*R.pIndex+0],G=L[3*R.pIndex+1],O=L[3*R.pIndex+2],N=new THREE.Vector3(W,G,O);N.applyMatrix4(this.matrixWorld),M[B]=N}else if("indices"===B);else if(1===I.itemSize)M[B]=I.array[h+Z];else{for(var X=[],Z=0;Zd;d++){var h=r[3*d+0],u=r[3*d+1],p=r[3*d+2],m=new THREE.Vector3(h,u,p).applyMatrix4(o),v=parseInt(s*(m.x-i.min.x)/n.x),E=parseInt(s*(m.z-i.min.z)/n.z);v=Math.min(v,s-1),E=Math.min(E,s-1);var f=v+E*s;a[f]||(a[f]=[]),a[f].push(m.y)}for(var d=0;d.5&&r.x.5&&r.y0;){{var r=n.shift(),s=r.dem,a=(s.demSize,s.boundingBox2D);a.containsPoint(t)}if(a.containsPoint(t)){var l=o(s);if(i?null!=l&&l>0&&(i=l):i=l,r.level<=2)for(var c=0;cs;s++)for(var a=0;o>a;a++){var l=s/t,c=a/o,d=l*e.size().x+e.min.x,h=c*e.size().z+e.min.z,u=this.getDEMHeight(new THREE.Vector3(d,0,h));u||(u=0),n[r+0]=d,n[r+1]=u,n[r+2]=h,r+=3}i.addAttribute("position",new THREE.BufferAttribute(n,3));var p=new THREE.PointCloudMaterial({size:20,color:65280}),m=new THREE.PointCloud(i,p);scene.add(m)};var nodesLoadTimes={};Potree.PointCloudOctreeGeometry=function(){Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.url=null,this.octreeDir=null,this.spacing=0,this.boundingBox=null,this.root=null,this.numNodesLoading=0,this.nodes=null,this.pointAttributes=null,this.hierarchyStepSize=-1,this.loader=null},Potree.PointCloudOctreeGeometryNode=function(e,t,o){this.id=Potree.PointCloudOctreeGeometryNode.IDCount++,this.name=e,this.index=parseInt(e.charAt(e.length-1)),this.pcoGeometry=t,this.geometry=null,this.boundingBox=o,this.boundingSphere=o.getBoundingSphere(),this.children={},this.numPoints=0,this.level=null},Potree.PointCloudOctreeGeometryNode.IDCount=0,Potree.PointCloudOctreeGeometryNode.prototype.getURL=function(){var e="",t=this.pcoGeometry.loader.version;return t.equalOrHigher("1.5")?e=this.pcoGeometry.octreeDir+"/"+this.getHierarchyPath()+"/"+this.name:t.equalOrHigher("1.4")?e=this.pcoGeometry.octreeDir+"/"+this.name:t.upTo("1.3")&&(e=this.pcoGeometry.octreeDir+"/"+this.name),e},Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath=function(){for(var e="r/",t=this.pcoGeometry.hierarchyStepSize,o=this.name.substr(1),i=Math.floor(o.length/t),n=0;i>n;n++)e+=o.substr(n*t,t)+"/";return e=e.slice(0,-1)},Potree.PointCloudOctreeGeometryNode.prototype.addChild=function(e){this.children[e.index]=e,e.parent=this},Potree.PointCloudOctreeGeometryNode.prototype.load=function(){this.loading===!0||this.pcoGeometry.numNodesLoading>3||(this.loading=!0,this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.version.equalOrHigher("1.5")&&this.level%this.pcoGeometry.hierarchyStepSize===0&&this.hasChildren?this.loadHierachyThenPoints():this.loadPoints())},Potree.PointCloudOctreeGeometryNode.prototype.loadPoints=function(){this.pcoGeometry.loader.load(this)},Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints=function(){var e=this,t=function(e,t){var o=(t.byteLength/5,new DataView(t)),i=[],n=o.getUint8(0),r=o.getUint32(1,!0);e.numPoints=r,i.push({children:n,numPoints:r,name:e.name});for(var s=[],a=5;i.length>0;){for(var l=i.shift(),c=1,d=0;8>d;d++){if(0!==(l.children&c)){var h=l.name+d,u=o.getUint8(a),p=o.getUint32(a+1,!0);i.push({children:u,numPoints:p,name:h}),s.push({children:u,numPoints:p,name:h}),a+=5}c=2*c}if(a===t.byteLength)break}var m={};m[e.name]=e;for(var v=e.pcoGeometry,d=0;d0,y.addChild(R),m[E]=R}e.loadPoints()};if(e.level%e.pcoGeometry.hierarchyStepSize===0){var o=e.pcoGeometry.octreeDir+"/"+e.getHierarchyPath()+"/"+e.name+".hrc",i=new XMLHttpRequest;i.open("GET",o,!0),i.responseType="arraybuffer",i.overrideMimeType("text/plain; charset=x-user-defined"),i.onreadystatechange=function(){if(4===i.readyState)if(200===i.status||0===i.status){var o=i.response;t(e,o)}else console.log("Failed to load file! HTTP status: "+i.status+", file: "+url)};try{i.send(null)}catch(n){console.log("fehler beim laden der punktwolke: "+n)}}},Potree.PointCloudOctreeGeometryNode.prototype.dispose=function(){this.geometry&&(this.geometry.dispose(),this.geometry=null,this.loaded=!1)},Potree.utils=function(){},Potree.utils.pathExists=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),200!==t.status?!1:!0},Potree.utils.computeTransformedBoundingBox=function(e,t){var o=[new THREE.Vector3(e.min.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.max.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.min.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.max.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.max.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.min.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.max.y,e.max.z).applyMatrix4(t)],i=new THREE.Box3;return i.setFromPoints(o),i},Potree.utils.addCommas=function(e){e+="",x=e.split("."),x1=x[0],x2=x.length>1?"."+x[1]:"";for(var t=/(\d+)(\d{3})/;t.test(x1);)x1=x1.replace(t,"$1,$2");return x1+x2},Potree.utils.createWorker=function(e){var t=new Blob([e],{type:"application/javascript"}),o=new Worker(URL.createObjectURL(t));return o},Potree.utils.loadSkybox=function(e){var t=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,1,1e5),o=new THREE.Scene,i=".jpg",n=[e+"px"+i,e+"nx"+i,e+"py"+i,e+"ny"+i,e+"pz"+i,e+"nz"+i],r=THREE.ImageUtils.loadTextureCube(n,THREE.CubeRefractionMapping),s={uniforms:{tCube:{type:"t",value:r},tFlip:{type:"f",value:-1}},vertexShader:THREE.ShaderLib.cube.vertexShader,fragmentShader:THREE.ShaderLib.cube.fragmentShader},a=new THREE.ShaderMaterial({fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,uniforms:s.uniforms,depthWrite:!1,side:THREE.BackSide}),l=new THREE.Mesh(new THREE.BoxGeometry(100,100,100),a);return o.add(l),{camera:t,scene:o}},Potree.utils.createGrid=function(e,t,o,i){for(var n=new THREE.LineBasicMaterial({color:i||8947848}),r=new THREE.Geometry,s=0;t>=s;s++)r.vertices.push(new THREE.Vector3(-(o*e)/2,0,s*o-o*t/2)),r.vertices.push(new THREE.Vector3(+(o*e)/2,0,s*o-o*t/2));for(var s=0;e>=s;s++)r.vertices.push(new THREE.Vector3(s*o-o*e/2,0,-(o*t)/2)),r.vertices.push(new THREE.Vector3(s*o-o*e/2,0,+(o*t)/2));var a=new THREE.Line(r,n,THREE.LinePieces);return a.receiveShadow=!0,a},Potree.utils.createBackgroundTexture=function(e,t){function o(e,t){return 1/(2*Math.PI)*Math.exp(-(e*e+t*t)/2)}var i=THREE.ImageUtils.generateDataTexture(e,t,new THREE.Color);i.magFilter=THREE.NearestFilter;for(var n=i.image.data,r=[1,1.5,1.7],s=o(0,0),a=0;e>a;a++)for(var l=0;t>l;l++){var c=2*(a/e)-1,d=2*(l/t)-1,h=a+e*l,u=o(2*c,2*d)/s,p=(Math.random()+Math.random()+Math.random())/3;p=(.5*u+.5)*p*.03,p=.4*p,n[3*h+0]=255*(u/15+.05+p)*r[0],n[3*h+1]=255*(u/15+.05+p)*r[1],n[3*h+2]=255*(u/15+.05+p)*r[2]}return i},Potree.utils.topView=function(e,t,o){if(e.position.set(0,1,0),e.rotation.set(-Math.PI/2,0,0),e.zoomTo(o,1),t.target){var i=o.boundingSphere.clone().applyMatrix4(o.matrixWorld),n=new THREE.Vector3(e.position.x,i.center.y,e.position.z);t.target.copy(n)}},Potree.utils.frontView=function(e,t,o){if(e.position.set(0,0,1),e.rotation.set(0,0,0),e.zoomTo(o,1),t.target){var i=o.boundingSphere.clone().applyMatrix4(o.matrixWorld),n=new THREE.Vector3(e.position.x,e.position.y,i.center.z);t.target.copy(n)}},Potree.utils.leftView=function(e,t,o){if(e.position.set(-1,0,0),e.rotation.set(0,-Math.PI/2,0),e.zoomTo(o,1),t.target){var i=o.boundingSphere.clone().applyMatrix4(o.matrixWorld),n=new THREE.Vector3(i.center.x,e.position.y,e.position.z);t.target.copy(n)}},Potree.utils.rightView=function(e,t,o){if(e.position.set(1,0,0),e.rotation.set(0,Math.PI/2,0),e.zoomTo(o,1),t.target){var i=o.boundingSphere.clone().applyMatrix4(o.matrixWorld),n=new THREE.Vector3(i.center.x,e.position.y,e.position.z);t.target.copy(n)}},Potree.Features=function(){var e=document.createElement("canvas").getContext("webgl");return{SHADER_INTERPOLATION:{isSupported:function(){var t=!0;return t=t&&e.getExtension("EXT_frag_depth"),t=t&&e.getParameter(e.MAX_VARYING_VECTORS)>=8}},SHADER_SPLATS:{isSupported:function(){var t=!0;return t=t&&e.getExtension("EXT_frag_depth"),t=t&&e.getExtension("OES_texture_float"),t=t&&e.getParameter(e.MAX_VARYING_VECTORS)>=8}}}}(),Potree.TextSprite=function(e){THREE.Object3D.call(this);var t=new THREE.Texture;t.minFilter=THREE.LinearFilter,t.magFilter=THREE.LinearFilter;var o=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});this.material=o,this.sprite=new THREE.Sprite(o),this.add(this.sprite),this.borderThickness=4,this.fontface="Arial",this.fontsize=28,this.borderColor={r:0,g:0,b:0,a:1},this.backgroundColor={r:255,g:255,b:255,a:1},this.textColor={r:255,g:255,b:255,a:1},this.text="",this.setText(e)},Potree.TextSprite.prototype=new THREE.Object3D,Potree.TextSprite.prototype.setText=function(e){this.text=e,this.update()},Potree.TextSprite.prototype.setTextColor=function(e){this.textColor=e,this.update()},Potree.TextSprite.prototype.setBorderColor=function(e){this.borderColor=e,this.update()},Potree.TextSprite.prototype.setBackgroundColor=function(e){this.backgroundColor=e,this.update()},Potree.TextSprite.prototype.update=function(){var e=document.createElement("canvas"),t=e.getContext("2d");t.font="Bold "+this.fontsize+"px "+this.fontface;var o=t.measureText(this.text),i=o.width,n=i+2*this.borderThickness,r=1.4*this.fontsize+2*this.borderThickness,e=document.createElement("canvas"),t=e.getContext("2d");t.canvas.width=n,t.canvas.height=r,t.font="Bold "+this.fontsize+"px "+this.fontface,t.fillStyle="rgba("+this.backgroundColor.r+","+this.backgroundColor.g+","+this.backgroundColor.b+","+this.backgroundColor.a+")",t.strokeStyle="rgba("+this.borderColor.r+","+this.borderColor.g+","+this.borderColor.b+","+this.borderColor.a+")",t.lineWidth=this.borderThickness,this.roundRect(t,this.borderThickness/2,this.borderThickness/2,i+this.borderThickness,1.4*this.fontsize+this.borderThickness,6),t.strokeStyle="rgba(0, 0, 0, 1.0)",t.strokeText(this.text,this.borderThickness,this.fontsize+this.borderThickness),t.fillStyle="rgba("+this.textColor.r+","+this.textColor.g+","+this.textColor.b+","+this.textColor.a+")",t.fillText(this.text,this.borderThickness,this.fontsize+this.borderThickness);var s=new THREE.Texture(e);s.minFilter=THREE.LinearFilter,s.magFilter=THREE.LinearFilter,s.needsUpdate=!0,this.sprite.material.map=s,this.sprite.scale.set(.01*n,.01*r,1)},Potree.TextSprite.prototype.roundRect=function(e,t,o,i,n,r){e.beginPath(),e.moveTo(t+r,o),e.lineTo(t+i-r,o),e.quadraticCurveTo(t+i,o,t+i,o+r),e.lineTo(t+i,o+n-r),e.quadraticCurveTo(t+i,o+n,t+i-r,o+n),e.lineTo(t+r,o+n),e.quadraticCurveTo(t,o+n,t,o+n-r),e.lineTo(t,o+r),e.quadraticCurveTo(t,o,t+r,o),e.closePath(),e.fill(),e.stroke()},Potree.Version=function(e){this.version=e;var t=-1===e.indexOf(".")?e.length:e.indexOf(".");this.versionMajor=parseInt(e.substr(0,t)),this.versionMinor=parseInt(e.substr(t+1)),0===this.versionMinor.length&&(this.versionMinor=0)},Potree.Version.prototype.newerThan=function(e){var t=new Potree.Version(e);return this.versionMajor>t.versionMajor?!0:this.versionMajor===t.versionMajor&&this.versionMinor>t.versionMinor?!0:!1},Potree.Version.prototype.equalOrHigher=function(e){var t=new Potree.Version(e);return this.versionMajor>t.versionMajor?!0:this.versionMajor===t.versionMajor&&this.versionMinor>=t.versionMinor?!0:!1},Potree.Version.prototype.upTo=function(e){return!this.newerThan(e)},Potree.AngleTool=function(e,t,o){"use strict";function i(e){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.angleLabels=[],this.root=e,this.closed=!0;var t=new THREE.SphereGeometry(.4,10,10),o=new THREE.Color(16711680),i=function(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e};this.add=function(e){this.points.push(e);var n=new THREE.Mesh(t,i());n.addEventListener("mousemove",m),n.addEventListener("mouseleave",v),n.addEventListener("mousedrag",E),n.addEventListener("drop",f);var r=new THREE.Geometry;r.vertices.push(new THREE.Vector3,new THREE.Vector3),r.colors.push(o,o,o);var s=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2});s.depthTest=!1;var a=new THREE.Line(r,s),l=new Potree.TextSprite;l.setBorderColor({r:0,g:255,b:0,a:0}),l.setBackgroundColor({r:0,g:255,b:0,a:0}),l.material.depthTest=!1,l.material.opacity=1,this.root.add(n),this.root.add(a),this.root.add(l),this.spheres.push(n),this.edges.push(a),this.angleLabels.push(l),this.setPosition(this.points.length-1,e)},this.remove=function(e){this.points.splice(e,1),this.root.remove(this.spheres[e]),this.root.remove(this.edges[e]),this.root.remove(this.angleLabels[e]),this.spheres.splice(e,1),this.edges.splice(e,1),this.angleLabels.splice(e,1),this.update()},this.removeAll=function(){for(;this.points.length>1;)this.remove(0);this.sceneRoot.visible=!1,this.update()},this.getAngleBetweenLines=function(e,t,o){var i=(new THREE.Vector3).subVectors(t,e),n=(new THREE.Vector3).subVectors(o,e);return i.angleTo(n)},this.getAngle=function(e){var t=0,o=this.points[0],i=this.points[1],n=this.points[2];return 0===e?t=this.getAngleBetweenLines(o,i,n):1===e?t=this.getAngleBetweenLines(i,o,n):2===e&&(t=this.getAngleBetweenLines(n,o,i)),t},this.setPosition=function(e,t){var o=this.points[e];o.copy(t),this.update()},this.setClosed=function(e){this.closed=e,this.update()},this.update=function(){var e,t;if(1===this.points.length)return e=this.points[0],this.spheres[0].position.copy(e),this.edges[0].visible=!1,void(this.angleLabels[0].visible=!1);var o=this.points.length-1,i=new THREE.Vector3;for(t=0;o>=t;t++){e=this.points[t];var n=this.spheres[t],r=0===t?o:t-1,s=this.edges[r],a=this.edges[t];n.position.copy(e),s.geometry.vertices[1].copy(e),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere(),a.geometry.vertices[0].copy(e),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere(),a.visible=t!==o||this.closed?!0:!1,i.add(e)}if(i.multiplyScalar(1/this.points.length),this.points.length>=3)for(t=0;o>=t;t++){this.angleLabels[t].visible=!0,this.angleLabels[t].setText(Potree.utils.addCommas((this.getAngle(t)*(180/Math.PI)).toFixed(1))+"°");var l=(new THREE.Vector3).addVectors(this.points[t],i).multiplyScalar(.5);this.angleLabels[t].position.copy(l)}else for(t=0;o>=t;t++)this.angleLabels[t].visible=!1}}function n(e){if(h.enabled&&void 0!==e){var t=d();if(t){var o=t.clone();if(p===u.DEFAULT&&(p=u.PICKING,h.activeMeasurement=new i),p===u.PICKING&&h.activeMeasurement&&h.activeMeasurement.points.length>2)h.measurements.push(h.activeMeasurement),h.activeMeasurement=void 0,p=u.DEFAULT,h.setEnabled(!1);else{h.activeMeasurement.add(o);var n={type:"newpoint",position:o.clone()};h.dispatchEvent(n)}}}}function r(e){if(void 0!==e){var t=h.domElement.getBoundingClientRect();h.mouse.x=(e.clientX-t.left)/h.domElement.clientWidth*2-1,h.mouse.y=2*-((e.clientY-t.top)/h.domElement.clientHeight)+1;var o;if(h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(p===u.PICKING&&h.activeMeasurement){if(o=d()){var i=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(i,o)}}else o=c(),o?(o.object.dispatchEvent({type:"mousemove",target:o.object,event:e}),h.hoveredElement&&h.hoveredElement!==o.object&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=o.object):(h.hoveredElement&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=null)}}function s(e){void 0!==e&&p===u.PICKING&&(h.activeMeasurement.removeAll(),h.activeMeasurement=void 0,p=u.DEFAULT,h.setEnabled(!1))}function a(e){if(1===e.which){p!==u.DEFAULT&&e.stopImmediatePropagation();var t=c();t&&(h.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:h.sceneRoot.position.clone(),mousePos:{x:h.mouse.x,y:h.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&s(e)}function l(e){h.dragstart&&(h.dragstart.object.dispatchEvent({type:"drop",event:e}),h.dragstart=null)}function c(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=new THREE.Raycaster;t.ray.set(h.camera.position,e.sub(h.camera.position).normalize());for(var o=[],i=0;i0?s[0]:!1}function d(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sc)&&(n=l,r=c)}}return n?n.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.accuracy=.5;var u={DEFAULT:0,PICKING:1},p=u.DEFAULT;this.activeMeasurement=null,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){var t=d();if(t)for(var o=0;o=0){h.measurements[o].setPosition(n,t);break}}e.event.stopImmediatePropagation()},f=function(e){};this.setEnabled=function(e){this.enabled!==e&&(this.enabled=e,e&&(p=u.PICKING,h.activeMeasurement=new i(h.sceneRoot),h.activeMeasurement.add(new THREE.Vector3(0,0,0))))},this.update=function(){var e,t,i=[];for(e=0;e=n;n++){var t=this.points[n];i.add(t)}i.divideScalar(this.points.length);for(var n=0;o>=n;n++){var r=n,s=n+1>o?0:n+1,t=this.points[r],a=this.points[s],l=this.spheres[r];l.position.copy(t),l.material.color=e.color;var c=this.edges[r];c.material.color=this.color,c.geometry.vertices[0].copy(t),c.geometry.vertices[1].copy(a),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),c.visible=o>r||this.closed;var d=this.edgeLabels[n],h=(new THREE.Vector3).add(t);h.add(a),h=h.multiplyScalar(.5);var u=t.distanceTo(a);d.position.copy(h),d.setText(u.toFixed(2)),d.visible=this.showDistances&&(o>r||this.closed)&&this.points.length>=2&&u>0}this.areaLabel.position.copy(i),this.areaLabel.visible=this.showArea&&this.points.length>=3;var p=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(p)}},this.raycast=function(e,t){for(var o=0;o0?s[0]:!1}var d=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};var h={DEFAULT:0,INSERT:1},u=h.DEFAULT;this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null,this.getState=function(){return u},this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=e.sub(d.camera.position).normalize(),o=new THREE.Ray(d.camera.position,t),i=[];d.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sc)&&(n=l,r=c)}}return n?n.position:null},this.startInsertion=function(e){u=h.INSERT;var e=e||{},t=e.showDistances||!0,o=e.showArea||!1,i=e.closed||!1;this.activeMeasurement=new Potree.Measure,this.activeMeasurement.showDistances=t,this.activeMeasurement.showArea=o,this.activeMeasurement.closed=i,this.sceneMeasurement.add(this.activeMeasurement),this.measurements.push(this.activeMeasurement),this.activeMeasurement.addMarker(new THREE.Vector3(0,0,0))},this.finishInsertion=function(){this.activeMeasurement.removeMarker(this.activeMeasurement.points.length-1),this.activeMeasurement=null,u=h.DEFAULT},this.addMeasurement=function(e){this.sceneMeasurement.add(e),this.measurements.push(e)},this.removeMeasurement=function(e){this.sceneMeasurement.remove(e);var t=this.measurements.indexOf(e);t>=0&&this.measurements.splice(t,1)},this.update=function(){for(var e=[],t=0;t1){var c=new THREE.Geometry;c.vertices.push(new THREE.Vector3,new THREE.Vector3),c.colors.push(o,o,o);var d=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2,transparent:!0,opacity:.4});d.depthTest=!1;var h=new THREE.Line(c,d);h.visible=!1,this.add(h),this.edges.push(h);var u=new THREE.BoxGeometry(1,1,1),p=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),m=new THREE.Mesh(u,p);m.visible=!1,this.add(m),this.boxes.push(m)}this.setPosition(this.points.length-1,e);var v={type:"marker_added",profile:this};this.dispatchEvent(v)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]);var t=0==e?0:e-1;this.remove(this.edges[t]),this.edges.splice(t,1),this.remove(this.boxes[t]),this.boxes.splice(t,1),this.spheres.splice(e,1),this.update();var o={type:"marker_removed",profile:this};this.dispatchEvent(o)},this.getArea=function(){for(var e=0,t=this.points.length-1,o=0;o=r;r++){{var e=this.points[r],s=this.spheres[r],a=0===r?n:r-1,l=r===n?0:r+1,c=this.points[a],d=this.points[l],h=this.edges[a],u=this.edges[r],p=this.boxes[a];this.boxes[r],e.distanceTo(c),e.distanceTo(d),(new THREE.Vector3).addVectors(c,e).multiplyScalar(.5),(new THREE.Vector3).addVectors(e,d).multiplyScalar(.5)}if(s.position.copy(e),s.visible=this._modifiable?!0:!1,h&&(h.geometry.vertices[1].copy(e),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere()),u&&(u.geometry.vertices[0].copy(e),u.geometry.verticesNeedUpdate=!0,u.geometry.computeBoundingSphere()),p){var m=c,v=e,E=m.clone().setY(0).distanceTo(v.clone().setY(0));p.scale.set(E,this.height,this.width);var f=(new THREE.Vector3).addVectors(m,v).multiplyScalar(.5),g=(new THREE.Vector3).subVectors(v,m),y=new THREE.Vector3(g.z,0,-g.x);p.position.set(0,0,0),p.lookAt(y),p.position.copy(f)}i.add(e),t.min(e),o.max(e)}i.multiplyScalar(1/this.points.length);for(var r=0;r0?o[0]:!1}var d=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};{var h={DEFAULT:0,INSERT:1},u=h.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeProfile,this.profiles=[],this.sceneProfile=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneProfile.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneProfile.add(this.light),this.hoveredElement=null,this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=e.sub(d.camera.position).normalize(),o=new THREE.Ray(d.camera.position,t),i=[];d.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sc)&&(n=l,r=c)}}return n?n.position:null},this.startInsertion=function(e){u=h.INSERT;var e=e||{},t=e.clip||!1,o=e.width||1;return this.activeProfile=new Potree.HeightProfile,this.activeProfile.clip=t,this.activeProfile.setWidth(o),this.addProfile(this.activeProfile),this.activeProfile.addMarker(new THREE.Vector3(0,0,0)),this.activeProfile},this.finishInsertion=function(){this.activeProfile.removeMarker(this.activeProfile.points.length-1),this.activeProfile=null,u=h.DEFAULT},this.addProfile=function(e){this.profiles.push(e),this.sceneProfile.add(e),e.update(),this.dispatchEvent({type:"profile_added",profile:e}),e.addEventListener("marker_added",function(e){d.dispatchEvent(e)}),e.addEventListener("marker_removed",function(e){d.dispatchEvent(e)})},this.removeProfile=function(e){this.sceneProfile.remove(e);var t=this.profiles.indexOf(e);t>=0&&this.profiles.splice(t,1),this.dispatchEvent({type:"profile_removed",profile:e})},this.update=function(){for(var e=0;e0?i[0]:!1}}var a=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.dragstart=null,this.sceneTransformation=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneTransformation.add(this.sceneRoot),this.sceneRotation=new THREE.Scene,this.translationNode=new THREE.Object3D,this.rotationNode=new THREE.Object3D,this.scaleNode=new THREE.Object3D,this.sceneRoot.add(this.translationNode),this.sceneRoot.add(this.rotationNode),this.sceneRoot.add(this.scaleNode),this.sceneRoot.visible=!1,this.hoveredElement=null,this.STATE={DEFAULT:0,TRANSLATE_X:1,TRANSLATE_Y:2,TRANSLATE_Z:3,SCALE_X:1,SCALE_Y:2,SCALE_Z:3},this.parts={ARROW_X:{name:"arrow_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.TRANSLATE_X},ARROW_Z:{name:"arrow_z",object:void 0,color:new THREE.Color(255),state:this.STATE.TRANSLATE_Z},ARROW_Y:{name:"arrow_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.TRANSLATE_Y},SCALE_X:{name:"scale_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.SCALE_X},SCALE_Z:{name:"scale_z",object:void 0,color:new THREE.Color(255),state:this.STATE.SCALE_Z},SCALE_Y:{name:"scale_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.SCALE_Y},ROTATE_X:{name:"rotate_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.ROTATE_X},ROTATE_Z:{name:"rotate_z",object:void 0,color:new THREE.Color(255),state:this.STATE.ROTATE_Z},ROTATE_Y:{name:"rotate_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.ROTATE_Y}},this.buildTranslationNode=function(){var e=a.createArrow(a.parts.ARROW_X,a.parts.ARROW_X.color);e.rotation.z=-Math.PI/2;var t=a.createArrow(a.parts.ARROW_Y,a.parts.ARROW_Y.color),o=a.createArrow(a.parts.ARROW_Z,a.parts.ARROW_Z.color);o.rotation.x=-Math.PI/2,this.translationNode.add(e),this.translationNode.add(t),this.translationNode.add(o)},this.buildScaleNode=function(){var e=this.createScaleHandle(a.parts.SCALE_X,16711680);e.rotation.z=-Math.PI/2;var t=this.createScaleHandle(a.parts.SCALE_Y,65280),o=this.createScaleHandle(a.parts.SCALE_Z,255);o.rotation.x=-Math.PI/2,this.scaleNode.add(e),this.scaleNode.add(t),this.scaleNode.add(o)},this.buildRotationNode=function(){var e=this.createRotationCircle(a.parts.ROTATE_X,16711680);e.rotation.y=-Math.PI/2;var t=this.createRotationCircle(a.parts.ROTATE_Y,65280),o=this.createRotationCircle(a.parts.ROTATE_Z,255);t.rotation.x=-Math.PI/2,this.rotationNode.add(e),this.rotationNode.add(t),this.rotationNode.add(o);var i=new THREE.SphereGeometry(2.9,24,24),n=new THREE.Mesh(i,new THREE.MeshBasicMaterial({color:11184810,transparent:!0,opacity:.4}));this.sceneRotation.add(n);var r=function(){n.material.color.setHex(5592405)},s=function(){n.material.color.setHex(11184810)},l=function(e){e.event.stopImmediatePropagation();for(var t=new THREE.Vector3(a.dragstart.mousePos.x,a.dragstart.mousePos.y,.1),o=new THREE.Vector3(a.mouse.x,a.mouse.y,.1),i=(new THREE.Vector3).subVectors(o,t),n=t.clone().unproject(a.camera),r=o.clone().unproject(a.camera),s=(new THREE.Vector3).subVectors(r,n),l=s.clone().normalize(),c=(new THREE.Vector3).subVectors(a.camera.position,n).normalize(),d=c.clone().cross(l),h=6*i.length(),u=0;u=n;n++){var r=2*Math.PI*n/i,s=3*Math.cos(r),l=3*Math.sin(r);o.push(new THREE.Vector3(s,l,0))}for(var c=new THREE.Geometry,n=0;nt;t++)n.label.children[t].updateMatrixWorld(!0)},this.setDimension=function(e,t,o){this.dimension.set(e,t,o),this.box.scale.set(e,t,o),this.frame.scale.set(e,t,o)},this.volume=function(){return Math.abs(this.scale.x*this.scale.y*this.scale.z)},this.update=function(){this.boundingBox=this.box.geometry.boundingBox,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)},this.raycast=function(e,t){var o=[];if(this.box.raycast(e,o),o.length>0){var i=o[0];t.push({distance:i.distance,object:this,point:i.point.clone()})}},this.update()},Potree.Volume.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(Potree.Volume.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this.update()}}),Object.defineProperty(Potree.Volume.prototype,"modifiable",{get:function(){return this._modifiable},set:function(e){this._modifiable=e,this.update()}}),Potree.VolumeTool=function(e,t,o){function i(e){var t=c.domElement.getBoundingClientRect();c.mouse.x=(e.clientX-t.left)/c.domElement.clientWidth*2-1,c.mouse.y=2*-((e.clientY-t.top)/c.domElement.clientHeight)+1}function n(){}function r(e){if(h!==d.DEFAULT&&e.stopImmediatePropagation(),h===d.INSERT_VOLUME)c.finishInsertion();else if(1===e.which){var t=a();t&&t.object.modifiable&&transformationTool.setTargets([t.object])}3===e.which}function s(e){return e.preventDefault(),!1}function a(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=new THREE.Raycaster;t.ray.set(c.camera.position,e.sub(c.camera.position).normalize());for(var o=[],i=0;i0?r[0]:!1}function l(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),o=new THREE.Ray(c.camera.position,t),i=[];c.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var c=this;this.enabled=!1,this.scene=e,this.sceneVolume=new THREE.Scene,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.volumes=[];var d={DEFAULT:0,INSERT_VOLUME:1},h=d.DEFAULT;this.update=function(){if(h===d.INSERT_VOLUME){var e=l();if(e){this.activeVolume.position.copy(e);var t=this.activeVolume.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),i=(new THREE.Vector4(t.x,t.y,t.z).applyMatrix4(this.camera.projectionMatrix),Math.abs(t.z/10));this.activeVolume.scale.set(i,i,i)}}for(var n=[],r=0;r=0&&this.volumes.splice(t,1)},this.render=function(){o.render(this.sceneVolume,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousedown",r,!1),this.domElement.addEventListener("mousemove",i,!1),this.domElement.addEventListener("contextmenu",s,!1)}; \ No newline at end of file diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index d8a57ab8..c6450165 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -1315,7 +1315,7 @@ Potree.PointCloudOctree.prototype.createDEM = function(node){ // var end = new Date().getTime(); var duration = end - start; - console.log(node.numPoints + " - " + duration); + //console.log(node.numPoints + " - " + duration); demTime += duration; @@ -1387,8 +1387,8 @@ Potree.PointCloudOctree.prototype.getDEMHeight = function(position){ var stack = []; var chosenNode = null; - if(pointcloud.children[0].dem){ - stack.push(pointcloud.children[0]); + if(this.children[0].dem){ + stack.push(this.children[0]); } while(stack.length > 0){ var node = stack.shift(); diff --git a/src/utils.js b/src/utils.js index d3f167ec..1859ea84 100644 --- a/src/utils.js +++ b/src/utils.js @@ -226,7 +226,7 @@ function projectedRadius(radius, fov, distance, screenHeight){ }; -function topView(){ +Potree.utils.topView = function(camera, controls, pointcloud){ camera.position.set(0, 1, 0); camera.rotation.set(-Math.PI / 2, 0, 0); camera.zoomTo(pointcloud, 1); @@ -238,7 +238,7 @@ function topView(){ } } -function frontView(){ +Potree.utils.frontView = function(camera, controls, pointcloud){ camera.position.set(0, 0, 1); camera.rotation.set(0, 0, 0); camera.zoomTo(pointcloud, 1); @@ -251,7 +251,7 @@ function frontView(){ } -function leftView(){ +Potree.utils.leftView = function(camera, controls, pointcloud){ camera.position.set(-1, 0, 0); camera.rotation.set(0, -Math.PI / 2, 0); camera.zoomTo(pointcloud, 1); @@ -263,7 +263,7 @@ function leftView(){ } } -function rightView(){ +Potree.utils.rightView = function(camera, controls, pointcloud){ camera.position.set(1, 0, 0); camera.rotation.set(0, Math.PI / 2, 0); camera.zoomTo(pointcloud, 1); diff --git a/src/utils/ProfileTool.js b/src/utils/ProfileTool.js index e92973fd..19e66a9b 100644 --- a/src/utils/ProfileTool.js +++ b/src/utils/ProfileTool.js @@ -13,9 +13,6 @@ Potree.HeightProfile = function(){ this.height = 20; this._modifiable = true; - this.camera = camera; - this.renderer = renderer; - var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); var lineColor = new THREE.Color( 0xff0000 );