@arcgis/core 4.26.0-next.20230119 → 4.26.0-next.20230121

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.
Files changed (98) hide show
  1. package/arcade/ArcadeDate.js +1 -1
  2. package/arcade/Feature.js +1 -1
  3. package/arcade/featureset/support/shared.js +1 -1
  4. package/arcade/featureset/support/sqlUtils.js +1 -1
  5. package/arcade/languageUtils.js +1 -1
  6. package/arcade/lib/arcade-parser.js +1 -1
  7. package/arcade/lib/parser.js +1 -1
  8. package/arcade/lib/scanner.js +1 -1
  9. package/arcade/lib/types.js +1 -1
  10. package/arcade/validation/arcadeValidator.js +1 -1
  11. package/arcade/validation/diagnosticMessages.js +1 -1
  12. package/arcade/validation/languageKeywords.js +5 -0
  13. package/assets/esri/core/workers/RemoteClient.js +1 -1
  14. package/assets/esri/core/workers/chunks/{e6c6e3c9750829ec82c1.js → 09ac51aeb0f6fe16aa30.js} +1 -1
  15. package/assets/esri/core/workers/chunks/293594192932f0e00ecf.js +1 -0
  16. package/assets/esri/core/workers/chunks/4f4064eabbbc4a66f95a.js +1 -0
  17. package/assets/esri/core/workers/chunks/{0417369a1d563a6280ff.js → 63706a04e173000994db.js} +1 -1
  18. package/assets/esri/core/workers/chunks/6a90b1d73d5941ebb112.js +1 -0
  19. package/assets/esri/core/workers/chunks/{0c242aa92ab4f0c996db.js → 70f1fe5f36bc4abff2d2.js} +1 -1
  20. package/assets/esri/core/workers/chunks/96d4c50f74a9c0dcdb66.js +1 -0
  21. package/assets/esri/core/workers/chunks/b26a671d3523b8a48404.js +1 -0
  22. package/assets/esri/core/workers/chunks/{5dfed65b615b33588488.js → db96a2dc1879b4944cb8.js} +1 -1
  23. package/assets/esri/core/workers/chunks/fcf033c581f58d006cf6.js +1 -0
  24. package/assets/esri/core/workers/chunks/{5e872adb3a5e84c49865.js → fde8827bd7f1a97a6db3.js} +1 -1
  25. package/assets/esri/themes/base/widgets/_Editor.scss +9 -14
  26. package/assets/esri/themes/dark/main.css +1 -1
  27. package/assets/esri/themes/light/main.css +1 -1
  28. package/assets/esri/themes/light/view.css +1 -1
  29. package/chunks/languageUtils.js +1 -1
  30. package/core/scheduling.js +1 -1
  31. package/interfaces.d.ts +24 -12
  32. package/layers/StreamLayer.js +1 -1
  33. package/layers/VoxelWasmPerSceneView.js +1 -1
  34. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  35. package/layers/graphics/controllers/StreamController.js +1 -1
  36. package/layers/graphics/data/StreamFeatureManager.js +1 -1
  37. package/layers/graphics/sources/connections/GeoEventConnection.js +1 -1
  38. package/layers/graphics/sources/connections/WebSocketConnection.js +1 -1
  39. package/layers/support/FeatureReductionBinning.js +1 -1
  40. package/layers/support/FeatureReductionCluster.js +1 -1
  41. package/layers/support/StreamConnection.js +1 -1
  42. package/layers/support/rasterDatasets/ImageServerRaster.js +1 -1
  43. package/layers/support/rasterFormats/pixelRangeUtils.js +1 -1
  44. package/layers/support/rasterFunctions/rasterProjectionHelper.js +1 -1
  45. package/package.json +1 -1
  46. package/support/revision.js +1 -1
  47. package/views/2d/interactive/editingTools/ControlPointsTransformTool.js +1 -1
  48. package/views/2d/interactive/editingTools/MediaTransformToolsWrapper.js +1 -1
  49. package/views/2d/interactive/editingTools/TransformTool.js +1 -1
  50. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  51. package/views/2d/layers/StreamLayerView2D.js +1 -1
  52. package/views/2d/layers/features/controllers/FeatureController2D.js +1 -1
  53. package/views/2d/layers/features/schemaUtils.js +1 -1
  54. package/views/2d/layers/features/sources/GeoEventSource.js +1 -1
  55. package/views/2d/layers/features/support/FeatureSetReader.js +1 -1
  56. package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
  57. package/views/2d/layers/support/FeatureLayerProxy.js +1 -1
  58. package/views/3d/environment/EnvironmentRenderer.js +1 -1
  59. package/views/3d/environment/SceneViewEnvironmentManager.js +1 -1
  60. package/views/3d/layers/DynamicLayerView3D.js +1 -1
  61. package/views/3d/layers/I3SMeshView3D.js +1 -1
  62. package/views/3d/layers/I3SMeshViewLabeler.js +1 -1
  63. package/views/3d/layers/PointCloudLayerView3D.js +1 -1
  64. package/views/3d/layers/PointCloudWorker.js +1 -1
  65. package/views/3d/layers/RouteLayerView3D.js +1 -1
  66. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  67. package/views/3d/layers/SceneLayerView3D.js +1 -1
  68. package/views/3d/layers/StreamLayerView3D.js +1 -1
  69. package/views/3d/layers/TileLayerView3D.js +1 -1
  70. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  71. package/views/3d/layers/i3s/I3SLodHandling.js +1 -1
  72. package/views/3d/layers/i3s/I3SMaterialUtil.js +1 -1
  73. package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
  74. package/views/3d/layers/i3s/I3SNodeLoader.js +1 -1
  75. package/views/3d/layers/i3s/I3SQueryEngine.js +1 -1
  76. package/views/3d/layers/i3s/PointCloudRendererUtil.js +1 -1
  77. package/views/3d/layers/i3s/PointCloudWorkerUtil.js +1 -1
  78. package/views/3d/layers/support/FeatureTileTree3D.js +1 -1
  79. package/views/3d/layers/support/I3STreeDebugger.js +1 -1
  80. package/views/3d/layers/support/SceneLayerViewRequiredFields.js +1 -1
  81. package/views/3d/terrain/TerrainSurface.js +1 -1
  82. package/views/3d/webgl-engine/core/shaderLibrary/shading/ScreenSpaceReflections.glsl.js +1 -1
  83. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  84. package/views/PopupView.js +1 -1
  85. package/views/SceneView.js +1 -1
  86. package/views/interactive/SegmentLabels.js +1 -1
  87. package/views/layers/ImageryLayerView.js +1 -1
  88. package/views/layers/SceneLayerView.js +1 -1
  89. package/views/layers/StreamLayerView.js +1 -1
  90. package/widgets/Editor.js +1 -1
  91. package/widgets/Fullscreen/FullscreenViewModel.js +1 -1
  92. package/widgets/Home/HomeViewModel.js +1 -1
  93. package/assets/esri/core/workers/chunks/0efee8d9fc5632346cb4.js +0 -1
  94. package/assets/esri/core/workers/chunks/10e715aa4ac96d7dd1b4.js +0 -1
  95. package/assets/esri/core/workers/chunks/2dfb17fa5b6a5d239942.js +0 -1
  96. package/assets/esri/core/workers/chunks/2e3962506c353b562a88.js +0 -1
  97. package/assets/esri/core/workers/chunks/7320e6d8f207399bc8f1.js +0 -1
  98. package/assets/esri/core/workers/chunks/a194f90ffe13b3d448b0.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{isNone as e,isSome as o}from"../../../../core/maybe.js";import r from"../../../../renderers/PointCloudClassBreaksRenderer.js";import t from"../../../../renderers/PointCloudStretchRenderer.js";import l from"../../../../renderers/PointCloudUniqueValueRenderer.js";import{createGeometryIndexFromSchema as n,createTypedView as s,readBinaryAttribute as i}from"./I3SBinaryReader.js";import{decodeXYZ as u}from"./LEPCC.js";function f(e,o,n,s){const{rendererJSON:i,isRGBRenderer:u}=e;let f=null,c=null;if(o&&u)f=o;else if(o&&"pointCloudUniqueValueRenderer"===i.type){c=l.fromJSON(i);const e=c.colorUniqueValueInfos;f=new Uint8Array(3*s);const r=p(c.fieldTransformType);for(let t=0;t<s;t++){const l=(r?r(o[t]):o[t])+"";for(let o=0;o<e.length;o++)if(e[o].values.includes(l)){f[3*t]=e[o].color.r,f[3*t+1]=e[o].color.g,f[3*t+2]=e[o].color.b;break}}}else if(o&&"pointCloudStretchRenderer"===i.type){c=t.fromJSON(i);const e=c.stops;f=new Uint8Array(3*s);const r=p(c.fieldTransformType);for(let t=0;t<s;t++){const l=r?r(o[t]):o[t],n=e.length-1;if(l<e[0].value)f[3*t]=e[0].color.r,f[3*t+1]=e[0].color.g,f[3*t+2]=e[0].color.b;else if(l>=e[n].value)f[3*t]=e[n].color.r,f[3*t+1]=e[n].color.g,f[3*t+2]=e[n].color.b;else for(let o=1;o<e.length;o++)if(l<e[o].value){const r=(l-e[o-1].value)/(e[o].value-e[o-1].value);f[3*t]=e[o].color.r*r+e[o-1].color.r*(1-r),f[3*t+1]=e[o].color.g*r+e[o-1].color.g*(1-r),f[3*t+2]=e[o].color.b*r+e[o-1].color.b*(1-r);break}}}else if(o&&"pointCloudClassBreaksRenderer"===i.type){c=r.fromJSON(i);const e=c.colorClassBreakInfos;f=new Uint8Array(3*s);const t=p(c.fieldTransformType);for(let r=0;r<s;r++){const l=t?t(o[r]):o[r];for(let o=0;o<e.length;o++)if(l>=e[o].minValue&&l<=e[o].maxValue){f[3*r]=e[o].color.r,f[3*r+1]=e[o].color.g,f[3*r+2]=e[o].color.b;break}}}else{f=new Uint8Array(3*s);for(let e=0;e<f.length;e++)f[e]=255}if(n&&c&&c.colorModulation){const e=c.colorModulation.minValue,o=c.colorModulation.maxValue,r=.3;for(let t=0;t<s;t++){const l=n[t],s=l>=o?1:l<=e?r:r+(1-r)*(l-e)/(o-e);f[3*t]=s*f[3*t],f[3*t+1]=s*f[3*t+1],f[3*t+2]=s*f[3*t+2]}}return f}function c(o,r){if(null==o.encoding||""===o.encoding){const t=n(r,o);if(e(t.vertexAttributes.position))return;const l=s(r,t.vertexAttributes.position),i=t.header.fields,u=[i.offsetX,i.offsetY,i.offsetZ],f=[i.scaleX,i.scaleY,i.scaleZ],c=l.length/3,a=new Float64Array(3*c);for(let e=0;e<c;e++)a[3*e]=l[3*e]*f[0]+u[0],a[3*e+1]=l[3*e+1]*f[1]+u[1],a[3*e+2]=l[3*e+2]*f[2]+u[2];return a}if("lepcc-xyz"===o.encoding)return u(r).result}function a(e,r,t){return o(e)&&e.attributeInfo.useElevation?d(r,t):o(e)?i(e.attributeInfo.storageInfo,e.buffer,t):null}function d(e,o){const r=new Float64Array(o);for(let t=0;t<o;t++)r[t]=e[3*t+2];return r}function m(e,o,r,t,l){const n=e.length/3;let s=0;for(let i=0;i<n;i++){let n=!0;for(let e=0;e<t.length&&n;e++){const{filterJSON:o}=t[e],r=l[e].values[i];switch(o.type){case"pointCloudValueFilter":{const e="exclude"===o.mode;o.values.includes(r)===e&&(n=!1);break}case"pointCloudBitfieldFilter":{const e=b(o.requiredSetBits),t=b(o.requiredClearBits);(r&e)===e&&0==(r&t)||(n=!1);break}case"pointCloudReturnFilter":{const e=15&r,t=r>>>4&15,l=t>1,s=1===e,i=e===t;let u=!1;for(const r of o.includedReturns)if("last"===r&&i||"firstOfMany"===r&&s&&l||"lastOfMany"===r&&i&&l||"single"===r&&!l){u=!0;break}u||(n=!1);break}}}n&&(r[s]=i,e[3*s]=e[3*i],e[3*s+1]=e[3*i+1],e[3*s+2]=e[3*i+2],o[3*s]=o[3*i],o[3*s+1]=o[3*i+1],o[3*s+2]=o[3*i+2],s++)}return s}function p(e){return null==e||"none"===e?null:"low-four-bit"===e?e=>15&e:"high-four-bit"===e?e=>(240&e)>>4:"absolute-value"===e?e=>Math.abs(e):"modulo-ten"===e?e=>e%10:null}function b(e){let o=0;for(const r of e||[])o|=1<<r;return o}export{d as elevationFromPositions,f as evaluateRenderer,m as filterInPlace,a as getAttributeValues,c as readGeometry};
5
+ import{isNone as e,isSome as o}from"../../../../core/maybe.js";import r from"../../../../renderers/PointCloudClassBreaksRenderer.js";import t from"../../../../renderers/PointCloudStretchRenderer.js";import l from"../../../../renderers/PointCloudUniqueValueRenderer.js";import{createGeometryIndexFromSchema as n,createTypedView as s,readBinaryAttribute as i}from"./I3SBinaryReader.js";import{decodeXYZ as u}from"./LEPCC.js";function f(e,o,n,s){const{rendererJSON:i,isRGBRenderer:u}=e;let f=null,c=null;if(o&&u)f=o;else if(o&&"pointCloudUniqueValueRenderer"===i?.type){c=l.fromJSON(i);const e=c.colorUniqueValueInfos;f=new Uint8Array(3*s);const r=b(c.fieldTransformType);for(let t=0;t<s;t++){const l=(r?r(o[t]):o[t])+"";for(let o=0;o<e.length;o++)if(e[o].values.includes(l)){f[3*t]=e[o].color.r,f[3*t+1]=e[o].color.g,f[3*t+2]=e[o].color.b;break}}}else if(o&&"pointCloudStretchRenderer"===i?.type){c=t.fromJSON(i);const e=c.stops;f=new Uint8Array(3*s);const r=b(c.fieldTransformType);for(let t=0;t<s;t++){const l=r?r(o[t]):o[t],n=e.length-1;if(l<e[0].value)f[3*t]=e[0].color.r,f[3*t+1]=e[0].color.g,f[3*t+2]=e[0].color.b;else if(l>=e[n].value)f[3*t]=e[n].color.r,f[3*t+1]=e[n].color.g,f[3*t+2]=e[n].color.b;else for(let o=1;o<e.length;o++)if(l<e[o].value){const r=(l-e[o-1].value)/(e[o].value-e[o-1].value);f[3*t]=e[o].color.r*r+e[o-1].color.r*(1-r),f[3*t+1]=e[o].color.g*r+e[o-1].color.g*(1-r),f[3*t+2]=e[o].color.b*r+e[o-1].color.b*(1-r);break}}}else if(o&&"pointCloudClassBreaksRenderer"===i?.type){c=r.fromJSON(i);const e=c.colorClassBreakInfos;f=new Uint8Array(3*s);const t=b(c.fieldTransformType);for(let r=0;r<s;r++){const l=t?t(o[r]):o[r];for(let o=0;o<e.length;o++)if(l>=e[o].minValue&&l<=e[o].maxValue){f[3*r]=e[o].color.r,f[3*r+1]=e[o].color.g,f[3*r+2]=e[o].color.b;break}}}else{f=new Uint8Array(3*s);for(let e=0;e<f.length;e++)f[e]=255}if(n&&c&&c.colorModulation){const e=c.colorModulation.minValue,o=c.colorModulation.maxValue,r=.3;for(let t=0;t<s;t++){const l=n[t],s=l>=o?1:l<=e?r:r+(1-r)*(l-e)/(o-e);f[3*t]=s*f[3*t],f[3*t+1]=s*f[3*t+1],f[3*t+2]=s*f[3*t+2]}}return f}function c(o,r){if(null==o.encoding||""===o.encoding){const t=n(r,o);if(e(t.vertexAttributes.position))return;const l=s(r,t.vertexAttributes.position),i=t.header.fields,u=[i.offsetX,i.offsetY,i.offsetZ],f=[i.scaleX,i.scaleY,i.scaleZ],c=l.length/3,a=new Float64Array(3*c);for(let e=0;e<c;e++)a[3*e]=l[3*e]*f[0]+u[0],a[3*e+1]=l[3*e+1]*f[1]+u[1],a[3*e+2]=l[3*e+2]*f[2]+u[2];return a}if("lepcc-xyz"===o.encoding)return u(r).result}function a(e,r,t){return o(e)&&e.attributeInfo.useElevation?r?d(r,t):null:o(e)&&e.attributeInfo.storageInfo?i(e.attributeInfo.storageInfo,e.buffer,t):null}function d(e,o){const r=new Float64Array(o);for(let t=0;t<o;t++)r[t]=e[3*t+2];return r}function m(e,o,r,t,l){const n=e.length/3;let s=0;for(let i=0;i<n;i++){let n=!0;for(let e=0;e<t.length&&n;e++){const{filterJSON:o}=t[e],r=l[e].values[i];switch(o.type){case"pointCloudValueFilter":{const e="exclude"===o.mode;o.values.includes(r)===e&&(n=!1);break}case"pointCloudBitfieldFilter":{const e=p(o.requiredSetBits),t=p(o.requiredClearBits);(r&e)===e&&0==(r&t)||(n=!1);break}case"pointCloudReturnFilter":{const e=15&r,t=r>>>4&15,l=t>1,s=1===e,i=e===t;let u=!1;for(const r of o.includedReturns)if("last"===r&&i||"firstOfMany"===r&&s&&l||"lastOfMany"===r&&i&&l||"single"===r&&!l){u=!0;break}u||(n=!1);break}}}n&&(r[s]=i,e[3*s]=e[3*i],e[3*s+1]=e[3*i+1],e[3*s+2]=e[3*i+2],o[3*s]=o[3*i],o[3*s+1]=o[3*i+1],o[3*s+2]=o[3*i+2],s++)}return s}function b(e){return null==e||"none"===e?null:"low-four-bit"===e?e=>15&e:"high-four-bit"===e?e=>(240&e)>>4:"absolute-value"===e?e=>Math.abs(e):"modulo-ten"===e?e=>e%10:null}function p(e){let o=0;for(const r of e||[])o|=1<<r;return o}export{d as elevationFromPositions,f as evaluateRenderer,m as filterInPlace,a as getAttributeValues,c as readGeometry};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import i from"../../../../core/Collection.js";import s from"../../../../core/Handles.js";import r from"../../../../core/Logger.js";import{isSome as n,isNone as o,removeMaybe as l,destroyMaybe as h}from"../../../../core/maybe.js";import a from"../../../../core/PooledArray.js";import{watch as c,sync as d,syncAndInitial as p}from"../../../../core/reactiveUtils.js";import{property as u}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as _}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as m,empty as f,expand as g,height as y,intersects as T}from"../../../../geometry/support/aaBoundingRect.js";import{FeatureTileDescriptor3D as S,Visibility as E}from"./FeatureTileDescriptor3D.js";import{FeatureTileMeasurements3D as v}from"./FeatureTileMeasurements3D.js";import{toBoundingRect as w}from"../../support/extentUtils.js";import{TaskPriority as R,noBudget as x}from"../../../support/Scheduler.js";let C=class extends t{get tilingScheme(){const e=this.tilingSchemeOwner.tilingScheme;if(!e)return null;return e.clone()}set filterExtent(e){if(n(e)&&!e.spatialReference.equals(this.viewState.spatialReference))return void r.getLogger(this.declaredClass).error("#extent","extent spatial reference needs to be in the same spatial reference as the view");const t=this._get("filterExtent");if(t===e||n(t)&&e&&t.equals(e))return;const i=n(e)?e.clone():null;this._set("filterExtent",i),this._setDirty()}get _filterExtentRect(){if(o(this.filterExtent)||!this.tilingScheme)return null;const e=m();return w(this.filterExtent,e,this.tilingScheme.spatialReference),e}get _rootTileIds(){return this._filterExtentRect?this.tilingScheme.rootTilesInExtent(this._filterExtentRect):[[0,0,0]]}set suspended(e){e!==this._get("suspended")&&(this._set("suspended",e),this._setDirty())}get updating(){return this._dirty||!!this._pendingTiles}constructor(e){super(e),this.tiles=new i,this.tileSize=512,this._idToTile=new Map,this._handles=new s,this._clients=new Set,this._dirty=!1,this._newTiles=new a}initialize(){this._handles.add([c((()=>[this.tilingScheme,this.tileSize]),(()=>this._reset()),d),c((()=>[this.tileSize,this.cameraOnSurface?.location,this.tilingScheme,this.viewState?.contentCamera,this.focus?.location]),(()=>this._setDirty()),p)]),this.scheduler&&(this._frameWorker=this.scheduler.registerTask(R.FEATURE_TILE_TREE,this))}destroy(){this._frameWorker=l(this._frameWorker),this._handles=h(this._handles)}addClient(){const e=O();return this._clients.add(e),1===this._clients.size&&this._setDirty(),{remove:()=>this._removeClient(e)}}_removeClient(e){this._clients.delete(e),this._hasClients||this._clear()}get _hasClients(){return this._clients.size>0}_setDirty(){!this._hasClients||this.suspended||this._dirty||(this._frameWorker?(this._dirty=!0,this.notifyChange("updating")):this.runTask(x))}_clear(){this.tiles.removeAll(),this._idToTile.clear(),this._reset(),this._dirty=!1,this.notifyChange("updating")}get running(){return this.updating}runTask(e){this._dirty=!1,this._pendingTiles||(this._startUpdate(),n(this._frameWorker)&&(this._frameWorker.priority=R.FEATURE_TILE_TREE_ACTIVE)),this._subdivideTilesForView(e),!this._pendingTiles&&n(this._frameWorker)&&(this._frameWorker.priority=R.FEATURE_TILE_TREE),this.notifyChange("updating")}_startUpdate(){if(this.suspended)return;if(!this.tilingScheme)return void this._clear();this._tileMeasurements||(this._tileMeasurements=new v({renderCoordsHelper:this.renderCoordsHelper,tilingScheme:this.tilingScheme,tileSize:this.tileSize}));const e=this.viewState.contentCamera;this._tileMeasurements.begin(e,this.focus.location,this.cameraOnSurface.location.z),this._pendingTiles=this._getRootTiles()}_reset(){this._newTiles.clear(),this._tileMeasurements=null,this._pendingTiles=null,this._setDirty()}_getRootTiles(){return this._rootTileIds.map((e=>new S(e[0],e[1],e[2],this.tilingScheme)))}_purgeHorizonTiles(e){e.sort(((e,t)=>{const i=e.measures.screenRect,s=t.measures.screenRect;return i[1]+i[3]-(s[1]+s[3])})),f(I);for(let t=0;t<e.length;t++)if(g(I,e.data[t].measures.screenRect,I),y(I)>k)return e.data.slice(t,e.length);return[]}_subdivideTilesForView(e){if(this._pendingTiles){for(;this._pendingTiles.length>0&&!e.done;){const t=this._pendingTiles.pop();e.madeProgress(),this._filterExtentRect&&!T(this._filterExtentRect,t.extent)||(this._tileMeasurements.updateTile(t),t.measures.visibility!==E.INVISIBLE&&(t.measures.shouldSplit?(this.tilingScheme.ensureMaxLod(t.lij[0]+1),this._pendingTiles.push(...t.getChildren())):this._newTiles.push(t)))}0===this._pendingTiles.length&&(this._updateTiles(this._purgeHorizonTiles(this._newTiles)),this._newTiles.clear(),this._tileMeasurements.end(),this._pendingTiles=null)}}_updateTiles(e){for(const s of this.tiles.items)s.used=!1;const t=e.filter((e=>{const t=this._idToTile.get(e.id);return t?(t.copyMeasurementsFrom(e),t.used=!0):this._idToTile.set(e.id,e),!t})),i=this.tiles.items.filter((e=>!e.used&&(this._idToTile.delete(e.id),!0)));this.tiles.removeMany(i),this.tiles.addMany(t),this._sortTiles()}_sortTiles(){this.viewState.fixedContentCamera||this.tiles.sort(((e,t)=>e.measures.visibility!==t.measures.visibility?e.measures.visibility===E.VISIBLE_ON_SURFACE?-1:1:e.measures.distance-t.measures.distance)),this.tiles.forEach(((e,t)=>e.loadPriority=t))}};e([u({constructOnly:!0})],C.prototype,"scheduler",void 0),e([u({constructOnly:!0})],C.prototype,"renderCoordsHelper",void 0),e([u({constructOnly:!0})],C.prototype,"tilingSchemeOwner",void 0),e([u({constructOnly:!0})],C.prototype,"cameraOnSurface",void 0),e([u({constructOnly:!0})],C.prototype,"focus",void 0),e([u({constructOnly:!0})],C.prototype,"viewState",void 0),e([u({constructOnly:!0})],C.prototype,"terrain",void 0),e([u()],C.prototype,"tiles",void 0),e([u()],C.prototype,"tileSize",void 0),e([u({readOnly:!0})],C.prototype,"tilingScheme",null),e([u()],C.prototype,"filterExtent",null),e([u({readOnly:!0})],C.prototype,"_filterExtentRect",null),e([u({readOnly:!0})],C.prototype,"_rootTileIds",null),e([u({value:!1})],C.prototype,"suspended",null),e([u({readOnly:!0})],C.prototype,"updating",null),C=e([_("esri.views.3d.layers.support.FeatureTileTree3D")],C);let j=0;function O(){return j++}const I=m(),k=10;export{C as FeatureTileTree3D};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import i from"../../../../core/Collection.js";import s from"../../../../core/Handles.js";import r from"../../../../core/Logger.js";import{isSome as n,isNone as o,removeMaybe as l,destroyMaybe as h}from"../../../../core/maybe.js";import a from"../../../../core/PooledArray.js";import{watch as c,sync as d,syncAndInitial as u}from"../../../../core/reactiveUtils.js";import{property as p}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as _}from"../../../../core/accessorSupport/decorators/subclass.js";import{create as m,empty as f,expand as g,height as T,intersects as y}from"../../../../geometry/support/aaBoundingRect.js";import{FeatureTileDescriptor3D as S,Visibility as E}from"./FeatureTileDescriptor3D.js";import{FeatureTileMeasurements3D as v}from"./FeatureTileMeasurements3D.js";import{toBoundingRect as w}from"../../support/extentUtils.js";import{TaskPriority as R,noBudget as x}from"../../../support/Scheduler.js";let C=class extends t{get tilingScheme(){const e=this.tilingSchemeOwner.tilingScheme;if(!e)return null;return e.clone()}set filterExtent(e){if(n(e)&&!e.spatialReference.equals(this.viewState.spatialReference))return void r.getLogger(this.declaredClass).error("#extent","extent spatial reference needs to be in the same spatial reference as the view");const t=this._get("filterExtent");if(t===e||n(t)&&e&&t.equals(e))return;const i=n(e)?e.clone():null;this._set("filterExtent",i),this._setDirty()}get _filterExtentRect(){if(o(this.filterExtent))return null;const e=m();return w(this.filterExtent,e,this.tilingScheme.spatialReference),e}get _rootTileIds(){const{tilingScheme:e}=this;return this._filterExtentRect&&e?e.rootTilesInExtent(this._filterExtentRect):[[0,0,0]]}set suspended(e){e!==this._get("suspended")&&(this._set("suspended",e),this._setDirty())}get updating(){return this._dirty||!!this._pendingTiles}constructor(e){super(e),this.tiles=new i,this.tileSize=512,this._idToTile=new Map,this._handles=new s,this._clients=new Set,this._dirty=!1,this._pendingTiles=null,this._newTiles=new a}initialize(){this._handles.add([c((()=>[this.tilingScheme,this.tileSize]),(()=>this._reset()),d),c((()=>[this.tileSize,this.cameraOnSurface?.location,this.tilingScheme,this.viewState?.contentCamera,this.focus?.location]),(()=>this._setDirty()),u)]),this.scheduler&&(this._frameWorker=this.scheduler.registerTask(R.FEATURE_TILE_TREE,this))}destroy(){this._frameWorker=l(this._frameWorker),this._handles=h(this._handles)}addClient(){const e=O();return this._clients.add(e),1===this._clients.size&&this._setDirty(),{remove:()=>this._removeClient(e)}}_removeClient(e){this._clients.delete(e),this._hasClients||this._clear()}get _hasClients(){return this._clients.size>0}_setDirty(){!this._hasClients||this.suspended||this._dirty||(this._frameWorker?(this._dirty=!0,this.notifyChange("updating")):this.runTask(x))}_clear(){this.tiles.removeAll(),this._idToTile.clear(),this._reset(),this._dirty=!1,this.notifyChange("updating")}get running(){return this.updating}runTask(e){this._dirty=!1,this._pendingTiles||(this._startUpdate(),n(this._frameWorker)&&(this._frameWorker.priority=R.FEATURE_TILE_TREE_ACTIVE)),this._subdivideTilesForView(e),!this._pendingTiles&&n(this._frameWorker)&&(this._frameWorker.priority=R.FEATURE_TILE_TREE),this.notifyChange("updating")}_startUpdate(){if(this.suspended)return;if(!this.tilingScheme)return void this._clear();this._tileMeasurements||(this._tileMeasurements=new v({renderCoordsHelper:this.renderCoordsHelper,tilingScheme:this.tilingScheme,tileSize:this.tileSize}));const e=this.viewState.contentCamera;this._tileMeasurements.begin(e,this.focus.location,this.cameraOnSurface.location.z??0),this._pendingTiles=this._getRootTiles()}_reset(){this._newTiles.clear(),this._tileMeasurements=null,this._pendingTiles=null,this._setDirty()}_getRootTiles(){const{tilingScheme:e}=this;return this._rootTileIds.map((t=>new S(t[0],t[1],t[2],e)))}_purgeHorizonTiles(e){e.sort(((e,t)=>{const i=e.measures.screenRect,s=t.measures.screenRect;return i[1]+i[3]-(s[1]+s[3])})),f(I);for(let t=0;t<e.length;t++)if(g(I,e.data[t].measures.screenRect,I),T(I)>k)return e.data.slice(t,e.length);return[]}_subdivideTilesForView(e){if(!this._pendingTiles)return;const{tilingScheme:t}=this;for(;this._pendingTiles.length>0&&!e.done;){const i=this._pendingTiles.pop();e.madeProgress(),this._filterExtentRect&&!y(this._filterExtentRect,i.extent)||(this._tileMeasurements.updateTile(i),i.measures.visibility!==E.INVISIBLE&&(i.measures.shouldSplit?(t.ensureMaxLod(i.lij[0]+1),this._pendingTiles.push(...i.getChildren())):this._newTiles.push(i)))}0===this._pendingTiles.length&&(this._updateTiles(this._purgeHorizonTiles(this._newTiles)),this._newTiles.clear(),this._tileMeasurements.end(),this._pendingTiles=null)}_updateTiles(e){for(const s of this.tiles.items)s.used=!1;const t=e.filter((e=>{const t=this._idToTile.get(e.id);return t?(t.copyMeasurementsFrom(e),t.used=!0):this._idToTile.set(e.id,e),!t})),i=this.tiles.items.filter((e=>!e.used&&(this._idToTile.delete(e.id),!0)));this.tiles.removeMany(i),this.tiles.addMany(t),this._sortTiles()}_sortTiles(){this.viewState.fixedContentCamera||this.tiles.sort(((e,t)=>e.measures.visibility!==t.measures.visibility?e.measures.visibility===E.VISIBLE_ON_SURFACE?-1:1:e.measures.distance-t.measures.distance)),this.tiles.forEach(((e,t)=>e.loadPriority=t))}};e([p({constructOnly:!0})],C.prototype,"scheduler",void 0),e([p({constructOnly:!0})],C.prototype,"renderCoordsHelper",void 0),e([p({constructOnly:!0})],C.prototype,"tilingSchemeOwner",void 0),e([p({constructOnly:!0})],C.prototype,"cameraOnSurface",void 0),e([p({constructOnly:!0})],C.prototype,"focus",void 0),e([p({constructOnly:!0})],C.prototype,"viewState",void 0),e([p({constructOnly:!0})],C.prototype,"terrain",void 0),e([p()],C.prototype,"tiles",void 0),e([p()],C.prototype,"tileSize",void 0),e([p({readOnly:!0})],C.prototype,"tilingScheme",null),e([p()],C.prototype,"filterExtent",null),e([p({readOnly:!0})],C.prototype,"_filterExtentRect",null),e([p({readOnly:!0})],C.prototype,"_rootTileIds",null),e([p({value:!1})],C.prototype,"suspended",null),e([p({readOnly:!0})],C.prototype,"updating",null),C=e([_("esri.views.3d.layers.support.FeatureTileTree3D")],C);let j=0;function O(){return j++}const I=m(),k=10;export{C as FeatureTileTree3D};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import{isNone as r}from"../../../../core/maybe.js";import{property as s}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as o}from"../../../../core/accessorSupport/decorators/subclass.js";import{F as t}from"../../../../chunks/mat4.js";import{c as i}from"../../../../chunks/mat4f64.js";import{c as p,m as c}from"../../../../chunks/vec3.js";import{c as l}from"../../../../chunks/vec3f64.js";import{projectBuffer as u}from"../../../../geometry/projection.js";import{TileTreeDebugger as n}from"../../../support/TileTreeDebugger.js";import a from"../../../../geometry/Polygon.js";let m=class extends n{constructor(e){super(e)}getTiles(){const e=this.lv.getVisibleNodes(),r=this.view.renderSpatialReference,s=this.nodeSR;return e.map((e=>h(e,r,s))).sort(((e,r)=>e.lij[0]===r.lij[0]?e.label>r.label?-1:1:e.lij[0]-r.lij[0]))}};function h(e,s,o){const i=e.serviceObb;if(r(i)||r(s))return null;t(f,i.quaternion),p(j,i.center),u(j,o,0,j,s,0,1),f[12]=j[0],f[13]=j[1],f[14]=j[2];const l=[[],[],[]];p(j,i.halfSize),c(j,j,f),u(j,s,0,j,o,0,1),l[0].push([j[0],j[1]]),p(j,i.halfSize),j[0]=-j[0],c(j,j,f),u(j,s,0,j,o,0,1),l[0].push([j[0],j[1]]),p(j,i.halfSize),j[0]=-j[0],j[1]=-j[1],c(j,j,f),u(j,s,0,j,o,0,1),l[0].push([j[0],j[1]]),p(j,i.halfSize),j[1]=-j[1],c(j,j,f),u(j,s,0,j,o,0,1),l[0].push([j[0],j[1]]),l[1].push(l[0][0]),l[1].push(l[0][1]),p(j,i.halfSize),j[0]=-j[0],j[2]=-j[2],c(j,j,f),u(j,s,0,j,o,0,1),l[1].push([j[0],j[1]]),p(j,i.halfSize),j[2]=-j[2],c(j,j,f),u(j,s,0,j,o,0,1),l[1].push([j[0],j[1]]),l[2].push(l[0][0]),l[2].push(l[0][3]),p(j,i.halfSize),j[1]=-j[1],j[2]=-j[2],c(j,j,f),u(j,s,0,j,o,0,1),l[2].push([j[0],j[1]]),l[2].push(l[1][3]);const n=new a({rings:l,spatialReference:o});return{lij:[e.level,e.childCount,0],label:e.id,geometry:n}}e([s({constructOnly:!0})],m.prototype,"lv",void 0),e([s({constructOnly:!0})],m.prototype,"nodeSR",void 0),m=e([o("esri.views.3d.layers.support.I3STreeDebugger")],m);const f=i(),j=l();export{m as I3STreeDebugger};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import{isSome as r,isNone as s}from"../../../../core/maybe.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as t}from"../../../../core/accessorSupport/decorators/subclass.js";import{F as i}from"../../../../chunks/mat4.js";import{c as p}from"../../../../chunks/mat4f64.js";import{c,m as l}from"../../../../chunks/vec3.js";import{c as u}from"../../../../chunks/vec3f64.js";import{projectBuffer as n}from"../../../../geometry/projection.js";import{TileTreeDebugger as a}from"../../../support/TileTreeDebugger.js";import m from"../../../../geometry/Polygon.js";let h=class extends a{constructor(e){super(e)}getTiles(){const e=this.lv.getVisibleNodes(),s=this.view.renderSpatialReference,o=this.nodeSR;return e.map((e=>f(e,s,o))).filter(r).sort(((e,r)=>e.lij[0]===r.lij[0]?e.label>r.label?-1:1:e.lij[0]-r.lij[0]))}};function f(e,r,o){const t=e.serviceObb;if(s(t)||s(r))return null;i(j,t.quaternion),c(y,t.center),n(y,o,0,y,r,0,1),j[12]=y[0],j[13]=y[1],j[14]=y[2];const p=[[],[],[]];c(y,t.halfSize),l(y,y,j),n(y,r,0,y,o,0,1),p[0].push([y[0],y[1]]),c(y,t.halfSize),y[0]=-y[0],l(y,y,j),n(y,r,0,y,o,0,1),p[0].push([y[0],y[1]]),c(y,t.halfSize),y[0]=-y[0],y[1]=-y[1],l(y,y,j),n(y,r,0,y,o,0,1),p[0].push([y[0],y[1]]),c(y,t.halfSize),y[1]=-y[1],l(y,y,j),n(y,r,0,y,o,0,1),p[0].push([y[0],y[1]]),p[1].push(p[0][0]),p[1].push(p[0][1]),c(y,t.halfSize),y[0]=-y[0],y[2]=-y[2],l(y,y,j),n(y,r,0,y,o,0,1),p[1].push([y[0],y[1]]),c(y,t.halfSize),y[2]=-y[2],l(y,y,j),n(y,r,0,y,o,0,1),p[1].push([y[0],y[1]]),p[2].push(p[0][0]),p[2].push(p[0][3]),c(y,t.halfSize),y[1]=-y[1],y[2]=-y[2],l(y,y,j),n(y,r,0,y,o,0,1),p[2].push([y[0],y[1]]),p[2].push(p[1][3]);const u=new m({rings:p,spatialReference:o});return{lij:[e.level,e.childCount,0],label:e.id,geometry:u}}e([o({constructOnly:!0})],h.prototype,"lv",void 0),e([o({constructOnly:!0})],h.prototype,"nodeSR",void 0),h=e([t("esri.views.3d.layers.support.I3STreeDebugger")],h);const j=p(),y=u();export{h as I3STreeDebugger};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import{AsyncUpdateMixin as r}from"../../../../core/AsyncUpdate.js";import{HandleOwner as s}from"../../../../core/HandleOwner.js";import t from"../../../../core/Logger.js";import{unwrapOr as i}from"../../../../core/maybe.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as l}from"../../../../core/accessorSupport/decorators/subclass.js";import{fixFields as n,collectLabelingFields as a,collectFilterFields as d}from"../../../../layers/support/fieldUtils.js";const p="esri.views.3d.layers.support.SceneLayerViewRequiredFields";let c=class extends(r(s)){get requiredFields(){const{layerView:{layer:{fieldsIndex:e},definitionExpressionFields:r},rendererFields:s,labelingFields:t,viewFilterFields:o}=this;return n(e,[...i(r,[]),...i(s,[]),...i(t,[]),...i(o,[])])}constructor(e){super(e)}initialize(){const e=this.layerView.layer;this.layer=e,this.handles.add([this.autoUpdateAsync("rendererFields",(()=>{const{fieldsIndex:e,renderer:r}=this.layer;return r?y((s=>r.collectRequiredFields(s,e))):null})),this.autoUpdateAsync("labelingFields",(()=>{const{layer:e}=this;return e.labelsVisible?y((r=>a(r,e))):null})),this.autoUpdateAsync("viewFilterFields",(()=>{const{layer:e,filter:r}=this.layerView;return y((s=>d(s,e,r)))}))])}};async function y(e){const r=new Set;try{return await e(r),Array.from(r).sort()}catch(s){return t.getLogger(p).error(s),null}}e([o()],c.prototype,"layerView",void 0),e([o()],c.prototype,"layer",void 0),e([o()],c.prototype,"requiredFields",null),e([o()],c.prototype,"rendererFields",void 0),e([o()],c.prototype,"labelingFields",void 0),e([o()],c.prototype,"viewFilterFields",void 0),c=e([l(p)],c);export{c as SceneLayerViewRequiredFields};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import{AsyncUpdateMixin as r}from"../../../../core/AsyncUpdate.js";import{HandleOwner as s}from"../../../../core/HandleOwner.js";import t from"../../../../core/Logger.js";import{unwrapOr as i}from"../../../../core/maybe.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as l}from"../../../../core/accessorSupport/decorators/subclass.js";import{fixFields as n,collectLabelingFields as a,collectFilterFields as d}from"../../../../layers/support/fieldUtils.js";const p="esri.views.3d.layers.support.SceneLayerViewRequiredFields";let c=class extends(r(s)){get requiredFields(){const{layerView:{layer:{fieldsIndex:e},definitionExpressionFields:r},rendererFields:s,labelingFields:t,viewFilterFields:o}=this;return n(e,[...i(r,[]),...i(s,[]),...i(t,[]),...i(o,[])])}constructor(e){super(e)}initialize(){const e=this.layerView.layer;this.layer=e,this.handles.add([this.autoUpdateAsync("rendererFields",(async()=>{const{fieldsIndex:e,renderer:r}=this.layer;return r?y((s=>r.collectRequiredFields(s,e))):null})),this.autoUpdateAsync("labelingFields",(async()=>{const{layer:e}=this;return e.labelsVisible?y((r=>a(r,e))):null})),this.autoUpdateAsync("viewFilterFields",(()=>{const{layer:e,filter:r}=this.layerView;return y((s=>d(s,e,r)))}))])}};async function y(e){const r=new Set;try{return await e(r),Array.from(r).sort()}catch(s){return t.getLogger(p).error(s),null}}e([o()],c.prototype,"layerView",void 0),e([o()],c.prototype,"layer",void 0),e([o()],c.prototype,"requiredFields",null),e([o()],c.prototype,"rendererFields",void 0),e([o()],c.prototype,"labelingFields",void 0),e([o()],c.prototype,"viewFilterFields",void 0),c=e([l(p)],c);export{c as SceneLayerViewRequiredFields};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{throwIfAborted as g,isAbortError as m,isAborted as T,createAbortError as f}from"../../../core/promiseUtils.js";import{watch as y,syncAndInitial as v,sync as w,initial as E}from"../../../core/reactiveUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as L}from"../../../core/accessorSupport/decorators/subclass.js";import{m as D}from"../../../chunks/mat4.js";import{c as P}from"../../../chunks/mat4f64.js";import{c as C}from"../../../chunks/vec3.js";import{c as U}from"../../../chunks/vec3f64.js";import{c as b}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as R}from"../../../core/support/WatchUpdatingTracking.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as M,projectPointToVector as j}from"../../../geometry/projection.js";import A from"../../../geometry/SpatialReference.js";import{create as I,equals as O,intersection as V,empty as k,expand as B,intersectsSphere as N}from"../../../geometry/support/aaBoundingRect.js";import{create as F,copy as G}from"../../../geometry/support/frustum.js";import{isPlateCarree as q}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as W}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{ElevationTileData as Q}from"../../../layers/support/ElevationTileData.js";import{isBaseLayer as z}from"../../../layers/support/layerUtils.js";import{acquireDecoder as X}from"../../../layers/support/LercDecoder.js";import{printAllocations as Y}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as $}from"../support/cameraUtils.js";import K from"../support/debugFlags.js";import{toBoundingRect as J}from"../support/extentUtils.js";import{ClientType as Z}from"../support/index.js";import{updatingProgress as ee}from"../support/updatingProperties.js";import{ElevationBounds as te}from"./ElevationBounds.js";import{ElevationData as ie,sampleElevation as re}from"./ElevationData.js";import{create as se}from"./ExtentHelper.js";import{LODSnapping as ae,TextureUpdate as ne}from"./interfaces.js";import{LayerClass as le,LayerClasses as oe}from"./LayerClass.js";import{OverlayManager as he}from"./OverlayManager.js";import{PlanarPatch as de}from"./PlanarPatch.js";import{RenderOrder as pe}from"./RenderOrder.js";import{ScaleRangeQueries as ue}from"./ScaleRangeQueries.js";import{SphericalPatch as ce}from"./SphericalPatch.js";import{SplitLimits as _e}from"./SplitLimits.js";import{MAX_ROOT_TILES as ge,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as me,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as Te,MAX_MEMORY_LOD_BIAS as fe,ELEVATION_NODATA_VALUE as ye}from"./TerrainConst.js";import{TerrainRenderer as ve,TransparencyMode as we}from"./TerrainRenderer.js";import Ee from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as Se,internalAssert as Le,oppositeEdge as De,isSurfaceLayerView as Pe,isGroupLayerView as Ce,isMapTileLayerView as Ue,isBlendableLayerView as be,isElevationLayerView as Re,isVectorTileLayerView as xe,useFetchTileForLayer as Me,isImageryTileLayerView as je,isTileLayerView as Ae,releaseTileData as Ie,neighborEdgeIndices as Oe,ENABLE_TERRAIN_INTERNAL_CHECKS as Ve,ENABLE_WATERPROOFNESS_TESTS as ke,enableTerrainInternalChecks as Be,enableTerrainWaterproofnessChecks as Ne}from"./terrainUtils.js";import{Tile as Fe}from"./Tile.js";import{printAllocations as Ge}from"./TilePerLayerInfo.js";import{TileUpdate as qe}from"./TileUpdate.js";import{IteratorPreorder as We,IteratorPostorder as He,compareTilesByLij as Qe,hasLoadableSiblings as ze,sortTilesByPOI as Xe,sortTiles as Ye}from"./tileUtils.js";import{TilingSchemeLogic as $e}from"./TilingSchemeLogic.js";import{UpsampleInfo as Ke}from"./UpsampleInfo.js";import{isCompositeBlendMode as Je,blendModeFromString as Ze}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{RenderRequestType as et}from"../webgl-engine/lib/basicInterfaces.js";import{RenderState as tt}from"../../support/RenderState.js";import{ImmediateTask as it,TaskPriority as rt,noBudget as st}from"../../support/Scheduler.js";let at=class extends(a.EventedMixin(i)){constructor(e){super(e),this._scaleRangeQueries=new ue,this._iteratorPool=new c(We,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new He,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new Ee,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=U(),this._eyePosSurfaceSR=U(),this._splitLimits=new _e,this._frustum=F(),this._viewProjectionMatrix=P(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new R,this._frameTask=it,this._allTiles=new _,this._upsampleInfoPool=new c(Ke),this._rootTilesExtent=I(),this.updatingProgress=0,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=A.WebMercator,this.visibleElevationBounds=new te(1/0,-1/0),this.rootTileElevationBounds=new te(1/0,-1/0),this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this.oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this._shading=!0,this._isWebMercator=!1,this._isWebMercatorOnPlateeCarree=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=X(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(de):new c(ce);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new H(e.newCache("elevation-query")),this._set("overlayManager",new he({surface:this})),this._handles.add([y((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),y((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e))),y((()=>this.overlayManager.renderer.isEmpty),(()=>this._evaluateTransparency()))],"overlayManager"),this._renderer=new ve({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:x(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([y((()=>this.baseOpacity),(()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?ne.UNFADED:ne.IMMEDIATE)}),v),y((()=>this.hasCompositeBlendMode),(()=>this._updateTileTextures(this._evaluateTransparency()?ne.UNFADED:ne.IMMEDIATE)),v),y((()=>this.renderingDisabled),(()=>this.view?._stage?.renderer.setParameters({terrainRenderingEnabled:!this.renderingDisabled})),w),y((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),v),y((()=>this.snapLevel),(()=>this._viewChanged=!0),w),y((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>this._allTilesSorted=!1))})),y((()=>K.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&K.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),E)]),this._extentHelper=se(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),i=new $e({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(Z.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(Z.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(rt.TERRAIN_SURFACE,this),this._handles.add([y((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),E),y((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),w),y((()=>this.extent),(()=>this._updateRootTiles()),E),this.view.on("resize",(()=>this._viewChangeUpdate())),y((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),v),y((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),E),y((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),w)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._handles.add([y((()=>this.view?.map.ground.shading),(()=>{this._updateShadingIfChanged()}))]),this._updateShading(),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache);const e=this.tilingSchemeLogic.layers;this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),e.destroy(),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Fe.prune(),this._treeDebugger=d(this._treeDebugger),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),Y(),Ge()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnapping===ae.ON){const e=this.view,t=this.tilingScheme,i=e.pointsOfInterest?.cameraOnSurface?.scale;if(i&&t){const r=e.state.contentCamera;let s=$(e,r.eye,r.viewForward,r.up).tilt;s>90&&(s=180-s);const a=2*(s/90)**2,n=t.levelAtScale(i)-a;return Math.round(n)}}return null}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?ae.ON:ae.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=I(),r=J(t,i,e)?i:null,s=this._get("extent");return O(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,I()),t=this._get("extent");return O(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this.running||this._watchUpdatingTracking.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager.updating)}get running(){return(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this._rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view.map.ground.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){this._renderer.velvetOverground=e,this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.transparency===we.Opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this._rootTiles;if(p(s)||!s.length)return null;if(0===s[0].layerInfo[le.ELEVATION].length)return null;const a=dt;if(a[0]=e,a[1]=t,a[2]=i,!M(a,r,a,this._spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;return mt(s,a[0],a[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[le.ELEVATION].length:0;if(!p(r)&&r.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,mt(r,e[t+0],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getScale(e){if(!this.tilingScheme)return null;if(!j(e,dt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(u(t))for(const i of t)if(i?.containsPoint(dt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;dt[0]>t[2]&&(i+=1),dt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}getSphereElevationBounds(e,t,i,r,s){if(dt[0]=e,dt[1]=t,dt[2]=i,dt[3]=r,!M(dt,s,dt,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&N(e.extent,dt))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this._rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!j(e,dt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;dt[3]=t;let i=null;const r=e=>{if(e&&N(e.extent,dt)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._allSurfaceLayersTransparent()?t?we.Empty:we.TransparentWithDraped:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?we.Opaque:we.Semitransparent,s=i!==r;return s&&(this._renderer.transparency=r,this.view?._stage?.renderer.setParameters({terrainTransparency:this._renderer.transparency})),s}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;Se(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??A.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateeCarree=this._isWebMercator&&q(this.view?.renderSpatialReference),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles())}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return ut[0]=e,ut[1]=t,ut[2]=i,s.init(ut,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=pt;let s=t.rootTilesInExtent(e,i,5*ge);if(u(this._rootTiles)){if(s.length>ge)return void l.getLogger(this.declaredClass).warn(me);const e=this._rootTiles.map((e=>e.lij)),t=r(e,s,lt);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter((e=>!(t.removed.findIndex((t=>lt(t,e.lij)))>-1)||(this._purgeTile(e),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ge&&(l.getLogger(this.declaredClass).warn(Te),s=t.rootTilesInExtent(e,i,ge)),this._setRootTiles(s.map((e=>this._newRootTile(e))));O(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter((e=>e.isLoaded&&e.intersectsClippingArea));e.forEach((e=>this._renderer.updateTileGeometryState(e))),e.forEach((e=>e.renderData.updateNeighborData())),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Qe);const t=this.renderer;e.forEach((e=>t.updateGeometryIfNeeded(e))),e.forEach((e=>this._pendingTilesForElevationUpdateEvent.add(e)))}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===qe.SPLIT}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(qe.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(qe.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(p(e))return;const t=ze(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this._viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(qe.GEOMETRY)&&this._updateTileGeometryState(e),e.setPendingUpdate(qe.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBounds[0],r),s=Math.max(e.elevationBounds[1],s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._batchUpdatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new te(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;u(i)&&i.forEach((({elevationBounds:i})=>{e=Math.min(e,i[0]),t=Math.max(t,i[1])}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new te(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=F()),G(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,G(this._frustum,e.frustum),D(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),C(this._eyePosRenderSR,t.eye),M(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(ot(e)?this._loadChildren(e):ht(e)&&this._loadParent(e))}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForGeometryUpdate(e){const t=this._pendingTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(qe.TEXTURE_FADING)?qe.TEXTURE_FADING:!!e.resetPendingUpdate(qe.TEXTURE_NOFADING)&&qe.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){const e=_t.extent;k(e),this._pendingTilesForElevationUpdateEvent.forEach((t=>B(e,t.extent,e))),this._pendingTilesForElevationUpdateEvent.clear(),_t.spatialReference=this.spatialReference,this.emit("elevation-change",_t)}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._batchUpdatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed?this.requestUpdate():this.getUsedMemory(),this.notifyChange("updatingProgressValue")}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();t.reset(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;for(;!t.done;){const e=t.next(),a=e.shouldSplit(r,s,i);if(a!==qe.SPLIT){if(e.resetPendingUpdate(qe.SPLIT)&&e.updateAgentSuspension(),a===qe.VSPLITMERGE&&e.updateAgents(le.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(qe.MERGE),e.resetPendingUpdate(qe.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);const i=this._viewProjectionMatrix;for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(i);t.remove()}}else e.resetPendingUpdate(qe.MERGE),e.isLeaf&&(e.setPendingUpdate(qe.SPLIT),t.skipSubtree()),e.rendered&&e.setPendingUpdate(qe.RENDERDATA)}t.remove(),this.requestUpdate(),(this.shortBatches||!this.oneBatchPerFrameTask)&&this._batchUpdatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(Xe(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){Le(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForGeometryUpdate(e))}_batchUpdatePendingTileGeometries(){const e=this._pendingTilesToUpdate;if(0===e.size)return;const t=Array.from(this._pendingTilesToUpdate.keys()).filter((e=>e.isLoaded&&e.intersectsClippingArea)),i=(i,r)=>{!r?.isLoaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Qe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Le(r.isLoaded),Le(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a._dirtyEdgeResolutions,l=a.geometryState.neighborData;for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.neighborData.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(De(Oe[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(Le(e.has(t)||Qe(r,t)<0),i(r,t),!0))),i(r,l.cornerPeerNeighbors[t]),i(r,l.cornerPeerNeighbors[(t+1)%4])}}e.clear(),this._updateTilesGeometries(t),Ve&&ke&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some((s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.resetPendingUpdate(qe.MERGE)){if(!t)return s.setPendingUpdate(qe.MERGE),e.done;for(;n.parent?.resetPendingUpdate(qe.MERGE);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else s.resetPendingUpdate(qe.SPLIT)&&(this._splitTile(s),a=!0,e.madeProgress());return!e.done&&n===s&&s.resetPendingUpdate(qe.RENDERDATA)&&(this._updateRenderData(s),e.madeProgress()),e.done}));if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this.oneBatchPerFrameTask&&this._batchUpdatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some((t=>(t.resetPendingUpdate(qe.GEOMETRY)&&(this._updateTileGeometryState(t),this._updateTileTexture(t,e),this.shortBatches&&this._batchUpdatePendingTileGeometries(),e.madeProgress()),e.done))),!this.oneBatchPerFrameTask&&this._batchUpdatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done)))}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(et.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*fe}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this._rootTiles)&&(this._rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(!e.children[0])return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i])||t;return e.unsetChildren(),t}_purgeTile(e){const t=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),this._tilePool.release(e),t}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload(this._renderer)}_splitTile(e){Se(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(qe.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){gt.spatialReference=this.spatialReference,gt.extent=e.extent,gt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",gt)}_createTile(e,t,i,r){Se(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(qe.SPLIT),s}get shortBatches(){return this.view.state.mode!==tt.IDLE}_mergeTile(e){Se(!e.hasPendingUpdate(qe.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(Se(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this.shortBatches&&this._batchUpdatePendingTileGeometries()),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_loadChildren(e){Se(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._loadTile(e))),t.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForGeometryUpdate(e),this._emitTileScaleChange(e,e.level+1),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_loadParent(e){const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._markTileToUpdate(t),this._emitTileScaleChange(t,t.level),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_unloadChildren(e){const t=e.children;if(t[0])for(let i=0;i<4;++i){const e=t[i];this._unloadChildren(e),this._unloadTile(e)}}_loadTile(e){e.load(),e.setPendingUpdate(qe.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new ie(e.lij,e.extent,i);e.dataArrived(t,le.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}0===a&&this._updateRootTileElevationBounds(),n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=st){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),Pe(s)||Ce(s))if(this._basemapLayerViewHandles.has(s.uid)&&!Ce(s)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Ue(t)&&!z(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((be(e)||Ce(e))&&Je(Ze[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Re(e)?le.ELEVATION:le.MAP}_registerTiledLayerView(e){const t=[];if((be(e)||Ce(e))&&t.push(y((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(ne.UNFADED)}))),Ce(e))return;const i=this._layerClassFromLayerView(e);t.push(y((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(y((()=>e.fullOpacity),(()=>this._updateTileTextures(ne.UNFADED)))),t.push(y((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach((e=>{if(!e.layer||e.suspended||!Pe(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===le.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of oe){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&this._viewChangeUpdate()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===le.ELEVATION&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(le.MAP),e===ne.IMMEDIATE?this.renderer.updateTileTexture(t,qe.TEXTURE_NOFADING):t.updateRenderData(le.MAP,e)})),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=et.UPDATE){this.renderer.setNeedsRender(e)}requestUpdate(){1==++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||xe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(r),m(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===le.ELEVATION?Re(i)?this._requestElevationTileData(e,i,r):Promise.reject():Ue(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(T(i))return;const s=this._layerIndexByUid[le.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",le.ELEVATION,e.lij.toString())},s=i=>{m(i)||(this._dataMissing(e,le.ELEVATION,t,i),this.requestUpdate())};if(Me(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:ye,signal:i.signal}).then((e=>{if(!T(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:ye},i.signal))).then((e=>{e?r(new Q(e)):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Ie(s),T(i)||(this._dataMissing(e,le.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),T(i)?Ie(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(xe(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(je(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(Ae(t)&&Me(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(T(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(f());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);W(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(le.MAP,t.uid);u(r)?e.dataArrived(r,le.MAP,i):(Ie(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this._rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this._rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this._rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this._rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return Se(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e._rootTiles)&&e._rootTiles.length>0&&(e._mergeTile(e._rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){ct.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&ct.push(e)}));const t=ct.toArray();return Ye(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!ke)return;const e=this._rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shading(){return this._shading}_updateShadingIfChanged(){const e=this.view?.map?.ground?.shading;e!==this._shading&&this._updateShading()}_updateShading(){const e=this.view?.map?.ground?.shading;this._shading=e,this.renderer&&(this.renderer.shading=e,this.renderer.setNeedsRender()),this._updateAllTileGeometries()}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateeCarree(){return this._isWebMercatorOnPlateeCarree}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Be(e)}enableWaterproofnessChecks(e){Ne(e)}};e([S()],at.prototype,"_renderer",void 0),e([S({constructOnly:!0})],at.prototype,"_scaleRangeQueries",void 0),e([S()],at.prototype,"_hasPendingUpdates",void 0),e([S()],at.prototype,"_asyncWorkItems",void 0),e([S()],at.prototype,"_allTilesDirty",void 0),e([S()],at.prototype,"_allTilesSorted",void 0),e([S()],at.prototype,"_viewChanged",void 0),e([S({readOnly:!0})],at.prototype,"_watchUpdatingTracking",void 0),e([S()],at.prototype,"_frameTask",void 0),e([S({readOnly:!0})],at.prototype,"snapLevel",null),e([S({readOnly:!0})],at.prototype,"lodSnapping",null),e([S({constructOnly:!0})],at.prototype,"view",void 0),e([S()],at.prototype,"_userClippingExtent",null),e([S()],at.prototype,"_rootTilesExtent",void 0),e([S({readOnly:!0})],at.prototype,"extent",null),e([S({readOnly:!0})],at.prototype,"groundExtent",null),e([S({readOnly:!0})],at.prototype,"_tilingSchemeExtent",null),e([S({readOnly:!0})],at.prototype,"updating",null),e([S({readOnly:!0})],at.prototype,"running",null),e([S(ee)],at.prototype,"updatingProgress",void 0),e([S({readOnly:!0})],at.prototype,"updatingProgressValue",null),e([S()],at.prototype,"_maxNumUpdating",void 0),e([S()],at.prototype,"baseOpacity",null),e([S()],at.prototype,"hasCompositeBlendMode",void 0),e([S({readOnly:!0})],at.prototype,"overlayManager",void 0),e([S({readOnly:!0})],at.prototype,"viewingMode",null),e([S()],at.prototype,"maxTextureScale",void 0),e([S({readOnly:!0})],at.prototype,"ready",null),e([S({value:pe.FRONT_TO_BACK})],at.prototype,"renderOrder",null),e([S({readOnly:!0})],at.prototype,"rootTiles",null),e([S()],at.prototype,"_rootTiles",void 0),e([S({readOnly:!0})],at.prototype,"spatialReference",null),e([S({type:t})],at.prototype,"backgroundColor",null),e([S({value:!1})],at.prototype,"slicePlaneEnabled",null),e([S({readOnly:!0})],at.prototype,"tilingScheme",void 0),e([S({readOnly:!0})],at.prototype,"tilingSchemeLocked",null),e([S({readOnly:!0})],at.prototype,"tilingSchemeLogic",void 0),e([S({value:!0})],at.prototype,"velvetOverground",null),e([S()],at.prototype,"wireframe",null),e([S({value:!1})],at.prototype,"suspended",null),e([S()],at.prototype,"textureFadeDuration",null),e([S()],at.prototype,"visibleElevationBounds",void 0),e([S()],at.prototype,"rootTileElevationBounds",void 0),e([S()],at.prototype,"_layerViewsDirty",void 0),e([S()],at.prototype,"renderPatchBorders",null),e([S()],at.prototype,"visualizeNormals",null),e([S()],at.prototype,"renderingDisabled",null),at=e([L("esri.views.3d.terrain.TerrainSurface")],at);const nt=at;function lt(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function ot(e){const t=e.children;if(!t[0])return!1;for(const i of t)if(i.shouldLoad)return!0;for(const i of t)if(ot(i))return!0;return!1}function ht(e){return e.isLeaf&&(e.parent?.shouldLoad??!1)}const dt=b(),pt=I(),ut=[0,0,0],ct=new _,_t={spatialReference:null,extent:I(),context:"ground"},gt={spatialReference:null,extent:null,scale:0};function mt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return re(t,i,s)}return null}export{nt as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{throwIfAborted as g,isAbortError as m,isAborted as T,createAbortError as f}from"../../../core/promiseUtils.js";import{watch as y,syncAndInitial as v,sync as w,initial as E}from"../../../core/reactiveUtils.js";import{property as S}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as L}from"../../../core/accessorSupport/decorators/subclass.js";import{m as D}from"../../../chunks/mat4.js";import{c as P}from"../../../chunks/mat4f64.js";import{c as C}from"../../../chunks/vec3.js";import{c as U}from"../../../chunks/vec3f64.js";import{c as b}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as R}from"../../../core/support/WatchUpdatingTracking.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as M,projectPointToVector as j}from"../../../geometry/projection.js";import A from"../../../geometry/SpatialReference.js";import{create as I,equals as O,intersection as V,empty as k,expand as B,intersectsSphere as N}from"../../../geometry/support/aaBoundingRect.js";import{create as F,copy as G}from"../../../geometry/support/frustum.js";import{isPlateCarree as q}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as W}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{ElevationTileData as Q}from"../../../layers/support/ElevationTileData.js";import{isBaseLayer as z}from"../../../layers/support/layerUtils.js";import{acquireDecoder as X}from"../../../layers/support/LercDecoder.js";import{printAllocations as Y}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as $}from"../support/cameraUtils.js";import K from"../support/debugFlags.js";import{toBoundingRect as J}from"../support/extentUtils.js";import{ClientType as Z}from"../support/index.js";import{updatingProgress as ee}from"../support/updatingProperties.js";import{ElevationBounds as te}from"./ElevationBounds.js";import{ElevationData as ie,sampleElevation as re}from"./ElevationData.js";import{create as se}from"./ExtentHelper.js";import{LODSnapping as ae,TextureUpdate as ne}from"./interfaces.js";import{LayerClass as le,LayerClasses as oe}from"./LayerClass.js";import{OverlayManager as he}from"./OverlayManager.js";import{PlanarPatch as de}from"./PlanarPatch.js";import{RenderOrder as pe}from"./RenderOrder.js";import{ScaleRangeQueries as ue}from"./ScaleRangeQueries.js";import{SphericalPatch as ce}from"./SphericalPatch.js";import{SplitLimits as _e}from"./SplitLimits.js";import{MAX_ROOT_TILES as ge,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as me,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as Te,MAX_MEMORY_LOD_BIAS as fe,ELEVATION_NODATA_VALUE as ye}from"./TerrainConst.js";import{TerrainRenderer as ve,TransparencyMode as we}from"./TerrainRenderer.js";import Ee from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as Se,internalAssert as Le,oppositeEdge as De,isSurfaceLayerView as Pe,isGroupLayerView as Ce,isMapTileLayerView as Ue,isBlendableLayerView as be,isElevationLayerView as Re,isVectorTileLayerView as xe,useFetchTileForLayer as Me,isImageryTileLayerView as je,isTileLayerView as Ae,releaseTileData as Ie,neighborEdgeIndices as Oe,ENABLE_TERRAIN_INTERNAL_CHECKS as Ve,ENABLE_WATERPROOFNESS_TESTS as ke,enableTerrainInternalChecks as Be,enableTerrainWaterproofnessChecks as Ne}from"./terrainUtils.js";import{Tile as Fe}from"./Tile.js";import{printAllocations as Ge}from"./TilePerLayerInfo.js";import{TileUpdate as qe}from"./TileUpdate.js";import{IteratorPreorder as We,IteratorPostorder as He,compareTilesByLij as Qe,hasLoadableSiblings as ze,sortTilesByPOI as Xe,sortTiles as Ye}from"./tileUtils.js";import{TilingSchemeLogic as $e}from"./TilingSchemeLogic.js";import{UpsampleInfo as Ke}from"./UpsampleInfo.js";import{isCompositeBlendMode as Je,blendModeFromString as Ze}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{RenderRequestType as et}from"../webgl-engine/lib/basicInterfaces.js";import{RenderState as tt}from"../../support/RenderState.js";import{ImmediateTask as it,TaskPriority as rt,noBudget as st}from"../../support/Scheduler.js";let at=class extends(a.EventedMixin(i)){constructor(e){super(e),this._scaleRangeQueries=new ue,this._iteratorPool=new c(We,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new He,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new Ee,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=U(),this._eyePosSurfaceSR=U(),this._splitLimits=new _e,this._frustum=F(),this._viewProjectionMatrix=P(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new R,this._frameTask=it,this._allTiles=new _,this._upsampleInfoPool=new c(Ke),this._rootTilesExtent=I(),this.updatingProgress=0,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=A.WebMercator,this.visibleElevationBounds=new te(1/0,-1/0),this.rootTileElevationBounds=new te(1/0,-1/0),this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this.oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this._shading=!0,this._isWebMercator=!1,this._isWebMercatorOnPlateeCarree=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=X(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(de):new c(ce);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new H(e.newCache("elevation-query")),this._set("overlayManager",new he({surface:this})),this._handles.add([y((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),y((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e))),y((()=>this.overlayManager.renderer.isEmpty),(()=>this._evaluateTransparency()))],"overlayManager"),this._renderer=new ve({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:x(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([y((()=>this.baseOpacity),(()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?ne.UNFADED:ne.IMMEDIATE)}),v),y((()=>this.hasCompositeBlendMode),(()=>this._updateTileTextures(this._evaluateTransparency()?ne.UNFADED:ne.IMMEDIATE)),v),y((()=>this.renderingDisabled),(()=>this.view?._stage?.renderer.setParameters({terrainRenderingEnabled:!this.renderingDisabled})),w),y((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),v),y((()=>this.snapLevel),(()=>this._viewChanged=!0),w),y((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>this._allTilesSorted=!1))})),y((()=>K.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&K.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),E)]);const{spatialReference:t}=this.view;this._extentHelper=se(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:t});const i=new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),r=new $e({layers:i,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:t});this._set("tilingSchemeLogic",r),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(Z.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(Z.BASEMAP);const a=this.view.resourceController.scheduler;this._frameTask=a.registerTask(rt.TERRAIN_SURFACE,this),this._handles.add([y((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),E),y((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),w),y((()=>this.extent),(()=>this._updateRootTiles()),E),this.view.on("resize",(()=>this._viewChangeUpdate())),y((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),v),y((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),E),y((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),w)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._handles.add([y((()=>this.view?.map.ground.shading),(()=>{this._updateShadingIfChanged()}))]),this._updateShading(),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache);const e=this.tilingSchemeLogic.layers;this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),e.destroy(),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Fe.prune(),this._treeDebugger=d(this._treeDebugger),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),Y(),Ge()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){if(this.lodSnapping===ae.ON){const e=this.view,t=this.tilingScheme,i=e.pointsOfInterest?.cameraOnSurface?.scale;if(i&&t){const r=e.state.contentCamera;let s=$(e,r.eye,r.viewForward,r.up).tilt;s>90&&(s=180-s);const a=2*(s/90)**2,n=t.levelAtScale(i)-a;return Math.round(n)}}return null}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?ae.ON:ae.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=I(),r=J(t,i,e)?i:null,s=this._get("extent");return O(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,I()),t=this._get("extent");return O(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this.running||this._watchUpdatingTracking.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager.updating)}get running(){return(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this._rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view.map.ground.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){this._renderer.velvetOverground=e,this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.transparency===we.Opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this._rootTiles;if(p(s)||!s.length)return null;if(0===s[0].layerInfo[le.ELEVATION].length)return null;const a=dt;if(a[0]=e,a[1]=t,a[2]=i,!M(a,r,a,this._spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;return mt(s,a[0],a[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[le.ELEVATION].length:0;if(!p(r)&&r.length&&0!==s)for(let a=0;a<t;++a){const t=3*a;i(a,mt(r,e[t+0],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getScale(e){if(!this.tilingScheme)return null;if(!j(e,dt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(u(t))for(const i of t)if(i?.containsPoint(dt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;dt[0]>t[2]&&(i+=1),dt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}getSphereElevationBounds(e,t,i,r,s){if(dt[0]=e,dt[1]=t,dt[2]=i,dt[3]=r,!M(dt,s,dt,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&N(e.extent,dt))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this._rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!j(e,dt,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;dt[3]=t;let i=null;const r=e=>{if(e&&N(e.extent,dt)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._allSurfaceLayersTransparent()?t?we.Empty:we.TransparentWithDraped:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?we.Opaque:we.Semitransparent,s=i!==r;return s&&(this._renderer.transparency=r,this.view?._stage?.renderer.setParameters({terrainTransparency:this._renderer.transparency})),s}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;if(!(e!==this.tilingScheme))return;Se(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??A.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateeCarree=this._isWebMercator&&q(this.view?.renderSpatialReference),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles())}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return ut[0]=e,ut[1]=t,ut[2]=i,s.init(ut,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=pt;let s=t.rootTilesInExtent(e,i,5*ge);if(u(this._rootTiles)){if(s.length>ge)return void l.getLogger(this.declaredClass).warn(me);const e=this._rootTiles.map((e=>e.lij)),t=r(e,s,lt);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter((e=>!(t.removed.findIndex((t=>lt(t,e.lij)))>-1)||(this._purgeTile(e),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ge&&(l.getLogger(this.declaredClass).warn(Te),s=t.rootTilesInExtent(e,i,ge)),this._setRootTiles(s.map((e=>this._newRootTile(e))));O(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter((e=>e.isLoaded&&e.intersectsClippingArea));e.forEach((e=>this._renderer.updateTileGeometryState(e))),e.forEach((e=>e.renderData.updateNeighborData())),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Qe);const t=this.renderer;e.forEach((e=>t.updateGeometryIfNeeded(e))),e.forEach((e=>this._pendingTilesForElevationUpdateEvent.add(e)))}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===qe.SPLIT}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(qe.SPLIT),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),u(e)){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(qe.GEOMETRY)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(p(e))return;const t=ze(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this._viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(qe.GEOMETRY)&&this._updateTileGeometryState(e),e.setPendingUpdate(qe.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBounds[0],r),s=Math.max(e.elevationBounds[1],s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._batchUpdatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new te(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;u(i)&&i.forEach((({elevationBounds:i})=>{e=Math.min(e,i[0]),t=Math.max(t,i[1])}));const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new te(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=F()),G(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,G(this._frustum,e.frustum),D(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),C(this._eyePosRenderSR,t.eye),M(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(ot(e)?this._loadChildren(e):ht(e)&&this._loadParent(e))}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this._usedMemory=null}_markAllTileNeighborsForGeometryUpdate(e){const t=this._pendingTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}_updateTileTexture(e,t){const i=e.resetPendingUpdate(qe.TEXTURE_FADING)?qe.TEXTURE_FADING:!!e.resetPendingUpdate(qe.TEXTURE_NOFADING)&&qe.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){const e=_t.extent;k(e),this._pendingTilesForElevationUpdateEvent.forEach((t=>B(e,t.extent,e))),this._pendingTilesForElevationUpdateEvent.clear(),_t.spatialReference=this.spatialReference,this.emit("elevation-change",_t)}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._batchUpdatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed?this.requestUpdate():this.getUsedMemory(),this.notifyChange("updatingProgressValue")}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();t.reset(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;for(;!t.done;){const e=t.next(),a=e.shouldSplit(r,s,i);if(a!==qe.SPLIT){if(e.resetPendingUpdate(qe.SPLIT)&&e.updateAgentSuspension(),a===qe.VSPLITMERGE&&e.updateAgents(le.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(qe.MERGE),e.resetPendingUpdate(qe.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);const i=this._viewProjectionMatrix;for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(i);t.remove()}}else e.resetPendingUpdate(qe.MERGE),e.isLeaf&&(e.setPendingUpdate(qe.SPLIT),t.skipSubtree()),e.rendered&&e.setPendingUpdate(qe.RENDERDATA)}t.remove(),this.requestUpdate(),(this.shortBatches||!this.oneBatchPerFrameTask)&&this._batchUpdatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(Xe(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_markTileToUpdate(e){Le(e.isLoaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForGeometryUpdate(e))}_batchUpdatePendingTileGeometries(){const e=this._pendingTilesToUpdate;if(0===e.size)return;const t=Array.from(this._pendingTilesToUpdate.keys()).filter((e=>e.isLoaded&&e.intersectsClippingArea)),i=(i,r)=>{!r?.isLoaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Qe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Le(r.isLoaded),Le(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a._dirtyEdgeResolutions,l=a.geometryState.neighborData;for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.neighborData.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(De(Oe[t]),(t=>!(!t.isLoaded||!t.intersectsClippingArea)&&(Le(e.has(t)||Qe(r,t)<0),i(r,t),!0))),i(r,l.cornerPeerNeighbors[t]),i(r,l.cornerPeerNeighbors[(t+1)%4])}}e.clear(),this._updateTilesGeometries(t),Ve&&ke&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some((s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.resetPendingUpdate(qe.MERGE)){if(!t)return s.setPendingUpdate(qe.MERGE),e.done;for(;n.parent?.resetPendingUpdate(qe.MERGE);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else s.resetPendingUpdate(qe.SPLIT)&&(this._splitTile(s),a=!0,e.madeProgress());return!e.done&&n===s&&s.resetPendingUpdate(qe.RENDERDATA)&&(this._updateRenderData(s),e.madeProgress()),e.done}));if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this.oneBatchPerFrameTask&&this._batchUpdatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some((t=>(t.resetPendingUpdate(qe.GEOMETRY)&&(this._updateTileGeometryState(t),this._updateTileTexture(t,e),this.shortBatches&&this._batchUpdatePendingTileGeometries(),e.madeProgress()),e.done))),!this.oneBatchPerFrameTask&&this._batchUpdatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done)))}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(et.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*fe}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){u(this._rootTiles)&&(this._rootTiles.forEach((e=>this._purgeTile(e))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(!e.children[0])return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i])||t;return e.unsetChildren(),t}_purgeTile(e){const t=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),this._tilePool.release(e),t}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload(this._renderer)}_splitTile(e){Se(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(qe.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){gt.spatialReference=this.spatialReference,gt.extent=e.extent,gt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",gt)}_createTile(e,t,i,r){Se(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(qe.SPLIT),s}get shortBatches(){return this.view.state.mode!==tt.IDLE}_mergeTile(e){Se(!e.hasPendingUpdate(qe.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(Se(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this.shortBatches&&this._batchUpdatePendingTileGeometries()),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_loadChildren(e){Se(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._loadTile(e))),t.forEach((e=>this._pendingTilesToUpdate.add(e))),this._markAllTileNeighborsForGeometryUpdate(e),this._emitTileScaleChange(e,e.level+1),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_loadParent(e){const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._markTileToUpdate(t),this._emitTileScaleChange(t,t.level),this.shortBatches&&this._batchUpdatePendingTileGeometries()}_unloadChildren(e){const t=e.children;if(t[0])for(let i=0;i<4;++i){const e=t[i];this._unloadChildren(e),this._unloadTile(e)}}_loadTile(e){e.load(),e.setPendingUpdate(qe.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e)}_elevationDataArrived(e,t,i){const r=new ie(e.lij,e.extent,i);e.dataArrived(t,le.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}0===a&&this._updateRootTileElevationBounds(),n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=st){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),Pe(s)||Ce(s))if(this._basemapLayerViewHandles.has(s.uid)&&!Ce(s)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(Ue(t)&&!z(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((be(e)||Ce(e))&&Je(Ze[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Re(e)?le.ELEVATION:le.MAP}_registerTiledLayerView(e){const t=[];if((be(e)||Ce(e))&&t.push(y((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(ne.UNFADED)}))),Ce(e))return;const i=this._layerClassFromLayerView(e);t.push(y((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(y((()=>e.fullOpacity),(()=>this._updateTileTextures(ne.UNFADED)))),t.push(y((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)t[e].remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach((e=>{if(!e.layer||e.suspended||!Pe(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===le.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of oe){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&this._viewChangeUpdate()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===le.ELEVATION&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(le.MAP),e===ne.IMMEDIATE?this.renderer.updateTileTexture(t,qe.TEXTURE_NOFADING):t.updateRenderData(le.MAP,e)})),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=et.UPDATE){this.renderer.setNeedsRender(e)}requestUpdate(){1==++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||xe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(r),m(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===le.ELEVATION?Re(i)?this._requestElevationTileData(e,i,r):Promise.reject():Ue(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(T(i))return;const s=this._layerIndexByUid[le.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",le.ELEVATION,e.lij.toString())},s=i=>{m(i)||(this._dataMissing(e,le.ELEVATION,t,i),this.requestUpdate())};if(Me(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:ye,signal:i.signal}).then((e=>{if(!T(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:ye},i.signal))).then((e=>{e?r(new Q(e)):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Ie(s),T(i)||(this._dataMissing(e,le.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),T(i)?Ie(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(xe(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(je(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(Ae(t)&&Me(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(T(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(f());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);W(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(le.MAP,t.uid);u(r)?e.dataArrived(r,le.MAP,i):(Ie(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this._rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll((t=>{t.isLeaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))})),e}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this._rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this._rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this._rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return Se(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e._rootTiles)&&e._rootTiles.length>0&&(e._mergeTile(e._rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){ct.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&ct.push(e)}));const t=ct.toArray();return Ye(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTilesWaterproofness(){if(!ke)return;const e=this._rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shading(){return this._shading}_updateShadingIfChanged(){const e=this.view?.map?.ground?.shading;e!==this._shading&&this._updateShading()}_updateShading(){const e=this.view?.map?.ground?.shading;this._shading=e,this.renderer&&(this.renderer.shading=e,this.renderer.setNeedsRender()),this._updateAllTileGeometries()}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateeCarree(){return this._isWebMercatorOnPlateeCarree}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.isGeographic?1:0))}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this.isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Be(e)}enableWaterproofnessChecks(e){Ne(e)}};e([S()],at.prototype,"_renderer",void 0),e([S({constructOnly:!0})],at.prototype,"_scaleRangeQueries",void 0),e([S()],at.prototype,"_hasPendingUpdates",void 0),e([S()],at.prototype,"_asyncWorkItems",void 0),e([S()],at.prototype,"_allTilesDirty",void 0),e([S()],at.prototype,"_allTilesSorted",void 0),e([S()],at.prototype,"_viewChanged",void 0),e([S({readOnly:!0})],at.prototype,"_watchUpdatingTracking",void 0),e([S()],at.prototype,"_frameTask",void 0),e([S({readOnly:!0})],at.prototype,"snapLevel",null),e([S({readOnly:!0})],at.prototype,"lodSnapping",null),e([S({constructOnly:!0})],at.prototype,"view",void 0),e([S()],at.prototype,"_userClippingExtent",null),e([S()],at.prototype,"_rootTilesExtent",void 0),e([S({readOnly:!0})],at.prototype,"extent",null),e([S({readOnly:!0})],at.prototype,"groundExtent",null),e([S({readOnly:!0})],at.prototype,"_tilingSchemeExtent",null),e([S({readOnly:!0})],at.prototype,"updating",null),e([S({readOnly:!0})],at.prototype,"running",null),e([S(ee)],at.prototype,"updatingProgress",void 0),e([S({readOnly:!0})],at.prototype,"updatingProgressValue",null),e([S()],at.prototype,"_maxNumUpdating",void 0),e([S()],at.prototype,"baseOpacity",null),e([S()],at.prototype,"hasCompositeBlendMode",void 0),e([S({readOnly:!0})],at.prototype,"overlayManager",void 0),e([S({readOnly:!0})],at.prototype,"viewingMode",null),e([S()],at.prototype,"maxTextureScale",void 0),e([S({readOnly:!0})],at.prototype,"ready",null),e([S({value:pe.FRONT_TO_BACK})],at.prototype,"renderOrder",null),e([S({readOnly:!0})],at.prototype,"rootTiles",null),e([S()],at.prototype,"_rootTiles",void 0),e([S({readOnly:!0})],at.prototype,"spatialReference",null),e([S({type:t})],at.prototype,"backgroundColor",null),e([S({value:!1})],at.prototype,"slicePlaneEnabled",null),e([S({readOnly:!0})],at.prototype,"tilingScheme",void 0),e([S({readOnly:!0})],at.prototype,"tilingSchemeLocked",null),e([S({readOnly:!0})],at.prototype,"tilingSchemeLogic",void 0),e([S({value:!0})],at.prototype,"velvetOverground",null),e([S()],at.prototype,"wireframe",null),e([S({value:!1})],at.prototype,"suspended",null),e([S()],at.prototype,"textureFadeDuration",null),e([S()],at.prototype,"visibleElevationBounds",void 0),e([S()],at.prototype,"rootTileElevationBounds",void 0),e([S()],at.prototype,"_layerViewsDirty",void 0),e([S()],at.prototype,"renderPatchBorders",null),e([S()],at.prototype,"visualizeNormals",null),e([S()],at.prototype,"renderingDisabled",null),at=e([L("esri.views.3d.terrain.TerrainSurface")],at);const nt=at;function lt(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function ot(e){const t=e.children;if(!t[0])return!1;for(const i of t)if(i.shouldLoad)return!0;for(const i of t)if(ot(i))return!0;return!1}function ht(e){return e.isLeaf&&(e.parent?.shouldLoad??!1)}const dt=b(),pt=I(),ut=[0,0,0],ct=new _,_t={spatialReference:null,extent:I(),context:"ground"},gt={spatialReference:null,extent:null,scale:0};function mt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return re(t,i,s)}return null}export{nt as default};
@@ -109,4 +109,4 @@ import{c as e}from"../../../../../../chunks/mat4f64.js";import{ReadLinearDepth a
109
109
  }
110
110
  return vec3(P, 0.0);
111
111
  }
112
- `)}class c{constructor(){this.fadeFactor=1,this.reprojectionMatrix=e()}}export{c as SSRUniforms,n as ScreenSpaceReflections};
112
+ `)}class c{constructor(){this.enabled=!1,this.fadeFactor=1,this.reprojectionMatrix=e()}}export{c as SSRUniforms,n as ScreenSpaceReflections};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import r from"../../../../core/Accessor.js";import{update as t}from"../../../../core/arrayUtils.js";import s from"../../../../core/Handles.js";import has from"../../../../core/has.js";import{unwrapOr as i,removeMaybe as a,disposeMaybe as n,isSome as h,isNone as o,applySome as d,unwrap as l}from"../../../../core/maybe.js";import _ from"../../../../core/PooledArray.js";import{watch as c,syncAndInitial as p,initial as m,sync as u}from"../../../../core/reactiveUtils.js";import{property as f}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as g}from"../../../../core/accessorSupport/decorators/subclass.js";import{h as T,a as b,m as R}from"../../../../chunks/mat4.js";import{I as E,c as A}from"../../../../chunks/mat4f64.js";import{a as P}from"../../../../chunks/boundedPlane.js";import S from"../../support/debugFlags.js";import{TransparencyMode as y}from"../../terrain/TerrainRenderer.js";import{RenderPassManager as w}from"../core/renderPasses/RenderPassManager.js";import{ShaderOutput as O}from"../core/shaderLibrary/ShaderOutput.js";import{HUDTransparentRenderStyle as C}from"../core/shaderLibrary/hud/HUDUniforms.js";import{AnimationTimeStep as D}from"./AnimationTimeStep.js";import{Decorations as I,RenderRequestType as x,StencilBits as H}from"./basicInterfaces.js";import{BoundingInfo as v}from"./BoundingInfo.js";import{ZERO as M,union as L}from"./depthRange.js";import{depthRangeFromScene as N}from"./depthRangeUtils.js";import{createEmptyDepthTexture as U}from"./glUtil3D.js";import{Highlight as F}from"./Highlight.js";import{RenderOccludedFlag as j}from"./Material.js";import{OffscreenRendering as G}from"./OffscreenRendering.js";import{RenderContext as q}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as V}from"./rendererUtils.js";import{RenderFeature as B,setupFeatureDefaults as W}from"./RenderFeature.js";import{RenderPluginManager as k}from"./RenderPluginManager.js";import{RenderSlot as Q}from"./RenderSlot.js";import{ShadowAccumulator as Y}from"./ShadowAccumulator.js";import{ShadowHighlight as X}from"./ShadowHighlight.js";import{ShadowMap as z,SnapshotSlot as J}from"./ShadowMap.js";import K from"./SliceHelper.js";import{SmaaRenderPass as Z}from"./SmaaRenderPass.js";import{SSAOHelper as $}from"./SSAOHelper.js";import{TransparencyPassType as ee}from"./TransparencyPassType.js";import{EdgeView as re}from"./edgeRendering/EdgeView.js";import{Transparency as te}from"./edgeRendering/interfaces.js";import{MergedRenderer as se}from"../materials/renderers/MergedRenderer.js";import{AlphaMode as ie}from"../shaders/CompositingTechniqueConfiguration.js";import{RendererPerformanceInfo as ae,PerformanceCategory as ne}from"../statistics/RendererPerformanceInfo.js";import{RenderState as he}from"../../../support/RenderState.js";import{ClearBufferBit as oe,PixelFormat as de,PixelType as le}from"../../../webgl/enums.js";let _e=class extends r{get _bindParameters(){return this._renderContext.bindParameters}isFeatureEnabled(e,r=this._state){return i(this._renderStateFeatures.get(r,e),!1)}setFeatureEnabled(e,r,t){this._renderStateFeatures.set(r,e,t),this.notifyChange("_renderStateFeatures"),this._requestRender()}get _antialiasing(){return this._antialiasingEnabled||this.isFeatureEnabled(B.Antialiasing)}get _highQualityTransparency(){return this._highQualityTransparencyEnabled||this.isFeatureEnabled(B.HighQualityTransparency)}get hasWaterReflection(){return this.hasWater&&(this._waterReflectionEnabled||this.isFeatureEnabled(B.WaterReflection))}get hasWater(){return this._hasWater||this._hasOverlayWater}constructor(e,r,t,i,a,n,h,o){super({}),this._stage=e,this._materialRepository=r,this._shaderTechniqueRepository=i,this._rctx=a,this._compositingHelper=n,this._magnifierHelper=h,this._requestRender=o,this._materialRenderers=new _,this._needsTransparentPass=!1,this._hasHUDElements=!1,this._hasHighlights=!1,this._hasWater=!1,this._hasOverlayWater=!1,this._renderOverlay=e=>{},this._isRendering=!1,this._fallbackDepthStencilTexture=null,this._sliceHelper=new K,this._state=he.IDLE,this._renderStateFeatures=W(),this._antialiasingEnabled=!0,this._highQualityTransparencyEnabled=!0,this._terrainRenderingEnabled=!0,this._terrainTransparency=y.Opaque,this._waterReflectionEnabled=!1,this._ssaoEnabled=!1,this._hasAnimations=!1,this._animationTimestep=new D,this._handles=new s,this._renderHiddenTransparentEdges=()=>{},this._oitUsed=!1,this._smaaPass=new Z(this._rctx,i),o(),this._offscreen=new G(this._rctx,this._compositingHelper),this.performanceInfo=new ae(this._rctx),this._shadowMap=new z(this._rctx,e.viewingMode),this._ssaoHelper=new $(e.view,i,this._rctx,o),this._highlight=new F(i,this._rctx),this._shadowHighlight=new X(this._rctx,e.viewingMode),this._shadowAccumulator=new Y(this._rctx,i,e,(e=>{const r=this.shadowsEnabled;this._shadowMap.enabled=!0,this._prepare(e.camera,e.contentCamera),this._renderPlugins.prepareRender(),this._shadowMap.enabled=r}),((e,r,t)=>{e.shadowMap.start(e.camera,r,t),this._renderShadowCascades(O.Shadow,e.shadowMap),e.camera.setGLViewport(this._rctx),this._prepare(e.camera,e.contentCamera)}),o),this._renderContext=new q(this._rctx,this._offscreen,this._shadowMap,this._ssaoHelper,this._sliceHelper),this._renderPlugins=new k({renderContext:this._renderContext,techniqueRepository:i,textureRepository:t,materialRepository:this._materialRepository,requestRender:o,controller:e}),this.renderPassManager=new w(this._rctx,this._shaderTechniqueRepository),this._renderPlugins.add(this.renderPassManager.slots(),this.renderPassManager),this._handles.add([c((()=>this._stage.view.state.camera),(()=>o()),p),c((()=>S.EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES),(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(te.TRANSPARENT):()=>{},o()}),m),c((()=>this._ssaoEnabled||this.isFeatureEnabled(B.SSAO)),(e=>this._ssaoHelper.enabled=e),p)])}normalizeCtorArgs(){return{}}destroy(){this._handles.destroy(),this._smaaPass.dispose(),this._gpuTimerHandle=a(this._gpuTimerHandle),this._materialRenderers.forAll((e=>e.dispose())),this._materialRenderers.clear(),this._offscreen.dispose(),this._fallbackDepthStencilTexture=n(this._fallbackDepthStencilTexture),this._shadowMap.dispose(),this._ssaoHelper.dispose(),this._highlight.dispose(),this._shadowHighlight.dispose(),this._shadowAccumulator.dispose(),v.prune()}disposeOffscreenBuffers(){this._offscreen.dispose(),this._shadowMap.dispose(),this._smaaPass.disable(),this._ssaoHelper.disposeOffscreenBuffers()}get updating(){return this._antialiasing&&this._smaaPass.updating||h(this._edgeView)&&this._edgeView.updating||this._shadowAccumulator.running||!this.isCameraFinal}ensureEdgeView(){return o(this._edgeView)&&(this._edgeView=new re({rctx:this._rctx,renderSR:this._stage.view.renderSpatialReference,viewingMode:this._stage.viewingMode,techniqueRepository:this._shaderTechniqueRepository,setNeedsRender:()=>this._requestRender(),schedule:e=>this._stage.view.resourceController.immediate.schedule(e)}),this._handles.add(c((()=>d(this._edgeView,(e=>e.updating))),(()=>this._requestRender()),u)),this._requestRender()),this._edgeView}get edgeView(){return this._edgeView}get isCameraFinal(){return T(this._bindParameters.ssr.reprojectionMatrix,E)}set _reprojectionMatrix(e){t(this._bindParameters.ssr.reprojectionMatrix,e)&&this.notifyChange("isCameraFinal")}get shadowsEnabled(){return!!this._shadowMap?.enabled}setParameters(e){const{_shadowMap:r,_bindParameters:t}=this;if(void 0!==e.screenSpaceReflectionsEnabled&&t.ssr.enabled!==e.screenSpaceReflectionsEnabled&&(t.ssr.enabled=e.screenSpaceReflectionsEnabled,this._requestRender()),void 0!==e.shadowMap&&this._shadowMap.enabled!==e.shadowMap&&(this._shadowMap.enabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&r.maxCascades!==e.shadowMapMaxCascades&&(r.maxCascades=e.shadowMapMaxCascades,this._requestRender()),h(e.environment)){h(e.environment.weather)&&(this._bindParameters.weather=e.environment.weather,this._bindParameters.weatherVisible=!!e.weatherVisible),void 0!==e.environment.lighting.ambientOcclusionEnabled&&this._ssaoEnabled!==e.environment.lighting.ambientOcclusionEnabled&&(this._ssaoEnabled=e.environment.lighting.ambientOcclusionEnabled,this._requestRender()),void 0!==e.environment.lighting.waterReflectionEnabled&&this._waterReflectionEnabled!==e.environment.lighting.waterReflectionEnabled&&(this._waterReflectionEnabled=e.environment.lighting.waterReflectionEnabled,this._requestRender());const r="virtual"!==e.environment.lighting.type;t.enableFillLights!==r&&(t.enableFillLights=r,this._requestRender())}e.background&&this._offscreen.background!==e.background&&(this._offscreen.background=e.background,this._requestRender()),void 0!==e.antialiasingEnabled&&this._antialiasingEnabled!==e.antialiasingEnabled&&(this._antialiasingEnabled=e.antialiasingEnabled,this._requestRender()),void 0!==e.highQualityTransparency&&this._highQualityTransparencyEnabled!==e.highQualityTransparency&&(this._highQualityTransparencyEnabled=e.highQualityTransparency,this._requestRender()),void 0!==e.defaultHighlightOptions&&(this._highlight.setDefaultOptions(e.defaultHighlightOptions),this._shadowHighlight.setDefaultOptions(e.defaultHighlightOptions),this._requestRender()),void 0!==e.overlays&&this._bindParameters.overlays!==e.overlays&&(this._bindParameters.overlays=e.overlays,this._requestRender()),void 0!==e.hasOverlayWater&&this._hasOverlayWater!==e.hasOverlayWater&&(this._hasOverlayWater=e.hasOverlayWater,this._requestRender()),void 0!==e.renderOverlay&&this._renderOverlay!==e.renderOverlay&&(this._renderOverlay=e.renderOverlay,this._requestRender()),void 0!==e.slicePlane&&this._sliceHelper.plane!==e.slicePlane&&(this._sliceHelper.plane=l(e.slicePlane),this._requestRender()),void 0!==e.terrainRenderingEnabled&&this._terrainRenderingEnabled!==e.terrainRenderingEnabled&&(this._terrainRenderingEnabled=e.terrainRenderingEnabled,this._requestRender()),void 0!==e.terrainTransparency&&this._terrainTransparency!==e.terrainTransparency&&(this._terrainTransparency=e.terrainTransparency,this._requestRender()),void 0!==e.shadowCastOptions&&this._shadowAccumulator.setOptions(e.shadowCastOptions)}get hasSlicePlane(){return!!this._sliceHelper.plane}get renderPlugins(){return this._renderPlugins}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlend.result}get _oitEnabled(){return this._highQualityTransparency&&this._hasOITSupport}modify(e,r){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:t,removes:s,updates:i}=e;if(0===t.length&&0===s.length&&0===i.length)return;const a=V(e);let n=!1;a.forEach(((t,s)=>{if(r.done)return;let i=this._materialRenderers.find((e=>e.material===s));o(i)&&t.adds.length>0&&(i=new se(this._rctx,this._materialRepository,s),this._materialRenderers.push(i)),i&&(i.modify(t),i.isEmpty&&(n=!0)),t.removes.forEach((r=>e.removes.removeUnordered(r))),t.adds.forEach((r=>e.adds.removeUnordered(r))),t.updates.forEach((r=>e.updates.removeUnordered(r))),r.madeProgress()})),n&&this._materialRenderers.filterInPlace((e=>!e.isEmpty||(e.dispose(),!1))),this._hasHighlights=this._materialRenderers.some((e=>e.hasHighlights)),this._bindParameters.hasOccludees=this._materialRenderers.some((e=>e.hasOccludees)),this._hasWater=this._materialRenderers.some((e=>e.hasWater)),this._hasHUDElements=this._materialRenderers.some((e=>e.requiresSlot(Q.LINE_CALLOUTS_HUD_DEPTH,O.Color)||e.requiresSlot(Q.HUD_MATERIAL,O.Color)||e.requiresSlot(Q.LABEL_MATERIAL,O.Color))),this._requestRender()}updateAnimation(e){const r=this._hasAnimations;return this._hasAnimations=!1,this._materialRenderers.forAll((r=>this._hasAnimations=r.updateAnimation(e)||this._hasAnimations)),this._hasAnimations=this._renderPlugins.updateAnimation(e)||this._hasAnimations,this._hasAnimations!==r&&(this._gpuTimerHandle=r?a(this._gpuTimerHandle):this.performanceInfo.enableGPUPerformanceInfo()),this._hasAnimations}get animationTimestep(){return this._animationTimestep.value}get animationTimeDilation(){return this._animationTimestep.timeDilation}resetAnimation(){this._animationTimestep.clear()}render(e,r,t,s,i){this._isRendering=!0,this.performanceInfo.startFrame();const{camera:a,contentCamera:n,mode:d}=t;this._state=d,this._renderOverlay(i),this.performanceInfo.advance(ne.OVERLAY),this._renderContext.time=i,this._bindParameters.transparencyPassType=ee.NONE;const l=this._offscreen;l.setupRenderTarget(this.hasWaterReflection);const _=P(this._sliceHelper.plane);s===I.OFF&&(this._sliceHelper.plane=null),this._rctx.bindFramebuffer(e),a.setGLViewport(this._rctx),this._prepare(a,n),this._renderPlugins.prepareRender(),this.performanceInfo.advance(ne.PREPARE);const c=this._computeDepthRange(a);this._renderShadowMap(e,a,this._bindParameters.lighting.mainLight.direction,c),this.performanceInfo.advance(ne.SHADOW_MAP),l.initializeFrame(a),this._ensureBindParameters(a,n),this._renderLinearDepth(),this.performanceInfo.advance(ne.LINEAR_DEPTH),this._accumulateShadows(c,a,n),this.performanceInfo.advance(ne.ACCUMULATED_SHADOWS),this._renderNormal(),this.performanceInfo.advance(ne.NORMALS),this._ensureBindParametersSSR(i),this._renderSSAO(i),this.performanceInfo.advance(ne.SSAO),this._renderContext.output=O.Color,l.bindFramebuffer(),this._renderOpaqueGeometry(),this.performanceInfo.advance(ne.OPAQUE);const p=this._terrainRenderingEnabled&&(this._terrainTransparency===y.Semitransparent||this._terrainTransparency===y.TransparentWithDraped),m=this._highQualityTransparency&&p;this._renderTerrainLinearDepth(m),this._setMultipassEnabled(m),this._setTerrainCulling(m),this._renderEdges(te.OPAQUE),this.performanceInfo.advance(ne.OPAQUE_EDGES),this._offscreen.bindTarget(this._offscreen.currentColorTarget,this._offscreen.mainDepth),this._renderSlot(Q.VOXEL),this.performanceInfo.advance(ne.VOXEL),this._renderHiddenTransparentEdges();const u=this._needsTransparentPass||this._renderPlugins.needsTransparentPass;u&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(ne.TRANSPARENT),this._renderGeometryLinearDepth(m);const f=this._renderHUDVisibility(m);m||this._renderInternalSlot(Q.LINE_CALLOUTS),this.performanceInfo.advance(ne.HUD_VISIBILITY),this._renderObjectAndLayerIdColor(r),this.performanceInfo.advance(ne.OBJECT_AND_LAYER_ID_COLOR),this._renderEdges(te.TRANSPARENT,m),this.performanceInfo.advance(ne.TRANSPARENT_EDGES),this._renderTransparentTerrain(),p&&f&&(m?this._renderLineCallouts(C.Occluded):l.compositeTransparentTerrainOntoHUDVisibility(this._bindParameters),this._renderHUD(C.Occluded,l.framebuffer),this.performanceInfo.advance(ne.HUD_OCCLUDED)),this.performanceInfo.advance(ne.TRANSPARENT_TERRAIN),this._setTerrainCulling(!1),p&&(l.compositeTransparentTerrainOntoMain(this._bindParameters),m&&(this._renderEdges(te.OPAQUE),this.performanceInfo.advance(ne.OPAQUE_EDGES),u&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(ne.TRANSPARENT),this._renderEdges(te.TRANSPARENT),this.performanceInfo.advance(ne.TRANSPARENT_EDGES))),m&&this._renderLineCallouts(C.NotOccluded),this._setMultipassEnabled(!1),this._shadowAccumulator.render(this._bindParameters),l.renderToTargets((()=>{this._renderInternalSlot(Q.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL),this._renderSlot(Q.POSTPROCESSING_ENVIRONMENT_TRANSPARENT),this._renderSlot(Q.LASERLINES)}),l.currentColorTarget,l.mainDepth),this.performanceInfo.advance(ne.ENVIRONMENT),this._renderPlugins.needsLaserlineWithContrastControl&&l.renderTmpAndCompositeToMain((()=>this._renderSlot(Q.LASERLINES_CONTRAST_CONTROL)),this._bindParameters,ie.PremultipliedAlpha),this.performanceInfo.advance(ne.LASER_LINE),this._renderOccluded(),this.performanceInfo.advance(ne.OCCLUDED);const g=s===I.ON&&this._magnifierHelper.enabled,T=g&&o(e)?this._offscreen.getFramebuffer(this._offscreen.tmpColor,this._offscreen.tmpDepth):e;this._rctx.bindFramebuffer(T);const b=this._offscreen.colorTexture;!this._renderAntiAliasing(b)&&h(b)&&this._compositingHelper.composite(this._bindParameters,b,ie.None),this.performanceInfo.advance(ne.ANTIALIASING),this._renderHUD(C.NotOccluded,T),this.performanceInfo.advance(ne.HUD),this._renderHighlights(T,this._bindParameters),this.performanceInfo.advance(ne.HIGHLIGHTS),g&&this._magnifierHelper.render(this._rctx,this._bindParameters),T!==e&&(this._rctx.bindFramebuffer(e),this._compositingHelper.composite(this._bindParameters,this._offscreen.tmpColorTexture,ie.None)),this._disposeOITBuffers(),this._renderContext.lastFrameCamera.copyFrom(this._bindParameters.camera),this._sliceHelper.plane=_,this._isRendering=!1,this.onPostRender&&this.onPostRender(),this.performanceInfo.finishFrame()}_renderObjectAndLayerIdColor(e){h(e)&&has("enable-feature:objectAndLayerId-rendering")&&(this._rctx.bindFramebuffer(e),this._offscreen.renderToFBO((()=>this._renderGeometryAndTransparentTerrainPass(O.ObjectAndLayerIdColor)),[0,0,0,0],!0,!0),this._rctx.bindFramebuffer(e),this._offscreen.renderToFBO((()=>{this._bindParameters.renderTransparentlyOccludedHUD=C.NotOccluded,this._renderInternalSlot(Q.HUD_MATERIAL)}),void 0,!0,!0))}finish(e){this._hasAnimations||this._animationTimestep.clear();const r=this.performanceInfo.gpuSamplingEnabled,t=e===x.BACKGROUND;if(t||r){const e=t?this.performanceInfo.elapsedTime:0,s=r?this.performanceInfo.totalGPUTimeSampler.last:this._rctx.gl.getError(),i=Math.max(e,s);this._animationTimestep.frame(i,t)}}readDepthPixels(e,r,t){const s=this._offscreen.bindTarget(this._offscreen.linearDepth,this._offscreen.tmpDepth);if(!this._needsLinearDepth){this._ensureBindParameters(e,e),this._bindParameters.camera.setGLViewport(this._rctx),this._rctx.setClearColor(0,0,0,0);const r=oe.COLOR_BUFFER_BIT|oe.DEPTH_BUFFER_BIT|oe.STENCIL_BUFFER_BIT;this._rctx.clearSafe(r),this._renderGeometryAndTransparentTerrainPass(O.Depth)}s.readPixels(r[0],r[1],r[2],r[3],de.RGBA,le.UNSIGNED_BYTE,t)}readHUDVisibility(e,r,t,s,i){this._offscreen.bindTarget(this._offscreen.hudVisibility).readPixels(e,r,t,s,de.RGBA,le.UNSIGNED_BYTE,i)}readAccumulatedShadow(e){return this._shadowAccumulator.readAccumulatedShadow(e[0],e[1])}_setMultipassEnabled(e){this._bindParameters.multipassTerrain.enabled=this._bindParameters.multipassGeometry.enabled=e}_setTerrainCulling(e){this._bindParameters.multipassTerrain.cullAboveGround=e}_renderSlot(e){this._bindParameters.slot=e,this._renderPlugins.render()}_renderEdges(e,r=!1){const t=this._edgeView;h(t)&&t.shouldRender()&&this._offscreen.renderTmpAndCompositeToMain((()=>t.render(this._bindParameters,e)),this._bindParameters,ie.Alpha,r)}_renderShadowMap(e,r,t,s){const i=this._shadowMap;i.enabled&&this.isFeatureEnabled(B.ShadowMapUpdate)&&(i.start(r,t,s),this._shadowHighlight.updateParameters(r,t),this._needsShadowHighlight?(this._renderShadowCascades(O.ShadowHighlight,this._shadowMap,(e=>i.takeCascadeSnapshotTo(e,J.Highlight))),i.clear(),this._renderShadowCascades(O.ShadowExcludeHighlight,this._shadowMap,(e=>{i.takeCascadeSnapshotTo(e,J.Default),this._renderGeometryAndTransparentTerrainPass(O.ShadowHighlight)}))):this._renderShadowCascades(O.Shadow),i.finish(e),r.setGLViewport(this._rctx))}_renderShadowCascades(e,r=this._shadowMap,t=(e=>{})){for(const s of r.cascades)s.camera.setGLViewport(this._rctx),this._prepare(s.camera,s.camera),this._renderGeometryAndTransparentTerrainPass(e),t(s)}get _needsLinearDepth(){return this._ssaoHelper.active||this._renderPlugins.needsLinearDepth||this.hasWaterReflection||this._needsShadowHighlight||this._needsShadowCast}_renderLinearDepth(){this._needsLinearDepth?this._offscreen.renderToTargets((()=>this._renderGeometryAndTransparentTerrainPass(O.Depth)),this._offscreen.linearDepth,this._offscreen.tmpDepth,[0,0,0,0],!0,!0):this._offscreen.disposeTarget(this._offscreen.linearDepth),this._bindParameters.linearDepthTexture=this._offscreen.linearDepthTexture}_renderTerrainLinearDepth(e){if(e){const e=this._renderContext.output;this._renderContext.output=O.Depth,this._offscreen.renderToTargets((()=>this._renderTransparentTerrain()),this._offscreen.terrainLinearDepth,this._offscreen.tmpDepth,[-1e10,-1e10,-1e10,1],!0,!0),this._renderContext.output=e}else this._offscreen.disposeTarget(this._offscreen.terrainLinearDepth);this._bindParameters.multipassTerrain.linearDepthTexture=this._offscreen.terrainLinearDepthTexture}_renderGeometryLinearDepth(e){if(e){const e=this._renderContext.output;this._offscreen.renderToTargets((()=>this._renderGeometryPass(O.Depth)),this._offscreen.geometryLinearDepth,this._offscreen.tmpDepth,[1,1,1,1],!0,!0),this._renderContext.output=e}else this._offscreen.disposeTarget(this._offscreen.geometryLinearDepth);this._bindParameters.multipassGeometry.linearDepthTexture=this._offscreen.geometryLinearDepthTexture}get _needsNormal(){return this._ssaoHelper.active}_renderNormal(){this._needsNormal?this._offscreen.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(O.Normal)}),this._offscreen.normal,this._offscreen.tmpDepth,[0,0,0,0],!0,!0):this._offscreen.disposeTarget(this._offscreen.normal)}get _needsDepthRange(){return this._shadowMap.enabled||this._needsShadowCast}_computeDepthRange(e){if(!this._needsDepthRange)return M;const r=N(e,this._materialRenderers,this._stage.layers);return L(r,this.renderPlugins.queryDepthRange(e)),r.near=Math.max(e.near,r.near),r.far=Math.min(e.far,r.far),r}_renderGeometryAndTransparentTerrainPass(e){this._renderContext.output=e,this._renderGeometryPass(e),this._renderTransparentTerrain()}_renderGeometryPass(e){this._renderContext.output=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderSSAO(e){this._ssaoHelper.render(this._bindParameters,e,this._offscreen.linearDepthTexture,this._offscreen.normalTexture)}_renderOpaqueGeometry(){this._renderSlot(Q.INTEGRATED_MESH),this._renderSlot(Q.OPAQUE_TERRAIN),this._renderInternalSlot(Q.OPAQUE_MATERIAL),this._renderSlot(Q.OPAQUE_MATERIAL),this._renderSlot(Q.POSTPROCESSING_ENVIRONMENT_OPAQUE)}_renderTransparentGeometry(){this._renderInternalSlot(Q.TRANSPARENT_MATERIAL),this._renderSlot(Q.TRANSPARENT_MATERIAL)}_renderTransparentTerrain(){this._renderSlot(Q.TRANSPARENT_TERRAIN)}_renderHUDVisibility(e){let r=!1;return this._renderContext.offscreenRenderingHelper&&this._renderContext.offscreenRenderingHelper.renderHUDVisibility((()=>{this._bindParameters.hudVisibilityTexture=this._renderContext.offscreenRenderingHelper.hudVisibilityTexture,r=this._renderInternalSlot(Q.OCCLUSION_PIXELS)}),e),r}_renderLineCallouts(e){this._bindParameters.renderTransparentlyOccludedHUD=e,e===C.Occluded?this._offscreen.renderToTargets((()=>this._renderInternalSlot(Q.LINE_CALLOUTS)),this._offscreen.currentColorTarget,this._offscreen.tmpDepth,void 0,!0,!0):this._renderInternalSlot(Q.LINE_CALLOUTS)}_renderHUD(e,r){this._hasHUDElements&&(this._oitEnabled?(this._renderOrderIndependentTransparency((()=>this._renderHUDElements(e)),!0),this._rctx.bindFramebuffer(r),this._compositingHelper.composite(this._bindParameters,this._offscreen.hudColorTexture,ie.PremultipliedAlpha)):e===C.Occluded?this._offscreen.renderToTargets((()=>this._renderHUDElements(C.Occluded)),this._offscreen.currentColorTarget,this._offscreen.tmpDepth,void 0,!0,!0):this._renderHUDElements(e))}_renderHUDElements(e){this._bindParameters.renderTransparentlyOccludedHUD=e,this._renderInternalSlot(Q.LINE_CALLOUTS_HUD_DEPTH),this._renderInternalSlot(Q.HUD_MATERIAL),this._renderInternalSlot(Q.LABEL_MATERIAL)}get _needsHighlight(){return this._hasHighlights||this._renderPlugins.needsHighlight}get _needsShadowHighlight(){return this._shadowMap.enabled&&this._shadowHighlight.isVisible&&this._needsHighlight}_renderHighlights(e,r){if(!this._needsHighlight)return void this._offscreen.disposeTarget(this._offscreen.highlight);const t=this._highlight,s=this._offscreen.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(O.Highlight),this._rctx.clearSafe(oe.DEPTH_BUFFER_BIT),this._renderHUDElements(C.Both)}),this._offscreen.highlight,this._offscreen.tmpDepth,[0,0,0,0],!0,!0);this._bindParameters.highlightColorTexture=s.colorTexture,this._needsShadowHighlight&&this._shadowHighlight.render(r,e),t.render(this._bindParameters,s,e)}get _needsShadowCast(){return this._shadowAccumulator.isAccumulating}_accumulateShadows(e,r,t){this._needsShadowCast&&h(this._offscreen.linearDepthTexture)&&this._shadowAccumulator.renderAccumulation(this._offscreen.linearDepthTexture,e,r,t)}_renderOrderIndependentTransparency(e,r){const t=t=>{this._bindParameters.transparencyPassType=t,this._offscreen.renderOITPass((()=>e()),t,r)},s=this._renderContext.output;this._renderContext.output=O.Alpha,t(ee.Alpha),this._renderContext.output=O.Color,t(ee.Color),t(ee.FrontFace),this._offscreen.compositeTransparentOntoOpaque(this._bindParameters,r),this._bindParameters.transparencyPassType=ee.NONE,this._renderContext.output=s,this._oitUsed=!0}_disposeOITBuffers(){this._oitUsed||(this._offscreen.disposeTarget(this._offscreen.alphaFloatTarget),this._offscreen.disposeTarget(this._offscreen.colorFloatTarget),this._offscreen.disposeTarget(this._offscreen.frontFaceTarget)),this._oitUsed=!1}_renderOccluded(){let e=0;pe.clear(),this._materialRenderers.forAll((r=>{r.material&&r.material.isVisible()&&r.material.renderOccluded===j.OccludeAndTransparentStencil&&(e|=r.material.renderOccluded,pe.push(r))}));const r=this._offscreen,t=(t,s,i,a,n)=>{0!=(e&s)&&(r.renderToTargets(i,r.tmpColor,r.mainDepth,[0,0,0,0],a,n),r.compositeOccludedOntoMain(this._bindParameters,t))};0!==pe.length&&(this._renderInternalSlot(Q.OCCLUDER_MATERIAL,pe),t(.5,j.OccludeAndTransparentStencil,(()=>this._renderInternalSlot(Q.TRANSPARENT_OCCLUDER_MATERIAL,pe)),!1,!1)),pe.clear(),this._materialRenderers.forAll((r=>{r.material&&r.material.isVisible()&&(r.material.renderOccluded===j.OccludeAndTransparent||r.material.renderOccluded===j.Transparent||r.material.renderOccluded===j.Opaque)&&(e|=r.material.renderOccluded,pe.push(r))}));const s=this._renderPlugins.renderOccludedFlags;if(e|=s,!e)return;const i=e=>{this._renderContext.renderOccludedMask=e,s>j.Occlude&&this._renderSlot(Q.OCCLUDED_TERRAIN),this._renderInternalSlot(Q.OPAQUE_MATERIAL,pe),this._renderInternalSlot(Q.TRANSPARENT_MATERIAL,pe),this._renderInternalSlot(Q.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL,pe),this._renderContext.resetRenderOccludedMask()};this._renderContext.output=O.Color,t(.5,j.OccludeAndTransparent,(()=>i(j.OccludeAndTransparent)),!0,H.OutlineVisualElementMask),t(.5,j.Transparent,(()=>i(j.Transparent)),!0,H.OutlineVisualElementMask),t(1,j.Opaque,(()=>i(j.Opaque)),!0,H.OutlineVisualElementMask),pe.clear()}_renderAntiAliasing(e){if(this._antialiasing){if(this._smaaPass.enable((()=>this._requestRender()))&&h(e))return this._smaaPass.render(e),!0}else this._smaaPass.disable();return!1}_prepare(e,r){this._needsTransparentPass=this._materialRenderers.some((e=>e.requiresSlot(Q.TRANSPARENT_MATERIAL,O.Color))),this._bindParameters.camera=e,this._bindParameters.contentCamera=r}_ensureBindParameters(e,r){this._bindParameters.camera=e,this._bindParameters.contentCamera=r;const t=this._renderContext.offscreenRenderingHelper;this._bindParameters.hudVisibilityTexture=t.hudVisibilityTexture,this._bindParameters.mainColorTexture=t.mainColorTexture,this._bindParameters.highlightDepthTexture=t.depthTexture??this._getFallbackDepthTexture()}_ensureBindParametersSSR(e){if(this._bindParameters.ssr.enabled=this.hasWaterReflection,this._bindParameters.ssr.enabled){o(this._waterReflectionEnableTime)&&(this._waterReflectionEnableTime=e),this._renderContext.lastFrameCamera.equals(this._bindParameters.camera)?this._reprojectionMatrix=E:(b(ue,this._bindParameters.camera.viewMatrix),b(me,this._bindParameters.camera.projectionMatrix),R(fe,ue,me),R(fe,this._renderContext.lastFrameCamera.viewMatrix,fe),R(fe,this._renderContext.lastFrameCamera.projectionMatrix,fe),this._reprojectionMatrix=fe),this._bindParameters.ssr.lastFrameColorTexture=this._offscreen.lastFrameColorTexture;const r=this._stage.view.qualitySettings.fadeDuration;this._bindParameters.ssr.fadeFactor=r>0?Math.min(r,e-this._waterReflectionEnableTime)/r:1,this._bindParameters.ssr.fadeFactor<1&&this._requestRender()}else this._bindParameters.ssr.lastFrameColorTexture=null,this._waterReflectionEnableTime=null}_renderInternalSlot(e,r=this._materialRenderers){let t=!1;return this._bindParameters.slot=e,r.forAll((e=>{e.material.shouldRender(this._renderContext)&&e.render(this._renderContext.output,this._bindParameters)&&(t=!0)})),t}_getFallbackDepthTexture(){return this._fallbackDepthStencilTexture||(this._fallbackDepthStencilTexture=U(this._rctx)),this._fallbackDepthStencilTexture}get gpuMemoryUsage(){return{offscreen:this._offscreen?.gpuMemoryUsage??0,highlights:(this._highlight?.gpuMemoryUsage??0)+(this._shadowHighlight?.gpuMemoryUsage??0),shadows:this._shadowMap?.gpuMemoryUsage??0,ssao:this._ssaoHelper?.gpuMemoryUsage??0}}get test(){const e=this;return{offscreen:this._offscreen,shadowMap:this._shadowMap,ssao:this._ssaoHelper,highlight:this._highlight,lighting:this._bindParameters.lighting,materialRenderers:this._materialRenderers,shadowAccumulator:this._shadowAccumulator,weatherIsFading:this._bindParameters.cloudsFade.isFading,getFramebufferTexture:r=>{switch(r){case ce.Color:return e._offscreen.colorTexture;case ce.LinearDepth:return e._offscreen.linearDepthTexture;case ce.Normals:return e._offscreen.normalTexture;case ce.ShadowMap:return e._shadowMap.depthTexture;case ce.HudVisibility:return e._offscreen.hudVisibilityTexture;case ce.Highlight:return e._offscreen.highlightTexture}}}}};var ce;e([f()],_e.prototype,"_shadowAccumulator",void 0),e([f()],_e.prototype,"_state",void 0),e([f({readOnly:!0})],_e.prototype,"_renderStateFeatures",void 0),e([f()],_e.prototype,"_antialiasingEnabled",void 0),e([f({readOnly:!0})],_e.prototype,"_antialiasing",null),e([f()],_e.prototype,"_ssaoEnabled",void 0),e([f()],_e.prototype,"_smaaPass",void 0),e([f({autoDestroy:!0})],_e.prototype,"_edgeView",void 0),e([f()],_e.prototype,"updating",null),e([f()],_e.prototype,"isCameraFinal",null),_e=e([g("esri.views.3d.webgl-engine.lib.Renderer")],_e),function(e){e[e.Color=0]="Color",e[e.LinearDepth=1]="LinearDepth",e[e.Normals=2]="Normals",e[e.ShadowMap=3]="ShadowMap",e[e.HudVisibility=4]="HudVisibility",e[e.Highlight=5]="Highlight"}(ce||(ce={}));const pe=new _,me=A(),ue=A(),fe=A();export{ce as FramebufferId,_e as Renderer};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import r from"../../../../core/Accessor.js";import{update as t}from"../../../../core/arrayUtils.js";import s from"../../../../core/Handles.js";import has from"../../../../core/has.js";import{unwrapOr as i,removeMaybe as a,disposeMaybe as n,isSome as h,isNone as o,applySome as d,unwrap as l}from"../../../../core/maybe.js";import _ from"../../../../core/PooledArray.js";import{watch as c,syncAndInitial as p,initial as m,sync as u}from"../../../../core/reactiveUtils.js";import{property as f}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as g}from"../../../../core/accessorSupport/decorators/subclass.js";import{h as T,a as b,m as R}from"../../../../chunks/mat4.js";import{I as E,c as A}from"../../../../chunks/mat4f64.js";import{a as P}from"../../../../chunks/boundedPlane.js";import S from"../../support/debugFlags.js";import{TransparencyMode as y}from"../../terrain/TerrainRenderer.js";import{RenderPassManager as w}from"../core/renderPasses/RenderPassManager.js";import{ShaderOutput as O}from"../core/shaderLibrary/ShaderOutput.js";import{HUDTransparentRenderStyle as C}from"../core/shaderLibrary/hud/HUDUniforms.js";import{AnimationTimeStep as D}from"./AnimationTimeStep.js";import{Decorations as I,RenderRequestType as x,StencilBits as H}from"./basicInterfaces.js";import{BoundingInfo as v}from"./BoundingInfo.js";import{ZERO as M,union as L}from"./depthRange.js";import{depthRangeFromScene as N}from"./depthRangeUtils.js";import{createEmptyDepthTexture as U}from"./glUtil3D.js";import{Highlight as F}from"./Highlight.js";import{RenderOccludedFlag as j}from"./Material.js";import{OffscreenRendering as G}from"./OffscreenRendering.js";import{RenderContext as q}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as V}from"./rendererUtils.js";import{RenderFeature as B,setupFeatureDefaults as W}from"./RenderFeature.js";import{RenderPluginManager as k}from"./RenderPluginManager.js";import{RenderSlot as Q}from"./RenderSlot.js";import{ShadowAccumulator as Y}from"./ShadowAccumulator.js";import{ShadowHighlight as X}from"./ShadowHighlight.js";import{ShadowMap as z,SnapshotSlot as J}from"./ShadowMap.js";import K from"./SliceHelper.js";import{SmaaRenderPass as Z}from"./SmaaRenderPass.js";import{SSAOHelper as $}from"./SSAOHelper.js";import{TransparencyPassType as ee}from"./TransparencyPassType.js";import{EdgeView as re}from"./edgeRendering/EdgeView.js";import{Transparency as te}from"./edgeRendering/interfaces.js";import{MergedRenderer as se}from"../materials/renderers/MergedRenderer.js";import{AlphaMode as ie}from"../shaders/CompositingTechniqueConfiguration.js";import{RendererPerformanceInfo as ae,PerformanceCategory as ne}from"../statistics/RendererPerformanceInfo.js";import{RenderState as he}from"../../../support/RenderState.js";import{ClearBufferBit as oe,PixelFormat as de,PixelType as le}from"../../../webgl/enums.js";let _e=class extends r{get _bindParameters(){return this._renderContext.bindParameters}isFeatureEnabled(e,r=this._state){return i(this._renderStateFeatures.get(r,e),!1)}setFeatureEnabled(e,r,t){this._renderStateFeatures.set(r,e,t),this.notifyChange("_renderStateFeatures"),this._requestRender()}get _antialiasing(){return this._antialiasingEnabled||this.isFeatureEnabled(B.Antialiasing)}get _highQualityTransparency(){return this._highQualityTransparencyEnabled||this.isFeatureEnabled(B.HighQualityTransparency)}get hasWaterReflection(){return this.hasWater&&(this._waterReflectionEnabled||this.isFeatureEnabled(B.WaterReflection))}get hasWater(){return this._hasWater||this._hasOverlayWater}constructor(e,r,t,i,a,n,h,o){super({}),this._stage=e,this._materialRepository=r,this._shaderTechniqueRepository=i,this._rctx=a,this._compositingHelper=n,this._magnifierHelper=h,this._requestRender=o,this._materialRenderers=new _,this._needsTransparentPass=!1,this._hasHUDElements=!1,this._hasHighlights=!1,this._hasWater=!1,this._hasOverlayWater=!1,this._renderOverlay=e=>{},this._isRendering=!1,this._fallbackDepthStencilTexture=null,this._sliceHelper=new K,this._state=he.IDLE,this._renderStateFeatures=W(),this._antialiasingEnabled=!0,this._highQualityTransparencyEnabled=!0,this._terrainRenderingEnabled=!0,this._terrainTransparency=y.Opaque,this._waterReflectionEnabled=!1,this._ssaoEnabled=!1,this._hasAnimations=!1,this._animationTimestep=new D,this._handles=new s,this._renderHiddenTransparentEdges=()=>{},this._oitUsed=!1,this._smaaPass=new Z(this._rctx,i),o(),this._offscreen=new G(this._rctx,this._compositingHelper),this.performanceInfo=new ae(this._rctx),this._shadowMap=new z(this._rctx,e.viewingMode),this._ssaoHelper=new $(e.view,i,this._rctx,o),this._highlight=new F(i,this._rctx),this._shadowHighlight=new X(this._rctx,e.viewingMode),this._shadowAccumulator=new Y(this._rctx,i,e,(e=>{const r=this.shadowsEnabled;this._shadowMap.enabled=!0,this._prepare(e.camera,e.contentCamera),this._renderPlugins.prepareRender(),this._shadowMap.enabled=r}),((e,r,t)=>{e.shadowMap.start(e.camera,r,t),this._renderShadowCascades(O.Shadow,e.shadowMap),e.camera.setGLViewport(this._rctx),this._prepare(e.camera,e.contentCamera)}),o),this._renderContext=new q(this._rctx,this._offscreen,this._shadowMap,this._ssaoHelper,this._sliceHelper),this._renderPlugins=new k({renderContext:this._renderContext,techniqueRepository:i,textureRepository:t,materialRepository:this._materialRepository,requestRender:o,controller:e}),this.renderPassManager=new w(this._rctx,this._shaderTechniqueRepository),this._renderPlugins.add(this.renderPassManager.slots(),this.renderPassManager),this._handles.add([c((()=>this._stage.view.state.camera),(()=>o()),p),c((()=>S.EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES),(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(te.TRANSPARENT):()=>{},o()}),m),c((()=>this._ssaoEnabled||this.isFeatureEnabled(B.SSAO)),(e=>this._ssaoHelper.enabled=e),p)])}normalizeCtorArgs(){return{}}destroy(){this._handles.destroy(),this._smaaPass.dispose(),this._gpuTimerHandle=a(this._gpuTimerHandle),this._materialRenderers.forAll((e=>e.dispose())),this._materialRenderers.clear(),this._offscreen.dispose(),this._fallbackDepthStencilTexture=n(this._fallbackDepthStencilTexture),this._shadowMap.dispose(),this._ssaoHelper.dispose(),this._highlight.dispose(),this._shadowHighlight.dispose(),this._shadowAccumulator.dispose(),v.prune()}disposeOffscreenBuffers(){this._offscreen.dispose(),this._shadowMap.dispose(),this._smaaPass.disable(),this._ssaoHelper.disposeOffscreenBuffers()}get updating(){return this._antialiasing&&this._smaaPass.updating||h(this._edgeView)&&this._edgeView.updating||this._shadowAccumulator.running||!this.isCameraFinal}ensureEdgeView(){return o(this._edgeView)&&(this._edgeView=new re({rctx:this._rctx,renderSR:this._stage.view.renderSpatialReference,viewingMode:this._stage.viewingMode,techniqueRepository:this._shaderTechniqueRepository,setNeedsRender:()=>this._requestRender(),schedule:e=>this._stage.view.resourceController.immediate.schedule(e)}),this._handles.add(c((()=>d(this._edgeView,(e=>e.updating))),(()=>this._requestRender()),u)),this._requestRender()),this._edgeView}get edgeView(){return this._edgeView}get isCameraFinal(){return T(this._bindParameters.ssr.reprojectionMatrix,E)}set _reprojectionMatrix(e){t(this._bindParameters.ssr.reprojectionMatrix,e)&&this.notifyChange("isCameraFinal")}get shadowsEnabled(){return!!this._shadowMap?.enabled}setParameters(e){const{_shadowMap:r,_bindParameters:t}=this;if(void 0!==e.screenSpaceReflectionsEnabled&&t.ssr.enabled!==e.screenSpaceReflectionsEnabled&&(t.ssr.enabled=e.screenSpaceReflectionsEnabled,this._requestRender()),void 0!==e.shadowMap&&this._shadowMap.enabled!==e.shadowMap&&(this._shadowMap.enabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&r.maxCascades!==e.shadowMapMaxCascades&&(r.maxCascades=e.shadowMapMaxCascades,this._requestRender()),h(e.environment)){h(e.environment.weather)&&(this._bindParameters.weather=e.environment.weather,this._bindParameters.weatherVisible=!!e.weatherVisible),void 0!==e.environment.lighting.ambientOcclusionEnabled&&this._ssaoEnabled!==e.environment.lighting.ambientOcclusionEnabled&&(this._ssaoEnabled=e.environment.lighting.ambientOcclusionEnabled,this._requestRender()),void 0!==e.environment.lighting.waterReflectionEnabled&&this._waterReflectionEnabled!==e.environment.lighting.waterReflectionEnabled&&(this._waterReflectionEnabled=e.environment.lighting.waterReflectionEnabled,this._requestRender());const r="virtual"!==e.environment.lighting.type;t.enableFillLights!==r&&(t.enableFillLights=r,this._requestRender())}e.background&&this._offscreen.background!==e.background&&(this._offscreen.background=e.background,this._requestRender()),void 0!==e.antialiasingEnabled&&this._antialiasingEnabled!==e.antialiasingEnabled&&(this._antialiasingEnabled=e.antialiasingEnabled,this._requestRender()),void 0!==e.highQualityTransparency&&this._highQualityTransparencyEnabled!==e.highQualityTransparency&&(this._highQualityTransparencyEnabled=e.highQualityTransparency,this._requestRender()),void 0!==e.defaultHighlightOptions&&(this._highlight.setDefaultOptions(e.defaultHighlightOptions),this._shadowHighlight.setDefaultOptions(e.defaultHighlightOptions),this._requestRender()),void 0!==e.overlays&&this._bindParameters.overlays!==e.overlays&&(this._bindParameters.overlays=e.overlays,this._requestRender()),void 0!==e.hasOverlayWater&&this._hasOverlayWater!==e.hasOverlayWater&&(this._hasOverlayWater=e.hasOverlayWater,this._requestRender()),void 0!==e.renderOverlay&&this._renderOverlay!==e.renderOverlay&&(this._renderOverlay=e.renderOverlay,this._requestRender()),void 0!==e.slicePlane&&this._sliceHelper.plane!==e.slicePlane&&(this._sliceHelper.plane=l(e.slicePlane),this._requestRender()),void 0!==e.terrainRenderingEnabled&&this._terrainRenderingEnabled!==e.terrainRenderingEnabled&&(this._terrainRenderingEnabled=e.terrainRenderingEnabled,this._requestRender()),void 0!==e.terrainTransparency&&this._terrainTransparency!==e.terrainTransparency&&(this._terrainTransparency=e.terrainTransparency,this._requestRender()),void 0!==e.shadowCastOptions&&this._shadowAccumulator.setOptions(e.shadowCastOptions)}get hasSlicePlane(){return!!this._sliceHelper.plane}get renderPlugins(){return this._renderPlugins}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlend.result}get _oitEnabled(){return this._highQualityTransparency&&this._hasOITSupport}modify(e,r){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:t,removes:s,updates:i}=e;if(0===t.length&&0===s.length&&0===i.length)return;const a=V(e);let n=!1;a.forEach(((t,s)=>{if(r.done)return;let i=this._materialRenderers.find((e=>e.material===s));o(i)&&t.adds.length>0&&(i=new se(this._rctx,this._materialRepository,s),this._materialRenderers.push(i)),i&&(i.modify(t),i.isEmpty&&(n=!0)),t.removes.forEach((r=>e.removes.removeUnordered(r))),t.adds.forEach((r=>e.adds.removeUnordered(r))),t.updates.forEach((r=>e.updates.removeUnordered(r))),r.madeProgress()})),n&&this._materialRenderers.filterInPlace((e=>!e.isEmpty||(e.dispose(),!1))),this._hasHighlights=this._materialRenderers.some((e=>e.hasHighlights)),this._bindParameters.hasOccludees=this._materialRenderers.some((e=>e.hasOccludees)),this._hasWater=this._materialRenderers.some((e=>e.hasWater)),this._hasHUDElements=this._materialRenderers.some((e=>e.requiresSlot(Q.LINE_CALLOUTS_HUD_DEPTH,O.Color)||e.requiresSlot(Q.HUD_MATERIAL,O.Color)||e.requiresSlot(Q.LABEL_MATERIAL,O.Color))),this._requestRender()}updateAnimation(e){const r=this._hasAnimations;return this._hasAnimations=!1,this._materialRenderers.forAll((r=>this._hasAnimations=r.updateAnimation(e)||this._hasAnimations)),this._hasAnimations=this._renderPlugins.updateAnimation(e)||this._hasAnimations,this._hasAnimations!==r&&(this._gpuTimerHandle=r?a(this._gpuTimerHandle):this.performanceInfo.enableGPUPerformanceInfo()),this._hasAnimations}get animationTimestep(){return this._animationTimestep.value}get animationTimeDilation(){return this._animationTimestep.timeDilation}resetAnimation(){this._animationTimestep.clear()}render(e,r,t,s,i){this._isRendering=!0,this.performanceInfo.startFrame();const{camera:a,contentCamera:n,mode:d}=t;this._state=d,this._renderOverlay(i),this.performanceInfo.advance(ne.OVERLAY),this._renderContext.time=i,this._bindParameters.transparencyPassType=ee.NONE;const l=this._offscreen;l.setupRenderTarget(this.hasWaterReflection);const _=P(this._sliceHelper.plane);s===I.OFF&&(this._sliceHelper.plane=null),this._rctx.bindFramebuffer(e),a.setGLViewport(this._rctx),this._prepare(a,n),this._renderPlugins.prepareRender(),this.performanceInfo.advance(ne.PREPARE);const c=this._computeDepthRange(a);this._renderShadowMap(e,a,this._bindParameters.lighting.mainLight.direction,c),this.performanceInfo.advance(ne.SHADOW_MAP),l.initializeFrame(a),this._ensureBindParameters(a,n),this._renderLinearDepth(),this.performanceInfo.advance(ne.LINEAR_DEPTH),this._accumulateShadows(c,a,n),this.performanceInfo.advance(ne.ACCUMULATED_SHADOWS),this._renderNormal(),this.performanceInfo.advance(ne.NORMALS),this._ensureBindParametersSSR(i),this._renderSSAO(i),this.performanceInfo.advance(ne.SSAO),this._renderContext.output=O.Color,l.bindFramebuffer(),this._renderOpaqueGeometry(),this.performanceInfo.advance(ne.OPAQUE);const p=this._terrainRenderingEnabled&&(this._terrainTransparency===y.Semitransparent||this._terrainTransparency===y.TransparentWithDraped),m=this._highQualityTransparency&&p;this._renderTerrainLinearDepth(m),this._setMultipassEnabled(m),this._setTerrainCulling(m),this._renderEdges(te.OPAQUE),this.performanceInfo.advance(ne.OPAQUE_EDGES),this._offscreen.bindTarget(this._offscreen.currentColorTarget,this._offscreen.mainDepth),this._renderSlot(Q.VOXEL),this.performanceInfo.advance(ne.VOXEL),this._renderHiddenTransparentEdges();const u=this._needsTransparentPass||this._renderPlugins.needsTransparentPass;u&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(ne.TRANSPARENT),this._renderGeometryLinearDepth(m);const f=this._renderHUDVisibility(m);m||this._renderInternalSlot(Q.LINE_CALLOUTS),this.performanceInfo.advance(ne.HUD_VISIBILITY),this._renderObjectAndLayerIdColor(r),this.performanceInfo.advance(ne.OBJECT_AND_LAYER_ID_COLOR),this._renderEdges(te.TRANSPARENT,m),this.performanceInfo.advance(ne.TRANSPARENT_EDGES),this._renderTransparentTerrain(),p&&f&&(m?this._renderLineCallouts(C.Occluded):l.compositeTransparentTerrainOntoHUDVisibility(this._bindParameters),this._renderHUD(C.Occluded,l.framebuffer),this.performanceInfo.advance(ne.HUD_OCCLUDED)),this.performanceInfo.advance(ne.TRANSPARENT_TERRAIN),this._setTerrainCulling(!1),p&&(l.compositeTransparentTerrainOntoMain(this._bindParameters),m&&(this._renderEdges(te.OPAQUE),this.performanceInfo.advance(ne.OPAQUE_EDGES),u&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(ne.TRANSPARENT),this._renderEdges(te.TRANSPARENT),this.performanceInfo.advance(ne.TRANSPARENT_EDGES))),m&&this._renderLineCallouts(C.NotOccluded),this._setMultipassEnabled(!1),this._shadowAccumulator.render(this._bindParameters),l.renderToTargets((()=>{this._renderInternalSlot(Q.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL),this._renderSlot(Q.POSTPROCESSING_ENVIRONMENT_TRANSPARENT),this._renderSlot(Q.LASERLINES)}),l.currentColorTarget,l.mainDepth),this.performanceInfo.advance(ne.ENVIRONMENT),this._renderPlugins.needsLaserlineWithContrastControl&&l.renderTmpAndCompositeToMain((()=>this._renderSlot(Q.LASERLINES_CONTRAST_CONTROL)),this._bindParameters,ie.PremultipliedAlpha),this.performanceInfo.advance(ne.LASER_LINE),this._renderOccluded(),this.performanceInfo.advance(ne.OCCLUDED);const g=s===I.ON&&this._magnifierHelper.enabled,T=g&&o(e)?this._offscreen.getFramebuffer(this._offscreen.tmpColor,this._offscreen.tmpDepth):e;this._rctx.bindFramebuffer(T);const b=this._offscreen.colorTexture;!this._renderAntiAliasing(b)&&h(b)&&this._compositingHelper.composite(this._bindParameters,b,ie.None),this.performanceInfo.advance(ne.ANTIALIASING),this._renderHUD(C.NotOccluded,T),this.performanceInfo.advance(ne.HUD),this._renderHighlights(T,this._bindParameters),this.performanceInfo.advance(ne.HIGHLIGHTS),g&&this._magnifierHelper.render(this._rctx,this._bindParameters),T!==e&&(this._rctx.bindFramebuffer(e),this._compositingHelper.composite(this._bindParameters,this._offscreen.tmpColorTexture,ie.None)),this._disposeOITBuffers(),this._renderContext.lastFrameCamera.copyFrom(this._bindParameters.camera),this._sliceHelper.plane=_,this._isRendering=!1,this.onPostRender&&this.onPostRender(),this.performanceInfo.finishFrame()}_renderObjectAndLayerIdColor(e){h(e)&&has("enable-feature:objectAndLayerId-rendering")&&(this._rctx.bindFramebuffer(e),this._offscreen.renderToFBO((()=>this._renderGeometryAndTransparentTerrainPass(O.ObjectAndLayerIdColor)),[0,0,0,0],!0,!0),this._rctx.bindFramebuffer(e),this._offscreen.renderToFBO((()=>{this._bindParameters.renderTransparentlyOccludedHUD=C.NotOccluded,this._renderInternalSlot(Q.HUD_MATERIAL)}),void 0,!0,!0))}finish(e){this._hasAnimations||this._animationTimestep.clear();const r=this.performanceInfo.gpuSamplingEnabled,t=e===x.BACKGROUND;if(t||r){const e=t?this.performanceInfo.elapsedTime:0,s=r?this.performanceInfo.totalGPUTimeSampler.last:this._rctx.gl.getError(),i=Math.max(e,s);this._animationTimestep.frame(i,t)}}readDepthPixels(e,r,t){const s=this._offscreen.bindTarget(this._offscreen.linearDepth,this._offscreen.tmpDepth);if(!this._needsLinearDepth){this._ensureBindParameters(e,e),this._bindParameters.camera.setGLViewport(this._rctx),this._rctx.setClearColor(0,0,0,0);const r=oe.COLOR_BUFFER_BIT|oe.DEPTH_BUFFER_BIT|oe.STENCIL_BUFFER_BIT;this._rctx.clearSafe(r),this._renderGeometryAndTransparentTerrainPass(O.Depth)}s.readPixels(r[0],r[1],r[2],r[3],de.RGBA,le.UNSIGNED_BYTE,t)}readHUDVisibility(e,r,t,s,i){this._offscreen.bindTarget(this._offscreen.hudVisibility).readPixels(e,r,t,s,de.RGBA,le.UNSIGNED_BYTE,i)}readAccumulatedShadow(e){return this._shadowAccumulator.readAccumulatedShadow(e[0],e[1])}_setMultipassEnabled(e){this._bindParameters.multipassTerrain.enabled=this._bindParameters.multipassGeometry.enabled=e}_setTerrainCulling(e){this._bindParameters.multipassTerrain.cullAboveGround=e}_renderSlot(e){this._bindParameters.slot=e,this._renderPlugins.render()}_renderEdges(e,r=!1){const t=this._edgeView;h(t)&&t.shouldRender()&&this._offscreen.renderTmpAndCompositeToMain((()=>t.render(this._bindParameters,e)),this._bindParameters,ie.Alpha,r)}_renderShadowMap(e,r,t,s){const i=this._shadowMap;i.enabled&&this.isFeatureEnabled(B.ShadowMapUpdate)&&(i.start(r,t,s),this._shadowHighlight.updateParameters(r,t),this._needsShadowHighlight?(this._renderShadowCascades(O.ShadowHighlight,this._shadowMap,(e=>i.takeCascadeSnapshotTo(e,J.Highlight))),i.clear(),this._renderShadowCascades(O.ShadowExcludeHighlight,this._shadowMap,(e=>{i.takeCascadeSnapshotTo(e,J.Default),this._renderGeometryAndTransparentTerrainPass(O.ShadowHighlight)}))):this._renderShadowCascades(O.Shadow),i.finish(e),r.setGLViewport(this._rctx))}_renderShadowCascades(e,r=this._shadowMap,t=(e=>{})){for(const s of r.cascades)s.camera.setGLViewport(this._rctx),this._prepare(s.camera,s.camera),this._renderGeometryAndTransparentTerrainPass(e),t(s)}get _needsLinearDepth(){return this._ssaoHelper.active||this._renderPlugins.needsLinearDepth||this.hasWaterReflection||this._needsShadowHighlight||this._needsShadowCast}_renderLinearDepth(){this._needsLinearDepth?this._offscreen.renderToTargets((()=>this._renderGeometryAndTransparentTerrainPass(O.Depth)),this._offscreen.linearDepth,this._offscreen.tmpDepth,[0,0,0,0],!0,!0):this._offscreen.disposeTarget(this._offscreen.linearDepth),this._bindParameters.linearDepthTexture=this._offscreen.linearDepthTexture}_renderTerrainLinearDepth(e){if(e){const e=this._renderContext.output;this._renderContext.output=O.Depth,this._offscreen.renderToTargets((()=>this._renderTransparentTerrain()),this._offscreen.terrainLinearDepth,this._offscreen.tmpDepth,[-1e10,-1e10,-1e10,1],!0,!0),this._renderContext.output=e}else this._offscreen.disposeTarget(this._offscreen.terrainLinearDepth);this._bindParameters.multipassTerrain.linearDepthTexture=this._offscreen.terrainLinearDepthTexture}_renderGeometryLinearDepth(e){if(e){const e=this._renderContext.output;this._offscreen.renderToTargets((()=>this._renderGeometryPass(O.Depth)),this._offscreen.geometryLinearDepth,this._offscreen.tmpDepth,[1,1,1,1],!0,!0),this._renderContext.output=e}else this._offscreen.disposeTarget(this._offscreen.geometryLinearDepth);this._bindParameters.multipassGeometry.linearDepthTexture=this._offscreen.geometryLinearDepthTexture}get _needsNormal(){return this._ssaoHelper.active}_renderNormal(){this._needsNormal?this._offscreen.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(O.Normal)}),this._offscreen.normal,this._offscreen.tmpDepth,[0,0,0,0],!0,!0):this._offscreen.disposeTarget(this._offscreen.normal)}get _needsDepthRange(){return this._shadowMap.enabled||this._needsShadowCast}_computeDepthRange(e){if(!this._needsDepthRange)return M;const r=N(e,this._materialRenderers,this._stage.layers);return L(r,this.renderPlugins.queryDepthRange(e)),r.near=Math.max(e.near,r.near),r.far=Math.min(e.far,r.far),r}_renderGeometryAndTransparentTerrainPass(e){this._renderContext.output=e,this._renderGeometryPass(e),this._renderTransparentTerrain()}_renderGeometryPass(e){this._renderContext.output=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderSSAO(e){this._ssaoHelper.render(this._bindParameters,e,this._offscreen.linearDepthTexture,this._offscreen.normalTexture)}_renderOpaqueGeometry(){this._renderSlot(Q.INTEGRATED_MESH),this._renderSlot(Q.OPAQUE_TERRAIN),this._renderInternalSlot(Q.OPAQUE_MATERIAL),this._renderSlot(Q.OPAQUE_MATERIAL),this._renderSlot(Q.POSTPROCESSING_ENVIRONMENT_OPAQUE)}_renderTransparentGeometry(){this._renderInternalSlot(Q.TRANSPARENT_MATERIAL),this._renderSlot(Q.TRANSPARENT_MATERIAL)}_renderTransparentTerrain(){this._renderSlot(Q.TRANSPARENT_TERRAIN)}_renderHUDVisibility(e){let r=!1;return this._renderContext.offscreenRenderingHelper&&this._renderContext.offscreenRenderingHelper.renderHUDVisibility((()=>{this._bindParameters.hudVisibilityTexture=this._renderContext.offscreenRenderingHelper.hudVisibilityTexture,r=this._renderInternalSlot(Q.OCCLUSION_PIXELS)}),e),r}_renderLineCallouts(e){this._bindParameters.renderTransparentlyOccludedHUD=e,e===C.Occluded?this._offscreen.renderToTargets((()=>this._renderInternalSlot(Q.LINE_CALLOUTS)),this._offscreen.currentColorTarget,this._offscreen.tmpDepth,void 0,!0,!0):this._renderInternalSlot(Q.LINE_CALLOUTS)}_renderHUD(e,r){this._hasHUDElements&&(this._oitEnabled?(this._renderOrderIndependentTransparency((()=>this._renderHUDElements(e)),!0),this._rctx.bindFramebuffer(r),this._compositingHelper.composite(this._bindParameters,this._offscreen.hudColorTexture,ie.PremultipliedAlpha)):e===C.Occluded?this._offscreen.renderToTargets((()=>this._renderHUDElements(C.Occluded)),this._offscreen.currentColorTarget,this._offscreen.tmpDepth,void 0,!0,!0):this._renderHUDElements(e))}_renderHUDElements(e){this._bindParameters.renderTransparentlyOccludedHUD=e,this._renderInternalSlot(Q.LINE_CALLOUTS_HUD_DEPTH),this._renderInternalSlot(Q.HUD_MATERIAL),this._renderInternalSlot(Q.LABEL_MATERIAL)}get _needsHighlight(){return this._hasHighlights||this._renderPlugins.needsHighlight}get _needsShadowHighlight(){return this._shadowMap.enabled&&this._shadowHighlight.isVisible&&this._needsHighlight}_renderHighlights(e,r){if(!this._needsHighlight)return void this._offscreen.disposeTarget(this._offscreen.highlight);const t=this._highlight,s=this._offscreen.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(O.Highlight),this._rctx.clearSafe(oe.DEPTH_BUFFER_BIT),this._renderHUDElements(C.Both)}),this._offscreen.highlight,this._offscreen.tmpDepth,[0,0,0,0],!0,!0);this._bindParameters.highlightColorTexture=s.colorTexture,this._needsShadowHighlight&&this._shadowHighlight.render(r,e),t.render(this._bindParameters,s,e)}get _needsShadowCast(){return this._shadowAccumulator.isAccumulating}_accumulateShadows(e,r,t){this._needsShadowCast&&h(this._offscreen.linearDepthTexture)&&this._shadowAccumulator.renderAccumulation(this._offscreen.linearDepthTexture,e,r,t)}_renderOrderIndependentTransparency(e,r){const t=t=>{this._bindParameters.transparencyPassType=t,this._offscreen.renderOITPass((()=>e()),t,r)},s=this._renderContext.output;this._renderContext.output=O.Alpha,t(ee.Alpha),this._renderContext.output=O.Color,t(ee.Color),t(ee.FrontFace),this._offscreen.compositeTransparentOntoOpaque(this._bindParameters,r),this._bindParameters.transparencyPassType=ee.NONE,this._renderContext.output=s,this._oitUsed=!0}_disposeOITBuffers(){this._oitUsed||(this._offscreen.disposeTarget(this._offscreen.alphaFloatTarget),this._offscreen.disposeTarget(this._offscreen.colorFloatTarget),this._offscreen.disposeTarget(this._offscreen.frontFaceTarget)),this._oitUsed=!1}_renderOccluded(){let e=0;pe.clear(),this._materialRenderers.forAll((r=>{r.material&&r.material.isVisible()&&r.material.renderOccluded===j.OccludeAndTransparentStencil&&(e|=r.material.renderOccluded,pe.push(r))}));const r=this._offscreen,t=(t,s,i,a,n)=>{0!=(e&s)&&(r.renderToTargets(i,r.tmpColor,r.mainDepth,[0,0,0,0],a,n),r.compositeOccludedOntoMain(this._bindParameters,t))};0!==pe.length&&(this._renderInternalSlot(Q.OCCLUDER_MATERIAL,pe),t(.5,j.OccludeAndTransparentStencil,(()=>this._renderInternalSlot(Q.TRANSPARENT_OCCLUDER_MATERIAL,pe)),!1,!1)),pe.clear(),this._materialRenderers.forAll((r=>{r.material&&r.material.isVisible()&&(r.material.renderOccluded===j.OccludeAndTransparent||r.material.renderOccluded===j.Transparent||r.material.renderOccluded===j.Opaque)&&(e|=r.material.renderOccluded,pe.push(r))}));const s=this._renderPlugins.renderOccludedFlags;if(e|=s,!e)return;const i=e=>{this._renderContext.renderOccludedMask=e,s>j.Occlude&&this._renderSlot(Q.OCCLUDED_TERRAIN),this._renderInternalSlot(Q.OPAQUE_MATERIAL,pe),this._renderInternalSlot(Q.TRANSPARENT_MATERIAL,pe),this._renderInternalSlot(Q.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL,pe),this._renderContext.resetRenderOccludedMask()};this._renderContext.output=O.Color,t(.5,j.OccludeAndTransparent,(()=>i(j.OccludeAndTransparent)),!0,H.OutlineVisualElementMask),t(.5,j.Transparent,(()=>i(j.Transparent)),!0,H.OutlineVisualElementMask),t(1,j.Opaque,(()=>i(j.Opaque)),!0,H.OutlineVisualElementMask),pe.clear()}_renderAntiAliasing(e){if(this._antialiasing){if(this._smaaPass.enable((()=>this._requestRender()))&&h(e))return this._smaaPass.render(e),!0}else this._smaaPass.disable();return!1}_prepare(e,r){this._needsTransparentPass=this._materialRenderers.some((e=>e.requiresSlot(Q.TRANSPARENT_MATERIAL,O.Color))),this._bindParameters.camera=e,this._bindParameters.contentCamera=r}_ensureBindParameters(e,r){this._bindParameters.camera=e,this._bindParameters.contentCamera=r;const t=this._renderContext.offscreenRenderingHelper;this._bindParameters.hudVisibilityTexture=t.hudVisibilityTexture,this._bindParameters.mainColorTexture=t.mainColorTexture,this._bindParameters.highlightDepthTexture=t.depthTexture??this._getFallbackDepthTexture()}_ensureBindParametersSSR(e){if(this._bindParameters.ssr.enabled=this.hasWaterReflection,this._bindParameters.ssr.enabled){o(this._waterReflectionEnableTime)&&(this._waterReflectionEnableTime=e),this._renderContext.lastFrameCamera.equals(this._bindParameters.camera)?this._reprojectionMatrix=E:(b(ue,this._bindParameters.camera.viewMatrix),b(me,this._bindParameters.camera.projectionMatrix),R(fe,ue,me),R(fe,this._renderContext.lastFrameCamera.viewMatrix,fe),R(fe,this._renderContext.lastFrameCamera.projectionMatrix,fe),this._reprojectionMatrix=fe),this._bindParameters.ssr.lastFrameColorTexture=this._offscreen.lastFrameColorTexture;const r=this._stage.view.qualitySettings.fadeDuration;this._bindParameters.ssr.fadeFactor=r>0?Math.min(r,e-this._waterReflectionEnableTime)/r:1,this._bindParameters.ssr.fadeFactor<1&&this._requestRender()}else this._bindParameters.ssr.lastFrameColorTexture=null,this._waterReflectionEnableTime=null}_renderInternalSlot(e,r=this._materialRenderers){let t=!1;return this._bindParameters.slot=e,r.forAll((e=>{e.material.shouldRender(this._renderContext)&&e.render(this._renderContext.output,this._bindParameters)&&(t=!0)})),t}_getFallbackDepthTexture(){return this._fallbackDepthStencilTexture||(this._fallbackDepthStencilTexture=U(this._rctx)),this._fallbackDepthStencilTexture}get gpuMemoryUsage(){return{offscreen:this._offscreen?.gpuMemoryUsage??0,highlights:(this._highlight?.gpuMemoryUsage??0)+(this._shadowHighlight?.gpuMemoryUsage??0),shadows:this._shadowMap?.gpuMemoryUsage??0,ssao:this._ssaoHelper?.gpuMemoryUsage??0}}get test(){const e=this;return{offscreen:this._offscreen,shadowMap:this._shadowMap,ssao:this._ssaoHelper,highlight:this._highlight,lighting:this._bindParameters.lighting,materialRenderers:this._materialRenderers,shadowAccumulator:this._shadowAccumulator,weatherIsFading:this._bindParameters.cloudsFade.isFading,resetRenderStateFeatures:()=>{e._renderStateFeatures=W()},getFramebufferTexture:r=>{switch(r){case ce.Color:return e._offscreen.colorTexture;case ce.LinearDepth:return e._offscreen.linearDepthTexture;case ce.Normals:return e._offscreen.normalTexture;case ce.ShadowMap:return e._shadowMap.depthTexture;case ce.HudVisibility:return e._offscreen.hudVisibilityTexture;case ce.Highlight:return e._offscreen.highlightTexture}}}}};var ce;e([f()],_e.prototype,"_shadowAccumulator",void 0),e([f()],_e.prototype,"_state",void 0),e([f()],_e.prototype,"_renderStateFeatures",void 0),e([f()],_e.prototype,"_antialiasingEnabled",void 0),e([f({readOnly:!0})],_e.prototype,"_antialiasing",null),e([f()],_e.prototype,"_ssaoEnabled",void 0),e([f()],_e.prototype,"_smaaPass",void 0),e([f({autoDestroy:!0})],_e.prototype,"_edgeView",void 0),e([f()],_e.prototype,"updating",null),e([f()],_e.prototype,"isCameraFinal",null),_e=e([g("esri.views.3d.webgl-engine.lib.Renderer")],_e),function(e){e[e.Color=0]="Color",e[e.LinearDepth=1]="LinearDepth",e[e.Normals=2]="Normals",e[e.ShadowMap=3]="ShadowMap",e[e.HudVisibility=4]="HudVisibility",e[e.Highlight=5]="Highlight"}(ce||(ce={}));const pe=new _,me=A(),ue=A(),fe=A();export{ce as FramebufferId,_e as Renderer};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.26/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../chunks/tslib.es6.js";import{isSome as r}from"../core/maybe.js";import{eachAlwaysValues as s}from"../core/promiseUtils.js";import"../core/Logger.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/Error.js";import"../core/has.js";import{subclass as i}from"../core/accessorSupport/decorators/subclass.js";const a=a=>{let p=class extends a{async fetchPopupFeatures(e,r){await this.when();const{location:i,queryArea:a,layerViewsAndGraphics:p,clientOnlyGraphics:t}=await this._prepareFetchPopupFeatures(e,r),o=Promise.resolve(t),c=this._queryLayerPopupFeatures(a,p,r),n=c.map((e=>e.promise));return{location:i,clientOnlyGraphics:t,allGraphicsPromise:s([o,...n]).then((e=>Array.from(new Set(e.flat())))),promisesPerLayerView:c}}_queryLayerPopupFeatures(e,s,i){return s.map((({layerView:s,graphics:a})=>{const p={clientGraphics:a,event:r(i)?i.event:void 0,signal:r(i)?i.signal:void 0,defaultPopupTemplateEnabled:!!r(i)&&!!i.defaultPopupTemplateEnabled},t=s.fetchPopupFeatures(e,p);return{layerView:s,promise:t}}))}_isValidPopupGraphic(e,s){return e&&!!e.getEffectivePopupTemplate(r(s)&&s.defaultPopupTemplateEnabled)}async _prepareFetchPopupFeatures(e,r){const{clientGraphics:s,queryArea:i,location:a}=await this._popupHitTestGraphics(e,r),p=this._getFetchPopupLayerViews(),{layerViewsAndGraphics:t,clientOnlyGraphics:o}=this._graphicsPerFetchPopupLayerView(s,p);return{clientOnlyGraphics:o,layerViewsAndGraphics:t,queryArea:i,location:a}}async _popupHitTestGraphics(e,r){const{results:s,mapPoint:i}=await this.popupHitTest(e),a=s.filter((e=>"graphic"===e.type&&this._isValidPopupGraphic(e.graphic,r))),p=a.length?a[0].mapPoint:null;return{clientGraphics:a.map((e=>e.graphic)),queryArea:i,location:i||p}}_getFetchPopupLayerViews(){const e=[];return this.allLayerViews.forEach((r=>{this._isValidPopupLayerView(r)&&e.push(r)})),r(this.graphicsView)&&this._isValidPopupLayerView(this.graphicsView)&&e.push(this.graphicsView),e.reverse()}_isValidPopupLayerView(e){return r(e)&&(!("layer"in e)||!e.suspended)&&"fetchPopupFeatures"in e}_graphicsPerFetchPopupLayerView(e,r){const s=[],i=new Map,a=r.map((e=>{const r=[];return"layer"in e?i.set(e.layer,r):i.set(e.graphics,r),{layerView:e,graphics:r}}));for(const p of e){const e=i.get(p.layer)||i.get(p.sourceLayer)||null;e?e.push(p):s.push(p)}return{layerViewsAndGraphics:a,clientOnlyGraphics:s}}};return p=e([i("esri.views.PopupView")],p),p};export{a as PopupView};
5
+ import{_ as e}from"../chunks/tslib.es6.js";import{isSome as r}from"../core/maybe.js";import{eachAlwaysValues as s}from"../core/promiseUtils.js";import"../core/Logger.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/Error.js";import"../core/has.js";import{subclass as i}from"../core/accessorSupport/decorators/subclass.js";const a=a=>{let p=class extends a{async fetchPopupFeatures(e,r){await this.when();const{location:i,queryArea:a,layerViewsAndGraphics:p,clientOnlyGraphics:t}=await this._prepareFetchPopupFeatures(e,r),o=Promise.resolve(t),c=this._queryLayerPopupFeatures(a,p,r),n=c.map((e=>e.promise));return{location:i,clientOnlyGraphics:t,allGraphicsPromise:s([o,...n]).then((e=>Array.from(new Set(e.flat())))),promisesPerLayerView:c}}_queryLayerPopupFeatures(e,s,i){return s.map((({layerView:s,graphics:a})=>{const p={clientGraphics:a,event:r(i)?i.event:void 0,signal:r(i)?i.signal:void 0,defaultPopupTemplateEnabled:!!r(i)&&!!i.defaultPopupTemplateEnabled},t=s.fetchPopupFeatures(e,p);return{layerView:s,promise:t}}))}_isValidPopupGraphic(e,s){return e&&!!e.getEffectivePopupTemplate(r(s)&&s.defaultPopupTemplateEnabled)}async _prepareFetchPopupFeatures(e,r){const{clientGraphics:s,queryArea:i,location:a}=await this._popupHitTestGraphics(e,r),p=this._getFetchPopupLayerViews(),{layerViewsAndGraphics:t,clientOnlyGraphics:o}=this._graphicsPerFetchPopupLayerView(s,p);return{clientOnlyGraphics:o,layerViewsAndGraphics:t,queryArea:i,location:a}}async _popupHitTestGraphics(e,r){const s=await this.popupHitTest(e),i=s.results,a=s.mapPoint,p=i.filter((e=>"graphic"===e.type&&this._isValidPopupGraphic(e.graphic,r))),t=p.length?p[0].mapPoint:null;return{clientGraphics:p.map((e=>e.graphic)),queryArea:a,location:a||t}}_getFetchPopupLayerViews(){const e=[];return this.allLayerViews.forEach((r=>{this._isValidPopupLayerView(r)&&e.push(r)})),r(this.graphicsView)&&this._isValidPopupLayerView(this.graphicsView)&&e.push(this.graphicsView),e.reverse()}_isValidPopupLayerView(e){return r(e)&&(!("layer"in e)||!e.suspended)&&"fetchPopupFeatures"in e}_graphicsPerFetchPopupLayerView(e,r){const s=[],i=new Map,a=r.map((e=>{const r=[];return"layer"in e?i.set(e.layer,r):i.set(e.graphics,r),{layerView:e,graphics:r}}));for(const p of e){const e=i.get(p.layer)||i.get(p.sourceLayer)||null;e?e.push(p):s.push(p)}return{layerViewsAndGraphics:a,clientOnlyGraphics:s}}};return p=e([i("esri.views.PopupView")],p),p};export{a as PopupView};