@shopware-ag/dive 1.5.0 → 1.6.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 (43) hide show
  1. package/README.md +38 -25
  2. package/build/dive.cjs +717 -500
  3. package/build/dive.cjs.map +1 -1
  4. package/build/dive.d.cts +174 -113
  5. package/build/dive.d.ts +174 -113
  6. package/build/dive.js +716 -486
  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 +50 -16
  15. package/src/com/__test__/Communication.test.ts +73 -24
  16. package/src/com/actions/camera/computeencompassingview.ts +9 -0
  17. package/src/com/actions/index.ts +2 -0
  18. package/src/com/actions/scene/updatescene.ts +1 -0
  19. package/src/controls/OrbitControls.ts +14 -2
  20. package/src/controls/__test__/OrbitControls.test.ts +31 -4
  21. package/src/dive.ts +93 -33
  22. package/src/grid/Grid.ts +4 -0
  23. package/src/grid/__test__/Grid.test.ts +7 -0
  24. package/src/interface/Selectable.ts +17 -0
  25. package/src/interface/__test__/Interfaces.test.ts +18 -0
  26. package/src/mediacreator/MediaCreator.ts +2 -2
  27. package/src/mediacreator/__test__/MediaCreator.test.ts +12 -10
  28. package/src/model/Model.ts +1 -1
  29. package/src/model/__test__/Model.test.ts +8 -1
  30. package/src/renderer/Renderer.ts +7 -1
  31. package/src/renderer/__test__/Renderer.test.ts +14 -5
  32. package/src/scene/Scene.ts +8 -2
  33. package/src/scene/__test__/Scene.test.ts +6 -0
  34. package/src/scene/root/Root.ts +11 -1
  35. package/src/scene/root/__test__/Root.test.ts +68 -2
  36. package/src/toolbox/BaseTool.ts +1 -1
  37. package/src/toolbox/Toolbox.ts +53 -37
  38. package/src/toolbox/__test__/BaseTool.test.ts +43 -7
  39. package/src/toolbox/__test__/Toolbox.test.ts +39 -44
  40. package/src/toolbox/select/SelectTool.ts +17 -28
  41. package/src/toolbox/select/__test__/SelectTool.test.ts +21 -12
  42. package/src/toolbox/transform/TransformTool.ts +7 -1
  43. package/src/toolbox/transform/__test__/TransformTool.test.ts +22 -5
package/build/dive.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Vector3Like, Mesh, ColorRepresentation, Object3D, Intersection, Vector2, Raycaster, Vector3 } from 'three';
1
+ import { ShadowMapType, ToneMapping, WebGLRenderer, Scene, Camera, PerspectiveCamera, Box3, Vector3Like, Mesh, ColorRepresentation, Object3D, Intersection, Vector2, Raycaster, Vector3 } from 'three';
2
2
  import { OrbitControls } from 'three/examples/jsm/Addons.js';
3
+ import { TransformControls } from 'three/examples/jsm/Addons';
3
4
 
4
5
  type DIVERendererSettings = {
5
6
  antialias: boolean;
@@ -23,6 +24,7 @@ declare class DIVERenderer extends WebGLRenderer {
23
24
  private preRenderCallbacks;
24
25
  private postRenderCallbacks;
25
26
  constructor(rendererSettings?: DIVERendererSettings);
27
+ Dispose(): void;
26
28
  StartRenderer(scene: Scene, cam: Camera): void;
27
29
  PauseRenderer(): void;
28
30
  ResumeRenderer(): void;
@@ -104,6 +106,10 @@ declare class DIVEOrbitControls extends OrbitControls {
104
106
  object: DIVEPerspectiveCamera;
105
107
  domElement: HTMLCanvasElement;
106
108
  constructor(camera: DIVEPerspectiveCamera, renderer: DIVERenderer, settings?: DIVEOrbitControlsSettings);
109
+ ComputeEncompassingView(bb: Box3): {
110
+ position: Vector3Like;
111
+ target: Vector3Like;
112
+ };
107
113
  ZoomIn(by?: number): void;
108
114
  ZoomOut(by?: number): void;
109
115
  MoveTo(pos: Vector3Like | undefined, target: Vector3Like | undefined, duration: number, lock: boolean): void;
@@ -111,95 +117,6 @@ declare class DIVEOrbitControls extends OrbitControls {
111
117
  private preRenderCallback;
112
118
  }
113
119
 
114
- type COMBaseEntity = {
115
- id: string;
116
- name: string;
117
- entityType: 'pov' | 'light' | 'model';
118
- visible: boolean;
119
- };
120
- type COMPov = COMBaseEntity & {
121
- position: Vector3Like;
122
- target: Vector3Like;
123
- locked?: boolean;
124
- };
125
- type COMLight = COMBaseEntity & {
126
- type: 'ambient' | 'point' | 'scene';
127
- intensity: number;
128
- color: string | number;
129
- enabled: boolean;
130
- position?: Vector3Like;
131
- };
132
- type COMModel = COMBaseEntity & {
133
- uri: string;
134
- position: Vector3Like;
135
- rotation: Vector3Like;
136
- scale: Vector3Like;
137
- loaded: boolean;
138
- };
139
- type COMEntity = COMPov | COMLight | COMModel;
140
-
141
- /**
142
- * A basic floor geometry.
143
- *
144
- * Can change the color and visibility of the floor.
145
- *
146
- * @module
147
- */
148
- declare class DIVEFloor extends Mesh {
149
- isFloor: true;
150
- constructor();
151
- SetVisibility(visible: boolean): void;
152
- SetColor(color: ColorRepresentation): void;
153
- }
154
-
155
- /**
156
- * A basic grid for the scene.
157
- *
158
- * @module
159
- */
160
- declare class DIVEGrid extends Object3D {
161
- constructor();
162
- }
163
-
164
- /**
165
- * A basic scene node to hold grid, floor and all lower level roots.
166
- *
167
- * @module
168
- */
169
- declare class DIVERoot extends Object3D {
170
- private lightRoot;
171
- private modelRoot;
172
- private floor;
173
- private grid;
174
- get Floor(): DIVEFloor;
175
- get Grid(): DIVEGrid;
176
- constructor();
177
- GetSceneObject(object: Partial<COMEntity>): Object3D | undefined;
178
- AddSceneObject(object: COMEntity): void;
179
- UpdateSceneObject(object: Partial<COMEntity>): void;
180
- DeleteSceneObject(object: Partial<COMEntity>): void;
181
- PlaceOnFloor(object: Partial<COMModel>): void;
182
- }
183
-
184
- /**
185
- * A basic scene class.
186
- *
187
- * Comes with a root object that contains all the scene objects.
188
- *
189
- * @module
190
- */
191
- declare class DIVEScene extends Scene {
192
- private root;
193
- get Root(): DIVERoot;
194
- constructor();
195
- SetBackground(color: ColorRepresentation): void;
196
- GetSceneObject(object: Partial<COMEntity>): Object3D | undefined;
197
- AddSceneObject(object: COMEntity): void;
198
- UpdateSceneObject(object: Partial<COMEntity>): void;
199
- DeleteSceneObject(object: Partial<COMEntity>): void;
200
- PlaceOnFloor(object: Partial<COMModel>): void;
201
- }
202
-
203
120
  interface SET_BACKGROUND {
204
121
  'PAYLOAD': {
205
122
  color: string | number;
@@ -265,6 +182,33 @@ interface PLACE_ON_FLOOR {
265
182
  'RETURN': boolean;
266
183
  }
267
184
 
185
+ type COMBaseEntity = {
186
+ id: string;
187
+ name: string;
188
+ entityType: 'pov' | 'light' | 'model';
189
+ visible: boolean;
190
+ };
191
+ type COMPov = COMBaseEntity & {
192
+ position: Vector3Like;
193
+ target: Vector3Like;
194
+ locked?: boolean;
195
+ };
196
+ type COMLight = COMBaseEntity & {
197
+ type: 'ambient' | 'point' | 'scene';
198
+ intensity: number;
199
+ color: string | number;
200
+ enabled: boolean;
201
+ position?: Vector3Like;
202
+ };
203
+ type COMModel = COMBaseEntity & {
204
+ uri: string;
205
+ position: Vector3Like;
206
+ rotation: Vector3Like;
207
+ scale: Vector3Like;
208
+ loaded: boolean;
209
+ };
210
+ type COMEntity = COMPov | COMLight | COMModel;
211
+
268
212
  interface GET_ALL_OBJECTS {
269
213
  'PAYLOAD': Map<string, COMEntity>;
270
214
  'RETURN': Map<string, COMEntity>;
@@ -307,6 +251,7 @@ interface UPDATE_SCENE {
307
251
  'PAYLOAD': {
308
252
  name?: string;
309
253
  backgroundColor?: string | number;
254
+ gridEnabled?: boolean;
310
255
  floorEnabled?: boolean;
311
256
  floorColor?: string | number;
312
257
  };
@@ -381,6 +326,14 @@ interface SET_GIZMO_VISIBILITY {
381
326
  'RETURN': boolean;
382
327
  }
383
328
 
329
+ interface COMPUTE_ENCOMPASSING_VIEW {
330
+ 'PAYLOAD': object;
331
+ 'RETURN': {
332
+ position: Vector3Like;
333
+ target: Vector3Like;
334
+ };
335
+ }
336
+
384
337
  type Actions = {
385
338
  GET_ALL_SCENE_DATA: GET_ALL_SCENE_DATA;
386
339
  GET_ALL_OBJECTS: GET_ALL_OBJECTS;
@@ -397,6 +350,7 @@ type Actions = {
397
350
  GET_CAMERA_TRANSFORM: GET_CAMERA_TRANSFORM;
398
351
  MOVE_CAMERA: MOVE_CAMERA;
399
352
  RESET_CAMERA: RESET_CAMERA;
353
+ COMPUTE_ENCOMPASSING_VIEW: COMPUTE_ENCOMPASSING_VIEW;
400
354
  SET_CAMERA_LAYER: SET_CAMERA_LAYER;
401
355
  ZOOM_CAMERA: ZOOM_CAMERA;
402
356
  SET_GIZMO_MODE: SET_GIZMO_MODE;
@@ -406,6 +360,71 @@ type Actions = {
406
360
  GENERATE_MEDIA: GENERATE_MEDIA;
407
361
  };
408
362
 
363
+ /**
364
+ * A basic floor geometry.
365
+ *
366
+ * Can change the color and visibility of the floor.
367
+ *
368
+ * @module
369
+ */
370
+ declare class DIVEFloor extends Mesh {
371
+ isFloor: true;
372
+ constructor();
373
+ SetVisibility(visible: boolean): void;
374
+ SetColor(color: ColorRepresentation): void;
375
+ }
376
+
377
+ /**
378
+ * A basic grid for the scene.
379
+ *
380
+ * @module
381
+ */
382
+ declare class DIVEGrid extends Object3D {
383
+ constructor();
384
+ SetVisibility(visible: boolean): void;
385
+ }
386
+
387
+ /**
388
+ * A basic scene node to hold grid, floor and all lower level roots.
389
+ *
390
+ * @module
391
+ */
392
+ declare class DIVERoot extends Object3D {
393
+ private lightRoot;
394
+ private modelRoot;
395
+ private floor;
396
+ private grid;
397
+ get Floor(): DIVEFloor;
398
+ get Grid(): DIVEGrid;
399
+ constructor();
400
+ ComputeSceneBB(): Box3;
401
+ GetSceneObject(object: Partial<COMEntity>): Object3D | undefined;
402
+ AddSceneObject(object: COMEntity): void;
403
+ UpdateSceneObject(object: Partial<COMEntity>): void;
404
+ DeleteSceneObject(object: Partial<COMEntity>): void;
405
+ PlaceOnFloor(object: Partial<COMModel>): void;
406
+ }
407
+
408
+ /**
409
+ * A basic scene class.
410
+ *
411
+ * Comes with a root object that contains all the scene objects.
412
+ *
413
+ * @module
414
+ */
415
+ declare class DIVEScene extends Scene {
416
+ private root;
417
+ get Root(): DIVERoot;
418
+ constructor();
419
+ SetBackground(color: ColorRepresentation): void;
420
+ ComputeSceneBB(): Box3;
421
+ GetSceneObject(object: Partial<COMEntity>): Object3D | undefined;
422
+ AddSceneObject(object: COMEntity): void;
423
+ UpdateSceneObject(object: Partial<COMEntity>): void;
424
+ DeleteSceneObject(object: Partial<COMEntity>): void;
425
+ PlaceOnFloor(object: Partial<COMModel>): void;
426
+ }
427
+
409
428
  interface DIVEDraggable {
410
429
  isDraggable: true;
411
430
  onDragStart?: (e: DraggableEvent) => void;
@@ -464,6 +483,53 @@ declare abstract class DIVEBaseTool {
464
483
  private pointerWasDragged;
465
484
  }
466
485
 
486
+ /**
487
+ * A Tool to select and move objects in the scene.
488
+ *
489
+ * Objects have to implement the DIVESelectable interface to be selectable and DIVEMoveable to be moveable.
490
+ *
491
+ * @module
492
+ */
493
+ declare class DIVETransformTool extends DIVEBaseTool {
494
+ readonly isTransformTool: boolean;
495
+ protected _gizmo: TransformControls;
496
+ constructor(scene: DIVEScene, controller: DIVEOrbitControls);
497
+ Activate(): void;
498
+ SetGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void;
499
+ SetGizmoVisibility(active: boolean): void;
500
+ }
501
+
502
+ /**
503
+ * Interface for objects that can be selected in the scene.
504
+ *
505
+ * @module
506
+ */
507
+
508
+ interface DIVESelectable {
509
+ isSelectable: true;
510
+ onSelect?: () => void;
511
+ onDeselect?: () => void;
512
+ }
513
+
514
+ /**
515
+ * A Tool to select and move objects in the scene.
516
+ *
517
+ * Objects have to implement the DIVESelectable interface to be selectable and DIVEMoveable to be moveable.
518
+ *
519
+ * @module
520
+ */
521
+ declare class DIVESelectTool extends DIVETransformTool {
522
+ readonly isSelectTool: boolean;
523
+ constructor(scene: DIVEScene, controller: DIVEOrbitControls);
524
+ Activate(): void;
525
+ Select(selectable: DIVESelectable): void;
526
+ Deselect(selectable: DIVESelectable): void;
527
+ AttachGizmo(selectable: DIVESelectable): void;
528
+ DetachGizmo(): void;
529
+ onClick(e: PointerEvent): void;
530
+ }
531
+
532
+ type ToolType = 'select' | 'none';
467
533
  /**
468
534
  * A Toolbox to activate and deactivate tools to use with the pointer.
469
535
  *
@@ -471,33 +537,23 @@ declare abstract class DIVEBaseTool {
471
537
  */
472
538
  declare class DIVEToolbox {
473
539
  static readonly DefaultTool = "select";
474
- private activeTool;
475
- private selectTool;
476
- private removeListenersCallback;
540
+ private _scene;
541
+ private _controller;
542
+ private _activeTool;
543
+ private _selectTool;
544
+ get selectTool(): DIVESelectTool;
477
545
  constructor(scene: DIVEScene, controller: DIVEOrbitControls);
478
- dispose(): void;
479
- GetActiveTool(): DIVEBaseTool;
480
- UseTool(tool: string): void;
546
+ Dispose(): void;
547
+ GetActiveTool(): DIVEBaseTool | null;
548
+ UseTool(tool: ToolType): void;
481
549
  SetGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void;
482
550
  SetGizmoVisibility(active: boolean): void;
483
551
  onPointerMove(e: PointerEvent): void;
484
552
  onPointerDown(e: PointerEvent): void;
485
553
  onPointerUp(e: PointerEvent): void;
486
554
  onWheel(e: WheelEvent): void;
487
- }
488
-
489
- /**
490
- * Creates renderings of the current scene
491
- *
492
- * @module
493
- */
494
- declare class DIVEMediaCreator {
495
- private renderer;
496
- private scene;
497
- private controller;
498
- constructor(renderer: DIVERenderer, scene: DIVEScene, controller: DIVEOrbitControls);
499
- GenerateMedia(position: Vector3Like, target: Vector3Like, width: number, height: number): string;
500
- DrawCanvas(canvasElement?: HTMLCanvasElement): HTMLCanvasElement;
555
+ private addEventListeners;
556
+ private removeEventListeners;
501
557
  }
502
558
 
503
559
  type EventListener<Action extends keyof Actions> = (payload: Actions[Action]['PAYLOAD']) => void;
@@ -525,13 +581,15 @@ declare class DIVECommunication {
525
581
  private static __instances;
526
582
  static get(id: string): DIVECommunication | undefined;
527
583
  private id;
584
+ private renderer;
528
585
  private scene;
529
586
  private controller;
530
587
  private toolbox;
531
- private mediaGenerator;
588
+ private _mediaGenerator;
589
+ private get mediaGenerator();
532
590
  private registered;
533
591
  private listeners;
534
- constructor(scene: DIVEScene, controls: DIVEOrbitControls, toolbox: DIVEToolbox, mediaGenerator: DIVEMediaCreator);
592
+ constructor(renderer: DIVERenderer, scene: DIVEScene, controls: DIVEOrbitControls, toolbox: DIVEToolbox);
535
593
  DestroyInstance(): boolean;
536
594
  PerformAction<Action extends keyof Actions>(action: Action, payload: Actions[Action]['PAYLOAD']): Actions[Action]['RETURN'];
537
595
  Subscribe<Action extends keyof Actions>(type: Action, listener: EventListener<Action>): Unsubscribe;
@@ -552,6 +610,7 @@ declare class DIVECommunication {
552
610
  private moveCamera;
553
611
  private setCameraLayer;
554
612
  private resetCamera;
613
+ private computeEncompassingView;
555
614
  private zoomCamera;
556
615
  private setGizmoMode;
557
616
  private setGizmoVisibility;
@@ -590,6 +649,7 @@ declare const DIVEMath: {
590
649
 
591
650
  type DIVESettings = {
592
651
  autoResize: boolean;
652
+ displayAxes: boolean;
593
653
  renderer: DIVERendererSettings;
594
654
  perspectiveCamera: DIVEPerspectiveCameraSettings;
595
655
  orbitControls: DIVEOrbitControlsSettings;
@@ -618,6 +678,7 @@ declare const DIVEDefaultSettings: DIVESettings;
618
678
  * @module
619
679
  */
620
680
  declare class DIVE {
681
+ static QuickView(uri: string): DIVE;
621
682
  private _settings;
622
683
  private _resizeObserverId;
623
684
  private _width;
@@ -626,7 +687,6 @@ declare class DIVE {
626
687
  private scene;
627
688
  private perspectiveCamera;
628
689
  private orbitControls;
629
- private mediaCreator;
630
690
  private toolbox;
631
691
  private communication;
632
692
  private animationSystem;
@@ -635,6 +695,7 @@ declare class DIVE {
635
695
  get Canvas(): HTMLCanvasElement;
636
696
  set Settings(settings: Partial<DIVESettings>);
637
697
  constructor(settings?: Partial<DIVESettings>);
698
+ Dispose(): void;
638
699
  OnResize(width: number, height: number): void;
639
700
  private addResizeObserver;
640
701
  private removeResizeObserver;