@inweb/viewer-visualize 26.12.5 → 26.12.7

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.
@@ -2504,7 +2504,6 @@ function regenerateAll(viewer) {
2504
2504
  function resetView(viewer) {
2505
2505
  if (!viewer.visualizeJs)
2506
2506
  return;
2507
- const reset = viewer.getComponent("ResetComponent");
2508
2507
  viewer.executeCommand("setActiveDragger");
2509
2508
  viewer.executeCommand("clearSlices");
2510
2509
  viewer.executeCommand("clearOverlay");
@@ -2513,7 +2512,6 @@ function resetView(viewer) {
2513
2512
  viewer.executeCommand("showAll");
2514
2513
  viewer.executeCommand("explode", 0);
2515
2514
  viewer.executeCommand("zoomToExtents", true);
2516
- reset.resetCameraPosition();
2517
2515
  viewer.emit({ type: "resetview" });
2518
2516
  }
2519
2517
 
@@ -3028,8 +3026,10 @@ class ResetComponent {
3028
3026
  };
3029
3027
  this.viewer = viewer;
3030
3028
  this.viewer.addEventListener("databasechunk", this.onDatabaseChunk);
3029
+ this.viewer.on("resetview", this.resetCameraPosition);
3031
3030
  }
3032
3031
  dispose() {
3032
+ this.viewer.off("resetview", this.resetCameraPosition);
3033
3033
  this.viewer.removeEventListener("databasechunk", this.onDatabaseChunk);
3034
3034
  }
3035
3035
  resetCameraPosition() {
@@ -3866,7 +3866,7 @@ class VisualizeMarkup {
3866
3866
  const visLib = this._viewer.visLib();
3867
3867
  const visViewer = this._viewer.visViewer();
3868
3868
  if (!viewpoint)
3869
- viewpoint = {};
3869
+ viewpoint = { custom_fields: {} };
3870
3870
  viewpoint.lines = [];
3871
3871
  viewpoint.texts = [];
3872
3872
  const model = visViewer.getMarkupModel();
@@ -3908,12 +3908,8 @@ class VisualizeMarkup {
3908
3908
  entityPtr.delete();
3909
3909
  }
3910
3910
  itr.delete();
3911
- viewpoint.snapshot = {
3912
- data: visLib.canvas.toDataURL("image/jpeg", 0.25),
3913
- };
3914
- viewpoint.custom_fields = {
3915
- markup_color: this.getMarkupColor(),
3916
- };
3911
+ viewpoint.snapshot = { data: visLib.canvas.toDataURL("image/jpeg", 0.25) };
3912
+ viewpoint.custom_fields.markup_color = this.getMarkupColor();
3917
3913
  return viewpoint;
3918
3914
  }
3919
3915
  enableEditMode(mode) {
@@ -4513,11 +4509,27 @@ class Viewer extends EventEmitter2 {
4513
4509
  const setOrthogonalCamera = (orthogonal_camera) => {
4514
4510
  if (orthogonal_camera) {
4515
4511
  activeView.setView(getPoint3dAsArray(orthogonal_camera.view_point), getPoint3dAsArray(orthogonal_camera.direction), getPoint3dAsArray(orthogonal_camera.up_vector), orthogonal_camera.field_width, orthogonal_camera.field_height, true);
4516
- this.syncOverlay();
4512
+ this.options.cameraMode = "orthographic";
4517
4513
  this.emitEvent({ type: "changecameramode", mode: "orthographic" });
4518
4514
  }
4519
4515
  };
4520
- const setPerspectiveCamera = (perspective_camera) => { };
4516
+ const setPerspectiveCamera = (perspective_camera) => {
4517
+ if (perspective_camera) {
4518
+ const aspectRatio = this.canvas.width / this.canvas.height;
4519
+ const position = perspective_camera.view_point;
4520
+ const target = perspective_camera.direction;
4521
+ const fov = (perspective_camera.field_of_view * Math.PI) / 180;
4522
+ const dx = target.x - position.x;
4523
+ const dy = target.y - position.y;
4524
+ const dz = target.z - position.z;
4525
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
4526
+ const fieldHeight = 2 * distance * Math.tan(fov / 2);
4527
+ const fieldWidth = fieldHeight * aspectRatio;
4528
+ activeView.setView(getPoint3dAsArray(perspective_camera.view_point), getPoint3dAsArray(perspective_camera.direction), getPoint3dAsArray(perspective_camera.up_vector), fieldWidth, fieldHeight, false);
4529
+ this.options.cameraMode = "perspective";
4530
+ this.emitEvent({ type: "changecameramode", mode: "perspective" });
4531
+ }
4532
+ };
4521
4533
  const setClippingPlanes = (clipping_planes) => {
4522
4534
  if (clipping_planes) {
4523
4535
  for (const clipping_plane of clipping_planes) {
@@ -4544,6 +4556,7 @@ class Viewer extends EventEmitter2 {
4544
4556
  setClippingPlanes(viewpoint.clipping_planes);
4545
4557
  setSelection(((_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.selection2) || viewpoint.selection);
4546
4558
  this._markup.setViewpoint(viewpoint);
4559
+ this.syncOverlay();
4547
4560
  this.setActiveDragger(draggerName);
4548
4561
  this.emitEvent({ type: "drawviewpoint", data: viewpoint });
4549
4562
  this.update();
@@ -4557,17 +4570,37 @@ class Viewer extends EventEmitter2 {
4557
4570
  return { x: array[0], y: array[1], z: array[2] };
4558
4571
  };
4559
4572
  const getOrthogonalCamera = () => {
4560
- return {
4561
- view_point: getPoint3dFromArray(activeView.viewPosition),
4562
- direction: getPoint3dFromArray(activeView.viewTarget),
4563
- up_vector: getPoint3dFromArray(activeView.upVector),
4564
- field_width: activeView.viewFieldWidth,
4565
- field_height: activeView.viewFieldHeight,
4566
- view_to_world_scale: 1,
4567
- };
4573
+ if (!activeView.perspective)
4574
+ return {
4575
+ view_point: getPoint3dFromArray(activeView.viewPosition),
4576
+ direction: getPoint3dFromArray(activeView.viewTarget),
4577
+ up_vector: getPoint3dFromArray(activeView.upVector),
4578
+ field_width: activeView.viewFieldWidth,
4579
+ field_height: activeView.viewFieldHeight,
4580
+ view_to_world_scale: 1,
4581
+ };
4582
+ else
4583
+ return undefined;
4568
4584
  };
4569
4585
  const getPerspectiveCamera = () => {
4570
- return undefined;
4586
+ if (activeView.perspective) {
4587
+ const position = activeView.viewPosition;
4588
+ const target = activeView.viewTarget;
4589
+ const fieldHeight = activeView.viewFieldHeight;
4590
+ const dx = target[0] - position[0];
4591
+ const dy = target[1] - position[1];
4592
+ const dz = target[2] - position[2];
4593
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
4594
+ const fov = 2 * Math.atan(fieldHeight / (2 * distance));
4595
+ return {
4596
+ view_point: getPoint3dFromArray(activeView.viewPosition),
4597
+ direction: getPoint3dFromArray(activeView.viewTarget),
4598
+ up_vector: getPoint3dFromArray(activeView.upVector),
4599
+ field_of_view: (fov * 180) / Math.PI,
4600
+ };
4601
+ }
4602
+ else
4603
+ return undefined;
4571
4604
  };
4572
4605
  const getClippingPlanes = () => {
4573
4606
  const clipping_planes = [];