diff --git a/.vscode/settings.json b/.vscode/settings.json
index 7107b6ac..a740241d 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -11,4 +11,8 @@
"editor.renderWhitespace": "all",
"editor.insertSpaces": false,
"editor.minimap.enabled": false,
+ "editor.autoClosingBrackets": false,
+ "editor.formatOnType": false,
+ "editor.acceptSuggestionOnEnter": "off",
+ "editor.acceptSuggestionOnCommitCharacter": false,
}
\ No newline at end of file
diff --git a/examples/ca13.html b/examples/ca13.html
index ad39eec0..06a58bfb 100644
--- a/examples/ca13.html
+++ b/examples/ca13.html
@@ -82,43 +82,24 @@
viewer.scene.addPointCloud(e.pointcloud);
e.pointcloud.position.z = 0;
let material = e.pointcloud.material;
- material.size = 1;
- material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
+ material.size = 3;
+ //material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
- viewer.switchCameraMode(Potree.CameraMode.ORTHOGRAPHIC);
+ //viewer.switchCameraMode(Potree.CameraMode.ORTHOGRAPHIC);
viewer.scene.view.position.set(695363.0922733713, 3917242.331591645, 4028.0733017667667);
viewer.scene.view.lookAt(695363.0922733713, 3917242.331591645, 64.48734585580951);
+ //viewer.scene.view.position.set(718764.4204117344, 3844982.7670604168, 75920.3357242614);
+ //viewer.scene.view.lookAt(700075.3335721092, 3922856.372034359, 4963.633805953286);
+
+ viewer.scene.view.position.set(694703.0370105016, 3916032.9522472788, 243.5959654984507);
+ viewer.scene.view.lookAt(694676.9779166604, 3916416.8064250476, 25.309048289985384);
+
+ viewer.scene.view.position.set(694991.9150582966, 3916274.3733733483, 76.41774609890476);
+ viewer.scene.view.lookAt(694878.4097257275, 3916332.0674868184, 14.497470898558227);
+
//viewer.fitToScreen();
});
-
- viewer.onGUILoaded(() => {
- let boxSelectTool = new Potree.ScreenBoxSelectTool(viewer);
- window.boxSelectTool = boxSelectTool;
-
- let createToolIcon = function (icon, title, callback) {
- let element = $(`
-
- `);
-
- element.click(callback);
-
- return element;
- };
-
- let clippingToolBar = $("#clipping_tools");
- clippingToolBar.append(createToolIcon(
- Potree.resourcePath + "/icons/clip-polygon.svg",
- "[title]tt.clip_polygon",
- function(){
- let item = boxSelectTool.startInsertion();
- }
- ));
-
- });
diff --git a/examples/clipping_volume.html b/examples/clipping_volume.html
index c46f05b2..cbd5f0df 100644
--- a/examples/clipping_volume.html
+++ b/examples/clipping_volume.html
@@ -96,6 +96,8 @@
scene.view.position.set(590017.55, 231689.93, 1027.90);
scene.view.lookAt(new THREE.Vector3(589807.53, 231410.61, 765.30));
// viewer.fitToScreen();
+
+ viewer.setClipTask(Potree.ClipTask.SHOW_INSIDE)
});
function test(){
diff --git a/examples/heidentor.html b/examples/heidentor.html
index ad09df58..2f92f2aa 100644
--- a/examples/heidentor.html
+++ b/examples/heidentor.html
@@ -32,6 +32,7 @@
+
@@ -64,9 +65,8 @@
viewer.setEDLEnabled(true);
viewer.setFOV(60);
- viewer.setPointBudget(10*1000*1000);
+ viewer.setPointBudget(1*1000*1000);
viewer.setMinNodeSize(0);
- viewer.useEDL = false;
viewer.loadSettingsFromURL();
viewer.setDescription("");
@@ -87,13 +87,43 @@
material.size = 1;
material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
- viewer.switchCameraMode(Potree.CameraMode.ORTHOGRAPHIC);
+ //viewer.setCameraMode(Potree.CameraMode.ORTHOGRAPHIC);
viewer.scene.view.position.set(13.856734292740617, -9.125174923658731, 14.563928417406354);
viewer.scene.view.lookAt(-3.5482630104475366, 2.728596783815762, 6.1406044783018725);
+
+ //viewer.clippingTool.setClipMode(Potree.ClipMode.INSIDE);
//viewer.fitToScreen();
+ //viewer.useHQ = true;
+
//Potree.measureTimings = true;
+
+
+ //{
+ // let volume = new Potree.Volume();
+ // volume.clip = true;
+ // volume.position.set(-2.628, -1.647, 5.946);
+ // volume.scale.set(20, 20, 20);
+ // viewer.scene.addVolume(volume);
+ //}
+
+ {
+ let volume = new Potree.Volume();
+ volume.clip = true;
+ volume.position.set(-2.628, -1.647, 5.946);
+ volume.scale.set(7.82, 1.32, 16.03);
+ viewer.scene.addVolume(volume);
+ }
+
+ {
+ let volume = new Potree.Volume();
+ volume.clip = true;
+ volume.position.set(-2.344, 3.199, 5.647);
+ volume.scale.set(9.04, 17.52, 1.11);
+ viewer.scene.addVolume(volume);
+ }
+
});
diff --git a/examples/heidentor_animated_light_and_shadows.html b/examples/heidentor_animated_light_and_shadows.html
index 2d3829e7..27ed7a79 100644
--- a/examples/heidentor_animated_light_and_shadows.html
+++ b/examples/heidentor_animated_light_and_shadows.html
@@ -12,6 +12,7 @@
+
@@ -30,6 +31,7 @@
+
diff --git a/gulpfile.js b/gulpfile.js
index 8253af0d..34760b05 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -16,15 +16,16 @@ var server;
var paths = {
potree : [
+ "src/KeyCodes.js",
+ "src/extensions/EventDispatcher.js",
+ "src/extensions/PerspectiveCamera.js",
+ "src/extensions/OrthographicCamera.js",
+ "src/extensions/Ray.js",
"src/Potree.js",
"src/PotreeRenderer.js",
"src/PointCloudTree.js",
"src/WorkerPool.js",
"build/shaders/shaders.js",
- "src/extensions/EventDispatcher.js",
- "src/extensions/PerspectiveCamera.js",
- "src/extensions/OrthographicCamera.js",
- "src/extensions/Ray.js",
"src/loader/POCLoader.js",
"src/loader/PointAttributes.js",
"src/loader/BinaryLoader.js",
@@ -34,6 +35,8 @@ var paths = {
"src/materials/PointCloudMaterial.js",
"src/materials/EyeDomeLightingMaterial.js",
"src/materials/BlurMaterial.js",
+ "src/materials/NormalizationMaterial.js",
+ "src/materials/NormalizationEDLMaterial.js",
"src/navigation/InputHandler.js",
"src/navigation/FirstPersonControls.js",
"src/navigation/GeoControls.js",
@@ -73,6 +76,7 @@ var paths = {
"src/arena4d/PointCloudArena4DGeometry.js",
"src/viewer/PotreeRenderer.js",
"src/viewer/EDLRenderer.js",
+ "src/viewer/HQSplatRenderer.js",
"src/viewer/RepRenderer.js",
"src/viewer/View.js",
"src/viewer/Scene.js",
@@ -133,6 +137,7 @@ var shaders = [
"src/materials/shaders/pointcloud_sm.fs",
"src/materials/shaders/normalize.vs",
"src/materials/shaders/normalize.fs",
+ "src/materials/shaders/normalize_and_edl.fs",
"src/materials/shaders/edl.vs",
"src/materials/shaders/edl.fs",
"src/materials/shaders/blur.vs",
diff --git a/resources/icons/copy.svg b/resources/icons/copy.svg
new file mode 100644
index 00000000..11cde80f
--- /dev/null
+++ b/resources/icons/copy.svg
@@ -0,0 +1,106 @@
+
+
+
+
diff --git a/src/KeyCodes.js b/src/KeyCodes.js
new file mode 100644
index 00000000..15b0f077
--- /dev/null
+++ b/src/KeyCodes.js
@@ -0,0 +1,3 @@
+Potree.KeyCodes = {
+ DELETE: 46
+};
\ No newline at end of file
diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js
index 816ac9d5..f280fb75 100644
--- a/src/PointCloudOctree.js
+++ b/src/PointCloudOctree.js
@@ -96,6 +96,7 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
constructor (geometry, material) {
super();
+ this.pointBudget = Infinity;
this.pcoGeometry = geometry;
this.boundingBox = this.pcoGeometry.boundingBox;
this.boundingSphere = this.boundingBox.getBoundingSphere();
@@ -574,7 +575,7 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
let getVal = (a, b) => a !== undefined ? a : b;
- let pickWindowSize = getVal(params.pickWindowSize, 65);
+ let pickWindowSize = getVal(params.pickWindowSize, 17);
let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
let size = renderer.getSize();
@@ -624,10 +625,10 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
pickMaterial.classification = this.material.classification;
if(params.pickClipped){
pickMaterial.clipBoxes = this.material.clipBoxes;
- if(this.material.clipMode === Potree.ClipMode.HIGHLIGHT){
- pickMaterial.clipMode = Potree.ClipMode.DISABLED;
+ if(this.material.clipTask === Potree.ClipTask.HIGHLIGHT){
+ pickMaterial.clipTask = Potree.ClipTask.NONE;
}else{
- pickMaterial.clipMode = this.material.clipMode;
+ pickMaterial.clipTask = this.material.clipTask;
}
}else{
pickMaterial.clipBoxes = [];
@@ -702,14 +703,26 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
pixels[4 * offset + 3] = 0;
let pIndex = ibuffer[offset];
- if (!(pcIndex === 0 && pIndex === 0)) {
+ if(!(pcIndex === 0 && pIndex === 0) && (pcIndex !== undefined) && (pIndex !== undefined)){
let hit = {
pIndex: pIndex,
pcIndex: pcIndex,
distanceToCenter: distance
};
- hits.push(hit);
+ if(params.all){
+ hits.push(hit);
+ }else{
+ if(hits.length > 0){
+ if(distance < hits[0].distanceToCenter){
+ hits[0] = hit;
+ }
+ }else{
+ hits.push(hit);
+ }
+ }
+
+
}
}
}
@@ -747,23 +760,21 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
let node = nodes[hit.pcIndex];
let pc = node.sceneNode;
- let iBuffer = node.geometryNode.buffer;
- let data = iBuffer.data;
- let view = new DataView(data);
+ let geometry = node.geometryNode.geometry;
- let offset = 0;
- for (let attribute of iBuffer.attributes) {
+ for(let attributeName in geometry.attributes){
+ let attribute = geometry.attributes[attributeName];
- if (attribute.name === 'position') {
- let x = view.getFloat32(iBuffer.stride * hit.pIndex + offset + 0, true);
- let y = view.getFloat32(iBuffer.stride * hit.pIndex + offset + 4, true);
- let z = view.getFloat32(iBuffer.stride * hit.pIndex + offset + 8, true);
+ if (attributeName === 'position') {
+ let x = attribute.array[3 * hit.pIndex + 0];
+ let y = attribute.array[3 * hit.pIndex + 1];
+ let z = attribute.array[3 * hit.pIndex + 2];
let position = new THREE.Vector3(x, y, z);
position.applyMatrix4(pc.matrixWorld);
- point[attribute.name] = position;
- } else if (attribute.name === 'indices') {
+ point[attributeName] = position;
+ } else if (attributeName === 'indices') {
} else {
//if (values.itemSize === 1) {
@@ -777,7 +788,6 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
//}
}
- offset += attribute.bytes;
}
hit.point = point;
@@ -792,9 +802,10 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree {
if(hits.length === 0){
return null;
}else{
- let sorted = hits.sort( (a, b) => a.distanceToCenter - b.distanceToCenter);
+ return hits[0].point;
+ //let sorted = hits.sort( (a, b) => a.distanceToCenter - b.distanceToCenter);
- return sorted[0].point;
+ //return sorted[0].point;
}
}
diff --git a/src/Potree.js b/src/Potree.js
index 50526d82..f65d1c83 100644
--- a/src/Potree.js
+++ b/src/Potree.js
@@ -4,8 +4,8 @@ function Potree () {
}
Potree.version = {
major: 1,
- minor: 5,
- suffix: 'RC'
+ minor: 6,
+ suffix: 'RC1'
};
console.log('Potree ' + Potree.version.major + '.' + Potree.version.minor + Potree.version.suffix);
@@ -25,6 +25,8 @@ Potree.webgl = {
vbos: {}
};
+Potree.debug = {};
+
Potree.scriptPath = null;
if (document.currentScript.src) {
Potree.scriptPath = new URL(document.currentScript.src + '/..').href;
@@ -42,6 +44,24 @@ Potree.CameraMode = {
PERSPECTIVE: 1
};
+Potree.ClipTask = {
+ NONE: 0,
+ HIGHLIGHT: 1,
+ SHOW_INSIDE: 2,
+ SHOW_OUTSIDE: 3
+};
+
+Potree.ClipMethod = {
+ INSIDE_ANY: 0,
+ INSIDE_ALL: 1
+};
+
+Potree.MOUSE = {
+ LEFT: 0b0001,
+ RIGHT: 0b0010,
+ MIDDLE: 0b0100
+};
+
Potree.timerQueries = {};
Potree.measureTimings = false;
@@ -113,12 +133,6 @@ Potree.resolveQueries = function (gl) {
return resolved;
};
-Potree.MOUSE = {
- LEFT: 0b0001,
- RIGHT: 0b0010,
- MIDDLE: 0b0100
-};
-
Potree.toMaterialID = function(materialName){
if (materialName === 'RGB'){
return Potree.PointColorType.RGB;
@@ -414,6 +428,8 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){
let numVisibleNodes = 0;
let numVisiblePoints = 0;
+ let numVisiblePointsInPointclouds = new Map(pointclouds.map(pc => [pc, 0]));
+
let visibleNodes = [];
let visibleGeometry = [];
let unloadedGeometry = [];
@@ -455,25 +471,70 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){
let level = node.getLevel();
let visible = insideFrustum;
visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.pointBudget);
+ visible = visible && !(numVisiblePointsInPointclouds.get(pointcloud) + node.getNumPoints() > pointcloud.pointBudget);
visible = visible && level < maxLevel;
- if (pointcloud.material.numClipBoxes > 0 && visible && pointcloud.material.clipMode === Potree.ClipMode.CLIP_OUTSIDE) {
- let box2 = box.clone();
- pointcloud.updateMatrixWorld(true);
- box2.applyMatrix4(pointcloud.matrixWorld);
- let intersectsClipBoxes = false;
- for (let clipBox of pointcloud.material.clipBoxes) {
- let clipMatrixWorld = clipBox.matrix;
- let clipBoxWorld = new THREE.Box3(
- new THREE.Vector3(-0.5, -0.5, -0.5),
- new THREE.Vector3(0.5, 0.5, 0.5)
- ).applyMatrix4(clipMatrixWorld);
- if (box2.intersectsBox(clipBoxWorld)) {
- intersectsClipBoxes = true;
- break;
+ if(false && pointcloud.material.clipBoxes.length > 0){
+
+ if(!window.warned125){
+ console.log("TODO");
+ window.warned125 = true;
+ }
+
+ //node.debug = false;
+
+ let numIntersecting = 0;
+ let numIntersectionVolumes = 0;
+
+ for(let clipBox of pointcloud.material.clipBoxes){
+
+ let pcWorldInverse = new THREE.Matrix4().getInverse(pointcloud.matrixWorld);
+ let toPCObject = pcWorldInverse.multiply(clipBox.box.matrixWorld);
+
+ let px = new THREE.Vector3(+1, 0, 0).applyMatrix4(toPCObject);
+ let nx = new THREE.Vector3(-1, 0, 0).applyMatrix4(toPCObject);
+ let py = new THREE.Vector3(0, +1, 0).applyMatrix4(toPCObject);
+ let ny = new THREE.Vector3(0, -1, 0).applyMatrix4(toPCObject);
+ let pz = new THREE.Vector3(0, 0, +1).applyMatrix4(toPCObject);
+ let nz = new THREE.Vector3(0, 0, -1).applyMatrix4(toPCObject);
+
+ let pxN = new THREE.Vector3().subVectors(nx, px).normalize();
+ let nxN = pxN.clone().multiplyScalar(-1);
+ let pyN = new THREE.Vector3().subVectors(ny, py).normalize();
+ let nyN = pyN.clone().multiplyScalar(-1);
+ let pzN = new THREE.Vector3().subVectors(nz, pz).normalize();
+ let nzN = pzN.clone().multiplyScalar(-1);
+
+ let pxPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(pxN, px);
+ let nxPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(nxN, nx);
+ let pyPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(pyN, py);
+ let nyPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(nyN, ny);
+ let pzPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(pzN, pz);
+ let nzPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(nzN, nz);
+
+ let frustum = new THREE.Frustum(pxPlane, nxPlane, pyPlane, nyPlane, pzPlane, nzPlane);
+ let intersects = frustum.intersectsBox(box);
+
+ if(intersects){
+ numIntersecting++;
+ }
+ numIntersectionVolumes++;
+ }
+
+ let insideAny = numIntersecting > 0;
+ let insideAll = numIntersecting === numIntersectionVolumes;
+
+ if(pointcloud.material.clipTask === Potree.ClipTask.SHOW_INSIDE){
+ if(pointcloud.material.clipMethod === Potree.ClipMethod.INSIDE_ANY && insideAny){
+ //node.debug = true
+ }else if(pointcloud.material.clipMethod === Potree.ClipMethod.INSIDE_ALL && insideAll){
+ //node.debug = true;
+ }else{
+ visible = false;
}
}
- visible = visible && intersectsClipBoxes;
+
+
}
// visible = ["r", "r0", "r06", "r060"].includes(node.name);
@@ -496,6 +557,8 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){
// TODO: not used, same as the declaration?
// numVisibleNodes++;
numVisiblePoints += node.getNumPoints();
+ let numVisiblePointsInPointcloud = numVisiblePointsInPointclouds.get(pointcloud);
+ numVisiblePointsInPointclouds.set(pointcloud, numVisiblePointsInPointcloud + node.getNumPoints());
pointcloud.numVisibleNodes++;
pointcloud.numVisiblePoints += node.getNumPoints();
diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js
index aeae629c..8b566183 100644
--- a/src/PotreeRenderer.js
+++ b/src/PotreeRenderer.js
@@ -135,8 +135,9 @@ Potree.attributeLocations = {
"returnNumber": 4,
"numberOfReturns": 5,
"pointSourceID": 6,
- "index": 7,
+ "indices": 7,
"normal": 8,
+ "spacing": 9,
};
Potree.Shader = class Shader {
@@ -166,7 +167,7 @@ Potree.Shader = class Shader {
this.linkProgram();
}
- compileShader(shader, source) {
+ compileShader(shader, source){
let gl = this.gl;
gl.shaderSource(shader, source);
@@ -374,16 +375,6 @@ Potree.Shader = class Shader {
};
-Potree.WebGLBuffer = class WebGLBuffer {
-
- constructor() {
- this.iBuffer = null;
- this.vao = null;
- this.vbo = null;
- }
-
-};
-
Potree.WebGLTexture = class WebGLTexture {
constructor(gl, texture) {
@@ -460,7 +451,15 @@ Potree.WebGLTexture = class WebGLTexture {
this.version = texture.version;
}
+};
+Potree.WebGLBuffer = class WebGLBuffer {
+
+ constructor() {
+ this.numElements = 0;
+ this.vao = null;
+ this.vbos = new Map();
+ }
};
@@ -474,42 +473,91 @@ Potree.Renderer = class Renderer {
this.shaders = new Map();
this.textures = new Map();
+ this.glTypeMapping = new Map();
+ this.glTypeMapping.set(Float32Array, this.gl.FLOAT);
+ this.glTypeMapping.set(Uint8Array, this.gl.UNSIGNED_BYTE);
+ this.glTypeMapping.set(Uint16Array, this.gl.UNSIGNED_SHORT);
this.toggle = 0;
}
- createBuffer(iBuffer) {
-
+ createBuffer(geometry){
let gl = this.gl;
- let buffer = new Potree.WebGLBuffer();
- buffer.iBuffer = iBuffer;
- buffer.vao = gl.createVertexArray();
- buffer.vbo = gl.createBuffer();
+ let webglBuffer = new Potree.WebGLBuffer();
+ webglBuffer.vao = gl.createVertexArray();
+ webglBuffer.numElements = geometry.attributes.position.count;
- gl.bindVertexArray(buffer.vao);
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer.vbo);
- gl.bufferData(gl.ARRAY_BUFFER, iBuffer.data, gl.STATIC_DRAW);
+ gl.bindVertexArray(webglBuffer.vao);
- let offset = 0;
- let i = 0;
- for (let attribute of iBuffer.attributes) {
+ for(let attributeName in geometry.attributes){
+ let bufferAttribute = geometry.attributes[attributeName];
- let type = gl[attribute.type];
- let normalized = attribute.normalized;
- let stride = iBuffer.stride;
- let numElements = attribute.numElements;
+ let vbo = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+ gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
- let location = Potree.attributeLocations[attribute.name];
- gl.vertexAttribPointer(location, numElements, type, normalized, stride, offset);
- gl.enableVertexAttribArray(location);
+ let attributeLocation = Potree.attributeLocations[attributeName];
+ let normalized = bufferAttribute.normalized;
+ let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
- offset += Math.ceil(attribute.bytes / 4) * 4;
- i++;
+ gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
+ gl.enableVertexAttribArray(attributeLocation);
+
+ webglBuffer.vbos.set(attributeName, {
+ handle: vbo,
+ name: attributeName,
+ count: bufferAttribute.count,
+ itemSize: bufferAttribute.itemSize,
+ type: geometry.attributes.position.array.constructor,
+ version: 0
+ });
}
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindVertexArray(null);
- return buffer;
+ return webglBuffer;
+ }
+
+ updateBuffer(geometry){
+ let gl = this.gl;
+
+ let webglBuffer = this.buffers.get(geometry);
+
+ gl.bindVertexArray(webglBuffer.vao);
+
+ for(let attributeName in geometry.attributes){
+ let bufferAttribute = geometry.attributes[attributeName];
+
+ let attributeLocation = Potree.attributeLocations[attributeName];
+ let normalized = bufferAttribute.normalized;
+ let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
+
+ let vbo = null;
+ if(!webglBuffer.vbos.has(attributeName)){
+ vbo = gl.createBuffer();
+
+ webglBuffer.vbos.set(attributeName, {
+ handle: vbo,
+ name: attributeName,
+ count: bufferAttribute.count,
+ itemSize: bufferAttribute.itemSize,
+ type: geometry.attributes.position.array.constructor,
+ version: bufferAttribute.version
+ });
+ }else{
+ vbo = webglBuffer.vbos.get(attributeName).handle;
+ webglBuffer.vbos.get(attributeName).version = bufferAttribute.version;
+ }
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+ gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
+ gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
+ gl.enableVertexAttribArray(attributeLocation);
+ }
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
+ gl.bindVertexArray(null);
}
traverse(scene) {
@@ -538,47 +586,7 @@ Potree.Renderer = class Renderer {
return result;
}
- // adapted from three.js Matrix4.js multiplyMatrices()
- // removed terms that evaluate to zero if world matrix has no rotation
- //multiplyViewWithScaleTrans(view, scaleTrans, target){
- // var ae = view.elements;
- // var be = scaleTrans.elements;
- // var te = target.elements;
- // let a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
- // let a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
- // let a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
- // let a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
-
- // let sx = be[0];
- // let sy = be[5];
- // let sz = be[10];
- // let tx = be[12];
- // let ty = be[13]
- // let tz = be[14];
-
- // te[ 0 ] = a11 * sx;
- // te[ 4 ] = a12 * sy;
- // te[ 8 ] = a13 * sz;
- // te[ 12 ] = a11 * tx + a12 * ty + a13 * tz + a14;
-
- // te[ 1 ] = a21 * sx;
- // te[ 5 ] = a22 * sy ;
- // te[ 9 ] = a23 * sz;
- // te[ 13 ] = a21 * tx + a22 * ty + a23 * tz + a24;
-
- // te[ 2 ] = a31 * sx;
- // te[ 6 ] = a32 * sy;
- // te[ 10 ] = a33 * sz;
- // te[ 14 ] = a31 * tx + a32 * ty + a33 * tz + a34;
-
- // te[ 3 ] = 0;
- // te[ 7 ] = 0;
- // te[ 11 ] = 0;
- // te[ 15 ] = 1;
-
- // return target;
- //}
renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params) {
@@ -586,6 +594,7 @@ Potree.Renderer = class Renderer {
let gl = this.gl;
+ let material = params.material ? params.material : octree.material;
let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
let view = camera.matrixWorldInverse;
let worldView = new THREE.Matrix4();
@@ -595,6 +604,19 @@ Potree.Renderer = class Renderer {
let i = 0;
for (let node of nodes) {
+ if(Potree.debug.allowedNodes !== undefined){
+ if(!Potree.debug.allowedNodes.includes(node.name)){
+ continue;
+ }
+ }
+
+ //if(![
+ // "r42006420226",
+ // ]
+ // .includes(node.name)){
+ // continue;
+ //}
+
let world = node.sceneNode.matrixWorld;
worldView.multiplyMatrices(view, world);
//this.multiplyViewWithScaleTrans(view, world, worldView);
@@ -607,6 +629,18 @@ Potree.Renderer = class Renderer {
let level = node.getLevel();
+ if(node.debug){
+ shader.setUniform("uDebug", true);
+ }else{
+ shader.setUniform("uDebug", false);
+ }
+
+ if(Object.keys(node.children).length === 0){
+ shader.setUniform("uIsLeafNode", true);
+ }else{
+ shader.setUniform("uIsLeafNode", false);
+ }
+
// TODO consider passing matrices in an array to avoid uniformMatrix4fv overhead
const lModel = shader.uniformLocations["modelMatrix"];
@@ -623,6 +657,47 @@ Potree.Renderer = class Renderer {
}
gl.uniformMatrix4fv(lModelView, false, mat4holder);
+ { // Clip Polygons
+ if(material.clipPolygons && material.clipPolygons.length > 0){
+
+ let clipPolygonVCount = [];
+ let worldViewProjMatrices = [];
+
+ for(let clipPolygon of material.clipPolygons){
+
+ let view = clipPolygon.viewMatrix;
+ let proj = clipPolygon.projMatrix;
+
+ let worldViewProj = proj.clone().multiply(view).multiply(world);
+
+ clipPolygonVCount.push(clipPolygon.markers.length);
+ worldViewProjMatrices.push(worldViewProj);
+ }
+
+ let flattenedMatrices = [].concat(...worldViewProjMatrices.map(m => m.elements));
+
+ let flattenedVertices = new Array(8 * 3 * material.clipPolygons.length);
+ for(let i = 0; i < material.clipPolygons.length; i++){
+ let clipPolygon = material.clipPolygons[i];
+ for(let j = 0; j < clipPolygon.markers.length; j++){
+ flattenedVertices[i * 24 + (j * 3 + 0)] = clipPolygon.markers[j].position.x;
+ flattenedVertices[i * 24 + (j * 3 + 1)] = clipPolygon.markers[j].position.y;
+ flattenedVertices[i * 24 + (j * 3 + 2)] = clipPolygon.markers[j].position.z;
+ }
+ }
+
+ const lClipPolygonVCount = shader.uniformLocations["uClipPolygonVCount[0]"];
+ gl.uniform1iv(lClipPolygonVCount, clipPolygonVCount);
+
+ const lClipPolygonVP = shader.uniformLocations["uClipPolygonWVP[0]"];
+ gl.uniformMatrix4fv(lClipPolygonVP, false, flattenedMatrices);
+
+ const lClipPolygons = shader.uniformLocations["uClipPolygonVertices[0]"];
+ gl.uniform3fv(lClipPolygons, flattenedVertices);
+
+ }
+ }
+
//shader.setUniformMatrix4("modelMatrix", world);
//shader.setUniformMatrix4("modelViewMatrix", worldView);
@@ -636,7 +711,7 @@ Potree.Renderer = class Renderer {
const lShadowMap = shader.uniformLocations["uShadowMap[0]"];
- shader.setUniform3f("uShadowColor", octree.material.uniforms.uShadowColor.value);
+ shader.setUniform3f("uShadowColor", material.uniforms.uShadowColor.value);
let bindingStart = 5;
let bindingPoints = new Array(shadowMaps.length).fill(bindingStart).map((a, i) => (a + i));
@@ -652,8 +727,9 @@ Potree.Renderer = class Renderer {
}
{
+
let worldViewMatrices = shadowMaps
- .map(sm => new THREE.Matrix4().makeTranslation(...sm.lightPos.clone().multiplyScalar(-1).toArray()))
+ .map(sm => sm.camera.matrixWorldInverse)
.map(view => new THREE.Matrix4().multiplyMatrices(view, world))
let flattenedMatrices = [].concat(...worldViewMatrices.map(c => c.elements));
@@ -661,23 +737,33 @@ Potree.Renderer = class Renderer {
gl.uniformMatrix4fv(lWorldView, false, flattenedMatrices);
}
-
-
+ {
+ let flattenedMatrices = [].concat(...shadowMaps.map(sm => sm.camera.projectionMatrix.elements));
+ const lProj = shader.uniformLocations["uShadowProj[0]"];
+ gl.uniformMatrix4fv(lProj, false, flattenedMatrices);
+ }
}
+ let geometry = node.geometryNode.geometry;
- let iBuffer = node.geometryNode.buffer;
+ let webglBuffer = null;
+ if(!this.buffers.has(geometry)){
+ webglBuffer = this.createBuffer(geometry);
+ this.buffers.set(geometry, webglBuffer);
+ }else{
+ webglBuffer = this.buffers.get(geometry);
+ for(let attributeName in geometry.attributes){
+ let attribute = geometry.attributes[attributeName];
- if (!this.buffers.has(iBuffer)) {
- let buffers = this.createBuffer(iBuffer);
- this.buffers.set(iBuffer, buffers);
+ if(attribute.version > webglBuffer.vbos.get(attributeName).version){
+ this.updateBuffer(geometry);
+ }
+ }
}
- let buffer = this.buffers.get(iBuffer);
+ gl.bindVertexArray(webglBuffer.vao);
- gl.bindVertexArray(buffer.vao);
-
- let numPoints = iBuffer.numElements;
+ let numPoints = webglBuffer.numElements;
gl.drawArrays(gl.POINTS, 0, numPoints);
i++;
@@ -695,6 +781,7 @@ Potree.Renderer = class Renderer {
let gl = this.gl;
+ let material = params.material ? params.material : octree.material;
let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
let view = camera.matrixWorldInverse;
let viewInv = camera.matrixWorld;
@@ -702,7 +789,6 @@ Potree.Renderer = class Renderer {
let projInv = new THREE.Matrix4().getInverse(proj);
let worldView = new THREE.Matrix4();
- let material = octree.material;
let shader = null;
let visibilityTextureData = null;
@@ -813,6 +899,28 @@ Potree.Renderer = class Renderer {
gl.enable(gl.DEPTH_TEST);
}
+ if(params.blendFunc !== undefined){
+ gl.enable(gl.BLEND);
+ gl.blendFunc(...params.blendFunc);
+ }
+
+ if(params.depthTest !== undefined){
+ if(params.depthTest === true){
+ gl.enable(gl.DEPTH_TEST);
+ }else{
+ gl.disable(gl.DEPTH_TEST);
+ }
+ }
+
+ if(params.depthWrite !== undefined){
+ if(params.depthWrite === true){
+ gl.depthMask(true);
+ }else{
+ gl.depthMask(false);
+ }
+
+ }
+
{ // UPDATE UNIFORMS
shader.setUniformMatrix4("projectionMatrix", proj);
@@ -820,12 +928,17 @@ Potree.Renderer = class Renderer {
shader.setUniformMatrix4("uViewInv", viewInv);
shader.setUniformMatrix4("uProjInv", projInv);
- shader.setUniform1f("uScreenHeight", material.screenHeight);
- shader.setUniform1f("uScreenWidth", material.screenWidth);
+ //shader.setUniform1f("uScreenHeight", material.screenHeight);
+ //shader.setUniform1f("uScreenWidth", material.screenWidth);
+
+ let screenWidth = target ? target.width : material.screenWidth;
+ let screenHeight = target ? target.height : material.screenHeight;
+
+ shader.setUniform1f("uScreenWidth", screenWidth);
+ shader.setUniform1f("uScreenHeight", screenHeight);
shader.setUniform1f("fov", Math.PI * camera.fov / 180);
shader.setUniform1f("near", camera.near);
shader.setUniform1f("far", camera.far);
-
if(camera instanceof THREE.OrthographicCamera){
shader.setUniform("uUseOrthographicCamera", true);
@@ -835,7 +948,13 @@ Potree.Renderer = class Renderer {
shader.setUniform("uUseOrthographicCamera", false);
}
- shader.setUniform1i("clipMode", material.clipMode);
+ if(material.clipBoxes.length + material.clipPolygons.length === 0){
+ shader.setUniform1i("clipTask", Potree.ClipTask.NONE);
+ }else{
+ shader.setUniform1i("clipTask", material.clipTask);
+ }
+
+ shader.setUniform1i("clipMethod", material.clipMethod);
if (material.clipBoxes && material.clipBoxes.length > 0) {
@@ -845,35 +964,9 @@ Potree.Renderer = class Renderer {
gl.uniformMatrix4fv(lClipBoxes, false, flattenedMatrices);
}
- if(material.clipPolygons && material.clipPolygons.length > 0){
- let clipPolygonVCount = material.clipPolygons.map(p => p.polygon.length);
- let flattenedMatrices = [].concat(...material.clipPolygons.map(c => c.view.elements));
-
- let flattenedVertices = new Array(8 * 3 * material.clipPolygons.length);
- for(let i = 0; i < material.clipPolygons.length; i++){
- let polygon = material.clipPolygons[i];
- for(let j = 0; j < polygon.polygon.length; j++){
- flattenedVertices[i * 24 + (j * 3 + 0)] = polygon.polygon[j].x;
- flattenedVertices[i * 24 + (j * 3 + 1)] = polygon.polygon[j].y;
- flattenedVertices[i * 24 + (j * 3 + 2)] = polygon.polygon[j].z;
- }
- }
-
- const lClipPolygonVCount = shader.uniformLocations["uClipPolygonVCount[0]"];
- gl.uniform1iv(lClipPolygonVCount, clipPolygonVCount);
-
- const lClipPolygonVP = shader.uniformLocations["uClipPolygonVP[0]"];
- gl.uniformMatrix4fv(lClipPolygonVP, false, flattenedMatrices);
-
- const lClipPolygons = shader.uniformLocations["uClipPolygonVertices[0]"];
- gl.uniform3fv(lClipPolygons, flattenedVertices);
-
- }
-
shader.setUniform1f("size", material.size);
- shader.setUniform1f("maxSize", 50);
- shader.setUniform1f("minSize", 2);
-
+ shader.setUniform1f("maxSize", material.uniforms.maxSize.value);
+ shader.setUniform1f("minSize", material.uniforms.minSize.value);
// uniform float uPCIndex
shader.setUniform1f("uOctreeSpacing", material.spacing);
diff --git a/src/ProfileRequest.js b/src/ProfileRequest.js
index 079189f9..eea90a99 100644
--- a/src/ProfileRequest.js
+++ b/src/ProfileRequest.js
@@ -171,15 +171,12 @@ Potree.ProfileRequest = class ProfileRequest {
}
}
- //console.log("updateGenerator finished");
yield true;
};
- * getAccepted(numPoints, buffer, posOffset, matrix, segment, segmentDir, points, totalMileage){
+ * getAccepted(numPoints, node, matrix, segment, segmentDir, points, totalMileage){
let checkpoint = performance.now();
- let view = new DataView(buffer.data);
-
let accepted = new Uint32Array(numPoints);
let mileage = new Float64Array(numPoints);
let acceptedPositions = new Float32Array(numPoints * 3);
@@ -188,12 +185,14 @@ Potree.ProfileRequest = class ProfileRequest {
let pos = new THREE.Vector3();
let svp = new THREE.Vector3();
+ let view = new Float32Array(node.geometry.attributes.position.array);
+
for (let i = 0; i < numPoints; i++) {
pos.set(
- view.getFloat32(i * buffer.stride + posOffset + 0, true),
- view.getFloat32(i * buffer.stride + posOffset + 4, true),
- view.getFloat32(i * buffer.stride + posOffset + 8, true));
+ view[i * 3 + 0],
+ view[i * 3 + 1],
+ view[i * 3 + 2]);
pos.applyMatrix4(matrix);
let distance = Math.abs(segment.cutPlane.distanceToPoint(pos));
@@ -246,8 +245,7 @@ Potree.ProfileRequest = class ProfileRequest {
for (let segment of target.segments) {
for (let node of nodes) {
let numPoints = node.numPoints;
- let buffer = node.buffer;
- let view = new DataView(buffer.data);
+ let geometry = node.geometry;
if(!numPoints){
continue;
@@ -288,13 +286,12 @@ Potree.ProfileRequest = class ProfileRequest {
let matrix = new THREE.Matrix4().multiplyMatrices(
this.pointcloud.matrixWorld, nodeMatrix);
- let posOffset = buffer.offset("position");
pointsProcessed = pointsProcessed + numPoints;
let accepted = null;
let mileage = null;
let acceptedPositions = null;
- for(let result of this.getAccepted(numPoints, buffer, posOffset, matrix, segment, segmentDir, points,totalMileage)){
+ for(let result of this.getAccepted(numPoints, node, matrix, segment, segmentDir, points,totalMileage)){
if(!result){
let duration = performance.now() - checkpoint;
//console.log(`getPointsInsideProfile yield after ${duration}ms`);
@@ -314,37 +311,30 @@ Potree.ProfileRequest = class ProfileRequest {
points.data.position = acceptedPositions;
- let relevantAttributes = buffer.attributes.filter(a => !["position", "index"].includes(a.name));
- for(let attribute of relevantAttributes){
+ let relevantAttributes = Object.keys(geometry.attributes).filter(a => !["position", "indices"].includes(a));
+ for(let attributeName of relevantAttributes){
- let filteredBuffer = null;
- if(attribute.type === "FLOAT"){
- filteredBuffer = new Float32Array(attribute.numElements * accepted.length);
- }else if(attribute.type === "UNSIGNED_BYTE"){
- filteredBuffer = new Uint8Array(attribute.numElements * accepted.length);
- }else if(attribute.type === "UNSIGNED_SHORT"){
- filteredBuffer = new Uint16Array(attribute.numElements * accepted.length);
- }else if(attribute.type === "UNSIGNED_INT"){
- filteredBuffer = new Uint32Array(attribute.numElements * accepted.length);
- }
+ let attribute = geometry.attributes[attributeName];
+ let numElements = attribute.array.length / numPoints;
+ let Type = attribute.array.constructor;
- let source = new Uint8Array(buffer.data);
- let target = new Uint8Array(filteredBuffer.buffer);
+ let filteredBuffer = new Type(numElements * accepted.length);
- let offset = buffer.offset(attribute.name);
+ let source = attribute.array;
+ let target = filteredBuffer;
for(let i = 0; i < accepted.length; i++){
let index = accepted[i];
- let start = buffer.stride * index + offset;
- let end = start + attribute.bytes;
+ let start = index * numElements;
+ let end = start + numElements;
let sub = source.subarray(start, end);
- target.set(sub, i * attribute.bytes);
+ target.set(sub, i * numElements);
}
- points.data[attribute.name] = filteredBuffer;
+ points.data[attributeName] = filteredBuffer;
}
points.data['mileage'] = mileage;
diff --git a/src/extensions/EventDispatcher.js b/src/extensions/EventDispatcher.js
index ea06d1f8..f49db850 100644
--- a/src/extensions/EventDispatcher.js
+++ b/src/extensions/EventDispatcher.js
@@ -7,4 +7,4 @@ THREE.EventDispatcher.prototype.removeEventListeners = function (type) {
if (this._listeners[ type ]) {
delete this._listeners[ type ];
}
-};
+};
\ No newline at end of file
diff --git a/src/loader/BinaryLoader.js b/src/loader/BinaryLoader.js
index 747b40a2..26b9e0bd 100644
--- a/src/loader/BinaryLoader.js
+++ b/src/loader/BinaryLoader.js
@@ -58,14 +58,7 @@ Potree.BinaryLoader.prototype.parse = function (node, buffer) {
worker.onmessage = function (e) {
let data = e.data;
- let iAttributes = pointAttributes.attributes
- .map(pa => Potree.toInterleavedBufferAttribute(pa))
- .filter(ia => ia != null);
- iAttributes.push(new Potree.InterleavedBufferAttribute("index", 4, 4, "UNSIGNED_BYTE", true));
- let iBuffer = new Potree.InterleavedBuffer(data.data, iAttributes, numPoints);
-
- //console.log(data.estimatedSpacing);
-
+ let buffers = data.attributeBuffers;
let tightBoundingBox = new THREE.Box3(
new THREE.Vector3().fromArray(data.tightBoundingBox.min),
new THREE.Vector3().fromArray(data.tightBoundingBox.max)
@@ -73,11 +66,43 @@ Potree.BinaryLoader.prototype.parse = function (node, buffer) {
Potree.workerPool.returnWorker(workerPath, worker);
+ let geometry = new THREE.BufferGeometry();
+
+ for(let property in buffers){
+ let buffer = buffers[property].buffer;
+
+ if (parseInt(property) === Potree.PointAttributeNames.POSITION_CARTESIAN) {
+ geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(buffer), 3));
+ } else if (parseInt(property) === Potree.PointAttributeNames.COLOR_PACKED) {
+ geometry.addAttribute('color', new THREE.BufferAttribute(new Uint8Array(buffer), 4, true));
+ } else if (parseInt(property) === Potree.PointAttributeNames.INTENSITY) {
+ geometry.addAttribute('intensity', new THREE.BufferAttribute(new Float32Array(buffer), 1));
+ } else if (parseInt(property) === Potree.PointAttributeNames.CLASSIFICATION) {
+ geometry.addAttribute('classification', new THREE.BufferAttribute(new Uint8Array(buffer), 1));
+ } else if (parseInt(property) === Potree.PointAttributeNames.NORMAL_SPHEREMAPPED) {
+ geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
+ } else if (parseInt(property) === Potree.PointAttributeNames.NORMAL_OCT16) {
+ geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
+ } else if (parseInt(property) === Potree.PointAttributeNames.NORMAL) {
+ geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
+ } else if (parseInt(property) === Potree.PointAttributeNames.INDICES) {
+ let bufferAttribute = new THREE.BufferAttribute(new Uint8Array(buffer), 4);
+ bufferAttribute.normalized = true;
+ geometry.addAttribute('indices', bufferAttribute);
+ } else if (parseInt(property) === Potree.PointAttributeNames.SPACING) {
+ let bufferAttribute = new THREE.BufferAttribute(new Float32Array(buffer), 1);
+ geometry.addAttribute('spacing', bufferAttribute);
+ }
+ }
+
+
tightBoundingBox.max.sub(tightBoundingBox.min);
tightBoundingBox.min.set(0, 0, 0);
+
+ let numPoints = e.data.buffer.byteLength / pointAttributes.byteSize;
- node.numPoints = iBuffer.numElements;
- node.buffer = iBuffer;
+ node.numPoints = numPoints;
+ node.geometry = geometry;
node.mean = new THREE.Vector3(...data.mean);
node.tightBoundingBox = tightBoundingBox;
node.loaded = true;
@@ -95,6 +120,7 @@ Potree.BinaryLoader.prototype.parse = function (node, buffer) {
scale: this.scale,
spacing: node.spacing,
hasChildren: node.hasChildren,
+ name: node.name
};
worker.postMessage(message, [message.buffer]);
};
diff --git a/src/loader/LasLazLoader.js b/src/loader/LasLazLoader.js
index 87e9a414..49ab605d 100644
--- a/src/loader/LasLazLoader.js
+++ b/src/loader/LasLazLoader.js
@@ -153,42 +153,46 @@ Potree.LasLazBatcher = class LasLazBatcher {
let node = this.node;
worker.onmessage = (e) => {
+ let geometry = new THREE.BufferGeometry();
let numPoints = lasBuffer.pointsCount;
- let attributes = [
- Potree.PointAttribute.POSITION_CARTESIAN,
- Potree.PointAttribute.RGBA_PACKED,
- Potree.PointAttribute.INTENSITY,
- Potree.PointAttribute.CLASSIFICATION,
- Potree.PointAttribute.RETURN_NUMBER,
- Potree.PointAttribute.NUMBER_OF_RETURNS,
- Potree.PointAttribute.SOURCE_ID,
- ];
+ let positions = new Float32Array(e.data.position);
+ let colors = new Uint8Array(e.data.color);
+ let intensities = new Float32Array(e.data.intensity);
+ let classifications = new Uint8Array(e.data.classification);
+ let returnNumbers = new Uint8Array(e.data.returnNumber);
+ let numberOfReturns = new Uint8Array(e.data.numberOfReturns);
+ let pointSourceIDs = new Uint16Array(e.data.pointSourceID);
+ let indices = new Uint8Array(e.data.indices);
- let data = e.data;
- let iAttributes = attributes
- .map(pa => Potree.toInterleavedBufferAttribute(pa))
- .filter(ia => ia != null);
- iAttributes.push(new Potree.InterleavedBufferAttribute("index", 4, 4, "UNSIGNED_BYTE", true));
- let iBuffer = new Potree.InterleavedBuffer(data.data, iAttributes, numPoints);
+ geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
+ geometry.addAttribute('color', new THREE.BufferAttribute(colors, 4, true));
+ //geometry.addAttribute('intensity', new THREE.BufferAttribute(intensities, 1));
+ //geometry.addAttribute('classification', new THREE.BufferAttribute(classifications, 1));
+ //geometry.addAttribute('returnNumber', new THREE.BufferAttribute(returnNumbers, 1));
+ //geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(numberOfReturns, 1));
+ //geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(pointSourceIDs, 1));
+ //geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(numPoints * 3), 3));
+ geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 4));
+ geometry.attributes.indices.normalized = true;
let tightBoundingBox = new THREE.Box3(
new THREE.Vector3().fromArray(e.data.tightBoundingBox.min),
new THREE.Vector3().fromArray(e.data.tightBoundingBox.max)
);
-
+
+ geometry.boundingBox = this.node.boundingBox;
+ this.node.tightBoundingBox = tightBoundingBox;
+
+ this.node.geometry = geometry;
+ this.node.loaded = true;
+ this.node.loading = false;
+ this.node.pcoGeometry.numNodesLoading--;
+ this.node.mean = new THREE.Vector3(...e.data.mean);
+
+ //debugger;
+
Potree.workerPool.returnWorker(workerPath, worker);
-
- node.estimatedSpacing = node.spacing;
- node.numPoints = iBuffer.numElements;
- node.buffer = iBuffer;
- node.mean = new THREE.Vector3(...data.mean);
- node.tightBoundingBox = tightBoundingBox;
- node.loaded = true;
- node.loading = false;
- node.pcoGeometry.numNodesLoading--;
-
-
};
let message = {
diff --git a/src/loader/PointAttributes.js b/src/loader/PointAttributes.js
index 4bb5b51c..ddf47576 100644
--- a/src/loader/PointAttributes.js
+++ b/src/loader/PointAttributes.js
@@ -15,6 +15,8 @@ Potree.PointAttributeNames.NORMAL = 10;
Potree.PointAttributeNames.RETURN_NUMBER = 11;
Potree.PointAttributeNames.NUMBER_OF_RETURNS = 12;
Potree.PointAttributeNames.SOURCE_ID = 13;
+Potree.PointAttributeNames.INDICES = 14;
+Potree.PointAttributeNames.SPACING = 15;
/**
* Some types of possible point attribute data formats
@@ -110,6 +112,14 @@ Potree.PointAttribute.SOURCE_ID = new Potree.PointAttribute(
Potree.PointAttributeNames.SOURCE_ID,
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 1);
+Potree.PointAttribute.INDICES = new Potree.PointAttribute(
+ Potree.PointAttributeNames.INDICES,
+ Potree.PointAttributeTypes.DATA_TYPE_UINT32, 1);
+
+Potree.PointAttribute.SPACING = new Potree.PointAttribute(
+ Potree.PointAttributeNames.SPACING,
+ Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 1);
+
/**
* Ordered list of PointAttributes used to identify how points are aligned in a buffer.
*
diff --git a/src/materials/NormalizationEDLMaterial.js b/src/materials/NormalizationEDLMaterial.js
new file mode 100644
index 00000000..ad35668b
--- /dev/null
+++ b/src/materials/NormalizationEDLMaterial.js
@@ -0,0 +1,68 @@
+
+Potree.NormalizationEDLMaterial = class NormalizationEDLMaterial extends THREE.ShaderMaterial{
+
+ constructor(parameters = {}){
+ super();
+
+ let uniforms = {
+ screenWidth: { type: 'f', value: 0 },
+ screenHeight: { type: 'f', value: 0 },
+ edlStrength: { type: 'f', value: 1.0 },
+ radius: { type: 'f', value: 1.0 },
+ neighbours: { type: '2fv', value: [] },
+ uEDLMap: { type: 't', value: null },
+ uDepthMap: { type: 't', value: null },
+ uWeightMap: { type: 't', value: null },
+ };
+
+ this.setValues({
+ uniforms: uniforms,
+ vertexShader: this.getDefines() + Potree.Shaders['normalize.vs'],
+ fragmentShader: this.getDefines() + Potree.Shaders['normalize_and_edl.fs'],
+ });
+
+ this.neighbourCount = 8;
+ }
+
+ getDefines() {
+ let defines = '';
+
+ defines += '#define NEIGHBOUR_COUNT ' + this.neighbourCount + '\n';
+
+ return defines;
+ }
+
+ updateShaderSource() {
+
+ let vs = this.getDefines() + Potree.Shaders['normalize.vs'];
+ let fs = this.getDefines() + Potree.Shaders['normalize_and_edl.fs'];
+
+ this.setValues({
+ vertexShader: vs,
+ fragmentShader: fs
+ });
+
+ this.uniforms.neighbours.value = this.neighbours;
+
+ this.needsUpdate = true;
+ }
+
+ get neighbourCount(){
+ return this._neighbourCount;
+ }
+
+ set neighbourCount(value){
+ if (this._neighbourCount !== value) {
+ this._neighbourCount = value;
+ this.neighbours = new Float32Array(this._neighbourCount * 2);
+ for (var c = 0; c < this._neighbourCount; c++) {
+ this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
+ this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
+ }
+
+ this.updateShaderSource();
+ }
+ }
+
+};
+
diff --git a/src/materials/NormalizationMaterial.js b/src/materials/NormalizationMaterial.js
new file mode 100644
index 00000000..758f5ca2
--- /dev/null
+++ b/src/materials/NormalizationMaterial.js
@@ -0,0 +1,38 @@
+
+Potree.NormalizationMaterial = class NormalizationMaterial extends THREE.ShaderMaterial{
+
+ constructor(parameters = {}){
+ super();
+
+ let uniforms = {
+ uDepthMap: { type: 't', value: null },
+ uWeightMap: { type: 't', value: null },
+ };
+
+ this.setValues({
+ uniforms: uniforms,
+ vertexShader: this.getDefines() + Potree.Shaders['normalize.vs'],
+ fragmentShader: this.getDefines() + Potree.Shaders['normalize.fs'],
+ });
+ }
+
+ getDefines() {
+ let defines = '';
+
+ return defines;
+ }
+
+ updateShaderSource() {
+
+ let vs = this.getDefines() + Potree.Shaders['normalize.vs'];
+ let fs = this.getDefines() + Potree.Shaders['normalize.fs'];
+
+ this.setValues({
+ vertexShader: vs,
+ fragmentShader: fs
+ });
+
+ this.needsUpdate = true;
+ }
+};
+
diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js
index 76c2a258..088a2b64 100644
--- a/src/materials/PointCloudMaterial.js
+++ b/src/materials/PointCloudMaterial.js
@@ -182,16 +182,26 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
this.visibleNodesTexture.minFilter = THREE.NearestFilter;
this.visibleNodesTexture.magFilter = THREE.NearestFilter;
- let pointSize = parameters.size || 1.0;
- let minSize = parameters.minSize || 1.0;
- let maxSize = parameters.maxSize || 50.0;
- let treeType = parameters.treeType || Potree.TreeType.OCTREE;
+ let getValid = (a, b) => {
+ if(a !== undefined){
+ return a;
+ }else{
+ return b;
+ }
+ }
+
+ let pointSize = getValid(parameters.size, 1.0);
+ let minSize = getValid(parameters.minSize, 2.0);
+ let maxSize = getValid(parameters.maxSize, 50.0);
+ let treeType = getValid(parameters.treeType, Potree.TreeType.OCTREE);
this._pointSizeType = Potree.PointSizeType.FIXED;
this._shape = Potree.PointShape.SQUARE;
this._pointColorType = Potree.PointColorType.RGB;
this._useClipBox = false;
+ this.clipBoxes = [];
this.numClipBoxes = 0;
+ this.clipPolygons = [];
this._weighted = false;
this._gradient = Potree.Gradients.SPECTRAL;
this.gradientTexture = Potree.PointCloudMaterial.generateGradientTexture(this._gradient);
@@ -201,6 +211,7 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
this._useEDL = false;
this._snapEnabled = false;
this._numSnapshots = 0;
+ this.defines = new Map();
this._defaultIntensityRangeChanged = false;
this._defaultElevationRangeChanged = false;
@@ -242,6 +253,7 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
pcIndex: { type: "f", value: 0 },
gradient: { type: "t", value: this.gradientTexture },
classificationLUT: { type: "t", value: this.classificationTexture },
+ uHQDepthMap: { type: "t", value: null },
clipBoxes: { type: "Matrix4fv", value: [] },
clipPolygons: { type: "3fv", value: [] },
clipPolygonVCount: { type: "iv", value: [] },
@@ -263,7 +275,8 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
wReturnNumber: { type: "f", value: 0 },
wSourceID: { type: "f", value: 0 },
useOrthographicCamera: { type: "b", value: false },
- clipMode: { type: "i", value: 1 },
+ clipTask: { type: "i", value: 1 },
+ clipMethod: { type: "i", value: 1 },
uSnapshot: { type: "tv", value: [] },
uSnapshotDepth: { type: "tv", value: [] },
uSnapView: { type: "Matrix4fv", value: [] },
@@ -284,6 +297,21 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
this.vertexColors = THREE.VertexColors;
}
+ setDefine(key, value){
+ if(value !== undefined && value !== null){
+ if(this.defines.get(key) !== value){
+ this.defines.set(key, value);
+ this.updateShaderSource();
+ }
+ }else{
+ this.removeDefine(key);
+ }
+ }
+
+ removeDefine(key){
+ this.defines.delete(key);
+ }
+
updateShaderSource () {
this.vertexShader = this.getDefines() + Potree.Shaders['pointcloud.vs'];
this.fragmentShader = this.getDefines() + Potree.Shaders['pointcloud.fs'];
@@ -312,83 +340,87 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
}
getDefines () {
- let defines = '';
+ let defines = [];
if (this.pointSizeType === Potree.PointSizeType.FIXED) {
- defines += '#define fixed_point_size\n';
+ defines.push('#define fixed_point_size');
} else if (this.pointSizeType === Potree.PointSizeType.ATTENUATED) {
- defines += '#define attenuated_point_size\n';
+ defines.push('#define attenuated_point_size');
} else if (this.pointSizeType === Potree.PointSizeType.ADAPTIVE) {
- defines += '#define adaptive_point_size\n';
+ defines.push('#define adaptive_point_size');
}
if (this.shape === Potree.PointShape.SQUARE) {
- defines += '#define square_point_shape\n';
+ defines.push('#define square_point_shape');
} else if (this.shape === Potree.PointShape.CIRCLE) {
- defines += '#define circle_point_shape\n';
+ defines.push('#define circle_point_shape');
} else if (this.shape === Potree.PointShape.PARABOLOID) {
- defines += '#define paraboloid_point_shape\n';
+ defines.push('#define paraboloid_point_shape');
}
if (this._useEDL) {
- defines += '#define use_edl\n';
+ defines.push('#define use_edl');
}
if (this._snapEnabled) {
- defines += '#define snap_enabled\n';
+ defines.push('#define snap_enabled');
}
if (this._pointColorType === Potree.PointColorType.RGB) {
- defines += '#define color_type_rgb\n';
+ defines.push('#define color_type_rgb');
} else if (this._pointColorType === Potree.PointColorType.COLOR) {
- defines += '#define color_type_color\n';
+ defines.push('#define color_type_color');
} else if (this._pointColorType === Potree.PointColorType.DEPTH) {
- defines += '#define color_type_depth\n';
+ defines.push('#define color_type_depth');
} else if (this._pointColorType === Potree.PointColorType.HEIGHT) {
- defines += '#define color_type_height\n';
+ defines.push('#define color_type_height');
} else if (this._pointColorType === Potree.PointColorType.INTENSITY) {
- defines += '#define color_type_intensity\n';
+ defines.push('#define color_type_intensity');
} else if (this._pointColorType === Potree.PointColorType.INTENSITY_GRADIENT) {
- defines += '#define color_type_intensity_gradient\n';
+ defines.push('#define color_type_intensity_gradient');
} else if (this._pointColorType === Potree.PointColorType.LOD) {
- defines += '#define color_type_lod\n';
+ defines.push('#define color_type_lod');
} else if (this._pointColorType === Potree.PointColorType.POINT_INDEX) {
- defines += '#define color_type_point_index\n';
+ defines.push('#define color_type_point_index');
} else if (this._pointColorType === Potree.PointColorType.CLASSIFICATION) {
- defines += '#define color_type_classification\n';
+ defines.push('#define color_type_classification');
} else if (this._pointColorType === Potree.PointColorType.RETURN_NUMBER) {
- defines += '#define color_type_return_number\n';
+ defines.push('#define color_type_return_number');
} else if (this._pointColorType === Potree.PointColorType.SOURCE) {
- defines += '#define color_type_source\n';
+ defines.push('#define color_type_source');
} else if (this._pointColorType === Potree.PointColorType.NORMAL) {
- defines += '#define color_type_normal\n';
+ defines.push('#define color_type_normal');
} else if (this._pointColorType === Potree.PointColorType.PHONG) {
- defines += '#define color_type_phong\n';
+ defines.push('#define color_type_phong');
} else if (this._pointColorType === Potree.PointColorType.RGB_HEIGHT) {
- defines += '#define color_type_rgb_height\n';
+ defines.push('#define color_type_rgb_height');
} else if (this._pointColorType === Potree.PointColorType.COMPOSITE) {
- defines += '#define color_type_composite\n';
+ defines.push('#define color_type_composite');
}
if(this._treeType === Potree.TreeType.OCTREE){
- defines += "#define tree_type_octree\n";
+ defines.push('#define tree_type_octree');
}else if(this._treeType === Potree.TreeType.KDTREE){
- defines += "#define tree_type_kdtree\n";
+ defines.push('#define tree_type_kdtree');
}
if (this.weighted) {
- defines += '#define weighted_splats\n';
+ defines.push('#define weighted_splats');
}
if (this.numClipBoxes > 0) {
- defines += '#define use_clip_box\n';
+ defines.push('#define use_clip_box');
}
- if(this.numClipPolygons > 0) {
- defines += "#define use_clip_polygon\n";
+ if(this.clipPolygons.length > 0) {
+ defines.push('#define use_clip_polygon');
}
- return defines;
+ for(let [key, value] of this.defines){
+ defines.push(value);
+ }
+
+ return defines.join("\n");
}
setClipBoxes (clipBoxes) {
@@ -428,30 +460,11 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
this.clipPolygons = clipPolygons;
- let doUpdate = (this.numClipPolygons !== clipPolygons.length) && (clipPolygons.length === 0 || this.numClipPolygons === 0);
-
- this.numClipPolygons = clipPolygons.length;
- this.uniforms.clipPolygonCount.value = this.numClipPolygons;
+ let doUpdate = (this.clipPolygons.length !== clipPolygons.length);
if(doUpdate){
this.updateShaderSource();
}
-
- this.uniforms.clipPolygons.value = new Float32Array(this.numClipPolygons * maxPolygonVertices * 3);
- this.uniforms.clipPolygonVP.value = new Float32Array(this.numClipPolygons * 16);
- this.uniforms.clipPolygonVCount.value = new Int32Array(this.numClipPolygons);
-
- for(let i = 0; i < this.numClipPolygons; i++){
- let poly = clipPolygons[i];
-
- this.uniforms.clipPolygonVCount.value[i] = poly.count;
- this.uniforms.clipPolygonVP.value.set(poly.view.elements, 16 * i);
- for(let j = 0; j < poly.count; j++) {
- this.uniforms.clipPolygons.value[i * 24 + (j * 3 + 0)] = poly.polygon[j].x;
- this.uniforms.clipPolygons.value[i * 24 + (j * 3 + 1)] = poly.polygon[j].y;
- this.uniforms.clipPolygons.value[i * 24 + (j * 3 + 2)] = poly.polygon[j].z;
- }
- }
}
get gradient(){
@@ -557,14 +570,21 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
}
}
- get clipMode() {
- return this.uniforms.clipMode.value;
+ get clipTask(){
+ return this.uniforms.clipTask.value;
}
- set clipMode(mode) {
- this.uniforms.clipMode.value = mode;
+ set clipTask(mode){
+ this.uniforms.clipTask.value = mode;
}
+ get clipMethod(){
+ return this.uniforms.clipMethod.value;
+ }
+
+ set clipMethod(mode){
+ this.uniforms.clipMethod.value = mode;
+ }
get weighted(){
return this._weighted;
@@ -1077,6 +1097,18 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
return texture;
}
+ disableEvents(){
+ if(this._hiddenListeners === undefined){
+ this._hiddenListeners = this._listeners;
+ this._listeners = {};
+ }
+ };
+
+ enableEvents(){
+ this._listeners = this._hiddenListeners;
+ this._hiddenListeners = undefined;
+ };
+
copyFrom(from){
for(let name of this.uniforms){
diff --git a/src/materials/shaders/normalize.fs b/src/materials/shaders/normalize.fs
index dacfc746..7c816f56 100644
--- a/src/materials/shaders/normalize.fs
+++ b/src/materials/shaders/normalize.fs
@@ -1,22 +1,22 @@
#extension GL_EXT_frag_depth : enable
-uniform sampler2D depthMap;
-uniform sampler2D texture;
+uniform sampler2D uWeightMap;
+uniform sampler2D uDepthMap;
varying vec2 vUv;
void main() {
- float depth = texture2D(depthMap, vUv).g;
+ float depth = texture2D(uDepthMap, vUv).g;
- if(depth <= 0.0){
+ if(depth >= 1.0){
discard;
}
-
- vec4 color = texture2D(texture, vUv);
+
+ vec4 color = texture2D(uWeightMap, vUv);
color = color / color.w;
-
+
gl_FragColor = vec4(color.xyz, 1.0);
-
+
gl_FragDepthEXT = depth;
}
\ No newline at end of file
diff --git a/src/materials/shaders/normalize.vs b/src/materials/shaders/normalize.vs
index dd473700..e60e8094 100644
--- a/src/materials/shaders/normalize.vs
+++ b/src/materials/shaders/normalize.vs
@@ -2,7 +2,6 @@
varying vec2 vUv;
void main() {
- vUv = uv;
-
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
+ vUv = uv;
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
}
\ No newline at end of file
diff --git a/src/materials/shaders/normalize_and_edl.fs b/src/materials/shaders/normalize_and_edl.fs
new file mode 100644
index 00000000..b017b111
--- /dev/null
+++ b/src/materials/shaders/normalize_and_edl.fs
@@ -0,0 +1,56 @@
+
+#extension GL_EXT_frag_depth : enable
+
+uniform sampler2D uWeightMap;
+uniform sampler2D uEDLMap;
+uniform sampler2D uDepthMap;
+
+uniform float screenWidth;
+uniform float screenHeight;
+uniform vec2 neighbours[NEIGHBOUR_COUNT];
+uniform float edlStrength;
+uniform float radius;
+
+varying vec2 vUv;
+
+float response(float depth){
+ vec2 uvRadius = radius / vec2(screenWidth, screenHeight);
+
+ float sum = 0.0;
+
+ for(int i = 0; i < NEIGHBOUR_COUNT; i++){
+ vec2 uvNeighbor = vUv + uvRadius * neighbours[i];
+
+ float neighbourDepth = texture2D(uEDLMap, uvNeighbor).a;
+
+ if(neighbourDepth != 0.0){
+ if(depth == 0.0){
+ sum += 100.0;
+ }else{
+ sum += max(0.0, depth - neighbourDepth);
+ }
+ }
+ }
+
+ return sum / float(NEIGHBOUR_COUNT);
+}
+
+void main() {
+ float depth = texture2D(uDepthMap, vUv).g;
+
+ if(depth >= 1.0){
+ discard;
+ }
+
+ float edlDepth = texture2D(uEDLMap, vUv).a;
+ float res = response(edlDepth);
+ float shade = exp(-res * 300.0 * edlStrength);
+
+ vec4 color = texture2D(uWeightMap, vUv);
+ color = color / color.w;
+ color = color * shade;
+
+ gl_FragColor = vec4(color.xyz, 1.0);
+
+ gl_FragDepthEXT = depth;
+}
\ No newline at end of file
diff --git a/src/materials/shaders/pointcloud.fs b/src/materials/shaders/pointcloud.fs
index d4b77bdd..8b2cb5e9 100644
--- a/src/materials/shaders/pointcloud.fs
+++ b/src/materials/shaders/pointcloud.fs
@@ -26,7 +26,6 @@ uniform float uScreenWidth;
uniform float uScreenHeight;
varying vec3 vColor;
-varying float vLinearDepth;
varying float vLogDepth;
varying vec3 vViewPosition;
varying float vRadius;
@@ -41,8 +40,7 @@ uniform mat4 uSnapProj[num_snapshots];
uniform mat4 uSnapProjInv[num_snapshots];
uniform mat4 uSnapViewInv[num_snapshots];
-varying vec4 vSnapProjected[num_snapshots];
-varying float vSnapProjectedDistance[num_snapshots];
+varying float vSnapTextureID;
#endif
@@ -58,56 +56,56 @@ void main() {
float depth = gl_FragCoord.z;
- #if defined(num_snapshots) && num_snapshots > 0
- vec3 sRGB = vec3(0.0, 0.0, 0.0);
- float sA = 0.0;
+ //#if defined(num_snapshots) && num_snapshots > 0
+ // vec3 sRGB = vec3(0.0, 0.0, 0.0);
+ // float sA = 0.0;
- for(int i = 0; i < num_snapshots; i++){
+ // for(int i = 0; i < num_snapshots; i++){
- float snapLinearDistance = 0.0;
- float currentLinearDistance = vSnapProjectedDistance[i];
- vec2 uv;
+ // float snapLinearDistance = 0.0;
+ // float currentLinearDistance = vSnapProjectedDistance[i];
+ // vec2 uv;
- {
- vec2 pc = vec2(gl_PointCoord.x - 0.5, (1.0 - gl_PointCoord.y) - 0.5);
- vec2 offset = (pc * vPointSize) / vec2(uScreenWidth, uScreenHeight);
-
- uv = 0.5 * (vSnapProjected[i].xy /vSnapProjected[i].w) + 0.5 + offset;
-
- vec4 td = texture2D(uSnapshotDepth[i], uv);
- float d = td.r;
+ // {
+ // vec2 pc = vec2(gl_PointCoord.x - 0.5, (1.0 - gl_PointCoord.y) - 0.5);
+ // vec2 offset = (pc * vPointSize) / vec2(uScreenWidth, uScreenHeight);
+ //
+ // uv = 0.5 * (vSnapProjected[i].xy /vSnapProjected[i].w) + 0.5 + offset;
+ //
+ // vec4 td = texture2D(uSnapshotDepth[i], uv);
+ // float d = td.r;
- // TODO save linear distance in uSnapshotDepth!!!
- vec4 snapViewPos = uSnapProjInv[i] * vec4(uv * 2.0 - 1.0, d * 2.0 - 1.0, 1.0);
- snapViewPos = snapViewPos / snapViewPos.w;
- snapLinearDistance = -snapViewPos.z;
+ // // TODO save linear distance in uSnapshotDepth!!!
+ // vec4 snapViewPos = uSnapProjInv[i] * vec4(uv * 2.0 - 1.0, d * 2.0 - 1.0, 1.0);
+ // snapViewPos = snapViewPos / snapViewPos.w;
+ // snapLinearDistance = -snapViewPos.z;
- }
+ // }
- if(abs(currentLinearDistance - snapLinearDistance) < vRadius * 1.0){
- vec4 col = texture2D(uSnapshot[i], uv);
- //vec4 col = vec4(0.5, 1.0, 0.0, 1.0);
- sRGB += col.rgb;
+ // if(abs(currentLinearDistance - snapLinearDistance) < vRadius * 1.0){
+ // vec4 col = texture2D(uSnapshot[i], uv);
+ // //vec4 col = vec4(0.5, 1.0, 0.0, 1.0);
+ // sRGB += col.rgb;
- if(col.a != 0.0){
- sA = sA + 1.0;
- }
- }else{
- //sRGB += vColor;
- //sA += 1.0;
-
- }
+ // if(col.a != 0.0){
+ // sA = sA + 1.0;
+ // }
+ // }else{
+ // //sRGB += vColor;
+ // //sA += 1.0;
+ //
+ // }
- }
+ // }
- color = sRGB / sA;
- if(sA == 0.0){
- //color = vColor;
- discard;
- }
-
- #endif
+ // color = sRGB / sA;
+ // if(sA == 0.0){
+ // //color = vColor;
+ // discard;
+ // }
+ //
+ //#endif
#if defined(circle_point_shape) || defined(paraboloid_point_shape)
@@ -153,6 +151,15 @@ void main() {
gl_FragColor.a = vLogDepth;
#endif
#endif
+
+ #if defined(weighted_splats)
+ float distance = 2.0 * length(gl_PointCoord.xy - 0.5);
+ float weight = max(0.0, 1.0 - distance);
+ weight = pow(weight, 1.5);
+
+ gl_FragColor.a = weight;
+ gl_FragColor.xyz = gl_FragColor.xyz * weight;
+ #endif
}
diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs
index 07f02349..70d90a57 100644
--- a/src/materials/shaders/pointcloud.vs
+++ b/src/materials/shaders/pointcloud.vs
@@ -12,7 +12,8 @@ attribute float classification;
attribute float returnNumber;
attribute float numberOfReturns;
attribute float pointSourceID;
-attribute vec4 index;
+attribute vec4 indices;
+attribute float spacing;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
@@ -25,11 +26,23 @@ uniform float fov;
uniform float near;
uniform float far;
+uniform bool uDebug;
+
uniform bool uUseOrthographicCamera;
uniform float uOrthoWidth;
uniform float uOrthoHeight;
-uniform int clipMode;
+
+#define CLIPTASK_NONE 0
+#define CLIPTASK_HIGHLIGHT 1
+#define CLIPTASK_SHOW_INSIDE 2
+#define CLIPTASK_SHOW_OUTSIDE 3
+
+#define CLIPMETHOD_INSIDE_ANY 0
+#define CLIPMETHOD_INSIDE_ALL 1
+
+uniform int clipTask;
+uniform int clipMethod;
#if defined(num_clipboxes) && num_clipboxes > 0
uniform mat4 clipBoxes[num_clipboxes];
#endif
@@ -37,7 +50,7 @@ uniform int clipMode;
#if defined(num_clippolygons) && num_clippolygons > 0
uniform int uClipPolygonVCount[num_clippolygons];
uniform vec3 uClipPolygonVertices[num_clippolygons * 8];
- uniform mat4 uClipPolygonVP[num_clippolygons];
+ uniform mat4 uClipPolygonWVP[num_clippolygons];
#endif
uniform float size;
@@ -51,6 +64,7 @@ uniform float uOctreeSize;
uniform vec3 uBBSize;
uniform float uLevel;
uniform float uVNStart;
+uniform bool uIsLeafNode;
uniform vec3 uColor;
uniform float uOpacity;
@@ -73,7 +87,6 @@ uniform float wSourceID;
uniform vec3 uShadowColor;
-
uniform sampler2D visibleNodes;
uniform sampler2D gradient;
uniform sampler2D classificationLUT;
@@ -81,6 +94,7 @@ uniform sampler2D classificationLUT;
#if defined(num_shadowmaps) && num_shadowmaps > 0
uniform sampler2D uShadowMap[num_shadowmaps];
uniform mat4 uShadowWorldView[num_shadowmaps];
+uniform mat4 uShadowProj[num_shadowmaps];
#endif
#if defined(num_snapshots) && num_snapshots > 0
@@ -89,16 +103,13 @@ uniform mat4 uSnapView[num_snapshots];
uniform mat4 uSnapProj[num_snapshots];
uniform mat4 uSnapScreenToCurrentView[num_snapshots];
-varying vec4 vSnapProjected[num_snapshots];
-varying float vSnapProjectedDistance[num_snapshots];
+varying float vSnapTextureID;
#endif
varying vec3 vColor;
-varying float vLinearDepth;
varying float vLogDepth;
varying vec3 vViewPosition;
varying float vRadius;
-varying vec3 vWorldPosition;
varying float vPointSize;
@@ -367,10 +378,10 @@ vec3 getRGB(){
rgb = pow(rgb, vec3(rgbGamma));
rgb = rgb + rgbBrightness;
- rgb = (rgb - 0.5) * getContrastFactor(rgbContrast) + 0.5;
+ //rgb = (rgb - 0.5) * getContrastFactor(rgbContrast) + 0.5;
rgb = clamp(rgb, 0.0, 1.0);
-
- //rgb = indices.rgb;
+
+ //rgb = indices.rgb;
//rgb.b = pcIndex / 255.0;
@@ -471,41 +482,6 @@ vec3 getCompositeColor(){
-#if defined(num_clippolygons) && num_clippolygons > 0
-bool pointInClipPolygon(vec3 point, int polyIdx) {
- vec4 screenClipPos = uClipPolygonVP[polyIdx] * modelMatrix * vec4(point, 1.0);
- screenClipPos.xy = screenClipPos.xy / screenClipPos.w * 0.5 + 0.5;
-
- int j = uClipPolygonVCount[polyIdx] - 1;
- bool c = false;
- for(int i = 0; i < 8; i++) {
- if(i == uClipPolygonVCount[polyIdx]) {
- break;
- }
-
- vec4 verti = uClipPolygonVP[polyIdx] * vec4(uClipPolygonVertices[polyIdx * 8 + i], 1);
- vec4 vertj = uClipPolygonVP[polyIdx] * vec4(uClipPolygonVertices[polyIdx * 8 + j], 1);
- verti.xy = verti.xy / verti.w * 0.5 + 0.5;
- vertj.xy = vertj.xy / vertj.w * 0.5 + 0.5;
- if( ((verti.y > screenClipPos.y) != (vertj.y > screenClipPos.y)) &&
- (screenClipPos.x < (vertj.x-verti.x) * (screenClipPos.y-verti.y) / (vertj.y-verti.y) + verti.x) ) {
- c = !c;
- }
- j = i;
- }
-
- return c;
-}
-#endif
-
-void testInsideClipVolume(bool inside) {
- if(inside && clipMode == 2 || !inside && clipMode == 3) {
- gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0);
- } else if(clipMode == 1 && inside) {
- vColor.r += 0.5;
- }
-}
-
vec3 getColor(){
vec3 color;
@@ -517,7 +493,7 @@ vec3 getColor(){
vec3 cHeight = getElevation();
color = (1.0 - uTransition) * getRGB() + uTransition * cHeight;
#elif defined color_type_depth
- float linearDepth = -mvPosition.z ;
+ float linearDepth = gl_Position.w;
float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5;
color = vec3(linearDepth, expDepth, 0.0);
#elif defined color_type_intensity
@@ -533,7 +509,7 @@ vec3 getColor(){
float w = depth / 10.0;
color = texture2D(gradient, vec2(w,1.0-w)).rgb;
#elif defined color_type_point_index
- color = index.rgb;
+ color = indices.rgb;
#elif defined color_type_classification
vec4 cl = getClassification();
color = cl.rgb;
@@ -556,25 +532,33 @@ float getPointSize(){
float pointSize = 1.0;
float slope = tan(fov / 2.0);
- float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z);
+ float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z);
+ //float size = spacing * 0.01;
+
float r = uOctreeSpacing * 1.5;
vRadius = r;
#if defined fixed_point_size
pointSize = size;
#elif defined attenuated_point_size
if(uUseOrthographicCamera){
- pointSize = size;
+ pointSize = size;
}else{
- pointSize = pointSize * projFactor;
+ pointSize = size * spacing * projFactor;
+ //pointSize = pointSize * projFactor;
}
#elif defined adaptive_point_size
if(uUseOrthographicCamera) {
float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
pointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth;
} else {
- float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
- pointSize = worldSpaceSize * projFactor;
+
+ if(uIsLeafNode && false){
+ pointSize = size * spacing * projFactor;
+ }else{
+ float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
+ pointSize = worldSpaceSize * projFactor;
+ }
}
#endif
@@ -586,6 +570,46 @@ float getPointSize(){
return pointSize;
}
+#if defined(num_clippolygons) && num_clippolygons > 0
+bool pointInClipPolygon(vec3 point, int polyIdx) {
+
+ mat4 wvp = uClipPolygonWVP[polyIdx];
+ //vec4 screenClipPos = uClipPolygonVP[polyIdx] * modelMatrix * vec4(point, 1.0);
+ //screenClipPos.xy = screenClipPos.xy / screenClipPos.w * 0.5 + 0.5;
+
+ vec4 pointNDC = wvp * vec4(point, 1.0);
+ pointNDC.xy = pointNDC.xy / pointNDC.w;
+
+ int j = uClipPolygonVCount[polyIdx] - 1;
+ bool c = false;
+ for(int i = 0; i < 8; i++) {
+ if(i == uClipPolygonVCount[polyIdx]) {
+ break;
+ }
+
+ //vec4 verti = wvp * vec4(uClipPolygonVertices[polyIdx * 8 + i], 1);
+ //vec4 vertj = wvp * vec4(uClipPolygonVertices[polyIdx * 8 + j], 1);
+
+ //verti.xy = verti.xy / verti.w;
+ //vertj.xy = vertj.xy / vertj.w;
+
+ //verti.xy = verti.xy / verti.w * 0.5 + 0.5;
+ //vertj.xy = vertj.xy / vertj.w * 0.5 + 0.5;
+
+ vec3 verti = uClipPolygonVertices[polyIdx * 8 + i];
+ vec3 vertj = uClipPolygonVertices[polyIdx * 8 + j];
+
+ if( ((verti.y > pointNDC.y) != (vertj.y > pointNDC.y)) &&
+ (pointNDC.x < (vertj.x-verti.x) * (pointNDC.y-verti.y) / (vertj.y-verti.y) + verti.x) ) {
+ c = !c;
+ }
+ j = i;
+ }
+
+ return c;
+}
+#endif
+
void doClipping(){
#if !defined color_type_composite
@@ -597,40 +621,52 @@ void doClipping(){
}
#endif
+ int clipVolumesCount = 0;
+ int insideCount = 0;
+
#if defined(num_clipboxes) && num_clipboxes > 0
- if(clipMode != 0) {
- bool insideAny = false;
- for(int i = 0; i < num_clipboxes; 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;
- }
- testInsideClipVolume(insideAny);
- }
+ for(int i = 0; i < num_clipboxes; 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;
+
+ insideCount = insideCount + (inside ? 1 : 0);
+ clipVolumesCount++;
+ }
#endif
#if defined(num_clippolygons) && num_clippolygons > 0
+ for(int i = 0; i < num_clippolygons; i++) {
+ bool inside = pointInClipPolygon(position, i);
-
- if(clipMode != 0) {
- bool polyInsideAny = false;
- for(int i = 0; i < num_clippolygons; i++) {
- polyInsideAny = polyInsideAny || pointInClipPolygon(position, i);
- }
- testInsideClipVolume(polyInsideAny);
+ insideCount = insideCount + (inside ? 1 : 0);
+ clipVolumesCount++;
}
- #endif
+ #endif
+
+ bool insideAny = insideCount > 0;
+ bool insideAll = (clipVolumesCount > 0) && (clipVolumesCount == insideCount);
+
+ if(clipMethod == CLIPMETHOD_INSIDE_ANY){
+ if(insideAny && clipTask == CLIPTASK_HIGHLIGHT){
+ vColor.r += 0.5;
+ }else if(!insideAny && clipTask == CLIPTASK_SHOW_INSIDE){
+ gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
+ }else if(insideAny && clipTask == CLIPTASK_SHOW_OUTSIDE){
+ gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
+ }
+ }else if(clipMethod == CLIPMETHOD_INSIDE_ALL){
+ if(insideAll && clipTask == CLIPTASK_HIGHLIGHT){
+ vColor.r += 0.5;
+ }else if(!insideAll && clipTask == CLIPTASK_SHOW_INSIDE){
+ gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
+ }else if(insideAll && clipTask == CLIPTASK_SHOW_OUTSIDE){
+ gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
+ }
+ }
}
-//float step(float edge, float v){
-// return v < edge ? 0.0 : 1.0;
-//}
-
-float linearStep(float min, float max, float v){
- return clamp((v - min) / (max - min), 0.0, 1.0);
-}
//
@@ -647,7 +683,6 @@ void main() {
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
vViewPosition = mvPosition.xyz;
gl_Position = projectionMatrix * mvPosition;
- vLinearDepth = gl_Position.w;
vLogDepth = log2(-mvPosition.z);
@@ -661,40 +696,36 @@ void main() {
// CLIPPING
doClipping();
-
-
-
-
- #if defined(num_snapshots) && num_snapshots > 0
-
- for(int i = 0; i < num_snapshots; i++){
- vSnapProjected[i] = uSnapProj[i] * uSnapView[i] * modelMatrix * vec4(position, 1.0);
- vSnapProjectedDistance[i] = -(uSnapView[i] * modelMatrix * vec4(position, 1.0)).z;
- }
-
- #endif
+ //#if defined(num_snapshots) && num_snapshots > 0
+
+ // for(int i = 0; i < num_snapshots; i++){
+ // vSnapProjected[i] = uSnapProj[i] * uSnapView[i] * modelMatrix * vec4(position, 1.0);
+ // vSnapProjectedDistance[i] = -(uSnapView[i] * modelMatrix * vec4(position, 1.0)).z;
+ // }
+ //
+ //#endif
#if defined(num_shadowmaps) && num_shadowmaps > 0
const float sm_near = 0.1;
- const float sm_far = 1000.0;
+ const float sm_far = 10000.0;
for(int i = 0; i < num_shadowmaps; i++){
vec3 viewPos = (uShadowWorldView[i] * vec4(position, 1.0)).xyz;
- float distanceToLight = length(viewPos);
- float u = atan(viewPos.y, viewPos.x) / PI;
- float v = atan(viewPos.z, length(viewPos.xy)) / PI;
- float distance = length(viewPos);
- float depth = ((distance - sm_near) / (sm_far - sm_near));
-
- vec2 uv = vec2(u, v) * 0.5 + 0.5;
- vec2 sampleStep = vec2(1.0 / (4.0*1024.0), 1.0 / (4.0*1024.0));
+ float distanceToLight = abs(viewPos.z);
+
+ vec4 projPos = uShadowProj[i] * uShadowWorldView[i] * vec4(position, 1);
+ vec3 nc = projPos.xyz / projPos.w;
+
+ float u = nc.x * 0.5 + 0.5;
+ float v = nc.y * 0.5 + 0.5;
+ vec2 sampleStep = vec2(1.0 / (2.0*1024.0), 1.0 / (2.0*1024.0)) * 1.5;
vec2 sampleLocations[9];
sampleLocations[0] = vec2(0.0, 0.0);
sampleLocations[1] = sampleStep;
@@ -707,28 +738,54 @@ void main() {
sampleLocations[7] = vec2(sampleStep.x, 0.0);
sampleLocations[8] = vec2(-sampleStep.x, 0.0);
- float visible_samples = 0.0;
- float sumSamples = 0.0;
+ float visibleSamples = 0.0;
+ float numSamples = 0.0;
+
+ float bias = vRadius * 2.0;
- float bias = vRadius * 1.0;
for(int j = 0; j < 9; j++){
+ vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]);
- vec2 moments = texture2D(uShadowMap[j], uv + sampleLocations[j]).xy + sm_near;
- //float p = smoothstep(distanceToLight - 10.0 * bias, distanceToLight, moments.x);
- float p = step(distanceToLight - 5.0 * bias, moments.x);
+ float linearDepthFromSM = depthMapValue.x + bias;
+ float linearDepthFromViewer = distanceToLight;
- visible_samples += (1.0 - p);
+ if(linearDepthFromSM > linearDepthFromViewer){
+ visibleSamples += 1.0;
+ }
-
- sumSamples = sumSamples + 1.0;
+ numSamples += 1.0;
}
- float coverage = 1.0 - visible_samples / sumSamples;
- float shade = coverage * 0.5 + 0.5;
+ float visibility = visibleSamples / numSamples;
- vColor = vColor * shade + uShadowColor * (1.0 - shade);
+ if(u < 0.0 || u > 1.0 || v < 0.0 || v > 1.0 || nc.x < -1.0 || nc.x > 1.0 || nc.y < -1.0 || nc.y > 1.0 || nc.z < -1.0 || nc.z > 1.0){
+ vColor = vec3(0.0, 0.0, 0.2);
+ }else{
+ vColor = vec3(1.0, 1.0, 1.0) * visibility + vec3(1.0, 1.0, 1.0) * vec3(0.5, 0.0, 0.0) * (1.0 - visibility);
+ }
}
#endif
+ #if defined hq_depth_pass
+ float originalDepth = gl_Position.w;
+ float adjustedDepth = originalDepth + 2.0 * vRadius;
+ float adjust = adjustedDepth / originalDepth;
+
+ mvPosition.xyz = mvPosition.xyz * adjust;
+ gl_Position = projectionMatrix * mvPosition;
+ #endif
+
+ if(uDebug){
+ vColor.b = (vColor.r + vColor.g + vColor.b) / 3.0;
+ vColor.r = 1.0;
+ vColor.g = 1.0;
+ }
+
+ //vColor = vec3(1.0, 1.0, 1.0) * spacing / 0.05;
+
+ //if(getLOD() != uLevel){
+ //gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
+ //}
+
}
diff --git a/src/materials/shaders/pointcloud_sm.vs b/src/materials/shaders/pointcloud_sm.vs
index d81b0ca6..927f4925 100644
--- a/src/materials/shaders/pointcloud_sm.vs
+++ b/src/materials/shaders/pointcloud_sm.vs
@@ -5,7 +5,10 @@ precision mediump int;
attribute vec3 position;
attribute vec3 color;
-uniform mat4 uWorldView;
+uniform mat4 modelMatrix;
+uniform mat4 modelViewMatrix;
+uniform mat4 projectionMatrix;
+uniform mat4 viewMatrix;
uniform float uScreenWidth;
uniform float uScreenHeight;
@@ -86,7 +89,6 @@ float getLOD(){
}
offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;
-
}
return depth;
@@ -94,84 +96,47 @@ float getLOD(){
#endif
+float getPointSize(){
+ float pointSize = 1.0;
+
+ float slope = tan(fov / 2.0);
+ float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z);
+
+ float r = uOctreeSpacing * 1.5;
+ vRadius = r;
+ #if defined fixed_point_size
+ pointSize = size;
+ #elif defined attenuated_point_size
+ if(uUseOrthographicCamera){
+ pointSize = size;
+ }else{
+ pointSize = pointSize * projFactor;
+ }
+ #elif defined adaptive_point_size
+ if(uUseOrthographicCamera) {
+ float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
+ pointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth;
+ } else {
+ float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
+ pointSize = worldSpaceSize * projFactor;
+ }
+ #endif
-vec3 sphericalToPlanar(vec3 pos){
- float u = atan(pos.y, pos.x) / PI;
- float v = atan(pos.z, length(pos.xy)) / PI;
- float distance = length(pos);
+ pointSize = max(minSize, pointSize);
+ pointSize = min(maxSize, pointSize);
+
+ vRadius = pointSize / projFactor;
- return vec3(u, v, distance);
+ return pointSize;
}
+
void main() {
- vec3 viewPos = (uWorldView * vec4(position, 1.0)).xyz;
-
- //float u = atan(viewPos.y, viewPos.x) / PI;
- //float v = atan(viewPos.z, length(viewPos.xy)) / PI;
- //float distance = length(viewPos);
-
- vec3 planar = sphericalToPlanar(viewPos);
- float distance = planar.z;
- vLinearDepth = distance;
-
- float t = 2.0 * ((planar.z - near) / (far - near)) - 1.0;
-
- gl_Position = vec4(planar.xy, t, 1.0);
-
- vColor = vec3(1.0, 1.0, 1.0) * (distance / 20.0);
-
- float pointSize = 2.0;
- #if defined(adaptive_point_size)
- float lod = getLOD();
- float r = uSpacing / pow(2.0, lod);
- float pr = 0.5 * r / distance;
-
- pointSize = pr * uScreenWidth;
-
-
- vColor = vec3(1.0, 1.0, 1.0) * lod * 0.2;
-
- #else
- pointSize = 2.0;
- #endif
-
- pointSize = min(pointSize, 20.0);
+ vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
+ vLinearDepth = gl_Position.w;
+ float pointSize = getPointSize();
gl_PointSize = pointSize;
-
- // ---------------------
- // POINT SIZE
- // ---------------------
- //float pointSize = 1.0;
- //
- //float slope = tan(fov / 2.0);
- //float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z);
- //
- //float r = uSpacing * 1.5;
- //vRadius = r;
- //#if defined fixed_point_size
- // pointSize = size;
- //#elif defined attenuated_point_size
- // pointSize = size;
- // if(!useOrthographicCamera)
- // pointSize = pointSize * projFactor;
- //#elif defined adaptive_point_size
- // if(useOrthographicCamera) {
- // pointSize = size * r / (orthoRange * pow(2.0, getLOD())) * uScreenWidth;
- // } else {
- // float worldSpaceSize = size * r / getPointSizeAttenuation();
- // pointSize = worldSpaceSize * projFactor;
- // }
- //#endif
-//
- //pointSize = max(minSize, pointSize);
- //pointSize = min(maxSize, pointSize);
- //
- //vRadius = pointSize / projFactor;
- //
- //gl_PointSize = pointSize;
- //vPointSize = gl_PointSize;
-
}
diff --git a/src/navigation/EarthControls.js b/src/navigation/EarthControls.js
index fd637189..bea31b19 100644
--- a/src/navigation/EarthControls.js
+++ b/src/navigation/EarthControls.js
@@ -115,7 +115,7 @@ Potree.EarthControls = class EarthControls extends THREE.EventDispatcher {
this.scene.getActiveCamera(),
this.viewer,
this.scene.pointclouds,
- {pickClipped: true});
+ {pickClipped: false});
if (I) {
this.pivot = I.location;
diff --git a/src/navigation/InputHandler.js b/src/navigation/InputHandler.js
index 6b082b63..6378d40c 100644
--- a/src/navigation/InputHandler.js
+++ b/src/navigation/InputHandler.js
@@ -170,8 +170,8 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher {
onKeyDown (e) {
if (this.logMessages) console.log(this.constructor.name + ': onKeyDown');
- if (e.keyCode === 46 && this.selection.length > 0) {
- // DELETE
+ // DELETE
+ if (e.keyCode === Potree.KeyCodes.DELETE && this.selection.length > 0) {
this.dispatchEvent({
type: 'delete',
selection: this.selection
@@ -561,6 +561,26 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher {
});
}
+ deselect(object){
+
+ let oldSelection = this.selection;
+
+ let index = this.selection.indexOf(object);
+
+ if(index >= 0){
+ this.selection.splice(index, 1);
+ object.dispatchEvent({
+ type: 'deselect'
+ });
+
+ this.dispatchEvent({
+ type: 'selection_changed',
+ oldSelection: oldSelection,
+ selection: this.selection
+ });
+ }
+ }
+
deselectAll () {
for (let object of this.selection) {
object.dispatchEvent({
diff --git a/src/stuff/HoverMenu.js b/src/stuff/HoverMenu.js
deleted file mode 100644
index 07ba458a..00000000
--- a/src/stuff/HoverMenu.js
+++ /dev/null
@@ -1,90 +0,0 @@
-/* globals HoverMenu:true HoverMenuItem:true */
-/* exported HoverMenu */
-/* exported HoverMenuItem */
-HoverMenuItem = class {
- constructor (icon, callback) {
- this.icon = icon;
- this.callback = callback;
-
- this.element = $(`
-
- `);
-
- this.element.click(function () {
- callback();
- });
- }
-};
-
-HoverMenu = class {
- constructor (icon) {
- let scope = this;
-
- this.items = [];
-
- this.x = 0;
- this.y = 0;
- this.circumference = 32;
-
- this.element = $('');
- this.elIcon = $(``);
- this.element.append(this.elIcon);
-
- this.element.click(function () {
- $(this).find('.hover_menu_item').fadeIn(200);
- $(this).find('.hover_menu_icon').fadeOut(200);
-
- $(this).css('left', (scope.x - scope.circumference - $(this).width() / 2) + 'px');
- $(this).css('top', (scope.y - scope.circumference - $(this).height() / 2) + 'px');
- $(this).css('border', scope.circumference + 'px solid transparent');
- }).mouseleave(function () {
- $(this).find('.hover_menu_item').fadeOut(200);
- $(this).find('.hover_menu_icon').fadeIn(200);
-
- $(this).css('left', (scope.x - $(this).width() / 2) + 'px');
- $(this).css('top', (scope.y - $(this).height() / 2) + 'px');
- $(this).css('border', '0px solid black');
- });
- }
-
- addItem (item) {
- this.items.push(item);
- this.element.append(item.element);
- item.element.hide();
-
- this.arrange();
- }
-
- removeItem (item) {
- this.items = this.items.filter(e => e !== item);
- this.element.remove(item.element);
-
- this.arrange();
- }
-
- arrange () {
- let menuItems = this.element.find('.hover_menu_item');
- menuItems.each(function (index, value) {
- let u = (index / menuItems.length) * Math.PI * 2;
- let radius = 22;
- let x = Math.cos(u) * radius;// + offset ;
- let y = Math.sin(u) * radius;// + offset ;
-
- $(this).css('left', x).css('top', y);
- });
- }
-
- setPosition (x, y) {
- this.x = x;
- this.y = y;
-
- let rect = this.element.get(0).getBoundingClientRect();
-
- this.element.css('left', (this.x - rect.width / 2) + 'px');
- this.element.css('top', (this.y - rect.height / 2) + 'px');
- }
-};
diff --git a/src/utils.js b/src/utils.js
index 743823b8..101f8f61 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -524,6 +524,46 @@ Potree.utils = class {
}
window.history.replaceState({}, '', url);
}
+
+ // see https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
+ static clipboardCopy(text){
+ let textArea = document.createElement("textarea");
+
+ textArea.style.position = 'fixed';
+ textArea.style.top = 0;
+ textArea.style.left = 0;
+
+ textArea.style.width = '2em';
+ textArea.style.height = '2em';
+
+ textArea.style.padding = 0;
+
+ textArea.style.border = 'none';
+ textArea.style.outline = 'none';
+ textArea.style.boxShadow = 'none';
+
+ textArea.style.background = 'transparent';
+
+ textArea.value = text;
+
+ document.body.appendChild(textArea);
+
+ textArea.select();
+
+ try {
+ let success = document.execCommand('copy');
+ if(success){
+ console.log("copied text to clipboard");
+ }else{
+ console.log("copy to clipboard failed");
+ }
+ } catch (err) {
+ console.log("error while trying to copy to clipboard");
+ }
+
+ document.body.removeChild(textArea);
+
+ }
};
Potree.utils.screenPass = new function () {
diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js
index ffd8d015..55ba6a92 100644
--- a/src/utils/ClippingTool.js
+++ b/src/utils/ClippingTool.js
@@ -1,12 +1,5 @@
-Potree.ClipMode = {
- DISABLED: 0,
- HIGHLIGHT: 1,
- INSIDE: 2,
- OUTSIDE: 3
-};
-
Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{
constructor(viewer){
@@ -14,7 +7,6 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{
this.viewer = viewer;
- this.clipMode = Potree.ClipMode.HIGHLIGHT;
this.maxPolygonVertices = 8;
this.addEventListener("start_inserting_clipping_volume", e => {
@@ -64,128 +56,110 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{
this.scene.addEventListener("polygon_clip_volume_removed", this.onRemove);
}
- setClipMode(mode) {
- if(this.clipMode == mode) return;
-
- this.clipMode = mode;
- viewer.dispatchEvent({"type": "clipper.clipMode_changed", "viewer": viewer, "mode": mode});
- }
-
startInsertion(args = {}) {
let type = args.type || null;
- if(!type) return;
+ if(!type) return null;
- if(type == "plane") {
- let clipVolume = new Potree.ClipVolume(args);
+ let domElement = this.viewer.renderer.domElement;
+ let canvasSize = this.viewer.renderer.getSize();
- this.dispatchEvent({"type": "start_inserting_clipping_volume"});
+ let svg = $(`
+ `);
+ $(domElement.parentElement).append(svg);
+
+ let polyClipVol = new Potree.PolygonClipVolume(this.viewer.scene.getActiveCamera().clone());
+
+ this.dispatchEvent({"type": "start_inserting_clipping_volume"});
+
+ this.viewer.scene.addPolygonClipVolume(polyClipVol);
+ this.sceneMarker.add(polyClipVol);
+
+ let cancel = {
+ callback: null
+ };
+
+ let insertionCallback = (e) => {
+ if(e.button === THREE.MOUSE.LEFT){
- let I = Potree.utils.getMousePointCloudIntersection(
- e.drag.end,
- this.viewer.scene.getActiveCamera(),
- this.viewer,
- this.viewer.scene.pointclouds);
-
- if(I){
- clipVolume.position.copy(I.location);
- }
- };
-
- let drop = e => {
- clipVolume.removeEventListener("drag", drag);
- clipVolume.removeEventListener("drop", drop);
+ polyClipVol.addMarker();
+
+ // SVC Screen Line
+ svg.find("polyline").each((index, target) => {
+ let newPoint = svg[0].createSVGPoint();
+ newPoint.x = e.offsetX;
+ newPoint.y = e.offsetY;
+ let polyline = target.points.appendItem(newPoint);
+ });
- cancel.callback();
-
- clipVolume.dispatchEvent({"type": "clip_volume_changed", "volume": clipVolume});
- };
-
- cancel.callback = e => {
- clipVolume.removeEventListener("drag", drag);
- clipVolume.removeEventListener("drop", drop);
- this.viewer.removeEventListener("cancel_insertions", cancel.callback);
- };
-
- clipVolume.addEventListener("drag", drag);
- clipVolume.addEventListener("drop", drop);
- this.viewer.addEventListener("cancel_insertions", cancel.callback);
-
- this.viewer.inputHandler.startDragging(clipVolume);
- } else if(type == "polygon") {
- let polyClipVol = new Potree.PolygonClipVolume(this.viewer.scene.getActiveCamera().clone());
-
- this.dispatchEvent({"type": "start_inserting_clipping_volume"});
-
- //this.viewer.scene.addPolygonClipVolume(polyClipVol);
- this.sceneMarker.add(polyClipVol);
-
- let cancel = {
- callback: null
- };
-
- let insertionCallback = (e) => {
- if(e.button === THREE.MOUSE.LEFT){
- if(polyClipVol.markers.length > 1) {
- polyClipVol.addEdge(polyClipVol.markers.length - 2, polyClipVol.markers.length - 1);
- }
-
- polyClipVol.addMarker();
-
- if(polyClipVol.markers.length > this.maxPolygonVertices){
- cancel.callback();
- }
-
- this.viewer.inputHandler.startDragging(
- polyClipVol.markers[polyClipVol.markers.length - 1]);
- }else if(e.button === THREE.MOUSE.RIGHT){
+
+ if(polyClipVol.markers.length > this.maxPolygonVertices){
cancel.callback();
}
- };
-
- cancel.callback = e => {
- this.sceneMarker.remove(polyClipVol);
- if(polyClipVol.markers.length > 3) {
- polyClipVol.removeLastMarker();
- for(let i = 0; i < polyClipVol.markers.length; i++) {
- polyClipVol.markers[i].position.copy(polyClipVol.markersPosWorld[i]);
- polyClipVol.markers[i].visible = false;
- polyClipVol.remove(polyClipVol.edges[i]);
- }
- polyClipVol.edges = [];
- for(let i = 0; i < polyClipVol.markers.length - 1; i++) {
- polyClipVol.addEdge(i, i+1);
- }
- polyClipVol.addEdge(polyClipVol.markers.length - 1, 0);
- polyClipVol.addExtrudedEdges();
- polyClipVol.initialized = true;
- this.viewer.scene.addPolygonClipVolume(polyClipVol);
- } else {
- this.viewer.scene.removePolygonClipVolume(polyClipVol);
- }
+
+ this.viewer.inputHandler.startDragging(
+ polyClipVol.markers[polyClipVol.markers.length - 1]);
+ }else if(e.button === THREE.MOUSE.RIGHT){
+ cancel.callback(e);
+ }
+ };
+
+ cancel.callback = e => {
- this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true);
- this.viewer.removeEventListener("cancel_insertions", cancel.callback);
- this.viewer.inputHandler.enabled = true;
- };
-
- this.viewer.addEventListener("cancel_insertions", cancel.callback);
- this.viewer.renderer.domElement.addEventListener("mouseup", insertionCallback , true);
- this.viewer.inputHandler.enabled = false;
-
- polyClipVol.addMarker();
- this.viewer.inputHandler.startDragging(
- polyClipVol.markers[polyClipVol.markers.length - 1]);
- }
+ //let first = svg.find("polyline")[0].points[0];
+ //svg.find("polyline").each((index, target) => {
+ // let newPoint = svg[0].createSVGPoint();
+ // newPoint.x = first.x;
+ // newPoint.y = first.y;
+ // let polyline = target.points.appendItem(newPoint);
+ //});
+ svg.remove();
+
+ if(polyClipVol.markers.length > 3) {
+ polyClipVol.removeLastMarker();
+ polyClipVol.initialized = true;
+ } else {
+ this.viewer.scene.removePolygonClipVolume(polyClipVol);
+ }
+
+ this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true);
+ this.viewer.removeEventListener("cancel_insertions", cancel.callback);
+ this.viewer.inputHandler.enabled = true;
+ };
+
+ this.viewer.addEventListener("cancel_insertions", cancel.callback);
+ this.viewer.renderer.domElement.addEventListener("mouseup", insertionCallback , true);
+ this.viewer.inputHandler.enabled = false;
+
+ polyClipVol.addMarker();
+ this.viewer.inputHandler.startDragging(
+ polyClipVol.markers[polyClipVol.markers.length - 1]);
+
+ return polyClipVol;
}
update() {
diff --git a/src/utils/PointCloudSM.js b/src/utils/PointCloudSM.js
index 734a88fb..8baab9e7 100644
--- a/src/utils/PointCloudSM.js
+++ b/src/utils/PointCloudSM.js
@@ -5,11 +5,8 @@ Potree.PointCloudSM = class PointCloudSM{
this.potreeRenderer = potreeRenderer;
this.threeRenderer = this.potreeRenderer.threeRenderer;
- this.gl = this.threeRenderer.getContext();
- this.shader = new Potree.Shader(this.gl, "shadow_map", Potree.Shaders['pointcloud_sm.vs'], Potree.Shaders['pointcloud_sm.fs']);
- this.lightPos = new THREE.Vector3();
- this.target = new THREE.WebGLRenderTarget(4 * 1024, 4 * 1024, {
+ this.target = new THREE.WebGLRenderTarget(2 * 1024, 2 * 1024, {
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
format: THREE.RGBAFormat,
@@ -17,39 +14,42 @@ Potree.PointCloudSM = class PointCloudSM{
});
this.target.depthTexture = new THREE.DepthTexture();
this.target.depthTexture.type = THREE.UnsignedIntType;
-
- this.vnTexture = null;
- {
- let gl = this.gl;
- this.vnTexture = gl.createTexture();
+ //this.target = new THREE.WebGLRenderTarget(1024, 1024, {
+ // minFilter: THREE.NearestFilter,
+ // magFilter: THREE.NearestFilter,
+ // format: THREE.RGBAFormat,
+ // type: THREE.FloatType,
+ // depthTexture: new THREE.DepthTexture(undefined, undefined, THREE.UnsignedIntType)
+ //});
- gl.bindTexture(gl.TEXTURE_2D, this.vnTexture);
-
- const level = 0;
- const internalFormat = gl.RGB;
- const width = 2048;
- const height = 1;
- const border = 0;
- const srcFormat = gl.RGB;
- const srcType = gl.UNSIGNED_BYTE;
- const pixel = new Uint8Array(3 * width);
- gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
- width, height, border, srcFormat, srcType,
- pixel);
-
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
-
- gl.bindTexture(gl.TEXTURE_2D, null);
- }
-
+ this.threeRenderer.setClearColor(0xff0000, 1);
+ this.threeRenderer.clearTarget(this.target, true, true, true);
}
- setLightPos(pos){
- this.lightPos.copy(pos);
+ setLight(light){
+ this.light = light;
+
+ //let fov = (180 / Math.PI) * 2 * light.angle;
+ let fov = 90;
+ let aspect = light.shadow.mapSize.width / light.shadow.mapSize.height;
+ let near = 0.1;
+ let far = 10000;
+ this.camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
+ this.camera.up.set(0, 0, 1);
+ //this.camera.position.copy(light.position);
+ //this.camera.position.set(10, 0, 15);
+ this.camera.position.copy(light.position);
+ //this.camera.lookAt(new THREE.Vector3(0, 0, 8));
+
+ let target = new THREE.Vector3().addVectors(light.position, light.getWorldDirection());
+ this.camera.lookAt(target);
+
+ //this.camera.rotation.copy(light.rotation);
+ this.camera.updateProjectionMatrix();
+ this.camera.updateMatrix();
+ this.camera.updateMatrixWorld();
+ this.camera.matrixWorldInverse.getInverse(this.camera.matrixWorld);
}
setSize(width, height){
@@ -59,82 +59,12 @@ Potree.PointCloudSM = class PointCloudSM{
this.target.setSize(width, height);
}
- renderOctree(octree, nodes){
+ render(scene, camera){
+ //this.threeRenderer.setClearColor(0x00ff00, 1);
- let gl = this.gl;
- let shader = this.shader;
- let material = octree.material;
-
- let vsSource = `#define adaptive_point_size\n` + Potree.Shaders['pointcloud_sm.vs'];
- let fsSource = `#define adaptive_point_size\n` + Potree.Shaders['pointcloud_sm.fs'];
-
- try{
- shader.update(vsSource, fsSource);
- }catch(e){
- console.log(e);
- }
-
- gl.useProgram(shader.program);
-
- this.threeRenderer.setClearColor(0x000000, 1);
this.threeRenderer.clearTarget( this.target, true, true, true );
- this.threeRenderer.setClearColor(0x000000, 0);
-
- let view = new THREE.Matrix4().makeTranslation(...this.lightPos.clone().multiplyScalar(-1).toArray());
-
- let visibilityTextureData = octree.computeVisibilityTextureData(nodes);
- gl.bindTexture(gl.TEXTURE_2D, this.vnTexture);
- let vnData = new Uint8Array(3 * 2048);
- vnData.set(visibilityTextureData.data);
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 2048, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, vnData);
- gl.bindTexture(gl.TEXTURE_2D, null);
-
-
- shader.setUniform1i("visibleNodes", 0);
- gl.activeTexture(gl.TEXTURE0);
- gl.bindTexture(gl.TEXTURE_2D, this.vnTexture);
-
-
- let near = 0.1;
- let far = 1000.0;
- shader.setUniform1f("near", near);
- shader.setUniform1f("far", far);
- shader.setUniform1f("uScreenWidth", this.target.width);
- shader.setUniform1f("uScreenHeight", this.target.height);
-
- shader.setUniform1f("uSpacing", material.spacing);
- shader.setUniform("uOctreeSize", material.uniforms.octreeSize.value);
-
- for(let node of nodes){
- let world = node.sceneNode.matrixWorld;
- let worldView = new THREE.Matrix4().multiplyMatrices(view, world);
-
- shader.setUniformMatrix4(`uWorldView`, worldView);
-
- let vnStart = visibilityTextureData.offsets.get(node);
- shader.setUniform1f("uVNStart", vnStart);
-
- let level = node.getLevel();
- shader.setUniform1f("uLevel", level);
-
- let iBuffer = node.geometryNode.buffer;
-
- if(!this.potreeRenderer.buffers.has(iBuffer)){
- let buffers = this.potreeRenderer.createBuffer(iBuffer);
- this.potreeRenderer.buffers.set(iBuffer, buffers);
- }
-
- let buffer = this.potreeRenderer.buffers.get(iBuffer);
-
- gl.bindVertexArray(buffer.vao);
-
- let numPoints = iBuffer.numElements;
- gl.drawArrays(gl.POINTS, 0, numPoints);
-
- }
-
- gl.bindVertexArray(null);
-
+ this.potreeRenderer.render(scene, this.camera, this.target, {});
}
+
};
\ No newline at end of file
diff --git a/src/utils/PolygonClipVolume.js b/src/utils/PolygonClipVolume.js
index 8281a7f9..e23407a5 100644
--- a/src/utils/PolygonClipVolume.js
+++ b/src/utils/PolygonClipVolume.js
@@ -12,72 +12,37 @@ Potree.PolygonClipVolume = class extends THREE.Object3D{
this.camera.updateMatrixWorld();
this.camera.updateProjectionMatrix();
this.camera.matrixWorldInverse.getInverse(this.camera.matrixWorld);
+
this.viewMatrix = this.camera.matrixWorldInverse.clone();
this.projMatrix = this.camera.projectionMatrix.clone();
- this.markers = [];
- this.markersPosWorld = [];
- this.edges = [];
- this.extrudedEdges = [];
- this.sphereGeometry = new THREE.SphereGeometry(0.005, 10, 10);
- this.color = new THREE.Color( 0xff0000 );
- this.initialized = false;
- this.material = this.createSphereMaterial();
+ // projected markers
+ this.markers = [];
+ this.initialized = false;
}
- createSphereMaterial() {
- let sphereMaterial = new THREE.MeshBasicMaterial({
- color: this.color,
- depthTest: false,
- depthWrite: false}
- );
-
- return sphereMaterial;
- };
-
addMarker() {
- let marker = new THREE.Mesh(this.sphereGeometry, this.createSphereMaterial());
- if(this.markers.length > 0) {
- marker.position.copy(this.markers[this.markers.length - 1].position);
- }
+ let marker = new THREE.Mesh();
- let cancel = {
- callback: null
- };
+ let cancel;
let drag = e => {
- let pos = new THREE.Vector3(
- (e.drag.end.x / e.viewer.renderer.domElement.clientWidth) * 2 - 1,
- -(e.drag.end.y / e.viewer.renderer.domElement.clientHeight) * 2 + 1,
- 0.5);
+ let size = e.viewer.renderer.getSize();
+ let projectedPos = new THREE.Vector3(
+ 2.0 * (e.drag.end.x / size.width) - 1.0,
+ -2.0 * (e.drag.end.y / size.height) + 1.0,
+ 0
+ );
- let posWorld = pos.clone();
- //let camera = e.viewer.scene.getActiveCamera();
- let camera = this.camera;
- if(camera.isPerspectiveCamera) {
- posWorld.unproject(camera);
- var dir = posWorld.clone().sub(camera.position).normalize();
- posWorld = camera.position.clone().add( dir.multiplyScalar(1));
- } else {
- posWorld.unproject(camera);
- posWorld.add(camera.getWorldDirection().clone().multiplyScalar(-(Math.abs(camera.near) - 1)));
- }
- this.markersPosWorld[this.markersPosWorld.length - 1].copy(posWorld);
-
- let width = e.viewer.scaleFactor * e.viewer.renderArea.clientWidth;
- let height = e.viewer.scaleFactor * e.viewer.renderArea.clientHeight;
- let aspect = width / height;
- pos.y = pos.y * 1 / aspect;
- pos.z = -pos.z;
- marker.position.copy(pos);
+ marker.position.copy(projectedPos);
};
let drop = e => {
- cancel.callback();
+ cancel();
};
- cancel.callback = e => {
+ cancel = e => {
marker.removeEventListener("drag", drag);
marker.removeEventListener("drop", drop);
};
@@ -86,63 +51,12 @@ Potree.PolygonClipVolume = class extends THREE.Object3D{
marker.addEventListener("drop", drop);
- this.markersPosWorld.push(new THREE.Vector3(0, 0, 0));
this.markers.push(marker);
- this.add(marker);
}
- addEdge(start, end) {
- let lineGeometry = new THREE.Geometry();
- lineGeometry.vertices.push(this.markers[start].position, this.markers[end].position);
- lineGeometry.colors.push(this.color, this.color, this.color);
- let lineMaterial = new THREE.LineBasicMaterial( {
- linewidth: 1
- });
- lineMaterial.depthTest = false;
- let edge = new THREE.Line(lineGeometry, lineMaterial);
- edge.visible = true;
-
- this.add(edge);
- this.edges.push(edge);
- };
-
removeLastMarker() {
if(this.markers.length > 0) {
- this.remove(this.markers[this.markers.length - 1]);
this.markers.splice(this.markers.length - 1, 1);
- this.markersPosWorld.splice(this.markersPosWorld.length - 1, 1);
- }
- }
-
- addExtrudedEdges() {
- let dir = this.camera.getWorldDirection().normalize();
- let camPos = this.camera.getWorldPosition();
- for(let i = 0; i < this.markers.length; i++) {
- //let frontMarker = this.markers[i].position.clone();
- let backMarker = this.markers[i].position.clone();
- if(this.camera.isOrthographicCamera) {
- //frontMarker.add(dir.clone().multiplyScalar(1000));
- backMarker.add(dir.clone().multiplyScalar(1000));
- } else {
- let markerDir = backMarker.clone().sub(camPos);
- backMarker.add(markerDir.clone().multiplyScalar(1000));
- //frontMarker.copy(camPos);
- }
-
- let lineGeometry = new THREE.Geometry();
- lineGeometry.vertices.push(this.markers[i].position, backMarker);
- //lineGeometry.colors.push(this.color, this.color, this.color);
- let lineMaterial = new THREE.LineBasicMaterial( {
- linewidth: 1,
- color: this.color
- });
- lineMaterial.depthWrite = false;
- lineMaterial.depthTest = true;
- let edge = new THREE.Line(lineGeometry, lineMaterial);
- edge.visible = true;
-
- this.add(edge);
- this.extrudedEdges.push(edge);
}
}
diff --git a/src/utils/ScreenBoxSelectTool.js b/src/utils/ScreenBoxSelectTool.js
index 87e384a7..03af9052 100644
--- a/src/utils/ScreenBoxSelectTool.js
+++ b/src/utils/ScreenBoxSelectTool.js
@@ -20,13 +20,35 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat
let domElement = this.viewer.renderer.domElement;
let volume = new Potree.Volume();
- volume.clip = true;
+ volume.position.set(12345, 12345, 12345);
+ volume.showVolumeLabel = false;
+ volume.visible = false;
+ volume.update();
this.viewer.scene.addVolume(volume);
this.importance = 10;
+ let selectionBox = $(``);
+ $(domElement.parentElement).append(selectionBox);
+ selectionBox.css("right", "10px");
+ selectionBox.css("bottom", "10px");
+
let drag = e =>{
+ volume.visible = true;
+
+ let mStart = e.drag.start;
+ let mEnd = e.drag.end;
+
+ let box2D = new THREE.Box2();
+ box2D.expandByPoint(mStart);
+ box2D.expandByPoint(mEnd);
+
+ selectionBox.css("left", `${box2D.min.x}px`);
+ selectionBox.css("top", `${box2D.min.y}px`);
+ selectionBox.css("width", `${box2D.max.x - box2D.min.x}px`);
+ selectionBox.css("height", `${box2D.max.y - box2D.min.y}px`);
+
let camera = e.viewer.scene.getActiveCamera();
let size = new THREE.Vector2(
e.viewer.renderer.getSize().width,
@@ -52,6 +74,8 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat
let drop = e => {
this.importance = 0;
+ $(selectionBox).remove();
+
this.viewer.inputHandler.deselectAll();
this.viewer.inputHandler.toggleSelection(volume);
@@ -67,9 +91,16 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat
this.removeEventListener("drag", drag);
this.removeEventListener("drop", drop);
+ let allPointsNear = [];
+ let allPointsFar = [];
+
// TODO support more than one point cloud
for(let pointcloud of this.viewer.scene.pointclouds){
+ if(!pointcloud.visible){
+ continue;
+ }
+
let volCam = camera.clone();
volCam.left = -volume.scale.x / 2;
volCam.right = +volume.scale.x / 2;
@@ -95,6 +126,7 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat
height: 8,
pickWindowSize: 8,
all: true,
+ pickClipped: true,
pointSizeType: Potree.PointSizeType.FIXED,
pointSize: 1};
let pointsNear = pointcloud.pick(viewer, volCam, ray, pickerSettings);
@@ -106,22 +138,26 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat
volCam.matrixWorldInverse.getInverse(volCam.matrixWorld);
let pointsFar = pointcloud.pick(viewer, volCam, rayInverse, pickerSettings);
- if(pointsNear.length > 0 && pointsFar.length > 0){
- let viewLine = new THREE.Line3(ray.origin, new THREE.Vector3().addVectors(ray.origin, ray.direction));
-
- let closestOnLine = pointsNear.map(p => viewLine.closestPointToPoint(p.position, false));
- let closest = closestOnLine.sort( (a, b) => ray.origin.distanceTo(a) - ray.origin.distanceTo(b))[0];
-
- let farthestOnLine = pointsFar.map(p => viewLine.closestPointToPoint(p.position, false));
- let farthest = farthestOnLine.sort( (a, b) => ray.origin.distanceTo(b) - ray.origin.distanceTo(a))[0];
-
- let distance = closest.distanceTo(farthest);
- let centroid = new THREE.Vector3().addVectors(closest, farthest).multiplyScalar(0.5);
- volume.scale.z = distance * 1.1;
- volume.position.copy(centroid);
-
- }
+ allPointsNear.push(...pointsNear);
+ allPointsFar.push(...pointsFar);
}
+
+ if(allPointsNear.length > 0 && allPointsFar.length > 0){
+ let viewLine = new THREE.Line3(ray.origin, new THREE.Vector3().addVectors(ray.origin, ray.direction));
+
+ let closestOnLine = allPointsNear.map(p => viewLine.closestPointToPoint(p.position, false));
+ let closest = closestOnLine.sort( (a, b) => ray.origin.distanceTo(a) - ray.origin.distanceTo(b))[0];
+
+ let farthestOnLine = allPointsFar.map(p => viewLine.closestPointToPoint(p.position, false));
+ let farthest = farthestOnLine.sort( (a, b) => ray.origin.distanceTo(b) - ray.origin.distanceTo(a))[0];
+
+ let distance = closest.distanceTo(farthest);
+ let centroid = new THREE.Vector3().addVectors(closest, farthest).multiplyScalar(0.5);
+ volume.scale.z = distance * 1.1;
+ volume.position.copy(centroid);
+ }
+
+ volume.clip = true;
};
this.addEventListener("drag", drag);
diff --git a/src/utils/TransformationTool.js b/src/utils/TransformationTool.js
index d74cf398..d39a2a0a 100644
--- a/src/utils/TransformationTool.js
+++ b/src/utils/TransformationTool.js
@@ -65,25 +65,40 @@ Potree.TransformationTool = class TransformationTool {
this.initializeRotationHandles();
+ let 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));
+ }
+ this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: 0xffff00}));
+ this.scene.add(this.frame);
-
- //{
- // this.scene.add(new THREE.AmbientLight(0xdddddd));
-
- // let sg = new THREE.SphereGeometry(30, 32, 32);
- // let sm = new THREE.MeshToonMaterial({
- // color: 0x00ff00,
- // emmisive: 0x00ff00,
- // shininess: 50,
- // specular: 0x333333,
- // bumpScale: 1,
- // });
- // let s = new THREE.Mesh(sg, sm);
- // //s.scale.set(30, 30, 30);
- // this.scene.add(s);
-
-
- //}
+
}
initializeScaleHandles(){
@@ -865,6 +880,26 @@ Potree.TransformationTool = class TransformationTool {
this.scene.position.copy(selected.position);
this.scene.rotation.copy(selected.rotation);
+ {
+ let axisScale = (alignment) => {
+ //let handlePos = boxCenter.clone().add(boxSize.clone().multiplyScalar(0.5).multiply(alignment));
+ //handlePos.applyMatrix4(selected.matrixWorld);
+ let transformed = new THREE.Vector3(...alignment).applyMatrix4(selected.matrixWorld);
+ let distance = transformed.distanceTo(selected.getWorldPosition());
+
+ return distance;
+ };
+
+ let scale = new THREE.Vector3(
+ axisScale([1, 0, 0]),
+ axisScale([0, 1, 0]),
+ axisScale([0, 0, 1]),
+ );
+
+ this.frame.scale.copy(scale);
+ }
+ //this.frame.scale.copy(box.getSize());
+
}else{
this.scene.visible = false;
}
diff --git a/src/utils/Volume.js b/src/utils/Volume.js
index d0995047..b78d3a64 100644
--- a/src/utils/Volume.js
+++ b/src/utils/Volume.js
@@ -8,6 +8,8 @@ Potree.Volume = class extends THREE.Object3D {
this.name = 'volume_' + this.constructor.counter;
this._clip = args.clip || false;
+ this._visible = true;
+ this.showVolumeLabel = true;
this._modifiable = args.modifiable || true;
let boxGeometry = new THREE.BoxGeometry(1, 1, 1);
@@ -15,34 +17,6 @@ Potree.Volume = class extends THREE.Object3D {
let boxFrameGeometry = new THREE.Geometry();
{
- // let l = 0.1;
-
- // corner vertices
- // let v = [
- // [-0.5, -0.5, -0.5],
- // [-0.5, -0.5, +0.5],
- // [-0.5, +0.5, -0.5],
- // [-0.5, +0.5, +0.5],
- // [+0.5, -0.5, -0.5],
- // [+0.5, -0.5, +0.5],
- // [+0.5, +0.5, -0.5],
- // [+0.5, +0.5, +0.5]
- // ];
- //
- /// / create a cross at each corner with cross length l
- // for(let b of v){
- //
- // let b1 = [ b[0] - l * Math.sign(b[0]), b[1], b[2] ];
- // let b2 = [ b[0], b[1] - l * Math.sign(b[1]), b[2] ];
- // let b3 = [ b[0], b[1], b[2] - l * Math.sign(b[2]) ];
- //
- // // create the 3 lines that a cross consists of
- // for(let d of [b, b1, b, b2, b, b3]){
- // boxFrameGeometry.vertices.push(new THREE.Vector3().fromArray(d));
- // }
- //
- // }
-
// 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));
@@ -118,6 +92,18 @@ Potree.Volume = class extends THREE.Object3D {
this.update();
}
+ get visible(){
+ return this._visible;
+ }
+
+ set visible(value){
+ if(this._visible !== value){
+ this._visible = value;
+
+ this.dispatchEvent({type: "visibility_changed", object: this});
+ }
+ }
+
getVolume () {
return Math.abs(this.scale.x * this.scale.y * this.scale.z);
}
@@ -131,7 +117,7 @@ Potree.Volume = class extends THREE.Object3D {
this.label.visible = false;
} else {
this.box.visible = true;
- this.label.visible = true;
+ this.label.visible = this.showVolumeLabel;
}
};
diff --git a/src/utils/VolumeTool.js b/src/utils/VolumeTool.js
index f9c02c8b..b3a175dc 100644
--- a/src/utils/VolumeTool.js
+++ b/src/utils/VolumeTool.js
@@ -83,7 +83,7 @@ Potree.VolumeTool = class VolumeTool extends THREE.EventDispatcher {
var wp = volume.getWorldPosition().applyMatrix4(camera.matrixWorldInverse);
// var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
- var w = Math.abs((wp.z / 10));
+ var w = Math.abs((wp.z / 5));
volume.scale.set(w, w, w);
}
};
diff --git a/src/viewer/EDLRenderer.js b/src/viewer/EDLRenderer.js
index c8828397..e07926f6 100644
--- a/src/viewer/EDLRenderer.js
+++ b/src/viewer/EDLRenderer.js
@@ -61,12 +61,12 @@ class EDLRenderer {
viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
this.resize();
-
+
let camera = viewer.scene.getActiveCamera();
let lights = [];
viewer.scene.scene.traverse(node => {
- if(node instanceof THREE.PointLight){
+ if(node instanceof THREE.SpotLight){
lights.push(node);
}
});
@@ -104,10 +104,21 @@ class EDLRenderer {
let queryShadows = Potree.startQuery('EDL - shadows', viewer.renderer.getContext());
- this.shadowMap.setLightPos(light.position);
+ this.shadowMap.setLight(light);
- for(let octree of viewer.scene.pointclouds){
- this.shadowMap.renderOctree(octree, octree.visibleNodes);
+ let originalAttributes = new Map();
+ for(let pointcloud of viewer.scene.pointclouds){
+ originalAttributes.set(pointcloud, pointcloud.material.pointColorType);
+ pointcloud.material.disableEvents();
+ pointcloud.material.pointColorType = Potree.PointColorType.DEPTH;
+ }
+
+ this.shadowMap.render(viewer.scene.scenePointCloud, camera);
+
+ for(let pointcloud of viewer.scene.pointclouds){
+ let originalAttribute = originalAttributes.get(pointcloud);
+ pointcloud.material.pointColorType = originalAttribute;
+ pointcloud.material.enableEvents();
}
viewer.shadowTestCam.updateMatrixWorld();
@@ -119,7 +130,6 @@ class EDLRenderer {
let queryColors = Potree.startQuery('EDL - colorpass', viewer.renderer.getContext());
- viewer.transformationTool.update();
viewer.renderer.render(viewer.scene.scene, camera);
viewer.renderer.clearTarget( this.rtColor, true, true, true );
@@ -151,17 +161,14 @@ class EDLRenderer {
}else{
viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtColor, {});
}
-
+
viewer.renderer.render(viewer.scene.scene, camera, this.rtColor);
viewer.renderer.setRenderTarget(this.rtColor);
viewer.dispatchEvent({type: "render.pass.scene", viewer: viewer, renderTarget: this.rtColor});
-
- //viewer.dispatchEvent({type: "render.pass.scene",viewer: viewer});
Potree.endQuery(queryColors, viewer.renderer.getContext());
-
{ // EDL OCCLUSION PASS
let queryEDL = Potree.startQuery('EDL - resolve', viewer.renderer.getContext());
@@ -181,6 +188,8 @@ class EDLRenderer {
viewer.renderer.clearDepth();
+ viewer.transformationTool.update();
+
viewer.dispatchEvent({type: "render.pass.perspective_overlay",viewer: viewer});
viewer.renderer.render(viewer.controls.sceneControls, camera);
diff --git a/src/viewer/HQSplatRenderer.js b/src/viewer/HQSplatRenderer.js
new file mode 100644
index 00000000..2d9933aa
--- /dev/null
+++ b/src/viewer/HQSplatRenderer.js
@@ -0,0 +1,210 @@
+
+
+class HQSplatRenderer {
+ constructor (viewer) {
+ this.viewer = viewer;
+
+ this.depthMaterial = null;
+ this.attributeMaterial = null;
+ this.normalizationMaterial = null;
+
+ this.rtDepth = null;
+ this.rtAttribute = null;
+ this.gl = viewer.renderer.context;
+ }
+
+ init(){
+ if (this.depthMaterial != null) {
+ return;
+ }
+
+ this.depthMaterial = new Potree.PointCloudMaterial();
+ this.attributeMaterial = new Potree.PointCloudMaterial();
+
+ this.depthMaterial.setDefine("depth_pass", "#define hq_depth_pass");
+ this.depthMaterial.setDefine("use_edl", "#define use_edl");
+
+ this.normalizationMaterial = new Potree.NormalizationMaterial();
+ this.normalizationMaterial.depthTest = true;
+ this.normalizationMaterial.depthWrite = true;
+ this.normalizationMaterial.transparent = true;
+
+ this.normalizationEDLMaterial = new Potree.NormalizationEDLMaterial();
+ this.normalizationEDLMaterial.depthTest = true;
+ this.normalizationEDLMaterial.depthWrite = true;
+ this.normalizationEDLMaterial.transparent = true;
+
+ this.rtDepth = new THREE.WebGLRenderTarget(1024, 1024, {
+ minFilter: THREE.NearestFilter,
+ magFilter: THREE.NearestFilter,
+ format: THREE.RGBAFormat,
+ type: THREE.FloatType,
+ depthTexture: new THREE.DepthTexture(undefined, undefined, THREE.UnsignedIntType)
+ });
+
+ this.rtAttribute = new THREE.WebGLRenderTarget(1024, 1024, {
+ minFilter: THREE.NearestFilter,
+ magFilter: THREE.NearestFilter,
+ format: THREE.RGBAFormat,
+ type: THREE.FloatType,
+ depthTexture: this.rtDepth.depthTexture,
+ //depthTexture: new THREE.DepthTexture(undefined, undefined, THREE.UnsignedIntType)
+ });
+
+ //{
+ // let geometry = new THREE.PlaneBufferGeometry( 1, 1, 32, 32);
+ // let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.rtDepth.texture} );
+ // let plane = new THREE.Mesh( geometry, material );
+ // plane.scale.set(0.3, 0.3, 1.0);
+ // plane.position.set(plane.scale.x / 2, plane.scale.y / 2, 0);
+ // this.viewer.overlay.add(plane);
+ //}
+ };
+
+ resize () {
+ const viewer = this.viewer;
+
+ let pixelRatio = viewer.renderer.getPixelRatio();
+ let width = viewer.renderer.getSize().width;
+ let height = viewer.renderer.getSize().height;
+ this.rtDepth.setSize(width * pixelRatio , height * pixelRatio);
+ this.rtAttribute.setSize(width * pixelRatio , height * pixelRatio);
+ }
+
+ render () {
+ this.init();
+ const viewer = this.viewer;
+
+ viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
+
+ this.resize();
+
+ let camera = viewer.scene.getActiveCamera();
+
+ viewer.renderer.render(viewer.scene.scene, camera);
+
+ viewer.renderer.clearTarget( this.rtDepth, true, true, true );
+ viewer.renderer.clearTarget( this.rtAttribute, true, true, true );
+
+ let width = viewer.renderer.getSize().width;
+ let height = viewer.renderer.getSize().height;
+
+ let queryHQSplats = Potree.startQuery('HQSplats', viewer.renderer.getContext());
+
+ { // DEPTH PASS
+ for (let pointcloud of viewer.scene.pointclouds) {
+ let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize().x;
+
+ this.depthMaterial.pointSizeType = pointcloud.material.pointSizeType;
+ this.depthMaterial.visibleNodesTexture = pointcloud.material.visibleNodesTexture;
+ this.depthMaterial.weighted = false;
+ this.depthMaterial.screenWidth = width;
+ this.depthMaterial.shape = Potree.PointShape.CIRCLE;
+ this.depthMaterial.screenHeight = height;
+ this.depthMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture;
+ this.depthMaterial.uniforms.octreeSize.value = octreeSize;
+ this.depthMaterial.spacing = pointcloud.pcoGeometry.spacing * Math.max(pointcloud.scale.x, pointcloud.scale.y, pointcloud.scale.z);
+ }
+
+ viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtDepth, {
+ material: this.depthMaterial
+ });
+ }
+
+ { // ATTRIBUTE PASS
+
+ for (let pointcloud of viewer.scene.pointclouds) {
+ let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize().x;
+
+ this.attributeMaterial.pointSizeType = pointcloud.material.pointSizeType;
+ this.attributeMaterial.pointColorType = pointcloud.material.pointColorType;
+ this.attributeMaterial.visibleNodesTexture = pointcloud.material.visibleNodesTexture;
+ this.attributeMaterial.weighted = true;
+ this.attributeMaterial.screenWidth = width;
+ this.attributeMaterial.screenHeight = height;
+ this.attributeMaterial.shape = Potree.PointShape.CIRCLE;
+ this.attributeMaterial.uniforms.visibleNodes.value = pointcloud.material.visibleNodesTexture;
+ this.attributeMaterial.uniforms.octreeSize.value = octreeSize;
+ this.attributeMaterial.spacing = pointcloud.pcoGeometry.spacing * Math.max(pointcloud.scale.x, pointcloud.scale.y, pointcloud.scale.z);
+
+ this.attributeMaterial.clipTask = pointcloud.material.clipTask;
+ this.attributeMaterial.clipMethod = pointcloud.material.clipMethod;
+ this.attributeMaterial.setClipBoxes(pointcloud.material.clipBoxes);
+ }
+
+ let gl = this.gl;
+
+ viewer.renderer.setRenderTarget(null);
+ viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtAttribute, {
+ material: this.attributeMaterial,
+ blendFunc: [gl.SRC_ALPHA, gl.ONE],
+ //depthTest: false,
+ depthWrite: false
+ });
+ }
+
+ viewer.renderer.setRenderTarget(null);
+ if(viewer.background === "skybox"){
+ viewer.renderer.setClearColor(0x000000, 0);
+ viewer.renderer.clear();
+ viewer.skybox.camera.rotation.copy(viewer.scene.cameraP.rotation);
+ viewer.skybox.camera.fov = viewer.scene.cameraP.fov;
+ viewer.skybox.camera.aspect = viewer.scene.cameraP.aspect;
+ viewer.skybox.camera.updateProjectionMatrix();
+ viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera);
+ } else if (viewer.background === 'gradient') {
+ viewer.renderer.setClearColor(0x000000, 0);
+ viewer.renderer.clear();
+ viewer.renderer.render(viewer.scene.sceneBG, viewer.scene.cameraBG);
+ } else if (viewer.background === 'black') {
+ viewer.renderer.setClearColor(0x000000, 1);
+ viewer.renderer.clear();
+ } else if (viewer.background === 'white') {
+ viewer.renderer.setClearColor(0xFFFFFF, 1);
+ viewer.renderer.clear();
+ } else {
+ viewer.renderer.setClearColor(0xFF0000, 0);
+ viewer.renderer.clear();
+ }
+
+ { // NORMALIZATION PASS
+
+ let normalizationMaterial = this.useEDL ? this.normalizationEDLMaterial : this.normalizationMaterial;
+
+ if(this.useEDL){
+ normalizationMaterial.uniforms.edlStrength.value = viewer.edlStrength;
+ normalizationMaterial.uniforms.radius.value = viewer.edlRadius;
+ normalizationMaterial.uniforms.screenWidth.value = width;
+ normalizationMaterial.uniforms.screenHeight.value = height;
+ normalizationMaterial.uniforms.uEDLMap.value = this.rtDepth.texture;
+ }
+
+ normalizationMaterial.uniforms.uWeightMap.value = this.rtAttribute.texture;
+ normalizationMaterial.uniforms.uDepthMap.value = this.rtAttribute.depthTexture;
+
+ Potree.utils.screenPass.render(viewer.renderer, normalizationMaterial);
+ }
+
+ Potree.endQuery(queryHQSplats, viewer.renderer.getContext());
+
+ viewer.renderer.clearDepth();
+
+ viewer.transformationTool.update();
+
+ viewer.dispatchEvent({type: "render.pass.perspective_overlay",viewer: viewer});
+
+ viewer.renderer.render(viewer.controls.sceneControls, camera);
+ viewer.renderer.render(viewer.clippingTool.sceneVolume, camera);
+ viewer.renderer.render(viewer.transformationTool.scene, camera);
+
+ viewer.renderer.setViewport(width - viewer.navigationCube.width,
+ height - viewer.navigationCube.width,
+ viewer.navigationCube.width, viewer.navigationCube.width);
+ viewer.renderer.render(viewer.navigationCube, viewer.navigationCube.camera);
+ viewer.renderer.setViewport(0, 0, width, height);
+
+ viewer.dispatchEvent({type: "render.pass.end",viewer: viewer});
+
+ }
+};
+
diff --git a/src/viewer/PotreeRenderer.js b/src/viewer/PotreeRenderer.js
index 412d6666..d9161d0b 100644
--- a/src/viewer/PotreeRenderer.js
+++ b/src/viewer/PotreeRenderer.js
@@ -10,27 +10,27 @@ class PotreeRenderer {
viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
- {// resize
- let width = viewer.scaleFactor * viewer.renderArea.clientWidth;
- let height = viewer.scaleFactor * viewer.renderArea.clientHeight;
- let aspect = width / height;
+ //{// resize
+ // let width = viewer.scaleFactor * viewer.renderArea.clientWidth;
+ // let height = viewer.scaleFactor * viewer.renderArea.clientHeight;
+ // let aspect = width / height;
- viewer.scene.cameraP.aspect = aspect;
- viewer.scene.cameraP.updateProjectionMatrix();
+ // viewer.scene.cameraP.aspect = aspect;
+ // viewer.scene.cameraP.updateProjectionMatrix();
- let frustumScale = viewer.moveSpeed * 2.0;
- viewer.scene.cameraO.left = -frustumScale;
- viewer.scene.cameraO.right = frustumScale;
- viewer.scene.cameraO.top = frustumScale * 1/aspect;
- viewer.scene.cameraO.bottom = -frustumScale * 1/aspect;
- viewer.scene.cameraO.updateProjectionMatrix();
+ // let frustumScale = viewer.moveSpeed * 2.0;
+ // viewer.scene.cameraO.left = -frustumScale;
+ // viewer.scene.cameraO.right = frustumScale;
+ // viewer.scene.cameraO.top = frustumScale * 1/aspect;
+ // viewer.scene.cameraO.bottom = -frustumScale * 1/aspect;
+ // viewer.scene.cameraO.updateProjectionMatrix();
- viewer.scene.cameraScreenSpace.top = 1/aspect;
- viewer.scene.cameraScreenSpace.bottom = -1/aspect;
- viewer.scene.cameraScreenSpace.updateProjectionMatrix();
-
- viewer.renderer.setSize(width, height);
- }
+ // viewer.scene.cameraScreenSpace.top = 1/aspect;
+ // viewer.scene.cameraScreenSpace.bottom = -1/aspect;
+ // viewer.scene.cameraScreenSpace.updateProjectionMatrix();
+ //
+ // viewer.renderer.setSize(width, height);
+ //}
// render skybox
if(viewer.background === "skybox"){
diff --git a/src/viewer/PropertiesPanel.js b/src/viewer/PropertiesPanel.js
index 07134716..ada23f86 100644
--- a/src/viewer/PropertiesPanel.js
+++ b/src/viewer/PropertiesPanel.js
@@ -76,14 +76,19 @@ class DistancePanel extends MeasurePanel{
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeMeasurement(measurement);
+ });
+
this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
@@ -139,14 +144,19 @@ class PointPanel extends MeasurePanel{
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeMeasurement(measurement);
+ });
+
this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
@@ -179,14 +189,19 @@ class AreaPanel extends MeasurePanel{
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeMeasurement(measurement);
+ });
+
this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
@@ -228,14 +243,19 @@ class AnglePanel extends MeasurePanel{
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeMeasurement(measurement);
+ });
+
this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
@@ -277,14 +297,19 @@ class HeightPanel extends MeasurePanel{
Height:
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeMeasurement(measurement);
+ });
+
this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
@@ -353,28 +378,51 @@ class VolumePanel extends MeasurePanel{
Volume:
+
+
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeVolume(measurement);
+ });
+
+ this.elContent.find("#volume_reset_orientation").click(() => {
+ measurement.rotation.set(0, 0, 0);
+ });
+
this.elCheckClip = this.elContent.find('#volume_clip');
this.elCheckClip.click(event => {
this.measurement.clip = event.target.checked;
});
+ this.elCheckShow = this.elContent.find('#volume_show');
+ this.elCheckShow.click(event => {
+ this.measurement.visible = event.target.checked;
+ });
+
this.propertiesPanel.addVolatileListener(measurement, "position_changed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "orientation_changed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "scale_changed", this._update);
@@ -423,6 +471,7 @@ class VolumePanel extends MeasurePanel{
}
this.elCheckClip.prop("checked", this.measurement.clip);
+ this.elCheckShow.prop("checked", this.measurement.visible);
}
}
@@ -449,14 +498,19 @@ class ProfilePanel extends MeasurePanel{
-
+
+
`);
+ this.elRemove = this.elContent.find("img[name=remove]");
+ this.elRemove.click( () => {
+ viewer.scene.removeProfile(measurement);
+ });
+
{ // download
this.elDownloadButton = this.elContent.find(`#download_profile`);
@@ -528,6 +582,82 @@ class ProfilePanel extends MeasurePanel{
}
}
+class CameraPanel{
+ constructor(viewer, propertiesPanel){
+ this.viewer = viewer;
+ this.propertiesPanel = propertiesPanel;
+
+ this._update = () => { this.update(); };
+
+ let copyIconPath = Potree.resourcePath + '/icons/copy.svg';
+ this.elContent = $(`
+
+
+
+ | position |
+ |
+
+
+ |
+ |
+ |
+
+
+ |
+
+
+ | target |
+ |
+
+
+ |
+ |
+ |
+
+
+ |
+
+
+
+ `);
+
+ this.elCopyPosition = this.elContent.find("img[name=copyPosition]");
+ this.elCopyPosition.click( () => {
+ let pos = this.viewer.scene.getActiveCamera().position.toArray();
+ let msg = pos.map(c => c.toFixed(3)).join(", ");
+ Potree.utils.clipboardCopy(msg);
+ });
+
+ this.elCopyTarget = this.elContent.find("img[name=copyTarget]");
+ this.elCopyTarget.click( () => {
+ let pos = this.viewer.scene.view.getPivot().toArray();
+ let msg = pos.map(c => c.toFixed(3)).join(", ");
+ Potree.utils.clipboardCopy(msg);
+ });
+
+ this.propertiesPanel.addVolatileListener(viewer, "camera_changed", this._update);
+
+ this.update();
+ }
+
+ update(){
+ console.log("updating camera panel");
+
+ let camera = this.viewer.scene.getActiveCamera();
+ let view = this.viewer.scene.view;
+
+ let pos = camera.position.toArray().map(c => Potree.utils.addCommas(c.toFixed(3)));
+ this.elContent.find("#camera_position_x").html(pos[0]);
+ this.elContent.find("#camera_position_y").html(pos[1]);
+ this.elContent.find("#camera_position_z").html(pos[2]);
+
+ let target = view.getPivot().toArray().map(c => Potree.utils.addCommas(c.toFixed(3)));
+ this.elContent.find("#camera_target_x").html(target[0]);
+ this.elContent.find("#camera_target_y").html(target[1]);
+ this.elContent.find("#camera_target_z").html(target[2]);
+ }
+}
+
Potree.PropertiesPanel = class PropertriesPanel{
@@ -547,6 +677,8 @@ Potree.PropertiesPanel = class PropertriesPanel{
if(this.object === object){
return;
}
+
+ this.object = object;
for(let task of this.cleanupTasks){
task();
@@ -558,11 +690,9 @@ Potree.PropertiesPanel = class PropertriesPanel{
this.setPointCloud(object);
}else if(object instanceof Potree.Measure || object instanceof Potree.Profile || object instanceof Potree.Volume){
this.setMeasurement(object);
- }else{
-
+ }else if(object instanceof THREE.Camera){
+ this.setCamera(object);
}
-
-
}
@@ -602,7 +732,7 @@ Potree.PropertiesPanel = class PropertriesPanel{
-
+