@threenative/core 0.3.11 → 0.3.12
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/capabilities.json +1096 -26
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-CWuFRT7G.d.ts} +1 -1
- package/dist/chunk-2Z44XSI2.js +35 -0
- package/dist/chunk-5O73CDMR.js +1849 -0
- package/dist/chunk-6KLNISRJ.js +153 -0
- package/dist/chunk-7UUT3TY5.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DBELTTTM.js +615 -0
- package/dist/chunk-GMHATRPW.js +7701 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-N5LRP4BR.js +220 -0
- package/dist/chunk-OKXUCASC.js +2238 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-VAZM36TV.js +497 -0
- package/dist/{game-DzMcitDO.d.ts → game-D7pAzZUY.d.ts} +15 -3
- package/dist/hot.d.ts +3 -3
- package/dist/hot.js +2 -46
- package/dist/index.d.ts +329 -302
- package/dist/index.js +10566 -22552
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-B6BMqS1r.d.ts} +33 -3
- package/dist/playtest.d.ts +3 -3
- package/dist/playtest.js +24 -75
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-DvFVoAgj.d.ts} +13 -4
- 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 +5 -384
- package/dist/worker.js +4 -41
- package/dist/world.d.ts +725 -259
- package/dist/world.js +16714 -18284
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +142 -47
- package/mcp/servers.mjs +9 -2
- package/mcp/terrain.mjs +8 -0
- package/package.json +14 -6
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/assets.ts +9 -2
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/frame-budget.ts +31 -20
- package/src/game-dev-tools.ts +93 -0
- package/src/game-frame-loop.ts +995 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1001 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +253 -1935
- package/src/index.ts +27 -2
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +24 -0
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quality.ts +10 -5
- package/src/look/world-environment.ts +76 -9
- package/src/loop.ts +29 -0
- package/src/model-lod.ts +42 -3
- package/src/particle-kinds.ts +515 -0
- package/src/picking.ts +17 -3
- package/src/playtest.ts +27 -1
- package/src/projection-apply.ts +4 -1
- package/src/projection-plan.ts +9 -6
- package/src/render/mesh-pool.ts +1 -1
- 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.ts +213 -992
- package/src/render/world-impostor-surface.ts +293 -34
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer.ts +92 -37
- package/src/snow-field.ts +1 -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-readiness.ts +128 -34
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/world-bundle-safety.ts +401 -0
- package/src/world-cell-batches.ts +1216 -0
- package/src/world-cell-chunks.ts +1132 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1449 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +189 -0
- package/src/world-cell-placements.ts +694 -0
- package/src/world-cell-prewarm.ts +557 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +714 -0
- package/src/world-cell-render-main-cull.ts +484 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +246 -0
- package/src/world-cell-render.ts +1493 -0
- package/src/world-cell-residency.ts +745 -0
- package/src/world-cells.ts +1318 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +163 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +510 -0
- package/src/world-gpu-scene.ts +214 -2264
- package/src/world-gpu-shadow.ts +190 -0
- package/src/world-gpu-types.ts +381 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +106 -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-terrain-splat.ts +365 -149
- package/src/world-tile-budget.ts +256 -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 +170 -1745
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +35 -741
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import type { Object3D } from "three";
|
|
2
|
+
import type { Material } from "three";
|
|
3
|
+
import { BundleGroup } from "three/webgpu";
|
|
4
|
+
import { lodChainOf } from "./model-lod.js";
|
|
5
|
+
import type { IRendererLike } from "./renderer.js";
|
|
6
|
+
import { markStatic } from "./static-transform.js";
|
|
7
|
+
import { BundleSurfaceSafety, bundleSafe, ownHook } from "./world-bundle-safety.js";
|
|
8
|
+
import type { SharedBatch } from "./world-cell-batches.js";
|
|
9
|
+
import type { IWorldCellsStats } from "./world-cell-data.js";
|
|
10
|
+
import { type IResidentCell, clusterOf } from "./world-cell-data.js";
|
|
11
|
+
import { chunkDraws } from "./world-cell-render-util.js";
|
|
12
|
+
import { mainShard } from "./world-cell-render-util.js";
|
|
13
|
+
import { CHUNK_NAME } from "./world-chunk-shadow.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The main pass's draw bundles: every recorded mesh parented under a shard's `BundleGroup`, every
|
|
17
|
+
* resident cell's hand-placed chunks under one of their own, and the version bookkeeping that makes
|
|
18
|
+
* a re-record a structural event and nothing else.
|
|
19
|
+
*
|
|
20
|
+
* A record is a render list three fixed when it made it, so this is the one part of the class that
|
|
21
|
+
* answers "did the set of things drawn change" rather than "what is drawn this frame": streaming,
|
|
22
|
+
* culling and LOD are the cull's and the dispatch's answer, and never bump a version.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** What a bundle record needs from the world it is recorded in. */
|
|
26
|
+
export interface ICellBundlesHost {
|
|
27
|
+
/** Add a group or a mesh to the world, which is where a chunk's record hangs. */
|
|
28
|
+
add(object: Object3D): void;
|
|
29
|
+
/** Whether the world itself is this object's parent, so a refused mesh still draws. */
|
|
30
|
+
isParent(object: Object3D): boolean;
|
|
31
|
+
/** Every shared batch, for the membership counts a settled frame reports. */
|
|
32
|
+
shared(): Map<string, SharedBatch>;
|
|
33
|
+
/** The renderer the last frame handed over, or `undefined` before the first one. */
|
|
34
|
+
renderer(): IRendererLike | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The three answers the load gave once, and every record reads. */
|
|
38
|
+
export interface ICellBundlesSettings {
|
|
39
|
+
readonly bundlesWanted: boolean;
|
|
40
|
+
readonly bundleReason: string;
|
|
41
|
+
readonly cellsPerCullCell: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class CellBundles {
|
|
45
|
+
readonly #host: ICellBundlesHost;
|
|
46
|
+
|
|
47
|
+
constructor(settings: ICellBundlesSettings, host: ICellBundlesHost) {
|
|
48
|
+
this.#host = host;
|
|
49
|
+
this.#bundlesWanted = settings.bundlesWanted;
|
|
50
|
+
this.#bundleReason = settings.bundleReason;
|
|
51
|
+
this.#cellsPerCullCell = settings.cellsPerCullCell;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The `BundleGroup`s every recorded main batch mesh is parented under, one per shard of
|
|
56
|
+
* {@link MAIN_BUNDLE_SHARDS}, and the number of times one has been re-recorded. A shard is minted by
|
|
57
|
+
* the first mesh that lands in it, so a world that never dresses a mesh has no group to pay for.
|
|
58
|
+
*
|
|
59
|
+
* A re-record is a structural change and nothing else: see `IWorldCellsStats.bundle` and
|
|
60
|
+
* {@link #bumpBundle}. Streaming, culling and LOD are GPU-side answers and never move it. A record
|
|
61
|
+
* walks every draw its group holds, so a mint pays for its own shard and not the whole main pass.
|
|
62
|
+
*/
|
|
63
|
+
readonly #bundleSafety = new BundleSurfaceSafety();
|
|
64
|
+
|
|
65
|
+
#ownsBundles: boolean | undefined;
|
|
66
|
+
|
|
67
|
+
readonly #bundles = new Map<number, BundleGroup>();
|
|
68
|
+
|
|
69
|
+
#bundleRecords = 0;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Shards re-recorded while a compile was in flight, so they are re-recorded again once it settles.
|
|
73
|
+
* Three encodes a draw only when its pipeline is ready, so a record cut during a `compileAsync`
|
|
74
|
+
* silently leaves a not-yet-ready draw out, and the replay never re-checks it. Bumped from
|
|
75
|
+
* {@link #bumpBundle} while {@link #compileBusy}, flushed at the top of the update that sees the
|
|
76
|
+
* compile settle.
|
|
77
|
+
*/
|
|
78
|
+
#compileSeen = 0;
|
|
79
|
+
|
|
80
|
+
#compileBusy = false;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The patched renderer's count of PMREM swaps, as of the last flush. A record holds the bind
|
|
84
|
+
* groups it was made with and a replay never refreshes them, so a sky that finishes after the
|
|
85
|
+
* first record would leave every recorded draw sampling the placeholder until a walk re-records.
|
|
86
|
+
*/
|
|
87
|
+
#pmremSwaps = 0;
|
|
88
|
+
|
|
89
|
+
readonly #recordedWhileBusy = new Set<BundleGroup>();
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* One `BundleGroup` per resident cell that has chunks attached, keyed by cell key, each with the
|
|
93
|
+
* main-cull cluster whose answer decides whether it is in the frame. Minted by the first chunk a
|
|
94
|
+
* cell attaches, so a world with no chunks pays nothing; see the `bundles` option.
|
|
95
|
+
*
|
|
96
|
+
* Per cell and not one group for the whole world: a record is fixed when it is made, so a group's
|
|
97
|
+
* own answer to "is this in view" cannot change without a re-record — which is the whole cost this
|
|
98
|
+
* is removing. A cell is the granularity the coarse cull already answers at, so `visible` on the
|
|
99
|
+
* group is a write rather than a record. See `#cullMainPass`.
|
|
100
|
+
*/
|
|
101
|
+
readonly #chunkBundles = new Map<
|
|
102
|
+
string,
|
|
103
|
+
{ readonly cluster: string; readonly group: BundleGroup }
|
|
104
|
+
>();
|
|
105
|
+
|
|
106
|
+
/** How many chunk roots those groups hold, so `stats().bundle.children` costs nothing to read. */
|
|
107
|
+
#chunkBundleChildren = 0;
|
|
108
|
+
|
|
109
|
+
/** `bundles` as the load asked for it, before the query string and the environment. */
|
|
110
|
+
readonly #bundlesWanted: boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Who decided that: the load that named `bundles`, the launch that asked for `off` or `on`, or
|
|
114
|
+
* nothing at all — which is what the marker reports so a run on the default is never mistaken for
|
|
115
|
+
* one a flag turned off. See {@link bundlesAsked}.
|
|
116
|
+
*/
|
|
117
|
+
readonly #bundleReason: string;
|
|
118
|
+
|
|
119
|
+
/** The square a cell's chunk record is answered at, which is the cull's own grid. */
|
|
120
|
+
readonly #cellsPerCullCell: number;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Parent one dressed main mesh under the world's single `BundleGroup`, so a settled frame replays
|
|
124
|
+
* its draw instead of re-walking three's per-object path for it.
|
|
125
|
+
*
|
|
126
|
+
* A mesh is shown once, here, and never hidden again: the bundle's render list is fixed when it is
|
|
127
|
+
* recorded, the dispatch already decided which instances each key draws, and an indirect draw of
|
|
128
|
+
* zero instances is close to free on the GPU — where a `visible` write would force the whole group
|
|
129
|
+
* to be recorded again. The prewarm draw this batch may still owe comes out of that same record.
|
|
130
|
+
*
|
|
131
|
+
* CPU joins and changed material revisions invalidate the record here, including a repaired mesh
|
|
132
|
+
* joining on a settled frame. GPU dressing invalidates its completed record at the caller.
|
|
133
|
+
*
|
|
134
|
+
* A mesh whose draw needs a live pass is refused rather than recorded — a transmissive impostor or
|
|
135
|
+
* a GPU batch reaching the framebuffer, the same answer a chunk's draws get. It keeps the per-object
|
|
136
|
+
* path and the coarse gate that hides it, which is the path it was already on. See `bundleSafe`.
|
|
137
|
+
*/
|
|
138
|
+
bundleIn(shared: SharedBatch, reuseSafety = false): void {
|
|
139
|
+
if (this.#bundlesWanted === false) return;
|
|
140
|
+
// Shared batches normally carry one material. A mutable array keeps the existing per-object path
|
|
141
|
+
// rather than compressing several material identities/revisions into an incomplete signature.
|
|
142
|
+
const arrayMaterial = Array.isArray(shared.mesh.material);
|
|
143
|
+
const checked =
|
|
144
|
+
reuseSafety && !arrayMaterial
|
|
145
|
+
? this.#bundleSafety.test(shared.mesh.material as Material, !this.ownsBundles())
|
|
146
|
+
: undefined;
|
|
147
|
+
shared.bundlable =
|
|
148
|
+
lodChainOf(shared.mesh.geometry) === undefined &&
|
|
149
|
+
(reuseSafety
|
|
150
|
+
? checked !== undefined &&
|
|
151
|
+
!ownHook(shared.mesh, "onBeforeRender") &&
|
|
152
|
+
!ownHook(shared.mesh, "onAfterRender") &&
|
|
153
|
+
Reflect.get(shared.mesh, "isSkinnedMesh") !== true &&
|
|
154
|
+
shared.mesh.morphTargetInfluences === undefined &&
|
|
155
|
+
checked.safe
|
|
156
|
+
: bundleSafe(shared.mesh));
|
|
157
|
+
if (shared.bundlable === false) {
|
|
158
|
+
if (shared.bundled) this.bundleOut(shared);
|
|
159
|
+
// A previously culled key may already be detached. Refusal still owes its live source draw.
|
|
160
|
+
if (!this.#host.isParent(shared.mesh)) this.#host.add(shared.mesh);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const group = this.shardOf(shared);
|
|
164
|
+
if (checked !== undefined) {
|
|
165
|
+
if (shared.bundled && shared.bundleMaterialRevision !== checked.revision)
|
|
166
|
+
this.bumpBundle(group);
|
|
167
|
+
shared.bundleMaterialRevision = checked.revision;
|
|
168
|
+
}
|
|
169
|
+
if (shared.mesh.parent !== group) {
|
|
170
|
+
group.add(shared.mesh);
|
|
171
|
+
if (reuseSafety) this.bumpBundle(group);
|
|
172
|
+
}
|
|
173
|
+
shared.bundled = true;
|
|
174
|
+
shared.bundledCount = shared.mesh.count;
|
|
175
|
+
// A recorded draw was cut from this camera's frustum, so the mesh's own whole-mesh test would drop
|
|
176
|
+
// it the moment the camera turned away from a window the record still holds. Off, like a chunk's.
|
|
177
|
+
shared.mesh.frustumCulled = false;
|
|
178
|
+
shared.mesh.visible = true;
|
|
179
|
+
// Read by `VirtualShadowNode#probe`, which must not hide a bundled mesh: the render list a bundle
|
|
180
|
+
// recorded is fixed, and `visible = false` would take the mesh out of every record after the next
|
|
181
|
+
// re-record. See `bundled`.
|
|
182
|
+
shared.mesh.userData.tnBundled = true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Take a mesh back out of the group, because the key it was minted under is leaving the world.
|
|
187
|
+
*
|
|
188
|
+
* A retire is a structural change — the recorded bundle still holds this render object, and
|
|
189
|
+
* replaying it would draw a key nothing owns — so it is one of the two events that re-records.
|
|
190
|
+
*/
|
|
191
|
+
bundleOut(shared: SharedBatch): void {
|
|
192
|
+
if (shared.bundled === false) return;
|
|
193
|
+
shared.bundled = false;
|
|
194
|
+
shared.bundledCount = -1;
|
|
195
|
+
shared.mesh.userData.tnBundled = false;
|
|
196
|
+
// Back on the per-object path, so the mesh's own whole-mesh test is its gate again.
|
|
197
|
+
shared.mesh.frustumCulled = true;
|
|
198
|
+
const group = this.#bundles.get(mainShard(shared.mesh.name));
|
|
199
|
+
if (group === undefined) return;
|
|
200
|
+
if (shared.mesh.parent === group) group.remove(shared.mesh);
|
|
201
|
+
this.bumpBundle(group);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Whether the renderer records its own bundles from each frame's draws, as the owned engine does
|
|
206
|
+
* (`info.engine`, the same check `game.ts` makes). Decided once a renderer is attached.
|
|
207
|
+
*/
|
|
208
|
+
ownsBundles(): boolean {
|
|
209
|
+
if (this.#ownsBundles !== undefined) return this.#ownsBundles;
|
|
210
|
+
const renderer = this.#host.renderer();
|
|
211
|
+
if (renderer === undefined) return false;
|
|
212
|
+
const info = (renderer.raw as { info?: object } | undefined)?.info;
|
|
213
|
+
this.#ownsBundles = info !== undefined && "engine" in info;
|
|
214
|
+
return this.#ownsBundles;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** One re-record, counted: `BundleGroup.needsUpdate` is a version bump, and nothing else. */
|
|
218
|
+
bumpBundle(group: BundleGroup): void {
|
|
219
|
+
this.#bundleRecords += 1;
|
|
220
|
+
group.needsUpdate = true;
|
|
221
|
+
if (this.#compileBusy) this.#recordedWhileBusy.add(group);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Put one CPU-path main batch into the world's record, or take it out, by the coarse gate's answer.
|
|
226
|
+
*
|
|
227
|
+
* A main batch the GPU scene dresses is recorded from `#dressGpu`, because its submission bound is
|
|
228
|
+
* its key's region capacity — a number only the dress writes, so the entry cannot go stale. A batch
|
|
229
|
+
* the scene does not own submits its own CPU window instead, and that window is per frame: the gate
|
|
230
|
+
* narrows it, a residency change repacks it, and a batch it narrows to nothing must draw nothing.
|
|
231
|
+
* A record fixes its render list, so all three are the record's business rather than a `visible`
|
|
232
|
+
* write the replay ignores. Hence this: the gate's answer is a join or a leave, a window that moved
|
|
233
|
+
* or a count that changed is one more record, and `frustumCulled` is off because the record's own
|
|
234
|
+
* list was cut by the same frustum when it was made.
|
|
235
|
+
*
|
|
236
|
+
* The trade is the one a cell's chunk record already makes and the visual A/B already judged: a
|
|
237
|
+
* batch whose window is half the view draws the half that faced the camera when the record was cut.
|
|
238
|
+
*/
|
|
239
|
+
recordCpuMain(shared: SharedBatch, outcome: "settled" | "narrowed" | "repacked"): void {
|
|
240
|
+
if (this.#bundlesWanted === false) return;
|
|
241
|
+
// `#publish` has just written this frame's answer onto the mesh, which is the only place it is.
|
|
242
|
+
if (shared.mesh.visible === false) {
|
|
243
|
+
this.bundleOut(shared);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
this.bundleIn(shared, true);
|
|
247
|
+
if (shared.bundled === false) return;
|
|
248
|
+
// The count a record freezes, and the layout behind it: a repack moves records inside the window
|
|
249
|
+
// without moving its length, so the epoch answer and the count are both read here.
|
|
250
|
+
if (outcome === "settled" && shared.mesh.count === shared.bundledCount) return;
|
|
251
|
+
shared.bundledCount = shared.mesh.count;
|
|
252
|
+
this.bumpBundle(this.shardOf(shared));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Attach one prepared chunk: to its cell's own record, or to the world when `bundles` is off.
|
|
257
|
+
*
|
|
258
|
+
* The group is minted with the first chunk the cell attaches, and a chunk added to it is a
|
|
259
|
+
* structural change — the recorded list does not hold this render object and the replay would draw
|
|
260
|
+
* the cell's chunks without it — so this is also the one re-record. See the `bundles` option for
|
|
261
|
+
* why the group is per cell.
|
|
262
|
+
*
|
|
263
|
+
* Only the draws a bundle can replay are recorded, and they carry the `tnBundled` marker and the
|
|
264
|
+
* frozen cull with them; the rest keep the per-object path. See `bundleSafe`.
|
|
265
|
+
*/
|
|
266
|
+
addChunk(cell: IResidentCell, chunk: Object3D): void {
|
|
267
|
+
if (this.#bundlesWanted === false) {
|
|
268
|
+
this.#host.add(chunk);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
// What the record can hold, and whether anything had to be left behind. A chunk whose every draw
|
|
272
|
+
// is recorded goes in whole, which is one entry per chunk; a chunk holding a draw a bundle cannot
|
|
273
|
+
// replay stays in the world and hands its safe draws to the record on their own, so one glass
|
|
274
|
+
// window does not put the whole building back on the per-object path. See `bundleSafe`.
|
|
275
|
+
const draws = chunkDraws(chunk);
|
|
276
|
+
const recorded = draws.filter(
|
|
277
|
+
(mesh) => lodChainOf(mesh.geometry) === undefined && bundleSafe(mesh),
|
|
278
|
+
);
|
|
279
|
+
if (recorded.length === 0) {
|
|
280
|
+
this.#host.add(chunk);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
let entry = this.#chunkBundles.get(cell.key);
|
|
284
|
+
if (entry === undefined) {
|
|
285
|
+
const group = new BundleGroup();
|
|
286
|
+
group.name = `${CHUNK_NAME}-bundles:${cell.key}`;
|
|
287
|
+
this.#host.add(group);
|
|
288
|
+
entry = { cluster: clusterOf(cell.x, cell.z, this.#cellsPerCullCell), group };
|
|
289
|
+
this.#chunkBundles.set(cell.key, entry);
|
|
290
|
+
}
|
|
291
|
+
const whole = recorded.length === draws.length;
|
|
292
|
+
if (whole) entry.group.add(chunk);
|
|
293
|
+
else {
|
|
294
|
+
// The chunk keeps its own hierarchy around whatever it could not record, and each recorded
|
|
295
|
+
// draw is attached rather than added so it keeps the world transform it was merged at. The root
|
|
296
|
+
// it came out of travels with it, because that is what releases the draw again.
|
|
297
|
+
this.#host.add(chunk);
|
|
298
|
+
for (const mesh of recorded) {
|
|
299
|
+
mesh.userData.tnChunkRoot = chunk;
|
|
300
|
+
entry.group.attach(mesh);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// A recorded draw is frozen where it stands: the group is a child of the world at identity, so
|
|
304
|
+
// its matrix will never move, and the freeze is what lets three's settled-object path skip the
|
|
305
|
+
// per-object work for the draw a frame is not re-recording anyway. See `markStatic`.
|
|
306
|
+
for (const mesh of recorded) {
|
|
307
|
+
mesh.userData.tnBundled = true;
|
|
308
|
+
mesh.frustumCulled = false;
|
|
309
|
+
if (whole === false) markStatic(mesh);
|
|
310
|
+
}
|
|
311
|
+
this.#chunkBundleChildren += whole ? 1 : recorded.length;
|
|
312
|
+
this.bumpBundle(entry.group);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Take a cell's chunk record out of the world, because the cell that owned every chunk in it has
|
|
317
|
+
* left: a record nothing owns must not be replayed, and the cell coming back mints its own.
|
|
318
|
+
*
|
|
319
|
+
* A chunk the bake split left its recorded draws in the group rather than under their own root, so
|
|
320
|
+
* each goes back to the root it came out of first: the caller's own disposal walk finds them there,
|
|
321
|
+
* and a draw released by neither is a buffer nothing ever asks for again.
|
|
322
|
+
*/
|
|
323
|
+
dropChunkBundles(cell: IResidentCell): void {
|
|
324
|
+
const entry = this.#chunkBundles.get(cell.key);
|
|
325
|
+
if (entry === undefined) return;
|
|
326
|
+
this.#chunkBundles.delete(cell.key);
|
|
327
|
+
const roots = new Set(cell.chunks);
|
|
328
|
+
// Counted before anything leaves the group, because that is what it is holding.
|
|
329
|
+
this.#chunkBundleChildren -= entry.group.children.length;
|
|
330
|
+
for (const child of entry.group.children) {
|
|
331
|
+
const root = child.userData.tnChunkRoot as Object3D | undefined;
|
|
332
|
+
if (roots.has(child) === false && root !== undefined) {
|
|
333
|
+
child.userData.tnChunkRoot = undefined;
|
|
334
|
+
root.attach(child);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
entry.group.removeFromParent();
|
|
338
|
+
this.bumpBundle(entry.group);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** The main-record shard a batch's key lands in, minted as a child of the world on first use. */
|
|
342
|
+
shardOf(shared: SharedBatch): BundleGroup {
|
|
343
|
+
const shard = mainShard(shared.mesh.name);
|
|
344
|
+
let group = this.#bundles.get(shard);
|
|
345
|
+
if (group === undefined) {
|
|
346
|
+
group = new BundleGroup();
|
|
347
|
+
group.name = "world-main-bundles";
|
|
348
|
+
this.#host.add(group);
|
|
349
|
+
this.#bundles.set(shard, group);
|
|
350
|
+
}
|
|
351
|
+
return group;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The recorded main batches, over every shard. */
|
|
355
|
+
mainBundleChildren(): number {
|
|
356
|
+
let children = 0;
|
|
357
|
+
for (const group of this.#bundles.values()) children += group.children.length;
|
|
358
|
+
return children;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Where a freshly bound or grown main batch's mesh goes: the bundle group when it has been dressed
|
|
363
|
+
* into one, the world otherwise. Three re-parents on `add`, so a bundled mesh has to be asked for
|
|
364
|
+
* or it silently leaves the group it was recorded in.
|
|
365
|
+
*/
|
|
366
|
+
attach(shared: SharedBatch): void {
|
|
367
|
+
// A grow replaces the mesh object, so the marker `#bundleIn` set has to follow the batch's own
|
|
368
|
+
// flag onto it. See `bundled`.
|
|
369
|
+
shared.mesh.userData.tnBundled = shared.bundled;
|
|
370
|
+
if (shared.bundled === true) this.shardOf(shared).add(shared.mesh);
|
|
371
|
+
else this.#host.add(shared.mesh);
|
|
372
|
+
// A record holds the object it was cut from, so a mesh that arrived by a rebind or a grow is not
|
|
373
|
+
// the one the last record named: one re-record, and the record counts this mesh from here.
|
|
374
|
+
if (shared.bundled === true) {
|
|
375
|
+
shared.mesh.frustumCulled = false;
|
|
376
|
+
shared.bundledCount = shared.mesh.count;
|
|
377
|
+
this.bumpBundle(this.shardOf(shared));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
bundleGroup(shard: number): BundleGroup | undefined {
|
|
382
|
+
return this.#bundles.get(shard);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
clearCompileRecords(): void {
|
|
386
|
+
this.#recordedWhileBusy.clear();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
invalidateBundles(key: string): void {
|
|
390
|
+
for (const group of this.#bundles.values()) this.bumpBundle(group);
|
|
391
|
+
const chunks = this.#chunkBundles.get(key)?.group;
|
|
392
|
+
if (chunks !== undefined) this.bumpBundle(chunks);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
bundleStats(): IWorldCellsStats["bundle"] {
|
|
396
|
+
return {
|
|
397
|
+
children: this.mainBundleChildren() + this.#chunkBundleChildren,
|
|
398
|
+
on: this.#bundlesWanted && (this.mainBundleChildren() > 0 || this.#chunkBundleChildren > 0),
|
|
399
|
+
cpuMeshes: [...this.#host.shared().values()].filter(
|
|
400
|
+
(shared) => shared.bundled && shared.gpu === undefined,
|
|
401
|
+
).length,
|
|
402
|
+
gpuMeshes: [...this.#host.shared().values()].filter(
|
|
403
|
+
(shared) => shared.bundled && shared.gpu !== undefined,
|
|
404
|
+
).length,
|
|
405
|
+
eligibility: { ...this.#bundleSafety.stats },
|
|
406
|
+
reason: this.#bundleReason,
|
|
407
|
+
records: this.#bundleRecords,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
#rerecordOnPmremSwap(raw: unknown): void {
|
|
412
|
+
const swaps = typeof raw === "object" && raw !== null ? Reflect.get(raw, "_tnPmremSwaps") : 0;
|
|
413
|
+
if (typeof swaps !== "number" || swaps === this.#pmremSwaps) return;
|
|
414
|
+
this.#pmremSwaps = swaps;
|
|
415
|
+
for (const group of this.#bundles.values()) this.bumpBundle(group);
|
|
416
|
+
for (const { group } of this.#chunkBundles.values()) this.bumpBundle(group);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
flushCompiles(renderer: IRendererLike | undefined): void {
|
|
420
|
+
// A bundle recorded while a compile was in flight left out every draw whose pipeline was not
|
|
421
|
+
// ready, and the replay never re-checks; re-record those shards now that it has settled. Set
|
|
422
|
+
// `#compileBusy` first, so this flush's own bumps are not added back to the set.
|
|
423
|
+
const compiles = renderer?.compileCount ?? 0;
|
|
424
|
+
const busy = renderer?.compiling === true || compiles !== this.#compileSeen;
|
|
425
|
+
this.#compileSeen = compiles;
|
|
426
|
+
this.#compileBusy = busy;
|
|
427
|
+
this.#rerecordOnPmremSwap(renderer?.raw);
|
|
428
|
+
if (!busy && this.#recordedWhileBusy.size > 0) {
|
|
429
|
+
const recorded = [...this.#recordedWhileBusy];
|
|
430
|
+
this.#recordedWhileBusy.clear();
|
|
431
|
+
for (const group of recorded) if (group.parent !== null) this.bumpBundle(group);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Whether the load asked for bundles at all, before a flag or a backend answered. */
|
|
436
|
+
get wanted(): boolean {
|
|
437
|
+
return this.#bundlesWanted;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Who decided that: the load's own option, a launch flag, or the default. */
|
|
441
|
+
get reason(): string {
|
|
442
|
+
return this.#bundleReason;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Every resident cell's chunk record, with the cull square whose answer shows or hides it. */
|
|
446
|
+
chunkGroups(): Map<string, { readonly cluster: string; readonly group: BundleGroup }> {
|
|
447
|
+
return this.#chunkBundles;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** Reset the per-frame eligibility counters at the top of a cull pass. */
|
|
451
|
+
beginFrame(): void {
|
|
452
|
+
this.#bundleSafety.beginFrame();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Drop the surface-safety proofs, which a lost device makes stale. */
|
|
456
|
+
release(): void {
|
|
457
|
+
this.#bundleSafety.clear();
|
|
458
|
+
}
|
|
459
|
+
}
|