ソースを参照

fix: 场景基本加载ok

xzw 2 年 前
コミット
932e611214

+ 4 - 0
examples/4dkk.html

@@ -53,6 +53,10 @@
         
         var number = browser.urlHasValue('m',true);
         console.log(number)
+        Potree.settings.isLocal = true;
+        Potree.settings.urls.prefix1 = Potree.settings.urls.prefix3 = Potree.scriptPath + '/data/'+number+'/';
+        
+        
         Potree.start(document.getElementById("potree_render_area"),null, number);
         
           

+ 7 - 152
src/Potree.js

@@ -175,135 +175,22 @@ export async function loadFile(path, params , callback, onError){
     
     //查询: http://192.168.0.26:8080/doc.html#/default/filter-%E6%BC%AB%E6%B8%B8%E7%82%B9/filterUsingGET    
 }
-
-export async function loadDatasets(callback,sceneCode,onError){//之后直接把path写进来
-    let path 
-    sceneCode = sceneCode || Potree.settings.number
-    if(Potree.fileServer){
-        path = `/laser/dataset/${sceneCode}/getDataSet` 
-    }else{
-        
-        //path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/datasets`
-        //现在只能加载得了本地的了
-        path = `${Potree.settings.urls.prefix}/laser/dataset/${sceneCode}/getDataSet`
-        //path = `${Potree.scriptPath}/data/${sceneCode}/getDataSet.json`
-        
-    }
-    return loadFile(path, null, callback,onError)
-    
-}
-
-
-//目前上传平面图后如果不点击保存按钮,数据还是旧的不生效
-export async function loadMapEntity(datasetId, force){ 
-    if(!Potree.settings.floorplanEnable && !force && Potree.fileServer  )return /* 等待平面图类型定义好会加载 */
-     
-    
-    let loaded = 0
-    
-    let needLoads = datasetId == 'all' ? viewer.scene.pointclouds.map(e=>e.dataset_id) : [datasetId]
-    
-    
-    let callback = (dataset_id, floorplanType, data  )=>{
-        //要防止旧的比新的先获取到导致覆盖新的,因为两种type随时可能切换
-        if(floorplanType != Potree.settings.floorplanType[dataset_id]) return //如果请求的floorplanType不是当前最新的floorplanType就返回
-        
-        var map = viewer.mapViewer.mapLayer.maps.find(e => e.name == 'floorplan_'+ dataset_id)
-        if(map){  
-            viewer.mapViewer.mapLayer.removeMap(map)
-        } 
-        
-        var mapNew = viewer.mapViewer.mapLayer.addMapEntity(data.data || data,  dataset_id)
-        if(map){
-            mapNew.visibleReasons = map.visibleReasons 
-            mapNew.unvisibleReasons = map.unvisibleReasons 
-        }
-        loaded ++; 
-    } 
-    
-    needLoads.forEach(dataset_id=>{
-        let floorplanType = Potree.settings.floorplanType[dataset_id],  prefix = ''
-        if(!Potree.fileServer){   
-            prefix = Potree.settings.urls.prefix
-        }
-        if(!floorplanType)return
-        var path 
-        /* if(Potree.fileServer){ 
-            path = `/laser/tiledMap/${Potree.settings.number}/tiledMap/${floorplanType}/${dataset_id}` 
-        }else{
-            path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/tiled_maps`
-            
-        } */
-        path = `${prefix}/laser/tiledMap/${Potree.settings.number}/tiledMap/${floorplanType}/${dataset_id}` 
-        
-        Potree.settings.floorplanRequests[dataset_id] = true //开始加载了
-        return loadFile(path, null, callback.bind(this,  dataset_id, floorplanType)  )
-    })
-    
-     
-    
-}
  
 export async function loadPanos( callback){
     var path 
     //let query = `?datasetId=${datasetId}`                  //`?lat=${center.lat}&lon=${center.lon}&radius=200000`
-    if(Potree.fileServer){
-        path = `vision.json` 
-    } 
+    if(Potree.fileServer){ 
+        path = 'vision.json'
+    }else{
+        path = `${Potree.settings.urls.prefix1}/vision.json` 
+    }
+     
     return loadFile(path, { }, callback) 
     
 }
 
-
  
 
-//site_model
-/* {
-    "area": 2503.30551910935,
-    "attributes": {},
-    "center": [
-        113.59568277455075,
-        22.366566635195288,
-        12.78751625
-    ],
-    "children": [],
-    "geometry_hash": 1891071345,
-    "id": 10,
-    "name": "港湾一号",
-    "parentId": null,
-    "polygon": {
-        "coordinates": [
-            [
-                [
-                    113.59590810534583,
-                    22.36679132753878
-                ],
-                [
-                    113.59590810534583,
-                    22.366807172528629
-                ],
-                [
-                    113.59545610274934,
-                    22.366807172528629
-                ],
-                [
-                    113.59545610274934,
-                    22.36679132753878
-                ]
-            ]
-        ],
-        "type": "Polygon"
-    },
-    "type": "BUILDING",
-    "volume": null,
-    "z_max": null,
-    "z_min": null
-}
- */
-
-
-
-
 export function Log(){ 
     
     let args = Array.from(arguments)
@@ -368,39 +255,7 @@ export function loadPointCloud(path,  timeStamp, callback, onError){
 					resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
 				}
 			});
-		}/*  else if (path.indexOf('metadata.json') > 0) {  //部分浏览器(如uc)不支持NodeLoader中的1n的大数据写法
-			Potree.OctreeLoader.load(path).then(e => {
-				let geometry = e.geometry;
-
-				if(!geometry){
-					console.error(new Error(`failed to load point cloud from URL: ${path}`));
-				}else{
-					let pointcloud = new ExtendPointCloudOctree(geometry);
-
-					let aPosition = pointcloud.getAttribute("position");
-
-					let material = pointcloud.material;
-					material.elevationRange = [
-						aPosition.range[0][2],
-						aPosition.range[1][2],
-					];
-
-					// loaded(pointcloud);
-					resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
-				}
-			});
-
-			OctreeLoader.load(path, function (geometry) {
-				if (!geometry) {
-					//callback({type: 'loading_failed'});
-					console.error(new Error(`failed to load point cloud from URL: ${path}`));
-				} else {
-					let pointcloud = new ExtendPointCloudOctree(geometry);
-					// loaded(pointcloud);
-					resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
-				}
-			});
-		}  */else if (path.indexOf('.vpc') > 0) {
+		} else if (path.indexOf('.vpc') > 0) {
 			PointCloudArena4DGeometry.load(path, function (geometry) {
 				if (!geometry) {
 					//callback({type: 'loading_failed'});

+ 16 - 15
src/custom/materials/ModelTextureMaterial.js

@@ -159,10 +159,10 @@ let shader = {
             
           
        
-            /* uniform sampler2D pano0Map;
-            uniform sampler2D pano1Map;    */   
-            uniform samplerCube pano0Map;
-            uniform samplerCube pano1Map;
+            uniform sampler2D pano0Map;
+            uniform sampler2D pano1Map;       
+            /* uniform samplerCube pano0Map;
+            uniform samplerCube pano1Map;*/
           
             
             varying vec2 vUv; 
@@ -203,7 +203,7 @@ let shader = {
                 
                 vec2 getDepth(vec3 dir, sampler2D depthMap, float heightDown, float heightUp, vec4 eyePos){
                     vec2 depthValue = vec2(0.0, 0.0);
-                    vec2 uv2 = getSamplerCoord2(/* vWorldPosition12 */dir.xyz);  //暂时只用基于目标漫游点的方向
+                    vec2 uv2 = getSamplerCoord2( dir.xyz);  //暂时只用基于目标漫游点的方向
                     uv2.x -= 0.25;    //全景图和Cube的水平采样起始坐标相差90度,这里矫正 0.25 个采样偏移
                     vec4 depth = texture2D(depthMap, uv2);
                     //float distance = depth.r + 256. * (depth.g + 256. * depth.b);
@@ -238,20 +238,21 @@ let shader = {
             #endif
             
             void main()
-            {
-                vec3 vWorldPosition0N = normalize(vWorldPosition0);
-                vec3 vWorldPosition1N = normalize(vWorldPosition1);
-                /* vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);
-                vec2 samplerCoord1 = getSamplerCoord(vWorldPosition1.xyz);  
-                vec4 colorFromPano0=texture2D(pano0Map,samplerCoord0);
-                vec4 colorFromPano1=texture2D(pano1Map,samplerCoord1); */
+            { 
                 
+                vec3 vWorldPosition0N;
                 vec4 colorFromPano0 = vec4(0.0,0.0,0.0,0.0);
                 if(progress < 1.0){//通常是1
-                    colorFromPano0=textureCube(pano0Map,vWorldPosition0N.xyz);
+                    vWorldPosition0N = normalize(vWorldPosition0);
+                    vec3 vWorldPosition0N = normalize(vWorldPosition0);
+                    vec2 samplerCoord0 = getSamplerCoord2(vWorldPosition0N.xyz);
+                    colorFromPano0 = texture2D(pano0Map,samplerCoord0); 
                 }
-                vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1N.xyz);
- 
+                
+                vec3 vWorldPosition1N = normalize(vWorldPosition1);
+                vec2 samplerCoord1 = getSamplerCoord2(vWorldPosition1N.xyz);  
+                vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);
+        
                 gl_FragColor=mix(colorFromPano0,colorFromPano1,progress);
               
               

+ 19 - 66
src/custom/modules/panos/Images360.js

@@ -128,12 +128,8 @@ export class Images360 extends THREE.EventDispatcher{
                 ||   Potree.settings.editType == 'merge' && !e.intersectPoint || viewer.inputHandler.hoveredElements[0] && viewer.inputHandler.hoveredElements[0].isModel && e.intersectPoint.distance > viewer.inputHandler.hoveredElements[0].distance
             )  return 
              
-            if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
-                if( e.hoverViewport == viewer.mapViewer.viewports[0]){
-                    return viewer.mapViewer.dispatchEvent(e/* {type:'global_click',e } */) 
-                }else if(e.hoverViewport != viewer.mainViewport){ //如数据集校准其他viewport
-                    return
-                }
+            if(e.hoverViewport != viewer.mainViewport){ //如数据集校准其他viewport
+                 return
             }
               
             if(!Potree.settings.dblToFocusPoint/*  && this.currentPano */){//双击不会focus点云 或者 已经focusPano了
@@ -282,14 +278,7 @@ export class Images360 extends THREE.EventDispatcher{
                                 this.addEventListener('flyToPanoDone',wait)   //等待飞行完毕。flyToPano的callback可能不执行所以换这个。但也可能被cancel
                                 this.flyToPano({
                                     pano: this.findNearestPano(),   
-                                    //dealDoneWhenCancel:true,
-                                    /* callback: ()=>{ 
-                                        setTimeout(()=>{ //防止循环,所以延迟
-                                           if(this.latestRequestMode == mode ){
-                                                Potree.settings.displayMode = mode 
-                                            } 
-                                        },1)  
-                                    } */
+                                     
                                 }) 
                                 
                                 return;
@@ -318,9 +307,9 @@ export class Images360 extends THREE.EventDispatcher{
                                 return
                             } */ 
                             if(!this.currentPano.skyboxTex){
-                                pano.waitForLoad() 
-                                this.addEventListener('loadedTex', wait, {once:true})     
-                                this.currentPano.loadTex()
+                                this.currentPano.waitForLoad() 
+                                this.currentPano.addEventListener('loadedTex', wait, {once:true})     
+                                return this.currentPano.loadTex()
                             }                            
                         } 
                         
@@ -692,7 +681,7 @@ export class Images360 extends THREE.EventDispatcher{
                 if(!pano.skyboxTex){
                     pano.waitForLoad() 
                     pano.addEventListener('loadedTex', wait, {once:true})     
-                    pano.loadTex()
+                    return pano.loadTex()
                 }
                 /* if(this.checkAndWaitForPanoLoad(pano, toPano.basePanoSize || this.basePanoSize,  wait )){
                     return
@@ -1046,19 +1035,7 @@ export class Images360 extends THREE.EventDispatcher{
         t || (t = 0);
         option1 = void 0 !== option1 ? option1 : .75;
         var o = option2 ? "angle" : "direction";
-        
-        var floor = viewer.modules.SiteModel.currentFloor;
-        var entity = viewer.modules.SiteModel.inEntity;
-        
-        var getHeightDis = (pano)=>{
-            if(floor && !floor.panos.includes(pano) && pano.position.z < this.position.z){ //若是上方的漫游点,就正常走。因为一般不会点击天花板。
-                return this.position.z - pano.position.z  
-            }else{
-                return 0
-            }  
-        } 
-        
-        
+         
         let disSquareMap = new Map()
         this.panos.forEach(pano=>{
             let dis2 = pano.position.distanceToSquared(this.position);  //距离目标点
@@ -1402,7 +1379,17 @@ export class Images360 extends THREE.EventDispatcher{
                           
       
                                
-                                  
+    getIntersect(pano, dir, origin){
+        if(pano && pano.pointcloud.hasDepthTex ){
+            return this.depthSampler.sample( {dir }, pano, true )
+        }else{
+            origin = origin || pano.position
+            return viewer.inputHandler.getIntersect(viewer.inputHandler.hoverViewport, true, null, null, true, {
+                point: origin.clone().add(dir),
+                cameraPos: origin
+            })
+        }
+    }                           
                              
                                  
                                         
@@ -1811,41 +1798,7 @@ Images360.prototype.updateCube = (function(){//增加细分的版本,且垂直
                 if(maxZ == Infinity) maxZ = skyHeight;   //maxZ = Math.max(skyHeight, maxZ)
                 
                 
-                   
-            
-                /* if(pano.ceilZ != void 0){
-                    maxZ = pano.ceilZ
-                }else{//天花板高度值
-                    //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
-                    let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
-                     
-                    let dirs = [new THREE.Vector3(0,0,1).applyMatrix4(rotMat)];
-                    if(depthTiming < 1){
-                        let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
-                        dirs.push(dirs[0].clone().applyMatrix4(rotMat1))
-                    }
-                    if(depthTiming < 0.3){
-                        let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
-                        dirs.push(dirs[0].clone().applyMatrix4(rotMat2)); 
-                    }
-                    
-                    
-                    let skyHeight = 50
-                    let zs = dirs.map(dir_=>{ 
-                        let intersect = this.getIntersect(pano, dir_) 
-                        let z = intersect ? intersect.location.z : pano.position.z+skyHeight //没有intersect代表可能是天空
-                        return z 
-                    })
-                    zs.sort((a,b)=>{return b-a});//得最大值  (不用中位数的原因:在屋檐处,如果仅有一个intersect是天空,因到了室外所以也用天空高度)
-                    maxZ = zs[0]
                     
-                    let min = pano.position.z + 1  // 防止意外太低
-                    maxZ = Math.max(min,maxZ)
-                    pano.ceilZ = maxZ
-                     
-                } */
-                //console.log(pano.id, 'maxZ:',maxZ )
-                //console.log(pano.id, 'minZ:',minZ )
                 [maxZ, minZ ].forEach(z=>{  
                     posArr.push(pano.position.clone().setZ(z))
                 })

+ 16 - 10
src/custom/modules/panos/Panorama.js

@@ -125,7 +125,7 @@ class Panorama extends THREE.EventDispatcher{
             this.quaternion = new THREE.Quaternion().copy(o.pose.rotation) 
             this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion)//4dkk内使用的quaternion 
             this.quaternion2 = this.quaternion.clone()
-            this.quaternion = new THREE.Quaternion().multiplyQuaternions(this.quaternion,  rot90);//全景图和Cube的水平采样起始坐标相差90度,cubeTex转90度
+            //this.quaternion = new THREE.Quaternion().multiplyQuaternions(this.quaternion,  rot90);//全景图和Cube的水平采样起始坐标相差90度,cubeTex转90度
             
             this.rotation4dkk = new THREE.Euler().setFromQuaternion(this.quaternion4dkk)
             
@@ -183,8 +183,8 @@ class Panorama extends THREE.EventDispatcher{
 
 
     waitForLoad(){
-        viewer.waitForLoad(pano, function() {//发送loading
-            return pano.depthTex && pano.skyboxTex
+        viewer.waitForLoad(this,  ()=>{//发送loading
+            return this.depthTex && this.skyboxTex
         });
     }
 
@@ -196,18 +196,19 @@ class Panorama extends THREE.EventDispatcher{
         //console.log('开始下载depthImg', this.id)
         let texture = texLoader.load( src, ()=>{
             this.skyboxTex = texture
-            this.dispatchEvent({type:'loadedTex', pano:this, loaded:true})
+            this.dispatchEvent({type:'loadedTex',   loaded:true})
             this.depthTexLoading = false
             //viewer.dispatchEvent('content_changed') 
         },null,(e)=>{//error
             console.error('loadTex失败, 数据集sceneCode'+ this.pointcloud.sceneCode,  this.id )
              
-            this.dispatchEvent({type:'loadedTex', pano:this, })
+            this.dispatchEvent({type:'loadedTex',   })
         });
         texture.wrapS = THREE.RepeatWrapping;
         texture.flipY = false 
-        texture.magFilter = THREE.LinearFilter
-        texture.minFilter = THREE.LinearFilter
+        texture.magFilter = THREE.LinearFilter  
+        texture.minFilter = THREE.LinearFilter //防止边缘竖线
+        texture.generateMipmaps = false
 	}
     
     
@@ -235,6 +236,7 @@ class Panorama extends THREE.EventDispatcher{
         texture.flipY = false 
         texture.magFilter = THREE.LinearFilter
         texture.minFilter = THREE.LinearFilter
+        texture.generateMipmaps = false
 	}
  
     
@@ -245,10 +247,14 @@ class Panorama extends THREE.EventDispatcher{
             //var quaternion = new THREE.Quaternion().multiplyQuaternions(this.quaternion,  rot901);//改  为球目全
             //quaternion.premultiply(rot90)
             this.panoMatrix = new THREE.Matrix4().makeRotationFromQuaternion(this.quaternion) 
-            this.oriPanoMatrix = this.panoMatrix.clone()
+            //this.oriPanoMatrix = this.panoMatrix.clone()
             
-            if(this.quaternion2)this.oriPanoMatrix2 = new THREE.Matrix4().makeRotationFromQuaternion(this.quaternion2) 
-         
+            //if(this.quaternion2)this.oriPanoMatrix2 = new THREE.Matrix4().makeRotationFromQuaternion(this.quaternion2) 
+            
+        
+            //补:全景图下和原来的一样
+            this.panoMatrix2 = this.panoMatrix  
+            this.panoMatrix2Inverse = this.panoMatrix2.clone().invert(); 
         } 
          
         let marker = new THREE.Mesh(planeGeo, this.getMarkerMat() ) 

+ 4 - 4
src/custom/start.js

@@ -21,7 +21,7 @@ export function start(dom, mapDom, number ){ //t-Zvd3w0m
     viewer.setFOV(Potree.config.view.fov); 
      
     
-     if(!Potree.settings.isOfficial){ 
+    /* if(!Potree.settings.isOfficial){ 
         viewer.loadGUI(() => {
             viewer.setLanguage('en');
             //$("#menu_appearance").next().show();
@@ -33,10 +33,10 @@ export function start(dom, mapDom, number ){ //t-Zvd3w0m
         }); 
         Potree.settings.sizeFitToLevel = true//当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
         Potree.settings.rotAroundPoint = false
-        if(/* Potree.settings.isTest && */ browser.isMobile()){
+        if( browser.isMobile()){
             changeLog()
         }
-    }  
+    } */  
 
     {
             
@@ -54,7 +54,7 @@ export function start(dom, mapDom, number ){ //t-Zvd3w0m
              
             //pointcloud.datasetData = dataset
             //pointcloud.dataset_id = dataset.id;//供漫游点找到属于的dataset点云
-            pointcloud.hasDepthTex = Potree.settings.useDepthTex && (!!dataset.has_depth  ||  Potree.settings.isLocalhost && Potree.settings.number == 'SS-t-7DUfWAUZ3V') //test   
+            pointcloud.hasDepthTex = Potree.settings.useDepthTex  
             material.minSize =  config.minSize
             material.maxSize =  config.maxSize   
             material.pointSizeType =/*   Potree.settings.isOfficial ?   */ config.pointSizeType    /* : 'ADAPTIVE'    */   //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED

+ 1 - 2
src/custom/viewer/ViewerNew.js

@@ -90,8 +90,7 @@ export class Viewer extends ViewerBase{
         this.modules = { 
             
         }
-        Potree.settings.useDepthTex = false
-        
+