@yangyongtao/gaea 1.1.10 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,18 +1,29 @@
1
1
  # @yangyongtao/gaea
2
2
 
3
- Gaea 3D 可视化组件库 — 基于 Godot WASM 引擎的 Vue 3 组件包。
3
+ 基于 Godot WASM 引擎的 Vue 3 三维可视化组件库。提供影像/地形/贴地线加载、相机视角控制、图层树、天气控制、沿线飞行、断面游览、室内游览等能力,并内置 Vite 插件自动注入引擎资源。
4
4
 
5
- ## 安装
5
+ > 完整可运行示例参考消费者项目的 `src/App.vue`,本文所有片段均以其为参考。
6
+
7
+ ---
8
+
9
+ ## 1. 安装
6
10
 
7
11
  ```bash
8
12
  npm install @yangyongtao/gaea
9
13
  ```
10
14
 
11
- ## 快速开始
15
+ peerDependencies(按需安装):`vue ^3.4`、`element-plus ^2.6`(可选)、`pinia ^2.1`(可选)。
16
+
17
+ > ⚠️ 引擎大资源文件(`Gaea.pck` / `Gaea.wasm` / `1111.res` / `gltf` 等)**不随 npm 包分发**,需手动放置,详见第 8 节。
12
18
 
13
- ### 1. `vite.config.js`
19
+ ---
20
+
21
+ ## 2. Vite 配置
22
+
23
+ 引入并注册 `gaeaVitePlugin`,它会自动注入 `Gaea.js`、提供引擎静态资源、设置 SharedArrayBuffer 所需的跨域隔离响应头。
14
24
 
15
25
  ```js
26
+ // vite.config.js
16
27
  import { defineConfig } from 'vite';
17
28
  import vue from '@vitejs/plugin-vue';
18
29
  import { gaeaVitePlugin } from '@yangyongtao/gaea/plugin';
@@ -24,95 +35,210 @@ export default defineConfig({
24
35
  });
25
36
  ```
26
37
 
27
- ### 2. `src/App.vue`
38
+ ---
39
+
40
+ ## 3. 快速开始
41
+
42
+ 页面里需要一个 `id="canvas"` 的画布。调用 `setConfig(...)` 后 `new GaeaApp()` 即可自动完成「引擎启动 → 环境初始化 → 图层加载 → 模型加载」。
28
43
 
29
44
  ```vue
30
45
  <template>
31
46
  <div id="gaea-app">
47
+ <div class="toolbar">
48
+ <button @click="showWeather = !showWeather">天气控制</button>
49
+ <button @click="showFly = !showFly">沿线飞行</button>
50
+ <button @click="showLayerTree = !showLayerTree">图层控制</button>
51
+ <WaterGateTour />
52
+ </div>
32
53
 
33
- <div class="canvas-area">
54
+ <div class="canvas-area" id="canvas-container">
34
55
  <canvas id="canvas"></canvas>
35
56
  </div>
57
+
58
+ <WeatherControl v-if="showWeather" :appInstance="app" @close="showWeather = false" />
59
+ <FlyAlongRoute v-if="showFly" :appInstance="app" @close="showFly = false" />
60
+ <LayerTree v-if="showLayerTree" :appInstance="app" @close="showLayerTree = false" @node-click="onLayerNodeClick" />
61
+ <HydrologicStationDialog />
62
+ <SecTourView />
36
63
  </div>
37
64
  </template>
38
65
 
39
66
  <script setup>
40
67
  import { ref } from 'vue';
41
68
  import { GaeaApp, setConfig } from '@yangyongtao/gaea';
69
+ import { WeatherControl, FlyAlongRoute, HydrologicStationDialog, SecTourView, WaterGateTour } from '@yangyongtao/gaea/components';
70
+ import LayerTree from '@yangyongtao/gaea/components/LayerTree.vue';
42
71
 
43
- // 配置
44
72
  setConfig({
45
- serveLocal: `${window.location.origin}/static/`,
73
+ serveLocal: `${window.location.origin}/static`,
46
74
  serveUrl: 'http://192.168.3.151:8088/gaeaExplorerServer/',
47
- defaultLayers: [
48
- { layerName: 'earthland', forMat: 'image/png', min: 0, max: 18, transparency: 0.3 },
49
- { layerName: '苍南L19', forMat: 'image/png', min: 5, max: 17 },
50
- ],
51
- useTianditu: true,
52
- tiandituToken: '4ebb3872e465273416314341a99caea6',
75
+ serviceMode: 'platform',
53
76
  defaultCameraPosition: '27.3680928977018,120.414139621887,0,109379.690132486,0,0',
54
77
  });
55
- // 初始化(自动完成:引擎启动 → 环境初始化 → 图层加载)
78
+
56
79
  const app = new GaeaApp();
57
- window.APP = app;
80
+ window.APP = app; // 组件内部通过 window.APP 兜底获取实例
58
81
 
59
82
  const showWeather = ref(false);
60
83
  const showFly = ref(false);
84
+ const showLayerTree = ref(false);
85
+
86
+ function onLayerNodeClick({ node }) {
87
+ app.flyToNode(node);
88
+ }
61
89
  </script>
62
90
  ```
63
91
 
64
- ## API
92
+ ---
93
+
94
+ ## 4. setConfig 配置项
65
95
 
66
- ### 配置项
96
+ | 参数 | 类型 | 默认值 | 说明 |
97
+ |------|------|--------|------|
98
+ | `serveLocal` | string | `''` | 引擎本地静态资源地址(AssetHost),一般为 `${origin}/static` |
99
+ | `serveUrl` | string | `''` | 服务平台地址(WMTS 影像 / 地形 / 贴地线均基于此) |
100
+ | `serviceMode` | `'platform' \| 'online'` | `'platform'` | **服务模式**:见下方说明 |
101
+ | `tiandituToken` | string | — | 在线模式的天地图 token |
102
+ | `tiandituLevelRange` | [number,number] | `[0,18]` | 天地图层级范围 |
103
+ | `defaultLayers` | Array | 见下 | 服务平台模式下加载的影像图层 |
104
+ | `defaultTerrains` | Array | 见下 | 服务平台模式下加载的地形服务 |
105
+ | `defaultGroundLines` | Array | 见下 | 服务平台模式下加载的贴地线 |
106
+ | `defaultCameraPosition` | string | — | 初始相机视角:`纬度,经度,高程,相机高,俯仰,朝向` |
107
+ | `layerCategories` | Array | 内置 | 图层树分类数据(接口数据会合并进来) |
108
+ | `dataHubApiUrl` | string | `''` | 图层树数据接口地址,为空则只用默认数据 |
109
+ | `onProgress` | function | — | 引擎加载进度回调 `(cur, total) => {}` |
110
+
111
+ ### 4.1 serviceMode —— 服务模式(区分「服务平台」与「在线」)
112
+
113
+ - `'platform'`(服务平台):影像走 `serveUrl` 的 WMTS,并加载 `defaultTerrains` 地形、`defaultGroundLines` 贴地线。
114
+ - `'online'`(在线):**仅加载天地图影像**,不加载地形和贴地线(在线模式目前只有天地图一种影像来源)。
67
115
 
68
116
  ```js
69
- import { setConfig } from '@yangyongtao/gaea';
117
+ setConfig({ serviceMode: 'platform' }); // 内网/服务平台
118
+ // 或
119
+ setConfig({ serviceMode: 'online', tiandituToken: '你的token' }); // 在线(天地图)
120
+ ```
70
121
 
71
- setConfig({
72
- serveUrl: '', // WMTS 服务地址
73
- serveLocal: '', // 静态资源地址
74
- defaultLayers: [], // 默认影像图层
75
- defaultCameraPosition: 'lat,lng,alt,dist,pitch,heading',
76
- onProgress: (cur, total) => {}, // 引擎加载进度回调
77
- });
122
+ ### 4.2 defaultLayers —— 影像图层(服务平台模式)
123
+
124
+ ```js
125
+ defaultLayers: [
126
+ { layerName: 'earthland', forMat: 'image/png', min: 0, max: 18, transparency: 0.3 },
127
+ { layerName: '苍南L19', forMat: 'image/png', min: 5, max: 17 },
128
+ ]
129
+ ```
130
+ - `layerName`:WMTS 服务里的图层名(Title)
131
+ - `forMat`:影像格式,如 `image/png`、`image/jpeg`
132
+ - `min` / `max`:显示层级范围
133
+ - `transparency`:透明度(可选)
134
+
135
+ ### 4.3 defaultTerrains —— 地形服务(服务平台模式)
136
+
137
+ ```js
138
+ defaultTerrains: [
139
+ { name: '苍南县地形', url: 'htc/service/tms/1.0.0/苍南县地形@EPSG%3A4326@terrain/' },
140
+ ]
78
141
  ```
142
+ - `name`:地形名称
143
+ - `url`:相对 `serveUrl` 的路径(也支持传完整 `http(s)://` 地址)
144
+ - 空数组 `[]` 则不加载地形
145
+
146
+ ### 4.4 defaultGroundLines —— 贴地线(服务平台模式)
79
147
 
80
- ### GaeaApp 方法
148
+ 依赖 `serveUrl` 的 WMTS 矢量线服务(自动通过 `getAllServe` 获取服务列表后按名匹配)。
149
+
150
+ ```js
151
+ defaultGroundLines: [
152
+ { name: '苍南县边界', range: [0, 9], color: [255, 255, 0], index: 100 },
153
+ { name: '苍南县镇边界', range: [9, 15], color: [0, 255, 0], index: 80 },
154
+ { name: '苍南县村边界', range: [15, 19], color: [255, 255, 255], index: 60 },
155
+ { name: '沿浦海塘工程范围线', range: [0, 21], color: [0, 255, 255], index: 120 },
156
+ ]
157
+ ```
158
+ - `name`:矢量线服务名(Title)
159
+ - `range`:显示层级范围 `[min, max]`
160
+ - `color`:线颜色 `[r, g, b]`(0-255)
161
+ - `index`:渲染优先级
162
+ - 每项可加 `isInitLoad: false` 跳过该条
163
+
164
+ ---
165
+
166
+ ## 5. 组件说明
167
+
168
+ 组件从 `@yangyongtao/gaea/components` 导入;`LayerTree` 需按路径单独导入。多数交互组件接收 `:appInstance="app"`,未传时内部回退到 `window.APP`。
169
+
170
+ | 组件 | 说明 | 主要事件 |
171
+ |------|------|----------|
172
+ | `WeatherControl` | 天气/台风控制面板(含台风路线拾取与播放) | `@close` |
173
+ | `FlyAlongRoute` | 沿线飞行:地图拾取点位,可设飞行高度/时长 | `@close` |
174
+ | `LayerTree` | 图层树,点击节点飞行定位 | `@close`、`@node-click` |
175
+ | `HydrologicStationDialog` | 水文测站弹窗,自监听 `gaea-icon-click` 事件 | — |
176
+ | `SecTourView` | 断面游览滚动条,模型锁定后显示 | — |
177
+ | `WaterGateTour` | 室内游览按钮(下拉选择水闸模型) | — |
178
+
179
+ ---
180
+
181
+ ## 6. 常用实例方法(window.APP / app)
81
182
 
82
183
  | 方法 | 说明 |
83
184
  |------|------|
84
- | `new GaeaApp(options)` | 创建实例,自动初始化引擎/环境/图层 |
85
- | `app.getAllServe()` | 获取 WMTS 服务图层列表 |
86
- | `app.addLayer({ layerName, forMat, min, max, transparency })` | 添加影像图层 |
87
- | `app.SetPosition('lat,lng,alt,dist,pitch,heading')` | 定位到指定视角 |
88
- | `app.favorite()` | 记录当前视角,返回 URI 字符串 |
89
- | `app.favoritePosition(uri)` | 恢复已保存的视角 |
90
- | `app.ready` | Promise,等待初始化完成 |
185
+ | `SetPosition('纬度,经度,高程,相机高,俯仰,朝向')` | 定位到指定视角 |
186
+ | `flyToNode({ position:{x,y,z} })` | 飞到指定位置 |
187
+ | `flyAlongPath(lineData, options)` | 沿线飞行,`lineData=[{x:纬度,y:经度,z:高度}]`,`options={duration,xrotation,lockEye,...}` |
188
+ | `stopFlyAlongPath()` | 停止沿线飞行 |
189
+ | `cameraReset()` | 相机复位到 `defaultCameraPosition` |
190
+ | `addInitTerrainServer(terrains?)` | 手动加载地形(不传则用 `defaultTerrains`) |
191
+ | `addGroundLines(lines?)` | 手动加载贴地线(不传则用 `defaultGroundLines`) |
192
+ | `addTyphoonRoute(pointList, options)` | 加载台风路线并播放动画 |
193
+ | `clearTyphoonRoute()` | 清除台风路线 |
194
+ | `getAllServe()` | 获取 WMTS 服务图层列表 |
195
+ | `addLayer({ layerName, forMat, min, max, transparency })` | 添加影像图层 |
196
+ | `favorite()` / `favoritePosition(uri)` | 记录 / 恢复视角 |
91
197
 
92
- ### Vue 组件
198
+ ---
93
199
 
94
- ```vue
95
- <script setup>
96
- import { WeatherControl, FlyAlongRoute } from '@yangyongtao/gaea/components';
200
+ ## 7. 注意事项
97
201
 
98
- const app = window.APP;
99
- const show = ref(false);
100
- </script>
202
+ - 页面必须存在 `id="canvas"` 的 `<canvas>`,引擎会挂载到它上面。
203
+ - 需要跨域隔离(COOP/COEP)才能启用 SharedArrayBuffer,`gaeaVitePlugin` 已自动处理;首次进入若未隔离会自动刷新一次。
204
+ - 服务平台模式下地形/贴地线依赖 `serveUrl` 对应服务,若服务器无对应服务名,控制台会打印「未找到/加载失败」警告,不影响其它功能。
205
+ - 大体积引擎资源不随 npm 包分发,需手动放置,详见第 8 节。
101
206
 
102
- <template>
103
- <WeatherControl :appInstance="app" @close="show = false" />
104
- <FlyAlongRoute :appInstance="app" @close="show = false" />
105
- </template>
207
+ ---
208
+
209
+ ## 8. 大资源文件的放置
210
+
211
+ 引擎运行需要的大文件体积过大,**不包含在 npm 包内,也不会自动下载**(`postinstall` 仅做检测与提示)。请通过内网传输或手动拷贝的方式,将它们放到消费者项目里 gaea 包的 `public` 目录下。
212
+
213
+ ### 8.1 需要放置的文件
214
+
215
+ 放置目标目录:`node_modules/@yangyongtao/gaea/public/`
216
+
217
+ | 文件 / 目录 | 目标位置 | 参考大小 | 说明 |
218
+ |------|------|------|------|
219
+ | `Gaea.pck` | `public/Gaea.pck` | ~450 MB | 引擎主资源包 |
220
+ | `Gaea.wasm` | `public/Gaea.wasm` | ~16 MB | 引擎 WASM |
221
+ | `1111.res` | `public/static/1111.res` | **~34.6 MB** | 点图标/纹理资源包(务必用完整版,见下方警告) |
222
+ | `gltf/` | `public/static/gltf/` | 若干 | 断面/水闸等 GLTF 模型 |
223
+
224
+ > ⚠️ **重要**:`1111.res` 必须使用 **完整版(约 34.6 MB)**。早期存在一个残缺的 6.5MB 版本,会导致点图标纹理为空、加载台风路线时引擎崩溃(`SimpleFeatureRenderer.CombineSymbolMeshs` 空引用)。放置后可用文件大小快速校验。
225
+
226
+ ### 8.2 校验是否就位
227
+
228
+ ```powershell
229
+ # Windows PowerShell
230
+ Get-Item node_modules/@yangyongtao/gaea/public/Gaea.pck | Select-Object Length
231
+ Get-Item node_modules/@yangyongtao/gaea/public/static/1111.res | Select-Object Length
106
232
  ```
233
+ `Gaea.pck` 约 450MB、`1111.res` 约 34.6MB 即为正确。
234
+
235
+ ### 8.3 注意事项
107
236
 
108
- ### 其他导出
237
+ - 更换 `1111.res` 后,若浏览器曾加载过旧的残缺资源,引擎会把资源按名缓存进持久化虚拟文件系统,需**强制刷新(Ctrl+Shift+R)**一次;本库已用版本化资源名规避该缓存问题。
238
+ - 若不放置这些文件,`npm install` 后控制台会打印提示,且页面无法正常渲染三维场景。
239
+ - CI 等无需下载/提示的环境,可设置环境变量 `GAEA_SKIP_DOWNLOAD=1` 跳过 postinstall 提示。
109
240
 
110
- | 导出 | 路径 | 说明 |
111
- |------|------|------|
112
- | `GaeaApp`, `setConfig`, `getConfig` | `@yangyongtao/gaea` | 核心功能 |
113
- | `loadResource`, `screenToLatLng` | `@yangyongtao/gaea` | 工具函数 |
114
- | `WeatherControl`, `FlyAlongRoute` | `@yangyongtao/gaea/components` | Vue 组件 |
115
- | `gaeaVitePlugin`, `GaeaPlugin` | `@yangyongtao/gaea/plugin` | Vite 插件 / v-drag 指令 |
241
+ ---
116
242
 
117
243
  ## License
118
244
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangyongtao/gaea",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "Gaea 3D visualization component library - Vue 3 components based on Godot WASM engine. Includes WMTS layer loading, camera view control, Vite plugin auto-injection, etc.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -14,6 +14,7 @@
14
14
  "import": "./src/components/index.js",
15
15
  "default": "./src/components/index.js"
16
16
  },
17
+ "./components/*": "./src/components/*",
17
18
  "./plugin": {
18
19
  "import": "./src/plugin.js",
19
20
  "default": "./src/plugin.js"
@@ -70,7 +71,8 @@
70
71
  }
71
72
  },
72
73
  "dependencies": {
73
- "@tweenjs/tween.js": "^25.0.0"
74
+ "@tweenjs/tween.js": "^25.0.0",
75
+ "echarts": "^5.5.0"
74
76
  },
75
77
  "license": "MIT",
76
78
  "publishConfig": {
@@ -168,3 +168,114 @@ input {
168
168
  a {
169
169
  color: #fcdab7;
170
170
  }
171
+
172
+ /* daba-tooltip 断面标签 hover 提示框 */
173
+ .daba-tooltip {
174
+ position: fixed;
175
+ z-index: 99999;
176
+ transform: translate(-50%, -100%);
177
+ pointer-events: none;
178
+ display: none;
179
+ min-width: 200px;
180
+ max-width: 320px;
181
+ background: rgba(2, 62, 138, 0.95);
182
+ border: 1px solid rgba(14, 165, 233, 0.6);
183
+ border-radius: 6px;
184
+ padding: 14px 18px;
185
+ box-shadow: 0 4px 20px rgba(0, 50, 100, 0.4);
186
+ font-size: 18px;
187
+ animation: dabaTooltipFadeIn 0.15s ease-out;
188
+ }
189
+ .daba-tooltip::after {
190
+ content: '';
191
+ position: absolute;
192
+ bottom: -6px;
193
+ left: 50%;
194
+ transform: translateX(-50%);
195
+ width: 0;
196
+ height: 0;
197
+ border-left: 6px solid transparent;
198
+ border-right: 6px solid transparent;
199
+ border-top: 6px solid rgba(2, 62, 138, 0.95);
200
+ }
201
+ @keyframes dabaTooltipFadeIn {
202
+ from { opacity: 0; transform: translate(-50%, calc(-100% - 4px)); }
203
+ to { opacity: 1; transform: translate(-50%, -100%); }
204
+ }
205
+ .daba-tooltip-title {
206
+ font-size: 17px; font-weight: 600; color: #e0f7ff;
207
+ padding-bottom: 8px; margin-bottom: 10px;
208
+ border-bottom: 1px solid rgba(255, 255, 255, 0.15);
209
+ }
210
+ .daba-tooltip-item {
211
+ position: relative; padding: 3px 0 3px 14px;
212
+ font-size: 15px; line-height: 1.7; color: #cbd5e1; word-break: break-word;
213
+ }
214
+ .daba-tooltip-item::before {
215
+ content: ''; position: absolute; left: 0; top: 11px;
216
+ width: 5px; height: 5px; border-radius: 50%; background: #38bdf8;
217
+ }
218
+
219
+ /* 断面标签样式 */
220
+ .waterLevel {
221
+ position: absolute;
222
+ z-index: 1000;
223
+ width: 7rem;
224
+ top: 16%;
225
+ left: 30%;
226
+ }
227
+ .waterLevel img {
228
+ width: 100%;
229
+ }
230
+ .waterLevel .content {
231
+ position: absolute;
232
+ top: 16%;
233
+ left: 25%;
234
+ white-space: nowrap;
235
+ }
236
+ .waterLevel .content .text {
237
+ font-size: 20px;
238
+ }
239
+
240
+ .damScreen {
241
+ position: absolute;
242
+ box-sizing: border-box;
243
+ top: 431.312px;
244
+ left: 630.192px;
245
+ width: 18rem;
246
+ height: 3rem;
247
+ padding: 0px;
248
+ margin: 0px;
249
+ overflow: hidden;
250
+ display: block;
251
+ z-index: 3;
252
+ }
253
+ .damScreen img {
254
+ position: absolute;
255
+ width: 100%;
256
+ height: 100%;
257
+ object-fit: cover;
258
+ z-index: 1;
259
+ }
260
+ .damScreen .content {
261
+ display: flex;
262
+ position: relative;
263
+ width: 100%;
264
+ min-height: 100%;
265
+ z-index: 2;
266
+ align-items: center;
267
+ }
268
+ .damScreen .content .box {
269
+ width: 2.2rem;
270
+ height: 100%;
271
+ box-sizing: border-box;
272
+ }
273
+ .damScreen .content .text {
274
+ flex: 1 1 0%;
275
+ height: 100%;
276
+ display: flex;
277
+ font-size: 18px;
278
+ align-items: center;
279
+ justify-content: center;
280
+ box-sizing: border-box;
281
+ }
@@ -1,128 +1,39 @@
1
1
  /**
2
- * Post-install script: auto-download engine + asset files from GitHub Releases.
2
+ * Post-install script.
3
3
  *
4
- * To skip (e.g. in CI): set env GAEA_SKIP_DOWNLOAD=1
4
+ * 说明:引擎与大资源文件(Gaea.pck / Gaea.wasm / static/1111.res / static/gltf/ 等)
5
+ * 体积较大,不随 npm 包分发,也不再自动从 GitHub 下载。
6
+ * 请通过其它方式(内网传输 / 手动拷贝)将这些文件放置到消费者项目的 public/static 目录,
7
+ * 详见 README.md 第 8 节「大资源文件的放置」。
5
8
  *
6
- * GitHub Releases 需要上传的文件:
7
- * gaea-assets-v{version}.zip (包含 Gaea.pck, Gaea.wasm, static/gltf/, static/1111.res)
8
- *
9
- * Zip 内部结构:
10
- * Gaea.pck
11
- * Gaea.wasm
12
- * static/
13
- * gltf/ (所有 .gltf 文件)
14
- * 1111.res
9
+ * 如需强制跳过本脚本的任何提示:设置环境变量 GAEA_SKIP_DOWNLOAD=1
15
10
  */
16
11
 
17
12
  import fs from 'fs';
18
13
  import path from 'path';
19
14
  import { fileURLToPath } from 'url';
20
- import https from 'https';
21
15
 
22
16
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
17
  const PACKAGE_ROOT = path.resolve(__dirname, '..');
24
18
  const PUBLIC_DIR = path.join(PACKAGE_ROOT, 'public');
25
- const PKG = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf-8'));
26
- const VERSION = PKG.version;
27
-
28
- const ASSETS_VERSION = '1.1.1'; // 大文件资源版本,不随 npm 版本变动
29
- const ZIP_NAME = `gaea-assets-v${ASSETS_VERSION}.zip`;
30
- const GITHUB_RELEASES = `https://github.com/smallflypig/Gaea/releases/download/v${ASSETS_VERSION}`;
31
- const ZIP_URL = `${GITHUB_RELEASES}/${ZIP_NAME}`;
32
-
33
- // ── helpers ──────────────────────────────────────────────────────────
34
-
35
- function download(url, dest) {
36
- return new Promise((resolve, reject) => {
37
- const file = fs.createWriteStream(dest);
38
- https.get(url, (res) => {
39
- if (res.statusCode === 302 || res.statusCode === 301) {
40
- file.close();
41
- try { fs.unlinkSync(dest); } catch {}
42
- return download(res.headers.location, dest).then(resolve, reject);
43
- }
44
- if (res.statusCode !== 200) {
45
- file.close();
46
- try { fs.unlinkSync(dest); } catch {}
47
- reject(new Error(`HTTP ${res.statusCode}`));
48
- return;
49
- }
50
-
51
- const total = parseInt(res.headers['content-length'], 10) || 0;
52
- let downloaded = 0;
53
-
54
- res.on('data', (chunk) => {
55
- downloaded += chunk.length;
56
- if (total > 0 && downloaded % (50 * 1024) < chunk.length) {
57
- const pct = Math.round((downloaded / total) * 100);
58
- process.stdout.write(` ${pct}%\r`);
59
- }
60
- });
61
-
62
- res.pipe(file);
63
-
64
- file.on('finish', () => {
65
- file.close();
66
- process.stdout.write('\r');
67
- resolve();
68
- });
69
- }).on('error', (err) => {
70
- file.close();
71
- try { fs.unlinkSync(dest); } catch {}
72
- reject(err);
73
- });
74
- });
75
- }
76
-
77
- // ── main ─────────────────────────────────────────────────────────────
78
19
 
79
20
  if (process.env.GAEA_SKIP_DOWNLOAD === '1') {
80
- console.log('[gaea] GAEA_SKIP_DOWNLOAD=1, skipping.');
81
21
  process.exit(0);
82
22
  }
83
23
 
84
- // Quick check: do essential files already exist?
24
+ // 检测关键资源是否已就位(Gaea.pck 通常 >100MB)
85
25
  const MARKER = path.join(PUBLIC_DIR, 'Gaea.pck');
86
- if (fs.existsSync(MARKER) && fs.statSync(MARKER).size > 100 * 1024 * 1024) {
87
- console.log('[gaea] Assets already exist, skip download.');
88
- process.exit(0);
26
+ const ready = fs.existsSync(MARKER) && fs.statSync(MARKER).size > 100 * 1024 * 1024;
27
+
28
+ if (ready) {
29
+ console.log('[gaea] 引擎资源已就位。');
30
+ } else {
31
+ console.log(
32
+ '\n[gaea] 未检测到引擎大资源文件(Gaea.pck / Gaea.wasm / static/1111.res / static/gltf 等)。\n' +
33
+ '[gaea] 这些文件不随 npm 包分发,请通过内网/手动方式放置到项目静态资源目录后再运行。\n' +
34
+ '[gaea] 放置方法详见 README.md 第 8 节。\n'
35
+ );
89
36
  }
90
37
 
91
- console.log(`[gaea] Downloading assets from GitHub Releases v${VERSION}...`);
92
- console.log(`[gaea] ${ZIP_URL}`);
93
-
94
- const tmpZip = path.join(PUBLIC_DIR, ZIP_NAME);
95
-
96
- (async () => {
97
- try {
98
- // 1. Download zip
99
- await download(ZIP_URL, tmpZip);
100
-
101
- // 2. Extract
102
- console.log('[gaea] Extracting...');
103
- const { execSync } = await import('child_process');
104
-
105
- try {
106
- execSync(`powershell -Command "Expand-Archive -Path '${tmpZip}' -DestinationPath '${PUBLIC_DIR}' -Force"`, {
107
- stdio: 'pipe',
108
- });
109
- } catch {
110
- // Fallback: try unzip
111
- execSync(`unzip -o "${tmpZip}" -d "${PUBLIC_DIR}"`, { stdio: 'pipe' });
112
- }
113
-
114
- // 3. Cleanup
115
- fs.unlinkSync(tmpZip);
38
+ process.exit(0);
116
39
 
117
- console.log('[gaea] Assets installed successfully.');
118
- } catch (e) {
119
- console.error(`\n[gaea] Download failed: ${e.message}`);
120
- console.error(
121
- `[gaea] Please download manually: ${ZIP_URL}\n` +
122
- ` Extract to: ${PUBLIC_DIR}\n` +
123
- ` Or set GAEA_SKIP_DOWNLOAD=1 to skip.`
124
- );
125
- try { fs.unlinkSync(tmpZip); } catch {}
126
- process.exit(0);
127
- }
128
- })();