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.
@@ -57640,6 +57640,7 @@ void main() {
57640
57640
  this.selectedShapes = []; // array of dict ObjectGroup, bool
57641
57641
  this.point1 = null;
57642
57642
  this.point2 = null;
57643
+ this.middlePoint = null;
57643
57644
  this.contextEnabled = false; // Tells if the measure context is active
57644
57645
  this.viewer = viewer;
57645
57646
  this.scene = new Scene();
@@ -57788,9 +57789,29 @@ void main() {
57788
57789
 
57789
57790
  const canvasRect = this.viewer.renderer.domElement.getBoundingClientRect();
57790
57791
  const panelRect = this.panel.html.getBoundingClientRect();
57791
- if (this.panelX == null) {
57792
- this.panelX = canvasRect.width - panelRect.width - 2;
57793
- this.panelY = canvasRect.height - panelRect.height - 2;
57792
+
57793
+ if (this.panelX == null && this.middlePoint != null) {
57794
+ let center = this.middlePoint
57795
+ .clone()
57796
+ .project(this.viewer.camera.getCamera());
57797
+ let panelX = (center.x + 1) * (canvasRect.width / 2);
57798
+ let panelY = (1 - center.y) * (canvasRect.height / 2);
57799
+
57800
+ if (panelX < canvasRect.width / 2) {
57801
+ this.panelX = panelX + panelRect.width / 2;
57802
+ } else {
57803
+ this.panelX = panelX - panelRect.width - panelRect.width / 2;
57804
+ }
57805
+ this.panelX = Math.max(
57806
+ 0,
57807
+ Math.min(canvasRect.width - panelRect.width, this.panelX),
57808
+ );
57809
+
57810
+ this.panelY = panelY;
57811
+ this.panelY = Math.max(
57812
+ 0,
57813
+ Math.min(canvasRect.height - panelRect.height, this.panelY),
57814
+ );
57794
57815
  }
57795
57816
 
57796
57817
  this.panel.relocate(this.panelX, this.panelY);
@@ -57907,6 +57928,7 @@ void main() {
57907
57928
  super(viewer, new DistancePanel(viewer.display));
57908
57929
  this.point1 = null;
57909
57930
  this.point2 = null;
57931
+ this.middlePoint = null;
57910
57932
  }
57911
57933
 
57912
57934
  _setMeasurementVals() {
@@ -57944,13 +57966,13 @@ void main() {
57944
57966
  );
57945
57967
  this.scene.add(distanceLine);
57946
57968
 
57947
- const middlePoint = new Vector3()
57969
+ this.middlePoint = new Vector3()
57948
57970
  .addVectors(this.point1, this.point2)
57949
57971
  .multiplyScalar(0.5);
57950
57972
  const connectingLine = new DistanceLineArrow(
57951
57973
  this.coneLength,
57952
57974
  this.panelCenter,
57953
- middlePoint,
57975
+ this.middlePoint,
57954
57976
  lineWidth,
57955
57977
  this.connectingLineColor,
57956
57978
  false,
@@ -57977,6 +57999,7 @@ void main() {
57977
57999
  class PropertiesMeasurement extends Measurement {
57978
58000
  constructor(viewer) {
57979
58001
  super(viewer, new PropertiesPanel(viewer.display));
58002
+ this.middlePoint = null;
57980
58003
  }
57981
58004
 
57982
58005
  _setMeasurementVals() {
@@ -58006,11 +58029,11 @@ void main() {
58006
58029
 
58007
58030
  _makeLines() {
58008
58031
  const lineWidth = 1.5;
58009
- const middlePoint = this.responseData.center;
58032
+ this.middlePoint = this.responseData.center;
58010
58033
  const connectingLine = new DistanceLineArrow(
58011
58034
  this.coneLength,
58012
58035
  this.panelCenter,
58013
- middlePoint,
58036
+ this.middlePoint,
58014
58037
  lineWidth,
58015
58038
  this.connectingLineColor,
58016
58039
  false,
@@ -58034,6 +58057,7 @@ void main() {
58034
58057
  class AngleMeasurement extends Measurement {
58035
58058
  constructor(viewer) {
58036
58059
  super(viewer, new AnglePanel(viewer.display));
58060
+ this.middlePoint = null;
58037
58061
  }
58038
58062
 
58039
58063
  _setMeasurementVals() {
@@ -58093,6 +58117,9 @@ void main() {
58093
58117
  );
58094
58118
  this.scene.add(item1Line);
58095
58119
  this.scene.add(item2Line);
58120
+ this.middlePoint = new Vector3()
58121
+ .addVectors(this.point1, this.point2)
58122
+ .multiplyScalar(0.5);
58096
58123
  }
58097
58124
 
58098
58125
  handleResponse(response) {
@@ -58375,10 +58402,10 @@ void main() {
58375
58402
  (options.theme == "browser" &&
58376
58403
  window.matchMedia("(prefers-color-scheme: dark)").matches)
58377
58404
  ) {
58378
- document.documentElement.setAttribute("data-theme", "dark");
58405
+ this.container.setAttribute("data-theme", "dark");
58379
58406
  theme = "dark";
58380
58407
  } else {
58381
- document.documentElement.setAttribute("data-theme", "light");
58408
+ this.container.setAttribute("data-theme", "light");
58382
58409
  theme = "light";
58383
58410
  }
58384
58411
 
@@ -59772,7 +59799,16 @@ void main() {
59772
59799
  const children = object.children;
59773
59800
 
59774
59801
  for (let i = 0, l = children.length; i < l; i++) {
59775
- this.expandByObject(children[i], precise);
59802
+ if (
59803
+ !(
59804
+ children[i].name == "PlaneMeshes" &&
59805
+ children[i].children &&
59806
+ children[i].children.length > 0 &&
59807
+ children[i].children[0].type.startsWith("StencilPlane")
59808
+ )
59809
+ ) {
59810
+ this.expandByObject(children[i], precise);
59811
+ }
59776
59812
  }
59777
59813
 
59778
59814
  return this;
@@ -62287,6 +62323,33 @@ void main() {
62287
62323
  * Tree handling high level API
62288
62324
  ************************************************************************************/
62289
62325
 
62326
+ /**
62327
+ * Scrolls the parent container to center the specified element within the visible area.
62328
+ * Ensures the scrolling does not exceed the scrollable bounds of the parent container.
62329
+ *
62330
+ * @param {HTMLElement} element - The DOM element to center within the scroll container.
62331
+ */
62332
+ scrollCentered(element) {
62333
+ if (element != null) {
62334
+ let parent = this.scrollContainer;
62335
+
62336
+ // Calculate the center position of the element relative to the parent
62337
+ const elementHeight = element.offsetHeight;
62338
+ const parentHeight = parent.clientHeight;
62339
+
62340
+ // Calculate scroll position that would center the element
62341
+ const elementOffset = element.offsetTop - parent.offsetTop;
62342
+ const scrollTop = elementOffset - parentHeight / 2 + elementHeight / 2;
62343
+
62344
+ // Ensure we don't scroll beyond the parent's scrollable area
62345
+ const maxScroll = parent.scrollHeight - parentHeight;
62346
+ const clampedScrollTop = Math.max(0, Math.min(scrollTop, maxScroll));
62347
+
62348
+ // Perform the scroll
62349
+ parent.scrollTo({ top: clampedScrollTop, behavior: "smooth" });
62350
+ }
62351
+ }
62352
+
62290
62353
  /**
62291
62354
  * Opens the specified path in the tree view.
62292
62355
  *
@@ -62296,13 +62359,11 @@ void main() {
62296
62359
  const parts = path.split("/").filter(Boolean);
62297
62360
  var current = "";
62298
62361
  var node;
62362
+ let el;
62299
62363
  for (var part of parts) {
62300
62364
  current += "/" + part;
62301
62365
  node = this.findNodeByPath(current);
62302
- const el = this.getDomNode(current);
62303
- if (el != null) {
62304
- el.children[0].scrollIntoView({ behaviour: "smooth", block: "center" });
62305
- }
62366
+ el = this.getDomNode(current);
62306
62367
  if (node) {
62307
62368
  node.expanded = true;
62308
62369
  this.showChildContainer(node);
@@ -62315,6 +62376,7 @@ void main() {
62315
62376
  break;
62316
62377
  }
62317
62378
  }
62379
+ this.scrollCentered(el);
62318
62380
  this.toggleLabelColor(node);
62319
62381
  }
62320
62382
 
@@ -62330,7 +62392,8 @@ void main() {
62330
62392
  this.showChildContainer(node);
62331
62393
  const el = this.getDomNode(path);
62332
62394
  if (el != null) {
62333
- el.scrollIntoView({ behaviour: "smooth", block: "start" });
62395
+ const parent = this.scrollContainer;
62396
+ parent.scrollTop = el.offsetTop - parent.offsetTop;
62334
62397
  }
62335
62398
  if (this.debug) {
62336
62399
  console.log("update => collapsePath");
@@ -62362,7 +62425,10 @@ void main() {
62362
62425
  };
62363
62426
  this.traverse(this.root, setLevel);
62364
62427
  const el = this.getDomNode(this.getNodePath(this.root));
62365
- el.scrollIntoView({ behaviour: "smooth", block: "start" });
62428
+ if (el != null) {
62429
+ const parent = this.scrollContainer;
62430
+ parent.scrollTop = el.offsetTop - parent.offsetTop;
62431
+ }
62366
62432
  for (var i = 0; i <= (level == -1 ? this.maxLevel : level); i++) {
62367
62433
  if (this.debug) {
62368
62434
  console.log("update => openLevel");
@@ -64991,7 +65057,7 @@ void main() {
64991
65057
  }
64992
65058
  }
64993
65059
 
64994
- const version = "3.3.0";
65060
+ const version = "3.3.2";
64995
65061
 
64996
65062
  Mesh.prototype.dispose = function () {
64997
65063
  if (this.geometry) {
@@ -66318,9 +66384,9 @@ void main() {
66318
66384
 
66319
66385
  this.display.setSliderLimits(this.gridSize / 2, this.bbox.center());
66320
66386
 
66321
- this.setClipNormal(0, viewerOptions.clipNormal0, true);
66322
- this.setClipNormal(1, viewerOptions.clipNormal1, true);
66323
- this.setClipNormal(2, viewerOptions.clipNormal2, true);
66387
+ this.setClipNormal(0, viewerOptions.clipNormal0, null, true);
66388
+ this.setClipNormal(1, viewerOptions.clipNormal1, null, true);
66389
+ this.setClipNormal(2, viewerOptions.clipNormal2, null, true);
66324
66390
 
66325
66391
  this.clipSlider0 =
66326
66392
  viewerOptions.clipSlider0 != null
@@ -67053,39 +67119,120 @@ void main() {
67053
67119
  this.update(this.updateMarker);
67054
67120
  };
67055
67121
 
67122
+ /**
67123
+ * Get intensity of ambient light.
67124
+ * @returns {number} ambientLight value.
67125
+ **/
67126
+ getAmbientLight() {
67127
+ return this.ambientIntensity;
67128
+ }
67129
+
67130
+ /**
67131
+ * Set the intensity of ambient light
67132
+ * @function
67133
+ * @param {number} val - the new ambient light intensity
67134
+ * @param {boolean} [ui=false] - if true, set the UI slider value
67135
+ * @param {boolean} [notify=true] - whether to send notification or not.
67136
+ */
67137
+ setAmbientLight = (val, ui = false, notify = true) => {
67138
+ this.ambientIntensity = val;
67139
+ this.ambientLight.intensity = scaleLight(val);
67140
+ this.checkChanges({ ambient_intensity: val }, notify);
67141
+ this.update(this.updateMarker, notify);
67142
+ if (ui) {
67143
+ this.display.setAmbientLight(val);
67144
+ }
67145
+ };
67146
+
67147
+ /**
67148
+ * Get intensity of direct light.
67149
+ * @returns {number} directLight value.
67150
+ **/
67151
+ getDirectLight() {
67152
+ return this.directIntensity;
67153
+ }
67154
+ /**
67155
+ * Set the intensity of directional light
67156
+ * @function
67157
+ * @param {number} val - the new direct light intensity
67158
+ * @param {boolean} [ui=false] - if true, set the UI slider value
67159
+ * @param {boolean} [notify=true] - whether to send notification or not.
67160
+ */
67161
+ setDirectLight = (val, ui = false, notify = true) => {
67162
+ this.directIntensity = val;
67163
+ this.directLight.intensity = scaleLight(val);
67164
+ this.checkChanges({ direct_intensity: val }, notify);
67165
+ this.update(this.updateMarker, notify);
67166
+ if (ui) {
67167
+ this.display.setDirectLight(val);
67168
+ }
67169
+ };
67170
+
67171
+ /**
67172
+ * Retrieves the metalness value.
67173
+ *
67174
+ * @returns {number} The current metalness value.
67175
+ */
67056
67176
  getMetalness = () => {
67057
67177
  return this.metalness;
67058
67178
  };
67059
67179
 
67060
- setMetalness = (value, notify = true) => {
67180
+ /**
67181
+ * Sets the metalness value for the viewer and updates related properties.
67182
+ *
67183
+ * @param {number} value - The metalness value to set.
67184
+ * @param {boolean} [ui=false] - Whether to update the UI with the new metalness value.
67185
+ * @param {boolean} [notify=true] - Whether to notify about the changes.
67186
+ */
67187
+ setMetalness = (value, ui = false, notify = true) => {
67061
67188
  this.metalness = value;
67062
67189
  this.nestedGroup.setMetalness(value);
67063
67190
  this.checkChanges({ metalness: value }, notify);
67064
67191
  this.update(this.updateMarker);
67192
+ if (ui) {
67193
+ this.display.setMetalness(value);
67194
+ }
67065
67195
  };
67196
+
67197
+ /**
67198
+ * Retrieves the roughness value.
67199
+ *
67200
+ * @returns {number} The current roughness value.
67201
+ */
67066
67202
  getRoughness = () => {
67067
67203
  return this.roughness;
67068
67204
  };
67069
67205
 
67070
- setRoughness = (value, notify = true) => {
67206
+ /**
67207
+ * Sets the roughness value for the viewer and updates related components.
67208
+ *
67209
+ * @param {number} value - The roughness value to set.
67210
+ * @param {boolean} [ui=false] - Whether to update the UI directly.
67211
+ * @param {boolean} [notify=true] - Whether to notify about the changes.
67212
+ * @returns {void}
67213
+ */
67214
+ setRoughness = (value, ui = false, notify = true) => {
67071
67215
  this.roughness = value;
67072
67216
  this.nestedGroup.setRoughness(value);
67073
67217
  this.checkChanges({ roughness: value }, notify);
67074
67218
  this.update(this.updateMarker);
67219
+ if (ui) {
67220
+ this.display.setRoughness(value);
67221
+ }
67075
67222
  };
67076
67223
 
67224
+ /**
67225
+ * Resets the material settings of the viewer to their default values.
67226
+ * Updates the metalness, roughness, ambient light intensity, and direct light intensity
67227
+ * based on the current material settings.
67228
+ *
67229
+ * @returns {void}
67230
+ */
67077
67231
  resetMaterial = () => {
67078
- this.setMetalness(this.materialSettings.metalness, true);
67079
- this.display.setMetalness(this.materialSettings.metalness);
67080
-
67081
- this.setRoughness(this.materialSettings.roughness, true);
67082
- this.display.setRoughness(this.materialSettings.roughness);
67083
-
67084
- this.setAmbientLight(this.materialSettings.ambientIntensity, true);
67085
- this.display.setAmbientLight(this.materialSettings.ambientIntensity);
67086
-
67087
- this.setDirectLight(this.materialSettings.directIntensity, true);
67088
- this.display.setDirectLight(this.materialSettings.directIntensity);
67232
+ this.setMetalness(this.materialSettings.metalness, true, true);
67233
+ this.setRoughness(this.materialSettings.roughness, true, true);
67234
+ this.setAmbientLight(this.materialSettings.ambientIntensity, true, true);
67235
+ this.setDirectLight(this.materialSettings.directIntensity, true, true);
67089
67236
  };
67090
67237
 
67091
67238
  /**
@@ -67322,47 +67469,6 @@ void main() {
67322
67469
  this.update(this.updateMarker, notify);
67323
67470
  };
67324
67471
 
67325
- /**
67326
- * Get intensity of ambient light.
67327
- * @returns {number} ambientLight value.
67328
- **/
67329
- getAmbientLight() {
67330
- return this.ambientIntensity;
67331
- }
67332
-
67333
- /**
67334
- * Set the intensity of ambient light
67335
- * @function
67336
- * @param {number} val - the new ambient light intensity
67337
- * @param {boolean} [notify=true] - whether to send notification or not.
67338
- */
67339
- setAmbientLight = (val, notify = true) => {
67340
- this.ambientIntensity = val;
67341
- this.ambientLight.intensity = scaleLight(val);
67342
- this.checkChanges({ ambient_intensity: val }, notify);
67343
- this.update(this.updateMarker, notify);
67344
- };
67345
-
67346
- /**
67347
- * Get intensity of direct light.
67348
- * @returns {number} directLight value.
67349
- **/
67350
- getDirectLight() {
67351
- return this.directIntensity;
67352
- }
67353
- /**
67354
- * Set the intensity of directional light
67355
- * @function
67356
- * @param {number} val - the new direct light intensity
67357
- * @param {boolean} [notify=true] - whether to send notification or not.
67358
- */
67359
- setDirectLight = (val, notify = true) => {
67360
- this.directIntensity = val;
67361
- this.directLight.intensity = scaleLight(val);
67362
- this.checkChanges({ direct_intensity: val }, notify);
67363
- this.update(this.updateMarker, notify);
67364
- };
67365
-
67366
67472
  /**
67367
67473
  * Get states of a treeview leafs.
67368
67474
  **/
@@ -67583,19 +67689,22 @@ void main() {
67583
67689
  * @function
67584
67690
  * @param {number} index - index of the normal: 0, 1 ,2
67585
67691
  * @param {number[]} normal - 3 dim array representing the normal
67692
+ * @param {number} [value=null] - value of the slider, if given
67586
67693
  * @param {boolean} [notify=true] - whether to send notification or not.
67587
67694
  */
67588
- setClipNormal(index, normal, notify = true) {
67695
+ setClipNormal(index, normal, value = null, notify = true) {
67589
67696
  if (normal == null) return;
67590
67697
  const normal1 = new Vector3(...normal).normalize().toArray();
67591
67698
  this.clipNormals[index] = normal1;
67592
67699
 
67593
67700
  this.clipping.setNormal(index, new Vector3(...normal1));
67594
67701
  this.clipping.setConstant(index, this.gridSize / 2);
67595
- this.setClipSlider(index, this.gridSize / 2);
67702
+ if (value == null) value = this.gridSize / 2;
67703
+ this.setClipSlider(index, value);
67704
+
67596
67705
  var notifyObject = {};
67597
67706
  notifyObject[`clip_normal_${index}`] = normal1;
67598
-
67707
+ notifyObject[`clip_slider_${index}`] = value;
67599
67708
  this.checkChanges(notifyObject, notify);
67600
67709
 
67601
67710
  this.nestedGroup.setClipPlanes(this.clipping.clipPlanes);
@@ -67616,7 +67725,11 @@ void main() {
67616
67725
  .normalize()
67617
67726
  .negate()
67618
67727
  .toArray();
67619
- this.setClipNormal(index, normal, notify);
67728
+ this.setClipNormal(index, normal, null, notify);
67729
+
67730
+ var notifyObject = {};
67731
+ notifyObject[`clip_normal_${index}`] = normal;
67732
+ this.checkChanges(notifyObject, notify);
67620
67733
  };
67621
67734
 
67622
67735
  /**