diff --git a/TODO.txt b/TODO.txt index d35cfe00..47dac434 100644 --- a/TODO.txt +++ b/TODO.txt @@ -10,6 +10,4 @@ TODO clipping: - polygon clipping (define polygon in screenspace) - profile clipping - resize after 1st click - - x, y, z planes - - do clipping (shader) - properties \ No newline at end of file diff --git a/src/utils/ClipVolume.js b/src/utils/ClipVolume.js index 43820ded..b15db66c 100644 --- a/src/utils/ClipVolume.js +++ b/src/utils/ClipVolume.js @@ -1,12 +1,25 @@ + Potree.ClipVolume = class extends THREE.Object3D{ - constructor(args = {}){ + constructor(axis){ super(); this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1; this.name = "clip_volume_" + this.constructor.counter; + + this.volWidth = 0.1; + + if(axis != -1) { + this.scale.set(1, 1, 1); + if(axis == Potree.ClipVolume.Axis.X) + this.scale.x = this.volWidth; + else if(axis == Potree.ClipVolume.Axis.Y) + this.scale.y = this.volWidth; + else if(axis == Potree.ClipVolume.Axis.Z) + this.scale.z = this.volWidth; + } let boxGeometry = new THREE.BoxGeometry(1, 1, 1); boxGeometry.computeBoundingBox(); @@ -110,4 +123,10 @@ Potree.ClipVolume = class extends THREE.Object3D{ }); } }; +}; + +Potree.ClipVolume.Axis = { + X: 0, + Y: 1, + Z: 2 }; \ No newline at end of file diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js index ba302c94..0f3af363 100644 --- a/src/utils/ClippingTool.js +++ b/src/utils/ClippingTool.js @@ -53,8 +53,12 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ viewer.dispatchEvent({"type": "clipper.clipInside_changed", "viewer": viewer}); } - startInsertion() { - let clipVolume = new Potree.ClipVolume(); + startInsertion(args = {}) { + let axis = -1; + if(args.axis + 1) + axis = args.axis; + let clipVolume = new Potree.ClipVolume(axis); + this.dispatchEvent({"type": "start_inserting_clipping_volume"}); this.viewer.scene.addClipVolume(clipVolume); @@ -88,6 +92,8 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ clipVolume.removeEventListener("drop", drop); cancel.callback(); + + //this.dispatchEvent({"type": "start_resizing_clipping_volume"}); }; cancel.callback = e => { @@ -95,6 +101,46 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ clipVolume.removeEventListener("drop", drop); this.viewer.removeEventListener("cancel_insertions", cancel.callback); }; + + + /*let cancel2 = { + callback: null + }; + + let drag2 = e => { + let mouse = e.drag.end; + + let nmouse = { + x: (mouse.x / this.viewer.renderer.domElement.clientWidth ) * 2 - 1, + y: - (mouse.y / this.viewer.renderer.domElement.clientHeight ) * 2 + 1 + }; + + let camera = this.viewer.scene.getActiveCamera(); + let mouseWS = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 ); + mouseWS.unproject(camera); + + let distance = clipVolume.position.distanceTo(mouseWS); + + clipVolume.scale.set(distance, distance, distance); + }; + + let drop2 = e => { + cancel2.callback(); + }; + + cancel2.callback = e => { + clipVolume.removeEventListener("drag", drag2); + clipVolume.removeEventListener("drop", drop2); + this.viewer.removeEventListener("cancel_insertions", cancel2.callback); + }; + + this.addEventListener("start_resizing_clipping_volume", function(event) { + clipVolume.addEventListener("drag", drag2); + clipVolume.addEventListener("drop", drop2); + this.viewer.addEventListener("cancel_insertions", cancel2.callback); + + this.viewer.inputHandler.startDragging(clipVolume); + });*/ clipVolume.addEventListener("drag", drag); clipVolume.addEventListener("drop", drop); diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index e0d757a4..7f039798 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -1477,7 +1477,23 @@ function initClippingTool() { Potree.resourcePath + "/icons/profile.svg", "[title]tt.height_profile", function(){ - viewer.clippingTool.startInsertion(); + viewer.clippingTool.startInsertion({axis: Potree.ClipVolume.Axis.X}); + } + )); + + clippingToolBar.append(createToolIcon( + Potree.resourcePath + "/icons/profile.svg", + "[title]tt.height_profile", + function(){ + viewer.clippingTool.startInsertion({axis: Potree.ClipVolume.Axis.Y}); + } + )); + + clippingToolBar.append(createToolIcon( + Potree.resourcePath + "/icons/profile.svg", + "[title]tt.height_profile", + function(){ + viewer.clippingTool.startInsertion({axis: Potree.ClipVolume.Axis.Z}); } )); diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 3252bc1f..1d588062 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -1508,10 +1508,11 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{ //let boxes = this.scene.profiles.reduce( (a, b) => {return a.boxes.concat(b.boxes)}, []); //boxes = boxes.concat(this.scene.volumes.filter(v => v.clip)); - let boxes = this.scene.volumes.filter(v => v.clip); - for(let profile of this.scene.profiles){ + //let boxes = this.scene.volumes.filter(v => v.clip); + let boxes = this.scene.clipVolumes; + /*for(let profile of this.scene.profiles){ boxes = boxes.concat(profile.boxes); - } + }*/ let clipBoxes = boxes.map( box => {