@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.
- package/README.md +26 -18
- package/dist/viewer-three.js +10315 -6179
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -2
- package/dist/viewer-three.module.js +1881 -322
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/IDisposable.d.ts +6 -0
- package/lib/Viewer/Viewer.d.ts +113 -14
- package/lib/Viewer/commands/ApplyModelTransform.d.ts +1 -0
- package/lib/Viewer/commands/ClearMarkup.d.ts +1 -0
- package/lib/Viewer/commands/ClearSlices.d.ts +1 -0
- package/lib/Viewer/commands/CreatePreview.d.ts +1 -0
- package/lib/Viewer/commands/Explode.d.ts +1 -0
- package/lib/Viewer/commands/GetDefaultViewPositions.d.ts +1 -0
- package/lib/Viewer/commands/GetModels.d.ts +1 -0
- package/lib/Viewer/commands/GetSelected.d.ts +1 -0
- package/lib/Viewer/commands/HideSelected.d.ts +1 -0
- package/lib/Viewer/commands/IsolateSelected.d.ts +1 -0
- package/lib/Viewer/commands/RegenerateAll.d.ts +1 -0
- package/lib/Viewer/commands/ResetView.d.ts +1 -0
- package/lib/Viewer/commands/SelectModel.d.ts +1 -0
- package/lib/Viewer/commands/SetActiveDragger.d.ts +1 -0
- package/lib/Viewer/commands/SetDefaultViewPosition.d.ts +13 -0
- package/lib/Viewer/commands/SetMarkupColor.d.ts +1 -0
- package/lib/Viewer/commands/SetSelected.d.ts +1 -0
- package/lib/Viewer/commands/ShowAll.d.ts +1 -0
- package/lib/Viewer/commands/Unselect.d.ts +1 -0
- package/lib/Viewer/commands/ZoomToExtents.d.ts +1 -0
- package/lib/Viewer/commands/ZoomToObjects.d.ts +1 -0
- package/lib/Viewer/commands/ZoomToSelected.d.ts +1 -0
- package/lib/Viewer/commands/index.d.ts +22 -0
- package/lib/Viewer/components/AxesHelperComponent.d.ts +10 -0
- package/lib/Viewer/components/BackgroundComponent.d.ts +4 -4
- package/lib/Viewer/components/{DefaultCameraPositionComponent.d.ts → DefaultPositionComponent.d.ts} +3 -2
- package/lib/Viewer/components/ExtentsComponent.d.ts +8 -0
- package/lib/Viewer/components/ExtentsHelperComponent.d.ts +9 -0
- package/lib/Viewer/components/LightComponent.d.ts +5 -5
- package/lib/Viewer/components/RenderLoopComponent.d.ts +3 -3
- package/lib/Viewer/components/ResizeCanvasComponent.d.ts +2 -2
- package/lib/Viewer/components/SelectionComponent.d.ts +19 -0
- package/lib/Viewer/components/ViewPositionComponent.d.ts +31 -0
- package/lib/Viewer/components/WCSHelperComponent.d.ts +9 -0
- package/lib/Viewer/controls/WalkControls.d.ts +26 -0
- package/lib/Viewer/draggers/CuttingPlaneDragger.d.ts +17 -0
- package/lib/Viewer/draggers/CuttingPlaneXAxis.d.ts +5 -0
- package/lib/Viewer/draggers/CuttingPlaneYAxis.d.ts +5 -0
- package/lib/Viewer/draggers/CuttingPlaneZAxis.d.ts +5 -0
- package/lib/Viewer/draggers/OrbitDragger.d.ts +9 -5
- package/lib/Viewer/draggers/WalkDragger.d.ts +7 -33
- package/lib/Viewer/helpers/PlaneHelper.d.ts +11 -0
- package/lib/Viewer/helpers/WCSHelper.d.ts +10 -0
- package/lib/Viewer/loaders/GLTFLoadingManager.d.ts +3 -3
- package/lib/index.d.ts +1 -0
- package/package.json +7 -6
- package/src/Viewer/IDisposable.ts +29 -0
- package/src/Viewer/Viewer.ts +218 -49
- package/src/Viewer/commands/ApplyModelTransform.ts +33 -0
- package/src/Viewer/commands/ClearMarkup.ts +29 -0
- package/src/Viewer/commands/ClearSlices.ts +32 -0
- package/src/Viewer/commands/CreatePreview.ts +32 -0
- package/src/Viewer/commands/Explode.ts +83 -0
- package/src/Viewer/commands/GetDefaultViewPositions.ts +31 -0
- package/src/Viewer/commands/GetModels.ts +32 -0
- package/src/Viewer/commands/GetSelected.ts +31 -0
- package/src/Viewer/commands/HideSelected.ts +40 -0
- package/src/Viewer/commands/IsolateSelected.ts +50 -0
- package/src/Viewer/commands/RegenerateAll.ts +32 -0
- package/src/Viewer/commands/ResetView.ts +41 -0
- package/src/Viewer/commands/SelectModel.ts +32 -0
- package/src/Viewer/commands/SetActiveDragger.ts +29 -0
- package/src/Viewer/commands/SetDefaultViewPosition.ts +83 -0
- package/src/Viewer/commands/SetMarkupColor.ts +30 -0
- package/src/Viewer/commands/SetSelected.ts +44 -0
- package/src/Viewer/commands/ShowAll.ts +34 -0
- package/src/Viewer/commands/Unselect.ts +37 -0
- package/src/Viewer/commands/ZoomToExtents.ts +47 -0
- package/src/Viewer/commands/ZoomToObjects.ts +55 -0
- package/src/Viewer/commands/ZoomToSelected.ts +51 -0
- package/src/Viewer/commands/index.ts +45 -0
- package/src/Viewer/components/AxesHelperComponent.ts +70 -0
- package/src/Viewer/components/BackgroundComponent.ts +9 -7
- package/src/Viewer/components/{DefaultCameraPositionComponent.ts → DefaultPositionComponent.ts} +11 -22
- package/src/Viewer/components/ExtentsComponent.ts +54 -0
- package/src/Viewer/components/ExtentsHelperComponent.ts +58 -0
- package/src/Viewer/components/LightComponent.ts +14 -10
- package/src/Viewer/components/RenderLoopComponent.ts +6 -6
- package/src/Viewer/components/ResizeCanvasComponent.ts +2 -2
- package/src/Viewer/components/SelectionComponent.ts +132 -0
- package/src/Viewer/components/ViewPositionComponent.ts +165 -0
- package/src/Viewer/components/WCSHelperComponent.ts +46 -0
- package/src/Viewer/controls/WalkControls.ts +221 -0
- package/src/Viewer/draggers/CuttingPlaneDragger.ts +110 -0
- package/src/Viewer/draggers/CuttingPlaneXAxis.ts +33 -0
- package/src/Viewer/draggers/CuttingPlaneYAxis.ts +33 -0
- package/src/Viewer/draggers/CuttingPlaneZAxis.ts +33 -0
- package/src/Viewer/draggers/OrbitDragger.ts +47 -22
- package/src/Viewer/draggers/PanDragger.ts +4 -3
- package/src/Viewer/draggers/WalkDragger.ts +27 -216
- package/src/Viewer/draggers/ZoomDragger.ts +4 -3
- package/src/Viewer/helpers/PlaneHelper.ts +99 -0
- package/src/Viewer/helpers/WCSHelper.ts +119 -0
- package/src/Viewer/loaders/GLTFLoadingManager.ts +6 -6
- package/src/index.ts +2 -0
- package/lib/Viewer/IComponent.d.ts +0 -3
- package/lib/Viewer/components/ObjectSelectionComponent.d.ts +0 -16
- package/lib/Viewer/draggers/ClippingPlaneDragger.d.ts +0 -17
- package/src/Viewer/IComponent.ts +0 -3
- package/src/Viewer/components/ObjectSelectionComponent.ts +0 -105
- package/src/Viewer/draggers/ClippingPlaneDragger.ts +0 -120
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "25.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "25.10.0",
|
|
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",
|
|
7
7
|
"author": "Open Design Alliance",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rollup -c rollup.config.js",
|
|
27
|
-
"test": "karma start karma.conf.js"
|
|
27
|
+
"test": "karma start karma.conf.js",
|
|
28
|
+
"docs": "typedoc"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@inweb/client": "~25.
|
|
31
|
-
"@inweb/eventemitter2": "~25.
|
|
32
|
-
"@inweb/viewer-core": "~25.
|
|
31
|
+
"@inweb/client": "~25.10.0",
|
|
32
|
+
"@inweb/eventemitter2": "~25.10.0",
|
|
33
|
+
"@inweb/viewer-core": "~25.10.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/three": "^0.152.1",
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
/**
|
|
25
|
+
* An object that performs a cleanup operation when `.dispose()` is called.
|
|
26
|
+
*/
|
|
27
|
+
export interface IDisposable {
|
|
28
|
+
dispose(): void;
|
|
29
|
+
}
|
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -21,8 +21,12 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
+
import { Box3, LinearToneMapping, Object3D, PerspectiveCamera, Scene, Vector3, WebGLRenderer } from "three";
|
|
25
|
+
import { GLTF, GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
26
|
+
import { GLTFLoadingManager } from "./loaders/GLTFLoadingManager";
|
|
27
|
+
|
|
24
28
|
import { EventEmitter2 } from "@inweb/eventemitter2";
|
|
25
|
-
import { Assembly, Client,
|
|
29
|
+
import { Assembly, Client, Model, File } from "@inweb/client";
|
|
26
30
|
import {
|
|
27
31
|
CANVAS_EVENTS,
|
|
28
32
|
CanvasEventMap,
|
|
@@ -35,68 +39,88 @@ import {
|
|
|
35
39
|
OptionsEventMap,
|
|
36
40
|
ViewerEventMap,
|
|
37
41
|
} from "@inweb/viewer-core";
|
|
38
|
-
import * as THREE from "three";
|
|
39
|
-
import { GLTF, GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
40
|
-
import { GLTFLoadingManager } from "./loaders/GLTFLoadingManager";
|
|
41
42
|
|
|
42
43
|
import { PanDragger } from "./draggers/PanDragger";
|
|
43
44
|
import { OrbitDragger } from "./draggers/OrbitDragger";
|
|
44
45
|
import { ZoomDragger } from "./draggers/ZoomDragger";
|
|
45
46
|
import { WalkDragger } from "./draggers/WalkDragger";
|
|
46
|
-
import {
|
|
47
|
+
import { CuttingPlaneXAxisDragger } from "./draggers/CuttingPlaneXAxis";
|
|
48
|
+
import { CuttingPlaneYAxisDragger } from "./draggers/CuttingPlaneYAxis";
|
|
49
|
+
import { CuttingPlaneZAxisDragger } from "./draggers/CuttingPlaneZAxis";
|
|
47
50
|
|
|
48
|
-
import {
|
|
51
|
+
import { IDisposable } from "./IDisposable";
|
|
52
|
+
import { ExtentsComponent } from "./components/ExtentsComponent";
|
|
49
53
|
import { LightComponent } from "./components/LightComponent";
|
|
50
54
|
import { BackgroundComponent } from "./components/BackgroundComponent";
|
|
51
|
-
import {
|
|
55
|
+
import { DefaultPositionComponent } from "./components/DefaultPositionComponent";
|
|
52
56
|
import { ResizeCanvasComponent } from "./components/ResizeCanvasComponent";
|
|
53
57
|
import { RenderLoopComponent } from "./components/RenderLoopComponent";
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
import { SelectionComponent } from "./components/SelectionComponent";
|
|
59
|
+
// import { ViewPositionComponent } from "./components/ViewPositionComponent";
|
|
60
|
+
import { WCSHelperComponent } from "./components/WCSHelperComponent";
|
|
61
|
+
// import { AxesHelperComponent } from "./components/AxesHelperComponent";
|
|
62
|
+
// import { ExtentsHelperComponent } from "./components/ExtentsHelperComponent";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 3D viewer powered by {@link https://threejs.org/ | Three.js}.
|
|
66
|
+
*/
|
|
56
67
|
export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & OptionsEventMap> implements IViewer {
|
|
57
68
|
public client: Client | undefined;
|
|
58
|
-
|
|
69
|
+
protected _options: Options;
|
|
59
70
|
|
|
60
71
|
private canvaseventlistener: (event: any) => void;
|
|
61
72
|
|
|
62
73
|
public canvas: HTMLCanvasElement | undefined;
|
|
63
74
|
public canvasEvents: string[];
|
|
64
75
|
|
|
65
|
-
public scene:
|
|
66
|
-
public
|
|
67
|
-
public
|
|
76
|
+
public scene: Scene | undefined;
|
|
77
|
+
public helpers: Scene | undefined;
|
|
78
|
+
public camera: PerspectiveCamera | undefined;
|
|
79
|
+
public renderer: WebGLRenderer | undefined;
|
|
68
80
|
public models: Array<GLTF>;
|
|
69
|
-
public
|
|
81
|
+
public selected: Array<Object3D>;
|
|
82
|
+
public extents: Box3;
|
|
83
|
+
public target: Vector3;
|
|
70
84
|
|
|
71
85
|
private draggerFactory: Record<string, any>;
|
|
72
86
|
private _activeDragger: IDragger | null;
|
|
73
87
|
|
|
74
|
-
private components: Array<
|
|
88
|
+
private components: Array<IDisposable>;
|
|
75
89
|
|
|
76
|
-
private renderNeeded
|
|
90
|
+
private renderNeeded: boolean;
|
|
77
91
|
private renderTime: DOMHighResTimeStamp;
|
|
78
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @param client - The `Client` instance that is used to load model reference files from the
|
|
95
|
+
* Open Cloud Server. Do not specify `Client` if you need a standalone viewer instance to
|
|
96
|
+
* view `glTF` files from the web or from local computer.
|
|
97
|
+
*/
|
|
79
98
|
constructor(client?: Client) {
|
|
80
99
|
super();
|
|
81
100
|
this._options = new Options(this);
|
|
82
101
|
|
|
83
102
|
this.client = client;
|
|
84
103
|
|
|
85
|
-
this.canvasEvents = CANVAS_EVENTS
|
|
104
|
+
this.canvasEvents = CANVAS_EVENTS;
|
|
86
105
|
this.canvaseventlistener = (event: Event) => this.emit(event);
|
|
87
106
|
|
|
107
|
+
this.extents = new Box3();
|
|
108
|
+
this.target = new Vector3();
|
|
109
|
+
|
|
88
110
|
this.draggerFactory = {
|
|
89
111
|
Pan: PanDragger,
|
|
90
112
|
Zoom: ZoomDragger,
|
|
91
113
|
Orbit: OrbitDragger,
|
|
92
114
|
Walk: WalkDragger,
|
|
93
|
-
|
|
115
|
+
CuttingPlaneXAxis: CuttingPlaneXAxisDragger,
|
|
116
|
+
CuttingPlaneYAxis: CuttingPlaneYAxisDragger,
|
|
117
|
+
CuttingPlaneZAxis: CuttingPlaneZAxisDragger,
|
|
94
118
|
};
|
|
95
119
|
this._activeDragger = null;
|
|
96
120
|
|
|
97
121
|
this.models = [];
|
|
98
122
|
this.components = [];
|
|
99
|
-
this.
|
|
123
|
+
this.selected = [];
|
|
100
124
|
|
|
101
125
|
this.renderTime = 0;
|
|
102
126
|
|
|
@@ -104,7 +128,7 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
104
128
|
this.update = this.update.bind(this);
|
|
105
129
|
}
|
|
106
130
|
|
|
107
|
-
get options():
|
|
131
|
+
get options(): IOptions {
|
|
108
132
|
return this._options;
|
|
109
133
|
}
|
|
110
134
|
|
|
@@ -112,38 +136,45 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
112
136
|
return Object.keys(this.draggerFactory);
|
|
113
137
|
}
|
|
114
138
|
|
|
115
|
-
initialize(canvas: HTMLCanvasElement, onProgress?: (event: ProgressEvent) => void): Promise<this> {
|
|
139
|
+
initialize(canvas: HTMLCanvasElement, onProgress?: (event: ProgressEvent<EventTarget>) => void): Promise<this> {
|
|
116
140
|
this.addEventListener("optionschange", (event) => this.syncOptions(event.data));
|
|
117
141
|
|
|
118
|
-
this.scene = new
|
|
142
|
+
this.scene = new Scene();
|
|
143
|
+
this.helpers = new Scene();
|
|
119
144
|
|
|
120
145
|
const rect = canvas.parentElement.getBoundingClientRect();
|
|
121
146
|
const width = rect.width || 1;
|
|
122
147
|
const height = rect.height || 1;
|
|
123
|
-
this.camera = new
|
|
148
|
+
this.camera = new PerspectiveCamera(45, width / height, 0.01, 1000);
|
|
124
149
|
this.camera.up.set(0, 0, 1);
|
|
125
150
|
|
|
126
|
-
this.renderer = new
|
|
151
|
+
this.renderer = new WebGLRenderer({ canvas, antialias: true, preserveDrawingBuffer: true });
|
|
127
152
|
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
128
153
|
this.renderer.setSize(width, height);
|
|
129
|
-
this.renderer.toneMapping =
|
|
154
|
+
this.renderer.toneMapping = LinearToneMapping;
|
|
130
155
|
|
|
131
156
|
this.canvas = canvas;
|
|
132
157
|
this.canvasEvents.forEach((x) => canvas.addEventListener(x, this.canvaseventlistener));
|
|
133
158
|
|
|
159
|
+
this.components.push(new ExtentsComponent(this));
|
|
134
160
|
this.components.push(new LightComponent(this));
|
|
135
161
|
this.components.push(new BackgroundComponent(this));
|
|
136
|
-
this.components.push(new
|
|
162
|
+
// this.components.push(new ViewPositionComponent(this));
|
|
163
|
+
this.components.push(new DefaultPositionComponent(this));
|
|
137
164
|
this.components.push(new ResizeCanvasComponent(this));
|
|
138
|
-
this.components.push(new RenderLoopComponent(this
|
|
139
|
-
|
|
165
|
+
this.components.push(new RenderLoopComponent(this));
|
|
166
|
+
this.components.push(new SelectionComponent(this));
|
|
167
|
+
this.components.push(new WCSHelperComponent(this));
|
|
168
|
+
// this.components.push(new AxesHelperComponent(this));
|
|
169
|
+
// this.components.push(new ExtentsHelperComponent(this));
|
|
140
170
|
|
|
141
171
|
this.syncOptions();
|
|
142
172
|
|
|
143
173
|
this.renderTime = performance.now();
|
|
144
174
|
this.render(this.renderTime);
|
|
145
175
|
|
|
146
|
-
if (
|
|
176
|
+
if (typeof onProgress === "function")
|
|
177
|
+
onProgress(new ProgressEvent("progress", { lengthComputable: true, loaded: 1, total: 1 }));
|
|
147
178
|
|
|
148
179
|
this.emitEvent({ type: "initializeprogress", data: 1, loaded: 1, total: 1 });
|
|
149
180
|
this.emitEvent({ type: "initialize" });
|
|
@@ -155,12 +186,14 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
155
186
|
this.cancel();
|
|
156
187
|
this.emitEvent({ type: "dispose" });
|
|
157
188
|
|
|
158
|
-
this.components.forEach((component:
|
|
189
|
+
this.components.forEach((component: IDisposable) => component.dispose());
|
|
159
190
|
this.components = [];
|
|
160
191
|
|
|
161
192
|
this.setActiveDragger("");
|
|
162
193
|
this.removeAllListeners();
|
|
163
194
|
|
|
195
|
+
this.clear();
|
|
196
|
+
|
|
164
197
|
if (this.canvas) {
|
|
165
198
|
this.canvasEvents.forEach((x) => this.canvas.removeEventListener(x, this.canvaseventlistener));
|
|
166
199
|
this.canvas = undefined;
|
|
@@ -171,6 +204,7 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
171
204
|
this.renderer = undefined;
|
|
172
205
|
this.camera = undefined;
|
|
173
206
|
this.scene = undefined;
|
|
207
|
+
this.helpers = undefined;
|
|
174
208
|
|
|
175
209
|
return this;
|
|
176
210
|
}
|
|
@@ -182,15 +216,24 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
182
216
|
public render(time: DOMHighResTimeStamp): void {
|
|
183
217
|
if (!this.renderNeeded) return;
|
|
184
218
|
if (!this.renderer) return;
|
|
185
|
-
if (!this.scene) return;
|
|
186
|
-
if (!this.camera) return;
|
|
187
219
|
|
|
220
|
+
const clippingPlanes = this.renderer.clippingPlanes;
|
|
221
|
+
|
|
222
|
+
this.renderer.setViewport(0, 0, this.canvas.offsetWidth, this.canvas.offsetHeight);
|
|
188
223
|
this.renderer.render(this.scene, this.camera);
|
|
189
|
-
|
|
224
|
+
|
|
225
|
+
this.renderer.clippingPlanes = [];
|
|
226
|
+
this.renderer.autoClear = false;
|
|
227
|
+
this.renderer.render(this.helpers, this.camera);
|
|
190
228
|
|
|
191
229
|
const deltaTime = (time - this.renderTime) / 1000;
|
|
192
230
|
this.renderTime = time;
|
|
193
231
|
this.emitEvent({ type: "render", time, deltaTime });
|
|
232
|
+
|
|
233
|
+
this.renderer.autoClear = true;
|
|
234
|
+
this.renderer.clippingPlanes = clippingPlanes;
|
|
235
|
+
|
|
236
|
+
this.renderNeeded = false;
|
|
194
237
|
}
|
|
195
238
|
|
|
196
239
|
public update(force = false): void {
|
|
@@ -208,7 +251,30 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
208
251
|
return Promise.resolve(this);
|
|
209
252
|
}
|
|
210
253
|
|
|
211
|
-
|
|
254
|
+
/**
|
|
255
|
+
* Loads a file from Open Cloud Server into the viewer.
|
|
256
|
+
*
|
|
257
|
+
* The file geometry data on the server must be converted to `glTF` format.
|
|
258
|
+
*
|
|
259
|
+
* This method requires a `Client` instance to be specified when creating the viewer to load
|
|
260
|
+
* model reference files from the Open Cloud Server. For a standalone viewer instance use
|
|
261
|
+
* {@link openGltfFile | openGltfFile()}.
|
|
262
|
+
*
|
|
263
|
+
* Fires:
|
|
264
|
+
*
|
|
265
|
+
* - {@link OpenEvent | open}
|
|
266
|
+
* - {@link GeometryStartEvent | geometrystart}
|
|
267
|
+
* - {@link GeometryProgressEvent | geometryprogress}
|
|
268
|
+
* - {@link DatabaseChunkEvent | databasechunk}
|
|
269
|
+
* - {@link GeometryChunkEvent | geometrychunk}
|
|
270
|
+
* - {@link GeometryEndEvent | geometryend}
|
|
271
|
+
* - {@link GeometryErrorEvent | geometryerror}
|
|
272
|
+
*
|
|
273
|
+
* @param file - File, assembly or specific model to load. If a `File` instance with multiple
|
|
274
|
+
* models is specified, the default model will be loaded. If there is no default model,
|
|
275
|
+
* first availiable model will be loaded.
|
|
276
|
+
*/
|
|
277
|
+
async open(file: Model | File | Assembly): Promise<this> {
|
|
212
278
|
if (!this.renderer) return this;
|
|
213
279
|
|
|
214
280
|
this.cancel();
|
|
@@ -240,9 +306,40 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
240
306
|
return this;
|
|
241
307
|
}
|
|
242
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Loads a `glTF` file into the viewer.
|
|
311
|
+
*
|
|
312
|
+
* Fires:
|
|
313
|
+
*
|
|
314
|
+
* - {@link OpenEvent | open}
|
|
315
|
+
* - {@link GeometryStartEvent | geometrystart}
|
|
316
|
+
* - {@link GeometryProgressEvent | geometryprogress}
|
|
317
|
+
* - {@link DatabaseChunkEvent | databasechunk}
|
|
318
|
+
* - {@link GeometryEndEvent | geometryend}
|
|
319
|
+
* - {@link GeometryErrorEvent | geometryerror}
|
|
320
|
+
*
|
|
321
|
+
* @param file - File URL or binary data buffer to load.
|
|
322
|
+
* @param externalData - External resource map such as binary data buffers or images. Each
|
|
323
|
+
* resource should be represented by a `uri` and a corresponding resource URL, or
|
|
324
|
+
* {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object, or
|
|
325
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer}
|
|
326
|
+
* or {@link https://developer.mozilla.org/docs/Web/API/Blob/Blob | Blob}, or
|
|
327
|
+
* {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL} string,
|
|
328
|
+
* @param params - Loader parameters.
|
|
329
|
+
* @param params.path - The base path from which to find subsequent glTF resources such as
|
|
330
|
+
* textures and .bin data files. If not defined, the base path of the file URL will be used.
|
|
331
|
+
* @param params.requestHeader - The
|
|
332
|
+
* {@link https://developer.mozilla.org/docs/Glossary/Request_header | request header} used
|
|
333
|
+
* in HTTP request.
|
|
334
|
+
* @param params.crossOrigin - The crossOrigin string to implement CORS for loading the url
|
|
335
|
+
* from a different domain that allows CORS. Default is `anonymous`.
|
|
336
|
+
* @param params.withCredentials - Whether the XMLHttpRequest uses credentials such as
|
|
337
|
+
* cookies, authorization headers or TLS client certificates. See
|
|
338
|
+
* {@link https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/withCredentials | XMLHttpRequest.withCredentials}.
|
|
339
|
+
*/
|
|
243
340
|
openGltfFile(
|
|
244
|
-
file: string | ArrayBuffer | Blob,
|
|
245
|
-
externalData: Map<string, string | ArrayBuffer | Blob> = new Map(),
|
|
341
|
+
file: string | globalThis.File | ArrayBuffer | Blob,
|
|
342
|
+
externalData: Map<string, string | globalThis.File | ArrayBuffer | Blob> = new Map(),
|
|
246
343
|
params: {
|
|
247
344
|
path?: string;
|
|
248
345
|
requestHeader?: HeadersInit;
|
|
@@ -260,9 +357,40 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
260
357
|
return this.loadGltfFile(file, externalData, params);
|
|
261
358
|
}
|
|
262
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Appends a `glTF` file to the existing opened file.
|
|
362
|
+
*
|
|
363
|
+
* Fires:
|
|
364
|
+
*
|
|
365
|
+
* - {@link OpenEvent | open}
|
|
366
|
+
* - {@link GeometryStartEvent | geometrystart}
|
|
367
|
+
* - {@link GeometryProgressEvent | geometryprogress}
|
|
368
|
+
* - {@link DatabaseChunkEvent | databasechunk}
|
|
369
|
+
* - {@link GeometryEndEvent | geometryend}
|
|
370
|
+
* - {@link GeometryErrorEvent | geometryerror}
|
|
371
|
+
*
|
|
372
|
+
* @param file - File URL or binary data buffer to load.
|
|
373
|
+
* @param externalData - External resource map such as binary data buffers or images. Each
|
|
374
|
+
* resource should be represented by a `uri` and a corresponding resource URL, or
|
|
375
|
+
* {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object, or
|
|
376
|
+
* {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer}
|
|
377
|
+
* or {@link https://developer.mozilla.org/docs/Web/API/Blob/Blob | Blob}, or
|
|
378
|
+
* {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL} string,
|
|
379
|
+
* @param params - Loader parameters.
|
|
380
|
+
* @param params.path - The base path from which to find subsequent glTF resources such as
|
|
381
|
+
* textures and .bin data files.
|
|
382
|
+
* @param params.requestHeader - The
|
|
383
|
+
* {@link https://developer.mozilla.org/docs/Glossary/Request_header | request header} used
|
|
384
|
+
* in HTTP request.
|
|
385
|
+
* @param params.crossOrigin - The crossOrigin string to implement CORS for loading the url
|
|
386
|
+
* from a different domain that allows CORS. Default is `anonymous`.
|
|
387
|
+
* @param params.withCredentials - Whether the XMLHttpRequest uses credentials such as
|
|
388
|
+
* cookies, authorization headers or TLS client certificates. See
|
|
389
|
+
* {@link https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/withCredentials | XMLHttpRequest.withCredentials}.
|
|
390
|
+
*/
|
|
263
391
|
async loadGltfFile(
|
|
264
|
-
file: string | ArrayBuffer | Blob,
|
|
265
|
-
externalData: Map<string, string | ArrayBuffer | Blob> = new Map(),
|
|
392
|
+
file: string | globalThis.File | ArrayBuffer | Blob,
|
|
393
|
+
externalData: Map<string, string | globalThis.File | ArrayBuffer | Blob> = new Map(),
|
|
266
394
|
params: {
|
|
267
395
|
path?: string;
|
|
268
396
|
requestHeader?: HeadersInit;
|
|
@@ -291,11 +419,13 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
291
419
|
|
|
292
420
|
this.models.push(gltf);
|
|
293
421
|
this.scene.add(gltf.scene);
|
|
422
|
+
|
|
294
423
|
this.update();
|
|
424
|
+
this.resetActiveDragger();
|
|
295
425
|
|
|
296
426
|
this.emitEvent({ type: "databasechunk" });
|
|
297
427
|
this.emitEvent({ type: "geometryend", data: gltf.scene });
|
|
298
|
-
} catch (error
|
|
428
|
+
} catch (error) {
|
|
299
429
|
this.emitEvent({ type: "geometryerror", data: error });
|
|
300
430
|
throw error;
|
|
301
431
|
} finally {
|
|
@@ -306,6 +436,8 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
306
436
|
}
|
|
307
437
|
|
|
308
438
|
clear(): this {
|
|
439
|
+
if (!this.renderer) return this;
|
|
440
|
+
|
|
309
441
|
function disposeMaterial(material: any) {
|
|
310
442
|
const materials = Array.isArray(material) ? material : [material];
|
|
311
443
|
materials.forEach((material: any) => {
|
|
@@ -319,14 +451,22 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
319
451
|
if (object.material) disposeMaterial(object.material);
|
|
320
452
|
}
|
|
321
453
|
|
|
322
|
-
this.
|
|
454
|
+
this.setActiveDragger();
|
|
455
|
+
|
|
456
|
+
this.selected = [];
|
|
457
|
+
this.renderer.clippingPlanes = [];
|
|
458
|
+
|
|
459
|
+
this.helpers.traverse(disposeObject);
|
|
460
|
+
this.helpers.clear();
|
|
323
461
|
|
|
324
462
|
this.models.forEach((gltf) => gltf.scene.traverse(disposeObject));
|
|
325
463
|
this.models.forEach((gltf) => gltf.scene.removeFromParent());
|
|
326
464
|
this.models = [];
|
|
327
465
|
|
|
328
|
-
this.
|
|
466
|
+
this.scene.clear();
|
|
467
|
+
|
|
329
468
|
this.emitEvent({ type: "clear" });
|
|
469
|
+
this.update(true);
|
|
330
470
|
|
|
331
471
|
return this;
|
|
332
472
|
}
|
|
@@ -335,17 +475,29 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
335
475
|
return this._activeDragger;
|
|
336
476
|
}
|
|
337
477
|
|
|
338
|
-
setActiveDragger(name
|
|
478
|
+
setActiveDragger(name = ""): IDragger | null {
|
|
339
479
|
if (!this._activeDragger || this._activeDragger.name !== name) {
|
|
340
480
|
if (this._activeDragger) {
|
|
341
481
|
this._activeDragger.dispose();
|
|
342
482
|
this._activeDragger = null;
|
|
343
483
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
484
|
+
if (this.isInitialized()) {
|
|
485
|
+
const Constructor = this.draggerFactory[name];
|
|
486
|
+
if (Constructor) {
|
|
487
|
+
this._activeDragger = new Constructor(this);
|
|
488
|
+
this._activeDragger.name = name;
|
|
489
|
+
}
|
|
348
490
|
}
|
|
491
|
+
const canvas = this.canvas;
|
|
492
|
+
if (canvas) {
|
|
493
|
+
canvas.className = canvas.className
|
|
494
|
+
.split(" ")
|
|
495
|
+
.filter((x) => !x.startsWith("oda-cursor-"))
|
|
496
|
+
.filter((x) => x)
|
|
497
|
+
.concat(`oda-cursor-${name.toLowerCase()}`)
|
|
498
|
+
.join(" ");
|
|
499
|
+
}
|
|
500
|
+
this.emitEvent({ type: "changeactivedragger", data: name });
|
|
349
501
|
}
|
|
350
502
|
return this._activeDragger;
|
|
351
503
|
}
|
|
@@ -353,22 +505,39 @@ export class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMap & Opti
|
|
|
353
505
|
resetActiveDragger(): void {
|
|
354
506
|
const dragger = this._activeDragger;
|
|
355
507
|
if (dragger) {
|
|
356
|
-
this.setActiveDragger(
|
|
508
|
+
this.setActiveDragger();
|
|
357
509
|
this.setActiveDragger(dragger.name);
|
|
358
510
|
}
|
|
359
511
|
}
|
|
360
512
|
|
|
361
513
|
is3D(): boolean {
|
|
362
|
-
return
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
getSelected(): string[] {
|
|
518
|
+
return this.executeCommand("getSelected");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
setSelected(handles?: string[]): void {
|
|
522
|
+
this.executeCommand("setSelected", handles);
|
|
363
523
|
}
|
|
364
524
|
|
|
365
525
|
executeCommand(id: string, ...args: any[]): any {
|
|
366
526
|
return commands("ThreeJS").executeCommand(id, this, ...args);
|
|
367
527
|
}
|
|
368
528
|
|
|
529
|
+
getComponent(type): any {
|
|
530
|
+
return this.components.find((component) => component instanceof type);
|
|
531
|
+
}
|
|
532
|
+
|
|
369
533
|
drawViewpoint(viewpoint: IViewpoint): void {}
|
|
370
534
|
|
|
371
535
|
createViewpoint(): IViewpoint {
|
|
372
|
-
|
|
536
|
+
const viewpoint: IViewpoint = {};
|
|
537
|
+
|
|
538
|
+
viewpoint.snapshot = { data: this.canvas?.toDataURL("image/jpeg", 0.25) };
|
|
539
|
+
viewpoint.description = new Date().toDateString();
|
|
540
|
+
|
|
541
|
+
return viewpoint;
|
|
373
542
|
}
|
|
374
543
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { Model, File, Assembly } from "@inweb/client";
|
|
25
|
+
import { commands } from "@inweb/viewer-core";
|
|
26
|
+
import type { Viewer } from "../Viewer";
|
|
27
|
+
|
|
28
|
+
// gltf root object don't have model handle
|
|
29
|
+
function applyModelTransform(viewer: Viewer, model: Model | File | Assembly) {
|
|
30
|
+
console.warn("applyModelTransform not implemented");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
commands("ThreeJS").registerCommand("applyModelTransform", applyModelTransform);
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
// markup should be as a separate library
|
|
28
|
+
commands("ThreeJS").registerCommand("clearMarkup", (viewer: Viewer) => console.warn("clearMarkup not implemented"));
|
|
29
|
+
commands("ThreeJS").registerCommandAlias("clearMarkup", "clearOverlay");
|
|
@@ -0,0 +1,32 @@
|
|
|
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 clearSlices(viewer: Viewer) {
|
|
28
|
+
viewer.renderer.clippingPlanes = [];
|
|
29
|
+
viewer.update();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
commands("ThreeJS").registerCommand("clearSlices", clearSlices);
|