@inweb/viewer-three 26.1.2 → 26.1.4

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 (31) hide show
  1. package/dist/viewer-three.js +16315 -16590
  2. package/dist/viewer-three.js.map +1 -1
  3. package/dist/viewer-three.min.js +3 -9
  4. package/dist/viewer-three.module.js +165 -251
  5. package/dist/viewer-three.module.js.map +1 -1
  6. package/lib/Viewer/Viewer.d.ts +34 -34
  7. package/lib/Viewer/commands/index.d.ts +8 -14
  8. package/lib/Viewer/components/DefaultPositionComponent.d.ts +9 -0
  9. package/lib/Viewer/components/WCSHelperComponent.d.ts +0 -1
  10. package/lib/Viewer/components/index.d.ts +20 -20
  11. package/lib/Viewer/draggers/OrbitDragger.d.ts +0 -1
  12. package/lib/Viewer/draggers/index.d.ts +19 -25
  13. package/package.json +9 -9
  14. package/src/Viewer/Viewer.ts +50 -112
  15. package/src/Viewer/commands/Explode.ts +27 -26
  16. package/src/Viewer/commands/IsolateSelected.ts +15 -6
  17. package/src/Viewer/commands/SetDefaultViewPosition.ts +4 -4
  18. package/src/Viewer/commands/ZoomToExtents.ts +15 -2
  19. package/src/Viewer/commands/ZoomToObjects.ts +12 -4
  20. package/src/Viewer/commands/ZoomToSelected.ts +14 -3
  21. package/src/Viewer/commands/index.ts +8 -14
  22. package/src/Viewer/{commands/ZoomTo.ts → components/DefaultPositionComponent.ts} +22 -34
  23. package/src/Viewer/components/ExtentsComponent.ts +3 -10
  24. package/src/Viewer/components/ResizeCanvasComponent.ts +2 -13
  25. package/src/Viewer/components/WCSHelperComponent.ts +0 -9
  26. package/src/Viewer/components/index.ts +22 -22
  27. package/src/Viewer/draggers/OrbitDragger.ts +8 -11
  28. package/src/Viewer/draggers/index.ts +19 -25
  29. package/lib/Viewer/commands/ZoomTo.d.ts +0 -3
  30. package/lib/Viewer/components/CameraComponent.d.ts +0 -8
  31. package/src/Viewer/components/CameraComponent.ts +0 -78
@@ -21,56 +21,57 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Box3, Vector3 } from "three";
24
+ import { Box3, Object3D, Vector3 } from "three";
25
25
  import type { Viewer } from "../Viewer";
26
26
 
27
- function calcExplodeDepth(object, depth: number): number {
27
+ function calcObjectDepth(object: Object3D, depth: number) {
28
28
  let res = depth;
29
29
  object.children.forEach((x) => {
30
- const objectDepth = calcExplodeDepth(x, depth + 1);
30
+ const objectDepth = calcObjectDepth(x, depth + 1);
31
31
  if (res < objectDepth) res = objectDepth;
32
32
  });
33
33
 
34
- object.originalPosition = object.position.clone();
35
- object.originalCenter = new Box3().setFromObject(object).getCenter(new Vector3());
36
- object.isExplodeLocked = depth > 2 && object.children.length === 0;
34
+ (object as any).originalPosition = object.position.clone();
37
35
 
38
36
  return res;
39
37
  }
40
38
 
41
- function explodeScene(scene, scale = 0, coeff = 4) {
39
+ function explodeScene(scene: Object3D, scale = 0) {
42
40
  scale /= 100;
43
41
 
44
- if (!scene.explodeDepth) scene.explodeDepth = calcExplodeDepth(scene, 1);
45
- const maxDepth = scene.explodeDepth;
42
+ if (!(scene as any).maxDepth) (scene as any).maxDepth = calcObjectDepth(scene, 1);
43
+ const maxDepth = (scene as any).maxDepth;
46
44
 
47
- const scaledExplodeDepth = scale * maxDepth + 1;
48
- const explodeDepth = 0 | scaledExplodeDepth;
49
- const currentSegmentFraction = scaledExplodeDepth - explodeDepth;
45
+ let explodeDepth = scale * (maxDepth - 1) + 1;
46
+ if (maxDepth === 1) explodeDepth = 1;
50
47
 
51
- function explodeObject(object, depth: number) {
52
- object.position.copy(object.originalPosition);
48
+ function explodeObject(object: Object3D, depth: number, parentCenter: Vector3, parentOffset: Vector3) {
49
+ const objectBox = new Box3().setFromObject(object);
50
+ const objectCenter = objectBox.getCenter(new Vector3());
53
51
 
54
- if (depth > 0 && depth <= explodeDepth && !object.isExplodeLocked) {
55
- let objectScale = scale * coeff;
56
- if (depth === explodeDepth) objectScale *= currentSegmentFraction;
52
+ const objectOffset = parentOffset.clone();
53
+ if (depth > 0 && depth <= explodeDepth) {
54
+ const offset = objectCenter.clone().sub(parentCenter).multiplyScalar(scale);
55
+ objectOffset.add(offset);
56
+ }
57
57
 
58
- const parentCenter = object.parent.originalCenter;
59
- const objectCenter = object.originalCenter;
60
- const objectOffset = objectCenter.clone().sub(parentCenter).multiplyScalar(objectScale);
58
+ object.children.forEach((object) => explodeObject(object, depth + 1, objectCenter, objectOffset));
61
59
 
62
- object.position.add(objectOffset);
60
+ const originalPosition = (object as any).originalPosition;
61
+ object.position.copy(originalPosition);
62
+ if (scale > 0) {
63
+ const direction = objectCenter.sub(parentCenter).normalize();
64
+ object.position.add(direction.add(objectOffset));
63
65
  }
64
-
65
- object.children.forEach((x) => explodeObject(x, depth + 1));
66
66
  }
67
67
 
68
- explodeObject(scene, 0);
68
+ const sceneExtents = new Box3().setFromObject(scene);
69
+ const sceneCenter = sceneExtents.getCenter(new Vector3());
70
+ explodeObject(scene, 0, sceneCenter, new Vector3(0, 0, 0));
69
71
  }
70
72
 
71
73
  export function explode(viewer: Viewer, index = 0): void {
72
- viewer.models.forEach((model) => explodeScene(model.scene, index));
73
- viewer.scene.updateMatrixWorld();
74
+ viewer.models.forEach((gltf) => explodeScene(gltf.scene, index));
74
75
 
75
76
  viewer.update();
76
77
  viewer.emitEvent({ type: "explode", data: index });
@@ -21,16 +21,25 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
+ import { Object3D } from "three";
24
25
  import type { Viewer } from "../Viewer";
25
26
 
26
27
  export function isolateSelected(viewer: Viewer): void {
27
- const visibleSet = new Set();
28
- viewer.selected.forEach((object) => {
29
- visibleSet.add(object);
30
- object.traverseAncestors((object2) => visibleSet.add(object2));
31
- });
28
+ const selectedSet = new Set(viewer.selected);
32
29
 
33
- viewer.scene.traverse((object) => (object.visible = visibleSet.has(object)));
30
+ function isolateObject(object: Object3D, depth: number): boolean {
31
+ let canBeIsolated = true;
32
+ object.children.forEach((object) => {
33
+ if (selectedSet.has(object)) canBeIsolated = false;
34
+ else isolateObject(object, depth + 1);
35
+ });
36
+
37
+ if (canBeIsolated && depth > 0) object.visible = false;
38
+
39
+ return canBeIsolated;
40
+ }
41
+
42
+ isolateObject(viewer.scene, 0);
34
43
 
35
44
  viewer.update();
36
45
  viewer.emitEvent({ type: "isolate" });
@@ -23,7 +23,6 @@
23
23
 
24
24
  import { Sphere, Vector3 } from "three";
25
25
  import type { Viewer } from "../Viewer";
26
- import { zoomTo } from "./ZoomTo";
27
26
 
28
27
  export const defaultViewPositions = {
29
28
  top: new Vector3(0, 0, 1),
@@ -43,11 +42,12 @@ export function setDefaultViewPosition(viewer: Viewer, position: string): void {
43
42
 
44
43
  const center = viewer.extents.getCenter(new Vector3());
45
44
  const sphere = viewer.extents.getBoundingSphere(new Sphere());
46
- const offset = direction.clone().multiplyScalar(sphere.radius);
45
+ const offet = direction.clone().multiplyScalar(sphere.radius);
47
46
 
48
47
  const camera = viewer.camera;
49
- camera.position.copy(center).add(offset);
48
+ camera.position.copy(center).add(offet);
50
49
  camera.lookAt(center);
50
+ camera.updateProjectionMatrix();
51
51
  camera.updateMatrixWorld();
52
52
 
53
53
  viewer.target.copy(center);
@@ -55,5 +55,5 @@ export function setDefaultViewPosition(viewer: Viewer, position: string): void {
55
55
  viewer.update();
56
56
  viewer.emit({ type: "viewposition", data: position });
57
57
 
58
- zoomTo(viewer, viewer.extents);
58
+ viewer.executeCommand("zoomToExtents");
59
59
  }
@@ -21,9 +21,22 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
+ import { Sphere, Vector3 } from "three";
24
25
  import type { Viewer } from "../Viewer";
25
- import { zoomTo } from "./ZoomTo";
26
26
 
27
27
  export function zoomToExtents(viewer: Viewer): void {
28
- zoomTo(viewer, viewer.extents);
28
+ if (viewer.extents.isEmpty()) return;
29
+
30
+ const center = viewer.extents.getCenter(new Vector3());
31
+ const distance = viewer.extents.getBoundingSphere(new Sphere()).radius;
32
+
33
+ const delta = new Vector3(0, 0, 1);
34
+ delta.applyQuaternion(viewer.camera.quaternion);
35
+ delta.multiplyScalar(distance * 3);
36
+
37
+ viewer.camera.position.copy(center).add(delta);
38
+ viewer.target.copy(center);
39
+
40
+ viewer.update();
41
+ viewer.emitEvent({ type: "zoom" });
29
42
  }
@@ -21,9 +21,8 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Box3 } from "three";
24
+ import { Box3, Sphere, Vector3 } from "three";
25
25
  import type { Viewer } from "../Viewer";
26
- import { zoomTo } from "./ZoomTo";
27
26
 
28
27
  export function zoomToObjects(viewer: Viewer, handles: string[] = []): void {
29
28
  const handleSet = new Set(handles);
@@ -33,7 +32,16 @@ export function zoomToObjects(viewer: Viewer, handles: string[] = []): void {
33
32
  });
34
33
 
35
34
  const extents = objects.reduce((result: Box3, object) => result.expandByObject(object), new Box3());
36
- if (extents.isEmpty()) extents.copy(viewer.extents);
35
+ const center = extents.getCenter(new Vector3());
36
+ const distance = extents.getBoundingSphere(new Sphere()).radius;
37
37
 
38
- zoomTo(viewer, extents);
38
+ const delta = new Vector3(0, 0, 1);
39
+ delta.applyQuaternion(viewer.camera.quaternion);
40
+ delta.multiplyScalar(distance * 3);
41
+
42
+ viewer.camera.position.copy(center).add(delta);
43
+ viewer.target.copy(center);
44
+
45
+ viewer.update();
46
+ viewer.emitEvent({ type: "zoom" });
39
47
  }
@@ -21,13 +21,24 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Box3 } from "three";
24
+ import { Box3, Sphere, Vector3 } from "three";
25
25
  import type { Viewer } from "../Viewer";
26
- import { zoomTo } from "./ZoomTo";
27
26
 
28
27
  export function zoomToSelected(viewer: Viewer): void {
29
28
  const extents = viewer.selected.reduce((result: Box3, object) => result.expandByObject(object), new Box3());
29
+
30
30
  if (extents.isEmpty()) extents.copy(viewer.extents);
31
31
 
32
- zoomTo(viewer, extents);
32
+ const center = extents.getCenter(new Vector3());
33
+ const distance = 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" });
33
44
  }
@@ -54,23 +54,17 @@ import { zoomToSelected } from "./ZoomToSelected";
54
54
  * 1. Define a command handler with a first `viewer` parameter.
55
55
  * 2. Register command handler in the commands registry by calling the {@link commands.registerCommand}.
56
56
  *
57
- * @example Implementing a custom command.
57
+ * @example <caption>Implementing a custom command.</caption>
58
+ * import { commands, Viewer } from "@inweb/viewer-three";
58
59
  *
59
- * ```javascript
60
- * import { commands, Viewer } from "@inweb/viewer-three";
60
+ * function commandHandler(viewer: Viewer, name = "world"): void {
61
+ * console.log(`Hello ${name}!!!`);
62
+ * }
61
63
  *
62
- * function commandHandler(viewer: Viewer, name = "world"): void {
63
- * console.log(`Hello ${name}!!!`);
64
- * }
64
+ * commands.registerCommand("sayHello", commandHandler);
65
65
  *
66
- * commands.registerCommand("sayHello", commandHandler);
67
- * ```
68
- *
69
- * @example Calling a custom command.
70
- *
71
- * ```javascript
72
- * viewer.executeCommand("sayHello", "user");
73
- * ```
66
+ * @example <caption>Calling a custom command.</caption>
67
+ * viewer.executeCommand("sayHello", "user");
74
68
  */
75
69
  export const commands: ICommandsRegistry = commandsRegistry("threejs");
76
70
 
@@ -21,46 +21,34 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Box3, MathUtils, Sphere, Vector2, Vector3 } from "three";
25
- import type { Viewer } from "../Viewer";
26
-
27
- export function zoomTo(viewer: Viewer, box: Box3): void {
28
- if (box.isEmpty()) return;
29
-
30
- const center = box.getCenter(new Vector3());
31
- const sphere = box.getBoundingSphere(new Sphere());
32
-
33
- const rendererSize = viewer.renderer.getSize(new Vector2());
34
- const aspect = rendererSize.x / rendererSize.y;
24
+ import { Vector3 } from "three";
35
25
 
36
- const camera = viewer.camera as any;
26
+ import { GeometryEndEvent, IComponent } from "@inweb/viewer-core";
27
+ import type { Viewer } from "../Viewer";
37
28
 
38
- if (camera.isPerspectiveCamera) {
39
- const offset = new Vector3(0, 0, 1);
40
- offset.applyQuaternion(camera.quaternion);
41
- offset.multiplyScalar(sphere.radius / Math.tan(MathUtils.DEG2RAD * camera.fov * 0.5));
29
+ export class DefaultPositionComponent implements IComponent {
30
+ protected viewer: Viewer;
31
+ public defaultCameraPositions: any;
42
32
 
43
- camera.position.copy(center).add(offset);
44
- camera.updateMatrixWorld();
33
+ constructor(viewer: Viewer) {
34
+ this.viewer = viewer;
35
+ this.viewer.addEventListener("geometryend", this.geometryEnd);
45
36
  }
46
- if (camera.isOrthographicCamera) {
47
- camera.top = sphere.radius;
48
- camera.bottom = -sphere.radius;
49
- camera.left = camera.bottom * aspect;
50
- camera.right = camera.top * aspect;
51
- camera.zoom = 1;
52
- camera.updateProjectionMatrix();
53
-
54
- const offset = new Vector3(0, 0, 1);
55
- offset.applyQuaternion(camera.quaternion);
56
- offset.multiplyScalar(viewer.extents.getBoundingSphere(new Sphere()).radius * 3);
57
37
 
58
- camera.position.copy(center).add(offset);
59
- camera.updateMatrixWorld();
38
+ dispose() {
39
+ this.viewer.removeEventListener("geometryend", this.geometryEnd);
60
40
  }
61
41
 
62
- viewer.target.copy(center);
42
+ geometryEnd = (event: GeometryEndEvent) => {
43
+ const box = this.viewer.extents;
44
+ const size = box.getSize(new Vector3()).length();
45
+
46
+ this.viewer.camera.near = size / 100;
47
+ this.viewer.camera.far = size * 100;
48
+ this.viewer.camera.updateMatrixWorld();
49
+ this.viewer.camera.updateProjectionMatrix();
63
50
 
64
- viewer.update();
65
- viewer.emitEvent({ type: "zoom" });
51
+ this.viewer.executeCommand("setDefaultViewPosition", "sw");
52
+ this.viewer.executeCommand("zoomToExtents");
53
+ };
66
54
  }
@@ -31,26 +31,19 @@ export class ExtentsComponent implements IComponent {
31
31
 
32
32
  constructor(viewer: Viewer) {
33
33
  this.viewer = viewer;
34
- this.viewer.addEventListener("databasechunk", this.syncExtents);
34
+ this.viewer.addEventListener("geometryend", this.syncExtents);
35
35
  this.viewer.addEventListener("clear", this.syncExtents);
36
36
  this.viewer.on("explode", this.syncExtents);
37
- this.viewer.on("isolate", this.syncExtents);
38
- this.viewer.on("hide", this.syncExtents);
39
- this.viewer.on("showall", this.syncExtents);
40
37
  }
41
38
 
42
39
  dispose() {
43
- this.viewer.removeEventListener("databasechunk", this.syncExtents);
40
+ this.viewer.removeEventListener("geometryend", this.syncExtents);
44
41
  this.viewer.removeEventListener("clear", this.syncExtents);
45
42
  this.viewer.off("explode", this.syncExtents);
46
- this.viewer.off("isolate", this.syncExtents);
47
- this.viewer.off("hide", this.syncExtents);
48
- this.viewer.off("showall", this.syncExtents);
49
43
  }
50
44
 
51
45
  syncExtents = () => {
52
- const extents = new Box3();
53
- this.viewer.scene.traverseVisible((object) => !object.children.length && extents.expandByObject(object));
46
+ const extents = this.viewer.models.reduce((result: Box3, gltf) => result.expandByObject(gltf.scene), new Box3());
54
47
 
55
48
  this.viewer.extents.copy(extents);
56
49
  this.viewer.target.copy(extents.getCenter(new Vector3()));
@@ -43,19 +43,8 @@ export class ResizeCanvasComponent implements IComponent {
43
43
 
44
44
  if (!width || !height) return; // <- invisible viewer, or viewer with parent removed
45
45
 
46
- const camera = this.viewer.camera as any;
47
- const aspect = width / height;
48
-
49
- if (camera.isPerspectiveCamera) {
50
- camera.aspect = aspect;
51
- camera.updateProjectionMatrix();
52
- }
53
- if (camera.isOrthographicCamera) {
54
- camera.left = camera.bottom * aspect;
55
- camera.right = camera.top * aspect;
56
- camera.updateProjectionMatrix();
57
- }
58
-
46
+ this.viewer.camera.aspect = width / height;
47
+ this.viewer.camera.updateProjectionMatrix();
59
48
  this.viewer.renderer.setSize(width, height, true);
60
49
 
61
50
  this.viewer.update(true);
@@ -32,23 +32,14 @@ export class WCSHelperComponent implements IComponent {
32
32
  constructor(viewer: Viewer) {
33
33
  this.wcsHelper = new WCSHelper(viewer.camera);
34
34
  this.viewer = viewer;
35
- this.viewer.addEventListener("databasechunk", this.geometryEnd);
36
- this.viewer.addEventListener("drawviewpoint", this.geometryEnd);
37
35
  this.viewer.addEventListener("render", this.viewerRender);
38
36
  }
39
37
 
40
38
  dispose() {
41
- this.viewer.removeEventListener("databasechunk", this.geometryEnd);
42
- this.viewer.removeEventListener("drawviewpoint", this.geometryEnd);
43
39
  this.viewer.removeEventListener("render", this.viewerRender);
44
40
  this.wcsHelper.dispose();
45
41
  }
46
42
 
47
- geometryEnd = () => {
48
- this.wcsHelper.dispose();
49
- this.wcsHelper = new WCSHelper(this.viewer.camera);
50
- };
51
-
52
43
  viewerRender = () => {
53
44
  if (!this.viewer.options.showWCS) return;
54
45
  if (this.viewer.extents.isEmpty()) return;
@@ -25,7 +25,7 @@ import { IComponentsRegistry, componentsRegistry } from "@inweb/viewer-core";
25
25
 
26
26
  // import { AxesHelperComponent } from "./AxesHelperComponent";
27
27
  import { BackgroundComponent } from "./BackgroundComponent";
28
- import { CameraComponent } from "./CameraComponent";
28
+ import { DefaultPositionComponent } from "./DefaultPositionComponent";
29
29
  import { ExtentsComponent } from "./ExtentsComponent";
30
30
  // import { ExtentsHelperComponent } from "./ExtentsHelperComponent";
31
31
  import { LightComponent } from "./LightComponent";
@@ -42,36 +42,36 @@ import { WCSHelperComponent } from "./WCSHelperComponent";
42
42
  *
43
43
  * 1. Define a component class implements {@link IComponent}.
44
44
  * 2. Define a constructor with a `viewer` parameter and add mouse event listeners for the specified viewer.
45
- * 3. Define the component logic in the event listeners. For example, listen for the `mousedown` event and
46
- * select objects when the left mouse button is pressed.
45
+ * 3. Define the component logic in the event listeners. For example, listen for the `mousedown`
46
+ * event and select objects when the left mouse button is pressed.
47
47
  * 4. Override {@link IComponent.dispose} and remove mouse event listeners from the viewer.
48
48
  * 5. Register component provider in the components registry by calling the
49
49
  * {@link components.registerComponent}.
50
50
  *
51
- * @example Implementing a custom component.
51
+ * @example <caption>Implementing a custom component.</caption>
52
+ * import { IComponent, components, Viewer } from "@inweb/viewer-three";
52
53
  *
53
- * ```javascript
54
- * import { IComponent, components, Viewer } from "@inweb/viewer-three";
54
+ * class MyComponent implements IComponent {
55
+ * protected viewer: Viewer;
55
56
  *
56
- * class MyComponent implements IComponent {
57
- * protected viewer: Viewer;
57
+ * constructor(viewer: Viewer) {
58
+ * this.viewer = viewer;
59
+ * this.viewer.addEventListener("mousedown", this.onMouseDown);
60
+ * }
58
61
  *
59
- * constructor(viewer: Viewer) {
60
- * this.viewer = viewer;
61
- * this.viewer.addEventListener("mousedown", this.onMouseDown);
62
- * }
62
+ * override dispose() {
63
+ * this.viewer.removeEventListener("mousedown", this.onMouseDown);
64
+ * }
63
65
  *
64
- * override dispose() {
65
- * this.viewer.removeEventListener("mousedown", this.onMouseDown);
66
+ * onMouseDown = (event: PointerEvent) => {
67
+ * // place custom logic here
68
+ * };
66
69
  * }
67
70
  *
68
- * onMouseDown = (event: PointerEvent) => {
69
- * // place custom logic here
70
- * };
71
- * }
72
- *
73
- * components.registerComponent("MyComponent", (viewer): IComponent => new MyComponent(viewer));
74
- * ```
71
+ * components.registerComponent(
72
+ * "MyComponent",
73
+ * (viewer): IComponent => new MyComponent(viewer)
74
+ * );
75
75
  */
76
76
  export const components: IComponentsRegistry = componentsRegistry("threejs");
77
77
 
@@ -80,9 +80,9 @@ export const components: IComponentsRegistry = componentsRegistry("threejs");
80
80
  components.registerComponent("ExtentsComponent", (viewer) => new ExtentsComponent(viewer));
81
81
  components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
82
82
  components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
83
- components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
84
83
  components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
85
84
  components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
85
+ components.registerComponent("DefaultPositionComponent", (viewer) => new DefaultPositionComponent(viewer));
86
86
  components.registerComponent("SelectionComponent", (viewer) => new SelectionComponent(viewer));
87
87
  components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
88
88
 
@@ -42,22 +42,20 @@ export class OrbitDragger implements IDragger {
42
42
  this.orbit.addEventListener("change", this.controlsChange);
43
43
  this.changed = false;
44
44
  this.viewer = viewer;
45
- this.viewer.addEventListener("databasechunk", this.updateControls);
45
+ this.viewer.on("geometryend", this.updateControls);
46
46
  this.viewer.on("viewposition", this.updateControls);
47
- this.viewer.addEventListener("zoom", this.updateControls);
48
- this.viewer.addEventListener("drawviewpoint", this.updateControls);
49
- this.viewer.addEventListener("contextmenu", this.stopContextMenu);
47
+ this.viewer.on("zoom", this.updateControls);
48
+ this.viewer.on("drawviewpoint", this.updateControls);
49
+ this.viewer.on("contextmenu", this.stopContextMenu);
50
50
  this.updateControls();
51
51
  }
52
52
 
53
- initialize() {}
54
-
55
53
  dispose(): void {
56
- this.viewer.removeEventListener("databasechunk", this.updateControls);
54
+ this.viewer.off("geometryend", this.updateControls);
57
55
  this.viewer.off("viewposition", this.updateControls);
58
- this.viewer.removeEventListener("zoom", this.updateControls);
59
- this.viewer.removeEventListener("drawviewpoint", this.updateControls);
60
- this.viewer.removeEventListener("contextmenu", this.stopContextMenu);
56
+ this.viewer.off("zoom", this.updateControls);
57
+ this.viewer.off("drawviewpoint", this.updateControls);
58
+ this.viewer.off("contextmenu", this.stopContextMenu);
61
59
 
62
60
  this.orbit.removeEventListener("start", this.controlsStart);
63
61
  this.orbit.removeEventListener("change", this.controlsChange);
@@ -67,7 +65,6 @@ export class OrbitDragger implements IDragger {
67
65
  updateControls = () => {
68
66
  this.orbit.maxDistance = this.viewer.camera.far;
69
67
  this.orbit.minDistance = this.viewer.camera.near;
70
- this.orbit.object = this.viewer.camera;
71
68
  this.orbit.target.copy(this.viewer.target);
72
69
  this.orbit.update();
73
70
  };
@@ -39,41 +39,35 @@ import { ZoomDragger } from "./ZoomDragger";
39
39
  *
40
40
  * 1. Define a dragger class implements {@link IDragger}.
41
41
  * 2. Define a constructor with a `viewer` parameter and add mouse event listeners for the specified viewer.
42
- * 3. Define the dragger logic in the event listeners. For example, listen for the `mousemove` event and
43
- * zoom in/out when the left mouse button is pressed.
42
+ * 3. Define the dragger logic in the event listeners. For example, listen for the `mousemove`
43
+ * event and zoom in/out when the left mouse button is pressed.
44
44
  * 4. Override {@link IDragger.dispose} and remove mouse event listeners from the viewer.
45
45
  * 5. Register dragger provider in the draggers registry by calling the {@link draggers.registerDragger}.
46
46
  *
47
- * @example Implementing a custom dragger.
47
+ * @example <caption>Implementing a custom dragger.</caption>
48
+ * import { IDragger, draggers, Viewer } from "@inweb/viewer-three";
48
49
  *
49
- * ```javascript
50
- * import { IDragger, draggers, Viewer } from "@inweb/viewer-three";
50
+ * class MyDragger implements IDragger {
51
+ * protected viewer: Viewer;
51
52
  *
52
- * class MyDragger implements IDragger {
53
- * protected viewer: Viewer;
53
+ * constructor(viewer: Viewer) {
54
+ * this.viewer = viewer;
55
+ * this.viewer.addEventListener("pointermove", this.onPointerMove);
56
+ * }
54
57
  *
55
- * constructor(viewer: Viewer) {
56
- * this.viewer = viewer;
57
- * this.viewer.addEventListener("pointermove", this.onPointerMove);
58
- * }
58
+ * override dispose() {
59
+ * this.viewer.removeEventListener("pointermove", this.onPointerMove);
60
+ * }
59
61
  *
60
- * override dispose() {
61
- * this.viewer.removeEventListener("pointermove", this.onPointerMove);
62
+ * onPointerMove = (event: PointerEvent) => {
63
+ * // place custom logic here
64
+ * };
62
65
  * }
63
66
  *
64
- * onPointerMove = (event: PointerEvent) => {
65
- * // place custom logic here
66
- * };
67
- * }
68
- *
69
- * draggers.registerDragger("MyDragger", (viewer): IDragger => new MyDragger(viewer));
70
- * ```
71
- *
72
- * @example Activating a custom dragger.
67
+ * draggers.registerDragger("MyDragger", (viewer): IDragger => new MyDragger(viewer));
73
68
  *
74
- * ```javascript
75
- * viewer.setActiveDragger("MyDragger");
76
- * ```
69
+ * @example <caption>Activating a custom dragger.</caption>
70
+ * viewer.setActiveDragger("MyDragger");
77
71
  */
78
72
  export const draggers: IDraggersRegistry = draggersRegistry("threejs");
79
73
 
@@ -1,3 +0,0 @@
1
- import { Box3 } from "three";
2
- import type { Viewer } from "../Viewer";
3
- export declare function zoomTo(viewer: Viewer, box: Box3): void;
@@ -1,8 +0,0 @@
1
- import { IComponent } from "@inweb/viewer-core";
2
- import type { Viewer } from "../Viewer";
3
- export declare class CameraComponent implements IComponent {
4
- protected viewer: Viewer;
5
- constructor(viewer: Viewer);
6
- dispose(): void;
7
- geometryEnd: () => void;
8
- }