@arcgis/core 6.0.0-next.58 → 6.0.0-next.59
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/Graphic.d.ts +1 -0
- package/applications/SceneViewer/sceneViewerUtils.d.ts +74 -0
- package/applications/SceneViewer/sceneViewerUtils.js +1 -1
- package/arcgisGlobal.d.ts +2 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{5e4de4ddd3bdc74100e0.js → 75667b1427a7f02f2cda.js} +1 -1
- package/assets/esri/core/workers/chunks/{b4018b21a03c0c909d23.js → 75a48b122254deb3ad59.js} +1 -1
- package/assets/esri/core/workers/chunks/{690041373d03d02a3044.js → 956810d6f553c2198aae.js} +1 -1
- package/assets/esri/core/workers/chunks/a27c2edd7e043643cdd1.js +1 -0
- package/assets/esri/core/workers/chunks/bd8ee0205f0a01d6d4d7.js +1 -0
- package/assets/esri/core/workers/chunks/{423c7a981b9a06b76cbd.js → d833fc1fe63c9917ae3e.js} +1 -1
- package/assets/esri/core/workers/chunks/{32d5aae2e0953420216a.js → dca6abf260c0bfb7c9c0.js} +1 -1
- package/assets/esri/core/workers/chunks/{fc8cb947a677aa12348d.js → e38ffdb19132529beda7.js} +1 -1
- package/chunks/BlurEmission.glsl.js +6 -6
- package/chunks/EmissionComposite.glsl.js +2 -2
- package/chunks/Fog.glsl.js +4 -4
- package/chunks/RibbonLine.glsl.js +154 -108
- package/config.js +1 -1
- package/core/urlUtils.js +1 -1
- package/interfaces.d.ts +8 -0
- package/kernel.js +1 -1
- package/layers/graphics/sources/CSVSource.js +1 -1
- package/layers/graphics/sources/GeoJSONSource.js +1 -1
- package/layers/raster/formats/tiffParser.js +1 -1
- package/package.json +2 -2
- package/popup/FeatureModel.js +1 -1
- package/popup/FeaturesModel.js +1 -1
- package/rest/support/AttributeBinsQuery.d.ts +41 -1
- package/rest/support/AttributeBinsQuery.js +1 -1
- package/rest/support/Query.d.ts +1 -2
- package/rest/versionManagement/gdbVersion/post.js +1 -1
- package/rest/versionManagement/gdbVersion/reconcile.js +1 -1
- package/rest/versionManagement/gdbVersion/serverVersionUtils.js +1 -1
- package/rest/versionManagement/gdbVersion/support/PostResult.d.ts +1 -1
- package/rest/versionManagement/gdbVersion/support/ReconcileResult.d.ts +1 -1
- package/smartMapping/statistics/histogram.js +1 -1
- package/smartMapping/statistics/types.d.ts +18 -0
- package/smartMapping/support/adapters/FeatureLayerAdapter.js +1 -1
- package/smartMapping/support/adapters/support/histogramUtils.js +1 -1
- package/symbols/LineSymbol3DLayer.js +1 -1
- package/tables/support/templateUtils.js +1 -1
- package/versionManagement/VersionManagementService.d.ts +47 -1
- package/versionManagement/VersionManagementService.js +1 -1
- package/versionManagement/support/PostJobInfo.d.ts +61 -0
- package/versionManagement/support/PostJobInfo.js +2 -0
- package/versionManagement/support/ReconcileJobInfo.d.ts +61 -0
- package/versionManagement/support/ReconcileJobInfo.js +2 -0
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/terrain/PatchGeometry.js +1 -1
- package/views/3d/terrain/PatchGeometryFactory.js +1 -1
- package/views/3d/terrain/TerrainRenderer.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/attributes/RibbonVertexPosition.glsl.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/shading/LineStipple.glsl.js +21 -12
- package/views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/fog/Fog.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/glow/BlurEmission.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/glow/applyEmissiveGlow.glsl.js +20 -15
- package/views/3d/webgl-engine/lib/EmissionComposite.glsl.js +1 -1
- package/views/3d/webgl-engine/lib/TriangleRangeBVH.js +1 -1
- package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLine.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLineTechnique.js +1 -1
- package/views/Attribution.js +2 -2
- package/views/DOMContainer.d.ts +3 -2
- package/views/DOMContainer.js +1 -1
- package/views/SceneView.js +1 -1
- package/views/View.d.ts +2 -2
- package/views/View.js +1 -1
- package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/294097140e349e073b7e.js +0 -1
- package/assets/esri/core/workers/chunks/6a202ef9ba9b89e09153.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import{property as t,subclass as n}from"../../../core/accessorSupport/decorators.js";import{unique as r}from"../../../core/arrayUtils.js";import{EventEmitter as i}from"../../../core/Evented.js";import"../../../core/has.js";import{ortho as a,fromTranslation as o}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{set as s}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ones as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{someMap as l,everyMap as u}from"../../../core/MapUtils.js";import{disposeMaybe as d}from"../../../core/maybe.js";import f from"../../../core/PooledArray.js";import{watch as p,syncAndInitial as m,on as h,initial as g}from"../../../core/reactiveUtils.js";import{someSet as _}from"../../../core/SetUtils.js";import{TaskPriority as v}from"../../support/Scheduler.js";import{Texture as y}from"../../webgl/Texture.js";import{TextureDescriptor as b}from"../../webgl/TextureDescriptor.js";import{debugFlags as x}from"../support/debugFlags.js";import{renderHighlightBuffer as S}from"../webgl-engine/effects/highlight/Highlight.js";import{SyncRenderPlugin as C}from"../webgl-engine/effects/RenderPlugin.js";import{GLMaterialRepository as w}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as T}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as E,defaultRenderOccludedMask as D}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as O}from"../webgl-engine/lib/ShadowMap.js";import{T as k}from"../../../chunks/Texture.glsl.js";import{TextureTechnique as A}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as j}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as M}from"../webgl-engine/lighting/Lightsources.js";import{O as N}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as P}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import F from"../webgl/RenderCamera.js";import{Overlay as I}from"./Overlay.js";import{OverlayRenderTargets as L}from"./OverlayRenderTargets.js";let R=class extends C{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new N,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new f,this._passParameters=new k,this._screenToMapUnitsRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new F,this.events=new i,this.longitudeCyclical=null,this.produces=new Map([[18,e=>e!==10||this.hasHighlights],[19,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1;let{state:t,stage:n}=e.parent.view,r=n.renderer.fboCache,a=n.renderView.renderingContext,o=n.renderView.techniques;this._renderContext=new E(a,new O(r,t.isGlobal),o)}initialize(){let e=this._view,t=e.stage.renderView.waterTextures;this.addHandles([p(()=>t.updating,()=>this.events.emit(`content-changed`),m),p(()=>this._spatialReference,e=>this._localOriginFactory=new T(e),m),h(()=>e.allLayerViews,`after-changes`,()=>this._sortedDrapeSourceRenderersDirty=!0),p(()=>this._highlightsString,()=>this._sortedDrapeSourceRenderersDirty=!0,g),p(()=>e.state.highlights,e=>this._bindParameters.highlights=e,g),e.resourceController.scheduler.registerTask(v.OVERLAY_RENDERER,this)]);let n=this._camera;n.near=1,n.far=1e4,n.relativeElevation=null,this._bindParameters.slot=18,this._bindParameters.camera=n,this._bindParameters.updateLighting(new M(c()),0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=d(this._passParameters.texture),this.disposeOverlays(),this._renderContext.destroy(),this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToMapUnitsRatio(){return this._screenToMapUnitsRatio}get mapUnitsToGroundRatio(){return this.parent.mapUnitsToPlanarDistanceRatio*this._bindParameters.planarDistanceToGroundRatio}get localOriginFactory(){return this._localOriginFactory}set overlayStretch(e){this._bindParameters.overlayStretch=e}get overlayStretch(){return this._bindParameters.overlayStretch}get _highlightsString(){return JSON.stringify(this._view.state.highlights.reduce((e,t)=>e+`:`+JSON.stringify(t.toJSON()),``))}set time(e){this._renderContext.time=e}get pluginContext(){return this._pluginContext}initializeRenderContext(e){let t=new w(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit(`content-changed`),this.notifyChange(`updating`),this.notifyChange(`isEmpty`)},()=>this.events.emit(`content-changed`));this._pluginContext={...e,materials:t},this._techniques.precompile(P)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||l(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return this._overlays!=null&&this._renderTargets!=null}getMaterialRenderer(e){for(let t of this._renderers.values()){let n=t.getMaterialRenderer(e);if(n)return n}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),r(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,t){this._renderers.get(e)?.destroy(),this._renderers.set(e,t),this._sortedDrapeSourceRenderersDirty=!0,`fullOpacity`in e&&this.addHandles(p(()=>e.fullOpacity,()=>this.events.emit(`content-changed`)),e)}removeDrapeSourceRenderer(e){if(e==null)return;let t=this._renderers.get(e);t!=null&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),t.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=this._overlays?_(e,e=>e.drapeTargetType===1):!1}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=_(e,e=>e.drapeSourceType===1),this._hasDrapedRasterSource=_(e,e=>e.drapeSourceType===0),this._hasDrapedFlowSource=_(e,e=>e.drapeSourceType===2)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,t){this._overlays??=(this._renderTargets=new L(this._stage.renderer.fboCache),[new I,new I]),this.ensureDrapeTargets(e),this.ensureDrapeSources(t)}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit(`textures-disposed`)}_useOverlayColorInsteadOfColorNoRasterImage(e){return e===1&&!this._needsColorWithoutRasterImage&&this._hasDrapedFeatureSource}getTexture(e){let t=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(t?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(()=>!0,e)}_onMaterialOrContentChanged(){this.renderOccludedFlags=l(this._renderers,e=>e.hasOccluders)?V:1}_processDrapeSources(e,t){let n=!1;for(let[r,i]of this._renderers){if(t?.done)break;(r.destroyed||e(r))&&i.commitChanges()&&(n=!0,t?.madeProgress())}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,n=!0,this._updateSortedDrapeSourceRenderers(),t?.madeProgress()),t&&this.compact(t),n&&(this._overlays!=null&&this._renderers.size===0&&this.disposeOverlays(),this.notifyChange(`updating`),this.notifyChange(`isEmpty`),this._onMaterialOrContentChanged(),this.hasHighlights=l(this._renderers,e=>e.hasHighlights),this.events.emit(`content-changed`))}compact(e){let t=!1;for(let n of this._renderers.values()){if(e.done)break;t=n.compact(e)||t}return t&&this.notifyChange(`updating`),t}hasHighlight(e){return l(this._renderers,t=>t.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(e=>e.updatePolicy===1)}get isEmpty(){return!x.OVERLAY_DRAW_DEBUG_TEXTURE&&u(this._renderers,e=>e.isEmpty)}get hasWater(){let e=l(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit(`has-water`)),this._hasWater}renders(e){if(x.OVERLAY_DRAW_DEBUG_TEXTURE&&e!==4&&e!==2)return!0;if(!this._overlays)return!1;let t=this._overlays[0];for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);if(!t.hasSomeSizedView())return!1;let n=this._setOutput(this._renderTargets?.targets.find(t=>t.content===e)?.output??0),r=this._bindParameters,i=r.highlightMixTexture;r.output===10&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null),++this._techniques.precompiling;let a=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,r.highlightMixTexture=i,this._setOutput(n),a}_setOutput(e){let t=this._bindParameters.output;return this._bindParameters.output=e,this._bindParameters.slot=e===4?19:18,t}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:+!!this._renderTargets?.getTexture(0)}updateAnimation(e){let t=!1;return this._renderers.forEach(n=>t=n.updateAnimation(e)||t),t&&this.parent.requestRender(0),t}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;let t=this._bindParameters;t.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(let e of this._renderTargets.targets){if(e.content===1&&!this._needsColorWithoutRasterImage)continue;let{output:n}=e;this._setOutput(n),n===10&&(t.highlightMixTexture=t.highlights.length>1?this._rctx.emptyTexture:null);let r=this._renderContext.renderOccludedMask;e.content===4&&(this._renderContext.renderOccludedMask=V),this._sortedRenderers.forAll(({drapeSource:t,renderer:n})=>{e.content===1&&t.drapeSourceType===0||e.content===4&&n.hasOnlyOccluders||n.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=r,t.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,t){if(!this._overlays||!this._renderTargets)return;for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;let n=this.allSourcesOccluders;for(let e of this._renderTargets.targets){if(!(e.content===0&&this._hasDrapedFlowSource)&&!e.handleRenderRequest(t)||e.content===1&&!this._needsColorWithoutRasterImage||e.content===4&&n)continue;let r=this._drawTarget(0,e),i=this._drawTarget(1,e);(r||i)&&e.fbo.generateMipMap()}}_drawTarget(e,t){let n=this._overlays[e],r=n.canvasGeometries;if(r.numViews===0)return!1;let i=this._view.state.contentPixelRatio;this._screenToMapUnitsRatio=i*n.mapUnitsPerPixel/this._bindParameters.overlayStretch;let{output:a,content:o}=t;if(this.isEmpty||a===4&&!this.hasWater||!n.hasSomeSizedView())return!1;let{_rctx:s,_camera:c,_renderContext:l,_bindParameters:u}=this;if(c.pixelRatio=n.pixelRatio*i,this._setOutput(a),u.screenToMapUnitsRatio=this._screenToMapUnitsRatio,u.screenToPlanarDistanceRatio=this._screenToMapUnitsRatio*this.parent.mapUnitsToPlanarDistanceRatio,o===4&&(l.renderOccludedMask=V),!this.renders(o))return l.renderOccludedMask=D,!1;let{resolution:d}=n,f=e===0,p=f?0:d;if(s.setViewport(p,0,d,d),this._bindTargetFBO(t),f&&(a===10?s.gl.clearBufferuiv(s.gl.COLOR,0,[0,0,0,0]):(s.setClearColor(0,0,0,0),s.clear(16384))),x.OVERLAY_DRAW_DEBUG_TEXTURE&&o!==4&&o!==2){this._techniques.precompile(A,H);let t=this._techniques.get(A,H);for(let i=0;i<r.numViews;i++)this._setViewParameters(r.extents[i],n),this._ensureDebugPatternResources(n.resolution,B[e]),s.bindTechnique(t,u,this._passParameters),s.screen.draw()}if(a===10){let{fboCache:n}=this._stage.renderer,r=this._resolution;this._bindTargetFBO(t),S(s,n,r,r,u,()=>this._renderAllGeometry(e,t),p)}else this._renderAllGeometry(e,t);return s.bindFramebuffer(null),l.renderOccludedMask=D,!0}get allSourcesOccluders(){return u(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,t){let n=this._overlays[e],r=n.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:a})=>{if(t.content===1&&i.drapeSourceType===0)return;let{fullOpacity:o}=i,s=o!=null&&o<1&&t.output===0&&this._bindTemporaryFBO();for(let e=0;e<r.numViews;e++)this._setViewParameters(r.extents[e],n),a.render(this._renderContext);if(s){this._bindTargetFBO(t),this._overlayParameters.texture=s.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;let n=this._techniques.get(P);this._rctx.bindTechnique(n,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),s.release()}})}_bindTargetFBO(e){let t=this._resolution,n=2*t;e.fbo.ensureFramebuffer(n,t),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){let e=this._resolution,t=2*e,n=this._stage.renderer.fboCache,r=n.acquire(t,e,`overlay tmp`);return n.rctx.bindFramebuffer(r.fbo),n.rctx.clear(16384),r}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit(`content-changed`)}intersectRay(e,t,n,r){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(let{renderer:a}of this._sortedRenderers)i=a.intersectRay?.(e,t,n,r,i)??i}*intersectScreenPolygon(e,t,n){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let r=0;for(let{renderer:i}of this._sortedRenderers)r=yield*i.intersectScreenPolygon(e,t,n,r)}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),this._renderers.size===0)return;let e=this._view.map.allLayers.map(e=>e.uid),t=Math.max(1,e.length);this._renderers.forEach((n,r)=>{let i=e.indexOf(r.layer?.uid),a=i>=0,o=r.renderGroup??+!a,s=r.drapeSourcePriorityOffset??0,c=t*o+(a?i:0)+s;this._sortedRenderers.push(new z(r,n,c))}),this._sortedRenderers.sort((e,t)=>e.index-t.index)}_setViewParameters(e,t){let n=this._camera;n.viewport=[0,0,t.resolution,t.resolution],this._bindParameters.planarDistanceToGroundRatio=this.parent.getPlanarDistanceToGroundRatio((e[1]+e[3])*.5),a(n.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],n.near,n.far),o(n.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,t){if(s(this._passParameters.color,t[0],t[1],t[2]),this._passParameters.texture)return;let n=new Uint8Array(e*e*4),r=0;for(let t=0;t<e;t++)for(let i=0;i<e;i++){let a=Math.floor(i/10),o=Math.floor(t/10);a<2||o<2||a*10>e-20||o*10>e-20?(n[r++]=255,n[r++]=255,n[r++]=255,n[r++]=255):(n[r++]=255,n[r++]=255,n[r++]=255,a&1&&o&1?n[r++]=i&1^t&1?0:255:n[r++]=a&1^o&1?0:128)}let i=new b(e);i.samplingMode=9728,this._passParameters.texture=new y(this._rctx,i,n)}get test(){}};e([t()],R.prototype,`hasHighlights`,void 0),e([t()],R.prototype,`renderOccludedFlags`,void 0),e([t()],R.prototype,`_sortedDrapeSourceRenderersDirty`,void 0),e([t({constructOnly:!0})],R.prototype,`parent`,void 0),e([t({readOnly:!0})],R.prototype,`_techniques`,null),e([t()],R.prototype,`_highlightsString`,null),e([t({type:Boolean,readOnly:!0})],R.prototype,`updating`,null),e([t()],R.prototype,`isEmpty`,null),R=e([n(`esri.views.3d.terrain.OverlayRenderer`)],R);class z{constructor(e,t,n){this.drapeSource=e,this.renderer=t,this.index=n}}const B=[[1,.5,.5],[.5,.5,1]],V=4,H=new j;H.hasAlpha=!0;export{R as OverlayRenderer,V as overlayRenderOccludedFlag};
|
|
2
|
+
import{__decorate as e}from"tslib";import{property as t,subclass as n}from"../../../core/accessorSupport/decorators.js";import{unique as r}from"../../../core/arrayUtils.js";import{EventEmitter as i}from"../../../core/Evented.js";import"../../../core/has.js";import{ortho as a,fromTranslation as o}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{set as s}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ones as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{someMap as l,everyMap as u}from"../../../core/MapUtils.js";import{disposeMaybe as d}from"../../../core/maybe.js";import f from"../../../core/PooledArray.js";import{watch as p,syncAndInitial as m,on as h,initial as g}from"../../../core/reactiveUtils.js";import{someSet as _}from"../../../core/SetUtils.js";import{TaskPriority as v}from"../../support/Scheduler.js";import{Texture as y}from"../../webgl/Texture.js";import{TextureDescriptor as b}from"../../webgl/TextureDescriptor.js";import{debugFlags as x}from"../support/debugFlags.js";import{renderHighlightBuffer as S}from"../webgl-engine/effects/highlight/Highlight.js";import{SyncRenderPlugin as C}from"../webgl-engine/effects/RenderPlugin.js";import{GLMaterialRepository as w}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as T}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as E,defaultRenderOccludedMask as D}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as O}from"../webgl-engine/lib/ShadowMap.js";import{T as k}from"../../../chunks/Texture.glsl.js";import{TextureTechnique as A}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as j}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as M}from"../webgl-engine/lighting/Lightsources.js";import{O as N}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as P}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import F from"../webgl/RenderCamera.js";import{Overlay as I}from"./Overlay.js";import{OverlayRenderTargets as L}from"./OverlayRenderTargets.js";let R=class extends C{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new N,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new f,this._passParameters=new k,this._screenToMapUnitsRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new F,this.events=new i,this.longitudeCyclical=null,this.produces=new Map([[18,e=>e!==10||this.hasHighlights],[19,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1;let{state:t,stage:n}=e.parent.view,r=n.renderer.fboCache,a=n.renderView.renderingContext,o=n.renderView.techniques;this._renderContext=new E(a,new O(r,t.isGlobal),o)}initialize(){let e=this._view,t=e.stage.renderView.waterTextures;this.addHandles([p(()=>t.updating,()=>this.events.emit(`content-changed`),m),p(()=>this._spatialReference,e=>this._localOriginFactory=new T(e),m),h(()=>e.allLayerViews,`after-changes`,()=>this._sortedDrapeSourceRenderersDirty=!0),p(()=>this._highlightsString,()=>this._sortedDrapeSourceRenderersDirty=!0,g),p(()=>e.state.highlights,e=>this._bindParameters.highlights=e,g),e.resourceController.scheduler.registerTask(v.OVERLAY_RENDERER,this)]);let n=this._camera;n.near=1,n.far=1e4,n.relativeElevation=null,this._bindParameters.slot=18,this._bindParameters.viewCamera=this._bindParameters.camera=n,this._bindParameters.updateLighting(new M(c()),0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=d(this._passParameters.texture),this.disposeOverlays(),this._renderContext.destroy(),this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToMapUnitsRatio(){return this._screenToMapUnitsRatio}get mapUnitsToGroundRatio(){return this.parent.mapUnitsToPlanarDistanceRatio*this._bindParameters.planarDistanceToGroundRatio}get localOriginFactory(){return this._localOriginFactory}set overlayStretch(e){this._bindParameters.overlayStretch=e}get overlayStretch(){return this._bindParameters.overlayStretch}get _highlightsString(){return JSON.stringify(this._view.state.highlights.reduce((e,t)=>e+`:`+JSON.stringify(t.toJSON()),``))}set time(e){this._renderContext.time=e}get pluginContext(){return this._pluginContext}initializeRenderContext(e){let t=new w(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit(`content-changed`),this.notifyChange(`updating`),this.notifyChange(`isEmpty`)},()=>this.events.emit(`content-changed`));this._pluginContext={...e,materials:t},this._techniques.precompile(P)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||l(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return this._overlays!=null&&this._renderTargets!=null}getMaterialRenderer(e){for(let t of this._renderers.values()){let n=t.getMaterialRenderer(e);if(n)return n}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),r(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,t){this._renderers.get(e)?.destroy(),this._renderers.set(e,t),this._sortedDrapeSourceRenderersDirty=!0,`fullOpacity`in e&&this.addHandles(p(()=>e.fullOpacity,()=>this.events.emit(`content-changed`)),e)}removeDrapeSourceRenderer(e){if(e==null)return;let t=this._renderers.get(e);t!=null&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),t.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=this._overlays?_(e,e=>e.drapeTargetType===1):!1}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=_(e,e=>e.drapeSourceType===1),this._hasDrapedRasterSource=_(e,e=>e.drapeSourceType===0),this._hasDrapedFlowSource=_(e,e=>e.drapeSourceType===2)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,t){this._overlays??=(this._renderTargets=new L(this._stage.renderer.fboCache),[new I,new I]),this.ensureDrapeTargets(e),this.ensureDrapeSources(t)}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit(`textures-disposed`)}_useOverlayColorInsteadOfColorNoRasterImage(e){return e===1&&!this._needsColorWithoutRasterImage&&this._hasDrapedFeatureSource}getTexture(e){let t=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(t?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(()=>!0,e)}_onMaterialOrContentChanged(){this.renderOccludedFlags=l(this._renderers,e=>e.hasOccluders)?V:1}_processDrapeSources(e,t){let n=!1;for(let[r,i]of this._renderers){if(t?.done)break;(r.destroyed||e(r))&&i.commitChanges()&&(n=!0,t?.madeProgress())}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,n=!0,this._updateSortedDrapeSourceRenderers(),t?.madeProgress()),t&&this.compact(t),n&&(this._overlays!=null&&this._renderers.size===0&&this.disposeOverlays(),this.notifyChange(`updating`),this.notifyChange(`isEmpty`),this._onMaterialOrContentChanged(),this.hasHighlights=l(this._renderers,e=>e.hasHighlights),this.events.emit(`content-changed`))}compact(e){let t=!1;for(let n of this._renderers.values()){if(e.done)break;t=n.compact(e)||t}return t&&this.notifyChange(`updating`),t}hasHighlight(e){return l(this._renderers,t=>t.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(e=>e.updatePolicy===1)}get isEmpty(){return!x.OVERLAY_DRAW_DEBUG_TEXTURE&&u(this._renderers,e=>e.isEmpty)}get hasWater(){let e=l(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit(`has-water`)),this._hasWater}renders(e){if(x.OVERLAY_DRAW_DEBUG_TEXTURE&&e!==4&&e!==2)return!0;if(!this._overlays)return!1;let t=this._overlays[0];for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);if(!t.hasSomeSizedView())return!1;let n=this._setOutput(this._renderTargets?.targets.find(t=>t.content===e)?.output??0),r=this._bindParameters,i=r.highlightMixTexture;r.output===10&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null),++this._techniques.precompiling;let a=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,r.highlightMixTexture=i,this._setOutput(n),a}_setOutput(e){let t=this._bindParameters.output;return this._bindParameters.output=e,this._bindParameters.slot=e===4?19:18,t}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:+!!this._renderTargets?.getTexture(0)}updateAnimation(e){let t=!1;return this._renderers.forEach(n=>t=n.updateAnimation(e)||t),t&&this.parent.requestRender(0),t}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;let t=this._bindParameters;t.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(let e of this._renderTargets.targets){if(e.content===1&&!this._needsColorWithoutRasterImage)continue;let{output:n}=e;this._setOutput(n),n===10&&(t.highlightMixTexture=t.highlights.length>1?this._rctx.emptyTexture:null);let r=this._renderContext.renderOccludedMask;e.content===4&&(this._renderContext.renderOccludedMask=V),this._sortedRenderers.forAll(({drapeSource:t,renderer:n})=>{e.content===1&&t.drapeSourceType===0||e.content===4&&n.hasOnlyOccluders||n.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=r,t.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,t){if(!this._overlays||!this._renderTargets)return;for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;let n=this.allSourcesOccluders;for(let e of this._renderTargets.targets){if(!(e.content===0&&this._hasDrapedFlowSource)&&!e.handleRenderRequest(t)||e.content===1&&!this._needsColorWithoutRasterImage||e.content===4&&n)continue;let r=this._drawTarget(0,e),i=this._drawTarget(1,e);(r||i)&&e.fbo.generateMipMap()}}_drawTarget(e,t){let n=this._overlays[e],r=n.canvasGeometries;if(r.numViews===0)return!1;let i=this._view.state.contentPixelRatio;this._screenToMapUnitsRatio=i*n.mapUnitsPerPixel/this._bindParameters.overlayStretch;let{output:a,content:o}=t;if(this.isEmpty||a===4&&!this.hasWater||!n.hasSomeSizedView())return!1;let{_rctx:s,_camera:c,_renderContext:l,_bindParameters:u}=this;if(c.pixelRatio=n.pixelRatio*i,this._setOutput(a),u.screenToMapUnitsRatio=this._screenToMapUnitsRatio,u.screenToPlanarDistanceRatio=this._screenToMapUnitsRatio*this.parent.mapUnitsToPlanarDistanceRatio,o===4&&(l.renderOccludedMask=V),!this.renders(o))return l.renderOccludedMask=D,!1;let{resolution:d}=n,f=e===0,p=f?0:d;if(s.setViewport(p,0,d,d),this._bindTargetFBO(t),f&&(a===10?s.gl.clearBufferuiv(s.gl.COLOR,0,[0,0,0,0]):(s.setClearColor(0,0,0,0),s.clear(16384))),x.OVERLAY_DRAW_DEBUG_TEXTURE&&o!==4&&o!==2){this._techniques.precompile(A,H);let t=this._techniques.get(A,H);for(let i=0;i<r.numViews;i++)this._setViewParameters(r.extents[i],n),this._ensureDebugPatternResources(n.resolution,B[e]),s.bindTechnique(t,u,this._passParameters),s.screen.draw()}if(a===10){let{fboCache:n}=this._stage.renderer,r=this._resolution;this._bindTargetFBO(t),S(s,n,r,r,u,()=>this._renderAllGeometry(e,t),p)}else this._renderAllGeometry(e,t);return s.bindFramebuffer(null),l.renderOccludedMask=D,!0}get allSourcesOccluders(){return u(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,t){let n=this._overlays[e],r=n.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:a})=>{if(t.content===1&&i.drapeSourceType===0)return;let{fullOpacity:o}=i,s=o!=null&&o<1&&t.output===0&&this._bindTemporaryFBO();for(let e=0;e<r.numViews;e++)this._setViewParameters(r.extents[e],n),a.render(this._renderContext);if(s){this._bindTargetFBO(t),this._overlayParameters.texture=s.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;let n=this._techniques.get(P);this._rctx.bindTechnique(n,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),s.release()}})}_bindTargetFBO(e){let t=this._resolution,n=2*t;e.fbo.ensureFramebuffer(n,t),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){let e=this._resolution,t=2*e,n=this._stage.renderer.fboCache,r=n.acquire(t,e,`overlay tmp`);return n.rctx.bindFramebuffer(r.fbo),n.rctx.clear(16384),r}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit(`content-changed`)}intersectRay(e,t,n,r){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(let{renderer:a}of this._sortedRenderers)i=a.intersectRay?.(e,t,n,r,i)??i}*intersectScreenPolygon(e,t,n){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let r=0;for(let{renderer:i}of this._sortedRenderers)r=yield*i.intersectScreenPolygon(e,t,n,r)}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),this._renderers.size===0)return;let e=this._view.map.allLayers.map(e=>e.uid),t=Math.max(1,e.length);this._renderers.forEach((n,r)=>{let i=e.indexOf(r.layer?.uid),a=i>=0,o=r.renderGroup??+!a,s=r.drapeSourcePriorityOffset??0,c=t*o+(a?i:0)+s;this._sortedRenderers.push(new z(r,n,c))}),this._sortedRenderers.sort((e,t)=>e.index-t.index)}_setViewParameters(e,t){let n=this._camera;n.viewport=[0,0,t.resolution,t.resolution],this._bindParameters.planarDistanceToGroundRatio=this.parent.getPlanarDistanceToGroundRatio((e[1]+e[3])*.5),a(n.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],n.near,n.far),o(n.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,t){if(s(this._passParameters.color,t[0],t[1],t[2]),this._passParameters.texture)return;let n=new Uint8Array(e*e*4),r=0;for(let t=0;t<e;t++)for(let i=0;i<e;i++){let a=Math.floor(i/10),o=Math.floor(t/10);a<2||o<2||a*10>e-20||o*10>e-20?(n[r++]=255,n[r++]=255,n[r++]=255,n[r++]=255):(n[r++]=255,n[r++]=255,n[r++]=255,a&1&&o&1?n[r++]=i&1^t&1?0:255:n[r++]=a&1^o&1?0:128)}let i=new b(e);i.samplingMode=9728,this._passParameters.texture=new y(this._rctx,i,n)}get test(){}};e([t()],R.prototype,`hasHighlights`,void 0),e([t()],R.prototype,`renderOccludedFlags`,void 0),e([t()],R.prototype,`_sortedDrapeSourceRenderersDirty`,void 0),e([t({constructOnly:!0})],R.prototype,`parent`,void 0),e([t({readOnly:!0})],R.prototype,`_techniques`,null),e([t()],R.prototype,`_highlightsString`,null),e([t({type:Boolean,readOnly:!0})],R.prototype,`updating`,null),e([t()],R.prototype,`isEmpty`,null),R=e([n(`esri.views.3d.terrain.OverlayRenderer`)],R);class z{constructor(e,t,n){this.drapeSource=e,this.renderer=t,this.index=n}}const B=[[1,.5,.5],[.5,.5,1]],V=4,H=new j;H.hasAlpha=!0;export{R as OverlayRenderer,V as overlayRenderOccludedFlag};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{add as e}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{releaseMaybe as t}from"../../../core/maybe.js";import{maxUint16 as n}from"../../../core/typedArrayUtil.js";import{empty as r}from"../../../geometry/support/aaBoundingBox.js";import{decompressNormal as i,compressNormal as a}from"../webgl-engine/lib/Normals.js";import{internalAssert as o}from"./terrainUtils.js";class s{constructor(){this.indices=null,this.indexCount=0,this.edgeIndicesStartIndex=0,this.poleIndicesStartIndex=0,this.vertexAttributes=null,this.edgeVerticesStartIndex=0,this.poleVerticesStartIndex=0,this.maxEdgeVertexCount=0,this.boundingBox=r(),this.numVerticesPerSide=0,this.minu=0,this.minv=0,this.maxu=1,this.maxv=1,this.outerEdgesOffsetAndLength=[0,0,0,0,0,0,0,0]}release(){this.vertexAttributes=t(this.vertexAttributes),this.indices=null}reset(){this.indices=null,this.vertexAttributes=null,r(this.boundingBox),this.numVerticesPerSide=0}getEdgeFirstVertexIndex(e){return this.outerEdgesOffsetAndLength[e*2]}getEdgeCount(e){return this.outerEdgesOffsetAndLength[e*2+1]}getEdgeVertexIndex(e,t){return this.getEdgeAttributeIndex(e,t)}getEdgeVertexPosition(t,n,r,i){this._getEdgeVertexRaw(this.getEdgeAttributeIndex(t,i),n),e(n,n,r)}getEdgeNormal(e,t,n){let{typedBuffer:r,typedBufferStride:a}=this.vertexAttributes.normalCompressed;i(t,r,this.getEdgeAttributeIndex(e,n),a)}setEdgeNormalFromValues(e,t,n,r,i){this._setNormal(this.getEdgeAttributeIndex(e,t),n,r,i)}setEdgeVertexFromValuesRawPositionUV(e,t,n,r,i,a,o){let s=this.getEdgeAttributeIndex(e,t);this.vertexAttributes.position.setValues(s,n,r,i),this._setUV(s,a,o)}setEdgeVertexFromValuesRawPositionUVNormal(e,t,n,r,i,a,o,s,c,l){let u=this.getEdgeAttributeIndex(e,t);this.vertexAttributes.position.setValues(u,n,r,i),this._setUV(u,a,o),this._setNormal(u,s,c,l)}_getEdgeVertexRaw(e,t){this.vertexAttributes.position.getVec(e,t)}_setNormal(e,t,n,r){let{typedBuffer:i,typedBufferStride:o}=this.vertexAttributes.normalCompressed;a(i,e,t,n,r,o)}_setUV(e,t,r){this.vertexAttributes.uv0.setValues(e,Math.round(t*n),Math.round(r*n))}getEdgeAttributeIndex(e,t){return o(0<=t&&t<this.getEdgeCount(e)),this.getEdgeFirstVertexIndex(e)+t}}export{s as PatchGeometry};
|
|
2
|
+
import{add as e}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{releaseMaybe as t}from"../../../core/maybe.js";import{maxUint16 as n}from"../../../core/typedArrayUtil.js";import{empty as r}from"../../../geometry/support/aaBoundingBox.js";import{decompressNormal as i,compressNormal as a}from"../webgl-engine/lib/Normals.js";import{internalAssert as o}from"./terrainUtils.js";class s{constructor(){this.indices=null,this.indexCount=0,this.edgeIndicesStartIndex=0,this.poleIndicesStartIndex=0,this.innerTriangleOrder=null,this.vertexAttributes=null,this.edgeVerticesStartIndex=0,this.poleVerticesStartIndex=0,this.maxEdgeVertexCount=0,this.boundingBox=r(),this.numVerticesPerSide=0,this.minu=0,this.minv=0,this.maxu=1,this.maxv=1,this.outerEdgesOffsetAndLength=[0,0,0,0,0,0,0,0]}release(){this.vertexAttributes=t(this.vertexAttributes),this.indices=null,this.innerTriangleOrder=null}reset(){this.indices=null,this.innerTriangleOrder=null,this.vertexAttributes=null,r(this.boundingBox),this.numVerticesPerSide=0}getEdgeFirstVertexIndex(e){return this.outerEdgesOffsetAndLength[e*2]}getEdgeCount(e){return this.outerEdgesOffsetAndLength[e*2+1]}getEdgeVertexIndex(e,t){return this.getEdgeAttributeIndex(e,t)}getEdgeVertexPosition(t,n,r,i){this._getEdgeVertexRaw(this.getEdgeAttributeIndex(t,i),n),e(n,n,r)}getEdgeNormal(e,t,n){let{typedBuffer:r,typedBufferStride:a}=this.vertexAttributes.normalCompressed;i(t,r,this.getEdgeAttributeIndex(e,n),a)}setEdgeNormalFromValues(e,t,n,r,i){this._setNormal(this.getEdgeAttributeIndex(e,t),n,r,i)}setEdgeVertexFromValuesRawPositionUV(e,t,n,r,i,a,o){let s=this.getEdgeAttributeIndex(e,t);this.vertexAttributes.position.setValues(s,n,r,i),this._setUV(s,a,o)}setEdgeVertexFromValuesRawPositionUVNormal(e,t,n,r,i,a,o,s,c,l){let u=this.getEdgeAttributeIndex(e,t);this.vertexAttributes.position.setValues(u,n,r,i),this._setUV(u,a,o),this._setNormal(u,s,c,l)}_getEdgeVertexRaw(e,t){this.vertexAttributes.position.getVec(e,t)}_setNormal(e,t,n,r){let{typedBuffer:i,typedBufferStride:o}=this.vertexAttributes.normalCompressed;a(i,e,t,n,r,o)}_setUV(e,t,r){this.vertexAttributes.uv0.setValues(e,Math.round(t*n),Math.round(r*n))}getEdgeAttributeIndex(e,t){return o(0<=t&&t<this.getEdgeCount(e)),this.getEdgeFirstVertexIndex(e)+t}}export{s as PatchGeometry};
|
|
@@ -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{compressNormal as a}from"../webgl-engine/lib/Normals.js";import{sampleElevation as o,sampleSingleElevation as s}from"./ElevationData.js";import{PatchGeometryLUT as c}from"./PatchGeometryLUT.js";import{zeroToFour as l,neighborTileIfLoadedOrSelf as u}from"./PatchRenderData.js";import{maxPatchTesselation as d,elevationNoDataValue as f}from"./TerrainConst.js";import{internalAssert as p,enableTerrainInternalChecks as m,neighborEdgeIndices as h,almostEquals as g}from"./terrainUtils.js";import{isCornerNeighbor as _}from"./Tile.js";import{compareTilesByLij as v}from"./tileUtils.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)*De*u,_=Se(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,ne(e),O(e,Te,Ee),W(i,T,d),e.intersectionData=null}function b(e,t,r){let{tile:i,localOrigin:o,geometry:s}=e,{extent:c,ellipsoid:l}=i,{boundingBox:u,numVerticesPerSide:d,vertexAttributes:f,poleVerticesStartIndex:p}=s,m=d-1,h=o[0],g=o[1],_=o[2],v=l.radius,y=c[1],b=c[3],x=[],S=p,C=(e,t)=>{let r=t*d;xe(-h,-g,-_+e*v,u),x.push(new Q(e===1,r,e===1?0:2,S,De));let i=j(e===-1?y:b,v),o=e*Math.PI/2-i,s=(e===1?1:-1)*.99,c=v+0,{position:l,uv0:p}=f,{typedBuffer:C,typedBufferStride:w}=f.normalCompressed;for(let e=1;e<=De;++e){let t=i+e/De*o,r=Math.cos(t),d=Math.sin(t);for(let e=0;e<=m;e++){let t=e/m,i=$.sinLonLUT[e],o=$.cosLonLUT[e]*r,f=i*r,v=d,y=o*c-h,b=f*c-g,x=v*c-_;xe(y,b,x,u),l.setValues(S,y,b,x),p.setValues(S,Math.round(t*n),Math.round(s*n)),a(C,S,o,f,v,w),++S}}};return t&&C(-1,0),r&&C(1,m),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:o}=e,{numVerticesPerSide:s}=i,c=s-2,l=s-1,{vertexAttributes:u,boundingBox:d}=r,{position:f,uv0:p}=u,{typedBuffer:m,typedBufferStride:h}=u.normalCompressed,{extent:g}=n,_=n.ellipsoid.radius,v=o[0],y=o[1],b=o[2],x=f.typedBuffer,S=f.typedBufferStride,C=p.typedBuffer,E=p.typedBufferStride;w(l,g,t);let D=0,O=t.data.values;if(1<=c){let e=le[1],t=$.sinLatLUT[1],n=$.cosLatLUT[1];for(let r=1;r<=c;r++){let i=$.sinLonLUT[r],a=$.cosLonLUT[r],o=_+T(r,1,O),s=-v+o*a*n,c=-y+o*i*n,l=-b+o*t;xe(s,c,l,d);let u=(r-1)*S;x[u]=s,x[u+1]=c,x[u+2]=l;let f=(r-1)*E;C[f]=le[r],C[f+1]=e}}for(let e=1;e<=c;e++){let t=$.sinLatLUT[e],n=$.cosLatLUT[e],r=e+1,i=le[r],o=$.sinLatLUT[r],s=$.cosLatLUT[r],u=$.sinLonLUT[0],f=$.cosLonLUT[0],p=_+T(0,e,O),g=f*n*p-v,w=u*n*p-y,k=t*p-b,A=D*S,j=x[A],M=x[A+1],N=x[A+2];for(let u=1;u<=c;u++){let f=$.sinLonLUT[u],p=$.cosLonLUT[u],A=0,P=0,F=0;if(u<c){let e=(D+1)*S;A=x[e],P=x[e+1],F=x[e+2]}else{let r=$.sinLonLUT[l],i=$.cosLonLUT[l],a=_+T(l,e,O);A=i*n*a-v,P=r*n*a-y,F=t*a-b}let I=g,L=w,R=k;g=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-c)*S;H=x[e],U=x[e+1],ee=x[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=_+T(u,0,O);H=p*t*n-v,U=f*t*n-y,ee=e*n-b}let W=_+T(u,r,O),G=p*s*W-v,K=f*s*W-y,q=o*W-b;if(e<c){let e=D+c,t=e*S;x[t]=G,x[t+1]=K,x[t+2]=q,xe(G,K,q,d);let n=e*E;C[n]=le[u],C[n+1]=i}let J=H-G,Y=U-K,te=ee-q,ne=p*n,X=f*n,re=t;re*re<.999&&(ne=V*Y-B*te,X=z*te-V*J,re=B*J-z*Y),a(m,D,ne,X,re,h),++D}}}function C(e){let{tile:t}=e;if(!t.intersectsClippingArea)return;let{geometry:r,geometryState:i,localOrigin:s}=e,{numVerticesPerSide:c,samplerData:l}=i,u=c-2,d=c-1,{vertexAttributes:f,boundingBox:p}=r,{position:m,uv0:h}=f,{typedBuffer:g,typedBufferStride:_}=f.normalCompressed,{extent:v}=t,y=v[0],b=v[2],x=v[1],S=v[3],C=t.ellipsoid.radius,w=s[0],T=s[1],E=s[2],D=m.typedBuffer,O=m.typedBufferStride,k=1/d,A=0;if(1<=u){let e=k,t=x*(1-e)+S*e,r=$.sinLatLUT[1],i=$.cosLatLUT[1];for(let a=1;a<=u;a++){let s=a*k,c=y*(1-s)+b*s,u=$.sinLonLUT[a],d=$.cosLonLUT[a],f=C+o(c,t,l),m=-w+f*d*i,g=-T+f*u*i,_=-E+f*r;xe(m,g,_,p);let v=(a-1)*O;D[v]=m,D[v+1]=g,D[v+2]=_,h.setValues(a-1,Math.round(s*n),Math.round(e*n))}}for(let e=1;e<=u;e++){let t=e*k,r=x*(1-t)+S*t,i=$.sinLatLUT[e],s=$.cosLatLUT[e],c=e+1,f=c*k,m=x*(1-f)+S*f,v=$.sinLatLUT[c],j=$.cosLatLUT[c],M=$.sinLonLUT[0],N=$.cosLonLUT[0],P=C+o(y,r,l),F=N*s*P-w,I=M*s*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<=u;t++){let c=t*k,S=y*(1-c)+b*c,M=$.sinLonLUT[t],N=$.cosLonLUT[t],P=0,R=0,H=0;if(t<u){let e=(A+1)*O;P=D[e],R=D[e+1],H=D[e+2]}else{let e=$.sinLonLUT[d],t=$.cosLonLUT[d],n=C+o(b,r,l);P=t*s*n-w,R=e*s*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,J=0,Y=0,te=0;if(e>1){let e=(A-u)*O;J=D[e],Y=D[e+1],te=D[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=C+o(S,x,l);J=N*t*n-w,Y=M*t*n-T,te=e*n-E}let ne=C+o(S,m,l),X=N*j*ne-w,re=M*j*ne-T,Z=v*ne-E;if(e<u){let e=A+u,t=e*O;D[t]=X,D[t+1]=re,D[t+2]=Z,xe(X,re,Z,p),h.setValues(e,Math.round(c*n),Math.round(f*n))}let ie=J-X,ae=Y-re,oe=te-Z,Q=N*s,se=M*s,ce=i;ce*ce<.999&&(Q=q*ae-K*oe,se=G*oe-q*ie,ce=K*ie-G*ae);let le=1/Math.sqrt(Q*Q+se*se+ce*ce);a(g,A,Q*le,se*le,ce*le,_),++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,t=!1){e.tile.intersectsClippingArea&&(O(e,t?Te:e.dirtyEdges,t?Ee:e.dirtyCorners),ae(e),e.intersectionData=null)}function D(e){e.tile.intersectsClippingArea&&(X(e),O(e,Te,Ee),ae(e),oe(e),e.intersectionData=null)}function O(e,t,n){e.tile.intersectsClippingArea&&(n&&A(e,n),t&&k(e,t),(n||t)&&be(e.geometry.boundingBox))}function k(e,r){let{geometry:i,geometryState:c,tile:l,localOrigin:d}=e,{level:f,extent:_,extentInRadians:y,ellipsoid:b}=l,x=b.radius,S=y[0],C=y[2],w=y[1],T=y[3],{samplerData:E}=c,D=_[0],O=_[2],k=_[1],A=_[3],j=P(e),{boundingBox:M,vertexAttributes:N}=i,F=d[0],I=d[1],L=d[2],{position:R,uv0:z}=N,B=R.typedBuffer,V=R.typedBufferStride,H=z.typedBuffer,U=z.typedBufferStride,{typedBuffer:ee,typedBufferStride:W}=N.normalCompressed,G=E?.length===1?E[0]:null,K=(e,t,n)=>G?s(e,t,G)??0:o(e,t,E)??0;for(let d=0;d<4;++d){if(!(r&1<<d))continue;let y=d===1||d===3,b=c.edgeResolutions[d];p(t(b));let N=b+1,P=u(l,c.edgePeerNeighbors[d]);if(_e(l,P,d)&&re(e,d,P))continue;let R=P!=null;p(!R||P.level===l.level),p(!R||v(l,P)<=0);let z=P?.renderData?.geometryState;if(m){let e=l.surface;if(!P&&e&&!e.updatingRootTiles){let t=h[d],n=l.findNeighborTile(t,e=>e.loaded||e.leaf||e.level===l.level);n?n.intersectsClippingArea&&(p(!n.loaded),p(!n.leaf),p(n.level===f)):p(e?.rootTiles==null||!l.shouldHaveNeighbor(t))}}let q=d===1?_[2]:_[0],J=P?.extent,Y=J&&y?d===1?J[0]:J[2]:q,te=d===0?_[3]:_[1],ne=+(d===1),X=+(d===0),Z=d===1?C:S,ie=d===0?T:w,ae=Math.sin(Z),oe=Math.cos(Z),Q=Math.sin(ie),se=Math.cos(ie),$=z?.samplerData,ce=$?.length===1?$[0]:null,le=(e,t,n)=>ce?s(n,t,ce)??0:o(n,t,$)??0,ue=R?(e,t,n)=>(K(e,t)+le(e,t,n))*.5:K,de=i.outerEdgesOffsetAndLength[d*2+0],fe=G!=null||E!=null&&E.some(e=>e!=null),pe=ce!=null||$!=null&&$.some(e=>e!=null),me=fe||pe,he=1/b,ge=n*he,ve=ne*n,ye=X*n,be=de;p(!J||g(J[2]-J[0],_[2]-_[0])),(()=>{let e=d===1?-1:+(d===3),t=d===0?-1:+(d===2),n=(_[2]-_[0])*he,r=e*n,i=t*n,c=C-S,l=y?c*he*e:0,u=y?0:t*he,f=X,p=y?Z+l:Z,m=y?Math.sin(p):ae,h=y?Math.cos(p):oe,g=y?Z-l:Z,v=y?Math.sin(g):ae,b=y?Math.cos(g):oe,w=f+u,T=y?ie:j(w),P=y?Q:Math.sin(T),z=y?se:Math.cos(T),K=f-u,J=y?ie:j(K),ne=y?Q:Math.sin(J),re=y?se:Math.cos(J),le=0,de=0,fe=0;{let e=0*he,t=y?q:D*(1-e)+O*e,n=y?Y:t,r=y?k*(1-e)+A*e:te,i=y?Z:S*(1-e)+C*e,a=y?ae:Math.sin(i),o=y?oe:Math.cos(i),s=y?j(e):ie,c=y?Math.sin(s):Q,l=y?Math.cos(s):se,u=x+ue(t,r,n);le=o*l*u,de=a*l*u,fe=c*u}let pe=0,_e=0,Se=0;{let e=+he,t=y?q:D*(1-e)+O*e,n=y?Y:t,r=y?k*(1-e)+A*e:te,i=y?Z:S*(1-e)+C*e,a=y?ae:Math.sin(i),o=y?oe:Math.cos(i),s=y?j(e):ie,c=y?Math.sin(s):Q,l=y?Math.cos(s):se,u=x+ue(t,r,n);pe=o*l*u,_e=a*l*u,Se=c*u}for(let e=1;e<N-1;++e){let t=0,n=0,c=0;{let r=(e+1)*he,i=y?q:D*(1-r)+O*r,a=y?Y:i,o=y?k*(1-r)+A*r:te,s=y?Z:S*(1-r)+C*r,l=y?ae:Math.sin(s),u=y?oe:Math.cos(s),d=y?j(r):ie,f=y?Math.sin(d):Q,p=y?Math.cos(d):se,m=x+ue(i,o,a);t=u*p*m,n=l*p*m,c=f*m}let l=t,u=n,f=c,p=pe,g=_e,_=Se;pe=l,_e=u,Se=f;{let t=be+e,n=t*V,r=p-F,i=g-I,a=_-L;B[n]=r,B[n+1]=i,B[n+2]=a,xe(r,i,a,M);let o=Math.round(e*ge),s=t*U;H[s]=y?ve:o,H[s+1]=y?o:ye}let w=le,T=de,N=fe;le=p,de=g,fe=_;let K=p,J=g,X=_,Ce=1/Math.sqrt(K*K+J*J+X*X),we=X*Ce,Te=0,Ee=0,De=0;if(me&&we*we<.999){let t=0,n=0,a=0;{let e=d===0?-1:1;t=e*(l-w),n=e*(u-T),a=e*(f-N)}{let c=e*he,l=y?q:D*(1-c)+O*c,u=y?Y:l,f=y?k*(1-c)+A*c:te,p=y?Z:S*(1-c)+C*c,g=y?ae:Math.sin(p),_=y?oe:Math.cos(p),w=y?j(c):ie,T=y?Math.sin(w):Q,M=y?Math.cos(w):se,N=K,F=J,I=X;if(R){let e=u-r,t=f-i,n=x+(ce?s(e,t,ce)??0:o(e,t,$)??0),a=y?v:g,c=y?b:_,l=y?T:ne,d=y?M:re;N=c*d*n,F=a*d*n,I=l*n}{let e=l+r,c=f+i,u=x+(G?s(e,c,G)??0:o(e,c,E)??0),p=y?m:g,v=y?h:_,b=y?T:P,S=y?M:z,C=v*S*u,w=p*S*u,D=b*u;R||(N=2*K-C,F=2*J-w,I=2*X-D);let O=d===3?-1:1,k=O*(N-C),A=O*(F-w),j=O*(I-D);Te=a*A-n*j,Ee=t*j-a*k,De=n*k-t*A;let L=1/Math.sqrt(Te*Te+Ee*Ee+De*De);Te*=L,Ee*=L,De*=L}}}else Te=K*Ce,Ee=J*Ce,De=X*Ce;a(ee,be+e,Te,Ee,De,W)}})()}}function A(e,t){Z(e,t)}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=Se(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,ne(e),z(e,Te,Ee),W(i,[],s),e.intersectionData=null}function I(t){let r=t.tile;if(!r.intersectsClippingArea)return;let{geometry:i,geometryState:c,localOrigin:l}=t,{samplerData:u,clippingArea:d,numVerticesPerSide:f}=c,{surface:p,extent:m,ellipsoid:h}=r,{isWebMercatorOnPlateCarree:g}=p,_=d??he,v=m[0],y=m[1],b=m[2],x=m[3],S=Math.max(v,_[0]),C=Math.min(b,_[2]),w=Math.max(y,_[1]),T=Math.min(x,_[3]),E=h.radius,D=r.horizontalScale,O=f-1,k=f-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=l[0],V=l[1],H=l[2],U=I.typedBuffer,ee=I.typedBufferStride,W=0,G=e(y,w,T),K=g?(Math.PI/2-2*Math.atan(Math.exp(-G/E)))*E:G*D,q=1/O,J=e(y*(1-q)+x*q,w,T),Y=g?(Math.PI/2-2*Math.atan(Math.exp(-J/E)))*E:J*D,te=K,ne=Y,X=u?.length===1?u[0]:null,re=X?(e,t)=>s(e,t,X)??0:(e,t)=>o(e,t,u)??0;for(let t=1;t<=k;t++){let r=t/O,i=e(y*(1-r)+x*r,w,T),o=e(r,j,N),s=ne,c=(t-1)/O,l=e(y*(1-c)+x*c,w,T),u=te,d=(t+1)/O,f=e(y*(1-d)+x*d,w,T),p=g?(Math.PI/2-2*Math.atan(Math.exp(-f/E)))*E:f*D,m=e(d,j,N);te=ne,ne=p;let h=e(v,S,C),_=h*D,F=re(h,i),I=1/O,G=e(I,A,M),K=e(v*(1-G)+b*G,S,C),q=G,J=K,Y=K*D,X=re(K,i);if(t===1){let t=Y-B,r=te-V,i=X-H,a=0*ee;U[a]=t,U[a+1]=r,U[a+2]=i,xe(t,r,i,P);let s=e(I,A,M);L.setValues(W,Math.round(s*n),Math.round(o*n))}for(let r=1;r<=k;r++){let c=Y,d=X,h=(r+1)/O,g=e(h,A,M),y=e(v*(1-h)+b*h,S,C),x=J;J=y;{let e=W+1,a=e*ee;if(t===1||r===k){let c=re(y,i),l=y*D,u=s,d=c;if(t===1&&r<k){let t=l-B,r=u-V,i=d-H;U[a]=t,U[a+1]=r,U[a+2]=i,xe(t,r,i,P),L.setValues(e,Math.round(g*n),Math.round(o*n))}Y=l,X=d}else Y=U[a]+B,X=U[a+2]+H}let w=Y,T=X,E=_,j=F;_=c,F=d;let N=(W-k)*ee,I=t===1?re(x,l):U[N+2]+H,G=re(x,f);if(t<k){let e=W+k,t=e*ee,r=c-B,i=p-V,a=G-H;U[t]=r,U[t+1]=i,U[t+2]=a,xe(r,i,a,P);let o=q;q=g,L.setValues(e,Math.round(o*n),Math.round(m*n))}{let e=w-E,t=T-j,n=u-p,r=I-G,i=n*t,o=e*r,s=-n*e,c=i*i+o*o+s*s;if(c===0)a(R,W,0,0,1,z);else{let e=1/Math.sqrt(c);a(R,W,i*e,o*e,s*e,z)}}++W}}}function L(e){e.tile.intersectsClippingArea&&(X(e),z(e,Te,Ee),ae(e),oe(e),e.intersectionData=null)}function R(e,t=!1){e.tile.intersectsClippingArea&&(z(e,t?Te:e.dirtyEdges,t?Ee:e.dirtyCorners),ae(e),e.intersectionData=null)}function z(e,t,n){e.tile.intersectsClippingArea&&(n&&V(e,n),t&&B(e,t),(n||t)&&be(e.geometry.boundingBox))}function B(n,r){let{geometry:i,geometryState:a,localOrigin:c}=n,l=n.tile,{surface:d,extent:f}=l,{clippingArea:g,samplerData:_}=a,y=g??he,b=f[0],x=f[2],S=f[1],C=f[3],w=[C>y[3],x>y[2],S<y[1],b<y[0]],T=l.horizontalScale,E=ee(d.isWebMercatorOnPlateCarree,l.ellipsoid.radius,T),{minu:D,minv:O,maxu:k,maxv:A,boundingBox:j}=i,M=Math.max(b,y[0]),N=Math.min(x,y[2]),P=Math.max(S,y[1]),F=Math.min(C,y[3]),I=c[0],L=c[1],R=c[2],z=_?.length===1?_[0]:void 0,B=z?(e,t)=>s(e,t,z)??0:(e,t)=>o(e,t,_)??0;for(let c=0;c<4;++c){if(!(r&1<<c))continue;let f=c===1||c===3,g=a.edgeResolutions[c];p(t(g));let y=g+1,z=w[c],V=u(l,a.edgePeerNeighbors[c]);if(!z&&_e(l,V,c)&&re(n,c,V))continue;let H=V!=null&&!z,U=V?.renderData?.geometryState;if(m&&(p(!H||V.level===l.level),p(!H||v(l,V)<=0),l&&!V&&!d.updatingRootTiles)){let e=h[c],t=l.findNeighborTile(e,e=>e.loaded||e.leaf||e.level===l.level);d.updatingRootTiles||(t?t.intersectsClippingArea&&(p(!t.loaded),p(!t.leaf),p(t.level===l.level)):p(d?.rootTiles==null||!l.shouldHaveNeighbor(e)))}let ee=e(c===1?x:b,M,N),W=e(c===0?C:S,P,F),G=U?.samplerData,K=e(+(c===1),D,k),q=e(+(c===0),O,A),J=G?.length===1?G[0]:null,Y=(e,t)=>J?s(e,t,J)??0:o(e,t,G)??0,te=H?(e,t)=>(Y(e,t)+B(e,t))*.5:B,ne=(x-b)/g,X=f?c===1?ne:-ne:0,Z=f?0:c===0?ne:-ne,ie=-X,ae=-Z,oe=0,Q=0,se=0;{let t=0/g,n=f?ee:e(b*(1-t)+x*t,M,N),r=f?e(S*(1-t)+C*t,P,F):W,i=te(n,r);oe=n*T,Q=E(r),se=i}let $=0,ce=0,le=0;{let t=1/g,n=f?ee:e(b*(1-t)+x*t,M,N),r=f?e(S*(1-t)+C*t,P,F):W,i=te(n,r),a=n*T,o=E(r),s=i;$=a,ce=o,le=s}for(let t=1;t<y-1;++t){let n=t/g,r=$,a=ce,s=le;{let o=f?K:e(n,D,k),l=f?e(n,O,A):q,u=r-I,d=a-L,p=s-R;xe(u,d,p,j),i.setEdgeVertexFromValuesRawPositionUV(c,t,u,d,p,o,l)}{let n=(t+1)/g,r=f?ee:e(b*(1-n)+x*n,M,N),i=f?e(S*(1-n)+C*n,P,F):W,a=te(r,i);$=r*T,ce=E(i),le=a}let l=$,u=ce,d=le,p=oe,m=Q,h=se;oe=r,Q=a,se=s;let v=0,y=0,w=0;if(f){let t=u-a,i=d-s,l=m-a,f=h-s,p=e(S*(1-n)+C*n,P,F),g=ee+ie,b=p,x=g*T,E=o(g,b,_),D=x-r,O=E-s,k=c===3?-1:1;if(v=k*(-l+t)*O,y=k*D*(-f+i),w=-k*D*(-l+t),H){let e=ee+X,n=p,a=e*T,c=o(e,n,G),u=a-r,d=c-s;v=(-l+t)*(O-d),y=(D-u)*(-f+i),w=-(D-u)*(-l+t)}}else{let t=l-r,i=d-s,u=p-r,f=h-s,m=e(b*(1-n)+x*n,M,N),g=m,S=W+ae,C=o(g,S,_)-s,T=E(S)-a,D=c===2?-1:1;if(v=D*T*(-f+i),y=D*(-u+t)*C,w=-D*T*(-u+t),H){let e=m,n=W+Z,r=E(n),c=o(e,n,G)-s,l=r-a;v=(-T+l)*(-f+i),y=(-u+t)*(-C+c),w=-(-T+l)*(-u+t)}}let z=1/Math.sqrt(v*v+y*y+w*w);i.setEdgeNormalFromValues(c,t,v*z,y*z,w*z)}}}function V(e,t){Z(e,t)}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,c=r-3,u=r-3,d=2*c*u,f=4*(o+a-3),p=l.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?(J(e),Y(e,t),te(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;Ce(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;p(u===i-1);let d=n===1||n===2,f=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,p=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||p<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+f]=n,t[o+m]=b,o+=3}}e.indexCount=o}function J(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;Ce(f,p,m,m-1,o,a)?(we(t,c,n,l,u),c+=6,we(t,c,u,d,n)):(we(t,c,n,l,d),c+=6,we(t,c,d,u,l)),c+=6}}}function Y(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++)we(n,o,s,s+1,t+r),o+=6,e<i.latitudeResolution-1&&(we(n,o,s+1,t+r+1,t+r),o+=6),s+=c;s=t,c=1}}}function te(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;p(u===i-1);let d=n===1||n===2,f=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,p=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||p<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+f]=n,t[o+f+1]=n,t[o+m]=b,t[o+m+1]=b,t[o+5]=e,o+=6}}e.indexCount=o}function ne(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 X(e){ne(e),e.geometryState.wireframe?te(e.geometry):q(e.geometry)}function re(r,i,a){let{geometryState:o,geometry:s,tile:c,localOrigin:l}=r,u=i===1||i===3,d=o.edgeResolutions[i];p(t(d));let f=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);p(C.edgeResolutions[T]===O),p(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<f-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,xe(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 Z(t,r){let{geometry:i,geometryState:a,localOrigin:s}=t,{clippingArea:c,samplerData:l}=a,{minu:u,minv:d,maxu:f,maxv:m,boundingBox:h,vertexAttributes:g}=i,_=t.tile,{surface:y,ellipsoid:b,extent:x,extentInRadians:S,horizontalScale:C}=_,w=b.radius,T=0,E=0,D=0,O=()=>{let t=c,n=t!=null&&(x[3]>t[3]||x[2]>t[2]||x[1]<t[1]||x[0]<t[0]),r=ee(y.isWebMercatorOnPlateCarree,w,C);return(i,a,o)=>{let s=i===0?x[0]:x[2],c=a===0?x[1]:x[3],l=n?e(s,t[0],t[2]):s,u=n?e(c,t[1],t[3]):c,d=o;T=l*C,E=r(u),D=d}},k=(e,t,n)=>{let r=S[t===0?1:3],i=S[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},A=y.isGlobal,j=A?k:O(),M=0,N=0,F=0,I=0,L=0,R=0,z=0,B=0,V=0,H=!A&&y.isWebMercatorOnPlateCarree,U=(e,t,n,r,i)=>{let a=0,o=0,s=0;if(A){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}else{let e=t*C,i=H?(Math.PI/2-2*Math.atan(Math.exp(-n/w)))*w:n*C,c=r;a=e-T,o=i-E,s=c-D}switch(i){case 0:z+=a,B+=o,V+=s;break;case 1:I-=a,L-=o,R-=s;break;case 2:z-=a,B-=o,V-=s;break;case 3:I+=a,L+=o,R+=s}},W=c??he,G=x[0],K=x[2],q=x[1],J=x[3],Y=[J>W[3],K>W[2],q<W[1],G<W[0]],te=Math.max(G,W[0]),ne=Math.min(K,W[2]),X=Math.max(q,W[1]),re=Math.min(J,W[3]),Z=e=>Math.max(W[0],Math.min(W[2],e)),ae=e=>Math.max(W[1],Math.min(W[3],e)),oe=e=>{let t=a.cornerNeighborCornerTiles;M=0,N=0,F=1,I=0,L=0,R=0,z=0,B=0,V=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,i=0;for(let e=0;e<4;++e){let t=ge[e];t&&(r=Math.max(r,t?.renderData.geometryState.numVerticesPerSide),i=t.extent[2]-t.extent[0])}let s=i,c=r;p(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 a=se[e][0]*l,s=se[e][1]*l,c=t.extent,u=Z(c[r===0||r===1?2:0]+a),d=ae(c[r===0||r===3?3:1]+s),f=n.extent,p=Z(f[i===0||i===1?2:0]+a),m=ae(f[i===0||i===3?3:1]+s),h=t.renderData,g=n.renderData,_=o(u,d,h.geometryState.samplerData),v=o(p,m,g.geometryState.samplerData);U(h,u,d,.5*(_+v),e)}else{let a=t??n,s=t?r:i,c=a.extent,u=se[e],d=Z(c[s===0||s===1?2:0]+u[0]*l),f=ae(c[s===0||s===3?3:1]+u[1]*l),p=a.renderData,m=o(d,f,p.geometryState.samplerData);U(p,d,f,m,e)}}if(A){let e=Math.sqrt(T*T+E*E+D*D);M=T/e,N=E/e,F=D/e}if(!A||F*F<.999){let e=Math.sqrt(I*I+L*L+R*R);I/=e,L/=e,R/=e;let t=Math.sqrt(z*z+B*B+V*V);z/=t,B/=t,V/=t,M=R*B-L*V,N=I*V-R*z,F=L*z-I*B;let n=1/Math.sqrt(M*M+N*N+F*F);M*=n,N*=n,F*=n}},Q=a.cornerNeighborCornerTiles;for(let t=0;t<4;++t){if(!(r&1<<t))continue;let c=t,y=(t+1)%4,b=+(t===0||t===1),x=+(t===0||t===3),S=e(b,u,f),C=e(x,d,m),w=i.getEdgeFirstVertexIndex(c),O=i.getEdgeCount(c),k=t===0||t===3?O-1:0,A=i.getEdgeFirstVertexIndex(y),P=i.getEdgeCount(y),I=t===0||t===1?P-1:0,L=-1;for(let e=0;e<4;++e){let n=Q[t*4+e],r=Q[t*4+L];n&&(L===-1||v(r,n)>0)&&(L=e)}let R=L,z=Q[t*4+R];if(z!==_){let e=_.level-z.level,r=2**e,i=[z.lij[0]+e,z.lij[1]*r,z.lij[2]*r],o=[i[1]+r===_.lij[1],t===0&&(R===1||R===0&&z!==Q[t*4+3])||t===1&&(R===0||R===1&&z!==Q[t*4+2]),i[1]===_.lij[1]+1,t===2&&(R===3||R===2&&z!==Q[t*4+1])||t===3&&(R===2||R===3&&z!==Q[t*4+0])],c=o.reduce((e,t)=>e+ +!!t,0);p(c===1||c===2);let l=-1,u=-1,d=z.renderData;if(c===1){let e=o.findIndex(e=>e);p(0<=e&&e<=3),l=(e+2)%4;let n=a.edgeResolutions[e];u=_.getNeighborEdgeStartVertexIndex(e,z)*n+n*+(e===0&&t===0||e===1&&t===0||e===2&&t===1||e===3&&t===3)}else{p(o[1]||o[3]),l=o[1]?3:1;let e=d.geometryState.edgeResolutions[l];u=t===0||t===3?0:e}let f=d.geometry;{let e=w+k,t=A+I,r=f.getEdgeFirstVertexIndex(l)+u,i=f.vertexAttributes,a=d.localOrigin,o=i.position,c=o.typedBuffer,p=r*o.typedBufferStride,m=c[p]+a[0]-s[0],_=c[p+1]+a[1]-s[1],v=c[p+2]+a[2]-s[2];xe(m,_,v,h);let y=g.position,b=y.typedBuffer,x=e*y.typedBufferStride;b[x]=m,b[x+1]=_,b[x+2]=v;let T=t*y.typedBufferStride;b[T]=m,b[T+1]=_,b[T+2]=v;let E=g.uv0;E.setValues(e,Math.round(S*n),Math.round(C*n)),E.setValues(t,Math.round(S*n),Math.round(C*n));{let n=i.normalCompressed.typedBuffer,a=r*i.normalCompressed.typedBufferStride,o=g.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=Y[c],r=Y[y],a;if(n||r){let t=e(G*(1-b)+K*b,te,ne),n=e(q*(1-x)+J*x,X,re);a=o(t,n,l)}else a=ie(Q,t);j(b,x,a),oe(t);let u=T-s[0],d=E-s[1],f=D-s[2];xe(u,d,f,h),i.setEdgeVertexFromValuesRawPositionUVNormal(c,k,u,d,f,S,C,M,N,F),i.setEdgeVertexFromValuesRawPositionUVNormal(y,I,u,d,f,S,C,M,N,F)}}for(let e=0;e<4;++e)ge[e]=null}function ie(e,t){let n=t*4,r=l.reduce((t,r)=>Math.min(t,e[n+r]?.level??1/0),1/0);m&&(p(!e[n+0]||!e[n+2]||_(e[n+0],e[n+2],5)),p(!e[n+1]||!e[n+3]||_(e[n+1],e[n+3],7)));let i=0,a=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=o(c,l,u);a+=d,i++}}let s=i?a/i:0;return p(s!=null),s}function ae(e){let{vao:t,geometry:n}=e,{vertexAttributes:r,edgeVerticesStartIndex:i}=n,{position:a}=r,o=a.typedBuffer,s=i*a.typedBufferStride,c=(n.getEdgeFirstVertexIndex(3)+n.getEdgeCount(3))*a.typedBufferStride;t.buffer()?.setSubData(o,s,s,c)}function oe(e){let{vao:t,geometry:n}=e,{indices:r,indexCount:i,edgeIndicesStartIndex:a}=n;t.indexBuffer.setSubData(r,a,a,i)}class Q{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 c,ce=.5*f,le=new Uint16Array(d+1),ue=new Int32Array(d+1),de=new Int32Array(d+1),fe=new Int32Array(d+1),pe=new Float64Array(d+1),me=new Float64Array(d+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=v(e,t);return r>0||r===0&&n>=2}class ve{constructor(){this.vertex0Index=0,this.stride=1,this.count=0}getVertexIndex(e){return p(0<=e&&e<this.count),this.vertex0Index+this.stride*e}}const ye=[new ve,new ve,new ve,new ve];function be(e){for(let t=0;t<3;t++)e[t]=Math.min(e[t],Math.fround(e[t])),e[t+3]=Math.max(e[t+3],Math.fround(e[t+3]))}function xe(e,t,n,r){r[0]=Math.min(r[0],e),r[3]=Math.max(r[3],e),r[1]=Math.min(r[1],t),r[4]=Math.max(r[4],t),r[2]=Math.min(r[2],n),r[5]=Math.max(r[5],n)}function Se(e){let{edgeResolutions:t,numVerticesPerSide:n}=e,r=1+Math.max(...t);return Math.max(n,r)}function Ce(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 we(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 Te=15,Ee=15,De=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{compressNormal as a}from"../webgl-engine/lib/Normals.js";import{sampleElevation as o,sampleSingleElevation as s}from"./ElevationData.js";import{PatchGeometryLUT as c}from"./PatchGeometryLUT.js";import{zeroToFour as l,neighborTileIfLoadedOrSelf as u}from"./PatchRenderData.js";import{maxPatchTesselation as d,elevationNoDataValue as f}from"./TerrainConst.js";import{internalAssert as p,enableTerrainInternalChecks as m,neighborEdgeIndices as h,almostEquals as g}from"./terrainUtils.js";import{isCornerNeighbor as _}from"./Tile.js";import{compareTilesByLij as v}from"./tileUtils.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)*ke*u,_=we(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,Y(e),O(e,De,Oe),W(i,T,d),e.intersectionData=null}function b(e,t,r){let{tile:i,localOrigin:o,geometry:s}=e,{extent:c,ellipsoid:l}=i,{boundingBox:u,numVerticesPerSide:d,vertexAttributes:f,poleVerticesStartIndex:p}=s,m=d-1,h=o[0],g=o[1],_=o[2],v=l.radius,y=c[1],b=c[3],x=[],S=p,C=(e,t)=>{let r=t*d;Ce(-h,-g,-_+e*v,u),x.push(new ce(e===1,r,e===1?0:2,S,ke));let i=j(e===-1?y:b,v),o=e*Math.PI/2-i,s=(e===1?1:-1)*.99,c=v+0,{position:l,uv0:p}=f,{typedBuffer:C,typedBufferStride:w}=f.normalCompressed;for(let e=1;e<=ke;++e){let t=i+e/ke*o,r=Math.cos(t),d=Math.sin(t);for(let e=0;e<=m;e++){let t=e/m,i=$.sinLonLUT[e],o=$.cosLonLUT[e]*r,f=i*r,v=d,y=o*c-h,b=f*c-g,x=v*c-_;Ce(y,b,x,u),l.setValues(S,y,b,x),p.setValues(S,Math.round(t*n),Math.round(s*n)),a(C,S,o,f,v,w),++S}}};return t&&C(-1,0),r&&C(1,m),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:o}=e,{numVerticesPerSide:s}=i,c=s-2,l=s-1,{vertexAttributes:u,boundingBox:d}=r,{position:f,uv0:p}=u,{typedBuffer:m,typedBufferStride:h}=u.normalCompressed,{extent:g}=n,_=n.ellipsoid.radius,v=o[0],y=o[1],b=o[2],x=f.typedBuffer,S=f.typedBufferStride,C=p.typedBuffer,E=p.typedBufferStride;w(l,g,t);let D=0,O=t.data.values;if(1<=c){let e=ue[1],t=$.sinLatLUT[1],n=$.cosLatLUT[1];for(let r=1;r<=c;r++){let i=$.sinLonLUT[r],a=$.cosLonLUT[r],o=_+T(r,1,O),s=-v+o*a*n,c=-y+o*i*n,l=-b+o*t;Ce(s,c,l,d);let u=(r-1)*S;x[u]=s,x[u+1]=c,x[u+2]=l;let f=(r-1)*E;C[f]=ue[r],C[f+1]=e}}for(let e=1;e<=c;e++){let t=$.sinLatLUT[e],n=$.cosLatLUT[e],r=e+1,i=ue[r],o=$.sinLatLUT[r],s=$.cosLatLUT[r],u=$.sinLonLUT[0],f=$.cosLonLUT[0],p=_+T(0,e,O),g=f*n*p-v,w=u*n*p-y,k=t*p-b,A=D*S,j=x[A],M=x[A+1],N=x[A+2];for(let u=1;u<=c;u++){let f=$.sinLonLUT[u],p=$.cosLonLUT[u],A=0,P=0,F=0;if(u<c){let e=(D+1)*S;A=x[e],P=x[e+1],F=x[e+2]}else{let r=$.sinLonLUT[l],i=$.cosLonLUT[l],a=_+T(l,e,O);A=i*n*a-v,P=r*n*a-y,F=t*a-b}let I=g,L=w,R=k;g=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-c)*S;H=x[e],U=x[e+1],ee=x[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=_+T(u,0,O);H=p*t*n-v,U=f*t*n-y,ee=e*n-b}let W=_+T(u,r,O),G=p*s*W-v,K=f*s*W-y,q=o*W-b;if(e<c){let e=D+c,t=e*S;x[t]=G,x[t+1]=K,x[t+2]=q,Ce(G,K,q,d);let n=e*E;C[n]=ue[u],C[n+1]=i}let J=H-G,te=U-K,ne=ee-q,re=p*n,Y=f*n,X=t;X*X<.999&&(re=V*te-B*ne,Y=z*ne-V*J,X=B*J-z*te),a(m,D,re,Y,X,h),++D}}}function C(e){let{tile:t}=e;if(!t.intersectsClippingArea)return;let{geometry:r,geometryState:i,localOrigin:s}=e,{numVerticesPerSide:c,samplerData:l}=i,u=c-2,d=c-1,{vertexAttributes:f,boundingBox:p}=r,{position:m,uv0:h}=f,{typedBuffer:g,typedBufferStride:_}=f.normalCompressed,{extent:v}=t,y=v[0],b=v[2],x=v[1],S=v[3],C=t.ellipsoid.radius,w=s[0],T=s[1],E=s[2],D=m.typedBuffer,O=m.typedBufferStride,k=1/d,A=0;if(1<=u){let e=k,t=x*(1-e)+S*e,r=$.sinLatLUT[1],i=$.cosLatLUT[1];for(let a=1;a<=u;a++){let s=a*k,c=y*(1-s)+b*s,u=$.sinLonLUT[a],d=$.cosLonLUT[a],f=C+o(c,t,l),m=-w+f*d*i,g=-T+f*u*i,_=-E+f*r;Ce(m,g,_,p);let v=(a-1)*O;D[v]=m,D[v+1]=g,D[v+2]=_,h.setValues(a-1,Math.round(s*n),Math.round(e*n))}}for(let e=1;e<=u;e++){let t=e*k,r=x*(1-t)+S*t,i=$.sinLatLUT[e],s=$.cosLatLUT[e],c=e+1,f=c*k,m=x*(1-f)+S*f,v=$.sinLatLUT[c],j=$.cosLatLUT[c],M=$.sinLonLUT[0],N=$.cosLonLUT[0],P=C+o(y,r,l),F=N*s*P-w,I=M*s*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<=u;t++){let c=t*k,S=y*(1-c)+b*c,M=$.sinLonLUT[t],N=$.cosLonLUT[t],P=0,R=0,H=0;if(t<u){let e=(A+1)*O;P=D[e],R=D[e+1],H=D[e+2]}else{let e=$.sinLonLUT[d],t=$.cosLonLUT[d],n=C+o(b,r,l);P=t*s*n-w,R=e*s*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,J=0,te=0,ne=0;if(e>1){let e=(A-u)*O;J=D[e],te=D[e+1],ne=D[e+2]}else{let e=$.sinLatLUT[0],t=$.cosLatLUT[0],n=C+o(S,x,l);J=N*t*n-w,te=M*t*n-T,ne=e*n-E}let re=C+o(S,m,l),Y=N*j*re-w,X=M*j*re-T,ie=v*re-E;if(e<u){let e=A+u,t=e*O;D[t]=Y,D[t+1]=X,D[t+2]=ie,Ce(Y,X,ie,p),h.setValues(e,Math.round(c*n),Math.round(f*n))}let ae=J-Y,oe=te-X,se=ne-ie,Z=N*s,ce=M*s,Q=i;Q*Q<.999&&(Z=q*oe-K*se,ce=G*se-q*ae,Q=K*ae-G*oe);let le=1/Math.sqrt(Z*Z+ce*ce+Q*Q);a(g,A,Z*le,ce*le,Q*le,_),++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);fe[r]=g,he[r]=i-g;let _=e(d*(p-(s*(1-t)+c*t)),0,m),v=Math.floor(_);pe[r]=v*h,me[r]=(v+1)*h,ge[r]=_-v,ue[r]=Math.round(t*n)}}function T(e,t,n){let r=fe[e],i=he[e],a=pe[t],o=me[t],s=ge[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>=le)return 0;let p=l+(u-l)*i;return p+(d+(f-d)*i-p)*s}function E(e,t=!1){e.tile.intersectsClippingArea&&(O(e,t?De:e.dirtyEdges,t?Oe:e.dirtyCorners),se(e),e.intersectionData=null)}function D(e){e.tile.intersectsClippingArea&&(X(e),O(e,De,Oe),se(e),Z(e),e.intersectionData=null)}function O(e,t,n){e.tile.intersectsClippingArea&&(n&&A(e,n),t&&k(e,t),(n||t)&&Se(e.geometry.boundingBox))}function k(e,r){let{geometry:i,geometryState:c,tile:l,localOrigin:d}=e,{level:f,extent:_,extentInRadians:y,ellipsoid:b}=l,x=b.radius,S=y[0],C=y[2],w=y[1],T=y[3],{samplerData:E}=c,D=_[0],O=_[2],k=_[1],A=_[3],j=P(e),{boundingBox:M,vertexAttributes:N}=i,F=d[0],I=d[1],L=d[2],{position:R,uv0:z}=N,B=R.typedBuffer,V=R.typedBufferStride,H=z.typedBuffer,U=z.typedBufferStride,{typedBuffer:ee,typedBufferStride:W}=N.normalCompressed,G=E?.length===1?E[0]:null,K=(e,t,n)=>G?s(e,t,G)??0:o(e,t,E)??0;for(let d=0;d<4;++d){if(!(r&1<<d))continue;let y=d===1||d===3,b=c.edgeResolutions[d];p(t(b));let N=b+1,P=u(l,c.edgePeerNeighbors[d]);if(ye(l,P,d)&&ie(e,d,P))continue;let R=P!=null;p(!R||P.level===l.level),p(!R||v(l,P)<=0);let z=P?.renderData?.geometryState;if(m){let e=l.surface;if(!P&&e&&!e.updatingRootTiles){let t=h[d],n=l.findNeighborTile(t,e=>e.loaded||e.leaf||e.level===l.level);n?n.intersectsClippingArea&&(p(!n.loaded),p(!n.leaf),p(n.level===f)):p(e?.rootTiles==null||!l.shouldHaveNeighbor(t))}}let q=d===1?_[2]:_[0],J=P?.extent,te=J&&y?d===1?J[0]:J[2]:q,ne=d===0?_[3]:_[1],re=+(d===1),Y=+(d===0),X=d===1?C:S,ae=d===0?T:w,oe=Math.sin(X),se=Math.cos(X),Z=Math.sin(ae),ce=Math.cos(ae),Q=z?.samplerData,$=Q?.length===1?Q[0]:null,le=(e,t,n)=>$?s(n,t,$)??0:o(n,t,Q)??0,ue=R?(e,t,n)=>(K(e,t)+le(e,t,n))*.5:K,de=i.outerEdgesOffsetAndLength[d*2+0],fe=G!=null||E!=null&&E.some(e=>e!=null),pe=$!=null||Q!=null&&Q.some(e=>e!=null),me=fe||pe,he=1/b,ge=n*he,_e=re*n,ve=Y*n,be=de;p(!J||g(J[2]-J[0],_[2]-_[0])),(()=>{let e=d===1?-1:+(d===3),t=d===0?-1:+(d===2),n=(_[2]-_[0])*he,r=e*n,i=t*n,c=C-S,l=y?c*he*e:0,u=y?0:t*he,f=Y,p=y?X+l:X,m=y?Math.sin(p):oe,h=y?Math.cos(p):se,g=y?X-l:X,v=y?Math.sin(g):oe,b=y?Math.cos(g):se,w=f+u,T=y?ae:j(w),P=y?Z:Math.sin(T),z=y?ce:Math.cos(T),K=f-u,J=y?ae:j(K),re=y?Z:Math.sin(J),ie=y?ce:Math.cos(J),le=0,de=0,fe=0;{let e=0*he,t=y?q:D*(1-e)+O*e,n=y?te:t,r=y?k*(1-e)+A*e:ne,i=y?X:S*(1-e)+C*e,a=y?oe:Math.sin(i),o=y?se:Math.cos(i),s=y?j(e):ae,c=y?Math.sin(s):Z,l=y?Math.cos(s):ce,u=x+ue(t,r,n);le=o*l*u,de=a*l*u,fe=c*u}let pe=0,ye=0,xe=0;{let e=+he,t=y?q:D*(1-e)+O*e,n=y?te:t,r=y?k*(1-e)+A*e:ne,i=y?X:S*(1-e)+C*e,a=y?oe:Math.sin(i),o=y?se:Math.cos(i),s=y?j(e):ae,c=y?Math.sin(s):Z,l=y?Math.cos(s):ce,u=x+ue(t,r,n);pe=o*l*u,ye=a*l*u,xe=c*u}for(let e=1;e<N-1;++e){let t=0,n=0,c=0;{let r=(e+1)*he,i=y?q:D*(1-r)+O*r,a=y?te:i,o=y?k*(1-r)+A*r:ne,s=y?X:S*(1-r)+C*r,l=y?oe:Math.sin(s),u=y?se:Math.cos(s),d=y?j(r):ae,f=y?Math.sin(d):Z,p=y?Math.cos(d):ce,m=x+ue(i,o,a);t=u*p*m,n=l*p*m,c=f*m}let l=t,u=n,f=c,p=pe,g=ye,_=xe;pe=l,ye=u,xe=f;{let t=be+e,n=t*V,r=p-F,i=g-I,a=_-L;B[n]=r,B[n+1]=i,B[n+2]=a,Ce(r,i,a,M);let o=Math.round(e*ge),s=t*U;H[s]=y?_e:o,H[s+1]=y?o:ve}let w=le,T=de,N=fe;le=p,de=g,fe=_;let K=p,J=g,Y=_,Se=1/Math.sqrt(K*K+J*J+Y*Y),we=Y*Se,Te=0,Ee=0,De=0;if(me&&we*we<.999){let t=0,n=0,a=0;{let e=d===0?-1:1;t=e*(l-w),n=e*(u-T),a=e*(f-N)}{let c=e*he,l=y?q:D*(1-c)+O*c,u=y?te:l,f=y?k*(1-c)+A*c:ne,p=y?X:S*(1-c)+C*c,g=y?oe:Math.sin(p),_=y?se:Math.cos(p),w=y?j(c):ae,T=y?Math.sin(w):Z,M=y?Math.cos(w):ce,N=K,F=J,I=Y;if(R){let e=u-r,t=f-i,n=x+($?s(e,t,$)??0:o(e,t,Q)??0),a=y?v:g,c=y?b:_,l=y?T:re,d=y?M:ie;N=c*d*n,F=a*d*n,I=l*n}{let e=l+r,c=f+i,u=x+(G?s(e,c,G)??0:o(e,c,E)??0),p=y?m:g,v=y?h:_,b=y?T:P,S=y?M:z,C=v*S*u,w=p*S*u,D=b*u;R||(N=2*K-C,F=2*J-w,I=2*Y-D);let O=d===3?-1:1,k=O*(N-C),A=O*(F-w),j=O*(I-D);Te=a*A-n*j,Ee=t*j-a*k,De=n*k-t*A;let L=1/Math.sqrt(Te*Te+Ee*Ee+De*De);Te*=L,Ee*=L,De*=L}}}else Te=K*Se,Ee=J*Se,De=Y*Se;a(ee,be+e,Te,Ee,De,W)}})()}}function A(e,t){ae(e,t)}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=we(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,Y(e),z(e,De,Oe),W(i,[],s),e.intersectionData=null}function I(t){let r=t.tile;if(!r.intersectsClippingArea)return;let{geometry:i,geometryState:c,localOrigin:l}=t,{samplerData:u,clippingArea:d,numVerticesPerSide:f}=c,{surface:p,extent:m,ellipsoid:h}=r,{isWebMercatorOnPlateCarree:g}=p,_=d??_e,v=m[0],y=m[1],b=m[2],x=m[3],S=Math.max(v,_[0]),C=Math.min(b,_[2]),w=Math.max(y,_[1]),T=Math.min(x,_[3]),E=h.radius,D=r.horizontalScale,O=f-1,k=f-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=l[0],V=l[1],H=l[2],U=I.typedBuffer,ee=I.typedBufferStride,W=0,G=e(y,w,T),K=g?(Math.PI/2-2*Math.atan(Math.exp(-G/E)))*E:G*D,q=1/O,J=e(y*(1-q)+x*q,w,T),te=g?(Math.PI/2-2*Math.atan(Math.exp(-J/E)))*E:J*D,ne=K,re=te,Y=u?.length===1?u[0]:null,X=Y?(e,t)=>s(e,t,Y)??0:(e,t)=>o(e,t,u)??0;for(let t=1;t<=k;t++){let r=t/O,i=e(y*(1-r)+x*r,w,T),o=e(r,j,N),s=re,c=(t-1)/O,l=e(y*(1-c)+x*c,w,T),u=ne,d=(t+1)/O,f=e(y*(1-d)+x*d,w,T),p=g?(Math.PI/2-2*Math.atan(Math.exp(-f/E)))*E:f*D,m=e(d,j,N);ne=re,re=p;let h=e(v,S,C),_=h*D,F=X(h,i),I=1/O,G=e(I,A,M),K=e(v*(1-G)+b*G,S,C),q=G,J=K,te=K*D,Y=X(K,i);if(t===1){let t=te-B,r=ne-V,i=Y-H,a=0*ee;U[a]=t,U[a+1]=r,U[a+2]=i,Ce(t,r,i,P);let s=e(I,A,M);L.setValues(W,Math.round(s*n),Math.round(o*n))}for(let r=1;r<=k;r++){let c=te,d=Y,h=(r+1)/O,g=e(h,A,M),y=e(v*(1-h)+b*h,S,C),x=J;J=y;{let e=W+1,a=e*ee;if(t===1||r===k){let c=X(y,i),l=y*D,u=s,d=c;if(t===1&&r<k){let t=l-B,r=u-V,i=d-H;U[a]=t,U[a+1]=r,U[a+2]=i,Ce(t,r,i,P),L.setValues(e,Math.round(g*n),Math.round(o*n))}te=l,Y=d}else te=U[a]+B,Y=U[a+2]+H}let w=te,T=Y,E=_,j=F;_=c,F=d;let N=(W-k)*ee,I=t===1?X(x,l):U[N+2]+H,G=X(x,f);if(t<k){let e=W+k,t=e*ee,r=c-B,i=p-V,a=G-H;U[t]=r,U[t+1]=i,U[t+2]=a,Ce(r,i,a,P);let o=q;q=g,L.setValues(e,Math.round(o*n),Math.round(m*n))}{let e=w-E,t=T-j,n=u-p,r=I-G,i=n*t,o=e*r,s=-n*e,c=i*i+o*o+s*s;if(c===0)a(R,W,0,0,1,z);else{let e=1/Math.sqrt(c);a(R,W,i*e,o*e,s*e,z)}}++W}}}function L(e){e.tile.intersectsClippingArea&&(X(e),z(e,De,Oe),se(e),Z(e),e.intersectionData=null)}function R(e,t=!1){e.tile.intersectsClippingArea&&(z(e,t?De:e.dirtyEdges,t?Oe:e.dirtyCorners),se(e),e.intersectionData=null)}function z(e,t,n){e.tile.intersectsClippingArea&&(n&&V(e,n),t&&B(e,t),(n||t)&&Se(e.geometry.boundingBox))}function B(n,r){let{geometry:i,geometryState:a,localOrigin:c}=n,l=n.tile,{surface:d,extent:f}=l,{clippingArea:g,samplerData:_}=a,y=g??_e,b=f[0],x=f[2],S=f[1],C=f[3],w=[C>y[3],x>y[2],S<y[1],b<y[0]],T=l.horizontalScale,E=ee(d.isWebMercatorOnPlateCarree,l.ellipsoid.radius,T),{minu:D,minv:O,maxu:k,maxv:A,boundingBox:j}=i,M=Math.max(b,y[0]),N=Math.min(x,y[2]),P=Math.max(S,y[1]),F=Math.min(C,y[3]),I=c[0],L=c[1],R=c[2],z=_?.length===1?_[0]:void 0,B=z?(e,t)=>s(e,t,z)??0:(e,t)=>o(e,t,_)??0;for(let c=0;c<4;++c){if(!(r&1<<c))continue;let f=c===1||c===3,g=a.edgeResolutions[c];p(t(g));let y=g+1,z=w[c],V=u(l,a.edgePeerNeighbors[c]);if(!z&&ye(l,V,c)&&ie(n,c,V))continue;let H=V!=null&&!z,U=V?.renderData?.geometryState;if(m&&(p(!H||V.level===l.level),p(!H||v(l,V)<=0),l&&!V&&!d.updatingRootTiles)){let e=h[c],t=l.findNeighborTile(e,e=>e.loaded||e.leaf||e.level===l.level);d.updatingRootTiles||(t?t.intersectsClippingArea&&(p(!t.loaded),p(!t.leaf),p(t.level===l.level)):p(d?.rootTiles==null||!l.shouldHaveNeighbor(e)))}let ee=e(c===1?x:b,M,N),W=e(c===0?C:S,P,F),G=U?.samplerData,K=e(+(c===1),D,k),q=e(+(c===0),O,A),J=G?.length===1?G[0]:null,te=(e,t)=>J?s(e,t,J)??0:o(e,t,G)??0,ne=H?(e,t)=>(te(e,t)+B(e,t))*.5:B,re=(x-b)/g,Y=f?c===1?re:-re:0,X=f?0:c===0?re:-re,ae=-Y,oe=-X,se=0,Z=0,ce=0;{let t=0/g,n=f?ee:e(b*(1-t)+x*t,M,N),r=f?e(S*(1-t)+C*t,P,F):W,i=ne(n,r);se=n*T,Z=E(r),ce=i}let Q=0,$=0,le=0;{let t=1/g,n=f?ee:e(b*(1-t)+x*t,M,N),r=f?e(S*(1-t)+C*t,P,F):W,i=ne(n,r),a=n*T,o=E(r),s=i;Q=a,$=o,le=s}for(let t=1;t<y-1;++t){let n=t/g,r=Q,a=$,s=le;{let o=f?K:e(n,D,k),l=f?e(n,O,A):q,u=r-I,d=a-L,p=s-R;Ce(u,d,p,j),i.setEdgeVertexFromValuesRawPositionUV(c,t,u,d,p,o,l)}{let n=(t+1)/g,r=f?ee:e(b*(1-n)+x*n,M,N),i=f?e(S*(1-n)+C*n,P,F):W,a=ne(r,i);Q=r*T,$=E(i),le=a}let l=Q,u=$,d=le,p=se,m=Z,h=ce;se=r,Z=a,ce=s;let v=0,y=0,w=0;if(f){let t=u-a,i=d-s,l=m-a,f=h-s,p=e(S*(1-n)+C*n,P,F),g=ee+ae,b=p,x=g*T,E=o(g,b,_),D=x-r,O=E-s,k=c===3?-1:1;if(v=k*(-l+t)*O,y=k*D*(-f+i),w=-k*D*(-l+t),H){let e=ee+Y,n=p,a=e*T,c=o(e,n,G),u=a-r,d=c-s;v=(-l+t)*(O-d),y=(D-u)*(-f+i),w=-(D-u)*(-l+t)}}else{let t=l-r,i=d-s,u=p-r,f=h-s,m=e(b*(1-n)+x*n,M,N),g=m,S=W+oe,C=o(g,S,_)-s,T=E(S)-a,D=c===2?-1:1;if(v=D*T*(-f+i),y=D*(-u+t)*C,w=-D*T*(-u+t),H){let e=m,n=W+X,r=E(n),c=o(e,n,G)-s,l=r-a;v=(-T+l)*(-f+i),y=(-u+t)*(-C+c),w=-(-T+l)*(-u+t)}}let z=1/Math.sqrt(v*v+y*y+w*w);i.setEdgeNormalFromValues(c,t,v*z,y*z,w*z)}}}function V(e,t){ae(e,t)}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,c=r-3,u=r-3,d=2*c*u,f=4*(o+a-3),p=l.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,e.innerTriangleOrder=!n&&c>0?G(c):null,n?(te(e),ne(e,t),re(e)):(K(e),q(e,t),J(e))}function G(e){let t=de.get(e);if(t)return t;let n=new Uint32Array(2*e*e),r=2**Math.ceil(Math.log2(e)),i=0;for(let t=0;t<r*r;++t){let a=0,o=0,s=t;for(let e=1;e<r;e*=2){let t=s>>1&1,n=(s^t)&1;if(n===0){t===1&&(a=e-1-a,o=e-1-o);let n=a;a=o,o=n}a+=e*t,o+=e*n,s>>=2}if(a<e&&o<e){let t=2*(o*e+a);n[i++]=t,n[i++]=t+1}}return de.set(e,n),n}function K(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;Te(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 q(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 J(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=xe[n],s=0,c=0,l=e.getEdgeCount(n),u=r.count;p(u===i-1);let d=n===1||n===2,f=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,p=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||p<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+f]=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;Te(f,p,m,m-1,o,a)?(Ee(t,c,n,l,u),c+=6,Ee(t,c,u,d,n)):(Ee(t,c,n,l,d),c+=6,Ee(t,c,d,u,l)),c+=6}}}function ne(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++)Ee(n,o,s,s+1,t+r),o+=6,e<i.latitudeResolution-1&&(Ee(n,o,s+1,t+r+1,t+r),o+=6),s+=c;s=t,c=1}}}function re(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=xe[n],s=0,c=0,l=e.getEdgeCount(n),u=r.count;p(u===i-1);let d=n===1||n===2,f=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,p=r?0+i*(s+.5)/(l-1):0,v=d?1+a*(c+.5)/(u-1):0,y=r&&(!d||p<=v);y?++s:++c;let b=y?n+1:e+_;t[o]=e,t[o+f]=n,t[o+f+1]=n,t[o+m]=b,t[o+m+1]=b,t[o+5]=e,o+=6}}e.indexCount=o}function Y(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=xe[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 X(e){Y(e),e.geometryState.wireframe?re(e.geometry):J(e.geometry)}function ie(r,i,a){let{geometryState:o,geometry:s,tile:c,localOrigin:l}=r,u=i===1||i===3,d=o.edgeResolutions[i];p(t(d));let f=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);p(C.edgeResolutions[T]===O),p(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<f-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,Ce(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 ae(t,r){let{geometry:i,geometryState:a,localOrigin:s}=t,{clippingArea:c,samplerData:l}=a,{minu:u,minv:d,maxu:f,maxv:m,boundingBox:h,vertexAttributes:g}=i,_=t.tile,{surface:y,ellipsoid:b,extent:x,extentInRadians:S,horizontalScale:C}=_,w=b.radius,T=0,E=0,D=0,O=()=>{let t=c,n=t!=null&&(x[3]>t[3]||x[2]>t[2]||x[1]<t[1]||x[0]<t[0]),r=ee(y.isWebMercatorOnPlateCarree,w,C);return(i,a,o)=>{let s=i===0?x[0]:x[2],c=a===0?x[1]:x[3],l=n?e(s,t[0],t[2]):s,u=n?e(c,t[1],t[3]):c,d=o;T=l*C,E=r(u),D=d}},k=(e,t,n)=>{let r=S[t===0?1:3],i=S[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},A=y.isGlobal,j=A?k:O(),M=0,N=0,F=0,I=0,L=0,R=0,z=0,B=0,V=0,H=!A&&y.isWebMercatorOnPlateCarree,U=(e,t,n,r,i)=>{let a=0,o=0,s=0;if(A){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}else{let e=t*C,i=H?(Math.PI/2-2*Math.atan(Math.exp(-n/w)))*w:n*C,c=r;a=e-T,o=i-E,s=c-D}switch(i){case 0:z+=a,B+=o,V+=s;break;case 1:I-=a,L-=o,R-=s;break;case 2:z-=a,B-=o,V-=s;break;case 3:I+=a,L+=o,R+=s}},W=c??_e,G=x[0],K=x[2],q=x[1],J=x[3],te=[J>W[3],K>W[2],q<W[1],G<W[0]],ne=Math.max(G,W[0]),re=Math.min(K,W[2]),Y=Math.max(q,W[1]),X=Math.min(J,W[3]),ie=e=>Math.max(W[0],Math.min(W[2],e)),ae=e=>Math.max(W[1],Math.min(W[3],e)),se=e=>{let t=a.cornerNeighborCornerTiles;M=0,N=0,F=1,I=0,L=0,R=0,z=0,B=0,V=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];ve[r]=i?.level===n?i:null}let r=1,i=0;for(let e=0;e<4;++e){let t=ve[e];t&&(r=Math.max(r,t?.renderData.geometryState.numVerticesPerSide),i=t.extent[2]-t.extent[0])}let s=i,c=r;p(c>1);let l=s/c;for(let e=0;e<4;++e){let t=ve[(e+3)%4],n=ve[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 a=Q[e][0]*l,s=Q[e][1]*l,c=t.extent,u=ie(c[r===0||r===1?2:0]+a),d=ae(c[r===0||r===3?3:1]+s),f=n.extent,p=ie(f[i===0||i===1?2:0]+a),m=ae(f[i===0||i===3?3:1]+s),h=t.renderData,g=n.renderData,_=o(u,d,h.geometryState.samplerData),v=o(p,m,g.geometryState.samplerData);U(h,u,d,.5*(_+v),e)}else{let a=t??n,s=t?r:i,c=a.extent,u=Q[e],d=ie(c[s===0||s===1?2:0]+u[0]*l),f=ae(c[s===0||s===3?3:1]+u[1]*l),p=a.renderData,m=o(d,f,p.geometryState.samplerData);U(p,d,f,m,e)}}if(A){let e=Math.sqrt(T*T+E*E+D*D);M=T/e,N=E/e,F=D/e}if(!A||F*F<.999){let e=Math.sqrt(I*I+L*L+R*R);I/=e,L/=e,R/=e;let t=Math.sqrt(z*z+B*B+V*V);z/=t,B/=t,V/=t,M=R*B-L*V,N=I*V-R*z,F=L*z-I*B;let n=1/Math.sqrt(M*M+N*N+F*F);M*=n,N*=n,F*=n}},Z=a.cornerNeighborCornerTiles;for(let t=0;t<4;++t){if(!(r&1<<t))continue;let c=t,y=(t+1)%4,b=+(t===0||t===1),x=+(t===0||t===3),S=e(b,u,f),C=e(x,d,m),w=i.getEdgeFirstVertexIndex(c),O=i.getEdgeCount(c),k=t===0||t===3?O-1:0,A=i.getEdgeFirstVertexIndex(y),P=i.getEdgeCount(y),I=t===0||t===1?P-1:0,L=-1;for(let e=0;e<4;++e){let n=Z[t*4+e],r=Z[t*4+L];n&&(L===-1||v(r,n)>0)&&(L=e)}let R=L,z=Z[t*4+R];if(z!==_){let e=_.level-z.level,r=2**e,i=[z.lij[0]+e,z.lij[1]*r,z.lij[2]*r],o=[i[1]+r===_.lij[1],t===0&&(R===1||R===0&&z!==Z[t*4+3])||t===1&&(R===0||R===1&&z!==Z[t*4+2]),i[1]===_.lij[1]+1,t===2&&(R===3||R===2&&z!==Z[t*4+1])||t===3&&(R===2||R===3&&z!==Z[t*4+0])],c=o.reduce((e,t)=>e+ +!!t,0);p(c===1||c===2);let l=-1,u=-1,d=z.renderData;if(c===1){let e=o.findIndex(e=>e);p(0<=e&&e<=3),l=(e+2)%4;let n=a.edgeResolutions[e];u=_.getNeighborEdgeStartVertexIndex(e,z)*n+n*+(e===0&&t===0||e===1&&t===0||e===2&&t===1||e===3&&t===3)}else{p(o[1]||o[3]),l=o[1]?3:1;let e=d.geometryState.edgeResolutions[l];u=t===0||t===3?0:e}let f=d.geometry;{let e=w+k,t=A+I,r=f.getEdgeFirstVertexIndex(l)+u,i=f.vertexAttributes,a=d.localOrigin,o=i.position,c=o.typedBuffer,p=r*o.typedBufferStride,m=c[p]+a[0]-s[0],_=c[p+1]+a[1]-s[1],v=c[p+2]+a[2]-s[2];Ce(m,_,v,h);let y=g.position,b=y.typedBuffer,x=e*y.typedBufferStride;b[x]=m,b[x+1]=_,b[x+2]=v;let T=t*y.typedBufferStride;b[T]=m,b[T+1]=_,b[T+2]=v;let E=g.uv0;E.setValues(e,Math.round(S*n),Math.round(C*n)),E.setValues(t,Math.round(S*n),Math.round(C*n));{let n=i.normalCompressed.typedBuffer,a=r*i.normalCompressed.typedBufferStride,o=g.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=te[c],r=te[y],a;if(n||r){let t=e(G*(1-b)+K*b,ne,re),n=e(q*(1-x)+J*x,Y,X);a=o(t,n,l)}else a=oe(Z,t);j(b,x,a),se(t);let u=T-s[0],d=E-s[1],f=D-s[2];Ce(u,d,f,h),i.setEdgeVertexFromValuesRawPositionUVNormal(c,k,u,d,f,S,C,M,N,F),i.setEdgeVertexFromValuesRawPositionUVNormal(y,I,u,d,f,S,C,M,N,F)}}for(let e=0;e<4;++e)ve[e]=null}function oe(e,t){let n=t*4,r=l.reduce((t,r)=>Math.min(t,e[n+r]?.level??1/0),1/0);m&&(p(!e[n+0]||!e[n+2]||_(e[n+0],e[n+2],5)),p(!e[n+1]||!e[n+3]||_(e[n+1],e[n+3],7)));let i=0,a=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=o(c,l,u);a+=d,i++}}let s=i?a/i:0;return p(s!=null),s}function se(e){let{vao:t,geometry:n}=e,{vertexAttributes:r,edgeVerticesStartIndex:i}=n,{position:a}=r,o=a.typedBuffer,s=i*a.typedBufferStride,c=(n.getEdgeFirstVertexIndex(3)+n.getEdgeCount(3))*a.typedBufferStride;t.buffer()?.setSubData(o,s,s,c)}function Z(e){let{vao:t,geometry:n}=e,{indices:r,indexCount:i,edgeIndicesStartIndex:a}=n;t.indexBuffer.setSubData(r,a,a,i)}class ce{constructor(e,t,n,r,i){this.isNorth=e,this.connectedRowOffset=t,this.connectedOuterEdgeOffset=n,this.rowOffset=r,this.latitudeResolution=i}}const Q=[[0,1],[1,0],[0,-1],[-1,0]],$=new c,le=.5*f,ue=new Uint16Array(d+1),de=new Map,fe=new Int32Array(d+1),pe=new Int32Array(d+1),me=new Int32Array(d+1),he=new Float64Array(d+1),ge=new Float64Array(d+1),_e=i(-1/0,-1/0,1/0,1/0),ve=[null,null,null,null];function ye(e,t,n){if(!t)return!1;let r=v(e,t);return r>0||r===0&&n>=2}class be{constructor(){this.vertex0Index=0,this.stride=1,this.count=0}getVertexIndex(e){return p(0<=e&&e<this.count),this.vertex0Index+this.stride*e}}const xe=[new be,new be,new be,new be];function Se(e){for(let t=0;t<3;t++)e[t]=Math.min(e[t],Math.fround(e[t])),e[t+3]=Math.max(e[t+3],Math.fround(e[t+3]))}function Ce(e,t,n,r){r[0]=Math.min(r[0],e),r[3]=Math.max(r[3],e),r[1]=Math.min(r[1],t),r[4]=Math.max(r[4],t),r[2]=Math.min(r[2],n),r[5]=Math.max(r[5],n)}function we(e){let{edgeResolutions:t,numVerticesPerSide:n}=e,r=1+Math.max(...t);return Math.max(n,r)}function Te(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 Ee(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 De=15,Oe=15,ke=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{__decorate as e}from"tslib";import{property as t,subclass as n}from"../../../core/accessorSupport/decorators.js";import has from"../../../core/has.js";import{fromTranslation as r}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as i}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{subtract as a,set as o,dot as s}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as c,fromValues as l,create as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as d,ZEROS as f}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{disposeMaybe as p}from"../../../core/maybe.js";import{MemCachePool as m}from"../../../core/MemCachePool.js";import h from"../../../core/ObjectPool.js";import{watch as g,sync as _}from"../../../core/reactiveUtils.js";import{create as v,set as y}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as b}from"../../../geometry/support/buffer/BufferView.js";import{noBudget as x}from"../../support/Scheduler.js";import{PrimitiveType as S}from"../../webgl/enums.js";import{getOverlayContentForOutputTerrain as C}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as w}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as T}from"../webgl-engine/lib/Attribute.js";import{unionDepthRangeWithAABB as E}from"../webgl-engine/lib/depthRangeUtils.js";import{IntersectorResultRay as D}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as ee,MeshIntersectionOptions as O,intersectTriangles as k}from"../webgl-engine/lib/RayIntersections.js";import{TriangleRangeBVH as A}from"../webgl-engine/lib/TriangleRangeBVH.js";import{terrainId as j,getVerticalOffsetTerrain as M}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as N}from"../webgl-engine/materials/DrawParameters.js";import{hasShadowHighlights as P}from"../webgl-engine/shaders/ReceiveShadowsConfiguration.js";import{T as F}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as I}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as L}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{overlayRenderOccludedFlag as R}from"./OverlayRenderer.js";import{PatchRenderData as z}from"./PatchRenderData.js";import{TerrainAttributesCache as B}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as V}from"./terrainUtils.js";import{TileRenderer as H}from"./TileRenderer.js";import{IteratorPreorder as U,fallsWithinLayerView as W,usesStencil as G,sortTiles as K,compareTiles as q}from"./tileUtils.js";const J=v(),Y=i();let X=class extends w{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return this._view.stage.isGlobal}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}get renderOccludedFlags(){return this._overlayRenderer.renderOccludedFlags}constructor(e,t,n,r,i){super(),this._surface=e,this._overlayRenderer=t,this._allTiles=n,this._compressionTracker=r,this.type=7,this.isGround=!0,this._passParameters=new F,this._drawParameters=new N,this._renderDataPool=new h(()=>new z),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new U,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===R]]),this._tileSize=256,this._configuration=new L(i.state.isGlobal),this._tileTextureCache=new m((e,t)=>i.resourceController.memoryController.newCache(e,t),`TileTexture`),this.tileGeometryCache=new B(i.resourceController.memoryController)}initialize(){this.addHandles(g(()=>this._overlayRenderer.renderOccludedFlags,()=>this.requestRender(),_))}destroy(){this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}unionDepthRange(e,t){if(this._produces()&&has(`enable-feature:terrain-shadows`)){this._updatePatchGroups();for(let[n,i]of this._visiblePatchesByOrigin){r(Y,n);for(let n of i)E(t,e,Y,n.renderData.geometry.boundingBox)}}}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 j}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)),e.surface.tileElevationRangeChanged(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=d(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(W(e,n)!==W(t,n))return!1}return!0}updateTileTexture(e,t){if(this._tileRenderer!=null){let n=t===32?0:2;if(!this._tileRenderer.updateTileTexture(e,n))return e.updateRenderData(1,n),!1;this.requestRender(),e.resetPendingUpdate(t)}return!0}updateTileGeometryState(e){for(let t of e.layerInfo[0])t.pendingUpdates&=-9;e.resetPendingUpdate(8);let t=e.renderData.updateGeometryState();return this._surface.updateElevationSources(e),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.dispose(),e.renderData=null,e.surface.tileElevationRangeChanged(e,e.elevationBoundsMin,e.elevationBoundsMax),e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){let t=Math.max(0,Math.floor((e.level-3)/7)*7);if(this._isGlobal&&t===0)return c;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 H(this._surface,this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=p(this._tileRenderer)}intersectRay(e,t,n,r){this.intersectRayBudgeted(e,t,n,r,x)}intersectRayBudgeted(e,t,n,r,i){let c=this._rootTiles;if(!c||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==0)return!0;let l=Z,u=Q;a(l,r,n),o(u,1/l[0],1/l[1],1/l[2]);let d=e.results.min,f=e.results.max,p=e.results.ground,m=e.options.store===0,h=!!e.results.ground.target,g=M(e.verticalOffset),_=e.tolerance,v,x=m&&d.distance!=null?d.distance:1/0,S=e.options,C=S.normalRequired||!S.backfacesTerrain,w=new O(_,!1,C),E=o=>{let c=o.renderData;if(!c?.vao)return!0;let h=c.geometry;y(J,h.boundingBox);let E=c.localOrigin;if(g!=null&&(g.localOrigin=E,g.applyToAabb(J)),$[0]=n[0]-E[0],$[1]=n[1]-E[1],$[2]=n[2]-E[2],!ee(J,$,u,_,x))return!0;let O=(e,t,n,r)=>{e.set(this.type,o,t,n,r),x=m&&d.renderDistance!=null?d.renderDistance:1/0},j=(i,a,o)=>{(!C||o!=null)&&a>=0&&(S.backfacesTerrain||s(o,l)<0)&&(S.invisibleTerrain||!S.selectionMode||t==null||t(n,r,a))&&((p.renderDistance==null||a<p.renderDistance)&&O(p,i,a,o),S.isFiltered||(S.store===2&&(v==null?(v=new D(e.ray),O(v,i,a,o),e.results.all.push(v)):a<v.renderDistance&&O(v,i,a,o)),(d.renderDistance==null||a<d.renderDistance)&&O(d,i,a,o),S.store!==0&&(f.renderDistance==null||a>f.renderDistance)&&O(f,i,a,o)))},M=te;a(M,r,E);let{indices:N,indexCount:P}=h,F=h.vertexAttributes,I=F.getField(`position`,b),L=new T(I.typedBuffer,3,F.stride/4),R=P/3;if(!g&&R>200){if(c.intersectionData??=new A(N,R,L,!0,[h.poleIndicesStartIndex/3,h.edgeIndicesStartIndex/3]),c.intersectionData.advance(i),!c.intersectionData.ready||i.done)return!1;c.intersectionData.intersectRay($,M,w,j)}else k($,M,0,R,(e,t)=>I.getVec(N[t],e),g,w,j);return!0},j=this._tileIterator;j.reset(c);let N=e.options.invisibleTerrain;for(let e=j.next();e;e=j.next()){if(i.done)return!1;if((e.visible||N&&e.intersectsClippingArea)&&(g!=null||e.intersectsRay(n,l,_,x))&&(!h||!G(e,this._stencilEnabledLayerExtents))){if(!E(e))return!1}else j.skipSubtree()}return i.madeProgress(),!0}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&R)===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,c.emissionReflections=c.screenSpaceReflections&&a&&n.reprojection.lastFrameEmission!=null;let r=i===9;return c.receiveShadows=t.ready&&!r,c.hasShadowHighlights=P(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=C(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=l(t[0]||0,t[1]||0,t[2]||0)}t.setBackground(n),this._allTiles.forAll(e=>{t.updateTileTexture(e,0)||e.updateRenderData(1,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)K(n,t);e.sort((e,t)=>q(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,o=this.transparency===2||this.transparency===3,s=this._passParameters.overlayContent===null||(e.output===3||e.output===4)&&!o;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],S.TRIANGLES,a,s)}),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`,c),i.setUniform4fv(`texOffsetAndScale`,f));let o=this._tileRenderer?.backgroundColor==null?c:this._tileRenderer.backgroundColor;this._configuration.tileBlendInput===1&&i.setUniform3fv(`backgroundColor`,o);let s=!!this._stencilEnabledLayerExtents?.length,l=this.wireframe?S.LINES:S.TRIANGLES;this._configuration.textureFadingEnabled&&!a&&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)):this._configuration.textureFadingEnabled&&i.setUniform1f(`fadeFactor`,1),n.textureIsFading&&this.requestRender(2),i.setUniform3fv(`textureOpacities`,o.opacities)}this._renderPatch(e,t,r,l,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){V&&console.error(`Rendered tile with no indices: `,n.lij,` : `,o);return}let l=t.program;!a&&this._configuration.overlayEnabled&&this._bindOverlayPatchData(l,o.overlay);let{rctx:u,bind:d}=e;i&&(this._passParameters.useStencil=G(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(I,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([t({readOnly:!0})],X.prototype,`visibleTiles`,null),e([t({readOnly:!0})],X.prototype,`_isGlobal`,null),e([t()],X.prototype,`renderOccludedFlags`,null),e([t({value:!1})],X.prototype,`renderingDisabled`,null),e([t({value:!0})],X.prototype,`visible`,null),e([t()],X.prototype,`renderPatchBorders`,null),e([t()],X.prototype,`wireframe`,null),X=e([n(`esri.views.3d.terrain.TerrainRenderer`)],X);const Z=u(),Q=u(),$=u(),te=u();export{X as TerrainRenderer};
|
|
2
|
+
import{__decorate as e}from"tslib";import{property as t,subclass as n}from"../../../core/accessorSupport/decorators.js";import has from"../../../core/has.js";import{fromTranslation as r}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as i}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{subtract as a,set as o,dot as s}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as c,fromValues as l,create as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as d,ZEROS as f}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{disposeMaybe as p}from"../../../core/maybe.js";import{MemCachePool as m}from"../../../core/MemCachePool.js";import h from"../../../core/ObjectPool.js";import{watch as g,sync as _}from"../../../core/reactiveUtils.js";import{create as v,set as y}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as b}from"../../../geometry/support/buffer/BufferView.js";import{noBudget as x}from"../../support/Scheduler.js";import{PrimitiveType as S}from"../../webgl/enums.js";import{getOverlayContentForOutputTerrain as C}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as w}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as T}from"../webgl-engine/lib/Attribute.js";import{unionDepthRangeWithAABB as E}from"../webgl-engine/lib/depthRangeUtils.js";import{IntersectorResultRay as D}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as ee,MeshIntersectionOptions as O,intersectTriangles as k}from"../webgl-engine/lib/RayIntersections.js";import{TriangleRangeBVH as A}from"../webgl-engine/lib/TriangleRangeBVH.js";import{terrainId as j,getVerticalOffsetTerrain as M}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as N}from"../webgl-engine/materials/DrawParameters.js";import{hasShadowHighlights as P}from"../webgl-engine/shaders/ReceiveShadowsConfiguration.js";import{T as F}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as I}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as L}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{overlayRenderOccludedFlag as R}from"./OverlayRenderer.js";import{PatchRenderData as z}from"./PatchRenderData.js";import{TerrainAttributesCache as B}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as V}from"./terrainUtils.js";import{TileRenderer as H}from"./TileRenderer.js";import{IteratorPreorder as U,fallsWithinLayerView as W,usesStencil as G,sortTiles as K,compareTiles as q}from"./tileUtils.js";const J=v(),Y=i();let X=class extends w{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return this._view.stage.isGlobal}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}get renderOccludedFlags(){return this._overlayRenderer.renderOccludedFlags}constructor(e,t,n,r,i){super(),this._surface=e,this._overlayRenderer=t,this._allTiles=n,this._compressionTracker=r,this.type=7,this.isGround=!0,this._passParameters=new F,this._drawParameters=new N,this._renderDataPool=new h(()=>new z),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new U,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===R]]),this._tileSize=256,this._configuration=new L(i.state.isGlobal),this._tileTextureCache=new m((e,t)=>i.resourceController.memoryController.newCache(e,t),`TileTexture`),this.tileGeometryCache=new B(i.resourceController.memoryController)}initialize(){this.addHandles(g(()=>this._overlayRenderer.renderOccludedFlags,()=>this.requestRender(),_))}destroy(){this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}unionDepthRange(e,t){if(this._produces()&&has(`enable-feature:terrain-shadows`)){this._updatePatchGroups();for(let[n,i]of this._visiblePatchesByOrigin){r(Y,n);for(let n of i)E(t,e,Y,n.renderData.geometry.boundingBox)}}}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 j}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)),e.surface.tileElevationRangeChanged(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=d(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(W(e,n)!==W(t,n))return!1}return!0}updateTileTexture(e,t){if(this._tileRenderer!=null){let n=t===32?0:2;if(!this._tileRenderer.updateTileTexture(e,n))return e.updateRenderData(1,n),!1;this.requestRender(),e.resetPendingUpdate(t)}return!0}updateTileGeometryState(e){for(let t of e.layerInfo[0])t.pendingUpdates&=-9;e.resetPendingUpdate(8);let t=e.renderData.updateGeometryState();return this._surface.updateElevationSources(e),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.dispose(),e.renderData=null,e.surface.tileElevationRangeChanged(e,e.elevationBoundsMin,e.elevationBoundsMax),e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){let t=Math.max(0,Math.floor((e.level-3)/7)*7);if(this._isGlobal&&t===0)return c;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 H(this._surface,this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=p(this._tileRenderer)}intersectRay(e,t,n,r){this.intersectRayBudgeted(e,t,n,r,x)}intersectRayBudgeted(e,t,n,r,i){let c=this._rootTiles;if(!c||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==0)return!0;let l=Z,u=Q;a(l,r,n),o(u,1/l[0],1/l[1],1/l[2]);let d=e.results.min,f=e.results.max,p=e.results.ground,m=e.options.store===0,h=!!e.results.ground.target,g=M(e.verticalOffset),_=e.tolerance,v,x=m&&d.distance!=null?d.distance:1/0,S=e.options,C=S.normalRequired||!S.backfacesTerrain,w=new O(_,!1,C),E=o=>{let c=o.renderData;if(!c?.vao)return!0;let h=c.geometry;y(J,h.boundingBox);let E=c.localOrigin;if(g!=null&&(g.localOrigin=E,g.applyToAabb(J)),$[0]=n[0]-E[0],$[1]=n[1]-E[1],$[2]=n[2]-E[2],!ee(J,$,u,_,x))return!0;let O=(e,t,n,r)=>{e.set(this.type,o,t,n,r),x=m&&d.renderDistance!=null?d.renderDistance:1/0},j=(i,a,o)=>{(!C||o!=null)&&a>=0&&(S.backfacesTerrain||s(o,l)<0)&&(S.invisibleTerrain||!S.selectionMode||t==null||t(n,r,a))&&((p.renderDistance==null||a<p.renderDistance)&&O(p,i,a,o),S.isFiltered||(S.store===2&&(v==null?(v=new D(e.ray),O(v,i,a,o),e.results.all.push(v)):a<v.renderDistance&&O(v,i,a,o)),(d.renderDistance==null||a<d.renderDistance)&&O(d,i,a,o),S.store!==0&&(f.renderDistance==null||a>f.renderDistance)&&O(f,i,a,o)))},M=te;a(M,r,E);let{indices:N,indexCount:P}=h,F=h.vertexAttributes,I=F.getField(`position`,b),L=new T(I.typedBuffer,3,F.stride/4),R=P/3;if(!g&&R>200){if(c.intersectionData??=new A(N,R,L,!0,[h.poleIndicesStartIndex/3,h.edgeIndicesStartIndex/3],[h.innerTriangleOrder]),c.intersectionData.advance(i),!c.intersectionData.ready||i.done)return!1;c.intersectionData.intersectRay($,M,w,j)}else k($,M,0,R,(e,t)=>I.getVec(N[t],e),g,w,j);return!0},j=this._tileIterator;j.reset(c);let N=e.options.invisibleTerrain;for(let e=j.next();e;e=j.next()){if(i.done)return!1;if((e.visible||N&&e.intersectsClippingArea)&&(g!=null||e.intersectsRay(n,l,_,x))&&(!h||!G(e,this._stencilEnabledLayerExtents))){if(!E(e))return!1}else j.skipSubtree()}return i.madeProgress(),!0}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&R)===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,c.emissionReflections=c.screenSpaceReflections&&a&&n.reprojection.lastFrameEmission!=null;let r=i===9;return c.receiveShadows=t.ready&&!r,c.hasShadowHighlights=P(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=C(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=l(t[0]||0,t[1]||0,t[2]||0)}t.setBackground(n),this._allTiles.forAll(e=>{t.updateTileTexture(e,0)||e.updateRenderData(1,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)K(n,t);e.sort((e,t)=>q(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,o=this.transparency===2||this.transparency===3,s=this._passParameters.overlayContent===null||(e.output===3||e.output===4)&&!o;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],S.TRIANGLES,a,s)}),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`,c),i.setUniform4fv(`texOffsetAndScale`,f));let o=this._tileRenderer?.backgroundColor==null?c:this._tileRenderer.backgroundColor;this._configuration.tileBlendInput===1&&i.setUniform3fv(`backgroundColor`,o);let s=!!this._stencilEnabledLayerExtents?.length,l=this.wireframe?S.LINES:S.TRIANGLES;this._configuration.textureFadingEnabled&&!a&&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)):this._configuration.textureFadingEnabled&&i.setUniform1f(`fadeFactor`,1),n.textureIsFading&&this.requestRender(2),i.setUniform3fv(`textureOpacities`,o.opacities)}this._renderPatch(e,t,r,l,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){V&&console.error(`Rendered tile with no indices: `,n.lij,` : `,o);return}let l=t.program;!a&&this._configuration.overlayEnabled&&this._bindOverlayPatchData(l,o.overlay);let{rctx:u,bind:d}=e;i&&(this._passParameters.useStencil=G(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(I,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([t({readOnly:!0})],X.prototype,`visibleTiles`,null),e([t({readOnly:!0})],X.prototype,`_isGlobal`,null),e([t()],X.prototype,`renderOccludedFlags`,null),e([t({value:!1})],X.prototype,`renderingDisabled`,null),e([t({value:!0})],X.prototype,`visible`,null),e([t()],X.prototype,`renderPatchBorders`,null),e([t()],X.prototype,`wireframe`,null),X=e([n(`esri.views.3d.terrain.TerrainRenderer`)],X);const Z=u(),Q=u(),$=u(),te=u();export{X as TerrainRenderer};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{invert as e,translate as t}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{ZEROS as r}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Float3PassUniform as i}from"../../shaderModules/Float3PassUniform.js";import{FloatPassUniform as a}from"../../shaderModules/FloatPassUniform.js";import{FloatsPassUniform as o}from"../../shaderModules/FloatsPassUniform.js";import{glsl as s,If as c}from"../../shaderModules/glsl.js";import{Matrix4DrawUniform as l}from"../../shaderModules/Matrix4DrawUniform.js";import{getLocalUp as u}from"../shading/getLocalUp.glsl.js";import{VisualVariables as d}from"../shading/VisualVariables.glsl.js";import{ScreenSizePerspective as f,addScreenSizePerspective as p}from"../util/ScreenSizePerspective.glsl.js";import{addCameraPosition as m,addLocalOrigin as h}from"../util/View.glsl.js";function g(n,g){let{vertex:v}=n;v.uniforms.add(new a(`intrinsicWidth`,e=>e.width));let{hasScreenSizePerspective:y}=g;y?(v.include(u,g),n.include(f,g),p(v),m(v,g),v.uniforms.add(new l(`inverseViewMatrix`,(n,r)=>e(_,t(_,r.
|
|
2
|
+
import{invert as e,translate as t}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{ZEROS as r}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Float3PassUniform as i}from"../../shaderModules/Float3PassUniform.js";import{FloatPassUniform as a}from"../../shaderModules/FloatPassUniform.js";import{FloatsPassUniform as o}from"../../shaderModules/FloatsPassUniform.js";import{glsl as s,If as c}from"../../shaderModules/glsl.js";import{Matrix4DrawUniform as l}from"../../shaderModules/Matrix4DrawUniform.js";import{getLocalUp as u}from"../shading/getLocalUp.glsl.js";import{VisualVariables as d}from"../shading/VisualVariables.glsl.js";import{ScreenSizePerspective as f,addScreenSizePerspective as p}from"../util/ScreenSizePerspective.glsl.js";import{addCameraPosition as m,addLocalOrigin as h}from"../util/View.glsl.js";function g(n,g){let{vertex:v}=n;v.uniforms.add(new a(`intrinsicWidth`,e=>e.width));let{hasScreenSizePerspective:y}=g;y?(v.include(u,g),n.include(f,g),p(v),m(v,g),v.uniforms.add(new l(`inverseViewMatrix`,(n,r)=>e(_,t(_,r.viewCamera.viewMatrix,n.origin)))),g.spherical?h(v,g):v.constants.add(`localOrigin`,`vec3`,r),v.code.add(s`float applyLineSizeScreenSizePerspective(float size, vec3 pos) {
|
|
3
3
|
vec3 worldPos = (inverseViewMatrix * vec4(pos, 1)).xyz;
|
|
4
4
|
vec3 groundUp = getLocalUp(worldPos, localOrigin);
|
|
5
5
|
float absCosAngle = abs(dot(groundUp, normalize(worldPos - cameraPosition)));
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{isImagePattern as e}from"../../../materials/lineStippleUtils.js";import{computeTextureSize as t}from"../../../materials/stippleTextureRepository.js";import{ensureColor4 as n}from"../../../shaders/ensureColor4.js";import{Float4PassUniform as r}from"../../shaderModules/Float4PassUniform.js";import{FloatPassUniform as i}from"../../shaderModules/FloatPassUniform.js";import{glsl as a,If as o}from"../../shaderModules/glsl.js";import{Texture2DPassUniform as s}from"../../shaderModules/Texture2DPassUniform.js";import{worldToScreenPerDistanceRatio as
|
|
2
|
+
import{isImagePattern as e}from"../../../materials/lineStippleUtils.js";import{computeTextureSize as t}from"../../../materials/stippleTextureRepository.js";import{ensureColor4 as n}from"../../../shaders/ensureColor4.js";import{Float4PassUniform as r}from"../../shaderModules/Float4PassUniform.js";import{FloatPassUniform as i}from"../../shaderModules/FloatPassUniform.js";import{glsl as a,If as o}from"../../shaderModules/glsl.js";import{Texture2DPassUniform as s}from"../../shaderModules/Texture2DPassUniform.js";import{isShadow as c}from"../ShaderOutput.js";import{worldToScreenPerDistanceRatio as l,pixelRatio as u}from"../util/cameraUniforms.js";import{MixExternalColor as d}from"../util/MixExternalColor.glsl.js";import{NoPerspectiveRead as f}from"../util/NoPerspective.glsl.js";import{addCameraPosition as p}from"../util/View.glsl.js";function m(e,t){if(!t.stippleEnabled){e.fragment.code.add(a`float getStippleAlpha(float lineWidth) { return 1.0; }
|
|
3
3
|
void discardByStippleAlpha(float stippleAlpha, float threshold) {}
|
|
4
|
-
vec4 blendStipple(vec4 color, float stippleAlpha) { return color; }`);return}let
|
|
4
|
+
vec4 blendStipple(vec4 color, float stippleAlpha) { return color; }`);return}let m=!(t.draped&&t.stipplePreferContinuous),{vertex:_,fragment:v}=e;t.draped||(p(_,t),_.uniforms.add(l).code.add(a`float computeWorldToScreenRatio(vec3 segmentCenter) {
|
|
5
5
|
float segmentDistanceToCamera = length(segmentCenter - cameraPosition);
|
|
6
6
|
return worldToScreenPerDistanceRatio / segmentDistanceToCamera;
|
|
7
|
-
}`)),e.varyings.add(`vStippleDistance`,`float`),e.varyings.add(`vStippleLimitsAndCaps`,`vec4`),e.varyings.add(`vStipplePatternStretch`,`float`),
|
|
7
|
+
}`)),e.varyings.add(`vStippleDistance`,`float`),e.varyings.add(`vStippleLimitsAndCaps`,`vec4`),e.varyings.add(`vStipplePatternStretch`,`float`),_.code.add(a`
|
|
8
8
|
float discretizeStippleDistanceToScreenRatio(float stippleDistanceToScreenRatio) {
|
|
9
|
-
float step = ${a.float(
|
|
9
|
+
float step = ${a.float(g)};
|
|
10
10
|
|
|
11
11
|
float discreteStippleDistanceToScreenRatio = log(stippleDistanceToScreenRatio);
|
|
12
12
|
discreteStippleDistanceToScreenRatio = ceil(discreteStippleDistanceToScreenRatio / step) * step;
|
|
13
13
|
discreteStippleDistanceToScreenRatio = exp(discreteStippleDistanceToScreenRatio);
|
|
14
14
|
return discreteStippleDistanceToScreenRatio;
|
|
15
15
|
}
|
|
16
|
-
`),
|
|
16
|
+
`),_.uniforms.add(u).code.add(a`
|
|
17
17
|
vec2 computeStippleDistanceLimits(float startPseudoScreen, float segmentLengthPseudoScreen, float segmentLengthScreen, float patternLength) {
|
|
18
18
|
|
|
19
19
|
// First check if the segment is long enough to support fully screen space patterns.
|
|
20
20
|
// Force sparse mode for segments that are very large in screen space even if it is not allowed,
|
|
21
21
|
// to avoid imprecision from calculating with large floats.
|
|
22
|
-
if (segmentLengthPseudoScreen >= ${
|
|
22
|
+
if (segmentLengthPseudoScreen >= ${m?`patternLength`:`1e4`}) {
|
|
23
23
|
// Round the screen length to get an integer number of pattern repetitions (minimum 1).
|
|
24
24
|
float repetitions = segmentLengthScreen / (patternLength * pixelRatio);
|
|
25
25
|
float flooredRepetitions = max(1.0, floor(repetitions + 0.5));
|
|
@@ -35,7 +35,7 @@ return worldToScreenPerDistanceRatio / segmentDistanceToCamera;
|
|
|
35
35
|
}
|
|
36
36
|
return vec2(startPseudoScreen, startPseudoScreen + segmentLengthPseudoScreen);
|
|
37
37
|
}
|
|
38
|
-
`),
|
|
38
|
+
`),v.uniforms.add(new s(`stipplePatternTexture`,e=>e.stippleTexture),new i(`stipplePatternPixelSizeInv`,e=>1/h(e))),t.stippleOffColorEnabled&&v.uniforms.add(new r(`stippleOffColor`,e=>n(e.stippleOffColor))),e.include(f);let y=t.worldSized&&t.imagePattern,{usePerspectiveCorrectStipple:b}=t,x=c(t.output)&&!t.worldSized;b&&e.varyings.add(`vStipplePerspective`,`vec4`),x&&e.varyings.add(`vStippleViewInverseW`,`vec2`),y?(e.varyings.add(`vStippleV`,`float`),e.fragment.include(d),v.code.add(a`vec4 getStippleColor(out bool isClamped) {
|
|
39
39
|
vec2 aaCorrectedLimits = vStippleLimitsAndCaps.xy + vec2(1.0, -1.0) / gl_FragCoord.w;
|
|
40
40
|
isClamped = (vStippleLimitsAndCaps.z <= 0.0 && vStippleDistance < aaCorrectedLimits.x) ||
|
|
41
41
|
(vStippleLimitsAndCaps.w <= 0.0 && vStippleDistance > aaCorrectedLimits.y);
|
|
@@ -60,7 +60,7 @@ int mixMode = 1;
|
|
|
60
60
|
vec3 col = mixExternalColor(color.rgb, vec3(1.0), stippleColor.rgb, mixMode);
|
|
61
61
|
float opacity = mixExternalOpacity(color.a, 1.0, stippleColor.a, mixMode);
|
|
62
62
|
return vec4(col, opacity);
|
|
63
|
-
}`)):
|
|
63
|
+
}`)):v.code.add(a`
|
|
64
64
|
float getStippleSDF(out bool isClamped) {
|
|
65
65
|
${o(t.worldSized,a`
|
|
66
66
|
float unclampedStippleDistance = noPerspectiveRead(vStippleDistance);
|
|
@@ -70,6 +70,15 @@ return vec4(col, opacity);
|
|
|
70
70
|
bool clampStart = vStippleLimitsAndCaps.z <= 0.0;
|
|
71
71
|
bool clampEnd = vStippleLimitsAndCaps.w <= 0.0;
|
|
72
72
|
float stippleDistance = vStippleDistance;
|
|
73
|
+
${o(x,a`
|
|
74
|
+
// The light-facing caster interpolates in world space; screen-sized patterns still follow view-space progress.
|
|
75
|
+
vec2 limits = vStippleLimitsAndCaps.xy;
|
|
76
|
+
float segmentLength = limits.y - limits.x;
|
|
77
|
+
float factor = segmentLength > 0.0 ? (stippleDistance - limits.x) / segmentLength : 0.0;
|
|
78
|
+
vec2 inverseW = vStippleViewInverseW;
|
|
79
|
+
float viewFactor = factor * inverseW.x / mix(inverseW.y, inverseW.x, factor);
|
|
80
|
+
stippleDistance = mix(limits.x, limits.y, viewFactor);
|
|
81
|
+
`)}
|
|
73
82
|
if (clampStart) {
|
|
74
83
|
stippleDistance = max(stippleDistance, vStippleLimitsAndCaps.x);
|
|
75
84
|
}
|
|
@@ -79,7 +88,7 @@ return vec4(col, opacity);
|
|
|
79
88
|
stippleDistance = noPerspectiveRead(stippleDistance);
|
|
80
89
|
float lineSizeInv = noPerspectiveRead(vLineSizeInv);
|
|
81
90
|
|
|
82
|
-
${o(
|
|
91
|
+
${o(b,a`
|
|
83
92
|
// Convert screen-space progress to progress along the 3D segment using the endpoints' inverse clip-W values.
|
|
84
93
|
// This keeps dash lengths constant in world units, so farther dashes appear shorter on screen.
|
|
85
94
|
vec4 stipplePerspective = noPerspectiveRead(vStipplePerspective);
|
|
@@ -90,7 +99,7 @@ return vec4(col, opacity);
|
|
|
90
99
|
stippleDistance = mix(stipplePerspective.x, stipplePerspective.y, perspectiveFactor);
|
|
91
100
|
`)}
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
vec2 aaCorrectedLimits = vStippleLimitsAndCaps.xy + vec2(1.0, -1.0) * stippleDistancePerPixel / noPerspectiveRead(1.0);
|
|
94
103
|
isClamped = (clampStart && vStippleDistance < aaCorrectedLimits.x) ||
|
|
95
104
|
(clampEnd && vStippleDistance > aaCorrectedLimits.y);
|
|
96
105
|
|
|
@@ -117,7 +126,7 @@ return vec4(col, opacity);
|
|
|
117
126
|
vec4 blendStipple(vec4 color, float stippleAlpha) {
|
|
118
127
|
return ${t.stippleOffColorEnabled?`mix(color, stippleOffColor, stippleAlpha)`:`vec4(color.rgb, color.a * stippleAlpha)`};
|
|
119
128
|
}
|
|
120
|
-
`),
|
|
129
|
+
`),v.code.add(a`
|
|
121
130
|
float getStippleCapDistance() {
|
|
122
131
|
return (getStippleSDF() * 2.0 - 1.0) * vStipplePatternStretch;
|
|
123
132
|
}
|
|
@@ -125,4 +134,4 @@ return vec4(col, opacity);
|
|
|
125
134
|
void discardByStippleAlpha(float stippleAlpha, float threshold) {
|
|
126
135
|
${o(!t.stippleOffColorEnabled,`if (stippleAlpha < threshold) { discard; }`)}
|
|
127
136
|
}
|
|
128
|
-
`)}function
|
|
137
|
+
`)}function h(n){let r=n.stipplePattern;return e(r)?r.length:r?t(r)/r.pixelRatio:1}const g=.4;export{m as LineStipple,h as computePixelSize};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{translate as e}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as t}from"../../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as n}from"../../../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as r,create as i}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Float3BindUniform as a}from"../../shaderModules/Float3BindUniform.js";import{Float3DrawUniform as o}from"../../shaderModules/Float3DrawUniform.js";import{Matrix4BindUniform as s}from"../../shaderModules/Matrix4BindUniform.js";import{Matrix4DrawUniform as c}from"../../shaderModules/Matrix4DrawUniform.js";import{projMatrix as l}from"./cameraUniforms.js";function u(e,t){t.instancedDoublePrecision?e.constants.add(`cameraPosition`,`vec3`,r):e.uniforms.add(new o(`cameraPosition`,({origin:e},{
|
|
2
|
+
import{translate as e}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as t}from"../../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as n}from"../../../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as r,create as i}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Float3BindUniform as a}from"../../shaderModules/Float3BindUniform.js";import{Float3DrawUniform as o}from"../../shaderModules/Float3DrawUniform.js";import{Matrix4BindUniform as s}from"../../shaderModules/Matrix4BindUniform.js";import{Matrix4DrawUniform as c}from"../../shaderModules/Matrix4DrawUniform.js";import{projMatrix as l}from"./cameraUniforms.js";function u(e,t){t.instancedDoublePrecision?e.constants.add(`cameraPosition`,`vec3`,r):e.uniforms.add(new o(`cameraPosition`,({origin:e},{viewCamera:t})=>n(g,t.viewInverseTransposeMatrix[3]-e[0],t.viewInverseTransposeMatrix[7]-e[1],t.viewInverseTransposeMatrix[11]-e[2])))}function d(e,t){f(e,t),p(e,t)}function f(t,n){t.uniforms.add(l,n.instancedDoublePrecision?new s(`view`,t=>e(h,t.camera.viewMatrix,m(t))):new c(`view`,(t,n)=>e(h,n.camera.viewMatrix,t.origin)))}function p(e,t){e.uniforms.add(t.instancedDoublePrecision?new a(`localOrigin`,e=>m(e)):new o(`localOrigin`,({origin:e})=>e))}function m({camera:e}){return n(g,e.viewInverseTransposeMatrix[3],e.viewInverseTransposeMatrix[7],e.viewInverseTransposeMatrix[11])}const h=t(),g=i();export{u as addCameraPosition,p as addLocalOrigin,f as addProjView,d as addProjViewLocalOrigin};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import"../../../../webgl/ShaderBuilder.js";import"../../core/shaderLibrary/bindUniforms.js";import"../../core/shaderLibrary/output/ReadDepth.glsl.js";import"../../core/shaderLibrary/shading/Gamma.glsl.js";import"../../core/shaderLibrary/util/ColorConversion.glsl.js";import"../../core/shaderModules/Float3PassUniform.js";import"../../core/shaderModules/FloatPassUniform.js";import"../../core/shaderModules/glsl.js";import"../../core/shaderModules/Texture2DPassUniform.js";import"../../shaders/ScreenSpacePassAtmosphere.glsl.js";import"../../shaders/ToneMapping.glsl.js";import"../glow/applyEmissiveGlow.glsl.js";import"../raymarching/DistanceFalloff.glsl.js";export{F as FogPassParameters,b as build}from"../../../../../chunks/Fog.glsl.js";
|
|
2
|
+
import"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import"../../../../webgl/ShaderBuilder.js";import"../../core/shaderLibrary/bindUniforms.js";import"../../core/shaderLibrary/output/ReadDepth.glsl.js";import"../../core/shaderLibrary/shading/Gamma.glsl.js";import"../../core/shaderLibrary/util/ColorConversion.glsl.js";import"../../core/shaderModules/Float3PassUniform.js";import"../../core/shaderModules/FloatPassUniform.js";import"../../core/shaderModules/glsl.js";import"../../core/shaderModules/Texture2DPassUniform.js";import"../../../../../chunks/EmissionComposite.glsl.js";import"../../shaders/ScreenSpacePassAtmosphere.glsl.js";import"../../shaders/ToneMapping.glsl.js";import"../glow/applyEmissiveGlow.glsl.js";import"../raymarching/DistanceFalloff.glsl.js";export{F as FogPassParameters,b as build}from"../../../../../chunks/Fog.glsl.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import"../../../../../core/arrayUtils.js";import"../../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import"../../../../../core/mathUtils.js";import"../../../../webgl/NoParameters.js";import"../../../../webgl/ShaderBuilder.js";import"../../core/shaderLibrary/bindUniforms.js";import"../../core/shaderLibrary/output/ReadDepth.glsl.js";import"../../core/shaderLibrary/ScreenSpacePass.glsl.js";import"../../core/shaderLibrary/shading/Gamma.glsl.js";import"../../core/
|
|
2
|
+
import"../../../../../core/arrayUtils.js";import"../../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import"../../../../../core/mathUtils.js";import"../../../../webgl/NoParameters.js";import"../../../../webgl/ShaderBuilder.js";import"../../core/shaderLibrary/bindUniforms.js";import"../../core/shaderLibrary/output/ReadDepth.glsl.js";import"../../core/shaderLibrary/ScreenSpacePass.glsl.js";import"../../core/shaderLibrary/shading/Gamma.glsl.js";import"../../core/shaderModules/BooleanDrawUniform.js";import"../../core/shaderModules/Float2DrawUniform.js";import"../../core/shaderModules/FloatDrawUniform.js";import"../../core/shaderModules/glsl.js";import"../../core/shaderModules/Texture2DDrawUniform.js";export{B as BlurEmissionDrawParameters,b as build}from"../../../../../chunks/BlurEmission.glsl.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../environment/FoggyWeather.js";import{mainDepth as n}from"../../core/shaderLibrary/bindUniforms.js";import{ReadDepth as r}from"../../core/shaderLibrary/output/ReadDepth.glsl.js";import{
|
|
3
|
-
vec4 readEmission(float level, float
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../environment/FoggyWeather.js";import{mainDepth as n}from"../../core/shaderLibrary/bindUniforms.js";import{ReadDepth as r}from"../../core/shaderLibrary/output/ReadDepth.glsl.js";import{FloatBindUniform as i}from"../../core/shaderModules/FloatBindUniform.js";import{FloatPassUniform as a}from"../../core/shaderModules/FloatPassUniform.js";import{If as o,glsl as s}from"../../core/shaderModules/glsl.js";import{Texture2DPassUniform as c}from"../../core/shaderModules/Texture2DPassUniform.js";import{parameter as l}from"../../core/shaderTechnique/ShaderTechniqueConfiguration.js";import{FloatBlendScaleConfiguration as u,floatBlendScale as d}from"../../shaders/floatBlendScale.glsl.js";import{ToneMapping as f}from"../../shaders/ToneMapping.glsl.js";import{DistanceFalloffPassParameters as p,getDistanceFalloff as m}from"../raymarching/DistanceFalloff.glsl.js";class h extends p{constructor(){super(...arguments),this.mipmapLevels=1,this.boost=1,this.scattering=1e-4}}class g extends u{constructor(){super(...arguments),this.hasFog=!1}}e([l()],g.prototype,`hasFog`,void 0);function _(e,l){e.include(d,l),e.include(m),e.include(r),e.include(f),e.uniforms.add(new c(`emissionTexture`,({emission:e})=>e?.attachment),new i(`emissionFade`,e=>e.emissionFade),n,new a(`scattering`,({scattering:e})=>e),new a(`boost`,({boost:e})=>1+e*.5),new a(`levels`,({mipmapLevels:e},{camera:t})=>e+1+Math.log2(t.pixelScale)),new i(`pixelRatioCorrection`,({camera:e})=>Math.log2(e.pixelScale)),new c(`mipmapTexture`,({mipmapTexture:e})=>e?.getTexture())).constants.add(`maxScattering`,`float`,t.maxScattering).constants.add(`weightEpsilon`,`float`,.01).code.add(s`
|
|
3
|
+
vec4 readEmission(float level, float reciprocalDepth) {
|
|
4
4
|
level *= levels;
|
|
5
5
|
level = max(0.0, level - pixelRatioCorrection);
|
|
6
6
|
if (level < 1.0) {
|
|
7
7
|
vec3 emission = texture(emissionTexture, uv).rgb * floatBlendInputScale;
|
|
8
|
-
vec4 unblurred = vec4(emission,
|
|
8
|
+
vec4 unblurred = vec4(emission, reciprocalDepth * dot(emission, vec3(1.0 / 3.0)));
|
|
9
9
|
return unblurred * (1.0 - level) + textureLod(mipmapTexture, uv, 0.0) * level * 0.5;
|
|
10
10
|
}
|
|
11
11
|
return textureLod(mipmapTexture, uv, level - 1.0) / pow(2.0, level);
|
|
@@ -15,16 +15,17 @@ import{__decorate as e}from"tslib";import t from"../../../environment/FoggyWeath
|
|
|
15
15
|
float expon = -(pow(x, 2.0) / (2.0 * sigmaSq));
|
|
16
16
|
return exp(expon) / sqrt(6.283185307179586 * sigmaSq);
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
vec3 applyEmissiveGlow() {
|
|
18
|
+
vec3 applyEmissiveGlow(float extinctionAmount, float maxDispersion) {
|
|
20
19
|
float depth = -1.0;
|
|
21
|
-
float
|
|
20
|
+
float surfaceDepth = -1.0;
|
|
21
|
+
float reciprocalDepth = 0.0;
|
|
22
22
|
float depthSample = depthFromTexture(mainDepth, uv);
|
|
23
23
|
if(depthSample < 1.0 && depthSample > 0.0){
|
|
24
|
-
|
|
24
|
+
surfaceDepth = -linearizeDepth(depthSample);
|
|
25
|
+
reciprocalDepth = 1.0 / (1.0 + surfaceDepth);
|
|
25
26
|
vec3 cameraSpaceRay = normalize(eyeDir);
|
|
26
27
|
cameraSpaceRay /= cameraSpaceRay.z;
|
|
27
|
-
cameraSpaceRay *=
|
|
28
|
+
cameraSpaceRay *= -surfaceDepth;
|
|
28
29
|
depth = max(0.0, length(cameraSpaceRay));
|
|
29
30
|
}
|
|
30
31
|
vec3 rayDir = normalize(worldRay);
|
|
@@ -48,12 +49,16 @@ import{__decorate as e}from"tslib";import t from"../../../environment/FoggyWeath
|
|
|
48
49
|
float dist = point - mainPoint;
|
|
49
50
|
float weight = gauss(dist, sigmaSq) * smoothstep(minPoint, fullPoint, point);
|
|
50
51
|
if(weight > weightEpsilon) {
|
|
51
|
-
vec4 emissionSample = readEmission(point,
|
|
52
|
-
${
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
float
|
|
56
|
-
|
|
52
|
+
vec4 emissionSample = readEmission(point, reciprocalDepth);
|
|
53
|
+
${o(l.hasFog,s`
|
|
54
|
+
if (surfaceDepth >= 0.0) {
|
|
55
|
+
float intensity = dot(emissionSample.rgb, vec3(1.0 / 3.0));
|
|
56
|
+
float depthNumerator = intensity - emissionSample.a;
|
|
57
|
+
if (depthNumerator > 0.0) {
|
|
58
|
+
// Decoded depth is intensity / alpha - 1. Form surfaceDepth / decodedDepth without
|
|
59
|
+
// dividing by alpha: sky emission (alpha = 0) is rejected without producing infinity or NaN.
|
|
60
|
+
emissionSample.rgb *= mix(1.0, min(1.0, surfaceDepth * emissionSample.a / depthNumerator), extinctionAmount);
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
`)}
|
|
59
64
|
emission += emissionSample.rgb * weight;
|
|
@@ -62,4 +67,4 @@ import{__decorate as e}from"tslib";import t from"../../../environment/FoggyWeath
|
|
|
62
67
|
}
|
|
63
68
|
return emission * boost / weights * emissionFade;
|
|
64
69
|
}
|
|
65
|
-
`)}export{
|
|
70
|
+
`)}export{g as EmissiveGlowConfiguration,h as EmissiveGlowPassParameters,_ as applyEmissiveGlow};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import"tslib";import"../../../webgl/ShaderBuilder.js";import"../core/shaderLibrary/shading/Gamma.glsl.js";import"../core/shaderModules/FloatBindUniform.js";import"../core/shaderModules/glsl.js";import"../core/shaderModules/Texture2DPassUniform.js";import"../core/shaderTechnique/ShaderTechniqueConfiguration.js";import"../effects/glow/applyEmissiveGlow.glsl.js";import"../shaders/floatBlendScale.glsl.js";import"../shaders/ScreenSpacePassAtmosphere.glsl.js";import"../shaders/ToneMapping.glsl.js";export{a as EmissionCompositePassParameters,E as EmissionCompositeTechniqueConfiguration,c as build}from"../../../../chunks/EmissionComposite.glsl.js";
|
|
2
|
+
import"tslib";import"../../../webgl/ShaderBuilder.js";import"../core/shaderLibrary/shading/Gamma.glsl.js";import"../core/shaderModules/FloatBindUniform.js";import"../core/shaderModules/glsl.js";import"../core/shaderModules/Texture2DPassUniform.js";import"../core/shaderTechnique/ShaderTechniqueConfiguration.js";import"../effects/glow/applyEmissiveGlow.glsl.js";import"../shaders/floatBlendScale.glsl.js";import"../shaders/ScreenSpacePassAtmosphere.glsl.js";import"../shaders/ToneMapping.glsl.js";export{a as EmissionCompositePassParameters,E as EmissionCompositeTechniqueConfiguration,c as build,h as hazeDispersion}from"../../../../chunks/EmissionComposite.glsl.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{subtract as e}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{estimateNumberArrayMemory as n,estimateNestedObjectMemory as r}from"../../../../core/memoryEstimations.js";import{isFloat32Array as i}from"../../../../core/typedArrayUtil.js";import{newDoubleArray as a}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as o}from"../../../../geometry/support/FloatArray.js";import{noBudget as s}from"../../../support/Scheduler.js";import{intersectRayTriangles as c}from"./RayIntersections.js";class l{constructor(e,t,n,r){this.firstTriangle=e,this.numTriangles=t,this.nodeOffset=n,this.leafCount=r}}class u{constructor(e,t,n,r=!1,c=[]){this.indices=e,this.numTriangles=t,this.positions=n,this._nextRange=0,this._nextLeaf=0,this._ranges=[];let
|
|
2
|
+
import{subtract as e}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{estimateNumberArrayMemory as n,estimateNestedObjectMemory as r}from"../../../../core/memoryEstimations.js";import{isFloat32Array as i}from"../../../../core/typedArrayUtil.js";import{newDoubleArray as a}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as o}from"../../../../geometry/support/FloatArray.js";import{noBudget as s}from"../../../support/Scheduler.js";import{intersectRayTriangles as c}from"./RayIntersections.js";class l{constructor(e,t,n,r,i){this.firstTriangle=e,this.numTriangles=t,this.nodeOffset=n,this.leafCount=r,this.triangleOrder=i}}class u{constructor(e,t,n,r=!1,c=[],u=[]){this.indices=e,this.numTriangles=t,this.positions=n,this._nextRange=0,this._nextLeaf=0,this._ranges=[];let d=0,f=0;for(let e=0;e<=c.length;e++){let n=e<c.length?c[e]:t;if(n===d)continue;let r=n-d,i=2**Math.ceil(Math.log2(Math.ceil(r/32)));this._ranges.push(new l(d,r,f,i,u[e])),d=n,f+=2*i-1}this._bounds=i(n.data)?o(f*6,!0):a(f*6),this._nextParent=this._ranges.length?this._ranges[0].leafCount-2:-1,r||this.advance(s)}advance(e){let{indices:t,positions:n,_bounds:r}=this,{data:i,stride:a}=n;for(;this._nextRange<this._ranges.length&&!e.done;){let{firstTriangle:n,numTriangles:o,nodeOffset:s,leafCount:c,triangleOrder:l}=this._ranges[this._nextRange],u=c-1;for(;this._nextLeaf<c&&!e.done;){let d=this._nextLeaf++,f=n+Math.floor(d*o/c),p=n+Math.floor((d+1)*o/c),m=(s+u+d)*6,h=1/0,g=1/0,_=1/0,v=-1/0,y=-1/0,b=-1/0;for(let e=f;e<p;e++){let r=l?n+l[e-n]:e;for(let e=0;e<3;e++){let n=t[r*3+e]*a,o=i[n],s=i[n+1],c=i[n+2];h=Math.min(h,o),g=Math.min(g,s),_=Math.min(_,c),v=Math.max(v,o),y=Math.max(y,s),b=Math.max(b,c)}}r[m]=h,r[m+1]=g,r[m+2]=_,r[m+3]=v,r[m+4]=y,r[m+5]=b,e.madeProgress()}for(;this._nextLeaf===c&&this._nextParent>=0&&!e.done;){let t=Math.max(0,this._nextParent-16+1);for(;this._nextParent>=t;){let e=this._nextParent--,t=(s+e)*6,n=(s+e*2+1)*6,i=n+6;for(let e=0;e<3;e++)r[t+e]=Math.min(r[n+e],r[i+e]),r[t+e+3]=Math.max(r[n+e+3],r[i+e+3])}e.madeProgress()}this._nextLeaf===c&&this._nextParent<0&&(this._nextRange++,this._nextLeaf=0,this._nextParent=this._nextRange<this._ranges.length?this._ranges[this._nextRange].leafCount-2:-1)}}get ready(){return this._nextRange===this._ranges.length}get estimatedMemoryUsage(){return n(this._bounds)+r(this._ranges)}intersectRay(n,r,i,a){this.ready||this.advance(s);let o=e(t(),r,n);if(this.numTriangles===0||o[0]**2+o[1]**2+o[2]**2<1e-6)return;let l=[];for(let e=this._ranges.length-1;e>=0;e--){let{firstTriangle:t,numTriangles:r,nodeOffset:s,leafCount:u,triangleOrder:f}=this._ranges[e],p=u-1;for(l.push(0);l.length;){let e=l.pop();if(!d(this._bounds,(s+e)*6,n,o,i.tolerance))continue;if(e<p){l.push(e*2+1,e*2+2);continue}let m=e-p;c(n,o,Math.floor(m*r/u),Math.floor((m+1)*r/u),this.indices,this.positions.data,this.positions.stride,i.normalRequired,a,f,t)}}}}function d(e,t,n,r,i){let a=0,o=1/0;for(let s=0;s<3;s++){let c=e[t+s]-i,l=e[t+s+3]+i,u=n[s],d=r[s];if(d===0){if(u<c||u>l)return!1;continue}let f=(c-u)/d,p=(l-u)/d;if(a=Math.max(a,Math.min(f,p)),o=Math.min(o,Math.max(f,p)),a>o)return!1}return!0}export{u as TriangleRangeBVH};
|