@shopware-ag/dive 1.19.0 → 1.19.1-beta.1

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.
Files changed (197) hide show
  1. package/build/dive.cjs +388 -220
  2. package/build/dive.cjs.map +1 -1
  3. package/build/dive.js +395 -21946
  4. package/build/dive.js.map +1 -1
  5. package/build/dive.mjs +28206 -0
  6. package/build/dive.mjs.map +1 -0
  7. package/build/src/ar/AR.d.ts +37 -14
  8. package/build/src/ar/arquicklook/ARQuickLook.d.ts +5 -6
  9. package/build/src/ar/sceneviewer/SceneViewer.d.ts +42 -6
  10. package/build/src/com/actions/scene/launchar.d.ts +5 -2
  11. package/build/src/converter/Converter.d.ts +21 -0
  12. package/build/src/dive.d.ts +3 -2
  13. package/build/src/exporter/Exporter.d.ts +11 -0
  14. package/build/src/helper/applyMixins/applyMixins.d.ts +22 -6
  15. package/build/src/info/Info.d.ts +37 -13
  16. package/build/src/interface/Movable.d.ts +5 -5
  17. package/build/src/interface/Selectable.d.ts +4 -4
  18. package/build/src/loader/Loader.d.ts +11 -0
  19. package/build/src/model/Model.d.ts +2 -2
  20. package/build/src/node/Node.d.ts +3 -3
  21. package/build/src/scene/root/Root.d.ts +1 -1
  22. package/build/src/types/ExporterOptions.d.ts +15 -0
  23. package/build/src/types/FileTypes.d.ts +27 -0
  24. package/build/src/types/index.d.ts +4 -0
  25. package/build/src/types/info/index.d.ts +66 -0
  26. package/package.json +17 -3
  27. package/build/src/exporters/usdz/USDZExporter.d.ts +0 -15
  28. package/build/src/loadingmanager/LoadingManager.d.ts +0 -14
  29. package/src/__test__/DIVE.test.ts +0 -274
  30. package/src/animation/AnimationSystem.ts +0 -34
  31. package/src/animation/__test__/AnimationSystem.test.ts +0 -40
  32. package/src/ar/AR.ts +0 -98
  33. package/src/ar/__test__/AR.test.ts +0 -187
  34. package/src/ar/arquicklook/ARQuickLook.ts +0 -93
  35. package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -93
  36. package/src/ar/sceneviewer/SceneViewer.ts +0 -74
  37. package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -93
  38. package/src/ar/webxr/WebXR.ts +0 -176
  39. package/src/ar/webxr/controller/WebXRController.ts +0 -340
  40. package/src/ar/webxr/crosshair/WebXRCrosshair.ts +0 -35
  41. package/src/ar/webxr/origin/WebXROrigin.ts +0 -192
  42. package/src/ar/webxr/overlay/Overlay.ts +0 -50
  43. package/src/ar/webxr/raycaster/WebXRRaycaster.ts +0 -131
  44. package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +0 -102
  45. package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +0 -49
  46. package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +0 -356
  47. package/src/axiscamera/AxisCamera.ts +0 -108
  48. package/src/axiscamera/__test__/AxisCamera.test.ts +0 -150
  49. package/src/camera/PerspectiveCamera.ts +0 -63
  50. package/src/camera/__test__/PerspectiveCamera.test.ts +0 -36
  51. package/src/com/Communication.ts +0 -808
  52. package/src/com/__test__/Communication.test.ts +0 -1024
  53. package/src/com/actions/camera/computeencompassingview.ts +0 -10
  54. package/src/com/actions/camera/getcameratransform.ts +0 -10
  55. package/src/com/actions/camera/movecamera.ts +0 -18
  56. package/src/com/actions/camera/resetcamera.ts +0 -5
  57. package/src/com/actions/camera/setcameralayer.ts +0 -5
  58. package/src/com/actions/camera/setcameratransform.ts +0 -10
  59. package/src/com/actions/camera/zoomcamera.ts +0 -5
  60. package/src/com/actions/index.ts +0 -61
  61. package/src/com/actions/media/generatemedia.ts +0 -18
  62. package/src/com/actions/object/addobject.ts +0 -7
  63. package/src/com/actions/object/deleteobject.ts +0 -7
  64. package/src/com/actions/object/deselectobject.ts +0 -7
  65. package/src/com/actions/object/getallobjects.ts +0 -7
  66. package/src/com/actions/object/getobjects.ts +0 -7
  67. package/src/com/actions/object/model/dropit.ts +0 -5
  68. package/src/com/actions/object/model/modelloaded.ts +0 -5
  69. package/src/com/actions/object/model/placeonfloor.ts +0 -5
  70. package/src/com/actions/object/selectobject.ts +0 -7
  71. package/src/com/actions/object/setparent.ts +0 -10
  72. package/src/com/actions/object/updateobject.ts +0 -7
  73. package/src/com/actions/renderer/startrender.ts +0 -5
  74. package/src/com/actions/scene/exportscene.ts +0 -7
  75. package/src/com/actions/scene/getallscenedata.ts +0 -7
  76. package/src/com/actions/scene/launchar.ts +0 -7
  77. package/src/com/actions/scene/setbackground.ts +0 -5
  78. package/src/com/actions/scene/updatescene.ts +0 -11
  79. package/src/com/actions/toolbox/select/setgizmomode.ts +0 -5
  80. package/src/com/actions/toolbox/transform/setgizmoscalelinked.ts +0 -5
  81. package/src/com/actions/toolbox/transform/setgizmovisible.ts +0 -5
  82. package/src/com/actions/toolbox/usetool.ts +0 -7
  83. package/src/com/types/COMBaseEntity.ts +0 -9
  84. package/src/com/types/COMEntity.ts +0 -7
  85. package/src/com/types/COMEntityType.ts +0 -1
  86. package/src/com/types/COMGeometry.ts +0 -8
  87. package/src/com/types/COMGeometryType.ts +0 -9
  88. package/src/com/types/COMGroup.ts +0 -9
  89. package/src/com/types/COMLight.ts +0 -11
  90. package/src/com/types/COMMaterial.ts +0 -12
  91. package/src/com/types/COMModel.ts +0 -12
  92. package/src/com/types/COMPov.ts +0 -8
  93. package/src/com/types/COMPrimitive.ts +0 -12
  94. package/src/com/types/index.ts +0 -23
  95. package/src/constant/AxisHelperColors.ts +0 -7
  96. package/src/constant/GridColors.ts +0 -2
  97. package/src/constant/VisibilityLayerMask.ts +0 -5
  98. package/src/controls/OrbitControls.ts +0 -211
  99. package/src/controls/__test__/OrbitControls.test.ts +0 -256
  100. package/src/dive.ts +0 -363
  101. package/src/events/EventExecutor.ts +0 -35
  102. package/src/exporters/usdz/USDZExporter.ts +0 -21
  103. package/src/exporters/usdz/__test__/USDZExporter.test.ts +0 -57
  104. package/src/gizmo/Gizmo.ts +0 -144
  105. package/src/gizmo/handles/AxisHandle.ts +0 -153
  106. package/src/gizmo/handles/RadialHandle.ts +0 -149
  107. package/src/gizmo/handles/ScaleHandle.ts +0 -195
  108. package/src/gizmo/plane/GizmoPlane.ts +0 -84
  109. package/src/gizmo/rotate/RotateGizmo.ts +0 -143
  110. package/src/gizmo/scale/ScaleGizmo.ts +0 -125
  111. package/src/gizmo/translate/TranslateGizmo.ts +0 -114
  112. package/src/grid/Grid.ts +0 -34
  113. package/src/grid/__test__/Grid.test.ts +0 -28
  114. package/src/group/Group.ts +0 -184
  115. package/src/group/__test__/Group.test.ts +0 -212
  116. package/src/helper/applyMixins/__test__/applyMixins.test.ts +0 -30
  117. package/src/helper/applyMixins/applyMixins.ts +0 -18
  118. package/src/helper/findInterface/__test__/findInterface.test.ts +0 -63
  119. package/src/helper/findInterface/findInterface.ts +0 -13
  120. package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +0 -40
  121. package/src/helper/findSceneRecursive/findSceneRecursive.ts +0 -16
  122. package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +0 -186
  123. package/src/helper/getObjectDelta/getObjectDelta.ts +0 -105
  124. package/src/helper/isInterface/__test__/implementsInterface.test.ts +0 -19
  125. package/src/helper/isInterface/implementsInterface.ts +0 -9
  126. package/src/info/Info.ts +0 -154
  127. package/src/info/__test__/Info.test.ts +0 -338
  128. package/src/interface/Draggable.ts +0 -14
  129. package/src/interface/Hoverable.ts +0 -14
  130. package/src/interface/Movable.ts +0 -12
  131. package/src/interface/Rotatable.ts +0 -10
  132. package/src/interface/Scalable.ts +0 -10
  133. package/src/interface/Selectable.ts +0 -11
  134. package/src/io/IO.ts +0 -62
  135. package/src/io/__test__/IO.test.ts +0 -116
  136. package/src/io/gltf/GLTFIO.ts +0 -56
  137. package/src/io/gltf/__test__/GLTFIO.test.ts +0 -108
  138. package/src/light/AmbientLight.ts +0 -39
  139. package/src/light/PointLight.ts +0 -115
  140. package/src/light/SceneLight.ts +0 -63
  141. package/src/light/__test__/AmbientLight.test.ts +0 -29
  142. package/src/light/__test__/PointLight.test.ts +0 -74
  143. package/src/light/__test__/SceneLight.test.ts +0 -47
  144. package/src/loadingmanager/LoadingManager.ts +0 -50
  145. package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -27
  146. package/src/math/__test__/DIVEMath.test.ts +0 -12
  147. package/src/math/ceil/__test__/ceilExp.test.ts +0 -12
  148. package/src/math/ceil/ceilExp.ts +0 -6
  149. package/src/math/degToRad/__test__/degToRad.test.ts +0 -172
  150. package/src/math/degToRad/degToRad.ts +0 -5
  151. package/src/math/floor/__test__/floorExp.test.ts +0 -14
  152. package/src/math/floor/floorExp.ts +0 -6
  153. package/src/math/helper/__test__/shift.test.ts +0 -12
  154. package/src/math/helper/shift.ts +0 -4
  155. package/src/math/index.ts +0 -28
  156. package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -155
  157. package/src/math/radToDeg/radToDeg.ts +0 -5
  158. package/src/math/round/__test__/roundExp.test.ts +0 -14
  159. package/src/math/round/roundExp.ts +0 -10
  160. package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +0 -20
  161. package/src/math/signedAngleTo/signedAngleTo.ts +0 -20
  162. package/src/math/toFixed/__test__/toFixedExp.test.ts +0 -14
  163. package/src/math/toFixed/toFixedExp.ts +0 -9
  164. package/src/math/truncate/__test__/truncateExp.test.ts +0 -14
  165. package/src/math/truncate/truncateExp.ts +0 -9
  166. package/src/mediacreator/MediaCreator.ts +0 -75
  167. package/src/mediacreator/__test__/MediaCreator.test.ts +0 -155
  168. package/src/model/Model.ts +0 -185
  169. package/src/model/__test__/Model.test.ts +0 -222
  170. package/src/module/Module.ts +0 -45
  171. package/src/module/__test__/Module.test.ts +0 -54
  172. package/src/node/Node.ts +0 -98
  173. package/src/node/__test__/Node.test.ts +0 -120
  174. package/src/primitive/Primitive.ts +0 -299
  175. package/src/primitive/__test__/Primitive.test.ts +0 -281
  176. package/src/primitive/floor/Floor.ts +0 -45
  177. package/src/primitive/floor/__test__/Floor.test.ts +0 -24
  178. package/src/renderer/Renderer.ts +0 -215
  179. package/src/renderer/__test__/Renderer.test.ts +0 -228
  180. package/src/scene/Scene.ts +0 -106
  181. package/src/scene/__test__/Scene.test.ts +0 -124
  182. package/src/scene/root/Root.ts +0 -426
  183. package/src/scene/root/__test__/Root.test.ts +0 -903
  184. package/src/scene/xrroot/XRRoot.ts +0 -56
  185. package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +0 -80
  186. package/src/toolbox/BaseTool.ts +0 -319
  187. package/src/toolbox/Toolbox.ts +0 -129
  188. package/src/toolbox/__test__/BaseTool.test.ts +0 -627
  189. package/src/toolbox/__test__/Toolbox.test.ts +0 -143
  190. package/src/toolbox/select/SelectTool.ts +0 -92
  191. package/src/toolbox/select/__test__/SelectTool.test.ts +0 -237
  192. package/src/toolbox/transform/TransformTool.ts +0 -166
  193. package/src/toolbox/transform/__test__/TransformTool.test.ts +0 -147
  194. package/src/types/SceneData.ts +0 -26
  195. package/src/types/SceneObjects.ts +0 -14
  196. package/src/types/SceneType.ts +0 -14
  197. package/src/types/index.ts +0 -5
@@ -1,143 +0,0 @@
1
- import DIVEToolbox, { type ToolType } from '../Toolbox';
2
- import type DIVEOrbitControls from '../../controls/OrbitControls';
3
- import { type DIVEScene } from '../../scene/Scene';
4
-
5
- /**
6
- * @jest-environment jsdom
7
- */
8
-
9
- jest.mock('../select/SelectTool.ts', () => {
10
- return {
11
- DIVESelectTool: jest.fn(function () {
12
- this.Activate = jest.fn();
13
- this.Deactivate = jest.fn();
14
- this.onPointerDown = jest.fn();
15
- this.onPointerMove = jest.fn();
16
- this.onPointerUp = jest.fn();
17
- this.onWheel = jest.fn();
18
- this.SetGizmoMode = jest.fn();
19
- this.SetGizmoVisibility = jest.fn();
20
- this.SetGizmoScaleLinked = jest.fn();
21
- return this;
22
- }),
23
- };
24
- });
25
-
26
- const mockController = {
27
- domElement: {
28
- width: 0,
29
- height: 0,
30
- addEventListener: jest.fn((type, callback) => {
31
- callback();
32
- }),
33
- getContext: jest.fn(),
34
- removeEventListener: jest.fn((type, callback) => {
35
- callback();
36
- }),
37
- clientWidth: 0,
38
- clientHeight: 0,
39
- offsetLeft: 0,
40
- offsetTop: 0,
41
- },
42
- object: {},
43
- } as unknown as DIVEOrbitControls;
44
-
45
- describe('dive/toolbox/DIVEToolBox', () => {
46
- afterEach(() => {
47
- jest.clearAllMocks();
48
- });
49
-
50
- it('should instantiate', () => {
51
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
52
- expect(toolBox).toBeDefined();
53
- });
54
-
55
- it('should dispose', () => {
56
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
57
- toolBox.Dispose();
58
- });
59
-
60
- it('should throw with incorrect tool', () => {
61
- const spy = jest.spyOn(console, 'warn').mockImplementation();
62
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
63
- expect(() =>
64
- toolBox.UseTool('not a real tool' as unknown as ToolType),
65
- ).not.toThrow();
66
- expect(spy).toHaveBeenCalled();
67
- });
68
-
69
- it('should use no tool', () => {
70
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
71
- expect(() => toolBox.UseTool('select')).not.toThrow();
72
- expect(() => toolBox.UseTool('none')).not.toThrow();
73
- });
74
-
75
- it('should use select tool', () => {
76
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
77
- expect(() => toolBox.UseTool(DIVEToolbox.DefaultTool)).not.toThrow();
78
- });
79
-
80
- it('should execute pointer down event on tool', () => {
81
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
82
- expect(() =>
83
- toolBox.onPointerDown({ type: 'pointerdown' } as PointerEvent),
84
- ).not.toThrow();
85
- expect(() => toolBox.UseTool('select')).not.toThrow();
86
- expect(() =>
87
- toolBox.onPointerDown({ type: 'pointerdown' } as PointerEvent),
88
- ).not.toThrow();
89
- });
90
-
91
- it('should execute pointer move event on tool', () => {
92
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
93
- expect(() =>
94
- toolBox.onPointerMove({ type: 'pointermove' } as PointerEvent),
95
- ).not.toThrow();
96
- expect(() => toolBox.UseTool('select')).not.toThrow();
97
- expect(() =>
98
- toolBox.onPointerMove({ type: 'pointermove' } as PointerEvent),
99
- ).not.toThrow();
100
- });
101
-
102
- it('should execute pointer up event on tool', () => {
103
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
104
- expect(() =>
105
- toolBox.onPointerUp({ type: 'pointerup' } as PointerEvent),
106
- ).not.toThrow();
107
- expect(() => toolBox.UseTool('select')).not.toThrow();
108
- expect(() =>
109
- toolBox.onPointerUp({ type: 'pointerup' } as PointerEvent),
110
- ).not.toThrow();
111
- });
112
-
113
- it('should execute wheel event on tool', () => {
114
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
115
- expect(() =>
116
- toolBox.onWheel({ type: 'wheel' } as WheelEvent),
117
- ).not.toThrow();
118
- expect(() => toolBox.UseTool('select')).not.toThrow();
119
- expect(() =>
120
- toolBox.onWheel({ type: 'wheel' } as WheelEvent),
121
- ).not.toThrow();
122
- });
123
-
124
- it('should get active tool', () => {
125
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
126
- expect(toolBox.GetActiveTool()).toBeDefined();
127
- });
128
-
129
- it('should set gizmo mode', () => {
130
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
131
- expect(() => toolBox.SetGizmoMode('translate')).not.toThrow();
132
- });
133
-
134
- it('should set gizmo active', () => {
135
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
136
- expect(() => toolBox.SetGizmoVisibility(true)).not.toThrow();
137
- });
138
-
139
- it('should set gizmo unified scale', () => {
140
- const toolBox = new DIVEToolbox({} as DIVEScene, mockController);
141
- expect(() => toolBox.SetGizmoScaleLinked(true)).not.toThrow();
142
- });
143
- });
@@ -1,92 +0,0 @@
1
- import { type Object3D } from 'three';
2
- import { type DIVEScene } from '../../scene/Scene.ts';
3
- import DIVETransformTool from '../transform/TransformTool.ts';
4
- import { findInterface } from '../../helper/findInterface/findInterface.ts';
5
- import type DIVEOrbitControls from '../../controls/OrbitControls.ts';
6
- import { type DIVESelectable } from '../../interface/Selectable.ts';
7
- import { type DIVEMovable } from '../../interface/Movable.ts';
8
- import { type DIVEBaseTool } from '../BaseTool.ts';
9
-
10
- export const isSelectTool = (tool: DIVEBaseTool): tool is DIVESelectTool => {
11
- return (tool as DIVESelectTool).isSelectTool !== undefined;
12
- };
13
-
14
- export interface DIVEObjectEventMap {
15
- select: object;
16
- }
17
-
18
- /**
19
- * A Tool to select and move objects in the scene.
20
- *
21
- * Objects have to implement the DIVESelectable interface to be selectable and DIVEMovable to be movable.
22
- *
23
- * @module
24
- */
25
-
26
- export class DIVESelectTool extends DIVETransformTool {
27
- readonly isSelectTool: boolean = true;
28
-
29
- constructor(scene: DIVEScene, controller: DIVEOrbitControls) {
30
- super(scene, controller);
31
- this.name = 'SelectTool';
32
- }
33
-
34
- public Activate(): void {}
35
-
36
- public Select(selectable: DIVESelectable): void {
37
- this.AttachGizmo(selectable);
38
-
39
- if (selectable.onSelect) selectable.onSelect();
40
- }
41
-
42
- public Deselect(selectable: DIVESelectable): void {
43
- this.DetachGizmo();
44
-
45
- if (selectable.onDeselect) selectable.onDeselect();
46
- }
47
-
48
- public AttachGizmo(selectable: DIVESelectable): void {
49
- if ('isMovable' in selectable) {
50
- const movable = selectable as Object3D &
51
- DIVESelectable &
52
- DIVEMovable;
53
- this._gizmo.attach(movable);
54
- this.SetGizmoVisibility(movable.visible);
55
- }
56
- }
57
-
58
- public DetachGizmo(): void {
59
- this._gizmo.detach();
60
- }
61
-
62
- public onClick(e: PointerEvent): void {
63
- super.onClick(e);
64
-
65
- const first = this._raycaster
66
- .intersectObjects(this._scene.Root.children, true)
67
- .filter((intersect) => intersect.object.visible)[0];
68
- const selectable = findInterface<DIVESelectable>(
69
- first?.object,
70
- 'isSelectable',
71
- );
72
-
73
- // if nothing is hit
74
- if (!first || !selectable) {
75
- if (this._gizmo.object) {
76
- this.Deselect(this._gizmo.object as Object3D & DIVESelectable);
77
- }
78
- return;
79
- }
80
-
81
- if (this._gizmo.object) {
82
- // do not reselect if the same object was clicked
83
- if (this._gizmo.object.uuid === selectable.uuid) return;
84
-
85
- // deselect previous object
86
- this.Deselect(this._gizmo.object as Object3D & DIVESelectable);
87
- }
88
-
89
- // select clicked object
90
- this.Select(selectable);
91
- }
92
- }
@@ -1,237 +0,0 @@
1
- import { DIVESelectTool, isSelectTool } from '../SelectTool';
2
- import { DIVEScene } from '../../../scene/Scene';
3
- import DIVEOrbitControls from '../../../controls/OrbitControls';
4
- import { DIVERenderer } from '../../../renderer/Renderer';
5
- import { DIVESelectable } from '../../../interface/Selectable';
6
- import type DIVEPerspectiveCamera from '../../../camera/PerspectiveCamera';
7
- import { type Object3D } from 'three';
8
- import { type DIVEBaseTool } from '../../BaseTool';
9
- import { DIVEAnimationSystem } from '../../../animation/AnimationSystem';
10
- import { Tween } from '@tweenjs/tween.js';
11
-
12
- jest.mock('../../../renderer/Renderer', () => {
13
- return jest.fn(function () {
14
- return this;
15
- });
16
- });
17
-
18
- jest.mock('../../../camera/PerspectiveCamera', () => {
19
- return jest.fn(function () {
20
- this.isPerspectiveCamera = true;
21
- this.layers = {
22
- mask: 0,
23
- };
24
- return this;
25
- });
26
- });
27
-
28
- jest.mock('../../../controls/OrbitControls', () => {
29
- return jest.fn(function () {
30
- this.enabled = true;
31
- this.domElement = {
32
- clientWIdth: 0,
33
- clientHeight: 0,
34
- };
35
- this.object = {
36
- layers: {
37
- mask: 0,
38
- },
39
- };
40
- return this;
41
- });
42
- });
43
-
44
- jest.mock('../../../animation/AnimationSystem', () => {
45
- return {
46
- DIVEAnimationSystem: jest.fn(function () {
47
- this.domElement = {
48
- style: {},
49
- };
50
- this.Animate = <T extends object>(obj: T) => {
51
- return new Tween<T>(obj);
52
- };
53
-
54
- return this;
55
- }),
56
- };
57
- });
58
-
59
- jest.mock('../../../scene/Scene', () => {
60
- return {
61
- DIVEScene: jest.fn(function () {
62
- this.add = jest.fn();
63
- this.children = [];
64
- this.Root = {
65
- children: [],
66
- };
67
- return this;
68
- }),
69
- };
70
- });
71
-
72
- const mockCamera: DIVEPerspectiveCamera = {} as DIVEPerspectiveCamera;
73
- const mockRenderer = {
74
- render: jest.fn(),
75
- OnResize: jest.fn(),
76
- } as unknown as DIVERenderer;
77
- const mockScene: DIVEScene = new DIVEScene();
78
- const mockAnimSystem = new DIVEAnimationSystem(mockRenderer);
79
- const mockController: DIVEOrbitControls = new DIVEOrbitControls(
80
- mockCamera,
81
- mockRenderer,
82
- mockAnimSystem,
83
- );
84
-
85
- let selectTool: DIVESelectTool;
86
- let intersectObjectsSpy: jest.SpyInstance;
87
-
88
- describe('dive/toolbox/select/DIVESelectTool', () => {
89
- beforeEach(() => {
90
- selectTool = new DIVESelectTool(mockScene, mockController);
91
- intersectObjectsSpy = jest
92
- .spyOn(selectTool['_raycaster'], 'intersectObjects')
93
- .mockReturnValue([]);
94
- });
95
-
96
- it('should test if it is SelectTool', () => {
97
- const selectTool = { isSelectTool: true } as unknown as DIVEBaseTool;
98
- expect(isSelectTool(selectTool)).toBeDefined();
99
- });
100
-
101
- it('should instantiate', () => {
102
- expect(selectTool).toBeDefined();
103
- });
104
-
105
- it('should activate', () => {
106
- expect(() => selectTool.Activate()).not.toThrow();
107
- });
108
-
109
- it('should execute onClick without hit', () => {
110
- selectTool.AttachGizmo({} as unknown as DIVESelectable);
111
- expect(() =>
112
- selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
113
- ).not.toThrow();
114
- });
115
-
116
- it('should execute onClick with hit', () => {
117
- intersectObjectsSpy.mockReturnValueOnce([
118
- {
119
- object: {
120
- uuid: 'test',
121
- visible: true,
122
- parent: {
123
- name: 'this is the test scene root!!!',
124
- parent: null,
125
- },
126
- },
127
- },
128
- ]);
129
-
130
- expect(() =>
131
- selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
132
- ).not.toThrow();
133
- });
134
-
135
- it('should execute onClick with same ISelectable hit', () => {
136
- const mock_onSelect = jest.fn();
137
-
138
- intersectObjectsSpy.mockReturnValueOnce([
139
- {
140
- object: {
141
- isSelectable: true,
142
- onSelect: mock_onSelect,
143
- visible: true,
144
- parent: {
145
- name: 'this is the test scene root!!!',
146
- parent: null,
147
- },
148
- uuid: 'test0',
149
- },
150
- },
151
- ]);
152
- selectTool.AttachGizmo({
153
- visible: true,
154
- isSelectable: true,
155
- uuid: 'test0',
156
- } as unknown as Object3D & DIVESelectable);
157
- expect(() =>
158
- selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
159
- ).not.toThrow();
160
- });
161
-
162
- it('should execute onClick with ISelectable hit', () => {
163
- const mock_onSelect = jest.fn();
164
-
165
- intersectObjectsSpy.mockReturnValueOnce([
166
- {
167
- object: {
168
- isSelectable: true,
169
- onSelect: mock_onSelect,
170
- visible: true,
171
- parent: {
172
- name: 'this is the test scene root!!!',
173
- parent: null,
174
- },
175
- uuid: 'test0',
176
- },
177
- },
178
- ]);
179
- selectTool.AttachGizmo({
180
- isSelectable: true,
181
- uuid: 'test1',
182
- } as unknown as Object3D & DIVESelectable);
183
- expect(() =>
184
- selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
185
- ).not.toThrow();
186
- });
187
-
188
- it('should execute onClick with IMovable hit', () => {
189
- const mock_onSelect = jest.fn();
190
-
191
- intersectObjectsSpy.mockReturnValueOnce([
192
- {
193
- object: {
194
- isSelectable: true,
195
- isMovable: true,
196
- onSelect: mock_onSelect,
197
- parent: {
198
- name: 'this is the test scene root!!!',
199
- parent: null,
200
- },
201
- },
202
- },
203
- ]);
204
-
205
- expect(() =>
206
- selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
207
- ).not.toThrow();
208
- });
209
-
210
- it('should Select', () => {
211
- const mock_onSelect = jest.fn();
212
- expect(() => selectTool.Select({ isSelectable: true })).not.toThrow();
213
- expect(() =>
214
- selectTool.Select({
215
- isMovable: true,
216
- onSelect: mock_onSelect,
217
- } as unknown as DIVESelectable),
218
- ).not.toThrow();
219
- expect(mock_onSelect).toHaveBeenCalledTimes(1);
220
- });
221
-
222
- it('should Deselect', () => {
223
- const mock_onDeselect = jest.fn();
224
- expect(() => selectTool.Deselect({ isSelectable: true })).not.toThrow();
225
- expect(() =>
226
- selectTool.Deselect({
227
- isMovable: true,
228
- onDeselect: mock_onDeselect,
229
- } as unknown as DIVESelectable),
230
- ).not.toThrow();
231
- expect(mock_onDeselect).toHaveBeenCalledTimes(1);
232
- });
233
-
234
- it('should set gizmo mode', () => {
235
- expect(() => selectTool.SetGizmoMode('translate')).not.toThrow();
236
- });
237
- });
@@ -1,166 +0,0 @@
1
- import { DIVEBaseTool } from '../BaseTool.ts';
2
- import { type DIVEScene } from '../../scene/Scene.ts';
3
- import type DIVEOrbitControls from '../../controls/OrbitControls.ts';
4
- import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
5
- import { type DIVEMovable } from '../../interface/Movable.ts';
6
- import { implementsInterface } from '../../helper/isInterface/implementsInterface.ts';
7
- import { DIVEGizmo } from '../../gizmo/Gizmo.ts';
8
- import { type Mesh, type MeshBasicMaterial } from 'three';
9
- import {
10
- AxesColorBlue,
11
- AxesColorGreen,
12
- AxesColorRed,
13
- } from '../../constant/AxisHelperColors.ts';
14
-
15
- export const isTransformTool = (
16
- tool: DIVEBaseTool,
17
- ): tool is DIVETransformTool => {
18
- return (tool as DIVETransformTool).isTransformTool !== undefined;
19
- };
20
-
21
- export interface DIVEObjectEventMap {
22
- select: object;
23
- }
24
-
25
- /**
26
- * A Tool to select and move objects in the scene.
27
- *
28
- * Objects have to implement the DIVESelectable interface to be selectable and DIVEMovable to be movable.
29
- *
30
- * @module
31
- */
32
-
33
- export default class DIVETransformTool extends DIVEBaseTool {
34
- readonly isTransformTool: boolean = true;
35
-
36
- private _scaleLinked: boolean;
37
-
38
- protected _gizmo: TransformControls | DIVEGizmo;
39
-
40
- constructor(scene: DIVEScene, controller: DIVEOrbitControls) {
41
- super(scene, controller);
42
- this.name = 'DIVETransformTool';
43
-
44
- this._scaleLinked = false;
45
-
46
- this._gizmo = this.initGizmo() as TransformControls;
47
-
48
- this._scene.add(this._gizmo);
49
- }
50
-
51
- public Activate(): void {}
52
-
53
- public SetGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void {
54
- this._gizmo.mode = mode;
55
- }
56
-
57
- public SetGizmoVisibility(active: boolean): void {
58
- const contains = this._scene.children.includes(this._gizmo);
59
- if (active && !contains) {
60
- this._scene.add(this._gizmo);
61
- if ('isTransformControls' in this._gizmo) {
62
- (this._gizmo as TransformControls)
63
- .getRaycaster()
64
- .layers.enableAll();
65
- }
66
- } else if (!active && contains) {
67
- this._scene.remove(this._gizmo);
68
- if ('isTransformControls' in this._gizmo) {
69
- (this._gizmo as TransformControls)
70
- .getRaycaster()
71
- .layers.disableAll();
72
- }
73
- }
74
- }
75
-
76
- public SetGizmoScaleLinked(linked: boolean): void {
77
- this._scaleLinked = linked;
78
- }
79
-
80
- // only used for optimizing pointer events with DIVEGizmo
81
- // public onPointerDown(e: PointerEvent): void {
82
- // super.onPointerDown(e);
83
-
84
- // if (this._hovered) {
85
- // this._dragRaycastOnObjects = (
86
- // this._gizmo as DIVEGizmo
87
- // ).gizmoPlane?.children;
88
- // }
89
- // }
90
-
91
- // only used for optimizing pointer events with DIVEGizmo
92
- // protected raycast(): Intersection[] {
93
- // return super.raycast((this._gizmo as DIVEGizmo).gizmoNode.children);
94
- // }
95
-
96
- private initGizmo(): TransformControls | DIVEGizmo {
97
- const g = new TransformControls(
98
- // this._controller,
99
- this._controller.object,
100
- this._controller.domElement,
101
- );
102
- // g.debug = true;
103
- g.mode = 'translate';
104
-
105
- g.traverse((child) => {
106
- if (!('isMesh' in child)) return;
107
-
108
- const material = (child as Mesh).material as MeshBasicMaterial;
109
-
110
- if (child.name === 'X') {
111
- material.color.set(AxesColorRed);
112
- }
113
- if (child.name === 'Y') {
114
- material.color.set(AxesColorGreen);
115
- }
116
- if (child.name === 'Z') {
117
- material.color.set(AxesColorBlue);
118
- }
119
- if (child.name === 'XY') {
120
- material.color.set(AxesColorBlue);
121
- }
122
- if (child.name === 'YZ') {
123
- material.color.set(AxesColorRed);
124
- }
125
- if (child.name === 'XZ') {
126
- material.color.set(AxesColorGreen);
127
- }
128
- });
129
-
130
- // happens when pointerDown event is called on gizmo
131
- g.addEventListener('mouseDown', () => {
132
- this._controller.enabled = false;
133
-
134
- if (!implementsInterface<DIVEMovable>(g.object, 'isMovable'))
135
- return;
136
- if (!g.object.onMoveStart) return;
137
- g.object.onMoveStart();
138
- });
139
-
140
- // happens when pointerMove event is called on gizmo
141
- g.addEventListener('objectChange', () => {
142
- if (!implementsInterface<DIVEMovable>(g.object, 'isMovable'))
143
- return;
144
- if (!g.object.onMove) return;
145
- g.object.onMove();
146
-
147
- if (this._scaleLinked) {
148
- const scale = g.object.scale;
149
- const averageScale = (scale.x + scale.y + scale.z) / 3;
150
- g.object.scale.set(averageScale, averageScale, averageScale);
151
- }
152
- });
153
-
154
- // happens when pointerUp event is called on gizmo
155
- g.addEventListener('mouseUp', () => {
156
- this._controller.enabled = true;
157
-
158
- if (!implementsInterface<DIVEMovable>(g.object, 'isMovable'))
159
- return;
160
- if (!g.object.onMoveEnd) return;
161
- g.object.onMoveEnd();
162
- });
163
-
164
- return g;
165
- }
166
- }