@drawcall/lod 0.2.0 → 0.4.0
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 +6 -7
- package/dist/bake.d.ts +36 -0
- package/dist/bake.js +176 -0
- package/dist/bake.js.map +1 -0
- package/dist/baked/codec.d.ts +3 -6
- package/dist/baked/codec.js +48 -154
- package/dist/baked/codec.js.map +1 -1
- package/dist/baked/coverage.d.ts +6 -3
- package/dist/baked/coverage.js +6 -3
- package/dist/baked/coverage.js.map +1 -1
- package/dist/baked/fields.d.ts +9 -0
- package/dist/baked/fields.js +22 -0
- package/dist/baked/fields.js.map +1 -0
- package/dist/baked/index.d.ts +14 -8
- package/dist/baked/index.js +24 -22
- package/dist/baked/index.js.map +1 -1
- package/dist/baked/interior/faces.d.ts +4 -3
- package/dist/baked/interior/faces.js +16 -11
- package/dist/baked/interior/faces.js.map +1 -1
- package/dist/baked/interior/material.d.ts +7 -10
- package/dist/baked/interior/material.js +29 -36
- package/dist/baked/interior/material.js.map +1 -1
- package/dist/baked/interior/rooms.d.ts +1 -1
- package/dist/baked/interior/rooms.js +2 -2
- package/dist/baked/interior/rooms.js.map +1 -1
- package/dist/baked/low.js +5 -4
- package/dist/baked/low.js.map +1 -1
- package/dist/baked/raster.js +6 -6
- package/dist/baked/raster.js.map +1 -1
- package/dist/baked/textures.d.ts +17 -0
- package/dist/baked/textures.js +95 -0
- package/dist/baked/textures.js.map +1 -0
- package/dist/baked/transfer.js +19 -18
- package/dist/baked/transfer.js.map +1 -1
- package/dist/baked/unwrap.js +4 -3
- package/dist/baked/unwrap.js.map +1 -1
- package/dist/baked/xatlas.js.map +1 -1
- package/dist/codec/container.d.ts +8 -0
- package/dist/codec/container.js +63 -0
- package/dist/codec/container.js.map +1 -0
- package/dist/codec/mesh.d.ts +8 -0
- package/dist/{mesh/codec.js → codec/mesh.js} +80 -52
- package/dist/codec/mesh.js.map +1 -0
- package/dist/dispose.d.ts +8 -5
- package/dist/dispose.js +22 -24
- package/dist/dispose.js.map +1 -1
- package/dist/foliage.d.ts +32 -0
- package/dist/foliage.js +137 -0
- package/dist/foliage.js.map +1 -0
- package/dist/impostor/bake/atlas.d.ts +4 -4
- package/dist/impostor/bake/atlas.js +12 -12
- package/dist/impostor/bake/atlas.js.map +1 -1
- package/dist/impostor/bake/fit.d.ts +8 -0
- package/dist/impostor/bake/fit.js +28 -0
- package/dist/impostor/bake/fit.js.map +1 -0
- package/dist/impostor/bake/index.d.ts +22 -14
- package/dist/impostor/bake/index.js +50 -134
- package/dist/impostor/bake/index.js.map +1 -1
- package/dist/impostor/bake/materials.d.ts +3 -3
- package/dist/impostor/bake/materials.js +51 -13
- package/dist/impostor/bake/materials.js.map +1 -1
- package/dist/impostor/bake/sheet.d.ts +8 -0
- package/dist/impostor/bake/sheet.js +90 -0
- package/dist/impostor/bake/sheet.js.map +1 -0
- package/dist/impostor/bake/source.d.ts +3 -2
- package/dist/impostor/bake/source.js +9 -20
- package/dist/impostor/bake/source.js.map +1 -1
- package/dist/impostor/codec.d.ts +4 -5
- package/dist/impostor/codec.js +36 -109
- package/dist/impostor/codec.js.map +1 -1
- package/dist/impostor/impostor.d.ts +31 -7
- package/dist/impostor/impostor.js +21 -6
- package/dist/impostor/impostor.js.map +1 -1
- package/dist/impostor/ktx2/encode.d.ts +26 -0
- package/dist/impostor/ktx2/encode.js +120 -0
- package/dist/impostor/ktx2/encode.js.map +1 -0
- package/dist/impostor/ktx2/transcode.d.ts +3 -0
- package/dist/impostor/ktx2/transcode.js +99 -0
- package/dist/impostor/ktx2/transcode.js.map +1 -0
- package/dist/impostor/ktx2/uastc.d.ts +7 -0
- package/dist/impostor/ktx2/uastc.js +65 -0
- package/dist/impostor/ktx2/uastc.js.map +1 -0
- package/dist/impostor/ktx2/wasm/encoder.d.ts +4 -0
- package/dist/impostor/ktx2/wasm/encoder.js +10 -0
- package/dist/impostor/ktx2/wasm/encoder.js.map +1 -0
- package/dist/impostor/ktx2/wasm/transcoder.d.ts +3 -0
- package/dist/impostor/ktx2/wasm/transcoder.js +9 -0
- package/dist/impostor/ktx2/wasm/transcoder.js.map +1 -0
- package/dist/impostor/ktx2/worker.d.ts +1 -0
- package/dist/impostor/ktx2/worker.js +10 -0
- package/dist/impostor/ktx2/worker.js.map +1 -0
- package/dist/impostor/mesh/card.d.ts +4 -4
- package/dist/impostor/mesh/card.js +7 -7
- package/dist/impostor/mesh/card.js.map +1 -1
- package/dist/impostor/mesh/index.d.ts +7 -6
- package/dist/impostor/mesh/index.js +10 -11
- package/dist/impostor/mesh/index.js.map +1 -1
- package/dist/impostor/mesh/material.d.ts +18 -9
- package/dist/impostor/mesh/material.js +40 -27
- package/dist/impostor/mesh/material.js.map +1 -1
- package/dist/impostor/mesh/surface.d.ts +1 -1
- package/dist/impostor/mesh/surface.js +13 -9
- package/dist/impostor/mesh/surface.js.map +1 -1
- package/dist/impostor/mesh/textures.d.ts +3 -3
- package/dist/impostor/mesh/textures.js +24 -34
- package/dist/impostor/mesh/textures.js.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/instanced/camera.d.ts +34 -0
- package/dist/instanced/camera.js +45 -0
- package/dist/instanced/camera.js.map +1 -0
- package/dist/instanced/clusters.d.ts +54 -0
- package/dist/instanced/clusters.js +151 -0
- package/dist/instanced/clusters.js.map +1 -0
- package/dist/instanced/cull.d.ts +28 -0
- package/dist/instanced/cull.js +22 -0
- package/dist/instanced/cull.js.map +1 -0
- package/dist/instanced/instances.d.ts +39 -0
- package/dist/instanced/instances.js +104 -0
- package/dist/instanced/instances.js.map +1 -0
- package/dist/instanced/key.d.ts +19 -0
- package/dist/instanced/key.js +45 -0
- package/dist/instanced/key.js.map +1 -0
- package/dist/instanced/levels.d.ts +60 -0
- package/dist/instanced/levels.js +131 -0
- package/dist/instanced/levels.js.map +1 -0
- package/dist/instanced/lists.d.ts +57 -0
- package/dist/instanced/lists.js +114 -0
- package/dist/instanced/lists.js.map +1 -0
- package/dist/instanced/measure.d.ts +28 -0
- package/dist/instanced/measure.js +203 -0
- package/dist/instanced/measure.js.map +1 -0
- package/dist/instanced/meshes.d.ts +44 -51
- package/dist/instanced/meshes.js +167 -179
- package/dist/instanced/meshes.js.map +1 -1
- package/dist/instanced/mirror.d.ts +24 -0
- package/dist/instanced/mirror.js +76 -0
- package/dist/instanced/mirror.js.map +1 -0
- package/dist/instanced/raycast.d.ts +10 -11
- package/dist/instanced/raycast.js +31 -41
- package/dist/instanced/raycast.js.map +1 -1
- package/dist/instanced/rows.d.ts +50 -0
- package/dist/instanced/rows.js +36 -0
- package/dist/instanced/rows.js.map +1 -0
- package/dist/instanced/shape.d.ts +27 -0
- package/dist/instanced/shape.js +54 -0
- package/dist/instanced/shape.js.map +1 -0
- package/dist/instanced/sort.d.ts +61 -0
- package/dist/instanced/sort.js +192 -0
- package/dist/instanced/sort.js.map +1 -0
- package/dist/instanced/update.d.ts +34 -0
- package/dist/instanced/update.js +180 -0
- package/dist/instanced/update.js.map +1 -0
- package/dist/levels/bounds.d.ts +21 -0
- package/dist/levels/bounds.js +42 -0
- package/dist/levels/bounds.js.map +1 -0
- package/dist/levels/cameras.d.ts +48 -0
- package/dist/levels/cameras.js +122 -0
- package/dist/levels/cameras.js.map +1 -0
- package/dist/levels/compile/contexts.d.ts +30 -0
- package/dist/levels/compile/contexts.js +18 -0
- package/dist/levels/compile/contexts.js.map +1 -0
- package/dist/levels/compile/index.d.ts +41 -0
- package/dist/levels/compile/index.js +193 -0
- package/dist/levels/compile/index.js.map +1 -0
- package/dist/levels/compile/pipelines.d.ts +26 -0
- package/dist/levels/compile/pipelines.js +172 -0
- package/dist/levels/compile/pipelines.js.map +1 -0
- package/dist/levels/compiles.d.ts +29 -0
- package/dist/levels/compiles.js +50 -0
- package/dist/levels/compiles.js.map +1 -0
- package/dist/levels/draw.d.ts +102 -0
- package/dist/levels/draw.js +401 -0
- package/dist/levels/draw.js.map +1 -0
- package/dist/levels/fade.d.ts +60 -0
- package/dist/levels/fade.js +129 -0
- package/dist/levels/fade.js.map +1 -0
- package/dist/levels/index.d.ts +99 -0
- package/dist/levels/index.js +155 -0
- package/dist/levels/index.js.map +1 -0
- package/dist/levels/item.d.ts +38 -0
- package/dist/levels/item.js +89 -0
- package/dist/levels/item.js.map +1 -0
- package/dist/levels/load.d.ts +31 -0
- package/dist/levels/load.js +144 -0
- package/dist/levels/load.js.map +1 -0
- package/dist/levels/manager.d.ts +158 -0
- package/dist/levels/manager.js +352 -0
- package/dist/levels/manager.js.map +1 -0
- package/dist/{material.d.ts → levels/material.d.ts} +2 -2
- package/dist/{material.js → levels/material.js} +6 -5
- package/dist/levels/material.js.map +1 -0
- package/dist/levels/renderer.d.ts +32 -0
- package/dist/levels/renderer.js +57 -0
- package/dist/levels/renderer.js.map +1 -0
- package/dist/levels/requests.d.ts +52 -0
- package/dist/levels/requests.js +97 -0
- package/dist/levels/requests.js.map +1 -0
- package/dist/levels/screen.d.ts +14 -0
- package/dist/levels/screen.js +21 -0
- package/dist/levels/screen.js.map +1 -0
- package/dist/loader/build.d.ts +10 -0
- package/dist/loader/build.js +28 -0
- package/dist/loader/build.js.map +1 -0
- package/dist/loader/context.d.ts +44 -0
- package/dist/loader/context.js +96 -0
- package/dist/loader/context.js.map +1 -0
- package/dist/loader/entry.d.ts +4 -0
- package/dist/loader/entry.js +43 -0
- package/dist/loader/entry.js.map +1 -0
- package/dist/loader/index.d.ts +76 -0
- package/dist/loader/index.js +272 -0
- package/dist/loader/index.js.map +1 -0
- package/dist/loader/level.d.ts +41 -0
- package/dist/loader/level.js +140 -0
- package/dist/loader/level.js.map +1 -0
- package/dist/loader/node.d.ts +26 -0
- package/dist/loader/node.js +199 -0
- package/dist/loader/node.js.map +1 -0
- package/dist/loader/request.d.ts +54 -0
- package/dist/loader/request.js +19 -0
- package/dist/loader/request.js.map +1 -0
- package/dist/loader/url.d.ts +10 -6
- package/dist/loader/url.js +22 -14
- package/dist/loader/url.js.map +1 -1
- package/dist/lod.d.ts +144 -43
- package/dist/lod.js +354 -163
- package/dist/lod.js.map +1 -1
- package/dist/meshopt.d.ts +6 -0
- package/dist/meshopt.js +20 -0
- package/dist/meshopt.js.map +1 -0
- package/dist/node-process.d.ts +5 -0
- package/dist/node-process.js +6 -0
- package/dist/node-process.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.js +5 -0
- package/dist/node.js.map +1 -0
- package/dist/simplify/cards.d.ts +14 -0
- package/dist/simplify/cards.js +128 -0
- package/dist/simplify/cards.js.map +1 -0
- package/dist/{simplify.d.ts → simplify/index.d.ts} +8 -5
- package/dist/{simplify.js → simplify/index.js} +45 -27
- package/dist/simplify/index.js.map +1 -0
- package/dist/{bounds.d.ts → source/detail.d.ts} +9 -23
- package/dist/{bounds.js → source/detail.js} +28 -58
- package/dist/source/detail.js.map +1 -0
- package/dist/source/deviation.js +6 -6
- package/dist/source/deviation.js.map +1 -1
- package/dist/source/{shading.d.ts → evaluator.d.ts} +10 -10
- package/dist/source/{shading.js → evaluator.js} +5 -5
- package/dist/source/evaluator.js.map +1 -0
- package/dist/source/{trace.d.ts → raycaster.d.ts} +6 -6
- package/dist/source/{trace.js → raycaster.js} +8 -8
- package/dist/source/raycaster.js.map +1 -0
- package/dist/source/{texels.d.ts → sampler.d.ts} +1 -1
- package/dist/source/{texels.js → sampler.js} +8 -5
- package/dist/source/sampler.js.map +1 -0
- package/dist/source/source.d.ts +1 -1
- package/dist/source/source.js +1 -1
- package/dist/source/source.js.map +1 -1
- package/dist/source/surface.js +1 -1
- package/dist/source/surface.js.map +1 -1
- package/dist/task.d.ts +6 -0
- package/dist/{pause.js → task.js} +5 -5
- package/dist/task.js.map +1 -0
- package/dist/three.d.ts +19 -30
- package/dist/three.js +30 -57
- package/dist/three.js.map +1 -1
- package/dist/tsl.d.ts +8 -12
- package/dist/tsl.js +11 -39
- package/dist/tsl.js.map +1 -1
- package/dist/typegpu.d.ts +37 -0
- package/dist/typegpu.js +37 -0
- package/dist/typegpu.js.map +1 -0
- package/dist/wind/bounds.js +3 -3
- package/dist/wind/bounds.js.map +1 -1
- package/dist/wind/hooks.d.ts +7 -4
- package/dist/wind/hooks.js +5 -2
- package/dist/wind/hooks.js.map +1 -1
- package/dist/wind/index.d.ts +4 -4
- package/dist/wind/index.js +25 -23
- package/dist/wind/index.js.map +1 -1
- package/dist/wind/sway.d.ts +2 -0
- package/dist/wind/sway.js +4 -1
- package/dist/wind/sway.js.map +1 -1
- package/package.json +24 -10
- package/skills/lod/SKILL.md +120 -32
- package/dist/bounds.js.map +0 -1
- package/dist/compile.d.ts +0 -4
- package/dist/compile.js +0 -100
- package/dist/compile.js.map +0 -1
- package/dist/deferred.d.ts +0 -12
- package/dist/deferred.js +0 -27
- package/dist/deferred.js.map +0 -1
- package/dist/fade.d.ts +0 -36
- package/dist/fade.js +0 -112
- package/dist/fade.js.map +0 -1
- package/dist/instanced/args.d.ts +0 -20
- package/dist/instanced/args.js +0 -77
- package/dist/instanced/args.js.map +0 -1
- package/dist/instanced/blocks.d.ts +0 -66
- package/dist/instanced/blocks.js +0 -294
- package/dist/instanced/blocks.js.map +0 -1
- package/dist/instanced/dirty.d.ts +0 -15
- package/dist/instanced/dirty.js +0 -96
- package/dist/instanced/dirty.js.map +0 -1
- package/dist/instanced/index.d.ts +0 -90
- package/dist/instanced/index.js +0 -349
- package/dist/instanced/index.js.map +0 -1
- package/dist/instanced/parts.d.ts +0 -14
- package/dist/instanced/parts.js +0 -79
- package/dist/instanced/parts.js.map +0 -1
- package/dist/instanced/select.d.ts +0 -92
- package/dist/instanced/select.js +0 -315
- package/dist/instanced/select.js.map +0 -1
- package/dist/instanced/store.d.ts +0 -31
- package/dist/instanced/store.js +0 -96
- package/dist/instanced/store.js.map +0 -1
- package/dist/levels.d.ts +0 -95
- package/dist/levels.js +0 -171
- package/dist/levels.js.map +0 -1
- package/dist/loader/bundle.d.ts +0 -25
- package/dist/loader/bundle.js +0 -241
- package/dist/loader/bundle.js.map +0 -1
- package/dist/loader/cache.d.ts +0 -15
- package/dist/loader/cache.js +0 -75
- package/dist/loader/cache.js.map +0 -1
- package/dist/loader/provenance.d.ts +0 -30
- package/dist/loader/provenance.js +0 -105
- package/dist/loader/provenance.js.map +0 -1
- package/dist/loader.d.ts +0 -55
- package/dist/loader.js +0 -239
- package/dist/loader.js.map +0 -1
- package/dist/material.js.map +0 -1
- package/dist/mesh/codec.d.ts +0 -4
- package/dist/mesh/codec.js.map +0 -1
- package/dist/pause.d.ts +0 -6
- package/dist/pause.js.map +0 -1
- package/dist/queue.d.ts +0 -2
- package/dist/queue.js +0 -33
- package/dist/queue.js.map +0 -1
- package/dist/renderer.d.ts +0 -21
- package/dist/renderer.js +0 -83
- package/dist/renderer.js.map +0 -1
- package/dist/residency.d.ts +0 -44
- package/dist/residency.js +0 -205
- package/dist/residency.js.map +0 -1
- package/dist/simplify.js.map +0 -1
- package/dist/source/shading.js.map +0 -1
- package/dist/source/texels.js.map +0 -1
- package/dist/source/trace.js.map +0 -1
- package/dist/view.d.ts +0 -45
- package/dist/view.js +0 -131
- package/dist/view.js.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Camera, Object3D, Object3DEventMap, Renderer } from "three/webgpu";
|
|
2
|
+
import type { d } from "typegpu";
|
|
3
|
+
import { type DrawLevels } from "./draw.js";
|
|
4
|
+
import type { LodLevel } from "./index.js";
|
|
5
|
+
import { LoadingItem } from "./item.js";
|
|
6
|
+
/** How long an arriving level fades in for, over what drew in its place. */
|
|
7
|
+
export declare const ARRIVAL_MS = 200;
|
|
8
|
+
export interface LodEventMap extends Object3DEventMap {
|
|
9
|
+
/** A compiled level has joined the loaded levels. */
|
|
10
|
+
levelschange: {};
|
|
11
|
+
/** Fetch, decode, or GPU preparation failed; the loaded levels still draw. */
|
|
12
|
+
levelserror: {
|
|
13
|
+
error: Error;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** What a Lod makes of a level's loaded object: `object` compiles, then joins the loaded levels or is discarded. */
|
|
17
|
+
export interface PreparedLevel {
|
|
18
|
+
object: Object3D;
|
|
19
|
+
/** The level joins the loaded levels: it draws from now on. */
|
|
20
|
+
join(): void;
|
|
21
|
+
/** The compile failed, or the Lod was disposed meanwhile: free what preparing made. */
|
|
22
|
+
discard(): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Loads a Lod's levels as its cameras request them, never blocking a render. The coarsest level that
|
|
26
|
+
* draws something loads first, as nothing draws before it has (see levelsToDraw); the other levels a camera wants
|
|
27
|
+
* start loading once it has loaded. Each level's load runs once; once the render that asked for it has ended, the Lod
|
|
28
|
+
* prepares it (`prepare`), it compiles for the render context of every camera rendering the Lod and joins the loaded
|
|
29
|
+
* levels. Levels join only between arrivals, each of which fades in for ARRIVAL_MS from the levels loaded `before` it.
|
|
30
|
+
* Each render context seen for the first time compiles in the background every loaded level that draws something,
|
|
31
|
+
* given ones included, that no camera rendering the Lod wants: three skips a draw whose pipeline a compileAsync is
|
|
32
|
+
* still building, in any context that shares it, so a level a camera may draw now builds as it first draws instead.
|
|
33
|
+
* Nothing is evicted: a level stays loaded until the Lod is disposed.
|
|
34
|
+
*
|
|
35
|
+
* A Lod draws with the first renderer that draws one of its meshes (see `see`), whose renders it learns its cameras
|
|
36
|
+
* from. Once one has, it holds an item on its LoadingManager while anything a camera wants is missing, compiling or
|
|
37
|
+
* arriving.
|
|
38
|
+
*/
|
|
39
|
+
export declare class LodLevelLoadManager {
|
|
40
|
+
private readonly lod;
|
|
41
|
+
/** The LoadingManager item's name, which errors name too: the kind of Lod and its uuid. */
|
|
42
|
+
private readonly name;
|
|
43
|
+
/** The levels as the Lod was given them: it holds them (see `LodLevel.hold`) until it is disposed. */
|
|
44
|
+
private readonly levels;
|
|
45
|
+
private readonly prepare;
|
|
46
|
+
/** What draws a loaded level, compiled for each render context it is wanted in. */
|
|
47
|
+
private readonly drawnBy;
|
|
48
|
+
/** The bits of the levels that draw: given ones from the start, deferred ones once loaded and compiled. */
|
|
49
|
+
loaded: number;
|
|
50
|
+
/** The bits loaded before the latest arrival (see `progress`). */
|
|
51
|
+
before: number;
|
|
52
|
+
/** The first failure; it stops further loading. */
|
|
53
|
+
error: Error | undefined;
|
|
54
|
+
/** Whether a renderer has drawn the Lod: its shaders are being or have been built. */
|
|
55
|
+
started: boolean;
|
|
56
|
+
/** Whether a camera has asked for levels since the Lod was bound: until then it is pending. */
|
|
57
|
+
private requested;
|
|
58
|
+
/** Its item on a LoadingManager. */
|
|
59
|
+
readonly item: LoadingItem;
|
|
60
|
+
/**
|
|
61
|
+
* The bits of the levels that draw nothing, the coarsest level that draws something, and the order levels load in: it
|
|
62
|
+
* first, then coarse to fine.
|
|
63
|
+
*/
|
|
64
|
+
private readonly empty;
|
|
65
|
+
private readonly coarsest;
|
|
66
|
+
private readonly order;
|
|
67
|
+
/** When the latest arrival began. */
|
|
68
|
+
private arrival;
|
|
69
|
+
/** Compiled levels waiting for the arrival under way to end. */
|
|
70
|
+
private readonly ready;
|
|
71
|
+
/** Levels being prepared and compiled to join the loaded ones. */
|
|
72
|
+
private readonly arriving;
|
|
73
|
+
/** The background compiles of loaded levels, per render context. */
|
|
74
|
+
private readonly compiles;
|
|
75
|
+
/** Per level, its load once started. */
|
|
76
|
+
private readonly loads;
|
|
77
|
+
/** What renders told of the cameras that drew the Lod. */
|
|
78
|
+
private readonly seen;
|
|
79
|
+
private disposed;
|
|
80
|
+
/** What `LodLevel.hold` answered, each called once the Lod is disposed. */
|
|
81
|
+
private readonly releases;
|
|
82
|
+
/** The renderer drawing the Lod and what the cameras rendering it there asked for, once one drew it (see `see`). */
|
|
83
|
+
private bound;
|
|
84
|
+
constructor(lod: Object3D<LodEventMap>,
|
|
85
|
+
/** The LoadingManager item's name, which errors name too: the kind of Lod and its uuid. */
|
|
86
|
+
name: string,
|
|
87
|
+
/** The levels as the Lod was given them: it holds them (see `LodLevel.hold`) until it is disposed. */
|
|
88
|
+
levels: readonly LodLevel[],
|
|
89
|
+
/** The levels as levelsToDraw reads them, for the ones that draw nothing and the coarsest that draws something. */
|
|
90
|
+
{ empty, coarsest }: d.Infer<typeof DrawLevels>, prepare: (level: number, loaded: Object3D) => PreparedLevel,
|
|
91
|
+
/** What draws a loaded level, compiled for each render context it is wanted in. */
|
|
92
|
+
drawnBy: (level: number) => readonly Object3D[]);
|
|
93
|
+
/** How far the latest arrival has faded in, in [0, 1]: 1 once it has. */
|
|
94
|
+
get progress(): number;
|
|
95
|
+
/** The renderer drawing the Lod: the first that drew one of its meshes; null before. */
|
|
96
|
+
get renderer(): Renderer | null;
|
|
97
|
+
/**
|
|
98
|
+
* `renderer` draws one of the Lod's meshes, as three tells a mesh but not a LOD's `update`: the first binds the Lod
|
|
99
|
+
* to it, once checked to draw it; another throws.
|
|
100
|
+
*/
|
|
101
|
+
see(renderer: Renderer): void;
|
|
102
|
+
/** Whether `camera` still renders the Lod (see `CameraRequests.rendering`). */
|
|
103
|
+
rendering(camera: Camera): boolean;
|
|
104
|
+
get pending(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* `camera`, a shadow map's when `shadow`, wants the levels of the bits `wanted` (see levelsToLoad) in an update once
|
|
107
|
+
* the Lod is bound to a renderer (see `see`): load what is missing, and answer the bits of the levels loaded now. Outside a
|
|
108
|
+
* Scene a missing level is an error, as no render of it would load it.
|
|
109
|
+
*/
|
|
110
|
+
request(camera: Camera, wanted: number, shadow: boolean): number;
|
|
111
|
+
/**
|
|
112
|
+
* The height `camera`, a shadow map's when `shadow`, draws at with `renderer` (see CameraRenders.heightOf), which
|
|
113
|
+
* levels are chosen at.
|
|
114
|
+
*/
|
|
115
|
+
heightOf(camera: Camera, renderer: Renderer, shadow: boolean): number;
|
|
116
|
+
/** The renderer drawing the Lod and its cameras' requests: known once it drew the Lod, before anything loads. */
|
|
117
|
+
private boundOrThrow;
|
|
118
|
+
/** What compiles for `cameras` are for: the shadow maps they drew, and the targets disposed. */
|
|
119
|
+
private compileFor;
|
|
120
|
+
/**
|
|
121
|
+
* Load what the cameras still rendering the Lod want, in `order`, compile for `camera`'s render context every loaded
|
|
122
|
+
* level that draws something, none of them wants and is not yet compiled for it, and prepare the levels that have
|
|
123
|
+
* loaded. `shadow` is whether a shadow map renders it, in the renderer's `frame`.
|
|
124
|
+
*/
|
|
125
|
+
private load;
|
|
126
|
+
/** Run level `level`'s `load`, holding the object it makes. */
|
|
127
|
+
private start;
|
|
128
|
+
private levelAt;
|
|
129
|
+
/** Compile the loaded levels of `bits` for `context`: a background compile (see ContextCompiles). */
|
|
130
|
+
private compileLevels;
|
|
131
|
+
/**
|
|
132
|
+
* Prepare `level` once the render that asked for it has ended, if a camera still wants it then, and compile it for
|
|
133
|
+
* the render context of every camera still rendering the Lod, `context` among them, to join the loaded levels: a
|
|
134
|
+
* slow level never holds another's, and no camera draws it uncompiled.
|
|
135
|
+
*/
|
|
136
|
+
private arrive;
|
|
137
|
+
/** Let compiled levels join the loaded ones, between arrivals: what draws never changes halfway through a fade. */
|
|
138
|
+
private join;
|
|
139
|
+
/**
|
|
140
|
+
* Hold the item while levels a camera wants are missing, compiling or arriving, and end it once they are done, so a host waiting for its LoadingManager renders its cameras complete. Called at
|
|
141
|
+
* the end of each request.
|
|
142
|
+
*/
|
|
143
|
+
private sync;
|
|
144
|
+
/**
|
|
145
|
+
* The one failure rule, for a level that fails and for anything that throws while three renders, where a throw would
|
|
146
|
+
* leave its internal target bound: note the error, log it, report it on the LoadingManager the item is held on and
|
|
147
|
+
* end the item, and dispatch `levelserror`. Only the first is reported; it stops further loading.
|
|
148
|
+
*/
|
|
149
|
+
report(error: unknown): void;
|
|
150
|
+
/** Run `action`, part of an update or a draw callback, reporting what it throws instead. */
|
|
151
|
+
guard(action: () => void): void;
|
|
152
|
+
/**
|
|
153
|
+
* Stop loading, then `release` what the Lod made of its levels and let go of what it holds of them (see
|
|
154
|
+
* `LodLevel.hold`), once nothing preparing, compiling or loading still uses them. What the levels gave or loaded is
|
|
155
|
+
* not freed: it is whoever made it's.
|
|
156
|
+
*/
|
|
157
|
+
dispose(release: () => void): void;
|
|
158
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { nextTask } from "../task.js";
|
|
2
|
+
import { isObject3D, isScene, rootOf } from "../three.js";
|
|
3
|
+
import { compilerOf } from "./compile/index.js";
|
|
4
|
+
import { CameraRenders } from "./cameras.js";
|
|
5
|
+
import { has } from "./draw.js";
|
|
6
|
+
import { LoadingItem } from "./item.js";
|
|
7
|
+
import { CameraRequests } from "./requests.js";
|
|
8
|
+
import { ContextCompiles } from "./compiles.js";
|
|
9
|
+
import { checkRenderer } from "./renderer.js";
|
|
10
|
+
/** How long an arriving level fades in for, over what drew in its place. */
|
|
11
|
+
export const ARRIVAL_MS = 200;
|
|
12
|
+
/**
|
|
13
|
+
* Loads a Lod's levels as its cameras request them, never blocking a render. The coarsest level that
|
|
14
|
+
* draws something loads first, as nothing draws before it has (see levelsToDraw); the other levels a camera wants
|
|
15
|
+
* start loading once it has loaded. Each level's load runs once; once the render that asked for it has ended, the Lod
|
|
16
|
+
* prepares it (`prepare`), it compiles for the render context of every camera rendering the Lod and joins the loaded
|
|
17
|
+
* levels. Levels join only between arrivals, each of which fades in for ARRIVAL_MS from the levels loaded `before` it.
|
|
18
|
+
* Each render context seen for the first time compiles in the background every loaded level that draws something,
|
|
19
|
+
* given ones included, that no camera rendering the Lod wants: three skips a draw whose pipeline a compileAsync is
|
|
20
|
+
* still building, in any context that shares it, so a level a camera may draw now builds as it first draws instead.
|
|
21
|
+
* Nothing is evicted: a level stays loaded until the Lod is disposed.
|
|
22
|
+
*
|
|
23
|
+
* A Lod draws with the first renderer that draws one of its meshes (see `see`), whose renders it learns its cameras
|
|
24
|
+
* from. Once one has, it holds an item on its LoadingManager while anything a camera wants is missing, compiling or
|
|
25
|
+
* arriving.
|
|
26
|
+
*/
|
|
27
|
+
export class LodLevelLoadManager {
|
|
28
|
+
lod;
|
|
29
|
+
name;
|
|
30
|
+
levels;
|
|
31
|
+
prepare;
|
|
32
|
+
drawnBy;
|
|
33
|
+
/** The bits of the levels that draw: given ones from the start, deferred ones once loaded and compiled. */
|
|
34
|
+
loaded = 0;
|
|
35
|
+
/** The bits loaded before the latest arrival (see `progress`). */
|
|
36
|
+
before = 0;
|
|
37
|
+
/** The first failure; it stops further loading. */
|
|
38
|
+
error;
|
|
39
|
+
/** Whether a renderer has drawn the Lod: its shaders are being or have been built. */
|
|
40
|
+
started = false;
|
|
41
|
+
/** Whether a camera has asked for levels since the Lod was bound: until then it is pending. */
|
|
42
|
+
requested = false;
|
|
43
|
+
/** Its item on a LoadingManager. */
|
|
44
|
+
item;
|
|
45
|
+
/**
|
|
46
|
+
* The bits of the levels that draw nothing, the coarsest level that draws something, and the order levels load in: it
|
|
47
|
+
* first, then coarse to fine.
|
|
48
|
+
*/
|
|
49
|
+
empty;
|
|
50
|
+
coarsest;
|
|
51
|
+
order;
|
|
52
|
+
/** When the latest arrival began. */
|
|
53
|
+
arrival;
|
|
54
|
+
/** Compiled levels waiting for the arrival under way to end. */
|
|
55
|
+
ready = new Map();
|
|
56
|
+
/** Levels being prepared and compiled to join the loaded ones. */
|
|
57
|
+
arriving = new Map();
|
|
58
|
+
/** The background compiles of loaded levels, per render context. */
|
|
59
|
+
compiles;
|
|
60
|
+
/** Per level, its load once started. */
|
|
61
|
+
loads = new Map();
|
|
62
|
+
/** What renders told of the cameras that drew the Lod. */
|
|
63
|
+
seen = new CameraRenders();
|
|
64
|
+
disposed = false;
|
|
65
|
+
/** What `LodLevel.hold` answered, each called once the Lod is disposed. */
|
|
66
|
+
releases;
|
|
67
|
+
/** The renderer drawing the Lod and what the cameras rendering it there asked for, once one drew it (see `see`). */
|
|
68
|
+
bound = null;
|
|
69
|
+
constructor(lod,
|
|
70
|
+
/** The LoadingManager item's name, which errors name too: the kind of Lod and its uuid. */
|
|
71
|
+
name,
|
|
72
|
+
/** The levels as the Lod was given them: it holds them (see `LodLevel.hold`) until it is disposed. */
|
|
73
|
+
levels,
|
|
74
|
+
/** The levels as levelsToDraw reads them, for the ones that draw nothing and the coarsest that draws something. */
|
|
75
|
+
{ empty, coarsest }, prepare,
|
|
76
|
+
/** What draws a loaded level, compiled for each render context it is wanted in. */
|
|
77
|
+
drawnBy) {
|
|
78
|
+
this.lod = lod;
|
|
79
|
+
this.name = name;
|
|
80
|
+
this.levels = levels;
|
|
81
|
+
this.prepare = prepare;
|
|
82
|
+
this.drawnBy = drawnBy;
|
|
83
|
+
this.loaded = this.before = levels.reduce((bits, level, i) => (level.object ? bits | (1 << i) : bits), 0);
|
|
84
|
+
this.empty = empty;
|
|
85
|
+
this.coarsest = coarsest;
|
|
86
|
+
this.order = levels.length === 0 ? [] : [coarsest, ...[...levels.keys()].reverse().filter((level) => level !== coarsest)];
|
|
87
|
+
this.releases = [...new Set(levels.flatMap(({ hold }) => (hold ? [hold] : [])))].map((hold) => hold());
|
|
88
|
+
this.compiles = new ContextCompiles((context, bits) => this.compileLevels(context, bits), (error) => this.report(error));
|
|
89
|
+
this.item = new LoadingItem(name);
|
|
90
|
+
}
|
|
91
|
+
/** How far the latest arrival has faded in, in [0, 1]: 1 once it has. */
|
|
92
|
+
get progress() {
|
|
93
|
+
if (this.arrival === undefined)
|
|
94
|
+
return 1;
|
|
95
|
+
return Math.min((performance.now() - this.arrival) / ARRIVAL_MS, 1);
|
|
96
|
+
}
|
|
97
|
+
/** The renderer drawing the Lod: the first that drew one of its meshes; null before. */
|
|
98
|
+
get renderer() {
|
|
99
|
+
return this.bound?.renderer ?? null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `renderer` draws one of the Lod's meshes, as three tells a mesh but not a LOD's `update`: the first binds the Lod
|
|
103
|
+
* to it, once checked to draw it; another throws.
|
|
104
|
+
*/
|
|
105
|
+
see(renderer) {
|
|
106
|
+
if (this.bound) {
|
|
107
|
+
if (renderer !== this.bound.renderer)
|
|
108
|
+
throw new Error(`${this.name}: another renderer than the first that drew it drew it`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
checkRenderer(renderer, this.name);
|
|
112
|
+
this.bound = { renderer, requests: new CameraRequests(renderer, this.seen) };
|
|
113
|
+
this.started = true;
|
|
114
|
+
// Its first frame drew nothing of it: it holds its item until the next asks for what its cameras need.
|
|
115
|
+
this.sync();
|
|
116
|
+
}
|
|
117
|
+
/** Whether `camera` still renders the Lod (see `CameraRequests.rendering`). */
|
|
118
|
+
rendering(camera) {
|
|
119
|
+
return this.bound?.requests.rendering(camera) ?? false;
|
|
120
|
+
}
|
|
121
|
+
get pending() {
|
|
122
|
+
if (this.disposed || this.error || !this.bound)
|
|
123
|
+
return false;
|
|
124
|
+
if (!this.requested)
|
|
125
|
+
return true;
|
|
126
|
+
const { requests } = this.bound;
|
|
127
|
+
if (this.arriving.size > 0 || this.ready.size > 0 || (requests.needed() & ~this.loaded) !== 0)
|
|
128
|
+
return true;
|
|
129
|
+
return this.compiles.running(requests);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* `camera`, a shadow map's when `shadow`, wants the levels of the bits `wanted` (see levelsToLoad) in an update once
|
|
133
|
+
* the Lod is bound to a renderer (see `see`): load what is missing, and answer the bits of the levels loaded now. Outside a
|
|
134
|
+
* Scene a missing level is an error, as no render of it would load it.
|
|
135
|
+
*/
|
|
136
|
+
request(camera, wanted, shadow) {
|
|
137
|
+
const scene = rootOf(this.lod);
|
|
138
|
+
if (this.disposed || this.error)
|
|
139
|
+
return this.loaded;
|
|
140
|
+
if (!isScene(scene)) {
|
|
141
|
+
if ((wanted & ~this.loaded) !== 0)
|
|
142
|
+
throw new Error(`${this.name}: render a Scene that holds it to load the levels it needs`);
|
|
143
|
+
return this.loaded;
|
|
144
|
+
}
|
|
145
|
+
this.item.touch();
|
|
146
|
+
const { requests } = this.boundOrThrow();
|
|
147
|
+
this.requested = true;
|
|
148
|
+
const frame = requests.set(scene, camera, wanted, shadow);
|
|
149
|
+
this.load(requests, camera, shadow, frame);
|
|
150
|
+
this.sync();
|
|
151
|
+
return this.loaded;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The height `camera`, a shadow map's when `shadow`, draws at with `renderer` (see CameraRenders.heightOf), which
|
|
155
|
+
* levels are chosen at.
|
|
156
|
+
*/
|
|
157
|
+
heightOf(camera, renderer, shadow) {
|
|
158
|
+
return this.seen.heightOf(camera, renderer, shadow);
|
|
159
|
+
}
|
|
160
|
+
/** The renderer drawing the Lod and its cameras' requests: known once it drew the Lod, before anything loads. */
|
|
161
|
+
boundOrThrow() {
|
|
162
|
+
if (!this.bound)
|
|
163
|
+
throw new Error(`${this.name}: no renderer has updated it`);
|
|
164
|
+
return this.bound;
|
|
165
|
+
}
|
|
166
|
+
/** What compiles for `cameras` are for: the shadow maps they drew, and the targets disposed. */
|
|
167
|
+
compileFor(cameras) {
|
|
168
|
+
return { shadows: this.seen.shadowsOf(cameras), isDisposed: (target) => this.seen.isDisposed(target) };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Load what the cameras still rendering the Lod want, in `order`, compile for `camera`'s render context every loaded
|
|
172
|
+
* level that draws something, none of them wants and is not yet compiled for it, and prepare the levels that have
|
|
173
|
+
* loaded. `shadow` is whether a shadow map renders it, in the renderer's `frame`.
|
|
174
|
+
*/
|
|
175
|
+
load(requests, camera, shadow, frame) {
|
|
176
|
+
const needed = requests.needed();
|
|
177
|
+
const coarsestLoaded = !this.levelAt(this.coarsest).load || this.loads.get(this.coarsest)?.object !== undefined;
|
|
178
|
+
for (const level of this.order) {
|
|
179
|
+
const { load } = this.levelAt(level);
|
|
180
|
+
if (!load || !has(needed, level) || this.loads.has(level) || (!coarsestLoaded && level !== this.coarsest))
|
|
181
|
+
continue;
|
|
182
|
+
this.start(level, load);
|
|
183
|
+
}
|
|
184
|
+
// What draws never changes halfway through a frame: once a camera updated the Lod in it, its indirect draws among
|
|
185
|
+
// them, a shadow map rendered later joins nothing. The camera's next update does; a Lod only shadow
|
|
186
|
+
// maps update joins in theirs.
|
|
187
|
+
if (!shadow || requests.cameraFrame !== frame)
|
|
188
|
+
this.join();
|
|
189
|
+
const context = this.seen.contextOf(camera);
|
|
190
|
+
if (!context)
|
|
191
|
+
return;
|
|
192
|
+
this.compiles.compile(context, this.compiles.claim(context, this.loaded & ~this.empty & ~needed));
|
|
193
|
+
const missing = needed & ~this.loaded;
|
|
194
|
+
for (const level of this.order) {
|
|
195
|
+
if (!has(missing, level) || !this.loads.get(level)?.object || this.arriving.has(level) || this.ready.has(level))
|
|
196
|
+
continue;
|
|
197
|
+
this.arrive(level, context);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Run level `level`'s `load`, holding the object it makes. */
|
|
201
|
+
start(level, load) {
|
|
202
|
+
const entry = {
|
|
203
|
+
promise: Promise.resolve()
|
|
204
|
+
.then(load)
|
|
205
|
+
.then((object) => {
|
|
206
|
+
if (!isObject3D(object))
|
|
207
|
+
throw new Error(`${this.name}: level ${level}'s load must return an Object3D`);
|
|
208
|
+
entry.object = object;
|
|
209
|
+
return object;
|
|
210
|
+
})
|
|
211
|
+
.catch((error) => {
|
|
212
|
+
entry.error = error instanceof Error ? error : new Error(`${this.name}: level ${level} failed to load`, { cause: error });
|
|
213
|
+
throw entry.error;
|
|
214
|
+
}),
|
|
215
|
+
};
|
|
216
|
+
this.loads.set(level, entry);
|
|
217
|
+
void entry.promise.catch((error) => this.report(error));
|
|
218
|
+
}
|
|
219
|
+
levelAt(level) {
|
|
220
|
+
const found = this.levels[level];
|
|
221
|
+
if (!found)
|
|
222
|
+
throw new Error(`${this.name}: no level ${level}`);
|
|
223
|
+
return found;
|
|
224
|
+
}
|
|
225
|
+
/** Compile the loaded levels of `bits` for `context`: a background compile (see ContextCompiles). */
|
|
226
|
+
async compileLevels(context, bits) {
|
|
227
|
+
// A context whose target was disposed meanwhile is dropped: compiling would revive the target.
|
|
228
|
+
if (this.disposed || !this.seen.holds(context))
|
|
229
|
+
return;
|
|
230
|
+
const objects = this.order.filter((level) => has(bits, level)).flatMap((level) => this.drawnBy(level));
|
|
231
|
+
const { renderer, requests } = this.boundOrThrow();
|
|
232
|
+
const compileFor = this.compileFor(requests.cameras());
|
|
233
|
+
await Promise.all(objects.map((object) => compilerOf(renderer).compileAsync(object, context, compileFor)));
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Prepare `level` once the render that asked for it has ended, if a camera still wants it then, and compile it for
|
|
237
|
+
* the render context of every camera still rendering the Lod, `context` among them, to join the loaded levels: a
|
|
238
|
+
* slow level never holds another's, and no camera draws it uncompiled.
|
|
239
|
+
*/
|
|
240
|
+
arrive(level, context) {
|
|
241
|
+
// A render runs within one task: the next starts after it has ended.
|
|
242
|
+
const done = nextTask()
|
|
243
|
+
.then(async () => {
|
|
244
|
+
const object = this.loads.get(level)?.object;
|
|
245
|
+
const { renderer, requests } = this.boundOrThrow();
|
|
246
|
+
if (this.disposed || !object || !has(requests.needed(), level))
|
|
247
|
+
return;
|
|
248
|
+
const cameras = requests.cameras();
|
|
249
|
+
// Contexts whose targets were disposed meanwhile are dropped. A camera that starts rendering the Lod while it
|
|
250
|
+
// arrives draws it with pipelines built in that frame.
|
|
251
|
+
const seen = [context, ...cameras.flatMap((camera) => this.seen.contextOf(camera) ?? [])];
|
|
252
|
+
const contexts = new Set(seen.filter((other) => this.seen.holds(other)));
|
|
253
|
+
for (const other of contexts)
|
|
254
|
+
this.compiles.claim(other, 1 << level);
|
|
255
|
+
const prepared = this.prepare(level, object);
|
|
256
|
+
try {
|
|
257
|
+
const compileFor = this.compileFor(cameras);
|
|
258
|
+
await Promise.all([...contexts].map((other) => compilerOf(renderer).compileAsync(prepared.object, other, compileFor)));
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
prepared.discard();
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
if (this.disposed)
|
|
265
|
+
return prepared.discard();
|
|
266
|
+
this.ready.set(level, prepared);
|
|
267
|
+
})
|
|
268
|
+
.catch((error) => this.report(error))
|
|
269
|
+
.finally(() => {
|
|
270
|
+
this.arriving.delete(level);
|
|
271
|
+
this.join();
|
|
272
|
+
});
|
|
273
|
+
this.arriving.set(level, done);
|
|
274
|
+
}
|
|
275
|
+
/** Let compiled levels join the loaded ones, between arrivals: what draws never changes halfway through a fade. */
|
|
276
|
+
join() {
|
|
277
|
+
if (this.disposed || this.ready.size === 0 || this.progress < 1)
|
|
278
|
+
return;
|
|
279
|
+
this.before = this.loaded;
|
|
280
|
+
for (const [level, prepared] of this.ready) {
|
|
281
|
+
prepared.join();
|
|
282
|
+
this.loaded |= 1 << level;
|
|
283
|
+
}
|
|
284
|
+
this.ready.clear();
|
|
285
|
+
this.arrival = performance.now();
|
|
286
|
+
queueMicrotask(() => {
|
|
287
|
+
if (!this.disposed)
|
|
288
|
+
this.lod.dispatchEvent({ type: "levelschange" });
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Hold the item while levels a camera wants are missing, compiling or arriving, and end it once they are done, so a host waiting for its LoadingManager renders its cameras complete. Called at
|
|
293
|
+
* the end of each request.
|
|
294
|
+
*/
|
|
295
|
+
sync() {
|
|
296
|
+
this.item.sync(this.renderer, !this.disposed && !this.error && (this.pending || this.progress < 1));
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The one failure rule, for a level that fails and for anything that throws while three renders, where a throw would
|
|
300
|
+
* leave its internal target bound: note the error, log it, report it on the LoadingManager the item is held on and
|
|
301
|
+
* end the item, and dispatch `levelserror`. Only the first is reported; it stops further loading.
|
|
302
|
+
*/
|
|
303
|
+
report(error) {
|
|
304
|
+
if (this.disposed || this.error)
|
|
305
|
+
return;
|
|
306
|
+
const failure = (this.error = error instanceof Error ? error : new Error("Lod: level failed", { cause: error }));
|
|
307
|
+
console.error(failure);
|
|
308
|
+
this.item.fail();
|
|
309
|
+
this.lod.dispatchEvent({ type: "levelserror", error: failure });
|
|
310
|
+
}
|
|
311
|
+
/** Run `action`, part of an update or a draw callback, reporting what it throws instead. */
|
|
312
|
+
guard(action) {
|
|
313
|
+
try {
|
|
314
|
+
action();
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
this.report(error);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Stop loading, then `release` what the Lod made of its levels and let go of what it holds of them (see
|
|
322
|
+
* `LodLevel.hold`), once nothing preparing, compiling or loading still uses them. What the levels gave or loaded is
|
|
323
|
+
* not freed: it is whoever made it's.
|
|
324
|
+
*/
|
|
325
|
+
dispose(release) {
|
|
326
|
+
this.disposed = true;
|
|
327
|
+
this.item.sync(this.renderer, false);
|
|
328
|
+
this.seen.dispose();
|
|
329
|
+
for (const prepared of this.ready.values())
|
|
330
|
+
prepared.discard();
|
|
331
|
+
this.ready.clear();
|
|
332
|
+
const free = () => {
|
|
333
|
+
release();
|
|
334
|
+
for (const letGo of this.releases)
|
|
335
|
+
letGo();
|
|
336
|
+
};
|
|
337
|
+
const finish = () => {
|
|
338
|
+
const unsettled = [...this.loads.values()].flatMap((entry) => (!entry.object && !entry.error ? [entry.promise] : []));
|
|
339
|
+
// A mesh decode can begin its source-material dependency after disposal starts.
|
|
340
|
+
if (unsettled.length)
|
|
341
|
+
void Promise.allSettled(unsettled).then(free);
|
|
342
|
+
else
|
|
343
|
+
free();
|
|
344
|
+
};
|
|
345
|
+
const tasks = [...this.arriving.values(), ...this.compiles.tasks()];
|
|
346
|
+
if (tasks.length > 0)
|
|
347
|
+
void Promise.all(tasks).then(finish);
|
|
348
|
+
else
|
|
349
|
+
finish();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/levels/manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU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OAAO,EAAE,CAAC;YACV,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ;gBAAE,KAAK,EAAE,CAAC;QAC7C,CAAC,CAAC;QACF,MAAM,MAAM,GAAG,GAAG,EAAE;YAClB,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACtH,gFAAgF;YAChF,IAAI,SAAS,CAAC,MAAM;gBAAE,KAAK,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;gBAC/D,IAAI,EAAE,CAAC;QACd,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;QACpE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,KAAK,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;YACtD,MAAM,EAAE,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Material, NodeMaterial } from "three/webgpu";
|
|
2
2
|
/**
|
|
3
|
-
* The copy of `material` (or of the material it copies) a level of a Lod
|
|
4
|
-
*
|
|
3
|
+
* The copy of `material` (or of the material it copies) a level of a Lod draws
|
|
4
|
+
* with: it keeps only the pixels of its draw (see fade.ts), tints by
|
|
5
5
|
* its level, casts nothing into shadow maps too coarse for it and, `swaying`, sways in
|
|
6
6
|
* the wind of whatever object draws it (see Wind). Made once per original and kind, and
|
|
7
7
|
* shared by every level drawing it: what differs per object is read while it renders.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Fn, output, positionLocal, vec4 } from "three/tsl";
|
|
2
2
|
import { castPosition, keepsPixel, placeInstances, tint } from "./fade.js";
|
|
3
|
-
import { toNodeMaterial } from "
|
|
4
|
-
import { isNodeOf } from "
|
|
5
|
-
import { sway } from "
|
|
3
|
+
import { toNodeMaterial } from "../three.js";
|
|
4
|
+
import { isNodeOf } from "../tsl.js";
|
|
5
|
+
import { sway } from "../wind/sway.js";
|
|
6
|
+
// Side tables, as three's Material has no typed place for a package's state (userData is the app's).
|
|
6
7
|
/** Copy → the material it copies. */
|
|
7
8
|
const originals = new WeakMap();
|
|
8
9
|
/** Original → its copies, still and swaying. */
|
|
@@ -14,8 +15,8 @@ function slot(node, type, builder) {
|
|
|
14
15
|
return node;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
|
-
* The copy of `material` (or of the material it copies) a level of a Lod
|
|
18
|
-
*
|
|
18
|
+
* The copy of `material` (or of the material it copies) a level of a Lod draws
|
|
19
|
+
* with: it keeps only the pixels of its draw (see fade.ts), tints by
|
|
19
20
|
* its level, casts nothing into shadow maps too coarse for it and, `swaying`, sways in
|
|
20
21
|
* the wind of whatever object draws it (see Wind). Made once per original and kind, and
|
|
21
22
|
* shared by every level drawing it: what differs per object is read while it renders.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"material.js","sourceRoot":"","sources":["../../src/levels/material.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EA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C,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qEAAqE;AACrE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAkB,EAAY,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Object3D, Renderer } from "three/webgpu";
|
|
2
|
+
/**
|
|
3
|
+
* How deep in renders `renderer` is: -1 outside them, 0 in a render of its own, 1 in one it draws inside another, as it
|
|
4
|
+
* draws shadow maps and post-processing. Read from r186's `_callDepth`: three keeps a draw's built shader per depth,
|
|
5
|
+
* and no public API tells which.
|
|
6
|
+
*/
|
|
7
|
+
export declare function callDepth(renderer: Renderer): number;
|
|
8
|
+
/**
|
|
9
|
+
* Whether `renderer` is rendering or compiling now, as it is while it updates what it draws; not while an app calls
|
|
10
|
+
* `update` itself or another renderer draws. A compile is told by r186's `_compilationPromises`, which no public API
|
|
11
|
+
* shows.
|
|
12
|
+
*/
|
|
13
|
+
export declare const busy: (renderer: Renderer) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Throws unless `renderer` can draw a Lod, `who`: three's WebGPU backend, whose device has indirect-first-instance, as
|
|
16
|
+
* each level's draws start at its list (see update.ts).
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkRenderer(renderer: Renderer, who: string): void;
|
|
19
|
+
/** The largest storage binding `renderer`'s device takes: r186's WebGPU backend's `device`, which three's types omit. */
|
|
20
|
+
export declare function maxStorageBinding(renderer: Renderer): number;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the scene `node` is in is being drawn into a shadow map: three's shadow map render
|
|
23
|
+
* draws it with its own override material, and calls `update` on every LOD with the
|
|
24
|
+
* light's camera, which must not switch the levels the scene's camera chose.
|
|
25
|
+
*/
|
|
26
|
+
export declare function inShadowMap(node: Object3D): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether `target` is the framebuffer target r186 draws the canvas (or output target) through when tone mapping or
|
|
29
|
+
* the output colour space needs a final pass. A draw meant for the output sees it as the active target; a compile for
|
|
30
|
+
* the output leaves the target unset and lets three resolve it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const isOutputPass: (target: unknown) => boolean;
|