ソースを参照

fix: 删了模型的路径不删除了

xzw 7 ヶ月 前
コミット
04fc8d2221
3 ファイル変更124 行追加72 行削除
  1. 95 53
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map
  3. 28 18
      src/sdk/cover/index.js

+ 95 - 53
public/lib/potree/potree.js

@@ -70613,9 +70613,22 @@
 	            this.updateMemoryUsage()
 	        },{once:true})  
 	    }) */
-
-	    this.changeModelPointCount(model, 'add');
-	    this.updateMemoryUsage();
+	    var weightUpdate = () => {
+	      this.changeModelPointCount(model, 'add');
+	      this.updateMemoryUsage();
+	    };
+	    if (model.fileType == 'obj') {
+	      //要等待贴图都加载完
+	      if (viewer.fileManager.loading) {
+	        viewer.addEventListener('managerOnLoad', e => {
+	          weightUpdate();
+	        }, {
+	          once: true
+	        }); //如果onError了咋办,暂时无法定位manager加载的哪个模型的
+	      }
+	    } else {
+	      weightUpdate();
+	    }
 	  },
 	  removeModel(model) {
 	    var _model$panos;
@@ -78264,8 +78277,7 @@
 	 *
 	 *
 	 */
-	var minRadius = 2,
-	  maxRadius = 300;
+	var standartMinRadius = 2;
 	class OrbitControls$1 extends EventDispatcher {
 	  constructor(viewer, viewport) {
 	    super();
@@ -78290,6 +78302,8 @@
 	    this.tweens = [];
 	    this.dollyStart = new Vector2();
 	    this.dollyEnd = new Vector2();
+	    this.minRadius = standartMinRadius;
+	    this.maxRadius = 300;
 	    this.keys = {
 	      FORWARD: ['W'.charCodeAt(0), 38],
 	      BACKWARD: ['S'.charCodeAt(0), 40],
@@ -78362,6 +78376,7 @@
 	      var resolvedRadius = this.currentViewport.view.radius + this.radiusDelta;
 	      this.radiusDelta += -e.delta * resolvedRadius * 0.1;
 	      this.stopTweens();
+	      this.updateRadius();
 	    };
 	    var dblclick = e => {
 	      if (!this.enabled) return;
@@ -78446,28 +78461,10 @@
 	    this.viewer.addEventListener('focusOnObject', o => {
 	      if (o.position && o.CamTarget) {
 	        var distance = o.position.distanceTo(o.CamTarget);
-	        if (distance < minRadius) minRadius = distance * 0.5; //融合页面当focus一个很小的物体时,需要将minRadius也调小
-	      }
-	    });
-	    this.viewer.addEventListener('camera_changed', e => {
-	      if (e.viewport == this.currentViewport) {
-	        var _viewer$inputHandler$, _viewer$inputHandler$2;
-	        var model = ((_viewer$inputHandler$ = viewer.inputHandler.intersect) === null || _viewer$inputHandler$ === void 0 ? void 0 : _viewer$inputHandler$.object) || ((_viewer$inputHandler$2 = viewer.inputHandler.intersect) === null || _viewer$inputHandler$2 === void 0 ? void 0 : _viewer$inputHandler$2.pointcloud);
-	        if (model) this.updateRadiusByModel(model, viewer.inputHandler.intersect.location.distanceTo(this.currentViewport.view.position));else {
-	          /* let disToGroundInDir = Math.abs(this.currentViewport.camera.position.z / this.currentViewport.view.direction.z)  //相机和地面交点距离
-	          maxRadius = Math.max(2, disToGroundInDir*1.5)//越靠近地面速度越慢,防止移动来移动去久了之后距离模型很近但radius很大
-	          
-	          minRadius = disToGroundInDir * 0.9 //防止在高空放大很慢(注:不要把mesh放到地平线以下,否则hover mesh时很快,不hover又很慢)
-	          console.log('changeRadius common', minRadius, maxRadius) */
-	          if (!viewer.bound || viewer.bound.boundSize.x == 0) return;
-	          var boundFloor = viewer.bound.boundingBox.clone();
-	          var dis1 = boundFloor.distanceToPoint(viewer.mainViewport.view.position);
-	          boundFloor.max.z = boundFloor.min.z;
-	          var dis2 = boundFloor.distanceToPoint(viewer.mainViewport.view.position);
-	          minRadius = Math.max(2, dis1 * 0.5);
-	          maxRadius = Math.max(4, dis2 * 1.5);
-	          //console.log('changeRadius common', minRadius, maxRadius)
-	        }
+	        //if(distance < minRadius) minRadius = distance * 0.5 //融合页面当focus一个很小的物体时,需要将minRadius也调小
+	        this.minRadius = Math.min(standartMinRadius, distance * 0.5);
+	        console.log('focus dis', distance);
+	        //console.log('minRadius',this.minRadius)
 	      }
 	    });
 	  }
@@ -78559,12 +78556,26 @@
 
 	  zoomToLocation(mouse) {
 	    var I = viewer.inputHandler.intersect;
-	    if (!I) return;
-	    var object = I.object || I.pointcloud;
-	    I = I.location;
-	    if (!I || !object) return;
+	    var object;
+	    if (I) {
+	      object = I.object || I.pointcloud;
+	      I = I.location;
+	    } else {
+	      //点击空白处(地面)
+	      var {
+	        x,
+	        y
+	      } = Potree.Utils.getPointerPosAtHeight(0, viewer.inputHandler.pointer);
+	      I = new Vector3(x, y, 0);
+	    }
 	    var dis = this.currentViewport.view.position.distanceTo(I);
-	    var distance = this.updateRadiusByModel(object, dis);
+	    var distance;
+	    if (object) {
+	      distance = this.updateRadiusByModel(object, dis);
+	    } else {
+	      distance = Math.min(dis, 50); //方便从高空回到地面
+	      this.updateRadius();
+	    }
 	    viewer.focusOnObject({
 	      position: I
 	    }, 'point', null, {
@@ -78578,11 +78589,25 @@
 	    var size = bound.getSize(new Vector3());
 	    var len = size.length();
 	    var distance = MathUtils.clamp(dis, 0.8 * object.scale.x, Math.max(len * 0.1, 3 * object.scale.x));
-	    minRadius = distance;
-	    maxRadius = dis * 2;
-	    //console.log('updateRadiusByModel',minRadius, maxRadius)
+	    this.minRadius = Math.min(distance, standartMinRadius);
+	    this.maxRadius = dis * 2;
+	    console.log('maxRadius hasIntersect', this.maxRadius);
 	    return distance;
 	  }
+	  updateRadius() {
+	    var _viewer$inputHandler$, _viewer$inputHandler$2;
+	    var model = ((_viewer$inputHandler$ = viewer.inputHandler.intersect) === null || _viewer$inputHandler$ === void 0 ? void 0 : _viewer$inputHandler$.object) || ((_viewer$inputHandler$2 = viewer.inputHandler.intersect) === null || _viewer$inputHandler$2 === void 0 ? void 0 : _viewer$inputHandler$2.pointcloud);
+	    if (model) {
+	      this.updateRadiusByModel(model, viewer.inputHandler.intersect.location.distanceTo(this.currentViewport.view.position));
+	    } else {
+	      if (!viewer.bound || viewer.bound.boundSize.x == 0) return;
+	      var boundFloor = viewer.bound.boundingBox.clone();
+	      boundFloor.max.z = boundFloor.min.z;
+	      var dis2 = boundFloor.distanceToPoint(viewer.mainViewport.view.position);
+	      this.maxRadius = Math.max(4, dis2 * 5);
+	      console.log('maxRadius noIntersect', this.maxRadius);
+	    }
+	  }
 	  stopTweens() {
 	    this.tweens.forEach(e => e.stop());
 	    this.tweens = [];
@@ -78655,14 +78680,10 @@
 	      var radius = view.radius + _progression * this.radiusDelta;
 	      var _V = view.direction.multiplyScalar(-radius);
 	      var _position = new Vector3().addVectors(view.getPivot(), _V);
-	      if (radius > maxRadius) {
-	        radius = maxRadius;
-	      }
+	      radius = Math.min(radius, this.maxRadius);
 	      if (this.constantlyForward) {
-	        // 到达中心点后还能继续向前移动,也就是能推进中心点
-	        if (radius < minRadius) {
-	          radius = minRadius;
-	        }
+	        // 到达中心点后还能继续向前移动,也就是能推进中心点 
+	        radius = Math.max(radius, this.minRadius);
 	      }
 	      view.radius = radius;
 	      view.position.copy(_position);
@@ -80663,7 +80684,6 @@
 
 	 */
 
-	var manager = new LoadingManager();
 	var loaders = {};
 	var mapArea;
 	var shelterHistory = [];
@@ -80693,6 +80713,7 @@
 
 	    window.viewer = this;
 	    mapArea = mapArea_;
+	    this.setLoaders();
 	    if (this.renderer.capabilities.isWebGL2) {
 	      Potree.settings.isWebgl2 = true; //是否启用webgl2
 	    }
@@ -81095,14 +81116,7 @@
 	      this.modules.Alignment.init();
 	      this.images360 = new Images360(this);
 	      this.scene.scene.add(this.objs);
-	      loaders = {
-	        objLoader: new OBJLoader(manager),
-	        mtlLoader: new MTLLoader(manager),
-	        glbLoader: new GLTFLoader(undefined, this.renderer, Potree.settings.libsUrl),
-	        plyLoader: new PLYLoader(manager),
-	        dxfLoader: new DxfLoader(),
-	        shapeLoader: new Potree.ShapefileLoader()
-	      };
+
 	      //add test
 	      /* const environment = new RoomEnvironment();
 	      const pmremGenerator = new THREE.PMREMGenerator( this.renderer ); 
@@ -81444,7 +81458,7 @@
 	        mats.forEach(mat => {
 	          if (mat.map) {
 	            if (!mat.map.image) {
-	              console.error('!mat.map.image  ??'); //obj可能会
+	              console.error('!mat.map.image  ??', mat.map.uuid); //obj可能会
 	              return;
 	            }
 	            texArea += mat.map.image.width * mat.map.image.height;
@@ -84446,7 +84460,7 @@
 	      {
 	        boundSize.x *= scale; //稍微放大一些,不然会靠到屏幕边缘
 	        boundSize.y *= scale;
-	        var min = 0.0001;
+	        var min = 1;
 	        boundSize.x = Math.max(min, boundSize.x);
 	        boundSize.y = Math.max(min, boundSize.y);
 	      }
@@ -85508,6 +85522,34 @@
 	  } 
 	   */
 
+	  setLoaders() {
+	    this.fileManager = new LoadingManager(); //整体的load manager
+	    this.fileManager.onLoad = () => {
+	      console.log('All resources have been loaded');
+	      this.fileManager.loading = false;
+	      this.dispatchEvent('managerOnLoad');
+	      // 在这里可以执行模型渲染、动画等操作
+	    };
+
+	    // 设置加载进度的回调函数(可选)
+	    this.fileManager.onProgress = (item, loaded, total) => {
+	      if (loaded < total) this.fileManager.loading = true;
+	      console.log("Loading ".concat(item, ": ").concat(loaded, " of ").concat(total));
+	    };
+
+	    // 设置加载失败的回调函数(可选)
+	    this.fileManager.onError = url => {
+	      console.error("Failed to load resource: ".concat(url));
+	    };
+	    loaders = {
+	      objLoader: new OBJLoader(this.fileManager),
+	      mtlLoader: new MTLLoader(this.fileManager),
+	      glbLoader: new GLTFLoader(undefined, this.renderer, Potree.settings.libsUrl),
+	      plyLoader: new PLYLoader(this.fileManager),
+	      dxfLoader: new DxfLoader(),
+	      shapeLoader: new Potree.ShapefileLoader()
+	    };
+	  }
 	  modelLoaded(object) {
 	    var fileInfo_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
 	    var done = arguments.length > 2 ? arguments[2] : undefined;

ファイルの差分が大きいため隠しています
+ 1 - 1
public/lib/potree/potree.js.map


+ 28 - 18
src/sdk/cover/index.js

@@ -20,7 +20,9 @@ const ModelTypes = {
 let cesAspect , cesImageryProvider
 
 
-
+let isValidPoint = (modelId)=>{//所存的modelId没被删或者它本身不在模型上
+    return modelId == Id_noIntersect || viewer.objs.children.concat(viewer.scene.pointclouds).some(e=>e.dataset_id == modelId )
+}
 
 
 
@@ -695,7 +697,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
             map.switchStyle(type )
         }, */
         switchMapType(type){//切换成江门的卫星或标准  
-         
+             return
             console.log('switchMapType',type)
             let maximumLevel, url
             if(type == 'satellite'){
@@ -1377,16 +1379,29 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                 })
                 viewer.dispatchEvent({ type: 'cancel_insertions', dontRemove: true, measure:path }) //要等进入编辑才能继续编辑
             }else{
-                info.points_datasets = props.points.map(e=> e.modelId == Id_noIntersect ? null : e.modelId)
+                
+                let originPointCount = props.points.length
+                props.points = props.points.filter(e=> isValidPoint(e.modelId))
+                info.points_datasets = props.points.map(e=> e.modelId == Id_noIntersect ? null : e.modelId) 
                 info.dataset_points = info.points = props.points.map(e=>e.position)//当该点不在任何模型上时,记录的是世界坐标,所以两个都赋值,过后根据有无datasetID选择
+                
                 path = viewer.measuringTool.createMeasureFromData(info);
             
                 if(props.line.position) { 
-                    let pos = props.line.modelId == Id_noIntersect ? new THREE.Vector3().copy(props.line.position) : 
-                              Potree.Utils.datasetPosTransform({fromDataset:true, position: props.line.position,  datasetId: props.line.modelId })
-                    path.updateTitlePos(pos) 
+                    if(isValidPoint(props.line.modelId)){ 
+                        let pos = props.line.modelId == Id_noIntersect ? new THREE.Vector3().copy(props.line.position) : 
+                                  Potree.Utils.datasetPosTransform({fromDataset:true, position: props.line.position,  datasetId: props.line.modelId })
+                        path.updateTitlePos(pos) 
+                    }else{
+                        console.log('path label pos 因模型被删而去除', info.title )
+                    }
+                    
                 }
-                 
+                if(props.points.length < originPointCount ) {
+                    path.dispatchEvent('createDone')
+                    console.log('path点因模型被删减少', info.title, originPointCount,'->',props.points.length)
+                }
+                
             }
             {
                 let curSelectMarker 
@@ -1913,7 +1928,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
             viewer.backgroundOpacity = 0
             //密钥
             Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2ZGM2YzY0ZC1kNWE0LTRiYTgtYTkwNS1kYmJiODRjMWUwMmQiLCJpZCI6MjMzMTQ1LCJpYXQiOjE3MjI5OTUwNTB9.niqpkl6xOkQ2KeJjelyDDDydmSGqKXKb5cX2NyxSNAw'
-          console.log('buildMap 啊啊啊啊啊啊 ')  
+          
             window.cesiumViewer = new Cesium.Viewer('app', {
                 useDefaultRenderLoop: true,
                 requestRenderMode: true, //add 只有需要render时才会render,如tile加载完后、镜头移动后
@@ -1926,23 +1941,18 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                 sceneModePicker: false,
                 selectionIndicator: false,
                 timeline: false,
-                navigationHelpButton: false,
-                //imageryProvider : Cesium.createOpenStreetMapImageryProvider({url : 'https://a.tile.openstreetmap.org/'}),
-                /* imageryProvider: cesImageryProvider || new Cesium.UrlTemplateImageryProvider({ //直接用84坐标,不用转高德
-                    url: 'https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}&token=YOUR_API_KEY',
-                    minimumLevel: 0,
-                    maximumLevel: 19,
-                    crossOrigin: 'anonymous',
-                }), */
+                navigationHelpButton: false, 
                 //高德秘钥版 imageryProvider: new Cesium.AmapImageryProvider({key, mapStyle: 'normal'})
                 //报错 401 (Unauthorized) 的方法 https://blog.csdn.net/LBY_XK/article/details/121992641
 
                 //terrainShadows: Cesium.ShadowMode.DISABLED, //terrain地形
             }); 
+            
+            let satellite = true
             let imageryProvider = cesImageryProvider || new Cesium.UrlTemplateImageryProvider({ //直接用84坐标,不用转高德
-                url: '//wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}&token=YOUR_API_KEY',
+                url: `//wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=${satellite?6:7}&x={x}&y={y}&z={z}&token=YOUR_API_KEY`, //style=6是卫星,7是标准
                 minimumLevel: 0,
-                maximumLevel: 19,
+                maximumLevel: satellite?18:19,
                 crossOrigin: 'anonymous',
             }) 
             cesiumViewer.imageryLayers.removeAll();