@xeokit/xeokit-sdk 2.6.13 → 2.6.16

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.13",
3
+ "version": "2.6.16",
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",
@@ -11,7 +11,7 @@
11
11
  "docs": "rm -Rf ./docs/*; ./node_modules/.bin/esdoc",
12
12
  "typedocs": "rm -Rf ./docs/*; typedoc --tsconfig tsconfig.json",
13
13
  "publish": "npm publish --access public",
14
- "changelog": "auto-changelog --commit-limit false --package --template changelog-template.hbs"
14
+ "changelog": "git fetch all; auto-changelog --commit-limit false --package --template changelog-template.hbs"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -318,6 +318,7 @@ class DistanceMeasurement extends Component {
318
318
  this.lengthLabelEnabled = cfg.lengthLabelEnabled;
319
319
  this.labelsVisible = cfg.labelsVisible;
320
320
  this.labelsOnWires = cfg.labelsOnWires;
321
+ this.useRotationAdjustment = cfg.useRotationAdjustment;
321
322
  }
322
323
 
323
324
  _update() {
@@ -331,7 +332,7 @@ class DistanceMeasurement extends Component {
331
332
  if (this._wpDirty) {
332
333
 
333
334
  this._measurementOrientation = determineMeasurementOrientation(this._originWorld, this._targetWorld, 1);
334
- if(this._measurementOrientation === 'Vertical'){
335
+ if(this._measurementOrientation === 'Vertical' && this.useRotationAdjustment){
335
336
  this._wp[0] = this._originWorld[0];
336
337
  this._wp[1] = this._originWorld[1];
337
338
  this._wp[2] = this._originWorld[2];
@@ -1,6 +1,6 @@
1
- import {Plugin} from "../../viewer/Plugin.js";
2
- import {DistanceMeasurement} from "./DistanceMeasurement.js";
3
- import {DistanceMeasurementsMouseControl} from "./DistanceMeasurementsMouseControl.js";
1
+ import { Plugin } from "../../viewer/Plugin.js";
2
+ import { DistanceMeasurement } from "./DistanceMeasurement.js";
3
+ import { DistanceMeasurementsMouseControl } from "./DistanceMeasurementsMouseControl.js";
4
4
 
5
5
  /**
6
6
  * {@link Viewer} plugin for measuring point-to-point distances.
@@ -263,304 +263,322 @@ import {DistanceMeasurementsMouseControl} from "./DistanceMeasurementsMouseContr
263
263
  * ````
264
264
  */
265
265
  class DistanceMeasurementsPlugin extends Plugin {
266
+ /**
267
+ * @constructor
268
+ * @param {Viewer} viewer The Viewer.
269
+ * @param {Object} [cfg] Plugin configuration.
270
+ * @param {String} [cfg.id="DistanceMeasurements"] Optional ID for this plugin, so that we can find it within {@link Viewer#plugins}.
271
+ * @param {Number} [cfg.labelMinAxisLength=25] The minimum length, in pixels, of an axis wire beyond which its label is shown.
272
+ * @param {HTMLElement} [cfg.container] Container DOM element for markers and labels. Defaults to ````document.body````.
273
+ * @param {boolean} [cfg.defaultVisible=true] The default value of the DistanceMeasurements `visible` property.
274
+ * @param {boolean} [cfg.defaultOriginVisible=true] The default value of the DistanceMeasurements `originVisible` property.
275
+ * @param {boolean} [cfg.defaultTargetVisible=true] The default value of the DistanceMeasurements `targetVisible` property.
276
+ * @param {boolean} [cfg.defaultWireVisible=true] The default value of the DistanceMeasurements `wireVisible` property.
277
+ * @param {boolean} [cfg.defaultLabelsVisible=true] The default value of the DistanceMeasurements `labelsVisible` property.
278
+ * @param {boolean} [cfg.defaultXLabelEnabled=true] The default value of the DistanceMeasurements `xLabelEnabled` property.
279
+ * @param {boolean} [cfg.defaultYLabelEnabled=true] The default value of the DistanceMeasurements `yLabelEnabled` property.
280
+ * @param {boolean} [cfg.defaultZLabelEnabled=true] The default value of the DistanceMeasurements `zLabelEnabled` property.
281
+ * @param {boolean} [cfg.defaultLengthLabelEnabled=true] The default value of the DistanceMeasurements `lengthLabelEnabled` property.
282
+ * @param {boolean} [cfg.defaultAxisVisible=true] The default value of the DistanceMeasurements `axisVisible` property.
283
+ * @param {boolean} [cfg.defaultXAxisVisible=true] The default value of the DistanceMeasurements `xAxisVisible` property.
284
+ * @param {boolean} [cfg.defaultYAxisVisible=true] The default value of the DistanceMeasurements `yAxisVisible` property.
285
+ * @param {boolean} [cfg.defaultZAxisVisible=true] The default value of the DistanceMeasurements `zAxisVisible` property.
286
+ * @param {boolean} [cfg.useRotationAdjustment=false] The default value of DistanceMeasurements `useRotationAdjustment` property.
287
+ * @param {string} [cfg.defaultColor=#00BBFF] The default color of the length dots, wire and label.
288
+ * @param {number} [cfg.zIndex] If set, the wires, dots and labels will have this zIndex (+1 for dots and +2 for labels).
289
+ * @param {boolean} [cfg.defaultLabelsOnWires=true] The default value of the DistanceMeasurements `labelsOnWires` property.
290
+ * @param {PointerCircle} [cfg.pointerLens] A PointerLens to help the user position the pointer. This can be shared with other plugins.
291
+ */
292
+ constructor(viewer, cfg = {}) {
293
+ super("DistanceMeasurements", viewer);
266
294
 
267
- /**
268
- * @constructor
269
- * @param {Viewer} viewer The Viewer.
270
- * @param {Object} [cfg] Plugin configuration.
271
- * @param {String} [cfg.id="DistanceMeasurements"] Optional ID for this plugin, so that we can find it within {@link Viewer#plugins}.
272
- * @param {Number} [cfg.labelMinAxisLength=25] The minimum length, in pixels, of an axis wire beyond which its label is shown.
273
- * @param {HTMLElement} [cfg.container] Container DOM element for markers and labels. Defaults to ````document.body````.
274
- * @param {boolean} [cfg.defaultVisible=true] The default value of the DistanceMeasurements `visible` property.
275
- * @param {boolean} [cfg.defaultOriginVisible=true] The default value of the DistanceMeasurements `originVisible` property.
276
- * @param {boolean} [cfg.defaultTargetVisible=true] The default value of the DistanceMeasurements `targetVisible` property.
277
- * @param {boolean} [cfg.defaultWireVisible=true] The default value of the DistanceMeasurements `wireVisible` property.
278
- * @param {boolean} [cfg.defaultLabelsVisible=true] The default value of the DistanceMeasurements `labelsVisible` property.
279
- * @param {boolean} [cfg.defaultXLabelEnabled=true] The default value of the DistanceMeasurements `xLabelEnabled` property.
280
- * @param {boolean} [cfg.defaultYLabelEnabled=true] The default value of the DistanceMeasurements `yLabelEnabled` property.
281
- * @param {boolean} [cfg.defaultZLabelEnabled=true] The default value of the DistanceMeasurements `zLabelEnabled` property.
282
- * @param {boolean} [cfg.defaultLengthLabelEnabled=true] The default value of the DistanceMeasurements `lengthLabelEnabled` property.
283
- * @param {boolean} [cfg.defaultAxisVisible=true] The default value of the DistanceMeasurements `axisVisible` property.
284
- * @param {boolean} [cfg.defaultXAxisVisible=true] The default value of the DistanceMeasurements `xAxisVisible` property.
285
- * @param {boolean} [cfg.defaultYAxisVisible=true] The default value of the DistanceMeasurements `yAxisVisible` property.
286
- * @param {boolean} [cfg.defaultZAxisVisible=true] The default value of the DistanceMeasurements `zAxisVisible` property.
287
- * @param {string} [cfg.defaultColor=#00BBFF] The default color of the length dots, wire and label.
288
- * @param {number} [cfg.zIndex] If set, the wires, dots and labels will have this zIndex (+1 for dots and +2 for labels).
289
- * @param {boolean} [cfg.defaultLabelsOnWires=true] The default value of the DistanceMeasurements `labelsOnWires` property.
290
- * @param {PointerCircle} [cfg.pointerLens] A PointerLens to help the user position the pointer. This can be shared with other plugins.
291
- */
292
- constructor(viewer, cfg = {}) {
295
+ this._pointerLens = cfg.pointerLens;
293
296
 
294
- super("DistanceMeasurements", viewer);
297
+ this._container = cfg.container || document.body;
295
298
 
296
- this._pointerLens = cfg.pointerLens;
299
+ this._defaultControl = null;
297
300
 
298
- this._container = cfg.container || document.body;
301
+ this._measurements = {};
299
302
 
300
- this._defaultControl = null;
303
+ this.labelMinAxisLength = cfg.labelMinAxisLength;
304
+ this.defaultVisible = cfg.defaultVisible !== false;
305
+ this.defaultOriginVisible = cfg.defaultOriginVisible !== false;
306
+ this.defaultTargetVisible = cfg.defaultTargetVisible !== false;
307
+ this.defaultWireVisible = cfg.defaultWireVisible !== false;
308
+ this.defaultXLabelEnabled = cfg.defaultXLabelEnabled !== false;
309
+ this.defaultYLabelEnabled = cfg.defaultYLabelEnabled !== false;
310
+ this.defaultZLabelEnabled = cfg.defaultZLabelEnabled !== false;
311
+ this.defaultLengthLabelEnabled = cfg.defaultLengthLabelEnabled !== false;
312
+ this.defaultLabelsVisible = cfg.defaultLabelsVisible !== false;
313
+ this.defaultAxisVisible = cfg.defaultAxisVisible !== false;
314
+ this.defaultXAxisVisible = cfg.defaultXAxisVisible !== false;
315
+ this.defaultYAxisVisible = cfg.defaultYAxisVisible !== false;
316
+ this.defaultZAxisVisible = cfg.defaultZAxisVisible !== false;
317
+ this.defaultColor =cfg.defaultColor !== undefined ? cfg.defaultColor : "#00BBFF";
318
+ this.zIndex = cfg.zIndex || 10000;
319
+ this.defaultLabelsOnWires = cfg.defaultLabelsOnWires !== false;
320
+ this.useRotationAdjustment = cfg.useRotationAdjustment !== undefined ? cfg.useRotationAdjustment !== false : false;
301
321
 
302
- this._measurements = {};
322
+ this._onMouseOver = (event, measurement) => {
323
+ this.fire("mouseOver", {
324
+ plugin: this,
325
+ distanceMeasurement: measurement,
326
+ measurement,
327
+ event,
328
+ });
329
+ };
303
330
 
304
- this.labelMinAxisLength = cfg.labelMinAxisLength;
305
- this.defaultVisible = cfg.defaultVisible !== false;
306
- this.defaultOriginVisible = cfg.defaultOriginVisible !== false;
307
- this.defaultTargetVisible = cfg.defaultTargetVisible !== false;
308
- this.defaultWireVisible = cfg.defaultWireVisible !== false;
309
- this.defaultXLabelEnabled = cfg.defaultXLabelEnabled !== false;
310
- this.defaultYLabelEnabled = cfg.defaultYLabelEnabled !== false;
311
- this.defaultZLabelEnabled = cfg.defaultZLabelEnabled !== false;
312
- this.defaultLengthLabelEnabled = cfg.defaultLengthLabelEnabled !== false;
313
- this.defaultLabelsVisible = cfg.defaultLabelsVisible !== false;
314
- this.defaultAxisVisible = cfg.defaultAxisVisible !== false;
315
- this.defaultXAxisVisible = cfg.defaultXAxisVisible !== false;
316
- this.defaultYAxisVisible = cfg.defaultYAxisVisible !== false;
317
- this.defaultZAxisVisible = cfg.defaultZAxisVisible !== false;
318
- this.defaultColor = cfg.defaultColor !== undefined ? cfg.defaultColor : "#00BBFF";
319
- this.zIndex = cfg.zIndex || 10000;
320
- this.defaultLabelsOnWires = cfg.defaultLabelsOnWires !== false;
331
+ this._onMouseLeave = (event, measurement) => {
332
+ this.fire("mouseLeave", {
333
+ plugin: this,
334
+ distanceMeasurement: measurement,
335
+ measurement,
336
+ event,
337
+ });
338
+ };
321
339
 
322
- this._onMouseOver = (event, measurement) => {
323
- this.fire("mouseOver", {
324
- plugin: this,
325
- distanceMeasurement: measurement,
326
- measurement,
327
- event
328
- });
329
- }
340
+ this._onContextMenu = (event, measurement) => {
341
+ this.fire("contextMenu", {
342
+ plugin: this,
343
+ distanceMeasurement: measurement,
344
+ measurement,
345
+ event,
346
+ });
347
+ };
348
+ }
330
349
 
331
- this._onMouseLeave = (event, measurement) => {
332
- this.fire("mouseLeave", {
333
- plugin: this,
334
- distanceMeasurement: measurement,
335
- measurement,
336
- event
337
- });
338
- };
350
+ /**
351
+ * Gets the plugin's HTML container element, if any.
352
+ * @returns {*|HTMLElement|HTMLElement}
353
+ */
354
+ getContainerElement() {
355
+ return this._container;
356
+ }
339
357
 
340
- this._onContextMenu = (event, measurement) => {
341
- this.fire("contextMenu", {
342
- plugin: this,
343
- distanceMeasurement: measurement,
344
- measurement,
345
- event
346
- });
347
- };
348
- }
349
-
350
- /**
351
- * Gets the plugin's HTML container element, if any.
352
- * @returns {*|HTMLElement|HTMLElement}
353
- */
354
- getContainerElement() {
355
- return this._container;
356
- }
358
+ /**
359
+ * @private
360
+ */
361
+ send(name, value) {}
357
362
 
358
- /**
359
- * @private
360
- */
361
- send(name, value) {
362
-
363
- }
363
+ /**
364
+ * Gets the PointerLens attached to this DistanceMeasurementsPlugin.
365
+ * @returns {PointerCircle}
366
+ */
367
+ get pointerLens() {
368
+ return this._pointerLens;
369
+ }
364
370
 
365
- /**
366
- * Gets the PointerLens attached to this DistanceMeasurementsPlugin.
367
- * @returns {PointerCircle}
368
- */
369
- get pointerLens() {
370
- return this._pointerLens;
371
+ /**
372
+ * Gets the default {@link DistanceMeasurementsControl}.
373
+ *
374
+ * @type {DistanceMeasurementsControl}
375
+ * @deprecated
376
+ */
377
+ get control() {
378
+ if (!this._defaultControl) {
379
+ this._defaultControl = new DistanceMeasurementsMouseControl(this, {});
371
380
  }
381
+ return this._defaultControl;
382
+ }
372
383
 
373
- /**
374
- * Gets the default {@link DistanceMeasurementsControl}.
375
- *
376
- * @type {DistanceMeasurementsControl}
377
- * @deprecated
378
- */
379
- get control() {
380
- if (!this._defaultControl) {
381
- this._defaultControl = new DistanceMeasurementsMouseControl(this, {});
382
- }
383
- return this._defaultControl;
384
- }
384
+ /**
385
+ * Gets the existing {@link DistanceMeasurement}s, each mapped to its {@link DistanceMeasurement#id}.
386
+ *
387
+ * @type {{String:DistanceMeasurement}}
388
+ */
389
+ get measurements() {
390
+ return this._measurements;
391
+ }
385
392
 
386
- /**
387
- * Gets the existing {@link DistanceMeasurement}s, each mapped to its {@link DistanceMeasurement#id}.
388
- *
389
- * @type {{String:DistanceMeasurement}}
390
- */
391
- get measurements() {
392
- return this._measurements;
393
+ /**
394
+ * Sets the minimum length, in pixels, of an axis wire beyond which its label is shown.
395
+ *
396
+ * The axis wire's label is not shown when its length is less than this value.
397
+ *
398
+ * This is ````25```` pixels by default.
399
+ *
400
+ * Must not be less than ````1````.
401
+ *
402
+ * @type {number}
403
+ */
404
+ set labelMinAxisLength(labelMinAxisLength) {
405
+ if (labelMinAxisLength < 1) {
406
+ this.error("labelMinAxisLength must be >= 1; defaulting to 25");
407
+ labelMinAxisLength = 25;
393
408
  }
409
+ this._labelMinAxisLength = labelMinAxisLength || 25;
410
+ }
394
411
 
395
- /**
396
- * Sets the minimum length, in pixels, of an axis wire beyond which its label is shown.
397
- *
398
- * The axis wire's label is not shown when its length is less than this value.
399
- *
400
- * This is ````25```` pixels by default.
401
- *
402
- * Must not be less than ````1````.
403
- *
404
- * @type {number}
405
- */
406
- set labelMinAxisLength(labelMinAxisLength) {
407
- if (labelMinAxisLength < 1) {
408
- this.error("labelMinAxisLength must be >= 1; defaulting to 25");
409
- labelMinAxisLength = 25;
410
- }
411
- this._labelMinAxisLength = labelMinAxisLength || 25;
412
- }
412
+ /**
413
+ * Gets the minimum length, in pixels, of an axis wire beyond which its label is shown.
414
+ * @returns {number}
415
+ */
416
+ get labelMinAxisLength() {
417
+ return this._labelMinAxisLength;
418
+ }
413
419
 
414
- /**
415
- * Gets the minimum length, in pixels, of an axis wire beyond which its label is shown.
416
- * @returns {number}
417
- */
418
- get labelMinAxisLength() {
419
- return this._labelMinAxisLength;
420
- }
420
+ /**
421
+ * Sets whether the measurement added is rotation adjusted or not.
422
+ *
423
+ * @type {boolean}
424
+ */
425
+ set useRotationAdjustment(_useRotationAdjustment) {
426
+ _useRotationAdjustment = _useRotationAdjustment !== undefined ? Boolean(_useRotationAdjustment) : false;
427
+ this._useRotationAdjustment = _useRotationAdjustment;
428
+ }
421
429
 
422
- /**
423
- * Creates a {@link DistanceMeasurement}.
424
- *
425
- * The DistanceMeasurement is then registered by {@link DistanceMeasurement#id} in {@link DistanceMeasurementsPlugin#measurements}.
426
- *
427
- * @param {Object} params {@link DistanceMeasurement} configuration.
428
- * @param {String} params.id Unique ID to assign to {@link DistanceMeasurement#id}. The DistanceMeasurement will be registered by this in {@link DistanceMeasurementsPlugin#measurements} and {@link Scene.components}. Must be unique among all components in the {@link Viewer}.
429
- * @param {Number[]} params.origin.worldPos Origin World-space 3D position.
430
- * @param {Entity} params.origin.entity Origin Entity.
431
- * @param {Number[]} params.target.worldPos Target World-space 3D position.
432
- * @param {Entity} params.target.entity Target Entity.
433
- * @param {Boolean} [params.visible=true] Whether to initially show the {@link DistanceMeasurement}.
434
- * @param {Boolean} [params.originVisible=true] Whether to initially show the {@link DistanceMeasurement} origin.
435
- * @param {Boolean} [params.targetVisible=true] Whether to initially show the {@link DistanceMeasurement} target.
436
- * @param {Boolean} [params.wireVisible=true] Whether to initially show the direct point-to-point wire between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
437
- * @param {Boolean} [params.axisVisible=true] Whether to initially show the axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
438
- * @param {Boolean} [params.xAxisVisible=true] Whether to initially show the X-axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
439
- * @param {Boolean} [params.yAxisVisible=true] Whether to initially show the Y-axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
440
- * @param {Boolean} [params.zAxisVisible=true] Whether to initially show the Z-axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
441
- * @param {Boolean} [params.xLabelEnabled=true] Whether to initially show the x label.
442
- * @param {Boolean} [params.yLabelEnabled=true] Whether to initially show the y label.
443
- * @param {Boolean} [params.zLabelEnabled=true] Whether to initially show the z label.
444
- * @param {Boolean} [params.lengthLabelEnabled=true] Whether to initially show the length label.
445
- * @param {Boolean} [params.labelsVisible=true] Whether to initially show the labels.
446
- * @param {Boolean} [params.lengthLabelVisible=true] Whether to initially show the labels.
447
- * @param {string} [params.color] The color of the length dot, wire and label.
448
- * @param {Boolean} [params.labelsOnWires=true] Determines if labels will be set on wires or one below the other.
449
- * @returns {DistanceMeasurement} The new {@link DistanceMeasurement}.
450
- */
451
- createMeasurement(params = {}) {
452
- if (this.viewer.scene.components[params.id]) {
453
- this.error("Viewer scene component with this ID already exists: " + params.id);
454
- delete params.id;
455
- }
456
- const origin = params.origin;
457
- const target = params.target;
458
- const measurement = new DistanceMeasurement(this, {
459
- id: params.id,
460
- plugin: this,
461
- container: this._container,
462
- origin: {
463
- entity: origin.entity,
464
- worldPos: origin.worldPos
465
- },
466
- target: {
467
- entity: target.entity,
468
- worldPos: target.worldPos
469
- },
470
- visible: params.visible,
471
- wireVisible: params.wireVisible,
472
- axisVisible: params.axisVisible !== false && this.defaultAxisVisible !== false,
473
- xAxisVisible: params.xAxisVisible !== false && this.defaultXAxisVisible !== false,
474
- yAxisVisible: params.yAxisVisible !== false && this.defaultYAxisVisible !== false,
475
- zAxisVisible: params.zAxisVisible !== false && this.defaultZAxisVisible !== false,
476
- xLabelEnabled: params.xLabelEnabled !== false && this.defaultXLabelEnabled !== false,
477
- yLabelEnabled: params.yLabelEnabled !== false && this.defaultYLabelEnabled !== false,
478
- zLabelEnabled: params.zLabelEnabled !== false && this.defaultZLabelEnabled !== false,
479
- lengthLabelEnabled: params.lengthLabelEnabled !== false && this.defaultLengthLabelEnabled !== false,
480
- labelsVisible: params.labelsVisible !== false && this.defaultLabelsVisible !== false,
481
- originVisible: params.originVisible,
482
- targetVisible: params.targetVisible,
483
- color: params.color,
484
- labelsOnWires: params.labelsOnWires !== false && this.defaultLabelsOnWires !== false,
485
- onMouseOver: this._onMouseOver,
486
- onMouseLeave: this._onMouseLeave,
487
- onContextMenu: this._onContextMenu
488
- });
489
- this._measurements[measurement.id] = measurement;
490
- measurement.clickable = true;
491
- measurement.on("destroyed", () => {
492
- delete this._measurements[measurement.id];
493
- });
494
- this.fire("measurementCreated", measurement);
495
- return measurement;
430
+ /**
431
+ * Gets whether the measurement added is rotation adjusted or not.
432
+ * @returns {number}
433
+ */
434
+ get useRotationAdjustment(){
435
+ return this._useRotationAdjustment;
436
+ }
437
+ /**
438
+ * Creates a {@link DistanceMeasurement}.
439
+ *
440
+ * The DistanceMeasurement is then registered by {@link DistanceMeasurement#id} in {@link DistanceMeasurementsPlugin#measurements}.
441
+ *
442
+ * @param {Object} params {@link DistanceMeasurement} configuration.
443
+ * @param {String} params.id Unique ID to assign to {@link DistanceMeasurement#id}. The DistanceMeasurement will be registered by this in {@link DistanceMeasurementsPlugin#measurements} and {@link Scene.components}. Must be unique among all components in the {@link Viewer}.
444
+ * @param {Number[]} params.origin.worldPos Origin World-space 3D position.
445
+ * @param {Entity} params.origin.entity Origin Entity.
446
+ * @param {Number[]} params.target.worldPos Target World-space 3D position.
447
+ * @param {Entity} params.target.entity Target Entity.
448
+ * @param {Boolean} [params.visible=true] Whether to initially show the {@link DistanceMeasurement}.
449
+ * @param {Boolean} [params.originVisible=true] Whether to initially show the {@link DistanceMeasurement} origin.
450
+ * @param {Boolean} [params.targetVisible=true] Whether to initially show the {@link DistanceMeasurement} target.
451
+ * @param {Boolean} [params.wireVisible=true] Whether to initially show the direct point-to-point wire between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
452
+ * @param {Boolean} [params.axisVisible=true] Whether to initially show the axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
453
+ * @param {Boolean} [params.xAxisVisible=true] Whether to initially show the X-axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
454
+ * @param {Boolean} [params.yAxisVisible=true] Whether to initially show the Y-axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
455
+ * @param {Boolean} [params.zAxisVisible=true] Whether to initially show the Z-axis-aligned wires between {@link DistanceMeasurement#origin} and {@link DistanceMeasurement#target}.
456
+ * @param {Boolean} [params.xLabelEnabled=true] Whether to initially show the x label.
457
+ * @param {Boolean} [params.yLabelEnabled=true] Whether to initially show the y label.
458
+ * @param {Boolean} [params.zLabelEnabled=true] Whether to initially show the z label.
459
+ * @param {Boolean} [params.lengthLabelEnabled=true] Whether to initially show the length label.
460
+ * @param {Boolean} [params.labelsVisible=true] Whether to initially show the labels.
461
+ * @param {Boolean} [params.lengthLabelVisible=true] Whether to initially show the labels.
462
+ * @param {string} [params.color] The color of the length dot, wire and label.
463
+ * @param {Boolean} [params.labelsOnWires=true] Determines if labels will be set on wires or one below the other.
464
+ * @returns {DistanceMeasurement} The new {@link DistanceMeasurement}.
465
+ */
466
+ createMeasurement(params = {}) {
467
+ if (this.viewer.scene.components[params.id]) {
468
+ this.error(
469
+ "Viewer scene component with this ID already exists: " + params.id
470
+ );
471
+ delete params.id;
496
472
  }
473
+ const origin = params.origin;
474
+ const target = params.target;
475
+ const measurement = new DistanceMeasurement(this, {
476
+ id: params.id,
477
+ plugin: this,
478
+ container: this._container,
479
+ origin: {
480
+ entity: origin.entity,
481
+ worldPos: origin.worldPos,
482
+ },
483
+ target: {
484
+ entity: target.entity,
485
+ worldPos: target.worldPos,
486
+ },
487
+ visible: params.visible,
488
+ wireVisible: params.wireVisible,
489
+ axisVisible: params.axisVisible !== false && this.defaultAxisVisible !== false,
490
+ xAxisVisible: params.xAxisVisible !== false && this.defaultXAxisVisible !== false,
491
+ yAxisVisible: params.yAxisVisible !== false && this.defaultYAxisVisible !== false,
492
+ zAxisVisibld: params.zAxisVisible !== false && this.defaultZAxisVisible !== false,
493
+ xLabelEnabled: params.xLabelEnabled !== false && this.defaultXLabelEnabled !== false,
494
+ yLabelEnabled: params.yLabelEnabled !== false && this.defaultYLabelEnabled !== false,
495
+ zLabelEnabled: params.zLabelEnabled !== false && this.defaultZLabelEnabled !== false,
496
+ lengthLabelEnabled: params.lengthLabelEnabled !== false && this.defaultLengthLabelEnabled !== false,
497
+ labelsVisible: params.labelsVisible !== false && this.defaultLabelsVisible !== false,
498
+ useRotationAdjustment: this.useRotationAdjustment,
499
+ originVisible: params.originVisible,
500
+ targetVisible: params.targetVisible,
501
+ color: params.color,
502
+ labelsOnWires:params.labelsOnWires !== false && this.defaultLabelsOnWires !== false,
503
+ onMouseOver: this._onMouseOver,
504
+ onMouseLeave: this._onMouseLeave,
505
+ onContextMenu: this._onContextMenu,
506
+ });
507
+ this._measurements[measurement.id] = measurement;
508
+ measurement.clickable = true;
509
+ measurement.on("destroyed", () => {
510
+ delete this._measurements[measurement.id];
511
+ });
512
+ this.fire("measurementCreated", measurement);
513
+ return measurement;
514
+ }
497
515
 
498
- /**
499
- * Destroys a {@link DistanceMeasurement}.
500
- *
501
- * @param {String} id ID of DistanceMeasurement to destroy.
502
- */
503
- destroyMeasurement(id) {
504
- const measurement = this._measurements[id];
505
- if (!measurement) {
506
- this.log("DistanceMeasurement not found: " + id);
507
- return;
508
- }
509
- measurement.destroy();
510
- this.fire("measurementDestroyed", measurement);
516
+ /**
517
+ * Destroys a {@link DistanceMeasurement}.
518
+ *
519
+ * @param {String} id ID of DistanceMeasurement to destroy.
520
+ */
521
+ destroyMeasurement(id) {
522
+ const measurement = this._measurements[id];
523
+ if (!measurement) {
524
+ this.log("DistanceMeasurement not found: " + id);
525
+ return;
511
526
  }
527
+ measurement.destroy();
528
+ this.fire("measurementDestroyed", measurement);
529
+ }
512
530
 
513
- /**
514
- * Shows all or hides the distance label of each {@link DistanceMeasurement}.
515
- *
516
- * @param {Boolean} labelsShown Whether or not to show the labels.
517
- */
518
- setLabelsShown(labelsShown) {
519
- for (const [key, measurement] of Object.entries(this.measurements)) {
520
- measurement.labelShown = labelsShown;
521
- }
531
+ /**
532
+ * Shows all or hides the distance label of each {@link DistanceMeasurement}.
533
+ *
534
+ * @param {Boolean} labelsShown Whether or not to show the labels.
535
+ */
536
+ setLabelsShown(labelsShown) {
537
+ for (const [key, measurement] of Object.entries(this.measurements)) {
538
+ measurement.labelShown = labelsShown;
522
539
  }
540
+ }
523
541
 
524
- /**
525
- * Shows all or hides the axis wires of each {@link DistanceMeasurement}.
526
- *
527
- * @param {Boolean} labelsShown Whether or not to show the axis wires.
528
- */
529
- setAxisVisible(axisVisible) {
530
- for (const [key, measurement] of Object.entries(this.measurements)) {
531
- measurement.axisVisible = axisVisible;
532
- }
533
- this.defaultAxisVisible = axisVisible;
542
+ /**
543
+ * Shows all or hides the axis wires of each {@link DistanceMeasurement}.
544
+ *
545
+ * @param {Boolean} labelsShown Whether or not to show the axis wires.
546
+ */
547
+ setAxisVisible(axisVisible) {
548
+ for (const [key, measurement] of Object.entries(this.measurements)) {
549
+ measurement.axisVisible = axisVisible;
534
550
  }
551
+ this.defaultAxisVisible = axisVisible;
552
+ }
535
553
 
536
- /**
537
- * Gets if the axis wires of each {@link DistanceMeasurement} are visible.
538
- *
539
- * @returns {Boolean} Whether or not the axis wires are visible.
540
- */
541
- getAxisVisible() {
542
- return this.defaultAxisVisible;
543
- }
554
+ /**
555
+ * Gets if the axis wires of each {@link DistanceMeasurement} are visible.
556
+ *
557
+ * @returns {Boolean} Whether or not the axis wires are visible.
558
+ */
559
+ getAxisVisible() {
560
+ return this.defaultAxisVisible;
561
+ }
544
562
 
545
- /**
546
- * Destroys all {@link DistanceMeasurement}s.
547
- */
548
- clear() {
549
- const ids = Object.keys(this._measurements);
550
- for (var i = 0, len = ids.length; i < len; i++) {
551
- this.destroyMeasurement(ids[i]);
552
- }
563
+ /**
564
+ * Destroys all {@link DistanceMeasurement}s.
565
+ */
566
+ clear() {
567
+ const ids = Object.keys(this._measurements);
568
+ for (var i = 0, len = ids.length; i < len; i++) {
569
+ this.destroyMeasurement(ids[i]);
553
570
  }
571
+ }
554
572
 
555
- /**
556
- * Destroys this DistanceMeasurementsPlugin.
557
- *
558
- * Destroys all {@link DistanceMeasurement}s first.
559
- */
560
- destroy() {
561
- this.clear();
562
- super.destroy();
563
- }
573
+ /**
574
+ * Destroys this DistanceMeasurementsPlugin.
575
+ *
576
+ * Destroys all {@link DistanceMeasurement}s first.
577
+ */
578
+ destroy() {
579
+ this.clear();
580
+ super.destroy();
581
+ }
564
582
  }
565
583
 
566
- export {DistanceMeasurementsPlugin}
584
+ export { DistanceMeasurementsPlugin };