@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,145 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
import { type FlockAttractor, type FlockFieldObstacle, type FlockDebugOptions, type FlockGeometry, type FlockInterleavedGeometry, type FlockObstacle, type FlockPath, type FlockPredator, type FlockPreset, type FlockSnapshot, type FlockStats, type GPUFlockOptions } from './flocking-sim.js';
|
|
5
|
+
export { createBirdGeometry, createFishGeometry, createFlockState, DEFAULT_FLOCK_OPTIONS, FLOCK_BOID_FLOATS, FLOCK_FLOW_FLOATS, FLOCK_MAX_STEP, FLOCK_MAX_SUBSTEP, FLOCK_PRESET_DEFAULTS, flockCellSize, flockStateHash, flockPathTarget, flockWanderAt, gridCellsForCount, hashCell, MAX_FLOCK_ATTRACTORS, MAX_FLOCK_BOIDS, MAX_FLOCK_FIELD_SAMPLES, MAX_FLOCK_FIELDS, MAX_FLOCK_MESH_TRIANGLES, MAX_FLOCK_OBSTACLES, MAX_FLOCK_PATH_POINTS, MAX_FLOCK_PREDATORS, packFlockGeometry, pcgHash, resolveFlockParams, sampleFlockField, sampleFlockFlow, stepFlockCPU, } from './flocking-sim.js';
|
|
6
|
+
export type { FlockAttractor, FlockBody, FlockBounds, FlockDebugOptions, FlockDistanceField, FlockFidelity, FlockFieldObstacle, FlockGeometry, FlockInterleavedGeometry, FlockMemberDefaults, FlockLit, FlockObstacle, FlockPath, FlockPredator, FlockPreset, FlockSimulationState, FlockSnapshot, FlockStats, FlockVec3, GPUFlockOptions, ResolvedFlockField, ResolvedFlockParams, ResolvedFlockPath, } from './flocking-sim.js';
|
|
7
|
+
/**
|
|
8
|
+
* GPU boid flock (`@margoengine/vfx/flocking`), an engine plugin.
|
|
9
|
+
*
|
|
10
|
+
* On WebGPU every step runs on the GPU (eight compute passes, no readback) and one instanced draw shows up to
|
|
11
|
+
* 262,144 birds or fish facing their velocity, banking into turns and flapping or swimming. Steps are deterministic: the
|
|
12
|
+
* same options and seed give the same state on the same GPU and driver, also after `snapshot` and `restore`. On the
|
|
13
|
+
* WebGL2 compatibility layer the same steps run on the CPU (`stats.backend` is `'webgl2-compat'`) and the same draw shows
|
|
14
|
+
* them; keep counts there to a few thousand. Throws a coded `MargoError` (help link) for any bad option.
|
|
15
|
+
*/
|
|
16
|
+
export declare class GPUFlock implements EnginePlugin {
|
|
17
|
+
/** Unique plugin name registered on the engine's frame graph. */
|
|
18
|
+
readonly name: string;
|
|
19
|
+
/** Live options; every field but `count` can change between frames. */
|
|
20
|
+
readonly options: GPUFlockOptions;
|
|
21
|
+
/** Boid count, fixed at construction. */
|
|
22
|
+
readonly count: number;
|
|
23
|
+
/** Live statistics. */
|
|
24
|
+
readonly stats: FlockStats;
|
|
25
|
+
private engine?;
|
|
26
|
+
private device?;
|
|
27
|
+
private disposed;
|
|
28
|
+
private compat;
|
|
29
|
+
private ping;
|
|
30
|
+
private readonly gridCells;
|
|
31
|
+
private meshVertexCount;
|
|
32
|
+
private meshDirty;
|
|
33
|
+
private mesh;
|
|
34
|
+
private pending?;
|
|
35
|
+
private needsInit;
|
|
36
|
+
private cpuState?;
|
|
37
|
+
private cpuDirty;
|
|
38
|
+
private clocked;
|
|
39
|
+
/** Frame deltas `advanceTime` took since the last simulate pass, each run in order by the next one. */
|
|
40
|
+
private owed;
|
|
41
|
+
private owned;
|
|
42
|
+
private states;
|
|
43
|
+
private meshBuf?;
|
|
44
|
+
private simUniform?;
|
|
45
|
+
private debugBuf?;
|
|
46
|
+
private renderUniform?;
|
|
47
|
+
private debugUniform?;
|
|
48
|
+
private compute?;
|
|
49
|
+
private fieldBuf?;
|
|
50
|
+
/** The sample arrays of the fields now in fieldBuf, in order. */
|
|
51
|
+
private fieldData;
|
|
52
|
+
private bindStep?;
|
|
53
|
+
/** Draw shader modules by their code: the own-light one and one per set of scene light sources. */
|
|
54
|
+
private renderModules;
|
|
55
|
+
/** The last lit draw shader: the sources' flags and declarations it was made from, and its code. */
|
|
56
|
+
private litCode?;
|
|
57
|
+
/** The scene light sources' bind group (group 1) of each lit pipeline, with the binding arrays it was made from. */
|
|
58
|
+
private litGroups;
|
|
59
|
+
private debugModule?;
|
|
60
|
+
private velocityModule?;
|
|
61
|
+
private renderPipelines;
|
|
62
|
+
private debugPipelines;
|
|
63
|
+
private readonly simData;
|
|
64
|
+
/** Seconds stepped since attach, reset or restore: the clock the flow is sampled at. */
|
|
65
|
+
private time;
|
|
66
|
+
private readonly simU32;
|
|
67
|
+
private readonly simF32;
|
|
68
|
+
private readonly renderData;
|
|
69
|
+
private readonly debugUniformData;
|
|
70
|
+
private readonly attachments;
|
|
71
|
+
private readonly colorAttachment;
|
|
72
|
+
private readonly depthAttachment;
|
|
73
|
+
private readonly renderPassDesc;
|
|
74
|
+
private readonly debugDepthAttachment;
|
|
75
|
+
private readonly debugPassDesc;
|
|
76
|
+
/** Creates a flock; pass it to `engine.use(flock)`, or use {@link GPUFlock.attach}. */
|
|
77
|
+
constructor(options?: GPUFlockOptions);
|
|
78
|
+
/** Creates a {@link GPUFlock} and attaches it to `engine`. */
|
|
79
|
+
static attach(engine: EngineKernel, options?: GPUFlockOptions): GPUFlock;
|
|
80
|
+
private assertAlive;
|
|
81
|
+
/** Merges debug overlay settings (velocity lines, grid, perception, vectors, inspected boid). */
|
|
82
|
+
setDebug(debug: FlockDebugOptions): void;
|
|
83
|
+
/** The current debug overlay settings with their defaults filled in. */
|
|
84
|
+
getDebug(): Required<FlockDebugOptions>;
|
|
85
|
+
/**
|
|
86
|
+
* Switches between the `'bird'` and `'fish'` presets, and optionally the mesh (copied now, so its source can be
|
|
87
|
+
* disposed), without recreating the flock. Change the mesh or the preset through this, not `options`.
|
|
88
|
+
*/
|
|
89
|
+
setPreset(preset: FlockPreset, geometry?: FlockGeometry | FlockInterleavedGeometry | null): void;
|
|
90
|
+
/** Replaces the attractors (up to 16). */
|
|
91
|
+
setAttractors(attractors: readonly FlockAttractor[]): void;
|
|
92
|
+
/** Replaces the predators (up to 16); a pointer is a predator at its world position. */
|
|
93
|
+
setPredators(predators: readonly FlockPredator[]): void;
|
|
94
|
+
/** Replaces the sphere obstacles (up to 32). */
|
|
95
|
+
setObstacles(obstacles: readonly FlockObstacle[]): void;
|
|
96
|
+
/** Replaces the distance-field obstacles (up to 4); a field whose `data` the flock has not seen uploads again. */
|
|
97
|
+
setFields(fields: readonly FlockFieldObstacle[]): void;
|
|
98
|
+
/** Replaces the path the flock follows (up to 16 points), or clears it with `null`. */
|
|
99
|
+
setPath(path: FlockPath | null): void;
|
|
100
|
+
/** Starts the flock again from `seed` (default: `options.seed`), the same state every time for a seed. */
|
|
101
|
+
reset(seed?: number): void;
|
|
102
|
+
/**
|
|
103
|
+
* Advances the flock by `dt` seconds now (0 to 1, in equal steps of at most 0.05 s), also while `paused`. Call it
|
|
104
|
+
* between frames; needs the flock attached.
|
|
105
|
+
*/
|
|
106
|
+
step(dt: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* Copies the flock's state, read back from the GPU (or the CPU twin on the WebGL2 layer). `restore` takes it back;
|
|
109
|
+
* `flockStateHash(snapshot.boids)` compares two.
|
|
110
|
+
*/
|
|
111
|
+
snapshot(): Promise<FlockSnapshot>;
|
|
112
|
+
/** Puts the flock back to a `snapshot` of a flock of the same count; the steps after it repeat exactly. */
|
|
113
|
+
restore(snapshot: FlockSnapshot): void;
|
|
114
|
+
/** Steps the CPU twin on the flock's clock. */
|
|
115
|
+
private stepTwin;
|
|
116
|
+
/** Checks WebGPU and the device's buffer limits for this count. */
|
|
117
|
+
setup(engine: Engine): void;
|
|
118
|
+
/** Registers the step, the instanced draw and the debug overlay on the frame graph. */
|
|
119
|
+
registerPasses(graph: FrameGraph): void;
|
|
120
|
+
/**
|
|
121
|
+
* The CPU part of a frame update, for `@margoengine/cutscene/seek`: owes the flock one frame step of `delta` seconds
|
|
122
|
+
* (at most 0.25; none while `paused`), run by the next simulate pass in the order owed. A seek's replayed steps and a
|
|
123
|
+
* live run's frames therefore step the flock alike, and a frame drawn into several views steps it once.
|
|
124
|
+
*/
|
|
125
|
+
advanceTime(delta: number): void;
|
|
126
|
+
/** Takes the frame delta once a tick, through {@link GPUFlock.advanceTime}. */
|
|
127
|
+
onPreUpdate(delta: number): void;
|
|
128
|
+
private buffer;
|
|
129
|
+
private ensureResources;
|
|
130
|
+
private writeSimUniforms;
|
|
131
|
+
/** Uploads the field samples when the flock's fields hold other arrays than last time, growing the buffer to fit. */
|
|
132
|
+
private writeFields;
|
|
133
|
+
/** Encodes `n` equal steps of `dt / n` seconds, ping-ponging the state buffers. */
|
|
134
|
+
private encodeSteps;
|
|
135
|
+
private simulate;
|
|
136
|
+
private draw;
|
|
137
|
+
private drawDebug;
|
|
138
|
+
private release;
|
|
139
|
+
/** Rebuilds every GPU buffer and pipeline after a device restore; the flock starts again from its seed. */
|
|
140
|
+
onDeviceRestored(engine: Engine): void;
|
|
141
|
+
/** Releases every GPU resource and detaches the flock from its engine. */
|
|
142
|
+
dispose(): void;
|
|
143
|
+
/** `using flock = GPUFlock.attach(...)` disposes it at the end of the scope. */
|
|
144
|
+
[Symbol.dispose]: () => void;
|
|
145
|
+
}
|