@polarfront-lab/ionian 1.3.0 → 1.4.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
@@ -142,6 +142,9 @@ class AssetService {
142
142
  getTextures() {
143
143
  return Array.from(this.textures.values());
144
144
  }
145
+ hasMatcap(id) {
146
+ return this.textures.has(id);
147
+ }
145
148
  /**
146
149
  * Loads a mesh asynchronously.
147
150
  * @param id - The ID of the mesh.
@@ -1572,6 +1575,30 @@ class ParticlesEngine {
1572
1575
  this.engineState.destinationMatcapID = matcapID;
1573
1576
  this.instancedMeshManager.setDestinationMatcap(this.assetService.getMatcap(matcapID));
1574
1577
  }
1578
+ setOriginColor(color, override = false) {
1579
+ if (override) this.eventEmitter.emit("transitionCancelled", { type: "matcap" });
1580
+ this.instancedMeshManager.setOriginColor(color);
1581
+ }
1582
+ setDestinationColor(color, override = false) {
1583
+ if (override) this.eventEmitter.emit("transitionCancelled", { type: "matcap" });
1584
+ this.instancedMeshManager.setDestinationColor(color);
1585
+ }
1586
+ setOriginTexture(id, override = false) {
1587
+ if (override) this.eventEmitter.emit("transitionCancelled", { type: "matcap" });
1588
+ if (typeof id === "string" && this.assetService.hasMatcap(id)) {
1589
+ this.setOriginMatcap(id);
1590
+ } else {
1591
+ this.setOriginColor(id);
1592
+ }
1593
+ }
1594
+ setDestinationTexture(id, override = false) {
1595
+ if (override) this.eventEmitter.emit("transitionCancelled", { type: "matcap" });
1596
+ if (typeof id === "string" && this.assetService.hasMatcap(id)) {
1597
+ this.setDestinationMatcap(id);
1598
+ } else {
1599
+ this.setDestinationColor(id);
1600
+ }
1601
+ }
1575
1602
  setMatcapProgress(progress, override = false) {
1576
1603
  if (override) this.eventEmitter.emit("transitionCancelled", { type: "matcap" });
1577
1604
  this.engineState.matcapTransitionProgress = progress;
@@ -1592,7 +1619,12 @@ class ParticlesEngine {
1592
1619
  this.eventEmitter.emit("invalidRequest", { message: `Mesh with id "${this.engineState.destinationMeshID}" does not exist` });
1593
1620
  return;
1594
1621
  }
1595
- this.dataTextureManager.getDataTexture(originMesh).then((texture) => this.simulationRendererService.setOriginDataTexture({ dataTexture: texture, textureSize: size }));
1622
+ this.dataTextureManager.getDataTexture(originMesh).then(
1623
+ (texture) => this.simulationRendererService.setOriginDataTexture({
1624
+ dataTexture: texture,
1625
+ textureSize: size
1626
+ })
1627
+ );
1596
1628
  this.dataTextureManager.getDataTexture(destinationMesh).then(
1597
1629
  (texture) => this.simulationRendererService.setDestinationDataTexture({
1598
1630
  dataTexture: texture,
@@ -1665,6 +1697,24 @@ class ParticlesEngine {
1665
1697
  }
1666
1698
  );
1667
1699
  }
1700
+ scheduleTextureTransition(origin, destination, options) {
1701
+ const easing = (options == null ? void 0 : options.easing) ?? linear;
1702
+ const duration = (options == null ? void 0 : options.duration) ?? 1e3;
1703
+ if (options == null ? void 0 : options.override) {
1704
+ this.eventEmitter.emit("transitionCancelled", { type: "matcap" });
1705
+ }
1706
+ this.transitionService.enqueue(
1707
+ "matcap",
1708
+ { easing, duration },
1709
+ {
1710
+ onTransitionBegin: () => {
1711
+ this.setOriginTexture(origin);
1712
+ this.setDestinationTexture(destination);
1713
+ this.setMatcapProgress(0);
1714
+ }
1715
+ }
1716
+ );
1717
+ }
1668
1718
  handleServiceStateUpdated({ type, state }) {
1669
1719
  this.serviceStates[type] = state;
1670
1720
  }
@@ -1726,12 +1776,6 @@ class ParticlesEngine {
1726
1776
  handleInteractionPositionUpdated({ position }) {
1727
1777
  this.simulationRendererService.setInteractionPosition(position);
1728
1778
  }
1729
- setOriginColor(color) {
1730
- this.instancedMeshManager.setOriginColor(color);
1731
- }
1732
- setDestinationColor(color) {
1733
- this.instancedMeshManager.setDestinationColor(color);
1734
- }
1735
1779
  }
1736
1780
  export {
1737
1781
  ParticlesEngine