@woosh/meep-engine 3.18.0 → 3.19.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.
Files changed (120) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/editor/view/particles/effect/ParticleCurveEditorView.d.ts.map +1 -1
  3. package/editor/view/particles/effect/ParticleCurveEditorView.js +303 -120
  4. package/editor/view/particles/effect/ParticleGradientEditorView.d.ts.map +1 -1
  5. package/editor/view/particles/effect/ParticleGradientEditorView.js +108 -63
  6. package/editor/view/particles/effect/ParticleGraphEditorView.js +1 -1
  7. package/editor/view/particles/effect/ParticleNodeParametersView.d.ts.map +1 -1
  8. package/editor/view/particles/effect/ParticleNodeParametersView.js +3 -1
  9. package/editor/view/particles/effect/particle-editor.css +60 -30
  10. package/package.json +1 -2
  11. package/samples/engine/README.md +1 -1
  12. package/src/core/binary/compression/decompress_bytes.d.ts +13 -0
  13. package/src/core/binary/compression/decompress_bytes.d.ts.map +1 -0
  14. package/src/core/binary/compression/decompress_bytes.js +28 -0
  15. package/src/core/model/node-graph/visual/layout/layout_assign_coordinates.js +67 -22
  16. package/src/engine/asset/loaders/image/ImageDecoderWorker.js +12 -27
  17. package/src/engine/asset/loaders/image/prototypePNG.js +8 -7
  18. package/src/engine/ecs/storage/populateEngineSerializationRegistry.d.ts.map +1 -1
  19. package/src/engine/ecs/storage/populateEngineSerializationRegistry.js +4 -0
  20. package/src/engine/graphics/ecs/particles/ParticleEffect.d.ts +266 -0
  21. package/src/engine/graphics/ecs/particles/ParticleEffect.d.ts.map +1 -0
  22. package/src/engine/graphics/ecs/particles/ParticleEffect.js +455 -0
  23. package/src/engine/graphics/ecs/particles/ParticleEffectSerializationAdapter.d.ts +58 -0
  24. package/src/engine/graphics/ecs/particles/ParticleEffectSerializationAdapter.d.ts.map +1 -0
  25. package/src/engine/graphics/ecs/particles/ParticleEffectSerializationAdapter.js +219 -0
  26. package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts +178 -25
  27. package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts.map +1 -1
  28. package/src/engine/graphics3/GPUParticleEmitterSystem.js +809 -310
  29. package/src/format/image/png/PNGReader.d.ts +7 -6
  30. package/src/format/image/png/PNGReader.d.ts.map +1 -1
  31. package/src/format/image/png/PNGReader.js +13 -12
  32. package/src/format/image/png/chunk/png_chunk_decode_iTXt.d.ts +3 -2
  33. package/src/format/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +1 -1
  34. package/src/format/image/png/chunk/png_chunk_decode_iTXt.js +5 -4
  35. package/src/format/image/png/chunk/png_chunk_decode_zTXt.d.ts +3 -2
  36. package/src/format/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +1 -1
  37. package/src/format/image/png/chunk/png_chunk_decode_zTXt.js +5 -4
  38. package/src/format/image/png/png_inflate.d.ts +3 -3
  39. package/src/format/image/png/png_inflate.d.ts.map +1 -1
  40. package/src/format/image/png/png_inflate.js +29 -39
  41. package/src/format/texture/ktx2/ktx2_read.d.ts +4 -4
  42. package/src/format/texture/ktx2/ktx2_read.d.ts.map +1 -1
  43. package/src/format/texture/ktx2/ktx2_read.js +18 -21
  44. package/src/shade/playground/particle_ecs/README.md +203 -0
  45. package/src/shade/playground/particle_ecs/bonfire_editor.d.ts +39 -0
  46. package/src/shade/playground/particle_ecs/bonfire_editor.d.ts.map +1 -0
  47. package/src/shade/playground/particle_ecs/bonfire_editor.js +315 -0
  48. package/src/shade/playground/particle_ecs/bonfire_effects.d.ts +145 -0
  49. package/src/shade/playground/particle_ecs/bonfire_effects.d.ts.map +1 -0
  50. package/src/shade/playground/particle_ecs/bonfire_effects.js +202 -0
  51. package/src/shade/playground/particle_ecs/bonfire_sprites.d.ts +23 -0
  52. package/src/shade/playground/particle_ecs/bonfire_sprites.d.ts.map +1 -0
  53. package/src/shade/playground/particle_ecs/bonfire_sprites.js +315 -0
  54. package/src/shade/playground/particle_ecs/bonfire_world.d.ts +86 -0
  55. package/src/shade/playground/particle_ecs/bonfire_world.d.ts.map +1 -0
  56. package/src/shade/playground/particle_ecs/bonfire_world.js +303 -0
  57. package/src/shade/playground/particle_ecs/effects/embers.json +1634 -0
  58. package/src/shade/playground/particle_ecs/effects/flame.json +1882 -0
  59. package/src/shade/playground/particle_ecs/effects/smoke.json +1860 -0
  60. package/src/shade/playground/particle_ecs/effects/soot.json +1606 -0
  61. package/src/shade/playground/particle_ecs/index.html +330 -0
  62. package/src/shade/playground/particle_ecs/main.d.ts +2 -0
  63. package/src/shade/playground/particle_ecs/main.d.ts.map +1 -0
  64. package/src/shade/playground/particle_ecs/main.js +566 -0
  65. package/src/shade/playground/particle_ecs/moonlit_environment.d.ts +16 -0
  66. package/src/shade/playground/particle_ecs/moonlit_environment.d.ts.map +1 -0
  67. package/src/shade/playground/particle_ecs/moonlit_environment.js +144 -0
  68. package/src/shade/playground/particle_editor/README.md +5 -4
  69. package/src/shade/playground/profile_hotkey.d.ts +58 -0
  70. package/src/shade/playground/profile_hotkey.d.ts.map +1 -0
  71. package/src/shade/playground/profile_hotkey.js +325 -0
  72. package/src/shade/playground/ssr_variance/README.md +105 -0
  73. package/src/shade/playground/ssr_variance/capture.d.ts +16 -0
  74. package/src/shade/playground/ssr_variance/capture.d.ts.map +1 -0
  75. package/src/shade/playground/ssr_variance/capture.js +96 -0
  76. package/src/shade/playground/ssr_variance/index.html +22 -0
  77. package/src/shade/playground/ssr_variance/main.d.ts +2 -0
  78. package/src/shade/playground/ssr_variance/main.d.ts.map +1 -0
  79. package/src/shade/playground/ssr_variance/main.js +246 -0
  80. package/src/shade/playground/ssr_variance/reference.d.ts +18 -0
  81. package/src/shade/playground/ssr_variance/reference.d.ts.map +1 -0
  82. package/src/shade/playground/ssr_variance/reference.js +78 -0
  83. package/src/shade/playground/ssr_variance/scene.d.ts +11 -0
  84. package/src/shade/playground/ssr_variance/scene.d.ts.map +1 -0
  85. package/src/shade/playground/ssr_variance/scene.js +61 -0
  86. package/src/shade/playground/ssr_variance/statistics.d.ts +44 -0
  87. package/src/shade/playground/ssr_variance/statistics.d.ts.map +1 -0
  88. package/src/shade/playground/ssr_variance/statistics.js +51 -0
  89. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts.map +1 -1
  90. package/src/shade/renderer/loader/gltf/tiny-gltf.js +9 -3
  91. package/src/shade/renderer/loader/usd/usd_decode_image.d.ts +4 -4
  92. package/src/shade/renderer/loader/usd/usd_decode_image.d.ts.map +1 -1
  93. package/src/shade/renderer/loader/usd/usd_decode_image.js +4 -4
  94. package/src/shade/renderer/particles/DESIGN.md +748 -703
  95. package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts +11 -4
  96. package/src/shade/renderer/particles/runtime/ParticleEmitter.d.ts.map +1 -1
  97. package/src/shade/renderer/particles/runtime/ParticleEmitter.js +431 -424
  98. package/src/shade/renderer/postprocess/ssr/SSR.d.ts.map +1 -1
  99. package/src/shade/renderer/postprocess/ssr/SSR.js +2 -1
  100. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_reprojection.d.ts.map +1 -1
  101. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_reprojection.js +0 -6
  102. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_sample_history.d.ts.map +1 -1
  103. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_sample_history.js +19 -5
  104. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_temporal_accumulate.d.ts +4 -0
  105. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_temporal_accumulate.d.ts.map +1 -0
  106. package/src/shade/renderer/postprocess/ssr/reproject/chunk_ssr_temporal_accumulate.js +133 -0
  107. package/src/shade/renderer/postprocess/ssr/ssr_reproject_shader.d.ts +0 -8
  108. package/src/shade/renderer/postprocess/ssr/ssr_reproject_shader.d.ts.map +1 -1
  109. package/src/shade/renderer/postprocess/ssr/ssr_reproject_shader.js +16 -113
  110. package/src/shade/renderer/texture/source/texel_data_from_ktx2.d.ts +2 -2
  111. package/src/shade/renderer/texture/source/texel_data_from_ktx2.d.ts.map +1 -1
  112. package/src/shade/renderer/texture/source/texel_data_from_ktx2.js +3 -3
  113. package/src/shade/renderer/particles/shaders/chunk_particle_emitter_warmup.d.ts +0 -20
  114. package/src/shade/renderer/particles/shaders/chunk_particle_emitter_warmup.d.ts.map +0 -1
  115. package/src/shade/renderer/particles/shaders/chunk_particle_emitter_world_sphere.d.ts +0 -14
  116. package/src/shade/renderer/particles/shaders/chunk_particle_emitter_world_sphere.d.ts.map +0 -1
  117. package/src/shade/renderer/particles/shaders/shader_particle_reclaim.d.ts +0 -50
  118. package/src/shade/renderer/particles/shaders/shader_particle_reclaim.d.ts.map +0 -1
  119. package/src/shade/renderer/postprocess/ssr/reproject/shader_ffx_denoiser_reflections_reproject.d.ts +0 -17
  120. package/src/shade/renderer/postprocess/ssr/reproject/shader_ffx_denoiser_reflections_reproject.d.ts.map +0 -1
@@ -0,0 +1,455 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import { float32_array_hash } from "../../../../core/collection/array/typed/float32_array_hash.js";
3
+ import { is_typed_array_equals } from "../../../../core/collection/array/typed/is_typed_array_equals.js";
4
+ import { hash_mix2 } from "../../../../core/math/hash/hash_mix2.js";
5
+ import { hash_mix3 } from "../../../../core/math/hash/hash_mix3.js";
6
+ import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
7
+ import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
8
+ import {
9
+ EMITTER_ATTRIBUTE_ABSENT,
10
+ make_emitter_flags
11
+ } from "../../../../shade/renderer/particles/data/PARTICLE_EMITTER_STRUCT.js";
12
+ import { EMITTER_RENDER_CHANNELS } from "../../../../shade/renderer/particles/runtime/ParticleEmitter.js";
13
+
14
+ /**
15
+ * What an entity emits. Paired with a {@link ../../../ecs/transform/Transform64.js Transform64},
16
+ * which says where, this is the whole of an emitter in the ECS:
17
+ *
18
+ * ```js
19
+ * new Entity()
20
+ * .add(new Transform64())
21
+ * .add(ParticleEffect.from({ ...create_particle_effect({ layout, init, update }), spawn_rate: 400 }))
22
+ * .build(dataset);
23
+ * ```
24
+ *
25
+ * {@link ../../../graphics3/GPUParticleEmitterSystem.js GPUParticleEmitterSystem} is what turns the
26
+ * pair into particles: it gives the entity a
27
+ * {@link ../../../../shade/renderer/particles/runtime/ParticleEmitter.js ParticleEmitter} node in
28
+ * the scene it owns, keeps that node where the transform says, packs {@link texture} into the
29
+ * scene's sprite atlas, and follows every field below. Nothing here reaches a device by itself, and
30
+ * an entity carrying one of these with no such system in the profile simply emits nothing.
31
+ *
32
+ * ## It is a description, and only a description
33
+ *
34
+ * Everything on it means the same thing with no renderer present: the attribute {@link layout} and
35
+ * the compiled {@link program} that make up an effect, the {@link texture} to draw with, the rate,
36
+ * the pre-warm, the blend / projection / feature {@link flags}, the render-attribute bindings and
37
+ * the flipbook grid. That is deliberate, and it is what makes the component the unit an editor
38
+ * inspects, a prefab carries and a system diffs.
39
+ *
40
+ * What is **not** here: the scene node the system built, the emitter's row in the GPU emitter table,
41
+ * the generation of that row, where the program was placed in the program heap, and where the
42
+ * texture landed in the atlas. All of that belongs to whoever registered the emitter — see
43
+ * {@link ../../../../shade/renderer/particles/runtime/GPUParticleEmitterContext.js} — and none of it
44
+ * survives a device restart, which is exactly why it is not on a component that does.
45
+ *
46
+ * There are no bounds here either. An emitter's particles are moved by arbitrary bytecode, so the
47
+ * box is **measured** from the live particles by a GPU pass at the end of every frame rather than
48
+ * authored; the one authored part of it is whether this effect opts into culling at all
49
+ * (`cull` in {@link flags}).
50
+ *
51
+ * ## Sharing
52
+ *
53
+ * {@link layout} and {@link program} are immutable once compiled and are meant to be shared: fifty
54
+ * campfires hold fifty components pointing at one compiled effect, which is what puts them on one id
55
+ * in the program heap and therefore in one simulation bucket. {@link copy} shares them rather than
56
+ * duplicating them for that reason.
57
+ *
58
+ * ## Changing one
59
+ *
60
+ * Assign to the fields. The system compares what it holds against what it last wrote to the scene
61
+ * node, once per frame per entity, so there is no flag to set and no signal to fire — a component
62
+ * whose fields have not moved costs a run of comparisons and no upload. That is a deliberate trade
63
+ * against the observable-per-field shape the older components use: an effect has fifteen fields,
64
+ * gameplay writes them in bursts, and a row is restaged whole either way.
65
+ *
66
+ * ## Saving one
67
+ *
68
+ * {@link ./ParticleEffectSerializationAdapter.js} writes all of it, the compiled program included.
69
+ * The VM's instruction set is a durable format by design — fixed-width opcodes and a constant pool —
70
+ * so a level carries the bytecode the way it carries a mesh's indices, and a shipped build needs
71
+ * neither the graph the effect was compiled from nor a compiler at runtime. Authoring belongs to an
72
+ * editor.
73
+ *
74
+ * Two things are consequently wire format: the opcode numbers, and the **order** of the attributes
75
+ * in {@link layout}, because the offsets in the render bindings are assigned from that order.
76
+ */
77
+ export class ParticleEffect {
78
+
79
+ /**
80
+ * The per-particle attribute schema: which named attributes a particle of this effect has, how
81
+ * wide each is, and what word of the record it sits at.
82
+ *
83
+ * `null` until an effect is assigned. An entity whose component has none is linked and idle
84
+ * rather than an error — an effect that is still compiling or still loading is ordinary — and it
85
+ * starts emitting on the frame after both this and {@link program} are set.
86
+ *
87
+ * @type {import("../../../../shade/renderer/particles/layout/ParticleLayout.js").ParticleLayout|null}
88
+ */
89
+ layout = null;
90
+
91
+ /**
92
+ * The compiled INIT/UPDATE bytecode run for every particle. Replace the immutable program to
93
+ * edit the effect; do not mutate its bytecode in place.
94
+ *
95
+ * @type {import("../../../../shade/renderer/particles/isa/ParticleProgram.js").ParticleProgram|null}
96
+ */
97
+ program = null;
98
+
99
+ /**
100
+ * Image to draw the particles with, by URL, or `null` to draw against a single white texel — so
101
+ * an untextured effect is a flat quad of its own colour.
102
+ *
103
+ * The system loads this through `AssetManager` and packs it into the sprite atlas its scene
104
+ * shares, one patch per distinct URL however many entities name it. Where it lands is the
105
+ * system's answer and changes on every repack, without this component changing.
106
+ *
107
+ * @type {string|null}
108
+ */
109
+ texture = null;
110
+
111
+ /**
112
+ * Base RNG seed.
113
+ *
114
+ * Two entities running one program produce identical particles from identical seeds. `0` reads
115
+ * as "unset", and the emitter then takes its registration's generation instead, which no other
116
+ * live emitter shares — so leaving this alone is what makes fifty campfires burn differently.
117
+ *
118
+ * @type {number}
119
+ */
120
+ seed = 0;
121
+
122
+ /**
123
+ * Continuous emission rate, particles per second. Integrated on the GPU; the CPU never counts
124
+ * particles.
125
+ *
126
+ * @type {number}
127
+ */
128
+ spawn_rate = 0;
129
+
130
+ /**
131
+ * Whether the effect is currently emitting.
132
+ *
133
+ * Turning it off holds {@link spawn_rate} at zero without the caller having to remember what the
134
+ * rate was — which is the whole reason it exists, because "put the torch out and light it again"
135
+ * otherwise means every caller keeping a shadow copy of the number. Particles already alive are
136
+ * **not** killed: a fire that stops emitting burns down, which is what stopping a fire looks
137
+ * like. Kill them from the effect's own UPDATE program if an effect wants to vanish.
138
+ *
139
+ * @type {boolean}
140
+ */
141
+ emitting = true;
142
+
143
+ /**
144
+ * Seconds this effect is run forward before it is first shown, `0` for none.
145
+ *
146
+ * A continuous effect starts empty and grows into its steady state over one particle lifetime,
147
+ * in front of whoever is watching. Setting this to about the effect's particle lifetime means
148
+ * the population on the first visible frame is the one the emitter would have had by then —
149
+ * spawned, aged and thinned by its own program over that long.
150
+ *
151
+ * It is paid once, on the frame the emitter is registered, by a pipeline of its own that
152
+ * simulates a private population and moves the result into the scene. Longer costs a longer loop
153
+ * on that one frame and nothing after it.
154
+ *
155
+ * @type {number}
156
+ */
157
+ prewarm = 0;
158
+
159
+ /**
160
+ * Packed feature / blend / projection bits — see
161
+ * {@link ../../../../shade/renderer/particles/data/PARTICLE_EMITTER_STRUCT.js make_emitter_flags}.
162
+ *
163
+ * @type {number}
164
+ */
165
+ flags = 0;
166
+
167
+ /**
168
+ * Flipbook grid: columns, rows, over whatever region {@link texture} was packed into. `[1, 1]`
169
+ * is a single frame.
170
+ *
171
+ * @type {Float32Array}
172
+ */
173
+ flipbook = new Float32Array([1, 1]);
174
+
175
+ /** @type {number} record word offset of world position, or {@link EMITTER_ATTRIBUTE_ABSENT} */
176
+ render_position = EMITTER_ATTRIBUTE_ABSENT;
177
+ /** @type {number} record word offset of size */
178
+ render_size = EMITTER_ATTRIBUTE_ABSENT;
179
+ /** @type {number} record word offset of rgba colour */
180
+ render_color = EMITTER_ATTRIBUTE_ABSENT;
181
+ /** @type {number} record word offset of roll angle, radians */
182
+ render_rotation = EMITTER_ATTRIBUTE_ABSENT;
183
+ /** @type {number} record word offset of flipbook frame index */
184
+ render_frame = EMITTER_ATTRIBUTE_ABSENT;
185
+ /** @type {number} record word offset of velocity, read by the STRETCHED projection */
186
+ render_velocity = EMITTER_ATTRIBUTE_ABSENT;
187
+
188
+ /**
189
+ * The rate the emitter actually runs at: {@link spawn_rate} while {@link emitting}, and zero
190
+ * otherwise. What the system writes to the GPU record.
191
+ *
192
+ * @returns {number}
193
+ */
194
+ get effective_spawn_rate() {
195
+ return this.emitting ? this.spawn_rate : 0;
196
+ }
197
+
198
+ /**
199
+ * Bind render channels to per-particle attributes of this effect, by attribute name.
200
+ *
201
+ * Channels left out of `channels` keep whatever they had; a channel that was never bound stays
202
+ * at {@link EMITTER_ATTRIBUTE_ABSENT}, which the passes read as "this effect has no such
203
+ * attribute" — the render pass substitutes a default and the sort pass treats the particle as
204
+ * being at the origin.
205
+ *
206
+ * Word offsets are stored rather than names because that is what the render and sort passes
207
+ * index a particle record with; resolving here is the only place a name is involved, which is
208
+ * also why this needs {@link layout} to have been set first.
209
+ *
210
+ * @param {Object<string,string>} channels channel name (see `EMITTER_RENDER_CHANNELS`) ->
211
+ * attribute name in this effect's layout
212
+ * @returns {ParticleEffect} this
213
+ */
214
+ bind_render(channels) {
215
+ assert.isObject(channels, 'channels');
216
+ assert.notEqual(this.layout, null, 'layout must be set before render channels are bound');
217
+ assert.defined(this.layout, 'this.layout');
218
+
219
+ const layout = this.layout;
220
+
221
+ for (const channel of Object.keys(channels)) {
222
+ const offset = layout.offsetOf(channels[channel]);
223
+
224
+ switch (channel) {
225
+ case "position":
226
+ this.render_position = offset;
227
+ break;
228
+ case "size":
229
+ this.render_size = offset;
230
+ break;
231
+ case "color":
232
+ this.render_color = offset;
233
+ break;
234
+ case "rotation":
235
+ this.render_rotation = offset;
236
+ break;
237
+ case "frame":
238
+ this.render_frame = offset;
239
+ break;
240
+ case "velocity":
241
+ this.render_velocity = offset;
242
+ break;
243
+ default:
244
+ throw new Error(
245
+ `Unknown render channel '${channel}', expected one of ${EMITTER_RENDER_CHANNELS.join(', ')}`
246
+ );
247
+ }
248
+ }
249
+
250
+ return this;
251
+ }
252
+
253
+ /**
254
+ * Structural equality over everything the component *is*. Two components that compare equal
255
+ * describe one effect, and one emitter row would serve both.
256
+ *
257
+ * The compiled program compares by its own bytecode rather than by object identity, so two
258
+ * components separately compiled from one graph compare equal.
259
+ *
260
+ * @param {ParticleEffect} other
261
+ * @returns {boolean}
262
+ */
263
+ equals(other) {
264
+ if (this === other) {
265
+ return true;
266
+ }
267
+
268
+ return this.texture === other.texture
269
+ && this.seed === other.seed
270
+ && this.spawn_rate === other.spawn_rate
271
+ && this.emitting === other.emitting
272
+ && this.prewarm === other.prewarm
273
+ && this.flags === other.flags
274
+ && this.render_position === other.render_position
275
+ && this.render_size === other.render_size
276
+ && this.render_color === other.render_color
277
+ && this.render_rotation === other.render_rotation
278
+ && this.render_frame === other.render_frame
279
+ && this.render_velocity === other.render_velocity
280
+ && is_typed_array_equals(this.flipbook, other.flipbook)
281
+ && optional_equals(this.layout, other.layout)
282
+ && optional_equals(this.program, other.program);
283
+ }
284
+
285
+ /**
286
+ * Hash over everything {@link equals} compares, in the same terms.
287
+ *
288
+ * @returns {number} int32
289
+ */
290
+ hash() {
291
+ const bindings = hash_mix3(
292
+ hash_mix3(this.render_position, this.render_size, this.render_color),
293
+ hash_mix3(this.render_rotation, this.render_frame, this.render_velocity),
294
+ this.flags
295
+ );
296
+
297
+ const appearance = hash_mix3(
298
+ computeStringHash(this.texture),
299
+ hash_mix3(this.seed, computeHashFloat(this.spawn_rate), computeHashFloat(this.prewarm)),
300
+ this.emitting ? 1 : 0
301
+ );
302
+
303
+ return hash_mix3(
304
+ hash_mix2(bindings, float32_array_hash(this.flipbook, 0, this.flipbook.length)),
305
+ appearance,
306
+ hash_mix2(
307
+ this.layout === null ? 0 : this.layout.hash(),
308
+ this.program === null ? 0 : this.program.hash()
309
+ )
310
+ );
311
+ }
312
+
313
+ /**
314
+ * Make this a copy of `other`: same effect, same settings.
315
+ *
316
+ * The layout and the compiled program are **shared** rather than duplicated — both are immutable
317
+ * once compiled, and sharing them is what puts two entities of one effect on one program id in
318
+ * the heap, hence in one simulation bucket.
319
+ *
320
+ * @param {ParticleEffect} other
321
+ * @returns {ParticleEffect} this
322
+ */
323
+ copy(other) {
324
+ this.layout = other.layout;
325
+ this.program = other.program;
326
+ this.texture = other.texture;
327
+
328
+ this.seed = other.seed;
329
+ this.spawn_rate = other.spawn_rate;
330
+ this.emitting = other.emitting;
331
+ this.prewarm = other.prewarm;
332
+ this.flags = other.flags;
333
+
334
+ this.flipbook.set(other.flipbook);
335
+
336
+ this.render_position = other.render_position;
337
+ this.render_size = other.render_size;
338
+ this.render_color = other.render_color;
339
+ this.render_rotation = other.render_rotation;
340
+ this.render_frame = other.render_frame;
341
+ this.render_velocity = other.render_velocity;
342
+
343
+ return this;
344
+ }
345
+
346
+ /**
347
+ * @returns {ParticleEffect}
348
+ */
349
+ clone() {
350
+ return new ParticleEffect().copy(this);
351
+ }
352
+
353
+ /**
354
+ * Build a component from a plain description. Every field is optional — a component with no
355
+ * effect is a placeholder waiting for one — so an effect goes in by spreading what
356
+ * {@link ../../../../shade/renderer/particles/runtime/create_particle_effect.js create_particle_effect}
357
+ * returns: `ParticleEffect.from({ ...effect, spawn_rate: 100 })`.
358
+ *
359
+ * @param {object} [config]
360
+ * @param {import("../../../../shade/renderer/particles/layout/ParticleLayout.js").ParticleLayout} [config.layout]
361
+ * @param {import("../../../../shade/renderer/particles/isa/ParticleProgram.js").ParticleProgram} [config.program]
362
+ * @param {string|null} [config.texture] image URL to draw with
363
+ * @param {number} [config.seed]
364
+ * @param {number} [config.spawn_rate] particles/second
365
+ * @param {boolean} [config.emitting]
366
+ * @param {number} [config.prewarm] seconds of emission to run forward before the first frame
367
+ * @param {object} [config.flags] passed to `make_emitter_flags`
368
+ * @param {Object<string,string>} [config.render] render channel -> attribute name
369
+ * @param {ArrayLike<number>} [config.flipbook] `[columns, rows]`
370
+ * @returns {ParticleEffect}
371
+ */
372
+ static from(config = {}) {
373
+ assert.isObject(config, 'config');
374
+
375
+ const effect = new ParticleEffect();
376
+
377
+ if (config.layout !== undefined) {
378
+ effect.layout = config.layout;
379
+ }
380
+
381
+ if (config.program !== undefined) {
382
+ effect.program = config.program;
383
+ }
384
+
385
+ if (config.texture !== undefined) {
386
+ effect.texture = config.texture;
387
+ }
388
+
389
+ if (config.seed !== undefined) {
390
+ effect.seed = config.seed;
391
+ }
392
+
393
+ if (config.spawn_rate !== undefined) {
394
+ effect.spawn_rate = config.spawn_rate;
395
+ }
396
+
397
+ if (config.emitting !== undefined) {
398
+ effect.emitting = config.emitting;
399
+ }
400
+
401
+ if (config.prewarm !== undefined) {
402
+ effect.prewarm = config.prewarm;
403
+ }
404
+
405
+ effect.flags = make_emitter_flags(config.flags ?? {});
406
+
407
+ if (config.flipbook !== undefined) {
408
+ effect.flipbook.set(config.flipbook);
409
+ }
410
+
411
+ if (config.render !== undefined) {
412
+ effect.bind_render(config.render);
413
+ }
414
+
415
+ return effect;
416
+ }
417
+ }
418
+
419
+ /**
420
+ * Compare two things that are either both absent or both know how to compare themselves.
421
+ *
422
+ * A component with no effect is an ordinary state — it is what an entity has while its effect is
423
+ * still being compiled — so `null` has to be a value here rather than a precondition.
424
+ *
425
+ * @param {{equals: function(*): boolean}|null} a
426
+ * @param {{equals: function(*): boolean}|null} b
427
+ * @returns {boolean}
428
+ */
429
+ function optional_equals(a, b) {
430
+ if (a === null || b === null) {
431
+ return a === b;
432
+ }
433
+
434
+ return a.equals(b);
435
+ }
436
+
437
+ /**
438
+ * The name this component is written under, and looked up by when a save is read. A serialization
439
+ * registry infers nothing from a class — see
440
+ * {@link ../../../ecs/storage/binary/BinarySerializationRegistry.js} — so this is what makes
441
+ * {@link ./ParticleEffectSerializationAdapter.js} reachable, and it is wire format: renaming the
442
+ * class is free, renaming this is a save-format break.
443
+ *
444
+ * @readonly
445
+ * @type {string}
446
+ */
447
+ ParticleEffect.typeName = "ParticleEffect";
448
+
449
+ /**
450
+ * Enables a fast type check, without having to import the class separately.
451
+ *
452
+ * @readonly
453
+ * @type {boolean}
454
+ */
455
+ ParticleEffect.prototype.isParticleEffect = true;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Binary serialization for {@link ParticleEffect}.
3
+ *
4
+ * **The compiled effect is written, not a reference to one.** The VM's instruction set was designed
5
+ * to be a durable format — a fixed-width opcode encoding with a constant pool beside it — so a
6
+ * compiled program is content in exactly the way a mesh's index buffer is content, and a level that
7
+ * carries one needs neither the graph it came from nor a compiler at runtime. Authoring is an
8
+ * editor's job; a shipped build opens a save, reads instruction words, and runs them.
9
+ *
10
+ * That is also what makes the format's stability a real obligation. Two things here are wire format
11
+ * and cannot be renumbered without a version bump and an upgrader:
12
+ *
13
+ * - **opcodes**, whose numbers are `../../../../shade/renderer/particles/isa/ParticleVMISA.js`, and
14
+ * - **attribute order in the layout**, because a layout assigns word offsets sequentially from the
15
+ * order it is built in, and the render bindings below are those offsets. Offsets are therefore not
16
+ * written: they are recomputed on load from the same order, and a change to how
17
+ * {@link ParticleLayout} packs would silently repoint every binding in every save.
18
+ *
19
+ * ## The constant pool is written as bits
20
+ *
21
+ * The pool holds constants, not measurements, and two of them can be the same number: `-0` and `+0`
22
+ * are distinct pool words because a `DIV` by each disagrees about the sign of the infinity it
23
+ * produces, and the assembler interns with `Object.is` to keep them apart. `ParticleProgram` compares
24
+ * and hashes the pool through its bit view (`constant_words`) for exactly that reason.
25
+ *
26
+ * So does this. Not because a float path is known to lose something — measured on V8 it does not,
27
+ * `-0` survives `setFloat32` and so does a NaN's payload — but because whether a NaN survives a
28
+ * round trip through a JS `number` is **implementation-defined**: the language permits an engine to
29
+ * canonicalize, and the one this runs on is not the only one it will ever run on. Writing the words
30
+ * the program is already compared by makes the reload exact by construction rather than by an
31
+ * engine's discretion, and it means there is one representation of the pool rather than two.
32
+ *
33
+ * ## Nothing device-shaped is written
34
+ *
35
+ * There is nothing here that a device assigned: no table row, no generation, no program-heap
36
+ * placement, no atlas patch. Those belong to the registry that registered the emitter and are
37
+ * rebuilt on load like every other GPU resource. What is written is what an author typed.
38
+ *
39
+ * @author Alex Goldring
40
+ * @copyright Company Named Limited (c) 2026
41
+ */
42
+ export class ParticleEffectSerializationAdapter extends BinaryClassSerializationAdapter<any> {
43
+ constructor();
44
+ klass: typeof ParticleEffect;
45
+ /**
46
+ * @param {BinaryBuffer} buffer
47
+ * @param {ParticleEffect} value
48
+ */
49
+ serialize(buffer: BinaryBuffer, value: ParticleEffect): void;
50
+ /**
51
+ * @param {BinaryBuffer} buffer
52
+ * @param {ParticleEffect} value
53
+ */
54
+ deserialize(buffer: BinaryBuffer, value: ParticleEffect): void;
55
+ }
56
+ import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
57
+ import { ParticleEffect } from "./ParticleEffect.js";
58
+ //# sourceMappingURL=ParticleEffectSerializationAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParticleEffectSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/particles/ParticleEffectSerializationAdapter.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH;;IAEI,6BAAuB;IAGvB;;;OAGG;IACH,uCAFW,cAAc,QAmCxB;IAED;;;OAGG;IACH,yCAFW,cAAc,QA8BxB;CACJ;gDAzH+C,gEAAgE;+BACjF,qBAAqB"}