@shopware-ag/dive 1.13.0 → 1.15.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.
@@ -1,10 +1,8 @@
1
- import { Box3, BoxGeometry, BufferGeometry, Color, ConeGeometry, CylinderGeometry, Mesh, MeshStandardMaterial, Object3D, Raycaster, SphereGeometry, Vector3, Vector3Like } from 'three';
1
+ import { BoxGeometry, BufferGeometry, Color, ConeGeometry, CylinderGeometry, Mesh, MeshStandardMaterial, Raycaster, SphereGeometry, Vector3 } from 'three';
2
2
  import { DIVECommunication } from '../com/Communication';
3
3
  import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
4
4
  import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
5
- import { type DIVESelectable } from '../interface/Selectable';
6
- import { type DIVEMoveable } from '../interface/Moveable';
7
- import { type TransformControls } from 'three/examples/jsm/controls/TransformControls';
5
+ import { DIVENode } from '../node/Node';
8
6
  import { type COMGeometry, type COMMaterial } from '../com/types';
9
7
 
10
8
  /**
@@ -17,29 +15,20 @@ import { type COMGeometry, type COMMaterial } from '../com/types';
17
15
  * @module
18
16
  */
19
17
 
20
- export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMoveable {
18
+ export class DIVEPrimitive extends DIVENode {
21
19
  readonly isDIVEPrimitive: true = true;
22
- readonly isSelectable: true = true;
23
- readonly isMoveable: true = true;
24
-
25
- public gizmo: TransformControls | null = null;
26
20
 
27
21
  private _mesh: Mesh;
28
- private _boundingBox: Box3;
29
22
 
30
23
  constructor() {
31
24
  super();
32
25
 
33
- this.layers.mask = PRODUCT_LAYER_MASK;
34
-
35
26
  this._mesh = new Mesh();
36
27
  this._mesh.layers.mask = PRODUCT_LAYER_MASK;
37
28
  this._mesh.castShadow = true;
38
29
  this._mesh.receiveShadow = true;
39
30
  this._mesh.material = new MeshStandardMaterial();
40
31
  this.add(this._mesh);
41
-
42
- this._boundingBox = new Box3();
43
32
  }
44
33
 
45
34
  public SetGeometry(geometry: COMGeometry): void {
@@ -47,24 +36,6 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
47
36
  this._boundingBox.setFromObject(this._mesh);
48
37
  }
49
38
 
50
- public SetPosition(position: Vector3Like): void {
51
- this.position.set(position.x, position.y, position.z);
52
- }
53
-
54
- public SetRotation(rotation: Vector3Like): void {
55
- this.rotation.setFromVector3(new Vector3(rotation.x, rotation.y, rotation.z));
56
- }
57
-
58
- public SetScale(scale: Vector3Like): void {
59
- this.scale.set(scale.x, scale.y, scale.z);
60
- }
61
-
62
- public SetVisibility(visible: boolean): void {
63
- this.traverse((child) => {
64
- child.visible = visible;
65
- });
66
- }
67
-
68
39
  public SetMaterial(material: Partial<COMMaterial>): void {
69
40
  const primitiveMaterial = this._mesh.material as MeshStandardMaterial;
70
41
 
@@ -121,11 +92,6 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
121
92
  if (this._mesh) this._mesh.material = primitiveMaterial;
122
93
  }
123
94
 
124
- public SetToWorldOrigin(): void {
125
- this.position.set(0, 0, 0);
126
- DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
127
- }
128
-
129
95
  public PlaceOnFloor(): void {
130
96
  this.position.y = -this._boundingBox.min.y * this.scale.y;
131
97
  DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
@@ -164,18 +130,6 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
164
130
  }
165
131
  }
166
132
 
167
- public onMove(): void {
168
- DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
169
- }
170
-
171
- public onSelect(): void {
172
- DIVECommunication.get(this.userData.id)?.PerformAction('SELECT_OBJECT', { id: this.userData.id });
173
- }
174
-
175
- public onDeselect(): void {
176
- DIVECommunication.get(this.userData.id)?.PerformAction('DESELECT_OBJECT', { id: this.userData.id });
177
- }
178
-
179
133
  private assembleGeometry(geometry: COMGeometry): BufferGeometry {
180
134
  switch (geometry.name) {
181
135
  case 'cylinder':
@@ -213,34 +213,6 @@ describe('dive/primitive/DIVEPrimitive', () => {
213
213
  expect(() => primitive.SetGeometry(bufferGeometry)).not.toThrow();
214
214
  });
215
215
 
216
- it('should set position', () => {
217
- expect(() => primitive.SetPosition({ x: 0, y: 0, z: 0 })).not.toThrow();
218
- });
219
-
220
- it('should set rotation', () => {
221
- expect(() => primitive.SetRotation({ x: 0, y: 0, z: 0 })).not.toThrow();
222
- });
223
-
224
- it('should set scale', () => {
225
- expect(() => primitive.SetScale({ x: 1, y: 1, z: 1 })).not.toThrow();
226
- });
227
-
228
- it('should set visibility', () => {
229
- expect(() => primitive.SetVisibility(true)).not.toThrow();
230
- });
231
-
232
- it('should set to world origin', () => {
233
- primitive.userData.id = 'something';
234
-
235
- expect(() => primitive.SetToWorldOrigin()).not.toThrow();
236
- expect(primitive.position.x).toBe(0);
237
- expect(primitive.position.y).toBe(0);
238
- expect(primitive.position.z).toBe(0);
239
-
240
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
241
- expect(() => primitive.SetToWorldOrigin()).not.toThrow();
242
- });
243
-
244
216
  it('should place on floor', () => {
245
217
  primitive.userData.id = 'something';
246
218
 
@@ -314,33 +286,6 @@ describe('dive/primitive/DIVEPrimitive', () => {
314
286
 
315
287
  });
316
288
 
317
- it('should onMove', () => {
318
- primitive.userData.id = 'something';
319
-
320
- expect(() => primitive.onMove()).not.toThrow();
321
-
322
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
323
- expect(() => primitive.onMove()).not.toThrow();
324
- });
325
-
326
- it('should onSelect', () => {
327
- primitive.userData.id = 'something';
328
-
329
- expect(() => primitive.onSelect()).not.toThrow();
330
-
331
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
332
- expect(() => primitive.onSelect()).not.toThrow();
333
- });
334
-
335
- it('should onDeselect', () => {
336
- primitive.userData.id = 'something';
337
-
338
- expect(() => primitive.onDeselect()).not.toThrow();
339
-
340
- jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
341
- expect(() => primitive.onDeselect()).not.toThrow();
342
- });
343
-
344
289
  it('should set geometry', () => {
345
290
  primitive.userData.id = 'something';
346
291