@skewedaspect/sage 0.9.1 → 0.9.3
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/dist/classes/debugConsole.d.ts +22 -0
- package/dist/classes/entity.d.ts +21 -0
- package/dist/classes/gameEngine.d.ts +12 -1
- package/dist/classes/gameLevel.d.ts +8 -1
- package/dist/debug/builtins.d.ts +6 -0
- package/dist/interfaces/entity.d.ts +3 -0
- package/dist/interfaces/game.d.ts +9 -0
- package/dist/interfaces/level.d.ts +5 -0
- package/dist/managers/colliderDebug.d.ts +16 -0
- package/dist/sage.d.ts +5 -1
- package/dist/sage.es.js +509 -228
- package/dist/sage.es.js.map +1 -1
- package/dist/sage.umd.js +1 -1
- package/dist/sage.umd.js.map +1 -1
- package/dist/utils/entityProxy.d.ts +2 -0
- package/dist/utils/vectors.d.ts +18 -1
- package/package.json +1 -1
package/dist/sage.es.js
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
|
-
import { AbstractMesh as e, ActionManager as t, ArcRotateCamera as n, Color3 as r, Color4 as i, CreateAudioEngineAsync as a, CubeTexture as o, DefaultRenderingPipeline as s, DirectionalLight as c, Engine as l, ExecuteCodeAction as u, FreeCamera as d, HDRCubeTexture as f, HavokPlugin as p, HemisphericLight as m, ImageProcessingConfiguration as h, ImportMeshAsync as g, LoadAssetContainerAsync as _,
|
|
2
|
-
import { registerBuiltInLoaders as
|
|
3
|
-
import { GeospatialCamera as
|
|
4
|
-
import { ClusteredLightContainer as
|
|
5
|
-
import pe from "@babylonjs/
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { AbstractMesh as e, ActionManager as t, ArcRotateCamera as n, Color3 as r, Color4 as i, CreateAudioEngineAsync as a, CubeTexture as o, DefaultRenderingPipeline as s, DirectionalLight as c, Engine as l, ExecuteCodeAction as u, FreeCamera as d, HDRCubeTexture as f, HavokPlugin as p, HemisphericLight as m, ImageProcessingConfiguration as h, ImportMeshAsync as g, LoadAssetContainerAsync as _, Matrix as v, Mesh as y, MeshBuilder as b, NullEngine as x, PBRMaterial as S, PhysicsAggregate as C, PhysicsShapeType as w, PointLight as ee, Quaternion as T, RectAreaLight as te, SSAO2RenderingPipeline as ne, Scene as re, SelectionOutlineLayer as ie, SoundState as ae, SpotLight as oe, StandardMaterial as E, Texture as se, TransformNode as D, UniversalCamera as ce, Vector3 as O, WebGPUEngine as le } from "@babylonjs/core";
|
|
2
|
+
import { registerBuiltInLoaders as ue } from "@babylonjs/loaders/dynamic";
|
|
3
|
+
import { GeospatialCamera as de } from "@babylonjs/core/Cameras/geospatialCamera";
|
|
4
|
+
import { ClusteredLightContainer as fe } from "@babylonjs/core/Lights/Clustered/clusteredLightContainer";
|
|
5
|
+
import { PhysicsViewer as pe } from "@babylonjs/core/Debug/physicsViewer";
|
|
6
|
+
import me from "@babylonjs/havok";
|
|
7
|
+
//#region src/classes/debugConsole.ts
|
|
8
|
+
var he = class {
|
|
9
|
+
_namespaceName;
|
|
10
|
+
_entries = /* @__PURE__ */ new Map();
|
|
11
|
+
_disposed = !1;
|
|
12
|
+
constructor(e = "sage") {
|
|
13
|
+
this._namespaceName = e, this._installNamespace();
|
|
14
|
+
}
|
|
15
|
+
expose(e, t) {
|
|
16
|
+
this._disposed || (this._isDynamicGetter(t) ? (this._entries.set(e, { getter: t.get }), this._defineGetter(e, t.get)) : (this._entries.set(e, { value: t }), this._defineValue(e, t)));
|
|
17
|
+
}
|
|
18
|
+
setNamespace(e) {
|
|
19
|
+
if (!(this._disposed || e === this._namespaceName)) {
|
|
20
|
+
this._removeNamespace(), this._namespaceName = e, this._installNamespace();
|
|
21
|
+
for (let [e, t] of this._entries) t.getter ? this._defineGetter(e, t.getter) : this._defineValue(e, t.value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
get namespaceName() {
|
|
25
|
+
return this._namespaceName;
|
|
26
|
+
}
|
|
27
|
+
dispose() {
|
|
28
|
+
this._disposed ||= (this._removeNamespace(), this._entries.clear(), !0);
|
|
29
|
+
}
|
|
30
|
+
async $teardown() {
|
|
31
|
+
this.dispose();
|
|
32
|
+
}
|
|
33
|
+
_isDynamicGetter(e) {
|
|
34
|
+
return typeof e == "object" && !!e && "get" in e && typeof e.get == "function";
|
|
35
|
+
}
|
|
36
|
+
_getNamespace() {
|
|
37
|
+
return Reflect.get(window, this._namespaceName);
|
|
38
|
+
}
|
|
39
|
+
_installNamespace() {
|
|
40
|
+
typeof window > "u" || Reflect.set(window, this._namespaceName, {});
|
|
41
|
+
}
|
|
42
|
+
_removeNamespace() {
|
|
43
|
+
typeof window > "u" || Reflect.deleteProperty(window, this._namespaceName);
|
|
44
|
+
}
|
|
45
|
+
_defineGetter(e, t) {
|
|
46
|
+
let n = this._getNamespace();
|
|
47
|
+
n && Object.defineProperty(n, e, {
|
|
48
|
+
get: t,
|
|
49
|
+
enumerable: !0,
|
|
50
|
+
configurable: !0
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
_defineValue(e, t) {
|
|
54
|
+
let n = this._getNamespace();
|
|
55
|
+
n && Object.defineProperty(n, e, {
|
|
56
|
+
value: t,
|
|
57
|
+
writable: !0,
|
|
58
|
+
enumerable: !0,
|
|
59
|
+
configurable: !0
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, k = "0.9.3", A = class {
|
|
8
63
|
canvas;
|
|
9
64
|
renderEngine;
|
|
10
65
|
physics;
|
|
@@ -14,14 +69,19 @@ var O = "0.9.1", k = class {
|
|
|
14
69
|
logger;
|
|
15
70
|
raycast;
|
|
16
71
|
timer;
|
|
72
|
+
debug;
|
|
17
73
|
largeWorldRendering;
|
|
18
74
|
started = !1;
|
|
19
75
|
_log;
|
|
20
76
|
_beforeStartHook = null;
|
|
21
77
|
_onStartHook = null;
|
|
22
78
|
_onTeardownHook = null;
|
|
23
|
-
constructor(e, t, n, r, i, a, o, s, c, l = !1) {
|
|
24
|
-
this.canvas = e, this.renderEngine = t, this.physics = n, this.eventBus = r, this.logger = i, this.raycast = a, this.timer = o, this.engines = s, this.managers = c, this.
|
|
79
|
+
constructor(e, t, n, r, i, a, o, s, c, l = !1, u) {
|
|
80
|
+
this.canvas = e, this.renderEngine = t, this.physics = n, this.eventBus = r, this.logger = i, this.raycast = a, this.timer = o, this.engines = s, this.managers = c, this.debug = u ?? {
|
|
81
|
+
colliders: void 0,
|
|
82
|
+
console: null,
|
|
83
|
+
expose: () => {}
|
|
84
|
+
}, this.largeWorldRendering = l, this._log = i.getLogger("GameEngine");
|
|
25
85
|
}
|
|
26
86
|
onBeforeStart(e) {
|
|
27
87
|
if (this._beforeStartHook !== null) throw Error("A beforeStart hook is already registered. Only one hook is allowed per lifecycle event.");
|
|
@@ -42,17 +102,18 @@ var O = "0.9.1", k = class {
|
|
|
42
102
|
return this.eventBus.subscribe(`action:${e}`, t);
|
|
43
103
|
}
|
|
44
104
|
async start() {
|
|
45
|
-
this.started ? this._log.warn("Game engine is already started. Skipping start.") : (this._log.info(`Starting SkewedAspect Game Engine (Version: ${
|
|
105
|
+
this.started ? this._log.warn("Game engine is already started. Skipping start.") : (this._log.info(`Starting SkewedAspect Game Engine (Version: ${k})...`), this._beforeStartHook && (this._log.debug("Executing beforeStart hook..."), await this._beforeStartHook(this)), await this.managers.gameManager.start(), this._log.info("Game engine started successfully"), this._onStartHook && (this._log.debug("Executing onStart hook..."), await this._onStartHook(this)), this.started = !0);
|
|
46
106
|
}
|
|
47
107
|
async stop() {
|
|
48
108
|
if (this.started) {
|
|
49
|
-
this._log.info(`Stopping SkewedAspect Game Engine (Version: ${
|
|
109
|
+
this._log.info(`Stopping SkewedAspect Game Engine (Version: ${k})...`);
|
|
50
110
|
let e = null;
|
|
51
111
|
if (this._onTeardownHook) try {
|
|
52
112
|
this._log.debug("Executing onTeardown hook..."), await this._onTeardownHook(this);
|
|
53
113
|
} catch (t) {
|
|
54
114
|
this._log.error(`Error in onTeardown hook: ${t}`), e ||= t;
|
|
55
115
|
}
|
|
116
|
+
this.debug.console && this.debug.console.dispose();
|
|
56
117
|
for (let t of Object.keys(this.managers)) {
|
|
57
118
|
let n = this.managers[t];
|
|
58
119
|
if (n) try {
|
|
@@ -72,7 +133,7 @@ var O = "0.9.1", k = class {
|
|
|
72
133
|
if (this.started = !1, this._log.info("Game engine stopped successfully"), e) throw e;
|
|
73
134
|
} else this._log.warn("Game engine is not started. Skipping stop.");
|
|
74
135
|
}
|
|
75
|
-
},
|
|
136
|
+
}, j = class {
|
|
76
137
|
timers;
|
|
77
138
|
constructor() {
|
|
78
139
|
this.timers = /* @__PURE__ */ new Map();
|
|
@@ -131,7 +192,7 @@ var O = "0.9.1", k = class {
|
|
|
131
192
|
console.info(`${a} Timer '${t}' completed in ${i.toFixed(2)}ms`, o, s, c);
|
|
132
193
|
} else console.warn(`[${e}]: Timer '${t}' does not exist`);
|
|
133
194
|
}
|
|
134
|
-
},
|
|
195
|
+
}, M = class {
|
|
135
196
|
trace(e, t, ...n) {}
|
|
136
197
|
debug(e, t, ...n) {}
|
|
137
198
|
info(e, t, ...n) {}
|
|
@@ -139,11 +200,11 @@ var O = "0.9.1", k = class {
|
|
|
139
200
|
error(e, t, ...n) {}
|
|
140
201
|
time(e, t) {}
|
|
141
202
|
timeEnd(e, t) {}
|
|
142
|
-
},
|
|
203
|
+
}, N = class {
|
|
143
204
|
category;
|
|
144
205
|
backend;
|
|
145
206
|
minLevel;
|
|
146
|
-
constructor(e, t = "none", n = new
|
|
207
|
+
constructor(e, t = "none", n = new M()) {
|
|
147
208
|
this.category = e, this.backend = n, this.minLevel = t;
|
|
148
209
|
}
|
|
149
210
|
updateSettings(e, t) {
|
|
@@ -181,21 +242,21 @@ var O = "0.9.1", k = class {
|
|
|
181
242
|
default: return !1;
|
|
182
243
|
}
|
|
183
244
|
}
|
|
184
|
-
},
|
|
245
|
+
}, P = class {
|
|
185
246
|
backend;
|
|
186
247
|
level;
|
|
187
248
|
loggers;
|
|
188
|
-
constructor(e = "debug", t = new
|
|
249
|
+
constructor(e = "debug", t = new j()) {
|
|
189
250
|
this.backend = t, this.level = e, this.loggers = /* @__PURE__ */ new Map();
|
|
190
251
|
}
|
|
191
252
|
setBackend(e) {
|
|
192
253
|
this.backend = e, this.loggers.forEach((e) => {
|
|
193
|
-
e instanceof
|
|
254
|
+
e instanceof N && e.updateSettings(this.backend, this.level);
|
|
194
255
|
});
|
|
195
256
|
}
|
|
196
257
|
setLevel(e) {
|
|
197
258
|
this.level = e, this.loggers.forEach((e) => {
|
|
198
|
-
e instanceof
|
|
259
|
+
e instanceof N && e.updateSettings(this.backend, this.level);
|
|
199
260
|
});
|
|
200
261
|
}
|
|
201
262
|
getLevel() {
|
|
@@ -203,14 +264,14 @@ var O = "0.9.1", k = class {
|
|
|
203
264
|
}
|
|
204
265
|
getLogger(e) {
|
|
205
266
|
let t = this.loggers.get(e);
|
|
206
|
-
return t || (t = new
|
|
267
|
+
return t || (t = new N(e, this.level, this.backend), this.loggers.set(e, t)), t;
|
|
207
268
|
}
|
|
208
|
-
},
|
|
269
|
+
}, F = class {
|
|
209
270
|
directMap = /* @__PURE__ */ new Map();
|
|
210
271
|
patternSubs = /* @__PURE__ */ new Set();
|
|
211
272
|
_log;
|
|
212
273
|
constructor(e) {
|
|
213
|
-
this._log = e?.getLogger("EventBus") || new
|
|
274
|
+
this._log = e?.getLogger("EventBus") || new N("EventBus");
|
|
214
275
|
}
|
|
215
276
|
subscribe(e, t) {
|
|
216
277
|
return this._log.trace(`Subscribe request for: ${e.toString()}`), e instanceof RegExp || typeof e == "string" && e.includes("*") ? this.subscribePattern(e, t) : this.subscribeExact(e, t);
|
|
@@ -255,7 +316,7 @@ var O = "0.9.1", k = class {
|
|
|
255
316
|
async $teardown() {
|
|
256
317
|
this._log.debug("Tearing down EventBus"), this.directMap.clear(), this.patternSubs.clear();
|
|
257
318
|
}
|
|
258
|
-
},
|
|
319
|
+
}, I = class {
|
|
259
320
|
_engine = null;
|
|
260
321
|
_mainBus = null;
|
|
261
322
|
_buses = /* @__PURE__ */ new Map();
|
|
@@ -299,8 +360,8 @@ var O = "0.9.1", k = class {
|
|
|
299
360
|
};
|
|
300
361
|
//#endregion
|
|
301
362
|
//#region src/engines/scene.ts
|
|
302
|
-
|
|
303
|
-
var
|
|
363
|
+
ue();
|
|
364
|
+
var L = class {
|
|
304
365
|
_canvas;
|
|
305
366
|
_engine;
|
|
306
367
|
_havok;
|
|
@@ -311,14 +372,14 @@ var I = class {
|
|
|
311
372
|
createScene() {
|
|
312
373
|
return new re(this._engine);
|
|
313
374
|
}
|
|
314
|
-
enablePhysics(e, t = new
|
|
375
|
+
enablePhysics(e, t = new O(0, -9.8, 0), n) {
|
|
315
376
|
this._log.debug(`Enabling physics with gravity (${t.x}, ${t.y}, ${t.z})...`);
|
|
316
377
|
let r = n === void 0 ? void 0 : { floatingOriginWorldRadius: n }, i = new p(!0, this._havok, r);
|
|
317
378
|
e.enablePhysics(t, i);
|
|
318
379
|
}
|
|
319
380
|
createFreeCamera(e, t, n, r) {
|
|
320
381
|
let i = new d(e, t, n);
|
|
321
|
-
return i.setTarget(
|
|
382
|
+
return i.setTarget(O.Zero()), r ??= this._canvas, r && i.attachControl(r, !0), i;
|
|
322
383
|
}
|
|
323
384
|
createHemisphericLight(e, t, n, r = .7) {
|
|
324
385
|
let i = new m(e, t, n);
|
|
@@ -329,7 +390,7 @@ var I = class {
|
|
|
329
390
|
return i.intensity = r, i;
|
|
330
391
|
}
|
|
331
392
|
createPointLight(e, t, n, r = 1) {
|
|
332
|
-
let i = new
|
|
393
|
+
let i = new ee(e, t, n);
|
|
333
394
|
return i.intensity = r, i;
|
|
334
395
|
}
|
|
335
396
|
createSpotLight(e, t, n, r, i, a, o = 1) {
|
|
@@ -337,24 +398,24 @@ var I = class {
|
|
|
337
398
|
return s.intensity = o, s;
|
|
338
399
|
}
|
|
339
400
|
createRectAreaLight(e, t, n, r, i, a = 1) {
|
|
340
|
-
let o = new
|
|
401
|
+
let o = new te(e, t, n, r, i);
|
|
341
402
|
return o.intensity = a, o;
|
|
342
403
|
}
|
|
343
404
|
createSphere(e, t = {}, n) {
|
|
344
|
-
return
|
|
405
|
+
return b.CreateSphere(e, {
|
|
345
406
|
diameter: 1,
|
|
346
407
|
segments: 32,
|
|
347
408
|
...t
|
|
348
409
|
}, n);
|
|
349
410
|
}
|
|
350
411
|
createBox(e, t = {}, n) {
|
|
351
|
-
return
|
|
412
|
+
return b.CreateBox(e, {
|
|
352
413
|
size: 1,
|
|
353
414
|
...t
|
|
354
415
|
}, n);
|
|
355
416
|
}
|
|
356
417
|
createGround(e, t = {}, n) {
|
|
357
|
-
return
|
|
418
|
+
return b.CreateGround(e, {
|
|
358
419
|
width: 6,
|
|
359
420
|
height: 6,
|
|
360
421
|
subdivisions: 2,
|
|
@@ -362,7 +423,7 @@ var I = class {
|
|
|
362
423
|
}, n);
|
|
363
424
|
}
|
|
364
425
|
createCylinder(e, t = {}, n) {
|
|
365
|
-
return
|
|
426
|
+
return b.CreateCylinder(e, {
|
|
366
427
|
height: 2,
|
|
367
428
|
diameterTop: 1,
|
|
368
429
|
diameterBottom: 1,
|
|
@@ -370,7 +431,7 @@ var I = class {
|
|
|
370
431
|
}, n);
|
|
371
432
|
}
|
|
372
433
|
addPhysics(e, t, n = {}, r) {
|
|
373
|
-
return new
|
|
434
|
+
return new C(e, t, {
|
|
374
435
|
mass: 1,
|
|
375
436
|
restitution: .75,
|
|
376
437
|
friction: .5,
|
|
@@ -398,14 +459,14 @@ var I = class {
|
|
|
398
459
|
async $teardown() {
|
|
399
460
|
this._log.info("Tearing down SceneEngine"), this._log.info("SceneEngine torn down successfully");
|
|
400
461
|
}
|
|
401
|
-
},
|
|
462
|
+
}, R = class {
|
|
402
463
|
_eventBus;
|
|
403
464
|
_sceneEngine;
|
|
404
465
|
_log;
|
|
405
466
|
_containers = /* @__PURE__ */ new Map();
|
|
406
467
|
_sourceMeshes = /* @__PURE__ */ new Map();
|
|
407
468
|
constructor(e, t, n) {
|
|
408
|
-
this._eventBus = e, this._sceneEngine = t, this._log = n?.getLogger("AssetManager") ?? new
|
|
469
|
+
this._eventBus = e, this._sceneEngine = t, this._log = n?.getLogger("AssetManager") ?? new N("AssetManager");
|
|
409
470
|
}
|
|
410
471
|
_parsePath(e) {
|
|
411
472
|
let t = e.indexOf("#");
|
|
@@ -491,16 +552,16 @@ var I = class {
|
|
|
491
552
|
async $teardown() {
|
|
492
553
|
this.disposeAll();
|
|
493
554
|
}
|
|
494
|
-
},
|
|
555
|
+
}, z = [
|
|
495
556
|
"trigger",
|
|
496
557
|
"toggle",
|
|
497
558
|
"value"
|
|
498
|
-
],
|
|
559
|
+
], ge = [
|
|
499
560
|
"keyboard",
|
|
500
561
|
"mouse",
|
|
501
562
|
"gamepad"
|
|
502
563
|
];
|
|
503
|
-
function
|
|
564
|
+
function _e(e) {
|
|
504
565
|
return e.type === "keyboard";
|
|
505
566
|
}
|
|
506
567
|
function B(e) {
|
|
@@ -511,7 +572,7 @@ function V(e) {
|
|
|
511
572
|
}
|
|
512
573
|
//#endregion
|
|
513
574
|
//#region src/classes/bindings/trigger.ts
|
|
514
|
-
var
|
|
575
|
+
var ve = class {
|
|
515
576
|
type = "trigger";
|
|
516
577
|
action;
|
|
517
578
|
context;
|
|
@@ -582,7 +643,7 @@ var he = class {
|
|
|
582
643
|
options: this.options
|
|
583
644
|
};
|
|
584
645
|
}
|
|
585
|
-
},
|
|
646
|
+
}, ye = class {
|
|
586
647
|
type = "toggle";
|
|
587
648
|
action;
|
|
588
649
|
context;
|
|
@@ -656,7 +717,7 @@ var he = class {
|
|
|
656
717
|
options: this.options
|
|
657
718
|
};
|
|
658
719
|
}
|
|
659
|
-
},
|
|
720
|
+
}, be = class {
|
|
660
721
|
type = "value";
|
|
661
722
|
action;
|
|
662
723
|
context;
|
|
@@ -719,7 +780,7 @@ var he = class {
|
|
|
719
780
|
options: this.options
|
|
720
781
|
};
|
|
721
782
|
}
|
|
722
|
-
},
|
|
783
|
+
}, xe = class e {
|
|
723
784
|
sourceType = "key";
|
|
724
785
|
sourceKey;
|
|
725
786
|
useDelta;
|
|
@@ -742,7 +803,7 @@ var he = class {
|
|
|
742
803
|
options: { useDelta: this.useDelta }
|
|
743
804
|
};
|
|
744
805
|
}
|
|
745
|
-
},
|
|
806
|
+
}, Se = class e {
|
|
746
807
|
sourceType;
|
|
747
808
|
sourceKey;
|
|
748
809
|
constructor(e, t) {
|
|
@@ -777,7 +838,7 @@ var he = class {
|
|
|
777
838
|
sourceKey: this.sourceKey
|
|
778
839
|
};
|
|
779
840
|
}
|
|
780
|
-
},
|
|
841
|
+
}, Ce = class e {
|
|
781
842
|
sourceType;
|
|
782
843
|
sourceKey;
|
|
783
844
|
useAnalogValue;
|
|
@@ -816,7 +877,7 @@ var he = class {
|
|
|
816
877
|
}
|
|
817
878
|
};
|
|
818
879
|
}
|
|
819
|
-
},
|
|
880
|
+
}, we = .05, Te = .5, Ee = class {
|
|
820
881
|
_bindings = /* @__PURE__ */ new Map();
|
|
821
882
|
_actions = /* @__PURE__ */ new Map();
|
|
822
883
|
_contexts = /* @__PURE__ */ new Map();
|
|
@@ -831,7 +892,7 @@ var he = class {
|
|
|
831
892
|
this._eventBus = e, this._inputUnsubscribe = this._eventBus.subscribe("input:changed", (e) => {
|
|
832
893
|
let t = e.payload;
|
|
833
894
|
t && this.$handleInput(t.device, t.state);
|
|
834
|
-
}), this._log = t?.getLogger("BindingManager") || new
|
|
895
|
+
}), this._log = t?.getLogger("BindingManager") || new N("BindingManager"), this._log.debug("BindingManager initialized");
|
|
835
896
|
}
|
|
836
897
|
_isBindingContextActive(e) {
|
|
837
898
|
return e.context ? this._activeContexts.has(e.context) : !0;
|
|
@@ -849,22 +910,22 @@ var he = class {
|
|
|
849
910
|
return t;
|
|
850
911
|
}
|
|
851
912
|
_shouldUpdateActiveDevice(e) {
|
|
852
|
-
return B(e) ? Object.values(e.buttons).some((e) => e.pressed) || e.wheel !== void 0 : V(e) ? Object.values(e.buttons).some((e) => e.pressed) || Object.values(e.axes).some((e) => Math.abs(e) >
|
|
913
|
+
return B(e) ? Object.values(e.buttons).some((e) => e.pressed) || e.wheel !== void 0 : V(e) ? Object.values(e.buttons).some((e) => e.pressed) || Object.values(e.axes).some((e) => Math.abs(e) > we) : !0;
|
|
853
914
|
}
|
|
854
915
|
_createBindingFromDefinition(e) {
|
|
855
916
|
let t = this._actions.get(e.action);
|
|
856
917
|
if (!t) return this._log.warn(`Cannot create binding: Action "${e.action}" not found.`), null;
|
|
857
918
|
let { deviceID: n, ...r } = e.input;
|
|
858
919
|
switch (e.type) {
|
|
859
|
-
case "trigger": return new
|
|
920
|
+
case "trigger": return new ve(t, n, e.input.type, this._createInputSourceFromDefinition(r), {
|
|
860
921
|
...e.options || {},
|
|
861
922
|
context: e.context
|
|
862
923
|
});
|
|
863
|
-
case "toggle": return new
|
|
924
|
+
case "toggle": return new ye(t, n, e.input.type, this._createInputSourceFromDefinition(r), {
|
|
864
925
|
...e.options || {},
|
|
865
926
|
context: e.context
|
|
866
927
|
});
|
|
867
|
-
case "value": return new
|
|
928
|
+
case "value": return new be(t, n, e.input.type, this._createInputSourceFromDefinition(r), {
|
|
868
929
|
...e.options || {},
|
|
869
930
|
context: e.context
|
|
870
931
|
});
|
|
@@ -873,16 +934,16 @@ var he = class {
|
|
|
873
934
|
}
|
|
874
935
|
_createInputSourceFromDefinition(e) {
|
|
875
936
|
switch (e.type) {
|
|
876
|
-
case "keyboard": return new
|
|
937
|
+
case "keyboard": return new xe(e.sourceKey, e.options);
|
|
877
938
|
case "mouse": {
|
|
878
939
|
let t = e.sourceType;
|
|
879
940
|
if (!(t === "button" || t === "position" || t === "wheel")) throw Error(`Invalid mouse source type: ${t}`);
|
|
880
|
-
return new
|
|
941
|
+
return new Se(t, e.sourceKey);
|
|
881
942
|
}
|
|
882
943
|
case "gamepad": {
|
|
883
944
|
let t = e.sourceType;
|
|
884
945
|
if (!(t === "button" || t === "axis")) throw Error(`Invalid gamepad source type: ${t}`);
|
|
885
|
-
return new
|
|
946
|
+
return new Ce(t, e.sourceKey, e.options);
|
|
886
947
|
}
|
|
887
948
|
default: throw Error(`Unsupported input source type: ${e.type}`);
|
|
888
949
|
}
|
|
@@ -893,7 +954,7 @@ var he = class {
|
|
|
893
954
|
let { options: r } = n;
|
|
894
955
|
if (!r.deviceTypes.includes(e.type)) return;
|
|
895
956
|
let i = null;
|
|
896
|
-
if (
|
|
957
|
+
if (_e(t)) {
|
|
897
958
|
if (t.event?.repeat === !0) return;
|
|
898
959
|
for (let n of Object.keys(t.delta)) if (t.delta[n] === !0) {
|
|
899
960
|
i = {
|
|
@@ -925,7 +986,7 @@ var he = class {
|
|
|
925
986
|
break;
|
|
926
987
|
}
|
|
927
988
|
if (!i) {
|
|
928
|
-
for (let n of Object.keys(t.axes)) if (Math.abs(t.axes[n]) >
|
|
989
|
+
for (let n of Object.keys(t.axes)) if (Math.abs(t.axes[n]) > Te) {
|
|
929
990
|
i = {
|
|
930
991
|
type: "gamepad",
|
|
931
992
|
sourceType: "axis",
|
|
@@ -1040,7 +1101,7 @@ var he = class {
|
|
|
1040
1101
|
return this._contexts.get(e) || null;
|
|
1041
1102
|
}
|
|
1042
1103
|
$registerBinding(e) {
|
|
1043
|
-
if (!
|
|
1104
|
+
if (!z.includes(e.type)) throw Error(`Invalid binding type: ${e.type}`);
|
|
1044
1105
|
e.context && !this._contexts.has(e.context) && this.registerContext(e.context), this._bindings.has(e.deviceID) || this._bindings.set(e.deviceID, []), this._bindings.get(e.deviceID)?.push(e), this._log.debug(`Registered ${e.type} binding for "${e.action.name}" in context "${e.context || null}"`);
|
|
1045
1106
|
}
|
|
1046
1107
|
registerBinding(e) {
|
|
@@ -1113,12 +1174,12 @@ var he = class {
|
|
|
1113
1174
|
function H() {
|
|
1114
1175
|
return typeof window < "u" && window.document !== void 0;
|
|
1115
1176
|
}
|
|
1116
|
-
function
|
|
1177
|
+
function De() {
|
|
1117
1178
|
return H() && !!window.navigator.gpu;
|
|
1118
1179
|
}
|
|
1119
1180
|
//#endregion
|
|
1120
1181
|
//#region node_modules/hexoid/dist/index.mjs
|
|
1121
|
-
for (var
|
|
1182
|
+
for (var Oe = class {
|
|
1122
1183
|
_engine;
|
|
1123
1184
|
_eventBus;
|
|
1124
1185
|
_entityManager;
|
|
@@ -1132,7 +1193,7 @@ for (var we = class {
|
|
|
1132
1193
|
_paused = !1;
|
|
1133
1194
|
started = !1;
|
|
1134
1195
|
constructor(e, t, n, r, i, a) {
|
|
1135
|
-
this._engine = e, this._eventBus = t, this._entityManager = n, this._inputManager = r, this._levelManager = i, this._log = a?.getLogger("GameManager") || new
|
|
1196
|
+
this._engine = e, this._eventBus = t, this._entityManager = n, this._inputManager = r, this._levelManager = i, this._log = a?.getLogger("GameManager") || new N("GameManager"), this._boundRenderLoop = this._renderLoop.bind(this), this._boundResizeHandler = this._resizeHandler.bind(this), H() && window.addEventListener("resize", this._boundResizeHandler);
|
|
1136
1197
|
}
|
|
1137
1198
|
get currentScene() {
|
|
1138
1199
|
return this._levelManager.currentLevel?.scene ?? null;
|
|
@@ -1194,21 +1255,21 @@ for (var we = class {
|
|
|
1194
1255
|
async $teardown() {
|
|
1195
1256
|
this._log.info("Tearing down GameManager"), this.started && await this.stop(), H() && window.removeEventListener("resize", this._boundResizeHandler), this._frameCallbacks = [], this._log.info("GameManager torn down successfully");
|
|
1196
1257
|
}
|
|
1197
|
-
},
|
|
1198
|
-
function
|
|
1258
|
+
}, U = 256, W = []; U--;) W[U] = (U + 256).toString(16).substring(1);
|
|
1259
|
+
function ke(e) {
|
|
1199
1260
|
e ||= 16;
|
|
1200
1261
|
var t = "", n = 0;
|
|
1201
1262
|
return function() {
|
|
1202
1263
|
if (!t || n === 256) {
|
|
1203
|
-
for (t = "", n = (1 + e) / 2 | 0; n--;) t +=
|
|
1264
|
+
for (t = "", n = (1 + e) / 2 | 0; n--;) t += W[256 * Math.random() | 0];
|
|
1204
1265
|
t = t.substring(n = 0, e - 2);
|
|
1205
1266
|
}
|
|
1206
|
-
return t +
|
|
1267
|
+
return t + W[n++];
|
|
1207
1268
|
};
|
|
1208
1269
|
}
|
|
1209
1270
|
//#endregion
|
|
1210
1271
|
//#region src/utils/id.ts
|
|
1211
|
-
var
|
|
1272
|
+
var Ae = ke(16), G = class {
|
|
1212
1273
|
entity = null;
|
|
1213
1274
|
$emit(e) {
|
|
1214
1275
|
if (!this.entity) throw Error("Entity is not set for this behavior.");
|
|
@@ -1229,7 +1290,7 @@ var Ee = Te(16), K = class {
|
|
|
1229
1290
|
$setEntity(e) {
|
|
1230
1291
|
this.entity = e;
|
|
1231
1292
|
}
|
|
1232
|
-
},
|
|
1293
|
+
}, je = class {
|
|
1233
1294
|
id;
|
|
1234
1295
|
type;
|
|
1235
1296
|
name;
|
|
@@ -1244,7 +1305,7 @@ var Ee = Te(16), K = class {
|
|
|
1244
1305
|
_tags = /* @__PURE__ */ new Set();
|
|
1245
1306
|
subscriptions = /* @__PURE__ */ new Map();
|
|
1246
1307
|
constructor(e, t, n, r, i) {
|
|
1247
|
-
this.id =
|
|
1308
|
+
this.id = Ae(), this.type = e, this.name = i, this.state = n, this.eventBus = t;
|
|
1248
1309
|
for (let e of r) this.attachBehavior(new e());
|
|
1249
1310
|
}
|
|
1250
1311
|
get tags() {
|
|
@@ -1287,6 +1348,51 @@ var Ee = Te(16), K = class {
|
|
|
1287
1348
|
let t = this._gameEngine?.managers?.levelManager?.currentLevel?.outlines;
|
|
1288
1349
|
t && (e ? t.unhighlightEntity(e, this) : t.unhighlightEntityAll(this));
|
|
1289
1350
|
}
|
|
1351
|
+
showCollider(e, t) {
|
|
1352
|
+
if (!this.node || !this._gameEngine) return;
|
|
1353
|
+
let n = this._gameEngine.debug?.colliders;
|
|
1354
|
+
if (!n) return;
|
|
1355
|
+
let r = this._getPhysicsNodes();
|
|
1356
|
+
if (e === void 0 || e === !0) {
|
|
1357
|
+
for (let e of r) n.showColliderForNode(e, void 0);
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
if (typeof e == "string") {
|
|
1361
|
+
if (e.startsWith("#")) {
|
|
1362
|
+
for (let t of r) n.showColliderForNode(t, e);
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
let i = r.find((t) => t.name === e);
|
|
1366
|
+
i && n.showColliderForNode(i, t);
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
if (typeof e == "object") {
|
|
1370
|
+
let t = e;
|
|
1371
|
+
for (let e of r) {
|
|
1372
|
+
let r = t[e.name];
|
|
1373
|
+
r && n.showColliderForNode(e, r);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
hideCollider(e) {
|
|
1378
|
+
if (!this.node || !this._gameEngine) return;
|
|
1379
|
+
let t = this._gameEngine.debug?.colliders;
|
|
1380
|
+
if (!t) return;
|
|
1381
|
+
let n = this._getPhysicsNodes();
|
|
1382
|
+
if (e === void 0) {
|
|
1383
|
+
for (let e of n) t.hideColliderForNode(e);
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
let r = n.find((t) => t.name === e);
|
|
1387
|
+
r && t.hideColliderForNode(r);
|
|
1388
|
+
}
|
|
1389
|
+
_getPhysicsNodes() {
|
|
1390
|
+
if (!this.node) return [];
|
|
1391
|
+
let e = [];
|
|
1392
|
+
this.node.physicsBody && e.push(this.node);
|
|
1393
|
+
for (let t of this.node.getChildTransformNodes(!1)) t.physicsBody && e.push(t);
|
|
1394
|
+
return e;
|
|
1395
|
+
}
|
|
1290
1396
|
$addChild(e) {
|
|
1291
1397
|
this.children.push(e), e.parent = this, this.node && e.node && (e.node.parent = this.node);
|
|
1292
1398
|
}
|
|
@@ -1413,7 +1519,7 @@ var Ee = Te(16), K = class {
|
|
|
1413
1519
|
}
|
|
1414
1520
|
return this.behaviors.splice(t, 1), n.$setEntity(null), !0;
|
|
1415
1521
|
}
|
|
1416
|
-
},
|
|
1522
|
+
}, Me = class {
|
|
1417
1523
|
eventBus;
|
|
1418
1524
|
entities = /* @__PURE__ */ new Map();
|
|
1419
1525
|
entityDefinitions = /* @__PURE__ */ new Map();
|
|
@@ -1426,7 +1532,7 @@ var Ee = Te(16), K = class {
|
|
|
1426
1532
|
_entitiesByNode = /* @__PURE__ */ new Map();
|
|
1427
1533
|
_pools = /* @__PURE__ */ new Map();
|
|
1428
1534
|
constructor(e, t, n) {
|
|
1429
|
-
this.eventBus = e, this.bindingManager = n, this._log = t?.getLogger("EntityManager") || new
|
|
1535
|
+
this.eventBus = e, this.bindingManager = n, this._log = t?.getLogger("EntityManager") || new N("EntityManager"), this._log.info("EntityManager initialized");
|
|
1430
1536
|
}
|
|
1431
1537
|
$setGameEngine(e) {
|
|
1432
1538
|
this._gameEngine = e;
|
|
@@ -1537,7 +1643,7 @@ var Ee = Te(16), K = class {
|
|
|
1537
1643
|
let t = await n.onBeforeCreate(r);
|
|
1538
1644
|
t !== void 0 && (r = t);
|
|
1539
1645
|
}
|
|
1540
|
-
let i = t.name ?? n.name, a = new
|
|
1646
|
+
let i = t.name ?? n.name, a = new je(n.type, this.eventBus, r, n.behaviors, i);
|
|
1541
1647
|
if (a.$setEntityManager(this), t.node && a.$attachToNode(t.node, this._engine), n.tags) for (let e of n.tags) a.$addTag(e);
|
|
1542
1648
|
if (t.tags) for (let e of t.tags) a.$addTag(e);
|
|
1543
1649
|
if (this.entities.set(a.id, a), this._indexEntity(a), this._log.debug(`Entity created with ID: ${a.id}${i ? ` (name: ${i})` : ""}`), n.onCreate) {
|
|
@@ -1707,18 +1813,18 @@ var Ee = Te(16), K = class {
|
|
|
1707
1813
|
}
|
|
1708
1814
|
this.entityDefinitions.clear(), this._entitiesByName.clear(), this._entitiesByType.clear(), this._entitiesByTag.clear(), this._entitiesByNode.clear(), this._log.info("EntityManager torn down successfully");
|
|
1709
1815
|
}
|
|
1710
|
-
},
|
|
1816
|
+
}, Ne = {
|
|
1711
1817
|
hable: h.TONEMAPPING_STANDARD,
|
|
1712
1818
|
reinhard: h.TONEMAPPING_STANDARD,
|
|
1713
1819
|
hejidawson: h.TONEMAPPING_STANDARD,
|
|
1714
1820
|
photographic: h.TONEMAPPING_STANDARD,
|
|
1715
1821
|
aces: h.TONEMAPPING_ACES
|
|
1716
1822
|
};
|
|
1717
|
-
function
|
|
1823
|
+
function Pe(e, t) {
|
|
1718
1824
|
if (!e.activeCamera) return;
|
|
1719
1825
|
t.volumetric && console.warn("[SAGE] Volumetric lighting requires renderer: \"frameGraph\". Ignored in pipeline mode.");
|
|
1720
1826
|
let n = new s("sage-default", !0, e, e.cameras);
|
|
1721
|
-
if (t.bloom && (n.bloomEnabled = !0, t.bloom.weight !== void 0 && (n.bloomWeight = t.bloom.weight), t.bloom.threshold !== void 0 && (n.bloomThreshold = t.bloom.threshold), t.bloom.scale !== void 0 && (n.bloomScale = t.bloom.scale), t.bloom.kernel !== void 0 && (n.bloomKernel = t.bloom.kernel)), t.tonemap && (n.imageProcessingEnabled = !0, n.imageProcessing.toneMappingEnabled = !0, t.tonemap.operator && (n.imageProcessing.toneMappingType =
|
|
1827
|
+
if (t.bloom && (n.bloomEnabled = !0, t.bloom.weight !== void 0 && (n.bloomWeight = t.bloom.weight), t.bloom.threshold !== void 0 && (n.bloomThreshold = t.bloom.threshold), t.bloom.scale !== void 0 && (n.bloomScale = t.bloom.scale), t.bloom.kernel !== void 0 && (n.bloomKernel = t.bloom.kernel)), t.tonemap && (n.imageProcessingEnabled = !0, n.imageProcessing.toneMappingEnabled = !0, t.tonemap.operator && (n.imageProcessing.toneMappingType = Ne[t.tonemap.operator] ?? h.TONEMAPPING_STANDARD)), t.grain && (n.grainEnabled = !0, t.grain.intensity !== void 0 && (n.grain.intensity = t.grain.intensity), t.grain.animated !== void 0 && (n.grain.animated = t.grain.animated)), t.vignette && (n.imageProcessingEnabled = !0, n.imageProcessing.vignetteEnabled = !0, t.vignette.weight !== void 0 && (n.imageProcessing.vignetteWeight = t.vignette.weight), t.vignette.stretch !== void 0 && (n.imageProcessing.vignetteStretch = t.vignette.stretch), t.vignette.color && (n.imageProcessing.vignetteColor = new i(t.vignette.color.r, t.vignette.color.g, t.vignette.color.b, 1))), t.sharpen && (n.sharpenEnabled = !0, t.sharpen.edge !== void 0 && (n.sharpen.edgeAmount = t.sharpen.edge), t.sharpen.color !== void 0 && (n.sharpen.colorAmount = t.sharpen.color)), t.chromaticAberration && (n.chromaticAberrationEnabled = !0, t.chromaticAberration.amount !== void 0 && (n.chromaticAberration.aberrationAmount = t.chromaticAberration.amount)), t.ssao) {
|
|
1722
1828
|
let n = new ne("sage-ssao", e, {
|
|
1723
1829
|
ssaoRatio: .5,
|
|
1724
1830
|
blurRatio: 1
|
|
@@ -1728,25 +1834,25 @@ function Ae(e, t) {
|
|
|
1728
1834
|
}
|
|
1729
1835
|
//#endregion
|
|
1730
1836
|
//#region src/handlers/postProcessing.ts
|
|
1731
|
-
async function
|
|
1837
|
+
async function Fe(e, t) {
|
|
1732
1838
|
if (t.renderer === "frameGraph") {
|
|
1733
1839
|
let { applyFrameGraphPostProcessing: n } = await import("./postProcessingFrameGraph-CaMgQzR-.js");
|
|
1734
1840
|
await n(e, t);
|
|
1735
|
-
} else
|
|
1841
|
+
} else Pe(e, t);
|
|
1736
1842
|
}
|
|
1737
1843
|
//#endregion
|
|
1738
1844
|
//#region src/utils/vectors.ts
|
|
1739
|
-
function
|
|
1845
|
+
function K(e) {
|
|
1740
1846
|
return {
|
|
1741
1847
|
x: e.x,
|
|
1742
1848
|
y: e.y,
|
|
1743
1849
|
z: e.z
|
|
1744
1850
|
};
|
|
1745
1851
|
}
|
|
1746
|
-
function
|
|
1747
|
-
return new
|
|
1852
|
+
function q(e) {
|
|
1853
|
+
return new O(e.x, e.y, e.z);
|
|
1748
1854
|
}
|
|
1749
|
-
function
|
|
1855
|
+
function Ie(e) {
|
|
1750
1856
|
return {
|
|
1751
1857
|
x: e.x,
|
|
1752
1858
|
y: e.y,
|
|
@@ -1754,12 +1860,27 @@ function Me(e) {
|
|
|
1754
1860
|
w: e.w
|
|
1755
1861
|
};
|
|
1756
1862
|
}
|
|
1757
|
-
function
|
|
1758
|
-
return new
|
|
1863
|
+
function Le(e) {
|
|
1864
|
+
return new T(e.x, e.y, e.z, e.w);
|
|
1865
|
+
}
|
|
1866
|
+
function Re(e) {
|
|
1867
|
+
e.computeWorldMatrix(!0);
|
|
1868
|
+
let t = e.getWorldMatrix().clone(), n = e.parent;
|
|
1869
|
+
for (; n;) {
|
|
1870
|
+
n.computeWorldMatrix(!0);
|
|
1871
|
+
let e = n.getWorldMatrix(), r = n.parent, i;
|
|
1872
|
+
r ? (r.computeWorldMatrix(!0), i = e.multiply(v.Invert(r.getWorldMatrix()))) : i = e, i.determinant() < 0 && (t = v.Invert(i).multiply(t)), n = r;
|
|
1873
|
+
}
|
|
1874
|
+
let r = new O(), i = new T(), a = new O();
|
|
1875
|
+
return t.decompose(a, i, r), {
|
|
1876
|
+
position: r,
|
|
1877
|
+
rotation: i,
|
|
1878
|
+
scaling: a
|
|
1879
|
+
};
|
|
1759
1880
|
}
|
|
1760
1881
|
//#endregion
|
|
1761
1882
|
//#region src/classes/level.ts
|
|
1762
|
-
var
|
|
1883
|
+
var ze = class {
|
|
1763
1884
|
name;
|
|
1764
1885
|
_log;
|
|
1765
1886
|
_context;
|
|
@@ -1767,7 +1888,7 @@ var Pe = class {
|
|
|
1767
1888
|
clusteredLights = null;
|
|
1768
1889
|
outlines = null;
|
|
1769
1890
|
constructor(e, t) {
|
|
1770
|
-
this.name = e.name, this._context = t, this._log = t.logger?.getLogger(`Level:${e.name}`) ?? new
|
|
1891
|
+
this.name = e.name, this._context = t, this._log = t.logger?.getLogger(`Level:${e.name}`) ?? new N(`Level:${e.name}`, "info");
|
|
1771
1892
|
}
|
|
1772
1893
|
get scene() {
|
|
1773
1894
|
return this._scene;
|
|
@@ -1822,7 +1943,7 @@ var Pe = class {
|
|
|
1822
1943
|
this.outlines &&= (this.outlines.dispose(), null), this.clusteredLights &&= (this.clusteredLights.dispose(), null), this._scene.dispose(), this._scene = null;
|
|
1823
1944
|
}
|
|
1824
1945
|
}
|
|
1825
|
-
},
|
|
1946
|
+
}, Be = class {
|
|
1826
1947
|
_scene;
|
|
1827
1948
|
_layers = /* @__PURE__ */ new Map();
|
|
1828
1949
|
constructor(e, t) {
|
|
@@ -1866,7 +1987,7 @@ var Pe = class {
|
|
|
1866
1987
|
n.length > 0 && e.layer.addSelection(n);
|
|
1867
1988
|
}
|
|
1868
1989
|
}
|
|
1869
|
-
},
|
|
1990
|
+
}, Ve = class extends ze {
|
|
1870
1991
|
_config;
|
|
1871
1992
|
_spawnPoints = [];
|
|
1872
1993
|
_entityNodes = [];
|
|
@@ -1888,9 +2009,9 @@ var Pe = class {
|
|
|
1888
2009
|
let n = e.createScene();
|
|
1889
2010
|
if (this._scene = n, this._config.physics && (this.$emitProgress(5, "Initializing physics..."), await this._enablePhysics(n)), this._config.scene && (this.$emitProgress(10, "Loading scene file..."), await this._loadSceneFile(n)), this._config.environment && (this.$emitProgress(15, "Setting up environment..."), this._processEnvironment(n)), this._processCameras(n), this._processLights(n), this._setupClustering(n), this._config.postProcessing) {
|
|
1890
2011
|
let e = this._config.postProcessing.renderer ?? "pipeline";
|
|
1891
|
-
this._log.info(`Applying post-processing with ${e} renderer`), await
|
|
2012
|
+
this._log.info(`Applying post-processing with ${e} renderer`), await Fe(n, this._config.postProcessing);
|
|
1892
2013
|
}
|
|
1893
|
-
return this.outlines = new
|
|
2014
|
+
return this.outlines = new Be(n, this._config.outlines), this.$emitProgress(50, "Processing scene properties..."), await this._processNodeProperties(n), this.$emitProgress(70, "Spawning entities..."), await this._processSpawnPoints(), this.$emitProgress(85, "Configuring entities..."), await this._processEntityNodes(), this._config.sounds && (this.$emitProgress(95, "Loading sounds..."), await this._processLevelSounds()), n;
|
|
1894
2015
|
}
|
|
1895
2016
|
async _loadSceneFile(e) {
|
|
1896
2017
|
let t = this._getScenePath();
|
|
@@ -1921,11 +2042,11 @@ var Pe = class {
|
|
|
1921
2042
|
}
|
|
1922
2043
|
e.environmentTexture && e.createDefaultSkybox(e.environmentTexture, !0, t.skyboxSize ?? 1e3, 0, !1);
|
|
1923
2044
|
} else {
|
|
1924
|
-
let n = t.skyboxSize ?? 1e3, r =
|
|
2045
|
+
let n = t.skyboxSize ?? 1e3, r = b.CreateSphere("skybox", {
|
|
1925
2046
|
diameter: n,
|
|
1926
2047
|
segments: 32
|
|
1927
|
-
}, e), i = new
|
|
1928
|
-
i.backFaceCulling = !1, i.disableLighting = !0, i.emissiveTexture = new
|
|
2048
|
+
}, e), i = new E("skybox-mat", e);
|
|
2049
|
+
i.backFaceCulling = !1, i.disableLighting = !0, i.emissiveTexture = new se(t.skybox, e), r.material = i, r.infiniteDistance = !0;
|
|
1929
2050
|
}
|
|
1930
2051
|
this._log.debug(`Skybox set from: ${t.skybox}`);
|
|
1931
2052
|
}
|
|
@@ -1961,20 +2082,20 @@ var Pe = class {
|
|
|
1961
2082
|
}
|
|
1962
2083
|
}
|
|
1963
2084
|
_createCamera(e, t, r) {
|
|
1964
|
-
let i = t.position ?
|
|
2085
|
+
let i = t.position ? q(t.position) : O.Zero(), a;
|
|
1965
2086
|
switch (t.type) {
|
|
1966
2087
|
case "arcRotate": {
|
|
1967
|
-
let i = t.target ?
|
|
2088
|
+
let i = t.target ? q(t.target) : O.Zero();
|
|
1968
2089
|
a = new n(e, t.alpha ?? Math.PI / 2, t.beta ?? Math.PI / 3, t.radius ?? 10, i, r);
|
|
1969
2090
|
break;
|
|
1970
2091
|
}
|
|
1971
2092
|
case "universal":
|
|
1972
|
-
a = new
|
|
2093
|
+
a = new ce(e, i, r);
|
|
1973
2094
|
break;
|
|
1974
2095
|
case "geospatial": {
|
|
1975
|
-
if (!t.planetRadius) return this._log.warn(`Geospatial camera "${e}" requires planetRadius -- skipping`), new d(e,
|
|
1976
|
-
let n = new
|
|
1977
|
-
t.center && (n.center =
|
|
2096
|
+
if (!t.planetRadius) return this._log.warn(`Geospatial camera "${e}" requires planetRadius -- skipping`), new d(e, O.Zero(), r);
|
|
2097
|
+
let n = new de(e, r, { planetRadius: t.planetRadius });
|
|
2098
|
+
t.center && (n.center = q(t.center)), t.yaw !== void 0 && (n.yaw = t.yaw), t.pitch !== void 0 && (n.pitch = t.pitch), t.radius !== void 0 && (n.radius = t.radius), t.checkCollisions !== void 0 && (n.checkCollisions = t.checkCollisions), t.radiusMin !== void 0 && (n.limits.radiusMin = t.radiusMin), t.radiusMax !== void 0 && (n.limits.radiusMax = t.radiusMax), t.pitchMin !== void 0 && (n.limits.pitchMin = t.pitchMin), t.pitchMax !== void 0 && (n.limits.pitchMax = t.pitchMax), t.yawMin !== void 0 && (n.limits.yawMin = t.yawMin), t.yawMax !== void 0 && (n.limits.yawMax = t.yawMax), a = n;
|
|
1978
2099
|
break;
|
|
1979
2100
|
}
|
|
1980
2101
|
default:
|
|
@@ -1984,7 +2105,7 @@ var Pe = class {
|
|
|
1984
2105
|
return this._applyCameraConfig(a, t), a;
|
|
1985
2106
|
}
|
|
1986
2107
|
_applyCameraConfig(e, t) {
|
|
1987
|
-
t.fov !== void 0 && (e.fov = t.fov), t.position && (e.position =
|
|
2108
|
+
t.fov !== void 0 && (e.fov = t.fov), t.position && (e.position = q(t.position)), t.minZ !== void 0 && (e.minZ = t.minZ), t.maxZ !== void 0 && (e.maxZ = t.maxZ), e instanceof d && (t.speed !== void 0 && (e.speed = t.speed), t.rotation && (e.rotation = q(t.rotation))), e instanceof n && (t.target && e.setTarget(q(t.target)), t.lowerRadiusLimit !== void 0 && (e.lowerRadiusLimit = t.lowerRadiusLimit), t.upperRadiusLimit !== void 0 && (e.upperRadiusLimit = t.upperRadiusLimit), t.lowerBetaLimit !== void 0 && (e.lowerBetaLimit = t.lowerBetaLimit), t.upperBetaLimit !== void 0 && (e.upperBetaLimit = t.upperBetaLimit), t.wheelPrecision !== void 0 && (e.wheelPrecision = t.wheelPrecision)), e instanceof de && (t.yaw !== void 0 && (e.yaw = t.yaw), t.pitch !== void 0 && (e.pitch = t.pitch), t.radius !== void 0 && (e.radius = t.radius), t.center && (e.center = q(t.center)), t.checkCollisions !== void 0 && (e.checkCollisions = t.checkCollisions), t.radiusMin !== void 0 && (e.limits.radiusMin = t.radiusMin), t.radiusMax !== void 0 && (e.limits.radiusMax = t.radiusMax), t.pitchMin !== void 0 && (e.limits.pitchMin = t.pitchMin), t.pitchMax !== void 0 && (e.limits.pitchMax = t.pitchMax));
|
|
1988
2109
|
}
|
|
1989
2110
|
_processLights(e) {
|
|
1990
2111
|
let t = this._config.lights;
|
|
@@ -1994,7 +2115,7 @@ var Pe = class {
|
|
|
1994
2115
|
}
|
|
1995
2116
|
}
|
|
1996
2117
|
_createLight(e, t, n) {
|
|
1997
|
-
let r = t.direction ?
|
|
2118
|
+
let r = t.direction ? q(t.direction) : new O(0, -1, 0), i = t.position ? q(t.position) : O.Zero();
|
|
1998
2119
|
switch (t.type) {
|
|
1999
2120
|
case "hemispheric": {
|
|
2000
2121
|
let i = new m(e, r, n);
|
|
@@ -2007,7 +2128,7 @@ var Pe = class {
|
|
|
2007
2128
|
break;
|
|
2008
2129
|
}
|
|
2009
2130
|
case "point": {
|
|
2010
|
-
let r = new
|
|
2131
|
+
let r = new ee(e, i, n);
|
|
2011
2132
|
this._applyLightConfig(r, t);
|
|
2012
2133
|
break;
|
|
2013
2134
|
}
|
|
@@ -2017,10 +2138,10 @@ var Pe = class {
|
|
|
2017
2138
|
break;
|
|
2018
2139
|
}
|
|
2019
2140
|
case "rectarea": {
|
|
2020
|
-
let a = new
|
|
2141
|
+
let a = new te(e, i, t.width ?? 1, t.height ?? 1, n);
|
|
2021
2142
|
if (this._applyLightConfig(a, t), t.direction) {
|
|
2022
|
-
let t = new
|
|
2023
|
-
t.position = a.position.clone(), a.position =
|
|
2143
|
+
let t = new D(`${e}_pivot`, n);
|
|
2144
|
+
t.position = a.position.clone(), a.position = O.Zero(), a.parent = t, t.lookAt(t.position.subtract(r));
|
|
2024
2145
|
}
|
|
2025
2146
|
break;
|
|
2026
2147
|
}
|
|
@@ -2032,22 +2153,22 @@ var Pe = class {
|
|
|
2032
2153
|
_setupClustering(e) {
|
|
2033
2154
|
let t = this._config.clustering;
|
|
2034
2155
|
if (!t?.enabled) return;
|
|
2035
|
-
let n = e.lights.filter((e) =>
|
|
2156
|
+
let n = e.lights.filter((e) => fe.IsLightSupported(e));
|
|
2036
2157
|
if (n.length === 0) {
|
|
2037
2158
|
this._log.debug("Clustering enabled but no eligible lights found");
|
|
2038
2159
|
return;
|
|
2039
2160
|
}
|
|
2040
2161
|
for (let t of n) e.removeLight(t);
|
|
2041
|
-
let r = new
|
|
2162
|
+
let r = new fe("sage-clustered", n, e);
|
|
2042
2163
|
t.horizontalTiles !== void 0 && (r.horizontalTiles = t.horizontalTiles), t.verticalTiles !== void 0 && (r.verticalTiles = t.verticalTiles), t.depthSlices !== void 0 && (r.depthSlices = t.depthSlices), t.maxRange !== void 0 && (r.maxRange = t.maxRange), this.clusteredLights = r, this._log.debug(`Clustered lighting enabled: ${n.length} lights, ${r.horizontalTiles}x${r.verticalTiles} tiles, ${r.depthSlices} depth slices`);
|
|
2043
|
-
for (let t of e.materials) t instanceof
|
|
2164
|
+
for (let t of e.materials) t instanceof S && (t.useGLTFLightFalloff = !0);
|
|
2044
2165
|
}
|
|
2045
2166
|
_toColor3(e) {
|
|
2046
2167
|
return new r(e.r, e.g, e.b);
|
|
2047
2168
|
}
|
|
2048
2169
|
async _enablePhysics(e) {
|
|
2049
|
-
let t = this._config.physics, n = new
|
|
2050
|
-
typeof t == "object" && t.gravity && (n = new
|
|
2170
|
+
let t = this._config.physics, n = new O(0, -9.81, 0);
|
|
2171
|
+
typeof t == "object" && t.gravity && (n = new O(t.gravity.x, t.gravity.y, t.gravity.z));
|
|
2051
2172
|
let r = this.gameEngine.largeWorldRendering ? 1e5 : void 0;
|
|
2052
2173
|
this._log.debug(`Enabling physics with gravity: ${n.toString()}`), await this.gameEngine.engines.sceneEngine.enablePhysics(e, n, r);
|
|
2053
2174
|
}
|
|
@@ -2068,13 +2189,17 @@ var Pe = class {
|
|
|
2068
2189
|
return t ? { ...t } : e.metadata;
|
|
2069
2190
|
}
|
|
2070
2191
|
async _processNodeMetadata(e) {
|
|
2071
|
-
"spawn" in e.metadata
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2192
|
+
if ("spawn" in e.metadata) {
|
|
2193
|
+
let { position: t, rotation: n, scaling: r } = Re(e);
|
|
2194
|
+
this._spawnPoints.push({
|
|
2195
|
+
name: e.metadata.spawn,
|
|
2196
|
+
position: t,
|
|
2197
|
+
rotation: n,
|
|
2198
|
+
scaling: r,
|
|
2199
|
+
node: e
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
"entity" in e.metadata && this._entityNodes.push({
|
|
2078
2203
|
type: e.metadata.entity,
|
|
2079
2204
|
node: e
|
|
2080
2205
|
}), await this._runPropertyHandlers(e);
|
|
@@ -2095,17 +2220,21 @@ var Pe = class {
|
|
|
2095
2220
|
async _processSpawnPoint(e, t) {
|
|
2096
2221
|
try {
|
|
2097
2222
|
let n = await this._spawnEntity(t, e);
|
|
2098
|
-
this._spawnedEntities.push(n), e.node.dispose(), this._log.debug(`Spawned entity '${t.entity}' at spawn point '${e.name}'`);
|
|
2223
|
+
this._spawnedEntities.push(n), this._applyDebugCollider(n, t.debugCollider), e.node.dispose(), this._log.debug(`Spawned entity '${t.entity}' at spawn point '${e.name}'`);
|
|
2099
2224
|
} catch (t) {
|
|
2100
2225
|
this._log.error(`Failed to spawn entity at spawn point '${e.name}':`, t);
|
|
2101
2226
|
}
|
|
2102
2227
|
}
|
|
2228
|
+
_applyDebugCollider(e, t) {
|
|
2229
|
+
let n = this.gameEngine.managers.entityManager.getDefinition(e.type)?.debugCollider, r = t ?? n;
|
|
2230
|
+
r && e.showCollider(r);
|
|
2231
|
+
}
|
|
2103
2232
|
async _spawnEntity(e, t) {
|
|
2104
2233
|
let n = {
|
|
2105
2234
|
...e.config,
|
|
2106
|
-
position:
|
|
2107
|
-
rotation:
|
|
2108
|
-
scaling:
|
|
2235
|
+
position: K(t.position),
|
|
2236
|
+
rotation: Ie(t.rotation),
|
|
2237
|
+
scaling: K(t.scaling)
|
|
2109
2238
|
}, r = await this.gameEngine.managers.entityManager.createEntity(e.entity, {
|
|
2110
2239
|
name: e.name,
|
|
2111
2240
|
tags: e.tags,
|
|
@@ -2117,12 +2246,10 @@ var Pe = class {
|
|
|
2117
2246
|
if (!this._scene) return;
|
|
2118
2247
|
let n = this.gameEngine.managers.entityManager.getDefinition(e.type);
|
|
2119
2248
|
if (!n?.mesh) return;
|
|
2120
|
-
let r = n.mesh, i = this._scene, a = new
|
|
2121
|
-
a.position.copyFrom(t.position), a.rotationQuaternion = t.rotation.clone(), a.scaling.copyFrom(t.scaling);
|
|
2122
|
-
let o;
|
|
2249
|
+
let r = n.mesh, i = this._scene, a = new D(`entity-${e.id}`, i), o;
|
|
2123
2250
|
switch (r.source) {
|
|
2124
2251
|
case "box":
|
|
2125
|
-
o = [
|
|
2252
|
+
o = [b.CreateBox(`${e.type}-mesh`, {
|
|
2126
2253
|
size: r.params?.size ?? 1,
|
|
2127
2254
|
width: r.params?.width,
|
|
2128
2255
|
height: r.params?.height,
|
|
@@ -2130,19 +2257,19 @@ var Pe = class {
|
|
|
2130
2257
|
}, i)];
|
|
2131
2258
|
break;
|
|
2132
2259
|
case "sphere":
|
|
2133
|
-
o = [
|
|
2260
|
+
o = [b.CreateSphere(`${e.type}-mesh`, {
|
|
2134
2261
|
diameter: r.params?.diameter ?? 1,
|
|
2135
2262
|
segments: r.params?.segments ?? 16
|
|
2136
2263
|
}, i)];
|
|
2137
2264
|
break;
|
|
2138
2265
|
case "capsule":
|
|
2139
|
-
o = [
|
|
2266
|
+
o = [b.CreateCapsule(`${e.type}-mesh`, {
|
|
2140
2267
|
height: r.params?.height ?? 1.8,
|
|
2141
2268
|
radius: r.params?.radius ?? .4
|
|
2142
2269
|
}, i)];
|
|
2143
2270
|
break;
|
|
2144
2271
|
case "cylinder":
|
|
2145
|
-
o = [
|
|
2272
|
+
o = [b.CreateCylinder(`${e.type}-mesh`, {
|
|
2146
2273
|
height: r.params?.height ?? 1,
|
|
2147
2274
|
diameter: r.params?.diameter ?? 1
|
|
2148
2275
|
}, i)];
|
|
@@ -2159,21 +2286,21 @@ var Pe = class {
|
|
|
2159
2286
|
}
|
|
2160
2287
|
}
|
|
2161
2288
|
for (let e of o) e.parent ||= a;
|
|
2162
|
-
r.scale && (typeof r.scale == "number" ? a.scaling.setAll(r.scale) : a.scaling.set(r.scale.x, r.scale.y, r.scale.z));
|
|
2289
|
+
a.position.copyFrom(t.position), a.rotationQuaternion = t.rotation.clone(), a.scaling.copyFrom(t.scaling), r.scale && (typeof r.scale == "number" ? a.scaling.setAll(r.scale) : a.scaling.set(r.scale.x, r.scale.y, r.scale.z));
|
|
2163
2290
|
let s = r.material;
|
|
2164
2291
|
if (s?.color) {
|
|
2165
2292
|
let t = s.color;
|
|
2166
2293
|
if (s.type === "pbr") {
|
|
2167
|
-
let n = new
|
|
2294
|
+
let n = new S(`${e.type}-material`, i);
|
|
2168
2295
|
n.albedoColor = this._toColor3(t), s.emissive && (n.emissiveColor = this._toColor3(s.emissive)), n.metallic = s.metallic ?? 0, n.roughness = s.roughness ?? 1;
|
|
2169
2296
|
for (let e of o) e.material = n;
|
|
2170
2297
|
} else {
|
|
2171
|
-
let n = new
|
|
2298
|
+
let n = new E(`${e.type}-material`, i);
|
|
2172
2299
|
n.diffuseColor = this._toColor3(t), s.emissive && (n.emissiveColor = this._toColor3(s.emissive));
|
|
2173
2300
|
for (let e of o) e.material = n;
|
|
2174
2301
|
}
|
|
2175
2302
|
}
|
|
2176
|
-
let c =
|
|
2303
|
+
let c = a.getDescendants(!1).filter((e) => e instanceof D);
|
|
2177
2304
|
for (let e of c) {
|
|
2178
2305
|
let t = this._getNormalizedMetadata(e);
|
|
2179
2306
|
t && Object.keys(t).length > 0 && (e.metadata = {
|
|
@@ -2191,14 +2318,14 @@ var Pe = class {
|
|
|
2191
2318
|
try {
|
|
2192
2319
|
let n = {
|
|
2193
2320
|
...t?.config,
|
|
2194
|
-
position:
|
|
2321
|
+
position: K(e.node.position)
|
|
2195
2322
|
}, r = await this.gameEngine.managers.entityManager.createEntity(e.type, {
|
|
2196
2323
|
name: t?.name ?? e.node.name,
|
|
2197
2324
|
tags: t?.tags,
|
|
2198
2325
|
initialState: n,
|
|
2199
2326
|
node: e.node
|
|
2200
2327
|
});
|
|
2201
|
-
this._spawnedEntities.push(r), this._log.debug(`Created entity '${e.type}' for node '${e.node.name}'`);
|
|
2328
|
+
this._spawnedEntities.push(r), this._applyDebugCollider(r, t?.debugCollider), this._log.debug(`Created entity '${e.type}' for node '${e.node.name}'`);
|
|
2202
2329
|
} catch (t) {
|
|
2203
2330
|
this._log.error(`Failed to create entity for node '${e.node.name}':`, t);
|
|
2204
2331
|
}
|
|
@@ -2243,7 +2370,7 @@ var Pe = class {
|
|
|
2243
2370
|
for (let e of this._levelSounds.values()) e.dispose();
|
|
2244
2371
|
this._levelSounds.clear(), this._playingSoundsBeforeDeactivate.clear(), await super.$dispose();
|
|
2245
2372
|
}
|
|
2246
|
-
},
|
|
2373
|
+
}, He = class {
|
|
2247
2374
|
_eventBus;
|
|
2248
2375
|
_gameEngine = null;
|
|
2249
2376
|
_log;
|
|
@@ -2261,7 +2388,7 @@ var Pe = class {
|
|
|
2261
2388
|
return this._propertyHandlers;
|
|
2262
2389
|
}
|
|
2263
2390
|
constructor(e, t) {
|
|
2264
|
-
this._eventBus = e, this._logger = t, this._log = t?.getLogger("LevelManager") || new
|
|
2391
|
+
this._eventBus = e, this._logger = t, this._log = t?.getLogger("LevelManager") || new N("LevelManager"), this._eventUnsubscribers.push(this._eventBus.subscribe("level:progress", (e) => {
|
|
2265
2392
|
this._handleProgress(e.payload);
|
|
2266
2393
|
})), this._eventUnsubscribers.push(this._eventBus.subscribe("level:complete", (e) => {
|
|
2267
2394
|
this._handleComplete(e.payload);
|
|
@@ -2296,7 +2423,7 @@ var Pe = class {
|
|
|
2296
2423
|
if (!n) throw Error(`Level class '${e.class}' is not registered.`);
|
|
2297
2424
|
return this._log.debug(`Creating level '${e.name}' using class '${e.class}'`), new n(e, t);
|
|
2298
2425
|
}
|
|
2299
|
-
return this._log.debug(`Creating level '${e.name}' using GameLevel`), new
|
|
2426
|
+
return this._log.debug(`Creating level '${e.name}' using GameLevel`), new Ve(e, t);
|
|
2300
2427
|
}
|
|
2301
2428
|
registerLevelConfig(e) {
|
|
2302
2429
|
this._levelConfigs.has(e.name) && this._log.warn(`Level config '${e.name}' is already registered. Overwriting.`), this._levelConfigs.set(e.name, e), this._log.info(`Registered level config: ${e.name}`);
|
|
@@ -2382,7 +2509,7 @@ var Pe = class {
|
|
|
2382
2509
|
for (let e of this._loadedLevels.values()) await e.$dispose();
|
|
2383
2510
|
this._loadedLevels.clear(), this._levelConfigs.clear(), this._currentLevel = null;
|
|
2384
2511
|
}
|
|
2385
|
-
},
|
|
2512
|
+
}, Ue = class {
|
|
2386
2513
|
_audioEngine;
|
|
2387
2514
|
_channels = /* @__PURE__ */ new Map();
|
|
2388
2515
|
_masterMuted = !1;
|
|
@@ -2453,14 +2580,14 @@ var Pe = class {
|
|
|
2453
2580
|
getChannels() {
|
|
2454
2581
|
return Array.from(this._channels.keys());
|
|
2455
2582
|
}
|
|
2456
|
-
},
|
|
2583
|
+
}, We = class {
|
|
2457
2584
|
_entityManager;
|
|
2458
2585
|
_levelManager;
|
|
2459
2586
|
_log;
|
|
2460
2587
|
_beforeSerializeHooks = [];
|
|
2461
2588
|
_afterDeserializeHooks = [];
|
|
2462
2589
|
constructor(e, t, n) {
|
|
2463
|
-
this._entityManager = e, this._levelManager = t, this._log = n?.getLogger("SaveManager") || new
|
|
2590
|
+
this._entityManager = e, this._levelManager = t, this._log = n?.getLogger("SaveManager") || new N("SaveManager"), this._log.info("SaveManager initialized");
|
|
2464
2591
|
}
|
|
2465
2592
|
onBeforeSerialize(e) {
|
|
2466
2593
|
this._beforeSerializeHooks.push(e);
|
|
@@ -2543,7 +2670,46 @@ var Pe = class {
|
|
|
2543
2670
|
async $teardown() {
|
|
2544
2671
|
this._beforeSerializeHooks = [], this._afterDeserializeHooks = [], this._log.info("SaveManager torn down");
|
|
2545
2672
|
}
|
|
2546
|
-
},
|
|
2673
|
+
}, Ge = class {
|
|
2674
|
+
_viewer = null;
|
|
2675
|
+
_shown = /* @__PURE__ */ new Map();
|
|
2676
|
+
_materials = /* @__PURE__ */ new Map();
|
|
2677
|
+
showColliderForNode(e, t) {
|
|
2678
|
+
if (!e.physicsBody || this._shown.has(e)) return;
|
|
2679
|
+
let n = this._getViewer(e).showBody(e.physicsBody);
|
|
2680
|
+
if (!n) return;
|
|
2681
|
+
let r = { debugMesh: n };
|
|
2682
|
+
if (t) {
|
|
2683
|
+
let i = this._getColorMaterial(t, e);
|
|
2684
|
+
n.material = i, r.colorMaterial = i;
|
|
2685
|
+
}
|
|
2686
|
+
this._shown.set(e, r);
|
|
2687
|
+
}
|
|
2688
|
+
hideColliderForNode(e) {
|
|
2689
|
+
!this._shown.get(e) || !this._viewer || (e.physicsBody && this._viewer.hideBody(e.physicsBody), this._shown.delete(e));
|
|
2690
|
+
}
|
|
2691
|
+
hideAll() {
|
|
2692
|
+
for (let [e] of this._shown) this.hideColliderForNode(e);
|
|
2693
|
+
}
|
|
2694
|
+
isShown(e) {
|
|
2695
|
+
return this._shown.has(e);
|
|
2696
|
+
}
|
|
2697
|
+
async $teardown() {
|
|
2698
|
+
this.dispose();
|
|
2699
|
+
}
|
|
2700
|
+
dispose() {
|
|
2701
|
+
this._viewer &&= (this.hideAll(), this._viewer.dispose(), null), this._shown.clear();
|
|
2702
|
+
for (let e of this._materials.values()) e.dispose();
|
|
2703
|
+
this._materials.clear();
|
|
2704
|
+
}
|
|
2705
|
+
_getViewer(e) {
|
|
2706
|
+
return this._viewer ||= new pe(e.getScene()), this._viewer;
|
|
2707
|
+
}
|
|
2708
|
+
_getColorMaterial(e, t) {
|
|
2709
|
+
let n = this._materials.get(e);
|
|
2710
|
+
return n || (n = new E(`sage-collider-debug-${e}`, t.getScene()), n.emissiveColor = r.FromHexString(e), n.disableLighting = !0, n.wireframe = !0, this._materials.set(e, n), n);
|
|
2711
|
+
}
|
|
2712
|
+
}, Ke = class {
|
|
2547
2713
|
_keyboardDevice;
|
|
2548
2714
|
_keysState = {};
|
|
2549
2715
|
_onDeviceConnected;
|
|
@@ -2608,7 +2774,7 @@ var Pe = class {
|
|
|
2608
2774
|
_notifyInputChanged(e) {
|
|
2609
2775
|
this._onInputChanged && this._onInputChanged(this._keyboardDevice, e);
|
|
2610
2776
|
}
|
|
2611
|
-
},
|
|
2777
|
+
}, qe = class {
|
|
2612
2778
|
_targetElement;
|
|
2613
2779
|
_mouseDevice;
|
|
2614
2780
|
_buttonState = {};
|
|
@@ -2727,7 +2893,7 @@ var Pe = class {
|
|
|
2727
2893
|
_notifyInputChanged(e) {
|
|
2728
2894
|
this._onInputChanged && this._onInputChanged(this._mouseDevice, e);
|
|
2729
2895
|
}
|
|
2730
|
-
},
|
|
2896
|
+
}, Je = class {
|
|
2731
2897
|
_gamepadDevices = {};
|
|
2732
2898
|
_buttonStates = {};
|
|
2733
2899
|
_axesStates = {};
|
|
@@ -2861,14 +3027,14 @@ var Pe = class {
|
|
|
2861
3027
|
_notifyInputChanged(e, t) {
|
|
2862
3028
|
this._onInputChanged && this._onInputChanged(e, t);
|
|
2863
3029
|
}
|
|
2864
|
-
},
|
|
3030
|
+
}, Ye = class {
|
|
2865
3031
|
_eventBus;
|
|
2866
3032
|
_keyboardRA;
|
|
2867
3033
|
_mouseRA;
|
|
2868
3034
|
_gamepadRA;
|
|
2869
3035
|
_log;
|
|
2870
3036
|
constructor(e, t, n) {
|
|
2871
|
-
this._eventBus = e, this._log = n?.getLogger("UserInputManager") || new
|
|
3037
|
+
this._eventBus = e, this._log = n?.getLogger("UserInputManager") || new N("UserInputManager"), this._log.info("Initializing UserInputManager"), this._log.debug("Initializing input resource access classes"), this._keyboardRA = new Ke(), this._mouseRA = new qe(t), this._gamepadRA = new Je(), this._log.debug("Registering input event callbacks"), this._keyboardRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._keyboardRA.onInputChanged(this._publishInputChanged.bind(this)), this._mouseRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._mouseRA.onInputChanged(this._publishInputChanged.bind(this)), this._gamepadRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._gamepadRA.onDeviceDisconnected(this._publishDeviceDisconnected.bind(this)), this._gamepadRA.onInputChanged(this._publishInputChanged.bind(this)), this._log.info("UserInputManager initialized successfully");
|
|
2872
3038
|
}
|
|
2873
3039
|
_publishDeviceConnected(e) {
|
|
2874
3040
|
this._log.debug(`Device connected: ${e.id} (${e.name})`), this._eventBus.publish({
|
|
@@ -2921,18 +3087,18 @@ var Pe = class {
|
|
|
2921
3087
|
};
|
|
2922
3088
|
//#endregion
|
|
2923
3089
|
//#region src/utils/graphics.ts
|
|
2924
|
-
async function
|
|
2925
|
-
let n = new
|
|
3090
|
+
async function Xe(e, t) {
|
|
3091
|
+
let n = new le(e, t);
|
|
2926
3092
|
return await n.initAsync(), n;
|
|
2927
3093
|
}
|
|
2928
|
-
function
|
|
3094
|
+
function J(e, t) {
|
|
2929
3095
|
return new l(e, t.antialias, t.options, t.adaptToDeviceRatio);
|
|
2930
3096
|
}
|
|
2931
|
-
function
|
|
2932
|
-
return new
|
|
3097
|
+
function Ze(e) {
|
|
3098
|
+
return new x(e);
|
|
2933
3099
|
}
|
|
2934
|
-
async function
|
|
2935
|
-
if (e === null) return console.debug("Using Null Engine"),
|
|
3100
|
+
async function Qe(e, t, n = !1) {
|
|
3101
|
+
if (e === null) return console.debug("Using Null Engine"), Ze(t);
|
|
2936
3102
|
if (n) if ("options" in t) {
|
|
2937
3103
|
let e = t;
|
|
2938
3104
|
t = {
|
|
@@ -2947,32 +3113,32 @@ async function Ke(e, t, n = !1) {
|
|
|
2947
3113
|
useLargeWorldRendering: !0
|
|
2948
3114
|
};
|
|
2949
3115
|
let r = t.engine || "auto";
|
|
2950
|
-
if (r === "webgpu") if (
|
|
2951
|
-
return console.debug("Using forced WebGPU engine"), await
|
|
3116
|
+
if (r === "webgpu") if (De()) try {
|
|
3117
|
+
return console.debug("Using forced WebGPU engine"), await Xe(e, t);
|
|
2952
3118
|
} catch (e) {
|
|
2953
3119
|
throw console.error("Forced WebGPU initialization failed:", e), Error("Forced WebGPU failed to initialize. If WebGPU is required, check browser compatibility.", { cause: e });
|
|
2954
3120
|
}
|
|
2955
3121
|
else throw Error("WebGPU was forced but is not available in this browser.");
|
|
2956
|
-
if (r === "webgl") return console.debug("Using forced WebGL engine"),
|
|
2957
|
-
if (
|
|
2958
|
-
return console.debug("Using WebGPU"),
|
|
3122
|
+
if (r === "webgl") return console.debug("Using forced WebGL engine"), J(e, t);
|
|
3123
|
+
if (De()) try {
|
|
3124
|
+
return console.debug("Using WebGPU"), Xe(e, t).catch((n) => (console.warn("WebGPU initialization failed, falling back to WebGL:", n), J(e, t)));
|
|
2959
3125
|
} catch (e) {
|
|
2960
3126
|
console.warn("WebGPU initialization failed, falling back to WebGL:", e);
|
|
2961
3127
|
}
|
|
2962
3128
|
else console.warn("WebGPU not supported, falling back to WebGL.");
|
|
2963
|
-
return console.debug("Using WebGL"),
|
|
3129
|
+
return console.debug("Using WebGL"), J(e, t);
|
|
2964
3130
|
}
|
|
2965
3131
|
//#endregion
|
|
2966
3132
|
//#region src/utils/physics.ts
|
|
2967
|
-
async function
|
|
2968
|
-
return await
|
|
3133
|
+
async function $e() {
|
|
3134
|
+
return await me();
|
|
2969
3135
|
}
|
|
2970
|
-
function
|
|
3136
|
+
function et(e) {
|
|
2971
3137
|
return new p(!0, e);
|
|
2972
3138
|
}
|
|
2973
3139
|
//#endregion
|
|
2974
3140
|
//#region src/utils/raycast.ts
|
|
2975
|
-
var
|
|
3141
|
+
var tt = class {
|
|
2976
3142
|
_entityManager;
|
|
2977
3143
|
constructor(e) {
|
|
2978
3144
|
this._entityManager = e;
|
|
@@ -3038,7 +3204,7 @@ var Ye = class {
|
|
|
3038
3204
|
pickingInfo: e
|
|
3039
3205
|
};
|
|
3040
3206
|
}
|
|
3041
|
-
},
|
|
3207
|
+
}, nt = class {
|
|
3042
3208
|
_nextId = 0;
|
|
3043
3209
|
_delays = [];
|
|
3044
3210
|
_intervals = [];
|
|
@@ -3093,21 +3259,120 @@ var Ye = class {
|
|
|
3093
3259
|
for (let t of this._intervals) for (t.elapsed += e; t.elapsed >= t.periodMs;) t.callback(), t.elapsed -= t.periodMs;
|
|
3094
3260
|
for (let t of this._cooldowns) t.remaining > 0 && (t.remaining = Math.max(0, t.remaining - e));
|
|
3095
3261
|
}
|
|
3096
|
-
}
|
|
3262
|
+
};
|
|
3263
|
+
//#endregion
|
|
3264
|
+
//#region src/utils/entityProxy.ts
|
|
3265
|
+
function rt(e) {
|
|
3266
|
+
return new Proxy(e, { get(e, t) {
|
|
3267
|
+
if (typeof t == "symbol") return Reflect.get(e, t);
|
|
3268
|
+
if (t in e) {
|
|
3269
|
+
let n = Reflect.get(e, t);
|
|
3270
|
+
return typeof n == "function" ? n.bind(e) : n;
|
|
3271
|
+
}
|
|
3272
|
+
return e.getByName(t);
|
|
3273
|
+
} });
|
|
3274
|
+
}
|
|
3275
|
+
//#endregion
|
|
3276
|
+
//#region src/debug/builtins.ts
|
|
3277
|
+
function it(e, t) {
|
|
3278
|
+
return typeof e == "string" ? t.managers.entityManager.getByName(e) : e;
|
|
3279
|
+
}
|
|
3280
|
+
function at(e, t) {
|
|
3281
|
+
let n = t.managers.entityManager;
|
|
3282
|
+
if (e === void 0) return [...n.getAllEntities()];
|
|
3283
|
+
if (typeof e != "string") return [e];
|
|
3284
|
+
let r = n.getByName(e);
|
|
3285
|
+
if (r) return [r];
|
|
3286
|
+
let i = n.getByType(e);
|
|
3287
|
+
return i.length > 0 ? i : (console.warn(`[sage] No entity found with name or type "${e}"`), []);
|
|
3288
|
+
}
|
|
3289
|
+
function ot(e, t) {
|
|
3290
|
+
let n = t.managers.entityManager, r = t.managers.gameManager, i = t.managers.levelManager, a = [];
|
|
3291
|
+
e.expose("engine", t), e.expose("events", t.eventBus), e.expose("physics", t.physics), e.expose("colliders", t.debug.colliders), e.expose("entities", rt(n)), e.expose("level", { get: () => i.currentLevel }), e.expose("scene", { get: () => i.currentLevel?.scene ?? null }), e.expose("tp", (e, n, r, i) => {
|
|
3292
|
+
let a = it(e, t);
|
|
3293
|
+
if (!a) {
|
|
3294
|
+
console.warn(`[sage] Entity not found: ${e}`);
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
if (!a.node) {
|
|
3298
|
+
console.warn(`[sage] Entity "${a.name ?? a.id}" has no node`);
|
|
3299
|
+
return;
|
|
3300
|
+
}
|
|
3301
|
+
a.node.position.x = n, a.node.position.y = r, a.node.position.z = i, console.log(`[sage] Teleported "${a.name ?? a.id}" to (${n}, ${r}, ${i})`);
|
|
3302
|
+
}), e.expose("spawn", async (e, t, r, i) => {
|
|
3303
|
+
let a = await n.createEntity(e, { initialState: { position: {
|
|
3304
|
+
x: t,
|
|
3305
|
+
y: r,
|
|
3306
|
+
z: i
|
|
3307
|
+
} } });
|
|
3308
|
+
return console.log(`[sage] Spawned "${e}" (${a.id}) at (${t}, ${r}, ${i})`), a;
|
|
3309
|
+
}), e.expose("list", (e) => {
|
|
3310
|
+
let t;
|
|
3311
|
+
t = e ? n.getByType(e) : [...n.getAllEntities()];
|
|
3312
|
+
let r = t.map((e) => ({
|
|
3313
|
+
id: e.id,
|
|
3314
|
+
type: e.type,
|
|
3315
|
+
name: e.name ?? "(unnamed)",
|
|
3316
|
+
node: e.node?.name ?? "(no node)"
|
|
3317
|
+
}));
|
|
3318
|
+
return console.table(r), t;
|
|
3319
|
+
}), e.expose("inspect", (e) => {
|
|
3320
|
+
let n = it(e, t);
|
|
3321
|
+
if (!n) {
|
|
3322
|
+
console.warn(`[sage] Entity not found: ${e}`);
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
let r = {
|
|
3326
|
+
id: n.id,
|
|
3327
|
+
type: n.type,
|
|
3328
|
+
name: n.name,
|
|
3329
|
+
state: n.state,
|
|
3330
|
+
behaviors: n.behaviors.map((e) => e.name),
|
|
3331
|
+
node: n.node?.name ?? null,
|
|
3332
|
+
position: n.node?.position ?? null
|
|
3333
|
+
};
|
|
3334
|
+
return console.log("[sage] Entity info:", r), r;
|
|
3335
|
+
}), e.expose("showColliders", (e) => {
|
|
3336
|
+
let n = at(e, t);
|
|
3337
|
+
for (let e of n) e.showCollider();
|
|
3338
|
+
console.log(`[sage] Showing colliders for ${n.length} entity(s)`);
|
|
3339
|
+
}), e.expose("hideColliders", (e) => {
|
|
3340
|
+
let n = at(e, t);
|
|
3341
|
+
for (let e of n) e.hideCollider();
|
|
3342
|
+
console.log(`[sage] Hiding colliders for ${n.length} entity(s)`);
|
|
3343
|
+
}), e.expose("logEvents", (e) => {
|
|
3344
|
+
let n = e ?? "*", r = t.eventBus.subscribe(n, (e) => {
|
|
3345
|
+
console.log(`[sage] Event: ${e.type}`, e.payload);
|
|
3346
|
+
});
|
|
3347
|
+
return a.push(r), console.log(`[sage] Logging events matching "${n}"`), r;
|
|
3348
|
+
}), e.expose("stopLogging", () => {
|
|
3349
|
+
for (let e of a) e();
|
|
3350
|
+
console.log(`[sage] Stopped ${a.length} event logger(s)`), a.length = 0;
|
|
3351
|
+
}), e.expose("pause", () => {
|
|
3352
|
+
r.pause("debug console"), console.log("[sage] Game paused");
|
|
3353
|
+
}), e.expose("resume", () => {
|
|
3354
|
+
r.resume("debug console"), console.log("[sage] Game resumed");
|
|
3355
|
+
}), e.expose("slow", (e) => {
|
|
3356
|
+
t.renderEngine.timeStep = 1 / 60 / e, console.log(`[sage] Time scale set to ${e}x (timeStep=${1 / 60 / e})`);
|
|
3357
|
+
});
|
|
3358
|
+
}
|
|
3359
|
+
//#endregion
|
|
3360
|
+
//#region src/interfaces/logger.ts
|
|
3361
|
+
var st = [
|
|
3097
3362
|
"trace",
|
|
3098
3363
|
"debug",
|
|
3099
3364
|
"info",
|
|
3100
3365
|
"warn",
|
|
3101
3366
|
"error",
|
|
3102
3367
|
"none"
|
|
3103
|
-
],
|
|
3368
|
+
], ct = class extends G {
|
|
3104
3369
|
name = "sound";
|
|
3105
3370
|
eventSubscriptions = [];
|
|
3106
3371
|
_sounds = /* @__PURE__ */ new Map();
|
|
3107
3372
|
_initialized = !1;
|
|
3108
3373
|
_audioManager = null;
|
|
3109
3374
|
_node = null;
|
|
3110
|
-
_log = new
|
|
3375
|
+
_log = new N("SoundBehavior");
|
|
3111
3376
|
onNodeAttached(e, t) {
|
|
3112
3377
|
if (this._initialized) return;
|
|
3113
3378
|
if (this._node = e, this._initialized = !0, this._log = t.logger.getLogger("SoundBehavior"), t.managers.audioManager) this._audioManager = t.managers.audioManager;
|
|
@@ -3190,7 +3455,7 @@ var Ye = class {
|
|
|
3190
3455
|
if (e) return this._sounds.get(e);
|
|
3191
3456
|
if (this._sounds.size === 1) return this._sounds.values().next().value;
|
|
3192
3457
|
}
|
|
3193
|
-
},
|
|
3458
|
+
}, Y = class {
|
|
3194
3459
|
_currentState;
|
|
3195
3460
|
transitions = /* @__PURE__ */ new Map();
|
|
3196
3461
|
wildcardTransitions = /* @__PURE__ */ new Map();
|
|
@@ -3245,13 +3510,13 @@ var Ye = class {
|
|
|
3245
3510
|
}
|
|
3246
3511
|
});
|
|
3247
3512
|
}
|
|
3248
|
-
},
|
|
3513
|
+
}, lt = class extends G {
|
|
3249
3514
|
name = "stateMachine";
|
|
3250
3515
|
eventSubscriptions = [];
|
|
3251
3516
|
stateMachine;
|
|
3252
3517
|
stateKey;
|
|
3253
3518
|
constructor() {
|
|
3254
|
-
super(), this.stateMachine = new
|
|
3519
|
+
super(), this.stateMachine = new Y(""), this.stateKey = "";
|
|
3255
3520
|
}
|
|
3256
3521
|
get currentState() {
|
|
3257
3522
|
return this.stateMachine.currentState;
|
|
@@ -3264,67 +3529,75 @@ var Ye = class {
|
|
|
3264
3529
|
}
|
|
3265
3530
|
static create(e) {
|
|
3266
3531
|
let { initialState: t, stateKey: n, transitions: r, wildcardTransitions: i } = e;
|
|
3267
|
-
class a extends
|
|
3532
|
+
class a extends lt {
|
|
3268
3533
|
constructor() {
|
|
3269
|
-
super(), this.stateKey = n, this.stateMachine = new
|
|
3534
|
+
super(), this.stateKey = n, this.stateMachine = new Y(t);
|
|
3270
3535
|
for (let e of r) this.stateMachine.addTransition(e.from, e.to, e.guard);
|
|
3271
3536
|
if (i) for (let e of i) this.stateMachine.addTransitionFromAny(e.to, e.guard);
|
|
3272
3537
|
}
|
|
3273
3538
|
}
|
|
3274
3539
|
return a;
|
|
3275
3540
|
}
|
|
3276
|
-
},
|
|
3277
|
-
function
|
|
3278
|
-
let r = e.
|
|
3279
|
-
|
|
3541
|
+
}, X = new N("ColliderHandler");
|
|
3542
|
+
function ut(e) {
|
|
3543
|
+
let { min: t, max: n } = e.getHierarchyBoundingVectors(!0), r = n.subtract(t), i = t.add(n).scale(.5).subtract(e.absolutePosition), a = e.absoluteRotationQuaternion, o = T.Inverse(a), s = new O();
|
|
3544
|
+
return i.rotateByQuaternionToRef(o, s), {
|
|
3545
|
+
extents: r,
|
|
3546
|
+
center: s
|
|
3547
|
+
};
|
|
3548
|
+
}
|
|
3549
|
+
function Z(e, t, n) {
|
|
3550
|
+
let r = e.getScene(), i = { mass: n };
|
|
3551
|
+
if (!(e instanceof y) && (t === w.BOX || t === w.SPHERE)) {
|
|
3552
|
+
let { extents: n, center: r } = ut(e);
|
|
3553
|
+
i.center = r, t === w.BOX ? i.extents = n : i.radius = Math.max(n.x, n.y, n.z) / 2;
|
|
3554
|
+
}
|
|
3555
|
+
new C(e, t, i, r);
|
|
3280
3556
|
}
|
|
3281
|
-
function
|
|
3557
|
+
function dt(e, t) {
|
|
3282
3558
|
let n = e.getChildMeshes().find((e) => e.metadata?.collider_mesh === !0);
|
|
3283
|
-
n instanceof
|
|
3559
|
+
n instanceof y ? (n.isVisible = !1, Z(n, w.MESH, t)) : Z(e, w.MESH, t);
|
|
3284
3560
|
}
|
|
3285
|
-
function
|
|
3561
|
+
function ft(t) {
|
|
3286
3562
|
t.registerPropertyHandler("collider", (t, n, r, i) => {
|
|
3287
3563
|
let a = n;
|
|
3288
|
-
if (
|
|
3289
|
-
if (!(t instanceof
|
|
3290
|
-
|
|
3564
|
+
if (X.debug(`Processing collider: ${t.name} -> ${a} (isMesh: ${t instanceof y})`), !r.scene) throw Error("Scene not available for collider handler");
|
|
3565
|
+
if (!(t instanceof y) && a === "mesh") {
|
|
3566
|
+
X.warn(`Skipping mesh collider for ${t.name}: not a Mesh instance`);
|
|
3291
3567
|
return;
|
|
3292
3568
|
}
|
|
3293
3569
|
let o = t.metadata?.collider_mass ?? 0;
|
|
3294
3570
|
switch (a) {
|
|
3295
3571
|
case "box":
|
|
3296
|
-
|
|
3572
|
+
Z(t, w.BOX, o);
|
|
3297
3573
|
break;
|
|
3298
3574
|
case "sphere":
|
|
3299
|
-
|
|
3575
|
+
Z(t, w.SPHERE, o);
|
|
3300
3576
|
break;
|
|
3301
3577
|
case "mesh":
|
|
3302
|
-
|
|
3578
|
+
dt(t, o);
|
|
3303
3579
|
break;
|
|
3304
3580
|
case "none":
|
|
3305
3581
|
t instanceof e && (t.checkCollisions = !1);
|
|
3306
3582
|
break;
|
|
3307
|
-
default:
|
|
3308
|
-
}
|
|
3309
|
-
if (t.metadata?.collider_kinematic) {
|
|
3310
|
-
let e = t;
|
|
3311
|
-
e.physicsBody && (e.physicsBody.disablePreStep = !1);
|
|
3583
|
+
default: X.warn(`Unknown collider type: ${a}`);
|
|
3312
3584
|
}
|
|
3585
|
+
t.metadata?.collider_kinematic && t instanceof e && t.physicsBody && (t.physicsBody.disablePreStep = !1);
|
|
3313
3586
|
});
|
|
3314
3587
|
}
|
|
3315
3588
|
//#endregion
|
|
3316
3589
|
//#region src/handlers/lod.ts
|
|
3317
|
-
var
|
|
3318
|
-
function
|
|
3590
|
+
var pt = new N("LodHandler");
|
|
3591
|
+
function mt(e) {
|
|
3319
3592
|
return e.split(",").map((e) => parseFloat(e.trim())).filter((e) => !isNaN(e));
|
|
3320
3593
|
}
|
|
3321
|
-
function
|
|
3594
|
+
function ht(e) {
|
|
3322
3595
|
e.registerPropertyHandler("lod_distances", (e, t, n, r) => {
|
|
3323
3596
|
let i = t;
|
|
3324
|
-
if (!(e instanceof
|
|
3325
|
-
let a =
|
|
3597
|
+
if (!(e instanceof y)) return;
|
|
3598
|
+
let a = mt(i);
|
|
3326
3599
|
if (a.length === 0) {
|
|
3327
|
-
|
|
3600
|
+
pt.warn(`Invalid lod_distances value: ${i}`);
|
|
3328
3601
|
return;
|
|
3329
3602
|
}
|
|
3330
3603
|
let o = e.getChildMeshes(!0), s = Math.min(a.length, o.length);
|
|
@@ -3335,14 +3608,14 @@ function it(e) {
|
|
|
3335
3608
|
}
|
|
3336
3609
|
//#endregion
|
|
3337
3610
|
//#region src/handlers/occluder.ts
|
|
3338
|
-
function
|
|
3611
|
+
function gt(e) {
|
|
3339
3612
|
e.registerPropertyHandler("occluder", (e, t, n, r) => {
|
|
3340
|
-
t && e instanceof
|
|
3613
|
+
t && e instanceof y && (e.isOccluder = !0, e.isVisible = !1);
|
|
3341
3614
|
});
|
|
3342
3615
|
}
|
|
3343
3616
|
//#endregion
|
|
3344
3617
|
//#region src/utils/metadata.ts
|
|
3345
|
-
function
|
|
3618
|
+
function _t(e, t) {
|
|
3346
3619
|
let n = {}, r = `${t}_`;
|
|
3347
3620
|
for (let [t, i] of Object.entries(e)) if (t.startsWith(r)) {
|
|
3348
3621
|
let e = t.slice(r.length);
|
|
@@ -3352,14 +3625,14 @@ function at(e, t) {
|
|
|
3352
3625
|
}
|
|
3353
3626
|
//#endregion
|
|
3354
3627
|
//#region src/handlers/sound.ts
|
|
3355
|
-
var
|
|
3356
|
-
function
|
|
3628
|
+
var vt = new N("SoundHandler");
|
|
3629
|
+
function yt(e) {
|
|
3357
3630
|
e.registerPropertyHandler("sound", (e, t, n, r) => {
|
|
3358
3631
|
let i = t;
|
|
3359
3632
|
if (!n.scene) throw Error("Scene not available for sound handler");
|
|
3360
|
-
let a =
|
|
3633
|
+
let a = _t(e.metadata, "sound"), o = a.volume ?? 1, s = a.loop ?? !0, c = a.spatial ?? !0, l = a.distance ?? 100, u = a.autoplay ?? !0, d = a.channel ?? "ambient", f = r.managers.audioManager;
|
|
3361
3634
|
if (!f) {
|
|
3362
|
-
|
|
3635
|
+
vt.warn(`No AudioManager available. Sound for "${e.name}" skipped.`);
|
|
3363
3636
|
return;
|
|
3364
3637
|
}
|
|
3365
3638
|
f.createSound(`${e.name}_sound`, i, d, {
|
|
@@ -3372,13 +3645,13 @@ function st(e) {
|
|
|
3372
3645
|
}).then((t) => {
|
|
3373
3646
|
c && t.spatial.attach(e);
|
|
3374
3647
|
}).catch((t) => {
|
|
3375
|
-
|
|
3648
|
+
vt.error(`Failed to create sound for node "${e.name}": ${t}`);
|
|
3376
3649
|
});
|
|
3377
3650
|
});
|
|
3378
3651
|
}
|
|
3379
3652
|
//#endregion
|
|
3380
3653
|
//#region src/handlers/trigger.ts
|
|
3381
|
-
function
|
|
3654
|
+
function Q(e, n, r, i, a) {
|
|
3382
3655
|
let o = a === "enter" ? t.OnIntersectionEnterTrigger : t.OnIntersectionExitTrigger, s = `trigger:${a}`;
|
|
3383
3656
|
e.registerAction(new u({
|
|
3384
3657
|
trigger: o,
|
|
@@ -3393,10 +3666,10 @@ function ct(e, n, r, i, a) {
|
|
|
3393
3666
|
});
|
|
3394
3667
|
}));
|
|
3395
3668
|
}
|
|
3396
|
-
function
|
|
3397
|
-
|
|
3669
|
+
function bt(e, t, n, r) {
|
|
3670
|
+
Q(e, t, n, r, "enter"), Q(e, t, n, r, "exit");
|
|
3398
3671
|
}
|
|
3399
|
-
function
|
|
3672
|
+
function xt(n) {
|
|
3400
3673
|
n.registerPropertyHandler("trigger", (n, r, i, a) => {
|
|
3401
3674
|
let o = r, s = i.scene;
|
|
3402
3675
|
if (!s) throw Error("Scene not available for trigger handler");
|
|
@@ -3405,9 +3678,9 @@ function ut(n) {
|
|
|
3405
3678
|
n.isVisible = !1, n.checkCollisions = !0;
|
|
3406
3679
|
let l = n.actionManager ?? new t(s);
|
|
3407
3680
|
n.actionManager = l;
|
|
3408
|
-
for (let e of s.meshes) e !== n && !e.metadata?.trigger &&
|
|
3681
|
+
for (let e of s.meshes) e !== n && !e.metadata?.trigger && bt(l, o, c, e);
|
|
3409
3682
|
let u = s.onNewMeshAddedObservable.add((e) => {
|
|
3410
|
-
e !== n && !e.metadata?.trigger &&
|
|
3683
|
+
e !== n && !e.metadata?.trigger && bt(l, o, c, e);
|
|
3411
3684
|
});
|
|
3412
3685
|
n.onDisposeObservable.add(() => {
|
|
3413
3686
|
s.onNewMeshAddedObservable.remove(u);
|
|
@@ -3416,7 +3689,7 @@ function ut(n) {
|
|
|
3416
3689
|
}
|
|
3417
3690
|
//#endregion
|
|
3418
3691
|
//#region src/handlers/visible.ts
|
|
3419
|
-
function
|
|
3692
|
+
function $(t) {
|
|
3420
3693
|
t.registerPropertyHandler("visible", (t, n, r, i) => {
|
|
3421
3694
|
if (!(t instanceof e)) return;
|
|
3422
3695
|
let a = !0;
|
|
@@ -3425,39 +3698,41 @@ function dt(t) {
|
|
|
3425
3698
|
}
|
|
3426
3699
|
//#endregion
|
|
3427
3700
|
//#region src/handlers/index.ts
|
|
3428
|
-
function
|
|
3429
|
-
|
|
3701
|
+
function St(e) {
|
|
3702
|
+
ft(e), ht(e), gt(e), yt(e), xt(e), $(e);
|
|
3430
3703
|
}
|
|
3431
3704
|
//#endregion
|
|
3432
3705
|
//#region src/sage.ts
|
|
3433
|
-
async function
|
|
3434
|
-
let r = new
|
|
3435
|
-
i.info(`Initializing SAGE Game Engine v${
|
|
3436
|
-
let a = await
|
|
3706
|
+
async function Ct(e, t, n = {}) {
|
|
3707
|
+
let r = new P(n.logLevel || "debug"), i = r.getLogger("SAGE");
|
|
3708
|
+
i.info(`Initializing SAGE Game Engine v${k}...`), i.debug("Creating rendering engine...");
|
|
3709
|
+
let a = await Qe(e, {
|
|
3437
3710
|
antialias: !0,
|
|
3438
3711
|
adaptToDeviceRatio: !0,
|
|
3439
3712
|
...n.renderOptions
|
|
3440
3713
|
}, n.largeWorldRendering ?? !1);
|
|
3441
3714
|
i.debug("Creating physics engine...");
|
|
3442
|
-
let o = await
|
|
3715
|
+
let o = await $e(), s = et(o);
|
|
3443
3716
|
i.debug("Creating event bus...");
|
|
3444
|
-
let c = new
|
|
3717
|
+
let c = new F(r);
|
|
3445
3718
|
i.debug("Creating scene engine...");
|
|
3446
|
-
let l = new
|
|
3719
|
+
let l = new L(e, a, o, r);
|
|
3447
3720
|
i.debug("Creating managers...");
|
|
3448
|
-
let u = new
|
|
3721
|
+
let u = new R(c, l, r), d = new Ye(c, e, r), f = new Ee(c, r), p = new Me(c, r, f), m = new He(c, r), h = new We(p, m, r), g = new Oe(a, c, p, d, m, r), _ = null;
|
|
3722
|
+
n.debug !== !1 && (i.debug("Creating debug console..."), _ = new he((typeof n.debug == "object" ? n.debug.namespace : void 0) ?? "sage")), i.debug("Creating collider debug manager...");
|
|
3723
|
+
let v = new Ge();
|
|
3449
3724
|
i.debug("Creating raycast helper...");
|
|
3450
|
-
let
|
|
3725
|
+
let y = new tt(p);
|
|
3451
3726
|
i.debug("Creating game timer...");
|
|
3452
|
-
let
|
|
3453
|
-
g.registerFrameCallback((e) =>
|
|
3454
|
-
let
|
|
3455
|
-
n.audioChannels && n.audioChannels.length > 0 && (i.debug("Creating audio engine..."),
|
|
3727
|
+
let b = new nt();
|
|
3728
|
+
g.registerFrameCallback((e) => b.tick(e * 1e3));
|
|
3729
|
+
let x, S;
|
|
3730
|
+
n.audioChannels && n.audioChannels.length > 0 && (i.debug("Creating audio engine..."), x = new I(r), await x.initialize(), i.debug("Creating audio manager..."), S = new Ue(x, r), await S.initialize(n.audioChannels)), i.info(`SAGE Game Engine v${k} initialized successfully.`), i.debug("Loading entities...");
|
|
3456
3731
|
for (let e of t) p.registerEntityDefinition(e);
|
|
3457
3732
|
if (i.debug("Registering default input bindings..."), n.bindings) for (let e of n.bindings) f.registerBinding(e);
|
|
3458
|
-
let
|
|
3733
|
+
let C = new A(e, a, s, c, r, y, b, {
|
|
3459
3734
|
sceneEngine: l,
|
|
3460
|
-
audioEngine:
|
|
3735
|
+
audioEngine: x
|
|
3461
3736
|
}, {
|
|
3462
3737
|
assetManager: u,
|
|
3463
3738
|
bindingManager: f,
|
|
@@ -3466,11 +3741,17 @@ async function pt(e, t, n = {}) {
|
|
|
3466
3741
|
inputManager: d,
|
|
3467
3742
|
levelManager: m,
|
|
3468
3743
|
saveManager: h,
|
|
3469
|
-
audioManager:
|
|
3470
|
-
}, n.largeWorldRendering ?? !1
|
|
3471
|
-
|
|
3744
|
+
audioManager: S
|
|
3745
|
+
}, n.largeWorldRendering ?? !1, {
|
|
3746
|
+
colliders: v,
|
|
3747
|
+
console: _,
|
|
3748
|
+
expose: (e, t) => {
|
|
3749
|
+
_?.expose(e, t);
|
|
3750
|
+
}
|
|
3751
|
+
});
|
|
3752
|
+
return p.$setGameEngine(C), m.$setGameEngine(C), _ && ot(_, C), C;
|
|
3472
3753
|
}
|
|
3473
3754
|
//#endregion
|
|
3474
|
-
export {
|
|
3755
|
+
export { R as AssetManager, I as AudioEngine, Ue as AudioManager, Ge as ColliderDebugManager, j as ConsoleBackend, he as DebugConsole, A as GameEngine, je as GameEntity, G as GameEntityBehavior, F as GameEventBus, Ve as GameLevel, nt as GameTimer, ze as Level, st as LogLevels, P as LoggingUtility, M as NullBackend, Be as OutlineManager, tt as RaycastHelper, N as SAGELogger, We as SaveManager, L as SceneEngine, ct as SoundBehavior, Y as StateMachine, lt as StateMachineBehavior, k as VERSION, Fe as applyPostProcessing, z as bindingTypes, _t as collectPrefixedProperties, rt as createEntityProxy, Ct as createGameEngine, Ae as generateId, Re as getCanonicalTransform, V as isGamepadState, _e as isKeyboardState, B as isMouseState, St as registerAllPropertyHandlers, ft as registerColliderHandler, ht as registerLodHandler, gt as registerOccluderHandler, yt as registerSoundHandler, xt as registerTriggerHandler, $ as registerVisibleHandler, Ie as toQuatObject, Le as toQuaternion, K as toVec3Object, q as toVector3, ge as validDeviceTypes };
|
|
3475
3756
|
|
|
3476
3757
|
//# sourceMappingURL=sage.es.js.map
|