@inweb/viewer-three 26.6.1 → 26.6.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/plugins/loaders/IFCXLoader.js +60 -60
- package/dist/plugins/loaders/IFCXLoader.js.map +1 -1
- package/dist/plugins/loaders/IFCXLoader.min.js +1 -1
- package/dist/plugins/loaders/IFCXLoader.module.js +49 -49
- package/dist/plugins/loaders/IFCXLoader.module.js.map +1 -1
- package/dist/viewer-three.js +1386 -305
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +2 -2
- package/dist/viewer-three.module.js +191 -50
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +1 -1
- package/lib/Viewer/components/HighlighterComponent.d.ts +18 -0
- package/lib/Viewer/components/HighlighterUtils.d.ts +6 -0
- package/lib/Viewer/components/SelectionComponent.d.ts +5 -4
- package/lib/Viewer/loaders/{GLTFModelLoader.d.ts → GLTFCloudModelLoader.d.ts} +1 -1
- package/lib/Viewer/loaders/GLTFFileLoader.d.ts +1 -1
- package/package.json +5 -5
- package/plugins/loaders/{IFCXModelLoader.ts → IFCXCloudFileLoader.ts} +6 -6
- package/plugins/loaders/IFCXLoader.ts +2 -2
- package/src/Viewer/Viewer.ts +11 -11
- package/src/Viewer/components/HighlighterComponent.ts +159 -0
- package/src/Viewer/components/HighlighterUtils.ts +116 -0
- package/src/Viewer/components/SelectionComponent.ts +10 -22
- package/src/Viewer/components/index.ts +2 -1
- package/src/Viewer/loaders/{GLTFModelLoader.ts → GLTFCloudModelLoader.ts} +1 -1
- package/src/Viewer/loaders/GLTFFileLoader.ts +4 -4
- package/src/Viewer/loaders/index.ts +2 -2
package/lib/Viewer/Viewer.d.ts
CHANGED
|
@@ -151,6 +151,7 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
151
151
|
activeDragger(): IDragger | null;
|
|
152
152
|
setActiveDragger(name?: string): IDragger | null;
|
|
153
153
|
resetActiveDragger(): void;
|
|
154
|
+
getComponent(name: string): IComponent;
|
|
154
155
|
is3D(): boolean;
|
|
155
156
|
screenToWorld(position: {
|
|
156
157
|
x: number;
|
|
@@ -174,7 +175,6 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
|
|
|
174
175
|
z: number;
|
|
175
176
|
};
|
|
176
177
|
executeCommand(id: string, ...args: any[]): any;
|
|
177
|
-
getComponent(name: string): IComponent;
|
|
178
178
|
drawViewpoint(viewpoint: IViewpoint): void;
|
|
179
179
|
createViewpoint(): IViewpoint;
|
|
180
180
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LineBasicMaterial, MeshBasicMaterial } from "three";
|
|
2
|
+
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
|
|
3
|
+
import { IComponent, ResizeEvent } from "@inweb/viewer-core";
|
|
4
|
+
import { Viewer } from "../Viewer";
|
|
5
|
+
export declare class HighlighterComponent implements IComponent {
|
|
6
|
+
protected viewer: Viewer;
|
|
7
|
+
highlightMaterial: MeshBasicMaterial;
|
|
8
|
+
outlineMaterial: LineMaterial;
|
|
9
|
+
highlightLineMaterial: LineBasicMaterial;
|
|
10
|
+
highlightLineGlowMaterial: LineMaterial;
|
|
11
|
+
constructor(viewer: Viewer);
|
|
12
|
+
dispose(): void;
|
|
13
|
+
highlight(object: any): void;
|
|
14
|
+
unhighlight(object: any): void;
|
|
15
|
+
geometryEnd: () => void;
|
|
16
|
+
optionsChange: () => void;
|
|
17
|
+
viewerResize(event: ResizeEvent): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LineSegmentsGeometry } from "three/examples/jsm/lines/LineSegmentsGeometry.js";
|
|
2
|
+
export declare class HighlighterUtils {
|
|
3
|
+
static isBreak(positions: Float32Array, i: number): boolean;
|
|
4
|
+
static fromIndexedLine(positions: Float32Array, indices: number[]): LineSegmentsGeometry;
|
|
5
|
+
static fromNonIndexedLine(positions: Float32Array, isLineSegments: boolean): LineSegmentsGeometry;
|
|
6
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Intersection,
|
|
1
|
+
import { Intersection, Object3D, Raycaster, Vector2 } from "three";
|
|
2
2
|
import { IComponent } from "@inweb/viewer-core";
|
|
3
|
-
import
|
|
3
|
+
import { Viewer } from "../Viewer";
|
|
4
|
+
import { HighlighterComponent } from "./HighlighterComponent";
|
|
4
5
|
export declare class SelectionComponent implements IComponent {
|
|
5
6
|
protected viewer: Viewer;
|
|
6
7
|
protected raycaster: Raycaster;
|
|
7
8
|
protected downPosition: Vector2;
|
|
8
|
-
protected
|
|
9
|
+
protected highlighter: HighlighterComponent;
|
|
9
10
|
constructor(viewer: Viewer);
|
|
10
11
|
dispose(): void;
|
|
11
12
|
onPointerDown: (event: PointerEvent) => void;
|
|
@@ -15,5 +16,5 @@ export declare class SelectionComponent implements IComponent {
|
|
|
15
16
|
getPointerIntersects(mouse: Vector2): Array<Intersection<Object3D>>;
|
|
16
17
|
select(object: any): void;
|
|
17
18
|
clearSelection(): void;
|
|
18
|
-
|
|
19
|
+
initHighlighter: () => void;
|
|
19
20
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Loader } from "@inweb/viewer-core";
|
|
2
2
|
import { Viewer } from "../Viewer";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class GLTFCloudModelLoader extends Loader {
|
|
4
4
|
viewer: Viewer;
|
|
5
5
|
constructor(viewer: Viewer);
|
|
6
6
|
isSupport(model: any): boolean;
|
|
@@ -5,5 +5,5 @@ export declare class GLTFFileLoader extends Loader {
|
|
|
5
5
|
viewer: Viewer;
|
|
6
6
|
constructor(viewer: Viewer);
|
|
7
7
|
isSupport(file: any, format?: string): boolean;
|
|
8
|
-
load(
|
|
8
|
+
load(file: any, format?: string, params?: GLTFLoadParams): Promise<this>;
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-three",
|
|
3
|
-
"version": "26.6.
|
|
3
|
+
"version": "26.6.3",
|
|
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",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"docs": "typedoc"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@inweb/client": "~26.6.
|
|
35
|
-
"@inweb/eventemitter2": "~26.6.
|
|
36
|
-
"@inweb/markup": "~26.6.
|
|
37
|
-
"@inweb/viewer-core": "~26.6.
|
|
34
|
+
"@inweb/client": "~26.6.3",
|
|
35
|
+
"@inweb/eventemitter2": "~26.6.3",
|
|
36
|
+
"@inweb/markup": "~26.6.3",
|
|
37
|
+
"@inweb/viewer-core": "~26.6.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/three": "^0.173.0",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { Loader, Viewer } from "@inweb/viewer-three";
|
|
25
25
|
import { parse, clear } from "./IFCX/render.js";
|
|
26
26
|
|
|
27
|
-
export class
|
|
27
|
+
export class IFCXCloudFileLoader extends Loader {
|
|
28
28
|
public viewer: Viewer;
|
|
29
29
|
|
|
30
30
|
constructor(viewer: Viewer) {
|
|
@@ -41,12 +41,12 @@ export class IFCXModelLoader extends Loader {
|
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
override async load(
|
|
44
|
+
override async load(file: any): Promise<this> {
|
|
45
45
|
const progress = (progress: number) => {
|
|
46
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file
|
|
46
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
const arrayBuffer = await
|
|
49
|
+
const arrayBuffer = await file.download(progress, this.abortController.signal);
|
|
50
50
|
if (!this.viewer.scene) return this;
|
|
51
51
|
|
|
52
52
|
const textDecoder = new TextDecoder();
|
|
@@ -56,7 +56,7 @@ export class IFCXModelLoader extends Loader {
|
|
|
56
56
|
clear();
|
|
57
57
|
|
|
58
58
|
let handle = 0;
|
|
59
|
-
scene.traverse((object) => {
|
|
59
|
+
scene.traverse((object: any) => {
|
|
60
60
|
object.userData = { handle, ...object.userData };
|
|
61
61
|
handle++;
|
|
62
62
|
});
|
|
@@ -68,7 +68,7 @@ export class IFCXModelLoader extends Loader {
|
|
|
68
68
|
this.viewer.syncOverlay();
|
|
69
69
|
this.viewer.update();
|
|
70
70
|
|
|
71
|
-
this.viewer.emitEvent({ type: "databasechunk", data: scene, file
|
|
71
|
+
this.viewer.emitEvent({ type: "databasechunk", data: scene, file });
|
|
72
72
|
|
|
73
73
|
return this;
|
|
74
74
|
}
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
import { loaders } from "@inweb/viewer-three";
|
|
25
25
|
|
|
26
|
-
import { IFCXModelLoader } from "./IFCXModelLoader";
|
|
27
26
|
import { IFCXFileLoader } from "./IFCXFileLoader";
|
|
27
|
+
import { IFCXCloudFileLoader } from "./IFCXCloudFileLoader";
|
|
28
28
|
|
|
29
|
-
loaders.registerLoader("ifcx", (viewer: any) => new IFCXModelLoader(viewer));
|
|
30
29
|
loaders.registerLoader("ifcx-file", (viewer: any) => new IFCXFileLoader(viewer));
|
|
30
|
+
loaders.registerLoader("ifcx-cloud-file", (viewer: any) => new IFCXCloudFileLoader(viewer));
|
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -192,15 +192,15 @@ export class Viewer
|
|
|
192
192
|
|
|
193
193
|
dispose(): this {
|
|
194
194
|
this.cancel();
|
|
195
|
-
this.
|
|
195
|
+
this.clear();
|
|
196
196
|
|
|
197
|
-
this.
|
|
198
|
-
this.
|
|
197
|
+
this.emitEvent({ type: "dispose" });
|
|
198
|
+
this.removeAllListeners();
|
|
199
199
|
|
|
200
200
|
this.setActiveDragger();
|
|
201
|
-
this.removeAllListeners();
|
|
202
201
|
|
|
203
|
-
this.
|
|
202
|
+
this._components.forEach((component: IComponent) => component.dispose());
|
|
203
|
+
this._components = [];
|
|
204
204
|
|
|
205
205
|
this._markup.dispose();
|
|
206
206
|
|
|
@@ -211,10 +211,10 @@ export class Viewer
|
|
|
211
211
|
|
|
212
212
|
if (this.renderer) this.renderer.dispose();
|
|
213
213
|
|
|
214
|
+
this.helpers = undefined;
|
|
215
|
+
this.scene = undefined;
|
|
214
216
|
this.renderer = undefined;
|
|
215
217
|
this.camera = undefined;
|
|
216
|
-
this.scene = undefined;
|
|
217
|
-
this.helpers = undefined;
|
|
218
218
|
|
|
219
219
|
return this;
|
|
220
220
|
}
|
|
@@ -535,6 +535,10 @@ export class Viewer
|
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
537
|
|
|
538
|
+
getComponent(name: string): IComponent {
|
|
539
|
+
return this._components.find((component) => component.name === name);
|
|
540
|
+
}
|
|
541
|
+
|
|
538
542
|
is3D(): boolean {
|
|
539
543
|
return true;
|
|
540
544
|
}
|
|
@@ -573,10 +577,6 @@ export class Viewer
|
|
|
573
577
|
return commands.executeCommand(id, this, ...args);
|
|
574
578
|
}
|
|
575
579
|
|
|
576
|
-
getComponent(name: string): IComponent {
|
|
577
|
-
return this._components.find((component) => component.name === name);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
580
|
drawViewpoint(viewpoint: IViewpoint): void {
|
|
581
581
|
if (!this.renderer) return;
|
|
582
582
|
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
import { Color, EdgesGeometry, LineBasicMaterial, MeshBasicMaterial, Vector2 } from "three";
|
|
25
|
+
import { LineSegmentsGeometry } from "three/examples/jsm/lines/LineSegmentsGeometry.js";
|
|
26
|
+
import { Wireframe } from "three/examples/jsm/lines/Wireframe.js";
|
|
27
|
+
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
|
|
28
|
+
|
|
29
|
+
import { IComponent, ResizeEvent } from "@inweb/viewer-core";
|
|
30
|
+
import { Viewer } from "../Viewer";
|
|
31
|
+
import { HighlighterUtils } from "./HighlighterUtils";
|
|
32
|
+
|
|
33
|
+
export class HighlighterComponent implements IComponent {
|
|
34
|
+
protected viewer: Viewer;
|
|
35
|
+
public highlightMaterial: MeshBasicMaterial;
|
|
36
|
+
public outlineMaterial: LineMaterial;
|
|
37
|
+
public highlightLineMaterial: LineBasicMaterial;
|
|
38
|
+
public highlightLineGlowMaterial: LineMaterial;
|
|
39
|
+
|
|
40
|
+
constructor(viewer: Viewer) {
|
|
41
|
+
this.viewer = viewer;
|
|
42
|
+
|
|
43
|
+
this.viewer.addEventListener("databasechunk", this.geometryEnd);
|
|
44
|
+
this.viewer.addEventListener("optionschange", this.optionsChange);
|
|
45
|
+
this.viewer.addEventListener("resize", this.viewerResize);
|
|
46
|
+
|
|
47
|
+
this.geometryEnd();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
dispose() {
|
|
51
|
+
this.viewer.removeEventListener("databasechunk", this.geometryEnd);
|
|
52
|
+
this.viewer.removeEventListener("optionschange", this.optionsChange);
|
|
53
|
+
this.viewer.removeEventListener("resize", this.viewerResize);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
highlight(object: any) {
|
|
57
|
+
if (object.isHighlighted) return;
|
|
58
|
+
|
|
59
|
+
if (object.isLine || object.isLineSegments) {
|
|
60
|
+
const positions = object.geometry.attributes.position.array;
|
|
61
|
+
const indices = object.geometry.index ? object.geometry.index.array : null;
|
|
62
|
+
const lineGeometry = indices
|
|
63
|
+
? HighlighterUtils.fromIndexedLine(positions, indices)
|
|
64
|
+
: HighlighterUtils.fromNonIndexedLine(positions, object.isLineSegments);
|
|
65
|
+
|
|
66
|
+
const wireframe = new Wireframe(lineGeometry, this.highlightLineGlowMaterial);
|
|
67
|
+
wireframe.position.copy(object.position);
|
|
68
|
+
wireframe.rotation.copy(object.rotation);
|
|
69
|
+
wireframe.scale.copy(object.scale);
|
|
70
|
+
|
|
71
|
+
object.parent.add(wireframe);
|
|
72
|
+
|
|
73
|
+
object.userData.highlightwireframe = wireframe;
|
|
74
|
+
object.userData.originalMaterial = object.material;
|
|
75
|
+
object.material = this.highlightLineMaterial;
|
|
76
|
+
object.isHighlighted = true;
|
|
77
|
+
} else if (object.isMesh) {
|
|
78
|
+
const edgesGeometry = new EdgesGeometry(object.geometry, 30);
|
|
79
|
+
const lineGeometry = new LineSegmentsGeometry().fromEdgesGeometry(edgesGeometry);
|
|
80
|
+
|
|
81
|
+
const wireframe = new Wireframe(lineGeometry, this.outlineMaterial);
|
|
82
|
+
wireframe.position.copy(object.position);
|
|
83
|
+
wireframe.rotation.copy(object.rotation);
|
|
84
|
+
wireframe.scale.copy(object.scale);
|
|
85
|
+
|
|
86
|
+
object.parent.add(wireframe);
|
|
87
|
+
|
|
88
|
+
object.userData.highlightwireframe = wireframe;
|
|
89
|
+
object.userData.originalMaterial = object.material;
|
|
90
|
+
object.material = this.highlightMaterial;
|
|
91
|
+
object.isHighlighted = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
unhighlight(object: any) {
|
|
96
|
+
if (!object.isHighlighted) return;
|
|
97
|
+
|
|
98
|
+
object.isHighlighted = false;
|
|
99
|
+
object.material = object.userData.originalMaterial;
|
|
100
|
+
object.userData.highlightwireframe.removeFromParent();
|
|
101
|
+
|
|
102
|
+
delete object.userData.originalMaterial;
|
|
103
|
+
delete object.userData.highlightwireframe;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
geometryEnd = () => {
|
|
107
|
+
const { facesColor, facesTransparancy, edgesColor } = this.viewer.options;
|
|
108
|
+
|
|
109
|
+
this.highlightMaterial = new MeshBasicMaterial({
|
|
110
|
+
color: new Color(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255),
|
|
111
|
+
transparent: true,
|
|
112
|
+
opacity: (255 - facesTransparancy) / 255,
|
|
113
|
+
depthTest: false,
|
|
114
|
+
depthWrite: false,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
this.outlineMaterial = new LineMaterial({
|
|
118
|
+
color: new Color(edgesColor.r / 255, edgesColor.g / 255, edgesColor.b / 255),
|
|
119
|
+
linewidth: 1.5,
|
|
120
|
+
depthTest: false,
|
|
121
|
+
depthWrite: false,
|
|
122
|
+
resolution: new Vector2(window.innerWidth, window.innerHeight),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
this.highlightLineMaterial = new LineBasicMaterial({
|
|
126
|
+
color: new Color(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255),
|
|
127
|
+
depthTest: false,
|
|
128
|
+
depthWrite: false,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
this.highlightLineGlowMaterial = new LineMaterial({
|
|
132
|
+
color: new Color(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255),
|
|
133
|
+
linewidth: 5,
|
|
134
|
+
transparent: true,
|
|
135
|
+
opacity: 0.8,
|
|
136
|
+
depthTest: true,
|
|
137
|
+
depthWrite: true,
|
|
138
|
+
resolution: new Vector2(window.innerWidth, window.innerHeight),
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
optionsChange = () => {
|
|
143
|
+
const { facesColor, facesTransparancy, edgesColor } = this.viewer.options;
|
|
144
|
+
|
|
145
|
+
this.highlightMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
146
|
+
this.highlightMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
147
|
+
this.outlineMaterial.color.setRGB(edgesColor.r / 255, edgesColor.g / 255, edgesColor.b / 255);
|
|
148
|
+
this.highlightLineMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
149
|
+
this.highlightLineGlowMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
150
|
+
|
|
151
|
+
this.viewer.update();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
viewerResize(event: ResizeEvent) {
|
|
155
|
+
if (!this.outlineMaterial) return;
|
|
156
|
+
|
|
157
|
+
this.outlineMaterial.resolution.set(event.width, event.height);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
import { LineSegmentsGeometry } from "three/examples/jsm/lines/LineSegmentsGeometry.js";
|
|
25
|
+
|
|
26
|
+
export class HighlighterUtils {
|
|
27
|
+
static isBreak(positions: Float32Array, i: number) {
|
|
28
|
+
return (
|
|
29
|
+
isNaN(positions[i]) ||
|
|
30
|
+
isNaN(positions[i + 1]) ||
|
|
31
|
+
isNaN(positions[i + 2]) ||
|
|
32
|
+
positions[i] === Infinity ||
|
|
33
|
+
positions[i] === -Infinity ||
|
|
34
|
+
positions[i + 1] === Infinity ||
|
|
35
|
+
positions[i + 1] === -Infinity ||
|
|
36
|
+
positions[i + 2] === Infinity ||
|
|
37
|
+
positions[i + 2] === -Infinity
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static fromIndexedLine(positions: Float32Array, indices: number[]) {
|
|
42
|
+
const lineGeometry = new LineSegmentsGeometry();
|
|
43
|
+
const segments = [];
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < indices.length; i += 2) {
|
|
46
|
+
const idx1 = indices[i] * 3;
|
|
47
|
+
const idx2 = indices[i + 1] * 3;
|
|
48
|
+
|
|
49
|
+
if (indices[i] === -1 || indices[i + 1] === -1) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
segments.push(
|
|
54
|
+
positions[idx1],
|
|
55
|
+
positions[idx1 + 1],
|
|
56
|
+
positions[idx1 + 2],
|
|
57
|
+
positions[idx2],
|
|
58
|
+
positions[idx2 + 1],
|
|
59
|
+
positions[idx2 + 2]
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (segments.length === 0) return null;
|
|
64
|
+
|
|
65
|
+
lineGeometry.setPositions(segments);
|
|
66
|
+
return lineGeometry;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static fromNonIndexedLine(positions: Float32Array, isLineSegments: boolean) {
|
|
70
|
+
const lineGeometry = new LineSegmentsGeometry();
|
|
71
|
+
const segments = [];
|
|
72
|
+
|
|
73
|
+
if (isLineSegments) {
|
|
74
|
+
for (let i = 0; i < positions.length; i += 6) {
|
|
75
|
+
if (i + 5 >= positions.length) break;
|
|
76
|
+
|
|
77
|
+
if (HighlighterUtils.isBreak(positions, i) || HighlighterUtils.isBreak(positions, i + 3)) continue;
|
|
78
|
+
|
|
79
|
+
segments.push(
|
|
80
|
+
positions[i],
|
|
81
|
+
positions[i + 1],
|
|
82
|
+
positions[i + 2],
|
|
83
|
+
positions[i + 3],
|
|
84
|
+
positions[i + 4],
|
|
85
|
+
positions[i + 5]
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
let lastValidIndex = -1;
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
92
|
+
if (HighlighterUtils.isBreak(positions, i)) {
|
|
93
|
+
lastValidIndex = -1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (lastValidIndex !== -1) {
|
|
98
|
+
segments.push(
|
|
99
|
+
positions[lastValidIndex],
|
|
100
|
+
positions[lastValidIndex + 1],
|
|
101
|
+
positions[lastValidIndex + 2],
|
|
102
|
+
positions[i],
|
|
103
|
+
positions[i + 1],
|
|
104
|
+
positions[i + 2]
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
lastValidIndex = i;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (segments.length === 0) return null;
|
|
112
|
+
|
|
113
|
+
lineGeometry.setPositions(segments);
|
|
114
|
+
return lineGeometry;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -21,41 +21,34 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { Intersection,
|
|
24
|
+
import { Intersection, Object3D, Raycaster, Vector2 } from "three";
|
|
25
25
|
|
|
26
26
|
import { IComponent } from "@inweb/viewer-core";
|
|
27
|
-
import
|
|
27
|
+
import { Viewer } from "../Viewer";
|
|
28
|
+
import { HighlighterComponent } from "./HighlighterComponent";
|
|
28
29
|
|
|
29
30
|
export class SelectionComponent implements IComponent {
|
|
30
31
|
protected viewer: Viewer;
|
|
31
32
|
protected raycaster: Raycaster;
|
|
32
33
|
protected downPosition: Vector2;
|
|
33
|
-
protected
|
|
34
|
+
protected highlighter: HighlighterComponent;
|
|
34
35
|
|
|
35
36
|
constructor(viewer: Viewer) {
|
|
36
37
|
this.viewer = viewer;
|
|
37
38
|
this.raycaster = new Raycaster();
|
|
38
39
|
this.downPosition = new Vector2();
|
|
39
40
|
|
|
40
|
-
const { facesColor, facesTransparancy } = this.viewer.options;
|
|
41
|
-
this.facesMaterial = new MeshBasicMaterial();
|
|
42
|
-
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
43
|
-
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
44
|
-
this.facesMaterial.transparent = true;
|
|
45
|
-
|
|
46
41
|
this.viewer.addEventListener("pointerdown", this.onPointerDown);
|
|
47
42
|
this.viewer.addEventListener("pointerup", this.onPointerUp);
|
|
48
43
|
this.viewer.addEventListener("dblclick", this.onDoubleClick);
|
|
49
|
-
this.viewer.addEventListener("
|
|
44
|
+
this.viewer.addEventListener("initialize", this.initHighlighter);
|
|
50
45
|
}
|
|
51
46
|
|
|
52
47
|
dispose() {
|
|
53
|
-
this.facesMaterial.dispose();
|
|
54
|
-
|
|
55
48
|
this.viewer.removeEventListener("pointerdown", this.onPointerDown);
|
|
56
49
|
this.viewer.removeEventListener("pointerup", this.onPointerUp);
|
|
57
50
|
this.viewer.removeEventListener("dblclick", this.onDoubleClick);
|
|
58
|
-
this.viewer.removeEventListener("
|
|
51
|
+
this.viewer.removeEventListener("initialize", this.initHighlighter);
|
|
59
52
|
}
|
|
60
53
|
|
|
61
54
|
onPointerDown = (event: PointerEvent) => {
|
|
@@ -116,8 +109,7 @@ export class SelectionComponent implements IComponent {
|
|
|
116
109
|
if (object.isSelected) return;
|
|
117
110
|
|
|
118
111
|
object.isSelected = true;
|
|
119
|
-
|
|
120
|
-
object.material = this.facesMaterial;
|
|
112
|
+
this.highlighter.highlight(object);
|
|
121
113
|
|
|
122
114
|
this.viewer.selected.push(object);
|
|
123
115
|
}
|
|
@@ -125,16 +117,12 @@ export class SelectionComponent implements IComponent {
|
|
|
125
117
|
clearSelection() {
|
|
126
118
|
this.viewer.selected.forEach((object: any) => {
|
|
127
119
|
object.isSelected = false;
|
|
128
|
-
|
|
120
|
+
this.highlighter.unhighlight(object);
|
|
129
121
|
});
|
|
130
122
|
this.viewer.selected.length = 0;
|
|
131
123
|
}
|
|
132
124
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.facesMaterial.color.setRGB(facesColor.r / 255, facesColor.g / 255, facesColor.b / 255);
|
|
136
|
-
this.facesMaterial.opacity = (255 - facesTransparancy) / 255;
|
|
137
|
-
|
|
138
|
-
this.viewer.update();
|
|
125
|
+
initHighlighter = () => {
|
|
126
|
+
this.highlighter = this.viewer.getComponent("HighlighterComponent") as any;
|
|
139
127
|
};
|
|
140
128
|
}
|
|
@@ -29,6 +29,7 @@ import { ExtentsComponent } from "./ExtentsComponent";
|
|
|
29
29
|
import { LightComponent } from "./LightComponent";
|
|
30
30
|
import { RenderLoopComponent } from "./RenderLoopComponent";
|
|
31
31
|
import { ResizeCanvasComponent } from "./ResizeCanvasComponent";
|
|
32
|
+
import { HighlighterComponent } from "./HighlighterComponent";
|
|
32
33
|
import { SelectionComponent } from "./SelectionComponent";
|
|
33
34
|
import { WCSHelperComponent } from "./WCSHelperComponent";
|
|
34
35
|
|
|
@@ -80,6 +81,6 @@ components.registerComponent("BackgroundComponent", (viewer) => new BackgroundCo
|
|
|
80
81
|
components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
|
|
81
82
|
components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
|
|
82
83
|
components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
|
|
84
|
+
components.registerComponent("HighlighterComponent", (viewer) => new HighlighterComponent(viewer));
|
|
83
85
|
components.registerComponent("SelectionComponent", (viewer) => new SelectionComponent(viewer));
|
|
84
|
-
|
|
85
86
|
components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
|
|
@@ -27,7 +27,7 @@ import { Loader } from "@inweb/viewer-core";
|
|
|
27
27
|
import { Viewer } from "../Viewer";
|
|
28
28
|
import { GLTFLoadingManager } from "./GLTFLoadingManager";
|
|
29
29
|
|
|
30
|
-
export class
|
|
30
|
+
export class GLTFCloudModelLoader extends Loader {
|
|
31
31
|
public viewer: Viewer;
|
|
32
32
|
|
|
33
33
|
constructor(viewer: Viewer) {
|
|
@@ -42,8 +42,8 @@ export class GLTFFileLoader extends Loader {
|
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
override async load(
|
|
46
|
-
const manager = new GLTFLoadingManager(
|
|
45
|
+
override async load(file: any, format?: string, params?: GLTFLoadParams): Promise<this> {
|
|
46
|
+
const manager = new GLTFLoadingManager(file, params);
|
|
47
47
|
|
|
48
48
|
const loader = new GLTFLoader(manager);
|
|
49
49
|
loader.setPath(manager.path);
|
|
@@ -53,7 +53,7 @@ export class GLTFFileLoader extends Loader {
|
|
|
53
53
|
const progress = (event: ProgressEvent) => {
|
|
54
54
|
const { lengthComputable, loaded, total } = event;
|
|
55
55
|
const progress = lengthComputable ? loaded / total : 1;
|
|
56
|
-
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file
|
|
56
|
+
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
const gltf = await loader.loadAsync(manager.fileURL, progress);
|
|
@@ -66,7 +66,7 @@ export class GLTFFileLoader extends Loader {
|
|
|
66
66
|
this.viewer.syncOverlay();
|
|
67
67
|
this.viewer.update();
|
|
68
68
|
|
|
69
|
-
this.viewer.emitEvent({ type: "databasechunk", data: gltf.scene, file
|
|
69
|
+
this.viewer.emitEvent({ type: "databasechunk", data: gltf.scene, file });
|
|
70
70
|
|
|
71
71
|
return this;
|
|
72
72
|
}
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
import { ILoadersRegistry, loadersRegistry } from "@inweb/viewer-core";
|
|
25
25
|
|
|
26
|
-
import { GLTFModelLoader } from "./GLTFModelLoader";
|
|
27
26
|
import { GLTFFileLoader } from "./GLTFFileLoader";
|
|
27
|
+
import { GLTFCloudModelLoader } from "./GLTFCloudModelLoader";
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Viewer loaders registry. Use this registry to register custom loaders.
|
|
@@ -95,5 +95,5 @@ export const loaders: ILoadersRegistry = loadersRegistry("threejs");
|
|
|
95
95
|
|
|
96
96
|
// build-in loaders
|
|
97
97
|
|
|
98
|
-
loaders.registerLoader("gltf", (viewer: any) => new GLTFModelLoader(viewer));
|
|
99
98
|
loaders.registerLoader("gltf-file", (viewer: any) => new GLTFFileLoader(viewer));
|
|
99
|
+
loaders.registerLoader("gltf-cloud-model", (viewer: any) => new GLTFCloudModelLoader(viewer));
|