redhotmagma-visualization 1.58.5 → 1.58.6

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/Three/Three2D.js CHANGED
@@ -1395,11 +1395,10 @@ export var Three2D = /*#__PURE__*/function (_ThreeBase) {
1395
1395
  _context12.next = 6;
1396
1396
  return _this0.setView(origDesignView);
1397
1397
  case 6:
1398
- _this0.renderer.setSize(origSize.width, origSize.height);
1399
- _this0.renderer.setPixelRatio(origPixelRatio);
1398
+ _this0.restoreSizeAfterScreenshotting(origSize, origPixelRatio);
1400
1399
  _this0.render();
1401
1400
  removeTempOverlay();
1402
- case 10:
1401
+ case 9:
1403
1402
  case "end":
1404
1403
  return _context12.stop();
1405
1404
  }
@@ -269,12 +269,11 @@ export var Three2DLayers = /*#__PURE__*/function (_Three2D) {
269
269
  _context4.next = 4;
270
270
  return _this4.setView(_this4.getDesignViewByViewImageIdentifier(origDesignView.identifier) || origDesignView);
271
271
  case 4:
272
- _this4.renderer.setSize(origSize.width, origSize.height);
273
- _this4.renderer.setPixelRatio(origPixelRatio);
274
272
  _this4.camera = origCamera;
273
+ _this4.restoreSizeAfterScreenshotting(origSize, origPixelRatio);
275
274
  _this4.render();
276
275
  removeTempOverlay();
277
- case 9:
276
+ case 8:
278
277
  case "end":
279
278
  return _context4.stop();
280
279
  }
package/Three/Three3D.js CHANGED
@@ -876,18 +876,16 @@ export var Three3D = /*#__PURE__*/function (_ThreeBase) {
876
876
  while (1) switch (_context8.prev = _context8.next) {
877
877
  case 0:
878
878
  _this5._screenshottingInProgress = false;
879
- _this5.renderer.setSize(origSize.width, origSize.height);
880
- _this5.renderer.setPixelRatio(origPixelRatio);
881
- _this5.updateCamera(origSize.width, origSize.height);
879
+ _this5.restoreSizeAfterScreenshotting(origSize, origPixelRatio);
882
880
  _this5.setCameraPosition(origPosition, origOrientation, origTarget);
883
881
  restoreCameraViewOffset();
884
882
  _this5._materialVariantPath = origVariantPath;
885
- _context8.next = 9;
883
+ _context8.next = 7;
886
884
  return _this5.updateMaterial();
887
- case 9:
885
+ case 7:
888
886
  _this5.render();
889
887
  removeTempOverlay();
890
- case 11:
888
+ case 9:
891
889
  case "end":
892
890
  return _context8.stop();
893
891
  }
@@ -584,6 +584,27 @@ export var ThreeBase = /*#__PURE__*/function (_VisualizationInterfa) {
584
584
  // eslint-disable-next-line no-console
585
585
  console.info("Three instance has been successfully disposed.");
586
586
  }
587
+
588
+ /**
589
+ * Restores the renderer size and pixel ratio after screenshotting.
590
+ * The container can be resized while the screenshots are taken (e.g. the design area editor
591
+ * gets closed right before the screenshots are created, which changes the layout), so the size
592
+ * stored before screenshotting may be stale. Use the current container size in that case,
593
+ * otherwise the canvas and the camera end up with different aspect ratios (distorted image).
594
+ * @param {Vector2} origSize renderer size stored before screenshotting
595
+ * @param {number} origPixelRatio renderer pixel ratio stored before screenshotting
596
+ */
597
+ }, {
598
+ key: "restoreSizeAfterScreenshotting",
599
+ value: function restoreSizeAfterScreenshotting(origSize, origPixelRatio) {
600
+ var container = this._container;
601
+ var useContainerSize = container && container.offsetWidth > 0 && container.offsetHeight > 0;
602
+ var width = useContainerSize ? container.offsetWidth : origSize.width;
603
+ var height = useContainerSize ? container.offsetHeight : origSize.height;
604
+ this.renderer.setPixelRatio(origPixelRatio);
605
+ this.renderer.setSize(width, height);
606
+ this.updateCamera(width, height);
607
+ }
587
608
  }, {
588
609
  key: "abortScreenshotting",
589
610
  value: function abortScreenshotting() {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "redhotmagma-visualization",
3
- "version": "1.58.5",
3
+ "version": "1.58.6",
4
4
  "license": "UNLICENSED",
5
5
  "private": false,
6
6
  "main": "./index.js",
7
7
  "dependencies": {
8
8
  "@babel/polyfill": "^7.12.1",
9
- "@configuratorware/scripts": "1.58.5",
9
+ "@configuratorware/scripts": "1.58.6",
10
10
  "@tweenjs/tween.js": "^17.6.0",
11
11
  "console-polyfill": "^0.3.0",
12
12
  "css-element-queries": "^1.2.3",
@@ -1018,8 +1018,7 @@ export class Three2D extends ThreeBase {
1018
1018
  this._materialVariantPath = origVariantPath;
1019
1019
  this._currentDesignView = null;
1020
1020
  await this.setView(origDesignView);
1021
- this.renderer.setSize(origSize.width, origSize.height);
1022
- this.renderer.setPixelRatio(origPixelRatio);
1021
+ this.restoreSizeAfterScreenshotting(origSize, origPixelRatio);
1023
1022
  this.render();
1024
1023
  removeTempOverlay();
1025
1024
  };
@@ -140,9 +140,8 @@ export class Three2DLayers extends Three2D {
140
140
  await this.setView(
141
141
  this.getDesignViewByViewImageIdentifier(origDesignView.identifier) || origDesignView
142
142
  );
143
- this.renderer.setSize(origSize.width, origSize.height);
144
- this.renderer.setPixelRatio(origPixelRatio);
145
143
  this.camera = origCamera;
144
+ this.restoreSizeAfterScreenshotting(origSize, origPixelRatio);
146
145
  this.render();
147
146
  removeTempOverlay();
148
147
  };
@@ -604,9 +604,7 @@ export class Three3D extends ThreeBase {
604
604
 
605
605
  const restoreOriginalValues = async () => {
606
606
  this._screenshottingInProgress = false;
607
- this.renderer.setSize(origSize.width, origSize.height);
608
- this.renderer.setPixelRatio(origPixelRatio);
609
- this.updateCamera(origSize.width, origSize.height);
607
+ this.restoreSizeAfterScreenshotting(origSize, origPixelRatio);
610
608
  this.setCameraPosition(origPosition, origOrientation, origTarget);
611
609
  restoreCameraViewOffset();
612
610
  this._materialVariantPath = origVariantPath;
@@ -492,6 +492,25 @@ export class ThreeBase extends VisualizationInterface {
492
492
  console.info("Three instance has been successfully disposed.");
493
493
  }
494
494
 
495
+ /**
496
+ * Restores the renderer size and pixel ratio after screenshotting.
497
+ * The container can be resized while the screenshots are taken (e.g. the design area editor
498
+ * gets closed right before the screenshots are created, which changes the layout), so the size
499
+ * stored before screenshotting may be stale. Use the current container size in that case,
500
+ * otherwise the canvas and the camera end up with different aspect ratios (distorted image).
501
+ * @param {Vector2} origSize renderer size stored before screenshotting
502
+ * @param {number} origPixelRatio renderer pixel ratio stored before screenshotting
503
+ */
504
+ restoreSizeAfterScreenshotting(origSize, origPixelRatio) {
505
+ const container = this._container;
506
+ const useContainerSize = container && container.offsetWidth > 0 && container.offsetHeight > 0;
507
+ const width = useContainerSize ? container.offsetWidth : origSize.width;
508
+ const height = useContainerSize ? container.offsetHeight : origSize.height;
509
+ this.renderer.setPixelRatio(origPixelRatio);
510
+ this.renderer.setSize(width, height);
511
+ this.updateCamera(width, height);
512
+ }
513
+
495
514
  abortScreenshotting() {
496
515
  this._screenshottingInProgress &&
497
516
  Object.defineProperty(this, "_abortScreenshotting", {