@shopware-ag/dive 1.4.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +38 -24
  2. package/build/dive.cjs +734 -492
  3. package/build/dive.cjs.map +1 -1
  4. package/build/dive.d.cts +182 -113
  5. package/build/dive.d.ts +182 -113
  6. package/build/dive.js +733 -478
  7. package/build/dive.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/__test__/DIVE.test.ts +66 -22
  10. package/src/animation/AnimationSystem.ts +16 -0
  11. package/src/animation/__test__/AnimationSystem.test.ts +23 -2
  12. package/src/axiscamera/AxisCamera.ts +40 -2
  13. package/src/axiscamera/__test__/AxisCamera.test.ts +178 -5
  14. package/src/com/Communication.ts +59 -16
  15. package/src/com/__test__/Communication.test.ts +83 -24
  16. package/src/com/actions/camera/computeencompassingview.ts +9 -0
  17. package/src/com/actions/index.ts +4 -0
  18. package/src/com/actions/scene/updatescene.ts +1 -0
  19. package/src/com/actions/toolbox/transform/setgizmovisible.ts +4 -0
  20. package/src/controls/OrbitControls.ts +14 -2
  21. package/src/controls/__test__/OrbitControls.test.ts +31 -4
  22. package/src/dive.ts +93 -33
  23. package/src/grid/Grid.ts +4 -0
  24. package/src/grid/__test__/Grid.test.ts +7 -0
  25. package/src/interface/Selectable.ts +17 -0
  26. package/src/interface/__test__/Interfaces.test.ts +18 -0
  27. package/src/mediacreator/MediaCreator.ts +2 -2
  28. package/src/mediacreator/__test__/MediaCreator.test.ts +12 -10
  29. package/src/model/Model.ts +6 -0
  30. package/src/model/__test__/Model.test.ts +9 -0
  31. package/src/renderer/Renderer.ts +7 -1
  32. package/src/renderer/__test__/Renderer.test.ts +14 -5
  33. package/src/scene/Scene.ts +8 -2
  34. package/src/scene/__test__/Scene.test.ts +6 -0
  35. package/src/scene/root/Root.ts +11 -1
  36. package/src/scene/root/__test__/Root.test.ts +68 -2
  37. package/src/scene/root/modelroot/ModelRoot.ts +1 -1
  38. package/src/scene/root/modelroot/__test__/ModelRoot.test.ts +1 -0
  39. package/src/toolbox/BaseTool.ts +3 -3
  40. package/src/toolbox/Toolbox.ts +57 -37
  41. package/src/toolbox/__test__/BaseTool.test.ts +49 -7
  42. package/src/toolbox/__test__/Toolbox.test.ts +43 -40
  43. package/src/toolbox/select/SelectTool.ts +18 -28
  44. package/src/toolbox/select/__test__/SelectTool.test.ts +27 -8
  45. package/src/toolbox/transform/TransformTool.ts +16 -1
  46. package/src/toolbox/transform/__test__/TransformTool.test.ts +34 -5
package/build/dive.cjs CHANGED
@@ -22,6 +22,9 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
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
+ };
25
28
  var __export = (target, all) => {
26
29
  for (var name in all)
27
30
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -64,6 +67,466 @@ var __async = (__this, __arguments, generator) => {
64
67
  });
65
68
  };
66
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/interface/Draggable.ts
84
+ var isDraggable, findDraggableInterface;
85
+ var init_Draggable = __esm({
86
+ "src/interface/Draggable.ts"() {
87
+ "use strict";
88
+ isDraggable = (object) => {
89
+ return "isDraggable" in object;
90
+ };
91
+ findDraggableInterface = (child) => {
92
+ if (child === void 0) return void 0;
93
+ if (child.parent === null) {
94
+ return void 0;
95
+ }
96
+ if (isDraggable(child)) {
97
+ return child;
98
+ }
99
+ return findDraggableInterface(child.parent);
100
+ };
101
+ }
102
+ });
103
+
104
+ // src/interface/Hoverable.ts
105
+ var isHoverable, findHoverableInterface;
106
+ var init_Hoverable = __esm({
107
+ "src/interface/Hoverable.ts"() {
108
+ "use strict";
109
+ isHoverable = (object) => {
110
+ return "isHoverable" in object;
111
+ };
112
+ findHoverableInterface = (child) => {
113
+ if (child === void 0) return void 0;
114
+ if (child.parent === null) {
115
+ return void 0;
116
+ }
117
+ if (isHoverable(child)) {
118
+ return child;
119
+ }
120
+ return findHoverableInterface(child.parent);
121
+ };
122
+ }
123
+ });
124
+
125
+ // src/toolbox/BaseTool.ts
126
+ var import_three3, DIVEBaseTool;
127
+ var init_BaseTool = __esm({
128
+ "src/toolbox/BaseTool.ts"() {
129
+ "use strict";
130
+ import_three3 = require("three");
131
+ init_VisibilityLayerMask();
132
+ init_Draggable();
133
+ init_Hoverable();
134
+ DIVEBaseTool = class {
135
+ constructor(scene, controller) {
136
+ this.POINTER_DRAG_THRESHOLD = 1e-3;
137
+ this.name = "BaseTool";
138
+ this._canvas = controller.domElement;
139
+ this._scene = scene;
140
+ this._controller = controller;
141
+ this._pointer = new import_three3.Vector2();
142
+ this._pointerPrimaryDown = false;
143
+ this._pointerMiddleDown = false;
144
+ this._pointerSecondaryDown = false;
145
+ this._lastPointerDown = new import_three3.Vector2();
146
+ this._lastPointerUp = new import_three3.Vector2();
147
+ this._raycaster = new import_three3.Raycaster();
148
+ this._raycaster.layers.mask = PRODUCT_LAYER_MASK | UI_LAYER_MASK;
149
+ this._intersects = [];
150
+ this._hovered = null;
151
+ this._dragging = false;
152
+ this._dragStart = new import_three3.Vector3();
153
+ this._dragCurrent = new import_three3.Vector3();
154
+ this._dragEnd = new import_three3.Vector3();
155
+ this._dragDelta = new import_three3.Vector3();
156
+ this._draggable = null;
157
+ this._dragRaycastOnObjects = null;
158
+ }
159
+ get _pointerAnyDown() {
160
+ return this._pointerPrimaryDown || this._pointerMiddleDown || this._pointerSecondaryDown;
161
+ }
162
+ Activate() {
163
+ }
164
+ Deactivate() {
165
+ }
166
+ onPointerDown(e) {
167
+ var _a;
168
+ switch (e.button) {
169
+ case 0:
170
+ this._pointerPrimaryDown = true;
171
+ break;
172
+ case 1:
173
+ this._pointerMiddleDown = true;
174
+ break;
175
+ case 2:
176
+ this._pointerSecondaryDown = true;
177
+ break;
178
+ }
179
+ this._lastPointerDown.copy(this._pointer);
180
+ this._draggable = findDraggableInterface((_a = this._intersects[0]) == null ? void 0 : _a.object) || null;
181
+ }
182
+ onDragStart(e) {
183
+ if (!this._draggable) return;
184
+ if (this._dragRaycastOnObjects !== null) {
185
+ this._intersects = this._raycaster.intersectObjects(this._dragRaycastOnObjects, true);
186
+ }
187
+ if (this._intersects.length === 0) return;
188
+ this._dragStart.copy(this._intersects[0].point.clone());
189
+ this._dragCurrent.copy(this._intersects[0].point.clone());
190
+ this._dragEnd.copy(this._dragStart.clone());
191
+ this._dragDelta.set(0, 0, 0);
192
+ if (this._draggable && this._draggable.onDragStart) {
193
+ this._draggable.onDragStart({
194
+ dragStart: this._dragStart,
195
+ dragCurrent: this._dragCurrent,
196
+ dragEnd: this._dragEnd,
197
+ dragDelta: this._dragDelta
198
+ });
199
+ this._dragging = true;
200
+ this._controller.enabled = false;
201
+ }
202
+ }
203
+ onPointerMove(e) {
204
+ var _a;
205
+ this._pointer.x = e.offsetX / this._canvas.clientWidth * 2 - 1;
206
+ this._pointer.y = -(e.offsetY / this._canvas.clientHeight) * 2 + 1;
207
+ this._raycaster.setFromCamera(this._pointer, this._controller.object);
208
+ this._intersects = this.raycast(this._scene.children);
209
+ const hoverable = findHoverableInterface((_a = this._intersects[0]) == null ? void 0 : _a.object);
210
+ if (this._intersects[0] && hoverable) {
211
+ if (!this._hovered) {
212
+ if (hoverable.onPointerEnter) hoverable.onPointerEnter(this._intersects[0]);
213
+ this._hovered = hoverable;
214
+ return;
215
+ }
216
+ if (this._hovered.uuid !== hoverable.uuid) {
217
+ if (this._hovered.onPointerLeave) this._hovered.onPointerLeave();
218
+ if (hoverable.onPointerEnter) hoverable.onPointerEnter(this._intersects[0]);
219
+ this._hovered = hoverable;
220
+ return;
221
+ }
222
+ if (hoverable.onPointerOver) hoverable.onPointerOver(this._intersects[0]);
223
+ this._hovered = hoverable;
224
+ } else {
225
+ if (this._hovered) {
226
+ if (this._hovered.onPointerLeave) this._hovered.onPointerLeave();
227
+ }
228
+ this._hovered = null;
229
+ }
230
+ if (this._pointerAnyDown) {
231
+ if (!this._dragging) {
232
+ this.onDragStart(e);
233
+ }
234
+ this.onDrag(e);
235
+ }
236
+ }
237
+ onDrag(e) {
238
+ if (this._dragRaycastOnObjects !== null) {
239
+ this._intersects = this._raycaster.intersectObjects(this._dragRaycastOnObjects, true);
240
+ }
241
+ const intersect = this._intersects[0];
242
+ if (!intersect) return;
243
+ this._dragCurrent.copy(intersect.point.clone());
244
+ this._dragEnd.copy(intersect.point.clone());
245
+ this._dragDelta.subVectors(this._dragCurrent.clone(), this._dragStart.clone());
246
+ if (this._draggable && this._draggable.onDrag) {
247
+ this._draggable.onDrag({
248
+ dragStart: this._dragStart,
249
+ dragCurrent: this._dragCurrent,
250
+ dragEnd: this._dragEnd,
251
+ dragDelta: this._dragDelta
252
+ });
253
+ }
254
+ }
255
+ onPointerUp(e) {
256
+ if (this.pointerWasDragged() || this._dragging) {
257
+ if (this._draggable) {
258
+ this.onDragEnd(e);
259
+ }
260
+ } else {
261
+ this.onClick(e);
262
+ }
263
+ switch (e.button) {
264
+ case 0:
265
+ this._pointerPrimaryDown = false;
266
+ break;
267
+ case 1:
268
+ this._pointerMiddleDown = false;
269
+ break;
270
+ case 2:
271
+ this._pointerSecondaryDown = false;
272
+ break;
273
+ }
274
+ this._lastPointerUp.copy(this._pointer);
275
+ }
276
+ onClick(e) {
277
+ }
278
+ onDragEnd(e) {
279
+ const intersect = this._intersects[0];
280
+ if (intersect) {
281
+ this._dragEnd.copy(intersect.point.clone());
282
+ this._dragCurrent.copy(intersect.point.clone());
283
+ this._dragDelta.subVectors(this._dragCurrent.clone(), this._dragStart.clone());
284
+ }
285
+ if (this._draggable && this._draggable.onDragEnd) {
286
+ this._draggable.onDragEnd({
287
+ dragStart: this._dragStart,
288
+ dragCurrent: this._dragCurrent,
289
+ dragEnd: this._dragEnd,
290
+ dragDelta: this._dragDelta
291
+ });
292
+ }
293
+ this._draggable = null;
294
+ this._dragging = false;
295
+ this._dragStart.set(0, 0, 0);
296
+ this._dragCurrent.set(0, 0, 0);
297
+ this._dragEnd.set(0, 0, 0);
298
+ this._dragDelta.set(0, 0, 0);
299
+ this._controller.enabled = true;
300
+ }
301
+ onWheel(e) {
302
+ }
303
+ raycast(objects) {
304
+ if (objects !== void 0) return this._raycaster.intersectObjects(objects, true).filter((i) => i.object.visible);
305
+ return this._raycaster.intersectObjects(this._scene.children, true).filter((i) => i.object.visible);
306
+ }
307
+ pointerWasDragged() {
308
+ return this._lastPointerDown.distanceTo(this._pointer) > this.POINTER_DRAG_THRESHOLD;
309
+ }
310
+ };
311
+ }
312
+ });
313
+
314
+ // src/toolbox/transform/TransformTool.ts
315
+ var import_Addons, DIVETransformTool;
316
+ var init_TransformTool = __esm({
317
+ "src/toolbox/transform/TransformTool.ts"() {
318
+ "use strict";
319
+ init_BaseTool();
320
+ import_Addons = require("three/examples/jsm/Addons");
321
+ DIVETransformTool = class extends DIVEBaseTool {
322
+ constructor(scene, controller) {
323
+ super(scene, controller);
324
+ this.isTransformTool = true;
325
+ this.name = "DIVETransformTool";
326
+ this._gizmo = new import_Addons.TransformControls(this._controller.object, this._controller.domElement);
327
+ this._gizmo.mode = "translate";
328
+ this._gizmo.addEventListener("mouseDown", () => {
329
+ controller.enabled = false;
330
+ });
331
+ this._gizmo.addEventListener("mouseUp", () => {
332
+ controller.enabled = true;
333
+ });
334
+ this._gizmo.addEventListener("objectChange", () => {
335
+ if (!this._gizmo.object) return;
336
+ if (!("isMoveable" in this._gizmo.object)) return;
337
+ if (!("onMove" in this._gizmo.object)) return;
338
+ this._gizmo.object.onMove();
339
+ });
340
+ scene.add(this._gizmo);
341
+ }
342
+ Activate() {
343
+ }
344
+ SetGizmoMode(mode) {
345
+ this._gizmo.mode = mode;
346
+ }
347
+ SetGizmoVisibility(active) {
348
+ const contains = this._scene.children.includes(this._gizmo);
349
+ if (active && !contains) {
350
+ this._scene.add(this._gizmo);
351
+ } else if (!active && contains) {
352
+ this._scene.remove(this._gizmo);
353
+ }
354
+ }
355
+ // public onPointerDown(e: PointerEvent): void {
356
+ // super.onPointerDown(e);
357
+ // // if (this._hovered) {
358
+ // // this._dragRaycastOnObjects = this._gizmo.gizmoPlane.children;
359
+ // // }
360
+ // }
361
+ // protected raycast(): Intersection[] {
362
+ // return super.raycast(this._gizmo.gizmoNode.children);
363
+ // }
364
+ };
365
+ }
366
+ });
367
+
368
+ // src/interface/Selectable.ts
369
+ function isSelectable(object) {
370
+ return "isSelectable" in object;
371
+ }
372
+ function findSelectableInterface(child) {
373
+ if (child === void 0) return void 0;
374
+ if (child.parent === null) {
375
+ return void 0;
376
+ }
377
+ if (isSelectable(child)) {
378
+ return child;
379
+ }
380
+ return findSelectableInterface(child.parent);
381
+ }
382
+ var init_Selectable = __esm({
383
+ "src/interface/Selectable.ts"() {
384
+ "use strict";
385
+ }
386
+ });
387
+
388
+ // src/toolbox/select/SelectTool.ts
389
+ var SelectTool_exports = {};
390
+ __export(SelectTool_exports, {
391
+ DIVESelectTool: () => DIVESelectTool,
392
+ isSelectTool: () => isSelectTool
393
+ });
394
+ var isSelectTool, DIVESelectTool;
395
+ var init_SelectTool = __esm({
396
+ "src/toolbox/select/SelectTool.ts"() {
397
+ "use strict";
398
+ init_TransformTool();
399
+ init_Selectable();
400
+ isSelectTool = (tool) => {
401
+ return tool.isSelectTool !== void 0;
402
+ };
403
+ DIVESelectTool = class extends DIVETransformTool {
404
+ constructor(scene, controller) {
405
+ super(scene, controller);
406
+ this.isSelectTool = true;
407
+ this.name = "SelectTool";
408
+ }
409
+ Activate() {
410
+ }
411
+ Select(selectable) {
412
+ if (selectable.onSelect) selectable.onSelect();
413
+ this.AttachGizmo(selectable);
414
+ }
415
+ Deselect(selectable) {
416
+ if (selectable.onDeselect) selectable.onDeselect();
417
+ this.DetachGizmo();
418
+ }
419
+ AttachGizmo(selectable) {
420
+ if ("isMoveable" in selectable) {
421
+ const movable = selectable;
422
+ this._gizmo.attach(movable);
423
+ this.SetGizmoVisibility(movable.visible);
424
+ }
425
+ }
426
+ DetachGizmo() {
427
+ this._gizmo.detach();
428
+ }
429
+ onClick(e) {
430
+ super.onClick(e);
431
+ const first = this._raycaster.intersectObjects(this._scene.Root.children, true).filter((intersect) => intersect.object.visible)[0];
432
+ const selectable = findSelectableInterface(first == null ? void 0 : first.object);
433
+ if (!first || !selectable) {
434
+ if (this._gizmo.object) {
435
+ this.Deselect(this._gizmo.object);
436
+ }
437
+ return;
438
+ }
439
+ if (this._gizmo.object) {
440
+ if (this._gizmo.object.uuid === selectable.uuid) return;
441
+ this.Deselect(this._gizmo.object);
442
+ }
443
+ this.Select(selectable);
444
+ }
445
+ };
446
+ }
447
+ });
448
+
449
+ // src/camera/PerspectiveCamera.ts
450
+ var import_three4, DIVEPerspectiveCameraDefaultSettings, _DIVEPerspectiveCamera, DIVEPerspectiveCamera;
451
+ var init_PerspectiveCamera = __esm({
452
+ "src/camera/PerspectiveCamera.ts"() {
453
+ "use strict";
454
+ import_three4 = require("three");
455
+ init_VisibilityLayerMask();
456
+ DIVEPerspectiveCameraDefaultSettings = {
457
+ fov: 80,
458
+ near: 0.1,
459
+ far: 1e3
460
+ };
461
+ _DIVEPerspectiveCamera = class _DIVEPerspectiveCamera extends import_three4.PerspectiveCamera {
462
+ constructor(settings = DIVEPerspectiveCameraDefaultSettings) {
463
+ super(settings.fov, 1, settings.near, settings.far);
464
+ this.onSetCameraLayer = () => {
465
+ };
466
+ this.layers.mask = _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
467
+ }
468
+ OnResize(width, height) {
469
+ this.aspect = width / height;
470
+ this.updateProjectionMatrix();
471
+ }
472
+ SetCameraLayer(layer) {
473
+ this.layers.mask = layer === "LIVE" ? _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK : _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
474
+ this.onSetCameraLayer(this.layers.mask);
475
+ }
476
+ };
477
+ _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK = DEFAULT_LAYER_MASK | UI_LAYER_MASK | HELPER_LAYER_MASK | PRODUCT_LAYER_MASK;
478
+ _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK = PRODUCT_LAYER_MASK;
479
+ DIVEPerspectiveCamera = _DIVEPerspectiveCamera;
480
+ }
481
+ });
482
+
483
+ // src/mediacreator/MediaCreator.ts
484
+ var MediaCreator_exports = {};
485
+ __export(MediaCreator_exports, {
486
+ DIVEMediaCreator: () => DIVEMediaCreator
487
+ });
488
+ var DIVEMediaCreator;
489
+ var init_MediaCreator = __esm({
490
+ "src/mediacreator/MediaCreator.ts"() {
491
+ "use strict";
492
+ init_PerspectiveCamera();
493
+ DIVEMediaCreator = class {
494
+ constructor(renderer, scene, controller) {
495
+ this.renderer = renderer;
496
+ this.scene = scene;
497
+ this.controller = controller;
498
+ }
499
+ GenerateMedia(position, target, width, height) {
500
+ const resetPosition = this.controller.object.position.clone();
501
+ const resetRotation = this.controller.object.quaternion.clone();
502
+ this.renderer.OnResize(width, height);
503
+ this.controller.object.OnResize(width, height);
504
+ this.controller.object.position.copy(position);
505
+ this.controller.target.copy(target);
506
+ this.controller.update();
507
+ const dataUri = this.DrawCanvas().toDataURL();
508
+ this.controller.object.position.copy(resetPosition);
509
+ this.controller.object.quaternion.copy(resetRotation);
510
+ return dataUri;
511
+ }
512
+ DrawCanvas(canvasElement) {
513
+ const restore = this.renderer.domElement;
514
+ if (canvasElement) {
515
+ this.renderer.domElement = canvasElement;
516
+ }
517
+ this.controller.object.layers.mask = DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
518
+ this.renderer.render(this.scene, this.controller.object);
519
+ this.controller.object.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
520
+ const returnCanvas = this.renderer.domElement;
521
+ if (canvasElement) {
522
+ this.renderer.domElement = restore;
523
+ }
524
+ return returnCanvas;
525
+ }
526
+ };
527
+ }
528
+ });
529
+
67
530
  // src/dive.ts
68
531
  var dive_exports = {};
69
532
  __export(dive_exports, {
@@ -74,7 +537,6 @@ __export(dive_exports, {
74
537
  default: () => DIVE
75
538
  });
76
539
  module.exports = __toCommonJS(dive_exports);
77
- var import_three17 = require("three");
78
540
 
79
541
  // src/renderer/Renderer.ts
80
542
  var import_three = require("three");
@@ -106,6 +568,11 @@ var DIVERenderer = class extends import_three.WebGLRenderer {
106
568
  this.toneMapping = rendererSettings.toneMapping;
107
569
  this.debug.checkShaderErrors = false;
108
570
  }
571
+ // Stops renderings and disposes the renderer.
572
+ Dispose() {
573
+ this.StopRenderer();
574
+ this.dispose();
575
+ }
109
576
  // Starts the renderer with the given scene and camera.
110
577
  StartRenderer(scene, cam) {
111
578
  this.setAnimationLoop(() => {
@@ -197,25 +664,17 @@ var DIVERenderer = class extends import_three.WebGLRenderer {
197
664
  };
198
665
 
199
666
  // src/scene/Scene.ts
200
- var import_three12 = require("three");
667
+ var import_three13 = require("three");
201
668
 
202
669
  // src/scene/root/Root.ts
203
- var import_three11 = require("three");
670
+ var import_three12 = require("three");
204
671
 
205
672
  // src/scene/root/lightroot/LightRoot.ts
206
- var import_three6 = require("three");
673
+ var import_three7 = require("three");
207
674
 
208
675
  // src/light/AmbientLight.ts
209
676
  var import_three2 = require("three");
210
-
211
- // src/constant/VisibilityLayerMask.ts
212
- var DEFAULT_LAYER_MASK = 1;
213
- var COORDINATE_LAYER_MASK = 2;
214
- var UI_LAYER_MASK = 4;
215
- var HELPER_LAYER_MASK = 8;
216
- var PRODUCT_LAYER_MASK = 16;
217
-
218
- // src/light/AmbientLight.ts
677
+ init_VisibilityLayerMask();
219
678
  var DIVEAmbientLight = class extends import_three2.Object3D {
220
679
  constructor() {
221
680
  super();
@@ -236,25 +695,34 @@ var DIVEAmbientLight = class extends import_three2.Object3D {
236
695
  };
237
696
 
238
697
  // src/light/PointLight.ts
239
- var import_three4 = require("three");
698
+ var import_three5 = require("three");
240
699
 
241
700
  // src/com/Communication.ts
242
- var import_three3 = require("three");
701
+ var import_MathUtils = require("three/src/math/MathUtils");
702
+ init_SelectTool();
243
703
  var _DIVECommunication = class _DIVECommunication {
244
- constructor(scene, controls, toolbox, mediaGenerator) {
704
+ constructor(renderer, scene, controls, toolbox) {
245
705
  this.registered = /* @__PURE__ */ new Map();
246
706
  // private listeners: { [key: string]: EventListener[] } = {};
247
707
  this.listeners = /* @__PURE__ */ new Map();
248
- this.id = import_three3.MathUtils.generateUUID();
708
+ this.id = (0, import_MathUtils.generateUUID)();
709
+ this.renderer = renderer;
249
710
  this.scene = scene;
250
711
  this.controller = controls;
251
712
  this.toolbox = toolbox;
252
- this.mediaGenerator = mediaGenerator;
713
+ this._mediaGenerator = null;
253
714
  _DIVECommunication.__instances.push(this);
254
715
  }
255
716
  static get(id) {
256
717
  return this.__instances.find((instance) => Array.from(instance.registered.values()).find((object) => object.id === id));
257
718
  }
719
+ get mediaGenerator() {
720
+ if (!this._mediaGenerator) {
721
+ const DIVEMediaCreator2 = (init_MediaCreator(), __toCommonJS(MediaCreator_exports)).default;
722
+ this._mediaGenerator = new DIVEMediaCreator2(this.renderer, this.scene, this.controller);
723
+ }
724
+ return this._mediaGenerator;
725
+ }
258
726
  DestroyInstance() {
259
727
  const existingIndex = _DIVECommunication.__instances.findIndex((entry) => entry.id === this.id);
260
728
  if (existingIndex === -1) return false;
@@ -324,6 +792,10 @@ var _DIVECommunication = class _DIVECommunication {
324
792
  returnValue = this.resetCamera(payload);
325
793
  break;
326
794
  }
795
+ case "COMPUTE_ENCOMPASSING_VIEW": {
796
+ returnValue = this.computeEncompassingView(payload);
797
+ break;
798
+ }
327
799
  case "SET_CAMERA_LAYER": {
328
800
  returnValue = this.setCameraLayer(payload);
329
801
  break;
@@ -336,6 +808,10 @@ var _DIVECommunication = class _DIVECommunication {
336
808
  returnValue = this.setGizmoMode(payload);
337
809
  break;
338
810
  }
811
+ case "SET_GIZMO_VISIBILITY": {
812
+ returnValue = this.setGizmoVisibility(payload);
813
+ break;
814
+ }
339
815
  case "MODEL_LOADED": {
340
816
  returnValue = this.modelLoaded(payload);
341
817
  break;
@@ -430,8 +906,10 @@ var _DIVECommunication = class _DIVECommunication {
430
906
  const sceneObject = this.scene.GetSceneObject(object);
431
907
  if (!sceneObject) return false;
432
908
  if (!("isSelectable" in sceneObject)) return false;
433
- this.toolbox.UseTool("select");
434
- this.toolbox.GetActiveTool().AttachGizmo(sceneObject);
909
+ const activeTool = this.toolbox.GetActiveTool();
910
+ if (activeTool && isSelectTool(activeTool)) {
911
+ activeTool.AttachGizmo(sceneObject);
912
+ }
435
913
  Object.assign(payload, object);
436
914
  return true;
437
915
  }
@@ -441,8 +919,10 @@ var _DIVECommunication = class _DIVECommunication {
441
919
  const sceneObject = this.scene.GetSceneObject(object);
442
920
  if (!sceneObject) return false;
443
921
  if (!("isSelectable" in sceneObject)) return false;
444
- this.toolbox.UseTool("select");
445
- this.toolbox.GetActiveTool().DetachGizmo();
922
+ const activeTool = this.toolbox.GetActiveTool();
923
+ if (activeTool && isSelectTool(activeTool)) {
924
+ activeTool.DetachGizmo();
925
+ }
446
926
  Object.assign(payload, object);
447
927
  return true;
448
928
  }
@@ -497,6 +977,12 @@ var _DIVECommunication = class _DIVECommunication {
497
977
  this.controller.RevertLast(payload.duration);
498
978
  return true;
499
979
  }
980
+ computeEncompassingView(payload) {
981
+ const sceneBB = this.scene.ComputeSceneBB();
982
+ const transform = this.controller.ComputeEncompassingView(sceneBB);
983
+ Object.assign(payload, transform);
984
+ return transform;
985
+ }
500
986
  zoomCamera(payload) {
501
987
  if (payload.direction === "IN") this.controller.ZoomIn(payload.by);
502
988
  if (payload.direction === "OUT") this.controller.ZoomOut(payload.by);
@@ -506,6 +992,10 @@ var _DIVECommunication = class _DIVECommunication {
506
992
  this.toolbox.SetGizmoMode(payload.mode);
507
993
  return true;
508
994
  }
995
+ setGizmoVisibility(payload) {
996
+ this.toolbox.SetGizmoVisibility(payload);
997
+ return payload;
998
+ }
509
999
  modelLoaded(payload) {
510
1000
  this.registered.get(payload.id).loaded = true;
511
1001
  return true;
@@ -513,10 +1003,12 @@ var _DIVECommunication = class _DIVECommunication {
513
1003
  updateScene(payload) {
514
1004
  if (payload.name !== void 0) this.scene.name = payload.name;
515
1005
  if (payload.backgroundColor !== void 0) this.scene.SetBackground(payload.backgroundColor);
1006
+ if (payload.gridEnabled !== void 0) this.scene.Root.Grid.SetVisibility(payload.gridEnabled);
516
1007
  if (payload.floorEnabled !== void 0) this.scene.Root.Floor.SetVisibility(payload.floorEnabled);
517
1008
  if (payload.floorColor !== void 0) this.scene.Root.Floor.SetColor(payload.floorColor);
518
1009
  payload.name = this.scene.name;
519
1010
  payload.backgroundColor = "#" + this.scene.background.getHexString();
1011
+ payload.gridEnabled = this.scene.Root.Grid.visible;
520
1012
  payload.floorEnabled = this.scene.Root.Floor.visible;
521
1013
  payload.floorColor = "#" + this.scene.Root.Floor.material.color.getHexString();
522
1014
  return true;
@@ -539,23 +1031,24 @@ _DIVECommunication.__instances = [];
539
1031
  var DIVECommunication = _DIVECommunication;
540
1032
 
541
1033
  // src/light/PointLight.ts
542
- var DIVEPointLight = class extends import_three4.Object3D {
1034
+ init_VisibilityLayerMask();
1035
+ var DIVEPointLight = class extends import_three5.Object3D {
543
1036
  constructor() {
544
1037
  super();
545
1038
  this.isMoveable = true;
546
1039
  this.isSelectable = true;
547
1040
  this.gizmo = null;
548
1041
  this.name = "DIVEPointLight";
549
- this.light = new import_three4.PointLight(16777215, 1);
1042
+ this.light = new import_three5.PointLight(16777215, 1);
550
1043
  this.light.layers.mask = PRODUCT_LAYER_MASK;
551
1044
  this.light.castShadow = true;
552
1045
  this.light.shadow.mapSize.width = 512;
553
1046
  this.light.shadow.mapSize.height = 512;
554
1047
  this.add(this.light);
555
1048
  const geoSize = 0.1;
556
- const geometry = new import_three4.SphereGeometry(geoSize, geoSize * 320, geoSize * 320);
557
- const material = new import_three4.MeshBasicMaterial({ color: this.light.color, transparent: true, opacity: 0.8, side: import_three4.FrontSide });
558
- this.mesh = new import_three4.Mesh(geometry, material);
1049
+ const geometry = new import_three5.SphereGeometry(geoSize, geoSize * 320, geoSize * 320);
1050
+ const material = new import_three5.MeshBasicMaterial({ color: this.light.color, transparent: true, opacity: 0.8, side: import_three5.FrontSide });
1051
+ this.mesh = new import_three5.Mesh(geometry, material);
559
1052
  this.mesh.layers.mask = UI_LAYER_MASK;
560
1053
  this.add(this.mesh);
561
1054
  }
@@ -585,16 +1078,17 @@ var DIVEPointLight = class extends import_three4.Object3D {
585
1078
  };
586
1079
 
587
1080
  // src/light/SceneLight.ts
588
- var import_three5 = require("three");
589
- var DIVESceneLight = class extends import_three5.Object3D {
1081
+ init_VisibilityLayerMask();
1082
+ var import_three6 = require("three");
1083
+ var DIVESceneLight = class extends import_three6.Object3D {
590
1084
  constructor() {
591
1085
  super();
592
1086
  this.name = "DIVESceneLight";
593
- this._hemiLight = new import_three5.HemisphereLight(16777215, 16777215, 2);
1087
+ this._hemiLight = new import_three6.HemisphereLight(16777215, 16777215, 2);
594
1088
  this._hemiLight.layers.mask = PRODUCT_LAYER_MASK;
595
1089
  this._hemiLight.position.set(0, 50, 0);
596
1090
  this.add(this._hemiLight);
597
- this._dirLight = new import_three5.DirectionalLight(16777215, 3);
1091
+ this._dirLight = new import_three6.DirectionalLight(16777215, 3);
598
1092
  this._dirLight.layers.mask = PRODUCT_LAYER_MASK;
599
1093
  this._dirLight.position.set(1, 1.75, 1);
600
1094
  this._dirLight.position.multiplyScalar(30);
@@ -624,7 +1118,7 @@ var DIVESceneLight = class extends import_three5.Object3D {
624
1118
  };
625
1119
 
626
1120
  // src/scene/root/lightroot/LightRoot.ts
627
- var DIVELightRoot = class extends import_three6.Object3D {
1121
+ var DIVELightRoot = class extends import_three7.Object3D {
628
1122
  constructor() {
629
1123
  super();
630
1124
  this.name = "LightRoot";
@@ -668,7 +1162,7 @@ var DIVELightRoot = class extends import_three6.Object3D {
668
1162
  if (light.position !== void 0 && light.position !== null) sceneObject.position.set(light.position.x, light.position.y, light.position.z);
669
1163
  if (light.intensity !== void 0 && light.intensity !== null) sceneObject.SetIntensity(light.intensity);
670
1164
  if (light.enabled !== void 0 && light.enabled !== null) sceneObject.SetEnabled(light.enabled);
671
- if (light.color !== void 0 && light.color !== null) sceneObject.SetColor(new import_three6.Color(light.color));
1165
+ if (light.color !== void 0 && light.color !== null) sceneObject.SetColor(new import_three7.Color(light.color));
672
1166
  if (light.visible !== void 0 && light.visible !== null) sceneObject.visible = light.visible;
673
1167
  }
674
1168
  DeleteLight(light) {
@@ -699,10 +1193,11 @@ var DIVELightRoot = class extends import_three6.Object3D {
699
1193
  };
700
1194
 
701
1195
  // src/scene/root/modelroot/ModelRoot.ts
702
- var import_three8 = require("three");
1196
+ var import_three9 = require("three");
703
1197
 
704
1198
  // src/model/Model.ts
705
- var import_three7 = require("three");
1199
+ var import_three8 = require("three");
1200
+ init_VisibilityLayerMask();
706
1201
 
707
1202
  // src/helper/findSceneRecursive/findSceneRecursive.ts
708
1203
  var findSceneRecursive = (object) => {
@@ -713,14 +1208,14 @@ var findSceneRecursive = (object) => {
713
1208
  };
714
1209
 
715
1210
  // src/model/Model.ts
716
- var DIVEModel = class extends import_three7.Object3D {
1211
+ var DIVEModel = class extends import_three8.Object3D {
717
1212
  constructor() {
718
1213
  super();
719
1214
  this.isSelectable = true;
720
1215
  this.isMoveable = true;
721
1216
  this.gizmo = null;
722
1217
  this.layers.mask = PRODUCT_LAYER_MASK;
723
- this.boundingBox = new import_three7.Box3();
1218
+ this.boundingBox = new import_three8.Box3();
724
1219
  }
725
1220
  SetModel(gltf) {
726
1221
  this.clear();
@@ -736,11 +1231,16 @@ var DIVEModel = class extends import_three7.Object3D {
736
1231
  this.position.set(position.x, position.y, position.z);
737
1232
  }
738
1233
  SetRotation(rotation) {
739
- this.rotation.setFromVector3(new import_three7.Vector3(rotation.x, rotation.y, rotation.z));
1234
+ this.rotation.setFromVector3(new import_three8.Vector3(rotation.x, rotation.y, rotation.z));
740
1235
  }
741
1236
  SetScale(scale) {
742
1237
  this.scale.set(scale.x, scale.y, scale.z);
743
1238
  }
1239
+ SetVisibility(visible) {
1240
+ this.traverse((child) => {
1241
+ child.visible = visible;
1242
+ });
1243
+ }
744
1244
  SetToWorldOrigin() {
745
1245
  var _a;
746
1246
  this.position.set(0, 0, 0);
@@ -758,9 +1258,9 @@ var DIVEModel = class extends import_three7.Object3D {
758
1258
  return;
759
1259
  }
760
1260
  const bottomY = this.boundingBox.min.y * this.scale.y;
761
- const bbBottomCenter = this.localToWorld(this.boundingBox.getCenter(new import_three7.Vector3()).multiply(this.scale));
1261
+ const bbBottomCenter = this.localToWorld(this.boundingBox.getCenter(new import_three8.Vector3()).multiply(this.scale));
762
1262
  bbBottomCenter.y = bottomY + this.position.y;
763
- const raycaster = new import_three7.Raycaster(bbBottomCenter, new import_three7.Vector3(0, -1, 0));
1263
+ const raycaster = new import_three8.Raycaster(bbBottomCenter, new import_three8.Vector3(0, -1, 0));
764
1264
  raycaster.layers.mask = PRODUCT_LAYER_MASK;
765
1265
  const intersections = raycaster.intersectObjects(findSceneRecursive(this).Root.children, true);
766
1266
  if (intersections.length > 0) {
@@ -769,7 +1269,7 @@ var DIVEModel = class extends import_three7.Object3D {
769
1269
  const meshBB = mesh.geometry.boundingBox;
770
1270
  const worldPos = mesh.localToWorld(meshBB.max.clone());
771
1271
  const oldPos = this.position.clone();
772
- const newPos = this.position.clone().setY(worldPos.y).add(new import_three7.Vector3(0, bottomY, 0));
1272
+ const newPos = this.position.clone().setY(worldPos.y).add(new import_three8.Vector3(0, bottomY, 0));
773
1273
  this.position.copy(newPos);
774
1274
  if (this.position.y === oldPos.y) return;
775
1275
  (_a = DIVECommunication.get(this.userData.id)) == null ? void 0 : _a.PerformAction("UPDATE_OBJECT", { id: this.userData.id, position: this.position, rotation: this.rotation, scale: this.scale });
@@ -790,13 +1290,13 @@ var DIVEModel = class extends import_three7.Object3D {
790
1290
  };
791
1291
 
792
1292
  // src/loadingmanager/LoadingManager.ts
793
- var import_Addons = require("three/examples/jsm/Addons.js");
1293
+ var import_Addons2 = require("three/examples/jsm/Addons.js");
794
1294
  var DIVELoadingManager = class {
795
1295
  // ... maybe extend with other loaders later
796
1296
  constructor() {
797
1297
  this.progress = /* @__PURE__ */ new Map();
798
- this.gltfloader = new import_Addons.GLTFLoader();
799
- this.dracoloader = new import_Addons.DRACOLoader();
1298
+ this.gltfloader = new import_Addons2.GLTFLoader();
1299
+ this.dracoloader = new import_Addons2.DRACOLoader();
800
1300
  this.dracoloader.setDecoderPath("https://www.gstatic.com/draco/v1/decoders/");
801
1301
  this.gltfloader.setDRACOLoader(this.dracoloader);
802
1302
  }
@@ -822,7 +1322,7 @@ var DIVELoadingManager = class {
822
1322
  };
823
1323
 
824
1324
  // src/scene/root/modelroot/ModelRoot.ts
825
- var DIVEModelRoot = class extends import_three8.Object3D {
1325
+ var DIVEModelRoot = class extends import_three9.Object3D {
826
1326
  constructor() {
827
1327
  super();
828
1328
  this.name = "ModelRoot";
@@ -855,7 +1355,7 @@ var DIVEModelRoot = class extends import_three8.Object3D {
855
1355
  if (object.position !== void 0) sceneObject.SetPosition(object.position);
856
1356
  if (object.rotation !== void 0) sceneObject.SetRotation(object.rotation);
857
1357
  if (object.scale !== void 0) sceneObject.SetScale(object.scale);
858
- if (object.visible !== void 0) sceneObject.visible = object.visible;
1358
+ if (object.visible !== void 0) sceneObject.SetVisibility(object.visible);
859
1359
  }
860
1360
  DeleteModel(object) {
861
1361
  if (object.id === void 0) {
@@ -891,10 +1391,11 @@ var DIVEModelRoot = class extends import_three8.Object3D {
891
1391
  };
892
1392
 
893
1393
  // src/primitive/floor/Floor.ts
894
- var import_three9 = require("three");
895
- var DIVEFloor = class extends import_three9.Mesh {
1394
+ var import_three10 = require("three");
1395
+ init_VisibilityLayerMask();
1396
+ var DIVEFloor = class extends import_three10.Mesh {
896
1397
  constructor() {
897
- super(new import_three9.PlaneGeometry(1e4, 1e4), new import_three9.MeshStandardMaterial({ color: new import_three9.Color(150 / 255, 150 / 255, 150 / 255) }));
1398
+ super(new import_three10.PlaneGeometry(1e4, 1e4), new import_three10.MeshStandardMaterial({ color: new import_three10.Color(150 / 255, 150 / 255, 150 / 255) }));
898
1399
  this.isFloor = true;
899
1400
  this.name = "Floor";
900
1401
  this.layers.mask = PRODUCT_LAYER_MASK;
@@ -905,7 +1406,7 @@ var DIVEFloor = class extends import_three9.Mesh {
905
1406
  this.visible = visible;
906
1407
  }
907
1408
  SetColor(color) {
908
- this.material.color = new import_three9.Color(color);
1409
+ this.material.color = new import_three10.Color(color);
909
1410
  }
910
1411
  };
911
1412
 
@@ -914,20 +1415,24 @@ var GRID_CENTER_LINE_COLOR = "#888888";
914
1415
  var GRID_SIDE_LINE_COLOR = "#dddddd";
915
1416
 
916
1417
  // src/grid/Grid.ts
917
- var import_three10 = require("three");
918
- var DIVEGrid = class extends import_three10.Object3D {
1418
+ init_VisibilityLayerMask();
1419
+ var import_three11 = require("three");
1420
+ var DIVEGrid = class extends import_three11.Object3D {
919
1421
  constructor() {
920
1422
  super();
921
1423
  this.name = "Grid";
922
- const grid = new import_three10.GridHelper(100, 100, GRID_CENTER_LINE_COLOR, GRID_SIDE_LINE_COLOR);
1424
+ const grid = new import_three11.GridHelper(100, 100, GRID_CENTER_LINE_COLOR, GRID_SIDE_LINE_COLOR);
923
1425
  grid.material.depthTest = false;
924
1426
  grid.layers.mask = HELPER_LAYER_MASK;
925
1427
  this.add(grid);
926
1428
  }
1429
+ SetVisibility(visible) {
1430
+ this.visible = visible;
1431
+ }
927
1432
  };
928
1433
 
929
1434
  // src/scene/root/Root.ts
930
- var DIVERoot = class extends import_three11.Object3D {
1435
+ var DIVERoot = class extends import_three12.Object3D {
931
1436
  get Floor() {
932
1437
  return this.floor;
933
1438
  }
@@ -946,6 +1451,15 @@ var DIVERoot = class extends import_three11.Object3D {
946
1451
  this.grid = new DIVEGrid();
947
1452
  this.add(this.grid);
948
1453
  }
1454
+ ComputeSceneBB() {
1455
+ const bb = new import_three12.Box3();
1456
+ this.modelRoot.traverse((object) => {
1457
+ if ("isObject3D" in object) {
1458
+ bb.expandByObject(object);
1459
+ }
1460
+ });
1461
+ return bb;
1462
+ }
949
1463
  GetSceneObject(object) {
950
1464
  switch (object.entityType) {
951
1465
  case "pov": {
@@ -1010,17 +1524,21 @@ var DIVERoot = class extends import_three11.Object3D {
1010
1524
  };
1011
1525
 
1012
1526
  // src/scene/Scene.ts
1013
- var DIVEScene = class extends import_three12.Scene {
1527
+ var DIVEScene = class extends import_three13.Scene {
1014
1528
  get Root() {
1015
1529
  return this.root;
1016
1530
  }
1017
1531
  constructor() {
1018
1532
  super();
1533
+ this.background = new import_three13.Color(16777215);
1019
1534
  this.root = new DIVERoot();
1020
1535
  this.add(this.root);
1021
1536
  }
1022
1537
  SetBackground(color) {
1023
- this.background = new import_three12.Color(color);
1538
+ this.background = new import_three13.Color(color);
1539
+ }
1540
+ ComputeSceneBB() {
1541
+ return this.Root.ComputeSceneBB();
1024
1542
  }
1025
1543
  GetSceneObject(object) {
1026
1544
  return this.Root.GetSceneObject(object);
@@ -1039,42 +1557,18 @@ var DIVEScene = class extends import_three12.Scene {
1039
1557
  }
1040
1558
  };
1041
1559
 
1042
- // src/camera/PerspectiveCamera.ts
1043
- var import_three13 = require("three");
1044
- var DIVEPerspectiveCameraDefaultSettings = {
1045
- fov: 80,
1046
- near: 0.1,
1047
- far: 1e3
1048
- };
1049
- var _DIVEPerspectiveCamera = class _DIVEPerspectiveCamera extends import_three13.PerspectiveCamera {
1050
- constructor(settings = DIVEPerspectiveCameraDefaultSettings) {
1051
- super(settings.fov, 1, settings.near, settings.far);
1052
- this.onSetCameraLayer = () => {
1053
- };
1054
- this.layers.mask = _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
1055
- }
1056
- OnResize(width, height) {
1057
- this.aspect = width / height;
1058
- this.updateProjectionMatrix();
1059
- }
1060
- SetCameraLayer(layer) {
1061
- this.layers.mask = layer === "LIVE" ? _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK : _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
1062
- this.onSetCameraLayer(this.layers.mask);
1063
- }
1064
- };
1065
- _DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK = DEFAULT_LAYER_MASK | UI_LAYER_MASK | HELPER_LAYER_MASK | PRODUCT_LAYER_MASK;
1066
- _DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK = PRODUCT_LAYER_MASK;
1067
- var DIVEPerspectiveCamera = _DIVEPerspectiveCamera;
1560
+ // src/dive.ts
1561
+ init_PerspectiveCamera();
1068
1562
 
1069
1563
  // src/controls/OrbitControls.ts
1070
- var import_Addons2 = require("three/examples/jsm/Addons.js");
1564
+ var import_Addons3 = require("three/examples/jsm/Addons.js");
1071
1565
  var import_three14 = require("three");
1072
1566
  var import_tween = require("@tweenjs/tween.js");
1073
1567
  var DIVEOrbitControlsDefaultSettings = {
1074
1568
  enableDamping: true,
1075
1569
  dampingFactor: 0.04
1076
1570
  };
1077
- var _DIVEOrbitControls = class _DIVEOrbitControls extends import_Addons2.OrbitControls {
1571
+ var _DIVEOrbitControls = class _DIVEOrbitControls extends import_Addons3.OrbitControls {
1078
1572
  constructor(camera, renderer, settings = DIVEOrbitControlsDefaultSettings) {
1079
1573
  super(camera, renderer.domElement);
1080
1574
  this.last = null;
@@ -1096,6 +1590,16 @@ var _DIVEOrbitControls = class _DIVEOrbitControls extends import_Addons2.OrbitCo
1096
1590
  this.enableDamping = settings.enableDamping;
1097
1591
  this.dampingFactor = settings.dampingFactor;
1098
1592
  }
1593
+ ComputeEncompassingView(bb) {
1594
+ const center = bb.getCenter(new import_three14.Vector3());
1595
+ const size = bb.getSize(new import_three14.Vector3());
1596
+ const distance = Math.max(size.x, size.y, size.z) * 1.25;
1597
+ const direction = this.object.position.clone().normalize();
1598
+ return {
1599
+ position: direction.multiplyScalar(distance),
1600
+ target: center
1601
+ };
1602
+ }
1099
1603
  ZoomIn(by) {
1100
1604
  const zoomBy = by || _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR;
1101
1605
  const { minDistance, maxDistance } = this;
@@ -1156,385 +1660,40 @@ var _DIVEOrbitControls = class _DIVEOrbitControls extends import_Addons2.OrbitCo
1156
1660
  _DIVEOrbitControls.DEFAULT_ZOOM_FACTOR = 1;
1157
1661
  var DIVEOrbitControls = _DIVEOrbitControls;
1158
1662
 
1159
- // src/mediacreator/MediaCreator.ts
1160
- var DIVEMediaCreator = class {
1161
- constructor(renderer, scene, controller) {
1162
- this.renderer = renderer;
1163
- this.scene = scene;
1164
- this.controller = controller;
1165
- }
1166
- GenerateMedia(position, target, width, height) {
1167
- const resetPosition = this.controller.object.position.clone();
1168
- const resetRotation = this.controller.object.quaternion.clone();
1169
- this.renderer.OnResize(width, height);
1170
- this.controller.object.OnResize(width, height);
1171
- this.controller.object.position.copy(position);
1172
- this.controller.target.copy(target);
1173
- this.controller.update();
1174
- const dataUri = this.DrawCanvas().toDataURL();
1175
- this.controller.object.position.copy(resetPosition);
1176
- this.controller.object.quaternion.copy(resetRotation);
1177
- return dataUri;
1178
- }
1179
- DrawCanvas(canvasElement) {
1180
- const restore = this.renderer.domElement;
1181
- if (canvasElement) {
1182
- this.renderer.domElement = canvasElement;
1183
- }
1184
- this.controller.object.layers.mask = DIVEPerspectiveCamera.LIVE_VIEW_LAYER_MASK;
1185
- this.renderer.render(this.scene, this.controller.object);
1186
- this.controller.object.layers.mask = DIVEPerspectiveCamera.EDITOR_VIEW_LAYER_MASK;
1187
- const returnCanvas = this.renderer.domElement;
1188
- if (canvasElement) {
1189
- this.renderer.domElement = restore;
1663
+ // src/toolbox/Toolbox.ts
1664
+ var DIVEToolbox = class {
1665
+ get selectTool() {
1666
+ if (!this._selectTool) {
1667
+ const DIVESelectTool2 = (init_SelectTool(), __toCommonJS(SelectTool_exports)).DIVESelectTool;
1668
+ this._selectTool = new DIVESelectTool2(this._scene, this._controller);
1190
1669
  }
1191
- return returnCanvas;
1670
+ return this._selectTool;
1192
1671
  }
1193
- };
1194
-
1195
- // src/interface/Selectable.ts
1196
- function isSelectable(object) {
1197
- return "isSelectable" in object;
1198
- }
1199
-
1200
- // src/toolbox/BaseTool.ts
1201
- var import_three15 = require("three");
1202
-
1203
- // src/interface/Draggable.ts
1204
- var isDraggable = (object) => {
1205
- return "isDraggable" in object;
1206
- };
1207
- var findDraggableInterface = (child) => {
1208
- if (child === void 0) return void 0;
1209
- if (child.parent === null) {
1210
- return void 0;
1211
- }
1212
- if (isDraggable(child)) {
1213
- return child;
1214
- }
1215
- return findDraggableInterface(child.parent);
1216
- };
1217
-
1218
- // src/interface/Hoverable.ts
1219
- var isHoverable = (object) => {
1220
- return "isHoverable" in object;
1221
- };
1222
- var findHoverableInterface = (child) => {
1223
- if (child === void 0) return void 0;
1224
- if (child.parent === null) {
1225
- return void 0;
1226
- }
1227
- if (isHoverable(child)) {
1228
- return child;
1229
- }
1230
- return findHoverableInterface(child.parent);
1231
- };
1232
-
1233
- // src/toolbox/BaseTool.ts
1234
- var DIVEBaseTool = class {
1235
1672
  constructor(scene, controller) {
1236
- this.POINTER_DRAG_THRESHOLD = 1e-3;
1237
- this.name = "BaseTool";
1238
- this._canvas = controller.domElement;
1239
1673
  this._scene = scene;
1240
1674
  this._controller = controller;
1241
- this._pointer = new import_three15.Vector2();
1242
- this._pointerPrimaryDown = false;
1243
- this._pointerMiddleDown = false;
1244
- this._pointerSecondaryDown = false;
1245
- this._lastPointerDown = new import_three15.Vector2();
1246
- this._lastPointerUp = new import_three15.Vector2();
1247
- this._raycaster = new import_three15.Raycaster();
1248
- this._raycaster.layers.mask = PRODUCT_LAYER_MASK | UI_LAYER_MASK;
1249
- this._intersects = [];
1250
- this._hovered = null;
1251
- this._dragging = false;
1252
- this._dragStart = new import_three15.Vector3();
1253
- this._dragCurrent = new import_three15.Vector3();
1254
- this._dragEnd = new import_three15.Vector3();
1255
- this._dragDelta = new import_three15.Vector3();
1256
- this._draggable = null;
1257
- this._dragRaycastOnObjects = null;
1258
- }
1259
- get _pointerAnyDown() {
1260
- return this._pointerPrimaryDown || this._pointerMiddleDown || this._pointerSecondaryDown;
1261
- }
1262
- Activate() {
1263
- }
1264
- Deactivate() {
1265
- }
1266
- onPointerDown(e) {
1267
- var _a;
1268
- switch (e.button) {
1269
- case 0:
1270
- this._pointerPrimaryDown = true;
1271
- break;
1272
- case 1:
1273
- this._pointerMiddleDown = true;
1274
- break;
1275
- case 2:
1276
- this._pointerSecondaryDown = true;
1277
- break;
1278
- }
1279
- this._lastPointerDown.copy(this._pointer);
1280
- this._draggable = findDraggableInterface((_a = this._intersects[0]) == null ? void 0 : _a.object) || null;
1281
- }
1282
- onDragStart(e) {
1283
- if (!this._draggable) return;
1284
- if (this._dragRaycastOnObjects !== null) {
1285
- this._intersects = this._raycaster.intersectObjects(this._dragRaycastOnObjects, true);
1286
- }
1287
- if (this._intersects.length === 0) return;
1288
- this._dragStart.copy(this._intersects[0].point.clone());
1289
- this._dragCurrent.copy(this._intersects[0].point.clone());
1290
- this._dragEnd.copy(this._dragStart.clone());
1291
- this._dragDelta.set(0, 0, 0);
1292
- if (this._draggable && this._draggable.onDragStart) {
1293
- this._draggable.onDragStart({
1294
- dragStart: this._dragStart,
1295
- dragCurrent: this._dragCurrent,
1296
- dragEnd: this._dragEnd,
1297
- dragDelta: this._dragDelta
1298
- });
1299
- this._dragging = true;
1300
- this._controller.enabled = false;
1301
- }
1302
- }
1303
- onPointerMove(e) {
1304
- var _a;
1305
- this._pointer.x = e.offsetX / this._canvas.clientWidth * 2 - 1;
1306
- this._pointer.y = -(e.offsetY / this._canvas.clientHeight) * 2 + 1;
1307
- this._raycaster.setFromCamera(this._pointer, this._controller.object);
1308
- this._intersects = this.raycast(this._scene.children);
1309
- const hoverable = findHoverableInterface((_a = this._intersects[0]) == null ? void 0 : _a.object);
1310
- if (this._intersects[0] && hoverable) {
1311
- if (!this._hovered) {
1312
- if (hoverable.onPointerEnter) hoverable.onPointerEnter(this._intersects[0]);
1313
- this._hovered = hoverable;
1314
- return;
1315
- }
1316
- if (this._hovered.uuid !== hoverable.uuid) {
1317
- if (this._hovered.onPointerLeave) this._hovered.onPointerLeave();
1318
- if (hoverable.onPointerEnter) hoverable.onPointerEnter(this._intersects[0]);
1319
- this._hovered = hoverable;
1320
- return;
1321
- }
1322
- if (hoverable.onPointerOver) hoverable.onPointerOver(this._intersects[0]);
1323
- this._hovered = hoverable;
1324
- } else {
1325
- if (this._hovered) {
1326
- if (this._hovered.onPointerLeave) this._hovered.onPointerLeave();
1327
- }
1328
- this._hovered = null;
1329
- }
1330
- if (this._pointerAnyDown) {
1331
- if (!this._dragging) {
1332
- this.onDragStart(e);
1333
- }
1334
- this.onDrag(e);
1335
- }
1336
- }
1337
- onDrag(e) {
1338
- if (this._dragRaycastOnObjects !== null) {
1339
- this._intersects = this._raycaster.intersectObjects(this._dragRaycastOnObjects, true);
1340
- }
1341
- const intersect = this._intersects[0];
1342
- if (!intersect) return;
1343
- this._dragCurrent.copy(intersect.point.clone());
1344
- this._dragEnd.copy(intersect.point.clone());
1345
- this._dragDelta.subVectors(this._dragCurrent.clone(), this._dragStart.clone());
1346
- if (this._draggable && this._draggable.onDrag) {
1347
- this._draggable.onDrag({
1348
- dragStart: this._dragStart,
1349
- dragCurrent: this._dragCurrent,
1350
- dragEnd: this._dragEnd,
1351
- dragDelta: this._dragDelta
1352
- });
1353
- }
1354
- }
1355
- onPointerUp(e) {
1356
- if (this.pointerWasDragged() || this._dragging) {
1357
- if (this._draggable) {
1358
- this.onDragEnd(e);
1359
- }
1360
- } else {
1361
- this.onClick(e);
1362
- }
1363
- switch (e.button) {
1364
- case 0:
1365
- this._pointerPrimaryDown = false;
1366
- break;
1367
- case 1:
1368
- this._pointerMiddleDown = false;
1369
- break;
1370
- case 2:
1371
- this._pointerSecondaryDown = false;
1372
- break;
1373
- }
1374
- this._lastPointerUp.copy(this._pointer);
1375
- }
1376
- onClick(e) {
1377
- }
1378
- onDragEnd(e) {
1379
- const intersect = this._intersects[0];
1380
- if (intersect) {
1381
- this._dragEnd.copy(intersect.point.clone());
1382
- this._dragCurrent.copy(intersect.point.clone());
1383
- this._dragDelta.subVectors(this._dragCurrent.clone(), this._dragStart.clone());
1384
- }
1385
- if (this._draggable && this._draggable.onDragEnd) {
1386
- this._draggable.onDragEnd({
1387
- dragStart: this._dragStart,
1388
- dragCurrent: this._dragCurrent,
1389
- dragEnd: this._dragEnd,
1390
- dragDelta: this._dragDelta
1391
- });
1392
- }
1393
- this._draggable = null;
1394
- this._dragging = false;
1395
- this._dragStart.set(0, 0, 0);
1396
- this._dragCurrent.set(0, 0, 0);
1397
- this._dragEnd.set(0, 0, 0);
1398
- this._dragDelta.set(0, 0, 0);
1399
- this._controller.enabled = true;
1400
- }
1401
- onWheel(e) {
1402
- }
1403
- raycast(objects) {
1404
- if (objects !== void 0) return this._raycaster.intersectObjects(objects, true);
1405
- return this._raycaster.intersectObjects(this._scene.children, true);
1675
+ this._selectTool = null;
1676
+ this._activeTool = null;
1406
1677
  }
1407
- pointerWasDragged() {
1408
- return this._lastPointerDown.distanceTo(this._pointer) > this.POINTER_DRAG_THRESHOLD;
1409
- }
1410
- };
1411
-
1412
- // src/toolbox/transform/TransformTool.ts
1413
- var import_Addons3 = require("three/examples/jsm/Addons");
1414
- var DIVETransformTool = class extends DIVEBaseTool {
1415
- constructor(scene, controller) {
1416
- super(scene, controller);
1417
- this.name = "DIVETransformTool";
1418
- this._gizmo = new import_Addons3.TransformControls(this._controller.object, this._controller.domElement);
1419
- this._gizmo.mode = "translate";
1420
- this._gizmo.addEventListener("mouseDown", () => {
1421
- controller.enabled = false;
1422
- });
1423
- this._gizmo.addEventListener("mouseUp", () => {
1424
- controller.enabled = true;
1425
- });
1426
- this._gizmo.addEventListener("objectChange", () => {
1427
- if (!this._gizmo.object) return;
1428
- if (!("isMoveable" in this._gizmo.object)) return;
1429
- if (!("onMove" in this._gizmo.object)) return;
1430
- this._gizmo.object.onMove();
1431
- });
1432
- scene.add(this._gizmo);
1433
- }
1434
- Activate() {
1435
- }
1436
- SetGizmoMode(mode) {
1437
- this._gizmo.mode = mode;
1438
- }
1439
- // public onPointerDown(e: PointerEvent): void {
1440
- // super.onPointerDown(e);
1441
- // // if (this._hovered) {
1442
- // // this._dragRaycastOnObjects = this._gizmo.gizmoPlane.children;
1443
- // // }
1444
- // }
1445
- // protected raycast(): Intersection[] {
1446
- // return super.raycast(this._gizmo.gizmoNode.children);
1447
- // }
1448
- };
1449
-
1450
- // src/toolbox/select/SelectTool.ts
1451
- var DIVESelectTool = class extends DIVETransformTool {
1452
- constructor(scene, controller) {
1453
- super(scene, controller);
1454
- this.name = "SelectTool";
1455
- }
1456
- Activate() {
1457
- }
1458
- Select(selectable) {
1459
- if (selectable.onSelect) selectable.onSelect();
1460
- this.AttachGizmo(selectable);
1461
- }
1462
- Deselect(selectable) {
1463
- if (selectable.onDeselect) selectable.onDeselect();
1464
- this.DetachGizmo();
1465
- }
1466
- DetachGizmo() {
1467
- this._gizmo.detach();
1468
- }
1469
- AttachGizmo(selectable) {
1470
- if ("isMoveable" in selectable) {
1471
- const movable = selectable;
1472
- this._gizmo.attach(movable);
1473
- }
1474
- }
1475
- onClick(e) {
1476
- super.onClick(e);
1477
- const first = this._raycaster.intersectObjects(this._scene.Root.children, true)[0];
1478
- const selectable = this.findSelectableInterface(first == null ? void 0 : first.object);
1479
- if (!first || !selectable) {
1480
- if (this._gizmo.object) {
1481
- this.Deselect(this._gizmo.object);
1482
- }
1483
- return;
1484
- }
1485
- if (this._gizmo.object) {
1486
- if (this._gizmo.object.uuid === selectable.uuid) return;
1487
- this.Deselect(this._gizmo.object);
1488
- }
1489
- this.Select(selectable);
1490
- }
1491
- findSelectableInterface(child) {
1492
- if (child === void 0) return void 0;
1493
- if (child.parent === null) {
1494
- return void 0;
1495
- }
1496
- if (isSelectable(child)) {
1497
- return child;
1498
- }
1499
- return this.findSelectableInterface(child.parent);
1500
- }
1501
- };
1502
-
1503
- // src/toolbox/Toolbox.ts
1504
- var DIVEToolbox = class {
1505
- constructor(scene, controller) {
1506
- this.removeListenersCallback = () => {
1507
- };
1508
- this.selectTool = new DIVESelectTool(scene, controller);
1509
- const pointerMove = this.onPointerMove.bind(this);
1510
- const pointerDown = this.onPointerDown.bind(this);
1511
- const pointerUp = this.onPointerUp.bind(this);
1512
- const wheel = this.onWheel.bind(this);
1513
- controller.domElement.addEventListener("pointermove", pointerMove);
1514
- controller.domElement.addEventListener("pointerdown", pointerDown);
1515
- controller.domElement.addEventListener("pointerup", pointerUp);
1516
- controller.domElement.addEventListener("wheel", wheel);
1517
- this.removeListenersCallback = () => {
1518
- controller.domElement.removeEventListener("pointermove", pointerMove);
1519
- controller.domElement.removeEventListener("pointerdown", pointerDown);
1520
- controller.domElement.removeEventListener("pointerup", pointerUp);
1521
- controller.domElement.removeEventListener("wheel", wheel);
1522
- };
1523
- this.activeTool = this.selectTool;
1524
- this.activeTool.Activate();
1525
- }
1526
- dispose() {
1527
- this.removeListenersCallback();
1678
+ Dispose() {
1679
+ this.removeEventListeners();
1528
1680
  }
1529
1681
  GetActiveTool() {
1530
- return this.activeTool;
1682
+ return this._activeTool;
1531
1683
  }
1532
1684
  UseTool(tool) {
1533
- this.activeTool.Deactivate();
1685
+ var _a;
1686
+ (_a = this._activeTool) == null ? void 0 : _a.Deactivate();
1534
1687
  switch (tool) {
1535
1688
  case "select": {
1689
+ this.addEventListeners();
1536
1690
  this.selectTool.Activate();
1537
- this.activeTool = this.selectTool;
1691
+ this._activeTool = this.selectTool;
1692
+ break;
1693
+ }
1694
+ case "none": {
1695
+ this.removeEventListeners();
1696
+ this._activeTool = null;
1538
1697
  break;
1539
1698
  }
1540
1699
  default: {
@@ -1545,32 +1704,44 @@ var DIVEToolbox = class {
1545
1704
  SetGizmoMode(mode) {
1546
1705
  this.selectTool.SetGizmoMode(mode);
1547
1706
  }
1707
+ SetGizmoVisibility(active) {
1708
+ this.selectTool.SetGizmoVisibility(active);
1709
+ }
1548
1710
  onPointerMove(e) {
1549
- this.activeTool.onPointerMove(e);
1711
+ var _a;
1712
+ (_a = this._activeTool) == null ? void 0 : _a.onPointerMove(e);
1550
1713
  }
1551
1714
  onPointerDown(e) {
1552
- this.activeTool.onPointerDown(e);
1715
+ var _a;
1716
+ (_a = this._activeTool) == null ? void 0 : _a.onPointerDown(e);
1553
1717
  }
1554
1718
  onPointerUp(e) {
1555
- this.activeTool.onPointerUp(e);
1719
+ var _a;
1720
+ (_a = this._activeTool) == null ? void 0 : _a.onPointerUp(e);
1556
1721
  }
1557
1722
  onWheel(e) {
1558
- this.activeTool.onWheel(e);
1723
+ var _a;
1724
+ (_a = this._activeTool) == null ? void 0 : _a.onWheel(e);
1559
1725
  }
1560
- };
1561
- DIVEToolbox.DefaultTool = "select";
1562
-
1563
- // src/animation/AnimationSystem.ts
1564
- var import_tween2 = require("@tweenjs/tween.js");
1565
- var DIVEAnimationSystem = class {
1566
- update() {
1567
- (0, import_tween2.update)();
1726
+ addEventListeners() {
1727
+ this._controller.domElement.addEventListener("pointermove", (e) => this.onPointerMove(e));
1728
+ this._controller.domElement.addEventListener("pointerdown", (e) => this.onPointerDown(e));
1729
+ this._controller.domElement.addEventListener("pointerup", (e) => this.onPointerUp(e));
1730
+ this._controller.domElement.addEventListener("wheel", (e) => this.onWheel(e));
1731
+ }
1732
+ removeEventListeners() {
1733
+ this._controller.domElement.removeEventListener("pointermove", (e) => this.onPointerMove(e));
1734
+ this._controller.domElement.removeEventListener("pointerdown", (e) => this.onPointerDown(e));
1735
+ this._controller.domElement.removeEventListener("pointerup", (e) => this.onPointerUp(e));
1736
+ this._controller.domElement.removeEventListener("wheel", (e) => this.onWheel(e));
1568
1737
  }
1569
1738
  };
1739
+ DIVEToolbox.DefaultTool = "select";
1570
1740
 
1571
1741
  // src/axiscamera/AxisCamera.ts
1572
- var import_three16 = require("three");
1742
+ var import_three15 = require("three");
1573
1743
  var import_three_spritetext = __toESM(require("three-spritetext"), 1);
1744
+ init_VisibilityLayerMask();
1574
1745
 
1575
1746
  // src/constant/AxisHelperColors.ts
1576
1747
  var AxesColorRedLetter = "#c20017";
@@ -1581,18 +1752,18 @@ var AxesColorGreen = AxesColorGreenLetter;
1581
1752
  var AxesColorBlue = AxesColorBlueLetter;
1582
1753
 
1583
1754
  // src/axiscamera/AxisCamera.ts
1584
- var DIVEAxisCamera = class extends import_three16.OrthographicCamera {
1585
- constructor() {
1755
+ var DIVEAxisCamera = class extends import_three15.OrthographicCamera {
1756
+ constructor(renderer, scene, controls) {
1586
1757
  super(-1, 1, 1, -1, 0.1, 100);
1587
1758
  this.layers.mask = COORDINATE_LAYER_MASK;
1588
- this.axesHelper = new import_three16.AxesHelper(0.5);
1759
+ this.axesHelper = new import_three15.AxesHelper(0.5);
1589
1760
  this.axesHelper.layers.mask = COORDINATE_LAYER_MASK;
1590
1761
  this.axesHelper.material.depthTest = false;
1591
1762
  this.axesHelper.position.set(0, 0, -1);
1592
1763
  this.axesHelper.setColors(
1593
- new import_three16.Color(AxesColorRed),
1594
- new import_three16.Color(AxesColorGreen),
1595
- new import_three16.Color(AxesColorBlue)
1764
+ new import_three15.Color(AxesColorRed),
1765
+ new import_three15.Color(AxesColorGreen),
1766
+ new import_three15.Color(AxesColorBlue)
1596
1767
  );
1597
1768
  const x = new import_three_spritetext.default("X", 0.2, AxesColorRedLetter);
1598
1769
  const y = new import_three_spritetext.default("Y", 0.2, AxesColorGreenLetter);
@@ -1607,9 +1778,29 @@ var DIVEAxisCamera = class extends import_three16.OrthographicCamera {
1607
1778
  this.axesHelper.add(y);
1608
1779
  this.axesHelper.add(z);
1609
1780
  this.add(this.axesHelper);
1781
+ this._renderer = renderer;
1782
+ this._scene = scene;
1783
+ this._scene.add(this);
1784
+ const restoreViewport = new import_three15.Vector4();
1785
+ this._renderCallbackId = renderer.AddPostRenderCallback(() => {
1786
+ const restoreBackground = scene.background;
1787
+ scene.background = null;
1788
+ renderer.getViewport(restoreViewport);
1789
+ renderer.setViewport(0, 0, 150, 150);
1790
+ renderer.autoClear = false;
1791
+ this.SetFromCameraMatrix(controls.object.matrix);
1792
+ renderer.render(scene, this);
1793
+ renderer.setViewport(restoreViewport);
1794
+ renderer.autoClear = true;
1795
+ scene.background = restoreBackground;
1796
+ });
1797
+ }
1798
+ Dispose() {
1799
+ this._renderer.RemovePostRenderCallback(this._renderCallbackId);
1800
+ this._scene.remove(this);
1610
1801
  }
1611
1802
  SetFromCameraMatrix(matrix) {
1612
- this.axesHelper.rotation.setFromRotationMatrix(new import_three16.Matrix4().extractRotation(matrix).invert());
1803
+ this.axesHelper.rotation.setFromRotationMatrix(new import_three15.Matrix4().extractRotation(matrix).invert());
1613
1804
  }
1614
1805
  };
1615
1806
 
@@ -1726,13 +1917,63 @@ var DIVEMath = {
1726
1917
  };
1727
1918
 
1728
1919
  // src/dive.ts
1920
+ var import_MathUtils2 = require("three/src/math/MathUtils");
1729
1921
  var DIVEDefaultSettings = {
1730
1922
  autoResize: true,
1923
+ displayAxes: false,
1731
1924
  renderer: DIVERendererDefaultSettings,
1732
1925
  perspectiveCamera: DIVEPerspectiveCameraDefaultSettings,
1733
1926
  orbitControls: DIVEOrbitControlsDefaultSettings
1734
1927
  };
1735
- var DIVE = class {
1928
+ var DIVE = class _DIVE {
1929
+ // static members
1930
+ static QuickView(uri) {
1931
+ const dive = new _DIVE();
1932
+ dive.Communication.PerformAction("SET_CAMERA_TRANSFORM", {
1933
+ position: { x: 0, y: 2, z: 2 },
1934
+ target: { x: 0, y: 0.5, z: 0 }
1935
+ });
1936
+ const lightid = (0, import_MathUtils2.generateUUID)();
1937
+ dive.Communication.PerformAction("ADD_OBJECT", {
1938
+ entityType: "light",
1939
+ type: "scene",
1940
+ name: "light",
1941
+ id: lightid,
1942
+ enabled: true,
1943
+ visible: true,
1944
+ intensity: 1,
1945
+ color: 16777215
1946
+ });
1947
+ const modelid = (0, import_MathUtils2.generateUUID)();
1948
+ dive.Communication.Subscribe("MODEL_LOADED", (data) => {
1949
+ if (data.id !== modelid) return;
1950
+ dive.Communication.PerformAction("PLACE_ON_FLOOR", {
1951
+ id: modelid
1952
+ });
1953
+ const transform = dive.Communication.PerformAction("COMPUTE_ENCOMPASSING_VIEW", {});
1954
+ dive.Communication.PerformAction("SET_CAMERA_TRANSFORM", {
1955
+ position: transform.position,
1956
+ target: transform.target
1957
+ });
1958
+ });
1959
+ dive.Communication.PerformAction("ADD_OBJECT", {
1960
+ entityType: "model",
1961
+ name: "object",
1962
+ id: modelid,
1963
+ position: { x: 0, y: 0, z: 0 },
1964
+ rotation: { x: 0, y: 0, z: 0 },
1965
+ scale: { x: 1, y: 1, z: 1 },
1966
+ uri,
1967
+ visible: true,
1968
+ loaded: false
1969
+ });
1970
+ dive.Communication.PerformAction("UPDATE_SCENE", {
1971
+ backgroundColor: 16777215,
1972
+ gridEnabled: false,
1973
+ floorColor: 16777215
1974
+ });
1975
+ return dive;
1976
+ }
1736
1977
  // getters
1737
1978
  get Communication() {
1738
1979
  return this.communication;
@@ -1742,6 +1983,7 @@ var DIVE = class {
1742
1983
  }
1743
1984
  // setters
1744
1985
  set Settings(settings) {
1986
+ var _a;
1745
1987
  const settingsDelta = getObjectDelta(this._settings, settings);
1746
1988
  if (settingsDelta.renderer) this.renderer = new DIVERenderer(this._settings.renderer);
1747
1989
  if (settingsDelta.perspectiveCamera) {
@@ -1761,6 +2003,12 @@ var DIVE = class {
1761
2003
  this.removeResizeObserver();
1762
2004
  }
1763
2005
  }
2006
+ if (settingsDelta.displayAxes) {
2007
+ this.axisCamera = new DIVEAxisCamera(this.renderer, this.scene, this.orbitControls);
2008
+ } else {
2009
+ (_a = this.axisCamera) == null ? void 0 : _a.Dispose();
2010
+ this.axisCamera = null;
2011
+ }
1764
2012
  Object.assign(this._settings, settings);
1765
2013
  }
1766
2014
  constructor(settings) {
@@ -1772,28 +2020,14 @@ var DIVE = class {
1772
2020
  this.scene = new DIVEScene();
1773
2021
  this.perspectiveCamera = new DIVEPerspectiveCamera(this._settings.perspectiveCamera);
1774
2022
  this.orbitControls = new DIVEOrbitControls(this.perspectiveCamera, this.renderer, this._settings.orbitControls);
1775
- this.mediaCreator = new DIVEMediaCreator(this.renderer, this.scene, this.orbitControls);
1776
2023
  this.toolbox = new DIVEToolbox(this.scene, this.orbitControls);
1777
- this.communication = new DIVECommunication(this.scene, this.orbitControls, this.toolbox, this.mediaCreator);
1778
- this.animationSystem = new DIVEAnimationSystem();
1779
- this.renderer.AddPreRenderCallback(() => {
1780
- this.animationSystem.update();
1781
- });
1782
- this.axisCamera = new DIVEAxisCamera();
1783
- this.scene.add(this.axisCamera);
1784
- const restoreViewport = new import_three17.Vector4();
1785
- this.renderer.AddPostRenderCallback(() => {
1786
- const restoreBackground = this.scene.background;
1787
- this.scene.background = null;
1788
- this.renderer.getViewport(restoreViewport);
1789
- this.renderer.setViewport(0, 0, 150, 150);
1790
- this.renderer.autoClear = false;
1791
- this.axisCamera.SetFromCameraMatrix(this.perspectiveCamera.matrix);
1792
- this.renderer.render(this.scene, this.axisCamera);
1793
- this.renderer.setViewport(restoreViewport);
1794
- this.renderer.autoClear = true;
1795
- this.scene.background = restoreBackground;
1796
- });
2024
+ this.communication = new DIVECommunication(this.renderer, this.scene, this.orbitControls, this.toolbox);
2025
+ this.animationSystem = null;
2026
+ if (this._settings.displayAxes) {
2027
+ this.axisCamera = new DIVEAxisCamera(this.renderer, this.scene, this.orbitControls);
2028
+ } else {
2029
+ this.axisCamera = null;
2030
+ }
1797
2031
  if (this._settings.autoResize) {
1798
2032
  this.addResizeObserver();
1799
2033
  }
@@ -1804,6 +2038,14 @@ var DIVE = class {
1804
2038
  }
1805
2039
  };
1806
2040
  }
2041
+ Dispose() {
2042
+ var _a;
2043
+ this.removeResizeObserver();
2044
+ this.renderer.Dispose();
2045
+ (_a = this.axisCamera) == null ? void 0 : _a.Dispose();
2046
+ this.toolbox.Dispose();
2047
+ this.communication.DestroyInstance();
2048
+ }
1807
2049
  // methods
1808
2050
  OnResize(width, height) {
1809
2051
  this.renderer.OnResize(width, height);