@xeokit/xeokit-sdk 2.6.55 → 2.6.57

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.
Files changed (32) hide show
  1. package/dist/xeokit-sdk.cjs.js +1369 -1771
  2. package/dist/xeokit-sdk.es.js +1367 -1772
  3. package/dist/xeokit-sdk.es5.js +709 -719
  4. package/dist/xeokit-sdk.min.cjs.js +5 -5
  5. package/dist/xeokit-sdk.min.es.js +5 -5
  6. package/dist/xeokit-sdk.min.es5.js +4 -4
  7. package/package.json +1 -1
  8. package/src/plugins/AngleMeasurementsPlugin/AngleMeasurement.js +155 -415
  9. package/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsMouseControl.js +1 -1
  10. package/src/plugins/AnnotationsPlugin/Annotation.js +7 -5
  11. package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurement.js +236 -750
  12. package/src/plugins/StoreyViewsPlugin/StoreyViewsPlugin.js +51 -0
  13. package/src/plugins/TreeViewPlugin/RenderService.js +2 -1
  14. package/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js +5 -1
  15. package/src/plugins/ZonesPlugin/ZonesPlugin.js +15 -79
  16. package/src/plugins/lib/html/Dot.js +14 -41
  17. package/src/plugins/lib/html/Label.js +10 -37
  18. package/src/plugins/lib/html/MenuEvent.js +74 -0
  19. package/src/plugins/lib/html/Wire.js +20 -47
  20. package/src/plugins/lib/ui/index.js +370 -12
  21. package/src/viewer/Viewer.js +9 -0
  22. package/src/viewer/index.js +1 -0
  23. package/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js +1 -1
  24. package/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js +2 -1
  25. package/src/viewer/scene/marker/Marker.js +20 -23
  26. package/src/viewer/scene/model/SceneModelEntity.js +5 -0
  27. package/src/viewer/utils/index.js +1 -0
  28. package/src/viewer/utils/os.js +8 -1
  29. package/types/viewer/scene/models/PerformanceModel/index.d.ts +0 -1
  30. package/types/viewer/scene/models/SceneModel.d.ts +0 -3
  31. package/types/viewer/scene/models/SceneModelEntity.d.ts +6 -0
  32. package/types/viewer/scene/nodes/Node.d.ts +1 -1
@@ -1,26 +1,13 @@
1
- import {Dot3D} from "../lib/ui/index.js";
2
- import {Wire} from "../lib/html/Wire.js";
3
- import {Label} from "../lib/html/Label.js";
1
+ import {Dot3D, Label3D, Wire3D} from "../lib/ui/index.js";
4
2
  import {math} from "../../viewer/scene/math/math.js";
5
3
  import {Component} from "../../viewer/scene/Component.js";
6
4
 
7
-
8
- const distVec3 = math.vec3();
9
- const tmpVec3 = math.vec3();
10
-
11
- const lengthWire = (x1, y1, x2, y2) => {
12
- var a = x1 - x2;
13
- var b = y1 - y2;
14
- return Math.sqrt(a * a + b * b);
15
- };
16
-
17
- function determineMeasurementOrientation(A, B, distance) {
18
- const yDiff = Math.abs(B[1] - A[1]);
19
-
20
- return yDiff > distance ? 'Vertical' : 'Horizontal';
21
- }
22
-
23
- // function findDistance
5
+ const tmpVec3a = math.vec3();
6
+ const tmpVec3b = math.vec3();
7
+ const tmpVec3c = math.vec3();
8
+ const tmpVec4a = math.vec4();
9
+ const tmpVec4b = math.vec4();
10
+ const tmpVec4c = math.vec4();
24
11
 
25
12
  /**
26
13
  * @desc Measures the distance between two 3D points.
@@ -34,7 +21,9 @@ class DistanceMeasurement extends Component {
34
21
  */
35
22
  constructor(plugin, cfg = {}) {
36
23
 
37
- super(plugin.viewer.scene, cfg);
24
+ const scene = plugin.viewer.scene;
25
+
26
+ super(scene, cfg);
38
27
 
39
28
  /**
40
29
  * The {@link DistanceMeasurementsPlugin} that owns this DistanceMeasurement.
@@ -42,598 +31,251 @@ class DistanceMeasurement extends Component {
42
31
  */
43
32
  this.plugin = plugin;
44
33
 
45
- this._container = cfg.container;
46
- if (!this._container) {
34
+ const container = cfg.container;
35
+ if (!container) {
47
36
  throw "config missing: container";
48
37
  }
49
38
 
50
- this._eventSubs = {};
51
-
52
- var scene = this.plugin.viewer.scene;
53
-
54
- this._originWorld = math.vec3();
55
- this._targetWorld = math.vec3();
39
+ this._color = cfg.color || plugin.defaultColor;
40
+
41
+ const channel = function(v, defaultIfUndefined) {
42
+ const listeners = [ ];
43
+ let value = v !== undefined ? Boolean(v) : defaultIfUndefined;
44
+ return {
45
+ reg: (l) => listeners.push(l),
46
+ get: () => value,
47
+ set: (v) => {
48
+ value = v !== undefined ? Boolean(v) : defaultIfUndefined;
49
+ listeners.forEach(l => l(value));
50
+ }
51
+ };
52
+ };
56
53
 
57
- this._wp = new Float64Array(24); //world position
58
- this._vp = new Float64Array(24); //view position
59
- this._pp = new Float64Array(24);
60
- this._cp = new Float64Array(8); //canvas position
54
+ this._visible = channel(cfg.visible, plugin.defaultVisible);
55
+ this._originVisible = channel(cfg.originVisible, plugin.defaultOriginVisible);
56
+ this._targetVisible = channel(cfg.targetVisible, plugin.defaultTargetVisible);
57
+ this._axisVisible = channel(cfg.axisVisible, plugin.defaultAxisVisible);
58
+ this._xAxisVisible = channel(cfg.xAxisVisible, plugin.defaultAxisVisible);
59
+ this._yAxisVisible = channel(cfg.yAxisVisible, plugin.defaultAxisVisible);
60
+ this._zAxisVisible = channel(cfg.zAxisVisible, plugin.defaultAxisVisible);
61
+ this._axisEnabled = channel(true, plugin.defaultAxisVisible);
62
+ this._wireVisible = channel(cfg.wireVisible, plugin.defaultWireVisible);
63
+ this._xLabelEnabled = channel(cfg.xLabelEnabled, plugin.defaultXLabelEnabled);
64
+ this._yLabelEnabled = channel(cfg.yLabelEnabled, plugin.defaultYLabelEnabled);
65
+ this._zLabelEnabled = channel(cfg.zLabelEnabled, plugin.defaultZLabelEnabled);
66
+ this._lengthLabelEnabled = channel(cfg.lengthLabelEnabled, plugin.defaultLengthLabelEnabled);
67
+ this._labelsVisible = channel(cfg.labelsVisible, plugin.defaultLabelsVisible);
68
+ this._clickable = channel(false, false);
69
+ this._labelsOnWires = channel(cfg.labelsOnWires, plugin.defaultLabelsOnWires);
70
+ this._useRotationAdjustment = channel(cfg.useRotationAdjustment, plugin.useRotationAdjustment);
71
+
72
+ this._axesBasis = math.identityMat4();
73
+ this.approximate = cfg.approximate;
61
74
 
62
- this._xAxisLabelCulled = false;
63
- this._yAxisLabelCulled = false;
64
- this._zAxisLabelCulled = false;
65
75
 
66
- this._color = cfg.color || this.plugin.defaultColor;
76
+ const canvas = scene.canvas.canvas;
67
77
 
68
78
  const onMouseOver = cfg.onMouseOver ? (event) => {
69
79
  cfg.onMouseOver(event, this);
70
- this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseover', event));
80
+ canvas.dispatchEvent(new MouseEvent('mouseover', event));
71
81
  } : null;
72
82
 
73
83
  const onMouseLeave = cfg.onMouseLeave ? (event) => {
74
84
  cfg.onMouseLeave(event, this);
75
- this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseleave', event));
85
+ canvas.dispatchEvent(new MouseEvent('mouseleave', event));
76
86
  } : null;
77
87
 
78
- const onMouseDown = (event) => {
79
- this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousedown', event));
80
- } ;
81
-
82
- const onMouseUp = (event) => {
83
- this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseup', event));
84
- };
85
-
86
- const onMouseMove = (event) => {
87
- this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousemove', event));
88
- };
89
-
90
88
  const onContextMenu = cfg.onContextMenu ? (event) => {
91
89
  cfg.onContextMenu(event, this);
92
90
  } : null;
93
91
 
94
- const onMouseWheel = (event) => {
95
- this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent('wheel', event));
96
- };
92
+ const onMouseDown = (event) => canvas.dispatchEvent(new MouseEvent('mousedown', event));
93
+ const onMouseUp = (event) => canvas.dispatchEvent(new MouseEvent('mouseup', event));
94
+ const onMouseMove = (event) => canvas.dispatchEvent(new MouseEvent('mousemove', event));
95
+ const onMouseWheel = (event) => canvas.dispatchEvent(new WheelEvent('wheel', event));
97
96
 
98
- this._originDot = new Dot3D(scene, cfg.origin, this._container, {
99
- fillColor: this._color,
100
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
101
- onMouseOver,
102
- onMouseLeave,
103
- onMouseWheel,
104
- onMouseDown,
105
- onMouseUp,
106
- onMouseMove,
107
- onContextMenu
108
- });
109
97
 
110
- this._targetDot = new Dot3D(scene, cfg.target, this._container, {
111
- fillColor: this._color,
112
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
113
- onMouseOver,
114
- onMouseLeave,
115
- onMouseWheel,
116
- onMouseDown,
117
- onMouseUp,
118
- onMouseMove,
119
- onContextMenu
120
- });
98
+ this._cleanups = [ ];
121
99
 
122
- this._lengthWire = new Wire(this._container, {
123
- color: this._color,
124
- thickness: 2,
125
- thicknessClickable: 6,
126
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 1 : undefined,
127
- onMouseOver,
128
- onMouseLeave,
129
- onMouseWheel,
130
- onMouseDown,
131
- onMouseUp,
132
- onMouseMove,
133
- onContextMenu
100
+ [ "units", "scale" ].forEach(evt => {
101
+ const handler = scene.metrics.on("units", () => this._update());
102
+ this._cleanups.push(() => scene.metrics.off(handler));
134
103
  });
135
104
 
136
- this._xAxisWire = new Wire(this._container, {
137
- color: "#FF0000",
138
- thickness: 1,
139
- thicknessClickable: 6,
140
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 1 : undefined,
141
- onMouseOver,
142
- onMouseLeave,
143
- onMouseWheel,
144
- onMouseDown,
145
- onMouseUp,
146
- onMouseMove,
147
- onContextMenu
148
- });
105
+ this._drawables = [ ];
149
106
 
150
- this._yAxisWire = new Wire(this._container, {
151
- color: "green",
152
- thickness: 1,
153
- thicknessClickable: 6,
154
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 1 : undefined,
155
- onMouseOver,
156
- onMouseLeave,
157
- onMouseWheel,
158
- onMouseDown,
159
- onMouseUp,
160
- onMouseMove,
161
- onContextMenu
162
- });
107
+ const registerDrawable = (drawable, visibilityChannels) => {
108
+ const updateVisibility = () => drawable.setVisible(visibilityChannels.every(ch => ch.get()));
109
+ visibilityChannels.forEach(ch => ch.reg(updateVisibility));
110
+ this._drawables.push(drawable);
111
+ this._cleanups.push(() => drawable.destroy());
112
+ };
163
113
 
164
- this._zAxisWire = new Wire(this._container, {
165
- color: "blue",
166
- thickness: 1,
167
- thicknessClickable: 6,
168
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 1 : undefined,
169
- onMouseOver,
170
- onMouseLeave,
171
- onMouseWheel,
172
- onMouseDown,
173
- onMouseUp,
174
- onMouseMove,
175
- onContextMenu
176
- });
114
+ const makeWire = (color, thickness, visibilityChannels) => {
115
+ const wire = new Wire3D(scene, container, {
116
+ color: color,
117
+ thickness: thickness,
118
+ thicknessClickable: 6,
119
+ zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 1 : undefined,
120
+ onMouseOver,
121
+ onMouseLeave,
122
+ onMouseWheel,
123
+ onMouseDown,
124
+ onMouseUp,
125
+ onMouseMove,
126
+ onContextMenu
127
+ });
128
+ registerDrawable(wire, visibilityChannels);
129
+ return {
130
+ setEnds: (p0, p1) => wire.setEnds(p0, p1),
131
+ setColor: value => wire.setColor(value)
132
+ };
133
+ };
134
+ this._lengthWire = makeWire(this._color, 2, [ this._visible, this._wireVisible ]);
135
+ this._xAxisWire = makeWire("red", 1, [ this._visible, this._axisEnabled, this._axisVisible, this._xAxisVisible ]);
136
+ this._yAxisWire = makeWire("green", 1, [ this._visible, this._axisEnabled, this._axisVisible, this._yAxisVisible ]);
137
+ this._zAxisWire = makeWire("blue", 1, [ this._visible, this._axisEnabled, this._axisVisible, this._zAxisVisible ]);
138
+
139
+ const makeLabel = (color, zIndexOffset, visibilityChannels) => {
140
+ const label = new Label3D(scene, container, {
141
+ fillColor: color,
142
+ zIndex: plugin.zIndex !== undefined ? plugin.zIndex + zIndexOffset : undefined,
143
+ onMouseOver,
144
+ onMouseLeave,
145
+ onMouseWheel,
146
+ onMouseDown,
147
+ onMouseUp,
148
+ onMouseMove,
149
+ onContextMenu
150
+ });
151
+ registerDrawable(label, visibilityChannels);
152
+ return {
153
+ setFillColor: value => label.setFillColor(value),
154
+ setPosOnWire: (p0, p1, offset, labelMinAxisLength) => label.setPosOnWire(p0, p1, offset, labelMinAxisLength),
155
+ setPosBetween: (p0, p1, p2) => label.setPosBetween(p0, p1, p2),
156
+ setText: str => label.setText(str.replace(/ /g, " "))
157
+ };
158
+ };
159
+ this._lengthLabel = makeLabel(this._color, 4, [ this._visible, this._wireVisible, this._labelsVisible, this._clickable, this._axisEnabled, this._lengthLabelEnabled ]);
160
+ this._xAxisLabel = makeLabel("red", 3, [ this._visible, this._axisEnabled, this._axisVisible, this._xAxisVisible, this._labelsVisible, this._clickable, this._xLabelEnabled ]);
161
+ this._yAxisLabel = makeLabel("green", 3, [ this._visible, this._axisEnabled, this._axisVisible, this._yAxisVisible, this._labelsVisible, this._clickable, this._yLabelEnabled ]);
162
+ this._zAxisLabel = makeLabel("blue", 3, [ this._visible, this._axisEnabled, this._axisVisible, this._zAxisVisible, this._labelsVisible, this._clickable, this._zLabelEnabled ]);
163
+
164
+ const makeDot = (cfg, visibilityChannels) => {
165
+ const dot = new Dot3D(scene, cfg, container, {
166
+ fillColor: this._color,
167
+ zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
168
+ onMouseOver,
169
+ onMouseLeave,
170
+ onMouseWheel,
171
+ onMouseDown,
172
+ onMouseUp,
173
+ onMouseMove,
174
+ onContextMenu
175
+ });
176
+ dot.on("worldPos", () => this._update());
177
+ registerDrawable(dot, visibilityChannels);
178
+ return dot;
179
+ };
180
+ this._originDot = makeDot(cfg.origin, [ this._visible, this._originVisible ]);
181
+ this._targetDot = makeDot(cfg.target, [ this._visible, this._targetVisible ]);
177
182
 
178
- this._lengthLabel = new Label(this._container, {
179
- fillColor: this._color,
180
- prefix: "",
181
- text: "",
182
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 4 : undefined,
183
- onMouseOver,
184
- onMouseLeave,
185
- onMouseWheel,
186
- onMouseDown,
187
- onMouseUp,
188
- onMouseMove,
189
- onContextMenu
190
- });
183
+ this._update();
184
+ }
191
185
 
192
- this._xAxisLabel = new Label(this._container, {
193
- fillColor: "red",
194
- prefix: "X",
195
- text: "",
196
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 3 : undefined,
197
- onMouseOver,
198
- onMouseLeave,
199
- onMouseWheel,
200
- onMouseDown,
201
- onMouseUp,
202
- onMouseMove,
203
- onContextMenu
204
- });
186
+ _update() {
187
+ if (! this._targetDot) {
188
+ return;
189
+ }
205
190
 
206
- this._yAxisLabel = new Label(this._container, {
207
- fillColor: "green",
208
- prefix: "Y",
209
- text: "",
210
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 3 : undefined,
211
- onMouseOver,
212
- onMouseLeave,
213
- onMouseWheel,
214
- onMouseDown,
215
- onMouseUp,
216
- onMouseMove,
217
- onContextMenu
218
- });
191
+ const p0 = this._originDot.worldPos;
192
+ const p1 = this._targetDot.worldPos;
193
+ const axesBasis = this._axesBasis;
194
+ const delta = math.subVec3(p1, p0, tmpVec3a);
195
+ const factors = math.transformVec3(axesBasis, delta, delta);
219
196
 
220
- this._zAxisLabel = new Label(this._container, {
221
- fillColor: "blue",
222
- prefix: "Z",
223
- text: "",
224
- zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 3 : undefined,
225
- onMouseOver,
226
- onMouseLeave,
227
- onMouseWheel,
228
- onMouseDown,
229
- onMouseUp,
230
- onMouseMove,
231
- onContextMenu
232
- });
197
+ const measurementOrientationVertical = this._useRotationAdjustment.get() && Math.abs(delta[1]) > 0;
233
198
 
234
- this._measurementOrientation = 'Horizontal';
235
- this._wpDirty = false;
236
- this._vpDirty = false;
237
- this._cpDirty = false;
238
- this._sectionPlanesDirty = true;
239
-
240
- this._visible = false;
241
- this._originVisible = false;
242
- this._targetVisible = false;
243
- this._useRotationAdjustment = false;
244
- this._wireVisible = false;
245
- this._axisVisible = false;
246
- this._xAxisVisible = false;
247
- this._yAxisVisible = false;
248
- this._zAxisVisible = false;
249
- this._axisEnabled = true;
250
- this._xLabelEnabled = false;
251
- this._yLabelEnabled = false;
252
- this._zLabelEnabled = false;
253
- this._lengthLabelEnabled = false;
254
- this._labelsVisible = false;
255
- this._labelsOnWires = false;
256
- this._clickable = false;
257
-
258
- this._originDot.on("worldPos", (value) => {
259
- this._originWorld.set(value || [0,0,0]);
260
- this._wpDirty = true;
261
- this._needUpdate(0); // No lag
262
- });
199
+ const setWireCoordinates = (xEnd, zStart) => {
263
200
 
264
- this._targetDot.on("worldPos", (value) => {
265
- this._targetWorld.set(value || [0,0,0]);
266
- this._wpDirty = true;
267
- this._needUpdate(0); // No lag
268
- });
201
+ const metrics = this.plugin.viewer.scene.metrics;
202
+ const scale = metrics.scale;
203
+ const unit = metrics.unitsInfo[metrics.units].abbrev;
269
204
 
270
- this._onViewMatrix = scene.camera.on("viewMatrix", () => {
271
- this._vpDirty = true;
272
- this._needUpdate(0); // No lag
273
- });
205
+ const setAxisLabelCoords = (label, a, b, offsetIdx) => {
206
+ if (this._labelsOnWires.get()) {
207
+ label.setPosOnWire(a, b, 0, this.plugin.labelMinAxisLength);
208
+ } else {
209
+ label.setPosOnWire(p0, p1, offsetIdx * 35, 0);
210
+ }
211
+ };
212
+ const unitStr = len => (this._approximate ? " ~ " : " = ") + len.toFixed(2) + unit;
274
213
 
275
- this._onProjMatrix = scene.camera.on("projMatrix", () => {
276
- this._cpDirty = true;
277
- this._needUpdate();
278
- });
214
+ this._xAxisWire.setEnds(p0, xEnd);
215
+ setAxisLabelCoords(this._xAxisLabel, p0, xEnd, 1);
216
+ this._xAxisLabel.setText("X" + unitStr(math.distVec3(p0, xEnd) * scale));
279
217
 
280
- this._onCanvasBoundary = scene.canvas.on("boundary", () => {
281
- this._cpDirty = true;
282
- this._needUpdate(0); // No lag
283
- });
218
+ this._yAxisWire.setEnds(xEnd, zStart);
219
+ setAxisLabelCoords(this._yAxisLabel, xEnd, zStart, 2);
220
+ this._yAxisLabel.setText("Y" + unitStr(math.distVec3(xEnd, zStart) * scale));
284
221
 
285
- this._onMetricsUnits = scene.metrics.on("units", () => {
286
- this._cpDirty = true;
287
- this._needUpdate();
288
- });
222
+ this._zAxisWire.setEnds(zStart, p1);
223
+ setAxisLabelCoords(this._zAxisLabel, zStart, p1, 3);
224
+ this._zAxisLabel.setText((measurementOrientationVertical ? "" : "Z") + unitStr(math.distVec3(zStart, p1) * scale));
289
225
 
290
- this._onMetricsScale = scene.metrics.on("scale", () => {
291
- this._cpDirty = true;
292
- this._needUpdate();
293
- });
226
+ this._lengthWire.setEnds(p0, p1);
227
+ setAxisLabelCoords(this._lengthLabel, p0, p1, 0);
228
+ this._length = math.distVec3(p0, p1) * scale;
229
+ this._lengthLabel.setText(unitStr(this._length));
230
+ };
294
231
 
295
- this._onMetricsOrigin = scene.metrics.on("origin", () => {
296
- this._cpDirty = true;
297
- this._needUpdate();
298
- });
232
+ if (measurementOrientationVertical) {
233
+ tmpVec3c[0] = p0[0];
234
+ tmpVec3c[1] = p1[1];
235
+ tmpVec3c[2] = p0[2];
299
236
 
300
- this._onSectionPlaneUpdated = scene.on("sectionPlaneUpdated", () =>{
301
- this._sectionPlanesDirty = true;
302
- this._needUpdate();
303
- });
237
+ setWireCoordinates(p0, tmpVec3c);
238
+ }
239
+ else {
240
+ tmpVec3b[0] = p0[0] + axesBasis[0] * factors[0];
241
+ tmpVec3b[1] = p0[1] + axesBasis[4] * factors[0];
242
+ tmpVec3b[2] = p0[2] + axesBasis[8] * factors[0];
304
243
 
305
- this.approximate = cfg.approximate;
306
- this.visible = cfg.visible;
307
- this.originVisible = cfg.originVisible;
308
- this.targetVisible = cfg.targetVisible;
309
- this.wireVisible = cfg.wireVisible;
310
- this.axisVisible = cfg.axisVisible;
311
- this.xAxisVisible = cfg.xAxisVisible;
312
- this.yAxisVisible = cfg.yAxisVisible;
313
- this.zAxisVisible = cfg.zAxisVisible;
314
- this.xLabelEnabled = cfg.xLabelEnabled;
315
- this.yLabelEnabled = cfg.yLabelEnabled;
316
- this.zLabelEnabled = cfg.zLabelEnabled;
317
- this.lengthLabelEnabled = cfg.lengthLabelEnabled;
318
- this.labelsVisible = cfg.labelsVisible;
319
- this.labelsOnWires = cfg.labelsOnWires;
320
- this._useRotationAdjustment = cfg.useRotationAdjustment;
244
+ tmpVec3c[0] = tmpVec3b[0] + axesBasis[1] * factors[1];
245
+ tmpVec3c[1] = tmpVec3b[1] + axesBasis[5] * factors[1];
246
+ tmpVec3c[2] = tmpVec3b[2] + axesBasis[9] * factors[1];
321
247
 
322
- /**
323
- * @type {number[]}
324
- */
325
- this._axesBasis = [
326
- 1, 0, 0, 0,
327
- 0, 1, 0, 0,
328
- 0, 0, 1, 0,
329
- 0, 0, 0, 1,
330
- ];
248
+ setWireCoordinates(tmpVec3b, tmpVec3c);
249
+ }
331
250
  }
332
251
 
333
252
  /**
334
253
  * Sets the axes basis for the measurement.
335
- *
254
+ *
336
255
  * The value is a 4x4 matrix where each column-vector defines an axis and must have unit length.
337
- *
256
+ *
338
257
  * This is the ```identity``` matrix by default, meaning the measurement axes are the same as the world axes.
339
- *
340
- * @param {number[]} value
258
+ *
259
+ * @param {number[]} value
341
260
  */
342
261
  set axesBasis(value) {
343
- this._axesBasis = value.slice();
344
- this._wpDirty = true;
345
- this._needUpdate(0); // No lag
262
+ this._axesBasis.set(value);
263
+ this._update();
346
264
  }
347
265
 
348
266
  /**
349
267
  * Gets the axes basis for the measurement.
350
- *
268
+ *
351
269
  * The value is a 4x4 matrix where each column-vector defines an axis and must have unit length.
352
- *
270
+ *
353
271
  * This is the ```identity``` matrix by default, meaning the measurement axes are the same as the world axes.
354
- *
272
+ *
355
273
  * @type {number[]}
356
274
  */
357
275
  get axesBasis() {
358
276
  return this._axesBasis;
359
277
  }
360
278
 
361
- _update() {
362
-
363
- if (!this._visible) {
364
- return;
365
- }
366
-
367
- const scene = this.plugin.viewer.scene;
368
-
369
- if (this._wpDirty) {
370
- const delta = math.subVec3(
371
- this._targetWorld,
372
- this._originWorld,
373
- tmpVec3
374
- );
375
-
376
- /**
377
- * The length detected for each measurement axis.
378
- */
379
- this._factors = math.transformVec3(this._axesBasis, delta);
380
-
381
- this._measurementOrientation = determineMeasurementOrientation(this._originWorld, this._targetWorld, 0);
382
- if (this._measurementOrientation === 'Vertical' && this._useRotationAdjustment) {
383
- this._wp[0] = this._originWorld[0];
384
- this._wp[1] = this._originWorld[1];
385
- this._wp[2] = this._originWorld[2];
386
- this._wp[3] = 1.0;
387
-
388
- this._wp[4] = this._originWorld[0]; //x-axis
389
- this._wp[5] = this._originWorld[1];
390
- this._wp[6] = this._originWorld[2];
391
- this._wp[7] = 1.0;
392
-
393
- this._wp[8] = this._originWorld[0]; //x-axis
394
- this._wp[9] = this._targetWorld[1]; //y-axis
395
- this._wp[10] = this._originWorld[2];
396
- this._wp[11] = 1.0;
397
-
398
- this._wp[12] = this._targetWorld[0];
399
- this._wp[13] = this._targetWorld[1];
400
- this._wp[14] = this._targetWorld[2];
401
- this._wp[15] = 1.0;
402
- }
403
- else {
404
-
405
- this._wp[0] = this._originWorld[0];
406
- this._wp[1] = this._originWorld[1];
407
- this._wp[2] = this._originWorld[2];
408
- this._wp[3] = 1.0;
409
-
410
- this._wp[4] = this._originWorld[0] + this._axesBasis[0]*this._factors[0];
411
- this._wp[5] = this._originWorld[1] + this._axesBasis[4]*this._factors[0];
412
- this._wp[6] = this._originWorld[2] + this._axesBasis[8]*this._factors[0];
413
- this._wp[7] = 1.0;
414
-
415
- this._wp[8] = this._originWorld[0] + this._axesBasis[0]*this._factors[0]+ this._axesBasis[1]*this._factors[1];
416
- this._wp[9] = this._originWorld[1] + this._axesBasis[4]*this._factors[0]+ this._axesBasis[5]*this._factors[1];
417
- this._wp[10] = this._originWorld[2] + this._axesBasis[8]*this._factors[0]+ this._axesBasis[9]*this._factors[1];;
418
- this._wp[11] = 1.0;
419
-
420
- this._wp[12] = this._targetWorld[0];
421
- this._wp[13] = this._targetWorld[1];
422
- this._wp[14] = this._targetWorld[2];
423
- this._wp[15] = 1.0;
424
- }
425
-
426
-
427
- this._wpDirty = false;
428
- this._vpDirty = true;
429
- }
430
-
431
- if (this._vpDirty) {
432
-
433
- math.transformPositions4(scene.camera.viewMatrix, this._wp, this._vp);
434
-
435
- this._vp[3] = 1.0;
436
- this._vp[7] = 1.0;
437
- this._vp[11] = 1.0;
438
- this._vp[15] = 1.0;
439
-
440
- this._vpDirty = false;
441
- this._cpDirty = true;
442
- }
443
-
444
- if (this._sectionPlanesDirty) {
445
-
446
- if (this._isSliced(this._originWorld) || this._isSliced(this._targetWorld)) {
447
- this._xAxisLabel.setCulled(true);
448
- this._yAxisLabel.setCulled(true);
449
- this._zAxisLabel.setCulled(true);
450
- this._lengthLabel.setCulled(true);
451
- this._xAxisWire.setCulled(true);
452
- this._yAxisWire.setCulled(true);
453
- this._zAxisWire.setCulled(true);
454
- this._lengthWire.setCulled(true);
455
- this._originDot.setCulled(true);
456
- this._targetDot.setCulled(true);
457
- return;
458
- } else {
459
- this._xAxisLabel.setCulled(false);
460
- this._yAxisLabel.setCulled(false);
461
- this._zAxisLabel.setCulled(false);
462
- this._lengthLabel.setCulled(false);
463
- this._xAxisWire.setCulled(false);
464
- this._yAxisWire.setCulled(false);
465
- this._zAxisWire.setCulled(false);
466
- this._lengthWire.setCulled(false);
467
- this._originDot.setCulled(false);
468
- this._targetDot.setCulled(false);
469
- }
470
-
471
- this._sectionPlanesDirty = true;
472
- }
473
-
474
- const near = -0.3;
475
- const vpz1 = this._originDot.viewPos[2];
476
- const vpz2 = this._targetDot.viewPos[2];
477
-
478
- if (vpz1 > near || vpz2 > near) {
479
-
480
- this._xAxisLabel.setCulled(true);
481
- this._yAxisLabel.setCulled(true);
482
- this._zAxisLabel.setCulled(true);
483
- this._lengthLabel.setCulled(true);
484
-
485
- this._xAxisWire.setVisible(false);
486
- this._yAxisWire.setVisible(false);
487
- this._zAxisWire.setVisible(false);
488
- this._lengthWire.setVisible(false);
489
-
490
- this._originDot.setVisible(false);
491
- this._targetDot.setVisible(false);
492
-
493
- return;
494
- }
495
-
496
- if (this._cpDirty) {
497
-
498
- math.transformPositions4(scene.camera.project.matrix, this._vp, this._pp);
499
-
500
- var pp = this._pp;
501
- var cp = this._cp;
502
-
503
- var canvas = scene.canvas.canvas;
504
- var offsets = canvas.getBoundingClientRect();
505
- const containerOffsets = this._container.getBoundingClientRect();
506
- var top = offsets.top - containerOffsets.top;
507
- var left = offsets.left - containerOffsets.left;
508
- var aabb = scene.canvas.boundary;
509
- var canvasWidth = aabb[2];
510
- var canvasHeight = aabb[3];
511
- var j = 0;
512
-
513
- const metrics = this.plugin.viewer.scene.metrics;
514
- const scale = metrics.scale;
515
- const units = metrics.units;
516
- const unitInfo = metrics.unitsInfo[units];
517
- const unitAbbrev = unitInfo.abbrev;
518
-
519
- for (var i = 0, len = pp.length; i < len; i += 4) {
520
- cp[j] = left + Math.floor((1 + pp[i + 0] / pp[i + 3]) * canvasWidth / 2);
521
- cp[j + 1] = top + Math.floor((1 - pp[i + 1] / pp[i + 3]) * canvasHeight / 2);
522
- j += 2;
523
- }
524
-
525
- this._lengthWire.setStartAndEnd(cp[0], cp[1], cp[6], cp[7]);
526
-
527
- this._xAxisWire.setStartAndEnd(cp[0], cp[1], cp[2], cp[3]);
528
- this._yAxisWire.setStartAndEnd(cp[2], cp[3], cp[4], cp[5]);
529
- this._zAxisWire.setStartAndEnd(cp[4], cp[5], cp[6], cp[7]);
530
-
531
- if (!this.labelsVisible) {
532
-
533
- this._lengthLabel.setCulled(true);
534
-
535
- this._xAxisLabel.setCulled(true);
536
- this._yAxisLabel.setCulled(true);
537
- this._zAxisLabel.setCulled(true);
538
-
539
- } else {
540
-
541
- this._lengthLabel.setPosOnWire(cp[0], cp[1], cp[6], cp[7]);
542
-
543
- if (this.labelsOnWires) {
544
- this._xAxisLabel.setPosOnWire(cp[0], cp[1], cp[2], cp[3]);
545
- this._yAxisLabel.setPosOnWire(cp[2], cp[3], cp[4], cp[5]);
546
- this._zAxisLabel.setPosOnWire(cp[4], cp[5], cp[6], cp[7]);
547
- } else {
548
- const labelOffset = 35;
549
- let currentLabelOffset = labelOffset;
550
- this._xAxisLabel.setPosOnWire(cp[0], cp[1] + currentLabelOffset, cp[6], cp[7] + currentLabelOffset);
551
- currentLabelOffset += labelOffset;
552
- this._yAxisLabel.setPosOnWire(cp[0], cp[1] + currentLabelOffset, cp[6], cp[7] + currentLabelOffset);
553
- currentLabelOffset += labelOffset;
554
- this._zAxisLabel.setPosOnWire(cp[0], cp[1] + currentLabelOffset, cp[6], cp[7] + currentLabelOffset);
555
- }
556
-
557
- const tilde = this._approximate ? " ~ " : " = ";
558
-
559
- this._length = Math.abs(math.lenVec3(math.subVec3(this._targetWorld, this._originWorld, distVec3)))
560
- this._lengthLabel.setText(tilde + (this._length * scale).toFixed(2) + unitAbbrev);
561
-
562
- const xAxisCanvasLength = Math.abs(lengthWire(cp[0], cp[1], cp[2], cp[3]));
563
- const yAxisCanvasLength = Math.abs(lengthWire(cp[2], cp[3], cp[4], cp[5]));
564
- const zAxisCanvasLength = Math.abs(lengthWire(cp[4], cp[5], cp[6], cp[7]));
565
-
566
- const labelMinAxisLength = this.plugin.labelMinAxisLength;
567
-
568
- if (this.labelsOnWires){
569
- this._xAxisLabelCulled = (xAxisCanvasLength < labelMinAxisLength);
570
- this._yAxisLabelCulled = (yAxisCanvasLength < labelMinAxisLength);
571
- this._zAxisLabelCulled = (zAxisCanvasLength < labelMinAxisLength);
572
- } else {
573
- this._xAxisLabelCulled = false;
574
- this._yAxisLabelCulled = false;
575
- this._zAxisLabelCulled = false;
576
- }
577
-
578
- if (!this._xAxisLabelCulled) {
579
- this._xAxisLabel.setText(tilde + Math.abs(this._factors[0] * scale).toFixed(2) + unitAbbrev);
580
- this._xAxisLabel.setCulled(!this.axisVisible);
581
- } else {
582
- this._xAxisLabel.setCulled(true);
583
- }
584
-
585
- if (!this._yAxisLabelCulled) {
586
- this._yAxisLabel.setText(tilde + Math.abs(this._factors[1] * scale).toFixed(2) + unitAbbrev);
587
- this._yAxisLabel.setCulled(!this.axisVisible);
588
- } else {
589
- this._yAxisLabel.setCulled(true);
590
- }
591
-
592
- if (!this._zAxisLabelCulled) {
593
- if (this._measurementOrientation === 'Vertical' && this._useRotationAdjustment) {
594
- this._zAxisLabel.setPrefix("");
595
- this._zAxisLabel.setText(tilde + Math.abs(math.lenVec3(math.subVec3(this._targetWorld, [this._originWorld[0], this._targetWorld[1], this._originWorld[2]], distVec3)) * scale).toFixed(2) + unitAbbrev);
596
- }
597
- else {
598
- this._zAxisLabel.setPrefix("Z");
599
- this._zAxisLabel.setText(tilde + Math.abs(this._factors[2] * scale).toFixed(2) + unitAbbrev);
600
- }
601
- this._zAxisLabel.setCulled(!this.axisVisible);
602
- } else {
603
- this._zAxisLabel.setCulled(true);
604
- }
605
- }
606
-
607
- // this._xAxisLabel.setVisible(this.axisVisible && this.xAxisVisible);
608
- // this._yAxisLabel.setVisible(this.axisVisible && this.yAxisVisible);
609
- // this._zAxisLabel.setVisible(this.axisVisible && this.zAxisVisible);
610
- // this._lengthLabel.setVisible(false);
611
-
612
- this._originDot.setVisible(this._visible && this._originVisible);
613
- this._targetDot.setVisible(this._visible && this._targetVisible);
614
-
615
- this._xAxisWire.setVisible(this.axisVisible && this.xAxisVisible);
616
- this._yAxisWire.setVisible(this.axisVisible && this.yAxisVisible);
617
- this._zAxisWire.setVisible(this.axisVisible && this.zAxisVisible);
618
-
619
- this._lengthWire.setVisible(this.wireVisible);
620
- this._lengthLabel.setCulled(!this.wireVisible);
621
-
622
- this._cpDirty = false;
623
- }
624
- }
625
-
626
- _isSliced(positions) {
627
- const sectionPlanes = this.scene._sectionPlanesState.sectionPlanes;
628
- for (let i = 0, len = sectionPlanes.length; i < len; i++) {
629
- const sectionPlane = sectionPlanes[i];
630
- if (math.planeClipsPositions3(sectionPlane.pos, sectionPlane.dir, positions, 4)) {
631
- return true
632
- }
633
- }
634
- return false;
635
- }
636
-
637
279
  /**
638
280
  * Sets whether this DistanceMeasurement indicates that its measurement is approximate.
639
281
  *
@@ -647,8 +289,7 @@ class DistanceMeasurement extends Component {
647
289
  return;
648
290
  }
649
291
  this._approximate = approximate;
650
- this._cpDirty = true;
651
- this._needUpdate(0);
292
+ this._update();
652
293
  }
653
294
 
654
295
  /**
@@ -686,9 +327,7 @@ class DistanceMeasurement extends Component {
686
327
  * @type {Number}
687
328
  */
688
329
  get length() {
689
- this._update();
690
- const scale = this.plugin.viewer.scene.metrics.scale;
691
- return this._length * scale;
330
+ return this._length;
692
331
  }
693
332
 
694
333
  get color() {
@@ -709,31 +348,7 @@ class DistanceMeasurement extends Component {
709
348
  * @type {Boolean}
710
349
  */
711
350
  set visible(value) {
712
-
713
- value = value !== undefined ? Boolean(value) : this.plugin.defaultVisible;
714
-
715
- this._visible = value;
716
-
717
- this._originDot.setVisible(this._visible && this._originVisible);
718
- this._targetDot.setVisible(this._visible && this._targetVisible);
719
- this._lengthWire.setVisible(this._visible && this._wireVisible);
720
- this._lengthLabel.setVisible(this._visible && this._wireVisible && this._lengthLabelEnabled);
721
-
722
- const xAxisVisible = this._visible && this._axisVisible && this._xAxisVisible;
723
- const yAxisVisible = this._visible && this._axisVisible && this._yAxisVisible;
724
- const zAxisVisible = this._visible && this._axisVisible && this._zAxisVisible;
725
-
726
- this._xAxisWire.setVisible(xAxisVisible);
727
- this._yAxisWire.setVisible(yAxisVisible);
728
- this._zAxisWire.setVisible(zAxisVisible);
729
-
730
- this._xAxisLabel.setVisible(xAxisVisible && !this._xAxisLabelCulled && this._EnabledVisible);
731
- this._yAxisLabel.setVisible(yAxisVisible && !this._yAxisLabelCulled && this._yLabelEnabled);
732
- this._zAxisLabel.setVisible(zAxisVisible && !this._zAxisLabelCulled && this._zLabelEnabled);
733
-
734
- this._cpDirty = true;
735
-
736
- this._needUpdate();
351
+ this._visible.set(value);
737
352
  }
738
353
 
739
354
  /**
@@ -742,7 +357,7 @@ class DistanceMeasurement extends Component {
742
357
  * @type {Boolean}
743
358
  */
744
359
  get visible() {
745
- return this._visible;
360
+ return this._visible.get();
746
361
  }
747
362
 
748
363
  /**
@@ -751,9 +366,7 @@ class DistanceMeasurement extends Component {
751
366
  * @type {Boolean}
752
367
  */
753
368
  set originVisible(value) {
754
- value = value !== undefined ? Boolean(value) : this.plugin.defaultOriginVisible;
755
- this._originVisible = value;
756
- this._originDot.setVisible(this._visible && this._originVisible);
369
+ this._originVisible.set(value);
757
370
  }
758
371
 
759
372
  /**
@@ -762,7 +375,7 @@ class DistanceMeasurement extends Component {
762
375
  * @type {Boolean}
763
376
  */
764
377
  get originVisible() {
765
- return this._originVisible;
378
+ return this._originVisible.get();
766
379
  }
767
380
 
768
381
  /**
@@ -771,9 +384,7 @@ class DistanceMeasurement extends Component {
771
384
  * @type {Boolean}
772
385
  */
773
386
  set targetVisible(value) {
774
- value = value !== undefined ? Boolean(value) : this.plugin.defaultTargetVisible;
775
- this._targetVisible = value;
776
- this._targetDot.setVisible(this._visible && this._targetVisible);
387
+ this._targetVisible.set(value);
777
388
  }
778
389
 
779
390
  /**
@@ -782,7 +393,7 @@ class DistanceMeasurement extends Component {
782
393
  * @type {Boolean}
783
394
  */
784
395
  get targetVisible() {
785
- return this._targetVisible;
396
+ return this._targetVisible.get();
786
397
  }
787
398
 
788
399
  /**
@@ -791,8 +402,8 @@ class DistanceMeasurement extends Component {
791
402
  * @type {Boolean}
792
403
  */
793
404
  set useRotationAdjustment(value) {
794
- value = value !== undefined ? Boolean(value) : this.plugin.useRotationAdjustment;
795
- this._useRotationAdjustment = value;
405
+ this._useRotationAdjustment.set(value);
406
+ this._update();
796
407
  }
797
408
 
798
409
  /**
@@ -801,7 +412,7 @@ class DistanceMeasurement extends Component {
801
412
  * @type {Boolean}
802
413
  */
803
414
  get useRotationAdjustment() {
804
- return this._useRotationAdjustment;
415
+ return this._useRotationAdjustment.get();
805
416
  }
806
417
 
807
418
  /**
@@ -812,17 +423,7 @@ class DistanceMeasurement extends Component {
812
423
  * @type {Boolean}
813
424
  */
814
425
  set axisEnabled(value) {
815
- value = value !== undefined ? Boolean(value) : this.plugin.defaultAxisVisible;
816
- this._axisEnabled = value;
817
- var axisVisible = this._visible && this._axisVisible && this._axisEnabled;
818
- this._xAxisWire.setVisible(axisVisible && this._xAxisVisible);
819
- this._yAxisWire.setVisible(axisVisible && this._yAxisVisible);
820
- this._zAxisWire.setVisible(axisVisible && this._zAxisVisible);
821
- this._xAxisLabel.setVisible(axisVisible && !this._xAxisLabelCulled&& this._xAxisVisible && this._xLabelEnabled);
822
- this._yAxisLabel.setVisible(axisVisible && !this._yAxisLabelCulled&& this._xAxisVisible && this._yLabelEnabled);
823
- this._zAxisLabel.setVisible(axisVisible && !this._zAxisLabelCulled&& this._xAxisVisible && this._zLabelEnabled);
824
- this._cpDirty = true;
825
- this._needUpdate();
426
+ this._axisEnabled.set(value);
826
427
  }
827
428
 
828
429
  /**
@@ -833,7 +434,7 @@ class DistanceMeasurement extends Component {
833
434
  * @type {Boolean}
834
435
  */
835
436
  get axisEnabled() {
836
- return this._axisEnabled;
437
+ return this._axisEnabled.get();
837
438
  }
838
439
 
839
440
  /**
@@ -844,17 +445,7 @@ class DistanceMeasurement extends Component {
844
445
  * @type {Boolean}
845
446
  */
846
447
  set axisVisible(value) {
847
- value = value !== undefined ? Boolean(value) : this.plugin.defaultAxisVisible;
848
- this._axisVisible = value;
849
- var axisVisible = this._visible && this._axisVisible && this._axisEnabled;
850
- this._xAxisWire.setVisible(axisVisible && this._xAxisVisible);
851
- this._yAxisWire.setVisible(axisVisible && this._yAxisVisible);
852
- this._zAxisWire.setVisible(axisVisible && this._zAxisVisible);
853
- this._xAxisLabel.setVisible(axisVisible && !this._xAxisLabelCulled&& this._xAxisVisible);
854
- this._yAxisLabel.setVisible(axisVisible && !this._yAxisLabelCulled&& this._yAxisVisible);
855
- this._zAxisLabel.setVisible(axisVisible && !this._zAxisLabelCulled&& this._zAxisVisible);
856
- this._cpDirty = true;
857
- this._needUpdate();
448
+ this._axisVisible.set(value);
858
449
  }
859
450
 
860
451
  /**
@@ -865,7 +456,7 @@ class DistanceMeasurement extends Component {
865
456
  * @type {Boolean}
866
457
  */
867
458
  get axisVisible() {
868
- return this._axisVisible;
459
+ return this._axisVisible.get();
869
460
  }
870
461
 
871
462
  /**
@@ -876,13 +467,7 @@ class DistanceMeasurement extends Component {
876
467
  * @type {Boolean}
877
468
  */
878
469
  set xAxisVisible(value) {
879
- value = value !== undefined ? Boolean(value) : this.plugin.defaultAxisVisible;
880
- this._xAxisVisible = value;
881
- const axisVisible = this._visible && this._axisVisible && this._xAxisVisible && this._axisEnabled;
882
- this._xAxisWire.setVisible(axisVisible);
883
- this._xAxisLabel.setVisible(axisVisible && !this._xAxisLabelCulled && this._xLabelEnabled);
884
- this._cpDirty = true;
885
- this._needUpdate();
470
+ this._xAxisVisible.set(value);
886
471
  }
887
472
 
888
473
  /**
@@ -893,7 +478,7 @@ class DistanceMeasurement extends Component {
893
478
  * @type {Boolean}
894
479
  */
895
480
  get xAxisVisible() {
896
- return this._xAxisVisible;
481
+ return this._xAxisVisible.get();
897
482
  }
898
483
 
899
484
  /**
@@ -904,13 +489,7 @@ class DistanceMeasurement extends Component {
904
489
  * @type {Boolean}
905
490
  */
906
491
  set yAxisVisible(value) {
907
- value = value !== undefined ? Boolean(value) : this.plugin.defaultAxisVisible;
908
- this._yAxisVisible = value;
909
- const axisVisible = this._visible && this._axisVisible && this._yAxisVisible && this._axisEnabled;
910
- this._yAxisWire.setVisible(axisVisible);
911
- this._yAxisLabel.setVisible(axisVisible && !this._yAxisLabelCulled && this._yLabelEnabled);
912
- this._cpDirty = true;
913
- this._needUpdate();
492
+ this._yAxisVisible.set(value);
914
493
  }
915
494
 
916
495
  /**
@@ -921,7 +500,7 @@ class DistanceMeasurement extends Component {
921
500
  * @type {Boolean}
922
501
  */
923
502
  get yAxisVisible() {
924
- return this._yAxisVisible;
503
+ return this._yAxisVisible.get();
925
504
  }
926
505
 
927
506
  /**
@@ -932,13 +511,7 @@ class DistanceMeasurement extends Component {
932
511
  * @type {Boolean}
933
512
  */
934
513
  set zAxisVisible(value) {
935
- value = value !== undefined ? Boolean(value) : this.plugin.defaultAxisVisible;
936
- this._zAxisVisible = value;
937
- const axisVisible = this._visible && this._axisVisible && this._zAxisVisible && this._axisEnabled;
938
- this._zAxisWire.setVisible(axisVisible);
939
- this._zAxisLabel.setVisible(axisVisible && !this._zAxisLabelCulled && this._zLabelEnabled);
940
- this._cpDirty = true;
941
- this._needUpdate();
514
+ this._zAxisVisible.set(value);
942
515
  }
943
516
 
944
517
  /**
@@ -949,7 +522,7 @@ class DistanceMeasurement extends Component {
949
522
  * @type {Boolean}
950
523
  */
951
524
  get zAxisVisible() {
952
- return this._zAxisVisible;
525
+ return this._zAxisVisible.get();
953
526
  }
954
527
 
955
528
  /**
@@ -958,11 +531,7 @@ class DistanceMeasurement extends Component {
958
531
  * @type {Boolean}
959
532
  */
960
533
  set wireVisible(value) {
961
- value = value !== undefined ? Boolean(value) : this.plugin.defaultWireVisible;
962
- this._wireVisible = value;
963
- var wireVisible = this._visible && this._wireVisible;
964
- this._lengthLabel.setVisible(wireVisible && this._lengthLabelEnabled);
965
- this._lengthWire.setVisible(wireVisible);
534
+ this._wireVisible.set(value);
966
535
  }
967
536
 
968
537
  /**
@@ -971,7 +540,7 @@ class DistanceMeasurement extends Component {
971
540
  * @type {Boolean}
972
541
  */
973
542
  get wireVisible() {
974
- return this._wireVisible;
543
+ return this._wireVisible.get();
975
544
  }
976
545
 
977
546
  /**
@@ -980,15 +549,7 @@ class DistanceMeasurement extends Component {
980
549
  * @type {Boolean}
981
550
  */
982
551
  set labelsVisible(value) {
983
- value = value !== undefined ? Boolean(value) : this.plugin.defaultLabelsVisible;
984
- this._labelsVisible = value;
985
- var labelsVisible = this._visible && this._labelsVisible;
986
- this._xAxisLabel.setVisible(labelsVisible && !this._xAxisLabelCulled && this._clickable && this._axisEnabled && this._xLabelEnabled);
987
- this._yAxisLabel.setVisible(labelsVisible && !this._yAxisLabelCulled && this._clickable && this._axisEnabled && this._yLabelEnabled);
988
- this._zAxisLabel.setVisible(labelsVisible && !this._zAxisLabelCulled && this._clickable && this._axisEnabled && this._zLabelEnabled);
989
- this._lengthLabel.setVisible(labelsVisible && this._lengthLabelEnabled);
990
- this._cpDirty = true;
991
- this._needUpdate();
552
+ this._labelsVisible.set(value);
992
553
  }
993
554
 
994
555
  /**
@@ -997,7 +558,7 @@ class DistanceMeasurement extends Component {
997
558
  * @type {Boolean}
998
559
  */
999
560
  get labelsVisible() {
1000
- return this._labelsVisible;
561
+ return this._labelsVisible.get();
1001
562
  }
1002
563
 
1003
564
  /**
@@ -1006,12 +567,7 @@ class DistanceMeasurement extends Component {
1006
567
  * @type {Boolean}
1007
568
  */
1008
569
  set xLabelEnabled(value) {
1009
- value = value !== undefined ? Boolean(value) : this.plugin.defaultXLabelEnabled;
1010
- this._xLabelEnabled = value;
1011
- var labelsVisible = this._visible && this._labelsVisible;
1012
- this._xAxisLabel.setVisible(labelsVisible && !this._xAxisLabelCulled && this._clickable && this._axisEnabled && this._xLabelEnabled);
1013
- this._cpDirty = true;
1014
- this._needUpdate();
570
+ this._xLabelEnabled.set(value);
1015
571
  }
1016
572
 
1017
573
  /**
@@ -1020,7 +576,7 @@ class DistanceMeasurement extends Component {
1020
576
  * @type {Boolean}
1021
577
  */
1022
578
  get xLabelEnabled(){
1023
- return this._xLabelEnabled;
579
+ return this._xLabelEnabled.get();
1024
580
  }
1025
581
 
1026
582
  /**
@@ -1029,12 +585,7 @@ class DistanceMeasurement extends Component {
1029
585
  * @type {Boolean}
1030
586
  */
1031
587
  set yLabelEnabled(value) {
1032
- value = value !== undefined ? Boolean(value) : this.plugin.defaultYLabelEnabled;
1033
- this._yLabelEnabled = value;
1034
- var labelsVisible = this._visible && this._labelsVisible;
1035
- this._yAxisLabel.setVisible(labelsVisible && !this._yAxisLabelCulled && this._clickable && this._axisEnabled && this._yLabelEnabled);
1036
- this._cpDirty = true;
1037
- this._needUpdate();
588
+ this._yLabelEnabled.set(value);
1038
589
  }
1039
590
 
1040
591
  /**
@@ -1043,7 +594,7 @@ class DistanceMeasurement extends Component {
1043
594
  * @type {Boolean}
1044
595
  */
1045
596
  get yLabelEnabled(){
1046
- return this._yLabelEnabled;
597
+ return this._yLabelEnabled.get();
1047
598
  }
1048
599
 
1049
600
  /**
@@ -1052,12 +603,7 @@ class DistanceMeasurement extends Component {
1052
603
  * @type {Boolean}
1053
604
  */
1054
605
  set zLabelEnabled(value) {
1055
- value = value !== undefined ? Boolean(value) : this.plugin.defaultZLabelEnabled;
1056
- this._zLabelEnabled = value;
1057
- var labelsVisible = this._visible && this._labelsVisible;
1058
- this._zAxisLabel.setVisible(labelsVisible && !this._zAxisLabelCulled && this._clickable && this._axisEnabled && this._zLabelEnabled);
1059
- this._cpDirty = true;
1060
- this._needUpdate();
606
+ this._zLabelEnabled.set(value);
1061
607
  }
1062
608
 
1063
609
  /**
@@ -1066,7 +612,7 @@ class DistanceMeasurement extends Component {
1066
612
  * @type {Boolean}
1067
613
  */
1068
614
  get zLabelEnabled(){
1069
- return this._zLabelEnabled;
615
+ return this._zLabelEnabled.get();
1070
616
  }
1071
617
 
1072
618
  /**
@@ -1075,12 +621,7 @@ class DistanceMeasurement extends Component {
1075
621
  * @type {Boolean}
1076
622
  */
1077
623
  set lengthLabelEnabled(value) {
1078
- value = value !== undefined ? Boolean(value) : this.plugin.defaultLengthLabelEnabled;
1079
- this._lengthLabelEnabled = value;
1080
- var labelsVisible = this._visible && this._labelsVisible;
1081
- this._lengthLabel.setVisible(labelsVisible && !this._lengthAxisLabelCulled && this._clickable && this._axisEnabled && this._lengthLabelEnabled);
1082
- this._cpDirty = true;
1083
- this._needUpdate();
624
+ this._lengthLabelEnabled.set(value);
1084
625
  }
1085
626
 
1086
627
  /**
@@ -1089,7 +630,7 @@ class DistanceMeasurement extends Component {
1089
630
  * @type {Boolean}
1090
631
  */
1091
632
  get lengthLabelEnabled(){
1092
- return this._lengthLabelEnabled;
633
+ return this._lengthLabelEnabled.get();
1093
634
  }
1094
635
 
1095
636
  /**
@@ -1098,8 +639,8 @@ class DistanceMeasurement extends Component {
1098
639
  * @type {Boolean}
1099
640
  */
1100
641
  set labelsOnWires(value) {
1101
- value = value !== undefined ? Boolean(value) : this.plugin.defaultLabelsOnWires;
1102
- this._labelsOnWires = value;
642
+ this._labelsOnWires.set(value);
643
+ this._update();
1103
644
  }
1104
645
 
1105
646
  /**
@@ -1108,7 +649,7 @@ class DistanceMeasurement extends Component {
1108
649
  * @type {Boolean}
1109
650
  */
1110
651
  get labelsOnWires() {
1111
- return this._labelsOnWires;
652
+ return this._labelsOnWires.get();
1112
653
  }
1113
654
 
1114
655
  /**
@@ -1116,16 +657,7 @@ class DistanceMeasurement extends Component {
1116
657
  * @param highlighted
1117
658
  */
1118
659
  setHighlighted(highlighted) {
1119
- this._originDot.setHighlighted(highlighted);
1120
- this._targetDot.setHighlighted(highlighted);
1121
- this._xAxisWire.setHighlighted(highlighted);
1122
- this._yAxisWire.setHighlighted(highlighted);
1123
- this._zAxisWire.setHighlighted(highlighted);
1124
- this._xAxisLabel.setHighlighted(highlighted);
1125
- this._yAxisLabel.setHighlighted(highlighted);
1126
- this._zAxisLabel.setHighlighted(highlighted);
1127
- this._lengthWire.setHighlighted(highlighted);
1128
- this._lengthLabel.setHighlighted(highlighted);
660
+ this._drawables.forEach(d => d.setHighlighted(highlighted));
1129
661
  }
1130
662
 
1131
663
  /**
@@ -1134,18 +666,8 @@ class DistanceMeasurement extends Component {
1134
666
  * @type {Boolean}
1135
667
  */
1136
668
  set clickable(value) {
1137
- value = !!value;
1138
- this._clickable = value;
1139
- this._originDot.setClickable(this._clickable);
1140
- this._targetDot.setClickable(this._clickable);
1141
- this._xAxisWire.setClickable(this._clickable);
1142
- this._yAxisWire.setClickable(this._clickable);
1143
- this._zAxisWire.setClickable(this._clickable);
1144
- this._lengthWire.setClickable(this._clickable);
1145
- this._xAxisLabel.setClickable(this._clickable);
1146
- this._yAxisLabel.setClickable(this._clickable);
1147
- this._zAxisLabel.setClickable(this._clickable);
1148
- this._lengthLabel.setClickable(this._clickable);
669
+ this._clickable.set(!!value);
670
+ this._drawables.forEach(d => d.setClickable(this._clickable.get()));
1149
671
  }
1150
672
 
1151
673
  /**
@@ -1154,52 +676,16 @@ class DistanceMeasurement extends Component {
1154
676
  * @type {Boolean}
1155
677
  */
1156
678
  get clickable() {
1157
- return this._clickable;
679
+ return this._clickable.get();
1158
680
  }
1159
681
 
1160
682
  /**
1161
683
  * @private
1162
684
  */
1163
685
  destroy() {
1164
-
1165
- const scene = this.plugin.viewer.scene;
1166
- const metrics = scene.metrics;
1167
-
1168
- if (this._onViewMatrix) {
1169
- scene.camera.off(this._onViewMatrix);
1170
- }
1171
- if (this._onProjMatrix) {
1172
- scene.camera.off(this._onProjMatrix);
1173
- }
1174
- if (this._onCanvasBoundary) {
1175
- scene.canvas.off(this._onCanvasBoundary);
1176
- }
1177
- if (this._onMetricsUnits) {
1178
- metrics.off(this._onMetricsUnits);
1179
- }
1180
- if (this._onMetricsScale) {
1181
- metrics.off(this._onMetricsScale);
1182
- }
1183
- if (this._onMetricsOrigin) {
1184
- metrics.off(this._onMetricsOrigin);
1185
- }
1186
- if (this._onSectionPlaneUpdated) {
1187
- scene.off(this._onSectionPlaneUpdated);
1188
- }
1189
-
1190
- this._originDot.destroy();
1191
- this._targetDot.destroy();
1192
- this._xAxisWire.destroy();
1193
- this._yAxisWire.destroy();
1194
- this._zAxisWire.destroy();
1195
- this._lengthLabel.destroy();
1196
- this._xAxisLabel.destroy();
1197
- this._yAxisLabel.destroy();
1198
- this._zAxisLabel.destroy();
1199
- this._lengthWire.destroy();
1200
-
686
+ this._cleanups.forEach(cleanup => cleanup());
1201
687
  super.destroy();
1202
688
  }
1203
689
  }
1204
690
 
1205
- export {DistanceMeasurement};
691
+ export {DistanceMeasurement};