@shopware-ag/dive 1.6.3 → 1.6.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.
package/build/dive.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Mesh, ColorRepresentation, Object3D, Intersection, Vector2, Raycaster, Vector3 } from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/Addons.js';
3
+ import { Tween } from '@tweenjs/tween.js';
3
4
  import { TransformControls } from 'three/examples/jsm/Addons';
4
5
 
5
6
  type DIVERendererSettings = {
@@ -87,6 +88,21 @@ declare class DIVEPerspectiveCamera extends PerspectiveCamera {
87
88
  SetCameraLayer(layer: 'LIVE' | 'EDITOR'): void;
88
89
  }
89
90
 
91
+ /**
92
+ * Updates all animations.
93
+ * DIVE uses Tween.js to handle animations.
94
+ *
95
+ * @module
96
+ */
97
+ declare class DIVEAnimationSystem {
98
+ private _renderer;
99
+ private _rendererCallbackId;
100
+ constructor(renderer: DIVERenderer);
101
+ Dispose(): void;
102
+ Update(): void;
103
+ Animate<T extends object>(object: T): Tween<T>;
104
+ }
105
+
90
106
  type DIVEOrbitControlsSettings = {
91
107
  enableDamping: boolean;
92
108
  dampingFactor: number;
@@ -98,6 +114,7 @@ type DIVEOrbitControlsSettings = {
98
114
  */
99
115
  declare class DIVEOrbitControls extends OrbitControls {
100
116
  static readonly DEFAULT_ZOOM_FACTOR = 1;
117
+ private _animationSystem;
101
118
  private last;
102
119
  private animating;
103
120
  private locked;
@@ -105,7 +122,9 @@ declare class DIVEOrbitControls extends OrbitControls {
105
122
  private stopRevertLast;
106
123
  object: DIVEPerspectiveCamera;
107
124
  domElement: HTMLCanvasElement;
108
- constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, settings?: DIVEOrbitControlsSettings);
125
+ private _removePreRenderCallback;
126
+ constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, animationSystem: DIVEAnimationSystem, settings?: DIVEOrbitControlsSettings);
127
+ Dispose(): void;
109
128
  ComputeEncompassingView(bb: Box3): {
110
129
  position: Vector3Like;
111
130
  target: Vector3Like;
@@ -588,7 +607,8 @@ type Unsubscribe = () => boolean;
588
607
  declare class DIVECommunication {
589
608
  private static __instances;
590
609
  static get(id: string): DIVECommunication | undefined;
591
- private id;
610
+ private _id;
611
+ get id(): string;
592
612
  private renderer;
593
613
  private scene;
594
614
  private controller;
package/build/dive.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Mesh, ColorRepresentation, Object3D, Intersection, Vector2, Raycaster, Vector3 } from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/Addons.js';
3
+ import { Tween } from '@tweenjs/tween.js';
3
4
  import { TransformControls } from 'three/examples/jsm/Addons';
4
5
 
5
6
  type DIVERendererSettings = {
@@ -87,6 +88,21 @@ declare class DIVEPerspectiveCamera extends PerspectiveCamera {
87
88
  SetCameraLayer(layer: 'LIVE' | 'EDITOR'): void;
88
89
  }
89
90
 
91
+ /**
92
+ * Updates all animations.
93
+ * DIVE uses Tween.js to handle animations.
94
+ *
95
+ * @module
96
+ */
97
+ declare class DIVEAnimationSystem {
98
+ private _renderer;
99
+ private _rendererCallbackId;
100
+ constructor(renderer: DIVERenderer);
101
+ Dispose(): void;
102
+ Update(): void;
103
+ Animate<T extends object>(object: T): Tween<T>;
104
+ }
105
+
90
106
  type DIVEOrbitControlsSettings = {
91
107
  enableDamping: boolean;
92
108
  dampingFactor: number;
@@ -98,6 +114,7 @@ type DIVEOrbitControlsSettings = {
98
114
  */
99
115
  declare class DIVEOrbitControls extends OrbitControls {
100
116
  static readonly DEFAULT_ZOOM_FACTOR = 1;
117
+ private _animationSystem;
101
118
  private last;
102
119
  private animating;
103
120
  private locked;
@@ -105,7 +122,9 @@ declare class DIVEOrbitControls extends OrbitControls {
105
122
  private stopRevertLast;
106
123
  object: DIVEPerspectiveCamera;
107
124
  domElement: HTMLCanvasElement;
108
- constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, settings?: DIVEOrbitControlsSettings);
125
+ private _removePreRenderCallback;
126
+ constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, animationSystem: DIVEAnimationSystem, settings?: DIVEOrbitControlsSettings);
127
+ Dispose(): void;
109
128
  ComputeEncompassingView(bb: Box3): {
110
129
  position: Vector3Like;
111
130
  target: Vector3Like;
@@ -588,7 +607,8 @@ type Unsubscribe = () => boolean;
588
607
  declare class DIVECommunication {
589
608
  private static __instances;
590
609
  static get(id: string): DIVECommunication | undefined;
591
- private id;
610
+ private _id;
611
+ get id(): string;
592
612
  private renderer;
593
613
  private scene;
594
614
  private controller;
package/build/dive.js CHANGED
@@ -683,7 +683,7 @@ var _DIVECommunication = class _DIVECommunication {
683
683
  this.registered = /* @__PURE__ */ new Map();
684
684
  // private listeners: { [key: string]: EventListener[] } = {};
685
685
  this.listeners = /* @__PURE__ */ new Map();
686
- this.id = generateUUID();
686
+ this._id = generateUUID();
687
687
  this.renderer = renderer;
688
688
  this.scene = scene;
689
689
  this.controller = controls;
@@ -692,8 +692,13 @@ var _DIVECommunication = class _DIVECommunication {
692
692
  _DIVECommunication.__instances.push(this);
693
693
  }
694
694
  static get(id) {
695
+ const fromComID = this.__instances.find((instance) => instance.id === id);
696
+ if (fromComID) return fromComID;
695
697
  return this.__instances.find((instance) => Array.from(instance.registered.values()).find((object) => object.id === id));
696
698
  }
699
+ get id() {
700
+ return this._id;
701
+ }
697
702
  get mediaGenerator() {
698
703
  if (!this._mediaGenerator) {
699
704
  const DIVEMediaCreator2 = (init_MediaCreator(), __toCommonJS(MediaCreator_exports)).DIVEMediaCreator;
@@ -1549,13 +1554,13 @@ init_PerspectiveCamera();
1549
1554
  // src/controls/OrbitControls.ts
1550
1555
  import { OrbitControls } from "three/examples/jsm/Addons.js";
1551
1556
  import { MathUtils as MathUtils2, Vector3 as Vector33 } from "three";
1552
- import { Easing, Tween } from "@tweenjs/tween.js";
1557
+ import { Easing } from "@tweenjs/tween.js";
1553
1558
  var DIVEOrbitControlsDefaultSettings = {
1554
1559
  enableDamping: true,
1555
1560
  dampingFactor: 0.04
1556
1561
  };
1557
1562
  var _DIVEOrbitControls = class _DIVEOrbitControls extends OrbitControls {
1558
- constructor(camera, renderer, settings = DIVEOrbitControlsDefaultSettings) {
1563
+ constructor(camera, renderer, animationSystem, settings = DIVEOrbitControlsDefaultSettings) {
1559
1564
  super(camera, renderer.domElement);
1560
1565
  this.last = null;
1561
1566
  this.animating = false;
@@ -1564,18 +1569,28 @@ var _DIVEOrbitControls = class _DIVEOrbitControls extends OrbitControls {
1564
1569
  };
1565
1570
  this.stopRevertLast = () => {
1566
1571
  };
1572
+ this._removePreRenderCallback = () => {
1573
+ };
1567
1574
  this.preRenderCallback = () => {
1568
1575
  if (this.locked) return;
1569
1576
  this.update();
1570
1577
  };
1578
+ this._animationSystem = animationSystem;
1571
1579
  this.domElement = renderer.domElement;
1572
1580
  this.object = camera;
1573
- renderer.AddPreRenderCallback(() => {
1581
+ const id = renderer.AddPreRenderCallback(() => {
1574
1582
  this.preRenderCallback();
1575
1583
  });
1584
+ this._removePreRenderCallback = () => {
1585
+ renderer.RemovePreRenderCallback(id);
1586
+ };
1576
1587
  this.enableDamping = settings.enableDamping;
1577
1588
  this.dampingFactor = settings.dampingFactor;
1578
1589
  }
1590
+ Dispose() {
1591
+ this._removePreRenderCallback();
1592
+ this.dispose();
1593
+ }
1579
1594
  ComputeEncompassingView(bb) {
1580
1595
  const center = bb.getCenter(new Vector33());
1581
1596
  const size = bb.getSize(new Vector33());
@@ -1611,8 +1626,8 @@ var _DIVEOrbitControls = class _DIVEOrbitControls extends OrbitControls {
1611
1626
  this.animating = duration > 0;
1612
1627
  this.locked = lock;
1613
1628
  this.enabled = false;
1614
- const tweenPos = new Tween(this.object.position).to(toPosition, duration).easing(Easing.Quadratic.Out).start();
1615
- const tweenQuat = new Tween(this.target).to(toTarget, duration).easing(Easing.Quadratic.Out).onUpdate(() => {
1629
+ const tweenPos = this._animationSystem.Animate(this.object.position).to(toPosition, duration).easing(Easing.Quadratic.Out).start();
1630
+ const tweenQuat = this._animationSystem.Animate(this.target).to(toTarget, duration).easing(Easing.Quadratic.Out).onUpdate(() => {
1616
1631
  this.object.lookAt(this.target);
1617
1632
  }).onComplete(() => {
1618
1633
  this.animating = false;
@@ -1629,8 +1644,8 @@ var _DIVEOrbitControls = class _DIVEOrbitControls extends OrbitControls {
1629
1644
  this.animating = duration > 0;
1630
1645
  this.enabled = false;
1631
1646
  const { pos, target } = this.last;
1632
- const tweenPos = new Tween(this.object.position).to(pos, duration).easing(Easing.Quadratic.Out).start();
1633
- const tweenQuat = new Tween(this.target).to(target, duration).easing(Easing.Quadratic.Out).onUpdate(() => {
1647
+ const tweenPos = this._animationSystem.Animate(this.object.position).to(pos, duration).easing(Easing.Quadratic.Out).start();
1648
+ const tweenQuat = this._animationSystem.Animate(this.target).to(target, duration).easing(Easing.Quadratic.Out).onUpdate(() => {
1634
1649
  this.object.lookAt(this.target);
1635
1650
  }).onComplete(() => {
1636
1651
  this.animating = false;
@@ -1724,6 +1739,26 @@ var DIVEToolbox = class {
1724
1739
  };
1725
1740
  DIVEToolbox.DefaultTool = "select";
1726
1741
 
1742
+ // src/animation/AnimationSystem.ts
1743
+ import { Tween, update as updateTween } from "@tweenjs/tween.js";
1744
+ var DIVEAnimationSystem = class {
1745
+ constructor(renderer) {
1746
+ this._renderer = renderer;
1747
+ this._rendererCallbackId = this._renderer.AddPreRenderCallback(() => {
1748
+ this.Update();
1749
+ });
1750
+ }
1751
+ Dispose() {
1752
+ this._renderer.RemovePreRenderCallback(this._rendererCallbackId);
1753
+ }
1754
+ Update() {
1755
+ updateTween();
1756
+ }
1757
+ Animate(object) {
1758
+ return new Tween(object);
1759
+ }
1760
+ };
1761
+
1727
1762
  // src/axiscamera/AxisCamera.ts
1728
1763
  init_VisibilityLayerMask();
1729
1764
  import { AxesHelper, Color as Color7, Matrix4, OrthographicCamera, Vector4 } from "three";
@@ -2005,10 +2040,10 @@ var DIVE = class _DIVE {
2005
2040
  this.renderer = new DIVERenderer(this._settings.renderer);
2006
2041
  this.scene = new DIVEScene();
2007
2042
  this.perspectiveCamera = new DIVEPerspectiveCamera(this._settings.perspectiveCamera);
2008
- this.orbitControls = new DIVEOrbitControls(this.perspectiveCamera, this.renderer, this._settings.orbitControls);
2043
+ this.animationSystem = new DIVEAnimationSystem(this.renderer);
2044
+ this.orbitControls = new DIVEOrbitControls(this.perspectiveCamera, this.renderer, this.animationSystem, this._settings.orbitControls);
2009
2045
  this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
2010
2046
  this.communication = new DIVECommunication(this.renderer, this.scene, this.orbitControls, this.toolbox);
2011
- this.animationSystem = null;
2012
2047
  if (this._settings.displayAxes) {
2013
2048
  this.axisCamera = new DIVEAxisCamera(this.renderer, this.scene, this.orbitControls);
2014
2049
  } else {
@@ -2028,7 +2063,9 @@ var DIVE = class _DIVE {
2028
2063
  var _a;
2029
2064
  this.removeResizeObserver();
2030
2065
  this.renderer.Dispose();
2066
+ this.orbitControls.Dispose();
2031
2067
  (_a = this.axisCamera) == null ? void 0 : _a.Dispose();
2068
+ this.animationSystem.Dispose();
2032
2069
  this.toolbox.Dispose();
2033
2070
  this.communication.DestroyInstance();
2034
2071
  }