@drawcall/lod 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +83 -2
- package/dist/baked/codec.d.ts +10 -0
- package/dist/baked/codec.js +291 -0
- package/dist/baked/codec.js.map +1 -0
- package/dist/baked/index.d.ts +51 -0
- package/dist/baked/index.js +183 -0
- package/dist/baked/index.js.map +1 -0
- package/dist/baked/interior/faces.d.ts +26 -0
- package/dist/baked/interior/faces.js +105 -0
- package/dist/baked/interior/faces.js.map +1 -0
- package/dist/baked/interior/material.d.ts +31 -0
- package/dist/baked/interior/material.js +157 -0
- package/dist/baked/interior/material.js.map +1 -0
- package/dist/baked/interior/rooms.d.ts +22 -0
- package/dist/baked/interior/rooms.js +78 -0
- package/dist/baked/interior/rooms.js.map +1 -0
- package/dist/baked/low.d.ts +20 -0
- package/dist/baked/low.js +75 -0
- package/dist/baked/low.js.map +1 -0
- package/dist/baked/raster.d.ts +20 -0
- package/dist/baked/raster.js +71 -0
- package/dist/baked/raster.js.map +1 -0
- package/dist/baked/transfer.d.ts +36 -0
- package/dist/baked/transfer.js +243 -0
- package/dist/baked/transfer.js.map +1 -0
- package/dist/baked/unwrap.d.ts +9 -0
- package/dist/baked/unwrap.js +167 -0
- package/dist/baked/unwrap.js.map +1 -0
- package/dist/baked/xatlas.d.ts +2 -0
- package/dist/baked/xatlas.js +31 -0
- package/dist/baked/xatlas.js.map +1 -0
- package/dist/bounds.d.ts +33 -0
- package/dist/bounds.js +127 -0
- package/dist/bounds.js.map +1 -0
- package/dist/dispose.d.ts +5 -0
- package/dist/dispose.js +28 -0
- package/dist/dispose.js.map +1 -0
- package/dist/fade.d.ts +44 -0
- package/dist/fade.js +78 -0
- package/dist/fade.js.map +1 -0
- package/dist/impostor/bake/atlas.d.ts +51 -0
- package/dist/impostor/bake/atlas.js +190 -0
- package/dist/impostor/bake/atlas.js.map +1 -0
- package/dist/impostor/bake/index.d.ts +50 -0
- package/dist/impostor/bake/index.js +221 -0
- package/dist/impostor/bake/index.js.map +1 -0
- package/dist/impostor/bake/materials.d.ts +29 -0
- package/dist/impostor/bake/materials.js +156 -0
- package/dist/impostor/bake/materials.js.map +1 -0
- package/dist/impostor/bake/source.d.ts +3 -0
- package/dist/impostor/bake/source.js +23 -0
- package/dist/impostor/bake/source.js.map +1 -0
- package/dist/impostor/cache.d.ts +15 -0
- package/dist/impostor/cache.js +44 -0
- package/dist/impostor/cache.js.map +1 -0
- package/dist/impostor/codec.d.ts +14 -0
- package/dist/impostor/codec.js +137 -0
- package/dist/impostor/codec.js.map +1 -0
- package/dist/impostor/impostor.d.ts +67 -0
- package/dist/impostor/impostor.js +79 -0
- package/dist/impostor/impostor.js.map +1 -0
- package/dist/impostor/mesh/card.d.ts +38 -0
- package/dist/impostor/mesh/card.js +79 -0
- package/dist/impostor/mesh/card.js.map +1 -0
- package/dist/impostor/mesh/index.d.ts +66 -0
- package/dist/impostor/mesh/index.js +174 -0
- package/dist/impostor/mesh/index.js.map +1 -0
- package/dist/impostor/mesh/material.d.ts +63 -0
- package/dist/impostor/mesh/material.js +199 -0
- package/dist/impostor/mesh/material.js.map +1 -0
- package/dist/impostor/mesh/surface.d.ts +63 -0
- package/dist/impostor/mesh/surface.js +162 -0
- package/dist/impostor/mesh/surface.js.map +1 -0
- package/dist/impostor/mesh/textures.d.ts +4 -0
- package/dist/impostor/mesh/textures.js +37 -0
- package/dist/impostor/mesh/textures.js.map +1 -0
- package/dist/impostor/octahedral.d.ts +29 -0
- package/dist/impostor/octahedral.js +83 -0
- package/dist/impostor/octahedral.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/instanced/args.d.ts +20 -0
- package/dist/instanced/args.js +77 -0
- package/dist/instanced/args.js.map +1 -0
- package/dist/instanced/bounds.d.ts +50 -0
- package/dist/instanced/bounds.js +271 -0
- package/dist/instanced/bounds.js.map +1 -0
- package/dist/instanced/dirty.d.ts +12 -0
- package/dist/instanced/dirty.js +61 -0
- package/dist/instanced/dirty.js.map +1 -0
- package/dist/instanced/index.d.ts +116 -0
- package/dist/instanced/index.js +573 -0
- package/dist/instanced/index.js.map +1 -0
- package/dist/instanced/meshes.d.ts +14 -0
- package/dist/instanced/meshes.js +54 -0
- package/dist/instanced/meshes.js.map +1 -0
- package/dist/instanced/select.d.ts +84 -0
- package/dist/instanced/select.js +264 -0
- package/dist/instanced/select.js.map +1 -0
- package/dist/lazy.d.ts +64 -0
- package/dist/lazy.js +187 -0
- package/dist/lazy.js.map +1 -0
- package/dist/levels.d.ts +72 -0
- package/dist/levels.js +146 -0
- package/dist/levels.js.map +1 -0
- package/dist/loader/cache.d.ts +15 -0
- package/dist/loader/cache.js +37 -0
- package/dist/loader/cache.js.map +1 -0
- package/dist/loader/dispose.d.ts +3 -0
- package/dist/loader/dispose.js +25 -0
- package/dist/loader/dispose.js.map +1 -0
- package/dist/loader.d.ts +99 -0
- package/dist/loader.js +234 -0
- package/dist/loader.js.map +1 -0
- package/dist/lod.d.ts +78 -0
- package/dist/lod.js +211 -0
- package/dist/lod.js.map +1 -0
- package/dist/material.d.ts +12 -0
- package/dist/material.js +52 -0
- package/dist/material.js.map +1 -0
- package/dist/pause.d.ts +6 -0
- package/dist/pause.js +20 -0
- package/dist/pause.js.map +1 -0
- package/dist/renderer.d.ts +21 -0
- package/dist/renderer.js +83 -0
- package/dist/renderer.js.map +1 -0
- package/dist/simplify.d.ts +24 -0
- package/dist/simplify.js +148 -0
- package/dist/simplify.js.map +1 -0
- package/dist/source/error.d.ts +14 -0
- package/dist/source/error.js +94 -0
- package/dist/source/error.js.map +1 -0
- package/dist/source/frame.d.ts +11 -0
- package/dist/source/frame.js +25 -0
- package/dist/source/frame.js.map +1 -0
- package/dist/source/shading.d.ts +96 -0
- package/dist/source/shading.js +224 -0
- package/dist/source/shading.js.map +1 -0
- package/dist/source/source.d.ts +23 -0
- package/dist/source/source.js +50 -0
- package/dist/source/source.js.map +1 -0
- package/dist/source/surface.d.ts +31 -0
- package/dist/source/surface.js +110 -0
- package/dist/source/surface.js.map +1 -0
- package/dist/source/texels.d.ts +45 -0
- package/dist/source/texels.js +191 -0
- package/dist/source/texels.js.map +1 -0
- package/dist/source/trace.d.ts +42 -0
- package/dist/source/trace.js +153 -0
- package/dist/source/trace.js.map +1 -0
- package/dist/three.d.ts +55 -0
- package/dist/three.js +103 -0
- package/dist/three.js.map +1 -0
- package/dist/tsl.d.ts +45 -0
- package/dist/tsl.js +99 -0
- package/dist/tsl.js.map +1 -0
- package/dist/view.d.ts +30 -0
- package/dist/view.js +75 -0
- package/dist/view.js.map +1 -0
- package/dist/wind/bounds.d.ts +3 -0
- package/dist/wind/bounds.js +47 -0
- package/dist/wind/bounds.js.map +1 -0
- package/dist/wind/hooks.d.ts +5 -0
- package/dist/wind/hooks.js +3 -0
- package/dist/wind/hooks.js.map +1 -0
- package/dist/wind/index.d.ts +57 -0
- package/dist/wind/index.js +196 -0
- package/dist/wind/index.js.map +1 -0
- package/dist/wind/sway.d.ts +29 -0
- package/dist/wind/sway.js +71 -0
- package/dist/wind/sway.js.map +1 -0
- package/package.json +69 -3
- package/skills/lod/SKILL.md +137 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Drawcall
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @drawcall/lod
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Level of detail for three.js. Load a model, get cheaper levels built for it — an
|
|
4
|
+
octahedral impostor, a simplified mesh, a baked low-poly mesh — and switch between them
|
|
5
|
+
by on-screen size, with a dithered fade so the switch does not pop.
|
|
6
|
+
|
|
7
|
+
**WebGPURenderer only** (`three/webgpu`): levels draw with three's node materials, and an
|
|
8
|
+
`InstancedLod` selects its instances' levels on the GPU.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @drawcall/lod three
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { LodLoader } from "@drawcall/lod";
|
|
18
|
+
|
|
19
|
+
const loader = new LodLoader(manager); // a three.js Loader
|
|
20
|
+
const tree = await loader.loadAsync("/models/tree.glb"); // source → impostor
|
|
21
|
+
scene.add(tree); // the renderer switches levels by itself, shadows included
|
|
22
|
+
|
|
23
|
+
const rock = await loader.loadAsync({ url: "/models/rock.glb", levels: [{ type: "simplified" }, { type: "impostor" }] });
|
|
24
|
+
const house = await loader.loadAsync({
|
|
25
|
+
url: "/models/house.glb",
|
|
26
|
+
levels: [
|
|
27
|
+
{ type: "baked", low: "/models/house-low.glb" },
|
|
28
|
+
{ type: "impostor", layout: "hemi" },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Which levels for which asset
|
|
34
|
+
|
|
35
|
+
| Asset | Levels |
|
|
36
|
+
| --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
+
| Foliage: trees, bushes, grass, plants — anything of alpha-tested leaf cards | the default: straight to an `impostor` (`layout: "hemi"` if it stands upright). Never a `simplified` level: decimation tears leaf cards apart |
|
|
38
|
+
| Closed hard-surface meshes: props, rocks, vehicles | `simplified`, then `impostor` |
|
|
39
|
+
| Buildings and large hard surfaces | `baked` onto an authored or generated low mesh, then `impostor`; with `interior: "/models/house-rooms.glts"` its windows show the rooms behind them |
|
|
40
|
+
| Low-poly props | `simplified`, or none: an impostor costs more than the mesh |
|
|
41
|
+
|
|
42
|
+
A `"baked"` level (experimental) is one low-poly mesh with the source's colour, normals
|
|
43
|
+
and material values baked into its own textures. Its low mesh has to keep the silhouette
|
|
44
|
+
(eaves, chimneys): only surface detail moves into its textures.
|
|
45
|
+
|
|
46
|
+
`.glb`/`.gltf` load through the manager's handler when one is registered (a GLTFLoader
|
|
47
|
+
with Draco), `.glts` through a registered `GLTSLoader` from `@drawcall/glts`. Levels are
|
|
48
|
+
built at load time.
|
|
49
|
+
|
|
50
|
+
For many copies, `loader.loadInstancesAsync(url, count)` gives an `InstancedLod`: one
|
|
51
|
+
draw per level and mesh, each instance switching by its own size on screen; place them
|
|
52
|
+
with `setMatrixAt`.
|
|
53
|
+
|
|
54
|
+
For vegetation, apply one shared breeze after building the levels:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { Wind } from "@drawcall/lod";
|
|
58
|
+
|
|
59
|
+
const wind = new Wind({ direction: [1, 0.3], speed: 0.25 });
|
|
60
|
+
wind.apply(tree, { amplitude: 0.2 }); // source, cheaper levels and shadows sway together
|
|
61
|
+
// Before rendering each frame:
|
|
62
|
+
wind.time = elapsedSeconds;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The same call works on an `InstancedLod` or a standalone mesh. Objects without wind
|
|
66
|
+
keep their static rendering path.
|
|
67
|
+
|
|
68
|
+
Bring your own levels with `new Lod([source, ...levels])` or
|
|
69
|
+
`new InstancedLod([source, ...levels], count)`: any `Object3D`, including another `Lod`
|
|
70
|
+
(but not inside an `InstancedLod`). `Lod.quality` trades detail for speed globally,
|
|
71
|
+
`Lod.debug` tints each level, `lod.forceLevel` pins one.
|
|
72
|
+
|
|
73
|
+
### Building blocks
|
|
74
|
+
|
|
75
|
+
The pieces behind the loader are exported too: `simplify` (meshoptimizer), `bakeMesh`
|
|
76
|
+
(the baked level), `bakeImpostor` and `ImpostorMesh` (one draw for thousands of
|
|
77
|
+
impostors, placed like an `InstancedMesh`'s instances), and `encodeImpostor`/`decodeImpostor` to save
|
|
78
|
+
impostors as KTX2.
|
|
79
|
+
|
|
80
|
+
The package ships a skill for coding agents with the details of when to use which part.
|
|
81
|
+
|
|
82
|
+
The showcase, `examples/city` (`pnpm city`), flies over a 4 km world from two
|
|
83
|
+
kilometres up down to a ladybird on a corn leaf, every kind of content on the levels
|
|
84
|
+
that suit it.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Mesh } from "three/webgpu";
|
|
2
|
+
/**
|
|
3
|
+
* Encode an unmodified `bakeMesh` result, before adding it to a Lod or changing its
|
|
4
|
+
* materials. This is a baked-result format, not an Object3D/NodeMaterial serializer.
|
|
5
|
+
* Geometry, map bytes (including cutout mips), rooms, placement and LOD error survive
|
|
6
|
+
* exactly. Decoding owns fresh resources; the input mesh remains owned by its caller.
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeBakedMesh(mesh: Mesh): Uint8Array;
|
|
9
|
+
/** Decode `encodeBakedMesh` bytes into an independently owned mesh, ready for a Lod. */
|
|
10
|
+
export declare function decodeBakedMesh(input: Uint8Array | ArrayBuffer): Mesh;
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
2
|
+
import { Box3, BufferAttribute, BufferGeometry, ClampToEdgeWrapping, DataArrayTexture, DataTexture, DoubleSide, FrontSide, LinearFilter, LinearMipmapLinearFilter, Mesh, MeshStandardNodeMaterial, NoColorSpace, RGBAFormat, RGFormat, SRGBColorSpace, UnsignedByteType, UVMapping, Vector3, } from "three/webgpu";
|
|
3
|
+
import { errorOf, recordError } from "../levels.js";
|
|
4
|
+
import { InteriorMaterial } from "./interior/material.js";
|
|
5
|
+
function fail(why) {
|
|
6
|
+
throw new Error(`Invalid baked mesh: ${why}`);
|
|
7
|
+
}
|
|
8
|
+
const object = (value) => {
|
|
9
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
10
|
+
fail("expected metadata object");
|
|
11
|
+
return Object.fromEntries(Object.entries(value));
|
|
12
|
+
};
|
|
13
|
+
const number = (value) => (typeof value === "number" && Number.isFinite(value) ? value : fail("expected finite number"));
|
|
14
|
+
const integer = (value) => {
|
|
15
|
+
const result = number(value);
|
|
16
|
+
return Number.isSafeInteger(result) && result > 0 ? result : fail("expected positive integer");
|
|
17
|
+
};
|
|
18
|
+
const boolean = (value) => (typeof value === "boolean" ? value : fail("expected boolean"));
|
|
19
|
+
const numbers = (value, count) => {
|
|
20
|
+
if (!Array.isArray(value) || value.length !== count)
|
|
21
|
+
fail(`expected ${count} numbers`);
|
|
22
|
+
return value.map(number);
|
|
23
|
+
};
|
|
24
|
+
const file = (files, name) => files[name] ?? fail(`missing ${name}`);
|
|
25
|
+
/**
|
|
26
|
+
* Encode an unmodified `bakeMesh` result, before adding it to a Lod or changing its
|
|
27
|
+
* materials. This is a baked-result format, not an Object3D/NodeMaterial serializer.
|
|
28
|
+
* Geometry, map bytes (including cutout mips), rooms, placement and LOD error survive
|
|
29
|
+
* exactly. Decoding owns fresh resources; the input mesh remains owned by its caller.
|
|
30
|
+
*/
|
|
31
|
+
export function encodeBakedMesh(mesh) {
|
|
32
|
+
const error = errorOf(mesh);
|
|
33
|
+
const { geometry, material } = mesh;
|
|
34
|
+
if (error === undefined || !(error >= 0) || !Number.isFinite(error))
|
|
35
|
+
fail("expected a bakeMesh result with its LOD error");
|
|
36
|
+
if (mesh.children.length ||
|
|
37
|
+
!mesh.matrixAutoUpdate ||
|
|
38
|
+
!mesh.visible ||
|
|
39
|
+
mesh.renderOrder !== 0 ||
|
|
40
|
+
mesh.layers.mask !== 1 ||
|
|
41
|
+
geometry.groups.length ||
|
|
42
|
+
Object.keys(geometry.morphAttributes).length ||
|
|
43
|
+
geometry.drawRange.start !== 0 ||
|
|
44
|
+
geometry.drawRange.count !== Infinity)
|
|
45
|
+
fail("modified baked geometry");
|
|
46
|
+
if (!(material instanceof MeshStandardNodeMaterial) ||
|
|
47
|
+
(Object.getPrototypeOf(material) !== MeshStandardNodeMaterial.prototype && Object.getPrototypeOf(material) !== InteriorMaterial.prototype))
|
|
48
|
+
fail("unsupported material");
|
|
49
|
+
const standard = new MeshStandardNodeMaterial();
|
|
50
|
+
// Only the maps, side and alphaTest differ from a default baked material. Refuse
|
|
51
|
+
// shader hooks and material changes rather than silently dropping them from a cache.
|
|
52
|
+
const allowed = new Set([
|
|
53
|
+
"uuid",
|
|
54
|
+
"id",
|
|
55
|
+
"version",
|
|
56
|
+
"_listeners",
|
|
57
|
+
"map",
|
|
58
|
+
"normalMap",
|
|
59
|
+
"aoMap",
|
|
60
|
+
"roughnessMap",
|
|
61
|
+
"metalnessMap",
|
|
62
|
+
"roughness",
|
|
63
|
+
"metalness",
|
|
64
|
+
"alphaTest",
|
|
65
|
+
"_alphaTest",
|
|
66
|
+
"side",
|
|
67
|
+
"rooms",
|
|
68
|
+
"bounds",
|
|
69
|
+
"isInteriorMaterial",
|
|
70
|
+
]);
|
|
71
|
+
for (const [key, value] of Object.entries(material)) {
|
|
72
|
+
if (allowed.has(key))
|
|
73
|
+
continue;
|
|
74
|
+
const expected = Reflect.get(standard, key);
|
|
75
|
+
if (typeof value === "function" ? value !== expected : JSON.stringify(value) !== JSON.stringify(expected))
|
|
76
|
+
fail(`modified material.${key}`);
|
|
77
|
+
}
|
|
78
|
+
if (material.roughness !== 1 ||
|
|
79
|
+
material.metalness !== 1 ||
|
|
80
|
+
![0, 0.5].includes(material.alphaTest) ||
|
|
81
|
+
(material.side !== FrontSide && material.side !== DoubleSide) ||
|
|
82
|
+
material.aoMap !== material.roughnessMap ||
|
|
83
|
+
material.aoMap !== material.metalnessMap)
|
|
84
|
+
fail("modified baked material");
|
|
85
|
+
if (Object.keys(geometry.attributes).sort().join() !== "normal,position,uv")
|
|
86
|
+
fail("unsupported geometry attributes");
|
|
87
|
+
const files = {};
|
|
88
|
+
for (const [name, size] of [
|
|
89
|
+
["position", 3],
|
|
90
|
+
["normal", 3],
|
|
91
|
+
["uv", 2],
|
|
92
|
+
]) {
|
|
93
|
+
const attribute = geometry.getAttribute(name);
|
|
94
|
+
if (!(attribute instanceof BufferAttribute) || !(attribute.array instanceof Float32Array) || attribute.itemSize !== size || attribute.normalized)
|
|
95
|
+
fail(`unsupported ${name} attribute`);
|
|
96
|
+
files[name] = new Uint8Array(attribute.array.buffer, attribute.array.byteOffset, attribute.array.byteLength);
|
|
97
|
+
}
|
|
98
|
+
const index = geometry.index;
|
|
99
|
+
if (!index || !(index.array instanceof Uint32Array) || index.itemSize !== 1)
|
|
100
|
+
fail("expected Uint32 indices");
|
|
101
|
+
files.index = new Uint8Array(index.array.buffer, index.array.byteOffset, index.array.byteLength);
|
|
102
|
+
const rooms = material instanceof InteriorMaterial ? (material.rooms ?? fail("unfurnished interior")) : null;
|
|
103
|
+
const meta = {
|
|
104
|
+
version: 1,
|
|
105
|
+
name: mesh.name,
|
|
106
|
+
error,
|
|
107
|
+
position: mesh.position.toArray(),
|
|
108
|
+
quaternion: mesh.quaternion.toArray(),
|
|
109
|
+
scale: mesh.scale.toArray(),
|
|
110
|
+
castShadow: mesh.castShadow,
|
|
111
|
+
receiveShadow: mesh.receiveShadow,
|
|
112
|
+
side: material.side,
|
|
113
|
+
alphaTest: material.alphaTest,
|
|
114
|
+
map: writeTexture(files, "map", material.map),
|
|
115
|
+
normal: writeTexture(files, "normal", material.normalMap),
|
|
116
|
+
orm: writeTexture(files, "orm", material.aoMap),
|
|
117
|
+
rooms: rooms && {
|
|
118
|
+
boxes: rooms.boxes.map((box) => [...box.min.toArray(), ...box.max.toArray()]),
|
|
119
|
+
span: rooms.span,
|
|
120
|
+
windows: writeTexture(files, "windows", rooms.windows),
|
|
121
|
+
response: writeTexture(files, "response", rooms.response),
|
|
122
|
+
glow: rooms.glow && writeTexture(files, "glow", rooms.glow),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
files.meta = strToU8(JSON.stringify(meta));
|
|
126
|
+
return zipSync(files, { level: 6 });
|
|
127
|
+
}
|
|
128
|
+
/** Decode `encodeBakedMesh` bytes into an independently owned mesh, ready for a Lod. */
|
|
129
|
+
export function decodeBakedMesh(input) {
|
|
130
|
+
const files = unzipSync(input instanceof Uint8Array ? input : new Uint8Array(input));
|
|
131
|
+
const parsed = JSON.parse(strFromU8(file(files, "meta")));
|
|
132
|
+
const meta = object(parsed);
|
|
133
|
+
if (meta.version !== 1)
|
|
134
|
+
fail("unsupported version");
|
|
135
|
+
if (typeof meta.name !== "string")
|
|
136
|
+
fail("missing name");
|
|
137
|
+
const error = number(meta.error);
|
|
138
|
+
if (error < 0)
|
|
139
|
+
fail("negative LOD error");
|
|
140
|
+
const position = floats(file(files, "position"));
|
|
141
|
+
const normal = floats(file(files, "normal"));
|
|
142
|
+
const uv = floats(file(files, "uv"));
|
|
143
|
+
const indices = file(files, "index");
|
|
144
|
+
if (!position.length || position.length % 3 || normal.length !== position.length || uv.length * 3 !== position.length * 2 || indices.byteLength % 12)
|
|
145
|
+
fail("invalid geometry lengths");
|
|
146
|
+
const index = new Uint32Array(indices.slice().buffer);
|
|
147
|
+
if (index.some((i) => i >= position.length / 3))
|
|
148
|
+
fail("index outside geometry");
|
|
149
|
+
const side = meta.side === FrontSide ? FrontSide : meta.side === DoubleSide ? DoubleSide : fail("unsupported side");
|
|
150
|
+
const alphaTest = meta.alphaTest === 0 ? 0 : meta.alphaTest === 0.5 ? 0.5 : fail("unsupported alpha test");
|
|
151
|
+
const map = readTexture(files, "map", meta.map, false);
|
|
152
|
+
const normalMap = readTexture(files, "normal", meta.normal, false);
|
|
153
|
+
const orm = readTexture(files, "orm", meta.orm, false);
|
|
154
|
+
const material = meta.rooms === null ? new MeshStandardNodeMaterial() : new InteriorMaterial();
|
|
155
|
+
material.setValues({ map, normalMap, aoMap: orm, roughnessMap: orm, metalnessMap: orm, roughness: 1, metalness: 1, side, alphaTest });
|
|
156
|
+
if (material instanceof InteriorMaterial) {
|
|
157
|
+
const rooms = object(meta.rooms);
|
|
158
|
+
if (!Array.isArray(rooms.boxes) || !rooms.boxes.length)
|
|
159
|
+
fail("missing room boxes");
|
|
160
|
+
const boxes = rooms.boxes.map((value) => {
|
|
161
|
+
const box = numbers(value, 6);
|
|
162
|
+
const result = new Box3(new Vector3().fromArray(box), new Vector3().fromArray(box, 3));
|
|
163
|
+
if (result.isEmpty())
|
|
164
|
+
fail("empty room");
|
|
165
|
+
return result;
|
|
166
|
+
});
|
|
167
|
+
const response = readTexture(files, "response", rooms.response, true);
|
|
168
|
+
const glow = rooms.glow === null ? null : readTexture(files, "glow", rooms.glow, true);
|
|
169
|
+
if (response.image.depth !== boxes.length * 6 || (glow && glow.image.depth !== response.image.depth))
|
|
170
|
+
fail("room texture layer count");
|
|
171
|
+
const windows = readTexture(files, "windows", rooms.windows, false);
|
|
172
|
+
const span = number(rooms.span);
|
|
173
|
+
if (span <= 0)
|
|
174
|
+
fail("invalid room span");
|
|
175
|
+
material.furnish({ boxes, span, response, glow, windows });
|
|
176
|
+
}
|
|
177
|
+
const geometry = new BufferGeometry();
|
|
178
|
+
geometry.setAttribute("position", new BufferAttribute(position, 3));
|
|
179
|
+
geometry.setAttribute("normal", new BufferAttribute(normal, 3));
|
|
180
|
+
geometry.setAttribute("uv", new BufferAttribute(uv, 2));
|
|
181
|
+
geometry.setIndex(new BufferAttribute(index, 1));
|
|
182
|
+
geometry.computeBoundingBox();
|
|
183
|
+
geometry.computeBoundingSphere();
|
|
184
|
+
const mesh = new Mesh(geometry, material);
|
|
185
|
+
mesh.name = meta.name;
|
|
186
|
+
mesh.position.fromArray(numbers(meta.position, 3));
|
|
187
|
+
mesh.quaternion.fromArray(numbers(meta.quaternion, 4));
|
|
188
|
+
mesh.scale.fromArray(numbers(meta.scale, 3));
|
|
189
|
+
mesh.castShadow = boolean(meta.castShadow);
|
|
190
|
+
mesh.receiveShadow = boolean(meta.receiveShadow);
|
|
191
|
+
recordError(mesh, error);
|
|
192
|
+
return mesh;
|
|
193
|
+
}
|
|
194
|
+
function floats(bytes) {
|
|
195
|
+
if (bytes.byteLength % 4)
|
|
196
|
+
fail("invalid float data length");
|
|
197
|
+
const values = new Float32Array(bytes.slice().buffer);
|
|
198
|
+
if (values.some((value) => !Number.isFinite(value)))
|
|
199
|
+
fail("non-finite geometry");
|
|
200
|
+
return values;
|
|
201
|
+
}
|
|
202
|
+
function writeTexture(files, name, texture) {
|
|
203
|
+
if (!(texture instanceof DataTexture) && !(texture instanceof DataArrayTexture))
|
|
204
|
+
fail(`missing ${name} data texture`);
|
|
205
|
+
const image = texture.image;
|
|
206
|
+
const base = object(image);
|
|
207
|
+
const width = integer(base.width), height = integer(base.height);
|
|
208
|
+
const depth = texture instanceof DataArrayTexture ? integer(base.depth) : 1;
|
|
209
|
+
if (texture.type !== UnsignedByteType ||
|
|
210
|
+
(texture.format !== RGBAFormat && texture.format !== RGFormat) ||
|
|
211
|
+
texture.minFilter !== LinearMipmapLinearFilter ||
|
|
212
|
+
texture.magFilter !== LinearFilter ||
|
|
213
|
+
texture.wrapS !== ClampToEdgeWrapping ||
|
|
214
|
+
texture.wrapT !== ClampToEdgeWrapping ||
|
|
215
|
+
texture.flipY ||
|
|
216
|
+
texture.premultiplyAlpha ||
|
|
217
|
+
texture.channel !== 0 ||
|
|
218
|
+
texture.mapping !== UVMapping ||
|
|
219
|
+
!texture.matrixAutoUpdate ||
|
|
220
|
+
texture.internalFormat !== null ||
|
|
221
|
+
texture.offset.x !== 0 ||
|
|
222
|
+
texture.offset.y !== 0 ||
|
|
223
|
+
texture.repeat.x !== 1 ||
|
|
224
|
+
texture.repeat.y !== 1 ||
|
|
225
|
+
texture.rotation !== 0 ||
|
|
226
|
+
(texture.colorSpace !== SRGBColorSpace && texture.colorSpace !== NoColorSpace))
|
|
227
|
+
fail(`unsupported ${name} texture settings`);
|
|
228
|
+
const channels = texture.format === RGFormat ? 2 : 4;
|
|
229
|
+
const pixels = (value, width, height) => {
|
|
230
|
+
if (!(value instanceof Uint8Array) || value.byteLength !== width * height * depth * channels)
|
|
231
|
+
fail(`invalid ${name} pixels`);
|
|
232
|
+
return value;
|
|
233
|
+
};
|
|
234
|
+
files[name + "/0"] = pixels(base.data, width, height);
|
|
235
|
+
const mips = texture.mipmaps.map((value, index) => {
|
|
236
|
+
const mip = object(value);
|
|
237
|
+
const w = integer(mip.width), h = integer(mip.height);
|
|
238
|
+
if (w !== Math.max(1, width >> index) || h !== Math.max(1, height >> index))
|
|
239
|
+
fail("invalid mip dimensions");
|
|
240
|
+
files[`${name}/mip${index}`] = pixels(mip.data, w, h);
|
|
241
|
+
return [w, h];
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
width,
|
|
245
|
+
height,
|
|
246
|
+
depth,
|
|
247
|
+
channels,
|
|
248
|
+
srgb: texture.colorSpace === SRGBColorSpace,
|
|
249
|
+
anisotropy: texture.anisotropy,
|
|
250
|
+
generateMipmaps: texture.generateMipmaps,
|
|
251
|
+
unpackAlignment: texture.unpackAlignment,
|
|
252
|
+
mips,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function readTexture(files, name, value, array) {
|
|
256
|
+
const meta = object(value);
|
|
257
|
+
const width = integer(meta.width), height = integer(meta.height), depth = integer(meta.depth);
|
|
258
|
+
const channels = meta.channels === 2 ? 2 : meta.channels === 4 ? 4 : fail("invalid texture channels");
|
|
259
|
+
if (!array && depth !== 1)
|
|
260
|
+
fail("2D texture with layers");
|
|
261
|
+
const pixels = (key, width, height) => {
|
|
262
|
+
const data = file(files, key);
|
|
263
|
+
if (data.byteLength !== width * height * depth * channels)
|
|
264
|
+
fail(`invalid ${key} byte length`);
|
|
265
|
+
return data;
|
|
266
|
+
};
|
|
267
|
+
const data = pixels(name + "/0", width, height);
|
|
268
|
+
const texture = array ? new DataArrayTexture(data, width, height, depth) : new DataTexture(data, width, height);
|
|
269
|
+
texture.format = channels === 2 ? RGFormat : RGBAFormat;
|
|
270
|
+
texture.colorSpace = boolean(meta.srgb) ? SRGBColorSpace : NoColorSpace;
|
|
271
|
+
texture.minFilter = LinearMipmapLinearFilter;
|
|
272
|
+
texture.magFilter = LinearFilter;
|
|
273
|
+
texture.anisotropy = number(meta.anisotropy);
|
|
274
|
+
texture.generateMipmaps = boolean(meta.generateMipmaps);
|
|
275
|
+
const alignment = meta.unpackAlignment;
|
|
276
|
+
if (alignment !== 1 && alignment !== 2 && alignment !== 4 && alignment !== 8)
|
|
277
|
+
fail("invalid texture alignment");
|
|
278
|
+
texture.unpackAlignment = alignment;
|
|
279
|
+
if (!Array.isArray(meta.mips))
|
|
280
|
+
fail("missing mipmaps");
|
|
281
|
+
texture.mipmaps = meta.mips.map((value, index) => {
|
|
282
|
+
const size = numbers(value, 2);
|
|
283
|
+
const w = integer(size[0]), h = integer(size[1]);
|
|
284
|
+
if (w !== Math.max(1, width >> index) || h !== Math.max(1, height >> index))
|
|
285
|
+
fail("invalid mip dimensions");
|
|
286
|
+
return { data: pixels(`${name}/mip${index}`, w, h), width: w, height: h };
|
|
287
|
+
});
|
|
288
|
+
texture.needsUpdate = true;
|
|
289
|
+
return texture;
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/baked/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,EACL,IAAI,EACJ,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,SAAS,EACT,YAAY,EACZ,wBAAwB,EACxB,IAAI,EACJ,wBAAwB,EACxB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,OAAO,GAER,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,SAAS,IAAI,CAAC,GAAW;IACvB,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;AAChD,CAAC;AACD,MAAM,MAAM,GAAG,CAAC,KAAc,EAA2B,EAAE;IACzD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC1G,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AACF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,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AAK,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC;QAAE,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAChH,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACvD,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACxB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC;YAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC5G,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Mesh, type Object3D } from "three/webgpu";
|
|
2
|
+
export type BakeMeshOptions = {
|
|
3
|
+
/** texels per side of each baked map; default 1024, or 512 when the source cuts out (foliage) */
|
|
4
|
+
textureSize?: number;
|
|
5
|
+
/**
|
|
6
|
+
* Rooms to show through the source's glass (interior mapping): each direct child is one
|
|
7
|
+
* room, which fills its bounding box; lights are refused (lamps: emissive materials).
|
|
8
|
+
* It sits in the source's space as a child of the source would, or where it is if it is
|
|
9
|
+
* inside the source; either way it is hidden from the exterior's bake. Glass is a
|
|
10
|
+
* surface that lets what is behind it show: transparent with opacity below 1, or
|
|
11
|
+
* transmissive (texture alpha is not read). Each room is captured from its box's centre
|
|
12
|
+
* as its colours and its glow; the baked material lights the colours by the indirect
|
|
13
|
+
* light reaching each window.
|
|
14
|
+
*/
|
|
15
|
+
interior?: Object3D;
|
|
16
|
+
} & ({
|
|
17
|
+
/**
|
|
18
|
+
* The mesh to bake onto, in the source's own space, such as a hand-made or generated
|
|
19
|
+
* low-poly shell of a building. Only its static geometry is used: materials are
|
|
20
|
+
* ignored, and its UVs are kept if they lie inside 0..1 without overlapping and
|
|
21
|
+
* with a texel of border between charts, else it is unwrapped again.
|
|
22
|
+
*/
|
|
23
|
+
low: Object3D;
|
|
24
|
+
ratio?: never;
|
|
25
|
+
} | {
|
|
26
|
+
low?: undefined;
|
|
27
|
+
/** share of the source's triangles the low mesh, simplified from it, keeps, in (0, 1]; default 0.05 */
|
|
28
|
+
ratio?: number;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Bake `source` (in its own space, ignoring its own transform) onto one low-poly mesh with
|
|
32
|
+
* its own textures: base colour (alpha: cut out or not), tangent-space normal and
|
|
33
|
+
* occlusion/roughness/metalness, drawn with a MeshStandardNodeMaterial. The mesh is placed
|
|
34
|
+
* like `source`. Materials are read on the CPU as MeshStandardMaterials (color, map,
|
|
35
|
+
* alphaTest, roughness, metalness, normal and ao maps); emissive, clearcoat, transmission
|
|
36
|
+
* and the like are not baked, and blended transparency bakes opaque: glass in its own
|
|
37
|
+
* colour, or as windows into the rooms of `interior`. Textures must be readable on the
|
|
38
|
+
* CPU (no compressed textures).
|
|
39
|
+
*
|
|
40
|
+
* Nested LODs are baked at their level 0; InstancedMeshes, and the source level of an
|
|
41
|
+
* InstancedLod, once per instance: a field of plants bakes as a whole. Skinned meshes
|
|
42
|
+
* and ImpostorMeshes (which have no surface to read) are refused.
|
|
43
|
+
*
|
|
44
|
+
* For each texel of the low mesh, the outermost source surface along the low mesh's
|
|
45
|
+
* normal is shaded. How far the result is off, the larger of a texel's size and the low
|
|
46
|
+
* surface's distance from the source, sets its default maxPixels in a Lod.
|
|
47
|
+
*
|
|
48
|
+
* Experimental, and slow: it runs on the calling thread, yielding to the page now and
|
|
49
|
+
* then.
|
|
50
|
+
*/
|
|
51
|
+
export declare function bakeMesh(source: Object3D, options?: BakeMeshOptions): Promise<Mesh>;
|