diff --git a/README.md b/README.md
index d93768cf..75280650 100644
--- a/README.md
+++ b/README.md
@@ -1,47 +1,50 @@
-# Potree - WebGL Pointcloud Viewer
+
+# README
+
+* [Getting Started](./docs/getting_started.md)
+* [Changelog](./docs/changelog.md)
+* [User Interface](./docs/user_interface.md)
+* [Converting Point Clouds](./docs/converting.md)
+* [FAQ](./docs/faq.md)
+* [Measuring](./docs/measuring.md)
+* [File Format](./docs/file_format.md)
## About
-Potree is a WebGL based point cloud viewer for large datasets.
-Thanks to WebGL, it runs in all major browsers without plugins.
+Potree is a free open-source WebGL based point cloud renderer for large point clouds.
+Similar to map software like Google Maps or OpenStreeMap, only data inside the visible area and up to a certain level of detail are loaded.
-Homepage: potree.org
-
+
-## Demos
+At the moment, this project is continued as master thesis under the [Harvest4D Project](https://harvest4d.org/)
-This video shows a point cloud of the St. Stephens Cathedral. It consists of ~700m points.
-
+Newest information and work in progress is usually available on [twitter](https://twitter.com/m_schuetz)
-Take a look at the [online showcase](http://potree.org/wp/demo/)
+General infos, downloads, showcase, etc. at [potree.org](http://potree.org/)
-## Getting Started
-1. Deploy potree on a webserver.
-2. Open one of the demos in the examples directory.
-Potree pages must run on a webserver so the url
-should be something like "localhost/potree/examples/lion.html". URLs starting with "file:///" will not work.
+## Downloads
-For more details, read the [Getting Started Section](./docs/getting_started.md)
+* [PotreeConverter windows binary (2014.12.30)](http://potree.org/downloads/PotreeConverter/PotreeConverter_2014.12.30.zip)
-## Convert Your Own Pointclouds
-Use the [PotreeConverter](https://github.com/potree/PotreeConverter) to convert your own point clouds into the potree format.
+## Showcase
-## Changelog
-Take a look at the changelog to get an overview of new features and possible changes to the usage:
-[docs/changelog.md](./docs/changelog.md)
+Take a look at the [potree showcase](http://potree.org/wp/demo/) for some live examples.
## Compatibility
| Browser | OS | Result |
| -------------------- |:-------:|:-------------:|
-| Chrome 32 | Win7 | works |
-| Firefox 26 | Win7 | works |
-| Opera 19 | Win7 | works |
-| Internet Explorer 11 | Win7 | technically works, if you don't expect performance |
-| Safari | Mac | works |
+| Chrome 39 | Win7 | works |
+| Firefox 34 | Win7 | works |
+| Internet Explorer 11 | Win7 | partially works; performance issues |
| Firefox | Android | partially works, GUI and stability issues |
| Opera | Android | partially works, GUI and stabilty issues and slow |
-## License
-Potree is available under the FreeBSD license.
+## Credits
+
+* The multi-res-octree algorithms used by this viewer were developed at the Vienna University of Technology by Michael Wimmer and Claus Scheiblauer as part of the [Scanopy Project](http://www.cg.tuwien.ac.at/research/projects/Scanopy/).
+* [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.
diff --git a/build/js/potree.js b/build/js/potree.js
index 5b494676..b23d2575 100644
--- a/build/js/potree.js
+++ b/build/js/potree.js
@@ -64,54 +64,93 @@ Potree.WorkerManager.fromUrls = function(urls){
return new Potree.WorkerManager(code);
}
-THREE.PerspectiveCamera.prototype.zoomTo = function(node, factor){
- if(factor === undefined){
- factor = 1;
- }
- node.updateMatrixWorld();
- this.updateMatrix();
- this.updateMatrixWorld();
+THREE.PerspectiveCamera.prototype.zoomTo = function( node, factor ){
+
+ if ( !node.geometry && !node.boundingSphere) {
- var box = Potree.utils.computeTransformedBoundingBox(node.boundingBox, node.matrixWorld);
- var dir = new THREE.Vector3(0, 0, -1).applyQuaternion(this.quaternion);
- var pos = box.center().sub(dir);
+ return;
- var ps = [
- new THREE.Vector3(box.min.x, box.min.y, box.min.z),
- new THREE.Vector3(box.min.x, box.min.y, box.min.z),
- new THREE.Vector3(box.max.x, box.min.y, box.min.z),
- new THREE.Vector3(box.min.x, box.max.y, box.min.z),
- new THREE.Vector3(box.min.x, box.min.y, box.max.z),
- new THREE.Vector3(box.min.x, box.max.y, box.max.z),
- new THREE.Vector3(box.max.x, box.max.y, box.min.z),
- new THREE.Vector3(box.max.x, box.min.y, box.max.z),
- new THREE.Vector3(box.max.x, box.max.y, box.max.z)
- ];
-
- var frustum = new THREE.Frustum();
- frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse));
-
- var max = Number.MIN_VALUE;
- for(var i = 0; i < ps.length; i++){
- var p = ps[i];
-
- var distance = Number.MIN_VALUE;
- // iterate through left, right, top and bottom planes
- for(var j = 0; j < frustum.planes.length-2; j++){
- var plane = frustum.planes[j];
- var ray = new THREE.Ray(p, dir);
- var dI = ray.distanceToPlaneWithNegative(plane);
- distance = Math.max(distance, dI);
- }
- max = Math.max(max, distance);
}
- var offset = dir.clone().multiplyScalar(-max);
- offset.multiplyScalar(factor);
- pos.add(offset);
- this.position.copy(pos);
-}
+ if ( node.geometry && node.geometry.boundingSphere === null ) {
+
+ node.geometry.computeBoundingSphere();
+
+ }
+
+ node.updateMatrixWorld();
+
+ var _factor = factor || 1;
+ var bs = node.boundingSphere || node.geometry.boundingSphere;
+ bs = bs.clone().applyMatrix4(node.matrixWorld);
+ var radius = bs.radius;
+ var fovr = this.fov * Math.PI / 180;
+
+ if( this.aspect < 1 ){
+
+ fovr = fovr * this.aspect;
+
+ }
+
+ var distanceFactor = Math.abs( radius / Math.sin( fovr / 2 ) ) * _factor ;
+
+ var dir = new THREE.Vector3( 0, 0, -1 ).applyQuaternion( this.quaternion );
+ var offset = dir.multiplyScalar( -distanceFactor );
+ this.position.copy(bs.center.clone().add( offset ));
+
+};
+
+
+
+//THREE.PerspectiveCamera.prototype.zoomTo = function(node, factor){
+// if(factor === undefined){
+// factor = 1;
+// }
+//
+// node.updateMatrixWorld();
+// this.updateMatrix();
+// this.updateMatrixWorld();
+//
+// var box = Potree.utils.computeTransformedBoundingBox(node.boundingBox, node.matrixWorld);
+// var dir = new THREE.Vector3(0, 0, -1).applyQuaternion(this.quaternion);
+// var pos = box.center().sub(dir);
+//
+// var ps = [
+// new THREE.Vector3(box.min.x, box.min.y, box.min.z),
+// new THREE.Vector3(box.min.x, box.min.y, box.min.z),
+// new THREE.Vector3(box.max.x, box.min.y, box.min.z),
+// new THREE.Vector3(box.min.x, box.max.y, box.min.z),
+// new THREE.Vector3(box.min.x, box.min.y, box.max.z),
+// new THREE.Vector3(box.min.x, box.max.y, box.max.z),
+// new THREE.Vector3(box.max.x, box.max.y, box.min.z),
+// new THREE.Vector3(box.max.x, box.min.y, box.max.z),
+// new THREE.Vector3(box.max.x, box.max.y, box.max.z)
+// ];
+//
+// var frustum = new THREE.Frustum();
+// frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse));
+//
+// var max = Number.MIN_VALUE;
+// for(var i = 0; i < ps.length; i++){
+// var p = ps[i];
+//
+// var distance = Number.MIN_VALUE;
+// // iterate through left, right, top and bottom planes
+// for(var j = 0; j < frustum.planes.length-2; j++){
+// var plane = frustum.planes[j];
+// var ray = new THREE.Ray(p, dir);
+// var dI = ray.distanceToPlaneWithNegative(plane);
+// distance = Math.max(distance, dI);
+// }
+// max = Math.max(max, distance);
+// }
+// var offset = dir.clone().multiplyScalar(-max);
+// offset.multiplyScalar(factor);
+// pos.add(offset);
+// this.position.copy(pos);
+//
+//}
THREE.Ray.prototype.distanceToPlaneWithNegative = function ( plane ) {
var denominator = plane.normal.dot( this.direction );
if ( denominator == 0 ) {
@@ -172,21 +211,33 @@ POCLoader.load = function load(url, callback) {
var min = new THREE.Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
var max = new THREE.Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
var boundingBox = new THREE.Box3(min, max);
+ var tightBoundingBox = boundingBox.clone();
+
+ if(fMno.tightBoundingBox){
+ tightBoundingBox.min.copy(new THREE.Vector3(fMno.tightBoundingBox.lx, fMno.tightBoundingBox.ly, fMno.tightBoundingBox.lz));
+ tightBoundingBox.max.copy(new THREE.Vector3(fMno.tightBoundingBox.ux, fMno.tightBoundingBox.uy, fMno.tightBoundingBox.uz));
+ }
var offset = new THREE.Vector3(0,0,0);
offset.set(-min.x, -min.y, -min.z);
+
boundingBox.min.add(offset);
boundingBox.max.add(offset);
+ tightBoundingBox.min.add(offset);
+ tightBoundingBox.max.add(offset);
+
pco.boundingBox = boundingBox;
+ pco.tightBoundingBox = tightBoundingBox;
pco.boundingSphere = boundingBox.getBoundingSphere();
+ pco.tightBoundingSphere = tightBoundingBox.getBoundingSphere();
pco.offset = offset;
if(fMno.pointAttributes === "LAS"){
pco.loader = new Potree.LasLazLoader(fMno.version);
}else if(fMno.pointAttributes === "LAZ"){
pco.loader = new Potree.LasLazLoader(fMno.version);
}else{
- pco.loader = new Potree.BinaryLoader(fMno.version);
+ pco.loader = new Potree.BinaryLoader(fMno.version, boundingBox, fMno.scale);
}
var nodes = {};
@@ -443,12 +494,15 @@ PointAttributes.prototype.hasNormals = function(){
-Potree.BinaryLoader = function(version){
+Potree.BinaryLoader = function(version, boundingBox, scale){
if(typeof(version) === "string"){
this.version = new Potree.Version(version);
}else{
this.version = version;
}
+
+ this.boundingBox = boundingBox;
+ this.scale = scale;
};
Potree.BinaryLoader.prototype.newerVersion = function(version){
@@ -500,14 +554,21 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){
var color = new THREE.Color();
var fView = new Float32Array(buffer);
+ var iView = new Int32Array(buffer);
var uiView = new Uint8Array(buffer);
var iIndices = new Uint32Array(indices);
for(var i = 0; i < numPoints; i++){
- positions[3*i+0] = fView[4*i+0] + node.pcoGeometry.offset.x;
- positions[3*i+1] = fView[4*i+1] + node.pcoGeometry.offset.y;
- positions[3*i+2] = fView[4*i+2] + node.pcoGeometry.offset.z;
+ if(this.version.newerThan("1.3")){
+ positions[3*i+0] = (iView[4*i+0] * this.scale) + node.boundingBox.min.x;
+ positions[3*i+1] = (iView[4*i+1] * this.scale) + node.boundingBox.min.y;
+ positions[3*i+2] = (iView[4*i+2] * this.scale) + node.boundingBox.min.z;
+ }else{
+ positions[3*i+0] = fView[4*i+0] + node.pcoGeometry.offset.x;
+ positions[3*i+1] = fView[4*i+1] + node.pcoGeometry.offset.y;
+ positions[3*i+2] = fView[4*i+2] + node.pcoGeometry.offset.z;
+ }
color.setRGB(uiView[16*i+12], uiView[16*i+13], uiView[16*i+14]);
colors[3*i+0] = color.r / 255;
@@ -783,6 +844,12 @@ Potree.PointColorType = {
SOURCE: 10
};
+Potree.ClipMode = {
+ DISABLED: 0,
+ CLIP_OUTSIDE: 1,
+ HIGHLIGHT_INSIDE: 2
+};
+
Potree.PointCloudMaterial = function(parameters){
parameters = parameters || {};
@@ -800,6 +867,12 @@ Potree.PointCloudMaterial = function(parameters){
this._interpolate = false;
this._pointColorType = Potree.PointColorType.RGB;
this._octreeLevels = 6.0;
+ this._useClipBox = false;
+ this.numClipBoxes = 0;
+ this._clipMode = Potree.ClipMode.DISABLED;
+ this._weighted = false;
+ this._blendDepth = 0.1;
+ this._depthMap;
this.gradientTexture = Potree.PointCloudMaterial.generateGradient();
@@ -822,7 +895,10 @@ Potree.PointCloudMaterial = function(parameters){
intensityMax: { type: "f", value: 1.0 },
visibleNodes: { type: "t", value: this.visibleNodesTexture },
pcIndex: { type: "f", value: 0 },
- gradient: {type: "t", value: this.gradientTexture},
+ gradient: { type: "t", value: this.gradientTexture },
+ clipBoxes: { type: "Matrix4fv", value: [] },
+ blendDepth: { type: "f", value: this._blendDepth },
+ depthMap: { type: "t", value: null },
};
@@ -863,6 +939,13 @@ Potree.PointCloudMaterial.prototype.updateShaderSource = function(){
fragmentShader: this.getDefines() + Potree.PointCloudMaterial.fs_points_rgb.join("\n")
});
+ if(this.depthMap){
+ this.uniforms.depthMap.value = this.depthMap;
+ this.setValues({
+ depthMap: this.depthMap,
+ });
+ }
+
if(this.opacity === 1.0){
this.setValues({
blending: THREE.NoBlending,
@@ -882,6 +965,18 @@ Potree.PointCloudMaterial.prototype.updateShaderSource = function(){
//});
}
+ if(this.weighted){
+ this.setValues({
+ blending: THREE.AdditiveBlending,
+ transparent: true,
+ depthTest: true,
+ depthWrite: false
+ });
+ }
+
+
+
+
this.needsUpdate = true;
};
@@ -931,10 +1026,46 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){
}else if(this._pointColorType === Potree.PointColorType.SOURCE){
defines += "#define color_type_source\n";
}
+
+ if(this.clipMode === Potree.ClipMode.DISABLED){
+ defines += "#define clip_disabled\n";
+ }else if(this.clipMode === Potree.ClipMode.CLIP_OUTSIDE){
+ defines += "#define clip_outside\n";
+ }else if(this.clipMode === Potree.ClipMode.HIGHLIGHT_INSIDE){
+ defines += "#define clip_highlight_inside\n";
+ }
+
+ if(this.weighted){
+ defines += "#define weighted_splats\n";
+ }
+
+ if(this.numClipBoxes > 0){
+ defines += "#define use_clip_box\n";
+ defines += "#define clip_box_count " + this.numClipBoxes + "\n";
+ }
return defines;
};
+Potree.PointCloudMaterial.prototype.setClipBoxes = function(clipBoxes){
+ var numBoxes = clipBoxes.length;
+ this.numClipBoxes = numBoxes;
+
+ 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++){
+ var box = clipBoxes[i];
+
+ this.uniforms.clipBoxes.value.set(box.elements, 16*i);
+ }
+
+
+};
+
Object.defineProperty(Potree.PointCloudMaterial.prototype, "spacing", {
get: function(){
return this.uniforms.spacing.value;
@@ -947,6 +1078,42 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "spacing", {
}
});
+Object.defineProperty(Potree.PointCloudMaterial.prototype, "blendDepth", {
+ get: function(){
+ return this.uniforms.blendDepth.value;
+ },
+ set: function(value){
+ if(this.uniforms.blendDepth.value !== value){
+ this.uniforms.blendDepth.value = value;
+ //this.updateShaderSource();
+ }
+ }
+});
+
+Object.defineProperty(Potree.PointCloudMaterial.prototype, "useClipBox", {
+ get: function(){
+ return this._useClipBox;
+ },
+ set: function(value){
+ if(this._useClipBox !== value){
+ this._useClipBox = value;
+ this.updateShaderSource();
+ }
+ }
+});
+
+Object.defineProperty(Potree.PointCloudMaterial.prototype, "weighted", {
+ get: function(){
+ return this._weighted;
+ },
+ set: function(value){
+ if(this._weighted !== value){
+ this._weighted = value;
+ this.updateShaderSource();
+ }
+ }
+});
+
Object.defineProperty(Potree.PointCloudMaterial.prototype, "fov", {
get: function(){
return this.uniforms.fov.value;
@@ -1043,6 +1210,18 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "pointColorType", {
}
});
+Object.defineProperty(Potree.PointCloudMaterial.prototype, "depthMap", {
+ get: function(){
+ return this._depthMap;
+ },
+ set: function(value){
+ if(this._depthMap !== value){
+ this._depthMap = value;
+ this.updateShaderSource();
+ }
+ }
+});
+
Object.defineProperty(Potree.PointCloudMaterial.prototype, "pointSizeType", {
get: function(){
return this._pointSizeType;
@@ -1055,6 +1234,18 @@ Object.defineProperty(Potree.PointCloudMaterial.prototype, "pointSizeType", {
}
});
+Object.defineProperty(Potree.PointCloudMaterial.prototype, "clipMode", {
+ get: function(){
+ return this._clipMode;
+ },
+ set: function(value){
+ if(this._clipMode !== value){
+ this._clipMode = value;
+ this.updateShaderSource();
+ }
+ }
+});
+
Object.defineProperty(Potree.PointCloudMaterial.prototype, "interpolate", {
get: function(){
return this._interpolate;
@@ -1188,15 +1379,15 @@ Potree.PointCloudMaterial.generateGradient = function() {
}
Potree.PointCloudMaterial.vs_points = [
- "precision mediump float; ",
- "precision mediump int; ",
+ "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 float classification; ",
+ "attribute float returnNumber; ",
+ "attribute float pointSourceID; ",
"attribute vec4 indices; ",
" ",
"uniform mat4 modelMatrix; ",
@@ -1205,12 +1396,17 @@ Potree.PointCloudMaterial.vs_points = [
"uniform mat4 viewMatrix; ",
"uniform mat3 normalMatrix; ",
"uniform vec3 cameraPosition; ",
- "uniform float screenWidth; ",
- "uniform float screenHeight; ",
- "uniform float fov; ",
- "uniform float spacing; ",
- "uniform float near; ",
- "uniform float far; ",
+ "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; ",
@@ -1221,12 +1417,17 @@ Potree.PointCloudMaterial.vs_points = [
"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) ",
@@ -1326,7 +1527,13 @@ Potree.PointCloudMaterial.vs_points = [
" ",
" 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 ",
" ",
@@ -1338,7 +1545,8 @@ Potree.PointCloudMaterial.vs_points = [
" ",
" vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; ",
" #elif defined color_type_depth ",
- " vColor = vec3(1.0, 1.0, 1.0) * gl_Position.w * 0.0001; ",
+ " float d = -mvPosition.z ; ",
+ " vColor = vec3(d, vDepth, 0.0); ",
" #elif defined color_type_intensity ",
" float w = (intensity - intensityMin) / intensityMax; ",
" vColor = vec3(w, w, w); ",
@@ -1365,6 +1573,7 @@ Potree.PointCloudMaterial.vs_points = [
" #endif ",
" ",
" ",
+ " ",
" // ",
" // POINT SIZE TYPES ",
" // ",
@@ -1385,6 +1594,33 @@ Potree.PointCloudMaterial.vs_points = [
" ",
" 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 ",
+ " ",
" ",
"} "];
@@ -1393,18 +1629,25 @@ Potree.PointCloudMaterial.fs_points_rgb = [
" #extension GL_EXT_frag_depth : enable ",
"#endif ",
" ",
- "precision highp float; ",
- "precision highp int; ",
+ "precision mediump float; ",
+ "precision mediump int; ",
" ",
- "uniform float opacity; ",
+ "//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) ",
+ " #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); ",
@@ -1413,6 +1656,15 @@ Potree.PointCloudMaterial.fs_points_rgb = [
" 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; ",
@@ -1422,9 +1674,18 @@ Potree.PointCloudMaterial.fs_points_rgb = [
" #if defined color_type_point_index ",
" gl_FragColor = vec4(vColor, pcIndex / 255.0); ",
" #else ",
- " gl_FragColor = vec4(vColor, opacity); ",
+ " 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 ",
+ " ",
+ " ",
+ " ",
"} "];
@@ -1967,8 +2228,10 @@ Potree.PointCloudOctree = function(geometry, material){
Potree.PointCloudOctree.lru = Potree.PointCloudOctree.lru || new LRU();
this.pcoGeometry = geometry;
- this.boundingBox = this.pcoGeometry.root.boundingBox;
+ 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.level = 0;
@@ -1979,6 +2242,7 @@ Potree.PointCloudOctree = function(geometry, material){
this.LODFalloff = 1.3;
this.LOD = 4;
this.showBoundingBox = false;
+ this.boundingBoxNodes = [];
this.loadQueue = [];
this.visibleBounds = new THREE.Box3();
this.profileRequests = [];
@@ -2009,6 +2273,10 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){
profileRequest.loadQueue = [];
}
+ for(var i = 0; i < this.boundingBoxNodes.length; i++){
+ this.boundingBoxNodes[i].visible = false;
+ }
+
this.loadQueue = [];
this.visibleNodes = [];
this.numVisibleNodes = 0;
@@ -2051,11 +2319,17 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){
this.maxLevel = Math.max(node.level, this.maxLevel);
}
- //if(!node.boundingBoxNode){
- // var boxHelper = new THREE.BoxHelper(node);
- // scene.add(boxHelper);
- // node.boundingBoxNode = boxHelper;
- //}
+ if(this.showBoundingBox && !node.boundingBoxNode){
+ var boxHelper = new THREE.BoxHelper(node);
+ scene.add(boxHelper);
+ this.boundingBoxNodes.push(boxHelper);
+ node.boundingBoxNode = boxHelper;
+ }else if(this.showBoundingBox){
+ node.boundingBoxNode.visible = true;
+ node.boundingBoxNode.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.boundingBoxNode.matrix );
+ }else if(!this.showBoundingBox && node.boundingBoxNode){
+ node.boundingBoxNode.visible = false;
+ }
for(var i = 0; i < node.children.length; i++){
var child = node.children[i];
@@ -2184,7 +2458,7 @@ Potree.PointCloudOctree.prototype.update = function(camera, renderer){
this.hideDescendants(this.children[0]);
for(var i = 0; i < this.visibleNodes.length; i++){
- this.visibleNodes[i].node.visible = true
+ this.visibleNodes[i].node.visible = true;
}
if(this.material.pointSizeType){
@@ -2239,8 +2513,8 @@ Potree.PointCloudOctree.prototype.getVisibleGeometry = function(camera){
var insideFrustum = frustum.intersectsBox(box);
- var visible = insideFrustum; // && node.level <= 1;
- //visible = visible && "r2".indexOf(node.name) === 0;
+ var visible = insideFrustum; // && node.level <= 3;
+ //visible = visible && "r7".indexOf(node.name) === 0;
if(!visible){
continue;
@@ -2327,6 +2601,8 @@ Potree.PointCloudOctree.prototype.updateVisibilityTexture = function(){
}
+
+
// sort by level and index, e.g. r, r0, r3, r4, r01, r07, r30, ...
var sort = function(a, b){
var na = a.name;
@@ -2338,6 +2614,22 @@ Potree.PointCloudOctree.prototype.updateVisibilityTexture = function(){
};
visibleNodes.sort(sort);
+ //var r = [];
+ //for(var i = 0; i < visibleNodes.length; i++){
+ // var node = visibleNodes[i];
+ //
+ // if(node.level < 2){
+ // r.push(node);
+ // }else{
+ //
+ // ß0
+ //
+ // //if(node.numPoints > 5000){
+ // // r.push(node);
+ // //}
+ //}
+ //visibleNodes = r;
+
for(var i = 0; i < visibleNodes.length; i++){
var node = visibleNodes[i];
var children = [];
@@ -2370,7 +2662,7 @@ Potree.PointCloudOctree.prototype.updateVisibilityTexture = function(){
}
- this.material.uniforms.nodeSize.value = this.boundingBox.size().x;
+ this.material.uniforms.nodeSize.value = this.pcoGeometry.boundingBox.size().x;
texture.needsUpdate = true;
}
@@ -2498,6 +2790,20 @@ Potree.PointCloudOctree.prototype.getBoundingBoxWorld = function(){
return tBox;
}
+Potree.PointCloudOctree.prototype.getPointsInProfile = function(profile, maxDepth){
+ var points = [];
+ for(var i = 0; i < profile.points.length - 1; i++){
+ var start = profile.points[i];
+ var end = profile.points[i+1];
+ var ps = pointcloud.getProfile(start, end, profile.width, maxDepth);
+ for(var j = 0; j < ps.length; j++){
+ points.push(ps[j]);
+ }
+ }
+
+ return points;
+};
+
Potree.PointCloudOctree.prototype.getProfile = function(start, end, width, depth, callback){
if(callback !== undefined){
this.profileRequests.push(new Potree.ProfileRequest(start, end, width, depth, callback));
@@ -2954,6 +3260,45 @@ Potree.utils.createGrid = function createGrid(width, length, spacing, color){
return line;
}
+
+Potree.utils.createBackgroundTexture = function(width, height){
+
+ function gauss(x, y){
+ return (1 / (2 * Math.PI)) * Math.exp( - (x*x + y*y) / 2);
+ };
+
+ var map = THREE.ImageUtils.generateDataTexture( width, height, new THREE.Color() );
+ map.magFilter = THREE.NearestFilter;
+ var data = map.image.data;
+
+ //var data = new Uint8Array(width*height*4);
+ var chroma = [1, 1.5, 1.7];
+ var max = gauss(0, 0);
+
+ 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 d = gauss(2*u, 2*v) / max;
+ var r = (Math.random() + Math.random() + Math.random()) / 3;
+ r = (d * 0.5 + 0.5) * r * 0.03;
+ r = r * 0.4;
+
+ //d = Math.pow(d, 0.6);
+
+ data[3*i+0] = 255 * (d / 15 + 0.05 + r) * chroma[0];
+ data[3*i+1] = 255 * (d / 15 + 0.05 + r) * chroma[1];
+ data[3*i+2] = 255 * (d / 15 + 0.05 + r) * chroma[2];
+
+ //data[4*i+3] = 255;
+
+ }
+ }
+
+ return map;
+};
/**
* adapted from http://stemkoski.github.io/Three.js/Sprite-Text-Labels.html
*/
@@ -3088,6 +3433,517 @@ Potree.Version.prototype.newerThan = function(version){
};
+//
+// 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};
+ this.accuracy = 0.5;
+
+ var STATE = {
+ DEFAULT: 0,
+ PICKING: 1
+ };
+
+ var state = STATE.DEFAULT;
+
+ var sphereGeometry = new THREE.SphereGeometry(0.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( 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.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 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();
+
+ 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);
+
+ }
+ };
+
+ function onMouseMove(event){
+ scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
+ scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 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;
+
+ }
+ }
+ };
+
+ function onRightClick(event){
+ if(state == STATE.PICKING){
+ scope.activeMeasurement.remove(scope.activeMeasurement.points.length-1);
+
+ scope.measurements.push(scope.activeMeasurement);
+ scope.activeMeasurement = undefined;
+
+ state = STATE.DEFAULT;
+ scope.setEnabled(false);
+ }
+ }
+
+ function onMouseDown(event){
+ if(event.which === 1){
+
+ 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}
+ };
+
+ }
+
+ }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, {accuracy: scope.accuracy});
+
+ 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 = [];
+ for(var i = 0; i < this.measurements.length; i++){
+ measurements.push(this.measurements[i]);
+ }
+ if(this.activeMeasurement){
+ measurements.push(this.activeMeasurement);
+ }
+
+
+ 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);
+ }
+
+ 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 / 10);
+ var l = label.scale.length();
+ label.scale.multiplyScalar(w / l);
+ }
+
+ var wp = measurement.areaLabel.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
+ var w = Math.abs(wp.z / 8);
+ var l = measurement.areaLabel.scale.length();
+ measurement.areaLabel.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.AreaTool.prototype = Object.create( THREE.EventDispatcher.prototype );
+
+
Potree.MeasuringTool = function(scene, camera, renderer){
var scope = this;
@@ -3338,7 +4194,9 @@ Potree.MeasuringTool = function(scene, camera, renderer){
};
scope.dispatchEvent(event);
+
}
+ //event.stopImmediatePropagation();
};
function onMouseMove(event){
@@ -3443,6 +4301,8 @@ Potree.MeasuringTool = function(scene, camera, renderer){
mousePos: {x: scope.mouse.x, y: scope.mouse.y}
};
+ event.stopImmediatePropagation();
+
}
}else if(event.which === 3){
@@ -3596,137 +4456,613 @@ Potree.MeasuringTool = function(scene, camera, renderer){
Potree.MeasuringTool.prototype = Object.create( THREE.EventDispatcher.prototype );
-Potree.ProfileTool = function(width, height, depth){
+//
+// calculating area of a polygon:
+// http://www.mathopenref.com/coordpolygonarea2.html
+//
+//
+//
- THREE.Object3D.call( this );
-
- var boxGeometry = new THREE.BoxGeometry(1,1,1,1,1,1);
- var boxMaterial = new THREE.MeshBasicMaterial({color: 0xFF0000, transparent: true, opacity: 0.3});
+Potree.ProfileTool = function(scene, camera, renderer){
- this.profileFrustum = new THREE.Mesh(boxGeometry, boxMaterial);
- this.add(this.profileFrustum);
-
- this.camera = new THREE.OrthographicCamera( -width / 2, width / 2, height / 2, -height / 2, 1, 1 + depth );
- this.add(this.camera);
- this.setDimension(width, height, depth);
-
- this.rtProfile = new THREE.WebGLRenderTarget( 512, 512, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBFormat } );
-
- this.hudGeometry = new THREE.BoxGeometry(2,2,1);
- this.hudMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff, map: this.rtProfile } );
- this.hudMaterial.depthTest = false;
- this.hudElement = new THREE.Mesh(this.hudGeometry, this.hudMaterial);
- this.hudElement.scale.set(1,1,1);
- this.hudElement.position.set(0, 0, 0);
-
- //var lblMax = new Potree.TextSprite("max");
- //lblMax.scale.multiplyScalar(0.05);
- //this.hudElement.add(lblMax);
-
- var start = new THREE.Vector3(0,0,0);
- var end = new THREE.Vector3(10,0,0);
- this.setCoordinates(start, end);
-}
-
-Potree.ProfileTool.prototype = Object.create( THREE.Object3D.prototype );
-
-Potree.ProfileTool.prototype.setDimension = function(width, height, depth){
- this.profileFrustum.scale.set(width, height, depth);
- this.width = width;
- this.height = height;
- this.depth = depth;
-
- this.camera.left = -width / 2;
- this.camera.right = width / 2;
- this.camera.top = height / 2;
- this.camera.bottom = -height / 2;
- this.camera.updateProjectionMatrix();
-}
-
-Potree.ProfileTool.prototype.setOrientation = function(forward, side){
- var oldPosition = this.position.clone();
- this.position.add(forward);
- this.lookAt(oldPosition);
- this.position.copy(oldPosition);
-
- this.camera.position.copy(oldPosition.clone().add(forward));
- this.camera.lookAt(oldPosition);
-}
-
-Potree.ProfileTool.prototype.setCoordinates = function(start, end){
- var width = start.distanceTo(end);
- this.setDimension(width, this.height, this.depth);
-
- 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);
- this.position.set(0,0,0);
- this.lookAt(target);
- this.position.copy(center);
-
- this.start = start;
- this.end = end;
-}
-
-Potree.ProfileTool.prototype.render = function(renderer, scene){
- this.camera.matrixWorld.copy(this.matrixWorld);
-
- //TODO maybe we should store old sizes in a map instead of the objects
- scene.traverse(function(object){
- if(object instanceof Potree.PointCloudOctree){
- object.material.oldSize = object.material.size;
- object.material.size = 0;
- }
- });
-
-
- renderer.render(scene, this.camera, this.rtProfile, true);
-
-
- scene.traverse(function(object){
- if(object instanceof Potree.PointCloudOctree){
- object.material.size = object.material.oldSize;
- }
- });
-}
-
-
-
-
-
-
-
-
-
-Potree.TranslationTool = function(camera) {
- THREE.Object3D.call( this );
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;
+
+ var STATE = {
+ DEFAULT: 0,
+ INSERT: 1
+ };
+
+ var state = STATE.DEFAULT;
+
+ var sphereGeometry = new THREE.SphereGeometry(0.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( 0xffffff, 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 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);
- this.geometry = new THREE.Geometry();
- this.material = new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
+ // 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 = function(){
+
+ 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,
+ color: 0xff0000,
+ ambient: 0xaaaaaa,
+ depthTest: false,
+ depthWrite: false}
+ );
+
+ return sphereMaterial;
+ };
+
+
+ function onClick(event){
+
+ if(state === STATE.INSERT){
+ var I = getMousePointCloudIntersection();
+ if(I){
+ var pos = I.clone();
+
+ scope.activeProfile.addMarker(pos);
+
+ var event = {
+ type: 'newpoint',
+ position: pos.clone()
+ };
+ scope.dispatchEvent(event);
+
+ }
+ }
+ };
+
+ function onMouseMove(event){
+ scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
+ scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
+
+ if(scope.dragstart){
+
+ scope.dragstart.object.dispatchEvent({type: "mousedrag", event: event});
+
+ }else if(state == STATE.INSERT && scope.activeProfile){
+ var I = getMousePointCloudIntersection();
+
+ if(I){
+
+ var lastIndex = scope.activeProfile.points.length-1;
+ scope.activeProfile.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;
+
+ }
+ }
+ };
+
+ function onRightClick(event){
+ if(state == STATE.INSERT){
+ scope.finishInsertion();
+ }
+ }
+
+ function onMouseDown(event){
+ if(event.which === 1){
+
+ var I = getHoveredElement();
+
+ if(I){
+
+ var widthStart = null;
+ for(var i = 0; i < scope.profiles.length; i++){
+ var profile = scope.profiles[i];
+ for(var j = 0; j < profile.spheres.length; j++){
+ var sphere = profile.spheres[j];
+
+ if(sphere === I.object){
+ widthStart = profile.width;
+ }
+ }
+ }
+
+ scope.dragstart = {
+ object: I.object,
+ sceneClickPos: I.point,
+ sceneStartPos: scope.sceneRoot.position.clone(),
+ mousePos: {x: scope.mouse.x, y: scope.mouse.y},
+ widthStart: widthStart
+ };
+
+ }
+
+ }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 intersections = raycaster.intersectObjects(scope.profiles);
+
+ 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, {accuracy: scope.accuracy});
+
+ 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.startInsertion = function(args){
+ state = STATE.INSERT;
+
+ var args = args || {};
+ var clip = args.clip || false;
+ var width = args.width || 1.0;
+
+ this.activeProfile = new Profile();
+ this.activeProfile.clip = clip;
+ this.activeProfile.setWidth(width);
+ 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;
+ state = STATE.DEFAULT;
+ };
+
+ 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);
+ }
+ }
+
+ 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.sceneProfile, 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.ProfileTool.prototype = Object.create( THREE.EventDispatcher.prototype );
+
+
+Potree.TransformationTool = 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};
+ 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 = false;
+
+ this.hoveredElement = null;
this.STATE = {
DEFAULT: 0,
TRANSLATE_X: 1,
TRANSLATE_Y: 2,
- TRANSLATE_Z: 3
+ TRANSLATE_Z: 3,
+ SCALE_X: 1,
+ SCALE_Y: 2,
+ SCALE_Z: 3
};
this.parts = {
- ARROW_X : {name: "arrow_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.TRANSLATE_X},
- ARROW_Y : {name: "arrow_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.TRANSLATE_Y},
- ARROW_Z : {name: "arrow_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.TRANSLATE_Z}
+ ARROW_X : {name: "arrow_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.TRANSLATE_X},
+ ARROW_Z : {name: "arrow_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.TRANSLATE_Z},
+ ARROW_Y : {name: "arrow_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.TRANSLATE_Y},
+ SCALE_X : {name: "scale_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.SCALE_X},
+ SCALE_Z : {name: "scale_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.SCALE_Z},
+ SCALE_Y : {name: "scale_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.SCALE_Y},
+ ROTATE_X : {name: "rotate_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.ROTATE_X},
+ ROTATE_Z : {name: "rotate_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.ROTATE_Z},
+ ROTATE_Y : {name: "rotate_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.ROTATE_Y}
}
-
- this.translateStart;
-
- this.state = this.STATE.DEFAULT;
- this.highlighted;
- this.targets;
-
- this.build = function(){
+
+ this.buildTranslationNode = function(){
var arrowX = scope.createArrow(scope.parts.ARROW_X, scope.parts.ARROW_X.color);
arrowX.rotation.z = -Math.PI/2;
@@ -3735,36 +5071,94 @@ Potree.TranslationTool = function(camera) {
var arrowZ = scope.createArrow(scope.parts.ARROW_Z, scope.parts.ARROW_Z.color);
arrowZ.rotation.x = -Math.PI/2;
- scope.add(arrowX);
- scope.add(arrowY);
- scope.add(arrowZ);
-
-
- var boxXY = scope.createBox(new THREE.Color( 0xffff00 ));
- boxXY.scale.z = 0.02;
- boxXY.position.set(0.5, 0.5, 0);
-
- var boxXZ = scope.createBox(new THREE.Color( 0xff00ff ));
- boxXZ.scale.y = 0.02;
- boxXZ.position.set(0.5, 0, -0.5);
-
- var boxYZ = scope.createBox(new THREE.Color( 0x00ffff ));
- boxYZ.scale.x = 0.02;
- boxYZ.position.set(0, 0.5, -0.5);
-
- scope.add(boxXY);
- scope.add(boxXZ);
- scope.add(boxYZ);
-
-
- scope.parts.ARROW_X.object = arrowX;
- scope.parts.ARROW_Y.object = arrowY;
- scope.parts.ARROW_Z.object = arrowZ;
-
-
- scope.scale.multiplyScalar(5);
+ this.translationNode.add(arrowX);
+ this.translationNode.add(arrowY);
+ this.translationNode.add(arrowZ);
};
+ this.buildScaleNode = function(){
+ var xHandle = this.createScaleHandle(scope.parts.SCALE_X, 0xff0000);
+ xHandle.rotation.z = -Math.PI/2;
+
+ var yHandle = this.createScaleHandle(scope.parts.SCALE_Y, 0x00ff00);
+
+ var zHandle = this.createScaleHandle(scope.parts.SCALE_Z, 0x0000ff);
+ zHandle.rotation.x = -Math.PI/2;
+
+ this.scaleNode.add(xHandle);
+ this.scaleNode.add(yHandle);
+ this.scaleNode.add(zHandle);
+ }
+
+ this.buildRotationNode = function(){
+ var xHandle = this.createRotationCircle(scope.parts.ROTATE_X, 0xff0000);
+ xHandle.rotation.y = -Math.PI/2;
+
+ var yHandle = this.createRotationCircle(scope.parts.ROTATE_Y, 0x00ff00);
+
+ var zHandle = this.createRotationCircle(scope.parts.ROTATE_Z, 0x0000ff);
+ yHandle.rotation.x = -Math.PI/2;
+
+ this.rotationNode.add(xHandle);
+ this.rotationNode.add(yHandle);
+ this.rotationNode.add(zHandle);
+
+
+ var sg = new THREE.SphereGeometry(2.9, 24, 24);
+ var sphere = new THREE.Mesh(sg, new THREE.MeshBasicMaterial({color: 0xaaaaaa, transparent: true, opacity: 0.4}));
+
+ this.sceneRotation.add(sphere);
+
+ var moveEvent = function(event){
+ sphere.material.color.setHex(0x555555);
+ };
+
+ var leaveEvent = function(event){
+ sphere.material.color.setHex(0xaaaaaa);
+ };
+
+ var dragEvent = function(event){
+ event.event.stopImmediatePropagation();
+
+ var mouseStart = new THREE.Vector3(scope.dragstart.mousePos.x, scope.dragstart.mousePos.y, 0.1);
+ var mouseEnd = new THREE.Vector3(scope.mouse.x, scope.mouse.y, 0.1);
+ var mouseDiff = new THREE.Vector3().subVectors(mouseEnd, mouseStart);
+
+ var sceneStart = mouseStart.clone().unproject(scope.camera);
+ var sceneEnd = mouseEnd.clone().unproject(scope.camera);
+ var sceneDiff = new THREE.Vector3().subVectors(sceneEnd, sceneStart);
+ var sceneDir = sceneDiff.clone().normalize();
+ var toCamDir = new THREE.Vector3().subVectors(scope.camera.position, sceneStart).normalize();
+ var rotationAxis = toCamDir.clone().cross(sceneDir);
+ var rotationAmount = 6 * mouseDiff.length();
+
+ for(var i = 0; i < scope.targets.length; i++){
+ var target = scope.targets[i];
+ var startRotation = scope.dragstart.rotations[i];
+
+ target.rotation.copy(startRotation);
+
+ var q = new THREE.Quaternion();
+
+ q.setFromAxisAngle( rotationAxis, rotationAmount );
+ target.quaternion.multiplyQuaternions( q, target.quaternion );
+
+ }
+ };
+
+ var dropEvent = function(event){
+
+ };
+
+ sphere.addEventListener("mousemove", moveEvent);
+ sphere.addEventListener("mouseleave", leaveEvent);
+ sphere.addEventListener("mousedrag", dragEvent);
+ sphere.addEventListener("drop", dropEvent);
+
+ }
+
+
+
this.createBox = function(color){
var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
var boxMaterial = new THREE.MeshBasicMaterial({color: color, transparent: true, opacity: 0.5});
@@ -3773,15 +5167,236 @@ Potree.TranslationTool = function(camera) {
return box;
};
+ var sph1, sph2, sph3;
+
+ this.createRotationCircle = function(partID, color){
+ //var geometry = new THREE.TorusGeometry(3, 0.1, 12, 48);
+ //var material = new THREE.MeshBasicMaterial({color: color});
+ //
+ //var ring = new THREE.Mesh(geometry, material);
+
+ var vertices = [];
+ var segments = 128;
+ for(var i = 0; i <= segments; i++){
+ var u = (2 * Math.PI * i) / segments;
+ var x = 3 * Math.cos(u);
+ var y = 3 * Math.sin(u);
+
+ vertices.push(new THREE.Vector3(x, y, 0));
+ }
+ var geometry = new THREE.Geometry();
+ for(var i = 0; i < vertices.length; i++){
+ geometry.vertices.push(vertices[i]);
+ }
+ var material = new THREE.LineBasicMaterial({color: color});
+ var ring = new THREE.Line( geometry, material);
+ ring.mode = THREE.LineStrip;
+ ring.scale.set(1, 1, 1);
+ //this.rotationNode.add(ring);
+
+
+ var moveEvent = function(event){
+ material.color.setRGB(1, 1, 0);
+ };
+
+ var leaveEvent = function(event){
+ material.color.setHex(color);
+ };
+
+ var dragEvent = function(event){
+
+ event.event.stopImmediatePropagation();
+
+ var normal = new THREE.Vector3();
+ if(partID === scope.parts.ROTATE_X){
+ normal.x = 1;
+ }else if(partID === scope.parts.ROTATE_Y){
+ normal.y = 1;
+ }else if(partID === scope.parts.ROTATE_Z){
+ normal.z = -1;
+ }
+
+ var sceneClickPos = scope.dragstart.sceneClickPos.clone();
+ var sceneOrigin = scope.sceneRoot.position.clone();
+ var sceneNormal = sceneClickPos.clone().sub(sceneOrigin).normalize();
+
+ var screenClickPos = sceneClickPos.clone().project(scope.camera);
+ var screenOrigin = sceneOrigin.clone().project(scope.camera);
+ var screenNormal = screenClickPos.clone().sub(screenOrigin).normalize();
+ var screenTangent = new THREE.Vector3(screenNormal.y, screenNormal.x, 0);
+
+ 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 plane = new THREE.Plane().setFromNormalAndCoplanarPoint(normal, scope.sceneRoot.position);
+ var camOrigin = scope.camera.position;
+ var camDirection = new THREE.Vector3( 0, 0, -1 ).applyQuaternion( scope.camera.quaternion );
+ var direction = new THREE.Vector3( mouseEnd.x, mouseEnd.y, 0.5 ).unproject(scope.camera).sub( scope.camera.position ).normalize();
+ var ray = new THREE.Ray( camOrigin, direction);
+ var I = ray.intersectPlane(plane);
+
+ if(!I){
+ return;
+ }
+
+ sceneTargetNormal = I.clone().sub(sceneOrigin).normalize();
+
+ var angleToClick;
+ var angleToTarget;
+
+ if(partID === scope.parts.ROTATE_X){
+ angleToClick = 2 * Math.PI + Math.atan2(sceneNormal.y, -sceneNormal.z);
+ angleToTarget = 4 * Math.PI + Math.atan2(sceneTargetNormal.y, -sceneTargetNormal.z);
+ }else if(partID === scope.parts.ROTATE_Y){
+ angleToClick = 2 * Math.PI + Math.atan2(-sceneNormal.z, sceneNormal.x);
+ angleToTarget = 4 * Math.PI + Math.atan2(-sceneTargetNormal.z, sceneTargetNormal.x);
+ }else if(partID === scope.parts.ROTATE_Z){
+ angleToClick = 2 * Math.PI + Math.atan2(sceneNormal.x, sceneNormal.y);
+ angleToTarget = 4 * Math.PI + Math.atan2(sceneTargetNormal.x, sceneTargetNormal.y);
+ }
+
+ var diff = angleToTarget - angleToClick;
+
+ for(var i = 0; i < scope.targets.length; i++){
+ var target = scope.targets[i];
+ var startRotation = scope.dragstart.rotations[i];
+
+ target.rotation.copy(startRotation);
+
+ var q = new THREE.Quaternion();
+
+ q.setFromAxisAngle( normal, diff ); // axis must be normalized, angle in radians
+ target.quaternion.multiplyQuaternions( q, target.quaternion );
+
+ }
+
+
+
+
+ };
+
+ var dropEvent = function(event){
+
+ };
+
+ ring.addEventListener("mousemove", moveEvent);
+ ring.addEventListener("mouseleave", leaveEvent);
+ ring.addEventListener("mousedrag", dragEvent);
+ ring.addEventListener("drop", dropEvent);
+
+ return ring;
+ };
+
+ this.createScaleHandle = function(partID, color){
+ var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
+ var material = new THREE.MeshBasicMaterial({color: color, depthTest: false, depthWrite: false});
+
+ var box = new THREE.Mesh(boxGeometry, material);
+ box.scale.set(0.3, 0.3, 0.3);
+ box.position.set(0, 3, 0);
+
+ var shaftGeometry = new THREE.Geometry();
+ shaftGeometry.vertices.push(new THREE.Vector3(0, 0, 0));
+ shaftGeometry.vertices.push(new THREE.Vector3(0, 3, 0));
+ var shaftMaterial = new THREE.LineBasicMaterial({color: color, depthTest: false, depthWrite: false});
+ var shaft = new THREE.Line(shaftGeometry, shaftMaterial);
+
+ var handle = new THREE.Object3D();
+ handle.add(box);
+ handle.add(shaft);
+
+ handle.partID = partID;
+
+
+ var moveEvent = function(event){
+ shaftMaterial.color.setRGB(1, 1, 0);
+ material.color.setRGB(1, 1, 0);
+ };
+
+ var leaveEvent = function(event){
+ shaftMaterial.color.setHex(color);
+ material.color.setHex(color);
+ };
+
+ var dragEvent = function(event){
+
+ var sceneDirection = new THREE.Vector3();
+ if(partID === scope.parts.SCALE_X){
+ sceneDirection.x = 1;
+ }else if(partID === scope.parts.SCALE_Y){
+ sceneDirection.y = 1;
+ }else if(partID === scope.parts.SCALE_Z){
+ sceneDirection.z = -1;
+ }
+
+ var sceneClickPos = scope.dragstart.sceneClickPos.clone();
+ sceneClickPos.multiply(sceneDirection);
+ sceneClickPos.z *= -1;
+
+ var lineStart = scope.dragstart.sceneStartPos.clone().project(scope.camera);
+ var lineEnd = scope.dragstart.sceneStartPos.clone().add(sceneDirection).project(scope.camera);
+
+ var origin = lineStart.clone();
+ var screenDirection = lineEnd.clone().sub(lineStart);
+ screenDirection.normalize();
+
+ 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 directionDistance = new THREE.Vector3().subVectors(mouseEnd, mouseStart).dot(screenDirection);
+ var pointOnLine = screenDirection.clone().multiplyScalar(directionDistance).add(origin);
+
+ pointOnLine.unproject(scope.camera);
+
+ var diff = scope.sceneRoot.position.clone().sub(pointOnLine);
+ diff.multiply(new THREE.Vector3(-1, -1, 1)).addScalar(1);
+
+ for(var i = 0; i < scope.targets.length; i++){
+ var target = scope.targets[i];
+ var startScale = scope.dragstart.scales[i];
+ target.scale.copy(startScale).add(diff);
+ target.scale.x = Math.max(target.scale.x, 0.01);
+ target.scale.y = Math.max(target.scale.y, 0.01);
+ target.scale.z = Math.max(target.scale.z, 0.01);
+ }
+
+ event.event.stopImmediatePropagation();
+
+ };
+
+ var dropEvent = function(event){
+ material.color.set(color);
+ };
+
+ box.addEventListener("mousemove", moveEvent);
+ box.addEventListener("mouseleave", leaveEvent);
+ box.addEventListener("mousedrag", dragEvent);
+ box.addEventListener("drop", dropEvent);
+ shaft.addEventListener("mousemove", moveEvent);
+ shaft.addEventListener("mouseleave", leaveEvent);
+ shaft.addEventListener("mousedrag", dragEvent);
+ shaft.addEventListener("drop", dropEvent);
+
+ return handle;
+ };
+
this.createArrow = function(partID, color){
- var material = new THREE.MeshBasicMaterial({color: color});
+ var material = new THREE.MeshBasicMaterial({color: color, depthTest: false, depthWrite: false});
- var shaftGeometry = new THREE.CylinderGeometry(0.1, 0.1, 3, 10, 1, false);
- var shaftMatterial = material;
- var shaft = new THREE.Mesh(shaftGeometry, shaftMatterial);
- shaft.position.y = 1.5;
+ //var shaftGeometry = new THREE.CylinderGeometry(0.05, 0.05, 3, 10, 1, false);
+ //var shaftMaterial = material;
+ //var shaft = new THREE.Mesh(shaftGeometry, shaftMaterial);
+ //shaft.position.y = 1.5;
- var headGeometry = new THREE.CylinderGeometry(0, 0.3, 1, 10, 1, false);
+ var shaftGeometry = new THREE.Geometry();
+ shaftGeometry.vertices.push(new THREE.Vector3(0, 0, 0));
+ shaftGeometry.vertices.push(new THREE.Vector3(0, 3, 0));
+ var shaftMaterial = new THREE.LineBasicMaterial({color: color, depthTest: false, depthWrite: false});
+ var shaft = new THREE.Line(shaftGeometry, shaftMaterial);
+
+
+
+ var headGeometry = new THREE.CylinderGeometry(0, 0.2, 0.5, 10, 1, false);
var headMaterial = material;
var head = new THREE.Mesh(headGeometry, headMaterial);
head.position.y = 3;
@@ -3792,152 +5407,650 @@ Potree.TranslationTool = function(camera) {
arrow.partID = partID;
arrow.material = material;
+ var moveEvent = function(event){
+ headMaterial.color.setRGB(1, 1, 0);
+ shaftMaterial.color.setRGB(1, 1, 0);
+ };
+
+ var leaveEvent = function(event){
+ headMaterial.color.set(color);
+ shaftMaterial.color.set(color);
+ };
+
+ var dragEvent = function(event){
+
+ var sceneDirection = new THREE.Vector3();
+ if(partID === scope.parts.ARROW_X){
+ sceneDirection.x = 1;
+ }else if(partID === scope.parts.ARROW_Y){
+ sceneDirection.y = 1;
+ }else if(partID === scope.parts.ARROW_Z){
+ sceneDirection.z = -1;
+ }
+
+ var sceneClickPos = scope.dragstart.sceneClickPos.clone();
+ sceneClickPos.multiply(sceneDirection);
+ sceneClickPos.z *= -1;
+
+ //var lineStart = new THREE.Vector3();
+ //lineStart.x = scope.dragstart.mousePos.x;
+ //lineStart.y = scope.dragstart.mousePos.y;
+ var lineStart = scope.dragstart.sceneStartPos.clone().project(scope.camera);
+ var lineEnd = scope.dragstart.sceneStartPos.clone().add(sceneDirection).project(scope.camera);
+
+ var origin = lineStart.clone();
+ var screenDirection = lineEnd.clone().sub(lineStart);
+ screenDirection.normalize();
+
+
+
+ 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 htmlStart = mouseStart.clone().addScalar(1).multiplyScalar(0.5);
+ //htmlStart.x *= scope.domElement.clientWidth;
+ //htmlStart.y *= scope.domElement.clientHeight;
+ //
+ //var htmlEnd = mouseEnd.clone().addScalar(1).multiplyScalar(0.5);
+ //htmlEnd.x *= scope.domElement.clientWidth;
+ //htmlEnd.y *= scope.domElement.clientHeight;
+ //
+ //var el = document.getElementById("testDiv");
+ //el.style.left = htmlStart.x;
+ //el.style.width = htmlEnd.x - htmlStart.x;
+ //el.style.bottom = htmlStart.y;
+ //el.style.top = scope.domElement.clientHeight - htmlEnd.y;
+
+
+
+
+ //var directionDistance = new THREE.Vector3().subVectors(mouseEnd, origin).dot(screenDirection);
+ var directionDistance = new THREE.Vector3().subVectors(mouseEnd, mouseStart).dot(screenDirection);
+ var pointOnLine = screenDirection.clone().multiplyScalar(directionDistance).add(origin);
+
+ pointOnLine.unproject(scope.camera);
+
+ var diff = scope.sceneRoot.position.clone();
+ //scope.position.copy(pointOnLine);
+ var offset = sceneClickPos.clone().sub(scope.dragstart.sceneStartPos);
+ scope.sceneRoot.position.copy(pointOnLine);
+ //scope.sceneRoot.position.sub(offset);
+ diff.sub(scope.sceneRoot.position);
+
+ for(var i = 0; i < scope.targets.length; i++){
+ var target = scope.targets[i];
+ target.position.sub(diff);
+ }
+
+ //if(!sph1){
+ // var g = new THREE.SphereGeometry(0.2);
+ //
+ // var m1 = new THREE.MeshBasicMaterial({color: 0xff0000});
+ // var m2 = new THREE.MeshBasicMaterial({color: 0x00ff00});
+ // var m3 = new THREE.MeshBasicMaterial({color: 0x0000ff});
+ //
+ // sph1 = new THREE.Mesh(g, m1);
+ // sph2 = new THREE.Mesh(g, m2);
+ // sph3 = new THREE.Mesh(g, m3);
+ //
+ // scope.scene.add(sph1);
+ // scope.scene.add(sph2);
+ // scope.scene.add(sph3);
+ //}
+ //sph1.position.copy(scope.dragstart.sceneStartPos);
+ //sph2.position.copy(scope.dragstart.sceneClickPos);
+ //sph3.position.copy(pointOnLine);
+
+ event.event.stopImmediatePropagation();
+
+ };
+
+ var dropEvent = function(event){
+ shaftMaterial.color.set(color);
+ };
+
+ shaft.addEventListener("mousemove", moveEvent);
+ head.addEventListener("mousemove", moveEvent);
+
+ shaft.addEventListener("mouseleave", leaveEvent);
+ head.addEventListener("mouseleave", leaveEvent);
+
+ shaft.addEventListener("mousedrag", dragEvent);
+ head.addEventListener("mousedrag", dragEvent);
+
+ shaft.addEventListener("drop", dropEvent);
+ head.addEventListener("drop", dropEvent);
+
+
+
return arrow;
};
- this.setHighlighted = function(partID){
- if(partID === undefined){
- if(scope.highlighted){
- scope.highlighted.object.material.color = scope.highlighted.color;
- scope.highlighted = undefined;
- }
-
- return;
- }else if(scope.highlighted !== undefined && scope.highlighted !== partID){
- scope.highlighted.object.material.color = scope.highlighted.color;
- }
-
- scope.highlighted = partID;
- partID.object.material.color = new THREE.Color(0xffff00);
- }
+ function onMouseMove(event){
+ scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
+ scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
- this.getHoveredObject = function(mouse){
- var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
+
+ if(scope.dragstart){
+
+ scope.dragstart.object.dispatchEvent({
+ type: "mousedrag",
+ event: event
+ });
+
+ }else{
+
+
+ var I = getHoveredElement();
+ if(I){
+ var object = I.object;
+
+ //var g = new THREE.SphereGeometry(2);
+ //var m = new THREE.Mesh(g);
+ //scope.scene.add(m);
+ //m.position.copy(I.point);
+
+ object.dispatchEvent({type: "mousemove", event: event});
+
+ if(scope.hoveredElement && scope.hoveredElement !== object){
+ scope.hoveredElement.dispatchEvent({type: "mouseleave", event: event});
+ }
+
+ scope.hoveredElement = object;
+
+ }else{
+ if(scope.hoveredElement){
+ scope.hoveredElement.dispatchEvent({type: "mouseleave", event: event});
+ }
+
+ scope.hoveredElement = null;
+ }
+
+ }
+
+
+ };
+
+ function onMouseDown(event){
+
+ if(event.which === 1){
+ // left click
+ var I = getHoveredElement();
+ if(I){
+
+ var scales = [];
+ var rotations = [];
+ for(var i = 0; i < scope.targets.length; i++){
+ scales.push(scope.targets[i].scale.clone());
+ rotations.push(scope.targets[i].rotation.clone());
+ }
+
+ scope.dragstart = {
+ object: I.object,
+ sceneClickPos: I.point,
+ sceneStartPos: scope.sceneRoot.position.clone(),
+ mousePos: {x: scope.mouse.x, y: scope.mouse.y},
+ scales: scales,
+ rotations: rotations
+ };
+ }
+ }else if(event.which === 3){
+ // right click
+
+ scope.setTargets([]);
+ }
+ };
+
+ function onMouseUp(event){
+
+ if(scope.dragstart){
+ scope.dragstart.object.dispatchEvent({type: "drop", event: event});
+ scope.dragstart = null;
+ }
+ };
+
+ function getHoveredElement(){
+
+ if(scope.targets.length === 0){
+ return;
+ }
+
+ 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() );
+ raycaster.linePrecision = 0.2;
- var intersections = raycaster.intersectObject(scope, true);
- if(intersections.length === 0){
- scope.setHighlighted(undefined);
- return undefined;
+ var objects = [];
+ if(scope.translationNode.visible){
+ objects.push(scope.translationNode);
+ }else if(scope.scaleNode.visible){
+ objects.push(scope.scaleNode);
+ }else if(scope.rotationNode.visible){
+ objects.push(scope.rotationNode);
+ objects.push(scope.sceneRotation);
}
- var I = intersections[0];
- var partID = I.object.parent.partID;
-
- return partID;
- }
-
- this.onMouseMove = function(event){
-
- var mouse = event.normalizedPosition;
+ var intersections = raycaster.intersectObjects(objects, true);
- if(scope.state === scope.STATE.DEFAULT){
- scope.setHighlighted(scope.getHoveredObject(mouse));
- }else if(scope.state === scope.STATE.TRANSLATE_X || scope.state === scope.STATE.TRANSLATE_Y || scope.state === scope.STATE.TRANSLATE_Z){
- var origin = scope.start.lineStart.clone();
- var direction = scope.start.lineEnd.clone().sub(scope.start.lineStart);
- direction.normalize();
-
- var mousePoint = new THREE.Vector3(mouse.x, mouse.y);
-
- var directionDistance = new THREE.Vector3().subVectors(mousePoint, origin).dot(direction);
- var pointOnLine = direction.clone().multiplyScalar(directionDistance).add(origin);
-
- pointOnLine.unproject(scope.camera);
-
- var diff = pointOnLine.clone().sub(scope.position);
- scope.position.copy(pointOnLine);
-
- for(var i = 0; i < scope.targets.length; i++){
- var target = scope.targets[0];
- target.position.add(diff);
- }
-
- event.signal.halt();
+ // 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 < intersections.length; i++){
+ var I = intersections[i];
+ I.distance = scope.camera.position.distanceTo(I.point);
}
+ intersections.sort( function ( a, b ) { return a.distance - b.distance;} );
- };
-
- this.onMouseDown = function(event){
-
- if(scope.state === scope.STATE.DEFAULT){
- var hoveredObject = scope.getHoveredObject(event.normalizedPosition, scope.camera);
- if(hoveredObject){
- scope.state = hoveredObject.state;
-
- var lineStart = scope.position.clone();
- var lineEnd;
-
- if(scope.state === scope.STATE.TRANSLATE_X){
- lineEnd = scope.position.clone();
- lineEnd.x += 2;
- }else if(scope.state === scope.STATE.TRANSLATE_Y){
- lineEnd = scope.position.clone();
- lineEnd.y += 2;
- }else if(scope.state === scope.STATE.TRANSLATE_Z){
- lineEnd = scope.position.clone();
- lineEnd.z -= 2;
- }
-
- lineStart.project(scope.camera);
- lineEnd.project(scope.camera);
-
- scope.start = {
- mouse: event.normalizedPosition,
- lineStart: lineStart,
- lineEnd: lineEnd
- };
-
- event.signal.halt();
- }
-
- }
- };
-
- this.onMouseUp = function(event){
- scope.setHighlighted();
- scope.state = scope.STATE.DEFAULT;
-
+ if(intersections.length > 0){
+ return intersections[0];
+ }else{
+ return false;
+ }
};
this.setTargets = function(targets){
scope.targets = targets;
if(scope.targets.length === 0){
+ this.sceneRoot.visible = false;
+ this.sceneRotation.visible = false;
+
return;
+ }else{
+ this.sceneRoot.visible = true;
}
//TODO calculate centroid of all targets
- var centroid = targets[0].position.clone();
+ var target = targets[0];
+ var bb;
+ if(target.geometry && target.geometry.boundingBox){
+ bb = target.geometry.boundingBox;
+ }else{
+ bb = target.boundingBox;
+ }
+
+ if(bb){
+ var centroid = bb.clone().applyMatrix4(target.matrixWorld).center();
+ scope.sceneRoot.position.copy(centroid);
+ }
+
//for(var i = 0; i < targets.length; i++){
// var target = targets[i];
//}
- scope.position.copy(centroid);
}
-
- this.build();
+
+ this.update = function(){
+ var node = this.sceneRoot;
+ var wp = node.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 / 20)); // * (2 - pp.z / pp.w);
+ node.scale.set(w, w, w);
+
+ if(this.targets && this.targets.length === 1){
+ this.scaleNode.rotation.copy(this.targets[0].rotation);
+ }
+
+ this.sceneRotation.scale.set(w,w,w);
+ };
+
+ this.render = function(){
+ this.update();
+ this.sceneRotation.position.copy(this.sceneRoot.position);
+ this.sceneRotation.visible = this.rotationNode.visible && this.sceneRoot.visible;
+
+ renderer.render(this.sceneRotation, this.camera);
+ renderer.render(this.sceneTransformation, this.camera);
+ };
+
+ this.translate = function(){
+ this.translationNode.visible = true;
+ this.scaleNode.visible = false;
+ this.rotationNode.visible = false;
+ };
+
+ this.scale = function(){
+ this.translationNode.visible = false;
+ this.scaleNode.visible = true;
+ this.rotationNode.visible = false;
+ };
+
+ this.rotate = function(){
+ this.translationNode.visible = false;
+ this.scaleNode.visible = false;
+ this.rotationNode.visible = true;
+ };
+
+ this.buildTranslationNode();
+ this.buildScaleNode();
+ this.buildRotationNode();
+
+ //this.translate();
+ this.rotate();
+
+ this.setTargets([]);
+
+ //this.domElement.addEventListener( 'click', onClick, false);
+ this.domElement.addEventListener( 'mousemove', onMouseMove, true );
+ this.domElement.addEventListener( 'mousedown', onMouseDown, true );
+ this.domElement.addEventListener( 'mouseup', onMouseUp, true );
};
-Potree.TranslationTool.prototype = Object.create( THREE.Object3D.prototype );
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+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.accuracy = 0.5;
+
+ this.volumes = [];
+
+ var STATE = {
+ DEFAULT: 0,
+ INSERT_VOLUME: 1
+
+ };
+
+ var state = STATE.DEFAULT;
+
+ var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
+ boxGeometry.computeBoundingBox();
+
+ var boxFrameGeometry = new THREE.Geometry();
+ // bottom
+ 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));
+ 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));
+ boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, -0.5));
+ boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0.5));
+ // top
+ 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));
+ 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));
+ boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, -0.5));
+ boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, 0.5));
+ // sides
+ 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));
+ 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));
+ 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;
+
+ 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);
+ 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(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()
+ });
+ }
+ };
+
+ };
+ Volume.prototype = Object.create( THREE.Object3D.prototype );
+
+ Object.defineProperty(Volume.prototype, "clip", {
+ get: function(){
+ return this._clip;
+ },
+
+ 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;
+ }
+ }
+ });
+
+
+ function onMouseMove(event){
+ scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
+ scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
+ };
+
+ function onMouseClick(event){
+
+ //if(state === STATE.INSERT_VOLUME){
+ // scope.finishInsertion();
+ //}else if(event.which === 1){
+ // var I = getHoveredElement();
+ //
+ // if(I){
+ // transformationTool.setTargets([I.object]);
+ // }
+ //}
+ };
+
+ function onMouseDown(event){
+
+ if(state === STATE.INSERT_VOLUME){
+ scope.finishInsertion();
+ }else if(event.which === 1){
+ var I = getHoveredElement();
+
+ if(I){
+ transformationTool.setTargets([I.object]);
+ }
+ }
+
+
+ if(event.which === 3){
+ // open context menu
+
+ //var element = getHoveredElement();
+ //
+ //if(element){
+ // var menu = document.createElement("div");
+ // menu.style.position = "fixed";
+ // menu.style.backgroundColor = "#bbbbbb";
+ // menu.style.top = event.clientY + "px";
+ // menu.style.left = event.clientX + "px";
+ // menu.style.width = "200px";
+ // menu.style.height = "100px";
+ // menu.innerHTML = "abc";
+ // menu.addEventListener("contextmenu", function(event){
+ // event.preventDefault();
+ // return false;
+ // }, false);
+ //
+ // scope.renderer.domElement.parentElement.appendChild(menu);
+ //}
+ }
+ };
+
+ function onContextMenu(event){
+ event.preventDefault();
+ return false;
+ }
+
+ 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 objects = [];
+ for(var i = 0; i < scope.volumes.length; i++){
+ var object = scope.volumes[i];
+ objects.push(object);
+ }
+
+ var intersections = raycaster.intersectObjects(objects, false);
+ 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, {accuracy: scope.accuracy});
+
+ 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.update = function(delta){
+
+ if(state === STATE.INSERT_VOLUME){
+ var I = getMousePointCloudIntersection();
+
+ if(I){
+ this.activeVolume.position.copy(I);
+
+ var wp = this.activeVolume.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 / 10));
+ this.activeVolume.scale.set(w, w, w);
+ }
+ }
+
+ var volumes = [];
+ for(var i = 0; i < this.volumes.length; i++){
+ volumes.push(this.volumes[i]);
+ }
+ if(this.activeVolume){
+ volumes.push(this.activeVolume);
+ }
+
+ for(var i = 0; i < volumes.length; i++){
+ var volume = volumes[i];
+ var box = volume.box;
+ var label = volume.label;
+
+ 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);
+ }
+
+ };
+
+ this.startInsertion = function(args){
+ state = STATE.INSERT_VOLUME;
+
+ var args = args || {};
+ var clip = args.clip || false;
+
+ this.activeVolume = new Volume();
+ this.activeVolume.clip = clip;
+ this.sceneVolume.add(this.activeVolume);
+ }
+
+ this.finishInsertion = function(){
+ this.volumes.push(this.activeVolume);
+ transformationTool.setTargets([this.activeVolume]);
+
+ this.activeVolume = null;
+ state = STATE.DEFAULT;
+
+ }
+
+ this.render = function(){
+
+ renderer.render(this.sceneVolume, this.camera);
+
+ };
+
+ this.domElement.addEventListener( 'click', onMouseClick, false );
+ this.domElement.addEventListener( 'mousedown', onMouseDown, false );
+ this.domElement.addEventListener( 'mousemove', onMouseMove, false );
+ this.domElement.addEventListener( 'contextmenu', onContextMenu, false );
+};
\ No newline at end of file
diff --git a/build/js/potree.min.js b/build/js/potree.min.js
index f894ef7b..5b20a1ef 100644
--- a/build/js/potree.min.js
+++ b/build/js/potree.min.js
@@ -1,3 +1,4 @@
-function Potree(){}function POCLoader(){}function PointAttributeNames(){}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 in e){var o=e[t];this.attributes.push(o),this.byteSize+=o.byteSize,this.size++}}function LRUItem(e){this.previous=null,this.next=null,this.node=e}function LRU(){this.first=null,this.last=null,this.items={},this.elements=0,this.numPoints=0}Potree.pointLoadLimit=5e7,Potree.workers={},Potree.WorkerManager=function(e){this.code=e,this.instances=[],this.createdInstances=0},Potree.WorkerManager.prototype.getWorker=function(){var e=this.instances.pop();return void 0===e&&(e=Potree.utils.createWorker(this.code),this.createdInstances++),e},Potree.WorkerManager.prototype.returnWorker=function(e){this.instances.push(e)},Potree.WorkerManager.fromUrls=function(e){for(var t="",o=0;ou;u++)r[3*u+0]=l[4*u+0]+e.pcoGeometry.offset.x,r[3*u+1]=l[4*u+1]+e.pcoGeometry.offset.y,r[3*u+2]=l[4*u+2]+e.pcoGeometry.offset.z,s.setRGB(d[16*u+12],d[16*u+13],d[16*u+14]),n[3*u+0]=s.r/255,n[3*u+1]=s.g/255,n[3*u+2]=s.b/255,c[u]=u;o.addAttribute("position",new THREE.BufferAttribute(r,3)),o.addAttribute("color",new THREE.BufferAttribute(n,3)),o.addAttribute("indices",new THREE.BufferAttribute(a,1)),o.boundingBox=e.boundingBox,e.geometry=o,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--},Potree.LasLazLoader=function(e){this.version="string"==typeof e?new Potree.Version(e):e},Potree.LasLazLoader.prototype.load=function(e){if(!e.loaded){var t=e.pcoGeometry.pointAttributes,o=e.pcoGeometry.octreeDir+"/"+e.name+"."+t.toLowerCase(),i=this,r=new XMLHttpRequest;r.open("GET",o,!0),r.responseType="arraybuffer",r.overrideMimeType("text/plain; charset=x-user-defined"),r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status){var t=r.response;i.parse(e,t)}else console.log("Failed to load file! HTTP status: "+r.status+", file: "+o)},r.send(null)}},Potree.LasLazLoader.progressCB=function(){},Potree.LasLazLoader.prototype.parse=function(e,t){var o=new LASFile(t),i=new Potree.LasLazBatcher(e);return Promise.resolve(o).cancellable().then(function(e){return e.open().then(function(){return e.isOpen=!0,e}).catch(Promise.CancellationError,function(t){return e.close().then(function(){throw t})})}).then(function(e){return e.getHeader().then(function(t){return[e,t]})}).then(function(e){var t=e[0],o=e[1],r=1,n=0,a=1>=r?o.pointsCount:o.pointsCount/r,s=function(){var e=t.readData(1e6,0,r);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)),n+=e.count,Potree.LasLazLoader.progressCB(n/a),e.hasMoreData?s():(o.totalRead=n,o.versionAsString=t.versionAsString,o.isCompressed=t.isCompressed,[t,o,i])})};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(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]),r=new THREE.Vector3(t.maxs[0],t.maxs[1],t.maxs[2]);i.add(e.pcoGeometry.offset),r.add(e.pcoGeometry.offset),o.onmessage=function(n){for(var a=new THREE.BufferGeometry,s=t.pointsCount,l=n.data.position,d=n.data.color,c=n.data.intensity,u=new Uint8Array(n.data.classification),p=new Float32Array(u.byteLength),h=new Uint8Array(n.data.returnNumber),m=new Float32Array(h.byteLength),f=new Uint16Array(n.data.pointSourceID),v=new Float32Array(f.length),y=new ArrayBuffer(4*s),E=new Uint32Array(y),T=new THREE.Box3,g=new Float32Array(l),P=0;s>P;P++)p[P]=u[P],m[P]=h[P],v[P]=f[P],E[P]=P,T.expandByPoint(new THREE.Vector3(g[3*P+0],g[3*P+1],g[3*P+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(p),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(y,1)),a.boundingBox=new THREE.Box3(i,r),e.boundingBox=a.boundingBox,e.geometry=a,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(o)};var n={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(n,[n.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.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,r=e.minSize||1,n=1;this._pointSizeType=Potree.PointSizeType.ATTENUATED,this._pointShape=Potree.PointShape.SQUARE,this._interpolate=!1,this._pointColorType=Potree.PointColorType.RGB,this._octreeLevels=6,this.gradientTexture=Potree.PointCloudMaterial.generateGradient();var a={},s={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:n},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}};this.setValues({uniforms:s,attributes:a,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:r,nodeSize:n,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.setValues(1===this.opacity?{blending:THREE.NoBlending,transparent:!1,depthTest:!0,depthWrite:!0}:{blending:THREE.AdditiveBlending,transparent:!0,depthTest:!1,depthWrite:!0}),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"),e},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,"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,"pointSizeType",{get:function(){return this._pointSizeType},set:function(e){this._pointSizeType!==e&&(this._pointSizeType=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 near; ","uniform float far; "," "," ","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 sampler2D visibleNodes; ","uniform sampler2D gradient; "," "," ","varying vec3 vColor; "," "," ","#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; "," "," "," // 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 "," vColor = vec3(1.0, 1.0, 1.0) * gl_Position.w * 0.0001; "," #elif defined color_type_intensity "," float w = (intensity - intensityMin) / intensityMax; "," vColor = vec3(w, w, w); "," //vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #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); "," ","} "],Potree.PointCloudMaterial.fs_points_rgb=["#if defined use_interpolation "," #extension GL_EXT_frag_depth : enable ","#endif "," ","precision highp float; ","precision highp int; "," ","uniform float opacity; ","uniform float pcIndex; "," ","varying vec3 vColor; "," "," ","void main() { "," "," #if defined(circle_point_shape) || defined(use_interpolation) "," 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 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, opacity); "," #endif "," ","} "],THREE.FirstPersonControls=function(e,t){function o(e){l.enabled!==!1&&(e.preventDefault(),0===e.button?(b=P.ROTATE,d.set(e.clientX,e.clientY)):2===e.button&&(b=P.PAN,p.set(e.clientX,e.clientY)),l.domElement.addEventListener("mousemove",i,!1),l.domElement.addEventListener("mouseup",r,!1),l.dispatchEvent(R))
-}function i(e){if(l.enabled!==!1){e.preventDefault();var t=l.domElement===document?l.domElement.body:l.domElement;b===P.ROTATE?(c.set(e.clientX,e.clientY),u.subVectors(c,d),l.rotateLeft(2*Math.PI*u.x/t.clientWidth*l.rotateSpeed),l.rotateUp(2*Math.PI*u.y/t.clientHeight*l.rotateSpeed),d.copy(c)):b===P.PAN&&(h.set(e.clientX,e.clientY),m.subVectors(h,p),m.multiplyScalar(5e-4).multiplyScalar(l.moveSpeed),l.pan(m.x,m.y),p.copy(h))}}function r(){l.enabled!==!1&&(l.domElement.removeEventListener("mousemove",i,!1),l.domElement.removeEventListener("mouseup",r,!1),l.dispatchEvent(w),b=P.NONE)}function n(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(R),l.dispatchEvent(w)}}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,u=new THREE.Vector2,p=new THREE.Vector2,h=new THREE.Vector2,m=new THREE.Vector2,f=new THREE.Vector3,v=(new THREE.Vector3,0),y=0,E=1,T=new THREE.Vector3,g=new THREE.Vector3,P={NONE:-1,ROTATE:0,SPEEDCHANGE:1,PAN:2},b=P.NONE;this.position0=this.object.position.clone();var x={type:"change"},R={type:"start"},w={type:"end"};this.rotateLeft=function(e){y-=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),T.add(f)},this.panUp=function(e){var t=this.object.matrix.elements;f.set(t[4],t[5],t[6]),f.multiplyScalar(e),T.add(f)},this.panForward=function(e){var t=this.object.matrix.elements;f.set(t[8],t[9],t[10]),f.multiplyScalar(e),T.add(f)},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,r=i.clone(),n=r.length();n*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*n/o.clientHeight),l.panUp(2*t*n/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)),!T.equals(new THREE.Vector3(0,0,0))){var o={type:"move",translation:T.clone()};this.dispatchEvent(o)}if(t.add(T),0!==y||0!==v){var o={type:"rotate",thetaDelta:y,phiDelta:v};this.dispatchEvent(o)}this.object.updateMatrix();var i=(new THREE.Matrix4).makeRotationY(y),r=(new THREE.Matrix4).multiplyMatrices(i,this.object.matrix);this.object.quaternion.setFromRotationMatrix(r),this.object.rotation.x+=v,y=0,v=0,E=1,T.set(0,0,0),g.distanceTo(this.object.position)>0&&(this.dispatchEvent(x),g.copy(this.object.position))},this.reset=function(){b=P.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",n,!1),this.domElement.addEventListener("DOMMouseScroll",n,!1),window.addEventListener("keydown",a,!1),window.addEventListener("keyup",s,!1)},THREE.FirstPersonControls.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,r){this.start=e,this.end=t,this.width=o,this.depth=i,this.callback=r,this.loadQueue=[];var n=((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(n,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.root.boundingBox,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.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.update=function(e,t){this.updateMatrixWorld(!0),this.visibleGeometry=this.getVisibleGeometry(e);for(var o=[],i=0;i0;){{var a=n.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){this.numVisibleNodes++,this.numVisiblePoints+=s.numPoints,s.material=this.material,this.visibleNodes.push(a),s.level&&(this.maxLevel=Math.max(s.level,this.maxLevel));for(var i=0;i=0;if(c)for(var u=0;u0;){var m=n.shift();if(m instanceof Potree.PointCloudOctreeProxyNode){var f=Potree.utils.computeTransformedBoundingBox(m.boundingBox,m.matrixWorld),v=f.getBoundingSphere();Math.abs(p.distanceToPoint(v.center))0){var m=g.loadQueue[0],l=m.geometryNode;if(l.loaded===!0&&void 0!==m.parent){var s=this.replaceProxy(m);s.updateMatrixWorld(),s.matrixWorld.multiplyMatrices(s.parent.matrixWorld,s.matrix)}else m.geometryNode.load()}else{var P=this.getProfile(g.start,g.end,g.width,g.depth);g.callback({type:"finished",points:P}),T.push(g)}}for(var i=0;i-1&&this.profileRequests.splice(b,1)}if(this.loadQueue.length>0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var i=0;i0;){E++;var T=h.shift(),g=T.node,P=g.boundingBox,f=g.boundingSphere,b=i.intersectsBox(P),x=b;if(x){if(m+g.numPoints>this.visiblePointsTarget)break;m+=g.numPoints,t.push(T);for(var R in g.children){var w=g.children[R],f=w.boundingSphere,v=f.center.distanceTo(u),C=f.radius,y=f.radius/v,A=e.fov/2*Math.PI/180,S=1/Math.tan(A)*C/Math.sqrt(v*v-C*C);if(!(.1>S))if(y=S,0>v-C&&(y=Number.MAX_VALUE),0===h.length)h.push({node:w,weight:y});else{for(var H=0,M=0;Mh[M].weight){var H=M;break}if(M==h.length-1){H=h.length;break}}h.splice(H,0,{node:w,weight:y})}}}}return t},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(){if(this.material){for(var e=this.material.visibleNodesTexture,t=e.image.data,o=[],i=0;io?-1:o>i?1:0};o.sort(r);for(var i=0;it.name?1:0}),t[3*i+0]=0,t[3*i+1]=0,t[3*i+2]=0;for(var s=0;sn;n++)if(void 0!==t.children[n]){var a=t.children[n],s=new Potree.PointCloudOctreeProxyNode(a);i.add(s)}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;){var f=n.shift(),v=0;if(f instanceof THREE.PointCloud)for(var y=f.geometry,E=y.attributes.position,T=E.array,g=E.length/E.itemSize,P=0;g>P;P++){var b=new THREE.Vector3(T[3*P],T[3*P+1],T[3*P+2]);b.applyMatrix4(this.matrixWorld);var x=Math.abs(p.distanceToPoint(b)),R=Math.abs(h.distanceToPoint(b));o/2>x&&s/2>R&&(m.push(b),v++)}if(f==this||f.levelt)},Potree.PointCloudOctree.disposeNode=function(e){var t=0,o=0,i=[];e.traverse(function(e){i.push(e)});for(var r=0;r1||(this.loading=!0,Potree.PointCloudOctree.lru.numPoints+this.numPoints>=Potree.pointLoadLimit&&Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints),this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.load(this))},Potree.BinaryNodeLoader=function(){},Potree.BinaryNodeLoader.load=function(e,t,o){var i=e.pcoGeometry.octreeDir+"/"+e.name;void 0!==t&&t.length>0&&(i+="."+t);var r=new XMLHttpRequest;r.open("GET",i,!0),r.responseType="arraybuffer",r.overrideMimeType("text/plain; charset=x-user-defined"),r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status||0===r.status){var t=r.response;o(e,t)}else console.log("Failed to load file! HTTP status: "+r.status+", file: "+i)};try{r.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",r=[e+"px"+i,e+"nx"+i,e+"py"+i,e+"ny"+i,e+"pz"+i,e+"nz"+i],n=THREE.ImageUtils.loadTextureCube(r,new THREE.CubeRefractionMapping),a=new THREE.MeshBasicMaterial({color:16777215,envMap:n,refractionRatio:.95}),s=THREE.ShaderLib.cube;s.uniforms.tCube.value=n;var 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 r=new THREE.LineBasicMaterial({color:i||8947848}),n=new THREE.Geometry,a=0;t>=a;a++)n.vertices.push(new THREE.Vector3(-(o*e)/2,0,a*o-o*t/2)),n.vertices.push(new THREE.Vector3(+(o*e)/2,0,a*o-o*t/2));for(var a=0;e>=a;a++)n.vertices.push(new THREE.Vector3(a*o-o*e/2,0,-(o*t)/2)),n.vertices.push(new THREE.Vector3(a*o-o*e/2,0,+(o*t)/2));var s=new THREE.Line(n,r,THREE.LinePieces);return s.receiveShadow=!0,s},Potree.TextSprite=function(e){var t=new THREE.Texture,o=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});THREE.Sprite.call(this,o),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.text="",this.setText(e)},Potree.TextSprite.prototype=new THREE.Sprite,Potree.TextSprite.prototype.setText=function(e){this.text=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,r=i+2*this.borderThickness,n=1.4*this.fontsize+2*this.borderThickness,e=document.createElement("canvas"),t=e.getContext("2d");t.canvas.width=r,t.canvas.height=n,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(255, 255, 255, 1.0)",t.fillText(this.text,this.borderThickness,this.fontsize+this.borderThickness);var a=new THREE.Texture(e);a.needsUpdate=!0,this.material.map=a,this.scale.set(.01*r,.01*n,1)},Potree.TextSprite.prototype.roundRect=function(e,t,o,i,r,n){e.beginPath(),e.moveTo(t+n,o),e.lineTo(t+i-n,o),e.quadraticCurveTo(t+i,o,t+i,o+n),e.lineTo(t+i,o+r-n),e.quadraticCurveTo(t+i,o+r,t+i-n,o+r),e.lineTo(t+n,o+r),e.quadraticCurveTo(t,o+r,t,o+r-n),e.lineTo(t,o+n),e.quadraticCurveTo(t,o,t+n,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=e.substr(0,t),this.versionMinor=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.MeasuringTool=function(e,t,o){function i(){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.edgeLabels=[]}function r(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e}function n(e){if(p.enabled){var t=u();if(t){var o=t.clone(),n=new THREE.Mesh(f,r());n.position.copy(t),p.sceneRoot.add(n),n.addEventListener("mousemove",v),n.addEventListener("mouseleave",y),n.addEventListener("mousedrag",E),n.addEventListener("drop",T);var a=new THREE.Mesh(f,r());a.position.copy(t),p.sceneRoot.add(a),a.addEventListener("mousemove",v),a.addEventListener("mouseleave",y),a.addEventListener("mousedrag",E),a.addEventListener("drop",T);var s=o.x.toFixed(2)+" / "+o.y.toFixed(2)+" / "+o.z.toFixed(2),l=new Potree.TextSprite(s);l.setBorderColor({r:0,g:255,b:0,a:1}),l.material.depthTest=!1,l.material.opacity=0,l.position.copy(t),l.position.y+=.5;var d=new Potree.TextSprite(s);d.setBorderColor({r:0,g:255,b:0,a:1}),d.material.depthTest=!1,d.material.opacity=0,d.position.copy(t),d.position.y+=.5;var c=new THREE.Color(16711680),g=new THREE.Geometry;g.vertices.push(t.clone(),t.clone()),g.colors.push(c,c,c);var P=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:10});P.depthTest=!1,sConnection=new THREE.Line(g,P);var b=new Potree.TextSprite(0);b.setBorderColor({r:0,g:255,b:0,a:0}),b.setBackgroundColor({r:0,g:255,b:0,a:0}),b.material.depthTest=!1,b.position.copy(t),b.position.y+=.5,p.sceneRoot.add(sConnection),p.sceneRoot.add(l),p.sceneRoot.add(d),p.sceneRoot.add(b),m===h.DEFAULT?(m=h.PICKING,p.activeMeasurement=new i,p.activeMeasurement.spheres.push(n)):m===h.PICKING&&p.sceneRoot.remove(n),p.activeMeasurement.points.push(t),p.activeMeasurement.spheres.push(a),p.activeMeasurement.sphereLabels.push(l),p.activeMeasurement.sphereLabels.push(d),p.activeMeasurement.edges.push(sConnection),p.activeMeasurement.edgeLabels.push(b);var e={type:"newpoint",position:o.clone()};p.dispatchEvent(e)}}}function a(e){if(p.mouse.x=e.clientX/p.domElement.clientWidth*2-1,p.mouse.y=2*-(e.clientY/p.domElement.clientHeight)+1,p.dragstart)p.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(m==h.PICKING&&p.activeMeasurement){var t=u();if(t)if(1===p.activeMeasurement.spheres.length){var o=t.clone(),i=p.activeMeasurement.spheres[0];i.position.copy(t)}else{var o=t.clone(),r=p.activeMeasurement.spheres.length,i=p.activeMeasurement.spheres[r-1],n=p.activeMeasurement.sphereLabels[r-1],a=p.activeMeasurement.edges[r-2],s=p.activeMeasurement.edgeLabels[r-2],l=o.x.toFixed(2)+" / "+o.y.toFixed(2)+" / "+o.z.toFixed(2);n.setText(l),i.position.copy(t),n.position.copy(t),n.position.y+=.5,a.geometry.vertices[1].copy(t),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere();var d=a.geometry.vertices[1].clone().add(a.geometry.vertices[0]).multiplyScalar(.5),f=a.geometry.vertices[0].distanceTo(a.geometry.vertices[1]).toFixed(2);s.position.copy(d),s.setText(f),s.scale.multiplyScalar(10)}}else{var t=c();t?(t.object.dispatchEvent({type:"mousemove",target:t.object,event:e}),p.hoveredElement&&p.hoveredElement!==t.object&&p.hoveredElement.dispatchEvent({type:"mouseleave",target:p.hoveredElement,event:e}),p.hoveredElement=t.object):(p.hoveredElement&&p.hoveredElement.dispatchEvent({type:"mouseleave",target:p.hoveredElement,event:e}),p.hoveredElement=null)}}function s(){if(m==h.PICKING){var e=p.activeMeasurement.spheres.pop(),t=p.activeMeasurement.edges.pop(),o=p.activeMeasurement.sphereLabels.pop(),i=p.activeMeasurement.edgeLabels.pop();p.sceneRoot.remove(e),p.sceneRoot.remove(t),p.sceneRoot.remove(o),p.sceneRoot.remove(i),p.measurements.push(p.activeMeasurement),p.activeMeasurement=void 0,m=h.DEFAULT,p.setEnabled(!1)}}function l(e){if(1===e.which){var t=c();t&&(p.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:p.sceneRoot.position.clone(),mousePos:{x:p.mouse.x,y:p.mouse.y}})}else 3===e.which&&s(e)}function d(e){p.dragstart&&(p.dragstart.object.dispatchEvent({type:"drop",event:e}),p.dragstart=null)}function c(){var e=new THREE.Vector3(p.mouse.x,p.mouse.y,.5);e.unproject(p.camera);var t=new THREE.Raycaster;t.ray.set(p.camera.position,e.sub(p.camera.position).normalize());for(var o=[],i=0;i0?a[0]:!1}function u(){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 r=null,n=null,a=0;ad)&&(r=l,n=d)}}return r?r.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},this.accuracy=.5;var h={DEFAULT:0,PICKING:1},m=h.DEFAULT,f=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 v=function(e){e.target.material.emissive.setHex(8947848)},y=function(e){e.target.material.emissive.setHex(0)},E=function(e){var t=u();if(t)for(var o=0;o=0){var n=i.spheres[r];if(0===r){var a=i.edges[r],s=i.edgeLabels[r];n.position.copy(t),a.geometry.vertices[0].copy(t),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere();var l=a.geometry.vertices[0].clone().add(a.geometry.vertices[1]).multiplyScalar(.5),d=a.geometry.vertices[0].distanceTo(a.geometry.vertices[1]).toFixed(2);s.position.copy(l),s.setText(d),s.scale.multiplyScalar(10)}else if(r===i.spheres.length-1){var a=i.edges[r-1],s=i.edgeLabels[r-1];n.position.copy(t),a.geometry.vertices[1].copy(t),a.geometry.verticesNeedUpdate=!0,a.geometry.computeBoundingSphere();var l=a.geometry.vertices[0].clone().add(a.geometry.vertices[1]).multiplyScalar(.5),d=a.geometry.vertices[0].distanceTo(a.geometry.vertices[1]).toFixed(2);s.position.copy(l),s.setText(d),s.scale.multiplyScalar(10)}else{var c=i.edges[r-1],h=i.edges[r],m=i.edgeLabels[r-1],f=i.edgeLabels[r];n.position.copy(t),c.geometry.vertices[1].copy(t),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),h.geometry.vertices[0].copy(t),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere();var v=c.geometry.vertices[0].clone().add(c.geometry.vertices[1]).multiplyScalar(.5),y=c.geometry.vertices[0].distanceTo(c.geometry.vertices[1]).toFixed(2);m.position.copy(v),m.setText(y),m.scale.multiplyScalar(10);var E=h.geometry.vertices[0].clone().add(h.geometry.vertices[1]).multiplyScalar(.5),T=h.geometry.vertices[0].distanceTo(h.geometry.vertices[1]).toFixed(2);f.position.copy(E),f.setText(T),f.scale.multiplyScalar(10)}break}}e.event.stopImmediatePropagation()},T=function(){};this.setEnabled=function(e){if(this.enabled!==e&&(this.enabled=e,e)){m=h.PICKING,p.activeMeasurement=new i;var t=new THREE.Mesh(f,r());p.sceneRoot.add(t),p.activeMeasurement.spheres.push(t),t.addEventListener("mousemove",v),t.addEventListener("mouseleave",y),t.addEventListener("mousedrag",E),t.addEventListener("drop",T)
-}},this.update=function(){for(var e=[],o=0;ou;u++)this.version.newerThan("1.3")?(r[3*u+0]=c[4*u+0]*this.scale+e.boundingBox.min.x,r[3*u+1]=c[4*u+1]*this.scale+e.boundingBox.min.y,r[3*u+2]=c[4*u+2]*this.scale+e.boundingBox.min.z):(r[3*u+0]=l[4*u+0]+e.pcoGeometry.offset.x,r[3*u+1]=l[4*u+1]+e.pcoGeometry.offset.y,r[3*u+2]=l[4*u+2]+e.pcoGeometry.offset.z),a.setRGB(d[16*u+12],d[16*u+13],d[16*u+14]),n[3*u+0]=a.r/255,n[3*u+1]=a.g/255,n[3*u+2]=a.b/255,h[u]=u;o.addAttribute("position",new THREE.BufferAttribute(r,3)),o.addAttribute("color",new THREE.BufferAttribute(n,3)),o.addAttribute("indices",new THREE.BufferAttribute(s,1)),o.boundingBox=e.boundingBox,e.geometry=o,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--},Potree.LasLazLoader=function(e){this.version="string"==typeof e?new Potree.Version(e):e},Potree.LasLazLoader.prototype.load=function(e){if(!e.loaded){var t=e.pcoGeometry.pointAttributes,o=e.pcoGeometry.octreeDir+"/"+e.name+"."+t.toLowerCase(),i=this,r=new XMLHttpRequest;r.open("GET",o,!0),r.responseType="arraybuffer",r.overrideMimeType("text/plain; charset=x-user-defined"),r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status){var t=r.response;i.parse(e,t)}else console.log("Failed to load file! HTTP status: "+r.status+", file: "+o)},r.send(null)}},Potree.LasLazLoader.progressCB=function(){},Potree.LasLazLoader.prototype.parse=function(e,t){var o=new LASFile(t),i=new Potree.LasLazBatcher(e);return Promise.resolve(o).cancellable().then(function(e){return e.open().then(function(){return e.isOpen=!0,e}).catch(Promise.CancellationError,function(t){return e.close().then(function(){throw t})})}).then(function(e){return e.getHeader().then(function(t){return[e,t]})}).then(function(e){var t=e[0],o=e[1],r=1,n=0,s=1>=r?o.pointsCount:o.pointsCount/r,a=function(){var e=t.readData(1e6,0,r);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)),n+=e.count,Potree.LasLazLoader.progressCB(n/s),e.hasMoreData?a():(o.totalRead=n,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]),r=new THREE.Vector3(t.maxs[0],t.maxs[1],t.maxs[2]);i.add(e.pcoGeometry.offset),r.add(e.pcoGeometry.offset),o.onmessage=function(n){for(var s=new THREE.BufferGeometry,a=t.pointsCount,l=n.data.position,c=n.data.color,d=n.data.intensity,h=new Uint8Array(n.data.classification),u=new Float32Array(h.byteLength),p=new Uint8Array(n.data.returnNumber),m=new Float32Array(p.byteLength),v=new Uint16Array(n.data.pointSourceID),f=new Float32Array(v.length),E=new ArrayBuffer(4*a),y=new Uint32Array(E),g=new THREE.Box3,T=new Float32Array(l),b=0;a>b;b++)u[b]=h[b],m[b]=p[b],f[b]=v[b],y[b]=b,g.expandByPoint(new THREE.Vector3(T[3*b+0],T[3*b+1],T[3*b+2]));s.addAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),s.addAttribute("color",new THREE.BufferAttribute(new Float32Array(c),3)),s.addAttribute("intensity",new THREE.BufferAttribute(new Float32Array(d),1)),s.addAttribute("classification",new THREE.BufferAttribute(new Float32Array(u),1)),s.addAttribute("returnNumber",new THREE.BufferAttribute(new Float32Array(m),1)),s.addAttribute("pointSourceID",new THREE.BufferAttribute(new Float32Array(f),1)),s.addAttribute("indices",new THREE.BufferAttribute(E,1)),s.boundingBox=new THREE.Box3(i,r),e.boundingBox=s.boundingBox,e.geometry=s,e.loaded=!0,e.loading=!1,e.pcoGeometry.numNodesLoading--,Potree.workers.lasdecoder.returnWorker(o)};var n={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(n,[n.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,r=e.minSize||1,n=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:n},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:r,nodeSize:n,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; "," vColor = vec3(w, w, w); "," //vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; "," #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?(P=b.ROTATE,c.set(e.clientX,e.clientY)):2===e.button&&(P=b.PAN,u.set(e.clientX,e.clientY)),l.domElement.addEventListener("mousemove",i,!1),l.domElement.addEventListener("mouseup",r,!1),l.dispatchEvent(R))
+}function i(e){if(l.enabled!==!1){e.preventDefault();var t=l.domElement===document?l.domElement.body:l.domElement;P===b.ROTATE?(d.set(e.clientX,e.clientY),h.subVectors(d,c),l.rotateLeft(2*Math.PI*h.x/t.clientWidth*l.rotateSpeed),l.rotateUp(2*Math.PI*h.y/t.clientHeight*l.rotateSpeed),c.copy(d)):P===b.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 r(){l.enabled!==!1&&(l.domElement.removeEventListener("mousemove",i,!1),l.domElement.removeEventListener("mouseup",r,!1),l.dispatchEvent(w),P=b.NONE)}function n(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(R),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,c=new THREE.Vector2,d=new THREE.Vector2,h=new THREE.Vector2,u=new THREE.Vector2,p=new THREE.Vector2,m=new THREE.Vector2,v=new THREE.Vector3,f=(new THREE.Vector3,0),E=0,y=1,g=new THREE.Vector3,T=new THREE.Vector3,b={NONE:-1,ROTATE:0,SPEEDCHANGE:1,PAN:2},P=b.NONE;this.position0=this.object.position.clone();var x={type:"change"},R={type:"start"},w={type:"end"};this.rotateLeft=function(e){E-=e},this.rotateUp=function(e){f-=e},this.panLeft=function(e){var t=this.object.matrix.elements;v.set(t[0],t[1],t[2]),v.multiplyScalar(-e),g.add(v)},this.panUp=function(e){var t=this.object.matrix.elements;v.set(t[4],t[5],t[6]),v.multiplyScalar(e),g.add(v)},this.panForward=function(e){var t=this.object.matrix.elements;v.set(t[8],t[9],t[10]),v.multiplyScalar(e),g.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,r=i.clone(),n=r.length();n*=Math.tan(l.object.fov/2*Math.PI/180),l.panLeft(2*e*n/o.clientHeight),l.panUp(2*t*n/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)),!g.equals(new THREE.Vector3(0,0,0))){var o={type:"move",translation:g.clone()};this.dispatchEvent(o)}if(t.add(g),0!==E||0!==f){var o={type:"rotate",thetaDelta:E,phiDelta:f};this.dispatchEvent(o)}this.object.updateMatrix();var i=(new THREE.Matrix4).makeRotationY(E),r=(new THREE.Matrix4).multiplyMatrices(i,this.object.matrix);this.object.quaternion.setFromRotationMatrix(r),this.object.rotation.x+=f,E=0,f=0,y=1,g.set(0,0,0),T.distanceTo(this.object.position)>0&&(this.dispatchEvent(x),T.copy(this.object.position))},this.reset=function(){P=b.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",n,!1),this.domElement.addEventListener("DOMMouseScroll",n,!1),window.addEventListener("keydown",s,!1),window.addEventListener("keyup",a,!1)},THREE.FirstPersonControls.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,r){this.start=e,this.end=t,this.width=o,this.depth=i,this.callback=r,this.loadQueue=[];var n=((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(n,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.update=function(e,t){this.updateMatrixWorld(!0),this.visibleGeometry=this.getVisibleGeometry(e);for(var o=[],i=0;i0;){{var s=n.shift(),a=s.node;s.weight}if(a.visible=!0,a.matrixWorld.multiplyMatrices(a.parent.matrixWorld,a.matrix),a instanceof Potree.PointCloudOctreeProxyNode){var l=a.geometryNode;l.loaded===!0?this.replaceProxy(a):this.loadQueue.push(s)}else if(a instanceof THREE.PointCloud){if(this.numVisibleNodes++,this.numVisiblePoints+=a.numPoints,a.material=this.material,this.visibleNodes.push(s),a.level&&(this.maxLevel=Math.max(a.level,this.maxLevel)),this.showBoundingBox&&!a.boundingBoxNode){var c=new THREE.BoxHelper(a);scene.add(c),this.boundingBoxNodes.push(c),a.boundingBoxNode=c}else this.showBoundingBox?(a.boundingBoxNode.visible=!0,a.boundingBoxNode.matrixWorld.multiplyMatrices(a.parent.matrixWorld,a.boundingBoxNode.matrix)):!this.showBoundingBox&&a.boundingBoxNode&&(a.boundingBoxNode.visible=!1);for(var i=0;i=0;if(h)for(var u=0;u0;){var v=n.shift();if(v instanceof Potree.PointCloudOctreeProxyNode){var f=Potree.utils.computeTransformedBoundingBox(v.boundingBox,v.matrixWorld),E=f.getBoundingSphere();Math.abs(p.distanceToPoint(E.center))0){var v=b.loadQueue[0],l=v.geometryNode;if(l.loaded===!0&&void 0!==v.parent){var a=this.replaceProxy(v);a.updateMatrixWorld(),a.matrixWorld.multiplyMatrices(a.parent.matrixWorld,a.matrix)}else v.geometryNode.load()}else{var P=this.getProfile(b.start,b.end,b.width,b.depth);b.callback({type:"finished",points:P}),T.push(b)}}for(var i=0;i-1&&this.profileRequests.splice(x,1)}if(this.loadQueue.length>0){this.loadQueue.length>=2&&this.loadQueue.sort(function(e,t){return t.weight-e.weight});for(var i=0;i0;){y++;var g=p.shift(),T=g.node,b=T.boundingBox,v=T.boundingSphere,P=i.intersectsBox(b),x=P;if(x){if(m+T.numPoints>this.visiblePointsTarget)break;m+=T.numPoints,t.push(g);for(var R in T.children){var w=T.children[R],v=w.boundingSphere,f=v.center.distanceTo(h),H=v.radius,E=v.radius/f,C=e.fov/2*Math.PI/180,M=1/Math.tan(C)*H/Math.sqrt(f*f-H*H);if(!(.1>M))if(E=M,0>f-H&&(E=Number.MAX_VALUE),0===p.length)p.push({node:w,weight:E});else{for(var S=0,L=0;Lp[L].weight){var S=L;break}if(L==p.length-1){S=p.length;break}}p.splice(S,0,{node:w,weight:E})}}}}return t},Potree.PointCloudOctree.prototype.updateVisibilityTexture=function(){if(this.material){for(var e=this.material.visibleNodesTexture,t=e.image.data,o=[],i=0;io?-1:o>i?1:0};o.sort(r);for(var i=0;it.name?1:0}),t[3*i+0]=0,t[3*i+1]=0,t[3*i+2]=0;for(var a=0;an;n++)if(void 0!==t.children[n]){var s=t.children[n],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;){var v=n.shift(),f=0;if(v instanceof THREE.PointCloud)for(var E=v.geometry,y=E.attributes.position,g=y.array,T=y.length/y.itemSize,b=0;T>b;b++){var P=new THREE.Vector3(g[3*b],g[3*b+1],g[3*b+2]);P.applyMatrix4(this.matrixWorld);var x=Math.abs(u.distanceToPoint(P)),R=Math.abs(p.distanceToPoint(P));o/2>x&&a/2>R&&(m.push(P),f++)}if(v==this||v.levelt)},Potree.PointCloudOctree.disposeNode=function(e){var t=0,o=0,i=[];e.traverse(function(e){i.push(e)});for(var r=0;r1||(this.loading=!0,Potree.PointCloudOctree.lru.numPoints+this.numPoints>=Potree.pointLoadLimit&&Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints),this.pcoGeometry.numNodesLoading++,this.pcoGeometry.loader.load(this))},Potree.BinaryNodeLoader=function(){},Potree.BinaryNodeLoader.load=function(e,t,o){var i=e.pcoGeometry.octreeDir+"/"+e.name;void 0!==t&&t.length>0&&(i+="."+t);var r=new XMLHttpRequest;r.open("GET",i,!0),r.responseType="arraybuffer",r.overrideMimeType("text/plain; charset=x-user-defined"),r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status||0===r.status){var t=r.response;o(e,t)}else console.log("Failed to load file! HTTP status: "+r.status+", file: "+i)};try{r.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",r=[e+"px"+i,e+"nx"+i,e+"py"+i,e+"ny"+i,e+"pz"+i,e+"nz"+i],n=THREE.ImageUtils.loadTextureCube(r,new THREE.CubeRefractionMapping),s=new THREE.MeshBasicMaterial({color:16777215,envMap:n,refractionRatio:.95}),a=THREE.ShaderLib.cube;a.uniforms.tCube.value=n;var 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 o.add(l),{camera:t,scene:o}},Potree.utils.createGrid=function(e,t,o,i){for(var r=new THREE.LineBasicMaterial({color:i||8947848}),n=new THREE.Geometry,s=0;t>=s;s++)n.vertices.push(new THREE.Vector3(-(o*e)/2,0,s*o-o*t/2)),n.vertices.push(new THREE.Vector3(+(o*e)/2,0,s*o-o*t/2));for(var s=0;e>=s;s++)n.vertices.push(new THREE.Vector3(s*o-o*e/2,0,-(o*t)/2)),n.vertices.push(new THREE.Vector3(s*o-o*e/2,0,+(o*t)/2));var a=new THREE.Line(n,r,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 r=i.image.data,n=[1,1.5,1.7],s=o(0,0),a=0;e>a;a++)for(var l=0;t>l;l++){var c=2*(a/e)-1,d=2*(l/t)-1,h=a+e*l,u=o(2*c,2*d)/s,p=(Math.random()+Math.random()+Math.random())/3;p=(.5*u+.5)*p*.03,p=.4*p,r[3*h+0]=255*(u/15+.05+p)*n[0],r[3*h+1]=255*(u/15+.05+p)*n[1],r[3*h+2]=255*(u/15+.05+p)*n[2]}return i},Potree.TextSprite=function(e){var t=new THREE.Texture,o=new THREE.SpriteMaterial({map:t,useScreenCoordinates:!1});THREE.Sprite.call(this,o),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.text="",this.setText(e)},Potree.TextSprite.prototype=new THREE.Sprite,Potree.TextSprite.prototype.setText=function(e){this.text=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,r=i+2*this.borderThickness,n=1.4*this.fontsize+2*this.borderThickness,e=document.createElement("canvas"),t=e.getContext("2d");t.canvas.width=r,t.canvas.height=n,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(255, 255, 255, 1.0)",t.fillText(this.text,this.borderThickness,this.fontsize+this.borderThickness);var s=new THREE.Texture(e);s.needsUpdate=!0,this.material.map=s,this.scale.set(.01*r,.01*n,1)},Potree.TextSprite.prototype.roundRect=function(e,t,o,i,r,n){e.beginPath(),e.moveTo(t+n,o),e.lineTo(t+i-n,o),e.quadraticCurveTo(t+i,o,t+i,o+n),e.lineTo(t+i,o+r-n),e.quadraticCurveTo(t+i,o+r,t+i-n,o+r),e.lineTo(t+n,o+r),e.quadraticCurveTo(t,o+r,t,o+r-n),e.lineTo(t,o+n),e.quadraticCurveTo(t,o,t+n,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=e.substr(0,t),this.versionMinor=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.AreaTool=function(e,t,o){function i(e){this.points=[],this.spheres=[],this.edges=[],this.sphereLabels=[],this.edgeLabels=[],this.root=e,this.closed=!0,this.areaLabel=new Potree.TextSprite,this.areaLabel.setBorderColor({r:0,g:255,b:0,a:0}),this.areaLabel.setBackgroundColor({r:0,g:255,b:0,a:0}),this.areaLabel.material.depthTest=!1,this.areaLabel.material.opacity=1,e.add(this.areaLabel);var t=new THREE.SphereGeometry(.4,10,10),o=new THREE.Color(16711680),i=function(){var e=new THREE.MeshLambertMaterial({shading:THREE.SmoothShading,color:16711680,ambient:11184810,depthTest:!1,depthWrite:!1});return e};this.add=function(e){this.points.push(e);var r=new THREE.Mesh(t,i());r.addEventListener("mousemove",m),r.addEventListener("mouseleave",v),r.addEventListener("mousedrag",f),r.addEventListener("drop",E);var n=new THREE.Geometry;n.vertices.push(new THREE.Vector3,new THREE.Vector3),n.colors.push(o,o,o);var s=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors,linewidth:2});s.depthTest=!1;var a=new THREE.Line(n,s),l=new Potree.TextSprite("abc");l.setBorderColor({r:0,g:255,b:0,a:0}),l.setBackgroundColor({r:0,g:255,b:0,a:0}),l.material.depthTest=!1,l.material.opacity=1,this.root.add(r),this.root.add(a),this.root.add(l),this.spheres.push(r),this.edges.push(a),this.edgeLabels.push(l),this.setPosition(this.points.length-1,e)},this.remove=function(e){this.points.splice(e,1),this.root.remove(this.spheres[e]),this.root.remove(this.edges[e]),this.root.remove(this.edgeLabels[e]),this.spheres.splice(e,1),this.edges.splice(e,1),this.edgeLabels.splice(e,1),this.update()},this.getArea=function(){for(var e=0,t=this.points.length-1,o=0;o=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],r=this.spheres[i],n=0===i?o:i-1,s=i===o?0:i+1,a=this.points[n],l=this.points[s],c=this.edges[n],d=this.edges[i],h=this.edgeLabels[n],u=this.edgeLabels[i],p=e.distanceTo(a),m=e.distanceTo(l),v=(new THREE.Vector3).addVectors(a,e).multiplyScalar(.5),f=(new THREE.Vector3).addVectors(e,l).multiplyScalar(.5);h.position.copy(v),u.position.copy(f),h.setText(p.toFixed(2)),u.setText(m.toFixed(2)),r.position.copy(e),c.geometry.vertices[1].copy(e),c.geometry.verticesNeedUpdate=!0,c.geometry.computeBoundingSphere(),d.geometry.vertices[0].copy(e),d.geometry.verticesNeedUpdate=!0,d.geometry.computeBoundingSphere(),i!==o||this.closed?(d.visible=!0,u.visible=!0):(d.visible=!1,u.visible=!1),t.add(e)}t.multiplyScalar(1/this.points.length);var E=Potree.utils.addCommas(this.getArea().toFixed(1))+"²";this.areaLabel.setText(E),this.areaLabel.position.copy(t)}}function r(e){if(h.enabled){var t=d();if(t){var o=t.clone();p===u.DEFAULT&&(p=u.PICKING,h.activeMeasurement=new i),h.activeMeasurement.add(o);var e={type:"newpoint",position:o.clone()};h.dispatchEvent(e)}}}function n(e){if(h.mouse.x=e.clientX/h.domElement.clientWidth*2-1,h.mouse.y=2*-(e.clientY/h.domElement.clientHeight)+1,h.dragstart)h.dragstart.object.dispatchEvent({type:"mousedrag",event:e});else if(p==u.PICKING&&h.activeMeasurement){var t=d();if(t){var o=h.activeMeasurement.points.length-1;h.activeMeasurement.setPosition(o,t)}}else{var t=c();t?(t.object.dispatchEvent({type:"mousemove",target:t.object,event:e}),h.hoveredElement&&h.hoveredElement!==t.object&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=t.object):(h.hoveredElement&&h.hoveredElement.dispatchEvent({type:"mouseleave",target:h.hoveredElement,event:e}),h.hoveredElement=null)}}function s(){p==u.PICKING&&(h.activeMeasurement.remove(h.activeMeasurement.points.length-1),h.measurements.push(h.activeMeasurement),h.activeMeasurement=void 0,p=u.DEFAULT,h.setEnabled(!1))}function a(e){if(1===e.which){var t=c();t&&(h.dragstart={object:t.object,sceneClickPos:t.point,sceneStartPos:h.sceneRoot.position.clone(),mousePos:{x:h.mouse.x,y:h.mouse.y}})}else 3===e.which&&s(e)}function l(e){h.dragstart&&(h.dragstart.object.dispatchEvent({type:"drop",event:e}),h.dragstart=null)}function c(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=new THREE.Raycaster;t.ray.set(h.camera.position,e.sub(h.camera.position).normalize());for(var o=[],i=0;i0?s[0]:!1}function d(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var r=null,n=null,s=0;sc)&&(r=l,n=c)}}return r?r.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.accuracy=.5;{var u={DEFAULT:0,PICKING:1},p=u.DEFAULT;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)},f=function(e){var t=d();if(t)for(var o=0;o=0){h.measurements[o].setPosition(r,t);break}}e.event.stopImmediatePropagation()},E=function(){};this.setEnabled=function(e){this.enabled!==e&&(this.enabled=e,e&&(p=u.PICKING,h.activeMeasurement=new i(h.sceneRoot),h.activeMeasurement.add(new THREE.Vector3(0,0,0))))
+},this.update=function(){for(var e=[],o=0;o0?s[0]:!1}function h(){var e=new THREE.Vector3(u.mouse.x,u.mouse.y,.5);e.unproject(u.camera);var t=e.sub(u.camera.position).normalize(),o=new THREE.Ray(u.camera.position,t),i=[];u.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var r=null,n=null,s=0;sc)&&(r=l,n=c)}}return r?r.position:null}var u=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.accuracy=.5;var p={DEFAULT:0,PICKING:1},m=p.DEFAULT,v=new THREE.SphereGeometry(.4,10,10);this.activeMeasurement,this.measurements=[],this.sceneMeasurement=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneMeasurement.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneMeasurement.add(this.light),this.hoveredElement=null;var f=function(e){e.target.material.emissive.setHex(8947848)},E=function(e){e.target.material.emissive.setHex(0)},y=function(e){var t=h();if(t)for(var o=0;o=0){var n=i.spheres[r];if(0===r){var s=i.edges[r],a=i.edgeLabels[r];n.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),c=s.geometry.vertices[0].distanceTo(s.geometry.vertices[1]).toFixed(2);a.position.copy(l),a.setText(c),a.scale.multiplyScalar(10)}else if(r===i.spheres.length-1){var s=i.edges[r-1],a=i.edgeLabels[r-1];n.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),c=s.geometry.vertices[0].distanceTo(s.geometry.vertices[1]).toFixed(2);a.position.copy(l),a.setText(c),a.scale.multiplyScalar(10)}else{var d=i.edges[r-1],p=i.edges[r],m=i.edgeLabels[r-1],v=i.edgeLabels[r];n.position.copy(t),d.geometry.vertices[1].copy(t),d.geometry.verticesNeedUpdate=!0,d.geometry.computeBoundingSphere(),p.geometry.vertices[0].copy(t),p.geometry.verticesNeedUpdate=!0,p.geometry.computeBoundingSphere();var f=d.geometry.vertices[0].clone().add(d.geometry.vertices[1]).multiplyScalar(.5),E=d.geometry.vertices[0].distanceTo(d.geometry.vertices[1]).toFixed(2);m.position.copy(f),m.setText(E),m.scale.multiplyScalar(10);var y=p.geometry.vertices[0].clone().add(p.geometry.vertices[1]).multiplyScalar(.5),g=p.geometry.vertices[0].distanceTo(p.geometry.vertices[1]).toFixed(2);v.position.copy(y),v.setText(g),v.scale.multiplyScalar(10)}break}}e.event.stopImmediatePropagation()},g=function(){};this.setEnabled=function(e){if(this.enabled!==e&&(this.enabled=e,e)){m=p.PICKING,u.activeMeasurement=new i;var t=new THREE.Mesh(v,r());u.sceneRoot.add(t),u.activeMeasurement.spheres.push(t),t.addEventListener("mousemove",f),t.addEventListener("mouseleave",E),t.addEventListener("mousedrag",y),t.addEventListener("drop",g)}},this.update=function(){for(var e=[],o=0;o1){var n=new THREE.Geometry;n.vertices.push(new THREE.Vector3,new THREE.Vector3),n.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(n,s);a.visible=!1,this.add(a),this.edges.push(a);var l=new THREE.BoxGeometry(1,1,1),c=new THREE.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.2}),d=new THREE.Mesh(l,c);d.visible=!1,this.add(d),this.boxes.push(d)}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=n;n++){{var e=this.points[n],s=this.spheres[n],a=0===n?r:n-1,l=n===r?0:n+1,c=this.points[a],d=this.points[l],h=this.edges[a],u=this.edges[n],p=this.boxes[a];this.boxes[n],e.distanceTo(c),e.distanceTo(d),(new THREE.Vector3).addVectors(c,e).multiplyScalar(.5),(new THREE.Vector3).addVectors(e,d).multiplyScalar(.5)}if(s.position.copy(e),h&&(h.geometry.vertices[1].copy(e),h.geometry.verticesNeedUpdate=!0,h.geometry.computeBoundingSphere()),u&&(u.geometry.vertices[0].copy(e),u.geometry.verticesNeedUpdate=!0,u.geometry.computeBoundingSphere()),p){var m=c,v=e,f=m.clone().setY(0).distanceTo(v.clone().setY(0));p.scale.set(f,this.height,this.width);var E=(new THREE.Vector3).addVectors(m,v).multiplyScalar(.5),y=(new THREE.Vector3).subVectors(v,m),g=new THREE.Vector3(y.z,0,-y.x);p.position.set(0,0,0),p.lookAt(g),p.position.copy(E)}i.add(e),t.min(e),o.max(e)}i.multiplyScalar(1/this.points.length);for(var n=0;n0?o[0]:!1}function d(){var e=new THREE.Vector3(h.mouse.x,h.mouse.y,.5);e.unproject(h.camera);var t=e.sub(h.camera.position).normalize(),o=new THREE.Ray(h.camera.position,t),i=[];h.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var r=null,n=null,s=0;sc)&&(r=l,n=c)}}return r?r.position:null}var h=this;this.enabled=!1,this.scene=e,this.camera=t,this.renderer=o,this.domElement=o.domElement,this.mouse={x:0,y:0},this.accuracy=.5;{var u={DEFAULT:0,INSERT:1},p=u.DEFAULT;new THREE.SphereGeometry(.4,10,10)}this.activeProfile,this.profiles=[],this.sceneProfile=new THREE.Scene,this.sceneRoot=new THREE.Object3D,this.sceneProfile.add(this.sceneRoot),this.light=new THREE.DirectionalLight(16777215,1),this.light.position.set(0,0,10),this.light.lookAt(new THREE.Vector3(0,0,0)),this.sceneProfile.add(this.light),this.hoveredElement=null;var m=function(e){e.target.material.emissive.setHex(8947848)},v=function(e){e.target.material.emissive.setHex(0)},f=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,r=1-10*(t.y-o.y);if(r=Math.max(.01,r),i)for(var n=0;n=0){s.setWidth(i*r),s.update();break}}}else{var l=d();if(l)for(var n=0;n=0){h.profiles[n].setPosition(a,l);break}}}e.event.stopImmediatePropagation()},E=function(){};i.prototype=Object.create(THREE.Object3D.prototype),this.startInsertion=function(e){p=u.INSERT;var e=e||{},t=e.clip||!1,o=e.width||1;this.activeProfile=new i,this.activeProfile.clip=t,this.activeProfile.setWidth(o),this.sceneProfile.add(this.activeProfile),this.profiles.push(this.activeProfile),this.activeProfile.addMarker(new THREE.Vector3(0,0,0))},this.finishInsertion=function(){this.activeProfile.removeMarker(this.activeProfile.points.length-1),this.activeProfile=null,p=u.DEFAULT},this.update=function(){for(var e=0;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),r=new THREE.Mesh(i,new THREE.MeshBasicMaterial({color:11184810,transparent:!0,opacity:.4}));this.sceneRotation.add(r);var n=function(){r.material.color.setHex(5592405)},s=function(){r.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),r=t.clone().unproject(a.camera),n=o.clone().unproject(a.camera),s=(new THREE.Vector3).subVectors(n,r),l=s.clone().normalize(),c=(new THREE.Vector3).subVectors(a.camera.position,r).normalize(),d=c.clone().cross(l),h=6*i.length(),u=0;u=r;r++){var n=2*Math.PI*r/i,s=3*Math.cos(n),l=3*Math.sin(n);o.push(new THREE.Vector3(s,l,0))}for(var c=new THREE.Geometry,r=0;r0){var i=o[0];t.push({distance:i.distance,object:this,point:i.point.clone()})}}}function r(e){d.mouse.x=e.clientX/d.domElement.clientWidth*2-1,d.mouse.y=2*-(e.clientY/d.domElement.clientHeight)+1}function n(){}function s(e){if(u===h.INSERT_VOLUME)d.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(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 o=[],i=0;i0?n[0]:!1}function c(){var e=new THREE.Vector3(d.mouse.x,d.mouse.y,.5);e.unproject(d.camera);var t=e.sub(d.camera.position).normalize(),o=new THREE.Ray(d.camera.position,t),i=[];d.scene.traverse(function(e){e instanceof Potree.PointCloudOctree&&i.push(e)});for(var r=null,n=null,s=0;sc)&&(r=l,n=c)}}return r?r.position:null}var d=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.accuracy=.5,this.volumes=[];
+var h={DEFAULT:0,INSERT_VOLUME:1},u=h.DEFAULT,p=new THREE.BoxGeometry(1,1,1);p.computeBoundingBox();var m=new THREE.Geometry;m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,.5)),m.vertices.push(new THREE.Vector3(-.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,.5)),m.vertices.push(new THREE.Vector3(.5,.5,.5)),m.vertices.push(new THREE.Vector3(.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(.5,.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,-.5,-.5)),m.vertices.push(new THREE.Vector3(-.5,.5,-.5)),i.prototype=Object.create(THREE.Object3D.prototype),Object.defineProperty(i.prototype,"clip",{get:function(){return this._clip},set:function(e){this._clip=e,this._clip?(this.box.visible=!1,this.label.visible=!1):(this.box.visible=!0,this.label.visible=!0)}}),this.update=function(){if(u===h.INSERT_VOLUME){var e=c();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=[],r=0;r Settings -> Transfers -> File Types -> Default Transfer Type
+
+Another option is to pack all your data into a zip file, upload it and unpack it on the server.
+
+### Are you using IIS?
+
+IIS may cause problems with files that have no extension, such as the data/r* files for potree format up to 1.3.
+
+In this case, you can try to configure IIS:
+http://www.serverintellect.com/support/iis/enable-no-extensions/
+
+## The converted point cloud is black
+
+As of now, the PotreeConvert expects rgb colors in LAS or LAZ files in a range of 0-65536.
+If you have colors in a 0-255 range, you will have to upscale them before conversion.
+You can use the [lastools](http://rapidlasso.com/lastools/) to do this:
+
+```
+las2las -i pointcloud.las -scale_rgb_up
+```
+
+
+
+## Can I use potree for commercial projects?
+
+Yes, the license allows you to do this free of charge. If you do use potree, please consider supporting this project with a donation.
diff --git a/docs/file_format.md b/docs/file_format.md
index 4187ea0f..5e0c6346 100644
--- a/docs/file_format.md
+++ b/docs/file_format.md
@@ -36,10 +36,10 @@ indicate which child it is.
Child nodes are arranged like this:
- 3----7
- /| /|
- y 2----6 |
- | -z | 1--|-5
+ 3----7
+ /| /|
+ y 2----6 |
+ | -z | 1--|-5
|/ |/ |/
O----x 0----4
@@ -54,7 +54,8 @@ Stores information about the pointcloud in JSON format.
necessary so that parsers know how to interpret the data.
* __octreeDir__ - Directory or URL where node data is stored. Usually points to
"data".
-* __boundingBox__ - Contains the minimum and maximum of the axis aligned bounding box.
+* __boundingBox__ - Contains the minimum and maximum of the axis aligned bounding box. This bounding box is cubic and aligned to fit to the octree root.
+* __tightBoundingBox__ - This bounding box thightly fits the point data.
* __pointAttributes__ - Declares the point data format.
As of now, only ["POSITION_CARTESIAN", "COLOR_PACKED"] is supported which
stores each point in 16 bytes. The first 12 bytes contain x/y/z coordinates and
@@ -96,6 +97,6 @@ The nodes must be stored top to bottom, i.e. root at the beginning and leaf-node
The node files in the data directory contain the point data.
With point attributes set to "POSITION_CARTESIAN" and "COLOR_PACKED",
-each point will be stored as 3x32bit floats for the xyz-coordinates and 4 unsigned bytes to store
+each point will be stored as 3x32bit signed integers for the xyz-coordinates and 4 unsigned bytes to store
rgba data. All data is stored in little endian order.
Other formats are not supported at the moment.
diff --git a/docs/getting_started.md b/docs/getting_started.md
index e321f375..efbc4dcc 100644
--- a/docs/getting_started.md
+++ b/docs/getting_started.md
@@ -1,190 +1,27 @@
# Getting Started
+Read the [FAQ](faq.md) if you encounter any problems.
+
+
## Converting A Point Cloud
-Potree requires a special point cloud format. Use the PotreeConverter to convert las, ply or xyz files into this format.
-See [PotreeConverter - usage](https://github.com/potree/PotreeConverter)
+Potree requires a special point cloud format. Use the [PotreeConverter](https://github.com/potree/PotreeConverter) to convert your las or laz files.
-## Including Source Files
+Try this for your first point cloud and then take a look at [conversion manual](converting.md) to learn more about the converter options to get better results:
+```
+./PotreeConverter.exe pointcloud.las -l 3
+```
-This example needs three.js, OrbitControls.js, and the potree source files:
+Copy the converted point cloud directory (with cloud.js + data directory) to _./resources/pointclouds_
-
-
-
-
-
-
-
-
-
+## Creating the Web Page
-## Setting Up The Scene
+Copy examples/viewer.html and change the path to your own point cloud.
-In this section, we will set up a simple scene to load and display a point cloud.
-
-
-Potree is built upon the three.js library and so the first step is to
-create a three.js scene, camera and renderer:
-
- scene = new THREE.Scene();
- camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
- renderer = new THREE.WebGLRenderer();
- renderer.setSize(window.innerWidth, window.innerHeight);
- document.body.appendChild(renderer.domElement);
-
-In the next step, we move the camera to position 1 / 7 / 7 and make it point
-to the target at 0 / 4 / 0. The OrbitControls makes it possible to rotate around
-the target by dragging the mouse.
-
- camera.position.set(1, 7, 7);
- controls = new THREE.OrbitControls(camera, renderer.domElement);
- controls.target.set(0, 4, 0 );
- camera.lookAt(controls.target);
-
-In the next few steps, we will load the pointcloud, modify its position and orientation
-and add it to the scene.
-
-First, load the pointcloud:
-
- var pco = POCLoader.load(pointcloudPath);
-
-POCLoader.load() returns a geometry object. Geometry objects can be attached to
-scene nodes, PointCloudOctree in this case, which in turn can be added to the scene:
-
-
- pointcloudMaterial = new THREE.PointCloudMaterial( { size: defaultPointSize, vertexColors: true } );
- pointcloud = new Potree.PointCloudOctree(pco, pointcloudMaterial);
- scene.add(pointcloud);
-
-It is possible to create multiple scene nodes that use the same geometry, if needed.
-
-Usually, the position and orientation of pointclouds must be modified as well.
-Use _moveToOrigin()_ if you want to center your pointcloud around the origin and
- _moveToGroundPlane()_ to put it on top of the ground plane.
- Change the LOD parameter to alter the Level of Detail. A higher LOD results in
- more octree nodes beeing displayed at once. If you experience performance problems,
- try to lower the LOD.
-
- pointcloud.LOD = defaultLOD;
- pointcloud.rotation.set(Math.PI/2, 0.85* -Math.PI/2, -0.0);
- pointcloud.moveToOrigin();
- pointcloud.moveToGroundPlane();
-
-A common problem is that your pointcloud is upside down or the y and z axis are
-flipped. In three.js / WebGL y points upwards while a lot of software packages
-use z as the up-vector.
-
-To fix the upside down problem, you an apply a matrix transformation to mirror
-along the y axis:
-
- pointcloud.applyMatrix(new THREE.Matrix4().set(
- 1,0,0,0,
- 0,-1,0,0,
- 0,0,1,0,
- 0,0,0,1
- ));
-
-To fix the problem with flipped y and z axis, you an apply another matrix transformation:
-
- pointcloud.applyMatrix(new THREE.Matrix4().set(
- 1,0,0,0,
- 0,0,1,0,
- 0,1,0,0,
- 0,0,0,1
- ));
-
-
-## Rendering the Scene
-
-pointcloud.update(camera) loads nodes that are visible from the given camera
-and hides nodes that are not.
-
- pointcloud.update(camera);
-
-Render the scene:
-
- renderer.render(scene, camera);
-
-
-
-## Putting It All Together
-
-This is a complete html file that will display the lion_takanawa pointcloud
-that is included in the potree repository.
-Make sure to put the html file into the potree root dir (not ./examples) or update
-the pointcloudPath variable.
-
-
-
- Lion
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+```
+var pointcloudPath = "../resources/pointclouds/my_own_pointcloud/cloud.js";
+```
## Deploying Potree On A Webserver
@@ -201,7 +38,7 @@ alone should work fine:
After you've installed apache/XAMPP, start it and copy your potree directory
to the htdocs directory. You should now be able to access your localy hosted files like this:
- http://localhost/potree/pointcloud.html
+ http://localhost/potree/examples/my_own_viewer.html

diff --git a/docs/images/lion_demo_screenshot.jpg b/docs/images/lion_demo_screenshot.jpg
index df01222f..197b869a 100644
Binary files a/docs/images/lion_demo_screenshot.jpg and b/docs/images/lion_demo_screenshot.jpg differ
diff --git a/docs/images/potree_screens.png b/docs/images/potree_screens.png
new file mode 100644
index 00000000..e21fd379
Binary files /dev/null and b/docs/images/potree_screens.png differ
diff --git a/docs/measuring.md b/docs/measuring.md
new file mode 100644
index 00000000..f6705f72
--- /dev/null
+++ b/docs/measuring.md
@@ -0,0 +1,15 @@
+
+# Measuring
+
+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.
+
+
+## Height Profile
+
+
+To get points inside a height profile, use this:
+```
+var maxOctreeDepth = 2;
+var points = pointcloud.getPointsInProfile(profileTool.profiles[0], maxOctreeDepth);
+console.log(points);
+```
diff --git a/docs/user_interface.md b/docs/user_interface.md
new file mode 100644
index 00000000..90c7ddda
--- /dev/null
+++ b/docs/user_interface.md
@@ -0,0 +1,82 @@
+
+# User Interface
+
+
+
+
+
+ __Fly-Navigation__
+
+ASDW or Arrow Keys: Move through scene
+
+Left Mouse: Rotate camera
+
+
+ __Orbit-Navigation__
+
+Left Mouse: Rotate camera around pivot.
+
+Right Mouse: Pan camera & pivot.
+
+ __Zoom to Point Cloud__
+
+Moves camera so that the whole point cloud is within the view area.
+
+ __Flip Y and Z__
+
+Flips y and -z coordinates. Some software uses y as the up vector(WebGL, three.js, potree), others use z.
+
+ __Distance Measurement__
+
+Left Mouse: Insert Measurement Point
+
+Right Mouse: Finish insertion
+
+Drag&Drop: Move Measurement Points
+
+Distance between measurement points will be displayed on the edge.
+
+ __Area Measurement__
+
+Left Mouse: Insert Measurement Point
+
+Right Mouse: Finish insertion
+
+Drag&Drop: Move Measurement Points
+
+Distance between measurement points will be displayed on the edge and the
+total area on the centroid.
+The area is calculated on the ground plane. The height does not affect the result.
+Crossings should be avoided.
+
+ __Volume Measurement__
+
+Left Mouse: Insert Volume or Select Inserted Volume
+
+E, R, T: Switch between translation, scale and rotation mode.
+
+Volume will be displayed on the objects centroid.
+
+ __Height Profile__
+
+Left Mouse: Insert Profile Marker
+
+Right Mouse: Finish insertion
+
+Drag&Drop: Move Profile Marker
+
+ctrl + Drag&Drop: Drag upwards to increase or downwards to decrease the profile width
+
+Depending on the Clip Mode, points inside the profile will be highlighted or points outside the profile will be clipped.
+
+
+ __Clip Volume__
+
+Left Mouse: Insert Volume or Select Inserted Volume
+
+E, R, T: Switch between translation, scale and rotation mode.
+
+Depending on the Clip Mode, points inside the volume will be highlighted or points outside the volume will be clipped.
+
+
+
diff --git a/examples/georeferencing_measurement_heightprofile.html b/examples/georeferencing.html
similarity index 76%
rename from examples/georeferencing_measurement_heightprofile.html
rename to examples/georeferencing.html
index 12b733a7..88cd210c 100644
--- a/examples/georeferencing_measurement_heightprofile.html
+++ b/examples/georeferencing.html
@@ -52,23 +52,6 @@ To transform the swissCoordinates to local coordinates, use
var sceneCoordinate = toLocal(new THREE.Vector3(swissCoordinate[0], swissCoordinate[1], 0));
-
-== Profile ==
-
-There are 2 ways to get a height profile:
-- ProfileTool: renders points inside the profile area into a texture.
-- pointcloud.getProfile(): Returns points inside the profile area
-
-In this demo, both are used side by side. The ProfileTool is very fast and can be used as a
-preview to the result of the getProfile() function.
-The depth parameter specifies the detail level of the result.
-Especially with higher depth values, it is likely that not all the octree nodes necessary
-for the calculation have been loaded, yet which is why you can provide a callback function
-that is called once all the necessary nodes have been loaded and the point profile has been calculated.
-If you call getProfile without a callback, it will ignore unloaded nodes and immediately return
-a result.
-
-
== GeoExtent ==
You can get the boundaries of the currently visible parts using pointcloud.getVisibleExtent()
@@ -144,17 +127,11 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
potree.org
Point cloud courtesy of sigeom sa
+ Georeferencing - Check "coordinates" to display mouse hover coordinates on the bottom left
-
- Georeferencing, Height Profile and Measurement.
- Double click to generate measurement points.
- Drag endpoints of red line in map window to modify the profile.
- Check "coordinates" to display mouse hover coordinates on the bottom left.
- Push the button to create some spheres along the profile
-
@@ -183,10 +160,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
var minWeb = proj4(swiss, webMercator, [minSwiss[0], minSwiss[1]]);
var maxWeb = proj4(swiss, webMercator, [maxSwiss[0], maxSwiss[1]]);
- // default values for start and end of profile in Web Mercator
- var profileStart = proj4(swiss, webMercator, [589468, 231313]);
- var profileEnd = proj4(swiss, webMercator, [590134, 231328]);
-
// bounds of the EPSG:21781 projection
//var swissMin = new THREE.Vector3(485869.5728, 76443.1884, 0);
//var swissMax = new THREE.Vector3(837076.5648, 299941.7864, 0);
@@ -195,7 +168,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
var featureVector;
var camFrustumFeatureVector;
var camFrustum;
- var profileOverlay;
var visibleBounds;
// three.js / potree stuff
@@ -206,8 +178,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
var skybox;
var pointcloud;
var clock = new THREE.Clock();
- var measuringTool;
- var profileTool;
var showCoordinates = false;
var mouse = {x: 0, y: 0};
var elCoordinates = document.getElementById("lblCoordinates");
@@ -333,36 +303,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
})
});
- {// profile layer
- profileOverlay = new ol.FeatureOverlay({
- style: new ol.style.Style({
- fill: new ol.style.Fill({
- color: 'rgba(255, 255, 255, 0.2)'
- }),
- stroke: new ol.style.Stroke({
- color: '#ff0000',
- width: 2
- }),
- image: new ol.style.Circle({
- radius: 7,
- fill: new ol.style.Fill({
- color: '#ff0000'
- })
- })
- })
- });
- profileOverlay.setMap(map);
-
- var profile = new ol.geom.LineString([profileStart, profileEnd]);
- var profileFeature = new ol.Feature(profile);
- profileOverlay.addFeature(profileFeature);
-
- // enable drag modification of the profile line
- var modify = new ol.interaction.Modify({
- features: profileOverlay.getFeatures(),
- });
- map.addInteraction(modify);
- }
}
function initPotreeView(){
@@ -393,11 +333,13 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
controls.moveSpeed *= 10;
camera.position.set(600, 880, -370);
camera.lookAt(new THREE.Vector3(480, 797, -219));
+
+ referenceFrame = new THREE.Object3D();
// load pointcloud
var pco = POCLoader.load(pointcloudPath, function(geometry){
offset = geometry.offset;
- pointcloud = new Potree.PointCloudOctree(geometry, new Potree.PointCloudMaterial());
+ pointcloud = new Potree.PointCloudOctree(geometry);
pointcloud.material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
pointcloud.material.size = pointSize;
pointcloud.visiblePointsTarget = pointCountTarget * 1000 * 1000;
@@ -405,9 +347,13 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
// the reference frame transforms the point cloud into the scene coordinate system
// by moving it towards the origin and flipping the y and z axes.
// This is necessary to avoid precision errors due to large floating point values.
- referenceFrame = new THREE.Object3D();
+ referenceFrame.add(pointcloud);
+
+ referenceFrame.updateMatrixWorld(true);
+
referenceFrame.position.set(-pointcloud.position.x, -pointcloud.position.y, 0);
- referenceFrame.updateMatrix();
+
+ referenceFrame.updateMatrixWorld(true);
referenceFrame.applyMatrix(new THREE.Matrix4().set(
1,0,0,0,
0,0,1,0,
@@ -415,35 +361,8 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
0,0,0,1
));
scene.add(referenceFrame);
- referenceFrame.add(pointcloud);
- referenceFrame.updateMatrixWorld();
});
- // create measuring tool
- measuringTool = new Potree.MeasuringTool(scene, camera, renderer);
- measuringTool.addEventListener("newpoint", function(event){
- point = toGeo(event.position);
-
- // transform from swiss projection to Web Mercator
- var swiss = proj4.defs("EPSG:21781");
- var WGS84 = proj4.defs("WGS84");
- var coordinate = proj4(swiss, webMercator, [point.x, point.y]);
-
- // add a point to the OpenLayers map
- var olPoint = new ol.geom.Point(coordinate);
- var feature = new ol.Feature(olPoint);
- featureVector.addFeature(feature);
- });
-
- // create profile tool
- profileTool = new Potree.ProfileTool(400, 200, 10);
- profileTool.position.set(0,0,0);
- scene.add(profileTool);
- sceneHUD.add(profileTool.hudElement);
- profileTool.setCoordinates(
- new THREE.Vector3(-32, 750, -13),
- new THREE.Vector3(634, 750, -28));
-
renderer.domElement.addEventListener( 'mousemove', onMouseMove, false );
}
@@ -579,7 +498,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
pointcloud.update(camera, renderer);
updateMapFrustum();
updateCoordinatePicking();
- updateProfile();
updateMapExtent();
updateProgressBar();
}
@@ -682,39 +600,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
]);
}
- /**
- * Update the ProfileTools start and end according to the users modification
- * in the map window
- */
- function updateProfile(){
- var features = profileOverlay.getFeatures();
- if(features.getArray().length == 0){
- return;
- }
-
- var geometry = profileOverlay.getFeatures().getArray()[0].getGeometry();
- var coordinates = geometry.getCoordinates();
-
- if(coordinates.length < 2){
- return;
- }
-
- var start = new THREE.Vector3(coordinates[0][0], coordinates[0][1], 0);
- var end = new THREE.Vector3(coordinates[1][0], coordinates[1][1], 0);
-
- var startSwiss = proj4(webMercator, swiss, [start.x, start.y]);
- var startScene = toLocal(new THREE.Vector3(startSwiss[0], startSwiss[1], 0));
-
- var endSwiss = proj4(webMercator, swiss, [end.x, end.y]);
- var endScene = toLocal(new THREE.Vector3(endSwiss[0], endSwiss[1], 0));
-
- startScene.y = 750;
- endScene.y = 750;
-
- profileTool.setCoordinates(startScene, endScene);
-
- }
-
function getMousePointCloudIntersection(){
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
vector.unproject(camera);
@@ -761,11 +646,6 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
renderer.setSize(width, height);
- profileTool.hudElement.scale.x = 400 / width;
- profileTool.hudElement.scale.y = 300 / height;
- profileTool.hudElement.position.x = 1 - 405 / width;
- profileTool.hudElement.position.y = -1 + 905 / height;
-
// render skybox
if(showSkybox){
skybox.camera.rotation.copy(camera.rotation);
@@ -774,44 +654,11 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
// render scenes
- profileTool.render(renderer, scene);
renderer.render(scene, camera);
- measuringTool.render();
renderer.render(sceneHUD, cameraHUD);
}
- /**
- * Demonstrating the pointcloud.getProfile() method by creating spheres at some
- * of the points inside the profile.
- * The depth value specifies the density of the points.
- * This method is async and will call its callback once all the necessary
- * nodes have been loaded. If no callback is given, it will immediately
- * return an array of points and ignore nodes that have not been loaded, yet.
- *
- */
- function doHeightProfile(){
- var start = profileTool.start;
- var end = profileTool.end;
- var width = 10;
- var depth = 4;
-
- var callback = function(event){
- if(event.type === "finished"){
- var points = event.points;
- var sphereGeometry = new THREE.SphereGeometry(1, 5, 5);
- for(var i = 0; i < points.length; i += Math.ceil(points.length / 500)){
- var point = points[i];
- var sphere = new THREE.Mesh(sphereGeometry);
- sphere.position.copy(point);
- scene.add(sphere);
- }
- }
- };
-
- pointcloud.getProfile(start, end, width, depth, callback);
- }
-
function onMouseMove(event){
mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;
diff --git a/examples/lion.html b/examples/lion.html
index 49268999..6484c2e5 100644
--- a/examples/lion.html
+++ b/examples/lion.html
@@ -1,7 +1,7 @@
- Lion
+ Viewer
@@ -28,69 +28,163 @@
}
+
+
+
+
+
+
-
+
+