@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
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ClampToEdgeWrapping, MirroredRepeatWrapping, RGBAFormat, SRGBColorSpace, UnsignedByteType } from "three/webgpu";
|
|
2
|
+
/**
|
|
3
|
+
* A texture's texels on the CPU, with a box-filtered mip chain like the GPU's, sampled
|
|
4
|
+
* trilinearly in its UV space (its matrix, wrapping and flipY applied). An sRGB texture is
|
|
5
|
+
* filtered and returned in linear values, as the GPU decodes before filtering. Every
|
|
6
|
+
* texture is read through the `uv` attribute: `texture.channel` is ignored. The pixels
|
|
7
|
+
* are read at the first sample: a texture nothing samples is never read.
|
|
8
|
+
*/
|
|
9
|
+
export class Texels {
|
|
10
|
+
texture;
|
|
11
|
+
/** |det| of the texture matrix: how much it scales UV area */
|
|
12
|
+
uvScale;
|
|
13
|
+
/** 8-bit value to 0..1, per channel: colour channels decode sRGB if the texture is sRGB */
|
|
14
|
+
decode;
|
|
15
|
+
/** the texture's UV transform (Matrix3 elements, column-major) */
|
|
16
|
+
matrix;
|
|
17
|
+
wrapS;
|
|
18
|
+
wrapT;
|
|
19
|
+
lower = new Float32Array(4);
|
|
20
|
+
upper = new Float32Array(4);
|
|
21
|
+
read = null;
|
|
22
|
+
constructor(texture) {
|
|
23
|
+
this.texture = texture;
|
|
24
|
+
this.decode = decoders(texture.colorSpace === SRGBColorSpace);
|
|
25
|
+
if (texture.matrixAutoUpdate)
|
|
26
|
+
texture.updateMatrix();
|
|
27
|
+
this.matrix = texture.matrix.elements.slice();
|
|
28
|
+
const [a = 1, b = 0, , c = 0, d = 1] = this.matrix;
|
|
29
|
+
this.uvScale = Math.abs(a * d - b * c);
|
|
30
|
+
this.wrapS = texture.wrapS;
|
|
31
|
+
this.wrapT = texture.wrapT;
|
|
32
|
+
}
|
|
33
|
+
get width() {
|
|
34
|
+
return this.base().width;
|
|
35
|
+
}
|
|
36
|
+
get height() {
|
|
37
|
+
return this.base().height;
|
|
38
|
+
}
|
|
39
|
+
base() {
|
|
40
|
+
return this.pixels().mips[0] ?? missing();
|
|
41
|
+
}
|
|
42
|
+
pixels() {
|
|
43
|
+
if (this.read)
|
|
44
|
+
return this.read;
|
|
45
|
+
const { texture } = this;
|
|
46
|
+
const { data, width, height, rowsUp } = pixels(texture);
|
|
47
|
+
// Row 0 of the pixels is v = 1 when they were uploaded flipped.
|
|
48
|
+
this.read = { mips: mipmaps({ data, width, height }, texture.colorSpace === SRGBColorSpace), flipY: texture.flipY && !rowsUp };
|
|
49
|
+
return this.read;
|
|
50
|
+
}
|
|
51
|
+
/** The texel at (u, v) from mip `mip` (fractional: trilinear) into `out`, channels 0..1. */
|
|
52
|
+
sample(u, v, mip, out) {
|
|
53
|
+
const [m0 = 1, m1 = 0, , m3 = 0, m4 = 1, , m6 = 0, m7 = 0] = this.matrix;
|
|
54
|
+
const su = wrap(m0 * u + m3 * v + m6, this.wrapS);
|
|
55
|
+
const tv = wrap(m1 * u + m4 * v + m7, this.wrapT);
|
|
56
|
+
const { mips, flipY } = this.pixels();
|
|
57
|
+
const sv = flipY ? 1 - tv : tv;
|
|
58
|
+
const top = mips.length - 1;
|
|
59
|
+
const l = Math.min(Math.max(mip, 0), top);
|
|
60
|
+
const l0 = Math.floor(l);
|
|
61
|
+
const f = l - l0;
|
|
62
|
+
this.bilinear(l0, su, sv, f > 0 ? this.lower : out);
|
|
63
|
+
if (f === 0)
|
|
64
|
+
return;
|
|
65
|
+
this.bilinear(Math.min(l0 + 1, top), su, sv, this.upper);
|
|
66
|
+
for (let k = 0; k < 4; k++)
|
|
67
|
+
out[k] = (this.lower[k] ?? 0) * (1 - f) + (this.upper[k] ?? 0) * f;
|
|
68
|
+
}
|
|
69
|
+
bilinear(mip, su, sv, out) {
|
|
70
|
+
const { data, width, height } = this.pixels().mips[mip] ?? missing();
|
|
71
|
+
const x = su * width - 0.5;
|
|
72
|
+
const y = sv * height - 0.5;
|
|
73
|
+
const x0 = Math.floor(x);
|
|
74
|
+
const y0 = Math.floor(y);
|
|
75
|
+
const fx = x - x0;
|
|
76
|
+
const fy = y - y0;
|
|
77
|
+
const cx = (i) => (this.wrapS === ClampToEdgeWrapping ? Math.min(Math.max(i, 0), width - 1) : ((i % width) + width) % width);
|
|
78
|
+
const cy = (i) => (this.wrapT === ClampToEdgeWrapping ? Math.min(Math.max(i, 0), height - 1) : ((i % height) + height) % height);
|
|
79
|
+
const a = (cy(y0) * width + cx(x0)) * 4;
|
|
80
|
+
const b = (cy(y0) * width + cx(x0 + 1)) * 4;
|
|
81
|
+
const c = (cy(y0 + 1) * width + cx(x0)) * 4;
|
|
82
|
+
const d = (cy(y0 + 1) * width + cx(x0 + 1)) * 4;
|
|
83
|
+
for (let k = 0; k < 4; k++) {
|
|
84
|
+
const decode = this.decode[k] ?? missing();
|
|
85
|
+
const top = (decode[data[a + k] ?? 0] ?? 0) * (1 - fx) + (decode[data[b + k] ?? 0] ?? 0) * fx;
|
|
86
|
+
const bottom = (decode[data[c + k] ?? 0] ?? 0) * (1 - fx) + (decode[data[d + k] ?? 0] ?? 0) * fx;
|
|
87
|
+
out[k] = top * (1 - fy) + bottom * fy;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const missing = () => {
|
|
92
|
+
throw new Error("Texels: lookup out of range");
|
|
93
|
+
};
|
|
94
|
+
export const srgbToLinear = (c) => (c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
|
|
95
|
+
export const linearToSrgb = (c) => (c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(Math.min(c, 1), 1 / 2.4) - 0.055);
|
|
96
|
+
function wrap(x, mode) {
|
|
97
|
+
if (mode === ClampToEdgeWrapping)
|
|
98
|
+
return Math.min(Math.max(x, 0), 1);
|
|
99
|
+
if (mode === MirroredRepeatWrapping) {
|
|
100
|
+
const f = ((x % 2) + 2) % 2;
|
|
101
|
+
return f > 1 ? 2 - f : f;
|
|
102
|
+
}
|
|
103
|
+
return x - Math.floor(x);
|
|
104
|
+
}
|
|
105
|
+
/** Whether `pixels` can read `texture` on the CPU. */
|
|
106
|
+
export function readable(texture) {
|
|
107
|
+
if ("isCompressedTexture" in texture)
|
|
108
|
+
return false;
|
|
109
|
+
const image = texture.image;
|
|
110
|
+
if (isData(image))
|
|
111
|
+
return texture.format === RGBAFormat && texture.type === UnsignedByteType;
|
|
112
|
+
return drawable(image) !== null;
|
|
113
|
+
}
|
|
114
|
+
/** The texture's 8-bit RGBA pixels; `rowsUp` when row 0 is v = 0 whatever flipY says. */
|
|
115
|
+
function pixels(texture) {
|
|
116
|
+
const image = texture.image;
|
|
117
|
+
if ("isCompressedTexture" in texture)
|
|
118
|
+
throw new Error(`cannot read compressed texture "${texture.name}" on the CPU`);
|
|
119
|
+
if (isData(image)) {
|
|
120
|
+
if (texture.format !== RGBAFormat || texture.type !== UnsignedByteType)
|
|
121
|
+
throw new Error(`cannot read data texture "${texture.name}" on the CPU: it is not 8-bit RGBA`);
|
|
122
|
+
const data = new Uint8ClampedArray(image.data.buffer, image.data.byteOffset, image.width * image.height * 4);
|
|
123
|
+
// Data textures are uploaded as they are.
|
|
124
|
+
return { data, width: image.width, height: image.height, rowsUp: true };
|
|
125
|
+
}
|
|
126
|
+
const source = drawable(image);
|
|
127
|
+
if (!source)
|
|
128
|
+
throw new Error(`cannot read the image of texture "${texture.name}" on the CPU`);
|
|
129
|
+
const { width, height } = source;
|
|
130
|
+
const context = new OffscreenCanvas(width, height).getContext("2d", { willReadFrequently: true });
|
|
131
|
+
if (!context)
|
|
132
|
+
throw new Error("no 2D canvas to read textures with");
|
|
133
|
+
context.drawImage(source, 0, 0);
|
|
134
|
+
const { data } = context.getImageData(0, 0, width, height, { colorSpace: "srgb" });
|
|
135
|
+
// ImageBitmaps ignore flipY on upload.
|
|
136
|
+
return { data, width, height, rowsUp: typeof ImageBitmap !== "undefined" && source instanceof ImageBitmap };
|
|
137
|
+
}
|
|
138
|
+
function isData(image) {
|
|
139
|
+
if (typeof image !== "object" || image === null || !("data" in image))
|
|
140
|
+
return false;
|
|
141
|
+
return image.data instanceof Uint8Array || image.data instanceof Uint8ClampedArray;
|
|
142
|
+
}
|
|
143
|
+
/** `image` as something a 2D canvas draws, if it is one. */
|
|
144
|
+
function drawable(image) {
|
|
145
|
+
const kinds = [globalThis.ImageBitmap, globalThis.HTMLImageElement, globalThis.HTMLCanvasElement, globalThis.OffscreenCanvas];
|
|
146
|
+
for (const kind of kinds)
|
|
147
|
+
if (kind && image instanceof kind)
|
|
148
|
+
return image;
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/** Per channel, 8-bit value to 0..1: the colour channels of an sRGB image decode to linear. */
|
|
152
|
+
function decoders(srgb) {
|
|
153
|
+
const linear = Float32Array.from({ length: 256 }, (_, i) => i / 255);
|
|
154
|
+
const color = srgb ? linear.map(srgbToLinear) : linear;
|
|
155
|
+
return [color, color, color, linear];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* `base` and its box-filtered halvings down to 1×1, as generateMipmap makes them: an sRGB
|
|
159
|
+
* image is averaged in linear values.
|
|
160
|
+
*/
|
|
161
|
+
export function mipmaps(base, srgb) {
|
|
162
|
+
const decode = decoders(srgb);
|
|
163
|
+
const encode = (value, channel) => (srgb && channel < 3 ? linearToSrgb(value) : value);
|
|
164
|
+
const mips = [base];
|
|
165
|
+
let mip = base;
|
|
166
|
+
while (mip.width > 1 || mip.height > 1) {
|
|
167
|
+
const { data: from, width: w, height: h } = mip;
|
|
168
|
+
const width = Math.max(1, w >> 1);
|
|
169
|
+
const height = Math.max(1, h >> 1);
|
|
170
|
+
const data = new Uint8ClampedArray(width * height * 4);
|
|
171
|
+
for (let k = 0; k < 4; k++) {
|
|
172
|
+
const d = decode[k] ?? missing();
|
|
173
|
+
for (let y = 0; y < height; y++) {
|
|
174
|
+
const row0 = Math.min(y * 2, h - 1) * w;
|
|
175
|
+
const row1 = Math.min(y * 2 + 1, h - 1) * w;
|
|
176
|
+
for (let x = 0; x < width; x++) {
|
|
177
|
+
const x0 = Math.min(x * 2, w - 1);
|
|
178
|
+
const x1 = Math.min(x * 2 + 1, w - 1);
|
|
179
|
+
const sum = (d[from[(row0 + x0) * 4 + k] ?? 0] ?? 0) +
|
|
180
|
+
(d[from[(row0 + x1) * 4 + k] ?? 0] ?? 0) +
|
|
181
|
+
(d[from[(row1 + x0) * 4 + k] ?? 0] ?? 0) +
|
|
182
|
+
(d[from[(row1 + x1) * 4 + k] ?? 0] ?? 0);
|
|
183
|
+
data[(y * width + x) * 4 + k] = encode(sum / 4, k) * 255;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
mips.push((mip = { data, width, height }));
|
|
188
|
+
}
|
|
189
|
+
return mips;
|
|
190
|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C,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;wBACxC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC3C,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;gBAC3D,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Vector3 } from "three/webgpu";
|
|
2
|
+
import type { Hit, Shading } from "./shading.js";
|
|
3
|
+
import type { Source } from "./source.js";
|
|
4
|
+
/**
|
|
5
|
+
* Casts rays at the source and finds the nearest hit the material keeps: the back of a
|
|
6
|
+
* single-sided surface and cut-out points are passed through, as three draws neither.
|
|
7
|
+
* One walk through the BVH, boxes nearest first and skipped once they start beyond the
|
|
8
|
+
* best hit so far, triangles tested inline (Möller–Trumbore); nothing is allocated per ray.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Tracer {
|
|
11
|
+
private readonly source;
|
|
12
|
+
private readonly shading;
|
|
13
|
+
/** after `cast`, the triangle hit (in the source's index) and the hit's weights for its second and third corners */
|
|
14
|
+
triangle: number;
|
|
15
|
+
w1: number;
|
|
16
|
+
w2: number;
|
|
17
|
+
private ox;
|
|
18
|
+
private oy;
|
|
19
|
+
private oz;
|
|
20
|
+
private dx;
|
|
21
|
+
private dy;
|
|
22
|
+
private dz;
|
|
23
|
+
/** 1 / direction, per axis */
|
|
24
|
+
private ix;
|
|
25
|
+
private iy;
|
|
26
|
+
private iz;
|
|
27
|
+
private best;
|
|
28
|
+
private cutout;
|
|
29
|
+
private facing;
|
|
30
|
+
private readonly callbacks;
|
|
31
|
+
constructor(source: Source, shading: Shading);
|
|
32
|
+
/**
|
|
33
|
+
* Cast from `origin` along unit `direction` up to `far`; `facing` decides which side of
|
|
34
|
+
* a surface is its front (null: both sides stop the ray). Returns "opaque" with `triangle`, `w1`, `w2` set; else
|
|
35
|
+
* "cutout" if it passed a cut-out point, else "back" (nothing kept).
|
|
36
|
+
*/
|
|
37
|
+
cast(origin: Vector3, direction: Vector3, far: number, facing: Vector3 | null): Hit;
|
|
38
|
+
/** Distance along the ray to where it enters `box`; Infinity if it misses it before `best`. */
|
|
39
|
+
private enter;
|
|
40
|
+
/** Test triangle `j` (in BVH order). */
|
|
41
|
+
private intersect;
|
|
42
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { INTERSECTED, NOT_INTERSECTED } from "three-mesh-bvh";
|
|
2
|
+
/**
|
|
3
|
+
* Casts rays at the source and finds the nearest hit the material keeps: the back of a
|
|
4
|
+
* single-sided surface and cut-out points are passed through, as three draws neither.
|
|
5
|
+
* One walk through the BVH, boxes nearest first and skipped once they start beyond the
|
|
6
|
+
* best hit so far, triangles tested inline (Möller–Trumbore); nothing is allocated per ray.
|
|
7
|
+
*/
|
|
8
|
+
export class Tracer {
|
|
9
|
+
source;
|
|
10
|
+
shading;
|
|
11
|
+
/** after `cast`, the triangle hit (in the source's index) and the hit's weights for its second and third corners */
|
|
12
|
+
triangle = -1;
|
|
13
|
+
w1 = 0;
|
|
14
|
+
w2 = 0;
|
|
15
|
+
ox = 0;
|
|
16
|
+
oy = 0;
|
|
17
|
+
oz = 0;
|
|
18
|
+
dx = 0;
|
|
19
|
+
dy = 0;
|
|
20
|
+
dz = 0;
|
|
21
|
+
/** 1 / direction, per axis */
|
|
22
|
+
ix = 0;
|
|
23
|
+
iy = 0;
|
|
24
|
+
iz = 0;
|
|
25
|
+
best = Infinity;
|
|
26
|
+
cutout = false;
|
|
27
|
+
facing = null;
|
|
28
|
+
callbacks;
|
|
29
|
+
constructor(source, shading) {
|
|
30
|
+
this.source = source;
|
|
31
|
+
this.shading = shading;
|
|
32
|
+
this.callbacks = {
|
|
33
|
+
boundsTraverseOrder: (box) => this.enter(box),
|
|
34
|
+
intersectsBounds: (_box, _isLeaf, score) => (score !== undefined && score <= this.best ? INTERSECTED : NOT_INTERSECTED),
|
|
35
|
+
intersectsRange: (offset, count) => {
|
|
36
|
+
for (let j = offset; j < offset + count; j++)
|
|
37
|
+
this.intersect(j);
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cast from `origin` along unit `direction` up to `far`; `facing` decides which side of
|
|
44
|
+
* a surface is its front (null: both sides stop the ray). Returns "opaque" with `triangle`, `w1`, `w2` set; else
|
|
45
|
+
* "cutout" if it passed a cut-out point, else "back" (nothing kept).
|
|
46
|
+
*/
|
|
47
|
+
cast(origin, direction, far, facing) {
|
|
48
|
+
this.ox = origin.x;
|
|
49
|
+
this.oy = origin.y;
|
|
50
|
+
this.oz = origin.z;
|
|
51
|
+
this.dx = direction.x;
|
|
52
|
+
this.dy = direction.y;
|
|
53
|
+
this.dz = direction.z;
|
|
54
|
+
this.ix = 1 / direction.x;
|
|
55
|
+
this.iy = 1 / direction.y;
|
|
56
|
+
this.iz = 1 / direction.z;
|
|
57
|
+
this.best = far;
|
|
58
|
+
this.triangle = -1;
|
|
59
|
+
this.cutout = false;
|
|
60
|
+
this.facing = facing;
|
|
61
|
+
this.source.bvh.shapecast(this.callbacks);
|
|
62
|
+
if (this.triangle >= 0)
|
|
63
|
+
return "opaque";
|
|
64
|
+
return this.cutout ? "cutout" : "back";
|
|
65
|
+
}
|
|
66
|
+
/** Distance along the ray to where it enters `box`; Infinity if it misses it before `best`. */
|
|
67
|
+
enter({ min, max }) {
|
|
68
|
+
let near = 0;
|
|
69
|
+
let far = this.best;
|
|
70
|
+
// Slab test per axis; along an axis the ray does not move, it is inside or misses.
|
|
71
|
+
if (this.dx === 0) {
|
|
72
|
+
if (this.ox < min.x || this.ox > max.x)
|
|
73
|
+
return Infinity;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const a = (min.x - this.ox) * this.ix;
|
|
77
|
+
const b = (max.x - this.ox) * this.ix;
|
|
78
|
+
near = Math.max(near, Math.min(a, b));
|
|
79
|
+
far = Math.min(far, Math.max(a, b));
|
|
80
|
+
}
|
|
81
|
+
if (this.dy === 0) {
|
|
82
|
+
if (this.oy < min.y || this.oy > max.y)
|
|
83
|
+
return Infinity;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const a = (min.y - this.oy) * this.iy;
|
|
87
|
+
const b = (max.y - this.oy) * this.iy;
|
|
88
|
+
near = Math.max(near, Math.min(a, b));
|
|
89
|
+
far = Math.min(far, Math.max(a, b));
|
|
90
|
+
}
|
|
91
|
+
if (this.dz === 0) {
|
|
92
|
+
if (this.oz < min.z || this.oz > max.z)
|
|
93
|
+
return Infinity;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const a = (min.z - this.oz) * this.iz;
|
|
97
|
+
const b = (max.z - this.oz) * this.iz;
|
|
98
|
+
near = Math.max(near, Math.min(a, b));
|
|
99
|
+
far = Math.min(far, Math.max(a, b));
|
|
100
|
+
}
|
|
101
|
+
return near <= far ? near : Infinity;
|
|
102
|
+
}
|
|
103
|
+
/** Test triangle `j` (in BVH order). */
|
|
104
|
+
intersect(j) {
|
|
105
|
+
const c = this.source.corners;
|
|
106
|
+
const o = j * 9;
|
|
107
|
+
const ax = c[o] ?? 0;
|
|
108
|
+
const ay = c[o + 1] ?? 0;
|
|
109
|
+
const az = c[o + 2] ?? 0;
|
|
110
|
+
const e1x = c[o + 3] ?? 0;
|
|
111
|
+
const e1y = c[o + 4] ?? 0;
|
|
112
|
+
const e1z = c[o + 5] ?? 0;
|
|
113
|
+
const e2x = c[o + 6] ?? 0;
|
|
114
|
+
const e2y = c[o + 7] ?? 0;
|
|
115
|
+
const e2z = c[o + 8] ?? 0;
|
|
116
|
+
const { dx, dy, dz } = this;
|
|
117
|
+
const px = dy * e2z - dz * e2y;
|
|
118
|
+
const py = dz * e2x - dx * e2z;
|
|
119
|
+
const pz = dx * e2y - dy * e2x;
|
|
120
|
+
const det = e1x * px + e1y * py + e1z * pz;
|
|
121
|
+
if (det === 0)
|
|
122
|
+
return;
|
|
123
|
+
const inverse = 1 / det;
|
|
124
|
+
const sx = this.ox - ax;
|
|
125
|
+
const sy = this.oy - ay;
|
|
126
|
+
const sz = this.oz - az;
|
|
127
|
+
const u = (sx * px + sy * py + sz * pz) * inverse;
|
|
128
|
+
if (u < 0 || u > 1)
|
|
129
|
+
return;
|
|
130
|
+
const qx = sy * e1z - sz * e1y;
|
|
131
|
+
const qy = sz * e1x - sx * e1z;
|
|
132
|
+
const qz = sx * e1y - sy * e1x;
|
|
133
|
+
const v = (dx * qx + dy * qy + dz * qz) * inverse;
|
|
134
|
+
if (v < 0 || u + v > 1)
|
|
135
|
+
return;
|
|
136
|
+
const t = (e2x * qx + e2y * qy + e2z * qz) * inverse;
|
|
137
|
+
if (t < 0 || t >= this.best)
|
|
138
|
+
return;
|
|
139
|
+
const triangle = this.source.order[j];
|
|
140
|
+
if (triangle === undefined)
|
|
141
|
+
throw new Error("@drawcall/lod: ray state broken");
|
|
142
|
+
const hit = this.shading.test(triangle, u, v, this.facing);
|
|
143
|
+
if (hit === "cutout")
|
|
144
|
+
this.cutout = true;
|
|
145
|
+
if (hit !== "opaque")
|
|
146
|
+
return;
|
|
147
|
+
this.best = t;
|
|
148
|
+
this.triangle = triangle;
|
|
149
|
+
this.w1 = u;
|
|
150
|
+
this.w2 = v;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAQ,CAAC;QACzB,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QACZ,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IACd,CAAC;CACF"}
|
package/dist/three.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MeshStandardNodeMaterial, type BatchedMesh, type BufferAttribute, type Color, type InstancedMesh, type Material, type Mesh, type MeshPhysicalMaterial, type MeshStandardMaterial, type NodeMaterial, type Object3D, type Renderer, type Scene, type SkinnedMesh, type StorageInstancedBufferAttribute, type Texture } from "three/webgpu";
|
|
2
|
+
import type { InstancedLod } from "./instanced/index.js";
|
|
3
|
+
import type { ImpostorMesh } from "./impostor/mesh/index.js";
|
|
4
|
+
import type { LazyImpostor } from "./lazy.js";
|
|
5
|
+
export declare const isObject3D: (value: unknown) => value is Object3D;
|
|
6
|
+
export declare const isMesh: (node: Object3D) => node is Mesh;
|
|
7
|
+
export declare const isSkinnedMesh: (node: Object3D) => node is SkinnedMesh;
|
|
8
|
+
export declare const isInstancedMesh: (node: Object3D) => node is InstancedMesh;
|
|
9
|
+
export declare const isBatchedMesh: (node: Object3D) => node is BatchedMesh;
|
|
10
|
+
export declare const isLight: (node: Object3D) => boolean;
|
|
11
|
+
export declare const isScene: (node: Object3D) => node is Scene;
|
|
12
|
+
export declare const isImpostorMesh: (node: Object3D) => node is ImpostorMesh;
|
|
13
|
+
export declare const isLazyImpostor: (node: Object3D) => node is LazyImpostor;
|
|
14
|
+
export declare const isInstancedLod: (node: Object3D) => node is InstancedLod;
|
|
15
|
+
/** three's LOD and this package's Lod and InstancedLod. */
|
|
16
|
+
export declare const isLOD: (node: Object3D) => node is Object3D & {
|
|
17
|
+
isLOD: true;
|
|
18
|
+
autoUpdate: boolean;
|
|
19
|
+
readonly levels: ReadonlyArray<{
|
|
20
|
+
readonly object: Object3D;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export declare const isStandard: (material: Material) => material is MeshStandardMaterial;
|
|
24
|
+
export declare const isPhysical: (material: Material) => material is MeshPhysicalMaterial;
|
|
25
|
+
export declare const isNodeMaterial: (material: Material) => material is NodeMaterial;
|
|
26
|
+
export declare const isStandardNode: (material: Material) => material is MeshStandardNodeMaterial;
|
|
27
|
+
export declare const isStorageInstanced: (attribute: BufferAttribute) => attribute is StorageInstancedBufferAttribute;
|
|
28
|
+
/**
|
|
29
|
+
* A node material that renders like `material`: a clone when it is one, else the node
|
|
30
|
+
* material of its type with its values, as three converts it for WebGPU itself.
|
|
31
|
+
*/
|
|
32
|
+
export declare function toNodeMaterial(material: Material): NodeMaterial;
|
|
33
|
+
export declare const isTexture: (value: unknown) => value is Texture;
|
|
34
|
+
export declare const isColor: (value: unknown) => value is Color;
|
|
35
|
+
/**
|
|
36
|
+
* `renderer` as the WebGPU renderer it is: three's typings give render callbacks a
|
|
37
|
+
* WebGLRenderer, which this package does not draw with.
|
|
38
|
+
*/
|
|
39
|
+
export declare function gpuRenderer(renderer: unknown): Renderer;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the scene `node` is in is being drawn into a shadow map: three's shadow pass
|
|
42
|
+
* draws it with its own override material, and calls `update` on every LOD with the
|
|
43
|
+
* light's camera, which must not switch the levels the view chose.
|
|
44
|
+
*/
|
|
45
|
+
export declare function inShadowPass(node: Object3D): boolean;
|
|
46
|
+
/** Whether `material` is the one three draws shadow maps with (a node material building for a shadow pass has it). */
|
|
47
|
+
export declare const isShadowPass: (material: unknown) => boolean;
|
|
48
|
+
/** The instance matrices of `object` when it keeps them in a storage buffer (an ImpostorMesh, or such an InstancedMesh); else null. */
|
|
49
|
+
export declare function storageMatrices(object: Object3D): StorageInstancedBufferAttribute | null;
|
|
50
|
+
/** Whether `value` is of exactly `like`'s class: a guard for clone() overrides. */
|
|
51
|
+
export declare const sameClass: <T extends object>(like: T, value: object) => value is T;
|
|
52
|
+
/** Throws if anything under `root` is skinned; `who` names the caller in the message. */
|
|
53
|
+
export declare function rejectSkinned(root: Object3D, who: string): void;
|
|
54
|
+
/** Give `level` the transform of `source`, and its shadows: cast or receive if any mesh of it does. */
|
|
55
|
+
export declare function placeLike(level: Object3D, source: Object3D): void;
|
package/dist/three.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { MeshBasicNodeMaterial, MeshLambertNodeMaterial, MeshMatcapNodeMaterial, MeshNormalNodeMaterial, MeshPhongNodeMaterial, MeshPhysicalNodeMaterial, MeshStandardNodeMaterial, MeshToonNodeMaterial, } from "three/webgpu";
|
|
2
|
+
// Type guards on three's `isX` flags, which hold across copies of three (and of this
|
|
3
|
+
// package, as in .glts scripts) where `instanceof` does not, and small checks on objects.
|
|
4
|
+
const flag = (value, name) => typeof value === "object" && value !== null && Reflect.get(value, name) === true;
|
|
5
|
+
export const isObject3D = (value) => flag(value, "isObject3D");
|
|
6
|
+
export const isMesh = (node) => flag(node, "isMesh");
|
|
7
|
+
export const isSkinnedMesh = (node) => flag(node, "isSkinnedMesh");
|
|
8
|
+
export const isInstancedMesh = (node) => flag(node, "isInstancedMesh");
|
|
9
|
+
export const isBatchedMesh = (node) => flag(node, "isBatchedMesh");
|
|
10
|
+
export const isLight = (node) => flag(node, "isLight");
|
|
11
|
+
export const isScene = (node) => flag(node, "isScene");
|
|
12
|
+
export const isImpostorMesh = (node) => flag(node, "isImpostorMesh");
|
|
13
|
+
export const isLazyImpostor = (node) => flag(node, "isLazyImpostor");
|
|
14
|
+
export const isInstancedLod = (node) => flag(node, "isInstancedLod");
|
|
15
|
+
/** three's LOD and this package's Lod and InstancedLod. */
|
|
16
|
+
export const isLOD = (node) => flag(node, "isLOD");
|
|
17
|
+
export const isStandard = (material) => flag(material, "isMeshStandardMaterial");
|
|
18
|
+
export const isPhysical = (material) => flag(material, "isMeshPhysicalMaterial");
|
|
19
|
+
export const isNodeMaterial = (material) => flag(material, "isNodeMaterial");
|
|
20
|
+
export const isStandardNode = (material) => flag(material, "isMeshStandardNodeMaterial");
|
|
21
|
+
export const isStorageInstanced = (attribute) => flag(attribute, "isStorageInstancedBufferAttribute");
|
|
22
|
+
/** The node material each built-in mesh material draws as with WebGPU. */
|
|
23
|
+
const NODE_MATERIALS = {
|
|
24
|
+
MeshBasicMaterial: MeshBasicNodeMaterial,
|
|
25
|
+
MeshLambertMaterial: MeshLambertNodeMaterial,
|
|
26
|
+
MeshPhongMaterial: MeshPhongNodeMaterial,
|
|
27
|
+
MeshStandardMaterial: MeshStandardNodeMaterial,
|
|
28
|
+
MeshPhysicalMaterial: MeshPhysicalNodeMaterial,
|
|
29
|
+
MeshToonMaterial: MeshToonNodeMaterial,
|
|
30
|
+
MeshMatcapMaterial: MeshMatcapNodeMaterial,
|
|
31
|
+
MeshNormalMaterial: MeshNormalNodeMaterial,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A node material that renders like `material`: a clone when it is one, else the node
|
|
35
|
+
* material of its type with its values, as three converts it for WebGPU itself.
|
|
36
|
+
*/
|
|
37
|
+
export function toNodeMaterial(material) {
|
|
38
|
+
if (isNodeMaterial(material)) {
|
|
39
|
+
const copy = material.clone();
|
|
40
|
+
// three's NodeMaterial.copy skips accessors of Material itself, alphaTest among them.
|
|
41
|
+
copy.alphaTest = material.alphaTest;
|
|
42
|
+
return copy;
|
|
43
|
+
}
|
|
44
|
+
const Type = NODE_MATERIALS[material.type];
|
|
45
|
+
if (!Type)
|
|
46
|
+
throw new Error(`@drawcall/lod: ${material.type} has no node material to draw with WebGPU`);
|
|
47
|
+
// Every own value but the source's identity and its event listeners.
|
|
48
|
+
const values = Object.fromEntries(Object.entries(material).filter(([key]) => key !== "uuid" && key !== "_listeners"));
|
|
49
|
+
return Object.assign(new Type(), values);
|
|
50
|
+
}
|
|
51
|
+
export const isTexture = (value) => flag(value, "isTexture");
|
|
52
|
+
export const isColor = (value) => flag(value, "isColor");
|
|
53
|
+
/**
|
|
54
|
+
* `renderer` as the WebGPU renderer it is: three's typings give render callbacks a
|
|
55
|
+
* WebGLRenderer, which this package does not draw with.
|
|
56
|
+
*/
|
|
57
|
+
export function gpuRenderer(renderer) {
|
|
58
|
+
if (!isRenderer(renderer))
|
|
59
|
+
throw new Error("@drawcall/lod: draws with three's WebGPURenderer only");
|
|
60
|
+
return renderer;
|
|
61
|
+
}
|
|
62
|
+
const isRenderer = (value) => flag(value, "isRenderer");
|
|
63
|
+
/**
|
|
64
|
+
* Whether the scene `node` is in is being drawn into a shadow map: three's shadow pass
|
|
65
|
+
* draws it with its own override material, and calls `update` on every LOD with the
|
|
66
|
+
* light's camera, which must not switch the levels the view chose.
|
|
67
|
+
*/
|
|
68
|
+
export function inShadowPass(node) {
|
|
69
|
+
let root = node;
|
|
70
|
+
while (root.parent)
|
|
71
|
+
root = root.parent;
|
|
72
|
+
return "overrideMaterial" in root && isShadowPass(root.overrideMaterial);
|
|
73
|
+
}
|
|
74
|
+
/** Whether `material` is the one three draws shadow maps with (a node material building for a shadow pass has it). */
|
|
75
|
+
export const isShadowPass = (material) => flag(material, "isShadowPassMaterial");
|
|
76
|
+
/** The instance matrices of `object` when it keeps them in a storage buffer (an ImpostorMesh, or such an InstancedMesh); else null. */
|
|
77
|
+
export function storageMatrices(object) {
|
|
78
|
+
if (isImpostorMesh(object))
|
|
79
|
+
return object.instanceMatrix;
|
|
80
|
+
return isInstancedMesh(object) && isStorageInstanced(object.instanceMatrix) ? object.instanceMatrix : null;
|
|
81
|
+
}
|
|
82
|
+
/** Whether `value` is of exactly `like`'s class: a guard for clone() overrides. */
|
|
83
|
+
export const sameClass = (like, value) => Object.getPrototypeOf(value) === Object.getPrototypeOf(like);
|
|
84
|
+
/** Throws if anything under `root` is skinned; `who` names the caller in the message. */
|
|
85
|
+
export function rejectSkinned(root, who) {
|
|
86
|
+
root.traverse((node) => {
|
|
87
|
+
if (isSkinnedMesh(node))
|
|
88
|
+
throw new Error(`${who}: skinned meshes are not supported ("${node.name}")`);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Give `level` the transform of `source`, and its shadows: cast or receive if any mesh of it does. */
|
|
92
|
+
export function placeLike(level, source) {
|
|
93
|
+
level.position.copy(source.position);
|
|
94
|
+
level.quaternion.copy(source.quaternion);
|
|
95
|
+
level.scale.copy(source.scale);
|
|
96
|
+
source.traverse((node) => {
|
|
97
|
+
if (!isMesh(node))
|
|
98
|
+
return;
|
|
99
|
+
level.castShadow ||= node.castShadow;
|
|
100
|
+
level.receiveShadow ||= node.receiveShadow;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=three.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three.js","sourceRoot":"","sources":["../src/three.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,GAgBrB,MAAM,cAAc,CAAC;AAKtB,qFAAqF;AACrF,0FAA0F;AAC1F,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,IAAY,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC;AAEhI,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAqB,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAC3F,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAc,EAAgB,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAc,EAAuB,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAClG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAc,EAAyB,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;AACxG,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K,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AAEhJ,yFAAyF;AACzF,MAAM,UAAU,aAAa,CAAC,IAAc,EAAE,GAAW;IACvD,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,IAAI,aAAa,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,wCAAwC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC;AACL,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,SAAS,CAAC,KAAe,EAAE,MAAgB;IACzD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACzC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE;QACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO;QAC1B,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC;QACrC,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/tsl.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BufferAttribute, ContextNode, Node, NodeBuilder, StorageBufferNode } from "three/webgpu";
|
|
2
|
+
/** Column `i` (0..3) of `m`. */
|
|
3
|
+
export declare const column: (m: Node<"mat4">, i: 0 | 1 | 2 | 3) => Node<"vec4">;
|
|
4
|
+
/** The largest scale `m` applies along an axis. */
|
|
5
|
+
export declare const maxScale: (m: Node<"mat4">) => Node<"float">;
|
|
6
|
+
/** Whether projection `m` is orthographic: its bottom-right element is 1. */
|
|
7
|
+
export declare const isOrthographic: (m: Node<"mat4">) => Node<"bool">;
|
|
8
|
+
/** An affine matrix `m` and the inverse of its linear part, as cofactor columns over the determinant. */
|
|
9
|
+
export interface Affine {
|
|
10
|
+
/** `m`'s linear part applied to direction `v` */
|
|
11
|
+
apply(v: Node<"vec3">): Node<"vec3">;
|
|
12
|
+
/** the inverse of the linear part applied to direction `v` */
|
|
13
|
+
solve(v: Node<"vec3">): Node<"vec3">;
|
|
14
|
+
/** point `p` through the inverse of `m`: into the space `m` maps from */
|
|
15
|
+
unproject(p: Node<"vec3">): Node<"vec3">;
|
|
16
|
+
/** the inverse transpose applied to `v`: how normals transform */
|
|
17
|
+
normal(v: Node<"vec3">): Node<"vec3">;
|
|
18
|
+
/** the columns of the inverse transpose */
|
|
19
|
+
normalColumns: [Node<"vec3">, Node<"vec3">, Node<"vec3">];
|
|
20
|
+
}
|
|
21
|
+
export declare function affine(m: Node<"mat4">): Affine;
|
|
22
|
+
/** The node at `path` in the context `builder` builds with, which three's typings leave open. */
|
|
23
|
+
export declare function contextNode(builder: NodeBuilder, ...path: string[]): Node;
|
|
24
|
+
/**
|
|
25
|
+
* An object that stays the same throughout one build of a shader, to cache per build
|
|
26
|
+
* what several of a material's slots read. Each slot is handed its own proxy of the
|
|
27
|
+
* builder, and three's typings expose no handle of the build itself: this is what the
|
|
28
|
+
* build keeps for `anchor`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildKey(builder: NodeBuilder, anchor: Node): object;
|
|
31
|
+
/**
|
|
32
|
+
* Whether `node` builds to a `type` value, which three's typings leave open for a
|
|
33
|
+
* material's slots. Checked while a shader builds, so a slot of another type fails there.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isNodeOf<T extends "bool" | "float" | "vec3" | "vec4" | "color">(node: Node, type: T, builder: NodeBuilder): node is Node<T>;
|
|
36
|
+
export declare const instanceFades: (attribute: BufferAttribute) => StorageBufferNode<"float">;
|
|
37
|
+
export declare const instanceColors: (attribute: BufferAttribute) => StorageBufferNode<"vec4">;
|
|
38
|
+
export declare const instanceMatrices: (attribute: BufferAttribute) => StorageBufferNode<"mat4">;
|
|
39
|
+
export declare const roomBounds: (attribute: BufferAttribute) => StorageBufferNode<"vec4">;
|
|
40
|
+
/**
|
|
41
|
+
* A context in which every texture read is `bias` mip levels above the level the
|
|
42
|
+
* hardware would pick: the level from the read's own texel footprint, plus `bias`. Reads
|
|
43
|
+
* with uv of their own making, or with an explicit level or gradients, keep theirs.
|
|
44
|
+
*/
|
|
45
|
+
export declare function biasedTextures(bias: Node<"float">): ContextNode<unknown>;
|