@inweb/viewer-three 26.6.1 → 26.6.2

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.
@@ -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, MeshBasicMaterial, Object3D, Raycaster, Vector2 } from "three";
1
+ import { Intersection, Object3D, Raycaster, Vector2 } from "three";
2
2
  import { IComponent } from "@inweb/viewer-core";
3
- import type { Viewer } from "../Viewer";
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 facesMaterial: MeshBasicMaterial;
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
- optionsChange: () => void;
19
+ initHighlighter: () => void;
19
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-three",
3
- "version": "26.6.1",
3
+ "version": "26.6.2",
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.1",
35
- "@inweb/eventemitter2": "~26.6.1",
36
- "@inweb/markup": "~26.6.1",
37
- "@inweb/viewer-core": "~26.6.1"
34
+ "@inweb/client": "~26.6.2",
35
+ "@inweb/eventemitter2": "~26.6.2",
36
+ "@inweb/markup": "~26.6.2",
37
+ "@inweb/viewer-core": "~26.6.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/three": "^0.173.0",
@@ -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, MeshBasicMaterial, Object3D, Raycaster, Vector2 } from "three";
24
+ import { Intersection, Object3D, Raycaster, Vector2 } from "three";
25
25
 
26
26
  import { IComponent } from "@inweb/viewer-core";
27
- import type { Viewer } from "../Viewer";
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 facesMaterial: MeshBasicMaterial;
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("optionschange", this.optionsChange);
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("optionschange", this.optionsChange);
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
- object.originalMaterial = object.material;
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
- object.material = object.originalMaterial;
120
+ this.highlighter.unhighlight(object);
129
121
  });
130
122
  this.viewer.selected.length = 0;
131
123
  }
132
124
 
133
- optionsChange = () => {
134
- const { facesColor, facesTransparancy } = this.viewer.options;
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,7 @@ 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
86
 
85
87
  components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));