three-cad-viewer 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57634,6 +57634,7 @@ class Measurement {
57634
57634
  this.selectedShapes = []; // array of dict ObjectGroup, bool
57635
57635
  this.point1 = null;
57636
57636
  this.point2 = null;
57637
+ this.middlePoint = null;
57637
57638
  this.contextEnabled = false; // Tells if the measure context is active
57638
57639
  this.viewer = viewer;
57639
57640
  this.scene = new Scene();
@@ -57782,9 +57783,29 @@ class Measurement {
57782
57783
 
57783
57784
  const canvasRect = this.viewer.renderer.domElement.getBoundingClientRect();
57784
57785
  const panelRect = this.panel.html.getBoundingClientRect();
57785
- if (this.panelX == null) {
57786
- this.panelX = canvasRect.width - panelRect.width - 2;
57787
- this.panelY = canvasRect.height - panelRect.height - 2;
57786
+
57787
+ if (this.panelX == null && this.middlePoint != null) {
57788
+ let center = this.middlePoint
57789
+ .clone()
57790
+ .project(this.viewer.camera.getCamera());
57791
+ let panelX = (center.x + 1) * (canvasRect.width / 2);
57792
+ let panelY = (1 - center.y) * (canvasRect.height / 2);
57793
+
57794
+ if (panelX < canvasRect.width / 2) {
57795
+ this.panelX = panelX + panelRect.width / 2;
57796
+ } else {
57797
+ this.panelX = panelX - panelRect.width - panelRect.width / 2;
57798
+ }
57799
+ this.panelX = Math.max(
57800
+ 0,
57801
+ Math.min(canvasRect.width - panelRect.width, this.panelX),
57802
+ );
57803
+
57804
+ this.panelY = panelY;
57805
+ this.panelY = Math.max(
57806
+ 0,
57807
+ Math.min(canvasRect.height - panelRect.height, this.panelY),
57808
+ );
57788
57809
  }
57789
57810
 
57790
57811
  this.panel.relocate(this.panelX, this.panelY);
@@ -57901,6 +57922,7 @@ class DistanceMeasurement extends Measurement {
57901
57922
  super(viewer, new DistancePanel(viewer.display));
57902
57923
  this.point1 = null;
57903
57924
  this.point2 = null;
57925
+ this.middlePoint = null;
57904
57926
  }
57905
57927
 
57906
57928
  _setMeasurementVals() {
@@ -57938,13 +57960,13 @@ class DistanceMeasurement extends Measurement {
57938
57960
  );
57939
57961
  this.scene.add(distanceLine);
57940
57962
 
57941
- const middlePoint = new Vector3()
57963
+ this.middlePoint = new Vector3()
57942
57964
  .addVectors(this.point1, this.point2)
57943
57965
  .multiplyScalar(0.5);
57944
57966
  const connectingLine = new DistanceLineArrow(
57945
57967
  this.coneLength,
57946
57968
  this.panelCenter,
57947
- middlePoint,
57969
+ this.middlePoint,
57948
57970
  lineWidth,
57949
57971
  this.connectingLineColor,
57950
57972
  false,
@@ -57971,6 +57993,7 @@ class DistanceMeasurement extends Measurement {
57971
57993
  class PropertiesMeasurement extends Measurement {
57972
57994
  constructor(viewer) {
57973
57995
  super(viewer, new PropertiesPanel(viewer.display));
57996
+ this.middlePoint = null;
57974
57997
  }
57975
57998
 
57976
57999
  _setMeasurementVals() {
@@ -58000,11 +58023,11 @@ class PropertiesMeasurement extends Measurement {
58000
58023
 
58001
58024
  _makeLines() {
58002
58025
  const lineWidth = 1.5;
58003
- const middlePoint = this.responseData.center;
58026
+ this.middlePoint = this.responseData.center;
58004
58027
  const connectingLine = new DistanceLineArrow(
58005
58028
  this.coneLength,
58006
58029
  this.panelCenter,
58007
- middlePoint,
58030
+ this.middlePoint,
58008
58031
  lineWidth,
58009
58032
  this.connectingLineColor,
58010
58033
  false,
@@ -58028,6 +58051,7 @@ class PropertiesMeasurement extends Measurement {
58028
58051
  class AngleMeasurement extends Measurement {
58029
58052
  constructor(viewer) {
58030
58053
  super(viewer, new AnglePanel(viewer.display));
58054
+ this.middlePoint = null;
58031
58055
  }
58032
58056
 
58033
58057
  _setMeasurementVals() {
@@ -58087,6 +58111,9 @@ class AngleMeasurement extends Measurement {
58087
58111
  );
58088
58112
  this.scene.add(item1Line);
58089
58113
  this.scene.add(item2Line);
58114
+ this.middlePoint = new Vector3()
58115
+ .addVectors(this.point1, this.point2)
58116
+ .multiplyScalar(0.5);
58090
58117
  }
58091
58118
 
58092
58119
  handleResponse(response) {
@@ -58369,10 +58396,10 @@ class Display {
58369
58396
  (options.theme == "browser" &&
58370
58397
  window.matchMedia("(prefers-color-scheme: dark)").matches)
58371
58398
  ) {
58372
- document.documentElement.setAttribute("data-theme", "dark");
58399
+ this.container.setAttribute("data-theme", "dark");
58373
58400
  theme = "dark";
58374
58401
  } else {
58375
- document.documentElement.setAttribute("data-theme", "light");
58402
+ this.container.setAttribute("data-theme", "light");
58376
58403
  theme = "light";
58377
58404
  }
58378
58405
 
@@ -59766,7 +59793,16 @@ class BoundingBox extends Box3 {
59766
59793
  const children = object.children;
59767
59794
 
59768
59795
  for (let i = 0, l = children.length; i < l; i++) {
59769
- this.expandByObject(children[i], precise);
59796
+ if (
59797
+ !(
59798
+ children[i].name == "PlaneMeshes" &&
59799
+ children[i].children &&
59800
+ children[i].children.length > 0 &&
59801
+ children[i].children[0].type.startsWith("StencilPlane")
59802
+ )
59803
+ ) {
59804
+ this.expandByObject(children[i], precise);
59805
+ }
59770
59806
  }
59771
59807
 
59772
59808
  return this;
@@ -62281,6 +62317,33 @@ class TreeView {
62281
62317
  * Tree handling high level API
62282
62318
  ************************************************************************************/
62283
62319
 
62320
+ /**
62321
+ * Scrolls the parent container to center the specified element within the visible area.
62322
+ * Ensures the scrolling does not exceed the scrollable bounds of the parent container.
62323
+ *
62324
+ * @param {HTMLElement} element - The DOM element to center within the scroll container.
62325
+ */
62326
+ scrollCentered(element) {
62327
+ if (element != null) {
62328
+ let parent = this.scrollContainer;
62329
+
62330
+ // Calculate the center position of the element relative to the parent
62331
+ const elementHeight = element.offsetHeight;
62332
+ const parentHeight = parent.clientHeight;
62333
+
62334
+ // Calculate scroll position that would center the element
62335
+ const elementOffset = element.offsetTop - parent.offsetTop;
62336
+ const scrollTop = elementOffset - parentHeight / 2 + elementHeight / 2;
62337
+
62338
+ // Ensure we don't scroll beyond the parent's scrollable area
62339
+ const maxScroll = parent.scrollHeight - parentHeight;
62340
+ const clampedScrollTop = Math.max(0, Math.min(scrollTop, maxScroll));
62341
+
62342
+ // Perform the scroll
62343
+ parent.scrollTo({ top: clampedScrollTop, behavior: "smooth" });
62344
+ }
62345
+ }
62346
+
62284
62347
  /**
62285
62348
  * Opens the specified path in the tree view.
62286
62349
  *
@@ -62290,13 +62353,11 @@ class TreeView {
62290
62353
  const parts = path.split("/").filter(Boolean);
62291
62354
  var current = "";
62292
62355
  var node;
62356
+ let el;
62293
62357
  for (var part of parts) {
62294
62358
  current += "/" + part;
62295
62359
  node = this.findNodeByPath(current);
62296
- const el = this.getDomNode(current);
62297
- if (el != null) {
62298
- el.children[0].scrollIntoView({ behaviour: "smooth", block: "center" });
62299
- }
62360
+ el = this.getDomNode(current);
62300
62361
  if (node) {
62301
62362
  node.expanded = true;
62302
62363
  this.showChildContainer(node);
@@ -62309,6 +62370,7 @@ class TreeView {
62309
62370
  break;
62310
62371
  }
62311
62372
  }
62373
+ this.scrollCentered(el);
62312
62374
  this.toggleLabelColor(node);
62313
62375
  }
62314
62376
 
@@ -62324,7 +62386,8 @@ class TreeView {
62324
62386
  this.showChildContainer(node);
62325
62387
  const el = this.getDomNode(path);
62326
62388
  if (el != null) {
62327
- el.scrollIntoView({ behaviour: "smooth", block: "start" });
62389
+ const parent = this.scrollContainer;
62390
+ parent.scrollTop = el.offsetTop - parent.offsetTop;
62328
62391
  }
62329
62392
  if (this.debug) {
62330
62393
  console.log("update => collapsePath");
@@ -62356,7 +62419,10 @@ class TreeView {
62356
62419
  };
62357
62420
  this.traverse(this.root, setLevel);
62358
62421
  const el = this.getDomNode(this.getNodePath(this.root));
62359
- el.scrollIntoView({ behaviour: "smooth", block: "start" });
62422
+ if (el != null) {
62423
+ const parent = this.scrollContainer;
62424
+ parent.scrollTop = el.offsetTop - parent.offsetTop;
62425
+ }
62360
62426
  for (var i = 0; i <= (level == -1 ? this.maxLevel : level); i++) {
62361
62427
  if (this.debug) {
62362
62428
  console.log("update => openLevel");
@@ -64985,7 +65051,7 @@ class Camera {
64985
65051
  }
64986
65052
  }
64987
65053
 
64988
- const version = "3.3.0";
65054
+ const version = "3.3.2";
64989
65055
 
64990
65056
  Mesh.prototype.dispose = function () {
64991
65057
  if (this.geometry) {
@@ -66312,9 +66378,9 @@ class Viewer {
66312
66378
 
66313
66379
  this.display.setSliderLimits(this.gridSize / 2, this.bbox.center());
66314
66380
 
66315
- this.setClipNormal(0, viewerOptions.clipNormal0, true);
66316
- this.setClipNormal(1, viewerOptions.clipNormal1, true);
66317
- this.setClipNormal(2, viewerOptions.clipNormal2, true);
66381
+ this.setClipNormal(0, viewerOptions.clipNormal0, null, true);
66382
+ this.setClipNormal(1, viewerOptions.clipNormal1, null, true);
66383
+ this.setClipNormal(2, viewerOptions.clipNormal2, null, true);
66318
66384
 
66319
66385
  this.clipSlider0 =
66320
66386
  viewerOptions.clipSlider0 != null
@@ -67047,39 +67113,120 @@ class Viewer {
67047
67113
  this.update(this.updateMarker);
67048
67114
  };
67049
67115
 
67116
+ /**
67117
+ * Get intensity of ambient light.
67118
+ * @returns {number} ambientLight value.
67119
+ **/
67120
+ getAmbientLight() {
67121
+ return this.ambientIntensity;
67122
+ }
67123
+
67124
+ /**
67125
+ * Set the intensity of ambient light
67126
+ * @function
67127
+ * @param {number} val - the new ambient light intensity
67128
+ * @param {boolean} [ui=false] - if true, set the UI slider value
67129
+ * @param {boolean} [notify=true] - whether to send notification or not.
67130
+ */
67131
+ setAmbientLight = (val, ui = false, notify = true) => {
67132
+ this.ambientIntensity = val;
67133
+ this.ambientLight.intensity = scaleLight(val);
67134
+ this.checkChanges({ ambient_intensity: val }, notify);
67135
+ this.update(this.updateMarker, notify);
67136
+ if (ui) {
67137
+ this.display.setAmbientLight(val);
67138
+ }
67139
+ };
67140
+
67141
+ /**
67142
+ * Get intensity of direct light.
67143
+ * @returns {number} directLight value.
67144
+ **/
67145
+ getDirectLight() {
67146
+ return this.directIntensity;
67147
+ }
67148
+ /**
67149
+ * Set the intensity of directional light
67150
+ * @function
67151
+ * @param {number} val - the new direct light intensity
67152
+ * @param {boolean} [ui=false] - if true, set the UI slider value
67153
+ * @param {boolean} [notify=true] - whether to send notification or not.
67154
+ */
67155
+ setDirectLight = (val, ui = false, notify = true) => {
67156
+ this.directIntensity = val;
67157
+ this.directLight.intensity = scaleLight(val);
67158
+ this.checkChanges({ direct_intensity: val }, notify);
67159
+ this.update(this.updateMarker, notify);
67160
+ if (ui) {
67161
+ this.display.setDirectLight(val);
67162
+ }
67163
+ };
67164
+
67165
+ /**
67166
+ * Retrieves the metalness value.
67167
+ *
67168
+ * @returns {number} The current metalness value.
67169
+ */
67050
67170
  getMetalness = () => {
67051
67171
  return this.metalness;
67052
67172
  };
67053
67173
 
67054
- setMetalness = (value, notify = true) => {
67174
+ /**
67175
+ * Sets the metalness value for the viewer and updates related properties.
67176
+ *
67177
+ * @param {number} value - The metalness value to set.
67178
+ * @param {boolean} [ui=false] - Whether to update the UI with the new metalness value.
67179
+ * @param {boolean} [notify=true] - Whether to notify about the changes.
67180
+ */
67181
+ setMetalness = (value, ui = false, notify = true) => {
67055
67182
  this.metalness = value;
67056
67183
  this.nestedGroup.setMetalness(value);
67057
67184
  this.checkChanges({ metalness: value }, notify);
67058
67185
  this.update(this.updateMarker);
67186
+ if (ui) {
67187
+ this.display.setMetalness(value);
67188
+ }
67059
67189
  };
67190
+
67191
+ /**
67192
+ * Retrieves the roughness value.
67193
+ *
67194
+ * @returns {number} The current roughness value.
67195
+ */
67060
67196
  getRoughness = () => {
67061
67197
  return this.roughness;
67062
67198
  };
67063
67199
 
67064
- setRoughness = (value, notify = true) => {
67200
+ /**
67201
+ * Sets the roughness value for the viewer and updates related components.
67202
+ *
67203
+ * @param {number} value - The roughness value to set.
67204
+ * @param {boolean} [ui=false] - Whether to update the UI directly.
67205
+ * @param {boolean} [notify=true] - Whether to notify about the changes.
67206
+ * @returns {void}
67207
+ */
67208
+ setRoughness = (value, ui = false, notify = true) => {
67065
67209
  this.roughness = value;
67066
67210
  this.nestedGroup.setRoughness(value);
67067
67211
  this.checkChanges({ roughness: value }, notify);
67068
67212
  this.update(this.updateMarker);
67213
+ if (ui) {
67214
+ this.display.setRoughness(value);
67215
+ }
67069
67216
  };
67070
67217
 
67218
+ /**
67219
+ * Resets the material settings of the viewer to their default values.
67220
+ * Updates the metalness, roughness, ambient light intensity, and direct light intensity
67221
+ * based on the current material settings.
67222
+ *
67223
+ * @returns {void}
67224
+ */
67071
67225
  resetMaterial = () => {
67072
- this.setMetalness(this.materialSettings.metalness, true);
67073
- this.display.setMetalness(this.materialSettings.metalness);
67074
-
67075
- this.setRoughness(this.materialSettings.roughness, true);
67076
- this.display.setRoughness(this.materialSettings.roughness);
67077
-
67078
- this.setAmbientLight(this.materialSettings.ambientIntensity, true);
67079
- this.display.setAmbientLight(this.materialSettings.ambientIntensity);
67080
-
67081
- this.setDirectLight(this.materialSettings.directIntensity, true);
67082
- this.display.setDirectLight(this.materialSettings.directIntensity);
67226
+ this.setMetalness(this.materialSettings.metalness, true, true);
67227
+ this.setRoughness(this.materialSettings.roughness, true, true);
67228
+ this.setAmbientLight(this.materialSettings.ambientIntensity, true, true);
67229
+ this.setDirectLight(this.materialSettings.directIntensity, true, true);
67083
67230
  };
67084
67231
 
67085
67232
  /**
@@ -67316,47 +67463,6 @@ class Viewer {
67316
67463
  this.update(this.updateMarker, notify);
67317
67464
  };
67318
67465
 
67319
- /**
67320
- * Get intensity of ambient light.
67321
- * @returns {number} ambientLight value.
67322
- **/
67323
- getAmbientLight() {
67324
- return this.ambientIntensity;
67325
- }
67326
-
67327
- /**
67328
- * Set the intensity of ambient light
67329
- * @function
67330
- * @param {number} val - the new ambient light intensity
67331
- * @param {boolean} [notify=true] - whether to send notification or not.
67332
- */
67333
- setAmbientLight = (val, notify = true) => {
67334
- this.ambientIntensity = val;
67335
- this.ambientLight.intensity = scaleLight(val);
67336
- this.checkChanges({ ambient_intensity: val }, notify);
67337
- this.update(this.updateMarker, notify);
67338
- };
67339
-
67340
- /**
67341
- * Get intensity of direct light.
67342
- * @returns {number} directLight value.
67343
- **/
67344
- getDirectLight() {
67345
- return this.directIntensity;
67346
- }
67347
- /**
67348
- * Set the intensity of directional light
67349
- * @function
67350
- * @param {number} val - the new direct light intensity
67351
- * @param {boolean} [notify=true] - whether to send notification or not.
67352
- */
67353
- setDirectLight = (val, notify = true) => {
67354
- this.directIntensity = val;
67355
- this.directLight.intensity = scaleLight(val);
67356
- this.checkChanges({ direct_intensity: val }, notify);
67357
- this.update(this.updateMarker, notify);
67358
- };
67359
-
67360
67466
  /**
67361
67467
  * Get states of a treeview leafs.
67362
67468
  **/
@@ -67577,19 +67683,22 @@ class Viewer {
67577
67683
  * @function
67578
67684
  * @param {number} index - index of the normal: 0, 1 ,2
67579
67685
  * @param {number[]} normal - 3 dim array representing the normal
67686
+ * @param {number} [value=null] - value of the slider, if given
67580
67687
  * @param {boolean} [notify=true] - whether to send notification or not.
67581
67688
  */
67582
- setClipNormal(index, normal, notify = true) {
67689
+ setClipNormal(index, normal, value = null, notify = true) {
67583
67690
  if (normal == null) return;
67584
67691
  const normal1 = new Vector3(...normal).normalize().toArray();
67585
67692
  this.clipNormals[index] = normal1;
67586
67693
 
67587
67694
  this.clipping.setNormal(index, new Vector3(...normal1));
67588
67695
  this.clipping.setConstant(index, this.gridSize / 2);
67589
- this.setClipSlider(index, this.gridSize / 2);
67696
+ if (value == null) value = this.gridSize / 2;
67697
+ this.setClipSlider(index, value);
67698
+
67590
67699
  var notifyObject = {};
67591
67700
  notifyObject[`clip_normal_${index}`] = normal1;
67592
-
67701
+ notifyObject[`clip_slider_${index}`] = value;
67593
67702
  this.checkChanges(notifyObject, notify);
67594
67703
 
67595
67704
  this.nestedGroup.setClipPlanes(this.clipping.clipPlanes);
@@ -67610,7 +67719,11 @@ class Viewer {
67610
67719
  .normalize()
67611
67720
  .negate()
67612
67721
  .toArray();
67613
- this.setClipNormal(index, normal, notify);
67722
+ this.setClipNormal(index, normal, null, notify);
67723
+
67724
+ var notifyObject = {};
67725
+ notifyObject[`clip_normal_${index}`] = normal;
67726
+ this.checkChanges(notifyObject, notify);
67614
67727
  };
67615
67728
 
67616
67729
  /**