Selaa lähdekoodia

fix: createFixPoint

xzw 1 vuosi sitten
vanhempi
commit
9e97576c64

+ 32 - 35
public/static/lib/potree/potree.js

@@ -90029,11 +90029,11 @@ void main()
 	    }
 
 
-	    ifBlockedByIntersect({pos3d, margin=0, cameraPos, pickWindowSize, pano, useDepthTex}={}){//某点是否被遮挡(不允许camera修改位置, 因为depthTex不好置换)
+	    ifBlockedByIntersect({point, margin=0, cameraPos, pickWindowSize, pano, useDepthTex}={}){//某点是否被遮挡(不允许camera修改位置, 因为depthTex不好置换)
 	          
-	        let intersect = this.getIntersect(this.hoverViewport, true, pickWindowSize, null, null, useDepthTex, {pos3d, cameraPos, pano});
+	        let intersect = this.getIntersect(this.hoverViewport, true, pickWindowSize, null, null, useDepthTex, {point, cameraPos, pano});
 	        let cameraPos_ = (!cameraPos && pano) ? pano.position : (cameraPos||this.hoverViewport.view.position);
-	        if(intersect && intersect.distance+margin <= pos3d.distanceTo(cameraPos_)){
+	        if(intersect && intersect.distance+margin <= point.distanceTo(cameraPos_)){
 	            return intersect //被遮挡
 	        }
 	        //点云模式,对没加载出的点云不准确。 尤其是需要修改相机位置时,因临时修改并不能使点云加载。
@@ -90050,14 +90050,14 @@ void main()
 	 
 	        let getByDepthTex = ()=>{ 
 	            let intersect;
-	            if(prop.pos3d){
+	            if(prop.point){
 	                let cameraPos = prop.pano ? prop.pano.position : camera.position;
-	                let dir = new Vector3().subVectors(prop.pos3d, cameraPos).normalize(); 
+	                let dir = new Vector3().subVectors(prop.point, cameraPos).normalize(); 
 	                intersect = {dir}; 
 	            }else {
 	                intersect = Utils.getIntersect(camera, [viewer.images360.cube], this.pointer, raycaster); 
 	            } 
-	            intersectPoint = viewer.images360.depthSampler.sample(intersect, prop.pano, !!prop.pos3d);  //可能不准确, 因pano可能未加载depthTex
+	            intersectPoint = viewer.images360.depthSampler.sample(intersect, prop.pano, !!prop.point);  //可能不准确, 因pano可能未加载depthTex
 	            if(intersectPoint && Potree.settings.depTexLocBindDataset){
 	                intersectPoint.pointcloud = (prop.pano || viewer.images360.currentPano).pointcloud;
 	                //在全景模式下,虽然深度图上的点可能对应别的pointcloud,但因为是在当前全景图处得到的,所以即使将原本对应的点云移走,该点也不移动是有道理的。它可以永远跟着该全景图。
@@ -90065,9 +90065,9 @@ void main()
 	        };
 	        
 	        let getByCloud = ()=>{
-	            if(prop.pos3d){//指定了目标点,而非只是用pointer所在位置
+	            if(prop.point){//指定了目标点,而非只是用pointer所在位置
 	                prop.cameraPos && camera.position.copy(prop.cameraPos);
-	                camera.lookAt(prop.pos3d);
+	                camera.lookAt(prop.point);
 	                camera.updateMatrixWorld();
 	                prop.pointer = this.pointer.clone();
 	                prop.mouse = this.mouse.clone();
@@ -90082,13 +90082,13 @@ void main()
 	                camera, 
 	                this.viewer, 
 	                this.viewer.scene.pointclouds,
-	                {pickClipped: true, isMeasuring: this.isMeasuring, pickWindowSize, cameraChanged: !!prop.pos3d }  
+	                {pickClipped: true, isMeasuring: this.isMeasuring, pickWindowSize, cameraChanged: !!prop.point }  
 	                
 	            );
 	            
 	        
 	            //恢复
-	            if(prop.pos3d){
+	            if(prop.point){
 	                viewport.view.applyToCamera(camera);
 	                this.pointer.copy(prop.pointer);
 	                this.mouse.copy(prop.mouse);
@@ -97762,10 +97762,10 @@ ENDSEC
 	                };   
 	                if(computeDirFirst){//先计算方向,防止重复计算ifBlockedByIntersect
 	                    if(inDirection()){
-	                        ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({pos3d:pano1.position, margin,  cameraPos:pano0.position});
+	                        ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({point:pano1.position, margin,  cameraPos:pano0.position});
 	                    }
 	                }else {
-	                    ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({pos3d:pano1.position, margin,  cameraPos:pano0.position});
+	                    ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({point:pano1.position, margin,  cameraPos:pano0.position});
 	                    if(ifNeighbour && !inDirection()){
 	                        ifNeighbour = undefined; //不确定
 	                    } 
@@ -98136,7 +98136,7 @@ ENDSEC
 	            (pano)=>{
 	                let  score = 0;
 	                if(pano.depthTex && checkIntersect){    
-	                    let intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true);       //viewer.inputHandler.ifBlockedByIntersect({pos3d:target, margin:0.1, cameraPos:pano})
+	                    let intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true);       //viewer.inputHandler.ifBlockedByIntersect({point:target, margin:0.1, cameraPos:pano})
 	                    if(intersect){ 
 	                        score = 0;
 	                    }else { 
@@ -134850,13 +134850,13 @@ ENDSEC
 	    
 	     
 	    
-	    ifPointBlockedByIntersect(pos3d , panoId,  soon ){//点是否被遮挡
+	    ifPointBlockedByIntersect(point , panoId,  soon ){//点是否被遮挡
 	        let ifShelter;
 	        let now = Date.now();
 	        let extraPanoId = panoId != void 0; 
 	        if(!this.shelterCount)return
 	        
-	        let history = shelterHistory.find(e=>e.pos3d.equals(pos3d)); 
+	        let history = shelterHistory.find(e=>e.point.equals(point)); 
 	        let cameraPos = this.mainViewport.view.position.clone();
 	        if(panoId == void 0){
 	            if(this.images360.isAtPano(0.05)){
@@ -134879,7 +134879,7 @@ ENDSEC
 	            shelterHistory.splice(index, 1);
 	            
 	        }else {//新增
-	            history = {pos3d,  panos:{}, notAtPano:{}}; 
+	            history = {point,  panos:{}, notAtPano:{}}; 
 	             
 	            const minCount = 100;
 	            if(shelterHistory.length > minCount){//去除最早的
@@ -134903,21 +134903,21 @@ ENDSEC
 	            if(panoId != void 0){
 	                let pano = this.images360.getPano(panoId);
 	                if((soon || this.shelterCount.byTex<this.shelterCount.maxByTex) && pano.depthTex){
-	                    ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({pos3d, margin:Potree.config.shelterMargin, useDepthTex:true, pano }  ); 
+	                    ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point, margin:Potree.config.shelterMargin, useDepthTex:true, pano }  ); 
 	                    history.panos[panoId] = ifShelter;
 	                    this.shelterCount.byTex ++ ;
-	                    //console.log('computeByTex direct', panoId, pos3d, ifShelter)
+	                    //console.log('computeByTex direct', panoId, point, ifShelter)
 	                }else {
-	                    //console.log('延迟tex',panoId, pos3d )
+	                    //console.log('延迟tex',panoId, point )
 	                    history.waitCompute = {panoId,   forceGet:extraPanoId  };
 	                    return useLastResult() 
 	                }
 	            }else { 
 	                if(/* history.ifShelter == void 0 || */ this.shelterCount.byCloud<this.shelterCount.maxByCloud){//弊端:第一个总是直接计算,后面的都是延后。但无法改进,因是一个个传进来的,无法预测。 
-	                    ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({pos3d, margin:Potree.config.shelterMargin, pickWindowSize:3}  ); 
+	                    ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point, margin:Potree.config.shelterMargin, pickWindowSize:3}  ); 
 	                    history.notAtPano = {cameraPos , ifShelter };
 	                    this.shelterCount.byCloud ++ ; 
-	                    //console.log('computeByCloud direct', pos3d.toArray())
+	                    //console.log('computeByCloud direct', point.toArray())
 	                }else {
 	                    //console.log('延迟cloud' )
 	                    history.waitCompute = {cameraPos};
@@ -134972,11 +134972,11 @@ ENDSEC
 	                             if(byTex >= maxTexCount)break
 	                             
 	                             byTex ++;
-	                             let ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({pos3d:history.pos3d, margin:Potree.config.shelterMargin, useDepthTex:true }  ); 
+	                             let ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point:history.point, margin:Potree.config.shelterMargin, useDepthTex:true }  ); 
 	                             history.panos[this.images360.currentPano.id] = ifShelter; 
 	                             history.ifShelter = ifShelter;
 	                             delete history.waitCompute;  
-	                             //console.log('补1', history.pos3d.toArray())
+	                             //console.log('补1', history.point.toArray())
 	                         }else {
 	                             if(this.images360.currentPano.pointcloud.hasDepthTex){
 	                                 //先等待加载完深度图
@@ -135015,14 +135015,14 @@ ENDSEC
 	            
 	            
 	            
-	                let list = waitCloud2.map(e=>e.pos3d); 
+	                let list = waitCloud2.map(e=>e.point); 
 	                let result = Common$1.batchHandling.getSlice('shelterByCloud', list, {maxUseCount:maxCloudCount,useEquals:true, stopWhenAllUsed:true} ); //iphonex稳定后大概在7-10。  
 	                //list.length>0 && console.log('list',list, maxCloudCount)
 	                
 	                result.list.forEach(e=>{
-	                    let history = waitCloud2.find(a=>a.pos3d.equals(e));
+	                    let history = waitCloud2.find(a=>a.point.equals(e));
 	                     
-	                    let ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({pos3d:history.pos3d, margin: Potree.config.shelterMargin , pickWindowSize:3}  ); 
+	                    let ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point:history.point, margin: Potree.config.shelterMargin , pickWindowSize:3}  ); 
 	                    
 	                    if(history.waitCompute.cameraPos){
 	                        history.notAtPano = {cameraPos: history.waitCompute.cameraPos , ifShelter };
@@ -135031,7 +135031,7 @@ ENDSEC
 	                    }
 	                    history.ifShelter = ifShelter;
 	                    byCloud++;
-	                    //console.log('补2',  history.pos3d.toArray()) 
+	                    //console.log('补2',  history.point.toArray()) 
 	                    delete history.waitCompute;
 	                });
 	            
@@ -137310,10 +137310,7 @@ ENDSEC
 		render(params={}){//add params 
 	        viewer.addTimeMark('render','start');
 	        const vrActive = this.renderer.xr.isPresenting;
-	         
-	        
-	        //Potree.settings.useRTPoint =  !(SiteModel.editing && SiteModel.selected && SiteModel.selected.buildType == 'room' )//空间模型的房间选中材质是需要depth的,这时候需要绘制两次点云
-	        
+	          
 	        Potree.settings.pointEnableRT = this.scene.measurements.length > 0 || !Potree.settings.useRTPoint; 
 	        
 	        
@@ -137905,12 +137902,12 @@ ENDSEC
 	                
 	                if(o.checkIntersect){
 	                    let checkIntersect = ( )=>{ 
-	                        let intersect = this.inputHandler.ifBlockedByIntersect({pos3d:position, cameraPos: target});// 不一定准确
+	                        let intersect = this.inputHandler.ifBlockedByIntersect({point:position, cameraPos: target});// 不一定准确
 	                        if(intersect){ 
 	                            let blockCount = 0, unblockCount = 0, visi;
 	                            for(let i=0;i<object.points.length;i++){ //如果顶点超过一半不可见,就要更改位置
 	                                let p = object.points[i];
-	                                let blocked = this.inputHandler.ifBlockedByIntersect({pos3d:p, margin:0.3 , cameraPos:position, pickWindowSize:4});
+	                                let blocked = this.inputHandler.ifBlockedByIntersect({point:p, margin:0.3 , cameraPos:position, pickWindowSize:4});
 	                                if(blocked){
 	                                    blockCount ++;
 	                                    if(blockCount / object.points.length >= 0.5){
@@ -137941,7 +137938,7 @@ ENDSEC
 	                                    let position1 = position.clone();
 	                                    let dir = new Vector3().subVectors(position, target); 
 	                                    position.copy(target).sub(dir); 
-	                                    let intersect2 = this.inputHandler.ifBlockedByIntersect({pos3d: position,  cameraPos:target});// 不一定准确
+	                                    let intersect2 = this.inputHandler.ifBlockedByIntersect({point: position,  cameraPos:target});// 不一定准确
 	                                    if(intersect2){
 	                                        if(intersect2.distance < intersect.distance ){
 	                                            position.copy(position1);//恢复
@@ -138040,7 +138037,7 @@ ENDSEC
 	                
 	                if(o.checkIntersect){//识别被点云遮住的话 
 	                    let intersect;  //反向查找从target到相机的第一个intersect
-	                    intersect = this.inputHandler.ifBlockedByIntersect({pos3d:position, margin:0,  cameraPos:target}   /* {pos3d:target, margin: 0.2,  cameraPos:position} */);  
+	                    intersect = this.inputHandler.ifBlockedByIntersect({point:position, margin:0,  cameraPos:target}   /* {point:target, margin: 0.2,  cameraPos:position} */);  
 	                     
 	                    if(intersect){ 
 	                        position.copy(intersect.location); 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
public/static/lib/potree/potree.js.map


+ 150 - 4
src/sdk/laser/core/enter.js

@@ -77,7 +77,7 @@ var enter = ({
     parameter.viewer = viewer;
     parameter.sceneBus = sceneBus;
     //Potree.settings.rotAroundPoint = false; //试验
-
+    viewer.fixPoints = []//固定点
 
     sceneBus.on("visible", (v) => {
         viewer.visible = v;
@@ -104,7 +104,7 @@ var enter = ({
     viewer.addEventListener("viewChanged", (e) => { 
          sceneBus.emit("viewChange", e.name) 
     });
-
+ 
 
     let cameraChange = (e) => {
         var camera = e.viewport.camera;
@@ -236,12 +236,13 @@ var enter = ({
         return info;
     };
 
-    let getMeasureFunction = function (measure, bus) {
+    let getMeasureFunction = function (measure, bus, isShape) {
         measure.addEventListener("marker_dropped", (e) => {
             //拖拽结束后发送changeCallBack
             if (measure.parent) {
                 //未被删除
-                bus.emit("update");
+                isShape ? bus.emit("graphChange") : bus.emit("update");
+                
             }
         });
         /* measure.addEventListener("highlight", (e) => {
@@ -368,6 +369,47 @@ var enter = ({
 
         };
     };
+    
+    let createMeasureForPoint = (fixPoint)=>{
+        let baseLine = viewer.scene.measurements.find(e=>e.isBaseLine && e.points.length == 2) 
+        if(!baseLine){
+            return console.error('创建失败,因基准线不存在')
+        }
+        
+        
+        let fixPoint2d = new THREE.Vector2.copy(fixPoint)
+        let baselineP12d = new THREE.Vector2.copy(baseLine.points[0])
+        let baselineP22d = new THREE.Vector2.copy(baseLine.points[1]) 
+        let foot1 = Potree.math.getFootPoint(fixPoint2d, baselineP12d, baselineP22d) 
+         
+        let info1 = {
+            measureType : 'Hor Distance',
+            unableChange: true,
+            points: [new THREE.Vector3().copy(fixPoint), new THREE.Vector3(foot1.x, foot1.y, fixPoint.z)],
+            projectPos: new THREE.Vector3(foot1.x, foot1.y, baseLine.points[0].z),
+              
+        }
+        /* let info2 = {
+            measureType : 'Distance'
+        } */
+        let disMeasure1 = viewer.measuringTool.createMeasureFromData(info1);
+        //let disMeasure2 = viewer.measuringTool.createMeasureFromData(info2);
+    
+        
+        fixPoint.disMeasure1 = disMeasure1
+    }
+    
+    let removeMeasureForPoint = (fixPoint)=>{
+        viewer.scene.removeMeasurement(fixPoint.disMeasure1);  
+        
+    }
+    
+    
+    
+    
+    
+    
+    
 
     var sdk = {
         temp: {}, //记录
@@ -603,6 +645,110 @@ var enter = ({
                 return ret;
             },
 
+
+
+/* 
+            // 创建固定点对象,measure是否是测量模式,
+            //graph 如果是形状则有形状路径点,如果不是形状则传入pos当前固定点的位置 
+            sdk.scene.createFixPoint({  measure: boolean, 
+                graph: Array<{x,y,z}>, pos: {xyz} })
+
+ */
+
+
+
+
+            createFixPoint({measure, graph, pos, basePoint}){//创建固定点或多线段
+             
+                
+                
+                const bus = mitt();
+                let info = {
+                    measureType : 'MulDistance' 
+                }
+                let measureFun, fixPoint 
+                if(graph){
+                    
+                    if(graph.length == 0){
+                        measure = viewer.measuringTool.startInsertion( info,
+                            () => { 
+                            bus.emit("end", ret); //完成
+                        },
+                        () => { 
+                            bus.emit("quit", ret); //删除
+                        });
+                    }else{ 
+                        info.points = graph;  
+                        info.sid = Math.random()//sid;
+                        info.bus = bus;
+                        //info.color = color
+                        measure = viewer.measuringTool.createMeasureFromData(info);
+                        Potree.Log("drawMeasure由数据新建: " + measure.id, {
+                            font: {
+                                color: "#00c7b2"
+                            },
+                        });
+                        measureFun = getMeasureFunction(measure, bus, true) 
+                    }
+                }else{
+                    fixPoint = new THREE.Vector3().copy(pos) 
+                    THREE.EventDispatcher.call(fixPoint) 
+                    fixPoint.bus = bus
+                    fixPoint.basePoint = new THREE.Vector3().copy(basePoint)
+                      
+                    if(measure){ 
+                        createMeasureForPoint(fixPoint) 
+                    }
+                    viewer.fixPoints.push(fixPoint)
+                }
+                 
+                
+                const ret = {
+                    // 退出测量模式,清除之前操作
+                    
+                    bus,
+                    destroy : isMeasure ? measureFun.clear : ()=>{
+                        
+                    },
+                    quitMeasure(){//退出测量模式,删除测量线
+                        removeMeasureForPoint(fixPoint) 
+                    },
+                    changePos(pos){//固定点修改
+                        fixPoint.copy(pos)
+                         
+                         
+                    },
+                    changeBase(){//基准点修改
+                        
+                    },
+                    graphDrawComplete: measureFun.end,
+                         
+                     
+                    
+                };
+                
+                
+                
+                return ret
+            },
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
             // 开启放大镜
             openMagnifier() {
                 //console.error('开启放大镜')