@shopware-ag/dive 1.6.3 → 1.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
@@ -1,4 +1,4 @@
1
- import { update as updateTween } from "@tweenjs/tween.js";
1
+ import { Tween, update as updateTween } from "@tweenjs/tween.js";
2
2
  import { DIVERenderer } from "../renderer/Renderer";
3
3
 
4
4
  /**
@@ -8,7 +8,7 @@ import { DIVERenderer } from "../renderer/Renderer";
8
8
  * @module
9
9
  */
10
10
 
11
- export default class DIVEAnimationSystem {
11
+ export class DIVEAnimationSystem {
12
12
  private _renderer: DIVERenderer;
13
13
  private _rendererCallbackId: string;
14
14
 
@@ -16,7 +16,7 @@ export default class DIVEAnimationSystem {
16
16
  this._renderer = renderer;
17
17
 
18
18
  this._rendererCallbackId = this._renderer.AddPreRenderCallback(() => {
19
- this.update();
19
+ this.Update();
20
20
  })
21
21
  }
22
22
 
@@ -24,7 +24,11 @@ export default class DIVEAnimationSystem {
24
24
  this._renderer.RemovePreRenderCallback(this._rendererCallbackId);
25
25
  }
26
26
 
27
- public update(): void {
27
+ public Update(): void {
28
28
  updateTween();
29
29
  }
30
+
31
+ public Animate<T extends object>(object: T): Tween<T> {
32
+ return new Tween<T>(object);
33
+ }
30
34
  }
@@ -1,8 +1,9 @@
1
1
  import { DIVERenderer } from '../../renderer/Renderer';
2
- import DIVEAnimationSystem from '../AnimationSystem';
2
+ import { DIVEAnimationSystem } from '../AnimationSystem';
3
3
 
4
4
  jest.mock('@tweenjs/tween.js', () => {
5
5
  return {
6
+ Tween: jest.fn(() => { }),
6
7
  update: jest.fn(),
7
8
  }
8
9
  });
@@ -28,9 +29,15 @@ describe('dive/animation/DIVEAnimationSystem', () => {
28
29
  expect(anim).toBeDefined();
29
30
  });
30
31
 
32
+ it('should Animate', () => {
33
+ const anim = new DIVEAnimationSystem(mockRenderer);
34
+ const tween = anim.Animate({});
35
+ expect(tween).toBeDefined();
36
+ });
37
+
31
38
  it('should update', () => {
32
39
  const anim = new DIVEAnimationSystem(mockRenderer);
33
- expect(() => anim.update()).not.toThrow();
40
+ expect(() => anim.Update()).not.toThrow();
34
41
  });
35
42
 
36
43
  it('should dispose', () => {
@@ -2,7 +2,8 @@ import { OrbitControls } from "three/examples/jsm/Addons.js";
2
2
  import DIVEPerspectiveCamera from "../camera/PerspectiveCamera.ts";
3
3
  import { DIVERenderer } from "../renderer/Renderer.ts";
4
4
  import { type Box3, MathUtils, Vector3, Vector3Like } from "three";
5
- import { Easing, Tween } from "@tweenjs/tween.js";
5
+ import { Easing } from "@tweenjs/tween.js";
6
+ import { type DIVEAnimationSystem } from "../animation/AnimationSystem.ts";
6
7
 
7
8
  export type DIVEOrbitControlsSettings = {
8
9
  enableDamping: boolean;
@@ -23,6 +24,8 @@ export const DIVEOrbitControlsDefaultSettings: DIVEOrbitControlsSettings = {
23
24
  export default class DIVEOrbitControls extends OrbitControls {
24
25
  public static readonly DEFAULT_ZOOM_FACTOR = 1;
25
26
 
27
+ private _animationSystem: DIVEAnimationSystem;
28
+
26
29
  private last: { pos: Vector3Like, target: Vector3Like } | null = null;
27
30
 
28
31
  private animating: boolean = false;
@@ -34,9 +37,11 @@ export default class DIVEOrbitControls extends OrbitControls {
34
37
  public object: DIVEPerspectiveCamera;
35
38
  public domElement: HTMLCanvasElement;
36
39
 
37
- constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, settings: DIVEOrbitControlsSettings = DIVEOrbitControlsDefaultSettings) {
40
+ constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, animationSystem: DIVEAnimationSystem, settings: DIVEOrbitControlsSettings = DIVEOrbitControlsDefaultSettings) {
38
41
  super(camera, renderer.domElement);
39
42
 
43
+ this._animationSystem = animationSystem;
44
+
40
45
  this.domElement = renderer.domElement;
41
46
 
42
47
  this.object = camera;
@@ -93,12 +98,12 @@ export default class DIVEOrbitControls extends OrbitControls {
93
98
  this.locked = lock;
94
99
  this.enabled = false;
95
100
 
96
- const tweenPos = new Tween(this.object.position)
101
+ const tweenPos = this._animationSystem.Animate(this.object.position)
97
102
  .to(toPosition, duration)
98
103
  .easing(Easing.Quadratic.Out)
99
104
  .start();
100
105
 
101
- const tweenQuat = new Tween(this.target)
106
+ const tweenQuat = this._animationSystem.Animate(this.target)
102
107
  .to(toTarget, duration)
103
108
  .easing(Easing.Quadratic.Out)
104
109
  .onUpdate(() => {
@@ -126,12 +131,12 @@ export default class DIVEOrbitControls extends OrbitControls {
126
131
 
127
132
  const { pos, target } = this.last!;
128
133
 
129
- const tweenPos = new Tween(this.object.position)
134
+ const tweenPos = this._animationSystem.Animate(this.object.position)
130
135
  .to(pos, duration)
131
136
  .easing(Easing.Quadratic.Out)
132
137
  .start();
133
138
 
134
- const tweenQuat = new Tween(this.target)
139
+ const tweenQuat = this._animationSystem.Animate(this.target)
135
140
  .to(target, duration)
136
141
  .easing(Easing.Quadratic.Out)
137
142
  .onUpdate(() => {
@@ -2,6 +2,15 @@ import DIVEOrbitControls from '../OrbitControls';
2
2
  import type DIVEPerspectiveCamera from '../../camera/PerspectiveCamera';
3
3
  import { DIVERenderer } from '../../renderer/Renderer';
4
4
  import { Box3 } from 'three';
5
+ import { DIVEAnimationSystem } from '../../animation/AnimationSystem';
6
+ import { Tween } from '@tweenjs/tween.js';
7
+
8
+ jest.mock('@tweenjs/tween.js', () => {
9
+ return {
10
+ Tween: jest.fn(() => { }),
11
+ update: jest.fn(),
12
+ }
13
+ });
5
14
 
6
15
  jest.mock('three/examples/jsm/Addons.js', () => {
7
16
  return {
@@ -60,6 +69,21 @@ jest.mock('../../renderer/Renderer', () => {
60
69
  });
61
70
  });
62
71
 
72
+ jest.mock('../../animation/AnimationSystem', () => {
73
+ return {
74
+ DIVEAnimationSystem: jest.fn(function () {
75
+ this.domElement = {
76
+ style: {},
77
+ };
78
+ this.Animate = <T extends object>(obj: T) => {
79
+ return new Tween<T>(obj);
80
+ };
81
+
82
+ return this;
83
+ }),
84
+ }
85
+ });
86
+
63
87
  jest.mock('@tweenjs/tween.js', () => {
64
88
  return {
65
89
  Easing: {
@@ -116,72 +140,74 @@ const mockRenderer = {
116
140
  RemovePostRenderCallback: jest.fn(),
117
141
  } as unknown as DIVERenderer;
118
142
 
143
+ const mockAnimSystem = new DIVEAnimationSystem(mockRenderer);
144
+
119
145
  describe('dive/controls/DIVEOrbitControls', () => {
120
146
  afterEach(() => {
121
147
  jest.clearAllMocks();
122
148
  });
123
149
 
124
150
  it('should instantiate', () => {
125
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
151
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
126
152
  expect(controller).toBeDefined();
127
153
  });
128
154
 
129
155
  it('should compute encompassing view', () => {
130
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
156
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
131
157
  expect(() => controller.ComputeEncompassingView(new Box3())).not.toThrow();
132
158
  });
133
159
 
134
160
  it('should zoom in with default value', () => {
135
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
161
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
136
162
  expect(() => controller.ZoomIn()).not.toThrow();
137
163
  });
138
164
 
139
165
  it('should zoom in with custom value', () => {
140
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
166
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
141
167
  expect(() => controller.ZoomIn(10)).not.toThrow();
142
168
  });
143
169
 
144
170
  it('should zoom out with default value', () => {
145
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
171
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
146
172
  expect(() => controller.ZoomOut()).not.toThrow();
147
173
  });
148
174
 
149
175
  it('should zoom out with custom value', () => {
150
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
176
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
151
177
  expect(() => controller.ZoomOut(10)).not.toThrow();
152
178
  });
153
179
 
154
180
  it('should move to', () => {
155
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
181
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
156
182
  expect(() => controller.MoveTo(moveToPos, moveToQuat, moveToDuration, false)).not.toThrow();
157
183
  });
158
184
 
159
185
  it('should revert move to', () => {
160
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
186
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
161
187
  controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true);
162
188
  expect(() => controller.RevertLast(moveToDuration)).not.toThrow();
163
189
  });
164
190
 
165
191
  it('should revert move to without values', () => {
166
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
192
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
167
193
  expect(() => controller.MoveTo(undefined, undefined, moveToDuration, true)).not.toThrow();
168
194
  });
169
195
 
170
196
  it('should revert move to with lock', async () => {
171
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
197
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
172
198
  controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true);
173
199
  expect(() => controller.RevertLast(moveToDuration)).not.toThrow();
174
200
  });
175
201
 
176
202
  it('should move after revert with lock', async () => {
177
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
203
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
178
204
  controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true);
179
205
  controller.RevertLast(moveToDuration);
180
206
  expect(() => controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true)).not.toThrow();
181
207
  });
182
208
 
183
209
  it('should catch multiple move tos', () => {
184
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
210
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
185
211
  controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true);
186
212
  controller.RevertLast(moveToDuration);
187
213
  expect(() => controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true)).not.toThrow();
@@ -191,7 +217,7 @@ describe('dive/controls/DIVEOrbitControls', () => {
191
217
  });
192
218
 
193
219
  it('should catch multiple reverts', () => {
194
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
220
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
195
221
  controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true);
196
222
  expect(() => controller.RevertLast(moveToDuration)).not.toThrow();
197
223
  expect(() => controller.RevertLast(moveToDuration)).not.toThrow();
@@ -199,7 +225,7 @@ describe('dive/controls/DIVEOrbitControls', () => {
199
225
  });
200
226
 
201
227
  it('should execute preRenderCallback', () => {
202
- const controller = new DIVEOrbitControls(mockCamera, mockRenderer);
228
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
203
229
  controller.MoveTo(moveToPos, moveToQuat, moveToDuration, true);
204
230
  expect(() => controller['preRenderCallback']()).not.toThrow();
205
231
  controller['locked'] = true;
package/src/dive.ts CHANGED
@@ -4,7 +4,7 @@ import DIVEPerspectiveCamera, { DIVEPerspectiveCameraDefaultSettings, DIVEPerspe
4
4
  import DIVEOrbitControls, { DIVEOrbitControlsDefaultSettings, DIVEOrbitControlsSettings } from "./controls/OrbitControls.ts";
5
5
  import DIVEToolbox from "./toolbox/Toolbox.ts";
6
6
  import DIVECommunication from "./com/Communication.ts";
7
- import DIVEAnimationSystem from "./animation/AnimationSystem.ts";
7
+ import { DIVEAnimationSystem } from "./animation/AnimationSystem.ts";
8
8
  import DIVEAxisCamera from "./axiscamera/AxisCamera.ts";
9
9
  import { getObjectDelta } from "./helper/getObjectDelta/getObjectDelta.ts";
10
10
 
@@ -133,7 +133,7 @@ export default class DIVE {
133
133
  private communication: DIVECommunication;
134
134
 
135
135
  // additional components
136
- private animationSystem: DIVEAnimationSystem | null;
136
+ private animationSystem: DIVEAnimationSystem;
137
137
  private axisCamera: DIVEAxisCamera | null;
138
138
 
139
139
  // getters
@@ -194,12 +194,14 @@ export default class DIVE {
194
194
  this.renderer = new DIVERenderer(this._settings.renderer);
195
195
  this.scene = new DIVEScene();
196
196
  this.perspectiveCamera = new DIVEPerspectiveCamera(this._settings.perspectiveCamera);
197
- this.orbitControls = new DIVEOrbitControls(this.perspectiveCamera, this.renderer, this._settings.orbitControls);
197
+
198
+ // initialize animation system
199
+ this.animationSystem = new DIVEAnimationSystem(this.renderer);
200
+
201
+ this.orbitControls = new DIVEOrbitControls(this.perspectiveCamera, this.renderer, this.animationSystem, this._settings.orbitControls);
198
202
  this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
199
203
  this.communication = new DIVECommunication(this.renderer, this.scene, this.orbitControls, this.toolbox);
200
204
 
201
- // initialize animation system
202
- this.animationSystem = null;
203
205
 
204
206
  // initialize axis camera
205
207
  if (this._settings.displayAxes) {
@@ -228,6 +230,7 @@ export default class DIVE {
228
230
  this.removeResizeObserver();
229
231
  this.renderer.Dispose();
230
232
  this.axisCamera?.Dispose();
233
+ this.animationSystem.Dispose();
231
234
  this.toolbox.Dispose();
232
235
  this.communication.DestroyInstance();
233
236
  }
@@ -4,6 +4,7 @@ import DIVEScene from '../../scene/Scene';
4
4
  import DIVEPerspectiveCamera, { DIVEPerspectiveCameraDefaultSettings } from '../../camera/PerspectiveCamera';
5
5
  import { COMPov } from '../../com';
6
6
  import DIVEOrbitControls from '../../controls/OrbitControls';
7
+ import { DIVEAnimationSystem } from '../../animation/AnimationSystem';
7
8
 
8
9
  /**
9
10
  * @jest-environment jsdom
@@ -83,12 +84,29 @@ jest.mock('../../renderer/Renderer', () => {
83
84
  }
84
85
  });
85
86
 
87
+ jest.mock('../../animation/AnimationSystem', () => {
88
+ return {
89
+ DIVEAnimationSystem: jest.fn(function () {
90
+ this.domElement = {
91
+ toDataURL: mock_toDataURL,
92
+ }
93
+ this.render = mock_render;
94
+ this.OnResize = jest.fn();
95
+ this.AddPreRenderCallback = jest.fn((callback) => {
96
+ callback();
97
+ return 'id';
98
+ });
99
+ return this;
100
+ })
101
+ }
102
+ });
103
+
86
104
  let mediaCreator: DIVEMediaCreator;
87
105
 
88
106
  describe('dive/mediacreator/DIVEMediaCreator', () => {
89
107
  beforeEach(() => {
90
108
  jest.clearAllMocks();
91
- mediaCreator = new DIVEMediaCreator(new DIVERenderer(), new DIVEScene(), new DIVEOrbitControls(new DIVEPerspectiveCamera(DIVEPerspectiveCameraDefaultSettings), new DIVERenderer()));
109
+ mediaCreator = new DIVEMediaCreator(new DIVERenderer(), new DIVEScene(), new DIVEOrbitControls(new DIVEPerspectiveCamera(DIVEPerspectiveCameraDefaultSettings), new DIVERenderer(), new DIVEAnimationSystem(new DIVERenderer())));
92
110
  });
93
111
 
94
112
  it('should instantiate', () => {
@@ -6,6 +6,15 @@ import { DIVESelectable } from '../../../interface/Selectable';
6
6
  import type DIVEPerspectiveCamera from '../../../camera/PerspectiveCamera';
7
7
  import { type Object3D } from 'three';
8
8
  import { type DIVEBaseTool } from '../../BaseTool';
9
+ import { DIVEAnimationSystem } from '../../../animation/AnimationSystem';
10
+ import { Tween } from '@tweenjs/tween.js';
11
+
12
+ jest.mock('@tweenjs/tween.js', () => {
13
+ return {
14
+ Tween: jest.fn(() => { }),
15
+ update: jest.fn(),
16
+ }
17
+ });
9
18
 
10
19
  jest.mock('../../../renderer/Renderer', () => {
11
20
  return jest.fn(function () {
@@ -39,6 +48,22 @@ jest.mock('../../../controls/OrbitControls', () => {
39
48
  });
40
49
  });
41
50
 
51
+
52
+ jest.mock('../../../animation/AnimationSystem', () => {
53
+ return {
54
+ DIVEAnimationSystem: jest.fn(function () {
55
+ this.domElement = {
56
+ style: {},
57
+ };
58
+ this.Animate = <T extends object>(obj: T) => {
59
+ return new Tween<T>(obj);
60
+ };
61
+
62
+ return this;
63
+ }),
64
+ }
65
+ });
66
+
42
67
  jest.mock('../../../scene/Scene', () => {
43
68
  return jest.fn(function () {
44
69
  this.add = jest.fn();
@@ -115,7 +140,8 @@ const mockRenderer = {
115
140
  OnResize: jest.fn(),
116
141
  } as unknown as DIVERenderer;
117
142
  const mockScene: DIVEScene = new DIVEScene();
118
- const mockController: DIVEOrbitControls = new DIVEOrbitControls(mockCamera, mockRenderer);
143
+ const mockAnimSystem = new DIVEAnimationSystem(mockRenderer);
144
+ const mockController: DIVEOrbitControls = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
119
145
 
120
146
  describe('dive/toolbox/select/DIVESelectTool', () => {
121
147
  it('should test if it is SelectTool', () => {
@@ -4,6 +4,15 @@ import DIVEOrbitControls from '../../../controls/OrbitControls';
4
4
  import DIVEPerspectiveCamera from '../../../camera/PerspectiveCamera';
5
5
  import { DIVERenderer } from '../../../renderer/Renderer';
6
6
  import { type DIVEBaseTool } from '../../BaseTool';
7
+ import { Tween } from '@tweenjs/tween.js';
8
+ import { DIVEAnimationSystem } from '../../../animation/AnimationSystem';
9
+
10
+ jest.mock('@tweenjs/tween.js', () => {
11
+ return {
12
+ Tween: jest.fn(() => { }),
13
+ update: jest.fn(),
14
+ }
15
+ });
7
16
 
8
17
  jest.mock('../../../renderer/Renderer', () => {
9
18
  return jest.fn(function () {
@@ -49,6 +58,21 @@ jest.mock('../../../scene/Scene', () => {
49
58
  });
50
59
  });
51
60
 
61
+ jest.mock('../../../animation/AnimationSystem', () => {
62
+ return {
63
+ DIVEAnimationSystem: jest.fn(function () {
64
+ this.domElement = {
65
+ style: {},
66
+ };
67
+ this.Animate = <T extends object>(obj: T) => {
68
+ return new Tween<T>(obj);
69
+ };
70
+
71
+ return this;
72
+ }),
73
+ }
74
+ });
75
+
52
76
  const mock_intersectObjects = jest.fn().mockReturnValue([]);
53
77
 
54
78
  jest.mock('three', () => {
@@ -126,7 +150,8 @@ const mockRenderer = {
126
150
  RemovePostRenderCallback: jest.fn(),
127
151
  } as unknown as DIVERenderer;
128
152
  const mockScene: DIVEScene = new DIVEScene();
129
- const mockController: DIVEOrbitControls = new DIVEOrbitControls(mockCamera, mockRenderer);
153
+ const mockAnimSystem = new DIVEAnimationSystem(mockRenderer);
154
+ const mockController: DIVEOrbitControls = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
130
155
 
131
156
  describe('dive/toolbox/select/DIVETransformTool', () => {
132
157
  it('should test if it is SelectTool', () => {