clipping tools

This commit is contained in:
m-schuetz 2018-01-19 15:11:49 +01:00
parent bdb6f8e316
commit b62e7fc44f
9 changed files with 151 additions and 51 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -353,15 +353,24 @@ class VolumePanel extends MeasurePanel{
<span style="font-weight: bold">Volume: </span>
<span id="measurement_volume"></span>
<!--
<li>
<label style="whitespace: nowrap">
<input id="volume_show" type="checkbox"/>
<span>show volume</span>
</label>
</li>-->
<li>
<label style="whitespace: nowrap">
<input id="volume_clip" type="checkbox"/>
<span>clip volume</span>
<span>make clip volume</span>
</label>
</li>
<!-- ACTIONS -->
<input id="volume_reset_orientation" type="button" value="reset orientation"/>
<!--<div style="display: flex; margin-top: 12px">
<span></span>
<span style="flex-grow: 1"></span>
@ -370,11 +379,20 @@ class VolumePanel extends MeasurePanel{
</div>
`);
this.elContent.find("#volume_reset_orientation").click(() => {
measurement.rotation.set(0, 0, 0);
});
this.elCheckClip = this.elContent.find('#volume_clip');
this.elCheckClip.click(event => {
this.measurement.clip = event.target.checked;
});
this.elCheckShow = this.elContent.find('#volume_show');
this.elCheckShow.click(event => {
this.measurement.visible = event.target.checked;
});
this.propertiesPanel.addVolatileListener(measurement, "position_changed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "orientation_changed", this._update);
this.propertiesPanel.addVolatileListener(measurement, "scale_changed", this._update);
@ -423,6 +441,7 @@ class VolumePanel extends MeasurePanel{
}
this.elCheckClip.prop("checked", this.measurement.clip);
this.elCheckShow.prop("checked", this.measurement.visible);
}
}

View File

@ -129,6 +129,7 @@ Potree.Scene = class extends THREE.EventDispatcher{
let index = this.volumes.indexOf(volume);
if (index > -1) {
this.volumes.splice(index, 1);
this.dispatchEvent({
'type': 'volume_removed',
'scene': this,

View File

@ -44,7 +44,8 @@ Potree.View = class {
set direction (dir) {
if(dir.x === dir.y){
//if(dir.x === dir.y){
if(dir.x === 0 && dir.y === 0){
this.pitch = Math.PI / 2 * Math.sign(dir.z);
}else{
let yaw = Math.atan2(dir.y, dir.x) - Math.PI / 2;

View File

@ -226,6 +226,11 @@ initSidebar = (viewer) => {
tree.on("select_node.jstree", function (e, data) {
let object = data.node.data;
propertiesPanel.set(object);
if(object instanceof Potree.Volume){
viewer.inputHandler.deselectAll();
viewer.inputHandler.toggleSelection(object);
}
});
tree.on('dblclick','.jstree-anchor', function (e) {
@ -320,7 +325,15 @@ initSidebar = (viewer) => {
let onVolumeAdded = (e) => {
let volume = e.volume;
let icon = Potree.getMeasurementIcon(volume);
createNode(measurementID, volume.name, icon, volume);
let node = createNode(measurementID, volume.name, icon, volume);
volume.addEventListener("visibility_changed", () => {
if(volume.visible){
tree.jstree('check_node', node);
}else{
tree.jstree('uncheck_node', node);
}
});
};
let onProfileAdded = (e) => {
@ -336,15 +349,23 @@ initSidebar = (viewer) => {
viewer.scene.addEventListener("polygon_clip_volume_added", onVolumeAdded);
let onMeasurementRemoved = (e) => {
console.log(e);
let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.measurement.uuid);
tree.jstree("delete_node", jsonNode.id);
};
let onVolumeRemoved = (e) => {
let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.volume.uuid);
tree.jstree("delete_node", jsonNode.id);
};
viewer.scene.addEventListener("measurement_removed", onMeasurementRemoved);
viewer.scene.addEventListener("volume_removed", onVolumeRemoved);
{
let annotationIcon = `${Potree.resourcePath}/icons/target.svg`;

View File

@ -144,6 +144,10 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{
}
};
let onVolumeRemoved = (e) => {
this.inputHandler.deselect(e.volume);
};
this.addEventListener('scene_changed', (e) => {
this.inputHandler.setScene(e.scene);
this.clippingTool.setScene(this.scene);
@ -151,8 +155,14 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{
if(!e.scene.hasEventListener("pointcloud_added", onPointcloudAdded)){
e.scene.addEventListener("pointcloud_added", onPointcloudAdded);
}
if(!e.scene.hasEventListener("volume_removed", onPointcloudAdded)){
e.scene.addEventListener("volume_removed", onVolumeRemoved);
}
});
this.scene.addEventListener("volume_removed", onVolumeRemoved);
this.scene.addEventListener('pointcloud_added', onPointcloudAdded);
}
@ -1162,6 +1172,12 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{
camera.near = result.lowestSpacing * 10.0;
camera.far = -this.getBoundingBox().applyMatrix4(camera.matrixWorldInverse).min.z;
camera.far = Math.max(camera.far * 1.5, 1000);
camera.near = Math.max(0.01, camera.near);
if(camera.near === Infinity){
camera.near = 0.1;
}
//camera.far = Math.min();
if(this.scene.cameraMode == Potree.CameraMode.ORTHOGRAPHIC) {
camera.near = -camera.far;
}