babylon.quarks 0.26.0 → 0.28.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 (83) hide show
  1. package/CHANGELOG.md +1194 -8
  2. package/README.md +13 -9
  3. package/dist/babylon.quarks.cjs +1 -1
  4. package/dist/babylon.quarks.cjs.map +1 -1
  5. package/dist/babylon.quarks.esm.js +1 -1
  6. package/dist/babylon.quarks.esm.js.map +1 -1
  7. package/dist/babylon.quarks.umd.min.js +1 -1
  8. package/dist/babylon.quarks.umd.min.js.map +1 -1
  9. package/dist/types/index.d.cts +10108 -0
  10. package/dist/types/index.d.ts +5794 -998
  11. package/package.json +18 -7
  12. package/src/BatchedRenderer.ts +274 -156
  13. package/src/EffectPool.ts +94 -12
  14. package/src/MeshSurfaceEmitter.ts +50 -14
  15. package/src/ParticleEmitter.ts +75 -17
  16. package/src/ParticleSystem.ts +981 -2066
  17. package/src/QuarksLoader.ts +666 -194
  18. package/src/QuarksPrefab.ts +367 -73
  19. package/src/QuarksSerializer.ts +512 -0
  20. package/src/QuarksUtil.ts +77 -7
  21. package/src/SpriteBatch.ts +127 -252
  22. package/src/TrailBatch.ts +545 -348
  23. package/src/VFXBatch.ts +238 -596
  24. package/src/batchKey.ts +239 -0
  25. package/src/batchSettings.ts +546 -0
  26. package/src/effectDocumentJSON.ts +261 -0
  27. package/src/effectResources.ts +76 -0
  28. package/src/envAtlas.ts +126 -18
  29. package/src/geometryUtil.ts +1 -1
  30. package/src/index.ts +69 -35
  31. package/src/nodeId.ts +36 -0
  32. package/src/shaderProgram.ts +419 -0
  33. package/src/shaderVariants.ts +245 -0
  34. package/src/shaders/chunks/blend.ts +31 -0
  35. package/src/shaders/chunks/fog.ts +12 -5
  36. package/src/shaders/chunks/sheet.ts +111 -0
  37. package/src/shaders/chunks/soft.ts +85 -0
  38. package/src/shaders/chunks/surface.ts +12 -2
  39. package/src/shaders/local_particle_physics_vert.glsl.ts +14 -28
  40. package/src/shaders/local_particle_physics_vert.wgsl.ts +16 -29
  41. package/src/shaders/particle_frag.glsl.ts +5 -22
  42. package/src/shaders/particle_frag.wgsl.ts +5 -23
  43. package/src/shaders/particle_physics_frag.glsl.ts +16 -26
  44. package/src/shaders/particle_physics_frag.wgsl.ts +14 -26
  45. package/src/shaders/particle_vert.glsl.ts +5 -27
  46. package/src/shaders/particle_vert.wgsl.ts +5 -26
  47. package/src/shaders/stretched_bb_particle_vert.glsl.ts +7 -33
  48. package/src/shaders/stretched_bb_particle_vert.wgsl.ts +7 -33
  49. package/src/shaders/trail_frag.glsl.ts +13 -0
  50. package/src/shaders/trail_frag.wgsl.ts +13 -0
  51. package/src/shaders/trail_vert.glsl.ts +45 -36
  52. package/src/shaders/trail_vert.wgsl.ts +46 -40
  53. package/src/softDepth.ts +136 -0
  54. package/src/system/BehaviorPlan.ts +85 -0
  55. package/src/system/BoundsTracker.ts +181 -0
  56. package/src/system/EmissionController.ts +358 -0
  57. package/src/system/EventDispatcher.ts +60 -0
  58. package/src/system/ParticleSpawner.ts +274 -0
  59. package/src/system/SimulationClock.ts +130 -0
  60. package/src/system/geometry.ts +104 -0
  61. package/src/system/integrate.ts +428 -0
  62. package/src/system/materialResolve.ts +165 -0
  63. package/src/system/normalize.ts +100 -0
  64. package/src/system/serialization.ts +422 -0
  65. package/src/system/settingsSchema.ts +339 -0
  66. package/src/system/types.ts +449 -0
  67. package/src/textureSource.ts +30 -0
  68. package/src/trailSettings.ts +54 -0
  69. package/src/BatchedParticleRenderer.ts +0 -3
  70. package/src/materials/ParticleMaterials.ts +0 -23
  71. package/src/materials/index.ts +0 -1
  72. package/src/shaders/chunks/index.ts +0 -1
  73. package/src/shaders/chunks/register-shader-chunks.ts +0 -32
  74. package/src/shaders/chunks/soft_fragment.glsl.ts +0 -13
  75. package/src/shaders/chunks/soft_pars_fragment.glsl.ts +0 -20
  76. package/src/shaders/chunks/soft_pars_vertex.glsl.ts +0 -6
  77. package/src/shaders/chunks/soft_vertex.glsl.ts +0 -6
  78. package/src/shaders/chunks/tile_fragment.glsl.ts +0 -9
  79. package/src/shaders/chunks/tile_pars_fragment.glsl.ts +0 -9
  80. package/src/shaders/chunks/tile_pars_vertex.glsl.ts +0 -28
  81. package/src/shaders/chunks/tile_vertex.glsl.ts +0 -18
  82. package/src/shaders/index.ts +0 -9
  83. package/src/shaders/local_particle_vert.glsl.ts +0 -50
@@ -0,0 +1,449 @@
1
+ import type {BaseTexture} from '@babylonjs/core/Materials/Textures/baseTexture';
2
+ import type {Texture} from '@babylonjs/core/Materials/Textures/texture';
3
+ import type {Scene} from '@babylonjs/core/scene';
4
+ import type {
5
+ Behavior,
6
+ BehaviorJSON,
7
+ ColorGenerator,
8
+ ColorGeneratorJSON,
9
+ EmitterShape,
10
+ FunctionColorGenerator,
11
+ FunctionValueGenerator,
12
+ RendererEmitterSettings,
13
+ RotationGenerator,
14
+ RotationGeneratorJSON,
15
+ ShapeJSON,
16
+ StretchedBillBoardSettings,
17
+ ValueGenerator,
18
+ ValueGeneratorJSON,
19
+ Vector2,
20
+ Vector3,
21
+ Vector3ArrayJSON,
22
+ Vector3Generator,
23
+ Vector3GeneratorJSON,
24
+ Vector3JSON,
25
+ } from 'quarks.core';
26
+ import type {
27
+ MeshLighting,
28
+ MeshRim,
29
+ ParticleErosionOptions,
30
+ ParticleGradientMap,
31
+ ParticleUVDistortionOptions,
32
+ RenderFace,
33
+ RenderMode,
34
+ SortMode,
35
+ TextureUV,
36
+ } from '../VFXBatch';
37
+ import type {GeometryEntry, QuarksMaterialJSON} from '../effectDocumentJSON';
38
+ import type {TrailOptions} from '../trailSettings';
39
+ import type {ParticleMaterialSource} from './materialResolve';
40
+
41
+ /** A trail's settings in JSON, each only when not its default: the start length as a generator's JSON, the side axis as `[x, y, z]`. */
42
+ export type TrailSettingsJSON = Partial<TrailOptions> & {
43
+ /** See `TrailSettings.startLength`. */
44
+ startLength?: ValueGeneratorJSON;
45
+ /** See `TrailSettings.sideAxis`; files may hold it as `{x, y, z}`. */
46
+ sideAxis?: Vector3ArrayJSON | Vector3JSON;
47
+ };
48
+
49
+ /**
50
+ * A render mode's own settings in JSON, see {@link RendererEmitterSettings}: a trail's or a
51
+ * stretched billboard's. The other render modes have none, and their systems leave the field out.
52
+ */
53
+ export type RendererEmitterSettingsJSON = TrailSettingsJSON | StretchedBillBoardSettings;
54
+
55
+ /**
56
+ * One burst of a system's emission (Unity's Emission Bursts): `count` particles at `time` seconds
57
+ * into each loop, repeated `cycle` times `interval` seconds apart, each wave with the chance
58
+ * `probability`. A burst given to the constructor or read from a file is normalised (a missing
59
+ * `interval` is 0.1 s, `probability` is kept to 0..1, `cycle` to at least 1) and the bursts are
60
+ * kept in time order.
61
+ */
62
+ export interface BurstParameters {
63
+ /** Seconds into the system's duration the first wave fires at. */
64
+ time: number;
65
+ /**
66
+ * Particles each wave spawns. The generator is rolled when the system plays or restarts, so
67
+ * a random count is the same for every loop of one play; a curve is read at the wave's time
68
+ * as a fraction of the duration, 0 to 1, like the start curves.
69
+ */
70
+ count: ValueGenerator | FunctionValueGenerator;
71
+ /** How many waves the burst fires, at least 1. */
72
+ cycle: number;
73
+ /** Seconds between waves; 0 fires them all at once. 0.1 when left out. */
74
+ interval: number;
75
+ /** Chance from 0 to 1 that a wave spawns at all, rolled per wave. */
76
+ probability: number;
77
+ }
78
+
79
+ /**
80
+ * What a system does while no camera can see its particles (Unity's Culling
81
+ * Mode). The {@link BatchedRenderer} tests each system's bounds against the
82
+ * active cameras' frusta every frame.
83
+ *
84
+ * - `'always'` keeps simulating off screen, so an effect is exactly where it
85
+ * would have been when it comes back into view. The default, and the only
86
+ * safe choice for an emitter whose particles reach the screen from off it.
87
+ * - `'pause'` freezes the system off screen and resumes it where it left off.
88
+ * - `'pauseAndCatchUp'` freezes it too, then runs the missed time (up to a few
89
+ * seconds) within the renderer's catch-up budget when it is seen again.
90
+ *
91
+ * An empty system is never culled, so it can start emitting and grow the
92
+ * bounds that decide its visibility. A system another one emits into is never
93
+ * culled either; its parent decides.
94
+ *
95
+ * The cameras tested are the scene's active cameras (`scene.activeCameras`, or
96
+ * `scene.activeCamera`), each only for the systems on a layer it renders
97
+ * (`camera.layerMask & system.layers.mask`). A camera that renders into a
98
+ * render target texture (a mirror, a minimap, a portal) is not one of them: a
99
+ * system seen only through one should keep `'always'`.
100
+ */
101
+ export type CullingMode = 'always' | 'pause' | 'pauseAndCatchUp';
102
+
103
+ /**
104
+ * What the emitter's world scale does to a world-space system (Unity's
105
+ * Scaling Mode, as far as it differs here). A local-space system lives in its
106
+ * emitter's space, so its scale reaches everything either way.
107
+ *
108
+ * - `'shape'` (default): the scale sizes the emission shape and the
109
+ * particles; speeds, forces and speed limits stay in world units, so a
110
+ * scaled-down effect moves as far as the full-size one.
111
+ * - `'hierarchy'`: the scale also multiplies start speeds (per axis),
112
+ * `ForceOverLife` and `LimitSpeedOverLife` (by the mean of the axes), so the
113
+ * whole effect, motion included, scales like a model would.
114
+ */
115
+ export type ScalingMode = 'shape' | 'hierarchy';
116
+
117
+ /**
118
+ * Where a {@link RenderMode.Beam} system's quads end: a point in world space,
119
+ * or anything with a world position, such as a Babylon `TransformNode`, read
120
+ * every frame.
121
+ */
122
+ export type BeamEnd =
123
+ | {
124
+ /** World x. */
125
+ x: number;
126
+ /** World y. */
127
+ y: number;
128
+ /** World z. */
129
+ z: number;
130
+ }
131
+ | {
132
+ /** The world position, read every frame. */
133
+ getAbsolutePosition(): {
134
+ /** World x. */
135
+ x: number;
136
+ /** World y. */
137
+ y: number;
138
+ /** World z. */
139
+ z: number;
140
+ };
141
+ };
142
+
143
+ /**
144
+ * Settings for a new {@link ParticleSystem}. Every one is optional: a setting left out takes the
145
+ * default named on it, the same default `fromJSON` gives a file that leaves it out.
146
+ */
147
+ export interface ParticleSystemParameters {
148
+ /** See {@link ParticleSystem.autoDestroy}. Default false. */
149
+ autoDestroy?: boolean;
150
+ /** See {@link ParticleSystem.looping}. Default true. */
151
+ looping?: boolean;
152
+ /** See {@link ParticleSystem.prewarm}. Default false. */
153
+ prewarm?: boolean;
154
+ /** See {@link ParticleSystem.prewarmTime}. Default 0: a whole cycle; only with `prewarm` on a looping system. */
155
+ prewarmTime?: number;
156
+ /** See {@link ParticleSystem.duration}. Default 1 second. */
157
+ duration?: number;
158
+ /** See {@link ParticleSystem.startDelay}. Default 0. */
159
+ startDelay?: ValueGenerator | FunctionValueGenerator;
160
+ /** Where particles are born and which way they start, see {@link ParticleSystem.emitterShape}. Default a `SphereEmitter`. */
161
+ shape?: EmitterShape;
162
+ /** See {@link ParticleSystem.startLife}. Default 5 seconds. */
163
+ startLife?: ValueGenerator | FunctionValueGenerator;
164
+ /** See {@link ParticleSystem.startSpeed}. Default 0. */
165
+ startSpeed?: ValueGenerator | FunctionValueGenerator;
166
+ /** See {@link ParticleSystem.startRotation}. Default 0. */
167
+ startRotation?: ValueGenerator | FunctionValueGenerator | RotationGenerator;
168
+ /** See {@link ParticleSystem.startSize}. Default 1. */
169
+ startSize?: ValueGenerator | FunctionValueGenerator | Vector3Generator;
170
+ /** See {@link ParticleSystem.startColor}. Default opaque white. */
171
+ startColor?: ColorGenerator | FunctionColorGenerator;
172
+ /** See {@link ParticleSystem.emissionOverTime}. Default 10 per second. */
173
+ emissionOverTime?: ValueGenerator | FunctionValueGenerator;
174
+ /** See {@link ParticleSystem.emissionOverDistance}. Default 0. */
175
+ emissionOverDistance?: ValueGenerator | FunctionValueGenerator;
176
+ /** See {@link ParticleSystem.emissionBursts}. Default none. */
177
+ emissionBursts?: Array<BurstParameters>;
178
+ /** Most particles alive at once; emission past it is dropped. Leave unset for no limit. */
179
+ maxParticles?: number;
180
+ /** See {@link ParticleSystem.onlyUsedByOther}. Default false. */
181
+ onlyUsedByOther?: boolean;
182
+ /** See {@link ParticleSystem.behaviors}. Default none. */
183
+ behaviors?: Array<Behavior>;
184
+ /** Mesh particles' vertex positions, three values per vertex. Default a unit quad in XY. */
185
+ instancingGeometry?: Float32Array;
186
+ /** Triangle indices into {@link instancingGeometry}. Default the unit quad's two triangles. */
187
+ instancingIndices?: Uint32Array | Uint16Array;
188
+ /** Mesh particles' first UV set, two values per vertex. Default the quad's UVs, or zeros for another geometry. */
189
+ instancingUVs?: Float32Array;
190
+ /**
191
+ * A second UV set for the mesh (glTF `TEXCOORD_1`, Unity's `uv2`), what
192
+ * textures on UV channel 1 read on a mesh particle; see `UVChannel`.
193
+ * Default none: channel 1 reads the first set.
194
+ */
195
+ instancingUVs2?: Float32Array;
196
+ /** Mesh particles' vertex normals, three values per vertex. Default +Z for every vertex. */
197
+ instancingNormals?: Float32Array;
198
+ /** See {@link ParticleSystem.renderMode}. Default `RenderMode.BillBoard`. */
199
+ renderMode?: RenderMode;
200
+ /** See {@link ParticleSystem.rendererEmitterSettings}. Default the render mode's own. */
201
+ rendererEmitterSettings?: RendererEmitterSettings;
202
+ /** @deprecated Set `speedFactor` in {@link rendererEmitterSettings} instead; this one wins when both are set. */
203
+ speedFactor?: number;
204
+ /** See {@link ParticleSystem.material}. Default none. */
205
+ material?: ParticleMaterialSource | null;
206
+ /** See {@link ParticleSystem.texture}. Unset takes the material's texture; null draws without one. */
207
+ texture?: Texture | null;
208
+ /** See {@link ParticleSystem.startTileIndex}. Default 0. */
209
+ startTileIndex?: ValueGenerator;
210
+ /** See {@link ParticleSystem.uTileCount}. Default 1. */
211
+ uTileCount?: number;
212
+ /** See {@link ParticleSystem.vTileCount}. Default 1. */
213
+ vTileCount?: number;
214
+ /** See {@link ParticleSystem.blendTiles}. Default false. */
215
+ blendTiles?: boolean;
216
+ /**
217
+ * Fade particles out as they near the scene behind them, like Unity's Soft Particles and
218
+ * Unreal's Depth Fade, between `softNearFade` and `softFarFade` world units. Needs a depth
219
+ * texture, see `BatchedRenderer.setDepthTexture`; without one particles draw hard. Applies to
220
+ * every render mode: billboard, stretched, mesh, beam and trail.
221
+ */
222
+ softParticles?: boolean;
223
+ /** See {@link ParticleSystem.softFarFade}. Default 1. */
224
+ softFarFade?: number;
225
+ /** See {@link ParticleSystem.softNearFade}. Default 0. */
226
+ softNearFade?: number;
227
+ /** See {@link ParticleSystem.renderOrder}. Default 0. */
228
+ renderOrder?: number;
229
+ /** See {@link ParticleSystem.worldSpace}. Default false. */
230
+ worldSpace?: boolean;
231
+ /** Babylon alpha mode the batch blends with, see {@link ParticleSystem.blending}. Default `Constants.ALPHA_ADD`. */
232
+ blendMode?: number;
233
+ /** Whether the batch draws in the transparent pass. Default true. */
234
+ transparent?: boolean;
235
+ /**
236
+ * Whether particles are hidden behind nearer geometry. `false` draws them over everything
237
+ * (Unity's `ZTest Always`), in every render mode. Default `true`.
238
+ */
239
+ depthTest?: boolean;
240
+ /** Whether the particles write depth. Default false. */
241
+ depthWrite?: boolean;
242
+ /** Alpha below which a fragment is discarded, 0 to 1. Default 0: nothing is. */
243
+ alphaTest?: number;
244
+ /** Camera layer mask the batch draws for, see {@link ParticleSystem.layers}. Default `0x0fffffff`. */
245
+ layerMask?: number;
246
+ /** Billboard pivot in particle-size units, see {@link VFXBatchSettings.pivot}. */
247
+ pivot?: Vector3;
248
+ /** Fraction of billboard particles mirrored along U (x) and V (y), see {@link ParticleSystem.flip}. */
249
+ flip?: Vector2;
250
+ /** How mesh particles are lit, see {@link ParticleSystem.lighting}. Default `'fixed'`. */
251
+ lighting?: MeshLighting;
252
+ /** Rim (Fresnel) term on mesh particles, see {@link ParticleSystem.rim}. Default none. */
253
+ rim?: Partial<MeshRim>;
254
+ /** The main map's layout, see {@link ParticleSystem.mapUV}. Default as drawn. */
255
+ mapUV?: Partial<TextureUV>;
256
+ /** Colour ramp for the map, see {@link ParticleSystem.gradientMap}. Default none. */
257
+ gradientMap?: Partial<ParticleGradientMap>;
258
+ /** Alpha erosion, see {@link ParticleSystem.erosion}. Default none. */
259
+ erosion?: ParticleErosionOptions;
260
+ /** Map UV distortion, see {@link ParticleSystem.uvDistortion}. Default none. */
261
+ uvDistortion?: ParticleUVDistortionOptions;
262
+ /** Multiplier on the time the system is advanced by, see {@link ParticleSystem.playbackSpeed}. Default 1. */
263
+ playbackSpeed?: number;
264
+ /** What the system does while off screen, see {@link CullingMode}. Default `'always'`. */
265
+ cullingMode?: CullingMode;
266
+ /** What the emitter's scale does to a world-space system, see {@link ScalingMode}. Default `'shape'`. */
267
+ scalingMode?: ScalingMode;
268
+ /** Seed for this system's own random generator, see {@link ParticleSystem.seed}. Default none. */
269
+ seed?: number;
270
+ /** Draw order within the batch, see {@link ParticleSystem.sortMode}. Default `'none'`. */
271
+ sortMode?: SortMode;
272
+ /** Which faces a mesh particle draws, see {@link ParticleSystem.renderFace}. Default `'both'`. */
273
+ renderFace?: RenderFace;
274
+ /** Whether particles start turned along their direction of travel, see {@link ParticleSystem.alignToDirection}. Default false. */
275
+ alignToDirection?: boolean;
276
+ /** Smallest on-screen size, as a fraction of the viewport height, see {@link ParticleSystem.minParticleSize}. Default 0. */
277
+ minParticleSize?: number;
278
+ /** Largest on-screen size, as a fraction of the viewport height, see {@link ParticleSystem.maxParticleSize}. Default unlimited. */
279
+ maxParticleSize?: number;
280
+ /** Babylon rendering group of the batch, see {@link ParticleSystem.renderingGroupId}. Default 0. */
281
+ renderingGroupId?: number;
282
+ /** Whether the scene's fog applies, see {@link ParticleSystem.applyFog}. Default true. */
283
+ applyFog?: boolean;
284
+ /** Scene the emitter node is created in. Default Babylon's last created scene. */
285
+ scene?: Scene;
286
+ }
287
+
288
+ /** A {@link BurstParameters} in an effect file. A plain number `count` is read as a constant. */
289
+ export interface BurstParametersJSON {
290
+ /** See {@link BurstParameters.time}. */
291
+ time: number;
292
+ /** See {@link BurstParameters.count}. */
293
+ count: ValueGeneratorJSON | number;
294
+ /** See {@link BurstParameters.cycle}. */
295
+ cycle: number;
296
+ /** See {@link BurstParameters.interval}. */
297
+ interval: number;
298
+ /** See {@link BurstParameters.probability}. */
299
+ probability: number;
300
+ /** `cycle`, as files before it was named wrote it; read when there is no `cycle`. */
301
+ cycleCount?: number;
302
+ }
303
+
304
+ /**
305
+ * A particle system in an effect file, as {@link ParticleSystem.toJSON} writes it and
306
+ * {@link ParticleSystem.fromJSON} reads it; `docs/FORMAT.md` describes the document around it.
307
+ * Each field mirrors the {@link ParticleSystem} member of the same name. Curves and generators
308
+ * are written as quarks.core's `FunctionJSON`; textures, materials and geometries as uuids into
309
+ * the document. Most settings are written only when they differ from their default, and a field
310
+ * that is missing reads as the default, so every field but `version` is optional. The shape, the
311
+ * start and emission curves except `startDelay`, `startTileIndex`, `instancingGeometry`, `material`
312
+ * and `behaviors` are always written, because older loaders and three.quarks need them.
313
+ */
314
+ export interface ParticleSystemJSONParameters {
315
+ /** The quarks.core version line the system was written with. */
316
+ version: string;
317
+ /** See {@link ParticleSystem.autoDestroy}. */
318
+ autoDestroy?: boolean;
319
+ /** See {@link ParticleSystem.looping}. */
320
+ looping?: boolean;
321
+ /** See {@link ParticleSystem.prewarm}. */
322
+ prewarm?: boolean;
323
+ /** See {@link ParticleSystem.prewarmTime}. */
324
+ prewarmTime?: number;
325
+ /** See {@link ParticleSystem.duration}. */
326
+ duration?: number;
327
+ /** See {@link ParticleSystem.startDelay}. */
328
+ startDelay?: ValueGeneratorJSON;
329
+ /** The emitter shape, as its `toJSON` writes it. */
330
+ shape?: ShapeJSON;
331
+ /** See {@link ParticleSystem.startLife}. */
332
+ startLife?: ValueGeneratorJSON;
333
+ /** See {@link ParticleSystem.startSpeed}. */
334
+ startSpeed?: ValueGeneratorJSON;
335
+ /** See {@link ParticleSystem.startRotation}. */
336
+ startRotation?: ValueGeneratorJSON | RotationGeneratorJSON;
337
+ /** See {@link ParticleSystem.startSize}. */
338
+ startSize?: ValueGeneratorJSON | Vector3GeneratorJSON;
339
+ /** See {@link ParticleSystem.startColor}. */
340
+ startColor?: ColorGeneratorJSON;
341
+ /** See {@link ParticleSystem.emissionOverTime}. */
342
+ emissionOverTime?: ValueGeneratorJSON;
343
+ /** See {@link ParticleSystem.emissionOverDistance}. */
344
+ emissionOverDistance?: ValueGeneratorJSON;
345
+ /** See {@link ParticleSystem.emissionBursts}. */
346
+ emissionBursts?: Array<BurstParametersJSON>;
347
+ /** See {@link ParticleSystem.maxParticles}. */
348
+ maxParticles?: number;
349
+ /** See {@link ParticleSystem.onlyUsedByOther}. */
350
+ onlyUsedByOther?: boolean;
351
+ /**
352
+ * Trail, stretched or mesh settings; a trail's `startLength` as `ValueGeneratorJSON`. Left out when
353
+ * the render mode has none.
354
+ */
355
+ rendererEmitterSettings?: RendererEmitterSettingsJSON;
356
+ /** Uuid of the mesh particles' geometry entry; a document made in code may hold the entry itself. */
357
+ instancingGeometry?: string | GeometryEntry;
358
+ /** A {@link RenderMode} value. */
359
+ renderMode?: number;
360
+ /** See {@link ParticleSystem.renderOrder}. */
361
+ renderOrder?: number;
362
+ /** Written only when not 0. */
363
+ renderingGroupId?: number;
364
+ /** Written only when false. */
365
+ applyFog?: boolean;
366
+ /** Written only when not 1. */
367
+ playbackSpeed?: number;
368
+ /** Written only when not `'always'`. */
369
+ cullingMode?: CullingMode;
370
+ /** Written only when not `'shape'`. */
371
+ scalingMode?: ScalingMode;
372
+ /** Written only when set. */
373
+ seed?: number;
374
+ /** Written only when not `'none'`. */
375
+ sortMode?: SortMode;
376
+ /** Written only when not `'both'`. */
377
+ renderFace?: RenderFace;
378
+ /** Written only when true. */
379
+ alignToDirection?: boolean;
380
+ /** Written only when not 0. */
381
+ minParticleSize?: number;
382
+ /** Written only when limited. */
383
+ maxParticleSize?: number;
384
+ /** A stretched billboard's speed factor, as older files wrote it outside `rendererEmitterSettings`. */
385
+ speedFactor?: number;
386
+ /** Uuid of the texture entry. */
387
+ texture?: string;
388
+ /** Uuid of the material entry. */
389
+ material?: string;
390
+ /** The camera layer mask. */
391
+ layers?: number;
392
+ /** See {@link ParticleSystem.startTileIndex}. */
393
+ startTileIndex?: ValueGeneratorJSON | number;
394
+ /** See {@link ParticleSystem.uTileCount}. */
395
+ uTileCount?: number;
396
+ /** See {@link ParticleSystem.vTileCount}. */
397
+ vTileCount?: number;
398
+ /** See {@link ParticleSystem.blendTiles}. */
399
+ blendTiles?: boolean;
400
+ /** See {@link ParticleSystem.softParticles}. */
401
+ softParticles?: boolean;
402
+ /** See {@link ParticleSystem.softFarFade}. */
403
+ softFarFade?: number;
404
+ /** See {@link ParticleSystem.softNearFade}. */
405
+ softNearFade?: number;
406
+ /** See {@link ParticleSystem.blending}. */
407
+ blending?: number;
408
+ /** See {@link ParticleSystemParameters.transparent}. */
409
+ transparent?: boolean;
410
+ /** See {@link ParticleSystemParameters.depthTest}. */
411
+ depthTest?: boolean;
412
+ /** See {@link ParticleSystemParameters.depthWrite}. */
413
+ depthWrite?: boolean;
414
+ /** See {@link ParticleSystemParameters.alphaTest}. */
415
+ alphaTest?: number;
416
+ /** Each behavior as its `toJSON` writes it. */
417
+ behaviors?: BehaviorJSON[];
418
+ /** See {@link ParticleSystem.worldSpace}. */
419
+ worldSpace?: boolean;
420
+ /** `[x, y, z]`; written only when non-zero. */
421
+ pivot?: number[];
422
+ /** `[u, v]`; written only when non-zero. */
423
+ flip?: number[];
424
+ }
425
+
426
+ /**
427
+ * The resources of one effect document, by uuid: what {@link ParticleSystem.toJSON} writes a
428
+ * system's geometry, material and texture into, and what {@link ParticleSystem.fromJSON} resolves
429
+ * them from. While writing, entries hold live Babylon objects; `serializeEffect` turns them into
430
+ * plain data.
431
+ */
432
+ export interface BabylonMetaData {
433
+ /** Textures by uuid; null for one that could not be made. */
434
+ textures: {[uuid: string]: BaseTexture | null};
435
+ /** Material entries by uuid. */
436
+ materials: {[uuid: string]: QuarksMaterialJSON};
437
+ /** Geometry entries by uuid. */
438
+ geometries: {[uuid: string]: GeometryEntry};
439
+ /** Not used by babylon.quarks; kept for three.js-shaped documents. */
440
+ images?: {[uuid: string]: unknown};
441
+ /** Not used by babylon.quarks; kept for three.js-shaped documents. */
442
+ shapes?: {[uuid: string]: unknown};
443
+ /** Not used by babylon.quarks; kept for three.js-shaped documents. */
444
+ skeletons?: {[uuid: string]: unknown};
445
+ /** Not used by babylon.quarks; kept for three.js-shaped documents. */
446
+ animations?: {[uuid: string]: unknown};
447
+ /** Not used by babylon.quarks; kept for three.js-shaped documents. */
448
+ nodes?: {[uuid: string]: unknown};
449
+ }
@@ -0,0 +1,30 @@
1
+ import type {Texture} from '@babylonjs/core/Materials/Textures/texture';
2
+
3
+ /** Per loaded texture: the url its effect file wrote, and the url the loader gave the texture. */
4
+ const sources = new WeakMap<Texture, {source: string; loaded: string}>();
5
+
6
+ /**
7
+ * Remembers the url a texture's image had in the effect file (`tex/a.png`) and the url the texture
8
+ * was made with (`fx/tex/a.png`). Called by the loader when it makes a texture.
9
+ */
10
+ export function setTextureSourceUrl(texture: Texture, source: string, loaded: string): void {
11
+ sources.set(texture, {source, loaded});
12
+ }
13
+
14
+ /**
15
+ * The url a texture's image had in the effect file it was loaded from, relative to that file.
16
+ * `serializeEffect` writes it by default, so a file saved next to the one it was loaded from loads
17
+ * the same images.
18
+ *
19
+ * `undefined` when there is no such url: a texture made in code or loaded another way; a texture
20
+ * whose image the loader's resolver inlined (`data:` or `blob:`), which holds the image itself; and
21
+ * a texture whose `url` was changed since it was loaded (`updateURL`, or a `data:` URI assigned
22
+ * before saving), since the file's path no longer names what it shows.
23
+ *
24
+ * A texture shared between effects (see `QuarksLoaderOptions.shareResources`) keeps the url of the
25
+ * first effect that loaded it; effects in different folders that join to the same image share it.
26
+ */
27
+ export function textureSourceUrl(texture: Texture): string | undefined {
28
+ const entry = sources.get(texture);
29
+ return entry !== undefined && texture.url === entry.loaded ? entry.source : undefined;
30
+ }
@@ -0,0 +1,54 @@
1
+ import type {TrailSettings, TrailTextureMode} from 'quarks.core';
2
+
3
+ /** A trail's settings other than its start length and side axis, alike in code and in JSON. */
4
+ export type TrailOptions = Omit<TrailSettings, 'startLength' | 'sideAxis'>;
5
+
6
+ /**
7
+ * The normalised values of a trail's optional settings (`TrailSettings`), each read with its
8
+ * default for a value that is unset or out of range, so the batch, the simulation, JSON and
9
+ * clones agree on what a setting means.
10
+ */
11
+
12
+ /** Most segments one recorded segment of a trail is drawn as, see `TrailSettings.tessellation`. */
13
+ export const MAX_TRAIL_TESSELLATION = 16;
14
+
15
+ /** A trail's tessellation, a whole number from 0 (the default: none) to {@link MAX_TRAIL_TESSELLATION}. */
16
+ export function trailTessellation(settings: Partial<TrailOptions> | undefined): number {
17
+ const value = Math.round(Number(settings?.tessellation) || 0);
18
+ return Math.min(MAX_TRAIL_TESSELLATION, Math.max(0, value));
19
+ }
20
+
21
+ /** A trail's curve tension, from 0 (the default: Catmull-Rom) to 1 (straight segments). */
22
+ export function trailCurveTension(settings: Partial<TrailOptions> | undefined): number {
23
+ const value = Number(settings?.curveTension) || 0;
24
+ return Math.min(1, Math.max(0, value));
25
+ }
26
+
27
+ const TEXTURE_MODES: readonly TrailTextureMode[] = ['stretch', 'tile', 'distributePerSegment', 'repeatPerSegment'];
28
+
29
+ /** A trail's texture mode, `'stretch'` (the default) unless set to one of the others. */
30
+ export function trailTextureMode(settings: Partial<TrailOptions> | undefined): TrailTextureMode {
31
+ const mode = settings?.textureMode;
32
+ return mode !== undefined && TEXTURE_MODES.includes(mode) ? mode : 'stretch';
33
+ }
34
+
35
+ /** A trail's texture scale: a finite number above 0, else the default 1. */
36
+ export function trailTextureScale(settings: Partial<TrailOptions> | undefined): number {
37
+ const value = Number(settings?.textureScale);
38
+ return Number.isFinite(value) && value > 0 ? value : 1;
39
+ }
40
+
41
+ /** A trail's minimum distance between samples: a finite number of at least 0, else the default 0. */
42
+ export function trailMinVertexDistance(settings: Partial<TrailOptions> | undefined): number {
43
+ const value = Number(settings?.minVertexDistance);
44
+ return Number.isFinite(value) && value > 0 ? value : 0;
45
+ }
46
+
47
+ /**
48
+ * How long a trail keeps a sample, in seconds: a finite number above 0, else `Infinity` (the
49
+ * default, as 0 is: until the history is full).
50
+ */
51
+ export function trailLifetime(settings: Partial<TrailOptions> | undefined): number {
52
+ const value = Number(settings?.lifetime);
53
+ return Number.isFinite(value) && value > 0 ? value : Infinity;
54
+ }
@@ -1,3 +0,0 @@
1
- import {BatchedRenderer} from './BatchedRenderer';
2
-
3
- export const BatchedParticleRenderer = BatchedRenderer;
@@ -1,23 +0,0 @@
1
- import {PBRMaterial} from '@babylonjs/core/Materials/PBR/pbrMaterial';
2
- import {StandardMaterial} from '@babylonjs/core/Materials/standardMaterial';
3
- import {Scene} from '@babylonjs/core/scene';
4
-
5
- export type BabylonParticleMaterialParameters = Record<string, any>;
6
-
7
- export class ParticleMeshStandardMaterial extends StandardMaterial {
8
- readonly isParticleMeshStandardMaterial = true;
9
-
10
- constructor(name: string, scene?: Scene, parameters: BabylonParticleMaterialParameters = {}) {
11
- super(name, scene);
12
- Object.assign(this, parameters);
13
- }
14
- }
15
-
16
- export class ParticleMeshPhysicsMaterial extends PBRMaterial {
17
- readonly isParticleMeshPhysicsMaterial = true;
18
-
19
- constructor(name: string, scene?: Scene, parameters: BabylonParticleMaterialParameters = {}) {
20
- super(name, scene);
21
- Object.assign(this, parameters);
22
- }
23
- }
@@ -1 +0,0 @@
1
- export * from './ParticleMaterials';
@@ -1 +0,0 @@
1
- export * from './register-shader-chunks';
@@ -1,32 +0,0 @@
1
- import softFragment from './soft_fragment.glsl';
2
- import softParsFragment from './soft_pars_fragment.glsl';
3
- import softParsVertex from './soft_pars_vertex.glsl';
4
- import softVertex from './soft_vertex.glsl';
5
- import tileFragment from './tile_fragment.glsl';
6
- import tileParsFragment from './tile_pars_fragment.glsl';
7
- import tileParsVertex from './tile_pars_vertex.glsl';
8
- import tileVertex from './tile_vertex.glsl';
9
-
10
- const shaderChunks: Record<string, string> = {};
11
- let registered = false;
12
-
13
- export function registerShaderChunks(): void {
14
- if (registered) return;
15
- shaderChunks.tile_pars_vertex = tileParsVertex;
16
- shaderChunks.tile_vertex = tileVertex;
17
- shaderChunks.tile_pars_fragment = tileParsFragment;
18
- shaderChunks.tile_fragment = tileFragment;
19
- shaderChunks.soft_pars_vertex = softParsVertex;
20
- shaderChunks.soft_vertex = softVertex;
21
- shaderChunks.soft_pars_fragment = softParsFragment;
22
- shaderChunks.soft_fragment = softFragment;
23
- registered = true;
24
- }
25
-
26
- export function getShaderChunk(chunkName: string): string | undefined {
27
- return shaderChunks[chunkName];
28
- }
29
-
30
- export function getRegisteredShaderChunks(): Readonly<Record<string, string>> {
31
- return shaderChunks;
32
- }
@@ -1,13 +0,0 @@
1
- export default /* glsl */ `
2
- #ifdef SOFT_PARTICLES
3
-
4
- vec2 p2 = projPosition.xy / projPosition.w;
5
- p2 = 0.5 * p2 + 0.5;
6
-
7
- float readDepth = texture2D(depthTexture, p2.xy).r;
8
- float viewDepth = linearize_depth(readDepth);
9
- float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));
10
-
11
- gl_FragColor *= softParticlesFade;
12
- #endif
13
- `;
@@ -1,20 +0,0 @@
1
- export default /* glsl */ `
2
- #ifdef SOFT_PARTICLES
3
- uniform sampler2D depthTexture;
4
- uniform vec4 projParams;
5
- uniform vec2 softParams;
6
-
7
- varying vec4 projPosition;
8
- varying float linearDepth;
9
-
10
- #define SOFT_NEAR_FADE softParams.x
11
- #define SOFT_INV_FADE_DISTANCE softParams.y
12
-
13
- #define zNear projParams.x
14
- #define zFar projParams.y
15
-
16
- float linearize_depth(float d) {
17
- return (zFar * zNear) / (zFar - d * (zFar - zNear));
18
- }
19
- #endif
20
- `;
@@ -1,6 +0,0 @@
1
- export default /* glsl */ `
2
- #ifdef SOFT_PARTICLES
3
- varying vec4 projPosition;
4
- varying float linearDepth;
5
- #endif
6
- `;
@@ -1,6 +0,0 @@
1
- export default /* glsl */ `
2
- #ifdef SOFT_PARTICLES
3
- projPosition = gl_Position;
4
- linearDepth = -mvPosition.z;
5
- #endif
6
- `;
@@ -1,9 +0,0 @@
1
- export default /* glsl */ `
2
- #ifdef USE_MAP
3
- vec4 texelColor = texture2D(map, vUv);
4
- #ifdef TILE_BLEND
5
- texelColor = mix(texelColor, texture2D(map, vUvNext), vUvBlend);
6
- #endif
7
- diffuseColor *= texelColor;
8
- #endif
9
- `;