diff --git a/src/core/App.js b/src/core/App.js index 56dd92e..3e4e61f 100644 --- a/src/core/App.js +++ b/src/core/App.js @@ -7,12 +7,14 @@ import { CesiumGlobe } from '../scene/CesiumGlobe.js'; import { Overlay } from '../ui/overlay.js'; import { clamp, easeInOutCubic } from '../utils/easing.js'; +// Three.js 相机的初始位(仅活页本/时间轴;地理视图用 Cesium 自己的相机) const CAMERA_POSES = { binder: { pos: new THREE.Vector3(0.2, 0.75, 2.95), target: new THREE.Vector3(0, 0.02, 0), max: 4.4, min: 2.4 }, timeline: { pos: new THREE.Vector3(0, 1.4, 6.86), target: new THREE.Vector3(0, 0, 0), max: 8, min: 1.2 }, - globe: { pos: new THREE.Vector3(0, 0.35, 3.7), target: new THREE.Vector3(0, 0, 0), max: 8, min: 2.2 }, }; +const VIEWS = ['binder', 'timeline', 'globe']; + export class App { constructor() { this.view = 'binder'; @@ -367,7 +369,7 @@ export class App { } switchView(view) { - if (view === this.view || !CAMERA_POSES[view]) return; + if (view === this.view || !VIEWS.includes(view)) return; // 地理视图尚未就绪(按钮仍置灰)时忽略切换,键盘也无法绕过 if (view === 'globe' && !this.globe.viewer) return; // 离开当前视图前,记住它的相机位置 @@ -417,28 +419,20 @@ export class App { // 登记卡详情在视图切换时保持显示,不隐藏 document.getElementById('detail-card').classList.remove('hidden'); - const pose = CAMERA_POSES[view]; - this.controls.minDistance = pose.min; - this.controls.maxDistance = pose.max; - // 时间轴:锁定旋转/平移;滚轮缩放;拖拽左右滑动 - const locked = view === 'timeline'; - this.controls.enableRotate = !locked; - this.controls.enablePan = !locked; - this.controls.enableZoom = false; // 滚轮缩放改为自定义渐变动画 - this.controls.autoRotate = false; - - // 左键旋转限制:以各视图初始视角为中心,各方向 ±10° - this._applyRotationLimits(pose); - - // 进入时间轴时:自动定位到当前选中的活页居中 - if (view === 'timeline') { - const limit = TIMELINE_SPREAD + 0.6; - this.timelineOffset = clamp(-this.timeline.getCardX(this.selected), -limit, limit); - this.timeline.group.position.x = this.timelineOffset; - this.timeline.refreshTextures(); - } - if (!isGlobe) { + const pose = CAMERA_POSES[view]; + this.controls.minDistance = pose.min; + this.controls.maxDistance = pose.max; + // 时间轴:锁定旋转/平移;滚轮缩放;拖拽左右滑动 + const locked = view === 'timeline'; + this.controls.enableRotate = !locked; + this.controls.enablePan = !locked; + this.controls.enableZoom = false; // 滚轮缩放改为自定义渐变动画 + this.controls.autoRotate = false; + + // 左键旋转限制:以各视图初始视角为中心,各方向 ±10° + this._applyRotationLimits(pose); + // 切换视图:直接定位(有记忆则恢复上次的相机位置) this.cameraTween = null; this.zoomTarget = null; @@ -451,6 +445,14 @@ export class App { this.controls.target.copy(pose.target); } } + + // 进入时间轴时:自动定位到当前选中的活页居中 + if (view === 'timeline') { + const limit = TIMELINE_SPREAD + 0.6; + this.timelineOffset = clamp(-this.timeline.getCardX(this.selected), -limit, limit); + this.timeline.group.position.x = this.timelineOffset; + this.timeline.refreshTextures(); + } this._needsRender = true; }