xzw 7 months ago
parent
commit
c3e3d73c30

+ 3 - 3
src/custom/mergeStartTest.js

@@ -320,10 +320,10 @@ var start = function(dom, mapDom, number, fileServer, webSite){ //t-Zvd3w0m
       
                 
             
-    let tilesetUrls = [   
+    let tilesetUrls = [  
+        `${Potree.resourcePath}/models/3dtiles/test/tileset.json`, 
         'http://192.168.0.25/oss/manage/media-library/result/test/tileset.json',
-        'https://4dkk.4dage.com/scene_view_data/SG-t-GvKLWIKfJGC/images/3dtiles/tileset.json?_=1742785956443',
-        `${Potree.resourcePath}/models/3dtiles/CC/tileset.json`, 
+        'https://4dkk.4dage.com/scene_view_data/SG-t-GvKLWIKfJGC/images/3dtiles/tileset.json?_=1742785956443', 
         'https://testgis.4dage.com/LVBADUI_qp/tileset.json', //村庄   含rtcCenter 
         'https://4dkk.4dage.com/fusion/test/b3dm/modelId_11947/tileset.json',//json有的包含多个materials,之前会花掉,现在解决了
         'https://4dkk.4dage.com/fusion/testb3dm/test001/tileset.json',  //体育中心

+ 1 - 1
src/custom/modules/datasetAlignment/Alignment.js

@@ -196,7 +196,7 @@ var Alignment = {
                         } */ 
                    
                      
-                    let center = e.pointclouds[0].translateUser //旋转中心是第一个点云的位置  
+                    let center = Potree.settings.editType == 'pano' ? e.pointclouds[0].translateUser : e.pointclouds[0].bound.getCenter(new THREE.Vector3) //点云编辑:旋转中心是第一个点云的位置  数据集校准:饶当前数据集bound中心,因有的上传的数据集偏离原点很远
                     if(e.intersect.equals(center))return
                     if(!transfromInfo.vecStart){  
                         //transfromInfo.orientationUser = e.pointclouds[0].orientationUser  

+ 9 - 2
src/custom/potree.shim.js

@@ -528,11 +528,18 @@ Utils.getPos2d = function(point, viewport , dom, renderer  ){//获取一个三
     return {
         pos:  new THREE.Vector2(left+x,top+y) ,// 屏幕像素坐标    
         vector:  pos,   //(范围 -1 ~ 1)
-        trueSide : pos.z<1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点   参见Tag.update
+        trueSide : pos.z<1 && pos.z>-1,  //z > 1 在远裁剪面之外, z < -1在近裁剪面之内。通常在相机背面时z也>1,反过来说z>1未必一定在背面
         inSight : inSight,	//在屏幕范围内可见,
         posInViewport: new THREE.Vector2(x,y),
-         
+        
     };
+    
+    /* 要判断一个点是否在相机背面,应该检查 相机空间(视图空间)的 z 值,而不是投影后的 z 值:
+    const viewPosition = vertex.clone().applyMatrix4(camera.matrixWorldInverse); //project的前半部分
+    const isBehindCamera = viewPosition.z > 0;  // 相机看向 -Z 方向
+    
+     */
+    
 } 
 
 Utils.getPointerPosAtHeight = function(planeZ=0, pointer, camera=viewer.mainViewport.camera){ 

+ 16 - 6
src/custom/viewer/ViewerNew.js

@@ -30,10 +30,9 @@ import {Renderer} from "../../PotreeRendererNew.js";
 //import {PotreeRenderer} from "../viewer/PotreeRenderer.js";
 import {EDLRenderer} from "../../viewer/EDLRendererNew.js";
 import {HQSplatRenderer} from "../../viewer/HQSplatRenderer.js";
-import {MapViewer} from "./map/MapViewer.js"; 
-import {Map3D} from "./map/Map3D.js"           
-
-                        
+import {MapViewer} from "./map/MapViewer.js";     
+//import {MapLayer} from "./map/Map3D.js"     
+      
 import {NavigationCube} from '../../viewer/NavigationCube.js'
    
 //import {MapView} from "../viewer/map.js"; 
@@ -564,9 +563,18 @@ export class Viewer extends ViewerBase{
                 if(Potree.settings.editType != "pano" && (Potree.settings.editType != 'merge' /* || Potree.settings.showObjectsOnMap */) && !args.noMap){
                     this.mapViewer = new MapViewer(mapArea/* $('#mapGaode')[0] */)
                     
-                    this.map3d = new Map3D(this)
+                    
+                    
                     
                 }
+                /* {//test
+                    this.map3d = new MapLayer(this,this.mainViewport)//new Map3D(this)
+                    this.scene.scene.add(this.map3d.sceneGroup)
+                    this.map3d.addEventListener('loadDone',()=>{
+                        this.dispatchEvent('content_changed')
+                    })
+                }
+                 */
                 
                 this.inputHandler = new InputHandler(this, this.scene.scene);
                 this.inputHandler.containsMouse = true//初始化,使键盘事件在mainViewer有效
@@ -3070,7 +3078,9 @@ export class Viewer extends ViewerBase{
         if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
             this.modules.ParticleEditor.update(delta)  
         }
-        this.mapViewer && this.mapViewer.update(delta)     //地图更新
+        this.mapViewer && this.mapViewer.update(delta);     //地图更新
+        (this.lastFrameChanged || this.map3d?.needUpdate) && this.map3d?.update(delta)     //地图更新
+        
         
 		this.dispatchEvent({ type: 'update', delta: delta, timestamp: timestamp});  //在有sidebar时耗高cpu,占本update函数80%
          

+ 69 - 68
src/custom/viewer/map/Map.js

@@ -38,9 +38,6 @@ const HALF_WORLD_SIZE = 21e6 //略大于半个周长(mapSizeM/2)
 const MAX_VERTICAL_DIST = 2 
 const MAX_VERTICAL_DIST_TO_BEST = 1  
  
-function defineLocalProj(locationLonLat){ 
-     proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
-}
  
 
 const getSid = (function(){
@@ -272,7 +269,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
     
     updateProjection(){ 
         if(!this.transformMapToLocal){
-            this.transformMapToLocal = proj4(this.projection, "LOCAL_MAP")  
+            this.transformMapToLocal = proj4(this.projection, "LOCAL_MAP")   //由地图原本的坐标转为本地坐标
         }  
     } 
     
@@ -300,7 +297,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
     
     
    
-    update(e, n){
+    update(frustum, sceneGroup){
         this.computeCount = 0 
         var unavailable = (this.disabled || !this.objectGroup.visible)//地图即使不显示也要获得zoomlevel
         if(this.name != 'map' && unavailable)return 
@@ -309,8 +306,8 @@ export class TiledMapBase extends THREE.EventDispatcher{
         
         if(!this.transformMapToLocal)return
         
-        if (!this.isTileVisible(new THREE.Vector3(0,0,0), this.mapSizeM, e))  
-            return this.removeFromSceneGroup(n), !0;
+        if (!this.isTileVisible(new THREE.Vector3(0,0,0), this.mapSizeM, frustum))  
+            return this.removeFromSceneGroup(sceneGroup), !0;
         
         let viewport = this.mapLayer.viewport
         
@@ -321,12 +318,12 @@ export class TiledMapBase extends THREE.EventDispatcher{
         var o = new THREE.Vector3(.5 * this.mapSizeM,0,0);
         o.applyMatrix4(this.objectGroup.matrixWorld),
         o.project(viewport.camera);
-        var a = viewport.resolution.x 
-          , s = viewport.resolution.y 
-        if (a <= 0 || s <= 0 || isNaN(i.x) || isNaN(o.x))  return !1;
+        var rx = viewport.resolution.x 
+          , ry = viewport.resolution.y 
+        if (rx <= 0 || ry <= 0 || isNaN(i.x) || isNaN(o.x))  return !1;
         i.sub(o),
-        i.x *= a / 2,
-        i.y *= s / 2;
+        i.x *= rx / 2,
+        i.y *= ry / 2;
         
         
          
@@ -351,7 +348,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
         }
         
         var c = this.tileSizePx / i.length() / scale      //多除以一个scale缩放因子,scale越大level越小
-          , level = Math.ceil(-Math.log(c) / Math.log(2) - this.bias);
+          , level = Math.ceil( -math.getBaseLog(2,c) - this.bias);
         
         if(this.style == 'dark-standard'){ //该模式贴图比较小放大点
             level -= 1
@@ -368,28 +365,28 @@ export class TiledMapBase extends THREE.EventDispatcher{
         } */
         
         if(!unavailable){
-            this.addToSceneGroup(n) 
-            return this.baseTile.update(this, e, level, this.mapSizeM, 0, 0, "")
+            this.addToSceneGroup(sceneGroup) 
+            return this.baseTile.update(this, frustum, level, this.mapSizeM, 0, 0, "")
         }
     }
      
      
      
      
-    isTileVisible(e, n, i){ 
-        if (n > HALF_WORLD_SIZE) return !0; 
-        var r = .5 * n;
+    isTileVisible(tileCenter, tileSize, frustum){ 
+        if (tileSize > HALF_WORLD_SIZE) return !0;  //root must visible
+        var halfSize = .5 * tileSize; //在地图上的size和local的差不多是吗
          
         //简单版:
-        this.transformMapToLocal.forward(e) //e转化为local
+        this.transformMapToLocal.forward(tileCenter) //e转化为local
         this.isTileVisibleBox.makeEmpty() 
-        this.isTileVisibleVec.set(e.x - r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
+        this.isTileVisibleVec.set(tileCenter.x - halfSize, tileCenter.y - halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
         this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
-        this.isTileVisibleVec.set(e.x - r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
+        this.isTileVisibleVec.set(tileCenter.x - halfSize, tileCenter.y + halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
         this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
-        this.isTileVisibleVec.set(e.x + r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
+        this.isTileVisibleVec.set(tileCenter.x + halfSize, tileCenter.y - halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
         this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
-        this.isTileVisibleVec.set(e.x + r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld)
+        this.isTileVisibleVec.set(tileCenter.x + halfSize, tileCenter.y + halfSize, tileCenter.z).applyMatrix4(this.objectGroup.matrixWorld)
         this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec) 
           
       
@@ -418,7 +415,7 @@ export class TiledMapBase extends THREE.EventDispatcher{
         this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)  */
             
        
-        return i.intersectsBox(this.isTileVisibleBox)  
+        return frustum.intersectsBox(this.isTileVisibleBox)  
          
         
         
@@ -465,6 +462,9 @@ const loadDone = (tile, success)=>{
     
 }
  
+ 
+ 
+ 
 function addLoadTile(tile){
     /* if(tile.texURL && tile.texURL.includes('testdata') ){ 
         console.error('addLoadTile',   tile.texURL.split('map_tiles/')[1] )
@@ -546,21 +546,21 @@ export class MapTile{
         this.children = []
         this.id = getSid();
     }
-    update(e, n, i, r, o, a, s){
-        return !!this.doesNotContainTilesToBeDisplayed(e) || (0 === i ? this.updateTile(e, r, o, a) : this.updateSubTiles(e, n, i, r, o, a, s))
-    }
+    update(entity, frustum, level, tileSize, centerX, centerY, treeStr){
+        return !!this.doesNotContainTilesToBeDisplayed(entity) || (0 === level ? this.updateTileLeaf(entity, tileSize, centerX, centerY ) : this.updateSubTiles(entity, frustum, level, tileSize, centerX, centerY, treeStr))
+    } 
     
-    doesNotContainTilesToBeDisplayed(t){
-        return t.tilePresenceMap && t.tilePresenceMap.empty
+    doesNotContainTilesToBeDisplayed(entity){
+        return entity.tilePresenceMap && entity.tilePresenceMap.empty
     }
     
-    updateTile(t, e, n, i){ //真正显示mesh的是这一层,最高level  
+    updateTileLeaf(entity, tileSize, centerX, centerY ){ //真正显示mesh的是这一层,最高level  
             
-        //if(this.map.name.includes('floorplan'))console.log('updateTile',this.name)
+        //if(this.map.name.includes('floorplan'))console.log('updateTileLeaf',this.name)
     
     
         if(!this.mesh){
-            this.createTileObject(t, e, n, i)
+            this.createTileObject(entity, tileSize, centerX, centerY )
         }
         if(!this.meshAdded){
             this.objectGroup.add(this.mesh) 
@@ -575,26 +575,28 @@ export class MapTile{
         return this.textureLoaded
     }
     
-    updateSubTiles(entity, n, level, o, a, s, c){
+    updateSubTiles(entity, frustum, level, tileSize, centerX, centerY, treeStr){
         //if(entity.name.includes('floorplan'))console.log('updateSubTiles',this.name) //名字越长代表level越高
         
-        
-        for (var childrenLoaded = !0, u = [-.25 * o, .25 * o, -.25 * o, .25 * o], d = [.25 * o, .25 * o, -.25 * o, -.25 * o], p = 0; p < 4; ++p){
-            var h = c + p.toString(10);
+        let shiftX = [-.25 * tileSize, .25 * tileSize, -.25 * tileSize, .25 * tileSize], 
+            shiftY = [ .25 * tileSize, .25 * tileSize, -.25 * tileSize, -.25 * tileSize] 
+            
+        for (var childrenLoaded = !0,  p = 0; p < 4; ++p){
+            var childTreeStr = treeStr + p.toString(10);
             //一级(512):0 1 2 3分别为左上、右上、左下、右下。二级(1024)就是把一级的每一块分裂,如00 01 02 03分别是0的左上、右上、左下、右下……
              
-            if (!entity.tilePresenceMap || entity.tilePresenceMap[h]){
+            if (!entity.tilePresenceMap || entity.tilePresenceMap[childTreeStr]){
                 //去掉判断,直接显示
-                var f = a + u[p]
-                  , m = s + d[p];
-                tempVector.set(f, m, 0);
+                var childCenterX = centerX + shiftX[p]  
+                  , childCenterY = centerY + shiftY[p];
+                tempVector.set(childCenterX, childCenterY, 0);
                 this.map.computeCount ++
                 //console.log(this.map.computeCount, this.name, 'level:',level)
                 
-                if (entity.isTileVisible(tempVector, .5 * o, n)){ 
+                if (entity.isTileVisible(tempVector, .5 * tileSize, frustum)){ 
                     this.children[p] || (this.children[p] = new MapTile(this.map, this.objectGroup,this.tileColor, this, this.name+p ))
-                    //childrenLoaded = childrenLoaded && this.children[p].update(entity, n, level - 1, .5 * o, f, m, h)   //这句会使若有一个tile还在加载,就阻断了。原版是这么写的。但是为了加快加载速度,改成下面两行。感觉直接全部updateTile也没太卡,不知道很大的场景会不会卡,单帧updateTile次数超过100次的话(应该不会吧,地图大小会限制住个数) -- 2023.12
-                    let childLoaded = this.children[p].update(entity, n, level - 1, .5 * o, f, m, h)  
+                    //childrenLoaded = childrenLoaded && this.children[p].update(entity, frustum, level - 1, .5 * tileSize, childCenterX, childCenterY, childTreeStr)   //这句会使若有一个tile还在加载,就阻断了。原版是这么写的。但是为了加快加载速度,改成下面两行。感觉直接全部updateTile也没太卡,不知道很大的场景会不会卡,单帧updateTile次数超过100次的话(应该不会吧,地图大小会限制住个数) -- 2023.12
+                    let childLoaded = this.children[p].update(entity, frustum, level - 1, .5 * tileSize, childCenterX, childCenterY, childTreeStr)  
                     childrenLoaded = childrenLoaded && childLoaded
                 } else {
                     if (this.children[p]){
@@ -616,19 +618,18 @@ export class MapTile{
     
     
     
-     */
-    
-    createTileObject(t, e, n, a){
+     */ 
+    createTileObject(entity, tileSize, centerXatMap, centerYatMap){
         var s = this;
-        this.mesh = this.createMesh(t.transformMapToLocal, e, n, a),
+        this.mesh = this.createMesh(entity.transformMapToLocal,tileSize, centerXatMap, centerYatMap),
         this.textureLoaded = !1;
-        var c = t.mapSizeM / e
-          , l = Math.log(c) / Math.log(2)
-          , u = n / e + .5 * (c - 1)
-          , d = -a / e + .5 * (c - 1)
-          , p = t.getTileUrl(Math.round(l), Math.round(u), Math.round(d));
+        var c = entity.mapSizeM / tileSize
+          , z = math.getBaseLog(2,c) //以2为底c的对数
+          , x = centerXatMap / tileSize + .5 * (c - 1)
+          , y = -centerYatMap / tileSize + .5 * (c - 1)
+          , p = entity.getTileUrl(Math.round(x), Math.round(y), Math.round(z));
         Potree.Utils.setObjectLayers(this.mesh, 'map' )
-        this.mesh.renderOrder = -(1e6 - l - 100 * (t.zIndex || 0));
+        this.mesh.renderOrder = -(1e6 - z - 100 * (entity.zIndex || 0));
         this.mesh.name = this.name //add
         this.texURL = p
         
@@ -641,16 +642,16 @@ export class MapTile{
         
     }
     
-    createMesh(t, e, n, o){
+    createMesh(transform, tileSize, centerXatMap, centerYatMap){
         var a = new THREE.Geometry;
-        return tempVector.set(n - e / 2, o - e / 2, 0),
-        a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
-        tempVector.set(n + e / 2, o - e / 2, 0),
-        a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
-        tempVector.set(n + e / 2, o + e / 2, 0),
-        a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
-        tempVector.set(n - e / 2, o + e / 2, 0),
-        a.vertices.push(new THREE.Vector3().copy(t.forward(tempVector))),
+        return tempVector.set(centerXatMap - tileSize / 2, centerYatMap - tileSize / 2, 0),
+        a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
+        tempVector.set(centerXatMap + tileSize / 2, centerYatMap - tileSize / 2, 0),
+        a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
+        tempVector.set(centerXatMap + tileSize / 2, centerYatMap + tileSize / 2, 0),
+        a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
+        tempVector.set(centerXatMap - tileSize / 2, centerYatMap + tileSize / 2, 0),
+        a.vertices.push(new THREE.Vector3().copy(transform.forward(tempVector))),
         a.faces.push(face1),
         a.faces.push(face2),
         a.faceVertexUvs[0].push(face1UV),
@@ -763,8 +764,8 @@ export class TiledMapOpenStreetMap extends TiledMapBase{
             
     }
     
-    getTileUrl(t, e, n){ 
-        return this.baseUrl.replace(/\${z}/, t.toString(10)).replace(/\${x}/, e.toString(10)).replace(/\${y}/, n.toString(10))
+    getTileUrl(x, y, z){  
+        return this.baseUrl.replace(/\${x}/, x.toString(10)).replace(/\${y}/, y.toString(10)).replace(/\${z}/, z.toString(10))
     } 
 
 
@@ -826,8 +827,8 @@ export class TiledMapOpenStreetMap extends TiledMapBase{
                     this.baseUrl = "https://wprd01.is.autonavi.com/appmaptile?lang=zh_cn&style=8&yrs=m&x=${x}&y=${y}&z=${z}"    //路网   加上scl=2后去掉名字
                 }else{
                     this.maxDepth = 19
-                    this.baseUrl = "https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&style=7&yrs=m&x=${x}&y=${y}&z=${z}"    //  
-               
+                    this.baseUrl = "https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&style=7&yrs=m&x=${x}&y=${y}&z=${z}"    //加这个才会精细lang=zh_cn
+                
              
                 }
             }//详解 https://www.cnblogs.com/lucio110/p/17310054.html
@@ -931,8 +932,8 @@ export class TiledMapFromEntity extends TiledMapBase{
         return  typeof(this.pointcloud.orientationUser ) == 'number' ? this.tiledMapEntity.orientation : this.pointcloud.orientationUser.clone()
     }
    
-    getTileUrl(t, e, n) {
-        var i = (this.tiledMapEntity.filePath + "/" + this.tiledMapEntity.fileName).replace(/\$DEPTH/g, t.toString(10)).replace(/\$X/g, e.toString(10)).replace(/\$Y/g, n.toString(10));
+    getTileUrl(x,y,z) {
+        var i = (this.tiledMapEntity.filePath + "/" + this.tiledMapEntity.fileName).replace(/\$DEPTH/g, z.toString(10)).replace(/\$X/g, x.toString(10)).replace(/\$Y/g, y.toString(10));
         return i += "?t=" + this.postStamp  
         //this.RestService.addAuthorizationQueryParameter(i) //????
     }