@inweb/viewer-three 26.1.1 → 26.1.3
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.
- package/dist/viewer-three.js +16543 -16268
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +9 -3
- package/dist/viewer-three.module.js +228 -2476
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +34 -34
- package/lib/Viewer/commands/ZoomTo.d.ts +3 -0
- package/lib/Viewer/commands/index.d.ts +14 -8
- package/lib/Viewer/components/CameraComponent.d.ts +8 -0
- package/lib/Viewer/components/WCSHelperComponent.d.ts +1 -0
- package/lib/Viewer/components/index.d.ts +20 -20
- package/lib/Viewer/draggers/OrbitDragger.d.ts +1 -0
- package/lib/Viewer/draggers/index.d.ts +25 -19
- package/package.json +9 -9
- package/src/Viewer/Viewer.ts +112 -50
- package/src/Viewer/commands/Explode.ts +26 -27
- package/src/Viewer/commands/IsolateSelected.ts +6 -15
- package/src/Viewer/commands/SetDefaultViewPosition.ts +4 -4
- package/src/Viewer/{components/DefaultPositionComponent.ts → commands/ZoomTo.ts} +34 -22
- package/src/Viewer/commands/ZoomToExtents.ts +2 -15
- package/src/Viewer/commands/ZoomToObjects.ts +4 -12
- package/src/Viewer/commands/ZoomToSelected.ts +3 -14
- package/src/Viewer/commands/index.ts +14 -8
- package/src/Viewer/components/CameraComponent.ts +78 -0
- package/src/Viewer/components/ExtentsComponent.ts +10 -3
- package/src/Viewer/components/ResizeCanvasComponent.ts +13 -2
- package/src/Viewer/components/WCSHelperComponent.ts +9 -0
- package/src/Viewer/components/index.ts +22 -22
- package/src/Viewer/draggers/OrbitDragger.ts +11 -8
- package/src/Viewer/draggers/index.ts +25 -19
- package/lib/Viewer/components/DefaultPositionComponent.d.ts +0 -9
|
@@ -21,57 +21,56 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Box3,
|
|
24
|
+
import { Box3, Vector3 } from "three";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
26
|
|
|
27
|
-
function
|
|
27
|
+
function calcExplodeDepth(object, depth: number): number {
|
|
28
28
|
let res = depth;
|
|
29
29
|
object.children.forEach((x) => {
|
|
30
|
-
const objectDepth =
|
|
30
|
+
const objectDepth = calcExplodeDepth(x, depth + 1);
|
|
31
31
|
if (res < objectDepth) res = objectDepth;
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
|
|
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;
|
|
35
37
|
|
|
36
38
|
return res;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
function explodeScene(scene
|
|
41
|
+
function explodeScene(scene, scale = 0, coeff = 4) {
|
|
40
42
|
scale /= 100;
|
|
41
43
|
|
|
42
|
-
if (!
|
|
43
|
-
const maxDepth =
|
|
44
|
+
if (!scene.explodeDepth) scene.explodeDepth = calcExplodeDepth(scene, 1);
|
|
45
|
+
const maxDepth = scene.explodeDepth;
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
const scaledExplodeDepth = scale * maxDepth + 1;
|
|
48
|
+
const explodeDepth = 0 | scaledExplodeDepth;
|
|
49
|
+
const currentSegmentFraction = scaledExplodeDepth - explodeDepth;
|
|
47
50
|
|
|
48
|
-
function explodeObject(object
|
|
49
|
-
|
|
50
|
-
const objectCenter = objectBox.getCenter(new Vector3());
|
|
51
|
+
function explodeObject(object, depth: number) {
|
|
52
|
+
object.position.copy(object.originalPosition);
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
objectOffset.add(offset);
|
|
56
|
-
}
|
|
54
|
+
if (depth > 0 && depth <= explodeDepth && !object.isExplodeLocked) {
|
|
55
|
+
let objectScale = scale * coeff;
|
|
56
|
+
if (depth === explodeDepth) objectScale *= currentSegmentFraction;
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
const parentCenter = object.parent.originalCenter;
|
|
59
|
+
const objectCenter = object.originalCenter;
|
|
60
|
+
const objectOffset = objectCenter.clone().sub(parentCenter).multiplyScalar(objectScale);
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
object.position.copy(originalPosition);
|
|
62
|
-
if (scale > 0) {
|
|
63
|
-
const direction = objectCenter.sub(parentCenter).normalize();
|
|
64
|
-
object.position.add(direction.add(objectOffset));
|
|
62
|
+
object.position.add(objectOffset);
|
|
65
63
|
}
|
|
64
|
+
|
|
65
|
+
object.children.forEach((x) => explodeObject(x, depth + 1));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
const sceneCenter = sceneExtents.getCenter(new Vector3());
|
|
70
|
-
explodeObject(scene, 0, sceneCenter, new Vector3(0, 0, 0));
|
|
68
|
+
explodeObject(scene, 0);
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
export function explode(viewer: Viewer, index = 0): void {
|
|
74
|
-
viewer.models.forEach((
|
|
72
|
+
viewer.models.forEach((model) => explodeScene(model.scene, index));
|
|
73
|
+
viewer.scene.updateMatrixWorld();
|
|
75
74
|
|
|
76
75
|
viewer.update();
|
|
77
76
|
viewer.emitEvent({ type: "explode", data: index });
|
|
@@ -21,25 +21,16 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Object3D } from "three";
|
|
25
24
|
import type { Viewer } from "../Viewer";
|
|
26
25
|
|
|
27
26
|
export function isolateSelected(viewer: Viewer): void {
|
|
28
|
-
const
|
|
27
|
+
const visibleSet = new Set();
|
|
28
|
+
viewer.selected.forEach((object) => {
|
|
29
|
+
visibleSet.add(object);
|
|
30
|
+
object.traverseAncestors((object2) => visibleSet.add(object2));
|
|
31
|
+
});
|
|
29
32
|
|
|
30
|
-
|
|
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);
|
|
33
|
+
viewer.scene.traverse((object) => (object.visible = visibleSet.has(object)));
|
|
43
34
|
|
|
44
35
|
viewer.update();
|
|
45
36
|
viewer.emitEvent({ type: "isolate" });
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { Sphere, Vector3 } from "three";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
|
+
import { zoomTo } from "./ZoomTo";
|
|
26
27
|
|
|
27
28
|
export const defaultViewPositions = {
|
|
28
29
|
top: new Vector3(0, 0, 1),
|
|
@@ -42,12 +43,11 @@ export function setDefaultViewPosition(viewer: Viewer, position: string): void {
|
|
|
42
43
|
|
|
43
44
|
const center = viewer.extents.getCenter(new Vector3());
|
|
44
45
|
const sphere = viewer.extents.getBoundingSphere(new Sphere());
|
|
45
|
-
const
|
|
46
|
+
const offset = direction.clone().multiplyScalar(sphere.radius);
|
|
46
47
|
|
|
47
48
|
const camera = viewer.camera;
|
|
48
|
-
camera.position.copy(center).add(
|
|
49
|
+
camera.position.copy(center).add(offset);
|
|
49
50
|
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
|
-
viewer.
|
|
58
|
+
zoomTo(viewer, viewer.extents);
|
|
59
59
|
}
|
|
@@ -21,34 +21,46 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Vector3 } from "three";
|
|
25
|
-
|
|
26
|
-
import { GeometryEndEvent, IComponent } from "@inweb/viewer-core";
|
|
24
|
+
import { Box3, MathUtils, Sphere, Vector2, Vector3 } from "three";
|
|
27
25
|
import type { Viewer } from "../Viewer";
|
|
28
26
|
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
public defaultCameraPositions: any;
|
|
27
|
+
export function zoomTo(viewer: Viewer, box: Box3): void {
|
|
28
|
+
if (box.isEmpty()) return;
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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;
|
|
35
|
+
|
|
36
|
+
const camera = viewer.camera as any;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
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));
|
|
42
|
+
|
|
43
|
+
camera.position.copy(center).add(offset);
|
|
44
|
+
camera.updateMatrixWorld();
|
|
40
45
|
}
|
|
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);
|
|
41
57
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
camera.position.copy(center).add(offset);
|
|
59
|
+
camera.updateMatrixWorld();
|
|
60
|
+
}
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
this.viewer.camera.far = size * 100;
|
|
48
|
-
this.viewer.camera.updateMatrixWorld();
|
|
49
|
-
this.viewer.camera.updateProjectionMatrix();
|
|
62
|
+
viewer.target.copy(center);
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
64
|
+
viewer.update();
|
|
65
|
+
viewer.emitEvent({ type: "zoom" });
|
|
54
66
|
}
|
|
@@ -21,22 +21,9 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Sphere, Vector3 } from "three";
|
|
25
24
|
import type { Viewer } from "../Viewer";
|
|
25
|
+
import { zoomTo } from "./ZoomTo";
|
|
26
26
|
|
|
27
27
|
export function zoomToExtents(viewer: Viewer): void {
|
|
28
|
-
|
|
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" });
|
|
28
|
+
zoomTo(viewer, viewer.extents);
|
|
42
29
|
}
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Box3
|
|
24
|
+
import { Box3 } from "three";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
|
+
import { zoomTo } from "./ZoomTo";
|
|
26
27
|
|
|
27
28
|
export function zoomToObjects(viewer: Viewer, handles: string[] = []): void {
|
|
28
29
|
const handleSet = new Set(handles);
|
|
@@ -32,16 +33,7 @@ export function zoomToObjects(viewer: Viewer, handles: string[] = []): void {
|
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
const extents = objects.reduce((result: Box3, object) => result.expandByObject(object), new Box3());
|
|
35
|
-
|
|
36
|
-
const distance = extents.getBoundingSphere(new Sphere()).radius;
|
|
36
|
+
if (extents.isEmpty()) extents.copy(viewer.extents);
|
|
37
37
|
|
|
38
|
-
|
|
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" });
|
|
38
|
+
zoomTo(viewer, extents);
|
|
47
39
|
}
|
|
@@ -21,24 +21,13 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Box3
|
|
24
|
+
import { Box3 } from "three";
|
|
25
25
|
import type { Viewer } from "../Viewer";
|
|
26
|
+
import { zoomTo } from "./ZoomTo";
|
|
26
27
|
|
|
27
28
|
export function zoomToSelected(viewer: Viewer): void {
|
|
28
29
|
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
|
-
|
|
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" });
|
|
32
|
+
zoomTo(viewer, extents);
|
|
44
33
|
}
|
|
@@ -54,17 +54,23 @@ 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
|
|
58
|
-
* import { commands, Viewer } from "@inweb/viewer-three";
|
|
57
|
+
* @example Implementing a custom command.
|
|
59
58
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* }
|
|
59
|
+
* ```javascript
|
|
60
|
+
* import { commands, Viewer } from "@inweb/viewer-three";
|
|
63
61
|
*
|
|
64
|
-
*
|
|
62
|
+
* function commandHandler(viewer: Viewer, name = "world"): void {
|
|
63
|
+
* console.log(`Hello ${name}!!!`);
|
|
64
|
+
* }
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
66
|
+
* commands.registerCommand("sayHello", commandHandler);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Calling a custom command.
|
|
70
|
+
*
|
|
71
|
+
* ```javascript
|
|
72
|
+
* viewer.executeCommand("sayHello", "user");
|
|
73
|
+
* ```
|
|
68
74
|
*/
|
|
69
75
|
export const commands: ICommandsRegistry = commandsRegistry("threejs");
|
|
70
76
|
|
|
@@ -0,0 +1,78 @@
|
|
|
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, Vector2 } from "three";
|
|
25
|
+
|
|
26
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
27
|
+
import type { Viewer } from "../Viewer";
|
|
28
|
+
|
|
29
|
+
export class CameraComponent implements IComponent {
|
|
30
|
+
protected viewer: Viewer;
|
|
31
|
+
|
|
32
|
+
constructor(viewer: Viewer) {
|
|
33
|
+
this.viewer = viewer;
|
|
34
|
+
this.viewer.addEventListener("databasechunk", this.geometryEnd);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
dispose() {
|
|
38
|
+
this.viewer.removeEventListener("databasechunk", this.geometryEnd);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
geometryEnd = () => {
|
|
42
|
+
const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
|
|
43
|
+
const rendererSize = this.viewer.renderer.getSize(new Vector2());
|
|
44
|
+
const aspect = rendererSize.x / rendererSize.y;
|
|
45
|
+
|
|
46
|
+
let sceneCamera: any;
|
|
47
|
+
this.viewer.scene.traverse((object: any) => {
|
|
48
|
+
if (object.isCamera)
|
|
49
|
+
if (!sceneCamera) sceneCamera = object;
|
|
50
|
+
else if (object.isPerspectiveCamera && sceneCamera.isOrthographicCamera) sceneCamera = object;
|
|
51
|
+
});
|
|
52
|
+
if (sceneCamera) {
|
|
53
|
+
this.viewer.camera = sceneCamera.clone();
|
|
54
|
+
this.viewer.camera.up.set(0, 0, 1);
|
|
55
|
+
this.viewer.camera.scale.set(1, 1, 1); // <- visualize fix
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const camera = this.viewer.camera as any;
|
|
59
|
+
|
|
60
|
+
if (camera.isPerspectiveCamera) {
|
|
61
|
+
camera.aspect = aspect;
|
|
62
|
+
camera.near = extentsSize / 100;
|
|
63
|
+
camera.far = extentsSize * 100;
|
|
64
|
+
camera.updateProjectionMatrix();
|
|
65
|
+
}
|
|
66
|
+
if (camera.isOrthographicCamera) {
|
|
67
|
+
camera.left = camera.bottom * aspect;
|
|
68
|
+
camera.right = camera.top * aspect;
|
|
69
|
+
camera.near = 0;
|
|
70
|
+
camera.far = extentsSize * 100;
|
|
71
|
+
camera.updateProjectionMatrix();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!sceneCamera) {
|
|
75
|
+
this.viewer.executeCommand("setDefaultViewPosition");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -31,19 +31,26 @@ export class ExtentsComponent implements IComponent {
|
|
|
31
31
|
|
|
32
32
|
constructor(viewer: Viewer) {
|
|
33
33
|
this.viewer = viewer;
|
|
34
|
-
this.viewer.addEventListener("
|
|
34
|
+
this.viewer.addEventListener("databasechunk", 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);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
dispose() {
|
|
40
|
-
this.viewer.removeEventListener("
|
|
43
|
+
this.viewer.removeEventListener("databasechunk", this.syncExtents);
|
|
41
44
|
this.viewer.removeEventListener("clear", this.syncExtents);
|
|
42
45
|
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);
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
syncExtents = () => {
|
|
46
|
-
const extents =
|
|
52
|
+
const extents = new Box3();
|
|
53
|
+
this.viewer.scene.traverseVisible((object) => !object.children.length && extents.expandByObject(object));
|
|
47
54
|
|
|
48
55
|
this.viewer.extents.copy(extents);
|
|
49
56
|
this.viewer.target.copy(extents.getCenter(new Vector3()));
|
|
@@ -43,8 +43,19 @@ export class ResizeCanvasComponent implements IComponent {
|
|
|
43
43
|
|
|
44
44
|
if (!width || !height) return; // <- invisible viewer, or viewer with parent removed
|
|
45
45
|
|
|
46
|
-
this.viewer.camera
|
|
47
|
-
|
|
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
|
+
|
|
48
59
|
this.viewer.renderer.setSize(width, height, true);
|
|
49
60
|
|
|
50
61
|
this.viewer.update(true);
|
|
@@ -32,14 +32,23 @@ 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);
|
|
35
37
|
this.viewer.addEventListener("render", this.viewerRender);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
dispose() {
|
|
41
|
+
this.viewer.removeEventListener("databasechunk", this.geometryEnd);
|
|
42
|
+
this.viewer.removeEventListener("drawviewpoint", this.geometryEnd);
|
|
39
43
|
this.viewer.removeEventListener("render", this.viewerRender);
|
|
40
44
|
this.wcsHelper.dispose();
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
geometryEnd = () => {
|
|
48
|
+
this.wcsHelper.dispose();
|
|
49
|
+
this.wcsHelper = new WCSHelper(this.viewer.camera);
|
|
50
|
+
};
|
|
51
|
+
|
|
43
52
|
viewerRender = () => {
|
|
44
53
|
if (!this.viewer.options.showWCS) return;
|
|
45
54
|
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 {
|
|
28
|
+
import { CameraComponent } from "./CameraComponent";
|
|
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`
|
|
46
|
-
*
|
|
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.
|
|
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
|
|
52
|
-
* import { IComponent, components, Viewer } from "@inweb/viewer-three";
|
|
51
|
+
* @example Implementing a custom component.
|
|
53
52
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
53
|
+
* ```javascript
|
|
54
|
+
* import { IComponent, components, Viewer } from "@inweb/viewer-three";
|
|
56
55
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* this.viewer.addEventListener("mousedown", this.onMouseDown);
|
|
60
|
-
* }
|
|
56
|
+
* class MyComponent implements IComponent {
|
|
57
|
+
* protected viewer: Viewer;
|
|
61
58
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
59
|
+
* constructor(viewer: Viewer) {
|
|
60
|
+
* this.viewer = viewer;
|
|
61
|
+
* this.viewer.addEventListener("mousedown", this.onMouseDown);
|
|
62
|
+
* }
|
|
65
63
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* };
|
|
64
|
+
* override dispose() {
|
|
65
|
+
* this.viewer.removeEventListener("mousedown", this.onMouseDown);
|
|
69
66
|
* }
|
|
70
67
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
68
|
+
* onMouseDown = (event: PointerEvent) => {
|
|
69
|
+
* // place custom logic here
|
|
70
|
+
* };
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* components.registerComponent("MyComponent", (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));
|
|
83
84
|
components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
|
|
84
85
|
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,20 +42,22 @@ 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.
|
|
45
|
+
this.viewer.addEventListener("databasechunk", this.updateControls);
|
|
46
46
|
this.viewer.on("viewposition", this.updateControls);
|
|
47
|
-
this.viewer.
|
|
48
|
-
this.viewer.
|
|
49
|
-
this.viewer.
|
|
47
|
+
this.viewer.addEventListener("zoom", this.updateControls);
|
|
48
|
+
this.viewer.addEventListener("drawviewpoint", this.updateControls);
|
|
49
|
+
this.viewer.addEventListener("contextmenu", this.stopContextMenu);
|
|
50
50
|
this.updateControls();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
initialize() {}
|
|
54
|
+
|
|
53
55
|
dispose(): void {
|
|
54
|
-
this.viewer.
|
|
56
|
+
this.viewer.removeEventListener("databasechunk", this.updateControls);
|
|
55
57
|
this.viewer.off("viewposition", this.updateControls);
|
|
56
|
-
this.viewer.
|
|
57
|
-
this.viewer.
|
|
58
|
-
this.viewer.
|
|
58
|
+
this.viewer.removeEventListener("zoom", this.updateControls);
|
|
59
|
+
this.viewer.removeEventListener("drawviewpoint", this.updateControls);
|
|
60
|
+
this.viewer.removeEventListener("contextmenu", this.stopContextMenu);
|
|
59
61
|
|
|
60
62
|
this.orbit.removeEventListener("start", this.controlsStart);
|
|
61
63
|
this.orbit.removeEventListener("change", this.controlsChange);
|
|
@@ -65,6 +67,7 @@ export class OrbitDragger implements IDragger {
|
|
|
65
67
|
updateControls = () => {
|
|
66
68
|
this.orbit.maxDistance = this.viewer.camera.far;
|
|
67
69
|
this.orbit.minDistance = this.viewer.camera.near;
|
|
70
|
+
this.orbit.object = this.viewer.camera;
|
|
68
71
|
this.orbit.target.copy(this.viewer.target);
|
|
69
72
|
this.orbit.update();
|
|
70
73
|
};
|