xzw %!s(int64=2) %!d(string=hai) anos
pai
achega
6591685d03
Modificáronse 4 ficheiros con 74 adicións e 21 borrados
  1. 28 7
      public/package/js/label.js
  2. 18 3
      public/package/js/objViewer.js
  3. 18 1
      public/package/js/utils.js
  4. 10 10
      src/views/Home_pc.vue

+ 28 - 7
public/package/js/label.js

@@ -35,9 +35,23 @@ class Label2D extends THREE.EventDispatcher {
             let update = (e) => {
                 this.update(e)
             }
-            viewer.addEventListener("view.changed", update)
+            let updateShelter = ()=>{
+                if (this.shelterByModel){
+                    if (convertTool.ifShelter(this.position, this.pos2d, viewer.camera, viewer.model.children, 0.05)) {
+                        this.sheltered = true
+                        this.elem.css('display', 'none'); 
+                    }else{
+                        this.sheltered = false
+                        this.update()
+                    }
+                }
+            }
+            viewer.addEventListener("view.changed", update) 
+            viewer.addEventListener("delayUpdate", updateShelter) 
+            
             this.addEventListener('dispose', (e) => {
                 viewer.removeEventListener("view.changed", update)
+                viewer.removeEventListener("delayUpdate", updateShelter)
             })
         }
         this.visible = true
@@ -46,21 +60,28 @@ class Label2D extends THREE.EventDispatcher {
     }
 
 
-
+    updateShelter
 
  
     update(e={}) {
-        if (!this.position || !this.visible || !e.changeSlightly && this.sheltered) return
+        if (!this.position || !this.visible || this.sheltered) return
  
 
         var p = convertTool.getPos2d(this.position, viewer.camera, $("#player")[0]);
+        this.pos2d = p.vector;
+        
+        
         if (!p || !p.trueSide) {
             this.elem.css('display', 'none'); return;
         }
 
         //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
-
-        if (e.changeSlightly) {//防卡: 画面要停止转动时才执行
+    
+    
+    
+            
+    
+       /*  if (e.changeSlightly) {//防卡: 画面要停止转动时才执行
             if (this.shelterByModel && convertTool.ifShelter(this.position, p.vector, viewer.camera, viewer.model.children, 0.05)) {
                 this.sheltered = true
                 this.elem.css('display', 'none'); return;
@@ -69,7 +90,7 @@ class Label2D extends THREE.EventDispatcher {
             }
         } else {
             //console.log('!changeSlightly')
-        }
+        } */
 
 
         this.elem.css({
@@ -78,7 +99,7 @@ class Label2D extends THREE.EventDispatcher {
         })
 
         this.elem.css('display', 'block');
-        this.pos2d = p.vector;
+        
     }
 
     setVisible(visi, reason, level = 0, type) {

+ 18 - 3
public/package/js/objViewer.js

@@ -159,7 +159,7 @@ Viewer.prototype.init = function () {
 }
 
 
-
+let delayNeedUpdated
 Viewer.prototype.animate = function () {
     var deltaTime = Math.min(1, this.updateClock.getDelta());
     this.update(deltaTime)
@@ -168,7 +168,20 @@ Viewer.prototype.animate = function () {
     let changed = this.hasChanged()
     if (changed.cameraChanged) {
         this.dispatchEvent({ type: 'view.changed', changeSlightly: changed.changeSlightly })
-
+        delayNeedUpdated = true
+        
+        if( !transitions.funcs.some(function (e) { return e.name === 'cameraFly' })){
+            convertTool.intervalTool.isWaiting('delayUpdate', ()=>{ //延时update,防止卡顿
+                if(delayNeedUpdated){  
+                    delayNeedUpdated = false 
+                    this.dispatchEvent({ type: 'delayUpdate'  }) 
+                    console.log('delayUpdate')                
+                    return true 
+                } 
+            }, 200)
+        }
+        
+        
         let label_ = this.labels.filter(e => e.elem[0].style.display == 'block')
         label_.sort((a, b) => b.pos2d.z - a.pos2d.z)
         label_.forEach((e, index) => e.elem.css('z-index', index + 1000));
@@ -311,6 +324,7 @@ Viewer.prototype.onPointerDown = function (event) {
     mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
     mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
     this.pointerDownPos = mouse.clone()
+    //console.log('onPointerDown')
 }
 
 Viewer.prototype.onPointerUp = function (event) {
@@ -319,7 +333,7 @@ Viewer.prototype.onPointerUp = function (event) {
     this.dispatchEvent({ type: 'onPointerUp' })
     mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
     mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
-    if (mouse.distanceTo(this.pointerDownPos) < 0.006) {//click
+    if (this.pointerDownPos && mouse.distanceTo(this.pointerDownPos) < 0.006) {//click
         this.checkIntersection()
         // if (this.intersects.length) {
         //     console.log(this.intersects[0].point);
@@ -337,6 +351,7 @@ Viewer.prototype.onPointerUp = function (event) {
         // this.clickTime = time;
     }
     this.pointerDownPos = null
+    //console.log('onPointerUp')
 }
 
 

+ 18 - 1
public/package/js/utils.js

@@ -498,7 +498,24 @@ let convertTool = {
         } else return f(e, t)
     },
 
-
+    intervalTool:{  //延时update,防止卡顿
+        list:[],
+        
+        isWaiting:function(name, func, delayTime){
+            if(!this.list.includes(name)){  //如果没有该项, 则开始判断
+                var needWait = func(); //触发了改变,则等待一段时间后再自动判断
+                if(needWait){
+                    this.list.push(name);
+                    setTimeout(()=>{
+                        var a = this.list.indexOf(name);
+                        this.list.splice(a,1);
+                        this.isWaiting(name, func, delayTime) //循环
+                    },delayTime)
+                } 
+            }
+        }, 
+    }
+    ,
 
 }
 

+ 10 - 10
src/views/Home_pc.vue

@@ -195,7 +195,7 @@ export default {
         () => { },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
     },
 
     info() {
@@ -212,7 +212,7 @@ export default {
         () => { },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
 
       //模型旋转角度
 
@@ -227,7 +227,7 @@ export default {
         },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
 
       //相机位置
       window.transitions.start(
@@ -237,7 +237,7 @@ export default {
         () => { },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
 
 
     },
@@ -258,7 +258,7 @@ export default {
         },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
 
       //模型位置
 
@@ -269,7 +269,7 @@ export default {
         () => { },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
 
       //模型旋转角度
 
@@ -283,7 +283,7 @@ export default {
         },
         0/* Delay */,
         window.easing.easeInOutQuad,
-        null);
+        'cameraFly');
 
 
     },
@@ -333,8 +333,8 @@ export default {
     let textrueLoader = new window.THREE.TextureLoader();
 
 
-    window.viewer.addEventListener("view.changed", (e) => {
-      if (e.changeSlightly) {
+    window.viewer.addEventListener("delayUpdate", (e) => {
+      //if (e.changeSlightly) {
         setTimeout(() => {
           if (this.currentItem == 'pic') {
             let centerLabel = window.viewer.getCLabel()
@@ -350,7 +350,7 @@ export default {
             }
           }
         });
-      }
+      //}
     })
 
     window.viewer.addEventListener("onPointerUp", () => {