@inweb/viewer-three 25.9.8 → 25.10.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 (109) hide show
  1. package/README.md +26 -18
  2. package/dist/viewer-three.js +10315 -6179
  3. package/dist/viewer-three.js.map +1 -1
  4. package/dist/viewer-three.min.js +3 -2
  5. package/dist/viewer-three.module.js +1881 -322
  6. package/dist/viewer-three.module.js.map +1 -1
  7. package/lib/Viewer/IDisposable.d.ts +6 -0
  8. package/lib/Viewer/Viewer.d.ts +113 -14
  9. package/lib/Viewer/commands/ApplyModelTransform.d.ts +1 -0
  10. package/lib/Viewer/commands/ClearMarkup.d.ts +1 -0
  11. package/lib/Viewer/commands/ClearSlices.d.ts +1 -0
  12. package/lib/Viewer/commands/CreatePreview.d.ts +1 -0
  13. package/lib/Viewer/commands/Explode.d.ts +1 -0
  14. package/lib/Viewer/commands/GetDefaultViewPositions.d.ts +1 -0
  15. package/lib/Viewer/commands/GetModels.d.ts +1 -0
  16. package/lib/Viewer/commands/GetSelected.d.ts +1 -0
  17. package/lib/Viewer/commands/HideSelected.d.ts +1 -0
  18. package/lib/Viewer/commands/IsolateSelected.d.ts +1 -0
  19. package/lib/Viewer/commands/RegenerateAll.d.ts +1 -0
  20. package/lib/Viewer/commands/ResetView.d.ts +1 -0
  21. package/lib/Viewer/commands/SelectModel.d.ts +1 -0
  22. package/lib/Viewer/commands/SetActiveDragger.d.ts +1 -0
  23. package/lib/Viewer/commands/SetDefaultViewPosition.d.ts +13 -0
  24. package/lib/Viewer/commands/SetMarkupColor.d.ts +1 -0
  25. package/lib/Viewer/commands/SetSelected.d.ts +1 -0
  26. package/lib/Viewer/commands/ShowAll.d.ts +1 -0
  27. package/lib/Viewer/commands/Unselect.d.ts +1 -0
  28. package/lib/Viewer/commands/ZoomToExtents.d.ts +1 -0
  29. package/lib/Viewer/commands/ZoomToObjects.d.ts +1 -0
  30. package/lib/Viewer/commands/ZoomToSelected.d.ts +1 -0
  31. package/lib/Viewer/commands/index.d.ts +22 -0
  32. package/lib/Viewer/components/AxesHelperComponent.d.ts +10 -0
  33. package/lib/Viewer/components/BackgroundComponent.d.ts +4 -4
  34. package/lib/Viewer/components/{DefaultCameraPositionComponent.d.ts → DefaultPositionComponent.d.ts} +3 -2
  35. package/lib/Viewer/components/ExtentsComponent.d.ts +8 -0
  36. package/lib/Viewer/components/ExtentsHelperComponent.d.ts +9 -0
  37. package/lib/Viewer/components/LightComponent.d.ts +5 -5
  38. package/lib/Viewer/components/RenderLoopComponent.d.ts +3 -3
  39. package/lib/Viewer/components/ResizeCanvasComponent.d.ts +2 -2
  40. package/lib/Viewer/components/SelectionComponent.d.ts +19 -0
  41. package/lib/Viewer/components/ViewPositionComponent.d.ts +31 -0
  42. package/lib/Viewer/components/WCSHelperComponent.d.ts +9 -0
  43. package/lib/Viewer/controls/WalkControls.d.ts +26 -0
  44. package/lib/Viewer/draggers/CuttingPlaneDragger.d.ts +17 -0
  45. package/lib/Viewer/draggers/CuttingPlaneXAxis.d.ts +5 -0
  46. package/lib/Viewer/draggers/CuttingPlaneYAxis.d.ts +5 -0
  47. package/lib/Viewer/draggers/CuttingPlaneZAxis.d.ts +5 -0
  48. package/lib/Viewer/draggers/OrbitDragger.d.ts +9 -5
  49. package/lib/Viewer/draggers/WalkDragger.d.ts +7 -33
  50. package/lib/Viewer/helpers/PlaneHelper.d.ts +11 -0
  51. package/lib/Viewer/helpers/WCSHelper.d.ts +10 -0
  52. package/lib/Viewer/loaders/GLTFLoadingManager.d.ts +3 -3
  53. package/lib/index.d.ts +1 -0
  54. package/package.json +7 -6
  55. package/src/Viewer/IDisposable.ts +29 -0
  56. package/src/Viewer/Viewer.ts +218 -49
  57. package/src/Viewer/commands/ApplyModelTransform.ts +33 -0
  58. package/src/Viewer/commands/ClearMarkup.ts +29 -0
  59. package/src/Viewer/commands/ClearSlices.ts +32 -0
  60. package/src/Viewer/commands/CreatePreview.ts +32 -0
  61. package/src/Viewer/commands/Explode.ts +83 -0
  62. package/src/Viewer/commands/GetDefaultViewPositions.ts +31 -0
  63. package/src/Viewer/commands/GetModels.ts +32 -0
  64. package/src/Viewer/commands/GetSelected.ts +31 -0
  65. package/src/Viewer/commands/HideSelected.ts +40 -0
  66. package/src/Viewer/commands/IsolateSelected.ts +50 -0
  67. package/src/Viewer/commands/RegenerateAll.ts +32 -0
  68. package/src/Viewer/commands/ResetView.ts +41 -0
  69. package/src/Viewer/commands/SelectModel.ts +32 -0
  70. package/src/Viewer/commands/SetActiveDragger.ts +29 -0
  71. package/src/Viewer/commands/SetDefaultViewPosition.ts +83 -0
  72. package/src/Viewer/commands/SetMarkupColor.ts +30 -0
  73. package/src/Viewer/commands/SetSelected.ts +44 -0
  74. package/src/Viewer/commands/ShowAll.ts +34 -0
  75. package/src/Viewer/commands/Unselect.ts +37 -0
  76. package/src/Viewer/commands/ZoomToExtents.ts +47 -0
  77. package/src/Viewer/commands/ZoomToObjects.ts +55 -0
  78. package/src/Viewer/commands/ZoomToSelected.ts +51 -0
  79. package/src/Viewer/commands/index.ts +45 -0
  80. package/src/Viewer/components/AxesHelperComponent.ts +70 -0
  81. package/src/Viewer/components/BackgroundComponent.ts +9 -7
  82. package/src/Viewer/components/{DefaultCameraPositionComponent.ts → DefaultPositionComponent.ts} +11 -22
  83. package/src/Viewer/components/ExtentsComponent.ts +54 -0
  84. package/src/Viewer/components/ExtentsHelperComponent.ts +58 -0
  85. package/src/Viewer/components/LightComponent.ts +14 -10
  86. package/src/Viewer/components/RenderLoopComponent.ts +6 -6
  87. package/src/Viewer/components/ResizeCanvasComponent.ts +2 -2
  88. package/src/Viewer/components/SelectionComponent.ts +132 -0
  89. package/src/Viewer/components/ViewPositionComponent.ts +165 -0
  90. package/src/Viewer/components/WCSHelperComponent.ts +46 -0
  91. package/src/Viewer/controls/WalkControls.ts +221 -0
  92. package/src/Viewer/draggers/CuttingPlaneDragger.ts +110 -0
  93. package/src/Viewer/draggers/CuttingPlaneXAxis.ts +33 -0
  94. package/src/Viewer/draggers/CuttingPlaneYAxis.ts +33 -0
  95. package/src/Viewer/draggers/CuttingPlaneZAxis.ts +33 -0
  96. package/src/Viewer/draggers/OrbitDragger.ts +47 -22
  97. package/src/Viewer/draggers/PanDragger.ts +4 -3
  98. package/src/Viewer/draggers/WalkDragger.ts +27 -216
  99. package/src/Viewer/draggers/ZoomDragger.ts +4 -3
  100. package/src/Viewer/helpers/PlaneHelper.ts +99 -0
  101. package/src/Viewer/helpers/WCSHelper.ts +119 -0
  102. package/src/Viewer/loaders/GLTFLoadingManager.ts +6 -6
  103. package/src/index.ts +2 -0
  104. package/lib/Viewer/IComponent.d.ts +0 -3
  105. package/lib/Viewer/components/ObjectSelectionComponent.d.ts +0 -16
  106. package/lib/Viewer/draggers/ClippingPlaneDragger.d.ts +0 -17
  107. package/src/Viewer/IComponent.ts +0 -3
  108. package/src/Viewer/components/ObjectSelectionComponent.ts +0 -105
  109. package/src/Viewer/draggers/ClippingPlaneDragger.ts +0 -120
@@ -0,0 +1,34 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { commands } from "@inweb/viewer-core";
25
+ import type { Viewer } from "../Viewer";
26
+
27
+ function showAll(viewer: Viewer): void {
28
+ viewer.scene.traverse((object) => (object.visible = true));
29
+
30
+ viewer.update();
31
+ viewer.emit({ type: "showall" });
32
+ }
33
+
34
+ commands("ThreeJS").registerCommand("showAll", showAll);
@@ -0,0 +1,37 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { commands } from "@inweb/viewer-core";
25
+ import type { Viewer } from "../Viewer";
26
+ import { SelectionComponent } from "../components/SelectionComponent";
27
+
28
+ function unselect(viewer: Viewer): void {
29
+ const selection = new SelectionComponent(viewer);
30
+ selection.clearSelection();
31
+ selection.dispose();
32
+
33
+ viewer.update();
34
+ viewer.emit({ type: "select", data: undefined, handles: [] });
35
+ }
36
+
37
+ commands("ThreeJS").registerCommand("unselect", unselect);
@@ -0,0 +1,47 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { Sphere, Vector3 } from "three";
25
+
26
+ import { commands } from "@inweb/viewer-core";
27
+ import type { Viewer } from "../Viewer";
28
+
29
+ function zoomToExtents(viewer: Viewer): void {
30
+ if (viewer.extents.isEmpty()) return;
31
+
32
+ const center = viewer.extents.getCenter(new Vector3());
33
+ const distance = viewer.extents.getBoundingSphere(new Sphere()).radius;
34
+
35
+ const delta = new Vector3(0, 0, 1);
36
+ delta.applyQuaternion(viewer.camera.quaternion);
37
+ delta.multiplyScalar(distance * 3);
38
+
39
+ viewer.camera.position.copy(center).add(delta);
40
+ viewer.target.copy(center);
41
+
42
+ viewer.update();
43
+ viewer.emitEvent({ type: "zoom" });
44
+ }
45
+
46
+ commands("ThreeJS").registerCommand("zoomToExtents", zoomToExtents);
47
+ commands("ThreeJS").registerCommandAlias("zoomToExtents", "zoomExtents");
@@ -0,0 +1,55 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { Box3, Sphere, Vector3 } from "three";
25
+
26
+ import { commands } from "@inweb/viewer-core";
27
+ import type { Viewer } from "../Viewer";
28
+
29
+ function zoomToObjects(viewer: Viewer, handles: string[] = []): void {
30
+ const handleSet = new Set(handles);
31
+ const objects = [];
32
+ viewer.scene.traverseVisible((child) => {
33
+ if (handleSet.has(child.userData?.handle)) objects.push(child);
34
+ });
35
+
36
+ const extents = objects.reduce((result, object) => {
37
+ const objectExtents = new Box3().setFromObject(object);
38
+ return result.isEmpty() ? result.copy(objectExtents) : result.union(objectExtents);
39
+ }, new Box3());
40
+
41
+ const center = extents.getCenter(new Vector3());
42
+ const distance = extents.getBoundingSphere(new Sphere()).radius;
43
+
44
+ const delta = new Vector3(0, 0, 1);
45
+ delta.applyQuaternion(viewer.camera.quaternion);
46
+ delta.multiplyScalar(distance * 3);
47
+
48
+ viewer.camera.position.copy(center).add(delta);
49
+ viewer.target.copy(center);
50
+
51
+ viewer.update();
52
+ viewer.emitEvent({ type: "zoom" });
53
+ }
54
+
55
+ commands("ThreeJS").registerCommand("zoomToObjects", zoomToObjects);
@@ -0,0 +1,51 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { Box3, Sphere, Vector3 } from "three";
25
+
26
+ import { commands } from "@inweb/viewer-core";
27
+ import type { Viewer } from "../Viewer";
28
+
29
+ function zoomToSelected(viewer: Viewer): void {
30
+ const extents = viewer.selected.reduce((result, object) => {
31
+ const objectExtents = new Box3().setFromObject(object);
32
+ return result.isEmpty() ? result.copy(objectExtents) : result.union(objectExtents);
33
+ }, new Box3());
34
+
35
+ if (extents.isEmpty()) extents.copy(viewer.extents);
36
+
37
+ const center = extents.getCenter(new Vector3());
38
+ const distance = extents.getBoundingSphere(new Sphere()).radius;
39
+
40
+ const delta = new Vector3(0, 0, 1);
41
+ delta.applyQuaternion(viewer.camera.quaternion);
42
+ delta.multiplyScalar(distance * 3);
43
+
44
+ viewer.camera.position.copy(center).add(delta);
45
+ viewer.target.copy(center);
46
+
47
+ viewer.update();
48
+ viewer.emitEvent({ type: "zoom" });
49
+ }
50
+
51
+ commands("ThreeJS").registerCommand("zoomToSelected", zoomToSelected);
@@ -0,0 +1,45 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import "./ApplyModelTransform";
25
+ import "./ClearMarkup";
26
+ import "./ClearSlices";
27
+ import "./CreatePreview";
28
+ import "./Explode";
29
+ import "./GetDefaultViewPositions";
30
+ import "./GetModels";
31
+ import "./GetSelected";
32
+ import "./HideSelected";
33
+ import "./IsolateSelected";
34
+ import "./RegenerateAll";
35
+ import "./ResetView";
36
+ import "./SelectModel";
37
+ import "./SetActiveDragger";
38
+ import "./SetDefaultViewPosition";
39
+ import "./SetMarkupColor";
40
+ import "./SetSelected";
41
+ import "./ShowAll";
42
+ import "./Unselect";
43
+ import "./ZoomToExtents";
44
+ import "./ZoomToObjects";
45
+ import "./ZoomToSelected";
@@ -0,0 +1,70 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { AxesHelper, Vector3 } from "three";
25
+
26
+ import { IDisposable } from "../IDisposable";
27
+ import type { Viewer } from "../Viewer";
28
+
29
+ export class AxesHelperComponent implements IDisposable {
30
+ private viewer: Viewer;
31
+ private axesHelper1: AxesHelper;
32
+ private axesHelper2: AxesHelper;
33
+
34
+ constructor(viewer: Viewer) {
35
+ this.axesHelper1 = new AxesHelper();
36
+ this.axesHelper2 = new AxesHelper();
37
+ this.viewer = viewer;
38
+ this.viewer.addEventListener("geometryend", this.geometryEnd);
39
+ this.viewer.addEventListener("clear", this.geometryEnd);
40
+ }
41
+
42
+ dispose() {
43
+ this.axesHelper1.removeFromParent();
44
+ this.axesHelper1 = undefined;
45
+
46
+ this.axesHelper2.removeFromParent();
47
+ this.axesHelper2 = undefined;
48
+
49
+ this.viewer.removeEventListener("geometryend", this.geometryEnd);
50
+ this.viewer.removeEventListener("clear", this.geometryEnd);
51
+ }
52
+
53
+ geometryEnd = () => {
54
+ this.axesHelper1.removeFromParent();
55
+ this.axesHelper2.removeFromParent();
56
+
57
+ if (!this.viewer.extents.isEmpty()) {
58
+ const size = this.viewer.extents.getSize(new Vector3()).length();
59
+ const center = this.viewer.extents.getCenter(new Vector3());
60
+
61
+ this.axesHelper1 = new AxesHelper(size);
62
+ this.axesHelper1.position.copy(center);
63
+ this.viewer.helpers.add(this.axesHelper1);
64
+
65
+ this.axesHelper2 = new AxesHelper(size);
66
+ this.axesHelper2.position.set(0, 0, 0);
67
+ this.viewer.helpers.add(this.axesHelper2);
68
+ }
69
+ };
70
+ }
@@ -21,23 +21,25 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import * as THREE from "three";
24
+ import { Color, PMREMGenerator } from "three";
25
25
  import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
26
- import { IComponent } from "../IComponent";
26
+
27
+ import { IDisposable } from "../IDisposable";
27
28
  import type { Viewer } from "../Viewer";
28
29
 
29
- export class BackgroundComponent implements IComponent {
30
+ export class BackgroundComponent implements IDisposable {
30
31
  protected viewer: Viewer;
31
- protected backgroundColor: THREE.Color;
32
+ protected backgroundColor: Color;
32
33
 
33
34
  constructor(viewer: Viewer) {
34
35
  this.viewer = viewer;
35
36
 
36
- this.backgroundColor = new THREE.Color(0xffffff);
37
+ this.backgroundColor = new Color(0xffffff);
37
38
 
38
39
  const environment = new RoomEnvironment();
39
- const pmremGenerator = new THREE.PMREMGenerator(this.viewer.renderer);
40
+ const pmremGenerator = new PMREMGenerator(this.viewer.renderer);
40
41
 
42
+ this.viewer.renderer.setClearColor(this.backgroundColor);
41
43
  this.viewer.scene.background = this.backgroundColor;
42
44
  this.viewer.scene.environment = pmremGenerator.fromScene(environment).texture;
43
45
  this.viewer.addEventListener("optionschange", this.syncOptions);
@@ -45,7 +47,7 @@ export class BackgroundComponent implements IComponent {
45
47
  environment.dispose();
46
48
  }
47
49
 
48
- dispose(): void {
50
+ dispose() {
49
51
  this.viewer.removeEventListener("optionschange", this.syncOptions);
50
52
  this.viewer.scene.environment = undefined;
51
53
  this.viewer.scene.background = undefined;
@@ -21,46 +21,35 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
+ import { Vector3 } from "three";
25
+
24
26
  import { GeometryEndEvent } from "@inweb/viewer-core";
25
- import * as THREE from "three";
26
- import { IComponent } from "../IComponent";
27
+ import { IDisposable } from "../IDisposable";
27
28
  import type { Viewer } from "../Viewer";
28
29
 
29
- export class DefaultCameraPositionComponent implements IComponent {
30
+ export class DefaultPositionComponent implements IDisposable {
30
31
  protected viewer: Viewer;
32
+ public defaultCameraPositions: any;
31
33
 
32
34
  constructor(viewer: Viewer) {
33
35
  this.viewer = viewer;
34
36
  this.viewer.addEventListener("geometryend", this.geometryEnd);
35
37
  }
36
38
 
37
- dispose(): void {
39
+ dispose() {
38
40
  this.viewer.removeEventListener("geometryend", this.geometryEnd);
39
41
  }
40
42
 
41
43
  geometryEnd = (event: GeometryEndEvent) => {
42
- const { data: scene } = event;
43
-
44
- scene.updateMatrixWorld();
45
-
46
- const box = new THREE.Box3().setFromObject(scene);
47
- const size = box.getSize(new THREE.Vector3()).length();
48
- const center = box.getCenter(new THREE.Vector3());
49
-
50
- scene.position.x += scene.position.x - center.x;
51
- scene.position.y += scene.position.y - center.y;
52
- scene.position.z += scene.position.z - center.z;
44
+ const box = this.viewer.extents;
45
+ const size = box.getSize(new Vector3()).length();
53
46
 
54
47
  this.viewer.camera.near = size / 100;
55
48
  this.viewer.camera.far = size * 100;
56
-
57
- this.viewer.camera.position.copy(center);
58
- this.viewer.camera.position.x += size / 2.0;
59
- this.viewer.camera.position.y += size / 5.0;
60
- this.viewer.camera.position.z += size / 2.0;
61
-
62
49
  this.viewer.camera.updateMatrixWorld();
63
50
  this.viewer.camera.updateProjectionMatrix();
64
- this.viewer.camera.lookAt(center);
51
+
52
+ // this.viewer.executeCommand("setDefaultViewPosition", "sw");
53
+ this.viewer.executeCommand("zoomToExtents");
65
54
  };
66
55
  }
@@ -0,0 +1,54 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { Box3, Vector3 } from "three";
25
+
26
+ import { IDisposable } from "../IDisposable";
27
+ import type { Viewer } from "../Viewer";
28
+
29
+ export class ExtentsComponent implements IDisposable {
30
+ private viewer: Viewer;
31
+
32
+ constructor(viewer: Viewer) {
33
+ this.viewer = viewer;
34
+ this.viewer.addEventListener("geometryend", this.syncExtents);
35
+ this.viewer.addEventListener("clear", this.syncExtents);
36
+ this.viewer.on("explode", this.syncExtents);
37
+ }
38
+
39
+ dispose() {
40
+ this.viewer.removeEventListener("geometryend", this.syncExtents);
41
+ this.viewer.removeEventListener("clear", this.syncExtents);
42
+ this.viewer.off("explode", this.syncExtents);
43
+ }
44
+
45
+ syncExtents = () => {
46
+ const extents = this.viewer.models.reduce((result, gltf) => {
47
+ const modelExtents = new Box3().setFromObject(gltf.scene);
48
+ return result.isEmpty() ? result.copy(modelExtents) : result.union(modelExtents);
49
+ }, new Box3());
50
+
51
+ this.viewer.extents.copy(extents);
52
+ this.viewer.target.copy(extents.getCenter(new Vector3()));
53
+ };
54
+ }
@@ -0,0 +1,58 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { Box3, Box3Helper, Color } from "three";
25
+
26
+ import { IDisposable } from "../IDisposable";
27
+ import type { Viewer } from "../Viewer";
28
+
29
+ export class ExtentsHelperComponent implements IDisposable {
30
+ private viewer: Viewer;
31
+ private boxHelper: Box3Helper;
32
+
33
+ constructor(viewer: Viewer) {
34
+ this.boxHelper = new Box3Helper(new Box3());
35
+ this.viewer = viewer;
36
+ this.viewer.on("geometryend", this.geometryEnd);
37
+ this.viewer.on("explode", this.geometryEnd);
38
+ this.viewer.on("clear", this.geometryEnd);
39
+ }
40
+
41
+ dispose() {
42
+ this.boxHelper.removeFromParent();
43
+ this.boxHelper = undefined;
44
+
45
+ this.viewer.off("geometryend", this.geometryEnd);
46
+ this.viewer.off("explode", this.geometryEnd);
47
+ this.viewer.off("clear", this.geometryEnd);
48
+ }
49
+
50
+ geometryEnd = () => {
51
+ this.boxHelper.removeFromParent();
52
+
53
+ if (!this.viewer.extents.isEmpty()) {
54
+ this.boxHelper = new Box3Helper(this.viewer.extents, new Color(0xff0000));
55
+ this.viewer.helpers.add(this.boxHelper);
56
+ }
57
+ };
58
+ }
@@ -21,28 +21,32 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import * as THREE from "three";
25
- import { IComponent } from "../IComponent";
24
+ import { AmbientLight, DirectionalLight } from "three";
25
+
26
+ import { IDisposable } from "../IDisposable";
26
27
  import type { Viewer } from "../Viewer";
27
28
 
28
- export class LightComponent implements IComponent {
29
+ export class LightComponent implements IDisposable {
29
30
  protected viewer: Viewer;
30
- protected ambientLight: THREE.AmbientLight;
31
- protected directLight: THREE.DirectionalLight;
31
+ protected ambientLight: AmbientLight;
32
+ protected directionalLight: DirectionalLight;
32
33
 
33
34
  constructor(viewer: Viewer) {
34
35
  this.viewer = viewer;
35
36
 
36
- this.ambientLight = new THREE.AmbientLight(0xffffff, 0);
37
+ this.ambientLight = new AmbientLight(0xffffff, 0);
37
38
  this.viewer.camera.add(this.ambientLight);
38
39
 
39
- this.directLight = new THREE.DirectionalLight(0xffffff, 1);
40
- this.directLight.position.set(0.5, 0, 0.866); // ~60º
41
- this.viewer.camera.add(this.directLight);
40
+ this.directionalLight = new DirectionalLight(0xffffff, 1);
41
+ this.directionalLight.position.set(0.5, 0, 0.866); // ~60º
42
+ this.viewer.camera.add(this.directionalLight);
42
43
  }
43
44
 
44
45
  dispose(): void {
45
46
  this.ambientLight.removeFromParent();
46
- this.directLight.removeFromParent();
47
+ this.ambientLight = undefined;
48
+
49
+ this.directionalLight.removeFromParent();
50
+ this.directionalLight = undefined;
47
51
  }
48
52
  }
@@ -21,24 +21,24 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { IComponent } from "../IComponent";
24
+ import { IDisposable } from "../IDisposable";
25
25
  import type { Viewer } from "../Viewer";
26
26
 
27
- export class RenderLoopComponent implements IComponent {
27
+ export class RenderLoopComponent implements IDisposable {
28
28
  protected viewer: Viewer;
29
- protected requestID = 0;
29
+ protected requestId: number;
30
30
 
31
31
  constructor(viewer: Viewer) {
32
32
  this.viewer = viewer;
33
33
  this.animate();
34
34
  }
35
35
 
36
- dispose(): void {
37
- cancelAnimationFrame(this.requestID);
36
+ dispose() {
37
+ cancelAnimationFrame(this.requestId);
38
38
  }
39
39
 
40
40
  animate = (time = 0) => {
41
- this.requestID = requestAnimationFrame(this.animate);
41
+ this.requestId = requestAnimationFrame(this.animate);
42
42
  this.viewer.render(time);
43
43
  };
44
44
  }