@drawcall/lod 0.1.2 → 0.3.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 +13 -70
- package/dist/at.d.ts +2 -0
- package/dist/at.js +8 -0
- package/dist/at.js.map +1 -0
- package/dist/bake.d.ts +22 -0
- package/dist/bake.js +88 -0
- package/dist/bake.js.map +1 -0
- package/dist/baked/codec.d.ts +5 -5
- package/dist/baked/codec.js +58 -158
- 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 +16 -6
- package/dist/baked/index.js +23 -21
- package/dist/baked/index.js.map +1 -1
- package/dist/baked/interior/faces.d.ts +4 -3
- package/dist/baked/interior/faces.js +13 -10
- 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.js +1 -1
- package/dist/baked/interior/rooms.js.map +1 -1
- package/dist/baked/low.d.ts +2 -2
- package/dist/baked/low.js +9 -8
- 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/codec/mesh.js +220 -0
- package/dist/codec/mesh.js.map +1 -0
- package/dist/dispose.d.ts +11 -4
- package/dist/dispose.js +39 -12
- package/dist/dispose.js.map +1 -1
- package/dist/gpu.d.ts +39 -0
- package/dist/gpu.js +41 -0
- package/dist/gpu.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 +23 -14
- package/dist/impostor/bake/index.js +42 -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 +60 -12
- 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 +2 -2
- package/dist/impostor/bake/source.js +8 -19
- package/dist/impostor/bake/source.js.map +1 -1
- package/dist/impostor/codec.d.ts +5 -11
- package/dist/impostor/codec.js +37 -121
- 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 +117 -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 +64 -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 +12 -0
- package/dist/impostor/ktx2/worker.js.map +1 -0
- package/dist/impostor/mesh/card.d.ts +3 -3
- package/dist/impostor/mesh/card.js +11 -8
- package/dist/impostor/mesh/card.js.map +1 -1
- package/dist/impostor/mesh/index.d.ts +10 -7
- package/dist/impostor/mesh/index.js +15 -18
- package/dist/impostor/mesh/index.js.map +1 -1
- package/dist/impostor/mesh/material.d.ts +24 -13
- package/dist/impostor/mesh/material.js +67 -51
- package/dist/impostor/mesh/material.js.map +1 -1
- package/dist/impostor/mesh/surface.d.ts +20 -16
- package/dist/impostor/mesh/surface.js +81 -58
- 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/impostor/octahedral.d.ts +1 -8
- package/dist/impostor/octahedral.js +3 -18
- package/dist/impostor/octahedral.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.js +14 -8
- package/dist/index.js.map +1 -1
- package/dist/instanced/camera.d.ts +46 -0
- package/dist/instanced/camera.js +70 -0
- package/dist/instanced/camera.js.map +1 -0
- package/dist/instanced/chunk.d.ts +97 -0
- package/dist/instanced/chunk.js +156 -0
- package/dist/instanced/chunk.js.map +1 -0
- package/dist/instanced/chunks.d.ts +60 -0
- package/dist/instanced/chunks.js +208 -0
- package/dist/instanced/chunks.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/index.d.ts +96 -92
- package/dist/instanced/index.js +229 -512
- package/dist/instanced/index.js.map +1 -1
- 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 +130 -0
- package/dist/instanced/levels.js.map +1 -0
- package/dist/instanced/lists.d.ts +70 -0
- package/dist/instanced/lists.js +133 -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 +46 -14
- package/dist/instanced/meshes.js +137 -22
- package/dist/instanced/meshes.js.map +1 -1
- package/dist/instanced/mirror.d.ts +20 -0
- package/dist/instanced/mirror.js +37 -0
- package/dist/instanced/mirror.js.map +1 -0
- package/dist/instanced/pages/buffers.d.ts +37 -0
- package/dist/instanced/pages/buffers.js +15 -0
- package/dist/instanced/pages/buffers.js.map +1 -0
- package/dist/instanced/pages/chunk.d.ts +51 -0
- package/dist/instanced/pages/chunk.js +81 -0
- package/dist/instanced/pages/chunk.js.map +1 -0
- package/dist/instanced/pages/index.d.ts +74 -0
- package/dist/instanced/pages/index.js +269 -0
- package/dist/instanced/pages/index.js.map +1 -0
- package/dist/instanced/pages/passes.d.ts +21 -0
- package/dist/instanced/pages/passes.js +52 -0
- package/dist/instanced/pages/passes.js.map +1 -0
- package/dist/instanced/pages/slots.d.ts +11 -0
- package/dist/instanced/pages/slots.js +90 -0
- package/dist/instanced/pages/slots.js.map +1 -0
- package/dist/instanced/pages/workgroup.d.ts +14 -0
- package/dist/instanced/pages/workgroup.js +38 -0
- package/dist/instanced/pages/workgroup.js.map +1 -0
- package/dist/instanced/raycast.d.ts +15 -0
- package/dist/instanced/raycast.js +46 -0
- package/dist/instanced/raycast.js.map +1 -0
- package/dist/instanced/rows.d.ts +108 -0
- package/dist/instanced/rows.js +209 -0
- package/dist/instanced/rows.js.map +1 -0
- package/dist/instanced/shape.d.ts +25 -0
- package/dist/instanced/shape.js +51 -0
- package/dist/instanced/shape.js.map +1 -0
- package/dist/instanced/sort.d.ts +63 -0
- package/dist/instanced/sort.js +162 -0
- package/dist/instanced/sort.js.map +1 -0
- package/dist/instanced/update.d.ts +30 -0
- package/dist/instanced/update.js +207 -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 +39 -0
- package/dist/levels/compile/index.js +185 -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 +177 -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 +69 -0
- package/dist/levels/fade.js +150 -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 +97 -0
- package/dist/levels/item.js.map +1 -0
- package/dist/levels/load.d.ts +31 -0
- package/dist/levels/load.js +142 -0
- package/dist/levels/load.js.map +1 -0
- package/dist/levels/manager.d.ts +159 -0
- package/dist/levels/manager.js +339 -0
- package/dist/levels/manager.js.map +1 -0
- package/dist/{material.js → levels/material.js} +13 -7
- package/dist/levels/material.js.map +1 -0
- package/dist/levels/renderer.d.ts +29 -0
- package/dist/levels/renderer.js +41 -0
- package/dist/levels/renderer.js.map +1 -0
- package/dist/levels/requests.d.ts +49 -0
- package/dist/levels/requests.js +95 -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/levels/wait.d.ts +27 -0
- package/dist/levels/wait.js +61 -0
- package/dist/levels/wait.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/cache.d.ts +12 -15
- package/dist/loader/cache.js +64 -33
- package/dist/loader/cache.js.map +1 -1
- package/dist/loader/context.d.ts +46 -0
- package/dist/loader/context.js +91 -0
- package/dist/loader/context.js.map +1 -0
- package/dist/loader/dependencies.d.ts +32 -0
- package/dist/loader/dependencies.js +113 -0
- package/dist/loader/dependencies.js.map +1 -0
- package/dist/loader/index.d.ts +62 -0
- package/dist/loader/index.js +284 -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/request.d.ts +87 -0
- package/dist/loader/request.js +59 -0
- package/dist/loader/request.js.map +1 -0
- package/dist/loader/url.d.ts +16 -0
- package/dist/loader/url.js +35 -0
- package/dist/loader/url.js.map +1 -0
- package/dist/lod.d.ts +79 -49
- package/dist/lod.js +209 -153
- package/dist/lod.js.map +1 -1
- package/dist/meshopt.d.ts +6 -0
- package/dist/meshopt.js +19 -0
- package/dist/meshopt.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} +7 -4
- package/dist/{simplify.js → simplify/index.js} +42 -22
- package/dist/simplify/index.js.map +1 -0
- package/dist/{bounds.d.ts → source/detail.d.ts} +4 -13
- package/dist/{bounds.js → source/detail.js} +62 -32
- package/dist/source/detail.js.map +1 -0
- package/dist/source/{error.d.ts → deviation.d.ts} +3 -3
- package/dist/source/{error.js → deviation.js} +12 -12
- package/dist/source/deviation.js.map +1 -0
- 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} +3 -3
- package/dist/source/sampler.js.map +1 -0
- package/dist/source/source.d.ts +2 -2
- package/dist/source/source.js +2 -2
- 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 +20 -19
- package/dist/three.js +29 -35
- package/dist/three.js.map +1 -1
- package/dist/tsl.d.ts +10 -14
- package/dist/tsl.js +12 -47
- 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 +2 -2
- 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 +43 -40
- package/dist/wind/index.js.map +1 -1
- package/dist/wind/sway.d.ts +4 -1
- package/dist/wind/sway.js +4 -1
- package/dist/wind/sway.js.map +1 -1
- package/package.json +24 -8
- package/skills/lod/SKILL.md +147 -108
- package/dist/bounds.js.map +0 -1
- package/dist/fade.d.ts +0 -44
- package/dist/fade.js +0 -78
- package/dist/fade.js.map +0 -1
- package/dist/impostor/cache.d.ts +0 -15
- package/dist/impostor/cache.js +0 -44
- package/dist/impostor/cache.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/bounds.d.ts +0 -50
- package/dist/instanced/bounds.js +0 -271
- package/dist/instanced/bounds.js.map +0 -1
- package/dist/instanced/dirty.d.ts +0 -12
- package/dist/instanced/dirty.js +0 -61
- package/dist/instanced/dirty.js.map +0 -1
- package/dist/instanced/select.d.ts +0 -84
- package/dist/instanced/select.js +0 -264
- package/dist/instanced/select.js.map +0 -1
- package/dist/lazy.d.ts +0 -64
- package/dist/lazy.js +0 -187
- package/dist/lazy.js.map +0 -1
- package/dist/levels.d.ts +0 -72
- package/dist/levels.js +0 -146
- package/dist/levels.js.map +0 -1
- package/dist/loader/dispose.d.ts +0 -3
- package/dist/loader/dispose.js +0 -25
- package/dist/loader/dispose.js.map +0 -1
- package/dist/loader.d.ts +0 -99
- package/dist/loader.js +0 -234
- package/dist/loader.js.map +0 -1
- package/dist/material.js.map +0 -1
- package/dist/pause.d.ts +0 -6
- package/dist/pause.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/simplify.js.map +0 -1
- package/dist/source/error.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 -30
- package/dist/view.js +0 -75
- package/dist/view.js.map +0 -1
- /package/dist/{material.d.ts → levels/material.d.ts} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ladderEntry } from "./cache.js";
|
|
2
|
+
import { loaderPathURL, sourceRelativeURL } from "./url.js";
|
|
3
|
+
// What a LodLoader is asked for, normalised, and the cache entries the levels it derives are saved under.
|
|
4
|
+
/**
|
|
5
|
+
* Whether this runs in a production server-side build (`import.meta.env.PROD` and `SSR`), which precomputes assets
|
|
6
|
+
* into the deployed cache: every level is built and saved, and a level that cannot be saved fails the build.
|
|
7
|
+
*/
|
|
8
|
+
export const warmup = import.meta.env?.PROD === true && import.meta.env?.SSR === true;
|
|
9
|
+
const DEFAULT_LEVELS = [{ type: "impostor" }];
|
|
10
|
+
/** `request` with its URLs resolved against `path`, and every asset URL it builds from named as a dependency. */
|
|
11
|
+
export function normalize(request, path) {
|
|
12
|
+
const input = typeof request === "string" ? { url: request } : request;
|
|
13
|
+
const url = loaderPathURL(input.url, path);
|
|
14
|
+
const levels = structuredClone(input.levels ?? DEFAULT_LEVELS);
|
|
15
|
+
const urls = { source: url };
|
|
16
|
+
levels.forEach((level, position) => {
|
|
17
|
+
if (level.type !== "baked")
|
|
18
|
+
return;
|
|
19
|
+
for (const name of ["low", "interior"]) {
|
|
20
|
+
const value = level[name];
|
|
21
|
+
if (value !== undefined)
|
|
22
|
+
urls[auxiliary(position + 1, name)] = sourceRelativeURL(value, url);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return { ...input, url, levels, urls };
|
|
26
|
+
}
|
|
27
|
+
/** The request of ladder level `index`, which must be a derived level. */
|
|
28
|
+
export function derived(levels, index) {
|
|
29
|
+
const level = levels[index - 1];
|
|
30
|
+
if (!level || level.type === "empty")
|
|
31
|
+
throw new Error(`LodLoader: level ${index} is not derived`);
|
|
32
|
+
return level;
|
|
33
|
+
}
|
|
34
|
+
/** The dependency name of the low or interior asset of the baked level at ladder index `level`. */
|
|
35
|
+
export const auxiliary = (level, name) => `auxiliary:${level}:${name}`;
|
|
36
|
+
/** Derived level `index`'s cache entry, keyed by the inputs it is built from; undefined when the ladder is not cacheable. */
|
|
37
|
+
export function levelEntry(ladder, index, dependencies, options) {
|
|
38
|
+
// Keyed by role rather than ladder position, so adding or removing another level leaves this one's entry.
|
|
39
|
+
const roles = { source: "source", low: auxiliary(index, "low"), interior: auxiliary(index, "interior") };
|
|
40
|
+
return entry(ladder, derived(ladder.levels, index), roles, dependencies, options);
|
|
41
|
+
}
|
|
42
|
+
/** The cache entry of the source's shape, which describes the ladder before any level is built. */
|
|
43
|
+
export function shapeEntry(ladder, dependencies, options) {
|
|
44
|
+
return entry(ladder, "shape", { source: "source" }, dependencies, options);
|
|
45
|
+
}
|
|
46
|
+
function entry({ modules }, of, roles, dependencies, options) {
|
|
47
|
+
if (!modules)
|
|
48
|
+
return undefined;
|
|
49
|
+
const pick = (values) => Object.fromEntries(Object.entries(roles).flatMap(([role, name]) => {
|
|
50
|
+
const value = values[name];
|
|
51
|
+
return value === undefined ? [] : [[role, value]];
|
|
52
|
+
}));
|
|
53
|
+
return ladderEntry(pick(dependencies.inputs), of, pick(modules), options);
|
|
54
|
+
}
|
|
55
|
+
/** `entry` and the bytes it holds, read: undefined when it holds none. */
|
|
56
|
+
export async function cached(entry) {
|
|
57
|
+
return { entry, bytes: await entry?.load() };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/loader/request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAwB,MAAM,YAAY,CAAC;AAG/D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE5D,0GAA0G;AAE1G;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;AA4CtF,MAAM,cAAc,GAA+B,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;AAK1E,iHAAiH;AACjH,MAAM,UAAU,SAAS,CAAC,OAAmB,EAAE,IAAY;IACzD,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACvE,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,CA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AAU,MAAM,CAAC,KAA6B;IACxD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Resolve a relative asset path without changing absolute URLs or root-relative paths. */
|
|
2
|
+
export declare function loaderPathURL(url: string, base: string): string;
|
|
3
|
+
export declare const urlPath: (url: string) => string;
|
|
4
|
+
export declare const urlQuery: (url: string) => string;
|
|
5
|
+
export declare function assetPath(url: string): {
|
|
6
|
+
path: string;
|
|
7
|
+
extension: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function sourceRelativeURL(value: string, source: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* A same-origin path, as localURL leaves it, or a `file:` URL, as a `vite build` warmup sees public files: vitecache
|
|
12
|
+
* can resolve only these to project files.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isLocal: (url: string) => boolean;
|
|
15
|
+
/** Same-origin dependencies as paths, portable between development and deployment. */
|
|
16
|
+
export declare function localURL(url: string): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LoaderUtils } from "three/webgpu";
|
|
2
|
+
const absolute = /^[a-z][a-z\d+.-]*:/i;
|
|
3
|
+
/** An origin no URL has, to parse paths with when there is no document to resolve them against. */
|
|
4
|
+
const placeholderOrigin = "https://lod.invalid";
|
|
5
|
+
/** Resolve a relative asset path without changing absolute URLs or root-relative paths. */
|
|
6
|
+
export function loaderPathURL(url, base) {
|
|
7
|
+
return absolute.test(url) || url.startsWith("/") ? url : LoaderUtils.resolveURL(url, base);
|
|
8
|
+
}
|
|
9
|
+
export const urlPath = (url) => url.replace(/[?#].*$/s, "");
|
|
10
|
+
export const urlQuery = (url) => new URL(url, placeholderOrigin).search;
|
|
11
|
+
export function assetPath(url) {
|
|
12
|
+
const path = urlPath(url);
|
|
13
|
+
const extension = /\.(glb|gltf|glts)$/i.exec(path)?.[1]?.toLowerCase();
|
|
14
|
+
if (!extension)
|
|
15
|
+
throw new Error(`LodLoader: cannot load "${url}": expected a .glb, .gltf or .glts file`);
|
|
16
|
+
return { path, extension };
|
|
17
|
+
}
|
|
18
|
+
export function sourceRelativeURL(value, source) {
|
|
19
|
+
const base = new URL(source, typeof document === "undefined" ? placeholderOrigin : document.baseURI);
|
|
20
|
+
const url = new URL(value, base);
|
|
21
|
+
return url.origin === base.origin && !absolute.test(source) ? url.pathname + url.search + url.hash : url.href;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A same-origin path, as localURL leaves it, or a `file:` URL, as a `vite build` warmup sees public files: vitecache
|
|
25
|
+
* can resolve only these to project files.
|
|
26
|
+
*/
|
|
27
|
+
export const isLocal = (url) => (url.startsWith("/") && !url.startsWith("//")) || url.startsWith("file:");
|
|
28
|
+
/** Same-origin dependencies as paths, portable between development and deployment. */
|
|
29
|
+
export function localURL(url) {
|
|
30
|
+
if (typeof location === "undefined" || !/^https?:/i.test(url))
|
|
31
|
+
return url;
|
|
32
|
+
const parsed = new URL(url);
|
|
33
|
+
return parsed.origin === location.origin ? parsed.pathname + parsed.search + parsed.hash : url;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/loader/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,mGAAmG;AACnG,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD,2FAA2F;AAC3F,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,IAAY;IACrD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE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C,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAE3H,sFAAsF;AACtF,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACjG,CAAC"}
|
package/dist/lod.d.ts
CHANGED
|
@@ -1,78 +1,108 @@
|
|
|
1
|
-
import { Object3D, type Camera, type Intersection, type Raycaster } from "three/webgpu";
|
|
2
|
-
import {
|
|
3
|
-
import { type LodLevel } from "./levels.js";
|
|
4
|
-
import {
|
|
1
|
+
import { Object3D, type Camera, type Intersection, type LoadingManager, type Raycaster } from "three/webgpu";
|
|
2
|
+
import type { LodGpu } from "./gpu.js";
|
|
3
|
+
import { type LodLevel, type ThresholdedLevel } from "./levels/index.js";
|
|
4
|
+
import { type LodEventMap } from "./levels/manager.js";
|
|
5
|
+
import { WIND } from "./wind/hooks.js";
|
|
6
|
+
export interface LodOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Gets an item while levels a camera needs load, compile or fade in, ended once they are complete. Without one, a
|
|
9
|
+
* Lod nested in another's level reports to that one's, any other to three's `DefaultLoadingManager`. Wait for a
|
|
10
|
+
* quiet frame, one in which no item started or ended, rendering (or compiling) the Scene that holds the Lod a frame
|
|
11
|
+
* apart meanwhile, to capture what a camera sees complete. A Lod its renderer rendered around for a frame without
|
|
12
|
+
* updating it ends its item, and its next update starts it again. Renders of other scenes in a separate task can end
|
|
13
|
+
* the item early, and the next update reopens it; a renderer that only compiles leaves a hidden Lod's item held.
|
|
14
|
+
*/
|
|
15
|
+
manager?: LoadingManager;
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* (
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
18
|
+
* One object's levels, switched by on-screen height with dithered fades. three's renderer calls `update` with each
|
|
19
|
+
* camera before it draws, shadow maps' included; each camera measures at the height it draws at, measured in each
|
|
20
|
+
* render (outside one, the canvas's). Orthographic cameras switch without fading. Shadows follow what the camera draws
|
|
21
|
+
* and omit casters smaller than a shadow texel; levels cast into three's shadow maps, not into a light whose shadow
|
|
22
|
+
* map a custom shadow node replaces. Nothing draws until the coarsest level that draws something has loaded, which
|
|
23
|
+
* loads first; a deferred level loads when a camera first needs it, once that one has loaded, and meanwhile the
|
|
24
|
+
* nearest loaded coarser level draws in its place.
|
|
13
25
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* (1080 before that), so several views each get their own. An orthographic camera has
|
|
18
|
-
* no distance to dither by: levels switch by on-screen size there too, but at once.
|
|
26
|
+
* Arriving levels' texture uploads are paced to about one uncompressed 2048² RGBA texture's bytes per frame. Levels
|
|
27
|
+
* are cloned into the Lod. A nested Lod switches and fades its own levels. Lines, points and sprites draw without
|
|
28
|
+
* fading. Raycasts hit the source only. A Lod draws with its LodGpu's renderer only.
|
|
19
29
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* tell the Lod the viewport height. A nested Lod hands over to its neighbours at once.
|
|
24
|
-
* Raycasts hit the source only.
|
|
25
|
-
*
|
|
26
|
-
* Levels are read when the Lod is built: meshes added to a level later, or moved within
|
|
27
|
-
* it, are neither faded nor measured right. Build a new Lod instead.
|
|
30
|
+
* Build a new Lod after adding or moving meshes within a level: geometry is measured and hooked at construction or
|
|
31
|
+
* arrival. Skinned meshes and ShaderMaterials are refused; use static meshes with node materials or supported built-in
|
|
32
|
+
* materials.
|
|
28
33
|
*/
|
|
29
|
-
export declare class Lod extends Object3D<
|
|
34
|
+
export declare class Lod extends Object3D<LodEventMap> {
|
|
35
|
+
private readonly gpu;
|
|
30
36
|
/** Multiplies every measured height: below 1, cheaper levels take over sooner. */
|
|
31
37
|
static quality: number;
|
|
32
38
|
/** Tint every level by its index, to see which level draws where. */
|
|
33
39
|
static debug: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Share of a level's range its fade spans: from `maxPixels × (1 - fade)` up to its
|
|
36
|
-
* `maxPixels`, the finer level draws too.
|
|
37
|
-
*/
|
|
40
|
+
/** Share of a level's range its fade spans: from `maxPixels × (1 - fade)` up to its `maxPixels`, the finer level draws too. */
|
|
38
41
|
static readonly fade = 0.1;
|
|
39
42
|
readonly isLOD = true;
|
|
40
43
|
/** Let the renderer call `update` with its camera every frame. */
|
|
41
44
|
autoUpdate: boolean;
|
|
42
|
-
/** Draw only this level, without fades. */
|
|
45
|
+
/** Draw only this level, without fades, once the coarsest level that draws something has loaded. */
|
|
43
46
|
forceLevel: number | null;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
private
|
|
48
|
-
/**
|
|
47
|
+
/** The levels, each `object` this Lod's own copy once there is one. Set `maxPixels` to move a switch. */
|
|
48
|
+
readonly levels: ThresholdedLevel[];
|
|
49
|
+
/** The levels as they were given, which a copy is made from. */
|
|
50
|
+
private inputs;
|
|
51
|
+
/** Per level, where its meshes' fade comes from. */
|
|
52
|
+
private readonly fades;
|
|
53
|
+
/** Per level, whether its object is a Lod, which fades its own levels. */
|
|
54
|
+
private readonly nested;
|
|
55
|
+
/**
|
|
56
|
+
* Per loaded level, what in it may cast (see `shadowCasters`): found when it is built or joins, read every shadow
|
|
57
|
+
* map.
|
|
58
|
+
*/
|
|
59
|
+
private readonly casters;
|
|
60
|
+
/** The levels as levelsToDraw reads them. */
|
|
61
|
+
private encoded;
|
|
62
|
+
/** Bounding sphere of the source (see `measureLevels`) in the Lod's own space. */
|
|
49
63
|
private sphere;
|
|
50
64
|
private casterRadius;
|
|
65
|
+
private loads;
|
|
51
66
|
private disposed;
|
|
52
|
-
private readonly installed;
|
|
53
|
-
private fallback;
|
|
54
67
|
/**
|
|
55
|
-
* `levels[0]` is the source. Empty only as the target of `copy`. A source that draws
|
|
56
|
-
*
|
|
57
|
-
*
|
|
68
|
+
* `levels[0]` is the source. Empty only as the target of `copy`. A source that draws nothing (an empty Object3D, for
|
|
69
|
+
* detail another system draws) is measured by the first level that draws something. `gpu` is what it shares with
|
|
70
|
+
* every Lod drawing with its renderer.
|
|
58
71
|
*/
|
|
59
|
-
constructor(levels
|
|
72
|
+
constructor(levels: readonly LodLevel[], gpu: LodGpu, options?: LodOptions);
|
|
60
73
|
private build;
|
|
61
|
-
/** Fade the meshes under `node` by `
|
|
74
|
+
/** Fade the meshes under `node` by `fade`; an inner Lod fades its own. */
|
|
62
75
|
private hook;
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
/** A copy of `loaded`, level `index`'s object, parented hidden for world matrices and wind until it joins. */
|
|
77
|
+
private prepare;
|
|
78
|
+
get pending(): boolean;
|
|
79
|
+
get error(): Error | undefined;
|
|
80
|
+
/** Where the item of levels a camera misses goes (see `LodOptions.manager`). */
|
|
81
|
+
get manager(): LoadingManager;
|
|
82
|
+
set manager(manager: LoadingManager | undefined);
|
|
83
|
+
/** Switch and fade the levels for `camera`, and load those it needs. What fails is reported (see `error`): three is rendering. */
|
|
65
84
|
update(camera: Camera): void;
|
|
85
|
+
/** Show the levels for `camera`, a shadow map's when `shadow`. */
|
|
86
|
+
private show;
|
|
87
|
+
/** The source's height on `camera`'s screen, and the levels as levelsToDraw reads them there. */
|
|
88
|
+
private measure;
|
|
89
|
+
/**
|
|
90
|
+
* The index of the level that draws most of the Lod's pixels for `camera` from where it is, with the levels loaded
|
|
91
|
+
* now and no arrival under way (see `drawnLevel`); null while no level it could draw is loaded.
|
|
92
|
+
*/
|
|
93
|
+
getLevel(camera: Camera): number | null;
|
|
94
|
+
[WIND](padding: number): void;
|
|
66
95
|
raycast(raycaster: Raycaster, intersects: Intersection[]): boolean;
|
|
67
96
|
/**
|
|
68
|
-
* Copies `source`'s levels into this empty Lod (it throws otherwise). The copies share
|
|
69
|
-
*
|
|
70
|
-
*
|
|
97
|
+
* Copies `source`'s levels into this empty Lod (it throws otherwise). The copies share geometry, materials and
|
|
98
|
+
* textures with `source`, as three's clone does; the settings, LoadingManager, wind and each level's `maxPixels`
|
|
99
|
+
* come along.
|
|
71
100
|
*/
|
|
72
101
|
copy(source: Lod): this;
|
|
102
|
+
clone(): this;
|
|
73
103
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
104
|
+
* Release what the Lod made of its levels, once nothing it prepares or compiles still uses them. Objects you give or
|
|
105
|
+
* load are yours to dispose; LodLoader's are freed when the last Lod holding them is disposed (see `LodLevel.hold`).
|
|
76
106
|
*/
|
|
77
107
|
dispose(): void;
|
|
78
108
|
}
|