xzw 2 years ago
parent
commit
a16385a9a3
2 changed files with 58 additions and 19 deletions
  1. 23 9
      src/ExtendPointCloudOctree.js
  2. 35 10
      src/custom/objects/Magnifier.js

+ 23 - 9
src/ExtendPointCloudOctree.js

@@ -221,6 +221,12 @@ export class ExtendPointCloudOctree extends PointCloudOctree{
         let pickWindowSize_ = THREE.Math.clamp( Math.round((1.1-this.maxLevel/this.nodeMaxLevel)*80),  5, 100)
 		let pickWindowSize = getVal(params.pickWindowSize, pickWindowSize_    ); /* 65 */ //拾取像素边长,越小越精准,但点云稀疏的话可能容易出现识别不到的情况。 另外左下侧会有缝隙无法识别到,缝隙大小和这个值有关//突然发现pickWindowSize在一百以内的变化对pick费时影响甚微,1和100差1毫秒不到,但400时会多4毫秒
             
+        if(camera.type == 'OrthographicCamera'){
+            var cameraDir = new THREE.Vector3(0,0,-1).applyQuaternion(camera.quaternion) 
+            pickWindowSize *= 4  //pointsize比较大时截取太小会没多少点可以选
+        }     
+            
+            
 		let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
 
 		let size = viewport ? viewport.resolution : renderer.getSize(new THREE.Vector2());
@@ -449,7 +455,12 @@ export class ExtendPointCloudOctree extends PointCloudOctree{
                     
                     //add
                     if(!params.all){
-                        hit.disSquare = camera.position.distanceToSquared(position)
+                        if(camera.type == 'OrthographicCamera'){
+                            let vec = new THREE.Vector3().subVectors(position, camera.position)
+                            hit.disSquare = vec.projectOnVector( cameraDir ).lengthSq();  //只考虑到相机的垂直距离 
+                        }else{ 
+                            hit.disSquare = camera.position.distanceToSquared(position)
+                        }  
                     }
 				} else if (attributeName === 'indices') {
 
@@ -491,13 +502,18 @@ export class ExtendPointCloudOctree extends PointCloudOctree{
 				return null;
 			}else{
                 //为了防止透过点云缝隙,选到后排的点云,将选取的位置离相机的距离考虑进去。倾向选择离相机近、且离鼠标位置近的点。(否则按照原方案只选离鼠标位置最近的,可能从高楼不小心走到下层,导航选点也是)
-                let sorted1 = hits.sort( (a, b) => a.disSquare - b.disSquare  );
+                let sorted1 = hits.sort( (a, b) => a.disSquare - b.disSquare  ).slice();
                 
                 let nearest = sorted1[0]  //return nearest.point;  //直接用最近点 在点云稀疏时不太跟手,如地面上,最近点往往在鼠标下方
+                 
+                let r  
+                if(camera.type != 'OrthographicCamera'){ 
+                    let ratio = 0.1 //系数越大越不跟手,但更容易pick近处的。 (当pick的点较远时,获取框内的点距离可能差别很大,就要所以除以disSquare)
+                    r = rSquare/Math.max(nearest.disSquare,0.001) * ratio
+                }else{ 
+                    r = 10      //大一点才能pick到表面的点,但太大了有时不跟手,且总容易吸附到近点
+                }
                 
-                
-                let ratio = 0.1 //系数越大越不跟手,但更容易pick近处的。 (当pick的点较远时,获取框内的点距离可能差别很大,就要所以除以disSquare)
-                let r = rSquare/Math.max(nearest.disSquare,0.001) * ratio
                 hits.forEach( hit=>{
                     let disDiff = hit.disSquare - nearest.disSquare //和最近点的偏差 
                     hit.disDiff = disDiff 
@@ -506,10 +522,8 @@ export class ExtendPointCloudOctree extends PointCloudOctree{
                 
                 let sorted2 = hits.sort( (a, b) => b.score - a.score  );
                    
-                //console.log(sorted2, 'nearest',nearest) 
-                return sorted2[0].point; 
-                  
-				//return hits[0].point;
+                //console.log(sorted2[0].point.position.z ) 
+                return sorted2[0].point;
 			}
 		}
 

+ 35 - 10
src/custom/objects/Magnifier.js

@@ -3,7 +3,7 @@ import * as THREE from "../../../libs/three.js/build/three.module.js";
 import math from '../utils/math.js'
 import browser from '../utils/browser.js'
 import Viewport from '../viewer/Viewport.js'
- 
+import {ExtendView} from "../../viewer/ExtendView.js"; 
 const texLoader = new THREE.TextureLoader() 
 const circleGeo = new THREE.CircleGeometry(1.45,100);
 const sphereGeo = new THREE.SphereBufferGeometry(0.018,10,10);
@@ -19,7 +19,7 @@ let maxPX = 1366*1024 //ipad pro.  大于这个分辨率的就直接用devicePix
 const width2dPX = Math.round(window.devicePixelRatio >= 2 ? ( window.screen.width * window.screen.height >= maxPX ? window.devicePixelRatio/1.2 : window.devicePixelRatio/1.5)*w : w)  //触屏或高分辨率的可能要放大些。但在手机上不能太大
 //console.log('width2dPX', width2dPX)
 
-
+const orthoView = new ExtendView();
 
 export default class Magnifier extends THREE.Object3D {//放大镜or望远镜
 	constructor (viewer) {
@@ -242,15 +242,30 @@ export default class Magnifier extends THREE.Object3D {//放大镜or望远镜
         
         const fareast = 300;  
         //相机位置
-        var finalDisToAim =  dis>magDisMin ? dis > fareast ? magDisMax : (dis-magDisMin) / (fareast-magDisMin) * (magDisMax-magDisMin) + magDisMin :  dis / 2;    //dis>magDistance_ ? magDistance_ : dis / 2;
-        
+        if(playerCamera.type == 'OrthographicCamera'){
+            
+            var finalDisToAim = 2
+             
+        }else{  
+            var finalDisToAim =  dis>magDisMin ? dis > fareast ? magDisMax : (dis-magDisMin) / (fareast-magDisMin) * (magDisMax-magDisMin) + magDisMin :  dis / 2;    //dis>magDistance_ ? magDistance_ : dis / 2;
+            
+        }
+         
         
         this.camera.position.copy(aimPos).add(dirToCamera.multiplyScalar(finalDisToAim))
         this.camera.lookAt(aimPos)
-        this.camera.fov = playerCamera.fov / 2
+        this.camera.fov = playerCamera.type == 'OrthographicCamera' ? 30 : playerCamera.fov / 2
         this.camera.updateProjectionMatrix()
         
         
+        if(playerCamera.type == 'OrthographicCamera'){
+            orthoView.position.copy(this.camera.position)
+         
+            orthoView.yaw = viewer.mainViewport.view.yaw;
+            orthoView.pitch = viewer.mainViewport.view.pitch;
+            orthoView.applyToCamera(this.camera)
+        }
+
 
          
         //自身位置 
@@ -260,12 +275,22 @@ export default class Magnifier extends THREE.Object3D {//放大镜or望远镜
         let screenPos = pos2d.clone().setY(pos2d.y + (pos2d.y>maxY ? -margin : margin ))
         
         let newPos = new THREE.Vector3(screenPos.x,screenPos.y,0.8).unproject(playerCamera); //z:-1朝外       
-        let dir = newPos.clone().sub(playerPos).normalize().multiplyScalar(10);//这个数值要大于playerCamera.near
-        let s =  finalDisToAim   // dis>magDisMin ? 1 : dis / magDisMin  ; 
+        if(playerCamera.type != 'OrthographicCamera'){
+            let dir = newPos.clone().sub(playerPos).normalize().multiplyScalar(10);//这个数值要大于playerCamera.near
+                                                                           
         
-        //let s = dis>magDisMin ? dis > fareast ? magDisMax : (dis-magDisMin) / (fareast-magDisMin) * (magDisMax-magDisMin) + magDisMin :  dis / magDisMin  
-        
-        this.position.copy(playerPos.clone().add(dir))
+                                                                                                                                                            
+            
+            this.position.copy(playerPos.clone().add(dir))
+        }else{
+            viewer.navCubeViewer.splitScreen.setShiftTarget(viewer.mainViewport, viewer.bound.center)
+            viewer.mainViewport.targetPlane.setFromNormalAndCoplanarPoint( viewer.mainViewport.view.direction.clone(), viewer.bound.center )  
+            viewer.mainViewport.targetPlane.projectPoint(newPos, viewer.mainViewport.shiftTarget )  
+            this.position.copy(viewer.mainViewport.shiftTarget.clone() ) 
+            
+            //this.position.copy(playerPos.clone().add(dir))
+        }
+        let s = finalDisToAim                        
         this.quaternion.copy(playerCamera.quaternion); 
         this.targetPoint.position.copy(aimPos); 
         this.targetPoint.scale.set(s,s,s)