@yangyongtao/gaea 1.0.0 → 1.0.2
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/package.json +1 -1
- package/src/GaeaMethods.js +57 -2
package/package.json
CHANGED
package/src/GaeaMethods.js
CHANGED
|
@@ -48,6 +48,42 @@ function rgbToGaeaColor(rgb) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
|
|
51
|
+
// ==================== Gaea 检查 ====================
|
|
52
|
+
|
|
53
|
+
function checkGaea() {
|
|
54
|
+
const G = window.Gaea;
|
|
55
|
+
if (!G || !G.World || !G.World.Instance) {
|
|
56
|
+
console.warn('Gaea 尚未加载完毕,请先调用 await GaeaApp.waitForReady()');
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return G;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 等待 Gaea 引擎初始化完毕(轮询 World.Instance)
|
|
64
|
+
* @param {number} timeout - 超时毫秒数,默认 30000
|
|
65
|
+
* @returns {Promise<boolean>}
|
|
66
|
+
*/
|
|
67
|
+
async function waitForGaea(timeout = 30000) {
|
|
68
|
+
if (window.Gaea && window.Gaea.World && window.Gaea.World.Instance) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const start = Date.now();
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
const timer = setInterval(() => {
|
|
74
|
+
if (window.Gaea && window.Gaea.World && window.Gaea.World.Instance) {
|
|
75
|
+
clearInterval(timer);
|
|
76
|
+
resolve(true);
|
|
77
|
+
} else if (Date.now() - start > timeout) {
|
|
78
|
+
clearInterval(timer);
|
|
79
|
+
console.error('Gaea 初始化超时');
|
|
80
|
+
resolve(false);
|
|
81
|
+
}
|
|
82
|
+
}, 200);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
51
87
|
// ==================== GaeaApp 类 ====================
|
|
52
88
|
|
|
53
89
|
import { Tween, Group, Easing } from '@tweenjs/tween.js';
|
|
@@ -81,6 +117,15 @@ export class GaeaApp {
|
|
|
81
117
|
this._tweenGroup = new Group();
|
|
82
118
|
}
|
|
83
119
|
|
|
120
|
+
/**
|
|
121
|
+
* 静态方法:等待 Gaea 引擎就绪
|
|
122
|
+
* @example await GaeaApp.waitForReady(); // 30s 超时
|
|
123
|
+
* @example await GaeaApp.waitForReady(60000); // 自定义超时
|
|
124
|
+
*/
|
|
125
|
+
static waitForReady(timeout) {
|
|
126
|
+
return waitForGaea(timeout);
|
|
127
|
+
}
|
|
128
|
+
|
|
84
129
|
// ==================== 点标注 ====================
|
|
85
130
|
|
|
86
131
|
/**
|
|
@@ -94,7 +139,8 @@ export class GaeaApp {
|
|
|
94
139
|
return null;
|
|
95
140
|
}
|
|
96
141
|
|
|
97
|
-
const Gaea =
|
|
142
|
+
const Gaea = checkGaea();
|
|
143
|
+
if (!Gaea) return null;
|
|
98
144
|
const resName = 'pointIcon.res';
|
|
99
145
|
|
|
100
146
|
if (!this._pointIconLoaded) {
|
|
@@ -156,7 +202,8 @@ export class GaeaApp {
|
|
|
156
202
|
* @param {Object} opts - { height, step, duration, xrotation, lockEye, minZoom, maxZoom }
|
|
157
203
|
*/
|
|
158
204
|
async flyAlongPath(lineData, opts = {}) {
|
|
159
|
-
const Gaea =
|
|
205
|
+
const Gaea = checkGaea();
|
|
206
|
+
if (!Gaea) return Promise.reject(new Error('Gaea 未加载'));
|
|
160
207
|
const {
|
|
161
208
|
height = 150, step = 1000, duration = 20,
|
|
162
209
|
xrotation = -30, lockEye = true, minZoom = 0, maxZoom = 400
|
|
@@ -264,6 +311,10 @@ export class GaeaApp {
|
|
|
264
311
|
_initWeather() {
|
|
265
312
|
if (this._weatherInited) return;
|
|
266
313
|
const Gaea = window.Gaea;
|
|
314
|
+
if (!Gaea || !Gaea.World || !Gaea.World.Instance) {
|
|
315
|
+
console.warn('Gaea 尚未加载完毕,无法初始化天气');
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
267
318
|
this._fullScreenQuad = Gaea.World.Instance.FullScreenQuad;
|
|
268
319
|
this._sky = Gaea.MeshInstance.ConvertBy(Gaea.World.Instance.GetNode('Sky'));
|
|
269
320
|
this._sun = Gaea.Sun.ConvertBy(Gaea.World.Instance.GetNode('Sun'));
|
|
@@ -335,6 +386,10 @@ export class GaeaApp {
|
|
|
335
386
|
/** 初始化基础环境(关闭默认雾、设置默认光照等) */
|
|
336
387
|
initDefaultEnvironment() {
|
|
337
388
|
const Gaea = window.Gaea;
|
|
389
|
+
if (!Gaea || !Gaea.World || !Gaea.World.Instance) {
|
|
390
|
+
console.warn('Gaea 尚未加载完毕,请确保在 Gaea 初始化之后调用此方法');
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
338
393
|
|
|
339
394
|
// 关闭默认雾
|
|
340
395
|
const fogEnv = Gaea.Environment.ConvertBy(
|