@arcgis/core 4.33.10 → 4.33.12

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 (93) hide show
  1. package/applications/KnowledgeStudio/reshape.d.ts +5 -0
  2. package/applications/KnowledgeStudio/reshape.js +5 -0
  3. package/assets/esri/core/workers/RemoteClient.js +1 -1
  4. package/assets/esri/core/workers/chunks/{1415d4e2f5f3193be004.js → 012dee84d97b71461397.js} +1 -1
  5. package/assets/esri/core/workers/chunks/{342f61e784c9364a493b.js → 1ebff223f0f241686669.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{fdfb5d601d318d6a49f9.js → 2f2cb0348f36a5157293.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{cb16ba9512ae0a09c55d.js → 4ab87eea6345818de60f.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{e9aa1d9ded8a52a40c57.js → 5d74b754ee0140afbd22.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{d33a5d79f2163ad62b1d.js → 64aebb3780ac4c8bfdc7.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{c6cd8784a3e222eb2d4a.js → 8edd8ebca441d670380f.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{cf25f487fe4eb1579aee.js → 9128902b127d0ec70fe0.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{17c623db3d9a06a9b711.js → a5fab8d7d8403b4de682.js} +1 -1
  13. package/assets/esri/core/workers/chunks/{bac5e1d50b69f0d94694.js → ad2a29aca4e5bcd545cc.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{9049c81445cc044286f1.js → bbb92d0ba6a34c7a7d1b.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{7b9d14cc4a466ef18d71.js → bfd51df0a44a05596061.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{3ca6f893fd58f5b17af5.js → c410b2b9d0645e9cea89.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{8008f5479f4d16964088.js → dded6853cebf2165cb37.js} +1 -1
  18. package/assets/esri/core/workers/chunks/{db192728fa0ee08a776a.js → e7ca7ced4dfb04c81e84.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{0155e6806621f3588ffa.js → fe71a2ea7965e75ee881.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{71e1a8bd432947c66357.js → ffeda53fee883f8025ed.js} +1 -1
  21. package/assets/esri/themes/base/widgets/_VideoPlayer.scss +16 -2
  22. package/assets/esri/themes/dark/main.css +1 -1
  23. package/assets/esri/themes/light/main.css +1 -1
  24. package/assets/esri/themes/light/view.css +1 -1
  25. package/chunks/GeodeticDistanceCalculator-Ce-woMPw.js +1 -1
  26. package/chunks/MultiPathImpl.js +1 -1
  27. package/chunks/OperatorGeodesicBuffer.js +1 -1
  28. package/chunks/OperatorGeodeticArea.js +1 -1
  29. package/chunks/OperatorGeodeticDensifyByLength.js +1 -1
  30. package/chunks/OperatorGeodeticLength.js +1 -1
  31. package/chunks/OperatorProximityGeodesic.js +1 -1
  32. package/chunks/OperatorShapePreservingLength.js +1 -1
  33. package/chunks/OperatorShapePreservingProject.js +1 -1
  34. package/chunks/Point2D.js +1 -1
  35. package/chunks/ProjectionTransformation.js +1 -1
  36. package/chunks/sphere.js +1 -1
  37. package/chunks/vec42.js +1 -1
  38. package/core/libs/gl-matrix-2/math/quat.js +1 -1
  39. package/core/libs/gl-matrix-2/math/vec4.js +1 -1
  40. package/core/quantityFormatUtils.js +1 -1
  41. package/core/unitFormatUtils.js +1 -1
  42. package/geometry/coordinateFormatter.js +1 -1
  43. package/geometry/operators/gx/operatorAlphaShape.js +1 -1
  44. package/geometry/operators/gx/operatorPolygonSlicer.js +1 -1
  45. package/geometry/support/sphere.js +1 -1
  46. package/interfaces.d.ts +128 -0
  47. package/kernel.js +1 -1
  48. package/layers/knowledgeGraph/nodeMovementUtils.js +5 -0
  49. package/package.json +1 -1
  50. package/renderers/support/RasterSymbolizer.js +1 -1
  51. package/support/revision.js +1 -1
  52. package/symbols/support/previewSymbol3D.js +1 -1
  53. package/views/2d/LabelManager.js +1 -1
  54. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  55. package/views/2d/layers/features/FeatureContainer.js +1 -1
  56. package/views/2d/layers/features/RenderState.js +1 -1
  57. package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
  58. package/views/2d/layers/imagery/ImageryTileView2D.js +1 -1
  59. package/views/3d/camera/constraintUtils/distance.js +1 -1
  60. package/views/3d/camera/constraintUtils/tilt.js +1 -1
  61. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  62. package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
  63. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  64. package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
  65. package/views/3d/state/utils/navigationUtils.js +1 -1
  66. package/views/3d/terrain/OverlayManager.js +1 -1
  67. package/views/3d/terrain/TerrainSurface.js +1 -1
  68. package/views/3d/webgl-engine/lib/Octree.js +1 -1
  69. package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
  70. package/views/LinkChartView.js +1 -1
  71. package/views/draw/DrawOperation.js +1 -1
  72. package/views/draw/support/GraphicMover.js +1 -1
  73. package/views/draw/support/HighlightHelper.js +1 -1
  74. package/views/draw/support/Reshape.js +1 -1
  75. package/views/interactive/Tooltip.js +1 -1
  76. package/views/interactive/sketch/SketchLabelOptions.js +1 -1
  77. package/views/interactive/sketch/SketchOptions.js +1 -1
  78. package/views/interactive/sketch/SketchTooltipOptions.js +1 -1
  79. package/views/interactive/sketch/SketchTooltipVisibleElements.js +1 -1
  80. package/views/interactive/sketch/SketchValueOptions.js +1 -1
  81. package/views/interactive/sketch/Units.js +1 -1
  82. package/views/interactive/sketch/constraints.js +1 -1
  83. package/views/interactive/snapping/featureSources/FeatureCollectionSnappingSource.js +1 -1
  84. package/views/interactive/snapping/featureSources/FeatureServiceSnappingSource.js +1 -1
  85. package/views/interactive/snapping/featureSources/GraphicsSnappingSource.js +1 -1
  86. package/views/interactive/tooltip/fields/fields.js +1 -1
  87. package/views/interactive/tooltip/fields/parsingAndFormattingUtils.js +1 -1
  88. package/views/interactive/tooltip/tooltipCommonUtils.js +1 -1
  89. package/views/support/LayerLayerViewInfo.js +1 -1
  90. package/views/support/angularMeasurementUtils.js +1 -1
  91. package/widgets/VideoPlayer/components/PlayerActionsGroup.js +1 -1
  92. package/widgets/VideoPlayer/css.js +1 -1
  93. package/widgets/VideoPlayer.js +1 -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.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as i}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{lerp as e}from"../../../../core/mathUtils.js";import{destroyMaybe as s}from"../../../../core/maybe.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as c}from"../../../../core/accessorSupport/decorators/subclass.js";import{transpose as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{t as l,g as h,i as u,c as d}from"../../../../chunks/vec32.js";import{ZEROS as p,create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as _,t as m,d as g}from"../../../../chunks/vec42.js";import{create as y}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as v}from"../../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b}from"../../../../geometry/ellipsoidUtils.js";import{create as O,empty as w,copy as I,offset as D,width as C,height as j,expand as G}from"../../../../geometry/support/aaBoundingRect.js";import{e as k,d as S,a as A}from"../../../../chunks/boundedPlane.js";import{create as Q}from"../../../../geometry/support/ray.js";import{a as N,c as P,h as T,i as x}from"../../../../chunks/sphere.js";import{DeconflictAABR as E}from"./DeconflictAABR.js";import{prepare as V,drawPoly as L}from"./deconflictorDebug.js";import{VisibilityGroup as U,VisibilityFlag as F}from"./enums.js";import R from"../../webgl/RenderCamera.js";import{GPUPointOcclusionQuery as H}from"../../webgl-engine/lib/GPUPointOcclusionQuery.js";import{applyPrecomputedScaleFactor as B}from"../../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as M}from"../../webgl-engine/lib/VertexAttribute.js";import{HUDMaterial as W}from"../../webgl-engine/materials/HUDMaterial.js";import{ScaleInfo as z}from"../../webgl-engine/materials/ScaleInfo.js";import{Yield as Y}from"../../../support/Yield.js";const q=f(),J=f(),K=y(),X=y(),Z=f(),$=n(),ii=P(),ti=Q(),ei=f(),si=O();class ri{constructor(i){this.id=i,this.aabr=O(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.culled=!1,this.visible=!1,this.priority=0}}function ci(i,t){const e=0!==i.distanceToOccluder&&i.distance>i.distanceToOccluder,s=0!==t.distanceToOccluder&&t.distance>t.distanceToOccluder;return e!==s?+e-+s:i.priority!==t.priority?t.priority-i.priority:i.distance!==t.distance?i.distance-t.distance:i.visible!==t.visible?+t.visible-+i.visible:i.id-t.id}class oi{constructor(i,t){this.graphics3DGraphic=i,this.slicePlaneEnabled=t,this._info=null,this._labelInfo=null}ensureInfo(i){let t=this.getInfo(i);return t||(t=new ri(this.graphics3DGraphic.graphic.uid),this._setInfo(i,t)),t}getInfo(i){return i===U.LABEL?this._labelInfo:this._info}removeInfo(i){this._setInfo(i,null)}_setInfo(i,t){i===U.LABEL?this._labelInfo=t:this._info=t}}var ni;!function(i){i[i.Idle=0]="Idle",i[i.CheckOcclusion=1]="CheckOcclusion",i[i.WaitOcclusion=2]="WaitOcclusion",i[i.Collect=3]="Collect",i[i.Deconflict=4]="Deconflict",i[i.NumStates=5]="NumStates"}(ni||(ni={}));class ai{constructor(){this.camera=new R,this.slicePlane=S(),this.slicePlaneEnabled=!1}copyFrom(i){this.camera.copyFrom(i.camera),A(i.slicePlane,this.slicePlane),this.slicePlaneEnabled=i.slicePlaneEnabled}}let li=class extends t{get dirty(){return this._dirty}get state(){return this._state}constructor(i){super(i),this._dirty=!1,this._viewState=new ai,this._state=ni.Idle,this._checkOcclusion=new Map,this._active=new Map,this._checkOcclusionIterator=null,this._activeIterator=null,this._occlusionQueryUids=new Array,this._updatingHandles=new v,this._deconflictor=new E(((i,t)=>{i.visible=t,this._setGraphicVisibility(this._active.get(i.id),t)}),((i,t)=>i.id!==t.id),ci),this._baseOccludedVisibility=10,this._altitudeFactor=2,this._minAltitudeDifference=100}initialize(){this._updatingHandles.add((()=>(this.view?.map?.ground?.opacity??0)>0),(()=>this.setDirty())),this._updatingHandles.add((()=>this.view.ready),(()=>this._occlusionQuery=null))}destroy(){this._occlusionQuery=null,this._updatingHandles.destroy(),this._deconflictor.destroy(),this._checkOcclusion.clear(),this._active.clear()}setDirty(){!this._dirty&&(this._active.size>0||this._checkOcclusion.size>0)&&(this._dirty=!0,this.notifyChange("updating"))}setPriority(i,t){const e=this._active.get(i.graphic.uid)?.getInfo(this.visibilityGroup);e&&(e.priority=t)}get updating(){return this._state!==ni.Idle||this._dirty||this._updatingHandles.updating}get updatingProgress(){if(!this.updating)return 1;const i=this._state/ni.NumStates;return this._dirty?.5*i:i}get running(){return this.view.ready&&null!=this.view.state&&this.updating}runTask(i){switch(this._state){case ni.Idle:this._startUpdate(),i.madeProgress();case ni.CheckOcclusion:if(this._state=ni.CheckOcclusion,!this._processCheckOcclusion(i))return;case ni.WaitOcclusion:if(this._state=ni.WaitOcclusion,this._occlusionQuery&&!this._occlusionQuery.done)return Y;this._readOcclusionQueryResult(),i.madeProgress();case ni.Collect:if(this._state=ni.Collect,!this._collectActiveGraphics(i))return;case ni.Deconflict:if(this._state=ni.Deconflict,this._deconflictor.run(i),!this._deconflictor.done)return;default:this._state=ni.Idle,this.notifyChange("updating")}}setGraphicsActive(i,t){t?i.forEach((i=>this.addToActiveGraphics(i))):i.forEach((i=>this.removeFromActiveGraphics(i)))}layerSupportsDeconfliction(i){if(null==i||"object3d"!==i.type)return!1;const t=i.stageObject;if(1!==(t?.geometries.length??0))return!1;const e=t?.geometries[0],s=e?.material;return s instanceof W}_startUpdate(){V(this.view),this._dirty=!1,this._viewState.copyFrom(this.viewState);const{fullWidth:i,fullHeight:t}=this._viewState.camera;this._deconflictor.reset(i,t),this._resetIterators(),this._occlusionQueryUids.length=0,this._checkOcclusion.size||(this._occlusionQuery=s(this._occlusionQuery))}addToActiveGraphics(i){i.ensureInfo(this.visibilityGroup),this._active.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromActiveGraphics(i){hi(i,this.visibilityGroup),i.removeInfo(this.visibilityGroup),this._active.delete(i.graphics3DGraphic.graphic.uid),this.setDirty()}addToCheckOcclusion(i){this._checkOcclusion.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromCheckOcclusion(i){this._checkOcclusion.delete(i.graphics3DGraphic.graphic.uid)}_processCheckOcclusion(i){if(0===this._checkOcclusion.size)return!0;const t=this._ensureCheckOcclusionIterator(),e=this._viewState.camera,r=o($,e.viewInverseTransposeMatrix),c=this.view.map.ground.opacity>0,n="global"===this.view.viewingMode&&c&&e.relativeElevation>0?ii:null;let a=0;null!=n&&(l(N(n),p,e.viewMatrix),n[3]=b(this.view.spatialReference).radius,a=T(n,p));const h=O();for(;;){if(i.done)return!1;i.madeProgress();const s=t.next();if(!0===s.done)break;const c=s.value,o=c.graphics3DGraphic;if(o.destroyed)continue;if(!o.isVisible(U.GRAPHIC,F.DECONFLICTION))continue;const u=fi(o,this.visibilityGroup);let d=null,p=!0;for(const i of u){if(!this.layerSupportsDeconfliction(i))continue;d=_i,this._projectHudLayer(i,e,d),w(h);const t=i.stageObject.geometries[0].material;if(this._expandBoundingRect(h,e,i,t,d),d.isOutsideScreen){p=!1;break}if(this._isCulledBySlice(c,d.positionView)){p=!1;break}if(null!=n&&pi(d,n,a)){p=!1;break}l(J,d.positionView,r),d.altitude=this.view.renderCoordsHelper.getAltitude(J);const s=c.ensureInfo(this.visibilityGroup);if(s.altitude=d.altitude,s.distance=d.distance,s.distanceToOccluder=d.distanceToOccluder,s.culled=!1,I(s.aabr,h),t.parameters.occlusionTest)break;this._ensureOcclusionQuery().addPosition(J)===this._occlusionQueryUids.length&&this._occlusionQueryUids.push(o.graphic.uid);break}if(this._active.has(o.graphic.uid)&&(!p||!d)){const i=c.ensureInfo(this.visibilityGroup);i.visible=!d,i.culled=!0}}return this._checkOcclusionIterator=null,this._occlusionQueryUids.length||(this._occlusionQuery=s(this._occlusionQuery)),this._occlusionQuery?.start(),!0}_readOcclusionQueryResult(){if(!this._occlusionQuery||!this._occlusionQueryUids.length)return;const i=this._viewState.camera,t=this.view.renderCoordsHelper.getAltitude(i.eye);for(let e=0;e<this._occlusionQueryUids.length;e++){const i=this._occlusionQueryUids[e],s=this._checkOcclusion.get(i);if(!s)continue;const r=this._occlusionQuery.getOcclusion(e)??-1,c=s.getInfo(this.visibilityGroup);c&&(c.distanceToOccluder=r>0?c.distance-r:0);const o=r<=0||this._occludedVisibility(c?.distanceToOccluder??0,c?.distance??r,c?.altitude??0,t);this._active.has(i)?c&&(c.culled=!o,c.visible=o):this._setGraphicVisibility(s,o)}this._occlusionQueryUids.length=0}_collectActiveGraphics(i){const t=this._ensureActiveGraphicsIterator(),e=this.visibilityGroup===U.LABEL;for(;!i.done;){i.madeProgress();const s=t.next();if(!0===s.done)return this._activeIterator=null,!0;const r=s.value,c=r.getInfo(this.visibilityGroup);if(!c)continue;!(!e||r.graphics3DGraphic.isVisible())||c.culled?(L(c.aabr,!1,!0),this._setGraphicVisibility(r,c.visible)):this._deconflictor.add(c)}return!1}_occludedVisibility(i,t,e,s){const r=Math.max(this._minAltitudeDifference,Math.abs(e-s))-this._minAltitudeDifference;return 0===i||t-i<=this._baseOccludedVisibility+this._altitudeFactor*r}_resetIterators(){this._checkOcclusionIterator=null,this._activeIterator=null}_ensureCheckOcclusionIterator(){return this._checkOcclusionIterator??=this._checkOcclusion.values(),this._checkOcclusionIterator}_ensureActiveGraphicsIterator(){return this._activeIterator??=this._active.values(),this._activeIterator}_ensureOcclusionQuery(){return this._occlusionQuery??=new H({view:this.view}),this._occlusionQueryUids.length||this._occlusionQuery.init(this._checkOcclusion.size,this._viewState.camera.eye),this._occlusionQuery}_projectHudLayer(i,t,e){const s=i.stageObject,r=s.geometries[0],c=r.material,o=N(s.boundingVolumeWorldSpace.bounds);l(q,o,t.viewMatrix);const n=r.attributes,a=n.get(M.NORMAL).data,d=n.get(M.CENTEROFFSETANDDISTANCE).data;c.applyShaderOffsetsView(q,a,s.transformation,d,t,e.scaleInfo,q),_(K,q[0],q[1],q[2],1),m(X,K,t.projectionMatrix),h(e.positionNDC,X,1/X[3]),c.applyShaderOffsetsNDC(e.positionNDC,d,t,e.positionNDC,Z),e.distanceWithoutPolygonOffset=t.depthNDCToWorld(Z[2]),e.distance=Z[2]===e.positionNDC[2]?e.distanceWithoutPolygonOffset:t.depthNDCToWorld(e.positionNDC[2]),_(X,e.positionNDC[0],e.positionNDC[1],e.positionNDC[2],1),m(K,X,t.inverseProjectionMatrix),g(K,K,1/K[3]),u(e.positionView,q[0],q[1],q[2])}_isCulledBySlice(i,t){return i.slicePlaneEnabled&&this._viewState.slicePlaneEnabled&&k(this._viewState.slicePlane,t)}_expandBoundingRect(i,t,s,r,{positionNDC:c,scaleInfo:o}){const n=s.getScreenSize(ui);B(n,o.factor,n),n[0]*=t.pixelRatio,n[1]*=t.pixelRatio;const a=D(r.calculateRelativeScreenBounds(n,o.factorAlignment.scale*t.pixelRatio,si),e(0,t.fullWidth,.5+.5*c[0]),e(0,t.fullHeight,.5+.5*c[1])),l=this.marginFactor;if(0!==l){const i=l*Math.min(C(a),j(a));a[0]-=i,a[1]-=i,a[2]+=i,a[3]+=i}G(i,a,i)}_setGraphicVisibility(i,t){const e=i?.graphics3DGraphic;e&&!e.destroyed&&(e.setVisibilityFlag(this.visibilityGroup,F.DECONFLICTION,t),this.visibilityGroup===U.LABEL&&this.view.labeler.setLabelGraphicVisibility(e,t))}};function hi(i,t){const e=i.graphics3DGraphic;e.destroyed||e.setVisibilityFlag(t,F.DECONFLICTION,!0)}i([r({constructOnly:!0})],li.prototype,"view",void 0),i([r({type:Boolean,readOnly:!0})],li.prototype,"updating",null),i([r({readOnly:!0})],li.prototype,"_updatingHandles",void 0),li=i([c("esri.views.3d.layers.graphics.Deconflictor")],li);const ui=a();class di{constructor(){this.positionView=f(),this.positionNDC=f(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.distanceWithoutPolygonOffset=0,this.scaleInfo=new z}get isOutsideScreen(){const i=this.positionNDC;return i[0]<-1||i[1]<-1||i[2]<-1||i[0]>=1||i[1]>=1||i[2]>=1}}function pi(i,t,e){return d(ti.direction,i.positionView),u(ti.origin,0,0,0),!!x(t,ti,ei)&&i.distanceWithoutPolygonOffset>e}function fi(i,t){return t===U.LABEL?i.labelLayers:i.layers}const _i=new di;export{li as Deconflictor,oi as DeconflictorGraphic,ai as DeconflictorViewState,ni as State};
5
+ import{_ as i}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import{lerp as e}from"../../../../core/mathUtils.js";import{destroyMaybe as s}from"../../../../core/maybe.js";import{property as r}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as c}from"../../../../core/accessorSupport/decorators/subclass.js";import{transpose as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{t as l,g as h,i as u,c as d}from"../../../../chunks/vec32.js";import{ZEROS as p,create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as _,t as m,d as g}from"../../../../chunks/vec42.js";import{create as y}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as v}from"../../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b}from"../../../../geometry/ellipsoidUtils.js";import{create as O,empty as w,copy as I,offset as D,width as C,height as j,expand as G}from"../../../../geometry/support/aaBoundingRect.js";import{e as k,d as S,a as A}from"../../../../chunks/boundedPlane.js";import{create as Q}from"../../../../geometry/support/ray.js";import{a as N,c as P,l as T,i as x}from"../../../../chunks/sphere.js";import{DeconflictAABR as E}from"./DeconflictAABR.js";import{prepare as V,drawPoly as L}from"./deconflictorDebug.js";import{VisibilityGroup as U,VisibilityFlag as F}from"./enums.js";import R from"../../webgl/RenderCamera.js";import{GPUPointOcclusionQuery as H}from"../../webgl-engine/lib/GPUPointOcclusionQuery.js";import{applyPrecomputedScaleFactor as B}from"../../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as M}from"../../webgl-engine/lib/VertexAttribute.js";import{HUDMaterial as W}from"../../webgl-engine/materials/HUDMaterial.js";import{ScaleInfo as z}from"../../webgl-engine/materials/ScaleInfo.js";import{Yield as Y}from"../../../support/Yield.js";const q=f(),J=f(),K=y(),X=y(),Z=f(),$=n(),ii=P(),ti=Q(),ei=f(),si=O();class ri{constructor(i){this.id=i,this.aabr=O(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.culled=!1,this.visible=!1,this.priority=0}}function ci(i,t){const e=0!==i.distanceToOccluder&&i.distance>i.distanceToOccluder,s=0!==t.distanceToOccluder&&t.distance>t.distanceToOccluder;return e!==s?+e-+s:i.priority!==t.priority?t.priority-i.priority:i.distance!==t.distance?i.distance-t.distance:i.visible!==t.visible?+t.visible-+i.visible:i.id-t.id}class oi{constructor(i,t){this.graphics3DGraphic=i,this.slicePlaneEnabled=t,this._info=null,this._labelInfo=null}ensureInfo(i){let t=this.getInfo(i);return t||(t=new ri(this.graphics3DGraphic.graphic.uid),this._setInfo(i,t)),t}getInfo(i){return i===U.LABEL?this._labelInfo:this._info}removeInfo(i){this._setInfo(i,null)}_setInfo(i,t){i===U.LABEL?this._labelInfo=t:this._info=t}}var ni;!function(i){i[i.Idle=0]="Idle",i[i.CheckOcclusion=1]="CheckOcclusion",i[i.WaitOcclusion=2]="WaitOcclusion",i[i.Collect=3]="Collect",i[i.Deconflict=4]="Deconflict",i[i.NumStates=5]="NumStates"}(ni||(ni={}));class ai{constructor(){this.camera=new R,this.slicePlane=S(),this.slicePlaneEnabled=!1}copyFrom(i){this.camera.copyFrom(i.camera),A(i.slicePlane,this.slicePlane),this.slicePlaneEnabled=i.slicePlaneEnabled}}let li=class extends t{get dirty(){return this._dirty}get state(){return this._state}constructor(i){super(i),this._dirty=!1,this._viewState=new ai,this._state=ni.Idle,this._checkOcclusion=new Map,this._active=new Map,this._checkOcclusionIterator=null,this._activeIterator=null,this._occlusionQueryUids=new Array,this._updatingHandles=new v,this._deconflictor=new E(((i,t)=>{i.visible=t,this._setGraphicVisibility(this._active.get(i.id),t)}),((i,t)=>i.id!==t.id),ci),this._baseOccludedVisibility=10,this._altitudeFactor=2,this._minAltitudeDifference=100}initialize(){this._updatingHandles.add((()=>(this.view?.map?.ground?.opacity??0)>0),(()=>this.setDirty())),this._updatingHandles.add((()=>this.view.ready),(()=>this._occlusionQuery=null))}destroy(){this._occlusionQuery=null,this._updatingHandles.destroy(),this._deconflictor.destroy(),this._checkOcclusion.clear(),this._active.clear()}setDirty(){!this._dirty&&(this._active.size>0||this._checkOcclusion.size>0)&&(this._dirty=!0,this.notifyChange("updating"))}setPriority(i,t){const e=this._active.get(i.graphic.uid)?.getInfo(this.visibilityGroup);e&&(e.priority=t)}get updating(){return this._state!==ni.Idle||this._dirty||this._updatingHandles.updating}get updatingProgress(){if(!this.updating)return 1;const i=this._state/ni.NumStates;return this._dirty?.5*i:i}get running(){return this.view.ready&&null!=this.view.state&&this.updating}runTask(i){switch(this._state){case ni.Idle:this._startUpdate(),i.madeProgress();case ni.CheckOcclusion:if(this._state=ni.CheckOcclusion,!this._processCheckOcclusion(i))return;case ni.WaitOcclusion:if(this._state=ni.WaitOcclusion,this._occlusionQuery&&!this._occlusionQuery.done)return Y;this._readOcclusionQueryResult(),i.madeProgress();case ni.Collect:if(this._state=ni.Collect,!this._collectActiveGraphics(i))return;case ni.Deconflict:if(this._state=ni.Deconflict,this._deconflictor.run(i),!this._deconflictor.done)return;default:this._state=ni.Idle,this.notifyChange("updating")}}setGraphicsActive(i,t){t?i.forEach((i=>this.addToActiveGraphics(i))):i.forEach((i=>this.removeFromActiveGraphics(i)))}layerSupportsDeconfliction(i){if(null==i||"object3d"!==i.type)return!1;const t=i.stageObject;if(1!==(t?.geometries.length??0))return!1;const e=t?.geometries[0],s=e?.material;return s instanceof W}_startUpdate(){V(this.view),this._dirty=!1,this._viewState.copyFrom(this.viewState);const{fullWidth:i,fullHeight:t}=this._viewState.camera;this._deconflictor.reset(i,t),this._resetIterators(),this._occlusionQueryUids.length=0,this._checkOcclusion.size||(this._occlusionQuery=s(this._occlusionQuery))}addToActiveGraphics(i){i.ensureInfo(this.visibilityGroup),this._active.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromActiveGraphics(i){hi(i,this.visibilityGroup),i.removeInfo(this.visibilityGroup),this._active.delete(i.graphics3DGraphic.graphic.uid),this.setDirty()}addToCheckOcclusion(i){this._checkOcclusion.set(i.graphics3DGraphic.graphic.uid,i),this.setDirty()}removeFromCheckOcclusion(i){this._checkOcclusion.delete(i.graphics3DGraphic.graphic.uid)}_processCheckOcclusion(i){if(0===this._checkOcclusion.size)return!0;const t=this._ensureCheckOcclusionIterator(),e=this._viewState.camera,r=o($,e.viewInverseTransposeMatrix),c=this.view.map.ground.opacity>0,n="global"===this.view.viewingMode&&c&&e.relativeElevation>0?ii:null;let a=0;null!=n&&(l(N(n),p,e.viewMatrix),n[3]=b(this.view.spatialReference).radius,a=T(n,p));const h=O();for(;;){if(i.done)return!1;i.madeProgress();const s=t.next();if(!0===s.done)break;const c=s.value,o=c.graphics3DGraphic;if(o.destroyed)continue;if(!o.isVisible(U.GRAPHIC,F.DECONFLICTION))continue;const u=fi(o,this.visibilityGroup);let d=null,p=!0;for(const i of u){if(!this.layerSupportsDeconfliction(i))continue;d=_i,this._projectHudLayer(i,e,d),w(h);const t=i.stageObject.geometries[0].material;if(this._expandBoundingRect(h,e,i,t,d),d.isOutsideScreen){p=!1;break}if(this._isCulledBySlice(c,d.positionView)){p=!1;break}if(null!=n&&pi(d,n,a)){p=!1;break}l(J,d.positionView,r),d.altitude=this.view.renderCoordsHelper.getAltitude(J);const s=c.ensureInfo(this.visibilityGroup);if(s.altitude=d.altitude,s.distance=d.distance,s.distanceToOccluder=d.distanceToOccluder,s.culled=!1,I(s.aabr,h),t.parameters.occlusionTest)break;this._ensureOcclusionQuery().addPosition(J)===this._occlusionQueryUids.length&&this._occlusionQueryUids.push(o.graphic.uid);break}if(this._active.has(o.graphic.uid)&&(!p||!d)){const i=c.ensureInfo(this.visibilityGroup);i.visible=!d,i.culled=!0}}return this._checkOcclusionIterator=null,this._occlusionQueryUids.length||(this._occlusionQuery=s(this._occlusionQuery)),this._occlusionQuery?.start(),!0}_readOcclusionQueryResult(){if(!this._occlusionQuery||!this._occlusionQueryUids.length)return;const i=this._viewState.camera,t=this.view.renderCoordsHelper.getAltitude(i.eye);for(let e=0;e<this._occlusionQueryUids.length;e++){const i=this._occlusionQueryUids[e],s=this._checkOcclusion.get(i);if(!s)continue;const r=this._occlusionQuery.getOcclusion(e)??-1,c=s.getInfo(this.visibilityGroup);c&&(c.distanceToOccluder=r>0?c.distance-r:0);const o=r<=0||this._occludedVisibility(c?.distanceToOccluder??0,c?.distance??r,c?.altitude??0,t);this._active.has(i)?c&&(c.culled=!o,c.visible=o):this._setGraphicVisibility(s,o)}this._occlusionQueryUids.length=0}_collectActiveGraphics(i){const t=this._ensureActiveGraphicsIterator(),e=this.visibilityGroup===U.LABEL;for(;!i.done;){i.madeProgress();const s=t.next();if(!0===s.done)return this._activeIterator=null,!0;const r=s.value,c=r.getInfo(this.visibilityGroup);if(!c)continue;!(!e||r.graphics3DGraphic.isVisible())||c.culled?(L(c.aabr,!1,!0),this._setGraphicVisibility(r,c.visible)):this._deconflictor.add(c)}return!1}_occludedVisibility(i,t,e,s){const r=Math.max(this._minAltitudeDifference,Math.abs(e-s))-this._minAltitudeDifference;return 0===i||t-i<=this._baseOccludedVisibility+this._altitudeFactor*r}_resetIterators(){this._checkOcclusionIterator=null,this._activeIterator=null}_ensureCheckOcclusionIterator(){return this._checkOcclusionIterator??=this._checkOcclusion.values(),this._checkOcclusionIterator}_ensureActiveGraphicsIterator(){return this._activeIterator??=this._active.values(),this._activeIterator}_ensureOcclusionQuery(){return this._occlusionQuery??=new H({view:this.view}),this._occlusionQueryUids.length||this._occlusionQuery.init(this._checkOcclusion.size,this._viewState.camera.eye),this._occlusionQuery}_projectHudLayer(i,t,e){const s=i.stageObject,r=s.geometries[0],c=r.material,o=N(s.boundingVolumeWorldSpace.bounds);l(q,o,t.viewMatrix);const n=r.attributes,a=n.get(M.NORMAL).data,d=n.get(M.CENTEROFFSETANDDISTANCE).data;c.applyShaderOffsetsView(q,a,s.transformation,d,t,e.scaleInfo,q),_(K,q[0],q[1],q[2],1),m(X,K,t.projectionMatrix),h(e.positionNDC,X,1/X[3]),c.applyShaderOffsetsNDC(e.positionNDC,d,t,e.positionNDC,Z),e.distanceWithoutPolygonOffset=t.depthNDCToWorld(Z[2]),e.distance=Z[2]===e.positionNDC[2]?e.distanceWithoutPolygonOffset:t.depthNDCToWorld(e.positionNDC[2]),_(X,e.positionNDC[0],e.positionNDC[1],e.positionNDC[2],1),m(K,X,t.inverseProjectionMatrix),g(K,K,1/K[3]),u(e.positionView,q[0],q[1],q[2])}_isCulledBySlice(i,t){return i.slicePlaneEnabled&&this._viewState.slicePlaneEnabled&&k(this._viewState.slicePlane,t)}_expandBoundingRect(i,t,s,r,{positionNDC:c,scaleInfo:o}){const n=s.getScreenSize(ui);B(n,o.factor,n),n[0]*=t.pixelRatio,n[1]*=t.pixelRatio;const a=D(r.calculateRelativeScreenBounds(n,o.factorAlignment.scale*t.pixelRatio,si),e(0,t.fullWidth,.5+.5*c[0]),e(0,t.fullHeight,.5+.5*c[1])),l=this.marginFactor;if(0!==l){const i=l*Math.min(C(a),j(a));a[0]-=i,a[1]-=i,a[2]+=i,a[3]+=i}G(i,a,i)}_setGraphicVisibility(i,t){const e=i?.graphics3DGraphic;e&&!e.destroyed&&(e.setVisibilityFlag(this.visibilityGroup,F.DECONFLICTION,t),this.visibilityGroup===U.LABEL&&this.view.labeler.setLabelGraphicVisibility(e,t))}};function hi(i,t){const e=i.graphics3DGraphic;e.destroyed||e.setVisibilityFlag(t,F.DECONFLICTION,!0)}i([r({constructOnly:!0})],li.prototype,"view",void 0),i([r({type:Boolean,readOnly:!0})],li.prototype,"updating",null),i([r({readOnly:!0})],li.prototype,"_updatingHandles",void 0),li=i([c("esri.views.3d.layers.graphics.Deconflictor")],li);const ui=a();class di{constructor(){this.positionView=f(),this.positionNDC=f(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.distanceWithoutPolygonOffset=0,this.scaleInfo=new z}get isOutsideScreen(){const i=this.positionNDC;return i[0]<-1||i[1]<-1||i[2]<-1||i[0]>=1||i[1]>=1||i[2]>=1}}function pi(i,t,e){return d(ti.direction,i.positionView),u(ti.origin,0,0,0),!!x(t,ti,ei)&&i.distanceWithoutPolygonOffset>e}function fi(i,t){return t===U.LABEL?i.labelLayers:i.layers}const _i=new di;export{li as Deconflictor,oi as DeconflictorGraphic,ai as DeconflictorViewState,ni as State};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../../core/Error.js";import{assertIsSome as t}from"../../../../core/maybe.js";import{MinPriority as r}from"../../../../core/MemCache.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{generateUUID as n}from"../../../../core/uuid.js";import{normalFromMat4 as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{q as i}from"../../../../chunks/vec32.js";import{ONES as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBoundingSphere as d}from"../../../../geometry/projection/projectBoundingSphere.js";import{isRelativeVertexSpace as c}from"../../../../geometry/support/meshVertexSpaceUtils.js";import{l as u}from"../../../../chunks/sphere.js";import{CachedMeshData as m}from"./CachedMeshData.js";import{convertMeshMaterialToPBRMaterial as h}from"./I3SClientMaterialUtil.js";class f{constructor(e,t,r,o){this._uid=e,this._worker=o,this._id2Meta=new Map,this._oid2Meta=new Map,this._indexSR=t.indexSR,this._vertexSR=t.vertexSR,this._renderSR=t.renderSR,this._memCache=r.newCache(`sl-client-mesh-data-${this._uid}`)}get uid(){return this._uid}get worker(){return this._worker}get indexSR(){return this._indexSR}get renderSR(){return this._renderSR}createMeshNodeInfo(e,t){const r=`mesh${t}`,o=e.extent,n=o.spatialReference,s=this._indexSR,a=y(o,e.origin);d(a,n,a,s);return{type:"mesh",id:r,version:w(e),oid:t,mbs:a,componentNodeIds:[],unloadedMesh:e,nodeIndex:null,loadMeshPromise:null}}addMeshNode(t,r){if(null!=this.getMeshNodeIndex(r.oid))throw new e("scenelayer",`I3SClientNodeLoader: client side mesh for feature oid=${r.oid} already exists`);r.nodeIndex=t,this._id2Meta.set(r.id,r),this._oid2Meta.set(r.oid,r)}getMeshNodeIndex(e){const t=this._oid2Meta.get(e);return null==t||"mesh"!==t.type?null:t.nodeIndex}getMeshNodeInfo(e){const t=this._oid2Meta.values();for(const r of t)if("mesh"===r.type&&r.id===e)return r;return null}removeNode(e){const t=this._id2Meta.get(e);null!=t&&(this._id2Meta.delete(e),"mesh"===t.type&&this._oid2Meta.delete(t.oid))}async loadNodeJSON(t){const r=this._id2Meta.get(t);if(null==r)throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to find node ${t}`);switch(r.type){case"mesh":return this._loadMeshNodeJSON(r);case"mesh-component":return p(r);default:throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to handle node ${t}`)}}async _loadMeshNodeJSON(e){const t=e.id,r=(await this._getMeshData(e)).loadedMesh;if(null==r.components||0===r.components.length)return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null};const o=[],n=r.components;for(let s=0;s<n.length;++s){const r=`${t}-component${s}`,n={type:"mesh-component",id:r,mbs:e.mbs,componentIndex:s,meshNodeInfo:e,textureData:new Map};this._id2Meta.set(n.id,n),e.componentNodeIds.push(r),o.push({id:n.id,href:null,mbs:n.mbs,obb:null})}return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:o}}updateNodeIndex(e,t,r){const o=this._id2Meta.get(e);o&&"mesh"===o.type&&(o.nodeIndex=r)}async loadNodeData(r,n){const s=this._id2Meta.get(r);if(null==s||"mesh-component"!==s.type)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected node info)`);const a=s.meshNodeInfo,i=await this._getMeshData(a),l=i.loadedMesh,d=a.oid;if(null==l.components)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected null reference)`);const c=l.components[s.componentIndex],{material:u,requiredTextures:m,textureData:f}=await h(c.material);if(null!=f)for(const e of f)null!=e&&s.textureData.set(e.id,e);const p={params:{material:u},type:"ArrayBufferView"},{vertexSpace:y,origin:M,transform:w}=l,S=[M.x,M.y,M.z??0];i.projectionPromise||(t(this._worker,"SceneLayerWorker is needed to project mesh"),i.projectionPromise=this._worker.project({positions:l.vertexAttributes.position,localMatrix:w?.localMatrix,vertexSpace:y.toJSON(),origin:S,inSpatialReference:l.spatialReference.toJSON(),outSpatialReference:this._vertexSR.toJSON()},n));const{projected:b,original:_,projectedOrigin:N}=await i.projectionPromise;l.vertexAttributes.position=_;const{transformed:v,original:D}=await x(c,i,this._worker,n);l.vertexAttributes.normal=D,o(n);const{geometryBuffer:R,geometryDescriptor:j}=g(b,c.faces,v,l.vertexAttributes.uv,l.vertexAttributes.color,d);return{geometryData:{featureDataPosition:N,featureIds:[],geometries:[p]},attributeDataInfo:{attributeData:{},loadedAttributes:[]},geometryBuffer:R,geometryDescriptor:j,requiredTextures:m,textureData:f,normalReferenceFrame:this._vertexSR.isGeographic?"east-north-up":"vertex-reference-frame"}}async loadAttributes(e,t,r){const o=e.numFeatures,n={};for(const{field:{name:s}}of t)n[s]=new Array(o);return n}async loadTextures(e,t,r){const o=e.id,n=this._id2Meta.get(o);if(null==n||"mesh-component"!==n.type)throw new Error(`Failed to load textures for node ${e.id} (unexpected node info)`);const s=[];for(const a of t)s.push(n.textureData.get(a.id)||null);return s}async _getMeshData(e){const t=e.version,o=this._memCache.get(t);if(null==o){if(null!=e.loadMeshPromise)return e.loadMeshPromise;const o=async(o,n)=>{const s=e.unloadedMesh.clone();try{await s.load()}catch(i){n(i)}const a=new m(s);this._memCache.put(t,a,r),e.loadMeshPromise=null,o(a)};return e.loadMeshPromise=new Promise(((e,t)=>o(e,t))),e.loadMeshPromise}return o}}async function p(e){return{id:e.id,version:e.meshNodeInfo.version,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null,isEmpty:!1}}function y(e,t){const{spatialReference:r}=e,o=[1,-1],n=[.5*e.width,.5*e.height,e.hasZ?.5*(e.zmax-e.zmin):0],s=r.isGeographic?r.metersPerUnit:1,a=e.center;let i=0;if(e.hasZ)for(let l=0;l<2;++l)for(let e=0;e<2;++e)for(let r=0;r<2;++r){const d=(a.x+o[l]*n[0]-t.x)*s,c=(a.y+o[e]*n[1]-t.y)*s,u=a.z+o[r]*n[2]-t.z;i=Math.max(d*d+c*c+u*u,i)}else for(let l=0;l<2;++l)for(let e=0;e<2;++e){const r=(a.x+o[l]*n[0]-t.x)*s,d=(a.y+o[e]*n[1]-t.y)*s;i=Math.max(r*r+d*d,i)}return u([t.x,t.y,t.z],Math.sqrt(i))}async function x(e,r,o,n){const{transform:d,vertexAttributes:c}=r.loadedMesh,u="source"===e.shading?c.normal:null;if(!(null!=u&&null!=d&&(0!==d.rotationAngle||!i(d.scale,l))))return{transformed:u,original:c.normal};if(!r.normalsTransformPromise){t(o,"SceneLayerWorker is needed to transform mesh normals");const e=a();s(e,d.localMatrix),r.normalsTransformPromise=o.transformNormals({normalMatrix:e,normals:u},n)}return r.normalsTransformPromise}function g(e,t,r,o,n,s){const a=1,i=(t?.length??0)/3,l=3*i;let d=0,c=0,u=!1,m=0,h=!1,f=0,p=!1,y=0,x=0,g=0;d+=S,d+=S,c=d,d+=3*l*b,null!=r&&(u=!0,m=d,d+=3*l*b),null!=o&&(h=!0,f=d,d+=2*l*b),null!=n&&(p=!0,y=d,d+=4*l*_),x=d,d+=a*N,g=d,d+=2*a*S;const w=new ArrayBuffer(d),v=new Uint8Array(w);M(v,0,l),M(v,S,a);const D=new Float32Array(w,c),R=null!=r?new Float32Array(w,m):null,j=null!=o?new Float32Array(w,f):null,I=null!=n?new Uint8Array(w,y):null;for(let M=0;M<i;++M){const s=3*M;for(let a=0;a<3;++a){const i=t[s+a],l=3*i,d=9*M+3*a;if(D[d]=e[l],D[d+1]=e[l+1],D[d+2]=e[l+2],R&&(R[d]=r[l],R[d+1]=r[l+1],R[d+2]=r[l+2]),j){const e=2*i,t=6*M+2*a;j[t]=o[e],j[t+1]=o[e+1]}if(I){const e=4*i,t=12*M+4*a;I[t]=n[e],I[t+1]=n[e+1],I[t+2]=n[e+2],I[t+3]=n[e+3]}}}M(v,x,s),M(v,x+S,s/2**32),M(v,g,0),M(v,g+S,i-1);return{geometryBuffer:w,geometryDescriptor:{isDraco:!1,isLegacy:!0,color:p,normal:u,uv0:h,uvRegion:!1,featureIndex:!0}}}function M(e,t,r){e[t]=255&r,e[t+1]=255&r>>8,e[t+2]=255&r>>16,e[t+3]=255&r>>24}function w(e){const t=e.metadata.displaySource?.source;if(null==t||!Array.isArray(t)||!t.length||t[0]instanceof File)return n();const r=t;let o="";for(const n of r)o+=n.makeHash();return o+JSON.stringify(e.transform?.toJSON()??"")+(c(e.vertexSpace)?JSON.stringify(e.vertexSpace.origin):"")+JSON.stringify(e.spatialReference)}const S=4,b=4,_=1,N=8;export{f as I3SClientNodeLoader,y as createSphereFromExtent,b as sizeOfFloat32,S as sizeOfInt32,N as sizeOfUInt64,_ as sizeOfUInt8,x as transformNormals};
5
+ import e from"../../../../core/Error.js";import{assertIsSome as t}from"../../../../core/maybe.js";import{MinPriority as r}from"../../../../core/MemCache.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{generateUUID as n}from"../../../../core/uuid.js";import{normalFromMat4 as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{q as i}from"../../../../chunks/vec32.js";import{ONES as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBoundingSphere as d}from"../../../../geometry/projection/projectBoundingSphere.js";import{isRelativeVertexSpace as c}from"../../../../geometry/support/meshVertexSpaceUtils.js";import{h as u}from"../../../../chunks/sphere.js";import{CachedMeshData as m}from"./CachedMeshData.js";import{convertMeshMaterialToPBRMaterial as h}from"./I3SClientMaterialUtil.js";class f{constructor(e,t,r,o){this._uid=e,this._worker=o,this._id2Meta=new Map,this._oid2Meta=new Map,this._indexSR=t.indexSR,this._vertexSR=t.vertexSR,this._renderSR=t.renderSR,this._memCache=r.newCache(`sl-client-mesh-data-${this._uid}`)}get uid(){return this._uid}get worker(){return this._worker}get indexSR(){return this._indexSR}get renderSR(){return this._renderSR}createMeshNodeInfo(e,t){const r=`mesh${t}`,o=e.extent,n=o.spatialReference,s=this._indexSR,a=y(o,e.origin);d(a,n,a,s);return{type:"mesh",id:r,version:w(e),oid:t,mbs:a,componentNodeIds:[],unloadedMesh:e,nodeIndex:null,loadMeshPromise:null}}addMeshNode(t,r){if(null!=this.getMeshNodeIndex(r.oid))throw new e("scenelayer",`I3SClientNodeLoader: client side mesh for feature oid=${r.oid} already exists`);r.nodeIndex=t,this._id2Meta.set(r.id,r),this._oid2Meta.set(r.oid,r)}getMeshNodeIndex(e){const t=this._oid2Meta.get(e);return null==t||"mesh"!==t.type?null:t.nodeIndex}getMeshNodeInfo(e){const t=this._oid2Meta.values();for(const r of t)if("mesh"===r.type&&r.id===e)return r;return null}removeNode(e){const t=this._id2Meta.get(e);null!=t&&(this._id2Meta.delete(e),"mesh"===t.type&&this._oid2Meta.delete(t.oid))}async loadNodeJSON(t){const r=this._id2Meta.get(t);if(null==r)throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to find node ${t}`);switch(r.type){case"mesh":return this._loadMeshNodeJSON(r);case"mesh-component":return p(r);default:throw new e("scenelayer",`I3SClientNodeLoader::loadNodeJSON unable to handle node ${t}`)}}async _loadMeshNodeJSON(e){const t=e.id,r=(await this._getMeshData(e)).loadedMesh;if(null==r.components||0===r.components.length)return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null};const o=[],n=r.components;for(let s=0;s<n.length;++s){const r=`${t}-component${s}`,n={type:"mesh-component",id:r,mbs:e.mbs,componentIndex:s,meshNodeInfo:e,textureData:new Map};this._id2Meta.set(n.id,n),e.componentNodeIds.push(r),o.push({id:n.id,href:null,mbs:n.mbs,obb:null})}return{id:t,version:null,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:o}}updateNodeIndex(e,t,r){const o=this._id2Meta.get(e);o&&"mesh"===o.type&&(o.nodeIndex=r)}async loadNodeData(r,n){const s=this._id2Meta.get(r);if(null==s||"mesh-component"!==s.type)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected node info)`);const a=s.meshNodeInfo,i=await this._getMeshData(a),l=i.loadedMesh,d=a.oid;if(null==l.components)throw new e("scenelayer",`Failed to load client node data for node ${r} (unexpected null reference)`);const c=l.components[s.componentIndex],{material:u,requiredTextures:m,textureData:f}=await h(c.material);if(null!=f)for(const e of f)null!=e&&s.textureData.set(e.id,e);const p={params:{material:u},type:"ArrayBufferView"},{vertexSpace:y,origin:M,transform:w}=l,S=[M.x,M.y,M.z??0];i.projectionPromise||(t(this._worker,"SceneLayerWorker is needed to project mesh"),i.projectionPromise=this._worker.project({positions:l.vertexAttributes.position,localMatrix:w?.localMatrix,vertexSpace:y.toJSON(),origin:S,inSpatialReference:l.spatialReference.toJSON(),outSpatialReference:this._vertexSR.toJSON()},n));const{projected:b,original:_,projectedOrigin:N}=await i.projectionPromise;l.vertexAttributes.position=_;const{transformed:v,original:D}=await x(c,i,this._worker,n);l.vertexAttributes.normal=D,o(n);const{geometryBuffer:R,geometryDescriptor:j}=g(b,c.faces,v,l.vertexAttributes.uv,l.vertexAttributes.color,d);return{geometryData:{featureDataPosition:N,featureIds:[],geometries:[p]},attributeDataInfo:{attributeData:{},loadedAttributes:[]},geometryBuffer:R,geometryDescriptor:j,requiredTextures:m,textureData:f,normalReferenceFrame:this._vertexSR.isGeographic?"east-north-up":"vertex-reference-frame"}}async loadAttributes(e,t,r){const o=e.numFeatures,n={};for(const{field:{name:s}}of t)n[s]=new Array(o);return n}async loadTextures(e,t,r){const o=e.id,n=this._id2Meta.get(o);if(null==n||"mesh-component"!==n.type)throw new Error(`Failed to load textures for node ${e.id} (unexpected node info)`);const s=[];for(const a of t)s.push(n.textureData.get(a.id)||null);return s}async _getMeshData(e){const t=e.version,o=this._memCache.get(t);if(null==o){if(null!=e.loadMeshPromise)return e.loadMeshPromise;const o=async(o,n)=>{const s=e.unloadedMesh.clone();try{await s.load()}catch(i){n(i)}const a=new m(s);this._memCache.put(t,a,r),e.loadMeshPromise=null,o(a)};return e.loadMeshPromise=new Promise(((e,t)=>o(e,t))),e.loadMeshPromise}return o}}async function p(e){return{id:e.id,version:e.meshNodeInfo.version,mbs:e.mbs,obb:null,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:null,isEmpty:!1}}function y(e,t){const{spatialReference:r}=e,o=[1,-1],n=[.5*e.width,.5*e.height,e.hasZ?.5*(e.zmax-e.zmin):0],s=r.isGeographic?r.metersPerUnit:1,a=e.center;let i=0;if(e.hasZ)for(let l=0;l<2;++l)for(let e=0;e<2;++e)for(let r=0;r<2;++r){const d=(a.x+o[l]*n[0]-t.x)*s,c=(a.y+o[e]*n[1]-t.y)*s,u=a.z+o[r]*n[2]-t.z;i=Math.max(d*d+c*c+u*u,i)}else for(let l=0;l<2;++l)for(let e=0;e<2;++e){const r=(a.x+o[l]*n[0]-t.x)*s,d=(a.y+o[e]*n[1]-t.y)*s;i=Math.max(r*r+d*d,i)}return u([t.x,t.y,t.z],Math.sqrt(i))}async function x(e,r,o,n){const{transform:d,vertexAttributes:c}=r.loadedMesh,u="source"===e.shading?c.normal:null;if(!(null!=u&&null!=d&&(0!==d.rotationAngle||!i(d.scale,l))))return{transformed:u,original:c.normal};if(!r.normalsTransformPromise){t(o,"SceneLayerWorker is needed to transform mesh normals");const e=a();s(e,d.localMatrix),r.normalsTransformPromise=o.transformNormals({normalMatrix:e,normals:u},n)}return r.normalsTransformPromise}function g(e,t,r,o,n,s){const a=1,i=(t?.length??0)/3,l=3*i;let d=0,c=0,u=!1,m=0,h=!1,f=0,p=!1,y=0,x=0,g=0;d+=S,d+=S,c=d,d+=3*l*b,null!=r&&(u=!0,m=d,d+=3*l*b),null!=o&&(h=!0,f=d,d+=2*l*b),null!=n&&(p=!0,y=d,d+=4*l*_),x=d,d+=a*N,g=d,d+=2*a*S;const w=new ArrayBuffer(d),v=new Uint8Array(w);M(v,0,l),M(v,S,a);const D=new Float32Array(w,c),R=null!=r?new Float32Array(w,m):null,j=null!=o?new Float32Array(w,f):null,I=null!=n?new Uint8Array(w,y):null;for(let M=0;M<i;++M){const s=3*M;for(let a=0;a<3;++a){const i=t[s+a],l=3*i,d=9*M+3*a;if(D[d]=e[l],D[d+1]=e[l+1],D[d+2]=e[l+2],R&&(R[d]=r[l],R[d+1]=r[l+1],R[d+2]=r[l+2]),j){const e=2*i,t=6*M+2*a;j[t]=o[e],j[t+1]=o[e+1]}if(I){const e=4*i,t=12*M+4*a;I[t]=n[e],I[t+1]=n[e+1],I[t+2]=n[e+2],I[t+3]=n[e+3]}}}M(v,x,s),M(v,x+S,s/2**32),M(v,g,0),M(v,g+S,i-1);return{geometryBuffer:w,geometryDescriptor:{isDraco:!1,isLegacy:!0,color:p,normal:u,uv0:h,uvRegion:!1,featureIndex:!0}}}function M(e,t,r){e[t]=255&r,e[t+1]=255&r>>8,e[t+2]=255&r>>16,e[t+3]=255&r>>24}function w(e){const t=e.metadata.displaySource?.source;if(null==t||!Array.isArray(t)||!t.length||t[0]instanceof File)return n();const r=t;let o="";for(const n of r)o+=n.makeHash();return o+JSON.stringify(e.transform?.toJSON()??"")+(c(e.vertexSpace)?JSON.stringify(e.vertexSpace.origin):"")+JSON.stringify(e.spatialReference)}const S=4,b=4,_=1,N=8;export{f as I3SClientNodeLoader,y as createSphereFromExtent,b as sizeOfFloat32,S as sizeOfInt32,N as sizeOfUInt64,_ as sizeOfUInt8,x as transformNormals};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{l as n,e as s,c as o,u as r}from"../../../../chunks/sphere.js";import{LodMetric as a,NodeBase as l,Node as d,NodeFilterImpact as h,NodeIMModificationImpact as u,NodeTraversalState as c}from"./I3SNode.js";import{invalidateMbs as g,addWraparound as _}from"./I3SUtil.js";import{ValidatedNode as f}from"./ValidatedNode.js";import{ElevationRange as m}from"../../support/ElevationRange.js";import{Obb as v}from"../../support/orientedBoundingBox.js";class N{constructor(e,t,i,n,s){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this.ref=n,this.node=s,this.useAsHole=0,this.filterImpact=h.NotChecked,this.traversalState=null,this.parent=-1}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.ref?.invalidateServiceBVsInRenderSR()}}class p{constructor(e=new Array,t=new Array){this.nodes=e,this.children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}}class b{get _useNodePages(){return this._pageSize>0}constructor(t,i,n,s,o,r,l,d,h,u,c,g,_,f,m,v){this.viewingMode=t,this._layer=i,this._streamDataController=s,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=l,this.holeFilling=d,this._isLoaded=h,this._isReloading=u,this._isSelected=c,this._enable=g,this._needsUpdate=_,this._canRequest=f,this._computeVisibilityObb=m,this._computeNodeFiltering=v,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=a.None,this._lodConversion=e=>e,this._isEditable=!1,this._urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=x(0),this._visibilityCacheVersion=x(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new y(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,this._init(n)}_init(e){if("page"===e.type){const t=e.rootPage;switch(this._urlPrefix=e.urlPrefix,this._pageSize=e.pageSize,e.lodMetric){case"maxScreenThreshold":this._lodMetric=a.MaxScreenThreshold;break;case"maxScreenThresholdSQ":this._lodMetric=a.MaxScreenThreshold,this._lodConversion=F}if(this._isEditable){this._rootIndex=-1;const i=E(e.rootIndex,e.pageSize),n=t.nodes[i],s={nodes:[{index:this._rootIndex,children:[e.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(w(this._rootIndex,this._pageSize),s),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=e.rootIndex;this._addPage(w(e.rootIndex,this._pageSize),t),this._updateParentsAndLevel()}else if("node"===e.type){this._urlPrefix=e.urlPrefix;const t=new p;if(this._nodePages.set(0,t),this._isEditable){this._clientNodePage=new p;const t={id:"-1",version:null,mbs:e.rootNode.mbs,obb:e.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:e.rootNode.mbs,obb:e.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new l(t.id,null),-1);const i=this._validateNode(t.id,t);i&&this._addNode(i,this._rootIndex)}else this._rootIndex=this._makeRefNode(new l(e.rootNode.id,null),-1);const i=this._validateNode(e.rootNode.id,e.rootNode);i&&this._addNode(i,0)}}addClientNodeToIndex(e,t){const i=-1,n=new l(e,t),s=this._makeClientRefNode(n,i);return this._linkChildToParentNode(i,s),this.requestUpdate(),s}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_loadPage(e){this._loadingPages.add(e);const i=this._urlPrefix+e;this._streamDataController.request(i,"json").then((t=>{this._pageQueue.push({pageIndex:e,page:t})})).catch((i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))}))}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach((e=>{let t=e.parent;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this.getParentIndex(t)}}))}}_addPage(e,t){const i=[],s=[],o=t.nodes.map(((t,o)=>{const r=i.length,a=t.children?t.children.length:0;s.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const l=`${t.index}`,h=v.fromJSON(t.obb),u=n(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,_=t.mesh?.material,f={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=_?.resource?`${_.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:_?_.definition:-1},m=new d(l,M(o,e,this._pageSize),u,a,0,f,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return m.serviceObbInIndexSR=h,m.visibilityObbInRenderSR=this._computeVisibilityObb(m),m.vertexCount=g?g.vertexCount:0,new N(r,a,P(this._visibilityCacheVersion),null,m)})),r=new p(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,n)=>{const s=this._getPage(t);if(null!=s){const o=E(t,this._pageSize),r=s.nodes[o];r.parent=null!=i?i:-1;const a=r.node;null!=a&&(a.level=n,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),n=this.getNode(i);if(null!=n)for(let e=0;e<n.childCount;e++){t(this.getChildIndex(n.index,e),i,n.level+1),this._maxLevel=Math.max(this._maxLevel,n.level+1)}}}_getPage(e){const t=w(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeInternal(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[E(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),n=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?n+1:n);const{lodMetric:s,maxError:o}=O(e.lodSelection),r=this._getNodeInternal(t),a=new d(e.id,t,e.mbs,r.childCount,n,e.resources,e.version,s,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=v.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const l=r.ref;return null!=l&&(null==l.serviceMbsInIndexSR&&(l.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const n=i.nodes.length,s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const n=-(i.nodes.length+1),s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const n=E(e,this._pageSize),s=E(t,this._pageSize),o=i.nodes[n],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const l of i.nodes)l.childOffset>r&&(l.childOffset+=a);i.nodes[s].parent=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const n=this._clientNodePage;if(null==n)return;const s=this.getParentIndex(e);if(null==s)return;const o=new Set,r=new Map,a=e=>{const i=E(e,this._pageSize),s=n.nodes[i];if(s.childCount>0)for(let t=s.childOffset;t<s.childOffset+s.childCount;++t)a(n.children[t]);const r=s.node?.id??s.ref?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(s)};a(e);const l=n.nodes,d=n.children,h=n.nodes.map((()=>-1)),u=[],c=[];for(let g=0;g<l.length;++g){const e=l[g];if(o.has(e))continue;const t=u.length,n=M(g,-1,this._pageSize),s=M(t,-1,this._pageSize);if(e.node&&(e.node.index=s),h[g]=s,u.push(e),n!==s){const t=e.node?.id??e.ref?.id;if(null==t)throw new Error("Node has no id");i(t,n,s),r.set(n,s)}}for(let g=0;g<u.length;++g){const e=M(g,-1,this._pageSize),t=u[g],i=c.length;for(let n=t.childOffset;n<t.childOffset+t.childCount;++n){const t=d[n];if(t>=0)c.push(t);else{const i=E(t,this._pageSize),n=l[i];if(o.has(n))continue;const s=h[i];c.push(s),n.parent=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}n.nodes=u,n.children=c,this._updateParentBoundingInformation(h[E(s,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,l=this._getNodeInternal(t);if(null==l)return;for(let o=0;o<l.childCount;o++){const l=this.getChildIndex(t,o),d=this._getNodeInternal(l),h=null!=d?d.ref||d.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=s(h.serviceMbsInIndexSR,D);else{const t=k,s=z,o=T;i(h.serviceMbsInIndexSR,n,t,a),i(e,n,s,a),r(t,s,o),i(o,a,e,n)}}const d=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),s(e,t.serviceMbsInIndexSR)):g(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};d(l.ref),d(l.node),this.invalidateNodeVisibilityCacheInternal(l),t=this.getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeInternal(e),n=this._getPage(e);i.childOffset=n.children.length,i.childCount=t.length;for(let s=0;s<t.length;s++){const i=this._makeRefNode(t[s],e);n.children.push(i)}}getNode(e){const t=this._getNodeInternal(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes(((i,n)=>{(null!=i.node&&i.node.id===e||null!=i.ref&&i.ref.id===e)&&(t=n)})),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const n=i.nodes[E(e,this._pageSize)];return i.children[n.childOffset+t]}getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[E(e,this._pageSize)]?.parent:null}getParent(e){const t=this.getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeInternal(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes((e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)}))}invalidateVisibilityCache(){this._visibilityCacheVersion=x(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeInternal(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=P(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeInternal(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeInternal(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.ref;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeInternal(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,(e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0)))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.ref;return!t||t.elevationRangeValid}updateElevationRange(e){this._updateElevationRangeInternal(e,null)}_updateElevationRangeInternal(e,t){const i=this._getNodeInternal(e);if(!i)return!1;const n=i?.node??i?.ref;if(!n)return!1;if(n.elevationRangeValid)return t?.expandElevationRange(n),!0;const s=new m;let o=!1;for(let l=0;l<i.childCount;l++){const t=this.getChildIndex(e,l),i=this._updateElevationRangeInternal(t,s);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(n,e,s)}const r=n.elevationRangeMin,a=n.elevationRangeMax;return r===s.elevationRangeMin&&a===s.elevationRangeMax?(t?.expandElevationRange(n),!0):(i.node?.setElevationRange(s),i.ref?.setElevationRange(s),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(n),!0)}isNodeVisible(e){const t=this._getNodeInternal(e);if(null==t)return!0;const i=t.ref;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&R(t.visibilityCache,this._visibilityCacheVersion))return C(t.visibilityCache);const n=t.node,s=this._viewportQueries;if(n){const e=s.ensureElevationAgnosticBoundingVolume(n),i=s.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=s.getNodeObbInRenderSRIndependentOfElevationOffset(n);null!=t&&(o=s.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=S(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=n||null!=i)&&t.filterImpact===h.NotChecked){const e=null!=n?n.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):h.Unmodified}const o=null!=n&&t.filterImpact===h.Culled;let r=!(null!=n&&n.imModificationImpact===u.Culled)&&!o;if(r){const t=!n||i&&!n.visibilityObbInRenderSR?i??null:n;if(null!=t){this.needNodeElevationRange&&this.updateElevationRange(e);r=s.isNodeVisible(t)}}return t.visibilityCache=S(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeInternal(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&t.node.imModificationImpact===u.NotChecked)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,n,s){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let l=t.childOffset;l<r;++l){const e=o.children[l],t=this._getNodeInternal(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}n/=a.length;for(const l of a){const e=l.node.index;this._isLoaded(e)||this._isReloading(e)?(s.delta=Math.max(s.delta,i),s.coverage+=n):this._traverseCoverage(e,l,i+1,n,s)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeInternal(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(R(t.useAsHole,this._version))return C(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const n=i.delta*i.coverage<=.5;return t.useAsHole=S(n,this._version),n}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.add.prune(),this._updates.update.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=x(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes((({node:e})=>{null!=e&&(e.imModificationImpact=u.NotChecked,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))})),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes((e=>{if(null!=e){e.filterImpact=h.NotChecked;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}})),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),I.clear();let n=!0;const s=new A,o=new L,r=this._imModificationUncategorized;r.clear();const a=new Set;let l=0;const d=(a,d,h)=>{const c=w(a,this._pageSize);if(null==d){let e=this._entryPriority(a);return e===1/0&&(e=this._entryPriority(h)),I.set(c,Math.max(e,I.get(c)||0)),this._loadingPages.has(c)||this._failedPages.has(c)||(this._missingPagesAndNodes.push(c),++l),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const g=d.node;if(this._updateNodeFeatureEstimate(g,o),null==g){const e=this._entryPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),I.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const _=this._getPage(a);if(0===this._missingPagesAndNodes.length&&!this._useNodePages)for(let e=0;e<d.childCount;e++){const t=_.children[d.childOffset+e],i=this._getNodeInternal(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(I.set(t,this._entryPriority(t)),this._prefetchNodes.push(t))}if(g.failed||g.resources.isEmpty)return void(n&&d.childCount>0&&this._isSelected(g)&&(n=!1));if(this._isLoaded(a)){if(s.known+=g.memory,++s.knownNodes,this._isSelected(g)?d.childCount>0&&(n=!1):(s.unremoved+=g.memory,n=!1),this._needsUpdate(g)){const e=this._entryPriority(a);I.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(g.memory&&(s.known+=g.memory,++s.knownNodes),!this._isSelected(g))return void(this._isReloading(a)&&this._updates.remove.push(a));if(d.childCount>0&&(n=!1),g.memory?(s.missing+=g.memory,s.known+=g.memory,++s.knownNodes):++s.missingNodes,e.includes(g.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(a)),void(this._updates.cancel=this._updates.cancel.filter((e=>e!==g.index)));if(!t.done&&this._enable(g))return void t.madeProgress();const f=this._entryPriority(a);I.set(a,f),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,f),this._updates.add.push(a),this.layerHasModifications&&i&&null!=g&&g.imModificationImpact===u.NotChecked&&r.push(a)};this.traverseVisible(d,a),this._frameNumber++,this._missingPagesAndNodes.sort(((e,t)=>e-t)),this._missingPagesAndNodes.filterInPlace(((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e)),this._missingPagesAndNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=I.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear()),this._removeUnusedNodePages(a,l);const h=this._updates.add;h.length>0&&this.layerHasModifications&&(r.length>0&&i?.(r),h.filterInPlace((e=>{const t=this._getNodeInternal(e),i=null==t?.node||t.node.imModificationImpact!==u.Culled;return i||this.invalidateNodeVisibilityCache(e),i}))),this._unloadedMemoryEstimate=s.missing-s.unremoved,s.knownNodes>3&&s.missingNodes>0&&(this._unloadedMemoryEstimate+=s.known/s.knownNodes*s.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=n,this._updates.add.filterInPlace((e=>I.get(e)>=this._maxUnloadedPrio)).sort(((e,t)=>I.get(e)-I.get(t))),this._updates.update.sort(((e,t)=>I.get(e)-I.get(t))),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,I.clear()}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let n=t,s=t,o=i,r=10;for(;r--;){const i=new L;this._updateFeatureEstimate(n,i);if(this._computeFeatureEstimate(i)<=e){if(n>=t||i.missingNodes>0||0===r)break;o=n,n=.5*(n+s)}else s=n,n=.5*(n+o)}return this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,n)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,n=this._nodePages,s=n.size+this._loadingPages.size+t;if(s>B&&s>i){const t=new Array;for(const[i,s]of n)0!==s.numNodesWithLoadedChildren||e.has(i)||t.push([s.lastTraversed,i]);t.sort(((e,t)=>e[0]-t[0])).some((e=>{const t=e[1];return this._deleteNodePage(t),n.size<=B}))}}_updateFeatureEstimate(e,t){this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible(((e,i)=>this._updateNodeFeatureEstimate(i?.node,t)))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._isSelected(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeInternal(t);if(!i)return null;let n=i?.traversalState;if(n&&R(n.version,this._version))return n;const s=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this.getParentIndex(t);if(null!=e){const t=this._getNodeInternal(e),i=t?.traversalState;r=!!i&&s>i.lodLevel}else r=s>0}else r=0===e.childCount;return n?(n.lodLevel=s,n.isChosen=r,n.version=S(!0,this._version),n):(n=new c(o,r,s,S(!0,this._version)),i.traversalState=n,n)}async _loadNode(e){this._loadingNodes.add(e);const i=this._getNodeInternal(e).ref;if(null==i)return void this._failedNodes.add(e);const n=i.id,s=this._urlPrefix+n,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};let r=null;try{r=e>=0?await this._streamDataController.request(s,"json"):await this._clientNodeLoader.loadNodeJSON(n)}catch(d){return o(),void(t(d)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+s),this._failedNodes.add(e)))}o();const a=this._validateNode(n,r);if(null==a)return;a.obb&&this.invalidateNodeVisibilityCache(e);const l=this._addNode(a,e);this.nodeTraversalState(l)}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const n=t.attributeData,s=this._layer.attributeStorageInfo;null==n||Array.isArray(n)&&!n.some(((e,t)=>e.href!==`./attributes/${s?.[t]?.key??`f_${t}`}/0`))||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,a=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const n=new l(`${t.id}`,t.mbs);return n.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?v.fromJSON(t.obb):null,n.visibilityObbInRenderSR=this._computeVisibilityObb(n),n},d=Array.isArray(t.children)?t.children.map(a).filter((e=>null!=e)):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new f(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},d,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes((e=>{null!=e.node&&(e.node.failed=!1)}))}_entryPriority(e){const t=this._getNodeInternal(e),i=this.getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._entryPriority(i);let n=0;if(t.node&&null!=i){const e=this._getNodeInternal(i).traversalState;null!=e&&(n=e.lodLevel)}let s=this.progressiveLoadPenalty;for(let r=e;null!=r;r=this.getParentIndex(r))if(this._isLoaded(r)){s=0;break}const o=null!=t.ref?this._viewportQueries.distToPOI(t.ref):null!=t.node?this._viewportQueries.distToPOI(t.node):0;return-o-n*(o+this.progressiveLoadPenalty)+s}traverseVisible(e,t){const i=this._getNodeInternal(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,n,s){const o=w(e,this._pageSize);if(s&&s.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&n(e,i,t));if(!this.isNodeVisible(e))return;if(n(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let l=0;l<i.childCount;l++){const t=a.children[i.childOffset+l],o=this._getNodeInternal(t);if(o)this._traverseVisible(t,e,o,n,s);else{if(s){const e=w(t,this._pageSize);s.add(e)}n(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,n=this._pageSize,s=w(i,n),o=this._getPageFromPageIndex(s);if(null==o)return;const r=this._frameNumber,a=this._nodePages,l=E(i,n),d=o.nodes[l],h=d.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=d,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let n=e;n<e+t;++n){const e=i[n];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let n=0;for(;n<u.length;){const s=u[n];++n;const o=-s-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:l}=r;if(0===l)continue;const{childOffset:d}=r,h=d+l;for(let e=d;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(n>0){let i=s*n,l=o,d=l.nodes;for(;e<g;){const s=c[e];let o;if(++e,i<=s&&s<i+n)o=l;else{const e=s/n|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,l=o,d=l.nodes,i=n*e}const h=d[s-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,N=v+_;for(let e=v;e<N;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const n=c[e++],s=i.nodes[n],o=s.node;if(!o||!t(o))continue;const{childCount:r}=s;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:l}=s,d=l+r;for(let e=l;e<d;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,n=e+t;i.childrenLoaded=n;const s=0===e?1:0===n?-1:0,o=i.index;if(0!==s){this._getPage(o).numNodesWithLoadedChildren+=s}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes((e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.ref?.invalidateElevationRange()}))}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const n=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],n+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible((e=>t.add(w(e,this._pageSize))));for(const[i,n]of e)if(0!==n.numNodesWithLoadedChildren||t.has(i))for(const e of n.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){this._nodePages.delete(e)}get test(){}}const I=new Map;class y{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function P(e){return _(e,-2)}function x(e){return _(e,2)}function S(e,t){return t+(e?1:0)}function R(e,t){return(-2&e)===t}function C(e){return!(1&~e)}function w(e,t){return e<0?-1:t>0?e/t|0:0}function E(e,t){return e<0?-e-1:0===t?e:e%t}function M(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const V=[["maxScreenThreshold",a.MaxScreenThreshold],["screenSpaceRelative",a.ScreenSpaceRelative],["removedFeatureDiameter",a.RemovedFeatureDiameter],["distanceRangeFromDefaultCamera",a.DistanceRangeFromDefaultCamera]];function O(e){if(e)for(let t=0;t<e.length;t++)for(const i of V)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:a.None,maxError:0}}class A{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class L{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function F(e){return Math.sqrt(e*(4/Math.PI))}const D=o(),k=o(),z=o(),T=o(),B=has("esri-mobile")?100:300;export{b as I3SIndex,O as selectErrorMetric};
5
+ import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{h as n,k as s,c as o,u as r}from"../../../../chunks/sphere.js";import{LodMetric as a,NodeBase as l,Node as d,NodeFilterImpact as h,NodeIMModificationImpact as u,NodeTraversalState as c}from"./I3SNode.js";import{invalidateMbs as g,addWraparound as _}from"./I3SUtil.js";import{ValidatedNode as f}from"./ValidatedNode.js";import{ElevationRange as m}from"../../support/ElevationRange.js";import{Obb as v}from"../../support/orientedBoundingBox.js";class N{constructor(e,t,i,n,s){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this.ref=n,this.node=s,this.useAsHole=0,this.filterImpact=h.NotChecked,this.traversalState=null,this.parent=-1}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.ref?.invalidateServiceBVsInRenderSR()}}class p{constructor(e=new Array,t=new Array){this.nodes=e,this.children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}}class b{get _useNodePages(){return this._pageSize>0}constructor(t,i,n,s,o,r,l,d,h,u,c,g,_,f,m,v){this.viewingMode=t,this._layer=i,this._streamDataController=s,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=l,this.holeFilling=d,this._isLoaded=h,this._isReloading=u,this._isSelected=c,this._enable=g,this._needsUpdate=_,this._canRequest=f,this._computeVisibilityObb=m,this._computeNodeFiltering=v,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=a.None,this._lodConversion=e=>e,this._isEditable=!1,this._urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=x(0),this._visibilityCacheVersion=x(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new y(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,this._init(n)}_init(e){if("page"===e.type){const t=e.rootPage;switch(this._urlPrefix=e.urlPrefix,this._pageSize=e.pageSize,e.lodMetric){case"maxScreenThreshold":this._lodMetric=a.MaxScreenThreshold;break;case"maxScreenThresholdSQ":this._lodMetric=a.MaxScreenThreshold,this._lodConversion=F}if(this._isEditable){this._rootIndex=-1;const i=E(e.rootIndex,e.pageSize),n=t.nodes[i],s={nodes:[{index:this._rootIndex,children:[e.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(w(this._rootIndex,this._pageSize),s),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=e.rootIndex;this._addPage(w(e.rootIndex,this._pageSize),t),this._updateParentsAndLevel()}else if("node"===e.type){this._urlPrefix=e.urlPrefix;const t=new p;if(this._nodePages.set(0,t),this._isEditable){this._clientNodePage=new p;const t={id:"-1",version:null,mbs:e.rootNode.mbs,obb:e.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:e.rootNode.mbs,obb:e.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new l(t.id,null),-1);const i=this._validateNode(t.id,t);i&&this._addNode(i,this._rootIndex)}else this._rootIndex=this._makeRefNode(new l(e.rootNode.id,null),-1);const i=this._validateNode(e.rootNode.id,e.rootNode);i&&this._addNode(i,0)}}addClientNodeToIndex(e,t){const i=-1,n=new l(e,t),s=this._makeClientRefNode(n,i);return this._linkChildToParentNode(i,s),this.requestUpdate(),s}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_loadPage(e){this._loadingPages.add(e);const i=this._urlPrefix+e;this._streamDataController.request(i,"json").then((t=>{this._pageQueue.push({pageIndex:e,page:t})})).catch((i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))}))}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach((e=>{let t=e.parent;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this.getParentIndex(t)}}))}}_addPage(e,t){const i=[],s=[],o=t.nodes.map(((t,o)=>{const r=i.length,a=t.children?t.children.length:0;s.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const l=`${t.index}`,h=v.fromJSON(t.obb),u=n(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,_=t.mesh?.material,f={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=_?.resource?`${_.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:_?_.definition:-1},m=new d(l,M(o,e,this._pageSize),u,a,0,f,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return m.serviceObbInIndexSR=h,m.visibilityObbInRenderSR=this._computeVisibilityObb(m),m.vertexCount=g?g.vertexCount:0,new N(r,a,P(this._visibilityCacheVersion),null,m)})),r=new p(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,n)=>{const s=this._getPage(t);if(null!=s){const o=E(t,this._pageSize),r=s.nodes[o];r.parent=null!=i?i:-1;const a=r.node;null!=a&&(a.level=n,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),n=this.getNode(i);if(null!=n)for(let e=0;e<n.childCount;e++){t(this.getChildIndex(n.index,e),i,n.level+1),this._maxLevel=Math.max(this._maxLevel,n.level+1)}}}_getPage(e){const t=w(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeInternal(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[E(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),n=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?n+1:n);const{lodMetric:s,maxError:o}=O(e.lodSelection),r=this._getNodeInternal(t),a=new d(e.id,t,e.mbs,r.childCount,n,e.resources,e.version,s,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=v.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const l=r.ref;return null!=l&&(null==l.serviceMbsInIndexSR&&(l.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const n=i.nodes.length,s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const n=-(i.nodes.length+1),s=new N(0,0,P(this._visibilityCacheVersion),e,null);return i.nodes.push(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const n=E(e,this._pageSize),s=E(t,this._pageSize),o=i.nodes[n],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const l of i.nodes)l.childOffset>r&&(l.childOffset+=a);i.nodes[s].parent=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const n=this._clientNodePage;if(null==n)return;const s=this.getParentIndex(e);if(null==s)return;const o=new Set,r=new Map,a=e=>{const i=E(e,this._pageSize),s=n.nodes[i];if(s.childCount>0)for(let t=s.childOffset;t<s.childOffset+s.childCount;++t)a(n.children[t]);const r=s.node?.id??s.ref?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(s)};a(e);const l=n.nodes,d=n.children,h=n.nodes.map((()=>-1)),u=[],c=[];for(let g=0;g<l.length;++g){const e=l[g];if(o.has(e))continue;const t=u.length,n=M(g,-1,this._pageSize),s=M(t,-1,this._pageSize);if(e.node&&(e.node.index=s),h[g]=s,u.push(e),n!==s){const t=e.node?.id??e.ref?.id;if(null==t)throw new Error("Node has no id");i(t,n,s),r.set(n,s)}}for(let g=0;g<u.length;++g){const e=M(g,-1,this._pageSize),t=u[g],i=c.length;for(let n=t.childOffset;n<t.childOffset+t.childCount;++n){const t=d[n];if(t>=0)c.push(t);else{const i=E(t,this._pageSize),n=l[i];if(o.has(n))continue;const s=h[i];c.push(s),n.parent=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}n.nodes=u,n.children=c,this._updateParentBoundingInformation(h[E(s,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,l=this._getNodeInternal(t);if(null==l)return;for(let o=0;o<l.childCount;o++){const l=this.getChildIndex(t,o),d=this._getNodeInternal(l),h=null!=d?d.ref||d.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=s(h.serviceMbsInIndexSR,D);else{const t=k,s=z,o=T;i(h.serviceMbsInIndexSR,n,t,a),i(e,n,s,a),r(t,s,o),i(o,a,e,n)}}const d=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),s(e,t.serviceMbsInIndexSR)):g(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};d(l.ref),d(l.node),this.invalidateNodeVisibilityCacheInternal(l),t=this.getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeInternal(e),n=this._getPage(e);i.childOffset=n.children.length,i.childCount=t.length;for(let s=0;s<t.length;s++){const i=this._makeRefNode(t[s],e);n.children.push(i)}}getNode(e){const t=this._getNodeInternal(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes(((i,n)=>{(null!=i.node&&i.node.id===e||null!=i.ref&&i.ref.id===e)&&(t=n)})),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const n=i.nodes[E(e,this._pageSize)];return i.children[n.childOffset+t]}getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[E(e,this._pageSize)]?.parent:null}getParent(e){const t=this.getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeInternal(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes((e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)}))}invalidateVisibilityCache(){this._visibilityCacheVersion=x(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeInternal(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=P(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeInternal(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeInternal(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.ref;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeInternal(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,(e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0)))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.ref;return!t||t.elevationRangeValid}updateElevationRange(e){this._updateElevationRangeInternal(e,null)}_updateElevationRangeInternal(e,t){const i=this._getNodeInternal(e);if(!i)return!1;const n=i?.node??i?.ref;if(!n)return!1;if(n.elevationRangeValid)return t?.expandElevationRange(n),!0;const s=new m;let o=!1;for(let l=0;l<i.childCount;l++){const t=this.getChildIndex(e,l),i=this._updateElevationRangeInternal(t,s);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(n,e,s)}const r=n.elevationRangeMin,a=n.elevationRangeMax;return r===s.elevationRangeMin&&a===s.elevationRangeMax?(t?.expandElevationRange(n),!0):(i.node?.setElevationRange(s),i.ref?.setElevationRange(s),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(n),!0)}isNodeVisible(e){const t=this._getNodeInternal(e);if(null==t)return!0;const i=t.ref;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&R(t.visibilityCache,this._visibilityCacheVersion))return C(t.visibilityCache);const n=t.node,s=this._viewportQueries;if(n){const e=s.ensureElevationAgnosticBoundingVolume(n),i=s.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=s.getNodeObbInRenderSRIndependentOfElevationOffset(n);null!=t&&(o=s.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=S(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=n||null!=i)&&t.filterImpact===h.NotChecked){const e=null!=n?n.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):h.Unmodified}const o=null!=n&&t.filterImpact===h.Culled;let r=!(null!=n&&n.imModificationImpact===u.Culled)&&!o;if(r){const t=!n||i&&!n.visibilityObbInRenderSR?i??null:n;if(null!=t){this.needNodeElevationRange&&this.updateElevationRange(e);r=s.isNodeVisible(t)}}return t.visibilityCache=S(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeInternal(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&t.node.imModificationImpact===u.NotChecked)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,n,s){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let l=t.childOffset;l<r;++l){const e=o.children[l],t=this._getNodeInternal(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}n/=a.length;for(const l of a){const e=l.node.index;this._isLoaded(e)||this._isReloading(e)?(s.delta=Math.max(s.delta,i),s.coverage+=n):this._traverseCoverage(e,l,i+1,n,s)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeInternal(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(R(t.useAsHole,this._version))return C(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const n=i.delta*i.coverage<=.5;return t.useAsHole=S(n,this._version),n}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.add.prune(),this._updates.update.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=x(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes((({node:e})=>{null!=e&&(e.imModificationImpact=u.NotChecked,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))})),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes((e=>{if(null!=e){e.filterImpact=h.NotChecked;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}})),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),I.clear();let n=!0;const s=new A,o=new L,r=this._imModificationUncategorized;r.clear();const a=new Set;let l=0;const d=(a,d,h)=>{const c=w(a,this._pageSize);if(null==d){let e=this._entryPriority(a);return e===1/0&&(e=this._entryPriority(h)),I.set(c,Math.max(e,I.get(c)||0)),this._loadingPages.has(c)||this._failedPages.has(c)||(this._missingPagesAndNodes.push(c),++l),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const g=d.node;if(this._updateNodeFeatureEstimate(g,o),null==g){const e=this._entryPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),I.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const _=this._getPage(a);if(0===this._missingPagesAndNodes.length&&!this._useNodePages)for(let e=0;e<d.childCount;e++){const t=_.children[d.childOffset+e],i=this._getNodeInternal(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(I.set(t,this._entryPriority(t)),this._prefetchNodes.push(t))}if(g.failed||g.resources.isEmpty)return void(n&&d.childCount>0&&this._isSelected(g)&&(n=!1));if(this._isLoaded(a)){if(s.known+=g.memory,++s.knownNodes,this._isSelected(g)?d.childCount>0&&(n=!1):(s.unremoved+=g.memory,n=!1),this._needsUpdate(g)){const e=this._entryPriority(a);I.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(g.memory&&(s.known+=g.memory,++s.knownNodes),!this._isSelected(g))return void(this._isReloading(a)&&this._updates.remove.push(a));if(d.childCount>0&&(n=!1),g.memory?(s.missing+=g.memory,s.known+=g.memory,++s.knownNodes):++s.missingNodes,e.includes(g.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(a)),void(this._updates.cancel=this._updates.cancel.filter((e=>e!==g.index)));if(!t.done&&this._enable(g))return void t.madeProgress();const f=this._entryPriority(a);I.set(a,f),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,f),this._updates.add.push(a),this.layerHasModifications&&i&&null!=g&&g.imModificationImpact===u.NotChecked&&r.push(a)};this.traverseVisible(d,a),this._frameNumber++,this._missingPagesAndNodes.sort(((e,t)=>e-t)),this._missingPagesAndNodes.filterInPlace(((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e)),this._missingPagesAndNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=I.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear()),this._removeUnusedNodePages(a,l);const h=this._updates.add;h.length>0&&this.layerHasModifications&&(r.length>0&&i?.(r),h.filterInPlace((e=>{const t=this._getNodeInternal(e),i=null==t?.node||t.node.imModificationImpact!==u.Culled;return i||this.invalidateNodeVisibilityCache(e),i}))),this._unloadedMemoryEstimate=s.missing-s.unremoved,s.knownNodes>3&&s.missingNodes>0&&(this._unloadedMemoryEstimate+=s.known/s.knownNodes*s.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=n,this._updates.add.filterInPlace((e=>I.get(e)>=this._maxUnloadedPrio)).sort(((e,t)=>I.get(e)-I.get(t))),this._updates.update.sort(((e,t)=>I.get(e)-I.get(t))),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,I.clear()}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let n=t,s=t,o=i,r=10;for(;r--;){const i=new L;this._updateFeatureEstimate(n,i);if(this._computeFeatureEstimate(i)<=e){if(n>=t||i.missingNodes>0||0===r)break;o=n,n=.5*(n+s)}else s=n,n=.5*(n+o)}return this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,n)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,n=this._nodePages,s=n.size+this._loadingPages.size+t;if(s>B&&s>i){const t=new Array;for(const[i,s]of n)0!==s.numNodesWithLoadedChildren||e.has(i)||t.push([s.lastTraversed,i]);t.sort(((e,t)=>e[0]-t[0])).some((e=>{const t=e[1];return this._deleteNodePage(t),n.size<=B}))}}_updateFeatureEstimate(e,t){this._version=x(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible(((e,i)=>this._updateNodeFeatureEstimate(i?.node,t)))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._isSelected(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort(((e,t)=>I.get(e)-I.get(t))),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeInternal(t);if(!i)return null;let n=i?.traversalState;if(n&&R(n.version,this._version))return n;const s=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this.getParentIndex(t);if(null!=e){const t=this._getNodeInternal(e),i=t?.traversalState;r=!!i&&s>i.lodLevel}else r=s>0}else r=0===e.childCount;return n?(n.lodLevel=s,n.isChosen=r,n.version=S(!0,this._version),n):(n=new c(o,r,s,S(!0,this._version)),i.traversalState=n,n)}async _loadNode(e){this._loadingNodes.add(e);const i=this._getNodeInternal(e).ref;if(null==i)return void this._failedNodes.add(e);const n=i.id,s=this._urlPrefix+n,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};let r=null;try{r=e>=0?await this._streamDataController.request(s,"json"):await this._clientNodeLoader.loadNodeJSON(n)}catch(d){return o(),void(t(d)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+s),this._failedNodes.add(e)))}o();const a=this._validateNode(n,r);if(null==a)return;a.obb&&this.invalidateNodeVisibilityCache(e);const l=this._addNode(a,e);this.nodeTraversalState(l)}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const n=t.attributeData,s=this._layer.attributeStorageInfo;null==n||Array.isArray(n)&&!n.some(((e,t)=>e.href!==`./attributes/${s?.[t]?.key??`f_${t}`}/0`))||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,a=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const n=new l(`${t.id}`,t.mbs);return n.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?v.fromJSON(t.obb):null,n.visibilityObbInRenderSR=this._computeVisibilityObb(n),n},d=Array.isArray(t.children)?t.children.map(a).filter((e=>null!=e)):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new f(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},d,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes((e=>{null!=e.node&&(e.node.failed=!1)}))}_entryPriority(e){const t=this._getNodeInternal(e),i=this.getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._entryPriority(i);let n=0;if(t.node&&null!=i){const e=this._getNodeInternal(i).traversalState;null!=e&&(n=e.lodLevel)}let s=this.progressiveLoadPenalty;for(let r=e;null!=r;r=this.getParentIndex(r))if(this._isLoaded(r)){s=0;break}const o=null!=t.ref?this._viewportQueries.distToPOI(t.ref):null!=t.node?this._viewportQueries.distToPOI(t.node):0;return-o-n*(o+this.progressiveLoadPenalty)+s}traverseVisible(e,t){const i=this._getNodeInternal(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,n,s){const o=w(e,this._pageSize);if(s&&s.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&n(e,i,t));if(!this.isNodeVisible(e))return;if(n(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let l=0;l<i.childCount;l++){const t=a.children[i.childOffset+l],o=this._getNodeInternal(t);if(o)this._traverseVisible(t,e,o,n,s);else{if(s){const e=w(t,this._pageSize);s.add(e)}n(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,n=this._pageSize,s=w(i,n),o=this._getPageFromPageIndex(s);if(null==o)return;const r=this._frameNumber,a=this._nodePages,l=E(i,n),d=o.nodes[l],h=d.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=d,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let n=e;n<e+t;++n){const e=i[n];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let n=0;for(;n<u.length;){const s=u[n];++n;const o=-s-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:l}=r;if(0===l)continue;const{childOffset:d}=r,h=d+l;for(let e=d;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(n>0){let i=s*n,l=o,d=l.nodes;for(;e<g;){const s=c[e];let o;if(++e,i<=s&&s<i+n)o=l;else{const e=s/n|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,l=o,d=l.nodes,i=n*e}const h=d[s-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,N=v+_;for(let e=v;e<N;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const n=c[e++],s=i.nodes[n],o=s.node;if(!o||!t(o))continue;const{childCount:r}=s;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:l}=s,d=l+r;for(let e=l;e<d;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,n=e+t;i.childrenLoaded=n;const s=0===e?1:0===n?-1:0,o=i.index;if(0!==s){this._getPage(o).numNodesWithLoadedChildren+=s}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes((e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.ref?.invalidateElevationRange()}))}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const n=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],n+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible((e=>t.add(w(e,this._pageSize))));for(const[i,n]of e)if(0!==n.numNodesWithLoadedChildren||t.has(i))for(const e of n.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){this._nodePages.delete(e)}get test(){}}const I=new Map;class y{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function P(e){return _(e,-2)}function x(e){return _(e,2)}function S(e,t){return t+(e?1:0)}function R(e,t){return(-2&e)===t}function C(e){return!(1&~e)}function w(e,t){return e<0?-1:t>0?e/t|0:0}function E(e,t){return e<0?-e-1:0===t?e:e%t}function M(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const V=[["maxScreenThreshold",a.MaxScreenThreshold],["screenSpaceRelative",a.ScreenSpaceRelative],["removedFeatureDiameter",a.RemovedFeatureDiameter],["distanceRangeFromDefaultCamera",a.DistanceRangeFromDefaultCamera]];function O(e){if(e)for(let t=0;t<e.length;t++)for(const i of V)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:a.None,maxError:0}}class A{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class L{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function F(e){return Math.sqrt(e*(4/Math.PI))}const D=o(),k=o(),z=o(),T=o(),B=has("esri-mobile")?100:300;export{b as I3SIndex,O as selectErrorMetric};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../../../chunks/tslib.es6.js";import{neverReached as e}from"../../../../core/compilerUtils.js";import{clamp as i,acosClamped as a,deg2rad as r}from"../../../../core/mathUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as s}from"../../../../core/accessorSupport/decorators/subclass.js";import{translate as n,rotate as c,identity as m}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d as h,t as p,f as d,g as u,c as _,u as f,l as v,i as C,n as g,h as y,j as w,E as O,e as b}from"../../../../chunks/vec32.js";import{create as S}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as x}from"../../../../geometry/ellipsoidUtils.js";import{wrap as j}from"../../../../geometry/support/ray.js";import{j as L,b as M,t as A}from"../../../../chunks/sphere.js";import{angle as T}from"../../../../geometry/support/vector.js";import{sv3d as E}from"../../../../geometry/support/vectorStacks.js";import{applyAll as z}from"../../camera/constraintUtils.js";import{ConstraintOptions as I}from"../../camera/constraintUtils/ConstraintOptions.js";import{ConstraintTypes as D}from"../../camera/constraintUtils/ConstraintTypes.js";import{InteractionType as R}from"../../camera/constraintUtils/InteractionType.js";import{TiltMode as U}from"../../camera/constraintUtils/TiltMode.js";import{TiltRange as k}from"../Constraints.js";import{InteractiveController as H}from"./InteractiveController.js";import{panMotionToRotationMatrix as N,onSurfaceTiltToEyeTiltGlobal as P,offSurfaceTiltToEyeTiltGlobal as G}from"../utils/navigationUtils.js";import{viewAngle as F}from"../utils/viewUtils.js";import{headingTiltToDirectionUp as B}from"../../support/cameraUtils.js";import{createDirectionUp as V}from"../../support/cameraUtilsInternal.js";import K from"../../webgl/RenderCamera.js";import{extractTransformation as X,isZeroTransformation as Z,extractTransformationKeyboard as q}from"../../../navigation/gamepadAndKeyboardUtils.js";let J=class extends H{constructor(t){super(t),this._filteredSurfaceElevation=0,this._transformation={translation:[0,0,0],heading:0,tilt:0,zoom:0},this._keysButtonState=[0,0,0,0,0,0,0,0,0,0,0,0],this._tmpCamera=new K,this._headingStart=0,this._constraintOptions=new I(D.ALL,R.NONE,0,new K,null,U.LOOK_AROUND)}handleEventGamepad(t){const e=X(t,this.view.navigation.gamepad,this._transformation);("end"===t.action||Z(e))&&this.finishController()}activateDirection(t){this._keysButtonState[t]=1,q(this._keysButtonState,this._transformation)}directionActive(t){return 1===this._keysButtonState[t]}countActiveDirections(){return this._keysButtonState.reduce(((t,e)=>e>0?t+1:t),0)}deactivateDirection(t){this._keysButtonState[t]=0;const e=q(this._keysButtonState,this._transformation);Z(e)&&this.finishController()}onControllerStart(t){this._filteredSurfaceElevation=this.view.pointsOfInterest.cameraOnSurface.location.z,this._headingStart=this.view.camera.heading,super.onControllerStart(t)}_updateFilteredSurfaceElevation(t){const e=this.view.pointsOfInterest.cameraOnSurface.location.z,i=1;this._filteredSurfaceElevation+=i*(e-this._filteredSurfaceElevation)*t}stepController(t,e){this._updateStartHeading(),this._updateFilteredSurfaceElevation(t),this.currentCamera.copyViewFrom(e),this._updateCameraCenter(),this._constraintOptions.interactionStartCamera?.copyFrom(this.currentCamera),this._calculateControlTransformation(t,this.currentCamera,at),this._applyDisabledMovementTypes(at),this._applyPan(at.pan),this._applyRotate(at.rotate),this._applyZoom(at.zoom),this._applyAscend(at.ascend),this._constraintOptions.interactionType=R.NONE,this._constraintOptions.selection=D.COLLISION,z(this.view,this.currentCamera,this._constraintOptions),super.stepController(t,e)}_updateStartHeading(){0!==this._transformation.heading&&(this._headingStart=this.view.camera.heading)}_applyRotate(t){if(!t.enabled)return;const e=this.currentCamera;h(rt,e.center,e.eye),p(rt,rt,t.matrix),e.center=d(rt,rt,e.eye),e.up=p(rt,e.up,t.matrix),this._constraintOptions.interactionType=R.LOOK_AROUND,this._constraintOptions.selection=D.ALL_EXCEPT_COLLISION,z(this.view,e,this._constraintOptions)}_applyPan(t,e=this.currentCamera){if(!t.enabled)return;e.eye=p(rt,e.eye,t.matrix),e.center=p(rt,e.center,t.matrix);this.view.state.isGlobal&&(e.up=p(rt,e.up,t.matrix)),this._constraintOptions.interactionType=R.PAN,this._constraintOptions.selection=D.ALL,z(this.view,e,this._constraintOptions)}_applyZoom(t){if(!t)return;const e=this.currentCamera.viewForward;this.currentCamera.eye=d(rt,this.currentCamera.eye,u(E.get(),e,t)),_(ot,e),f(ot,ot),this._constraintOptions.interactionDirection=ot,this._constraintOptions.interactionType=R.ZOOM,this._constraintOptions.selection=D.ALL_EXCEPT_COLLISION,z(this.view,this.currentCamera,this._constraintOptions),this._constraintOptions.interactionDirection=null}_applyAscend(t){if(!t)return;const e=this.view.renderCoordsHelper.worldUpAtPosition(this.currentCamera.eye,E.get());this._constraintOptions.interactionDirection=_(ot,e);if(this.view.state.isGlobal){const e=v(this.currentCamera.eye),i=(e+t)/e;this.currentCamera.eye=u(rt,this.currentCamera.eye,i),this.currentCamera.center=u(rt,this.currentCamera.center,i)}else{const i=u(E.get(),e,t);this.currentCamera.eye=d(rt,this.currentCamera.eye,i),this.currentCamera.center=d(rt,this.currentCamera.center,i)}this._updateCameraCenter(),this._constraintOptions.interactionType=R.ASCEND,this._constraintOptions.selection=D.COLLISION,z(this.view,this.currentCamera,this._constraintOptions)&&this._updateCameraCenter(),this._constraintOptions.selection=D.ALL_EXCEPT_COLLISION,z(this.view,this.currentCamera,this._constraintOptions),this._constraintOptions.interactionDirection=null}_calculateControlTransformation(t,e,i){nt(i);const a=this._computeVelocities(t);this.view.state.isLocal?this._calculateControlTransformationLocal(a,e,i):this._calculateControlTransformationGlobal(a,e,i)}_updateCameraCenter(){const t=this.view.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude,e=this.view.renderCoordsHelper,i=this.currentCamera.ray;this.currentCamera.center=e.intersectManifoldClosestSilhouette(i,t,rt)}_calculateControlTransformationLocal(t,a,r){const{viewRight:o,viewForward:s}=a,m=this._transformation,l=this.view.navigation.gamepad,h=C(E.get(),s[0],s[1],0);g(h,h);const p=m.translation[0]*t.pan;if(0!==p){const t=u(E.get(),o,p);n(r.pan.matrix,r.pan.matrix,t),r.pan.enabled=!0}switch(l.mode){case"pan":{const e=-m.translation[1]*t.pan;if(0!==e){const t=u(E.get(),h,e);n(r.pan.matrix,r.pan.matrix,t),r.pan.enabled=!0}r.zoom=m.zoom*t.zoom;break}case"zoom":r.zoom=(-m.translation[1]+m.zoom)*t.zoom;break;default:e(l.mode)}const d=m.translation[2]*t.ascend;r.ascend=d;const _=-m.heading*t.rotate;0!==_&&(c(r.rotate.matrix,r.rotate.matrix,_,this.view.renderCoordsHelper.worldUpAtPosition(a.eye,E.get())),r.rotate.enabled=!0);const f=m.tilt*t.rotate,v=F(this.view.renderCoordsHelper,a.center,a.eye),y=i(v+f,k.min,k.max)-v;y&&(c(r.rotate.matrix,r.rotate.matrix,y,o),r.rotate.enabled=!0)}_calculateControlTransformationGlobal(t,e,i){const{eye:a,viewRight:r}=e,o=this._transformation,s=this.view.navigation.gamepad,n=y(E.get(),r,a);g(n,n),f(n,n),N(this.startCamera,e,o,t,this.view.camera.heading,this._headingStart,this.view.camera.tilt,i,s),this._tmpCamera.copyFrom(this.currentCamera),this._applyPan(at.pan,this._tmpCamera);const m=this.view.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude,l=o.translation[2]*t.ascend;i.ascend=l;const h=-o.heading*t.rotate;0!==h&&(c(i.rotate.matrix,i.rotate.matrix,h,this._tmpCamera.eye),i.rotate.enabled=!0);const p=o.tilt*t.rotate,d=this._clampTiltDeltaGlobalToValidRange(p,e.ray,m);0!==d&&(c(i.rotate.matrix,i.rotate.matrix,d,this._tmpCamera.viewRight),i.rotate.enabled=!0),i.zoom+=o.zoom*t.zoom}_clampTiltDeltaGlobalToValidRange(t,e,a){const r=x(this.view.spatialReference),o=P(k.min,e.origin,a,r);let s=0,n=0;const c=E.get();if(this.view.renderCoordsHelper.intersectManifold(e,a,c)){const t=F(this.view.renderCoordsHelper,c,e.origin);s=P(t,e.origin,a,r),n=P(k.max,e.origin,a,r)}else{L(M(A,a+r.radius),e,c);const t=Math.PI+T(e.direction,c);s=G(t,e.origin,a,r),n=G(k.max,e.origin,a,r)}return i(s+t,o,n)-s}_getPointAbsoluteSurfaceElevation(t,e,i){const{renderCoordsHelper:a}=this.view,r=a.getAltitude(t),o=e+Math.abs(r-e);return a.setAltitude(i,o,t),o}_clampedDistanceToSurface(t,e){const{renderCoordsHelper:i}=this.view,{camera:a}=this.view.state,{direction:r}=B(this.view,e,0,W,st),o=i.intersectManifoldClosestSilhouette(j(e,r),t,E.get()),s=w(e,o),n=i.intersectManifoldClosestSilhouette(j(e,O(E.get(),e,a.center)),t,E.get()),c=w(e,n);return Math.min(s,c)}_computeHeadingRotateRadius(t){const{renderCoordsHelper:e,state:i}=this.view,{camera:r,isGlobal:o}=i,s=e.intersectManifoldClosestSilhouette(r.ray,this._filteredSurfaceElevation,E.get());if(o){const e=h(E.get(),t,s),i=v(e);u(e,e,1/i);const r=g(E.get(),t),o=a(b(r,e));return i*Math.sin(Math.min(Y,o))}{const i=_(E.get(),t);return e.setAltitude(i,this._filteredSurfaceElevation),w(s,i)}}_minimumAscendVelocity(){return this.view.state.constraints.collision.enabled?0:tt}_computeVelocities(t){const e=this._filteredSurfaceElevation,a=e+x(this.view.spatialReference).radius,{camera:r,isGlobal:o}=this.view.state,s=E.get(),n=this._getPointAbsoluteSurfaceElevation(r.eye,e,s),c=this._clampedDistanceToSurface(e,s),m=r.width/2,l=$*r.width,h=$*r.width,p=c*Math.tan(.5*r.fovX)/m,d=p/a,u=p/this._computeHeadingRotateRadius(s),_=n-e;return{pan:(o?d:p)*l*t,ascend:Math.max(this._minimumAscendVelocity()*t,2**(l*t/m)*_-_),zoom:2**(l*t/m)*c-c,rotate:i(u*h,et,it)*t}}_applyDisabledMovementTypes(t){null==this.disableMovements||void 0!==this.disableMovements.mode&&this.view.state.viewingMode!==this.disableMovements.mode||(t.zoom=this.disableMovements.zoom?0:t.zoom,t.ascend=this.disableMovements.ascend?0:t.ascend,t.pan.enabled=!this.disableMovements.pan,this.disableMovements.pan&&m(t.pan.matrix),t.rotate.enabled=!this.disableMovements.rotate,this.disableMovements.rotate&&m(t.rotate.matrix))}static activatesFor(t,e){const i=X(e,t.navigation.gamepad,Q);return!("end"===e.action||Z(i))}};t([o({constructOnly:!0})],J.prototype,"gamepadDevice",void 0),t([o({constructOnly:!0})],J.prototype,"disableMovements",void 0),J=t([s("esri.views.3d.state.controllers.GamepadKeyboardController")],J);const Q={translation:[0,0,0],heading:0,tilt:0,zoom:0},W=80,Y=r(W),$=.75,tt=5,et=r(30),it=r(80),at={zoom:0,ascend:0,pan:{enabled:!1,matrix:l()},rotate:{enabled:!1,matrix:l()}},rt=S(),ot=S(),st=V();function nt(t){t.zoom=0,t.ascend=0,t.pan.enabled=!1,m(t.pan.matrix),t.rotate.enabled=!1,m(t.rotate.matrix)}export{J as GamepadKeyboardController};
5
+ import{_ as t}from"../../../../chunks/tslib.es6.js";import{neverReached as e}from"../../../../core/compilerUtils.js";import{clamp as i,acosClamped as a,deg2rad as r}from"../../../../core/mathUtils.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as s}from"../../../../core/accessorSupport/decorators/subclass.js";import{translate as n,rotate as c,identity as m}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{d as h,t as p,f as d,g as u,c as _,u as f,l as v,i as C,n as g,h as y,j as w,E as O,e as b}from"../../../../chunks/vec32.js";import{create as S}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as x}from"../../../../geometry/ellipsoidUtils.js";import{wrap as j}from"../../../../geometry/support/ray.js";import{m as L,b as M,t as A}from"../../../../chunks/sphere.js";import{angle as T}from"../../../../geometry/support/vector.js";import{sv3d as E}from"../../../../geometry/support/vectorStacks.js";import{applyAll as z}from"../../camera/constraintUtils.js";import{ConstraintOptions as I}from"../../camera/constraintUtils/ConstraintOptions.js";import{ConstraintTypes as D}from"../../camera/constraintUtils/ConstraintTypes.js";import{InteractionType as R}from"../../camera/constraintUtils/InteractionType.js";import{TiltMode as U}from"../../camera/constraintUtils/TiltMode.js";import{TiltRange as k}from"../Constraints.js";import{InteractiveController as H}from"./InteractiveController.js";import{panMotionToRotationMatrix as N,onSurfaceTiltToEyeTiltGlobal as P,offSurfaceTiltToEyeTiltGlobal as G}from"../utils/navigationUtils.js";import{viewAngle as F}from"../utils/viewUtils.js";import{headingTiltToDirectionUp as B}from"../../support/cameraUtils.js";import{createDirectionUp as V}from"../../support/cameraUtilsInternal.js";import K from"../../webgl/RenderCamera.js";import{extractTransformation as X,isZeroTransformation as Z,extractTransformationKeyboard as q}from"../../../navigation/gamepadAndKeyboardUtils.js";let J=class extends H{constructor(t){super(t),this._filteredSurfaceElevation=0,this._transformation={translation:[0,0,0],heading:0,tilt:0,zoom:0},this._keysButtonState=[0,0,0,0,0,0,0,0,0,0,0,0],this._tmpCamera=new K,this._headingStart=0,this._constraintOptions=new I(D.ALL,R.NONE,0,new K,null,U.LOOK_AROUND)}handleEventGamepad(t){const e=X(t,this.view.navigation.gamepad,this._transformation);("end"===t.action||Z(e))&&this.finishController()}activateDirection(t){this._keysButtonState[t]=1,q(this._keysButtonState,this._transformation)}directionActive(t){return 1===this._keysButtonState[t]}countActiveDirections(){return this._keysButtonState.reduce(((t,e)=>e>0?t+1:t),0)}deactivateDirection(t){this._keysButtonState[t]=0;const e=q(this._keysButtonState,this._transformation);Z(e)&&this.finishController()}onControllerStart(t){this._filteredSurfaceElevation=this.view.pointsOfInterest.cameraOnSurface.location.z,this._headingStart=this.view.camera.heading,super.onControllerStart(t)}_updateFilteredSurfaceElevation(t){const e=this.view.pointsOfInterest.cameraOnSurface.location.z,i=1;this._filteredSurfaceElevation+=i*(e-this._filteredSurfaceElevation)*t}stepController(t,e){this._updateStartHeading(),this._updateFilteredSurfaceElevation(t),this.currentCamera.copyViewFrom(e),this._updateCameraCenter(),this._constraintOptions.interactionStartCamera?.copyFrom(this.currentCamera),this._calculateControlTransformation(t,this.currentCamera,at),this._applyDisabledMovementTypes(at),this._applyPan(at.pan),this._applyRotate(at.rotate),this._applyZoom(at.zoom),this._applyAscend(at.ascend),this._constraintOptions.interactionType=R.NONE,this._constraintOptions.selection=D.COLLISION,z(this.view,this.currentCamera,this._constraintOptions),super.stepController(t,e)}_updateStartHeading(){0!==this._transformation.heading&&(this._headingStart=this.view.camera.heading)}_applyRotate(t){if(!t.enabled)return;const e=this.currentCamera;h(rt,e.center,e.eye),p(rt,rt,t.matrix),e.center=d(rt,rt,e.eye),e.up=p(rt,e.up,t.matrix),this._constraintOptions.interactionType=R.LOOK_AROUND,this._constraintOptions.selection=D.ALL_EXCEPT_COLLISION,z(this.view,e,this._constraintOptions)}_applyPan(t,e=this.currentCamera){if(!t.enabled)return;e.eye=p(rt,e.eye,t.matrix),e.center=p(rt,e.center,t.matrix);this.view.state.isGlobal&&(e.up=p(rt,e.up,t.matrix)),this._constraintOptions.interactionType=R.PAN,this._constraintOptions.selection=D.ALL,z(this.view,e,this._constraintOptions)}_applyZoom(t){if(!t)return;const e=this.currentCamera.viewForward;this.currentCamera.eye=d(rt,this.currentCamera.eye,u(E.get(),e,t)),_(ot,e),f(ot,ot),this._constraintOptions.interactionDirection=ot,this._constraintOptions.interactionType=R.ZOOM,this._constraintOptions.selection=D.ALL_EXCEPT_COLLISION,z(this.view,this.currentCamera,this._constraintOptions),this._constraintOptions.interactionDirection=null}_applyAscend(t){if(!t)return;const e=this.view.renderCoordsHelper.worldUpAtPosition(this.currentCamera.eye,E.get());this._constraintOptions.interactionDirection=_(ot,e);if(this.view.state.isGlobal){const e=v(this.currentCamera.eye),i=(e+t)/e;this.currentCamera.eye=u(rt,this.currentCamera.eye,i),this.currentCamera.center=u(rt,this.currentCamera.center,i)}else{const i=u(E.get(),e,t);this.currentCamera.eye=d(rt,this.currentCamera.eye,i),this.currentCamera.center=d(rt,this.currentCamera.center,i)}this._updateCameraCenter(),this._constraintOptions.interactionType=R.ASCEND,this._constraintOptions.selection=D.COLLISION,z(this.view,this.currentCamera,this._constraintOptions)&&this._updateCameraCenter(),this._constraintOptions.selection=D.ALL_EXCEPT_COLLISION,z(this.view,this.currentCamera,this._constraintOptions),this._constraintOptions.interactionDirection=null}_calculateControlTransformation(t,e,i){nt(i);const a=this._computeVelocities(t);this.view.state.isLocal?this._calculateControlTransformationLocal(a,e,i):this._calculateControlTransformationGlobal(a,e,i)}_updateCameraCenter(){const t=this.view.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude,e=this.view.renderCoordsHelper,i=this.currentCamera.ray;this.currentCamera.center=e.intersectManifoldClosestSilhouette(i,t,rt)}_calculateControlTransformationLocal(t,a,r){const{viewRight:o,viewForward:s}=a,m=this._transformation,l=this.view.navigation.gamepad,h=C(E.get(),s[0],s[1],0);g(h,h);const p=m.translation[0]*t.pan;if(0!==p){const t=u(E.get(),o,p);n(r.pan.matrix,r.pan.matrix,t),r.pan.enabled=!0}switch(l.mode){case"pan":{const e=-m.translation[1]*t.pan;if(0!==e){const t=u(E.get(),h,e);n(r.pan.matrix,r.pan.matrix,t),r.pan.enabled=!0}r.zoom=m.zoom*t.zoom;break}case"zoom":r.zoom=(-m.translation[1]+m.zoom)*t.zoom;break;default:e(l.mode)}const d=m.translation[2]*t.ascend;r.ascend=d;const _=-m.heading*t.rotate;0!==_&&(c(r.rotate.matrix,r.rotate.matrix,_,this.view.renderCoordsHelper.worldUpAtPosition(a.eye,E.get())),r.rotate.enabled=!0);const f=m.tilt*t.rotate,v=F(this.view.renderCoordsHelper,a.center,a.eye),y=i(v+f,k.min,k.max)-v;y&&(c(r.rotate.matrix,r.rotate.matrix,y,o),r.rotate.enabled=!0)}_calculateControlTransformationGlobal(t,e,i){const{eye:a,viewRight:r}=e,o=this._transformation,s=this.view.navigation.gamepad,n=y(E.get(),r,a);g(n,n),f(n,n),N(this.startCamera,e,o,t,this.view.camera.heading,this._headingStart,this.view.camera.tilt,i,s),this._tmpCamera.copyFrom(this.currentCamera),this._applyPan(at.pan,this._tmpCamera);const m=this.view.pointsOfInterest.centerOnSurfaceFrequent.estimatedSurfaceAltitude,l=o.translation[2]*t.ascend;i.ascend=l;const h=-o.heading*t.rotate;0!==h&&(c(i.rotate.matrix,i.rotate.matrix,h,this._tmpCamera.eye),i.rotate.enabled=!0);const p=o.tilt*t.rotate,d=this._clampTiltDeltaGlobalToValidRange(p,e.ray,m);0!==d&&(c(i.rotate.matrix,i.rotate.matrix,d,this._tmpCamera.viewRight),i.rotate.enabled=!0),i.zoom+=o.zoom*t.zoom}_clampTiltDeltaGlobalToValidRange(t,e,a){const r=x(this.view.spatialReference),o=P(k.min,e.origin,a,r);let s=0,n=0;const c=E.get();if(this.view.renderCoordsHelper.intersectManifold(e,a,c)){const t=F(this.view.renderCoordsHelper,c,e.origin);s=P(t,e.origin,a,r),n=P(k.max,e.origin,a,r)}else{L(M(A,a+r.radius),e,c);const t=Math.PI+T(e.direction,c);s=G(t,e.origin,a,r),n=G(k.max,e.origin,a,r)}return i(s+t,o,n)-s}_getPointAbsoluteSurfaceElevation(t,e,i){const{renderCoordsHelper:a}=this.view,r=a.getAltitude(t),o=e+Math.abs(r-e);return a.setAltitude(i,o,t),o}_clampedDistanceToSurface(t,e){const{renderCoordsHelper:i}=this.view,{camera:a}=this.view.state,{direction:r}=B(this.view,e,0,W,st),o=i.intersectManifoldClosestSilhouette(j(e,r),t,E.get()),s=w(e,o),n=i.intersectManifoldClosestSilhouette(j(e,O(E.get(),e,a.center)),t,E.get()),c=w(e,n);return Math.min(s,c)}_computeHeadingRotateRadius(t){const{renderCoordsHelper:e,state:i}=this.view,{camera:r,isGlobal:o}=i,s=e.intersectManifoldClosestSilhouette(r.ray,this._filteredSurfaceElevation,E.get());if(o){const e=h(E.get(),t,s),i=v(e);u(e,e,1/i);const r=g(E.get(),t),o=a(b(r,e));return i*Math.sin(Math.min(Y,o))}{const i=_(E.get(),t);return e.setAltitude(i,this._filteredSurfaceElevation),w(s,i)}}_minimumAscendVelocity(){return this.view.state.constraints.collision.enabled?0:tt}_computeVelocities(t){const e=this._filteredSurfaceElevation,a=e+x(this.view.spatialReference).radius,{camera:r,isGlobal:o}=this.view.state,s=E.get(),n=this._getPointAbsoluteSurfaceElevation(r.eye,e,s),c=this._clampedDistanceToSurface(e,s),m=r.width/2,l=$*r.width,h=$*r.width,p=c*Math.tan(.5*r.fovX)/m,d=p/a,u=p/this._computeHeadingRotateRadius(s),_=n-e;return{pan:(o?d:p)*l*t,ascend:Math.max(this._minimumAscendVelocity()*t,2**(l*t/m)*_-_),zoom:2**(l*t/m)*c-c,rotate:i(u*h,et,it)*t}}_applyDisabledMovementTypes(t){null==this.disableMovements||void 0!==this.disableMovements.mode&&this.view.state.viewingMode!==this.disableMovements.mode||(t.zoom=this.disableMovements.zoom?0:t.zoom,t.ascend=this.disableMovements.ascend?0:t.ascend,t.pan.enabled=!this.disableMovements.pan,this.disableMovements.pan&&m(t.pan.matrix),t.rotate.enabled=!this.disableMovements.rotate,this.disableMovements.rotate&&m(t.rotate.matrix))}static activatesFor(t,e){const i=X(e,t.navigation.gamepad,Q);return!("end"===e.action||Z(i))}};t([o({constructOnly:!0})],J.prototype,"gamepadDevice",void 0),t([o({constructOnly:!0})],J.prototype,"disableMovements",void 0),J=t([s("esri.views.3d.state.controllers.GamepadKeyboardController")],J);const Q={translation:[0,0,0],heading:0,tilt:0,zoom:0},W=80,Y=r(W),$=.75,tt=5,et=r(30),it=r(80),at={zoom:0,ascend:0,pan:{enabled:!1,matrix:l()},rotate:{enabled:!1,matrix:l()}},rt=S(),ot=S(),st=V();function nt(t){t.zoom=0,t.ascend=0,t.pan.enabled=!1,m(t.pan.matrix),t.rotate.enabled=!1,m(t.rotate.matrix)}export{J as GamepadKeyboardController};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{cyclicalPI as t}from"../../../../core/Cyclical.js";import{deg2rad as e,clamp as n,acosClamped as o,asinClamped as r}from"../../../../core/mathUtils.js";import{createScreenPointArray as a}from"../../../../core/screenUtils.js";import{fromRotation as i,exactEquals as s,rotate as c,multiply as l}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as m,create as u}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as f}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{e as h,l as M,d as g,t as y,f as b,n as d,s as x,c as v,h as j,g as z,m as P,i as w}from"../../../../chunks/vec32.js";import{create as I}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as H,fromPoints as S,axis as A,wrapAxisAngle as E}from"../../../../geometry/support/axisAngle.js";import{coordinateSystemFromOneAxisAndNormalVector as k,vectorCoordinates as T}from"../../../../geometry/support/coordinateSystem.js";import{create as U,fromNormalAndOffset as G,intersectRay as R}from"../../../../geometry/support/plane.js";import{c as q,j as C,i as F,a as V}from"../../../../chunks/sphere.js";import{sm4d as O,sv3d as W}from"../../../../geometry/support/vectorStacks.js";import{fromScreenAtEye as B,fromScreen as D}from"../../support/geometryUtils/ray.js";import{intersectScreen as J}from"../../support/geometryUtils/sphere.js";import K from"../../webgl/RenderCamera.js";import{terrainId as L}from"../../webgl-engine/lib/verticalOffsetUtils.js";var N;!function(t){t[t.Ellipsoid=0]="Ellipsoid",t[t.Silhouette=1]="Silhouette"}(N||(N={}));const Q=30,X=[1,3e8],Y=80,Z=8,$=200,_=1508e5,tt=5,et=50,nt=5,ot=10,rt=90,at={exclude:new Set([L])};function it(t,e,n){return n[0]=e[0]/(t.fullWidth/t.pixelRatio),n[1]=e[1]/(t.fullHeight/t.pixelRatio),n}function st(t){for(;t>Math.PI;)t-=2*Math.PI;for(;t<-Math.PI;)t+=2*Math.PI;return t}function ct(t,e,n){const o=i(O.get(),n[3],A(n));null==o||s(o,m)||(g(re,t.eye,e),y(re,re,o),t.eye=b(re,re,e),g(re,t.center,e),y(re,re,o),t.center=b(re,re,e),t.up=y(re,t.up,o))}function lt(t,e,n,o){return R(t,D(e,n,le),o)}function mt(t,e,n,o){return R(t,B(e,n,le),o)}function ut(t,e,n,o){const r=W.get();let a=1-n;g(r,e,t.eye);const i=M(r);let s=i*(1-a);a>=0&&s<o&&(s=o,a=-(s-i)/i),Math.abs(i-s)<1e-6||(z(r,r,a),t.eye=b(re,t.eye,r),t.center=P(re,t.center,e,a))}function ft(t,e,n){e.getScreenCenter(pt),J(t,e,pt,re)&&(e.center=re);const o=e.distance,r=o*n;if(Math.abs(o-r)<1e-6)return;const a=z(W.get(),e.viewForward,r);e.eye=g(re,e.center,a)}const pt=a();function ht(t,e){w(e,0,0,0);for(const n of t)b(e,e,n);z(e,e,1/t.length)}function Mt(t,e,n,o){return Math.sin(t/M(e))*(n+o.radius)}function gt(t,e,n,o){return Mt(Math.PI/2,e,n,o)+(t-Math.PI/2)}var yt;!function(t){t[t.Vertical=0]="Vertical",t[t.Horizontal=1]="Horizontal"}(yt||(yt={}));const bt={Elevation:3e4,Angle:e(16)},dt=e(80);function xt(t,e,n,o,r,a){const i=I(),s=q();let c=!0,l=!0;return t.intersectScreen(n,i,a)?s[3]=M(i):(l=!1,e.aboveGround&&r!==N.Ellipsoid?s[3]=Math.max(M(e.center),.9*o):s[3]=M(e.eye)-e.relativeElevation,r===N.Silhouette?Pt(s,e,n,i):c=J(s,e,n,i)),{sphere:s,scenePickPoint:c?i:null,hasGeometryIntersection:l}}function vt(t,e,n,o){const r=t.relativeElevation;if(r>bt.Elevation&&"global"===o)return yt.Horizontal;B(t,e,me);const a=Math.sign(r),i=n.worldUpAtPosition(t.eye,re);return-a*h(i,me.direction)<Math.sin(bt.Angle)*M(me.direction)?yt.Vertical:yt.Horizontal}function jt(t,e,n){g(zt,n,e),t.eye=g(re,t.eye,zt),t.center=g(re,t.center,zt)}const zt=I();function Pt(t,e,n,o){const r=B(e,n,le);return null!=r&&(C(t,r,wt),F(t,r,o)?!(x(wt,r.origin)<x(o,r.origin))||(v(o,wt),!1):(g(It,e.eye,e.center),d(It,It),G(It,-h(d(It,It),wt),Ht),R(Ht,r,o),!1))}const wt=I(),It=I(),Ht=U();function St(a,i,s,c,l,m){let u=0;if(j(se,a,i),g(ae,a,i),M(a)<=l||!c.aboveGround){j(s,ae,c.eye);const f=h(a,i)/(M(a)*M(i));if(f<.9999)u=o(f);else{const t=M(j(I(),a,i))/(M(a)*M(i));u=r(t)}const p=Math.cos(n(t.normalize(e(m)),0,dt));u=-u-Math.max(0,M(i)-l)/(p*l)}else g(At,c.eye,c.center),j(s,ae,At),u=-M(ae)/l;return d(s,s),z(s,s,M(se)),u}const At=I();function Et(r,a,i,s){let c,l;const m=Math.cos(n(t.normalize(e(s)),0,dt));return c=a>i?-(a-i)/(m*i):a<-i?Math.PI-(a+i)/(m*i):o(a/i),l=r>i?-(r-i)/(m*i):r<-i?Math.PI-(r+i)/(m*i):o(r/i),(l-c)*i}function kt(t,e,n,o,r,a,i,s,c,l){const m=Et(t[2],e[2],a[3],s),u=c?Et(t[0],e[0],a[3],180):e[0]-t[0],p=Math.sin(i)*u-Math.cos(i)*m,M=Math.cos(i)*u+Math.sin(i)*m;d(re,r);const g=c?p/Math.sqrt(Math.abs(a[3]**2-h(n,re)**2)):p/a[3],y=M/Math.sqrt(Math.abs(a[3]**2-h(n,o)**2));f(l,g,y)}function Tt(t,e,n,o,r,a,i,s,c,l){j(se,t,e),k(a.up,a.eye,Nt,Qt,Xt),k([0,0,1],a.eye,Jt,Kt,Lt),v(n,Kt),v(o,Jt),d(n,n),z(n,n,M(se)),T(t,d(Qt,Qt),d(Xt,Xt),d(Nt,Nt),Yt),T(e,Qt,Xt,Nt,Zt),kt(Yt,Zt,t,Jt,Kt,i,s,c,l,r)}function Ut(t,e,n,o,r,a,s){i(te,r,o),i(ee,s,a),l(ne,te,ee),g(e,t,n),y(e,e,ne),b(e,e,n)}function Gt(t,e,n,o,r,a){i(te,o,n),i(ee,a,r),l(ne,te,ee),g(re,t.eye,e),y(re,re,ne),t.eye=b(re,re,e),g(re,t.center,e),y(re,re,ne),t.center=b(re,re,e),g(re,t.up,e),y(re,re,ne),t.up=b(re,re,e)}const Rt={Pole:.95,Angle:e(18),Tilt:45,TiltHysteresisMargin:1e-7};let qt=!1;function Ct(t,e,n,o,r,a){const i=Math.abs(o)>Math.PI-Rt.Angle||Math.abs(o)<Rt.Angle,s=(Math.abs(t[2])<n*Rt.Pole||Math.abs(e)>n)&&a;return i&&s?!qt&&r<Rt.Tilt-Rt.TiltHysteresisMargin?qt=!0:qt&&r>Rt.Tilt+Rt.TiltHysteresisMargin&&(qt=!1):qt=!1,qt}function Ft(t,e,n,o,r,a){if(a)S(n,o,_t),ct(e,V(t),_t);else{const a=St(n,o,ce,e,t[3],r);ct(e,V(t),E(ce,a))}}function Vt(t,e,n,o,r,a,i){const s=i?20:1,c=1e-12;let l,m;v(oe,o),ie.copyFrom(e);for(let u=0;u<s&&x(n,oe)>c&&(l=x(n,oe),Tt(n,oe,Kt,Jt,$t,ie,t,r,a,i),Gt(ie,V(t),Jt,$t[1],Kt,$t[0]),Ut(oe,oe,V(t),Jt,$t[1],Kt,$t[0]),m=x(n,oe),m<l||0===u);u++)e.copyFrom(ie)}function Ot(n,o,r,a,i,s,c){Ct(r,h(o.up,r),n[3],-t.normalize(e(i)),s,o.aboveGround)?Vt(n,o,r,a,-t.normalize(e(i)),s,c):Ft(n,o,r,a,s,c)}function Wt(t,e,n,o,r,a){const{eye:i}=t;k([0,0,1],i,Jt,Kt,Lt);const s=e.translation[0]*n.pan,l="zoom"===r.mode?0:e.translation[1]*n.pan,m=Math.max(Math.sqrt(Math.abs(1-h(t.center,Jt)**2/M(t.center)**2)),.5),u=(Math.sin(a)*l+Math.cos(a)*s)/m,f=-Math.cos(a)*l+Math.sin(a)*s;switch(c(o.pan.matrix,o.pan.matrix,u,Jt),o.pan.enabled=!0,r.mode){case"pan":c(o.pan.matrix,o.pan.matrix,f,Kt),o.pan.enabled=!0;break;case"zoom":o.zoom=-e.translation[1]*n.zoom}}function Bt(t,e,n,o,r){const{eye:a,viewRight:i}=t,s=j(W.get(),i,a),l=e.translation[0]*n.pan;switch(0!==l&&(c(o.pan.matrix,o.pan.matrix,-l,s),o.pan.enabled=!0),r.mode){case"pan":{const t=e.translation[1]*n.pan;0!==t&&(c(o.pan.matrix,o.pan.matrix,t,i),o.pan.enabled=!0);break}case"zoom":o.zoom=-e.translation[1]*n.zoom}}function Dt(n,o,r,a,i,s,c,l,m){Ct(n.center,h(n.up,n.center),M(n.center),-t.normalize(e(s)),c,o.aboveGround)?Wt(o,r,a,l,m,-t.normalize(e(i))):Bt(o,r,a,l,m)}const Jt=I(),Kt=I(),Lt=I(),Nt=I(),Qt=I(),Xt=I(),Yt=I(),Zt=I(),$t=p(),_t=H(),te=u(),ee=u(),ne=u(),oe=I(),re=I(),ae=I(),ie=new K,se=I(),ce=I(),le={origin:I(),direction:I()},me={origin:I(),direction:I()};export{yt as NavigationMode,N as SpherePickPointFallback,dt as TiltThresholdPanningSpeed,bt as VerticalPanTresholds,jt as applyPanPlanar,Ft as applyPanSphericalDirectRotation,Vt as applyPanSphericalPreserveHeading,ct as applyRotation,Gt as applyRotationWithTwoAxes,ft as applyZoomOnSphere,ut as applyZoomToPoint,ht as centroid,X as distanceClampValues,at as excludeTerrain,lt as intersectPlaneFromScreenPoint,mt as intersectPlaneFromScreenPointAtEye,Et as lengthFromPoints,et as minHeightLimit,vt as navigationMode,it as normalizeCoordinate,st as normalizeRotationDelta,gt as offSurfaceTiltToEyeTiltGlobal,Mt as onSurfaceTiltToEyeTiltGlobal,tt as panDistanceModifier,Dt as panMotionToRotationMatrix,Ot as panToPosition,xt as pickPointAndInitSphere,Q as pivotDistanceModifier,Rt as preservingHeadingThresholds,nt as rotatePivotDistanceModifier,ot as rotatePivotMinDistanceModifier,Ut as rotatePointAroundTwoAxes,rt as rotateScreenPixelArea,St as rotationAngleAndAxisDirectRotation,Tt as rotationAnglesAndAxesHeadingPreserving,kt as rotationAnglesHeadingPreserving,Y as screenPixelArea,Ct as shouldPreserveHeading,Pt as sphereOrPlanePointFromScreenPoint,Z as zoomDistanceModifier,_ as zoomMaxDistanceModifier,$ as zoomMinDistanceModifier};
5
+ import{cyclicalPI as t}from"../../../../core/Cyclical.js";import{deg2rad as e,clamp as n,acosClamped as o,asinClamped as r}from"../../../../core/mathUtils.js";import{createScreenPointArray as a}from"../../../../core/screenUtils.js";import{fromRotation as i,exactEquals as s,rotate as c,multiply as l}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as m,create as u}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as f}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{e as h,l as M,d as g,t as y,f as b,n as d,s as x,c as v,h as j,g as z,m as P,i as w}from"../../../../chunks/vec32.js";import{create as I}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as H,fromPoints as S,axis as A,wrapAxisAngle as E}from"../../../../geometry/support/axisAngle.js";import{coordinateSystemFromOneAxisAndNormalVector as k,vectorCoordinates as T}from"../../../../geometry/support/coordinateSystem.js";import{create as U,fromNormalAndOffset as G,intersectRay as R}from"../../../../geometry/support/plane.js";import{c as q,m as C,i as F,a as V}from"../../../../chunks/sphere.js";import{sm4d as O,sv3d as W}from"../../../../geometry/support/vectorStacks.js";import{fromScreenAtEye as B,fromScreen as D}from"../../support/geometryUtils/ray.js";import{intersectScreen as J}from"../../support/geometryUtils/sphere.js";import K from"../../webgl/RenderCamera.js";import{terrainId as L}from"../../webgl-engine/lib/verticalOffsetUtils.js";var N;!function(t){t[t.Ellipsoid=0]="Ellipsoid",t[t.Silhouette=1]="Silhouette"}(N||(N={}));const Q=30,X=[1,3e8],Y=80,Z=8,$=200,_=1508e5,tt=5,et=50,nt=5,ot=10,rt=90,at={exclude:new Set([L])};function it(t,e,n){return n[0]=e[0]/(t.fullWidth/t.pixelRatio),n[1]=e[1]/(t.fullHeight/t.pixelRatio),n}function st(t){for(;t>Math.PI;)t-=2*Math.PI;for(;t<-Math.PI;)t+=2*Math.PI;return t}function ct(t,e,n){const o=i(O.get(),n[3],A(n));null==o||s(o,m)||(g(re,t.eye,e),y(re,re,o),t.eye=b(re,re,e),g(re,t.center,e),y(re,re,o),t.center=b(re,re,e),t.up=y(re,t.up,o))}function lt(t,e,n,o){return R(t,D(e,n,le),o)}function mt(t,e,n,o){return R(t,B(e,n,le),o)}function ut(t,e,n,o){const r=W.get();let a=1-n;g(r,e,t.eye);const i=M(r);let s=i*(1-a);a>=0&&s<o&&(s=o,a=-(s-i)/i),Math.abs(i-s)<1e-6||(z(r,r,a),t.eye=b(re,t.eye,r),t.center=P(re,t.center,e,a))}function ft(t,e,n){e.getScreenCenter(pt),J(t,e,pt,re)&&(e.center=re);const o=e.distance,r=o*n;if(Math.abs(o-r)<1e-6)return;const a=z(W.get(),e.viewForward,r);e.eye=g(re,e.center,a)}const pt=a();function ht(t,e){w(e,0,0,0);for(const n of t)b(e,e,n);z(e,e,1/t.length)}function Mt(t,e,n,o){return Math.sin(t/M(e))*(n+o.radius)}function gt(t,e,n,o){return Mt(Math.PI/2,e,n,o)+(t-Math.PI/2)}var yt;!function(t){t[t.Vertical=0]="Vertical",t[t.Horizontal=1]="Horizontal"}(yt||(yt={}));const bt={Elevation:3e4,Angle:e(16)},dt=e(80);function xt(t,e,n,o,r,a){const i=I(),s=q();let c=!0,l=!0;return t.intersectScreen(n,i,a)?s[3]=M(i):(l=!1,e.aboveGround&&r!==N.Ellipsoid?s[3]=Math.max(M(e.center),.9*o):s[3]=M(e.eye)-e.relativeElevation,r===N.Silhouette?Pt(s,e,n,i):c=J(s,e,n,i)),{sphere:s,scenePickPoint:c?i:null,hasGeometryIntersection:l}}function vt(t,e,n,o){const r=t.relativeElevation;if(r>bt.Elevation&&"global"===o)return yt.Horizontal;B(t,e,me);const a=Math.sign(r),i=n.worldUpAtPosition(t.eye,re);return-a*h(i,me.direction)<Math.sin(bt.Angle)*M(me.direction)?yt.Vertical:yt.Horizontal}function jt(t,e,n){g(zt,n,e),t.eye=g(re,t.eye,zt),t.center=g(re,t.center,zt)}const zt=I();function Pt(t,e,n,o){const r=B(e,n,le);return null!=r&&(C(t,r,wt),F(t,r,o)?!(x(wt,r.origin)<x(o,r.origin))||(v(o,wt),!1):(g(It,e.eye,e.center),d(It,It),G(It,-h(d(It,It),wt),Ht),R(Ht,r,o),!1))}const wt=I(),It=I(),Ht=U();function St(a,i,s,c,l,m){let u=0;if(j(se,a,i),g(ae,a,i),M(a)<=l||!c.aboveGround){j(s,ae,c.eye);const f=h(a,i)/(M(a)*M(i));if(f<.9999)u=o(f);else{const t=M(j(I(),a,i))/(M(a)*M(i));u=r(t)}const p=Math.cos(n(t.normalize(e(m)),0,dt));u=-u-Math.max(0,M(i)-l)/(p*l)}else g(At,c.eye,c.center),j(s,ae,At),u=-M(ae)/l;return d(s,s),z(s,s,M(se)),u}const At=I();function Et(r,a,i,s){let c,l;const m=Math.cos(n(t.normalize(e(s)),0,dt));return c=a>i?-(a-i)/(m*i):a<-i?Math.PI-(a+i)/(m*i):o(a/i),l=r>i?-(r-i)/(m*i):r<-i?Math.PI-(r+i)/(m*i):o(r/i),(l-c)*i}function kt(t,e,n,o,r,a,i,s,c,l){const m=Et(t[2],e[2],a[3],s),u=c?Et(t[0],e[0],a[3],180):e[0]-t[0],p=Math.sin(i)*u-Math.cos(i)*m,M=Math.cos(i)*u+Math.sin(i)*m;d(re,r);const g=c?p/Math.sqrt(Math.abs(a[3]**2-h(n,re)**2)):p/a[3],y=M/Math.sqrt(Math.abs(a[3]**2-h(n,o)**2));f(l,g,y)}function Tt(t,e,n,o,r,a,i,s,c,l){j(se,t,e),k(a.up,a.eye,Nt,Qt,Xt),k([0,0,1],a.eye,Jt,Kt,Lt),v(n,Kt),v(o,Jt),d(n,n),z(n,n,M(se)),T(t,d(Qt,Qt),d(Xt,Xt),d(Nt,Nt),Yt),T(e,Qt,Xt,Nt,Zt),kt(Yt,Zt,t,Jt,Kt,i,s,c,l,r)}function Ut(t,e,n,o,r,a,s){i(te,r,o),i(ee,s,a),l(ne,te,ee),g(e,t,n),y(e,e,ne),b(e,e,n)}function Gt(t,e,n,o,r,a){i(te,o,n),i(ee,a,r),l(ne,te,ee),g(re,t.eye,e),y(re,re,ne),t.eye=b(re,re,e),g(re,t.center,e),y(re,re,ne),t.center=b(re,re,e),g(re,t.up,e),y(re,re,ne),t.up=b(re,re,e)}const Rt={Pole:.95,Angle:e(18),Tilt:45,TiltHysteresisMargin:1e-7};let qt=!1;function Ct(t,e,n,o,r,a){const i=Math.abs(o)>Math.PI-Rt.Angle||Math.abs(o)<Rt.Angle,s=(Math.abs(t[2])<n*Rt.Pole||Math.abs(e)>n)&&a;return i&&s?!qt&&r<Rt.Tilt-Rt.TiltHysteresisMargin?qt=!0:qt&&r>Rt.Tilt+Rt.TiltHysteresisMargin&&(qt=!1):qt=!1,qt}function Ft(t,e,n,o,r,a){if(a)S(n,o,_t),ct(e,V(t),_t);else{const a=St(n,o,ce,e,t[3],r);ct(e,V(t),E(ce,a))}}function Vt(t,e,n,o,r,a,i){const s=i?20:1,c=1e-12;let l,m;v(oe,o),ie.copyFrom(e);for(let u=0;u<s&&x(n,oe)>c&&(l=x(n,oe),Tt(n,oe,Kt,Jt,$t,ie,t,r,a,i),Gt(ie,V(t),Jt,$t[1],Kt,$t[0]),Ut(oe,oe,V(t),Jt,$t[1],Kt,$t[0]),m=x(n,oe),m<l||0===u);u++)e.copyFrom(ie)}function Ot(n,o,r,a,i,s,c){Ct(r,h(o.up,r),n[3],-t.normalize(e(i)),s,o.aboveGround)?Vt(n,o,r,a,-t.normalize(e(i)),s,c):Ft(n,o,r,a,s,c)}function Wt(t,e,n,o,r,a){const{eye:i}=t;k([0,0,1],i,Jt,Kt,Lt);const s=e.translation[0]*n.pan,l="zoom"===r.mode?0:e.translation[1]*n.pan,m=Math.max(Math.sqrt(Math.abs(1-h(t.center,Jt)**2/M(t.center)**2)),.5),u=(Math.sin(a)*l+Math.cos(a)*s)/m,f=-Math.cos(a)*l+Math.sin(a)*s;switch(c(o.pan.matrix,o.pan.matrix,u,Jt),o.pan.enabled=!0,r.mode){case"pan":c(o.pan.matrix,o.pan.matrix,f,Kt),o.pan.enabled=!0;break;case"zoom":o.zoom=-e.translation[1]*n.zoom}}function Bt(t,e,n,o,r){const{eye:a,viewRight:i}=t,s=j(W.get(),i,a),l=e.translation[0]*n.pan;switch(0!==l&&(c(o.pan.matrix,o.pan.matrix,-l,s),o.pan.enabled=!0),r.mode){case"pan":{const t=e.translation[1]*n.pan;0!==t&&(c(o.pan.matrix,o.pan.matrix,t,i),o.pan.enabled=!0);break}case"zoom":o.zoom=-e.translation[1]*n.zoom}}function Dt(n,o,r,a,i,s,c,l,m){Ct(n.center,h(n.up,n.center),M(n.center),-t.normalize(e(s)),c,o.aboveGround)?Wt(o,r,a,l,m,-t.normalize(e(i))):Bt(o,r,a,l,m)}const Jt=I(),Kt=I(),Lt=I(),Nt=I(),Qt=I(),Xt=I(),Yt=I(),Zt=I(),$t=p(),_t=H(),te=u(),ee=u(),ne=u(),oe=I(),re=I(),ae=I(),ie=new K,se=I(),ce=I(),le={origin:I(),direction:I()},me={origin:I(),direction:I()};export{yt as NavigationMode,N as SpherePickPointFallback,dt as TiltThresholdPanningSpeed,bt as VerticalPanTresholds,jt as applyPanPlanar,Ft as applyPanSphericalDirectRotation,Vt as applyPanSphericalPreserveHeading,ct as applyRotation,Gt as applyRotationWithTwoAxes,ft as applyZoomOnSphere,ut as applyZoomToPoint,ht as centroid,X as distanceClampValues,at as excludeTerrain,lt as intersectPlaneFromScreenPoint,mt as intersectPlaneFromScreenPointAtEye,Et as lengthFromPoints,et as minHeightLimit,vt as navigationMode,it as normalizeCoordinate,st as normalizeRotationDelta,gt as offSurfaceTiltToEyeTiltGlobal,Mt as onSurfaceTiltToEyeTiltGlobal,tt as panDistanceModifier,Dt as panMotionToRotationMatrix,Ot as panToPosition,xt as pickPointAndInitSphere,Q as pivotDistanceModifier,Rt as preservingHeadingThresholds,nt as rotatePivotDistanceModifier,ot as rotatePivotMinDistanceModifier,Ut as rotatePointAroundTwoAxes,rt as rotateScreenPixelArea,St as rotationAngleAndAxisDirectRotation,Tt as rotationAnglesAndAxesHeadingPreserving,kt as rotationAnglesHeadingPreserving,Y as screenPixelArea,Ct as shouldPreserveHeading,Pt as sphereOrPlanePointFromScreenPoint,Z as zoomDistanceModifier,_ as zoomMaxDistanceModifier,$ as zoomMinDistanceModifier};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{Cyclical as r,cyclicalPI as s}from"../../../core/Cyclical.js";import"../../../core/has.js";import{clamp as i,deg2rad as a}from"../../../core/mathUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{watch as o,sync as l}from"../../../core/reactiveUtils.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{subtract as d}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{f as u,d as p,c as m,j as g}from"../../../chunks/vec32.js";import{create as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as y,d as f,g as v}from"../../../chunks/vec42.js";import{fromValues as R,create as O}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as w}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,width as T,copy as D,center as E,height as P,intersection as M,contains as j,intersects as b,offset as I}from"../../../geometry/support/aaBoundingRect.js";import{create as U,wrap as C}from"../../../geometry/support/ray.js";import{j as N,b as A,t as q}from"../../../chunks/sphere.js";import{angleAroundAxis as G}from"../../../geometry/support/vector.js";import{y2lat as V}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as F}from"../state/utils/viewUtils.js";import{debugFlags as L}from"../support/debugFlags.js";import{DebugPoint as H}from"../support/debugUtils.js";import{OverlayIndex as B}from"./interfaces.js";import{OverlayRenderer as z}from"./OverlayRenderer.js";import{RenderRequestType as k}from"../webgl-engine/lib/basicInterfaces.js";import{Intersector as Y}from"../webgl-engine/lib/Intersector.js";import{fromValues as W}from"../webgl-engine/lib/LocalOriginFactory.js";import{SortedRenderGeometryRenderer as X}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as K,ensureTextureSize as Z}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as J}from"../webgl-engine/parts/renderUtils.js";import{TaskPriority as Q,noBudget as $}from"../../support/Scheduler.js";import{Yield as ee}from"../../support/Yield.js";const te=1.3,re=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let se,ie=class extends t{constructor(e){super(e),this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._latestOriginId=0}initialize(){const e=this.view;this.renderer=new z({parent:this}),e.stage.renderer.plugins.add(this.renderer);const t=()=>this.requestRender();this._groundIntersector=new Y(this.view.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([o((()=>this.renderer.hasHighlights),t),this.renderer.events.on("has-water",(()=>e.stage?.renderer.updateHasFlags())),this.renderer.events.on("content-changed",t),o((()=>e.state.camera.pixelRatio),t),o((()=>e.state.alignPixelEnabled),t),this.renderer.events.on("textures-disposed",(()=>this.surface.requestRender())),o((()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location]),(()=>this.setPlacementDirty())),o((()=>[e.state?.pixelRatio,e.state?.contentPixelRatio]),(()=>this.setPlacementDirty()),l),this.surface.on("elevation-change",(()=>this.setPlacementDirty())),e.on("resize",(()=>this.setPlacementDirty())),e.resourceController.scheduler.registerTask(Q.OVERLAY,this),e.stage.renderView.events.on("force-camera-for-screenshot",(e=>{this._updateOverlays($,e.camera,k.BACKGROUND),this.renderer.hasOverlays&&this._drawOverlays(k.BACKGROUND,e)}))]),e.stage.renderer.overlay=this}destroy(){this.view?.stage&&(this.view.stage.renderer.plugins.remove(this.renderer),this.view.stage.renderer.overlay=null),se&&(se.hide(),se=null),this.renderer=n(this.renderer)}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.renderer.longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this.renderer.longitudeCyclical=e.isWebMercator?new r(-20037508.342787,20037508.342787):new r(-180,180))):this.renderer.disposeOverlays()}get running(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||L.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.surface.ready}get _isSpherical(){return this.view.state.isGlobal}get worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?x(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return te/this.view.resolutionScale}get _longitudeCyclical(){return this.renderer.longitudeCyclical}get suspended(){return this.surface.suspended}get updating(){return this.running||this.renderer.updating||this._contentUpdated}get rendersOccludedDraped(){return this.renderer.rendersOccludedDraped}render(){if(this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.hasOverlays)return this._precompileShaders()?this._drawOverlays(k.UPDATE):null}get hasOverlays(){return this.renderer.hasOverlays}registerDrapeSource(e,t){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources),this.renderer.registerDrapeSource(e,t),this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("running")}registerGeometryDrapeSource(e){const t=new X({stage:this.view.stage,drapeSource:e,rendererContext:this.renderer});return this.registerDrapeSource(e,t),t}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("running"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.requestRender()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this._updateOverlays(e,this.view.state.contentCamera,k.UPDATE)}_updateOverlays(e,t,r){if(!this._spatialReference)return ee;const s=this._computeOverlayHeight(t);this._computeOverlayExtents(t,s,he),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,he.stretch);const i=this._updateOverlay(B.INNER,he.inner,s,1*he.pixelRatioAdjustment,he.mapUnitsPerPixel),a=T(he.inner)/T(he.outer),n=this._updateOverlay(B.OUTER,he.outer,s,a*he.pixelRatioAdjustment,he.mapUnitsPerPixel);i!==pe.EXTENT&&n!==pe.EXTENT||(this._drapeSources.forEach((e=>this._updateDrapeSourceExtent(e))),this.updateOverlayParameters(r)),i===pe.NONE&&n===pe.NONE||this.requestRender(),this._placementDirty=!1,e.madeProgress()}_computeOverlayHeight(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s)),{maxPreferredTexturePixels:a,maxTextureSize:n}=this.view.stage.renderView.renderingContext.parameters,o=.5*n;return K(Z({width:i,height:i},{maxPreferredTexturePixels:2*a,maxTextureSize:o})[1],o)}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return pe.NONE;const a=this.renderer.overlays[e],n=a.mapUnitsPerPixel;if(a.mapUnitsPerPixel=i,a.pixelRatio=s,ae(t,a.extent)&&r===a.resolution)return n===i?pe.NONE:pe.RERENDER_ONLY;D(a.extent,t),a.resolution=r;const o=E(a.extent);return a.renderLocalOrigin=W(o[0],o[1],0,"OV_"+this._latestOriginId++),pe.EXTENT}updateOverlayParameters(e){this.surface.allTiles.forAll((e=>this.updateTileOverlayParameters(e))),this.surface.requestRender(e)}updateTileOverlayParameters(e){if(!e.renderData)return;const t=e.renderData.overlay;if(0===this.renderer.overlays.length)this._clearTileOverlayData(B.INNER,t),this._clearTileOverlayData(B.OUTER,t);else{const[r,s]=this.renderer.overlays,i=e.extent;this._rectInsideRect(r.extent,i)||this._rectanglesOverlap(i,r.extent)||this._rectanglesOverlap(i,s.extent)?(this._setTileOverlayData(i,B.INNER,t),this._setTileOverlayData(i,B.OUTER,t)):(this._clearTileOverlayData(B.INNER,t),this._clearTileOverlayData(B.OUTER,t))}}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[B.INNER],s=this.renderer.overlays[B.OUTER],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}_setTileOverlayData(e,t,r){if(0===this.renderer.overlays.length)return;const s=this.renderer.overlays[t].extent,i=T(s),a=P(s);let n=e[0];if(this._longitudeCyclical){n=this._longitudeCyclical.minimalMonotonic(s[0],n);const t=this._longitudeCyclical.minimalMonotonic(s[0],e[2]);n>t&&(n=t-(e[2]-e[0]))}r.setScale(t,T(e)/i,P(e)/a),r.setOffset(t,(n-s[0])/i,(e[1]-s[1])/a)}_clearTileOverlayData(e,t){t.setScale(e,-1,-1),t.setOffset(e,-1,-1)}reloadShaders(){J(),this.requestRender(),this.runTask($)}requestRender(e=k.UPDATE){this.renderer.hasOverlays?(e===k.UPDATE?(this._contentUpdated=!0,this._drawTexturesDirty=!0):this._drawTexturesAnimateDirty=!0,this.view.stage.renderView.requestRender(e)):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s,i){const a=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,ue,t,r);if(null==a)return!1;const n=a.origin,o=u(le,a.origin,a.direction);this._groundIntersector.reset(n,o,e),this._groundIntersector.intersect([]),this.view.basemapTerrain.intersect(this._groundIntersector,null,n,o);const l=this._groundIntersector.results.min;return l.getIntersectionPoint(i)&&l.withinDistance(s)}_findHorizonBasedPointOfInterest(e,t){let r=.5;const a=.55,n=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=i(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:n+l,e.aboveGround?n-l:1/0),c=e.aboveGround;if("global"===this.view.viewingMode){const t=le;N(A(q,x(this.view.spatialReference).radius+h),C(e.eye,e.viewForward),t),p(t,t,e.eye);const i=s.normalize(G(e.viewForward,t,e.viewRight))/e.fovY+.5,n=i<=0||i>=1?.5:a;r=c?n*i:i+n*(1-i)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),s=Math.tan(t),n=R(0,s,1,0),o=y(n,n,e.projectionMatrix)[1],l=i(.5+.5*o,0,1);r=1===l||0===l?.5:c?l*a:1-(1-l)*a}return this._intersectGroundFromView(e,.5,r,o.distance,t)}_computeOverlayExtents(e,t,r){const s=this.view.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i=_();this._findHorizonBasedPointOfInterest(e,i)||m(i,s),L.OVERLAY_SHOW_CENTER?(null==se&&(se=new H(this.view.graphics,"red")),se.show(i,this._renderSR)):null!=se&&se.hide();const n=Math.max(.1,g(e.eye,i)),o=F(this.view.renderCoordsHelper,s,e.eye);this._overlaySREqualsRenderSR||w(i,this._renderSR,i,this._spatialReference);const l=this.surface.extent,h=!this._isSpherical&&this._spatialReference?.isGeographic,c=h&&this._spatialReference?1/x(this._spatialReference).metersPerDegree:1,u=this.view.state.contentPixelRatio,p=e.perScreenPixelRatio/u*n*c;r.mapUnitsPerPixel=p/this.worldToPCSRatio,r.stretch=this._overlayStretch;let y=t*p/2*r.stretch,R=!1,O=h?90:1/0;this._isSpherical&&l&&this._spatialReference&&(this._spatialReference.isWebMercator?(y/=Math.cos(V(i[1])),O=l[3]):(R=!0,y/=x(this._spatialReference).metersPerDegree,O=90),y>=O&&(y=O,i[1]=0,this._spatialReference.isWebMercator&&(i[0]=0)));let S=1;R&&(S=1/Math.max(.2,Math.cos(Math.abs(a(i[1])))),y*S>180&&(S=180/y),r.mapUnitsPerPixel*=S);const E=Math.log(2)/12;y=Math.exp(Math.round(Math.log(y)/E)*E);const P=y*S,b=32,I=.5*t/(b*P),U=.5*t/(b*y);i[0]=Math.round(i[0]*I)/I,i[1]=Math.round(i[1]*U)/U;const C=r.inner;C[0]=i[0]-P,C[1]=i[1]-y,C[2]=i[0]+P,C[3]=i[1]+y,this._isSpherical&&this._shiftExtentToFitBounds(C,1/0,O);const N=r.outer;if(6*P>T(l))D(N,l);else{if(Math.PI/2-Math.abs(o-Math.PI/2)<=.25*Math.PI)N[0]=C[0]-P,N[1]=C[1]-y,N[2]=C[2]+P,N[3]=C[3]+y;else{w(e.eye,this._renderSR,le,this._spatialReference),d(oe,i,le);let t=-Math.atan2(oe[1],oe[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));f(oe,re[r],2*y),oe[0]*=S,oe[2]*=S,v(N,C,oe)}}if(this._isSpherical)N[0]=this._longitudeCyclical.clamp(N[0]),N[2]=this._longitudeCyclical.clamp(N[2]),N[1]=Math.max(N[1],-O),N[3]=Math.min(N[3],O);else{const e=M(C,l,ce),t=M(N,l,de);j(e,t)&&(N[2]=N[0],N[3]=N[1])}const A=Math.abs(C[2]-C[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,A),r.pixelRatioAdjustment=r.mapUnitsPerPixel/A}_precompileShaders(){return!!this.renderer.hasOverlays&&(this.renderer.precompileShaders(this.view.state),!0)}_drawOverlays(e,t=this.view.state){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const r=this._drawTexturesDirty;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const s=this.renderer.computeValidity();this.renderer.releaseRenderTargets(),this.renderer.drawOverlays(t);return s!==this.renderer.computeValidity()&&this.updateOverlayParameters(k.UPDATE),r?(this.surface.requestRender(e),e===k.UPDATE&&this.surface.requestUpdate()):this.surface.requestRender(k.BACKGROUND),this.renderer}_rectanglesOverlap(e,t){return null!=e&&(this._longitudeCyclical?(this._longitudeCyclical.contains(t[0],t[2],e[0])||this._longitudeCyclical.contains(t[0],t[2],e[2])||this._longitudeCyclical.contains(e[0],e[2],t[0]))&&!(e[1]>t[3]||e[3]<t[1]):b(e,t))}_rectInsideRect(e,t){return null!=t&&(this._longitudeCyclical?this._longitudeCyclical.contains(e[0],e[2],t[0])&&this._longitudeCyclical.contains(e[0],e[2],t[2])&&t[1]>e[1]&&t[3]<e[3]:j(e,t))}_pointIsInExtent(e,t){if(this._longitudeCyclical)return this._longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),I(e,s,i)}get test(){}};function ae(e,t){const r=1e-5,s=L.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([h()],ie.prototype,"_spatialReference",void 0),e([h({readOnly:!0})],ie.prototype,"running",null),e([h()],ie.prototype,"_placementDirty",void 0),e([h()],ie.prototype,"_contentUpdated",void 0),e([h()],ie.prototype,"_isSpherical",null),e([h()],ie.prototype,"worldToPCSRatio",null),e([h()],ie.prototype,"renderer",void 0),e([h({constructOnly:!0})],ie.prototype,"view",void 0),e([h({constructOnly:!0})],ie.prototype,"surface",void 0),e([h()],ie.prototype,"suspended",null),e([h()],ie.prototype,"updating",null),e([h({type:Boolean})],ie.prototype,"rendersOccludedDraped",null),ie=e([c("esri.views.3d.terrain.OverlayManager")],ie);class ne{constructor(){this.inner=S(),this.outer=S(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=te}}const oe=O(),le=_(),he=new ne,ce=S(),de=S(),ue=U();var pe;!function(e){e[e.NONE=0]="NONE",e[e.EXTENT=1]="EXTENT",e[e.RERENDER_ONLY=2]="RERENDER_ONLY"}(pe||(pe={}));export{ie as OverlayManager};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{Cyclical as r,cyclicalPI as s}from"../../../core/Cyclical.js";import"../../../core/has.js";import{clamp as i,deg2rad as a}from"../../../core/mathUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{watch as o,sync as l}from"../../../core/reactiveUtils.js";import{property as h}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{subtract as d}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{f as u,d as p,c as m,j as g}from"../../../chunks/vec32.js";import{create as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as y,d as f,h as v}from"../../../chunks/vec42.js";import{fromValues as R,create as O}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as x}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as w}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,width as T,copy as D,center as E,height as P,intersection as M,contains as j,intersects as b,offset as I}from"../../../geometry/support/aaBoundingRect.js";import{create as U,wrap as C}from"../../../geometry/support/ray.js";import{m as N,b as A,t as q}from"../../../chunks/sphere.js";import{angleAroundAxis as G}from"../../../geometry/support/vector.js";import{y2lat as V}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as F}from"../state/utils/viewUtils.js";import{debugFlags as L}from"../support/debugFlags.js";import{DebugPoint as H}from"../support/debugUtils.js";import{OverlayIndex as B}from"./interfaces.js";import{OverlayRenderer as z}from"./OverlayRenderer.js";import{RenderRequestType as k}from"../webgl-engine/lib/basicInterfaces.js";import{Intersector as Y}from"../webgl-engine/lib/Intersector.js";import{fromValues as W}from"../webgl-engine/lib/LocalOriginFactory.js";import{SortedRenderGeometryRenderer as X}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as K,ensureTextureSize as Z}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as J}from"../webgl-engine/parts/renderUtils.js";import{TaskPriority as Q,noBudget as $}from"../../support/Scheduler.js";import{Yield as ee}from"../../support/Yield.js";const te=1.3,re=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let se,ie=class extends t{constructor(e){super(e),this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._latestOriginId=0}initialize(){const e=this.view;this.renderer=new z({parent:this}),e.stage.renderer.plugins.add(this.renderer);const t=()=>this.requestRender();this._groundIntersector=new Y(this.view.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([o((()=>this.renderer.hasHighlights),t),this.renderer.events.on("has-water",(()=>e.stage?.renderer.updateHasFlags())),this.renderer.events.on("content-changed",t),o((()=>e.state.camera.pixelRatio),t),o((()=>e.state.alignPixelEnabled),t),this.renderer.events.on("textures-disposed",(()=>this.surface.requestRender())),o((()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location]),(()=>this.setPlacementDirty())),o((()=>[e.state?.pixelRatio,e.state?.contentPixelRatio]),(()=>this.setPlacementDirty()),l),this.surface.on("elevation-change",(()=>this.setPlacementDirty())),e.on("resize",(()=>this.setPlacementDirty())),e.resourceController.scheduler.registerTask(Q.OVERLAY,this),e.stage.renderView.events.on("force-camera-for-screenshot",(e=>{this._updateOverlays($,e.camera,k.BACKGROUND),this.renderer.hasOverlays&&this._drawOverlays(k.BACKGROUND,e)}))]),e.stage.renderer.overlay=this}destroy(){this.view?.stage&&(this.view.stage.renderer.plugins.remove(this.renderer),this.view.stage.renderer.overlay=null),se&&(se.hide(),se=null),this.renderer=n(this.renderer)}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.renderer.longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this.renderer.longitudeCyclical=e.isWebMercator?new r(-20037508.342787,20037508.342787):new r(-180,180))):this.renderer.disposeOverlays()}get running(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||L.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.surface.ready}get _isSpherical(){return this.view.state.isGlobal}get worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?x(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return te/this.view.resolutionScale}get _longitudeCyclical(){return this.renderer.longitudeCyclical}get suspended(){return this.surface.suspended}get updating(){return this.running||this.renderer.updating||this._contentUpdated}get rendersOccludedDraped(){return this.renderer.rendersOccludedDraped}render(){if(this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.hasOverlays)return this._precompileShaders()?this._drawOverlays(k.UPDATE):null}get hasOverlays(){return this.renderer.hasOverlays}registerDrapeSource(e,t){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources),this.renderer.registerDrapeSource(e,t),this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("running")}registerGeometryDrapeSource(e){const t=new X({stage:this.view.stage,drapeSource:e,rendererContext:this.renderer});return this.registerDrapeSource(e,t),t}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("running"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.requestRender()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this._updateOverlays(e,this.view.state.contentCamera,k.UPDATE)}_updateOverlays(e,t,r){if(!this._spatialReference)return ee;const s=this._computeOverlayHeight(t);this._computeOverlayExtents(t,s,he),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,he.stretch);const i=this._updateOverlay(B.INNER,he.inner,s,1*he.pixelRatioAdjustment,he.mapUnitsPerPixel),a=T(he.inner)/T(he.outer),n=this._updateOverlay(B.OUTER,he.outer,s,a*he.pixelRatioAdjustment,he.mapUnitsPerPixel);i!==pe.EXTENT&&n!==pe.EXTENT||(this._drapeSources.forEach((e=>this._updateDrapeSourceExtent(e))),this.updateOverlayParameters(r)),i===pe.NONE&&n===pe.NONE||this.requestRender(),this._placementDirty=!1,e.madeProgress()}_computeOverlayHeight(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s)),{maxPreferredTexturePixels:a,maxTextureSize:n}=this.view.stage.renderView.renderingContext.parameters,o=.5*n;return K(Z({width:i,height:i},{maxPreferredTexturePixels:2*a,maxTextureSize:o})[1],o)}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return pe.NONE;const a=this.renderer.overlays[e],n=a.mapUnitsPerPixel;if(a.mapUnitsPerPixel=i,a.pixelRatio=s,ae(t,a.extent)&&r===a.resolution)return n===i?pe.NONE:pe.RERENDER_ONLY;D(a.extent,t),a.resolution=r;const o=E(a.extent);return a.renderLocalOrigin=W(o[0],o[1],0,"OV_"+this._latestOriginId++),pe.EXTENT}updateOverlayParameters(e){this.surface.allTiles.forAll((e=>this.updateTileOverlayParameters(e))),this.surface.requestRender(e)}updateTileOverlayParameters(e){if(!e.renderData)return;const t=e.renderData.overlay;if(0===this.renderer.overlays.length)this._clearTileOverlayData(B.INNER,t),this._clearTileOverlayData(B.OUTER,t);else{const[r,s]=this.renderer.overlays,i=e.extent;this._rectInsideRect(r.extent,i)||this._rectanglesOverlap(i,r.extent)||this._rectanglesOverlap(i,s.extent)?(this._setTileOverlayData(i,B.INNER,t),this._setTileOverlayData(i,B.OUTER,t)):(this._clearTileOverlayData(B.INNER,t),this._clearTileOverlayData(B.OUTER,t))}}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[B.INNER],s=this.renderer.overlays[B.OUTER],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}_setTileOverlayData(e,t,r){if(0===this.renderer.overlays.length)return;const s=this.renderer.overlays[t].extent,i=T(s),a=P(s);let n=e[0];if(this._longitudeCyclical){n=this._longitudeCyclical.minimalMonotonic(s[0],n);const t=this._longitudeCyclical.minimalMonotonic(s[0],e[2]);n>t&&(n=t-(e[2]-e[0]))}r.setScale(t,T(e)/i,P(e)/a),r.setOffset(t,(n-s[0])/i,(e[1]-s[1])/a)}_clearTileOverlayData(e,t){t.setScale(e,-1,-1),t.setOffset(e,-1,-1)}reloadShaders(){J(),this.requestRender(),this.runTask($)}requestRender(e=k.UPDATE){this.renderer.hasOverlays?(e===k.UPDATE?(this._contentUpdated=!0,this._drawTexturesDirty=!0):this._drawTexturesAnimateDirty=!0,this.view.stage.renderView.requestRender(e)):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s,i){const a=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,ue,t,r);if(null==a)return!1;const n=a.origin,o=u(le,a.origin,a.direction);this._groundIntersector.reset(n,o,e),this._groundIntersector.intersect([]),this.view.basemapTerrain.intersect(this._groundIntersector,null,n,o);const l=this._groundIntersector.results.min;return l.getIntersectionPoint(i)&&l.withinDistance(s)}_findHorizonBasedPointOfInterest(e,t){let r=.5;const a=.55,n=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=i(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:n+l,e.aboveGround?n-l:1/0),c=e.aboveGround;if("global"===this.view.viewingMode){const t=le;N(A(q,x(this.view.spatialReference).radius+h),C(e.eye,e.viewForward),t),p(t,t,e.eye);const i=s.normalize(G(e.viewForward,t,e.viewRight))/e.fovY+.5,n=i<=0||i>=1?.5:a;r=c?n*i:i+n*(1-i)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),s=Math.tan(t),n=R(0,s,1,0),o=y(n,n,e.projectionMatrix)[1],l=i(.5+.5*o,0,1);r=1===l||0===l?.5:c?l*a:1-(1-l)*a}return this._intersectGroundFromView(e,.5,r,o.distance,t)}_computeOverlayExtents(e,t,r){const s=this.view.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i=_();this._findHorizonBasedPointOfInterest(e,i)||m(i,s),L.OVERLAY_SHOW_CENTER?(null==se&&(se=new H(this.view.graphics,"red")),se.show(i,this._renderSR)):null!=se&&se.hide();const n=Math.max(.1,g(e.eye,i)),o=F(this.view.renderCoordsHelper,s,e.eye);this._overlaySREqualsRenderSR||w(i,this._renderSR,i,this._spatialReference);const l=this.surface.extent,h=!this._isSpherical&&this._spatialReference?.isGeographic,c=h&&this._spatialReference?1/x(this._spatialReference).metersPerDegree:1,u=this.view.state.contentPixelRatio,p=e.perScreenPixelRatio/u*n*c;r.mapUnitsPerPixel=p/this.worldToPCSRatio,r.stretch=this._overlayStretch;let y=t*p/2*r.stretch,R=!1,O=h?90:1/0;this._isSpherical&&l&&this._spatialReference&&(this._spatialReference.isWebMercator?(y/=Math.cos(V(i[1])),O=l[3]):(R=!0,y/=x(this._spatialReference).metersPerDegree,O=90),y>=O&&(y=O,i[1]=0,this._spatialReference.isWebMercator&&(i[0]=0)));let S=1;R&&(S=1/Math.max(.2,Math.cos(Math.abs(a(i[1])))),y*S>180&&(S=180/y),r.mapUnitsPerPixel*=S);const E=Math.log(2)/12;y=Math.exp(Math.round(Math.log(y)/E)*E);const P=y*S,b=32,I=.5*t/(b*P),U=.5*t/(b*y);i[0]=Math.round(i[0]*I)/I,i[1]=Math.round(i[1]*U)/U;const C=r.inner;C[0]=i[0]-P,C[1]=i[1]-y,C[2]=i[0]+P,C[3]=i[1]+y,this._isSpherical&&this._shiftExtentToFitBounds(C,1/0,O);const N=r.outer;if(6*P>T(l))D(N,l);else{if(Math.PI/2-Math.abs(o-Math.PI/2)<=.25*Math.PI)N[0]=C[0]-P,N[1]=C[1]-y,N[2]=C[2]+P,N[3]=C[3]+y;else{w(e.eye,this._renderSR,le,this._spatialReference),d(oe,i,le);let t=-Math.atan2(oe[1],oe[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));f(oe,re[r],2*y),oe[0]*=S,oe[2]*=S,v(N,C,oe)}}if(this._isSpherical)N[0]=this._longitudeCyclical.clamp(N[0]),N[2]=this._longitudeCyclical.clamp(N[2]),N[1]=Math.max(N[1],-O),N[3]=Math.min(N[3],O);else{const e=M(C,l,ce),t=M(N,l,de);j(e,t)&&(N[2]=N[0],N[3]=N[1])}const A=Math.abs(C[2]-C[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,A),r.pixelRatioAdjustment=r.mapUnitsPerPixel/A}_precompileShaders(){return!!this.renderer.hasOverlays&&(this.renderer.precompileShaders(this.view.state),!0)}_drawOverlays(e,t=this.view.state){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const r=this._drawTexturesDirty;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const s=this.renderer.computeValidity();this.renderer.releaseRenderTargets(),this.renderer.drawOverlays(t);return s!==this.renderer.computeValidity()&&this.updateOverlayParameters(k.UPDATE),r?(this.surface.requestRender(e),e===k.UPDATE&&this.surface.requestUpdate()):this.surface.requestRender(k.BACKGROUND),this.renderer}_rectanglesOverlap(e,t){return null!=e&&(this._longitudeCyclical?(this._longitudeCyclical.contains(t[0],t[2],e[0])||this._longitudeCyclical.contains(t[0],t[2],e[2])||this._longitudeCyclical.contains(e[0],e[2],t[0]))&&!(e[1]>t[3]||e[3]<t[1]):b(e,t))}_rectInsideRect(e,t){return null!=t&&(this._longitudeCyclical?this._longitudeCyclical.contains(e[0],e[2],t[0])&&this._longitudeCyclical.contains(e[0],e[2],t[2])&&t[1]>e[1]&&t[3]<e[3]:j(e,t))}_pointIsInExtent(e,t){if(this._longitudeCyclical)return this._longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),I(e,s,i)}get test(){}};function ae(e,t){const r=1e-5,s=L.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([h()],ie.prototype,"_spatialReference",void 0),e([h({readOnly:!0})],ie.prototype,"running",null),e([h()],ie.prototype,"_placementDirty",void 0),e([h()],ie.prototype,"_contentUpdated",void 0),e([h()],ie.prototype,"_isSpherical",null),e([h()],ie.prototype,"worldToPCSRatio",null),e([h()],ie.prototype,"renderer",void 0),e([h({constructOnly:!0})],ie.prototype,"view",void 0),e([h({constructOnly:!0})],ie.prototype,"surface",void 0),e([h()],ie.prototype,"suspended",null),e([h()],ie.prototype,"updating",null),e([h({type:Boolean})],ie.prototype,"rendersOccludedDraped",null),ie=e([c("esri.views.3d.terrain.OverlayManager")],ie);class ne{constructor(){this.inner=S(),this.outer=S(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=te}}const oe=O(),le=_(),he=new ne,ce=S(),de=S(),ue=U();var pe;!function(e){e[e.NONE=0]="NONE",e[e.EXTENT=1]="EXTENT",e[e.RERENDER_ONLY=2]="RERENDER_ONLY"}(pe||(pe={}));export{ie as OverlayManager};