diff --git a/build/js/potree.js b/build/js/potree.js index 295d78da..fd9f0fa0 100644 --- a/build/js/potree.js +++ b/build/js/potree.js @@ -1167,6 +1167,11 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ } geometry.addAttribute("indices", new THREE.BufferAttribute(new Float32Array(data.indices), 1)); + if(!geometry.attributes.normal){ + var buffer = new Float32Array(numPoints*3); + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3)); + } + geometry.boundingBox = node.boundingBox; node.geometry = geometry; node.loaded = true; @@ -1387,7 +1392,8 @@ Potree.LasLazBatcher = function(node){ geometry.addAttribute('returnNumber', new THREE.BufferAttribute(new Float32Array(returnNumbers_f), 1)); geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(new Float32Array(pointSourceIDs_f), 1)); geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 1)); - //geometry.boundingBox = node.boundingBox; + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3)); + geometry.boundingBox = new THREE.Box3(mins, maxs); node.boundingBox = geometry.boundingBox; @@ -4751,13 +4757,6 @@ Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params) _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.UNSIGNED_BYTE, true, 0, 0 ); _gl.uniform1f(material.program.uniforms.pcIndex, material.pcIndex); - - // TODO: another ugly hack...disable normal attributes, if they're activated - var alNormal = _gl.getAttribLocation(program, "normal"); - if(alNormal >= 0){ - _gl.disableVertexAttribArray( alNormal ); - } - } renderer.renderBufferDirect(camera, [], null, material, geometry, object); @@ -6583,7 +6582,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ this.render = function(){ this.update(); - renderer.render(this.sceneMeasurement, this.camera); + this.renderer.render(this.sceneMeasurement, this.camera); }; this.domElement.addEventListener( 'click', onClick, false); @@ -8949,12 +8948,6 @@ Potree.PointCloudArena4D.prototype.pick = function(renderer, camera, ray, params _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.UNSIGNED_BYTE, true, 0, 0 ); _gl.uniform1f(material.program.uniforms.pcIndex, material.pcIndex); - - // TODO: another ugly hack...disable normal attributes, if they're activated - var alNormal = _gl.getAttribLocation(program, "normal"); - if(alNormal >= 0){ - _gl.disableVertexAttribArray( alNormal ); - } } renderer.renderBufferDirect(camera, [], null, material, geometry, object); @@ -9212,6 +9205,7 @@ Potree.PointCloudArena4DGeometryNode.prototype.load = function(){ geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3)); geometry.addAttribute("color", new THREE.BufferAttribute(colors, 3)); geometry.addAttribute("indices", new THREE.BufferAttribute(indices, 1)); + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3)); scope.geometry = geometry; scope.loaded = true; diff --git a/build/js/potree.min.js b/build/js/potree.min.js index 746fa8a9..5d9c084d 100644 --- a/build/js/potree.min.js +++ b/build/js/potree.min.js @@ -1,5 +1,5 @@ function Potree(){}function POCLoader(){}function PointAttribute(e,t,i){this.name=e,this.type=t,this.numElements=i,this.byteSize=this.numElements*this.type.size}function PointAttributes(e){if(this.attributes=new Array,this.byteSize=0,this.size=0,null!=e)for(var t=0;tu)&&(s=h,l=u)}}return s?s.position:null}function pixelsArrayToImage(e,t,i){var o=document.createElement("canvas");o.width=t,o.height=i;var n=o.getContext("2d");e=new e.constructor(e);for(var r=0;r 0",""," uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];"," uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];"," uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",""," #endif",""," #if MAX_DIR_LIGHTS > 0",""," uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];"," uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",""," #endif","","#endif","","//#if MAX_SPOT_LIGHTS > 0","//","// uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];","// uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];","// uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];","// uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];","// uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];","//","// uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];","//","//#endif","","uniform float fov;","uniform float spacing;","uniform float near;","uniform float far;","uniform float pcIndex;","uniform float screenWidth;","uniform float screenHeight;","uniform float blendDepth;","","uniform sampler2D depthMap;","","varying vec3 vColor;","varying float vOpacity;","varying float vLinearDepth;","varying float vDepth;","varying vec3 vViewPosition;","varying float vRadius;","varying vec3 vWorldPosition;","varying vec3 vNormal;","","float specularStrength = 1.0;","","void main() {",""," #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats)"," float u = 2.0 * gl_PointCoord.x - 1.0;"," float v = 2.0 * gl_PointCoord.y - 1.0;"," #endif"," "," #if defined(circle_point_shape) || defined (weighted_splats)"," float cc = u*u + v*v;"," if(cc > 1.0){"," discard;"," }"," #endif"," "," #if defined weighted_splats"," vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight);"," float depth = texture2D(depthMap, uv).r;"," if(vLinearDepth > depth + vRadius * 0.5){"," discard;"," }"," #endif"," "," #if defined use_interpolation"," float w = 1.0 - ( u*u + v*v);"," vec4 pos = vec4(-vViewPosition, 1.0);"," pos.z += w * vRadius;"," pos = projectionMatrix * pos;"," pos = pos / pos.w;"," gl_FragDepthEXT = (pos.z + 1.0) / 2.0;"," #endif"," "," #if defined color_type_point_index"," gl_FragColor = vec4(vColor, pcIndex / 255.0);"," #else"," gl_FragColor = vec4(vColor, vOpacity);"," #endif"," "," #if defined weighted_splats"," float w = pow(1.0 - (u*u + v*v), 2.0);"," gl_FragColor.rgb = gl_FragColor.rgb * w;"," gl_FragColor.a = w;"," #endif"," "," vec3 normal = normalize( vNormal );"," normal.z = abs(normal.z);"," vec3 viewPosition = normalize( vViewPosition );"," "," #if defined(color_type_phong)",""," // code taken from three.js phong light fragment shader"," "," #if MAX_POINT_LIGHTS > 0",""," vec3 pointDiffuse = vec3( 0.0 );"," vec3 pointSpecular = vec3( 0.0 );",""," for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",""," vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );"," vec3 lVector = lPosition.xyz + vViewPosition.xyz;",""," float lDistance = 1.0;"," if ( pointLightDistance[ i ] > 0.0 )"," lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",""," lVector = normalize( lVector );",""," // diffuse",""," float dotProduct = dot( normal, lVector );",""," #ifdef WRAP_AROUND",""," float pointDiffuseWeightFull = max( dotProduct, 0.0 );"," float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",""," vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",""," #else",""," float pointDiffuseWeight = max( dotProduct, 0.0 );",""," #endif",""," pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;",""," // specular",""," vec3 pointHalfVector = normalize( lVector + viewPosition );"," float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );"," float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );",""," float specularNormalization = ( shininess + 2.0 ) / 8.0;",""," vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );"," pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;"," pointSpecular = vec3(0.0, 0.0, 0.0);"," }"," "," #endif"," "," #if MAX_DIR_LIGHTS > 0",""," vec3 dirDiffuse = vec3( 0.0 );"," vec3 dirSpecular = vec3( 0.0 );",""," for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",""," vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );"," vec3 dirVector = normalize( lDirection.xyz );",""," // diffuse",""," float dotProduct = dot( normal, dirVector );",""," #ifdef WRAP_AROUND",""," float dirDiffuseWeightFull = max( dotProduct, 0.0 );"," float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",""," vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );",""," #else",""," float dirDiffuseWeight = max( dotProduct, 0.0 );",""," #endif",""," dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;",""," // specular",""," vec3 dirHalfVector = normalize( dirVector + viewPosition );"," float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );"," float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );",""," float specularNormalization = ( shininess + 2.0 ) / 8.0;",""," vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );"," dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;"," }",""," #endif"," "," vec3 totalDiffuse = vec3( 0.0 );"," vec3 totalSpecular = vec3( 0.0 );"," "," #if MAX_POINT_LIGHTS > 0",""," totalDiffuse += pointDiffuse;"," totalSpecular += pointSpecular;",""," #endif"," "," #if MAX_DIR_LIGHTS > 0",""," totalDiffuse += dirDiffuse;"," totalSpecular += dirSpecular;",""," #endif"," "," gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",""," #endif"," ","}","","",""].join("\n"),THREE.PerspectiveCamera.prototype.zoomTo=function(e,t){if(e.geometry||e.boundingSphere){e.geometry&&null===e.geometry.boundingSphere&&e.geometry.computeBoundingSphere(),e.updateMatrixWorld();var i=t||1,o=e.boundingSphere||e.geometry.boundingSphere;o=o.clone().applyMatrix4(e.matrixWorld);var n=o.radius,r=this.fov*Math.PI/180;this.aspect<1&&(r*=this.aspect);var a=Math.abs(n/Math.sin(r/2))*i,s=new THREE.Vector3(0,0,-1).applyQuaternion(this.quaternion),l=s.multiplyScalar(-a);this.position.copy(o.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 i=-(this.origin.dot(e.normal)+e.constant)/t;return i},POCLoader.load=function(e,t){try{var i=new Potree.PointCloudOctreeGeometry;i.url=e;var o=new XMLHttpRequest;o.open("GET",e,!0),o.onreadystatechange=function(){if(4===o.readyState&&(200===o.status||0===o.status)){var n=JSON.parse(o.responseText),r=new Potree.Version(n.version);i.octreeDir=0===n.octreeDir.indexOf("http")?n.octreeDir:e+"/../"+n.octreeDir,i.spacing=n.spacing,i.hierarchyStepSize=n.hierarchyStepSize,i.pointAttributes=n.pointAttributes; -var a=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),l=new THREE.Box3(a,s),d=l.clone();n.tightBoundingBox&&(d.min.copy(new THREE.Vector3(n.tightBoundingBox.lx,n.tightBoundingBox.ly,n.tightBoundingBox.lz)),d.max.copy(new THREE.Vector3(n.tightBoundingBox.ux,n.tightBoundingBox.uy,n.tightBoundingBox.uz)));var c=new THREE.Vector3(0,0,0);c.set(-a.x,-a.y,-a.z),l.min.add(c),l.max.add(c),d.min.add(c),d.max.add(c),i.boundingBox=l,i.tightBoundingBox=d,i.boundingSphere=l.getBoundingSphere(),i.tightBoundingSphere=d.getBoundingSphere(),i.offset=c,"LAS"===n.pointAttributes?i.loader=new Potree.LasLazLoader(n.version):"LAZ"===n.pointAttributes?i.loader=new Potree.LasLazLoader(n.version):(i.loader=new Potree.BinaryLoader(n.version,l,n.scale),i.pointAttributes=new PointAttributes(i.pointAttributes));var h={},u="r",p=new Potree.PointCloudOctreeGeometryNode(u,i,l);if(p.level=0,p.hasChildren=!0,p.numPoints=r.upTo("1.5")?n.hierarchy[0][1]:0,i.root=p,i.root.load(),h[u]=p,r.upTo("1.4"))for(var m=1;m=n?i.pointsCount:i.pointsCount/n,s=function(){var e=t.readData(1e6,0,n);return e.then(function(e){return o.push(new LASDecoder(e.buffer,i.pointsFormatId,i.pointsStructSize,e.count,i.scale,i.offset,i.mins,i.maxs)),r+=e.count,Potree.LasLazLoader.progressCB(r/a),e.hasMoreData?s():(i.totalRead=r,i.versionAsString=t.versionAsString,i.isCompressed=t.isCompressed,[t,i,o])})};return s()}).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(i.isOpen)return i.close().then(function(){throw i.isOpen=!1,e});throw e})},Potree.LasLazLoader.prototype.handle=function(){},Potree.LasLazBatcher=function(e){this.push=function(t){var i=Potree.workers.lasdecoder.getWorker(),o=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]);o.add(e.pcoGeometry.offset),n.add(e.pcoGeometry.offset),i.onmessage=function(r){for(var a=new THREE.BufferGeometry,s=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),f=new Uint16Array(r.data.pointSourceID),v=new Float32Array(f.length),g=new ArrayBuffer(4*s),E=new Uint32Array(g),y=new THREE.Box3,b=new Float32Array(l),T=0;s>T;T++)u[T]=h[T],m[T]=p[T],v[T]=f[T],E[T]=T,y.expandByPoint(new THREE.Vector3(b[3*T+0],b[3*T+1],b[3*T+2]));a.addAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),a.addAttribute("color",new THREE.BufferAttribute(new Float32Array(d),3)),a.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(c),1)),a.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(u),1)),a.addAttribute("returnNumber",new THREE.BufferAttribute(new Float32Array(m),1)),a.addAttribute("pointSourceID",new THREE.BufferAttribute(new Float32Array(v),1)),a.addAttribute("indices",new THREE.BufferAttribute(g,1)),a.boundingBox=new THREE.Box3(o,n),e.boundingBox=a.boundingBox,e.geometry=a,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(i)};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]};i.postMessage(r,[r.buffer])}},Potree.Gradients={RAINBOW:[[0,new THREE.Color(.278,0,.714)],[1/6,new THREE.Color(0,0,1)],[2/6,new THREE.Color(0,1,1)],[.5,new THREE.Color(0,1,0)],[4/6,new THREE.Color(1,1,0)],[5/6,new THREE.Color(1,.64,0)],[1,new THREE.Color(1,0,0)]],GRAYSCALE:[[0,new THREE.Color(0,0,0)],[1,new THREE.Color(1,1,1)]]},Potree.Classification={DEFAULT:{0:new THREE.Color(.5,.5,.5),1:new THREE.Color(.5,.5,.5),2:new THREE.Color(.63,.32,.18),3:new THREE.Color(0,1,0),4:new THREE.Color(0,.8,0),5:new THREE.Color(0,.6,0),6:new THREE.Color(1,.66,0),7:new THREE.Color(1,0,1),8:new THREE.Color(1,0,0),9:new THREE.Color(0,0,1),12:new THREE.Color(1,1,0),DEFAULT:new THREE.Color(.3,.6,.6)}},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,TREE_DEPTH:6,POINT_INDEX:7,CLASSIFICATION:8,RETURN_NUMBER:9,SOURCE:10,NORMAL:11,PHONG:12,TREE_DEPTH:13},Potree.ClipMode={DISABLED:0,CLIP_OUTSIDE:1,HIGHLIGHT_INSIDE:2},Potree.TreeType={OCTREE:0,KDTREE:1},Potree.PointCloudMaterial=function(e){e=e||{};var t=new THREE.Color(0),i=THREE.ImageUtils.generateDataTexture(2048,1,t);i.magFilter=THREE.NearestFilter,this.visibleNodesTexture=i;var o=e.size||1,n=e.minSize||1,r=e.maxSize||50,a=e.treeType||Potree.TreeType.OCTREE,s=1;this._pointSizeType=Potree.PointSizeType.ATTENUATED,this._pointShape=Potree.PointShape.SQUARE,this._interpolate=!1,this._pointColorType=Potree.PointColorType.RGB,this._levels=6,this._useClipBox=!1,this.numClipBoxes=0,this._clipMode=Potree.ClipMode.DISABLED,this._weighted=!1,this._blendDepth=.1,this._depthMap,this._gradient=Potree.Gradients.RAINBOW,this._classification=Potree.Classification.DEFAULT,this.gradientTexture=Potree.PointCloudMaterial.generateGradientTexture(this._gradient),this.classificationTexture=Potree.PointCloudMaterial.generateClassificationTexture(this._classification),this.lights=!0,this._treeType=a;var l={},d={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},maxSize:{type:"f",value:2},nodeSize:{type:"f",value:s},bbSize:{type:"fv",value:[0,0,0]},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},classificationLUT:{type:"t",value:this.classificationTexture},clipBoxes:{type:"Matrix4fv",value:[]},blendDepth:{type:"f",value:this._blendDepth},depthMap:{type:"t",value:null},diffuse:{type:"fv",value:[1,1,1]},ambient:{type:"fv",value:[.1,.1,.1]},ambientLightColor:{type:"fv",value:[1,1,1]},directionalLightColor:{type:"fv",value:null},directionalLightDirection:{type:"fv",value:null},pointLightColor:{type:"fv",value:null},pointLightPosition:{type:"fv",value:null},pointLightDistance:{type:"fv1",value:null},spotLightColor:{type:"fv",value:null},spotLightPosition:{type:"fv",value:null},spotLightDistance:{type:"fv1",value:null},spotLightDirection:{type:"fv",value:null},spotLightAngleCos:{type:"fv1",value:null},spotLightExponent:{type:"fv1",value:null},hemisphereLightSkyColor:{type:"fv",value:null},hemisphereLightGroundColor:{type:"fv",value:null},hemisphereLightDirection:{type:"fv",value:null}};this.defaultAttributeValues.normal=[0,0,0],this.setValues({uniforms:d,attributes:l,vertexShader:this.getDefines()+Potree.Shaders["pointcloud.vs"],fragmentShader:this.getDefines()+Potree.Shaders["pointcloud.fs"],vertexColors:THREE.VertexColors,size:o,minSize:n,maxSize:r,nodeSize:s,pcIndex:0,alphaTest:.9})},Potree.PointCloudMaterial.prototype=new THREE.ShaderMaterial,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.pointColorType===Potree.PointColorType.NORMAL||this.pointColorType===Potree.PointColorType.PHONG)&&(e.normal={type:"f",value:[]});var t=this.getDefines()+Potree.Shaders["pointcloud.vs"],i=this.getDefines()+Potree.Shaders["pointcloud.fs"];this.setValues({attributes:e,vertexShader:t,fragmentShader:i}),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 levels "+Math.max(0,this._levels-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.TREE_DEPTH?e+="#define color_type_tree_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._pointColorType===Potree.PointColorType.NORMAL?e+="#define color_type_normal\n":this._pointColorType===Potree.PointColorType.PHONG&&(e+="#define color_type_phong\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._treeType===Potree.TreeType.OCTREE?e+="#define tree_type_octree\n":this._treeType===Potree.TreeType.KDTREE&&(e+="#define tree_type_kdtree\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 i=0;t>i;i++){var o=e[i];this.uniforms.clipBoxes.value.set(o.elements,16*i)}},Object.defineProperty(Potree.PointCloudMaterial.prototype,"gradient",{get:function(){return this._gradient},set:function(e){this._gradient!==e&&(this._gradient=e,this.gradientTexture=Potree.PointCloudMaterial.generateGradientTexture(this._gradient),this.uniforms.gradient.value=this.gradientTexture)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"classification",{get:function(){return this._classification},set:function(e){this._classification!==e&&(this._classification=e,this.classificationTexture=Potree.PointCloudMaterial.generateClassificationTexture(this._classification),this.uniforms.classificationLUT.value=this.classificationTexture)}}),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,"levels",{get:function(){return this._levels},set:function(e){this._levels!==e&&(this._levels=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,"maxSize",{get:function(){return this.uniforms.maxSize.value},set:function(e){this.uniforms.maxSize.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}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"treeType",{get:function(){return this._treeType},set:function(e){this._treeType!=e&&(this._treeType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"bbSize",{get:function(){return this.uniforms.bbSize.value},set:function(e){this.uniforms.bbSize.value=e}}),Potree.PointCloudMaterial.generateGradientTexture=function(e){var t=64;canvas=document.createElement("canvas"),canvas.width=t,canvas.height=t;var i=canvas.getContext("2d");i.rect(0,0,t,t);for(var o=i.createLinearGradient(0,0,t,t),n=0;nr;r++)for(var a=0;i>a;a++){var s,l=r+t*a;s=e[r]?e[r]:e.DEFAULT,n[3*l+0]=255*s.r,n[3*l+1]=255*s.g,n[3*l+2]=255*s.b}return o},THREE.FirstPersonControls=function(e,t){function i(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",o,!1),l.domElement.addEventListener("mouseup",n,!1),l.dispatchEvent(x))}function o(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",o,!1),l.domElement.removeEventListener("mouseup",n,!1),l.dispatchEvent(C),R=T.NONE)}function r(e){if(l.enabled!==!1&&l.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1;l.moveSpeed+=.1*l.moveSpeed*t,l.moveSpeed=Math.max(.1,l.moveSpeed),l.dispatchEvent(x),l.dispatchEvent(C)}}function a(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 s(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,f=new THREE.Vector3,v=(new THREE.Vector3,0),g=0,E=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"},x={type:"start"},C={type:"end"};this.rotateLeft=function(e){g-=e},this.rotateUp=function(e){v-=e},this.panLeft=function(e){var t=this.object.matrix.elements;f.set(t[0],t[1],t[2]),f.multiplyScalar(-e),y.add(f)},this.panUp=function(e){var t=this.object.matrix.elements;f.set(t[4],t[5],t[6]),f.multiplyScalar(e),y.add(f)},this.panForward=function(e){var t=this.object.matrix.elements;f.set(t[8],t[9],t[10]),f.multiplyScalar(e),y.add(f)},this.pan=function(e,t){var i=l.domElement===document?l.domElement.body:l.domElement;if(void 0!==l.object.fov){var o=l.object.position,n=o.clone(),r=n.length();r*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*r/i.clientHeight),l.panUp(2*t*r/i.clientHeight)}else void 0!==l.object.top?(l.panLeft(e*(l.object.right-l.object.left)/i.clientWidth),l.panUp(t*(l.object.top-l.object.bottom)/i.clientHeight)):console.warn("WARNING: FirstPersonControls.js encountered an unknown camera type - pan disabled.")},this.update=function(e){this.object.rotation.order="ZYX";var t=this.object;this.object=new THREE.Object3D,this.object.position.copy(t.position),this.object.rotation.copy(t.rotation),this.object.updateMatrix(),this.object.updateMatrixWorld();var i=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(i.add(y),0!==g||0!==v){var o={type:"rotate",thetaDelta:g,phiDelta:v};this.dispatchEvent(o)}this.object.updateMatrix();var n=(new THREE.Matrix4).makeRotationY(g),r=(new THREE.Matrix4).multiplyMatrices(n,this.object.matrix);this.object.quaternion.setFromRotationMatrix(r),this.object.rotation.x+=v,this.object.updateMatrixWorld();var a={type:"proposeTransform",oldPosition:t.position,newPosition:this.object.position,objections:0,counterProposals:[]};if(this.dispatchEvent(a),a.objections>0&&a.counterProposals.length>0){var s=a.counterProposals;this.object.position.copy(s[0]),a.objections=0,a.counterProposals=[]}a.objections>0||t.position.copy(this.object.position),t.rotation.copy(this.object.rotation),this.object=t,g=0,v=0,E=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",i,!1),this.domElement.addEventListener("mousewheel",r,!1),this.domElement.addEventListener("DOMMouseScroll",r,!1),window.addEventListener("keydown",a,!1),window.addEventListener("keyup",s,!1)},THREE.FirstPersonControls.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.OrbitControls=function(e,t){function i(){return 2*Math.PI/60/60*u.autoRotateSpeed}function o(){return Math.pow(.95,u.zoomSpeed)}function n(e){if(u.enabled!==!1){if(e.preventDefault(),0===e.button){if(u.noRotate===!0)return;V=A.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(u.noZoom===!0)return;V=A.DOLLY,R.set(e.clientX,e.clientY)}else if(2===e.button){if(u.noPan===!0)return;V=A.PAN,g.set(e.clientX,e.clientY)}u.domElement.addEventListener("mousemove",r,!1),u.domElement.addEventListener("mouseup",a,!1),u.dispatchEvent(I)}}function r(e){if(u.enabled!==!1){e.preventDefault();var t=u.domElement===document?u.domElement.body:u.domElement;if(V===A.ROTATE){if(u.noRotate===!0)return;f.set(e.clientX,e.clientY),v.subVectors(f,m),u.rotateLeft(2*Math.PI*v.x/t.clientWidth*u.rotateSpeed),u.rotateUp(2*Math.PI*v.y/t.clientHeight*u.rotateSpeed),m.copy(f)}else if(V===A.DOLLY){if(u.noZoom===!0)return;P.set(e.clientX,e.clientY),x.subVectors(P,R),x.y>0?u.dollyIn():u.dollyOut(),R.copy(P)}else if(V===A.PAN){if(u.noPan===!0)return;E.set(e.clientX,e.clientY),y.subVectors(E,g),u.pan(y.x,y.y),g.copy(E)}}}function a(){u.enabled!==!1&&(u.domElement.removeEventListener("mousemove",r,!1),u.domElement.removeEventListener("mouseup",a,!1),u.dispatchEvent(L),V=A.NONE)}function s(e){if(u.enabled!==!1&&u.noZoom!==!0){e.preventDefault();var t=0;void 0!==e.wheelDelta?t=e.wheelDelta:void 0!==e.detail&&(t=-e.detail),t>0?u.dollyOut():u.dollyIn(),u.dispatchEvent(I),u.dispatchEvent(L)}}function l(e){if(u.enabled!==!1&&u.noKeys!==!0&&u.noPan!==!0)switch(e.keyCode){case u.keys.UP:u.pan(0,u.keyPanSpeed); -break;case u.keys.BOTTOM:u.pan(0,-u.keyPanSpeed);break;case u.keys.LEFT:u.pan(u.keyPanSpeed,0);break;case u.keys.RIGHT:u.pan(-u.keyPanSpeed,0)}}function d(e){if(u.enabled!==!1){switch(e.touches.length){case 1:if(u.noRotate===!0)return;V=A.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(u.noZoom===!0)return;V=A.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,i=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(t*t+i*i);R.set(0,o);break;case 3:if(u.noPan===!0)return;V=A.TOUCH_PAN,g.set(e.touches[0].pageX,e.touches[0].pageY);break;default:V=A.NONE}u.dispatchEvent(I)}}function c(e){if(u.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=u.domElement===document?u.domElement.body:u.domElement;switch(e.touches.length){case 1:if(u.noRotate===!0)return;if(V!==A.TOUCH_ROTATE)return;f.set(e.touches[0].pageX,e.touches[0].pageY),v.subVectors(f,m),u.rotateLeft(2*Math.PI*v.x/t.clientWidth*u.rotateSpeed),u.rotateUp(2*Math.PI*v.y/t.clientHeight*u.rotateSpeed),m.copy(f);break;case 2:if(u.noZoom===!0)return;if(V!==A.TOUCH_DOLLY)return;var i=e.touches[0].pageX-e.touches[1].pageX,o=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(i*i+o*o);P.set(0,n),x.subVectors(P,R);var r=t.clientWidth,a=t.clientHeight,s=Math.sqrt(r*r+a*a),l=x.y/s;x.y>0?u.dollyOut(1-l):u.dollyIn(1+l),R.copy(P);break;case 3:if(u.noPan===!0)return;if(V!==A.TOUCH_PAN)return;E.set(e.touches[0].pageX,e.touches[0].pageY),y.subVectors(E,g),u.pan(y.x,y.y),g.copy(E);break;default:V=A.NONE}}}function h(){u.enabled!==!1&&(u.dispatchEvent(L),V=A.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.fadeFactor=10,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var u=this,p=1e-6,m=new THREE.Vector2,f=new THREE.Vector2,v=new THREE.Vector2,g=new THREE.Vector2,E=new THREE.Vector2,y=new THREE.Vector2,b=new THREE.Vector3,T=new THREE.Vector3,R=new THREE.Vector2,P=new THREE.Vector2,x=new THREE.Vector2,C=0,w=0,H=1,S=new THREE.Vector3,M=new THREE.Vector3,A={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},V=A.NONE;this.target0=this.target.clone(),this.position0=this.object.position.clone();var B={type:"change"},I={type:"start"},L={type:"end"};this.rotateLeft=function(e){void 0===e&&(e=i()),w-=e},this.rotateUp=function(e){void 0===e&&(e=i()),C-=e},this.panLeft=function(e){var t=this.object.matrix.elements;b.set(t[0],t[1],t[2]),b.multiplyScalar(-e),S.add(b)},this.panUp=function(e){var t=this.object.matrix.elements;b.set(t[4],t[5],t[6]),b.multiplyScalar(e),S.add(b)},this.pan=function(e,t){var i=u.domElement===document?u.domElement.body:u.domElement;if(void 0!==u.object.fov){var o=u.object.position,n=o.clone().sub(u.target),r=n.length();r*=Math.tan(u.object.fov/2*Math.PI/180),u.panLeft(2*e*r/i.clientHeight),u.panUp(2*t*r/i.clientHeight)}else void 0!==u.object.top?(u.panLeft(e*(u.object.right-u.object.left)/i.clientWidth),u.panUp(t*(u.object.top-u.object.bottom)/i.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=o()),H/=e},this.dollyOut=function(e){void 0===e&&(e=o()),H*=e},this.update=function(e){var t=this.object.position.clone();T.copy(t).sub(this.target);var o=Math.atan2(T.x,T.z),n=Math.atan2(Math.sqrt(T.x*T.x+T.z*T.z),T.y);this.autoRotate&&this.rotateLeft(i());var r=Math.min(1,this.fadeFactor*e);o+=r*w,n+=r*C,n=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,n)),n=Math.max(p,Math.min(Math.PI-p,n));var a=T.length();a+=(H-1)*a*r,a=Math.max(this.minDistance,Math.min(this.maxDistance,a)),this.target.add(S.clone().multiplyScalar(r)),T.x=a*Math.sin(n)*Math.sin(o),T.y=a*Math.cos(n),T.z=a*Math.sin(n)*Math.cos(o),t.copy(this.target).add(T);var s={type:"proposeTransform",oldPosition:this.object.position,newPosition:t,objections:0,counterProposals:[]};if(this.dispatchEvent(s),s.objections>0&&s.counterProposals.length>0){var l=s.counterProposals;t.copy(l[0]),s.objections=0,s.counterProposals=[]}if(s.objections>0)w=0,C=0,H=1,S.set(0,0,0);else{this.object.position.copy(t),this.object.lookAt(this.target);var d=Math.max(0,1-this.fadeFactor*e);w*=d,C*=d,H=1+(H-1)*d,S.multiplyScalar(d)}M.distanceTo(this.object.position)>0&&(this.dispatchEvent(B),M.copy(this.object.position))},this.reset=function(){V=A.NONE,this.target.copy(this.target0),this.object.position.copy(this.position0),this.update()},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",n,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1),this.domElement.addEventListener("touchstart",d,!1),this.domElement.addEventListener("touchend",h,!1),this.domElement.addEventListener("touchmove",c,!1),window.addEventListener("keydown",l,!1)},Potree.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype),THREE.EarthControls=function(e,t,i){function o(e){if(s.enabled!==!1){e.preventDefault();var t=s.domElement.getBoundingClientRect(),i={x:(e.clientX-t.left)/s.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/s.domElement.clientHeight)+1},o=getMousePointCloudIntersection(i,s.camera,s.renderer,s.pointclouds);if(o){var a=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),o),u=new THREE.Vector3(i.x,i.y,.5);u.unproject(s.camera);var p=u.sub(s.camera.position).normalize(),m=new THREE.Ray(s.camera.position,p);v=m.intersectPlane(a),f=s.camera.clone(),f.rotation.copy(s.camera.rotation),c.set(e.clientX-t.left,e.clientY-t.top),h.set(e.clientX-t.left,e.clientY-t.top),s.scene.add(s.pivotNode),s.pivotNode.position.copy(v),0===e.button?d=l.DRAG:2===e.button&&(d=l.ROTATE),s.domElement.addEventListener("mousemove",n,!1),s.domElement.addEventListener("mouseup",r,!1)}}}function n(e){if(s.enabled!==!1){e.preventDefault();{var t=s.domElement.getBoundingClientRect();s.domElement===document?s.domElement.body:s.domElement}m.set(e.clientX-t.left-h.x,e.clientY-t.top-h.y),h.set(e.clientX-t.left,e.clientY-t.top)}}function r(){s.enabled!==!1&&(s.domElement.removeEventListener("mousemove",n,!1),s.domElement.removeEventListener("mouseup",r,!1),d=l.NONE,s.scene.remove(s.pivotNode))}function a(e){if(s.enabled!==!1&&s.noZoom!==!0){e.preventDefault();var t=s.domElement.getBoundingClientRect(),i=e.detail<0||e.wheelDelta>0?1:-1,o={x:(e.clientX-t.left)/s.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/s.domElement.clientHeight)+1},n=getMousePointCloudIntersection(o,s.camera,s.renderer,s.pointclouds);if(n){var r=n.distanceTo(s.camera.position),a=(new THREE.Vector3).subVectors(n,s.camera.position).normalize();s.camera.position.add(a.multiplyScalar(.1*r*i))}}}this.camera=e,this.renderer=t,this.pointclouds=[],this.domElement=t.domElement,this.scene=i,this.enabled=!0;var s=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,f=null,v=null;this.minAngle=10/180*Math.PI,this.maxAngle=70/180*Math.PI,this.update=function(e){this.camera.position;this.camera.updateMatrixWorld();var t=new THREE.Object3D;if(t.position.copy(this.camera.position),t.rotation.copy(this.camera.rotation),t.updateMatrix(),t.updateMatrixWorld(),v){if(d===l.DRAG){var i=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),v),o={x:h.x/this.domElement.clientWidth*2-1,y:2*-(h.y/this.domElement.clientHeight)+1},n=new THREE.Vector3(o.x,o.y,.5);n.unproject(f);var r=n.sub(f.position).normalize(),a=new THREE.Ray(f.position,r),s=a.distanceToPlane(i);if(s>0){var c=(new THREE.Vector3).subVectors(v,r.clone().multiplyScalar(s));t.position.copy(c)}}else if(d===l.ROTATE){var u=m.clone().multiplyScalar(e);u.x*=.3,u.y*=.2;var p=new THREE.Object3D,g=new THREE.Object3D;p.add(g),p.position.copy(v),g.position.copy(this.camera.position).sub(v),g.rotation.copy(this.camera.rotation),p.rotation.y+=-u.x;var r=this.camera.getWorldDirection(),E=new THREE.Vector3(0,1,0),y=(new THREE.Vector3).crossVectors(E,r),b=g.position.clone();b.y=0,b.normalize();var T=b.dot(g.position.clone().normalize()),R=Math.acos(T);g.position.y<0&&(R=-R);var P=0;P=u.y>0?u.y-Math.max(0,this.minAngle-(R-u.y)):u.y+Math.max(0,R-u.y-this.maxAngle),p.rotateOnAxis(y,-P),p.updateMatrixWorld(),t.position.copy(g.getWorldPosition()),t.quaternion.copy(g.getWorldQuaternion())}var x={type:"proposeTransform",oldPosition:this.camera.position,newPosition:t.position,objections:0};this.dispatchEvent(x),x.objections>0||(this.camera.position.copy(t.position),this.camera.rotation.copy(t.rotation));var C=this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),w=Math.abs(C.z/30),H=this.pivotNode.scale.length();this.pivotNode.scale.multiplyScalar(w/H)}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",o,!1),this.domElement.addEventListener("mousewheel",a,!1),this.domElement.addEventListener("DOMMouseScroll",a,!1)},THREE.EarthControls.prototype=Object.create(THREE.EventDispatcher.prototype),LRU.prototype.size=function(){return this.elements},LRU.prototype.contains=function(e){return null==this.items[e.id]},LRU.prototype.touch=function(e){if(e.loaded){var t;null==this.items[e.id]?(t=new LRUItem(e),t.previous=this.last,this.last=t,null!==t.previous&&(t.previous.next=t),this.items[e.id]=t,this.elements++,null===this.first&&(this.first=t),this.numPoints+=e.numPoints):(t=this.items[e.id],null===t.previous?null!==t.next&&(this.first=t.next,this.first.previous=null,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t):null===t.next||(t.previous.next=t.next,t.next.previous=t.previous,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t))}},LRU.prototype.remove=function(e){var t=this.items[e.id];t&&(1===this.elements?(this.first=null,this.last=null):(t.previous||(this.first=t.next,this.first.previous=null),t.next||(this.last=t.previous,this.last.next=null),t.previous&&t.next&&(t.previous.next=t.next,t.next.previous=t.previous)),delete this.items[e.id],this.elements--,this.numPoints-=e.numPoints)},LRU.prototype.getLRUItem=function(){if(null===this.first)return null;var e=this.first;return e.node},LRU.prototype.toString=function(){for(var e="{ ",t=this.first;null!==t;)e+=t.node.id,null!==t.next&&(e+=", "),t=t.next;return e+="}",e+="("+this.size()+")"},LRU.prototype.freeMemory=function(){if(!(this.elements<=1))for(;this.numPoints>Potree.pointLoadLimit;){var e=this.first,t=e.node;this.disposeDescendants(t)}},LRU.prototype.disposeDescendants=function(e){var t=[];for(t.push(e);t.length>0;){var i=t.pop();i.dispose(),this.remove(i);for(var o in i.children)if(i.children.hasOwnProperty(o)){var n=i.children[o];n.loaded&&t.push(i.children[o])}}},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,i,o,n){this.start=e,this.end=t,this.width=i,this.depth=o,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()),a=new THREE.Vector3(0,1,0),s=(new THREE.Vector3).crossVectors(r,a).normalize(),l=s;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.minimumNodePixelSize=150,this.level=0,this.position.sub(e.offset),this.updateMatrix(),this.LODDistance=20,this.LODFalloff=1.3,this.LOD=4,this.showBoundingBox=!1,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleBounds=new THREE.Box3,this.profileRequests=[],this.visibleNodes=[],this.visibleGeometry=[],this.pickTarget,this.pickMaterial,this.maxLevel=0,this.generateDEM=!1;var i=new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);this.add(i)},Potree.PointCloudOctree.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudOctree.prototype.updateVisibleBounds=function(){for(var e=[],t=0;t0;){var r=n.shift();if(r instanceof Potree.PointCloudOctreeProxyNode){var a=Potree.utils.computeTransformedBoundingBox(r.boundingBox,r.matrixWorld),s=a.getBoundingSphere();Math.abs(i.distanceToPoint(s.center))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-1&&this.profileRequests.splice(m,1)}},Potree.PointCloudOctree.prototype.updatePointCloud=function(e,t,i,o){if(this.numVisibleNodes++,this.numVisiblePoints+=e.numPoints,e.material=this.material,this.visibleNodes.push(t),e.level&&(this.maxLevel=Math.max(e.level,this.maxLevel)),this.showBoundingBox&&!e.boundingBoxNode){var n=new THREE.BoxHelper(e);this.add(n),this.boundingBoxNodes.push(n),e.boundingBoxNode=n,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)}else this.showBoundingBox?(e.boundingBoxNode.visible=!0,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)):!this.showBoundingBox&&e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);this.generateDEM&&e.level<=2&&(e.dem||(e.dem=this.createDEM(e)));for(var r=0;r=0;if(s)for(var l=0;l0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0;){{var a=r.shift(),s=a.node;a.weight}if(s.visible=!0,s.matrixWorld.multiplyMatrices(s.parent.matrixWorld,s.matrix),s instanceof Potree.PointCloudOctreeProxyNode){var l=s.geometryNode;l.loaded===!0?this.replaceProxy(s):this.loadQueue.push(a)}else if(s instanceof THREE.PointCloud)if(s.pcoGeometry.loaded)Potree.PointCloudOctree.lru.touch(s.pcoGeometry),this.updatePointCloud(s,a,r,i);else{var d=new Potree.PointCloudOctreeProxyNode(s.pcoGeometry),c=s.parent;c.remove(s),c.add(d)}}this.updateProfileRequests(),this.updateVisibleBounds(),this.updateLoadQueue(),this.hideDescendants(this.children[0]);for(var h=[],o=0;o0;){y++;var b=m.shift(),T=b.node,R=T.boundingBox,v=T.boundingSphere,P=n.intersectsBox(R),x=P;if(x){if(f+T.numPoints>this.visiblePointsTarget)break;f+=T.numPoints,i.push(b);for(var C=0;8>C;C++)if(T.children[C]){var w=T.children[C],v=w.boundingSphere,g=v.center.distanceTo(u),H=v.radius,E=v.radius/g,S=e.fov/2*Math.PI/180,M=1/Math.tan(S)*H/Math.sqrt(g*g-H*H),A=t.domElement.clientHeight*M;if(!(Ag-H&&(E=Number.MAX_VALUE),0===m.length)m.push({node:w,weight:E});else{for(var V=0,B=0;Bm[B].weight){var V=B;break}if(B==m.length-1){V=m.length;break}}m.splice(V,0,{node:w,weight:E})}}}}return i},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(e,t){if(e){var i=e.visibleNodesTexture,o=i.image.data;t=t.slice();var n=function(e,t){var i=e.name,o=t.name;return i.length!=o.length?i.length-o.length:o>i?-1:i>o?1:0};t.sort(n);for(var r={},a=0;at.name?1:0}),o[3*a+0]=0,o[3*a+1]=0,o[3*a+2]=0;for(var d=0;dr;r++)if(void 0!==t.children[r]){var a=t.children[r],s=new Potree.PointCloudOctreeProxyNode(a);o.add(s)}return o}},Potree.PointCloudOctree.prototype.hideDescendants=function(e){for(var t=[],i=0;i0;){var e=t.shift();e.visible=!1;for(var i=0;i0&&(l=-l),function(e){var t=(new THREE.Matrix4).makeTranslation(-o.x,-o.y,-o.z),i=(new THREE.Matrix4).makeRotationY(-l),n=(new THREE.Matrix4).makeTranslation(r,0,0),a=e.clone();return a.applyMatrix4(t),a.applyMatrix4(i),a.applyMatrix4(n),a}}(r,a,o),d={start:r,end:a,points:s,project:l};i.push(d),o+=r.distanceTo(a)}return i},Potree.PointCloudOctree.prototype.getProfile=function(e,t,i,o,n){if(void 0===n){var r=[];r.push(this);for(var a=(new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),s=(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,a),m=null;r.length>0;){var f=r.shift(),v=0;if(f instanceof THREE.PointCloud){var g=f.geometry,E=g.attributes.position,y=E.array,b=f.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 x=Math.abs(u.distanceToPoint(P)),C=Math.abs(p.distanceToPoint(P));if(i/2>x&&s/2>C){for(var T in g.attributes)if(g.attributes.hasOwnProperty(T))if("position"===T)m[T].push(P);else if("indices"===T);else{var w=g.attributes[T];if(1===w.itemSize)m[T].push(w.array[R+S]);else{for(var H=[],S=0;S0&&(a=-a),function(e){var t=(new THREE.Matrix4).makeTranslation(-i.x,-i.y,-i.z),o=(new THREE.Matrix4).makeRotationY(-a),n=e.clone();return n.applyMatrix4(t),n.applyMatrix4(o),n}}(e,t);return m.project=V,m}this.profileRequests.push(new Potree.ProfileRequest(e,t,i,o,n))},Potree.PointCloudOctree.prototype.getVisibleExtent=function(){return this.visibleBounds.applyMatrix4(this.matrixWorld)},Potree.PointCloudOctree.prototype.pick=function(e,t,i,o){var o=o||{},n=o.pickWindowSize||17,r=this.nodesOnRay(this.visibleNodes,i);if(0===r.length)return null;var a=Math.ceil(e.domElement.clientWidth),s=Math.ceil(e.domElement.clientHeight),l=(new THREE.Vector3).addVectors(t.position,i.direction).project(t);l.addScalar(1).multiplyScalar(.5),l.x*=a,l.y*=s,this.pickTarget?(this.pickTarget.width!=a||this.pickTarget.height!=s)&&(this.pickTarget.dispose(),this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat})):this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat}),this.pickTarget.setSize(a,s),this.pickMaterial||(this.pickMaterial=new Potree.PointCloudMaterial,this.pickMaterial.pointColorType=Potree.PointColorType.POINT_INDEX,this.pickMaterial.pointSizeType=Potree.PointSizeType.FIXED),this.pickMaterial.pointSizeType=this.material.pointSizeType,this.pickMaterial.size=this.material.size,this.pickMaterial.pointSizeType===Potree.PointSizeType.ADAPTIVE&&this.updateVisibilityTexture(this.pickMaterial,r),this.pickMaterial.fov=this.material.fov,this.pickMaterial.screenWidth=this.material.screenWidth,this.pickMaterial.screenHeight=this.material.screenHeight,this.pickMaterial.spacing=this.material.spacing,this.pickMaterial.near=this.material.near,this.pickMaterial.far=this.material.far,this.pickMaterial.octreeLevels=this.material.octreeLevels,this.pickMaterial.pointShape=this.material.pointShape;var 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=0&&d.disableVertexAttribArray(g)}e.renderBufferDirect(t,[],null,c,p,u)}}var E=n*n,y=new ArrayBuffer(4*E),b=new Uint8Array(y),T=new Uint32Array(y);e.context.readPixels(l.x-(n-1)/2,l.y-(n-1)/2,n,n,e.context.RGBA,e.context.UNSIGNED_BYTE,b);for(var R=Number.MAX_VALUE,P=null,x=0;n>x;x++)for(var C=0;n>C;C++){var w=x+C*n,H=Math.pow(x-(n-1)/2,2)+Math.pow(C-(n-1)/2,2),S=b[4*w+3];b[4*w+3]=0;var M=T[w];(0!==M||0!==S)&&R>H&&(P={pIndex:M,pcIndex:S},R=H)}if(P){var A={},V=r[P.pcIndex],B=V.geometry.attributes;for(var I in B)if(B.hasOwnProperty(I)){var L=p.attributes[I];if("position"===I){var G=V.geometry.attributes.position.array,W=G[3*P.pIndex+0],N=G[3*P.pIndex+1],O=G[3*P.pIndex+2],_=new THREE.Vector3(W,N,O);_.applyMatrix4(this.matrixWorld),A[I]=_}else if("indices"===I);else if(1===L.itemSize)A[I]=L.array[h+z];else{for(var D=[],z=0;zc;c++){var h=r[3*c+0],u=r[3*c+1],p=r[3*c+2],m=new THREE.Vector3(h,u,p).applyMatrix4(i),f=parseInt(a*(m.x-o.min.x)/n.x),v=parseInt(a*(m.z-o.min.z)/n.z);f=Math.min(f,a-1),v=Math.min(v,a-1);var g=f+v*a;s[g]||(s[g]=[]),s[g].push(m.y)}for(var c=0;c.5&&r.x.5&&r.y0;){{var r=n.shift(),a=r.dem,s=(a.demSize,a.boundingBox2D);s.containsPoint(t)}if(s.containsPoint(t)){var l=i(a);if(o?null!=l&&l>0&&(o=l):o=l,r.level<=2)for(var d=0;da;a++)for(var s=0;i>s;s++){var l=a/t,d=s/i,c=l*e.size().x+e.min.x,h=d*e.size().z+e.min.z,u=this.getDEMHeight(new THREE.Vector3(c,0,h));u||(u=0),n[r+0]=c,n[r+1]=u,n[r+2]=h,r+=3}o.addAttribute("position",new THREE.BufferAttribute(n,3));var p=new THREE.PointCloudMaterial({size:20,color:65280}),m=new THREE.PointCloud(o,p);scene.add(m)},Object.defineProperty(Potree.PointCloudOctree.prototype,"progress",{get:function(){return this.visibleNodes.length/this.visibleGeometry.length}});var nodesLoadTimes={};Potree.PointCloudOctreeGeometry=function(){Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.url=null,this.octreeDir=null,this.spacing=0,this.boundingBox=null,this.root=null,this.numNodesLoading=0,this.nodes=null,this.pointAttributes=null,this.hierarchyStepSize=-1,this.loader=null},Potree.PointCloudOctreeGeometryNode=function(e,t,i){this.id=Potree.PointCloudOctreeGeometryNode.IDCount++,this.name=e,this.index=parseInt(e.charAt(e.length-1)),this.pcoGeometry=t,this.geometry=null,this.boundingBox=i,this.boundingSphere=i.getBoundingSphere(),this.children={},this.numPoints=0,this.level=null},Potree.PointCloudOctreeGeometryNode.IDCount=0,Potree.PointCloudOctreeGeometryNode.prototype.getURL=function(){var e="",t=this.pcoGeometry.loader.version;return t.equalOrHigher("1.5")?e=this.pcoGeometry.octreeDir+"/"+this.getHierarchyPath()+"/"+this.name:t.equalOrHigher("1.4")?e=this.pcoGeometry.octreeDir+"/"+this.name:t.upTo("1.3")&&(e=this.pcoGeometry.octreeDir+"/"+this.name),e},Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath=function(){for(var e="r/",t=this.pcoGeometry.hierarchyStepSize,i=this.name.substr(1),o=Math.floor(i.length/t),n=0;o>n;n++)e+=i.substr(n*t,t)+"/";return e=e.slice(0,-1)},Potree.PointCloudOctreeGeometryNode.prototype.addChild=function(e){this.children[e.index]=e,e.parent=this},Potree.PointCloudOctreeGeometryNode.prototype.load=function(){this.loading===!0||this.pcoGeometry.numNodesLoading>3||(this.loading=!0,this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.version.equalOrHigher("1.5")&&this.level%this.pcoGeometry.hierarchyStepSize===0&&this.hasChildren?this.loadHierachyThenPoints():this.loadPoints())},Potree.PointCloudOctreeGeometryNode.prototype.loadPoints=function(){this.pcoGeometry.loader.load(this)},Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints=function(){var e=this,t=function(e,t){var i=(t.byteLength/5,new DataView(t)),o=[],n=i.getUint8(0),r=i.getUint32(1,!0); -e.numPoints=r,o.push({children:n,numPoints:r,name:e.name});for(var a=[],s=5;o.length>0;){for(var l=o.shift(),d=1,c=0;8>c;c++){if(0!==(l.children&d)){var h=l.name+c,u=i.getUint8(s),p=i.getUint32(s+1,!0);o.push({children:u,numPoints:p,name:h}),a.push({children:u,numPoints:p,name:h}),s+=5}d=2*d}if(s===t.byteLength)break}var m={};m[e.name]=e;for(var f=e.pcoGeometry,c=0;c0,y.addChild(R),m[v]=R}e.loadPoints()};if(e.level%e.pcoGeometry.hierarchyStepSize===0){var i=e.pcoGeometry.octreeDir+"/"+e.getHierarchyPath()+"/"+e.name+".hrc",o=new XMLHttpRequest;o.open("GET",i,!0),o.responseType="arraybuffer",o.overrideMimeType("text/plain; charset=x-user-defined"),o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status||0===o.status){var i=o.response;t(e,i)}else console.log("Failed to load file! HTTP status: "+o.status+", file: "+url)};try{o.send(null)}catch(n){console.log("fehler beim laden der punktwolke: "+n)}}},Potree.PointCloudOctreeGeometryNode.prototype.dispose=function(){this.geometry&&(this.geometry.dispose(),this.geometry=null,this.loaded=!1)},Potree.utils=function(){},Potree.utils.pathExists=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),200!==t.status?!1:!0},Potree.utils.computeTransformedBoundingBox=function(e,t){var i=[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)],o=new THREE.Box3;return o.setFromPoints(i),o},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"}),i=new Worker(URL.createObjectURL(t));return i},Potree.utils.loadSkybox=function(e){var t=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,1,1e5),i=new THREE.Scene,o=".jpg",n=[e+"px"+o,e+"nx"+o,e+"py"+o,e+"ny"+o,e+"pz"+o,e+"nz"+o],r=THREE.ImageUtils.loadTextureCube(n,THREE.CubeRefractionMapping),a={uniforms:{tCube:{type:"t",value:r},tFlip:{type:"f",value:-1}},vertexShader:THREE.ShaderLib.cube.vertexShader,fragmentShader:THREE.ShaderLib.cube.fragmentShader},s=new THREE.ShaderMaterial({fragmentShader:a.fragmentShader,vertexShader:a.vertexShader,uniforms:a.uniforms,depthWrite:!1,side:THREE.BackSide}),l=new THREE.Mesh(new THREE.BoxGeometry(100,100,100),s);return i.add(l),{camera:t,scene:i}},Potree.utils.createGrid=function(e,t,i,o){for(var n=new THREE.LineBasicMaterial({color:o||8947848}),r=new THREE.Geometry,a=0;t>=a;a++)r.vertices.push(new THREE.Vector3(-(i*e)/2,0,a*i-i*t/2)),r.vertices.push(new THREE.Vector3(+(i*e)/2,0,a*i-i*t/2));for(var a=0;e>=a;a++)r.vertices.push(new THREE.Vector3(a*i-i*e/2,0,-(i*t)/2)),r.vertices.push(new THREE.Vector3(a*i-i*e/2,0,+(i*t)/2));var s=new THREE.Line(r,n,THREE.LinePieces);return s.receiveShadow=!0,s},Potree.utils.createBackgroundTexture=function(e,t){function i(e,t){return 1/(2*Math.PI)*Math.exp(-(e*e+t*t)/2)}var o=THREE.ImageUtils.generateDataTexture(e,t,new THREE.Color);o.magFilter=THREE.NearestFilter;for(var n=o.image.data,r=[1,1.5,1.7],a=i(0,0),s=0;e>s;s++)for(var l=0;t>l;l++){var d=2*(s/e)-1,c=2*(l/t)-1,h=s+e*l,u=i(2*d,2*c)/a,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 o},Potree.utils.topView=function(e,t,i){if(e.position.set(0,1,0),e.rotation.set(-Math.PI/2,0,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(e.position.x,o.center.y,e.position.z);t.target.copy(n)}},Potree.utils.frontView=function(e,t,i){if(e.position.set(0,0,1),e.rotation.set(0,0,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(e.position.x,e.position.y,o.center.z);t.target.copy(n)}},Potree.utils.leftView=function(e,t,i){if(e.position.set(-1,0,0),e.rotation.set(0,-Math.PI/2,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(o.center.x,e.position.y,e.position.z);t.target.copy(n)}},Potree.utils.rightView=function(e,t,i){if(e.position.set(1,0,0),e.rotation.set(0,Math.PI/2,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(o.center.x,e.position.y,e.position.z);t.target.copy(n)}},Potree.utils.frustumSphereIntersection=function(e,t){for(var i=e.planes,o=t.center,n=-t.radius,r=Number.MAX_VALUE,a=0;6>a;a++){var s=i[a].distanceToPoint(o);if(n>s)return 0;r=Math.min(r,s)}return r>=t.radius?2:1},Potree.Features=function(){var e,t=document.createElement("canvas"),i=t.getContext("webgl")||t.getContext("experimental-webgl"),o=i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.HIGH_FLOAT),n=i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT),r=(i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.LOW_FLOAT),i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT)),a=i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT),s=(i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.LOW_FLOAT),o.precision>0&&r.precision>0),l=n.precision>0&&a.precision>0;return e=s?"highp":l?"mediump":"lowp",{SHADER_INTERPOLATION:{isSupported:function(){var e=!0;return e=e&&i.getExtension("EXT_frag_depth"),e=e&&i.getParameter(i.MAX_VARYING_VECTORS)>=8}},SHADER_SPLATS:{isSupported:function(){var e=!0;return e=e&&i.getExtension("EXT_frag_depth"),e=e&&i.getExtension("OES_texture_float"),e=e&&i.getParameter(i.MAX_VARYING_VECTORS)>=8}},precision:e}}(),Potree.TextSprite=function(e){THREE.Object3D.call(this);var t=new THREE.Texture;t.minFilter=THREE.LinearFilter,t.magFilter=THREE.LinearFilter;var i=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});this.material=i,this.sprite=new THREE.Sprite(i),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 i=t.measureText(this.text),o=i.width,n=o+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,o+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 a=new THREE.Texture(e);a.minFilter=THREE.LinearFilter,a.magFilter=THREE.LinearFilter,a.needsUpdate=!0,this.sprite.material.map=a,this.sprite.scale.set(.01*n,.01*r,1)},Potree.TextSprite.prototype.roundRect=function(e,t,i,o,n,r){e.beginPath(),e.moveTo(t+r,i),e.lineTo(t+o-r,i),e.quadraticCurveTo(t+o,i,t+o,i+r),e.lineTo(t+o,i+n-r),e.quadraticCurveTo(t+o,i+n,t+o-r,i+n),e.lineTo(t+r,i+n),e.quadraticCurveTo(t,i+n,t,i+n-r),e.lineTo(t,i+r),e.quadraticCurveTo(t,i,t+r,i),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.Measure=function(){var e=this;THREE.Object3D.call(this),this.points=[],this._showDistances=!0,this._showArea=!0,this._closed=!0,this.maxMarkers=Number.MAX_SAFE_INTEGER,this.spheres=[],this.edges=[],this.sphereLabels=[],this.edgeLabels=[],this.angleLabels=[],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,this.add(this.areaLabel);var t=new THREE.SphereGeometry(.4,10,10);this.color=new THREE.Color(16711680);var i=function(){var t=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:e.color,ambient:11184810,depthTest:!1,depthWrite:!1});return t},o=function(e){e.target.material.emissive.setHex(8947848)},n=function(e){e.target.material.emissive.setHex(0)},r=function(t){var i=t.tool,o=(i.dragstart,i.mouse,i.getMousePointCloudIntersection());if(o){var n=e.spheres.indexOf(i.dragstart.object);e.setPosition(n,o)}},a=function(){};this.addMarker=function(e){this.points.push(e);var s=new THREE.Mesh(t,i());s.addEventListener("move",o),s.addEventListener("leave",n),s.addEventListener("drag",r),s.addEventListener("drop",a),this.add(s),this.spheres.push(s);var l=new THREE.Geometry;l.vertices.push(new THREE.Vector3,new THREE.Vector3),l.colors.push(this.color,this.color,this.color);var d=new THREE.LineBasicMaterial({linewidth:1});d.depthTest=!1;var c=new THREE.Line(l,d);c.visible=!0,this.add(c),this.edges.push(c);var h=new Potree.TextSprite(0);h.setBorderColor({r:0,g:255,b:0,a:0}),h.setBackgroundColor({r:0,g:255,b:0,a:0}),h.material.depthTest=!1,h.visible=!1,this.edgeLabels.push(h),this.add(h);var u=new Potree.TextSprite;u.setBorderColor({r:0,g:255,b:0,a:0}),u.setBackgroundColor({r:0,g:255,b:0,a:0}),u.material.depthTest=!1,u.material.opacity=1,u.visible=!1,this.angleLabels.push(u),this.add(u);var p={type:"marker_added",measurement:this};this.dispatchEvent(p),this.setPosition(this.points.length-1,e)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]);var t=0==e?0:e-1;this.remove(this.edges[t]),this.edges.splice(t,1),this.remove(this.edgeLabels[t]),this.edgeLabels.splice(t,1),this.spheres.splice(e,1),this.update()},this.setPosition=function(e,t){var i=this.points[e];i.copy(t);var o={type:"marker_moved",measure:this,index:e,position:t.clone()};this.dispatchEvent(o),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,i=0;i=n;n++){var t=this.points[n];o.add(t)}o.divideScalar(this.points.length);for(var n=0;i>=n;n++){var r=n,a=n+1>i?0:n+1,s=0===n?i:n-1,t=this.points[r],l=this.points[a],d=this.points[s],c=this.spheres[r];c.position.copy(t),c.material.color=e.color;var h=this.edges[r];h.material.color=this.color,h.geometry.vertices[0].copy(t),h.geometry.vertices[1].copy(l),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere(),h.visible=i>r||this.closed;var u=this.edgeLabels[n],p=(new THREE.Vector3).add(t);p.add(l),p=p.multiplyScalar(.5);var m=t.distanceTo(l);u.position.copy(p),u.setText(m.toFixed(2)),u.visible=this.showDistances&&(i>r||this.closed)&&this.points.length>=2&&m>0;var f=this.angleLabels[n],v=this.getAngleBetweenLines(t,d,l),g=l.clone().sub(d);g.multiplyScalar(.5),g=d.clone().add(g).sub(t).normalize();var E=Math.min(t.distanceTo(d),t.distanceTo(l));E/=9;var y=t.clone().add(g.multiplyScalar(E));f.position.copy(y);var b=Potree.utils.addCommas((v*(180/Math.PI)).toFixed(1))+"°";f.setText(b),f.visible=this.showAngles&&(i>r||this.closed)&&this.points.length>=3&&v>0}this.areaLabel.position.copy(o),this.areaLabel.visible=this.showArea&&this.points.length>=3;var b=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(b)}},this.raycast=function(e,t){for(var i=0;ic.activeMeasurement.maxMarkers&&c.finishInsertion()}}}function n(e){var t=c.domElement.getBoundingClientRect();if(c.mouse.x=(e.clientX-t.left)/c.domElement.clientWidth*2-1,c.mouse.y=2*-((e.clientY-t.top)/c.domElement.clientHeight)+1,c.dragstart){var i={type:"drag",event:e,tool:c};c.dragstart.object.dispatchEvent(i)}else if(u==h.INSERT&&c.activeMeasurement){var o=c.getMousePointCloudIntersection();if(o){var n=c.activeMeasurement.points.length-1;c.activeMeasurement.setPosition(n,o)}}else{var o=d();o?(o.object.dispatchEvent({type:"move",target:o.object,event:e}),c.hoveredElement&&c.hoveredElement!==o.object&&c.hoveredElement.dispatchEvent({type:"leave",target:c.hoveredElement,event:e}),c.hoveredElement=o.object):(c.hoveredElement&&c.hoveredElement.dispatchEvent({type:"leave",target:c.hoveredElement,event:e}),c.hoveredElement=null)}}function r(){u==h.INSERT&&c.finishInsertion()}function a(e){if(1===e.which){u!==h.DEFAULT&&e.stopImmediatePropagation();var t=d();t&&(c.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:c.sceneRoot.position.clone(),mousePos:{x:c.mouse.x,y:c.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&r(e)}function s(){window.getSelection?window.getSelection().removeAllRanges():document.selection&&document.selection.empty(),c.activeMeasurement&&u===h.INSERT&&(c.activeMeasurement.removeMarker(c.activeMeasurement.points.length-1),c.finishInsertion())}function l(e){c.dragstart&&(c.dragstart.object.dispatchEvent({type:"drop",event:e}),c.dragstart=null)}function d(){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 i=[],o=0;o0?a[0]:!1}var c=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=i,this.domElement=i.domElement,this.mouse={x:0,y:0};var h={DEFAULT:0,INSERT:1},u=h.DEFAULT;this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null,this.getState=function(){return u},this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),i=new THREE.Ray(c.camera.position,t),o=[];c.scene.traverse(function(e){(e instanceof Potree.PointCloudOctree||e instanceof Potree.PointCloudArena4D)&&o.push(e)});for(var n=null,r=null,a=0;ad)&&(n=l,r=d)}}return n?n.position:null},this.startInsertion=function(e){u=h.INSERT;var e=e||{},t="undefined"!=typeof e.showDistances?e.showDistances:!0,i="undefined"!=typeof e.showArea?e.showArea:!1,o="undefined"!=typeof e.showAngles?e.showAngles:!1,n="undefined"!=typeof e.closed?e.closed:!1,r=e.maxMarkers||Number.MAX_SAFE_INTEGER,a=new Potree.Measure;a.showDistances=t,a.showArea=i,a.showAngles=o,a.closed=n,a.maxMarkers=r,this.addMeasurement(a),a.addMarker(new THREE.Vector3(0,0,0)),this.activeMeasurement=a},this.finishInsertion=function(){this.activeMeasurement.removeMarker(this.activeMeasurement.points.length-1);var e={type:"insertion_finished",measurement:this.activeMeasurement};this.dispatchEvent(e),this.activeMeasurement=null,u=h.DEFAULT},this.addMeasurement=function(e){this.sceneMeasurement.add(e),this.measurements.push(e),this.dispatchEvent({type:"measurement_added",measurement:e}),e.addEventListener("marker_added",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_removed",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_moved",function(e){c.dispatchEvent(e)})},this.removeMeasurement=function(e){this.sceneMeasurement.remove(e);var t=this.measurements.indexOf(e);t>=0&&this.measurements.splice(t,1)},this.reset=function(){for(var e=this.measurements.length-1;e>=0;e--){var t=this.measurements[e];this.removeMeasurement(t)}},this.update=function(){for(var e=[],t=0;t1){var d=new THREE.Geometry;d.vertices.push(new THREE.Vector3,new THREE.Vector3),d.colors.push(i,i,i);var c=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2,transparent:!0,opacity:.4});c.depthTest=!1;var h=new THREE.Line(d,c);h.visible=!1,this.add(h),this.edges.push(h);var u=new THREE.BoxGeometry(1,1,1),p=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),m=new THREE.Mesh(u,p);m.visible=!1,this.add(m),this.boxes.push(m)}var f={type:"marker_added",profile:this};this.dispatchEvent(f),this.setPosition(this.points.length-1,e)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]);var t=0==e?0:e-1;this.remove(this.edges[t]),this.edges.splice(t,1),this.remove(this.boxes[t]),this.boxes.splice(t,1),this.spheres.splice(e,1),this.update();var i={type:"marker_removed",profile:this};this.dispatchEvent(i)},this.getArea=function(){for(var e=0,t=this.points.length-1,i=0;i=r;r++){{var e=this.points[r],a=this.spheres[r],s=0===r?n:r-1,l=r===n?0:r+1,d=this.points[s],c=this.points[l],h=this.edges[s],u=this.edges[r],p=this.boxes[s];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(a.position.copy(e),a.visible=this._modifiable?!0:!1,h&&(h.geometry.vertices[1].copy(e),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere()),u&&(u.geometry.vertices[0].copy(e),u.geometry.verticesNeedUpdate=!0,u.geometry.computeBoundingSphere()),p){var m=d,f=e,v=m.clone().setY(0).distanceTo(f.clone().setY(0));p.scale.set(v,this.height,this.width);var g=(new THREE.Vector3).addVectors(m,f).multiplyScalar(.5),E=(new THREE.Vector3).subVectors(f,m),y=new THREE.Vector3(E.z,0,-E.x);p.position.set(0,0,0),p.lookAt(y),p.position.copy(g)}o.add(e),t.min(e),i.max(e)}o.multiplyScalar(1/this.points.length);for(var r=0;r0?i[0]:!1}var c=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=i,this.domElement=i.domElement,this.mouse={x:0,y:0};{var h={DEFAULT:0,INSERT:1},u=h.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeProfile,this.profiles=[],this.sceneProfile=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneProfile.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneProfile.add(this.light),this.hoveredElement=null,this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),i=new THREE.Ray(c.camera.position,t),o=[];c.scene.traverse(function(e){(e instanceof Potree.PointCloudOctree||e instanceof Potree.PointCloudArena4D)&&o.push(e)});for(var n=null,r=null,a=0;ad)&&(n=l,r=d)}}return n?n.position:null},this.startInsertion=function(e){u=h.INSERT;var e=e||{},t=e.clip||!1,i=e.width||1;return this.activeProfile=new Potree.HeightProfile,this.activeProfile.clip=t,this.activeProfile.setWidth(i),this.addProfile(this.activeProfile),this.activeProfile.addMarker(new THREE.Vector3(0,0,0)),this.activeProfile},this.finishInsertion=function(){this.activeProfile.removeMarker(this.activeProfile.points.length-1);var e={type:"insertion_finished",profile:this.activeProfile};this.dispatchEvent(e),this.activeProfile=null,u=h.DEFAULT},this.addProfile=function(e){this.profiles.push(e),this.sceneProfile.add(e),e.update(),this.dispatchEvent({type:"profile_added",profile:e}),e.addEventListener("marker_added",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_removed",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_moved",function(e){c.dispatchEvent(e)})},this.removeProfile=function(e){this.sceneProfile.remove(e);var t=this.profiles.indexOf(e);t>=0&&this.profiles.splice(t,1),this.dispatchEvent({type:"profile_removed",profile:e})},this.reset=function(){for(var e=this.profiles.length-1;e>=0;e--){var t=this.profiles[e];this.removeProfile(t)}},this.update=function(){for(var e=0;e0?o[0]:!1}}var s=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=i,this.domElement=i.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=s.createArrow(s.parts.ARROW_X,s.parts.ARROW_X.color); -e.rotation.z=-Math.PI/2;var t=s.createArrow(s.parts.ARROW_Y,s.parts.ARROW_Y.color),i=s.createArrow(s.parts.ARROW_Z,s.parts.ARROW_Z.color);i.rotation.x=-Math.PI/2,this.translationNode.add(e),this.translationNode.add(t),this.translationNode.add(i)},this.buildScaleNode=function(){var e=this.createScaleHandle(s.parts.SCALE_X,16711680);e.rotation.z=-Math.PI/2;var t=this.createScaleHandle(s.parts.SCALE_Y,65280),i=this.createScaleHandle(s.parts.SCALE_Z,255);i.rotation.x=-Math.PI/2,this.scaleNode.add(e),this.scaleNode.add(t),this.scaleNode.add(i)},this.buildRotationNode=function(){var e=this.createRotationCircle(s.parts.ROTATE_X,16711680);e.rotation.y=-Math.PI/2;var t=this.createRotationCircle(s.parts.ROTATE_Y,65280),i=this.createRotationCircle(s.parts.ROTATE_Z,255);t.rotation.x=-Math.PI/2,this.rotationNode.add(e),this.rotationNode.add(t),this.rotationNode.add(i);var o=new THREE.SphereGeometry(2.9,24,24),n=new THREE.Mesh(o,new THREE.MeshBasicMaterial({color:11184810,transparent:!0,opacity:.4}));this.sceneRotation.add(n);var r=function(){n.material.color.setHex(5592405)},a=function(){n.material.color.setHex(11184810)},l=function(e){e.event.stopImmediatePropagation();for(var t=new THREE.Vector3(s.dragstart.mousePos.x,s.dragstart.mousePos.y,.1),i=new THREE.Vector3(s.mouse.x,s.mouse.y,.1),o=(new THREE.Vector3).subVectors(i,t),n=t.clone().unproject(s.camera),r=i.clone().unproject(s.camera),a=(new THREE.Vector3).subVectors(r,n),l=a.clone().normalize(),d=(new THREE.Vector3).subVectors(s.camera.position,n).normalize(),c=d.clone().cross(l),h=6*o.length(),u=0;u=n;n++){var r=2*Math.PI*n/o,a=3*Math.cos(r),l=3*Math.sin(r);i.push(new THREE.Vector3(a,l,0))}for(var d=new THREE.Geometry,n=0;nt;t++)n.label.children[t].updateMatrixWorld(!0)},this.setDimension=function(e,t,i){this.dimension.set(e,t,i),this.box.scale.set(e,t,i),this.frame.scale.set(e,t,i)},this.volume=function(){return Math.abs(this.scale.x*this.scale.y*this.scale.z)},this.update=function(){this.boundingBox=this.box.geometry.boundingBox,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)},this.raycast=function(e,t){var i=[];if(this.box.raycast(e,i),i.length>0){var o=i[0];t.push({distance:o.distance,object:this,point:o.point.clone()})}},this.update()},Potree.Volume.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(Potree.Volume.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this.update()}}),Object.defineProperty(Potree.Volume.prototype,"modifiable",{get:function(){return this._modifiable},set:function(e){this._modifiable=e,this.update()}}),Potree.VolumeTool=function(e,t,i){function o(e){var t=d.domElement.getBoundingClientRect();d.mouse.x=(e.clientX-t.left)/d.domElement.clientWidth*2-1,d.mouse.y=2*-((e.clientY-t.top)/d.domElement.clientHeight)+1}function n(){}function r(e){if(h!==c.DEFAULT&&e.stopImmediatePropagation(),h===c.INSERT_VOLUME)d.finishInsertion();else if(1===e.which){var t=s();t&&t.object.modifiable&&transformationTool.setTargets([t.object])}3===e.which}function a(e){return e.preventDefault(),!1}function s(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=new THREE.Raycaster;t.ray.set(d.camera.position,e.sub(d.camera.position).normalize());for(var i=[],o=0;o0?r[0]:!1}function l(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=e.sub(d.camera.position).normalize(),i=new THREE.Ray(d.camera.position,t),o=[];d.scene.traverse(function(e){(e instanceof Potree.PointCloudOctree||e instanceof Potree.PointCloudArena4D)&&o.push(e)});for(var n=null,r=null,a=0;ac)&&(n=l,r=c)}}return n?n.position:null}var d=this;this.enabled=!1,this.scene=e,this.sceneVolume=new THREE.Scene,this.camera=t,this.renderer=i,this.domElement=i.domElement,this.mouse={x:0,y:0},this.volumes=[];var c={DEFAULT:0,INSERT_VOLUME:1},h=c.DEFAULT;this.update=function(){if(h===c.INSERT_VOLUME){var e=l();if(e){this.activeVolume.position.copy(e);var t=this.activeVolume.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),o=(new THREE.Vector4(t.x,t.y,t.z).applyMatrix4(this.camera.projectionMatrix),Math.abs(t.z/10));this.activeVolume.scale.set(o,o,o)}}for(var n=[],r=0;r=0&&this.volumes.splice(t,1)},this.reset=function(){for(var e=this.volumes.length-1;e>=0;e--){var t=this.volumes[e];this.removeVolume(t)}},this.render=function(){i.render(this.sceneVolume,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousedown",r,!1),this.domElement.addEventListener("mousemove",o,!1),this.domElement.addEventListener("contextmenu",a,!1)},Potree.VolumeTool.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.PointCloudArena4DProxyNode=function(e){THREE.Object3D.call(this),this.geometryNode=e,this.pcoGeometry=e,this.boundingBox=e.boundingBox,this.boundingSphere=e.boundingSphere,this.number=e.name,this.numPoints=e.numPoints,this.level=e.level},Potree.PointCloudArena4DProxyNode.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudArena4D=function(e){THREE.Object3D.call(this),this.root=null,this.visiblePointsTarget=2e6,this.minimumNodePixelSize=150,this.position.sub(e.offset),this.updateMatrix(),this.numVisibleNodes=0,this.numVisiblePoints=0,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleNodes=[],this.pcoGeometry=e,this.boundingBox=this.pcoGeometry.boundingBox,this.boundingSphere=this.pcoGeometry.boundingSphere,this.material=new Potree.PointCloudMaterial({vertexColors:THREE.VertexColors,size:.05,treeType:Potree.TreeType.KDTREE}),this.material.sizeType=Potree.PointSizeType.ATTENUATED,this.material.size=.05,this.pickTarget,this.pickMaterial,this.updateMatrixWorld()},Potree.PointCloudArena4D.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudArena4D.prototype.updateMaterial=function(e,t){this.material.fov=e.fov*(Math.PI/180),this.material.screenWidth=t.domElement.clientWidth,this.material.screenHeight=t.domElement.clientHeight,this.material.spacing=this.pcoGeometry.spacing,this.material.near=e.near,this.material.far=e.far,this.maxLevel>this.material.levels&&(this.material.levels=this.maxLevel+2),this.material.minSize=3;var i=this.boundingBox.size();this.material.bbSize=[i.x,i.y,i.z]},Potree.PointCloudArena4D.prototype.hideDescendants=function(e){for(var t=[],i=0;i0;){var e=t.shift();e.visible=!1,e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);for(var i=0;i0;){var v=f.shift(),g=v.node,E=v.weight;g.matrixWorld.multiplyMatrices(this.matrixWorld,g.matrix);var y=g.boundingBox.clone(),b=a.intersectsBox(y),T=b;if(g.visible=T,T){var R=0;if(8===R&&dbgFullyInside++,g instanceof Potree.PointCloudArena4DProxyNode){var P=g.geometryNode;P.loaded===!0?this.replaceProxy(g):this.loadQueue.push(v)}else if(g instanceof THREE.PointCloud){if(this.numVisiblePoints+g.pcoGeometry.numPoints>pointcloud.visiblePointsTarget)break;if(this.numVisibleNodes++,this.numVisiblePoints+=g.pcoGeometry.numPoints,this.visibleNodes.push({node:g,weight:E}),this.showBoundingBox&&!g.boundingBoxNode){var x=new THREE.BoxHelper(g);this.add(x),this.boundingBoxNodes.push(x),g.boundingBoxNode=x,g.boundingBoxNode.matrixWorld.copy(g.matrixWorld)}else this.showBoundingBox&&g.boundingBoxNode?g.boundingBoxNode.visible=!0:this.showBoundingBox||delete g.boundingBoxNode;for(var n=0;nH&&(A=Number.MAX_VALUE);var V=t.domElement.clientHeight*A;if(!(Vf[I].weight){var B=I;break}if(I==f.length-1){B=f.length;break}}f.splice(B,0,{node:C,weight:E})}}}}}}this.updateLoadQueue(),this.maxLevel=0;for(var n=0;n0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0&&!(t.length>12);){var d=s.shift(),c=d.boundingBox.clone();c.max.sub(c.min),c.min.sub(c.min);var h=i.intersectsBox(c),u=h;if(u){if(l+d.numPoints>this.visiblePointsTarget)break;l+=d.numPoints,t.push(d),d.loaded&&(d.left&&s.push(d.left),d.right&&s.push(d.right))}}return t},Potree.PointCloudArena4D.prototype.nodesOnRay=function(e,t){for(var i=[],o=t.clone(),n=0;n0&&r.push(r[0]);for(var h=0;h=0&&d.disableVertexAttribArray(g)}e.renderBufferDirect(t,[],null,c,p,u)}}var n=17,E=n*n,y=new ArrayBuffer(4*E),b=new Uint8Array(y),T=new Uint32Array(y);e.context.readPixels(l.x-(n-1)/2,l.y-(n-1)/2,n,n,e.context.RGBA,e.context.UNSIGNED_BYTE,b);for(var R=Number.MAX_VALUE,P=null,x=0;n>x;x++)for(var C=0;n>C;C++){var w=x+C*n,H=Math.pow(x-(n-1)/2,2)+Math.pow(C-(n-1)/2,2),S=b[4*w+3];b[4*w+3]=0;var M=T[w];(0!==M||0!==S)&&R>H&&(P={pIndex:M,pcIndex:S},R=H)}if(P){var A={},V=r[P.pcIndex],B=V.geometry.attributes;for(var I in B)if(B.hasOwnProperty(I)){var L=p.attributes[I];if("position"===I){var G=V.geometry.attributes.position.array,W=G[3*P.pIndex+0],N=G[3*P.pIndex+1],O=G[3*P.pIndex+2],_=new THREE.Vector3(W,N,O);_.applyMatrix4(this.matrixWorld),A[I]=_}else if("indices"===I);else if(1===L.itemSize)A[I]=L.array[h+z];else{for(var D=[],z=0;zn?-1:n>r?1:0};t.sort(n);for(var r=[],a=0;a0&&(l+=1,d=r.indexOf(s.pcoGeometry.left.number)-a),s.pcoGeometry.right&&r.indexOf(s.pcoGeometry.right.number)>0&&(l+=2,d=0===d?r.indexOf(s.pcoGeometry.right.number)-a:d),"X"===s.pcoGeometry.split?c=1:"Y"===s.pcoGeometry.split?c=2:"Z"===s.pcoGeometry.split&&(c=4),o[3*a+0]=l,o[3*a+1]=d,o[3*a+2]=c}e.uniforms.nodeSize.value=this.pcoGeometry.boundingBox.size().x,i.needsUpdate=!0}},Object.defineProperty(Potree.PointCloudArena4D.prototype,"progress",{get:function(){return this.pcoGeometry.root?Potree.PointCloudArena4DGeometryNode.nodesLoading>0?0:1:0}}),Potree.PointCloudArena4DGeometryNode=function(){this.left=null,this.right=null,this.boundingBox=null,this.number=null,this.pcoGeometry=null,this.loaded=!1,this.numPoints=0,this.level=0},Potree.PointCloudArena4DGeometryNode.nodesLoading=0,Potree.PointCloudArena4DGeometryNode.prototype.load=function(){if(!(this.loaded||this.loading||Potree.PointCloudArena4DGeometryNode.nodesLoading>=5)){Potree.PointCloudArena4DGeometryNode.nodesLoading++;var e=this.pcoGeometry.url+"?node="+this.number,t=new XMLHttpRequest;t.open("GET",e,!0),t.responseType="arraybuffer";var i=this;t.onreadystatechange=function(){if(4===t.readyState&&200===t.status){for(var e=t.response,o=new DataView(e),n=e.byteLength/17,r=new Float32Array(3*n),a=new Float32Array(3*n),s=new Uint32Array(n),l=0;n>l;l++){var d=o.getFloat32(17*l+0,!0)+i.boundingBox.min.x,c=o.getFloat32(17*l+4,!0)+i.boundingBox.min.y,h=o.getFloat32(17*l+8,!0)+i.boundingBox.min.z,u=o.getUint8(17*l+12,!0)/256,p=o.getUint8(17*l+13,!0)/256,m=o.getUint8(17*l+14,!0)/256;r[3*l+0]=d,r[3*l+1]=c,r[3*l+2]=h,a[3*l+0]=u,a[3*l+1]=p,a[3*l+2]=m,s[l]=l}var f=new THREE.BufferGeometry;f.addAttribute("position",new THREE.BufferAttribute(r,3)),f.addAttribute("color",new THREE.BufferAttribute(a,3)),f.addAttribute("indices",new THREE.BufferAttribute(s,1)),i.geometry=f,i.loaded=!0,Potree.PointCloudArena4DGeometryNode.nodesLoading--,f.boundingBox=i.boundingBox,f.boundingSphere=i.boundingSphere,i.numPoints=n}},t.send(null)}},Potree.PointCloudArena4DGeometry=function(){this.numPoints=0,this.version=0,this.boundingBox=null,this.numNodes=0,this.name=null,this.provider=null,this.url=null,this.root=null,this.levels=0,this._spacing=null,this.pointAttributes=new PointAttributes(["POSITION_CARTESIAN","COLOR_PACKED"])},Potree.PointCloudArena4DGeometry.load=function(e,t){var i=new XMLHttpRequest;i.open("GET",e+"?info",!0),i.onreadystatechange=function(){try{if(4===i.readyState&&200===i.status){var o=JSON.parse(i.responseText),n=new Potree.PointCloudArena4DGeometry;n.url=e,n.name=o.Name,n.provider=o.Provider,n.numNodes=o.Nodes,n.numPoints=o.Points,n.version=o.Version,n.boundingBox=new THREE.Box3((new THREE.Vector3).fromArray(o.BoundingBox.slice(0,3)),(new THREE.Vector3).fromArray(o.BoundingBox.slice(3,6))),o.Spacing&&(n.spacing=o.Spacing);var r=n.boundingBox.min.clone().multiplyScalar(-1);n.boundingBox.min.add(r),n.boundingBox.max.add(r),n.offset=r;var a=n.boundingBox.center(),s=n.boundingBox.size().length()/2;n.boundingSphere=new THREE.Sphere(a,s),n.loadHierarchy(),t(n)}else 4===i.readyState&&t(null)}catch(l){t(null)}},i.send(null)},Potree.PointCloudArena4DGeometry.prototype.loadHierarchy=function(){var e=this.url+"?tree",t=new XMLHttpRequest;t.open("GET",e,!0),t.responseType="arraybuffer";var i=this;t.onreadystatechange=function(){if(4===t.readyState&&200===t.status){for(var e=t.response,o=e.byteLength/3,n=new DataView(e),r=[],a=null,s=0,l=((new Date).getTime(),0);o>l;l++){var d=n.getUint8(3*l+0,!0),c=(n.getUint16(3*l+1,!0),(1&d)>0),h=(2&d)>0,u=(4&d)>0,p=(8&d)>0,m=(16&d)>0,f=null;u?f="X":p&&(f="Y"),m&&(f="Z");var v=new Potree.PointCloudArena4DGeometryNode;if(v.hasLeft=c,v.hasRight=h,v.split=f,v.isLeaf=!c&&!h,v.number=l,v.left=null,v.right=null,v.pcoGeometry=i,v.level=r.length,s=Math.max(s,v.level),r.length>0){var g=r[r.length-1];v.boundingBox=g.boundingBox.clone();var E=g.boundingBox.size();if(g.hasLeft&&!g.left){g.left=v,"X"===g.split?v.boundingBox.max.x=v.boundingBox.min.x+E.x/2:"Y"===g.split?v.boundingBox.max.y=v.boundingBox.min.y+E.y/2:"Z"===g.split&&(v.boundingBox.max.z=v.boundingBox.min.z+E.z/2);var y=v.boundingBox.center(),b=v.boundingBox.size().length()/2;v.boundingSphere=new THREE.Sphere(y,b)}else{g.right=v,"X"===g.split?v.boundingBox.min.x=v.boundingBox.min.x+E.x/2:"Y"===g.split?v.boundingBox.min.y=v.boundingBox.min.y+E.y/2:"Z"===g.split&&(v.boundingBox.min.z=v.boundingBox.min.z+E.z/2);var y=v.boundingBox.center(),b=v.boundingBox.size().length()/2;v.boundingSphere=new THREE.Sphere(y,b)}}else{a=v,a.boundingBox=i.boundingBox.clone();var y=a.boundingBox.center(),b=a.boundingBox.size().length()/2;a.boundingSphere=new THREE.Sphere(y,b)}var T=v.boundingBox.size();if(v.spacing=(T.x+T.y+T.z)/3/75,r.push(v),v.isLeaf)for(var R=!1;!R&&r.length>0;){r.pop();var P=r[r.length-1];R=r.length>0&&P.hasRight&&null==P.right}}{(new Date).getTime()}i.root=a,i.levels=s}},t.send(null)},Object.defineProperty(Potree.PointCloudArena4DGeometry.prototype,"spacing",{get:function(){return this._spacing?this._spacing:this.root?this.root.spacing:void 0},set:function(e){this._spacing=e}}); \ No newline at end of file +var a=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),l=new THREE.Box3(a,s),d=l.clone();n.tightBoundingBox&&(d.min.copy(new THREE.Vector3(n.tightBoundingBox.lx,n.tightBoundingBox.ly,n.tightBoundingBox.lz)),d.max.copy(new THREE.Vector3(n.tightBoundingBox.ux,n.tightBoundingBox.uy,n.tightBoundingBox.uz)));var c=new THREE.Vector3(0,0,0);c.set(-a.x,-a.y,-a.z),l.min.add(c),l.max.add(c),d.min.add(c),d.max.add(c),i.boundingBox=l,i.tightBoundingBox=d,i.boundingSphere=l.getBoundingSphere(),i.tightBoundingSphere=d.getBoundingSphere(),i.offset=c,"LAS"===n.pointAttributes?i.loader=new Potree.LasLazLoader(n.version):"LAZ"===n.pointAttributes?i.loader=new Potree.LasLazLoader(n.version):(i.loader=new Potree.BinaryLoader(n.version,l,n.scale),i.pointAttributes=new PointAttributes(i.pointAttributes));var h={},u="r",p=new Potree.PointCloudOctreeGeometryNode(u,i,l);if(p.level=0,p.hasChildren=!0,p.numPoints=r.upTo("1.5")?n.hierarchy[0][1]:0,i.root=p,i.root.load(),h[u]=p,r.upTo("1.4"))for(var m=1;m=n?i.pointsCount:i.pointsCount/n,s=function(){var e=t.readData(1e6,0,n);return e.then(function(e){return o.push(new LASDecoder(e.buffer,i.pointsFormatId,i.pointsStructSize,e.count,i.scale,i.offset,i.mins,i.maxs)),r+=e.count,Potree.LasLazLoader.progressCB(r/a),e.hasMoreData?s():(i.totalRead=r,i.versionAsString=t.versionAsString,i.isCompressed=t.isCompressed,[t,i,o])})};return s()}).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(i.isOpen)return i.close().then(function(){throw i.isOpen=!1,e});throw e})},Potree.LasLazLoader.prototype.handle=function(){},Potree.LasLazBatcher=function(e){this.push=function(t){var i=Potree.workers.lasdecoder.getWorker(),o=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]);o.add(e.pcoGeometry.offset),n.add(e.pcoGeometry.offset),i.onmessage=function(r){for(var a=new THREE.BufferGeometry,s=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),f=new Uint16Array(r.data.pointSourceID),v=new Float32Array(f.length),g=new ArrayBuffer(4*s),E=new Uint32Array(g),y=new THREE.Box3,b=new Float32Array(l),T=0;s>T;T++)u[T]=h[T],m[T]=p[T],v[T]=f[T],E[T]=T,y.expandByPoint(new THREE.Vector3(b[3*T+0],b[3*T+1],b[3*T+2]));a.addAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),a.addAttribute("color",new THREE.BufferAttribute(new Float32Array(d),3)),a.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(c),1)),a.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(u),1)),a.addAttribute("returnNumber",new THREE.BufferAttribute(new Float32Array(m),1)),a.addAttribute("pointSourceID",new THREE.BufferAttribute(new Float32Array(v),1)),a.addAttribute("indices",new THREE.BufferAttribute(g,1)),a.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(3*s),3)),a.boundingBox=new THREE.Box3(o,n),e.boundingBox=a.boundingBox,e.geometry=a,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(i)};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]};i.postMessage(r,[r.buffer])}},Potree.Gradients={RAINBOW:[[0,new THREE.Color(.278,0,.714)],[1/6,new THREE.Color(0,0,1)],[2/6,new THREE.Color(0,1,1)],[.5,new THREE.Color(0,1,0)],[4/6,new THREE.Color(1,1,0)],[5/6,new THREE.Color(1,.64,0)],[1,new THREE.Color(1,0,0)]],GRAYSCALE:[[0,new THREE.Color(0,0,0)],[1,new THREE.Color(1,1,1)]]},Potree.Classification={DEFAULT:{0:new THREE.Color(.5,.5,.5),1:new THREE.Color(.5,.5,.5),2:new THREE.Color(.63,.32,.18),3:new THREE.Color(0,1,0),4:new THREE.Color(0,.8,0),5:new THREE.Color(0,.6,0),6:new THREE.Color(1,.66,0),7:new THREE.Color(1,0,1),8:new THREE.Color(1,0,0),9:new THREE.Color(0,0,1),12:new THREE.Color(1,1,0),DEFAULT:new THREE.Color(.3,.6,.6)}},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,TREE_DEPTH:6,POINT_INDEX:7,CLASSIFICATION:8,RETURN_NUMBER:9,SOURCE:10,NORMAL:11,PHONG:12,TREE_DEPTH:13},Potree.ClipMode={DISABLED:0,CLIP_OUTSIDE:1,HIGHLIGHT_INSIDE:2},Potree.TreeType={OCTREE:0,KDTREE:1},Potree.PointCloudMaterial=function(e){e=e||{};var t=new THREE.Color(0),i=THREE.ImageUtils.generateDataTexture(2048,1,t);i.magFilter=THREE.NearestFilter,this.visibleNodesTexture=i;var o=e.size||1,n=e.minSize||1,r=e.maxSize||50,a=e.treeType||Potree.TreeType.OCTREE,s=1;this._pointSizeType=Potree.PointSizeType.ATTENUATED,this._pointShape=Potree.PointShape.SQUARE,this._interpolate=!1,this._pointColorType=Potree.PointColorType.RGB,this._levels=6,this._useClipBox=!1,this.numClipBoxes=0,this._clipMode=Potree.ClipMode.DISABLED,this._weighted=!1,this._blendDepth=.1,this._depthMap,this._gradient=Potree.Gradients.RAINBOW,this._classification=Potree.Classification.DEFAULT,this.gradientTexture=Potree.PointCloudMaterial.generateGradientTexture(this._gradient),this.classificationTexture=Potree.PointCloudMaterial.generateClassificationTexture(this._classification),this.lights=!0,this._treeType=a;var l={},d={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},maxSize:{type:"f",value:2},nodeSize:{type:"f",value:s},bbSize:{type:"fv",value:[0,0,0]},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},classificationLUT:{type:"t",value:this.classificationTexture},clipBoxes:{type:"Matrix4fv",value:[]},blendDepth:{type:"f",value:this._blendDepth},depthMap:{type:"t",value:null},diffuse:{type:"fv",value:[1,1,1]},ambient:{type:"fv",value:[.1,.1,.1]},ambientLightColor:{type:"fv",value:[1,1,1]},directionalLightColor:{type:"fv",value:null},directionalLightDirection:{type:"fv",value:null},pointLightColor:{type:"fv",value:null},pointLightPosition:{type:"fv",value:null},pointLightDistance:{type:"fv1",value:null},spotLightColor:{type:"fv",value:null},spotLightPosition:{type:"fv",value:null},spotLightDistance:{type:"fv1",value:null},spotLightDirection:{type:"fv",value:null},spotLightAngleCos:{type:"fv1",value:null},spotLightExponent:{type:"fv1",value:null},hemisphereLightSkyColor:{type:"fv",value:null},hemisphereLightGroundColor:{type:"fv",value:null},hemisphereLightDirection:{type:"fv",value:null}};this.defaultAttributeValues.normal=[0,0,0],this.setValues({uniforms:d,attributes:l,vertexShader:this.getDefines()+Potree.Shaders["pointcloud.vs"],fragmentShader:this.getDefines()+Potree.Shaders["pointcloud.fs"],vertexColors:THREE.VertexColors,size:o,minSize:n,maxSize:r,nodeSize:s,pcIndex:0,alphaTest:.9})},Potree.PointCloudMaterial.prototype=new THREE.ShaderMaterial,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.pointColorType===Potree.PointColorType.NORMAL||this.pointColorType===Potree.PointColorType.PHONG)&&(e.normal={type:"f",value:[]});var t=this.getDefines()+Potree.Shaders["pointcloud.vs"],i=this.getDefines()+Potree.Shaders["pointcloud.fs"];this.setValues({attributes:e,vertexShader:t,fragmentShader:i}),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 levels "+Math.max(0,this._levels-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.TREE_DEPTH?e+="#define color_type_tree_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._pointColorType===Potree.PointColorType.NORMAL?e+="#define color_type_normal\n":this._pointColorType===Potree.PointColorType.PHONG&&(e+="#define color_type_phong\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._treeType===Potree.TreeType.OCTREE?e+="#define tree_type_octree\n":this._treeType===Potree.TreeType.KDTREE&&(e+="#define tree_type_kdtree\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 i=0;t>i;i++){var o=e[i];this.uniforms.clipBoxes.value.set(o.elements,16*i)}},Object.defineProperty(Potree.PointCloudMaterial.prototype,"gradient",{get:function(){return this._gradient},set:function(e){this._gradient!==e&&(this._gradient=e,this.gradientTexture=Potree.PointCloudMaterial.generateGradientTexture(this._gradient),this.uniforms.gradient.value=this.gradientTexture)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"classification",{get:function(){return this._classification},set:function(e){this._classification!==e&&(this._classification=e,this.classificationTexture=Potree.PointCloudMaterial.generateClassificationTexture(this._classification),this.uniforms.classificationLUT.value=this.classificationTexture)}}),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,"levels",{get:function(){return this._levels},set:function(e){this._levels!==e&&(this._levels=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,"maxSize",{get:function(){return this.uniforms.maxSize.value},set:function(e){this.uniforms.maxSize.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}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"treeType",{get:function(){return this._treeType},set:function(e){this._treeType!=e&&(this._treeType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"bbSize",{get:function(){return this.uniforms.bbSize.value},set:function(e){this.uniforms.bbSize.value=e}}),Potree.PointCloudMaterial.generateGradientTexture=function(e){var t=64;canvas=document.createElement("canvas"),canvas.width=t,canvas.height=t;var i=canvas.getContext("2d");i.rect(0,0,t,t);for(var o=i.createLinearGradient(0,0,t,t),n=0;nr;r++)for(var a=0;i>a;a++){var s,l=r+t*a;s=e[r]?e[r]:e.DEFAULT,n[3*l+0]=255*s.r,n[3*l+1]=255*s.g,n[3*l+2]=255*s.b}return o},THREE.FirstPersonControls=function(e,t){function i(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",o,!1),l.domElement.addEventListener("mouseup",n,!1),l.dispatchEvent(x))}function o(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",o,!1),l.domElement.removeEventListener("mouseup",n,!1),l.dispatchEvent(C),R=T.NONE)}function r(e){if(l.enabled!==!1&&l.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1;l.moveSpeed+=.1*l.moveSpeed*t,l.moveSpeed=Math.max(.1,l.moveSpeed),l.dispatchEvent(x),l.dispatchEvent(C)}}function a(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 s(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,f=new THREE.Vector3,v=(new THREE.Vector3,0),g=0,E=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"},x={type:"start"},C={type:"end"};this.rotateLeft=function(e){g-=e},this.rotateUp=function(e){v-=e},this.panLeft=function(e){var t=this.object.matrix.elements;f.set(t[0],t[1],t[2]),f.multiplyScalar(-e),y.add(f)},this.panUp=function(e){var t=this.object.matrix.elements;f.set(t[4],t[5],t[6]),f.multiplyScalar(e),y.add(f)},this.panForward=function(e){var t=this.object.matrix.elements;f.set(t[8],t[9],t[10]),f.multiplyScalar(e),y.add(f)},this.pan=function(e,t){var i=l.domElement===document?l.domElement.body:l.domElement;if(void 0!==l.object.fov){var o=l.object.position,n=o.clone(),r=n.length();r*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*r/i.clientHeight),l.panUp(2*t*r/i.clientHeight)}else void 0!==l.object.top?(l.panLeft(e*(l.object.right-l.object.left)/i.clientWidth),l.panUp(t*(l.object.top-l.object.bottom)/i.clientHeight)):console.warn("WARNING: FirstPersonControls.js encountered an unknown camera type - pan disabled.")},this.update=function(e){this.object.rotation.order="ZYX";var t=this.object;this.object=new THREE.Object3D,this.object.position.copy(t.position),this.object.rotation.copy(t.rotation),this.object.updateMatrix(),this.object.updateMatrixWorld();var i=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(i.add(y),0!==g||0!==v){var o={type:"rotate",thetaDelta:g,phiDelta:v};this.dispatchEvent(o)}this.object.updateMatrix();var n=(new THREE.Matrix4).makeRotationY(g),r=(new THREE.Matrix4).multiplyMatrices(n,this.object.matrix);this.object.quaternion.setFromRotationMatrix(r),this.object.rotation.x+=v,this.object.updateMatrixWorld();var a={type:"proposeTransform",oldPosition:t.position,newPosition:this.object.position,objections:0,counterProposals:[]};if(this.dispatchEvent(a),a.objections>0&&a.counterProposals.length>0){var s=a.counterProposals;this.object.position.copy(s[0]),a.objections=0,a.counterProposals=[]}a.objections>0||t.position.copy(this.object.position),t.rotation.copy(this.object.rotation),this.object=t,g=0,v=0,E=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",i,!1),this.domElement.addEventListener("mousewheel",r,!1),this.domElement.addEventListener("DOMMouseScroll",r,!1),window.addEventListener("keydown",a,!1),window.addEventListener("keyup",s,!1)},THREE.FirstPersonControls.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.OrbitControls=function(e,t){function i(){return 2*Math.PI/60/60*u.autoRotateSpeed}function o(){return Math.pow(.95,u.zoomSpeed)}function n(e){if(u.enabled!==!1){if(e.preventDefault(),0===e.button){if(u.noRotate===!0)return;V=A.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(u.noZoom===!0)return;V=A.DOLLY,R.set(e.clientX,e.clientY)}else if(2===e.button){if(u.noPan===!0)return;V=A.PAN,g.set(e.clientX,e.clientY)}u.domElement.addEventListener("mousemove",r,!1),u.domElement.addEventListener("mouseup",a,!1),u.dispatchEvent(I)}}function r(e){if(u.enabled!==!1){e.preventDefault();var t=u.domElement===document?u.domElement.body:u.domElement;if(V===A.ROTATE){if(u.noRotate===!0)return;f.set(e.clientX,e.clientY),v.subVectors(f,m),u.rotateLeft(2*Math.PI*v.x/t.clientWidth*u.rotateSpeed),u.rotateUp(2*Math.PI*v.y/t.clientHeight*u.rotateSpeed),m.copy(f)}else if(V===A.DOLLY){if(u.noZoom===!0)return;P.set(e.clientX,e.clientY),x.subVectors(P,R),x.y>0?u.dollyIn():u.dollyOut(),R.copy(P)}else if(V===A.PAN){if(u.noPan===!0)return;E.set(e.clientX,e.clientY),y.subVectors(E,g),u.pan(y.x,y.y),g.copy(E)}}}function a(){u.enabled!==!1&&(u.domElement.removeEventListener("mousemove",r,!1),u.domElement.removeEventListener("mouseup",a,!1),u.dispatchEvent(L),V=A.NONE)}function s(e){if(u.enabled!==!1&&u.noZoom!==!0){e.preventDefault(); +var t=0;void 0!==e.wheelDelta?t=e.wheelDelta:void 0!==e.detail&&(t=-e.detail),t>0?u.dollyOut():u.dollyIn(),u.dispatchEvent(I),u.dispatchEvent(L)}}function l(e){if(u.enabled!==!1&&u.noKeys!==!0&&u.noPan!==!0)switch(e.keyCode){case u.keys.UP:u.pan(0,u.keyPanSpeed);break;case u.keys.BOTTOM:u.pan(0,-u.keyPanSpeed);break;case u.keys.LEFT:u.pan(u.keyPanSpeed,0);break;case u.keys.RIGHT:u.pan(-u.keyPanSpeed,0)}}function d(e){if(u.enabled!==!1){switch(e.touches.length){case 1:if(u.noRotate===!0)return;V=A.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(u.noZoom===!0)return;V=A.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,i=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(t*t+i*i);R.set(0,o);break;case 3:if(u.noPan===!0)return;V=A.TOUCH_PAN,g.set(e.touches[0].pageX,e.touches[0].pageY);break;default:V=A.NONE}u.dispatchEvent(I)}}function c(e){if(u.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=u.domElement===document?u.domElement.body:u.domElement;switch(e.touches.length){case 1:if(u.noRotate===!0)return;if(V!==A.TOUCH_ROTATE)return;f.set(e.touches[0].pageX,e.touches[0].pageY),v.subVectors(f,m),u.rotateLeft(2*Math.PI*v.x/t.clientWidth*u.rotateSpeed),u.rotateUp(2*Math.PI*v.y/t.clientHeight*u.rotateSpeed),m.copy(f);break;case 2:if(u.noZoom===!0)return;if(V!==A.TOUCH_DOLLY)return;var i=e.touches[0].pageX-e.touches[1].pageX,o=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(i*i+o*o);P.set(0,n),x.subVectors(P,R);var r=t.clientWidth,a=t.clientHeight,s=Math.sqrt(r*r+a*a),l=x.y/s;x.y>0?u.dollyOut(1-l):u.dollyIn(1+l),R.copy(P);break;case 3:if(u.noPan===!0)return;if(V!==A.TOUCH_PAN)return;E.set(e.touches[0].pageX,e.touches[0].pageY),y.subVectors(E,g),u.pan(y.x,y.y),g.copy(E);break;default:V=A.NONE}}}function h(){u.enabled!==!1&&(u.dispatchEvent(L),V=A.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.fadeFactor=10,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var u=this,p=1e-6,m=new THREE.Vector2,f=new THREE.Vector2,v=new THREE.Vector2,g=new THREE.Vector2,E=new THREE.Vector2,y=new THREE.Vector2,b=new THREE.Vector3,T=new THREE.Vector3,R=new THREE.Vector2,P=new THREE.Vector2,x=new THREE.Vector2,C=0,w=0,H=1,S=new THREE.Vector3,M=new THREE.Vector3,A={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},V=A.NONE;this.target0=this.target.clone(),this.position0=this.object.position.clone();var B={type:"change"},I={type:"start"},L={type:"end"};this.rotateLeft=function(e){void 0===e&&(e=i()),w-=e},this.rotateUp=function(e){void 0===e&&(e=i()),C-=e},this.panLeft=function(e){var t=this.object.matrix.elements;b.set(t[0],t[1],t[2]),b.multiplyScalar(-e),S.add(b)},this.panUp=function(e){var t=this.object.matrix.elements;b.set(t[4],t[5],t[6]),b.multiplyScalar(e),S.add(b)},this.pan=function(e,t){var i=u.domElement===document?u.domElement.body:u.domElement;if(void 0!==u.object.fov){var o=u.object.position,n=o.clone().sub(u.target),r=n.length();r*=Math.tan(u.object.fov/2*Math.PI/180),u.panLeft(2*e*r/i.clientHeight),u.panUp(2*t*r/i.clientHeight)}else void 0!==u.object.top?(u.panLeft(e*(u.object.right-u.object.left)/i.clientWidth),u.panUp(t*(u.object.top-u.object.bottom)/i.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=o()),H/=e},this.dollyOut=function(e){void 0===e&&(e=o()),H*=e},this.update=function(e){var t=this.object.position.clone();T.copy(t).sub(this.target);var o=Math.atan2(T.x,T.z),n=Math.atan2(Math.sqrt(T.x*T.x+T.z*T.z),T.y);this.autoRotate&&this.rotateLeft(i());var r=Math.min(1,this.fadeFactor*e);o+=r*w,n+=r*C,n=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,n)),n=Math.max(p,Math.min(Math.PI-p,n));var a=T.length();a+=(H-1)*a*r,a=Math.max(this.minDistance,Math.min(this.maxDistance,a)),this.target.add(S.clone().multiplyScalar(r)),T.x=a*Math.sin(n)*Math.sin(o),T.y=a*Math.cos(n),T.z=a*Math.sin(n)*Math.cos(o),t.copy(this.target).add(T);var s={type:"proposeTransform",oldPosition:this.object.position,newPosition:t,objections:0,counterProposals:[]};if(this.dispatchEvent(s),s.objections>0&&s.counterProposals.length>0){var l=s.counterProposals;t.copy(l[0]),s.objections=0,s.counterProposals=[]}if(s.objections>0)w=0,C=0,H=1,S.set(0,0,0);else{this.object.position.copy(t),this.object.lookAt(this.target);var d=Math.max(0,1-this.fadeFactor*e);w*=d,C*=d,H=1+(H-1)*d,S.multiplyScalar(d)}M.distanceTo(this.object.position)>0&&(this.dispatchEvent(B),M.copy(this.object.position))},this.reset=function(){V=A.NONE,this.target.copy(this.target0),this.object.position.copy(this.position0),this.update()},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",n,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1),this.domElement.addEventListener("touchstart",d,!1),this.domElement.addEventListener("touchend",h,!1),this.domElement.addEventListener("touchmove",c,!1),window.addEventListener("keydown",l,!1)},Potree.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype),THREE.EarthControls=function(e,t,i){function o(e){if(s.enabled!==!1){e.preventDefault();var t=s.domElement.getBoundingClientRect(),i={x:(e.clientX-t.left)/s.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/s.domElement.clientHeight)+1},o=getMousePointCloudIntersection(i,s.camera,s.renderer,s.pointclouds);if(o){var a=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),o),u=new THREE.Vector3(i.x,i.y,.5);u.unproject(s.camera);var p=u.sub(s.camera.position).normalize(),m=new THREE.Ray(s.camera.position,p);v=m.intersectPlane(a),f=s.camera.clone(),f.rotation.copy(s.camera.rotation),c.set(e.clientX-t.left,e.clientY-t.top),h.set(e.clientX-t.left,e.clientY-t.top),s.scene.add(s.pivotNode),s.pivotNode.position.copy(v),0===e.button?d=l.DRAG:2===e.button&&(d=l.ROTATE),s.domElement.addEventListener("mousemove",n,!1),s.domElement.addEventListener("mouseup",r,!1)}}}function n(e){if(s.enabled!==!1){e.preventDefault();{var t=s.domElement.getBoundingClientRect();s.domElement===document?s.domElement.body:s.domElement}m.set(e.clientX-t.left-h.x,e.clientY-t.top-h.y),h.set(e.clientX-t.left,e.clientY-t.top)}}function r(){s.enabled!==!1&&(s.domElement.removeEventListener("mousemove",n,!1),s.domElement.removeEventListener("mouseup",r,!1),d=l.NONE,s.scene.remove(s.pivotNode))}function a(e){if(s.enabled!==!1&&s.noZoom!==!0){e.preventDefault();var t=s.domElement.getBoundingClientRect(),i=e.detail<0||e.wheelDelta>0?1:-1,o={x:(e.clientX-t.left)/s.domElement.clientWidth*2-1,y:2*-((e.clientY-t.top)/s.domElement.clientHeight)+1},n=getMousePointCloudIntersection(o,s.camera,s.renderer,s.pointclouds);if(n){var r=n.distanceTo(s.camera.position),a=(new THREE.Vector3).subVectors(n,s.camera.position).normalize();s.camera.position.add(a.multiplyScalar(.1*r*i))}}}this.camera=e,this.renderer=t,this.pointclouds=[],this.domElement=t.domElement,this.scene=i,this.enabled=!0;var s=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,f=null,v=null;this.minAngle=10/180*Math.PI,this.maxAngle=70/180*Math.PI,this.update=function(e){this.camera.position;this.camera.updateMatrixWorld();var t=new THREE.Object3D;if(t.position.copy(this.camera.position),t.rotation.copy(this.camera.rotation),t.updateMatrix(),t.updateMatrixWorld(),v){if(d===l.DRAG){var i=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),v),o={x:h.x/this.domElement.clientWidth*2-1,y:2*-(h.y/this.domElement.clientHeight)+1},n=new THREE.Vector3(o.x,o.y,.5);n.unproject(f);var r=n.sub(f.position).normalize(),a=new THREE.Ray(f.position,r),s=a.distanceToPlane(i);if(s>0){var c=(new THREE.Vector3).subVectors(v,r.clone().multiplyScalar(s));t.position.copy(c)}}else if(d===l.ROTATE){var u=m.clone().multiplyScalar(e);u.x*=.3,u.y*=.2;var p=new THREE.Object3D,g=new THREE.Object3D;p.add(g),p.position.copy(v),g.position.copy(this.camera.position).sub(v),g.rotation.copy(this.camera.rotation),p.rotation.y+=-u.x;var r=this.camera.getWorldDirection(),E=new THREE.Vector3(0,1,0),y=(new THREE.Vector3).crossVectors(E,r),b=g.position.clone();b.y=0,b.normalize();var T=b.dot(g.position.clone().normalize()),R=Math.acos(T);g.position.y<0&&(R=-R);var P=0;P=u.y>0?u.y-Math.max(0,this.minAngle-(R-u.y)):u.y+Math.max(0,R-u.y-this.maxAngle),p.rotateOnAxis(y,-P),p.updateMatrixWorld(),t.position.copy(g.getWorldPosition()),t.quaternion.copy(g.getWorldQuaternion())}var x={type:"proposeTransform",oldPosition:this.camera.position,newPosition:t.position,objections:0};this.dispatchEvent(x),x.objections>0||(this.camera.position.copy(t.position),this.camera.rotation.copy(t.rotation));var C=this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),w=Math.abs(C.z/30),H=this.pivotNode.scale.length();this.pivotNode.scale.multiplyScalar(w/H)}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",o,!1),this.domElement.addEventListener("mousewheel",a,!1),this.domElement.addEventListener("DOMMouseScroll",a,!1)},THREE.EarthControls.prototype=Object.create(THREE.EventDispatcher.prototype),LRU.prototype.size=function(){return this.elements},LRU.prototype.contains=function(e){return null==this.items[e.id]},LRU.prototype.touch=function(e){if(e.loaded){var t;null==this.items[e.id]?(t=new LRUItem(e),t.previous=this.last,this.last=t,null!==t.previous&&(t.previous.next=t),this.items[e.id]=t,this.elements++,null===this.first&&(this.first=t),this.numPoints+=e.numPoints):(t=this.items[e.id],null===t.previous?null!==t.next&&(this.first=t.next,this.first.previous=null,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t):null===t.next||(t.previous.next=t.next,t.next.previous=t.previous,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t))}},LRU.prototype.remove=function(e){var t=this.items[e.id];t&&(1===this.elements?(this.first=null,this.last=null):(t.previous||(this.first=t.next,this.first.previous=null),t.next||(this.last=t.previous,this.last.next=null),t.previous&&t.next&&(t.previous.next=t.next,t.next.previous=t.previous)),delete this.items[e.id],this.elements--,this.numPoints-=e.numPoints)},LRU.prototype.getLRUItem=function(){if(null===this.first)return null;var e=this.first;return e.node},LRU.prototype.toString=function(){for(var e="{ ",t=this.first;null!==t;)e+=t.node.id,null!==t.next&&(e+=", "),t=t.next;return e+="}",e+="("+this.size()+")"},LRU.prototype.freeMemory=function(){if(!(this.elements<=1))for(;this.numPoints>Potree.pointLoadLimit;){var e=this.first,t=e.node;this.disposeDescendants(t)}},LRU.prototype.disposeDescendants=function(e){var t=[];for(t.push(e);t.length>0;){var i=t.pop();i.dispose(),this.remove(i);for(var o in i.children)if(i.children.hasOwnProperty(o)){var n=i.children[o];n.loaded&&t.push(i.children[o])}}},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,i,o,n){this.start=e,this.end=t,this.width=i,this.depth=o,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()),a=new THREE.Vector3(0,1,0),s=(new THREE.Vector3).crossVectors(r,a).normalize(),l=s;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.minimumNodePixelSize=150,this.level=0,this.position.sub(e.offset),this.updateMatrix(),this.LODDistance=20,this.LODFalloff=1.3,this.LOD=4,this.showBoundingBox=!1,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleBounds=new THREE.Box3,this.profileRequests=[],this.visibleNodes=[],this.visibleGeometry=[],this.pickTarget,this.pickMaterial,this.maxLevel=0,this.generateDEM=!1;var i=new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);this.add(i)},Potree.PointCloudOctree.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudOctree.prototype.updateVisibleBounds=function(){for(var e=[],t=0;t0;){var r=n.shift();if(r instanceof Potree.PointCloudOctreeProxyNode){var a=Potree.utils.computeTransformedBoundingBox(r.boundingBox,r.matrixWorld),s=a.getBoundingSphere();Math.abs(i.distanceToPoint(s.center))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-1&&this.profileRequests.splice(m,1)}},Potree.PointCloudOctree.prototype.updatePointCloud=function(e,t,i,o){if(this.numVisibleNodes++,this.numVisiblePoints+=e.numPoints,e.material=this.material,this.visibleNodes.push(t),e.level&&(this.maxLevel=Math.max(e.level,this.maxLevel)),this.showBoundingBox&&!e.boundingBoxNode){var n=new THREE.BoxHelper(e);this.add(n),this.boundingBoxNodes.push(n),e.boundingBoxNode=n,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)}else this.showBoundingBox?(e.boundingBoxNode.visible=!0,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)):!this.showBoundingBox&&e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);this.generateDEM&&e.level<=2&&(e.dem||(e.dem=this.createDEM(e)));for(var r=0;r=0;if(s)for(var l=0;l0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0;){{var a=r.shift(),s=a.node;a.weight}if(s.visible=!0,s.matrixWorld.multiplyMatrices(s.parent.matrixWorld,s.matrix),s instanceof Potree.PointCloudOctreeProxyNode){var l=s.geometryNode;l.loaded===!0?this.replaceProxy(s):this.loadQueue.push(a)}else if(s instanceof THREE.PointCloud)if(s.pcoGeometry.loaded)Potree.PointCloudOctree.lru.touch(s.pcoGeometry),this.updatePointCloud(s,a,r,i);else{var d=new Potree.PointCloudOctreeProxyNode(s.pcoGeometry),c=s.parent;c.remove(s),c.add(d)}}this.updateProfileRequests(),this.updateVisibleBounds(),this.updateLoadQueue(),this.hideDescendants(this.children[0]);for(var h=[],o=0;o0;){y++;var b=m.shift(),T=b.node,R=T.boundingBox,v=T.boundingSphere,P=n.intersectsBox(R),x=P;if(x){if(f+T.numPoints>this.visiblePointsTarget)break;f+=T.numPoints,i.push(b);for(var C=0;8>C;C++)if(T.children[C]){var w=T.children[C],v=w.boundingSphere,g=v.center.distanceTo(u),H=v.radius,E=v.radius/g,S=e.fov/2*Math.PI/180,M=1/Math.tan(S)*H/Math.sqrt(g*g-H*H),A=t.domElement.clientHeight*M;if(!(Ag-H&&(E=Number.MAX_VALUE),0===m.length)m.push({node:w,weight:E});else{for(var V=0,B=0;Bm[B].weight){var V=B;break}if(B==m.length-1){V=m.length;break}}m.splice(V,0,{node:w,weight:E})}}}}return i},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(e,t){if(e){var i=e.visibleNodesTexture,o=i.image.data;t=t.slice();var n=function(e,t){var i=e.name,o=t.name;return i.length!=o.length?i.length-o.length:o>i?-1:i>o?1:0};t.sort(n);for(var r={},a=0;at.name?1:0}),o[3*a+0]=0,o[3*a+1]=0,o[3*a+2]=0;for(var d=0;dr;r++)if(void 0!==t.children[r]){var a=t.children[r],s=new Potree.PointCloudOctreeProxyNode(a);o.add(s)}return o}},Potree.PointCloudOctree.prototype.hideDescendants=function(e){for(var t=[],i=0;i0;){var e=t.shift();e.visible=!1;for(var i=0;i0&&(l=-l),function(e){var t=(new THREE.Matrix4).makeTranslation(-o.x,-o.y,-o.z),i=(new THREE.Matrix4).makeRotationY(-l),n=(new THREE.Matrix4).makeTranslation(r,0,0),a=e.clone();return a.applyMatrix4(t),a.applyMatrix4(i),a.applyMatrix4(n),a}}(r,a,o),d={start:r,end:a,points:s,project:l};i.push(d),o+=r.distanceTo(a)}return i},Potree.PointCloudOctree.prototype.getProfile=function(e,t,i,o,n){if(void 0===n){var r=[];r.push(this);for(var a=(new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),s=(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,a),m=null;r.length>0;){var f=r.shift(),v=0;if(f instanceof THREE.PointCloud){var g=f.geometry,E=g.attributes.position,y=E.array,b=f.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 x=Math.abs(u.distanceToPoint(P)),C=Math.abs(p.distanceToPoint(P));if(i/2>x&&s/2>C){for(var T in g.attributes)if(g.attributes.hasOwnProperty(T))if("position"===T)m[T].push(P);else if("indices"===T);else{var w=g.attributes[T];if(1===w.itemSize)m[T].push(w.array[R+S]);else{for(var H=[],S=0;S0&&(a=-a),function(e){var t=(new THREE.Matrix4).makeTranslation(-i.x,-i.y,-i.z),o=(new THREE.Matrix4).makeRotationY(-a),n=e.clone();return n.applyMatrix4(t),n.applyMatrix4(o),n}}(e,t);return m.project=V,m}this.profileRequests.push(new Potree.ProfileRequest(e,t,i,o,n))},Potree.PointCloudOctree.prototype.getVisibleExtent=function(){return this.visibleBounds.applyMatrix4(this.matrixWorld)},Potree.PointCloudOctree.prototype.pick=function(e,t,i,o){var o=o||{},n=o.pickWindowSize||17,r=this.nodesOnRay(this.visibleNodes,i);if(0===r.length)return null;var a=Math.ceil(e.domElement.clientWidth),s=Math.ceil(e.domElement.clientHeight),l=(new THREE.Vector3).addVectors(t.position,i.direction).project(t);l.addScalar(1).multiplyScalar(.5),l.x*=a,l.y*=s,this.pickTarget?(this.pickTarget.width!=a||this.pickTarget.height!=s)&&(this.pickTarget.dispose(),this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat})):this.pickTarget=new THREE.WebGLRenderTarget(1,1,{minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat}),this.pickTarget.setSize(a,s),this.pickMaterial||(this.pickMaterial=new Potree.PointCloudMaterial,this.pickMaterial.pointColorType=Potree.PointColorType.POINT_INDEX,this.pickMaterial.pointSizeType=Potree.PointSizeType.FIXED),this.pickMaterial.pointSizeType=this.material.pointSizeType,this.pickMaterial.size=this.material.size,this.pickMaterial.pointSizeType===Potree.PointSizeType.ADAPTIVE&&this.updateVisibilityTexture(this.pickMaterial,r),this.pickMaterial.fov=this.material.fov,this.pickMaterial.screenWidth=this.material.screenWidth,this.pickMaterial.screenHeight=this.material.screenHeight,this.pickMaterial.spacing=this.material.spacing,this.pickMaterial.near=this.material.near,this.pickMaterial.far=this.material.far,this.pickMaterial.octreeLevels=this.material.octreeLevels,this.pickMaterial.pointShape=this.material.pointShape;var 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;hP;P++)for(var x=0;n>x;x++){var C=P+x*n,w=Math.pow(P-(n-1)/2,2)+Math.pow(x-(n-1)/2,2),H=y[4*C+3];y[4*C+3]=0;var S=b[C];(0!==S||0!==H)&&T>w&&(R={pIndex:S,pcIndex:H},T=w)}if(R){var M={},A=r[R.pcIndex],V=A.geometry.attributes;for(var B in V)if(V.hasOwnProperty(B)){var I=p.attributes[B];if("position"===B){var L=A.geometry.attributes.position.array,G=L[3*R.pIndex+0],W=L[3*R.pIndex+1],N=L[3*R.pIndex+2],O=new THREE.Vector3(G,W,N);O.applyMatrix4(this.matrixWorld),M[B]=O}else if("indices"===B);else if(1===I.itemSize)M[B]=I.array[h+D];else{for(var _=[],D=0;Dc;c++){var h=r[3*c+0],u=r[3*c+1],p=r[3*c+2],m=new THREE.Vector3(h,u,p).applyMatrix4(i),f=parseInt(a*(m.x-o.min.x)/n.x),v=parseInt(a*(m.z-o.min.z)/n.z);f=Math.min(f,a-1),v=Math.min(v,a-1);var g=f+v*a;s[g]||(s[g]=[]),s[g].push(m.y)}for(var c=0;c.5&&r.x.5&&r.y0;){{var r=n.shift(),a=r.dem,s=(a.demSize,a.boundingBox2D);s.containsPoint(t)}if(s.containsPoint(t)){var l=i(a);if(o?null!=l&&l>0&&(o=l):o=l,r.level<=2)for(var d=0;da;a++)for(var s=0;i>s;s++){var l=a/t,d=s/i,c=l*e.size().x+e.min.x,h=d*e.size().z+e.min.z,u=this.getDEMHeight(new THREE.Vector3(c,0,h));u||(u=0),n[r+0]=c,n[r+1]=u,n[r+2]=h,r+=3}o.addAttribute("position",new THREE.BufferAttribute(n,3));var p=new THREE.PointCloudMaterial({size:20,color:65280}),m=new THREE.PointCloud(o,p);scene.add(m)},Object.defineProperty(Potree.PointCloudOctree.prototype,"progress",{get:function(){return this.visibleNodes.length/this.visibleGeometry.length}});var nodesLoadTimes={};Potree.PointCloudOctreeGeometry=function(){Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.url=null,this.octreeDir=null,this.spacing=0,this.boundingBox=null,this.root=null,this.numNodesLoading=0,this.nodes=null,this.pointAttributes=null,this.hierarchyStepSize=-1,this.loader=null},Potree.PointCloudOctreeGeometryNode=function(e,t,i){this.id=Potree.PointCloudOctreeGeometryNode.IDCount++,this.name=e,this.index=parseInt(e.charAt(e.length-1)),this.pcoGeometry=t,this.geometry=null,this.boundingBox=i,this.boundingSphere=i.getBoundingSphere(),this.children={},this.numPoints=0,this.level=null},Potree.PointCloudOctreeGeometryNode.IDCount=0,Potree.PointCloudOctreeGeometryNode.prototype.getURL=function(){var e="",t=this.pcoGeometry.loader.version;return t.equalOrHigher("1.5")?e=this.pcoGeometry.octreeDir+"/"+this.getHierarchyPath()+"/"+this.name:t.equalOrHigher("1.4")?e=this.pcoGeometry.octreeDir+"/"+this.name:t.upTo("1.3")&&(e=this.pcoGeometry.octreeDir+"/"+this.name),e},Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath=function(){for(var e="r/",t=this.pcoGeometry.hierarchyStepSize,i=this.name.substr(1),o=Math.floor(i.length/t),n=0;o>n;n++)e+=i.substr(n*t,t)+"/";return e=e.slice(0,-1)},Potree.PointCloudOctreeGeometryNode.prototype.addChild=function(e){this.children[e.index]=e,e.parent=this},Potree.PointCloudOctreeGeometryNode.prototype.load=function(){this.loading===!0||this.pcoGeometry.numNodesLoading>3||(this.loading=!0,this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.version.equalOrHigher("1.5")&&this.level%this.pcoGeometry.hierarchyStepSize===0&&this.hasChildren?this.loadHierachyThenPoints():this.loadPoints())},Potree.PointCloudOctreeGeometryNode.prototype.loadPoints=function(){this.pcoGeometry.loader.load(this) +},Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints=function(){var e=this,t=function(e,t){var i=(t.byteLength/5,new DataView(t)),o=[],n=i.getUint8(0),r=i.getUint32(1,!0);e.numPoints=r,o.push({children:n,numPoints:r,name:e.name});for(var a=[],s=5;o.length>0;){for(var l=o.shift(),d=1,c=0;8>c;c++){if(0!==(l.children&d)){var h=l.name+c,u=i.getUint8(s),p=i.getUint32(s+1,!0);o.push({children:u,numPoints:p,name:h}),a.push({children:u,numPoints:p,name:h}),s+=5}d=2*d}if(s===t.byteLength)break}var m={};m[e.name]=e;for(var f=e.pcoGeometry,c=0;c0,y.addChild(R),m[v]=R}e.loadPoints()};if(e.level%e.pcoGeometry.hierarchyStepSize===0){var i=e.pcoGeometry.octreeDir+"/"+e.getHierarchyPath()+"/"+e.name+".hrc",o=new XMLHttpRequest;o.open("GET",i,!0),o.responseType="arraybuffer",o.overrideMimeType("text/plain; charset=x-user-defined"),o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status||0===o.status){var i=o.response;t(e,i)}else console.log("Failed to load file! HTTP status: "+o.status+", file: "+url)};try{o.send(null)}catch(n){console.log("fehler beim laden der punktwolke: "+n)}}},Potree.PointCloudOctreeGeometryNode.prototype.dispose=function(){this.geometry&&(this.geometry.dispose(),this.geometry=null,this.loaded=!1)},Potree.utils=function(){},Potree.utils.pathExists=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),200!==t.status?!1:!0},Potree.utils.computeTransformedBoundingBox=function(e,t){var i=[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)],o=new THREE.Box3;return o.setFromPoints(i),o},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"}),i=new Worker(URL.createObjectURL(t));return i},Potree.utils.loadSkybox=function(e){var t=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,1,1e5),i=new THREE.Scene,o=".jpg",n=[e+"px"+o,e+"nx"+o,e+"py"+o,e+"ny"+o,e+"pz"+o,e+"nz"+o],r=THREE.ImageUtils.loadTextureCube(n,THREE.CubeRefractionMapping),a={uniforms:{tCube:{type:"t",value:r},tFlip:{type:"f",value:-1}},vertexShader:THREE.ShaderLib.cube.vertexShader,fragmentShader:THREE.ShaderLib.cube.fragmentShader},s=new THREE.ShaderMaterial({fragmentShader:a.fragmentShader,vertexShader:a.vertexShader,uniforms:a.uniforms,depthWrite:!1,side:THREE.BackSide}),l=new THREE.Mesh(new THREE.BoxGeometry(100,100,100),s);return i.add(l),{camera:t,scene:i}},Potree.utils.createGrid=function(e,t,i,o){for(var n=new THREE.LineBasicMaterial({color:o||8947848}),r=new THREE.Geometry,a=0;t>=a;a++)r.vertices.push(new THREE.Vector3(-(i*e)/2,0,a*i-i*t/2)),r.vertices.push(new THREE.Vector3(+(i*e)/2,0,a*i-i*t/2));for(var a=0;e>=a;a++)r.vertices.push(new THREE.Vector3(a*i-i*e/2,0,-(i*t)/2)),r.vertices.push(new THREE.Vector3(a*i-i*e/2,0,+(i*t)/2));var s=new THREE.Line(r,n,THREE.LinePieces);return s.receiveShadow=!0,s},Potree.utils.createBackgroundTexture=function(e,t){function i(e,t){return 1/(2*Math.PI)*Math.exp(-(e*e+t*t)/2)}var o=THREE.ImageUtils.generateDataTexture(e,t,new THREE.Color);o.magFilter=THREE.NearestFilter;for(var n=o.image.data,r=[1,1.5,1.7],a=i(0,0),s=0;e>s;s++)for(var l=0;t>l;l++){var d=2*(s/e)-1,c=2*(l/t)-1,h=s+e*l,u=i(2*d,2*c)/a,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 o},Potree.utils.topView=function(e,t,i){if(e.position.set(0,1,0),e.rotation.set(-Math.PI/2,0,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(e.position.x,o.center.y,e.position.z);t.target.copy(n)}},Potree.utils.frontView=function(e,t,i){if(e.position.set(0,0,1),e.rotation.set(0,0,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(e.position.x,e.position.y,o.center.z);t.target.copy(n)}},Potree.utils.leftView=function(e,t,i){if(e.position.set(-1,0,0),e.rotation.set(0,-Math.PI/2,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(o.center.x,e.position.y,e.position.z);t.target.copy(n)}},Potree.utils.rightView=function(e,t,i){if(e.position.set(1,0,0),e.rotation.set(0,Math.PI/2,0),e.zoomTo(i,1),t.target){var o=i.boundingSphere.clone().applyMatrix4(i.matrixWorld),n=new THREE.Vector3(o.center.x,e.position.y,e.position.z);t.target.copy(n)}},Potree.utils.frustumSphereIntersection=function(e,t){for(var i=e.planes,o=t.center,n=-t.radius,r=Number.MAX_VALUE,a=0;6>a;a++){var s=i[a].distanceToPoint(o);if(n>s)return 0;r=Math.min(r,s)}return r>=t.radius?2:1},Potree.Features=function(){var e,t=document.createElement("canvas"),i=t.getContext("webgl")||t.getContext("experimental-webgl"),o=i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.HIGH_FLOAT),n=i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT),r=(i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.LOW_FLOAT),i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT)),a=i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT),s=(i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.LOW_FLOAT),o.precision>0&&r.precision>0),l=n.precision>0&&a.precision>0;return e=s?"highp":l?"mediump":"lowp",{SHADER_INTERPOLATION:{isSupported:function(){var e=!0;return e=e&&i.getExtension("EXT_frag_depth"),e=e&&i.getParameter(i.MAX_VARYING_VECTORS)>=8}},SHADER_SPLATS:{isSupported:function(){var e=!0;return e=e&&i.getExtension("EXT_frag_depth"),e=e&&i.getExtension("OES_texture_float"),e=e&&i.getParameter(i.MAX_VARYING_VECTORS)>=8}},precision:e}}(),Potree.TextSprite=function(e){THREE.Object3D.call(this);var t=new THREE.Texture;t.minFilter=THREE.LinearFilter,t.magFilter=THREE.LinearFilter;var i=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});this.material=i,this.sprite=new THREE.Sprite(i),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 i=t.measureText(this.text),o=i.width,n=o+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,o+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 a=new THREE.Texture(e);a.minFilter=THREE.LinearFilter,a.magFilter=THREE.LinearFilter,a.needsUpdate=!0,this.sprite.material.map=a,this.sprite.scale.set(.01*n,.01*r,1)},Potree.TextSprite.prototype.roundRect=function(e,t,i,o,n,r){e.beginPath(),e.moveTo(t+r,i),e.lineTo(t+o-r,i),e.quadraticCurveTo(t+o,i,t+o,i+r),e.lineTo(t+o,i+n-r),e.quadraticCurveTo(t+o,i+n,t+o-r,i+n),e.lineTo(t+r,i+n),e.quadraticCurveTo(t,i+n,t,i+n-r),e.lineTo(t,i+r),e.quadraticCurveTo(t,i,t+r,i),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.Measure=function(){var e=this;THREE.Object3D.call(this),this.points=[],this._showDistances=!0,this._showArea=!0,this._closed=!0,this.maxMarkers=Number.MAX_SAFE_INTEGER,this.spheres=[],this.edges=[],this.sphereLabels=[],this.edgeLabels=[],this.angleLabels=[],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,this.add(this.areaLabel);var t=new THREE.SphereGeometry(.4,10,10);this.color=new THREE.Color(16711680);var i=function(){var t=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:e.color,ambient:11184810,depthTest:!1,depthWrite:!1});return t},o=function(e){e.target.material.emissive.setHex(8947848)},n=function(e){e.target.material.emissive.setHex(0)},r=function(t){var i=t.tool,o=(i.dragstart,i.mouse,i.getMousePointCloudIntersection());if(o){var n=e.spheres.indexOf(i.dragstart.object);e.setPosition(n,o)}},a=function(){};this.addMarker=function(e){this.points.push(e);var s=new THREE.Mesh(t,i());s.addEventListener("move",o),s.addEventListener("leave",n),s.addEventListener("drag",r),s.addEventListener("drop",a),this.add(s),this.spheres.push(s);var l=new THREE.Geometry;l.vertices.push(new THREE.Vector3,new THREE.Vector3),l.colors.push(this.color,this.color,this.color);var d=new THREE.LineBasicMaterial({linewidth:1});d.depthTest=!1;var c=new THREE.Line(l,d);c.visible=!0,this.add(c),this.edges.push(c);var h=new Potree.TextSprite(0);h.setBorderColor({r:0,g:255,b:0,a:0}),h.setBackgroundColor({r:0,g:255,b:0,a:0}),h.material.depthTest=!1,h.visible=!1,this.edgeLabels.push(h),this.add(h);var u=new Potree.TextSprite;u.setBorderColor({r:0,g:255,b:0,a:0}),u.setBackgroundColor({r:0,g:255,b:0,a:0}),u.material.depthTest=!1,u.material.opacity=1,u.visible=!1,this.angleLabels.push(u),this.add(u);var p={type:"marker_added",measurement:this};this.dispatchEvent(p),this.setPosition(this.points.length-1,e)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]);var t=0==e?0:e-1;this.remove(this.edges[t]),this.edges.splice(t,1),this.remove(this.edgeLabels[t]),this.edgeLabels.splice(t,1),this.spheres.splice(e,1),this.update()},this.setPosition=function(e,t){var i=this.points[e];i.copy(t);var o={type:"marker_moved",measure:this,index:e,position:t.clone()};this.dispatchEvent(o),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,i=0;i=n;n++){var t=this.points[n];o.add(t)}o.divideScalar(this.points.length);for(var n=0;i>=n;n++){var r=n,a=n+1>i?0:n+1,s=0===n?i:n-1,t=this.points[r],l=this.points[a],d=this.points[s],c=this.spheres[r];c.position.copy(t),c.material.color=e.color;var h=this.edges[r];h.material.color=this.color,h.geometry.vertices[0].copy(t),h.geometry.vertices[1].copy(l),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere(),h.visible=i>r||this.closed;var u=this.edgeLabels[n],p=(new THREE.Vector3).add(t);p.add(l),p=p.multiplyScalar(.5);var m=t.distanceTo(l);u.position.copy(p),u.setText(m.toFixed(2)),u.visible=this.showDistances&&(i>r||this.closed)&&this.points.length>=2&&m>0;var f=this.angleLabels[n],v=this.getAngleBetweenLines(t,d,l),g=l.clone().sub(d);g.multiplyScalar(.5),g=d.clone().add(g).sub(t).normalize();var E=Math.min(t.distanceTo(d),t.distanceTo(l));E/=9;var y=t.clone().add(g.multiplyScalar(E));f.position.copy(y);var b=Potree.utils.addCommas((v*(180/Math.PI)).toFixed(1))+"°";f.setText(b),f.visible=this.showAngles&&(i>r||this.closed)&&this.points.length>=3&&v>0}this.areaLabel.position.copy(o),this.areaLabel.visible=this.showArea&&this.points.length>=3;var b=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(b)}},this.raycast=function(e,t){for(var i=0;ic.activeMeasurement.maxMarkers&&c.finishInsertion()}}}function n(e){var t=c.domElement.getBoundingClientRect();if(c.mouse.x=(e.clientX-t.left)/c.domElement.clientWidth*2-1,c.mouse.y=2*-((e.clientY-t.top)/c.domElement.clientHeight)+1,c.dragstart){var i={type:"drag",event:e,tool:c};c.dragstart.object.dispatchEvent(i)}else if(u==h.INSERT&&c.activeMeasurement){var o=c.getMousePointCloudIntersection();if(o){var n=c.activeMeasurement.points.length-1;c.activeMeasurement.setPosition(n,o)}}else{var o=d();o?(o.object.dispatchEvent({type:"move",target:o.object,event:e}),c.hoveredElement&&c.hoveredElement!==o.object&&c.hoveredElement.dispatchEvent({type:"leave",target:c.hoveredElement,event:e}),c.hoveredElement=o.object):(c.hoveredElement&&c.hoveredElement.dispatchEvent({type:"leave",target:c.hoveredElement,event:e}),c.hoveredElement=null)}}function r(){u==h.INSERT&&c.finishInsertion()}function a(e){if(1===e.which){u!==h.DEFAULT&&e.stopImmediatePropagation();var t=d();t&&(c.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:c.sceneRoot.position.clone(),mousePos:{x:c.mouse.x,y:c.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&r(e)}function s(){window.getSelection?window.getSelection().removeAllRanges():document.selection&&document.selection.empty(),c.activeMeasurement&&u===h.INSERT&&(c.activeMeasurement.removeMarker(c.activeMeasurement.points.length-1),c.finishInsertion())}function l(e){c.dragstart&&(c.dragstart.object.dispatchEvent({type:"drop",event:e}),c.dragstart=null)}function d(){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 i=[],o=0;o0?a[0]:!1}var c=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=i,this.domElement=i.domElement,this.mouse={x:0,y:0};var h={DEFAULT:0,INSERT:1},u=h.DEFAULT;this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null,this.getState=function(){return u},this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),i=new THREE.Ray(c.camera.position,t),o=[];c.scene.traverse(function(e){(e instanceof Potree.PointCloudOctree||e instanceof Potree.PointCloudArena4D)&&o.push(e)});for(var n=null,r=null,a=0;ad)&&(n=l,r=d)}}return n?n.position:null},this.startInsertion=function(e){u=h.INSERT;var e=e||{},t="undefined"!=typeof e.showDistances?e.showDistances:!0,i="undefined"!=typeof e.showArea?e.showArea:!1,o="undefined"!=typeof e.showAngles?e.showAngles:!1,n="undefined"!=typeof e.closed?e.closed:!1,r=e.maxMarkers||Number.MAX_SAFE_INTEGER,a=new Potree.Measure;a.showDistances=t,a.showArea=i,a.showAngles=o,a.closed=n,a.maxMarkers=r,this.addMeasurement(a),a.addMarker(new THREE.Vector3(0,0,0)),this.activeMeasurement=a},this.finishInsertion=function(){this.activeMeasurement.removeMarker(this.activeMeasurement.points.length-1);var e={type:"insertion_finished",measurement:this.activeMeasurement};this.dispatchEvent(e),this.activeMeasurement=null,u=h.DEFAULT},this.addMeasurement=function(e){this.sceneMeasurement.add(e),this.measurements.push(e),this.dispatchEvent({type:"measurement_added",measurement:e}),e.addEventListener("marker_added",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_removed",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_moved",function(e){c.dispatchEvent(e)})},this.removeMeasurement=function(e){this.sceneMeasurement.remove(e);var t=this.measurements.indexOf(e);t>=0&&this.measurements.splice(t,1)},this.reset=function(){for(var e=this.measurements.length-1;e>=0;e--){var t=this.measurements[e];this.removeMeasurement(t)}},this.update=function(){for(var e=[],t=0;t1){var d=new THREE.Geometry;d.vertices.push(new THREE.Vector3,new THREE.Vector3),d.colors.push(i,i,i);var c=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2,transparent:!0,opacity:.4});c.depthTest=!1;var h=new THREE.Line(d,c);h.visible=!1,this.add(h),this.edges.push(h);var u=new THREE.BoxGeometry(1,1,1),p=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),m=new THREE.Mesh(u,p);m.visible=!1,this.add(m),this.boxes.push(m)}var f={type:"marker_added",profile:this};this.dispatchEvent(f),this.setPosition(this.points.length-1,e)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]);var t=0==e?0:e-1;this.remove(this.edges[t]),this.edges.splice(t,1),this.remove(this.boxes[t]),this.boxes.splice(t,1),this.spheres.splice(e,1),this.update();var i={type:"marker_removed",profile:this};this.dispatchEvent(i)},this.getArea=function(){for(var e=0,t=this.points.length-1,i=0;i=r;r++){{var e=this.points[r],a=this.spheres[r],s=0===r?n:r-1,l=r===n?0:r+1,d=this.points[s],c=this.points[l],h=this.edges[s],u=this.edges[r],p=this.boxes[s];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(a.position.copy(e),a.visible=this._modifiable?!0:!1,h&&(h.geometry.vertices[1].copy(e),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere()),u&&(u.geometry.vertices[0].copy(e),u.geometry.verticesNeedUpdate=!0,u.geometry.computeBoundingSphere()),p){var m=d,f=e,v=m.clone().setY(0).distanceTo(f.clone().setY(0));p.scale.set(v,this.height,this.width);var g=(new THREE.Vector3).addVectors(m,f).multiplyScalar(.5),E=(new THREE.Vector3).subVectors(f,m),y=new THREE.Vector3(E.z,0,-E.x);p.position.set(0,0,0),p.lookAt(y),p.position.copy(g)}o.add(e),t.min(e),i.max(e)}o.multiplyScalar(1/this.points.length);for(var r=0;r0?i[0]:!1}var c=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=i,this.domElement=i.domElement,this.mouse={x:0,y:0};{var h={DEFAULT:0,INSERT:1},u=h.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeProfile,this.profiles=[],this.sceneProfile=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneProfile.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneProfile.add(this.light),this.hoveredElement=null,this.getMousePointCloudIntersection=function(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),i=new THREE.Ray(c.camera.position,t),o=[];c.scene.traverse(function(e){(e instanceof Potree.PointCloudOctree||e instanceof Potree.PointCloudArena4D)&&o.push(e)});for(var n=null,r=null,a=0;ad)&&(n=l,r=d)}}return n?n.position:null},this.startInsertion=function(e){u=h.INSERT;var e=e||{},t=e.clip||!1,i=e.width||1;return this.activeProfile=new Potree.HeightProfile,this.activeProfile.clip=t,this.activeProfile.setWidth(i),this.addProfile(this.activeProfile),this.activeProfile.addMarker(new THREE.Vector3(0,0,0)),this.activeProfile},this.finishInsertion=function(){this.activeProfile.removeMarker(this.activeProfile.points.length-1);var e={type:"insertion_finished",profile:this.activeProfile};this.dispatchEvent(e),this.activeProfile=null,u=h.DEFAULT},this.addProfile=function(e){this.profiles.push(e),this.sceneProfile.add(e),e.update(),this.dispatchEvent({type:"profile_added",profile:e}),e.addEventListener("marker_added",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_removed",function(e){c.dispatchEvent(e)}),e.addEventListener("marker_moved",function(e){c.dispatchEvent(e)})},this.removeProfile=function(e){this.sceneProfile.remove(e);var t=this.profiles.indexOf(e);t>=0&&this.profiles.splice(t,1),this.dispatchEvent({type:"profile_removed",profile:e})},this.reset=function(){for(var e=this.profiles.length-1;e>=0;e--){var t=this.profiles[e];this.removeProfile(t)}},this.update=function(){for(var e=0;e0?o[0]:!1}}var s=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=i,this.domElement=i.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=s.createArrow(s.parts.ARROW_X,s.parts.ARROW_X.color); +e.rotation.z=-Math.PI/2;var t=s.createArrow(s.parts.ARROW_Y,s.parts.ARROW_Y.color),i=s.createArrow(s.parts.ARROW_Z,s.parts.ARROW_Z.color);i.rotation.x=-Math.PI/2,this.translationNode.add(e),this.translationNode.add(t),this.translationNode.add(i)},this.buildScaleNode=function(){var e=this.createScaleHandle(s.parts.SCALE_X,16711680);e.rotation.z=-Math.PI/2;var t=this.createScaleHandle(s.parts.SCALE_Y,65280),i=this.createScaleHandle(s.parts.SCALE_Z,255);i.rotation.x=-Math.PI/2,this.scaleNode.add(e),this.scaleNode.add(t),this.scaleNode.add(i)},this.buildRotationNode=function(){var e=this.createRotationCircle(s.parts.ROTATE_X,16711680);e.rotation.y=-Math.PI/2;var t=this.createRotationCircle(s.parts.ROTATE_Y,65280),i=this.createRotationCircle(s.parts.ROTATE_Z,255);t.rotation.x=-Math.PI/2,this.rotationNode.add(e),this.rotationNode.add(t),this.rotationNode.add(i);var o=new THREE.SphereGeometry(2.9,24,24),n=new THREE.Mesh(o,new THREE.MeshBasicMaterial({color:11184810,transparent:!0,opacity:.4}));this.sceneRotation.add(n);var r=function(){n.material.color.setHex(5592405)},a=function(){n.material.color.setHex(11184810)},l=function(e){e.event.stopImmediatePropagation();for(var t=new THREE.Vector3(s.dragstart.mousePos.x,s.dragstart.mousePos.y,.1),i=new THREE.Vector3(s.mouse.x,s.mouse.y,.1),o=(new THREE.Vector3).subVectors(i,t),n=t.clone().unproject(s.camera),r=i.clone().unproject(s.camera),a=(new THREE.Vector3).subVectors(r,n),l=a.clone().normalize(),d=(new THREE.Vector3).subVectors(s.camera.position,n).normalize(),c=d.clone().cross(l),h=6*o.length(),u=0;u=n;n++){var r=2*Math.PI*n/o,a=3*Math.cos(r),l=3*Math.sin(r);i.push(new THREE.Vector3(a,l,0))}for(var d=new THREE.Geometry,n=0;nt;t++)n.label.children[t].updateMatrixWorld(!0)},this.setDimension=function(e,t,i){this.dimension.set(e,t,i),this.box.scale.set(e,t,i),this.frame.scale.set(e,t,i)},this.volume=function(){return Math.abs(this.scale.x*this.scale.y*this.scale.z)},this.update=function(){this.boundingBox=this.box.geometry.boundingBox,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)},this.raycast=function(e,t){var i=[];if(this.box.raycast(e,i),i.length>0){var o=i[0];t.push({distance:o.distance,object:this,point:o.point.clone()})}},this.update()},Potree.Volume.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(Potree.Volume.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this.update()}}),Object.defineProperty(Potree.Volume.prototype,"modifiable",{get:function(){return this._modifiable},set:function(e){this._modifiable=e,this.update()}}),Potree.VolumeTool=function(e,t,i){function o(e){var t=d.domElement.getBoundingClientRect();d.mouse.x=(e.clientX-t.left)/d.domElement.clientWidth*2-1,d.mouse.y=2*-((e.clientY-t.top)/d.domElement.clientHeight)+1}function n(){}function r(e){if(h!==c.DEFAULT&&e.stopImmediatePropagation(),h===c.INSERT_VOLUME)d.finishInsertion();else if(1===e.which){var t=s();t&&t.object.modifiable&&transformationTool.setTargets([t.object])}3===e.which}function a(e){return e.preventDefault(),!1}function s(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=new THREE.Raycaster;t.ray.set(d.camera.position,e.sub(d.camera.position).normalize());for(var i=[],o=0;o0?r[0]:!1}function l(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=e.sub(d.camera.position).normalize(),i=new THREE.Ray(d.camera.position,t),o=[];d.scene.traverse(function(e){(e instanceof Potree.PointCloudOctree||e instanceof Potree.PointCloudArena4D)&&o.push(e)});for(var n=null,r=null,a=0;ac)&&(n=l,r=c)}}return n?n.position:null}var d=this;this.enabled=!1,this.scene=e,this.sceneVolume=new THREE.Scene,this.camera=t,this.renderer=i,this.domElement=i.domElement,this.mouse={x:0,y:0},this.volumes=[];var c={DEFAULT:0,INSERT_VOLUME:1},h=c.DEFAULT;this.update=function(){if(h===c.INSERT_VOLUME){var e=l();if(e){this.activeVolume.position.copy(e);var t=this.activeVolume.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),o=(new THREE.Vector4(t.x,t.y,t.z).applyMatrix4(this.camera.projectionMatrix),Math.abs(t.z/10));this.activeVolume.scale.set(o,o,o)}}for(var n=[],r=0;r=0&&this.volumes.splice(t,1)},this.reset=function(){for(var e=this.volumes.length-1;e>=0;e--){var t=this.volumes[e];this.removeVolume(t)}},this.render=function(){i.render(this.sceneVolume,this.camera)},this.domElement.addEventListener("click",n,!1),this.domElement.addEventListener("mousedown",r,!1),this.domElement.addEventListener("mousemove",o,!1),this.domElement.addEventListener("contextmenu",a,!1)},Potree.VolumeTool.prototype=Object.create(THREE.EventDispatcher.prototype),Potree.PointCloudArena4DProxyNode=function(e){THREE.Object3D.call(this),this.geometryNode=e,this.pcoGeometry=e,this.boundingBox=e.boundingBox,this.boundingSphere=e.boundingSphere,this.number=e.name,this.numPoints=e.numPoints,this.level=e.level},Potree.PointCloudArena4DProxyNode.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudArena4D=function(e){THREE.Object3D.call(this),this.root=null,this.visiblePointsTarget=2e6,this.minimumNodePixelSize=150,this.position.sub(e.offset),this.updateMatrix(),this.numVisibleNodes=0,this.numVisiblePoints=0,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleNodes=[],this.pcoGeometry=e,this.boundingBox=this.pcoGeometry.boundingBox,this.boundingSphere=this.pcoGeometry.boundingSphere,this.material=new Potree.PointCloudMaterial({vertexColors:THREE.VertexColors,size:.05,treeType:Potree.TreeType.KDTREE}),this.material.sizeType=Potree.PointSizeType.ATTENUATED,this.material.size=.05,this.pickTarget,this.pickMaterial,this.updateMatrixWorld()},Potree.PointCloudArena4D.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudArena4D.prototype.updateMaterial=function(e,t){this.material.fov=e.fov*(Math.PI/180),this.material.screenWidth=t.domElement.clientWidth,this.material.screenHeight=t.domElement.clientHeight,this.material.spacing=this.pcoGeometry.spacing,this.material.near=e.near,this.material.far=e.far,this.maxLevel>this.material.levels&&(this.material.levels=this.maxLevel+2),this.material.minSize=3;var i=this.boundingBox.size();this.material.bbSize=[i.x,i.y,i.z]},Potree.PointCloudArena4D.prototype.hideDescendants=function(e){for(var t=[],i=0;i0;){var e=t.shift();e.visible=!1,e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);for(var i=0;i0;){var v=f.shift(),g=v.node,E=v.weight;g.matrixWorld.multiplyMatrices(this.matrixWorld,g.matrix);var y=g.boundingBox.clone(),b=a.intersectsBox(y),T=b;if(g.visible=T,T){var R=0;if(8===R&&dbgFullyInside++,g instanceof Potree.PointCloudArena4DProxyNode){var P=g.geometryNode;P.loaded===!0?this.replaceProxy(g):this.loadQueue.push(v)}else if(g instanceof THREE.PointCloud){if(this.numVisiblePoints+g.pcoGeometry.numPoints>pointcloud.visiblePointsTarget)break;if(this.numVisibleNodes++,this.numVisiblePoints+=g.pcoGeometry.numPoints,this.visibleNodes.push({node:g,weight:E}),this.showBoundingBox&&!g.boundingBoxNode){var x=new THREE.BoxHelper(g);this.add(x),this.boundingBoxNodes.push(x),g.boundingBoxNode=x,g.boundingBoxNode.matrixWorld.copy(g.matrixWorld)}else this.showBoundingBox&&g.boundingBoxNode?g.boundingBoxNode.visible=!0:this.showBoundingBox||delete g.boundingBoxNode;for(var n=0;nH&&(A=Number.MAX_VALUE);var V=t.domElement.clientHeight*A;if(!(Vf[I].weight){var B=I;break}if(I==f.length-1){B=f.length;break}}f.splice(B,0,{node:C,weight:E})}}}}}}this.updateLoadQueue(),this.maxLevel=0;for(var n=0;n0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0&&!(t.length>12);){var d=s.shift(),c=d.boundingBox.clone();c.max.sub(c.min),c.min.sub(c.min);var h=i.intersectsBox(c),u=h;if(u){if(l+d.numPoints>this.visiblePointsTarget)break;l+=d.numPoints,t.push(d),d.loaded&&(d.left&&s.push(d.left),d.right&&s.push(d.right))}}return t},Potree.PointCloudArena4D.prototype.nodesOnRay=function(e,t){for(var i=[],o=t.clone(),n=0;n0&&r.push(r[0]);for(var h=0;hP;P++)for(var x=0;n>x;x++){var C=P+x*n,w=Math.pow(P-(n-1)/2,2)+Math.pow(x-(n-1)/2,2),H=y[4*C+3];y[4*C+3]=0;var S=b[C];(0!==S||0!==H)&&T>w&&(R={pIndex:S,pcIndex:H},T=w)}if(R){var M={},A=r[R.pcIndex],V=A.geometry.attributes;for(var B in V)if(V.hasOwnProperty(B)){var I=p.attributes[B];if("position"===B){var L=A.geometry.attributes.position.array,G=L[3*R.pIndex+0],W=L[3*R.pIndex+1],N=L[3*R.pIndex+2],O=new THREE.Vector3(G,W,N);O.applyMatrix4(this.matrixWorld),M[B]=O}else if("indices"===B);else if(1===I.itemSize)M[B]=I.array[h+D];else{for(var _=[],D=0;Dn?-1:n>r?1:0};t.sort(n);for(var r=[],a=0;a0&&(l+=1,d=r.indexOf(s.pcoGeometry.left.number)-a),s.pcoGeometry.right&&r.indexOf(s.pcoGeometry.right.number)>0&&(l+=2,d=0===d?r.indexOf(s.pcoGeometry.right.number)-a:d),"X"===s.pcoGeometry.split?c=1:"Y"===s.pcoGeometry.split?c=2:"Z"===s.pcoGeometry.split&&(c=4),o[3*a+0]=l,o[3*a+1]=d,o[3*a+2]=c}e.uniforms.nodeSize.value=this.pcoGeometry.boundingBox.size().x,i.needsUpdate=!0}},Object.defineProperty(Potree.PointCloudArena4D.prototype,"progress",{get:function(){return this.pcoGeometry.root?Potree.PointCloudArena4DGeometryNode.nodesLoading>0?0:1:0}}),Potree.PointCloudArena4DGeometryNode=function(){this.left=null,this.right=null,this.boundingBox=null,this.number=null,this.pcoGeometry=null,this.loaded=!1,this.numPoints=0,this.level=0},Potree.PointCloudArena4DGeometryNode.nodesLoading=0,Potree.PointCloudArena4DGeometryNode.prototype.load=function(){if(!(this.loaded||this.loading||Potree.PointCloudArena4DGeometryNode.nodesLoading>=5)){Potree.PointCloudArena4DGeometryNode.nodesLoading++;var e=this.pcoGeometry.url+"?node="+this.number,t=new XMLHttpRequest;t.open("GET",e,!0),t.responseType="arraybuffer";var i=this;t.onreadystatechange=function(){if(4===t.readyState&&200===t.status){for(var e=t.response,o=new DataView(e),n=e.byteLength/17,r=new Float32Array(3*n),a=new Float32Array(3*n),s=new Uint32Array(n),l=0;n>l;l++){var d=o.getFloat32(17*l+0,!0)+i.boundingBox.min.x,c=o.getFloat32(17*l+4,!0)+i.boundingBox.min.y,h=o.getFloat32(17*l+8,!0)+i.boundingBox.min.z,u=o.getUint8(17*l+12,!0)/256,p=o.getUint8(17*l+13,!0)/256,m=o.getUint8(17*l+14,!0)/256;r[3*l+0]=d,r[3*l+1]=c,r[3*l+2]=h,a[3*l+0]=u,a[3*l+1]=p,a[3*l+2]=m,s[l]=l}var f=new THREE.BufferGeometry;f.addAttribute("position",new THREE.BufferAttribute(r,3)),f.addAttribute("color",new THREE.BufferAttribute(a,3)),f.addAttribute("indices",new THREE.BufferAttribute(s,1)),f.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(3*n),3)),i.geometry=f,i.loaded=!0,Potree.PointCloudArena4DGeometryNode.nodesLoading--,f.boundingBox=i.boundingBox,f.boundingSphere=i.boundingSphere,i.numPoints=n}},t.send(null)}},Potree.PointCloudArena4DGeometry=function(){this.numPoints=0,this.version=0,this.boundingBox=null,this.numNodes=0,this.name=null,this.provider=null,this.url=null,this.root=null,this.levels=0,this._spacing=null,this.pointAttributes=new PointAttributes(["POSITION_CARTESIAN","COLOR_PACKED"])},Potree.PointCloudArena4DGeometry.load=function(e,t){var i=new XMLHttpRequest;i.open("GET",e+"?info",!0),i.onreadystatechange=function(){try{if(4===i.readyState&&200===i.status){var o=JSON.parse(i.responseText),n=new Potree.PointCloudArena4DGeometry;n.url=e,n.name=o.Name,n.provider=o.Provider,n.numNodes=o.Nodes,n.numPoints=o.Points,n.version=o.Version,n.boundingBox=new THREE.Box3((new THREE.Vector3).fromArray(o.BoundingBox.slice(0,3)),(new THREE.Vector3).fromArray(o.BoundingBox.slice(3,6))),o.Spacing&&(n.spacing=o.Spacing);var r=n.boundingBox.min.clone().multiplyScalar(-1);n.boundingBox.min.add(r),n.boundingBox.max.add(r),n.offset=r;var a=n.boundingBox.center(),s=n.boundingBox.size().length()/2;n.boundingSphere=new THREE.Sphere(a,s),n.loadHierarchy(),t(n)}else 4===i.readyState&&t(null)}catch(l){t(null)}},i.send(null)},Potree.PointCloudArena4DGeometry.prototype.loadHierarchy=function(){var e=this.url+"?tree",t=new XMLHttpRequest;t.open("GET",e,!0),t.responseType="arraybuffer";var i=this;t.onreadystatechange=function(){if(4===t.readyState&&200===t.status){for(var e=t.response,o=e.byteLength/3,n=new DataView(e),r=[],a=null,s=0,l=((new Date).getTime(),0);o>l;l++){var d=n.getUint8(3*l+0,!0),c=(n.getUint16(3*l+1,!0),(1&d)>0),h=(2&d)>0,u=(4&d)>0,p=(8&d)>0,m=(16&d)>0,f=null;u?f="X":p&&(f="Y"),m&&(f="Z");var v=new Potree.PointCloudArena4DGeometryNode;if(v.hasLeft=c,v.hasRight=h,v.split=f,v.isLeaf=!c&&!h,v.number=l,v.left=null,v.right=null,v.pcoGeometry=i,v.level=r.length,s=Math.max(s,v.level),r.length>0){var g=r[r.length-1];v.boundingBox=g.boundingBox.clone();var E=g.boundingBox.size();if(g.hasLeft&&!g.left){g.left=v,"X"===g.split?v.boundingBox.max.x=v.boundingBox.min.x+E.x/2:"Y"===g.split?v.boundingBox.max.y=v.boundingBox.min.y+E.y/2:"Z"===g.split&&(v.boundingBox.max.z=v.boundingBox.min.z+E.z/2);var y=v.boundingBox.center(),b=v.boundingBox.size().length()/2;v.boundingSphere=new THREE.Sphere(y,b)}else{g.right=v,"X"===g.split?v.boundingBox.min.x=v.boundingBox.min.x+E.x/2:"Y"===g.split?v.boundingBox.min.y=v.boundingBox.min.y+E.y/2:"Z"===g.split&&(v.boundingBox.min.z=v.boundingBox.min.z+E.z/2);var y=v.boundingBox.center(),b=v.boundingBox.size().length()/2;v.boundingSphere=new THREE.Sphere(y,b)}}else{a=v,a.boundingBox=i.boundingBox.clone();var y=a.boundingBox.center(),b=a.boundingBox.size().length()/2;a.boundingSphere=new THREE.Sphere(y,b)}var T=v.boundingBox.size();if(v.spacing=(T.x+T.y+T.z)/3/75,r.push(v),v.isLeaf)for(var R=!1;!R&&r.length>0;){r.pop();var P=r[r.length-1];R=r.length>0&&P.hasRight&&null==P.right}}{(new Date).getTime()}i.root=a,i.levels=s}},t.send(null)},Object.defineProperty(Potree.PointCloudArena4DGeometry.prototype,"spacing",{get:function(){return this._spacing?this._spacing:this.root?this.root.spacing:void 0},set:function(e){this._spacing=e}}); \ No newline at end of file diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index ca1cf2cd..22f35266 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -1067,13 +1067,6 @@ Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params) _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.UNSIGNED_BYTE, true, 0, 0 ); _gl.uniform1f(material.program.uniforms.pcIndex, material.pcIndex); - - // TODO: another ugly hack...disable normal attributes, if they're activated - var alNormal = _gl.getAttribLocation(program, "normal"); - if(alNormal >= 0){ - _gl.disableVertexAttribArray( alNormal ); - } - } renderer.renderBufferDirect(camera, [], null, material, geometry, object); diff --git a/src/arena4d/PointCloudArena4D.js b/src/arena4d/PointCloudArena4D.js index 3b09cb20..cf26636b 100644 --- a/src/arena4d/PointCloudArena4D.js +++ b/src/arena4d/PointCloudArena4D.js @@ -579,12 +579,6 @@ Potree.PointCloudArena4D.prototype.pick = function(renderer, camera, ray, params _gl.vertexAttribPointer( attributePointer, attributeSize, _gl.UNSIGNED_BYTE, true, 0, 0 ); _gl.uniform1f(material.program.uniforms.pcIndex, material.pcIndex); - - // TODO: another ugly hack...disable normal attributes, if they're activated - var alNormal = _gl.getAttribLocation(program, "normal"); - if(alNormal >= 0){ - _gl.disableVertexAttribArray( alNormal ); - } } renderer.renderBufferDirect(camera, [], null, material, geometry, object); diff --git a/src/arena4d/PointCloudArena4DGeometry.js b/src/arena4d/PointCloudArena4DGeometry.js index 01220383..953622a0 100644 --- a/src/arena4d/PointCloudArena4DGeometry.js +++ b/src/arena4d/PointCloudArena4DGeometry.js @@ -70,6 +70,7 @@ Potree.PointCloudArena4DGeometryNode.prototype.load = function(){ geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3)); geometry.addAttribute("color", new THREE.BufferAttribute(colors, 3)); geometry.addAttribute("indices", new THREE.BufferAttribute(indices, 1)); + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3)); scope.geometry = geometry; scope.loaded = true; diff --git a/src/loader/BinaryLoader.js b/src/loader/BinaryLoader.js index d8205a28..a567e8c5 100644 --- a/src/loader/BinaryLoader.js +++ b/src/loader/BinaryLoader.js @@ -83,6 +83,11 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ } geometry.addAttribute("indices", new THREE.BufferAttribute(new Float32Array(data.indices), 1)); + if(!geometry.attributes.normal){ + var buffer = new Float32Array(numPoints*3); + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3)); + } + geometry.boundingBox = node.boundingBox; node.geometry = geometry; node.loaded = true; diff --git a/src/loader/LasLazLoader.js b/src/loader/LasLazLoader.js index a0959f72..a3717d34 100644 --- a/src/loader/LasLazLoader.js +++ b/src/loader/LasLazLoader.js @@ -196,7 +196,8 @@ Potree.LasLazBatcher = function(node){ geometry.addAttribute('returnNumber', new THREE.BufferAttribute(new Float32Array(returnNumbers_f), 1)); geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(new Float32Array(pointSourceIDs_f), 1)); geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 1)); - //geometry.boundingBox = node.boundingBox; + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3)); + geometry.boundingBox = new THREE.Box3(mins, maxs); node.boundingBox = geometry.boundingBox; diff --git a/src/utils/MeasuringTool.js b/src/utils/MeasuringTool.js index be70996d..bbf97637 100644 --- a/src/utils/MeasuringTool.js +++ b/src/utils/MeasuringTool.js @@ -672,7 +672,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ this.render = function(){ this.update(); - renderer.render(this.sceneMeasurement, this.camera); + this.renderer.render(this.sceneMeasurement, this.camera); }; this.domElement.addEventListener( 'click', onClick, false);