xzw 2 gadi atpakaļ
vecāks
revīzija
6398736713
2 mainītis faili ar 243 papildinājumiem un 67 dzēšanām
  1. 242 66
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map

+ 242 - 66
public/lib/potree/potree.js

@@ -737,7 +737,7 @@
         originDatasetId:'',//场景原本的数据集id,应该就是数据集第一个吧
         isOfficial:false,
         webSite:'testdata',//正式:'datav1', //不同环境对应的静态文件的地址不同
-        
+         
         isLocal:false, //是否本地 局域网版本
         libsUrl:'../libs/',
         displayMode:'',
@@ -53692,9 +53692,16 @@
         getAngle:function(vec1, vec2, axis){//带方向的角度 vector3
             var angle = vec1.angleTo(vec2);
             var axis_ = vec1.clone().cross(vec2);
-            if(axis_[axis] < 0){
-                angle *= -1;
+            if(typeof axis == 'string'){
+                if(axis_[axis] < 0){
+                    angle *= -1;
+                }
+            }else {//vector3
+                if(axis_.dot(axis)< 0){
+                    angle *= -1;
+                }
             }
+            
             return angle
         }, 
         
@@ -116029,10 +116036,6 @@ ENDSEC
     };
      */
 
-    //import {Utils} from "../../utils.js";
-        
-     
-
     var TransformControls = function ( camera, domElement, options ) {
 
     	if ( domElement === undefined ) {
@@ -116167,7 +116170,13 @@ ENDSEC
             },10);
 
     	}
-
+        
+        
+        
+        this.setRotateMethod = function(number){//add  注意为2时 旋转期间不能改变位置 space可能不能为local ._gizmo.hideAxis = {  rotate:[这里必须包含'e' ] } 
+            this.rotateMethod = number;
+            
+        };
     	this.dispose = function () {
 
     		domElement.removeEventListener( "mousedown", onPointerDown );
@@ -116215,7 +116224,7 @@ ENDSEC
     		return this;
 
     	};
-        
+        //this.space = 'local'
         
         /* this.hideAxis = function ( mode, axis=[] ) {//xzw add 设置不可见的axis
 
@@ -116270,7 +116279,7 @@ ENDSEC
      
     	// updateMatrixWorld  updates key transformation variables
     	this.updateMatrixWorld = function () {
-     
+            if(!this.visible)return//add
     		if ( this.object !== undefined ) {
 
     			this.object.updateMatrixWorld();
@@ -116322,7 +116331,7 @@ ENDSEC
                 );
 
 
-                var intersect = ray.intersectObjects( _gizmo.picker[ this.mode ].children, true )[ 0 ] || false;
+                var intersect = ray.intersectObjects( _gizmo.picker[ this.mode ].children.filter(e=>e.visible), true )[ 0 ] || false;
 
                 if ( intersect ) {
 
@@ -116639,49 +116648,112 @@ ENDSEC
 
 
     		} else if ( mode === 'rotate' ) {
+                if(this.rotateMethod == 2){//新版参照transfromTool的写法,但是有bug,在同时移动位置时或e轴上有问题
+                    if ( axis === 'E' ) {//绕着视线转
 
-    			offset.copy( pointEnd ).sub( pointStart );
+                        rotationAxis.copy( eye );//旋转轴
+                        rotationAngle = pointEnd.angleTo( pointStart );
 
-    			var ROTATION_SPEED = 2 / worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
+                        startNorm.copy( pointStart ).normalize();
+                        endNorm.copy( pointEnd ).normalize();
 
-    			if ( axis === 'E' ) {
+                        rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 ); //角度
 
-    				rotationAxis.copy( eye );
-    				rotationAngle = pointEnd.angleTo( pointStart );
+                    }else {
+                        if ( axis === 'XYZE' ) {//像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
+                            offset.copy( pointEnd ).sub( pointStart );
+                            rotationAxis.copy( offset ).cross( eye ).normalize();
+                        }else {
+                            rotationAxis.copy( _unit[ axis ] );
+                        }
+                        let center = new Vector3;//坐标轴位置
+                        if(this.object.boundingBox){
+                            this.object.boundingBox.getCenter(center).applyMatrix4(this.object.matrixWorld);
+                        }else {
+                            center.copy(worldPositionStart);//boundingBox中心可能变化 这里可能要改成直接获取model的position
+                        }
+                         
 
-    				startNorm.copy( pointStart ).normalize();
-    				endNorm.copy( pointEnd ).normalize();
+                         
+                        let rotationAxis_ = space === 'local' ? rotationAxis.clone().applyQuaternion(worldQuaternion) : rotationAxis;
+                        let plane = new Plane().setFromNormalAndCoplanarPoint(rotationAxis_, center);//旋转过程中rotationAxis不会变化,但center可能会
+                         
+                        
+                        let {origin, direction} = viewer.inputHandler.getMouseDirection();  
+                        ray.set(origin,  direction); 
+                        let I = ray.ray.intersectPlane(plane, new Vector3());
+                        
+                        if (I) { 
+                             
+                            let v2 = I.clone().sub(center);//.normalize();
+                             
+                            if(!this.rotateStart){ 
+                                this.rotateStart = {
+                                    v1: v2
+                                };
+                                return 
+                            
+                            }
+                            let v1 = this.rotateStart.v1;
+                            
+                            rotationAngle = math.getAngle(  v1, v2, rotationAxis_); 
+                            console.log(rotationAngle);
+                            if (Number.isNaN(rotationAngle)) {
+                                return;
+                            }
+     
+                            this.rotateStart.v1 = v2;
+                        } 
+                    } 
+                    
+                }else {
+                    //pointStart 是起始intersect - object中心的向量
+                    //pointEnd 是当前intersect - object中心的向量
+                    offset.copy( pointEnd ).sub( pointStart );
 
-    				rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 );
+                    var ROTATION_SPEED = 2 / worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
 
-    			} else if ( axis === 'XYZE' ) {
+                    if ( axis === 'E' ) {//绕着视线转
 
-    				rotationAxis.copy( offset ).cross( eye ).normalize();
-    				rotationAngle = offset.dot( _tempVector.copy( rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
+                        rotationAxis.copy( eye );//旋转轴
+                        rotationAngle = pointEnd.angleTo( pointStart );
 
-    			} else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
+                        startNorm.copy( pointStart ).normalize();
+                        endNorm.copy( pointEnd ).normalize();
 
-    				rotationAxis.copy( _unit[ axis ] );
+                        rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 ); //角度
 
-    				_tempVector.copy( _unit[ axis ] );
+                    } else if ( axis === 'XYZE' ) {//像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
 
-    				if ( space === 'local' ) {
+                        rotationAxis.copy( offset ).cross( eye ).normalize();
+                        rotationAngle = offset.dot( _tempVector.copy( rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
 
-    					_tempVector.applyQuaternion( worldQuaternion );
+                    } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
 
-    				}
+                        rotationAxis.copy( _unit[ axis ] );
 
-    				rotationAngle = offset.dot( _tempVector.cross( eye ).normalize() ) * ROTATION_SPEED;
+                        _tempVector.copy( _unit[ axis ] );
 
-    			}
+                        if ( space === 'local' ) {
+
+                            _tempVector.applyQuaternion( worldQuaternion );
+
+                        }
 
-    			// Apply rotation snap
+                        rotationAngle = offset.dot( _tempVector.cross( eye ).normalize() ) * ROTATION_SPEED;
 
-    			if ( this.rotationSnap ) rotationAngle = Math.round( rotationAngle / this.rotationSnap ) * this.rotationSnap;
+                    }
+
+                    // Apply rotation snap
 
-    			this.rotationAngle = rotationAngle;
+                    if ( this.rotationSnap ) rotationAngle = Math.round( rotationAngle / this.rotationSnap ) * this.rotationSnap;
+
+                    this.rotationAngle = rotationAngle;
+                }
 
-    			// Apply rotate
+    			 
+                
+                // Apply rotate
     			if ( space === 'local' && axis !== 'E' && axis !== 'XYZE' ) {
                     object.scale[axis.toLowerCase()] < 0 && (rotationAngle *= -1); //xzw 加,否则会反向 
     				object.quaternion.copy( quaternionStart );
@@ -116695,6 +116767,11 @@ ENDSEC
 
     			}
                 
+                
+                if ( this.rotateMethod == 2 && axis != 'E' ) {
+                    quaternionStart.copy(object.quaternion);
+                }
+                
                 //add:
                 
                 object.dispatchEvent({
@@ -116723,7 +116800,7 @@ ENDSEC
                     this.player.cameraControls.activeControl.pointerDragOn = false //add 
                     this.player.cameraControls.activeControl.enabled = true
                 } */
-
+                this.rotateStart = null;//add
 
     		}
 
@@ -117305,7 +117382,7 @@ ENDSEC
     	// updateMatrixWorld will update transformations and appearance of individual handles
 
     	this.updateMatrixWorld = function () {
-
+            if(!this.parent.visible)return //add
     		var space = this.space;
 
     		if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
@@ -117810,7 +117887,7 @@ ENDSEC
     	var identityQuaternion = new Quaternion();
 
     	this.updateMatrixWorld = function () {
-
+            if(!this.visible)return//add 
             var space = this.space;
 
     		this.position.copy( this.worldPosition );
@@ -118002,6 +118079,9 @@ ENDSEC
                 //this.transformControls.space = 'local'//为了在当前方向上平移
                 this.transformControls.setSize(1.5);
                 viewer.scene.scene.add(this.transformControls);
+                this.transformControls._gizmo.hideAxis = {rotate:['e']};
+                this.transformControls.setRotateMethod(2);
+                
                 
                 //右屏
                 this.transformControls2 = new TransformControls(viewer.mainViewport.camera, viewer.renderArea,{ 
@@ -118256,7 +118336,7 @@ ENDSEC
             } */
             this.transformControls.camera = viewer.viewports[0].camera;
             this.transformControls.view = viewer.viewports[0].view; 
-            this.transformControls._gizmo.hideAxis = {};
+            this.transformControls._gizmo.hideAxis = {rotate:['e']};
             viewer.setObjectLayers(this.transformControls, 'sceneObjects' );  //恢复
             
             
@@ -122087,7 +122167,7 @@ ENDSEC
 
     const texLoader$c = new TextureLoader(); 
         texLoader$c.crossOrigin = "anonymous"; 
-        
+    const rotQua = new Quaternion().setFromAxisAngle(new Vector3(0,0,1), Math.PI);    
     const lineMats$3 = {};
     const circleMats = {};
 
@@ -122121,8 +122201,6 @@ ENDSEC
         }  
     ];   
 
-     
-
 
 
 
@@ -122165,7 +122243,55 @@ ENDSEC
                  
             }
         
-        
+            {
+                this.transformControls = new TransformControls(viewer.mainViewport.camera, viewer.renderArea,{
+                    dontHideWhenFaceCamera: true,
+                }); 
+                this.transformControls.setSize(1.5);
+                viewer.scene.scene.add(this.transformControls);
+                this.transformControls._gizmo.hideAxis = {translate:[], rotate:['x','y','e'] };
+                this.transformControls.setRotateMethod(2);
+                
+                this.fakeMarkerForTran = new Mesh(new BoxBufferGeometry(0.3,0.3,0.3) , new MeshBasicMaterial({
+                    color:"#FFFFFF",  opacity:0.4,  transparent:true, visible:false
+                }));//一个看不见的mesh,只是为了让transformControls移动点云
+                viewer.scene.scene.add(this.fakeMarkerForTran);
+                
+                
+           
+                let afterMoveCircle = (type)=>{
+                      
+                    if(type == 'position'){
+                        let moveVec = new Vector3().subVectors(this.fakeMarkerForTran.position, this.fakeMarkerForTran.oldState.position);
+                        this.selectedClouds.forEach(cloud=>Alignment$1.translate(cloud, moveVec));
+                    }else {
+                        let center = this.selectedPano.position;
+                        let forward = new Vector3(0,1,0);
+                        let vec1 = forward.clone().applyQuaternion(this.fakeMarkerForTran.oldState.quaternion);
+                        let vec2 = forward.clone().applyQuaternion(this.fakeMarkerForTran.quaternion);
+                         
+                        let diffAngle = math.getAngle(vec1,vec2,'z');    
+                            
+                        this.selectedClouds.forEach(cloud=>{ 
+                            Alignment$1.rotateAround(center, cloud, null, diffAngle);    
+                        });
+                    }
+                    
+                    
+                    this.fakeMarkerForTran.oldState = {
+                        position: this.fakeMarkerForTran.position.clone(),
+                        quaternion: this.fakeMarkerForTran.quaternion.clone(),
+                    };
+                };
+                 
+                this.fakeMarkerForTran.addEventListener('position_changed', afterMoveCircle.bind(this,'position')); 
+                this.fakeMarkerForTran.addEventListener("rotation_changed", afterMoveCircle.bind(this,'rotation') );
+              
+                
+            }
+            
+            
+            
             this.initViews();
             
             
@@ -122215,8 +122341,12 @@ ENDSEC
                          this.setLinkOperateState('addLink',false);
                          this.setLinkOperateState('removeLink',false);
                     }else if(this.clickToZoomInEnabled){
-                            
-                        this.zoomIn(e.intersect.orthoIntersect, e.pointer);
+                        if(this.activeViewName == 'mainView'){
+                            viewer.controls.zoomToLocation(e.mouse);
+                        }else {
+                            this.zoomIn(e.intersect.orthoIntersect, e.pointer);
+                        }
+                         
                          
                         this.setZoomInState(false);
                     }
@@ -122271,7 +122401,32 @@ ENDSEC
         }
         
         
-                    
+        setTranMode(mode){//rotate or translate 
+            this.tranMode = mode;
+            if(this.activeViewName == 'mainView'){
+                mode && this.transformControls.setMode(mode);
+                this.updateTranCtl(); 
+            }else {
+                Alignment$1.switchHandle(mode); 
+            } 
+        }
+        
+        updateTranCtl(){// 设置3D页面的transformControls相关
+            if(!this.tranMode || !this.selectedPano || this.activeViewName != 'mainView' ) {
+                return this.transformControls.detach() 
+            }else if(this.checkIfAllLinked({group:this.selectedGroup})){
+                this.dispatchEvent('needToDisConnect');
+                return this.transformControls.detach()
+            }
+            this.transformControls.attach(this.fakeMarkerForTran);
+            let {position, quaternion} = this.getPanoPose(this.selectedPano);
+            this.fakeMarkerForTran.position.copy(position);
+            this.fakeMarkerForTran.quaternion.copy(quaternion);
+            this.fakeMarkerForTran.oldState = {
+                position: position.clone(),
+                quaternion: quaternion.clone(),
+            };
+        }
         
         
          
@@ -122331,7 +122486,7 @@ ENDSEC
                      
                 });
                 viewer.updateVisible(viewer.reticule, 'force', true);
-                
+                 
                 if(lastView){
                     
                     view.copy(lastView);
@@ -122390,7 +122545,11 @@ ENDSEC
                  
             } 
             
+            
+            this.updateTranCtl();
+            this.setTranMode(); // update
             this.setZoomInState(false); //取消放大模式
+            
         }
         
         
@@ -122441,7 +122600,7 @@ ENDSEC
         
         
         rotateSideCamera(angle){//侧视图绕模型中心水平旋转
-             this.splitScreenTool.rotateSideCamera(viewer.mainViewport, angle); 
+            this.splitScreenTool.rotateSideCamera(viewer.mainViewport, angle); 
         }
         
         /* rotateSideCamera(angle){//侧视图绕模型中心水平旋转
@@ -122511,7 +122670,7 @@ ENDSEC
         }
         
         setZoomInState(state, informinformBy2d){//是否点击后可放大
-            if(state && this.activeViewName == 'mainView')return console.log('3D不可放大')
+            //if(state && this.activeViewName == 'mainView')return console.log('3D不可放大')
             this.clickToZoomInEnabled = !!state;
         
         
@@ -122868,6 +123027,9 @@ ENDSEC
         
         
         
+                    
+                 
+        
         addPanoMesh(){ 
             let map = texLoader$c.load(Potree.resourcePath+'/textures/correct_n.png' );  
             circleMats.default = new MeshBasicMaterial({
@@ -122924,7 +123086,6 @@ ENDSEC
                 this.panoMeshs.add(circle);
                 
                 
-                
                 setPos(circle); 
                 pano.addEventListener('rePos', setPos.bind(this,circle));
                    
@@ -123020,15 +123181,14 @@ ENDSEC
                 this.selectedPano.circle.material = circleMats.default; 
                 this.selectedPano.circle.renderOrder = renderOrders$1.circle; 
 
-                if(this.activeViewName != 'mainView'){
+                if(this.activeViewName == 'mainView'){
+                     
+                }else {
                     this.selectedClouds.forEach(e=>{
                         e.changePointOpacity(opacitys.default,true);
                         e.material.color = pointColor.default;  
                     });
-                    
-                    //this.selectedPano.pointcloud.changePointOpacity(opacitys.default,true)
-                    //this.selectedPano.pointcloud.material.color = Potree.config.material.pointColor
-                } 
+                }
                  
             }
          
@@ -123039,9 +123199,10 @@ ENDSEC
             if(pano){
                 this.selectedPano.circle.material = circleMats.selected;  
                 this.selectedPano.circle.renderOrder = this.selectedPano.circle.pickOrder = renderOrders$1.circleSelected; //侧视图能显示在最前
-                //this.selectedPano.pointcloud.material.color = '#ff0000'
-                //this.selectedPano.pointcloud.changePointOpacity(opacitys.selected,true) 
-                if(this.activeViewName != 'mainView'){
+                 
+                if(this.activeViewName == 'mainView'){
+                    
+                }else {
                     this.selectedClouds.forEach(e=>{
                         e.changePointOpacity(opacitys.selected,true);
                         e.material.color = pointColor.selected;  
@@ -123067,9 +123228,8 @@ ENDSEC
             }
             
             
-            this.updateCursor();
-
-
+            this.updateCursor(); 
+            this.updateTranCtl();
 
 
             if(informinformBy2d){
@@ -123125,14 +123285,25 @@ ENDSEC
                 group = this.panoGroup.find(panos=>panos[0].pointcloud.dataset_id == datasetId );
                 if(!group)return //要找的数据集的pano全部都孤立了
             }
-            
+            if(!datasetId)return
             let panos = Potree.settings.datasetsPanos[datasetId].panos;
             return panos.length == group.length
         }
         
+       
+        
+        getPanoPose(pano){
+            let pose = {
+                position:  pano.position.clone(),
+                quaternion:  new Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua)  ,
+            };
+            return pose
+            
+        }
+        
         exportSavingData(){//输出漫游点新的坐标和朝向、以及连接信息
             let sweepLocations = {};
-            let rotQua = new Quaternion().setFromAxisAngle(new Vector3(0,0,1), Math.PI);
+            
             for(let datasetId in Potree.settings.datasetsPanos ) {
                 let {panos} = Potree.settings.datasetsPanos[datasetId];
                 let data = panos.map(pano=>{
@@ -123142,13 +123313,18 @@ ENDSEC
                             visibles.push(viewer.images360.getPano(id).index);
                         }
                     }
-                    
+                    let {position, quaternion} = this.getPanoPose(pano);
                     return Object.assign({},  pano.panosData,  {
                         uuid: pano.uuid, 
-                        pose:{
-                            translation: dealData(pano.position.clone()/* .negate() */),
-                            rotation: dealData(new Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua)  ),
+                        /* pose:{
+                            translation: dealData(pano.position.clone() ),
+                            rotation: dealData(new THREE.Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua)  ),
+                        }, */
+                        pose : { 
+                            translation : dealData(position), 
+                            rotation : dealData(quaternion) 
                         },
+                        
                         visibles,
                         
                         //subgroup: 0,group: 1, "id_view":..

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
public/lib/potree/potree.js.map