@threenative/core 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import type { Scene as ThreeScene } from "three";
|
|
2
|
+
import type { AutoBatch } from "./auto-batch.js";
|
|
3
|
+
import { ComputeDrivenRegistry } from "./compute-driven.js";
|
|
4
|
+
import type { Registry } from "./entities.js";
|
|
5
|
+
import type { FrameBudget } from "./frame-budget.js";
|
|
6
|
+
import type { IGameConfig, IGamePlatformSource, IGamePluginHooks } from "./game.js";
|
|
7
|
+
import type { GeometryCapture } from "./geometry-capture.js";
|
|
8
|
+
import type { InputMap } from "./input.js";
|
|
9
|
+
import type { PhysicsInterpolation } from "./interpolation.js";
|
|
10
|
+
import type { IAfterPhysicsPhase } from "./loop.js";
|
|
11
|
+
import type { MatrixWorldPass } from "./matrix-world.js";
|
|
12
|
+
import type { ScenePicker } from "./picking.js";
|
|
13
|
+
import type { PointerEvents3D } from "./pointer-events.js";
|
|
14
|
+
import type { RenderCameraCull } from "./render-camera-cull.js";
|
|
15
|
+
import type { SceneRenderProjection } from "./renderProjection.js";
|
|
16
|
+
import type { IRendererLike } from "./renderer.js";
|
|
17
|
+
import type { ICtx, Scene, SceneFrame } from "./scene.js";
|
|
18
|
+
import type { Scheduler } from "./schedule.js";
|
|
19
|
+
import type { GameStore } from "./state.js";
|
|
20
|
+
import type { IUiBridge } from "./ui-bridge.js";
|
|
21
|
+
import type { Viewport } from "./viewport.js";
|
|
22
|
+
import type { IWarmUpOptions } from "./warmup.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The state the boot phases own: every resource a phase acquires, and every flag a phase reads.
|
|
26
|
+
* One object, assigned by name, so a phase that needs a field this lacks fails to compile.
|
|
27
|
+
*/
|
|
28
|
+
export interface IBootState<TState extends Record<string, unknown>, TPhysics> {
|
|
29
|
+
/** Releases pushed as resources are acquired; `#teardown` drains them, newest first. */
|
|
30
|
+
readonly cleanup: Array<() => void>;
|
|
31
|
+
readonly computeDriven: ComputeDrivenRegistry;
|
|
32
|
+
readonly config: IGameConfig<TState, TPhysics>;
|
|
33
|
+
readonly state: GameStore<TState>;
|
|
34
|
+
/**
|
|
35
|
+
* Unlike afterPhysics, this seam's frame boundary is the world-render block, so it is a plain
|
|
36
|
+
* scene-owned set rather than a phase on the loop.
|
|
37
|
+
*/
|
|
38
|
+
readonly beforeRenderCallbacks: Set<() => void>;
|
|
39
|
+
activePlugins: Array<IGamePluginHooks<TState, TPhysics>>;
|
|
40
|
+
aborted: boolean;
|
|
41
|
+
afterPhysicsPhase: IAfterPhysicsPhase | undefined;
|
|
42
|
+
autoBatch: AutoBatch | undefined;
|
|
43
|
+
/** Reused snapshot buffers, one per nesting depth, so a steady frame allocates no callback array. */
|
|
44
|
+
beforeRenderSnapshots: Array<Array<() => void>>;
|
|
45
|
+
beforeRenderDepth: number;
|
|
46
|
+
cameraCull: RenderCameraCull | undefined;
|
|
47
|
+
ctx: ICtx<TState, TPhysics> | undefined;
|
|
48
|
+
entities: Registry | undefined;
|
|
49
|
+
frameBudget: FrameBudget | undefined;
|
|
50
|
+
geometryCapture: GeometryCapture | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Depth-coupled output needs the scene hook before its pass; ordinary scenes retain the
|
|
53
|
+
* historical after-render hook so an atmosphere-free game has the same render path as HEAD.
|
|
54
|
+
*/
|
|
55
|
+
hasDepthCoupledOutput: boolean;
|
|
56
|
+
input: InputMap | undefined;
|
|
57
|
+
interpolation: PhysicsInterpolation | undefined;
|
|
58
|
+
matrixWorld: MatrixWorldPass | undefined;
|
|
59
|
+
/** One-shot notification after the scene that owns the world has entered, before warm-up. */
|
|
60
|
+
onStartSceneEntered: (() => void) | undefined;
|
|
61
|
+
paused: boolean;
|
|
62
|
+
/** The full `goto()` transition, including first-use warm-up, or undefined when none is. */
|
|
63
|
+
pendingSceneEnter: Promise<void> | undefined;
|
|
64
|
+
picker: ScenePicker | undefined;
|
|
65
|
+
pointerEvents: PointerEvents3D | undefined;
|
|
66
|
+
projection: SceneRenderProjection | undefined;
|
|
67
|
+
renderer: IRendererLike | undefined;
|
|
68
|
+
/** Flipped only by a diagnostics consumer announcing itself; see enableRuntimeDiagnostics(). */
|
|
69
|
+
renderMetricsEnabled: boolean;
|
|
70
|
+
resumeScene: string | undefined;
|
|
71
|
+
scene: Scene<TState, TPhysics> | undefined;
|
|
72
|
+
sceneEntered: boolean;
|
|
73
|
+
sceneFrame: SceneFrame<TState, TPhysics> | undefined;
|
|
74
|
+
/** Bumped on every scene change, so a row id is stable exactly as long as the scene is. */
|
|
75
|
+
sceneGeneration: number;
|
|
76
|
+
/**
|
|
77
|
+
* The name of the scene currently entered. Carried across a hot update so a reload resumes
|
|
78
|
+
* where the session was, instead of restoring the game's state into its start scene.
|
|
79
|
+
*/
|
|
80
|
+
sceneName: string | undefined;
|
|
81
|
+
scheduler: Scheduler | undefined;
|
|
82
|
+
started: boolean;
|
|
83
|
+
/** Startup readiness has begun its first-use gate; before that, it bakes the entered environment. */
|
|
84
|
+
startupGateStarted: boolean;
|
|
85
|
+
uiBridge: IUiBridge | undefined;
|
|
86
|
+
uiReady: boolean;
|
|
87
|
+
/** The loading cover has lifted and page UI may show state; see `UI_STARTUP_MESSAGE`. */
|
|
88
|
+
uiRevealed: boolean;
|
|
89
|
+
viewport: Viewport | undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The game's own calls a phase makes, bound to the game. */
|
|
93
|
+
export interface IBootHost<TState extends Record<string, unknown>, TPhysics> {
|
|
94
|
+
connectUi(): IUiBridge;
|
|
95
|
+
enterScene(scene: Scene<TState, TPhysics>, ctx: ICtx<TState, TPhysics>): boolean;
|
|
96
|
+
goto(name: string, ctx: ICtx<TState, TPhysics>): Promise<void>;
|
|
97
|
+
postUiStartup(): void;
|
|
98
|
+
teardown(): void;
|
|
99
|
+
warmUpConfiguredExplicitly(): boolean;
|
|
100
|
+
warmUpOptions(): IWarmUpOptions;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The game's own platform source, else the one a worker host installed on the global scope: worker
|
|
105
|
+
* mode runs the unchanged portable entry, so it cannot pass `platform` here (PRD-752).
|
|
106
|
+
*/
|
|
107
|
+
export interface IBootPlatform {
|
|
108
|
+
readonly platform: IGamePlatformSource | undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type IBootGame<TState extends Record<string, unknown>, TPhysics> = IBootHost<
|
|
112
|
+
TState,
|
|
113
|
+
TPhysics
|
|
114
|
+
> &
|
|
115
|
+
IBootPlatform &
|
|
116
|
+
IBootState<TState, TPhysics>;
|
|
117
|
+
|
|
118
|
+
/** What the frame loop and the scene-entry phase read from the game, and nothing else. */
|
|
119
|
+
export type ILoopPhase<TState extends Record<string, unknown>, TPhysics> = Pick<
|
|
120
|
+
IBootGame<TState, TPhysics>,
|
|
121
|
+
| "aborted"
|
|
122
|
+
| "activePlugins"
|
|
123
|
+
| "beforeRenderCallbacks"
|
|
124
|
+
| "beforeRenderDepth"
|
|
125
|
+
| "beforeRenderSnapshots"
|
|
126
|
+
| "cameraCull"
|
|
127
|
+
| "cleanup"
|
|
128
|
+
| "computeDriven"
|
|
129
|
+
| "config"
|
|
130
|
+
| "enterScene"
|
|
131
|
+
| "entities"
|
|
132
|
+
| "frameBudget"
|
|
133
|
+
| "geometryCapture"
|
|
134
|
+
| "hasDepthCoupledOutput"
|
|
135
|
+
| "input"
|
|
136
|
+
| "matrixWorld"
|
|
137
|
+
| "onStartSceneEntered"
|
|
138
|
+
| "paused"
|
|
139
|
+
| "pendingSceneEnter"
|
|
140
|
+
| "postUiStartup"
|
|
141
|
+
| "projection"
|
|
142
|
+
| "renderer"
|
|
143
|
+
| "renderMetricsEnabled"
|
|
144
|
+
| "scene"
|
|
145
|
+
| "sceneEntered"
|
|
146
|
+
| "sceneFrame"
|
|
147
|
+
| "sceneGeneration"
|
|
148
|
+
| "started"
|
|
149
|
+
| "startupGateStarted"
|
|
150
|
+
| "state"
|
|
151
|
+
| "teardown"
|
|
152
|
+
| "uiBridge"
|
|
153
|
+
| "uiRevealed"
|
|
154
|
+
| "warmUpConfiguredExplicitly"
|
|
155
|
+
| "warmUpOptions"
|
|
156
|
+
>;
|
|
157
|
+
|
|
158
|
+
/** What the startup phase reads and assigns: the loop's view, plus what only the world build touches. */
|
|
159
|
+
export type IBootPhase<TState extends Record<string, unknown>, TPhysics> = ILoopPhase<
|
|
160
|
+
TState,
|
|
161
|
+
TPhysics
|
|
162
|
+
> &
|
|
163
|
+
Pick<
|
|
164
|
+
IBootGame<TState, TPhysics>,
|
|
165
|
+
| "afterPhysicsPhase"
|
|
166
|
+
| "autoBatch"
|
|
167
|
+
| "connectUi"
|
|
168
|
+
| "ctx"
|
|
169
|
+
| "goto"
|
|
170
|
+
| "interpolation"
|
|
171
|
+
| "picker"
|
|
172
|
+
| "platform"
|
|
173
|
+
| "pointerEvents"
|
|
174
|
+
| "resumeScene"
|
|
175
|
+
| "sceneName"
|
|
176
|
+
| "scheduler"
|
|
177
|
+
| "uiReady"
|
|
178
|
+
| "viewport"
|
|
179
|
+
>;
|
|
180
|
+
|
|
181
|
+
/** The boot state at rest: nothing acquired, nothing paused, every flag down. */
|
|
182
|
+
export function createBootGame<TState extends Record<string, unknown>, TPhysics>(
|
|
183
|
+
input: Pick<IBootState<TState, TPhysics>, "config" | "state"> & IBootHost<TState, TPhysics>,
|
|
184
|
+
): IBootGame<TState, TPhysics> {
|
|
185
|
+
const { config } = input;
|
|
186
|
+
return {
|
|
187
|
+
...input,
|
|
188
|
+
activePlugins: [],
|
|
189
|
+
aborted: false,
|
|
190
|
+
afterPhysicsPhase: undefined,
|
|
191
|
+
autoBatch: undefined,
|
|
192
|
+
beforeRenderCallbacks: new Set(),
|
|
193
|
+
beforeRenderDepth: 0,
|
|
194
|
+
beforeRenderSnapshots: [],
|
|
195
|
+
cameraCull: undefined,
|
|
196
|
+
cleanup: [],
|
|
197
|
+
computeDriven: new ComputeDrivenRegistry(),
|
|
198
|
+
ctx: undefined,
|
|
199
|
+
entities: undefined,
|
|
200
|
+
frameBudget: undefined,
|
|
201
|
+
geometryCapture: undefined,
|
|
202
|
+
hasDepthCoupledOutput: false,
|
|
203
|
+
input: undefined,
|
|
204
|
+
interpolation: undefined,
|
|
205
|
+
matrixWorld: undefined,
|
|
206
|
+
onStartSceneEntered: undefined,
|
|
207
|
+
paused: false,
|
|
208
|
+
pendingSceneEnter: undefined,
|
|
209
|
+
picker: undefined,
|
|
210
|
+
get platform(): IGamePlatformSource | undefined {
|
|
211
|
+
return (
|
|
212
|
+
config.platform ??
|
|
213
|
+
(globalThis as { __tnGamePlatform?: IGamePlatformSource }).__tnGamePlatform
|
|
214
|
+
);
|
|
215
|
+
},
|
|
216
|
+
pointerEvents: undefined,
|
|
217
|
+
projection: undefined,
|
|
218
|
+
renderer: undefined,
|
|
219
|
+
renderMetricsEnabled: false,
|
|
220
|
+
resumeScene: undefined,
|
|
221
|
+
scene: undefined,
|
|
222
|
+
sceneEntered: false,
|
|
223
|
+
sceneFrame: undefined,
|
|
224
|
+
sceneGeneration: 0,
|
|
225
|
+
sceneName: undefined,
|
|
226
|
+
scheduler: undefined,
|
|
227
|
+
started: false,
|
|
228
|
+
startupGateStarted: false,
|
|
229
|
+
uiBridge: undefined,
|
|
230
|
+
uiReady: false,
|
|
231
|
+
uiRevealed: false,
|
|
232
|
+
viewport: undefined,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Runs every release even after one throws, and returns the failures in the order they came. */
|
|
237
|
+
export function runAll(releases: Iterable<() => void>): unknown[] {
|
|
238
|
+
const failures: unknown[] = [];
|
|
239
|
+
for (const release of releases) {
|
|
240
|
+
try {
|
|
241
|
+
release();
|
|
242
|
+
} catch (error) {
|
|
243
|
+
failures.push(error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return failures;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** The first failure is the original cause; a release throws that one after all have run. */
|
|
250
|
+
export function throwFirst(failures: readonly unknown[]): void {
|
|
251
|
+
if (failures.length > 0) throw failures[0];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Drains the cleanups, newest first, so a resource is released before anything it was built on.
|
|
256
|
+
* Each release that throws is collected and the rest still run.
|
|
257
|
+
*/
|
|
258
|
+
export function drainCleanup(cleanup: Array<() => void>): unknown[] {
|
|
259
|
+
return runAll(cleanup.splice(0).reverse());
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Empties the authored scene and everything it was reading from. */
|
|
263
|
+
export function clearScene(scene: ThreeScene, computeDriven: ComputeDrivenRegistry): void {
|
|
264
|
+
computeDriven.clear();
|
|
265
|
+
scene.clear();
|
|
266
|
+
scene.background = null;
|
|
267
|
+
scene.environment = null;
|
|
268
|
+
scene.fog = null;
|
|
269
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/// <reference path="./import-meta.d.ts" />
|
|
2
|
+
|
|
3
|
+
import { DEV_GLOBAL_KEY, type IDevTools, devGlobal } from "./dev-global.js";
|
|
4
|
+
import type { EntitySnapshot, Registry } from "./entities.js";
|
|
5
|
+
import type {
|
|
6
|
+
GeometryCapture,
|
|
7
|
+
IGeometryCaptureReport,
|
|
8
|
+
IGeometryCaptureRequest,
|
|
9
|
+
} from "./geometry-capture.js";
|
|
10
|
+
|
|
11
|
+
export type DevToolsHost = Record<string, unknown> &
|
|
12
|
+
Partial<Record<typeof DEV_GLOBAL_KEY, Partial<IDevTools>>>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The bundler's dev flag.
|
|
16
|
+
*
|
|
17
|
+
* The `import.meta.env` access must stay written out exactly here. Vite replaces that member
|
|
18
|
+
* expression at build time; any indirection — a variable holding `import.meta`, or a helper that
|
|
19
|
+
* takes it as an argument — survives into the bundle, where the game is compiled as a script and
|
|
20
|
+
* not a module, and the whole bundle then fails to parse with "Cannot use 'import.meta' outside a
|
|
21
|
+
* module". That is a game that never starts, so the literal access is load-bearing, not style.
|
|
22
|
+
*/
|
|
23
|
+
function bundlerDevFlag(): boolean {
|
|
24
|
+
return (import.meta as IImportMeta).env?.DEV === true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether this launch is a development one.
|
|
29
|
+
*
|
|
30
|
+
* A web build answers through Vite's own flag. A native build has no bundler flag at launch, so the
|
|
31
|
+
* host publishes `DEV_MODE` on `process.env` — the one place a game can read how it was started —
|
|
32
|
+
* and this reads it. Both routes answer the same question: should the dev surfaces exist.
|
|
33
|
+
*/
|
|
34
|
+
export function isDevLaunch(): boolean {
|
|
35
|
+
// `process.env` exists only where a host installed one: the native runtime does, a browser
|
|
36
|
+
// bundle does not. Narrowed rather than asserted, so a host that installs something else
|
|
37
|
+
// answers "not dev" instead of reading a field that is not there.
|
|
38
|
+
const scope: unknown = globalThis;
|
|
39
|
+
if (typeof scope === "object" && scope !== null && "process" in scope) {
|
|
40
|
+
const hostProcess: unknown = scope.process;
|
|
41
|
+
if (typeof hostProcess === "object" && hostProcess !== null && "env" in hostProcess) {
|
|
42
|
+
const env: unknown = hostProcess.env;
|
|
43
|
+
if (typeof env === "object" && env !== null && "DEV_MODE" in env) {
|
|
44
|
+
const flag: unknown = env.DEV_MODE;
|
|
45
|
+
if (typeof flag === "string" && flag !== "" && flag !== "0" && flag !== "false")
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return bundlerDevFlag();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function installDevTools(
|
|
54
|
+
entities: Registry,
|
|
55
|
+
host: DevToolsHost | undefined,
|
|
56
|
+
// Late-bound: the capture is constructed with the render loop, after this install runs.
|
|
57
|
+
geometry: () => GeometryCapture | undefined,
|
|
58
|
+
): () => void {
|
|
59
|
+
// Written out here, not through `isDevLaunch()`: the bundler must see the literal flag to strip
|
|
60
|
+
// this whole install from a production build, and a runtime `DEV_MODE` check cannot be stripped.
|
|
61
|
+
const isDev = (import.meta as IImportMeta).env?.DEV === true;
|
|
62
|
+
if (!isDev || host === undefined) return () => undefined;
|
|
63
|
+
const current = devGlobal(host) ?? {};
|
|
64
|
+
const devTools: IDevTools = {
|
|
65
|
+
...(current as Partial<IDevTools>),
|
|
66
|
+
geometry: async (request) => {
|
|
67
|
+
const capture = geometry();
|
|
68
|
+
if (capture === undefined) {
|
|
69
|
+
return {
|
|
70
|
+
reason: "TN_GEOMETRY_CAPTURE_NO_LOOP: the game has no running render loop to capture.",
|
|
71
|
+
status: "unavailable",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return capture.request(request);
|
|
75
|
+
},
|
|
76
|
+
snapshot: () => entities.snapshot(),
|
|
77
|
+
};
|
|
78
|
+
host[DEV_GLOBAL_KEY] = devTools;
|
|
79
|
+
return () => {
|
|
80
|
+
if (devGlobal(host) !== devTools) return;
|
|
81
|
+
const remaining = Object.fromEntries(
|
|
82
|
+
Object.entries(devTools).filter(([key]) => key !== "snapshot" && key !== "geometry"),
|
|
83
|
+
);
|
|
84
|
+
host[DEV_GLOBAL_KEY] = Object.keys(remaining).length === 0 ? undefined : remaining;
|
|
85
|
+
};
|
|
86
|
+
}
|