three-cad-viewer 1.6.0 → 1.6.1

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.
@@ -30,6 +30,9 @@
30
30
  --tcv-scrollbar-thumb: rgba(255, 255, 255, 0.2);
31
31
  }
32
32
 
33
+ .tcv_none {
34
+ display: none;
35
+ }
33
36
  canvas {
34
37
  outline: none !important;
35
38
  }
@@ -30,6 +30,9 @@
30
30
  --tcv-scrollbar-thumb: rgba(255, 255, 255, 0.2);
31
31
  }
32
32
 
33
+ .tcv_none {
34
+ display: none;
35
+ }
33
36
  canvas {
34
37
  outline: none !important;
35
38
  }
@@ -51284,8 +51284,7 @@ function getIconBackground(theme, name) {
51284
51284
  return `url(data:image/svg+xml;utf8,${escape(icons[name][theme])});`;
51285
51285
  }
51286
51286
 
51287
- function TEMPLATE(id, more) {
51288
- const tag = more ? "div" : "span";
51287
+ function TEMPLATE(id) {
51289
51288
 
51290
51289
  var html = `
51291
51290
  <div class="tcv_cad_viewer">
@@ -51346,29 +51345,27 @@ function TEMPLATE(id, more) {
51346
51345
  </span>
51347
51346
  <span class="tcv_tooltip" data-tooltip="Switch to right view">
51348
51347
  <input class='tcv_right tcv_btn' type="button" />
51349
- </span>`;
51350
-
51351
- html += more ? `<div class="tcv_more-dropdown">
51348
+ </span>
51349
+ <div class="tcv_more-dropdown">
51352
51350
  <button class="tcv_more-btn">More<span class="tcv_more_icon">\u25BC</span></button>
51353
- <div class="tcv_more-content tcv_dropdown-content">` : "";
51354
-
51355
- html += ` <${tag} class="tcv_tooltip" data-tooltip="Toggle transparent objects">
51351
+ <span class="tcv_more-wrapper tcv_more-content tcv_dropdown-content">
51352
+ <span class="tcv_more_check" class="tcv_tooltip" data-tooltip="Toggle transparent objects">
51356
51353
  <input class='tcv_transparent tcv_check tcv_dropdown-entry' id='tcv_transparent_${id}' type="checkbox" />
51357
51354
  <label for='tcv_transparent_${id}' class="tcv_label tcv_dropdown-entry">Transparent</label>
51358
- </${tag}>
51359
- <${tag} class="tcv_tooltip" data-tooltip="Toggle black edges">
51355
+ </span class="tcv_more_check">
51356
+ <span class="tcv_more_check" class="tcv_tooltip" data-tooltip="Toggle black edges">
51360
51357
  <input class='tcv_black_edges tcv_check tcv_dropdown-entry' id='tcv_black_edges_${id}' type="checkbox" />
51361
51358
  <label for='tcv_black_edges_${id}' class="tcv_label tcv_dropdown-entry">Black edges</label>
51362
- </${tag}>
51363
- <${tag} class="tcv_explode_widget tcv_tooltip"
51359
+ </span class="tcv_more_check">
51360
+ <span class="tcv_more_check" class="tcv_explode_widget tcv_tooltip"
51364
51361
  data-tooltip="Explode assembly (@0 determines explosion center)">
51365
51362
  <input class='tcv_explode tcv_check tcv_dropdown-entry' id='tcv_explode_${id}' type="checkbox" />
51366
51363
  <label for='tcv_explode_${id}' class="tcv_label tcv_dropdown-entry">Explode</label>
51367
- </${tag}>`;
51368
- html += more ? `</div>
51369
- </div>` : "";
51364
+ </span class="tcv_more_check">
51365
+ </span>
51366
+ </div>
51370
51367
 
51371
- html += `<span class="tcv_align_right">
51368
+ <span class="tcv_align_right">
51372
51369
  <span class="tcv_tooltip" data-tooltip="Toggle help">
51373
51370
  <input class='tcv_help tcv_btn' type="button" />
51374
51371
  </span>
@@ -51656,8 +51653,9 @@ class Display {
51656
51653
  constructor(container, options) {
51657
51654
  this.container = container;
51658
51655
 
51656
+ this.container.innerHTML = TEMPLATE(this.container.id);
51659
51657
  const fullWidth = options.cadWidth + (options.glass ? 0 : options.treeWidth);
51660
- this.container.innerHTML = TEMPLATE(this.container.id, fullWidth < 950);
51658
+ this.handleMoreButton(fullWidth);
51661
51659
  this.cadBody = this._getElement("tcv_cad_body");
51662
51660
  this.cadTool = this._getElement("tcv_cad_toolbar");
51663
51661
  this.cadView = this._getElement("tcv_cad_view");
@@ -51756,6 +51754,24 @@ class Display {
51756
51754
  this.container.innerHTML = "";
51757
51755
  }
51758
51756
 
51757
+ /**
51758
+ * Use More fropdown if overall width < 970px else just check boxes
51759
+ * @param {number} fullWidth - overall width of tree and cad view (taking glass mode into account)
51760
+ */
51761
+ handleMoreButton(fullWidth) {
51762
+ const moreButton = this._getElement("tcv_more-btn");
51763
+ const moreContent = this._getElement("tcv_more-wrapper");
51764
+ if (fullWidth < 970) {
51765
+ moreButton.classList.remove("tcv_none");
51766
+ moreContent.classList.add("tcv_dropdown-content");
51767
+ moreContent.classList.add("tcv_more-content");
51768
+ } else {
51769
+ moreButton.classList.add("tcv_none");
51770
+ moreContent.classList.remove("tcv_dropdown-content");
51771
+ moreContent.classList.remove("tcv_more-content");
51772
+ }
51773
+ }
51774
+
51759
51775
  /**
51760
51776
  * Set the width and height of the different UI elements (tree, canvas and info box)
51761
51777
  * @param {DisplayOptions} options
@@ -52181,7 +52197,10 @@ class Display {
52181
52197
  this.viewer.resize();
52182
52198
  };
52183
52199
 
52184
- clearHighlights() {
52200
+ /**
52201
+ * Clear all highlights of navigation tree entries
52202
+ */
52203
+ clearHighlights() {
52185
52204
  const buttons = [
52186
52205
  "tcv_front",
52187
52206
  "tcv_rear",
@@ -52197,6 +52216,10 @@ class Display {
52197
52216
  });
52198
52217
  }
52199
52218
 
52219
+ /**
52220
+ * Highlight the selected navigation tree entry
52221
+ * @param {string} name - A CAD object id (path)
52222
+ */
52200
52223
  highlightButton(name) {
52201
52224
  this.clearHighlights();
52202
52225
  var el = this._getElement(`tcv_${name}`);
@@ -52402,9 +52425,15 @@ class Display {
52402
52425
  */
52403
52426
  animationChange = (e) => {
52404
52427
  this.viewer.animation.setRelativeTime(e.target.valueAsNumber / 1000);
52405
- this.viewer.lastBbox.needsUpdate = true;
52428
+ if(this.viewer.lastBbox != null){
52429
+ this.viewer.lastBbox.needsUpdate = true;
52430
+ }
52406
52431
  };
52407
52432
 
52433
+ /**
52434
+ * Set label text of animation control
52435
+ * @param {string} label - "A" for animation and "E" for Explode control
52436
+ */
52408
52437
  setAnimationLabel(label) {
52409
52438
  var el = this._getElement("tcv_animation_label");
52410
52439
  el.innerHTML = label;
@@ -52513,6 +52542,9 @@ class Display {
52513
52542
  treeWidth: flag ? 0 : this.treeWidth,
52514
52543
  };
52515
52544
  this.setSizes(options);
52545
+
52546
+ const fullWidth = this.cadWidth + (this.glass ? 0 : this.treeWidth);
52547
+ this.handleMoreButton(fullWidth);
52516
52548
  }
52517
52549
  }
52518
52550
 
@@ -53842,7 +53874,8 @@ class BoundingBox extends Box3 {
53842
53874
  expandByObject(object, precise = false) {
53843
53875
  object.updateWorldMatrix(false, false);
53844
53876
 
53845
- if (object instanceof ObjectGroup) {
53877
+ // don't use instanceof => circular dependencies with bbox.js
53878
+ if (object.constructor.name == "ObjectGroup") {
53846
53879
  // for ObjectGroups calculate bounding box of first Mesh only
53847
53880
  this.expandByObject(object.children[0], precise);
53848
53881
  return this;
@@ -57607,9 +57640,24 @@ class Camera {
57607
57640
  getRotation() {
57608
57641
  return this.camera.rotation;
57609
57642
  }
57643
+
57644
+ changeDimensions(distance, width, height) {
57645
+ const aspect = width / height;
57646
+ const w = distance * 1.35;
57647
+ const h = (distance * 1.35) / aspect;
57648
+
57649
+ this.oCamera.left = -w;
57650
+ this.oCamera.right = w;
57651
+ this.oCamera.top = h;
57652
+ this.oCamera.bottom = -h;
57653
+
57654
+ this.pCamera.aspect = aspect;
57655
+
57656
+ this.camera.updateProjectionMatrix();
57657
+ }
57610
57658
  }
57611
57659
 
57612
- const version="1.6.0";
57660
+ const version="1.6.1";
57613
57661
 
57614
57662
  class Viewer {
57615
57663
  /**
@@ -59508,31 +59556,36 @@ class Viewer {
59508
59556
  }
59509
59557
  }
59510
59558
 
59511
- //
59512
- // DOESN'T WORK DUE TO CAMERA CANNOT BE CHANGED EASILY
59513
- //
59514
- // /**
59515
- // * Resize cadWidth, treeWidth and height of thew viewer
59516
- // *
59517
- // * @param {cadWidth} tags - e.g. ["axes", "axes0", "grid", "ortho", "more", "help"]
59518
- // * @param {treeWidth} flag - whether to turn on or off the UI elements.
59519
- // * @param {height} flag - whether to turn on or off the UI elements.
59520
- // */
59521
- // resetUISize(cadWidth, treeWidth, height) {
59522
- // this.cadWidth = cadWidth;
59523
- // this.treeWidth = treeWidth;
59524
- // this.height = height;
59525
- // this.display.setSizes({
59526
- // cadWidth: cadWidth,
59527
- // treeWidth: treeWidth,
59528
- // height: height,
59529
- // tools: this.tools,
59530
- // glass: this.glass,
59531
- // });
59532
- // this.display.autoCollapse();
59533
- // this.renderer.setSize(cadWidth, height);
59534
- // this.update(true);
59535
- // }
59559
+ /**
59560
+ * Resize UI and renderer
59561
+ *
59562
+ * @param {number} cadWidth - new width of CAD View
59563
+ * @param {number} treeWidth - new width of navigation tree
59564
+ * @param {number} height - new height of CAD View
59565
+ * @param {boolean} [glass=false] - Whether to use glass mode or not
59566
+ */
59567
+ resizeCadView(cadWidth, treeWidth, height, glass=false) {
59568
+ this.cadWidth = cadWidth;
59569
+ this.height = height;
59570
+
59571
+ // Adapt renderer dimensions
59572
+ this.renderer.setSize(cadWidth, height);
59573
+
59574
+ // Adapt display dimensions
59575
+ this.display.setSizes({"treeWidth": treeWidth, "cadWidth": cadWidth, "height": height});
59576
+ this.display.cadView.children[2].style.width = `${cadWidth}px`;
59577
+ this.display.cadView.children[2].style.height = `${height}px`;
59578
+ this.display.glassMode(glass);
59579
+
59580
+ const fullWidth = cadWidth + (glass ? 0 : treeWidth);
59581
+ this.display.handleMoreButton(fullWidth);
59582
+
59583
+ // Adapt camers to new dimensions
59584
+ this.camera.changeDimensions(this.bb_radius, cadWidth, height);
59585
+
59586
+ // update the this
59587
+ this.update(true);
59588
+ }
59536
59589
  }
59537
59590
 
59538
59591
  export { Display, Timer, Viewer };
@@ -30,6 +30,9 @@
30
30
  --tcv-scrollbar-thumb: rgba(255, 255, 255, 0.2);
31
31
  }
32
32
 
33
+ .tcv_none {
34
+ display: none;
35
+ }
33
36
  canvas {
34
37
  outline: none !important;
35
38
  }