Explorar o código

fix: 经纬度初始位置

xzw hai 7 meses
pai
achega
10e61e3a76
Modificáronse 3 ficheiros con 96 adicións e 33 borrados
  1. 65 20
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map
  3. 30 12
      src/sdk/cover/index.js

+ 65 - 20
public/lib/potree/potree.js

@@ -22072,29 +22072,75 @@
 	    var loadDone = model => {
 	      model.dataset_id = prop.id; //唯一标识
 
-	      if (prop.position) {
-	        if (prop.position.x != 0 || prop.position.y != 0 || prop.position.z != 0) {
-	          //移动过后使用移动后的坐标
-	          model.position.copy(prop.position);
-	        } else {
-	          //用户没设置位置(首次添加后没按保存)
-	          if (!model.isPointcloud && prop.raw.wgs84) {
-	            //有经纬度   
-	            var locationLonLat = prop.raw.wgs84.split(',').map(e => parseFloat(e));
-	            var location = viewer.transform.lonlatToLocal.forward(locationLonLat);
-	            MergeEditor.moveBoundCenterTo(model, new Vector3().fromArray(location));
+	      {
+	        //设置下默认经纬度位置,当点击恢复默认时要恢复到此位置
+
+	        if (!model.isPointcloud) {
+	          //有经纬度    3dtiles
+	          model.rotation.copy(prop.baseRotation); //有的需要翻转90度 
+	          var lonlat = prop.raw.wgs84 || prop.raw.rtkLocation; //前者为素材库的osgb的
+	          if (lonlat) {
+	            var locationLonLat = lonlat.split(',').map(e => parseFloat(e));
+	            var location = new Vector3().fromArray(viewer.transform.lonlatToLocal.forward(locationLonLat));
 	            model.hasLonLat = true;
-	            model.lonLatPos = model.position.clone();
-	          }
-	          if (model.fileType == 'shp') {
-	            if (model.prjNotSure) {
-	              MergeEditor.moveBoundCenterTo(model, new Vector3()); //因为不确定坐标类型,而点坐标可能几万米,所以放原点好一些
+	            if (model.fileType == '3dTiles' && prop.is4dkkModel) {
+	              //深时深光mesh
+	              model.position.fromArray(model.runtime.getTileset().tileset.root.boundingVolume.box.slice(0, 3)); //必须要平移一段才能重合 
+	              model.position.copy(Potree.math.convertVector.ZupToYup(model.position));
+
+	              //饶原点旋转  类似Alignment.setMatrix 和点云一样处理 
+	              if (prop.raw.orientation) {
+	                model.updateMatrixWorld(); //此时和点云没有旋转平移时一样。
+	                var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0, 0, 1), parseFloat(prop.raw.orientation));
+	                var pos2Matrix = new Matrix4().setPosition(location); //最后是平移
+	                var matrix = new Matrix4().multiplyMatrices(pos2Matrix, rotMatrix);
+	                model.matrix.premultiply(matrix);
+	                model.matrix.decompose(model.position, model.quaternion, model.scale);
+	              } else {
+	                model.position.add(location);
+	              }
 	            } else {
-	              model.hasLonLat = true;
-	              model.lonLatPos = model.position.clone();
+	              MergeEditor.moveBoundCenterTo(model, location);
+	              if (prop.raw.orientation) {
+	                model.rotation.y = parseFloat(prop.raw.orientation);
+	              }
+	              if (model.is4dkkModel) {
+	                console.warn('遇到is4dkkModel的且有经纬度的mesh,但不是3dtiles! 位置估计不准', model);
+	                /* if(model.panos?.length){//只能通过漫游点经纬度来校准 
+	                    //但这时候panos还没加载。。。。
+	                    let sceneCode = ...从url中解析
+	                    Potree.loadDatasets((data)=>{ //获取datasetId
+	                        let originDataset = data.find(e=>e.sceneCode == sceneCode);//只加载初始数据集  
+	                        Potree.loadPanos(originDataset.datasetId)
+	                     
+	                  }, sceneCode, (e)=>{
+	                    console.log(e)
+	                  } , prop.prefix)
+	                    
+	                    
+	                } */
+	              }
 	            }
 	          }
-	          MergeEditor.setModelBtmHeight(model, 0.1); // 离地高度为0 (因为不想在地图下方所以高程不管了,都在地面上即可)
+	        }
+	        if (model.fileType == 'shp') {
+	          if (model.prjNotSure) {
+	            MergeEditor.moveBoundCenterTo(model, new Vector3()); //因为不确定坐标类型,而点坐标可能几万米,所以放原点好一些
+	          }
+	          model.hasLonLat = true;
+	        }
+	        MergeEditor.setModelBtmHeight(model, 0); // 离地高度为0 (因为不想在地图下方所以高程不管了,都在地面上即可)
+
+	        if (model.hasLonLat) {
+	          model.lonLatPos = model.position.clone();
+	          model.lonLatRot = model.rotation.clone();
+	        }
+	      }
+	      if (prop.position) {
+	        if (prop.position.x != 0 || prop.position.y != 0 || prop.position.z != 0) {
+	          //移动过后使用移动后的坐标
+	          model.position.copy(prop.position);
+	        } else {//用户没设置位置(首次添加后没按保存)
 	        }
 	      }
 	      if (prop.rotation && (prop.rotation.x != 0 || prop.rotation.y != 0 || prop.rotation.z != 0)) {
@@ -22289,7 +22335,6 @@
 	          pointcloud.matrixAutoUpdate = true;
 	          if (pointcloud.hasLonLat) {
 	            pointcloud.matrix.decompose(pointcloud.position, pointcloud.quaternion, pointcloud.scale); //将数据集的经纬度和旋转应用到rotation和position (注意position和translateUser并不一样)
-	            pointcloud.lonLatPos = pointcloud.position.clone();
 	          } else if (!prop.isFirstLoad) {
 	            //点云一般加载后position都不是0, 但后台初始化为0所以先归零要不然撤销后容易错
 	            pointcloud.position.set(0, 0, 0);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
public/lib/potree/potree.js.map


+ 30 - 12
src/sdk/cover/index.js

@@ -867,24 +867,37 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
 
 
         addModel(props) {
+            let model
             let bus = props.bus = mitt()
             //console.log('--addModel',props)
             props.isFirstLoad = isLocal ? props.bottom == void 0 : (props.isDynamicAdded || props.mode == 'single')  // 在编辑时用户添加的 或 展示单个模型 (props.mode='single'模型展示页, props.mode='many'融合页)
             if (props.opacity == void 0) props.opacity = 1
             if (props.type == 'obj') props.type = 'glb'
             props.scale /= 100
-            if (props.rotation) {
-                if (props.rotation._x == void 0 && props.rotation.x != void 0) {
-                    props.rotation = new THREE.Euler().setFromVector3(props.rotation)
-                }
-            }
-            let getDefaultRotation = () => {
+            
+            let getBaseRotation = () => {
                 if(ModelTypes[props.fromType]?.rot90 && props.type != 'glb'){
                     return new THREE.Euler(Math.PI / 2, 0, 0)
                 } else return new THREE.Euler(0, 0, 0)
             }
-
-
+            let getDefaultRotation = () => { 
+                if(model.lonLatRot){ 
+                    return model.lonLatRot
+                }else{
+                    return getBaseRotation() 
+                } 
+            }
+            
+            if (props.rotation) {
+                if (props.rotation._x == void 0 && props.rotation.x != void 0) {
+                    props.rotation = new THREE.Euler().setFromVector3(props.rotation)
+                }
+            } 
+            props.baseRotation = getBaseRotation()
+            
+            props.is4dkkModel = ModelTypes[props.fromType].panos4dkk
+            
+            
             if (!props.isFirstLoad) {
                 if (autoLoads.length == 0) { //首次加载
                     setTimeout(() => {
@@ -906,7 +919,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
             } else {
                 readyToAddModel = true
 
-                props.rotation = getDefaultRotation()
+                
             }
 
 
@@ -918,7 +931,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
 
             
 
-            let model
+            
             let done = (model_) => {
                 model = model_
                 model.result_ = result
@@ -969,7 +982,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                     }, 1)
                 }
                 if(ModelTypes[props.fromType].panos4dkk){
-                    Potree.load4dkkPanos(props.raw.num, model, getDefaultRotation(), () => {
+                    Potree.load4dkkPanos(props.raw.num, model, getBaseRotation(), () => {
                         bus.emit('loadDone')
                     },    props.fromType == 0 ? '2k' : '4k' ) //看看场景是2k
                 } else {
@@ -1099,7 +1112,12 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                 },
                 changeRotation(rot) {//校准取消时执行 
                     //console.log('changeRotation', model.name, rot.x, rot.y, rot.z)
-                    model && model.rotation.setFromVector3(rot)
+                    /* if(rot.x == 0 && rot.y == 0 && rot.z == 0 && model.lonLatRot ){
+                        model && model.rotation.copy(model.lonLatRot)
+                        console.log('changePosition 使用经纬度坐标', model.name )
+                    }else{ */
+                        model && model.rotation.setFromVector3(rot)
+                    //} 
                     model.dispatchEvent({ type: 'rotation_changed' , by2d:true})
                 },