@xeokit/xeokit-sdk 2.4.0-alpha-27 → 2.4.0-alpha-28

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.
@@ -15555,221 +15555,6 @@ function createSampleOffsets(kernelRadius, uvIncrement) {
15555
15555
  return offsets;
15556
15556
  }
15557
15557
 
15558
- /*
15559
- * Canvas2Image v0.1
15560
- * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com
15561
- * MIT License [http://www.opensource.org/licenses/mit-license.php]
15562
- *
15563
- * Modified by @xeolabs to permit vertical flipping, so that snapshot can be taken from WebGL frame buffers,
15564
- * which vertically flip image data as part of the way that WebGL renders textures.
15565
- */
15566
-
15567
- /**
15568
- * @private
15569
- */
15570
- const Canvas2Image = (function () {
15571
- // check if we have canvas support
15572
- const oCanvas = document.createElement("canvas"), sc = String.fromCharCode;
15573
-
15574
- // no canvas, bail out.
15575
- if (!oCanvas.getContext) {
15576
- return {
15577
- saveAsBMP: function () {
15578
- },
15579
- saveAsPNG: function () {
15580
- },
15581
- saveAsJPEG: function () {
15582
- }
15583
- }
15584
- }
15585
-
15586
- const bHasImageData = !!(oCanvas.getContext("2d").getImageData), bHasDataURL = !!(oCanvas.toDataURL),
15587
- bHasBase64 = !!(window.btoa);
15588
-
15589
- // ok, we're good
15590
- const readCanvasData = function (oCanvas) {
15591
- const iWidth = parseInt(oCanvas.width), iHeight = parseInt(oCanvas.height);
15592
- return oCanvas.getContext("2d").getImageData(0, 0, iWidth, iHeight);
15593
- };
15594
-
15595
- // base64 encodes either a string or an array of charcodes
15596
- const encodeData = function (data) {
15597
- let i, aData, strData = "";
15598
-
15599
- if (typeof data == "string") {
15600
- strData = data;
15601
- } else {
15602
- aData = data;
15603
- for (i = 0; i < aData.length; i++) {
15604
- strData += sc(aData[i]);
15605
- }
15606
- }
15607
- return btoa(strData);
15608
- };
15609
-
15610
- // creates a base64 encoded string containing BMP data takes an imagedata object as argument
15611
- const createBMP = function (oData) {
15612
- let strHeader = '';
15613
- const iWidth = oData.width;
15614
- const iHeight = oData.height;
15615
-
15616
- strHeader += 'BM';
15617
-
15618
- let iFileSize = iWidth * iHeight * 4 + 54; // total header size = 54 bytes
15619
- strHeader += sc(iFileSize % 256);
15620
- iFileSize = Math.floor(iFileSize / 256);
15621
- strHeader += sc(iFileSize % 256);
15622
- iFileSize = Math.floor(iFileSize / 256);
15623
- strHeader += sc(iFileSize % 256);
15624
- iFileSize = Math.floor(iFileSize / 256);
15625
- strHeader += sc(iFileSize % 256);
15626
-
15627
- strHeader += sc(0, 0, 0, 0, 54, 0, 0, 0); // data offset
15628
- strHeader += sc(40, 0, 0, 0); // info header size
15629
-
15630
- let iImageWidth = iWidth;
15631
- strHeader += sc(iImageWidth % 256);
15632
- iImageWidth = Math.floor(iImageWidth / 256);
15633
- strHeader += sc(iImageWidth % 256);
15634
- iImageWidth = Math.floor(iImageWidth / 256);
15635
- strHeader += sc(iImageWidth % 256);
15636
- iImageWidth = Math.floor(iImageWidth / 256);
15637
- strHeader += sc(iImageWidth % 256);
15638
-
15639
- let iImageHeight = iHeight;
15640
- strHeader += sc(iImageHeight % 256);
15641
- iImageHeight = Math.floor(iImageHeight / 256);
15642
- strHeader += sc(iImageHeight % 256);
15643
- iImageHeight = Math.floor(iImageHeight / 256);
15644
- strHeader += sc(iImageHeight % 256);
15645
- iImageHeight = Math.floor(iImageHeight / 256);
15646
- strHeader += sc(iImageHeight % 256);
15647
-
15648
- strHeader += sc(1, 0, 32, 0); // num of planes & num of bits per pixel
15649
- strHeader += sc(0, 0, 0, 0); // compression = none
15650
-
15651
- let iDataSize = iWidth * iHeight * 4;
15652
- strHeader += sc(iDataSize % 256);
15653
- iDataSize = Math.floor(iDataSize / 256);
15654
- strHeader += sc(iDataSize % 256);
15655
- iDataSize = Math.floor(iDataSize / 256);
15656
- strHeader += sc(iDataSize % 256);
15657
- iDataSize = Math.floor(iDataSize / 256);
15658
- strHeader += sc(iDataSize % 256);
15659
-
15660
- strHeader += sc(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // these bytes are not used
15661
-
15662
- const aImgData = oData.data;
15663
- let strPixelData = "";
15664
- let x;
15665
- let y = iHeight;
15666
- let iOffsetX;
15667
- let iOffsetY;
15668
- let strPixelRow;
15669
-
15670
- do {
15671
- iOffsetY = iWidth * (y - 1) * 4;
15672
- strPixelRow = "";
15673
- for (x = 0; x < iWidth; x++) {
15674
- iOffsetX = 4 * x;
15675
- strPixelRow += sc(
15676
- aImgData[iOffsetY + iOffsetX + 2], // B
15677
- aImgData[iOffsetY + iOffsetX + 1], // G
15678
- aImgData[iOffsetY + iOffsetX], // R
15679
- aImgData[iOffsetY + iOffsetX + 3] // A
15680
- );
15681
- }
15682
- strPixelData += strPixelRow;
15683
- } while (--y);
15684
-
15685
- return encodeData(strHeader + strPixelData);
15686
- };
15687
-
15688
- // sends the generated file to the client
15689
- const saveFile = function (strData) {
15690
- if (!window.open(strData)) {
15691
- document.location.href = strData;
15692
- }
15693
- };
15694
-
15695
- const makeDataURI = function (strData, strMime) {
15696
- return "data:" + strMime + ";base64," + strData;
15697
- };
15698
-
15699
- // generates a <img> object containing the imagedata
15700
- const makeImageObject = function (strSource) {
15701
- const oImgElement = document.createElement("img");
15702
- oImgElement.src = strSource;
15703
- return oImgElement;
15704
- };
15705
-
15706
- const scaleCanvas = function (oCanvas, iWidth, iHeight, flipy) {
15707
- if (iWidth && iHeight) {
15708
- const oSaveCanvas = document.createElement("canvas");
15709
- oSaveCanvas.width = iWidth;
15710
- oSaveCanvas.height = iHeight;
15711
- oSaveCanvas.style.width = iWidth + "px";
15712
- oSaveCanvas.style.height = iHeight + "px";
15713
- const oSaveCtx = oSaveCanvas.getContext("2d");
15714
- if (flipy) {
15715
- oSaveCtx.save();
15716
- oSaveCtx.scale(1.0, -1.0);
15717
- oSaveCtx.imageSmoothingEnabled = true;
15718
- oSaveCtx.drawImage(oCanvas, 0, 0, oCanvas.width, oCanvas.height, 0, 0, iWidth, -iHeight);
15719
- oSaveCtx.restore();
15720
- } else {
15721
- oSaveCtx.imageSmoothingEnabled = true;
15722
- oSaveCtx.drawImage(oCanvas, 0, 0, oCanvas.width, oCanvas.height, 0, 0, iWidth, iHeight);
15723
- }
15724
- return oSaveCanvas;
15725
- }
15726
- return oCanvas;
15727
- };
15728
-
15729
- return {
15730
- saveAsPNG: function (oCanvas, bReturnImg, iWidth, iHeight, flipy) {
15731
- if (!bHasDataURL) return false;
15732
- const oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight, flipy);
15733
- const strMime = "image/png";
15734
- const strData = oScaledCanvas.toDataURL(strMime);
15735
- if (bReturnImg) {
15736
- return makeImageObject(strData);
15737
- } else {
15738
- saveFile(strData);
15739
- }
15740
- return true;
15741
- },
15742
-
15743
- saveAsJPEG: function (oCanvas, bReturnImg, iWidth, iHeight, flipy) {
15744
- if (!bHasDataURL) return false;
15745
- const oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight, flipy);
15746
- const strMime = "image/jpeg";
15747
- const strData = oScaledCanvas.toDataURL(strMime);
15748
- // check if browser actually supports jpeg by looking for the mime type in the data uri. if not, return false
15749
- if (strData.indexOf(strMime) != 5) return false;
15750
- if (bReturnImg) {
15751
- return makeImageObject(strData);
15752
- } else {
15753
- saveFile(strData);
15754
- }
15755
- return true;
15756
- },
15757
-
15758
- saveAsBMP: function (oCanvas, bReturnImg, iWidth, iHeight, flipy) {
15759
- if (!(bHasDataURL && bHasImageData && bHasBase64)) return false;
15760
- const oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight, flipy);
15761
- const strMime = "image/bmp";
15762
- const oData = readCanvasData(oScaledCanvas), strImgData = createBMP(oData);
15763
- if (bReturnImg) {
15764
- return makeImageObject(makeDataURI(strImgData, strMime));
15765
- } else {
15766
- saveFile(makeDataURI(strImgData, strMime));
15767
- }
15768
- return true;
15769
- }
15770
- };
15771
- })();
15772
-
15773
15558
  /**
15774
15559
  * @desc Represents a WebGL render buffer.
15775
15560
  * @private
@@ -15967,42 +15752,21 @@ class RenderBuffer {
15967
15752
  }
15968
15753
 
15969
15754
  readImage(params) {
15970
-
15971
15755
  const gl = this.gl;
15972
15756
  const imageDataCache = this._getImageDataCache();
15973
15757
  const pixelData = imageDataCache.pixelData;
15974
15758
  const canvas = imageDataCache.canvas;
15975
15759
  const imageData = imageDataCache.imageData;
15976
15760
  const context = imageDataCache.context;
15977
-
15978
15761
  gl.readPixels(0, 0, this.buffer.width, this.buffer.height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
15979
-
15980
15762
  imageData.data.set(pixelData);
15981
15763
  context.putImageData(imageData, 0, 0);
15982
-
15983
- const imageWidth = params.width || canvas.width;
15984
- const imageHeight = params.height || canvas.height;
15985
- const format = params.format || "jpeg";
15986
- const flipy = true; // Account for WebGL texture flipping
15987
-
15988
- let image;
15989
-
15990
- switch (format) {
15991
- case "jpeg":
15992
- image = Canvas2Image.saveAsJPEG(canvas, true, imageWidth, imageHeight, flipy);
15993
- break;
15994
- case "png":
15995
- image = Canvas2Image.saveAsPNG(canvas, true, imageWidth, imageHeight, flipy);
15996
- break;
15997
- case "bmp":
15998
- image = Canvas2Image.saveAsBMP(canvas, true, imageWidth, imageHeight, flipy);
15999
- break;
16000
- default:
16001
- console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");
16002
- image = Canvas2Image.saveAsJPEG(canvas, true, imageWidth, imageHeight, flipy);
15764
+ let format = params.format || "png";
15765
+ if (format !== "jpeg" && format !== "png" && format !== "bmp") {
15766
+ console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");
15767
+ format = "png";
16003
15768
  }
16004
-
16005
- return image.src;
15769
+ return canvas.toDataURL(`image/${format}`);
16006
15770
  }
16007
15771
 
16008
15772
  _getImageDataCache() {
@@ -35072,10 +34836,6 @@ const Renderer$1 = function (scene, options) {
35072
34836
  pickResult.worldNormal = worldSurfaceNormal;
35073
34837
  }
35074
34838
 
35075
- // if (params.pickSurfaceNormal !== false) {
35076
- // gpuPickWorldNormal(pickBuffer, pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
35077
- // }
35078
-
35079
34839
  pickResult.pickSurfacePrecision = true;
35080
34840
  }
35081
34841
 
@@ -35464,8 +35224,7 @@ const Renderer$1 = function (scene, options) {
35464
35224
  */
35465
35225
  this.readSnapshot = function (params) {
35466
35226
  const snapshotBuffer = renderBufferManager.getRenderBuffer("snapshot");
35467
- const imageDataURI = snapshotBuffer.readImage(params);
35468
- return imageDataURI;
35227
+ return snapshotBuffer.readImage(params);
35469
35228
  };
35470
35229
 
35471
35230
  /**
@@ -84187,9 +83946,11 @@ class TrianglesInstancingLayer {
84187
83946
  c[1] = quantizedPositions[ic + 1];
84188
83947
  c[2] = quantizedPositions[ic + 2];
84189
83948
 
84190
- math.decompressPosition(a, state.positionsDecodeMatrix);
84191
- math.decompressPosition(b, state.positionsDecodeMatrix);
84192
- math.decompressPosition(c, state.positionsDecodeMatrix);
83949
+ const { positionsDecodeMatrix } = state.geometry;
83950
+
83951
+ math.decompressPosition(a, positionsDecodeMatrix);
83952
+ math.decompressPosition(b, positionsDecodeMatrix);
83953
+ math.decompressPosition(c, positionsDecodeMatrix);
84193
83954
 
84194
83955
  if (math.rayTriangleIntersect(rtcRayOrigin, rtcRayDir, a, b, c, closestIntersectPos)) {
84195
83956
 
@@ -110731,24 +110492,10 @@ class Viewer {
110731
110492
  if (needFinishSnapshot) {
110732
110493
  this.endSnapshot();
110733
110494
  }
110734
- const imageWidth = snapshotCanvas.width;
110735
- const imageHeight = snapshotCanvas.height;
110736
- const format = params.format || "jpeg";
110737
- const flipy = false;
110738
- let image;
110739
- switch (format) {
110740
- case "jpeg":
110741
- image = Canvas2Image.saveAsJPEG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110742
- break;
110743
- case "png":
110744
- image = Canvas2Image.saveAsPNG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110745
- break;
110746
- case "bmp":
110747
- image = Canvas2Image.saveAsBMP(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110748
- break;
110749
- default:
110750
- this.error("[Viewer.getSnapshotWithPlugins] Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");
110751
- image = Canvas2Image.saveAsJPEG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110495
+ let format = params.format || "png";
110496
+ if (format !== "jpeg" && format !== "png" && format !== "bmp") {
110497
+ console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");
110498
+ format = "png";
110752
110499
  }
110753
110500
  if (!params.includeGizmos) {
110754
110501
  this.sendToPlugins("snapshotFinished");
@@ -110756,7 +110503,7 @@ class Viewer {
110756
110503
  if (needFinishSnapshot) {
110757
110504
  this.endSnapshot();
110758
110505
  }
110759
- resolve(image.src);
110506
+ resolve(snapshotCanvas.toDataURL(`image/${format}`));
110760
110507
  };
110761
110508
 
110762
110509
  for (let i = 0, len = this._plugins.length; i < len; i++) { // Find plugin container elements
@@ -15551,221 +15551,6 @@ function createSampleOffsets(kernelRadius, uvIncrement) {
15551
15551
  return offsets;
15552
15552
  }
15553
15553
 
15554
- /*
15555
- * Canvas2Image v0.1
15556
- * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com
15557
- * MIT License [http://www.opensource.org/licenses/mit-license.php]
15558
- *
15559
- * Modified by @xeolabs to permit vertical flipping, so that snapshot can be taken from WebGL frame buffers,
15560
- * which vertically flip image data as part of the way that WebGL renders textures.
15561
- */
15562
-
15563
- /**
15564
- * @private
15565
- */
15566
- const Canvas2Image = (function () {
15567
- // check if we have canvas support
15568
- const oCanvas = document.createElement("canvas"), sc = String.fromCharCode;
15569
-
15570
- // no canvas, bail out.
15571
- if (!oCanvas.getContext) {
15572
- return {
15573
- saveAsBMP: function () {
15574
- },
15575
- saveAsPNG: function () {
15576
- },
15577
- saveAsJPEG: function () {
15578
- }
15579
- }
15580
- }
15581
-
15582
- const bHasImageData = !!(oCanvas.getContext("2d").getImageData), bHasDataURL = !!(oCanvas.toDataURL),
15583
- bHasBase64 = !!(window.btoa);
15584
-
15585
- // ok, we're good
15586
- const readCanvasData = function (oCanvas) {
15587
- const iWidth = parseInt(oCanvas.width), iHeight = parseInt(oCanvas.height);
15588
- return oCanvas.getContext("2d").getImageData(0, 0, iWidth, iHeight);
15589
- };
15590
-
15591
- // base64 encodes either a string or an array of charcodes
15592
- const encodeData = function (data) {
15593
- let i, aData, strData = "";
15594
-
15595
- if (typeof data == "string") {
15596
- strData = data;
15597
- } else {
15598
- aData = data;
15599
- for (i = 0; i < aData.length; i++) {
15600
- strData += sc(aData[i]);
15601
- }
15602
- }
15603
- return btoa(strData);
15604
- };
15605
-
15606
- // creates a base64 encoded string containing BMP data takes an imagedata object as argument
15607
- const createBMP = function (oData) {
15608
- let strHeader = '';
15609
- const iWidth = oData.width;
15610
- const iHeight = oData.height;
15611
-
15612
- strHeader += 'BM';
15613
-
15614
- let iFileSize = iWidth * iHeight * 4 + 54; // total header size = 54 bytes
15615
- strHeader += sc(iFileSize % 256);
15616
- iFileSize = Math.floor(iFileSize / 256);
15617
- strHeader += sc(iFileSize % 256);
15618
- iFileSize = Math.floor(iFileSize / 256);
15619
- strHeader += sc(iFileSize % 256);
15620
- iFileSize = Math.floor(iFileSize / 256);
15621
- strHeader += sc(iFileSize % 256);
15622
-
15623
- strHeader += sc(0, 0, 0, 0, 54, 0, 0, 0); // data offset
15624
- strHeader += sc(40, 0, 0, 0); // info header size
15625
-
15626
- let iImageWidth = iWidth;
15627
- strHeader += sc(iImageWidth % 256);
15628
- iImageWidth = Math.floor(iImageWidth / 256);
15629
- strHeader += sc(iImageWidth % 256);
15630
- iImageWidth = Math.floor(iImageWidth / 256);
15631
- strHeader += sc(iImageWidth % 256);
15632
- iImageWidth = Math.floor(iImageWidth / 256);
15633
- strHeader += sc(iImageWidth % 256);
15634
-
15635
- let iImageHeight = iHeight;
15636
- strHeader += sc(iImageHeight % 256);
15637
- iImageHeight = Math.floor(iImageHeight / 256);
15638
- strHeader += sc(iImageHeight % 256);
15639
- iImageHeight = Math.floor(iImageHeight / 256);
15640
- strHeader += sc(iImageHeight % 256);
15641
- iImageHeight = Math.floor(iImageHeight / 256);
15642
- strHeader += sc(iImageHeight % 256);
15643
-
15644
- strHeader += sc(1, 0, 32, 0); // num of planes & num of bits per pixel
15645
- strHeader += sc(0, 0, 0, 0); // compression = none
15646
-
15647
- let iDataSize = iWidth * iHeight * 4;
15648
- strHeader += sc(iDataSize % 256);
15649
- iDataSize = Math.floor(iDataSize / 256);
15650
- strHeader += sc(iDataSize % 256);
15651
- iDataSize = Math.floor(iDataSize / 256);
15652
- strHeader += sc(iDataSize % 256);
15653
- iDataSize = Math.floor(iDataSize / 256);
15654
- strHeader += sc(iDataSize % 256);
15655
-
15656
- strHeader += sc(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // these bytes are not used
15657
-
15658
- const aImgData = oData.data;
15659
- let strPixelData = "";
15660
- let x;
15661
- let y = iHeight;
15662
- let iOffsetX;
15663
- let iOffsetY;
15664
- let strPixelRow;
15665
-
15666
- do {
15667
- iOffsetY = iWidth * (y - 1) * 4;
15668
- strPixelRow = "";
15669
- for (x = 0; x < iWidth; x++) {
15670
- iOffsetX = 4 * x;
15671
- strPixelRow += sc(
15672
- aImgData[iOffsetY + iOffsetX + 2], // B
15673
- aImgData[iOffsetY + iOffsetX + 1], // G
15674
- aImgData[iOffsetY + iOffsetX], // R
15675
- aImgData[iOffsetY + iOffsetX + 3] // A
15676
- );
15677
- }
15678
- strPixelData += strPixelRow;
15679
- } while (--y);
15680
-
15681
- return encodeData(strHeader + strPixelData);
15682
- };
15683
-
15684
- // sends the generated file to the client
15685
- const saveFile = function (strData) {
15686
- if (!window.open(strData)) {
15687
- document.location.href = strData;
15688
- }
15689
- };
15690
-
15691
- const makeDataURI = function (strData, strMime) {
15692
- return "data:" + strMime + ";base64," + strData;
15693
- };
15694
-
15695
- // generates a <img> object containing the imagedata
15696
- const makeImageObject = function (strSource) {
15697
- const oImgElement = document.createElement("img");
15698
- oImgElement.src = strSource;
15699
- return oImgElement;
15700
- };
15701
-
15702
- const scaleCanvas = function (oCanvas, iWidth, iHeight, flipy) {
15703
- if (iWidth && iHeight) {
15704
- const oSaveCanvas = document.createElement("canvas");
15705
- oSaveCanvas.width = iWidth;
15706
- oSaveCanvas.height = iHeight;
15707
- oSaveCanvas.style.width = iWidth + "px";
15708
- oSaveCanvas.style.height = iHeight + "px";
15709
- const oSaveCtx = oSaveCanvas.getContext("2d");
15710
- if (flipy) {
15711
- oSaveCtx.save();
15712
- oSaveCtx.scale(1.0, -1.0);
15713
- oSaveCtx.imageSmoothingEnabled = true;
15714
- oSaveCtx.drawImage(oCanvas, 0, 0, oCanvas.width, oCanvas.height, 0, 0, iWidth, -iHeight);
15715
- oSaveCtx.restore();
15716
- } else {
15717
- oSaveCtx.imageSmoothingEnabled = true;
15718
- oSaveCtx.drawImage(oCanvas, 0, 0, oCanvas.width, oCanvas.height, 0, 0, iWidth, iHeight);
15719
- }
15720
- return oSaveCanvas;
15721
- }
15722
- return oCanvas;
15723
- };
15724
-
15725
- return {
15726
- saveAsPNG: function (oCanvas, bReturnImg, iWidth, iHeight, flipy) {
15727
- if (!bHasDataURL) return false;
15728
- const oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight, flipy);
15729
- const strMime = "image/png";
15730
- const strData = oScaledCanvas.toDataURL(strMime);
15731
- if (bReturnImg) {
15732
- return makeImageObject(strData);
15733
- } else {
15734
- saveFile(strData);
15735
- }
15736
- return true;
15737
- },
15738
-
15739
- saveAsJPEG: function (oCanvas, bReturnImg, iWidth, iHeight, flipy) {
15740
- if (!bHasDataURL) return false;
15741
- const oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight, flipy);
15742
- const strMime = "image/jpeg";
15743
- const strData = oScaledCanvas.toDataURL(strMime);
15744
- // check if browser actually supports jpeg by looking for the mime type in the data uri. if not, return false
15745
- if (strData.indexOf(strMime) != 5) return false;
15746
- if (bReturnImg) {
15747
- return makeImageObject(strData);
15748
- } else {
15749
- saveFile(strData);
15750
- }
15751
- return true;
15752
- },
15753
-
15754
- saveAsBMP: function (oCanvas, bReturnImg, iWidth, iHeight, flipy) {
15755
- if (!(bHasDataURL && bHasImageData && bHasBase64)) return false;
15756
- const oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight, flipy);
15757
- const strMime = "image/bmp";
15758
- const oData = readCanvasData(oScaledCanvas), strImgData = createBMP(oData);
15759
- if (bReturnImg) {
15760
- return makeImageObject(makeDataURI(strImgData, strMime));
15761
- } else {
15762
- saveFile(makeDataURI(strImgData, strMime));
15763
- }
15764
- return true;
15765
- }
15766
- };
15767
- })();
15768
-
15769
15554
  /**
15770
15555
  * @desc Represents a WebGL render buffer.
15771
15556
  * @private
@@ -15963,42 +15748,21 @@ class RenderBuffer {
15963
15748
  }
15964
15749
 
15965
15750
  readImage(params) {
15966
-
15967
15751
  const gl = this.gl;
15968
15752
  const imageDataCache = this._getImageDataCache();
15969
15753
  const pixelData = imageDataCache.pixelData;
15970
15754
  const canvas = imageDataCache.canvas;
15971
15755
  const imageData = imageDataCache.imageData;
15972
15756
  const context = imageDataCache.context;
15973
-
15974
15757
  gl.readPixels(0, 0, this.buffer.width, this.buffer.height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
15975
-
15976
15758
  imageData.data.set(pixelData);
15977
15759
  context.putImageData(imageData, 0, 0);
15978
-
15979
- const imageWidth = params.width || canvas.width;
15980
- const imageHeight = params.height || canvas.height;
15981
- const format = params.format || "jpeg";
15982
- const flipy = true; // Account for WebGL texture flipping
15983
-
15984
- let image;
15985
-
15986
- switch (format) {
15987
- case "jpeg":
15988
- image = Canvas2Image.saveAsJPEG(canvas, true, imageWidth, imageHeight, flipy);
15989
- break;
15990
- case "png":
15991
- image = Canvas2Image.saveAsPNG(canvas, true, imageWidth, imageHeight, flipy);
15992
- break;
15993
- case "bmp":
15994
- image = Canvas2Image.saveAsBMP(canvas, true, imageWidth, imageHeight, flipy);
15995
- break;
15996
- default:
15997
- console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");
15998
- image = Canvas2Image.saveAsJPEG(canvas, true, imageWidth, imageHeight, flipy);
15760
+ let format = params.format || "png";
15761
+ if (format !== "jpeg" && format !== "png" && format !== "bmp") {
15762
+ console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");
15763
+ format = "png";
15999
15764
  }
16000
-
16001
- return image.src;
15765
+ return canvas.toDataURL(`image/${format}`);
16002
15766
  }
16003
15767
 
16004
15768
  _getImageDataCache() {
@@ -35068,10 +34832,6 @@ const Renderer$1 = function (scene, options) {
35068
34832
  pickResult.worldNormal = worldSurfaceNormal;
35069
34833
  }
35070
34834
 
35071
- // if (params.pickSurfaceNormal !== false) {
35072
- // gpuPickWorldNormal(pickBuffer, pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
35073
- // }
35074
-
35075
34835
  pickResult.pickSurfacePrecision = true;
35076
34836
  }
35077
34837
 
@@ -35460,8 +35220,7 @@ const Renderer$1 = function (scene, options) {
35460
35220
  */
35461
35221
  this.readSnapshot = function (params) {
35462
35222
  const snapshotBuffer = renderBufferManager.getRenderBuffer("snapshot");
35463
- const imageDataURI = snapshotBuffer.readImage(params);
35464
- return imageDataURI;
35223
+ return snapshotBuffer.readImage(params);
35465
35224
  };
35466
35225
 
35467
35226
  /**
@@ -84183,9 +83942,11 @@ class TrianglesInstancingLayer {
84183
83942
  c[1] = quantizedPositions[ic + 1];
84184
83943
  c[2] = quantizedPositions[ic + 2];
84185
83944
 
84186
- math.decompressPosition(a, state.positionsDecodeMatrix);
84187
- math.decompressPosition(b, state.positionsDecodeMatrix);
84188
- math.decompressPosition(c, state.positionsDecodeMatrix);
83945
+ const { positionsDecodeMatrix } = state.geometry;
83946
+
83947
+ math.decompressPosition(a, positionsDecodeMatrix);
83948
+ math.decompressPosition(b, positionsDecodeMatrix);
83949
+ math.decompressPosition(c, positionsDecodeMatrix);
84189
83950
 
84190
83951
  if (math.rayTriangleIntersect(rtcRayOrigin, rtcRayDir, a, b, c, closestIntersectPos)) {
84191
83952
 
@@ -110727,24 +110488,10 @@ class Viewer {
110727
110488
  if (needFinishSnapshot) {
110728
110489
  this.endSnapshot();
110729
110490
  }
110730
- const imageWidth = snapshotCanvas.width;
110731
- const imageHeight = snapshotCanvas.height;
110732
- const format = params.format || "jpeg";
110733
- const flipy = false;
110734
- let image;
110735
- switch (format) {
110736
- case "jpeg":
110737
- image = Canvas2Image.saveAsJPEG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110738
- break;
110739
- case "png":
110740
- image = Canvas2Image.saveAsPNG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110741
- break;
110742
- case "bmp":
110743
- image = Canvas2Image.saveAsBMP(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110744
- break;
110745
- default:
110746
- this.error("[Viewer.getSnapshotWithPlugins] Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");
110747
- image = Canvas2Image.saveAsJPEG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110491
+ let format = params.format || "png";
110492
+ if (format !== "jpeg" && format !== "png" && format !== "bmp") {
110493
+ console.error("Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");
110494
+ format = "png";
110748
110495
  }
110749
110496
  if (!params.includeGizmos) {
110750
110497
  this.sendToPlugins("snapshotFinished");
@@ -110752,7 +110499,7 @@ class Viewer {
110752
110499
  if (needFinishSnapshot) {
110753
110500
  this.endSnapshot();
110754
110501
  }
110755
- resolve(image.src);
110502
+ resolve(snapshotCanvas.toDataURL(`image/${format}`));
110756
110503
  };
110757
110504
 
110758
110505
  for (let i = 0, len = this._plugins.length; i < len; i++) { // Find plugin container elements