/**
 *
 * @param {*} Vec3  保存单前摄像机位置状态
 */
export function saveState() {
  //  保存当前摄像机位置
  if (this.viewSate && this.viewSate.isSave) return;
  this.viewSate = {
    position: this.camera.position.clone(),
    isSave: true,
  };
}
/**
 * 恢复摄像机状态
 */
export function resetState() {
  if (this.viewSate && this.viewSate.isSave) {
    this.viewSate.isSave = false;
    this.orbitControls.enabled = true;
    // //恢复原始的镜头指向
    // this.camera.lookAt(0, 0, 0);
    // this.orbitControls.target.set(0, 0, 0);
    //创建动画
    this.viewSateResetAnimation = new this.TWEEN.Tween({
      x: this.camera.position.x,
      y: this.camera.position.y,
      z: this.camera.position.z,
      tx: this.orbitControls.target.x,
      ty: this.orbitControls.target.y,
      tz: this.orbitControls.target.z,
    });
    this.viewSateResetAnimation.to(
      {
        x: this.viewSate.position.x,
        y: this.viewSate.position.y,
        z: this.viewSate.position.z,
        tx: 0,
        ty: 0,
        tz: 0,
      },
      500
    );
    this.viewSateResetAnimation.start();
    this.viewSateResetAnimation.onUpdate((obj) => {
      this.camera.position.set(obj.x, obj.y, obj.z);
      this.camera.lookAt(obj.tx, obj.ty, obj.tz);
      this.orbitControls.target.set(obj.tx, obj.ty, obj.tz);
    }),
      //清空boxHelper
      this.scene.remove(this.scene.getObjectByName("boxHelper"));
  }
}
