火箭模拟地球贴图改用 assets 内置资源并按系统时间昼夜切换

- 贴图路径由 /upload/texture 改为 /upload/assets,昼夜两张图都随 git 分发
- 06:00-18:00 用昼间图,其余时间用夜间城市灯光图(挂载时取一次,飞行途中不跳变)
- .gitignore 只放行 backend/upload/assets,其余上传目录仍排除
- docker-compose 把仓库的 assets 只读挂到 /app/upload/assets,避免依赖数据目录
main
mula.liu 2026-10-08 00:47:20 +08:00
parent 24e191f991
commit f940f1381d
6 changed files with 16 additions and 3 deletions

4
.gitignore vendored
View File

@ -3,7 +3,9 @@
# 运行时上传目录:管理端上传的纹理/模型/图标、用户头像等,不随 git 分发
# (服务器上运行时读的是 bind mount 的 /opt/cosmo/data/upload)
/backend/upload/
# 例外:assets 是随代码分发的内置资源(火箭模拟的昼/夜地球贴图、滴答音效)
/backend/upload/*
!/backend/upload/assets/
# OS files
.DS_Store

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

View File

@ -87,6 +87,9 @@ services:
HTTPS_PROXY: ${HTTPS_PROXY:-}
volumes:
- /opt/cosmo/data/upload:/app/upload
# 仓库内置资源(火箭模拟的昼/夜地球贴图、滴答音效)随 git 分发,
# 单独挂到 /app/upload/assets,免得每次升级都要往数据目录里拷一份。
- ./backend/upload/assets:/app/upload/assets:ro
- /opt/cosmo/data/logs/backend:/app/logs
ports:
- "8000:8000"

View File

@ -21,11 +21,18 @@ interface RocketFlightSceneProps {
const EARTH_RADIUS_METERS = 6_371_000;
const EARTH_RADIUS = 34;
const EARTH_TEXTURE = '/upload/texture/2k_earth_daymap.jpg';
const EARTH_DAY_TEXTURE = '/upload/assets/2k_earth_daymap.jpg';
const EARTH_NIGHT_TEXTURE = '/upload/assets/2k_earth_nightmap.jpg';
const EARTH_CENTER = new THREE.Vector3(0, -EARTH_RADIUS, 0);
const EARTH_ROTATION = new THREE.Euler(0, -1.25, -0.08);
const VIEW_SCALE_CALIBRATION = 0.7;
/** 地球贴图按系统时间取用:06:00-18:00 用昼间图,其余时间用夜间的城市灯光图。 */
function earthTexturePath() {
const hour = new Date().getHours();
return hour >= 6 && hour < 18 ? EARTH_DAY_TEXTURE : EARTH_NIGHT_TEXTURE;
}
interface LaunchSite {
latitude: number;
longitude: number;
@ -461,7 +468,8 @@ function Atmosphere({ state, mode }: { state: SimulationState; mode: CameraMode
}
function SceneContents({ rocket, state, cameraMode, viewScale, viewScaleResetTrigger, onViewScaleChange }: RocketFlightSceneProps) {
const earthTexture = useOptionalTexture(EARTH_TEXTURE);
// 只在挂载时取一次小时数,免得一次飞行中途跨过 6/18 点导致贴图来回跳。
const earthTexture = useOptionalTexture(useMemo(() => earthTexturePath(), []));
const manualCameraRef = useRef(false);
const orbitControlsRef = useRef<OrbitControlsImpl>(null);
const manualDistanceRef = useRef<number | null>(null);