@inweb/viewer-three 27.1.3 → 27.1.5

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.
@@ -2192,9 +2192,15 @@ function clearSlices(viewer) {
2192
2192
  viewer.clearSlices();
2193
2193
  }
2194
2194
 
2195
- function createPreview(viewer, type = "image/jpeg", quality = 0.25) {
2195
+ function getSnapshot(viewer, type, quality) {
2196
+ var _a, _b;
2196
2197
  viewer.update(true);
2197
- return viewer.canvas.toDataURL(type, quality);
2198
+ const mimeType = (_a = type !== null && type !== void 0 ? type : viewer.options.snapshotMimeType) !== null && _a !== void 0 ? _a : "image/jpeg";
2199
+ const imageQuality = (_b = quality !== null && quality !== void 0 ? quality : viewer.options.snapshotQuality) !== null && _b !== void 0 ? _b : 0.25;
2200
+ if (viewer.markup) {
2201
+ return viewer.markup.getSnapshot(mimeType, imageQuality);
2202
+ }
2203
+ return viewer.canvas.toDataURL(mimeType, imageQuality);
2198
2204
  }
2199
2205
 
2200
2206
  function explode(viewer, index = 0) {
@@ -2403,7 +2409,7 @@ commands.registerCommand("clearMarkup", clearMarkup);
2403
2409
  commands.registerCommand("clearSelected", clearSelected);
2404
2410
  commands.registerCommand("clearSlices", clearSlices);
2405
2411
  commands.registerCommand("collect", collect);
2406
- commands.registerCommand("createPreview", createPreview);
2412
+ commands.registerCommand("getSnapshot", getSnapshot);
2407
2413
  commands.registerCommand("explode", explode);
2408
2414
  commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
2409
2415
  commands.registerCommand("getModels", getModels);
@@ -2435,6 +2441,7 @@ commands.registerCommand("ne", (viewer) => setDefaultViewPosition(viewer, "ne"))
2435
2441
  commands.registerCommand("nw", (viewer) => setDefaultViewPosition(viewer, "nw"));
2436
2442
  commands.registerCommandAlias("clearMarkup", "clearOverlay");
2437
2443
  commands.registerCommandAlias("clearSelected", "unselect");
2444
+ commands.registerCommandAlias("getSnapshot", "createPreview");
2438
2445
  commands.registerCommandAlias("zoomToExtents", "zoomExtents");
2439
2446
  commands.registerCommandAlias("top", "k3DViewTop");
2440
2447
  commands.registerCommandAlias("bottom", "k3DViewBottom");
@@ -2521,7 +2528,7 @@ class CameraComponent {
2521
2528
  if (camera.isOrthographicCamera) {
2522
2529
  camera.left = camera.bottom * aspectRatio;
2523
2530
  camera.right = camera.top * aspectRatio;
2524
- camera.near = 0;
2531
+ camera.near = -extentsSize * 1000;
2525
2532
  camera.far = extentsSize * 1000;
2526
2533
  }
2527
2534
  camera.updateProjectionMatrix();
@@ -2787,22 +2794,7 @@ class InfoComponent {
2787
2794
  }
2788
2795
  }
2789
2796
 
2790
- class RenderLoopComponent {
2791
- constructor(viewer) {
2792
- this.animate = (time) => {
2793
- this.requestId = requestAnimationFrame(this.animate);
2794
- this.viewer.render(time);
2795
- this.viewer.emitEvent({ type: "animate", time });
2796
- };
2797
- this.viewer = viewer;
2798
- this.requestId = requestAnimationFrame(this.animate);
2799
- }
2800
- dispose() {
2801
- cancelAnimationFrame(this.requestId);
2802
- }
2803
- }
2804
-
2805
- class ResizeCanvasComponent {
2797
+ class CanvasResizeComponent {
2806
2798
  constructor(viewer) {
2807
2799
  this.resizeViewer = (entries) => {
2808
2800
  const { width, height } = entries[0].contentRect;
@@ -2819,6 +2811,46 @@ class ResizeCanvasComponent {
2819
2811
  }
2820
2812
  }
2821
2813
 
2814
+ class CanvasRemoveComponent {
2815
+ constructor(viewer) {
2816
+ this.cleanupViewer = (mutations) => {
2817
+ for (const mutation of mutations) {
2818
+ if (mutation.type === "childList" && mutation.removedNodes.length > 0) {
2819
+ for (const node of mutation.removedNodes) {
2820
+ if (node === this.viewer.canvas || node.contains(this.viewer.canvas)) {
2821
+ this.viewer.emitEvent({ type: "canvasremoved" });
2822
+ this.viewer.dispose();
2823
+ return;
2824
+ }
2825
+ }
2826
+ }
2827
+ }
2828
+ };
2829
+ this.viewer = viewer;
2830
+ this.mutationObserver = new MutationObserver(this.cleanupViewer);
2831
+ this.mutationObserver.observe(document, { childList: true, subtree: true });
2832
+ }
2833
+ dispose() {
2834
+ this.mutationObserver.disconnect();
2835
+ this.mutationObserver = undefined;
2836
+ }
2837
+ }
2838
+
2839
+ class RenderLoopComponent {
2840
+ constructor(viewer) {
2841
+ this.animate = (time) => {
2842
+ this.requestId = requestAnimationFrame(this.animate);
2843
+ this.viewer.render(time);
2844
+ this.viewer.emitEvent({ type: "animate", time });
2845
+ };
2846
+ this.viewer = viewer;
2847
+ this.requestId = requestAnimationFrame(this.animate);
2848
+ }
2849
+ dispose() {
2850
+ cancelAnimationFrame(this.requestId);
2851
+ }
2852
+ }
2853
+
2822
2854
  class HighlighterUtils {
2823
2855
  static isBreak(positions, i) {
2824
2856
  return (isNaN(positions[i]) ||
@@ -3275,7 +3307,8 @@ components.registerComponent("CameraComponent", (viewer) => new CameraComponent(
3275
3307
  components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
3276
3308
  components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
3277
3309
  components.registerComponent("InfoComponent", (viewer) => new InfoComponent(viewer));
3278
- components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
3310
+ components.registerComponent("CanvasResizeComponent", (viewer) => new CanvasResizeComponent(viewer));
3311
+ components.registerComponent("CanvasRemoveComponent", (viewer) => new CanvasRemoveComponent(viewer));
3279
3312
  components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
3280
3313
  components.registerComponent("HighlighterComponent", (viewer) => new HighlighterComponent(viewer));
3281
3314
  components.registerComponent("SelectionComponent", (viewer) => new SelectionComponent(viewer));
@@ -7194,7 +7227,7 @@ class Viewer extends EventEmitter2 {
7194
7227
  camera.bottom = -orthogonal_camera.field_height / 2;
7195
7228
  camera.left = camera.bottom * aspectRatio;
7196
7229
  camera.right = camera.top * aspectRatio;
7197
- camera.near = 0;
7230
+ camera.near = -extentsSize * 1000;
7198
7231
  camera.far = extentsSize * 1000;
7199
7232
  camera.zoom = orthogonal_camera.view_to_world_scale;
7200
7233
  camera.updateProjectionMatrix();
@@ -7315,12 +7348,16 @@ class Viewer extends EventEmitter2 {
7315
7348
  viewpoint.clipping_planes = getClippingPlanes();
7316
7349
  viewpoint.selection = getSelection();
7317
7350
  viewpoint.description = new Date().toDateString();
7351
+ viewpoint.snapshot = { data: this.getSnapshot() };
7318
7352
  this._markup.getViewpoint(viewpoint);
7319
7353
  viewpoint.custom_fields.camera_target = getPoint3dFromVector3(this.target);
7320
7354
  viewpoint.custom_fields.selection2 = getSelection2();
7321
7355
  this.emitEvent({ type: "createviewpoint", data: viewpoint });
7322
7356
  return viewpoint;
7323
7357
  }
7358
+ getSnapshot(type, quality) {
7359
+ return this.executeCommand("getSnapshot", type, quality);
7360
+ }
7324
7361
  screenToWorld(position) {
7325
7362
  if (!this.renderer)
7326
7363
  return { x: position.x, y: position.y, z: 0 };