@xeokit/xeokit-sdk 2.4.0-alpha-26 → 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.
@@ -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
 
@@ -110649,6 +110410,10 @@ class Viewer {
110649
110410
  * Gets a snapshot of this Viewer's {@link Scene} as a Base64-encoded image which includes
110650
110411
  * the HTML elements created by various plugins.
110651
110412
  *
110413
+ * The snapshot image is composed of an image of the viewer canvas, overlaid with an image
110414
+ * of the HTML container element belonging to each installed Viewer plugin. Each container
110415
+ * element is only rendered once, so it's OK for plugins to share the same container.
110416
+ *
110652
110417
  * #### Usage:
110653
110418
  *
110654
110419
  * ````javascript
@@ -110723,24 +110488,10 @@ class Viewer {
110723
110488
  if (needFinishSnapshot) {
110724
110489
  this.endSnapshot();
110725
110490
  }
110726
- const imageWidth = snapshotCanvas.width;
110727
- const imageHeight = snapshotCanvas.height;
110728
- const format = params.format || "jpeg";
110729
- const flipy = false;
110730
- let image;
110731
- switch (format) {
110732
- case "jpeg":
110733
- image = Canvas2Image.saveAsJPEG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110734
- break;
110735
- case "png":
110736
- image = Canvas2Image.saveAsPNG(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110737
- break;
110738
- case "bmp":
110739
- image = Canvas2Image.saveAsBMP(snapshotCanvas, true, imageWidth, imageHeight, flipy);
110740
- break;
110741
- default:
110742
- this.error("[Viewer.getSnapshotWithPlugins] Unsupported image format: '" + format + "' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");
110743
- 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";
110744
110495
  }
110745
110496
  if (!params.includeGizmos) {
110746
110497
  this.sendToPlugins("snapshotFinished");
@@ -110748,7 +110499,7 @@ class Viewer {
110748
110499
  if (needFinishSnapshot) {
110749
110500
  this.endSnapshot();
110750
110501
  }
110751
- resolve(image.src);
110502
+ resolve(snapshotCanvas.toDataURL(`image/${format}`));
110752
110503
  };
110753
110504
 
110754
110505
  for (let i = 0, len = this._plugins.length; i < len; i++) { // Find plugin container elements
@@ -4098,34 +4098,7 @@ this._getInverseProjectMat=function(){var projMatDirty=true;_this25._scene.camer
4098
4098
  gl.uniform2fv(this._uSampleOffsets,sampleOffsetsHor);}else{// Vertical
4099
4099
  gl.uniform2fv(this._uSampleOffsets,sampleOffsetsVert);}gl.uniform1fv(this._uSampleWeights,sampleWeights);var depthTexture=depthRenderBuffer.getDepthTexture();var occlusionTexture=occlusionRenderBuffer.getTexture();program.bindTexture(this._uDepthTexture,depthTexture,0);// TODO: use FrameCtx.textureUnit
4100
4100
  program.bindTexture(this._uOcclusionTexture,occlusionTexture,1);this._aUV.bindArrayBuffer(this._uvBuf);this._aPosition.bindArrayBuffer(this._positionsBuf);this._indicesBuf.bind();gl.drawElements(gl.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0);}},{key:"destroy",value:function destroy(){this._program.destroy();}}]);return SAODepthLimitedBlurRenderer;}();function createSampleWeights(kernelRadius,stdDev){var weights=[];for(var _i52=0;_i52<=kernelRadius;_i52++){weights.push(gaussian(_i52,stdDev));}return weights;// TODO: Optimize
4101
- }function gaussian(x,stdDev){return Math.exp(-(x*x)/(2.0*(stdDev*stdDev)))/(Math.sqrt(2.0*Math.PI)*stdDev);}function createSampleOffsets(kernelRadius,uvIncrement){var offsets=[];for(var _i53=0;_i53<=kernelRadius;_i53++){offsets.push(uvIncrement[0]*_i53);offsets.push(uvIncrement[1]*_i53);}return offsets;}/*
4102
- * Canvas2Image v0.1
4103
- * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com
4104
- * MIT License [http://www.opensource.org/licenses/mit-license.php]
4105
- *
4106
- * Modified by @xeolabs to permit vertical flipping, so that snapshot can be taken from WebGL frame buffers,
4107
- * which vertically flip image data as part of the way that WebGL renders textures.
4108
- */ /**
4109
- * @private
4110
- */var Canvas2Image=function(){// check if we have canvas support
4111
- var oCanvas=document.createElement("canvas"),sc=String.fromCharCode;// no canvas, bail out.
4112
- if(!oCanvas.getContext){return{saveAsBMP:function saveAsBMP(){},saveAsPNG:function saveAsPNG(){},saveAsJPEG:function saveAsJPEG(){}};}var bHasImageData=!!oCanvas.getContext("2d").getImageData,bHasDataURL=!!oCanvas.toDataURL,bHasBase64=!!window.btoa;// ok, we're good
4113
- var readCanvasData=function readCanvasData(oCanvas){var iWidth=parseInt(oCanvas.width),iHeight=parseInt(oCanvas.height);return oCanvas.getContext("2d").getImageData(0,0,iWidth,iHeight);};// base64 encodes either a string or an array of charcodes
4114
- var encodeData=function encodeData(data){var i,aData,strData="";if(typeof data=="string"){strData=data;}else{aData=data;for(i=0;i<aData.length;i++){strData+=sc(aData[i]);}}return btoa(strData);};// creates a base64 encoded string containing BMP data takes an imagedata object as argument
4115
- var createBMP=function createBMP(oData){var strHeader='';var iWidth=oData.width;var iHeight=oData.height;strHeader+='BM';var iFileSize=iWidth*iHeight*4+54;// total header size = 54 bytes
4116
- strHeader+=sc(iFileSize%256);iFileSize=Math.floor(iFileSize/256);strHeader+=sc(iFileSize%256);iFileSize=Math.floor(iFileSize/256);strHeader+=sc(iFileSize%256);iFileSize=Math.floor(iFileSize/256);strHeader+=sc(iFileSize%256);strHeader+=sc(0,0,0,0,54,0,0,0);// data offset
4117
- strHeader+=sc(40,0,0,0);// info header size
4118
- var iImageWidth=iWidth;strHeader+=sc(iImageWidth%256);iImageWidth=Math.floor(iImageWidth/256);strHeader+=sc(iImageWidth%256);iImageWidth=Math.floor(iImageWidth/256);strHeader+=sc(iImageWidth%256);iImageWidth=Math.floor(iImageWidth/256);strHeader+=sc(iImageWidth%256);var iImageHeight=iHeight;strHeader+=sc(iImageHeight%256);iImageHeight=Math.floor(iImageHeight/256);strHeader+=sc(iImageHeight%256);iImageHeight=Math.floor(iImageHeight/256);strHeader+=sc(iImageHeight%256);iImageHeight=Math.floor(iImageHeight/256);strHeader+=sc(iImageHeight%256);strHeader+=sc(1,0,32,0);// num of planes & num of bits per pixel
4119
- strHeader+=sc(0,0,0,0);// compression = none
4120
- var iDataSize=iWidth*iHeight*4;strHeader+=sc(iDataSize%256);iDataSize=Math.floor(iDataSize/256);strHeader+=sc(iDataSize%256);iDataSize=Math.floor(iDataSize/256);strHeader+=sc(iDataSize%256);iDataSize=Math.floor(iDataSize/256);strHeader+=sc(iDataSize%256);strHeader+=sc(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);// these bytes are not used
4121
- var aImgData=oData.data;var strPixelData="";var x;var y=iHeight;var iOffsetX;var iOffsetY;var strPixelRow;do{iOffsetY=iWidth*(y-1)*4;strPixelRow="";for(x=0;x<iWidth;x++){iOffsetX=4*x;strPixelRow+=sc(aImgData[iOffsetY+iOffsetX+2],// B
4122
- aImgData[iOffsetY+iOffsetX+1],// G
4123
- aImgData[iOffsetY+iOffsetX],// R
4124
- aImgData[iOffsetY+iOffsetX+3]// A
4125
- );}strPixelData+=strPixelRow;}while(--y);return encodeData(strHeader+strPixelData);};// sends the generated file to the client
4126
- var saveFile=function saveFile(strData){if(!window.open(strData)){document.location.href=strData;}};var makeDataURI=function makeDataURI(strData,strMime){return"data:"+strMime+";base64,"+strData;};// generates a <img> object containing the imagedata
4127
- var makeImageObject=function makeImageObject(strSource){var oImgElement=document.createElement("img");oImgElement.src=strSource;return oImgElement;};var scaleCanvas=function scaleCanvas(oCanvas,iWidth,iHeight,flipy){if(iWidth&&iHeight){var oSaveCanvas=document.createElement("canvas");oSaveCanvas.width=iWidth;oSaveCanvas.height=iHeight;oSaveCanvas.style.width=iWidth+"px";oSaveCanvas.style.height=iHeight+"px";var oSaveCtx=oSaveCanvas.getContext("2d");if(flipy){oSaveCtx.save();oSaveCtx.scale(1.0,-1.0);oSaveCtx.imageSmoothingEnabled=true;oSaveCtx.drawImage(oCanvas,0,0,oCanvas.width,oCanvas.height,0,0,iWidth,-iHeight);oSaveCtx.restore();}else{oSaveCtx.imageSmoothingEnabled=true;oSaveCtx.drawImage(oCanvas,0,0,oCanvas.width,oCanvas.height,0,0,iWidth,iHeight);}return oSaveCanvas;}return oCanvas;};return{saveAsPNG:function saveAsPNG(oCanvas,bReturnImg,iWidth,iHeight,flipy){if(!bHasDataURL)return false;var oScaledCanvas=scaleCanvas(oCanvas,iWidth,iHeight,flipy);var strMime="image/png";var strData=oScaledCanvas.toDataURL(strMime);if(bReturnImg){return makeImageObject(strData);}else{saveFile(strData);}return true;},saveAsJPEG:function saveAsJPEG(oCanvas,bReturnImg,iWidth,iHeight,flipy){if(!bHasDataURL)return false;var oScaledCanvas=scaleCanvas(oCanvas,iWidth,iHeight,flipy);var strMime="image/jpeg";var strData=oScaledCanvas.toDataURL(strMime);// check if browser actually supports jpeg by looking for the mime type in the data uri. if not, return false
4128
- if(strData.indexOf(strMime)!=5)return false;if(bReturnImg){return makeImageObject(strData);}else{saveFile(strData);}return true;},saveAsBMP:function saveAsBMP(oCanvas,bReturnImg,iWidth,iHeight,flipy){if(!(bHasDataURL&&bHasImageData&&bHasBase64))return false;var oScaledCanvas=scaleCanvas(oCanvas,iWidth,iHeight,flipy);var strMime="image/bmp";var oData=readCanvasData(oScaledCanvas),strImgData=createBMP(oData);if(bReturnImg){return makeImageObject(makeDataURI(strImgData,strMime));}else{saveFile(makeDataURI(strImgData,strMime));}return true;}};}();/**
4101
+ }function gaussian(x,stdDev){return Math.exp(-(x*x)/(2.0*(stdDev*stdDev)))/(Math.sqrt(2.0*Math.PI)*stdDev);}function createSampleOffsets(kernelRadius,uvIncrement){var offsets=[];for(var _i53=0;_i53<=kernelRadius;_i53++){offsets.push(uvIncrement[0]*_i53);offsets.push(uvIncrement[1]*_i53);}return offsets;}/**
4129
4102
  * @desc Represents a WebGL render buffer.
4130
4103
  * @private
4131
4104
  */var RenderBuffer=/*#__PURE__*/function(){function RenderBuffer(canvas,gl,options){_classCallCheck(this,RenderBuffer);options=options||{};this.gl=gl;this.allocated=false;this.canvas=canvas;this.buffer=null;this.bound=false;this.size=options.size;this._hasDepthTexture=!!options.depthTexture;}_createClass(RenderBuffer,[{key:"setSize",value:function setSize(size){this.size=size;}},{key:"webglContextRestored",value:function webglContextRestored(gl){this.gl=gl;this.buffer=null;this.allocated=false;this.bound=false;}},{key:"bind",value:function bind(){this._touch();if(this.bound){return;}var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,this.buffer.framebuf);this.bound=true;}},{key:"_touch",value:function _touch(){var width;var height;var gl=this.gl;if(this.size){width=this.size[0];height=this.size[1];}else{width=gl.drawingBufferWidth;height=gl.drawingBufferHeight;}if(this.buffer){if(this.buffer.width===width&&this.buffer.height===height){return;}else{gl.deleteTexture(this.buffer.texture);gl.deleteFramebuffer(this.buffer.framebuf);gl.deleteRenderbuffer(this.buffer.renderbuf);}}var colorTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,colorTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,width,height,0,gl.RGBA,gl.UNSIGNED_BYTE,null);var depthTexture;if(this._hasDepthTexture){depthTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,depthTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texImage2D(gl.TEXTURE_2D,0,gl.DEPTH_COMPONENT32F,width,height,0,gl.DEPTH_COMPONENT,gl.FLOAT,null);}var renderbuf=gl.createRenderbuffer();gl.bindRenderbuffer(gl.RENDERBUFFER,renderbuf);gl.renderbufferStorage(gl.RENDERBUFFER,gl.DEPTH_COMPONENT32F,width,height);var framebuf=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,framebuf);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,colorTexture,0);if(this._hasDepthTexture){gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.TEXTURE_2D,depthTexture,0);}else{gl.framebufferRenderbuffer(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER,renderbuf);}gl.bindTexture(gl.TEXTURE_2D,null);gl.bindRenderbuffer(gl.RENDERBUFFER,null);gl.bindFramebuffer(gl.FRAMEBUFFER,null);// Verify framebuffer is OK
@@ -4137,8 +4110,7 @@ gl.bindFramebuffer(gl.FRAMEBUFFER,framebuf);if(!gl.isFramebuffer(framebuf)){thro
4137
4110
  *
4138
4111
  * @returns {HTMLCanvasElement}
4139
4112
  */},{key:"readImageAsCanvas",value:function readImageAsCanvas(){var gl=this.gl;var imageDataCache=this._getImageDataCache();var pixelData=imageDataCache.pixelData;var canvas=imageDataCache.canvas;var imageData=imageDataCache.imageData;var context=imageDataCache.context;gl.readPixels(0,0,this.buffer.width,this.buffer.height,gl.RGBA,gl.UNSIGNED_BYTE,pixelData);var width=this.buffer.width;var height=this.buffer.height;var halfHeight=height/2|0;// the | 0 keeps the result an int
4140
- var bytesPerRow=width*4;var temp=new Uint8Array(width*4);for(var y=0;y<halfHeight;++y){var topOffset=y*bytesPerRow;var bottomOffset=(height-y-1)*bytesPerRow;temp.set(pixelData.subarray(topOffset,topOffset+bytesPerRow));pixelData.copyWithin(topOffset,bottomOffset,bottomOffset+bytesPerRow);pixelData.set(temp,bottomOffset);}imageData.data.set(pixelData);context.putImageData(imageData,0,0);return canvas;}},{key:"readImage",value:function readImage(params){var gl=this.gl;var imageDataCache=this._getImageDataCache();var pixelData=imageDataCache.pixelData;var canvas=imageDataCache.canvas;var imageData=imageDataCache.imageData;var context=imageDataCache.context;gl.readPixels(0,0,this.buffer.width,this.buffer.height,gl.RGBA,gl.UNSIGNED_BYTE,pixelData);imageData.data.set(pixelData);context.putImageData(imageData,0,0);var imageWidth=params.width||canvas.width;var imageHeight=params.height||canvas.height;var format=params.format||"jpeg";var flipy=true;// Account for WebGL texture flipping
4141
- var image;switch(format){case"jpeg":image=Canvas2Image.saveAsJPEG(canvas,true,imageWidth,imageHeight,flipy);break;case"png":image=Canvas2Image.saveAsPNG(canvas,true,imageWidth,imageHeight,flipy);break;case"bmp":image=Canvas2Image.saveAsBMP(canvas,true,imageWidth,imageHeight,flipy);break;default:console.error("Unsupported image format: '"+format+"' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");image=Canvas2Image.saveAsJPEG(canvas,true,imageWidth,imageHeight,flipy);}return image.src;}},{key:"_getImageDataCache",value:function _getImageDataCache(){var bufferWidth=this.buffer.width;var bufferHeight=this.buffer.height;var imageDataCache=this._imageDataCache;if(imageDataCache){if(imageDataCache.width!==bufferWidth||imageDataCache.height!==bufferHeight){this._imageDataCache=null;imageDataCache=null;}}if(!imageDataCache){var _canvas=document.createElement('canvas');_canvas.width=bufferWidth;_canvas.height=bufferHeight;var context=_canvas.getContext('2d');imageDataCache={pixelData:new Uint8Array(bufferWidth*bufferHeight*4),canvas:_canvas,context:context,imageData:context.createImageData(bufferWidth,bufferHeight),width:bufferWidth,height:bufferHeight};this._imageDataCache=imageDataCache;}imageDataCache.context.resetTransform();// Prevents strange scale-accumulation effect with html2canvas
4113
+ var bytesPerRow=width*4;var temp=new Uint8Array(width*4);for(var y=0;y<halfHeight;++y){var topOffset=y*bytesPerRow;var bottomOffset=(height-y-1)*bytesPerRow;temp.set(pixelData.subarray(topOffset,topOffset+bytesPerRow));pixelData.copyWithin(topOffset,bottomOffset,bottomOffset+bytesPerRow);pixelData.set(temp,bottomOffset);}imageData.data.set(pixelData);context.putImageData(imageData,0,0);return canvas;}},{key:"readImage",value:function readImage(params){var gl=this.gl;var imageDataCache=this._getImageDataCache();var pixelData=imageDataCache.pixelData;var canvas=imageDataCache.canvas;var imageData=imageDataCache.imageData;var context=imageDataCache.context;gl.readPixels(0,0,this.buffer.width,this.buffer.height,gl.RGBA,gl.UNSIGNED_BYTE,pixelData);imageData.data.set(pixelData);context.putImageData(imageData,0,0);var format=params.format||"png";if(format!=="jpeg"&&format!=="png"&&format!=="bmp"){console.error("Unsupported image format: '"+format+"' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");format="png";}return canvas.toDataURL("image/".concat(format));}},{key:"_getImageDataCache",value:function _getImageDataCache(){var bufferWidth=this.buffer.width;var bufferHeight=this.buffer.height;var imageDataCache=this._imageDataCache;if(imageDataCache){if(imageDataCache.width!==bufferWidth||imageDataCache.height!==bufferHeight){this._imageDataCache=null;imageDataCache=null;}}if(!imageDataCache){var _canvas=document.createElement('canvas');_canvas.width=bufferWidth;_canvas.height=bufferHeight;var context=_canvas.getContext('2d');imageDataCache={pixelData:new Uint8Array(bufferWidth*bufferHeight*4),canvas:_canvas,context:context,imageData:context.createImageData(bufferWidth,bufferHeight),width:bufferWidth,height:bufferHeight};this._imageDataCache=imageDataCache;}imageDataCache.context.resetTransform();// Prevents strange scale-accumulation effect with html2canvas
4142
4114
  return imageDataCache;}},{key:"unbind",value:function unbind(){var gl=this.gl;gl.bindFramebuffer(gl.FRAMEBUFFER,null);this.bound=false;}},{key:"getTexture",value:function getTexture(){var self=this;return this._texture||(this._texture={renderBuffer:this,bind:function bind(unit){if(self.buffer&&self.buffer.texture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,self.buffer.texture);return true;}return false;},unbind:function unbind(unit){if(self.buffer&&self.buffer.texture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,null);}}});}},{key:"hasDepthTexture",value:function hasDepthTexture(){return this._hasDepthTexture;}},{key:"getDepthTexture",value:function getDepthTexture(){if(!this._hasDepthTexture){return null;}var self=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function bind(unit){if(self.buffer&&self.buffer.depthTexture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,self.buffer.depthTexture);return true;}return false;},unbind:function unbind(unit){if(self.buffer&&self.buffer.depthTexture){self.gl.activeTexture(self.gl["TEXTURE"+unit]);self.gl.bindTexture(self.gl.TEXTURE_2D,null);}}});}},{key:"destroy",value:function destroy(){if(this.allocated){var _gl2=this.gl;_gl2.deleteTexture(this.buffer.texture);_gl2.deleteTexture(this.buffer.depthTexture);_gl2.deleteFramebuffer(this.buffer.framebuf);_gl2.deleteRenderbuffer(this.buffer.renderbuf);this.allocated=false;this.buffer=null;this.bound=false;}this._imageDataCache=null;this._texture=null;this._depthTexture=null;}}]);return RenderBuffer;}();/**
4143
4115
  * @private
4144
4116
  */var RenderBufferManager=/*#__PURE__*/function(){function RenderBufferManager(scene){_classCallCheck(this,RenderBufferManager);this.scene=scene;this._renderBuffersBasic={};this._renderBuffersScaled={};}_createClass(RenderBufferManager,[{key:"getRenderBuffer",value:function getRenderBuffer(id,options){var renderBuffers=this.scene.canvas.resolutionScale===1.0?this._renderBuffersBasic:this._renderBuffersScaled;var renderBuffer=renderBuffers[id];if(!renderBuffer){renderBuffer=new RenderBuffer(this.scene.canvas.canvas,this.scene.canvas.gl,options);renderBuffers[id]=renderBuffer;}return renderBuffer;}},{key:"destroy",value:function destroy(){for(var id in this._renderBuffersBasic){this._renderBuffersBasic[id].destroy();}for(var _id in this._renderBuffersScaled){this._renderBuffersScaled[_id].destroy();}}}]);return RenderBufferManager;}();/**
@@ -7521,10 +7493,7 @@ for(var _ii=0;_ii<numVertexAttribs;_ii++){gl.disableVertexAttribArray(_ii);}// }
7521
7493
  // Align camera along ray and fire ray through center of canvas
7522
7494
  var pickFrustumMatrix=math.frustumMat4(-1,1,-1,1,0.01,scene.camera.project.far,tempMat4a);if(params.matrix){pickViewMatrix=params.matrix;pickProjMatrix=pickFrustumMatrix;}else{worldRayOrigin.set(params.origin||[0,0,0]);worldRayDir.set(params.direction||[0,0,1]);look=math.addVec3(worldRayOrigin,worldRayDir,tempVec3a);randomVec3[0]=Math.random();randomVec3[1]=Math.random();randomVec3[2]=Math.random();math.normalizeVec3(randomVec3);math.cross3Vec3(worldRayDir,randomVec3,up);pickViewMatrix=math.lookAtMat4v(worldRayOrigin,look,up,tempMat4b);pickProjMatrix=pickFrustumMatrix;pickResult.origin=worldRayOrigin;pickResult.direction=worldRayDir;}canvasPos[0]=canvas.clientWidth*0.5;canvasPos[1]=canvas.clientHeight*0.5;}if(null!==pickViewMatrix){// data-textures: update the pick-camera-matrices of all DataTextureSceneModel's
7523
7495
  for(var type in drawableTypeInfo){if(drawableTypeInfo.hasOwnProperty(type)){var drawableList=drawableTypeInfo[type].drawableList;for(var _i193=0,len=drawableList.length;_i193<len;_i193++){var drawable=drawableList[_i193];if(drawable instanceof DataTextureSceneModel){if(drawable.pickCameraTexture){drawable.pickCameraTexture._updateViewMatrix(pickViewMatrix,pickProjMatrix);}}}}}}var pickBuffer=renderBufferManager.getRenderBuffer("pick");pickBuffer.bind();var pickable=gpuPickPickable(pickBuffer,canvasPos,pickViewMatrix,pickProjMatrix,params,pickResult);if(!pickable){pickBuffer.unbind();return null;}var pickedEntity=pickable.delegatePickedEntity?pickable.delegatePickedEntity():pickable;if(!pickedEntity){pickBuffer.unbind();return null;}if(params.pickSurface){if(params.pickSurfacePrecision&&scene.pickSurfacePrecisionEnabled){// JavaScript-based ray-picking - slow and precise
7524
- if(params.canvasPos){math.canvasPosToWorldRay(scene.canvas.canvas,pickViewMatrix,pickProjMatrix,canvasPos,worldRayOrigin,worldRayDir);}if(pickable.precisionRayPickSurface(worldRayOrigin,worldRayDir,worldSurfacePos,worldSurfaceNormal)){pickResult.worldPos=worldSurfacePos;if(params.pickSurfaceNormal!==false){pickResult.worldNormal=worldSurfaceNormal;}// if (params.pickSurfaceNormal !== false) {
7525
- // gpuPickWorldNormal(pickBuffer, pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
7526
- // }
7527
- pickResult.pickSurfacePrecision=true;}}else{// GPU-based ray-picking - fast and imprecise
7496
+ if(params.canvasPos){math.canvasPosToWorldRay(scene.canvas.canvas,pickViewMatrix,pickProjMatrix,canvasPos,worldRayOrigin,worldRayDir);}if(pickable.precisionRayPickSurface(worldRayOrigin,worldRayDir,worldSurfacePos,worldSurfaceNormal)){pickResult.worldPos=worldSurfacePos;if(params.pickSurfaceNormal!==false){pickResult.worldNormal=worldSurfaceNormal;}pickResult.pickSurfacePrecision=true;}}else{// GPU-based ray-picking - fast and imprecise
7528
7497
  if(pickable.canPickTriangle&&pickable.canPickTriangle()){gpuPickTriangle(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult);pickable.pickTriangleSurface(pickViewMatrix,pickProjMatrix,pickResult);pickResult.pickSurfacePrecision=false;}else{if(pickable.canPickWorldPos&&pickable.canPickWorldPos()){nearAndFar[0]=scene.camera.project.near;nearAndFar[1]=scene.camera.project.far;gpuPickWorldPos(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,nearAndFar,pickResult);if(params.pickSurfaceNormal!==false){gpuPickWorldNormal(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult);}pickResult.pickSurfacePrecision=false;}}}}pickBuffer.unbind();pickResult.entity=pickedEntity;return pickResult;};}();function gpuPickPickable(pickBuffer,canvasPos,pickViewMatrix,pickProjMatrix,params,pickResult){frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw"
7529
7498
  frameCtx.pickOrigin=pickResult.origin;frameCtx.pickViewMatrix=pickViewMatrix;frameCtx.pickProjMatrix=pickProjMatrix;frameCtx.pickInvisible=!!params.pickInvisible;gl.viewport(0,0,gl.drawingBufferWidth,gl.drawingBufferHeight);gl.clearColor(0,0,0,0);gl.enable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);var includeEntityIds=params.includeEntityIds;var excludeEntityIds=params.excludeEntityIds;for(var type in drawableTypeInfo){if(drawableTypeInfo.hasOwnProperty(type)){var drawableInfo=drawableTypeInfo[type];var drawableList=drawableInfo.drawableList;for(var _i194=0,len=drawableList.length;_i194<len;_i194++){var drawable=drawableList[_i194];if(!drawable.drawPickMesh||drawable.culled===true||params.pickInvisible!==true&&drawable.visible===false||drawable.pickable===false){continue;}if(includeEntityIds&&!includeEntityIds[drawable.id]){// TODO: push this logic into drawable
7530
7499
  continue;}if(excludeEntityIds&&excludeEntityIds[drawable.id]){continue;}drawable.drawPickMesh(frameCtx);}}}var resolutionScale=scene.canvas.resolutionScale;var pix=pickBuffer.read(Math.round(canvasPos[0]*resolutionScale),Math.round(canvasPos[1]*resolutionScale));var pickID=pix[0]+pix[1]*256+pix[2]*256*256+pix[3]*256*256*256;if(pickID<0){return;}var pickable=pickIDs.items[pickID];return pickable;}function gpuPickTriangle(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult){if(!pickable.drawPickTriangles){return;}frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw"
@@ -7573,7 +7542,7 @@ this._occlusionTester.unbindRenderBuf();}};/**
7573
7542
  *
7574
7543
  * @private
7575
7544
  * @returns {String} The image data URI.
7576
- */this.readSnapshot=function(params){var snapshotBuffer=renderBufferManager.getRenderBuffer("snapshot");var imageDataURI=snapshotBuffer.readImage(params);return imageDataURI;};/**
7545
+ */this.readSnapshot=function(params){var snapshotBuffer=renderBufferManager.getRenderBuffer("snapshot");return snapshotBuffer.readImage(params);};/**
7577
7546
  * Returns an HTMLCanvas containing an image of the snapshot canvas.
7578
7547
  *
7579
7548
  * - The HTMLCanvas has a CanvasRenderingContext2D.
@@ -19338,7 +19307,7 @@ this._instancingRenderers.occlusionRenderer.drawLayer(frameCtx,this,RENDER_PASSE
19338
19307
  },{key:"drawShadow",value:function drawShadow(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.shadowRenderer){this._instancingRenderers.shadowRenderer.drawLayer(frameCtx,this,RENDER_PASSES.COLOR_OPAQUE);}}//---- PICKING ----------------------------------------------------------------------------------------------------
19339
19308
  },{key:"drawPickMesh",value:function drawPickMesh(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.pickMeshRenderer){this._instancingRenderers.pickMeshRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}},{key:"drawPickDepths",value:function drawPickDepths(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.pickDepthRenderer){this._instancingRenderers.pickDepthRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}},{key:"drawPickNormals",value:function drawPickNormals(renderFlags,frameCtx){if(this._numCulledLayerPortions===this._numPortions||this._numVisibleLayerPortions===0){return;}this._updateBackfaceCull(renderFlags,frameCtx);if(this._instancingRenderers.pickNormalsRenderer){this._instancingRenderers.pickNormalsRenderer.drawLayer(frameCtx,this,RENDER_PASSES.PICK);}}//-----------------------------------------------------------------------------------------
19340
19309
  },{key:"precisionRayPickSurface",value:function precisionRayPickSurface(portionId,worldRayOrigin,worldRayDir,worldSurfacePos,worldNormal){if(!this.model.scene.pickSurfacePrecisionEnabled){return false;}var geometry=this._state.geometry;var state=this._state;var portion=this._portions[portionId];if(!portion){this.model.error("portion not found: "+portionId);return false;}if(!portion.inverseMatrix){portion.inverseMatrix=math.inverseMat4(portion.matrix,math.mat4());}if(worldNormal&&!portion.normalMatrix){portion.normalMatrix=math.transposeMat4(portion.inverseMatrix,math.mat4());}var quantizedPositions=geometry.quantizedPositions;var indices=geometry.indices;var origin=state.origin;var offset=portion.offset;var rtcRayOrigin=tempVec3a$q;var rtcRayDir=tempVec3b$6;rtcRayOrigin.set(origin?math.subVec3(worldRayOrigin,origin,tempVec3c$4):worldRayOrigin);// World -> RTC
19341
- rtcRayDir.set(worldRayDir);if(offset){math.subVec3(rtcRayOrigin,offset);}math.transformRay(this.model.worldNormalMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);math.transformRay(portion.inverseMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);var a=tempVec3d$1;var b=tempVec3e;var c=tempVec3f;var gotIntersect=false;var closestDist=0;var closestIntersectPos=tempVec3g;for(var _i407=0,len=indices.length;_i407<len;_i407+=3){var ia=indices[_i407+0]*3;var ib=indices[_i407+1]*3;var ic=indices[_i407+2]*3;a[0]=quantizedPositions[ia];a[1]=quantizedPositions[ia+1];a[2]=quantizedPositions[ia+2];b[0]=quantizedPositions[ib];b[1]=quantizedPositions[ib+1];b[2]=quantizedPositions[ib+2];c[0]=quantizedPositions[ic];c[1]=quantizedPositions[ic+1];c[2]=quantizedPositions[ic+2];math.decompressPosition(a,state.positionsDecodeMatrix);math.decompressPosition(b,state.positionsDecodeMatrix);math.decompressPosition(c,state.positionsDecodeMatrix);if(math.rayTriangleIntersect(rtcRayOrigin,rtcRayDir,a,b,c,closestIntersectPos)){math.transformPoint3(portion.matrix,closestIntersectPos,closestIntersectPos);math.transformPoint3(this.model.worldMatrix,closestIntersectPos,closestIntersectPos);if(offset){math.addVec3(closestIntersectPos,offset);}if(origin){math.addVec3(closestIntersectPos,origin);}var dist=Math.abs(math.lenVec3(math.subVec3(closestIntersectPos,worldRayOrigin,[])));if(!gotIntersect||dist>closestDist){closestDist=dist;worldSurfacePos.set(closestIntersectPos);if(worldNormal){// Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
19310
+ rtcRayDir.set(worldRayDir);if(offset){math.subVec3(rtcRayOrigin,offset);}math.transformRay(this.model.worldNormalMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);math.transformRay(portion.inverseMatrix,rtcRayOrigin,rtcRayDir,rtcRayOrigin,rtcRayDir);var a=tempVec3d$1;var b=tempVec3e;var c=tempVec3f;var gotIntersect=false;var closestDist=0;var closestIntersectPos=tempVec3g;for(var _i407=0,len=indices.length;_i407<len;_i407+=3){var ia=indices[_i407+0]*3;var ib=indices[_i407+1]*3;var ic=indices[_i407+2]*3;a[0]=quantizedPositions[ia];a[1]=quantizedPositions[ia+1];a[2]=quantizedPositions[ia+2];b[0]=quantizedPositions[ib];b[1]=quantizedPositions[ib+1];b[2]=quantizedPositions[ib+2];c[0]=quantizedPositions[ic];c[1]=quantizedPositions[ic+1];c[2]=quantizedPositions[ic+2];var positionsDecodeMatrix=state.geometry.positionsDecodeMatrix;math.decompressPosition(a,positionsDecodeMatrix);math.decompressPosition(b,positionsDecodeMatrix);math.decompressPosition(c,positionsDecodeMatrix);if(math.rayTriangleIntersect(rtcRayOrigin,rtcRayDir,a,b,c,closestIntersectPos)){math.transformPoint3(portion.matrix,closestIntersectPos,closestIntersectPos);math.transformPoint3(this.model.worldMatrix,closestIntersectPos,closestIntersectPos);if(offset){math.addVec3(closestIntersectPos,offset);}if(origin){math.addVec3(closestIntersectPos,origin);}var dist=Math.abs(math.lenVec3(math.subVec3(closestIntersectPos,worldRayOrigin,[])));if(!gotIntersect||dist>closestDist){closestDist=dist;worldSurfacePos.set(closestIntersectPos);if(worldNormal){// Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
19342
19311
  math.triangleNormal(a,b,c,worldNormal);}gotIntersect=true;}}}if(gotIntersect&&worldNormal){math.transformVec3(portion.normalMatrix,worldNormal,worldNormal);math.transformVec3(this.model.worldNormalMatrix,worldNormal,worldNormal);math.normalizeVec3(worldNormal);}return gotIntersect;}},{key:"destroy",value:function destroy(){var state=this._state;if(state.colorsBuf){state.colorsBuf.destroy();state.colorsBuf=null;}if(state.metallicRoughnessBuf){state.metallicRoughnessBuf.destroy();state.metallicRoughnessBuf=null;}if(state.flagsBuf){state.flagsBuf.destroy();state.flagsBuf=null;}if(state.offsetsBuf){state.offsetsBuf.destroy();state.offsetsBuf=null;}if(state.modelMatrixCol0Buf){state.modelMatrixCol0Buf.destroy();state.modelMatrixCol0Buf=null;}if(state.modelMatrixCol1Buf){state.modelMatrixCol1Buf.destroy();state.modelMatrixCol1Buf=null;}if(state.modelMatrixCol2Buf){state.modelMatrixCol2Buf.destroy();state.modelMatrixCol2Buf=null;}if(state.modelNormalMatrixCol0Buf){state.modelNormalMatrixCol0Buf.destroy();state.modelNormalMatrixCol0Buf=null;}if(state.modelNormalMatrixCol1Buf){state.modelNormalMatrixCol1Buf.destroy();state.modelNormalMatrixCol1Buf=null;}if(state.modelNormalMatrixCol2Buf){state.modelNormalMatrixCol2Buf.destroy();state.modelNormalMatrixCol2Buf=null;}if(state.pickColorsBuf){state.pickColorsBuf.destroy();state.pickColorsBuf=null;}state.destroy();}}]);return TrianglesInstancingLayer;}();var tempVec3a$p=math.vec3();/**
19343
19312
  * @private
19344
19313
  */var LinesBatchingColorRenderer=/*#__PURE__*/function(){function LinesBatchingColorRenderer(scene){_classCallCheck(this,LinesBatchingColorRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(LinesBatchingColorRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,batchingLayer,renderPass){var scene=this._scene;var camera=scene.camera;var model=batchingLayer.model;var gl=scene.canvas.gl;var state=batchingLayer._state;var origin=batchingLayer._state.origin;batchingLayer.geometry;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uViewMatrix,false,origin?createRTCViewMat(camera.viewMatrix,origin):camera.viewMatrix);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);gl.lineWidth(scene.linesMaterial.lineWidth);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=batchingLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex<numSectionPlanes;sectionPlaneIndex++){var sectionPlaneUniforms=this._uSectionPlanes[sectionPlaneIndex];if(sectionPlaneUniforms){var active=renderFlags.sectionPlanesActivePerLayer[baseIndex+sectionPlaneIndex];gl.uniform1i(sectionPlaneUniforms.active,active?1:0);if(active){var sectionPlane=sectionPlanes[sectionPlaneIndex];if(origin){var rtcSectionPlanePos=getPlaneRTCPos(sectionPlane.dist,sectionPlane.dir,origin,tempVec3a$p);gl.uniform3fv(sectionPlaneUniforms.pos,rtcSectionPlanePos);}else{gl.uniform3fv(sectionPlaneUniforms.pos,sectionPlane.pos);}gl.uniform3fv(sectionPlaneUniforms.dir,sectionPlane.dir);}}}}gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,batchingLayer._state.positionsDecodeMatrix);this._aPosition.bindArrayBuffer(state.positionsBuf);if(this._aColor){this._aColor.bindArrayBuffer(state.colorsBuf);}if(this._aFlags){this._aFlags.bindArrayBuffer(state.flagsBuf);}if(this._aOffset){this._aOffset.bindArrayBuffer(state.offsetsBuf);}state.indicesBuf.bind();gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i408=0,len=scene._sectionPlanesState.sectionPlanes.length;_i408<len;_i408++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i408),pos:program.getLocation("sectionPlanePos"+_i408),dir:program.getLocation("sectionPlaneDir"+_i408)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aColor=program.getAttribute("color");this._aFlags=program.getAttribute("flags");if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var project=scene.camera.project;program.bind();gl.uniformMatrix4fv(this._uProjMatrix,false,project.matrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Lines batching color vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform mat4 positionsDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
@@ -23836,6 +23805,10 @@ doublePickFlyTo:true});this._plugins=[];/**
23836
23805
  * Gets a snapshot of this Viewer's {@link Scene} as a Base64-encoded image which includes
23837
23806
  * the HTML elements created by various plugins.
23838
23807
  *
23808
+ * The snapshot image is composed of an image of the viewer canvas, overlaid with an image
23809
+ * of the HTML container element belonging to each installed Viewer plugin. Each container
23810
+ * element is only rendered once, so it's OK for plugins to share the same container.
23811
+ *
23839
23812
  * #### Usage:
23840
23813
  *
23841
23814
  * ````javascript
@@ -23863,7 +23836,7 @@ doublePickFlyTo:true});this._plugins=[];/**
23863
23836
  // canvas ourselves, in order to allow the Viewer to render the
23864
23837
  // right amount of pixels, for a sharper image.
23865
23838
  return new Promise(function(resolve,reject){var needFinishSnapshot=!_this97._snapshotBegun;var resize=params.width!==undefined&&params.height!==undefined;var canvas=_this97.scene.canvas.canvas;var saveWidth=canvas.clientWidth;var saveHeight=canvas.clientHeight;var snapshotWidth=params.width?Math.floor(params.width):canvas.width;var snapshotHeight=params.height?Math.floor(params.height):canvas.height;if(resize){canvas.width=snapshotWidth;canvas.height=snapshotHeight;}if(!_this97._snapshotBegun){_this97.beginSnapshot();}if(!params.includeGizmos){_this97.sendToPlugins("snapshotStarting");// Tells plugins to hide things that shouldn't be in snapshot
23866
- }_this97.scene._renderer.renderSnapshot();var snapshotCanvas=_this97.scene._renderer.readSnapshotAsCanvas();if(resize){canvas.width=saveWidth;canvas.height=saveHeight;_this97.scene.glRedraw();}var pluginToCapture={};var pluginContainerElements=[];var finishSnapshot=function finishSnapshot(){if(!params.includeGizmos){_this97.sendToPlugins("snapshotFinished");}if(needFinishSnapshot){_this97.endSnapshot();}var imageWidth=snapshotCanvas.width;var imageHeight=snapshotCanvas.height;var format=params.format||"jpeg";var flipy=false;var image;switch(format){case"jpeg":image=Canvas2Image.saveAsJPEG(snapshotCanvas,true,imageWidth,imageHeight,flipy);break;case"png":image=Canvas2Image.saveAsPNG(snapshotCanvas,true,imageWidth,imageHeight,flipy);break;case"bmp":image=Canvas2Image.saveAsBMP(snapshotCanvas,true,imageWidth,imageHeight,flipy);break;default:_this97.error("[Viewer.getSnapshotWithPlugins] Unsupported image format: '"+format+"' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'jpeg'");image=Canvas2Image.saveAsJPEG(snapshotCanvas,true,imageWidth,imageHeight,flipy);}if(!params.includeGizmos){_this97.sendToPlugins("snapshotFinished");}if(needFinishSnapshot){_this97.endSnapshot();}resolve(image.src);};for(var _i538=0,len=_this97._plugins.length;_i538<len;_i538++){// Find plugin container elements
23839
+ }_this97.scene._renderer.renderSnapshot();var snapshotCanvas=_this97.scene._renderer.readSnapshotAsCanvas();if(resize){canvas.width=saveWidth;canvas.height=saveHeight;_this97.scene.glRedraw();}var pluginToCapture={};var pluginContainerElements=[];var finishSnapshot=function finishSnapshot(){if(!params.includeGizmos){_this97.sendToPlugins("snapshotFinished");}if(needFinishSnapshot){_this97.endSnapshot();}var format=params.format||"png";if(format!=="jpeg"&&format!=="png"&&format!=="bmp"){console.error("Unsupported image format: '"+format+"' - supported types are 'jpeg', 'bmp' and 'png' - defaulting to 'png'");format="png";}if(!params.includeGizmos){_this97.sendToPlugins("snapshotFinished");}if(needFinishSnapshot){_this97.endSnapshot();}resolve(snapshotCanvas.toDataURL("image/".concat(format)));};for(var _i538=0,len=_this97._plugins.length;_i538<len;_i538++){// Find plugin container elements
23867
23840
  var plugin=_this97._plugins[_i538];if(plugin.getContainerElement){var containerElement=plugin.getContainerElement();if(containerElement!==document.body){if(!pluginToCapture[containerElement.id]){pluginToCapture[containerElement.id]=true;pluginContainerElements.push(containerElement);}}}}if(pluginContainerElements.length>0){// Render plugin container elements to the snapshot canvas
23868
23841
  for(var _i539=0,_len120=pluginContainerElements.length;_i539<_len120;_i539++){var _containerElement=pluginContainerElements[_i539];html2canvas(_containerElement,{canvas:snapshotCanvas,backgroundColor:null,scale:snapshotCanvas.width/_containerElement.clientWidth}).then(function(){pluginContainerElements.pop();if(pluginContainerElements.length===0){finishSnapshot();}});}}else{finishSnapshot();}});}/**
23869
23842
  * Exits snapshot mode.