@xeokit/xeokit-sdk 2.6.23 → 2.6.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.6.23",
3
+ "version": "2.6.26",
4
4
  "description": "Web Programming Toolkit for 3D/2D BIM and AEC Graphics",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -1,6 +1,5 @@
1
- import {Marker} from "../../viewer/scene/marker/Marker.js";
1
+ import {Dot3D} from "../lib/ui/index.js";
2
2
  import {Wire} from "../lib/html/Wire.js";
3
- import {Dot} from "../lib/html/Dot.js";
4
3
  import {Label} from "../lib/html/Label.js";
5
4
  import {math} from "../../viewer/scene/math/math.js";
6
5
  import {Component} from "../../viewer/scene/Component.js";
@@ -37,10 +36,6 @@ class AngleMeasurement extends Component {
37
36
 
38
37
  var scene = this.plugin.viewer.scene;
39
38
 
40
- this._originMarker = new Marker(scene, cfg.origin);
41
- this._cornerMarker = new Marker(scene, cfg.corner);
42
- this._targetMarker = new Marker(scene, cfg.target);
43
-
44
39
  this._originWorld = math.vec3();
45
40
  this._cornerWorld = math.vec3();
46
41
  this._targetWorld = math.vec3();
@@ -80,7 +75,7 @@ class AngleMeasurement extends Component {
80
75
  this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousemove', event));
81
76
  };
82
77
 
83
- this._originDot = new Dot(this._container, {
78
+ this._originDot = new Dot3D(scene, cfg.origin, this._container, {
84
79
  fillColor: this._color,
85
80
  zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
86
81
  onMouseOver,
@@ -91,7 +86,7 @@ class AngleMeasurement extends Component {
91
86
  onMouseMove,
92
87
  onContextMenu
93
88
  });
94
- this._cornerDot = new Dot(this._container, {
89
+ this._cornerDot = new Dot3D(scene, cfg.corner, this._container, {
95
90
  fillColor: this._color,
96
91
  zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
97
92
  onMouseOver,
@@ -102,7 +97,7 @@ class AngleMeasurement extends Component {
102
97
  onMouseMove,
103
98
  onContextMenu
104
99
  });
105
- this._targetDot = new Dot(this._container, {
100
+ this._targetDot = new Dot3D(scene, cfg.target, this._container, {
106
101
  fillColor: this._color,
107
102
  zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
108
103
  onMouseOver,
@@ -169,19 +164,19 @@ class AngleMeasurement extends Component {
169
164
  this._labelsVisible = false;
170
165
  this._clickable = false;
171
166
 
172
- this._originMarker.on("worldPos", (value) => {
167
+ this._originDot.on("worldPos", (value) => {
173
168
  this._originWorld.set(value || [0, 0, 0]);
174
169
  this._wpDirty = true;
175
170
  this._needUpdate(0); // No lag
176
171
  });
177
172
 
178
- this._cornerMarker.on("worldPos", (value) => {
173
+ this._cornerDot.on("worldPos", (value) => {
179
174
  this._cornerWorld.set(value || [0, 0, 0]);
180
175
  this._wpDirty = true;
181
176
  this._needUpdate(0); // No lag
182
177
  });
183
178
 
184
- this._targetMarker.on("worldPos", (value) => {
179
+ this._targetDot.on("worldPos", (value) => {
185
180
  this._targetWorld.set(value || [0, 0, 0]);
186
181
  this._wpDirty = true;
187
182
  this._needUpdate(0); // No lag
@@ -287,9 +282,9 @@ class AngleMeasurement extends Component {
287
282
  if (this._cpDirty) {
288
283
 
289
284
  const near = -0.3;
290
- const zOrigin = this._originMarker.viewPos[2];
291
- const zCorner = this._cornerMarker.viewPos[2];
292
- const zTarget = this._targetMarker.viewPos[2];
285
+ const zOrigin = this._originDot.viewPos[2];
286
+ const zCorner = this._cornerDot.viewPos[2];
287
+ const zTarget = this._targetDot.viewPos[2];
293
288
 
294
289
  if (zOrigin > near || zCorner > near || zTarget > near) {
295
290
 
@@ -326,10 +321,6 @@ class AngleMeasurement extends Component {
326
321
  j += 2;
327
322
  }
328
323
 
329
- this._originDot.setPos(cp[0], cp[1]);
330
- this._cornerDot.setPos(cp[2], cp[3]);
331
- this._targetDot.setPos(cp[4], cp[5]);
332
-
333
324
  this._originWire.setStartAndEnd(cp[0], cp[1], cp[2], cp[3]);
334
325
  this._targetWire.setStartAndEnd(cp[2], cp[3], cp[4], cp[5]);
335
326
 
@@ -410,30 +401,30 @@ class AngleMeasurement extends Component {
410
401
  }
411
402
 
412
403
  /**
413
- * Gets the origin {@link Marker}.
404
+ * Gets the origin {@link Dot3D}.
414
405
  *
415
- * @type {Marker}
406
+ * @type {Dot3D}
416
407
  */
417
408
  get origin() {
418
- return this._originMarker;
409
+ return this._originDot;
419
410
  }
420
411
 
421
412
  /**
422
- * Gets the corner {@link Marker}.
413
+ * Gets the corner {@link Dot3D}.
423
414
  *
424
- * @type {Marker}
415
+ * @type {Dot3D}
425
416
  */
426
417
  get corner() {
427
- return this._cornerMarker;
418
+ return this._cornerDot;
428
419
  }
429
420
 
430
421
  /**
431
- * Gets the target {@link Marker}.
422
+ * Gets the target {@link Dot3D}.
432
423
  *
433
- * @type {Marker}
424
+ * @type {Dot3D}
434
425
  */
435
426
  get target() {
436
- return this._targetMarker;
427
+ return this._targetDot;
437
428
  }
438
429
 
439
430
  /**
@@ -503,7 +494,7 @@ class AngleMeasurement extends Component {
503
494
  }
504
495
 
505
496
  /**
506
- * Sets if the origin {@link Marker} is visible.
497
+ * Sets if the origin {@link Dot3D} is visible.
507
498
  *
508
499
  * @type {Boolean}
509
500
  */
@@ -516,7 +507,7 @@ class AngleMeasurement extends Component {
516
507
  }
517
508
 
518
509
  /**
519
- * Gets if the origin {@link Marker} is visible.
510
+ * Gets if the origin {@link Dot3D} is visible.
520
511
  *
521
512
  * @type {Boolean}
522
513
  */
@@ -525,7 +516,7 @@ class AngleMeasurement extends Component {
525
516
  }
526
517
 
527
518
  /**
528
- * Sets if the corner {@link Marker} is visible.
519
+ * Sets if the corner {@link Dot3D} is visible.
529
520
  *
530
521
  * @type {Boolean}
531
522
  */
@@ -538,7 +529,7 @@ class AngleMeasurement extends Component {
538
529
  }
539
530
 
540
531
  /**
541
- * Gets if the corner {@link Marker} is visible.
532
+ * Gets if the corner {@link Dot3D} is visible.
542
533
  *
543
534
  * @type {Boolean}
544
535
  */
@@ -547,7 +538,7 @@ class AngleMeasurement extends Component {
547
538
  }
548
539
 
549
540
  /**
550
- * Sets if the target {@link Marker} is visible.
541
+ * Sets if the target {@link Dot3D} is visible.
551
542
  *
552
543
  * @type {Boolean}
553
544
  */
@@ -560,7 +551,7 @@ class AngleMeasurement extends Component {
560
551
  }
561
552
 
562
553
  /**
563
- * Gets if the target {@link Marker} is visible.
554
+ * Gets if the target {@link Dot3D} is visible.
564
555
  *
565
556
  * @type {Boolean}
566
557
  */
@@ -4,6 +4,7 @@ export * from "./AngleMeasurementsMouseControl.js";
4
4
  export * from "./AngleMeasurementsTouchControl.js";
5
5
 
6
6
  import {Component} from "../../viewer/scene/Component.js";
7
+ import {math} from "../../viewer/scene/math/math.js";
7
8
  import {activateDraggableDots} from "../../../src/plugins/lib/ui/index.js";
8
9
 
9
10
  class AngleMeasurementEditControl extends Component {
@@ -28,11 +29,30 @@ class AngleMeasurementEditControl extends Component {
28
29
  viewer: viewer,
29
30
  handleMouseEvents: handleMouseEvents,
30
31
  handleTouchEvents: handleTouchEvents,
31
- snapping: cfg.snapping,
32
32
  pointerLens: cfg.pointerLens,
33
- color: measurement.color,
34
- markers: [ measurement.origin, measurement.corner, measurement.target ],
35
- onEdit: () => this.fire("edited")
33
+ dots: [ measurement.origin, measurement.corner, measurement.target ],
34
+ ray2WorldPos: (orig, dir, canvasPos) => {
35
+ const tryPickWorldPos = snap => {
36
+ const pickResult = viewer.scene.pick({
37
+ canvasPos: canvasPos,
38
+ snapToEdge: snap,
39
+ snapToVertex: snap,
40
+ pickSurface: true // <<------ This causes picking to find the intersection point on the entity
41
+ });
42
+
43
+ // If - when snapping - no pick found, then try w/o snapping
44
+ return (pickResult && pickResult.worldPos) ? pickResult.worldPos : (snap && tryPickWorldPos(false));
45
+ };
46
+
47
+ return tryPickWorldPos(!!cfg.snapping);
48
+ },
49
+ onEnd: (initPos, dot) => {
50
+ const changed = ! math.compareVec3(initPos, dot.worldPos);
51
+ if (changed) {
52
+ this.fire("edited");
53
+ }
54
+ return changed;
55
+ }
36
56
  });
37
57
 
38
58
  const destroyCb = measurement.on("destroyed", cleanup);
@@ -1,6 +1,11 @@
1
+ import {math} from '../../viewer/scene/math/math.js';
1
2
  import {Marker} from "../../viewer/scene/marker/Marker.js";
2
3
  import {utils} from "../../viewer/scene/utils.js";
3
4
 
5
+ const tempVec3a = math.vec3();
6
+ const tempVec3b = math.vec3();
7
+ const tempVec3c = math.vec3();
8
+
4
9
  /**
5
10
  * A {@link Marker} with an HTML label attached to it, managed by an {@link AnnotationsPlugin}.
6
11
  *
@@ -40,6 +45,9 @@ class Annotation extends Marker {
40
45
  this._marker.addEventListener("click", this._onMouseClickedExternalMarker = () => {
41
46
  this.plugin.fire("markerClicked", this);
42
47
  });
48
+ this._marker.addEventListener("contextmenu", this._onContextMenuExtenalMarker = () => {
49
+ this.plugin.fire("contextmenu", this);
50
+ });
43
51
  this._marker.addEventListener("mouseenter", this._onMouseEnterExternalMarker = () => {
44
52
  this.plugin.fire("markerMouseEnter", this);
45
53
  });
@@ -67,6 +75,7 @@ class Annotation extends Marker {
67
75
  this._values = cfg.values || {};
68
76
  this._layoutDirty = true;
69
77
  this._visibilityDirty = true;
78
+ this._labelPosition = 24;
70
79
 
71
80
  this._buildHTML();
72
81
 
@@ -159,6 +168,10 @@ class Annotation extends Marker {
159
168
  this._marker.addEventListener("click", () => {
160
169
  this.plugin.fire("markerClicked", this);
161
170
  });
171
+ this._marker.addEventListener("contextmenu", e => {
172
+ e.preventDefault();
173
+ this.plugin.fire("contextmenu", this);
174
+ });
162
175
  this._marker.addEventListener("mouseenter", () => {
163
176
  this.plugin.fire("markerMouseEnter", this);
164
177
  });
@@ -193,17 +206,23 @@ class Annotation extends Marker {
193
206
  * @private
194
207
  */
195
208
  _updatePosition() {
209
+ const px = x => x + "px";
196
210
  const boundary = this.scene.canvas.boundary;
197
- const left = boundary[0];
198
- const top = boundary[1];
199
- const canvasPos = this.canvasPos;
200
- this._marker.style.left = (Math.floor(left + canvasPos[0]) - 12) + "px";
201
- this._marker.style.top = (Math.floor(top + canvasPos[1]) - 12) + "px";
211
+ const left = boundary[0] + this.canvasPos[0];
212
+ const top = boundary[1] + this.canvasPos[1];
213
+ const markerRect = this._marker.getBoundingClientRect();
214
+ const markerWidth = markerRect.width;
215
+ const markerDir = (this._markerAlign === "right") ? -1 : ((this._markerAlign === "center") ? 0 : 1);
216
+ const markerCenter = left + markerDir * (markerWidth / 2 - 12);
217
+ this._marker.style.left = px(markerCenter - markerWidth / 2);
218
+ this._marker.style.top = px(top - 12);
202
219
  this._marker.style["z-index"] = 90005 + Math.floor(this._viewPos[2]) + 1;
203
- const offsetX = 20;
204
- const offsetY = -17;
205
- this._label.style.left = 20 + Math.floor(left + canvasPos[0] + offsetX) + "px";
206
- this._label.style.top = Math.floor(top + canvasPos[1] + offsetY) + "px";
220
+
221
+ const labelRect = this._label.getBoundingClientRect();
222
+ const labelWidth = labelRect.width;
223
+ const labelDir = Math.sign(this._labelPosition);
224
+ this._label.style.left = px(markerCenter + labelDir * (markerWidth / 2 + Math.abs(this._labelPosition) + labelWidth / 2) - labelWidth / 2);
225
+ this._label.style.top = px(top - 17);
207
226
  this._label.style["z-index"] = 90005 + Math.floor(this._viewPos[2]) + 1;
208
227
  }
209
228
 
@@ -220,6 +239,55 @@ class Annotation extends Marker {
220
239
  return template;
221
240
  }
222
241
 
242
+ /**
243
+ * Sets the Marker's worldPos and entity properties based on passed {@link PickResult}
244
+ *
245
+ * @param {PickResult} pickResult A PickResult to position the Marker at.
246
+ */
247
+ setFromPickResult(pickResult) {
248
+ if (!pickResult.worldPos || !pickResult.worldNormal) {
249
+ this.error("Param 'pickResult' does not have both worldPos and worldNormal");
250
+ } else {
251
+ const normalizedWorldNormal = math.normalizeVec3(pickResult.worldNormal, tempVec3a);
252
+ const offset = (this.plugin && this.plugin.surfaceOffset) || 0;
253
+ const offsetVec = math.mulVec3Scalar(normalizedWorldNormal, offset, tempVec3b);
254
+ const offsetWorldPos = math.addVec3(pickResult.worldPos, offsetVec, tempVec3c);
255
+ this.entity = pickResult.entity;
256
+ this.worldPos = offsetWorldPos;
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Sets the horizontal alignment of the Annotation's marker HTML.
262
+ *
263
+ * @param {String} align Either "left", "center", "right" (default "left")
264
+ */
265
+ setMarkerAlign(align) {
266
+ const valid = [ "left", "center", "right" ];
267
+ if (! valid.includes(align)) {
268
+ this.error("Param 'align' should be one of: " + JSON.stringify(valid));
269
+ } else {
270
+ this._markerAlign = align;
271
+ this._updatePosition();
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Sets the relative horizontal position of the Annotation's label HTML.
277
+ *
278
+ * @param {Number} position Negative - to the left, positive - to the right, otherwise ignore (default 24)
279
+ */
280
+ setLabelPosition(position) {
281
+ if (typeof position !== "number") {
282
+ this.error("Param 'position' is not a number");
283
+ } else if (position === 0) {
284
+ this.error("Param 'position' is zero");
285
+ } else {
286
+ this._labelPosition = position;
287
+ this._updatePosition();
288
+ }
289
+ }
290
+
223
291
  /**
224
292
  * Sets whether or not to show this Annotation's marker.
225
293
  *
@@ -350,6 +418,7 @@ class Annotation extends Marker {
350
418
  this._marker = null;
351
419
  } else {
352
420
  this._marker.removeEventListener("click", this._onMouseClickedExternalMarker);
421
+ this._marker.removeEventListener("contextmenu", this._onContextMenuExtenalMarker);
353
422
  this._marker.removeEventListener("mouseenter", this._onMouseEnterExternalMarker);
354
423
  this._marker.removeEventListener("mouseleave", this._onMouseLeaveExternalMarker);
355
424
  this._marker = null;
@@ -3,10 +3,6 @@ import {Annotation} from "./Annotation.js";
3
3
  import {utils} from "../../viewer/scene/utils.js";
4
4
  import {math} from "../../viewer/scene/math/math.js";
5
5
 
6
- const tempVec3a = math.vec3();
7
- const tempVec3b = math.vec3();
8
- const tempVec3c = math.vec3();
9
-
10
6
  /**
11
7
  * {@link Viewer} plugin that creates {@link Annotation}s.
12
8
  *
@@ -481,24 +477,6 @@ class AnnotationsPlugin extends Plugin {
481
477
  this.error("Viewer component with this ID already exists: " + params.id);
482
478
  delete params.id;
483
479
  }
484
- var worldPos;
485
- var entity;
486
- params.pickResult = params.pickResult || params.pickRecord;
487
- if (params.pickResult) {
488
- const pickResult = params.pickResult;
489
- if (!pickResult.worldPos || !pickResult.worldNormal) {
490
- this.error("Param 'pickResult' does not have both worldPos and worldNormal");
491
- } else {
492
- const normalizedWorldNormal = math.normalizeVec3(pickResult.worldNormal, tempVec3a);
493
- const offsetVec = math.mulVec3Scalar(normalizedWorldNormal, this._surfaceOffset, tempVec3b);
494
- const offsetWorldPos = math.addVec3(pickResult.worldPos, offsetVec, tempVec3c);
495
- worldPos = offsetWorldPos;
496
- entity = pickResult.entity;
497
- }
498
- } else {
499
- worldPos = params.worldPos;
500
- entity = params.entity;
501
- }
502
480
 
503
481
  var markerElement = null;
504
482
  if (params.markerElementId) {
@@ -519,8 +497,6 @@ class AnnotationsPlugin extends Plugin {
519
497
  const annotation = new Annotation(this.viewer.scene, {
520
498
  id: params.id,
521
499
  plugin: this,
522
- entity: entity,
523
- worldPos: worldPos,
524
500
  container: this._container,
525
501
  markerElement: markerElement,
526
502
  labelElement: labelElement,
@@ -536,6 +512,15 @@ class AnnotationsPlugin extends Plugin {
536
512
  projection: params.projection,
537
513
  visible: (params.visible !== false)
538
514
  });
515
+
516
+ params.pickResult = params.pickResult || params.pickRecord;
517
+ if (params.pickResult) {
518
+ annotation.setFromPickResult(params.pickResult);
519
+ } else {
520
+ annotation.entity = params.entity;
521
+ annotation.worldPos = params.worldPos;
522
+ }
523
+
539
524
  this.annotations[annotation.id] = annotation;
540
525
  annotation.on("destroyed", () => {
541
526
  delete this.annotations[annotation.id];
@@ -1,6 +1,5 @@
1
- import {Marker} from "../../viewer/scene/marker/Marker.js";
1
+ import {Dot3D} from "../lib/ui/index.js";
2
2
  import {Wire} from "../lib/html/Wire.js";
3
- import {Dot} from "../lib/html/Dot.js";
4
3
  import {Label} from "../lib/html/Label.js";
5
4
  import {math} from "../../viewer/scene/math/math.js";
6
5
  import {Component} from "../../viewer/scene/Component.js";
@@ -50,8 +49,6 @@ class DistanceMeasurement extends Component {
50
49
  this._eventSubs = {};
51
50
 
52
51
  var scene = this.plugin.viewer.scene;
53
- this._originMarker = new Marker(scene, cfg.origin);
54
- this._targetMarker = new Marker(scene, cfg.target);
55
52
 
56
53
  this._originWorld = math.vec3();
57
54
  this._targetWorld = math.vec3();
@@ -97,7 +94,7 @@ class DistanceMeasurement extends Component {
97
94
  this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent('wheel', event));
98
95
  };
99
96
 
100
- this._originDot = new Dot(this._container, {
97
+ this._originDot = new Dot3D(scene, cfg.origin, this._container, {
101
98
  fillColor: this._color,
102
99
  zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
103
100
  onMouseOver,
@@ -109,7 +106,7 @@ class DistanceMeasurement extends Component {
109
106
  onContextMenu
110
107
  });
111
108
 
112
- this._targetDot = new Dot(this._container, {
109
+ this._targetDot = new Dot3D(scene, cfg.target, this._container, {
113
110
  fillColor: this._color,
114
111
  zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
115
112
  onMouseOver,
@@ -256,13 +253,13 @@ class DistanceMeasurement extends Component {
256
253
  this._labelsOnWires = false;
257
254
  this._clickable = false;
258
255
 
259
- this._originMarker.on("worldPos", (value) => {
256
+ this._originDot.on("worldPos", (value) => {
260
257
  this._originWorld.set(value || [0,0,0]);
261
258
  this._wpDirty = true;
262
259
  this._needUpdate(0); // No lag
263
260
  });
264
261
 
265
- this._targetMarker.on("worldPos", (value) => {
262
+ this._targetDot.on("worldPos", (value) => {
266
263
  this._targetWorld.set(value || [0,0,0]);
267
264
  this._wpDirty = true;
268
265
  this._needUpdate(0); // No lag
@@ -424,8 +421,8 @@ class DistanceMeasurement extends Component {
424
421
  }
425
422
 
426
423
  const near = -0.3;
427
- const vpz1 = this._originMarker.viewPos[2];
428
- const vpz2 = this._targetMarker.viewPos[2];
424
+ const vpz1 = this._originDot.viewPos[2];
425
+ const vpz2 = this._targetDot.viewPos[2];
429
426
 
430
427
  if (vpz1 > near || vpz2 > near) {
431
428
 
@@ -474,9 +471,6 @@ class DistanceMeasurement extends Component {
474
471
  j += 2;
475
472
  }
476
473
 
477
- this._originDot.setPos(cp[0], cp[1]);
478
- this._targetDot.setPos(cp[6], cp[7]);
479
-
480
474
  this._lengthWire.setStartAndEnd(cp[0], cp[1], cp[6], cp[7]);
481
475
 
482
476
  this._xAxisWire.setStartAndEnd(cp[0], cp[1], cp[2], cp[3]);
@@ -618,21 +612,21 @@ class DistanceMeasurement extends Component {
618
612
  }
619
613
 
620
614
  /**
621
- * Gets the origin {@link Marker}.
615
+ * Gets the origin {@link Dot3D}.
622
616
  *
623
- * @type {Marker}
617
+ * @type {Dot3D}
624
618
  */
625
619
  get origin() {
626
- return this._originMarker;
620
+ return this._originDot;
627
621
  }
628
622
 
629
623
  /**
630
- * Gets the target {@link Marker}.
624
+ * Gets the target {@link Dot3D}.
631
625
  *
632
- * @type {Marker}
626
+ * @type {Dot3D}
633
627
  */
634
628
  get target() {
635
- return this._targetMarker;
629
+ return this._targetDot;
636
630
  }
637
631
 
638
632
  /**
@@ -701,7 +695,7 @@ class DistanceMeasurement extends Component {
701
695
  }
702
696
 
703
697
  /**
704
- * Sets if the origin {@link Marker} is visible.
698
+ * Sets if the origin {@link Dot3D} is visible.
705
699
  *
706
700
  * @type {Boolean}
707
701
  */
@@ -712,7 +706,7 @@ class DistanceMeasurement extends Component {
712
706
  }
713
707
 
714
708
  /**
715
- * Gets if the origin {@link Marker} is visible.
709
+ * Gets if the origin {@link Dot3D} is visible.
716
710
  *
717
711
  * @type {Boolean}
718
712
  */
@@ -721,7 +715,7 @@ class DistanceMeasurement extends Component {
721
715
  }
722
716
 
723
717
  /**
724
- * Sets if the target {@link Marker} is visible.
718
+ * Sets if the target {@link Dot3D} is visible.
725
719
  *
726
720
  * @type {Boolean}
727
721
  */
@@ -732,7 +726,7 @@ class DistanceMeasurement extends Component {
732
726
  }
733
727
 
734
728
  /**
735
- * Gets if the target {@link Marker} is visible.
729
+ * Gets if the target {@link Dot3D} is visible.
736
730
  *
737
731
  * @type {Boolean}
738
732
  */
@@ -4,6 +4,7 @@ export * from "./DistanceMeasurementsMouseControl.js";
4
4
  export * from "./DistanceMeasurementsTouchControl.js";
5
5
 
6
6
  import {Component} from "../../viewer/scene/Component.js";
7
+ import {math} from "../../viewer/scene/math/math.js";
7
8
  import {activateDraggableDots} from "../../../src/plugins/lib/ui/index.js";
8
9
 
9
10
  class DistanceMeasurementEditControl extends Component {
@@ -28,11 +29,30 @@ class DistanceMeasurementEditControl extends Component {
28
29
  viewer: viewer,
29
30
  handleMouseEvents: handleMouseEvents,
30
31
  handleTouchEvents: handleTouchEvents,
31
- snapping: cfg.snapping,
32
32
  pointerLens: cfg.pointerLens,
33
- color: measurement.color,
34
- markers: [ measurement.origin, measurement.target ],
35
- onEdit: () => this.fire("edited")
33
+ dots: [ measurement.origin, measurement.target ],
34
+ ray2WorldPos: (orig, dir, canvasPos) => {
35
+ const tryPickWorldPos = snap => {
36
+ const pickResult = viewer.scene.pick({
37
+ canvasPos: canvasPos,
38
+ snapToEdge: snap,
39
+ snapToVertex: snap,
40
+ pickSurface: true // <<------ This causes picking to find the intersection point on the entity
41
+ });
42
+
43
+ // If - when snapping - no pick found, then try w/o snapping
44
+ return (pickResult && pickResult.worldPos) ? pickResult.worldPos : (snap && tryPickWorldPos(false));
45
+ };
46
+
47
+ return tryPickWorldPos(!!cfg.snapping);
48
+ },
49
+ onEnd: (initPos, dot) => {
50
+ const changed = ! math.compareVec3(initPos, dot.worldPos);
51
+ if (changed) {
52
+ this.fire("edited");
53
+ }
54
+ return changed;
55
+ }
36
56
  });
37
57
 
38
58
  const destroyCb = measurement.on("destroyed", cleanup);
@@ -1,5 +1,4 @@
1
1
  import {utils} from "../../viewer/scene/utils.js";
2
- import {math} from "../../viewer";
3
2
 
4
3
  /**
5
4
  * Default data access strategy for {@link XKTLoaderPlugin}.