diff --git a/src/Potree.js b/src/Potree.js index 461a9d0d..a6fbf145 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -469,8 +469,9 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.pointBudget); visible = visible && level < maxLevel; - if(pointcloud.material.numClipBoxes > 0){ + if(pointcloud.material.numClipBoxes > 0 && !window.warned125){ console.log("TODO"); + window.warned125 = true; } // visible = ["r", "r0", "r06", "r060"].includes(node.name); diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index 8bcdba80..0ec75147 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -481,33 +481,6 @@ vec3 getCompositeColor(){ -#if defined(num_clippolygons) && num_clippolygons > 0 -bool pointInClipPolygon(vec3 point, int polyIdx) { - vec4 screenClipPos = uClipPolygonVP[polyIdx] * modelMatrix * vec4(point, 1.0); - screenClipPos.xy = screenClipPos.xy / screenClipPos.w * 0.5 + 0.5; - - int j = uClipPolygonVCount[polyIdx] - 1; - bool c = false; - for(int i = 0; i < 8; i++) { - if(i == uClipPolygonVCount[polyIdx]) { - break; - } - - vec4 verti = uClipPolygonVP[polyIdx] * vec4(uClipPolygonVertices[polyIdx * 8 + i], 1); - vec4 vertj = uClipPolygonVP[polyIdx] * vec4(uClipPolygonVertices[polyIdx * 8 + j], 1); - verti.xy = verti.xy / verti.w * 0.5 + 0.5; - vertj.xy = vertj.xy / vertj.w * 0.5 + 0.5; - if( ((verti.y > screenClipPos.y) != (vertj.y > screenClipPos.y)) && - (screenClipPos.x < (vertj.x-verti.x) * (screenClipPos.y-verti.y) / (vertj.y-verti.y) + verti.x) ) { - c = !c; - } - j = i; - } - - return c; -} -#endif - vec3 getColor(){ vec3 color; @@ -588,6 +561,33 @@ float getPointSize(){ return pointSize; } +#if defined(num_clippolygons) && num_clippolygons > 0 +bool pointInClipPolygon(vec3 point, int polyIdx) { + vec4 screenClipPos = uClipPolygonVP[polyIdx] * modelMatrix * vec4(point, 1.0); + screenClipPos.xy = screenClipPos.xy / screenClipPos.w * 0.5 + 0.5; + + int j = uClipPolygonVCount[polyIdx] - 1; + bool c = false; + for(int i = 0; i < 8; i++) { + if(i == uClipPolygonVCount[polyIdx]) { + break; + } + + vec4 verti = uClipPolygonVP[polyIdx] * vec4(uClipPolygonVertices[polyIdx * 8 + i], 1); + vec4 vertj = uClipPolygonVP[polyIdx] * vec4(uClipPolygonVertices[polyIdx * 8 + j], 1); + verti.xy = verti.xy / verti.w * 0.5 + 0.5; + vertj.xy = vertj.xy / vertj.w * 0.5 + 0.5; + if( ((verti.y > screenClipPos.y) != (vertj.y > screenClipPos.y)) && + (screenClipPos.x < (vertj.x-verti.x) * (screenClipPos.y-verti.y) / (vertj.y-verti.y) + verti.x) ) { + c = !c; + } + j = i; + } + + return c; +} +#endif + void doClipping(){ #if !defined color_type_composite @@ -617,7 +617,7 @@ void doClipping(){ for(int i = 0; i < num_clippolygons; i++) { bool inside = pointInClipPolygon(position, i);; insideAny = insideAny || inside; - insideAll = insideAll // inside; + insideAll = insideAll && inside; } #endif diff --git a/src/utils/ClippingTool.js b/src/utils/ClippingTool.js index d5b25fb1..eba90801 100644 --- a/src/utils/ClippingTool.js +++ b/src/utils/ClippingTool.js @@ -59,118 +59,124 @@ Potree.ClippingTool = class ClippingTool extends THREE.EventDispatcher{ startInsertion(args = {}) { let type = args.type || null; - if(!type) return; + if(!type) return null; - if(type == "plane") { - let clipVolume = new Potree.ClipVolume(args); + let domElement = this.viewer.renderer.domElement; + let canvasSize = this.viewer.renderer.getSize(); - this.dispatchEvent({"type": "start_inserting_clipping_volume"}); + let svg = $(` + - this.viewer.scene.addClipVolume(clipVolume); + + + + + - let cancel = { - callback: null - }; + + + - let drag = e => { - let camera = this.viewer.scene.getActiveCamera(); - let I = Potree.utils.getMousePointCloudIntersection( - e.drag.end, - this.viewer.scene.getActiveCamera(), - this.viewer, - this.viewer.scene.pointclouds); - - if(I){ - clipVolume.position.copy(I.location); + + + `); + $(domElement.parentElement).append(svg); + + let polyClipVol = new Potree.PolygonClipVolume(this.viewer.scene.getActiveCamera().clone()); + + this.dispatchEvent({"type": "start_inserting_clipping_volume"}); + + this.viewer.scene.addPolygonClipVolume(polyClipVol); + this.sceneMarker.add(polyClipVol); + + let cancel = { + callback: null + }; + + let insertionCallback = (e) => { + if(e.button === THREE.MOUSE.LEFT){ + if(polyClipVol.markers.length > 1) { + polyClipVol.addEdge(polyClipVol.markers.length - 2, polyClipVol.markers.length - 1); } - }; - - let drop = e => { - clipVolume.removeEventListener("drag", drag); - clipVolume.removeEventListener("drop", drop); - cancel.callback(); + polyClipVol.addMarker(); - clipVolume.dispatchEvent({"type": "clip_volume_changed", "volume": clipVolume}); - }; - - cancel.callback = e => { - clipVolume.removeEventListener("drag", drag); - clipVolume.removeEventListener("drop", drop); - this.viewer.removeEventListener("cancel_insertions", cancel.callback); - }; - - clipVolume.addEventListener("drag", drag); - clipVolume.addEventListener("drop", drop); - this.viewer.addEventListener("cancel_insertions", cancel.callback); - - this.viewer.inputHandler.startDragging(clipVolume); - } else if(type == "polygon") { - let polyClipVol = new Potree.PolygonClipVolume(this.viewer.scene.getActiveCamera().clone()); - - this.dispatchEvent({"type": "start_inserting_clipping_volume"}); - - //this.viewer.scene.addPolygonClipVolume(polyClipVol); - this.sceneMarker.add(polyClipVol); - - let cancel = { - callback: null - }; - - let insertionCallback = (e) => { - if(e.button === THREE.MOUSE.LEFT){ - if(polyClipVol.markers.length > 1) { - polyClipVol.addEdge(polyClipVol.markers.length - 2, polyClipVol.markers.length - 1); - } - - polyClipVol.addMarker(); - - if(polyClipVol.markers.length > this.maxPolygonVertices){ - cancel.callback(); - } - - this.viewer.inputHandler.startDragging( - polyClipVol.markers[polyClipVol.markers.length - 1]); - }else if(e.button === THREE.MOUSE.RIGHT){ + svg.find("polyline").each((index, target) => { + let newPoint = svg[0].createSVGPoint(); + newPoint.x = e.offsetX; + newPoint.y = e.offsetY; + let polyline = target.points.appendItem(newPoint); + }); + + + if(polyClipVol.markers.length > this.maxPolygonVertices){ cancel.callback(); } - }; - - cancel.callback = e => { - this.sceneMarker.remove(polyClipVol); - if(polyClipVol.markers.length > 3) { - polyClipVol.removeLastMarker(); - for(let i = 0; i < polyClipVol.markers.length; i++) { - polyClipVol.markers[i].position.copy(polyClipVol.markersPosWorld[i]); - polyClipVol.markers[i].visible = false; - polyClipVol.remove(polyClipVol.edges[i]); - } - polyClipVol.edges = []; - for(let i = 0; i < polyClipVol.markers.length - 1; i++) { - polyClipVol.addEdge(i, i+1); - } - polyClipVol.addEdge(polyClipVol.markers.length - 1, 0); - polyClipVol.addExtrudedEdges(); - polyClipVol.initialized = true; - this.viewer.scene.addPolygonClipVolume(polyClipVol); - } else { - this.viewer.scene.removePolygonClipVolume(polyClipVol); - } + + this.viewer.inputHandler.startDragging( + polyClipVol.markers[polyClipVol.markers.length - 1]); + }else if(e.button === THREE.MOUSE.RIGHT){ + cancel.callback(e); + } + }; + + cancel.callback = e => { - this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true); - this.viewer.removeEventListener("cancel_insertions", cancel.callback); - this.viewer.inputHandler.enabled = true; - }; - - this.viewer.addEventListener("cancel_insertions", cancel.callback); - this.viewer.renderer.domElement.addEventListener("mouseup", insertionCallback , true); - this.viewer.inputHandler.enabled = false; - - polyClipVol.addMarker(); - this.viewer.inputHandler.startDragging( - polyClipVol.markers[polyClipVol.markers.length - 1]); - } + let first = svg.find("polyline")[0].points[0]; + svg.find("polyline").each((index, target) => { + let newPoint = svg[0].createSVGPoint(); + newPoint.x = first.x; + newPoint.y = first.y; + let polyline = target.points.appendItem(newPoint); + }); + + this.sceneMarker.remove(polyClipVol); + if(polyClipVol.markers.length > 3) { + polyClipVol.removeLastMarker(); + for(let i = 0; i < polyClipVol.markers.length; i++) { + polyClipVol.markers[i].position.copy(polyClipVol.markersPosWorld[i]); + polyClipVol.markers[i].visible = false; + polyClipVol.remove(polyClipVol.edges[i]); + } + polyClipVol.edges = []; + for(let i = 0; i < polyClipVol.markers.length - 1; i++) { + polyClipVol.addEdge(i, i+1); + } + polyClipVol.addEdge(polyClipVol.markers.length - 1, 0); + polyClipVol.addExtrudedEdges(); + polyClipVol.initialized = true; + } else { + this.viewer.scene.removePolygonClipVolume(polyClipVol); + } + + this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true); + this.viewer.removeEventListener("cancel_insertions", cancel.callback); + this.viewer.inputHandler.enabled = true; + }; + + this.viewer.addEventListener("cancel_insertions", cancel.callback); + this.viewer.renderer.domElement.addEventListener("mouseup", insertionCallback , true); + this.viewer.inputHandler.enabled = false; + + polyClipVol.addMarker(); + this.viewer.inputHandler.startDragging( + polyClipVol.markers[polyClipVol.markers.length - 1]); + + return polyClipVol; } update() {