three-cad-viewer 1.1.5 → 1.2.0

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.
@@ -50306,7 +50306,7 @@ const icons = {
50306
50306
  shape_mix: { light: light_shape_mix, dark: dark_shape_mix },
50307
50307
  shape_no: { light: light_shape_no, dark: dark_shape_no },
50308
50308
  stop: { light: light_stop, dark: dark_stop },
50309
- top: { light: light_top, dark: dark_top }
50309
+ top: { light: light_top, dark: dark_top },
50310
50310
  };
50311
50311
 
50312
50312
  function getIconBackground(theme, name) {
@@ -50485,7 +50485,7 @@ const buttons = [
50485
50485
  "plane",
50486
50486
  "play",
50487
50487
  "pause",
50488
- "stop"
50488
+ "stop",
50489
50489
  ];
50490
50490
  class Slider {
50491
50491
  constructor(index, min, max, display) {
@@ -50493,12 +50493,12 @@ class Slider {
50493
50493
  this.display = display;
50494
50494
 
50495
50495
  this.slider = display.container.getElementsByClassName(
50496
- `tcv_sld_value_plane${index}`
50496
+ `tcv_sld_value_plane${index}`,
50497
50497
  )[0];
50498
50498
  this.slider.min = min;
50499
50499
  this.slider.max = max;
50500
50500
  this.input = display.container.getElementsByClassName(
50501
- `tcv_inp_value_plane${index}`
50501
+ `tcv_inp_value_plane${index}`,
50502
50502
  )[0];
50503
50503
  this.input.value = max;
50504
50504
  this.slider.oninput = this.sliderChange;
@@ -50521,7 +50521,7 @@ class Slider {
50521
50521
  inputChange = (e) => {
50522
50522
  const value = Math.max(
50523
50523
  Math.min(e.target.value, this.slider.max),
50524
- this.slider.min
50524
+ this.slider.min,
50525
50525
  );
50526
50526
  // if (value != e.target.value) {
50527
50527
  // this.input.value = Math.round(1000 * value) / 1000;
@@ -50548,7 +50548,7 @@ class Slider {
50548
50548
  setValue(value, notify = true) {
50549
50549
  const trimmed_value = Math.max(
50550
50550
  Math.min(value, this.slider.max),
50551
- this.slider.min
50551
+ this.slider.min,
50552
50552
  );
50553
50553
  this.input.value = trimmed_value;
50554
50554
  this.slider.value = value;
@@ -50570,15 +50570,15 @@ class Display {
50570
50570
  this.cadTool = this.container.getElementsByClassName("tcv_cad_toolbar")[0];
50571
50571
  this.cadView = this.container.getElementsByClassName("tcv_cad_view")[0];
50572
50572
  this.cadTree = this.container.getElementsByClassName(
50573
- "tcv_cad_tree_container"
50573
+ "tcv_cad_tree_container",
50574
50574
  )[0];
50575
50575
  this.cadClip = this.container.getElementsByClassName(
50576
- "tcv_cad_clip_container"
50576
+ "tcv_cad_clip_container",
50577
50577
  )[0];
50578
50578
  this.tabTree = this.container.getElementsByClassName("tcv_tab_tree")[0];
50579
50579
  this.tabClip = this.container.getElementsByClassName("tcv_tab_clip")[0];
50580
50580
  this.cadInfo = this.container.getElementsByClassName(
50581
- "tcv_cad_info_container"
50581
+ "tcv_cad_info_container",
50582
50582
  )[0];
50583
50583
  this.cadAnim =
50584
50584
  this.container.getElementsByClassName("tcv_cad_animation")[0];
@@ -50588,7 +50588,7 @@ class Display {
50588
50588
  this.planeLabels = [];
50589
50589
  for (var i = 1; i < 4; i++) {
50590
50590
  this.planeLabels.push(
50591
- this.container.getElementsByClassName(`tcv_lbl_norm_plane${i}`)[0]
50591
+ this.container.getElementsByClassName(`tcv_lbl_norm_plane${i}`)[0],
50592
50592
  );
50593
50593
  }
50594
50594
 
@@ -50599,7 +50599,7 @@ class Display {
50599
50599
  this.treeWidth = options.treeWidth;
50600
50600
  this.setSizes(options);
50601
50601
 
50602
- this.activeTab = "tab_tree";
50602
+ this.activeTab = "tree";
50603
50603
  this.cadTree.style.display = "block";
50604
50604
  this.cadClip.style.display = "none";
50605
50605
  this.clipSliders = null;
@@ -50618,7 +50618,7 @@ class Display {
50618
50618
  var el = elements[i];
50619
50619
  el.setAttribute(
50620
50620
  "style",
50621
- `background-image: ${getIconBackground(options.theme, btn)}`
50621
+ `background-image: ${getIconBackground(options.theme, btn)}`,
50622
50622
  );
50623
50623
  }
50624
50624
  }
@@ -50680,16 +50680,16 @@ class Display {
50680
50680
  if (options.treeWidth) {
50681
50681
  this.treeWidth = options.treeWidth;
50682
50682
  this.cadTree.parentElement.parentElement.style.width = px(
50683
- options.treeWidth
50683
+ options.treeWidth,
50684
50684
  );
50685
50685
  this.cadInfo.parentElement.parentElement.style.width = px(
50686
- options.treeWidth
50686
+ options.treeWidth,
50687
50687
  );
50688
50688
  }
50689
50689
  const treeHeight = Math.round((this.height * 2) / 3);
50690
50690
  this.cadTree.parentElement.parentElement.style.height = px(treeHeight);
50691
50691
  this.cadInfo.parentElement.parentElement.style.height = px(
50692
- this.height - treeHeight - 4
50692
+ this.height - treeHeight - 4,
50693
50693
  );
50694
50694
  this.cadTool.style.width = px(this.treeWidth + this.cadWidth);
50695
50695
  }
@@ -50711,12 +50711,12 @@ class Display {
50711
50711
  this._setupCheckEvent(
50712
50712
  "tcv_transparent",
50713
50713
  this.setTransparent,
50714
- viewer.transparent
50714
+ viewer.transparent,
50715
50715
  );
50716
50716
  this._setupCheckEvent(
50717
50717
  "tcv_black_edges",
50718
50718
  this.setBlackEdges,
50719
- viewer.blackEdges
50719
+ viewer.blackEdges,
50720
50720
  );
50721
50721
 
50722
50722
  this._setupClickEvent("tcv_reset", this.reset);
@@ -50729,7 +50729,7 @@ class Display {
50729
50729
  "tcv_bottom",
50730
50730
  "tcv_left",
50731
50731
  "tcv_right",
50732
- "tcv_iso"
50732
+ "tcv_iso",
50733
50733
  ];
50734
50734
  buttons.forEach((name) => {
50735
50735
  this._setupClickEvent(name, this.setView);
@@ -50752,19 +50752,19 @@ class Display {
50752
50752
  this._setupCheckEvent(
50753
50753
  "tcv_clip_plane_helpers",
50754
50754
  this.setClipPlaneHelpers,
50755
- false
50755
+ false,
50756
50756
  );
50757
50757
  this._setupCheckEvent(
50758
50758
  "tcv_clip_intersection",
50759
50759
  this.setClipIntersection,
50760
- false
50760
+ false,
50761
50761
  );
50762
50762
 
50763
50763
  for (i = 1; i < 4; i++) {
50764
50764
  this._setupClickEvent(
50765
50765
  `tcv_btn_norm_plane${i}`,
50766
50766
  this.setClipNormalFromPosition,
50767
- false
50767
+ false,
50768
50768
  );
50769
50769
  }
50770
50770
 
@@ -50776,6 +50776,25 @@ class Display {
50776
50776
  this.setHelp(false);
50777
50777
  }
50778
50778
 
50779
+ /**
50780
+ * Check or uncheck a checkbox
50781
+ * @property {boolean} [axes = false] - show X-, Y-, Z-axes.
50782
+ * @property {boolean} [axes0 = false] - show axes at [0,0,0] ot at object center (target).
50783
+ * @property {boolean} [ortho = true] - use an orthographic (true) or perspective camera (false)
50784
+ * @property {boolean} [transparent = false] - show CAD object trasparent.
50785
+ * @property {boolean} [blackEdges = false] - show edges in black and not in edgeColor.
50786
+ * @property {boolean} [clipIntersection = false] - use intersection clipping
50787
+ * @property {boolean} [clipPlaneHelpers = false] - show clipping planes
50788
+ * @property {boolean} [tools = true] - Show/hide all tools.
50789
+ */
50790
+ updateUI(axes, axes0, ortho, transparent, blackEdges, tools) {
50791
+ this.checkElement("tcv_axes", axes);
50792
+ this.checkElement("tcv_axes0", axes0);
50793
+ this.checkElement("tcv_ortho", ortho);
50794
+ this.checkElement("tcv_transparent", transparent);
50795
+ this.checkElement("tcv_black_edges", blackEdges);
50796
+ this.setTools(tools);
50797
+ }
50779
50798
  // setup functions
50780
50799
 
50781
50800
  /**
@@ -50933,6 +50952,7 @@ class Display {
50933
50952
  */
50934
50953
  setClipPlaneHelpers = (e) => {
50935
50954
  const flag = !!e.target.checked;
50955
+ this.setClipPlaneHelpersCheck(flag);
50936
50956
  this.viewer.setClipPlaneHelpers(flag);
50937
50957
  };
50938
50958
 
@@ -50943,6 +50963,7 @@ class Display {
50943
50963
  */
50944
50964
  setClipPlaneHelpersCheck = (flag) => {
50945
50965
  this.checkElement("tcv_clip_plane_helpers", flag);
50966
+ this.lastPlaneState = flag;
50946
50967
  };
50947
50968
 
50948
50969
  /**
@@ -51028,7 +51049,7 @@ class Display {
51028
51049
  */
51029
51050
  setNormalLabel = (index, normal) => {
51030
51051
  this.planeLabels[index].innerHTML = `N=(${normal[0].toFixed(
51031
- 2
51052
+ 2,
51032
51053
  )}, ${normal[1].toFixed(2)}, ${normal[2].toFixed(2)})`;
51033
51054
  };
51034
51055
 
@@ -51086,10 +51107,11 @@ class Display {
51086
51107
  }
51087
51108
 
51088
51109
  /**
51089
- * Set minimum and maximumu of the sliders
51110
+ * Set minimum and maximum of the sliders
51111
+ * @param {number} index - index of the plane: 0,1,2
51090
51112
  * @param {number} limit - the value for both minumum and maximum valaue of the slider
51091
51113
  */
51092
- setSliders(limit) {
51114
+ setSliderLimits(limit) {
51093
51115
  for (var i = 0; i < 3; i++) {
51094
51116
  this.clipSliders[i].setSlider(limit);
51095
51117
  }
@@ -52492,8 +52514,8 @@ class BoundingBox {
52492
52514
  ];
52493
52515
  this.max = Math.max(
52494
52516
  ...[this.xmin, this.xmax, this.ymin, this.ymax, this.zmin, this.zmax].map(
52495
- (x) => Math.abs(x)
52496
- )
52517
+ (x) => Math.abs(x),
52518
+ ),
52497
52519
  );
52498
52520
  }
52499
52521
 
@@ -52551,6 +52573,16 @@ class ObjectGroup extends Group {
52551
52573
  }
52552
52574
  }
52553
52575
 
52576
+ setOpacity(opacity) {
52577
+ if (this.types.front || this.types.back) {
52578
+ this.opacity = opacity;
52579
+ this.types.back.material.opacity = this.opacity;
52580
+ this.types.front.material.opacity = this.opacity;
52581
+ this.types.back.material.needsUpdate = true;
52582
+ this.types.front.material.needsUpdate = true;
52583
+ }
52584
+ }
52585
+
52554
52586
  setShapeVisible(flag) {
52555
52587
  if (this.types.back) {
52556
52588
  this.types.back.visible = flag;
@@ -52628,7 +52660,7 @@ class NestedGroup {
52628
52660
  transparent,
52629
52661
  opacity,
52630
52662
  normalLen,
52631
- bb_max
52663
+ bb_max,
52632
52664
  ) {
52633
52665
  this.shapes = shapes;
52634
52666
  this.width = width;
@@ -52671,14 +52703,14 @@ class NestedGroup {
52671
52703
  transparent: true,
52672
52704
  depthWrite: !this.transparent,
52673
52705
  depthTest: !this.transparent,
52674
- clipIntersection: false
52706
+ clipIntersection: false,
52675
52707
  });
52676
52708
 
52677
52709
  if (Array.isArray(color)) {
52678
52710
  var colors = color
52679
52711
  .map((c) => [
52680
52712
  new Color(c).toArray(),
52681
- new Color(c).toArray()
52713
+ new Color(c).toArray(),
52682
52714
  ])
52683
52715
  .flat()
52684
52716
  .flat();
@@ -52686,7 +52718,7 @@ class NestedGroup {
52686
52718
  lineMaterial.vertexColors = "VertexColors";
52687
52719
  } else {
52688
52720
  lineMaterial.color = new Color(
52689
- color == null ? this.edgeColor : color
52721
+ color == null ? this.edgeColor : color,
52690
52722
  );
52691
52723
  }
52692
52724
 
@@ -52701,7 +52733,7 @@ class NestedGroup {
52701
52733
  renderEdges(edgeList, lineWidth, color, name) {
52702
52734
  var group = new ObjectGroup(
52703
52735
  this.defaultOpacity,
52704
- color == null ? this.edgeColor : color
52736
+ color == null ? this.edgeColor : color,
52705
52737
  );
52706
52738
 
52707
52739
  var edges = this._renderEdges(edgeList, lineWidth, color);
@@ -52716,7 +52748,7 @@ class NestedGroup {
52716
52748
  renderVertices(vertexList, size, color, name) {
52717
52749
  var group = new ObjectGroup(
52718
52750
  this.defaultOpacity,
52719
- color == null ? this.edgeColor : color
52751
+ color == null ? this.edgeColor : color,
52720
52752
  );
52721
52753
 
52722
52754
  const vertex_color = color == null ? this.edgeColor : color;
@@ -52725,7 +52757,7 @@ class NestedGroup {
52725
52757
  const geometry = new BufferGeometry();
52726
52758
  geometry.setAttribute(
52727
52759
  "position",
52728
- new Float32BufferAttribute(positions, 3)
52760
+ new Float32BufferAttribute(positions, 3),
52729
52761
  );
52730
52762
 
52731
52763
  const material = new PointsMaterial({
@@ -52733,7 +52765,7 @@ class NestedGroup {
52733
52765
  sizeAttenuation: false,
52734
52766
  size: size,
52735
52767
  transparent: true,
52736
- clipIntersection: false
52768
+ clipIntersection: false,
52737
52769
  });
52738
52770
 
52739
52771
  var points = new Points(geometry, material);
@@ -52764,7 +52796,7 @@ class NestedGroup {
52764
52796
  var shapeGeometry = new BufferGeometry();
52765
52797
  shapeGeometry.setAttribute(
52766
52798
  "position",
52767
- new BufferAttribute(positions, 3)
52799
+ new BufferAttribute(positions, 3),
52768
52800
  );
52769
52801
  shapeGeometry.setAttribute("normal", new BufferAttribute(normals, 3));
52770
52802
  shapeGeometry.setIndex(new BufferAttribute(triangles, 1));
@@ -52780,7 +52812,7 @@ class NestedGroup {
52780
52812
  depthTest: !this.transparent,
52781
52813
  clipIntersection: false,
52782
52814
  side: FrontSide,
52783
- visible: true
52815
+ visible: true,
52784
52816
  });
52785
52817
 
52786
52818
  const backMaterial = new MeshBasicMaterial({
@@ -52794,7 +52826,7 @@ class NestedGroup {
52794
52826
  depthWrite: !this.transparent,
52795
52827
  depthTest: !this.transparent,
52796
52828
  clipIntersection: false,
52797
- visible: this.backVisible
52829
+ visible: this.backVisible,
52798
52830
  });
52799
52831
 
52800
52832
  const front = new Mesh(shapeGeometry, frontMaterial);
@@ -52810,7 +52842,7 @@ class NestedGroup {
52810
52842
  const normalsHelper = new VertexNormalsHelper(
52811
52843
  front,
52812
52844
  this.normalLen,
52813
- 0xff00ff
52845
+ 0xff00ff,
52814
52846
  );
52815
52847
  group.add(normalsHelper);
52816
52848
  }
@@ -52836,7 +52868,7 @@ class NestedGroup {
52836
52868
  shape.shape,
52837
52869
  shape.width,
52838
52870
  shape.color,
52839
- shape.name
52871
+ shape.name,
52840
52872
  );
52841
52873
  break;
52842
52874
  case "vertices":
@@ -52844,7 +52876,7 @@ class NestedGroup {
52844
52876
  shape.shape,
52845
52877
  shape.size,
52846
52878
  shape.color,
52847
- shape.name
52879
+ shape.name,
52848
52880
  );
52849
52881
  break;
52850
52882
  default:
@@ -52857,7 +52889,7 @@ class NestedGroup {
52857
52889
  if (shapes.loc == null) {
52858
52890
  shapes.loc = [
52859
52891
  [0.0, 0.0, 0.0],
52860
- [0.0, 0.0, 0.0, 1.0]
52892
+ [0.0, 0.0, 0.0, 1.0],
52861
52893
  ];
52862
52894
  }
52863
52895
  group.position.set(...shapes.loc[0]);
@@ -52895,7 +52927,7 @@ class NestedGroup {
52895
52927
  b.min.y,
52896
52928
  b.max.y,
52897
52929
  b.min.z,
52898
- b.max.z
52930
+ b.max.z,
52899
52931
  );
52900
52932
  }
52901
52933
  return this.bbox;
@@ -52931,6 +52963,11 @@ class NestedGroup {
52931
52963
  this._traverse("setEdgeColor", color);
52932
52964
  }
52933
52965
 
52966
+ setOpacity(opacity) {
52967
+ this.opacity = opacity;
52968
+ this._traverse("setOpacity", opacity);
52969
+ }
52970
+
52934
52971
  setClipIntersection(flag) {
52935
52972
  this._traverse("setClipIntersection", flag);
52936
52973
  }
@@ -52966,7 +53003,7 @@ class Grid {
52966
53003
  var [axisStart, axisEnd, niceTick] = this.niceBounds(
52967
53004
  -bbox.max * 1.1,
52968
53005
  bbox.max * 1.1,
52969
- 2 * ticks
53006
+ 2 * ticks,
52970
53007
  );
52971
53008
  this.size = axisEnd - axisStart;
52972
53009
 
@@ -52978,8 +53015,8 @@ class Grid {
52978
53015
  this.size,
52979
53016
  this.size / this.ticks,
52980
53017
  0x888888,
52981
- 0xcccccc
52982
- )
53018
+ 0xcccccc,
53019
+ ),
52983
53020
  );
52984
53021
  }
52985
53022
 
@@ -53244,7 +53281,7 @@ class OrientationMarker {
53244
53281
  this.height,
53245
53282
  -this.height,
53246
53283
  1,
53247
- 1000
53284
+ 1000,
53248
53285
  );
53249
53286
  this.camera.up = this.cad_camera.up; // important!
53250
53287
  this.camera.lookAt(new Vector3(0, 0, 0));
@@ -53258,7 +53295,7 @@ class OrientationMarker {
53258
53295
  this.height,
53259
53296
  true,
53260
53297
  true,
53261
- this.theme
53298
+ this.theme,
53262
53299
  );
53263
53300
  this.scene.add(axes);
53264
53301
 
@@ -53267,12 +53304,12 @@ class OrientationMarker {
53267
53304
  ? [
53268
53305
  [1, 0x45 / 255, 0],
53269
53306
  [0x32 / 255, 0xcd / 255, 0x32 / 255],
53270
- [0x3b / 255, 0x9e / 255, 1]
53307
+ [0x3b / 255, 0x9e / 255, 1],
53271
53308
  ]
53272
53309
  : [
53273
53310
  [1, 0, 0],
53274
53311
  [0, 0.7, 0],
53275
- [0, 0, 1]
53312
+ [0, 0, 1],
53276
53313
  ];
53277
53314
  this.cones = [];
53278
53315
  for (var i = 0; i < 3; i++) {
@@ -53281,11 +53318,11 @@ class OrientationMarker {
53281
53318
  3 * size,
53282
53319
  6 * size,
53283
53320
  20,
53284
- 1
53321
+ 1,
53285
53322
  );
53286
53323
  const coneMaterial = new MeshBasicMaterial({
53287
53324
  color: new Color(...colors[i]),
53288
- toneMapped: false
53325
+ toneMapped: false,
53289
53326
  });
53290
53327
  const cone = new Mesh(coneGeometry, coneMaterial);
53291
53328
  cone.matrixAutoUpdate = false;
@@ -53353,7 +53390,7 @@ const States = {
53353
53390
  unselected: 0,
53354
53391
  selected: 1,
53355
53392
  mixed: 2,
53356
- empty: 3
53393
+ empty: 3,
53357
53394
  };
53358
53395
 
53359
53396
  class TreeView {
@@ -53390,7 +53427,7 @@ class TreeView {
53390
53427
  name: tree.name,
53391
53428
  color: tree.color,
53392
53429
  imgs: [],
53393
- states: []
53430
+ states: [],
53394
53431
  };
53395
53432
  var i = 0;
53396
53433
 
@@ -53427,7 +53464,7 @@ class TreeView {
53427
53464
  for (icon_id in this.icons) {
53428
53465
  img_button = tag("input", ["tcv_icon"], {
53429
53466
  type: "button",
53430
- style: `background-image: ${this.getIcon(icon_id, 1)}`
53467
+ style: `background-image: ${this.getIcon(icon_id, 1)}`,
53431
53468
  });
53432
53469
  img_button.setAttribute("icon_id", icon_id);
53433
53470
  img_button.addEventListener("click", (e) => {
@@ -53435,7 +53472,7 @@ class TreeView {
53435
53472
  this.handle(
53436
53473
  model.type,
53437
53474
  model.id,
53438
- e.srcElement.getAttribute("icon_id")
53475
+ e.srcElement.getAttribute("icon_id"),
53439
53476
  );
53440
53477
  });
53441
53478
  entry.appendChild(img_button);
@@ -53455,8 +53492,8 @@ class TreeView {
53455
53492
  type: "button",
53456
53493
  style: `background-image: ${this.getIcon(
53457
53494
  icon_id,
53458
- model.states[icon_id]
53459
- )}`
53495
+ model.states[icon_id],
53496
+ )}`,
53460
53497
  });
53461
53498
  img_button.setAttribute("icon_id", icon_id);
53462
53499
  if (icon_id == 0) {
@@ -53469,7 +53506,7 @@ class TreeView {
53469
53506
  this.handle(
53470
53507
  model.type,
53471
53508
  model.id,
53472
- e.srcElement.getAttribute("icon_id")
53509
+ e.srcElement.getAttribute("icon_id"),
53473
53510
  );
53474
53511
  });
53475
53512
  }
@@ -53545,7 +53582,7 @@ class TreeView {
53545
53582
  } else {
53546
53583
  state = filtered_states.reduce(
53547
53584
  (s1, s2) => (s1 == s2 ? s1 : States.mixed),
53548
- filtered_states[0]
53585
+ filtered_states[0],
53549
53586
  );
53550
53587
  }
53551
53588
  model.states[icon_id] = state;
@@ -53563,7 +53600,7 @@ class TreeView {
53563
53600
  setIcon(img, icon_id, state) {
53564
53601
  img.setAttribute(
53565
53602
  "style",
53566
- `background-image: ${this.getIcon(icon_id, state)}`
53603
+ `background-image: ${this.getIcon(icon_id, state)}`,
53567
53604
  );
53568
53605
  }
53569
53606
 
@@ -53606,21 +53643,29 @@ class Timer {
53606
53643
  this.timeit = timeit;
53607
53644
  this.start = performance.now();
53608
53645
  if (timeit) {
53609
- console.warn(`${prefix}:start`);
53646
+ console.info(`three-cad-viewer: Timer ${prefix}:start`);
53610
53647
  }
53611
53648
  }
53612
53649
 
53613
53650
  split(msg) {
53614
53651
  if (this.timeit) {
53615
53652
  const t = performance.now();
53616
- console.warn(`${this.prefix}:${msg} ${t - this.start} ms`);
53653
+ console.info(
53654
+ `three-cad-viewer: Timer ${this.prefix}:${msg} ${(
53655
+ t - this.start
53656
+ ).toFixed(1)} ms`,
53657
+ );
53617
53658
  }
53618
53659
  }
53619
53660
 
53620
53661
  stop() {
53621
53662
  if (this.timeit) {
53622
53663
  const t = performance.now();
53623
- console.warn(`${this.prefix}:stop ${t - this.start} ms`);
53664
+ console.info(
53665
+ `three-cad-viewer: Timer ${this.prefix}:stop ${(t - this.start).toFixed(
53666
+ 1,
53667
+ )} ms`,
53668
+ );
53624
53669
  }
53625
53670
  }
53626
53671
  }
@@ -53634,13 +53679,13 @@ class PlaneHelper extends Line {
53634
53679
  const geometry = new BufferGeometry();
53635
53680
  geometry.setAttribute(
53636
53681
  "position",
53637
- new Float32BufferAttribute(positions, 3)
53682
+ new Float32BufferAttribute(positions, 3),
53638
53683
  );
53639
53684
  geometry.computeBoundingSphere();
53640
53685
 
53641
53686
  super(
53642
53687
  geometry,
53643
- new LineBasicMaterial({ color: color, toneMapped: false })
53688
+ new LineBasicMaterial({ color: color, toneMapped: false }),
53644
53689
  );
53645
53690
 
53646
53691
  this.type = "PlaneHelper";
@@ -53656,7 +53701,7 @@ class PlaneHelper extends Line {
53656
53701
  const geometry2 = new BufferGeometry();
53657
53702
  geometry2.setAttribute(
53658
53703
  "position",
53659
- new Float32BufferAttribute(positions2, 3)
53704
+ new Float32BufferAttribute(positions2, 3),
53660
53705
  );
53661
53706
  geometry2.computeBoundingSphere();
53662
53707
 
@@ -53668,7 +53713,7 @@ class PlaneHelper extends Line {
53668
53713
  transparent: true,
53669
53714
  depthWrite: false,
53670
53715
  toneMapped: false,
53671
- })
53716
+ }),
53672
53717
  );
53673
53718
  this.add(this.planeMesh);
53674
53719
  }
@@ -53713,8 +53758,8 @@ class Clipping {
53713
53758
  this.clipPlanes[0],
53714
53759
  center,
53715
53760
  size,
53716
- theme === "light" ? 0xff0000 : 0xff4500
53717
- )
53761
+ theme === "light" ? 0xff0000 : 0xff4500,
53762
+ ),
53718
53763
  );
53719
53764
  this.planeHelpers.add(
53720
53765
  new PlaneHelper(
@@ -53722,8 +53767,8 @@ class Clipping {
53722
53767
  this.clipPlanes[1],
53723
53768
  center,
53724
53769
  size,
53725
- theme === "light" ? 0x00ff00 : 0x32cd32
53726
- )
53770
+ theme === "light" ? 0x00ff00 : 0x32cd32,
53771
+ ),
53727
53772
  );
53728
53773
  this.planeHelpers.add(
53729
53774
  new PlaneHelper(
@@ -53731,8 +53776,8 @@ class Clipping {
53731
53776
  this.clipPlanes[2],
53732
53777
  center,
53733
53778
  size,
53734
- theme === "light" ? 0x0000ff : 0x3b9eff
53735
- )
53779
+ theme === "light" ? 0x0000ff : 0x3b9eff,
53780
+ ),
53736
53781
  );
53737
53782
  this.planeHelpers.visible = false;
53738
53783
  }
@@ -53798,22 +53843,22 @@ class Animation {
53798
53843
  position
53799
53844
  .clone()
53800
53845
  .add(new Vector3(...v))
53801
- .toArray()
53846
+ .toArray(),
53802
53847
  );
53803
53848
  break;
53804
53849
  case "tx":
53805
53850
  newValues = values.map((v) =>
53806
- position.clone().add(new Vector3(v, 0, 0)).toArray()
53851
+ position.clone().add(new Vector3(v, 0, 0)).toArray(),
53807
53852
  );
53808
53853
  break;
53809
53854
  case "ty":
53810
53855
  newValues = values.map((v) =>
53811
- position.clone().add(new Vector3(0, v, 0)).toArray()
53856
+ position.clone().add(new Vector3(0, v, 0)).toArray(),
53812
53857
  );
53813
53858
  break;
53814
53859
  case "tz":
53815
53860
  newValues = values.map((v) =>
53816
- position.clone().add(new Vector3(0, 0, v)).toArray()
53861
+ position.clone().add(new Vector3(0, 0, v)).toArray(),
53817
53862
  );
53818
53863
  break;
53819
53864
  default:
@@ -53825,18 +53870,18 @@ class Animation {
53825
53870
  new NumberKeyframeTrack(
53826
53871
  selector + ".position",
53827
53872
  times,
53828
- newValues.flat()
53829
- )
53873
+ newValues.flat(),
53874
+ ),
53830
53875
  );
53831
53876
  } else {
53832
53877
  const quaternion = group.quaternion;
53833
53878
 
53834
53879
  if (action.startsWith("r")) {
53835
53880
  const quatValues = values.map((angle) =>
53836
- fromAxisAngle(action.slice(1), angle)
53881
+ fromAxisAngle(action.slice(1), angle),
53837
53882
  );
53838
53883
  newValues = quatValues.map((rot) =>
53839
- quaternion.clone().multiply(rot).toArray()
53884
+ quaternion.clone().multiply(rot).toArray(),
53840
53885
  );
53841
53886
  } else if (action == "q") {
53842
53887
  newValues = values.map((q) => quaternion.clone().multiply(q).toArray());
@@ -53849,8 +53894,8 @@ class Animation {
53849
53894
  new QuaternionKeyframeTrack(
53850
53895
  selector + ".quaternion",
53851
53896
  times,
53852
- newValues.flat()
53853
- )
53897
+ newValues.flat(),
53898
+ ),
53854
53899
  );
53855
53900
  }
53856
53901
  }
@@ -53929,7 +53974,7 @@ class Info {
53929
53974
  <table>
53930
53975
  <tr class="tcv_small_table"><td>CadQuery:</td> <td>${cqVersion}</td> </tr>
53931
53976
  <tr class="tcv_small_table"><td>Jupyter CadQuery:</td><td>${jcqVersion}</td> </tr>
53932
- </table>`
53977
+ </table>`,
53933
53978
  );
53934
53979
  }
53935
53980
 
@@ -55400,7 +55445,7 @@ class Controls {
55400
55445
  domElement,
55401
55446
  rotateSpeed = 1.0,
55402
55447
  zoomSpeed = 1.0,
55403
- panSpeed = 1.0
55448
+ panSpeed = 1.0,
55404
55449
  ) {
55405
55450
  this.type = type;
55406
55451
  this.camera = camera;
@@ -55547,6 +55592,35 @@ class Controls {
55547
55592
  this.controls.rotateSpeed = val;
55548
55593
  }
55549
55594
 
55595
+ /**
55596
+ * Get reset location value.
55597
+ * @function
55598
+ * @returns {object} - target, position, quaternion, zoom as object.
55599
+ */
55600
+ getResetLocation = () => {
55601
+ return {
55602
+ target0: this.controls.target0.clone(),
55603
+ position0: this.controls.position0.clone(),
55604
+ quaternion0: this.controls.quaternion0.clone(),
55605
+ zoom0: this.controls.zoom0,
55606
+ };
55607
+ };
55608
+
55609
+ /**
55610
+ * Set reset location value.
55611
+ * @function
55612
+ * @param {number[]} target - camera target as 3 dim Array [x,y,z].
55613
+ * @param {number[]} position - camera position as 3 dim Array [x,y,z].
55614
+ * @returns {number[]} camera rotation as 4 dim quaternion array [x,y,z,w].
55615
+ * @param {boolean} [notify=true] - whether to send notification or not.
55616
+ */
55617
+ setResetLocation = (target, position, quaternion, zoom) => {
55618
+ this.controls.target0.copy(target);
55619
+ this.controls.position0.copy(position);
55620
+ this.controls.quaternion0.copy(quaternion);
55621
+ this.controls.zoom0 = zoom;
55622
+ };
55623
+
55550
55624
  // Rotations for OrbitControls
55551
55625
 
55552
55626
  /**
@@ -55604,7 +55678,7 @@ const defaultDirections = {
55604
55678
  left: new Vector3(0, 1, 0),
55605
55679
  right: new Vector3(0, -1, 0),
55606
55680
  top: new Vector3(0, 0, 1),
55607
- bottom: new Vector3(0, 0, -1)
55681
+ bottom: new Vector3(0, 0, -1),
55608
55682
  };
55609
55683
  class Camera {
55610
55684
  /**
@@ -55635,7 +55709,7 @@ class Camera {
55635
55709
  fov,
55636
55710
  aspect,
55637
55711
  0.1,
55638
- 100 * distance
55712
+ 100 * distance,
55639
55713
  );
55640
55714
  this.pCamera.up.set(0, 0, 1);
55641
55715
  this.pCamera.lookAt(this.target);
@@ -55651,7 +55725,7 @@ class Camera {
55651
55725
  h,
55652
55726
  -h,
55653
55727
  0.1,
55654
- 100 * distance
55728
+ 100 * distance,
55655
55729
  );
55656
55730
  this.oCamera.up.set(0, 0, 1);
55657
55731
  this.oCamera.lookAt(this.target);
@@ -55852,20 +55926,30 @@ class Viewer {
55852
55926
  /**
55853
55927
  * Create Viewer.
55854
55928
  * @param {Display} display - The Display object.
55855
- * @param {ViewerOptions} options - configuration parameters.
55929
+ * @param {DisplayOptions} options - configuration parameters.
55856
55930
  * @param {NotificationCallback} notifyCallback - The callback to receive changes of viewer parameters.
55931
+ * @param {boolean} updateMarker - enforce to redraw orientation marker after evry ui activity
55857
55932
  */
55858
- constructor(container, options, notifyCallback, pinAsPngCallback = null) {
55859
- this.setDefaults(options);
55933
+ constructor(
55934
+ container,
55935
+ options,
55936
+ notifyCallback,
55937
+ pinAsPngCallback = null,
55938
+ updateMarker = true,
55939
+ ) {
55860
55940
  this.notifyCallback = notifyCallback;
55861
55941
  this.pinAsPngCallback = pinAsPngCallback;
55942
+ this.updateMarker = updateMarker;
55862
55943
 
55863
55944
  this.hasAnimationLoop = false;
55945
+
55946
+ this.setDisplayDefaults(options);
55947
+
55864
55948
  this.display = new Display(container, options);
55865
55949
  this.display.setSizes({
55866
55950
  cadWidth: this.cadWidth,
55867
55951
  height: this.height,
55868
- treeWidth: this.treeWidth
55952
+ treeWidth: this.treeWidth,
55869
55953
  });
55870
55954
 
55871
55955
  window.THREE = THREE;
@@ -55888,19 +55972,23 @@ class Viewer {
55888
55972
  this.animation = null;
55889
55973
  this.continueAnimation = true;
55890
55974
 
55975
+ this.clipNormals = [
55976
+ [-1, 0, 0],
55977
+ [0, -1, 0],
55978
+ [0, 0, -1],
55979
+ ];
55980
+
55891
55981
  this.camera_distance = 0;
55892
55982
  this.raycaster = new Raycaster();
55893
55983
  this.mouse = new Vector2();
55894
55984
 
55895
- this.width = this.cadWidth;
55896
-
55897
55985
  // setup renderer
55898
55986
  this.renderer = new WebGLRenderer({
55899
55987
  alpha: !this.dark,
55900
- antialias: true
55988
+ antialias: true,
55901
55989
  });
55902
55990
  this.renderer.setPixelRatio(window.devicePixelRatio);
55903
- this.renderer.setSize(this.width, this.height);
55991
+ this.renderer.setSize(this.cadWidth, this.height);
55904
55992
  this.renderer.setClearColor(0xffffff, 0);
55905
55993
  this.renderer.autoClear = false;
55906
55994
 
@@ -55908,7 +55996,7 @@ class Viewer {
55908
55996
 
55909
55997
  this.renderer.domElement.addEventListener("dblclick", this.pick, false);
55910
55998
  this.renderer.domElement.addEventListener("contextmenu", (e) =>
55911
- e.stopPropagation()
55999
+ e.stopPropagation(),
55912
56000
  );
55913
56001
 
55914
56002
  this.display.addCadView(this.renderer.domElement);
@@ -55921,53 +56009,132 @@ class Viewer {
55921
56009
  }
55922
56010
 
55923
56011
  /**
55924
- * Enhance the given options by all default values.
55925
- * @param {ViewerOptions} options - The provided options object for the viewer.
56012
+ * Enhance the given options for viewer creation by default values.
56013
+ * @param {DisplayOptions} options - The provided options object for the viewer.
55926
56014
  */
55927
- setDefaults(options) {
56015
+ setDisplayDefaults(options) {
56016
+ this.theme = "light";
55928
56017
  this.cadWidth = 800;
55929
- this.height = 600;
55930
56018
  this.treeWidth = 250;
55931
- this.treeHeight = 250;
55932
- this.theme = "light";
55933
- this.bbFactor = 1.0;
55934
- this.zoom0 = 1.0;
55935
- this.grid = [false, false, false];
55936
- this.ticks = 10;
56019
+ this.height = 600;
56020
+ this.pinning = false;
56021
+
56022
+ for (var option in options) {
56023
+ if (this[option] == null) {
56024
+ console.warn(`Unknown option "${option}" to create a viewer - ignored`);
56025
+ } else {
56026
+ this[option] = options[option];
56027
+ }
56028
+ }
56029
+ }
56030
+
56031
+ /**
56032
+ * Enhance the given options for rendering by default values.
56033
+ * @param {RenderOptions} options - The provided options object for the viewer.
56034
+ */
56035
+ setRenderDefaults(options) {
56036
+ this.ambientIntensity = 0.5;
56037
+ this.directIntensity = 0.3;
56038
+ this.defaultOpacity = 0.5;
56039
+ this.edgeColor = 0x707070;
56040
+ this.normalLen = 0;
56041
+
56042
+ for (var option in options) {
56043
+ if (this[option] == null) {
56044
+ console.warn(`Unknown option "${option}" to create a viewer - ignored`);
56045
+ } else {
56046
+ this[option] = options[option];
56047
+ }
56048
+ }
56049
+ }
56050
+
56051
+ /**
56052
+ * Enhance the given options for the view by default values.
56053
+ * @param {ViewOptions} options - The provided options object for the viewer.
56054
+ */
56055
+
56056
+ setViewerDefaults(options) {
55937
56057
  this.axes = false;
55938
56058
  this.axes0 = false;
56059
+ this.grid = [false, false, false];
55939
56060
  this.ortho = true;
56061
+ this.transparent = false;
56062
+ this.blackEdges = false;
56063
+
56064
+ this.clipIntersection = false;
56065
+ this.clipPlaneHelpers = false;
56066
+ this.clipNormal0 = [-1, 0, 0];
56067
+ this.clipNormal1 = [0, -1, 0];
56068
+ this.clipNormal2 = [0, 0, -1];
56069
+ this.clipSlider0 = -1;
56070
+ this.clipSlider1 = -1;
56071
+ this.clipSlider2 = -1;
56072
+ this.tools = true;
55940
56073
  this.control = "orbit";
56074
+ this.ticks = 10;
56075
+
56076
+ this.position = null;
56077
+ this.quaternion = null;
56078
+ this.zoom = null;
56079
+ this.zoom0 = 1.0;
56080
+
56081
+ this.panSpeed = 0.5;
55941
56082
  this.rotateSpeed = 1.0;
55942
56083
  this.zoomSpeed = 0.5;
55943
- this.panSpeed = 0.5;
55944
- this.blackEdges = false;
55945
- this.edgeColor = 0x707070;
55946
- this.ambientIntensity = 0.5;
55947
- this.directIntensity = 0.3;
55948
- this.transparent = false;
55949
- this.defaultOpacity = 0.4;
55950
- this.normalLen = 0;
55951
- this.tools = true;
55952
56084
  this.timeit = false;
55953
- this.clipIntersection = false;
55954
- this.clipPlaneHelpers = false;
55955
- this.clipNormal = [
55956
- [-1, 0, 0],
55957
- [0, -1, 0],
55958
- [0, 0, -1]
55959
- ];
55960
- this.pinning = false;
55961
56085
 
55962
56086
  for (var option in options) {
55963
56087
  if (this[option] == null) {
55964
- console.warn(`unknown option ${option} ignored`);
56088
+ console.warn(`Unknown option ${option} to add shapes - ignored`);
55965
56089
  } else {
55966
56090
  this[option] = options[option];
55967
56091
  }
55968
56092
  }
55969
56093
  }
55970
56094
 
56095
+ dumpOptions() {
56096
+ console.log("Display:");
56097
+ console.log("- cadWidth", this.cadWidth);
56098
+ console.log("- control", this.control);
56099
+ console.log("- height", this.height);
56100
+ console.log("- pinning", this.pinning);
56101
+ console.log("- theme", this.theme);
56102
+ console.log("- treeHeight", this.treeHeight);
56103
+ console.log("- treeWidth", this.treeWidth);
56104
+
56105
+ console.log("Render:");
56106
+ console.log("- ambientIntensity", this.ambientIntensity);
56107
+ console.log("- defaultOpacity", this.defaultOpacity);
56108
+ console.log("- directIntensity", this.directIntensity);
56109
+ console.log("- edgeColor", this.edgeColor);
56110
+ console.log("- normalLen", this.normalLen);
56111
+
56112
+ console.log("View:");
56113
+ console.log("- axes", this.axes);
56114
+ console.log("- axes0", this.axes0);
56115
+ console.log("- blackEdges", this.blackEdges);
56116
+ console.log("- clipIntersection", this.clipIntersection);
56117
+ console.log("- clipPlaneHelpers", this.clipPlaneHelpers);
56118
+ console.log("- clipNormal0", this.clipNormal0);
56119
+ console.log("- clipNormal1", this.clipNormal1);
56120
+ console.log("- clipNormal2", this.clipNormal2);
56121
+ console.log("- clipSlider0", this.clipSlider0);
56122
+ console.log("- clipSlider1", this.clipSlider1);
56123
+ console.log("- clipSlider2", this.clipSlider2);
56124
+ console.log("- grid", this.grid);
56125
+ console.log("- ortho", this.ortho);
56126
+ console.log("- panSpeed", this.panSpeed);
56127
+ console.log("- position", this.position);
56128
+ console.log("- quaternion", this.quaternion);
56129
+ console.log("- rotateSpeed", this.rotateSpeed);
56130
+ console.log("- ticks", this.ticks);
56131
+ console.log("- timeit", this.timeit);
56132
+ console.log("- tools", this.tools);
56133
+ console.log("- transparent", this.transparent);
56134
+ console.log("- zoom", this.zoom);
56135
+ console.log("- zoom0", this.zoom0);
56136
+ console.log("- zoomSpeed", this.zoomSpeed);
56137
+ }
55971
56138
  // - - - - - - - - - - - - - - - - - - - - - - - -
55972
56139
  // Load Tesselated Shapes
55973
56140
  // - - - - - - - - - - - - - - - - - - - - - - - -
@@ -55980,12 +56147,12 @@ class Viewer {
55980
56147
  _renderTessellatedShapes(shapes) {
55981
56148
  const nestedGroup = new NestedGroup(
55982
56149
  shapes,
55983
- this.width,
56150
+ this.cadWidth,
55984
56151
  this.height,
55985
56152
  this.edgeColor,
55986
56153
  this.transparent,
55987
56154
  this.defaultOpacity,
55988
- this.normalLen
56155
+ this.normalLen,
55989
56156
  );
55990
56157
  nestedGroup.render();
55991
56158
  return nestedGroup;
@@ -56004,7 +56171,7 @@ class Viewer {
56004
56171
  const newPath = `${path}${delim}${subGroup.name}`;
56005
56172
  var result = {
56006
56173
  name: subGroup.name,
56007
- id: newPath
56174
+ id: newPath,
56008
56175
  };
56009
56176
  if (subGroup.parts) {
56010
56177
  result.type = "node";
@@ -56026,12 +56193,14 @@ class Viewer {
56026
56193
  * Render the shapes of the CAD object.
56027
56194
  * @param {Shapes} shapes - The Shapes object.
56028
56195
  * @param {States} states - the visibility state of meshes and edges
56196
+ * @param {RenderOptions} options - the options for rendering
56029
56197
  * @returns {THREE.Group} A nested THREE.Group object.
56030
56198
  */
56031
- renderTessellatedShapes(shapes, states) {
56199
+ renderTessellatedShapes(shapes, states, options) {
56200
+ this.setRenderDefaults(options);
56032
56201
  return [
56033
56202
  this._renderTessellatedShapes(shapes),
56034
- this._getTree(shapes, states)
56203
+ this._getTree(shapes, states),
56035
56204
  ];
56036
56205
  }
56037
56206
 
@@ -56052,7 +56221,7 @@ class Viewer {
56052
56221
  this.nestedGroup.groups[selector],
56053
56222
  action,
56054
56223
  time,
56055
- values
56224
+ values,
56056
56225
  );
56057
56226
  }
56058
56227
 
@@ -56075,7 +56244,7 @@ class Viewer {
56075
56244
  this.clipAction = this.animation.animate(
56076
56245
  this.nestedGroup.rootGroup,
56077
56246
  duration,
56078
- speed
56247
+ speed,
56079
56248
  );
56080
56249
  }
56081
56250
 
@@ -56112,7 +56281,7 @@ class Viewer {
56112
56281
  old:
56113
56282
  this.lastNotification[key] == null
56114
56283
  ? null
56115
- : clone(this.lastNotification[key])
56284
+ : clone(this.lastNotification[key]),
56116
56285
  };
56117
56286
  this.lastNotification[key] = change;
56118
56287
  }
@@ -56142,7 +56311,7 @@ class Viewer {
56142
56311
 
56143
56312
  this.orientationMarker.update(
56144
56313
  this.camera.getPosition().clone().sub(this.controls.getTarget()),
56145
- this.camera.getRotation()
56314
+ this.camera.getRotation(),
56146
56315
  );
56147
56316
  this.orientationMarker.render(this.renderer);
56148
56317
  }
@@ -56156,9 +56325,9 @@ class Viewer {
56156
56325
  {
56157
56326
  zoom: this.camera.getZoom(),
56158
56327
  position: this.camera.getPosition().toArray(),
56159
- quaternion: this.camera.getQuaternion().toArray()
56328
+ quaternion: this.camera.getQuaternion().toArray(),
56160
56329
  },
56161
- notify
56330
+ notify,
56162
56331
  );
56163
56332
  };
56164
56333
 
@@ -56297,16 +56466,16 @@ class Viewer {
56297
56466
  * @param {Shapes} shapes - the shapes of the CAD object to be rendered
56298
56467
  * @param {NavTree} tree - The navigation tree object
56299
56468
  * @param {States} states - the visibility state of meshes and edges
56300
- * @param {number[]} [position=null] - the camera position.
56301
- * @param {number[]} [quaternion=null] - the camera rotation as quaternion. Only relevant for TrackballControls and needs position to be set, too.
56302
- * @param {number} [zoom=null] - zoom value.
56469
+ * @param {ViewerOptions} options - the Viewer options
56303
56470
  */
56304
- render(group, tree, states, position = null, quaternion = null, zoom = null) {
56305
- this.states = states;
56306
- this.scene = new Scene();
56471
+ render(group, tree, states, options) {
56472
+ this.setViewerDefaults(options);
56307
56473
 
56308
56474
  const timer = new Timer("viewer", this.timeit);
56309
56475
 
56476
+ this.states = states;
56477
+ this.scene = new Scene();
56478
+
56310
56479
  //
56311
56480
  // render the input assembly
56312
56481
  //
@@ -56336,12 +56505,12 @@ class Viewer {
56336
56505
  // create cameras
56337
56506
  //
56338
56507
  this.camera = new Camera(
56339
- this.width,
56508
+ this.cadWidth,
56340
56509
  this.height,
56341
56510
  this.bb_radius,
56342
56511
  this.bbox.center,
56343
56512
  this.ortho,
56344
- this.control
56513
+ this.control,
56345
56514
  );
56346
56515
 
56347
56516
  //
@@ -56354,7 +56523,7 @@ class Viewer {
56354
56523
  this.renderer.domElement,
56355
56524
  this.rotateSpeed,
56356
56525
  this.zoomSpeed,
56357
- this.panSpeed
56526
+ this.panSpeed,
56358
56527
  );
56359
56528
  this.controls.enableKeys = false;
56360
56529
 
@@ -56362,18 +56531,18 @@ class Viewer {
56362
56531
  this.controls.controls.screenSpacePanning = true;
56363
56532
 
56364
56533
  // this needs to happen after the controls have been established
56365
- if (position == null && quaternion == null) {
56366
- this.presetCamera("iso", zoom);
56367
- } else if (position != null) {
56368
- this.setCamera(false, position, quaternion, zoom);
56369
- if (quaternion == null) {
56534
+ if (options.position == null && options.quaternion == null) {
56535
+ this.presetCamera("iso", options.zoom);
56536
+ } else if (options.position != null) {
56537
+ this.setCamera(false, options.position, options.quaternion, options.zoom);
56538
+ if (options.quaternion == null) {
56370
56539
  this.camera.lookAtTarget();
56371
56540
  }
56372
56541
  } else {
56373
56542
  this.info.addHtml(
56374
- "<b>quaternion needs position to be provided, falling back to ISO view</b>"
56543
+ "<b>quaternion needs position to be provided, falling back to ISO view</b>",
56375
56544
  );
56376
- this.presetCamera("iso", zoom);
56545
+ this.presetCamera("iso", options.zoom);
56377
56546
  }
56378
56547
 
56379
56548
  // Save the new state again
@@ -56391,7 +56560,7 @@ class Viewer {
56391
56560
  for (var zpos of [-this.bb_max, this.bb_max]) {
56392
56561
  const directionalLight = new DirectionalLight(
56393
56562
  0xffffff,
56394
- this.directIntensity
56563
+ this.directIntensity,
56395
56564
  );
56396
56565
  directionalLight.position.set(10 * xpos, 10 * ypos, 10 * zpos);
56397
56566
  this.scene.add(directionalLight);
@@ -56408,7 +56577,7 @@ class Viewer {
56408
56577
  this.bbox,
56409
56578
  this.ticks,
56410
56579
  this.axes0,
56411
- this.grid
56580
+ this.grid,
56412
56581
  );
56413
56582
  this.gridHelper.computeGrid();
56414
56583
 
@@ -56426,11 +56595,11 @@ class Viewer {
56426
56595
  this.bbox.center,
56427
56596
  this.gridSize / 2,
56428
56597
  2,
56429
- this.width,
56598
+ this.cadWidth,
56430
56599
  this.height,
56431
56600
  this.axes0,
56432
56601
  this.axes,
56433
- this.theme
56602
+ this.theme,
56434
56603
  );
56435
56604
  this.scene.add(this.axesHelper);
56436
56605
 
@@ -56443,12 +56612,27 @@ class Viewer {
56443
56612
  this.gridSize,
56444
56613
  this.gridSize / 2,
56445
56614
  (index, normal) => this.display.setNormalLabel(index, normal),
56446
- this.theme
56615
+ this.theme,
56447
56616
  );
56448
56617
 
56618
+ this.display.setSliderLimits(this.gridSize / 2);
56619
+
56620
+ this.clipSlider0 = this.gridSize / 2;
56621
+ this.clipSlider1 = this.gridSize / 2;
56622
+ this.clipSlider2 = this.gridSize / 2;
56623
+ this.setClipSlider(0, this.clipSlider0, true);
56624
+ this.setClipSlider(1, this.clipSlider1, true);
56625
+ this.setClipSlider(2, this.clipSlider2, true);
56626
+
56627
+ this.setClipNormal(0, options.clipNormal0, false);
56628
+ this.setClipNormal(1, options.clipNormal1, false);
56629
+ this.setClipNormal(2, options.clipNormal2, false);
56630
+
56631
+ this.setClipIntersection(options.clipIntersection, false);
56632
+ this.setClipPlaneHelpersCheck(options.clipPlaneHelpers);
56633
+
56449
56634
  this.scene.add(this.clipping.planeHelpers);
56450
56635
  this.nestedGroup.setClipPlanes(this.clipping.clipPlanes);
56451
- this.display.setSliders(this.gridSize / 2);
56452
56636
 
56453
56637
  this.setLocalClipping(false); // only allow clipping when Clipping tab is selected
56454
56638
 
@@ -56460,7 +56644,7 @@ class Viewer {
56460
56644
  80,
56461
56645
  80,
56462
56646
  this.camera.getCamera(),
56463
- this.theme
56647
+ this.theme,
56464
56648
  );
56465
56649
  this.orientationMarker.create();
56466
56650
 
@@ -56473,7 +56657,7 @@ class Viewer {
56473
56657
  clone(this.states),
56474
56658
  this.tree,
56475
56659
  this.setObjects,
56476
- this.theme
56660
+ this.theme,
56477
56661
  );
56478
56662
  this.display.addCadTree(this.treeview.render());
56479
56663
 
@@ -56481,6 +56665,19 @@ class Viewer {
56481
56665
 
56482
56666
  timer.split("scene done");
56483
56667
 
56668
+ //
56669
+ // update UI elements
56670
+ //
56671
+
56672
+ this.display.updateUI(
56673
+ this.axes,
56674
+ this.axes0,
56675
+ this.ortho,
56676
+ this.transparent,
56677
+ this.blackEdges,
56678
+ this.tools,
56679
+ );
56680
+
56484
56681
  //
56485
56682
  // show the rendering
56486
56683
  //
@@ -56489,6 +56686,21 @@ class Viewer {
56489
56686
 
56490
56687
  this.ready = true;
56491
56688
  this.info.readyMsg(this.gridHelper.ticks, this.control);
56689
+
56690
+ //
56691
+ // notify calculated results
56692
+ //
56693
+
56694
+ if (this.notifyCallback) {
56695
+ this.notifyCallback({
56696
+ tab: { old: null, new: this.display.activeTab },
56697
+ target: { old: null, new: this.controls.target },
56698
+ target0: { old: null, new: this.controls.target0 },
56699
+ clip_normal_0: { old: null, new: this.clipNormal0 },
56700
+ clip_normal_1: { old: null, new: this.clipNormal1 },
56701
+ clip_normal_2: { old: null, new: this.clipNormal2 },
56702
+ });
56703
+ }
56492
56704
  timer.stop();
56493
56705
  }
56494
56706
 
@@ -56510,14 +56722,14 @@ class Viewer {
56510
56722
  position,
56511
56723
  quaternion = null,
56512
56724
  zoom = null,
56513
- notify = true
56725
+ notify = true,
56514
56726
  ) => {
56515
56727
  this.camera.setupCamera(
56516
56728
  relative,
56517
56729
  new Vector3(...position),
56518
56730
  quaternion != null ? new Quaternion(...quaternion) : null,
56519
56731
  zoom,
56520
- notify
56732
+ notify,
56521
56733
  );
56522
56734
  this.update(true, notify);
56523
56735
  };
@@ -56582,7 +56794,7 @@ class Viewer {
56582
56794
  */
56583
56795
  setLocalClipping(flag) {
56584
56796
  this.renderer.localClippingEnabled = flag;
56585
- this.update(false);
56797
+ this.update(this.updateMarker);
56586
56798
  }
56587
56799
 
56588
56800
  /**
@@ -56608,7 +56820,7 @@ class Viewer {
56608
56820
 
56609
56821
  this.checkChanges({ states: states }, notify);
56610
56822
 
56611
- this.update(false);
56823
+ this.update(this.updateMarker);
56612
56824
  };
56613
56825
 
56614
56826
  /**
@@ -56619,7 +56831,7 @@ class Viewer {
56619
56831
  */
56620
56832
  refreshPlane = (index, value) => {
56621
56833
  this.clipping.setConstant(index, value);
56622
- this.update(false);
56834
+ this.update(this.updateMarker);
56623
56835
  };
56624
56836
 
56625
56837
  /**
@@ -56653,9 +56865,9 @@ class Viewer {
56653
56865
  */
56654
56866
  setState = (id, state, notify = true) => {
56655
56867
  [0, 1].forEach((i) =>
56656
- this.treeview.handleStateChange("leaf", id, i, state[i])
56868
+ this.treeview.handleStateChange("leaf", id, i, state[i]),
56657
56869
  );
56658
- this.update(false, notify);
56870
+ this.update(this.updateMarker, notify);
56659
56871
  };
56660
56872
 
56661
56873
  /**
@@ -56667,14 +56879,14 @@ class Viewer {
56667
56879
  const rect = this.renderer.domElement.getBoundingClientRect();
56668
56880
  const offsetX = rect.x + window.pageXOffset;
56669
56881
  const offsetY = rect.y + window.pageYOffset;
56670
- this.mouse.x = ((e.pageX - offsetX) / this.width) * 2 - 1;
56882
+ this.mouse.x = ((e.pageX - offsetX) / this.cadWidth) * 2 - 1;
56671
56883
  this.mouse.y = -((e.pageY - offsetY) / this.height) * 2 + 1;
56672
56884
 
56673
56885
  this.raycaster.setFromCamera(this.mouse, this.camera.getCamera());
56674
56886
 
56675
56887
  const objects = this.raycaster.intersectObjects(
56676
56888
  this.scene.children.slice(0, 1),
56677
- true
56889
+ true,
56678
56890
  );
56679
56891
  var nearest = null;
56680
56892
  for (var object of objects) {
@@ -56684,7 +56896,7 @@ class Viewer {
56684
56896
  name: object.object.name,
56685
56897
  boundingBox: object.object.geometry.boundingBox,
56686
56898
  boundingSphere: object.object.geometry.boundingSphere,
56687
- objectGroup: object.object.parent
56899
+ objectGroup: object.object.parent,
56688
56900
  };
56689
56901
  break;
56690
56902
  }
@@ -56695,8 +56907,8 @@ class Viewer {
56695
56907
  path: nearest.path,
56696
56908
  name: nearest.name,
56697
56909
  boundingBox: JSON.parse(JSON.stringify(nearest.boundingBox)),
56698
- boundingSphere: JSON.parse(JSON.stringify(nearest.boundingSphere))
56699
- }
56910
+ boundingSphere: JSON.parse(JSON.stringify(nearest.boundingSphere)),
56911
+ },
56700
56912
  });
56701
56913
  if (e.metaKey) {
56702
56914
  var update = {};
@@ -56733,7 +56945,7 @@ class Viewer {
56733
56945
 
56734
56946
  this.checkChanges({ axes: flag }, notify);
56735
56947
 
56736
- this.update(false);
56948
+ this.update(this.updateMarker);
56737
56949
  };
56738
56950
 
56739
56951
  /**
@@ -56747,7 +56959,7 @@ class Viewer {
56747
56959
 
56748
56960
  this.checkChanges({ grid: this.gridHelper.grid }, notify);
56749
56961
 
56750
- this.update(false);
56962
+ this.update(this.updateMarker);
56751
56963
  };
56752
56964
 
56753
56965
  /**
@@ -56770,7 +56982,7 @@ class Viewer {
56770
56982
 
56771
56983
  this.checkChanges({ grid: this.gridHelper.grid }, notify);
56772
56984
 
56773
- this.update(false);
56985
+ this.update(this.updateMarker);
56774
56986
  };
56775
56987
 
56776
56988
  /**
@@ -56795,7 +57007,7 @@ class Viewer {
56795
57007
 
56796
57008
  this.checkChanges({ axes0: flag }, notify);
56797
57009
 
56798
- this.update(false);
57010
+ this.update(this.updateMarker);
56799
57011
  };
56800
57012
 
56801
57013
  /**
@@ -56819,7 +57031,7 @@ class Viewer {
56819
57031
 
56820
57032
  this.checkChanges({ transparent: flag }, notify);
56821
57033
 
56822
- this.update(false);
57034
+ this.update(this.updateMarker);
56823
57035
  };
56824
57036
 
56825
57037
  /**
@@ -56843,7 +57055,7 @@ class Viewer {
56843
57055
 
56844
57056
  this.checkChanges({ black_edges: flag }, notify);
56845
57057
 
56846
- this.update(false);
57058
+ this.update(this.updateMarker);
56847
57059
  };
56848
57060
 
56849
57061
  /**
@@ -56934,7 +57146,27 @@ class Viewer {
56934
57146
  setEdgeColor = (color, notify = true) => {
56935
57147
  this.edgeColor = color;
56936
57148
  this.nestedGroup.setEdgeColor(color);
56937
- this.update(false, notify);
57149
+ this.update(this.updateMarker, notify);
57150
+ };
57151
+
57152
+ /**
57153
+ * Get default opacity.
57154
+ * @returns {number} opacity value.
57155
+ **/
57156
+ getOpacity() {
57157
+ return this.defaultOpacity;
57158
+ }
57159
+
57160
+ /**
57161
+ * Set the default opacity
57162
+ * @function
57163
+ * @param {number} opacity (between 0.0 and 1.0)
57164
+ * @param {boolean} [notify=true] - whether to send notification or not.
57165
+ */
57166
+ setOpacity = (opacity, notify = true) => {
57167
+ this.defaultOpacity = opacity;
57168
+ this.nestedGroup.setOpacity(opacity);
57169
+ this.update(this.updateMarker, notify);
56938
57170
  };
56939
57171
 
56940
57172
  /**
@@ -56954,7 +57186,7 @@ class Viewer {
56954
57186
  setTools = (flag, notify = true) => {
56955
57187
  this.tools = flag;
56956
57188
  this.display.setTools(flag);
56957
- this.update(false, notify);
57189
+ this.update(this.updateMarker, notify);
56958
57190
  };
56959
57191
 
56960
57192
  /**
@@ -56978,7 +57210,7 @@ class Viewer {
56978
57210
  el.intensity = val;
56979
57211
  }
56980
57212
  }
56981
- this.update(false, notify);
57213
+ this.update(this.updateMarker, notify);
56982
57214
  };
56983
57215
 
56984
57216
  /**
@@ -57001,7 +57233,7 @@ class Viewer {
57001
57233
  el.intensity = val;
57002
57234
  }
57003
57235
  }
57004
- this.update(false, notify);
57236
+ this.update(this.updateMarker, notify);
57005
57237
  };
57006
57238
 
57007
57239
  /**
@@ -57103,13 +57335,15 @@ class Viewer {
57103
57335
  * @param {boolean} [notify=true] - whether to send notification or not.
57104
57336
  */
57105
57337
  setClipIntersection = (flag, notify = true) => {
57338
+ if (flag == null) return;
57339
+
57106
57340
  this.clipIntersection = flag;
57107
57341
  this.nestedGroup.setClipIntersection(flag);
57108
57342
  this.display.setClipIntersectionCheck(flag);
57109
57343
 
57110
57344
  this.checkChanges({ clip_intersection: flag }, notify);
57111
57345
 
57112
- this.update(false);
57346
+ this.update(this.updateMarker);
57113
57347
  };
57114
57348
 
57115
57349
  /**
@@ -57120,6 +57354,17 @@ class Viewer {
57120
57354
  return this.clipPlaneHelpers;
57121
57355
  }
57122
57356
 
57357
+ /**
57358
+ * Set clip plane helpers check box
57359
+ * @function
57360
+ * @param {boolean} flag - whether to show clip plane helpers
57361
+ */
57362
+ setClipPlaneHelpersCheck(flag) {
57363
+ if (flag == null) return;
57364
+
57365
+ this.display.setClipPlaneHelpersCheck(flag);
57366
+ }
57367
+
57123
57368
  /**
57124
57369
  * Show/hide clip plane helpers
57125
57370
  * @function
@@ -57127,13 +57372,14 @@ class Viewer {
57127
57372
  * @param {boolean} [notify=true] - whether to send notification or not.
57128
57373
  */
57129
57374
  setClipPlaneHelpers = (flag, notify = true) => {
57375
+ if (flag == null) return;
57376
+
57130
57377
  this.clipPlaneHelpers = flag;
57131
57378
  this.clipping.planeHelpers.visible = flag;
57132
- this.display.setClipPlaneHelpersCheck(flag);
57133
57379
 
57134
57380
  this.checkChanges({ clip_planes: flag }, notify);
57135
57381
 
57136
- this.update(false);
57382
+ this.update(this.updateMarker);
57137
57383
  };
57138
57384
 
57139
57385
  /**
@@ -57142,7 +57388,7 @@ class Viewer {
57142
57388
  * @returns {boolean} clip plane visibility value.
57143
57389
  **/
57144
57390
  getClipNormal(index) {
57145
- return this.clipNormal[index];
57391
+ return this.clipNormals[index];
57146
57392
  }
57147
57393
 
57148
57394
  /**
@@ -57153,7 +57399,9 @@ class Viewer {
57153
57399
  * @param {boolean} [notify=true] - whether to send notification or not.
57154
57400
  */
57155
57401
  setClipNormal(index, normal, notify = true) {
57156
- this.clipNormal[index] = normal;
57402
+ if (normal == null) return;
57403
+
57404
+ this.clipNormals[index] = normal;
57157
57405
 
57158
57406
  this.clipping.setNormal(index, new Vector3(...normal));
57159
57407
  var notifyObject = {};
@@ -57162,7 +57410,8 @@ class Viewer {
57162
57410
  this.checkChanges(notifyObject, notify);
57163
57411
 
57164
57412
  this.nestedGroup.setClipPlanes(this.clipping.clipPlanes);
57165
- this.update(false);
57413
+
57414
+ this.update(this.updateMarker);
57166
57415
  }
57167
57416
 
57168
57417
  /**
@@ -57199,11 +57448,51 @@ class Viewer {
57199
57448
  * @param {boolean} [notify=true] - whether to send notification or not.
57200
57449
  */
57201
57450
  setClipSlider = (index, value, notify = true) => {
57451
+ if (value == -1 || value == null) return;
57452
+
57202
57453
  this.display.clipSliders[index].setValue(value, notify);
57203
- // var notifyObject = {};
57204
- // notifyObject[`clip_slider_${index}`] = value;
57454
+ };
57455
+
57456
+ /**
57457
+ * Get reset location value.
57458
+ * @function
57459
+ * @returns {object} - target, position, quaternion, zoom as object.
57460
+ */
57461
+ getResetLocation = () => {
57462
+ const location = this.controls.getResetLocation();
57463
+ return {
57464
+ target0: location.target0.toArray(),
57465
+ position0: location.position0.toArray(),
57466
+ quaternion0: location.quaternion0.toArray(),
57467
+ zoom0: location.zoom0,
57468
+ };
57469
+ };
57205
57470
 
57206
- // this.checkChanges(notifyObject, notify);
57471
+ /**
57472
+ * Set reset location value.
57473
+ * @function
57474
+ * @param {number[]} target - camera target as 3 dim Array [x,y,z].
57475
+ * @param {number[]} position - camera position as 3 dim Array [x,y,z].
57476
+ * @param {number[]} quaternion - camera rotation as 4 dim quaternion array [x,y,z,w].
57477
+ * @param {number} zoom - camera zoom value.
57478
+ * @param {boolean} [notify=true] - whether to send notification or not.
57479
+ */
57480
+ setResetLocation = (target, position, quaternion, zoom, notify = true) => {
57481
+ var location = this.getResetLocation();
57482
+ this.controls.setResetLocation(
57483
+ new Vector3(...target),
57484
+ new Vector3(...position),
57485
+ new Vector4(...quaternion),
57486
+ zoom,
57487
+ );
57488
+ if (notify && this.notifyCallback) {
57489
+ this.notifyCallback({
57490
+ target0: { old: location.target0, new: target },
57491
+ position0: { old: location.position0, new: position },
57492
+ quaternion0: { old: location.quaternion0, new: quaternion },
57493
+ zoom0: { old: location.zoom0, new: zoom },
57494
+ });
57495
+ }
57207
57496
  };
57208
57497
 
57209
57498
  /**
@@ -57236,7 +57525,7 @@ class Viewer {
57236
57525
  scope.pinAsPngCallback(image);
57237
57526
  }
57238
57527
  },
57239
- false
57528
+ false,
57240
57529
  );
57241
57530
  reader.readAsDataURL(blob);
57242
57531
  });