@yangyongtao/gaea 1.1.5 → 1.1.7

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/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## [1.1.6] - 2026-07-01
4
+
5
+ ### Changed
6
+ - 优化引入方式:`loadResource`、`screenToLatLng` 工具函数可直接从 `@yangyongtao/gaea` 导入
7
+ - 移除冗余的 `@yangyongtao/gaea/methods` 导出路径
8
+
9
+ ## [1.1.5] - 2026-07-01
10
+
11
+ ### Added
12
+ - 添加 `npm run pub` 快捷发布命令
13
+
14
+ ### Changed
15
+ - 更新 GitHub 仓库地址为 smallflypig/Gaea
16
+ - 优化 postinstall 脚本,大文件资源版本锁定 1.1.1
17
+
18
+ ## [1.1.0] - 2026-06-30
19
+
20
+ ### Changed
21
+ - 大文件 (Gaea.pck, Gaea.wasm, gltf, 1111.res) 从 npm 包中分离,改为 postinstall 自动下载
22
+ - npm 包体积从 310MB 降至 19.5MB
23
+
24
+ ### Added
25
+ - 添加 postinstall 自动下载脚本
26
+ - 添加 .npmignore 排除大文件
package/README.md CHANGED
@@ -8,7 +8,7 @@ Gaea 3D 可视化组件库 — 基于 Godot WASM 引擎的 Vue 3 组件包。
8
8
  npm install @yangyongtao/gaea
9
9
  ```
10
10
 
11
- ## 项目配置
11
+ ## 快速开始
12
12
 
13
13
  ### 1. `vite.config.js`
14
14
 
@@ -19,140 +19,107 @@ import { gaeaVitePlugin } from '@yangyongtao/gaea/plugin';
19
19
 
20
20
  export default defineConfig({
21
21
  plugins: [vue(), gaeaVitePlugin()],
22
- resolve: {
23
- preserveSymlinks: true,
24
- },
25
- optimizeDeps: {
26
- exclude: ['@yangyongtao/gaea'],
27
- },
22
+ resolve: { preserveSymlinks: true },
23
+ optimizeDeps: { exclude: ['@yangyongtao/gaea'] },
28
24
  });
29
25
  ```
30
26
 
31
- `gaeaVitePlugin()` 会自动完成:
32
- - 在 HTML 中注入 `<script src="/Gaea.js">`
33
- - 提供 `/Gaea.js` `/Gaea.wasm` `/Gaea.pck` 等所有 public/ 静态文件
34
- - 设置 COEP/COOP 响应头
35
- - 检测浏览器跨域隔离状态
36
-
37
- ### 2. `src/App.vue` — 完整初始化示例
27
+ ### 2. `src/App.vue`
38
28
 
39
29
  ```vue
40
30
  <template>
41
- <canvas id="canvas" style="width:100vw;height:100vh"></canvas>
31
+ <div id="gaea-app">
32
+ <div class="toolbar">
33
+ <button @click="showWeather = !showWeather">天气控制</button>
34
+ <button @click="showFly = !showFly">沿线飞行</button>
35
+ </div>
36
+
37
+ <div class="canvas-area">
38
+ <canvas id="canvas"></canvas>
39
+ </div>
40
+
41
+ <WeatherControl v-if="showWeather" :appInstance="app" @close="showWeather = false" />
42
+ <FlyAlongRoute v-if="showFly" :appInstance="app" @close="showFly = false" />
43
+ </div>
42
44
  </template>
43
45
 
44
46
  <script setup>
45
- import { onMounted } from 'vue';
47
+ import { ref } from 'vue';
46
48
  import { GaeaApp, setConfig } from '@yangyongtao/gaea';
49
+ import { WeatherControl, FlyAlongRoute } from '@yangyongtao/gaea/components';
50
+
51
+ // 配置
52
+ setConfig({
53
+ serveLocal: `${window.location.origin}/static/`,
54
+ serveUrl: 'http://192.168.3.151:8088/gaeaExplorerServer/',
55
+ defaultLayers: [
56
+ { layerName: 'earthland', forMat: 'image/png', min: 0, max: 18, transparency: 0.3 },
57
+ { layerName: '苍南L19', forMat: 'image/png', min: 5, max: 17 },
58
+ ],
59
+ defaultCameraPosition: '27.3680928977018,120.414139621887,0,109379.690132486,0,0',
60
+ });
47
61
 
62
+ // 初始化(自动完成:引擎启动 → 环境初始化 → 图层加载)
48
63
  const app = new GaeaApp();
49
64
  window.APP = app;
50
65
 
51
- onMounted(async () => {
52
- setConfig({
53
- serveLocal: `${window.location.origin}/static/`,
54
- serveUrl: 'http://192.168.3.151:8088/gaeaExplorerServer/',
55
- });
56
-
57
- new window.Engine({
58
- args: [],
59
- canvasResizePolicy: 2,
60
- executable: '/Gaea',
61
- experimentalVK: false,
62
- fileSizes: {
63
- 'Gaea.pck': 450751936,
64
- 'Gaea.wasm': 16580215,
65
- },
66
- focusCanvas: true,
67
- gdnativeLibs: [],
68
- }).startGame({
69
- onProgress: (current, total) => console.log(`加载: ${current}/${total}`),
70
- });
71
-
72
- await app.initDefaultEnvironment();
73
-
74
- app.getAllServe().then(() => {
75
- app.addLayer({ layerName: 'earthland', forMat: 'image/png', min: 0, max: 18, transparency: 0.3 });
76
- app.addLayer({ layerName: '苍南L19', forMat: 'image/png', min: 5, max: 17 });
77
- });
78
- });
66
+ const showWeather = ref(false);
67
+ const showFly = ref(false);
79
68
  </script>
80
69
  ```
81
70
 
82
- > **注意**:`fileSizes` 需与 npm 包 `public/Gaea.pck` 和 `public/Gaea.wasm` 实际文件大小一致。
83
-
84
71
  ## API
85
72
 
86
- ### 配置
73
+ ### 配置项
87
74
 
88
75
  ```js
89
76
  import { setConfig } from '@yangyongtao/gaea';
90
77
 
91
78
  setConfig({
92
- serveUrl: 'http://192.168.3.151:8088/gaeaExplorerServer/',
93
- serveLocal: 'http://localhost:8080/static/',
79
+ serveUrl: '', // WMTS 服务地址
80
+ serveLocal: '', // 静态资源地址
81
+ defaultLayers: [], // 默认影像图层
82
+ defaultCameraPosition: 'lat,lng,alt,dist,pitch,heading',
83
+ onProgress: (cur, total) => {}, // 引擎加载进度回调
94
84
  });
95
85
  ```
96
86
 
97
- ### 环境初始化
98
-
99
- ```js
100
- await app.initDefaultEnvironment();
101
- ```
102
-
103
- ### 影像图层
104
-
105
- ```js
106
- await app.getAllServe();
87
+ ### GaeaApp 方法
107
88
 
108
- app.addLayer({
109
- layerName: 'earthland',
110
- forMat: 'image/png',
111
- min: 0, max: 18,
112
- transparency: 0.3,
113
- });
114
- ```
115
-
116
- ### 相机控制
117
-
118
- ```js
119
- app.SetPosition('27.3809, 120.4499, 0, 3000, 0, 0');
120
- const uri = app.favorite();
121
- app.favoritePosition(uri);
122
- ```
89
+ | 方法 | 说明 |
90
+ |------|------|
91
+ | `new GaeaApp(options)` | 创建实例,自动初始化引擎/环境/图层 |
92
+ | `app.getAllServe()` | 获取 WMTS 服务图层列表 |
93
+ | `app.addLayer({ layerName, forMat, min, max, transparency })` | 添加影像图层 |
94
+ | `app.SetPosition('lat,lng,alt,dist,pitch,heading')` | 定位到指定视角 |
95
+ | `app.favorite()` | 记录当前视角,返回 URI 字符串 |
96
+ | `app.favoritePosition(uri)` | 恢复已保存的视角 |
97
+ | `app.ready` | Promise,等待初始化完成 |
123
98
 
124
99
  ### Vue 组件
125
100
 
126
101
  ```vue
127
102
  <script setup>
128
103
  import { WeatherControl, FlyAlongRoute } from '@yangyongtao/gaea/components';
104
+
105
+ const app = window.APP;
106
+ const show = ref(false);
129
107
  </script>
130
108
 
131
109
  <template>
132
- <WeatherControl :appInstance="app" @close="close" />
133
- <FlyAlongRoute :appInstance="app" @close="close" />
110
+ <WeatherControl :appInstance="app" @close="show = false" />
111
+ <FlyAlongRoute :appInstance="app" @close="show = false" />
134
112
  </template>
135
113
  ```
136
114
 
137
115
  ### 其他导出
138
116
 
139
- | 导出 | 路径 |
140
- |------|------|
141
- | `gaeaVitePlugin` | `@yangyongtao/gaea/plugin` |
142
- | `GaeaPlugin` (v-drag 指令) | `@yangyongtao/gaea/plugin` |
143
- | `loadResource`, `screenToLatLng` | `@yangyongtao/gaea` |
144
-
145
- ## 静态资源
146
-
147
- npm 包 `public/` 中的文件由 `gaeaVitePlugin` 自动提供服务。
148
-
149
- ```
150
- public/
151
- ├── Gaea.js / Gaea.wasm / Gaea.pck # Godot 引擎核心
152
- ├── index.js # Godot 类绑定
153
- ├── math/ # 数学工具
154
- └── static/ # 点标注、底图、模型等资源
155
- ```
117
+ | 导出 | 路径 | 说明 |
118
+ |------|------|------|
119
+ | `GaeaApp`, `setConfig`, `getConfig` | `@yangyongtao/gaea` | 核心功能 |
120
+ | `loadResource`, `screenToLatLng` | `@yangyongtao/gaea` | 工具函数 |
121
+ | `WeatherControl`, `FlyAlongRoute` | `@yangyongtao/gaea/components` | Vue 组件 |
122
+ | `gaeaVitePlugin`, `GaeaPlugin` | `@yangyongtao/gaea/plugin` | Vite 插件 / v-drag 指令 |
156
123
 
157
124
  ## License
158
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangyongtao/gaea",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
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,10 +14,6 @@
14
14
  "import": "./src/components/index.js",
15
15
  "default": "./src/components/index.js"
16
16
  },
17
- "./methods": {
18
- "import": "./src/GaeaMethods.js",
19
- "default": "./src/GaeaMethods.js"
20
- },
21
17
  "./plugin": {
22
18
  "import": "./src/plugin.js",
23
19
  "default": "./src/plugin.js"
@@ -27,6 +23,7 @@
27
23
  "src/",
28
24
  "scripts/",
29
25
  "README.md",
26
+ "CHANGELOG.md",
30
27
  "public/*.js",
31
28
  "public/*.html",
32
29
  "public/*.png",
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * gaea-3dview npm package
3
3
  *
4
- * 初始化流程:
5
- * 1. HTML 加载 <script src="/Gaea.js"> → window.Engine 可用
6
- * 2. import Gaea from '../public/index.js' → window.InstanceMap / NativeCall 等全局变量
7
- * 3. new window.Engine({...}).startGame({...}) → Godot WASM 启动
8
- * 4. app.initDefaultEnvironment() → 环境初始化
4
+ * 初始化在 new GaeaApp() 时自动完成,Vue 页面只需配置。
5
+ *
6
+ * 用法:
7
+ * setConfig({ serveUrl: '...', serveLocal: '...' });
8
+ * const app = new GaeaApp();
9
+ * await app.ready; // 可选,等待初始化完成
9
10
  */
10
11
 
11
12
  import Gaea from '../public/index.js';
@@ -13,7 +14,26 @@ import Gaea from '../public/index.js';
13
14
 
14
15
  // ==================== 配置 ====================
15
16
 
16
- const defaultConfig = { serveUrl: '', serveLocal: '' };
17
+ const defaultConfig = {
18
+ serveUrl: '',
19
+ serveLocal: '',
20
+ // Engine 配置
21
+ executable: '/Gaea',
22
+ fileSizes: { 'Gaea.pck': 450751936, 'Gaea.wasm': 16580215 },
23
+ canvasResizePolicy: 2,
24
+ experimentalVK: false,
25
+ focusCanvas: true,
26
+ /** 默认加载的影像图层 */
27
+ defaultLayers: [
28
+ { layerName: 'earthland', forMat: 'image/png', min: 0, max: 18, transparency: 0.3 },
29
+ { layerName: '苍南L19', forMat: 'image/png', min: 5, max: 17 },
30
+ ],
31
+ /** 默认相机视角 */
32
+ defaultCameraPosition: '27.3680928977018,120.414139621887,0,109379.690132486,0,0',
33
+ /** 引擎加载进度回调 */
34
+ onProgress: null,
35
+ };
36
+
17
37
  const _config = { ...defaultConfig };
18
38
 
19
39
  export function setConfig(cfg) { Object.assign(_config, cfg); }
@@ -27,12 +47,80 @@ export class GaeaApp {
27
47
  this._options = options;
28
48
  this.layers = [];
29
49
  this.tLayers = [];
50
+ window.Gaea = Gaea;
51
+
52
+ // 自动启动初始化,catch 防止未处理的 Promise rejection
53
+ this.ready = this._autoInit().catch(err => {
54
+ console.error('[GaeaApp] 初始化失败:', err);
55
+ });
30
56
  }
31
57
 
32
58
  get config() { return { ..._config, ...this._options }; }
33
59
 
34
- async initDefaultEnvironment() {
35
- window.Gaea = Gaea;
60
+ // ---- 内部初始化 ----
61
+
62
+ async _autoInit() {
63
+ console.log('[GaeaApp] 开始初始化...');
64
+
65
+ // 1. 等 canvas 就绪
66
+ await this._waitForCanvas();
67
+ console.log('[GaeaApp] canvas 就绪');
68
+
69
+ // 2. 启动 Godot 引擎
70
+ await this._startEngine();
71
+ console.log('[GaeaApp] 引擎启动完成');
72
+
73
+ // 3. 初始化环境
74
+ await this._initEnvironment();
75
+ console.log('[GaeaApp] 环境初始化完成');
76
+
77
+ // 4. 加载默认图层
78
+ await this._initLayers();
79
+ console.log('[GaeaApp] 初始化完成');
80
+ }
81
+
82
+ _waitForCanvas() {
83
+ return new Promise((resolve, reject) => {
84
+ const start = Date.now();
85
+ const check = () => {
86
+ const el = document.getElementById('canvas');
87
+ if (el && el.width > 0) {
88
+ resolve();
89
+ } else if (Date.now() - start > 10000) {
90
+ reject(new Error('等待 canvas 超时'));
91
+ } else {
92
+ requestAnimationFrame(check);
93
+ }
94
+ };
95
+ check();
96
+ });
97
+ }
98
+
99
+ async _startEngine() {
100
+ if (!window.Engine) {
101
+ throw new Error('window.Engine 不存在,请确保 <script src="/Gaea.js"> 已加载');
102
+ }
103
+ if (!window.Engine.isWebGLAvailable()) {
104
+ throw new Error('WebGL 不可用');
105
+ }
106
+
107
+ const cfg = this.config;
108
+ const engine = new window.Engine({
109
+ args: [],
110
+ canvasResizePolicy: cfg.canvasResizePolicy,
111
+ executable: cfg.executable,
112
+ experimentalVK: cfg.experimentalVK,
113
+ fileSizes: cfg.fileSizes,
114
+ focusCanvas: cfg.focusCanvas,
115
+ gdnativeLibs: [],
116
+ });
117
+
118
+ await engine.startGame({
119
+ onProgress: cfg.onProgress || ((cur, total) => console.log(`引擎加载: ${cur}/${total}`)),
120
+ });
121
+ }
122
+
123
+ async _initEnvironment() {
36
124
  Gaea.World.Instance.Is3DTilesNeedCache = false;
37
125
  Gaea.World.Instance.IsPyramidTileSetNeedCache = false;
38
126
 
@@ -53,6 +141,41 @@ export class GaeaApp {
53
141
  Gaea.World.Instance.CloudVisalbe = false;
54
142
  }
55
143
 
144
+ async _initLayers() {
145
+ const cfg = this.config;
146
+ await this.getAllServe();
147
+
148
+ const pos = cfg.defaultCameraPosition;
149
+ if (pos) this.SetPosition(pos);
150
+
151
+ const list = cfg.defaultLayers;
152
+ if (list?.length) {
153
+ for (const layer of list) {
154
+ this.addLayer(layer);
155
+ }
156
+ }
157
+ }
158
+
159
+ // ---- 公开方法 ----
160
+
161
+ /** 初始化默认图层和相机视角(手动调用,可传参覆盖配置) */
162
+ async initDefaultLayers({ layers, cameraPosition } = {}) {
163
+ const cfg = this.config;
164
+ await this.getAllServe();
165
+ console.log('WMTS 图层数量:', this.layers.length);
166
+ this.layers.slice(0, 10).forEach(l => console.log(' -', l.Title));
167
+
168
+ const pos = cameraPosition ?? cfg.defaultCameraPosition;
169
+ if (pos) this.SetPosition(pos);
170
+
171
+ const list = layers ?? cfg.defaultLayers;
172
+ if (list?.length) {
173
+ for (const layer of list) {
174
+ this.addLayer(layer);
175
+ }
176
+ }
177
+ }
178
+
56
179
  async getAllServe() {
57
180
  const cfg = this.config;
58
181
  const url = `${cfg.serveUrl}htc/service/wmts?REQUEST=GetCapabilities`;
package/src/index.js CHANGED
@@ -1,7 +1,12 @@
1
1
  /**
2
2
  * gaea-3dview 主入口
3
+ *
4
+ * 用法:
5
+ * import { GaeaApp, setConfig } from '@yangyongtao/gaea';
6
+ * import { loadResource, screenToLatLng } from '@yangyongtao/gaea';
7
+ * import { WeatherControl, FlyAlongRoute } from '@yangyongtao/gaea/components';
8
+ * import GaeaPlugin, { gaeaVitePlugin } from '@yangyongtao/gaea/plugin';
3
9
  */
4
10
 
5
- export { setConfig, getConfig } from './GaeaMethods.js';
6
- export { GaeaApp } from './GaeaMethods.js';
7
- export { default } from './GaeaMethods.js';
11
+ export { GaeaApp, setConfig, getConfig } from './GaeaMethods.js';
12
+ export { loadResource, screenToLatLng } from './utils.js';