@arcgis/core 6.0.0-next.29 → 6.0.0-next.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WebDocument2D.js +1 -1
- package/WebMap.d.ts +3 -19
- package/WebMap.js +1 -1
- package/WebScene.js +1 -1
- package/arcgisGlobal.d.ts +1 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/039d9bc5b5015012f811.js +1 -0
- package/assets/esri/core/workers/chunks/{b01688ccc29d33bfc82d.js → 28a821de9dbf10324033.js} +1 -1
- package/assets/esri/core/workers/chunks/{d3c3fb079ad97970f834.js → 4fb2fcc95f852bf8f86c.js} +1 -1
- package/assets/esri/core/workers/chunks/{84940d8e14caf5a27e04.js → 64b360625c68cb863a08.js} +1 -1
- package/assets/esri/core/workers/chunks/71f792a20077aa739f87.js +1 -0
- package/assets/esri/core/workers/chunks/{e480e7d5f40049a2053b.js → 7af4edc6e87d27b9d467.js} +1 -1
- package/assets/esri/core/workers/chunks/90c1d10eae7ae71889b0.js +1 -0
- package/assets/esri/core/workers/chunks/{8a485130781b49dbf608.js → 9d40786c5ceface786ba.js} +1 -1
- package/assets/esri/core/workers/chunks/aba259a70bee68d2edb7.js +1 -0
- package/assets/esri/core/workers/chunks/c33a9635c294c8774977.js +1 -0
- package/assets/esri/views/3d/environment/resources/milkyway-band.avif +0 -0
- package/chunks/GlobalIllumination.glsl.js +16 -10
- package/chunks/GlobalIlluminationBlur.glsl.js +14 -14
- package/chunks/GlobalIlluminationUpscale.glsl.js +4 -4
- package/chunks/RibbonLine.glsl.js +78 -75
- package/config.js +1 -1
- package/core/workers/WorkerHandle.js +1 -1
- package/kernel.js +1 -1
- package/layers/WMTSLayer.d.ts +1 -1
- package/layers/WMTSLayer.js +1 -1
- package/layers/mixins/TiledImagery.d.ts +7 -0
- package/layers/support/WMTSSublayer.d.ts +5 -5
- package/networks/Network.js +1 -1
- package/networks/support/TopologyValidationJobInfo.js +1 -1
- package/package.json +2 -2
- package/rest/networks/support/ValidateNetworkTopologyResult.js +1 -1
- package/support/timeUtils.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedMarkerMeshWriter.js +1 -1
- package/views/2d/layers/GeospatialPDFLayerView2D.js +1 -1
- package/views/2d/layers/SketchLayerView2D.js +1 -1
- package/views/2d/layers/WMTSLayerView2D.js +1 -1
- package/views/2d/types.d.ts +2 -1
- package/views/3d/interactive/editingTools/move/MoveTool3D.js +1 -1
- package/views/3d/interactive/editingTools/reshape/ReshapeOperation.js +1 -1
- package/views/3d/interactive/visualElements/Object3DVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/PointVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/StageObjectVisualElement.js +2 -0
- package/views/3d/layers/WMTSLayerView3D.js +1 -1
- package/views/3d/layers/graphics/Deconflictor.js +1 -1
- package/views/3d/layers/graphics/ElevationAligners.js +1 -1
- package/views/3d/layers/graphics/Graphics3DBufferGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineCalloutSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPathSymbolLayerConstants.js +1 -1
- package/views/3d/layers/graphics/Graphics3DStageObjectGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/elevationAlignmentUtils.js +1 -1
- package/views/3d/layers/graphics/pointUtils.js +1 -1
- package/views/3d/terrain/ExtentHelper.js +1 -1
- package/views/3d/terrain/PatchGeometryFactory.js +1 -1
- package/views/3d/terrain/PatchRenderData.js +1 -1
- package/views/3d/terrain/SphericalPatch.js +1 -1
- package/views/3d/terrain/TerrainRenderer.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/Tile.js +1 -1
- package/views/3d/terrain/tileUtils.js +1 -1
- package/views/3d/types.d.ts +2 -1
- package/views/3d/webgl-engine/Stage.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/attributes/PathVertexInfo.glsl.js +10 -11
- package/views/3d/webgl-engine/core/shaderLibrary/util/PackedUint32.glsl.js +2 -0
- package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/globalIllumination/GlobalIllumination.js +1 -1
- package/views/3d/webgl-engine/effects/globalIllumination/GlobalIlluminationBlur.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/globalIllumination/GlobalIlluminationUpscale.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/globalIllumination/globalIlluminationUniforms.js +2 -0
- package/views/3d/webgl-engine/effects/stars/Stars.js +1 -1
- package/views/3d/webgl-engine/lib/GeometryUtil.js +1 -1
- package/views/3d/webgl-engine/lib/Object3D.js +1 -1
- package/views/3d/webgl-engine/lib/PackedUint32.js +2 -0
- package/views/3d/webgl-engine/lib/PathGeometry.js +1 -1
- package/views/3d/webgl-engine/lib/PathVertexInfo.js +1 -1
- package/views/3d/webgl-engine/lib/RibbonLineVertexInfo.js +2 -0
- package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/HUDMaterialBaseInstance.js +1 -1
- package/views/3d/webgl-engine/materials/LineCalloutMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/LineCalloutMaterialBaseInstance.js +1 -1
- package/views/3d/webgl-engine/materials/PathMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/internal/bufferWriterUtils.js +1 -1
- package/views/3d/webgl-engine/parts/Model.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLine.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLineLayouts.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLineTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLineTextureBuffer.glsl.js +1 -1
- package/views/SelectionManager.d.ts +5 -5
- package/views/SelectionManager.js +1 -1
- package/views/input/InputManager.js +1 -1
- package/views/layers/WMTSLayerView.d.ts +16 -0
- package/views/layers/WMTSLayerView.js +2 -0
- package/views/layers/support/highlightUtils.js +1 -1
- package/views/selection/SelectionOperation.js +1 -1
- package/views/selection/types.d.ts +3 -3
- package/views/support/GeometryWorker.js +1 -1
- package/views/support/GeometryWorkerHandle.js +1 -1
- package/views/support/selectionUtils.js +1 -1
- package/webdoc/support/webdocLoadUtils.js +1 -1
- package/widgets/BatchAttributeForm/inputs/RelationshipElementInput.js +1 -1
- package/widgets/FeatureTable/AttachmentsColumn.js +1 -1
- package/widgets/FeatureTable/RelationshipColumn.js +1 -1
- package/widgets/OrientedImageryViewer/imageMeasurementWorkerUtils.js +1 -1
- package/widgets/support/SelectionList/GroupLayerItem.d.ts +5 -5
- package/widgets/support/SelectionList/GroupLayerItem.js +1 -1
- package/widgets/support/SelectionList/ItemBase.d.ts +3 -3
- package/widgets/support/SelectionList/LayerItem.js +1 -1
- package/widgets/support/SelectionList/SelectionListViewModel.d.ts +5 -6
- package/widgets/support/SelectionList/SelectionListViewModel.js +1 -1
- package/widgets/support/SelectionList/types.d.ts +3 -1
- package/widgets/support/SelectionToolbar/SelectionToolbarViewModel.js +1 -1
- package/widgets/support/Selector2D/selectorUtils.js +1 -1
- package/widgets/support/symbolPreviewUtils.js +1 -1
- package/assets/esri/core/workers/chunks/2de4296590bf9f9e9add.js +0 -1
- package/assets/esri/core/workers/chunks/4976f5567fc7f1b63d10.js +0 -1
- package/assets/esri/core/workers/chunks/53c7510df09b71ab5646.js +0 -1
- package/assets/esri/core/workers/chunks/66c2a28a851130b87c04.js +0 -1
- package/assets/esri/core/workers/chunks/e7aaf7579592b79d6dd7.js +0 -1
- package/layers/geospatialPDF/CIM2DLayerview.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{clamp as e,isPowerOfTwo as t}from"../../../core/mathUtils.js";import{maxUint16 as n}from"../../../core/typedArrayUtil.js";import{empty as r}from"../../../geometry/support/aaBoundingBox.js";import{fromValues as i}from"../../../geometry/support/aaBoundingRect.js";import{sampleElevation as a,sampleSingleElevation as o}from"./ElevationData.js";import{PatchGeometryLUT as s}from"./PatchGeometryLUT.js";import{zeroToFour as c,neighborTileIfLoadedOrSelf as l}from"./PatchRenderData.js";import{maxPatchTesselation as u,elevationNoDataValue as d}from"./TerrainConst.js";import{internalAssert as f,enableTerrainInternalChecks as p,neighborEdgeIndices as m,almostEquals as h}from"./terrainUtils.js";import{isCornerNeighbor as g}from"./Tile.js";import{compareTilesByLij as _}from"./tileUtils.js";import{compressNormal as v}from"../webgl-engine/lib/Normals.js";function y(e,t){let{tile:n,geometry:i,geometryState:a}=e,{extentInRadians:o,surface:s}=n,{isWebMercator:c,renderer:l}=s,{numVerticesPerSide:u,wireframe:d}=a,f=u-1,p=(u-2)**2,m=c&&(t===2||t===3),h=c&&(t===1||t===3),g=(+!!m+ +!!h)*we*u,_=xe(a),v=4*_,y=p+g+v,S=l.tileGeometryCache.acquire(y);i.numVerticesPerSide=u,i.vertexAttributes=S,i.maxEdgeVertexCount=_;let{boundingBox:C}=i;r(C);let w=P(e);$.update(f,o,w),x(e),i.poleVerticesStartIndex=p;let T=b(e,m,h);i.edgeVerticesStartIndex=p+g,X(e),O(e),W(i,T,d),e.intersectionData=null}function b(e,t,r){let{tile:i,localOrigin:a,geometry:o}=e,{extent:s,ellipsoid:c}=i,{boundingBox:l,numVerticesPerSide:u,vertexAttributes:d,poleVerticesStartIndex:f}=o,p=u-1,m=a[0],h=a[1],g=a[2],_=c.radius,y=s[1],b=s[3],x=[],S=f,C=(e,t)=>{let r=t*u;be(-m,-h,-g+e*_,l),x.push(new oe(e===1,r,e===1?0:2,S,we));let i=j(e===-1?y:b,_),a=e*Math.PI/2-i,o=(e===1?1:-1)*.99,s=_+0,{position:c,uv0:f}=d,{typedBuffer:C,typedBufferStride:w}=d.normalCompressed;for(let e=1;e<=we;++e){let t=i+e/we*a,r=Math.cos(t),u=Math.sin(t);for(let e=0;e<=p;e++){let t=e/p,i=$.sinLonLUT[e],a=$.cosLonLUT[e]*r,d=i*r,_=u,y=a*s-m,b=d*s-h,x=_*s-g;be(y,b,x,l),c.setValues(S,y,b,x),f.setValues(S,Math.round(t*n),Math.round(o*n)),v(C,S,a,d,_,w),++S}}};return t&&C(-1,0),r&&C(1,p),x}function x(e){let t=e.geometryState.samplerData,n=t?.length===1?t[0]:null;n?S(e,n):C(e)}function S(e,t){let{tile:n}=e;if(!n.intersectsClippingArea)return;let{geometry:r,geometryState:i,localOrigin:a}=e,{numVerticesPerSide:o}=i,s=o-2,c=o-1,{vertexAttributes:l,boundingBox:u}=r,{position:d,uv0:f}=l,{typedBuffer:p,typedBufferStride:m}=l.normalCompressed,{extent:h}=n,g=n.ellipsoid.radius,_=a[0],y=a[1],b=a[2],x=d.typedBuffer,S=d.typedBufferStride,C=f.typedBuffer,E=f.typedBufferStride;w(c,h,t);let D=0,O=t.data.values;if(1<=s){let e=le[1],t=$.sinLatLUT[1],n=$.cosLatLUT[1];for(let r=1;r<=s;r++){let i=$.sinLonLUT[r],a=$.cosLonLUT[r],o=g+T(r,1,O),s=-_+o*a*n,c=-y+o*i*n,l=-b+o*t;be(s,c,l,u);let d=(r-1)*S;x[d]=s,x[d+1]=c,x[d+2]=l;let f=(r-1)*E;C[f]=le[r],C[f+1]=e}}for(let e=1;e<=s;e++){let t=$.sinLatLUT[e],n=$.cosLatLUT[e],r=e+1,i=le[r],a=$.sinLatLUT[r],o=$.cosLatLUT[r],l=$.sinLonLUT[0],d=$.cosLonLUT[0],f=g+T(0,e,O),h=d*n*f-_,w=l*n*f-y,k=t*f-b,A=D*S,j=x[A],M=x[A+1],N=x[A+2];for(let l=1;l<=s;l++){let d=$.sinLonLUT[l],f=$.cosLonLUT[l],A=0,P=0,F=0;if(l<s){let e=(D+1)*S;A=x[e],P=x[e+1],F=x[e+2]}else{let r=$.sinLonLUT[c],i=$.cosLonLUT[c],a=g+T(c,e,O);A=i*n*a-_,P=r*n*a-y,F=t*a-b}let I=h,L=w,R=k;h=j,w=M,k=N,j=A,M=P,N=F;let z=A-I,B=P-L,V=F-R,H=0,U=0,ee=0;if(e>1){let e=(D-s)*S;H=x[e],U=x[e+1],ee=x[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=g+T(l,0,O);H=f*t*n-_,U=d*t*n-y,ee=e*n-b}let W=g+T(l,r,O),G=f*o*W-_,K=d*o*W-y,q=a*W-b;if(e<s){let e=D+s,t=e*S;x[t]=G,x[t+1]=K,x[t+2]=q,be(G,K,q,u);let n=e*E;C[n]=le[l],C[n+1]=i}let te=H-G,J=U-K,Y=ee-q,X=f*n,Z=d*n,ne=t;ne*ne<.999&&(X=V*J-B*Y,Z=z*Y-V*te,ne=B*te-z*J);let Q=1/Math.sqrt(X*X+Z*Z+ne*ne);v(p,D,X*Q,Z*Q,ne*Q,m),++D}}}function C(e){let{tile:t}=e;if(!t.intersectsClippingArea)return;let{geometry:r,geometryState:i,localOrigin:o}=e,{numVerticesPerSide:s,samplerData:c}=i,l=s-2,u=s-1,{vertexAttributes:d,boundingBox:f}=r,{position:p,uv0:m}=d,{typedBuffer:h,typedBufferStride:g}=d.normalCompressed,{extent:_}=t,y=_[0],b=_[2],x=_[1],S=_[3],C=t.ellipsoid.radius,w=o[0],T=o[1],E=o[2],D=p.typedBuffer,O=p.typedBufferStride,k=1/u,A=0;if(1<=l){let e=k,t=x*(1-e)+S*e,r=$.sinLatLUT[1],i=$.cosLatLUT[1];for(let o=1;o<=l;o++){let s=o*k,l=y*(1-s)+b*s,u=$.sinLonLUT[o],d=$.cosLonLUT[o],p=C+a(l,t,c),h=-w+p*d*i,g=-T+p*u*i,_=-E+p*r;be(h,g,_,f);let v=(o-1)*O;D[v]=h,D[v+1]=g,D[v+2]=_,m.setValues(o-1,Math.round(s*n),Math.round(e*n))}}for(let e=1;e<=l;e++){let t=e*k,r=x*(1-t)+S*t,i=$.sinLatLUT[e],o=$.cosLatLUT[e],s=e+1,d=s*k,p=x*(1-d)+S*d,_=$.sinLatLUT[s],j=$.cosLatLUT[s],M=$.sinLonLUT[0],N=$.cosLonLUT[0],P=C+a(y,r,c),F=N*o*P-w,I=M*o*P-T,L=i*P-E,R=A*O,z=D[R],B=D[R+1],V=D[R+2];for(let t=1;t<=l;t++){let s=t*k,S=y*(1-s)+b*s,M=$.sinLonLUT[t],N=$.cosLonLUT[t],P=0,R=0,H=0;if(t<l){let e=(A+1)*O;P=D[e],R=D[e+1],H=D[e+2]}else{let e=$.sinLonLUT[u],t=$.cosLonLUT[u],n=C+a(b,r,c);P=t*o*n-w,R=e*o*n-T,H=i*n-E}let U=F,ee=I,W=L;F=z,I=B,L=V,z=P,B=R,V=H;let G=P-U,K=R-ee,q=H-W,te=0,J=0,Y=0;if(e>1){let e=(A-l)*O;te=D[e],J=D[e+1],Y=D[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=C+a(S,x,c);te=N*t*n-w,J=M*t*n-T,Y=e*n-E}let X=C+a(S,p,c),Z=N*j*X-w,ne=M*j*X-T,Q=_*X-E;if(e<l){let e=A+l,t=e*O;D[t]=Z,D[t+1]=ne,D[t+2]=Q,be(Z,ne,Q,f),m.setValues(e,Math.round(s*n),Math.round(d*n))}let re=te-Z,ie=J-ne,ae=Y-Q,oe=N*o,se=M*o,ce=i;ce*ce<.999&&(oe=q*ie-K*ae,se=G*ae-q*re,ce=K*re-G*ie);let le=1/Math.sqrt(oe*oe+se*se+ce*ce);v(h,A,oe*le,se*le,ce*le,g),++A}}}function w(t,r,i){let a=r[0],o=r[2],s=r[1],c=r[3],l=1/t,{dx:u,dy:d,x0:f,y1:p,safeWidth:m}=i,h=i.data.width;for(let r=0;r<=t;r++){let t=r*l,i=e(u*(a*(1-t)+o*t-f),0,m),g=Math.floor(i);ue[r]=g,pe[r]=i-g;let _=e(d*(p-(s*(1-t)+c*t)),0,m),v=Math.floor(_);de[r]=v*h,fe[r]=(v+1)*h,me[r]=_-v,le[r]=Math.round(t*n)}}function T(e,t,n){let r=ue[e],i=pe[e],a=de[t],o=fe[t],s=me[t],c=a+r,l=n[c],u=n[c+1],d=n[o+r],f=n[o+r+1];if(l+d+u+f>=ce)return 0;let p=l+(u-l)*i;return p+(d+(f-d)*i-p)*s}function E(e){e.tile.intersectsClippingArea&&(O(e),ie(e),e.intersectionData=null)}function D(e){e.tile.intersectsClippingArea&&(Z(e),O(e),ie(e),ae(e),e.intersectionData=null)}function O(e){e.tile.intersectsClippingArea&&(A(e),k(e))}function k(e){let{geometry:r,geometryState:i,tile:s,localOrigin:c}=e,{level:u,extent:d,extentInRadians:g,ellipsoid:y}=s,b=y.radius,x=g[0],S=g[2],C=g[1],w=g[3],{samplerData:T}=i,E=d[0],D=d[2],O=d[1],k=d[3],A=P(e),{boundingBox:j,vertexAttributes:M}=r,N=c[0],F=c[1],I=c[2],{position:L,uv0:R}=M,z=L.typedBuffer,B=L.typedBufferStride,V=R.typedBuffer,H=R.typedBufferStride,{typedBuffer:U,typedBufferStride:ee}=M.normalCompressed,W=T?.length===1?T[0]:null,G=(e,t,n)=>W?o(e,t,W)??0:a(e,t,T)??0;for(let c=0;c<4;++c){let g=c===1||c===3,y=i.edgeResolutions[c];f(t(y));let M=y+1,P=l(s,i.edgePeerNeighbors[c]);if(_e(s,P,c)&&ne(e,c,P))continue;let L=P!=null;f(!L||P.level===s.level),f(!L||_(s,P)<=0);let R=P?.renderData?.geometryState;if(p){let e=s.surface;if(!P&&e&&!e.updatingRootTiles){let t=m[c],n=s.findNeighborTile(t,e=>e.loaded||e.leaf||e.level===s.level);n?n.intersectsClippingArea&&(f(!n.loaded),f(!n.leaf),f(n.level===u)):f(e?.rootTiles==null||!s.shouldHaveNeighbor(t))}}let K=c===1?d[2]:d[0],q=P?.extent,te=q&&g?c===1?q[0]:q[2]:K,J=c===0?d[3]:d[1],Y=+(c===1),X=+(c===0),Z=c===1?S:x,Q=c===0?w:C,re=Math.sin(Z),ie=Math.cos(Z),ae=Math.sin(Q),oe=Math.cos(Q),se=R?.samplerData,$=se?.length===1?se[0]:null,ce=(e,t,n)=>$?o(n,t,$)??0:a(n,t,se)??0,le=L?(e,t,n)=>(G(e,t)+ce(e,t,n))*.5:G,ue=r.outerEdgesOffsetAndLength[c*2+0],de=W!=null||T!=null&&T.some(e=>e!=null),fe=$!=null||se!=null&&se.some(e=>e!=null),pe=de||fe,me=1/y,he=n*me,ge=Y*n,ve=X*n,ye=ue;f(!q||h(q[2]-q[0],d[2]-d[0])),(()=>{let e=c===1?-1:+(c===3),t=c===0?-1:+(c===2),n=(d[2]-d[0])*me,r=e*n,i=t*n,s=S-x,l=g?s*me*e:0,u=g?0:t*me,f=X,p=g?Z+l:Z,m=g?Math.sin(p):re,h=g?Math.cos(p):ie,_=g?Z-l:Z,y=g?Math.sin(_):re,C=g?Math.cos(_):ie,w=f+u,P=g?Q:A(w),R=g?ae:Math.sin(P),G=g?oe:Math.cos(P),q=f-u,Y=g?Q:A(q),ne=g?ae:Math.sin(Y),ce=g?oe:Math.cos(Y),ue=0,de=0,fe=0;{let e=0*me,t=g?K:E*(1-e)+D*e,n=g?te:t,r=g?O*(1-e)+k*e:J,i=g?Z:x*(1-e)+S*e,a=g?re:Math.sin(i),o=g?ie:Math.cos(i),s=g?A(e):Q,c=g?Math.sin(s):ae,l=g?Math.cos(s):oe,u=b+le(t,r,n);ue=o*l*u,de=a*l*u,fe=c*u}let _e=0,xe=0,Se=0;{let e=1*me,t=g?K:E*(1-e)+D*e,n=g?te:t,r=g?O*(1-e)+k*e:J,i=g?Z:x*(1-e)+S*e,a=g?re:Math.sin(i),o=g?ie:Math.cos(i),s=g?A(e):Q,c=g?Math.sin(s):ae,l=g?Math.cos(s):oe,u=b+le(t,r,n);_e=o*l*u,xe=a*l*u,Se=c*u}for(let e=1;e<M-1;++e){let t=0,n=0,s=0;{let r=(e+1)*me,i=g?K:E*(1-r)+D*r,a=g?te:i,o=g?O*(1-r)+k*r:J,c=g?Z:x*(1-r)+S*r,l=g?re:Math.sin(c),u=g?ie:Math.cos(c),d=g?A(r):Q,f=g?Math.sin(d):ae,p=g?Math.cos(d):oe,m=b+le(i,o,a);t=u*p*m,n=l*p*m,s=f*m}let l=t,u=n,d=s,f=_e,p=xe,_=Se;_e=l,xe=u,Se=d;{let t=ye+e,n=t*B,r=f-N,i=p-F,a=_-I;z[n]=r,z[n+1]=i,z[n+2]=a,be(r,i,a,j);let o=Math.round(e*he),s=t*H;V[s]=g?ge:o,V[s+1]=g?o:ve}let w=ue,M=de,P=fe;ue=f,de=p,fe=_;let q=f,Y=p,X=_,Ce=1/Math.sqrt(q*q+Y*Y+X*X),we=X*Ce,Te=0,Ee=0,De=0;if(pe&&we*we<.999){let t=0,n=0,s=0;{let e=c===0?-1:1;t=e*(l-w),n=e*(u-M),s=e*(d-P)}{let l=e*me,u=g?K:E*(1-l)+D*l,d=g?te:u,f=g?O*(1-l)+k*l:J,p=g?Z:x*(1-l)+S*l,_=g?re:Math.sin(p),v=g?ie:Math.cos(p),w=g?A(l):Q,j=g?Math.sin(w):ae,M=g?Math.cos(w):oe,N=q,P=Y,F=X;if(L){let e=d-r,t=f-i,n=b+($?o(e,t,$)??0:a(e,t,se)??0),s=g?y:_,c=g?C:v,l=g?j:ne,u=g?M:ce;N=c*u*n,P=s*u*n,F=l*n}{let e=u+r,l=f+i,d=b+(W?o(e,l,W)??0:a(e,l,T)??0),p=g?m:_,y=g?h:v,x=g?j:R,S=g?M:G,C=y*S*d,w=p*S*d,E=x*d;L||(N=2*q-C,P=2*Y-w,F=2*X-E);let D=c===3?-1:1,O=D*(N-C),k=D*(P-w),A=D*(F-E);Te=s*k-n*A,Ee=t*A-s*O,De=n*O-t*k;let I=1/Math.sqrt(Te*Te+Ee*Ee+De*De);Te*=I,Ee*=I,De*=I}}}else Te=q*Ce,Ee=Y*Ce,De=X*Ce;v(U,ye+e,Te,Ee,De,ee)}})()}}function A(e){Q(e)}function j(e,t){return Math.PI/2-2*Math.atan(Math.exp(-e/t))}function M(e,t,n,r){return j(e*(1-r)+t*r,n)}function N(e,t,n){return e*(1-n)+t*n}function P(e){let{tile:t}=e;if(t.surface.isWebMercator){let e=t.extent,n=t.ellipsoid.radius;return t=>M(e[1],e[3],n,t)}let n=t.extentInRadians;return e=>N(n[1],n[3],e)}function F(e){let{tile:t,geometryState:n,geometry:i}=e,{extent:a,surface:o}=t,{wireframe:s}=n,c=a[0],l=a[1],u=a[2],d=a[3],f=u-c,p=d-l,{numVerticesPerSide:m,clippingArea:h}=n,g=h==null?0:Math.max(0,(h[0]-c)/f),_=h==null?0:Math.max(0,(h[1]-l)/p),v=h==null?1:Math.min(1,(h[2]-c)/f),y=h==null?1:Math.min(1,(h[3]-l)/p),b=(m-2)**2,x=xe(n),S=b+4*x,C=o.renderer.tileGeometryCache.acquire(S),{boundingBox:w}=i;r(w),i.numVerticesPerSide=m,i.vertexAttributes=C,i.maxEdgeVertexCount=x,i.minu=g,i.minv=_,i.maxu=v,i.maxv=y,I(e),i.edgeVerticesStartIndex=b,X(e),z(e),W(i,[],s),e.intersectionData=null}function I(t){let r=t.tile;if(!r.intersectsClippingArea)return;let{geometry:i,geometryState:s,localOrigin:c}=t,{samplerData:l,clippingArea:u,numVerticesPerSide:d}=s,{surface:f,extent:p,ellipsoid:m}=r,{isWebMercatorOnPlateCarree:h}=f,g=u??he,_=p[0],y=p[1],b=p[2],x=p[3],S=Math.max(_,g[0]),C=Math.min(b,g[2]),w=Math.max(y,g[1]),T=Math.min(x,g[3]),E=m.radius,D=r.horizontalScale,O=d-1,k=d-2,{minu:A,minv:j,maxu:M,maxv:N,boundingBox:P,vertexAttributes:F}=i,{position:I,uv0:L}=F,{typedBuffer:R,typedBufferStride:z}=F.normalCompressed,B=c[0],V=c[1],H=c[2],U=I.typedBuffer,ee=I.typedBufferStride,W=0,G=e(y,w,T),K=h?(Math.PI/2-2*Math.atan(Math.exp(-G/E)))*E:G*D,q=1/O,te=e(y*(1-q)+x*q,w,T),J=h?(Math.PI/2-2*Math.atan(Math.exp(-te/E)))*E:te*D,Y=K,X=J,Z=l?.length===1?l[0]:null,ne=Z?(e,t)=>o(e,t,Z)??0:(e,t)=>a(e,t,l)??0;for(let t=1;t<=k;t++){let r=t/O,i=e(y*(1-r)+x*r,w,T),a=e(r,j,N),o=X,s=(t-1)/O,c=e(y*(1-s)+x*s,w,T),l=Y,u=(t+1)/O,d=e(y*(1-u)+x*u,w,T),f=h?(Math.PI/2-2*Math.atan(Math.exp(-d/E)))*E:d*D,p=e(u,j,N);Y=X,X=f;let m=e(_,S,C),g=m*D,F=ne(m,i),I=1/O,G=e(I,A,M),K=e(_*(1-G)+b*G,S,C),q=G,te=K,J=K*D,Z=ne(K,i);if(t===1){let t=J-B,r=Y-V,i=Z-H,o=0*ee;U[o]=t,U[o+1]=r,U[o+2]=i,be(t,r,i,P);let s=e(I,A,M);L.setValues(W,Math.round(s*n),Math.round(a*n))}for(let r=1;r<=k;r++){let s=J,u=Z,m=(r+1)/O,h=e(m,A,M),y=e(_*(1-m)+b*m,S,C),x=te;te=y;{let e=W+1,s=e*ee;if(t===1||r===k){let c=ne(y,i),l=y*D,u=o,d=c;if(t===1&&r<k){let t=l-B,r=u-V,i=d-H;U[s]=t,U[s+1]=r,U[s+2]=i,be(t,r,i,P),L.setValues(e,Math.round(h*n),Math.round(a*n))}J=l,Z=d}else J=U[s]+B,Z=U[s+2]+H}let w=J,T=Z,E=g,j=F;g=s,F=u;let N=(W-k)*ee,I=t===1?ne(x,c):U[N+2]+H,G=ne(x,d);if(t<k){let e=W+k,t=e*ee,r=s-B,i=f-V,a=G-H;U[t]=r,U[t+1]=i,U[t+2]=a,be(r,i,a,P);let o=q;q=h,L.setValues(e,Math.round(o*n),Math.round(p*n))}{let e=w-E,t=T-j,n=l-f,r=I-G,i=n*t,a=e*r,o=-n*e,s=i*i+a*a+o*o;if(s===0)v(R,W,0,0,1,z);else{let e=1/Math.sqrt(s);v(R,W,i*e,a*e,o*e,z)}}++W}}}function L(e){e.tile.intersectsClippingArea&&(Z(e),z(e),ie(e),ae(e),e.intersectionData=null)}function R(e){e.tile.intersectsClippingArea&&(z(e),ie(e),e.intersectionData=null)}function z(e){e.tile.intersectsClippingArea&&(V(e),B(e))}function B(n){let{geometry:r,geometryState:i,localOrigin:s}=n,c=n.tile,{surface:u,extent:d}=c,{clippingArea:h,samplerData:g}=i,v=h??he,y=d[0],b=d[2],x=d[1],S=d[3],C=[S>v[3],b>v[2],x<v[1],y<v[0]],w=c.horizontalScale,T=ee(u.isWebMercatorOnPlateCarree,c.ellipsoid.radius,w),{minu:E,minv:D,maxu:O,maxv:k,boundingBox:A}=r,j=Math.max(y,v[0]),M=Math.min(b,v[2]),N=Math.max(x,v[1]),P=Math.min(S,v[3]),F=s[0],I=s[1],L=s[2],R=g?.length===1?g[0]:void 0,z=R?(e,t)=>o(e,t,R)??0:(e,t)=>a(e,t,g)??0;for(let s=0;s<4;++s){let d=s===1||s===3,h=i.edgeResolutions[s];f(t(h));let v=h+1,R=C[s],B=l(c,i.edgePeerNeighbors[s]);if(!R&&_e(c,B,s)&&ne(n,s,B))continue;let V=B!=null&&!R,H=B?.renderData?.geometryState;if(p&&(f(!V||B.level===c.level),f(!V||_(c,B)<=0),c&&!B&&!u.updatingRootTiles)){let e=m[s],t=c.findNeighborTile(e,e=>e.loaded||e.leaf||e.level===c.level);u.updatingRootTiles||(t?t.intersectsClippingArea&&(f(!t.loaded),f(!t.leaf),f(t.level===c.level)):f(u?.rootTiles==null||!c.shouldHaveNeighbor(e)))}let U=e(s===1?b:y,j,M),ee=e(s===0?S:x,N,P),W=H?.samplerData,G=e(+(s===1),E,O),K=e(+(s===0),D,k),q=W?.length===1?W[0]:null,te=(e,t)=>q?o(e,t,q)??0:a(e,t,W)??0,J=V?(e,t)=>(te(e,t)+z(e,t))*.5:z,Y=(b-y)/h,X=d?s===1?Y:-Y:0,Z=d?0:s===0?Y:-Y,Q=-X,re=-Z,ie=0,ae=0,oe=0;{let t=0/h,n=d?U:e(y*(1-t)+b*t,j,M),r=d?e(x*(1-t)+S*t,N,P):ee,i=J(n,r);ie=n*w,ae=T(r),oe=i}let se=0,$=0,ce=0;{let t=1/h,n=d?U:e(y*(1-t)+b*t,j,M),r=d?e(x*(1-t)+S*t,N,P):ee,i=J(n,r),a=n*w,o=T(r),s=i;se=a,$=o,ce=s}for(let t=1;t<v-1;++t){let n=t/h,i=se,o=$,c=ce;{let a=d?G:e(n,E,O),l=d?e(n,D,k):K,u=i-F,f=o-I,p=c-L;be(i,f,p,A),r.setEdgeVertexFromValuesRawPositionUV(s,t,u,f,p,a,l)}{let n=(t+1)/h,r=d?U:e(y*(1-n)+b*n,j,M),i=d?e(x*(1-n)+S*n,N,P):ee,a=J(r,i);se=r*w,$=T(i),ce=a}let l=se,u=$,f=ce,p=ie,m=ae,_=oe;ie=i,ae=o,oe=c;let v=0,C=0,R=0;if(d){let t=u-o,r=f-c,l=m-o,d=_-c,p=e(x*(1-n)+S*n,N,P),h=U+Q,y=p,b=h*w,T=a(h,y,g),E=b-i,D=T-c,O=s===3?-1:1;if(v=O*(-l+t)*D,C=O*E*(-d+r),R=-O*E*(-l+t),V){let e=U+X,n=p,o=e*w,s=a(e,n,W),u=o-i,f=s-c;v=(-l+t)*(D-f),C=(E-u)*(-d+r),R=-(E-u)*(-l+t)}}else{let t=l-i,r=f-c,u=p-i,d=_-c,m=e(y*(1-n)+b*n,j,M),h=m,x=ee+re,S=a(h,x,g)-c,w=T(x)-o,E=s===2?-1:1;if(v=E*w*(-d+r),C=E*(-u+t)*S,R=-E*w*(-u+t),V){let e=m,n=ee+Z,i=T(n),s=a(e,n,W)-c,l=i-o;v=(-w+l)*(-d+r),C=(-u+t)*(-S+s),R=-(-w+l)*(-u+t)}}let z=1/Math.sqrt(v*v+C*C+R*R);r.setEdgeNormalFromValues(s,t,v*z,C*z,R*z)}}}function V(e){Q(e)}function H(e,t){return(Math.PI/2-2*Math.atan(Math.exp(-e/t)))*t}function U(e,t){return e*t}function ee(e,t,n){return e?e=>H(e,t):e=>U(e,n)}function W(e,t,n){let{numVerticesPerSide:r,vertexAttributes:i,maxEdgeVertexCount:a}=e,o=r-1,s=i.count,l=r-3,u=r-3,d=2*l*u,f=4*(o+a-3),p=c.reduce((t,n)=>t+(o+e.getEdgeCount(n)-3),0),m=t.reduce((e,t)=>e+o*((t.latitudeResolution-1)*2+1),0),h=3*(n?2:1),g=(d+f+m)*h,_=s>=65536?new Uint32Array(g):new Uint16Array(g);for(let e=0;e<g;++e)_[e]=0;e.indices=_,e.indexCount=(d+p+m)*h,e.poleIndicesStartIndex=d*h,e.edgeIndicesStartIndex=(d+m)*h,n?(te(e),J(e,t),Y(e)):(G(e),K(e,t),q(e))}function G(e){let{numVerticesPerSide:t,indices:n,vertexAttributes:r}=e,{position:i}=r,{typedBuffer:a,typedBufferStride:o}=i,s=t-2,c=t-3,l=t-3,u=0;for(let e=0;e<c;++e){let t=e*s;for(let e=0;e<l;++e){let r=t+e,i=r+1,c=i+s,l=c-1;Se(r,i,c,l,o,a)?(n[u]=r,n[u+1]=i,n[u+2]=c,n[u+3]=c,n[u+4]=l,n[u+5]=r):(n[u]=r,n[u+1]=i,n[u+2]=l,n[u+3]=l,n[u+4]=i,n[u+5]=c),u+=6}}}function K(e,t){let{numVerticesPerSide:n,indices:r,poleIndicesStartIndex:i}=e,a=n-1,o=i;for(let i of t){let t=i.isNorth?1:2,s=i.isNorth?2:1,c=i.isNorth?3:4,l=i.isNorth?4:3,u=e.getEdgeVertexIndex(i.connectedOuterEdgeOffset,0),d=1;for(let e=0;e<i.latitudeResolution;++e){let f=e===0?i.rowOffset:u+n;for(let n=0;n<a;n++){let a=f+n;r[o]=u,r[o+t]=u+1,r[o+s]=a,e<i.latitudeResolution-1?(r[o+c]=u+1,r[o+l]=a+1,r[o+5]=a,o+=6):o+=3,u+=d}u=f,d=1}}}function q(e){let{indices:t,numVerticesPerSide:n,edgeIndicesStartIndex:r}=e,i=n-1,a=i-2,o=r;for(let n=0;n<4;++n){let r=ye[n],s=0,c=0,l=e.getEdgeCount(n),u=r.count;f(u===i-1);let d=n===1||n===2,p=d?1:2,m=d?2:1,h=e.getEdgeFirstVertexIndex(n),g=r.vertex0Index,_=r.stride;for(;s<l-1||c<u-1;){let e=g+c*_,n=h+s*1,r=s<l-1,d=c<u-1,f=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||f<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+p]=n,t[o+m]=b,o+=3}}e.indexCount=o}function te(e){let{indices:t,numVerticesPerSide:n,vertexAttributes:r}=e,{position:i}=r,{typedBuffer:a,typedBufferStride:o}=i,s=n-2,c=0;for(let e=0;e<n-3;++e){let r=e*s;for(let i=0;i<n-3;++i){let n=e*s+i,l=n+1,u=l+s,d=u-1,f=r+i,p=f+1,m=p+s;Se(f,p,m,m-1,o,a)?(Ce(t,c,n,l,u),c+=6,Ce(t,c,u,d,n)):(Ce(t,c,n,l,d),c+=6,Ce(t,c,d,u,l)),c+=6}}}function J(e,t){let{indices:n,numVerticesPerSide:r,poleIndicesStartIndex:i}=e,a=r-1,o=i;for(let i of t){let t=i.connectedOuterEdgeOffset,s=e.getEdgeVertexIndex(t,0),c=1;for(let e=0;e<i.latitudeResolution;++e){let t=e===0?i.rowOffset:s+r;for(let r=0;r<a;r++)Ce(n,o,s,s+1,t+r),o+=6,e<i.latitudeResolution-1&&(Ce(n,o,s+1,t+r+1,t+r),o+=6),s+=c;s=t,c=1}}}function Y(e){let{indices:t,numVerticesPerSide:n,edgeIndicesStartIndex:r}=e,i=n-1,a=i-2,o=r;for(let n=0;n<4;++n){let r=ye[n],s=0,c=0,l=e.getEdgeCount(n),u=r.count;f(u===i-1);let d=n===1||n===2,p=d?1:3,m=d?3:1,h=e.getEdgeFirstVertexIndex(n),g=r.vertex0Index,_=r.stride;for(;s<l-1||c<u-1;){let e=g+c*_,n=h+s*1,r=s<l-1,d=c<u-1,f=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||f<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+p]=n,t[o+p+1]=n,t[o+m]=b,t[o+m+1]=b,t[o+5]=e,o+=6}}e.indexCount=o}function X(e){let{geometry:t,geometryState:n}=e,{edgeResolutions:r}=n,{numVerticesPerSide:i,edgeVerticesStartIndex:a}=t,o=i-2,s=a;for(let e=0;e<4;++e){{let t=e===1?o-1:0,n=e===0?o-1:0,r=e===0||e===2,i=+!!r,a=+!r,s=n*o+t,c=a*o+i,l=ye[e];l.vertex0Index=s,l.stride=c,l.count=o}{let n=r[e]+1;t.outerEdgesOffsetAndLength[e*2+0]=s,t.outerEdgesOffsetAndLength[e*2+1]=n,s+=n}}}function Z(e){X(e),e.geometryState.wireframe?Y(e.geometry):q(e.geometry)}function ne(r,i,a){let{geometryState:o,geometry:s,tile:c,localOrigin:l}=r,u=i===1||i===3,d=o.edgeResolutions[i];f(t(d));let p=d+1,{boundingBox:m,minu:h,minv:g,maxu:_,maxv:v,vertexAttributes:y}=s,b=e(+(i===1),h,_),x=e(+(i===0),g,v),S=a.renderData,C=S.geometryState;if(!C||!S.geometry.vertexAttributes)return!1;let w=S.geometry,T=(i+2)%4,E=w.getEdgeCount(T),D=c.getNeighborEdgeStartVertexIndex(i,a)*d,O=d*2**(c.level-a.level);f(C.edgeResolutions[T]===O),f(E-1===O);let k=S.localOrigin[0]-l[0],A=S.localOrigin[1]-l[1],j=S.localOrigin[2]-l[2],M=s.getEdgeFirstVertexIndex(i),{position:N,uv0:P}=y,F=N.typedBuffer,I=N.typedBufferStride,L=y.normalCompressed,R=L.typedBuffer,z=L.typedBufferStride,B=w.vertexAttributes,V=w.getEdgeFirstVertexIndex(T),H=B.position.typedBuffer,U=B.position.typedBufferStride,ee=B.normalCompressed.typedBuffer,W=B.normalCompressed.typedBufferStride;for(let t=1;t<p-1;++t){let r=D+t,i=M+t,a=V+r,o=i*I,s=a*U,c=H[s]+k,l=H[s+1]+A,f=H[s+2]+j;F[o]=c,F[o+1]=l,F[o+2]=f,be(c,l,f,m);let p=i*z,y=a*W;R[p]=ee[y],R[p+1]=ee[y+1];let S=t/d,C=u?b:e(S,h,_),w=u?e(S,g,v):x;P.setValues(i,Math.round(C*n),Math.round(w*n))}return!0}function Q(t){let{geometry:r,geometryState:i,localOrigin:o}=t,{clippingArea:s,samplerData:c}=i,{minu:l,minv:u,maxu:d,maxv:p,boundingBox:m,vertexAttributes:h}=r,g=t.tile,{surface:v,ellipsoid:y,extent:b,extentInRadians:x,horizontalScale:S}=g,C=v.view?.viewingMode===`local`,w=y.radius,T=0,E=0,D=0,O=C?(()=>{let t=s,n=t!=null&&(b[3]>t[3]||b[2]>t[2]||b[1]<t[1]||b[0]<t[0]),r=ee(v.isWebMercatorOnPlateCarree,w,S);return(i,a,o)=>{let s=i===0?b[0]:b[2],c=a===0?b[1]:b[3],l=n?e(s,t[0],t[2]):s,u=n?e(c,t[1],t[3]):c,d=o;T=l*S,E=r(u),D=d}})():(e,t,n)=>{let r=x[t===0?1:3],i=x[e===0?0:2],a=Math.cos(r),o=Math.sin(r),s=Math.sin(i),c=Math.cos(i),l=w+n;T=c*a*l,E=s*a*l,D=o*l},k=0,A=0,j=0,M=0,N=0,F=0,I=0,L=0,R=0,z=C&&v.isWebMercatorOnPlateCarree,B=(e,t,n,r,i)=>{let a=0,o=0,s=0;if(C){let e=t*S,i=z?(Math.PI/2-2*Math.atan(Math.exp(-n/w)))*w:n*S,c=r;a=e-T,o=i-E,s=c-D}else{let i=P(e),c=e.tile,l=c.extent,u=c.extentInRadians,d=(t-l[0])/(l[2]-l[0]),f=(n-l[1])/(l[3]-l[1]),p=u[0]*(1-d)+u[2]*d,m=i(f),h=Math.cos(m),g=Math.sin(m),_=Math.sin(p),v=Math.cos(p),y=w+r,b=v*h*y,x=_*h*y,S=g*y;a=b-T,o=x-E,s=S-D}switch(i){case 0:I+=a,L+=o,R+=s;break;case 1:M-=a,N-=o,F-=s;break;case 2:I-=a,L-=o,R-=s;break;case 3:M+=a,N+=o,F+=s}},V=s??he,H=b[0],U=b[2],W=b[1],G=b[3],K=[G>V[3],U>V[2],W<V[1],H<V[0]],q=Math.max(H,V[0]),te=Math.min(U,V[2]),J=Math.max(W,V[1]),Y=Math.min(G,V[3]),X=e=>Math.max(V[0],Math.min(V[2],e)),Z=e=>Math.max(V[1],Math.min(V[3],e)),ne=e=>{let t=i.cornerNeighborCornerTiles;k=0,A=0,j=1,M=0,N=0,F=0,I=0,L=0,R=0;let n=1/0;for(let r=0;r<4;++r){let i=t[e*4+r];n=Math.min(n,i?.level??1/0)}for(let r=0;r<4;++r){let i=t[e*4+r];ge[r]=i?.level===n?i:null}let r=1,o=0;for(let e=0;e<4;++e){let t=ge[e];t&&(r=Math.max(r,t?.renderData.geometryState.numVerticesPerSide),o=t.extent[2]-t.extent[0])}let s=o,c=r;f(c>1);let l=s/c;for(let e=0;e<4;++e){let t=ge[(e+3)%4],n=ge[e%4];if(!t&&!n)continue;let r=e===0?1:e===1?2:e===2?3:0,i=e===0?2:e===1?3:e===2?0:1;if(t&&n){let o=se[e][0]*l,s=se[e][1]*l,c=t.extent,u=X(c[r===0||r===1?2:0]+o),d=Z(c[r===0||r===3?3:1]+s),f=n.extent,p=X(f[i===0||i===1?2:0]+o),m=Z(f[i===0||i===3?3:1]+s),h=t.renderData,g=n.renderData,_=a(u,d,h.geometryState.samplerData),v=a(p,m,g.geometryState.samplerData);B(h,u,d,.5*(_+v),e)}else{let o=t??n,s=t?r:i,c=o.extent,u=se[e],d=X(c[s===0||s===1?2:0]+u[0]*l),f=Z(c[s===0||s===3?3:1]+u[1]*l),p=o.renderData,m=a(d,f,p.geometryState.samplerData);B(p,d,f,m,e)}}if(!C){let e=Math.sqrt(T*T+E*E+D*D);k=T/e,A=E/e,j=D/e}if(C||j*j<.999){let e=Math.sqrt(M*M+N*N+F*F);M/=e,N/=e,F/=e;let t=Math.sqrt(I*I+L*L+R*R);I/=t,L/=t,R/=t,k=F*L-N*R,A=M*R-F*I,j=N*I-M*L;let n=1/Math.sqrt(k*k+A*A+j*j);k*=n,A*=n,j*=n}},Q=i.cornerNeighborCornerTiles;for(let t=0;t<4;++t){let s=t,v=(t+1)%4,y=+(t===0||t===1),b=+(t===0||t===3),x=e(y,l,d),S=e(b,u,p),C=r.getEdgeFirstVertexIndex(s),w=r.getEdgeCount(s),M=t===0||t===3?w-1:0,N=r.getEdgeFirstVertexIndex(v),P=r.getEdgeCount(v),F=t===0||t===1?P-1:0,I=-1;for(let e=0;e<4;++e){let n=Q[t*4+e],r=Q[t*4+I];n&&(I===-1||_(r,n)>0)&&(I=e)}let L=I,R=Q[t*4+L];if(R!==g){let e=g.level-R.level,r=2**e,a=[R.lij[0]+e,R.lij[1]*r,R.lij[2]*r],s=[a[1]+r===g.lij[1],t===0&&(L===1||L===0&&R!==Q[t*4+3])||t===1&&(L===0||L===1&&R!==Q[t*4+2]),a[1]===g.lij[1]+1,t===2&&(L===3||L===2&&R!==Q[t*4+1])||t===3&&(L===2||L===3&&R!==Q[t*4+0])],c=s.reduce((e,t)=>e+ +!!t,0);f(c===1||c===2);let l=-1,u=-1,d=R.renderData;if(c===1){let e=s.findIndex(e=>e);f(0<=e&&e<=3),l=(e+2)%4;let n=i.edgeResolutions[e];u=g.getNeighborEdgeStartVertexIndex(e,R)*n+n*+(e===0&&t===0||e===1&&t===0||e===2&&t===1||e===3&&t===3)}else{f(s[1]||s[3]),l=s[1]?3:1;let e=d.geometryState.edgeResolutions[l];u=t===0||t===3?0:e}let p=d.geometry;{let e=C+M,t=N+F,r=p.getEdgeFirstVertexIndex(l)+u,i=p.vertexAttributes,a=d.localOrigin,s=i.position,c=s.typedBuffer,f=r*s.typedBufferStride,g=c[f]+a[0]-o[0],_=c[f+1]+a[1]-o[1],v=c[f+2]+a[2]-o[2];be(g,_,v,m);let y=h.position,b=y.typedBuffer,w=e*y.typedBufferStride;b[w]=g,b[w+1]=_,b[w+2]=v;let T=t*y.typedBufferStride;b[T]=g,b[T+1]=_,b[T+2]=v;let E=h.uv0;E.setValues(e,Math.round(x*n),Math.round(S*n)),E.setValues(t,Math.round(x*n),Math.round(S*n));{let n=i.normalCompressed.typedBuffer,a=r*i.normalCompressed.typedBufferStride,o=h.normalCompressed,s=o.typedBuffer;{let t=e*o.typedBufferStride;s[t]=n[a],s[t+1]=n[a+1]}{let e=t*o.typedBufferStride;s[e]=n[a],s[e+1]=n[a+1]}}}}else{let n=K[s],i=K[v],l;if(n||i){let t=e(H*(1-y)+U*y,q,te),n=e(W*(1-b)+G*b,J,Y);l=a(t,n,c)}else l=re(Q,t);O(y,b,l),ne(t);let u=T-o[0],d=E-o[1],f=D-o[2];be(u,d,f,m),r.setEdgeVertexFromValuesRawPositionUVNormal(s,M,u,d,f,x,S,k,A,j),r.setEdgeVertexFromValuesRawPositionUVNormal(v,F,u,d,f,x,S,k,A,j)}}for(let e=0;e<4;++e)ge[e]=null}function re(e,t){let n=t*4,r=c.reduce((t,r)=>Math.min(t,e[n+r]?.level??1/0),1/0);p&&(f(!e[n+0]||!e[n+2]||g(e[n+0],e[n+2],5)),f(!e[n+1]||!e[n+3]||g(e[n+1],e[n+3],7)));let i=0,o=0;for(let t=0;t<4;++t){let s=e[n+t];if(s?.level===r){let e=t===0||t===1,n=t===0||t===3,r=s.extent,c=r[e?0:2],l=r[n?1:3],u=s.renderData?.geometryState?.samplerData,d=a(c,l,u);o+=d,i++}}let s=i?o/i:0;return f(s!=null),s}function ie(e){let{vao:t,geometry:n}=e,{vertexAttributes:r,edgeVerticesStartIndex:i}=n,a=r.position.typedBuffer;t.buffer()?.setSubData(a,i,i,a.length)}function ae(e){let{vao:t,geometry:n}=e,{indices:r,indexCount:i,edgeIndicesStartIndex:a}=n;t.indexBuffer.setSubData(r,a,a,i)}class oe{constructor(e,t,n,r,i){this.isNorth=e,this.connectedRowOffset=t,this.connectedOuterEdgeOffset=n,this.rowOffset=r,this.latitudeResolution=i}}const se=[[0,1],[1,0],[0,-1],[-1,0]],$=new s,ce=.5*d,le=new Uint16Array(u+1),ue=new Int32Array(u+1),de=new Int32Array(u+1),fe=new Int32Array(u+1),pe=new Float64Array(u+1),me=new Float64Array(u+1),he=i(-1/0,-1/0,1/0,1/0),ge=[null,null,null,null];function _e(e,t,n){if(!t)return!1;let r=_(e,t);return r>0||r===0&&n>=2}class ve{constructor(){this.vertex0Index=0,this.stride=1,this.count=0}getVertexIndex(e){return f(0<=e&&e<this.count),this.vertex0Index+this.stride*e}}const ye=[new ve,new ve,new ve,new ve];function be(e,t,n,r){e<r[0]?r[0]=e:e>r[3]&&(r[3]=e),t<r[1]?r[1]=t:t>r[4]&&(r[4]=t),n<r[2]?r[2]=n:n>r[5]&&(r[5]=n)}function xe(e){let{edgeResolutions:t,numVerticesPerSide:n}=e,r=1+Math.max(...t);return Math.max(n,r)}function Se(e,t,n,r,i,a){let o=e*i,s=a[o],c=a[o+1],l=a[o+2],u=t*i,d=a[u],f=a[u+1],p=a[u+2],m=n*i,h=a[m],g=a[m+1],_=a[m+2],v=r*i,y=a[v],b=a[v+1],x=a[v+2],S=(s-h)*(s-h)+(c-g)*(c-g)+(l-_)*(l-_);return(d-y)*(d-y)+(f-b)*(f-b)+(p-x)*(p-x)>S}function Ce(e,t,n,r,i){e[t]=n,e[t+1]=r,e[t+2]=r,e[t+3]=i,e[t+4]=i,e[t+5]=n}const we=6;export{F as createPlanarGlobePatch,y as createSphericalGlobePatch,L as updateEdgeElevationsAndResolutionsPlanar,D as updateEdgeElevationsAndResolutionsSpherical,R as updateEdgesAndCornersPlanar,E as updateEdgesAndCornersSpherical};
|
|
2
|
+
import{clamp as e,isPowerOfTwo as t}from"../../../core/mathUtils.js";import{maxUint16 as n}from"../../../core/typedArrayUtil.js";import{empty as r}from"../../../geometry/support/aaBoundingBox.js";import{fromValues as i}from"../../../geometry/support/aaBoundingRect.js";import{sampleElevation as a,sampleSingleElevation as o}from"./ElevationData.js";import{PatchGeometryLUT as s}from"./PatchGeometryLUT.js";import{zeroToFour as c,neighborTileIfLoadedOrSelf as l}from"./PatchRenderData.js";import{maxPatchTesselation as u,elevationNoDataValue as d}from"./TerrainConst.js";import{internalAssert as f,enableTerrainInternalChecks as p,neighborEdgeIndices as m,almostEquals as h}from"./terrainUtils.js";import{isCornerNeighbor as g}from"./Tile.js";import{compareTilesByLij as _}from"./tileUtils.js";import{compressNormal as v}from"../webgl-engine/lib/Normals.js";function y(e,t){let{tile:n,geometry:i,geometryState:a}=e,{extentInRadians:o,surface:s}=n,{isWebMercator:c,renderer:l}=s,{numVerticesPerSide:u,wireframe:d}=a,f=u-1,p=(u-2)**2,m=c&&(t===2||t===3),h=c&&(t===1||t===3),g=(+!!m+ +!!h)*we*u,_=xe(a),v=4*_,y=p+g+v,S=l.tileGeometryCache.acquire(y);i.numVerticesPerSide=u,i.vertexAttributes=S,i.maxEdgeVertexCount=_;let{boundingBox:C}=i;r(C);let w=P(e);$.update(f,o,w),x(e),i.poleVerticesStartIndex=p;let T=b(e,m,h);i.edgeVerticesStartIndex=p+g,X(e),O(e),W(i,T,d),e.intersectionData=null}function b(e,t,r){let{tile:i,localOrigin:a,geometry:o}=e,{extent:s,ellipsoid:c}=i,{boundingBox:l,numVerticesPerSide:u,vertexAttributes:d,poleVerticesStartIndex:f}=o,p=u-1,m=a[0],h=a[1],g=a[2],_=c.radius,y=s[1],b=s[3],x=[],S=f,C=(e,t)=>{let r=t*u;be(-m,-h,-g+e*_,l),x.push(new oe(e===1,r,e===1?0:2,S,we));let i=j(e===-1?y:b,_),a=e*Math.PI/2-i,o=(e===1?1:-1)*.99,s=_+0,{position:c,uv0:f}=d,{typedBuffer:C,typedBufferStride:w}=d.normalCompressed;for(let e=1;e<=we;++e){let t=i+e/we*a,r=Math.cos(t),u=Math.sin(t);for(let e=0;e<=p;e++){let t=e/p,i=$.sinLonLUT[e],a=$.cosLonLUT[e]*r,d=i*r,_=u,y=a*s-m,b=d*s-h,x=_*s-g;be(y,b,x,l),c.setValues(S,y,b,x),f.setValues(S,Math.round(t*n),Math.round(o*n)),v(C,S,a,d,_,w),++S}}};return t&&C(-1,0),r&&C(1,p),x}function x(e){let t=e.geometryState.samplerData,n=t?.length===1?t[0]:null;n?S(e,n):C(e)}function S(e,t){let{tile:n}=e;if(!n.intersectsClippingArea)return;let{geometry:r,geometryState:i,localOrigin:a}=e,{numVerticesPerSide:o}=i,s=o-2,c=o-1,{vertexAttributes:l,boundingBox:u}=r,{position:d,uv0:f}=l,{typedBuffer:p,typedBufferStride:m}=l.normalCompressed,{extent:h}=n,g=n.ellipsoid.radius,_=a[0],y=a[1],b=a[2],x=d.typedBuffer,S=d.typedBufferStride,C=f.typedBuffer,E=f.typedBufferStride;w(c,h,t);let D=0,O=t.data.values;if(1<=s){let e=le[1],t=$.sinLatLUT[1],n=$.cosLatLUT[1];for(let r=1;r<=s;r++){let i=$.sinLonLUT[r],a=$.cosLonLUT[r],o=g+T(r,1,O),s=-_+o*a*n,c=-y+o*i*n,l=-b+o*t;be(s,c,l,u);let d=(r-1)*S;x[d]=s,x[d+1]=c,x[d+2]=l;let f=(r-1)*E;C[f]=le[r],C[f+1]=e}}for(let e=1;e<=s;e++){let t=$.sinLatLUT[e],n=$.cosLatLUT[e],r=e+1,i=le[r],a=$.sinLatLUT[r],o=$.cosLatLUT[r],l=$.sinLonLUT[0],d=$.cosLonLUT[0],f=g+T(0,e,O),h=d*n*f-_,w=l*n*f-y,k=t*f-b,A=D*S,j=x[A],M=x[A+1],N=x[A+2];for(let l=1;l<=s;l++){let d=$.sinLonLUT[l],f=$.cosLonLUT[l],A=0,P=0,F=0;if(l<s){let e=(D+1)*S;A=x[e],P=x[e+1],F=x[e+2]}else{let r=$.sinLonLUT[c],i=$.cosLonLUT[c],a=g+T(c,e,O);A=i*n*a-_,P=r*n*a-y,F=t*a-b}let I=h,L=w,R=k;h=j,w=M,k=N,j=A,M=P,N=F;let z=A-I,B=P-L,V=F-R,H=0,U=0,ee=0;if(e>1){let e=(D-s)*S;H=x[e],U=x[e+1],ee=x[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=g+T(l,0,O);H=f*t*n-_,U=d*t*n-y,ee=e*n-b}let W=g+T(l,r,O),G=f*o*W-_,K=d*o*W-y,q=a*W-b;if(e<s){let e=D+s,t=e*S;x[t]=G,x[t+1]=K,x[t+2]=q,be(G,K,q,u);let n=e*E;C[n]=le[l],C[n+1]=i}let te=H-G,J=U-K,Y=ee-q,X=f*n,Z=d*n,ne=t;ne*ne<.999&&(X=V*J-B*Y,Z=z*Y-V*te,ne=B*te-z*J);let Q=1/Math.sqrt(X*X+Z*Z+ne*ne);v(p,D,X*Q,Z*Q,ne*Q,m),++D}}}function C(e){let{tile:t}=e;if(!t.intersectsClippingArea)return;let{geometry:r,geometryState:i,localOrigin:o}=e,{numVerticesPerSide:s,samplerData:c}=i,l=s-2,u=s-1,{vertexAttributes:d,boundingBox:f}=r,{position:p,uv0:m}=d,{typedBuffer:h,typedBufferStride:g}=d.normalCompressed,{extent:_}=t,y=_[0],b=_[2],x=_[1],S=_[3],C=t.ellipsoid.radius,w=o[0],T=o[1],E=o[2],D=p.typedBuffer,O=p.typedBufferStride,k=1/u,A=0;if(1<=l){let e=k,t=x*(1-e)+S*e,r=$.sinLatLUT[1],i=$.cosLatLUT[1];for(let o=1;o<=l;o++){let s=o*k,l=y*(1-s)+b*s,u=$.sinLonLUT[o],d=$.cosLonLUT[o],p=C+a(l,t,c),h=-w+p*d*i,g=-T+p*u*i,_=-E+p*r;be(h,g,_,f);let v=(o-1)*O;D[v]=h,D[v+1]=g,D[v+2]=_,m.setValues(o-1,Math.round(s*n),Math.round(e*n))}}for(let e=1;e<=l;e++){let t=e*k,r=x*(1-t)+S*t,i=$.sinLatLUT[e],o=$.cosLatLUT[e],s=e+1,d=s*k,p=x*(1-d)+S*d,_=$.sinLatLUT[s],j=$.cosLatLUT[s],M=$.sinLonLUT[0],N=$.cosLonLUT[0],P=C+a(y,r,c),F=N*o*P-w,I=M*o*P-T,L=i*P-E,R=A*O,z=D[R],B=D[R+1],V=D[R+2];for(let t=1;t<=l;t++){let s=t*k,S=y*(1-s)+b*s,M=$.sinLonLUT[t],N=$.cosLonLUT[t],P=0,R=0,H=0;if(t<l){let e=(A+1)*O;P=D[e],R=D[e+1],H=D[e+2]}else{let e=$.sinLonLUT[u],t=$.cosLonLUT[u],n=C+a(b,r,c);P=t*o*n-w,R=e*o*n-T,H=i*n-E}let U=F,ee=I,W=L;F=z,I=B,L=V,z=P,B=R,V=H;let G=P-U,K=R-ee,q=H-W,te=0,J=0,Y=0;if(e>1){let e=(A-l)*O;te=D[e],J=D[e+1],Y=D[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=C+a(S,x,c);te=N*t*n-w,J=M*t*n-T,Y=e*n-E}let X=C+a(S,p,c),Z=N*j*X-w,ne=M*j*X-T,Q=_*X-E;if(e<l){let e=A+l,t=e*O;D[t]=Z,D[t+1]=ne,D[t+2]=Q,be(Z,ne,Q,f),m.setValues(e,Math.round(s*n),Math.round(d*n))}let re=te-Z,ie=J-ne,ae=Y-Q,oe=N*o,se=M*o,ce=i;ce*ce<.999&&(oe=q*ie-K*ae,se=G*ae-q*re,ce=K*re-G*ie);let le=1/Math.sqrt(oe*oe+se*se+ce*ce);v(h,A,oe*le,se*le,ce*le,g),++A}}}function w(t,r,i){let a=r[0],o=r[2],s=r[1],c=r[3],l=1/t,{dx:u,dy:d,x0:f,y1:p,safeWidth:m}=i,h=i.data.width;for(let r=0;r<=t;r++){let t=r*l,i=e(u*(a*(1-t)+o*t-f),0,m),g=Math.floor(i);ue[r]=g,pe[r]=i-g;let _=e(d*(p-(s*(1-t)+c*t)),0,m),v=Math.floor(_);de[r]=v*h,fe[r]=(v+1)*h,me[r]=_-v,le[r]=Math.round(t*n)}}function T(e,t,n){let r=ue[e],i=pe[e],a=de[t],o=fe[t],s=me[t],c=a+r,l=n[c],u=n[c+1],d=n[o+r],f=n[o+r+1];if(l+d+u+f>=ce)return 0;let p=l+(u-l)*i;return p+(d+(f-d)*i-p)*s}function E(e){e.tile.intersectsClippingArea&&(O(e),ie(e),e.intersectionData=null)}function D(e){e.tile.intersectsClippingArea&&(Z(e),O(e),ie(e),ae(e),e.intersectionData=null)}function O(e){e.tile.intersectsClippingArea&&(A(e),k(e))}function k(e){let{geometry:r,geometryState:i,tile:s,localOrigin:c}=e,{level:u,extent:d,extentInRadians:g,ellipsoid:y}=s,b=y.radius,x=g[0],S=g[2],C=g[1],w=g[3],{samplerData:T}=i,E=d[0],D=d[2],O=d[1],k=d[3],A=P(e),{boundingBox:j,vertexAttributes:M}=r,N=c[0],F=c[1],I=c[2],{position:L,uv0:R}=M,z=L.typedBuffer,B=L.typedBufferStride,V=R.typedBuffer,H=R.typedBufferStride,{typedBuffer:U,typedBufferStride:ee}=M.normalCompressed,W=T?.length===1?T[0]:null,G=(e,t,n)=>W?o(e,t,W)??0:a(e,t,T)??0;for(let c=0;c<4;++c){let g=c===1||c===3,y=i.edgeResolutions[c];f(t(y));let M=y+1,P=l(s,i.edgePeerNeighbors[c]);if(_e(s,P,c)&&ne(e,c,P))continue;let L=P!=null;f(!L||P.level===s.level),f(!L||_(s,P)<=0);let R=P?.renderData?.geometryState;if(p){let e=s.surface;if(!P&&e&&!e.updatingRootTiles){let t=m[c],n=s.findNeighborTile(t,e=>e.loaded||e.leaf||e.level===s.level);n?n.intersectsClippingArea&&(f(!n.loaded),f(!n.leaf),f(n.level===u)):f(e?.rootTiles==null||!s.shouldHaveNeighbor(t))}}let K=c===1?d[2]:d[0],q=P?.extent,te=q&&g?c===1?q[0]:q[2]:K,J=c===0?d[3]:d[1],Y=+(c===1),X=+(c===0),Z=c===1?S:x,Q=c===0?w:C,re=Math.sin(Z),ie=Math.cos(Z),ae=Math.sin(Q),oe=Math.cos(Q),se=R?.samplerData,$=se?.length===1?se[0]:null,ce=(e,t,n)=>$?o(n,t,$)??0:a(n,t,se)??0,le=L?(e,t,n)=>(G(e,t)+ce(e,t,n))*.5:G,ue=r.outerEdgesOffsetAndLength[c*2+0],de=W!=null||T!=null&&T.some(e=>e!=null),fe=$!=null||se!=null&&se.some(e=>e!=null),pe=de||fe,me=1/y,he=n*me,ge=Y*n,ve=X*n,ye=ue;f(!q||h(q[2]-q[0],d[2]-d[0])),(()=>{let e=c===1?-1:+(c===3),t=c===0?-1:+(c===2),n=(d[2]-d[0])*me,r=e*n,i=t*n,s=S-x,l=g?s*me*e:0,u=g?0:t*me,f=X,p=g?Z+l:Z,m=g?Math.sin(p):re,h=g?Math.cos(p):ie,_=g?Z-l:Z,y=g?Math.sin(_):re,C=g?Math.cos(_):ie,w=f+u,P=g?Q:A(w),R=g?ae:Math.sin(P),G=g?oe:Math.cos(P),q=f-u,Y=g?Q:A(q),ne=g?ae:Math.sin(Y),ce=g?oe:Math.cos(Y),ue=0,de=0,fe=0;{let e=0*me,t=g?K:E*(1-e)+D*e,n=g?te:t,r=g?O*(1-e)+k*e:J,i=g?Z:x*(1-e)+S*e,a=g?re:Math.sin(i),o=g?ie:Math.cos(i),s=g?A(e):Q,c=g?Math.sin(s):ae,l=g?Math.cos(s):oe,u=b+le(t,r,n);ue=o*l*u,de=a*l*u,fe=c*u}let _e=0,xe=0,Se=0;{let e=1*me,t=g?K:E*(1-e)+D*e,n=g?te:t,r=g?O*(1-e)+k*e:J,i=g?Z:x*(1-e)+S*e,a=g?re:Math.sin(i),o=g?ie:Math.cos(i),s=g?A(e):Q,c=g?Math.sin(s):ae,l=g?Math.cos(s):oe,u=b+le(t,r,n);_e=o*l*u,xe=a*l*u,Se=c*u}for(let e=1;e<M-1;++e){let t=0,n=0,s=0;{let r=(e+1)*me,i=g?K:E*(1-r)+D*r,a=g?te:i,o=g?O*(1-r)+k*r:J,c=g?Z:x*(1-r)+S*r,l=g?re:Math.sin(c),u=g?ie:Math.cos(c),d=g?A(r):Q,f=g?Math.sin(d):ae,p=g?Math.cos(d):oe,m=b+le(i,o,a);t=u*p*m,n=l*p*m,s=f*m}let l=t,u=n,d=s,f=_e,p=xe,_=Se;_e=l,xe=u,Se=d;{let t=ye+e,n=t*B,r=f-N,i=p-F,a=_-I;z[n]=r,z[n+1]=i,z[n+2]=a,be(r,i,a,j);let o=Math.round(e*he),s=t*H;V[s]=g?ge:o,V[s+1]=g?o:ve}let w=ue,M=de,P=fe;ue=f,de=p,fe=_;let q=f,Y=p,X=_,Ce=1/Math.sqrt(q*q+Y*Y+X*X),we=X*Ce,Te=0,Ee=0,De=0;if(pe&&we*we<.999){let t=0,n=0,s=0;{let e=c===0?-1:1;t=e*(l-w),n=e*(u-M),s=e*(d-P)}{let l=e*me,u=g?K:E*(1-l)+D*l,d=g?te:u,f=g?O*(1-l)+k*l:J,p=g?Z:x*(1-l)+S*l,_=g?re:Math.sin(p),v=g?ie:Math.cos(p),w=g?A(l):Q,j=g?Math.sin(w):ae,M=g?Math.cos(w):oe,N=q,P=Y,F=X;if(L){let e=d-r,t=f-i,n=b+($?o(e,t,$)??0:a(e,t,se)??0),s=g?y:_,c=g?C:v,l=g?j:ne,u=g?M:ce;N=c*u*n,P=s*u*n,F=l*n}{let e=u+r,l=f+i,d=b+(W?o(e,l,W)??0:a(e,l,T)??0),p=g?m:_,y=g?h:v,x=g?j:R,S=g?M:G,C=y*S*d,w=p*S*d,E=x*d;L||(N=2*q-C,P=2*Y-w,F=2*X-E);let D=c===3?-1:1,O=D*(N-C),k=D*(P-w),A=D*(F-E);Te=s*k-n*A,Ee=t*A-s*O,De=n*O-t*k;let I=1/Math.sqrt(Te*Te+Ee*Ee+De*De);Te*=I,Ee*=I,De*=I}}}else Te=q*Ce,Ee=Y*Ce,De=X*Ce;v(U,ye+e,Te,Ee,De,ee)}})()}}function A(e){Q(e)}function j(e,t){return Math.PI/2-2*Math.atan(Math.exp(-e/t))}function M(e,t,n,r){return j(e*(1-r)+t*r,n)}function N(e,t,n){return e*(1-n)+t*n}function P(e){let{tile:t}=e;if(t.surface.isWebMercator){let e=t.extent,n=t.ellipsoid.radius;return t=>M(e[1],e[3],n,t)}let n=t.extentInRadians;return e=>N(n[1],n[3],e)}function F(e){let{tile:t,geometryState:n,geometry:i}=e,{extent:a,surface:o}=t,{wireframe:s}=n,c=a[0],l=a[1],u=a[2],d=a[3],f=u-c,p=d-l,{numVerticesPerSide:m,clippingArea:h}=n,g=h==null?0:Math.max(0,(h[0]-c)/f),_=h==null?0:Math.max(0,(h[1]-l)/p),v=h==null?1:Math.min(1,(h[2]-c)/f),y=h==null?1:Math.min(1,(h[3]-l)/p),b=(m-2)**2,x=xe(n),S=b+4*x,C=o.renderer.tileGeometryCache.acquire(S),{boundingBox:w}=i;r(w),i.numVerticesPerSide=m,i.vertexAttributes=C,i.maxEdgeVertexCount=x,i.minu=g,i.minv=_,i.maxu=v,i.maxv=y,I(e),i.edgeVerticesStartIndex=b,X(e),z(e),W(i,[],s),e.intersectionData=null}function I(t){let r=t.tile;if(!r.intersectsClippingArea)return;let{geometry:i,geometryState:s,localOrigin:c}=t,{samplerData:l,clippingArea:u,numVerticesPerSide:d}=s,{surface:f,extent:p,ellipsoid:m}=r,{isWebMercatorOnPlateCarree:h}=f,g=u??he,_=p[0],y=p[1],b=p[2],x=p[3],S=Math.max(_,g[0]),C=Math.min(b,g[2]),w=Math.max(y,g[1]),T=Math.min(x,g[3]),E=m.radius,D=r.horizontalScale,O=d-1,k=d-2,{minu:A,minv:j,maxu:M,maxv:N,boundingBox:P,vertexAttributes:F}=i,{position:I,uv0:L}=F,{typedBuffer:R,typedBufferStride:z}=F.normalCompressed,B=c[0],V=c[1],H=c[2],U=I.typedBuffer,ee=I.typedBufferStride,W=0,G=e(y,w,T),K=h?(Math.PI/2-2*Math.atan(Math.exp(-G/E)))*E:G*D,q=1/O,te=e(y*(1-q)+x*q,w,T),J=h?(Math.PI/2-2*Math.atan(Math.exp(-te/E)))*E:te*D,Y=K,X=J,Z=l?.length===1?l[0]:null,ne=Z?(e,t)=>o(e,t,Z)??0:(e,t)=>a(e,t,l)??0;for(let t=1;t<=k;t++){let r=t/O,i=e(y*(1-r)+x*r,w,T),a=e(r,j,N),o=X,s=(t-1)/O,c=e(y*(1-s)+x*s,w,T),l=Y,u=(t+1)/O,d=e(y*(1-u)+x*u,w,T),f=h?(Math.PI/2-2*Math.atan(Math.exp(-d/E)))*E:d*D,p=e(u,j,N);Y=X,X=f;let m=e(_,S,C),g=m*D,F=ne(m,i),I=1/O,G=e(I,A,M),K=e(_*(1-G)+b*G,S,C),q=G,te=K,J=K*D,Z=ne(K,i);if(t===1){let t=J-B,r=Y-V,i=Z-H,o=0*ee;U[o]=t,U[o+1]=r,U[o+2]=i,be(t,r,i,P);let s=e(I,A,M);L.setValues(W,Math.round(s*n),Math.round(a*n))}for(let r=1;r<=k;r++){let s=J,u=Z,m=(r+1)/O,h=e(m,A,M),y=e(_*(1-m)+b*m,S,C),x=te;te=y;{let e=W+1,s=e*ee;if(t===1||r===k){let c=ne(y,i),l=y*D,u=o,d=c;if(t===1&&r<k){let t=l-B,r=u-V,i=d-H;U[s]=t,U[s+1]=r,U[s+2]=i,be(t,r,i,P),L.setValues(e,Math.round(h*n),Math.round(a*n))}J=l,Z=d}else J=U[s]+B,Z=U[s+2]+H}let w=J,T=Z,E=g,j=F;g=s,F=u;let N=(W-k)*ee,I=t===1?ne(x,c):U[N+2]+H,G=ne(x,d);if(t<k){let e=W+k,t=e*ee,r=s-B,i=f-V,a=G-H;U[t]=r,U[t+1]=i,U[t+2]=a,be(r,i,a,P);let o=q;q=h,L.setValues(e,Math.round(o*n),Math.round(p*n))}{let e=w-E,t=T-j,n=l-f,r=I-G,i=n*t,a=e*r,o=-n*e,s=i*i+a*a+o*o;if(s===0)v(R,W,0,0,1,z);else{let e=1/Math.sqrt(s);v(R,W,i*e,a*e,o*e,z)}}++W}}}function L(e){e.tile.intersectsClippingArea&&(Z(e),z(e),ie(e),ae(e),e.intersectionData=null)}function R(e){e.tile.intersectsClippingArea&&(z(e),ie(e),e.intersectionData=null)}function z(e){e.tile.intersectsClippingArea&&(V(e),B(e))}function B(n){let{geometry:r,geometryState:i,localOrigin:s}=n,c=n.tile,{surface:u,extent:d}=c,{clippingArea:h,samplerData:g}=i,v=h??he,y=d[0],b=d[2],x=d[1],S=d[3],C=[S>v[3],b>v[2],x<v[1],y<v[0]],w=c.horizontalScale,T=ee(u.isWebMercatorOnPlateCarree,c.ellipsoid.radius,w),{minu:E,minv:D,maxu:O,maxv:k,boundingBox:A}=r,j=Math.max(y,v[0]),M=Math.min(b,v[2]),N=Math.max(x,v[1]),P=Math.min(S,v[3]),F=s[0],I=s[1],L=s[2],R=g?.length===1?g[0]:void 0,z=R?(e,t)=>o(e,t,R)??0:(e,t)=>a(e,t,g)??0;for(let s=0;s<4;++s){let d=s===1||s===3,h=i.edgeResolutions[s];f(t(h));let v=h+1,R=C[s],B=l(c,i.edgePeerNeighbors[s]);if(!R&&_e(c,B,s)&&ne(n,s,B))continue;let V=B!=null&&!R,H=B?.renderData?.geometryState;if(p&&(f(!V||B.level===c.level),f(!V||_(c,B)<=0),c&&!B&&!u.updatingRootTiles)){let e=m[s],t=c.findNeighborTile(e,e=>e.loaded||e.leaf||e.level===c.level);u.updatingRootTiles||(t?t.intersectsClippingArea&&(f(!t.loaded),f(!t.leaf),f(t.level===c.level)):f(u?.rootTiles==null||!c.shouldHaveNeighbor(e)))}let U=e(s===1?b:y,j,M),ee=e(s===0?S:x,N,P),W=H?.samplerData,G=e(+(s===1),E,O),K=e(+(s===0),D,k),q=W?.length===1?W[0]:null,te=(e,t)=>q?o(e,t,q)??0:a(e,t,W)??0,J=V?(e,t)=>(te(e,t)+z(e,t))*.5:z,Y=(b-y)/h,X=d?s===1?Y:-Y:0,Z=d?0:s===0?Y:-Y,Q=-X,re=-Z,ie=0,ae=0,oe=0;{let t=0/h,n=d?U:e(y*(1-t)+b*t,j,M),r=d?e(x*(1-t)+S*t,N,P):ee,i=J(n,r);ie=n*w,ae=T(r),oe=i}let se=0,$=0,ce=0;{let t=1/h,n=d?U:e(y*(1-t)+b*t,j,M),r=d?e(x*(1-t)+S*t,N,P):ee,i=J(n,r),a=n*w,o=T(r),s=i;se=a,$=o,ce=s}for(let t=1;t<v-1;++t){let n=t/h,i=se,o=$,c=ce;{let a=d?G:e(n,E,O),l=d?e(n,D,k):K,u=i-F,f=o-I,p=c-L;be(i,f,p,A),r.setEdgeVertexFromValuesRawPositionUV(s,t,u,f,p,a,l)}{let n=(t+1)/h,r=d?U:e(y*(1-n)+b*n,j,M),i=d?e(x*(1-n)+S*n,N,P):ee,a=J(r,i);se=r*w,$=T(i),ce=a}let l=se,u=$,f=ce,p=ie,m=ae,_=oe;ie=i,ae=o,oe=c;let v=0,C=0,R=0;if(d){let t=u-o,r=f-c,l=m-o,d=_-c,p=e(x*(1-n)+S*n,N,P),h=U+Q,y=p,b=h*w,T=a(h,y,g),E=b-i,D=T-c,O=s===3?-1:1;if(v=O*(-l+t)*D,C=O*E*(-d+r),R=-O*E*(-l+t),V){let e=U+X,n=p,o=e*w,s=a(e,n,W),u=o-i,f=s-c;v=(-l+t)*(D-f),C=(E-u)*(-d+r),R=-(E-u)*(-l+t)}}else{let t=l-i,r=f-c,u=p-i,d=_-c,m=e(y*(1-n)+b*n,j,M),h=m,x=ee+re,S=a(h,x,g)-c,w=T(x)-o,E=s===2?-1:1;if(v=E*w*(-d+r),C=E*(-u+t)*S,R=-E*w*(-u+t),V){let e=m,n=ee+Z,i=T(n),s=a(e,n,W)-c,l=i-o;v=(-w+l)*(-d+r),C=(-u+t)*(-S+s),R=-(-w+l)*(-u+t)}}let z=1/Math.sqrt(v*v+C*C+R*R);r.setEdgeNormalFromValues(s,t,v*z,C*z,R*z)}}}function V(e){Q(e)}function H(e,t){return(Math.PI/2-2*Math.atan(Math.exp(-e/t)))*t}function U(e,t){return e*t}function ee(e,t,n){return e?e=>H(e,t):e=>U(e,n)}function W(e,t,n){let{numVerticesPerSide:r,vertexAttributes:i,maxEdgeVertexCount:a}=e,o=r-1,s=i.count,l=r-3,u=r-3,d=2*l*u,f=4*(o+a-3),p=c.reduce((t,n)=>t+(o+e.getEdgeCount(n)-3),0),m=t.reduce((e,t)=>e+o*((t.latitudeResolution-1)*2+1),0),h=3*(n?2:1),g=(d+f+m)*h;e.indices=s>=65536?new Uint32Array(g):new Uint16Array(g),e.indexCount=(d+p+m)*h,e.poleIndicesStartIndex=d*h,e.edgeIndicesStartIndex=(d+m)*h,n?(te(e),J(e,t),Y(e)):(G(e),K(e,t),q(e))}function G(e){let{numVerticesPerSide:t,indices:n,vertexAttributes:r}=e,{position:i}=r,{typedBuffer:a,typedBufferStride:o}=i,s=t-2,c=t-3,l=t-3,u=0;for(let e=0;e<c;++e){let t=e*s;for(let e=0;e<l;++e){let r=t+e,i=r+1,c=i+s,l=c-1;Se(r,i,c,l,o,a)?(n[u]=r,n[u+1]=i,n[u+2]=c,n[u+3]=c,n[u+4]=l,n[u+5]=r):(n[u]=r,n[u+1]=i,n[u+2]=l,n[u+3]=l,n[u+4]=i,n[u+5]=c),u+=6}}}function K(e,t){let{numVerticesPerSide:n,indices:r,poleIndicesStartIndex:i}=e,a=n-1,o=i;for(let i of t){let t=i.isNorth?1:2,s=i.isNorth?2:1,c=i.isNorth?3:4,l=i.isNorth?4:3,u=e.getEdgeVertexIndex(i.connectedOuterEdgeOffset,0),d=1;for(let e=0;e<i.latitudeResolution;++e){let f=e===0?i.rowOffset:u+n;for(let n=0;n<a;n++){let a=f+n;r[o]=u,r[o+t]=u+1,r[o+s]=a,e<i.latitudeResolution-1?(r[o+c]=u+1,r[o+l]=a+1,r[o+5]=a,o+=6):o+=3,u+=d}u=f,d=1}}}function q(e){let{indices:t,numVerticesPerSide:n,edgeIndicesStartIndex:r}=e,i=n-1,a=i-2,o=r;for(let n=0;n<4;++n){let r=ye[n],s=0,c=0,l=e.getEdgeCount(n),u=r.count;f(u===i-1);let d=n===1||n===2,p=d?1:2,m=d?2:1,h=e.getEdgeFirstVertexIndex(n),g=r.vertex0Index,_=r.stride;for(;s<l-1||c<u-1;){let e=g+c*_,n=h+s*1,r=s<l-1,d=c<u-1,f=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||f<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+p]=n,t[o+m]=b,o+=3}}e.indexCount=o}function te(e){let{indices:t,numVerticesPerSide:n,vertexAttributes:r}=e,{position:i}=r,{typedBuffer:a,typedBufferStride:o}=i,s=n-2,c=0;for(let e=0;e<n-3;++e){let r=e*s;for(let i=0;i<n-3;++i){let n=e*s+i,l=n+1,u=l+s,d=u-1,f=r+i,p=f+1,m=p+s;Se(f,p,m,m-1,o,a)?(Ce(t,c,n,l,u),c+=6,Ce(t,c,u,d,n)):(Ce(t,c,n,l,d),c+=6,Ce(t,c,d,u,l)),c+=6}}}function J(e,t){let{indices:n,numVerticesPerSide:r,poleIndicesStartIndex:i}=e,a=r-1,o=i;for(let i of t){let t=i.connectedOuterEdgeOffset,s=e.getEdgeVertexIndex(t,0),c=1;for(let e=0;e<i.latitudeResolution;++e){let t=e===0?i.rowOffset:s+r;for(let r=0;r<a;r++)Ce(n,o,s,s+1,t+r),o+=6,e<i.latitudeResolution-1&&(Ce(n,o,s+1,t+r+1,t+r),o+=6),s+=c;s=t,c=1}}}function Y(e){let{indices:t,numVerticesPerSide:n,edgeIndicesStartIndex:r}=e,i=n-1,a=i-2,o=r;for(let n=0;n<4;++n){let r=ye[n],s=0,c=0,l=e.getEdgeCount(n),u=r.count;f(u===i-1);let d=n===1||n===2,p=d?1:3,m=d?3:1,h=e.getEdgeFirstVertexIndex(n),g=r.vertex0Index,_=r.stride;for(;s<l-1||c<u-1;){let e=g+c*_,n=h+s*1,r=s<l-1,d=c<u-1,f=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||f<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+p]=n,t[o+p+1]=n,t[o+m]=b,t[o+m+1]=b,t[o+5]=e,o+=6}}e.indexCount=o}function X(e){let{geometry:t,geometryState:n}=e,{edgeResolutions:r}=n,{numVerticesPerSide:i,edgeVerticesStartIndex:a}=t,o=i-2,s=a;for(let e=0;e<4;++e){{let t=e===1?o-1:0,n=e===0?o-1:0,r=e===0||e===2,i=+!!r,a=+!r,s=n*o+t,c=a*o+i,l=ye[e];l.vertex0Index=s,l.stride=c,l.count=o}{let n=r[e]+1;t.outerEdgesOffsetAndLength[e*2+0]=s,t.outerEdgesOffsetAndLength[e*2+1]=n,s+=n}}}function Z(e){X(e),e.geometryState.wireframe?Y(e.geometry):q(e.geometry)}function ne(r,i,a){let{geometryState:o,geometry:s,tile:c,localOrigin:l}=r,u=i===1||i===3,d=o.edgeResolutions[i];f(t(d));let p=d+1,{boundingBox:m,minu:h,minv:g,maxu:_,maxv:v,vertexAttributes:y}=s,b=e(+(i===1),h,_),x=e(+(i===0),g,v),S=a.renderData,C=S.geometryState;if(!C||!S.geometry.vertexAttributes)return!1;let w=S.geometry,T=(i+2)%4,E=w.getEdgeCount(T),D=c.getNeighborEdgeStartVertexIndex(i,a)*d,O=d*2**(c.level-a.level);f(C.edgeResolutions[T]===O),f(E-1===O);let k=S.localOrigin[0]-l[0],A=S.localOrigin[1]-l[1],j=S.localOrigin[2]-l[2],M=s.getEdgeFirstVertexIndex(i),{position:N,uv0:P}=y,F=N.typedBuffer,I=N.typedBufferStride,L=y.normalCompressed,R=L.typedBuffer,z=L.typedBufferStride,B=w.vertexAttributes,V=w.getEdgeFirstVertexIndex(T),H=B.position.typedBuffer,U=B.position.typedBufferStride,ee=B.normalCompressed.typedBuffer,W=B.normalCompressed.typedBufferStride;for(let t=1;t<p-1;++t){let r=D+t,i=M+t,a=V+r,o=i*I,s=a*U,c=H[s]+k,l=H[s+1]+A,f=H[s+2]+j;F[o]=c,F[o+1]=l,F[o+2]=f,be(c,l,f,m);let p=i*z,y=a*W;R[p]=ee[y],R[p+1]=ee[y+1];let S=t/d,C=u?b:e(S,h,_),w=u?e(S,g,v):x;P.setValues(i,Math.round(C*n),Math.round(w*n))}return!0}function Q(t){let{geometry:r,geometryState:i,localOrigin:o}=t,{clippingArea:s,samplerData:c}=i,{minu:l,minv:u,maxu:d,maxv:p,boundingBox:m,vertexAttributes:h}=r,g=t.tile,{surface:v,ellipsoid:y,extent:b,extentInRadians:x,horizontalScale:S}=g,C=v.view?.viewingMode===`local`,w=y.radius,T=0,E=0,D=0,O=C?(()=>{let t=s,n=t!=null&&(b[3]>t[3]||b[2]>t[2]||b[1]<t[1]||b[0]<t[0]),r=ee(v.isWebMercatorOnPlateCarree,w,S);return(i,a,o)=>{let s=i===0?b[0]:b[2],c=a===0?b[1]:b[3],l=n?e(s,t[0],t[2]):s,u=n?e(c,t[1],t[3]):c,d=o;T=l*S,E=r(u),D=d}})():(e,t,n)=>{let r=x[t===0?1:3],i=x[e===0?0:2],a=Math.cos(r),o=Math.sin(r),s=Math.sin(i),c=Math.cos(i),l=w+n;T=c*a*l,E=s*a*l,D=o*l},k=0,A=0,j=0,M=0,N=0,F=0,I=0,L=0,R=0,z=C&&v.isWebMercatorOnPlateCarree,B=(e,t,n,r,i)=>{let a=0,o=0,s=0;if(C){let e=t*S,i=z?(Math.PI/2-2*Math.atan(Math.exp(-n/w)))*w:n*S,c=r;a=e-T,o=i-E,s=c-D}else{let i=P(e),c=e.tile,l=c.extent,u=c.extentInRadians,d=(t-l[0])/(l[2]-l[0]),f=(n-l[1])/(l[3]-l[1]),p=u[0]*(1-d)+u[2]*d,m=i(f),h=Math.cos(m),g=Math.sin(m),_=Math.sin(p),v=Math.cos(p),y=w+r,b=v*h*y,x=_*h*y,S=g*y;a=b-T,o=x-E,s=S-D}switch(i){case 0:I+=a,L+=o,R+=s;break;case 1:M-=a,N-=o,F-=s;break;case 2:I-=a,L-=o,R-=s;break;case 3:M+=a,N+=o,F+=s}},V=s??he,H=b[0],U=b[2],W=b[1],G=b[3],K=[G>V[3],U>V[2],W<V[1],H<V[0]],q=Math.max(H,V[0]),te=Math.min(U,V[2]),J=Math.max(W,V[1]),Y=Math.min(G,V[3]),X=e=>Math.max(V[0],Math.min(V[2],e)),Z=e=>Math.max(V[1],Math.min(V[3],e)),ne=e=>{let t=i.cornerNeighborCornerTiles;k=0,A=0,j=1,M=0,N=0,F=0,I=0,L=0,R=0;let n=1/0;for(let r=0;r<4;++r){let i=t[e*4+r];n=Math.min(n,i?.level??1/0)}for(let r=0;r<4;++r){let i=t[e*4+r];ge[r]=i?.level===n?i:null}let r=1,o=0;for(let e=0;e<4;++e){let t=ge[e];t&&(r=Math.max(r,t?.renderData.geometryState.numVerticesPerSide),o=t.extent[2]-t.extent[0])}let s=o,c=r;f(c>1);let l=s/c;for(let e=0;e<4;++e){let t=ge[(e+3)%4],n=ge[e%4];if(!t&&!n)continue;let r=e===0?1:e===1?2:e===2?3:0,i=e===0?2:e===1?3:e===2?0:1;if(t&&n){let o=se[e][0]*l,s=se[e][1]*l,c=t.extent,u=X(c[r===0||r===1?2:0]+o),d=Z(c[r===0||r===3?3:1]+s),f=n.extent,p=X(f[i===0||i===1?2:0]+o),m=Z(f[i===0||i===3?3:1]+s),h=t.renderData,g=n.renderData,_=a(u,d,h.geometryState.samplerData),v=a(p,m,g.geometryState.samplerData);B(h,u,d,.5*(_+v),e)}else{let o=t??n,s=t?r:i,c=o.extent,u=se[e],d=X(c[s===0||s===1?2:0]+u[0]*l),f=Z(c[s===0||s===3?3:1]+u[1]*l),p=o.renderData,m=a(d,f,p.geometryState.samplerData);B(p,d,f,m,e)}}if(!C){let e=Math.sqrt(T*T+E*E+D*D);k=T/e,A=E/e,j=D/e}if(C||j*j<.999){let e=Math.sqrt(M*M+N*N+F*F);M/=e,N/=e,F/=e;let t=Math.sqrt(I*I+L*L+R*R);I/=t,L/=t,R/=t,k=F*L-N*R,A=M*R-F*I,j=N*I-M*L;let n=1/Math.sqrt(k*k+A*A+j*j);k*=n,A*=n,j*=n}},Q=i.cornerNeighborCornerTiles;for(let t=0;t<4;++t){let s=t,v=(t+1)%4,y=+(t===0||t===1),b=+(t===0||t===3),x=e(y,l,d),S=e(b,u,p),C=r.getEdgeFirstVertexIndex(s),w=r.getEdgeCount(s),M=t===0||t===3?w-1:0,N=r.getEdgeFirstVertexIndex(v),P=r.getEdgeCount(v),F=t===0||t===1?P-1:0,I=-1;for(let e=0;e<4;++e){let n=Q[t*4+e],r=Q[t*4+I];n&&(I===-1||_(r,n)>0)&&(I=e)}let L=I,R=Q[t*4+L];if(R!==g){let e=g.level-R.level,r=2**e,a=[R.lij[0]+e,R.lij[1]*r,R.lij[2]*r],s=[a[1]+r===g.lij[1],t===0&&(L===1||L===0&&R!==Q[t*4+3])||t===1&&(L===0||L===1&&R!==Q[t*4+2]),a[1]===g.lij[1]+1,t===2&&(L===3||L===2&&R!==Q[t*4+1])||t===3&&(L===2||L===3&&R!==Q[t*4+0])],c=s.reduce((e,t)=>e+ +!!t,0);f(c===1||c===2);let l=-1,u=-1,d=R.renderData;if(c===1){let e=s.findIndex(e=>e);f(0<=e&&e<=3),l=(e+2)%4;let n=i.edgeResolutions[e];u=g.getNeighborEdgeStartVertexIndex(e,R)*n+n*+(e===0&&t===0||e===1&&t===0||e===2&&t===1||e===3&&t===3)}else{f(s[1]||s[3]),l=s[1]?3:1;let e=d.geometryState.edgeResolutions[l];u=t===0||t===3?0:e}let p=d.geometry;{let e=C+M,t=N+F,r=p.getEdgeFirstVertexIndex(l)+u,i=p.vertexAttributes,a=d.localOrigin,s=i.position,c=s.typedBuffer,f=r*s.typedBufferStride,g=c[f]+a[0]-o[0],_=c[f+1]+a[1]-o[1],v=c[f+2]+a[2]-o[2];be(g,_,v,m);let y=h.position,b=y.typedBuffer,w=e*y.typedBufferStride;b[w]=g,b[w+1]=_,b[w+2]=v;let T=t*y.typedBufferStride;b[T]=g,b[T+1]=_,b[T+2]=v;let E=h.uv0;E.setValues(e,Math.round(x*n),Math.round(S*n)),E.setValues(t,Math.round(x*n),Math.round(S*n));{let n=i.normalCompressed.typedBuffer,a=r*i.normalCompressed.typedBufferStride,o=h.normalCompressed,s=o.typedBuffer;{let t=e*o.typedBufferStride;s[t]=n[a],s[t+1]=n[a+1]}{let e=t*o.typedBufferStride;s[e]=n[a],s[e+1]=n[a+1]}}}}else{let n=K[s],i=K[v],l;if(n||i){let t=e(H*(1-y)+U*y,q,te),n=e(W*(1-b)+G*b,J,Y);l=a(t,n,c)}else l=re(Q,t);O(y,b,l),ne(t);let u=T-o[0],d=E-o[1],f=D-o[2];be(u,d,f,m),r.setEdgeVertexFromValuesRawPositionUVNormal(s,M,u,d,f,x,S,k,A,j),r.setEdgeVertexFromValuesRawPositionUVNormal(v,F,u,d,f,x,S,k,A,j)}}for(let e=0;e<4;++e)ge[e]=null}function re(e,t){let n=t*4,r=c.reduce((t,r)=>Math.min(t,e[n+r]?.level??1/0),1/0);p&&(f(!e[n+0]||!e[n+2]||g(e[n+0],e[n+2],5)),f(!e[n+1]||!e[n+3]||g(e[n+1],e[n+3],7)));let i=0,o=0;for(let t=0;t<4;++t){let s=e[n+t];if(s?.level===r){let e=t===0||t===1,n=t===0||t===3,r=s.extent,c=r[e?0:2],l=r[n?1:3],u=s.renderData?.geometryState?.samplerData,d=a(c,l,u);o+=d,i++}}let s=i?o/i:0;return f(s!=null),s}function ie(e){let{vao:t,geometry:n}=e,{vertexAttributes:r,edgeVerticesStartIndex:i}=n,{position:a}=r,o=a.typedBuffer,s=i*a.typedBufferStride;t.buffer()?.setSubData(o,s,s,o.length)}function ae(e){let{vao:t,geometry:n}=e,{indices:r,indexCount:i,edgeIndicesStartIndex:a}=n;t.indexBuffer.setSubData(r,a,a,i)}class oe{constructor(e,t,n,r,i){this.isNorth=e,this.connectedRowOffset=t,this.connectedOuterEdgeOffset=n,this.rowOffset=r,this.latitudeResolution=i}}const se=[[0,1],[1,0],[0,-1],[-1,0]],$=new s,ce=.5*d,le=new Uint16Array(u+1),ue=new Int32Array(u+1),de=new Int32Array(u+1),fe=new Int32Array(u+1),pe=new Float64Array(u+1),me=new Float64Array(u+1),he=i(-1/0,-1/0,1/0,1/0),ge=[null,null,null,null];function _e(e,t,n){if(!t)return!1;let r=_(e,t);return r>0||r===0&&n>=2}class ve{constructor(){this.vertex0Index=0,this.stride=1,this.count=0}getVertexIndex(e){return f(0<=e&&e<this.count),this.vertex0Index+this.stride*e}}const ye=[new ve,new ve,new ve,new ve];function be(e,t,n,r){e<r[0]?r[0]=e:e>r[3]&&(r[3]=e),t<r[1]?r[1]=t:t>r[4]&&(r[4]=t),n<r[2]?r[2]=n:n>r[5]&&(r[5]=n)}function xe(e){let{edgeResolutions:t,numVerticesPerSide:n}=e,r=1+Math.max(...t);return Math.max(n,r)}function Se(e,t,n,r,i,a){let o=e*i,s=a[o],c=a[o+1],l=a[o+2],u=t*i,d=a[u],f=a[u+1],p=a[u+2],m=n*i,h=a[m],g=a[m+1],_=a[m+2],v=r*i,y=a[v],b=a[v+1],x=a[v+2],S=(s-h)*(s-h)+(c-g)*(c-g)+(l-_)*(l-_);return(d-y)*(d-y)+(f-b)*(f-b)+(p-x)*(p-x)>S}function Ce(e,t,n,r,i){e[t]=n,e[t+1]=r,e[t+2]=r,e[t+3]=i,e[t+4]=i,e[t+5]=n}const we=6;export{F as createPlanarGlobePatch,y as createSphericalGlobePatch,L as updateEdgeElevationsAndResolutionsPlanar,D as updateEdgeElevationsAndResolutionsSpherical,R as updateEdgesAndCornersPlanar,E as updateEdgesAndCornersSpherical};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as n,releaseMaybe as r}from"../../../core/maybe.js";import{equals as i}from"../../../geometry/support/aaBoundingRect.js";import{glLayout as a}from"../support/buffer/glUtil.js";import{GeometryState as o}from"./GeometryState.js";import{PatchGeometry as s}from"./PatchGeometry.js";import"../../../geometry/support/Ellipsoid.js";import{internalAssert as c,
|
|
2
|
+
import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as n,releaseMaybe as r}from"../../../core/maybe.js";import{equals as i}from"../../../geometry/support/aaBoundingRect.js";import{glLayout as a}from"../support/buffer/glUtil.js";import{GeometryState as o}from"./GeometryState.js";import{PatchGeometry as s}from"./PatchGeometry.js";import"../../../geometry/support/Ellipsoid.js";import{internalAssert as c,oppositeEdge as l,neighborEdgeIndices as u,neighborCornerIndices as d,enableTerrainInternalChecks as f}from"./terrainUtils.js";import{maxTileNeighborLevelDelta as p}from"./TerrainConst.js";import{TextureFader as m}from"./TextureFader.js";import{TextureReference as h}from"./TextureReference.js";import g from"./TileOverlayData.js";import{fallsWithinLayerView as _}from"./tileUtils.js";import{VertexArrayObject as v}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as y}from"../../webgl/BufferObject.js";import{VertexBuffer as b}from"../../webgl/VertexBuffer.js";class x{constructor(){this.geometry=new s,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureFader=new m(()=>this._tile.surface.fadeDuration),this.overlay=new g,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new o,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureFader.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if(this._tile&&this.geometryState&&((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),f&&this.tile.intersectsClippingArea))for(let e=0;e<j;++e)c(this.geometry.getEdgeCount(e)===this.geometryState.edgeResolutions[e]+1)}_calculateEdgeResolution(e,t){let n=this.tile,r=this.geometryState.numVerticesPerSide-1;if(!n.surface.isGlobal){let t=n.surface.groundExtent;if(t!=null&&(e===0&&n.extent[3]>t[3]||e===1&&n.extent[2]>t[2]||e===2&&n.extent[1]<t[1]||e===3&&n.extent[0]<t[0]))return r}let i=n.level,a=u[e];if(!t)return f&&c(n.surface?.rootTiles==null||n.surface.updatingRootTiles||!n.shouldHaveNeighbor(a)),r;if(t.loaded){let n=t,a=n.renderData?.geometryState;if(!a)return r;let o=i-n.level;if(c(o>=0),o===0){let e=a.numVerticesPerSide-1;return Math.max(e,r)}let s=2**o,l=a.edgeResolutions[(e+2)%4]/s;return Math.max(1,l)}c(!t.leaf);let o=r;return t.forAllSubtreeOnSide(l(a),e=>e===n?!0:e.loaded?(o=Math.max(o,2**(e.level-i)),!0):(c(!e.leaf),!1)),o}updateNeighborData(){let e=this.tile;if(!e.intersectsClippingArea)return;let n=e.renderData.geometryState,r=t=>(t.loaded||t.level===e.level)&&t.intersectsClippingArea,i=n.edgePeerNeighbors,a=n.edgePeerNeighborSamplerVersions;for(let o=0;o<j;++o){let s=e.findNeighborTile(u[o],r),l=C(e,s),d=l?.renderData?.geometryState.samplerDataVersion??-1,m=i[o],h=l!==C(e,m),g=a[o]!==d;f&&s&&(c(e.level>=s.level),c(e.level-s.level<=p)),i[o]=s,(h||g)&&(a[o]=d,this._markEdgeDirty(o));let _=n.edgeResolutions[o],v=this._calculateEdgeResolution(o,s);c(t(v)),c(v>=1),n.edgeResolutions[o]=v,_!==v&&this._markEdgeResolutionDirty(o)}for(let t=0;t<j;++t){let a=e.findNeighborTile(d[t],r);n.cornerPeerNeighbors[t]=a;let o=C(e,i[t]),s=C(e,i[(t+1)%j]),l=C(e,a);S[t]=l,S[(t+1)%j]=s,S[(t+2)%j]=e,S[(t+3)%j]=o,f&&c(S.some(t=>t?.loaded||t===e));let u=S.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);S.forEach((e,t)=>{e&&e.level>u&&(S[t]=null)}),f&&c(S.some(t=>t?.loaded||t===e));let p=n.cornerNeighborCornerTiles,m=n.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<j;++e){let n=S[e],r=n?.renderData?.geometryState?.samplerDataVersion??-1,i=t*j+e,a=p[i]!==n,o=!a&&m[i]!==r;(a||o)&&(p[i]=n,m[i]=r,this._markCornerDirty(t))}f&&c(M.some(n=>{let r=p[t*j+n];return r?.loaded||r===e}))}f&&c(n.edgeResolutions.every(e=>e>0));for(let e=0;e<j;++e)S[e]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;f&&c(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;let{tile:t,_vao:n,geometry:r,geometryState:i}=this,{vertexAttributes:a}=r,o=!n||!a||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged,s=this.dirtyEdgeResolutions!==0,l=i.edgeResolutions.reduce((e,t)=>Math.max(e,t),0)+1,u=s&&l>r.maxEdgeVertexCount,d=o||this.numVerticesPerSideChanged||u,p=!d&&s,m=!p&&this.dirtyEdges!==0,h=!m&&this.dirtyCorners!==0;d?(this.releaseGeometry(),this._createGeometry(e)):p?t.updateEdgeElevationsAndResolutions():m||h?t.updateEdgeElevations():console.warn(`Update for no reason?`),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,this._vao?(this._vao=n(this._vao),this.geometry.release(),!0):!1}ensureTexture(e,t,n,r){let i=t?6408:6407;return this._texture!=null&&(n===0&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==i)&&this.releaseTexture(),this._texture??(this._texture=r(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=r(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!e||!this._texture?!1:(e.setTextureReference(new h(this._texture,!1,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return(this._modifiedFlags&w)!==0}get samplerDataChanged(){return(this._modifiedFlags&T)!==0}get clippingAreaChanged(){return(this._modifiedFlags&E)!==0}get wireframeChanged(){return(this._modifiedFlags&D)!==0}get dirtyEdges(){return this._modifiedFlags>>O&15}get dirtyCorners(){return this._modifiedFlags>>k&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>A&15}_markCornerDirty(e){let t=1<<e<<k;this._modifiedFlags|=t}_markEdgeDirty(e){let t=1<<e<<O;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){let t=1<<e<<A;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<k|15<<O|15<<A}updateGeometryState(){let e=this._elevationInfo,t=this.tile,n=e.samplerData?t.getElevationVerticesPerSide(e.maxTileLevel):t.minimumVerticesPerSide,r=Math.max(n,5),a=t.clippingArea;(!t.intersectsClippingArea||t.withinClippingArea)&&(a=null);let o=this.geometryState,s=!1;o.numVerticesPerSide!==r&&(this._modifiedFlags|=w,o.numVerticesPerSide=r,o.samplerDataVersion++,s=!0),e.changed&&(this._modifiedFlags|=T,o.samplerData=e.samplerData,o.samplerDataSourceLevels=e.samplerDataSourceLevels,o.samplerDataVersion++,s=!0),i(o.clippingArea,a)||(this._modifiedFlags|=E,o.clippingArea=a,s=!0);let c=t.surface.wireframe;return o.wireframe!==c&&(this._modifiedFlags|=D,o.wireframe=c,s=!0),this._geometryStateChangedSinceLastUpdate||=s,s&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();let{vertexAttributes:t,indices:n}=this.geometry,r=e.gl;this._vao=new v(e,new b(e,a(t.layout),t.buffer),y.createIndex(e,r.STATIC_DRAW,n)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureFader.push(e,t)}get textureReference(){return this._textureFader.current}get nextTextureReference(){return this._textureFader.next}get textureFadeFactor(){return this._textureFader.fadeFactor}get textureIsFading(){return this._textureFader.isFading}_isTextureVisible(e){return this._textureFader.current?.texture===e||this._textureFader.next?.texture===e&&this._textureFader.fadeFactor<1}get _elevationInfo(){let t=this.geometryState.samplerData,n=this.geometryState.samplerDataSourceLevels,r=this.tile.layerInfo[0],i=r.length,a=Array(i),o=Array(i),s=0,c=0,l=!1;for(let e=0;e<i;e++){let n=r[e],i=n.upsampleInfo?.tile;if(i){let n=i.layerInfo[0][e].data,r=n&&n.samplerData;t&&t[s]===r||(l=!0),a[s++]=r,o[s-1]=n?.level??i.level,c=Math.max(c,i.lij[0])}else if(n.data){let r=this.tile.surface.layerViewByIndex(e,0);if(_(this.tile,r)){let e=n.data;t&&t[s]===e.samplerData||(l=!0),a[s++]=e.samplerData,o[s-1]=e.level,c=this.tile.level}}}t!=null&&t.length!==s&&(l=!0);let u=s>0,d=u?a:null,f=u?o:null;return u&&(a.length=s,o.length=s),e(n,f)||(l=!0),{changed:l,samplerData:d,samplerDataSourceLevels:f,maxTileLevel:c}}get estimatedGeometryMemoryUsage(){let e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){}}const S=[null,null,null,null];function C(e,t){return t?.loaded||t===e?t:null}const w=1,T=2,E=4,D=8,O=4,k=8,A=12,j=4,M=[0,1,2,3];export{x as PatchRenderData,C as neighborTileIfLoadedOrSelf,M as zeroToFour};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import"../../../core/has.js";import{lerp as e}from"../../../core/mathUtils.js";import{normalize as t,set as n,add as r,scale as i,len as a,dot as o}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as s,ZEROS as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as l}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{intersectsSphere as u,numPlanes as d}from"../../../geometry/support/frustumPlanes.js";import{Sphere as f}from"../../../geometry/support/sphere.js";import{sphereIntersectsInfiniteRadialConeConservative as p}from"../support/ElevationAgnosticVisibility.js";import{correctSphericalTileCornersForLatitude as m,computeSmallestSphericalTileCone as h,getSphericalTilePole as g}from"../support/sphericalTileUtils.js";import{createSphericalGlobePatch as _,updateEdgesAndCornersSpherical as v,updateEdgeElevationsAndResolutionsSpherical as y}from"./PatchGeometryFactory.js";import"../../../core/Collection.js";import"../../../geometry/ellipsoidUtils.js";import"../../../geometry/support/spatialReferenceUtils.js";import"../../../kernel.js";import"../../../request.js";import"../../../core/urlUtils.js";import"../../../core/RandomLCG.js";import"../../../core/Logger.js";import"../../../core/accessorSupport/watch.js";import"../../../core/accessorSupport/tracking/SimpleTrackingTarget.js";import"../../../layers/Layer.js";import"../../../geometry/Extent.js";import"./TerrainConst.js";import"./TilingScheme.js";import{Tile as b}from"./Tile.js";class x extends b{constructor(e,t,n,r,i){super(),this._convexHull=Array(24),this._boundingConeAxis=s(),this._boundingConeHalfAngleSin=1,this._boundingSphere=new f,this._baseUsedMemory=1816,this.init(e,t,n,r,i)}init(n,r,i,a,o){super.init(n,r,i,a,o);let s=this.ellipsoid.radius,c=this.extentInRadians[0],u=this.extentInRadians[1],d=this.extentInRadians[2],f=this.extentInRadians[3],p=e(u,f,.5),m=e(c,d,.5),h=n===0?0:Math.min(Math.abs(u),Math.abs(f));this._edgeLen=(d-c)*Math.cos(h)*s,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=s-Math.sqrt(s*s-this._edgeLen2/4),l(this.centerAtSeaLevel,m,p,this.ellipsoid.radius),t(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();let e=this._center;if(this.lij[0]===0)e[1].center=c,n(e[0],0,0,0),n(e[2],0,0,0),e[1].radius=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();let t=e[1],n=this.convexHull,r=0,i=t.center;for(let e=0;e<8;++e)r=Math.max(r,C(i,n,e*3));e[1].radius=Math.sqrt(r)}}_calculateFrustumVisibility(e,t){if(!u(e,this._boundingSphere))return 2;let{level:n}=this;if(n>=2&&t!=null&&this._getPatchType()===0&&!p(this._boundingConeAxis,this._boundingConeHalfAngleSin,t.center,t.radius))return 2;if(n<10)return 1;let r=this.convexHull,i=this.surface.view.state.camera.near,a=!0;for(let t=0;t<d;t++){let n=t===4,o=e[t],s=o[0],c=o[1],l=o[2],u=o[3]-(n?i:0),d=!1;for(let e=0;e<8;++e){let t=e*3;if(s*r[t]+c*r[t+1]+l*r[t+2]+u<0){if(d=!0,!a)break}else a=!1}if(!d)return 2}return+!a}
|
|
2
|
+
import"../../../core/has.js";import{lerp as e}from"../../../core/mathUtils.js";import{normalize as t,set as n,add as r,scale as i,len as a,dot as o}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as s,ZEROS as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as l}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{intersectsSphere as u,numPlanes as d}from"../../../geometry/support/frustumPlanes.js";import{Sphere as f}from"../../../geometry/support/sphere.js";import{sphereIntersectsInfiniteRadialConeConservative as p}from"../support/ElevationAgnosticVisibility.js";import{correctSphericalTileCornersForLatitude as m,computeSmallestSphericalTileCone as h,getSphericalTilePole as g}from"../support/sphericalTileUtils.js";import{createSphericalGlobePatch as _,updateEdgesAndCornersSpherical as v,updateEdgeElevationsAndResolutionsSpherical as y}from"./PatchGeometryFactory.js";import"../../../core/Collection.js";import"../../../geometry/ellipsoidUtils.js";import"../../../geometry/support/spatialReferenceUtils.js";import"../../../kernel.js";import"../../../request.js";import"../../../core/urlUtils.js";import"../../../core/RandomLCG.js";import"../../../core/Logger.js";import"../../../core/accessorSupport/watch.js";import"../../../core/accessorSupport/tracking/SimpleTrackingTarget.js";import"../../../layers/Layer.js";import"../../../geometry/Extent.js";import"./TerrainConst.js";import"./TilingScheme.js";import{Tile as b}from"./Tile.js";class x extends b{constructor(e,t,n,r,i){super(),this._convexHull=Array(24),this._boundingConeAxis=s(),this._boundingConeHalfAngleSin=1,this._boundingSphere=new f,this._baseUsedMemory=1816,this.init(e,t,n,r,i)}init(n,r,i,a,o){super.init(n,r,i,a,o);let s=this.ellipsoid.radius,c=this.extentInRadians[0],u=this.extentInRadians[1],d=this.extentInRadians[2],f=this.extentInRadians[3],p=e(u,f,.5),m=e(c,d,.5),h=n===0?0:Math.min(Math.abs(u),Math.abs(f));this._edgeLen=(d-c)*Math.cos(h)*s,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=s-Math.sqrt(s*s-this._edgeLen2/4),l(this.centerAtSeaLevel,m,p,this.ellipsoid.radius),t(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();let e=this._center;if(this.lij[0]===0)e[1].center=c,n(e[0],0,0,0),n(e[2],0,0,0),e[1].radius=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();let t=e[1],n=this.convexHull,r=0,i=t.center;for(let e=0;e<8;++e)r=Math.max(r,C(i,n,e*3));e[1].radius=Math.sqrt(r)}}_calculateFrustumVisibility(e,t){if(!u(e,this._boundingSphere))return 2;let{level:n}=this;if(n>=2&&t!=null&&this._getPatchType()===0&&!p(this._boundingConeAxis,this._boundingConeHalfAngleSin,t.center,t.radius))return 2;if(n<10)return 1;let r=this.convexHull,i=this.surface.view.state.camera.near,a=!0;for(let t=0;t<d;t++){let n=t===4,o=e[t],s=o[0],c=o[1],l=o[2],u=o[3]-(n?i:0),d=!1;for(let e=0;e<8;++e){let t=e*3;if(s*r[t]+c*r[t+1]+l*r[t+2]+u<0){if(d=!0,!a)break}else a=!1}if(!d)return 2}return+!a}createGeometry(){_(this.renderData,this._getPatchType()),this.setMemoryDirty()}_updateBoundingVolumes(){this._updateConvexHull(),this._updateBoundingSphere()}_updateBoundingSphere(){let e=this._boundingSphere,t=this.elevationBoundsMin,n=this.elevationBoundsMax,o=this.ellipsoid.radius,s=n;if(this.level===0)e.center=c,e.radius=o+s;else{let s=this.extentInRadians,c=.5*(s[0]+s[2]),l=s[1],u=s[3];T(D,c,l,o),T(O,c,u,o),r(e.center,D,O);let d=o+.5*(t+n);i(e.center,e.center,d/a(e.center));let f=this.convexHull,p=0;for(let t=0;t<8;++t)p=Math.max(p,C(e.center,f,t*3));e.radius=Math.sqrt(p)+2}}_updateConvexHull(){let e=this.extentInRadians,n=this.ellipsoid.radius;if(this.level===0)return;let i=this.elevationBoundsMin,a=this.elevationBoundsMax,s=this._getPatchType(),c=this.surface.isWebMercator,l=c&&s===1,u=c&&s===2,d=u||l,f=Math.PI/2,p=e[0],g=e[2],_=u?-f:e[1],v=l?f:e[3],y=.5*(p+g),b=i,x=n+(d?Math.min(0,b-1):b),S=(e,t,n)=>T(e,t,n,x),C=k,w=A,D=j,O=M;S(C,p,_),S(w,p,v),S(D,g,v),S(O,g,_);let I=(e,t)=>{for(let n=0;n<3;++n)this._convexHull[t*3+n]=e[n]},L=a,R=n+(d?Math.max(0,L+1):L),z=N,B=P,V=F;T(B,y,v,x),T(V,y,_,x),r(z,B,V),t(z,z);let H=E;H[0]=C,H[1]=O,H[2]=D,H[3]=w,H[4]=V,H[5]=B,m(H,x),this._boundingConeHalfAngleSin=h(C,O,D,w,this._boundingConeAxis),I(C,0),I(w,1),I(D,2),I(O,3);let U=(e,t)=>{let n=R/o(t,z);for(let r=0;r<3;++r)this._convexHull[e*3+r]=t[r]*n};U(4,C),U(5,w),U(6,D),U(7,O)}_getPatchType(){let e=g(this.lij,this.spatialReference),t=e===1||e===3,n=e===2||e===3;return t?n?3:1:n?2:0}intersectsRay(e,t,n,r){let i=this._boundingSphere,a=i.radius+n,o=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=i.center[0]-e[0],c=i.center[1]-e[1],l=i.center[2]-e[2],u=(s*t[0]+c*t[1]+l*t[2])/o,d=t[0]*u,f=t[1]*u,p=t[2]*u,m=d-s,h=f-c,g=p-l;return m*m+h*h+g*g<a*a}get minimumVerticesPerSide(){return this.level<S.length?S[this.level]+1:2}updateEdgeElevations(){v(this.renderData)}updateEdgeElevationsAndResolutions(){y(this.renderData)}_checkBVs(){}get convexHull(){return this._convexHull}}const S=[128,64,64,32,16,8,8,4];function C(e,t,n){return w(e[0],e[1],e[2],t[n],t[n+1],t[n+2])}function w(e,t,n,r,i,a){let o=r-e,s=i-t,c=a-n;return o*o+s*s+c*c}const T=(e,t,n,r)=>{let i=Math.cos(t),a=Math.sin(t),o=Math.cos(n),s=Math.sin(n);e[0]=r*o*i,e[1]=r*o*a,e[2]=r*s},E=[null,null,null,null,null,null],D=s(),O=s(),k=s(),A=s(),j=s(),M=s(),N=s(),P=s(),F=s();export{x as SphericalPatch};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import has from"../../../core/has.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{MemCachePool as n}from"../../../core/MemCachePool.js";import r from"../../../core/ObjectPool.js";import{watch as i,sync as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import{subtract as c,set as l,dot as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as d,fromValues as f,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as m,ZEROS as h}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as g,set as _}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as v}from"../../../geometry/support/buffer/BufferView.js";import{overlayRenderOccludedFlag as y}from"./OverlayRenderer.js";import{PatchRenderData as b}from"./PatchRenderData.js";import{TerrainAttributesCache as x}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as S}from"./terrainUtils.js";import{TileRenderer as C}from"./TileRenderer.js";import{IteratorPreorder as w,fallsWithinLayerView as T,sortTiles as E,compareTiles as D}from"./tileUtils.js";import{getOverlayContentForOutputTerrain as O}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as k}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as A}from"../webgl-engine/lib/Attribute.js";import{IntersectorResultRay as j}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as M,MeshIntersectionOptions as N,intersectTriangles as P}from"../webgl-engine/lib/RayIntersections.js";import{TriangleIntersectionData as F}from"../webgl-engine/lib/TriangleIntersectionData.js";import{terrainId as I,getVerticalOffsetTerrain as L}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as R}from"../webgl-engine/materials/DrawParameters.js";import{hasShadowHighlights as z}from"../webgl-engine/shaders/ReceiveShadowsConfiguration.js";import{T as B}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as V}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as H}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as U}from"../../webgl/enums.js";const W=g();let G=class extends k{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return this._view.stage.viewingMode===1}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}get renderOccludedFlags(){return this._overlayRenderer.renderOccludedFlags}constructor(e,t,i,a,o){super({}),this._surface=e,this._overlayRenderer=t,this._allTiles=i,this._compressionTracker=a,this.type=7,this.isGround=!0,this._passParameters=new B,this._drawParameters=new R,this._renderDataPool=new r(()=>new b),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new w,this._castShadows=!1,this._inViewshed=!1,this._cutFillEnabled=!1,this._tileRenderer=null,this._stencilEnabledLayerExtents=[],this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.produces=new Map([[1,()=>this._desiredSlot===1],[7,()=>this._desiredSlot===7],[9,()=>this._produces()&&this.renderOccludedFlags===y]]),this._tileSize=256,this._configuration=new H(e.isGlobal),this._tileTextureCache=new n((e,t)=>o.newCache(e,t),`TileTexture`),this.tileGeometryCache=new x(o)}normalizeCtorArgs(){return{}}initialize(){this.addHandles(i(()=>this._overlayRenderer.renderOccludedFlags,()=>this.requestRender(),a))}destroy(){this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set(`renderingDisabled`,!!e),this.setDirty()}set visible(e){this._set(`visible`,!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.requestRender())}get transparency(){return this._configuration.transparencyMode}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.requestRender(),this.notifyChange(`renderPatchBorders`))}get layerViewUid(){return I}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.requestRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.requestRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.requestRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,this._tileRenderer!=null&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,32)}reuseTextureFromParent(e){let{parent:t}=e;if(!this._canReuseTextureFromParent(t,e))return!1;let n=m(e.lij[2]&1?.5:0,e.lij[1]&1?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,n)??!1}_canReuseTextureFromParent(e,t){if(!e)return!1;let{layerInfo:n,surface:r}=t;for(let i=0;i<n[1].length;i++){let n=r.layerViewByIndex(i,1);if(T(e,n)!==T(t,n))return!1}return!0}updateTileTexture(e,t){this._tileRenderer!=null&&(this._tileRenderer.updateTileTexture(e,t===32?0:2),this.requestRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(let t of e.layerInfo[0])t.pendingUpdates&=-9;e.resetPendingUpdate(8);let t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){let t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){let t=Math.max(0,Math.floor((e.level-3)/7)*7);if(this._isGlobal&&t===0)return d;for(;e.parent&&e.level>t;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get(`wireframe`)!==e&&(this._set(`wireframe`,e),this.requestRender())}setDirty(e=1){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=1){this._patchSortingDirty=!0,this._context.requestRender(e)}requestRender(e=1){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new C(this._surface,this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=t(this._tileRenderer)}intersectRay(e,t,n,r){let i=this._rootTiles;if(!i||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==0)return;let a=K,o=q;c(a,r,n),l(o,1/a[0],1/a[1],1/a[2]);let s=e.results.min,d=e.results.max,f=e.results.ground,p=e.options.store===0,m=!!e.results.ground.target,h=L(e.verticalOffset),g=e.tolerance,y,b=p&&s.distance!=null?s.distance:1/0,x=e.options,S=x.normalRequired||!x.backfacesTerrain,C=new N(g,!1,S),w=i=>{let l=i.renderData;if(!l?.vao)return;let m=l.geometry;_(W,m.boundingBox);let w=l.localOrigin;if(h!=null&&(h.localOrigin=w,h.applyToAabb(W)),J[0]=n[0]-w[0],J[1]=n[1]-w[1],J[2]=n[2]-w[2],!M(W,J,o,g,b))return;let T=(e,t,n,r)=>{e.set(this.type,i,t,n,r),b=p&&s.renderDistance!=null?s.renderDistance:1/0},E=(i,o,c)=>{(!S||c!=null)&&o>=0&&(x.backfacesTerrain||u(c,a)<0)&&(x.invisibleTerrain||!x.selectionMode||t==null||t(n,r,o))&&((f.renderDistance==null||o<f.renderDistance)&&T(f,i,o,c),x.isFiltered||(x.store===2&&(y==null?(y=new j(e.ray),T(y,i,o,c),e.results.all.push(y)):o<y.renderDistance&&T(y,i,o,c)),(s.renderDistance==null||o<s.renderDistance)&&T(s,i,o,c),x.store!==0&&(d.renderDistance==null||o>d.renderDistance)&&T(d,i,o,c)))},D=Y;c(D,r,w);let{indices:O,indexCount:k}=m,N=m.vertexAttributes,I=N.getField(`position`,v),L=new A(I.typedBuffer,3,N.stride/4),R=k/3;!h&&R>200?(l.intersectionData??=new F(O,R,L),l.intersectionData.intersectRay(J,D,C,E)):P(J,D,0,R,(e,t)=>I.getVec(O[t],e),h,C,E)},T=this._tileIterator;T.reset(i);let E=e.options.invisibleTerrain;for(let e=T.next();e;e=T.next())(e.visible||E&&e.intersectsClippingArea)&&(h!=null||e.intersectsRay(n,a,g,b))&&(!m||!this._useStencilForTile(e))?w(e):T.skipSubtree()}processScaleRangeQueries(e,t){if(!t.done&&e)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(let t of this._visiblePatchesByOrigin.values())for(let n of t)n.renderData?.textureReference!=null&&e.queriesForTile(n);e.process(),t.madeProgress()}}get _view(){return this._surface.view}get _desiredSlot(){if(!this._produces())return null;switch(this.transparency){case 0:return 1;case 1:case 2:return 7;case 3:case 4:return null}}acquireTechniques(e){let{shadowMap:t,viewshedEnabled:n,cutFillComputationEnabled:r,slot:i,hasEmission:a,useFloatBlend:o}=e.bind,s=!!has(`enable-feature:terrain-shadows`)&&t.enabled;if(s!==this._castShadows&&(this._castShadows=s,this._patchesByOriginDirty=!0),this._inViewshed!==n&&(this._inViewshed=n,this._patchesByOriginDirty=!0),this._cutFillEnabled!==r&&(this._cutFillEnabled=r,this._patchesByOriginDirty=!0),this.transparency===3)return null;if(i===9){if((e.renderOccludedMask&y)===0)return null}else if(i!==this._desiredSlot)return null;let c=this._configuration;switch(c.receiveGlobalIllumination=c.screenSpaceReflections=c.cloudReflections=c.receiveShadows=c.hasShadowHighlights=c.receiveAmbientOcclusion=c.renderOccluded=c.hasHighlightMixTexture=!1,c.hasEmission=a,c.overlayMode=this._overlayRenderer.mode,c.useFloatBlend=o.value,e.output){case 0:case 1:case 2:{let n=e.bind;c.screenSpaceReflections=n.hasScreenSpaceReflections,c.cloudReflections=n.clouds.data!=null;let r=i===9;return c.receiveShadows=t.ready&&!r,c.hasShadowHighlights=z(c,e.bind),c.renderOccluded=r,c.receiveAmbientOcclusion=!r&&n.ssao!=null,c.receiveGlobalIllumination=!r&&n.globalIlluminationEnabled,this._acquireTechnique(e.output)}case 5:case 7:return this._castShadows?this._acquireTechnique(5):null;case 8:return this._inViewshed?this._acquireTechnique(8):null;case 9:return this._cutFillEnabled?this._acquireTechnique(9):null;case 3:case 4:case 11:return this._acquireTechnique(e.output);case 10:return c.hasHighlightMixTexture=e.bind.highlightMixTexture!=null,this._overlayRenderer.hasHighlights?this._acquireTechnique(10):null}return null}render(e,t){switch(this._updatePatchGroups(),this._passParameters.useStencil=!1,this._passParameters.overlayContent=O(e.output,e.bind),e.output){case 0:case 1:case 2:return this._renderMaterialPass(e,t);case 3:case 4:case 11:return this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);case 10:{let n=e.bind.highlight?.name;n&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(2)&&this._overlayRenderer.hasHighlight(n)&&this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);break}case 5:case 7:case 8:case 9:return this._renderAuxiliaryPass(e,t,this._allPatchesByOrigin)}}updateTileBackground(e){if(this._tileRenderer==null)return;let t=this._tileRenderer,n;if(e!=null){let t=e.toUnitRGBA();n=f(t[0]||0,t[1]||0,t[2]||0)}t.setBackground(n),this._allTiles.forAll(e=>t.updateTileTexture(e,0)),this._configuration.tileBlendInput=t.backgroundIsGrid?2:t.backgroundColor==null?0:1,this.requestRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty){let e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(let n of e)E(n,t);e.sort((e,t)=>D(e[0],t[0])),this._visiblePatchesByOrigin=new Map(e.map(e=>[e[0].renderData.localOrigin,e])),this.notifyChange(`visibleTiles`),this._patchSortingDirty=!1}}_rebuildPatchGroups(){let e=this._rootTiles;if(e!=null){e[0]?.surface.checkAllTilesWaterproofness(`render-patch-groups`),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(let t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){let t=this._tileIterator;for(t.resetOne(e);!t.done;){let e=t.next(),n=e.renderData;if(!n){this._numTilesCulled++;continue}let r=n.localOrigin;if(this._castShadows||this._inViewshed||this._cutFillEnabled){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let i=this._visiblePatchesByOrigin.get(r);i||(i=[],this._visiblePatchesByOrigin.set(r,i)),i.push(e),t.skipSubtree()}}_useStencilForTile(e){for(let t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderAuxiliaryPass(e,t,n){let{rctx:r,bind:i}=e;r.bindTechnique(t,i,this._passParameters);let a=this._stencilEnabledLayerExtents.length>0;n.forEach(n=>{this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(i,this._passParameters,this._drawParameters);for(let r=0;r<n.length;r++)this._renderPatch(e,t,n[r],U.TRIANGLES,a,this._passParameters.overlayContent===null)}),r.bindVAO(null)}_renderMaterialPass(e,t){let{rctx:n,bind:r}=e,i=n.bindTechnique(t,r,this._passParameters);this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;let a=r.slot===9;a&&(i.bindTexture(`tex`,n.emptyTexture),i.setUniform3fv(`textureOpacities`,d),i.setUniform4fv(`texOffsetAndScale`,h));let o=this._tileRenderer?.backgroundColor==null?d:this._tileRenderer.backgroundColor;this._configuration.tileBlendInput===1&&i.setUniform3fv(`backgroundColor`,o);let s=this._stencilEnabledLayerExtents.length>0,c=this.wireframe?U.LINES:U.TRIANGLES;this._configuration.textureFadingEnabled&&i.bindTexture(`texNext`,n.emptyTexture);for(let n of this._visiblePatchesByOrigin.values()){this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(r,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(let r of n){let n=r.renderData,o=n.textureReference;if(o!=null){if(!a){i.setUniform4fv(`texOffsetAndScale`,o.offsetAndScale),i.bindTexture(`tex`,o.texture.texture);let e=n.textureFadeFactor,t=e<1?n.nextTextureReference:null;this._configuration.textureFadingEnabled&&t&&e<1?(i.setUniform1f(`fadeFactor`,e),i.setUniform4fv(`nextTexOffsetAndScale`,t.offsetAndScale),i.setUniform3fv(`nextTexOpacities`,t.opacities),i.bindTexture(`texNext`,t.texture.texture)):i.setUniform1f(`fadeFactor`,1),n.textureIsFading&&this.requestRender(2),i.setUniform3fv(`textureOpacities`,o.opacities)}this._renderPatch(e,t,r,c,s),r.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}n.bindVAO(null)}_renderPatch(e,t,n,r,i,a=!1){let o=n.renderData,s=o.vao,c=s?.indexBuffer;if(!s||c==null){S&&console.error(`Rendered tile with no indices: `,n.lij,` : `,o);return}let l=t.program;!a&&!this._overlayRenderer.isEmpty&&this._bindOverlayPatchData(l,o.overlay);let{rctx:u,bind:d}=e;i&&(this._passParameters.useStencil=this._useStencilForTile(n),u.setPipelineState(t.getPipeline(d,this._passParameters)));let f=o.geometry.indexCount;u.bindVAO(s),l.assertCompatibleVertexAttributeLocations(s),u.drawElements(r,f,c.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv(`overlayTexOffset`,t.offsets),e.setUniform4fv(`overlayTexScale`,t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(V,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([o({readOnly:!0})],G.prototype,`visibleTiles`,null),e([o({readOnly:!0})],G.prototype,`_isGlobal`,null),e([o()],G.prototype,`renderOccludedFlags`,null),e([o({value:!1})],G.prototype,`renderingDisabled`,null),e([o({value:!0})],G.prototype,`visible`,null),e([o()],G.prototype,`renderPatchBorders`,null),e([o()],G.prototype,`wireframe`,null),G=e([s(`esri.views.3d.terrain.TerrainRenderer`)],G);const K=p(),q=p(),J=p(),Y=p();export{G as TerrainRenderer};
|
|
2
|
+
import{__decorate as e}from"tslib";import has from"../../../core/has.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{MemCachePool as n}from"../../../core/MemCachePool.js";import r from"../../../core/ObjectPool.js";import{watch as i,sync as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import{subtract as c,set as l,dot as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as d,fromValues as f,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as m,ZEROS as h}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as g,set as _}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as v}from"../../../geometry/support/buffer/BufferView.js";import{overlayRenderOccludedFlag as y}from"./OverlayRenderer.js";import{PatchRenderData as b}from"./PatchRenderData.js";import{TerrainAttributesCache as x}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as S}from"./terrainUtils.js";import{TileRenderer as C}from"./TileRenderer.js";import{IteratorPreorder as w,fallsWithinLayerView as T,usesStencil as E,sortTiles as D,compareTiles as O}from"./tileUtils.js";import{getOverlayContentForOutputTerrain as k}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as A}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as j}from"../webgl-engine/lib/Attribute.js";import{IntersectorResultRay as M}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as N,MeshIntersectionOptions as P,intersectTriangles as F}from"../webgl-engine/lib/RayIntersections.js";import{TriangleIntersectionData as I}from"../webgl-engine/lib/TriangleIntersectionData.js";import{terrainId as L,getVerticalOffsetTerrain as R}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as z}from"../webgl-engine/materials/DrawParameters.js";import{hasShadowHighlights as B}from"../webgl-engine/shaders/ReceiveShadowsConfiguration.js";import{T as V}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as H}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as U}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as W}from"../../webgl/enums.js";const G=g();let K=class extends A{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return this._view.stage.viewingMode===1}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}get renderOccludedFlags(){return this._overlayRenderer.renderOccludedFlags}constructor(e,t,i,a,o){super({}),this._surface=e,this._overlayRenderer=t,this._allTiles=i,this._compressionTracker=a,this.type=7,this.isGround=!0,this._passParameters=new V,this._drawParameters=new z,this._renderDataPool=new r(()=>new b),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new w,this._castShadows=!1,this._inViewshed=!1,this._cutFillEnabled=!1,this._tileRenderer=null,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.produces=new Map([[1,()=>this._desiredSlot===1],[7,()=>this._desiredSlot===7],[9,()=>this._produces()&&this.renderOccludedFlags===y]]),this._tileSize=256,this._configuration=new U(e.isGlobal),this._tileTextureCache=new n((e,t)=>o.newCache(e,t),`TileTexture`),this.tileGeometryCache=new x(o)}normalizeCtorArgs(){return{}}initialize(){this.addHandles(i(()=>this._overlayRenderer.renderOccludedFlags,()=>this.requestRender(),a))}destroy(){this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set(`renderingDisabled`,!!e),this.setDirty()}set visible(e){this._set(`visible`,!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.requestRender())}get transparency(){return this._configuration.transparencyMode}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.requestRender(),this.notifyChange(`renderPatchBorders`))}get layerViewUid(){return L}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.requestRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.requestRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.requestRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,this._tileRenderer!=null&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,32)}reuseTextureFromParent(e){let{parent:t}=e;if(!this._canReuseTextureFromParent(t,e))return!1;let n=m(e.lij[2]&1?.5:0,e.lij[1]&1?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,n)??!1}_canReuseTextureFromParent(e,t){if(!e)return!1;let{layerInfo:n,surface:r}=t;for(let i=0;i<n[1].length;i++){let n=r.layerViewByIndex(i,1);if(T(e,n)!==T(t,n))return!1}return!0}updateTileTexture(e,t){this._tileRenderer!=null&&(this._tileRenderer.updateTileTexture(e,t===32?0:2),this.requestRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(let t of e.layerInfo[0])t.pendingUpdates&=-9;e.resetPendingUpdate(8);let t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){let t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){let t=Math.max(0,Math.floor((e.level-3)/7)*7);if(this._isGlobal&&t===0)return d;for(;e.parent&&e.level>t;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get(`wireframe`)!==e&&(this._set(`wireframe`,e),this.requestRender())}setDirty(e=1){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=1){this._patchSortingDirty=!0,this._context.requestRender(e)}requestRender(e=1){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new C(this._surface,this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=t(this._tileRenderer)}intersectRay(e,t,n,r){let i=this._rootTiles;if(!i||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==0)return;let a=q,o=J;c(a,r,n),l(o,1/a[0],1/a[1],1/a[2]);let s=e.results.min,d=e.results.max,f=e.results.ground,p=e.options.store===0,m=!!e.results.ground.target,h=R(e.verticalOffset),g=e.tolerance,y,b=p&&s.distance!=null?s.distance:1/0,x=e.options,S=x.normalRequired||!x.backfacesTerrain,C=new P(g,!1,S),w=i=>{let l=i.renderData;if(!l?.vao)return;let m=l.geometry;_(G,m.boundingBox);let w=l.localOrigin;if(h!=null&&(h.localOrigin=w,h.applyToAabb(G)),Y[0]=n[0]-w[0],Y[1]=n[1]-w[1],Y[2]=n[2]-w[2],!N(G,Y,o,g,b))return;let T=(e,t,n,r)=>{e.set(this.type,i,t,n,r),b=p&&s.renderDistance!=null?s.renderDistance:1/0},E=(i,o,c)=>{(!S||c!=null)&&o>=0&&(x.backfacesTerrain||u(c,a)<0)&&(x.invisibleTerrain||!x.selectionMode||t==null||t(n,r,o))&&((f.renderDistance==null||o<f.renderDistance)&&T(f,i,o,c),x.isFiltered||(x.store===2&&(y==null?(y=new M(e.ray),T(y,i,o,c),e.results.all.push(y)):o<y.renderDistance&&T(y,i,o,c)),(s.renderDistance==null||o<s.renderDistance)&&T(s,i,o,c),x.store!==0&&(d.renderDistance==null||o>d.renderDistance)&&T(d,i,o,c)))},D=X;c(D,r,w);let{indices:O,indexCount:k}=m,A=m.vertexAttributes,P=A.getField(`position`,v),L=new j(P.typedBuffer,3,A.stride/4),R=k/3;!h&&R>200?(l.intersectionData??=new I(O,R,L),l.intersectionData.intersectRay(Y,D,C,E)):F(Y,D,0,R,(e,t)=>P.getVec(O[t],e),h,C,E)},T=this._tileIterator;T.reset(i);let D=e.options.invisibleTerrain;for(let e=T.next();e;e=T.next())(e.visible||D&&e.intersectsClippingArea)&&(h!=null||e.intersectsRay(n,a,g,b))&&(!m||!E(e,this._stencilEnabledLayerExtents))?w(e):T.skipSubtree()}processScaleRangeQueries(e,t){if(!t.done&&e)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(let t of this._visiblePatchesByOrigin.values())for(let n of t)n.renderData?.textureReference!=null&&e.queriesForTile(n);e.process(),t.madeProgress()}}get _view(){return this._surface.view}get _desiredSlot(){if(!this._produces())return null;switch(this.transparency){case 0:return 1;case 1:case 2:return 7;case 3:case 4:return null}}acquireTechniques(e){let{shadowMap:t,viewshedEnabled:n,cutFillComputationEnabled:r,slot:i,hasEmission:a,useFloatBlend:o}=e.bind,s=!!has(`enable-feature:terrain-shadows`)&&t.enabled;if(s!==this._castShadows&&(this._castShadows=s,this._patchesByOriginDirty=!0),this._inViewshed!==n&&(this._inViewshed=n,this._patchesByOriginDirty=!0),this._cutFillEnabled!==r&&(this._cutFillEnabled=r,this._patchesByOriginDirty=!0),this.transparency===3)return null;if(i===9){if((e.renderOccludedMask&y)===0)return null}else if(i!==this._desiredSlot)return null;let c=this._configuration;switch(c.receiveGlobalIllumination=c.screenSpaceReflections=c.cloudReflections=c.receiveShadows=c.hasShadowHighlights=c.receiveAmbientOcclusion=c.renderOccluded=c.hasHighlightMixTexture=!1,c.hasEmission=a,c.overlayMode=this._overlayRenderer.mode,c.useFloatBlend=o.value,e.output){case 0:case 1:case 2:{let n=e.bind;c.screenSpaceReflections=n.hasScreenSpaceReflections,c.cloudReflections=n.clouds.data!=null;let r=i===9;return c.receiveShadows=t.ready&&!r,c.hasShadowHighlights=B(c,e.bind),c.renderOccluded=r,c.receiveAmbientOcclusion=!r&&n.ssao!=null,c.receiveGlobalIllumination=!r&&n.globalIlluminationEnabled,this._acquireTechnique(e.output)}case 5:case 7:return this._castShadows?this._acquireTechnique(5):null;case 8:return this._inViewshed?this._acquireTechnique(8):null;case 9:return this._cutFillEnabled?this._acquireTechnique(9):null;case 3:case 4:case 11:return this._acquireTechnique(e.output);case 10:return c.hasHighlightMixTexture=e.bind.highlightMixTexture!=null,this._overlayRenderer.hasHighlights?this._acquireTechnique(10):null}return null}render(e,t){switch(this._updatePatchGroups(),this._passParameters.useStencil=!1,this._passParameters.overlayContent=k(e.output,e.bind),e.output){case 0:case 1:case 2:return this._renderMaterialPass(e,t);case 3:case 4:case 11:return this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);case 10:{let n=e.bind.highlight?.name;n&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(2)&&this._overlayRenderer.hasHighlight(n)&&this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);break}case 5:case 7:case 8:case 9:return this._renderAuxiliaryPass(e,t,this._allPatchesByOrigin)}}updateTileBackground(e){if(this._tileRenderer==null)return;let t=this._tileRenderer,n;if(e!=null){let t=e.toUnitRGBA();n=f(t[0]||0,t[1]||0,t[2]||0)}t.setBackground(n),this._allTiles.forAll(e=>t.updateTileTexture(e,0)),this._configuration.tileBlendInput=t.backgroundIsGrid?2:t.backgroundColor==null?0:1,this.requestRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty){let e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(let n of e)D(n,t);e.sort((e,t)=>O(e[0],t[0])),this._visiblePatchesByOrigin=new Map(e.map(e=>[e[0].renderData.localOrigin,e])),this.notifyChange(`visibleTiles`),this._patchSortingDirty=!1}}_rebuildPatchGroups(){let e=this._rootTiles;if(e!=null){e[0]?.surface.checkAllTilesWaterproofness(`render-patch-groups`),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(let t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){let t=this._tileIterator;for(t.resetOne(e);!t.done;){let e=t.next(),n=e.renderData;if(!n){this._numTilesCulled++;continue}let r=n.localOrigin;if(this._castShadows||this._inViewshed||this._cutFillEnabled){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let i=this._visiblePatchesByOrigin.get(r);i||(i=[],this._visiblePatchesByOrigin.set(r,i)),i.push(e),t.skipSubtree()}}_renderAuxiliaryPass(e,t,n){let{rctx:r,bind:i}=e;r.bindTechnique(t,i,this._passParameters);let a=!!this._stencilEnabledLayerExtents?.length;n.forEach(n=>{this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(i,this._passParameters,this._drawParameters);for(let r=0;r<n.length;r++)this._renderPatch(e,t,n[r],W.TRIANGLES,a,this._passParameters.overlayContent===null)}),r.bindVAO(null)}_renderMaterialPass(e,t){let{rctx:n,bind:r}=e,i=n.bindTechnique(t,r,this._passParameters);this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;let a=r.slot===9;a&&(i.bindTexture(`tex`,n.emptyTexture),i.setUniform3fv(`textureOpacities`,d),i.setUniform4fv(`texOffsetAndScale`,h));let o=this._tileRenderer?.backgroundColor==null?d:this._tileRenderer.backgroundColor;this._configuration.tileBlendInput===1&&i.setUniform3fv(`backgroundColor`,o);let s=!!this._stencilEnabledLayerExtents?.length,c=this.wireframe?W.LINES:W.TRIANGLES;this._configuration.textureFadingEnabled&&i.bindTexture(`texNext`,n.emptyTexture);for(let n of this._visiblePatchesByOrigin.values()){this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(r,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(let r of n){let n=r.renderData,o=n.textureReference;if(o!=null){if(!a){i.setUniform4fv(`texOffsetAndScale`,o.offsetAndScale),i.bindTexture(`tex`,o.texture.texture);let e=n.textureFadeFactor,t=e<1?n.nextTextureReference:null;this._configuration.textureFadingEnabled&&t&&e<1?(i.setUniform1f(`fadeFactor`,e),i.setUniform4fv(`nextTexOffsetAndScale`,t.offsetAndScale),i.setUniform3fv(`nextTexOpacities`,t.opacities),i.bindTexture(`texNext`,t.texture.texture)):i.setUniform1f(`fadeFactor`,1),n.textureIsFading&&this.requestRender(2),i.setUniform3fv(`textureOpacities`,o.opacities)}this._renderPatch(e,t,r,c,s),r.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}n.bindVAO(null)}_renderPatch(e,t,n,r,i,a=!1){let o=n.renderData,s=o.vao,c=s?.indexBuffer;if(!s||c==null){S&&console.error(`Rendered tile with no indices: `,n.lij,` : `,o);return}let l=t.program;!a&&!this._overlayRenderer.isEmpty&&this._bindOverlayPatchData(l,o.overlay);let{rctx:u,bind:d}=e;i&&(this._passParameters.useStencil=E(n,this._stencilEnabledLayerExtents),u.setPipelineState(t.getPipeline(d,this._passParameters)));let f=o.geometry.indexCount;u.bindVAO(s),l.assertCompatibleVertexAttributeLocations(s),u.drawElements(r,f,c.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv(`overlayTexOffset`,t.offsets),e.setUniform4fv(`overlayTexScale`,t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(H,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([o({readOnly:!0})],K.prototype,`visibleTiles`,null),e([o({readOnly:!0})],K.prototype,`_isGlobal`,null),e([o()],K.prototype,`renderOccludedFlags`,null),e([o({value:!1})],K.prototype,`renderingDisabled`,null),e([o({value:!0})],K.prototype,`visible`,null),e([o()],K.prototype,`renderPatchBorders`,null),e([o()],K.prototype,`wireframe`,null),K=e([s(`esri.views.3d.terrain.TerrainRenderer`)],K);const q=p(),J=p(),Y=p(),X=p();export{K as TerrainRenderer};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as p,isAborted as m}from"../../../core/promiseUtils.js";import{watch as h,syncAndInitial as g,initial as _,sync as v}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as ne}from"../../../core/units.js";import{property as y,subclass as re}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ie,set as ae,copy as oe}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as se}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ce,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import x from"../../../geometry/SpatialReference.js";import{getProjector as S}from"../../../geometry/projection/projectors.js";import{projectPointToVector as C}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as ue}from"../../../geometry/projection/projectVectorToVector.js";import{create as w,equals as T,intersection as de,intersectsSphere as fe}from"../../../geometry/support/aaBoundingRect.js";import{copy as pe,create as me}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as he}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as ge}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as _e}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as ve}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as ye}from"../../../layers/support/layerUtils.js";import{queueHighPriority as be}from"../../../request/queue.js";import{debugFlags as E}from"../support/debugFlags.js";import{ElevationRange as D}from"../support/ElevationRange.js";import{ElevationUpdateEvent as xe}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Se}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as Ce}from"../support/extentUtils.js";import{updatingProgress as we}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Te,sampleElevation as Ee}from"./ElevationData.js";import{create as De}from"./ExtentHelper.js";import{LayerClasses as Oe}from"./LayerClass.js";import{OverlayManager as ke}from"./OverlayManager.js";import{PlanarPatch as Ae}from"./PlanarPatch.js";import{Queue as je}from"./Queue.js";import{ScaleRangeQueries as Me}from"./ScaleRangeQueries.js";import{SphericalPatch as Ne}from"./SphericalPatch.js";import{SplitLimits as Pe}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as Fe,tooManyRootTilesForLayerError as Ie,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Le}from"./TerrainConst.js";import{TerrainRenderer as Re}from"./TerrainRenderer.js";import ze from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Be,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as Ve,enableTerrainInternalChecks as V,enableWaterproofTests as He,enableInternalTerrainChecks as Ue,enableTerrainWaterproofChecks as We,neighborCornerIndices as Ge}from"./terrainUtils.js";import{Tile as Ke,lijEquals as H}from"./Tile.js";import{printAllocations as qe}from"./TilePerLayerInfo.js";import{sortTiles as Je,IteratorPreorder as Ye,IteratorPostorder as Xe,compareTilesByLij as U,hasLoadableSiblings as Ze,sortTilesByPOI as Qe,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as $e}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as et}from"./TransparencyMode.js";import{UpsampleInfo as tt}from"./UpsampleInfo.js";import{isCompositeBlendMode as nt,blendModeFromString as rt}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as it}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as at,noBudget as ot}from"../../support/Scheduler.js";import{TextureCompressionTracker as st}from"../../support/TextureCompressionTracker.js";import{Yield as ct}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Je(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=ne(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new st,this._iteratorPool=new d(()=>new Ye,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Xe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new ze,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=b(),this._eyePosSurfaceSR=b(),this._splitLimits=new Pe,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new se,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new tt),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=w(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new D(1/0,-1/0),this._rootTileElevationRange=new D(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new ke({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?Ne:Ae,this._ellipsoid=ce(t.spatialReference),this._renderer=new Re(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),it()||(this._scaleRangeQueries=new Me)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new ve(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([h(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),h(()=>this.renderer.visible,e=>this.freeze=!e),h(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},g)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},_),this.addHandles([h(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},g),h(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),g),h(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},v),h(()=>this.snapLevel,()=>this._viewChanged=!0,v),h(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ie}))}),h(()=>E.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&E.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},_)]);let{spatialReference:a}=e;this._extentHelper=De(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new $e({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(at.TERRAIN_SURFACE,this),this.addHandles([h(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),_),h(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),v),h(()=>this.groundExtent,()=>this._updateRootTiles(),_),e.on(`resize`,()=>this._viewChangeUpdate()),h(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),g),h(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,_),h(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,_),h(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),h(()=>this.userClippingExtent,()=>this._updateClippingExtent(),v)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),Ke.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),qe(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=w(),r=Ce(t,n,e)?n:null,i=this._get(`userClippingExtent`);return T(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=de(this.fullGroundExtent,this.userClippingExtent,w()),t=this._get(`groundExtent`);return T(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._hasElevationSourceUpdates||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.freeze}get _hasElevationSourceUpdates(){return this._allTiles.some(e=>e.needsElevationSourceUpdate())}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||this._rootTiles!=null}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set(`slicePlaneEnabled`,e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return he(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=S(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=ae(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return ft(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=ft(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!C(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}_ensureProjector(e){let t=this._projectorCache.get(e);if(t)return t;let n=S(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,n),n}getSphereElevationRange(e,t){if(!this.enabled||this._rootTiles==null)return null;let n=this._ensureProjector(t);if(n==null)return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system`),null;Y.copyFrom(e),n(Y.center,0,Y.center,0);let r=new D,i=this._rootTiles;if(i!=null){let e=[];for(let t of i)e.push(t);let t=0;for(;t<e.length;){let n=e[t];if(++t,!fe(n.extent,Y))continue;let i=n.children;if(i[0]==null||n.rendered)r.expandElevationRangeValues(n.elevationBoundsMin,n.elevationBoundsMax);else for(let t of i)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new D(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!C(e,Y.center,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system`),null;Y.radius=t;let n=null,r=e=>{if(e&&fe(e.extent,Y)){let t=e.children;if(t[0]&&!e.rendered)for(let e of t)r(e);else{let t=this._getLodBiasCorrectedScale(e.level);n=n==null?t:Math.min(n,t)}}},i=this._rootTiles;if(i!=null)for(let e of i)r(e);return n}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?et(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&ge(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=ut,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(Fe);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(Ie),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));T(n,this._rootTilesExtent)||(this._rootTilesExtent=w(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),e!=null){let t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.freeze&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(e==null)return;let t=Ze(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=pe(this._splitLimits.frustum??me(),t.frustum):this._splitLimits.frustum=null,oe(this._eyePosRenderSR,t.eye),ue(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();let t=this._renderer.updateTileGeometryState(e);e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate()),t&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(M)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.resetPendingUpdate(32)?32:e.resetPendingUpdate(16)?16:!1;n&&(this._renderer.updateTileTexture(e,n),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Se(t,this.spatialReference)){let t=new xe(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateElevationSources(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let n=this._pendingTilesToUpdate.size>0,r=n&&this._hasPendingGeometryWithoutIndices();if((!e.done||r)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||n&&!r)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!e.hasProgressed)return ct}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new je(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=s?4:e.shouldSplit(i,a,r),l=c===1;e.leaf?Z(e,l):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):l?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),c===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(Qe(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=Ge[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(Ve(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Be(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&He&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}_updateElevationSources(e){e.done||this._allTiles.some(t=>(t.needsElevationSourceUpdate()&&(t.updateAgents(0),t.markElevationSourceUpdateRequested(),e.madeProgress()),e.done))}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*Le}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange(`ready`)),this._allTiles.clear(),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){let t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?mt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._tileMemcacheKey,e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),mt(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(e.rendered,`parent should be rendered`),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=ot){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(let e of this.view.allLayerViews.items)if(L(e)&&!ye(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&nt(rt[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(h(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(h(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(h(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(h(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of Oe){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),p(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!m(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{p(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...be,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Te(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),m(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(this._usedMemory??=this._recalculateUsedMemory(),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(e=`render-patch-groups`){}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ue(e)}enableWaterproofnessChecks(e){We(e)}static cleanupTerrainSurface(){dt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([y()],q.prototype,`_renderer`,void 0),e([y({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([y({constructOnly:!0})],q.prototype,`view`,void 0),e([y({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([y()],q.prototype,`_hasPendingUpdates`,void 0),e([y()],q.prototype,`_asyncWorkItems`,void 0),e([y()],q.prototype,`_allTilesDirty`,void 0),e([y()],q.prototype,`_allTilesSorted`,void 0),e([y()],q.prototype,`allTilesCreated`,null),e([y()],q.prototype,`_allTilesCreated`,void 0),e([y()],q.prototype,`_viewChanged`,void 0),e([y({type:Number})],q.prototype,`heading`,void 0),e([y()],q.prototype,`_splitLimits`,void 0),e([y()],q.prototype,`_frameTask`,void 0),e([y()],q.prototype,`demResolution`,null),e([y({readOnly:!0})],q.prototype,`snapLevel`,null),e([y({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([y({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([y()],q.prototype,`_rootTilesExtent`,void 0),e([y({readOnly:!0})],q.prototype,`groundExtent`,null),e([y({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([y({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([y({readOnly:!0})],q.prototype,`updating`,null),e([y({readOnly:!0})],q.prototype,`readyToRun`,null),e([y(we)],q.prototype,`updatingProgress`,void 0),e([y({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([y()],q.prototype,`_maxNumUpdating`,void 0),e([y()],q.prototype,`baseOpacity`,null),e([y()],q.prototype,`hasCompositeBlendMode`,void 0),e([y({readOnly:!0})],q.prototype,`viewingMode`,null),e([y()],q.prototype,`maxTextureScale`,void 0),e([y({readOnly:!0})],q.prototype,`ready`,null),e([y({readOnly:!0})],q.prototype,`rootTiles`,null),e([y()],q.prototype,`_rootTiles`,void 0),e([y({readOnly:!0})],q.prototype,`spatialReference`,null),e([y({type:t})],q.prototype,`backgroundColor`,null),e([y({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([y({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([y({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([y({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([y()],q.prototype,`wireframe`,null),e([y()],q.prototype,`opaque`,null),e([y()],q.prototype,`invisible`,null),e([y({value:!1})],q.prototype,`freeze`,null),e([y()],q.prototype,`fadeDuration`,null),e([y()],q.prototype,`_xNormalizer`,null),e([y()],q.prototype,`visibleElevationRange`,void 0),e([y()],q.prototype,`_rootTileElevationRange`,void 0),e([y()],q.prototype,`_layerViewsDirty`,void 0),e([y()],q.prototype,`renderPatchBorders`,null),e([y()],q.prototype,`renderingDisabled`,null),e([y({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([re(`esri.views.3d.terrain.TerrainSurface`)],q);const lt=q,J=b(),Y=new _e,ut=w(),dt=new f,X={spatialReference:null,extent:null,scale:0};function ft(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return Ee(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&&pt(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}function pt(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<A||$(e,e=>{pt(e)})}function mt(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{lt as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as p,isAborted as m}from"../../../core/promiseUtils.js";import{watch as h,syncAndInitial as g,initial as _,sync as v}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as ne}from"../../../core/units.js";import{property as y,subclass as re}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ie,set as ae,copy as oe}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as se}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ce,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as ue}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{getProjector as de}from"../../../geometry/projection/projectors.js";import{projectPointToVector as S}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as fe}from"../../../geometry/projection/projectVectorToVector.js";import{create as C,fromExtent as pe,equals as w,intersection as me,intersectsSphere as T}from"../../../geometry/support/aaBoundingRect.js";import{copy as he,create as ge}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as _e}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as ve}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as ye}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as be}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as xe,isBaseLayer as Se}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ce}from"../../../request/queue.js";import{debugFlags as E}from"../support/debugFlags.js";import{ElevationRange as D}from"../support/ElevationRange.js";import{ElevationUpdateEvent as we}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Te}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as Ee}from"../support/extentUtils.js";import{updatingProgress as De}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Oe,sampleElevation as ke}from"./ElevationData.js";import{create as Ae}from"./ExtentHelper.js";import{LayerClasses as je}from"./LayerClass.js";import{OverlayManager as Me}from"./OverlayManager.js";import{PlanarPatch as Ne}from"./PlanarPatch.js";import{Queue as Pe}from"./Queue.js";import{ScaleRangeQueries as Fe}from"./ScaleRangeQueries.js";import{SphericalPatch as Ie}from"./SphericalPatch.js";import{SplitLimits as Le}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as Re,tooManyRootTilesForLayerError as ze,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Be}from"./TerrainConst.js";import{TerrainRenderer as Ve}from"./TerrainRenderer.js";import He from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Ue,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as We,enableTerrainInternalChecks as V,enableWaterproofTests as Ge,enableInternalTerrainChecks as Ke,enableTerrainWaterproofChecks as qe,neighborCornerIndices as Je}from"./terrainUtils.js";import{Tile as Ye,lijEquals as H}from"./Tile.js";import{printAllocations as Xe}from"./TilePerLayerInfo.js";import{sortTiles as Ze,IteratorPreorder as Qe,IteratorPostorder as $e,compareTilesByLij as U,hasLoadableSiblings as et,sortTilesByPOI as tt,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as nt}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as rt}from"./TransparencyMode.js";import{UpsampleInfo as it}from"./UpsampleInfo.js";import{isCompositeBlendMode as at,blendModeFromString as ot}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as st}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as ct,noBudget as lt}from"../../support/Scheduler.js";import{TextureCompressionTracker as ut}from"../../support/TextureCompressionTracker.js";import{Yield as dt}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ze(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=ne(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new ut,this._iteratorPool=new d(()=>new Qe,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new $e,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new He,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=b(),this._eyePosSurfaceSR=b(),this._splitLimits=new Le,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new se,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new it),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=C(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new D(1/0,-1/0),this._rootTileElevationRange=new D(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new Me({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?Ie:Ne,this._ellipsoid=ce(t.spatialReference),this._renderer=new Ve(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),st()||(this._scaleRangeQueries=new Fe)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new be(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([h(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),h(()=>this.renderer.visible,e=>this.freeze=!e),h(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},g)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},_),this.addHandles([h(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},g),h(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),g),h(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},v),h(()=>this.snapLevel,()=>this._viewChanged=!0,v),h(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ie}))}),h(()=>E.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&E.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},_)]);let{spatialReference:a}=e;this._extentHelper=Ae(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new nt({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(ct.TERRAIN_SURFACE,this),this.addHandles([h(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),_),h(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),v),h(()=>this.groundExtent,()=>this._updateRootTiles(),_),e.on(`resize`,()=>this._viewChangeUpdate()),h(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),g),h(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,_),h(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,_),h(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),h(()=>this.userClippingExtent,()=>this._updateClippingExtent(),v)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),Ye.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),Xe(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return!!this._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!xe(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:ue(i,i.spatialReference,e);return a?pe(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=C(),r=Ee(t,n,e)?n:null,i=this._get(`userClippingExtent`);return w(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=me(this.fullGroundExtent,this.userClippingExtent,C()),t=this._get(`groundExtent`);return w(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._hasElevationSourceUpdates||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.freeze}get _hasElevationSourceUpdates(){return this._allTiles.some(e=>e.needsElevationSourceUpdate())}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||this._rootTiles!=null}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set(`slicePlaneEnabled`,e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return _e(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=de(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=ae(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return ht(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=ht(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!S(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}_ensureProjector(e){let t=this._projectorCache.get(e);if(t)return t;let n=de(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,n),n}getSphereElevationRange(e,t){if(!this.enabled||this._rootTiles==null)return null;let n=this._ensureProjector(t);if(n==null)return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system`),null;Y.copyFrom(e),n(Y.center,0,Y.center,0);let r=new D,i=this._rootTiles;if(i!=null){let e=[];for(let t of i)e.push(t);let t=0;for(;t<e.length;){let n=e[t];if(++t,!T(n.extent,Y))continue;let i=n.children;if(i[0]==null||n.rendered)r.expandElevationRangeValues(n.elevationBoundsMin,n.elevationBoundsMax);else for(let t of i)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new D(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!S(e,Y.center,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system`),null;Y.radius=t;let n=null,r=e=>{if(e&&T(e.extent,Y)){let t=e.children;if(t[0]&&!e.rendered)for(let e of t)r(e);else{let t=this._getLodBiasCorrectedScale(e.level);n=n==null?t:Math.min(n,t)}}},i=this._rootTiles;if(i!=null)for(let e of i)r(e);return n}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?rt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&ve(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=pt,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(Re);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(ze),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));w(n,this._rootTilesExtent)||(this._rootTilesExtent=C(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),e!=null){let t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.freeze&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(e==null)return;let t=et(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=he(this._splitLimits.frustum??ge(),t.frustum):this._splitLimits.frustum=null,oe(this._eyePosRenderSR,t.eye),fe(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();let t=this._renderer.updateTileGeometryState(e);e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate()),t&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(M),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.resetPendingUpdate(32)?32:e.resetPendingUpdate(16)?16:!1;n&&(this._renderer.updateTileTexture(e,n),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Te(t,this.spatialReference)){let t=new we(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateElevationSources(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let n=this._pendingTilesToUpdate.size>0,r=n&&this._hasPendingGeometryWithoutIndices();if((!e.done||r)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||n&&!r)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!e.hasProgressed)return dt}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Pe(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=s?4:e.shouldSplit(i,a,r),l=c===1;e.leaf?Z(e,l):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):l?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),c===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(tt(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=Je[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(We(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Ue(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&Ge&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}_updateElevationSources(e){e.done||this._allTiles.some(t=>(t.needsElevationSourceUpdate()&&(t.updateAgents(0),t.markElevationSourceUpdateRequested(),e.madeProgress()),e.done))}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*Be}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange(`ready`)),this._allTiles.clear(),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){let t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?_t(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._tileMemcacheKey,e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),_t(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(e.rendered,`parent should be rendered`),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=lt){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(let e of this.view.allLayerViews.items)if(L(e)&&!Se(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&at(ot[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(h(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(h(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(h(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(h(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of je){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),p(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!m(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{p(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ce,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Oe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),m(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(this._usedMemory??=this._recalculateUsedMemory(),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(e=`render-patch-groups`){}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ke(e)}enableWaterproofnessChecks(e){qe(e)}static cleanupTerrainSurface(){mt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([y()],q.prototype,`_renderer`,void 0),e([y({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([y({constructOnly:!0})],q.prototype,`view`,void 0),e([y({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([y()],q.prototype,`_hasPendingUpdates`,void 0),e([y()],q.prototype,`_asyncWorkItems`,void 0),e([y()],q.prototype,`_allTilesDirty`,void 0),e([y()],q.prototype,`_allTilesSorted`,void 0),e([y()],q.prototype,`allTilesCreated`,null),e([y()],q.prototype,`_allTilesCreated`,void 0),e([y()],q.prototype,`_viewChanged`,void 0),e([y({type:Number})],q.prototype,`heading`,void 0),e([y()],q.prototype,`_splitLimits`,void 0),e([y()],q.prototype,`_frameTask`,void 0),e([y()],q.prototype,`demResolution`,null),e([y({readOnly:!0})],q.prototype,`snapLevel`,null),e([y({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([y()],q.prototype,`_stencilEnabledExtents`,null),e([y({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([y()],q.prototype,`_rootTilesExtent`,void 0),e([y({readOnly:!0})],q.prototype,`groundExtent`,null),e([y({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([y({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([y({readOnly:!0})],q.prototype,`updating`,null),e([y({readOnly:!0})],q.prototype,`readyToRun`,null),e([y(De)],q.prototype,`updatingProgress`,void 0),e([y({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([y()],q.prototype,`_maxNumUpdating`,void 0),e([y()],q.prototype,`baseOpacity`,null),e([y()],q.prototype,`hasCompositeBlendMode`,void 0),e([y({readOnly:!0})],q.prototype,`viewingMode`,null),e([y()],q.prototype,`maxTextureScale`,void 0),e([y({readOnly:!0})],q.prototype,`ready`,null),e([y({readOnly:!0})],q.prototype,`rootTiles`,null),e([y()],q.prototype,`_rootTiles`,void 0),e([y({readOnly:!0})],q.prototype,`spatialReference`,null),e([y({type:t})],q.prototype,`backgroundColor`,null),e([y({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([y({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([y({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([y({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([y()],q.prototype,`wireframe`,null),e([y()],q.prototype,`opaque`,null),e([y()],q.prototype,`invisible`,null),e([y({value:!1})],q.prototype,`freeze`,null),e([y()],q.prototype,`fadeDuration`,null),e([y()],q.prototype,`_xNormalizer`,null),e([y()],q.prototype,`visibleElevationRange`,void 0),e([y()],q.prototype,`_rootTileElevationRange`,void 0),e([y()],q.prototype,`_layerViewsDirty`,void 0),e([y()],q.prototype,`renderPatchBorders`,null),e([y()],q.prototype,`renderingDisabled`,null),e([y({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([re(`esri.views.3d.terrain.TerrainSurface`)],q);const ft=q,J=b(),Y=new ye,pt=C(),mt=new f,X={spatialReference:null,extent:null,scale:0};function ht(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return ke(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&>(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}function gt(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<A||$(e,e=>{gt(e)})}function _t(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{ft as default};
|