@polarfront-lab/ionian 1.4.0 → 1.5.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.
package/dist/ionian.js CHANGED
@@ -726,6 +726,7 @@ class IntersectionService {
726
726
  * @param destinationGeometry The destination geometry.
727
727
  */
728
728
  constructor(eventEmitter, camera, originGeometry, destinationGeometry) {
729
+ __publicField(this, "active", true);
729
730
  __publicField(this, "raycaster", new THREE.Raycaster());
730
731
  __publicField(this, "mousePosition", new THREE.Vector2());
731
732
  __publicField(this, "camera");
@@ -745,6 +746,9 @@ class IntersectionService {
745
746
  this.destinationGeometry = destinationGeometry;
746
747
  this.geometryNeedsUpdate = true;
747
748
  }
749
+ setActive(active) {
750
+ this.active = active;
751
+ }
748
752
  getIntersectionMesh() {
749
753
  return this.intersectionMesh;
750
754
  }
@@ -791,7 +795,7 @@ class IntersectionService {
791
795
  * Set the mouse position.
792
796
  * @param mousePosition
793
797
  */
794
- setMousePosition(mousePosition) {
798
+ setPointerPosition(mousePosition) {
795
799
  if (mousePosition) this.mousePosition.copy(mousePosition);
796
800
  }
797
801
  /**
@@ -799,6 +803,7 @@ class IntersectionService {
799
803
  * @returns The intersection point or undefined if no intersection was found.
800
804
  */
801
805
  calculate(instancedMesh) {
806
+ if (!this.active) return;
802
807
  this.updateIntersectionMesh(instancedMesh);
803
808
  if (!this.camera) return;
804
809
  if (this.geometryNeedsUpdate) {
@@ -1501,20 +1506,22 @@ class ParticlesEngine {
1501
1506
  __publicField(this, "transitionService");
1502
1507
  __publicField(this, "engineState");
1503
1508
  __publicField(this, "intersectionService");
1509
+ const { scene, renderer, camera, textureSize, useIntersection = true } = params;
1504
1510
  this.eventEmitter = new DefaultEventEmitter();
1505
- this.serviceStates = this.initialServiceStates();
1511
+ this.serviceStates = this.getInitialServiceStates();
1506
1512
  this.eventEmitter.on("serviceStateUpdated", this.handleServiceStateUpdated.bind(this));
1507
- this.scene = params.scene;
1508
- this.renderer = params.renderer;
1509
- this.engineState = this.initialEngineState(params.textureSize);
1513
+ this.scene = scene;
1514
+ this.renderer = renderer;
1515
+ this.engineState = this.initialEngineState(params);
1510
1516
  this.assetService = new AssetService(this.eventEmitter);
1511
1517
  this.transitionService = new TransitionService(this.eventEmitter);
1512
- this.dataTextureManager = new DataTextureService(this.eventEmitter, params.textureSize);
1513
- this.simulationRendererService = new SimulationRendererService(this.eventEmitter, params.textureSize, this.renderer);
1514
- this.instancedMeshManager = new InstancedMeshManager(params.textureSize);
1518
+ this.dataTextureManager = new DataTextureService(this.eventEmitter, textureSize);
1519
+ this.simulationRendererService = new SimulationRendererService(this.eventEmitter, textureSize, this.renderer);
1520
+ this.instancedMeshManager = new InstancedMeshManager(textureSize);
1515
1521
  this.instancedMeshManager.useMatcapMaterial();
1516
1522
  this.scene.add(this.instancedMeshManager.getMesh());
1517
- this.intersectionService = new IntersectionService(this.eventEmitter, params.camera);
1523
+ this.intersectionService = new IntersectionService(this.eventEmitter, camera);
1524
+ if (!useIntersection) this.intersectionService.setActive(false);
1518
1525
  this.eventEmitter.on("transitionProgressed", this.handleTransitionProgress.bind(this));
1519
1526
  this.eventEmitter.on("interactionPositionUpdated", this.handleInteractionPositionUpdated.bind(this));
1520
1527
  }
@@ -1651,9 +1658,18 @@ class ParticlesEngine {
1651
1658
  async fetchAndRegisterMatcap(id, url) {
1652
1659
  return await this.assetService.loadTextureAsync(id, url);
1653
1660
  }
1661
+ useIntersect(use) {
1662
+ this.intersectionService.setActive(use);
1663
+ this.engineState.useIntersect = use;
1664
+ if (!use) {
1665
+ this.engineState.pointerPosition = { x: -99999999, y: -99999999 };
1666
+ this.intersectionService.setPointerPosition(this.engineState.pointerPosition);
1667
+ }
1668
+ }
1654
1669
  setPointerPosition(position) {
1670
+ if (!this.engineState.useIntersect) return;
1655
1671
  this.engineState.pointerPosition = position;
1656
- this.intersectionService.setMousePosition(position);
1672
+ this.intersectionService.setPointerPosition(position);
1657
1673
  }
1658
1674
  setGeometrySize(geometrySize) {
1659
1675
  this.engineState.instanceGeometryScale = geometrySize;
@@ -1738,9 +1754,9 @@ class ParticlesEngine {
1738
1754
  this.assetService.dispose();
1739
1755
  this.dataTextureManager.dispose();
1740
1756
  }
1741
- initialEngineState(textureSize) {
1757
+ initialEngineState(params) {
1742
1758
  return {
1743
- textureSize,
1759
+ textureSize: params.textureSize,
1744
1760
  originMeshID: "",
1745
1761
  destinationMeshID: "",
1746
1762
  dataTextureTransitionProgress: 0,
@@ -1751,10 +1767,11 @@ class ParticlesEngine {
1751
1767
  positionalTractionForce: 0.1,
1752
1768
  maxRepelDistance: 0.3,
1753
1769
  pointerPosition: { x: 0, y: 0 },
1754
- instanceGeometryScale: { x: 1, y: 1, z: 1 }
1770
+ instanceGeometryScale: { x: 1, y: 1, z: 1 },
1771
+ useIntersect: params.useIntersection ?? true
1755
1772
  };
1756
1773
  }
1757
- initialServiceStates() {
1774
+ getInitialServiceStates() {
1758
1775
  return {
1759
1776
  "data-texture": "created",
1760
1777
  "instanced-mesh": "created",