babylon.quarks 0.26.0 → 0.27.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 (79) hide show
  1. package/CHANGELOG.md +769 -8
  2. package/README.md +10 -8
  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 +6683 -0
  10. package/dist/types/index.d.ts +1959 -588
  11. package/package.json +12 -6
  12. package/src/BatchedRenderer.ts +204 -101
  13. package/src/EffectPool.ts +4 -1
  14. package/src/MeshSurfaceEmitter.ts +29 -4
  15. package/src/ParticleEmitter.ts +45 -15
  16. package/src/ParticleSystem.ts +909 -2061
  17. package/src/QuarksLoader.ts +421 -67
  18. package/src/QuarksPrefab.ts +91 -4
  19. package/src/QuarksSerializer.ts +484 -0
  20. package/src/QuarksUtil.ts +15 -0
  21. package/src/SpriteBatch.ts +106 -246
  22. package/src/TrailBatch.ts +533 -342
  23. package/src/VFXBatch.ts +236 -136
  24. package/src/batchKey.ts +237 -0
  25. package/src/effectResources.ts +79 -0
  26. package/src/envAtlas.ts +119 -17
  27. package/src/index.ts +32 -33
  28. package/src/nodeId.ts +13 -0
  29. package/src/shaderProgram.ts +325 -0
  30. package/src/shaderVariants.ts +225 -0
  31. package/src/shaders/chunks/fog.ts +4 -2
  32. package/src/shaders/chunks/sheet.ts +111 -0
  33. package/src/shaders/chunks/soft.ts +84 -0
  34. package/src/shaders/chunks/surface.ts +10 -0
  35. package/src/shaders/local_particle_physics_vert.glsl.ts +14 -28
  36. package/src/shaders/local_particle_physics_vert.wgsl.ts +16 -29
  37. package/src/shaders/particle_frag.glsl.ts +3 -22
  38. package/src/shaders/particle_frag.wgsl.ts +3 -23
  39. package/src/shaders/particle_physics_frag.glsl.ts +12 -25
  40. package/src/shaders/particle_physics_frag.wgsl.ts +12 -26
  41. package/src/shaders/particle_vert.glsl.ts +5 -27
  42. package/src/shaders/particle_vert.wgsl.ts +5 -26
  43. package/src/shaders/stretched_bb_particle_vert.glsl.ts +7 -33
  44. package/src/shaders/stretched_bb_particle_vert.wgsl.ts +7 -33
  45. package/src/shaders/trail_frag.glsl.ts +11 -1
  46. package/src/shaders/trail_frag.wgsl.ts +11 -0
  47. package/src/shaders/trail_vert.glsl.ts +45 -36
  48. package/src/shaders/trail_vert.wgsl.ts +46 -40
  49. package/src/softDepth.ts +136 -0
  50. package/src/system/BehaviorPlan.ts +85 -0
  51. package/src/system/BoundsTracker.ts +181 -0
  52. package/src/system/EmissionController.ts +360 -0
  53. package/src/system/EventDispatcher.ts +44 -0
  54. package/src/system/ParticleSpawner.ts +274 -0
  55. package/src/system/SimulationClock.ts +130 -0
  56. package/src/system/geometry.ts +111 -0
  57. package/src/system/integrate.ts +428 -0
  58. package/src/system/materialResolve.ts +116 -0
  59. package/src/system/normalize.ts +95 -0
  60. package/src/system/serialization.ts +401 -0
  61. package/src/system/settingsSchema.ts +317 -0
  62. package/src/system/types.ts +410 -0
  63. package/src/textureSource.ts +30 -0
  64. package/src/trailSettings.ts +51 -0
  65. package/src/BatchedParticleRenderer.ts +0 -3
  66. package/src/materials/ParticleMaterials.ts +0 -23
  67. package/src/materials/index.ts +0 -1
  68. package/src/shaders/chunks/index.ts +0 -1
  69. package/src/shaders/chunks/register-shader-chunks.ts +0 -32
  70. package/src/shaders/chunks/soft_fragment.glsl.ts +0 -13
  71. package/src/shaders/chunks/soft_pars_fragment.glsl.ts +0 -20
  72. package/src/shaders/chunks/soft_pars_vertex.glsl.ts +0 -6
  73. package/src/shaders/chunks/soft_vertex.glsl.ts +0 -6
  74. package/src/shaders/chunks/tile_fragment.glsl.ts +0 -9
  75. package/src/shaders/chunks/tile_pars_fragment.glsl.ts +0 -9
  76. package/src/shaders/chunks/tile_pars_vertex.glsl.ts +0 -28
  77. package/src/shaders/chunks/tile_vertex.glsl.ts +0 -18
  78. package/src/shaders/index.ts +0 -9
  79. package/src/shaders/local_particle_vert.glsl.ts +0 -50
@@ -1,8 +1,33 @@
1
1
  import {TransformNode} from '@babylonjs/core/Meshes/transformNode';
2
2
  import {Scene} from '@babylonjs/core/scene';
3
3
  import {IParticleSystem, Matrix4, SerializationOptions} from 'quarks.core';
4
+ import {quarksNodeId} from './nodeId';
4
5
 
6
+ /**
7
+ * Above 0 while a particle system disposes its own emitter (`ParticleSystem.dispose()`, which
8
+ * `autoDestroy` calls when the system finishes). Babylon then disposes the child nodes too, and
9
+ * child emitters keep their systems playing, so an effect's longer-lived children are not cut off
10
+ * when a short parent finishes. Disposing a node directly (`root.dispose()`) disposes its systems.
11
+ */
12
+ let systemDisposeDepth = 0;
13
+
14
+ /** Disposes `emitter` for its own system without disposing the systems of child emitters. */
15
+ export function disposeEmitterForSystem(emitter: TransformNode): void {
16
+ systemDisposeDepth++;
17
+ try {
18
+ emitter.dispose();
19
+ } finally {
20
+ systemDisposeDepth--;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * The Babylon node a particle system lives at: its position, rotation and scale place the system,
26
+ * parenting it moves the effect with another node, and disabling it freezes and hides the system.
27
+ * Every {@link ParticleSystem} makes its own, as `system.emitter`.
28
+ */
5
29
  export class ParticleEmitter extends TransformNode {
30
+ /** The particle system this node carries. */
6
31
  system: IParticleSystem;
7
32
  private _matrixWorld: Matrix4 = new Matrix4();
8
33
  private _matrixWorldFlag = -1;
@@ -40,6 +65,7 @@ export class ParticleEmitter extends TransformNode {
40
65
  return this._matrixWorld;
41
66
  }
42
67
 
68
+ /** Whether the node and its parents are enabled; setting it is `setEnabled`. */
43
69
  get visible(): boolean {
44
70
  return this.isEnabled();
45
71
  }
@@ -48,8 +74,9 @@ export class ParticleEmitter extends TransformNode {
48
74
  this.setEnabled(value);
49
75
  }
50
76
 
77
+ /** The id effect files know this emitter by; see {@link quarksNodeId}. */
51
78
  get uuid(): string {
52
- return this.uniqueId.toString();
79
+ return quarksNodeId(this);
53
80
  }
54
81
 
55
82
  constructor(system: IParticleSystem, scene?: Scene) {
@@ -57,20 +84,22 @@ export class ParticleEmitter extends TransformNode {
57
84
  this.system = system;
58
85
  }
59
86
 
60
- dispose(): void {
61
- super.dispose();
62
- }
63
-
64
- extractFromCache(cache: any): any[] {
65
- const values: any[] = [];
66
- for (const key in cache) {
67
- const data = cache[key];
68
- if (data && typeof data === 'object') {
69
- delete data.metadata;
70
- }
71
- values.push(data);
87
+ /**
88
+ * Disposes the node and the particle system it carries, so `root.dispose()` on an effect tree
89
+ * also removes its systems from their renderer. Safe to call more than once. When a system
90
+ * disposes its own emitter (`ParticleSystem.dispose()`, `autoDestroy`), the systems of child
91
+ * emitters keep playing until they finish or are disposed themselves.
92
+ */
93
+ dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {
94
+ if (this.isDisposed()) {
95
+ return;
96
+ }
97
+ super.dispose(doNotRecurse, disposeMaterialAndTextures);
98
+ if (systemDisposeDepth > 0) {
99
+ return;
72
100
  }
73
- return values;
101
+ // IParticleSystem (quarks.core) has no dispose(); ParticleSystem does.
102
+ (this.system as IParticleSystem & {dispose?: () => void}).dispose?.();
74
103
  }
75
104
 
76
105
  clone(name?: string): ParticleEmitter {
@@ -88,9 +117,10 @@ export class ParticleEmitter extends TransformNode {
88
117
  return clonedEmitter;
89
118
  }
90
119
 
120
+ /** The node and its system in effect-file form; `serializeEffect` writes whole effects. @internal */
91
121
  toJSON(meta?: any, options: SerializationOptions = {}): any {
92
122
  return {
93
- uuid: (this as any)._quarksUUID ?? this.uniqueId.toString(),
123
+ uuid: quarksNodeId(this),
94
124
  type: 'ParticleEmitter',
95
125
  name: this.name,
96
126
  position: [this.position.x, this.position.y, this.position.z],