@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.
- package/build/dive.cjs +90 -45
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +38 -2
- package/build/dive.d.ts +38 -2
- package/build/dive.js +90 -45
- package/build/dive.js.map +1 -1
- package/package.json +2 -1
- package/src/com/Communication.ts +41 -0
- package/src/gizmo/Gizmo.ts +6 -0
- package/src/gizmo/handles/AxisHandle.ts +14 -8
- package/src/gizmo/handles/RadialHandle.ts +12 -6
- package/src/gizmo/handles/ScaleHandle.ts +14 -8
- package/src/gizmo/rotate/RotateGizmo.ts +6 -0
- package/src/gizmo/scale/ScaleGizmo.ts +6 -0
- package/src/gizmo/translate/TranslateGizmo.ts +6 -0
- package/src/model/Model.ts +7 -2
- package/src/model/__test__/Model.test.ts +48 -73
- package/src/primitive/Primitive.ts +7 -2
- package/src/primitive/__test__/Primitive.test.ts +25 -18
- package/src/toolbox/select/__test__/SelectTool.test.ts +32 -27
- package/src/toolbox/transform/TransformTool.ts +61 -53
- package/src/toolbox/transform/__test__/TransformTool.test.ts +27 -25
|
@@ -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
|
-
|
|
107
|
-
|
|
108
|
-
callback: (e: object) => void
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
//
|
|
106
|
-
//
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
callback: (e: object) => void
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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 = {
|