@yangyongtao/gaea 1.1.4 → 1.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangyongtao/gaea",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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",
@@ -45,6 +42,7 @@
45
42
  ],
46
43
  "scripts": {
47
44
  "postinstall": "node scripts/postinstall.mjs",
45
+ "pub": "npm publish --access public",
48
46
  "test": "echo \"No tests yet\""
49
47
  },
50
48
  "keywords": [
@@ -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';