X, Y, Z aligned clip volumes

This commit is contained in:
Lukas Gersthofer 2017-06-26 11:18:57 +02:00
parent 1f49ab01a4
commit 1c42315313
5 changed files with 89 additions and 9 deletions

View File

@ -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

View File

@ -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
};

View File

@ -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);

View File

@ -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});
}
));

View File

@ -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 => {