@shopware-ag/dive 1.17.0 → 1.17.2

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.
@@ -103,31 +103,37 @@ const mock_detach = jest.fn();
103
103
  jest.mock('three/examples/jsm/controls/TransformControls', () => {
104
104
  return {
105
105
  TransformControls: jest.fn(function () {
106
- (this.addEventListener = (
107
- type: string,
108
- callback: (e: object) => void,
109
- ) => {
110
- callback({ value: false });
111
- this.object = {};
112
- callback({ value: false });
113
- this.object = {
114
- onMove: 'hello',
115
- };
116
- callback({ value: false });
117
- this.object = {
118
- onMove: jest.fn(),
119
- };
120
- callback({ value: false });
121
- }),
122
- (this.attach = mock_attach),
123
- (this.detach = mock_detach),
124
- (this.traverse = function (callback: (obj: object) => void) {
125
- callback(this);
126
- });
106
+ this.isTransformControls = true;
107
+ this.addEventListener = jest.fn(
108
+ (type: string, callback: (e: object) => void) => {
109
+ callback({ value: false });
110
+ this.object = {};
111
+ callback({ value: false });
112
+ this.object = {
113
+ onMove: 'hello',
114
+ };
115
+ callback({ value: false });
116
+ this.object = {
117
+ onMove: jest.fn(),
118
+ };
119
+ callback({ value: false });
120
+ },
121
+ );
122
+ this.attach = jest.fn((object) => {
123
+ this.object = object;
124
+ });
125
+ this.detach = jest.fn(() => {
126
+ this.object = null;
127
+ });
128
+ this.traverse = function (callback: (obj: object) => void) {
129
+ callback(this);
130
+ };
127
131
  this.setMode = jest.fn();
128
132
  this.getRaycaster = jest.fn().mockReturnValue({
129
133
  layers: {
130
134
  mask: 0,
135
+ disableAll: jest.fn(),
136
+ enableAll: jest.fn(),
131
137
  },
132
138
  });
133
139
  this.layers = {
@@ -169,8 +175,7 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
169
175
 
170
176
  it('should execute onClick without hit', () => {
171
177
  const selectTool = new DIVESelectTool(mockScene, mockController);
172
- selectTool['_gizmo'].object = {} as unknown as Object3D &
173
- DIVESelectable;
178
+ selectTool.AttachGizmo({} as unknown as DIVESelectable);
174
179
  expect(() =>
175
180
  selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
176
181
  ).not.toThrow();
@@ -213,11 +218,11 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
213
218
  },
214
219
  ]);
215
220
  const selectTool = new DIVESelectTool(mockScene, mockController);
216
- selectTool['_gizmo'].object = {
221
+ selectTool.AttachGizmo({
217
222
  visible: true,
218
223
  isSelectable: true,
219
224
  uuid: 'test0',
220
- } as unknown as Object3D & DIVESelectable;
225
+ } as unknown as Object3D & DIVESelectable);
221
226
  expect(() =>
222
227
  selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
223
228
  ).not.toThrow();
@@ -241,10 +246,10 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
241
246
  },
242
247
  ]);
243
248
  const selectTool = new DIVESelectTool(mockScene, mockController);
244
- selectTool['_gizmo'].object = {
249
+ selectTool.AttachGizmo({
245
250
  isSelectable: true,
246
251
  uuid: 'test1',
247
- } as unknown as Object3D & DIVESelectable;
252
+ } as unknown as Object3D & DIVESelectable);
248
253
  expect(() =>
249
254
  selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
250
255
  ).not.toThrow();
@@ -4,6 +4,7 @@ import type DIVEOrbitControls from '../../controls/OrbitControls.ts';
4
4
  import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
5
5
  import { type DIVEMovable } from '../../interface/Movable.ts';
6
6
  import { implementsInterface } from '../../helper/isInterface/implementsInterface.ts';
7
+ import { DIVEGizmo } from '../../gizmo/Gizmo.ts';
7
8
 
8
9
  export const isTransformTool = (
9
10
  tool: DIVEBaseTool,
@@ -26,60 +27,13 @@ export interface DIVEObjectEventMap {
26
27
  export default class DIVETransformTool extends DIVEBaseTool {
27
28
  readonly isTransformTool: boolean = true;
28
29
 
29
- protected _gizmo: TransformControls;
30
+ protected _gizmo: TransformControls | DIVEGizmo;
30
31
 
31
32
  constructor(scene: DIVEScene, controller: DIVEOrbitControls) {
32
33
  super(scene, controller);
33
34
  this.name = 'DIVETransformTool';
34
35
 
35
- this._gizmo = new TransformControls(
36
- this._controller.object,
37
- this._controller.domElement,
38
- );
39
- this._gizmo.mode = 'translate';
40
-
41
- // happens when pointerDown event is called on gizmo
42
- this._gizmo.addEventListener('mouseDown', () => {
43
- controller.enabled = false;
44
-
45
- if (
46
- !implementsInterface<DIVEMovable>(
47
- this._gizmo.object,
48
- 'isMovable',
49
- )
50
- )
51
- return;
52
- if (!this._gizmo.object.onMoveStart) return;
53
- this._gizmo.object.onMoveStart();
54
- });
55
-
56
- // happens when pointerMove event is called on gizmo
57
- this._gizmo.addEventListener('objectChange', () => {
58
- if (
59
- !implementsInterface<DIVEMovable>(
60
- this._gizmo.object,
61
- 'isMovable',
62
- )
63
- )
64
- return;
65
- if (!this._gizmo.object.onMove) return;
66
- this._gizmo.object.onMove();
67
- });
68
-
69
- // happens when pointerUp event is called on gizmo
70
- this._gizmo.addEventListener('mouseUp', () => {
71
- controller.enabled = true;
72
-
73
- if (
74
- !implementsInterface<DIVEMovable>(
75
- this._gizmo.object,
76
- 'isMovable',
77
- )
78
- )
79
- return;
80
- if (!this._gizmo.object.onMoveEnd) return;
81
- this._gizmo.object.onMoveEnd();
82
- });
36
+ this._gizmo = this.initGizmo();
83
37
 
84
38
  this._scene.add(this._gizmo);
85
39
  }
@@ -94,20 +48,74 @@ export default class DIVETransformTool extends DIVEBaseTool {
94
48
  const contains = this._scene.children.includes(this._gizmo);
95
49
  if (active && !contains) {
96
50
  this._scene.add(this._gizmo);
51
+ if ('isTransformControls' in this._gizmo) {
52
+ (this._gizmo as TransformControls)
53
+ .getRaycaster()
54
+ .layers.enableAll();
55
+ }
97
56
  } else if (!active && contains) {
98
57
  this._scene.remove(this._gizmo);
58
+ if ('isTransformControls' in this._gizmo) {
59
+ (this._gizmo as TransformControls)
60
+ .getRaycaster()
61
+ .layers.disableAll();
62
+ }
99
63
  }
100
64
  }
101
65
 
66
+ // only used for optimizing pointer events with DIVEGizmo
102
67
  // public onPointerDown(e: PointerEvent): void {
103
68
  // super.onPointerDown(e);
104
69
 
105
- // // if (this._hovered) {
106
- // // this._dragRaycastOnObjects = this._gizmo.gizmoPlane.children;
107
- // // }
70
+ // if (this._hovered) {
71
+ // this._dragRaycastOnObjects = (
72
+ // this._gizmo as DIVEGizmo
73
+ // ).gizmoPlane?.children;
74
+ // }
108
75
  // }
109
76
 
77
+ // only used for optimizing pointer events with DIVEGizmo
110
78
  // protected raycast(): Intersection[] {
111
- // return super.raycast(this._gizmo.gizmoNode.children);
79
+ // return super.raycast((this._gizmo as DIVEGizmo).gizmoNode.children);
112
80
  // }
81
+
82
+ private initGizmo(): TransformControls | DIVEGizmo {
83
+ const g = new TransformControls(
84
+ // this._controller,
85
+ this._controller.object,
86
+ this._controller.domElement,
87
+ );
88
+ // g.debug = true;
89
+ g.mode = 'translate';
90
+
91
+ // happens when pointerDown event is called on gizmo
92
+ g.addEventListener('mouseDown', () => {
93
+ this._controller.enabled = false;
94
+
95
+ if (!implementsInterface<DIVEMovable>(g.object, 'isMovable'))
96
+ return;
97
+ if (!g.object.onMoveStart) return;
98
+ g.object.onMoveStart();
99
+ });
100
+
101
+ // happens when pointerMove event is called on gizmo
102
+ g.addEventListener('objectChange', () => {
103
+ if (!implementsInterface<DIVEMovable>(g.object, 'isMovable'))
104
+ return;
105
+ if (!g.object.onMove) return;
106
+ g.object.onMove();
107
+ });
108
+
109
+ // happens when pointerUp event is called on gizmo
110
+ g.addEventListener('mouseUp', () => {
111
+ this._controller.enabled = true;
112
+
113
+ if (!implementsInterface<DIVEMovable>(g.object, 'isMovable'))
114
+ return;
115
+ if (!g.object.onMoveEnd) return;
116
+ g.object.onMoveEnd();
117
+ });
118
+
119
+ return g;
120
+ }
113
121
  }
@@ -102,35 +102,37 @@ const mock_detach = jest.fn();
102
102
  jest.mock('three/examples/jsm/controls/TransformControls', () => {
103
103
  return {
104
104
  TransformControls: jest.fn(function () {
105
- (this.addEventListener = (
106
- type: string,
107
- callback: (e: object) => void,
108
- ) => {
109
- this.object = null;
110
- callback({ value: false });
111
- this.object = {};
112
- callback({ value: false });
113
- this.object = {
114
- isMovable: true,
115
- };
116
- callback({ value: false });
117
- this.object = {
118
- isMovable: true,
119
- onMove: jest.fn(),
120
- onMoveStart: jest.fn(),
121
- onMoveEnd: jest.fn(),
122
- };
123
- callback({ value: false });
124
- }),
125
- (this.attach = mock_attach),
126
- (this.detach = mock_detach),
127
- (this.traverse = function (callback: (obj: object) => void) {
128
- callback(this);
129
- });
105
+ this.isTransformControls = true;
106
+ this.addEventListener = jest.fn(
107
+ (type: string, callback: (e: object) => void) => {
108
+ this.object = null;
109
+ callback({ value: false });
110
+ this.object = {};
111
+ callback({ value: false });
112
+ this.object = {
113
+ isMovable: true,
114
+ };
115
+ callback({ value: false });
116
+ this.object = {
117
+ isMovable: true,
118
+ onMove: jest.fn(),
119
+ onMoveStart: jest.fn(),
120
+ onMoveEnd: jest.fn(),
121
+ };
122
+ callback({ value: false });
123
+ },
124
+ );
125
+ this.attach = mock_attach;
126
+ this.detach = mock_detach;
127
+ this.traverse = jest.fn((callback: (obj: object) => void) => {
128
+ callback(this);
129
+ });
130
130
  this.setMode = jest.fn();
131
131
  this.getRaycaster = jest.fn().mockReturnValue({
132
132
  layers: {
133
133
  mask: 0,
134
+ disableAll: jest.fn(),
135
+ enableAll: jest.fn(),
134
136
  },
135
137
  });
136
138
  this.layers = {