@aethervtt/shard-structure 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 +2 -2
- package/dist/bench.d.ts +15 -0
- package/dist/bench.js +112 -0
- package/dist/bricks.d.ts +27 -0
- package/dist/bricks.js +98 -0
- package/dist/compile.d.ts +292 -0
- package/dist/compile.js +1602 -0
- package/dist/components.d.ts +156 -0
- package/dist/components.js +294 -0
- package/dist/contact-shade.d.ts +4 -0
- package/dist/contact-shade.js +76 -0
- package/dist/contact.d.ts +65 -0
- package/dist/contact.js +343 -0
- package/dist/curve.d.ts +50 -0
- package/dist/curve.js +224 -0
- package/dist/fixtures.d.ts +77 -0
- package/dist/fixtures.js +327 -0
- package/dist/geometry.d.ts +178 -0
- package/dist/geometry.js +926 -0
- package/dist/harness.d.ts +27 -0
- package/dist/harness.js +74 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +189 -0
- package/dist/interior-plugin.d.ts +206 -0
- package/dist/interior-plugin.js +988 -0
- package/dist/interior.d.ts +159 -0
- package/dist/interior.js +645 -0
- package/dist/planar.d.ts +61 -0
- package/dist/planar.js +105 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.js +119 -0
- package/package.json +49 -4
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { LINK_X, LINK_Z } from '@aethervtt/shard-render';
|
|
2
|
+
import type { FloorShape } from './geometry.js';
|
|
3
|
+
export { LINK_X, LINK_Z };
|
|
4
|
+
/** The field's grid: origin (x, z) of texel (0, 0)'s corner, texel size, size in texels. */
|
|
5
|
+
export interface FieldGrid {
|
|
6
|
+
ox: number;
|
|
7
|
+
oz: number;
|
|
8
|
+
texel: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
/** A rectangle of texels, [x0, x1) × [z0, z1). */
|
|
13
|
+
export interface TexelRect {
|
|
14
|
+
x0: number;
|
|
15
|
+
z0: number;
|
|
16
|
+
x1: number;
|
|
17
|
+
z1: number;
|
|
18
|
+
}
|
|
19
|
+
/** A world rectangle, [minX, maxX] × [minZ, maxZ]. */
|
|
20
|
+
export interface Bounds {
|
|
21
|
+
minX: number;
|
|
22
|
+
minZ: number;
|
|
23
|
+
maxX: number;
|
|
24
|
+
maxZ: number;
|
|
25
|
+
}
|
|
26
|
+
/** A barrier for the field and the rows: a segment, its top (y), and its wall's thickness. */
|
|
27
|
+
export interface Barrier {
|
|
28
|
+
ax: number;
|
|
29
|
+
az: number;
|
|
30
|
+
bx: number;
|
|
31
|
+
bz: number;
|
|
32
|
+
/** World y of its top, for wall-blocked lights (a window's sill, a low wall's top). */
|
|
33
|
+
top: number;
|
|
34
|
+
thickness: number;
|
|
35
|
+
/** Blocks the field's spill (a gap for the field may still block low for the rows). */
|
|
36
|
+
field: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** A cover: a slab outline (holes included) whose surface stands over the layer. */
|
|
39
|
+
export interface Cover {
|
|
40
|
+
shape: FloorShape;
|
|
41
|
+
/** Rings of closed hatches: they cover though their hole is in the shape. */
|
|
42
|
+
closed: readonly number[];
|
|
43
|
+
}
|
|
44
|
+
/** One level's field: cover, links and visibility per texel. */
|
|
45
|
+
export declare class FieldLayer {
|
|
46
|
+
/** Cover top y over the layer's base, per texel; Infinity where uncovered. */
|
|
47
|
+
cover: Float32Array;
|
|
48
|
+
/** LINK_X | LINK_Z: flux to the +x and +z neighbour is blocked. */
|
|
49
|
+
links: Uint8Array;
|
|
50
|
+
/** The solve's visibility, before the blur: a region re-solve starts from it. */
|
|
51
|
+
value: Float32Array;
|
|
52
|
+
/** What uploads: blurred visibility, links and cover, packed (see `packTexel`). */
|
|
53
|
+
packed: Uint32Array;
|
|
54
|
+
/** The y cover heights count from: the level's elevation (the ground level's is 0). */
|
|
55
|
+
base: number;
|
|
56
|
+
constructor(width: number, height: number);
|
|
57
|
+
}
|
|
58
|
+
/** Scratch shared by solves: reused, grown when a solve needs more. */
|
|
59
|
+
export declare class SolveScratch {
|
|
60
|
+
blurred: Float32Array<ArrayBuffer>;
|
|
61
|
+
/** Per texel: neighbours reached, and 1 / (their count + κ). */
|
|
62
|
+
mask: Uint8Array<ArrayBuffer>;
|
|
63
|
+
inv: Float32Array<ArrayBuffer>;
|
|
64
|
+
/** Per tile: how far its texels moved in the last sweep, and in this one. */
|
|
65
|
+
moved: Float32Array<ArrayBuffer>;
|
|
66
|
+
movedNext: Float32Array<ArrayBuffer>;
|
|
67
|
+
crossings: Float64Array<ArrayBuffer>;
|
|
68
|
+
/** Aggregation (the coarse pass): aggregate per texel, and per aggregate its sums. */
|
|
69
|
+
agg: Int32Array<ArrayBuffer>;
|
|
70
|
+
aggValue: Float64Array<ArrayBuffer>;
|
|
71
|
+
aggDiag: Float64Array<ArrayBuffer>;
|
|
72
|
+
aggRhs: Float64Array<ArrayBuffer>;
|
|
73
|
+
/** Coarse couplings as CSR. */
|
|
74
|
+
rowStart: Int32Array<ArrayBuffer>;
|
|
75
|
+
colIndex: Int32Array<ArrayBuffer>;
|
|
76
|
+
weight: Float64Array<ArrayBuffer>;
|
|
77
|
+
stack: Int32Array<ArrayBuffer>;
|
|
78
|
+
ensure(n: number): void;
|
|
79
|
+
}
|
|
80
|
+
/** Texels of `rect` clipped to the grid. */
|
|
81
|
+
export declare function clipRect(grid: FieldGrid, r: TexelRect): TexelRect;
|
|
82
|
+
/** The texels whose centres lie within `b` grown by `grow` metres, clipped to the grid. */
|
|
83
|
+
export declare function texelsOf(grid: FieldGrid, b: Bounds, grow: number): TexelRect;
|
|
84
|
+
/**
|
|
85
|
+
* Covers the texels of `rect` whose centres are inside `cover` (even-odd over its rings, so
|
|
86
|
+
* holes stay open; closed hatches cover again): each keeps the lowest cover top over `base`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function rasterCover(grid: FieldGrid, layer: FieldLayer, cover: Cover, rect: TexelRect, base: number, scratch: SolveScratch): void;
|
|
89
|
+
/**
|
|
90
|
+
* Marks the links of `rect`'s texels (each texel owns its links to +x and +z) that a barrier
|
|
91
|
+
* crosses: the segment meets the line between the two centres, ends included, so walls meeting
|
|
92
|
+
* at a corner leave no crack.
|
|
93
|
+
*/
|
|
94
|
+
export declare function rasterBarrier(grid: FieldGrid, layer: FieldLayer, s: Barrier, rect: TexelRect): void;
|
|
95
|
+
/** Clears `rect`'s cover and links, before they're rasterized again. */
|
|
96
|
+
export declare function clearRect(grid: FieldGrid, layer: FieldLayer, rect: TexelRect): void;
|
|
97
|
+
/** κ = h² / L²: the screening term of a texel h wide for spill reach L. */
|
|
98
|
+
export declare function screening(texel: number, reach: number): number;
|
|
99
|
+
/** SOR's relaxation for the screened Laplacian: optimal for its slowest mode. */
|
|
100
|
+
export declare function relaxation(kappa: number): number;
|
|
101
|
+
/** Options of a solve. */
|
|
102
|
+
export interface SolveOptions {
|
|
103
|
+
/** Spill reach (m). */
|
|
104
|
+
reach: number;
|
|
105
|
+
/** Stop once no texel moves more than this in a sweep. */
|
|
106
|
+
tolerance?: number;
|
|
107
|
+
/** At most this many sweeps at the texel size. */
|
|
108
|
+
maxSweeps?: number;
|
|
109
|
+
/** Start from an aggregated coarse solve (whole-field solves); a region starts from its old values. */
|
|
110
|
+
coarse?: boolean;
|
|
111
|
+
/** Coarse cells, in texels: about 1 m. */
|
|
112
|
+
coarseCells?: number;
|
|
113
|
+
}
|
|
114
|
+
/** What a solve did. */
|
|
115
|
+
export interface SolveReport {
|
|
116
|
+
texels: number;
|
|
117
|
+
sweeps: number;
|
|
118
|
+
coarseSweeps: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Solves `rect` of a layer: uncovered texels are 1, covered ones the screened diffusion, with
|
|
122
|
+
* texels outside the rect held at their values. Then blurs and packs `rect` grown by a texel
|
|
123
|
+
* (`packRect` reads it back). Whole-field solves start from a coarse pass over ~1 m aggregates;
|
|
124
|
+
* a region starts from the values it had, which an edit changes only near it.
|
|
125
|
+
*/
|
|
126
|
+
export declare function solveRect(grid: FieldGrid, layer: FieldLayer, rect: TexelRect, options: SolveOptions, scratch: SolveScratch): SolveReport;
|
|
127
|
+
/**
|
|
128
|
+
* Blurs `rect` of the solved values once (each covered texel with the neighbours it isn't walled
|
|
129
|
+
* off from, itself weighted 4) and packs it for upload. Uncovered texels stay 1.
|
|
130
|
+
*/
|
|
131
|
+
export declare function packRect(grid: FieldGrid, layer: FieldLayer, rect: TexelRect, scratch: SolveScratch): void;
|
|
132
|
+
/** A field texel as uploaded: visibility (14 bits) over the link bits, the cover code above. */
|
|
133
|
+
export declare function packTexel(visibility: number, links: number, cover: number): number;
|
|
134
|
+
/** The uploaded visibility of a packed texel. */
|
|
135
|
+
export declare function unpackVisibility(texel: number): number;
|
|
136
|
+
/**
|
|
137
|
+
* A direction's place around the circle, 0 to 1 from −x counter-clockwise (+x at ½): the pseudo-
|
|
138
|
+
* angle `interior_bin` in the lighting stage reads bins by (one division, not an atan2).
|
|
139
|
+
*/
|
|
140
|
+
export declare function binOf(x: number, z: number): number;
|
|
141
|
+
/** Scratch for `buildRow`. */
|
|
142
|
+
export declare class RowScratch {
|
|
143
|
+
distance: Float64Array<ArrayBuffer>;
|
|
144
|
+
top: Float64Array<ArrayBuffer>;
|
|
145
|
+
ensure(bins: number): void;
|
|
146
|
+
}
|
|
147
|
+
/** How far behind a barrier's centreline a receiver counts as behind it: a quarter of its thickness, at most 5 cm. */
|
|
148
|
+
export declare function rowBias(thickness: number): number;
|
|
149
|
+
/**
|
|
150
|
+
* A light's polar row: per bin, the distance to the nearest barrier along the bin's direction
|
|
151
|
+
* within `range` (plus its bias), and that barrier's top, packed for upload (`ROW_*`). Only the
|
|
152
|
+
* first `count` barriers are tested: the caller gathers the ones near the light.
|
|
153
|
+
*/
|
|
154
|
+
export declare function buildRow(out: Uint32Array, x: number, y: number, z: number, range: number, barriers: readonly Barrier[], count: number, scratch: RowScratch): void;
|
|
155
|
+
/** A row bin's barrier distance (Infinity for none) and top (relative to the light's y). */
|
|
156
|
+
export declare function unpackBin(bin: number): {
|
|
157
|
+
distance: number;
|
|
158
|
+
top: number;
|
|
159
|
+
};
|