@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,90 @@
|
|
|
1
|
+
import { HalfFloatType, NearestFilter, RenderTarget, Vector2 } from "three/webgpu";
|
|
2
|
+
import { at } from "../../at.js";
|
|
3
|
+
import { readFloats } from "../../bake.js";
|
|
4
|
+
import { nextTask } from "../../task.js";
|
|
5
|
+
import { OUTPUTS } from "./materials.js";
|
|
6
|
+
// Rendering an atlas mip: its frames side by side in sheets, each read back at once.
|
|
7
|
+
/** Edge of the largest target frames render into side by side, a sheet, which is read back at once. */
|
|
8
|
+
const SHEET = 1024;
|
|
9
|
+
/**
|
|
10
|
+
* Colour attachments one target renders: four half-float targets fill the 32 bytes per
|
|
11
|
+
* sample WebGPU guarantees.
|
|
12
|
+
*/
|
|
13
|
+
const PER_TARGET = 4;
|
|
14
|
+
/**
|
|
15
|
+
* Render every frame (`frameCameras`: camera matrices, in atlas order) into `atlas`, at its
|
|
16
|
+
* cell size × `supersample`. Frames render side by side into sheets of up to SHEET square,
|
|
17
|
+
* so that each map is read back once per sheet, into targets of up to PER_TARGET outputs.
|
|
18
|
+
*/
|
|
19
|
+
export async function bakeMip(atlas, supersample, renderer, scene, camera, frameCameras) {
|
|
20
|
+
const { frames, maps } = atlas;
|
|
21
|
+
const side = atlas.cell * supersample;
|
|
22
|
+
const buffer = renderer.getDrawingBufferSize(new Vector2());
|
|
23
|
+
if (buffer.x === side && buffer.y === side)
|
|
24
|
+
throw new Error(`bakeImpostor: the renderer's canvas is ${side} px square, a frame's size: three would draw that frame over the whole sheet`);
|
|
25
|
+
const per = Math.max(1, Math.min(frames, Math.floor(SHEET / side)));
|
|
26
|
+
const width = per * side;
|
|
27
|
+
// one output per map, then the second way to store the normals (see ImpostorAtlasMip), then the specular
|
|
28
|
+
const names = OUTPUTS.filter((name) => (name === "emissive" ? maps.includes("emissive") : name !== "specular" || atlas.specular));
|
|
29
|
+
const targets = Array.from({ length: Math.ceil(names.length / PER_TARGET) }, (_, p) => {
|
|
30
|
+
const outputs = names.slice(p * PER_TARGET, (p + 1) * PER_TARGET);
|
|
31
|
+
const target = new RenderTarget(width, width, {
|
|
32
|
+
count: outputs.length,
|
|
33
|
+
type: HalfFloatType,
|
|
34
|
+
minFilter: NearestFilter,
|
|
35
|
+
magFilter: NearestFilter,
|
|
36
|
+
depthBuffer: true,
|
|
37
|
+
});
|
|
38
|
+
outputs.forEach((name, i) => {
|
|
39
|
+
const texture = target.textures[i];
|
|
40
|
+
if (!texture)
|
|
41
|
+
throw new Error("bakeImpostor: a render target lacks a texture");
|
|
42
|
+
texture.name = name;
|
|
43
|
+
});
|
|
44
|
+
return target;
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
for (let row0 = 0; row0 < frames; row0 += per)
|
|
48
|
+
for (let col0 = 0; col0 < frames; col0 += per) {
|
|
49
|
+
const sheet = [];
|
|
50
|
+
for (let row = row0; row < Math.min(row0 + per, frames); row++)
|
|
51
|
+
for (let col = col0; col < Math.min(col0 + per, frames); col++)
|
|
52
|
+
sheet.push({ col, row, x: (col - col0) * side, y: (row - row0) * side });
|
|
53
|
+
const placed = sheet.map(({ col, row, x, y }) => ({ matrix: at(frameCameras, row * frames + col), x, y }));
|
|
54
|
+
for (const target of targets)
|
|
55
|
+
renderSheet(renderer, target, scene, camera, placed, side);
|
|
56
|
+
const pixels = await Promise.all(targets.flatMap((target) => target.textures.map((_, i) => readFloats(renderer, target, i))));
|
|
57
|
+
for (const { col, row, x, y } of sheet)
|
|
58
|
+
atlas.write(pixels, width, supersample, col, row, x, y);
|
|
59
|
+
// Yield to the page between sheets, so that a long bake does not freeze it.
|
|
60
|
+
await nextTask();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
for (const target of targets)
|
|
65
|
+
target.dispose();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Clear `target` and render each frame, its camera at `matrix`, into its `side` square at (x, y), counted from the
|
|
70
|
+
* bottom left as the atlas is.
|
|
71
|
+
*/
|
|
72
|
+
function renderSheet(renderer, target, scene, camera, frames, side) {
|
|
73
|
+
const previous = renderer.getRenderTarget();
|
|
74
|
+
renderer.setRenderTarget(target);
|
|
75
|
+
try {
|
|
76
|
+
renderer.clear(true, true, true);
|
|
77
|
+
for (const { matrix, x, y } of frames) {
|
|
78
|
+
// WebGPU counts viewport rows from the top; `readFloats` turns the image over.
|
|
79
|
+
const top = target.height - y - side;
|
|
80
|
+
target.viewport.set(x, top, side, side);
|
|
81
|
+
camera.matrix.copy(matrix);
|
|
82
|
+
camera.updateMatrixWorld(true);
|
|
83
|
+
renderer.render(scene, camera);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
renderer.setRenderTarget(previous);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=sheet.js.map
|
|
@@ -0,0 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import type { Object3D } from "three/webgpu";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { type BakeCopy } from "../../bake.js";
|
|
3
|
+
/** A copy of `object` to bake, which the bake may move and change; ImpostorMeshes are refused. */
|
|
4
|
+
export declare function sourceForBake(object: Object3D): Promise<BakeCopy>;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forEachMesh } from "../../
|
|
1
|
+
import { bakeCopy } from "../../bake.js";
|
|
2
|
+
import { forEachMesh } from "../../source/detail.js";
|
|
3
3
|
import { isImpostorMesh } from "../../three.js";
|
|
4
|
-
/**
|
|
5
|
-
export function sourceForBake(object
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (excluded.length > 0)
|
|
12
|
-
object.children = children.filter((child) => !excluded.includes(child));
|
|
13
|
-
forEachMesh(object, (mesh) => {
|
|
14
|
-
if (isImpostorMesh(mesh))
|
|
15
|
-
throw new Error(`bakeImpostor: cannot bake an ImpostorMesh ("${mesh.name}"); bake from its source instead`);
|
|
16
|
-
});
|
|
17
|
-
return clone(object);
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
object.children = children;
|
|
21
|
-
}
|
|
4
|
+
/** A copy of `object` to bake, which the bake may move and change; ImpostorMeshes are refused. */
|
|
5
|
+
export function sourceForBake(object) {
|
|
6
|
+
forEachMesh(object, (mesh) => {
|
|
7
|
+
if (isImpostorMesh(mesh))
|
|
8
|
+
throw new Error(`bakeImpostor: cannot bake an ImpostorMesh ("${mesh.name}"); bake from its source instead`);
|
|
9
|
+
});
|
|
10
|
+
return bakeCopy(object);
|
|
22
11
|
}
|
|
23
12
|
//# sourceMappingURL=source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/impostor/bake/source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../src/impostor/bake/source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,kGAAkG;AAClG,MAAM,UAAU,aAAa,CAAC,MAAgB;IAC5C,WAAW,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAC3B,IAAI,cAAc,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,CAAC,IAAI,kCAAkC,CAAC,CAAC;IACxI,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/impostor/codec.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type Impostor } from "./impostor.js";
|
|
2
2
|
/**
|
|
3
|
-
* Serializes `impostor
|
|
4
|
-
*
|
|
5
|
-
* "impostor" key.
|
|
3
|
+
* Serializes a baked `impostor`: every field but the layers as JSON, then one KTX2 file per map of GPU-compressible
|
|
4
|
+
* Basis UASTC, encoded in workers. A few seconds for a 1024 atlas.
|
|
6
5
|
*/
|
|
7
|
-
export declare function
|
|
8
|
-
/** Parses a file written by `
|
|
6
|
+
export declare function encodeImpostorAsync(impostor: Impostor): Promise<Uint8Array>;
|
|
7
|
+
/** Parses a file written by `encodeImpostorAsync`, transcoding its maps off the main thread to a format the GPU takes. */
|
|
9
8
|
export declare function decodeImpostorAsync(bytes: Uint8Array): Promise<Impostor>;
|
package/dist/impostor/codec.js
CHANGED
|
@@ -1,126 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { read } from "ktx-parse";
|
|
2
|
+
import { RGBAFormat } from "three/webgpu";
|
|
3
|
+
import { pack, unpack } from "../codec/container.js";
|
|
3
4
|
import { validateImpostor } from "./impostor.js";
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import { encodeLayer } from "./ktx2/encode.js";
|
|
6
|
+
import { transcode } from "./ktx2/transcode.js";
|
|
7
|
+
const srgb = (map) => map === "base" || map === "emissive";
|
|
6
8
|
/**
|
|
7
|
-
* Serializes `impostor
|
|
8
|
-
*
|
|
9
|
-
* "impostor" key.
|
|
9
|
+
* Serializes a baked `impostor`: every field but the layers as JSON, then one KTX2 file per map of GPU-compressible
|
|
10
|
+
* Basis UASTC, encoded in workers. A few seconds for a 1024 atlas.
|
|
10
11
|
*/
|
|
11
|
-
export function
|
|
12
|
+
export async function encodeImpostorAsync(impostor) {
|
|
12
13
|
validateImpostor(impostor);
|
|
13
14
|
const { layers, ...meta } = impostor;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
const ktx = createDefaultContainer();
|
|
23
|
-
ktx.vkFormat = VK_FORMAT_R8G8B8A8_UNORM;
|
|
24
|
-
ktx.typeSize = 1;
|
|
25
|
-
ktx.pixelWidth = meta.size;
|
|
26
|
-
ktx.pixelHeight = meta.size;
|
|
27
|
-
ktx.layerCount = layers.length;
|
|
28
|
-
ktx.levelCount = levels.length;
|
|
29
|
-
ktx.supercompressionScheme = KHR_SUPERCOMPRESSION_ZLIB;
|
|
30
|
-
ktx.levels = levels;
|
|
31
|
-
// UNORM data must declare a linear transfer; base/emissive are sRGB-encoded but the
|
|
32
|
-
// renderer decodes them itself, as it does with the linear normal/orm layers.
|
|
33
|
-
const channels = [KHR_DF_CHANNEL_RGBSDA_RED, KHR_DF_CHANNEL_RGBSDA_GREEN, KHR_DF_CHANNEL_RGBSDA_BLUE, KHR_DF_CHANNEL_RGBSDA_ALPHA];
|
|
34
|
-
for (const dfd of ktx.dataFormatDescriptor) {
|
|
35
|
-
dfd.colorModel = KHR_DF_MODEL_RGBSDA;
|
|
36
|
-
dfd.transferFunction = KHR_DF_TRANSFER_LINEAR;
|
|
37
|
-
dfd.bytesPlane = [4, 0, 0, 0, 0, 0, 0, 0];
|
|
38
|
-
dfd.samples = channels.map((channelType, i) => ({
|
|
39
|
-
bitOffset: i * 8,
|
|
40
|
-
bitLength: 7, // stored as bits - 1
|
|
41
|
-
channelType,
|
|
42
|
-
samplePosition: [0, 0, 0, 0],
|
|
43
|
-
sampleLower: 0,
|
|
44
|
-
sampleUpper: 255,
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
ktx.keyValue[KEY] = JSON.stringify(meta);
|
|
48
|
-
return write(ktx);
|
|
15
|
+
const files = await Promise.all(layers.map((layer, i) => {
|
|
16
|
+
const map = impostor.maps[i];
|
|
17
|
+
if (!map || layer.format !== RGBAFormat)
|
|
18
|
+
throw new Error("encodeImpostorAsync: encode a baked impostor; this one holds compressed blocks");
|
|
19
|
+
return encodeLayer({ levels: layer.mipmaps, size: impostor.size, srgb: srgb(map) });
|
|
20
|
+
}));
|
|
21
|
+
return pack(meta, files);
|
|
49
22
|
}
|
|
50
|
-
/** Parses a file written by `
|
|
23
|
+
/** Parses a file written by `encodeImpostorAsync`, transcoding its maps off the main thread to a format the GPU takes. */
|
|
51
24
|
export async function decodeImpostorAsync(bytes) {
|
|
52
|
-
const
|
|
53
|
-
|
|
25
|
+
const { header, files } = await unpack(bytes, fail);
|
|
26
|
+
if (typeof header !== "object" || header === null)
|
|
27
|
+
fail("metadata is not an object");
|
|
28
|
+
const size = Reflect.get(header, "size");
|
|
29
|
+
const layers = await Promise.all(files.map(async (file, i) => {
|
|
30
|
+
let ktx;
|
|
31
|
+
try {
|
|
32
|
+
ktx = read(file);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
fail(`map ${i} is not a KTX2 file`, error);
|
|
36
|
+
}
|
|
37
|
+
if (ktx.pixelWidth !== size || ktx.pixelHeight !== size)
|
|
38
|
+
fail(`map ${i} is ${ktx.pixelWidth}x${ktx.pixelHeight}, not the atlas size`);
|
|
54
39
|
try {
|
|
55
|
-
|
|
56
|
-
if (length >= 8 * 1024 * 1024)
|
|
57
|
-
return await new Promise((resolve, reject) => {
|
|
58
|
-
unzlib(data.slice(), { consume: true }, (error, raw) => {
|
|
59
|
-
if (error)
|
|
60
|
-
reject(error);
|
|
61
|
-
else
|
|
62
|
-
resolve(raw);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
const stream = new Blob([data.slice()]).stream().pipeThrough(new DecompressionStream("deflate"));
|
|
66
|
-
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
40
|
+
return await transcode(file);
|
|
67
41
|
}
|
|
68
42
|
catch (error) {
|
|
69
|
-
|
|
43
|
+
fail(`map ${i} does not transcode`, error);
|
|
70
44
|
}
|
|
71
45
|
}));
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
function parse(bytes) {
|
|
75
|
-
// ktx-parse reads through `bytes.buffer` without checking the view's end, so a truncated
|
|
76
|
-
// view would read past it; give it a buffer of exactly the file instead.
|
|
77
|
-
const file = bytes.byteLength === bytes.buffer.byteLength ? bytes : bytes.slice();
|
|
78
|
-
const ktx = attempt("not a KTX2 container", () => read(file));
|
|
79
|
-
if (ktx.vkFormat !== VK_FORMAT_R8G8B8A8_UNORM)
|
|
80
|
-
fail(`vkFormat ${ktx.vkFormat} is not R8G8B8A8_UNORM`);
|
|
81
|
-
if (ktx.supercompressionScheme !== KHR_SUPERCOMPRESSION_ZLIB)
|
|
82
|
-
fail(`supercompression ${ktx.supercompressionScheme} is not zlib`);
|
|
83
|
-
if (ktx.pixelWidth !== ktx.pixelHeight)
|
|
84
|
-
fail(`atlas is ${ktx.pixelWidth}x${ktx.pixelHeight}, not square`);
|
|
85
|
-
const json = ktx.keyValue[KEY];
|
|
86
|
-
if (!(json instanceof Uint8Array))
|
|
87
|
-
fail(`missing "${KEY}" metadata`);
|
|
88
|
-
// ktx-parse returns values of keys not starting with "KTX" as raw bytes, NUL included.
|
|
89
|
-
const meta = attempt("metadata is not JSON", () => JSON.parse(new TextDecoder().decode(json).replace(/\0$/, "")));
|
|
90
|
-
if (typeof meta !== "object" || meta === null)
|
|
91
|
-
fail("metadata is not an object");
|
|
92
|
-
const levels = ktx.levels.map((level, m) => {
|
|
93
|
-
const bytes = (ktx.pixelWidth >> m) ** 2 * 4;
|
|
94
|
-
if (level.uncompressedByteLength !== bytes * ktx.layerCount)
|
|
95
|
-
fail(`level ${m} size does not match the atlas`);
|
|
96
|
-
return { data: level.levelData, length: level.uncompressedByteLength };
|
|
97
|
-
});
|
|
98
|
-
return { meta, layerCount: ktx.layerCount, levels };
|
|
99
|
-
}
|
|
100
|
-
function decoded(file, levels) {
|
|
101
|
-
levels.forEach((raw, m) => {
|
|
102
|
-
if (raw.length !== file.levels[m]?.length)
|
|
103
|
-
fail(`level ${m} inflates to the wrong size`);
|
|
104
|
-
});
|
|
105
|
-
// Layers share one inflated buffer per mip, in KTX2's layer-major order.
|
|
106
|
-
const layers = Array.from({ length: file.layerCount }, (_, i) => levels.map((raw) => raw.subarray((i * raw.length) / file.layerCount, ((i + 1) * raw.length) / file.layerCount)));
|
|
107
|
-
const impostor = { ...file.meta, layers };
|
|
46
|
+
const impostor = { ...header, layers };
|
|
108
47
|
validateImpostor(impostor);
|
|
109
48
|
return impostor;
|
|
110
49
|
}
|
|
111
|
-
function fail(why) {
|
|
112
|
-
throw new Error(`Invalid impostor file: ${why}
|
|
113
|
-
}
|
|
114
|
-
/** Runs `run`, turning any throw into an "Invalid impostor file" error. */
|
|
115
|
-
function attempt(why, run) {
|
|
116
|
-
try {
|
|
117
|
-
return run();
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
throw invalid(why, error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function invalid(why, error) {
|
|
124
|
-
return new Error(`Invalid impostor file: ${why} (${error instanceof Error ? error.message : String(error)})`, { cause: error });
|
|
50
|
+
function fail(why, cause) {
|
|
51
|
+
throw new Error(`Invalid impostor file: ${why}`, { cause });
|
|
125
52
|
}
|
|
126
53
|
//# sourceMappingURL=codec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/impostor/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/impostor/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAmC,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,IAAI,GAAG,CAAC,GAAgB,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,UAAU,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAkB;IAC1D,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IACrC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QACtB,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;QAC3I,OAAO,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,QAA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AM,QAAQ,GAAY,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC;IAChD,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,IAAI,CAAC,GAAW,EAAE,KAAe;IACxC,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { RGBAFormat, type CompressedPixelFormat } from "three/webgpu";
|
|
1
2
|
/** Which part of the view sphere the atlas covers. */
|
|
2
3
|
export type ImpostorLayout = "hemi" | "full";
|
|
3
4
|
/**
|
|
4
|
-
* The atlas maps, in the order they are stored. Each is one
|
|
5
|
+
* The atlas maps, in the order they are stored. Each is one RGBA layer:
|
|
5
6
|
*
|
|
6
7
|
* - `base`: base colour (sRGB) in RGB, coverage in A.
|
|
7
8
|
* - `normalDepth`: an object-space normal n in RGB (`n * 0.5 + 0.5`), depth in A. The
|
|
@@ -13,6 +14,18 @@ export type ImpostorLayout = "hemi" | "full";
|
|
|
13
14
|
*/
|
|
14
15
|
export declare const MAPS: readonly ["base", "normalDepth", "orm", "emissive"];
|
|
15
16
|
export type ImpostorMap = (typeof MAPS)[number];
|
|
17
|
+
/**
|
|
18
|
+
* One map's mip chain, `size >> level` square, from `size` down to one texel per frame (`frames` square). The levels
|
|
19
|
+
* are baked, not filtered from level 0.
|
|
20
|
+
*/
|
|
21
|
+
export interface ImpostorLayer {
|
|
22
|
+
/**
|
|
23
|
+
* RGBAFormat: 4 bytes a texel, as baked. A decoded impostor holds the block-compressed format its decoder transcoded
|
|
24
|
+
* to for the GPU, or RGBAFormat where the GPU takes none.
|
|
25
|
+
*/
|
|
26
|
+
format: typeof RGBAFormat | CompressedPixelFormat;
|
|
27
|
+
mipmaps: Uint8Array[];
|
|
28
|
+
}
|
|
16
29
|
/**
|
|
17
30
|
* A baked octahedral impostor: plain data, no GPU resources.
|
|
18
31
|
*
|
|
@@ -25,7 +38,7 @@ export type ImpostorMap = (typeof MAPS)[number];
|
|
|
25
38
|
* toward the camera that baked the frame and 0 is away from it.
|
|
26
39
|
*/
|
|
27
40
|
export interface Impostor {
|
|
28
|
-
version:
|
|
41
|
+
version: 4;
|
|
29
42
|
layout: ImpostorLayout;
|
|
30
43
|
/** frames per atlas side */
|
|
31
44
|
frames: number;
|
|
@@ -45,22 +58,33 @@ export interface Impostor {
|
|
|
45
58
|
*/
|
|
46
59
|
specular?: [number, number, number, number];
|
|
47
60
|
/**
|
|
48
|
-
* One per entry in `maps
|
|
49
|
-
*
|
|
50
|
-
* filtered from level 0. An ImpostorMesh's textures share these arrays, so they stay in
|
|
51
|
-
* memory while the impostor is referenced, ready for `encodeImpostor`.
|
|
61
|
+
* One per entry in `maps`. An ImpostorMesh's textures share these arrays, so they stay in memory while the impostor is
|
|
62
|
+
* referenced, ready for `encodeImpostorAsync` when they are RGBAFormat.
|
|
52
63
|
*/
|
|
53
|
-
layers:
|
|
64
|
+
layers: ImpostorLayer[];
|
|
54
65
|
}
|
|
55
66
|
export declare function boxCentre(b: Impostor["box"]): [number, number, number];
|
|
56
67
|
/** Half the box's edges. */
|
|
57
68
|
export declare function boxExtent(b: Impostor["box"]): [number, number, number];
|
|
58
69
|
/** Radius of the sphere around the box: the depth channel's unit. */
|
|
59
70
|
export declare function boundingRadius(b: Impostor["box"]): number;
|
|
71
|
+
/**
|
|
72
|
+
* Empty border around the object in every frame, as a fraction of the frame's half
|
|
73
|
+
* size. It keeps mip levels from blending a frame's silhouette into its neighbour.
|
|
74
|
+
*/
|
|
75
|
+
export declare const PAD = 0.06;
|
|
76
|
+
/**
|
|
77
|
+
* `texelPixels` of any impostor baked at `resolution`, at least: a frame fitted to the source's bounding sphere, the
|
|
78
|
+
* widest it can be. The default `maxPixels` of an impostor level a loader describes before building it.
|
|
79
|
+
*/
|
|
80
|
+
export declare const framePixels: (resolution?: number) => number;
|
|
60
81
|
/**
|
|
61
82
|
* On-screen height of the object at which two atlas texels span one pixel: the default
|
|
62
83
|
* `LodLevel.maxPixels` of an impostor. An impostor blends filtered reads of several
|
|
63
84
|
* views, so it keeps the source's colour detail only down to about two texels per pixel.
|
|
85
|
+
* A CachedLodLoader describes its levels before baking them, so its impostor levels default to
|
|
86
|
+
* `framePixels` instead: this height for a frame fitted to the bounding sphere, up to about
|
|
87
|
+
* 1.5 times lower than for the frame the bake fits.
|
|
64
88
|
*/
|
|
65
89
|
export declare function texelPixels(impostor: Pick<Impostor, "size" | "frames" | "box" | "halfSize">): number;
|
|
66
90
|
/** Throws unless `value` is a usable impostor. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { RGBAFormat } from "three/webgpu";
|
|
1
2
|
/**
|
|
2
|
-
* The atlas maps, in the order they are stored. Each is one
|
|
3
|
+
* The atlas maps, in the order they are stored. Each is one RGBA layer:
|
|
3
4
|
*
|
|
4
5
|
* - `base`: base colour (sRGB) in RGB, coverage in A.
|
|
5
6
|
* - `normalDepth`: an object-space normal n in RGB (`n * 0.5 + 0.5`), depth in A. The
|
|
@@ -21,10 +22,23 @@ export function boxExtent(b) {
|
|
|
21
22
|
export function boundingRadius(b) {
|
|
22
23
|
return Math.hypot(b[3] - b[0], b[4] - b[1], b[5] - b[2]) / 2;
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Empty border around the object in every frame, as a fraction of the frame's half
|
|
27
|
+
* size. It keeps mip levels from blending a frame's silhouette into its neighbour.
|
|
28
|
+
*/
|
|
29
|
+
export const PAD = 0.06;
|
|
30
|
+
/**
|
|
31
|
+
* `texelPixels` of any impostor baked at `resolution`, at least: a frame fitted to the source's bounding sphere, the
|
|
32
|
+
* widest it can be. The default `maxPixels` of an impostor level a loader describes before building it.
|
|
33
|
+
*/
|
|
34
|
+
export const framePixels = (resolution = 128) => 2 ** Math.floor(Math.log2(resolution)) / (2 * (1 + PAD));
|
|
24
35
|
/**
|
|
25
36
|
* On-screen height of the object at which two atlas texels span one pixel: the default
|
|
26
37
|
* `LodLevel.maxPixels` of an impostor. An impostor blends filtered reads of several
|
|
27
38
|
* views, so it keeps the source's colour detail only down to about two texels per pixel.
|
|
39
|
+
* A CachedLodLoader describes its levels before baking them, so its impostor levels default to
|
|
40
|
+
* `framePixels` instead: this height for a frame fitted to the bounding sphere, up to about
|
|
41
|
+
* 1.5 times lower than for the frame the bake fits.
|
|
28
42
|
*/
|
|
29
43
|
export function texelPixels(impostor) {
|
|
30
44
|
const cell = impostor.size / impostor.frames;
|
|
@@ -42,7 +56,7 @@ export function validateImpostor(value) {
|
|
|
42
56
|
fail("not an object");
|
|
43
57
|
const fields = value;
|
|
44
58
|
const { version, layout, frames, size, box, halfSize, maps, specular, layers } = fields;
|
|
45
|
-
if (version !==
|
|
59
|
+
if (version !== 4)
|
|
46
60
|
fail(`unsupported version ${String(version)}; bake it again`);
|
|
47
61
|
if (layout !== "hemi" && layout !== "full")
|
|
48
62
|
fail(`unknown layout "${String(layout)}"`);
|
|
@@ -67,12 +81,13 @@ export function validateImpostor(value) {
|
|
|
67
81
|
fail(`frame size ${cell} is not a power of two`);
|
|
68
82
|
const levels = Math.log2(cell) + 1;
|
|
69
83
|
for (const layer of layers) {
|
|
70
|
-
if (!Array.isArray(layer) || layer.length !== levels)
|
|
84
|
+
if (typeof layer !== "object" || layer === null || !Array.isArray(layer.mipmaps) || layer.mipmaps.length !== levels)
|
|
71
85
|
fail(`every layer must be a mip chain of ${levels} levels`);
|
|
72
|
-
layer.
|
|
86
|
+
const rgba = layer.format === RGBAFormat;
|
|
87
|
+
layer.mipmaps.forEach((level, m) => {
|
|
73
88
|
const bytes = (size >> m) ** 2 * 4;
|
|
74
|
-
if (!(level instanceof Uint8Array) || level.length !== bytes)
|
|
75
|
-
fail(`mip level ${m} must be a Uint8Array of ${bytes} bytes`);
|
|
89
|
+
if (!(level instanceof Uint8Array) || (rgba ? level.length !== bytes : !level.length))
|
|
90
|
+
fail(`mip level ${m} must be a Uint8Array${rgba ? ` of ${bytes} bytes` : ""}`);
|
|
76
91
|
});
|
|
77
92
|
}
|
|
78
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impostor.js","sourceRoot":"","sources":["../../src/impostor/impostor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"impostor.js","sourceRoot":"","sources":["../../src/impostor/impostor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA8B,MAAM,cAAc,CAAC;AAKtE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,CAAU,CAAC;AAsDxE,MAAM,UAAU,SAAS,CAAC,CAAkB;IAC1C,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,SAAS,CAAC,CAAkB;IAC1C,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,cAAc,CAAC,CAAkB;IAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,G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AAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM;YACjH,IAAI,CAAC,sCAAsC,MAAM,SAAS,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,KAAK,UAAU,CAAC;QACzC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAc,EAAE,CAAS,EAAE,EAAE;YAClD,MAAM,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;gBACnF,IAAI,CAAC,aAAa,CAAC,wBAAwB,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACnF,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** One map's RGBA8 mip levels, `size >> level` square. */
|
|
2
|
+
export interface Layer {
|
|
3
|
+
levels: Uint8Array[];
|
|
4
|
+
size: number;
|
|
5
|
+
/** Whether the texels are sRGB-encoded colour; otherwise linear data. */
|
|
6
|
+
srgb: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** What the worker encodes: RGBA8 rows of a mip level, `width` wide and `height` high. */
|
|
9
|
+
export interface Job {
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
srgb: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** What the worker answers a job with. */
|
|
16
|
+
export type Reply = {
|
|
17
|
+
file: Uint8Array;
|
|
18
|
+
} | {
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* One map as a KTX2 file of Basis UASTC. Each level encodes as `parts` strips of rows, by default one per worker, so
|
|
23
|
+
* that a map's top level, which holds three quarters of its texels, takes all workers; the strips' and levels' files
|
|
24
|
+
* are then joined. Takes about a second per million texels and worker.
|
|
25
|
+
*/
|
|
26
|
+
export declare function encodeLayer({ levels, size, srgb }: Layer, parts?: number): Promise<Uint8Array>;
|