浏览代码

fix: 改善路径飞行

xzw 7 月之前
父节点
当前提交
c7bca35ea9
共有 3 个文件被更改,包括 79 次插入60 次删除
  1. 66 51
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map
  3. 12 8
      src/sdk/cover/index.js

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

@@ -43229,6 +43229,7 @@
 	    if (count <= 1) {
 	      geo = voidGeometry;
 	      this.geoPoints = [];
+	      this.curve = null;
 	    } else {
 	      if (Potree.settings.pathSmooth) {
 	        //使用曲线
@@ -59318,6 +59319,7 @@
 	  position: 'red',
 	  target: 'blue'
 	};
+	var lastQuaternion;
 	var lineMats$1;
 	var getLineMat = function getLineMat(name) {
 	  if (!lineMats$1) {
@@ -59578,36 +59580,49 @@
 	        percent = easing.easeOutSine(originPercent-(1-easePercent), 1-easePercent, easePercent, easePercent)
 	    } */
 
-	    var quaternion, position;
-	    if (percent < 1) {
-	      //修改第二层:使用每个点的重定位的 newPointsPercents
-
-	      this.currentIndex = this.newPointsPercents.findIndex(e => e > percent) - 1;
-	      //假设每个节点的百分比是精确的,那么:
-	      var curIndexPercent = this.newPointsPercents[this.currentIndex];
-	      var nextIndexPercent = this.newPointsPercents[this.currentIndex + 1];
-	      var progress = (percent - curIndexPercent) / (nextIndexPercent - curIndexPercent); //在这两个节点间的百分比
-
-	      //投影到原本的 posCurve.pointsPercent上:
-	      var curIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex];
-	      var nextIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex + 1];
-	      percent = curIndexOriPercent + (nextIndexOriPercent - curIndexOriPercent) * progress;
-	      var endQuaternion = this.quaternions[this.currentIndex + 1];
-	      var startQuaternion = this.quaternions[this.currentIndex];
-	      quaternion = new Quaternion().copy(startQuaternion);
-	      lerp.quaternion(quaternion, endQuaternion)(progress);
-
-	      /* let endPos = this.posCurve.points[this.currentIndex+1]
-	      let startPos = this.posCurve.points[this.currentIndex]       
-	      position = (new THREE.Vector3()).copy(startPos) 
-	      lerp.vector(position, endPos)(progress)    */
+	    var position = this.posCurve.getPointAt(percent); // 需要this.posCurve.points.length>1 否则报错
+	    var quaternion;
+	    if (this.quaFromCurveTan) {
+	      //沿着curve行走,目视curve前方
+	      var percent2 = percent + (this.tangentDt || 0.001);
+	      if (percent2 <= 1) {
+	        var position2 = this.posCurve.getPointAt(percent2);
+	        quaternion = math.getQuaFromPosAim(position, position2);
+	      } else {
+	        quaternion = lastQuaternion;
+	      }
 	    } else {
-	      this.currentIndex = this.posCurve.points.length - 1;
-	      quaternion = this.quaternions[this.currentIndex];
-	      position = this.posCurve.points[this.currentIndex];
+	      if (percent < 1) {
+	        //修改第二层:使用每个点的重定位的 newPointsPercents
+
+	        this.currentIndex = this.newPointsPercents.findIndex(e => e > percent) - 1;
+	        //假设每个节点的百分比是精确的,那么:
+	        var curIndexPercent = this.newPointsPercents[this.currentIndex];
+	        var nextIndexPercent = this.newPointsPercents[this.currentIndex + 1];
+	        var progress = (percent - curIndexPercent) / (nextIndexPercent - curIndexPercent); //在这两个节点间的百分比
+
+	        //投影到原本的 posCurve.pointsPercent上:
+	        var curIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex];
+	        var nextIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex + 1];
+	        percent = curIndexOriPercent + (nextIndexOriPercent - curIndexOriPercent) * progress;
+	        var endQuaternion = this.quaternions[this.currentIndex + 1];
+	        var startQuaternion = this.quaternions[this.currentIndex];
+	        quaternion = new Quaternion().copy(startQuaternion);
+	        lerp.quaternion(quaternion, endQuaternion)(progress);
+
+	        /* if(this.posInterpolate){  
+	            let endPos = this.posCurve.points[this.currentIndex+1]
+	            let startPos = this.posCurve.points[this.currentIndex]       
+	            position = (new THREE.Vector3()).copy(startPos) 
+	            lerp.vector(position, endPos)(progress) 
+	        }           */
+	      } else {
+	        this.currentIndex = this.posCurve.points.length - 1;
+	        quaternion = this.quaternions[this.currentIndex];
+	        position = this.posCurve.points[this.currentIndex];
+	      }
 	    }
-	    position = this.posCurve.getPointAt(percent); // 需要this.posCurve.points.length>1 否则报错
-
+	    lastQuaternion = quaternion;
 	    //console.log(this.currentIndex, originPercent)
 	    //缓动:
 	    var aimQua, aimPos;
@@ -59620,8 +59635,8 @@
 	        aimQua = camera.quaternion.clone();
 	        aimPos = camera.position.clone();
 	      }
-	      transitionRatio = transitionRatio || 1 / Potree.settings.cameraAniSmoothRatio; //渐变系数,越小缓动程度越高,越平滑
-	      transitionRatio *= delta * 60; //假设标准帧率为60fps,当帧率低时(delta大时)要降低缓动
+	      transitionRatio = transitionRatio || 1 / (this.cameraAniSmoothRatio || Potree.settings.cameraAniSmoothRatio); //渐变系数,越小缓动程度越高,越平滑
+	      transitionRatio *= delta * 60; //假设标准帧率为60fps,当帧率低时(delta大时) 降低缓动。速度快时缓动太高会偏移路径
 	      //console.log(transitionRatio, delta) //画面ui变化会使delta变大
 	      transitionRatio = MathUtils.clamp(transitionRatio, 0, 1);
 	      lerp.quaternion(aimQua, quaternion)(transitionRatio); //每次只改变一点点  
@@ -59710,7 +59725,7 @@
 	      var frame = this.at(percent, e.delta, transitionRatio);
 	      if (currentIndex != this.currentIndex) {
 	        currentIndex = this.currentIndex;
-	        console.log('updateCurrentIndex', currentIndex);
+	        //console.log('updateCurrentIndex', currentIndex)
 	        this.dispatchEvent({
 	          type: 'updateCurrentIndex',
 	          currentIndex
@@ -74207,30 +74222,30 @@
 	class CameraAnimationCurve extends EventDispatcher {
 	  //沿着curve轨迹的相机动画,不指定target,因视线沿着路线
 
-	  constructor(curve, points, UtoTMapArr, duration) {
+	  constructor(curve, duration, tangentDt) {
+	    //直接传入curve得到的points和UtoTMapArr
 	    //简单写
 	    super();
+	    this.quaFromCurveTan = true;
 	    this.viewer = viewer;
-	    this.curve = curve;
+	    //this.curve = curve
 	    this.duration = duration;
-	    this.newPointsPercents = UtoTMapArr.slice();
-	    this.posCurve = {
-	      points,
-	      pointsPercent: this.newPointsPercents,
-	      getPointAt(t) {
-	        return curve.getPointAt(t);
-	      }
-	    };
-
+	    this.cameraAniSmoothRatio = 5; //缓动系数设置小点,尽量贴合路径,尤其速度快时
+	    //this.newPointsPercents = UtoTMapArr.slice()
+	    //this.posInterpolate = true  //不直接在curve上取点,因为UtoTMapArr也是getUtoTmapping得来的, curve上getUtoTmapping后和这个不对应。否则要再算一遍pointsPercent
+
+	    /* this.posCurve = { points getPointAt(t){
+	        return curve.getPointAt(t)
+	    } } */
+	    this.posCurve = curve;
 	    //每个点直接朝向前面那个点
-	    this.quaternions = [];
-	    var quaternion,
-	      length = points.length;
-	    for (var i = 0; i < length - 1; i++) {
-	      quaternion = math.getQuaFromPosAim(points[i], points[i + 1]);
-	      this.quaternions.push(quaternion);
+	    /* this.quaternions = [] 
+	    let quaternion, length = points.length
+	    for(let i=0; i<length-1; i++){
+	        quaternion = math.getQuaFromPosAim( points[i],  points[i+1]) 
+	        this.quaternions.push(quaternion) 
 	    }
-	    this.quaternions.push(quaternion); //最后一个点的朝向和前一个相同即可
+	    this.quaternions.push(quaternion)//最后一个点的朝向和前一个相同即可 */
 	  }
 	  setVisible() {}
 	  updateFrustum() {}
@@ -74445,8 +74460,8 @@
 	    };
 	    return result;
 	  },
-	  createCurveAni(curve, points, UtoTMapArr, duration) {
-	    var ani = new CameraAnimationCurve(curve, points, UtoTMapArr, duration);
+	  createCurveAni(curve, duration, tangentDt) {
+	    var ani = new CameraAnimationCurve(curve, duration, tangentDt);
 	    return ani;
 	  }
 	};

文件差异内容过多而无法显示
+ 1 - 1
public/lib/potree/potree.js.map


+ 12 - 8
src/sdk/cover/index.js

@@ -1634,6 +1634,8 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                 
                 
                 play(playDone){
+                    if(path.points.length < 2)return playDone && playDone()  //no points
+                    
                     
                     let oldStates = {
                        editEnable:  path.editEnable,
@@ -1642,15 +1644,16 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                     path.editEnable && functions.changeEditMode(false)
                     path.addOrRemovePoint && path.setAddOrRemPoint(false)
                   
-                    /* if(Potree.settings.pathSmooth){ 
+                    if(Potree.settings.pathSmooth){  
                         let curve = path.curve.clone();
                             curve.points.forEach(e=>e.z += 2)
-                        let geoPoints = path.geoPoints.map(e=> e.clone().add(new THREE.Vector3(0,0,2)) )//height
-                        let duration = path.totalLength / 30 
-                        path.animation_ = viewer.modules.CamAniEditor.createCurveAni(curve,  geoPoints, path.UtoTMapArr, duration, 2)
-                    }else{ */
+                        //let geoPoints = path.geoPoints.map(e=> e.clone().add(new THREE.Vector3(0,0,2)) )//height
+                        let duration = path.totalLength / 3  
+                        //let tangentDt =  path.totalLength * 0.0001
+                        path.animation_ = viewer.modules.CamAniEditor.createCurveAni(curve,  duration   )
+                    }else{
                         functions.createAni();//不传参数时路径最圆润缓和,但会脱离原路径。传参后除了拐弯都按路径,参数越大越圆润,但容易有折回的bug。 如果没有严格要求就不传参效果最佳。
-                    //}
+                    }
                     path.animation_.play() 
                     path.animation_.addEventListener('playDone', () => {
                         oldStates.editEnable && functions.changeEditMode(true)
@@ -1659,8 +1662,9 @@ export const enter = ({ dom, mapDom, isLocal, lonlat, scenes, laserRoot, laserOS
                     },{once:true}) 
                 },
                 pause(){
-                    path.animation_.pause()
-                    viewer.modules.CamAniEditor.removeAnimation(path.animation_)
+                    path.animation_?.pause()
+                    path.animation_ && viewer.modules.CamAniEditor.removeAnimation(path.animation_)
+                    path.animation_ = null
                 }
                 
             })