@shopware-ag/dive 1.18.4 → 1.18.5-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 (139) hide show
  1. package/build/AR-B6LRgTEL.js +1482 -0
  2. package/build/AR-B6LRgTEL.js.map +1 -0
  3. package/build/AR-YJZL1lm5.cjs +170 -0
  4. package/build/AR-YJZL1lm5.cjs.map +1 -0
  5. package/build/dive-BmDCwQRo.js +24811 -0
  6. package/build/dive-BmDCwQRo.js.map +1 -0
  7. package/build/dive-C-5_QywE.cjs +3857 -0
  8. package/build/dive-C-5_QywE.cjs.map +1 -0
  9. package/build/dive.cjs +2 -4860
  10. package/build/dive.cjs.map +1 -1
  11. package/build/dive.d.ts +6 -1186
  12. package/build/dive.js +7 -4889
  13. package/build/dive.js.map +1 -1
  14. package/build/src/animation/AnimationSystem.d.ts +16 -0
  15. package/build/src/ar/AR.d.ts +21 -0
  16. package/build/src/ar/arquicklook/ARQuickLook.d.ts +8 -0
  17. package/build/src/ar/sceneviewer/SceneViewer.d.ts +7 -0
  18. package/build/src/ar/webxr/WebXR.d.ts +21 -0
  19. package/build/src/ar/webxr/controller/WebXRController.d.ts +46 -0
  20. package/build/src/ar/webxr/crosshair/WebXRCrosshair.d.ts +7 -0
  21. package/build/src/ar/webxr/origin/WebXROrigin.d.ts +31 -0
  22. package/build/src/ar/webxr/overlay/Overlay.d.ts +8 -0
  23. package/build/src/ar/webxr/raycaster/WebXRRaycaster.d.ts +40 -0
  24. package/build/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.d.ts +15 -0
  25. package/build/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.d.ts +12 -0
  26. package/build/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.d.ts +73 -0
  27. package/build/src/axiscamera/AxisCamera.d.ts +18 -0
  28. package/build/src/camera/PerspectiveCamera.d.ts +20 -0
  29. package/build/src/com/Communication.d.ts +77 -0
  30. package/build/src/com/actions/camera/computeencompassingview.d.ts +9 -0
  31. package/build/src/com/actions/camera/getcameratransform.d.ts +9 -0
  32. package/build/src/com/actions/camera/movecamera.d.ts +15 -0
  33. package/build/src/com/actions/camera/resetcamera.d.ts +7 -0
  34. package/build/src/com/actions/camera/setcameralayer.d.ts +7 -0
  35. package/build/src/com/actions/camera/setcameratransform.d.ts +9 -0
  36. package/build/src/com/actions/camera/zoomcamera.d.ts +8 -0
  37. package/build/src/com/actions/index.d.ts +58 -0
  38. package/build/src/com/actions/media/generatemedia.d.ts +15 -0
  39. package/build/src/com/actions/object/addobject.d.ts +6 -0
  40. package/build/src/com/actions/object/deleteobject.d.ts +8 -0
  41. package/build/src/com/actions/object/deselectobject.d.ts +8 -0
  42. package/build/src/com/actions/object/getallobjects.d.ts +6 -0
  43. package/build/src/com/actions/object/getobjects.d.ts +8 -0
  44. package/build/src/com/actions/object/model/dropit.d.ts +7 -0
  45. package/build/src/com/actions/object/model/modelloaded.d.ts +7 -0
  46. package/build/src/com/actions/object/model/placeonfloor.d.ts +7 -0
  47. package/build/src/com/actions/object/selectobject.d.ts +8 -0
  48. package/build/src/com/actions/object/setparent.d.ts +13 -0
  49. package/build/src/com/actions/object/updateobject.d.ts +8 -0
  50. package/build/src/com/actions/scene/exportscene.d.ts +8 -0
  51. package/build/src/com/actions/scene/getallscenedata.d.ts +6 -0
  52. package/build/src/com/actions/scene/launchar.d.ts +6 -0
  53. package/build/src/com/actions/scene/setbackground.d.ts +7 -0
  54. package/build/src/com/actions/scene/updatescene.d.ts +11 -0
  55. package/build/src/com/actions/toolbox/select/setgizmomode.d.ts +7 -0
  56. package/build/src/com/actions/toolbox/transform/setgizmoscalelinked.d.ts +5 -0
  57. package/build/src/com/actions/toolbox/transform/setgizmovisible.d.ts +5 -0
  58. package/build/src/com/actions/toolbox/usetool.d.ts +8 -0
  59. package/build/src/com/types/COMBaseEntity.d.ts +8 -0
  60. package/build/src/com/types/COMEntity.d.ts +6 -0
  61. package/build/src/com/types/COMEntityType.d.ts +1 -0
  62. package/build/src/com/types/COMGeometry.d.ts +7 -0
  63. package/build/src/com/types/COMGeometryType.d.ts +1 -0
  64. package/build/src/com/types/COMGroup.d.ts +8 -0
  65. package/build/src/com/types/COMLight.d.ts +10 -0
  66. package/build/src/com/types/COMMaterial.d.ts +11 -0
  67. package/build/src/com/types/COMModel.d.ts +11 -0
  68. package/build/src/com/types/COMPov.d.ts +7 -0
  69. package/build/src/com/types/COMPrimitive.d.ts +11 -0
  70. package/build/src/com/types/index.d.ts +11 -0
  71. package/build/src/constant/AxisHelperColors.d.ts +6 -0
  72. package/build/src/constant/GridColors.d.ts +2 -0
  73. package/build/src/constant/VisibilityLayerMask.d.ts +5 -0
  74. package/build/src/controls/OrbitControls.d.ts +38 -0
  75. package/build/src/dive.d.ts +64 -0
  76. package/build/src/events/EventExecutor.d.ts +5 -0
  77. package/build/src/exporters/usdz/USDZExporter.d.ts +15 -0
  78. package/build/src/gizmo/Gizmo.d.ts +27 -0
  79. package/build/src/gizmo/handles/AxisHandle.d.ts +30 -0
  80. package/build/src/gizmo/handles/RadialHandle.d.ts +30 -0
  81. package/build/src/gizmo/handles/ScaleHandle.d.ts +33 -0
  82. package/build/src/gizmo/plane/GizmoPlane.d.ts +12 -0
  83. package/build/src/gizmo/rotate/RotateGizmo.d.ts +17 -0
  84. package/build/src/gizmo/scale/ScaleGizmo.d.ts +20 -0
  85. package/build/src/gizmo/translate/TranslateGizmo.d.ts +17 -0
  86. package/build/src/grid/Grid.d.ts +10 -0
  87. package/build/src/group/Group.d.ts +23 -0
  88. package/build/src/helper/applyMixins/applyMixins.d.ts +8 -0
  89. package/build/src/helper/findInterface/findInterface.d.ts +2 -0
  90. package/build/src/helper/findSceneRecursive/findSceneRecursive.d.ts +9 -0
  91. package/build/src/helper/getObjectDelta/getObjectDelta.d.ts +4 -0
  92. package/build/src/helper/isInterface/implementsInterface.d.ts +2 -0
  93. package/build/src/info/Info.d.ts +39 -0
  94. package/build/src/interface/Draggable.d.ts +7 -0
  95. package/build/src/interface/Hoverable.d.ts +7 -0
  96. package/build/src/interface/Movable.d.ts +11 -0
  97. package/build/src/interface/Rotatable.d.ts +9 -0
  98. package/build/src/interface/Scalable.d.ts +9 -0
  99. package/build/src/interface/Selectable.d.ts +10 -0
  100. package/build/src/io/IO.d.ts +10 -0
  101. package/build/src/io/gltf/GLTFIO.d.ts +12 -0
  102. package/build/src/light/AmbientLight.d.ts +17 -0
  103. package/build/src/light/PointLight.d.ts +29 -0
  104. package/build/src/light/SceneLight.d.ts +18 -0
  105. package/build/src/loadingmanager/LoadingManager.d.ts +14 -0
  106. package/build/src/math/ceil/ceilExp.d.ts +1 -0
  107. package/build/src/math/degToRad/degToRad.d.ts +1 -0
  108. package/build/src/math/floor/floorExp.d.ts +1 -0
  109. package/build/src/math/helper/shift.d.ts +1 -0
  110. package/build/src/math/index.d.ts +18 -0
  111. package/build/src/math/radToDeg/radToDeg.d.ts +1 -0
  112. package/build/src/math/round/roundExp.d.ts +1 -0
  113. package/build/src/math/signedAngleTo/signedAngleTo.d.ts +9 -0
  114. package/build/src/math/toFixed/toFixedExp.d.ts +1 -0
  115. package/build/src/math/truncate/truncateExp.d.ts +1 -0
  116. package/build/src/mediacreator/MediaCreator.d.ts +17 -0
  117. package/build/src/model/Model.d.ts +21 -0
  118. package/build/src/node/Node.d.ts +24 -0
  119. package/build/src/primitive/Primitive.d.ts +28 -0
  120. package/build/src/primitive/floor/Floor.d.ts +14 -0
  121. package/build/src/renderer/Renderer.d.ts +69 -0
  122. package/build/src/scene/Scene.d.ts +46 -0
  123. package/build/src/scene/root/Root.d.ts +42 -0
  124. package/build/src/scene/xrroot/XRRoot.d.ts +17 -0
  125. package/build/src/scene/xrroot/xrlightroot/XRLightRoot.d.ts +13 -0
  126. package/build/src/toolbox/BaseTool.d.ts +48 -0
  127. package/build/src/toolbox/Toolbox.d.ts +31 -0
  128. package/build/src/toolbox/select/SelectTool.d.ts +26 -0
  129. package/build/src/toolbox/transform/TransformTool.d.ts +27 -0
  130. package/build/src/types/SceneData.d.ts +19 -0
  131. package/build/src/types/SceneObjects.d.ts +7 -0
  132. package/build/src/types/SceneType.d.ts +4 -0
  133. package/build/src/types/index.d.ts +4 -0
  134. package/package.json +9 -8
  135. package/src/camera/PerspectiveCamera.ts +1 -1
  136. package/src/com/Communication.ts +33 -8
  137. package/src/com/__test__/Communication.test.ts +2 -1
  138. package/src/dive.ts +0 -3
  139. package/build/dive.d.cts +0 -1186
package/build/dive.cjs CHANGED
@@ -1,4860 +1,2 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __esm = (fn, res) => function __init() {
26
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
27
- };
28
- var __export = (target, all) => {
29
- for (var name in all)
30
- __defProp(target, name, { get: all[name], enumerable: true });
31
- };
32
- var __copyProps = (to, from, except, desc) => {
33
- if (from && typeof from === "object" || typeof from === "function") {
34
- for (let key of __getOwnPropNames(from))
35
- if (!__hasOwnProp.call(to, key) && key !== except)
36
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
37
- }
38
- return to;
39
- };
40
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
41
- // If the importer is in node compatibility mode or this is not an ESM
42
- // file that has been converted to a CommonJS file using a Babel-
43
- // compatible transform (i.e. "__esModule" has not been set), then set
44
- // "default" to the CommonJS "module.exports" for node compatibility.
45
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
46
- mod
47
- ));
48
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
49
- var __async = (__this, __arguments, generator) => {
50
- return new Promise((resolve, reject) => {
51
- var fulfilled = (value) => {
52
- try {
53
- step(generator.next(value));
54
- } catch (e) {
55
- reject(e);
56
- }
57
- };
58
- var rejected = (value) => {
59
- try {
60
- step(generator.throw(value));
61
- } catch (e) {
62
- reject(e);
63
- }
64
- };
65
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
66
- step((generator = generator.apply(__this, __arguments)).next());
67
- });
68
- };
69
-
70
- // src/constant/VisibilityLayerMask.ts
71
- var DEFAULT_LAYER_MASK, COORDINATE_LAYER_MASK, UI_LAYER_MASK, HELPER_LAYER_MASK, PRODUCT_LAYER_MASK;
72
- var init_VisibilityLayerMask = __esm({
73
- "src/constant/VisibilityLayerMask.ts"() {
74
- "use strict";
75
- DEFAULT_LAYER_MASK = 1;
76
- COORDINATE_LAYER_MASK = 2;
77
- UI_LAYER_MASK = 4;
78
- HELPER_LAYER_MASK = 8;
79
- PRODUCT_LAYER_MASK = 16;
80
- }
81
- });
82
-
83
- // src/helper/isInterface/implementsInterface.ts
84
- function implementsInterface(object, discriminator) {
85
- if (!object) return false;
86
- return discriminator in object;
87
- }
88
- var init_implementsInterface = __esm({
89
- "src/helper/isInterface/implementsInterface.ts"() {
90
- "use strict";
91
- }
92
- });
93
-
94
- // src/helper/findInterface/findInterface.ts
95
- function findInterface(object, discriminator) {
96
- if (!object) return void 0;
97
- if (implementsInterface(object, discriminator)) return object;
98
- return findInterface(object.parent, discriminator);
99
- }
100
- var init_findInterface = __esm({
101
- "src/helper/findInterface/findInterface.ts"() {
102
- "use strict";
103
- init_implementsInterface();
104
- }
105
- });
106
-
107
- // src/toolbox/BaseTool.ts
108
- var import_three3, DIVEBaseTool;
109
- var init_BaseTool = __esm({
110
- "src/toolbox/BaseTool.ts"() {
111
- "use strict";
112
- import_three3 = require("three");
113
- init_VisibilityLayerMask();
114
- init_findInterface();
115
- DIVEBaseTool = class {
116
- constructor(scene, controller) {
117
- this.POINTER_DRAG_THRESHOLD = 1e-3;
118
- this.name = "BaseTool";
119
- this._canvas = controller.domElement;
120
- this._scene = scene;
121
- this._controller = controller;
122
- this._pointer = new import_three3.Vector2();
123
- this._pointerPrimaryDown = false;
124
- this._pointerMiddleDown = false;
125
- this._pointerSecondaryDown = false;
126
- this._lastPointerDown = new import_three3.Vector2();
127
- this._lastPointerUp = new import_three3.Vector2();
128
- this._raycaster = new import_three3.Raycaster();
129
- this._raycaster.layers.mask = PRODUCT_LAYER_MASK | UI_LAYER_MASK;
130
- this._intersects = [];
131
- this._hovered = null;
132
- this._dragging = false;
133
- this._dragStart = new import_three3.Vector3();
134
- this._dragCurrent = new import_three3.Vector3();
135
- this._dragEnd = new import_three3.Vector3();
136
- this._dragDelta = new import_three3.Vector3();
137
- this._draggable = null;
138
- this._dragRaycastOnObjects = null;
139
- }
140
- get _pointerAnyDown() {
141
- return this._pointerPrimaryDown || this._pointerMiddleDown || this._pointerSecondaryDown;
142
- }
143
- Activate() {
144
- }
145
- Deactivate() {
146
- }
147
- onPointerDown(e) {
148
- var _a;
149
- switch (e.button) {
150
- case 0: {
151
- this._pointerPrimaryDown = true;
152
- break;
153
- }
154
- case 1: {
155
- this._pointerMiddleDown = true;
156
- break;
157
- }
158
- case 2: {
159
- this._pointerSecondaryDown = true;
160
- break;
161
- }
162
- default: {
163
- console.warn(
164
- "DIVEBaseTool.onPointerDown: Unknown button: " + e.button
165
- );
166
- }
167
- }
168
- this._lastPointerDown.copy(this._pointer);
169
- this._draggable = findInterface(
170
- (_a = this._intersects[0]) == null ? void 0 : _a.object,
171
- "isDraggable"
172
- ) || null;
173
- }
174
- onDragStart(e) {
175
- if (!this._draggable) return;
176
- if (this._dragRaycastOnObjects !== null) {
177
- this._intersects = this._raycaster.intersectObjects(
178
- this._dragRaycastOnObjects,
179
- true
180
- );
181
- }
182
- if (this._intersects.length === 0) return;
183
- this._dragStart.copy(this._intersects[0].point.clone());
184
- this._dragCurrent.copy(this._intersects[0].point.clone());
185
- this._dragEnd.copy(this._dragStart.clone());
186
- this._dragDelta.set(0, 0, 0);
187
- if (this._draggable && this._draggable.onDragStart) {
188
- this._draggable.onDragStart({
189
- dragStart: this._dragStart,
190
- dragCurrent: this._dragCurrent,
191
- dragEnd: this._dragEnd,
192
- dragDelta: this._dragDelta
193
- });
194
- this._dragging = true;
195
- this._controller.enabled = false;
196
- }
197
- }
198
- onPointerMove(e) {
199
- var _a;
200
- this._pointer.x = e.offsetX / this._canvas.clientWidth * 2 - 1;
201
- this._pointer.y = -(e.offsetY / this._canvas.clientHeight) * 2 + 1;
202
- this._raycaster.setFromCamera(this._pointer, this._controller.object);
203
- this._intersects = this.raycast(this._scene.children);
204
- const hoverable = findInterface(
205
- (_a = this._intersects[0]) == null ? void 0 : _a.object,
206
- "isHoverable"
207
- );
208
- if (this._intersects[0] && hoverable) {
209
- if (!this._hovered) {
210
- if (hoverable.onPointerEnter)
211
- hoverable.onPointerEnter(this._intersects[0]);
212
- this._hovered = hoverable;
213
- return;
214
- }
215
- if (this._hovered.uuid !== hoverable.uuid) {
216
- if (this._hovered.onPointerLeave)
217
- this._hovered.onPointerLeave();
218
- if (hoverable.onPointerEnter)
219
- hoverable.onPointerEnter(this._intersects[0]);
220
- this._hovered = hoverable;
221
- return;
222
- }
223
- if (hoverable.onPointerOver)
224
- hoverable.onPointerOver(this._intersects[0]);
225
- this._hovered = hoverable;
226
- } else {
227
- if (this._hovered) {
228
- if (this._hovered.onPointerLeave)
229
- this._hovered.onPointerLeave();
230
- }
231
- this._hovered = null;
232
- }
233
- if (this._pointerAnyDown) {
234
- if (!this._dragging) {
235
- this.onDragStart(e);
236
- }
237
- this.onDrag(e);
238
- }
239
- }
240
- onDrag(e) {
241
- if (this._dragRaycastOnObjects !== null) {
242
- this._intersects = this._raycaster.intersectObjects(
243
- this._dragRaycastOnObjects,
244
- true
245
- );
246
- }
247
- const intersect = this._intersects[0];
248
- if (!intersect) return;
249
- this._dragCurrent.copy(intersect.point.clone());
250
- this._dragEnd.copy(intersect.point.clone());
251
- this._dragDelta.subVectors(
252
- this._dragCurrent.clone(),
253
- this._dragStart.clone()
254
- );
255
- if (this._draggable && this._draggable.onDrag) {
256
- this._draggable.onDrag({
257
- dragStart: this._dragStart,
258
- dragCurrent: this._dragCurrent,
259
- dragEnd: this._dragEnd,
260
- dragDelta: this._dragDelta
261
- });
262
- }
263
- }
264
- onPointerUp(e) {
265
- if (this.pointerWasDragged() || this._dragging) {
266
- if (this._draggable) {
267
- this.onDragEnd(e);
268
- }
269
- } else {
270
- this.onClick(e);
271
- }
272
- switch (e.button) {
273
- case 0:
274
- this._pointerPrimaryDown = false;
275
- break;
276
- case 1:
277
- this._pointerMiddleDown = false;
278
- break;
279
- case 2:
280
- this._pointerSecondaryDown = false;
281
- break;
282
- }
283
- this._lastPointerUp.copy(this._pointer);
284
- }
285
- onClick(e) {
286
- }
287
- onDragEnd(e) {
288
- const intersect = this._intersects[0];
289
- if (intersect) {
290
- this._dragEnd.copy(intersect.point.clone());
291
- this._dragCurrent.copy(intersect.point.clone());
292
- this._dragDelta.subVectors(
293
- this._dragCurrent.clone(),
294
- this._dragStart.clone()
295
- );
296
- }
297
- if (this._draggable && this._draggable.onDragEnd) {
298
- this._draggable.onDragEnd({
299
- dragStart: this._dragStart,
300
- dragCurrent: this._dragCurrent,
301
- dragEnd: this._dragEnd,
302
- dragDelta: this._dragDelta
303
- });
304
- }
305
- this._draggable = null;
306
- this._dragging = false;
307
- this._dragStart.set(0, 0, 0);
308
- this._dragCurrent.set(0, 0, 0);
309
- this._dragEnd.set(0, 0, 0);
310
- this._dragDelta.set(0, 0, 0);
311
- this._controller.enabled = true;
312
- }
313
- onWheel(e) {
314
- }
315
- raycast(objects) {
316
- if (objects !== void 0)
317
- return this._raycaster.intersectObjects(objects, true).filter((i) => i.object.visible);
318
- return this._raycaster.intersectObjects(this._scene.children, true).filter((i) => i.object.visible);
319
- }
320
- pointerWasDragged() {
321
- return this._lastPointerDown.distanceTo(this._pointer) > this.POINTER_DRAG_THRESHOLD;
322
- }
323
- };
324
- }
325
- });
326
-
327
- // src/constant/AxisHelperColors.ts
328
- var AxesColorRedLetter, AxesColorGreenLetter, AxesColorBlueLetter, AxesColorRed, AxesColorGreen, AxesColorBlue;
329
- var init_AxisHelperColors = __esm({
330
- "src/constant/AxisHelperColors.ts"() {
331
- "use strict";
332
- AxesColorRedLetter = "#c20017";
333
- AxesColorGreenLetter = "#00ab26";
334
- AxesColorBlueLetter = "#0081d4";
335
- AxesColorRed = AxesColorRedLetter;
336
- AxesColorGreen = AxesColorGreenLetter;
337
- AxesColorBlue = AxesColorBlueLetter;
338
- }
339
- });
340
-
341
- // src/toolbox/transform/TransformTool.ts
342
- var import_TransformControls, DIVETransformTool;
343
- var init_TransformTool = __esm({
344
- "src/toolbox/transform/TransformTool.ts"() {
345
- "use strict";
346
- init_BaseTool();
347
- import_TransformControls = require("three/examples/jsm/controls/TransformControls");
348
- init_implementsInterface();
349
- init_AxisHelperColors();
350
- DIVETransformTool = class extends DIVEBaseTool {
351
- constructor(scene, controller) {
352
- super(scene, controller);
353
- this.isTransformTool = true;
354
- this.name = "DIVETransformTool";
355
- this._scaleLinked = false;
356
- this._gizmo = this.initGizmo();
357
- this._scene.add(this._gizmo);
358
- }
359
- Activate() {
360
- }
361
- SetGizmoMode(mode) {
362
- this._gizmo.mode = mode;
363
- }
364
- SetGizmoVisibility(active) {
365
- const contains = this._scene.children.includes(this._gizmo);
366
- if (active && !contains) {
367
- this._scene.add(this._gizmo);
368
- if ("isTransformControls" in this._gizmo) {
369
- this._gizmo.getRaycaster().layers.enableAll();
370
- }
371
- } else if (!active && contains) {
372
- this._scene.remove(this._gizmo);
373
- if ("isTransformControls" in this._gizmo) {
374
- this._gizmo.getRaycaster().layers.disableAll();
375
- }
376
- }
377
- }
378
- SetGizmoScaleLinked(linked) {
379
- this._scaleLinked = linked;
380
- }
381
- // only used for optimizing pointer events with DIVEGizmo
382
- // public onPointerDown(e: PointerEvent): void {
383
- // super.onPointerDown(e);
384
- // if (this._hovered) {
385
- // this._dragRaycastOnObjects = (
386
- // this._gizmo as DIVEGizmo
387
- // ).gizmoPlane?.children;
388
- // }
389
- // }
390
- // only used for optimizing pointer events with DIVEGizmo
391
- // protected raycast(): Intersection[] {
392
- // return super.raycast((this._gizmo as DIVEGizmo).gizmoNode.children);
393
- // }
394
- initGizmo() {
395
- const g = new import_TransformControls.TransformControls(
396
- // this._controller,
397
- this._controller.object,
398
- this._controller.domElement
399
- );
400
- g.mode = "translate";
401
- g.traverse((child) => {
402
- if (!("isMesh" in child)) return;
403
- const material = child.material;
404
- if (child.name === "X") {
405
- material.color.set(AxesColorRed);
406
- }
407
- if (child.name === "Y") {
408
- material.color.set(AxesColorGreen);
409
- }
410
- if (child.name === "Z") {
411
- material.color.set(AxesColorBlue);
412
- }
413
- if (child.name === "XY") {
414
- material.color.set(AxesColorBlue);
415
- }
416
- if (child.name === "YZ") {
417
- material.color.set(AxesColorRed);
418
- }
419
- if (child.name === "XZ") {
420
- material.color.set(AxesColorGreen);
421
- }
422
- });
423
- g.addEventListener("mouseDown", () => {
424
- this._controller.enabled = false;
425
- if (!implementsInterface(g.object, "isMovable"))
426
- return;
427
- if (!g.object.onMoveStart) return;
428
- g.object.onMoveStart();
429
- });
430
- g.addEventListener("objectChange", () => {
431
- if (!implementsInterface(g.object, "isMovable"))
432
- return;
433
- if (!g.object.onMove) return;
434
- g.object.onMove();
435
- if (this._scaleLinked) {
436
- const scale = g.object.scale;
437
- const averageScale = (scale.x + scale.y + scale.z) / 3;
438
- g.object.scale.set(averageScale, averageScale, averageScale);
439
- }
440
- });
441
- g.addEventListener("mouseUp", () => {
442
- this._controller.enabled = true;
443
- if (!implementsInterface(g.object, "isMovable"))
444
- return;
445
- if (!g.object.onMoveEnd) return;
446
- g.object.onMoveEnd();
447
- });
448
- return g;
449
- }
450
- };
451
- }
452
- });
453
-
454
- // src/toolbox/select/SelectTool.ts
455
- var SelectTool_exports = {};
456
- __export(SelectTool_exports, {
457
- DIVESelectTool: () => DIVESelectTool,
458
- isSelectTool: () => isSelectTool
459
- });
460
- var isSelectTool, DIVESelectTool;
461
- var init_SelectTool = __esm({
462
- "src/toolbox/select/SelectTool.ts"() {
463
- "use strict";
464
- init_TransformTool();
465
- init_findInterface();
466
- isSelectTool = (tool) => {
467
- return tool.isSelectTool !== void 0;
468
- };
469
- DIVESelectTool = class extends DIVETransformTool {
470
- constructor(scene, controller) {
471
- super(scene, controller);
472
- this.isSelectTool = true;
473
- this.name = "SelectTool";
474
- }
475
- Activate() {
476
- }
477
- Select(selectable) {
478
- this.AttachGizmo(selectable);
479
- if (selectable.onSelect) selectable.onSelect();
480
- }
481
- Deselect(selectable) {
482
- this.DetachGizmo();
483
- if (selectable.onDeselect) selectable.onDeselect();
484
- }
485
- AttachGizmo(selectable) {
486
- if ("isMovable" in selectable) {
487
- const movable = selectable;
488
- this._gizmo.attach(movable);
489
- this.SetGizmoVisibility(movable.visible);
490
- }
491
- }
492
- DetachGizmo() {
493
- this._gizmo.detach();
494
- }
495
- onClick(e) {
496
- super.onClick(e);
497
- const first = this._raycaster.intersectObjects(this._scene.Root.children, true).filter((intersect) => intersect.object.visible)[0];
498
- const selectable = findInterface(
499
- first == null ? void 0 : first.object,
500
- "isSelectable"
501
- );
502
- if (!first || !selectable) {
503
- if (this._gizmo.object) {
504
- this.Deselect(this._gizmo.object);
505
- }
506
- return;
507
- }
508
- if (this._gizmo.object) {
509
- if (this._gizmo.object.uuid === selectable.uuid) return;
510
- this.Deselect(this._gizmo.object);
511
- }
512
- this.Select(selectable);
513
- }
514
- };
515
- }
516
- });
517
-
518
- // src/camera/PerspectiveCamera.ts
519
- var import_three4, DIVEPerspectiveCameraDefaultSettings, _DIVEPerspectiveCamera, DIVEPerspectiveCamera;
520
- var init_PerspectiveCamera = __esm({
521
- "src/camera/PerspectiveCamera.ts"() {
522
- "use strict";
523
- import_three4 = require("three");
524
- init_VisibilityLayerMask();
525
- DIVEPerspectiveCameraDefaultSettings = {
526
- fov: 80,
527
- near: 0.1,
528
- far: 1e3
529
- };
530
- _DIVEPerspectiveCamera = class _DIVEPerspectiveCamera extends import_three4.PerspectiveCamera {
531
- constructor(settings = DIVEPerspectiveCameraDefaultSettings) {
532
- super(
533
- settings.fov || DIVEPerspectiveCameraDefaultSettings.fov,
534
- 1,
535
- settings.near || DIVEPerspectiveCameraDefaultSettings.near,
536
- settings.far || DIVEPerspectiveCameraDefaultSettings.far
537
- );
538
- this.onSetCameraLayer = () => {
539
- };
540
- this.layers.mask = _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
541
- }
542
- OnResize(width, height) {
543
- this.aspect = width / height;
544
- this.updateProjectionMatrix();
545
- }
546
- SetCameraLayer(layer) {
547
- this.layers.mask = layer === "LIVE" ? _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK : _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
548
- this.onSetCameraLayer(this.layers.mask);
549
- }
550
- };
551
- _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK = DEFAULT_LAYER_MASK | UI_LAYER_MASK | HELPER_LAYER_MASK | PRODUCT_LAYER_MASK;
552
- _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK = PRODUCT_LAYER_MASK;
553
- DIVEPerspectiveCamera = _DIVEPerspectiveCamera;
554
- }
555
- });
556
-
557
- // src/mediacreator/MediaCreator.ts
558
- var MediaCreator_exports = {};
559
- __export(MediaCreator_exports, {
560
- DIVEMediaCreator: () => DIVEMediaCreator
561
- });
562
- var DIVEMediaCreator;
563
- var init_MediaCreator = __esm({
564
- "src/mediacreator/MediaCreator.ts"() {
565
- "use strict";
566
- init_PerspectiveCamera();
567
- DIVEMediaCreator = class {
568
- constructor(renderer, scene, controller) {
569
- this.renderer = renderer;
570
- this.scene = scene;
571
- this.controller = controller;
572
- }
573
- GenerateMedia(position, target, width, height) {
574
- const resetPosition = this.controller.object.position.clone();
575
- const resetRotation = this.controller.object.quaternion.clone();
576
- this.renderer.OnResize(width, height);
577
- this.controller.object.OnResize(width, height);
578
- this.controller.object.position.copy(position);
579
- this.controller.target.copy(target);
580
- this.controller.update();
581
- const dataUri = this.DrawCanvas().toDataURL();
582
- this.controller.object.position.copy(resetPosition);
583
- this.controller.object.quaternion.copy(resetRotation);
584
- return dataUri;
585
- }
586
- DrawCanvas(canvasElement) {
587
- const restore = this.renderer.domElement;
588
- if (canvasElement) {
589
- this.renderer.domElement = canvasElement;
590
- }
591
- this.controller.object.layers.mask = DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
592
- this.renderer.render(this.scene, this.controller.object);
593
- this.controller.object.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
594
- const returnCanvas = this.renderer.domElement;
595
- if (canvasElement) {
596
- this.renderer.domElement = restore;
597
- }
598
- return returnCanvas;
599
- }
600
- };
601
- }
602
- });
603
-
604
- // src/io/gltf/GLTFIO.ts
605
- var import_GLTFLoader, import_GLTFExporter, DIVEGLTFIO;
606
- var init_GLTFIO = __esm({
607
- "src/io/gltf/GLTFIO.ts"() {
608
- "use strict";
609
- import_GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
610
- import_GLTFExporter = require("three/examples/jsm/exporters/GLTFExporter");
611
- DIVEGLTFIO = class {
612
- constructor() {
613
- this._importer = new import_GLTFLoader.GLTFLoader();
614
- this._exporter = new import_GLTFExporter.GLTFExporter();
615
- }
616
- Import(url, onProgress) {
617
- return this._importer.loadAsync(url, (progress) => {
618
- if (!onProgress) return;
619
- onProgress(progress.loaded / progress.total);
620
- });
621
- }
622
- Export(object, binary, onlyVisible) {
623
- if (binary) {
624
- return this._exporter.parseAsync(object, {
625
- binary,
626
- onlyVisible
627
- });
628
- } else {
629
- return this._exporter.parseAsync(object, {
630
- binary,
631
- onlyVisible
632
- });
633
- }
634
- }
635
- };
636
- }
637
- });
638
-
639
- // src/io/IO.ts
640
- var IO_exports = {};
641
- __export(IO_exports, {
642
- DIVEIO: () => DIVEIO
643
- });
644
- var DIVEIO;
645
- var init_IO = __esm({
646
- "src/io/IO.ts"() {
647
- "use strict";
648
- init_GLTFIO();
649
- DIVEIO = class {
650
- constructor(scene) {
651
- this._scene = scene;
652
- this._gltfIO = new DIVEGLTFIO();
653
- }
654
- Import(type, url) {
655
- switch (type) {
656
- case "glb": {
657
- return this._gltfIO.Import(url).catch((error) => {
658
- console.error(error);
659
- return null;
660
- });
661
- }
662
- default: {
663
- console.error("DIVEIO.Import: Unsupported file type: " + type);
664
- return Promise.reject();
665
- }
666
- }
667
- }
668
- Export(type) {
669
- switch (type) {
670
- case "glb": {
671
- return this._gltfIO.Export(this._scene, true, true).then((data) => {
672
- return this._createBlobURL(data);
673
- }).catch((error) => {
674
- console.error(error);
675
- return null;
676
- });
677
- }
678
- default: {
679
- console.error("DIVEIO.Export: Unsupported file type: " + type);
680
- return Promise.reject();
681
- }
682
- }
683
- }
684
- _createBlobURL(data) {
685
- return URL.createObjectURL(new Blob([data]));
686
- }
687
- };
688
- }
689
- });
690
-
691
- // src/info/Info.ts
692
- var WebXRUnsupportedReason, DIVEInfo;
693
- var init_Info = __esm({
694
- "src/info/Info.ts"() {
695
- "use strict";
696
- WebXRUnsupportedReason = /* @__PURE__ */ ((WebXRUnsupportedReason2) => {
697
- WebXRUnsupportedReason2[WebXRUnsupportedReason2["UNKNWON_ERROR"] = 0] = "UNKNWON_ERROR";
698
- WebXRUnsupportedReason2[WebXRUnsupportedReason2["NO_HTTPS"] = 1] = "NO_HTTPS";
699
- WebXRUnsupportedReason2[WebXRUnsupportedReason2["IMMERSIVE_AR_NOT_SUPPORTED_BY_DEVICE"] = 2] = "IMMERSIVE_AR_NOT_SUPPORTED_BY_DEVICE";
700
- WebXRUnsupportedReason2[WebXRUnsupportedReason2["AR_SESSION_NOT_ALLOWED"] = 3] = "AR_SESSION_NOT_ALLOWED";
701
- return WebXRUnsupportedReason2;
702
- })(WebXRUnsupportedReason || {});
703
- DIVEInfo = class {
704
- /**
705
- *
706
- * @returns The system the user is using. Possible values are "Android", "iOS", "Windows", "MacOS", "Linux" or "Unknown".
707
- */
708
- static GetSystem() {
709
- const platform = navigator.platform;
710
- if (/Android/.test(navigator.userAgent)) {
711
- return "Android";
712
- } else if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
713
- return "iOS";
714
- } else if (platform.startsWith("Win")) {
715
- return "Windows";
716
- } else if (platform.startsWith("Mac")) {
717
- return "MacOS";
718
- } else if (platform.startsWith("Linux")) {
719
- return "Linux";
720
- } else {
721
- return "Unknown";
722
- }
723
- }
724
- /**
725
- * @returns A promise that resolves to a boolean indicating whether the user's device supports WebXR.
726
- */
727
- static GetSupportsWebXR() {
728
- return __async(this, null, function* () {
729
- if (this._supportsWebXR !== null) {
730
- return this._supportsWebXR;
731
- }
732
- if (!navigator.xr) {
733
- this._supportsWebXR = false;
734
- if (window.isSecureContext === false) {
735
- this._webXRUnsupportedReason = 1 /* NO_HTTPS */;
736
- } else {
737
- this._webXRUnsupportedReason = 0 /* UNKNWON_ERROR */;
738
- }
739
- return this._supportsWebXR;
740
- }
741
- try {
742
- const supported = yield navigator.xr.isSessionSupported("immersive-ar");
743
- if (!supported) {
744
- this._webXRUnsupportedReason = 2 /* IMMERSIVE_AR_NOT_SUPPORTED_BY_DEVICE */;
745
- }
746
- this._supportsWebXR = supported;
747
- } catch (error) {
748
- this._supportsWebXR = false;
749
- this._webXRUnsupportedReason = 3 /* AR_SESSION_NOT_ALLOWED */;
750
- }
751
- return this._supportsWebXR;
752
- });
753
- }
754
- /**
755
- * @returns The reason why WebXR is not supported on the user's device. Returns null if WebXR is supported nor not has been checked yet.
756
- */
757
- static GetWebXRUnsupportedReason() {
758
- if (this._supportsWebXR === null) {
759
- console.log("WebXR support has not been checked yet.");
760
- return null;
761
- }
762
- return this._webXRUnsupportedReason;
763
- }
764
- /**
765
- * @returns A boolean indicating whether the user's device supports AR Quick Look.
766
- */
767
- static GetSupportsARQuickLook() {
768
- const a = document.createElement("a");
769
- if (a.relList.supports("ar")) {
770
- return true;
771
- }
772
- const userAgent = navigator.userAgent;
773
- const isIOS = /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream;
774
- if (!isIOS) {
775
- return false;
776
- }
777
- const match = userAgent.match(/OS (\d+)_/);
778
- if (!match || match.length < 2) {
779
- return false;
780
- }
781
- const iOSVersion = parseInt(match[1], 10);
782
- const minQuickLookVersion = 12;
783
- if (iOSVersion < minQuickLookVersion) {
784
- return false;
785
- }
786
- const isSupportedBrowser = /^((?!chrome|android).)*safari|CriOS|FxiOS/i.test(userAgent);
787
- if (isSupportedBrowser) {
788
- return true;
789
- }
790
- return false;
791
- }
792
- /**
793
- * @returns A boolean indicating whether the user's device is a mobile device.
794
- */
795
- static get isMobile() {
796
- return this.GetSystem() === "Android" || this.GetSystem() === "iOS";
797
- }
798
- /**
799
- * @returns A boolean indicating whether the user's device is a desktop device.
800
- */
801
- static get isDesktop() {
802
- return !this.isMobile;
803
- }
804
- /**
805
- * @returns A promise that resolves to a boolean indicating whether the user's device is capable of AR.
806
- */
807
- static GetIsARCapable() {
808
- return __async(this, null, function* () {
809
- if (this.GetSupportsARQuickLook()) {
810
- return true;
811
- }
812
- return yield this.GetSupportsWebXR();
813
- });
814
- }
815
- };
816
- DIVEInfo._supportsWebXR = null;
817
- DIVEInfo._webXRUnsupportedReason = null;
818
- }
819
- });
820
-
821
- // src/exporters/usdz/USDZExporter.ts
822
- var import_USDZExporter, DIVEUSDZExporter;
823
- var init_USDZExporter = __esm({
824
- "src/exporters/usdz/USDZExporter.ts"() {
825
- "use strict";
826
- import_USDZExporter = require("three/examples/jsm/exporters/USDZExporter");
827
- DIVEUSDZExporter = class extends import_USDZExporter.USDZExporter {
828
- parse(scene, options) {
829
- return super.parse(scene, options);
830
- }
831
- };
832
- }
833
- });
834
-
835
- // src/ar/arquicklook/ARQuickLook.ts
836
- var import_three5, DIVEARQuickLook;
837
- var init_ARQuickLook = __esm({
838
- "src/ar/arquicklook/ARQuickLook.ts"() {
839
- "use strict";
840
- import_three5 = require("three");
841
- init_USDZExporter();
842
- DIVEARQuickLook = class {
843
- static Launch(scene, options) {
844
- const quickLookScene = new import_three5.Object3D();
845
- quickLookScene.add(...this.extractModels(scene));
846
- return this.launchARFromNode(quickLookScene, options);
847
- }
848
- static extractModels(scene) {
849
- return scene.Root.children;
850
- }
851
- static launchARFromNode(node, options) {
852
- return this._usdzExporter.parse(node, {
853
- quickLookCompatible: true,
854
- ar: {
855
- anchoring: { type: "plane" },
856
- planeAnchoring: {
857
- alignment: (options == null ? void 0 : options.arPlacement) === "vertical" ? "vertical" : "horizontal"
858
- }
859
- }
860
- }).then((usdz) => {
861
- const blob = new Blob([usdz], { type: "model/vnd.usdz+zip" });
862
- let url = URL.createObjectURL(blob);
863
- if ((options == null ? void 0 : options.arScale) === "fixed") {
864
- url = url.concat("#allowsContentScaling=0");
865
- }
866
- const a = document.createElement("a");
867
- a.innerHTML = "<picture></picture>";
868
- a.rel = "ar";
869
- a.href = url;
870
- a.download = "scene.usdz";
871
- a.click();
872
- });
873
- }
874
- };
875
- DIVEARQuickLook._usdzExporter = new DIVEUSDZExporter();
876
- }
877
- });
878
-
879
- // src/ar/webxr/overlay/Overlay.ts
880
- var Overlay;
881
- var init_Overlay = __esm({
882
- "src/ar/webxr/overlay/Overlay.ts"() {
883
- "use strict";
884
- Overlay = class {
885
- get Element() {
886
- return this._element;
887
- }
888
- get CloseButton() {
889
- return this._closeButton;
890
- }
891
- constructor() {
892
- this._element = document.createElement("div");
893
- this._closeButton = this.createCloseButton();
894
- this._element.appendChild(this._closeButton);
895
- document.body.appendChild(this._element);
896
- }
897
- createCloseButton() {
898
- const path = document.createElementNS(
899
- "http://www.w3.org/2000/svg",
900
- "path"
901
- );
902
- path.setAttribute("d", "M 12,12 L 28,28 M 28,12 12,28");
903
- path.setAttribute("stroke", "#fff");
904
- path.setAttribute("stroke-width", "2");
905
- const svg = document.createElementNS(
906
- "http://www.w3.org/2000/svg",
907
- "svg"
908
- );
909
- svg.setAttribute("width", "38");
910
- svg.setAttribute("height", "38");
911
- svg.style.position = "absolute";
912
- svg.style.right = "20px";
913
- svg.style.top = "20px";
914
- svg.appendChild(path);
915
- return svg;
916
- }
917
- };
918
- }
919
- });
920
-
921
- // src/ar/webxr/crosshair/WebXRCrosshair.ts
922
- var import_three6, DIVEWebXRCrosshair;
923
- var init_WebXRCrosshair = __esm({
924
- "src/ar/webxr/crosshair/WebXRCrosshair.ts"() {
925
- "use strict";
926
- import_three6 = require("three");
927
- DIVEWebXRCrosshair = class extends import_three6.Object3D {
928
- set mesh(mesh) {
929
- this.clear();
930
- if (mesh) {
931
- this.add(mesh);
932
- }
933
- }
934
- constructor(mesh) {
935
- super();
936
- if (mesh) {
937
- this.mesh = mesh;
938
- } else {
939
- this.UseDefaultMesh();
940
- }
941
- this.matrixAutoUpdate = false;
942
- return this;
943
- }
944
- UseDefaultMesh() {
945
- const geometry = new import_three6.RingGeometry(0.08, 0.1, 32).rotateX(-Math.PI / 2);
946
- const material = new import_three6.MeshBasicMaterial();
947
- this.mesh = new import_three6.Mesh(geometry, material);
948
- }
949
- UpdateFromPose(pose) {
950
- this.matrix.fromArray(pose.transform.matrix);
951
- }
952
- };
953
- }
954
- });
955
-
956
- // src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts
957
- var import_three7, DIVEWebXRRaycasterAR;
958
- var init_WebXRRaycasterAR = __esm({
959
- "src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts"() {
960
- "use strict";
961
- import_three7 = require("three");
962
- DIVEWebXRRaycasterAR = class {
963
- constructor(session, renderer) {
964
- this._referenceSpaceBuffer = null;
965
- this._requesting = false;
966
- this._initialized = false;
967
- this._session = session;
968
- this._renderer = renderer;
969
- this._hitMatrixBuffer = new import_three7.Matrix4();
970
- }
971
- Dispose() {
972
- var _a;
973
- (_a = this._transientHitTestSource) == null ? void 0 : _a.cancel();
974
- this._transientHitTestSource = void 0;
975
- this._initialized = false;
976
- }
977
- Init() {
978
- return __async(this, null, function* () {
979
- if (!this._session) {
980
- console.error(
981
- "DIVEWebXRRaycaster: No session set in Init()! Aborting initialization..."
982
- );
983
- return Promise.reject();
984
- }
985
- if (this._requesting) {
986
- console.error(
987
- "DIVEWebXRRaycaster: Currently initializing! Aborting initialization..."
988
- );
989
- return Promise.reject();
990
- }
991
- if (this._initialized) {
992
- console.error(
993
- "DIVEWebXRRaycaster: Already initialized! Aborting initialization..."
994
- );
995
- return Promise.reject();
996
- }
997
- this._requesting = true;
998
- this._transientHitTestSource = yield this._session.requestHitTestSourceForTransientInput({
999
- profile: "generic-touchscreen"
1000
- });
1001
- this._referenceSpaceBuffer = this._renderer.xr.getReferenceSpace();
1002
- this._requesting = false;
1003
- if (!this._transientHitTestSource) {
1004
- return Promise.reject();
1005
- }
1006
- this._initialized = true;
1007
- console.log("DIVEWebXRRaycasterAR: Initialized");
1008
- return Promise.resolve(this);
1009
- });
1010
- }
1011
- GetIntersections(frame) {
1012
- if (!this._transientHitTestSource) return [];
1013
- const touches = frame.getHitTestResultsForTransientInput(
1014
- this._transientHitTestSource
1015
- );
1016
- if (touches.length === 0) return [];
1017
- const hits = touches.map((touch) => {
1018
- if (!this._referenceSpaceBuffer) return void 0;
1019
- if (!touch.results[0]) return void 0;
1020
- if (!touch.results[0].getPose) return void 0;
1021
- const pose = touch.results[0].getPose(this._referenceSpaceBuffer);
1022
- if (!pose) return void 0;
1023
- this._hitMatrixBuffer.fromArray(pose.transform.matrix);
1024
- const position = new import_three7.Vector3().setFromMatrixPosition(
1025
- this._hitMatrixBuffer
1026
- );
1027
- return {
1028
- point: position,
1029
- matrix: this._hitMatrixBuffer,
1030
- object: void 0
1031
- };
1032
- });
1033
- return hits.filter((hit) => hit !== void 0);
1034
- }
1035
- };
1036
- }
1037
- });
1038
-
1039
- // src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts
1040
- var import_three8, DIVEWebXRRaycasterTHREE;
1041
- var init_WebXRRaycasterTHREE = __esm({
1042
- "src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts"() {
1043
- "use strict";
1044
- import_three8 = require("three");
1045
- DIVEWebXRRaycasterTHREE = class {
1046
- constructor(renderer, scene) {
1047
- // internal raycaster
1048
- this._raycaster = new import_three8.Raycaster();
1049
- this._renderer = renderer;
1050
- this._scene = scene;
1051
- this._controller = this._renderer.xr.getController(0);
1052
- }
1053
- Init() {
1054
- return __async(this, null, function* () {
1055
- console.log("DIVEWebXRRaycasterTHREE: Initialized");
1056
- return Promise.resolve(this);
1057
- });
1058
- }
1059
- GetIntersections() {
1060
- this._controller.updateMatrixWorld();
1061
- this._raycaster.setFromXRController(this._controller);
1062
- const intersections = this._raycaster.intersectObjects(
1063
- this._scene.XRRoot.XRModelRoot.children
1064
- );
1065
- if (intersections.length === 0) return [];
1066
- return intersections.map((intersection) => {
1067
- return {
1068
- point: intersection.point,
1069
- matrix: intersection.object.matrixWorld,
1070
- object: intersection.object
1071
- };
1072
- });
1073
- }
1074
- };
1075
- }
1076
- });
1077
-
1078
- // src/events/EventExecutor.ts
1079
- var DIVEEventExecutor;
1080
- var init_EventExecutor = __esm({
1081
- "src/events/EventExecutor.ts"() {
1082
- "use strict";
1083
- DIVEEventExecutor = class {
1084
- constructor() {
1085
- this._listeners = /* @__PURE__ */ new Map();
1086
- }
1087
- Subscribe(type, listener) {
1088
- if (!this._listeners.get(type)) this._listeners.set(type, []);
1089
- this._listeners.get(type).push(listener);
1090
- return () => {
1091
- const listenerArray = this._listeners.get(type);
1092
- if (!listenerArray) return false;
1093
- const existingIndex = listenerArray.findIndex(
1094
- (entry) => entry === listener
1095
- );
1096
- if (existingIndex === -1) return false;
1097
- listenerArray.splice(existingIndex, 1);
1098
- return true;
1099
- };
1100
- }
1101
- dispatch(type, payload) {
1102
- const listenerArray = this._listeners.get(type);
1103
- if (!listenerArray) return;
1104
- listenerArray.forEach((listener) => listener(payload));
1105
- }
1106
- };
1107
- }
1108
- });
1109
-
1110
- // src/ar/webxr/raycaster/WebXRRaycaster.ts
1111
- var DIVEWebXRRaycaster;
1112
- var init_WebXRRaycaster = __esm({
1113
- "src/ar/webxr/raycaster/WebXRRaycaster.ts"() {
1114
- "use strict";
1115
- init_WebXRRaycasterAR();
1116
- init_WebXRRaycasterTHREE();
1117
- init_EventExecutor();
1118
- DIVEWebXRRaycaster = class extends DIVEEventExecutor {
1119
- constructor(session, renderer, scene) {
1120
- super();
1121
- this._initialized = false;
1122
- this._arHitResultBuffer = [];
1123
- this._sceneHitResultBuffer = [];
1124
- // buffers
1125
- this._hasHit = false;
1126
- this._session = session;
1127
- this._threeRaycaster = new DIVEWebXRRaycasterTHREE(renderer, scene);
1128
- this._arRaycaster = new DIVEWebXRRaycasterAR(session, renderer);
1129
- }
1130
- Dispose() {
1131
- this._initialized = false;
1132
- }
1133
- Init() {
1134
- return __async(this, null, function* () {
1135
- if (!this._session) {
1136
- console.error(
1137
- "DIVEWebXRRaycaster: No session set in Init()! Aborting initialization..."
1138
- );
1139
- return Promise.reject();
1140
- }
1141
- if (this._initialized) {
1142
- console.error(
1143
- "DIVEWebXRRaycaster: Already initialized! Aborting initialization..."
1144
- );
1145
- return Promise.reject();
1146
- }
1147
- yield this._threeRaycaster.Init();
1148
- yield this._arRaycaster.Init();
1149
- console.log("DIVEWebXRRaycaster: Initialized");
1150
- this._initialized = true;
1151
- return Promise.resolve(this);
1152
- });
1153
- }
1154
- GetARIntersections(frame) {
1155
- this._arHitResultBuffer = this._arRaycaster.GetIntersections(frame);
1156
- if (this._arHitResultBuffer.length > 0) {
1157
- this.onARHitFound(this._arHitResultBuffer[0]);
1158
- } else {
1159
- this.onARHitLost();
1160
- }
1161
- return this._arHitResultBuffer;
1162
- }
1163
- GetSceneIntersections() {
1164
- this._sceneHitResultBuffer = this._threeRaycaster.GetIntersections();
1165
- if (this._sceneHitResultBuffer.length > 0) {
1166
- this.onSceneHitFound(this._sceneHitResultBuffer[0]);
1167
- } else {
1168
- this.onSceneHitLost();
1169
- }
1170
- return this._sceneHitResultBuffer;
1171
- }
1172
- onARHitFound(hit) {
1173
- this._hasHit = true;
1174
- this.dispatch("AR_HIT_FOUND", { hit });
1175
- }
1176
- onARHitLost() {
1177
- if (!this._hasHit) return;
1178
- this._hasHit = false;
1179
- this.dispatch("AR_HIT_LOST");
1180
- }
1181
- onSceneHitFound(hit) {
1182
- this._hasHit = true;
1183
- this.dispatch("SCENE_HIT_FOUND", { hit });
1184
- }
1185
- onSceneHitLost() {
1186
- if (!this._hasHit) return;
1187
- this._hasHit = false;
1188
- this.dispatch("SCENE_HIT_LOST");
1189
- }
1190
- };
1191
- }
1192
- });
1193
-
1194
- // src/ar/webxr/origin/WebXROrigin.ts
1195
- var import_three9, DIVEWebXROrigin;
1196
- var init_WebXROrigin = __esm({
1197
- "src/ar/webxr/origin/WebXROrigin.ts"() {
1198
- "use strict";
1199
- import_three9 = require("three");
1200
- DIVEWebXROrigin = class {
1201
- constructor(session, renderer, entityTypes) {
1202
- this._raycastHitCounter = 0;
1203
- this._originSetResolve = () => {
1204
- };
1205
- this._renderer = renderer;
1206
- this._session = session;
1207
- this._originSet = new Promise((resolve) => {
1208
- this._originSetResolve = resolve;
1209
- });
1210
- this._requesting = false;
1211
- this._initialized = false;
1212
- this._referenceSpaceBuffer = null;
1213
- this._hitTestSource = null;
1214
- this._entityTypes = entityTypes || ["plane"];
1215
- this._hitTestResultBuffer = [];
1216
- this._matrix = new import_three9.Matrix4();
1217
- this._position = new import_three9.Vector3();
1218
- this._quaternion = new import_three9.Quaternion();
1219
- this._scale = new import_three9.Vector3();
1220
- this._originSet.then(() => {
1221
- this._matrix.decompose(
1222
- this._position,
1223
- this._quaternion,
1224
- this._scale
1225
- );
1226
- });
1227
- }
1228
- get originSet() {
1229
- return this._originSet;
1230
- }
1231
- get matrix() {
1232
- return this._matrix;
1233
- }
1234
- set matrix(value) {
1235
- this._matrix = value;
1236
- this._matrix.decompose(this._position, this._quaternion, this._scale);
1237
- }
1238
- get position() {
1239
- return this._position;
1240
- }
1241
- get quaternion() {
1242
- return this._quaternion;
1243
- }
1244
- get scale() {
1245
- return this._scale;
1246
- }
1247
- Init() {
1248
- return __async(this, null, function* () {
1249
- if (this._initialized) {
1250
- return Promise.resolve(this);
1251
- }
1252
- if (!this._session) {
1253
- console.error(
1254
- "DIVEWebXROrigin: No session set in Init()! Aborting initialization..."
1255
- );
1256
- return Promise.reject();
1257
- }
1258
- if (this._requesting) {
1259
- console.error(
1260
- "DIVEWebXROrigin: Currently initializing! Aborting initialization..."
1261
- );
1262
- return Promise.reject();
1263
- }
1264
- this._requesting = true;
1265
- const referenceSpace = yield this._session.requestReferenceSpace("viewer");
1266
- this._hitTestSource = (yield this._session.requestHitTestSource({
1267
- space: referenceSpace,
1268
- entityTypes: this._entityTypes
1269
- })) || null;
1270
- this._requesting = false;
1271
- if (!this._hitTestSource) {
1272
- return Promise.reject();
1273
- }
1274
- this._initialized = true;
1275
- return Promise.resolve(this);
1276
- });
1277
- }
1278
- Dispose() {
1279
- var _a;
1280
- this._initialized = false;
1281
- this._requesting = false;
1282
- (_a = this._hitTestSource) == null ? void 0 : _a.cancel();
1283
- this._hitTestSource = null;
1284
- this._hitTestResultBuffer = [];
1285
- this._matrix = new import_three9.Matrix4();
1286
- this._position = new import_three9.Vector3();
1287
- this._quaternion = new import_three9.Quaternion();
1288
- this._scale = new import_three9.Vector3();
1289
- }
1290
- Update(frame) {
1291
- if (!this._initialized) return;
1292
- if (!this._hitTestSource) {
1293
- throw new Error(
1294
- "DIVEWebXRRaycaster: Critical Error: HitTestSource not available but WebXROrigin is initialized!"
1295
- );
1296
- }
1297
- this._hitTestResultBuffer = frame.getHitTestResults(
1298
- this._hitTestSource
1299
- );
1300
- if (this._hitTestResultBuffer.length > 0) {
1301
- this._referenceSpaceBuffer = this._renderer.xr.getReferenceSpace();
1302
- if (!this._referenceSpaceBuffer) {
1303
- this.onHitLost();
1304
- return;
1305
- }
1306
- const pose = this._hitTestResultBuffer[0].getPose(
1307
- this._referenceSpaceBuffer
1308
- );
1309
- if (!pose) {
1310
- this.onHitLost();
1311
- return;
1312
- }
1313
- this.onHitFound(pose);
1314
- } else {
1315
- this.onHitLost();
1316
- }
1317
- }
1318
- onHitFound(pose) {
1319
- this._raycastHitCounter++;
1320
- this.matrix.fromArray(pose.transform.matrix);
1321
- if (this._raycastHitCounter > 50) {
1322
- this._originSetResolve();
1323
- }
1324
- }
1325
- onHitLost() {
1326
- this._raycastHitCounter = 0;
1327
- }
1328
- };
1329
- }
1330
- });
1331
-
1332
- // src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts
1333
- var import_three10, DIVEWebXRTouchscreenControls;
1334
- var init_WebXRTouchscreenControls = __esm({
1335
- "src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts"() {
1336
- "use strict";
1337
- import_three10 = require("three");
1338
- init_EventExecutor();
1339
- DIVEWebXRTouchscreenControls = class extends DIVEEventExecutor {
1340
- constructor(session) {
1341
- super();
1342
- // touch members
1343
- this._touchCount = 0;
1344
- this._touches = [];
1345
- // rotate members
1346
- this._handleRotateStarted = false;
1347
- this._handleRotateMoved = false;
1348
- this._handleRotateEnded = false;
1349
- this._startAngle = 0;
1350
- this._lastAngle = 0;
1351
- this._angleDelta = 0;
1352
- // scale members
1353
- this._handlePinchStarted = false;
1354
- this._handlePinchMoved = false;
1355
- this._handlePinchEnded = false;
1356
- this._scaleDistanceStart = 0;
1357
- this._currentDistance = 1;
1358
- this._deltaDistance = 0;
1359
- this._session = session;
1360
- this._touches = [
1361
- {
1362
- start: new import_three10.Vector2(),
1363
- current: new import_three10.Vector2(),
1364
- delta: new import_three10.Vector2()
1365
- },
1366
- {
1367
- start: new import_three10.Vector2(),
1368
- current: new import_three10.Vector2(),
1369
- delta: new import_three10.Vector2()
1370
- }
1371
- ];
1372
- this._handleRotateStarted = false;
1373
- window.addEventListener(
1374
- "touchstart",
1375
- (e) => this.onTouchStart(e)
1376
- );
1377
- window.addEventListener(
1378
- "touchmove",
1379
- (e) => this.onTouchMove(e)
1380
- );
1381
- window.addEventListener(
1382
- "touchend",
1383
- (e) => this.onTouchEnd(e)
1384
- );
1385
- this._session.addEventListener(
1386
- "selectstart",
1387
- () => this.onSessionSelectStart()
1388
- );
1389
- this._session.addEventListener(
1390
- "selectend",
1391
- () => this.onSessionSelectEnd()
1392
- );
1393
- }
1394
- Dispose() {
1395
- window.removeEventListener(
1396
- "touchstart",
1397
- (e) => this.onTouchStart(e)
1398
- );
1399
- window.removeEventListener(
1400
- "touchmove",
1401
- (e) => this.onTouchMove(e)
1402
- );
1403
- window.removeEventListener(
1404
- "touchend",
1405
- (e) => this.onTouchEnd(e)
1406
- );
1407
- this._session.removeEventListener(
1408
- "selectstart",
1409
- () => this.onSessionSelectStart()
1410
- );
1411
- this._session.removeEventListener(
1412
- "selectend",
1413
- () => this.onSessionSelectEnd()
1414
- );
1415
- }
1416
- onTouchStart(event) {
1417
- this._touchCount = event.touches.length;
1418
- this._touches[0].start.set(
1419
- event.touches[0].clientX,
1420
- event.touches[0].clientY
1421
- );
1422
- this._touches[0].current.set(
1423
- event.touches[0].clientX,
1424
- event.touches[0].clientY
1425
- );
1426
- this._touches[0].delta.set(0, 0);
1427
- if (this._touchCount > 1) {
1428
- this._touches[1].start.set(
1429
- event.touches[1].clientX,
1430
- event.touches[1].clientY
1431
- );
1432
- this._touches[1].current.set(
1433
- event.touches[1].clientX,
1434
- event.touches[1].clientY
1435
- );
1436
- this._touches[1].delta.set(0, 0);
1437
- }
1438
- if (this._touchCount === 2) {
1439
- this.handleRotateStart();
1440
- this.handlePinchStart();
1441
- }
1442
- if (this._handleRotateStarted) {
1443
- this.dispatch("ROTATE_START", {
1444
- current: 0
1445
- });
1446
- this._handleRotateStarted = false;
1447
- }
1448
- if (this._handlePinchStarted) {
1449
- this.dispatch("PINCH_START", {
1450
- current: 0
1451
- });
1452
- this._handlePinchStarted = false;
1453
- }
1454
- }
1455
- onTouchMove(event) {
1456
- this._touchCount = event.touches.length;
1457
- this._touches[0].start.set(
1458
- event.touches[0].clientX,
1459
- event.touches[0].clientY
1460
- );
1461
- this._touches[0].current.set(
1462
- event.touches[0].clientX,
1463
- event.touches[0].clientY
1464
- );
1465
- this._touches[0].delta.copy(
1466
- this._touches[0].current.clone().sub(this._touches[0].start)
1467
- );
1468
- if (this._touchCount > 1) {
1469
- this._touches[1].start.set(
1470
- event.touches[1].clientX,
1471
- event.touches[1].clientY
1472
- );
1473
- this._touches[1].current.set(
1474
- event.touches[1].clientX,
1475
- event.touches[1].clientY
1476
- );
1477
- this._touches[1].delta.copy(
1478
- this._touches[1].current.clone().sub(this._touches[1].start)
1479
- );
1480
- }
1481
- if (this._touchCount === 2) {
1482
- this.handleRotateMoved();
1483
- this.handlePinchMoved();
1484
- }
1485
- if (this._touchCount === 1) {
1486
- this.dispatch("TOUCH_MOVE", {
1487
- touches: [
1488
- {
1489
- current: this._touches[0].current.clone(),
1490
- delta: this._touches[0].delta.clone()
1491
- },
1492
- {
1493
- current: this._touches[1].current.clone(),
1494
- delta: this._touches[1].delta.clone()
1495
- }
1496
- ],
1497
- touchCount: this._touchCount
1498
- });
1499
- }
1500
- if (this._touchCount === 2) {
1501
- if (this._handleRotateMoved) {
1502
- this.dispatch("ROTATE_MOVE", {
1503
- current: this._lastAngle,
1504
- delta: this._angleDelta
1505
- });
1506
- this._handleRotateMoved = false;
1507
- }
1508
- if (this._handlePinchMoved) {
1509
- this.dispatch("PINCH_MOVE", {
1510
- current: this._currentDistance,
1511
- delta: this._deltaDistance
1512
- });
1513
- this._handlePinchMoved = false;
1514
- }
1515
- }
1516
- }
1517
- onTouchEnd(event) {
1518
- this._touchCount = event.touches.length;
1519
- if (this._touchCount === 0) {
1520
- this._touches[0].start.set(0, 0);
1521
- this._touches[0].current.set(0, 0);
1522
- this._touches[0].delta.set(0, 0);
1523
- }
1524
- if (this._touchCount === 1) {
1525
- this.handleRotateEnded();
1526
- this.handlePinchEnded();
1527
- this._touches[1].start.set(0, 0);
1528
- this._touches[1].current.set(0, 0);
1529
- this._touches[1].delta.set(0, 0);
1530
- }
1531
- if (this._handleRotateEnded) {
1532
- this.dispatch("ROTATE_END", {
1533
- current: this._lastAngle
1534
- });
1535
- this._handleRotateEnded = false;
1536
- }
1537
- if (this._handlePinchEnded) {
1538
- this.dispatch("PINCH_END", {
1539
- current: this._currentDistance
1540
- });
1541
- this._handlePinchEnded = false;
1542
- }
1543
- }
1544
- onSessionSelectStart() {
1545
- this.dispatch("TOUCH_START", {
1546
- touches: [
1547
- {
1548
- current: this._touches[0].current.clone()
1549
- },
1550
- {
1551
- current: this._touches[1].current.clone()
1552
- }
1553
- ],
1554
- touchCount: this._touchCount
1555
- });
1556
- }
1557
- onSessionSelectEnd() {
1558
- this.dispatch("TOUCH_END", {
1559
- touches: [
1560
- {
1561
- current: this._touches[0].current.clone()
1562
- },
1563
- {
1564
- current: this._touches[1].current.clone()
1565
- }
1566
- ],
1567
- touchCount: this._touchCount
1568
- });
1569
- }
1570
- // rotation handler
1571
- handleRotateStart() {
1572
- this._handleRotateStarted = true;
1573
- this._startAngle = this._touches[1].start.clone().sub(this._touches[0].current).angle();
1574
- }
1575
- handleRotateMoved() {
1576
- this._handleRotateMoved = true;
1577
- const currentAngle = this._touches[1].current.clone().sub(this._touches[0].current).angle();
1578
- this._angleDelta = currentAngle - this._startAngle;
1579
- this._lastAngle = this._angleDelta * -1;
1580
- }
1581
- handleRotateEnded() {
1582
- this._handleRotateEnded = true;
1583
- }
1584
- // pinch handler
1585
- handlePinchStart() {
1586
- this._handlePinchStarted = true;
1587
- this._scaleDistanceStart = this._touches[1].start.distanceTo(
1588
- this._touches[0].current
1589
- );
1590
- }
1591
- handlePinchMoved() {
1592
- this._handlePinchMoved = true;
1593
- const beforeDistance = this._currentDistance;
1594
- const distance = this._touches[1].current.distanceTo(
1595
- this._touches[0].current
1596
- );
1597
- this._currentDistance = distance / this._scaleDistanceStart;
1598
- this._deltaDistance = this._currentDistance - beforeDistance;
1599
- }
1600
- handlePinchEnded() {
1601
- this._handlePinchEnded = true;
1602
- }
1603
- };
1604
- }
1605
- });
1606
-
1607
- // src/ar/webxr/controller/WebXRController.ts
1608
- var import_three11, DIVEWebXRController;
1609
- var init_WebXRController = __esm({
1610
- "src/ar/webxr/controller/WebXRController.ts"() {
1611
- "use strict";
1612
- import_three11 = require("three");
1613
- init_WebXRCrosshair();
1614
- init_WebXRRaycaster();
1615
- init_WebXROrigin();
1616
- init_WebXRTouchscreenControls();
1617
- init_findInterface();
1618
- DIVEWebXRController = class extends import_three11.Object3D {
1619
- constructor(session, renderer, scene) {
1620
- super();
1621
- this._frameBuffer = null;
1622
- this._handNodeInitialPosition = new import_three11.Vector3();
1623
- this._placed = false;
1624
- // grabbing
1625
- this._grabbedObject = null;
1626
- this._arHitPosition = new import_three11.Vector3();
1627
- this._arHitQuaternion = new import_three11.Quaternion();
1628
- this._arHitScale = new import_three11.Vector3(1, 1, 1);
1629
- // grabbing position
1630
- this._initialObjectPosition = null;
1631
- this._initialRaycastHit = null;
1632
- this._deltaRaycastHit = new import_three11.Vector3();
1633
- // grabbing rotation
1634
- this._touchQuaterion = new import_three11.Quaternion();
1635
- // grabbing scale
1636
- this._touchScale = 1;
1637
- this._scaleThreshold = 0.1;
1638
- this._startTouchQuaternion = new import_three11.Quaternion();
1639
- this._startTouchScale = 1;
1640
- this._renderer = renderer;
1641
- this._scene = scene;
1642
- this._session = session;
1643
- this._xrRaycaster = new DIVEWebXRRaycaster(session, renderer, scene);
1644
- this._origin = new DIVEWebXROrigin(this._session, this._renderer, [
1645
- "plane"
1646
- ]);
1647
- this._crosshair = new DIVEWebXRCrosshair();
1648
- this._crosshair.visible = false;
1649
- this._xrCamera = this._renderer.xr.getCamera();
1650
- this._scene.XRRoot.XRHandNode.position.set(0, -0.05, -0.25);
1651
- this._handNodeInitialPosition = this._scene.XRRoot.XRHandNode.position.clone();
1652
- this._touchscreenControls = new DIVEWebXRTouchscreenControls(
1653
- this._session
1654
- );
1655
- this._touchscreenControls.Subscribe(
1656
- "TOUCH_START",
1657
- () => this.onTouchStart()
1658
- );
1659
- this._touchscreenControls.Subscribe(
1660
- "TOUCH_MOVE",
1661
- () => this.onTouchMove()
1662
- );
1663
- this._touchscreenControls.Subscribe(
1664
- "TOUCH_END",
1665
- (p) => this.onTouchEnd(p)
1666
- );
1667
- this._touchscreenControls.Subscribe(
1668
- "ROTATE_START",
1669
- () => this.onRotateStart()
1670
- );
1671
- this._touchscreenControls.Subscribe(
1672
- "ROTATE_MOVE",
1673
- (p) => this.onRotateMove(p)
1674
- );
1675
- this._touchscreenControls.Subscribe(
1676
- "PINCH_START",
1677
- () => this.onPinchStart()
1678
- );
1679
- this._touchscreenControls.Subscribe(
1680
- "PINCH_MOVE",
1681
- (p) => this.onPinchMove(p)
1682
- );
1683
- }
1684
- Init() {
1685
- return __async(this, null, function* () {
1686
- this.prepareScene();
1687
- yield this.initOrigin();
1688
- yield this.initRaycaster();
1689
- return Promise.resolve(this);
1690
- });
1691
- }
1692
- Dispose() {
1693
- this.restoreScene();
1694
- this._origin.Dispose();
1695
- this._xrRaycaster.Dispose();
1696
- this._placed = false;
1697
- }
1698
- Update(frame) {
1699
- this._frameBuffer = frame;
1700
- if (!this._placed) {
1701
- this.updateHandNode();
1702
- if (this._origin) {
1703
- this._origin.Update(frame);
1704
- }
1705
- }
1706
- }
1707
- updateHandNode() {
1708
- this._xrCamera.updateMatrixWorld();
1709
- this._scene.XRRoot.XRHandNode.position.copy(
1710
- this._handNodeInitialPosition.clone().applyMatrix4(this._xrCamera.matrixWorld)
1711
- );
1712
- this._scene.XRRoot.XRHandNode.quaternion.setFromRotationMatrix(
1713
- this._xrCamera.matrixWorld
1714
- );
1715
- }
1716
- // placement
1717
- initOrigin() {
1718
- return __async(this, null, function* () {
1719
- this._origin = yield this._origin.Init();
1720
- this._origin.originSet.then(() => {
1721
- this.placeObjects(this._origin.matrix);
1722
- });
1723
- });
1724
- }
1725
- placeObjects(matrix) {
1726
- this._scene.XRRoot.XRModelRoot.matrix.copy(matrix);
1727
- [...this._scene.XRRoot.XRHandNode.children].forEach((child) => {
1728
- this._scene.XRRoot.XRModelRoot.add(child);
1729
- });
1730
- this._placed = true;
1731
- }
1732
- // grabbing
1733
- updateObject() {
1734
- if (!this._grabbedObject) return;
1735
- this._grabbedObject.position.copy(this._arHitPosition);
1736
- this._grabbedObject.quaternion.copy(
1737
- this._arHitQuaternion.clone().multiply(this._touchQuaterion)
1738
- );
1739
- this._grabbedObject.scale.copy(
1740
- new import_three11.Vector3(
1741
- this._touchScale,
1742
- this._touchScale,
1743
- this._touchScale
1744
- ).multiply(this._arHitScale)
1745
- );
1746
- }
1747
- onTouchStart() {
1748
- const sceneHits = this._xrRaycaster.GetSceneIntersections();
1749
- console.log("sceneHits", sceneHits);
1750
- if (sceneHits.length === 0) return;
1751
- if (!sceneHits[0].object) return;
1752
- const moveable = findInterface(
1753
- sceneHits[0].object,
1754
- "isMovable"
1755
- );
1756
- if (!moveable) return;
1757
- this._grabbedObject = moveable;
1758
- }
1759
- onTouchMove() {
1760
- if (!this._frameBuffer) return;
1761
- if (!this._grabbedObject) return;
1762
- const intersections = this._xrRaycaster.GetARIntersections(
1763
- this._frameBuffer
1764
- );
1765
- if (intersections.length === 0) {
1766
- this._crosshair.visible = false;
1767
- return;
1768
- }
1769
- const hit = intersections[0];
1770
- this._crosshair.visible = true;
1771
- this._crosshair.matrix.copy(hit.matrix);
1772
- if (!this._grabbedObject) return;
1773
- if (!this._initialObjectPosition || !this._initialRaycastHit) {
1774
- this._initialObjectPosition = this._grabbedObject.position.clone();
1775
- this._initialRaycastHit = hit.point.clone();
1776
- }
1777
- hit.matrix.decompose(
1778
- this._arHitPosition,
1779
- this._arHitQuaternion,
1780
- this._arHitScale
1781
- );
1782
- this._deltaRaycastHit.copy(
1783
- hit.point.clone().sub(this._initialRaycastHit)
1784
- );
1785
- this._arHitPosition.copy(
1786
- this._initialObjectPosition.clone().add(this._deltaRaycastHit)
1787
- );
1788
- console.log("arHitPosition", this._arHitPosition);
1789
- this.updateObject();
1790
- }
1791
- onTouchEnd(payload) {
1792
- if (payload.touchCount === 0) {
1793
- this._crosshair.visible = false;
1794
- this._initialObjectPosition = null;
1795
- this._initialRaycastHit = null;
1796
- this._grabbedObject = null;
1797
- }
1798
- }
1799
- onRotateStart() {
1800
- this._startTouchQuaternion = this._touchQuaterion.clone();
1801
- }
1802
- onRotateMove(payload) {
1803
- this._touchQuaterion.setFromAxisAngle(
1804
- new import_three11.Vector3(0, -1, 0),
1805
- payload.delta * 3
1806
- );
1807
- this._touchQuaterion.multiply(this._startTouchQuaternion);
1808
- this.updateObject();
1809
- }
1810
- onPinchStart() {
1811
- this._startTouchScale = this._touchScale;
1812
- }
1813
- onPinchMove(payload) {
1814
- this._touchScale = this._startTouchScale * payload.current;
1815
- this.updateObject();
1816
- }
1817
- // prepare & cleanup scene
1818
- prepareScene() {
1819
- this._scene.XRRoot.XRModelRoot.matrixAutoUpdate = false;
1820
- this._scene.add(this._crosshair);
1821
- const children = [];
1822
- this._scene.Root.children.forEach((child) => {
1823
- const clone = child.clone();
1824
- clone.layers.enableAll();
1825
- clone.traverse((obj) => {
1826
- obj.layers.enableAll();
1827
- if (obj instanceof import_three11.Mesh) {
1828
- obj.scale.set(0.1, 0.1, 0.1);
1829
- }
1830
- });
1831
- clone.position.set(0, 0, 0);
1832
- children.push(clone);
1833
- });
1834
- this._scene.XRRoot.XRHandNode.add(...children);
1835
- }
1836
- restoreScene() {
1837
- this._scene.remove(this._crosshair);
1838
- this._scene.XRRoot.XRHandNode.clear();
1839
- this._scene.XRRoot.XRModelRoot.clear();
1840
- this._scene.XRRoot.XRModelRoot.matrixAutoUpdate = true;
1841
- }
1842
- // raycast
1843
- initRaycaster() {
1844
- return __async(this, null, function* () {
1845
- yield this._xrRaycaster.Init();
1846
- if (!this._xrRaycaster) {
1847
- console.error(
1848
- "Raycaster not initialized successfully. Aborting WebXR..."
1849
- );
1850
- this.Dispose();
1851
- return Promise.reject();
1852
- }
1853
- });
1854
- }
1855
- };
1856
- }
1857
- });
1858
-
1859
- // src/ar/webxr/WebXR.ts
1860
- var _DIVEWebXR, DIVEWebXR;
1861
- var init_WebXR = __esm({
1862
- "src/ar/webxr/WebXR.ts"() {
1863
- "use strict";
1864
- init_Overlay();
1865
- init_WebXRController();
1866
- _DIVEWebXR = class _DIVEWebXR {
1867
- static Launch(renderer, scene, controller) {
1868
- return __async(this, null, function* () {
1869
- this._renderer = renderer;
1870
- this._scene = scene;
1871
- this._controller = controller;
1872
- this._cameraPosition = this._controller.object.position.clone();
1873
- this._cameraTarget = this._controller.target.clone();
1874
- if (!navigator.xr) {
1875
- console.error("WebXR not supported");
1876
- return Promise.reject();
1877
- }
1878
- this._renderer.xr.enabled = true;
1879
- this._scene.InitXR(renderer);
1880
- if (!_DIVEWebXR._overlay) {
1881
- const overlay = new Overlay();
1882
- _DIVEWebXR._overlay = overlay;
1883
- }
1884
- _DIVEWebXR._options.domOverlay = { root: _DIVEWebXR._overlay.Element };
1885
- const session = yield navigator.xr.requestSession(
1886
- "immersive-ar",
1887
- this._options
1888
- );
1889
- session.addEventListener("end", () => {
1890
- this._onSessionEnded();
1891
- });
1892
- renderer.xr.setReferenceSpaceType(this._referenceSpaceType);
1893
- yield renderer.xr.setSession(session);
1894
- _DIVEWebXR._overlay.Element.style.display = "";
1895
- this._session = session;
1896
- _DIVEWebXR._overlay.CloseButton.addEventListener(
1897
- "click",
1898
- () => this.End()
1899
- );
1900
- yield this._onSessionStarted();
1901
- return Promise.resolve();
1902
- });
1903
- }
1904
- static Update(_time, frame) {
1905
- if (!this._session) return;
1906
- if (this._xrController) {
1907
- this._xrController.Update(frame);
1908
- }
1909
- }
1910
- static End() {
1911
- if (!this._session) return;
1912
- this._session.end();
1913
- }
1914
- static _onSessionStarted() {
1915
- return __async(this, null, function* () {
1916
- if (!this._session) return;
1917
- this._renderCallbackId = this._renderer.AddPreRenderCallback(
1918
- (time, frame) => {
1919
- this.Update(time, frame);
1920
- }
1921
- );
1922
- this._xrController = new DIVEWebXRController(
1923
- this._session,
1924
- this._renderer,
1925
- this._scene
1926
- );
1927
- yield this._xrController.Init().catch(() => {
1928
- this.End();
1929
- });
1930
- return Promise.resolve();
1931
- });
1932
- }
1933
- static _onSessionEnded() {
1934
- if (!this._session) return;
1935
- if (this._xrController) {
1936
- this._xrController.Dispose();
1937
- }
1938
- if (this._renderCallbackId) {
1939
- this._renderer.RemovePreRenderCallback(this._renderCallbackId);
1940
- this._renderCallbackId = null;
1941
- }
1942
- this._renderer.xr.enabled = false;
1943
- const canvasWrapper = this._renderer.domElement.parentElement;
1944
- if (canvasWrapper) {
1945
- const { clientWidth, clientHeight } = canvasWrapper;
1946
- this._renderer.OnResize(clientWidth, clientHeight);
1947
- this._controller.object.OnResize(clientWidth, clientHeight);
1948
- }
1949
- this._controller.object.position.copy(this._cameraPosition);
1950
- this._controller.target.copy(this._cameraTarget);
1951
- this._cameraPosition.set(0, 0, 0);
1952
- this._cameraTarget.set(0, 0, 0);
1953
- this._scene.DisposeXR();
1954
- this._session.removeEventListener("end", this._onSessionEnded);
1955
- _DIVEWebXR._overlay.Element.style.display = "none";
1956
- this._session = null;
1957
- }
1958
- };
1959
- // render loop members
1960
- _DIVEWebXR._renderCallbackId = null;
1961
- // setup members
1962
- _DIVEWebXR._session = null;
1963
- _DIVEWebXR._referenceSpaceType = "local";
1964
- _DIVEWebXR._overlay = null;
1965
- _DIVEWebXR._options = {
1966
- requiredFeatures: [
1967
- "local",
1968
- "hit-test"
1969
- ],
1970
- optionalFeatures: [
1971
- "light-estimation",
1972
- "local-floor",
1973
- "dom-overlay",
1974
- "depth-sensing"
1975
- ],
1976
- depthSensing: {
1977
- usagePreference: ["gpu-optimized"],
1978
- dataFormatPreference: []
1979
- },
1980
- domOverlay: { root: {} }
1981
- };
1982
- _DIVEWebXR._xrController = null;
1983
- DIVEWebXR = _DIVEWebXR;
1984
- }
1985
- });
1986
-
1987
- // src/ar/sceneviewer/SceneViewer.ts
1988
- var DIVESceneViewer;
1989
- var init_SceneViewer = __esm({
1990
- "src/ar/sceneviewer/SceneViewer.ts"() {
1991
- "use strict";
1992
- DIVESceneViewer = class {
1993
- static Launch(scene, options) {
1994
- const url = this.findSceneViewerSrc(scene);
1995
- this.launchSceneViewer(url, options);
1996
- }
1997
- static launchSceneViewer(url, options) {
1998
- const anchor = document.createElement("a");
1999
- const noArViewerSigil = "#model-viewer-no-ar-fallback";
2000
- const location = self.location.toString();
2001
- const locationUrl = new URL(location);
2002
- const modelUrl = new URL(url, location);
2003
- const params = new URLSearchParams(modelUrl.search);
2004
- locationUrl.hash = noArViewerSigil;
2005
- params.set("mode", "ar_only");
2006
- if ((options == null ? void 0 : options.arScale) === "fixed") {
2007
- params.set("resizable", "false");
2008
- }
2009
- if ((options == null ? void 0 : options.arPlacement) === "vertical") {
2010
- params.set("enable_vertical_placement", "true");
2011
- }
2012
- const intent = `intent://arvr.google.com/scene-viewer/1.2?${params.toString() + "&file=" + modelUrl.toString()}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(
2013
- locationUrl.toString()
2014
- )};end;`;
2015
- anchor.setAttribute("href", intent);
2016
- anchor.click();
2017
- }
2018
- static findSceneViewerSrc(scene) {
2019
- let uri = null;
2020
- scene.traverse((object) => {
2021
- if (uri) return;
2022
- if (object.userData.uri) {
2023
- uri = object.userData.uri;
2024
- }
2025
- });
2026
- if (!uri) {
2027
- throw new Error("No model found in scene");
2028
- }
2029
- return uri;
2030
- }
2031
- };
2032
- }
2033
- });
2034
-
2035
- // src/ar/AR.ts
2036
- var AR_exports = {};
2037
- __export(AR_exports, {
2038
- DIVEAR: () => DIVEAR
2039
- });
2040
- var DIVEAR;
2041
- var init_AR = __esm({
2042
- "src/ar/AR.ts"() {
2043
- "use strict";
2044
- init_Info();
2045
- init_ARQuickLook();
2046
- init_WebXR();
2047
- init_SceneViewer();
2048
- DIVEAR = class {
2049
- constructor(renderer, scene, controller) {
2050
- this._renderer = renderer;
2051
- this._scene = scene;
2052
- this._controller = controller;
2053
- }
2054
- Launch(options) {
2055
- return __async(this, null, function* () {
2056
- const system = DIVEInfo.GetSystem();
2057
- if (system === "iOS") {
2058
- return this.tryARQuickLook();
2059
- }
2060
- if (system === "Android") {
2061
- if (options == null ? void 0 : options.useWebXR) {
2062
- console.warn("DIVE: WebXR is experimental on Android.");
2063
- return this.tryWebXR();
2064
- }
2065
- return this.trySceneViewer();
2066
- }
2067
- console.log(
2068
- "DIVE: AR not supported. Not a mobile system. (System is " + system + ")"
2069
- );
2070
- });
2071
- }
2072
- tryARQuickLook(options) {
2073
- return __async(this, null, function* () {
2074
- const support = DIVEInfo.GetSupportsARQuickLook();
2075
- if (!support) {
2076
- console.log("ARQuickLook not supported");
2077
- return Promise.reject();
2078
- }
2079
- console.log("DIVE: Launching AR with ARQuickLook ...");
2080
- yield DIVEARQuickLook.Launch(this._scene, options);
2081
- return Promise.resolve();
2082
- });
2083
- }
2084
- tryWebXR() {
2085
- return __async(this, null, function* () {
2086
- const support = yield DIVEInfo.GetSupportsWebXR();
2087
- if (!support) {
2088
- console.log(
2089
- "WebXR not supported. Reason: " + WebXRUnsupportedReason[DIVEInfo.GetWebXRUnsupportedReason()]
2090
- );
2091
- return Promise.reject();
2092
- }
2093
- console.log("DIVE: Launching AR with WebXR ...");
2094
- yield DIVEWebXR.Launch(this._renderer, this._scene, this._controller);
2095
- return Promise.resolve();
2096
- });
2097
- }
2098
- trySceneViewer(options) {
2099
- return __async(this, null, function* () {
2100
- console.log("DIVE: Launching AR with SceneViewer ...");
2101
- DIVESceneViewer.Launch(this._scene, options);
2102
- return Promise.resolve();
2103
- });
2104
- }
2105
- };
2106
- }
2107
- });
2108
-
2109
- // src/dive.ts
2110
- var dive_exports = {};
2111
- __export(dive_exports, {
2112
- DIVE: () => DIVE,
2113
- DIVECommunication: () => DIVECommunication,
2114
- DIVEDefaultSettings: () => DIVEDefaultSettings,
2115
- DIVEMath: () => DIVEMath,
2116
- default: () => DIVE
2117
- });
2118
- module.exports = __toCommonJS(dive_exports);
2119
-
2120
- // src/renderer/Renderer.ts
2121
- var import_three = require("three");
2122
- var DIVERendererDefaultSettings = {
2123
- antialias: true,
2124
- alpha: true,
2125
- stencil: false,
2126
- shadowMapEnabled: true,
2127
- shadowMapType: import_three.PCFSoftShadowMap,
2128
- toneMapping: import_three.NoToneMapping,
2129
- canvas: void 0
2130
- };
2131
- var DIVERenderer = class extends import_three.WebGLRenderer {
2132
- constructor(rendererSettings = DIVERendererDefaultSettings) {
2133
- super({
2134
- antialias: rendererSettings.antialias || DIVERendererDefaultSettings.antialias,
2135
- alpha: rendererSettings.alpha || DIVERendererDefaultSettings.alpha,
2136
- preserveDrawingBuffer: true,
2137
- canvas: rendererSettings.canvas
2138
- });
2139
- // basic functionality members
2140
- this.paused = false;
2141
- this.running = false;
2142
- this.force = false;
2143
- // pre- and post-render callbacks
2144
- this.preRenderCallbacks = /* @__PURE__ */ new Map();
2145
- this.postRenderCallbacks = /* @__PURE__ */ new Map();
2146
- this.setPixelRatio(window.devicePixelRatio);
2147
- this.shadowMap.enabled = rendererSettings.shadowMapEnabled || DIVERendererDefaultSettings.shadowMapEnabled;
2148
- this.shadowMap.type = rendererSettings.shadowMapType || DIVERendererDefaultSettings.shadowMapType;
2149
- this.toneMapping = rendererSettings.toneMapping || DIVERendererDefaultSettings.toneMapping;
2150
- this.debug.checkShaderErrors = false;
2151
- }
2152
- // Stops renderings and disposes the renderer.
2153
- Dispose() {
2154
- this.StopRenderer();
2155
- this.dispose();
2156
- }
2157
- // Starts the renderer with the given scene and camera.
2158
- StartRenderer(scene, cam) {
2159
- this.setAnimationLoop((time, frame) => {
2160
- this.internal_render(scene, cam, time, frame);
2161
- });
2162
- this.running = true;
2163
- }
2164
- // Pauses the renderer.
2165
- PauseRenderer() {
2166
- this.paused = true;
2167
- }
2168
- // Resumes the renderer after pausing.
2169
- ResumeRenderer() {
2170
- this.paused = false;
2171
- }
2172
- // Stops the renderer completely. Has to be started again with StartRenderer().
2173
- StopRenderer() {
2174
- this.setAnimationLoop(null);
2175
- this.running = false;
2176
- }
2177
- // Resizes the renderer to the given width and height.
2178
- OnResize(width, height) {
2179
- this.setSize(width, height);
2180
- }
2181
- /**
2182
- * Adds a callback to the render loop before actual render call.
2183
- * @param callback Executed before rendering.
2184
- * @returns uuid to remove the callback.
2185
- */
2186
- AddPreRenderCallback(callback) {
2187
- const newUUID = import_three.MathUtils.generateUUID();
2188
- this.preRenderCallbacks.set(newUUID, callback);
2189
- return newUUID;
2190
- }
2191
- /**
2192
- * Removes a callback from the render loop before actual render call.
2193
- * @param uuid of callback to remove.
2194
- * @returns if removing was successful.
2195
- */
2196
- RemovePreRenderCallback(uuid) {
2197
- if (!this.preRenderCallbacks.has(uuid)) return false;
2198
- this.preRenderCallbacks.delete(uuid);
2199
- return true;
2200
- }
2201
- /**
2202
- * Adds a callback to the render loop after actual render call.
2203
- * @param callback Executed after rendering.
2204
- * @returns uuid to remove the callback.
2205
- */
2206
- AddPostRenderCallback(callback) {
2207
- const newUUID = import_three.MathUtils.generateUUID();
2208
- this.postRenderCallbacks.set(newUUID, callback);
2209
- return newUUID;
2210
- }
2211
- /**
2212
- * Removes a callback from the render loop after actual render call.
2213
- * @param uuid of callback to remove.
2214
- * @returns if removing was successful.
2215
- */
2216
- RemovePostRenderCallback(uuid) {
2217
- if (!this.postRenderCallbacks.has(uuid)) return false;
2218
- this.postRenderCallbacks.delete(uuid);
2219
- return true;
2220
- }
2221
- /**
2222
- * Forces the renderer to render the next frame.
2223
- */
2224
- ForceRendering() {
2225
- this.force = true;
2226
- }
2227
- /**
2228
- * Internal render loop.
2229
- *
2230
- * To control renderloop you can add callbacks via AddPreRenderCallback() and AddPostRenderCallback().
2231
- * @param scene Scene to render.
2232
- * @param cam Camera to render with.
2233
- */
2234
- internal_render(scene, cam, time, frame) {
2235
- if ((this.paused || !this.running) && !this.force) return;
2236
- this.preRenderCallbacks.forEach((callback) => {
2237
- callback(time, frame);
2238
- });
2239
- this.render(scene, cam);
2240
- this.postRenderCallbacks.forEach((callback) => {
2241
- callback(time, frame);
2242
- });
2243
- this.force = false;
2244
- }
2245
- };
2246
-
2247
- // src/scene/Scene.ts
2248
- var import_three23 = require("three");
2249
-
2250
- // src/scene/root/Root.ts
2251
- var import_three18 = require("three");
2252
-
2253
- // src/light/AmbientLight.ts
2254
- var import_three2 = require("three");
2255
- init_VisibilityLayerMask();
2256
- var DIVEAmbientLight = class extends import_three2.Object3D {
2257
- constructor() {
2258
- super();
2259
- this.isDIVELight = true;
2260
- this.isDIVEAmbientLight = true;
2261
- this.name = "DIVEAmbientLight";
2262
- this._light = new import_three2.AmbientLight(16777215, 1);
2263
- this._light.layers.mask = PRODUCT_LAYER_MASK;
2264
- this.add(this._light);
2265
- }
2266
- SetColor(color) {
2267
- this._light.color = color;
2268
- }
2269
- SetIntensity(intensity) {
2270
- this._light.intensity = intensity;
2271
- }
2272
- SetEnabled(enabled) {
2273
- this._light.visible = enabled;
2274
- }
2275
- };
2276
-
2277
- // src/light/PointLight.ts
2278
- var import_three12 = require("three");
2279
-
2280
- // src/com/Communication.ts
2281
- var import_MathUtils = require("three/src/math/MathUtils");
2282
- init_SelectTool();
2283
- var import_lodash = require("lodash");
2284
- var _DIVECommunication = class _DIVECommunication {
2285
- constructor(renderer, scene, controls, toolbox) {
2286
- this.registered = /* @__PURE__ */ new Map();
2287
- // private listeners: { [key: string]: EventListener[] } = {};
2288
- this.listeners = /* @__PURE__ */ new Map();
2289
- this._id = (0, import_MathUtils.generateUUID)();
2290
- this.renderer = renderer;
2291
- this.scene = scene;
2292
- this.controller = controls;
2293
- this.toolbox = toolbox;
2294
- this._mediaGenerator = null;
2295
- this._io = null;
2296
- this._ar = null;
2297
- _DIVECommunication.__instances.push(this);
2298
- }
2299
- static get(id) {
2300
- const fromComID = this.__instances.find(
2301
- (instance) => instance.id === id
2302
- );
2303
- if (fromComID) return fromComID;
2304
- return this.__instances.find(
2305
- (instance) => Array.from(instance.registered.values()).find(
2306
- (object) => object.id === id
2307
- )
2308
- );
2309
- }
2310
- get id() {
2311
- return this._id;
2312
- }
2313
- get mediaGenerator() {
2314
- if (!this._mediaGenerator) {
2315
- const DIVEMediaCreator2 = (init_MediaCreator(), __toCommonJS(MediaCreator_exports)).DIVEMediaCreator;
2316
- this._mediaGenerator = new DIVEMediaCreator2(
2317
- this.renderer,
2318
- this.scene,
2319
- this.controller
2320
- );
2321
- }
2322
- return this._mediaGenerator;
2323
- }
2324
- get io() {
2325
- if (!this._io) {
2326
- const DIVEIO2 = (init_IO(), __toCommonJS(IO_exports)).DIVEIO;
2327
- this._io = new DIVEIO2(this.scene);
2328
- }
2329
- return this._io;
2330
- }
2331
- get ar() {
2332
- if (!this._ar) {
2333
- const DIVEAR2 = (init_AR(), __toCommonJS(AR_exports)).DIVEAR;
2334
- this._ar = new DIVEAR2(this.renderer, this.scene, this.controller);
2335
- }
2336
- return this._ar;
2337
- }
2338
- DestroyInstance() {
2339
- const existingIndex = _DIVECommunication.__instances.findIndex(
2340
- (entry) => entry.id === this.id
2341
- );
2342
- if (existingIndex === -1) return false;
2343
- _DIVECommunication.__instances.splice(existingIndex, 1);
2344
- return true;
2345
- }
2346
- PerformAction(action, payload) {
2347
- let returnValue = false;
2348
- switch (action) {
2349
- case "GET_ALL_SCENE_DATA": {
2350
- returnValue = this.getAllSceneData(
2351
- payload
2352
- );
2353
- break;
2354
- }
2355
- case "GET_ALL_OBJECTS": {
2356
- returnValue = this.getAllObjects(
2357
- payload
2358
- );
2359
- break;
2360
- }
2361
- case "GET_OBJECTS": {
2362
- returnValue = this.getObjects(
2363
- payload
2364
- );
2365
- break;
2366
- }
2367
- case "ADD_OBJECT": {
2368
- returnValue = this.addObject(
2369
- payload
2370
- );
2371
- break;
2372
- }
2373
- case "UPDATE_OBJECT": {
2374
- returnValue = this.updateObject(
2375
- payload
2376
- );
2377
- break;
2378
- }
2379
- case "DELETE_OBJECT": {
2380
- returnValue = this.deleteObject(
2381
- payload
2382
- );
2383
- break;
2384
- }
2385
- case "SELECT_OBJECT": {
2386
- returnValue = this.selectObject(
2387
- payload
2388
- );
2389
- break;
2390
- }
2391
- case "DESELECT_OBJECT": {
2392
- returnValue = this.deselectObject(
2393
- payload
2394
- );
2395
- break;
2396
- }
2397
- case "SET_BACKGROUND": {
2398
- returnValue = this.setBackground(
2399
- payload
2400
- );
2401
- break;
2402
- }
2403
- case "DROP_IT": {
2404
- returnValue = this.dropIt(
2405
- payload
2406
- );
2407
- break;
2408
- }
2409
- case "PLACE_ON_FLOOR": {
2410
- returnValue = this.placeOnFloor(
2411
- payload
2412
- );
2413
- break;
2414
- }
2415
- case "SET_CAMERA_TRANSFORM": {
2416
- returnValue = this.setCameraTransform(
2417
- payload
2418
- );
2419
- break;
2420
- }
2421
- case "GET_CAMERA_TRANSFORM": {
2422
- returnValue = this.getCameraTransform(
2423
- payload
2424
- );
2425
- break;
2426
- }
2427
- case "MOVE_CAMERA": {
2428
- returnValue = this.moveCamera(
2429
- payload
2430
- );
2431
- break;
2432
- }
2433
- case "RESET_CAMERA": {
2434
- returnValue = this.resetCamera(
2435
- payload
2436
- );
2437
- break;
2438
- }
2439
- case "COMPUTE_ENCOMPASSING_VIEW": {
2440
- returnValue = this.computeEncompassingView(
2441
- payload
2442
- );
2443
- break;
2444
- }
2445
- case "SET_CAMERA_LAYER": {
2446
- returnValue = this.setCameraLayer(
2447
- payload
2448
- );
2449
- break;
2450
- }
2451
- case "ZOOM_CAMERA": {
2452
- returnValue = this.zoomCamera(
2453
- payload
2454
- );
2455
- break;
2456
- }
2457
- case "SET_GIZMO_MODE": {
2458
- returnValue = this.setGizmoMode(
2459
- payload
2460
- );
2461
- break;
2462
- }
2463
- case "SET_GIZMO_VISIBILITY": {
2464
- returnValue = this.setGizmoVisibility(
2465
- payload
2466
- );
2467
- break;
2468
- }
2469
- case "SET_GIZMO_SCALE_LINKED": {
2470
- returnValue = this.setGizmoScaleLinked(
2471
- payload
2472
- );
2473
- break;
2474
- }
2475
- case "USE_TOOL": {
2476
- returnValue = this.useTool(
2477
- payload
2478
- );
2479
- break;
2480
- }
2481
- case "MODEL_LOADED": {
2482
- returnValue = this.modelLoaded(
2483
- payload
2484
- );
2485
- break;
2486
- }
2487
- case "UPDATE_SCENE": {
2488
- returnValue = this.updateScene(
2489
- payload
2490
- );
2491
- break;
2492
- }
2493
- case "GENERATE_MEDIA": {
2494
- returnValue = this.generateMedia(
2495
- payload
2496
- );
2497
- break;
2498
- }
2499
- case "SET_PARENT": {
2500
- returnValue = this.setParent(
2501
- payload
2502
- );
2503
- break;
2504
- }
2505
- case "EXPORT_SCENE": {
2506
- returnValue = this.exportScene(
2507
- payload
2508
- );
2509
- break;
2510
- }
2511
- case "LAUNCH_AR": {
2512
- returnValue = this.ar.Launch(
2513
- payload
2514
- );
2515
- break;
2516
- }
2517
- default: {
2518
- console.warn(
2519
- `DIVECommunication.PerformAction: has been executed with unknown Action type ${action}`
2520
- );
2521
- }
2522
- }
2523
- this.dispatch(action, payload);
2524
- return returnValue;
2525
- }
2526
- Subscribe(type, listener) {
2527
- if (!this.listeners.get(type)) this.listeners.set(type, []);
2528
- this.listeners.get(type).push(listener);
2529
- return () => {
2530
- const listenerArray = this.listeners.get(type);
2531
- if (!listenerArray) return false;
2532
- const existingIndex = listenerArray.findIndex(
2533
- (entry) => entry === listener
2534
- );
2535
- if (existingIndex === -1) return false;
2536
- listenerArray.splice(existingIndex, 1);
2537
- return true;
2538
- };
2539
- }
2540
- dispatch(type, payload) {
2541
- const listenerArray = this.listeners.get(type);
2542
- if (!listenerArray) return;
2543
- listenerArray.forEach((listener) => listener(payload));
2544
- }
2545
- getAllSceneData(payload) {
2546
- const sceneData = {
2547
- name: this.scene.name,
2548
- mediaItem: null,
2549
- backgroundColor: "#" + this.scene.background.getHexString(),
2550
- floorEnabled: this.scene.Floor.visible,
2551
- floorColor: "#" + this.scene.Floor.material.color.getHexString(),
2552
- userCamera: {
2553
- position: this.controller.object.position.clone(),
2554
- target: this.controller.target.clone()
2555
- },
2556
- spotmarks: [],
2557
- lights: Array.from(this.registered.values()).filter(
2558
- (object) => object.entityType === "light"
2559
- ),
2560
- objects: Array.from(this.registered.values()).filter(
2561
- (object) => object.entityType === "model"
2562
- ),
2563
- cameras: Array.from(this.registered.values()).filter(
2564
- (object) => object.entityType === "pov"
2565
- ),
2566
- primitives: Array.from(this.registered.values()).filter(
2567
- (object) => object.entityType === "primitive"
2568
- ),
2569
- groups: Array.from(this.registered.values()).filter(
2570
- (object) => object.entityType === "group"
2571
- )
2572
- };
2573
- Object.assign(payload, sceneData);
2574
- return sceneData;
2575
- }
2576
- getAllObjects(payload) {
2577
- Object.assign(payload, this.registered);
2578
- return this.registered;
2579
- }
2580
- getObjects(payload) {
2581
- if (payload.ids.length === 0) return [];
2582
- const objects = [];
2583
- this.registered.forEach((object) => {
2584
- if (!payload.ids.includes(object.id)) return;
2585
- objects.push(object);
2586
- });
2587
- return objects;
2588
- }
2589
- addObject(payload) {
2590
- if (this.registered.get(payload.id)) return false;
2591
- if (payload.parentId === void 0) payload.parentId = null;
2592
- this.registered.set(payload.id, payload);
2593
- this.scene.AddSceneObject(payload);
2594
- return true;
2595
- }
2596
- updateObject(payload) {
2597
- const objectToUpdate = this.registered.get(payload.id);
2598
- if (!objectToUpdate) return false;
2599
- this.registered.set(payload.id, (0, import_lodash.merge)(objectToUpdate, payload));
2600
- const updatedObject = this.registered.get(payload.id);
2601
- this.scene.UpdateSceneObject(__spreadProps(__spreadValues({}, payload), {
2602
- id: updatedObject.id,
2603
- entityType: updatedObject.entityType
2604
- }));
2605
- Object.assign(payload, updatedObject);
2606
- return true;
2607
- }
2608
- deleteObject(payload) {
2609
- const deletedObject = this.registered.get(payload.id);
2610
- if (!deletedObject) return false;
2611
- if (deletedObject.parentId) {
2612
- this.setParent({
2613
- object: { id: deletedObject.id },
2614
- parent: null
2615
- });
2616
- }
2617
- if (deletedObject.entityType === "group") {
2618
- this.registered.forEach((object) => {
2619
- if (object.parentId === deletedObject.id) {
2620
- this.updateObject({
2621
- id: object.id,
2622
- parentId: null
2623
- });
2624
- }
2625
- });
2626
- }
2627
- Object.assign(payload, deletedObject);
2628
- this.registered.delete(payload.id);
2629
- Array.from(this.registered.values()).forEach((object) => {
2630
- if (!object.parentId) return;
2631
- if (object.parentId !== payload.id) return;
2632
- object.parentId = null;
2633
- });
2634
- this.scene.DeleteSceneObject(deletedObject);
2635
- return true;
2636
- }
2637
- selectObject(payload) {
2638
- const object = this.registered.get(payload.id);
2639
- if (!object) return false;
2640
- const sceneObject = this.scene.GetSceneObject(object);
2641
- if (!sceneObject) return false;
2642
- if (!("isSelectable" in sceneObject)) return false;
2643
- const activeTool = this.toolbox.GetActiveTool();
2644
- if (activeTool && isSelectTool(activeTool)) {
2645
- activeTool.AttachGizmo(sceneObject);
2646
- }
2647
- Object.assign(payload, object);
2648
- return true;
2649
- }
2650
- deselectObject(payload) {
2651
- const object = this.registered.get(payload.id);
2652
- if (!object) return false;
2653
- const sceneObject = this.scene.GetSceneObject(object);
2654
- if (!sceneObject) return false;
2655
- if (!("isSelectable" in sceneObject)) return false;
2656
- const activeTool = this.toolbox.GetActiveTool();
2657
- if (activeTool && isSelectTool(activeTool)) {
2658
- activeTool.DetachGizmo();
2659
- }
2660
- Object.assign(payload, object);
2661
- return true;
2662
- }
2663
- setBackground(payload) {
2664
- this.scene.SetBackground(payload.color);
2665
- return true;
2666
- }
2667
- dropIt(payload) {
2668
- const object = this.registered.get(payload.id);
2669
- if (!object) return false;
2670
- const model = this.scene.GetSceneObject(object);
2671
- model.DropIt();
2672
- return true;
2673
- }
2674
- placeOnFloor(payload) {
2675
- const object = this.registered.get(payload.id);
2676
- if (!object) return false;
2677
- this.scene.PlaceOnFloor(object);
2678
- return true;
2679
- }
2680
- setCameraTransform(payload) {
2681
- this.controller.object.position.copy(payload.position);
2682
- this.controller.target.copy(payload.target);
2683
- this.controller.update();
2684
- return true;
2685
- }
2686
- getCameraTransform(payload) {
2687
- const transform = {
2688
- position: this.controller.object.position.clone(),
2689
- target: this.controller.target.clone()
2690
- };
2691
- Object.assign(payload, transform);
2692
- return transform;
2693
- }
2694
- moveCamera(payload) {
2695
- let position = { x: 0, y: 0, z: 0 };
2696
- let target = { x: 0, y: 0, z: 0 };
2697
- if ("id" in payload) {
2698
- position = this.registered.get(payload.id).position;
2699
- target = this.registered.get(payload.id).target;
2700
- } else {
2701
- position = payload.position;
2702
- target = payload.target;
2703
- }
2704
- this.controller.MoveTo(
2705
- position,
2706
- target,
2707
- payload.duration,
2708
- payload.locked
2709
- );
2710
- return true;
2711
- }
2712
- setCameraLayer(payload) {
2713
- this.controller.object.SetCameraLayer(payload.layer);
2714
- return true;
2715
- }
2716
- resetCamera(payload) {
2717
- this.controller.RevertLast(payload.duration);
2718
- return true;
2719
- }
2720
- computeEncompassingView(payload) {
2721
- const sceneBB = this.scene.ComputeSceneBB();
2722
- const transform = this.controller.ComputeEncompassingView(sceneBB);
2723
- Object.assign(payload, transform);
2724
- return transform;
2725
- }
2726
- zoomCamera(payload) {
2727
- if (payload.direction === "IN") this.controller.ZoomIn(payload.by);
2728
- if (payload.direction === "OUT") this.controller.ZoomOut(payload.by);
2729
- return true;
2730
- }
2731
- setGizmoMode(payload) {
2732
- this.toolbox.SetGizmoMode(payload.mode);
2733
- return true;
2734
- }
2735
- setGizmoVisibility(payload) {
2736
- this.toolbox.SetGizmoVisibility(payload);
2737
- return payload;
2738
- }
2739
- setGizmoScaleLinked(payload) {
2740
- this.toolbox.SetGizmoScaleLinked(payload);
2741
- return payload;
2742
- }
2743
- useTool(payload) {
2744
- this.toolbox.UseTool(payload.tool);
2745
- return true;
2746
- }
2747
- modelLoaded(payload) {
2748
- this.registered.get(payload.id).loaded = true;
2749
- return true;
2750
- }
2751
- updateScene(payload) {
2752
- if (payload.name !== void 0) this.scene.name = payload.name;
2753
- if (payload.backgroundColor !== void 0)
2754
- this.scene.SetBackground(payload.backgroundColor);
2755
- if (payload.gridEnabled !== void 0)
2756
- this.scene.Grid.SetVisibility(payload.gridEnabled);
2757
- if (payload.floorEnabled !== void 0)
2758
- this.scene.Floor.SetVisibility(payload.floorEnabled);
2759
- if (payload.floorColor !== void 0)
2760
- this.scene.Floor.SetColor(payload.floorColor);
2761
- payload.name = this.scene.name;
2762
- payload.backgroundColor = "#" + this.scene.background.getHexString();
2763
- payload.gridEnabled = this.scene.Grid.visible;
2764
- payload.floorEnabled = this.scene.Floor.visible;
2765
- payload.floorColor = "#" + this.scene.Floor.material.color.getHexString();
2766
- return true;
2767
- }
2768
- generateMedia(payload) {
2769
- let position = { x: 0, y: 0, z: 0 };
2770
- let target = { x: 0, y: 0, z: 0 };
2771
- if ("id" in payload) {
2772
- position = this.registered.get(payload.id).position;
2773
- target = this.registered.get(payload.id).target;
2774
- } else {
2775
- position = payload.position;
2776
- target = payload.target;
2777
- }
2778
- payload.dataUri = this.mediaGenerator.GenerateMedia(
2779
- position,
2780
- target,
2781
- payload.width,
2782
- payload.height
2783
- );
2784
- return true;
2785
- }
2786
- setParent(payload) {
2787
- const object = this.registered.get(payload.object.id);
2788
- if (!object) return false;
2789
- const sceneObject = this.scene.GetSceneObject(object);
2790
- if (!sceneObject) return false;
2791
- if (payload.parent === null) {
2792
- this.scene.Root.attach(sceneObject);
2793
- this.updateObject({
2794
- id: object.id,
2795
- parentId: null
2796
- });
2797
- return true;
2798
- }
2799
- if (payload.object.id === payload.parent.id) {
2800
- return false;
2801
- }
2802
- const parent = this.registered.get(payload.parent.id);
2803
- if (!parent) {
2804
- this.scene.Root.attach(sceneObject);
2805
- this.updateObject({
2806
- id: object.id,
2807
- parentId: null
2808
- });
2809
- return true;
2810
- }
2811
- const parentObject = this.scene.GetSceneObject(parent);
2812
- if (!parentObject) {
2813
- this.scene.Root.attach(sceneObject);
2814
- this.updateObject({
2815
- id: object.id,
2816
- parentId: null
2817
- });
2818
- return true;
2819
- }
2820
- parentObject.attach(sceneObject);
2821
- this.updateObject({
2822
- id: object.id,
2823
- parentId: parent.id
2824
- });
2825
- return true;
2826
- }
2827
- exportScene(payload) {
2828
- return this.io.Export(payload.type);
2829
- }
2830
- };
2831
- _DIVECommunication.__instances = [];
2832
- var DIVECommunication = _DIVECommunication;
2833
-
2834
- // src/light/PointLight.ts
2835
- init_VisibilityLayerMask();
2836
- var DIVEPointLight = class extends import_three12.Object3D {
2837
- constructor() {
2838
- super();
2839
- this.isDIVELight = true;
2840
- this.isDIVEPointLight = true;
2841
- this.isMovable = true;
2842
- this.isSelectable = true;
2843
- this.gizmo = null;
2844
- this.name = "DIVEPointLight";
2845
- this.light = new import_three12.PointLight(16777215, 1);
2846
- this.light.layers.mask = PRODUCT_LAYER_MASK;
2847
- this.light.castShadow = true;
2848
- this.light.shadow.mapSize.width = 512;
2849
- this.light.shadow.mapSize.height = 512;
2850
- this.add(this.light);
2851
- const geoSize = 0.1;
2852
- const geometry = new import_three12.SphereGeometry(
2853
- geoSize,
2854
- geoSize * 320,
2855
- geoSize * 320
2856
- );
2857
- const material = new import_three12.MeshBasicMaterial({
2858
- color: this.light.color,
2859
- transparent: true,
2860
- opacity: 0.8,
2861
- side: import_three12.FrontSide
2862
- });
2863
- this.mesh = new import_three12.Mesh(geometry, material);
2864
- this.mesh.layers.mask = UI_LAYER_MASK;
2865
- this.add(this.mesh);
2866
- }
2867
- SetColor(color) {
2868
- this.light.color = color;
2869
- this.mesh.material.color = color;
2870
- }
2871
- SetIntensity(intensity) {
2872
- this.light.intensity = intensity;
2873
- this.mesh.material.opacity = intensity > 0.8 ? 0.8 : intensity * 0.8;
2874
- }
2875
- SetEnabled(enabled) {
2876
- this.light.visible = enabled;
2877
- }
2878
- onMove() {
2879
- var _a;
2880
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
2881
- "UPDATE_OBJECT",
2882
- { id: this.userData.id, position: this.position }
2883
- );
2884
- }
2885
- onSelect() {
2886
- var _a;
2887
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
2888
- "SELECT_OBJECT",
2889
- { id: this.userData.id }
2890
- );
2891
- }
2892
- onDeselect() {
2893
- var _a;
2894
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
2895
- "DESELECT_OBJECT",
2896
- { id: this.userData.id }
2897
- );
2898
- }
2899
- };
2900
-
2901
- // src/light/SceneLight.ts
2902
- init_VisibilityLayerMask();
2903
- var import_three13 = require("three");
2904
- var DIVESceneLight = class extends import_three13.Object3D {
2905
- constructor() {
2906
- super();
2907
- this.isDIVELight = true;
2908
- this.isDIVESceneLight = true;
2909
- this.name = "DIVESceneLight";
2910
- this._hemiLight = new import_three13.HemisphereLight(16777215, 16777215, 2);
2911
- this._hemiLight.layers.mask = PRODUCT_LAYER_MASK;
2912
- this._hemiLight.position.set(0, 50, 0);
2913
- this.add(this._hemiLight);
2914
- this._dirLight = new import_three13.DirectionalLight(16777215, 3);
2915
- this._dirLight.layers.mask = PRODUCT_LAYER_MASK;
2916
- this._dirLight.position.set(1, 1.75, 1);
2917
- this._dirLight.position.multiplyScalar(30);
2918
- this._dirLight.castShadow = true;
2919
- this._dirLight.shadow.mapSize.width = 2048;
2920
- this._dirLight.shadow.mapSize.height = 2048;
2921
- const d = 5;
2922
- this._dirLight.shadow.camera.left = -d;
2923
- this._dirLight.shadow.camera.right = d;
2924
- this._dirLight.shadow.camera.top = d;
2925
- this._dirLight.shadow.camera.bottom = -d;
2926
- this._dirLight.shadow.camera.far = 3500;
2927
- this.add(this._dirLight);
2928
- }
2929
- SetColor(color) {
2930
- this._hemiLight.color = color;
2931
- this._dirLight.color = color;
2932
- }
2933
- SetIntensity(intensity) {
2934
- this._hemiLight.intensity = intensity * 2;
2935
- this._dirLight.intensity = intensity * 3;
2936
- }
2937
- SetEnabled(enabled) {
2938
- this._hemiLight.visible = enabled;
2939
- this._dirLight.visible = enabled;
2940
- }
2941
- };
2942
-
2943
- // src/model/Model.ts
2944
- var import_three15 = require("three");
2945
- init_VisibilityLayerMask();
2946
-
2947
- // src/helper/findSceneRecursive/findSceneRecursive.ts
2948
- var findSceneRecursive = (object) => {
2949
- if (object.parent) {
2950
- return findSceneRecursive(object.parent);
2951
- }
2952
- return object;
2953
- };
2954
-
2955
- // src/node/Node.ts
2956
- var import_three14 = require("three");
2957
- init_VisibilityLayerMask();
2958
- var DIVENode = class extends import_three14.Object3D {
2959
- constructor() {
2960
- super();
2961
- this.isDIVENode = true;
2962
- this.isSelectable = true;
2963
- this.isMovable = true;
2964
- this.gizmo = null;
2965
- this.layers.mask = PRODUCT_LAYER_MASK;
2966
- this._positionWorldBuffer = new import_three14.Vector3();
2967
- this._boundingBox = new import_three14.Box3();
2968
- }
2969
- SetPosition(position) {
2970
- if (!this.parent) {
2971
- this.position.set(position.x, position.y, position.z);
2972
- return;
2973
- }
2974
- const newPosition = new import_three14.Vector3(position.x, position.y, position.z);
2975
- this.position.copy(this.parent.worldToLocal(newPosition));
2976
- if ("isDIVEGroup" in this.parent) {
2977
- this.parent.UpdateLineTo(this);
2978
- }
2979
- }
2980
- SetRotation(rotation) {
2981
- this.rotation.set(rotation.x, rotation.y, rotation.z);
2982
- }
2983
- SetScale(scale) {
2984
- this.scale.set(scale.x, scale.y, scale.z);
2985
- }
2986
- SetVisibility(visible) {
2987
- this.visible = visible;
2988
- }
2989
- SetToWorldOrigin() {
2990
- var _a;
2991
- this.position.set(0, 0, 0);
2992
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
2993
- "UPDATE_OBJECT",
2994
- {
2995
- id: this.userData.id,
2996
- position: this.getWorldPosition(this._positionWorldBuffer),
2997
- rotation: this.rotation,
2998
- scale: this.scale
2999
- }
3000
- );
3001
- }
3002
- /**
3003
- * Can be called when the object is moved from a foreign object (gizmo, parent, etc.) to update the object's position.
3004
- */
3005
- onMove() {
3006
- var _a;
3007
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3008
- "UPDATE_OBJECT",
3009
- {
3010
- id: this.userData.id,
3011
- position: this.getWorldPosition(this._positionWorldBuffer),
3012
- rotation: this.rotation,
3013
- scale: this.scale
3014
- }
3015
- );
3016
- }
3017
- onSelect() {
3018
- var _a;
3019
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3020
- "SELECT_OBJECT",
3021
- { id: this.userData.id }
3022
- );
3023
- }
3024
- onDeselect() {
3025
- var _a;
3026
- (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction(
3027
- "DESELECT_OBJECT",
3028
- { id: this.userData.id }
3029
- );
3030
- }
3031
- };
3032
-
3033
- // src/model/Model.ts
3034
- var DIVEModel = class extends DIVENode {
3035
- constructor() {
3036
- super(...arguments);
3037
- this.isDIVEModel = true;
3038
- this._mesh = null;
3039
- this._material = null;
3040
- }
3041
- SetModel(gltf) {
3042
- this.clear();
3043
- this._boundingBox.makeEmpty();
3044
- gltf.scene.traverse((child) => {
3045
- child.castShadow = true;
3046
- child.receiveShadow = true;
3047
- child.layers.mask = this.layers.mask;
3048
- this._boundingBox.expandByObject(child);
3049
- if (!this._mesh && "isMesh" in child) {
3050
- this._mesh = child;
3051
- if (this._material) {
3052
- this._mesh.material = this._material;
3053
- } else {
3054
- this._material = child.material;
3055
- }
3056
- }
3057
- });
3058
- this.add(gltf.scene);
3059
- }
3060
- SetMaterial(material) {
3061
- if (!this._material) {
3062
- this._material = new import_three15.MeshStandardMaterial();
3063
- }
3064
- if (material.vertexColors !== void 0) {
3065
- this._material.vertexColors = material.vertexColors;
3066
- }
3067
- if (material.color !== void 0) {
3068
- this._material.color.set(material.color);
3069
- }
3070
- if (material.map !== void 0) {
3071
- this._material.map = material.map;
3072
- }
3073
- if (material.normalMap !== void 0) {
3074
- this._material.normalMap = material.normalMap;
3075
- }
3076
- if (material.roughness !== void 0) {
3077
- this._material.roughness = material.roughness;
3078
- }
3079
- if (material.roughnessMap !== void 0) {
3080
- this._material.roughnessMap = material.roughnessMap;
3081
- if (this._material.roughnessMap) {
3082
- this._material.roughness = 1;
3083
- }
3084
- }
3085
- if (material.metalness !== void 0) {
3086
- this._material.metalness = material.metalness;
3087
- }
3088
- if (material.metalnessMap !== void 0) {
3089
- this._material.metalnessMap = material.metalnessMap;
3090
- if (this._material.metalnessMap) {
3091
- this._material.metalness = 1;
3092
- }
3093
- }
3094
- if (this._mesh) {
3095
- this._mesh.material = this._material;
3096
- }
3097
- }
3098
- PlaceOnFloor() {
3099
- var _a, _b, _c, _d, _e;
3100
- const worldPos = this.getWorldPosition(this._positionWorldBuffer);
3101
- const oldWorldPos = worldPos.clone();
3102
- (_b = (_a = this._mesh) == null ? void 0 : _a.geometry) == null ? void 0 : _b.computeBoundingBox();
3103
- const meshBB = (_d = (_c = this._mesh) == null ? void 0 : _c.geometry) == null ? void 0 : _d.boundingBox;
3104
- if (!meshBB || !this._mesh) return;
3105
- worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
3106
- if (worldPos.y === oldWorldPos.y) return;
3107
- (_e = DIVECommunication.get(this.userData.id)) == null ? void 0 : _e.PerformAction(
3108
- "UPDATE_OBJECT",
3109
- {
3110
- id: this.userData.id,
3111
- position: worldPos,
3112
- rotation: this.rotation,
3113
- scale: this.scale
3114
- }
3115
- );
3116
- }
3117
- DropIt() {
3118
- if (!this.parent) {
3119
- console.warn(
3120
- "DIVEModel: DropIt() called on a model that is not in the scene.",
3121
- this
3122
- );
3123
- return;
3124
- }
3125
- const bottomY = this._boundingBox.min.y * this.scale.y;
3126
- const bbBottomCenter = this.localToWorld(
3127
- this._boundingBox.getCenter(new import_three15.Vector3()).multiply(this.scale)
3128
- );
3129
- bbBottomCenter.y = bottomY + this.position.y;
3130
- const raycaster = new import_three15.Raycaster(bbBottomCenter, new import_three15.Vector3(0, -1, 0));
3131
- raycaster.layers.mask = PRODUCT_LAYER_MASK;
3132
- const intersections = raycaster.intersectObjects(
3133
- findSceneRecursive(this).Root.children,
3134
- true
3135
- );
3136
- if (intersections.length > 0) {
3137
- const mesh = intersections[0].object;
3138
- mesh.geometry.computeBoundingBox();
3139
- const meshBB = mesh.geometry.boundingBox;
3140
- const worldPos = mesh.localToWorld(meshBB.max.clone());
3141
- const oldPos = this.position.clone();
3142
- const newPos = this.position.clone().setY(worldPos.y).sub(new import_three15.Vector3(0, bottomY, 0));
3143
- this.position.copy(newPos);
3144
- if (this.position.y === oldPos.y) return;
3145
- this.onMove();
3146
- }
3147
- }
3148
- };
3149
-
3150
- // src/loadingmanager/LoadingManager.ts
3151
- var import_DRACOLoader = require("three/examples/jsm/loaders/DRACOLoader");
3152
- var import_GLTFLoader2 = require("three/examples/jsm/loaders/GLTFLoader");
3153
- var DIVELoadingManager = class {
3154
- // ... maybe extend with other loaders later
3155
- constructor() {
3156
- this.progress = /* @__PURE__ */ new Map();
3157
- this.gltfloader = new import_GLTFLoader2.GLTFLoader();
3158
- this.dracoloader = new import_DRACOLoader.DRACOLoader();
3159
- this.dracoloader.setDecoderPath(
3160
- "https://www.gstatic.com/draco/v1/decoders/"
3161
- );
3162
- this.gltfloader.setDRACOLoader(this.dracoloader);
3163
- }
3164
- LoadGLTF(uri) {
3165
- return __async(this, null, function* () {
3166
- const progEvent = (p) => {
3167
- this.progress.set(uri, p.loaded / p.total);
3168
- };
3169
- this.progress.set(uri, 0);
3170
- return new Promise((resolve, reject) => {
3171
- this.gltfloader.loadAsync(uri, progEvent).then(resolve).catch(reject);
3172
- });
3173
- });
3174
- }
3175
- PollProgress() {
3176
- let total = 0;
3177
- this.progress.forEach((progress) => {
3178
- total += progress;
3179
- });
3180
- if (this.progress.size === 0) return 1;
3181
- return total / this.progress.size;
3182
- }
3183
- };
3184
-
3185
- // src/primitive/Primitive.ts
3186
- var import_three16 = require("three");
3187
- init_VisibilityLayerMask();
3188
- var DIVEPrimitive = class extends DIVENode {
3189
- constructor() {
3190
- super();
3191
- this.isDIVEPrimitive = true;
3192
- this._mesh = new import_three16.Mesh();
3193
- this._mesh.layers.mask = PRODUCT_LAYER_MASK;
3194
- this._mesh.castShadow = true;
3195
- this._mesh.receiveShadow = true;
3196
- this._mesh.material = new import_three16.MeshStandardMaterial();
3197
- this.add(this._mesh);
3198
- }
3199
- SetGeometry(geometry) {
3200
- const geo = this.assembleGeometry(geometry);
3201
- if (!geo) return;
3202
- this._mesh.geometry = geo;
3203
- this._boundingBox.setFromObject(this._mesh);
3204
- }
3205
- SetMaterial(material) {
3206
- const primitiveMaterial = this._mesh.material;
3207
- if (material.vertexColors !== void 0) {
3208
- primitiveMaterial.vertexColors = material.vertexColors;
3209
- }
3210
- if (material.color !== void 0) {
3211
- primitiveMaterial.color = new import_three16.Color(material.color);
3212
- }
3213
- if (material.map !== void 0) {
3214
- primitiveMaterial.map = material.map;
3215
- }
3216
- if (material.normalMap !== void 0) {
3217
- primitiveMaterial.normalMap = material.normalMap;
3218
- }
3219
- if (material.roughness !== void 0) {
3220
- primitiveMaterial.roughness = material.roughness;
3221
- }
3222
- if (material.roughnessMap !== void 0) {
3223
- primitiveMaterial.roughnessMap = material.roughnessMap;
3224
- if (primitiveMaterial.roughnessMap) {
3225
- primitiveMaterial.roughness = 1;
3226
- }
3227
- }
3228
- if (material.metalness !== void 0) {
3229
- primitiveMaterial.metalness = material.metalness;
3230
- }
3231
- if (material.metalnessMap !== void 0) {
3232
- primitiveMaterial.metalnessMap = material.metalnessMap;
3233
- if (primitiveMaterial.metalnessMap) {
3234
- primitiveMaterial.metalness = 0;
3235
- }
3236
- }
3237
- if (this._mesh) this._mesh.material = primitiveMaterial;
3238
- }
3239
- PlaceOnFloor() {
3240
- var _a, _b, _c, _d, _e;
3241
- const worldPos = this.getWorldPosition(this._positionWorldBuffer);
3242
- const oldWorldPos = worldPos.clone();
3243
- (_b = (_a = this._mesh) == null ? void 0 : _a.geometry) == null ? void 0 : _b.computeBoundingBox();
3244
- const meshBB = (_d = (_c = this._mesh) == null ? void 0 : _c.geometry) == null ? void 0 : _d.boundingBox;
3245
- if (!meshBB || !this._mesh) return;
3246
- worldPos.y = worldPos.y - this._mesh.localToWorld(meshBB.min.clone()).y;
3247
- if (worldPos.y === oldWorldPos.y) return;
3248
- (_e = DIVECommunication.get(this.userData.id)) == null ? void 0 : _e.PerformAction(
3249
- "UPDATE_OBJECT",
3250
- {
3251
- id: this.userData.id,
3252
- position: worldPos,
3253
- rotation: this.rotation,
3254
- scale: this.scale
3255
- }
3256
- );
3257
- }
3258
- DropIt() {
3259
- if (!this.parent) {
3260
- console.warn(
3261
- "DIVEPrimitive: DropIt() called on a model that is not in the scene.",
3262
- this
3263
- );
3264
- return;
3265
- }
3266
- const bottomY = this._boundingBox.min.y * this.scale.y;
3267
- const bbBottomCenter = this.localToWorld(
3268
- this._boundingBox.getCenter(new import_three16.Vector3()).multiply(this.scale)
3269
- );
3270
- bbBottomCenter.y = bottomY + this.position.y;
3271
- const raycaster = new import_three16.Raycaster(bbBottomCenter, new import_three16.Vector3(0, -1, 0));
3272
- raycaster.layers.mask = PRODUCT_LAYER_MASK;
3273
- const intersections = raycaster.intersectObjects(
3274
- findSceneRecursive(this).Root.children,
3275
- true
3276
- );
3277
- if (intersections.length > 0) {
3278
- const mesh = intersections[0].object;
3279
- mesh.geometry.computeBoundingBox();
3280
- const meshBB = mesh.geometry.boundingBox;
3281
- const worldPos = mesh.localToWorld(meshBB.max.clone());
3282
- const oldPos = this.position.clone();
3283
- const newPos = this.position.clone().setY(worldPos.y).sub(new import_three16.Vector3(0, bottomY, 0));
3284
- this.position.copy(newPos);
3285
- if (this.position.y === oldPos.y) return;
3286
- this.onMove();
3287
- }
3288
- }
3289
- assembleGeometry(geometry) {
3290
- this._mesh.material.flatShading = false;
3291
- switch (geometry.name.toLowerCase()) {
3292
- case "cylinder":
3293
- return this.createCylinderGeometry(geometry);
3294
- case "sphere":
3295
- return this.createSphereGeometry(geometry);
3296
- case "pyramid":
3297
- this._mesh.material.flatShading = true;
3298
- return this.createPyramidGeometry(geometry);
3299
- case "cube":
3300
- case "box":
3301
- return this.createBoxGeometry(geometry);
3302
- case "cone":
3303
- return this.createConeGeometry(geometry);
3304
- case "wall":
3305
- return this.createWallGeometry(geometry);
3306
- case "plane":
3307
- return this.createPlaneGeometry(geometry);
3308
- default: {
3309
- console.warn(
3310
- "DIVEPrimitive.assembleGeometry: Invalid geometry type:",
3311
- geometry.name.toLowerCase()
3312
- );
3313
- return null;
3314
- }
3315
- }
3316
- }
3317
- createCylinderGeometry(geometry) {
3318
- const geo = new import_three16.CylinderGeometry(
3319
- geometry.width / 2,
3320
- geometry.width / 2,
3321
- geometry.height,
3322
- 64
3323
- );
3324
- geo.translate(0, geometry.height / 2, 0);
3325
- return geo;
3326
- }
3327
- createSphereGeometry(geometry) {
3328
- const geo = new import_three16.SphereGeometry(geometry.width / 2, 256, 256);
3329
- return geo;
3330
- }
3331
- createPyramidGeometry(geometry) {
3332
- const vertices = new Float32Array([
3333
- -geometry.width / 2,
3334
- 0,
3335
- -geometry.depth / 2,
3336
- // 0
3337
- geometry.width / 2,
3338
- 0,
3339
- -geometry.depth / 2,
3340
- // 1
3341
- geometry.width / 2,
3342
- 0,
3343
- geometry.depth / 2,
3344
- // 2
3345
- -geometry.width / 2,
3346
- 0,
3347
- geometry.depth / 2,
3348
- // 3
3349
- 0,
3350
- geometry.height,
3351
- 0
3352
- ]);
3353
- const indices = new Uint16Array([
3354
- 0,
3355
- 1,
3356
- 2,
3357
- 0,
3358
- 2,
3359
- 3,
3360
- 0,
3361
- 4,
3362
- 1,
3363
- 1,
3364
- 4,
3365
- 2,
3366
- 2,
3367
- 4,
3368
- 3,
3369
- 3,
3370
- 4,
3371
- 0
3372
- ]);
3373
- const geometryBuffer = new import_three16.BufferGeometry();
3374
- geometryBuffer.setAttribute(
3375
- "position",
3376
- new import_three16.BufferAttribute(vertices, 3)
3377
- );
3378
- geometryBuffer.setIndex(new import_three16.BufferAttribute(indices, 1));
3379
- geometryBuffer.computeVertexNormals();
3380
- geometryBuffer.computeBoundingBox();
3381
- geometryBuffer.computeBoundingSphere();
3382
- return geometryBuffer;
3383
- }
3384
- createBoxGeometry(geometry) {
3385
- const geo = new import_three16.BoxGeometry(
3386
- geometry.width,
3387
- geometry.height,
3388
- geometry.depth
3389
- );
3390
- geo.translate(0, geometry.height / 2, 0);
3391
- return geo;
3392
- }
3393
- createConeGeometry(geometry) {
3394
- const geo = new import_three16.ConeGeometry(geometry.width / 2, geometry.height, 256);
3395
- geo.translate(0, geometry.height / 2, 0);
3396
- return geo;
3397
- }
3398
- createWallGeometry(geometry) {
3399
- const geo = new import_three16.BoxGeometry(
3400
- geometry.width,
3401
- geometry.height,
3402
- geometry.depth || 0.05,
3403
- 16
3404
- );
3405
- geo.translate(0, geometry.height / 2, 0);
3406
- return geo;
3407
- }
3408
- createPlaneGeometry(geometry) {
3409
- const geo = new import_three16.BoxGeometry(
3410
- geometry.width,
3411
- geometry.height,
3412
- geometry.depth
3413
- );
3414
- geo.translate(0, geometry.height / 2, 0);
3415
- return geo;
3416
- }
3417
- };
3418
-
3419
- // src/group/Group.ts
3420
- var import_three17 = require("three");
3421
- var DIVEGroup = class extends DIVENode {
3422
- // lines to children
3423
- constructor() {
3424
- super();
3425
- this.isDIVEGroup = true;
3426
- this.name = "DIVEGroup";
3427
- this._members = [];
3428
- this._lines = [];
3429
- }
3430
- // children objects
3431
- get members() {
3432
- return this._members;
3433
- }
3434
- SetPosition(position) {
3435
- super.SetPosition(position);
3436
- this._members.forEach((member) => {
3437
- if ("isDIVENode" in member) {
3438
- member.onMove();
3439
- }
3440
- });
3441
- }
3442
- SetLinesVisibility(visible, object) {
3443
- if (!object) {
3444
- this._lines.forEach((line) => {
3445
- line.visible = visible;
3446
- });
3447
- return;
3448
- }
3449
- const index = this._members.indexOf(object);
3450
- if (index === -1) return;
3451
- this._lines[index].visible = visible;
3452
- }
3453
- attach(object) {
3454
- if (this._members.includes(object)) {
3455
- return this;
3456
- }
3457
- const line = this.createLine();
3458
- this.add(line);
3459
- this._lines.push(line);
3460
- super.attach(object);
3461
- this._members.push(object);
3462
- this.updateLineTo(line, object);
3463
- this.SetLinesVisibility(true, object);
3464
- return this;
3465
- }
3466
- remove(object) {
3467
- const index = this._members.indexOf(object);
3468
- if (index === -1) return this;
3469
- const line = this._lines[index];
3470
- super.remove(line);
3471
- this._lines.splice(index, 1);
3472
- super.remove(object);
3473
- this._members.splice(index, 1);
3474
- return this;
3475
- }
3476
- UpdateLineTo(object) {
3477
- const index = this._members.indexOf(object);
3478
- if (index === -1) return;
3479
- this.updateLineTo(this._lines[index], object);
3480
- }
3481
- /**
3482
- * Adds a line to this grouo as last child.
3483
- */
3484
- createLine() {
3485
- const geo = new import_three17.BufferGeometry();
3486
- const mat = new import_three17.LineDashedMaterial({
3487
- color: 6710886,
3488
- dashSize: 0.05,
3489
- gapSize: 0.025
3490
- });
3491
- const line = new import_three17.Line(geo, mat);
3492
- line.visible = false;
3493
- return line;
3494
- }
3495
- /**
3496
- * Updates a line to the object.
3497
- */
3498
- updateLineTo(line, object) {
3499
- line.geometry.setFromPoints([
3500
- new import_three17.Vector3(0, 0, 0),
3501
- object.position.clone()
3502
- ]);
3503
- line.computeLineDistances();
3504
- }
3505
- // public SetBoundingBoxVisibility(visible: boolean): void {
3506
- // this._boxMesh.visible = visible;
3507
- // }
3508
- // /**
3509
- // * Recalculates the position of the group based on it's bounding box.
3510
- // * Children's world positions are kept.
3511
- // */
3512
- // private recalculatePosition(): void {
3513
- // // store all children's world positions
3514
- // const childrensWorldPositions: Vector3[] = this.children.map((child) => child.getWorldPosition(new Vector3()));
3515
- // // calculate new center and set it as the group's position
3516
- // const bbcenter = this.updateBB();
3517
- // this.position.copy(bbcenter);
3518
- // // set childrens's positions so their world positions are kept
3519
- // this.children.forEach((child, i) => {
3520
- // if (child.uuid === this._boxMesh.uuid) return;
3521
- // child.position.copy(this.worldToLocal(childrensWorldPositions[i]));
3522
- // });
3523
- // DIVECommunication.get(this.userData.id)?.PerformAction('UPDATE_OBJECT', { id: this.userData.id, position: this.position });
3524
- // }
3525
- // /**
3526
- // * Updates the bounding box of the group.
3527
- // * @returns {Vector3} The new center of the bounding box.
3528
- // */
3529
- // private updateBB(): Vector3 {
3530
- // this._boundingBox.makeEmpty();
3531
- // if (this.children.length === 1) {
3532
- // // because we always have the box mesh as 1 child
3533
- // return this.position.clone();
3534
- // }
3535
- // this.children.forEach((child) => {
3536
- // if (child.uuid === this._boxMesh.uuid) return;
3537
- // this._boundingBox.expandByObject(child);
3538
- // });
3539
- // return this._boundingBox.getCenter(new Vector3());
3540
- // }
3541
- // private updateBoxMesh(): void {
3542
- // if (this.children.length === 1) {
3543
- // // because we always have the box mesh as 1 child
3544
- // this._boxMesh.visible = false;
3545
- // return;
3546
- // }
3547
- // this._boxMesh.quaternion.copy(this.quaternion.clone().invert());
3548
- // this._boxMesh.scale.set(1 / this.scale.x, 1 / this.scale.y, 1 / this.scale.z);
3549
- // this._boxMesh.geometry = new BoxGeometry(this._boundingBox.max.x - this._boundingBox.min.x, this._boundingBox.max.y - this._boundingBox.min.y, this._boundingBox.max.z - this._boundingBox.min.z);
3550
- // this._boxMesh.visible = true;
3551
- // }
3552
- };
3553
-
3554
- // src/scene/root/Root.ts
3555
- var DIVERoot = class extends import_three18.Object3D {
3556
- constructor() {
3557
- super();
3558
- this.isDIVERoot = true;
3559
- this.name = "Root";
3560
- this.loadingManager = new DIVELoadingManager();
3561
- }
3562
- ComputeSceneBB() {
3563
- const bb = new import_three18.Box3();
3564
- this.traverse((object) => {
3565
- if ("isObject3D" in object) {
3566
- bb.expandByObject(object);
3567
- }
3568
- });
3569
- return bb;
3570
- }
3571
- GetSceneObject(object) {
3572
- let foundObject;
3573
- this.traverse((object3D) => {
3574
- if (foundObject) return;
3575
- if (object3D.userData.id === object.id) {
3576
- foundObject = object3D;
3577
- }
3578
- });
3579
- return foundObject;
3580
- }
3581
- AddSceneObject(object) {
3582
- switch (object.entityType) {
3583
- case "pov": {
3584
- break;
3585
- }
3586
- case "light": {
3587
- this.updateLight(object);
3588
- break;
3589
- }
3590
- case "model": {
3591
- this.updateModel(object);
3592
- break;
3593
- }
3594
- case "primitive": {
3595
- this.updatePrimitive(object);
3596
- break;
3597
- }
3598
- case "group": {
3599
- this.updateGroup(object);
3600
- break;
3601
- }
3602
- default: {
3603
- console.warn(
3604
- `DIVERoot.AddSceneObject: Unknown entity type: ${object.entityType}`
3605
- );
3606
- }
3607
- }
3608
- }
3609
- UpdateSceneObject(object) {
3610
- switch (object.entityType) {
3611
- case "pov": {
3612
- break;
3613
- }
3614
- case "light": {
3615
- this.updateLight(object);
3616
- break;
3617
- }
3618
- case "model": {
3619
- this.updateModel(object);
3620
- break;
3621
- }
3622
- case "primitive": {
3623
- this.updatePrimitive(object);
3624
- break;
3625
- }
3626
- case "group": {
3627
- this.updateGroup(object);
3628
- break;
3629
- }
3630
- default: {
3631
- console.warn(
3632
- `DIVERoot.UpdateSceneObject: Unknown entity type: ${object.entityType}`
3633
- );
3634
- }
3635
- }
3636
- }
3637
- DeleteSceneObject(object) {
3638
- switch (object.entityType) {
3639
- case "pov": {
3640
- break;
3641
- }
3642
- case "light": {
3643
- this.deleteLight(object);
3644
- break;
3645
- }
3646
- case "model": {
3647
- this.deleteModel(object);
3648
- break;
3649
- }
3650
- case "primitive": {
3651
- this.deletePrimitive(object);
3652
- break;
3653
- }
3654
- case "group": {
3655
- this.deleteGroup(object);
3656
- break;
3657
- }
3658
- default: {
3659
- console.warn(
3660
- `DIVERoot.DeleteSceneObject: Unknown entity type: ${object.entityType}`
3661
- );
3662
- }
3663
- }
3664
- }
3665
- PlaceOnFloor(object) {
3666
- switch (object.entityType) {
3667
- case "pov":
3668
- case "light": {
3669
- break;
3670
- }
3671
- case "model":
3672
- case "primitive": {
3673
- this.placeOnFloor(object);
3674
- break;
3675
- }
3676
- default: {
3677
- console.warn(
3678
- `DIVERoot.PlaceOnFloor: Unknown entity type: ${object.entityType}`
3679
- );
3680
- }
3681
- }
3682
- }
3683
- updateLight(light) {
3684
- let sceneObject = this.GetSceneObject(light);
3685
- if (!sceneObject) {
3686
- switch (light.type) {
3687
- case "scene": {
3688
- sceneObject = new DIVESceneLight();
3689
- break;
3690
- }
3691
- case "ambient": {
3692
- sceneObject = new DIVEAmbientLight();
3693
- break;
3694
- }
3695
- case "point": {
3696
- sceneObject = new DIVEPointLight();
3697
- break;
3698
- }
3699
- default: {
3700
- console.warn(
3701
- `DIVERoot.updateLight: Unknown light type: ${light.type}`
3702
- );
3703
- return;
3704
- }
3705
- }
3706
- sceneObject.userData.id = light.id;
3707
- this.add(sceneObject);
3708
- }
3709
- if (light.name !== void 0 && light.name !== null)
3710
- sceneObject.name = light.name;
3711
- if (light.position !== void 0 && light.position !== null)
3712
- sceneObject.position.set(
3713
- light.position.x,
3714
- light.position.y,
3715
- light.position.z
3716
- );
3717
- if (light.intensity !== void 0 && light.intensity !== null)
3718
- sceneObject.SetIntensity(
3719
- light.intensity
3720
- );
3721
- if (light.enabled !== void 0 && light.enabled !== null)
3722
- sceneObject.SetEnabled(
3723
- light.enabled
3724
- );
3725
- if (light.color !== void 0 && light.color !== null)
3726
- sceneObject.SetColor(
3727
- new import_three18.Color(light.color)
3728
- );
3729
- if (light.visible !== void 0 && light.visible !== null)
3730
- sceneObject.visible = light.visible;
3731
- if (light.parentId !== void 0)
3732
- this.setParent(__spreadProps(__spreadValues({}, light), { parentId: light.parentId }));
3733
- }
3734
- updateModel(model) {
3735
- let sceneObject = this.GetSceneObject(model);
3736
- if (!sceneObject) {
3737
- const created = new DIVEModel();
3738
- sceneObject = created;
3739
- sceneObject.userData.id = model.id;
3740
- sceneObject.userData.uri = model.uri;
3741
- this.add(sceneObject);
3742
- }
3743
- if (model.uri !== void 0) {
3744
- this.loadingManager.LoadGLTF(model.uri).then((gltf) => {
3745
- var _a;
3746
- sceneObject.SetModel(gltf);
3747
- (_a = DIVECommunication.get(model.id)) == null ? void 0 : _a.PerformAction(
3748
- "MODEL_LOADED",
3749
- { id: model.id }
3750
- );
3751
- });
3752
- }
3753
- if (model.name !== void 0) sceneObject.name = model.name;
3754
- if (model.position !== void 0)
3755
- sceneObject.SetPosition(model.position);
3756
- if (model.rotation !== void 0)
3757
- sceneObject.SetRotation(model.rotation);
3758
- if (model.scale !== void 0)
3759
- sceneObject.SetScale(model.scale);
3760
- if (model.visible !== void 0)
3761
- sceneObject.SetVisibility(model.visible);
3762
- if (model.material !== void 0)
3763
- sceneObject.SetMaterial(model.material);
3764
- if (model.parentId !== void 0)
3765
- this.setParent(__spreadProps(__spreadValues({}, model), { parentId: model.parentId }));
3766
- }
3767
- updatePrimitive(primitive) {
3768
- let sceneObject = this.GetSceneObject(primitive);
3769
- if (!sceneObject) {
3770
- const created = new DIVEPrimitive();
3771
- sceneObject = created;
3772
- sceneObject.userData.id = primitive.id;
3773
- this.add(sceneObject);
3774
- }
3775
- if (primitive.name !== void 0) sceneObject.name = primitive.name;
3776
- if (primitive.geometry !== void 0)
3777
- sceneObject.SetGeometry(primitive.geometry);
3778
- if (primitive.position !== void 0)
3779
- sceneObject.SetPosition(primitive.position);
3780
- if (primitive.rotation !== void 0)
3781
- sceneObject.SetRotation(primitive.rotation);
3782
- if (primitive.scale !== void 0)
3783
- sceneObject.SetScale(primitive.scale);
3784
- if (primitive.visible !== void 0)
3785
- sceneObject.SetVisibility(primitive.visible);
3786
- if (primitive.material !== void 0)
3787
- sceneObject.SetMaterial(primitive.material);
3788
- if (primitive.parentId !== void 0)
3789
- this.setParent(__spreadProps(__spreadValues({}, primitive), { parentId: primitive.parentId }));
3790
- }
3791
- updateGroup(group) {
3792
- let sceneObject = this.GetSceneObject(group);
3793
- if (!sceneObject) {
3794
- const created = new DIVEGroup();
3795
- sceneObject = created;
3796
- sceneObject.userData.id = group.id;
3797
- this.add(sceneObject);
3798
- }
3799
- if (group.name !== void 0) sceneObject.name = group.name;
3800
- if (group.position !== void 0)
3801
- sceneObject.SetPosition(group.position);
3802
- if (group.rotation !== void 0)
3803
- sceneObject.SetRotation(group.rotation);
3804
- if (group.scale !== void 0)
3805
- sceneObject.SetScale(group.scale);
3806
- if (group.visible !== void 0)
3807
- sceneObject.SetVisibility(group.visible);
3808
- if (group.bbVisible !== void 0)
3809
- sceneObject.SetLinesVisibility(group.bbVisible);
3810
- if (group.parentId !== void 0)
3811
- this.setParent(__spreadProps(__spreadValues({}, group), { parentId: group.parentId }));
3812
- }
3813
- deleteLight(light) {
3814
- const sceneObject = this.GetSceneObject(light);
3815
- if (!sceneObject) {
3816
- console.warn(
3817
- `DIVERoot.deleteLight: Light with id ${light.id} not found`
3818
- );
3819
- return;
3820
- }
3821
- this.detachTransformControls(sceneObject);
3822
- sceneObject.parent.remove(sceneObject);
3823
- }
3824
- deleteModel(model) {
3825
- const sceneObject = this.GetSceneObject(model);
3826
- if (!sceneObject) {
3827
- console.warn(
3828
- `DIVERoot.deleteModel: Model with id ${model.id} not found`
3829
- );
3830
- return;
3831
- }
3832
- this.detachTransformControls(sceneObject);
3833
- sceneObject.parent.remove(sceneObject);
3834
- }
3835
- deletePrimitive(primitive) {
3836
- const sceneObject = this.GetSceneObject(primitive);
3837
- if (!sceneObject) {
3838
- console.warn(
3839
- `DIVERoot.deletePrimitive: Primitive with id ${primitive.id} not found`
3840
- );
3841
- return;
3842
- }
3843
- this.detachTransformControls(sceneObject);
3844
- sceneObject.parent.remove(sceneObject);
3845
- }
3846
- deleteGroup(group) {
3847
- const sceneObject = this.GetSceneObject(group);
3848
- if (!sceneObject) {
3849
- console.warn(
3850
- `DIVERoot.deleteGroup: Group with id ${group.id} not found`
3851
- );
3852
- return;
3853
- }
3854
- this.detachTransformControls(sceneObject);
3855
- for (let i = sceneObject.members.length - 1; i >= 0; i--) {
3856
- this.attach(sceneObject.members[i]);
3857
- }
3858
- sceneObject.parent.remove(sceneObject);
3859
- }
3860
- placeOnFloor(object) {
3861
- const sceneObject = this.GetSceneObject(object);
3862
- if (!sceneObject) return;
3863
- sceneObject.PlaceOnFloor();
3864
- }
3865
- setParent(object) {
3866
- const sceneObject = this.GetSceneObject(object);
3867
- if (!sceneObject) return;
3868
- if (object.parentId !== null) {
3869
- const parent = this.GetSceneObject({
3870
- id: object.parentId
3871
- });
3872
- if (!parent) return;
3873
- parent.attach(sceneObject);
3874
- } else {
3875
- this.attach(sceneObject);
3876
- }
3877
- }
3878
- detachTransformControls(object) {
3879
- this.findScene(object).children.find((object2) => {
3880
- if ("isTransformControls" in object2) {
3881
- object2.detach();
3882
- }
3883
- });
3884
- }
3885
- findScene(object) {
3886
- if (object.parent !== null) {
3887
- return this.findScene(object.parent);
3888
- }
3889
- return object;
3890
- }
3891
- };
3892
-
3893
- // src/constant/GridColors.ts
3894
- var GRID_CENTER_LINE_COLOR = "#888888";
3895
- var GRID_SIDE_LINE_COLOR = "#dddddd";
3896
-
3897
- // src/grid/Grid.ts
3898
- init_VisibilityLayerMask();
3899
- var import_three19 = require("three");
3900
- var DIVEGrid = class extends import_three19.Object3D {
3901
- constructor() {
3902
- super();
3903
- this.name = "Grid";
3904
- const grid = new import_three19.GridHelper(
3905
- 100,
3906
- 100,
3907
- GRID_CENTER_LINE_COLOR,
3908
- GRID_SIDE_LINE_COLOR
3909
- );
3910
- grid.material.depthTest = false;
3911
- grid.layers.mask = HELPER_LAYER_MASK;
3912
- this.add(grid);
3913
- }
3914
- SetVisibility(visible) {
3915
- this.visible = visible;
3916
- }
3917
- };
3918
-
3919
- // src/primitive/floor/Floor.ts
3920
- var import_three20 = require("three");
3921
- init_VisibilityLayerMask();
3922
- var DIVEFloor = class extends import_three20.Mesh {
3923
- constructor() {
3924
- super(
3925
- new import_three20.PlaneGeometry(1e4, 1e4),
3926
- new import_three20.MeshStandardMaterial({
3927
- color: new import_three20.Color(150 / 255, 150 / 255, 150 / 255)
3928
- })
3929
- );
3930
- this.isFloor = true;
3931
- this.name = "Floor";
3932
- this.layers.mask = PRODUCT_LAYER_MASK;
3933
- this.receiveShadow = true;
3934
- this.rotateX(-Math.PI / 2);
3935
- }
3936
- SetVisibility(visible) {
3937
- this.visible = visible;
3938
- }
3939
- SetColor(color) {
3940
- this.material.color = new import_three20.Color(color);
3941
- }
3942
- };
3943
-
3944
- // src/scene/xrroot/XRRoot.ts
3945
- var import_three22 = require("three");
3946
-
3947
- // src/scene/xrroot/xrlightroot/XRLightRoot.ts
3948
- var import_XREstimatedLight = require("three/examples/jsm/webxr/XREstimatedLight");
3949
- var import_three21 = require("three");
3950
- init_VisibilityLayerMask();
3951
- var DIVEXRLightRoot = class extends import_three21.Object3D {
3952
- constructor(scene) {
3953
- super();
3954
- this.name = "XRLightRoot";
3955
- this._scene = scene;
3956
- this._xrLight = null;
3957
- this._lightRoot = new DIVERoot();
3958
- this._lightRoot.UpdateSceneObject({
3959
- id: "XRSceneLight",
3960
- entityType: "light",
3961
- name: "XRSceneLight",
3962
- type: "scene",
3963
- color: 16777215,
3964
- intensity: 1,
3965
- enabled: true,
3966
- visible: true
3967
- });
3968
- this.add(this._lightRoot);
3969
- }
3970
- InitLightEstimation(renderer) {
3971
- if (!this._xrLight) {
3972
- this._xrLight = new import_XREstimatedLight.XREstimatedLight(renderer, true);
3973
- this._xrLight.layers.mask = PRODUCT_LAYER_MASK;
3974
- this.add(this._xrLight);
3975
- }
3976
- this._xrLight.addEventListener("estimationstart", () => {
3977
- this.onEstimationStart();
3978
- });
3979
- this._xrLight.addEventListener("estimationend", () => {
3980
- this.onEstimationEnd();
3981
- });
3982
- }
3983
- DisposeLightEstimation() {
3984
- if (!this._xrLight) return;
3985
- this._xrLight.removeEventListener("estimationstart", () => {
3986
- this.onEstimationStart();
3987
- });
3988
- this._xrLight.removeEventListener("estimationend", () => {
3989
- this.onEstimationEnd();
3990
- });
3991
- }
3992
- onEstimationStart() {
3993
- this._lightRoot.visible = false;
3994
- if (!this._xrLight) return;
3995
- if (this._xrLight.environment) {
3996
- this._scene.environment = this._xrLight.environment;
3997
- }
3998
- }
3999
- onEstimationEnd() {
4000
- this._lightRoot.visible = true;
4001
- this._scene.environment = null;
4002
- if (!this._xrLight) return;
4003
- }
4004
- };
4005
-
4006
- // src/scene/xrroot/XRRoot.ts
4007
- var DIVEXRRoot = class extends import_three22.Object3D {
4008
- get XRModelRoot() {
4009
- return this._xrModelRoot;
4010
- }
4011
- get XRLightRoot() {
4012
- return this._xrLightRoot;
4013
- }
4014
- get XRHandNode() {
4015
- return this._xrHandNode;
4016
- }
4017
- constructor(scene) {
4018
- super();
4019
- this.name = "XRRoot";
4020
- this._xrModelRoot = new DIVERoot();
4021
- this._xrModelRoot.name = "XRModelRoot";
4022
- this.add(this._xrModelRoot);
4023
- this._xrShadowPlane = new import_three22.Mesh(
4024
- new import_three22.PlaneGeometry(100, 100),
4025
- new import_three22.ShadowMaterial({ opacity: 1, transparent: true })
4026
- );
4027
- this._xrModelRoot.add(this._xrShadowPlane);
4028
- this._xrLightRoot = new DIVEXRLightRoot(scene);
4029
- this._xrLightRoot.name = "XRLightRoot";
4030
- this.add(this._xrLightRoot);
4031
- this._xrHandNode = new import_three22.Object3D();
4032
- this._xrHandNode.name = "XRHandNode";
4033
- this.add(this._xrHandNode);
4034
- }
4035
- InitLightEstimation(renderer) {
4036
- this._xrLightRoot.InitLightEstimation(renderer);
4037
- }
4038
- DisposeLightEstimation() {
4039
- this._xrLightRoot.DisposeLightEstimation();
4040
- }
4041
- };
4042
-
4043
- // src/scene/Scene.ts
4044
- var DIVEScene = class extends import_three23.Scene {
4045
- get Root() {
4046
- return this._root;
4047
- }
4048
- get XRRoot() {
4049
- return this._xrRoot;
4050
- }
4051
- get Floor() {
4052
- return this._floor;
4053
- }
4054
- get Grid() {
4055
- return this._grid;
4056
- }
4057
- constructor() {
4058
- super();
4059
- this.background = new import_three23.Color(16777215);
4060
- this._root = new DIVERoot();
4061
- this.add(this._root);
4062
- this._floor = new DIVEFloor();
4063
- this.add(this._floor);
4064
- this._grid = new DIVEGrid();
4065
- this.add(this._grid);
4066
- this._xrRoot = new DIVEXRRoot(this);
4067
- this._xrRoot.visible = false;
4068
- this.add(this._xrRoot);
4069
- }
4070
- InitXR(renderer) {
4071
- this._root.visible = false;
4072
- this._xrRoot.visible = true;
4073
- this._xrRoot.InitLightEstimation(renderer);
4074
- }
4075
- DisposeXR() {
4076
- this._root.visible = true;
4077
- this._xrRoot.visible = false;
4078
- this._xrRoot.DisposeLightEstimation();
4079
- }
4080
- SetBackground(color) {
4081
- this.background = new import_three23.Color(color);
4082
- }
4083
- ComputeSceneBB() {
4084
- return this.Root.ComputeSceneBB();
4085
- }
4086
- GetSceneObject(object) {
4087
- return this.Root.GetSceneObject(object);
4088
- }
4089
- AddSceneObject(object) {
4090
- this.Root.AddSceneObject(object);
4091
- }
4092
- UpdateSceneObject(object) {
4093
- this.Root.UpdateSceneObject(object);
4094
- }
4095
- DeleteSceneObject(object) {
4096
- this.Root.DeleteSceneObject(object);
4097
- }
4098
- PlaceOnFloor(object) {
4099
- this.Root.PlaceOnFloor(object);
4100
- }
4101
- };
4102
-
4103
- // src/dive.ts
4104
- init_PerspectiveCamera();
4105
-
4106
- // src/controls/OrbitControls.ts
4107
- var import_OrbitControls = require("three/examples/jsm/controls/OrbitControls");
4108
- var import_three24 = require("three");
4109
- var import_tween = require("@tweenjs/tween.js");
4110
- var DIVEOrbitControlsDefaultSettings = {
4111
- enableDamping: true,
4112
- dampingFactor: 0.04
4113
- };
4114
- var _DIVEOrbitControls = class _DIVEOrbitControls extends import_OrbitControls.OrbitControls {
4115
- constructor(camera, renderer, animationSystem, settings = DIVEOrbitControlsDefaultSettings) {
4116
- super(camera, renderer.domElement);
4117
- this.last = null;
4118
- this.animating = false;
4119
- this.locked = false;
4120
- this.stopMoveTo = () => {
4121
- };
4122
- this.stopRevertLast = () => {
4123
- };
4124
- this._removePreRenderCallback = () => {
4125
- };
4126
- this.preRenderCallback = () => {
4127
- if (this.locked) return;
4128
- this.update();
4129
- };
4130
- this._animationSystem = animationSystem;
4131
- this.domElement = renderer.domElement;
4132
- this.object = camera;
4133
- const id = renderer.AddPreRenderCallback(() => {
4134
- this.preRenderCallback();
4135
- });
4136
- this._removePreRenderCallback = () => {
4137
- renderer.RemovePreRenderCallback(id);
4138
- };
4139
- this.enableDamping = settings.enableDamping || DIVEOrbitControlsDefaultSettings.enableDamping;
4140
- this.dampingFactor = settings.dampingFactor || DIVEOrbitControlsDefaultSettings.dampingFactor;
4141
- this.object.position.set(0, 2, 2);
4142
- this.target.copy({ x: 0, y: 0.5, z: 0 });
4143
- this.update();
4144
- }
4145
- Dispose() {
4146
- this._removePreRenderCallback();
4147
- this.dispose();
4148
- }
4149
- ComputeEncompassingView(bb) {
4150
- const center = bb.getCenter(new import_three24.Vector3());
4151
- const size = bb.getSize(new import_three24.Vector3());
4152
- const distance = Math.max(size.x, size.y, size.z) * 1.25;
4153
- const direction = this.object.position.clone().normalize();
4154
- return {
4155
- position: direction.multiplyScalar(distance),
4156
- target: center
4157
- };
4158
- }
4159
- ZoomIn(by) {
4160
- const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
4161
- const { minDistance, maxDistance } = this;
4162
- this.minDistance = this.maxDistance = import_three24.MathUtils.clamp(
4163
- this.getDistance() - zoomBy,
4164
- minDistance + zoomBy,
4165
- maxDistance - zoomBy
4166
- );
4167
- this.update();
4168
- this.minDistance = minDistance;
4169
- this.maxDistance = maxDistance;
4170
- }
4171
- ZoomOut(by) {
4172
- const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
4173
- const { minDistance, maxDistance } = this;
4174
- this.minDistance = this.maxDistance = import_three24.MathUtils.clamp(
4175
- this.getDistance() + zoomBy,
4176
- minDistance + zoomBy,
4177
- maxDistance - zoomBy
4178
- );
4179
- this.update();
4180
- this.minDistance = minDistance;
4181
- this.maxDistance = maxDistance;
4182
- }
4183
- MoveTo(pos, target, duration, lock) {
4184
- if (this.animating) return;
4185
- const toPosition = pos || this.object.position.clone();
4186
- const toTarget = target || this.target.clone();
4187
- this.stopRevertLast();
4188
- if (!this.locked)
4189
- this.last = {
4190
- pos: this.object.position.clone(),
4191
- target: this.target.clone()
4192
- };
4193
- this.animating = duration > 0;
4194
- this.locked = lock;
4195
- this.enabled = false;
4196
- const tweenPos = this._animationSystem.Animate(this.object.position).to(toPosition, duration).easing(import_tween.Easing.Quadratic.Out).start();
4197
- const tweenQuat = this._animationSystem.Animate(this.target).to(toTarget, duration).easing(import_tween.Easing.Quadratic.Out).onUpdate(() => {
4198
- this.object.lookAt(this.target);
4199
- }).onComplete(() => {
4200
- this.animating = false;
4201
- this.enabled = !lock;
4202
- }).start();
4203
- this.stopMoveTo = () => {
4204
- tweenPos.stop();
4205
- tweenQuat.stop();
4206
- };
4207
- }
4208
- RevertLast(duration) {
4209
- if (this.animating || !this.locked) return;
4210
- this.stopMoveTo();
4211
- this.animating = duration > 0;
4212
- this.enabled = false;
4213
- const { pos, target } = this.last;
4214
- const tweenPos = this._animationSystem.Animate(this.object.position).to(pos, duration).easing(import_tween.Easing.Quadratic.Out).start();
4215
- const tweenQuat = this._animationSystem.Animate(this.target).to(target, duration).easing(import_tween.Easing.Quadratic.Out).onUpdate(() => {
4216
- this.object.lookAt(this.target);
4217
- }).onComplete(() => {
4218
- this.animating = false;
4219
- this.locked = false;
4220
- this.enabled = true;
4221
- }).start();
4222
- this.stopRevertLast = () => {
4223
- tweenPos.stop();
4224
- tweenQuat.stop();
4225
- };
4226
- }
4227
- };
4228
- _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR = 1;
4229
- var DIVEOrbitControls = _DIVEOrbitControls;
4230
-
4231
- // src/toolbox/Toolbox.ts
4232
- var DIVEToolbox = class {
4233
- get selectTool() {
4234
- if (!this._selectTool) {
4235
- const DIVESelectTool2 = (init_SelectTool(), __toCommonJS(SelectTool_exports)).DIVESelectTool;
4236
- this._selectTool = new DIVESelectTool2(
4237
- this._scene,
4238
- this._controller
4239
- );
4240
- }
4241
- return this._selectTool;
4242
- }
4243
- constructor(scene, controller) {
4244
- this._scene = scene;
4245
- this._controller = controller;
4246
- this._selectTool = null;
4247
- this._activeTool = null;
4248
- }
4249
- Dispose() {
4250
- this.removeEventListeners();
4251
- }
4252
- GetActiveTool() {
4253
- return this._activeTool;
4254
- }
4255
- UseTool(tool) {
4256
- var _a;
4257
- (_a = this._activeTool) == null ? void 0 : _a.Deactivate();
4258
- switch (tool) {
4259
- case "select": {
4260
- this.addEventListeners();
4261
- this.selectTool.Activate();
4262
- this._activeTool = this.selectTool;
4263
- break;
4264
- }
4265
- case "none": {
4266
- this.removeEventListeners();
4267
- this._activeTool = null;
4268
- break;
4269
- }
4270
- default: {
4271
- console.warn(`DIVEToolBox.UseTool: Unknown tool: ${tool}`);
4272
- }
4273
- }
4274
- }
4275
- SetGizmoMode(mode) {
4276
- this.selectTool.SetGizmoMode(mode);
4277
- }
4278
- SetGizmoVisibility(active) {
4279
- this.selectTool.SetGizmoVisibility(active);
4280
- }
4281
- SetGizmoScaleLinked(linked) {
4282
- this.selectTool.SetGizmoScaleLinked(linked);
4283
- }
4284
- onPointerMove(e) {
4285
- var _a;
4286
- (_a = this._activeTool) == null ? void 0 : _a.onPointerMove(e);
4287
- }
4288
- onPointerDown(e) {
4289
- var _a;
4290
- (_a = this._activeTool) == null ? void 0 : _a.onPointerDown(e);
4291
- }
4292
- onPointerUp(e) {
4293
- var _a;
4294
- (_a = this._activeTool) == null ? void 0 : _a.onPointerUp(e);
4295
- }
4296
- onWheel(e) {
4297
- var _a;
4298
- (_a = this._activeTool) == null ? void 0 : _a.onWheel(e);
4299
- }
4300
- addEventListeners() {
4301
- this._controller.domElement.addEventListener(
4302
- "pointermove",
4303
- (e) => this.onPointerMove(e)
4304
- );
4305
- this._controller.domElement.addEventListener(
4306
- "pointerdown",
4307
- (e) => this.onPointerDown(e)
4308
- );
4309
- this._controller.domElement.addEventListener(
4310
- "pointerup",
4311
- (e) => this.onPointerUp(e)
4312
- );
4313
- this._controller.domElement.addEventListener(
4314
- "wheel",
4315
- (e) => this.onWheel(e)
4316
- );
4317
- }
4318
- removeEventListeners() {
4319
- this._controller.domElement.removeEventListener(
4320
- "pointermove",
4321
- (e) => this.onPointerMove(e)
4322
- );
4323
- this._controller.domElement.removeEventListener(
4324
- "pointerdown",
4325
- (e) => this.onPointerDown(e)
4326
- );
4327
- this._controller.domElement.removeEventListener(
4328
- "pointerup",
4329
- (e) => this.onPointerUp(e)
4330
- );
4331
- this._controller.domElement.removeEventListener(
4332
- "wheel",
4333
- (e) => this.onWheel(e)
4334
- );
4335
- }
4336
- };
4337
- DIVEToolbox.DefaultTool = "select";
4338
-
4339
- // src/animation/AnimationSystem.ts
4340
- var import_tween2 = require("@tweenjs/tween.js");
4341
- var DIVEAnimationSystem = class {
4342
- constructor(renderer) {
4343
- this._renderer = renderer;
4344
- this._rendererCallbackId = this._renderer.AddPreRenderCallback(() => {
4345
- this.Update();
4346
- });
4347
- }
4348
- Dispose() {
4349
- this._renderer.RemovePreRenderCallback(this._rendererCallbackId);
4350
- }
4351
- Update() {
4352
- (0, import_tween2.update)();
4353
- }
4354
- Animate(object) {
4355
- return new import_tween2.Tween(object);
4356
- }
4357
- };
4358
-
4359
- // src/axiscamera/AxisCamera.ts
4360
- var import_three25 = require("three");
4361
- var import_three_spritetext = __toESM(require("three-spritetext"), 1);
4362
- init_VisibilityLayerMask();
4363
- init_AxisHelperColors();
4364
- var DIVEAxisCamera = class extends import_three25.OrthographicCamera {
4365
- constructor(renderer, scene, controls) {
4366
- super(-1, 1, 1, -1, 0.1, 100);
4367
- this.layers.mask = COORDINATE_LAYER_MASK;
4368
- this.axesHelper = new import_three25.AxesHelper(0.5);
4369
- this.axesHelper.layers.mask = COORDINATE_LAYER_MASK;
4370
- this.axesHelper.material.depthTest = false;
4371
- this.axesHelper.position.set(0, 0, -1);
4372
- this.axesHelper.setColors(
4373
- new import_three25.Color(AxesColorRed),
4374
- new import_three25.Color(AxesColorGreen),
4375
- new import_three25.Color(AxesColorBlue)
4376
- );
4377
- const x = new import_three_spritetext.default("X", 0.2, AxesColorRedLetter);
4378
- const y = new import_three_spritetext.default("Y", 0.2, AxesColorGreenLetter);
4379
- const z = new import_three_spritetext.default("Z", 0.2, AxesColorBlueLetter);
4380
- x.layers.mask = COORDINATE_LAYER_MASK;
4381
- y.layers.mask = COORDINATE_LAYER_MASK;
4382
- z.layers.mask = COORDINATE_LAYER_MASK;
4383
- x.position.set(0.7, 0, 0);
4384
- y.position.set(0, 0.7, 0);
4385
- z.position.set(0, 0, 0.7);
4386
- this.axesHelper.add(x);
4387
- this.axesHelper.add(y);
4388
- this.axesHelper.add(z);
4389
- this.add(this.axesHelper);
4390
- this._renderer = renderer;
4391
- this._scene = scene;
4392
- this._scene.add(this);
4393
- const restoreViewport = new import_three25.Vector4();
4394
- this._renderCallbackId = renderer.AddPostRenderCallback(() => {
4395
- const restoreBackground = scene.background;
4396
- scene.background = null;
4397
- renderer.getViewport(restoreViewport);
4398
- renderer.setViewport(0, 0, 150, 150);
4399
- renderer.autoClear = false;
4400
- this.SetFromCameraMatrix(controls.object.matrix);
4401
- renderer.render(scene, this);
4402
- renderer.setViewport(restoreViewport);
4403
- renderer.autoClear = true;
4404
- scene.background = restoreBackground;
4405
- });
4406
- }
4407
- Dispose() {
4408
- this._renderer.RemovePostRenderCallback(this._renderCallbackId);
4409
- this._scene.remove(this);
4410
- }
4411
- SetFromCameraMatrix(matrix) {
4412
- this.axesHelper.rotation.setFromRotationMatrix(
4413
- new import_three25.Matrix4().extractRotation(matrix).invert()
4414
- );
4415
- }
4416
- };
4417
-
4418
- // src/helper/getObjectDelta/getObjectDelta.ts
4419
- var getObjectDelta = (a, b) => {
4420
- if (Object.keys(a).length === 0 && Object.keys(b).length === 0) {
4421
- return {};
4422
- }
4423
- if (typeof a !== "object" || typeof b !== "object") {
4424
- return b;
4425
- }
4426
- let delta = {};
4427
- Object.keys(b).forEach((key) => {
4428
- if (!Object.keys(a).includes(key)) {
4429
- delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
4430
- return;
4431
- }
4432
- if (Array.isArray(b[key])) {
4433
- if (!Array.isArray(a[key])) {
4434
- delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
4435
- return;
4436
- }
4437
- const aArray = a[key];
4438
- const bArray = b[key];
4439
- if (aArray.length === 0 && bArray.length === 0) {
4440
- delta = __spreadValues({}, delta);
4441
- return;
4442
- }
4443
- if (aArray.length !== bArray.length) {
4444
- delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
4445
- return;
4446
- }
4447
- const arrayDeltas = [];
4448
- bArray.forEach((entry, index) => {
4449
- const inArrayDelta = getObjectDelta(
4450
- aArray[index],
4451
- bArray[index]
4452
- );
4453
- if (Object.keys(inArrayDelta).length) {
4454
- arrayDeltas.push(bArray[index]);
4455
- }
4456
- });
4457
- if (Object.keys(arrayDeltas).length) {
4458
- delta = __spreadProps(__spreadValues({}, delta), { [key]: arrayDeltas });
4459
- return;
4460
- }
4461
- return;
4462
- }
4463
- if (typeof b[key] === "object") {
4464
- if (typeof a[key] !== "object") {
4465
- delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
4466
- return;
4467
- }
4468
- const objectDelta = getObjectDelta(
4469
- a[key],
4470
- b[key]
4471
- );
4472
- if (Object.keys(objectDelta).length) {
4473
- delta = __spreadProps(__spreadValues({}, delta), { [key]: objectDelta });
4474
- return;
4475
- }
4476
- }
4477
- if (a[key] !== b[key]) {
4478
- delta = __spreadProps(__spreadValues({}, delta), { [key]: b[key] });
4479
- }
4480
- });
4481
- return delta;
4482
- };
4483
-
4484
- // src/dive.ts
4485
- var import_three28 = require("three");
4486
- init_Info();
4487
-
4488
- // package.json
4489
- var package_default = {
4490
- name: "@shopware-ag/dive",
4491
- version: "1.18.4",
4492
- description: "Shopware Spatial Framework",
4493
- type: "module",
4494
- main: "./build/dive.cjs",
4495
- module: "./build/dive.js",
4496
- types: "./build/dive.d.ts",
4497
- files: [
4498
- "build",
4499
- "LICENSE",
4500
- "package.json",
4501
- "README.md",
4502
- "src"
4503
- ],
4504
- keywords: [
4505
- "dive",
4506
- "shopware",
4507
- "sw6",
4508
- "three",
4509
- "three.js",
4510
- "3d",
4511
- "typescript"
4512
- ],
4513
- repository: "git@github.com:shopware/dive.git",
4514
- author: "ffrank <f.frank@shopware.com>",
4515
- license: "MIT",
4516
- browserslist: [
4517
- "> 1%, not dead, not ie 11, not op_mini all"
4518
- ],
4519
- dependencies: {
4520
- "@tweenjs/tween.js": "^23.1.1",
4521
- lodash: "^4.17.21",
4522
- three: "^0.163.0",
4523
- "three-spritetext": "^1.8.2"
4524
- },
4525
- devDependencies: {
4526
- "@eslint/js": "^9.1.1",
4527
- "@types/jest": "^29.5.12",
4528
- "@types/lodash": "^4.17.12",
4529
- "@types/node": "^20.12.7",
4530
- "@types/three": "^0.163.0",
4531
- eslint: "^9.1.1",
4532
- globals: "^15.0.0",
4533
- jest: "^29.7.0",
4534
- "jest-environment-jsdom": "^29.7.0",
4535
- "jest-junit": "^16.0.0",
4536
- jsdom: "^24.0.0",
4537
- prettier: "^3.3.3",
4538
- "prettier-plugin-multiline-arrays": "^3.0.6",
4539
- "ts-jest": "^29.1.2",
4540
- "ts-node": "^10.9.2",
4541
- tsc: "^2.0.4",
4542
- tsup: "^8.0.2",
4543
- typescript: "^5.4.5",
4544
- "typescript-eslint": "^7.7.1"
4545
- },
4546
- scripts: {
4547
- build: "tsup --env.DIVE_NODE_ENV production",
4548
- dev: "tsup --watch --env.DIVE_NODE_ENV development",
4549
- lint: "eslint",
4550
- "lint:actions": "yarn lint:actions:transpile && yarn lint:actions:check && yarn lint:actions:cleanup",
4551
- "lint:actions:transpile": "yarn tsc --resolveJsonModule --esModuleInterop ci/lint/lint-actions.ts && mv ci/lint/lint-actions.js ci/lint/lint-actions.cjs",
4552
- "lint:actions:check": "yarn node ci/lint/lint-actions.cjs",
4553
- "lint:actions:cleanup": `node -e "require('fs').unlinkSync('ci/lint/lint-actions.cjs')"`,
4554
- "prettier:check": "prettier --check .",
4555
- "prettier:fix": "prettier --write .",
4556
- unit: "jest",
4557
- coverage: "jest --coverage",
4558
- "generate-readme": "yarn generate-readme:transpile && yarn generate-readme:write && yarn generate-readme:cleanup",
4559
- "generate-readme:transpile": "yarn tsc --resolveJsonModule --esModuleInterop ci/readme/generate-readme.ts && mv ci/readme/generate-readme.js ci/readme/generate-readme.cjs",
4560
- "generate-readme:write": "node ci/readme/generate-readme.cjs",
4561
- "generate-readme:cleanup": `node -e "require('fs').unlinkSync('ci/readme/generate-readme.cjs')"`,
4562
- ci: "yarn lint && yarn coverage && yarn prettier:check && yarn build && bash ci/lint/lint-actions.sh"
4563
- }
4564
- };
4565
-
4566
- // src/math/helper/shift.ts
4567
- function shift(value, exponent) {
4568
- const subvalues = (value + "e").split("e");
4569
- return +(subvalues[0] + "e" + (+subvalues[1] + (exponent || 0)));
4570
- }
4571
-
4572
- // src/math/ceil/ceilExp.ts
4573
- function ceilExp(number, decimals = 0) {
4574
- const n = shift(number, +decimals);
4575
- return shift(Math.ceil(n), -decimals);
4576
- }
4577
-
4578
- // src/math/floor/floorExp.ts
4579
- function floorExp(number, decimals = 0) {
4580
- const n = shift(number, +decimals);
4581
- return shift(Math.floor(n), -decimals);
4582
- }
4583
-
4584
- // src/math/round/roundExp.ts
4585
- function roundExponential(number, decimals = 0) {
4586
- if (number < 0) return -roundExponential(-number, decimals);
4587
- const n = shift(number, +decimals);
4588
- return shift(Math.round(n), -decimals);
4589
- }
4590
-
4591
- // src/math/signedAngleTo/signedAngleTo.ts
4592
- function signedAngleTo(vecA, vecB, planeNormal) {
4593
- return Math.atan2(
4594
- vecA.clone().cross(vecB).dot(planeNormal),
4595
- vecB.clone().dot(vecA)
4596
- );
4597
- }
4598
-
4599
- // src/math/toFixed/toFixedExp.ts
4600
- function toFixedExp(number, decimals = 0) {
4601
- const n = shift(number, +decimals);
4602
- return shift(Math.round(n), -decimals).toFixed(decimals);
4603
- }
4604
-
4605
- // src/math/truncate/truncateExp.ts
4606
- function truncateExp(number, decimals = 0) {
4607
- const n = shift(number, +decimals);
4608
- return shift(Math.trunc(n), -decimals);
4609
- }
4610
-
4611
- // src/math/radToDeg/radToDeg.ts
4612
- var import_three26 = require("three");
4613
- function radToDeg(radians) {
4614
- return (import_three26.MathUtils.radToDeg(radians) + 360) % 360;
4615
- }
4616
-
4617
- // src/math/degToRad/degToRad.ts
4618
- var import_three27 = require("three");
4619
- function degToRad(degrees) {
4620
- return import_three27.MathUtils.degToRad(degrees);
4621
- }
4622
-
4623
- // src/math/index.ts
4624
- var DIVEMath = {
4625
- ceilExp,
4626
- floorExp,
4627
- roundExp: roundExponential,
4628
- toFixedExp,
4629
- truncateExp,
4630
- signedAngleTo,
4631
- radToDeg,
4632
- degToRad
4633
- };
4634
-
4635
- // src/dive.ts
4636
- var DIVEDefaultSettings = {
4637
- autoResize: true,
4638
- displayAxes: false,
4639
- renderer: DIVERendererDefaultSettings,
4640
- perspectiveCamera: DIVEPerspectiveCameraDefaultSettings,
4641
- orbitControls: DIVEOrbitControlsDefaultSettings
4642
- };
4643
- var DIVE = class _DIVE {
4644
- // static members
4645
- static QuickView(uri, settings) {
4646
- const dive = new _DIVE(settings);
4647
- dive.Communication.PerformAction("SET_CAMERA_TRANSFORM", {
4648
- position: { x: 0, y: 2, z: 2 },
4649
- target: { x: 0, y: 0.5, z: 0 }
4650
- });
4651
- const lightid = import_three28.MathUtils.generateUUID();
4652
- dive.Communication.PerformAction("ADD_OBJECT", {
4653
- entityType: "light",
4654
- type: "scene",
4655
- name: "light",
4656
- id: lightid,
4657
- enabled: true,
4658
- visible: true,
4659
- intensity: 1,
4660
- color: 16777215
4661
- });
4662
- const modelid = import_three28.MathUtils.generateUUID();
4663
- dive.Communication.Subscribe("MODEL_LOADED", (data) => {
4664
- if (data.id !== modelid) return;
4665
- const transform = dive.Communication.PerformAction(
4666
- "COMPUTE_ENCOMPASSING_VIEW",
4667
- {}
4668
- );
4669
- dive.Communication.PerformAction("SET_CAMERA_TRANSFORM", {
4670
- position: transform.position,
4671
- target: transform.target
4672
- });
4673
- });
4674
- dive.Communication.PerformAction("ADD_OBJECT", {
4675
- entityType: "model",
4676
- name: "object",
4677
- id: modelid,
4678
- position: { x: 0, y: 0, z: 0 },
4679
- rotation: { x: 0, y: 0, z: 0 },
4680
- scale: { x: 1, y: 1, z: 1 },
4681
- uri,
4682
- visible: true,
4683
- loaded: false
4684
- });
4685
- dive.Communication.PerformAction("UPDATE_SCENE", {
4686
- backgroundColor: 16777215,
4687
- gridEnabled: false,
4688
- floorColor: 16777215
4689
- });
4690
- return dive;
4691
- }
4692
- // getters
4693
- get Communication() {
4694
- return this.communication;
4695
- }
4696
- get Canvas() {
4697
- return this.renderer.domElement;
4698
- }
4699
- get Info() {
4700
- return DIVEInfo;
4701
- }
4702
- // setters
4703
- set Settings(settings) {
4704
- var _a;
4705
- const settingsDelta = getObjectDelta(this._settings, settings);
4706
- if (settingsDelta.renderer)
4707
- this.renderer = new DIVERenderer(this._settings.renderer);
4708
- if (settingsDelta.perspectiveCamera) {
4709
- if (settingsDelta.perspectiveCamera.fov !== void 0)
4710
- this.perspectiveCamera.fov = settingsDelta.perspectiveCamera.fov;
4711
- if (settingsDelta.perspectiveCamera.near !== void 0)
4712
- this.perspectiveCamera.near = settingsDelta.perspectiveCamera.near;
4713
- if (settingsDelta.perspectiveCamera.far !== void 0)
4714
- this.perspectiveCamera.far = settingsDelta.perspectiveCamera.far;
4715
- this.perspectiveCamera.OnResize(
4716
- this.renderer.domElement.width,
4717
- this.renderer.domElement.height
4718
- );
4719
- }
4720
- if (settingsDelta.orbitControls) {
4721
- if (settingsDelta.orbitControls.enableDamping !== void 0)
4722
- this.orbitControls.enableDamping = settingsDelta.orbitControls.enableDamping;
4723
- if (settingsDelta.orbitControls.dampingFactor !== void 0)
4724
- this.orbitControls.dampingFactor = settingsDelta.orbitControls.dampingFactor;
4725
- }
4726
- if (settingsDelta.autoResize !== this._settings.autoResize) {
4727
- if (settingsDelta.autoResize) {
4728
- this.addResizeObserver();
4729
- } else {
4730
- this.removeResizeObserver();
4731
- }
4732
- }
4733
- if (settingsDelta.displayAxes) {
4734
- this.axisCamera = new DIVEAxisCamera(
4735
- this.renderer,
4736
- this.scene,
4737
- this.orbitControls
4738
- );
4739
- } else {
4740
- (_a = this.axisCamera) == null ? void 0 : _a.Dispose();
4741
- this.axisCamera = null;
4742
- }
4743
- Object.assign(this._settings, settings);
4744
- }
4745
- constructor(settings) {
4746
- this._settings = __spreadValues(__spreadValues({}, DIVEDefaultSettings), settings !== void 0 ? settings : {});
4747
- this._resizeObserverId = "";
4748
- this._width = 0;
4749
- this._height = 0;
4750
- this.renderer = new DIVERenderer(this._settings.renderer);
4751
- this.scene = new DIVEScene();
4752
- this.perspectiveCamera = new DIVEPerspectiveCamera(
4753
- this._settings.perspectiveCamera
4754
- );
4755
- this.animationSystem = new DIVEAnimationSystem(this.renderer);
4756
- this.orbitControls = new DIVEOrbitControls(
4757
- this.perspectiveCamera,
4758
- this.renderer,
4759
- this.animationSystem,
4760
- this._settings.orbitControls
4761
- );
4762
- this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
4763
- this.communication = new DIVECommunication(
4764
- this.renderer,
4765
- this.scene,
4766
- this.orbitControls,
4767
- this.toolbox
4768
- );
4769
- if (this._settings.displayAxes) {
4770
- this.axisCamera = new DIVEAxisCamera(
4771
- this.renderer,
4772
- this.scene,
4773
- this.orbitControls
4774
- );
4775
- } else {
4776
- this.axisCamera = null;
4777
- }
4778
- if (this._settings.autoResize) {
4779
- this.addResizeObserver();
4780
- }
4781
- this.renderer.StartRenderer(this.scene, this.perspectiveCamera);
4782
- window.DIVE = {
4783
- PrintScene: () => {
4784
- console.log(this.scene);
4785
- }
4786
- };
4787
- console.log(`DIVE ${package_default.version} initialized successfully!`);
4788
- if (false) {
4789
- console.log("DIVE is running in development mode.");
4790
- }
4791
- console.log(`
4792
- @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@
4793
- @@@@+-:::::::---------------------==------------------------------=#@@@@
4794
- @@%=::::.......::---------------------------------------------------------+@@
4795
- @@+:::...........::-----------------------------------------------------------#@@
4796
- @@=:::.........::::::-------------------------------------------------------------%@
4797
- @%:::.......:::::::-----------------------------------------------------------------#@
4798
- @*:::.....:::::-----------------------------------------------------------------------*@
4799
- @%::::::.::::---------------------------------------------------------------------------@@
4800
- @@-:::::::::-----------------------------------------------------------------------------=@
4801
- @%::::::::--------------------------------------------------------------------------------%@
4802
- @+::::::::--------------------------------=@@@@@%-----------------------------------------%@
4803
- @=:::::::--------------------------------*@@ @@+---------------------------------------#@
4804
- @+:::::::-------------------------------*@ @*--------------------------------------%@
4805
- @#::::::::-----------------------------=@@ @@=-------------------------------------%@
4806
- @@-::::::::----------------------------@@ @@------------------------------------=@
4807
- @%:::::::::--------------------------*@ @*-----------------------------------@@
4808
- @*:::::::::-------------------------@@ @@----------------------------------%@
4809
- @#::::::::::----------------------%@ @%--------------------------------%@
4810
- @#:::::::::::-------------------=@@ @@=------------------------------%@
4811
- @@-::::::::::::----------------%@ @%----------------------------=@@
4812
- @@#::::::::::::::------------*@ @*--------------------------#@@
4813
- @@+::::::::::::::::--------@@ @@------------------------+@@
4814
- @@*:::::::::::::::::----@@ @@---------------------+@@
4815
- @@@-:::::::::::::::--#@ @#-----------------=%@@
4816
- @@%-::::::::::::-%@ @%-------------=%@@
4817
- @@@@+:::::::#@@ @@*-------*@@@@
4818
- @@@@@@@ @@@@@@
4819
-
4820
- `);
4821
- }
4822
- Dispose() {
4823
- var _a;
4824
- this.removeResizeObserver();
4825
- this.renderer.Dispose();
4826
- this.orbitControls.Dispose();
4827
- (_a = this.axisCamera) == null ? void 0 : _a.Dispose();
4828
- this.animationSystem.Dispose();
4829
- this.toolbox.Dispose();
4830
- this.communication.DestroyInstance();
4831
- }
4832
- // methods
4833
- OnResize(width, height) {
4834
- this.renderer.OnResize(width, height);
4835
- this.perspectiveCamera.OnResize(width, height);
4836
- }
4837
- addResizeObserver() {
4838
- this._resizeObserverId = this.renderer.AddPreRenderCallback(() => {
4839
- const canvasWrapper = this.renderer.domElement.parentElement;
4840
- if (!canvasWrapper) return;
4841
- const { clientWidth, clientHeight } = canvasWrapper;
4842
- if (clientWidth === this._width && clientHeight === this._height)
4843
- return;
4844
- this.OnResize(clientWidth, clientHeight);
4845
- this._width = clientWidth;
4846
- this._height = clientHeight;
4847
- });
4848
- }
4849
- removeResizeObserver() {
4850
- this.renderer.RemovePreRenderCallback(this._resizeObserverId);
4851
- }
4852
- };
4853
- // Annotate the CommonJS export names for ESM import in node:
4854
- 0 && (module.exports = {
4855
- DIVE,
4856
- DIVECommunication,
4857
- DIVEDefaultSettings,
4858
- DIVEMath
4859
- });
4860
- //# sourceMappingURL=dive.cjs.map
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./dive-C-5_QywE.cjs");exports.DIVE=e.DIVE;exports.DIVECommunication=e.DIVECommunication;exports.DIVEDefaultSettings=e.DIVEDefaultSettings;exports.DIVEMath=e.DIVEMath;exports.default=e.DIVE;
2
+ //# sourceMappingURL=dive.cjs.map