@inweb/viewer-three 26.9.5 → 26.9.7
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 +37 -29
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +37 -29
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/components/ResetComponent.d.ts +10 -0
- package/lib/Viewer/controls/WalkControls.d.ts +1 -8
- package/package.json +5 -5
- package/src/Viewer/commands/ResetView.ts +5 -1
- package/src/Viewer/components/ResetComponent.ts +64 -0
- package/src/Viewer/components/index.ts +2 -0
- package/src/Viewer/controls/WalkControls.ts +3 -35
- package/src/Viewer/draggers/WalkDragger.ts +7 -7
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
2
|
+
import type { Viewer } from "../Viewer";
|
|
3
|
+
export declare class ResetComponent implements IComponent {
|
|
4
|
+
private viewer;
|
|
5
|
+
private savedCameraPosition;
|
|
6
|
+
constructor(viewer: Viewer);
|
|
7
|
+
dispose(): void;
|
|
8
|
+
onDatabaseChunk: () => void;
|
|
9
|
+
resetCameraPosition(): void;
|
|
10
|
+
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { Camera, Controls, Vector2, Object3D } from "three";
|
|
2
|
-
import { Viewer } from "../Viewer";
|
|
3
|
-
import { IModelImpl } from "../models/IModelImpl";
|
|
4
|
-
import { HighlighterComponent } from "../components/HighlighterComponent";
|
|
5
2
|
interface WalkControlsEventMap {
|
|
6
3
|
change: {
|
|
7
4
|
type: "change";
|
|
@@ -30,9 +27,7 @@ export declare class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
30
27
|
private mouseDragOn;
|
|
31
28
|
rotateDelta: Vector2;
|
|
32
29
|
private camera;
|
|
33
|
-
|
|
34
|
-
protected highlighter: HighlighterComponent;
|
|
35
|
-
constructor(camera: Camera, canvas: HTMLElement, groundObjects: Object3D[], viewer: Viewer);
|
|
30
|
+
constructor(camera: Camera, canvas: HTMLElement, groundObjects: Object3D[]);
|
|
36
31
|
dispose(): void;
|
|
37
32
|
onPointerDown: (event: PointerEvent) => void;
|
|
38
33
|
onPointerMove: (event: PointerEvent) => void;
|
|
@@ -42,8 +37,6 @@ export declare class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
42
37
|
onKeyDown: (event: KeyboardEvent) => void;
|
|
43
38
|
onKeyUp: (event: KeyboardEvent) => void;
|
|
44
39
|
private updateGroundFollowing;
|
|
45
|
-
select(objects: Object3D | Object3D[], model?: IModelImpl): void;
|
|
46
|
-
initHighlighter: () => void;
|
|
47
40
|
update(): void;
|
|
48
41
|
rotateCamera(delta: Vector2): void;
|
|
49
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "26.9.
|
|
3
|
+
"version": "26.9.7",
|
|
4
4
|
"description": "JavaScript library for rendering CAD and BIM files in a browser using Three.js",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"docs": "typedoc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@inweb/client": "~26.9.
|
|
39
|
-
"@inweb/eventemitter2": "~26.9.
|
|
40
|
-
"@inweb/markup": "~26.9.
|
|
41
|
-
"@inweb/viewer-core": "~26.9.
|
|
38
|
+
"@inweb/client": "~26.9.7",
|
|
39
|
+
"@inweb/eventemitter2": "~26.9.7",
|
|
40
|
+
"@inweb/markup": "~26.9.7",
|
|
41
|
+
"@inweb/viewer-core": "~26.9.7"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/three": "^0.179.0",
|
|
@@ -22,8 +22,11 @@
|
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
import type { Viewer } from "../Viewer";
|
|
25
|
+
import type { ResetComponent } from "../components/ResetComponent";
|
|
25
26
|
|
|
26
27
|
export function resetView(viewer: Viewer): void {
|
|
28
|
+
const reset = viewer.getComponent("ResetComponent") as ResetComponent;
|
|
29
|
+
|
|
27
30
|
viewer.executeCommand("setActiveDragger");
|
|
28
31
|
viewer.executeCommand("clearSlices");
|
|
29
32
|
viewer.executeCommand("clearOverlay");
|
|
@@ -32,7 +35,8 @@ export function resetView(viewer: Viewer): void {
|
|
|
32
35
|
viewer.executeCommand("showAll");
|
|
33
36
|
viewer.executeCommand("explode", 0);
|
|
34
37
|
viewer.executeCommand("zoomToExtents", true);
|
|
35
|
-
|
|
38
|
+
|
|
39
|
+
reset.resetCameraPosition();
|
|
36
40
|
|
|
37
41
|
viewer.emit({ type: "resetview" });
|
|
38
42
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2025, 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-2025 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
|
+
// ===================== AI-CODE-FILE ======================
|
|
25
|
+
// Source: Claude Sonnet 4
|
|
26
|
+
// Date: 2025-09-10
|
|
27
|
+
// Reviewer: vitaly.ivanov@opendesign.com
|
|
28
|
+
// Issue: CLOUD-5835
|
|
29
|
+
// Notes: Originally AI-generated, modified manually 2025-09-11
|
|
30
|
+
// =========================================================
|
|
31
|
+
|
|
32
|
+
import { IComponent } from "@inweb/viewer-core";
|
|
33
|
+
import type { Viewer } from "../Viewer";
|
|
34
|
+
import { Vector3 } from "three";
|
|
35
|
+
|
|
36
|
+
export class ResetComponent implements IComponent {
|
|
37
|
+
private viewer: Viewer;
|
|
38
|
+
private savedCameraPosition: any = null;
|
|
39
|
+
|
|
40
|
+
constructor(viewer: Viewer) {
|
|
41
|
+
this.viewer = viewer;
|
|
42
|
+
this.viewer.addEventListener("databasechunk", this.onDatabaseChunk);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
dispose() {
|
|
46
|
+
this.viewer.removeEventListener("databasechunk", this.onDatabaseChunk);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onDatabaseChunk = () => {
|
|
50
|
+
this.savedCameraPosition = {
|
|
51
|
+
position: this.viewer.camera.position.clone(),
|
|
52
|
+
up: this.viewer.camera.up.clone(),
|
|
53
|
+
direction: this.viewer.camera.getWorldDirection(new Vector3()),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
resetCameraPosition() {
|
|
58
|
+
if (this.savedCameraPosition) {
|
|
59
|
+
this.viewer.camera.position.copy(this.savedCameraPosition.position);
|
|
60
|
+
this.viewer.camera.up.copy(this.savedCameraPosition.up);
|
|
61
|
+
this.viewer.camera.lookAt(this.savedCameraPosition.position.clone().add(this.savedCameraPosition.direction));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -32,6 +32,7 @@ import { ResizeCanvasComponent } from "./ResizeCanvasComponent";
|
|
|
32
32
|
import { HighlighterComponent } from "./HighlighterComponent";
|
|
33
33
|
import { SelectionComponent } from "./SelectionComponent";
|
|
34
34
|
import { WCSHelperComponent } from "./WCSHelperComponent";
|
|
35
|
+
import { ResetComponent } from "./ResetComponent";
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Viewer components registry. Use this registry to register custom components.
|
|
@@ -84,3 +85,4 @@ components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopCo
|
|
|
84
85
|
components.registerComponent("HighlighterComponent", (viewer) => new HighlighterComponent(viewer));
|
|
85
86
|
components.registerComponent("SelectionComponent", (viewer) => new SelectionComponent(viewer));
|
|
86
87
|
components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
|
|
88
|
+
components.registerComponent("ResetComponent", (viewer) => new ResetComponent(viewer));
|
|
@@ -22,9 +22,6 @@
|
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
import { Clock, Camera, Controls, Quaternion, Vector2, Vector3, Raycaster, Object3D, MathUtils } from "three";
|
|
25
|
-
import { Viewer } from "../Viewer";
|
|
26
|
-
import { IModelImpl } from "../models/IModelImpl";
|
|
27
|
-
import { HighlighterComponent } from "../components/HighlighterComponent";
|
|
28
25
|
|
|
29
26
|
interface WalkControlsEventMap {
|
|
30
27
|
change: { type: "change" };
|
|
@@ -55,13 +52,10 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
55
52
|
public rotateDelta: Vector2;
|
|
56
53
|
|
|
57
54
|
private camera: Camera;
|
|
58
|
-
private viewer: Viewer;
|
|
59
|
-
protected highlighter: HighlighterComponent;
|
|
60
55
|
|
|
61
|
-
constructor(camera: Camera, canvas: HTMLElement, groundObjects: Object3D[]
|
|
56
|
+
constructor(camera: Camera, canvas: HTMLElement, groundObjects: Object3D[]) {
|
|
62
57
|
super(camera, canvas);
|
|
63
58
|
this.camera = camera;
|
|
64
|
-
this.viewer = viewer;
|
|
65
59
|
|
|
66
60
|
this.groundObjects = groundObjects;
|
|
67
61
|
this.raycaster = new Raycaster();
|
|
@@ -171,7 +165,8 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
171
165
|
};
|
|
172
166
|
|
|
173
167
|
private updateGroundFollowing() {
|
|
174
|
-
|
|
168
|
+
const up = new Vector3().copy(this.camera.up);
|
|
169
|
+
this.raycaster.set(this.object.position, up.negate());
|
|
175
170
|
|
|
176
171
|
this.raycaster.params = this.raycaster.params = {
|
|
177
172
|
Mesh: {},
|
|
@@ -189,36 +184,9 @@ export class WalkControls extends Controls<WalkControlsEventMap> {
|
|
|
189
184
|
|
|
190
185
|
// Smoothly interpolate the camera's y position to the target height
|
|
191
186
|
this.object.position.y = MathUtils.lerp(this.object.position.y, targetY, this.GROUND_FOLLOWING_SPEED);
|
|
192
|
-
|
|
193
|
-
// Only for debug
|
|
194
|
-
// const model = this.viewer.models[0];
|
|
195
|
-
// const handles = model.getHandlesByObjects(intersects[0].object);
|
|
196
|
-
// const objects = model.getObjectsByHandles(handles);
|
|
197
|
-
// this.viewer.clearSelected();
|
|
198
|
-
// this.select(objects, model);
|
|
199
187
|
}
|
|
200
188
|
}
|
|
201
189
|
|
|
202
|
-
select(objects: Object3D | Object3D[], model?: IModelImpl) {
|
|
203
|
-
if (!model) {
|
|
204
|
-
this.viewer.models.forEach((model) => this.select(objects, model));
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!Array.isArray(objects)) objects = [objects];
|
|
209
|
-
if (!objects.length) return;
|
|
210
|
-
|
|
211
|
-
model.showOriginalObjects(objects);
|
|
212
|
-
this.highlighter.highlight(objects);
|
|
213
|
-
|
|
214
|
-
objects.forEach((object: any) => this.viewer.selected.push(object));
|
|
215
|
-
objects.forEach((object: any) => (object.isSelected = true));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
initHighlighter = () => {
|
|
219
|
-
this.highlighter = this.viewer.getComponent("HighlighterComponent") as HighlighterComponent;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
190
|
override update() {
|
|
223
191
|
let moved = false;
|
|
224
192
|
let upgradeGroundFollowing = false;
|
|
@@ -33,14 +33,14 @@ export class WalkDragger implements IDragger {
|
|
|
33
33
|
|
|
34
34
|
constructor(viewer: Viewer) {
|
|
35
35
|
const meshOnlyGround: Mesh[] = [];
|
|
36
|
-
viewer.models
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
meshOnlyGround.push(
|
|
36
|
+
viewer.models.forEach((model) =>
|
|
37
|
+
model.getVisibleObjects().forEach((obj) => {
|
|
38
|
+
if (obj instanceof Mesh) {
|
|
39
|
+
meshOnlyGround.push(obj);
|
|
40
40
|
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
this.controls = new WalkControls(viewer.camera, viewer.canvas, meshOnlyGround
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
this.controls = new WalkControls(viewer.camera, viewer.canvas, meshOnlyGround);
|
|
44
44
|
this.controls.addEventListener("change", this.controlsChange);
|
|
45
45
|
this.controls.addEventListener("walkspeedchange", this.walkspeedChange);
|
|
46
46
|
this.viewer = viewer;
|