@zylem/behaviors 0.2.0 → 0.3.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 (139) hide show
  1. package/dist/{chunk-3PYGRHAL.js → chunk-23HQH3GJ.js} +1 -2
  2. package/dist/{chunk-EIWQM6U3.js → chunk-2HKY6WF7.js} +0 -1
  3. package/dist/{chunk-KS72RZHX.js → chunk-2HLZBWGD.js} +0 -1
  4. package/dist/{chunk-HZMY3TT4.js → chunk-4DVDFCVY.js} +0 -1
  5. package/dist/{chunk-LD5SMIB3.js → chunk-4EWASZHB.js} +0 -1
  6. package/dist/{chunk-4I6E6DGV.js → chunk-6UMC6BB5.js} +4 -5
  7. package/dist/{chunk-ARJWUNRE.js → chunk-6Y3GB76J.js} +3 -4
  8. package/dist/{chunk-FPTWVCPN.js → chunk-7IZ36Y5G.js} +2 -3
  9. package/dist/{chunk-ID5QJYF5.js → chunk-7U4WFBWM.js} +0 -1
  10. package/dist/{chunk-GCNRXAKH.js → chunk-7Y6JVZ5H.js} +1 -2
  11. package/dist/{chunk-2CLT36VB.js → chunk-BC3IJYS7.js} +4 -5
  12. package/dist/{chunk-XIJNE67Y.js → chunk-D53GNZXP.js} +3 -4
  13. package/dist/{chunk-XG2YMCJW.js → chunk-E4HTCQPK.js} +4 -5
  14. package/dist/{chunk-WOMHL23C.js → chunk-ERS6SNA5.js} +1 -2
  15. package/dist/{chunk-BXP4K7RF.js → chunk-F6LFX4V3.js} +2 -3
  16. package/dist/{chunk-DYLH6K7B.js → chunk-F7E23E26.js} +0 -1
  17. package/dist/{chunk-RTRVBEIB.js → chunk-FHDYJ5WP.js} +2 -3
  18. package/dist/{chunk-F3KRX2V4.js → chunk-FOOM42MK.js} +5 -6
  19. package/dist/{chunk-OYWFPIHF.js → chunk-HIBJDA5Z.js} +4 -5
  20. package/dist/{chunk-6C6NXNEW.js → chunk-IEA7F73P.js} +1 -2
  21. package/dist/{chunk-SS7ELMJ7.js → chunk-IQRG5BAZ.js} +4 -5
  22. package/dist/{chunk-K3UNLQ7W.js → chunk-J5XLB24H.js} +1 -2
  23. package/dist/{chunk-2C3Z5GE7.js → chunk-K4UBXSZL.js} +1 -2
  24. package/dist/{chunk-UYFOLI2X.js → chunk-K6CWKFHL.js} +0 -1
  25. package/dist/{chunk-STCCNLPC.js → chunk-L76JG73P.js} +3 -4
  26. package/dist/{chunk-KOZUNIIE.js → chunk-RD2YTTXY.js} +3 -4
  27. package/dist/{chunk-4URF65BR.js → chunk-RER2IDPW.js} +0 -1
  28. package/dist/{chunk-WWVD5DR5.js → chunk-RHW3IDQX.js} +0 -1
  29. package/dist/{chunk-RTVRUNYR.js → chunk-RQWWUML4.js} +0 -1
  30. package/dist/{chunk-YUO6SKJD.js → chunk-SBACY5SU.js} +5 -6
  31. package/dist/{chunk-JAN34G6S.js → chunk-T2P4JTQN.js} +2 -3
  32. package/dist/{chunk-SVLNF434.js → chunk-UFHYR2LV.js} +0 -1
  33. package/dist/{chunk-VAN4WW3F.js → chunk-VO5J64DG.js} +2 -3
  34. package/dist/{chunk-POZER3MQ.js → chunk-VPZ32CCD.js} +101 -96
  35. package/dist/{chunk-OHCPV2NT.js → chunk-WHKPWIQO.js} +0 -1
  36. package/dist/chunk-WSKD7GY3.js +2630 -0
  37. package/dist/{chunk-EZNCCO4L.js → chunk-YDLO5M7S.js} +0 -1
  38. package/dist/{chunk-Y6UJOUE5.js → chunk-YYJP62QD.js} +0 -1
  39. package/dist/{chunk-KDY5N6J4.js → chunk-ZHBD65AZ.js} +0 -1
  40. package/dist/cooldown.js +2 -3
  41. package/dist/coordinators/boundary-ricochet-3d.js +2 -3
  42. package/dist/coordinators/boundary-ricochet.js +2 -3
  43. package/dist/coordinators/first-person-shooter.js +3 -4
  44. package/dist/coordinators/multidirectional-space-shooter.js +4 -5
  45. package/dist/coordinators/top-down-shooter.js +4 -5
  46. package/dist/core.js +6 -7
  47. package/dist/destructible-3d.js +3 -4
  48. package/dist/destructible-prebake.js +1 -2
  49. package/dist/first-person.js +6 -7
  50. package/dist/index.d.ts +2 -2
  51. package/dist/index.js +38 -39
  52. package/dist/jumper-2d.js +5 -6
  53. package/dist/jumper-3d.js +6 -7
  54. package/dist/particle-emitter/presets.d.ts +2 -2
  55. package/dist/particle-emitter/presets.js +1 -2
  56. package/dist/particle-emitter.d.ts +9 -4
  57. package/dist/particle-emitter.js +4 -5
  58. package/dist/platformer-3d.js +3 -4
  59. package/dist/ricochet-2d.js +4 -5
  60. package/dist/ricochet-3d.js +4 -5
  61. package/dist/runtime-2d.js +2 -3
  62. package/dist/runtime-pong.js +2 -3
  63. package/dist/screen-visibility.js +2 -3
  64. package/dist/screen-wrap.js +4 -5
  65. package/dist/shooter-2d.js +4 -5
  66. package/dist/spark-Dx3cJbTW.d.ts +356 -0
  67. package/dist/thruster.js +5 -6
  68. package/dist/top-down-movement.js +5 -6
  69. package/dist/world-boundary-2d.js +5 -6
  70. package/dist/world-boundary-3d.js +5 -6
  71. package/package.json +158 -159
  72. package/dist/chunk-2C3Z5GE7.js.map +0 -1
  73. package/dist/chunk-2CLT36VB.js.map +0 -1
  74. package/dist/chunk-3PYGRHAL.js.map +0 -1
  75. package/dist/chunk-4I6E6DGV.js.map +0 -1
  76. package/dist/chunk-4URF65BR.js.map +0 -1
  77. package/dist/chunk-6C6NXNEW.js.map +0 -1
  78. package/dist/chunk-ARJWUNRE.js.map +0 -1
  79. package/dist/chunk-BXP4K7RF.js.map +0 -1
  80. package/dist/chunk-DYLH6K7B.js.map +0 -1
  81. package/dist/chunk-EIWQM6U3.js.map +0 -1
  82. package/dist/chunk-EZNCCO4L.js.map +0 -1
  83. package/dist/chunk-F3KRX2V4.js.map +0 -1
  84. package/dist/chunk-FPTWVCPN.js.map +0 -1
  85. package/dist/chunk-GCNRXAKH.js.map +0 -1
  86. package/dist/chunk-GYURWCIQ.js +0 -1985
  87. package/dist/chunk-GYURWCIQ.js.map +0 -1
  88. package/dist/chunk-HZMY3TT4.js.map +0 -1
  89. package/dist/chunk-ID5QJYF5.js.map +0 -1
  90. package/dist/chunk-JAN34G6S.js.map +0 -1
  91. package/dist/chunk-K3UNLQ7W.js.map +0 -1
  92. package/dist/chunk-KDY5N6J4.js.map +0 -1
  93. package/dist/chunk-KOZUNIIE.js.map +0 -1
  94. package/dist/chunk-KS72RZHX.js.map +0 -1
  95. package/dist/chunk-LD5SMIB3.js.map +0 -1
  96. package/dist/chunk-OHCPV2NT.js.map +0 -1
  97. package/dist/chunk-OYWFPIHF.js.map +0 -1
  98. package/dist/chunk-POZER3MQ.js.map +0 -1
  99. package/dist/chunk-RTRVBEIB.js.map +0 -1
  100. package/dist/chunk-RTVRUNYR.js.map +0 -1
  101. package/dist/chunk-SS7ELMJ7.js.map +0 -1
  102. package/dist/chunk-STCCNLPC.js.map +0 -1
  103. package/dist/chunk-SVLNF434.js.map +0 -1
  104. package/dist/chunk-UYFOLI2X.js.map +0 -1
  105. package/dist/chunk-VAN4WW3F.js.map +0 -1
  106. package/dist/chunk-WOMHL23C.js.map +0 -1
  107. package/dist/chunk-WWVD5DR5.js.map +0 -1
  108. package/dist/chunk-XG2YMCJW.js.map +0 -1
  109. package/dist/chunk-XIJNE67Y.js.map +0 -1
  110. package/dist/chunk-Y6UJOUE5.js.map +0 -1
  111. package/dist/chunk-YUO6SKJD.js.map +0 -1
  112. package/dist/cooldown.js.map +0 -1
  113. package/dist/coordinators/boundary-ricochet-3d.js.map +0 -1
  114. package/dist/coordinators/boundary-ricochet.js.map +0 -1
  115. package/dist/coordinators/first-person-shooter.js.map +0 -1
  116. package/dist/coordinators/multidirectional-space-shooter.js.map +0 -1
  117. package/dist/coordinators/top-down-shooter.js.map +0 -1
  118. package/dist/core.js.map +0 -1
  119. package/dist/destructible-3d.js.map +0 -1
  120. package/dist/destructible-prebake.js.map +0 -1
  121. package/dist/first-person.js.map +0 -1
  122. package/dist/index.js.map +0 -1
  123. package/dist/jumper-2d.js.map +0 -1
  124. package/dist/jumper-3d.js.map +0 -1
  125. package/dist/particle-emitter/presets.js.map +0 -1
  126. package/dist/particle-emitter.js.map +0 -1
  127. package/dist/platformer-3d.js.map +0 -1
  128. package/dist/ricochet-2d.js.map +0 -1
  129. package/dist/ricochet-3d.js.map +0 -1
  130. package/dist/runtime-2d.js.map +0 -1
  131. package/dist/runtime-pong.js.map +0 -1
  132. package/dist/screen-visibility.js.map +0 -1
  133. package/dist/screen-wrap.js.map +0 -1
  134. package/dist/shooter-2d.js.map +0 -1
  135. package/dist/spark-DDlIg1nM.d.ts +0 -148
  136. package/dist/thruster.js.map +0 -1
  137. package/dist/top-down-movement.js.map +0 -1
  138. package/dist/world-boundary-2d.js.map +0 -1
  139. package/dist/world-boundary-3d.js.map +0 -1
@@ -1,29 +1,23 @@
1
1
  import {
2
- createParticleMaterial,
3
- createRangeValue,
4
- createTextureSystemOptions,
2
+ Particles,
5
3
  electricityPresets,
6
4
  firePresets,
7
5
  gasPresets,
8
6
  magicPresets,
9
7
  particleEffect,
10
- toColorVector,
11
8
  waterPresets
12
- } from "./chunk-GYURWCIQ.js";
9
+ } from "./chunk-WSKD7GY3.js";
13
10
  import {
14
11
  VEC3_ZERO,
15
12
  normalizeVec3,
16
13
  toThreeVector3
17
- } from "./chunk-WWVD5DR5.js";
14
+ } from "./chunk-RHW3IDQX.js";
18
15
  import {
19
16
  defineBehavior
20
- } from "./chunk-EZNCCO4L.js";
17
+ } from "./chunk-YDLO5M7S.js";
21
18
 
22
19
  // src/lib/behaviors/particle-emitter/particle-emitter.descriptor.ts
23
20
  import { Group, Quaternion, Vector3 } from "three";
24
- import {
25
- BatchedRenderer
26
- } from "three.quarks";
27
21
  function getRefGlobals(ref) {
28
22
  return ref.__getGlobals ?? null;
29
23
  }
@@ -48,28 +42,26 @@ var defaultOptions = {
48
42
  var ParticleRendererService = class {
49
43
  constructor(sceneRoot) {
50
44
  this.sceneRoot = sceneRoot;
51
- this.renderer.name = "zylem-particle-batch-renderer";
52
- this.sceneRoot.add(this.renderer);
53
45
  }
54
46
  sceneRoot;
55
- renderer = new BatchedRenderer();
56
47
  systems = /* @__PURE__ */ new Set();
48
+ /** Scene node that emitter anchors are parented to. */
49
+ get root() {
50
+ return this.sceneRoot;
51
+ }
57
52
  register(system) {
58
- if (this.systems.has(system)) {
59
- return;
60
- }
61
- this.renderer.addSystem(system);
62
53
  this.systems.add(system);
63
54
  }
64
55
  forget(system) {
65
56
  this.systems.delete(system);
66
57
  }
67
58
  update(delta) {
68
- this.renderer.update(delta);
59
+ for (const system of this.systems) {
60
+ system.update(delta);
61
+ }
69
62
  }
70
63
  destroy() {
71
64
  this.systems.clear();
72
- this.renderer.removeFromParent();
73
65
  }
74
66
  };
75
67
  function getParticleControlState(ref) {
@@ -146,7 +138,15 @@ function applyRuntimeState(ref) {
146
138
  }
147
139
  if (state.pendingRestart) {
148
140
  runtime.system.restart();
141
+ runtime.started = true;
149
142
  state.pendingRestart = false;
143
+ if (state.desiredState === "paused") {
144
+ runtime.system.pause();
145
+ } else if (state.desiredState === "stopped") {
146
+ runtime.system.stop();
147
+ runtime.started = false;
148
+ }
149
+ return;
150
150
  }
151
151
  if (state.desiredState === "paused") {
152
152
  runtime.system.pause();
@@ -154,9 +154,15 @@ function applyRuntimeState(ref) {
154
154
  }
155
155
  if (state.desiredState === "stopped") {
156
156
  runtime.system.stop();
157
+ runtime.started = false;
157
158
  return;
158
159
  }
159
- runtime.system.play();
160
+ if (!runtime.started) {
161
+ runtime.system.start();
162
+ runtime.started = true;
163
+ } else {
164
+ runtime.system.resume();
165
+ }
160
166
  }
161
167
  function releaseRuntime(ref, reason) {
162
168
  const state = getParticleControlState(ref);
@@ -166,7 +172,6 @@ function releaseRuntime(ref, reason) {
166
172
  }
167
173
  state.runtime = null;
168
174
  state.pendingRestart = false;
169
- runtime.system.removeEventListener("destroy", runtime.onDestroy);
170
175
  runtime.service.forget(runtime.system);
171
176
  if (reason === "manual") {
172
177
  runtime.system.dispose();
@@ -191,14 +196,12 @@ function createRuntime(entity, ref, service) {
191
196
  service,
192
197
  initialPosition: initialTransform.position.clone(),
193
198
  initialQuaternion: initialTransform.quaternion.clone(),
194
- onDestroy: () => handleSystemDestroyed(entity, ref)
199
+ started: false
195
200
  };
196
201
  anchor.name = `${entity.name || entity.uuid}:particle-anchor`;
197
- system.autoDestroy = ref.options.autoDestroy;
198
- anchor.add(system.emitter);
202
+ anchor.add(system);
199
203
  service.register(system);
200
- service.renderer.parent?.add(anchor);
201
- system.addEventListener("destroy", runtime.onDestroy);
204
+ service.root.add(anchor);
202
205
  syncRuntimeTransform(entity, ref, runtime);
203
206
  return runtime;
204
207
  }
@@ -237,7 +240,7 @@ function createParticleEmitterHandle(ref) {
237
240
  if (!runtime) {
238
241
  return getParticleControlState(ref).desiredState === "playing";
239
242
  }
240
- return !runtime.system.paused;
243
+ return runtime.system.running;
241
244
  },
242
245
  getSystem: () => getParticleControlState(ref).runtime?.system ?? null
243
246
  };
@@ -287,6 +290,9 @@ var ParticleEmitterBehaviorSystem = class {
287
290
  hasRuntime = true;
288
291
  syncRuntimeTransform(entity, ref, state.runtime);
289
292
  applyRuntimeState(ref);
293
+ if (ref.options.autoDestroy && state.runtime.started && state.desiredState === "playing" && state.runtime.system.isComplete()) {
294
+ handleSystemDestroyed(entity, ref);
295
+ }
290
296
  }
291
297
  if (hasRuntime && rendererService) {
292
298
  rendererService.update(delta);
@@ -320,78 +326,78 @@ var ParticleEmitterBehavior = defineBehavior({
320
326
  });
321
327
 
322
328
  // src/lib/behaviors/particle-emitter/particle-effect.ts
323
- import {
324
- ConstantColor,
325
- ConstantValue,
326
- ParticleSystem as ParticleSystem2,
327
- PointEmitter,
328
- RenderMode
329
- } from "three.quarks";
329
+ import { AdditiveBlending, Color } from "three";
330
+ function toRange(value, fallback) {
331
+ if (value === void 0) return fallback;
332
+ if (Array.isArray(value)) {
333
+ return [value[0] ?? fallback[0], value[1] ?? fallback[1]];
334
+ }
335
+ const single = value;
336
+ return [single, single];
337
+ }
338
+ function toHexColor(color) {
339
+ return `#${new Color(color).getHexString()}`;
340
+ }
341
+ function makeBurstConfig(options, defaults) {
342
+ const count = Math.max(1, Math.round(options.count ?? defaults.count));
343
+ const color = toHexColor(options.color ?? defaults.color);
344
+ const blending = options.blending ?? AdditiveBlending;
345
+ const particles = {
346
+ count,
347
+ intensity: options.opacity ?? defaults.intensity,
348
+ colors: [
349
+ [
350
+ { color, stop: 0 },
351
+ { color, stop: 1 }
352
+ ]
353
+ ],
354
+ fadeAlpha: [0.05, 0.7],
355
+ fadeSize: [0.1, 0.85]
356
+ };
357
+ if (options.texture) {
358
+ particles.alphaMapsStart = [options.texture];
359
+ }
360
+ return {
361
+ particles,
362
+ emitter: {
363
+ duration: options.duration ?? defaults.duration,
364
+ loop: false,
365
+ spawnMode: "burst",
366
+ rate: count,
367
+ static: 0,
368
+ lifetime: toRange(options.life, defaults.life),
369
+ speed: toRange(options.speed, defaults.speed),
370
+ size: toRange(options.size, defaults.size),
371
+ directionMin: [-1, -1, -1],
372
+ directionMax: [1, 1, 1]
373
+ },
374
+ render: { blendingMode: blending }
375
+ };
376
+ }
330
377
  var particlePresets = {
331
378
  burst(options = {}) {
332
- return particleEffect(
333
- () => new ParticleSystem2({
334
- duration: options.duration ?? 0.25,
335
- looping: false,
336
- worldSpace: options.worldSpace ?? false,
337
- startLife: createRangeValue(options.life ?? [0.3, 0.7], [0.3, 0.7]),
338
- startSpeed: createRangeValue(options.speed ?? [1.5, 4], [1.5, 4]),
339
- startSize: createRangeValue(options.size ?? [0.08, 0.18], [0.08, 0.18]),
340
- startColor: new ConstantColor(
341
- toColorVector(options.color ?? "#ffffff")
342
- ),
343
- emissionOverTime: new ConstantValue(0),
344
- emissionBursts: [
345
- {
346
- time: 0,
347
- count: new ConstantValue(options.count ?? 18),
348
- cycle: 1,
349
- interval: 0,
350
- probability: 1
351
- }
352
- ],
353
- shape: new PointEmitter(),
354
- material: createParticleMaterial(
355
- options.color ?? "#ffffff",
356
- options
357
- ),
358
- ...createTextureSystemOptions(options),
359
- renderMode: RenderMode.BillBoard
360
- })
361
- );
379
+ const config = makeBurstConfig(options, {
380
+ duration: 0.25,
381
+ life: [0.3, 0.7],
382
+ speed: [1.5, 4],
383
+ size: [0.08, 0.18],
384
+ color: "#ffffff",
385
+ count: 18,
386
+ intensity: 1
387
+ });
388
+ return particleEffect(() => new Particles(config));
362
389
  },
363
390
  smoke(options = {}) {
364
- return particleEffect(
365
- () => new ParticleSystem2({
366
- duration: options.duration ?? 1.1,
367
- looping: false,
368
- worldSpace: options.worldSpace ?? false,
369
- startLife: createRangeValue(options.life ?? [0.8, 1.6], [0.8, 1.6]),
370
- startSpeed: createRangeValue(options.speed ?? [0.2, 0.8], [0.2, 0.8]),
371
- startSize: createRangeValue(options.size ?? [0.2, 0.5], [0.2, 0.5]),
372
- startColor: new ConstantColor(
373
- toColorVector(options.color ?? "#999999")
374
- ),
375
- emissionOverTime: new ConstantValue(0),
376
- emissionBursts: [
377
- {
378
- time: 0,
379
- count: new ConstantValue(options.count ?? 10),
380
- cycle: 1,
381
- interval: 0,
382
- probability: 1
383
- }
384
- ],
385
- shape: new PointEmitter(),
386
- material: createParticleMaterial(
387
- options.color ?? "#999999",
388
- options,
389
- 0.85
390
- ),
391
- ...createTextureSystemOptions(options),
392
- renderMode: RenderMode.BillBoard
393
- })
394
- );
391
+ const config = makeBurstConfig(options, {
392
+ duration: 1.1,
393
+ life: [0.8, 1.6],
394
+ speed: [0.2, 0.8],
395
+ size: [0.2, 0.5],
396
+ color: "#999999",
397
+ count: 10,
398
+ intensity: 0.85
399
+ });
400
+ return particleEffect(() => new Particles(config));
395
401
  },
396
402
  fire: firePresets,
397
403
  water: waterPresets,
@@ -404,4 +410,3 @@ export {
404
410
  ParticleEmitterBehavior,
405
411
  particlePresets
406
412
  };
407
- //# sourceMappingURL=chunk-POZER3MQ.js.map
@@ -83,4 +83,3 @@ export {
83
83
  clampPointToBounds3D,
84
84
  getBounds3DNormalFromHits
85
85
  };
86
- //# sourceMappingURL=chunk-OHCPV2NT.js.map