Преглед изворни кода

fix: animation almost done

xzw пре 4 месеци
родитељ
комит
36026a3382
3 измењених фајлова са 54 додато и 25 уклоњено
  1. 51 22
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map
  3. 2 2
      src/sdk/cover/index.js

+ 51 - 22
public/lib/potree/potree.js

@@ -75964,6 +75964,7 @@
 	      this.transformControls.detach(); //viewer.transformObject(null);
 	      //console.log('selectModel', null)
 	    }
+	    this.bus.dispatchEvent('changeSelect');
 	  },
 	  updateBoxHelper(model) {
 	    var size = new Vector3();
@@ -82114,6 +82115,17 @@
 	    this.duration = 0; //动画时长
 	    this.time = 0; //当前播放时间
 	    this.cursorTime = 0; //时间轴指针时间
+
+	    this.keepDistance = true; //focus的物体和相机保持不变的距离
+	    this.poseTransition = false; //pose缓动
+
+	    if (Potree.settings.isOfficial) {
+	      viewer.modules.MergeEditor.bus.addEventListener('changeSelect', () => {
+	        var targetObject = viewer.modules.MergeEditor.selected;
+	        targetObject = this.ifContainsModel(targetObject) ? targetObject : null;
+	        this.setCameraFollow(targetObject);
+	      });
+	    }
 	  }
 	  addKey(model, keyType, key) {
 	    var keys = this[keyType + 'Keys'].get(model);
@@ -82145,7 +82157,8 @@
 	    this.addKey(model, keyType, key);
 	  }
 	  at(time, delta, force) {
-	    var _this = this;
+	    var _this$camFollowObject,
+	      _this = this;
 	    this.dispatchEvent({
 	      type: 'atTime',
 	      time
@@ -82161,7 +82174,9 @@
 	    if (this.time == time && !force) return;
 	    this.time = time; //真实值
 
+	    var oldDisToCam = ((_this$camFollowObject = this.camFollowObject) === null || _this$camFollowObject === void 0 ? void 0 : _this$camFollowObject.length) == 1 && this.keepDistance && this.camFollowObject[0].boundCenter.distanceTo(viewer.mainViewport.view.position);
 	    var transitionRatio = 0.05 * delta * 60; //渐变系数,越小缓动程度越高,越平滑 //假设标准帧率为60fps,当帧率低时(delta大时) 降低缓动。速度快时缓动太高会偏移路径
+	    var transitionRatio2 = 0.8 * delta * 60;
 	    var _loop = function _loop() {
 	      //路径。开头结尾和别的衔接过渡
 	      var atPath; //是否在path中 至多只有一个 
@@ -82239,8 +82254,13 @@
 	          lerp.quaternion(_model2.quaternion, quaternion)(transitionRatio); //每次只改变一点点  
 	          lerp.vector(_model2.position, position)(transitionRatio);
 	        } else {
-	          _model2.position.copy(position);
-	          _model2.quaternion.copy(quaternion);
+	          if (this.poseTransition && delta != void 0) {
+	            lerp.quaternion(_model2.quaternion, quaternion)(transitionRatio2); //每次只改变一点点  
+	            lerp.vector(_model2.position, position)(transitionRatio2);
+	          } else {
+	            _model2.position.copy(position);
+	            _model2.quaternion.copy(quaternion);
+	          }
 	        }
 	      }
 	      _model2.dispatchEvent('position_changed');
@@ -82296,21 +82316,24 @@
 	    }
 	    {
 	      if (this.camFollowObject) {
-	        //in front of model
-	        var dir = new Vector3(0, 0.1, 1).normalize(); //稍微朝上
-
+	        //in front of model 
 	        if (this.camFollowObject.length == 1) {
-	          var dis = 4;
 	          var _model4 = this.camFollowObject[0];
-	          dir.multiplyScalar(dis).applyQuaternion(_model4.quaternion);
-	          var pos = new Vector3().addVectors(_model4.boundCenter, dir);
-	          viewer.mainViewport.view.position.copy(pos);
-	          viewer.mainViewport.view.lookAt(_model4.boundCenter);
+	          if (this.camFaceToObject) {
+	            var dis = 4;
+	            var dir = new Vector3(0, 0.1, 1).normalize(); //稍微朝上
+	            dir.multiplyScalar(dis).applyQuaternion(_model4.quaternion);
+	            var pos = new Vector3().addVectors(_model4.boundCenter, dir);
+	            viewer.mainViewport.view.position.copy(pos);
+	            viewer.mainViewport.view.lookAt(_model4.boundCenter);
+	          } else if (this.keepDistance) {
+	            //不改镜头方向 保持一定角度。如果要改镜头方向,把lookAt提前
+	            viewer.mainViewport.view.position.subVectors(_model4.boundCenter, viewer.mainViewport.view.direction.clone().multiplyScalar(oldDisToCam));
+	            viewer.mainViewport.view.radius = oldDisToCam;
+	          } else {
+	            viewer.mainViewport.view.lookAt(_model4.boundCenter);
+	          }
 	        } else {
-	          /* let dirAve = new THREE.Vector3
-	          this.camFollowObject.forEach(model=>{
-	              dirAve.add(dir.clone().applyQuaternion(model.quaternion))
-	          }) */
 	          viewer.modules.MergeEditor.focusOn(this.camFollowObject, 0, true /* ,false,dirAve */);
 	        }
 	      }
@@ -82334,13 +82357,11 @@
 	  }
 	  play() {
 	    var {
-	      camFollowObject,
 	      time = -maxClipFadeTime / 2
 	    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
 	    //动画时长比duration多一个maxClipFadeTime,为了给开始和结束动画过渡
 
 	    this.updateTimeRange();
-	    this.setCameraFollow(camFollowObject);
 	    this.playing && this.pause();
 	    var maxTime = this.duration + maxClipFadeTime / 2;
 	    this.playing = true;
@@ -82357,11 +82378,11 @@
 	        this.pause();
 	      }
 	    };
-	    viewer.addEventListener("update", this.onUpdate);
+	    viewer.addEventListener("update_start", this.onUpdate);
 	  }
 	  pause() {
 	    this.playing = false;
-	    viewer.removeEventListener("update", this.onUpdate);
+	    viewer.removeEventListener("update_start", this.onUpdate);
 	    /* for(let [model, keys] of this.clipKeys){
 	        model.actions.forEach(a=>a.stop())
 	    } */
@@ -82371,7 +82392,9 @@
 	    //for test
 	    this.camFollowObject = camFollowObject;
 	    if (!camFollowObject) return;
-	    Potree.settings.displayMode = 'showPointCloud';
+
+	    //Potree.settings.displayMode = 'showPointCloud'
+
 	    if (!(this.camFollowObject instanceof Array)) {
 	      //支持相机跟随多个物体,对着bound的中心
 	      this.camFollowObject = [this.camFollowObject];
@@ -82590,6 +82613,12 @@
 	      if (_loop5(_name)) continue;
 	    }
 	  }
+	  ifContainsModel(model) {
+	    //动画帧里是否包含它
+	    return [this.poseKeys, this.pathKeys, this.clipKeys].some(e => {
+	      return e.has(model);
+	    });
+	  }
 	}
 
 	/* 
@@ -82638,7 +82667,7 @@
 	  速度       每个模型的步长系数    幅度
 
 	 
-
+	 
 
 	 */
 
@@ -90537,7 +90566,7 @@
 	        dis += camera.near;
 	      }
 	      dis = Math.max(0.1, dis);
-
+	      o.maxDis && (dis = Math.min(o.maxDis, dis));
 	      //三个顶点以上的由于measure的中心不等于bound的中心,所以点会超出bound外。 且由于视椎近大远小,即使是两个点的,bound居中后线看上去仍旧不居中.
 
 	      //获得相机最佳位置

Разлика између датотеке није приказан због своје велике величине
+ 1 - 1
public/lib/potree/potree.js.map


+ 2 - 2
src/sdk/cover/index.js

@@ -483,7 +483,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
             fly() {
                 if(measure.type == 'Path') Potree.settings.displayMode = 'showPointCloud'
                 
-                let result = viewer.focusOnObject(measure, 'measure', 1200, {dontLookUp:measure.type == 'Path'})
+                let result = viewer.focusOnObject(measure, 'measure', 1200, {dontLookUp:measure.type == 'Path', maxDis:  measure.fadeFar && measure.fadeFar*1.5})
  
                 return result.msg ? result.msg : result.promise
                 //返回值 1 deferred 表示即将位移 2 'posNoChange' 表示已在最佳位置 3 'tooFar' 表示距离最佳位置太远 
@@ -1404,7 +1404,7 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                 bus,
                 play(){
                     console.log('play ani,  time:', AnimationEditor.cursorTime)
-                    AnimationEditor.play({time:AnimationEditor.cursorTime})
+                    AnimationEditor.play({time:AnimationEditor.cursorTime })
                 },
                 pause(){
                     console.log('pause ani')