three-cad-viewer 1.5.6 → 1.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -117,3 +117,18 @@ yarn run start
117
117
  ```
118
118
 
119
119
  For the deployment, see [Release.md](./Release.md)
120
+
121
+ # Changes
122
+
123
+ v1.5.7
124
+
125
+ - fixed ids of checkboxes to be unique across the document
126
+
127
+ v1.5.8
128
+
129
+ - fixed glass and tools paramewter handling
130
+ - fixed initial zoom for wide cad views with low height
131
+
132
+ v1.5.9
133
+
134
+ - fixed a regression from v1.5.8 around initial zoom value handling)
@@ -51284,37 +51284,38 @@ function getIconBackground(theme, name) {
51284
51284
  return `url(data:image/svg+xml;utf8,${escape(icons[name][theme])});`;
51285
51285
  }
51286
51286
 
51287
- const TEMPLATE = `
51287
+ function TEMPLATE(id) {
51288
+ return `
51288
51289
  <div class="tcv_cad_viewer">
51289
51290
  <div class="tcv_cad_toolbar tcv_round">
51290
51291
  <span class="tcv_tooltip" data-tooltip="Show coordinate axis">
51291
- <input class='tcv_axes tcv_check' id='tcv_axes' type="checkbox" />
51292
- <label for='tcv_axes' class="tcv_label">Axes</label>
51292
+ <input class='tcv_axes tcv_check' id='tcv_axes_${id}' type="checkbox" />
51293
+ <label for='tcv_axes_${id}' class="tcv_label">Axes</label>
51293
51294
  </span>
51294
51295
  <div class="tcv_grid-dropdown">
51295
51296
  <input class='tcv_grid tcv_check' id='tcv_grid' type="checkbox" /><label for='tcv_grid'
51296
51297
  class="tcv_label">Grid</label>
51297
51298
  <div class="tcv_grid-content tcv_dropdown-content">
51298
51299
  <div class="tcv_tooltip" data-tooltip="Show xy grid">
51299
- <input class='tcv_grid-xy tcv_check tcv_dropdown-entry' id='tcv_grid-xy' type="checkbox">
51300
- <label for='tcv_grid-xy' class="tcv_label tcv_dropdown-entry">xy</label>
51300
+ <input class='tcv_grid-xy tcv_check tcv_dropdown-entry' id='tcv_grid-xy_${id}' type="checkbox">
51301
+ <label for='tcv_grid-xy_${id}' class="tcv_label tcv_dropdown-entry">xy</label>
51301
51302
  </div>
51302
51303
  <div class="tcv_tooltip" data-tooltip="Show xz grid">
51303
- <input class='tcv_grid-xz tcv_check tcv_dropdown-entry' id='tcv_grid-xz' type="checkbox">
51304
- <label for='tcv_grid-xz' class="tcv_label tcv_dropdown-entry">xz</label>
51304
+ <input class='tcv_grid-xz tcv_check tcv_dropdown-entry' id='tcv_grid-xz_${id}' type="checkbox">
51305
+ <label for='tcv_grid-xz_${id}' class="tcv_label tcv_dropdown-entry">xz</label>
51305
51306
  </div>
51306
51307
  <div class="tcv_tooltip" data-tooltip="Show yz grid">
51307
- <input class='tcv_grid-yz tcv_check tcv_dropdown-entry' id='tcv_grid-yz' type="checkbox">
51308
- <label for='tcv_grid-yz' class="tcv_label tcv_dropdown-entry">yz</label>
51308
+ <input class='tcv_grid-yz tcv_check tcv_dropdown-entry' id='tcv_grid-yz_${id}' type="checkbox">
51309
+ <label for='tcv_grid-yz_${id}' class="tcv_label tcv_dropdown-entry">yz</label>
51309
51310
  </div>
51310
51311
  </div>
51311
51312
  </div>
51312
51313
  <span class="tcv_tooltip" data-tooltip="Move center of axis and grid to (0,0,0)">
51313
- <input class='tcv_axes0 tcv_check' id='tcv_axes0' type="checkbox" /><label for='tcv_axes0'
51314
+ <input class='tcv_axes0 tcv_check' id='tcv_axes0_${id}' type="checkbox" /><label for='tcv_axes0_${id}'
51314
51315
  class="tcv_label">@0</label>
51315
51316
  </span>
51316
51317
  <span class="tcv_tooltip" data-tooltip="Toggle camera between orthographic and perspective view">
51317
- <input class='tcv_ortho tcv_check' id='tcv_ortho' type="checkbox" /><label for='tcv_ortho'
51318
+ <input class='tcv_ortho tcv_check' id='tcv_ortho_${id}' type="checkbox" /><label for='tcv_ortho_${id}'
51318
51319
  class="tcv_label">Ortho</label>
51319
51320
  </span>
51320
51321
  <span class="tcv_tooltip" data-tooltip="Reset view">
@@ -51348,17 +51349,17 @@ const TEMPLATE = `
51348
51349
  <button class="tcv_more-btn">More<span class="tcv_more_icon">\u25BC</span></button>
51349
51350
  <div class="tcv_more-content tcv_dropdown-content">
51350
51351
  <div class="tcv_tooltip" data-tooltip="Toggle transparent objects">
51351
- <input class='tcv_transparent tcv_check tcv_dropdown-entry' id='tcv_transparent' type="checkbox" />
51352
- <label for='tcv_transparent' class="tcv_label tcv_dropdown-entry">Transparent</label>
51352
+ <input class='tcv_transparent tcv_check tcv_dropdown-entry' id='tcv_transparent_${id}' type="checkbox" />
51353
+ <label for='tcv_transparent_${id}' class="tcv_label tcv_dropdown-entry">Transparent</label>
51353
51354
  </div>
51354
51355
  <div class="tcv_tooltip" data-tooltip="Toggle black edges">
51355
- <input class='tcv_black_edges tcv_check tcv_dropdown-entry' id='tcv_black_edges' type="checkbox" />
51356
- <label for='tcv_black_edges' class="tcv_label tcv_dropdown-entry">Black edges</label>
51356
+ <input class='tcv_black_edges tcv_check tcv_dropdown-entry' id='tcv_black_edges_${id}' type="checkbox" />
51357
+ <label for='tcv_black_edges_${id}' class="tcv_label tcv_dropdown-entry">Black edges</label>
51357
51358
  </div>
51358
51359
  <div class="tcv_explode_widget tcv_tooltip"
51359
51360
  data-tooltip="Explode assembly (@0 determines explosion center)">
51360
- <input class='tcv_explode tcv_check tcv_dropdown-entry' id='tcv_explode' type="checkbox" />
51361
- <label for='tcv_explode' class="tcv_label tcv_dropdown-entry">Explode</label>
51361
+ <input class='tcv_explode tcv_check tcv_dropdown-entry' id='tcv_explode_${id}' type="checkbox" />
51362
+ <label for='tcv_explode_${id}' class="tcv_label tcv_dropdown-entry">Explode</label>
51362
51363
  </div>
51363
51364
  </div>
51364
51365
  </div>
@@ -51535,6 +51536,7 @@ const TEMPLATE = `
51535
51536
  </div>
51536
51537
  </div>
51537
51538
  `;
51539
+ }
51538
51540
 
51539
51541
  function px(val) {
51540
51542
  return `${val}px`;
@@ -51636,7 +51638,7 @@ class Display {
51636
51638
  constructor(container, options) {
51637
51639
  this.container = container;
51638
51640
 
51639
- this.container.innerHTML = TEMPLATE;
51641
+ this.container.innerHTML = TEMPLATE(this.container.id);
51640
51642
  this.cadBody = this._getElement("tcv_cad_body");
51641
51643
  this.cadTool = this._getElement("tcv_cad_toolbar");
51642
51644
  this.cadView = this._getElement("tcv_cad_view");
@@ -51656,15 +51658,14 @@ class Display {
51656
51658
  }
51657
51659
 
51658
51660
  this.viewer = null;
51659
- this._glassMode = false;
51660
- this.tools = true;
51661
- this._events = [];
51661
+ this.glass = options.glass;
51662
+ this.tools = options.tools;
51662
51663
  this.cadWidth = options.cadWidth;
51663
51664
  this.height = options.height;
51664
51665
  this.treeWidth = options.treeWidth;
51665
51666
 
51666
- this.showTools(options.tools);
51667
- this.glassMode(options.glass);
51667
+ this._events = [];
51668
+
51668
51669
  this.setSizes(options);
51669
51670
 
51670
51671
  this.activeTab = "tree";
@@ -51829,7 +51830,7 @@ class Display {
51829
51830
  this._setupClickEvent("tcv_pin", this.pinAsPng);
51830
51831
  this._setupClickEvent("tcv_help", this.toggleHelp);
51831
51832
  this.help_shown = true;
51832
- this.info_shown = !this._glassMode;
51833
+ this.info_shown = !this.glass;
51833
51834
 
51834
51835
  const tabs = ["tcv_tab_tree", "tcv_tab_clip"];
51835
51836
  tabs.forEach((name) => {
@@ -51880,15 +51881,18 @@ class Display {
51880
51881
  * @property {boolean} [ortho = true] - use an orthographic (true) or perspective camera (false)
51881
51882
  * @property {boolean} [transparent = false] - show CAD object transparent.
51882
51883
  * @property {boolean} [blackEdges = false] - show edges in black and not in edgeColor.
51883
- * @property {boolean} [clipIntersection = false] - use intersection clipping
51884
- * @property {boolean} [clipPlaneHelpers = false] - show clipping planes
51884
+ * @property {boolean} [tools = true] - show CAD tools.
51885
+ * @property {boolean} [glass = false] - use glass mode, i.e. CAD navigation as overlay.
51885
51886
  */
51886
- updateUI(axes, axes0, ortho, transparent, blackEdges) {
51887
+ updateUI(axes, axes0, ortho, transparent, blackEdges, tools, glass) {
51887
51888
  this.checkElement("tcv_axes", axes);
51888
51889
  this.checkElement("tcv_axes0", axes0);
51889
51890
  this.checkElement("tcv_ortho", ortho);
51890
51891
  this.checkElement("tcv_transparent", transparent);
51891
51892
  this.checkElement("tcv_black_edges", blackEdges);
51893
+
51894
+ this.showTools(tools);
51895
+ this.glassMode(glass);
51892
51896
  }
51893
51897
  // setup functions
51894
51898
 
@@ -52104,6 +52108,10 @@ class Display {
52104
52108
  */
52105
52109
  showTools = (flag) => {
52106
52110
  this.tools = flag;
52111
+ if (this.viewer) {
52112
+ // not available at first call
52113
+ this.viewer.tools = flag;
52114
+ }
52107
52115
  var tb = this._getElement("tcv_cad_toolbar");
52108
52116
  var cn = this._getElement("tcv_cad_navigation");
52109
52117
  for (var el of [cn, tb]) {
@@ -52416,6 +52424,18 @@ class Display {
52416
52424
  this.showInfo(!this.info_shown);
52417
52425
  };
52418
52426
 
52427
+ /**
52428
+ * Auto collapse tree nodes, when cad width < 600
52429
+ * @function
52430
+ * @param {boolean} flag - whether to enable/disable glass mode
52431
+ */
52432
+ autoCollapse() {
52433
+ if (this.cadWidth < 600 && this.glass) {
52434
+ console.info("Small view, collapsing tree");
52435
+ this.collapseNodes("C");
52436
+ }
52437
+ }
52438
+
52419
52439
  /**
52420
52440
  * Enable/disable glass mode
52421
52441
  * @function
@@ -52435,7 +52455,8 @@ class Display {
52435
52455
  this._getElement("tcv_toggle_info_wrapper").style.display = "block";
52436
52456
 
52437
52457
  this.showInfo(false);
52438
- this._glassMode = true;
52458
+ this.glass = true;
52459
+ this.autoCollapse();
52439
52460
  } else {
52440
52461
  this._getElement("tcv_cad_tree").classList.remove("tcv_cad_tree_glass");
52441
52462
  this._getElement("tcv_cad_tree").style["max-height"] = null;
@@ -52448,14 +52469,18 @@ class Display {
52448
52469
  this._getElement("tcv_toggle_info_wrapper").style.display = "none";
52449
52470
 
52450
52471
  this.showInfo(true);
52451
- this._glassMode = false;
52472
+ this.glass = false;
52473
+ }
52474
+ if (this.viewer) {
52475
+ // not available at first call
52476
+ this.viewer.glass = false;
52452
52477
  }
52453
52478
  const options = {
52454
52479
  cadWidth: this.cadWidth,
52455
- glass: this._glassMode,
52480
+ glass: this.glass,
52456
52481
  height: this.height,
52457
52482
  tools: this.tools,
52458
- treeWidth: (flag) ? 0 : this.treeWidth
52483
+ treeWidth: flag ? 0 : this.treeWidth,
52459
52484
  };
52460
52485
  this.setSizes(options);
52461
52486
  }
@@ -57005,6 +57030,13 @@ class Controls {
57005
57030
  return this.controls.target;
57006
57031
  }
57007
57032
 
57033
+ /**
57034
+ * Get the initial zoom value of the camera.
57035
+ **/
57036
+ getZoom0() {
57037
+ return this.controls.zoom0;
57038
+ }
57039
+
57008
57040
  /**
57009
57041
  * Get the lookAt target of the camera.
57010
57042
  * @param {number[]} target - camera target as THREE.Vector3.
@@ -57389,7 +57421,6 @@ class Viewer {
57389
57421
  this.hasAnimationLoop = false;
57390
57422
 
57391
57423
  this.setDisplayDefaults(options);
57392
- this.theme = options.theme;
57393
57424
 
57394
57425
  this.display = new Display(container, {
57395
57426
  theme: this.theme,
@@ -57521,16 +57552,17 @@ class Viewer {
57521
57552
  this.clipSlider0 = -1;
57522
57553
  this.clipSlider1 = -1;
57523
57554
  this.clipSlider2 = -1;
57524
- this.tools = true;
57525
57555
  this.control = "orbit";
57526
- this.glass = false;
57527
57556
  this.ticks = 10;
57528
57557
 
57529
57558
  this.position = null;
57530
57559
  this.quaternion = null;
57531
57560
  this.target = null;
57532
- this.zoom = null;
57533
- this.zoom0 = 1.0;
57561
+
57562
+ this.zoom = 4 / 3;
57563
+ if (this.cadWidth >= this.height) {
57564
+ this.zoom *= this.height / this.cadWidth;
57565
+ }
57534
57566
 
57535
57567
  this.panSpeed = 0.5;
57536
57568
  this.rotateSpeed = 1.0;
@@ -57587,7 +57619,7 @@ class Viewer {
57587
57619
  console.log("- glass", this.glass);
57588
57620
  console.log("- transparent", this.transparent);
57589
57621
  console.log("- zoom", this.zoom);
57590
- console.log("- zoom0", this.zoom0);
57622
+ console.log("- zoom0", this.controls.getZoom0());
57591
57623
  console.log("- zoomSpeed", this.zoomSpeed);
57592
57624
  }
57593
57625
  // - - - - - - - - - - - - - - - - - - - - - - - -
@@ -57991,10 +58023,10 @@ class Viewer {
57991
58023
 
57992
58024
  // this needs to happen after the controls have been established
57993
58025
  if (options.position == null && options.quaternion == null) {
57994
- this.presetCamera("iso", options.zoom);
58026
+ this.presetCamera("iso", this.zoom);
57995
58027
  this.display.highlightButton("iso");
57996
58028
  } else if (options.position != null) {
57997
- this.setCamera(false, options.position, options.quaternion, options.zoom);
58029
+ this.setCamera(false, options.position, options.quaternion, this.zoom);
57998
58030
  if (options.quaternion == null) {
57999
58031
  this.camera.lookAtTarget();
58000
58032
  }
@@ -58002,7 +58034,7 @@ class Viewer {
58002
58034
  this.info.addHtml(
58003
58035
  "<b>quaternion needs position to be provided, falling back to ISO view</b>",
58004
58036
  );
58005
- this.presetCamera("iso", options.zoom);
58037
+ this.presetCamera("iso", this.zoom);
58006
58038
  }
58007
58039
  this.controls.update();
58008
58040
 
@@ -58143,12 +58175,11 @@ class Viewer {
58143
58175
  this.ortho,
58144
58176
  this.transparent,
58145
58177
  this.blackEdges,
58178
+ this.tools,
58179
+ this.glass,
58146
58180
  );
58147
58181
 
58148
- if (this.cadWidth < 600 && this.display._glassMode) {
58149
- console.info("Small view, collapsing tree");
58150
- this.display.collapseNodes("C");
58151
- }
58182
+ this.display.autoCollapse();
58152
58183
 
58153
58184
  //
58154
58185
  // show the rendering
@@ -58246,7 +58277,7 @@ class Viewer {
58246
58277
  * @function
58247
58278
  */
58248
58279
  resize = () => {
58249
- this.camera.setZoom(this.zoom0);
58280
+ this.camera.setZoom(this.controls.getZoom0());
58250
58281
  this.camera.updateProjectionMatrix();
58251
58282
  this.update(true);
58252
58283
  };
@@ -59082,6 +59113,13 @@ class Viewer {
59082
59113
  });
59083
59114
  };
59084
59115
 
59116
+ /**
59117
+ * Calculate explode trajectories and initiate the animation
59118
+ *
59119
+ * @param {number} [duration=2] - duration of animation.
59120
+ * @param {number} [speed=1] - speed of animation.
59121
+ * @param {number} [multiplier=2.5] - multiplier for length of trajectories.
59122
+ */
59085
59123
  explode(duration = 2, speed = 1, multiplier = 2.5) {
59086
59124
  this.clearAnimation();
59087
59125
 
@@ -59141,6 +59179,12 @@ class Viewer {
59141
59179
  this.initAnimation(duration, speed, "E", false);
59142
59180
  }
59143
59181
 
59182
+ /**
59183
+ * Calculate explode trajectories and initiate the animation
59184
+ *
59185
+ * @param {string[]} tags - e.g. ["axes", "axes0", "grid", "ortho", "more", "help"]
59186
+ * @param {boolean} flag - whether to turn on or off the UI elements.
59187
+ */
59144
59188
  trimUI(tags, flag) {
59145
59189
  var display = flag ? "inline-block" : "none";
59146
59190
  for (var tag of tags) {
@@ -59159,6 +59203,32 @@ class Viewer {
59159
59203
  }
59160
59204
  }
59161
59205
  }
59206
+
59207
+ //
59208
+ // DOESN'T WORK DUE TO CAMERA CANNOT BE CHANGED EASILY
59209
+ //
59210
+ // /**
59211
+ // * Resize cadWidth, treeWidth and height of thew viewer
59212
+ // *
59213
+ // * @param {cadWidth} tags - e.g. ["axes", "axes0", "grid", "ortho", "more", "help"]
59214
+ // * @param {treeWidth} flag - whether to turn on or off the UI elements.
59215
+ // * @param {height} flag - whether to turn on or off the UI elements.
59216
+ // */
59217
+ // resetUISize(cadWidth, treeWidth, height) {
59218
+ // this.cadWidth = cadWidth;
59219
+ // this.treeWidth = treeWidth;
59220
+ // this.height = height;
59221
+ // this.display.setSizes({
59222
+ // cadWidth: cadWidth,
59223
+ // treeWidth: treeWidth,
59224
+ // height: height,
59225
+ // tools: this.tools,
59226
+ // glass: this.glass,
59227
+ // });
59228
+ // this.display.autoCollapse();
59229
+ // this.renderer.setSize(cadWidth, height);
59230
+ // this.update(true);
59231
+ // }
59162
59232
  }
59163
59233
 
59164
59234
  export { Display, Timer, Viewer };