Quellcode durchsuchen

fix: iframe getRootWindow bug

xzw vor 2 Jahren
Ursprung
Commit
a05d1d5a5d
3 geänderte Dateien mit 164 neuen und 78 gelöschten Zeilen
  1. 162 76
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map
  3. 1 1
      src/sdk/cover/index.js

+ 162 - 76
public/lib/potree/potree.js

@@ -53704,12 +53704,12 @@
 	        
 	    }, 
 	        
-	    getRootWindow(){
+	    getRootWindow(){//获取包含Potree的根window
 	        let win = window;
-	        while(win.parent!=win){
+	        while(win.parent!=win && win.parent.Potree){
 	            win = win.parent;
 	        }
-	        return win
+	        if(window != win)return win
 	    },
 	    
 	    
@@ -53762,7 +53762,7 @@
 	        
 			if(dir.x === 0 && dir.y === 0){
 				this.pitch = Math.PI / 2 * Math.sign(dir.z); 
-	            this.yaw = 0;   //add:还是要指定一下, 否则不统一
+	            //this.yaw = 0   //add:还是要指定一下, 否则不统一
 	            
 			}else {
 				let yaw = Math.atan2(dir.y, dir.x) - Math.PI / 2;
@@ -53956,7 +53956,7 @@
 	    }
 	    
 	    set quaternion(q){
-	        this.direction = new Vector3(0,0,-1).applyQuaternion(q);
+	        this.direction = new Vector3(0,0,-1).applyQuaternion(q); //注意如果得到的dir.x==dir.y==0,  yaw不会变为0, 导致算的quaternion和q不一致
 	    }
 	    
 	    copy(a){
@@ -54086,7 +54086,7 @@
 	    setView( info = {}){
 	        // position, target, duration = 0, callback = null, onUpdate = null, Easing='', cancelFun
 	        this.cancelFlying();
-	        let posWaitDone,  rotWaitDone; 
+	        let posWaitDone,  rotWaitDone , dir;
 	        
 	        let posDone = ()=>{
 	            rotWaitDone || done();
@@ -54094,10 +54094,14 @@
 	        };
 	        let rotDone = ()=>{
 	            if(endTarget){
-	                this.lookAt(endTarget); //compute radius for orbitcontrol
+	                this.lookAt(endTarget); //compute radius for orbitcontrol 
 	            }else if(endQuaternion){
 	                this.rotation = new Euler().setFromQuaternion(endQuaternion);
+	            }else if(endYaw != void 0){
+	                this.yaw = endYaw,  this.pitch = endPitch;
 	            }
+	            //if(dir.x == 0 && dir.y == 0)this.yaw = 0 //统一一下 朝上的话是正的。朝下的一般不是0,会保留一个接近0的小数所以不用管
+	           
 	            posWaitDone || done();
 	            rotWaitDone = false; 
 	        };
@@ -54118,24 +54122,33 @@
 	        
 	        let endPosition = new Vector3().copy(info.position);
 	        let startPosition = this.position.clone();
-			let startQuaternion, endQuaternion, endTarget = null ;
+			let startQuaternion, endQuaternion, endTarget = null,  
+	            endYaw, startYaw, endPitch, startPitch ;
+	        
+	        
 	        this.restrictPos(endPosition);
 	         
-			if(info.target ){
+	         
+	        if(info.endYaw != void 0) { 
+	            startPitch = this.pitch;
+	            endPitch = info.endPitch;
+	            startYaw = this.yaw;
+	            endYaw = info.endYaw; 
+	            if(Math.abs(startYaw - endYaw)>Math.PI){//如果差距大于半个圆,就要反个方向转(把大的那个数字减去360度)
+	                startYaw > endYaw ? (startYaw -= Math.PI*2) : (endYaw -= Math.PI*2); 
+	            }
+	            
+			}else if(info.target ){
 				endTarget = new Vector3().copy(info.target);  
 	            endQuaternion = math.getQuaFromPosAim(endPosition,endTarget); //若为垂直,会自动偏向x负的方向
-	            let dir = new Vector3().subVectors(endTarget, endPosition).normalize();
-	           
-	            let view = this.clone();
-	            view.direction = dir;
-	              
+	            dir = new Vector3().subVectors(endTarget, endPosition).normalize();
+	            //console.log(dir, this.direction)   
 			}else if(info.quaternion){
 	            endQuaternion = info.quaternion.clone();
 	        }
 	         
 	        if(endQuaternion){ 
-	            startQuaternion = new Quaternion().setFromEuler(this.rotation);
-	           
+	            startQuaternion = this.quaternion; 
 	        }
 	        
 	        
@@ -54170,16 +54183,19 @@
 	                }, info.ignoreFirstFrame);  
 	            } 
 	            
-	            if(endQuaternion){
+	            if(endQuaternion || endYaw != void 0){
 	                rotWaitDone = true; 
 	                transitions.start( (progress, delta )=>{
-	                   
-	                    let quaternion = (new Quaternion()).copy(startQuaternion); 
-	                    lerp.quaternion(quaternion, endQuaternion)(progress);  //在垂直的视角下的角度突变的厉害,这时候可能渐变yaw比较好
-	             
-	                    //this.rotation = new THREE.Euler().setFromQuaternion(quaternion)
-	                    this.quaternion = quaternion;
-	                     
+	                    if(endYaw != void 0){
+	                        this.yaw = startYaw * (1-progress) + endYaw * progress;
+	                        this.pitch = startPitch * (1-progress) + endPitch * progress;
+	                    }else { 
+	                        let quaternion = (new Quaternion()).copy(startQuaternion); 
+	                        lerp.quaternion(quaternion, endQuaternion)(progress);  //在垂直的视角下的角度突变的厉害,这时候可能渐变yaw比较好
+	                        //console.log(quaternion)
+	                        //this.rotation = new THREE.Euler().setFromQuaternion(quaternion)
+	                        this.quaternion = quaternion;
+	                    }
 	                    posChange || info.onUpdate && info.onUpdate(progress, delta);  
 	                    
 	                }, info.duration, rotDone , 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine ,null, this.LookTransition, ()=>{
@@ -54214,13 +54230,16 @@
 	    
 	    //平移Ortho相机
 	    moveOrthoCamera(viewport,  info, duration,  easeName){//boundSize优先于endZoom。
-	        let camera = viewport.camera;
+	        let camera = info.camera || viewport.camera;
 	        
 	        let startZoom = camera.zoom; 
 	        let endPosition = info.endPosition; 
 	        let boundSize = info.boundSize;
 	        let endZoom = info.endZoom;
 	        let margin = info.margin || {x:0,y:0};/* 200 */ //像素
+	        let onUpdate = info.onUpdate; 
+	        
+	        
 	        
 	        if(info.bound){//需要修改boundSize以适应相机的旋转,当相机不在xy水平面上朝向z时
 	            endPosition = endPosition || info.bound.getCenter(new Vector3());
@@ -54235,9 +54254,12 @@
 	            boundSize.set(1,1);  //避免infinity
 	        }
 	        
+	        
+	        
+	        
 	        this.setView( Object.assign(info,  { position:endPosition,  duration, 
 	            
-	            onUpdate:(progress)=>{ 
+	            onUpdate:(progress, delta)=>{ 
 	                if(boundSize || endZoom){ 
 	                    if(boundSize){
 	                        let aspect = boundSize.x / boundSize.y;
@@ -54255,6 +54277,7 @@
 	                    
 	                    camera.zoom = endZoom * progress + startZoom * (1 - progress);
 	                    camera.updateProjectionMatrix(); 
+	                    onUpdate && onUpdate(progress, delta);
 	                } 
 	            },
 	            
@@ -54297,6 +54320,42 @@
 	    
 	        
 	        
+	    } 
+	    
+	    
+	    tranCamera(viewport,  info, duration,  easeName){
+	        viewport.camera = info.midCamera;
+	        //viewport.camera.matrixWorld = info.endCamera.matrixWorld
+	        
+	        
+	        //viewer.setCameraMode(CameraMode.ORTHOGRAPHIC) 
+	        info.midCamera.projectionMatrix.copy(info.startCamera.projectionMatrix);
+	        
+	        let onUpdate = info.onUpdate;
+	        info.onUpdate = (progress, delta)=>{ 
+	            lerp.matrix4(info.midCamera.projectionMatrix, info.endCamera.projectionMatrix)(progress); 
+	            
+	            /* console.log('matrixWorld', viewport.camera.position.toArray(), viewport.camera.matrixWorld.toArray())
+	            console.log('projectionMatrix', info.endCamera.zoom,  viewport.camera.projectionMatrix.toArray())
+	             */
+	            onUpdate && onUpdate(progress, delta);
+	        };
+	        
+	        let callback = info.callback;
+	        info.callback = ()=>{ 
+	            viewport.camera = info.endCamera; 
+	            callback && callback();
+	        }; 
+	        
+	        
+	        info.camera = info.endCamera;
+	        
+	        if(info.camera.type == "OrthographicCamera"){
+	            this.moveOrthoCamera(viewport,  info, duration,  easeName);
+	        }else {
+	            this.setView( Object.assign(info,  { duration}) );
+	        }
+	        
 	    }
 	    
 	     
@@ -72492,13 +72551,16 @@ void main()
 	        
 	        var transformPointcloud = (pointcloud, dataset)=>{
 	            var locationLonLat = dataset.location.slice(0,2);
+	             
+	           
+	            //当只有一个dataset时,无论如何transform 点云和漫游点都能对应上。
 	            
-	            /* if(window.AMapWith84){//需要转换
-	                locationLonLat = AMapWith84.wgs84ToAMap({x:locationLonLat[0], y:locationLonLat[1]})
+	            /* if(window.AMapWith84 && Potree.settings.mapCompany != 'google'){
+	                 locationLonLat = AMapWith84.wgs84ToAMap({x:locationLonLat[0], y:locationLonLat[1]})
+	                  
 	                locationLonLat = [locationLonLat.x,locationLonLat.y] 
 	            } */
-	           
-	            //当只有一个dataset时,无论如何transform 点云和漫游点都能对应上。
+	            
 	            var location = viewer.transform.lonlatToLocal.forward(locationLonLat);  //transform.inverse()
 	            //初始化位置 
 	            
@@ -72530,6 +72592,12 @@ void main()
 	        
 	        {//拿初始数据集作为基准。它的位置是000
 	            var locationLonLat = originDataset.location.slice(0,2);
+	            
+	            if(window.AMapWith84){//需要转换为高德的
+	                locationLonLat = AMapWith84.wgs84ToAMap({x:locationLonLat[0], y:locationLonLat[1]});
+	                locationLonLat = [locationLonLat.x,locationLonLat.y]; 
+	            } 
+	            
 	            proj4.defs("LOCAL", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //高德坐标系
 	            proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
 	            proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
@@ -92226,6 +92294,7 @@ void main()
 	        this.name = args.name;
 	        this.renderArea = domElement; 
 	        this.oldResolution = new Vector2();
+	        this.oldResolution2 = new Vector2();
 	        
 	        this.screenSizeInfo = {
 	            W:0, H:0, pixelRatio:1 , windowWidth:0, windowHeight:0
@@ -92340,14 +92409,15 @@ void main()
 
 	            w = this.renderArea.clientWidth;
 	            h = this.renderArea.clientHeight;
-	             
+	            
+	            
 	            if(w !== this.screenSizeInfo.W || h !== this.screenSizeInfo.H || o.forceUpdateSize || this.screenSizeInfo.pixelRatio != window.devicePixelRatio){
 	                this.screenSizeInfo.W = w; 
 	                this.screenSizeInfo.H = h; 
 	                render = true; 
 	                this.screenSizeInfo.pixelRatio = window.devicePixelRatio;  //如果player放在小窗口了,也要监测devicePixelRatio,因为缩放时client宽高不会改变
 	                //config.isMobile ? (ratio = Math.min(window.devicePixelRatio, 2)) : (ratio = window.devicePixelRatio)
-	                ratio = window.devicePixelRatio;
+	                ratio = window.devicePixelRatio; 
 	            }     
 	        }
 	        if (render) { 
@@ -92406,18 +92476,17 @@ void main()
 	        
 	        
 	        if(!onlyForTarget){//因为onlyForTarget不传递devicePixelRatio所以不发送了
-	            this.emitResizeMsg({viewport:this.viewports[0],  deviceRatio:devicePixelRatio});
-	        }
+	            this.ifEmitResize({viewport:this.viewports[0],  deviceRatio:devicePixelRatio});
+	        }  
 	         
 	    } 
 	    
-	    emitResizeMsg(e){//切换viewport渲染时就发送一次, 通知一些材质更新resolution。  
-	        if(!e.viewport.resolution.equals(this.oldResolution)){ 
+	    ifEmitResize(e){//切换viewport渲染时, 若这些viewport大小不同就发送一次, 通知一些材质更新resolution。  
+	        if(!e.viewport.resolution.equals(this.oldResolution)||!e.viewport.resolution2.equals(this.oldResolution2)){ 
 	            this.dispatchEvent($.extend(e, {type:'resize'})); 
 	            this.oldResolution.copy(e.viewport.resolution);
-	        }
-	        
-	        
+	            this.oldResolution2.copy(e.viewport.resolution2);  
+	         } 
 	    }
 	    
 	    
@@ -92445,9 +92514,9 @@ void main()
 	                    //this.changeTime = (this.changeTime || 0) +1
 	                //}
 	                viewport.needRender = true;  //直接写这咯  
-	                if(viewport.resolutionChanged){
-	                    this.emitResizeMsg({viewport});
-	                }
+	                if(changeInfo.resolutionChanged){
+	                    this.dispatchEvent( {type:'resize', viewport});  
+	                } 
 	                  
 	            }                
 	        }
@@ -92575,6 +92644,7 @@ void main()
 	                quaternion: this.camera.quaternion.clone(),
 	                active:this.active,
 	                resolution:this.resolution.clone(),
+	                resolution2:this.resolution2.clone(), //有时clientWidth没变但是ratio缩放了
 	            }; 
 	        };
 	        let projectionChanged = true, positionChanged = true, quaternionChanged = true, activeChanged = true, resolutionChanged = true;
@@ -92589,7 +92659,7 @@ void main()
 	            positionChanged = !this.camera.position.equals(this.previousState.position);  
 	            quaternionChanged = !this.camera.quaternion.equals(this.previousState.quaternion); 
 	            activeChanged = this.active != this.previousState.active;
-	            resolutionChanged = !this.resolution.equals(this.previousState.resolution);
+	            resolutionChanged = !this.resolution.equals(this.previousState.resolution) || !this.resolution2.equals(this.previousState.resolution2);
 	        }   
 	        copy(); 
 	        
@@ -117546,7 +117616,7 @@ ENDSEC
 	                    matrix : new Matrix4().elements,  //参照downloadNoCrop,给默认值,表示没有最外层裁剪
 	                    VisiMatrixes: cloud.material.clipBoxes_in.filter(e=>!e.box.isNew).map(e=>Clip.getTransformationMatrix(cloud, e.inverse).elements), 
 	                    UnVisiMatrixes: cloud.material.clipBoxes_out.filter(e=>!e.box.isNew).map(e=>Clip.getTransformationMatrix(cloud, e.inverse).elements),
-	                    modelMatrix:(new Matrix4).copy(cloud.transformMatrix).transpose().elements
+	                    modelMatrix:(new Matrix4).copy(cloud.transformMatrix).transpose().elements   //需要保证没有位移,否则剪裁后的模型位置会变化
 	                };  
 	                return data
 	            }) ,
@@ -150582,7 +150652,7 @@ ENDSEC
 	Potree.isIframeChild = window.parent!=window;  //子页面
 	if(Potree.isIframeChild){ 
 	    let rootWin = Common$1.getRootWindow(); 
-	    rootWin.viewer.dispatchEvent({type:'createIframe', window}); //给祖先页面发送信息
+	    rootWin && rootWin.viewer.dispatchEvent({type:'createIframe', window}); //给祖先页面发送信息
 	} 
 	/* window.addEventListener('focus',()=>{
 	    console.log('focus',window.winIndex)
@@ -151183,8 +151253,7 @@ ENDSEC
 	            
 	        }); 
 	        
-	        
-	        
+	         
 	        
 	        if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
 	              
@@ -153561,7 +153630,7 @@ ENDSEC
 	            } 
 	            
 	            if(needSResize){
-	                this.emitResizeMsg( { viewport:view} );
+	                this.ifEmitResize( { viewport:view} );
 	            } 
 	             
 	            viewer.dispatchEvent({type: "render.begin",  viewer: viewer, viewport:view, params });
@@ -154116,12 +154185,12 @@ ENDSEC
 	            position = new Vector3, //相机最终位置
 	            dis;                          //相机距离目标
 	        duration = duration == void 0 ? 1200 : duration;      
-	        let camera = viewer.scene.getActiveCamera();
+	        let camera = o.endCamera || viewer.scene.getActiveCamera();
 	        let cameraPos = camera.position.clone();
-	         
-	        if(camera.type == 'OrthographicCamera'){
+	        let boundSize;   
+	        /* if(camera.type == 'OrthographicCamera'){
 	            return console.error('focusOnObject暂不支持OrthographicCamera。因情况复杂,请视情况使用splitScreenTool.viewportFitBound')
-	        }
+	        } */
 	        
 	        let getPosWithFullBound = (points, boundingBox, target, cameraPos  )=>{//使boundingBox差不多占满屏幕时的相机到target的距离
 	            // points 和 boundingBox 至少有一个
@@ -154150,7 +154219,7 @@ ENDSEC
 	                bound = boundingBox.applyMatrix4(inv);
 	                scale = 0.9; 
 	            }
-	            let boundSize = bound.getSize(new Vector3);
+	            boundSize = bound.getSize(new Vector3);
 	            
 	            
 	            {
@@ -154161,14 +154230,16 @@ ENDSEC
 	                boundSize.x = Math.max(min, boundSize.x);
 	                boundSize.y = Math.max(min, boundSize.y);
 	            }
-	            
-	            
-	            let aspect = boundSize.x / boundSize.y;
-	            if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
-	                dis = boundSize.y/2/ Math.tan(MathUtils.degToRad(camera.fov / 2)) + boundSize.z/2; 
-	            }else {
-	                let hfov = cameraLight.getHFOVForCamera(camera, true);
-	                dis = boundSize.x/2 / Math.tan(hfov / 2) + boundSize.z/2;
+	            if(camera.type == 'OrthographicCamera'){
+	                dis = boundSize.length() / 2;
+	            }else {     
+	                let aspect = boundSize.x / boundSize.y;
+	                if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
+	                    dis = boundSize.y/2/ Math.tan(MathUtils.degToRad(camera.fov / 2)) + boundSize.z/2; 
+	                }else {
+	                    let hfov = cameraLight.getHFOVForCamera(camera, true);
+	                    dis = boundSize.x/2 / Math.tan(hfov / 2) + boundSize.z/2;
+	                }
 	            }
 	            dis = Math.max(0.1,dis);
 	            
@@ -154455,7 +154526,10 @@ ENDSEC
 	            }
 	        }else if(object.boundingBox && type == 'boundingBox'){//使屏幕刚好看全boundingBox
 	            target = object.boundingBox.getCenter(new Vector3);
-	            position = getPosWithFullBound(object.points, object.boundingBox, target, cameraPos  );
+	            if(o.dir){ //指定方向
+	                cameraPos.copy(target).sub(o.dir);
+	            }  
+	            position = getPosWithFullBound(object.points, object.boundingBox.clone(), target, cameraPos  );
 	            if(Potree.settings.displayMode == 'showPanos'){//全景 (比较难校准)
 	                let pano = viewer.images360.fitPanoTowardPoint({ 
 	                    point : position,
@@ -154484,21 +154558,33 @@ ENDSEC
 
 
 	 
-	         
-	            
-	        /*} else if(dimension == 2){//线
-	            
-	        }else if(dimension == 3){//面
-	            
-	        }else{//立体
-	            
-	        } */
-
-	        viewer.scene.view.setView({position, target, duration, callback:()=>{
-	                //console.log('focusOnObjectSuccess: '+object.name,  type)
-	                deferred.resolve();
+	        if(o.startCamera && o.endCamera){
+	            viewer.scene.view.tranCamera(this.mainViewport,  { endPosition:position, target ,
+	                boundSize, 
+	                callback:()=>{
+	                    //console.log('focusOnObjectSuccess: '+object.name,  type)
+	                    deferred.resolve();
+	                }, startCamera:o.startCamera, endCamera:o.endCamera, midCamera:this.scene.cameraBasic,
+	                endYaw:o.endYaw,  endPitch:o.endPitch
+	            }, duration); 
+	        }else if(camera.type == "OrthographicCamera"){   
+	            viewer.scene.view.moveOrthoCamera(this.mainViewport,  { endPosition:position, target ,
+	                boundSize, 
+	                endYaw:o.endYaw,  endPitch:o.endPitch,
+	                callback:()=>{
+	                    //console.log('focusOnObjectSuccess: '+object.name,  type)
+	                    deferred.resolve();
+	                }, 
+	            }, duration);
+	        }else { 
+	            viewer.scene.view.setView({position, target, duration,
+	                endYaw:o.endYaw,  endPitch:o.endPitch,
+	                callback:()=>{
+	                    //console.log('focusOnObjectSuccess: '+object.name,  type)
+	                    deferred.resolve();
+	                }
 	            }
-	        });
+	        );}
 	         
 	        this.dispatchEvent({type:'focusOnObject', CamTarget:target, position}); //给controls发送信息
 	        

Datei-Diff unterdrückt, da er zu groß ist
+ 1 - 1
public/lib/potree/potree.js.map


+ 1 - 1
src/sdk/cover/index.js

@@ -58,7 +58,7 @@ export const enter = (dom, isLocal) => {
                 viewer.setDisplay(false  )
                 
                 let rootWin = Potree.Common.getRootWindow()
-                rootWin.viewer.setDisplay(true )//恢复主页的模型显示
+                rootWin && rootWin.viewer.setDisplay(true )//恢复主页的模型显示
             }
         }
     }