three-cad-viewer 1.6.4 → 1.7.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.
package/Readme.md CHANGED
@@ -120,15 +120,46 @@ For the deployment, see [Release.md](./Release.md)
120
120
 
121
121
  # Changes
122
122
 
123
- v1.5.7
123
+ v1.7.0
124
124
 
125
- - fixed ids of checkboxes to be unique across the document
125
+ - Changed Z orientation to follow standard CAD programs. The old behaviour can be still used by using uo="L" (legacy)
126
+
127
+ v1.6.4
128
+
129
+ - add support for color alpha channel
130
+
131
+ v1.6.3
132
+
133
+ - Introduce a new parameter "up" that determines whther camera up is Y (up="Y") or Z (up="Z")
134
+
135
+ v1.6.2
136
+
137
+ - Fixed bounding box max_dist_from_center algorithm
138
+
139
+ v1.6.1
140
+
141
+ - Increase minimum width to 970
142
+ - Handle more button in glassMode function
143
+ - Allow resizing after view is created
144
+
145
+ v1.6.0
146
+
147
+ - Disable jupyter cell select on shift mousedown in cad tree
148
+ - Remove bounding box for isolate mode and improve click states
149
+ - Center isolated objects around bounding box center
150
+ - Extend help for picking/hiding/isolating
151
+ - highlight tree node when element picked
152
+ - A new bounding box algorithm (AABB)
153
+
154
+ v1.5.9
155
+
156
+ - fixed a regression from v1.5.8 around initial zoom value handling)
126
157
 
127
158
  v1.5.8
128
159
 
129
160
  - fixed glass and tools paramewter handling
130
161
  - fixed initial zoom for wide cad views with low height
131
162
 
132
- v1.5.9
163
+ v1.5.7
133
164
 
134
- - fixed a regression from v1.5.8 around initial zoom value handling)
165
+ - fixed ids of checkboxes to be unique across the document
@@ -54263,7 +54263,7 @@ class NestedGroup {
54263
54263
  this.edgeColor,
54264
54264
  renderback,
54265
54265
  );
54266
-
54266
+
54267
54267
  if (alpha == null) {
54268
54268
  alpha = 1.0;
54269
54269
  } else if (alpha < 1.0) {
@@ -54296,7 +54296,7 @@ class NestedGroup {
54296
54296
  side: FrontSide,
54297
54297
  visible: states[0] == 1,
54298
54298
  });
54299
-
54299
+
54300
54300
  const backMaterial = new MeshBasicMaterial({
54301
54301
  color: new Color(this.edgeColor),
54302
54302
  side: BackSide,
@@ -54318,7 +54318,7 @@ class NestedGroup {
54318
54318
 
54319
54319
  const back = new Mesh(shapeGeometry, backMaterial);
54320
54320
  back.name = name;
54321
-
54321
+
54322
54322
  // ensure, transparent objects will be rendered at the end
54323
54323
  if (alpha < 1.0) {
54324
54324
  back.renderOrder = 999;
@@ -54381,6 +54381,11 @@ class NestedGroup {
54381
54381
  states[shape.id],
54382
54382
  );
54383
54383
  }
54384
+ // support object locations
54385
+ if (shape.loc != null) {
54386
+ mesh.position.set(...shape.loc[0]);
54387
+ mesh.quaternion.set(...shape.loc[1]);
54388
+ }
54384
54389
  return mesh;
54385
54390
  };
54386
54391
 
@@ -54477,7 +54482,7 @@ class NestedGroup {
54477
54482
  }
54478
54483
 
54479
54484
  class Grid {
54480
- constructor(display, bbox, ticks, axes0, grid) {
54485
+ constructor(display, bbox, ticks, axes0, grid, flipY) {
54481
54486
  if (ticks === undefined) {
54482
54487
  ticks = 10;
54483
54488
  }
@@ -54514,7 +54519,7 @@ class Grid {
54514
54519
  this.gridHelper[1].rotateY(Math.PI / 2);
54515
54520
  this.gridHelper[2].rotateZ(Math.PI / 2);
54516
54521
 
54517
- this.setCenter(axes0);
54522
+ this.setCenter(axes0, flipY);
54518
54523
 
54519
54524
  this.setVisible();
54520
54525
  }
@@ -54610,13 +54615,13 @@ class Grid {
54610
54615
  this.computeGrid();
54611
54616
  }
54612
54617
 
54613
- setCenter(axes0) {
54618
+ setCenter(axes0, flipY) {
54614
54619
  if (axes0) {
54615
54620
  for (var i = 0; i < 3; i++) {
54616
54621
  this.gridHelper[i].position.set(0, 0, 0);
54617
54622
  }
54618
54623
  this.gridHelper[0].position.z = -this.size / 2;
54619
- this.gridHelper[1].position.y = -this.size / 2;
54624
+ this.gridHelper[1].position.y = ((flipY ? 1 : -1) * this.size) / 2;
54620
54625
  this.gridHelper[2].position.x = -this.size / 2;
54621
54626
  } else {
54622
54627
  const c = this.bbox.center();
@@ -54624,7 +54629,7 @@ class Grid {
54624
54629
  this.gridHelper[i].position.set(...c);
54625
54630
  }
54626
54631
  this.gridHelper[0].position.z = -this.size / 2 + c[2];
54627
- this.gridHelper[1].position.y = -this.size / 2 + c[1];
54632
+ this.gridHelper[1].position.y = ((flipY ? 1 : -1) * this.size) / 2 + c[1];
54628
54633
  this.gridHelper[2].position.x = -this.size / 2 + c[0];
54629
54634
  }
54630
54635
  }
@@ -57386,29 +57391,39 @@ class Controls {
57386
57391
  }
57387
57392
 
57388
57393
  const defaultDirections = {
57389
- y_up: {
57390
- iso: new Vector3(1, 1, 1),
57391
- front: new Vector3(0, 0, 1),
57392
- rear: new Vector3(0, 0, -1),
57393
- left: new Vector3(-1, 0, 0), // compatible to fusion 360
57394
- right: new Vector3(1, 0, 0), // compatible to fusion 360
57395
- top: new Vector3(0, 1, 0),
57396
- bottom: new Vector3(0, -1, 0),
57394
+ y_up: { // compatible to fusion 360
57395
+ iso: { pos: new Vector3(1, 1, 1), z_rot: 0 },
57396
+ front: { pos: new Vector3(0, 0, 1), z_rot: 0 },
57397
+ rear: { pos: new Vector3(0, 0, -1), z_rot: 0 },
57398
+ left: { pos: new Vector3(-1, 0, 0), z_rot: 0 },
57399
+ right: { pos: new Vector3(1, 0, 0), z_rot: 0 },
57400
+ top: { pos: new Vector3(0, 1, 0), z_rot: 0 },
57401
+ bottom: { pos: new Vector3(0, -1, 0), z_rot: 0 },
57397
57402
  },
57398
- z_up: {
57399
- iso: new Vector3(1, 1, 1),
57400
- front: new Vector3(1, 0, 0),
57401
- rear: new Vector3(-1, 0, 0),
57402
- left: new Vector3(0, 1, 0),
57403
- right: new Vector3(0, -1, 0),
57404
- top: new Vector3(0, 0, 1),
57405
- bottom: new Vector3(0, 0, -1),
57403
+ z_up: { // compatible to FreeCAD, OnShape
57404
+ iso: { pos: new Vector3(1, -1, 1), z_rot: 0 },
57405
+ front: { pos: new Vector3(0, -1, 0), z_rot: 0 },
57406
+ rear: { pos: new Vector3(0, 1, 0), z_rot: 0 },
57407
+ left: { pos: new Vector3(-1, 0, 0), z_rot: 0 },
57408
+ right: { pos: new Vector3(1, 0, 0), z_rot: 0 },
57409
+ top: { pos: new Vector3(0, 0, 1), z_rot: -Math.PI / 2 },
57410
+ bottom: { pos: new Vector3(0, 0, -1), z_rot: -Math.PI / 2 },
57411
+ },
57412
+ legacy: { // legacy Z up
57413
+ iso: { pos: new Vector3(1, 1, 1), z_rot: 0 },
57414
+ front: { pos: new Vector3(1, 0, 0), z_rot: 0 },
57415
+ rear: { pos: new Vector3(-1, 0, 0), z_rot: 0 },
57416
+ left: { pos: new Vector3(0, 1, 0), z_rot: 0 },
57417
+ right: { pos: new Vector3(0, -1, 0), z_rot: 0 },
57418
+ top: { pos: new Vector3(0, 0, 1), z_rot: 0 },
57419
+ bottom: { pos: new Vector3(0, 0, -1), z_rot: 0 },
57406
57420
  }
57407
57421
  };
57408
57422
 
57409
57423
  const cameraUp = {
57410
57424
  y_up: [0, 1, 0],
57411
57425
  z_up: [0, 0, 1],
57426
+ legacy: [0, 0, 1],
57412
57427
  };
57413
57428
 
57414
57429
  class Camera {
@@ -57422,9 +57437,14 @@ class Camera {
57422
57437
  * @param {string} up - Z or Y to define whether Z or Y direction is camera up.
57423
57438
  **/
57424
57439
  constructor(width, height, distance, target, ortho, up) {
57440
+ const mapping = {
57441
+ "Y": "y_up",
57442
+ "Z": "z_up",
57443
+ "L": "legacy"
57444
+ };
57425
57445
  this.target = new Vector3(...target);
57426
57446
  this.ortho = ortho;
57427
- this.up = (up == "Y") ? "y_up" : "z_up";
57447
+ this.up = mapping[up];
57428
57448
  this.yaxis = new Vector3(0, 1, 0);
57429
57449
  this.zaxis = new Vector3(0, 0, 1);
57430
57450
 
@@ -57531,10 +57551,10 @@ class Camera {
57531
57551
  if (position != null) {
57532
57552
  var cameraPosition = relative
57533
57553
  ? position
57534
- .clone()
57535
- .normalize()
57536
- .multiplyScalar(this.camera_distance)
57537
- .add(this.target)
57554
+ .clone()
57555
+ .normalize()
57556
+ .multiplyScalar(this.camera_distance)
57557
+ .add(this.target)
57538
57558
  : position;
57539
57559
 
57540
57560
  this.camera.position.set(...cameraPosition.toArray());
@@ -57560,8 +57580,14 @@ class Camera {
57560
57580
  zoom = this.camera.zoom;
57561
57581
  }
57562
57582
  // For the default directions quaternion can be ignored, it will be reset automatically
57563
- this.setupCamera(true, defaultDirections[this.up][dir], null, zoom);
57583
+ this.setupCamera(true, defaultDirections[this.up][dir].pos, null, zoom);
57564
57584
  this.lookAtTarget();
57585
+ if (defaultDirections[this.up][dir].z_rot != 0) {
57586
+ var quaternion = new Quaternion();
57587
+ quaternion.setFromAxisAngle(new Vector3(0, 0, 1), defaultDirections[this.up][dir].z_rot);
57588
+ quaternion.multiply(this.getQuaternion());
57589
+ this.setQuaternion(quaternion);
57590
+ }
57565
57591
  }
57566
57592
 
57567
57593
  /**
@@ -57665,11 +57691,11 @@ class Camera {
57665
57691
 
57666
57692
  this.pCamera.aspect = aspect;
57667
57693
 
57668
- this.camera.updateProjectionMatrix();
57694
+ this.camera.updateProjectionMatrix();
57669
57695
  }
57670
57696
  }
57671
57697
 
57672
- const version="1.6.4";
57698
+ const version="1.7.1";
57673
57699
 
57674
57700
  class Viewer {
57675
57701
  /**
@@ -58364,6 +58390,7 @@ class Viewer {
58364
58390
  this.ticks,
58365
58391
  this.axes0,
58366
58392
  this.grid,
58393
+ options.up == "Z",
58367
58394
  );
58368
58395
  this.gridHelper.computeGrid();
58369
58396
 
@@ -58717,7 +58744,7 @@ class Viewer {
58717
58744
  this.treeview.removeLabelHighlight();
58718
58745
  }
58719
58746
  }
58720
-
58747
+
58721
58748
  /**
58722
58749
  * Handle bounding box and notifications for picked elements
58723
58750
  * @function
@@ -58738,7 +58765,7 @@ class Viewer {
58738
58765
  const object = this.nestedGroup.groups[id];
58739
58766
  const boundingBox = new BoundingBox().setFromObject(object, true);
58740
58767
 
58741
- if(this.lastBbox != null && this.lastBbox.id === id && !meta && !shift){
58768
+ if (this.lastBbox != null && this.lastBbox.id === id && !meta && !shift) {
58742
58769
  this.removeLastBbox();
58743
58770
  } else {
58744
58771
  if (highlight) {
@@ -58892,7 +58919,7 @@ class Viewer {
58892
58919
  */
58893
58920
  setAxes0 = (flag, notify = true) => {
58894
58921
  this.axes0 = flag;
58895
- this.gridHelper.setCenter(flag);
58922
+ this.gridHelper.setCenter(flag, this.up == "Z");
58896
58923
  this.display.setAxes0Check(flag);
58897
58924
  this.axesHelper.setCenter(flag);
58898
58925
 
@@ -59576,23 +59603,27 @@ class Viewer {
59576
59603
  * @param {number} treeWidth - new width of navigation tree
59577
59604
  * @param {number} height - new height of CAD View
59578
59605
  * @param {boolean} [glass=false] - Whether to use glass mode or not
59579
- */
59580
- resizeCadView(cadWidth, treeWidth, height, glass=false) {
59606
+ */
59607
+ resizeCadView(cadWidth, treeWidth, height, glass = false) {
59581
59608
  this.cadWidth = cadWidth;
59582
59609
  this.height = height;
59583
-
59610
+
59584
59611
  // Adapt renderer dimensions
59585
59612
  this.renderer.setSize(cadWidth, height);
59586
59613
 
59587
59614
  // Adapt display dimensions
59588
- this.display.setSizes({"treeWidth": treeWidth, "cadWidth": cadWidth, "height": height});
59615
+ this.display.setSizes({
59616
+ treeWidth: treeWidth,
59617
+ cadWidth: cadWidth,
59618
+ height: height,
59619
+ });
59589
59620
  this.display.cadView.children[2].style.width = `${cadWidth}px`;
59590
59621
  this.display.cadView.children[2].style.height = `${height}px`;
59591
59622
  this.display.glassMode(glass);
59592
-
59623
+
59593
59624
  const fullWidth = cadWidth + (glass ? 0 : treeWidth);
59594
59625
  this.display.handleMoreButton(fullWidth);
59595
-
59626
+
59596
59627
  // Adapt camers to new dimensions
59597
59628
  this.camera.changeDimensions(this.bb_radius, cadWidth, height);
59598
59629