Repository navigation
Add real-time 3D solar system simulator with ephemeris calculations - #1
Open
yipeng0428 wants to merge 4 commits into
Open
yipeng0428 wants to merge 4 commits into
yipeng0428 wants to merge 4 commits into
Conversation
基于 three.js 的单页太阳系模拟,行星位置按当前真实时刻由 JPL Standish 解析星历(1800–2050 六要素线性模型)计算,支持点选天体 查看实时量(日心距、与地球距离、光行时、轨道速度、相位角、近日点 日期等)与物理参数。 实现要点: - 零安装、零外部请求:three.js r169 以全局脚本形式内置(由 tools/make-three-bundle.mjs 从官方 ESM 构建机械改写),行星纹理 运行时用 Canvas 值噪声程序化生成,双击 index.html 即可运行。 - 自写轨道相机,精确区分拖拽与点击;拾取改用屏幕空间像素距离, 解决小目标(2–8 px)难以点中的问题。 - 三套比例映射(示意 √r / 真实距离 / 真实尺寸可调放大),并对 天体半径做轨道比例限幅,限幅生效时在界面明确标注。 - 时间控制:实时同步、1 分–1 年每秒流速、暂停、日期跳转与步进; 自转相位以 J2000 为零点计算,时间回拖可复现。 - tests/smoke.mjs:Playwright 冒烟测试 22 项断言,当前全部通过。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
|
Kilo Code Review could not run — your account is out of credits. Add credits or switch to a free model to enable reviews on this change. |
Owner
Author
CI 状态说明:
|
新增 tools/build-single-file.mjs:按 index.html 原有加载顺序,把 styles.css 与全部脚本内联成单个 HTML。由于项目本就不用 ES module、 不请求任何外部资源,内联后行为与多文件版完全一致。 - dist/solar-system.html(约 765 KB):零外部引用(0 个 link href / script src / url()),双击即可离线运行。 - tests/smoke.mjs 支持传入目标路径,可用同一套断言验证打包版; 多文件版与单文件版 22 项断言均全部通过。 - 内联时对字面量 </script 做防御性转义,避免日后源码中出现该串时 静默截断宿主标签。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
内容深度: - 月球:ELP2000-82B 截断式(Meeus 第 47 章,黄经 19 项 / 黄纬 13 项 / 距离 13 项)。对 Meeus 例 47.a 黄经差 0.0054°、距离差 17 km;139 个 朔望月平均 29.53095 天(理论 29.530588,差 0.5 分钟)。对黄经做一阶 总岁差改正,与行星的 J2000 框架对齐。 - 实时月相:相位名称、照亮比例、月龄、下次朔/望时刻,并绘制月相图 (北半球视角,8 个相位有像素级方向断言)。相位命名不按 45° 均分, 朔望弦各取 ±7.5° 窄窗口,避免把 110° / 照亮 68% 叫成"上弦"。 - 场景中的月球:方向真实、间距按母星放大倍数反向压缩,并按潮汐锁定 使月海密集的近地面始终朝向地球。 - 视星等:Astronomical Almanac 经典式;天王星 +5.6、海王星 +7.8、 冥王星 +14.5 与实际量级一致。土星未计环的贡献,界面已标注。 交互(借鉴外部参考页的信息设计,物理模型不借): - 左侧天体目录:固定顺序的导航锚点,编号与数字键快捷键同源。 - 定位标记:固定像素大小的空心环,真实比例下行星缩成亚像素点时 仍可定位与点击;天体够大时自动淡出。 - 屏幕比例尺:按割线而非导数计算——压缩映射在太阳处 dr/dd→0, 取导数会给出"100 px ≈ 33 km"的荒谬读数。 - 标签防重叠:按选中优先、近者优先摆放,重叠者退化为圆点。 诚实性与可访问性: - 越界警告:时间超出 Standish 根数表 1800–2050 的标称区间时明确提示 结果不可信;日期输入框按此设 min/max。 - WCAG 2.1 AA:次要文字对比度 4.22→5.4:1、canvas 可聚焦且方向键可 转动视角、统一 focus-visible、标签与目录改为真 button、开关加 role=switch。面板刻意不加 aria-live(9 Hz 刷新会让读屏器持续念数字), 改为仅在选中项变化时向专用状态区播报一次。 - 界面内直接给出数据来源链接。 测试:tests/smoke.mjs 断言 22 → 48 项,多文件版与单文件打包版均全通过。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
1) 平移修复(架构问题,不是事件问题)
主循环每帧调用 setTarget() 重设注视点,右键拖出的偏移在同一帧被
覆盖,所以平移此前完全不生效。改为:
注视点 = 基准点(场景每帧给,可能跟随天体)+ 平移偏移(用户拖的,持久)
平移量按目标平面上每像素的世界单位换算(2·tan(fov/2)·d / 视口高),
画面 1:1 跟随光标。右键 / 中键 / Shift+左键均可平移。
2) 锁定跟随
- 悬浮时提示下一步操作,文案随状态变化(未选 / 已选 / 已锁定)。
- 第一次单击选中,再次单击锁定;标签加锁定标记,面板按钮变为
"已锁定 · 解除"(aria-pressed)。
- 锁定后镜头持续跟随天体,但旋转、平移、缩放全部照常可用,
不会因交互而解除锁定。
- 解除锁定时把当前注视点转存进平移偏移,画面原地不动;只有显式
点「回到太阳」才重新取景,避免镜头被吸回太阳的突兀滑动。
3) 比例改为三挡互斥模型:简化示意 / 真实距离 / 完全真实
原先两个复选框可拼出"真实尺寸 + 压缩距离"这类自相矛盾的组合。
新增对"完全真实确实是 1:1"的逐项验证:直接量场景几何与真实公里数
对账,八大行星的半径/日心距比值、太阳半径/地球轨道半径、地月距离/
地球半径共 11 项,相对误差 <1e-9;同时断言简化示意模式下地球半径
确实被放大约 891 倍(模式语义自洽)。
太阳限幅阈值由 35% 调到 42%:示意太阳半径恰为水星轨道的 39.7%,
默认模式因此不再误触发限幅提示。
4) 移除尺寸放大滑杆(完全真实模式即 ×1,无需放大系数)。
测试:48 → 71 项,多文件版与单文件打包版均全通过。
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a complete, single-page solar system simulator that calculates planetary positions in real-time using JPL analytical ephemeris. The application requires no build tools or external dependencies (three.js is bundled) and runs directly from
file://by double-clickingindex.html.Key Changes
Ephemeris Engine (
src/ephemeris.js): Implements Standish/JPL Keplerian element model (1800–2050) with Newton-Raphson Kepler equation solver. Converts orbital elements to J2000 heliocentric ecliptic coordinates with ~10 arcsecond accuracy for inner planets.Scene Architecture (
src/app.js):Procedural Textures (
src/textures.js):UI Layer (
src/ui.js):Camera Controller (
src/controls.js): Custom orbit camera (no external dependencies) with precise click/drag distinction (<6 px, <450 ms = click), supporting rotate/pan/zoom via mouse and touch.Static Data (
src/data.js): Physical parameters (radius, mass, tilt, rotation period), orbital elements, color palettes, and descriptive facts for 10 bodies (Sun through Pluto).Styling (
styles.css): Dark theme with low saturation, monospace numerics for frame-by-frame readability, responsive layout with collapsible dock.Testing (
tests/smoke.mjs): Playwright-based smoke test verifying WebGL rendering, ephemeris sanity (perihelion/aphelion bounds), and UI interactivity.Build Tooling (
tools/make-three-bundle.mjs): Converts three.js ESM to IIFE global script by rewriting export statement, enablingfile://execution without a dev server.Notable Implementation Details
https://claude.ai/code/session_01DXvpPgYUh43Xv48Q5DtUtY