@margoengine/vfx 0.0.0-stage → 1.0.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 +201 -0
- package/NOTICE +4 -0
- package/README.md +2240 -2
- package/dist/base-LGs65K7K.js +709 -0
- package/dist/base.d.ts +869 -0
- package/dist/base.js +1 -0
- package/dist/blown-sand.d.ts +218 -0
- package/dist/blown-sand.js +700 -0
- package/dist/clouds.d.ts +237 -0
- package/dist/clouds.js +583 -0
- package/dist/compat-BFjXAQuu.js +14 -0
- package/dist/compat-CVSEj1Bp.js +217 -0
- package/dist/compat.d.ts +59 -0
- package/dist/curves.d.ts +11 -0
- package/dist/curves.js +59 -0
- package/dist/debris.d.ts +154 -0
- package/dist/debris.js +290 -0
- package/dist/depth-collide.d.ts +7 -0
- package/dist/depth-collide.js +96 -0
- package/dist/dust-current.d.ts +66 -0
- package/dist/dust-current.js +92 -0
- package/dist/emitter.d.ts +10 -0
- package/dist/emitter.js +125 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +131 -0
- package/dist/extra-CgGjbojB.js +4 -0
- package/dist/extra.d.ts +2 -0
- package/dist/fields.d.ts +11 -0
- package/dist/fields.js +95 -0
- package/dist/fire-front.d.ts +610 -0
- package/dist/fire-front.js +1080 -0
- package/dist/fire.d.ts +140 -0
- package/dist/fire.js +194 -0
- package/dist/flame-ramp-VoBKpYnM.js +75 -0
- package/dist/flame-ramp.d.ts +61 -0
- package/dist/flame.d.ts +428 -0
- package/dist/flame.js +817 -0
- package/dist/flipbook.d.ts +7 -0
- package/dist/flipbook.js +23 -0
- package/dist/flocking-shaders.d.ts +48 -0
- package/dist/flocking-sim.d.ts +623 -0
- package/dist/flocking.d.ts +145 -0
- package/dist/flocking.js +1846 -0
- package/dist/fog-B-kBv7g0.js +32 -0
- package/dist/frame-BuvMFBPp.js +4 -0
- package/dist/frame.d.ts +7 -0
- package/dist/gunfire.d.ts +742 -0
- package/dist/gunfire.js +1214 -0
- package/dist/hash-Btsp6fGK.js +7 -0
- package/dist/hash.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +60 -0
- package/dist/json.d.ts +53 -0
- package/dist/json.js +239 -0
- package/dist/lit-Dx2tNwP-.js +152 -0
- package/dist/lit.d.ts +18 -0
- package/dist/lit.js +1 -0
- package/dist/mesh.d.ts +16 -0
- package/dist/mesh.js +248 -0
- package/dist/node-system.d.ts +315 -0
- package/dist/node-system.js +384 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.js +293 -0
- package/dist/obstacles.d.ts +3 -0
- package/dist/obstacles.js +25 -0
- package/dist/over-life.d.ts +14 -0
- package/dist/over-life.js +94 -0
- package/dist/reactive-mask-B8xbyzlk.js +69 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/ribbons.d.ts +22 -0
- package/dist/ribbons.js +165 -0
- package/dist/schedule.d.ts +29 -0
- package/dist/schedule.js +47 -0
- package/dist/settings.d.ts +362 -0
- package/dist/settings.js +707 -0
- package/dist/shader.d.ts +49 -0
- package/dist/shadows.d.ts +26 -0
- package/dist/shadows.js +182 -0
- package/dist/shapes.d.ts +34 -0
- package/dist/shapes.js +81 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/skinned.d.ts +11 -0
- package/dist/skinned.js +104 -0
- package/dist/smoke.d.ts +283 -0
- package/dist/smoke.js +504 -0
- package/dist/soft.d.ts +17 -0
- package/dist/soft.js +55 -0
- package/dist/solid.d.ts +168 -0
- package/dist/solid.js +403 -0
- package/dist/sort.d.ts +3 -0
- package/dist/sort.js +58 -0
- package/dist/space.d.ts +14 -0
- package/dist/space.js +88 -0
- package/dist/stretch.d.ts +7 -0
- package/dist/stretch.js +40 -0
- package/dist/texture.d.ts +8 -0
- package/dist/texture.js +45 -0
- package/dist/view-RKprOPAy.js +30 -0
- package/dist/view-rect-DkeiiUtw.js +13 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.js +5 -0
- package/package.json +198 -4
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
import { type ColorInput } from '@margoengine/math/color';
|
|
2
|
+
import { MargoError } from '@margoengine/math/errors';
|
|
3
|
+
import type { FlowField } from '@margoengine/math/fields';
|
|
4
|
+
import type { VFXLightSource } from './base.js';
|
|
5
|
+
/** Maximum boid count accepted by `GPUFlock`. */
|
|
6
|
+
export declare const MAX_FLOCK_BOIDS = 262144;
|
|
7
|
+
/** Maximum live attractors supported per flock. */
|
|
8
|
+
export declare const MAX_FLOCK_ATTRACTORS = 16;
|
|
9
|
+
/** Maximum live predators supported per flock. */
|
|
10
|
+
export declare const MAX_FLOCK_PREDATORS = 16;
|
|
11
|
+
/** Maximum live sphere obstacles supported per flock. */
|
|
12
|
+
export declare const MAX_FLOCK_OBSTACLES = 32;
|
|
13
|
+
/** Maximum distance-field obstacles (meshes, terrain) supported per flock. */
|
|
14
|
+
export declare const MAX_FLOCK_FIELDS = 4;
|
|
15
|
+
/** Maximum points of a flock's path. */
|
|
16
|
+
export declare const MAX_FLOCK_PATH_POINTS = 16;
|
|
17
|
+
/** Most samples all of a flock's distance fields hold together (4 MiB of f32). */
|
|
18
|
+
export declare const MAX_FLOCK_FIELD_SAMPLES = 1048576;
|
|
19
|
+
/** Maximum triangles accepted for a custom boid mesh. */
|
|
20
|
+
export declare const MAX_FLOCK_MESH_TRIANGLES = 16384;
|
|
21
|
+
/** Longest single integration step in seconds; a longer `dt` is split into equal steps no longer than this. */
|
|
22
|
+
export declare const FLOCK_MAX_SUBSTEP = 0.05;
|
|
23
|
+
/** Longest `dt` one `step` call or `stepFlockCPU` call takes, in seconds. */
|
|
24
|
+
export declare const FLOCK_MAX_STEP = 1;
|
|
25
|
+
/** Floats per boid in a state or snapshot: x, y, z, animation phase, vx, vy, vz, bank angle. */
|
|
26
|
+
export declare const FLOCK_BOID_FLOATS = 8;
|
|
27
|
+
/** 3D vector tuple. */
|
|
28
|
+
export type FlockVec3 = readonly [number, number, number];
|
|
29
|
+
/** Built-in visual and locomotion preset for a flock. */
|
|
30
|
+
export type FlockPreset = 'bird' | 'fish';
|
|
31
|
+
/** Axis-aligned box or sphere domain that contains the flock. */
|
|
32
|
+
export type FlockBounds = {
|
|
33
|
+
shape: 'box';
|
|
34
|
+
/** Center of the box in world units. Default `[0, 0, 0]`. */
|
|
35
|
+
center?: FlockVec3;
|
|
36
|
+
/** Positive half-extents `[hx, hy, hz]` in world units. */
|
|
37
|
+
halfSize: FlockVec3;
|
|
38
|
+
} | {
|
|
39
|
+
shape: 'sphere';
|
|
40
|
+
/** Center of the sphere in world units. Default `[0, 0, 0]`. */
|
|
41
|
+
center?: FlockVec3;
|
|
42
|
+
/** Positive sphere radius in world units. */
|
|
43
|
+
radius: number;
|
|
44
|
+
};
|
|
45
|
+
/** Point attractor that draws nearby boids toward a target position. */
|
|
46
|
+
export interface FlockAttractor {
|
|
47
|
+
/** World-space position of the attractor. */
|
|
48
|
+
position: FlockVec3;
|
|
49
|
+
/** Steering pull weight, `>= 0`. Default `2.5`. */
|
|
50
|
+
strength?: number;
|
|
51
|
+
/** Influence radius in world units, `>= 0` (`0` means infinite range). Default `0`. */
|
|
52
|
+
radius?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A path the flock follows (Reynolds 1999, path following): each boid predicts where it will be `predictSeconds`
|
|
56
|
+
* ahead; when that point lies outside the tube of `radius` around the polyline, it seeks the point `lookahead`
|
|
57
|
+
* further along the path from the nearest one. Inside the tube the flock rules steer alone. Stateless, so the same
|
|
58
|
+
* seed replays the same flight. Read each frame.
|
|
59
|
+
*/
|
|
60
|
+
export interface FlockPath {
|
|
61
|
+
/** 2 to 16 world-space points, in the order the flock flies them; the path is not zero length. */
|
|
62
|
+
points: readonly FlockVec3[];
|
|
63
|
+
/** Closes the path from the last point back to the first. Default `false`: the flock gathers at the last point. */
|
|
64
|
+
loop?: boolean;
|
|
65
|
+
/** Tube radius in world units, `>= 0`. Default the flock's `neighborRadius`. */
|
|
66
|
+
radius?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Distance along the path, ahead of the nearest point, that a boid outside the tube seeks, `> 0`. Default 2 x
|
|
69
|
+
* `neighborRadius`.
|
|
70
|
+
*/
|
|
71
|
+
lookahead?: number;
|
|
72
|
+
/** How far ahead a boid predicts its position, seconds, `>= 0`. Default `0.5`. */
|
|
73
|
+
predictSeconds?: number;
|
|
74
|
+
/** Steering weight of the seek, as an attractor's, `>= 0`. Default `2.5`. */
|
|
75
|
+
strength?: number;
|
|
76
|
+
}
|
|
77
|
+
/** A resolved {@link FlockPath}: points as `(x, y, z, arc length to the point)`, four floats a point. */
|
|
78
|
+
export interface ResolvedFlockPath {
|
|
79
|
+
/** Points, `(x, y, z, s)` each, `s` the arc length from the first point. */
|
|
80
|
+
points: Float64Array;
|
|
81
|
+
/** Number of points, 2 to 16. */
|
|
82
|
+
count: number;
|
|
83
|
+
/** Closed path. */
|
|
84
|
+
loop: boolean;
|
|
85
|
+
/** Tube radius. */
|
|
86
|
+
radius: number;
|
|
87
|
+
/** Seek distance ahead along the path. */
|
|
88
|
+
lookahead: number;
|
|
89
|
+
/** Prediction time, seconds. */
|
|
90
|
+
predictSeconds: number;
|
|
91
|
+
/** Seek weight. */
|
|
92
|
+
strength: number;
|
|
93
|
+
/** Arc length of the whole path (with the closing segment when it loops), `> 0`. */
|
|
94
|
+
length: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A body a flock reads live, such as a `Physics` body (`@margoengine/physics`): its `position` (and, for a predator,
|
|
98
|
+
* `linearVelocity`) is read every time the flock resolves its options, each frame and each `step`.
|
|
99
|
+
*/
|
|
100
|
+
export interface FlockBody {
|
|
101
|
+
/** World-space position, metres (read as its first three numbers). */
|
|
102
|
+
readonly position: ArrayLike<number>;
|
|
103
|
+
/** World-space velocity, metres per second (read as its first three numbers). */
|
|
104
|
+
readonly linearVelocity?: ArrayLike<number>;
|
|
105
|
+
/** World-space rotation quaternion `[x, y, z, w]`, read by field obstacles. */
|
|
106
|
+
readonly rotation?: ArrayLike<number>;
|
|
107
|
+
}
|
|
108
|
+
/** Floats of a sampled flow lattice: origin (vec4), spacing and an on flag (vec4), then 64 velocities (vec4). */
|
|
109
|
+
export declare const FLOCK_FLOW_FLOATS: number;
|
|
110
|
+
/** Moving or static predator (or the pointer) that boids flee from within its radius. */
|
|
111
|
+
export interface FlockPredator {
|
|
112
|
+
/** World-space position of the predator. */
|
|
113
|
+
position: FlockVec3;
|
|
114
|
+
/**
|
|
115
|
+
* Detection and flee radius in world units, `> 0`. Default the preset's (`FLOCK_PRESET_DEFAULTS`): 6 m bird,
|
|
116
|
+
* 0.43 m fish.
|
|
117
|
+
*/
|
|
118
|
+
radius?: number;
|
|
119
|
+
/** Flee acceleration weight, `>= 0`; `0` turns the predator off. Default `12`. */
|
|
120
|
+
strength?: number;
|
|
121
|
+
/** World-space velocity, for the `'high'` tier's prediction of its course. Default `[0, 0, 0]`. */
|
|
122
|
+
velocity?: FlockVec3;
|
|
123
|
+
/** A live body whose position and velocity replace `position` and `velocity` each frame (a hunting hawk). */
|
|
124
|
+
body?: FlockBody;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Model tier of a flock: `'fast'` steers by Reynolds' (1987) weighted rules, the rival GPU birds' model. `'high'`
|
|
128
|
+
* flies birds by StarDisplay (Hildenbrandt, Carere & Hemelrijk 2010) with the social forces of its 2015 revision
|
|
129
|
+
* (Hemelrijk & Hildenbrandt, PLoS ONE e0126913): separation from the single nearest neighbour out to
|
|
130
|
+
* `separationRadius`, cohesion scaled by how far a bird sits at the rim, heading alignment, cruise-speed control over
|
|
131
|
+
* 10 s, a small seeded random force and fixed-wing flight with lift,
|
|
132
|
+
* drag, gravity and banked turns, with the predicted predator escape. For fish `'high'` steers by the zones of Couzin
|
|
133
|
+
* et al. (2002) with priority repulsion, that escape and a cruise-speed response, the rule of the physics
|
|
134
|
+
* `SchoolSolver` (`@margoengine/physics/schooling`) in f32.
|
|
135
|
+
*/
|
|
136
|
+
export type FlockFidelity = 'fast' | 'high';
|
|
137
|
+
/** Sphere obstacle that boids steer around and bounce off. */
|
|
138
|
+
export interface FlockObstacle {
|
|
139
|
+
/** World-space center of the sphere obstacle. */
|
|
140
|
+
position: FlockVec3;
|
|
141
|
+
/** Positive sphere radius in world units. */
|
|
142
|
+
radius: number;
|
|
143
|
+
/** Avoidance steering weight, `>= 0`. Default `8`. */
|
|
144
|
+
strength?: number;
|
|
145
|
+
/** A live body whose position replaces `position` each frame (a boat, a diver, a falling rock). */
|
|
146
|
+
body?: FlockBody;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A signed distance field sampled on a grid, negative inside: `MeshSDF` from `bakeSDF` of `@margoengine/bvh/sdf` (a
|
|
150
|
+
* mesh, rock, hull or terrain baked once), or any field of the same shape. Samples sit on the cell corners from `min`
|
|
151
|
+
* to `max` inclusive, x fastest, then y, then z, and are read back trilinearly in the field's own space.
|
|
152
|
+
*/
|
|
153
|
+
export interface FlockDistanceField {
|
|
154
|
+
/** `size[0] * size[1] * size[2]` finite samples, world units. */
|
|
155
|
+
readonly data: ArrayLike<number>;
|
|
156
|
+
/** Samples per axis, each 2 to 512. */
|
|
157
|
+
readonly size: readonly [number, number, number];
|
|
158
|
+
/** The grid's first corner, in the field's space. */
|
|
159
|
+
readonly min: FlockVec3;
|
|
160
|
+
/** The grid's last corner, above `min` on every axis. */
|
|
161
|
+
readonly max: FlockVec3;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* An obstacle of any shape, given by its distance field: boids steer off its surface within `margin` and are put back
|
|
165
|
+
* on it if they reach it. Placed by `position` and `rotation`, or by a live `body` (a ship's hull). The samples are
|
|
166
|
+
* uploaded when the flock first sees the field object; pass a new object to change them.
|
|
167
|
+
*/
|
|
168
|
+
export interface FlockFieldObstacle {
|
|
169
|
+
/** The shape. */
|
|
170
|
+
field: FlockDistanceField;
|
|
171
|
+
/** World position of the field's origin. Default `[0, 0, 0]`. */
|
|
172
|
+
position?: FlockVec3;
|
|
173
|
+
/** World rotation of the field, a quaternion `[x, y, z, w]` (normalized here). Default `[0, 0, 0, 1]`. */
|
|
174
|
+
rotation?: readonly [number, number, number, number];
|
|
175
|
+
/** Distance from the surface at which the boids start to steer off it, `> 0`. Default as the sphere obstacles'. */
|
|
176
|
+
margin?: number;
|
|
177
|
+
/** Avoidance steering weight, `>= 0`. Default `8`. */
|
|
178
|
+
strength?: number;
|
|
179
|
+
/** A live body whose `position` (and `rotation`, when it has one) replace the placement each frame. */
|
|
180
|
+
body?: FlockBody;
|
|
181
|
+
}
|
|
182
|
+
/** A field obstacle as the solver reads it: placement resolved, rotation normalized. */
|
|
183
|
+
export interface ResolvedFlockField {
|
|
184
|
+
data: ArrayLike<number>;
|
|
185
|
+
size: readonly [number, number, number];
|
|
186
|
+
min: FlockVec3;
|
|
187
|
+
spacing: [number, number, number];
|
|
188
|
+
position: [number, number, number];
|
|
189
|
+
rotation: [number, number, number, number];
|
|
190
|
+
/** 0 means the sphere obstacles' margin. */
|
|
191
|
+
margin: number;
|
|
192
|
+
strength: number;
|
|
193
|
+
}
|
|
194
|
+
/** The scene's lights a flock is shaded by (`GPUFlockOptions.lit`); both are read each time the flock draws. */
|
|
195
|
+
export interface FlockLit {
|
|
196
|
+
/** Point and spot lights: `Clustered` from `@margoengine/clustered`. */
|
|
197
|
+
lights?: VFXLightSource;
|
|
198
|
+
/** Sun shadows on the boids: `Shadows` from `@margoengine/shadows`. */
|
|
199
|
+
shadows?: VFXLightSource;
|
|
200
|
+
}
|
|
201
|
+
/** Custom triangle mesh for instanced boid rendering (`+Z` forward, `+Y` up, `+X` right). */
|
|
202
|
+
export interface FlockGeometry {
|
|
203
|
+
/** Flat xyz vertex positions. */
|
|
204
|
+
positions: ArrayLike<number>;
|
|
205
|
+
/** Optional flat xyz vertex normals (face normals when omitted). */
|
|
206
|
+
normals?: ArrayLike<number>;
|
|
207
|
+
/** Optional triangle index list. */
|
|
208
|
+
indices?: ArrayLike<number>;
|
|
209
|
+
/** Optional per-vertex animation weight in `0..1` driving wing-flap or tail-swim displacement. */
|
|
210
|
+
weights?: ArrayLike<number>;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* An interleaved mesh, six floats a vertex (x, y, z, nx, ny, nz) and triangle indices: the layout of a core
|
|
214
|
+
* `Geometry`, so `model.meshes[i].geometry` of a loaded glTF passes as it is.
|
|
215
|
+
*/
|
|
216
|
+
export interface FlockInterleavedGeometry {
|
|
217
|
+
/** Six floats a vertex: position then normal. */
|
|
218
|
+
readonly vertices: ArrayLike<number>;
|
|
219
|
+
/** Triangle indices into the vertices. */
|
|
220
|
+
readonly indices: ArrayLike<number>;
|
|
221
|
+
}
|
|
222
|
+
/** Built-in debug overlay settings for a `GPUFlock`. */
|
|
223
|
+
export interface FlockDebugOptions {
|
|
224
|
+
/** Enable or disable the debug overlay. Default `false`. */
|
|
225
|
+
enabled?: boolean;
|
|
226
|
+
/** Draw a velocity line on every boid, coloured from slow (blue) to fast (red). Default `true`. */
|
|
227
|
+
velocities?: boolean;
|
|
228
|
+
/** Draw the flock's bounds and the inspected boid's grid cell and its 3 x 3 x 3 neighbourhood. Default `true`. */
|
|
229
|
+
grid?: boolean;
|
|
230
|
+
/** Draw the inspected boid's separation sphere and its neighbour radius as a vision cone. Default `true`. */
|
|
231
|
+
perception?: boolean;
|
|
232
|
+
/** Draw the inspected boid's velocity and its separation, alignment, cohesion and predator steering. Default `true`. */
|
|
233
|
+
vectors?: boolean;
|
|
234
|
+
/** Zero-based index of the inspected boid. Default `0`. */
|
|
235
|
+
selectedIndex?: number;
|
|
236
|
+
}
|
|
237
|
+
/** Configuration options for `GPUFlock`. Every option except `count` can change between frames. */
|
|
238
|
+
export interface GPUFlockOptions {
|
|
239
|
+
/** Number of boids in the flock, integer `1..262,144`. Fixed at attach. Default `4096`. */
|
|
240
|
+
count?: number;
|
|
241
|
+
/** PRNG seed for the starting positions, velocities and phases, a 32-bit integer. Default `1337`. */
|
|
242
|
+
seed?: number;
|
|
243
|
+
/** Visual and animation preset: `'bird'` (wing flap + banking) or `'fish'` (sinusoidal tail swim). Default `'bird'`. */
|
|
244
|
+
preset?: FlockPreset;
|
|
245
|
+
/** Optional custom mesh overriding the built-in bird or fish mesh (a glTF mesh's `geometry` passes). Default `null`. */
|
|
246
|
+
geometry?: FlockGeometry | FlockInterleavedGeometry | null;
|
|
247
|
+
/**
|
|
248
|
+
* Containment domain (`box` or `sphere`). Default a box centered at origin, the preset's `halfSize`:
|
|
249
|
+
* `[18, 10, 18]` m bird, `[1.29, 0.71, 1.29]` m fish.
|
|
250
|
+
*/
|
|
251
|
+
bounds?: FlockBounds;
|
|
252
|
+
/** Soft steering margin inside the domain boundary in world units, `>= 0`. Default `3` m bird, `0.21` m fish. */
|
|
253
|
+
boundsMargin?: number;
|
|
254
|
+
/** Inward turn-back strength near the domain boundary, `>= 0`. Default `6`. */
|
|
255
|
+
boundsStrength?: number;
|
|
256
|
+
/** Separation rule weight (Reynolds 1987, collision avoidance), `>= 0`. Default `1.8`. */
|
|
257
|
+
separation?: number;
|
|
258
|
+
/** Alignment rule weight (Reynolds 1987, velocity matching), `>= 0`. Default `1.1`. */
|
|
259
|
+
alignment?: number;
|
|
260
|
+
/**
|
|
261
|
+
* Cohesion rule weight (Reynolds 1987, flock centering), `>= 0`. Default `1`. The `'fast'` tier scales it by the
|
|
262
|
+
* boid's centrality, the length of the mean unit vector to its neighbours inside `neighborRadius` (0 inside the
|
|
263
|
+
* flock, 1 at its rim), as StarDisplay does (Hildenbrandt et al. 2010).
|
|
264
|
+
*/
|
|
265
|
+
cohesion?: number;
|
|
266
|
+
/**
|
|
267
|
+
* Perception radius for alignment and cohesion in world units, `> 0`. Default `2.9` m bird (holds the 7
|
|
268
|
+
* nearest starlings), `0.2` m fish (the tetra's attraction range).
|
|
269
|
+
*/
|
|
270
|
+
neighborRadius?: number;
|
|
271
|
+
/**
|
|
272
|
+
* Repulsion radius for separation in world units, `> 0`. Default `1.05` m bird (measured spacing), `0.03` m fish.
|
|
273
|
+
* The bird `'high'` tier reads it as StarDisplay's separation radius r_sep, calibrated, as its authors calibrate it,
|
|
274
|
+
* to the measured nearest-neighbour distance: 1.05 m gives about 0.76 m, Ballerini et al.'s flock 28-10 (0.73 m).
|
|
275
|
+
*/
|
|
276
|
+
separationRadius?: number;
|
|
277
|
+
/** Full forward vision cone angle in radians `[0.05, 2*PI]`; neighbours behind it are not seen. Default `1.5 * PI`. */
|
|
278
|
+
visionAngle?: number;
|
|
279
|
+
/**
|
|
280
|
+
* Topological neighbours a boid steers by, integer `1..128`: the nearest it sees inside `neighborRadius`, ranked by
|
|
281
|
+
* distance and then index, so the choice does not depend on the grid or the boid order. Default `7`, the six to
|
|
282
|
+
* seven neighbours starlings interact with (Ballerini et al. 2008).
|
|
283
|
+
*/
|
|
284
|
+
maxNeighbors?: number;
|
|
285
|
+
/**
|
|
286
|
+
* Model tier, `'fast'` or `'high'` (see {@link FlockFidelity}). Both steer by the same topological neighbours and
|
|
287
|
+
* share the speed limits, attractors, obstacles and bounds; `'high'` ignores the three rule weights and steers to
|
|
288
|
+
* `cruiseSpeed`, and for birds its wings, not `maxForce` and `maxTurnAccel`, limit the turns and its neighbour radius
|
|
289
|
+
* defaults to four separation radii. Default `'fast'`, the look of the rival GPU birds.
|
|
290
|
+
*/
|
|
291
|
+
fidelity?: FlockFidelity;
|
|
292
|
+
/**
|
|
293
|
+
* `'high'` tier: neighbours from `separationRadius` to this radius align, those beyond it out to `neighborRadius`
|
|
294
|
+
* attract; from `separationRadius` to `neighborRadius`. Default `0.075` m fish (where the tetra's alignment stops
|
|
295
|
+
* dominating), otherwise midway between them (at most `neighborRadius`).
|
|
296
|
+
*/
|
|
297
|
+
orientationRadius?: number;
|
|
298
|
+
/**
|
|
299
|
+
* `'high'` tier: the speed a boid steers to, from `minSpeed` to `maxSpeed`. Default `10.6` m/s bird,
|
|
300
|
+
* `0.14` m/s fish (clamped into them).
|
|
301
|
+
*/
|
|
302
|
+
cruiseSpeed?: number;
|
|
303
|
+
/**
|
|
304
|
+
* `'high'` tier: the time a boid takes to reach its desired velocity, seconds, `>= 0.001`. Default `0.5`
|
|
305
|
+
* bird, `0.8` fish.
|
|
306
|
+
*/
|
|
307
|
+
responseSeconds?: number;
|
|
308
|
+
/** `'high'` tier: how far ahead a predator's course is predicted, seconds, `>= 0`. Default `1`. */
|
|
309
|
+
predictionSeconds?: number;
|
|
310
|
+
/** Minimum cruising speed in world units per second, `> 0`. Default `6.9` m/s bird, `0.0155` m/s fish. */
|
|
311
|
+
minSpeed?: number;
|
|
312
|
+
/** Maximum cruising speed in world units per second, `>= minSpeed`. Default `15.2` m/s bird, `0.28` m/s fish. */
|
|
313
|
+
maxSpeed?: number;
|
|
314
|
+
/** Maximum flocking steering acceleration in world units per second squared, `> 0`. Default `14` bird, `0.294` fish. */
|
|
315
|
+
maxForce?: number;
|
|
316
|
+
/**
|
|
317
|
+
* Maximum lateral (centripetal) turning acceleration in world units per second squared, `> 0`. Default `12`
|
|
318
|
+
* bird, `0.252` fish.
|
|
319
|
+
*/
|
|
320
|
+
maxTurnAccel?: number;
|
|
321
|
+
/**
|
|
322
|
+
* Wander (Reynolds 1999): each boid also steers along its own seeded direction, which turns smoothly as it travels,
|
|
323
|
+
* `wander` times `maxForce`, `0..8`. Same seed, same wander. Default `0`, off.
|
|
324
|
+
*/
|
|
325
|
+
wander?: number;
|
|
326
|
+
/**
|
|
327
|
+
* Distance a boid travels while its wander direction turns once, in world units, `>= 0.001`. Default 4 x
|
|
328
|
+
* `neighborRadius`.
|
|
329
|
+
*/
|
|
330
|
+
wanderScale?: number;
|
|
331
|
+
/** A path the flock follows (see {@link FlockPath}), read each frame. Default `null`, no path. */
|
|
332
|
+
path?: FlockPath | null;
|
|
333
|
+
/** Up to 16 live attractors read each frame. Default `[]`. */
|
|
334
|
+
attractors?: readonly FlockAttractor[];
|
|
335
|
+
/** Up to 16 live predators read each frame (a pointer is a predator at its world position). Default `[]`. */
|
|
336
|
+
predators?: readonly FlockPredator[];
|
|
337
|
+
/** Up to 32 live sphere obstacles read each frame. Default `[]`. */
|
|
338
|
+
obstacles?: readonly FlockObstacle[];
|
|
339
|
+
/**
|
|
340
|
+
* Up to 4 obstacles of any shape by their distance fields (meshes baked with `bakeSDF` of `@margoengine/bvh/sdf`,
|
|
341
|
+
* terrain, hulls), at most {@link MAX_FLOCK_FIELD_SAMPLES} samples in all; placement read each frame. Default `[]`.
|
|
342
|
+
*/
|
|
343
|
+
fields?: readonly FlockFieldObstacle[];
|
|
344
|
+
/**
|
|
345
|
+
* The air or water the flock flies or swims in, such as a `Wind` or a sea current (`FlowField`,
|
|
346
|
+
* `@margoengine/math/fields`; its cell's origin is the flock's). Boids steer by their velocity through the medium
|
|
347
|
+
* and are carried by it: each step moves a boid by its velocity plus the flow, trilinear on a 4 x 4 x 4 lattice
|
|
348
|
+
* sampled over the bounds once each step call (held outside them). Default `null`, still air.
|
|
349
|
+
*/
|
|
350
|
+
flow?: FlowField | null;
|
|
351
|
+
/**
|
|
352
|
+
* Uniform mesh scale per boid, `> 0` (the mesh is scaled so its farthest vertex is 1 first). Default `0.2`
|
|
353
|
+
* bird (0.4 m wingspan), `0.0155` fish (31 mm body).
|
|
354
|
+
*/
|
|
355
|
+
scale?: number;
|
|
356
|
+
/** Banking roll sensitivity to lateral turn acceleration, `>= 0`. Default `0.55`. */
|
|
357
|
+
bankStrength?: number;
|
|
358
|
+
/** Base wing-flap or tail-swim frequency in Hz, `>= 0`. Default `5.5` (bird) or `7` (fish). */
|
|
359
|
+
flapFrequency?: number;
|
|
360
|
+
/** Wing-flap or tail-swim vertex displacement amplitude, `>= 0`. Default `0.45`. */
|
|
361
|
+
flapAmplitude?: number;
|
|
362
|
+
/** Primary boid body color (linear RGB or hex). Default `'#e8eef8'` (bird) or `'#38c6e8'` (fish). */
|
|
363
|
+
color?: ColorInput;
|
|
364
|
+
/** Secondary wingtip/fin accent color varied across boids. Default `'#4c7cc2'` (bird) or `'#f0a83c'` (fish). */
|
|
365
|
+
accentColor?: ColorInput;
|
|
366
|
+
/** World-space direction toward the key directional light (non-zero). Default `[0.45, 1, 0.35]`. */
|
|
367
|
+
lightDirection?: FlockVec3;
|
|
368
|
+
/** Directional light color (linear RGB or hex). Default `[1, 1, 1]`. */
|
|
369
|
+
lightColor?: ColorInput;
|
|
370
|
+
/** Hemisphere ambient floor in `0..1`. Default `0.38`. */
|
|
371
|
+
ambient?: number;
|
|
372
|
+
/**
|
|
373
|
+
* The scene's lights in place of the flock's own: with `lit` set (`{}` for the sun alone) each boid is shaded by the
|
|
374
|
+
* engine's sun and ambient (`engine.lighting`, read every frame), plus `lights` (`Clustered` of
|
|
375
|
+
* `@margoengine/clustered`: point and spot lights) and `shadows` (`Shadows` of `@margoengine/shadows`: the sun's
|
|
376
|
+
* shadows on the boids); `lightDirection`, `lightColor` and `ambient` are then unused. Default `null`.
|
|
377
|
+
*/
|
|
378
|
+
lit?: FlockLit | null;
|
|
379
|
+
/** Pause frame-driven integration while keeping rendering active (`step(dt)` still runs). Default `false`. */
|
|
380
|
+
paused?: boolean;
|
|
381
|
+
/** Initial debug overlay settings. */
|
|
382
|
+
debug?: FlockDebugOptions;
|
|
383
|
+
}
|
|
384
|
+
/** Live statistics of a `GPUFlock`. */
|
|
385
|
+
export interface FlockStats {
|
|
386
|
+
/** Active boid count. */
|
|
387
|
+
count: number;
|
|
388
|
+
/** Where the flock steps: `'webgpu'` compute, or `'webgl2-compat'`, the CPU twin on the WebGL2 layer. */
|
|
389
|
+
backend: 'webgpu' | 'webgl2-compat';
|
|
390
|
+
/** Draw calls submitted in the last rendered frame. */
|
|
391
|
+
drawCalls: number;
|
|
392
|
+
/** Number of uniform-grid hash buckets in use. */
|
|
393
|
+
gridCells: number;
|
|
394
|
+
/** Integration steps run since attach, reset or restore (a long `dt` counts each of its equal steps). */
|
|
395
|
+
steps: number;
|
|
396
|
+
/** Whether the debug overlay is currently enabled. */
|
|
397
|
+
debugEnabled: boolean;
|
|
398
|
+
}
|
|
399
|
+
/** Normalized parameters after validation and defaulting. */
|
|
400
|
+
export interface ResolvedFlockParams {
|
|
401
|
+
count: number;
|
|
402
|
+
seed: number;
|
|
403
|
+
preset: FlockPreset;
|
|
404
|
+
boundsShape: 0 | 1;
|
|
405
|
+
boundsCenter: [number, number, number];
|
|
406
|
+
boundsHalf: [number, number, number];
|
|
407
|
+
boundsRadius: number;
|
|
408
|
+
boundsMargin: number;
|
|
409
|
+
boundsStrength: number;
|
|
410
|
+
separation: number;
|
|
411
|
+
alignment: number;
|
|
412
|
+
cohesion: number;
|
|
413
|
+
neighborRadius: number;
|
|
414
|
+
separationRadius: number;
|
|
415
|
+
visionAngle: number;
|
|
416
|
+
cosHalfVision: number;
|
|
417
|
+
maxNeighbors: number;
|
|
418
|
+
fidelity: FlockFidelity;
|
|
419
|
+
orientationRadius: number;
|
|
420
|
+
cruiseSpeed: number;
|
|
421
|
+
responseSeconds: number;
|
|
422
|
+
predictionSeconds: number;
|
|
423
|
+
minSpeed: number;
|
|
424
|
+
maxSpeed: number;
|
|
425
|
+
maxForce: number;
|
|
426
|
+
maxTurnAccel: number;
|
|
427
|
+
/** Wander weight, a fraction of `maxForce`. */
|
|
428
|
+
wander: number;
|
|
429
|
+
/** 1 / `wanderScale`. */
|
|
430
|
+
wanderInvScale: number;
|
|
431
|
+
/** PCG hash of the seed, the root of each boid's wander phases. */
|
|
432
|
+
seedHash: number;
|
|
433
|
+
/** The path the flock follows, or `null`. */
|
|
434
|
+
path: ResolvedFlockPath | null;
|
|
435
|
+
scale: number;
|
|
436
|
+
bankStrength: number;
|
|
437
|
+
flapFrequency: number;
|
|
438
|
+
flapAmplitude: number;
|
|
439
|
+
color: [number, number, number];
|
|
440
|
+
accentColor: [number, number, number];
|
|
441
|
+
lightDirection: [number, number, number];
|
|
442
|
+
lightColor: [number, number, number];
|
|
443
|
+
ambient: number;
|
|
444
|
+
lit: FlockLit | null;
|
|
445
|
+
paused: boolean;
|
|
446
|
+
attractors: readonly FlockAttractor[];
|
|
447
|
+
predators: readonly FlockPredator[];
|
|
448
|
+
obstacles: readonly FlockObstacle[];
|
|
449
|
+
fields: readonly ResolvedFlockField[];
|
|
450
|
+
flow: FlowField | null;
|
|
451
|
+
debug: Required<FlockDebugOptions>;
|
|
452
|
+
}
|
|
453
|
+
/** CPU-side simulation state, for tests and the WebGL2 compatibility layer's route. */
|
|
454
|
+
export interface FlockSimulationState {
|
|
455
|
+
/** Number of boids. */
|
|
456
|
+
readonly count: number;
|
|
457
|
+
/** Eight floats a boid: x, y, z, animation phase, vx, vy, vz, bank angle (length `count * 8`). */
|
|
458
|
+
readonly boids: Float32Array;
|
|
459
|
+
/** Eight `vec4f` records for the inspected boid, the debug overlay's input (length `32`). */
|
|
460
|
+
readonly debugData: Float32Array;
|
|
461
|
+
/** Seconds stepped, the time the flow is sampled at. Default `0`. */
|
|
462
|
+
time?: number;
|
|
463
|
+
/** Scratch buffers reused by every step. */
|
|
464
|
+
readonly scratch: {
|
|
465
|
+
next: Float32Array;
|
|
466
|
+
cellCounts: Uint32Array;
|
|
467
|
+
cellOffsets: Uint32Array;
|
|
468
|
+
cellCursor: Uint32Array;
|
|
469
|
+
boidCell: Uint32Array;
|
|
470
|
+
sortedIdx: Uint32Array;
|
|
471
|
+
seen: Uint32Array;
|
|
472
|
+
gridCells: number;
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
/** A copy of a flock's state that `restore` takes back. */
|
|
476
|
+
export interface FlockSnapshot {
|
|
477
|
+
/** Number of boids. */
|
|
478
|
+
readonly count: number;
|
|
479
|
+
/** Integration steps run when it was taken. */
|
|
480
|
+
readonly steps: number;
|
|
481
|
+
/** Eight floats a boid: x, y, z, animation phase, vx, vy, vz, bank angle. */
|
|
482
|
+
readonly boids: Float32Array;
|
|
483
|
+
/** Seconds stepped when it was taken, the flow's clock. Default `0`. */
|
|
484
|
+
readonly time?: number;
|
|
485
|
+
}
|
|
486
|
+
/** A preset's member defaults: the measured animal it stands for, in metres and seconds. */
|
|
487
|
+
export interface FlockMemberDefaults {
|
|
488
|
+
/** The animal the numbers come from. */
|
|
489
|
+
readonly species: string;
|
|
490
|
+
/** Mesh scale: half the wingspan (bird) or half the body length (fish), metres. */
|
|
491
|
+
readonly scale: number;
|
|
492
|
+
/** Separation radius, the spacing a member keeps from its nearest neighbour, metres. */
|
|
493
|
+
readonly separationRadius: number;
|
|
494
|
+
/** Neighbour radius, wide enough to hold the 7 nearest, metres. */
|
|
495
|
+
readonly neighborRadius: number;
|
|
496
|
+
/** `'high'` tier: where alignment gives way to attraction, metres; absent, midway between the two radii above. */
|
|
497
|
+
readonly orientationRadius?: number;
|
|
498
|
+
/** Slowest speed, metres a second. */
|
|
499
|
+
readonly minSpeed: number;
|
|
500
|
+
/** Typical speed (the `'high'` tier steers to it), metres a second. */
|
|
501
|
+
readonly cruiseSpeed: number;
|
|
502
|
+
/** Fastest cruising speed, metres a second. */
|
|
503
|
+
readonly maxSpeed: number;
|
|
504
|
+
/** Steering acceleration cap, metres a second squared. */
|
|
505
|
+
readonly maxForce: number;
|
|
506
|
+
/** Lateral turning acceleration cap, metres a second squared. */
|
|
507
|
+
readonly maxTurnAccel: number;
|
|
508
|
+
/** Default box half-size, metres. */
|
|
509
|
+
readonly boundsHalfSize: readonly [number, number, number];
|
|
510
|
+
/** Default soft margin inside the bounds, metres. */
|
|
511
|
+
readonly boundsMargin: number;
|
|
512
|
+
/** Default predator detection radius, metres. */
|
|
513
|
+
readonly predatorRadius: number;
|
|
514
|
+
/** `'high'` tier: seconds to reach the desired velocity. */
|
|
515
|
+
readonly responseSeconds: number;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Member defaults of each preset, in metres and seconds, from measured animals (sources in docs/clean-room.md, "GPU
|
|
519
|
+
* flocking"). `'bird'` is the European starling of M. Ballerini et al. 2008 (Animal Behaviour 76; PNAS 105):
|
|
520
|
+
* 0.4 m wingspan, the mean nearest-neighbour distance of their ten flocks (1.05 m), a radius holding the 7 nearest
|
|
521
|
+
* even in the sparsest flock (2.9 m), and their flocks' mean speeds, 6.9 to 15.2 m/s, mean 10.6. `'fish'` is the
|
|
522
|
+
* rummy-nose tetra of D. S. Calovi et al. 2018 (PLoS Comput Biol 14): 31 mm body, repulsion within about 30 mm, alignment dominant to
|
|
523
|
+
* 75 mm, attraction peaking at 200 mm (l_Att, which W. Wang et al. 2022, PLoS Comput Biol 18, also take), the turn cap
|
|
524
|
+
* of its measured heading changes, 140 mm/s typical speed, a 0.8 s relaxation time, and 0.5 body lengths a second as the slowest swimming that
|
|
525
|
+
* counts (also Y. Katz et al. 2011, PNAS 108). The fish's top speed is twice its typical speed, a bound and not a
|
|
526
|
+
* measurement. Any option passed overrides these.
|
|
527
|
+
*/
|
|
528
|
+
export declare const FLOCK_PRESET_DEFAULTS: Readonly<Record<FlockPreset, FlockMemberDefaults>>;
|
|
529
|
+
/** Default flock configuration values: the `'bird'` preset's (the fish's members are in `FLOCK_PRESET_DEFAULTS`). */
|
|
530
|
+
export declare const DEFAULT_FLOCK_OPTIONS: Readonly<{
|
|
531
|
+
count: 4096;
|
|
532
|
+
seed: 1337;
|
|
533
|
+
preset: FlockPreset;
|
|
534
|
+
boundsMargin: 3;
|
|
535
|
+
boundsStrength: 6;
|
|
536
|
+
separation: 1.8;
|
|
537
|
+
alignment: 1.1;
|
|
538
|
+
cohesion: 1;
|
|
539
|
+
neighborRadius: 2.9;
|
|
540
|
+
separationRadius: 1.05;
|
|
541
|
+
visionAngle: number;
|
|
542
|
+
maxNeighbors: 7;
|
|
543
|
+
minSpeed: 6.9;
|
|
544
|
+
maxSpeed: 15.2;
|
|
545
|
+
maxForce: 14;
|
|
546
|
+
maxTurnAccel: 12;
|
|
547
|
+
scale: 0.2;
|
|
548
|
+
bankStrength: 0.55;
|
|
549
|
+
flapAmplitude: 0.45;
|
|
550
|
+
ambient: 0.38;
|
|
551
|
+
}>;
|
|
552
|
+
/** A flock input that cannot be used: code `unsupported`, the message naming the input and its fix, and the help link. */
|
|
553
|
+
export declare function flockError(message: string): MargoError;
|
|
554
|
+
/**
|
|
555
|
+
* The hash grid's cell width: the wider of the neighbour and separation radii, so a boid's 3 x 3 x 3 cells hold every
|
|
556
|
+
* boid it can see at any scale (a 31 mm tetra's school as a starling flock), with no fixed floor.
|
|
557
|
+
*/
|
|
558
|
+
export declare function flockCellSize(p: {
|
|
559
|
+
neighborRadius: number;
|
|
560
|
+
separationRadius: number;
|
|
561
|
+
}): number;
|
|
562
|
+
/** PCG hash (M. E. O'Neill 2014, in the form of Jarzynski and Olano 2020) of a u32; the WGSL `pcgWander` is the same. */
|
|
563
|
+
export declare function pcgHash(v: number): number;
|
|
564
|
+
/**
|
|
565
|
+
* Boid `i`'s wander direction at `(x, y, z)`, each component in [-1, 1]: per axis, the mean of two waves along fixed
|
|
566
|
+
* directions over `wanderScale`, shifted by phases hashed from the seed and the boid's index. A boid flying through it
|
|
567
|
+
* turns smoothly once every `wanderScale` or so, and no two boids share their phases (Reynolds 1999's wander, as a
|
|
568
|
+
* stateless field so it needs no stored jitter and replays bit for bit).
|
|
569
|
+
*/
|
|
570
|
+
export declare function flockWanderAt(p: Pick<ResolvedFlockParams, 'wanderInvScale' | 'seedHash'>, i: number, x: number, y: number, z: number, out: Float32Array | number[]): void;
|
|
571
|
+
/**
|
|
572
|
+
* Reynolds 1999 path following for a boid predicted to be at `(fx, fy, fz)`: finds the nearest point of the path to
|
|
573
|
+
* the prediction (the first segment wins a tie). When the prediction is farther than the tube radius, writes the point
|
|
574
|
+
* `lookahead` further along the path (wrapped on a loop, held at the last point otherwise) to `out` and returns
|
|
575
|
+
* `true`; inside the tube returns `false`. The WGSL `pathTarget` is the same.
|
|
576
|
+
*/
|
|
577
|
+
export declare function flockPathTarget(path: ResolvedFlockPath, fx: number, fy: number, fz: number, out: number[]): boolean;
|
|
578
|
+
/** Power-of-two spatial-hash table size: 16,384 to 65,536 buckets, so one two-level 256-wide prefix scan covers it. */
|
|
579
|
+
export declare function gridCellsForCount(count: number): number;
|
|
580
|
+
/** Spatial hash of a grid cell (Teschner et al. 2003), the same bits as the WGSL solver's. */
|
|
581
|
+
export declare function hashCell(cx: number, cy: number, cz: number, mask: number): number;
|
|
582
|
+
/** FNV-1a (32-bit) of the state's bytes as 8 hex digits: equal states give equal hashes. */
|
|
583
|
+
export declare function flockStateHash(boids: Float32Array): string;
|
|
584
|
+
/**
|
|
585
|
+
* The distance from world point (x, y, z) to a field obstacle's surface, negative inside, and its unit outward
|
|
586
|
+
* gradient in `out` (world space). Trilinear in the cell, as `MeshSDF.distance`; outside the grid it adds the way to the
|
|
587
|
+
* grid. The gradient is that function's own: the trilinear slope on the axes inside the grid, the way out on the
|
|
588
|
+
* others. The WGSL `fieldAt` is this in f32.
|
|
589
|
+
*/
|
|
590
|
+
export declare function sampleFlockField(f: ResolvedFlockField, x: number, y: number, z: number, out: number[]): number;
|
|
591
|
+
/** Validates and resolves `GPUFlockOptions`; throws a coded `MargoError` naming the bad option. */
|
|
592
|
+
export declare function resolveFlockParams(options?: GPUFlockOptions, fixedCount?: number): ResolvedFlockParams;
|
|
593
|
+
/**
|
|
594
|
+
* Built-in swept-wing bird mesh (`+Z` forward, `+Y` up, `+X` right).
|
|
595
|
+
* Per-vertex `weights` are `0` along the spine and `1` at the wingtips for the wing flap.
|
|
596
|
+
*/
|
|
597
|
+
export declare function createBirdGeometry(): FlockGeometry;
|
|
598
|
+
/**
|
|
599
|
+
* Built-in fish mesh (`+Z` forward, `+Y` up, `+X` right).
|
|
600
|
+
* Per-vertex `weights` rise from `0` at the snout to `1` at the tail fin for the swimming wave.
|
|
601
|
+
*/
|
|
602
|
+
export declare function createFishGeometry(): FlockGeometry;
|
|
603
|
+
/** Validates and packs a mesh into corner records (two `vec4f` a triangle corner) and scales it to a unit radius. */
|
|
604
|
+
export declare function packFlockGeometry(geometry: FlockGeometry | FlockInterleavedGeometry, preset: FlockPreset): {
|
|
605
|
+
corners: Float32Array;
|
|
606
|
+
vertexCount: number;
|
|
607
|
+
};
|
|
608
|
+
/** Seeds a `FlockSimulationState` inside the bounds: the same seed gives the same state. */
|
|
609
|
+
export declare function createFlockState(options?: GPUFlockOptions): FlockSimulationState;
|
|
610
|
+
/** How many equal steps no longer than `FLOCK_MAX_SUBSTEP` a `dt` splits into; throws for a `dt` out of range. */
|
|
611
|
+
export declare function flockSubsteps(dt: number): number;
|
|
612
|
+
/**
|
|
613
|
+
* Advances a `FlockSimulationState` by `dt` seconds (0 to 1, split into equal steps of at most 0.05 s) with the
|
|
614
|
+
* WebGPU solver's model, steps and order: counting sort into hash buckets, 3 x 3 x 3 cell neighbourhood, the rules,
|
|
615
|
+
* then integration. Ignores `paused`. Returns the number of steps run.
|
|
616
|
+
*/
|
|
617
|
+
export declare function stepFlockCPU(state: FlockSimulationState, options: GPUFlockOptions, dt: number): number;
|
|
618
|
+
/**
|
|
619
|
+
* Samples `p.flow` at time `t` on the 4 x 4 x 4 lattice over the flock's bounds box (a sphere's enclosing box), into
|
|
620
|
+
* `out` (`FLOCK_FLOW_FLOATS` floats, the uniform's layout): origin, spacing with an on flag, then the velocities with
|
|
621
|
+
* x fastest. Without a flow it writes zeros (flag off). Returns `out`.
|
|
622
|
+
*/
|
|
623
|
+
export declare function sampleFlockFlow(p: ResolvedFlockParams, t: number, out: Float32Array): Float32Array;
|