@zylem/behaviors 0.5.2 → 0.5.5

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 (73) hide show
  1. package/dist/{behavior-system-CldqNUgr.d.ts → behavior-system-HEt67el5.d.ts} +14 -1
  2. package/dist/{chunk-Y4PHT2HG.js → chunk-3QUECYMT.js} +2 -2
  3. package/dist/{chunk-DZ4LLQON.js → chunk-4GW6DCYF.js} +24 -2
  4. package/dist/chunk-4GW6DCYF.js.map +1 -0
  5. package/dist/{chunk-G2KUXVU6.js → chunk-B2ERQ6HD.js} +2 -2
  6. package/dist/{chunk-7W3KY55G.js → chunk-D7N6SC4D.js} +2 -2
  7. package/dist/{chunk-LZIHSJZR.js → chunk-DWVLGXMF.js} +2 -2
  8. package/dist/{chunk-WU6XXL3D.js → chunk-GL5JGXPR.js} +2 -2
  9. package/dist/{chunk-7JLWZXPA.js → chunk-GLXEJD2P.js} +2 -2
  10. package/dist/{chunk-4MZ57HPD.js → chunk-IRMJTAIK.js} +2 -2
  11. package/dist/{chunk-7DGXUAPV.js → chunk-JACX7ZMJ.js} +2 -2
  12. package/dist/{chunk-4LLK2FJI.js → chunk-S5HFWDGM.js} +2 -2
  13. package/dist/{chunk-7JJEIADR.js → chunk-USFIJUDN.js} +300 -157
  14. package/dist/chunk-USFIJUDN.js.map +1 -0
  15. package/dist/{chunk-QS3VXWVO.js → chunk-WQUPSOFV.js} +2 -2
  16. package/dist/{chunk-4CEW64HO.js → chunk-ZOYA3TZG.js} +2 -2
  17. package/dist/{components-BmievOxF.d.ts → components-JZQoO2sU.d.ts} +1 -1
  18. package/dist/cooldown.d.ts +1 -1
  19. package/dist/coordinators/boundary-ricochet-3d.d.ts +2 -2
  20. package/dist/coordinators/boundary-ricochet.d.ts +2 -2
  21. package/dist/coordinators/multidirectional-space-shooter.d.ts +1 -1
  22. package/dist/coordinators/top-down-shooter.d.ts +1 -1
  23. package/dist/core.d.ts +20 -5
  24. package/dist/core.js +24 -1
  25. package/dist/core.js.map +1 -1
  26. package/dist/destructible-3d.d.ts +1 -1
  27. package/dist/first-person.d.ts +1 -1
  28. package/dist/first-person.js +2 -2
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.js +13 -13
  31. package/dist/jumper-2d.d.ts +1 -1
  32. package/dist/jumper-2d.js +2 -2
  33. package/dist/jumper-3d.d.ts +1 -1
  34. package/dist/jumper-3d.js +2 -2
  35. package/dist/{moveable-rdIvWiak.d.ts → moveable-BdFmI3s1.d.ts} +1 -1
  36. package/dist/particle-emitter/presets.d.ts +1 -1
  37. package/dist/particle-emitter/presets.js +1 -1
  38. package/dist/particle-emitter.d.ts +3 -3
  39. package/dist/particle-emitter.js +2 -2
  40. package/dist/platformer-2d.d.ts +1 -1
  41. package/dist/platformer-2d.js +2 -2
  42. package/dist/platformer-3d.d.ts +1 -1
  43. package/dist/platformer-3d.js +2 -2
  44. package/dist/ricochet-2d.d.ts +1 -1
  45. package/dist/ricochet-2d.js +2 -2
  46. package/dist/ricochet-3d.d.ts +1 -1
  47. package/dist/ricochet-3d.js +2 -2
  48. package/dist/runtime-2d.d.ts +1 -1
  49. package/dist/screen-visibility.d.ts +1 -1
  50. package/dist/screen-wrap.d.ts +1 -1
  51. package/dist/shooter-2d.d.ts +1 -1
  52. package/dist/{spark-Dx3cJbTW.d.ts → spark-C4Tp-52_.d.ts} +4 -2
  53. package/dist/thruster.d.ts +1 -1
  54. package/dist/top-down-movement.d.ts +1 -1
  55. package/dist/top-down-movement.js +2 -2
  56. package/dist/world-boundary-2d.d.ts +1 -1
  57. package/dist/world-boundary-2d.js +2 -2
  58. package/dist/world-boundary-3d.d.ts +1 -1
  59. package/dist/world-boundary-3d.js +2 -2
  60. package/package.json +159 -161
  61. package/dist/chunk-7JJEIADR.js.map +0 -1
  62. package/dist/chunk-DZ4LLQON.js.map +0 -1
  63. /package/dist/{chunk-Y4PHT2HG.js.map → chunk-3QUECYMT.js.map} +0 -0
  64. /package/dist/{chunk-G2KUXVU6.js.map → chunk-B2ERQ6HD.js.map} +0 -0
  65. /package/dist/{chunk-7W3KY55G.js.map → chunk-D7N6SC4D.js.map} +0 -0
  66. /package/dist/{chunk-LZIHSJZR.js.map → chunk-DWVLGXMF.js.map} +0 -0
  67. /package/dist/{chunk-WU6XXL3D.js.map → chunk-GL5JGXPR.js.map} +0 -0
  68. /package/dist/{chunk-7JLWZXPA.js.map → chunk-GLXEJD2P.js.map} +0 -0
  69. /package/dist/{chunk-4MZ57HPD.js.map → chunk-IRMJTAIK.js.map} +0 -0
  70. /package/dist/{chunk-7DGXUAPV.js.map → chunk-JACX7ZMJ.js.map} +0 -0
  71. /package/dist/{chunk-4LLK2FJI.js.map → chunk-S5HFWDGM.js.map} +0 -0
  72. /package/dist/{chunk-QS3VXWVO.js.map → chunk-WQUPSOFV.js.map} +0 -0
  73. /package/dist/{chunk-4CEW64HO.js.map → chunk-ZOYA3TZG.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
 
7
7
  // src/lib/behaviors/particle-emitter/gpu/particles.ts
8
8
  import * as THREE3 from "three/webgpu";
9
- import { texture as texture2, uniform, instancedArray } from "three/tsl";
9
+ import { instancedArray, texture as texture2, uniform } from "three/tsl";
10
10
 
11
11
  // src/lib/behaviors/particle-emitter/gpu/types.ts
12
12
  var EASE_FUNCTIONS = [
@@ -128,7 +128,8 @@ import * as THREE2 from "three/webgpu";
128
128
  import {
129
129
  normalize,
130
130
  max,
131
- varying,
131
+ min,
132
+ varyingProperty,
132
133
  If as If2,
133
134
  distance,
134
135
  Discard,
@@ -138,6 +139,7 @@ import {
138
139
  instanceIndex,
139
140
  vec3,
140
141
  float as float2,
142
+ int,
141
143
  mix,
142
144
  vec4,
143
145
  Fn as Fn2,
@@ -383,8 +385,89 @@ var easeInOutBack = /* @__PURE__ */ Fn(
383
385
  );
384
386
  var applyEasing = /* @__PURE__ */ Fn(
385
387
  ([t, easingId]) => {
386
- Switch(easingId).Case(0, () => easeLinear(t)).Case(1, () => easeInPower1(t)).Case(2, () => easeOutPower1(t)).Case(3, () => easeInOutPower1(t)).Case(4, () => easeInPower2(t)).Case(5, () => easeOutPower2(t)).Case(6, () => easeInOutPower2(t)).Case(7, () => easeInPower3(t)).Case(8, () => easeOutPower3(t)).Case(9, () => easeInOutPower3(t)).Case(10, () => easeInPower4(t)).Case(11, () => easeOutPower4(t)).Case(12, () => easeInOutPower4(t)).Case(13, () => easeInQuad(t)).Case(14, () => easeOutQuad(t)).Case(15, () => easeInOutQuad(t)).Case(16, () => easeInCubic(t)).Case(17, () => easeOutCubic(t)).Case(18, () => easeInOutCubic(t)).Case(19, () => easeInQuart(t)).Case(20, () => easeOutQuart(t)).Case(21, () => easeInOutQuart(t)).Case(22, () => easeInQuint(t)).Case(23, () => easeOutQuint(t)).Case(24, () => easeInOutQuint(t)).Case(25, () => easeInSine(t)).Case(26, () => easeOutSine(t)).Case(27, () => easeInOutSine(t)).Case(28, () => easeInExpo(t)).Case(29, () => easeOutExpo(t)).Case(30, () => easeInOutExpo(t)).Case(31, () => easeInCirc(t)).Case(32, () => easeOutCirc(t)).Case(33, () => easeInOutCirc(t)).Case(34, () => easeInElastic(t)).Case(35, () => easeOutElastic(t)).Case(36, () => easeInOutElastic(t)).Case(37, () => easeInBack(t)).Case(38, () => easeOutBack(t)).Case(39, () => easeInOutBack(t));
387
- return t;
388
+ const result = t.toVar();
389
+ Switch(easingId).Case(0, () => {
390
+ result.assign(easeLinear(t));
391
+ }).Case(1, () => {
392
+ result.assign(easeInPower1(t));
393
+ }).Case(2, () => {
394
+ result.assign(easeOutPower1(t));
395
+ }).Case(3, () => {
396
+ result.assign(easeInOutPower1(t));
397
+ }).Case(4, () => {
398
+ result.assign(easeInPower2(t));
399
+ }).Case(5, () => {
400
+ result.assign(easeOutPower2(t));
401
+ }).Case(6, () => {
402
+ result.assign(easeInOutPower2(t));
403
+ }).Case(7, () => {
404
+ result.assign(easeInPower3(t));
405
+ }).Case(8, () => {
406
+ result.assign(easeOutPower3(t));
407
+ }).Case(9, () => {
408
+ result.assign(easeInOutPower3(t));
409
+ }).Case(10, () => {
410
+ result.assign(easeInPower4(t));
411
+ }).Case(11, () => {
412
+ result.assign(easeOutPower4(t));
413
+ }).Case(12, () => {
414
+ result.assign(easeInOutPower4(t));
415
+ }).Case(13, () => {
416
+ result.assign(easeInQuad(t));
417
+ }).Case(14, () => {
418
+ result.assign(easeOutQuad(t));
419
+ }).Case(15, () => {
420
+ result.assign(easeInOutQuad(t));
421
+ }).Case(16, () => {
422
+ result.assign(easeInCubic(t));
423
+ }).Case(17, () => {
424
+ result.assign(easeOutCubic(t));
425
+ }).Case(18, () => {
426
+ result.assign(easeInOutCubic(t));
427
+ }).Case(19, () => {
428
+ result.assign(easeInQuart(t));
429
+ }).Case(20, () => {
430
+ result.assign(easeOutQuart(t));
431
+ }).Case(21, () => {
432
+ result.assign(easeInOutQuart(t));
433
+ }).Case(22, () => {
434
+ result.assign(easeInQuint(t));
435
+ }).Case(23, () => {
436
+ result.assign(easeOutQuint(t));
437
+ }).Case(24, () => {
438
+ result.assign(easeInOutQuint(t));
439
+ }).Case(25, () => {
440
+ result.assign(easeInSine(t));
441
+ }).Case(26, () => {
442
+ result.assign(easeOutSine(t));
443
+ }).Case(27, () => {
444
+ result.assign(easeInOutSine(t));
445
+ }).Case(28, () => {
446
+ result.assign(easeInExpo(t));
447
+ }).Case(29, () => {
448
+ result.assign(easeOutExpo(t));
449
+ }).Case(30, () => {
450
+ result.assign(easeInOutExpo(t));
451
+ }).Case(31, () => {
452
+ result.assign(easeInCirc(t));
453
+ }).Case(32, () => {
454
+ result.assign(easeOutCirc(t));
455
+ }).Case(33, () => {
456
+ result.assign(easeInOutCirc(t));
457
+ }).Case(34, () => {
458
+ result.assign(easeInElastic(t));
459
+ }).Case(35, () => {
460
+ result.assign(easeOutElastic(t));
461
+ }).Case(36, () => {
462
+ result.assign(easeInOutElastic(t));
463
+ }).Case(37, () => {
464
+ result.assign(easeInBack(t));
465
+ }).Case(38, () => {
466
+ result.assign(easeOutBack(t));
467
+ }).Case(39, () => {
468
+ result.assign(easeInOutBack(t));
469
+ });
470
+ return result;
388
471
  },
389
472
  { t: "float", easingId: "int", return: "float" }
390
473
  );
@@ -393,26 +476,25 @@ var applyEasing = /* @__PURE__ */ Fn(
393
476
  var idx7 = instanceIndex.mul(7);
394
477
  var idx3 = instanceIndex.mul(3);
395
478
  var idx2 = instanceIndex.mul(2);
396
- var vProgress = varying(float2(0), "vProgress");
397
479
  var positionNode = /* @__PURE__ */ Fn2(
398
- ([pos, age, duration, vProgress2, uGravity, dir, speed, worldUpRight, easingIndex]) => {
480
+ ([pos, age, duration, vProgress, uGravity, dir, speed, worldUpRight, easingIndex]) => {
399
481
  const progress = age.div(duration);
400
482
  const _pos = vec3(pos);
401
483
  If2(progress.lessThan(0).or(progress.greaterThan(1)), () => {
402
- vProgress2.assign(1);
484
+ vProgress.assign(1);
403
485
  _pos.assign(vec3(0, 9999, 0));
404
486
  }).Else(() => {
405
- vProgress2.assign(applyEasing(progress, easingIndex));
487
+ vProgress.assign(applyEasing(progress, easingIndex));
406
488
  const normalizedDirection = select2(length(dir).greaterThan(0), normalize(dir), vec3(0));
407
489
  const gravityForce = uGravity.mul(0.5).mul(age.mul(age));
408
- const easedAge = vProgress2.mul(duration);
490
+ const easedAge = vProgress.mul(duration);
409
491
  const offset = normalizedDirection.mul(easedAge).mul(speed).add(gravityForce);
410
492
  If2(worldUpRight, () => {
411
493
  const m = mat3(modelWorldMatrix);
412
494
  const rot = mat3(normalize(m[0]), normalize(m[1]), normalize(m[2]));
413
495
  const inverseRotation = transpose(rot);
414
496
  const worldOffset = inverseRotation.mul(offset);
415
- const blendedOffset = mix(offset, worldOffset, vProgress2);
497
+ const blendedOffset = mix(offset, worldOffset, vProgress);
416
498
  _pos.addAssign(blendedOffset);
417
499
  }).Else(() => {
418
500
  _pos.addAssign(offset);
@@ -428,9 +510,13 @@ var rotationNode = /* @__PURE__ */ Fn2(([rot, rotSpeed, age]) => {
428
510
  const wrapped = angle.mod(tau);
429
511
  return wrapped.add(tau).mod(tau);
430
512
  });
431
- var scaleNode = /* @__PURE__ */ Fn2(([fadeSize, scale, vProgress2]) => {
513
+ var scaleNode = /* @__PURE__ */ Fn2(([fadeSize, scale, vProgress]) => {
432
514
  const uFadeSize = vec2(fadeSize[0], fadeSize[1]).toVar();
433
- return smoothstep(0, uFadeSize.x, vProgress2).mul(smoothstep(1.01, uFadeSize.y, vProgress2)).mul(scale);
515
+ const fadeInEnd = min(max(uFadeSize.x, 1e-4), 0.9999);
516
+ const fadeOutStart = min(max(uFadeSize.y, 1e-4), 0.9999);
517
+ const fadeIn = smoothstep(0, fadeInEnd, vProgress);
518
+ const fadeOut = float2(1).sub(smoothstep(fadeOutStart, 1, vProgress));
519
+ return fadeIn.mul(fadeOut).mul(scale);
434
520
  });
435
521
  var colorNode = /* @__PURE__ */ Fn2(
436
522
  ([
@@ -438,7 +524,7 @@ var colorNode = /* @__PURE__ */ Fn2(
438
524
  intensity,
439
525
  fadeAlpha,
440
526
  fadeAlphaMap,
441
- vProgress2,
527
+ vProgress,
442
528
  uColorGradient,
443
529
  uAlphaMapCount,
444
530
  vAlphaMapUVOffsetX,
@@ -450,13 +536,15 @@ var colorNode = /* @__PURE__ */ Fn2(
450
536
  const uIntensity = float2(intensity).toVar();
451
537
  const uFadeAlpha = vec2(fadeAlpha[0], fadeAlpha[1]).toVar();
452
538
  const uFadeAlphaMap = vec2(fadeAlphaMap[0], fadeAlphaMap[1]).toVar();
453
- const u = vProgress2;
539
+ const u = vProgress;
454
540
  const v = vColorGradientRow.add(0.5).div(max(uColorGradientRows, 1));
455
541
  const finalColor = uColorGradient.sample(vec2(u, v)).rgb;
456
542
  finalColor.mulAssign(uIntensity);
457
- const alpha = smoothstep(0, uFadeAlpha.x, vProgress2).mul(
458
- smoothstep(1.01, uFadeAlpha.y, vProgress2)
459
- );
543
+ const fadeInEnd = min(max(uFadeAlpha.x, 1e-4), 0.9999);
544
+ const fadeOutStart = min(max(uFadeAlpha.y, 1e-4), 0.9999);
545
+ const fadeIn = smoothstep(0, fadeInEnd, vProgress);
546
+ const fadeOut = float2(1).sub(smoothstep(fadeOutStart, 1, vProgress));
547
+ const alpha = fadeIn.mul(fadeOut);
460
548
  const vUv = uv();
461
549
  If2(uAlphaMapCount.equal(0), () => {
462
550
  const center = vec2(0.5).toVar();
@@ -474,7 +562,7 @@ var colorNode = /* @__PURE__ */ Fn2(
474
562
  const endU = vAlphaMapUVOffsetY.add(vUv.x).div(uAlphaMapCount);
475
563
  const endUV = vec2(endU, vUv.y);
476
564
  const endAlpha = alphaMap.sample(endUV).a;
477
- const morphProgress = smoothstep(uFadeAlphaMap.x, uFadeAlphaMap.y, vProgress2);
565
+ const morphProgress = smoothstep(uFadeAlphaMap.x, uFadeAlphaMap.y, vProgress);
478
566
  const morphedAlpha = mix(startAlpha, endAlpha, morphProgress);
479
567
  alpha.assign(morphedAlpha.mul(alpha));
480
568
  }).Else(() => {
@@ -484,115 +572,158 @@ var colorNode = /* @__PURE__ */ Fn2(
484
572
  return vec4(finalColor, alpha);
485
573
  }
486
574
  );
487
- var InstancePositionNode = class extends THREE2.Node {
488
- constructor() {
489
- super("vec3");
490
- this.updateType = THREE2.NodeUpdateType.OBJECT;
491
- }
492
- setup(frame) {
493
- const mesh = frame.object;
494
- const { attributes, uniforms, config, easingIndex } = mesh.userData;
495
- const uPosition = uniforms.uPosition;
496
- const _static = float2(config.emitter.static).toVar();
497
- const posX = attributes.instance.element(idx7.add(0));
498
- const posY = attributes.instance.element(idx7.add(1));
499
- const posZ = attributes.instance.element(idx7.add(2));
500
- const pos = vec3(posX, posY, posZ).add(uPosition.mul(_static));
501
- const dirX = attributes.instanceDirection.element(idx3.add(0));
502
- const dirY = attributes.instanceDirection.element(idx3.add(1));
503
- const dirZ = attributes.instanceDirection.element(idx3.add(2));
504
- const dir = vec3(dirX, dirY, dirZ);
505
- const time = uniforms.uTime;
506
- const uGravity = vec3(...config.particles.gravity);
507
- const worldUpRight = bool(config.emitter.worldUpRight);
508
- const startTime = attributes.instanceLifetime.element(idx2.add(0));
509
- const duration = attributes.instanceLifetime.element(idx2.add(1));
510
- const speed = attributes.instanceSpeed.element(instanceIndex).toVar();
511
- const age = select2(speed.lessThan(0), duration.sub(time.sub(startTime)), time.sub(startTime));
512
- return positionNode(pos, age, duration, vProgress, uGravity, dir, speed, worldUpRight, easingIndex);
513
- }
514
- };
515
- var InstanceRotationNode = class extends THREE2.Node {
516
- constructor() {
517
- super("vec3");
518
- this.updateType = THREE2.NodeUpdateType.OBJECT;
519
- }
520
- setup(frame) {
521
- const mesh = frame.object;
522
- const { attributes, uniforms } = mesh.userData;
523
- const rotX = attributes.instance.element(idx7.add(3));
524
- const rotY = attributes.instance.element(idx7.add(4));
525
- const rotZ = attributes.instance.element(idx7.add(5));
526
- const rot = vec3(rotX, rotY, rotZ);
527
- const rotSpeedX = attributes.instanceRotationSpeed.element(idx3.add(0));
528
- const rotSpeedY = attributes.instanceRotationSpeed.element(idx3.add(1));
529
- const rotSpeedZ = attributes.instanceRotationSpeed.element(idx3.add(2));
530
- const rotSpeed = vec3(rotSpeedX, rotSpeedY, rotSpeedZ);
531
- const time = uniforms.uTime;
532
- const startTime = attributes.instanceLifetime.element(idx2.add(0));
533
- const duration = attributes.instanceLifetime.element(idx2.add(1));
534
- const speed = attributes.instanceSpeed.element(instanceIndex).toVar();
535
- const age = select2(speed.lessThan(0), duration.sub(time.sub(startTime)), time.sub(startTime));
536
- return rotationNode(rot, rotSpeed, age);
537
- }
538
- };
539
- var InstanceScaleNode = class extends THREE2.Node {
540
- constructor() {
541
- super("vec3");
542
- this.updateType = THREE2.NodeUpdateType.OBJECT;
543
- }
544
- setup(frame) {
545
- const mesh = frame.object;
546
- const { attributes, config } = mesh.userData;
547
- const scale = attributes.instance.element(idx7.add(6));
548
- return scaleNode(config.particles.fadeSize, scale, vProgress);
549
- }
550
- };
551
- var InstanceColorNode = class extends THREE2.Node {
552
- constructor() {
553
- super("vec3");
554
- this.updateType = THREE2.NodeUpdateType.OBJECT;
555
- }
556
- setup(frame) {
557
- const mesh = frame.object;
558
- const { attributes, uniforms, config, alphaMapCount } = mesh.userData;
559
- const uAlphaMapCount = uint(alphaMapCount).toVar();
560
- const vAlphaMapUVOffsetX = attributes.instanceAlphaMapUVOffset.element(idx2.add(0));
561
- const vAlphaMapUVOffsetY = attributes.instanceAlphaMapUVOffset.element(idx2.add(1));
562
- return colorNode(
563
- config.particles.colors,
564
- config.particles.intensity,
565
- config.particles.fadeAlpha,
566
- config.particles.fadeAlphaMap,
567
- vProgress,
568
- uniforms.uColorGradient,
569
- uAlphaMapCount,
570
- vAlphaMapUVOffsetX,
571
- vAlphaMapUVOffsetY,
572
- uniforms.alphaMap
573
- );
574
- }
575
- };
576
- function createParticleMaterialTemplate() {
575
+ function createInstancePositionNode(ctx, vProgress) {
576
+ return new class extends THREE2.Node {
577
+ constructor() {
578
+ super("vec3");
579
+ this.updateType = THREE2.NodeUpdateType.NONE;
580
+ }
581
+ setup() {
582
+ const { attributes, uniforms, config, easingIndex } = ctx;
583
+ const uPosition = uniforms.uPosition;
584
+ const _static = float2(config.emitter.static).toVar();
585
+ const pos = vec3(
586
+ attributes.instance.element(idx7.add(0)),
587
+ attributes.instance.element(idx7.add(1)),
588
+ attributes.instance.element(idx7.add(2))
589
+ ).add(uPosition.mul(_static));
590
+ const dir = vec3(
591
+ attributes.instanceDirection.element(idx3.add(0)),
592
+ attributes.instanceDirection.element(idx3.add(1)),
593
+ attributes.instanceDirection.element(idx3.add(2))
594
+ );
595
+ const time = uniforms.uTime;
596
+ const uGravity = vec3(...config.particles.gravity);
597
+ const worldUpRight = bool(config.emitter.worldUpRight);
598
+ const startTime = attributes.instanceLifetime.element(idx2.add(0));
599
+ const duration = attributes.instanceLifetime.element(idx2.add(1));
600
+ const speed = attributes.instanceSpeed.element(instanceIndex).toVar();
601
+ const age = select2(
602
+ speed.lessThan(0),
603
+ duration.sub(time.sub(startTime)),
604
+ time.sub(startTime)
605
+ );
606
+ return positionNode(
607
+ pos,
608
+ age,
609
+ duration,
610
+ vProgress,
611
+ uGravity,
612
+ dir,
613
+ speed,
614
+ worldUpRight,
615
+ int(easingIndex)
616
+ );
617
+ }
618
+ }();
619
+ }
620
+ function createInstanceRotationNode(ctx) {
621
+ return new class extends THREE2.Node {
622
+ constructor() {
623
+ super("float");
624
+ this.updateType = THREE2.NodeUpdateType.NONE;
625
+ }
626
+ setup() {
627
+ const { attributes, uniforms } = ctx;
628
+ const rot = vec3(
629
+ attributes.instance.element(idx7.add(3)),
630
+ attributes.instance.element(idx7.add(4)),
631
+ attributes.instance.element(idx7.add(5))
632
+ );
633
+ const rotSpeed = vec3(
634
+ attributes.instanceRotationSpeed.element(idx3.add(0)),
635
+ attributes.instanceRotationSpeed.element(idx3.add(1)),
636
+ attributes.instanceRotationSpeed.element(idx3.add(2))
637
+ );
638
+ const time = uniforms.uTime;
639
+ const startTime = attributes.instanceLifetime.element(idx2.add(0));
640
+ const duration = attributes.instanceLifetime.element(idx2.add(1));
641
+ const speed = attributes.instanceSpeed.element(instanceIndex).toVar();
642
+ const age = select2(
643
+ speed.lessThan(0),
644
+ duration.sub(time.sub(startTime)),
645
+ time.sub(startTime)
646
+ );
647
+ return rotationNode(rot, rotSpeed, age);
648
+ }
649
+ }();
650
+ }
651
+ function createInstanceScaleNode(ctx, vProgress) {
652
+ return new class extends THREE2.Node {
653
+ constructor() {
654
+ super("float");
655
+ this.updateType = THREE2.NodeUpdateType.NONE;
656
+ }
657
+ setup() {
658
+ const { attributes, config } = ctx;
659
+ const scale = attributes.instance.element(idx7.add(6));
660
+ return scaleNode(config.particles.fadeSize, scale, vProgress);
661
+ }
662
+ }();
663
+ }
664
+ function createInstanceColorNode(ctx, vProgress) {
665
+ return new class extends THREE2.Node {
666
+ constructor() {
667
+ super("vec4");
668
+ this.updateType = THREE2.NodeUpdateType.NONE;
669
+ }
670
+ setup() {
671
+ const { attributes, uniforms, config, alphaMapCount } = ctx;
672
+ const uAlphaMapCount = uint(alphaMapCount).toVar();
673
+ return colorNode(
674
+ config.particles.colors,
675
+ config.particles.intensity,
676
+ config.particles.fadeAlpha,
677
+ config.particles.fadeAlphaMap,
678
+ vProgress,
679
+ uniforms.uColorGradient,
680
+ uAlphaMapCount,
681
+ attributes.instanceAlphaMapUVOffset.element(idx2.add(0)),
682
+ attributes.instanceAlphaMapUVOffset.element(idx2.add(1)),
683
+ uniforms.alphaMap
684
+ );
685
+ }
686
+ }();
687
+ }
688
+ var particleMaterialCounter = 0;
689
+ function createParticleMaterialTemplate(ctx) {
690
+ const materialId = particleMaterialCounter++;
691
+ const vProgress = varyingProperty("float", `vProgress_${materialId}`);
577
692
  const mat = new THREE2.SpriteNodeMaterial();
578
- mat.positionNode = new InstancePositionNode();
579
- mat.rotationNode = new InstanceRotationNode();
580
- mat.scaleNode = new InstanceScaleNode();
581
- mat.colorNode = new InstanceColorNode();
693
+ mat.positionNode = createInstancePositionNode(ctx, vProgress);
694
+ mat.rotationNode = createInstanceRotationNode(ctx);
695
+ mat.scaleNode = createInstanceScaleNode(ctx, vProgress);
696
+ mat.colorNode = createInstanceColorNode(ctx, vProgress);
582
697
  return mat;
583
698
  }
584
699
 
585
700
  // src/lib/behaviors/particle-emitter/gpu/utils.ts
586
- function randFloat(min, max2) {
587
- return Math.random() * (max2 - min) + min;
701
+ function randFloat(min2, max2) {
702
+ return Math.random() * (max2 - min2) + min2;
588
703
  }
589
- function randInt(min, max2) {
590
- return Math.floor(Math.random() * (max2 - min + 1)) + min;
704
+ function randInt(min2, max2) {
705
+ return Math.floor(Math.random() * (max2 - min2 + 1)) + min2;
591
706
  }
592
707
 
593
708
  // src/lib/behaviors/particle-emitter/gpu/particles.ts
709
+ function markStorageDirty(node) {
710
+ if (node.value) {
711
+ node.value.needsUpdate = true;
712
+ }
713
+ }
714
+ function createWhiteCanvasTexture() {
715
+ const canvas = document.createElement("canvas");
716
+ canvas.width = 1;
717
+ canvas.height = 1;
718
+ const ctx = canvas.getContext("2d");
719
+ ctx.fillStyle = "#ffffff";
720
+ ctx.fillRect(0, 0, 1, 1);
721
+ const tex = new THREE3.CanvasTexture(canvas);
722
+ tex.needsUpdate = true;
723
+ return tex;
724
+ }
594
725
  var Particles = class extends THREE3.Object3D {
595
- mesh;
726
+ sprite;
596
727
  /** Base object for positioning the emitter. */
597
728
  base;
598
729
  debugMesh;
@@ -607,10 +738,11 @@ var Particles = class extends THREE3.Object3D {
607
738
  cursor = 0;
608
739
  /** Whether the particle system is currently running. */
609
740
  running = false;
610
- constructor(config, geometry) {
741
+ constructor(config, _geometry) {
611
742
  super();
612
743
  this.name = "Particles";
613
744
  this.type = "Particles";
745
+ this.frustumCulled = false;
614
746
  this.base = new THREE3.Object3D();
615
747
  this.base.name = "Base";
616
748
  this.add(this.base);
@@ -640,7 +772,7 @@ var Particles = class extends THREE3.Object3D {
640
772
  render: {
641
773
  alphaMapSize: r.alphaMapSize ?? 256,
642
774
  alphaMapFilter: r.alphaMapFilter ?? THREE3.LinearFilter,
643
- frustumCulled: r.frustumCulled ?? true,
775
+ frustumCulled: r.frustumCulled ?? false,
644
776
  blendingMode: r.blendingMode ?? THREE3.AdditiveBlending,
645
777
  side: r.side ?? THREE3.FrontSide,
646
778
  depthTest: r.depthTest ?? true
@@ -684,8 +816,7 @@ var Particles = class extends THREE3.Object3D {
684
816
  this.config.render.alphaMapFilter
685
817
  );
686
818
  } else {
687
- const canvas = document.createElement("canvas");
688
- atlas = new THREE3.CanvasTexture(canvas);
819
+ atlas = createWhiteCanvasTexture();
689
820
  }
690
821
  const colorGradientTexture = createColorGradientTexture(this.config.particles.colors, 128);
691
822
  this.uniforms = {
@@ -696,7 +827,6 @@ var Particles = class extends THREE3.Object3D {
696
827
  alphaMap: texture2(atlas),
697
828
  uColorGradient: texture2(colorGradientTexture)
698
829
  };
699
- const defaultGeometry = geometry ?? new THREE3.PlaneGeometry(0.5, 0.5);
700
830
  const count = this.config.particles.count;
701
831
  this.buffers = {
702
832
  instanceLifetime: new Float32Array(count * 2),
@@ -715,19 +845,20 @@ var Particles = class extends THREE3.Object3D {
715
845
  instanceSpeed: instancedArray(this.buffers.instanceSpeed, "float")
716
846
  };
717
847
  this.material = this.createMaterial();
718
- this.mesh = new THREE3.InstancedMesh(defaultGeometry, this.material, count);
719
- this.mesh.userData = {
848
+ this.sprite = new THREE3.Sprite(this.material);
849
+ this.sprite.count = count;
850
+ this.sprite.renderOrder = 10;
851
+ this.add(this.sprite);
852
+ this.sprite.frustumCulled = this.config.render.frustumCulled ?? false;
853
+ }
854
+ createMaterial() {
855
+ const _mat = createParticleMaterialTemplate({
720
856
  attributes: this.attributes,
721
857
  uniforms: this.uniforms,
722
858
  config: this.config,
723
859
  alphaMapCount: this.alphaMapCount,
724
860
  easingIndex: this.easingIndex
725
- };
726
- this.add(this.mesh);
727
- this.mesh.frustumCulled = this.config.render.frustumCulled ?? false;
728
- }
729
- createMaterial() {
730
- const _mat = createParticleMaterialTemplate();
861
+ });
731
862
  _mat.blending = this.config.render.blendingMode;
732
863
  _mat.premultipliedAlpha = this.config.render.blendingMode === THREE3.SubtractiveBlending || this.config.render.blendingMode === THREE3.MultiplyBlending;
733
864
  _mat.depthWrite = false;
@@ -743,8 +874,21 @@ var Particles = class extends THREE3.Object3D {
743
874
  this.cursor = 0;
744
875
  this.emitted = 0;
745
876
  this.visible = true;
746
- this.mesh.visible = true;
747
- this.attributes.instanceLifetime.value.array.fill(0);
877
+ this.sprite.visible = true;
878
+ this.resetDeadSlots();
879
+ this.markAllStorageDirty();
880
+ this._update();
881
+ }
882
+ resetDeadSlots() {
883
+ const count = this.config.particles.count;
884
+ const lifetime = this.buffers.instanceLifetime;
885
+ const speed = this.buffers.instanceSpeed;
886
+ for (let i = 0; i < count; i++) {
887
+ const i2 = i * 2;
888
+ lifetime[i2] = 0;
889
+ lifetime[i2 + 1] = 1e-4;
890
+ speed[i] = -1;
891
+ }
748
892
  }
749
893
  /** Restarts (alias for start). */
750
894
  restart() {
@@ -758,13 +902,13 @@ var Particles = class extends THREE3.Object3D {
758
902
  resume() {
759
903
  this.running = true;
760
904
  this.visible = true;
761
- this.mesh.visible = true;
905
+ this.sprite.visible = true;
762
906
  }
763
907
  /** Stops the particle system and hides it. */
764
908
  stop() {
765
909
  this.running = false;
766
910
  this.visible = false;
767
- this.mesh.visible = false;
911
+ this.sprite.visible = false;
768
912
  }
769
913
  /** Whether emission loops continuously. */
770
914
  get looping() {
@@ -783,16 +927,21 @@ var Particles = class extends THREE3.Object3D {
783
927
  }
784
928
  /** Updates the particle system. Call each frame. */
785
929
  update(delta) {
786
- this.mesh.visible = this.visible;
930
+ this.sprite.visible = this.visible;
787
931
  if (!this.running) return;
788
932
  this._update();
789
933
  this.uniforms.uTime.value += delta;
790
934
  }
935
+ markAllStorageDirty() {
936
+ for (const attr of Object.values(this.attributes)) {
937
+ markStorageDirty(attr);
938
+ }
939
+ }
791
940
  _compute(i) {
792
941
  const { emitter } = this.config;
793
942
  const pos = this.uniforms.uPosition.value;
794
943
  const dynamicFactor = 1 - emitter.static;
795
- const inst = this.attributes.instance.value.array;
944
+ const inst = this.buffers.instance;
796
945
  const i7 = i * 7;
797
946
  inst[i7 + 0] = randFloat(emitter.startPositionMin[0], emitter.startPositionMax[0]) + pos.x * dynamicFactor;
798
947
  inst[i7 + 1] = randFloat(emitter.startPositionMin[1], emitter.startPositionMax[1]) + pos.y * dynamicFactor;
@@ -802,16 +951,16 @@ var Particles = class extends THREE3.Object3D {
802
951
  inst[i7 + 5] = randFloat(emitter.startRotationMin[2], emitter.startRotationMax[2]);
803
952
  inst[i7 + 6] = randFloat(emitter.size[0], emitter.size[1]);
804
953
  const i3 = i * 3;
805
- const dir = this.attributes.instanceDirection.value.array;
954
+ const dir = this.buffers.instanceDirection;
806
955
  dir[i3 + 0] = randFloat(emitter.directionMin[0], emitter.directionMax[0]);
807
956
  dir[i3 + 1] = randFloat(emitter.directionMin[1], emitter.directionMax[1]);
808
957
  dir[i3 + 2] = randFloat(emitter.directionMin[2], emitter.directionMax[2]);
809
- const rotSpeed = this.attributes.instanceRotationSpeed.value.array;
958
+ const rotSpeed = this.buffers.instanceRotationSpeed;
810
959
  rotSpeed[i3 + 0] = randFloat(emitter.rotationSpeedMin[0], emitter.rotationSpeedMax[0]);
811
960
  rotSpeed[i3 + 1] = randFloat(emitter.rotationSpeedMin[1], emitter.rotationSpeedMax[1]);
812
961
  rotSpeed[i3 + 2] = randFloat(emitter.rotationSpeedMin[2], emitter.rotationSpeedMax[2]);
813
962
  const i2 = i * 2;
814
- const lifetime = this.attributes.instanceLifetime.value.array;
963
+ const lifetime = this.buffers.instanceLifetime;
815
964
  lifetime[i2 + 0] = this.uniforms.uTime.value;
816
965
  lifetime[i2 + 1] = randFloat(emitter.lifetime[0], emitter.lifetime[1]);
817
966
  const startCount = this.config.particles.alphaMapsStart?.length ?? 0;
@@ -823,10 +972,10 @@ var Particles = class extends THREE3.Object3D {
823
972
  } else if (startCount > 0) {
824
973
  endIdx = randInt(0, startCount - 1);
825
974
  }
826
- const alphaOffset = this.attributes.instanceAlphaMapUVOffset.value.array;
975
+ const alphaOffset = this.buffers.instanceAlphaMapUVOffset;
827
976
  alphaOffset[i2 + 0] = startIdx;
828
977
  alphaOffset[i2 + 1] = endIdx;
829
- this.attributes.instanceSpeed.value.array[i] = randFloat(emitter.speed[0], emitter.speed[1]);
978
+ this.buffers.instanceSpeed[i] = randFloat(emitter.speed[0], emitter.speed[1]);
830
979
  }
831
980
  _update() {
832
981
  const loop = this.config.emitter.loop;
@@ -849,12 +998,7 @@ var Particles = class extends THREE3.Object3D {
849
998
  for (let _i = this.cursor; _i < this.cursor + rate; _i++) {
850
999
  this._compute(_i % maxParticlesTotal);
851
1000
  }
852
- this.attributes.instance.value.needsUpdate = true;
853
- this.attributes.instanceDirection.value.needsUpdate = true;
854
- this.attributes.instanceRotationSpeed.value.needsUpdate = true;
855
- this.attributes.instanceLifetime.value.needsUpdate = true;
856
- this.attributes.instanceAlphaMapUVOffset.value.needsUpdate = true;
857
- this.attributes.instanceSpeed.value.needsUpdate = true;
1001
+ this.markAllStorageDirty();
858
1002
  if (spawnMode === "time") {
859
1003
  this.cursor += rate;
860
1004
  this.cursor = this.cursor % maxParticlesTotal;
@@ -870,7 +1014,6 @@ var Particles = class extends THREE3.Object3D {
870
1014
  /** Disposes of all resources used by the particle system. */
871
1015
  dispose() {
872
1016
  this.stop();
873
- this.mesh.geometry.dispose();
874
1017
  this.material.dispose();
875
1018
  }
876
1019
  };
@@ -1055,8 +1198,8 @@ function deriveFadeFromSizeCurve(points) {
1055
1198
  function forceToGravity(force) {
1056
1199
  const mid = (range2) => {
1057
1200
  if (range2 === void 0) return 0;
1058
- const [min, max2] = toRange(range2);
1059
- return (min + max2) * 0.5;
1201
+ const [min2, max2] = toRange(range2);
1202
+ return (min2 + max2) * 0.5;
1060
1203
  };
1061
1204
  return [mid(force.x), mid(force.y), mid(force.z)];
1062
1205
  }
@@ -1089,13 +1232,13 @@ function rotationToStart(rotation) {
1089
1232
  if (rotation === void 0) {
1090
1233
  return { min: [0, 0, 0], max: [0, 0, 0] };
1091
1234
  }
1092
- const [min, max2] = toRange(rotation);
1235
+ const [min2, max2] = toRange(rotation);
1093
1236
  const norm = (theta) => theta / Math.PI - 1;
1094
- return { min: [0, 0, norm(min)], max: [0, 0, norm(max2)] };
1237
+ return { min: [0, 0, norm(min2)], max: [0, 0, norm(max2)] };
1095
1238
  }
1096
1239
  function rangeToRotationSpeedZ(rotation) {
1097
- const [min, max2] = toRange(rotation);
1098
- return { min: [0, 0, min], max: [0, 0, max2] };
1240
+ const [min2, max2] = toRange(rotation);
1241
+ return { min: [0, 0, min2], max: [0, 0, max2] };
1099
1242
  }
1100
1243
  function toGpuColorStop(color, stop) {
1101
1244
  return { color: toHexColor(color), stop };
@@ -1297,8 +1440,8 @@ function mixColors(base, overlay, amount) {
1297
1440
  color.lerp(new Color(overlay), clamp(amount, 0, 1));
1298
1441
  return `#${color.getHexString()}`;
1299
1442
  }
1300
- function clamp(value, min, max2) {
1301
- return Math.min(Math.max(value, min), max2);
1443
+ function clamp(value, min2, max2) {
1444
+ return Math.min(Math.max(value, min2), max2);
1302
1445
  }
1303
1446
 
1304
1447
  // src/lib/behaviors/particle-emitter/presets/electricity/arc.ts
@@ -2628,4 +2771,4 @@ export {
2628
2771
  magicPresets,
2629
2772
  waterPresets
2630
2773
  };
2631
- //# sourceMappingURL=chunk-7JJEIADR.js.map
2774
+ //# sourceMappingURL=chunk-USFIJUDN.js.map