@inweb/viewer-three 27.12.0 → 27.12.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.
@@ -1,6 +1,7 @@
1
1
  import { Box3, Object3D } from "three";
2
2
  import { IInfo } from "@inweb/viewer-core";
3
3
  import { ModelImpl } from "../../models/ModelImpl";
4
+ import { IHighlightStyle } from "../../models/ModelImpl.types";
4
5
  import { DynamicGltfLoader } from "./DynamicGltfLoader.js";
5
6
  export declare class DynamicModelImpl extends ModelImpl {
6
7
  gltfLoader: DynamicGltfLoader;
@@ -16,7 +17,8 @@ export declare class DynamicModelImpl extends ModelImpl {
16
17
  isolate(handles: string[]): this;
17
18
  show(handles: string[]): this;
18
19
  showAll(): this;
19
- highlight(handles: string[]): this;
20
+ highlight(handles: string[], style?: string): this;
20
21
  unhighlight(handles: string[]): this;
22
+ setHighlightStyle(name: string, style: IHighlightStyle): this;
21
23
  explode(scale?: number, coeff?: number): this;
22
24
  }
@@ -1,6 +1,6 @@
1
1
  import { Box3, Object3D } from "three";
2
2
  import { IInfo } from "@inweb/viewer-core";
3
- import { IModelImpl } from "./ModelImpl.types";
3
+ import { IHighlightStyle, IModelImpl } from "./ModelImpl.types";
4
4
  import { IHighlighter } from "./Highlighter.types";
5
5
  export declare class ModelImpl implements IModelImpl {
6
6
  id: string;
@@ -27,7 +27,8 @@ export declare class ModelImpl implements IModelImpl {
27
27
  isolate(handles: string[]): this;
28
28
  show(handles: string[]): this;
29
29
  showAll(): this;
30
- highlight(handles: string[]): this;
30
+ highlight(handles: string[], style?: string): this;
31
31
  unhighlight(handles: string[]): this;
32
+ setHighlightStyle(name: string, style: IHighlightStyle): this;
32
33
  explode(scale?: number, coeff?: number): this;
33
34
  }
@@ -1,6 +1,62 @@
1
- import { Box3, Object3D } from "three";
1
+ import { Box3, ColorRepresentation, Object3D } from "three";
2
2
  import { IInfo, IModel } from "@inweb/viewer-core";
3
3
  import { IHighlighter } from "./Highlighter.types";
4
+ /**
5
+ * Highlight style of a model, see {@link IModelImpl.setHighlightStyle}. Unset settings take their default
6
+ * values.
7
+ *
8
+ * The style applies to the faces, lines and points of the highlighted objects (fill settings) and to
9
+ * their edges, the model edges drawn with the `edgeModel` option (line settings).
10
+ */
11
+ export interface IHighlightStyle {
12
+ /**
13
+ * Fill color. Default is `0x4aa9fa`.
14
+ */
15
+ fillColor?: ColorRepresentation;
16
+ /**
17
+ * Blend of the object color with the fill color, from `0` (object color) to `1` (fill color). Default
18
+ * is `1`.
19
+ */
20
+ fillMix?: number;
21
+ /**
22
+ * Opacity of the highlighted objects, from `0` to `1`, or `-1` to keep the opacity of their materials.
23
+ * Default is `-1`.
24
+ */
25
+ fillOpacity?: number;
26
+ /**
27
+ * Edge color. Default is the fill color.
28
+ */
29
+ lineColor?: ColorRepresentation;
30
+ /**
31
+ * Blend of the edge color with the line color, from `0` (edge color) to `1` (line color). Default is
32
+ * `1`.
33
+ */
34
+ lineMix?: number;
35
+ /**
36
+ * Intensity of the fill color added on top of the lighting, a glow. Default is `0`.
37
+ */
38
+ emissiveIntensity?: number;
39
+ /**
40
+ * Sets both {@link facesOverlay} and {@link edgesOverlay}.
41
+ */
42
+ overlay?: boolean;
43
+ /**
44
+ * Draws the faces, lines and points of the highlighted objects once more, in the fill color with the
45
+ * {@link overlayOpacity}, over all other geometry. The objects themselves then keep their colors.
46
+ * Default is `true`.
47
+ */
48
+ facesOverlay?: boolean;
49
+ /**
50
+ * Draws the edges of the highlighted objects once more, in the line color with the
51
+ * {@link overlayOpacity}, over all other geometry. The edges themselves then keep their colors. Default
52
+ * is `true`.
53
+ */
54
+ edgesOverlay?: boolean;
55
+ /**
56
+ * Opacity of the geometry drawn over all other geometry, from `0` to `1`. Default is `1`.
57
+ */
58
+ overlayOpacity?: number;
59
+ }
4
60
  /**
5
61
  * Basic model implementation.
6
62
  */
@@ -19,4 +75,29 @@ export interface IModelImpl extends IModel {
19
75
  getObjectsByHandles(handles: string[]): Object3D[];
20
76
  getHandles(): string[];
21
77
  getHandlesByObjects(objects: Object3D[]): string[];
78
+ /**
79
+ * Highlights the specified objects.
80
+ *
81
+ * An object is highlighted in one style: highlighting it again replaces its style, and
82
+ * {@link unhighlight} removes it. The viewer selection highlights objects in the default style.
83
+ *
84
+ * @param handles - The list of object handles.
85
+ * @param style - Name of a highlight style added by {@link setHighlightStyle}. Omitted, the objects are
86
+ * highlighted in the default style, set by the highlight options of the viewer. Objects are not
87
+ * highlighted in an unknown style. Models that do not support highlight styles ignore the style.
88
+ */
89
+ highlight(handles: string[], style?: string): this;
90
+ /**
91
+ * Adds a named highlight style, or changes it. The objects highlighted in this style are redrawn with
92
+ * the new settings.
93
+ *
94
+ * A model holds up to 8 highlight styles, the default one included; a new style beyond that is
95
+ * ignored. Styles cannot be removed, so set the same names again to change them. The default style is
96
+ * named `default` and is changed by the highlight options of the viewer. Models that do not support
97
+ * highlight styles ignore this method.
98
+ *
99
+ * @param name - Style name.
100
+ * @param style - Style settings. Unset settings take their default values, not the values set before.
101
+ */
102
+ setHighlightStyle(name: string, style: IHighlightStyle): this;
22
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-three",
3
- "version": "27.12.0",
3
+ "version": "27.12.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",
@@ -35,10 +35,10 @@
35
35
  "docs": "typedoc"
36
36
  },
37
37
  "dependencies": {
38
- "@inweb/client": "~27.12.0",
39
- "@inweb/eventemitter2": "~27.12.0",
40
- "@inweb/markup": "~27.12.0",
41
- "@inweb/viewer-core": "~27.12.0"
38
+ "@inweb/client": "~27.12.2",
39
+ "@inweb/eventemitter2": "~27.12.2",
40
+ "@inweb/markup": "~27.12.2",
41
+ "@inweb/viewer-core": "~27.12.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@streamparser/json": "^0.0.22",
@@ -1710,7 +1710,9 @@ export class DynamicGltfLoader {
1710
1710
  uniform highp sampler2D highlightTexture;
1711
1711
  uniform float objectStateTextureSize;
1712
1712
  varying vec4 vColorOverride;
1713
- varying float vHighlightStyle;
1713
+ // The style index is the same for all vertices of an object. Interpolated, it can come out just below the
1714
+ // integer, and int() then picks the previous style (pixel noise on some GPUs, e.g. SwiftShader).
1715
+ flat varying float vHighlightStyle;
1714
1716
 
1715
1717
  ivec2 getObjectStateCoord(float instanceId) {
1716
1718
  int size = int(objectStateTextureSize);
@@ -1779,7 +1781,7 @@ export class DynamicGltfLoader {
1779
1781
  #include <common>
1780
1782
  varying float vVisibility;
1781
1783
  varying vec4 vColorOverride;
1782
- varying float vHighlightStyle;
1784
+ flat varying float vHighlightStyle;
1783
1785
  uniform vec4 highlightStyles[${MAX_HIGHLIGHT_STYLES * HIGHLIGHT_STYLE_VEC4_COUNT}];
1784
1786
 
1785
1787
  // Edges color for the "edges" material, faces color for everything else
@@ -25,6 +25,7 @@ import { Box3, Matrix4, Object3D, Vector3 } from "three";
25
25
  import { IInfo, Info } from "@inweb/viewer-core";
26
26
 
27
27
  import { ModelImpl } from "../../models/ModelImpl";
28
+ import { IHighlightStyle } from "../../models/ModelImpl.types";
28
29
  import { DynamicGltfLoader } from "./DynamicGltfLoader.js";
29
30
 
30
31
  // Dynamic model implementation.
@@ -111,8 +112,8 @@ export class DynamicModelImpl extends ModelImpl {
111
112
  return this;
112
113
  }
113
114
 
114
- override highlight(handles: string[]): this {
115
- this.gltfLoader.highlightObjects(handles);
115
+ override highlight(handles: string[], style?: string): this {
116
+ this.gltfLoader.highlightObjects(handles, style);
116
117
  return this;
117
118
  }
118
119
 
@@ -121,6 +122,11 @@ export class DynamicModelImpl extends ModelImpl {
121
122
  return this;
122
123
  }
123
124
 
125
+ override setHighlightStyle(name: string, style: IHighlightStyle): this {
126
+ this.gltfLoader.setHighlightStyle(name, style);
127
+ return this;
128
+ }
129
+
124
130
  override explode(scale = 0, coeff = 4): this {
125
131
  const centersCache = new Map();
126
132
 
@@ -24,7 +24,7 @@
24
24
  import { Box3, Object3D, Vector3 } from "three";
25
25
  import { IInfo, Info } from "@inweb/viewer-core";
26
26
 
27
- import { IModelImpl } from "./ModelImpl.types";
27
+ import { IHighlightStyle, IModelImpl } from "./ModelImpl.types";
28
28
  import { IHighlighter } from "./Highlighter.types";
29
29
  import { convertUnits } from "../measurement/UnitConverter";
30
30
  import { getDisplayUnit } from "../measurement/UnitFormatter";
@@ -399,7 +399,8 @@ export class ModelImpl implements IModelImpl {
399
399
  return this;
400
400
  }
401
401
 
402
- highlight(handles: string[]): this {
402
+ // The highlighter of the viewer has one style, the style of the default highlight.
403
+ highlight(handles: string[], style?: string): this {
403
404
  if (this.highlighter) {
404
405
  const objects = this.getObjectsByHandles(handles);
405
406
  this.highlighter.highlightObjects(objects);
@@ -415,6 +416,10 @@ export class ModelImpl implements IModelImpl {
415
416
  return this;
416
417
  }
417
418
 
419
+ setHighlightStyle(name: string, style: IHighlightStyle): this {
420
+ return this;
421
+ }
422
+
418
423
  explode(scale = 0, coeff = 4): this {
419
424
  const centersCache = new Map();
420
425
 
@@ -21,11 +21,77 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Box3, Object3D } from "three";
24
+ import { Box3, ColorRepresentation, Object3D } from "three";
25
25
  import { IInfo, IModel } from "@inweb/viewer-core";
26
26
 
27
27
  import { IHighlighter } from "./Highlighter.types";
28
28
 
29
+ /**
30
+ * Highlight style of a model, see {@link IModelImpl.setHighlightStyle}. Unset settings take their default
31
+ * values.
32
+ *
33
+ * The style applies to the faces, lines and points of the highlighted objects (fill settings) and to
34
+ * their edges, the model edges drawn with the `edgeModel` option (line settings).
35
+ */
36
+ export interface IHighlightStyle {
37
+ /**
38
+ * Fill color. Default is `0x4aa9fa`.
39
+ */
40
+ fillColor?: ColorRepresentation;
41
+
42
+ /**
43
+ * Blend of the object color with the fill color, from `0` (object color) to `1` (fill color). Default
44
+ * is `1`.
45
+ */
46
+ fillMix?: number;
47
+
48
+ /**
49
+ * Opacity of the highlighted objects, from `0` to `1`, or `-1` to keep the opacity of their materials.
50
+ * Default is `-1`.
51
+ */
52
+ fillOpacity?: number;
53
+
54
+ /**
55
+ * Edge color. Default is the fill color.
56
+ */
57
+ lineColor?: ColorRepresentation;
58
+
59
+ /**
60
+ * Blend of the edge color with the line color, from `0` (edge color) to `1` (line color). Default is
61
+ * `1`.
62
+ */
63
+ lineMix?: number;
64
+
65
+ /**
66
+ * Intensity of the fill color added on top of the lighting, a glow. Default is `0`.
67
+ */
68
+ emissiveIntensity?: number;
69
+
70
+ /**
71
+ * Sets both {@link facesOverlay} and {@link edgesOverlay}.
72
+ */
73
+ overlay?: boolean;
74
+
75
+ /**
76
+ * Draws the faces, lines and points of the highlighted objects once more, in the fill color with the
77
+ * {@link overlayOpacity}, over all other geometry. The objects themselves then keep their colors.
78
+ * Default is `true`.
79
+ */
80
+ facesOverlay?: boolean;
81
+
82
+ /**
83
+ * Draws the edges of the highlighted objects once more, in the line color with the
84
+ * {@link overlayOpacity}, over all other geometry. The edges themselves then keep their colors. Default
85
+ * is `true`.
86
+ */
87
+ edgesOverlay?: boolean;
88
+
89
+ /**
90
+ * Opacity of the geometry drawn over all other geometry, from `0` to `1`. Default is `1`.
91
+ */
92
+ overlayOpacity?: number;
93
+ }
94
+
29
95
  /**
30
96
  * Basic model implementation.
31
97
  */
@@ -56,4 +122,31 @@ export interface IModelImpl extends IModel {
56
122
  getHandles(): string[];
57
123
 
58
124
  getHandlesByObjects(objects: Object3D[]): string[];
125
+
126
+ /**
127
+ * Highlights the specified objects.
128
+ *
129
+ * An object is highlighted in one style: highlighting it again replaces its style, and
130
+ * {@link unhighlight} removes it. The viewer selection highlights objects in the default style.
131
+ *
132
+ * @param handles - The list of object handles.
133
+ * @param style - Name of a highlight style added by {@link setHighlightStyle}. Omitted, the objects are
134
+ * highlighted in the default style, set by the highlight options of the viewer. Objects are not
135
+ * highlighted in an unknown style. Models that do not support highlight styles ignore the style.
136
+ */
137
+ highlight(handles: string[], style?: string): this;
138
+
139
+ /**
140
+ * Adds a named highlight style, or changes it. The objects highlighted in this style are redrawn with
141
+ * the new settings.
142
+ *
143
+ * A model holds up to 8 highlight styles, the default one included; a new style beyond that is
144
+ * ignored. Styles cannot be removed, so set the same names again to change them. The default style is
145
+ * named `default` and is changed by the highlight options of the viewer. Models that do not support
146
+ * highlight styles ignore this method.
147
+ *
148
+ * @param name - Style name.
149
+ * @param style - Style settings. Unset settings take their default values, not the values set before.
150
+ */
151
+ setHighlightStyle(name: string, style: IHighlightStyle): this;
59
152
  }