# Earth 前端结构 本文件描述当前 Earth 大屏前端的真实结构,重点是帮助后续继续改 HUD、图层、媒体面板、真实地形、BGP 可视化时,不再重复踩结构和状态同步上的坑。 相关规则建议一起参考: - [项目规则](/home/ray/dev/linkong/planet/rules.md) - [前端布局指南](/home/ray/dev/linkong/planet/docs/technical/zh/frontend-layout-guidelines.md) ## 当前目标 Earth 前端不是普通管理页,它是独立的大屏展示前端。当前产品目标是: - 维持地球视图的空间感和可读性 - 让 HUD、图层、媒体面板、BGP、卫星、海缆等保持统一交互 - 把加载中、已启用、已隐藏、锁定中这类状态做清楚 ## 当前入口 React 路由入口: - [Earth.tsx](/home/ray/dev/linkong/planet/frontend/src/pages/Earth/Earth.tsx) 当前做法很简单: - React 页面只负责提供一个全屏 `iframe` - 真正的 Earth 应用运行在: - [index.html](/home/ray/dev/linkong/planet/frontend/public/earth/index.html) 所以 Earth 前端本质上是 `public/earth` 下的一套独立静态应用。 ## 当前文件分层 ### 1. 页面入口与结构 - [index.html](/home/ray/dev/linkong/planet/frontend/public/earth/index.html) 职责: - HUD 基础 DOM - 图层面板 - 媒体面板 - 工具栏 - 设置弹窗 - 兼容旧元素 id ### 2. 主运行时 - [main.js](/home/ray/dev/linkong/planet/frontend/public/earth/js/main.js) 职责: - 地球初始化 - Three.js 场景组装 - 数据加载与刷新 - 各图层集成 - Earth 级别状态同步 ### 3. 地球控制层 - [controls.js](/home/ray/dev/linkong/planet/frontend/public/earth/js/controls.js) 职责: - 工具栏交互 - 图层面板交互 - 旋转/缩放/布局 - HUD 面板拖拽 - 图层开关状态机 - Earth 设置读取、持久化与重置 这份文件是 Earth 前端当前最核心的 UI 控制入口。 ### 4. UI 与状态消息 - [ui.js](/home/ray/dev/linkong/planet/frontend/public/earth/js/ui.js) 职责: - loading 面板 - status message - tooltip / error / 清理逻辑 当前 status message 有两类短提示: - 普通业务提示:通过 `showStatusMessage()` 入队显示。 - 手势提示:通过 `showGestureStatusMessage()` 直接短暂显示,用于缩放视角时的 `缩放 N%`。 手势提示不会抢占 loading 状态。对应样式是 [hud.css](/home/ray/dev/linkong/planet/frontend/public/earth/css/hud.css) 中的 `.earth-status-message.gesture`。 ### 5. 动作捕捉控制适配层 - [motion-control.js](/home/ray/dev/linkong/planet/frontend/public/earth/js/motion-control.js) 职责: - 作为 Motion Provider manager,统一接入 `browser_camera` 与 `motion_agent`。 - 默认使用浏览器 `getUserMedia` + 本地 MediaPipe 识别;高级模式可连接本地 Motion Capture Agent WebSocket。 - 处理浏览器摄像头权限/安全上下文错误,以及 Agent 断线重连和 `status` / `heartbeat`。 - 过滤低置信度和过快重复的手势事件。 - 将 `rotate_left`、`rotate_right`、`rotate_up`、`rotate_down`、`zoom_in`、`zoom_out`、`focus_prev`、`focus_next`、`layer_prev`、`layer_next`、`confirm` 映射到 `main.js` 暴露的动作入口。 - 解析 `skeleton` 调试事件并派发 `earth:motion-debug-frame`。 动作捕捉识别可以在浏览器本地执行,也可以在本地 Agent 中执行,但两者都不会把实时视频帧发给 SaaS 云端。`main.js` 暴露旋转、缩放、目标切换、图层切换和确认入口,并通过 `window.__planetEarth.motion` 提供调试入口。默认只有 URL 参数 `?motion=1`、本地存储 `planet-earth-motion-control-enabled=true`,或 Earth 设置中的“动捕调试模式”打开时才启动当前 provider。 动捕调试面板由 [motion-debug-panel.js](/home/ray/dev/linkong/planet/frontend/public/earth/js/motion-debug-panel.js) 负责。它监听 `earth:motion-debug-frame`,用 canvas 绘制归一化骨架点和连线;Browser Camera provider 会额外通过 `earth:motion-debug-video-source` 提供本机 `