diff --git a/README.md b/README.md index cfe59c51..ae87aa30 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,5 @@ Take a look at the [potree showcase](http://potree.org/wp/demo/) for some live e * [Three.js](https://github.com/mrdoob/three.js), the WebGL 3D rendering library on which potree is built. * [plas.io](http://plas.io/) point cloud viewer. LAS and LAZ support have been taken from the laslaz.js implementation of plas.io. Thanks to [Uday Verma](https://twitter.com/udaykverma) and [Howard Butler](https://twitter.com/howardbutler) for this! * [Harvest4D](https://harvest4d.org/) Potree currently runs as Master Thesis under the Harvest4D Project -* [Martin Isenburg](http://rapidlasso.com/), [Georepublic](http://georepublic.de/en/), [Sigeom Sa](http://www.sigeom.ch/), [SITN](http://www.ne.ch/sitn), [Pix4D](http://pix4d.com/) as well as all the contributers to potree and PotreeConverter and many more for their support. +* [Martin Isenburg](http://rapidlasso.com/), [Georepublic](http://georepublic.de/en/), +[Veesus](http://veesus.com/), [Sigeom Sa](http://www.sigeom.ch/), [SITN](http://www.ne.ch/sitn), [Pix4D](http://pix4d.com/) as well as all the contributers to potree and PotreeConverter and many more for their support. diff --git a/build/js/potree.js b/build/js/potree.js index 01e91966..295d78da 100644 --- a/build/js/potree.js +++ b/build/js/potree.js @@ -5,11 +5,10 @@ function Potree(){ } -Potree.pointLoadLimit = 50*1000*1000; - // contains WebWorkers with base64 encoded code Potree.workers = {}; +Potree.Shaders = {}; @@ -60,7 +59,588 @@ Potree.WorkerManager.fromUrls = function(urls){ return new Potree.WorkerManager(code); } -Potree.workers.binaryDecoder = new Potree.WorkerManager(atob("DQovLyBodHRwOi8vanNwZXJmLmNvbS91aW50OGFycmF5LXZzLWRhdGF2aWV3My8zDQpmdW5jdGlvbiBDdXN0b21WaWV3KGJ1ZmZlcikgew0KCXRoaXMuYnVmZmVyID0gYnVmZmVyOw0KCXRoaXMudTggPSBuZXcgVWludDhBcnJheShidWZmZXIpOw0KCQ0KCXZhciB0bXAgPSBuZXcgQXJyYXlCdWZmZXIoNCk7DQoJdmFyIHRt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RBdHRyaWJ1dGUpewoJdGhpcy5hdHRyaWJ1dGVzLnB1c2gocG9pbnRBdHRyaWJ1dGUpOwoJdGhpcy5ieXRlU2l6ZSArPSBwb2ludEF0dHJpYnV0ZS5ieXRlU2l6ZTsKCXRoaXMuc2l6ZSsrOwp9OwoKUG9pbnRBdHRyaWJ1dGVzLnByb3RvdHlwZS5oYXNDb2xvcnMgPSBmdW5jdGlvbigpewoJZm9yKHZhciBuYW1lIGluIHRoaXMuYXR0cmlidXRlcyl7CgkJdmFyIHBvaW50QXR0cmlidXRlID0gdGhpcy5hdHRyaWJ1dGVzW25hbWVdOwoJCWlmKHBvaW50QXR0cmlidXRlLm5hbWUgPT09IFBvaW50QXR0cmlidXRlTmFtZXMuQ09MT1JfUEFDS0VEKXsKCQkJcmV0dXJuIHRydWU7CgkJfQoJfQoJCglyZXR1cm4gZmFsc2U7Cn07CgpQb2ludEF0dHJpYnV0ZXMucHJvdG90eXBlLmhhc05vcm1hbHMgPSBmdW5jdGlvbigpewoJZm9yKHZhciBuYW1lIGluIHRoaXMuYXR0cmlidXRlcyl7CgkJdmFyIHBvaW50QXR0cmlidXRlID0gdGhpcy5hdHRyaWJ1dGVzW25hbWVdOwoJCWlmKHBvaW50QXR0cmlidXRlID09PSBQb2ludEF0dHJpYnV0ZS5OT1JNQUxfU1BIRVJFTUFQUEVEIHx8IHBvaW50QXR0cmlidXRlID09PSBQb2ludEF0dHJpYnV0ZS5OT1JNQUxfRkxPQVRTKXsKCQkJcmV0dXJuIHRydWU7CgkJfQoJfQoJCglyZXR1cm4gZmFsc2U7Cn07CgoK")); +Potree.Shaders["pointcloud.vs"] = [ + "", + "// the following is an incomplete list of attributes, uniforms and defines", + "// which are automatically added through the THREE.ShaderMaterial", + "", + "//attribute vec3 position;", + "//attribute vec3 color;", + "//attribute vec3 normal;", + "", + "//uniform mat4 modelMatrix;", + "//uniform mat4 modelViewMatrix;", + "//uniform mat4 projectionMatrix;", + "//uniform mat4 viewMatrix;", + "//uniform mat3 normalMatrix;", + "//uniform vec3 cameraPosition;", + "", + "//#define MAX_DIR_LIGHTS 0", + "//#define MAX_POINT_LIGHTS 1", + "//#define MAX_SPOT_LIGHTS 0", + "//#define MAX_HEMI_LIGHTS 0", + "//#define MAX_SHADOWS 0", + "//#define MAX_BONES 58", + "", + "", + "attribute float intensity;", + "attribute float classification;", + "attribute float returnNumber;", + "attribute float pointSourceID;", + "attribute vec4 indices;", + "", + "uniform float screenWidth;", + "uniform float screenHeight;", + "uniform float fov;", + "uniform float spacing;", + "uniform float blendDepth;", + "uniform float near;", + "uniform float far;", + "", + "#if defined use_clip_box", + " uniform mat4 clipBoxes[clip_box_count];", + "#endif", + "", + "", + "uniform float heightMin;", + "uniform float heightMax;", + "uniform float intensityMin;", + "uniform float intensityMax;", + "uniform float size;", + "uniform float minSize;", + "uniform float maxSize;", + "uniform float nodeSize;", + "uniform vec3 bbSize;", + "uniform vec3 uColor;", + "uniform float opacity;", + "", + "", + "uniform sampler2D visibleNodes;", + "uniform sampler2D gradient;", + "uniform sampler2D classificationLUT;", + "uniform sampler2D depthMap;", + "", + "varying float vOpacity;", + "varying vec3 vColor;", + "varying float vDepth;", + "varying float vLinearDepth;", + "varying vec3 vViewPosition;", + "varying float vRadius;", + "varying vec3 vWorldPosition;", + "varying vec3 vNormal;", + "", + "", + "// ---------------------", + "// OCTREE", + "// ---------------------", + "", + "#if (defined(adaptive_point_size) || defined(color_type_tree_depth)) && defined(tree_type_octree)", + "/**", + " * number of 1-bits up to inclusive index position", + " * number is treated as if it were an integer in the range 0-255", + " *", + " */", + "float numberOfOnes(float number, float index){", + " float tmp = mod(number, pow(2.0, index + 1.0));", + " float numOnes = 0.0;", + " for(float i = 0.0; i < 8.0; i++){", + " if(mod(tmp, 2.0) != 0.0){", + " numOnes++;", + " }", + " tmp = floor(tmp / 2.0);", + " }", + " return numOnes;", + "}", + "", + "", + "/**", + " * checks whether the bit at index is 1", + " * number is treated as if it were an integer in the range 0-255", + " *", + " */", + "bool isBitSet(float number, float index){", + " return mod(floor(number / pow(2.0, index)), 2.0) != 0.0;", + "}", + "", + "", + "/**", + " * find the tree depth at the point position", + " */", + "float getLocalTreeDepth(){", + " vec3 offset = vec3(0.0, 0.0, 0.0);", + " float iOffset = 0.0;", + " float depth = 0.0;", + " for(float i = 0.0; i <= levels + 1.0; i++){", + " ", + " float nodeSizeAtLevel = nodeSize / pow(2.0, i);", + " vec3 index3d = (position - offset) / nodeSizeAtLevel;", + " index3d = floor(index3d + 0.5);", + " float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z;", + " ", + " vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));", + " float mask = value.r * 255.0;", + " if(isBitSet(mask, index)){", + " // there are more visible child nodes at this position", + " iOffset = iOffset + value.g * 255.0 + numberOfOnes(mask, index - 1.0);", + " depth++;", + " }else{", + " // no more visible child nodes at this position", + " return depth;", + " }", + " offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;", + " }", + " ", + " return depth;", + "}", + "", + "float getPointSizeAttenuation(){", + " return pow(1.9, getLocalTreeDepth());", + "}", + "", + "", + "#endif", + "", + "", + "// ---------------------", + "// KD-TREE", + "// ---------------------", + "", + "#if (defined(adaptive_point_size) || defined(color_type_tree_depth)) && defined(tree_type_kdtree)", + "", + "float getLocalTreeDepth(){", + " vec3 offset = vec3(0.0, 0.0, 0.0);", + " float iOffset = 0.0;", + " float depth = 0.0;", + " ", + " ", + " vec3 size = bbSize; ", + " vec3 pos = position;", + " ", + " for(float i = 0.0; i <= levels + 1.0; i++){", + " ", + " vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));", + " ", + " int children = int(value.r * 255.0);", + " float next = value.g * 255.0;", + " int split = int(value.b * 255.0);", + " ", + " if(next == 0.0){", + " return depth;", + " }", + " ", + " vec3 splitv = vec3(0.0, 0.0, 0.0);", + " if(split == 1){", + " splitv.x = 1.0;", + " }else if(split == 2){", + " splitv.y = 1.0;", + " }else if(split == 4){", + " splitv.z = 1.0;", + " }", + " ", + " iOffset = iOffset + next;", + " ", + " float factor = length(pos * splitv / size);", + " if(factor < 0.5){", + " // left", + " if(children == 0 || children == 2){", + " return depth;", + " }", + " }else{", + " // right", + " pos = pos - size * splitv * 0.5;", + " if(children == 0 || children == 1){", + " return depth;", + " }", + " if(children == 3){", + " iOffset = iOffset + 1.0;", + " }", + " }", + " size = size * ((1.0 - (splitv + 1.0) / 2.0) + 0.5);", + " ", + " depth++;", + " }", + " ", + " ", + " return depth; ", + "}", + "", + "float getPointSizeAttenuation(){", + " return pow(1.3, getLocalTreeDepth());", + "}", + "", + "#endif", + "", + "void main() {", + " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", + " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", + " vViewPosition = -mvPosition.xyz;", + " vWorldPosition = worldPosition.xyz;", + " gl_Position = projectionMatrix * mvPosition;", + " vOpacity = opacity;", + " vLinearDepth = -mvPosition.z;", + " vDepth = mvPosition.z / gl_Position.w;", + " vNormal = normalMatrix * normal;", + "", + "", + " // ---------------------", + " // POINT COLOR", + " // ---------------------", + " ", + " #ifdef color_type_rgb", + " vColor = color;", + " #elif defined color_type_height", + " vec4 world = modelMatrix * vec4( position, 1.0 );", + " float w = (world.y - heightMin) / (heightMax-heightMin);", + " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;", + " #elif defined color_type_depth", + " float d = -mvPosition.z ;", + " vColor = vec3(d, vDepth, 0.0);", + " #elif defined color_type_intensity", + " float w = (intensity - intensityMin) / (intensityMax - intensityMin);", + " vColor = vec3(w, w, w);", + " #elif defined color_type_intensity_gradient", + " float w = (intensity - intensityMin) / intensityMax;", + " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;", + " #elif defined color_type_color", + " vColor = uColor;", + " #elif defined color_type_tree_depth", + " float depth = getLocalTreeDepth();", + " float w = depth / 10.0;", + " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;", + " #elif defined color_type_point_index", + " vColor = indices.rgb;", + " #elif defined color_type_classification", + " float c = mod(classification, 16.0);", + " vec2 uv = vec2(c / 255.0, 0.5);", + " vColor = texture2D(classificationLUT, uv).rgb;", + " #elif defined color_type_return_number", + " float w = (returnNumber - 1.0) / 4.0 + 0.1;", + " vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb;", + " #elif defined color_type_source", + " float w = mod(pointSourceID, 10.0) / 10.0;", + " vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb;", + " #elif defined color_type_normal", + " vColor = (modelMatrix * vec4(normal, 0.0)).xyz;", + " #elif defined color_type_phong", + " vColor = color;", + " #endif", + " ", + " //if(vNormal.z < 0.0){", + " // gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);", + " //}", + " ", + " // ---------------------", + " // POINT SIZE", + " // ---------------------", + " float pointSize = 1.0;", + " ", + " float projFactor = 1.0 / tan(fov / 2.0);", + " projFactor /= vViewPosition.z;", + " projFactor *= screenHeight / 2.0;", + " float r = spacing * 1.5;", + " vRadius = r;", + " #if defined fixed_point_size", + " pointSize = size;", + " #elif defined attenuated_point_size", + " pointSize = size * projFactor;", + " #elif defined adaptive_point_size", + " float worldSpaceSize = size * r / getPointSizeAttenuation();", + " pointSize = worldSpaceSize * projFactor;", + " #endif", + "", + " pointSize = max(minSize, pointSize);", + " pointSize = min(maxSize, pointSize);", + " ", + " vRadius = pointSize / projFactor;", + " ", + " gl_PointSize = pointSize;", + " ", + " ", + " // ---------------------", + " // CLIPPING", + " // ---------------------", + " ", + " #if defined use_clip_box", + " bool insideAny = false;", + " for(int i = 0; i < clip_box_count; i++){", + " vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 );", + " bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5;", + " inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5;", + " inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5;", + " insideAny = insideAny || inside;", + " }", + " if(!insideAny){", + " ", + " #if defined clip_outside", + " gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);", + " #elif defined clip_highlight_inside && !defined(color_type_depth)", + " float c = (vColor.r + vColor.g + vColor.b) / 6.0;", + " #endif", + " }else{", + " #if defined clip_highlight_inside", + " vColor.r += 0.5;", + " #endif", + " }", + " ", + " #endif", + " ", + "}", + "", +].join("\n"); + +Potree.Shaders["pointcloud.fs"] = [ + "", + "#if defined use_interpolation", + " #extension GL_EXT_frag_depth : enable", + "#endif", + "", + "", + "// the following is an incomplete list of attributes, uniforms and defines", + "// which are automatically added through the THREE.ShaderMaterial", + "", + "// #define USE_COLOR", + "// ", + "// uniform mat4 viewMatrix;", + "// uniform vec3 cameraPosition;", + "", + "", + "uniform mat4 projectionMatrix;", + "uniform float opacity;", + "", + "", + "#if defined(color_type_phong)", + "", + " uniform vec3 diffuse;", + " uniform vec3 ambient;", + " uniform vec3 emissive;", + " uniform vec3 specular;", + " uniform float shininess;", + " uniform vec3 ambientLightColor;", + "", + " #if MAX_POINT_LIGHTS > 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( node, factor ){ @@ -252,8 +832,9 @@ POCLoader.load = function load(url, callback) { root.hasChildren = true; if(version.upTo("1.5")){ root.numPoints = fMno.hierarchy[0][1]; + }else{ + root.numPoints = 0; } - root.numPoints = 0; pco.root = root; pco.root.load(); nodes[name] = root; @@ -366,6 +947,7 @@ PointAttributeNames.NORMAL_FLOATS = 4; // float x, y, z; PointAttributeNames.FILLER = 5; PointAttributeNames.INTENSITY = 6; PointAttributeNames.CLASSIFICATION = 7; +PointAttributeNames.NORMAL_SPHEREMAPPED = 8; /** * Some types of possible point attribute data formats @@ -436,6 +1018,10 @@ PointAttribute.INTENSITY = new PointAttribute( PointAttribute.CLASSIFICATION = new PointAttribute( PointAttributeNames.CLASSIFICATION, PointAttributeTypes.DATA_TYPE_UINT8, 1); + +PointAttribute.NORMAL_SPHEREMAPPED = new PointAttribute( + PointAttributeNames.NORMAL_SPHEREMAPPED, + PointAttributeTypes.DATA_TYPE_UINT8, 2); /** * Ordered list of PointAttributes used to identify how points are aligned in a buffer. @@ -486,7 +1072,7 @@ PointAttributes.prototype.hasColors = function(){ PointAttributes.prototype.hasNormals = function(){ for(var name in this.attributes){ var pointAttribute = this.attributes[name]; - if(pointAttribute === PointAttribute.NORMAL_FLOATS){ + if(pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED || pointAttribute === PointAttribute.NORMAL_FLOATS){ return true; } } @@ -547,6 +1133,9 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ var numPoints = buffer.byteLength / node.pcoGeometry.pointAttributes.byteSize; var pointAttributes = node.pcoGeometry.pointAttributes; + if(this.version.upTo("1.5")){ + node.numPoints = numPoints; + } var ww = Potree.workers.binaryDecoder.getWorker(); ww.onmessage = function(e){ @@ -571,6 +1160,8 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ geometry.addAttribute("intensity", new THREE.BufferAttribute(new Float32Array(buffer), 1)); }else if(parseInt(property) === PointAttributeNames.CLASSIFICATION){ geometry.addAttribute("classification", new THREE.BufferAttribute(new Float32Array(buffer), 1)); + }else if(parseInt(property) === PointAttributeNames.NORMAL_SPHEREMAPPED){ + geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3)); } } } @@ -581,6 +1172,8 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ node.loaded = true; node.loading = false; node.pcoGeometry.numNodesLoading--; + + //console.log("loaded: " + node.name + "\t, " + renderer.info.memory.geometries + ", " + Potree.PointCloudOctree.lru.elements); } var message = { @@ -830,11 +1423,44 @@ Potree.LasLazBatcher = function(node){ // http://stackoverflow.com/questions/3717226/radius-of-projected-sphere // +Potree.Gradients = { + RAINBOW: [ + [0, new THREE.Color(0.278, 0, 0.714)], + [1/6, new THREE.Color(0, 0, 1)], + [2/6, new THREE.Color(0, 1, 1)], + [3/6, new THREE.Color(0, 1, 0)], + [4/6, new THREE.Color(1, 1, 0)], + [5/6, new THREE.Color(1, 0.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(0.5, 0.5,0.5), + 1: new THREE.Color(0.5, 0.5,0.5), + 2: new THREE.Color(0.63, 0.32, 0.18), + 3: new THREE.Color(0.0, 1.0, 0.0), + 4: new THREE.Color(0.0, 0.8, 0.0), + 5: new THREE.Color(0.0, 0.6, 0.0 ), + 6: new THREE.Color(1.0, 0.66, 0.0), + 7: new THREE.Color(1.0, 0, 1.0 ), + 8: new THREE.Color(1.0, 0, 0.0 ), + 9: new THREE.Color(0.0, 0.0, 1.0 ), + 12: new THREE.Color(1.0, 1.0, 0.0 ), + "DEFAULT": new THREE.Color(0.3, 0.6, 0.6 ) + } +}; + Potree.PointSizeType = { - FIXED: 0, + FIXED: 0, ATTENUATED: 1, - ADAPTIVE: 2 + ADAPTIVE: 2 }; Potree.PointShape = { @@ -843,23 +1469,31 @@ Potree.PointShape = { }; Potree.PointColorType = { - RGB: 0, - COLOR: 1, - DEPTH: 2, - HEIGHT: 3, - INTENSITY: 4, - INTENSITY_GRADIENT: 5, - OCTREE_DEPTH: 6, - POINT_INDEX: 7, - CLASSIFICATION: 8, - RETURN_NUMBER: 9, - SOURCE: 10 + 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 + DISABLED: 0, + CLIP_OUTSIDE: 1, + HIGHLIGHT_INSIDE: 2 +}; + +Potree.TreeType = { + OCTREE: 0, + KDTREE: 1 }; Potree.PointCloudMaterial = function(parameters){ @@ -872,64 +1506,94 @@ Potree.PointCloudMaterial = function(parameters){ var pointSize = parameters.size || 1.0; var minSize = parameters.minSize || 1.0; + var maxSize = parameters.maxSize || 50.0; + var treeType = parameters.treeType || Potree.TreeType.OCTREE; var nodeSize = 1.0; this._pointSizeType = Potree.PointSizeType.ATTENUATED; this._pointShape = Potree.PointShape.SQUARE; this._interpolate = false; this._pointColorType = Potree.PointColorType.RGB; - this._octreeLevels = 6.0; + this._levels = 6.0; this._useClipBox = false; this.numClipBoxes = 0; this._clipMode = Potree.ClipMode.DISABLED; this._weighted = false; this._blendDepth = 0.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 = true; + this._treeType = treeType; + + - this.gradientTexture = Potree.PointCloudMaterial.generateGradient(); var attributes = {}; var uniforms = { - spacing: { type: "f", value: 1.0 }, - fov: { type: "f", value: 1.0 }, - screenWidth: { type: "f", value: 1.0 }, - screenHeight: { type: "f", value: 1.0 }, - near: { type: "f", value: 0.1 }, - far: { type: "f", value: 1.0 }, - uColor: { type: "c", value: new THREE.Color( 0xff0000 ) }, - opacity: { type: "f", value: 1.0 }, - size: { type: "f", value: 10 }, - minSize: { type: "f", value: 2 }, - nodeSize: { type: "f", value: nodeSize }, - heightMin: { type: "f", value: 0.0 }, - heightMax: { type: "f", value: 1.0 }, - intensityMin: { type: "f", value: 0.0 }, - intensityMax: { type: "f", value: 1.0 }, - visibleNodes: { type: "t", value: this.visibleNodesTexture }, - pcIndex: { type: "f", value: 0 }, - gradient: { type: "t", value: this.gradientTexture }, - clipBoxes: { type: "Matrix4fv", value: [] }, - blendDepth: { type: "f", value: this._blendDepth }, - depthMap: { type: "t", value: null }, + spacing: { type: "f", value: 1.0 }, + fov: { type: "f", value: 1.0 }, + screenWidth: { type: "f", value: 1.0 }, + screenHeight: { type: "f", value: 1.0 }, + near: { type: "f", value: 0.1 }, + far: { type: "f", value: 1.0 }, + uColor: { type: "c", value: new THREE.Color( 0xff0000 ) }, + opacity: { type: "f", value: 1.0 }, + size: { type: "f", value: 10 }, + minSize: { type: "f", value: 2 }, + maxSize: { type: "f", value: 2 }, + nodeSize: { type: "f", value: nodeSize }, + bbSize: { type: "fv", value: [0,0,0] }, + heightMin: { type: "f", value: 0.0 }, + heightMax: { type: "f", value: 1.0 }, + intensityMin: { type: "f", value: 0.0 }, + intensityMax: { type: "f", value: 1.0 }, + 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: [0.1, 0.1, 0.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: uniforms, attributes: attributes, - vertexShader: this.getDefines() + Potree.PointCloudMaterial.vs_points.join("\n"), - fragmentShader: this.getDefines() + Potree.PointCloudMaterial.fs_points_rgb.join("\n"), + vertexShader: this.getDefines() + Potree.Shaders["pointcloud.vs"], + fragmentShader: this.getDefines() + Potree.Shaders["pointcloud.fs"], vertexColors: THREE.VertexColors, size: pointSize, minSize: minSize, + maxSize: maxSize, nodeSize: nodeSize, pcIndex: 0, alphaTest: 0.9 }); }; -Potree.PointCloudMaterial.prototype = new THREE.RawShaderMaterial(); +Potree.PointCloudMaterial.prototype = new THREE.ShaderMaterial(); Potree.PointCloudMaterial.prototype.updateShaderSource = function(){ @@ -943,12 +1607,17 @@ Potree.PointCloudMaterial.prototype.updateShaderSource = function(){ attributes.returnNumber = { type: "f", value: [] }; }else if(this.pointColorType === Potree.PointColorType.SOURCE){ attributes.pointSourceID = { type: "f", value: [] }; + }else if(this.pointColorType === Potree.PointColorType.NORMAL || this.pointColorType === Potree.PointColorType.PHONG){ + attributes.normal = { type: "f", value: [] }; } + var vs = this.getDefines() + Potree.Shaders["pointcloud.vs"]; + var fs = this.getDefines() + Potree.Shaders["pointcloud.fs"]; + this.setValues({ attributes: attributes, - vertexShader: this.getDefines() + Potree.PointCloudMaterial.vs_points.join("\n"), - fragmentShader: this.getDefines() + Potree.PointCloudMaterial.fs_points_rgb.join("\n") + vertexShader: vs, + fragmentShader: fs }); if(this.depthMap){ @@ -972,9 +1641,6 @@ Potree.PointCloudMaterial.prototype.updateShaderSource = function(){ depthTest: false, depthWrite: true }); - //this.setValues({ - // transparent: true - //}); } if(this.weighted){ @@ -1002,7 +1668,7 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){ defines += "#define attenuated_point_size\n"; }else if(this.pointSizeType === Potree.PointSizeType.ADAPTIVE){ defines += "#define adaptive_point_size\n"; - defines += "#define octreeLevels " + Math.max(0, this._octreeLevels - 2).toFixed(1) + "\n"; + defines += "#define levels " + Math.max(0, this._levels - 2).toFixed(1) + "\n"; } if(this.pointShape === Potree.PointShape.SQUARE){ @@ -1027,8 +1693,8 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){ defines += "#define color_type_intensity\n"; }else if(this._pointColorType === Potree.PointColorType.INTENSITY_GRADIENT){ defines += "#define color_type_intensity_gradient\n"; - }else if(this._pointColorType === Potree.PointColorType.OCTREE_DEPTH){ - defines += "#define color_type_octree_depth\n"; + }else if(this._pointColorType === Potree.PointColorType.TREE_DEPTH){ + defines += "#define color_type_tree_depth\n"; }else if(this._pointColorType === Potree.PointColorType.POINT_INDEX){ defines += "#define color_type_point_index\n"; }else if(this._pointColorType === Potree.PointColorType.CLASSIFICATION){ @@ -1037,6 +1703,10 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){ defines += "#define color_type_return_number\n"; }else if(this._pointColorType === Potree.PointColorType.SOURCE){ defines += "#define color_type_source\n"; + }else if(this._pointColorType === Potree.PointColorType.NORMAL){ + defines += "#define color_type_normal\n"; + }else if(this._pointColorType === Potree.PointColorType.PHONG){ + defines += "#define color_type_phong\n"; } if(this.clipMode === Potree.ClipMode.DISABLED){ @@ -1047,6 +1717,12 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){ defines += "#define clip_highlight_inside\n"; } + if(this._treeType === Potree.TreeType.OCTREE){ + defines += "#define tree_type_octree\n"; + }else if(this._treeType === Potree.TreeType.KDTREE){ + defines += "#define tree_type_kdtree\n"; + } + if(this.weighted){ defines += "#define weighted_splats\n"; } @@ -1066,7 +1742,6 @@ Potree.PointCloudMaterial.prototype.setClipBoxes = function(clipBoxes){ if(this.uniforms.clipBoxes.value.length / 16 !== numBoxes){ this.uniforms.clipBoxes.value = new Float32Array(numBoxes * 16); this.updateShaderSource(); - } for(var i = 0; i < numBoxes; i++){ @@ -1074,10 +1749,35 @@ Potree.PointCloudMaterial.prototype.setClipBoxes = function(clipBoxes){ this.uniforms.clipBoxes.value.set(box.elements, 16*i); } - - }; + +Object.defineProperty(Potree.PointCloudMaterial.prototype, "gradient", { + get: function(){ + return this._gradient; + }, + set: function(value){ + if(this._gradient !== value){ + this._gradient = value; + 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(value){ + if(this._classification !== value){ + this._classification = value; + 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; @@ -1198,13 +1898,13 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "opacity", { } }); -Object.defineProperty(Potree.PointCloudMaterial.prototype, "octreeLevels", { +Object.defineProperty(Potree.PointCloudMaterial.prototype, "levels", { get: function(){ - return this._octreeLevels; + return this._levels; }, set: function(value){ - if(this._octreeLevels !== value){ - this._octreeLevels = value; + if(this._levels !== value){ + this._levels = value; this.updateShaderSource(); } } @@ -1312,6 +2012,15 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "minSize", { } }); +Object.defineProperty(Potree.PointCloudMaterial.prototype, "maxSize", { + get: function(){ + return this.uniforms.maxSize.value; + }, + set: function(value){ + this.uniforms.maxSize.value = value; + } +}); + Object.defineProperty(Potree.PointCloudMaterial.prototype, "heightMin", { get: function(){ return this.uniforms.heightMin.value; @@ -1357,7 +2066,32 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "pcIndex", { } }); -Potree.PointCloudMaterial.generateGradient = function() { +Object.defineProperty(Potree.PointCloudMaterial.prototype, "treeType", { + get: function(){ + return this._treeType; + }, + set: function(value){ + if(this._treeType != value){ + this._treeType = value; + this.updateShaderSource(); + } + } +}); + +Object.defineProperty(Potree.PointCloudMaterial.prototype, "bbSize", { + get: function(){ + return this.uniforms.bbSize.value; + }, + set: function(value){ + this.uniforms.bbSize.value = value; + } +}); + +/** + * Generates a look-up texture for gradient values (height, intensity, ...) + * + */ +Potree.PointCloudMaterial.generateGradientTexture = function(gradient) { var size = 64; // create canvas @@ -1370,17 +2104,15 @@ Potree.PointCloudMaterial.generateGradient = function() { // draw gradient context.rect( 0, 0, size, size ); - var gradient = context.createLinearGradient( 0, 0, size, size ); - gradient.addColorStop(0, "#4700b6"); - gradient.addColorStop(1/6, 'blue'); - gradient.addColorStop(2/6, 'aqua'); - gradient.addColorStop(3/6, 'green') - gradient.addColorStop(4/6, 'yellow'); - gradient.addColorStop(5/6, 'orange'); - gradient.addColorStop(1, 'red'); - + var ctxGradient = context.createLinearGradient( 0, 0, size, size ); + + for(var i = 0;i < gradient.length; i++){ + var step = gradient[i]; + + ctxGradient.addColorStop(step[0], "#" + step[1].getHexString()); + } - context.fillStyle = gradient; + context.fillStyle = ctxGradient; context.fill(); var texture = new THREE.Texture( canvas ); @@ -1388,318 +2120,43 @@ Potree.PointCloudMaterial.generateGradient = function() { textureImage = texture.image; return texture; -} - -Potree.PointCloudMaterial.vs_points = [ - "precision mediump float; ", - "precision mediump int; ", - " ", - "attribute vec3 position; ", - "attribute vec3 color; ", - "attribute float intensity; ", - "attribute float classification; ", - "attribute float returnNumber; ", - "attribute float pointSourceID; ", - "attribute vec4 indices; ", - " ", - "uniform mat4 modelMatrix; ", - "uniform mat4 modelViewMatrix; ", - "uniform mat4 projectionMatrix; ", - "uniform mat4 viewMatrix; ", - "uniform mat3 normalMatrix; ", - "uniform vec3 cameraPosition; ", - "uniform float screenWidth; ", - "uniform float screenHeight; ", - "uniform float fov; ", - "uniform float spacing; ", - "uniform float blendDepth; ", - "uniform float near; ", - "uniform float far; ", - " ", - "#if defined use_clip_box ", - " uniform mat4 clipBoxes[clip_box_count]; ", - "#endif ", - " ", - " ", - "uniform float heightMin; ", - "uniform float heightMax; ", - "uniform float intensityMin; ", - "uniform float intensityMax; ", - "uniform float size; ", - "uniform float minSize; ", - "uniform float nodeSize; ", - "uniform vec3 uColor; ", - "uniform float opacity; ", - " ", - " ", - "uniform sampler2D visibleNodes; ", - "uniform sampler2D gradient; ", - "uniform sampler2D depthMap; ", - " ", - "varying float vOpacity; ", - "varying vec3 vColor; ", - "varying float vDepth; ", - "varying float vLinearDepth; ", - " ", - " ", - "#if defined(adaptive_point_size) || defined(color_type_octree_depth) ", - "/** ", - " * number of 1-bits up to inclusive index position ", - " * number is treated as if it were an integer in the range 0-255 ", - " * ", - " */ ", - "float numberOfOnes(float number, float index){ ", - " float tmp = mod(number, pow(2.0, index + 1.0)); ", - " float numOnes = 0.0; ", - " for(float i = 0.0; i < 8.0; i++){ ", - " if(mod(tmp, 2.0) != 0.0){ ", - " numOnes++; ", - " } ", - " tmp = floor(tmp / 2.0); ", - " } ", - " return numOnes; ", - "} ", - " ", - " ", - "/** ", - " * checks whether the bit at index is 1 ", - " * number is treated as if it were an integer in the range 0-255 ", - " * ", - " */ ", - "bool isBitSet(float number, float index){ ", - " return mod(floor(number / pow(2.0, index)), 2.0) != 0.0; ", - "} ", - " ", - " ", - "/** ", - " * find the octree depth at the point position ", - " */ ", - "float getOctreeDepth(){ ", - " vec3 offset = vec3(0.0, 0.0, 0.0); ", - " float iOffset = 0.0; ", - " float depth = 0.0; ", - " for(float i = 0.0; i <= octreeLevels + 1.0; i++){ ", - " ", - " float nodeSizeAtLevel = nodeSize / pow(2.0, i); ", - " vec3 index3d = (position - offset) / nodeSizeAtLevel; ", - " index3d = floor(index3d + 0.5); ", - " float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z; ", - " ", - " vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0)); ", - " float mask = value.r * 255.0; ", - " if(isBitSet(mask, index)){ ", - " // there are more visible child nodes at this position ", - " iOffset = iOffset + value.g * 255.0 + numberOfOnes(mask, index - 1.0); ", - " depth++; ", - " }else{ ", - " // no more visible child nodes at this position ", - " return depth; ", - " } ", - " offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; ", - " } ", - " ", - " return depth; ", - "} ", - " ", - "#endif ", - " ", - "vec3 classificationColor(float classification){ ", - " vec3 color = vec3(0.0, 0.0, 0.0); ", - " float c = mod(classification, 16.0); ", - " if(c == 0.0){ ", - " color = vec3(0.5, 0.5, 0.5); ", - " }else if(c == 1.0){ ", - " color = vec3(0.5, 0.5, 0.5); ", - " }else if(c == 2.0){ ", - " color = vec3(0.63, 0.32, 0.18); ", - " }else if(c == 3.0){ ", - " color = vec3(0.0, 1.0, 0.0); ", - " }else if(c == 4.0){ ", - " color = vec3(0.0, 0.8, 0.0); ", - " }else if(c == 5.0){ ", - " color = vec3(0.0, 0.6, 0.0); ", - " }else if(c == 6.0){ ", - " color = vec3(1.0, 0.66, 0.0); ", - " }else if(c == 7.0){ ", - " color = vec3(1.0, 0, 1.0); ", - " }else if(c == 8.0){ ", - " color = vec3(1.0, 0, 0.0); ", - " }else if(c == 9.0){ ", - " color = vec3(0.0, 0.0, 1.0); ", - " }else if(c == 12.0){ ", - " color = vec3(1.0, 1.0, 0.0); ", - " }else{ ", - " color = vec3(0.3, 0.6, 0.6); ", - " } ", - " ", - " return color; ", - "} ", - " ", - "void main() { ", - " ", - " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); ", - " gl_Position = projectionMatrix * mvPosition; ", - " //float pw = gl_Position.w; ", - " //float pd = gl_Position.z; ", - " //gl_Position = gl_Position / pw; ", - " //gl_Position.z = 2.0*((pw - near) / far)-1.0; ", - " vOpacity = opacity; ", - " vLinearDepth = -mvPosition.z; ", - " vDepth = mvPosition.z / gl_Position.w; ", - " ", - " // COLOR TYPES ", - " ", - " #ifdef color_type_rgb ", - " vColor = color; ", - " #elif defined color_type_height ", - " vec4 world = modelMatrix * vec4( position, 1.0 ); ", - " float w = (world.y - heightMin) / (heightMax-heightMin); ", - " ", - " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; ", - " #elif defined color_type_depth ", - " float d = -mvPosition.z ; ", - " vColor = vec3(d, vDepth, 0.0); ", - " #elif defined color_type_intensity ", - " float w = (intensity - intensityMin) / (intensityMax - intensityMin); ", - " vColor = vec3(w, w, w); ", - " #elif defined color_type_intensity_gradient ", - " float w = (intensity - intensityMin) / intensityMax; ", - " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; ", - " #elif defined color_type_color ", - " vColor = uColor; ", - " #elif defined color_type_octree_depth ", - " float depth = getOctreeDepth(); ", - " float w = depth / 10.0; ", - " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; ", - " #elif defined color_type_point_index ", - " vColor = indices.rgb; ", - " #elif defined color_type_classification ", - " vColor = classificationColor(classification); ", - " #elif defined color_type_return_number ", - " float w = (returnNumber - 1.0) / 4.0 + 0.1; ", - " vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb; ", - " #elif defined color_type_source ", - " float w = mod(pointSourceID, 10.0) / 10.0; ", - " vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb; ", - " #endif ", - " ", - " ", - " ", - " // ", - " // POINT SIZE TYPES ", - " // ", - " float r = spacing * 1.5; ", - " #if defined fixed_point_size ", - " gl_PointSize = size; ", - " #elif defined attenuated_point_size ", - " //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ", - " gl_PointSize = (1.0 / tan(fov/2.0)) * size / (-mvPosition.z); ", - " gl_PointSize = gl_PointSize * screenHeight / 2.0; ", - " #elif defined adaptive_point_size ", - " //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ", - " //gl_PointSize = (1.0 / tan(fov/2.0)) * r / sqrt( max(0.0, mvPosition.z * mvPosition.z - r * r)); ", - " gl_PointSize = (1.0 / tan(fov/2.0)) * r / (-mvPosition.z); ", - " gl_PointSize = size * gl_PointSize * screenHeight / 2.0; ", - " gl_PointSize = gl_PointSize / pow(1.9, getOctreeDepth()); ", - " #endif ", - " ", - " gl_PointSize = max(minSize, gl_PointSize); ", - " gl_PointSize = min(50.0, gl_PointSize); ", - " ", - " // clip box ", - " #if defined use_clip_box ", - " bool insideAny = false; ", - " for(int i = 0; i < clip_box_count; i++){ ", - " vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 ); ", - " bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5; ", - " inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5; ", - " inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5; ", - " insideAny = insideAny || inside; ", - " } ", - " if(!insideAny){ ", - " ", - " #if defined clip_outside ", - " gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0); ", - " #elif defined clip_highlight_inside && !defined(color_type_depth) ", - " float c = (vColor.r + vColor.g + vColor.b) / 6.0; ", - " //vColor = vec3(c, c, c); ", - " #endif ", - " }else{ ", - " #if defined clip_highlight_inside ", - " vColor.r += 0.5; ", - " #endif ", - " } ", - " ", - " #endif ", - " ", - " ", - "} "]; - -Potree.PointCloudMaterial.fs_points_rgb = [ - "#if defined use_interpolation ", - " #extension GL_EXT_frag_depth : enable ", - "#endif ", - " ", - "precision mediump float; ", - "precision mediump int; ", - " ", - "//uniform float opacity; ", - "uniform float pcIndex; ", - "uniform float screenWidth; ", - "uniform float screenHeight; ", - "uniform float blendDepth; ", - " ", - "uniform sampler2D depthMap; ", - " ", - "varying vec3 vColor; ", - "varying float vOpacity; ", - "varying float vLinearDepth; ", - "varying float vDepth; ", - " ", - "void main() { ", - " ", - " #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats) ", - " float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0); ", - " float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0); ", - " float c = 1.0 - (a + b); ", - " ", - " if(c < 0.0){ ", - " discard; ", - " } ", - " #endif ", - " ", - " #if defined weighted_splats ", - " vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight); ", - " ", - " float depth = texture2D(depthMap, uv).r; ", - " if(vLinearDepth > depth + blendDepth){ ", - " discard; ", - " } ", - " #endif ", - " ", - " #if defined use_interpolation ", - " gl_FragDepthEXT = gl_FragCoord.z + 0.002*(1.0-pow(c, 1.0)) * gl_FragCoord.w; ", - " #endif ", - " ", - " ", - " #if defined color_type_point_index ", - " gl_FragColor = vec4(vColor, pcIndex / 255.0); ", - " #else ", - " gl_FragColor = vec4(vColor, vOpacity); ", - " #endif ", - " ", - " ", - " #if defined weighted_splats ", - " float w = pow(c, 2.0); ", - " gl_FragColor.rgb = gl_FragColor.rgb * w; ", - " gl_FragColor.a = w; ", - " #endif ", - " ", - " ", - " ", - "} "]; - +}; +/** + * Generates a look up texture for classification colors + * + */ +Potree.PointCloudMaterial.generateClassificationTexture = function(classification){ + var width = 256; + var height = 256; + var map = THREE.ImageUtils.generateDataTexture( width, height, new THREE.Color() ); + map.magFilter = THREE.NearestFilter; + var data = map.image.data; + + for(var x = 0; x < width; x++){ + for(var y = 0; y < height; y++){ + var u = 2 * (x / width) - 1; + var v = 2 * (y / height) - 1; + + var i = x + width*y; + + var color; + if(classification[x]){ + color = classification[x]; + }else{ + color = classification.DEFAULT; + } + + + data[3*i+0] = 255 * color.r; + data[3*i+1] = 255 * color.g; + data[3*i+2] = 255 * color.b; + } + } + + return map; + +}; /** @@ -1857,6 +2314,15 @@ THREE.FirstPersonControls = function ( object, domElement ) { this.update = function (delta) { this.object.rotation.order = 'ZYX'; + + var object = this.object; + + this.object = new THREE.Object3D(); + this.object.position.copy(object.position); + this.object.rotation.copy(object.rotation); + this.object.updateMatrix(); + this.object.updateMatrixWorld(); + var position = this.object.position; if(delta !== undefined){ @@ -1899,6 +2365,39 @@ THREE.FirstPersonControls = function ( object, domElement ) { this.object.quaternion.setFromRotationMatrix(res); this.object.rotation.x += phiDelta; + this.object.updateMatrixWorld(); + + // send transformation proposal to listeners + var proposeTransformEvent = { + type: "proposeTransform", + oldPosition: object.position, + newPosition: this.object.position, + objections: 0, + counterProposals: [] + }; + this.dispatchEvent(proposeTransformEvent); + + // check some counter proposals if transformation wasn't accepted + if(proposeTransformEvent.objections > 0 ){ + if(proposeTransformEvent.counterProposals.length > 0){ + var cp = proposeTransformEvent.counterProposals; + this.object.position.copy(cp[0]); + + proposeTransformEvent.objections = 0; + proposeTransformEvent.counterProposals = []; + } + } + + // apply transformation, if accepted + if(proposeTransformEvent.objections > 0){ + + }else{ + object.position.copy(this.object.position); + } + + object.rotation.copy(this.object.rotation); + + this.object = object; thetaDelta = 0; phiDelta = 0; @@ -2032,6 +2531,683 @@ THREE.FirstPersonControls = function ( object, domElement ) { }; THREE.FirstPersonControls.prototype = Object.create( THREE.EventDispatcher.prototype ); +/** + * @author mschuetz / http://mschuetz.at/ + * @author qiao / https://github.com/qiao + * @author mrdoob / http://mrdoob.com + * @author alteredq / http://alteredqualia.com/ + * @author WestLangley / http://github.com/WestLangley + * @author erich666 / http://erichaines.com + */ +/*global THREE, console */ + +// +// Adapted from THREE.OrbitControls +// - Smooth movements +// - creates "proposeTransform" events +// +// +// This set of controls performs orbiting, dollying (zooming), and panning. It maintains +// the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is +// supported. +// +// Orbit - left mouse / touch: one finger move +// Zoom - middle mouse, or mousewheel / touch: two finger spread or squish +// Pan - right mouse, or arrow keys / touch: three finter swipe +// +// This is a drop-in replacement for (most) TrackballControls used in examples. +// That is, include this js file and wherever you see: +// controls = new THREE.TrackballControls( camera ); +// controls.target.z = 150; +// Simple substitute "OrbitControls" and the control should work as-is. + +Potree.OrbitControls = function ( object, domElement ) { + + this.object = object; + this.domElement = ( domElement !== undefined ) ? domElement : document; + + // API + + // Set to false to disable this control + this.enabled = true; + + // "target" sets the location of focus, where the control orbits around + // and where it pans with respect to. + this.target = new THREE.Vector3(); + + // center is old, deprecated; use "target" instead + this.center = this.target; + + // This option actually enables dollying in and out; left as "zoom" for + // backwards compatibility + this.noZoom = false; + this.zoomSpeed = 1.0; + + // Limits to how far you can dolly in and out + this.minDistance = 0; + this.maxDistance = Infinity; + + // Set to true to disable this control + this.noRotate = false; + this.rotateSpeed = 1.0; + + // Set to true to disable this control + this.noPan = false; + this.keyPanSpeed = 7.0; // pixels moved per arrow key push + + // Set to true to automatically rotate around the target + this.autoRotate = false; + this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60 + + this.fadeFactor = 10; + + // How far you can orbit vertically, upper and lower limits. + // Range is 0 to Math.PI radians. + this.minPolarAngle = 0; // radians + this.maxPolarAngle = Math.PI; // radians + + // Set to true to disable use of the keys + this.noKeys = false; + + // The four arrow keys + this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 }; + + //////////// + // internals + + var scope = this; + + var EPS = 0.000001; + + var rotateStart = new THREE.Vector2(); + var rotateEnd = new THREE.Vector2(); + var rotateDelta = new THREE.Vector2(); + + var panStart = new THREE.Vector2(); + var panEnd = new THREE.Vector2(); + var panDelta = new THREE.Vector2(); + var panOffset = new THREE.Vector3(); + + var offset = new THREE.Vector3(); + + var dollyStart = new THREE.Vector2(); + var dollyEnd = new THREE.Vector2(); + var dollyDelta = new THREE.Vector2(); + + var phiDelta = 0; + var thetaDelta = 0; + var scale = 1; + var pan = new THREE.Vector3(); + + var lastPosition = new THREE.Vector3(); + + var STATE = { NONE : -1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 }; + + var state = STATE.NONE; + + // for reset + + this.target0 = this.target.clone(); + this.position0 = this.object.position.clone(); + + // events + + var changeEvent = { type: 'change' }; + var startEvent = { type: 'start'}; + var endEvent = { type: 'end'}; + + this.rotateLeft = function ( angle ) { + + if ( angle === undefined ) { + + angle = getAutoRotationAngle(); + + } + + thetaDelta -= angle; + + }; + + this.rotateUp = function ( angle ) { + + if ( angle === undefined ) { + + angle = getAutoRotationAngle(); + + } + + phiDelta -= angle; + + }; + + // pass in distance in world space to move left + this.panLeft = function ( distance ) { + + var te = this.object.matrix.elements; + + // get X column of matrix + panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] ); + panOffset.multiplyScalar( - distance ); + + pan.add( panOffset ); + + }; + + // pass in distance in world space to move up + this.panUp = function ( distance ) { + + var te = this.object.matrix.elements; + + // get Y column of matrix + panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] ); + panOffset.multiplyScalar( distance ); + + pan.add( panOffset ); + + }; + + // pass in x,y of change desired in pixel space, + // right and down are positive + this.pan = function ( deltaX, deltaY ) { + + var element = scope.domElement === document ? scope.domElement.body : scope.domElement; + + if ( scope.object.fov !== undefined ) { + + // perspective + var position = scope.object.position; + var offset = position.clone().sub( scope.target ); + var targetDistance = offset.length(); + + // half of the fov is center to top of screen + targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 ); + + // we actually don't use screenWidth, since perspective camera is fixed to screen height + scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight ); + scope.panUp( 2 * deltaY * targetDistance / element.clientHeight ); + + } else if ( scope.object.top !== undefined ) { + + // orthographic + scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth ); + scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight ); + + } else { + + // camera neither orthographic or perspective + console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' ); + + } + + }; + + this.dollyIn = function ( dollyScale ) { + + if ( dollyScale === undefined ) { + + dollyScale = getZoomScale(); + + } + + scale /= dollyScale; + + }; + + this.dollyOut = function ( dollyScale ) { + + if ( dollyScale === undefined ) { + + dollyScale = getZoomScale(); + + } + + scale *= dollyScale; + + }; + + this.update = function ( delta ) { + + var position = this.object.position.clone(); + + offset.copy( position ).sub( this.target ); + + // angle from z-axis around y-axis + + var theta = Math.atan2( offset.x, offset.z ); + + // angle from y-axis + + var phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y ); + + if ( this.autoRotate ) { + + this.rotateLeft( getAutoRotationAngle() ); + + } + + var progression = Math.min(1, this.fadeFactor * delta); + + theta += progression * thetaDelta; + phi += progression * phiDelta; + + // restrict phi to be between desired limits + phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) ); + + // restrict phi to be betwee EPS and PI-EPS + phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) ); + + //var radius = offset.length() * scale; + var radius = offset.length(); + radius += (scale-1) * radius * progression; + + // restrict radius to be between desired limits + radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) ); + + // move target to panned location + this.target.add( pan.clone().multiplyScalar( progression ) ); + + offset.x = radius * Math.sin( phi ) * Math.sin( theta ); + offset.y = radius * Math.cos( phi ); + offset.z = radius * Math.sin( phi ) * Math.cos( theta ); + + position.copy( this.target ).add( offset ); + + // send transformation proposal to listeners + var proposeTransformEvent = { + type: "proposeTransform", + oldPosition: this.object.position, + newPosition: position, + objections: 0, + counterProposals: [] + }; + this.dispatchEvent(proposeTransformEvent); + + // check some counter proposals if transformation wasn't accepted + if(proposeTransformEvent.objections > 0 ){ + + if(proposeTransformEvent.counterProposals.length > 0){ + var cp = proposeTransformEvent.counterProposals; + position.copy(cp[0]); + + proposeTransformEvent.objections = 0; + proposeTransformEvent.counterProposals = []; + } + } + + + // apply transformation, if accepted + if(proposeTransformEvent.objections > 0){ + thetaDelta = 0; + phiDelta = 0; + scale = 1; + pan.set(0,0,0); + }else{ + this.object.position.copy(position); + this.object.lookAt( this.target ); + + var attenuation = Math.max(0, 1 - this.fadeFactor * delta); + + thetaDelta *= attenuation; + phiDelta *= attenuation; + scale = 1 + (scale-1) * attenuation; + pan.multiplyScalar( attenuation ); + } + + if ( lastPosition.distanceTo( this.object.position ) > 0 ) { + + this.dispatchEvent( changeEvent ); + + lastPosition.copy( this.object.position ); + + } + + }; + + + this.reset = function () { + + state = STATE.NONE; + + this.target.copy( this.target0 ); + this.object.position.copy( this.position0 ); + + this.update(); + + }; + + function getAutoRotationAngle() { + + return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed; + + } + + function getZoomScale() { + + return Math.pow( 0.95, scope.zoomSpeed ); + + } + + function onMouseDown( event ) { + + if ( scope.enabled === false ) return; + event.preventDefault(); + + if ( event.button === 0 ) { + if ( scope.noRotate === true ) return; + + state = STATE.ROTATE; + + rotateStart.set( event.clientX, event.clientY ); + + } else if ( event.button === 1 ) { + if ( scope.noZoom === true ) return; + + state = STATE.DOLLY; + + dollyStart.set( event.clientX, event.clientY ); + + } else if ( event.button === 2 ) { + if ( scope.noPan === true ) return; + + state = STATE.PAN; + + panStart.set( event.clientX, event.clientY ); + + } + + scope.domElement.addEventListener( 'mousemove', onMouseMove, false ); + scope.domElement.addEventListener( 'mouseup', onMouseUp, false ); + scope.dispatchEvent( startEvent ); + + } + + function onMouseMove( event ) { + + if ( scope.enabled === false ) return; + + event.preventDefault(); + + var element = scope.domElement === document ? scope.domElement.body : scope.domElement; + + if ( state === STATE.ROTATE ) { + + if ( scope.noRotate === true ) return; + + rotateEnd.set( event.clientX, event.clientY ); + rotateDelta.subVectors( rotateEnd, rotateStart ); + + // rotating across whole screen goes 360 degrees around + scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed ); + + // rotating up and down along whole screen attempts to go 360, but limited to 180 + scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed ); + + rotateStart.copy( rotateEnd ); + + } else if ( state === STATE.DOLLY ) { + + if ( scope.noZoom === true ) return; + + dollyEnd.set( event.clientX, event.clientY ); + dollyDelta.subVectors( dollyEnd, dollyStart ); + + if ( dollyDelta.y > 0 ) { + + scope.dollyIn(); + + } else { + + scope.dollyOut(); + + } + + dollyStart.copy( dollyEnd ); + + } else if ( state === STATE.PAN ) { + + if ( scope.noPan === true ) return; + + panEnd.set( event.clientX, event.clientY ); + panDelta.subVectors( panEnd, panStart ); + + scope.pan( panDelta.x, panDelta.y ); + + panStart.copy( panEnd ); + + } + + //scope.update(); + + } + + function onMouseUp( /* event */ ) { + + if ( scope.enabled === false ) return; + + scope.domElement.removeEventListener( 'mousemove', onMouseMove, false ); + scope.domElement.removeEventListener( 'mouseup', onMouseUp, false ); + scope.dispatchEvent( endEvent ); + state = STATE.NONE; + + } + + function onMouseWheel( event ) { + + if ( scope.enabled === false || scope.noZoom === true ) return; + + event.preventDefault(); + + var delta = 0; + + if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9 + + delta = event.wheelDelta; + + } else if ( event.detail !== undefined ) { // Firefox + + delta = - event.detail; + + } + + if ( delta > 0 ) { + + scope.dollyOut(); + + } else { + + scope.dollyIn(); + + } + + //scope.update(); + scope.dispatchEvent( startEvent ); + scope.dispatchEvent( endEvent ); + + } + + function onKeyDown( event ) { + + if ( scope.enabled === false || scope.noKeys === true || scope.noPan === true ) return; + + switch ( event.keyCode ) { + + case scope.keys.UP: + scope.pan( 0, scope.keyPanSpeed ); + //scope.update(); + break; + + case scope.keys.BOTTOM: + scope.pan( 0, - scope.keyPanSpeed ); + //scope.update(); + break; + + case scope.keys.LEFT: + scope.pan( scope.keyPanSpeed, 0 ); + //scope.update(); + break; + + case scope.keys.RIGHT: + scope.pan( - scope.keyPanSpeed, 0 ); + //scope.update(); + break; + + } + + } + + function touchstart( event ) { + + if ( scope.enabled === false ) return; + + switch ( event.touches.length ) { + + case 1: // one-fingered touch: rotate + + if ( scope.noRotate === true ) return; + + state = STATE.TOUCH_ROTATE; + + rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + case 2: // two-fingered touch: dolly + + if ( scope.noZoom === true ) return; + + state = STATE.TOUCH_DOLLY; + + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + var distance = Math.sqrt( dx * dx + dy * dy ); + dollyStart.set( 0, distance ); + break; + + case 3: // three-fingered touch: pan + + if ( scope.noPan === true ) return; + + state = STATE.TOUCH_PAN; + + panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + break; + + default: + + state = STATE.NONE; + + } + + scope.dispatchEvent( startEvent ); + + } + + function touchmove( event ) { + + if ( scope.enabled === false ) return; + + event.preventDefault(); + event.stopPropagation(); + + var element = scope.domElement === document ? scope.domElement.body : scope.domElement; + + switch ( event.touches.length ) { + + case 1: // one-fingered touch: rotate + + if ( scope.noRotate === true ) return; + if ( state !== STATE.TOUCH_ROTATE ) return; + + rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + rotateDelta.subVectors( rotateEnd, rotateStart ); + + // rotating across whole screen goes 360 degrees around + scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed ); + // rotating up and down along whole screen attempts to go 360, but limited to 180 + scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed ); + + rotateStart.copy( rotateEnd ); + + //scope.update(); + break; + + case 2: // two-fingered touch: dolly + + if ( scope.noZoom === true ) return; + if ( state !== STATE.TOUCH_DOLLY ) return; + + var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; + var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; + var distance = Math.sqrt( dx * dx + dy * dy ); + + dollyEnd.set( 0, distance ); + dollyDelta.subVectors( dollyEnd, dollyStart ); + + var ew = element.clientWidth; + var eh = element.clientHeight; + var diagonal = Math.sqrt(ew * ew + eh * eh); + var delta = dollyDelta.y / diagonal; + + if ( dollyDelta.y > 0 ) { + + scope.dollyOut(1 - delta); + + } else { + + scope.dollyIn(1 + delta); + + } + + dollyStart.copy( dollyEnd ); + + //scope.update(); + break; + + case 3: // three-fingered touch: pan + + if ( scope.noPan === true ) return; + if ( state !== STATE.TOUCH_PAN ) return; + + panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); + panDelta.subVectors( panEnd, panStart ); + + scope.pan( panDelta.x, panDelta.y ); + + panStart.copy( panEnd ); + + //scope.update(); + break; + + default: + + state = STATE.NONE; + + } + + } + + function touchend( /* event */ ) { + + if ( scope.enabled === false ) return; + + scope.dispatchEvent( endEvent ); + state = STATE.NONE; + + } + + this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false ); + this.domElement.addEventListener( 'mousedown', onMouseDown, false ); + this.domElement.addEventListener( 'mousewheel', onMouseWheel, false ); + this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox + + this.domElement.addEventListener( 'touchstart', touchstart, false ); + this.domElement.addEventListener( 'touchend', touchend, false ); + this.domElement.addEventListener( 'touchmove', touchmove, false ); + + window.addEventListener( 'keydown', onKeyDown, false ); + +}; + +Potree.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype ); /** @@ -2082,6 +3258,13 @@ THREE.EarthControls = function ( camera, renderer, scene ) { this.update = function (delta) { var position = this.camera.position; + this.camera.updateMatrixWorld(); + + var proposal = new THREE.Object3D(); + proposal.position.copy(this.camera.position); + proposal.rotation.copy(this.camera.rotation); + proposal.updateMatrix(); + proposal.updateMatrixWorld(); if(pivot){ if(state === STATE.DRAG){ @@ -2100,7 +3283,7 @@ THREE.EarthControls = function ( camera, renderer, scene ) { if(distanceToPlane > 0){ var newCamPos = new THREE.Vector3().subVectors(pivot, dir.clone().multiplyScalar(distanceToPlane)); - this.camera.position.copy(newCamPos); + proposal.position.copy(newCamPos); } @@ -2111,7 +3294,6 @@ THREE.EarthControls = function ( camera, renderer, scene ) { diff.x *= 0.3; diff.y *= 0.2; - this.camera.updateMatrixWorld(); // do calculations on fresh nodes var p = new THREE.Object3D(); @@ -2153,17 +3335,33 @@ THREE.EarthControls = function ( camera, renderer, scene ) { // apply changes to object p.updateMatrixWorld(); - this.camera.position.copy(c.getWorldPosition()); - this.camera.quaternion.copy(c.getWorldQuaternion()); + proposal.position.copy(c.getWorldPosition()); + proposal.quaternion.copy(c.getWorldQuaternion()); } + var proposeTransformEvent = { + type: "proposeTransform", + oldPosition: this.camera.position, + newPosition: proposal.position, + objections: 0 + }; + this.dispatchEvent(proposeTransformEvent); + + if(proposeTransformEvent.objections > 0){ + + }else{ + this.camera.position.copy(proposal.position); + this.camera.rotation.copy(proposal.rotation); + } var wp = this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); var w = Math.abs(wp.z / 30); var l = this.pivotNode.scale.length(); this.pivotNode.scale.multiplyScalar(w / l); } + + mouseDelta.set(0,0); }; @@ -2179,9 +3377,11 @@ THREE.EarthControls = function ( camera, renderer, scene ) { if ( scope.enabled === false ) return; event.preventDefault(); + var rect = scope.domElement.getBoundingClientRect(); + var mouse = { - x: ( event.clientX / scope.domElement.clientWidth ) * 2 - 1, - y: - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1 + x: ( (event.clientX - rect.left) / scope.domElement.clientWidth ) * 2 - 1, + y: - ( (event.clientY - rect.top) / scope.domElement.clientHeight ) * 2 + 1 }; var I = getMousePointCloudIntersection(mouse, scope.camera, scope.renderer, scope.pointclouds) if(!I){ @@ -2200,8 +3400,8 @@ THREE.EarthControls = function ( camera, renderer, scene ) { //pivot = I; camStart = scope.camera.clone(); camStart.rotation.copy(scope.camera.rotation); - dragStart.set( event.clientX, event.clientY ); - dragEnd.set(event.clientX, event.clientY); + dragStart.set( event.clientX - rect.left, event.clientY - rect.top); + dragEnd.set(event.clientX - rect.left, event.clientY - rect.top); scope.scene.add(scope.pivotNode); @@ -2221,11 +3421,13 @@ THREE.EarthControls = function ( camera, renderer, scene ) { if ( scope.enabled === false ) return; event.preventDefault(); + + var rect = scope.domElement.getBoundingClientRect(); var element = scope.domElement === document ? scope.domElement.body : scope.domElement; - mouseDelta.set(event.clientX - dragEnd.x, event.clientY - dragEnd.y); - dragEnd.set(event.clientX, event.clientY); + mouseDelta.set(event.clientX - rect.left - dragEnd.x, event.clientY - rect.top - dragEnd.y); + dragEnd.set(event.clientX - rect.left, event.clientY - rect.top); } @@ -2245,11 +3447,13 @@ THREE.EarthControls = function ( camera, renderer, scene ) { if ( scope.enabled === false || scope.noZoom === true ) return; event.preventDefault(); + + var rect = scope.domElement.getBoundingClientRect(); var amount = (event.detail<0 || event.wheelDelta>0) ? 1 : -1; var mouse = { - x: ( event.clientX / scope.domElement.clientWidth ) * 2 - 1, - y: - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1 + x: ( (event.clientX - rect.left) / scope.domElement.clientWidth ) * 2 - 1, + y: - ( (event.clientY - rect.top) / scope.domElement.clientHeight ) * 2 + 1 }; var I = getMousePointCloudIntersection(mouse, scope.camera, scope.renderer, scope.pointclouds) @@ -2315,6 +3519,10 @@ LRU.prototype.contains = function(node){ * @param node */ LRU.prototype.touch = function(node){ + if(!node.loaded){ + return; + } + var item; if(this.items[node.id] == null){ // add to list @@ -2361,31 +3569,61 @@ LRU.prototype.touch = function(node){ } }; -/** - * removes the least recently used item from the list and returns it. - * if the list was empty, null will be returned. - */ -LRU.prototype.remove = function remove(){ - if(this.first === null){ - return null; - } - var lru = this.first; +///** +// * removes the least recently used item from the list and returns it. +// * if the list was empty, null will be returned. +// */ +//LRU.prototype.remove = function remove(){ +// if(this.first === null){ +// return null; +// } +// var lru = this.first; +// +// // if the lru list contains at least 2 items, the item after the least recently used elemnt will be the new lru item. +// if(lru.next !== null){ +// this.first = lru.next; +// this.first.previous = null; +// }else{ +// this.first = null; +// this.last = null; +// } +// +// delete this.items[lru.node.id]; +// this.elements--; +// this.numPoints -= lru.node.numPoints; +// +//// Logger.info("removed node: " + lru.node.id); +// return lru.node; +//}; - // if the lru list contains at least 2 items, the item after the least recently used elemnt will be the new lru item. - if(lru.next !== null){ - this.first = lru.next; - this.first.previous = null; - }else{ - this.first = null; - this.last = null; +LRU.prototype.remove = function remove(node){ + + var lruItem = this.items[node.id]; + if(lruItem){ + + if(this.elements === 1){ + this.first = null; + this.last = null; + }else{ + if(!lruItem.previous){ + this.first = lruItem.next; + this.first.previous = null; + } + if(!lruItem.next){ + this.last = lruItem.previous; + this.last.next = null; + } + if(lruItem.previous &&lruItem.next){ + lruItem.previous.next = lruItem.next; + lruItem.next.previous = lruItem.previous; + } + } + + delete this.items[node.id]; + this.elements--; + this.numPoints -= node.numPoints; } - delete this.items[lru.node.id]; - this.elements--; - this.numPoints -= lru.node.numPoints; - -// Logger.info("removed node: " + lru.node.id); - return lru.node; }; LRU.prototype.getLRUItem = function(){ @@ -2412,6 +3650,38 @@ LRU.prototype.toString = function(){ return string; }; +LRU.prototype.freeMemory = function(){ + if(this.elements <= 1){ + return; + } + + while(this.numPoints > Potree.pointLoadLimit){ + var element = this.first; + var node = element.node; + this.disposeDescendants(node); + + }; +}; + +LRU.prototype.disposeDescendants = function(node){ + var stack = []; + stack.push(node); + while(stack.length > 0){ + var current = stack.pop(); + + current.dispose(); + this.remove(current); + + for(var key in current.children){ + if(current.children.hasOwnProperty(key)){ + var child = current.children[key]; + if(child.loaded){ + stack.push(current.children[key]); + } + } + } + } +}; /** @@ -2477,10 +3747,9 @@ Potree.PointCloudOctree = function(geometry, material){ this.pcoGeometry = geometry; this.boundingBox = this.pcoGeometry.tightBoundingBox; this.boundingSphere = this.boundingBox.getBoundingSphere(); - //this.boundingBox = this.pcoGeometry.root.boundingBox; - //this.boundingSphere = this.boundingBox.getBoundingSphere(); this.material = material || new Potree.PointCloudMaterial(); this.visiblePointsTarget = 2*1000*1000; + this.minimumNodePixelSize = 150; this.level = 0; this.position.sub(geometry.offset); this.updateMatrix(); @@ -2498,6 +3767,7 @@ Potree.PointCloudOctree = function(geometry, material){ this.pickTarget; this.pickMaterial; this.maxLevel = 0; + this.generateDEM = false; var rootProxy = new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root); this.add(rootProxy); @@ -2631,6 +3901,12 @@ Potree.PointCloudOctree.prototype.updatePointCloud = function(node, element, sta node.boundingBoxNode.visible = false; } + if(this.generateDEM && node.level <= 2){ + if(!node.dem){ + node.dem = this.createDEM(node); + } + } + for(var i = 0; i < node.children.length; i++){ var child = node.children[i]; var visible = visibleGeometryNames.indexOf(child.name) >= 0; @@ -2690,7 +3966,7 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){ this.updateMatrixWorld(true); - this.visibleGeometry = this.getVisibleGeometry(camera); + this.visibleGeometry = this.getVisibleGeometry(camera, renderer); var visibleGeometryNames = []; for(var i = 0; i < this.visibleGeometry.length; i++){ @@ -2731,7 +4007,15 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){ this.loadQueue.push(element); } }else if(node instanceof THREE.PointCloud){ - this.updatePointCloud(node, element, stack, visibleGeometryNames); + if(node.pcoGeometry.loaded){ + Potree.PointCloudOctree.lru.touch(node.pcoGeometry); + this.updatePointCloud(node, element, stack, visibleGeometryNames); + }else{ + var proxy = new Potree.PointCloudOctreeProxyNode(node.pcoGeometry); + var parent = node.parent; + parent.remove(node); + parent.add(proxy); + } } } @@ -2747,9 +4031,10 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){ } this.updateMaterial(vn, camera, renderer); + Potree.PointCloudOctree.lru.freeMemory(); }; -Potree.PointCloudOctree.prototype.getVisibleGeometry = function(camera){ +Potree.PointCloudOctree.prototype.getVisibleGeometry = function(camera, renderer){ var visibleGeometry = []; var geometry = this.pcoGeometry; @@ -2826,7 +4111,9 @@ Potree.PointCloudOctree.prototype.getVisibleGeometry = function(camera){ // see http://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space var fov = camera.fov / 2 * Math.PI / 180.0; var pr = 1 / Math.tan(fov) * radius / Math.sqrt(distance * distance - radius * radius); - if(pr < 0.1){ + + var screenPixelRadius = renderer.domElement.clientHeight * pr; + if(screenPixelRadius < this.minimumNodePixelSize){ continue; } @@ -3268,61 +4555,72 @@ Potree.PointCloudOctree.prototype.getProfile = function(start, end, width, depth } } -/** - * - * amount: minimum number of points to remove - */ -Potree.PointCloudOctree.disposeLeastRecentlyUsed = function(amount){ - - - var freed = 0; - do{ - var node = this.lru.first.node; - var parent = node.parent; - var geometry = node.geometry; - var pcoGeometry = node.pcoGeometry; - var proxy = new Potree.PointCloudOctreeProxyNode(pcoGeometry); - - var result = Potree.PointCloudOctree.disposeNode(node); - freed += result.freed; - - parent.add(proxy); - - if(result.numDeletedNodes == 0){ - break; - } - }while(freed < amount); -} - -Potree.PointCloudOctree.disposeNode = function(node){ - - var freed = 0; - var numDeletedNodes = 0; - var descendants = []; - - node.traverse(function(object){ - descendants.push(object); - }); - - for(var i = 0; i < descendants.length; i++){ - var descendant = descendants[i]; - if(descendant instanceof THREE.PointCloud){ - freed += descendant.pcoGeometry.numPoints; - descendant.pcoGeometry.dispose(); - descendant.geometry.dispose(); - Potree.PointCloudOctree.lru.remove(descendant); - numDeletedNodes++; - } - } - - Potree.PointCloudOctree.lru.remove(node); - node.parent.remove(node); - - return { - "freed": freed, - "numDeletedNodes": numDeletedNodes - }; -} +///** +// * +// * amount: minimum number of points to remove +// */ +//Potree.PointCloudOctree.disposeLeastRecentlyUsed = function(amount){ +// +// return; +// +// var freed = 0; +// do{ +// if(!Potree.PointCloudOctree.lru.first){ +// return; +// } +// +// var node = Potree.PointCloudOctree.lru.first.node; +// if(node.visible){ +// return; +// } +// +// var parent = node.parent; +// var geometry = node.geometry; +// var pcoGeometry = node.pcoGeometry; +// var proxy = new Potree.PointCloudOctreeProxyNode(pcoGeometry); +// +// var result = Potree.PointCloudOctree.disposeNode(node); +// freed += result.freed; +// +// parent.add(proxy); +// +// if(result.numDeletedNodes == 0){ +// break; +// } +// }while(freed < amount); +//} +// +//Potree.PointCloudOctree.disposeNode = function(node){ +// +// var freed = 0; +// var numDeletedNodes = 0; +// var descendants = []; +// +// node.traverse(function(object){ +// descendants.push(object); +// }); +// +// for(var i = 0; i < descendants.length; i++){ +// var descendant = descendants[i]; +// if(descendant instanceof THREE.PointCloud){ +// freed += descendant.pcoGeometry.numPoints; +// descendant.pcoGeometry.dispose(); +// descendant.geometry.dispose(); +// Potree.PointCloudOctree.lru.remove(descendant); +// numDeletedNodes++; +// +// console.log("disposed: " + node.name + "\t, " + renderer.info.memory.geometries + ", " + Potree.PointCloudOctree.lru.elements); +// } +// } +// +// Potree.PointCloudOctree.lru.remove(node); +// node.parent.remove(node); +// +// return { +// "freed": freed, +// "numDeletedNodes": numDeletedNodes +// }; +//} Potree.PointCloudOctree.prototype.getVisibleExtent = function(){ return this.visibleBounds.applyMatrix4(this.matrixWorld); @@ -3339,7 +4637,7 @@ Potree.PointCloudOctree.prototype.getVisibleExtent = function(){ * TODO: only draw pixels that are actually read with readPixels(). * */ -var point = Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params){ +Potree.PointCloudOctree.prototype.pick = function(renderer, camera, ray, params){ // this function finds intersections by rendering point indices and then checking the point index at the mouse location. // point indices are 3 byte and rendered to the RGB component. // point cloud node indices are 1 byte and stored in the ALPHA component. @@ -3453,14 +4751,18 @@ var point = Potree.PointCloudOctree.prototype.pick = function(renderer, camera, _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); } - - - var pickWindowSize = 17; var pixelCount = pickWindowSize * pickWindowSize; var buffer = new ArrayBuffer(pixelCount*4); var pixels = new Uint8Array(buffer); @@ -3536,6 +4838,330 @@ var point = Potree.PointCloudOctree.prototype.pick = function(renderer, camera, } } +var demTime = 0; + +Potree.PointCloudOctree.prototype.createDEM = function(node){ + + var start = new Date().getTime(); + + + var world = node.matrixWorld; + + var boundingBox = node.boundingBox.clone().applyMatrix4(world); + var bbSize = boundingBox.size(); + var positions = node.geometry.attributes.position.array; + var demSize = 64; + var demMArray = new Array(demSize*demSize); + var dem = new Float32Array(demSize*demSize); + var n = positions.length / 3; + + var toWorld = function(dx, dy){ + var x = (dx * bbSize.x) / (demSize - 1) + boundingBox.min.x; + var y = dem[dx + dy * demSize]; + var z = (dy * bbSize.z) / (demSize - 1)+ boundingBox.min.z; + + return [x, y, z]; + }; + + var toDem = function(x, y){ + var dx = parseInt(demSize * (x - boundingBox.min.x) / bbSize.x); + var dy = parseInt(demSize * (z - boundingBox.min.z) / bbSize.z); + dx = Math.min(dx, demSize - 1); + dy = Math.min(dy, demSize - 1); + + return [dx, dy]; + }; + + for(var i = 0; i < n; i++){ + var x = positions[3*i + 0]; + var y = positions[3*i + 1]; + var z = positions[3*i + 2]; + + var worldPos = new THREE.Vector3(x,y,z).applyMatrix4(world); + + var dx = parseInt(demSize * (worldPos.x - boundingBox.min.x) / bbSize.x); + var dy = parseInt(demSize * (worldPos.z - boundingBox.min.z) / bbSize.z); + dx = Math.min(dx, demSize - 1); + dy = Math.min(dy, demSize - 1); + + var index = dx + dy * demSize; + if(!demMArray[index]){ + demMArray[index] = []; + } + demMArray[index].push(worldPos.y); + + //if(dem[dx + dy * demSize] === 0){ + // dem[dx + dy * demSize] = worldPos.y; + //}else{ + // dem[dx + dy * demSize] = Math.max(dem[dx + dy * demSize], worldPos.y); + //} + } + + for(var i = 0; i < demMArray.length; i++){ + var values = demMArray[i]; + + if(!values){ + dem[i] = 0; + }else if(values.length === 0){ + dem[i] = 0; + }else{ + var medianIndex = parseInt((values.length-1) / 2); + dem[i] = values[medianIndex]; + } + } + + var box2 = new THREE.Box2(); + box2.expandByPoint(new THREE.Vector3(boundingBox.min.x, boundingBox.min.z)); + box2.expandByPoint(new THREE.Vector3(boundingBox.max.x, boundingBox.max.z)); + + var result = { + boundingBox: boundingBox, + boundingBox2D: box2, + dem: dem, + demSize: demSize + }; + + + + //var geometry = new THREE.BufferGeometry(); + //var vertices = new Float32Array((demSize-1)*(demSize-1)*2*3*3); + //var offset = 0; + //for(var i = 0; i < demSize-1; i++){ + // for(var j = 0; j < demSize-1; j++){ + // //var offset = 18*i + 18*j*demSize; + // + // var dx = i; + // var dy = j; + // + // var v1 = toWorld(dx, dy); + // var v2 = toWorld(dx+1, dy); + // var v3 = toWorld(dx+1, dy+1); + // var v4 = toWorld(dx, dy+1); + // + // vertices[offset+0] = v3[0]; + // vertices[offset+1] = v3[1]; + // vertices[offset+2] = v3[2]; + // + // vertices[offset+3] = v2[0]; + // vertices[offset+4] = v2[1]; + // vertices[offset+5] = v2[2]; + // + // vertices[offset+6] = v1[0]; + // vertices[offset+7] = v1[1]; + // vertices[offset+8] = v1[2]; + // + // + // vertices[offset+9 ] = v3[0]; + // vertices[offset+10] = v3[1]; + // vertices[offset+11] = v3[2]; + // + // vertices[offset+12] = v1[0]; + // vertices[offset+13] = v1[1]; + // vertices[offset+14] = v1[2]; + // + // vertices[offset+15] = v4[0]; + // vertices[offset+16] = v4[1]; + // vertices[offset+17] = v4[2]; + // + // + // + // //var x = (dx * bbSize.min.x) / demSize + boundingBox.min.x; + // //var y = (dy * bbSize.min.y) / demSize + boundingBox.min.y; + // //var z = dem[dx + dy * demSize]; + // + // offset += 18; + // + // } + //} + // + //geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) ); + //geometry.computeFaceNormals(); + //geometry.computeVertexNormals(); + // + //var material = new THREE.MeshNormalMaterial( { color: 0xff0000, shading: THREE.SmoothShading } ); + //var mesh = new THREE.Mesh( geometry, material ); + // + //if(node.level == 1){ + // scene.add(mesh); + // + // var demb = new Uint8Array(demSize*demSize*4); + // for(var i = 0; i < demSize*demSize; i++){ + // demb[4*i + 0] = 255 * dem[i] / 6000; + // demb[4*i + 1] = 255 * dem[i] / 6000; + // demb[4*i + 2] = 255 * dem[i] / 6000; + // demb[4*i + 3] = 255; + // } + // + // var img = pixelsArrayToImage(demb, demSize, demSize); + // img.style.boder = "2px solid red"; + // var txt = document.createElement("div"); + // txt.innerHTML = node.name; + // document.body.appendChild(txt); + // document.body.appendChild(img); + //} + + + + //console.log(n); + // + var end = new Date().getTime(); + var duration = end - start; + //console.log(node.numPoints + " - " + duration); + + demTime += duration; + + + + + return result; +} + +Potree.PointCloudOctree.prototype.getDEMHeight = function(position){ + var pos2 = new THREE.Vector2(position.x, position.z); + + var demHeight = function(dem){ + var demSize = dem.demSize; + var box = dem.boundingBox2D; + var insideBox = box.containsPoint(pos2); + if(box.containsPoint(pos2)){ + var uv = pos2.clone().sub(box.min).divide(box.size()); + var xy = uv.clone().multiplyScalar(demSize); + + var demHeight = 0; + + if((xy.x > 0.5 && xy.x < demSize - 0.5) && (xy.y > 0.5 && xy.y < demSize - 0.5)){ + var i = Math.floor(xy.x - 0.5); + var j = Math.floor(xy.y - 0.5); + i = (i === demSize - 1) ? (demSize-2) : i; + j = (j === demSize - 1) ? (demSize-2) : j; + + var u = xy.x - i - 0.5; + var v = xy.y - j - 0.5; + + var index00 = i + j * demSize; + var index10 = (i+1) + j * demSize; + var index01 = i + (j+1) * demSize; + var index11 = (i+1) + (j+1) * demSize; + + var height00 = dem.dem[index00]; + var height10 = dem.dem[index10]; + var height01 = dem.dem[index01]; + var height11 = dem.dem[index11]; + + if(height00 === 0 || height10 === 0 || height01 === 0 || height11 === 0){ + demHeight = null; + }else{ + + var hx1 = height00 * (1-u) + height10 * u; + var hx2 = height01 * (1-u) + height11 * u; + + demHeight = hx1 * (1-v) + hx2 * v; + } + + var bla; + }else{ + xy.x = Math.min(parseInt(Math.min(xy.x, demSize)), demSize-1); + xy.y = Math.min(parseInt(Math.min(xy.y, demSize)), demSize-1); + + var index = xy.x + xy.y * demSize; + demHeight = dem.dem[index]; + } + + + return demHeight; + } + + return null; + }; + + var height = null; + + var stack = []; + var chosenNode = null; + if(this.children[0].dem){ + stack.push(this.children[0]); + } + while(stack.length > 0){ + var node = stack.shift(); + var dem = node.dem; + + var demSize = dem.demSize; + var box = dem.boundingBox2D; + var insideBox = box.containsPoint(pos2); + if(!box.containsPoint(pos2)){ + continue; + } + + var dh = demHeight(dem); + if(!height){ + height = dh; + }else if(dh != null && dh > 0){ + height = dh; + } + + if(node.level <= 2){ + for(var i = 0; i < node.children.length; i++){ + var child = node.children[i]; + if(child.dem){ + stack.push(child); + } + } + } + } + + + + return height; +} + +Potree.PointCloudOctree.prototype.generateTerain = function(){ + var bb = this.boundingBox.clone().applyMatrix4(this.matrixWorld); + + var width = 300; + var height = 300; + var geometry = new THREE.BufferGeometry(); + var vertices = new Float32Array(width*height*3); + + var offset = 0; + for(var i = 0; i < width; i++){ + for( var j = 0; j < height; j++){ + var u = i / width; + var v = j / height; + + var x = u * bb.size().x + bb.min.x; + var z = v * bb.size().z + bb.min.z; + + var y = this.getDEMHeight(new THREE.Vector3(x, 0, z)); + if(!y){ + y = 0; + } + + vertices[offset + 0] = x; + vertices[offset + 1] = y; + vertices[offset + 2] = z; + + //var sm = new THREE.Mesh(sg); + //sm.position.set(x,y,z); + //scene.add(sm); + + offset += 3; + } + } + + geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) ); + var material = new THREE.PointCloudMaterial({size: 20, color: 0x00ff00}); + + var pc = new THREE.PointCloud(geometry, material); + scene.add(pc); + +}; + +Object.defineProperty(Potree.PointCloudOctree.prototype, "progress", { + get: function(){ + return this.visibleNodes.length / this.visibleGeometry.length; + } +}); + var nodesLoadTimes = {}; Potree.PointCloudOctreeGeometry = function(){ @@ -3554,9 +5180,11 @@ Potree.PointCloudOctreeGeometry = function(){ } Potree.PointCloudOctreeGeometryNode = function(name, pcoGeometry, boundingBox){ + this.id = Potree.PointCloudOctreeGeometryNode.IDCount++; this.name = name; this.index = parseInt(name.charAt(name.length-1)); this.pcoGeometry = pcoGeometry; + this.geometry = null; this.boundingBox = boundingBox; this.boundingSphere = boundingBox.getBoundingSphere(); this.children = {}; @@ -3564,6 +5192,8 @@ Potree.PointCloudOctreeGeometryNode = function(name, pcoGeometry, boundingBox){ this.level = null; } +Potree.PointCloudOctreeGeometryNode.IDCount = 0; + Potree.PointCloudOctreeGeometryNode.prototype.getURL = function(){ var url = ""; @@ -3590,6 +5220,8 @@ Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath = function(){ for(var i = 0; i < numParts; i++){ path += indices.substr(i * hierarchyStepSize, hierarchyStepSize) + "/"; } + + path = path.slice(0,-1); return path; } @@ -3606,9 +5238,9 @@ Potree.PointCloudOctreeGeometryNode.prototype.load = function(){ this.loading = true; - if(Potree.PointCloudOctree.lru.numPoints + this.numPoints >= Potree.pointLoadLimit){ - Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints); - } + //if(Potree.PointCloudOctree.lru.numPoints + this.numPoints >= Potree.pointLoadLimit){ + // Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints); + //} this.pcoGeometry.numNodesLoading++; @@ -3734,8 +5366,11 @@ Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function( Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){ - delete this.geometry; - this.loaded = false; + if(this.geometry){ + this.geometry.dispose(); + this.geometry = null; + this.loaded = false; + } } @@ -3958,19 +5593,124 @@ function pixelsArrayToImage(pixels, width, height){ return img; } + +function projectedRadius(radius, fov, distance, screenHeight){ + var projFactor = (1 / Math.tan(fov / 2)) / distance; + projFactor = projFactor * screenHeight / 2; + + return radius * projFactor; +}; +Potree.utils.topView = function(camera, controls, pointcloud){ + camera.position.set(0, 1, 0); + camera.rotation.set(-Math.PI / 2, 0, 0); + camera.zoomTo(pointcloud, 1); + + if(controls.target){ + var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld); + var target = new THREE.Vector3(camera.position.x, sg.center.y, camera.position.z); + controls.target.copy(target); + } +} + +Potree.utils.frontView = function(camera, controls, pointcloud){ + camera.position.set(0, 0, 1); + camera.rotation.set(0, 0, 0); + camera.zoomTo(pointcloud, 1); + + if(controls.target){ + var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld); + var target = new THREE.Vector3(camera.position.x, camera.position.y, sg.center.z); + controls.target.copy(target); + } +} + + +Potree.utils.leftView = function(camera, controls, pointcloud){ + camera.position.set(-1, 0, 0); + camera.rotation.set(0, -Math.PI / 2, 0); + camera.zoomTo(pointcloud, 1); + + if(controls.target){ + var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld); + var target = new THREE.Vector3(sg.center.x, camera.position.y, camera.position.z); + controls.target.copy(target); + } +} + +Potree.utils.rightView = function(camera, controls, pointcloud){ + camera.position.set(1, 0, 0); + camera.rotation.set(0, Math.PI / 2, 0); + camera.zoomTo(pointcloud, 1); + + if(controls.target){ + var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld); + var target = new THREE.Vector3(sg.center.x, camera.position.y, camera.position.z); + controls.target.copy(target); + } +} +/** + * + * 0: no intersection + * 1: intersection + * 2: fully inside + */ +Potree.utils.frustumSphereIntersection = function(frustum, sphere){ + var planes = frustum.planes; + var center = sphere.center; + var negRadius = - sphere.radius; + + var minDistance = Number.MAX_VALUE; - + for ( var i = 0; i < 6; i ++ ) { + + var distance = planes[ i ].distanceToPoint( center ); + + if ( distance < negRadius ) { + + return 0; + + } + + minDistance = Math.min(minDistance, distance); + + } + + return (minDistance >= sphere.radius) ? 2 : 1; +}; Potree.Features = function(){ - - var gl = document.createElement("canvas").getContext("webgl"); + + var ftCanvas = document.createElement("canvas"); + var gl = ftCanvas.getContext("webgl") || ftCanvas.getContext("experimental-webgl"); + + // -- code taken from THREE.WebGLRenderer -- + var _vertexShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ); + var _vertexShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ); + var _vertexShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.LOW_FLOAT ); + + var _fragmentShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ); + var _fragmentShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ); + var _fragmentShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.LOW_FLOAT ); + + var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0; + var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0; + // ----------------------------------------- + + var precision; + if(highpAvailable){ + precision = "highp"; + }else if(mediumpAvailable){ + precision = "mediump"; + }else{ + precision = "lowp"; + } return { SHADER_INTERPOLATION: { @@ -3998,7 +5738,8 @@ Potree.Features = function(){ } - } + }, + precision: precision } }(); @@ -4011,6 +5752,8 @@ Potree.TextSprite = function(text){ THREE.Object3D.call(this); var texture = new THREE.Texture(); + texture.minFilter = THREE.LinearFilter; + texture.magFilter = THREE.LinearFilter; var spriteMaterial = new THREE.SpriteMaterial( { map: texture, useScreenCoordinates: false} ); @@ -4096,6 +5839,8 @@ Potree.TextSprite.prototype.update = function(){ var texture = new THREE.Texture(canvas); + texture.minFilter = THREE.LinearFilter; + texture.magFilter = THREE.LinearFilter; texture.needsUpdate = true; //var spriteMaterial = new THREE.SpriteMaterial( @@ -4164,774 +5909,39 @@ Potree.Version.prototype.equalOrHigher = function(version){ Potree.Version.prototype.upTo = function(version){ return !this.newerThan(version); } -/* global THREE, Potree */ -// Tool to calculate angles between lines. -// Limited (on purpose) to 3 points. -// @author m-schuetz, maartenvm - -Potree.AngleTool = function(scene, camera, renderer){ - 'use strict'; - +Potree.Measure = function(){ var scope = this; - this.enabled = false; - this.scene = scene; - this.camera = camera; - this.renderer = renderer; - this.domElement = renderer.domElement; - this.mouse = {x: 0, y: 0}; - this.accuracy = 0.5; + THREE.Object3D.call( this ); - var STATE = { - DEFAULT: 0, - PICKING: 1 - }; + this.points = []; + this._showDistances = true; + this._showArea = true; + this._closed = true; + this.maxMarkers = Number.MAX_SAFE_INTEGER; - var state = STATE.DEFAULT; + this.spheres = []; + this.edges = []; + this.sphereLabels = []; + this.edgeLabels = []; + this.angleLabels = []; - this.activeMeasurement = null; - this.measurements = []; - this.sceneMeasurement = new THREE.Scene(); - this.sceneRoot = new THREE.Object3D(); - this.sceneMeasurement.add(this.sceneRoot); - - this.light = new THREE.DirectionalLight( 0xffffff, 1 ); - this.light.position.set( 0, 0, 10 ); - this.light.lookAt(new THREE.Vector3(0,0,0)); - this.sceneMeasurement.add( this.light ); - - this.hoveredElement = null; - - var moveEvent = function(event){ - event.target.material.emissive.setHex(0x888888); - }; - - var leaveEvent = function(event){ - event.target.material.emissive.setHex(0x000000); - }; - - var dragEvent = function(event){ - var I = getMousePointCloudIntersection(); - - if(I){ - for(var i = 0; i < scope.measurements.length; i++){ - var m = scope.measurements[i]; - var index = m.spheres.indexOf(scope.dragstart.object); - - if(index >= 0){ - scope.measurements[i].setPosition(index, I); - - - break; - } - } - - //scope.dragstart.object.position.copy(I); - } - - event.event.stopImmediatePropagation(); - }; - - var dropEvent = function(event){ - if(event === undefined) { - return; - } - }; - - - function Measure(root){ - this.points = []; - this.spheres = []; - this.edges = []; - this.sphereLabels = []; - this.angleLabels = []; - this.root = root; - this.closed = true; - - var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); - var lineColor = new THREE.Color( 0xff0000 ); - - var createSphereMaterial = function(){ - var sphereMaterial = new THREE.MeshLambertMaterial({ - shading: THREE.SmoothShading, - color: 0xff0000, - ambient: 0xaaaaaa, - depthTest: false, - depthWrite: false} - ); - - return sphereMaterial; - }; - - this.add = function(point){ - this.points.push(point); - - // sphere - var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - sphere.addEventListener('mousemove', moveEvent); - sphere.addEventListener('mouseleave', leaveEvent); - sphere.addEventListener('mousedrag', dragEvent); - sphere.addEventListener('drop', dropEvent); - - // edge - var lineGeometry = new THREE.Geometry(); - lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3()); - lineGeometry.colors.push(lineColor, lineColor, lineColor); - var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, linewidth: 2 } ); - lineMaterial.depthTest = false; - var edge = new THREE.Line(lineGeometry, lineMaterial); - - // angleLabel - var angleLabel = new Potree.TextSprite(); - angleLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); - angleLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); - angleLabel.material.depthTest = false; - angleLabel.material.opacity = 1; - - this.root.add(sphere); - this.root.add(edge); - this.root.add(angleLabel); - - this.spheres.push(sphere); - this.edges.push(edge); - this.angleLabels.push(angleLabel); - - this.setPosition(this.points.length-1, point); - }; - - this.remove = function(index){ - this.points.splice(index, 1); - - this.root.remove(this.spheres[index]); - this.root.remove(this.edges[index]); - this.root.remove(this.angleLabels[index]); - - this.spheres.splice(index, 1); - this.edges.splice(index, 1); - this.angleLabels.splice(index, 1); - - this.update(); - }; - - this.removeAll = function(){ - while (this.points.length > 1) { - this.remove(0); - } - - this.sceneRoot.visible = false; - - this.update(); - }; - - this.getAngleBetweenLines = function(cornerPoint, point1, point2) { - var v1 = new THREE.Vector3().subVectors(point1, cornerPoint); - var v2 = new THREE.Vector3().subVectors(point2, cornerPoint); - return v1.angleTo(v2); - }; - - this.getAngle = function(index){ - var angle = 0; - - var p0 = this.points[0]; - var p1 = this.points[1]; - var p2 = this.points[2]; - - if (index === 0) { - angle = this.getAngleBetweenLines(p0, p1, p2); - } else if (index === 1) { - angle = this.getAngleBetweenLines(p1, p0, p2); - } else if (index === 2) { - angle = this.getAngleBetweenLines(p2, p0, p1); - } - - return angle; - }; - - this.setPosition = function(index, position){ - var point = this.points[index]; - point.copy(position); - - this.update(); - }; - - this.setClosed = function(closed){ - this.closed = closed; - - this.update(); - }; - - this.update = function(){ - //this.areaLabel.visible = this.points.length >= 3; - - var point, i; - - if(this.points.length === 1){ - point = this.points[0]; - this.spheres[0].position.copy(point); - this.edges[0].visible = false; - this.angleLabels[0].visible = false; - - return; - } - - var lastIndex = this.points.length - 1; - - var centroid = new THREE.Vector3(); - - for(i = 0; i <= lastIndex; i++){ - point = this.points[i]; - var sphere = this.spheres[i]; - var leftIndex = (i === 0) ? lastIndex : i - 1; - var leftEdge = this.edges[leftIndex]; - var rightEdge = this.edges[i]; - - sphere.position.copy(point); - leftEdge.geometry.vertices[1].copy(point); - leftEdge.geometry.verticesNeedUpdate = true; - leftEdge.geometry.computeBoundingSphere(); - rightEdge.geometry.vertices[0].copy(point); - rightEdge.geometry.verticesNeedUpdate = true; - rightEdge.geometry.computeBoundingSphere(); - - if(i === lastIndex && !this.closed){ - rightEdge.visible = false; - }else{ - rightEdge.visible = true; - } - - centroid.add(point); - } - centroid.multiplyScalar(1 / this.points.length); - - if (this.points.length >= 3) { - for(i = 0; i <= lastIndex; i++){ - this.angleLabels[i].visible = true; - - this.angleLabels[i].setText(Potree.utils.addCommas((this.getAngle(i)*(180.0/Math.PI)).toFixed(1)) + '\u00B0'); - var anglePos = new THREE.Vector3().addVectors(this.points[i], centroid).multiplyScalar(0.5); - this.angleLabels[i].position.copy(anglePos); - } - } else { - for(i = 0; i <= lastIndex; i++){ - this.angleLabels[i].visible = false; - } - } - }; - } - - function onClick(event) { - if(!scope.enabled || event === undefined) { - return; - } - - var I = getMousePointCloudIntersection(); - if(I) { - var pos = I.clone(); - - if(state === STATE.DEFAULT){ - state = STATE.PICKING; - scope.activeMeasurement = new Measure(); - } - - if (state === STATE.PICKING && scope.activeMeasurement && scope.activeMeasurement.points.length > 2) { - scope.measurements.push(scope.activeMeasurement); - scope.activeMeasurement = undefined; - state = STATE.DEFAULT; - scope.setEnabled(false); - } else { - scope.activeMeasurement.add(pos); - - var newEvent = { - type: 'newpoint', - position: pos.clone() - }; - scope.dispatchEvent(newEvent); - } - } - } - - function onMouseMove(event){ - if(event === undefined) { - return; - } - - var rect = scope.domElement.getBoundingClientRect(); - scope.mouse.x = ((event.clientX - rect.left) / scope.domElement.clientWidth) * 2 - 1; - scope.mouse.y = -((event.clientY - rect.top) / scope.domElement.clientHeight) * 2 + 1; - - var I; - - if(scope.dragstart){ - - scope.dragstart.object.dispatchEvent({type: 'mousedrag', event: event}); - - }else if(state === STATE.PICKING && scope.activeMeasurement){ - I = getMousePointCloudIntersection(); - - if(I){ - - var lastIndex = scope.activeMeasurement.points.length-1; - scope.activeMeasurement.setPosition(lastIndex, I); - } - - }else{ - I = getHoveredElement(); - - if(I){ - - I.object.dispatchEvent({type: 'mousemove', target: I.object, event: event}); - - if(scope.hoveredElement && scope.hoveredElement !== I.object){ - scope.hoveredElement.dispatchEvent({type: 'mouseleave', target: scope.hoveredElement, event: event}); - } - - scope.hoveredElement = I.object; - - }else{ - - if(scope.hoveredElement){ - scope.hoveredElement.dispatchEvent({type: 'mouseleave', target: scope.hoveredElement, event: event}); - } - - scope.hoveredElement = null; - - } - } - } - - function onRightClick(event){ - if(event === undefined) { - return; - } - - if(state === STATE.PICKING){ - scope.activeMeasurement.removeAll(); - scope.activeMeasurement = undefined; - - state = STATE.DEFAULT; - scope.setEnabled(false); - } - } - - function onMouseDown(event){ - - if(event.which === 1){ - - if(state !== STATE.DEFAULT){ - event.stopImmediatePropagation(); - } - - var I = getHoveredElement(); - - if(I){ - scope.dragstart = { - object: I.object, - sceneClickPos: I.point, - sceneStartPos: scope.sceneRoot.position.clone(), - mousePos: {x: scope.mouse.x, y: scope.mouse.y} - }; - event.stopImmediatePropagation(); - } - - }else if(event.which === 3){ - onRightClick(event); - } - } - - function onMouseUp(event){ - - if(scope.dragstart){ - scope.dragstart.object.dispatchEvent({type: 'drop', event: event}); - scope.dragstart = null; - } - - } - - function getHoveredElement(){ - - var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 ); - vector.unproject(scope.camera); - - var raycaster = new THREE.Raycaster(); - raycaster.ray.set( scope.camera.position, vector.sub( scope.camera.position ).normalize() ); - - var spheres = []; - for(var i = 0; i < scope.measurements.length; i++){ - var m = scope.measurements[i]; - - for(var j = 0; j < m.spheres.length; j++){ - spheres.push(m.spheres[j]); - } - } - - var intersections = raycaster.intersectObjects(spheres, true); - if(intersections.length > 0){ - return intersections[0]; - }else{ - return false; - } - } - - function getMousePointCloudIntersection(){ - var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 ); - vector.unproject(scope.camera); - - var direction = vector.sub(scope.camera.position).normalize(); - var ray = new THREE.Ray(scope.camera.position, direction); - - var pointClouds = []; - scope.scene.traverse(function(object){ - if(object instanceof Potree.PointCloudOctree){ - pointClouds.push(object); - } - }); - - var closestPoint = null; - var closestPointDistance = null; - - for(var i = 0; i < pointClouds.length; i++){ - var pointcloud = pointClouds[i]; - var point = pointcloud.pick(scope.renderer, scope.camera, ray); - - if(!point){ - continue; - } - - var distance = scope.camera.position.distanceTo(point.position); - - if(!closestPoint || distance < closestPointDistance){ - closestPoint = point; - closestPointDistance = distance; - } - } - - return closestPoint ? closestPoint.position : null; - } - - this.setEnabled = function(enable){ - if(this.enabled === enable){ - return; - } - - this.enabled = enable; - - if(enable){ - - state = STATE.PICKING; - scope.activeMeasurement = new Measure(scope.sceneRoot); - - scope.activeMeasurement.add(new THREE.Vector3(0,0,0)); - } - }; - - this.update = function(){ - var measurements = []; - var i, j, wp, w; - - for(i = 0; i < this.measurements.length; i++){ - measurements.push(this.measurements[i]); - } - if(this.activeMeasurement){ - measurements.push(this.activeMeasurement); - } - - for(i = 0; i < measurements.length; i++){ - var measurement = measurements[i]; - for(j = 0; j < measurement.spheres.length; j++){ - var sphere = measurement.spheres[j]; - wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - w = Math.abs((wp.z / 60)); - sphere.scale.set(w, w, w); - } - - for(j = 0; j < measurement.angleLabels.length; j++){ - var label = measurement.angleLabels[j]; - wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - w = Math.abs(wp.z / 5); - var l = label.scale.length(); - label.scale.multiplyScalar(w / l); - } - - } - - this.light.position.copy(this.camera.position); - this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position)); - }; - - this.render = function(){ - this.update(); - renderer.render(this.sceneMeasurement, this.camera); - }; - - this.domElement.addEventListener( 'click', onClick, false); - this.domElement.addEventListener( 'mousemove', onMouseMove, false ); - this.domElement.addEventListener( 'mousedown', onMouseDown, false ); - this.domElement.addEventListener( 'mouseup', onMouseUp, true ); -}; - -Potree.AngleTool.prototype = Object.create( THREE.EventDispatcher.prototype ); - -// -// calculating area of a polygon: -// http://www.mathopenref.com/coordpolygonarea2.html -// -// -// - -Potree.AreaTool = function(scene, camera, renderer){ - - var scope = this; - this.enabled = false; - - this.scene = scene; - this.camera = camera; - this.renderer = renderer; - this.domElement = renderer.domElement; - this.mouse = {x: 0, y: 0}; - - var STATE = { - DEFAULT: 0, - PICKING: 1 - }; - - var state = STATE.DEFAULT; + this.areaLabel = new Potree.TextSprite(""); + this.areaLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); + this.areaLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); + this.areaLabel.setTextColor({r:180, g:220, b:180, a:1.0}); + this.areaLabel.material.depthTest = false; + this.areaLabel.material.opacity = 1; + this.add(this.areaLabel); var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); + this.color = new THREE.Color( 0xff0000 ); - this.activeMeasurement; - this.measurements = []; - this.sceneMeasurement = new THREE.Scene(); - this.sceneRoot = new THREE.Object3D(); - this.sceneMeasurement.add(this.sceneRoot); - - this.light = new THREE.DirectionalLight( 0xffffff, 1 ); - this.light.position.set( 0, 0, 10 ); - this.light.lookAt(new THREE.Vector3(0,0,0)); - this.sceneMeasurement.add( this.light ); - - this.hoveredElement = null; - - var moveEvent = function(event){ - event.target.material.emissive.setHex(0x888888); - }; - - var leaveEvent = function(event){ - event.target.material.emissive.setHex(0x000000); - }; - - var dragEvent = function(event){ - var I = getMousePointCloudIntersection(); - - if(I){ - for(var i = 0; i < scope.measurements.length; i++){ - var m = scope.measurements[i]; - var index = m.spheres.indexOf(scope.dragstart.object); - - if(index >= 0){ - scope.measurements[i].setPosition(index, I); - - - break; - } - } - - //scope.dragstart.object.position.copy(I); - } - - event.event.stopImmediatePropagation(); - }; - - var dropEvent = function(event){ - - }; - - - function Measure(root){ - this.points = []; - this.spheres = []; - this.edges = []; - this.sphereLabels = []; - this.edgeLabels = []; - this.root = root; - this.closed = true; - - this.areaLabel = new Potree.TextSprite(); - this.areaLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); - this.areaLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); - this.areaLabel.setTextColor({r:180, g:220, b:180, a:1.0}); - this.areaLabel.material.depthTest = false; - this.areaLabel.material.opacity = 1; - root.add(this.areaLabel); - - var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); - var lineColor = new THREE.Color( 0xff0000 ); - - var createSphereMaterial = function(){ - var sphereMaterial = new THREE.MeshLambertMaterial({ - shading: THREE.SmoothShading, - color: 0xff0000, - ambient: 0xaaaaaa, - depthTest: false, - depthWrite: false} - ); - - return sphereMaterial; - }; - - this.add = function(point){ - - this.points.push(point); - - // sphere - var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - sphere.addEventListener("mousemove", moveEvent); - sphere.addEventListener("mouseleave", leaveEvent); - sphere.addEventListener("mousedrag", dragEvent); - sphere.addEventListener("drop", dropEvent); - - // edge - var lineGeometry = new THREE.Geometry(); - lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3()); - lineGeometry.colors.push(lineColor, lineColor, lineColor); - var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, linewidth: 2 } ); - lineMaterial.depthTest = false; - var edge = new THREE.Line(lineGeometry, lineMaterial); - - - // edgeLabel - var edgeLabel = new Potree.TextSprite("abc"); - edgeLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); - edgeLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); - edgeLabel.material.depthTest = false; - edgeLabel.material.opacity = 1; - - - this.root.add(sphere); - this.root.add(edge); - this.root.add(edgeLabel); - - this.spheres.push(sphere); - this.edges.push(edge); - this.edgeLabels.push(edgeLabel); - - this.setPosition(this.points.length-1, point); - }; - - this.remove = function(index){ - this.points.splice(index, 1); - - this.root.remove(this.spheres[index]); - this.root.remove(this.edges[index]); - this.root.remove(this.edgeLabels[index]); - - this.spheres.splice(index, 1); - this.edges.splice(index, 1); - this.edgeLabels.splice(index, 1); - - this.update(); - }; - - /** - * see http://www.mathopenref.com/coordpolygonarea2.html - */ - this.getArea = function(){ - var area = 0; - var j = this.points.length - 1; - - for(var i = 0; i < this.points.length; i++){ - var p1 = this.points[i]; - var p2 = this.points[j]; - area += (p2.x + p1.x) * (p1.z - p2.z); - j = i; - } - - return Math.abs(area / 2); - }; - - this.setPosition = function(index, position){ - var point = this.points[index]; - point.copy(position); - - this.update(); - }; - - this.setClosed = function(closed){ - this.closed = closed; - - this.update(); - }; - - this.update = function(){ - this.areaLabel.visible = this.points.length >= 3; - - if(this.points.length === 1){ - var point = this.points[0]; - this.spheres[0].position.copy(point); - this.edges[0].visible = false; - this.edgeLabels[0].visible = false; - - return; - } - - - var centroid = new THREE.Vector3(); - var lastIndex = this.points.length - 1; - for(var i = 0; i <= lastIndex; i++){ - var point = this.points[i]; - var sphere = this.spheres[i]; - var leftIndex = (i === 0) ? lastIndex : i - 1; - var rightIndex = (i === lastIndex) ? 0 : i + 1; - var leftVertex = this.points[leftIndex]; - var rightVertex = this.points[rightIndex]; - var leftEdge = this.edges[leftIndex]; - var rightEdge = this.edges[i]; - var leftEdgeLabel = this.edgeLabels[leftIndex]; - var rightEdgeLabel = this.edgeLabels[i]; - - var leftEdgeLength = point.distanceTo(leftVertex); - var rightEdgeLength = point.distanceTo(rightVertex); - var leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5); - var rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5); - - leftEdgeLabel.position.copy(leftEdgeCenter); - rightEdgeLabel.position.copy(rightEdgeCenter); - leftEdgeLabel.setText(leftEdgeLength.toFixed(2)); - rightEdgeLabel.setText(rightEdgeLength.toFixed(2)); - - sphere.position.copy(point); - leftEdge.geometry.vertices[1].copy(point); - leftEdge.geometry.verticesNeedUpdate = true; - leftEdge.geometry.computeBoundingSphere(); - rightEdge.geometry.vertices[0].copy(point); - rightEdge.geometry.verticesNeedUpdate = true; - rightEdge.geometry.computeBoundingSphere(); - - if(i === lastIndex && !this.closed){ - rightEdge.visible = false; - rightEdgeLabel.visible = false; - }else{ - rightEdge.visible = true; - rightEdgeLabel.visible = true; - } - - centroid.add(point); - } - centroid.multiplyScalar(1 / this.points.length); - - - var msg = Potree.utils.addCommas(this.getArea().toFixed(1)) + "²"; - this.areaLabel.setText(msg); - this.areaLabel.position.copy(centroid); - }; - - - } - - function createSphereMaterial(){ + var createSphereMaterial = function(){ var sphereMaterial = new THREE.MeshLambertMaterial({ shading: THREE.SmoothShading, - color: 0xff0000, + color: scope.color, ambient: 0xaaaaaa, depthTest: false, depthWrite: false} @@ -4939,254 +5949,286 @@ Potree.AreaTool = function(scene, camera, renderer){ return sphereMaterial; }; - - function onClick(event){ + var moveEvent = function(event){ + event.target.material.emissive.setHex(0x888888); + }; - if(!scope.enabled){ - return; - } + var leaveEvent = function(event){ + event.target.material.emissive.setHex(0x000000); + }; - var I = getMousePointCloudIntersection(); + var dragEvent = function(event){ + var tool = event.tool; + var dragstart = tool.dragstart; + var mouse = tool.mouse; + + var I = tool.getMousePointCloudIntersection(); + if(I){ - var pos = I.clone(); + var index = scope.spheres.indexOf(tool.dragstart.object); + scope.setPosition(index, I); + } + + //event.event.stopImmediatePropagation(); + }; + + var dropEvent = function(event){ + + }; + + this.addMarker = function(point){ + this.points.push(point); + + // sphere + var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); + sphere.addEventListener("move", moveEvent); + sphere.addEventListener("leave", leaveEvent); + sphere.addEventListener("drag", dragEvent); + sphere.addEventListener("drop", dropEvent); + + this.add(sphere); + this.spheres.push(sphere); + + { // edges + var lineGeometry = new THREE.Geometry(); + lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3()); + lineGeometry.colors.push(this.color, this.color, this.color); + var lineMaterial = new THREE.LineBasicMaterial( { + linewidth: 1 + }); + lineMaterial.depthTest = false; + var edge = new THREE.Line(lineGeometry, lineMaterial); + edge.visible = true; + + this.add(edge); + this.edges.push(edge); + } + + { // edge labels + var edgeLabel = new Potree.TextSprite(0); + edgeLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); + edgeLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); + edgeLabel.material.depthTest = false; + edgeLabel.visible = false; + this.edgeLabels.push(edgeLabel); + this.add(edgeLabel); + } + + { // angle labels + var angleLabel = new Potree.TextSprite(); + angleLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); + angleLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); + angleLabel.material.depthTest = false; + angleLabel.material.opacity = 1; + angleLabel.visible = false; + this.angleLabels.push(angleLabel); + this.add(angleLabel); + } - if(state === STATE.DEFAULT){ - state = STATE.PICKING; - scope.activeMeasurement = new Measure(); - } - - scope.activeMeasurement.add(pos); - - var event = { - type: 'newpoint', - position: pos.clone() - }; - scope.dispatchEvent(event); - - } + + + var event = { + type: "marker_added", + measurement: this + }; + this.dispatchEvent(event); + + this.setPosition(this.points.length-1, point); }; - function onMouseMove(event){ - var rect = scope.domElement.getBoundingClientRect(); - scope.mouse.x = ((event.clientX - rect.left) / scope.domElement.clientWidth) * 2 - 1; - scope.mouse.y = -((event.clientY - rect.top) / scope.domElement.clientHeight) * 2 + 1; + this.removeMarker = function(index){ + this.points.splice(index, 1); - if(scope.dragstart){ - - scope.dragstart.object.dispatchEvent({type: "mousedrag", event: event}); - - }else if(state == STATE.PICKING && scope.activeMeasurement){ - var I = getMousePointCloudIntersection(); - - if(I){ - - var lastIndex = scope.activeMeasurement.points.length-1; - scope.activeMeasurement.setPosition(lastIndex, I); - } - - }else{ - var I = getHoveredElement(); - - if(I){ - - I.object.dispatchEvent({type: "mousemove", target: I.object, event: event}); - - if(scope.hoveredElement && scope.hoveredElement !== I.object){ - scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event}); - } - - scope.hoveredElement = I.object; - - }else{ - - if(scope.hoveredElement){ - scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event}); - } - - scope.hoveredElement = null; - - } - } + this.remove(this.spheres[index]); + + var edgeIndex = (index == 0) ? 0 : (index - 1); + this.remove(this.edges[edgeIndex]); + this.edges.splice(edgeIndex, 1); + + this.remove(this.edgeLabels[edgeIndex]); + this.edgeLabels.splice(edgeIndex, 1); + + this.spheres.splice(index, 1); + + this.update(); }; - function onRightClick(event){ - if(state == STATE.PICKING){ - scope.activeMeasurement.remove(scope.activeMeasurement.points.length-1); + this.setPosition = function(index, position){ + var point = this.points[index]; + point.copy(position); - scope.measurements.push(scope.activeMeasurement); - scope.activeMeasurement = undefined; + var event = { + type: 'marker_moved', + measure: this, + index: index, + position: position.clone() + }; + this.dispatchEvent(event); - state = STATE.DEFAULT; - scope.setEnabled(false); - } - } - - function onMouseDown(event){ - if(event.which === 1){ - - if(state !== STATE.DEFAULT){ - event.stopImmediatePropagation(); - } - - var I = getHoveredElement(); - - if(I){ - - scope.dragstart = { - object: I.object, - sceneClickPos: I.point, - sceneStartPos: scope.sceneRoot.position.clone(), - mousePos: {x: scope.mouse.x, y: scope.mouse.y} - }; - event.stopImmediatePropagation(); - } - - }else if(event.which === 3){ - onRightClick(event); - } - } - - function onMouseUp(event){ - - if(scope.dragstart){ - scope.dragstart.object.dispatchEvent({type: "drop", event: event}); - scope.dragstart = null; - } - - } - - function getHoveredElement(){ - - var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 ); - vector.unproject(scope.camera); - - var raycaster = new THREE.Raycaster(); - raycaster.ray.set( scope.camera.position, vector.sub( scope.camera.position ).normalize() ); - - var spheres = []; - for(var i = 0; i < scope.measurements.length; i++){ - var m = scope.measurements[i]; - - for(var j = 0; j < m.spheres.length; j++){ - spheres.push(m.spheres[j]); - } - } - - var intersections = raycaster.intersectObjects(spheres, true); - if(intersections.length > 0){ - return intersections[0]; - }else{ - return false; - } + this.update(); }; - function getMousePointCloudIntersection(){ - var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 ); - vector.unproject(scope.camera); - - var direction = vector.sub(scope.camera.position).normalize(); - var ray = new THREE.Ray(scope.camera.position, direction); + this.getArea = function(){ + var area = 0; + var j = this.points.length - 1; - var pointClouds = []; - scope.scene.traverse(function(object){ - if(object instanceof Potree.PointCloudOctree){ - pointClouds.push(object); - } - }); - - var closestPoint = null; - var closestPointDistance = null; - - for(var i = 0; i < pointClouds.length; i++){ - var pointcloud = pointClouds[i]; - var point = pointcloud.pick(scope.renderer, scope.camera, ray); - - if(!point){ - continue; - } - - var distance = scope.camera.position.distanceTo(point.position); - - if(!closestPoint || distance < closestPointDistance){ - closestPoint = point; - closestPointDistance = distance; - } + for(var i = 0; i < this.points.length; i++){ + var p1 = this.points[i]; + var p2 = this.points[j]; + area += (p2.x + p1.x) * (p1.z - p2.z); + j = i; } - return closestPoint ? closestPoint.position : null; - } - - this.setEnabled = function(enable){ - if(this.enabled === enable){ - return; - } - - this.enabled = enable; - - if(enable){ - - state = STATE.PICKING; - scope.activeMeasurement = new Measure(scope.sceneRoot); - - scope.activeMeasurement.add(new THREE.Vector3(0,0,0)); - } + return Math.abs(area / 2); }; + this.getAngleBetweenLines = function(cornerPoint, point1, point2) { + var v1 = new THREE.Vector3().subVectors(point1, cornerPoint); + var v2 = new THREE.Vector3().subVectors(point2, cornerPoint); + return v1.angleTo(v2); + }; + this.update = function(){ - var measurements = []; - for(var i = 0; i < this.measurements.length; i++){ - measurements.push(this.measurements[i]); - } - if(this.activeMeasurement){ - measurements.push(this.activeMeasurement); + + if(this.points.length === 0){ + return; + }else if(this.points.length === 1){ + var point = this.points[0]; + this.spheres[0].position.copy(point); + + return; } + var lastIndex = this.points.length - 1; - for(var i = 0; i < measurements.length; i++){ - var measurement = measurements[i]; - for(var j = 0; j < measurement.spheres.length; j++){ - var sphere = measurement.spheres[j]; - var wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix); - var w = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w); - sphere.scale.set(w, w, w); + var centroid = new THREE.Vector3(); + for(var i = 0; i <= lastIndex; i++){ + var point = this.points[i]; + centroid.add(point); + } + centroid.divideScalar(this.points.length); + + for(var i = 0; i <= lastIndex; i++){ + var index = i; + var nextIndex = ( i + 1 > lastIndex ) ? 0 : i + 1; + var previousIndex = (i === 0) ? lastIndex : i - 1; + + var point = this.points[index]; + var nextPoint = this.points[nextIndex]; + var previousPoint = this.points[previousIndex]; + + var sphere = this.spheres[index]; + + // spheres + sphere.position.copy(point); + sphere.material.color = scope.color; + + {// edges + var edge = this.edges[index]; + + edge.material.color = this.color; + + edge.geometry.vertices[0].copy(point); + edge.geometry.vertices[1].copy(nextPoint); + + edge.geometry.verticesNeedUpdate = true; + edge.geometry.computeBoundingSphere(); + edge.visible = index < lastIndex || this.closed; } - for(var j = 0; j < measurement.edgeLabels.length; j++){ - var label = measurement.edgeLabels[j]; - var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var w = Math.abs(wp.z / 5); - var l = label.scale.length(); - label.scale.multiplyScalar(w / l); + {// edge labels + var edgeLabel = this.edgeLabels[i]; + + var center = new THREE.Vector3().add(point); + center.add(nextPoint); + center = center.multiplyScalar(0.5); + var distance = point.distanceTo(nextPoint); + + edgeLabel.position.copy(center); + edgeLabel.setText(distance.toFixed(2)); + edgeLabel.visible = this.showDistances && (index < lastIndex || this.closed) && this.points.length >= 2 && distance > 0; } - var wp = measurement.areaLabel.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var w = Math.abs(wp.z / 4); - var l = measurement.areaLabel.scale.length(); - measurement.areaLabel.scale.multiplyScalar(w / l); + {// angle labels + var angleLabel = this.angleLabels[i]; + var angle = this.getAngleBetweenLines(point, previousPoint, nextPoint); + + var dir = nextPoint.clone().sub(previousPoint); + dir.multiplyScalar(0.5); + dir = previousPoint.clone().add(dir).sub(point).normalize(); + + var dist = Math.min(point.distanceTo(previousPoint), point.distanceTo(nextPoint)); + dist = dist / 9; + + var labelPos = point.clone().add(dir.multiplyScalar(dist)); + angleLabel.position.copy(labelPos); + + var msg = Potree.utils.addCommas((angle*(180.0/Math.PI)).toFixed(1)) + '\u00B0'; + angleLabel.setText(msg); + + angleLabel.visible = this.showAngles && (index < lastIndex || this.closed) && this.points.length >= 3 && angle > 0; + } } - - this.light.position.copy(this.camera.position); - this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position)); + // update area label + this.areaLabel.position.copy(centroid); + this.areaLabel.visible = this.showArea && this.points.length >= 3; + var msg = Potree.utils.addCommas(this.getArea().toFixed(1)) + "²"; + this.areaLabel.setText(msg); }; - this.render = function(){ - this.update(); - renderer.render(this.sceneMeasurement, this.camera); - }; - - this.domElement.addEventListener( 'click', onClick, false); - this.domElement.addEventListener( 'mousemove', onMouseMove, false ); - this.domElement.addEventListener( 'mousedown', onMouseDown, false ); - this.domElement.addEventListener( 'mouseup', onMouseUp, true ); - + this.raycast = function(raycaster, intersects){ + + for(var i = 0; i < this.points.length; i++){ + var sphere = this.spheres[i]; + + sphere.raycast(raycaster, intersects); + } + + // recalculate distances because they are not necessarely correct + // for scaled objects. + // see https://github.com/mrdoob/three.js/issues/5827 + // TODO: remove this once the bug has been fixed + for(var i = 0; i < intersects.length; i++){ + var I = intersects[i]; + I.distance = raycaster.ray.origin.distanceTo(I.point); + } + intersects.sort( function ( a, b ) { return a.distance - b.distance;} ); + } }; +Potree.Measure.prototype = Object.create( THREE.Object3D.prototype ); -Potree.AreaTool.prototype = Object.create( THREE.EventDispatcher.prototype ); +Object.defineProperty(Potree.Measure.prototype, "showArea", { + get: function(){ + return this._showArea; + }, + set: function(value){ + this._showArea = value; + this.update(); + } +}); +Object.defineProperty(Potree.Measure.prototype, "closed", { + get: function(){ + return this._closed; + }, + set: function(value){ + this._closed = value; + this.update(); + } +}); + +Object.defineProperty(Potree.Measure.prototype, "showDistances", { + get: function(){ + return this._showDistances; + }, + set: function(value){ + this._showDistances = value; + this.update(); + } +}); Potree.MeasuringTool = function(scene, camera, renderer){ @@ -5201,13 +6243,11 @@ Potree.MeasuringTool = function(scene, camera, renderer){ var STATE = { DEFAULT: 0, - PICKING: 1 + INSERT: 1 }; var state = STATE.DEFAULT; - var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); - this.activeMeasurement; this.measurements = []; this.sceneMeasurement = new THREE.Scene(); @@ -5221,269 +6261,49 @@ Potree.MeasuringTool = function(scene, camera, renderer){ this.hoveredElement = null; - var moveEvent = function(event){ - event.target.material.emissive.setHex(0x888888); - }; - - var leaveEvent = function(event){ - event.target.material.emissive.setHex(0x000000); - }; - - var dragEvent = function(event){ - var I = getMousePointCloudIntersection(); - - if(I){ - for(var i = 0; i < scope.measurements.length; i++){ - var m = scope.measurements[i]; - var index = m.spheres.indexOf(scope.dragstart.object); - - if(index >= 0){ - var sphere = m.spheres[index]; - - if(index === 0){ - var edge = m.edges[index]; - var edgeLabel = m.edgeLabels[index]; - - sphere.position.copy(I); - edge.geometry.vertices[0].copy(I); - edge.geometry.verticesNeedUpdate = true; - edge.geometry.computeBoundingSphere(); - - var edgeLabelPos = edge.geometry.vertices[0].clone().add(edge.geometry.vertices[1]).multiplyScalar(0.5); - var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2); - - edgeLabel.position.copy(edgeLabelPos); - edgeLabel.setText(edgeLabelText); - edgeLabel.scale.multiplyScalar(10); - }else if(index === m.spheres.length - 1){ - var edge = m.edges[index - 1]; - var edgeLabel = m.edgeLabels[index - 1]; - - sphere.position.copy(I); - edge.geometry.vertices[1].copy(I); - edge.geometry.verticesNeedUpdate = true; - edge.geometry.computeBoundingSphere(); - - var edgeLabelPos = edge.geometry.vertices[0].clone().add(edge.geometry.vertices[1]).multiplyScalar(0.5); - var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2); - - edgeLabel.position.copy(edgeLabelPos); - edgeLabel.setText(edgeLabelText); - edgeLabel.scale.multiplyScalar(10); - }else{ - var edge1 = m.edges[index-1]; - var edge2 = m.edges[index]; - - var edge1Label = m.edgeLabels[index-1]; - var edge2Label = m.edgeLabels[index]; - - sphere.position.copy(I); - - edge1.geometry.vertices[1].copy(I); - edge1.geometry.verticesNeedUpdate = true; - edge1.geometry.computeBoundingSphere(); - - edge2.geometry.vertices[0].copy(I); - edge2.geometry.verticesNeedUpdate = true; - edge2.geometry.computeBoundingSphere(); - - var edge1LabelPos = edge1.geometry.vertices[0].clone().add(edge1.geometry.vertices[1]).multiplyScalar(0.5); - var edge1LabelText = edge1.geometry.vertices[0].distanceTo(edge1.geometry.vertices[1]).toFixed(2); - - edge1Label.position.copy(edge1LabelPos); - edge1Label.setText(edge1LabelText); - edge1Label.scale.multiplyScalar(10); - - var edge2LabelPos = edge2.geometry.vertices[0].clone().add(edge2.geometry.vertices[1]).multiplyScalar(0.5); - var edge2LabelText = edge2.geometry.vertices[0].distanceTo(edge2.geometry.vertices[1]).toFixed(2); - - edge2Label.position.copy(edge2LabelPos); - edge2Label.setText(edge2LabelText); - edge2Label.scale.multiplyScalar(10); - - } - - - break; - } - } - - //scope.dragstart.object.position.copy(I); - } - - event.event.stopImmediatePropagation(); - }; - - var dropEvent = function(event){ - - }; - - - function Measure(){ - this.points = []; - this.spheres = []; - this.edges = []; - this.sphereLabels = []; - this.edgeLabels = []; - } - - function createSphereMaterial(){ - var sphereMaterial = new THREE.MeshLambertMaterial({ - shading: THREE.SmoothShading, - color: 0xff0000, - ambient: 0xaaaaaa, - depthTest: false, - depthWrite: false} - ); - - return sphereMaterial; - }; - - function onClick(event){ - - if(!scope.enabled){ - return; - } - - var I = getMousePointCloudIntersection(); - if(I){ - var pos = I.clone(); - - var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - sphere.position.copy(I); - scope.sceneRoot.add(sphere); - sphere.addEventListener("mousemove", moveEvent); - sphere.addEventListener("mouseleave", leaveEvent); - sphere.addEventListener("mousedrag", dragEvent); - sphere.addEventListener("drop", dropEvent); - - var sphereEnd = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - sphereEnd.position.copy(I); - scope.sceneRoot.add(sphereEnd); - sphereEnd.addEventListener("mousemove", moveEvent); - sphereEnd.addEventListener("mouseleave", leaveEvent); - sphereEnd.addEventListener("mousedrag", dragEvent); - sphereEnd.addEventListener("drop", dropEvent); - - var msg = pos.x.toFixed(2) + " / " + pos.y.toFixed(2) + " / " + pos.z.toFixed(2); - - var label = new Potree.TextSprite(msg); - label.setBorderColor({r:0, g:255, b:0, a:1.0}); - label.material.depthTest = false; - label.material.opacity = 0; - label.position.copy(I); - label.position.y += 0.5; - - - var labelEnd = new Potree.TextSprite(msg); - labelEnd.setBorderColor({r:0, g:255, b:0, a:1.0}); - labelEnd.material.depthTest = false; - labelEnd.material.opacity = 0; - labelEnd.position.copy(I); - labelEnd.position.y += 0.5; - - - var lc = new THREE.Color( 0xff0000 ); - var lineGeometry = new THREE.Geometry(); - lineGeometry.vertices.push(I.clone(), I.clone()); - lineGeometry.colors.push(lc, lc, lc); - var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, linewidth: 10 } ); - lineMaterial.depthTest = false; - sConnection = new THREE.Line(lineGeometry, lineMaterial); - - var edgeLabel = new Potree.TextSprite(0); - edgeLabel.setBorderColor({r:0, g:255, b:0, a:0.0}); - edgeLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0}); - edgeLabel.material.depthTest = false; - edgeLabel.position.copy(I); - edgeLabel.position.y += 0.5; - - - scope.sceneRoot.add(sConnection); - scope.sceneRoot.add( label ); - scope.sceneRoot.add( labelEnd ); - scope.sceneRoot.add( edgeLabel ); - - - //floatingOrigin.addReferenceFrame(sphere); - //floatingOrigin.addReferenceFrame(sphereEnd); - //floatingOrigin.addReferenceFrame(label); - //floatingOrigin.addReferenceFrame(labelEnd); - //floatingOrigin.addReferenceFrame(sConnection); - //floatingOrigin.addReferenceFrame(edgeLabel); - - if(state === STATE.DEFAULT){ - state = STATE.PICKING; - scope.activeMeasurement = new Measure(); + if(state === STATE.INSERT){ + var I = scope.getMousePointCloudIntersection(); + if(I){ + var pos = I.clone(); + + scope.activeMeasurement.addMarker(pos); + + var event = { + type: 'newpoint', + position: pos.clone() + }; + scope.dispatchEvent(event); + + if(scope.activeMeasurement.points.length > scope.activeMeasurement.maxMarkers){ + scope.finishInsertion(); + } - scope.activeMeasurement.spheres.push(sphere); - }else if(state === STATE.PICKING){ - scope.sceneRoot.remove(sphere); } - - scope.activeMeasurement.points.push(I); - - scope.activeMeasurement.spheres.push(sphereEnd); - scope.activeMeasurement.sphereLabels.push(label); - scope.activeMeasurement.sphereLabels.push(labelEnd); - scope.activeMeasurement.edges.push(sConnection); - scope.activeMeasurement.edgeLabels.push(edgeLabel); - - - var event = { - type: 'newpoint', - position: pos.clone() - }; - scope.dispatchEvent(event); - - } - //event.stopImmediatePropagation(); }; - function onMouseMove(event){ + function onMouseMove(event){ + var rect = scope.domElement.getBoundingClientRect(); scope.mouse.x = ((event.clientX - rect.left) / scope.domElement.clientWidth) * 2 - 1; scope.mouse.y = -((event.clientY - rect.top) / scope.domElement.clientHeight) * 2 + 1; if(scope.dragstart){ + var arg = { + type: "drag", + event: event, + tool: scope + }; + scope.dragstart.object.dispatchEvent(arg); - scope.dragstart.object.dispatchEvent({type: "mousedrag", event: event}); - - }else if(state == STATE.PICKING && scope.activeMeasurement){ - var I = getMousePointCloudIntersection(); + }else if(state == STATE.INSERT && scope.activeMeasurement){ + var I = scope.getMousePointCloudIntersection(); if(I){ - if(scope.activeMeasurement.spheres.length === 1){ - var pos = I.clone(); - var sphere = scope.activeMeasurement.spheres[0]; - sphere.position.copy(I); - }else{ - var pos = I.clone(); - var l = scope.activeMeasurement.spheres.length; - var sphere = scope.activeMeasurement.spheres[l-1]; - var label = scope.activeMeasurement.sphereLabels[l-1]; - var edge = scope.activeMeasurement.edges[l-2]; - var edgeLabel = scope.activeMeasurement.edgeLabels[l-2]; - - var msg = pos.x.toFixed(2) + " / " + pos.y.toFixed(2) + " / " + pos.z.toFixed(2); - label.setText(msg); - - sphere.position.copy(I); - label.position.copy(I); - label.position.y += 0.5; - - edge.geometry.vertices[1].copy(I); - edge.geometry.verticesNeedUpdate = true; - edge.geometry.computeBoundingSphere(); - - var edgeLabelPos = edge.geometry.vertices[1].clone().add(edge.geometry.vertices[0]).multiplyScalar(0.5); - var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2); - edgeLabel.position.copy(edgeLabelPos); - edgeLabel.setText(edgeLabelText); - edgeLabel.scale.multiplyScalar(10); - } + + var lastIndex = scope.activeMeasurement.points.length-1; + scope.activeMeasurement.setPosition(lastIndex, I); } }else{ @@ -5491,10 +6311,10 @@ Potree.MeasuringTool = function(scene, camera, renderer){ if(I){ - I.object.dispatchEvent({type: "mousemove", target: I.object, event: event}); + I.object.dispatchEvent({type: "move", target: I.object, event: event}); if(scope.hoveredElement && scope.hoveredElement !== I.object){ - scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event}); + scope.hoveredElement.dispatchEvent({type: "leave", target: scope.hoveredElement, event: event}); } scope.hoveredElement = I.object; @@ -5502,7 +6322,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ }else{ if(scope.hoveredElement){ - scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event}); + scope.hoveredElement.dispatchEvent({type: "leave", target: scope.hoveredElement, event: event}); } scope.hoveredElement = null; @@ -5512,26 +6332,19 @@ Potree.MeasuringTool = function(scene, camera, renderer){ }; function onRightClick(event){ - if(state == STATE.PICKING){ - var sphere = scope.activeMeasurement.spheres.pop(); - var edge = scope.activeMeasurement.edges.pop(); - var sphereLabel = scope.activeMeasurement.sphereLabels.pop(); - var edgeLabel = scope.activeMeasurement.edgeLabels.pop(); - - scope.sceneRoot.remove(sphere); - scope.sceneRoot.remove(edge); - scope.sceneRoot.remove(sphereLabel); - scope.sceneRoot.remove(edgeLabel); - - scope.measurements.push(scope.activeMeasurement); - scope.activeMeasurement = undefined; - - state = STATE.DEFAULT; - scope.setEnabled(false); + if(state == STATE.INSERT){ + scope.finishInsertion(); } } + this.getState = function(){ + // TODO remove + + return state; + } + function onMouseDown(event){ + if(event.which === 1){ if(state !== STATE.DEFAULT){ @@ -5558,8 +6371,25 @@ Potree.MeasuringTool = function(scene, camera, renderer){ } } - function onMouseUp(event){ + function onDoubleClick(event){ + // fix move event after double click + // see: http://stackoverflow.com/questions/8125165/event-listener-for-dblclick-causes-event-for-mousemove-to-not-work-and-show-a-ci + if (window.getSelection){ + window.getSelection().removeAllRanges(); + }else if (document.selection){ + document.selection.empty(); + } + + + if(scope.activeMeasurement && state === STATE.INSERT){ + scope.activeMeasurement.removeMarker(scope.activeMeasurement.points.length-1); + scope.finishInsertion(); + } + } + + function onMouseUp(event){ + if(scope.dragstart){ scope.dragstart.object.dispatchEvent({type: "drop", event: event}); scope.dragstart = null; @@ -5592,7 +6422,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ } }; - function getMousePointCloudIntersection(){ + this.getMousePointCloudIntersection = function(){ var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 ); vector.unproject(scope.camera); @@ -5601,7 +6431,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ var pointClouds = []; scope.scene.traverse(function(object){ - if(object instanceof Potree.PointCloudOctree){ + if(object instanceof Potree.PointCloudOctree || object instanceof Potree.PointCloudArena4D){ pointClouds.push(object); } }); @@ -5628,30 +6458,70 @@ Potree.MeasuringTool = function(scene, camera, renderer){ return closestPoint ? closestPoint.position : null; } - this.setEnabled = function(enable){ - if(this.enabled === enable){ - return; + this.startInsertion = function(args){ + state = STATE.INSERT; + + var args = args || {}; + var showDistances = (typeof args.showDistances != "undefined") ? args.showDistances : true; + var showArea = (typeof args.showArea != "undefined") ? args.showArea : false; + var showAngles = (typeof args.showAngles != "undefined") ? args.showAngles : false; + var closed = (typeof args.closed != "undefined") ? args.closed : false; + var maxMarkers = args.maxMarkers || Number.MAX_SAFE_INTEGER; + + var measurement = new Potree.Measure(); + measurement.showDistances = showDistances; + measurement.showArea = showArea; + measurement.showAngles = showAngles; + measurement.closed = closed; + measurement.maxMarkers = maxMarkers; + + this.addMeasurement(measurement); + measurement.addMarker(new THREE.Vector3(0,0,0)); + + this.activeMeasurement = measurement; + }; + + this.finishInsertion = function(){ + this.activeMeasurement.removeMarker(this.activeMeasurement.points.length-1); + + var event = { + type: "insertion_finished", + measurement: this.activeMeasurement + }; + this.dispatchEvent(event); + + this.activeMeasurement = null; + state = STATE.DEFAULT; + }; + + this.addMeasurement = function(measurement){ + this.sceneMeasurement.add(measurement); + this.measurements.push(measurement); + + this.dispatchEvent({"type": "measurement_added", measurement: measurement}); + measurement.addEventListener("marker_added", function(event){ + scope.dispatchEvent(event); + }); + measurement.addEventListener("marker_removed", function(event){ + scope.dispatchEvent(event); + }); + measurement.addEventListener("marker_moved", function(event){ + scope.dispatchEvent(event); + }); + }; + + this.removeMeasurement = function(measurement){ + this.sceneMeasurement.remove(measurement); + var index = this.measurements.indexOf(measurement); + if(index >= 0){ + this.measurements.splice(index, 1); } - - this.enabled = enable; - - if(enable){ - - state = STATE.PICKING; - scope.activeMeasurement = new Measure(); - - var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - scope.sceneRoot.add(sphere); - scope.activeMeasurement.spheres.push(sphere); - - sphere.addEventListener("mousemove", moveEvent); - sphere.addEventListener("mouseleave", leaveEvent); - sphere.addEventListener("mousedrag", dragEvent); - sphere.addEventListener("drop", dropEvent); - }else{ - //this.domElement.removeEventListener( 'click', onClick, false); - //this.domElement.removeEventListener( 'mousemove', onMouseMove, false ); - //this.domElement.removeEventListener( 'mousedown', onMouseDown, false ); + }; + + this.reset = function(){ + for(var i = this.measurements.length - 1; i >= 0; i--){ + var measurement = this.measurements[i]; + this.removeMeasurement(measurement); } }; @@ -5664,24 +6534,46 @@ Potree.MeasuringTool = function(scene, camera, renderer){ measurements.push(this.activeMeasurement); } - + // make sizes independant of distance and fov for(var i = 0; i < measurements.length; i++){ var measurement = measurements[i]; + + // spheres for(var j = 0; j < measurement.spheres.length; j++){ var sphere = measurement.spheres[j]; - var wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix); - var w = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w); - sphere.scale.set(w, w, w); + + var distance = scope.camera.position.distanceTo(sphere.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (15 / pr); + sphere.scale.set(scale, scale, scale); + } + // edgeLabels for(var j = 0; j < measurement.edgeLabels.length; j++){ var label = measurement.edgeLabels[j]; - var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var w = Math.abs(wp.z / 5); - var l = label.scale.length(); - label.scale.multiplyScalar(w / l); + + var distance = scope.camera.position.distanceTo(label.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (70 / pr); + label.scale.set(scale, scale, scale); } + + // angle labels + for(var j = 0; j < measurement.edgeLabels.length; j++){ + var label = measurement.angleLabels[j]; + + var distance = scope.camera.position.distanceTo(label.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (70 / pr); + label.scale.set(scale, scale, scale); + } + + // areaLabel + var distance = scope.camera.position.distanceTo(measurement.areaLabel.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (80 / pr); + measurement.areaLabel.scale.set(scale, scale, scale); } this.light.position.copy(this.camera.position); @@ -5695,6 +6587,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){ }; this.domElement.addEventListener( 'click', onClick, false); + this.domElement.addEventListener( 'dblclick', onDoubleClick, false); this.domElement.addEventListener( 'mousemove', onMouseMove, false ); this.domElement.addEventListener( 'mousedown', onMouseDown, false ); this.domElement.addEventListener( 'mouseup', onMouseUp, true ); @@ -5704,6 +6597,316 @@ Potree.MeasuringTool = function(scene, camera, renderer){ Potree.MeasuringTool.prototype = Object.create( THREE.EventDispatcher.prototype ); + +Potree.HeightProfile = function(){ + var scope = this; + + THREE.Object3D.call( this ); + + this.points = []; + this.spheres = []; + this.edges = []; + this.boxes = []; + this.width = 1; + this.height = 20; + this._modifiable = true; + + var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); + var lineColor = new THREE.Color( 0xff0000 ); + + var createSphereMaterial = function(){ + var sphereMaterial = new THREE.MeshLambertMaterial({ + shading: THREE.SmoothShading, + color: 0xff0000, + ambient: 0xaaaaaa, + depthTest: false, + depthWrite: false} + ); + + return sphereMaterial; + }; + + var moveEvent = function(event){ + event.target.material.emissive.setHex(0x888888); + }; + + var leaveEvent = function(event){ + event.target.material.emissive.setHex(0x000000); + }; + + var dragEvent = function(event){ + + var tool = event.tool; + var dragstart = tool.dragstart; + var mouse = tool.mouse; + + if(event.event.ctrlKey){ + + var mouseStart = new THREE.Vector3(dragstart.mousePos.x, dragstart.mousePos.y, 0); + var mouseEnd = new THREE.Vector3(mouse.x, mouse.y, 0); + var widthStart = dragstart.widthStart; + + var scale = 1 - 10 * (mouseStart.y - mouseEnd.y); + scale = Math.max(0.01, scale); + if(widthStart){ + scope.setWidth(widthStart * scale); + } + + }else{ + + var I = tool.getMousePointCloudIntersection(); + + if(I){ + var index = scope.spheres.indexOf(tool.dragstart.object); + scope.setPosition(index, I); + } + } + + event.event.stopImmediatePropagation(); + }; + + var dropEvent = function(event){ + + }; + + this.addMarker = function(point){ + + this.points.push(point); + + // sphere + var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); + sphere.addEventListener("mousemove", moveEvent); + sphere.addEventListener("mouseleave", leaveEvent); + sphere.addEventListener("mousedrag", dragEvent); + sphere.addEventListener("drop", dropEvent); + + this.add(sphere); + this.spheres.push(sphere); + + // edges & boxes + if(this.points.length > 1){ + + var lineGeometry = new THREE.Geometry(); + lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3()); + lineGeometry.colors.push(lineColor, lineColor, lineColor); + var lineMaterial = new THREE.LineBasicMaterial( { + vertexColors: THREE.VertexColors, + linewidth: 2, + transparent: true, + opacity: 0.4 + }); + lineMaterial.depthTest = false; + var edge = new THREE.Line(lineGeometry, lineMaterial); + edge.visible = false; + + this.add(edge); + this.edges.push(edge); + + + var boxGeometry = new THREE.BoxGeometry(1, 1, 1); + var boxMaterial = new THREE.MeshBasicMaterial({color: 0xff0000, transparent: true, opacity: 0.2}); + var box = new THREE.Mesh(boxGeometry, boxMaterial); + box.visible = false; + + this.add(box); + this.boxes.push(box); + + } + + + var event = { + "type": "marker_added", + "profile": this + }; + this.dispatchEvent(event); + + this.setPosition(this.points.length-1, point); + }; + + this.removeMarker = function(index){ + this.points.splice(index, 1); + + this.remove(this.spheres[index]); + + var edgeIndex = (index == 0) ? 0 : (index - 1); + this.remove(this.edges[edgeIndex]); + this.edges.splice(edgeIndex, 1); + this.remove(this.boxes[edgeIndex]); + this.boxes.splice(edgeIndex, 1); + + this.spheres.splice(index, 1); + + this.update(); + + var event = { + "type": "marker_removed", + "profile": this + }; + this.dispatchEvent(event); + }; + + /** + * see http://www.mathopenref.com/coordpolygonarea2.html + */ + this.getArea = function(){ + var area = 0; + var j = this.points.length - 1; + + for(var i = 0; i < this.points.length; i++){ + var p1 = this.points[i]; + var p2 = this.points[j]; + area += (p2.x + p1.x) * (p1.z - p2.z); + j = i; + } + + return Math.abs(area / 2); + }; + + this.setPosition = function(index, position){ + var point = this.points[index]; + point.copy(position); + + var event = { + type: 'marker_moved', + profile: this, + index: index, + position: position.clone() + }; + this.dispatchEvent(event); + + this.update(); + }; + + this.setWidth = function(width){ + this.width = width; + + this.update(); + }; + + this.update = function(){ + + if(this.points.length === 0){ + return; + }else if(this.points.length === 1){ + var point = this.points[0]; + this.spheres[0].position.copy(point); + + return; + } + + var min = this.points[0].clone(); + var max = this.points[0].clone(); + var centroid = new THREE.Vector3(); + var lastIndex = this.points.length - 1; + for(var i = 0; i <= lastIndex; i++){ + var point = this.points[i]; + var sphere = this.spheres[i]; + var leftIndex = (i === 0) ? lastIndex : i - 1; + var rightIndex = (i === lastIndex) ? 0 : i + 1; + var leftVertex = this.points[leftIndex]; + var rightVertex = this.points[rightIndex]; + var leftEdge = this.edges[leftIndex]; + var rightEdge = this.edges[i]; + var leftBox = this.boxes[leftIndex]; + var rightBox = this.boxes[i]; + + var leftEdgeLength = point.distanceTo(leftVertex); + var rightEdgeLength = point.distanceTo(rightVertex); + var leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5); + var rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5); + + sphere.position.copy(point); + + if(this._modifiable){ + sphere.visible = true; + }else{ + sphere.visible = false; + } + + if(leftEdge){ + leftEdge.geometry.vertices[1].copy(point); + leftEdge.geometry.verticesNeedUpdate = true; + leftEdge.geometry.computeBoundingSphere(); + } + + if(rightEdge){ + rightEdge.geometry.vertices[0].copy(point); + rightEdge.geometry.verticesNeedUpdate = true; + rightEdge.geometry.computeBoundingSphere(); + } + + if(leftBox){ + var start = leftVertex; + var end = point; + var length = start.clone().setY(0).distanceTo(end.clone().setY(0)); + leftBox.scale.set(length, this.height, this.width); + + var center = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5); + var diff = new THREE.Vector3().subVectors(end, start); + var target = new THREE.Vector3(diff.z, 0, -diff.x); + + leftBox.position.set(0,0,0); + leftBox.lookAt(target); + leftBox.position.copy(center); + } + + + + + centroid.add(point); + min.min(point); + max.max(point); + } + centroid.multiplyScalar(1 / this.points.length); + + for(var i = 0; i < this.boxes.length; i++){ + var box = this.boxes[i]; + + box.position.y = min.y + (max.y - min.y) / 2; + //box.scale.y = max.y - min.y + 50; + box.scale.y = 1000000; + } + + }; + + this.raycast = function(raycaster, intersects){ + + for(var i = 0; i < this.points.length; i++){ + var sphere = this.spheres[i]; + + sphere.raycast(raycaster, intersects); + } + + // recalculate distances because they are not necessarely correct + // for scaled objects. + // see https://github.com/mrdoob/three.js/issues/5827 + // TODO: remove this once the bug has been fixed + for(var i = 0; i < intersects.length; i++){ + var I = intersects[i]; + I.distance = raycaster.ray.origin.distanceTo(I.point); + } + intersects.sort( function ( a, b ) { return a.distance - b.distance;} ); + } + + +} + +Potree.HeightProfile.prototype = Object.create( THREE.Object3D.prototype ); + +Object.defineProperty(Potree.HeightProfile.prototype, "modifiable", { + get: function(){ + return this.modifiable; + }, + set: function(value){ + this._modifiable = value; + this.update(); + } +}); + + + + + // // calculating area of a polygon: // http://www.mathopenref.com/coordpolygonarea2.html @@ -5744,292 +6947,6 @@ Potree.ProfileTool = function(scene, camera, renderer){ this.hoveredElement = null; - var moveEvent = function(event){ - event.target.material.emissive.setHex(0x888888); - }; - - var leaveEvent = function(event){ - event.target.material.emissive.setHex(0x000000); - }; - - var dragEvent = function(event){ - - if(event.event.ctrlKey){ - - var mouseStart = new THREE.Vector3(scope.dragstart.mousePos.x, scope.dragstart.mousePos.y, 0); - var mouseEnd = new THREE.Vector3(scope.mouse.x, scope.mouse.y, 0); - var widthStart = scope.dragstart.widthStart; - - var scale = 1 - 10 * (mouseStart.y - mouseEnd.y); - scale = Math.max(0.01, scale); - if(widthStart){ - for(var i = 0; i < scope.profiles.length; i++){ - var m = scope.profiles[i]; - var index = m.spheres.indexOf(scope.dragstart.object); - - if(index >= 0){ - m.setWidth(widthStart * scale); - m.update(); - - - break; - } - } - } - - }else{ - - var I = getMousePointCloudIntersection(); - - if(I){ - for(var i = 0; i < scope.profiles.length; i++){ - var m = scope.profiles[i]; - var index = m.spheres.indexOf(scope.dragstart.object); - - if(index >= 0){ - scope.profiles[i].setPosition(index, I); - - - break; - } - } - - //scope.dragstart.object.position.copy(I); - } - } - - event.event.stopImmediatePropagation(); - }; - - var dropEvent = function(event){ - - }; - - - function Profile(){ - THREE.Object3D.call( this ); - - this.points = []; - this.spheres = []; - this.edges = []; - this.boxes = []; - this.width = 1; - this.height = 20; - - var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10); - var lineColor = new THREE.Color( 0xff0000 ); - - var createSphereMaterial = function(){ - var sphereMaterial = new THREE.MeshLambertMaterial({ - shading: THREE.SmoothShading, - color: 0xff0000, - ambient: 0xaaaaaa, - depthTest: false, - depthWrite: false} - ); - - return sphereMaterial; - }; - - this.addMarker = function(point){ - - this.points.push(point); - - // sphere - var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial()); - sphere.addEventListener("mousemove", moveEvent); - sphere.addEventListener("mouseleave", leaveEvent); - sphere.addEventListener("mousedrag", dragEvent); - sphere.addEventListener("drop", dropEvent); - - this.add(sphere); - this.spheres.push(sphere); - - // edges & boxes - if(this.points.length > 1){ - - var lineGeometry = new THREE.Geometry(); - lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3()); - lineGeometry.colors.push(lineColor, lineColor, lineColor); - var lineMaterial = new THREE.LineBasicMaterial( { - vertexColors: THREE.VertexColors, - linewidth: 2, - transparent: true, - opacity: 0.4 - }); - lineMaterial.depthTest = false; - var edge = new THREE.Line(lineGeometry, lineMaterial); - edge.visible = false; - - this.add(edge); - this.edges.push(edge); - - - var boxGeometry = new THREE.BoxGeometry(1, 1, 1); - var boxMaterial = new THREE.MeshBasicMaterial({color: 0xff0000, transparent: true, opacity: 0.2}); - var box = new THREE.Mesh(boxGeometry, boxMaterial); - box.visible = false; - - this.add(box); - this.boxes.push(box); - - } - - this.setPosition(this.points.length-1, point); - }; - - this.removeMarker = function(index){ - this.points.splice(index, 1); - - this.remove(this.spheres[index]); - - if(index > 0){ - this.remove(this.edges[index-1]); - this.edges.splice(index-1, 1); - - this.remove(this.boxes[index-1]); - this.boxes.splice(index-1, 1); - } - - this.spheres.splice(index, 1); - - this.update(); - }; - - /** - * see http://www.mathopenref.com/coordpolygonarea2.html - */ - this.getArea = function(){ - var area = 0; - var j = this.points.length - 1; - - for(var i = 0; i < this.points.length; i++){ - var p1 = this.points[i]; - var p2 = this.points[j]; - area += (p2.x + p1.x) * (p1.z - p2.z); - j = i; - } - - return Math.abs(area / 2); - }; - - this.setPosition = function(index, position){ - var point = this.points[index]; - point.copy(position); - - this.update(); - }; - - this.setWidth = function(width){ - this.width = width; - - this.update(); - }; - - this.update = function(){ - - if(this.points.length === 0){ - return; - }else if(this.points.length === 1){ - var point = this.points[0]; - this.spheres[0].position.copy(point); - - return; - } - - var min = this.points[0].clone(); - var max = this.points[0].clone(); - var centroid = new THREE.Vector3(); - var lastIndex = this.points.length - 1; - for(var i = 0; i <= lastIndex; i++){ - var point = this.points[i]; - var sphere = this.spheres[i]; - var leftIndex = (i === 0) ? lastIndex : i - 1; - var rightIndex = (i === lastIndex) ? 0 : i + 1; - var leftVertex = this.points[leftIndex]; - var rightVertex = this.points[rightIndex]; - var leftEdge = this.edges[leftIndex]; - var rightEdge = this.edges[i]; - var leftBox = this.boxes[leftIndex]; - var rightBox = this.boxes[i]; - - var leftEdgeLength = point.distanceTo(leftVertex); - var rightEdgeLength = point.distanceTo(rightVertex); - var leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5); - var rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5); - - sphere.position.copy(point); - - if(leftEdge){ - leftEdge.geometry.vertices[1].copy(point); - leftEdge.geometry.verticesNeedUpdate = true; - leftEdge.geometry.computeBoundingSphere(); - } - - if(rightEdge){ - rightEdge.geometry.vertices[0].copy(point); - rightEdge.geometry.verticesNeedUpdate = true; - rightEdge.geometry.computeBoundingSphere(); - } - - if(leftBox){ - var start = leftVertex; - var end = point; - var length = start.clone().setY(0).distanceTo(end.clone().setY(0)); - leftBox.scale.set(length, this.height, this.width); - - var center = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5); - var diff = new THREE.Vector3().subVectors(end, start); - var target = new THREE.Vector3(diff.z, 0, -diff.x); - - leftBox.position.set(0,0,0); - leftBox.lookAt(target); - leftBox.position.copy(center); - } - - - - - centroid.add(point); - min.min(point); - max.max(point); - } - centroid.multiplyScalar(1 / this.points.length); - - for(var i = 0; i < this.boxes.length; i++){ - var box = this.boxes[i]; - - box.position.y = min.y + (max.y - min.y) / 2; - //box.scale.y = max.y - min.y + 50; - box.scale.y = 1000000; - } - - }; - - this.raycast = function(raycaster, intersects){ - - for(var i = 0; i < this.points.length; i++){ - var sphere = this.spheres[i]; - - sphere.raycast(raycaster, intersects); - } - - // recalculate distances because they are not necessarely correct - // for scaled objects. - // see https://github.com/mrdoob/three.js/issues/5827 - // TODO: remove this once the bug has been fixed - for(var i = 0; i < intersects.length; i++){ - var I = intersects[i]; - I.distance = raycaster.ray.origin.distanceTo(I.point); - } - intersects.sort( function ( a, b ) { return a.distance - b.distance;} ); - } - - - } - - Profile.prototype = Object.create( THREE.Object3D.prototype ); - function createSphereMaterial(){ var sphereMaterial = new THREE.MeshLambertMaterial({ shading: THREE.SmoothShading, @@ -6046,7 +6963,7 @@ Potree.ProfileTool = function(scene, camera, renderer){ function onClick(event){ if(state === STATE.INSERT){ - var I = getMousePointCloudIntersection(); + var I = scope.getMousePointCloudIntersection(); if(I){ var pos = I.clone(); @@ -6068,11 +6985,15 @@ Potree.ProfileTool = function(scene, camera, renderer){ scope.mouse.y = -((event.clientY - rect.top) / scope.domElement.clientHeight) * 2 + 1; if(scope.dragstart){ - - scope.dragstart.object.dispatchEvent({type: "mousedrag", event: event}); + var arg = { + type: "mousedrag", + event: event, + tool: scope + }; + scope.dragstart.object.dispatchEvent(arg); }else if(state == STATE.INSERT && scope.activeProfile){ - var I = getMousePointCloudIntersection(); + var I = scope.getMousePointCloudIntersection(); if(I){ @@ -6151,6 +7072,22 @@ Potree.ProfileTool = function(scene, camera, renderer){ } } + function onDoubleClick(event){ + + // fix move event after double click + // see: http://stackoverflow.com/questions/8125165/event-listener-for-dblclick-causes-event-for-mousemove-to-not-work-and-show-a-ci + if (window.getSelection){ + window.getSelection().removeAllRanges(); + }else if (document.selection){ + document.selection.empty(); + } + + if(scope.activeProfile && state === STATE.INSERT){ + scope.activeProfile.removeMarker(scope.activeProfile.points.length-1); + scope.finishInsertion(); + } + } + function onMouseUp(event){ if(scope.dragstart){ @@ -6177,7 +7114,7 @@ Potree.ProfileTool = function(scene, camera, renderer){ } }; - function getMousePointCloudIntersection(){ + this.getMousePointCloudIntersection = function(){ var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 ); vector.unproject(scope.camera); @@ -6186,7 +7123,7 @@ Potree.ProfileTool = function(scene, camera, renderer){ var pointClouds = []; scope.scene.traverse(function(object){ - if(object instanceof Potree.PointCloudOctree){ + if(object instanceof Potree.PointCloudOctree || object instanceof Potree.PointCloudArena4D){ pointClouds.push(object); } }); @@ -6220,30 +7157,73 @@ Potree.ProfileTool = function(scene, camera, renderer){ var clip = args.clip || false; var width = args.width || 1.0; - this.activeProfile = new Profile(); + this.activeProfile = new Potree.HeightProfile(); this.activeProfile.clip = clip; this.activeProfile.setWidth(width); - this.sceneProfile.add(this.activeProfile); - this.profiles.push(this.activeProfile); + this.addProfile(this.activeProfile); this.activeProfile.addMarker(new THREE.Vector3(0,0,0)); + + return this.activeProfile; }; this.finishInsertion = function(){ this.activeProfile.removeMarker(this.activeProfile.points.length-1); + + var event = { + type: "insertion_finished", + profile: this.activeProfile + }; + this.dispatchEvent(event); + this.activeProfile = null; state = STATE.DEFAULT; }; + this.addProfile = function(profile){ + this.profiles.push(profile); + this.sceneProfile.add(profile); + profile.update(); + + this.dispatchEvent({"type": "profile_added", profile: profile}); + profile.addEventListener("marker_added", function(event){ + scope.dispatchEvent(event); + }); + profile.addEventListener("marker_removed", function(event){ + scope.dispatchEvent(event); + }); + profile.addEventListener("marker_moved", function(event){ + scope.dispatchEvent(event); + }); + }; + + this.removeProfile = function(profile){ + this.sceneProfile.remove(profile); + var index = this.profiles.indexOf(profile); + if(index >= 0){ + this.profiles.splice(index, 1); + } + + this.dispatchEvent({"type": "profile_removed", profile: profile}); + } + + this.reset = function(){ + for(var i = this.profiles.length - 1; i >= 0; i--){ + var profile = this.profiles[i]; + this.removeProfile(profile); + } + } + this.update = function(){ for(var i = 0; i < this.profiles.length; i++){ var profile = this.profiles[i]; for(var j = 0; j < profile.spheres.length; j++){ var sphere = profile.spheres[j]; - var wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix); - var w = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w); - sphere.scale.set(w, w, w); + + var distance = scope.camera.position.distanceTo(sphere.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (15 / pr); + sphere.scale.set(scale, scale, scale); } } @@ -6258,6 +7238,7 @@ Potree.ProfileTool = function(scene, camera, renderer){ }; this.domElement.addEventListener( 'click', onClick, false); + this.domElement.addEventListener( 'dblclick', onDoubleClick, false); this.domElement.addEventListener( 'mousemove', onMouseMove, false ); this.domElement.addEventListener( 'mousedown', onMouseDown, false ); this.domElement.addEventListener( 'mouseup', onMouseUp, true ); @@ -7000,27 +7981,13 @@ Potree.TransformationTool = function(scene, camera, renderer){ this.domElement.addEventListener( 'mouseup', onMouseUp, true ); }; -Potree.VolumeTool = function(scene, camera, renderer){ - - var scope = this; - this.enabled = false; - - this.scene = scene; - this.sceneVolume = new THREE.Scene(); - this.camera = camera; - this.renderer = renderer; - this.domElement = renderer.domElement; - this.mouse = {x: 0, y: 0}; - - this.volumes = []; - - var STATE = { - DEFAULT: 0, - INSERT_VOLUME: 1 - - }; - - var state = STATE.DEFAULT; +Potree.Volume = function(args){ + + THREE.Object3D.call( this ); + + args = args || {}; + this._clip = args.clip || false; + this._modifiable = args.modifiable || true; var boxGeometry = new THREE.BoxGeometry(1, 1, 1); boxGeometry.computeBoundingBox(); @@ -7053,96 +8020,129 @@ Potree.VolumeTool = function(scene, camera, renderer){ boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, -0.5)); boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, -0.5)); boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, -0.5)); - - function Volume(){ - - THREE.Object3D.call( this ); - - this._clip = false; - - this.dimension = new THREE.Vector3(1,1,1); - var material = new THREE.MeshBasicMaterial( {color: 0x00ff00, transparent: true, opacity: 0.3} ); - this.box = new THREE.Mesh( boxGeometry, material); - this.box.geometry.computeBoundingBox(); - this.boundingBox = this.box.geometry.boundingBox; - this.add(this.box); - - this.frame = new THREE.Line( boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000})); - this.frame.mode = THREE.LinePieces; - this.add(this.frame); - - this.label = new Potree.TextSprite("0"); - this.label.setBorderColor({r:0, g:255, b:0, a:0.0}); - this.label.setBackgroundColor({r:0, g:255, b:0, a:0.0}); - this.label.material.depthTest = false; - this.label.position.y -= 0.5; - this.add(this.label); - - var v = this; - this.label.updateMatrixWorld = function(){ - var volumeWorldPos = new THREE.Vector3(); - volumeWorldPos.setFromMatrixPosition( v.matrixWorld ); - v.label.position.copy(volumeWorldPos); - v.label.updateMatrix(); - v.label.matrixWorld.copy(v.label.matrix); - v.label.matrixWorldNeedsUpdate = false; - - for ( var i = 0, l = v.label.children.length; i < l; i ++ ) { - v.label.children[ i ].updateMatrixWorld( true ); - } - }; - - this.setDimension = function(x,y,z){ - this.dimension.set(x,y,z); - this.box.scale.set(x,y,z); - this.frame.scale.set(x,y,z); - }; - this.volume = function(){ - return Math.abs(this.scale.x * this.scale.y * this.scale.z); - //return Math.abs(this.dimension.x * this.dimension.y * this.dimension.z); - }; - - this.update = function(){ - this.boundingBox = this.box.geometry.boundingBox; - }; - - this.raycast = function(raycaster, intersects){ - - var is = []; - this.box.raycast(raycaster, is); - - if(is.length > 0){ - var I = is[0]; - intersects.push({ - distance: I.distance, - object: this, - point: I.point.clone() - }); - } - }; + this.dimension = new THREE.Vector3(1,1,1); + var material = new THREE.MeshBasicMaterial( {color: 0x00ff00, transparent: true, opacity: 0.3} ); + this.box = new THREE.Mesh( boxGeometry, material); + this.box.geometry.computeBoundingBox(); + this.boundingBox = this.box.geometry.boundingBox; + this.add(this.box); + + this.frame = new THREE.Line( boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000})); + this.frame.mode = THREE.LinePieces; + this.add(this.frame); + + this.label = new Potree.TextSprite("0"); + this.label.setBorderColor({r:0, g:255, b:0, a:0.0}); + this.label.setBackgroundColor({r:0, g:255, b:0, a:0.0}); + this.label.material.depthTest = false; + this.label.position.y -= 0.5; + this.add(this.label); + + var v = this; + this.label.updateMatrixWorld = function(){ + var volumeWorldPos = new THREE.Vector3(); + volumeWorldPos.setFromMatrixPosition( v.matrixWorld ); + v.label.position.copy(volumeWorldPos); + v.label.updateMatrix(); + v.label.matrixWorld.copy(v.label.matrix); + v.label.matrixWorldNeedsUpdate = false; + for ( var i = 0, l = v.label.children.length; i < l; i ++ ) { + v.label.children[ i ].updateMatrixWorld( true ); + } + }; + + this.setDimension = function(x,y,z){ + this.dimension.set(x,y,z); + this.box.scale.set(x,y,z); + this.frame.scale.set(x,y,z); }; - Volume.prototype = Object.create( THREE.Object3D.prototype ); + this.volume = function(){ + return Math.abs(this.scale.x * this.scale.y * this.scale.z); + //return Math.abs(this.dimension.x * this.dimension.y * this.dimension.z); + }; - Object.defineProperty(Volume.prototype, "clip", { - get: function(){ - return this._clip; - }, + this.update = function(){ + this.boundingBox = this.box.geometry.boundingBox; - set: function(value){ - this._clip = value; - - if(this._clip){ - this.box.visible = false; - this.label.visible = false; - }else{ - this.box.visible = true; - this.label.visible = true; - } + if(this._clip){ + this.box.visible = false; + this.label.visible = false; + }else{ + this.box.visible = true; + this.label.visible = true; } - }); + }; + + this.raycast = function(raycaster, intersects){ + + var is = []; + this.box.raycast(raycaster, is); + + if(is.length > 0){ + var I = is[0]; + intersects.push({ + distance: I.distance, + object: this, + point: I.point.clone() + }); + } + }; + + this.update(); + +}; + +Potree.Volume.prototype = Object.create( THREE.Object3D.prototype ); + +Object.defineProperty(Potree.Volume.prototype, "clip", { + get: function(){ + return this._clip; + }, + + set: function(value){ + this._clip = value; + + this.update(); + } +}); + +Object.defineProperty(Potree.Volume.prototype, "modifiable", { + get: function(){ + return this._modifiable; + }, + + set: function(value){ + this._modifiable = value; + + this.update(); + } +}); + + +Potree.VolumeTool = function(scene, camera, renderer){ + + var scope = this; + this.enabled = false; + + this.scene = scene; + this.sceneVolume = new THREE.Scene(); + this.camera = camera; + this.renderer = renderer; + this.domElement = renderer.domElement; + this.mouse = {x: 0, y: 0}; + + this.volumes = []; + + var STATE = { + DEFAULT: 0, + INSERT_VOLUME: 1 + + }; + + var state = STATE.DEFAULT; function onMouseMove(event){ @@ -7175,7 +8175,7 @@ Potree.VolumeTool = function(scene, camera, renderer){ }else if(event.which === 1){ var I = getHoveredElement(); - if(I){ + if(I && I.object.modifiable){ transformationTool.setTargets([I.object]); } } @@ -7241,7 +8241,7 @@ Potree.VolumeTool = function(scene, camera, renderer){ var pointClouds = []; scope.scene.traverse(function(object){ - if(object instanceof Potree.PointCloudOctree){ + if(object instanceof Potree.PointCloudOctree || object instanceof Potree.PointCloudArena4D){ pointClouds.push(object); } }); @@ -7299,13 +8299,12 @@ Potree.VolumeTool = function(scene, camera, renderer){ var capacity = volume.volume(); var msg = Potree.utils.addCommas(capacity.toFixed(1)) + "³"; - - var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse); - var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(this.camera.projectionMatrix); - var w = Math.abs(wp.z / 5); label.setText(msg); - var l = label.scale.length(); - label.scale.multiplyScalar(w / l); + + var distance = scope.camera.position.distanceTo(label.getWorldPosition()); + var pr = projectedRadius(1, scope.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight); + var scale = (70 / pr); + label.scale.set(scale, scale, scale); } }; @@ -7316,20 +8315,46 @@ Potree.VolumeTool = function(scene, camera, renderer){ var args = args || {}; var clip = args.clip || false; - this.activeVolume = new Volume(); + this.activeVolume = new Potree.Volume(); this.activeVolume.clip = clip; this.sceneVolume.add(this.activeVolume); + this.volumes.push(this.activeVolume); } this.finishInsertion = function(){ - this.volumes.push(this.activeVolume); transformationTool.setTargets([this.activeVolume]); + var event = { + type: "insertion_finished", + volume: this.activeVolume + }; + this.dispatchEvent(event); + this.activeVolume = null; state = STATE.DEFAULT; - } + this.addVolume = function(volume){ + this.sceneVolume.add(volume); + this.volumes.push(volume); + }; + + this.removeVolume = function(volume){ + this.sceneVolume.remove(volume); + var index = this.volumes.indexOf(volume); + if(index >= 0){ + this.volumes.splice(index, 1); + } + }; + + this.reset = function(){ + for(var i = this.volumes.length - 1; i >= 0; i--){ + var volume = this.volumes[i]; + this.removeVolume(volume); + } + } + + this.render = function(){ renderer.render(this.sceneVolume, this.camera); @@ -7340,4 +8365,1080 @@ Potree.VolumeTool = function(scene, camera, renderer){ this.domElement.addEventListener( 'mousedown', onMouseDown, false ); this.domElement.addEventListener( 'mousemove', onMouseMove, false ); this.domElement.addEventListener( 'contextmenu', onContextMenu, false ); -}; \ No newline at end of file +}; + +Potree.VolumeTool.prototype = Object.create( THREE.EventDispatcher.prototype ); + +Potree.PointCloudArena4DProxyNode = function(geometryNode){ + THREE.Object3D.call( this ); + + this.geometryNode = geometryNode; + this.pcoGeometry = geometryNode; + this.boundingBox = geometryNode.boundingBox; + this.boundingSphere = geometryNode.boundingSphere; + this.number = geometryNode.name; + this.numPoints = geometryNode.numPoints; + this.level = geometryNode.level; +} + +Potree.PointCloudArena4DProxyNode.prototype = Object.create(THREE.Object3D.prototype); + + + +Potree.PointCloudArena4D = function(geometry){ + THREE.Object3D.call( this ); + + this.root = null; + + this.visiblePointsTarget = 2*1000*1000; + this.minimumNodePixelSize = 150; + + this.position.sub(geometry.offset); + this.updateMatrix(); + + this.numVisibleNodes = 0; + this.numVisiblePoints = 0; + + this.boundingBoxNodes = []; + this.loadQueue = []; + this.visibleNodes = []; + + this.pcoGeometry = geometry; + this.boundingBox = this.pcoGeometry.boundingBox; + this.boundingSphere = this.pcoGeometry.boundingSphere; + this.material = new Potree.PointCloudMaterial({vertexColors: THREE.VertexColors, size: 0.05, treeType: Potree.TreeType.KDTREE}); + this.material.sizeType = Potree.PointSizeType.ATTENUATED; + this.material.size = 0.05; + + this.pickTarget; + this.pickMaterial; + + this.updateMatrixWorld(); +}; + +Potree.PointCloudArena4D.prototype = Object.create(THREE.Object3D.prototype); + +Potree.PointCloudArena4D.prototype.updateMaterial = function(camera, renderer){ + this.material.fov = camera.fov * (Math.PI / 180); + this.material.screenWidth = renderer.domElement.clientWidth; + this.material.screenHeight = renderer.domElement.clientHeight; + this.material.spacing = this.pcoGeometry.spacing; + this.material.near = camera.near; + this.material.far = camera.far; + + // reduce shader source updates by setting maxLevel slightly higher than actually necessary + if(this.maxLevel > this.material.levels){ + this.material.levels = this.maxLevel + 2; + } + + this.material.minSize = 3; + + var bbSize = this.boundingBox.size(); + this.material.bbSize = [bbSize.x, bbSize.y, bbSize.z]; +}; + +Potree.PointCloudArena4D.prototype.hideDescendants = function(object){ + var stack = []; + for(var i = 0; i < object.children.length; i++){ + var child = object.children[i]; + if(child.visible){ + stack.push(child); + } + } + + while(stack.length > 0){ + var object = stack.shift(); + + object.visible = false; + if(object.boundingBoxNode){ + object.boundingBoxNode.visible = false; + } + + for(var i = 0; i < object.children.length; i++){ + var child = object.children[i]; + if(child.visible){ + stack.push(child); + } + } + } +} + +Potree.PointCloudArena4D.prototype.updateMatrixWorld = function( force ){ + //node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix ); + + if ( this.matrixAutoUpdate === true ) this.updateMatrix(); + + if ( this.matrixWorldNeedsUpdate === true || force === true ) { + + if ( this.parent === undefined ) { + + this.matrixWorld.copy( this.matrix ); + + } else { + + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + + } + + this.matrixWorldNeedsUpdate = false; + + force = true; + + } +}; + +var dbgFullyInside = 0; + +Potree.PointCloudArena4D.prototype.update = function(camera, renderer){ + var geometry = this.pcoGeometry; + + if(!geometry.root){ + return; + }else if(!this.rootProxyGenerated){ + var rootProxy = new Potree.PointCloudArena4DProxyNode(this.pcoGeometry.root); + this.add(rootProxy); + this.rootProxyGenerated = true; + } + + this.updateMatrixWorld(true); + + this.loadQueue = []; + this.visibleNodes = []; + this.numVisibleNodes = 0; + this.numVisiblePoints = 0; + dbgFullyInside = 0; + + if(!this.showBoundingBox){ + for(var i = 0; i < this.boundingBoxNodes.length; i++){ + var bbNode = this.boundingBoxNodes[i]; + this.remove(bbNode); + bbNode.geometry.dispose(); + } + } + + this.updateMaterial(camera, renderer); + + this.hideDescendants(this.children[0]); + + // create frustum in object space + camera.updateMatrixWorld(); + var frustum = new THREE.Frustum(); + var viewI = camera.matrixWorldInverse; + var world = this.matrixWorld; + var proj = camera.projectionMatrix; + var fm = new THREE.Matrix4().multiply(proj).multiply(viewI).multiply(world); + frustum.setFromMatrix( fm ); + + // calculate camera position in object space + var view = camera.matrixWorld; + var worldI = new THREE.Matrix4().getInverse(world); + var camMatrixObject = new THREE.Matrix4().multiply(worldI).multiply(view); + var camObjPos = new THREE.Vector3().setFromMatrixPosition( camMatrixObject ); + + var stack = []; + stack.push({node: this.children[0], weight: 1}); + while(stack.length > 0){ + var element = stack.shift(); + var node = element.node; + var weight = element.weight; + + //if(node.level > 3){ + // continue; + //} + + node.matrixWorld.multiplyMatrices( this.matrixWorld, node.matrix ); + + var box = node.boundingBox.clone(); + //box.min.sub(this.boundingBox.min); + //box.max.sub(this.boundingBox.min); + var insideFrustum = frustum.intersectsBox(box); + + var visible = insideFrustum; + node.visible = visible; + + + + if(!visible){ + continue; + } + + var pointsInside = 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.min.x, box.min.y, box.min.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.min.x, box.min.y, box.max.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.min.x, box.max.y, box.min.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.min.x, box.max.y, box.max.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.max.x, box.min.y, box.min.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.max.x, box.min.y, box.max.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.max.x, box.max.y, box.min.z)) ? 1 : 0; + //pointsInside += frustum.containsPoint(new THREE.Vector3(box.max.x, box.max.y, box.max.z)) ? 1 : 0; + + if(pointsInside === 8){ + dbgFullyInside++; + } + + + if (node instanceof Potree.PointCloudArena4DProxyNode) { + var geometryNode = node.geometryNode; + if(geometryNode.loaded === true){ + this.replaceProxy(node); + }else{ + this.loadQueue.push(element); + } + }else if(node instanceof THREE.PointCloud){ + if(this.numVisiblePoints + node.pcoGeometry.numPoints > pointcloud.visiblePointsTarget){ + break; + } + this.numVisibleNodes++; + this.numVisiblePoints += node.pcoGeometry.numPoints; + this.visibleNodes.push({node: node, weight: weight}); + + if(this.showBoundingBox && !node.boundingBoxNode){ + var boxHelper = new THREE.BoxHelper(node); + this.add(boxHelper); + this.boundingBoxNodes.push(boxHelper); + node.boundingBoxNode = boxHelper; + node.boundingBoxNode.matrixWorld.copy(node.matrixWorld); + }else if(this.showBoundingBox && node.boundingBoxNode){ + node.boundingBoxNode.visible = true; + }else if(!this.showBoundingBox){ + delete node.boundingBoxNode; + } + + for(var i = 0; i < node.children.length; i++){ + var child = node.children[i]; + //var box = child.geometryNode.boundingBox; + var sphere = child.boundingSphere; + var distance = sphere.center.distanceTo(camObjPos); + + var radius = box.size().length() / 2; + var fov = camera.fov / 2 * Math.PI / 180.0; + var pr = 1 / Math.tan(fov) * radius / Math.sqrt(distance * distance - radius * radius); + + if(distance < radius){ + pr = Number.MAX_VALUE; + } + + var screenPixelRadius = renderer.domElement.clientHeight * pr; + if(screenPixelRadius < this.minimumNodePixelSize){ + continue; + } + + var weight = pr; + + if(stack.length === 0){ + stack.push({node: child, weight: weight}); + }else{ + var ipos = 0; + + for(var j = 0; j < stack.length; j++){ + if(weight > stack[j].weight){ + var ipos = j; + break; + }else if(j == stack.length -1){ + ipos = stack.length; + break; + } + + + } + + stack.splice(ipos, 0, {node: child, weight: weight}); + } + + //stack.push({node: child, weight: 1}); + } + } + } + + + + this.updateLoadQueue(); + + this.maxLevel = 0; + for(var i = 0; i < this.visibleNodes.length; i++){ + this.maxLevel = Math.max(this.visibleNodes[i].node.pcoGeometry.level, this.maxLevel); + } + + var vn = []; + for(var i = 0; i < this.visibleNodes.length; i++){ + vn.push(this.visibleNodes[i].node); + } + this.updateVisibilityTexture(this.material, vn); + + //{ // only show nodes on ray + // var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 ); + // vector.unproject(camera); + // + // var direction = vector.sub(camera.position).normalize(); + // var ray = new THREE.Ray(camera.position, direction); + // + // + // var nodesOnRay = pointcloud.nodesOnRay(pointcloud.visibleNodes, ray); + // + // for(var i = 0; i < this.visibleNodes.length; i++){ + // var node = this.visibleNodes[i].node; + // + // node.visible = false; + // if(node.boundingBoxNode){ + // node.boundingBoxNode.visible = false; + // } + // } + // + // for(var i = 0; i < nodesOnRay.length; i++){ + // var node = nodesOnRay[i]; + // + // node.visible = true; + // this.numVisiblePoints += node.pcoGeometry.numPoints; + // if(node.boundingBoxNode){ + // node.boundingBoxNode.visible = true; + // } + // } + // this.numVisibleNodes = nodesOnRay.length; + // + // var pickPos = this.pick(renderer, camera, ray, {}); + // if(pickPos){ + // var sg = new THREE.SphereGeometry(0.2); + // var sm = new THREE.Mesh(sg); + // sm.position.copy(pickPos.position); + // scene.add(sm); + // } + //} + +}; + +Potree.PointCloudArena4D.prototype.replaceProxy = function(proxy){ + + var geometryNode = proxy.geometryNode; + if(geometryNode.loaded === true){ + var geometry = geometryNode.geometry; + var node = new THREE.PointCloud(geometry, this.material); + node.number = proxy.number; + node.numPoints = proxy.numPoints; + node.boundingBox = geometryNode.boundingBox; + node.boundingSphere = geometryNode.boundingSphere; + node.pcoGeometry = geometryNode; + var parent = proxy.parent; + parent.remove(proxy); + parent.add(node); + //node.position.copy(node.boundingBox.min); + //node.position.sub(this.pcoGeometry.boundingBox.min); + //var current = parent; + //while(!(current instanceof Potree.PointCloudArena4D)){ + // node.position.sub(current.boundingBox.min); + // + // current = current.parent; + //} + + node.updateMatrix(); + + //console.log(geometryNode.number + ": " + node.position.x + ", " + node.position.y + ", " + node.position.z); + + node.matrixWorld.multiplyMatrices( this.matrixWorld, node.matrix ); + + if(geometryNode.left){ + var child = geometryNode.left; + var childProxy = new Potree.PointCloudArena4DProxyNode(child); + node.add(childProxy); + } + if(geometryNode.right){ + var child = geometryNode.right; + var childProxy = new Potree.PointCloudArena4DProxyNode(child); + node.add(childProxy); + } + + return node; + } +} + +Potree.PointCloudArena4D.prototype.updateLoadQueue = function(vn){ + if(this.loadQueue.length > 0){ + if(this.loadQueue.length >= 2){ + this.loadQueue.sort(function(a,b){return b.weight - a.weight}); + } + + for(var i = 0; i < Math.min(5, this.loadQueue.length); i++){ + this.loadQueue[i].node.geometryNode.load(); + } + } +} + +Potree.PointCloudArena4D.prototype.getVisibleGeometry = function(camera){ + var visibleGeometry = []; + + // create frustum in object space + camera.updateMatrixWorld(); + var frustum = new THREE.Frustum(); + var viewI = camera.matrixWorldInverse; + var world = this.matrixWorld; + var proj = camera.projectionMatrix; + var fm = new THREE.Matrix4().multiply(proj).multiply(viewI).multiply(world); + frustum.setFromMatrix( fm ); + + var stack = []; + var pointCount = 0; + + stack.push(this.pcoGeometry.root); + while(stack.length > 0){ + if(visibleGeometry.length > 12){ + break; + } + + var node = stack.shift(); + + var box = node.boundingBox.clone(); + box.max.sub(box.min); + box.min.sub(box.min); + var insideFrustum = frustum.intersectsBox(box); + + var visible = insideFrustum; + + if(!visible){ + continue; + } + + if(pointCount + node.numPoints > this.visiblePointsTarget){ + break; + } + + pointCount += node.numPoints; + + visibleGeometry.push(node); + + if(node.loaded){ + if(node.left){ + stack.push(node.left); + } + + if(node.right){ + stack.push(node.right); + } + } + } + + return visibleGeometry; + +}; + +Potree.PointCloudArena4D.prototype.nodesOnRay = function(nodes, ray){ + var nodesOnRay = []; + + var _ray = ray.clone(); + for(var i = 0; i < nodes.length; i++){ + var node = nodes[i].node; + //var inverseWorld = new THREE.Matrix4().getInverse(node.matrixWorld); + var sphere = node.boundingSphere.clone().applyMatrix4(node.matrixWorld); + var box = node.boundingBox.clone().applyMatrix4(node.matrixWorld); + + + if(_ray.isIntersectionBox(box)){ + //if(_ray.isIntersectionSphere(sphere)){ + nodesOnRay.push(node); + } + } + + return nodesOnRay; +}; + +Potree.PointCloudArena4D.prototype.pick = function(renderer, camera, ray, params){ + + var params = params || {}; + var pickWindowSize = params.pickWindowSize || 17; + + var nodes = this.nodesOnRay(this.visibleNodes, ray); + + if(nodes.length === 0){ + return null; + } + + var width = Math.ceil(renderer.domElement.clientWidth); + var height = Math.ceil(renderer.domElement.clientHeight); + + var pixelPos = new THREE.Vector3().addVectors(camera.position, ray.direction).project(camera); + pixelPos.addScalar(1).multiplyScalar(0.5); + pixelPos.x *= width; + pixelPos.y *= height + + if(!this.pickTarget){ + this.pickTarget = new THREE.WebGLRenderTarget( + 1, 1, + { minFilter: THREE.LinearFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat } + ); + }else if(this.pickTarget.width != width || this.pickTarget.height != height){ + this.pickTarget.dispose(); + this.pickTarget = new THREE.WebGLRenderTarget( + 1, 1, + { minFilter: THREE.LinearFilter, + magFilter: THREE.NearestFilter, + format: THREE.RGBAFormat } + ); + } + this.pickTarget.setSize(width, height); + + // setup pick material. + // use the same point size functions as the main material to get the same point sizes. + if(!this.pickMaterial){ + this.pickMaterial = new Potree.PointCloudMaterial({treeType: Potree.TreeType.KDTREE}); + 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; + + if(this.pickMaterial.pointSizeType === Potree.PointSizeType.ADAPTIVE){ + this.updateVisibilityTexture(this.pickMaterial, nodes); + } + + 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.levels = this.material.levels; + this.pickMaterial.pointShape = this.material.pointShape; + + + + var _gl = renderer.context; + + _gl.enable(_gl.SCISSOR_TEST); + _gl.scissor(pixelPos.x - (pickWindowSize - 1) / 2, pixelPos.y - (pickWindowSize - 1) / 2,pickWindowSize,pickWindowSize); + _gl.disable(_gl.SCISSOR_TEST); + + var material = this.pickMaterial; + + renderer.setRenderTarget( this.pickTarget ); + + renderer.setDepthTest( material.depthTest ); + renderer.setDepthWrite( material.depthWrite ) + renderer.setBlending( THREE.NoBlending ); + + renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); + + //TODO: UGLY HACK CHAMPIONSHIP SUBMISSION!! drawing first node does not work properly so we draw it twice. + if(nodes.length > 0){ + nodes.push(nodes[0]); + } + + for(var i = 0; i < nodes.length; i++){ + var object = nodes[i]; + var geometry = object.geometry; + + if(!geometry.attributes.indices.buffer){ + continue; + } + + material.pcIndex = i; + + if(material.program){ + var program = material.program.program; + _gl.useProgram( program ); + //_gl.disable( _gl.BLEND ); + + var attributePointer = _gl.getAttribLocation(program, "indices"); + var attributeSize = 4; + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.attributes.indices.buffer ); + //if(!bufferSubmitted){ + // _gl.bufferData( _gl.ARRAY_BUFFER, new Uint8Array(geometry.attributes.indices.array), _gl.STATIC_DRAW ); + // bufferSubmitted = true; + //} + _gl.enableVertexAttribArray( attributePointer ); + _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); + } + + + + var pickWindowSize = 17; + var pixelCount = pickWindowSize * pickWindowSize; + var buffer = new ArrayBuffer(pixelCount*4); + var pixels = new Uint8Array(buffer); + var ibuffer = new Uint32Array(buffer); + renderer.context.readPixels( + pixelPos.x - (pickWindowSize-1) / 2, pixelPos.y - (pickWindowSize-1) / 2, + pickWindowSize, pickWindowSize, + renderer.context.RGBA, renderer.context.UNSIGNED_BYTE, pixels); + + // find closest hit inside pixelWindow boundaries + var min = Number.MAX_VALUE; + var hit = null; + //console.log("finding closest hit"); + for(var u = 0; u < pickWindowSize; u++){ + for(var v = 0; v < pickWindowSize; v++){ + var offset = (u + v*pickWindowSize); + var distance = Math.pow(u - (pickWindowSize-1) / 2, 2) + Math.pow(v - (pickWindowSize-1) / 2, 2); + + var pcIndex = pixels[4*offset + 3]; + pixels[4*offset + 3] = 0; + var pIndex = ibuffer[offset]; + + if((pIndex !== 0 || pcIndex !== 0) && distance < min){ + + hit = { + pIndex: pIndex, + pcIndex: pcIndex + }; + min = distance; + } + } + } + + if(hit){ + var point = {}; + + var pc = nodes[hit.pcIndex]; + var attributes = pc.geometry.attributes; + + for (var property in attributes) { + if (attributes.hasOwnProperty(property)) { + var values = geometry.attributes[property]; + + if(property === "position"){ + var positionArray = pc.geometry.attributes.position.array; + var x = positionArray[3*hit.pIndex+0]; + var y = positionArray[3*hit.pIndex+1]; + var z = positionArray[3*hit.pIndex+2]; + var position = new THREE.Vector3(x, y, z); + position.applyMatrix4(this.matrixWorld); + + point[property] = position; + }else if(property === "indices"){ + + }else{ + if(values.itemSize === 1){ + point[property] = values.array[i + j]; + }else{ + var value = []; + for(var j = 0; j < values.itemSize; j++){ + value.push(values.array[i*values.itemSize + j]); + } + point[property] = value; + } + } + } + } + + + return point; + }else{ + return null; + } +}; + + +Potree.PointCloudArena4D.prototype.updateVisibilityTexture = function(material, visibleNodes){ + + if(!material){ + return; + } + + var texture = material.visibleNodesTexture; + var data = texture.image.data; + + // copy array + visibleNodes = visibleNodes.slice(); + + // sort by level and number + var sort = function(a, b){ + var la = a.pcoGeometry.level; + var lb = b.pcoGeometry.level; + var na = a.pcoGeometry.number; + var nb = b.pcoGeometry.number; + if(la != lb) return la - lb; + if(na < nb) return -1; + if(na > nb) return 1; + return 0; + }; + visibleNodes.sort(sort); + + var visibleNodeNames = []; + for(var i = 0; i < visibleNodes.length; i++){ + //visibleNodeNames[visibleNodes[i].pcoGeometry.number] = true; + visibleNodeNames.push(visibleNodes[i].pcoGeometry.number); + } + + for(var i = 0; i < visibleNodes.length; i++){ + var node = visibleNodes[i]; + + var b1 = 0; // children + var b2 = 0; // offset to first child + var b3 = 0; // split + + if(node.pcoGeometry.left && visibleNodeNames.indexOf(node.pcoGeometry.left.number) > 0){ + b1 += 1; + b2 = visibleNodeNames.indexOf(node.pcoGeometry.left.number) - i; + } + if(node.pcoGeometry.right && visibleNodeNames.indexOf(node.pcoGeometry.right.number) > 0){ + b1 += 2; + b2 = (b2 === 0) ? visibleNodeNames.indexOf(node.pcoGeometry.right.number) - i : b2; + } + + if(node.pcoGeometry.split === "X"){ + b3 = 1; + }else if(node.pcoGeometry.split === "Y"){ + b3 = 2; + }else if(node.pcoGeometry.split === "Z"){ + b3 = 4; + } + + + data[i*3+0] = b1; + data[i*3+1] = b2; + data[i*3+2] = b3; + } + + + material.uniforms.nodeSize.value = this.pcoGeometry.boundingBox.size().x; + texture.needsUpdate = true; +} + + + +Object.defineProperty(Potree.PointCloudArena4D.prototype, "progress", { + get: function(){ + if(this.pcoGeometry.root){ + return Potree.PointCloudArena4DGeometryNode.nodesLoading > 0 ? 0 : 1; + }else{ + return 0; + } + } +}); + +//Potree.PointCloudArena4D.prototype.updateMatrixWorld = function( force ){ +// //node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix ); +// +// if ( this.matrixAutoUpdate === true ) this.updateMatrix(); +// +// if ( this.matrixWorldNeedsUpdate === true || force === true ) { +// +// if ( this.parent === undefined ) { +// +// this.matrixWorld.copy( this.matrix ); +// +// } else { +// +// this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); +// +// } +// +// this.matrixWorldNeedsUpdate = false; +// +// force = true; +// +// } +//}; + + +Potree.PointCloudArena4DGeometryNode = function(){ + var scope = this; + + this.left = null; + this.right = null; + this.boundingBox = null; + this.number = null; + this.pcoGeometry = null; + this.loaded = false; + this.numPoints = 0; + this.level = 0; +}; + +Potree.PointCloudArena4DGeometryNode.nodesLoading = 0; + +Potree.PointCloudArena4DGeometryNode.prototype.load = function(){ + + if(this.loaded || this.loading){ + return; + } + + if(Potree.PointCloudArena4DGeometryNode.nodesLoading >= 5){ + return; + } + + Potree.PointCloudArena4DGeometryNode.nodesLoading++; + + var url = this.pcoGeometry.url + "?node=" + this.number; + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + xhr.responseType = "arraybuffer"; + + var scope = this; + + xhr.onreadystatechange = function(){ + if(!(xhr.readyState === 4 && xhr.status === 200)){ + return; + } + + var buffer = xhr.response; + var view = new DataView(buffer); + var numPoints = buffer.byteLength / 17; + + var positions = new Float32Array(numPoints*3); + var colors = new Float32Array(numPoints*3); + var indices = new Uint32Array(numPoints); + + for(var i = 0; i < numPoints; i++){ + var x = view.getFloat32(i*17 + 0, true) + scope.boundingBox.min.x; + var y = view.getFloat32(i*17 + 4, true) + scope.boundingBox.min.y; + var z = view.getFloat32(i*17 + 8, true) + scope.boundingBox.min.z; + var r = view.getUint8(i*17 + 12, true) / 256; + var g = view.getUint8(i*17 + 13, true) / 256; + var b = view.getUint8(i*17 + 14, true) / 256; + + positions[i*3+0] = x; + positions[i*3+1] = y; + positions[i*3+2] = z; + + colors[i*3+0] = r; + colors[i*3+1] = g; + colors[i*3+2] = b; + + indices[i] = i; + } + + var geometry = new THREE.BufferGeometry(); + geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3)); + geometry.addAttribute("color", new THREE.BufferAttribute(colors, 3)); + geometry.addAttribute("indices", new THREE.BufferAttribute(indices, 1)); + + scope.geometry = geometry; + scope.loaded = true; + Potree.PointCloudArena4DGeometryNode.nodesLoading--; + + geometry.boundingBox = scope.boundingBox; + geometry.boundingSphere = scope.boundingSphere; + + scope.numPoints = numPoints; + }; + + xhr.send(null); +}; + + +Potree.PointCloudArena4DGeometry = function(){ + var scope = this; + + 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(url, callback){ + + var xhr = new XMLHttpRequest(); + xhr.open('GET', url + "?info", true); + + xhr.onreadystatechange = function(){ + try{ + if(xhr.readyState === 4 && xhr.status === 200){ + var response = JSON.parse(xhr.responseText); + + var geometry = new Potree.PointCloudArena4DGeometry(); + geometry.url = url; + geometry.name = response.Name; + geometry.provider = response.Provider; + geometry.numNodes = response.Nodes; + geometry.numPoints = response.Points; + geometry.version = response.Version; + geometry.boundingBox = new THREE.Box3( + new THREE.Vector3().fromArray(response.BoundingBox.slice(0,3)), + new THREE.Vector3().fromArray(response.BoundingBox.slice(3,6)) + ); + if(response.Spacing){ + geometry.spacing = response.Spacing; + } + + var offset = geometry.boundingBox.min.clone().multiplyScalar(-1); + + geometry.boundingBox.min.add(offset) + geometry.boundingBox.max.add(offset); + geometry.offset = offset; + + var center = geometry.boundingBox.center(); + var radius = geometry.boundingBox.size().length() / 2; + geometry.boundingSphere = new THREE.Sphere(center, radius); + + geometry.loadHierarchy(); + + callback(geometry); + }else if(xhr.readyState === 4){ + callback(null); + } + }catch(e){ + callback(null); + } + }; + + xhr.send(null); + +}; + +Potree.PointCloudArena4DGeometry.prototype.loadHierarchy = function(){ + var url = this.url + "?tree"; + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + xhr.responseType = "arraybuffer"; + + var scope = this; + + xhr.onreadystatechange = function(){ + if(!(xhr.readyState === 4 && xhr.status === 200)){ + return; + } + + var buffer = xhr.response; + var numNodes = buffer.byteLength / 3; + var view = new DataView(buffer); + var stack = []; + var root = null; + + var levels = 0; + + var start = new Date().getTime(); + // read hierarchy + for(var i = 0; i < numNodes; i++){ + var mask = view.getUint8(i*3+0, true); + var numPoints = view.getUint16(i*3+1, true); + + + var hasLeft = (mask & 1) > 0; + var hasRight = (mask & 2) > 0; + var splitX = (mask & 4) > 0; + var splitY = (mask & 8) > 0; + var splitZ = (mask & 16) > 0; + var split = null; + if(splitX){ + split = "X"; + }else if(splitY){ + split = "Y"; + }if(splitZ){ + split = "Z"; + } + + + var node = new Potree.PointCloudArena4DGeometryNode(); + node.hasLeft = hasLeft; + node.hasRight = hasRight; + node.split = split; + node.isLeaf = !hasLeft && !hasRight; + node.number = i; + node.left = null; + node.right = null; + node.pcoGeometry = scope; + node.level = stack.length; + levels = Math.max(levels, node.level); + + if(stack.length > 0){ + var parent = stack[stack.length-1]; + node.boundingBox = parent.boundingBox.clone(); + var parentBBSize = parent.boundingBox.size(); + + if(parent.hasLeft && !parent.left){ + parent.left = node; + + if(parent.split === "X"){ + node.boundingBox.max.x = node.boundingBox.min.x + parentBBSize.x / 2; + }else if(parent.split === "Y"){ + node.boundingBox.max.y = node.boundingBox.min.y + parentBBSize.y / 2; + }else if(parent.split === "Z"){ + node.boundingBox.max.z = node.boundingBox.min.z + parentBBSize.z / 2; + } + + var center = node.boundingBox.center(); + var radius = node.boundingBox.size().length() / 2; + node.boundingSphere = new THREE.Sphere(center, radius); + + }else{ + parent.right = node; + + if(parent.split === "X"){ + node.boundingBox.min.x = node.boundingBox.min.x + parentBBSize.x / 2; + }else if(parent.split === "Y"){ + node.boundingBox.min.y = node.boundingBox.min.y + parentBBSize.y / 2; + }else if(parent.split === "Z"){ + node.boundingBox.min.z = node.boundingBox.min.z + parentBBSize.z / 2; + } + + var center = node.boundingBox.center(); + var radius = node.boundingBox.size().length() / 2; + node.boundingSphere = new THREE.Sphere(center, radius); + } + }else{ + root = node; + root.boundingBox = scope.boundingBox.clone(); + var center = root.boundingBox.center(); + var radius = root.boundingBox.size().length() / 2; + root.boundingSphere = new THREE.Sphere(center, radius); + } + + var bbSize = node.boundingBox.size(); + node.spacing = ((bbSize.x + bbSize.y + bbSize.z) / 3) / 75; + + stack.push(node); + + if(node.isLeaf){ + var done = false; + while(!done && stack.length > 0){ + stack.pop(); + + var top = stack[stack.length-1]; + + done = stack.length > 0 && top.hasRight && top.right == null; + } + } + } + var end = new Date().getTime(); + var parseDuration = end - start; + var msg = parseDuration; + //document.getElementById("lblDebug").innerHTML = msg; + + scope.root = root; + scope.levels = levels; + //console.log(this.root); + + } + + xhr.send(null); + + +}; + +Object.defineProperty(Potree.PointCloudArena4DGeometry.prototype, "spacing", { + get: function(){ + if(this._spacing){ + return this._spacing; + }else if(this.root){ + return this.root.spacing; + }else{ + null; + } + }, + set: function(value){ + this._spacing = value; + } +}); + + diff --git a/build/js/potree.min.js b/build/js/potree.min.js index 623e2da6..746fa8a9 100644 --- a/build/js/potree.min.js +++ b/build/js/potree.min.js @@ -1,5 +1,5 @@ -function Potree(){}function POCLoader(){}function PointAttribute(e,t,o){this.name=e,this.type=t,this.numElements=o,this.byteSize=this.numElements*this.type.size}function PointAttributes(e){if(this.attributes=new Array,this.byteSize=0,this.size=0,null!=e)for(var t=0;tp)&&(a=h,l=p)}}return a?a.position:null}function pixelsArrayToImage(e,t,o){var i=document.createElement("canvas");i.width=t,i.height=o;var n=i.getContext("2d");e=new e.constructor(e);for(var r=0;r=n?o.pointsCount:o.pointsCount/n,a=function(){var e=t.readData(1e6,0,n);return e.then(function(e){return i.push(new LASDecoder(e.buffer,o.pointsFormatId,o.pointsStructSize,e.count,o.scale,o.offset,o.mins,o.maxs)),r+=e.count,Potree.LasLazLoader.progressCB(r/s),e.hasMoreData?a():(o.totalRead=r,o.versionAsString=t.versionAsString,o.isCompressed=t.isCompressed,[t,o,i])})};return a()}).then(function(e){var t=e[0];return Potree.LasLazLoader.progressCB(1),t.close().then(function(){return t.isOpen=!1,Promise.delay(200).cancellable()}).then(function(){return e.slice(1)})})["catch"](Promise.CancellationError,function(e){if(o.isOpen)return o.close().then(function(){throw o.isOpen=!1,e});throw e})},Potree.LasLazLoader.prototype.handle=function(){},Potree.LasLazBatcher=function(e){this.push=function(t){var o=Potree.workers.lasdecoder.getWorker(),i=new THREE.Vector3(t.mins[0],t.mins[1],t.mins[2]),n=new THREE.Vector3(t.maxs[0],t.maxs[1],t.maxs[2]);i.add(e.pcoGeometry.offset),n.add(e.pcoGeometry.offset),o.onmessage=function(r){for(var s=new THREE.BufferGeometry,a=t.pointsCount,l=r.data.position,d=r.data.color,c=r.data.intensity,h=new Uint8Array(r.data.classification),p=new Float32Array(h.byteLength),u=new Uint8Array(r.data.returnNumber),m=new Float32Array(u.byteLength),v=new Uint16Array(r.data.pointSourceID),E=new Float32Array(v.length),g=new ArrayBuffer(4*a),f=new Uint32Array(g),y=new THREE.Box3,b=new Float32Array(l),T=0;a>T;T++)p[T]=h[T],m[T]=u[T],E[T]=v[T],f[T]=T,y.expandByPoint(new THREE.Vector3(b[3*T+0],b[3*T+1],b[3*T+2]));s.addAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),s.addAttribute("color",new THREE.BufferAttribute(new Float32Array(d),3)),s.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(c),1)),s.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(p),1)),s.addAttribute("returnNumber",new THREE.BufferAttribute(new Float32Array(m),1)),s.addAttribute("pointSourceID",new THREE.BufferAttribute(new Float32Array(E),1)),s.addAttribute("indices",new THREE.BufferAttribute(g,1)),s.boundingBox=new THREE.Box3(i,n),e.boundingBox=s.boundingBox,e.geometry=s,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(o)};var r={buffer:t.arrayb,numPoints:t.pointsCount,pointSize:t.pointSize,pointFormatID:2,scale:t.scale,offset:t.offset,mins:[e.pcoGeometry.boundingBox.min.x,e.pcoGeometry.boundingBox.min.y,e.pcoGeometry.boundingBox.min.z],maxs:[e.pcoGeometry.boundingBox.max.x,e.pcoGeometry.boundingBox.max.y,e.pcoGeometry.boundingBox.max.z],bbOffset:[e.pcoGeometry.offset.x,e.pcoGeometry.offset.y,e.pcoGeometry.offset.z]};o.postMessage(r,[r.buffer])}},Potree.PointSizeType={FIXED:0,ATTENUATED:1,ADAPTIVE:2},Potree.PointShape={SQUARE:0,CIRCLE:1},Potree.PointColorType={RGB:0,COLOR:1,DEPTH:2,HEIGHT:3,INTENSITY:4,INTENSITY_GRADIENT:5,OCTREE_DEPTH:6,POINT_INDEX:7,CLASSIFICATION:8,RETURN_NUMBER:9,SOURCE:10},Potree.ClipMode={DISABLED:0,CLIP_OUTSIDE:1,HIGHLIGHT_INSIDE:2},Potree.PointCloudMaterial=function(e){e=e||{};var t=new THREE.Color(0),o=THREE.ImageUtils.generateDataTexture(2048,1,t);o.magFilter=THREE.NearestFilter,this.visibleNodesTexture=o;var i=e.size||1,n=e.minSize||1,r=1;this._pointSizeType=Potree.PointSizeType.ATTENUATED,this._pointShape=Potree.PointShape.SQUARE,this._interpolate=!1,this._pointColorType=Potree.PointColorType.RGB,this._octreeLevels=6,this._useClipBox=!1,this.numClipBoxes=0,this._clipMode=Potree.ClipMode.DISABLED,this._weighted=!1,this._blendDepth=.1,this._depthMap,this.gradientTexture=Potree.PointCloudMaterial.generateGradient();var s={},a={spacing:{type:"f",value:1},fov:{type:"f",value:1},screenWidth:{type:"f",value:1},screenHeight:{type:"f",value:1},near:{type:"f",value:.1},far:{type:"f",value:1},uColor:{type:"c",value:new THREE.Color(16711680)},opacity:{type:"f",value:1},size:{type:"f",value:10},minSize:{type:"f",value:2},nodeSize:{type:"f",value:r},heightMin:{type:"f",value:0},heightMax:{type:"f",value:1},intensityMin:{type:"f",value:0},intensityMax:{type:"f",value:1},visibleNodes:{type:"t",value:this.visibleNodesTexture},pcIndex:{type:"f",value:0},gradient:{type:"t",value:this.gradientTexture},clipBoxes:{type:"Matrix4fv",value:[]},blendDepth:{type:"f",value:this._blendDepth},depthMap:{type:"t",value:null}};this.setValues({uniforms:a,attributes:s,vertexShader:this.getDefines()+Potree.PointCloudMaterial.vs_points.join("\n"),fragmentShader:this.getDefines()+Potree.PointCloudMaterial.fs_points_rgb.join("\n"),vertexColors:THREE.VertexColors,size:i,minSize:n,nodeSize:r,pcIndex:0,alphaTest:.9})},Potree.PointCloudMaterial.prototype=new THREE.RawShaderMaterial,Potree.PointCloudMaterial.prototype.updateShaderSource=function(){var e={};this.pointColorType===Potree.PointColorType.INTENSITY||this.pointColorType===Potree.PointColorType.INTENSITY_GRADIENT?e.intensity={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.CLASSIFICATION?e.classification={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.RETURN_NUMBER?e.returnNumber={type:"f",value:[]}:this.pointColorType===Potree.PointColorType.SOURCE&&(e.pointSourceID={type:"f",value:[]}),this.setValues({attributes:e,vertexShader:this.getDefines()+Potree.PointCloudMaterial.vs_points.join("\n"),fragmentShader:this.getDefines()+Potree.PointCloudMaterial.fs_points_rgb.join("\n")}),this.depthMap&&(this.uniforms.depthMap.value=this.depthMap,this.setValues({depthMap:this.depthMap})),this.setValues(1===this.opacity?{blending:THREE.NoBlending,transparent:!1,depthTest:!0,depthWrite:!0}:{blending:THREE.AdditiveBlending,transparent:!0,depthTest:!1,depthWrite:!0}),this.weighted&&this.setValues({blending:THREE.AdditiveBlending,transparent:!0,depthTest:!0,depthWrite:!1}),this.needsUpdate=!0},Potree.PointCloudMaterial.prototype.getDefines=function(){var e="";return this.pointSizeType===Potree.PointSizeType.FIXED?e+="#define fixed_point_size\n":this.pointSizeType===Potree.PointSizeType.ATTENUATED?e+="#define attenuated_point_size\n":this.pointSizeType===Potree.PointSizeType.ADAPTIVE&&(e+="#define adaptive_point_size\n",e+="#define octreeLevels "+Math.max(0,this._octreeLevels-2).toFixed(1)+"\n"),this.pointShape===Potree.PointShape.SQUARE?e+="#define square_point_shape\n":this.pointShape===Potree.PointShape.CIRCLE&&(e+="#define circle_point_shape\n"),this._interpolate&&(e+="#define use_interpolation\n"),this._pointColorType===Potree.PointColorType.RGB?e+="#define color_type_rgb\n":this._pointColorType===Potree.PointColorType.COLOR?e+="#define color_type_color\n":this._pointColorType===Potree.PointColorType.DEPTH?e+="#define color_type_depth\n":this._pointColorType===Potree.PointColorType.HEIGHT?e+="#define color_type_height\n":this._pointColorType===Potree.PointColorType.INTENSITY?e+="#define color_type_intensity\n":this._pointColorType===Potree.PointColorType.INTENSITY_GRADIENT?e+="#define color_type_intensity_gradient\n":this._pointColorType===Potree.PointColorType.OCTREE_DEPTH?e+="#define color_type_octree_depth\n":this._pointColorType===Potree.PointColorType.POINT_INDEX?e+="#define color_type_point_index\n":this._pointColorType===Potree.PointColorType.CLASSIFICATION?e+="#define color_type_classification\n":this._pointColorType===Potree.PointColorType.RETURN_NUMBER?e+="#define color_type_return_number\n":this._pointColorType===Potree.PointColorType.SOURCE&&(e+="#define color_type_source\n"),this.clipMode===Potree.ClipMode.DISABLED?e+="#define clip_disabled\n":this.clipMode===Potree.ClipMode.CLIP_OUTSIDE?e+="#define clip_outside\n":this.clipMode===Potree.ClipMode.HIGHLIGHT_INSIDE&&(e+="#define clip_highlight_inside\n"),this.weighted&&(e+="#define weighted_splats\n"),this.numClipBoxes>0&&(e+="#define use_clip_box\n",e+="#define clip_box_count "+this.numClipBoxes+"\n"),e},Potree.PointCloudMaterial.prototype.setClipBoxes=function(e){var t=e.length;this.numClipBoxes=t,this.uniforms.clipBoxes.value.length/16!==t&&(this.uniforms.clipBoxes.value=new Float32Array(16*t),this.updateShaderSource());for(var o=0;t>o;o++){var i=e[o];this.uniforms.clipBoxes.value.set(i.elements,16*o)}},Object.defineProperty(Potree.PointCloudMaterial.prototype,"spacing",{get:function(){return this.uniforms.spacing.value},set:function(e){this.uniforms.spacing.value!==e&&(this.uniforms.spacing.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"blendDepth",{get:function(){return this.uniforms.blendDepth.value},set:function(e){this.uniforms.blendDepth.value!==e&&(this.uniforms.blendDepth.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"useClipBox",{get:function(){return this._useClipBox},set:function(e){this._useClipBox!==e&&(this._useClipBox=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"weighted",{get:function(){return this._weighted},set:function(e){this._weighted!==e&&(this._weighted=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"fov",{get:function(){return this.uniforms.fov.value},set:function(e){this.uniforms.fov.value!==e&&(this.uniforms.fov.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"screenWidth",{get:function(){return this.uniforms.screenWidth.value -},set:function(e){this.uniforms.screenWidth.value!==e&&(this.uniforms.screenWidth.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"screenHeight",{get:function(){return this.uniforms.screenHeight.value},set:function(e){this.uniforms.screenHeight.value!==e&&(this.uniforms.screenHeight.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"near",{get:function(){return this.uniforms.near.value},set:function(e){this.uniforms.near.value!==e&&(this.uniforms.near.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"far",{get:function(){return this.uniforms.far.value},set:function(e){this.uniforms.far.value!==e&&(this.uniforms.far.value=e)}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"opacity",{get:function(){return this.uniforms.opacity.value},set:function(e){this.uniforms.opacity.value!==e&&(this.uniforms.opacity.value=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"octreeLevels",{get:function(){return this._octreeLevels},set:function(e){this._octreeLevels!==e&&(this._octreeLevels=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointColorType",{get:function(){return this._pointColorType},set:function(e){this._pointColorType!==e&&(this._pointColorType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"depthMap",{get:function(){return this._depthMap},set:function(e){this._depthMap!==e&&(this._depthMap=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointSizeType",{get:function(){return this._pointSizeType},set:function(e){this._pointSizeType!==e&&(this._pointSizeType=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"clipMode",{get:function(){return this._clipMode},set:function(e){this._clipMode!==e&&(this._clipMode=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"interpolate",{get:function(){return this._interpolate},set:function(e){this._interpolate!==e&&(this._interpolate=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"color",{get:function(){return this.uniforms.uColor.value},set:function(e){this.uniforms.uColor.value!==e&&(this.uniforms.uColor.value.copy(e),this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pointShape",{get:function(){return this._pointShape},set:function(e){this._pointShape!==e&&(this._pointShape=e,this.updateShaderSource())}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"size",{get:function(){return this.uniforms.size.value},set:function(e){this.uniforms.size.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"minSize",{get:function(){return this.uniforms.minSize.value},set:function(e){this.uniforms.minSize.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"heightMin",{get:function(){return this.uniforms.heightMin.value},set:function(e){this.uniforms.heightMin.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"heightMax",{get:function(){return this.uniforms.heightMax.value},set:function(e){this.uniforms.heightMax.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"intensityMin",{get:function(){return this.uniforms.intensityMin.value},set:function(e){this.uniforms.intensityMin.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"intensityMax",{get:function(){return this.uniforms.intensityMax.value},set:function(e){this.uniforms.intensityMax.value=e}}),Object.defineProperty(Potree.PointCloudMaterial.prototype,"pcIndex",{get:function(){return this.uniforms.pcIndex.value},set:function(e){this.uniforms.pcIndex.value=e}}),Potree.PointCloudMaterial.generateGradient=function(){var e=64;canvas=document.createElement("canvas"),canvas.width=e,canvas.height=e;var t=canvas.getContext("2d");t.rect(0,0,e,e);var o=t.createLinearGradient(0,0,e,e);o.addColorStop(0,"#4700b6"),o.addColorStop(1/6,"blue"),o.addColorStop(2/6,"aqua"),o.addColorStop(.5,"green"),o.addColorStop(4/6,"yellow"),o.addColorStop(5/6,"orange"),o.addColorStop(1,"red"),t.fillStyle=o,t.fill();var i=new THREE.Texture(canvas);return i.needsUpdate=!0,textureImage=i.image,i},Potree.PointCloudMaterial.vs_points=["precision mediump float; ","precision mediump int; "," ","attribute vec3 position; ","attribute vec3 color; ","attribute float intensity; ","attribute float classification; ","attribute float returnNumber; ","attribute float pointSourceID; ","attribute vec4 indices; "," ","uniform mat4 modelMatrix; ","uniform mat4 modelViewMatrix; ","uniform mat4 projectionMatrix; ","uniform mat4 viewMatrix; ","uniform mat3 normalMatrix; ","uniform vec3 cameraPosition; ","uniform float screenWidth; ","uniform float screenHeight; ","uniform float fov; ","uniform float spacing; ","uniform float blendDepth; ","uniform float near; ","uniform float far; "," ","#if defined use_clip_box "," uniform mat4 clipBoxes[clip_box_count]; ","#endif "," "," ","uniform float heightMin; ","uniform float heightMax; ","uniform float intensityMin; ","uniform float intensityMax; ","uniform float size; ","uniform float minSize; ","uniform float nodeSize; ","uniform vec3 uColor; ","uniform float opacity; "," "," ","uniform sampler2D visibleNodes; ","uniform sampler2D gradient; ","uniform sampler2D depthMap; "," ","varying float vOpacity; ","varying vec3 vColor; ","varying float vDepth; ","varying float vLinearDepth; "," "," ","#if defined(adaptive_point_size) || defined(color_type_octree_depth) ","/** "," * number of 1-bits up to inclusive index position "," * number is treated as if it were an integer in the range 0-255 "," * "," */ ","float numberOfOnes(float number, float index){ "," float tmp = mod(number, pow(2.0, index + 1.0)); "," float numOnes = 0.0; "," for(float i = 0.0; i < 8.0; i++){ "," if(mod(tmp, 2.0) != 0.0){ "," numOnes++; "," } "," tmp = floor(tmp / 2.0); "," } "," return numOnes; ","} "," "," ","/** "," * checks whether the bit at index is 1 "," * number is treated as if it were an integer in the range 0-255 "," * "," */ ","bool isBitSet(float number, float index){ "," return mod(floor(number / pow(2.0, index)), 2.0) != 0.0; ","} "," "," ","/** "," * find the octree depth at the point position "," */ ","float getOctreeDepth(){ "," vec3 offset = vec3(0.0, 0.0, 0.0); "," float iOffset = 0.0; "," float depth = 0.0; "," for(float i = 0.0; i <= octreeLevels + 1.0; i++){ "," "," float nodeSizeAtLevel = nodeSize / pow(2.0, i); "," vec3 index3d = (position - offset) / nodeSizeAtLevel; "," index3d = floor(index3d + 0.5); "," float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z; "," "," vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0)); "," float mask = value.r * 255.0; "," if(isBitSet(mask, index)){ "," // there are more visible child nodes at this position "," iOffset = iOffset + value.g * 255.0 + numberOfOnes(mask, index - 1.0); "," depth++; "," }else{ "," // no more visible child nodes at this position "," return depth; "," } "," offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d; "," } "," "," return depth; ","} "," ","#endif "," ","vec3 classificationColor(float classification){ "," vec3 color = vec3(0.0, 0.0, 0.0); "," float c = mod(classification, 16.0); "," if(c == 0.0){ "," color = vec3(0.5, 0.5, 0.5); "," }else if(c == 1.0){ "," color = vec3(0.5, 0.5, 0.5); "," }else if(c == 2.0){ "," color = vec3(0.63, 0.32, 0.18); "," }else if(c == 3.0){ "," color = vec3(0.0, 1.0, 0.0); "," }else if(c == 4.0){ "," color = vec3(0.0, 0.8, 0.0); "," }else if(c == 5.0){ "," color = vec3(0.0, 0.6, 0.0); "," }else if(c == 6.0){ "," color = vec3(1.0, 0.66, 0.0); "," }else if(c == 7.0){ "," color = vec3(1.0, 0, 1.0); "," }else if(c == 8.0){ "," color = vec3(1.0, 0, 0.0); "," }else if(c == 9.0){ "," color = vec3(0.0, 0.0, 1.0); "," }else if(c == 12.0){ "," color = vec3(1.0, 1.0, 0.0); "," }else{ "," color = vec3(0.3, 0.6, 0.6); "," } "," "," return color; ","} "," ","void main() { "," "," vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); "," gl_Position = projectionMatrix * mvPosition; "," //float pw = gl_Position.w; "," //float pd = gl_Position.z; "," //gl_Position = gl_Position / pw; "," //gl_Position.z = 2.0*((pw - near) / far)-1.0; "," vOpacity = opacity; "," vLinearDepth = -mvPosition.z; "," vDepth = mvPosition.z / gl_Position.w; "," "," // COLOR TYPES "," "," #ifdef color_type_rgb "," vColor = color; "," #elif defined color_type_height "," vec4 world = modelMatrix * vec4( position, 1.0 ); "," float w = (world.y - heightMin) / (heightMax-heightMin); "," "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_depth "," float d = -mvPosition.z ; "," vColor = vec3(d, vDepth, 0.0); "," #elif defined color_type_intensity "," float w = (intensity - intensityMin) / (intensityMax - intensityMin); "," vColor = vec3(w, w, w); "," #elif defined color_type_intensity_gradient "," float w = (intensity - intensityMin) / intensityMax; "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_color "," vColor = uColor; "," #elif defined color_type_octree_depth "," float depth = getOctreeDepth(); "," float w = depth / 10.0; "," vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #elif defined color_type_point_index "," vColor = indices.rgb; "," #elif defined color_type_classification "," vColor = classificationColor(classification); "," #elif defined color_type_return_number "," float w = (returnNumber - 1.0) / 4.0 + 0.1; "," vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb; "," #elif defined color_type_source "," float w = mod(pointSourceID, 10.0) / 10.0; "," vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb; "," #endif "," "," "," "," // "," // POINT SIZE TYPES "," // "," float r = spacing * 1.5; "," #if defined fixed_point_size "," gl_PointSize = size; "," #elif defined attenuated_point_size "," //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); "," gl_PointSize = (1.0 / tan(fov/2.0)) * size / (-mvPosition.z); "," gl_PointSize = gl_PointSize * screenHeight / 2.0; "," #elif defined adaptive_point_size "," //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); "," //gl_PointSize = (1.0 / tan(fov/2.0)) * r / sqrt( max(0.0, mvPosition.z * mvPosition.z - r * r)); "," gl_PointSize = (1.0 / tan(fov/2.0)) * r / (-mvPosition.z); "," gl_PointSize = size * gl_PointSize * screenHeight / 2.0; "," gl_PointSize = gl_PointSize / pow(1.9, getOctreeDepth()); "," #endif "," "," gl_PointSize = max(minSize, gl_PointSize); "," gl_PointSize = min(50.0, gl_PointSize); "," "," // clip box "," #if defined use_clip_box "," bool insideAny = false; "," for(int i = 0; i < clip_box_count; i++){ "," vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 ); "," bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5; "," inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5; "," inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5; "," insideAny = insideAny || inside; "," } "," if(!insideAny){ "," "," #if defined clip_outside "," gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0); "," #elif defined clip_highlight_inside && !defined(color_type_depth) "," float c = (vColor.r + vColor.g + vColor.b) / 6.0; "," //vColor = vec3(c, c, c); "," #endif "," }else{ "," #if defined clip_highlight_inside "," vColor.r += 0.5; "," #endif "," } "," "," #endif "," "," ","} "],Potree.PointCloudMaterial.fs_points_rgb=["#if defined use_interpolation "," #extension GL_EXT_frag_depth : enable ","#endif "," ","precision mediump float; ","precision mediump int; "," ","//uniform float opacity; ","uniform float pcIndex; ","uniform float screenWidth; ","uniform float screenHeight; ","uniform float blendDepth; "," ","uniform sampler2D depthMap; "," ","varying vec3 vColor; ","varying float vOpacity; ","varying float vLinearDepth; ","varying float vDepth; "," ","void main() { "," "," #if defined(circle_point_shape) || defined(use_interpolation) || defined (weighted_splats) "," float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0); "," float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0); "," float c = 1.0 - (a + b); "," "," if(c < 0.0){ "," discard; "," } "," #endif "," "," #if defined weighted_splats "," vec2 uv = gl_FragCoord.xy / vec2(screenWidth, screenHeight); "," "," float depth = texture2D(depthMap, uv).r; "," if(vLinearDepth > depth + blendDepth){ "," discard; "," } "," #endif "," "," #if defined use_interpolation "," gl_FragDepthEXT = gl_FragCoord.z + 0.002*(1.0-pow(c, 1.0)) * gl_FragCoord.w; "," #endif "," "," "," #if defined color_type_point_index "," gl_FragColor = vec4(vColor, pcIndex / 255.0); "," #else "," gl_FragColor = vec4(vColor, vOpacity); "," #endif "," "," "," #if defined weighted_splats "," float w = pow(c, 2.0); "," gl_FragColor.rgb = gl_FragColor.rgb * w; "," gl_FragColor.a = w; "," #endif "," "," "," ","} "],THREE.FirstPersonControls=function(e,t){function o(e){l.enabled!==!1&&(e.preventDefault(),0===e.button?(R=T.ROTATE,d.set(e.clientX,e.clientY)):2===e.button&&(R=T.PAN,p.set(e.clientX,e.clientY)),l.domElement.addEventListener("mousemove",i,!1),l.domElement.addEventListener("mouseup",n,!1),l.dispatchEvent(C))}function i(e){if(l.enabled!==!1){e.preventDefault();var t=l.domElement===document?l.domElement.body:l.domElement;R===T.ROTATE?(c.set(e.clientX,e.clientY),h.subVectors(c,d),l.rotateLeft(2*Math.PI*h.x/t.clientWidth*l.rotateSpeed),l.rotateUp(2*Math.PI*h.y/t.clientHeight*l.rotateSpeed),d.copy(c)):R===T.PAN&&(u.set(e.clientX,e.clientY),m.subVectors(u,p),m.multiplyScalar(5e-4).multiplyScalar(l.moveSpeed),l.pan(m.x,m.y),p.copy(u))}}function n(){l.enabled!==!1&&(l.domElement.removeEventListener("mousemove",i,!1),l.domElement.removeEventListener("mouseup",n,!1),l.dispatchEvent(w),R=T.NONE) -}function r(e){if(l.enabled!==!1&&l.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1;l.moveSpeed+=.1*l.moveSpeed*t,l.moveSpeed=Math.max(.1,l.moveSpeed),l.dispatchEvent(C),l.dispatchEvent(w)}}function s(e){if(l.enabled!==!1)switch(e.keyCode){case l.keys.UP:l.moveForward=!0;break;case l.keys.BOTTOM:l.moveBackward=!0;break;case l.keys.LEFT:l.moveLeft=!0;break;case l.keys.RIGHT:l.moveRight=!0;break;case l.keys.W:l.moveForward=!0;break;case l.keys.S:l.moveBackward=!0;break;case l.keys.A:l.moveLeft=!0;break;case l.keys.D:l.moveRight=!0}}function a(e){switch(e.keyCode){case l.keys.W:l.moveForward=!1;break;case l.keys.S:l.moveBackward=!1;break;case l.keys.A:l.moveLeft=!1;break;case l.keys.D:l.moveRight=!1;break;case l.keys.UP:l.moveForward=!1;break;case l.keys.BOTTOM:l.moveBackward=!1;break;case l.keys.LEFT:l.moveLeft=!1;break;case l.keys.RIGHT:l.moveRight=!1}}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.rotateSpeed=1,this.moveSpeed=10,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40,A:"A".charCodeAt(0),S:"S".charCodeAt(0),D:"D".charCodeAt(0),W:"W".charCodeAt(0)};var l=this,d=new THREE.Vector2,c=new THREE.Vector2,h=new THREE.Vector2,p=new THREE.Vector2,u=new THREE.Vector2,m=new THREE.Vector2,v=new THREE.Vector3,E=(new THREE.Vector3,0),g=0,f=1,y=new THREE.Vector3,b=new THREE.Vector3,T={NONE:-1,ROTATE:0,SPEEDCHANGE:1,PAN:2},R=T.NONE;this.position0=this.object.position.clone();var P={type:"change"},C={type:"start"},w={type:"end"};this.rotateLeft=function(e){g-=e},this.rotateUp=function(e){E-=e},this.panLeft=function(e){var t=this.object.matrix.elements;v.set(t[0],t[1],t[2]),v.multiplyScalar(-e),y.add(v)},this.panUp=function(e){var t=this.object.matrix.elements;v.set(t[4],t[5],t[6]),v.multiplyScalar(e),y.add(v)},this.panForward=function(e){var t=this.object.matrix.elements;v.set(t[8],t[9],t[10]),v.multiplyScalar(e),y.add(v)},this.pan=function(e,t){var o=l.domElement===document?l.domElement.body:l.domElement;if(void 0!==l.object.fov){var i=l.object.position,n=i.clone(),r=n.length();r*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*r/o.clientHeight),l.panUp(2*t*r/o.clientHeight)}else void 0!==l.object.top?(l.panLeft(e*(l.object.right-l.object.left)/o.clientWidth),l.panUp(t*(l.object.top-l.object.bottom)/o.clientHeight)):console.warn("WARNING: FirstPersonControls.js encountered an unknown camera type - pan disabled.")},this.update=function(e){this.object.rotation.order="ZYX";var t=this.object.position;if(void 0!==e&&(this.moveRight&&this.panLeft(-e*this.moveSpeed),this.moveLeft&&this.panLeft(e*this.moveSpeed),this.moveForward&&this.panForward(-e*this.moveSpeed),this.moveBackward&&this.panForward(e*this.moveSpeed)),!y.equals(new THREE.Vector3(0,0,0))){var o={type:"move",translation:y.clone()};this.dispatchEvent(o)}if(t.add(y),0!==g||0!==E){var o={type:"rotate",thetaDelta:g,phiDelta:E};this.dispatchEvent(o)}this.object.updateMatrix();var i=(new THREE.Matrix4).makeRotationY(g),n=(new THREE.Matrix4).multiplyMatrices(i,this.object.matrix);this.object.quaternion.setFromRotationMatrix(n),this.object.rotation.x+=E,g=0,E=0,f=1,y.set(0,0,0),b.distanceTo(this.object.position)>0&&(this.dispatchEvent(P),b.copy(this.object.position))},this.reset=function(){R=T.NONE,this.object.position.copy(this.position0)},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",r,!1),this.domElement.addEventListener("DOMMouseScroll",r,!1),window.addEventListener("keydown",s,!1),window.addEventListener("keyup",a,!1)},THREE.FirstPersonControls.prototype=Object.create(THREE.EventDispatcher.prototype),THREE.EarthControls=function(e,t,o){function i(e){if(a.enabled!==!1){e.preventDefault();var t={x:e.clientX/a.domElement.clientWidth*2-1,y:2*-(e.clientY/a.domElement.clientHeight)+1},o=getMousePointCloudIntersection(t,a.camera,a.renderer,a.pointclouds);if(o){var i=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),o),s=new THREE.Vector3(t.x,t.y,.5);s.unproject(a.camera);var p=s.sub(a.camera.position).normalize(),u=new THREE.Ray(a.camera.position,p);E=u.intersectPlane(i),v=a.camera.clone(),v.rotation.copy(a.camera.rotation),c.set(e.clientX,e.clientY),h.set(e.clientX,e.clientY),a.scene.add(a.pivotNode),a.pivotNode.position.copy(E),0===e.button?d=l.DRAG:2===e.button&&(d=l.ROTATE),a.domElement.addEventListener("mousemove",n,!1),a.domElement.addEventListener("mouseup",r,!1)}}}function n(e){if(a.enabled!==!1){e.preventDefault();{a.domElement===document?a.domElement.body:a.domElement}m.set(e.clientX-h.x,e.clientY-h.y),h.set(e.clientX,e.clientY)}}function r(){a.enabled!==!1&&(a.domElement.removeEventListener("mousemove",n,!1),a.domElement.removeEventListener("mouseup",r,!1),d=l.NONE,a.scene.remove(a.pivotNode))}function s(e){if(a.enabled!==!1&&a.noZoom!==!0){e.preventDefault();var t=e.detail<0||e.wheelDelta>0?1:-1,o={x:e.clientX/a.domElement.clientWidth*2-1,y:2*-(e.clientY/a.domElement.clientHeight)+1},i=getMousePointCloudIntersection(o,a.camera,a.renderer,a.pointclouds);if(i){var n=i.distanceTo(a.camera.position),r=(new THREE.Vector3).subVectors(i,a.camera.position).normalize();a.camera.position.add(r.multiplyScalar(.1*n*t))}}}this.camera=e,this.renderer=t,this.pointclouds=[],this.domElement=t.domElement,this.scene=o,this.enabled=!0;var a=this,l={NONE:-1,DRAG:0,ROTATE:1},d=l.NONE,c=new THREE.Vector2,h=new THREE.Vector2,p=new THREE.SphereGeometry(1,32,32),u=new THREE.MeshNormalMaterial({shading:THREE.SmoothShading,transparent:!0,opacity:.5});this.pivotNode=new THREE.Mesh(p,u);var m=new THREE.Vector2,v=null,E=null;this.minAngle=10/180*Math.PI,this.maxAngle=70/180*Math.PI,this.update=function(e){this.camera.position;if(E){if(d===l.DRAG){var t=(new THREE.Plane).setFromNormalAndCoplanarPoint(new THREE.Vector3(0,1,0),E),o={x:h.x/this.domElement.clientWidth*2-1,y:2*-(h.y/this.domElement.clientHeight)+1},i=new THREE.Vector3(o.x,o.y,.5);i.unproject(v);var n=i.sub(v.position).normalize(),r=new THREE.Ray(v.position,n),s=r.distanceToPlane(t);if(s>0){var a=(new THREE.Vector3).subVectors(E,n.clone().multiplyScalar(s));this.camera.position.copy(a)}}else if(d===l.ROTATE){var c=m.clone().multiplyScalar(e);c.x*=.3,c.y*=.2,this.camera.updateMatrixWorld();var p=new THREE.Object3D,u=new THREE.Object3D;p.add(u),p.position.copy(E),u.position.copy(this.camera.position).sub(E),u.rotation.copy(this.camera.rotation),p.rotation.y+=-c.x;var n=this.camera.getWorldDirection(),g=new THREE.Vector3(0,1,0),f=(new THREE.Vector3).crossVectors(g,n),y=u.position.clone();y.y=0,y.normalize();var b=y.dot(u.position.clone().normalize()),T=Math.acos(b);u.position.y<0&&(T=-T);var R=0;R=c.y>0?c.y-Math.max(0,this.minAngle-(T-c.y)):c.y+Math.max(0,T-c.y-this.maxAngle),p.rotateOnAxis(f,-R),p.updateMatrixWorld(),this.camera.position.copy(u.getWorldPosition()),this.camera.quaternion.copy(u.getWorldQuaternion())}var P=this.pivotNode.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),C=Math.abs(P.z/30),w=this.pivotNode.scale.length();this.pivotNode.scale.multiplyScalar(C/w)}m.set(0,0)},this.reset=function(){d=l.NONE,this.camera.position.copy(this.position0)},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",i,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1)},THREE.EarthControls.prototype=Object.create(THREE.EventDispatcher.prototype),LRU.prototype.size=function(){return this.elements},LRU.prototype.contains=function(e){return null==this.items[e.id]},LRU.prototype.touch=function(e){var t;null==this.items[e.id]?(t=new LRUItem(e),t.previous=this.last,this.last=t,null!==t.previous&&(t.previous.next=t),this.items[e.id]=t,this.elements++,null===this.first&&(this.first=t),this.numPoints+=e.numPoints):(t=this.items[e.id],null===t.previous?null!==t.next&&(this.first=t.next,this.first.previous=null,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t):null===t.next||(t.previous.next=t.next,t.next.previous=t.previous,t.previous=this.last,t.next=null,this.last=t,t.previous.next=t))},LRU.prototype.remove=function(){if(null===this.first)return null;var e=this.first;return null!==e.next?(this.first=e.next,this.first.previous=null):(this.first=null,this.last=null),delete this.items[e.node.id],this.elements--,this.numPoints-=e.node.numPoints,e.node},LRU.prototype.getLRUItem=function(){if(null===this.first)return null;var e=this.first;return e.node},LRU.prototype.toString=function(){for(var e="{ ",t=this.first;null!==t;)e+=t.node.id,null!==t.next&&(e+=", "),t=t.next;return e+="}",e+="("+this.size()+")"},Potree.PointCloudOctreeProxyNode=function(e){THREE.Object3D.call(this),this.geometryNode=e,this.boundingBox=e.boundingBox,this.boundingSphere=this.boundingBox.getBoundingSphere(),this.name=e.name,this.level=e.level,this.numPoints=e.numPoints},Potree.PointCloudOctreeProxyNode.prototype=Object.create(THREE.Object3D.prototype),Potree.ProfileRequest=function(e,t,o,i,n){this.start=e,this.end=t,this.width=o,this.depth=i,this.callback=n,this.loadQueue=[];var r=((new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),(new THREE.Vector3).subVectors(t,e).length(),(new THREE.Vector3).subVectors(t,e).normalize()),s=new THREE.Vector3(0,1,0),a=(new THREE.Vector3).crossVectors(r,s).normalize(),l=a;this.plane=(new THREE.Plane).setFromNormalAndCoplanarPoint(l,e)},Potree.PointCloudOctree=function(e,t){THREE.Object3D.call(this),Potree.PointCloudOctree.lru=Potree.PointCloudOctree.lru||new LRU,this.pcoGeometry=e,this.boundingBox=this.pcoGeometry.tightBoundingBox,this.boundingSphere=this.boundingBox.getBoundingSphere(),this.material=t||new Potree.PointCloudMaterial,this.visiblePointsTarget=2e6,this.level=0,this.position.sub(e.offset),this.updateMatrix(),this.LODDistance=20,this.LODFalloff=1.3,this.LOD=4,this.showBoundingBox=!1,this.boundingBoxNodes=[],this.loadQueue=[],this.visibleBounds=new THREE.Box3,this.profileRequests=[],this.visibleNodes=[],this.visibleGeometry=[],this.pickTarget,this.pickMaterial,this.maxLevel=0;var o=new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);this.add(o)},Potree.PointCloudOctree.prototype=Object.create(THREE.Object3D.prototype),Potree.PointCloudOctree.prototype.updateVisibleBounds=function(){for(var e=[],t=0;t0;){var r=n.shift();if(r instanceof Potree.PointCloudOctreeProxyNode){var s=Potree.utils.computeTransformedBoundingBox(r.boundingBox,r.matrixWorld),a=s.getBoundingSphere();Math.abs(o.distanceToPoint(a.center))0){var r=c.loadQueue[0],h=r.geometryNode;if(h.loaded===!0&&void 0!==r.parent){var p=this.replaceProxy(r);p.updateMatrixWorld(),p.matrixWorld.multiplyMatrices(p.parent.matrixWorld,p.matrix)}else r.geometryNode.load()}else{var u=this.getProfile(c.start,c.end,c.width,c.depth);c.callback({type:"finished",points:u}),d.push(c)}}for(var e=0;e-1&&this.profileRequests.splice(m,1)}},Potree.PointCloudOctree.prototype.updatePointCloud=function(e,t,o,i){if(this.numVisibleNodes++,this.numVisiblePoints+=e.numPoints,e.material=this.material,this.visibleNodes.push(t),e.level&&(this.maxLevel=Math.max(e.level,this.maxLevel)),this.showBoundingBox&&!e.boundingBoxNode){var n=new THREE.BoxHelper(e);this.add(n),this.boundingBoxNodes.push(n),e.boundingBoxNode=n,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)}else this.showBoundingBox?(e.boundingBoxNode.visible=!0,e.boundingBoxNode.matrixWorld.copy(e.matrixWorld)):!this.showBoundingBox&&e.boundingBoxNode&&(e.boundingBoxNode.visible=!1);for(var r=0;r=0;if(a)for(var l=0;l0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var e=0;e0;){{var s=r.shift(),a=s.node;s.weight}if(a.visible=!0,a.matrixWorld.multiplyMatrices(a.parent.matrixWorld,a.matrix),a instanceof Potree.PointCloudOctreeProxyNode){var l=a.geometryNode;l.loaded===!0?this.replaceProxy(a):this.loadQueue.push(s)}else a instanceof THREE.PointCloud&&this.updatePointCloud(a,s,r,o)}this.updateProfileRequests(),this.updateVisibleBounds(),this.updateLoadQueue(),this.hideDescendants(this.children[0]);for(var d=[],i=0;i0;){f++;var y=u.shift(),b=y.node,T=b.boundingBox,v=b.boundingSphere,R=i.intersectsBox(T),P=R;if(P){if(m+b.numPoints>this.visiblePointsTarget)break;m+=b.numPoints,t.push(y);for(var C=0;8>C;C++)if(b.children[C]){var w=b.children[C],v=w.boundingSphere,E=v.center.distanceTo(h),x=v.radius,g=v.radius/E,H=e.fov/2*Math.PI/180,V=1/Math.tan(H)*x/Math.sqrt(E*E-x*x);if(!(.1>V))if(g=V,0>E-x&&(g=Number.MAX_VALUE),0===u.length)u.push({node:w,weight:g});else{for(var S=0,M=0;Mu[M].weight){var S=M;break}if(M==u.length-1){S=u.length;break}}u.splice(S,0,{node:w,weight:g})}}}}return t},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(e,t){if(e){var o=e.visibleNodesTexture,i=o.image.data;t=t.slice();var n=function(e,t){var o=e.name,i=t.name;return o.length!=i.length?o.length-i.length:i>o?-1:o>i?1:0};t.sort(n);for(var r={},s=0;st.name?1:0}),i[3*s+0]=0,i[3*s+1]=0,i[3*s+2]=0;for(var d=0;dr;r++)if(void 0!==t.children[r]){var s=t.children[r],a=new Potree.PointCloudOctreeProxyNode(s);i.add(a)}return i}},Potree.PointCloudOctree.prototype.hideDescendants=function(e){for(var t=[],o=0;o0;){var e=t.shift();e.visible=!1;for(var o=0;o0&&(l=-l),function(e){var t=(new THREE.Matrix4).makeTranslation(-i.x,-i.y,-i.z),o=(new THREE.Matrix4).makeRotationY(-l),n=(new THREE.Matrix4).makeTranslation(r,0,0),s=e.clone();return s.applyMatrix4(t),s.applyMatrix4(o),s.applyMatrix4(n),s}}(r,s,i),d={start:r,end:s,points:a,project:l};o.push(d),i+=r.distanceTo(s)}return o},Potree.PointCloudOctree.prototype.getProfile=function(e,t,o,i,n){if(void 0===n){var r=[];r.push(this);for(var s=(new THREE.Vector3).addVectors(t,e).multiplyScalar(.5),a=(new THREE.Vector3).subVectors(t,e).length(),l=(new THREE.Vector3).subVectors(t,e).normalize(),d=new THREE.Vector3(0,1,0),c=(new THREE.Vector3).crossVectors(l,d).normalize(),h=c,p=(new THREE.Plane).setFromNormalAndCoplanarPoint(h,e),u=(new THREE.Plane).setFromNormalAndCoplanarPoint(l,s),m=null;r.length>0;){var v=r.shift(),E=0;if(v instanceof THREE.PointCloud){var g=v.geometry,f=g.attributes.position,y=f.array,b=v.numPoints;if(!m){m={};for(var T in g.attributes)g.attributes.hasOwnProperty(T)&&("indices"===T||(m[T]=[]))}for(var R=0;b>R;R++){var P=new THREE.Vector3(y[3*R],y[3*R+1],y[3*R+2]);P.applyMatrix4(this.matrixWorld);var C=Math.abs(p.distanceToPoint(P)),w=Math.abs(u.distanceToPoint(P));if(o/2>C&&a/2>w){for(var T in g.attributes)if(g.attributes.hasOwnProperty(T))if("position"===T)m[T].push(P);else if("indices"===T);else{var x=g.attributes[T];if(1===x.itemSize)m[T].push(x.array[R+V]);else{for(var H=[],V=0;V0&&(s=-s),function(e){var t=(new THREE.Matrix4).makeTranslation(-o.x,-o.y,-o.z),i=(new THREE.Matrix4).makeRotationY(-s),n=e.clone();return n.applyMatrix4(t),n.applyMatrix4(i),n}}(e,t);return m.project=B,m}this.profileRequests.push(new Potree.ProfileRequest(e,t,o,i,n))},Potree.PointCloudOctree.disposeLeastRecentlyUsed=function(e){var t=0;do{var o=this.lru.first.node,i=o.parent,n=(o.geometry,o.pcoGeometry),r=new Potree.PointCloudOctreeProxyNode(n),s=Potree.PointCloudOctree.disposeNode(o);if(t+=s.freed,i.add(r),0==s.numDeletedNodes)break}while(e>t)},Potree.PointCloudOctree.disposeNode=function(e){var t=0,o=0,i=[];e.traverse(function(e){i.push(e)});for(var n=0;n0&&r.push(r[0]);for(var h=0;hP;P++)for(var C=0;n>C;C++){var w=P+C*n,x=Math.pow(P-(n-1)/2,2)+Math.pow(C-(n-1)/2,2),H=y[4*w+3];y[4*w+3]=0;var V=b[w];(0!==V||0!==H)&&T>x&&(R={pIndex:V,pcIndex:H},T=x)}if(R){var S={},M=r[R.pcIndex],B=M.geometry.attributes;for(var A in B)if(B.hasOwnProperty(A)){var I=u.attributes[A];if("position"===A){var L=M.geometry.attributes.position.array,N=L[3*R.pIndex+0],W=L[3*R.pIndex+1],G=L[3*R.pIndex+2],X=new THREE.Vector3(N,W,G);X.applyMatrix4(this.matrixWorld),S[A]=X}else if("indices"===A);else if(1===I.itemSize)S[A]=I.array[h+z];else{for(var Z=[],z=0;zn;n++)e+=o.substr(n*t,t)+"/";return e},Potree.PointCloudOctreeGeometryNode.prototype.addChild=function(e){this.children[e.index]=e,e.parent=this},Potree.PointCloudOctreeGeometryNode.prototype.load=function(){this.loading===!0||this.pcoGeometry.numNodesLoading>3||(this.loading=!0,Potree.PointCloudOctree.lru.numPoints+this.numPoints>=Potree.pointLoadLimit&&Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints),this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.version.equalOrHigher("1.5")&&this.level%this.pcoGeometry.hierarchyStepSize===0&&this.hasChildren?this.loadHierachyThenPoints():this.loadPoints())},Potree.PointCloudOctreeGeometryNode.prototype.loadPoints=function(){this.pcoGeometry.loader.load(this)},Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints=function(){var e=this,t=function(e,t){var o=(t.byteLength/5,new DataView(t)),i=[],n=o.getUint8(0),r=o.getUint32(1,!0);e.numPoints=r,i.push({children:n,numPoints:r,name:e.name});for(var s=[],a=5;i.length>0;){for(var l=i.shift(),d=1,c=0;8>c;c++){if(0!==(l.children&d)){var h=l.name+c,p=o.getUint8(a),u=o.getUint32(a+1,!0);i.push({children:p,numPoints:u,name:h}),s.push({children:p,numPoints:u,name:h}),a+=5}d=2*d}if(a===t.byteLength)break}var m={};m[e.name]=e;for(var v=e.pcoGeometry,c=0;c0,y.addChild(R),m[E]=R}e.loadPoints()};if(e.level%e.pcoGeometry.hierarchyStepSize===0){var o=e.pcoGeometry.octreeDir+"/"+e.getHierarchyPath()+"/"+e.name+".hrc",i=new XMLHttpRequest;i.open("GET",o,!0),i.responseType="arraybuffer",i.overrideMimeType("text/plain; charset=x-user-defined"),i.onreadystatechange=function(){if(4===i.readyState)if(200===i.status||0===i.status){var o=i.response;t(e,o)}else console.log("Failed to load file! HTTP status: "+i.status+", file: "+url)};try{i.send(null)}catch(n){console.log("fehler beim laden der punktwolke: "+n)}}},Potree.PointCloudOctreeGeometryNode.prototype.dispose=function(){delete this.geometry,this.loaded=!1},Potree.utils=function(){},Potree.utils.pathExists=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),200!==t.status?!1:!0},Potree.utils.computeTransformedBoundingBox=function(e,t){var o=[new THREE.Vector3(e.min.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.min.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.max.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.min.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.min.x,e.max.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.max.y,e.min.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.min.y,e.max.z).applyMatrix4(t),new THREE.Vector3(e.max.x,e.max.y,e.max.z).applyMatrix4(t)],i=new THREE.Box3;return i.setFromPoints(o),i},Potree.utils.addCommas=function(e){e+="",x=e.split("."),x1=x[0],x2=x.length>1?"."+x[1]:"";for(var t=/(\d+)(\d{3})/;t.test(x1);)x1=x1.replace(t,"$1,$2");return x1+x2},Potree.utils.createWorker=function(e){var t=new Blob([e],{type:"application/javascript"}),o=new Worker(URL.createObjectURL(t));return o},Potree.utils.loadSkybox=function(e){var t=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,1,1e5),o=new THREE.Scene,i=".jpg",n=[e+"px"+i,e+"nx"+i,e+"py"+i,e+"ny"+i,e+"pz"+i,e+"nz"+i],r=THREE.ImageUtils.loadTextureCube(n,THREE.CubeRefractionMapping),s={uniforms:{tCube:{type:"t",value:r},tFlip:{type:"f",value:-1}},vertexShader:THREE.ShaderLib.cube.vertexShader,fragmentShader:THREE.ShaderLib.cube.fragmentShader},a=new THREE.ShaderMaterial({fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,uniforms:s.uniforms,depthWrite:!1,side:THREE.BackSide}),l=new THREE.Mesh(new THREE.BoxGeometry(100,100,100),a);return o.add(l),{camera:t,scene:o}},Potree.utils.createGrid=function(e,t,o,i){for(var n=new THREE.LineBasicMaterial({color:i||8947848}),r=new THREE.Geometry,s=0;t>=s;s++)r.vertices.push(new THREE.Vector3(-(o*e)/2,0,s*o-o*t/2)),r.vertices.push(new THREE.Vector3(+(o*e)/2,0,s*o-o*t/2));for(var s=0;e>=s;s++)r.vertices.push(new THREE.Vector3(s*o-o*e/2,0,-(o*t)/2)),r.vertices.push(new THREE.Vector3(s*o-o*e/2,0,+(o*t)/2));var a=new THREE.Line(r,n,THREE.LinePieces);return a.receiveShadow=!0,a},Potree.utils.createBackgroundTexture=function(e,t){function o(e,t){return 1/(2*Math.PI)*Math.exp(-(e*e+t*t)/2)}var i=THREE.ImageUtils.generateDataTexture(e,t,new THREE.Color);i.magFilter=THREE.NearestFilter;for(var n=i.image.data,r=[1,1.5,1.7],s=o(0,0),a=0;e>a;a++)for(var l=0;t>l;l++){var d=2*(a/e)-1,c=2*(l/t)-1,h=a+e*l,p=o(2*d,2*c)/s,u=(Math.random()+Math.random()+Math.random())/3;u=(.5*p+.5)*u*.03,u=.4*u,n[3*h+0]=255*(p/15+.05+u)*r[0],n[3*h+1]=255*(p/15+.05+u)*r[1],n[3*h+2]=255*(p/15+.05+u)*r[2]}return i},Potree.Features=function(){var e=document.createElement("canvas").getContext("webgl");return{SHADER_INTERPOLATION:{isSupported:function(){var t=!0;return t=t&&e.getExtension("EXT_frag_depth"),t=t&&e.getParameter(e.MAX_VARYING_VECTORS)>=8}},SHADER_SPLATS:{isSupported:function(){var t=!0;return t=t&&e.getExtension("EXT_frag_depth"),t=t&&e.getExtension("OES_texture_float"),t=t&&e.getParameter(e.MAX_VARYING_VECTORS)>=8}}}}(),Potree.TextSprite=function(e){THREE.Object3D.call(this);var t=new THREE.Texture,o=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});this.material=o,this.sprite=new THREE.Sprite(o),this.add(this.sprite),this.borderThickness=4,this.fontface="Arial",this.fontsize=28,this.borderColor={r:0,g:0,b:0,a:1},this.backgroundColor={r:255,g:255,b:255,a:1},this.textColor={r:255,g:255,b:255,a:1},this.text="",this.setText(e) -},Potree.TextSprite.prototype=new THREE.Object3D,Potree.TextSprite.prototype.setText=function(e){this.text=e,this.update()},Potree.TextSprite.prototype.setTextColor=function(e){this.textColor=e,this.update()},Potree.TextSprite.prototype.setBorderColor=function(e){this.borderColor=e,this.update()},Potree.TextSprite.prototype.setBackgroundColor=function(e){this.backgroundColor=e,this.update()},Potree.TextSprite.prototype.update=function(){var e=document.createElement("canvas"),t=e.getContext("2d");t.font="Bold "+this.fontsize+"px "+this.fontface;var o=t.measureText(this.text),i=o.width,n=i+2*this.borderThickness,r=1.4*this.fontsize+2*this.borderThickness,e=document.createElement("canvas"),t=e.getContext("2d");t.canvas.width=n,t.canvas.height=r,t.font="Bold "+this.fontsize+"px "+this.fontface,t.fillStyle="rgba("+this.backgroundColor.r+","+this.backgroundColor.g+","+this.backgroundColor.b+","+this.backgroundColor.a+")",t.strokeStyle="rgba("+this.borderColor.r+","+this.borderColor.g+","+this.borderColor.b+","+this.borderColor.a+")",t.lineWidth=this.borderThickness,this.roundRect(t,this.borderThickness/2,this.borderThickness/2,i+this.borderThickness,1.4*this.fontsize+this.borderThickness,6),t.strokeStyle="rgba(0, 0, 0, 1.0)",t.strokeText(this.text,this.borderThickness,this.fontsize+this.borderThickness),t.fillStyle="rgba("+this.textColor.r+","+this.textColor.g+","+this.textColor.b+","+this.textColor.a+")",t.fillText(this.text,this.borderThickness,this.fontsize+this.borderThickness);var s=new THREE.Texture(e);s.needsUpdate=!0,this.sprite.material.map=s,this.sprite.scale.set(.01*n,.01*r,1)},Potree.TextSprite.prototype.roundRect=function(e,t,o,i,n,r){e.beginPath(),e.moveTo(t+r,o),e.lineTo(t+i-r,o),e.quadraticCurveTo(t+i,o,t+i,o+r),e.lineTo(t+i,o+n-r),e.quadraticCurveTo(t+i,o+n,t+i-r,o+n),e.lineTo(t+r,o+n),e.quadraticCurveTo(t,o+n,t,o+n-r),e.lineTo(t,o+r),e.quadraticCurveTo(t,o,t+r,o),e.closePath(),e.fill(),e.stroke()},Potree.Version=function(e){this.version=e;var t=-1===e.indexOf(".")?e.length:e.indexOf(".");this.versionMajor=parseInt(e.substr(0,t)),this.versionMinor=parseInt(e.substr(t+1)),0===this.versionMinor.length&&(this.versionMinor=0)},Potree.Version.prototype.newerThan=function(e){var t=new Potree.Version(e);return this.versionMajor>t.versionMajor?!0:this.versionMajor===t.versionMajor&&this.versionMinor>t.versionMinor?!0:!1},Potree.Version.prototype.equalOrHigher=function(e){var t=new Potree.Version(e);return this.versionMajor>t.versionMajor?!0:this.versionMajor===t.versionMajor&&this.versionMinor>=t.versionMinor?!0:!1},Potree.Version.prototype.upTo=function(e){return!this.newerThan(e)},Potree.AngleTool=function(e,t,o){"use strict";function i(e){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.angleLabels=[],this.root=e,this.closed=!0;var t=new THREE.SphereGeometry(.4,10,10),o=new THREE.Color(16711680),i=function(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e};this.add=function(e){this.points.push(e);var n=new THREE.Mesh(t,i());n.addEventListener("mousemove",m),n.addEventListener("mouseleave",v),n.addEventListener("mousedrag",E),n.addEventListener("drop",g);var r=new THREE.Geometry;r.vertices.push(new THREE.Vector3,new THREE.Vector3),r.colors.push(o,o,o);var s=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2});s.depthTest=!1;var a=new THREE.Line(r,s),l=new Potree.TextSprite;l.setBorderColor({r:0,g:255,b:0,a:0}),l.setBackgroundColor({r:0,g:255,b:0,a:0}),l.material.depthTest=!1,l.material.opacity=1,this.root.add(n),this.root.add(a),this.root.add(l),this.spheres.push(n),this.edges.push(a),this.angleLabels.push(l),this.setPosition(this.points.length-1,e)},this.remove=function(e){this.points.splice(e,1),this.root.remove(this.spheres[e]),this.root.remove(this.edges[e]),this.root.remove(this.angleLabels[e]),this.spheres.splice(e,1),this.edges.splice(e,1),this.angleLabels.splice(e,1),this.update()},this.removeAll=function(){for(;this.points.length>1;)this.remove(0);this.sceneRoot.visible=!1,this.update()},this.getAngleBetweenLines=function(e,t,o){var i=(new THREE.Vector3).subVectors(t,e),n=(new THREE.Vector3).subVectors(o,e);return i.angleTo(n)},this.getAngle=function(e){var t=0,o=this.points[0],i=this.points[1],n=this.points[2];return 0===e?t=this.getAngleBetweenLines(o,i,n):1===e?t=this.getAngleBetweenLines(i,o,n):2===e&&(t=this.getAngleBetweenLines(n,o,i)),t},this.setPosition=function(e,t){var o=this.points[e];o.copy(t),this.update()},this.setClosed=function(e){this.closed=e,this.update()},this.update=function(){var e,t;if(1===this.points.length)return e=this.points[0],this.spheres[0].position.copy(e),this.edges[0].visible=!1,void(this.angleLabels[0].visible=!1);var o=this.points.length-1,i=new THREE.Vector3;for(t=0;o>=t;t++){e=this.points[t];var n=this.spheres[t],r=0===t?o:t-1,s=this.edges[r],a=this.edges[t];n.position.copy(e),s.geometry.vertices[1].copy(e),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere(),a.geometry.vertices[0].copy(e),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere(),a.visible=t!==o||this.closed?!0:!1,i.add(e)}if(i.multiplyScalar(1/this.points.length),this.points.length>=3)for(t=0;o>=t;t++){this.angleLabels[t].visible=!0,this.angleLabels[t].setText(Potree.utils.addCommas((this.getAngle(t)*(180/Math.PI)).toFixed(1))+"°");var l=(new THREE.Vector3).addVectors(this.points[t],i).multiplyScalar(.5);this.angleLabels[t].position.copy(l)}else for(t=0;o>=t;t++)this.angleLabels[t].visible=!1}}function n(e){if(h.enabled&&void 0!==e){var t=c();if(t){var o=t.clone();if(u===p.DEFAULT&&(u=p.PICKING,h.activeMeasurement=new i),u===p.PICKING&&h.activeMeasurement&&h.activeMeasurement.points.length>2)h.measurements.push(h.activeMeasurement),h.activeMeasurement=void 0,u=p.DEFAULT,h.setEnabled(!1);else{h.activeMeasurement.add(o);var n={type:"newpoint",position:o.clone()};h.dispatchEvent(n)}}}}function r(e){if(void 0!==e){var t=h.domElement.getBoundingClientRect();h.mouse.x=(e.clientX-t.left)/h.domElement.clientWidth*2-1,h.mouse.y=2*-((e.clientY-t.top)/h.domElement.clientHeight)+1;var o;if(h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(u===p.PICKING&&h.activeMeasurement){if(o=c()){var i=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(i,o)}}else o=d(),o?(o.object.dispatchEvent({type:"mousemove",target:o.object,event:e}),h.hoveredElement&&h.hoveredElement!==o.object&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=o.object):(h.hoveredElement&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=null)}}function s(e){void 0!==e&&u===p.PICKING&&(h.activeMeasurement.removeAll(),h.activeMeasurement=void 0,u=p.DEFAULT,h.setEnabled(!1))}function a(e){if(1===e.which){u!==p.DEFAULT&&e.stopImmediatePropagation();var t=d();t&&(h.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:h.sceneRoot.position.clone(),mousePos:{x:h.mouse.x,y:h.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&s(e)}function l(e){h.dragstart&&(h.dragstart.object.dispatchEvent({type:"drop",event:e}),h.dragstart=null)}function d(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=new THREE.Raycaster;t.ray.set(h.camera.position,e.sub(h.camera.position).normalize());for(var o=[],i=0;i0?s[0]:!1}function c(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.accuracy=.5;var p={DEFAULT:0,PICKING:1},u=p.DEFAULT;this.activeMeasurement=null,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){var t=c();if(t)for(var o=0;o=0){h.measurements[o].setPosition(n,t);break}}e.event.stopImmediatePropagation()},g=function(e){};this.setEnabled=function(e){this.enabled!==e&&(this.enabled=e,e&&(u=p.PICKING,h.activeMeasurement=new i(h.sceneRoot),h.activeMeasurement.add(new THREE.Vector3(0,0,0))))},this.update=function(){var e,t,o,i,n=[];for(e=0;e=3,1===this.points.length){var e=this.points[0];return this.spheres[0].position.copy(e),this.edges[0].visible=!1,void(this.edgeLabels[0].visible=!1)}for(var t=new THREE.Vector3,o=this.points.length-1,i=0;o>=i;i++){var e=this.points[i],n=this.spheres[i],r=0===i?o:i-1,s=i===o?0:i+1,a=this.points[r],l=this.points[s],d=this.edges[r],c=this.edges[i],h=this.edgeLabels[r],p=this.edgeLabels[i],u=e.distanceTo(a),m=e.distanceTo(l),v=(new THREE.Vector3).addVectors(a,e).multiplyScalar(.5),E=(new THREE.Vector3).addVectors(e,l).multiplyScalar(.5);h.position.copy(v),p.position.copy(E),h.setText(u.toFixed(2)),p.setText(m.toFixed(2)),n.position.copy(e),d.geometry.vertices[1].copy(e),d.geometry.verticesNeedUpdate=!0,d.geometry.computeBoundingSphere(),c.geometry.vertices[0].copy(e),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),i!==o||this.closed?(c.visible=!0,p.visible=!0):(c.visible=!1,p.visible=!1),t.add(e)}t.multiplyScalar(1/this.points.length);var g=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(g),this.areaLabel.position.copy(t)}}function n(e){if(h.enabled){var t=c();if(t){var o=t.clone();u===p.DEFAULT&&(u=p.PICKING,h.activeMeasurement=new i),h.activeMeasurement.add(o);var e={type:"newpoint",position:o.clone()};h.dispatchEvent(e)}}}function r(e){var t=h.domElement.getBoundingClientRect();if(h.mouse.x=(e.clientX-t.left)/h.domElement.clientWidth*2-1,h.mouse.y=2*-((e.clientY-t.top)/h.domElement.clientHeight)+1,h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(u==p.PICKING&&h.activeMeasurement){var o=c();if(o){var i=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(i,o)}}else{var o=d();o?(o.object.dispatchEvent({type:"mousemove",target:o.object,event:e}),h.hoveredElement&&h.hoveredElement!==o.object&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=o.object):(h.hoveredElement&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=null)}}function s(){u==p.PICKING&&(h.activeMeasurement.remove(h.activeMeasurement.points.length-1),h.measurements.push(h.activeMeasurement),h.activeMeasurement=void 0,u=p.DEFAULT,h.setEnabled(!1))}function a(e){if(1===e.which){u!==p.DEFAULT&&e.stopImmediatePropagation();var t=d();t&&(h.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:h.sceneRoot.position.clone(),mousePos:{x:h.mouse.x,y:h.mouse.y}},e.stopImmediatePropagation())}else 3===e.which&&s(e)}function l(e){h.dragstart&&(h.dragstart.object.dispatchEvent({type:"drop",event:e}),h.dragstart=null)}function d(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=new THREE.Raycaster;t.ray.set(h.camera.position,e.sub(h.camera.position).normalize());for(var o=[],i=0;i0?s[0]:!1}function c(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};{var p={DEFAULT:0,PICKING:1},u=p.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){var t=c();if(t)for(var o=0;o=0){h.measurements[o].setPosition(n,t);break}}e.event.stopImmediatePropagation()},g=function(){};this.setEnabled=function(e){this.enabled!==e&&(this.enabled=e,e&&(u=p.PICKING,h.activeMeasurement=new i(h.sceneRoot),h.activeMeasurement.add(new THREE.Vector3(0,0,0))))},this.update=function(){for(var e=[],o=0;o0?s[0]:!1}function h(){var e=new THREE.Vector3(p.mouse.x,p.mouse.y,.5);e.unproject(p.camera);var t=e.sub(p.camera.position).normalize(),o=new THREE.Ray(p.camera.position,t),i=[];p.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var p=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0};var u={DEFAULT:0,PICKING:1},m=u.DEFAULT,v=new THREE.SphereGeometry(.4,10,10);this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null;var E=function(e){e.target.material.emissive.setHex(8947848)},g=function(e){e.target.material.emissive.setHex(0)},f=function(e){var t=h();if(t)for(var o=0;o=0){var r=i.spheres[n];if(0===n){var s=i.edges[n],a=i.edgeLabels[n];r.position.copy(t),s.geometry.vertices[0].copy(t),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere();var l=s.geometry.vertices[0].clone().add(s.geometry.vertices[1]).multiplyScalar(.5),d=s.geometry.vertices[0].distanceTo(s.geometry.vertices[1]).toFixed(2);a.position.copy(l),a.setText(d),a.scale.multiplyScalar(10)}else if(n===i.spheres.length-1){var s=i.edges[n-1],a=i.edgeLabels[n-1];r.position.copy(t),s.geometry.vertices[1].copy(t),s.geometry.verticesNeedUpdate=!0,s.geometry.computeBoundingSphere();var l=s.geometry.vertices[0].clone().add(s.geometry.vertices[1]).multiplyScalar(.5),d=s.geometry.vertices[0].distanceTo(s.geometry.vertices[1]).toFixed(2);a.position.copy(l),a.setText(d),a.scale.multiplyScalar(10)}else{var c=i.edges[n-1],u=i.edges[n],m=i.edgeLabels[n-1],v=i.edgeLabels[n];r.position.copy(t),c.geometry.vertices[1].copy(t),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),u.geometry.vertices[0].copy(t),u.geometry.verticesNeedUpdate=!0,u.geometry.computeBoundingSphere();var E=c.geometry.vertices[0].clone().add(c.geometry.vertices[1]).multiplyScalar(.5),g=c.geometry.vertices[0].distanceTo(c.geometry.vertices[1]).toFixed(2);m.position.copy(E),m.setText(g),m.scale.multiplyScalar(10);var f=u.geometry.vertices[0].clone().add(u.geometry.vertices[1]).multiplyScalar(.5),y=u.geometry.vertices[0].distanceTo(u.geometry.vertices[1]).toFixed(2);v.position.copy(f),v.setText(y),v.scale.multiplyScalar(10)}break}}e.event.stopImmediatePropagation()},y=function(){};this.setEnabled=function(e){if(this.enabled!==e&&(this.enabled=e,e)){m=u.PICKING,p.activeMeasurement=new i;var t=new THREE.Mesh(v,n());p.sceneRoot.add(t),p.activeMeasurement.spheres.push(t),t.addEventListener("mousemove",E),t.addEventListener("mouseleave",g),t.addEventListener("mousedrag",f),t.addEventListener("drop",y)}},this.update=function(){for(var e=[],o=0;o1){var r=new THREE.Geometry;r.vertices.push(new THREE.Vector3,new THREE.Vector3),r.colors.push(t,t,t);var s=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2,transparent:!0,opacity:.4});s.depthTest=!1;var a=new THREE.Line(r,s);a.visible=!1,this.add(a),this.edges.push(a);var l=new THREE.BoxGeometry(1,1,1),d=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),c=new THREE.Mesh(l,d);c.visible=!1,this.add(c),this.boxes.push(c)}this.setPosition(this.points.length-1,i)},this.removeMarker=function(e){this.points.splice(e,1),this.remove(this.spheres[e]),e>0&&(this.remove(this.edges[e-1]),this.edges.splice(e-1,1),this.remove(this.boxes[e-1]),this.boxes.splice(e-1,1)),this.spheres.splice(e,1),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,o=0;o=r;r++){{var e=this.points[r],s=this.spheres[r],a=0===r?n:r-1,l=r===n?0:r+1,d=this.points[a],c=this.points[l],h=this.edges[a],p=this.edges[r],u=this.boxes[a];this.boxes[r],e.distanceTo(d),e.distanceTo(c),(new THREE.Vector3).addVectors(d,e).multiplyScalar(.5),(new THREE.Vector3).addVectors(e,c).multiplyScalar(.5)}if(s.position.copy(e),h&&(h.geometry.vertices[1].copy(e),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere()),p&&(p.geometry.vertices[0].copy(e),p.geometry.verticesNeedUpdate=!0,p.geometry.computeBoundingSphere()),u){var m=d,v=e,E=m.clone().setY(0).distanceTo(v.clone().setY(0));u.scale.set(E,this.height,this.width);var g=(new THREE.Vector3).addVectors(m,v).multiplyScalar(.5),f=(new THREE.Vector3).subVectors(v,m),y=new THREE.Vector3(f.z,0,-f.x);u.position.set(0,0,0),u.lookAt(y),u.position.copy(g)}i.add(e),t.min(e),o.max(e)}i.multiplyScalar(1/this.points.length);for(var r=0;r0?o[0]:!1}function c(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0}; -{var p={DEFAULT:0,INSERT:1},u=p.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeProfile,this.profiles=[],this.sceneProfile=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneProfile.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneProfile.add(this.light),this.hoveredElement=null;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},E=function(e){if(e.event.ctrlKey){var t=new THREE.Vector3(h.dragstart.mousePos.x,h.dragstart.mousePos.y,0),o=new THREE.Vector3(h.mouse.x,h.mouse.y,0),i=h.dragstart.widthStart,n=1-10*(t.y-o.y);if(n=Math.max(.01,n),i)for(var r=0;r=0){s.setWidth(i*n),s.update();break}}}else{var l=c();if(l)for(var r=0;r=0){h.profiles[r].setPosition(a,l);break}}}e.event.stopImmediatePropagation()},g=function(){};i.prototype=Object.create(THREE.Object3D.prototype),this.startInsertion=function(e){u=p.INSERT;var e=e||{},t=e.clip||!1,o=e.width||1;this.activeProfile=new i,this.activeProfile.clip=t,this.activeProfile.setWidth(o),this.sceneProfile.add(this.activeProfile),this.profiles.push(this.activeProfile),this.activeProfile.addMarker(new THREE.Vector3(0,0,0))},this.finishInsertion=function(){this.activeProfile.removeMarker(this.activeProfile.points.length-1),this.activeProfile=null,u=p.DEFAULT},this.update=function(){for(var e=0;e0?i[0]:!1}}var a=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.dragstart=null,this.sceneTransformation=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneTransformation.add(this.sceneRoot),this.sceneRotation=new THREE.Scene,this.translationNode=new THREE.Object3D,this.rotationNode=new THREE.Object3D,this.scaleNode=new THREE.Object3D,this.sceneRoot.add(this.translationNode),this.sceneRoot.add(this.rotationNode),this.sceneRoot.add(this.scaleNode),this.sceneRoot.visible=!1,this.hoveredElement=null,this.STATE={DEFAULT:0,TRANSLATE_X:1,TRANSLATE_Y:2,TRANSLATE_Z:3,SCALE_X:1,SCALE_Y:2,SCALE_Z:3},this.parts={ARROW_X:{name:"arrow_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.TRANSLATE_X},ARROW_Z:{name:"arrow_z",object:void 0,color:new THREE.Color(255),state:this.STATE.TRANSLATE_Z},ARROW_Y:{name:"arrow_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.TRANSLATE_Y},SCALE_X:{name:"scale_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.SCALE_X},SCALE_Z:{name:"scale_z",object:void 0,color:new THREE.Color(255),state:this.STATE.SCALE_Z},SCALE_Y:{name:"scale_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.SCALE_Y},ROTATE_X:{name:"rotate_x",object:void 0,color:new THREE.Color(16711680),state:this.STATE.ROTATE_X},ROTATE_Z:{name:"rotate_z",object:void 0,color:new THREE.Color(255),state:this.STATE.ROTATE_Z},ROTATE_Y:{name:"rotate_y",object:void 0,color:new THREE.Color(65280),state:this.STATE.ROTATE_Y}},this.buildTranslationNode=function(){var e=a.createArrow(a.parts.ARROW_X,a.parts.ARROW_X.color);e.rotation.z=-Math.PI/2;var t=a.createArrow(a.parts.ARROW_Y,a.parts.ARROW_Y.color),o=a.createArrow(a.parts.ARROW_Z,a.parts.ARROW_Z.color);o.rotation.x=-Math.PI/2,this.translationNode.add(e),this.translationNode.add(t),this.translationNode.add(o)},this.buildScaleNode=function(){var e=this.createScaleHandle(a.parts.SCALE_X,16711680);e.rotation.z=-Math.PI/2;var t=this.createScaleHandle(a.parts.SCALE_Y,65280),o=this.createScaleHandle(a.parts.SCALE_Z,255);o.rotation.x=-Math.PI/2,this.scaleNode.add(e),this.scaleNode.add(t),this.scaleNode.add(o)},this.buildRotationNode=function(){var e=this.createRotationCircle(a.parts.ROTATE_X,16711680);e.rotation.y=-Math.PI/2;var t=this.createRotationCircle(a.parts.ROTATE_Y,65280),o=this.createRotationCircle(a.parts.ROTATE_Z,255);t.rotation.x=-Math.PI/2,this.rotationNode.add(e),this.rotationNode.add(t),this.rotationNode.add(o);var i=new THREE.SphereGeometry(2.9,24,24),n=new THREE.Mesh(i,new THREE.MeshBasicMaterial({color:11184810,transparent:!0,opacity:.4}));this.sceneRotation.add(n);var r=function(){n.material.color.setHex(5592405)},s=function(){n.material.color.setHex(11184810)},l=function(e){e.event.stopImmediatePropagation();for(var t=new THREE.Vector3(a.dragstart.mousePos.x,a.dragstart.mousePos.y,.1),o=new THREE.Vector3(a.mouse.x,a.mouse.y,.1),i=(new THREE.Vector3).subVectors(o,t),n=t.clone().unproject(a.camera),r=o.clone().unproject(a.camera),s=(new THREE.Vector3).subVectors(r,n),l=s.clone().normalize(),d=(new THREE.Vector3).subVectors(a.camera.position,n).normalize(),c=d.clone().cross(l),h=6*i.length(),p=0;p=n;n++){var r=2*Math.PI*n/i,s=3*Math.cos(r),l=3*Math.sin(r);o.push(new THREE.Vector3(s,l,0))}for(var d=new THREE.Geometry,n=0;no;o++)t.label.children[o].updateMatrixWorld(!0)},this.setDimension=function(e,t,o){this.dimension.set(e,t,o),this.box.scale.set(e,t,o),this.frame.scale.set(e,t,o)},this.volume=function(){return Math.abs(this.scale.x*this.scale.y*this.scale.z)},this.update=function(){this.boundingBox=this.box.geometry.boundingBox},this.raycast=function(e,t){var o=[];if(this.box.raycast(e,o),o.length>0){var i=o[0];t.push({distance:i.distance,object:this,point:i.point.clone()})}}}function n(e){var t=c.domElement.getBoundingClientRect();c.mouse.x=(e.clientX-t.left)/c.domElement.clientWidth*2-1,c.mouse.y=2*-((e.clientY-t.top)/c.domElement.clientHeight)+1}function r(){}function s(e){if(p!==h.DEFAULT&&e.stopImmediatePropagation(),p===h.INSERT_VOLUME)c.finishInsertion();else if(1===e.which){var t=l();t&&transformationTool.setTargets([t.object])}3===e.which}function a(e){return e.preventDefault(),!1}function l(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=new THREE.Raycaster;t.ray.set(c.camera.position,e.sub(c.camera.position).normalize());for(var o=[],i=0;i0?r[0]:!1}function d(){var e=new THREE.Vector3(c.mouse.x,c.mouse.y,.5);e.unproject(c.camera);var t=e.sub(c.camera.position).normalize(),o=new THREE.Ray(c.camera.position,t),i=[];c.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var n=null,r=null,s=0;sd)&&(n=l,r=d)}}return n?n.position:null}var c=this;this.enabled=!1,this.scene=e,this.sceneVolume=new THREE.Scene,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.volumes=[];var h={DEFAULT:0,INSERT_VOLUME:1},p=h.DEFAULT,u=new THREE.BoxGeometry(1,1,1);u.computeBoundingBox();var m=new THREE.Geometry;m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),i.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(i.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)}}),this.update=function(){if(p===h.INSERT_VOLUME){var e=d();if(e){this.activeVolume.position.copy(e);var t=this.activeVolume.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse),o=(new THREE.Vector4(t.x,t.y,t.z).applyMatrix4(this.camera.projectionMatrix),Math.abs(t.z/10));this.activeVolume.scale.set(o,o,o)}}for(var i=[],n=0;nu)&&(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 diff --git a/build/shaders/shaders.js b/build/shaders/shaders.js new file mode 100644 index 00000000..a886a7e1 --- /dev/null +++ b/build/shaders/shaders.js @@ -0,0 +1,580 @@ +Potree.Shaders["pointcloud.vs"] = [ + "", + "// the following is an incomplete list of attributes, uniforms and defines", + "// which are automatically added through the THREE.ShaderMaterial", + "", + "//attribute vec3 position;", + "//attribute vec3 color;", + "//attribute vec3 normal;", + "", + "//uniform mat4 modelMatrix;", + "//uniform mat4 modelViewMatrix;", + "//uniform mat4 projectionMatrix;", + "//uniform mat4 viewMatrix;", + "//uniform mat3 normalMatrix;", + "//uniform vec3 cameraPosition;", + "", + "//#define MAX_DIR_LIGHTS 0", + "//#define MAX_POINT_LIGHTS 1", + "//#define MAX_SPOT_LIGHTS 0", + "//#define MAX_HEMI_LIGHTS 0", + "//#define MAX_SHADOWS 0", + "//#define MAX_BONES 58", + "", + "", + "attribute float intensity;", + "attribute float classification;", + "attribute float returnNumber;", + "attribute float pointSourceID;", + "attribute vec4 indices;", + "", + "uniform float screenWidth;", + "uniform float screenHeight;", + "uniform float fov;", + "uniform float spacing;", + "uniform float blendDepth;", + "uniform float near;", + "uniform float far;", + "", + "#if defined use_clip_box", + " uniform mat4 clipBoxes[clip_box_count];", + "#endif", + "", + "", + "uniform float heightMin;", + "uniform float heightMax;", + "uniform float intensityMin;", + "uniform float intensityMax;", + "uniform float size;", + "uniform float minSize;", + "uniform float maxSize;", + "uniform float nodeSize;", + "uniform vec3 bbSize;", + "uniform vec3 uColor;", + "uniform float opacity;", + "", + "", + "uniform sampler2D visibleNodes;", + "uniform sampler2D gradient;", + "uniform sampler2D classificationLUT;", + "uniform sampler2D depthMap;", + "", + "varying float vOpacity;", + "varying vec3 vColor;", + "varying float vDepth;", + "varying float vLinearDepth;", + "varying vec3 vViewPosition;", + "varying float vRadius;", + "varying vec3 vWorldPosition;", + "varying vec3 vNormal;", + "", + "", + "// ---------------------", + "// OCTREE", + "// ---------------------", + "", + "#if (defined(adaptive_point_size) || defined(color_type_tree_depth)) && defined(tree_type_octree)", + "/**", + " * number of 1-bits up to inclusive index position", + " * number is treated as if it were an integer in the range 0-255", + " *", + " */", + "float numberOfOnes(float number, float index){", + " float tmp = mod(number, pow(2.0, index + 1.0));", + " float numOnes = 0.0;", + " for(float i = 0.0; i < 8.0; i++){", + " if(mod(tmp, 2.0) != 0.0){", + " numOnes++;", + " }", + " tmp = floor(tmp / 2.0);", + " }", + " return numOnes;", + "}", + "", + "", + "/**", + " * checks whether the bit at index is 1", + " * number is treated as if it were an integer in the range 0-255", + " *", + " */", + "bool isBitSet(float number, float index){", + " return mod(floor(number / pow(2.0, index)), 2.0) != 0.0;", + "}", + "", + "", + "/**", + " * find the tree depth at the point position", + " */", + "float getLocalTreeDepth(){", + " vec3 offset = vec3(0.0, 0.0, 0.0);", + " float iOffset = 0.0;", + " float depth = 0.0;", + " for(float i = 0.0; i <= levels + 1.0; i++){", + " ", + " float nodeSizeAtLevel = nodeSize / pow(2.0, i);", + " vec3 index3d = (position - offset) / nodeSizeAtLevel;", + " index3d = floor(index3d + 0.5);", + " float index = 4.0*index3d.x + 2.0*index3d.y + index3d.z;", + " ", + " vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));", + " float mask = value.r * 255.0;", + " if(isBitSet(mask, index)){", + " // there are more visible child nodes at this position", + " iOffset = iOffset + value.g * 255.0 + numberOfOnes(mask, index - 1.0);", + " depth++;", + " }else{", + " // no more visible child nodes at this position", + " return depth;", + " }", + " offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;", + " }", + " ", + " return depth;", + "}", + "", + "float getPointSizeAttenuation(){", + " return pow(1.9, getLocalTreeDepth());", + "}", + "", + "", + "#endif", + "", + "", + "// ---------------------", + "// KD-TREE", + "// ---------------------", + "", + "#if (defined(adaptive_point_size) || defined(color_type_tree_depth)) && defined(tree_type_kdtree)", + "", + "float getLocalTreeDepth(){", + " vec3 offset = vec3(0.0, 0.0, 0.0);", + " float iOffset = 0.0;", + " float depth = 0.0;", + " ", + " ", + " vec3 size = bbSize; ", + " vec3 pos = position;", + " ", + " for(float i = 0.0; i <= levels + 1.0; i++){", + " ", + " vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));", + " ", + " int children = int(value.r * 255.0);", + " float next = value.g * 255.0;", + " int split = int(value.b * 255.0);", + " ", + " if(next == 0.0){", + " return depth;", + " }", + " ", + " vec3 splitv = vec3(0.0, 0.0, 0.0);", + " if(split == 1){", + " splitv.x = 1.0;", + " }else if(split == 2){", + " splitv.y = 1.0;", + " }else if(split == 4){", + " splitv.z = 1.0;", + " }", + " ", + " iOffset = iOffset + next;", + " ", + " float factor = length(pos * splitv / size);", + " if(factor < 0.5){", + " // left", + " if(children == 0 || children == 2){", + " return depth;", + " }", + " }else{", + " // right", + " pos = pos - size * splitv * 0.5;", + " if(children == 0 || children == 1){", + " return depth;", + " }", + " if(children == 3){", + " iOffset = iOffset + 1.0;", + " }", + " }", + " size = size * ((1.0 - (splitv + 1.0) / 2.0) + 0.5);", + " ", + " depth++;", + " }", + " ", + " ", + " return depth; ", + "}", + "", + "float getPointSizeAttenuation(){", + " return pow(1.3, getLocalTreeDepth());", + "}", + "", + "#endif", + "", + "void main() {", + " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", + " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", + " vViewPosition = -mvPosition.xyz;", + " vWorldPosition = worldPosition.xyz;", + " gl_Position = projectionMatrix * mvPosition;", + " vOpacity = opacity;", + " vLinearDepth = -mvPosition.z;", + " vDepth = mvPosition.z / gl_Position.w;", + " vNormal = normalMatrix * normal;", + "", + "", + " // ---------------------", + " // POINT COLOR", + " // ---------------------", + " ", + " #ifdef color_type_rgb", + " vColor = color;", + " #elif defined color_type_height", + " vec4 world = modelMatrix * vec4( position, 1.0 );", + " float w = (world.y - heightMin) / (heightMax-heightMin);", + " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;", + " #elif defined color_type_depth", + " float d = -mvPosition.z ;", + " vColor = vec3(d, vDepth, 0.0);", + " #elif defined color_type_intensity", + " float w = (intensity - intensityMin) / (intensityMax - intensityMin);", + " vColor = vec3(w, w, w);", + " #elif defined color_type_intensity_gradient", + " float w = (intensity - intensityMin) / intensityMax;", + " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;", + " #elif defined color_type_color", + " vColor = uColor;", + " #elif defined color_type_tree_depth", + " float depth = getLocalTreeDepth();", + " float w = depth / 10.0;", + " vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;", + " #elif defined color_type_point_index", + " vColor = indices.rgb;", + " #elif defined color_type_classification", + " float c = mod(classification, 16.0);", + " vec2 uv = vec2(c / 255.0, 0.5);", + " vColor = texture2D(classificationLUT, uv).rgb;", + " #elif defined color_type_return_number", + " float w = (returnNumber - 1.0) / 4.0 + 0.1;", + " vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb;", + " #elif defined color_type_source", + " float w = mod(pointSourceID, 10.0) / 10.0;", + " vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb;", + " #elif defined color_type_normal", + " vColor = (modelMatrix * vec4(normal, 0.0)).xyz;", + " #elif defined color_type_phong", + " vColor = color;", + " #endif", + " ", + " //if(vNormal.z < 0.0){", + " // gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);", + " //}", + " ", + " // ---------------------", + " // POINT SIZE", + " // ---------------------", + " float pointSize = 1.0;", + " ", + " float projFactor = 1.0 / tan(fov / 2.0);", + " projFactor /= vViewPosition.z;", + " projFactor *= screenHeight / 2.0;", + " float r = spacing * 1.5;", + " vRadius = r;", + " #if defined fixed_point_size", + " pointSize = size;", + " #elif defined attenuated_point_size", + " pointSize = size * projFactor;", + " #elif defined adaptive_point_size", + " float worldSpaceSize = size * r / getPointSizeAttenuation();", + " pointSize = worldSpaceSize * projFactor;", + " #endif", + "", + " pointSize = max(minSize, pointSize);", + " pointSize = min(maxSize, pointSize);", + " ", + " vRadius = pointSize / projFactor;", + " ", + " gl_PointSize = pointSize;", + " ", + " ", + " // ---------------------", + " // CLIPPING", + " // ---------------------", + " ", + " #if defined use_clip_box", + " bool insideAny = false;", + " for(int i = 0; i < clip_box_count; i++){", + " vec4 clipPosition = clipBoxes[i] * modelMatrix * vec4( position, 1.0 );", + " bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5;", + " inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5;", + " inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5;", + " insideAny = insideAny || inside;", + " }", + " if(!insideAny){", + " ", + " #if defined clip_outside", + " gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);", + " #elif defined clip_highlight_inside && !defined(color_type_depth)", + " float c = (vColor.r + vColor.g + vColor.b) / 6.0;", + " #endif", + " }else{", + " #if defined clip_highlight_inside", + " vColor.r += 0.5;", + " #endif", + " }", + " ", + " #endif", + " ", + "}", + "", +].join("\n"); + +Potree.Shaders["pointcloud.fs"] = [ + "", + "#if defined use_interpolation", + " #extension GL_EXT_frag_depth : enable", + "#endif", + "", + "", + "// the following is an incomplete list of attributes, uniforms and defines", + "// which are automatically added through the THREE.ShaderMaterial", + "", + "// #define USE_COLOR", + "// ", + "// uniform mat4 viewMatrix;", + "// uniform vec3 cameraPosition;", + "", + "", + "uniform mat4 projectionMatrix;", + "uniform float opacity;", + "", + "", + "#if defined(color_type_phong)", + "", + " uniform vec3 diffuse;", + " uniform vec3 ambient;", + " uniform vec3 emissive;", + " uniform vec3 specular;", + " uniform float shininess;", + " uniform vec3 ambientLightColor;", + "", + " #if MAX_POINT_LIGHTS > 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"); + diff --git a/build/workers/BinaryDecoderWorker.js b/build/workers/BinaryDecoderWorker.js index f71b210a..3e325082 100644 --- a/build/workers/BinaryDecoderWorker.js +++ b/build/workers/BinaryDecoderWorker.js @@ -1 +1 @@ -Potree.workers.binaryDecoder = new Potree.WorkerManager(atob("DQovLyBodHRwOi8vanNwZXJmLmNvbS91aW50OGFycmF5LXZzLWRhdGF2aWV3My8zDQpmdW5jdGlvbiBDdXN0b21WaWV3KGJ1ZmZlcikgew0KCXRoaXMuYnVmZmVyID0gYnVmZmVyOw0KCXRoaXMudTggPSBuZXcgVWludDhBcnJheShidWZmZXIpOw0KCQ0KCXZhciB0bXAgPSBuZXcgQXJyYXlCdWZmZXIoNCk7DQoJdmFyIHRtcGYgPSBuZXcgRmxvYXQzMkFycmF5KHRtcCk7DQoJdmFyIHRtcHU4ID0gbmV3IFVpbnQ4QXJyYXkodG1wKTsNCgkNCgl0aGlzLmdldFVpbnQzMiA9IGZ1bmN0aW9uIChpKSB7DQoJCXJldHVybiAodGhpcy51OFtpKzNdIDw8IDI0KSB8ICh0aGlzLnU4W2krMl0gPDwgMTYpIHwgKHRoaXMudThbaSsxXSA8PCA4KSB8IHRoaXMudThbaV07DQoJfQ0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RoaXMuYXR0cmlidXRlcyl7CgkJdmFyIHBvaW50QXR0cmlidXRlID0gdGhpcy5hdHRyaWJ1dGVzW25hbWVdOwoJCWlmKHBvaW50QXR0cmlidXRlLm5hbWUgPT09IFBvaW50QXR0cmlidXRlTmFtZXMuQ09MT1JfUEFDS0VEKXsKCQkJcmV0dXJuIHRydWU7CgkJfQoJfQoJCglyZXR1cm4gZmFsc2U7Cn07CgpQb2ludEF0dHJpYnV0ZXMucHJvdG90eXBlLmhhc05vcm1hbHMgPSBmdW5jdGlvbigpewoJZm9yKHZhciBuYW1lIGluIHRoaXMuYXR0cmlidXRlcyl7CgkJdmFyIHBvaW50QXR0cmlidXRlID0gdGhpcy5hdHRyaWJ1dGVzW25hbWVdOwoJCWlmKHBvaW50QXR0cmlidXRlID09PSBQb2ludEF0dHJpYnV0ZS5OT1JNQUxfU1BIRVJFTUFQUEVEIHx8IHBvaW50QXR0cmlidXRlID09PSBQb2ludEF0dHJpYnV0ZS5OT1JNQUxfRkxPQVRTKXsKCQkJcmV0dXJuIHRydWU7CgkJfQoJfQoJCglyZXR1cm4gZmFsc2U7Cn07CgoK")); \ No newline at end of file diff --git a/docs/build.md b/docs/build.md index 9002f14a..baa8b216 100644 --- a/docs/build.md +++ b/docs/build.md @@ -13,4 +13,6 @@ Setting up gulp: ## Usage - gulp scripts // creates single script files in build/js + gulp build + +This will create a single build/js/potree.js file \ No newline at end of file diff --git a/docs/scripting.md b/docs/scripting.md index 5ac08036..5f1aba07 100644 --- a/docs/scripting.md +++ b/docs/scripting.md @@ -3,34 +3,104 @@ If you're missing some functionality in the interface, you can still achieve certain things by using your browsers developer tools as a scripting console. Open the developer tools with ctrl + shift + i, paste code into the console and execute it. +## Creating a height profile + +A height profile can be created with code as follows: + +``` +var p = new Potree.HeightProfile(); +p.addMarker(new THREE.Vector3(-100,0,0)); +p.addMarker(new THREE.Vector3(100,0,0)); +p.addMarker(new THREE.Vector3(100,0,100)); +p.addMarker(new THREE.Vector3(-100,0,100)); +p.setWidth(5); +profileTool.addProfile(p); +``` + +This will create a profile with 4 points / 3 segments. + +With this method, the height of the markers is not necessarly aligned with the point +cloud. Height markers can be removed with + +``` +p.modifiable = false; +``` + +The positions can still be modified programmatically through + +``` +var markerIndex = 0; +var position = new THREE.Vector3(10, 10, 0); +p.setPosition(markerIndex, position); +``` + +In order to remove a marker, call + +``` +p.removeMarker(index); +``` + + ## Get points inside height profile Use this to get a list of points inside the profile. -Right now, an array of point coordinates will be returned. -In a future version, all point attributes (intensity, classification, ...) -will be returned. +Points are grouped in segments. ``` var maxOctreeDepth = 2; -var points = pointcloud.getPointsInProfile(profileTool.profiles[0], maxOctreeDepth); +var segments = pointcloud.getPointsInProfile(profileTool.profiles[0], maxOctreeDepth); ``` The following code will create a sphere at each point location in the profile: ``` var maxOctreeDepth = 2; -var points = pointcloud.getPointsInProfile(profileTool.profiles[0], maxOctreeDepth); +var segments = pointcloud.getPointsInProfile(profileTool.profiles[0], maxOctreeDepth); var sg = new THREE.SphereGeometry(1, 8, 8); -for(var i = 0; i < points.length; i++){ - var sphere = new THREE.Mesh(sg); - sphere.position.copy(points[i]); - scene.add(sphere); +for(var i = 0; i < segments.length; i++){ + var segment = segments[i]; + for(var j = 0; j < segment.points.numPoints; j++){ + var position = segment.points.position[j]; + var sphere = new THREE.Mesh(sg); + sphere.position.copy(position); + scene.add(sphere); + } } ``` ![](./images/scripting_profile_spheres.png) +### Projecting a profile to 2D + +Each segment also contains a project() function which aligns the points along the x-axis. +This can be used, for example, to generate 2D height profile images. + +``` +position = segment.project(position); +``` + +Consecutive segments are placed next to each other. The following code +creates spheres on the x-axis projected point coordinates: + +``` +var maxOctreeDepth = 1; +var segments = pointcloud.getPointsInProfile(profileTool.profiles[0], maxOctreeDepth); + +var sg = new THREE.SphereGeometry(1, 8, 8); +for(var i = 0; i < segments.length; i++){ + var segment = segments[i]; + for(var j = 0; j < segment.points.numPoints; j++){ + var position = segment.points.position[j]; + position = segment.project(position); + var sphere = new THREE.Mesh(sg); + sphere.position.copy(position); + scene.add(sphere); + } +} +``` + + ## Set width of height profile The profile width can be changed either by holding ctrl while dragging one of the @@ -38,9 +108,6 @@ endpoints up and down or using this code: ``` profileTool.profiles[0].setWidth(2); -profileTool.profiles[0].update(); ``` -(The call to update() is required now but won't be in a future version.) - ![](./images/scripting_profile_width.png) diff --git a/examples/arena4d.html b/examples/arena4d.html new file mode 100644 index 00000000..e8f5258d --- /dev/null +++ b/examples/arena4d.html @@ -0,0 +1,1018 @@ + + + + Viewer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + +
+
+ Streaming points from an Arena4D Point Server + into potree
+
+
+ +
+
+
+ Enter URL of vpc file: +
+
+ + + + +
+
+ +
+
+
+ +
+ + + + + diff --git a/examples/js/ProgressBar.js b/examples/js/ProgressBar.js index 49459547..fb648533 100644 --- a/examples/js/ProgressBar.js +++ b/examples/js/ProgressBar.js @@ -15,7 +15,7 @@ function ProgressBar(){ this.element.innerHTML = ""; this.element.style.position = "fixed"; - this.element.style.bottom = "20px"; + this.element.style.bottom = "40px"; this.element.style.width = "200px"; this.element.style.marginLeft = "-100px"; this.element.style.left = "50%"; @@ -47,6 +47,7 @@ function ProgressBar(){ this.element.appendChild(this.elProgress); this.element.appendChild(this.elProgressMessage); + this.hide(); }; ProgressBar.prototype.hide = function(){ diff --git a/examples/lion.html b/examples/lion.html index 0e50e8c0..44dae59e 100644 --- a/examples/lion.html +++ b/examples/lion.html @@ -8,16 +8,16 @@