@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.d.cts 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
  };
@@ -376,6 +321,19 @@ interface DROP_IT {
376
321
  'RETURN': boolean;
377
322
  }
378
323
 
324
+ interface SET_GIZMO_VISIBILITY {
325
+ 'PAYLOAD': boolean;
326
+ 'RETURN': boolean;
327
+ }
328
+
329
+ interface COMPUTE_ENCOMPASSING_VIEW {
330
+ 'PAYLOAD': object;
331
+ 'RETURN': {
332
+ position: Vector3Like;
333
+ target: Vector3Like;
334
+ };
335
+ }
336
+
379
337
  type Actions = {
380
338
  GET_ALL_SCENE_DATA: GET_ALL_SCENE_DATA;
381
339
  GET_ALL_OBJECTS: GET_ALL_OBJECTS;
@@ -392,14 +350,81 @@ type Actions = {
392
350
  GET_CAMERA_TRANSFORM: GET_CAMERA_TRANSFORM;
393
351
  MOVE_CAMERA: MOVE_CAMERA;
394
352
  RESET_CAMERA: RESET_CAMERA;
353
+ COMPUTE_ENCOMPASSING_VIEW: COMPUTE_ENCOMPASSING_VIEW;
395
354
  SET_CAMERA_LAYER: SET_CAMERA_LAYER;
396
355
  ZOOM_CAMERA: ZOOM_CAMERA;
397
356
  SET_GIZMO_MODE: SET_GIZMO_MODE;
357
+ SET_GIZMO_VISIBILITY: SET_GIZMO_VISIBILITY;
398
358
  MODEL_LOADED: MODEL_LOADED;
399
359
  UPDATE_SCENE: UPDATE_SCENE;
400
360
  GENERATE_MEDIA: GENERATE_MEDIA;
401
361
  };
402
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
+
403
428
  interface DIVEDraggable {
404
429
  isDraggable: true;
405
430
  onDragStart?: (e: DraggableEvent) => void;
@@ -458,6 +483,53 @@ declare abstract class DIVEBaseTool {
458
483
  private pointerWasDragged;
459
484
  }
460
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';
461
533
  /**
462
534
  * A Toolbox to activate and deactivate tools to use with the pointer.
463
535
  *
@@ -465,32 +537,23 @@ declare abstract class DIVEBaseTool {
465
537
  */
466
538
  declare class DIVEToolbox {
467
539
  static readonly DefaultTool = "select";
468
- private activeTool;
469
- private selectTool;
470
- private removeListenersCallback;
540
+ private _scene;
541
+ private _controller;
542
+ private _activeTool;
543
+ private _selectTool;
544
+ get selectTool(): DIVESelectTool;
471
545
  constructor(scene: DIVEScene, controller: DIVEOrbitControls);
472
- dispose(): void;
473
- GetActiveTool(): DIVEBaseTool;
474
- UseTool(tool: string): void;
546
+ Dispose(): void;
547
+ GetActiveTool(): DIVEBaseTool | null;
548
+ UseTool(tool: ToolType): void;
475
549
  SetGizmoMode(mode: 'translate' | 'rotate' | 'scale'): void;
550
+ SetGizmoVisibility(active: boolean): void;
476
551
  onPointerMove(e: PointerEvent): void;
477
552
  onPointerDown(e: PointerEvent): void;
478
553
  onPointerUp(e: PointerEvent): void;
479
554
  onWheel(e: WheelEvent): void;
480
- }
481
-
482
- /**
483
- * Creates renderings of the current scene
484
- *
485
- * @module
486
- */
487
- declare class DIVEMediaCreator {
488
- private renderer;
489
- private scene;
490
- private controller;
491
- constructor(renderer: DIVERenderer, scene: DIVEScene, controller: DIVEOrbitControls);
492
- GenerateMedia(position: Vector3Like, target: Vector3Like, width: number, height: number): string;
493
- DrawCanvas(canvasElement?: HTMLCanvasElement): HTMLCanvasElement;
555
+ private addEventListeners;
556
+ private removeEventListeners;
494
557
  }
495
558
 
496
559
  type EventListener<Action extends keyof Actions> = (payload: Actions[Action]['PAYLOAD']) => void;
@@ -518,13 +581,15 @@ declare class DIVECommunication {
518
581
  private static __instances;
519
582
  static get(id: string): DIVECommunication | undefined;
520
583
  private id;
584
+ private renderer;
521
585
  private scene;
522
586
  private controller;
523
587
  private toolbox;
524
- private mediaGenerator;
588
+ private _mediaGenerator;
589
+ private get mediaGenerator();
525
590
  private registered;
526
591
  private listeners;
527
- constructor(scene: DIVEScene, controls: DIVEOrbitControls, toolbox: DIVEToolbox, mediaGenerator: DIVEMediaCreator);
592
+ constructor(renderer: DIVERenderer, scene: DIVEScene, controls: DIVEOrbitControls, toolbox: DIVEToolbox);
528
593
  DestroyInstance(): boolean;
529
594
  PerformAction<Action extends keyof Actions>(action: Action, payload: Actions[Action]['PAYLOAD']): Actions[Action]['RETURN'];
530
595
  Subscribe<Action extends keyof Actions>(type: Action, listener: EventListener<Action>): Unsubscribe;
@@ -545,8 +610,10 @@ declare class DIVECommunication {
545
610
  private moveCamera;
546
611
  private setCameraLayer;
547
612
  private resetCamera;
613
+ private computeEncompassingView;
548
614
  private zoomCamera;
549
615
  private setGizmoMode;
616
+ private setGizmoVisibility;
550
617
  private modelLoaded;
551
618
  private updateScene;
552
619
  private generateMedia;
@@ -582,6 +649,7 @@ declare const DIVEMath: {
582
649
 
583
650
  type DIVESettings = {
584
651
  autoResize: boolean;
652
+ displayAxes: boolean;
585
653
  renderer: DIVERendererSettings;
586
654
  perspectiveCamera: DIVEPerspectiveCameraSettings;
587
655
  orbitControls: DIVEOrbitControlsSettings;
@@ -610,6 +678,7 @@ declare const DIVEDefaultSettings: DIVESettings;
610
678
  * @module
611
679
  */
612
680
  declare class DIVE {
681
+ static QuickView(uri: string): DIVE;
613
682
  private _settings;
614
683
  private _resizeObserverId;
615
684
  private _width;
@@ -618,7 +687,6 @@ declare class DIVE {
618
687
  private scene;
619
688
  private perspectiveCamera;
620
689
  private orbitControls;
621
- private mediaCreator;
622
690
  private toolbox;
623
691
  private communication;
624
692
  private animationSystem;
@@ -627,6 +695,7 @@ declare class DIVE {
627
695
  get Canvas(): HTMLCanvasElement;
628
696
  set Settings(settings: Partial<DIVESettings>);
629
697
  constructor(settings?: Partial<DIVESettings>);
698
+ Dispose(): void;
630
699
  OnResize(width: number, height: number): void;
631
700
  private addResizeObserver;
632
701
  private removeResizeObserver;