potree/build/js/potree.min.js
2015-03-12 22:38:50 +01:00

5 lines
145 KiB
JavaScript

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;t<e.length;t++){var o=e[t],i=PointAttribute[o];this.attributes.push(i),this.byteSize+=i.byteSize,this.size++}}function LRUItem(e){this.previous=null,this.next=null,this.node=e}function LRU(){this.first=null,this.last=null,this.items={},this.elements=0,this.numPoints=0}function getMousePointCloudIntersection(e,t,o,i){var n=new THREE.Vector3(e.x,e.y,.5);n.unproject(t);for(var r=n.sub(t.position).normalize(),s=new THREE.Ray(t.position,r),a=null,l=null,d=0;d<i.length;d++){var c=i[d],h=c.pick(o,t,s);if(h){var u=t.position.distanceTo(h.position);(!a||l>u)&&(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<e.length;r++)e[4*r+3]=255;var s=n.createImageData(t,o);s.data.set(e),n.putImageData(s,0,0);var a=new Image;return a.src=i.toDataURL(),a.style.transform="scaleY(-1)",a}Potree.pointLoadLimit=5e7,Potree.workers={},Potree.WorkerManager=function(e){this.code=e,this.instances=[],this.createdInstances=0},Potree.WorkerManager.prototype.getWorker=function(){var e=this.instances.pop();return void 0===e&&(e=Potree.utils.createWorker(this.code),this.createdInstances++),e},Potree.WorkerManager.prototype.returnWorker=function(e){this.instances.push(e)},Potree.WorkerManager.fromUrls=function(e){for(var t="",o=0;o<e.length;o++){var i=e[o],n=new XMLHttpRequest;n.open("GET",i,!1),n.responseType="text",n.overrideMimeType("text/plain; charset=x-user-defined"),n.send(null),200===n.status&&(t+=n.responseText+"\n")}return new Potree.WorkerManager(t)},Potree.workers.binaryDecoder=new Potree.WorkerManager(atob("DQovLyBodHRwOi8vanNwZXJmLmNvbS91aW50OG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xPUl9QQUNLRUQpewoJCQlyZXR1cm4gdHJ1ZTsKCQl9Cgl9CgkKCXJldHVybiBmYWxzZTsKfTsKClBvaW50QXR0cmlidXRlcy5wcm90b3R5cGUuaGFzTm9ybWFscyA9IGZ1bmN0aW9uKCl7Cglmb3IodmFyIG5hbWUgaW4gdGhpcy5hdHRyaWJ1dGVzKXsKCQl2YXIgcG9pbnRBdHRyaWJ1dGUgPSB0aGlzLmF0dHJpYnV0ZXNbbmFtZV07CgkJaWYocG9pbnRBdHRyaWJ1dGUgPT09IFBvaW50QXR0cmlidXRlLk5PUk1BTF9GTE9BVFMpewoJCQlyZXR1cm4gdHJ1ZTsKCQl9Cgl9CgkKCXJldHVybiBmYWxzZTsKfTsKCgo=")),THREE.PerspectiveCamera.prototype.zoomTo=function(e,t){if(e.geometry||e.boundingSphere){e.geometry&&null===e.geometry.boundingSphere&&e.geometry.computeBoundingSphere(),e.updateMatrixWorld();var o=t||1,i=e.boundingSphere||e.geometry.boundingSphere;i=i.clone().applyMatrix4(e.matrixWorld);var n=i.radius,r=this.fov*Math.PI/180;this.aspect<1&&(r*=this.aspect);var s=Math.abs(n/Math.sin(r/2))*o,a=new THREE.Vector3(0,0,-1).applyQuaternion(this.quaternion),l=a.multiplyScalar(-s);this.position.copy(i.center.clone().add(l))}},THREE.Ray.prototype.distanceToPlaneWithNegative=function(e){var t=e.normal.dot(this.direction);if(0==t)return 0==e.distanceToPoint(this.origin)?0:null;var o=-(this.origin.dot(e.normal)+e.constant)/t;return o},POCLoader.load=function(e,t){try{var o=new Potree.PointCloudOctreeGeometry;o.url=e;var i=new XMLHttpRequest;i.open("GET",e,!0),i.onreadystatechange=function(){if(4===i.readyState&&(200===i.status||0===i.status)){var n=JSON.parse(i.responseText);o.octreeDir=0===n.octreeDir.indexOf("http")?n.octreeDir:e+"/../"+n.octreeDir,o.spacing=n.spacing,o.hierarchyStepSize=n.hierarchyStepSize,o.pointAttributes=n.pointAttributes;var r=new THREE.Vector3(n.boundingBox.lx,n.boundingBox.ly,n.boundingBox.lz),s=new THREE.Vector3(n.boundingBox.ux,n.boundingBox.uy,n.boundingBox.uz),a=new THREE.Box3(r,s),l=a.clone();n.tightBoundingBox&&(l.min.copy(new THREE.Vector3(n.tightBoundingBox.lx,n.tightBoundingBox.ly,n.tightBoundingBox.lz)),l.max.copy(new THREE.Vector3(n.tightBoundingBox.ux,n.tightBoundingBox.uy,n.tightBoundingBox.uz)));var d=new THREE.Vector3(0,0,0);d.set(-r.x,-r.y,-r.z),a.min.add(d),a.max.add(d),l.min.add(d),l.max.add(d),o.boundingBox=a,o.tightBoundingBox=l,o.boundingSphere=a.getBoundingSphere(),o.tightBoundingSphere=l.getBoundingSphere(),o.offset=d,"LAS"===n.pointAttributes?o.loader=new Potree.LasLazLoader(n.version):"LAZ"===n.pointAttributes?o.loader=new Potree.LasLazLoader(n.version):(o.loader=new Potree.BinaryLoader(n.version,a,n.scale),o.pointAttributes=new PointAttributes(o.pointAttributes));var c={},h="r",u=new Potree.PointCloudOctreeGeometryNode(h,o,a);if(u.level=0,u.hasChildren=!0,o.loader.version.upTo("1.5")&&(u.numPoints=n.hierarchy[0][1]),u.numPoints=0,o.root=u,o.root.load(),c[h]=u,o.loader.version.upTo("1.4"))for(var p=1;p<n.hierarchy.length;p++){var h=n.hierarchy[p][0],m=n.hierarchy[p][1],v=parseInt(h.charAt(h.length-1)),E=h.substring(0,h.length-1),g=c[E],f=h.length-1,a=POCLoader.createChildAABB(g.boundingBox,v),y=new Potree.PointCloudOctreeGeometryNode(h,o,a);y.level=f,y.numPoints=m,g.addChild(y),c[h]=y}o.nodes=c,t(o)}},i.send(null)}catch(n){console.log("loading failed: '"+e+"'"),console.log(n)}},POCLoader.loadPointAttributes=function(e){for(var t=e.pointAttributes,o=new PointAttributes,i=0;i<t.length;i++){var n=PointAttribute[t[i]];o.add(n)}return o},POCLoader.createChildAABB=function(e,t){var o,i,o=(THREE.Vector3,e.min),i=e.max,n=(new THREE.Vector3).copy(i).sub(o).multiplyScalar(.5),r=new THREE.Vector3(n.x,0,0),s=new THREE.Vector3(0,n.y,0),a=new THREE.Vector3(0,0,n.z),l=o,d=(new THREE.Vector3).add(o).add(n);return 1===t?(o=(new THREE.Vector3).copy(l).add(a),i=(new THREE.Vector3).copy(d).add(a)):3===t?(o=(new THREE.Vector3).copy(l).add(a).add(s),i=(new THREE.Vector3).copy(d).add(a).add(s)):0===t?(o=l,i=d):2===t?(o=(new THREE.Vector3).copy(l).add(s),i=(new THREE.Vector3).copy(d).add(s)):5===t?(o=(new THREE.Vector3).copy(l).add(a).add(r),i=(new THREE.Vector3).copy(d).add(a).add(r)):7===t?(o=(new THREE.Vector3).copy(l).add(n),i=(new THREE.Vector3).copy(d).add(n)):4===t?(o=(new THREE.Vector3).copy(l).add(r),i=(new THREE.Vector3).copy(d).add(r)):6===t&&(o=(new THREE.Vector3).copy(l).add(r).add(s),i=(new THREE.Vector3).copy(d).add(r).add(s)),new THREE.Box3(o,i)};var PointAttributeNames={};PointAttributeNames.POSITION_CARTESIAN=0,PointAttributeNames.COLOR_PACKED=1,PointAttributeNames.COLOR_FLOATS_1=2,PointAttributeNames.COLOR_FLOATS_255=3,PointAttributeNames.NORMAL_FLOATS=4,PointAttributeNames.FILLER=5,PointAttributeNames.INTENSITY=6,PointAttributeNames.CLASSIFICATION=7;var PointAttributeTypes={DATA_TYPE_DOUBLE:{ordinal:0,size:8},DATA_TYPE_FLOAT:{ordinal:1,size:4},DATA_TYPE_INT8:{ordinal:2,size:1},DATA_TYPE_UINT8:{ordinal:3,size:1},DATA_TYPE_INT16:{ordinal:4,size:2},DATA_TYPE_UINT16:{ordinal:5,size:2},DATA_TYPE_INT32:{ordinal:6,size:4},DATA_TYPE_UINT32:{ordinal:7,size:4},DATA_TYPE_INT64:{ordinal:8,size:8},DATA_TYPE_UINT64:{ordinal:9,size:8}},i=0;for(var obj in PointAttributeTypes)PointAttributeTypes[i]=PointAttributeTypes[obj],i++;PointAttribute.POSITION_CARTESIAN=new PointAttribute(PointAttributeNames.POSITION_CARTESIAN,PointAttributeTypes.DATA_TYPE_FLOAT,3),PointAttribute.RGBA_PACKED=new PointAttribute(PointAttributeNames.COLOR_PACKED,PointAttributeTypes.DATA_TYPE_INT8,4),PointAttribute.COLOR_PACKED=PointAttribute.RGBA_PACKED,PointAttribute.RGB_PACKED=new PointAttribute(PointAttributeNames.COLOR_PACKED,PointAttributeTypes.DATA_TYPE_INT8,3),PointAttribute.NORMAL_FLOATS=new PointAttribute(PointAttributeNames.NORMAL_FLOATS,PointAttributeTypes.DATA_TYPE_FLOAT,3),PointAttribute.FILLER_1B=new PointAttribute(PointAttributeNames.FILLER,PointAttributeTypes.DATA_TYPE_UINT8,1),PointAttribute.INTENSITY=new PointAttribute(PointAttributeNames.INTENSITY,PointAttributeTypes.DATA_TYPE_UINT16,1),PointAttribute.CLASSIFICATION=new PointAttribute(PointAttributeNames.CLASSIFICATION,PointAttributeTypes.DATA_TYPE_UINT8,1),PointAttributes.prototype.add=function(e){this.attributes.push(e),this.byteSize+=e.byteSize,this.size++},PointAttributes.prototype.hasColors=function(){for(var e in this.attributes){var t=this.attributes[e];if(t.name===PointAttributeNames.COLOR_PACKED)return!0}return!1},PointAttributes.prototype.hasNormals=function(){for(var e in this.attributes){var t=this.attributes[e];if(t===PointAttribute.NORMAL_FLOATS)return!0}return!1},Potree.BinaryLoader=function(e,t,o){this.version="string"==typeof e?new Potree.Version(e):e,this.boundingBox=t,this.scale=o},Potree.BinaryLoader.prototype.load=function(e){if(!e.loaded){var t=this,o=e.getURL();this.version.equalOrHigher("1.4")&&(o+=".bin");var 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 n=i.response;t.parse(e,n)}else console.log("Failed to load file! HTTP status: "+i.status+", file: "+o)};try{i.send(null)}catch(n){console.log("fehler beim laden der punktwolke: "+n)}}},Potree.BinaryLoader.prototype.parse=function(e,t){var o=(t.byteLength/e.pcoGeometry.pointAttributes.byteSize,e.pcoGeometry.pointAttributes),i=Potree.workers.binaryDecoder.getWorker();i.onmessage=function(t){var o=t.data,n=o.attributeBuffers;Potree.workers.binaryDecoder.returnWorker(i);var r=new THREE.BufferGeometry;for(var s in n)if(n.hasOwnProperty(s)){{var a=n[s].buffer,l=n[s].attribute;l.numElements}parseInt(s)===PointAttributeNames.POSITION_CARTESIAN?r.addAttribute("position",new THREE.BufferAttribute(new Float32Array(a),3)):parseInt(s)===PointAttributeNames.COLOR_PACKED?r.addAttribute("color",new THREE.BufferAttribute(new Float32Array(a),3)):parseInt(s)===PointAttributeNames.INTENSITY?r.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(a),1)):parseInt(s)===PointAttributeNames.CLASSIFICATION&&r.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(a),1))}r.addAttribute("indices",new THREE.BufferAttribute(new Float32Array(o.indices),1)),r.boundingBox=e.boundingBox,e.geometry=r,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--};var n={buffer:t,pointAttributes:o,version:this.version.version,min:[e.boundingBox.min.x,e.boundingBox.min.y,e.boundingBox.min.z],offset:[e.pcoGeometry.offset.x,e.pcoGeometry.offset.y,e.pcoGeometry.offset.z],scale:this.scale};i.postMessage(n,[n.buffer])},Potree.LasLazLoader=function(e){this.version="string"==typeof e?new Potree.Version(e):e},Potree.LasLazLoader.prototype.load=function(e){if(!e.loaded){var t=e.pcoGeometry.pointAttributes,o=e.getURL();this.version.equalOrHigher("1.4")&&(o+="."+t.toLowerCase());var i=this,n=new XMLHttpRequest;n.open("GET",o,!0),n.responseType="arraybuffer",n.overrideMimeType("text/plain; charset=x-user-defined"),n.onreadystatechange=function(){if(4===n.readyState)if(200===n.status){var t=n.response;i.parse(e,t)}else console.log("Failed to load file! HTTP status: "+n.status+", file: "+o)},n.send(null)}},Potree.LasLazLoader.progressCB=function(){},Potree.LasLazLoader.prototype.parse=function(e,t){var o=new LASFile(t),i=new Potree.LasLazBatcher(e);return Promise.resolve(o).cancellable().then(function(e){return e.open().then(function(){return e.isOpen=!0,e})["catch"](Promise.CancellationError,function(t){return e.close().then(function(){throw t})})}).then(function(e){return e.getHeader().then(function(t){return[e,t]})}).then(function(e){var t=e[0],o=e[1],n=1,r=0,s=1>=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,d=r.data.color,c=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),g=new ArrayBuffer(4*a),f=new Uint32Array(g),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],f[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(d),3)),s.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(c),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(g,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; "," "," ","#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 ); "," 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 r = spacing * 1.5; "," #if defined fixed_point_size "," gl_PointSize = size; "," #elif defined attenuated_point_size "," //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); "," gl_PointSize = (1.0 / tan(fov/2.0)) * size / (-mvPosition.z); "," gl_PointSize = gl_PointSize * screenHeight / 2.0; "," #elif defined adaptive_point_size "," //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); "," //gl_PointSize = (1.0 / tan(fov/2.0)) * r / sqrt( max(0.0, mvPosition.z * mvPosition.z - r * r)); "," gl_PointSize = (1.0 / tan(fov/2.0)) * r / (-mvPosition.z); "," gl_PointSize = size * gl_PointSize * screenHeight / 2.0; "," gl_PointSize = gl_PointSize / pow(1.9, getOctreeDepth()); "," #endif "," "," gl_PointSize = max(minSize, gl_PointSize); "," gl_PointSize = min(50.0, gl_PointSize); "," "," // 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 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; "," ","void main() { "," "," #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats) "," float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0); "," float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0); "," float c = 1.0 - (a + b); "," "," if(c < 0.0){ "," discard; "," } "," #endif "," "," #if defined weighted_splats "," vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight); "," "," float depth = texture2D(depthMap, uv).r; "," if(vLinearDepth > depth + blendDepth){ "," discard; "," } "," #endif "," "," #if defined use_interpolation "," gl_FragDepthEXT = gl_FragCoord.z + 0.002*(1.0-pow(c, 1.0)) * gl_FragCoord.w; "," #endif "," "," "," #if defined color_type_point_index "," gl_FragColor = vec4(vColor, pcIndex / 255.0); "," #else "," gl_FragColor = vec4(vColor, vOpacity); "," #endif "," "," "," #if defined weighted_splats "," float w = pow(c, 2.0); "," gl_FragColor.rgb = gl_FragColor.rgb * w; "," gl_FragColor.a = w; "," #endif "," "," "," ","} "],THREE.FirstPersonControls=function(e,t){function o(e){l.enabled!==!1&&(e.preventDefault(),0===e.button?(R=T.ROTATE,d.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(C))}function i(e){if(l.enabled!==!1){e.preventDefault();var t=l.domElement===document?l.domElement.body:l.domElement;R===T.ROTATE?(c.set(e.clientX,e.clientY),h.subVectors(c,d),l.rotateLeft(2*Math.PI*h.x/t.clientWidth*l.rotateSpeed),l.rotateUp(2*Math.PI*h.y/t.clientHeight*l.rotateSpeed),d.copy(c)):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(w),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(C),l.dispatchEvent(w)}}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,d=new THREE.Vector2,c=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),g=0,f=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"},C={type:"start"},w={type:"end"};this.rotateLeft=function(e){g-=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.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 o={type:"move",translation:y.clone()};this.dispatchEvent(o)}if(t.add(y),0!==g||0!==E){var o={type:"rotate",thetaDelta:g,phiDelta:E};this.dispatchEvent(o)}this.object.updateMatrix();var i=(new THREE.Matrix4).makeRotationY(g),n=(new THREE.Matrix4).multiplyMatrices(i,this.object.matrix);this.object.quaternion.setFromRotationMatrix(n),this.object.rotation.x+=E,g=0,E=0,f=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),THREE.EarthControls=function(e,t,o){function i(e){if(a.enabled!==!1){e.preventDefault();var t={x:e.clientX/a.domElement.clientWidth*2-1,y:2*-(e.clientY/a.domElement.clientHeight)+1},o=getMousePointCloudIntersection(t,a.camera,a.renderer,a.pointclouds);if(o){var i=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),o),s=new THREE.Vector3(t.x,t.y,.5);s.unproject(a.camera);var u=s.sub(a.camera.position).normalize(),p=new THREE.Ray(a.camera.position,u);E=p.intersectPlane(i),v=a.camera.clone(),v.rotation.copy(a.camera.rotation),c.set(e.clientX,e.clientY),h.set(e.clientX,e.clientY),a.scene.add(a.pivotNode),a.pivotNode.position.copy(E),0===e.button?d=l.DRAG:2===e.button&&(d=l.ROTATE),a.domElement.addEventListener("mousemove",n,!1),a.domElement.addEventListener("mouseup",r,!1)}}}function n(e){if(a.enabled!==!1){e.preventDefault();{a.domElement===document?a.domElement.body:a.domElement}m.set(e.clientX-h.x,e.clientY-h.y),h.set(e.clientX,e.clientY)}}function r(){a.enabled!==!1&&(a.domElement.removeEventListener("mousemove",n,!1),a.domElement.removeEventListener("mouseup",r,!1),d=l.NONE,a.scene.remove(a.pivotNode))}function s(e){if(a.enabled!==!1&&a.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1,o={x:e.clientX/a.domElement.clientWidth*2-1,y:2*-(e.clientY/a.domElement.clientHeight)+1},i=getMousePointCloudIntersection(o,a.camera,a.renderer,a.pointclouds);if(i){var n=i.distanceTo(a.camera.position),r=(new THREE.Vector3).subVectors(i,a.camera.position).normalize();a.camera.position.add(r.multiplyScalar(.1*n*t))}}}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},d=l.NONE,c=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;if(E){if(d===l.DRAG){var t=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),E),o={x:h.x/this.domElement.clientWidth*2-1,y:2*-(h.y/this.domElement.clientHeight)+1},i=new THREE.Vector3(o.x,o.y,.5);i.unproject(v);var n=i.sub(v.position).normalize(),r=new THREE.Ray(v.position,n),s=r.distanceToPlane(t);if(s>0){var a=(new THREE.Vector3).subVectors(E,n.clone().multiplyScalar(s));this.camera.position.copy(a)}}else if(d===l.ROTATE){var c=m.clone().multiplyScalar(e);c.x*=.3,c.y*=.2,this.camera.updateMatrixWorld();var u=new THREE.Object3D,p=new THREE.Object3D;u.add(p),u.position.copy(E),p.position.copy(this.camera.position).sub(E),p.rotation.copy(this.camera.rotation),u.rotation.y+=-c.x;var n=this.camera.getWorldDirection(),g=new THREE.Vector3(0,1,0),f=(new THREE.Vector3).crossVectors(g,n),y=p.position.clone();y.y=0,y.normalize();var b=y.dot(p.position.clone().normalize()),T=Math.acos(b);p.position.y<0&&(T=-T);var R=0;R=c.y>0?c.y-Math.max(0,this.minAngle-(T-c.y)):c.y+Math.max(0,T-c.y-this.maxAngle),u.rotateOnAxis(f,-R),u.updateMatrixWorld(),this.camera.position.copy(p.getWorldPosition()),this.camera.quaternion.copy(p.getWorldQuaternion())}var P=this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),C=Math.abs(P.z/30),w=this.pivotNode.scale.length();this.pivotNode.scale.multiplyScalar(C/w)}m.set(0,0)},this.reset=function(){d=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){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(){if(null===this.first)return null;var e=this.first;return null!==e.next?(this.first=e.next,this.first.previous=null):(this.first=null,this.last=null),delete this.items[e.node.id],this.elements--,this.numPoints-=e.node.numPoints,e.node},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()+")"},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;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;t<this.visibleNodes.length;t++){for(var o=this.visibleNodes[t],i=o.node,n=!0,r=0;r<i.children.length;r++){var s=i.children[r];s instanceof THREE.PointCloud&&(n=n&&!s.visible)}n&&e.push(i)}this.visibleBounds.min=new THREE.Vector3(1/0,1/0,1/0),this.visibleBounds.max=new THREE.Vector3(-1/0,-1/0,-1/0);for(var t=0;t<e.length;t++){var i=e[t];this.visibleBounds.expandByPoint(i.boundingBox.min),this.visibleBounds.expandByPoint(i.boundingBox.max)}},Potree.PointCloudOctree.prototype.updateProfileRequests=function(){for(var e=0;e<this.profileRequests.length;e++){var t=this.profileRequests[e],o=t.plane,i=(t.start,t.end,t.depth),n=[];for(n.push(this);n.length>0;){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))<a.radius&&t.loadQueue.push(r)}if(r.level<i)for(var e=0;e<r.children.length;e++){var l=r.children[e];(l instanceof Potree.PointCloudOctreeProxyNode||l instanceof THREE.PointCloud)&&n.push(r.children[e])}}}for(var d=[],e=0;e<this.profileRequests.length;e++){var c=this.profileRequests[e];if(c.loadQueue.length>0){var r=c.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(c.start,c.end,c.width,c.depth);c.callback({type:"finished",points:p}),d.push(c)}}for(var e=0;e<d.length;e++){var m=this.profileRequests.indexOf(d[e]);m>-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);for(var r=0;r<e.children.length;r++){var s=e.children[r],a=i.indexOf(s.name)>=0;if(a)for(var l=0;l<this.visibleGeometry.length;l++)if(this.visibleGeometry[l].node.name===s.name){o.push({node:s,weight:this.visibleGeometry[l].weight});break}}},Potree.PointCloudOctree.prototype.updateMaterial=function(e,t,o){this.material.fov=t.fov*(Math.PI/180),this.material.screenWidth=o.domElement.clientWidth,this.material.screenHeight=o.domElement.clientHeight,this.material.spacing=this.pcoGeometry.spacing,this.material.near=t.near,this.material.far=t.far,this.material.octreeLevels=this.maxLevel,this.material.pointSizeType&&(this.material.pointSizeType===Potree.PointSizeType.ADAPTIVE||this.material.pointColorType===Potree.PointColorType.OCTREE_DEPTH)&&this.updateVisibilityTexture(this.material,e)},Potree.PointCloudOctree.prototype.updateLoadQueue=function(){if(this.loadQueue.length>0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e<Math.min(5,this.loadQueue.length);e++)this.loadQueue[e].node.geometryNode.load()}},Potree.PointCloudOctree.prototype.update=function(e,t){if(this.visibleGeometry=[],this.loadQueue=[],this.visibleNodes=[],this.numVisibleNodes=0,this.numVisiblePoints=0,this.visible){this.updateMatrixWorld(!0),this.visibleGeometry=this.getVisibleGeometry(e);for(var o=[],i=0;i<this.visibleGeometry.length;i++)o.push(this.visibleGeometry[i].node.name);for(var i=0;i<this.profileRequests.length;i++){var n=this.profileRequests[i];n.loadQueue=[]}for(var i=0;i<this.boundingBoxNodes.length;i++)this.boundingBoxNodes[i].visible=!1;this.hideDescendants(this.children[0]);var r=[];for(r.push({node:this.children[0],weight:1});r.length>0;){{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 a instanceof THREE.PointCloud&&this.updatePointCloud(a,s,r,o)}this.updateProfileRequests(),this.updateVisibleBounds(),this.updateLoadQueue(),this.hideDescendants(this.children[0]);for(var d=[],i=0;i<this.visibleNodes.length;i++)this.visibleNodes[i].node.visible=!0,d.push(this.visibleNodes[i].node);this.updateMaterial(d,e,t)}},Potree.PointCloudOctree.prototype.getVisibleGeometry=function(e){var t=[],o=this.pcoGeometry;e.updateMatrixWorld();var i=new THREE.Frustum,n=e.matrixWorldInverse,r=this.matrixWorld,s=e.projectionMatrix,a=(new THREE.Matrix4).multiply(s).multiply(n).multiply(r);i.setFromMatrix(a);var l=e.matrixWorld,d=(new THREE.Matrix4).getInverse(r),c=(new THREE.Matrix4).multiply(d).multiply(l),h=(new THREE.Vector3).setFromMatrixPosition(c),u=o.root,p=[],m=0,v=u.boundingBox.getBoundingSphere(),E=v.center.distanceTo(h),g=1/Math.max(.1,v.center.distanceTo(h)-v.radius);p.push({node:u,weight:g});for(var f=0;p.length>0;){f++;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 C=0;8>C;C++)if(b.children[C]){var w=b.children[C],v=w.boundingSphere,E=v.center.distanceTo(h),x=v.radius,g=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(g=V,0>E-x&&(g=Number.MAX_VALUE),0===p.length)p.push({node:w,weight:g});else{for(var S=0,M=0;M<p.length;M++){if(g>p[M].weight){var S=M;break}if(M==p.length-1){S=p.length;break}}p.splice(S,0,{node:w,weight:g})}}}}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;s<t.length;s++)r[t[s].name]=!0;for(var s=0;s<t.length;s++){for(var a=t[s],l=[],d=0;d<a.children.length;d++){var c=a.children[d];c instanceof THREE.PointCloud&&c.visible&&r[c.name]&&l.push(c)}l.sort(function(e,t){return e.name<t.name?-1:e.name>t.name?1:0}),i[3*s+0]=0,i[3*s+1]=0,i[3*s+2]=0;for(var d=0;d<l.length;d++){var c=l[d],h=parseInt(c.name.substr(-1));if(i[3*s+0]+=Math.pow(2,h),0===d){var u=t.indexOf(c);i[3*s+1]=u-s}}}e.uniforms.nodeSize.value=this.pcoGeometry.boundingBox.size().x,o.needsUpdate=!0}},Potree.PointCloudOctree.prototype.nodesOnRay=function(e,t){for(var o=[],i=t.clone(),n=0;n<e.length;n++){var r=e[n].node,s=r.boundingSphere.clone().applyMatrix4(r.matrixWorld);i.isIntersectionSphere(s)&&o.push(r)}return o},Potree.PointCloudOctree.prototype.updateMatrixWorld=function(e){this.matrixAutoUpdate===!0&&this.updateMatrix(),(this.matrixWorldNeedsUpdate===!0||e===!0)&&(void 0===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1,e=!0)},Potree.PointCloudOctree.prototype.replaceProxy=function(e){var t=e.geometryNode;if(t.loaded===!0){var o=t.geometry,i=new THREE.PointCloud(o,this.material);i.name=e.name,i.level=e.level,i.numPoints=e.numPoints,i.boundingBox=o.boundingBox,i.boundingSphere=i.boundingBox.getBoundingSphere(),i.pcoGeometry=t;var n=e.parent;n.remove(e),n.add(i),i.matrixWorld.multiplyMatrices(i.parent.matrixWorld,i.matrix);for(var r=0;8>r;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;o<e.children.length;o++){var i=e.children[o];i.visible&&t.push(i)}for(;t.length>0;){var e=t.shift();e.visible=!1;for(var o=0;o<e.children.length;o++){var i=e.children[o];i.visible&&t.push(i)}}},Potree.PointCloudOctree.prototype.moveToOrigin=function(){this.position.set(0,0,0),this.updateMatrixWorld(!0);var e=this.boundingBox,t=this.matrixWorld,o=Potree.utils.computeTransformedBoundingBox(e,t);this.position.set(0,0,0).sub(o.center())},Potree.PointCloudOctree.prototype.moveToGroundPlane=function(){this.updateMatrixWorld(!0);var e=this.boundingBox,t=this.matrixWorld,o=Potree.utils.computeTransformedBoundingBox(e,t);this.position.y+=-o.min.y},Potree.PointCloudOctree.prototype.getBoundingBoxWorld=function(){this.updateMatrixWorld(!0);var e=this.boundingBox,t=this.matrixWorld,o=Potree.utils.computeTransformedBoundingBox(e,t);return o},Potree.PointCloudOctree.prototype.getPointsInProfile=function(e,t){for(var o=[],i=0,n=0;n<e.points.length-1;n++){var r=e.points[n],s=e.points[n+1],a=this.getProfile(r,s,e.width,t),l=function(e,t,o){var i=e,n=t,r=o,s=new THREE.Vector3(1,0,0),a=(new THREE.Vector3).subVectors(n,i);a.y=0,a.normalize();var l=Math.acos(s.dot(a));return a.z>0&&(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),d={start:r,end:s,points:a,project:l};o.push(d),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(),d=new THREE.Vector3(0,1,0),c=(new THREE.Vector3).crossVectors(l,d).normalize(),h=c,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 g=v.geometry,f=g.attributes.position,y=f.array,b=v.numPoints;if(!m){m={};for(var T in g.attributes)g.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 C=Math.abs(u.distanceToPoint(P)),w=Math.abs(p.distanceToPoint(P));if(o/2>C&&a/2>w){for(var T in g.attributes)if(g.attributes.hasOwnProperty(T))if("position"===T)m[T].push(P);else if("indices"===T);else{var x=g.attributes[T];if(1===x.itemSize)m[T].push(x.array[R+V]);else{for(var H=[],V=0;V<x.itemSize;V++)H.push(x.array[R*x.itemSize+V]);m[T].push(H)}}E++}}}if(v==this||v.level<i)for(var R=0;R<v.children.length;R++){var S=v.children[R];if(S instanceof THREE.PointCloud){var M=S.boundingSphere.clone().applyMatrix4(S.matrixWorld);u.distanceToSphere(M)<M.radius&&r.push(S)}}}m.numPoints=m.position.length;var B=function(e,t){var o=e,i=t,n=new THREE.Vector3(1,0,0),r=(new THREE.Vector3).subVectors(i,o);r.y=0,r.normalize();var s=Math.acos(n.dot(r));return r.z>0&&(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=B,m}this.profileRequests.push(new Potree.ProfileRequest(e,t,o,i,n))},Potree.PointCloudOctree.disposeLeastRecentlyUsed=function(e){var t=0;do{var o=this.lru.first.node,i=o.parent,n=(o.geometry,o.pcoGeometry),r=new Potree.PointCloudOctreeProxyNode(n),s=Potree.PointCloudOctree.disposeNode(o);if(t+=s.freed,i.add(r),0==s.numDeletedNodes)break}while(e>t)},Potree.PointCloudOctree.disposeNode=function(e){var t=0,o=0,i=[];e.traverse(function(e){i.push(e)});for(var n=0;n<i.length;n++){var r=i[n];r instanceof THREE.PointCloud&&(t+=r.pcoGeometry.numPoints,r.pcoGeometry.dispose(),r.geometry.dispose(),Potree.PointCloudOctree.lru.remove(r),o++)}return Potree.PointCloudOctree.lru.remove(e),e.parent.remove(e),{freed:t,numDeletedNodes:o}},Potree.PointCloudOctree.prototype.getVisibleExtent=function(){return this.visibleBounds.applyMatrix4(this.matrixWorld)};var point=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=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat})),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,this.pickTarget.setSize(s,a);var d=e.context;d.enable(d.SCISSOR_TEST),d.scissor(l.x-(n-1)/2,l.y-(n-1)/2,n,n),d.disable(d.SCISSOR_TEST);var c=this.pickMaterial;e.setRenderTarget(this.pickTarget),e.setDepthTest(c.depthTest),e.setDepthWrite(c.depthWrite),e.setBlending(THREE.NoBlending),e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),r.length>0&&r.push(r[0]);for(var h=0;h<r.length;h++){var u=r[h],p=u.geometry;if(p.attributes.indices.buffer){if(c.pcIndex=h,c.program){var m=c.program.program;d.useProgram(m);var v=d.getAttribLocation(m,"indices"),E=4;d.bindBuffer(d.ARRAY_BUFFER,p.attributes.indices.buffer),d.enableVertexAttribArray(v),d.vertexAttribPointer(v,E,d.UNSIGNED_BYTE,!0,0,0),d.uniform1f(c.program.uniforms.pcIndex,c.pcIndex)}e.renderBufferDirect(t,[],null,c,p,u)}}var n=17,g=n*n,f=new ArrayBuffer(4*g),y=new Uint8Array(f),b=new Uint32Array(f);e.context.readPixels(l.x-(n-1)/2,l.y-(n-1)/2,n,n,e.context.RGBA,e.context.UNSIGNED_BYTE,y);for(var T=Number.MAX_VALUE,R=null,P=0;n>P;P++)for(var C=0;n>C;C++){var w=P+C*n,x=Math.pow(P-(n-1)/2,2)+Math.pow(C-(n-1)/2,2),H=y[4*w+3];y[4*w+3]=0;var V=b[w];(0!==V||0!==H)&&T>x&&(R={pIndex:V,pcIndex:H},T=x)}if(R){var S={},M=r[R.pcIndex],B=M.geometry.attributes;for(var A in B)if(B.hasOwnProperty(A)){var I=p.attributes[A];if("position"===A){var L=M.geometry.attributes.position.array,N=L[3*R.pIndex+0],W=L[3*R.pIndex+1],G=L[3*R.pIndex+2],X=new THREE.Vector3(N,W,G);X.applyMatrix4(this.matrixWorld),S[A]=X}else if("indices"===A);else if(1===I.itemSize)S[A]=I.array[h+z];else{for(var Z=[],z=0;z<I.itemSize;z++)Z.push(I.array[h*I.itemSize+z]);S[A]=Z}}return S}return null},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.name=e,this.index=parseInt(e.charAt(e.length-1)),this.pcoGeometry=t,this.boundingBox=o,this.boundingSphere=o.getBoundingSphere(),this.children={},this.numPoints=0,this.level=null},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(){var e,t="",o=this.pcoGeometry.hierarchyStepSize,i=this.name.substr(1);if(e=0==i.length?0:Math.ceil(i.length/o),0==e)t="";else{t="";for(var n=0;e>n;n++)t+="r"+i.substr(0,n*o)+"/"}return t},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,Potree.PointCloudOctree.lru.numPoints+this.numPoints>=Potree.pointLoadLimit&&Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints),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(),d=1,c=0;8>c;c++){if(0!==(l.children&d)){var h=l.name+c,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}d=2*d}if(a===t.byteLength)break}var m={};m[e.name]=e;for(var v=e.pcoGeometry,c=0;c<s.length;c++){var E=s[c].name,r=s[c].numPoints,g=parseInt(E.charAt(E.length-1)),f=E.substring(0,E.length-1),y=m[f],b=E.length-1,T=POCLoader.createChildAABB(y.boundingBox,g),R=new Potree.PointCloudOctreeGeometryNode(E,v,T);R.level=b,R.numPoints=r,R.hasChildren=s[c].children>0,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(){delete this.geometry,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 d=2*(a/e)-1,c=2*(l/t)-1,h=a+e*l,u=o(2*d,2*c)/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,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.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",g);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=c();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=c()){var i=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(i,o)}}else o=d(),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=d();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 d(){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;i<h.measurements.length;i++)for(var n=h.measurements[i],r=0;r<n.spheres.length;r++)o.push(n.spheres[r]);var s=t.intersectObjects(o,!0);return s.length>0?s[0]:!1}function c(){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;s<i.length;s++){var a=i[s],l=a.pick(h.renderer,h.camera,o);if(l){var d=h.camera.position.distanceTo(l.position);(!n||r>d)&&(n=l,r=d)}}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=c();if(t)for(var o=0;o<h.measurements.length;o++){var i=h.measurements[o],n=i.spheres.indexOf(h.dragstart.object);if(n>=0){h.measurements[o].setPosition(n,t);break}}e.event.stopImmediatePropagation()},g=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<this.measurements.length;e++)n.push(this.measurements[e]);for(this.activeMeasurement&&n.push(this.activeMeasurement),e=0;e<n.length;e++){var r=n[e];for(t=0;t<r.spheres.length;t++){var s=r.spheres[t];o=s.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),i=Math.abs(o.z/60),s.scale.set(i,i,i)}for(t=0;t<r.angleLabels.length;t++){var a=r.angleLabels[t];o=a.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),i=Math.abs(o.z/5);var l=a.scale.length();a.scale.multiplyScalar(i/l)}}this.light.position.copy(this.camera.position),this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position))},this.render=function(){this.update(),o.render(this.sceneMeasurement,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousemove",r,!1),this.domElement.addEventListener("mousedown",a,!1),this.domElement.addEventListener("mouseup",l,!0)},Potree.AngleTool.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.AreaTool=function(e,t,o){function i(e){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.edgeLabels=[],this.root=e,this.closed=!0,this.areaLabel=new Potree.TextSprite,this.areaLabel.setBorderColor({r:0,g:255,b:0,a:0}),this.areaLabel.setBackgroundColor({r:0,g:255,b:0,a:0}),this.areaLabel.setTextColor({r:180,g:220,b:180,a:1}),this.areaLabel.material.depthTest=!1,this.areaLabel.material.opacity=1,e.add(this.areaLabel);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",g);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("abc");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.edgeLabels.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.edgeLabels[e]),this.spheres.splice(e,1),this.edges.splice(e,1),this.edgeLabels.splice(e,1),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,o=0;o<this.points.length;o++){var i=this.points[o],n=this.points[t];e+=(n.x+i.x)*(i.z-n.z),t=o}return Math.abs(e/2)},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(){if(this.areaLabel.visible=this.points.length>=3,1===this.points.length){var e=this.points[0];return this.spheres[0].position.copy(e),this.edges[0].visible=!1,void(this.edgeLabels[0].visible=!1)}for(var t=new THREE.Vector3,o=this.points.length-1,i=0;o>=i;i++){var e=this.points[i],n=this.spheres[i],r=0===i?o:i-1,s=i===o?0:i+1,a=this.points[r],l=this.points[s],d=this.edges[r],c=this.edges[i],h=this.edgeLabels[r],u=this.edgeLabels[i],p=e.distanceTo(a),m=e.distanceTo(l),v=(new THREE.Vector3).addVectors(a,e).multiplyScalar(.5),E=(new THREE.Vector3).addVectors(e,l).multiplyScalar(.5);h.position.copy(v),u.position.copy(E),h.setText(p.toFixed(2)),u.setText(m.toFixed(2)),n.position.copy(e),d.geometry.vertices[1].copy(e),d.geometry.verticesNeedUpdate=!0,d.geometry.computeBoundingSphere(),c.geometry.vertices[0].copy(e),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),i!==o||this.closed?(c.visible=!0,u.visible=!0):(c.visible=!1,u.visible=!1),t.add(e)}t.multiplyScalar(1/this.points.length);var g=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(g),this.areaLabel.position.copy(t)}}function n(e){if(h.enabled){var t=c();if(t){var o=t.clone();p===u.DEFAULT&&(p=u.PICKING,h.activeMeasurement=new i),h.activeMeasurement.add(o);var e={type:"newpoint",position:o.clone()};h.dispatchEvent(e)}}}function r(e){var t=h.domElement.getBoundingClientRect();if(h.mouse.x=(e.clientX-t.left)/h.domElement.clientWidth*2-1,h.mouse.y=2*-((e.clientY-t.top)/h.domElement.clientHeight)+1,h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(p==u.PICKING&&h.activeMeasurement){var o=c();if(o){var i=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(i,o)}}else{var o=d();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(){p==u.PICKING&&(h.activeMeasurement.remove(h.activeMeasurement.points.length-1),h.measurements.push(h.activeMeasurement),h.activeMeasurement=void 0,p=u.DEFAULT,h.setEnabled(!1))}function a(e){if(1===e.which){p!==u.DEFAULT&&e.stopImmediatePropagation();var t=d();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 d(){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;i<h.measurements.length;i++)for(var n=h.measurements[i],r=0;r<n.spheres.length;r++)o.push(n.spheres[r]);var s=t.intersectObjects(o,!0);return s.length>0?s[0]:!1}function c(){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;s<i.length;s++){var a=i[s],l=a.pick(h.renderer,h.camera,o);if(l){var d=h.camera.position.distanceTo(l.position);(!n||r>d)&&(n=l,r=d)}}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};{var u={DEFAULT:0,PICKING:1},p=u.DEFAULT;new THREE.SphereGeometry(.4,10,10)}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;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){var t=c();if(t)for(var o=0;o<h.measurements.length;o++){var i=h.measurements[o],n=i.spheres.indexOf(h.dragstart.object);if(n>=0){h.measurements[o].setPosition(n,t);break}}e.event.stopImmediatePropagation()},g=function(){};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(){for(var e=[],o=0;o<this.measurements.length;o++)e.push(this.measurements[o]);this.activeMeasurement&&e.push(this.activeMeasurement);for(var o=0;o<e.length;o++){for(var i=e[o],n=0;n<i.spheres.length;n++){var r=i.spheres[n],s=r.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),a=(new THREE.Vector4(s.x,s.y,s.z).applyMatrix4(t.projectionMatrix),Math.abs(s.z/60));r.scale.set(a,a,a)}for(var n=0;n<i.edgeLabels.length;n++){var l=i.edgeLabels[n],s=l.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),a=Math.abs(s.z/5),d=l.scale.length();l.scale.multiplyScalar(a/d)}var s=i.areaLabel.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),a=Math.abs(s.z/4),d=i.areaLabel.scale.length();i.areaLabel.scale.multiplyScalar(a/d)}this.light.position.copy(this.camera.position),this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position))},this.render=function(){this.update(),o.render(this.sceneMeasurement,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousemove",r,!1),this.domElement.addEventListener("mousedown",a,!1),this.domElement.addEventListener("mouseup",l,!0)},Potree.AreaTool.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.MeasuringTool=function(e,t,o){function i(){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.edgeLabels=[]}function n(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e}function r(e){if(u.enabled){var t=h();if(t){var o=t.clone(),r=new THREE.Mesh(v,n());r.position.copy(t),u.sceneRoot.add(r),r.addEventListener("mousemove",E),r.addEventListener("mouseleave",g),r.addEventListener("mousedrag",f),r.addEventListener("drop",y);var s=new THREE.Mesh(v,n());s.position.copy(t),u.sceneRoot.add(s),s.addEventListener("mousemove",E),s.addEventListener("mouseleave",g),s.addEventListener("mousedrag",f),s.addEventListener("drop",y);var a=o.x.toFixed(2)+" / "+o.y.toFixed(2)+" / "+o.z.toFixed(2),l=new Potree.TextSprite(a);l.setBorderColor({r:0,g:255,b:0,a:1}),l.material.depthTest=!1,l.material.opacity=0,l.position.copy(t),l.position.y+=.5;var d=new Potree.TextSprite(a);d.setBorderColor({r:0,g:255,b:0,a:1}),d.material.depthTest=!1,d.material.opacity=0,d.position.copy(t),d.position.y+=.5;var c=new THREE.Color(16711680),b=new THREE.Geometry;b.vertices.push(t.clone(),t.clone()),b.colors.push(c,c,c);var T=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:10});T.depthTest=!1,sConnection=new THREE.Line(b,T);var R=new Potree.TextSprite(0);R.setBorderColor({r:0,g:255,b:0,a:0}),R.setBackgroundColor({r:0,g:255,b:0,a:0}),R.material.depthTest=!1,R.position.copy(t),R.position.y+=.5,u.sceneRoot.add(sConnection),u.sceneRoot.add(l),u.sceneRoot.add(d),u.sceneRoot.add(R),m===p.DEFAULT?(m=p.PICKING,u.activeMeasurement=new i,u.activeMeasurement.spheres.push(r)):m===p.PICKING&&u.sceneRoot.remove(r),u.activeMeasurement.points.push(t),u.activeMeasurement.spheres.push(s),u.activeMeasurement.sphereLabels.push(l),u.activeMeasurement.sphereLabels.push(d),u.activeMeasurement.edges.push(sConnection),u.activeMeasurement.edgeLabels.push(R);var e={type:"newpoint",position:o.clone()};u.dispatchEvent(e)}}}function s(e){var t=u.domElement.getBoundingClientRect();if(u.mouse.x=(e.clientX-t.left)/u.domElement.clientWidth*2-1,u.mouse.y=2*-((e.clientY-t.top)/u.domElement.clientHeight)+1,u.dragstart)u.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(m==p.PICKING&&u.activeMeasurement){var o=h();if(o)if(1===u.activeMeasurement.spheres.length){var i=o.clone(),n=u.activeMeasurement.spheres[0];n.position.copy(o)}else{var i=o.clone(),r=u.activeMeasurement.spheres.length,n=u.activeMeasurement.spheres[r-1],s=u.activeMeasurement.sphereLabels[r-1],a=u.activeMeasurement.edges[r-2],l=u.activeMeasurement.edgeLabels[r-2],d=i.x.toFixed(2)+" / "+i.y.toFixed(2)+" / "+i.z.toFixed(2);s.setText(d),n.position.copy(o),s.position.copy(o),s.position.y+=.5,a.geometry.vertices[1].copy(o),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere();var v=a.geometry.vertices[1].clone().add(a.geometry.vertices[0]).multiplyScalar(.5),E=a.geometry.vertices[0].distanceTo(a.geometry.vertices[1]).toFixed(2);l.position.copy(v),l.setText(E),l.scale.multiplyScalar(10)}}else{var o=c();o?(o.object.dispatchEvent({type:"mousemove",target:o.object,event:e}),u.hoveredElement&&u.hoveredElement!==o.object&&u.hoveredElement.dispatchEvent({type:"mouseleave",target:u.hoveredElement,event:e}),u.hoveredElement=o.object):(u.hoveredElement&&u.hoveredElement.dispatchEvent({type:"mouseleave",target:u.hoveredElement,event:e}),u.hoveredElement=null)}}function a(){if(m==p.PICKING){var e=u.activeMeasurement.spheres.pop(),t=u.activeMeasurement.edges.pop(),o=u.activeMeasurement.sphereLabels.pop(),i=u.activeMeasurement.edgeLabels.pop();u.sceneRoot.remove(e),u.sceneRoot.remove(t),u.sceneRoot.remove(o),u.sceneRoot.remove(i),u.measurements.push(u.activeMeasurement),u.activeMeasurement=void 0,m=p.DEFAULT,u.setEnabled(!1)}}function l(e){if(1===e.which){m!==p.DEFAULT&&e.stopImmediatePropagation();var t=c();t&&(u.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:u.sceneRoot.position.clone(),mousePos:{x:u.mouse.x,y:u.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&a(e)}function d(e){u.dragstart&&(u.dragstart.object.dispatchEvent({type:"drop",event:e}),u.dragstart=null)}function c(){var e=new THREE.Vector3(u.mouse.x,u.mouse.y,.5);e.unproject(u.camera);var t=new THREE.Raycaster;t.ray.set(u.camera.position,e.sub(u.camera.position).normalize());for(var o=[],i=0;i<u.measurements.length;i++)for(var n=u.measurements[i],r=0;r<n.spheres.length;r++)o.push(n.spheres[r]);var s=t.intersectObjects(o,!0);return s.length>0?s[0]:!1}function h(){var e=new THREE.Vector3(u.mouse.x,u.mouse.y,.5);e.unproject(u.camera);var t=e.sub(u.camera.position).normalize(),o=new THREE.Ray(u.camera.position,t),i=[];u.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;s<i.length;s++){var a=i[s],l=a.pick(u.renderer,u.camera,o);if(l){var d=u.camera.position.distanceTo(l.position);(!n||r>d)&&(n=l,r=d)}}return n?n.position:null}var u=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};var p={DEFAULT:0,PICKING:1},m=p.DEFAULT,v=new THREE.SphereGeometry(.4,10,10);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;var E=function(e){e.target.material.emissive.setHex(8947848)},g=function(e){e.target.material.emissive.setHex(0)},f=function(e){var t=h();if(t)for(var o=0;o<u.measurements.length;o++){var i=u.measurements[o],n=i.spheres.indexOf(u.dragstart.object);if(n>=0){var r=i.spheres[n];if(0===n){var s=i.edges[n],a=i.edgeLabels[n];r.position.copy(t),s.geometry.vertices[0].copy(t),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere();var l=s.geometry.vertices[0].clone().add(s.geometry.vertices[1]).multiplyScalar(.5),d=s.geometry.vertices[0].distanceTo(s.geometry.vertices[1]).toFixed(2);a.position.copy(l),a.setText(d),a.scale.multiplyScalar(10)}else if(n===i.spheres.length-1){var s=i.edges[n-1],a=i.edgeLabels[n-1];r.position.copy(t),s.geometry.vertices[1].copy(t),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere();var l=s.geometry.vertices[0].clone().add(s.geometry.vertices[1]).multiplyScalar(.5),d=s.geometry.vertices[0].distanceTo(s.geometry.vertices[1]).toFixed(2);a.position.copy(l),a.setText(d),a.scale.multiplyScalar(10)}else{var c=i.edges[n-1],p=i.edges[n],m=i.edgeLabels[n-1],v=i.edgeLabels[n];r.position.copy(t),c.geometry.vertices[1].copy(t),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),p.geometry.vertices[0].copy(t),p.geometry.verticesNeedUpdate=!0,p.geometry.computeBoundingSphere();var E=c.geometry.vertices[0].clone().add(c.geometry.vertices[1]).multiplyScalar(.5),g=c.geometry.vertices[0].distanceTo(c.geometry.vertices[1]).toFixed(2);m.position.copy(E),m.setText(g),m.scale.multiplyScalar(10);var f=p.geometry.vertices[0].clone().add(p.geometry.vertices[1]).multiplyScalar(.5),y=p.geometry.vertices[0].distanceTo(p.geometry.vertices[1]).toFixed(2);v.position.copy(f),v.setText(y),v.scale.multiplyScalar(10)}break}}e.event.stopImmediatePropagation()},y=function(){};this.setEnabled=function(e){if(this.enabled!==e&&(this.enabled=e,e)){m=p.PICKING,u.activeMeasurement=new i;var t=new THREE.Mesh(v,n());u.sceneRoot.add(t),u.activeMeasurement.spheres.push(t),t.addEventListener("mousemove",E),t.addEventListener("mouseleave",g),t.addEventListener("mousedrag",f),t.addEventListener("drop",y)}},this.update=function(){for(var e=[],o=0;o<this.measurements.length;o++)e.push(this.measurements[o]);this.activeMeasurement&&e.push(this.activeMeasurement);for(var o=0;o<e.length;o++){for(var i=e[o],n=0;n<i.spheres.length;n++){var r=i.spheres[n],s=r.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),a=(new THREE.Vector4(s.x,s.y,s.z).applyMatrix4(t.projectionMatrix),Math.abs(s.z/60));r.scale.set(a,a,a)}for(var n=0;n<i.edgeLabels.length;n++){var l=i.edgeLabels[n],s=l.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),a=Math.abs(s.z/5),d=l.scale.length();l.scale.multiplyScalar(a/d)}}this.light.position.copy(this.camera.position),this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position))},this.render=function(){this.update(),o.render(this.sceneMeasurement,this.camera)},this.domElement.addEventListener("click",r,!1),this.domElement.addEventListener("mousemove",s,!1),this.domElement.addEventListener("mousedown",l,!1),this.domElement.addEventListener("mouseup",d,!0)},Potree.MeasuringTool.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.ProfileTool=function(e,t,o){function i(){THREE.Object3D.call(this),this.points=[],this.spheres=[],this.edges=[],this.boxes=[],this.width=1,this.height=20;var e=new THREE.SphereGeometry(.4,10,10),t=new THREE.Color(16711680),o=function(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e};this.addMarker=function(i){this.points.push(i);var n=new THREE.Mesh(e,o());if(n.addEventListener("mousemove",m),n.addEventListener("mouseleave",v),n.addEventListener("mousedrag",E),n.addEventListener("drop",g),this.add(n),this.spheres.push(n),this.points.length>1){var r=new THREE.Geometry;r.vertices.push(new THREE.Vector3,new THREE.Vector3),r.colors.push(t,t,t);var s=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2,transparent:!0,opacity:.4});s.depthTest=!1;var a=new THREE.Line(r,s);a.visible=!1,this.add(a),this.edges.push(a);var l=new THREE.BoxGeometry(1,1,1),d=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),c=new THREE.Mesh(l,d);c.visible=!1,this.add(c),this.boxes.push(c)}this.setPosition(this.points.length-1,i)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]),e>0&&(this.remove(this.edges[e-1]),this.edges.splice(e-1,1),this.remove(this.boxes[e-1]),this.boxes.splice(e-1,1)),this.spheres.splice(e,1),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,o=0;o<this.points.length;o++){var i=this.points[o],n=this.points[t];e+=(n.x+i.x)*(i.z-n.z),t=o}return Math.abs(e/2)},this.setPosition=function(e,t){var o=this.points[e];o.copy(t),this.update()},this.setWidth=function(e){this.width=e,this.update()},this.update=function(){if(0!==this.points.length){if(1===this.points.length){var e=this.points[0];return void this.spheres[0].position.copy(e)}for(var t=this.points[0].clone(),o=this.points[0].clone(),i=new THREE.Vector3,n=this.points.length-1,r=0;n>=r;r++){{var e=this.points[r],s=this.spheres[r],a=0===r?n:r-1,l=r===n?0:r+1,d=this.points[a],c=this.points[l],h=this.edges[a],u=this.edges[r],p=this.boxes[a];this.boxes[r],e.distanceTo(d),e.distanceTo(c),(new THREE.Vector3).addVectors(d,e).multiplyScalar(.5),(new THREE.Vector3).addVectors(e,c).multiplyScalar(.5)}if(s.position.copy(e),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=d,v=e,E=m.clone().setY(0).distanceTo(v.clone().setY(0));p.scale.set(E,this.height,this.width);var g=(new THREE.Vector3).addVectors(m,v).multiplyScalar(.5),f=(new THREE.Vector3).subVectors(v,m),y=new THREE.Vector3(f.z,0,-f.x);p.position.set(0,0,0),p.lookAt(y),p.position.copy(g)}i.add(e),t.min(e),o.max(e)}i.multiplyScalar(1/this.points.length);for(var r=0;r<this.boxes.length;r++){var b=this.boxes[r];b.position.y=t.y+(o.y-t.y)/2,b.scale.y=1e6}}},this.raycast=function(e,t){for(var o=0;o<this.points.length;o++){var i=this.spheres[o];i.raycast(e,t)}for(var o=0;o<t.length;o++){var n=t[o];n.distance=e.ray.origin.distanceTo(n.point)}t.sort(function(e,t){return e.distance-t.distance})}}function n(e){if(p===u.INSERT){var t=c();if(t){var o=t.clone();h.activeProfile.addMarker(o);var e={type:"newpoint",position:o.clone()};h.dispatchEvent(e)}}}function r(e){var t=h.domElement.getBoundingClientRect();if(h.mouse.x=(e.clientX-t.left)/h.domElement.clientWidth*2-1,h.mouse.y=2*-((e.clientY-t.top)/h.domElement.clientHeight)+1,h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(p==u.INSERT&&h.activeProfile){var o=c();if(o){var i=h.activeProfile.points.length-1;h.activeProfile.setPosition(i,o)}}else{var o=d();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(){p==u.INSERT&&h.finishInsertion()}function a(e){if(p!==u.DEFAULT&&e.stopImmediatePropagation(),1===e.which){var t=d();if(t){for(var o=null,i=0;i<h.profiles.length;i++)for(var n=h.profiles[i],r=0;r<n.spheres.length;r++){var a=n.spheres[r];a===t.object&&(o=n.width)}h.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:h.sceneRoot.position.clone(),mousePos:{x:h.mouse.x,y:h.mouse.y},widthStart:o},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 d(){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());var o=t.intersectObjects(h.profiles);return o.length>0?o[0]:!1}function c(){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;s<i.length;s++){var a=i[s],l=a.pick(h.renderer,h.camera,o);if(l){var d=h.camera.position.distanceTo(l.position);(!n||r>d)&&(n=l,r=d)}}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};{var u={DEFAULT:0,INSERT:1},p=u.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;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){if(e.event.ctrlKey){var t=new THREE.Vector3(h.dragstart.mousePos.x,h.dragstart.mousePos.y,0),o=new THREE.Vector3(h.mouse.x,h.mouse.y,0),i=h.dragstart.widthStart,n=1-10*(t.y-o.y);if(n=Math.max(.01,n),i)for(var r=0;r<h.profiles.length;r++){var s=h.profiles[r],a=s.spheres.indexOf(h.dragstart.object);if(a>=0){s.setWidth(i*n),s.update();break}}}else{var l=c();if(l)for(var r=0;r<h.profiles.length;r++){var s=h.profiles[r],a=s.spheres.indexOf(h.dragstart.object);if(a>=0){h.profiles[r].setPosition(a,l);break}}}e.event.stopImmediatePropagation()},g=function(){};i.prototype=Object.create(THREE.Object3D.prototype),this.startInsertion=function(e){p=u.INSERT;var e=e||{},t=e.clip||!1,o=e.width||1;this.activeProfile=new i,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,p=u.DEFAULT},this.update=function(){for(var e=0;e<this.profiles.length;e++)for(var o=this.profiles[e],i=0;i<o.spheres.length;i++){var n=o.spheres[i],r=n.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),s=(new THREE.Vector4(r.x,r.y,r.z).applyMatrix4(t.projectionMatrix),Math.abs(r.z/60));n.scale.set(s,s,s)}this.light.position.copy(this.camera.position),this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position))},this.render=function(){this.update(),o.render(this.sceneProfile,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousemove",r,!1),this.domElement.addEventListener("mousedown",a,!1),this.domElement.addEventListener("mouseup",l,!0)},Potree.ProfileTool.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.TransformationTool=function(e,t,o){function i(e){if(a.mouse.x=e.clientX/a.domElement.clientWidth*2-1,a.mouse.y=2*-(e.clientY/a.domElement.clientHeight)+1,a.dragstart)a.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else{var t=s();if(t){var o=t.object;o.dispatchEvent({type:"mousemove",event:e}),a.hoveredElement&&a.hoveredElement!==o&&a.hoveredElement.dispatchEvent({type:"mouseleave",event:e}),a.hoveredElement=o}else a.hoveredElement&&a.hoveredElement.dispatchEvent({type:"mouseleave",event:e}),a.hoveredElement=null}}function n(e){if(1===e.which){var t=s();if(t){for(var o=[],i=[],n=0;n<a.targets.length;n++)o.push(a.targets[n].scale.clone()),i.push(a.targets[n].rotation.clone());a.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:a.sceneRoot.position.clone(),mousePos:{x:a.mouse.x,y:a.mouse.y},scales:o,rotations:i},e.stopImmediatePropagation()}}else 3===e.which&&a.setTargets([])}function r(e){a.dragstart&&(a.dragstart.object.dispatchEvent({type:"drop",event:e}),a.dragstart=null)}function s(){if(0!==a.targets.length){var e=new THREE.Vector3(a.mouse.x,a.mouse.y,.5);e.unproject(a.camera);var t=new THREE.Raycaster;t.ray.set(a.camera.position,e.sub(a.camera.position).normalize()),t.linePrecision=.2;var o=[];a.translationNode.visible?o.push(a.translationNode):a.scaleNode.visible?o.push(a.scaleNode):a.rotationNode.visible&&(o.push(a.rotationNode),o.push(a.sceneRotation));for(var i=t.intersectObjects(o,!0),n=0;n<i.length;n++){var r=i[n];r.distance=a.camera.position.distanceTo(r.point)}return i.sort(function(e,t){return e.distance-t.distance}),i.length>0?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(),d=(new THREE.Vector3).subVectors(a.camera.position,n).normalize(),c=d.clone().cross(l),h=6*i.length(),u=0;u<a.targets.length;u++){var p=a.targets[u],m=a.dragstart.rotations[u];p.rotation.copy(m);var v=new THREE.Quaternion;v.setFromAxisAngle(c,h),p.quaternion.multiplyQuaternions(v,p.quaternion)}},d=function(){};n.addEventListener("mousemove",r),n.addEventListener("mouseleave",s),n.addEventListener("mousedrag",l),n.addEventListener("drop",d)},this.createBox=function(e){var t=new THREE.BoxGeometry(1,1,1),o=new THREE.MeshBasicMaterial({color:e,transparent:!0,opacity:.5}),i=new THREE.Mesh(t,o);return i};this.createRotationCircle=function(e,t){for(var o=[],i=128,n=0;i>=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 d=new THREE.Geometry,n=0;n<o.length;n++)d.vertices.push(o[n]);var c=new THREE.LineBasicMaterial({color:t}),h=new THREE.Line(d,c);h.mode=THREE.LineStrip,h.scale.set(1,1,1);var u=function(){c.color.setRGB(1,1,0)},p=function(){c.color.setHex(t)},m=function(t){t.event.stopImmediatePropagation();var o=new THREE.Vector3;e===a.parts.ROTATE_X?o.x=1:e===a.parts.ROTATE_Y?o.y=1:e===a.parts.ROTATE_Z&&(o.z=-1);var i=a.dragstart.sceneClickPos.clone(),n=a.sceneRoot.position.clone(),r=i.clone().sub(n).normalize(),s=i.clone().project(a.camera),l=n.clone().project(a.camera),d=s.clone().sub(l).normalize(),c=(new THREE.Vector3(d.y,d.x,0),new THREE.Vector3(a.dragstart.mousePos.x,a.dragstart.mousePos.y,0),new THREE.Vector3(a.mouse.x,a.mouse.y,0)),h=(new THREE.Plane).setFromNormalAndCoplanarPoint(o,a.sceneRoot.position),u=a.camera.position,p=(new THREE.Vector3(0,0,-1).applyQuaternion(a.camera.quaternion),new THREE.Vector3(c.x,c.y,.5).unproject(a.camera).sub(a.camera.position).normalize()),m=new THREE.Ray(u,p),v=m.intersectPlane(h);if(v){sceneTargetNormal=v.clone().sub(n).normalize();var E,g;e===a.parts.ROTATE_X?(E=2*Math.PI+Math.atan2(r.y,-r.z),g=4*Math.PI+Math.atan2(sceneTargetNormal.y,-sceneTargetNormal.z)):e===a.parts.ROTATE_Y?(E=2*Math.PI+Math.atan2(-r.z,r.x),g=4*Math.PI+Math.atan2(-sceneTargetNormal.z,sceneTargetNormal.x)):e===a.parts.ROTATE_Z&&(E=2*Math.PI+Math.atan2(r.x,r.y),g=4*Math.PI+Math.atan2(sceneTargetNormal.x,sceneTargetNormal.y));for(var f=g-E,y=0;y<a.targets.length;y++){var b=a.targets[y],T=a.dragstart.rotations[y];b.rotation.copy(T);var R=new THREE.Quaternion;R.setFromAxisAngle(o,f),b.quaternion.multiplyQuaternions(R,b.quaternion)}}},v=function(){};return h.addEventListener("mousemove",u),h.addEventListener("mouseleave",p),h.addEventListener("mousedrag",m),h.addEventListener("drop",v),h},this.createScaleHandle=function(e,t){var o=new THREE.BoxGeometry(1,1,1),i=new THREE.MeshBasicMaterial({color:t,depthTest:!1,depthWrite:!1}),n=new THREE.Mesh(o,i);n.scale.set(.3,.3,.3),n.position.set(0,3,0);var r=new THREE.Geometry;r.vertices.push(new THREE.Vector3(0,0,0)),r.vertices.push(new THREE.Vector3(0,3,0));var s=new THREE.LineBasicMaterial({color:t,depthTest:!1,depthWrite:!1}),l=new THREE.Line(r,s),d=new THREE.Object3D;d.add(n),d.add(l),d.partID=e;var c=function(){s.color.setRGB(1,1,0),i.color.setRGB(1,1,0)},h=function(){s.color.setHex(t),i.color.setHex(t)},u=function(t){var o=new THREE.Vector3;e===a.parts.SCALE_X?o.x=1:e===a.parts.SCALE_Y?o.y=1:e===a.parts.SCALE_Z&&(o.z=-1);var i=a.dragstart.sceneClickPos.clone();i.multiply(o),i.z*=-1;var n=a.dragstart.sceneStartPos.clone().project(a.camera),r=a.dragstart.sceneStartPos.clone().add(o).project(a.camera),s=n.clone(),l=r.clone().sub(n);l.normalize();var d=new THREE.Vector3(a.dragstart.mousePos.x,a.dragstart.mousePos.y,0),c=new THREE.Vector3(a.mouse.x,a.mouse.y,0),h=(new THREE.Vector3).subVectors(c,d).dot(l),u=l.clone().multiplyScalar(h).add(s);u.unproject(a.camera);var p=a.sceneRoot.position.clone().sub(u);p.multiply(new THREE.Vector3(-1,-1,1)).addScalar(1);for(var m=0;m<a.targets.length;m++){var v=a.targets[m],E=a.dragstart.scales[m];v.scale.copy(E).add(p),v.scale.x=Math.max(v.scale.x,.01),v.scale.y=Math.max(v.scale.y,.01),v.scale.z=Math.max(v.scale.z,.01)}t.event.stopImmediatePropagation()},p=function(){i.color.set(t)};return n.addEventListener("mousemove",c),n.addEventListener("mouseleave",h),n.addEventListener("mousedrag",u),n.addEventListener("drop",p),l.addEventListener("mousemove",c),l.addEventListener("mouseleave",h),l.addEventListener("mousedrag",u),l.addEventListener("drop",p),d},this.createArrow=function(e,t){var o=new THREE.MeshBasicMaterial({color:t,depthTest:!1,depthWrite:!1}),i=new THREE.Geometry;i.vertices.push(new THREE.Vector3(0,0,0)),i.vertices.push(new THREE.Vector3(0,3,0));var n=new THREE.LineBasicMaterial({color:t,depthTest:!1,depthWrite:!1}),r=new THREE.Line(i,n),s=new THREE.CylinderGeometry(0,.2,.5,10,1,!1),l=o,d=new THREE.Mesh(s,l);d.position.y=3;var c=new THREE.Object3D;c.add(r),c.add(d),c.partID=e,c.material=o;var h=function(){l.color.setRGB(1,1,0),n.color.setRGB(1,1,0)},u=function(){l.color.set(t),n.color.set(t)},p=function(t){var o=new THREE.Vector3;e===a.parts.ARROW_X?o.x=1:e===a.parts.ARROW_Y?o.y=1:e===a.parts.ARROW_Z&&(o.z=-1);var i=a.dragstart.sceneClickPos.clone();i.multiply(o),i.z*=-1;var n=a.dragstart.sceneStartPos.clone().project(a.camera),r=a.dragstart.sceneStartPos.clone().add(o).project(a.camera),s=n.clone(),l=r.clone().sub(n);l.normalize();var d=new THREE.Vector3(a.dragstart.mousePos.x,a.dragstart.mousePos.y,0),c=new THREE.Vector3(a.mouse.x,a.mouse.y,0),h=(new THREE.Vector3).subVectors(c,d).dot(l),u=l.clone().multiplyScalar(h).add(s);u.unproject(a.camera);{var p=a.sceneRoot.position.clone();i.clone().sub(a.dragstart.sceneStartPos)}a.sceneRoot.position.copy(u),p.sub(a.sceneRoot.position);for(var m=0;m<a.targets.length;m++){var v=a.targets[m];v.position.sub(p)}t.event.stopImmediatePropagation()},m=function(){n.color.set(t)};return r.addEventListener("mousemove",h),d.addEventListener("mousemove",h),r.addEventListener("mouseleave",u),d.addEventListener("mouseleave",u),r.addEventListener("mousedrag",p),d.addEventListener("mousedrag",p),r.addEventListener("drop",m),d.addEventListener("drop",m),c},this.setTargets=function(e){if(a.targets=e,0===a.targets.length)return this.sceneRoot.visible=!1,void(this.sceneRotation.visible=!1);this.sceneRoot.visible=!0;var t,o=e[0];if(t=o.geometry&&o.geometry.boundingBox?o.geometry.boundingBox:o.boundingBox){var i=t.clone().applyMatrix4(o.matrixWorld).center();a.sceneRoot.position.copy(i)}},this.update=function(){var e=this.sceneRoot,o=e.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),i=(new THREE.Vector4(o.x,o.y,o.z).applyMatrix4(t.projectionMatrix),Math.abs(o.z/20));e.scale.set(i,i,i),this.targets&&1===this.targets.length&&this.scaleNode.rotation.copy(this.targets[0].rotation),this.sceneRotation.scale.set(i,i,i)},this.render=function(){this.update(),this.sceneRotation.position.copy(this.sceneRoot.position),this.sceneRotation.visible=this.rotationNode.visible&&this.sceneRoot.visible,o.render(this.sceneRotation,this.camera),o.render(this.sceneTransformation,this.camera)},this.translate=function(){this.translationNode.visible=!0,this.scaleNode.visible=!1,this.rotationNode.visible=!1},this.scale=function(){this.translationNode.visible=!1,this.scaleNode.visible=!0,this.rotationNode.visible=!1},this.rotate=function(){this.translationNode.visible=!1,this.scaleNode.visible=!1,this.rotationNode.visible=!0},this.buildTranslationNode(),this.buildScaleNode(),this.buildRotationNode(),this.rotate(),this.setTargets([]),this.domElement.addEventListener("mousemove",i,!0),this.domElement.addEventListener("mousedown",n,!0),this.domElement.addEventListener("mouseup",r,!0)},Potree.VolumeTool=function(e,t,o){function i(){THREE.Object3D.call(this),this._clip=!1,this.dimension=new THREE.Vector3(1,1,1);var e=new THREE.MeshBasicMaterial({color:65280,transparent:!0,opacity:.3});this.box=new THREE.Mesh(p,e),this.box.geometry.computeBoundingBox(),this.boundingBox=this.box.geometry.boundingBox,this.add(this.box),this.frame=new THREE.Line(m,new THREE.LineBasicMaterial({color:0})),this.frame.mode=THREE.LinePieces,this.add(this.frame),this.label=new Potree.TextSprite("0"),this.label.setBorderColor({r:0,g:255,b:0,a:0}),this.label.setBackgroundColor({r:0,g:255,b:0,a:0}),this.label.material.depthTest=!1,this.label.position.y-=.5,this.add(this.label);var t=this;this.label.updateMatrixWorld=function(){var e=new THREE.Vector3;e.setFromMatrixPosition(t.matrixWorld),t.label.position.copy(e),t.label.updateMatrix(),t.label.matrixWorld.copy(t.label.matrix),t.label.matrixWorldNeedsUpdate=!1;for(var o=0,i=t.label.children.length;i>o;o++)t.label.children[o].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.dimension.x*this.dimension.y*this.dimension.z)},this.update=function(){this.boundingBox=this.box.geometry.boundingBox},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()})}}}function n(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 r(){}function s(e){if(u!==h.DEFAULT&&e.stopImmediatePropagation(),u===h.INSERT_VOLUME)c.finishInsertion();else if(1===e.which){var t=l();t&&transformationTool.setTargets([t.object])}3===e.which}function a(e){return e.preventDefault(),!1}function l(){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;i<c.volumes.length;i++){var n=c.volumes[i];o.push(n)}var r=t.intersectObjects(o,!1);return r.length>0?r[0]:!1}function d(){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;s<i.length;s++){var a=i[s],l=a.pick(c.renderer,c.camera,o);if(l){var d=c.camera.position.distanceTo(l.position);(!n||r>d)&&(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 h={DEFAULT:0,INSERT_VOLUME:1},u=h.DEFAULT,p=new THREE.BoxGeometry(1,1,1);p.computeBoundingBox();var m=new THREE.Geometry;m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),i.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(i.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)}}),this.update=function(){if(u===h.INSERT_VOLUME){var e=d();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.setDimension(o,o,o)}}for(var i=[],n=0;n<this.volumes.length;n++)i.push(this.volumes[n]);this.activeVolume&&i.push(this.activeVolume);for(var n=0;n<i.length;n++){var r=i[n],s=(r.box,r.label),a=r.volume(),l=Potree.utils.addCommas(a.toFixed(1))+"³",t=s.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),o=(new THREE.Vector4(t.x,t.y,t.z).applyMatrix4(this.camera.projectionMatrix),Math.abs(t.z/5));s.setText(l);var c=s.scale.length();s.scale.multiplyScalar(o/c)}},this.startInsertion=function(e){u=h.INSERT_VOLUME;var e=e||{},t=e.clip||!1;this.activeVolume=new i,this.activeVolume.clip=t,this.sceneVolume.add(this.activeVolume)},this.finishInsertion=function(){this.volumes.push(this.activeVolume),transformationTool.setTargets([this.activeVolume]),this.activeVolume=null,u=h.DEFAULT},this.render=function(){o.render(this.sceneVolume,this.camera)},this.domElement.addEventListener("click",r,!1),this.domElement.addEventListener("mousedown",s,!1),this.domElement.addEventListener("mousemove",n,!1),this.domElement.addEventListener("contextmenu",a,!1)};