From 9029f1d9d94f619175b4bffbb930fa647ebf45af Mon Sep 17 00:00:00 2001 From: Lukas Gersthofer Date: Mon, 17 Jul 2017 11:10:44 +0200 Subject: [PATCH] rendering extruded clip polygon edges --- TODO.txt | 3 +-- src/utils/ClippingTool.js | 5 ++--- src/utils/PolygonClipVolume.js | 40 +++++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/TODO.txt b/TODO.txt index c38fc1e2..e7ed844f 100644 --- a/TODO.txt +++ b/TODO.txt @@ -10,7 +10,6 @@ TODO clipping: - polygon clipping - vertices are distorted at the boundaries of the render area (caused by perspective projection) - picking with ortho cameras (fix ortho camera picking first) - - TODO: - + render extruded clip polygon + - EDL renderer: no depth of volumes stored -> no depth test possible - clip planes - EDL renderer: no depth of volumes stored -> no depth test possible diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js index c48a69fd..2e0fc143 100644 --- a/src/utils/ClippingTool.js +++ b/src/utils/ClippingTool.js @@ -120,9 +120,7 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ this.viewer.inputHandler.startDragging(clipVolume); } else if(type == "polygon") { - let camera = this.viewer.scene.getActiveCamera(); - camera.updateMatrixWorld(); - let polyClipVol = new Potree.PolygonClipVolume(camera.matrixWorldInverse, camera.projectionMatrix); + let polyClipVol = new Potree.PolygonClipVolume(this.viewer.scene.getActiveCamera().clone()); this.dispatchEvent({"type": "start_inserting_clipping_volume"}); @@ -161,6 +159,7 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ } this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true); this.viewer.removeEventListener("cancel_insertions", cancel.callback); + polyClipVol.addExtrudedEdges(); this.viewer.inputHandler.enabled = true; }; diff --git a/src/utils/PolygonClipVolume.js b/src/utils/PolygonClipVolume.js index 0507a641..0f828d27 100644 --- a/src/utils/PolygonClipVolume.js +++ b/src/utils/PolygonClipVolume.js @@ -1,16 +1,19 @@ Potree.PolygonClipVolume = class extends THREE.Object3D{ - constructor(viewMatrix, projMatrix){ + constructor(camera){ super(); this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1; this.name = "polygon_clip_volume_" + this.constructor.counter; - this.viewMatrix = viewMatrix.clone(); - this.projMatrix = projMatrix.clone(); + this.camera = camera; + this.camera.updateMatrixWorld(); + this.viewMatrix = this.camera.matrixWorldInverse.clone(); + this.projMatrix = this.camera.projectionMatrix.clone(); this.markers = []; this.edges = []; + this.extrudedEdges = []; this.sphereGeometry = new THREE.SphereGeometry(0.01, 5, 5); this.color = new THREE.Color( 0xff0000 ); this.initialized = false; @@ -106,4 +109,35 @@ Potree.PolygonClipVolume = class extends THREE.Object3D{ } } + 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(frontMarker, backMarker); + lineGeometry.colors.push(this.color, this.color, this.color); + let lineMaterial = new THREE.LineBasicMaterial( { + linewidth: 1 + }); + lineMaterial.depthWrite = false; + lineMaterial.depthTest = true; + let edge = new THREE.Line(lineGeometry, lineMaterial); + edge.visible = true; + + this.add(edge); + this.extrudedEdges.push(edge); + } + } + }; \ No newline at end of file