@shopware-ag/dive 1.6.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
@@ -137,6 +137,7 @@ jest.mock('../controls/OrbitControls.ts', () => {
137
137
  id: undefined,
138
138
  }
139
139
  this.removeFromParent = jest.fn();
140
+ this.Dispose = jest.fn();
140
141
  return this;
141
142
  });
142
143
  });
@@ -41,10 +41,16 @@ export default class DIVECommunication {
41
41
  private static __instances: DIVECommunication[] = [];
42
42
 
43
43
  public static get(id: string): DIVECommunication | undefined {
44
+ const fromComID = this.__instances.find((instance) => instance.id === id);
45
+ if (fromComID) return fromComID;
44
46
  return this.__instances.find((instance) => Array.from(instance.registered.values()).find((object) => object.id === id));
45
47
  }
46
48
 
47
- private id: string;
49
+ private _id: string;
50
+ public get id(): string {
51
+ return this._id;
52
+ }
53
+
48
54
  private renderer: DIVERenderer;
49
55
  private scene: DIVEScene;
50
56
  private controller: DIVEOrbitControls;
@@ -65,7 +71,7 @@ export default class DIVECommunication {
65
71
  private listeners: Map<keyof Actions, EventListener<keyof Actions>[]> = new Map();
66
72
 
67
73
  constructor(renderer: DIVERenderer, scene: DIVEScene, controls: DIVEOrbitControls, toolbox: DIVEToolbox) {
68
- this.id = generateUUID();
74
+ this._id = generateUUID();
69
75
  this.renderer = renderer;
70
76
  this.scene = scene;
71
77
  this.controller = controls;
@@ -186,10 +186,19 @@ describe('dive/communication/DIVECommunication', () => {
186
186
 
187
187
  it('should instantiate', () => {
188
188
  expect(testCom).toBeDefined();
189
- expect(() => DIVECommunication.get('id')).not.toThrow();
190
189
  expect(DIVECommunication['__instances']).toHaveLength(1);
191
190
  });
192
191
 
192
+ it('should get instance', () => {
193
+ expect(testCom).toBeDefined();
194
+ expect(DIVECommunication.get(testCom.id)).toBeDefined();
195
+
196
+ testCom.PerformAction('ADD_OBJECT', {
197
+ id: 'someID',
198
+ } as COMModel);
199
+ expect(DIVECommunication.get('someID')).toBeDefined();
200
+ });
201
+
193
202
  it('should destroy instance', () => {
194
203
  expect(testCom).toBeDefined();
195
204
  testCom.DestroyInstance();
@@ -670,6 +679,14 @@ describe('dive/communication/DIVECommunication', () => {
670
679
  expect(visibility).toBe(false);
671
680
  });
672
681
 
682
+ it('should perform action USE_TOOL', () => {
683
+ let success = testCom.PerformAction('USE_TOOL', { tool: 'select' });
684
+ expect(success).toBe(true);
685
+
686
+ success = testCom.PerformAction('USE_TOOL', { tool: 'none' });
687
+ expect(success).toBe(true);
688
+ });
689
+
673
690
  it('should perform action MODEL_LOADED', () => {
674
691
  const payload = {
675
692
  entityType: "model",
@@ -37,6 +37,8 @@ export default class DIVEOrbitControls extends OrbitControls {
37
37
  public object: DIVEPerspectiveCamera;
38
38
  public domElement: HTMLCanvasElement;
39
39
 
40
+ private _removePreRenderCallback: () => void = () => { };
41
+
40
42
  constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, animationSystem: DIVEAnimationSystem, settings: DIVEOrbitControlsSettings = DIVEOrbitControlsDefaultSettings) {
41
43
  super(camera, renderer.domElement);
42
44
 
@@ -46,14 +48,23 @@ export default class DIVEOrbitControls extends OrbitControls {
46
48
 
47
49
  this.object = camera;
48
50
 
49
- renderer.AddPreRenderCallback(() => {
51
+ const id = renderer.AddPreRenderCallback(() => {
50
52
  this.preRenderCallback();
51
53
  });
52
54
 
55
+ this._removePreRenderCallback = () => {
56
+ renderer.RemovePreRenderCallback(id);
57
+ }
58
+
53
59
  this.enableDamping = settings.enableDamping;
54
60
  this.dampingFactor = settings.dampingFactor;
55
61
  }
56
62
 
63
+ public Dispose(): void {
64
+ this._removePreRenderCallback();
65
+ this.dispose();
66
+ }
67
+
57
68
  public ComputeEncompassingView(bb: Box3): { position: Vector3Like, target: Vector3Like } {
58
69
  const center = bb.getCenter(new Vector3());
59
70
  const size = bb.getSize(new Vector3());
@@ -152,6 +152,11 @@ describe('dive/controls/DIVEOrbitControls', () => {
152
152
  expect(controller).toBeDefined();
153
153
  });
154
154
 
155
+ it('should dispose', () => {
156
+ const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
157
+ expect(() => controller.Dispose()).not.toThrow();
158
+ });
159
+
155
160
  it('should compute encompassing view', () => {
156
161
  const controller = new DIVEOrbitControls(mockCamera, mockRenderer, mockAnimSystem);
157
162
  expect(() => controller.ComputeEncompassingView(new Box3())).not.toThrow();
package/src/dive.ts CHANGED
@@ -229,6 +229,7 @@ export default class DIVE {
229
229
  public Dispose(): void {
230
230
  this.removeResizeObserver();
231
231
  this.renderer.Dispose();
232
+ this.orbitControls.Dispose();
232
233
  this.axisCamera?.Dispose();
233
234
  this.animationSystem.Dispose();
234
235
  this.toolbox.Dispose();