From bdb6f8e31603cab842b3b1636eaa119429b61558 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Fri, 19 Jan 2018 12:02:51 +0100 Subject: [PATCH 01/22] ... --- examples/heidentor.html | 5 +++- src/materials/shaders/pointcloud.vs | 39 ++++++++++++++++++++--------- src/utils/ScreenBoxSelectTool.js | 27 +++++++++++++++++++- src/utils/Volume.js | 3 ++- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/examples/heidentor.html b/examples/heidentor.html index ad09df58..79118f53 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -32,6 +32,7 @@ + @@ -64,7 +65,7 @@ viewer.setEDLEnabled(true); viewer.setFOV(60); - viewer.setPointBudget(10*1000*1000); + viewer.setPointBudget(1*1000*1000); viewer.setMinNodeSize(0); viewer.useEDL = false; viewer.loadSettingsFromURL(); @@ -91,6 +92,8 @@ 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(); //Potree.measureTimings = true; diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 07f02349..a1306aa6 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -498,14 +498,6 @@ bool pointInClipPolygon(vec3 point, int polyIdx) { } #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; @@ -586,6 +578,24 @@ float getPointSize(){ return pointSize; } +#define CLIP_DISABLED 0 +#define CLIP_HIGHLIGHT 1 +#define CLIP_INSIDE 2 +#define CLIP_OUTSIDE 3 + +void testInsideClipVolume(bool insideAny, bool insideAll) { + + if(clipMode == CLIP_INSIDE && !insideAll){ + gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0); + } + + //if(insideAny && 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; + //} +} + void doClipping(){ #if !defined color_type_composite @@ -600,14 +610,16 @@ void doClipping(){ #if defined(num_clipboxes) && num_clipboxes > 0 if(clipMode != 0) { bool insideAny = false; + bool insideAll = true; 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; + insideAll = insideAll && inside; } - testInsideClipVolume(insideAny); + testInsideClipVolume(insideAny, insideAll); } #endif @@ -615,11 +627,14 @@ void doClipping(){ if(clipMode != 0) { - bool polyInsideAny = false; + bool insideAny = false; + bool insideAll = false; for(int i = 0; i < num_clippolygons; i++) { - polyInsideAny = polyInsideAny || pointInClipPolygon(position, i); + bool inside = pointInClipPolygon(position, i);; + insideAny = insideAny || inside; + insideAll = insideAll // inside; } - testInsideClipVolume(polyInsideAny); + testInsideClipVolume(insideAny, insideAll); } #endif } diff --git a/src/utils/ScreenBoxSelectTool.js b/src/utils/ScreenBoxSelectTool.js index 87e384a7..0b9d8915 100644 --- a/src/utils/ScreenBoxSelectTool.js +++ b/src/utils/ScreenBoxSelectTool.js @@ -20,13 +20,34 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat let domElement = this.viewer.renderer.domElement; let volume = new Potree.Volume(); - volume.clip = true; + 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 +73,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); @@ -121,6 +144,8 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat volume.position.copy(centroid); } + + volume.clip = true; } }; diff --git a/src/utils/Volume.js b/src/utils/Volume.js index d0995047..e936a649 100644 --- a/src/utils/Volume.js +++ b/src/utils/Volume.js @@ -8,6 +8,7 @@ Potree.Volume = class extends THREE.Object3D { this.name = 'volume_' + this.constructor.counter; this._clip = args.clip || false; + this.showVolumeLabel = true; this._modifiable = args.modifiable || true; let boxGeometry = new THREE.BoxGeometry(1, 1, 1); @@ -131,7 +132,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; } }; From b62e7fc44f22fe5fe22dcaf4a25477868709827b Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Fri, 19 Jan 2018 15:11:49 +0100 Subject: [PATCH 02/22] clipping tools --- src/navigation/InputHandler.js | 20 +++++++++ src/utils/ScreenBoxSelectTool.js | 2 + src/utils/TransformationTool.js | 71 ++++++++++++++++++++++++-------- src/utils/Volume.js | 41 ++++++------------ src/viewer/PropertiesPanel.js | 21 +++++++++- src/viewer/Scene.js | 1 + src/viewer/View.js | 3 +- src/viewer/sidebar.js | 27 ++++++++++-- src/viewer/viewer.js | 16 +++++++ 9 files changed, 151 insertions(+), 51 deletions(-) diff --git a/src/navigation/InputHandler.js b/src/navigation/InputHandler.js index 6b082b63..ee2eb8ae 100644 --- a/src/navigation/InputHandler.js +++ b/src/navigation/InputHandler.js @@ -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/utils/ScreenBoxSelectTool.js b/src/utils/ScreenBoxSelectTool.js index 0b9d8915..4b8c131d 100644 --- a/src/utils/ScreenBoxSelectTool.js +++ b/src/utils/ScreenBoxSelectTool.js @@ -20,6 +20,7 @@ Potree.ScreenBoxSelectTool = class ScreenBoxSelectTool extends THREE.EventDispat let domElement = this.viewer.renderer.domElement; let volume = new Potree.Volume(); + volume.position.set(12345, 12345, 12345); volume.showVolumeLabel = false; volume.visible = false; volume.update(); @@ -118,6 +119,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); 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 e936a649..b78d3a64 100644 --- a/src/utils/Volume.js +++ b/src/utils/Volume.js @@ -8,6 +8,7 @@ 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; @@ -16,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)); @@ -119,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); } diff --git a/src/viewer/PropertiesPanel.js b/src/viewer/PropertiesPanel.js index 07134716..de34c201 100644 --- a/src/viewer/PropertiesPanel.js +++ b/src/viewer/PropertiesPanel.js @@ -353,15 +353,24 @@ class VolumePanel extends MeasurePanel{ Volume: + +
  • +
      -
    • :
    • -
    • :
    • - -
      -
      - Eye-Dome-Lighting -
      - +
    • :
    • +
    • :
    • + +
      Eye-Dome-Lighting
      +
    • :
    • :
    • -
      - -
      -
      - Background -
      - - - - - - - - -
      +
      Background
      -
      -
      - Other -
      +
    • + + + + + + +
    • + +
      Other
    • :
    • -
      - - -
    @@ -73,14 +54,12 @@
    -
    - Measurement -
    +
    Measurement
    +
  • -
    - Clipping -
    +
    Clipping
    +
  • @@ -92,10 +71,10 @@
  • -
    - Navigation -
    +
    Navigation
    + +
  • :
  • diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index a41d8995..647de338 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -531,8 +531,8 @@ initSidebar = (viewer) => { let header = $(this); let content = $(this).next(); - header.addClass('accordion-header ui-widget'); - content.addClass('accordion-content ui-widget'); + //header.addClass('accordion-header ui-widget'); + //content.addClass('accordion-content ui-widget'); content.hide(); From d5909f6c0e047b66a1084d9d19d8c2d769a8eb99 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Sat, 20 Jan 2018 13:47:07 +0100 Subject: [PATCH 04/22] update css --- src/viewer/potree.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/viewer/potree.css b/src/viewer/potree.css index 78f199b8..0181e91d 100644 --- a/src/viewer/potree.css +++ b/src/viewer/potree.css @@ -420,6 +420,7 @@ body{ margin: 2px 0 0 0; padding: 4px 10px 4px 30px; box-shadow: 0px 3px 3px #111; + text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; font-size: 1em; } From 37cbea8d82d7676cdb4508d81948ff64b91bd6e3 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Sat, 20 Jan 2018 18:09:35 +0100 Subject: [PATCH 05/22] go back to individual geometry attribute buffers using THREE.BufferGeometry --- examples/heidentor.html | 2 +- src/PotreeRenderer.js | 176 ++++++------ src/loader/BinaryLoader.js | 40 ++- src/loader/PointAttributes.js | 5 + src/materials/shaders/pointcloud.vs | 13 +- src/viewer/viewer.js | 29 +- src/workers/BinaryDecoderWorker.js | 412 ++++++++++++++-------------- 7 files changed, 354 insertions(+), 323 deletions(-) diff --git a/examples/heidentor.html b/examples/heidentor.html index 79118f53..b5265438 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -88,7 +88,7 @@ material.size = 1; material.pointSizeType = Potree.PointSizeType.ADAPTIVE; - viewer.switchCameraMode(Potree.CameraMode.ORTHOGRAPHIC); + //viewer.switchCameraMode(Potree.CameraMode.ORTHOGRAPHIC); viewer.scene.view.position.set(13.856734292740617, -9.125174923658731, 14.563928417406354); viewer.scene.view.lookAt(-3.5482630104475366, 2.728596783815762, 6.1406044783018725); diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index aeae629c..7a0d756a 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -374,16 +374,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 +450,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 +472,90 @@ 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.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 +584,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) { @@ -660,24 +666,28 @@ Potree.Renderer = class Renderer { const lWorldView = shader.uniformLocations["uShadowWorldView[0]"]; gl.uniformMatrix4fv(lWorldView, 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++; diff --git a/src/loader/BinaryLoader.js b/src/loader/BinaryLoader.js index 747b40a2..8dcf7dc1 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,38 @@ 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.INDEX) { + geometry.addAttribute('indices', new THREE.BufferAttribute(new Uint8Array(buffer), 4)); + } + } + + 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; diff --git a/src/loader/PointAttributes.js b/src/loader/PointAttributes.js index 4bb5b51c..643a8a58 100644 --- a/src/loader/PointAttributes.js +++ b/src/loader/PointAttributes.js @@ -15,6 +15,7 @@ Potree.PointAttributeNames.NORMAL = 10; Potree.PointAttributeNames.RETURN_NUMBER = 11; Potree.PointAttributeNames.NUMBER_OF_RETURNS = 12; Potree.PointAttributeNames.SOURCE_ID = 13; +Potree.PointAttributeNames.INDICES = 14; /** * Some types of possible point attribute data formats @@ -110,6 +111,10 @@ 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); + /** * Ordered list of PointAttributes used to identify how points are aligned in a buffer. * diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index a1306aa6..462cc185 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -12,7 +12,7 @@ attribute float classification; attribute float returnNumber; attribute float numberOfReturns; attribute float pointSourceID; -attribute vec4 index; +attribute vec4 indices; uniform mat4 modelMatrix; uniform mat4 modelViewMatrix; @@ -73,15 +73,10 @@ uniform float wSourceID; uniform vec3 uShadowColor; - uniform sampler2D visibleNodes; uniform sampler2D gradient; uniform sampler2D classificationLUT; - -#if defined(num_shadowmaps) && num_shadowmaps > 0 -uniform sampler2D uShadowMap[num_shadowmaps]; -uniform mat4 uShadowWorldView[num_shadowmaps]; -#endif +uniform sampler2D uShadow; #if defined(num_snapshots) && num_snapshots > 0 uniform sampler2D uSnapshot[num_snapshots]; @@ -525,7 +520,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; @@ -746,4 +741,6 @@ void main() { #endif + + } diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index e1b41535..8925cd09 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1081,27 +1081,19 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ if (!pointcloud.material._defaultIntensityRangeChanged) { let root = pointcloud.pcoGeometry.root; if (root != null && root.loaded) { - //let attributes = pointcloud.pcoGeometry.root.geometry.attributes; - let buffer = pointcloud.pcoGeometry.root.buffer; - let attIntensity = buffer.attributes.find(a => a.name === "intensity"); - if (attIntensity) { + let attributes = pointcloud.pcoGeometry.root.geometry.attributes; + if (attributes.intensity) { + let array = attributes.intensity.array; - let byteOffset = buffer.attributes - .slice(0, buffer.attributes.indexOf(attIntensity)) - .map(a => Math.ceil(a.bytes / 4) * 4) - .reduce( (a, i) => a + i, 0); - - let view = new DataView(buffer.data) - let intensities = []; - for(let i = 0; i < buffer.numElements; i++){ - let index = i * buffer.stride + byteOffset; - intensities.push(view.getFloat32(index, true)); + // chose max value from the 0.75 percentile + let ordered = []; + for (let j = 0; j < array.length; j++) { + ordered.push(array[j]); } - intensities.sort(); + ordered.sort(); + let capIndex = parseInt((ordered.length - 1) * 0.75); + let cap = ordered[capIndex]; - let capIndex = parseInt((intensities.length - 1) * 0.75); - let cap = intensities[capIndex]; - if (cap <= 1) { pointcloud.material.intensityRange = [0, 1]; } else if (cap <= 256) { @@ -1109,6 +1101,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ } else { pointcloud.material.intensityRange = [0, cap]; } + } // pointcloud._intensityMaxEvaluated = true; } diff --git a/src/workers/BinaryDecoderWorker.js b/src/workers/BinaryDecoderWorker.js index 15f347d3..82693311 100644 --- a/src/workers/BinaryDecoderWorker.js +++ b/src/workers/BinaryDecoderWorker.js @@ -51,237 +51,238 @@ onmessage = function (event) { let tightBoxMax = [ Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY ]; let mean = [0, 0, 0]; - 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 iStride = iAttributes.reduce( (a, att) => a + att.bytes, 0); - iStride = Math.ceil(iStride / 4) * 4; // round to nearest multiple of 4 - let iData = new ArrayBuffer(numPoints * iStride); - let iView = new DataView(iData); - + + let attributeBuffers = {}; let inOffset = 0; - let outOffset = 0; - for (let i = 0; i < pointAttributes.attributes.length; i++) { - let pointAttribute = pointAttributes.attributes[i]; - let iAttribute = Potree.toInterleavedBufferAttribute(pointAttribute); + for (let pointAttribute of pointAttributes.attributes) { - if(iAttribute){ - if (pointAttribute.name === Potree.PointAttribute.POSITION_CARTESIAN.name) { - - for (let j = 0; j < numPoints; j++) { - let x, y, z; + if (pointAttribute.name === Potree.PointAttribute.POSITION_CARTESIAN.name) { + let buff = new ArrayBuffer(numPoints * 4 * 3); + let positions = new Float32Array(buff); + + for (let j = 0; j < numPoints; j++) { + let x, y, z; - if (version.newerThan('1.3')) { - x = (cv.getUint32(inOffset + j * pointAttributes.byteSize + 0, true) * scale); - y = (cv.getUint32(inOffset + j * pointAttributes.byteSize + 4, true) * scale); - z = (cv.getUint32(inOffset + j * pointAttributes.byteSize + 8, true) * scale); - } else { - x = cv.getFloat32(j * pointAttributes.byteSize + 0, true) + nodeOffset[0]; - y = cv.getFloat32(j * pointAttributes.byteSize + 4, true) + nodeOffset[1]; - z = cv.getFloat32(j * pointAttributes.byteSize + 8, true) + nodeOffset[2]; - } - - let firstByte = j * iStride + outOffset; - iView.setFloat32(firstByte + 0, x, true); - iView.setFloat32(firstByte + 4, y, true); - iView.setFloat32(firstByte + 8, z, true); - - mean[0] += x / numPoints; - mean[1] += y / numPoints; - mean[2] += z / numPoints; - - tightBoxMin[0] = Math.min(tightBoxMin[0], x); - tightBoxMin[1] = Math.min(tightBoxMin[1], y); - tightBoxMin[2] = Math.min(tightBoxMin[2], z); - - tightBoxMax[0] = Math.max(tightBoxMax[0], x); - tightBoxMax[1] = Math.max(tightBoxMax[1], y); - tightBoxMax[2] = Math.max(tightBoxMax[2], z); - } - - } else if (pointAttribute.name === Potree.PointAttribute.COLOR_PACKED.name) { - - for (let j = 0; j < numPoints; j++) { - let r = cv.getUint8(inOffset + j * pointAttributes.byteSize + 0); - let g = cv.getUint8(inOffset + j * pointAttributes.byteSize + 1); - let b = cv.getUint8(inOffset + j * pointAttributes.byteSize + 2); - - let firstByte = j * iStride + outOffset; - iView.setUint8(firstByte + 0, r, true); - iView.setUint8(firstByte + 1, g, true); - iView.setUint8(firstByte + 2, b, true); + if (version.newerThan('1.3')) { + x = (cv.getUint32(inOffset + j * pointAttributes.byteSize + 0, true) * scale); + y = (cv.getUint32(inOffset + j * pointAttributes.byteSize + 4, true) * scale); + z = (cv.getUint32(inOffset + j * pointAttributes.byteSize + 8, true) * scale); + } else { + x = cv.getFloat32(j * pointAttributes.byteSize + 0, true) + nodeOffset[0]; + y = cv.getFloat32(j * pointAttributes.byteSize + 4, true) + nodeOffset[1]; + z = cv.getFloat32(j * pointAttributes.byteSize + 8, true) + nodeOffset[2]; } - } else if (pointAttribute.name === Potree.PointAttribute.INTENSITY.name) { + positions[3 * j + 0] = x; + positions[3 * j + 1] = y; + positions[3 * j + 2] = z; - for (let j = 0; j < numPoints; j++) { - let intensity = cv.getUint16(inOffset + j * pointAttributes.byteSize, true); - let firstByte = j * iStride + outOffset; - iView.setFloat32(firstByte + 0, intensity, true); - } + mean[0] += x / numPoints; + mean[1] += y / numPoints; + mean[2] += z / numPoints; - } else if (pointAttribute.name === Potree.PointAttribute.CLASSIFICATION.name) { - - for (let j = 0; j < numPoints; j++) { - let classification = cv.getUint8(inOffset + j * pointAttributes.byteSize); - let firstByte = j * iStride + outOffset; - iView.setFloat32(firstByte + 0, classification, true); - } - - } else if (pointAttribute.name === Potree.PointAttribute.NORMAL_SPHEREMAPPED.name) { - - for (let j = 0; j < numPoints; j++) { - let bx = cv.getUint8(inOffset + j * pointAttributes.byteSize + 0); - let by = cv.getUint8(inOffset + j * pointAttributes.byteSize + 1); - - let ex = bx / 255; - let ey = by / 255; - - let nx = ex * 2 - 1; - let ny = ey * 2 - 1; - let nz = 1; - let nw = -1; - - let l = (nx * (-nx)) + (ny * (-ny)) + (nz * (-nw)); - nz = l; - nx = nx * Math.sqrt(l); - ny = ny * Math.sqrt(l); - - nx = nx * 2; - ny = ny * 2; - nz = nz * 2 - 1; - - let firstByte = j * iStride + outOffset; - iView.setFloat32(firstByte + 0, nx, true); - iView.setFloat32(firstByte + 4, ny, true); - iView.setFloat32(firstByte + 8, nz, true); - } - - } else if (pointAttribute.name === Potree.PointAttribute.NORMAL_OCT16.name) { - - for (let j = 0; j < numPoints; j++) { - let bx = cv.getUint8(inOffset + j * pointAttributes.byteSize + 0); - let by = cv.getUint8(inOffset + j * pointAttributes.byteSize + 1); - - let u = (bx / 255) * 2 - 1; - let v = (by / 255) * 2 - 1; - - let z = 1 - Math.abs(u) - Math.abs(v); - - let x = 0; - let y = 0; - if (z >= 0) { - x = u; - y = v; - } else { - x = -(v / Math.sign(v) - 1) / Math.sign(u); - y = -(u / Math.sign(u) - 1) / Math.sign(v); - } - - let length = Math.sqrt(x * x + y * y + z * z); - x = x / length; - y = y / length; - z = z / length; - - let firstByte = j * iStride + outOffset; - iView.setFloat32(firstByte + 0, x, true); - iView.setFloat32(firstByte + 4, y, true); - iView.setFloat32(firstByte + 8, z, true); - } - - } else if (pointAttribute.name === Potree.PointAttribute.NORMAL.name) { - - for (let j = 0; j < numPoints; j++) { - let x = cv.getFloat32(inOffset + j * pointAttributes.byteSize + 0, true); - let y = cv.getFloat32(inOffset + j * pointAttributes.byteSize + 4, true); - let z = cv.getFloat32(inOffset + j * pointAttributes.byteSize + 8, true); - - let firstByte = j * iStride + outOffset; - iView.setFloat32(firstByte + 0, x, true); - iView.setFloat32(firstByte + 4, y, true); - iView.setFloat32(firstByte + 8, z, true); - } + tightBoxMin[0] = Math.min(tightBoxMin[0], x); + tightBoxMin[1] = Math.min(tightBoxMin[1], y); + tightBoxMin[2] = Math.min(tightBoxMin[2], z); + tightBoxMax[0] = Math.max(tightBoxMax[0], x); + tightBoxMax[1] = Math.max(tightBoxMax[1], y); + tightBoxMax[2] = Math.max(tightBoxMax[2], z); } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; + } else if (pointAttribute.name === Potree.PointAttribute.COLOR_PACKED.name) { + let buff = new ArrayBuffer(numPoints * 4); + let colors = new Uint8Array(buff); + + for (let j = 0; j < numPoints; j++) { + colors[4 * j + 0] = cv.getUint8(inOffset + j * pointAttributes.byteSize + 0); + colors[4 * j + 1] = cv.getUint8(inOffset + j * pointAttributes.byteSize + 1); + colors[4 * j + 2] = cv.getUint8(inOffset + j * pointAttributes.byteSize + 2); + } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; + } else if (pointAttribute.name === Potree.PointAttribute.INTENSITY.name) { + let buff = new ArrayBuffer(numPoints * 4); + let intensities = new Float32Array(buff); + + for (let j = 0; j < numPoints; j++) { + let intensity = cv.getUint16(inOffset + j * pointAttributes.byteSize, true); + intensities[j] = intensity; + } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; + } else if (pointAttribute.name === Potree.PointAttribute.CLASSIFICATION.name) { + let buff = new ArrayBuffer(numPoints); + let classifications = new Uint8Array(buff); + + for (let j = 0; j < numPoints; j++) { + let classification = cv.getUint8(inOffset + j * pointAttributes.byteSize); + classifications[j] = classification; + } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; + } else if (pointAttribute.name === Potree.PointAttribute.NORMAL_SPHEREMAPPED.name) { + let buff = new ArrayBuffer(numPoints * 4 * 3); + let normals = new Float32Array(buff); + + for (let j = 0; j < numPoints; j++) { + let bx = cv.getUint8(inOffset + j * pointAttributes.byteSize + 0); + let by = cv.getUint8(inOffset + j * pointAttributes.byteSize + 1); + + let ex = bx / 255; + let ey = by / 255; + + let nx = ex * 2 - 1; + let ny = ey * 2 - 1; + let nz = 1; + let nw = -1; + + let l = (nx * (-nx)) + (ny * (-ny)) + (nz * (-nw)); + nz = l; + nx = nx * Math.sqrt(l); + ny = ny * Math.sqrt(l); + + nx = nx * 2; + ny = ny * 2; + nz = nz * 2 - 1; + + normals[3 * j + 0] = nx; + normals[3 * j + 1] = ny; + normals[3 * j + 2] = nz; + } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; + } else if (pointAttribute.name === Potree.PointAttribute.NORMAL_OCT16.name) { + let buff = new ArrayBuffer(numPoints * 4 * 3); + let normals = new Float32Array(buff); + + for (let j = 0; j < numPoints; j++) { + let bx = cv.getUint8(inOffset + j * pointAttributes.byteSize + 0); + let by = cv.getUint8(inOffset + j * pointAttributes.byteSize + 1); + + let u = (bx / 255) * 2 - 1; + let v = (by / 255) * 2 - 1; + + let z = 1 - Math.abs(u) - Math.abs(v); + + let x = 0; + let y = 0; + if (z >= 0) { + x = u; + y = v; + } else { + x = -(v / Math.sign(v) - 1) / Math.sign(u); + y = -(u / Math.sign(u) - 1) / Math.sign(v); + } + + let length = Math.sqrt(x * x + y * y + z * z); + x = x / length; + y = y / length; + z = z / length; + + normals[3 * j + 0] = x; + normals[3 * j + 1] = y; + normals[3 * j + 2] = z; + } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; + } else if (pointAttribute.name === Potree.PointAttribute.NORMAL.name) { + let buff = new ArrayBuffer(numPoints * 4 * 3); + let normals = new Float32Array(buff); + + for (let j = 0; j < numPoints; j++) { + let x = cv.getFloat32(inOffset + j * pointAttributes.byteSize + 0, true); + let y = cv.getFloat32(inOffset + j * pointAttributes.byteSize + 4, true); + let z = cv.getFloat32(inOffset + j * pointAttributes.byteSize + 8, true); + + normals[3 * j + 0] = x; + normals[3 * j + 1] = y; + normals[3 * j + 2] = z; + } + + attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute }; } inOffset += pointAttribute.byteSize; - outOffset += Math.ceil(iAttribute.bytes / 4) * 4; } - let estimatedSpacing; - if(hasChildren || true){ - estimatedSpacing = spacing; - }else{ - performance.mark("spacing-start"); + //let estimatedSpacing; + //if(hasChildren || true){ + // estimatedSpacing = spacing; + //}else{ + // performance.mark("spacing-start"); - let knnCount = 5; - let n = 5; - let choice = []; - for(let i = 0; i < Math.min(n, numPoints); i++){ - let index = parseInt(Math.random() * numPoints); + // let knnCount = 5; + // let n = 5; + // let choice = []; + // for(let i = 0; i < Math.min(n, numPoints); i++){ + // let index = parseInt(Math.random() * numPoints); - let x = iView.getFloat32(index * iStride + 0, true); - let y = iView.getFloat32(index * iStride + 4, true); - let z = iView.getFloat32(index * iStride + 8, true); + // let x = iView.getFloat32(index * iStride + 0, true); + // let y = iView.getFloat32(index * iStride + 4, true); + // let z = iView.getFloat32(index * iStride + 8, true); - choice.push({ - knn: [], - position: [x, y, z] - }); - } + // choice.push({ + // knn: [], + // position: [x, y, z] + // }); + // } - let squaredDistanceBetween = (v1, v2) => { - let dx = v1[0] - v2[0]; - let dy = v1[1] - v2[1]; - let dz = v1[2] - v2[2]; + // let squaredDistanceBetween = (v1, v2) => { + // let dx = v1[0] - v2[0]; + // let dy = v1[1] - v2[1]; + // let dz = v1[2] - v2[2]; - return dx * dx + dy * dy + dz * dz; - }; + // return dx * dx + dy * dy + dz * dz; + // }; - for(let i = 0; i < numPoints; i++){ - - let pos = [ - iView.getFloat32(i * iStride + 0, true), - iView.getFloat32(i * iStride + 4, true), - iView.getFloat32(i * iStride + 8, true), - ]; + // for(let i = 0; i < numPoints; i++){ + // + // let pos = [ + // iView.getFloat32(i * iStride + 0, true), + // iView.getFloat32(i * iStride + 4, true), + // iView.getFloat32(i * iStride + 8, true), + // ]; - for(let point of choice){ + // for(let point of choice){ - let distance = squaredDistanceBetween(pos, point.position); + // let distance = squaredDistanceBetween(pos, point.position); - if(distance > 0){ - point.knn.push(distance); - point.knn.sort(); - point.knn = point.knn.slice(0, knnCount); - } - } - } + // if(distance > 0){ + // point.knn.push(distance); + // point.knn.sort(); + // point.knn = point.knn.slice(0, knnCount); + // } + // } + // } - { - let knns = []; - for(let knn of choice.map(point => point.knn)){ - knns.push(...knn); - } - knns = knns.map(value => Math.sqrt(value)); + // { + // let knns = []; + // for(let knn of choice.map(point => point.knn)){ + // knns.push(...knn); + // } + // knns = knns.map(value => Math.sqrt(value)); - knns.sort(); - let medianPos = Math.floor(knns.length / 2); - let medianSpacing = knns[medianPos]; + // knns.sort(); + // let medianPos = Math.floor(knns.length / 2); + // let medianSpacing = knns[medianPos]; - estimatedSpacing = Math.min(medianSpacing, spacing); - } + // estimatedSpacing = Math.min(medianSpacing, spacing); + // } - performance.mark("spacing-end"); - } + // performance.mark("spacing-end"); + //} { // add indices + let buff = new ArrayBuffer(numPoints * 4); + let indices = new Uint32Array(buff); + for (let i = 0; i < numPoints; i++) { - let firstByte = i * iStride + outOffset; - iView.setUint32(firstByte, i, true); + indices[i] = i; } + + attributeBuffers[Potree.PointAttribute.INDICES.name] = { buffer: buff, attribute: Potree.PointAttribute.INDICES }; } performance.mark("binary-decoder-end"); @@ -299,13 +300,18 @@ onmessage = function (event) { performance.clearMeasures(); let message = { + buffer: buffer, mean: mean, - data: iData, + attributeBuffers: attributeBuffers, tightBoundingBox: { min: tightBoxMin, max: tightBoxMax }, - estimatedSpacing: estimatedSpacing, + //estimatedSpacing: estimatedSpacing, }; - let transferables = [message.data]; + let transferables = []; + for (let property in message.attributeBuffers) { + transferables.push(message.attributeBuffers[property].buffer); + } + transferables.push(buffer); postMessage(message, transferables); }; From e3574bf251591d2b99a7b8403f7bdf46f36d322c Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Sun, 21 Jan 2018 17:38:42 +0100 Subject: [PATCH 06/22] ... --- examples/ca13.html | 15 +- examples/heidentor.html | 23 +++ .../heidentor_animated_light_and_shadows.html | 2 + src/PotreeRenderer.js | 116 +++++++++++++- src/loader/LasLazLoader.js | 57 +++---- src/materials/shaders/pointcloud.vs | 6 +- src/utils/PointCloudSM.js | 12 +- src/workers/LASDecoderWorker.js | 148 +++++++++++++----- 8 files changed, 303 insertions(+), 76 deletions(-) diff --git a/examples/ca13.html b/examples/ca13.html index ad39eec0..f23d850b 100644 --- a/examples/ca13.html +++ b/examples/ca13.html @@ -82,13 +82,22 @@ 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(); }); diff --git a/examples/heidentor.html b/examples/heidentor.html index b5265438..38691c20 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -97,6 +97,29 @@ //viewer.fitToScreen(); //Potree.measureTimings = true; + + + + + viewer.addEventListener("update", () => { + + let sceneNode = viewer.scene.pointclouds[0].root.sceneNode; + + if(!sceneNode){ + return; + } + + let geometry = sceneNode.geometry; + let aColor = geometry.attributes.color; + + aColor.array = aColor.array.map(v => Math.random() * 255); + aColor.needsUpdate = true; + + + + }); + + }); 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/src/PotreeRenderer.js b/src/PotreeRenderer.js index 7a0d756a..8daee2f3 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -135,7 +135,7 @@ Potree.attributeLocations = { "returnNumber": 4, "numberOfReturns": 5, "pointSourceID": 6, - "index": 7, + "indices": 7, "normal": 8, }; @@ -475,6 +475,7 @@ Potree.Renderer = class Renderer { 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; } @@ -601,6 +602,119 @@ Potree.Renderer = class Renderer { let i = 0; for (let node of nodes) { + //if(![ + // "r42006420226", + // "r42006420602", + // "r42006420462", + // "r42006420265", + // "r42006422041", + // "r42006420426", + // "r42006422064", + // "r42006420264", + // "r42006420664", + // "r42006424200", + // "r42006420626", + // "r42006420642", + // "r42006420621", + // "r42006420604", + // "r42006422400", + // "r42006420225", + // "r42006420062", + // "r42006422440", + // "r42006420267", + // "r42006420240", + // "r42006422406", + // "r42006420644", + // "r42006422046", + // "r42006420662", + // "r42006420660", + // "r42006420266", + // "r42006420624", + // "r42006420620", + // "r42006420243", + // "r42006424026", + // "r42006420640", + // "r42006420227", + // "r42006420242", + // "r42006420466", + // "r42006420422", + // "r42006422040", + // "r42006420066", + // "r42006420666", + // "r42006420244", + // "r42006420261", + // "r42006420206", + // "r42006420260", + // "r42006420646", + // "r42006424204", + // "r42006420600", + // "r42006422402", + // "r42006422044", + // "r42006420247", + // "r42006420606", + // "r42006420224", + // "r42006424202", + // "r42006424220", + // "r42006420603", + // "r42006422404", + // "r42006420263", + // "r42006420246", + // "r42006420262", + // "r42006420022", + // "r42006420026", + // "r42006424022", + // "r42006422420", + // "r42006420204", + // "r42006420622", + // "r42006420200", + // "r420064206442", + // "r420064206604", + // "r420064206044", + // "r420064204266", + // "r420064206420", + // "r420064206426", + // "r420064206422", + // "r420064206402", + // "r420064206400", + // "r420064206046", + // "r420064204620", + // "r420064204622", + // "r420064206424", + // "r420064206425", + // "r420064206406", + // "r420064206404", + // "r420064204624", + // "r420064206407", + // "r420064204626", + // "r420064206405", + // "r420064204627", + // "r420064204264", + // "r420064206440", + // "r420064206443", + // "r420064206064", + // "r420064204662", + // "r420064206441", + // "r420064206606", + // "r420064206446", + // "r420064206600", + // "r420064204663", + // "r420064206444", + // "r420064204664", + // "r420064206447", + // "r420064206660", + // "r420064204262", + // "r420064204666", + // "r420064206445", + // "r420064204665", + // "r420064206040", + // "r420064204667", + // "r420064206066", + // "r420064204660", + // ] + // .includes(node.name)){ + // continue; + //} + let world = node.sceneNode.matrixWorld; worldView.multiplyMatrices(view, world); //this.multiplyViewWithScaleTrans(view, world, worldView); diff --git a/src/loader/LasLazLoader.js b/src/loader/LasLazLoader.js index 87e9a414..73a70333 100644 --- a/src/loader/LasLazLoader.js +++ b/src/loader/LasLazLoader.js @@ -153,42 +153,45 @@ 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)); 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/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 462cc185..ca683329 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -76,7 +76,11 @@ uniform vec3 uShadowColor; uniform sampler2D visibleNodes; uniform sampler2D gradient; uniform sampler2D classificationLUT; -uniform sampler2D uShadow; + +#if defined(num_shadowmaps) && num_shadowmaps > 0 +uniform sampler2D uShadowMap[num_shadowmaps]; +uniform mat4 uShadowWorldView[num_shadowmaps]; +#endif #if defined(num_snapshots) && num_snapshots > 0 uniform sampler2D uSnapshot[num_snapshots]; diff --git a/src/utils/PointCloudSM.js b/src/utils/PointCloudSM.js index 734a88fb..64949cd2 100644 --- a/src/utils/PointCloudSM.js +++ b/src/utils/PointCloudSM.js @@ -117,18 +117,18 @@ Potree.PointCloudSM = class PointCloudSM{ let level = node.getLevel(); shader.setUniform1f("uLevel", level); - let iBuffer = node.geometryNode.buffer; + let geometry = node.geometryNode.geometry; - if(!this.potreeRenderer.buffers.has(iBuffer)){ - let buffers = this.potreeRenderer.createBuffer(iBuffer); - this.potreeRenderer.buffers.set(iBuffer, buffers); + if(!this.potreeRenderer.buffers.has(geometry)){ + let webglBuffer = this.potreeRenderer.createBuffer(geometry); + this.potreeRenderer.buffers.set(geometry, webglBuffer); } - let buffer = this.potreeRenderer.buffers.get(iBuffer); + let buffer = this.potreeRenderer.buffers.get(geometry); gl.bindVertexArray(buffer.vao); - let numPoints = iBuffer.numElements; + let numPoints = geometry.attributes.position.count; gl.drawArrays(gl.POINTS, 0, numPoints); } diff --git a/src/workers/LASDecoderWorker.js b/src/workers/LASDecoderWorker.js index feec02f0..65595d5c 100644 --- a/src/workers/LASDecoderWorker.js +++ b/src/workers/LASDecoderWorker.js @@ -62,6 +62,22 @@ function readUsingTempArrays(event) { }; let mean = [0, 0, 0]; + + let pBuff = new ArrayBuffer(numPoints * 3 * 4); + let cBuff = new ArrayBuffer(numPoints * 4); + let iBuff = new ArrayBuffer(numPoints * 4); + let clBuff = new ArrayBuffer(numPoints); + let rnBuff = new ArrayBuffer(numPoints); + let nrBuff = new ArrayBuffer(numPoints); + let psBuff = new ArrayBuffer(numPoints * 2); + + let positions = new Float32Array(pBuff); + let colors = new Uint8Array(cBuff); + let intensities = new Float32Array(iBuff); + let classifications = new Uint8Array(clBuff); + let returnNumbers = new Uint8Array(rnBuff); + let numberOfReturns = new Uint8Array(nrBuff); + let pointSourceIDs = new Uint16Array(psBuff); for (let i = 0; i < numPoints; i++) { // POSITION @@ -87,9 +103,9 @@ function readUsingTempArrays(event) { y = y * scale[1] + offset[1] - event.data.mins[1]; z = z * scale[2] + offset[2] - event.data.mins[2]; - targetView.setFloat32(i * targetPointSize + 0, x, true); - targetView.setFloat32(i * targetPointSize + 4, y, true); - targetView.setFloat32(i * targetPointSize + 8, z, true); + positions[3 * i + 0] = x; + positions[3 * i + 1] = y; + positions[3 * i + 2] = z; mean[0] += x / numPoints; mean[1] += y / numPoints; @@ -107,24 +123,24 @@ function readUsingTempArrays(event) { tempUint8[0] = sourceUint8[i * sourcePointSize + 12]; tempUint8[1] = sourceUint8[i * sourcePointSize + 13]; let intensity = tempUint16[0]; - //targetView.setFloat32(i * numPoints + 0, x, true); + intensities[i] = intensity; // RETURN NUMBER, stored in the first 3 bits - 00000111 let returnNumber = sourceUint8[i * sourcePointSize + 14] & 7; - //returnNumbers[i] = returnNumber; + returnNumbers[i] = returnNumber; // NUMBER OF RETURNS, stored in 00111000 - //numberOfReturns[i] = (sourceUint8[i * pointSize + 14] & 56) / 8; + numberOfReturns[i] = (sourceUint8[i * pointSize + 14] & 56) / 8; // CLASSIFICATION let classification = sourceUint8[i * sourcePointSize + 15]; - //classifications[i] = classification; + classifications[i] = classification; // POINT SOURCE ID tempUint8[0] = sourceUint8[i * sourcePointSize + 18]; tempUint8[1] = sourceUint8[i * sourcePointSize + 19]; let pointSourceID = tempUint16[0]; - //pointSourceIDs[i] = pointSourceID; + pointSourceIDs[i] = pointSourceID; // COLOR, if available if (pointFormatID === 2) { @@ -143,15 +159,17 @@ function readUsingTempArrays(event) { r = r / 256; g = g / 256; b = b / 256; - targetView.setUint8(i * targetPointSize + 12, r, true); - targetView.setUint8(i * targetPointSize + 13, g, true); - targetView.setUint8(i * targetPointSize + 14, b, true); - targetView.setUint8(i * targetPointSize + 15, 255, true); + colors[4 * i + 0] = r; + colors[4 * i + 1] = g; + colors[4 * i + 2] = b; + } } + let indices = new ArrayBuffer(numPoints * 4); + let iIndices = new Uint32Array(indices); for (let i = 0; i < numPoints; i++) { - targetView.setUint32(i * targetPointSize + 16, i, true); + iIndices[i] = i; } performance.mark("laslaz-end"); @@ -167,11 +185,28 @@ function readUsingTempArrays(event) { let message = { mean: mean, - data: targetBuffer, - tightBoundingBox: tightBoundingBox + position: pBuff, + color: cBuff, + intensity: iBuff, + classification: clBuff, + returnNumber: rnBuff, + numberOfReturns: nrBuff, + pointSourceID: psBuff, + tightBoundingBox: tightBoundingBox, + indices: indices }; - let transferables = [message.data]; + let transferables = [ + message.position, + message.color, + message.intensity, + message.classification, + message.returnNumber, + message.numberOfReturns, + message.pointSourceID, + message.indices]; + + debugger; postMessage(message, transferables); }; @@ -201,20 +236,40 @@ function readUsingDataView(event) { }; let mean = [0, 0, 0]; + + let pBuff = new ArrayBuffer(numPoints * 3 * 4); + let cBuff = new ArrayBuffer(numPoints * 4); + let iBuff = new ArrayBuffer(numPoints * 4); + let clBuff = new ArrayBuffer(numPoints); + let rnBuff = new ArrayBuffer(numPoints); + let nrBuff = new ArrayBuffer(numPoints); + let psBuff = new ArrayBuffer(numPoints * 2); + + let positions = new Float32Array(pBuff); + let colors = new Uint8Array(cBuff); + let intensities = new Float32Array(iBuff); + let classifications = new Uint8Array(clBuff); + let returnNumbers = new Uint8Array(rnBuff); + let numberOfReturns = new Uint8Array(nrBuff); + let pointSourceIDs = new Uint16Array(psBuff); for (let i = 0; i < numPoints; i++) { // POSITION - let x = sourceView.getInt32(i * sourcePointSize + 0, true); - let y = sourceView.getInt32(i * sourcePointSize + 4, true); - let z = sourceView.getInt32(i * sourcePointSize + 8, true); + let ux = sourceView.getInt32(i * sourcePointSize + 0, true); + let uy = sourceView.getInt32(i * sourcePointSize + 4, true); + let uz = sourceView.getInt32(i * sourcePointSize + 8, true); - x = x * scale[0] + offset[0] - event.data.mins[0]; - y = y * scale[1] + offset[1] - event.data.mins[1]; - z = z * scale[2] + offset[2] - event.data.mins[2]; + x = ux * scale[0] + offset[0] - event.data.mins[0]; + y = uy * scale[1] + offset[1] - event.data.mins[1]; + z = uz * scale[2] + offset[2] - event.data.mins[2]; - targetView.setFloat32(i * targetPointSize + 0, x, true); - targetView.setFloat32(i * targetPointSize + 4, y, true); - targetView.setFloat32(i * targetPointSize + 8, z, true); + //x = ux * scale[0]; + //y = uy * scale[1]; + //z = uz * scale[2]; + + positions[3 * i + 0] = x; + positions[3 * i + 1] = y; + positions[3 * i + 2] = z; mean[0] += x / numPoints; mean[1] += y / numPoints; @@ -230,23 +285,23 @@ function readUsingDataView(event) { // INTENSITY let intensity = sourceView.getUint16(i * sourcePointSize + 12, true); - targetView.setFloat32(i * targetPointSize + 16, intensity, true); + intensities[i] = intensity; // RETURN NUMBER, stored in the first 3 bits - 00000111 // number of returns stored in next 3 bits - 00111000 let returnNumberAndNumberOfReturns = sourceView.getUint8(i * sourcePointSize + 14, true); let returnNumber = returnNumberAndNumberOfReturns & 0b0111; let numberOfReturns = (returnNumberAndNumberOfReturns & 0b00111000) >> 3; - targetView.setFloat32(i * targetPointSize + 24, returnNumber, true); - targetView.setFloat32(i * targetPointSize + 28, numberOfReturns, true); + returnNumbers[i] = returnNumber; + numberOfReturns[i] = numberOfReturns; // CLASSIFICATION let classification = sourceView.getUint8(i * sourcePointSize + 15, true); - targetView.setFloat32(i * targetPointSize + 20, classification, true); + classifications[i] = classification; // POINT SOURCE ID let pointSourceID = sourceView.getUint16(i * sourcePointSize + 18, true); - targetView.setFloat32(i * targetPointSize + 32, pointSourceID, true); + pointSourceIDs[i] = pointSourceID; // COLOR, if available if (pointFormatID === 2) { @@ -254,15 +309,17 @@ function readUsingDataView(event) { let g = sourceView.getUint16(i * sourcePointSize + 22, true) / 256; let b = sourceView.getUint16(i * sourcePointSize + 24, true) / 256; - targetView.setUint8(i * targetPointSize + 12, r, true); - targetView.setUint8(i * targetPointSize + 13, g, true); - targetView.setUint8(i * targetPointSize + 14, b, true); - targetView.setUint8(i * targetPointSize + 15, 255, true); + colors[4 * i + 0] = r; + colors[4 * i + 1] = g; + colors[4 * i + 2] = b; + colors[4 * i + 3] = 255; } } + let indices = new ArrayBuffer(numPoints * 4); + let iIndices = new Uint32Array(indices); for (let i = 0; i < numPoints; i++) { - targetView.setUint32(i * targetPointSize + 36, i, true); + iIndices[i] = i; } performance.mark("laslaz-end"); @@ -279,11 +336,26 @@ function readUsingDataView(event) { let message = { mean: mean, - data: targetBuffer, - tightBoundingBox: tightBoundingBox + position: pBuff, + color: cBuff, + intensity: iBuff, + classification: clBuff, + returnNumber: rnBuff, + numberOfReturns: nrBuff, + pointSourceID: psBuff, + tightBoundingBox: tightBoundingBox, + indices: indices }; - let transferables = [message.data]; + let transferables = [ + message.position, + message.color, + message.intensity, + message.classification, + message.returnNumber, + message.numberOfReturns, + message.pointSourceID, + message.indices]; postMessage(message, transferables); }; From bcce8b7f81e3c627ce910f46b86491a4ed2d5585 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Mon, 22 Jan 2018 08:05:42 +0100 Subject: [PATCH 07/22] ... --- src/PotreeRenderer.js | 9 +- src/materials/shaders/pointcloud.vs | 53 +++------- src/materials/shaders/pointcloud_sm.vs | 111 +++++++------------- src/utils/PointCloudSM.js | 139 ++++++------------------- src/viewer/EDLRenderer.js | 40 ++++--- 5 files changed, 119 insertions(+), 233 deletions(-) diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index 8daee2f3..959c292c 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -772,14 +772,21 @@ 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)); const lWorldView = shader.uniformLocations["uShadowWorldView[0]"]; 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; diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index ca683329..667ebc08 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -80,6 +80,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 @@ -508,7 +509,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 @@ -700,47 +701,25 @@ void main() { 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)); + //float distanceToLight = length(viewPos); + 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 uv = vec2(u, v) * 0.5 + 0.5; - vec2 sampleStep = vec2(1.0 / (4.0*1024.0), 1.0 / (4.0*1024.0)); + vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v)); - vec2 sampleLocations[9]; - sampleLocations[0] = vec2(0.0, 0.0); - sampleLocations[1] = sampleStep; - sampleLocations[2] = -sampleStep; - sampleLocations[3] = vec2(sampleStep.x, -sampleStep.y); - sampleLocations[4] = vec2(-sampleStep.x, sampleStep.y); + float linearDepthFromSM = depthMapValue.x + 0.1; + float linearDepthFromViewer = distanceToLight; - sampleLocations[5] = vec2(0.0, sampleStep.y); - sampleLocations[6] = vec2(0.0, -sampleStep.y); - sampleLocations[7] = vec2(sampleStep.x, 0.0); - sampleLocations[8] = vec2(-sampleStep.x, 0.0); - - float visible_samples = 0.0; - float sumSamples = 0.0; - - float bias = vRadius * 1.0; - for(int j = 0; j < 9; 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); - - visible_samples += (1.0 - p); - - - sumSamples = sumSamples + 1.0; + if(linearDepthFromSM < linearDepthFromViewer){ + vColor = vec3(0.2, 0.2, 0.2); } - float coverage = 1.0 - visible_samples / sumSamples; - float shade = coverage * 0.5 + 0.5; - - vColor = vColor * shade + uShadowColor * (1.0 - shade); + //vColor = vec3(1.0, 1.0, 1.0) * distanceToLight * 0.05; } #endif 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/utils/PointCloudSM.js b/src/utils/PointCloudSM.js index 64949cd2..73fce43d 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,36 @@ 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 = 60; + let aspect = light.shadow.mapSize.width / light.shadow.mapSize.height; + let near = 0.1; + let far = 1000; + 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.lookAt(new THREE.Vector3(0, 0, 8)); + this.camera.updateProjectionMatrix(); + this.camera.updateMatrix(); + this.camera.updateMatrixWorld(); + this.camera.matrixWorldInverse.getInverse(this.camera.matrixWorld); } setSize(width, height){ @@ -59,82 +53,11 @@ Potree.PointCloudSM = class PointCloudSM{ this.target.setSize(width, height); } - renderOctree(octree, nodes){ - - 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); + render(scene, camera){ + this.threeRenderer.setClearColor(0x00ff00, 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 geometry = node.geometryNode.geometry; - - if(!this.potreeRenderer.buffers.has(geometry)){ - let webglBuffer = this.potreeRenderer.createBuffer(geometry); - this.potreeRenderer.buffers.set(geometry, webglBuffer); - } - - let buffer = this.potreeRenderer.buffers.get(geometry); - - gl.bindVertexArray(buffer.vao); - - let numPoints = geometry.attributes.position.count; - 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/viewer/EDLRenderer.js b/src/viewer/EDLRenderer.js index c8828397..28deb5ac 100644 --- a/src/viewer/EDLRenderer.js +++ b/src/viewer/EDLRenderer.js @@ -35,14 +35,19 @@ class EDLRenderer { 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.shadowMap.target.texture} ); - // let plane = new THREE.Mesh( geometry, material ); - // plane.scale.set(0.5, 0.5, 1.0); - // plane.position.set(plane.scale.x / 2, plane.scale.y / 2, 0); - // this.viewer.overlay.add(plane); - //} + { + //this.viewer.renderer.setClearColor(0xff0000, 0); + //this.viewer.renderer.clearTarget(this.shadowMap.target, true, true, true); + + let geometry = new THREE.PlaneBufferGeometry( 1, 1, 32, 32); + //let material = new THREE.MeshNormalMaterial(); + let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.shadowMap.target.texture} ); + //let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.rtColor.texture} ); + let plane = new THREE.Mesh( geometry, material ); + plane.scale.set(0.5, 0.5, 1.0); + plane.position.set(plane.scale.x / 2, plane.scale.y / 2, 0); + this.viewer.overlay.add(plane); + } }; resize () { @@ -61,12 +66,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,11 +109,14 @@ 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 originalMaterials = viewer.scene.pointclouds.map(pc => pc.material.pointColorType); + viewer.scene.pointclouds.map(pc => pc.material.pointColorType = Potree.PointColorType.DEPTH); + + this.shadowMap.render(viewer.scene.scenePointCloud, camera); + + viewer.scene.pointclouds.map( (pc, index) => pc.material.pointColorType = originalMaterials[index]);; viewer.shadowTestCam.updateMatrixWorld(); viewer.shadowTestCam.matrixWorldInverse.getInverse(viewer.shadowTestCam.matrixWorld); @@ -151,6 +159,10 @@ class EDLRenderer { }else{ viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtColor, {}); } + + //viewer.renderer.setClearColor(0x00ff00, 1); + //viewer.renderer.clearTarget( this.shadowMap.target, true, true, true ); + //viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.shadowMap.target, {}); viewer.renderer.render(viewer.scene.scene, camera, this.rtColor); From 9f02538a19378bec9e40212e2790c677c9db83d8 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Mon, 22 Jan 2018 10:14:03 +0100 Subject: [PATCH 08/22] ... --- src/PotreeRenderer.js | 10 ++++-- src/materials/shaders/pointcloud.vs | 53 +++++++++++++++++++++++++---- src/utils/PointCloudSM.js | 17 ++++++--- src/viewer/EDLRenderer.js | 21 +++++------- 4 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index 959c292c..837741bd 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -951,8 +951,14 @@ 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); diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 667ebc08..deaf4491 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -697,7 +697,7 @@ void main() { #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; @@ -710,16 +710,55 @@ void main() { float u = nc.x * 0.5 + 0.5; float v = nc.y * 0.5 + 0.5; - vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v)); + 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; + sampleLocations[2] = -sampleStep; + sampleLocations[3] = vec2(sampleStep.x, -sampleStep.y); + sampleLocations[4] = vec2(-sampleStep.x, sampleStep.y); - float linearDepthFromSM = depthMapValue.x + 0.1; - float linearDepthFromViewer = distanceToLight; + sampleLocations[5] = vec2(0.0, sampleStep.y); + sampleLocations[6] = vec2(0.0, -sampleStep.y); + sampleLocations[7] = vec2(sampleStep.x, 0.0); + sampleLocations[8] = vec2(-sampleStep.x, 0.0); - if(linearDepthFromSM < linearDepthFromViewer){ - vColor = vec3(0.2, 0.2, 0.2); + float visibleSamples = 0.0; + float numSamples = 0.0; + + float bias = vRadius * 2.0; + + for(int j = 0; j < 9; j++){ + vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]); + + float linearDepthFromSM = depthMapValue.x + bias; + float linearDepthFromViewer = distanceToLight; + + if(linearDepthFromSM < linearDepthFromViewer){ + vColor = vColor * vec3(0.5, 0.0, 0.0); + }else{ + visibleSamples += 1.0; + } + + numSamples += 1.0; } - //vColor = vec3(1.0, 1.0, 1.0) * distanceToLight * 0.05; + float visibility = visibleSamples / numSamples; + //vColor = visibility * vColor + (1.0 - visibility) * vColor * vec3(0.5, 0.0, 0.0); + vColor = vec3(1.0, 1.0, 1.0) * visibility; + + //vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v)); + + //float linearDepthFromSM = depthMapValue.x + 0.2; + //float linearDepthFromViewer = distanceToLight; + + //if(linearDepthFromSM < linearDepthFromViewer){ + // vColor = vColor * vec3(0.5, 0.0, 0.0); + //} + + if(u < 0.0 || u > 1.0 || v < 0.0 || v > 1.0){ + vColor = vec3(0.0, 0.0, 0.2); + } } #endif diff --git a/src/utils/PointCloudSM.js b/src/utils/PointCloudSM.js index 73fce43d..8baab9e7 100644 --- a/src/utils/PointCloudSM.js +++ b/src/utils/PointCloudSM.js @@ -31,15 +31,21 @@ Potree.PointCloudSM = class PointCloudSM{ this.light = light; //let fov = (180 / Math.PI) * 2 * light.angle; - let fov = 60; + let fov = 90; let aspect = light.shadow.mapSize.width / light.shadow.mapSize.height; let near = 0.1; - let far = 1000; + 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.lookAt(new THREE.Vector3(0, 0, 8)); + //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(); @@ -54,7 +60,8 @@ Potree.PointCloudSM = class PointCloudSM{ } render(scene, camera){ - this.threeRenderer.setClearColor(0x00ff00, 1); + //this.threeRenderer.setClearColor(0x00ff00, 1); + this.threeRenderer.clearTarget( this.target, true, true, true ); this.potreeRenderer.render(scene, this.camera, this.target, {}); } diff --git a/src/viewer/EDLRenderer.js b/src/viewer/EDLRenderer.js index 28deb5ac..9e73d2ec 100644 --- a/src/viewer/EDLRenderer.js +++ b/src/viewer/EDLRenderer.js @@ -35,19 +35,14 @@ class EDLRenderer { depthTexture: new THREE.DepthTexture(undefined, undefined, THREE.UnsignedIntType) }); - { - //this.viewer.renderer.setClearColor(0xff0000, 0); - //this.viewer.renderer.clearTarget(this.shadowMap.target, true, true, true); - - let geometry = new THREE.PlaneBufferGeometry( 1, 1, 32, 32); - //let material = new THREE.MeshNormalMaterial(); - let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.shadowMap.target.texture} ); - //let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.rtColor.texture} ); - let plane = new THREE.Mesh( geometry, material ); - plane.scale.set(0.5, 0.5, 1.0); - plane.position.set(plane.scale.x / 2, plane.scale.y / 2, 0); - this.viewer.overlay.add(plane); - } + //{ + // let geometry = new THREE.PlaneBufferGeometry( 1, 1, 32, 32); + // let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.shadowMap.target.texture} ); + // let plane = new THREE.Mesh( geometry, material ); + // plane.scale.set(0.5, 0.5, 1.0); + // plane.position.set(plane.scale.x / 2, plane.scale.y / 2, 0); + // this.viewer.overlay.add(plane); + //} }; resize () { From 89bb3d0de8935a9c5d829260bd072bdeed57e1e9 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Mon, 22 Jan 2018 11:48:10 +0100 Subject: [PATCH 09/22] some fixes --- examples/heidentor.html | 24 ------------------------ gulpfile.js | 8 ++++---- src/PointCloudOctree.js | 23 ++++++++++------------- src/extensions/EventDispatcher.js | 2 +- src/loader/BinaryLoader.js | 6 ++++-- src/materials/PointCloudMaterial.js | 12 ++++++++++++ src/materials/shaders/pointcloud.vs | 4 +--- src/viewer/EDLRenderer.js | 14 +++++++++++--- src/viewer/PropertiesPanel.js | 2 +- src/viewer/potree.css | 14 ++++++++++++++ src/workers/BinaryDecoderWorker.js | 2 +- 11 files changed, 59 insertions(+), 52 deletions(-) diff --git a/examples/heidentor.html b/examples/heidentor.html index 38691c20..8ae9ce5b 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -96,30 +96,6 @@ viewer.clippingTool.setClipMode(Potree.ClipMode.INSIDE); //viewer.fitToScreen(); - //Potree.measureTimings = true; - - - - - viewer.addEventListener("update", () => { - - let sceneNode = viewer.scene.pointclouds[0].root.sceneNode; - - if(!sceneNode){ - return; - } - - let geometry = sceneNode.geometry; - let aColor = geometry.attributes.color; - - aColor.array = aColor.array.map(v => Math.random() * 255); - aColor.needsUpdate = true; - - - - }); - - }); diff --git a/gulpfile.js b/gulpfile.js index 8253af0d..9c645d29 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,15 +16,15 @@ var server; var paths = { potree : [ + "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", diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 816ac9d5..ceb94fba 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -702,7 +702,7 @@ 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, @@ -747,23 +747,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 +775,6 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree { //} } - offset += attribute.bytes; } hit.point = point; 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 8dcf7dc1..4ca0ee1b 100644 --- a/src/loader/BinaryLoader.js +++ b/src/loader/BinaryLoader.js @@ -85,8 +85,10 @@ Potree.BinaryLoader.prototype.parse = function (node, buffer) { 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.INDEX) { - geometry.addAttribute('indices', new THREE.BufferAttribute(new Uint8Array(buffer), 4)); + } else if (parseInt(property) === Potree.PointAttributeNames.INDICES) { + let bufferAttribute = new THREE.BufferAttribute(new Uint8Array(buffer), 4); + bufferAttribute.normalized = true; + geometry.addAttribute('indices', bufferAttribute); } } diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js index 76c2a258..6a933cc2 100644 --- a/src/materials/PointCloudMaterial.js +++ b/src/materials/PointCloudMaterial.js @@ -1077,6 +1077,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/pointcloud.vs b/src/materials/shaders/pointcloud.vs index deaf4491..282efc55 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -692,8 +692,6 @@ void main() { #endif - - #if defined(num_shadowmaps) && num_shadowmaps > 0 const float sm_near = 0.1; @@ -763,6 +761,6 @@ void main() { #endif - + } diff --git a/src/viewer/EDLRenderer.js b/src/viewer/EDLRenderer.js index 9e73d2ec..9ddc1d87 100644 --- a/src/viewer/EDLRenderer.js +++ b/src/viewer/EDLRenderer.js @@ -106,12 +106,20 @@ class EDLRenderer { this.shadowMap.setLight(light); - let originalMaterials = viewer.scene.pointclouds.map(pc => pc.material.pointColorType); - viewer.scene.pointclouds.map(pc => pc.material.pointColorType = Potree.PointColorType.DEPTH); + 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); - viewer.scene.pointclouds.map( (pc, index) => pc.material.pointColorType = originalMaterials[index]);; + for(let pointcloud of viewer.scene.pointclouds){ + let originalAttribute = originalAttributes.get(pointcloud); + pointcloud.material.pointColorType = originalAttribute; + pointcloud.material.enableEvents(); + } viewer.shadowTestCam.updateMatrixWorld(); viewer.shadowTestCam.matrixWorldInverse.getInverse(viewer.shadowTestCam.matrixWorld); diff --git a/src/viewer/PropertiesPanel.js b/src/viewer/PropertiesPanel.js index de34c201..950199d6 100644 --- a/src/viewer/PropertiesPanel.js +++ b/src/viewer/PropertiesPanel.js @@ -621,7 +621,7 @@ Potree.PropertiesPanel = class PropertriesPanel{
  • - +
  • diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index 647de338..0dc994db 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -433,7 +433,6 @@ initSidebar = (viewer) => { let currentClipMode = Object.keys(Potree.ClipMode) .filter(key => Potree.ClipMode[key] === viewer.clippingTool.clipMode); elClipModes.find(`input[value=${currentClipMode}]`).trigger("click"); - } let clippingToolBar = $("#clipping_tools"); @@ -768,19 +767,38 @@ initSidebar = (viewer) => { let initSettings = function () { - $('#sldMinNodeSize').slider({ - value: viewer.getMinNodeSize(), - min: 0, - max: 1000, - step: 0.01, - slide: function (event, ui) { viewer.setMinNodeSize(ui.value); } - }); - viewer.addEventListener('minnodesize_changed', function (event) { + { + $('#sldMinNodeSize').slider({ + value: viewer.getMinNodeSize(), + min: 0, + max: 1000, + step: 0.01, + slide: function (event, ui) { viewer.setMinNodeSize(ui.value); } + }); + + viewer.addEventListener('minnodesize_changed', function (event) { + $('#lblMinNodeSize').html(parseInt(viewer.getMinNodeSize())); + $('#sldMinNodeSize').slider({value: viewer.getMinNodeSize()}); + }); $('#lblMinNodeSize').html(parseInt(viewer.getMinNodeSize())); - $('#sldMinNodeSize').slider({value: viewer.getMinNodeSize()}); - }); - $('#lblMinNodeSize').html(parseInt(viewer.getMinNodeSize())); + } + + { + let elSplatQuality = $("#splat_quality_options"); + elSplatQuality.selectgroup({title: "Splat Quality"}); + + elSplatQuality.find("input").click( (e) => { + if(e.target.value === "standard"){ + viewer.useHQ = false; + }else if(e.target.value === "hq"){ + viewer.useHQ = true; + } + }); + + let currentQuality = viewer.useHQ ? "hq" : "standard"; + elSplatQuality.find(`input[value=${currentQuality}]`).trigger("click"); + } $('#show_bounding_box').click(() => { viewer.setShowBoundingBox($('#show_bounding_box').prop("checked")); diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 84f022ab..e954c46f 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1284,29 +1284,50 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ try{ - if(this.useRep){ - if (!this.repRenderer) { - this.repRenderer = new RepRenderer(this); - } - this.repRenderer.render(this.renderer); - } else if (this.useEDL && Potree.Features.SHADER_EDL.isSupported()) { - if (!this.edlRenderer) { - this.edlRenderer = new EDLRenderer(this); - } - this.edlRenderer.render(this.renderer); - } else if (this.useHQ) { + + if(this.useHQ){ if (!this.hqRenderer) { this.hqRenderer = new HQSplatRenderer(this); } + this.hqRenderer.useEDL = this.useEDL; this.hqRenderer.render(this.renderer); - } else { - if (!this.potreeRenderer) { - this.potreeRenderer = new PotreeRenderer(this); + }else{ + if (this.useEDL && Potree.Features.SHADER_EDL.isSupported()) { + if (!this.edlRenderer) { + this.edlRenderer = new EDLRenderer(this); + } + this.edlRenderer.render(this.renderer); + } else { + if (!this.potreeRenderer) { + this.potreeRenderer = new PotreeRenderer(this); + } + this.potreeRenderer.render(); } - - this.potreeRenderer.render(); } + //if(this.useRep){ + // if (!this.repRenderer) { + // this.repRenderer = new RepRenderer(this); + // } + // this.repRenderer.render(this.renderer); + //} else if (this.useHQ && Potree.Features.SHADER_SPLATS.isSupported()) { + // if (!this.hqRenderer) { + // this.hqRenderer = new HQSplatRenderer(this); + // } + // this.hqRenderer.render(this.renderer); + //} else if (this.useEDL && Potree.Features.SHADER_EDL.isSupported()) { + // if (!this.edlRenderer) { + // this.edlRenderer = new EDLRenderer(this); + // } + // this.edlRenderer.render(this.renderer); + //} else { + // if (!this.potreeRenderer) { + // this.potreeRenderer = new PotreeRenderer(this); + // } + + // this.potreeRenderer.render(); + //} + this.renderer.render(this.overlay, this.overlayCamera); }catch(e){ From 5c8c1c6f6f429c87ede704585370493fbac8ed9e Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Wed, 24 Jan 2018 17:04:27 +0100 Subject: [PATCH 15/22] fixes & cleanup --- examples/clipping_volume.html | 2 + examples/heidentor.html | 9 ++- src/PointCloudOctree.js | 6 +- src/Potree.js | 31 ++++---- src/PotreeRenderer.js | 3 +- src/materials/PointCloudMaterial.js | 18 +++-- src/materials/shaders/pointcloud.vs | 106 +++++++++++++--------------- src/utils/ClippingTool.js | 15 ---- src/viewer/sidebar.html | 17 +++-- src/viewer/sidebar.js | 35 ++++++--- src/viewer/viewer.js | 56 ++++++++++----- 11 files changed, 164 insertions(+), 134 deletions(-) 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 8ae9ce5b..8c52c036 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -67,7 +67,6 @@ viewer.setFOV(60); viewer.setPointBudget(1*1000*1000); viewer.setMinNodeSize(0); - viewer.useEDL = false; viewer.loadSettingsFromURL(); viewer.setDescription(""); @@ -88,14 +87,18 @@ 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.clippingTool.setClipMode(Potree.ClipMode.INSIDE); //viewer.fitToScreen(); + //viewer.useHQ = true; + + //Potree.measureTimings = true; + }); diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 1f1695b2..692d48e3 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -624,10 +624,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 = []; diff --git a/src/Potree.js b/src/Potree.js index 50526d82..461a9d0d 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -42,6 +42,18 @@ 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.timerQueries = {}; Potree.measureTimings = false; @@ -457,23 +469,8 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.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; - } - } - visible = visible && intersectsClipBoxes; + if(pointcloud.material.numClipBoxes > 0){ + console.log("TODO"); } // visible = ["r", "r0", "r06", "r060"].includes(node.name); diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index 87398106..369b9a64 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -889,7 +889,8 @@ Potree.Renderer = class Renderer { shader.setUniform("uUseOrthographicCamera", false); } - shader.setUniform1i("clipMode", material.clipMode); + shader.setUniform1i("clipTask", material.clipTask); + shader.setUniform1i("clipMethod", material.clipMethod); if (material.clipBoxes && material.clipBoxes.length > 0) { diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js index f4e1053f..ad795ca8 100644 --- a/src/materials/PointCloudMaterial.js +++ b/src/materials/PointCloudMaterial.js @@ -265,7 +265,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: [] }, @@ -578,14 +579,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; diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 14fffc5a..8bcdba80 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -29,7 +29,17 @@ 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 @@ -578,24 +588,6 @@ float getPointSize(){ return pointSize; } -#define CLIP_DISABLED 0 -#define CLIP_HIGHLIGHT 1 -#define CLIP_INSIDE 2 -#define CLIP_OUTSIDE 3 - -void testInsideClipVolume(bool insideAny, bool insideAll) { - - if(clipMode == CLIP_INSIDE && !insideAll){ - gl_Position = vec4(1000.0, 1000.0, 1000.0, 1.0); - } - - //if(insideAny && 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; - //} -} - void doClipping(){ #if !defined color_type_composite @@ -607,45 +599,47 @@ void doClipping(){ } #endif + bool insideAny = false; + bool insideAll = true; + #if defined(num_clipboxes) && num_clipboxes > 0 - if(clipMode != 0) { - bool insideAny = false; - bool insideAll = true; - 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; - insideAll = insideAll && inside; - } - testInsideClipVolume(insideAny, insideAll); - } + 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; + insideAll = insideAll && inside; + } #endif #if defined(num_clippolygons) && num_clippolygons > 0 - - - if(clipMode != 0) { - bool insideAny = false; - bool insideAll = false; - for(int i = 0; i < num_clippolygons; i++) { - bool inside = pointInClipPolygon(position, i);; - insideAny = insideAny || inside; - insideAll = insideAll // inside; - } - testInsideClipVolume(insideAny, insideAll); + for(int i = 0; i < num_clippolygons; i++) { + bool inside = pointInClipPolygon(position, i);; + insideAny = insideAny || inside; + insideAll = insideAll // inside; } - #endif + #endif + + 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); -} // @@ -672,12 +666,10 @@ void main() { vPointSize = pointSize; // COLOR - vec3 color = getColor(); + vColor = getColor(); // CLIPPING doClipping(); - - @@ -741,16 +733,14 @@ void main() { float visibility = visibleSamples / numSamples; 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){ - color = vec3(0.0, 0.0, 0.2); + vColor = vec3(0.0, 0.0, 0.2); }else{ - color = 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); + 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 - vColor = color; - #if defined hq_depth_pass float originalDepth = gl_Position.w; float adjustedDepth = originalDepth + 2.0 * vRadius; diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js index ffd8d015..d5b25fb1 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,13 +56,6 @@ 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; diff --git a/src/viewer/sidebar.html b/src/viewer/sidebar.html index ffb185a9..441f1338 100644 --- a/src/viewer/sidebar.html +++ b/src/viewer/sidebar.html @@ -70,11 +70,18 @@
  • - - - - - + + + + + + +
  • + +
  • + + +
  • diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index 0dc994db..bc20dcbb 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -418,21 +418,38 @@ initSidebar = (viewer) => { function initClippingTool() { - viewer.addEventListener("clipper.clipMode_changed", function(event){ + viewer.addEventListener("cliptask_changed", function(event){ + console.log("TODO"); + }); + + viewer.addEventListener("clipmethod_changed", function(event){ console.log("TODO"); }); { - let elClipModes = $("#optClipMode"); - elClipModes.selectgroup({title: "Clip Mode"}); + let elClipTask = $("#cliptask_options"); + elClipTask.selectgroup({title: "Clip Task"}); - elClipModes.find("input").click( (e) => { - viewer.clippingTool.setClipMode(Potree.ClipMode[e.target.value]); + elClipTask.find("input").click( (e) => { + viewer.setClipTask(Potree.ClipTask[e.target.value]); }); - let currentClipMode = Object.keys(Potree.ClipMode) - .filter(key => Potree.ClipMode[key] === viewer.clippingTool.clipMode); - elClipModes.find(`input[value=${currentClipMode}]`).trigger("click"); + let currentClipTask = Object.keys(Potree.ClipTask) + .filter(key => Potree.ClipTask[key] === viewer.clipTask); + elClipTask.find(`input[value=${currentClipTask}]`).trigger("click"); + } + + { + let elClipMethod = $("#clipmethod_options"); + elClipMethod.selectgroup({title: "Clip Method"}); + + elClipMethod.find("input").click( (e) => { + viewer.setClipMethod(Potree.ClipMethod[e.target.value]); + }); + + let currentClipMethod = Object.keys(Potree.ClipMethod) + .filter(key => Potree.ClipMethod[key] === viewer.clipMethod); + elClipMethod.find(`input[value=${currentClipMethod}]`).trigger("click"); } let clippingToolBar = $("#clipping_tools"); @@ -733,7 +750,7 @@ initSidebar = (viewer) => { elNavigation.append(elCameraProjection); elCameraProjection.selectgroup({title: "Camera Projection"}); elCameraProjection.find("input").click( (e) => { - viewer.switchCameraMode(Potree.CameraMode[e.target.value]); + viewer.setCameraMode(Potree.CameraMode[e.target.value]); }); let cameraMode = Object.keys(Potree.CameraMode) .filter(key => Potree.CameraMode[key] === viewer.scene.cameraMode); diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index e954c46f..2ff2abcd 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -37,7 +37,6 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.server = null; this.fov = 60; - //this.clipMode = Potree.ClipMode.HIGHLIGHT_INSIDE; this.isFlipYZ = false; this.useDEMCollisions = false; this.generateDEM = false; @@ -71,11 +70,8 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.showBoundingBox = false; this.showAnnotations = true; this.freeze = false; - - this.stats = new Stats(); - // this.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom - // document.body.appendChild( this.stats.dom ); - // this.stats.dom.style.left = "100px"; + this.clipTask = Potree.ClipTask.HIGHLIGHT; + this.clipMethod = Potree.ClipMethod.INSIDE_ANY; this.potreeRenderer = null; this.edlRenderer = null; @@ -171,7 +167,8 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.setEDLEnabled(false); this.setEDLRadius(1.4); this.setEDLStrength(0.4); - this.clippingTool.setClipMode(Potree.ClipMode.HIGHLIGHT); + this.setClipTask(Potree.ClipTask.HIGHLIGHT); + this.setClipMethod(Potree.ClipMethod.INSIDE_ANY); this.setPointBudget(1*1000*1000); this.setShowBoundingBox(false); this.setFreeze(false); @@ -326,10 +323,6 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ $('#potree_description')[0].innerHTML = value; }; - setClipMode(clipMode){ - this.clippingTool.setClipMode(clipMode); - } - setNavigationMode (value) { this.scene.view.navigationMode = value; }; @@ -375,6 +368,36 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ return this.freeze; }; + getClipTask(){ + return this.clipTask; + } + + getClipMethod(){ + return this.clipMethod; + } + + setClipTask(value){ + if(this.clipTask !== value){ + + this.clipTask = value; + + viewer.dispatchEvent({ + type: "cliptask_changed", + viewer: viewer}); + } + } + + setClipMethod(value){ + if(this.clipMethod !== value){ + + this.clipMethod = value; + + viewer.dispatchEvent({ + type: "clipmethod_changed", + viewer: viewer}); + } + } + setPointBudget (value) { if (Potree.pointBudget !== value) { Potree.pointBudget = parseInt(value); @@ -652,8 +675,8 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ // TODO flipyz console.log('TODO'); } - - switchCameraMode(mode) { + + setCameraMode(mode){ this.scene.cameraMode = mode; for(let pointcloud of this.scene.pointclouds) { @@ -1248,7 +1271,8 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ for(let pointcloud of this.scene.pointclouds){ pointcloud.material.setClipBoxes(clipBoxes); pointcloud.material.setClipPolygons(clipPolygons, this.clippingTool.maxPolygonVertices); - pointcloud.material.clipMode = this.clippingTool.clipMode; + pointcloud.material.clipTask = this.clipTask; + pointcloud.material.clipMethod = this.clipMethod; } } @@ -1471,8 +1495,6 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ performance.mark("loop-start"); } - this.stats.begin(); - this.update(this.clock.getDelta(), timestamp); this.render(); @@ -1484,8 +1506,6 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.resolveTimings(timestamp); - this.stats.end(); - Potree.framenumber++; } }; From 91c63273e1b0813d09b31f590206afda7766cc10 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Wed, 24 Jan 2018 18:53:13 +0100 Subject: [PATCH 16/22] clip polygons --- src/Potree.js | 3 +- src/materials/shaders/pointcloud.vs | 56 ++++---- src/utils/ClippingTool.js | 206 ++++++++++++++-------------- 3 files changed, 136 insertions(+), 129 deletions(-) diff --git a/src/Potree.js b/src/Potree.js index 461a9d0d..a6fbf145 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -469,8 +469,9 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.pointBudget); visible = visible && level < maxLevel; - if(pointcloud.material.numClipBoxes > 0){ + if(pointcloud.material.numClipBoxes > 0 && !window.warned125){ console.log("TODO"); + window.warned125 = true; } // visible = ["r", "r0", "r06", "r060"].includes(node.name); diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 8bcdba80..0ec75147 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -481,33 +481,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 - vec3 getColor(){ vec3 color; @@ -588,6 +561,33 @@ float getPointSize(){ return pointSize; } +#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 doClipping(){ #if !defined color_type_composite @@ -617,7 +617,7 @@ void doClipping(){ for(int i = 0; i < num_clippolygons; i++) { bool inside = pointInClipPolygon(position, i);; insideAny = insideAny || inside; - insideAll = insideAll // inside; + insideAll = insideAll && inside; } #endif diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js index d5b25fb1..eba90801 100644 --- a/src/utils/ClippingTool.js +++ b/src/utils/ClippingTool.js @@ -59,118 +59,124 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ 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 = $(` + - this.viewer.scene.addClipVolume(clipVolume); + + + + + - let cancel = { - callback: null - }; + + + - let drag = e => { - let camera = this.viewer.scene.getActiveCamera(); - 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); + + + `); + $(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){ + if(polyClipVol.markers.length > 1) { + polyClipVol.addEdge(polyClipVol.markers.length - 2, polyClipVol.markers.length - 1); } - }; - - let drop = e => { - clipVolume.removeEventListener("drag", drag); - clipVolume.removeEventListener("drop", drop); - cancel.callback(); + polyClipVol.addMarker(); - 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){ + 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); + }); + + + 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); + }); + + 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; + } 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() { From 917d22616edd03f30658625cdb0606208f4eaa0b Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Thu, 25 Jan 2018 17:43:43 +0100 Subject: [PATCH 17/22] ... --- src/Potree.js | 12 ++++++------ src/viewer/sidebar.js | 13 +++++++++++-- src/viewer/viewer.js | 9 +++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Potree.js b/src/Potree.js index a6fbf145..18c64865 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -54,6 +54,12 @@ Potree.ClipMethod = { INSIDE_ALL: 1 }; +Potree.MOUSE = { + LEFT: 0b0001, + RIGHT: 0b0010, + MIDDLE: 0b0100 +}; + Potree.timerQueries = {}; Potree.measureTimings = false; @@ -125,12 +131,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; diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index bc20dcbb..dc45e1e1 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -277,8 +277,17 @@ initSidebar = (viewer) => { object.moveHere(viewer.scene.getActiveCamera()); }else if(object instanceof Potree.PolygonClipVolume){ let dir = object.camera.getWorldDirection(); - dir.multiplyScalar(viewer.scene.view.radius); - let target = new THREE.Vector3().addVectors(object.camera.position, dir); + let target; + + if(object.camera instanceof THREE.OrthographicCamera){ + dir.multiplyScalar(object.camera.right) + target = new THREE.Vector3().addVectors(object.camera.position, dir); + viewer.setCameraMode(Potree.CameraMode.ORTHOGRAPHIC); + }else if(object.camera instanceof THREE.PerspectiveCamera){ + dir.multiplyScalar(viewer.scene.view.radius); + target = new THREE.Vector3().addVectors(object.camera.position, dir); + viewer.setCameraMode(Potree.CameraMode.PERSPECTIVE); + } viewer.scene.view.position.copy(object.camera.position); viewer.scene.view.lookAt(target); diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 2ff2abcd..88f5d212 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1464,7 +1464,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ } } - loop (timestamp) { + loop(timestamp){ requestAnimationFrame(this.loop.bind(this)); { // resize @@ -1476,11 +1476,12 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.scene.cameraP.aspect = aspect; this.scene.cameraP.updateProjectionMatrix(); - let frustumScale = viewer.moveSpeed * 2.0; + //let frustumScale = viewer.moveSpeed * 2.0; + let frustumScale = viewer.scene.view.radius; this.scene.cameraO.left = -frustumScale; this.scene.cameraO.right = frustumScale; - this.scene.cameraO.top = frustumScale * 1/aspect; - this.scene.cameraO.bottom = -frustumScale * 1/aspect; + this.scene.cameraO.top = frustumScale * 1 / aspect; + this.scene.cameraO.bottom = -frustumScale * 1 / aspect; this.scene.cameraO.updateProjectionMatrix(); this.scene.cameraScreenSpace.top = 1/aspect; From b8b9dc9e238873eb4dfe5067a9221b9b367d604e Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Fri, 26 Jan 2018 17:09:19 +0100 Subject: [PATCH 18/22] various fixes --- examples/ca13.html | 28 ------- examples/heidentor.html | 2 +- src/PotreeRenderer.js | 66 ++++++++++------ src/materials/PointCloudMaterial.js | 24 +----- src/materials/shaders/pointcloud.vs | 52 +++++++++---- src/utils/ClippingTool.js | 35 +++------ src/utils/PolygonClipVolume.js | 116 ++++------------------------ src/utils/VolumeTool.js | 2 +- src/viewer/HQSplatRenderer.js | 4 + src/viewer/viewer.js | 17 ++-- 10 files changed, 116 insertions(+), 230 deletions(-) diff --git a/examples/ca13.html b/examples/ca13.html index f23d850b..06a58bfb 100644 --- a/examples/ca13.html +++ b/examples/ca13.html @@ -100,34 +100,6 @@ //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/heidentor.html b/examples/heidentor.html index 8c52c036..1cbbd640 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -87,7 +87,7 @@ material.size = 1; material.pointSizeType = Potree.PointSizeType.ADAPTIVE; - viewer.setCameraMode(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); diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index 369b9a64..c28376ff 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -638,6 +638,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); @@ -900,31 +941,6 @@ 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); diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js index ad795ca8..cfe365c5 100644 --- a/src/materials/PointCloudMaterial.js +++ b/src/materials/PointCloudMaterial.js @@ -192,6 +192,7 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate this._pointColorType = Potree.PointColorType.RGB; this._useClipBox = false; this.numClipBoxes = 0; + this.clipPolygons = []; this._weighted = false; this._gradient = Potree.Gradients.SPECTRAL; this.gradientTexture = Potree.PointCloudMaterial.generateGradientTexture(this._gradient); @@ -402,7 +403,7 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate defines.push('#define use_clip_box'); } - if(this.numClipPolygons > 0) { + if(this.clipPolygons.length > 0) { defines.push('#define use_clip_polygon'); } @@ -450,30 +451,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(){ diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 0ec75147..37d1bc56 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -47,7 +47,7 @@ uniform int clipMethod; #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; @@ -563,8 +563,13 @@ float getPointSize(){ #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; + + 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; @@ -573,12 +578,20 @@ bool pointInClipPolygon(vec3 point, int 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) ) { + //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; @@ -599,8 +612,8 @@ void doClipping(){ } #endif - bool insideAny = false; - bool insideAll = true; + int clipVolumesCount = 0; + int insideCount = 0; #if defined(num_clipboxes) && num_clipboxes > 0 for(int i = 0; i < num_clipboxes; i++){ @@ -608,19 +621,24 @@ void doClipping(){ 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; - insideAll = insideAll && inside; + + 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);; - insideAny = insideAny || inside; - insideAll = insideAll && inside; + bool inside = pointInClipPolygon(position, i); + + insideCount = insideCount + (inside ? 1 : 0); + clipVolumesCount++; } #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; @@ -673,7 +691,7 @@ void main() { - + #if defined(num_snapshots) && num_snapshots > 0 diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js index eba90801..55ba6a92 100644 --- a/src/utils/ClippingTool.js +++ b/src/utils/ClippingTool.js @@ -89,10 +89,6 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ marker-mid="url(#diamond)" marker-end="url(#diamond)" /> - - - - `); $(domElement.parentElement).append(svg); @@ -109,12 +105,10 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ 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(); + // SVC Screen Line svg.find("polyline").each((index, target) => { let newPoint = svg[0].createSVGPoint(); newPoint.x = e.offsetX; @@ -136,28 +130,17 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ cancel.callback = e => { - 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); - }); + //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(); - 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; } else { this.viewer.scene.removePolygonClipVolume(polyClipVol); 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/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/HQSplatRenderer.js b/src/viewer/HQSplatRenderer.js index db4e70e5..2d9933aa 100644 --- a/src/viewer/HQSplatRenderer.js +++ b/src/viewer/HQSplatRenderer.js @@ -126,6 +126,10 @@ class HQSplatRenderer { 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; diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 88f5d212..4db43546 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1041,7 +1041,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ }); } - update (delta, timestamp) { + update(delta, timestamp){ if(Potree.measureTimings) performance.mark("update-start"); @@ -1212,16 +1212,12 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ this.controls.enabled = true; this.inputHandler.addInputListener(this.controls); } - // + if (this.controls !== null) { this.controls.setScene(scene); this.controls.update(delta); this.scene.cameraP.position.copy(scene.view.position); - //camera.rotation.x = scene.view.pitch; - //camera.rotation.y = scene.view.yaw; - - //camera.lookAt(scene.view.getPivot()); this.scene.cameraP.rotation.order = "ZXY"; this.scene.cameraP.rotation.x = Math.PI / 2 + this.scene.view.pitch; this.scene.cameraP.rotation.z = this.scene.view.yaw; @@ -1262,10 +1258,11 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ })); // clip polygons - let clipPolygons = this.scene.polygonClipVolumes.filter(vol => vol.initialized).map(vol => { - let vp = vol.projMatrix.clone().multiply(vol.viewMatrix); - return {polygon: vol.markersPosWorld, count: vol.markersPosWorld.length, view: vp}; - }); + //let clipPolygons = this.scene.polygonClipVolumes.filter(vol => vol.initialized).map(vol => { + // let vp = vol.projMatrix.clone().multiply(vol.viewMatrix); + // return {polygon: vol.markersPosWorld, count: vol.markersPosWorld.length, view: vp}; + //}); + let clipPolygons = this.scene.polygonClipVolumes.filter(vol => vol.initialized); // set clip volumes in material for(let pointcloud of this.scene.pointclouds){ From 6baeea6529cec03dc6616f818ca7a1005894b3c6 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Sat, 27 Jan 2018 16:05:24 +0100 Subject: [PATCH 19/22] various fixes --- src/PointCloudOctree.js | 3 +- src/Potree.js | 7 ++++- src/PotreeRenderer.js | 12 +++++--- src/materials/PointCloudMaterial.js | 17 +++++++++--- src/utils/ScreenBoxSelectTool.js | 43 +++++++++++++++++------------ src/viewer/PotreeRenderer.js | 36 ++++++++++++------------ src/viewer/Scene.js | 27 ++---------------- src/viewer/sidebar.js | 22 +++++++++++++++ src/viewer/viewer.js | 36 ++++++++---------------- 9 files changed, 110 insertions(+), 93 deletions(-) diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 692d48e3..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(); diff --git a/src/Potree.js b/src/Potree.js index 18c64865..2d7d52a6 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -426,6 +426,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 = []; @@ -467,9 +469,10 @@ 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 && !window.warned125){ + if(pointcloud.material.clipBoxes.length > 0 && !window.warned125){ console.log("TODO"); window.warned125 = true; } @@ -494,6 +497,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 c28376ff..190f8450 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -930,7 +930,12 @@ Potree.Renderer = class Renderer { shader.setUniform("uUseOrthographicCamera", false); } - shader.setUniform1i("clipTask", material.clipTask); + 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) { @@ -942,9 +947,8 @@ Potree.Renderer = class Renderer { } 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/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js index cfe365c5..088a2b64 100644 --- a/src/materials/PointCloudMaterial.js +++ b/src/materials/PointCloudMaterial.js @@ -182,15 +182,24 @@ 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; diff --git a/src/utils/ScreenBoxSelectTool.js b/src/utils/ScreenBoxSelectTool.js index 4b8c131d..03af9052 100644 --- a/src/utils/ScreenBoxSelectTool.js +++ b/src/utils/ScreenBoxSelectTool.js @@ -91,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; @@ -131,24 +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); - - } - - volume.clip = true; + 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/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/Scene.js b/src/viewer/Scene.js index 7757b304..1e736fad 100644 --- a/src/viewer/Scene.js +++ b/src/viewer/Scene.js @@ -20,7 +20,6 @@ Potree.Scene = class extends THREE.EventDispatcher{ this.measurements = []; this.profiles = []; this.volumes = []; - this.clipVolumes = []; this.polygonClipVolumes = []; this.fpControls = null; @@ -138,27 +137,6 @@ Potree.Scene = class extends THREE.EventDispatcher{ } }; - addClipVolume(volume){ - this.clipVolumes.push(volume); - this.dispatchEvent({ - "type": "clip_volume_added", - "scene": this, - "volume": volume - }); - }; - - removeClipVolume(volume){ - let index = this.clipVolumes.indexOf(volume); - if (index > -1) { - this.clipVolumes.splice(index, 1); - this.dispatchEvent({ - "type": "clip_volume_removed", - "scene": this, - "volume": volume - }); - } - }; - addPolygonClipVolume(volume){ this.polygonClipVolumes.push(volume); this.dispatchEvent({ @@ -238,8 +216,9 @@ Potree.Scene = class extends THREE.EventDispatcher{ } removeAllClipVolumes(){ - while(this.clipVolumes.length > 0){ - this.removeClipVolume(this.clipVolumes[0]); + let clipVolumes = this.volumes.filter(volume => volume.clip === true); + for(let clipVolume of clipVolumes){ + this.removeVolume(clipVolume); } while(this.polygonClipVolumes.length > 0){ diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index dc45e1e1..bc4b0f73 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -512,6 +512,28 @@ initSidebar = (viewer) => { )); } + { // REMOVE CLIPPING TOOLS + clippingToolBar.append(createToolIcon( + Potree.resourcePath + "/icons/remove.svg", + "[title]tt.remove_all_measurement", + function(){ + + viewer.scene.removeAllClipVolumes(); + + //if(!(viewer.scene.getActiveCamera() instanceof THREE.OrthographicCamera)){ + // return; + //} + // + //let item = boxSelectTool.startInsertion(); + + //let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements"); + //let jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid); + //$.jstree.reference(jsonNode.id).deselect_all(); + //$.jstree.reference(jsonNode.id).select_node(jsonNode.id); + } + )); + } + } function initClassificationList () { diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 4db43546..5184a194 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1232,40 +1232,28 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ camera.updateMatrixWorld(); camera.matrixWorldInverse.getInverse(camera.matrixWorld); - { // update clip boxes - // ordinary clip boxes (clip planes) - let boxes = this.scene.clipVolumes; + { // update clip boxes + let boxes = []; + + // volumes with clipping enabled + boxes.push(...this.scene.volumes.filter(v => v.clip)); + + // profile segments + for(let profile of this.scene.profiles){ + boxes.push(...profile.boxes); + } let clipBoxes = boxes.map( box => { - box.updateMatrixWorld(); - let boxPosition = box.getWorldPosition(); - let boxMatrixWorld = new THREE.Matrix4().compose(boxPosition, box.getWorldQuaternion(), box.children[0].scale); - let boxInverse = new THREE.Matrix4().getInverse(boxMatrixWorld); - return {inverse: boxInverse, position: boxPosition}; - }); - - // extraordinary clip boxes (volume, profile) - boxes = this.scene.volumes.filter(v => v.clip); - for(let profile of this.scene.profiles){ - boxes = boxes.concat(profile.boxes); - } - - clipBoxes = clipBoxes.concat(boxes.map( box => { box.updateMatrixWorld(); let boxInverse = new THREE.Matrix4().getInverse(box.matrixWorld); let boxPosition = box.getWorldPosition(); return {inverse: boxInverse, position: boxPosition}; - })); + }); - // clip polygons - //let clipPolygons = this.scene.polygonClipVolumes.filter(vol => vol.initialized).map(vol => { - // let vp = vol.projMatrix.clone().multiply(vol.viewMatrix); - // return {polygon: vol.markersPosWorld, count: vol.markersPosWorld.length, view: vp}; - //}); let clipPolygons = this.scene.polygonClipVolumes.filter(vol => vol.initialized); // set clip volumes in material - for(let pointcloud of this.scene.pointclouds){ + for(let pointcloud of this.scene.pointclouds.filter(pc => pc.visible)){ pointcloud.material.setClipBoxes(clipBoxes); pointcloud.material.setClipPolygons(clipPolygons, this.clippingTool.maxPolygonVertices); pointcloud.material.clipTask = this.clipTask; From bcbcafb6fca0239042aa732a717cd1697de4cf9c Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Sun, 28 Jan 2018 17:32:44 +0100 Subject: [PATCH 20/22] various fixes --- .vscode/settings.json | 4 + examples/heidentor.html | 25 +++++ gulpfile.js | 1 + resources/icons/copy.svg | 106 ++++++++++++++++++ src/KeyCodes.js | 3 + src/Potree.js | 64 ++++++++++- src/PotreeRenderer.js | 6 ++ src/materials/shaders/pointcloud.vs | 8 ++ src/navigation/EarthControls.js | 2 +- src/navigation/InputHandler.js | 4 +- src/utils.js | 40 +++++++ src/viewer/PropertiesPanel.js | 160 +++++++++++++++++++++++----- src/viewer/potree.css | 8 +- src/viewer/sidebar.js | 29 ++++- src/viewer/viewer.js | 27 ++++- 15 files changed, 448 insertions(+), 39 deletions(-) create mode 100644 resources/icons/copy.svg create mode 100644 src/KeyCodes.js 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/heidentor.html b/examples/heidentor.html index 1cbbd640..2f92f2aa 100644 --- a/examples/heidentor.html +++ b/examples/heidentor.html @@ -99,6 +99,31 @@ //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/gulpfile.js b/gulpfile.js index 309ba9cc..34760b05 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,6 +16,7 @@ var server; var paths = { potree : [ + "src/KeyCodes.js", "src/extensions/EventDispatcher.js", "src/extensions/PerspectiveCamera.js", "src/extensions/OrthographicCamera.js", 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 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + 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/Potree.js b/src/Potree.js index 2d7d52a6..7b44a542 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -472,9 +472,67 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ visible = visible && !(numVisiblePointsInPointclouds.get(pointcloud) + node.getNumPoints() > pointcloud.pointBudget); visible = visible && level < maxLevel; - if(pointcloud.material.clipBoxes.length > 0 && !window.warned125){ - console.log("TODO"); - window.warned125 = true; + 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 = ["r", "r0", "r06", "r060"].includes(node.name); diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index 190f8450..65b64a15 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -622,6 +622,12 @@ Potree.Renderer = class Renderer { let level = node.getLevel(); + if(node.debug){ + shader.setUniform("uDebug", true); + }else{ + shader.setUniform("uDebug", false); + } + // TODO consider passing matrices in an array to avoid uniformMatrix4fv overhead const lModel = shader.uniformLocations["modelMatrix"]; diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 37d1bc56..f1cd1bb6 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -25,6 +25,8 @@ uniform float fov; uniform float near; uniform float far; +uniform bool uDebug; + uniform bool uUseOrthographicCamera; uniform float uOrthoWidth; uniform float uOrthoHeight; @@ -768,4 +770,10 @@ void main() { 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; + } + } 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 ee2eb8ae..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 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/viewer/PropertiesPanel.js b/src/viewer/PropertiesPanel.js index 950199d6..3d81e8a4 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); @@ -371,14 +396,19 @@ class VolumePanel extends MeasurePanel{ - + + `); + 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); }); @@ -468,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`); @@ -547,6 +582,75 @@ 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.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{ @@ -566,6 +670,8 @@ Potree.PropertiesPanel = class PropertriesPanel{ if(this.object === object){ return; } + + this.object = object; for(let task of this.cleanupTasks){ task(); @@ -577,11 +683,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); } - - } @@ -1101,9 +1205,11 @@ Potree.PropertiesPanel = class PropertriesPanel{ let panel = new Panel(this.scene, object, this); this.container.append(panel.elContent); + } - - + setCamera(camera){ + let panel = new CameraPanel(this.viewer, this); + this.container.append(panel.elContent); } } \ No newline at end of file diff --git a/src/viewer/potree.css b/src/viewer/potree.css index 664aef4f..c36c2d79 100644 --- a/src/viewer/potree.css +++ b/src/viewer/potree.css @@ -86,7 +86,8 @@ top: 10px; left: 50%; transform: translateX(-50%); - text-align: center + text-align: center; + z-index: 1000; } #potree_sidebar_container{ @@ -334,6 +335,11 @@ body{ /*background-color: rgba(0, 0, 0, 0.4);*/ } +.propertypanel_content{ + padding: 5px 15px 5px 10px; + /*background-color: rgba(0, 0, 0, 0.4);*/ +} + .measurement_value_table{ width: 100%; } diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index bc4b0f73..3b7d12fe 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -219,18 +219,29 @@ initSidebar = (viewer) => { tree.jstree("check_node", annotationsID); tree.jstree("check_node", otherID); - tree.on('create_node.jstree', function(e, data) { + tree.on('create_node.jstree', function(e, data){ tree.jstree("open_all"); }); - tree.on("select_node.jstree", function (e, data) { + tree.on("select_node.jstree", function(e, data){ let object = data.node.data; propertiesPanel.set(object); + viewer.inputHandler.deselectAll(); + if(object instanceof Potree.Volume){ - viewer.inputHandler.deselectAll(); viewer.inputHandler.toggleSelection(object); } + + $(viewer.renderer.domElement).focus(); + }); + + tree.on("deselect_node.jstree", function(e, data){ + propertiesPanel.set(null); + }); + + tree.on("delete_node.jstree", function(e, data){ + propertiesPanel.set(null); }); tree.on('dblclick','.jstree-anchor', function (e) { @@ -371,10 +382,16 @@ initSidebar = (viewer) => { tree.jstree("delete_node", jsonNode.id); }; - + let onProfileRemoved = (e) => { + let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements"); + let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.profile.uuid); + + tree.jstree("delete_node", jsonNode.id); + }; viewer.scene.addEventListener("measurement_removed", onMeasurementRemoved); viewer.scene.addEventListener("volume_removed", onVolumeRemoved); + viewer.scene.addEventListener("profile_removed", onProfileRemoved); { let annotationIcon = `${Potree.resourcePath}/icons/target.svg`; @@ -404,6 +421,10 @@ initSidebar = (viewer) => { onProfileAdded({profile: profile}); } + { + createNode(otherID, "Camera", null, new THREE.Camera()); + } + viewer.addEventListener("scene_changed", (e) => { propertiesPanel.setScene(e.scene); diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 5184a194..763ebd5b 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1232,6 +1232,31 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ camera.updateMatrixWorld(); camera.matrixWorldInverse.getInverse(camera.matrixWorld); + { + if(this._previousCamera === undefined){ + this._previousCamera = this.scene.getActiveCamera().clone(); + this._previousCamera.rotation.copy(this.scene.getActiveCamera()); + } + + if(!this._previousCamera.matrixWorld.equals(camera.matrixWorld)){ + this.dispatchEvent({ + type: "camera_changed", + previous: this._previousCamera, + camera: camera + }); + }else if(!this._previousCamera.projectionMatrix.equals(camera.matrixWorld)){ + this.dispatchEvent({ + type: "camera_changed", + previous: this._previousCamera, + camera: camera + }); + } + + this._previousCamera = this.scene.getActiveCamera().clone(); + this._previousCamera.rotation.copy(this.scene.getActiveCamera()); + + } + { // update clip boxes let boxes = []; @@ -1247,7 +1272,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ box.updateMatrixWorld(); let boxInverse = new THREE.Matrix4().getInverse(box.matrixWorld); let boxPosition = box.getWorldPosition(); - return {inverse: boxInverse, position: boxPosition}; + return {box: box, inverse: boxInverse, position: boxPosition}; }); let clipPolygons = this.scene.polygonClipVolumes.filter(vol => vol.initialized); From dc6b777b0dba11be953a33c4a7c3e46ba15227d8 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Mon, 29 Jan 2018 10:58:21 +0100 Subject: [PATCH 21/22] spacing --- src/Potree.js | 2 + src/PotreeRenderer.js | 14 ++- src/loader/BinaryLoader.js | 4 + src/loader/PointAttributes.js | 5 + src/materials/shaders/pointcloud.fs | 84 +++++++------ src/materials/shaders/pointcloud.vs | 46 +++++--- src/viewer/PropertiesPanel.js | 9 +- src/viewer/RepRenderer.js | 15 +-- src/viewer/sidebar.js | 2 +- src/viewer/viewer.js | 9 +- src/workers/BinaryDecoderWorker.js | 176 +++++++++++++++++++--------- 11 files changed, 239 insertions(+), 127 deletions(-) diff --git a/src/Potree.js b/src/Potree.js index 7b44a542..a8cb1408 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -25,6 +25,8 @@ Potree.webgl = { vbos: {} }; +Potree.debug = {}; + Potree.scriptPath = null; if (document.currentScript.src) { Potree.scriptPath = new URL(document.currentScript.src + '/..').href; diff --git a/src/PotreeRenderer.js b/src/PotreeRenderer.js index 65b64a15..8b566183 100644 --- a/src/PotreeRenderer.js +++ b/src/PotreeRenderer.js @@ -137,6 +137,7 @@ Potree.attributeLocations = { "pointSourceID": 6, "indices": 7, "normal": 8, + "spacing": 9, }; Potree.Shader = class Shader { @@ -603,6 +604,12 @@ 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", // ] @@ -628,6 +635,12 @@ Potree.Renderer = class Renderer { 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"]; @@ -926,7 +939,6 @@ Potree.Renderer = class Renderer { 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); diff --git a/src/loader/BinaryLoader.js b/src/loader/BinaryLoader.js index 4ca0ee1b..26b9e0bd 100644 --- a/src/loader/BinaryLoader.js +++ b/src/loader/BinaryLoader.js @@ -89,6 +89,9 @@ Potree.BinaryLoader.prototype.parse = function (node, buffer) { 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); } } @@ -117,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/PointAttributes.js b/src/loader/PointAttributes.js index 643a8a58..ddf47576 100644 --- a/src/loader/PointAttributes.js +++ b/src/loader/PointAttributes.js @@ -16,6 +16,7 @@ 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 @@ -115,6 +116,10 @@ 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/shaders/pointcloud.fs b/src/materials/shaders/pointcloud.fs index 2fce5528..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) diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index f1cd1bb6..c27b62d6 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -13,6 +13,7 @@ attribute float returnNumber; attribute float numberOfReturns; attribute float pointSourceID; attribute vec4 indices; +attribute float spacing; uniform mat4 modelMatrix; uniform mat4 modelViewMatrix; @@ -63,6 +64,7 @@ uniform float uOctreeSize; uniform vec3 uBBSize; uniform float uLevel; uniform float uVNStart; +uniform bool uIsLeafNode; uniform vec3 uColor; uniform float uOpacity; @@ -101,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; @@ -533,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 @@ -676,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); @@ -695,14 +701,14 @@ void main() { - #if defined(num_snapshots) && num_snapshots > 0 + //#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 + // 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 @@ -776,4 +782,10 @@ void main() { 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/viewer/PropertiesPanel.js b/src/viewer/PropertiesPanel.js index 3d81e8a4..ada23f86 100644 --- a/src/viewer/PropertiesPanel.js +++ b/src/viewer/PropertiesPanel.js @@ -614,7 +614,7 @@ class CameraPanel{ - + @@ -628,6 +628,13 @@ class CameraPanel{ 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(); diff --git a/src/viewer/RepRenderer.js b/src/viewer/RepRenderer.js index fcb9c5ae..2448806f 100644 --- a/src/viewer/RepRenderer.js +++ b/src/viewer/RepRenderer.js @@ -31,7 +31,7 @@ class RepRenderer { }; this.history = { - maxSnapshots: 5, + maxSnapshots: 10, snapshots: [], version: 0 }; @@ -142,10 +142,7 @@ class RepRenderer { viewer.renderer.clear(); } - viewer.measuringTool.update(); - viewer.profileTool.update(); viewer.transformationTool.update(); - viewer.volumeTool.update(); viewer.renderer.render(viewer.scene.scene, camera); @@ -217,10 +214,13 @@ class RepRenderer { viewer.renderer.clearTarget(snap.target, true, true, true); viewer.renderer.setRenderTarget(snap.target); + for(const octree of viewer.scene.pointclouds){ octree.material.snapEnabled = false; octree.material.needsUpdate = true; + + let from = this.history.version * (octree.visibleNodes.length / this.history.maxSnapshots); let to = (this.history.version + 1) * (octree.visibleNodes.length / this.history.maxSnapshots); @@ -273,7 +273,7 @@ class RepRenderer { octree.material.needsUpdate = true; } - let nodes = octree.visibleNodes.slice(0, 5); + let nodes = octree.visibleNodes.slice(0, 50); //let nodes = octree.visibleNodes; viewer.pRenderer.renderOctree(octree, nodes, camera, this.rtColor, {vnTextureNodes: nodes}); @@ -319,11 +319,8 @@ class RepRenderer { viewer.renderer.clearDepth(); viewer.renderer.render(viewer.controls.sceneControls, camera); - viewer.renderer.render(viewer.measuringTool.sceneMeasurement, camera); - viewer.renderer.render(viewer.volumeTool.sceneVolume, camera); viewer.renderer.render(viewer.clippingTool.sceneVolume, camera); - viewer.renderer.render(viewer.profileTool.sceneProfile, camera); - viewer.renderer.render(viewer.transformationTool.sceneTransform, camera); + viewer.renderer.render(viewer.transformationTool.scene, camera); viewer.renderer.setViewport(viewer.renderer.domElement.clientWidth - viewer.navigationCube.width, viewer.renderer.domElement.clientHeight - viewer.navigationCube.width, diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index 3b7d12fe..85e18782 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -654,7 +654,7 @@ initSidebar = (viewer) => { $('#sldPointBudget').slider({ value: viewer.getPointBudget(), min: 100 * 1000, - max: 5 * 1000 * 1000, + max: 10 * 1000 * 1000, step: 1000, slide: function (event, ui) { viewer.setPointBudget(ui.value); } }); diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 763ebd5b..d6e3d42c 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1244,7 +1244,7 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ previous: this._previousCamera, camera: camera }); - }else if(!this._previousCamera.projectionMatrix.equals(camera.matrixWorld)){ + }else if(!this._previousCamera.projectionMatrix.equals(camera.projectionMatrix)){ this.dispatchEvent({ type: "camera_changed", previous: this._previousCamera, @@ -1319,7 +1319,12 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ try{ - if(this.useHQ){ + if(this.useRep){ + if (!this.repRenderer) { + this.repRenderer = new RepRenderer(this); + } + this.repRenderer.render(this.renderer); + }else if(this.useHQ){ if (!this.hqRenderer) { this.hqRenderer = new HQSplatRenderer(this); } diff --git a/src/workers/BinaryDecoderWorker.js b/src/workers/BinaryDecoderWorker.js index c9eee6ff..24804548 100644 --- a/src/workers/BinaryDecoderWorker.js +++ b/src/workers/BinaryDecoderWorker.js @@ -46,6 +46,7 @@ onmessage = function (event) { let scale = event.data.scale; let spacing = event.data.spacing; let hasChildren = event.data.hasChildren; + let name = event.data.name; let tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY ]; let tightBoxMax = [ Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY ]; @@ -207,72 +208,141 @@ onmessage = function (event) { inOffset += pointAttribute.byteSize; } - //let estimatedSpacing; - //if(hasChildren || true){ - // estimatedSpacing = spacing; - //}else{ - // performance.mark("spacing-start"); + //let debugNodes = ["r026", "r0226","r02274"]; + //if(debugNodes.includes(name)){ + if(false){ + console.log("estimate spacing!"); - // let knnCount = 5; - // let n = 5; - // let choice = []; - // for(let i = 0; i < Math.min(n, numPoints); i++){ - // let index = parseInt(Math.random() * numPoints); - // let x = iView.getFloat32(index * iStride + 0, true); - // let y = iView.getFloat32(index * iStride + 4, true); - // let z = iView.getFloat32(index * iStride + 8, true); + let sparseGrid = new Map(); + let gridSize = 16; - // choice.push({ - // knn: [], - // position: [x, y, z] - // }); - // } + let tightBoxSize = tightBoxMax.map( (a, i) => a - tightBoxMin[i]); + let cubeLength = Math.max(...tightBoxSize); + let cube = { + min: tightBoxMin, + max: tightBoxMin.map(v => v + cubeLength) + }; - // let squaredDistanceBetween = (v1, v2) => { - // let dx = v1[0] - v2[0]; - // let dy = v1[1] - v2[1]; - // let dz = v1[2] - v2[2]; + let positions = new Float32Array(attributeBuffers[Potree.PointAttribute.POSITION_CARTESIAN.name].buffer); + for(let i = 0; i < numPoints; i++){ + let x = positions[3 * i + 0]; + let y = positions[3 * i + 1]; + let z = positions[3 * i + 2]; - // return dx * dx + dy * dy + dz * dz; - // }; + let ix = Math.max(0, Math.min(gridSize * (x - cube.min[0]) / cubeLength, gridSize - 1)); + let iy = Math.max(0, Math.min(gridSize * (y - cube.min[1]) / cubeLength, gridSize - 1)); + let iz = Math.max(0, Math.min(gridSize * (z - cube.min[2]) / cubeLength, gridSize - 1)); - // for(let i = 0; i < numPoints; i++){ - // - // let pos = [ - // iView.getFloat32(i * iStride + 0, true), - // iView.getFloat32(i * iStride + 4, true), - // iView.getFloat32(i * iStride + 8, true), - // ]; + ix = Math.floor(ix); + iy = Math.floor(iy); + iz = Math.floor(iz); - // for(let point of choice){ + let cellIndex = ix | (iy << 8) | (iz << 16); + + if(!sparseGrid.has(cellIndex)){ + sparseGrid.set(cellIndex, []); + } - // let distance = squaredDistanceBetween(pos, point.position); + sparseGrid.get(cellIndex).push(i); + } - // if(distance > 0){ - // point.knn.push(distance); - // point.knn.sort(); - // point.knn = point.knn.slice(0, knnCount); - // } - // } - // } + let kNearest = (pointIndex, candidates, numNearest) => { + + let x = positions[3 * pointIndex + 0]; + let y = positions[3 * pointIndex + 1]; + let z = positions[3 * pointIndex + 2]; - // { - // let knns = []; - // for(let knn of choice.map(point => point.knn)){ - // knns.push(...knn); - // } - // knns = knns.map(value => Math.sqrt(value)); + let candidateDistances = []; - // knns.sort(); - // let medianPos = Math.floor(knns.length / 2); - // let medianSpacing = knns[medianPos]; + for(let candidateIndex of candidates){ + if(candidateIndex === pointIndex){ + continue; + } - // estimatedSpacing = Math.min(medianSpacing, spacing); - // } + let cx = positions[3 * candidateIndex + 0]; + let cy = positions[3 * candidateIndex + 1]; + let cz = positions[3 * candidateIndex + 2]; + + let squaredDistance = (cx - x) ** 2 + (cy - y) ** 2 + (cz - z) ** 2; + + candidateDistances.push({candidateInde: candidateIndex, squaredDistance: squaredDistance}); + } + + candidateDistances.sort( (a, b) => a.squaredDistance - b.squaredDistance); + let nearest = candidateDistances.slice(0, numNearest); + + return nearest; + }; + + let meansBuffer = new ArrayBuffer(numPoints * 4); + let means = new Float32Array(meansBuffer); + + for(let [key, value] of sparseGrid){ + + for(let pointIndex of value){ + + if(value.length === 1){ + means[pointIndex] = 0; + continue; + } + + let [ix, iy, iz] = [(key & 255), ((key >> 8) & 255), ((key >> 16) & 255)]; + + //let candidates = value; + let candidates = []; + for(let i of [-1, 0, 1]){ + for(let j of [-1, 0, 1]){ + for(let k of [-1, 0, 1]){ + let cellIndex = (ix + i) | ((iy + j) << 8) | ((iz + k) << 16); + + if(sparseGrid.has(cellIndex)){ + candidates.push(...sparseGrid.get(cellIndex)); + } + } + } + } + + + let nearestNeighbors = kNearest(pointIndex, candidates, 10); + + let sum = 0; + for(let neighbor of nearestNeighbors){ + sum += Math.sqrt(neighbor.squaredDistance); + } + + //let mean = sum / nearestNeighbors.length; + let mean = Math.sqrt(Math.max(...nearestNeighbors.map(n => n.squaredDistance))); + + if(Number.isNaN(mean)){ + debugger; + } + + + means[pointIndex] = mean; + + } + + } + + + let maxMean = Math.max(...means); + let minMean = Math.min(...means); + + //let colors = new Uint8Array(attributeBuffers[Potree.PointAttribute.COLOR_PACKED.name].buffer); + //for(let i = 0; i < numPoints; i++){ + // let v = means[i] / 0.05; + + // colors[4 * i + 0] = 255 * v; + // colors[4 * i + 1] = 255 * v; + // colors[4 * i + 2] = 255 * v; + //} + + attributeBuffers[Potree.PointAttribute.SPACING.name] = { buffer: meansBuffer, attribute: Potree.PointAttribute.SPACING }; + + + } - // performance.mark("spacing-end"); - //} { // add indices let buff = new ArrayBuffer(numPoints * 4); From b2903dd02133a2ee50f95839a2b1f256f654f1e4 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Tue, 30 Jan 2018 18:18:33 +0100 Subject: [PATCH 22/22] fixes and polishing --- src/Potree.js | 4 +-- src/ProfileRequest.js | 50 ++++++++++++----------------- src/materials/shaders/pointcloud.vs | 4 +-- src/viewer/potree.css | 23 ++++++++++++- src/viewer/profile.html | 7 ++-- src/viewer/profile.js | 3 ++ src/viewer/sidebar.html | 2 ++ src/viewer/sidebar.js | 44 ++++++++----------------- 8 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/Potree.js b/src/Potree.js index a8cb1408..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); 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/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index c27b62d6..70d90a57 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -784,8 +784,8 @@ void main() { //vColor = vec3(1.0, 1.0, 1.0) * spacing / 0.05; - if(getLOD() != uLevel){ + //if(getLOD() != uLevel){ //gl_Position = vec4(100.0, 100.0, 100.0, 1.0); - } + //} } diff --git a/src/viewer/potree.css b/src/viewer/potree.css index c36c2d79..d32fe571 100644 --- a/src/viewer/potree.css +++ b/src/viewer/potree.css @@ -428,7 +428,7 @@ body{ } .ui-widget-content{ - color: var(--font-color) !important; + //color: var(--font-color) !important; } .accordion > h3{ @@ -465,6 +465,23 @@ body{ transition: top .35s, left .35s, bottom .35s, right .35s, width .35s; } +#profile_window{ + background-color: var(--bg-color); +} + +#profile_titlebar{ + background-color: var(--bg-color-2); + color: var(--font-color-2); + text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; + font-size: 1em; + font-weight: bold; +} + +#profile_window_title{ + position: absolute; + margin: 5px; +} + .profile-container-button{ cursor: pointer; } @@ -615,6 +632,10 @@ body{ */ +.ui-spinner-input{ + color: black; +} + .jstree-themeicon-custom{ background-size: 16px !important; } diff --git a/src/viewer/profile.html b/src/viewer/profile.html index 82b3c7ef..855216fc 100644 --- a/src/viewer/profile.html +++ b/src/viewer/profile.html @@ -7,10 +7,13 @@ display: none; box-sizing: border-box; z-index:10000">
    - + + + - + +
    diff --git a/src/viewer/profile.js b/src/viewer/profile.js index 2969e3e3..ba45e09b 100644 --- a/src/viewer/profile.js +++ b/src/viewer/profile.js @@ -206,6 +206,9 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher { let lasIcon = `${Potree.resourcePath}/icons/file_las_3d.svg`; $('#potree_download_las_icon').attr('src', lasIcon); + let closeIcon = `${Potree.resourcePath}/icons/close.svg`; + $('#closeProfileContainer').attr("src", closeIcon); + this.initTHREE(); this.initSVG(); this.initListeners(); diff --git a/src/viewer/sidebar.html b/src/viewer/sidebar.html index 441f1338..6cb6a4f2 100644 --- a/src/viewer/sidebar.html +++ b/src/viewer/sidebar.html @@ -43,12 +43,14 @@
    Other
    +
  • :
  • diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index 85e18782..0315a6ed 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -642,14 +642,6 @@ initSidebar = (viewer) => { } function initAppearance () { - // $( "#optQuality" ).selectmenu(); - - // $("#optQuality").val(viewer.getQuality()).selectmenu("refresh") - // $("#optQuality").selectmenu({ - // change: function(event, ui){ - // viewer.setQuality(ui.item.value); - // } - // }); $('#sldPointBudget').slider({ value: viewer.getPointBudget(), @@ -693,16 +685,6 @@ initSidebar = (viewer) => { $('#sldFOV').slider({value: viewer.getFOV()}); }); - // viewer.addEventListener("quality_changed", e => { - // - // let name = viewer.quality; - // - // $( "#optQuality" ) - // .selectmenu() - // .val(name) - // .selectmenu("refresh"); - // }); - viewer.addEventListener('edl_radius_changed', function (event) { $('#lblEDLRadius')[0].innerHTML = viewer.getEDLRadius().toFixed(1); $('#sldEDLRadius').slider({value: viewer.getEDLRadius()}); @@ -853,21 +835,21 @@ initSidebar = (viewer) => { $('#lblMinNodeSize').html(parseInt(viewer.getMinNodeSize())); } - { - let elSplatQuality = $("#splat_quality_options"); - elSplatQuality.selectgroup({title: "Splat Quality"}); + //{ + // let elSplatQuality = $("#splat_quality_options"); + // elSplatQuality.selectgroup({title: "Splat Quality"}); - elSplatQuality.find("input").click( (e) => { - if(e.target.value === "standard"){ - viewer.useHQ = false; - }else if(e.target.value === "hq"){ - viewer.useHQ = true; - } - }); + // elSplatQuality.find("input").click( (e) => { + // if(e.target.value === "standard"){ + // viewer.useHQ = false; + // }else if(e.target.value === "hq"){ + // viewer.useHQ = true; + // } + // }); - let currentQuality = viewer.useHQ ? "hq" : "standard"; - elSplatQuality.find(`input[value=${currentQuality}]`).trigger("click"); - } + // let currentQuality = viewer.useHQ ? "hq" : "standard"; + // elSplatQuality.find(`input[value=${currentQuality}]`).trigger("click"); + //} $('#show_bounding_box').click(() => { viewer.setShowBoundingBox($('#show_bounding_box').prop("checked"));