Bladeren bron

fix: 上一版有点卡

xzw 2 jaren geleden
bovenliggende
commit
d8afb66882

+ 3 - 3
src/custom/materials/ModelTextureMaterial.js

@@ -390,18 +390,18 @@ export default class ModelTextureMaterial extends THREE.RawShaderMaterial {
     
     
     
-    updateDepthTex(pano){
+    updateDepthTex(pano, extra){
         if( !Potree.settings.useDepthTex || !pano || !pano.depthTex || pano!=this.pano0 && pano!=this.pano1)return
         //console.log('updateDepthTex', pano.id,  this.pano0 && this.pano0.id,  this.pano1 && this.pano1.id)
         
          
         if(this.pano0){ 
-            this.uniforms.depthMap0.value = this.pano0.depthTex 
+            this.uniforms.depthMap0.value = this.pano0.loaded ? this.pano0.depthTex : null;   //dispose了就不要赋值否则dispose会失败
             this.uniforms.cameraHeight0.value = this.pano0.floorPosition.distanceTo(this.pano0.position)
             this.uniforms.ceilHeight0.value = this.pano0.getCeilHeight() - this.pano0.position.z  
         }
         if(this.pano1){ 
-            this.uniforms.depthMap1.value = this.pano1.depthTex 
+            this.uniforms.depthMap1.value = this.pano1.loaded ? this.pano1.depthTex : null;
             this.uniforms.cameraHeight1.value = this.pano1.floorPosition.distanceTo(this.pano1.position)
             this.uniforms.ceilHeight1.value = this.pano1.getCeilHeight() - this.pano1.position.z  
         } 

+ 10 - 6
src/custom/modules/panos/Images360.js

@@ -860,7 +860,7 @@ export class Images360 extends THREE.EventDispatcher{
                             e.material.stopProjectedPanos()
                         })
                     }
-                  
+                    this.lastPano = this.currentPano //记录,调试
                     this.currentPano = pano;
                     
                     this.nextPano = null;
@@ -871,7 +871,7 @@ export class Images360 extends THREE.EventDispatcher{
                     }
                     done(true);
                    
-                    this.updateDepthTex(this.currentPano)
+                    this.updateDepthTex(this.currentPano) //删除dispose的depthTex
                     
                     
                     
@@ -2240,8 +2240,9 @@ Images360.prototype.checkAndWaitForPanoLoad = function() {
 
 Images360.prototype.getNeighbours = function(){ //逐渐自动获取neighbours。 200个点差不多在半分钟内算完
     let lastIndex //标记上次查询到哪,防止重新sortByScore
-    return function(){
-        if(!this.currentPano || viewer.mainViewport.view.isFlying() || viewer.lastFrameChanged){
+    return function( interacted){
+         
+        if(!this.currentPano || viewer.mainViewport.view.isFlying() || viewer.lastFrameChanged || viewer.inputHandler.drag /* interacted */){ //拖拽时不更新,否则移动端卡
             return lastIndex = 0; 
         }
           
@@ -2257,11 +2258,14 @@ Images360.prototype.getNeighbours = function(){ //逐渐自动获取neighbours
         let changeTexCount = ()=>{
             changeCount ++;
         }
+        let median = Math.max(10, Potree.timeCollect.depthSampler.median)
+        
+        
         let ifOverTime = ()=>{ 
-            let is = changeCount * Potree.timeCollect.depthSampler.median  +    getCount * 0.01 > maxWaitDur//不换贴图也要一丢丢计算时间 
+            let is = changeCount * median  +  getCount * 0.01 > maxWaitDur//不换贴图也要一丢丢计算时间 
             /* if(is){
                 console.log(1)
-            } */
+            } */  
             return is
         }
         this.depthSampler.addEventListener('changeImg', changeTexCount)

+ 4 - 1
src/custom/modules/panos/Panorama.js

@@ -407,7 +407,8 @@ class Panorama extends THREE.EventDispatcher{
     
     
     enter(){ 
-        this.setZoomed(!1),
+        this.loaded = true
+        this.setZoomed(!1) 
         viewer.dispatchEvent({type:PanoramaEvents.Enter,  oldPano:old, newPano:this  }  )
         old = this 
         //console.log("enter pano "+ this.id)
@@ -421,6 +422,8 @@ class Panorama extends THREE.EventDispatcher{
         this.images360.panoRenderer.deactivateTiledPano(this);
         this.highestPartialTileRenderOpCompleted = 0;
         this.highestFullTileRenderOpCompleted = 0;
+        this.depthTex && this.depthTex.dispose()  //贴图不使用后先dispose,下次到该点时会自动还原
+        this.loaded = false //add
         
         //console.log("exit pano "+ this.id)
         

+ 15 - 4
src/custom/viewer/ViewerNew.js

@@ -762,7 +762,15 @@ export class Viewer extends ViewerBase{
             
         } 
         
-        
+        {
+            let setInteract = ()=>{
+                this.interacted = true //标记这一帧用户有操作屏幕
+            }
+            this.addEventListener('global_mousedown', setInteract)
+            this.addEventListener('global_touchmove', setInteract)
+            this.addEventListener('global_mousewheel', setInteract)
+              
+        }
          
 	}
     
@@ -4164,10 +4172,11 @@ export class Viewer extends ViewerBase{
        
         performance.mark('loop-start') ;// 无论有没有reportTimings都要获取,因为getBestCound需要
         
+        this.interacted = false
         let depthTiming = Potree.timeCollect.depthSampler.median 
         this.shelterCount = {byTex:0, byCloud:0,   maxByTex: THREE.Math.clamp(0.2/depthTiming, 1, 10), maxByCloud:0   } //清空 因ifPointBlockedByIntersect可能在任何时候触发,所以需要一开始就定义这个,且每次计算最大可计算次数太麻烦了就定义一个吧。
         
-
+        
 
         let deltaTime = this.clock.getDelta()
 		this.update(deltaTime, timestamp);
@@ -4200,7 +4209,7 @@ export class Viewer extends ViewerBase{
         //-------------
         this.images360.tileDownloader.update() 
         this.images360.panoRenderer.update()
-        this.images360.getNeighbours()
+        this.images360.getNeighbours(this.interacted)
         this.computeShelter()
         //-------------
 		if(this.stats){
@@ -4213,7 +4222,9 @@ export class Viewer extends ViewerBase{
 		this.resolveTimings(timestamp, Potree.measureTimings);
         //Potree.measureTimings = 1
 	}
-
+    
+    
+     
 	postError(content, params = {}){
 		let message = this.postMessage(content, params);