rendering extruded clip polygon edges

This commit is contained in:
Lukas Gersthofer 2017-07-17 11:10:44 +02:00
parent 32f8e6521c
commit 9029f1d9d9
3 changed files with 40 additions and 8 deletions

View File

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

View File

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

View File

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