UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 19.2 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{isSome as r,disposeMaybe as s,isNone as n}from"../../../core/maybe.js";import o from"../../../core/ObjectPool.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{I as h}from"../../../chunks/mat4f64.js";import{b as c,s as d,e as u}from"../../../chunks/vec3.js";import{Z as p,f,c as _}from"../../../chunks/vec3f64.js";import{Z as g}from"../../../chunks/vec4f64.js";import{create as m,set as b}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as y}from"../../../geometry/support/buffer/BufferView.js";import{ViewingMode as T}from"../../ViewingMode.js";import{TextureUpdate as R}from"./interfaces.js";import{LayerClass as v}from"./LayerClass.js";import{OverlaySource as O}from"./Overlay.js";import{overlayRenderOccludedFlag as x}from"./OverlayRenderer.js";import{clearCaches as C}from"./PatchGeometry.js";import{PatchRenderData as D}from"./PatchRenderData.js";import{RenderOrder as P}from"./RenderOrder.js";import{ENABLE_TERRAIN_INTERNAL_CHECKS as S}from"./terrainUtils.js";import{TileRenderer as q}from"./TileRenderer.js";import{TileUpdate as E}from"./TileUpdate.js";import{IteratorPreorder as A,sortTiles as w,compareTiles as N}from"./tileUtils.js";import{componentMinimalSizeForIntersectionData as j,ComponentIntersectionData as G}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as I}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{OverlayMode as L}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{T as F}from"../../../chunks/Terrain.glsl.js";import{TileBlendInput as U}from"../webgl-engine/core/shaderLibrary/terrain/TileBlendInput.js";import{Attribute as k}from"../webgl-engine/lib/Attribute.js";import{RenderRequestType as B}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as M}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as z}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as H,StoreResults as V}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as W}from"../webgl-engine/lib/Material.js";import{RenderSlot as Y}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as Q}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as X}from"../webgl-engine/lib/VertexAttribute.js";import{TERRAIN_ID as Z,getVerticalOffsetTerrain as K}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as J}from"../webgl-engine/materials/DrawParameters.js";import{intersectAabbInvDirBefore as $,intersectTriangles as ee}from"../webgl-engine/materials/internal/MaterialUtil.js";import{TerrainTechnique as te}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as ie}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as re}from"../../webgl/enums.js";const se=7,ne=10,oe=m();var ae;!function(e){e[e.Opaque=0]="Opaque",e[e.Semitransparent=1]="Semitransparent",e[e.TransparentWithDraped=2]="TransparentWithDraped",e[e.Empty=3]="Empty"}(ae||(ae={}));let le=class extends i{get _isGlobal(){return this._stage.viewingMode===T.Global}get shading(){return this._techniqueConfiguration.shading}set shading(e){this._techniqueConfiguration.shading=e}constructor(e){super(e),this.type=H.TERRAIN,this.isGround=!0,this._tileSize=256,this._techniqueConfiguration=new ie,this._passParameters=new F,this._rctx=null,this._renderDataPool=new o(D),this._patchGroups=new Map,this._patchGroupsDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new A,this._highestVisibleLODTile=null,this._visible=!0,this._transparencyState=ae.Opaque,this._velvetOverground=!0,this._castShadows=!0,this._emptyTex=null,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.needsHighlight=!1,this.renderOccludedFlags=W.Occlude}initialize(){const e=[Y.OPAQUE_TERRAIN,Y.TRANSPARENT_TERRAIN,Y.OCCLUDED_TERRAIN];this._stage.addRenderPlugin(e,this)}destroy(){this._stage.removeRenderPlugin(this),C()}get canRender(){return this._visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set transparency(e){this._transparencyState!==e&&(this._techniqueConfiguration.invisible=e===ae.TransparentWithDraped||e===ae.Empty,this._transparencyState=e,this.setNeedsRender())}get transparency(){return this._transparencyState}get needsLinearDepth(){return this._overlayRenderer.hasWater}get renderPatchBorders(){return!!this._techniqueConfiguration.tileBorders}set renderPatchBorders(e){this._techniqueConfiguration.tileBorders!==e&&(this._techniqueConfiguration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get visualizeNormals(){return!!this._techniqueConfiguration.visualizeNormals}set visualizeNormals(e){this._techniqueConfiguration.visualizeNormals!==e&&(this._techniqueConfiguration.visualizeNormals=e,this.setNeedsRender(),this.notifyChange("visualizeNormals"))}get cullBackFaces(){return this._techniqueConfiguration.backfaceCullingEnabled}set cullBackFaces(e){this._techniqueConfiguration.backfaceCullingEnabled!==e&&(this._techniqueConfiguration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this._setSortingDirty()}set velvetOverground(e){this._velvetOverground!==e&&(this._velvetOverground=e,this.setNeedsRender())}get layerUid(){return Z}get slicePlaneEnabled(){return this._techniqueConfiguration.hasSlicePlane}set slicePlaneEnabled(e){this._techniqueConfiguration.hasSlicePlane!==e&&(this._techniqueConfiguration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._techniqueConfiguration.textureFadingEnabled!==e&&(this._techniqueConfiguration.textureFadingEnabled=e,this.setNeedsRender())}set pbrMode(e){this._techniqueConfiguration.pbrMode!==e&&(this._techniqueConfiguration.pbrMode=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._techniqueConfiguration.screenSizePerspective!==e&&(this._techniqueConfiguration.screenSizePerspective=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setNeedsHighlight(e){this.needsHighlight=e,this.setNeedsRender()}setRenderOccludedOverlay(e){this.renderOccludedFlags=e?x:W.Occlude,this.setNeedsRender()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}setTileSize(e){this._tileSize=e,r(this._tileRenderer)&&(this._tileRenderer.tileSize=e),this.setDirty()}_prepareTileForLoading(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e),e.renderData.localOrigin=this._getLocalOriginOfTile(e))}loadTile(e){this._prepareTileForLoading(e),this.updateTileGeometryState(e),this.updateTileTexture(e,E.TEXTURE_FADING)}updateTileTexture(e,t){r(this._tileRenderer)&&(this._tileRenderer.updateTileTexture(e,t===E.TEXTURE_FADING?R.FADING:R.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(const i of e.layerInfo[v.ELEVATION])i.pendingUpdates&=~E.GEOMETRY;e.resetPendingUpdate(E.GEOMETRY);const t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.isLoaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){const t=ne-se,i=Math.max(0,Math.floor((e.level-t)/se)*se);if(this._isGlobal&&0===i)return p;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}setVisibility(e){this._visible=e,this.setDirty()}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.setNeedsRender())}setDirty(e=B.UPDATE){this._patchGroupsDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=B.UPDATE){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=B.UPDATE){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._rctx=e.renderContext.rctx,this._techniqueRepository=e.techniqueRepository,this._tileRenderer=new q(this._rctx,this._tileSize,this._techniqueRepository),this.updateTileBackground(),this._emptyTex=M(this._rctx)}uninitializeRenderContext(){this._emptyTex=s(this._emptyTex),this._tileRenderer=s(this._tileRenderer)}intersect(e,t,i,s){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==ae.Opaque)return;const o=he,a=ce;c(o,s,i),d(a,1/o[0],1/o[1],1/o[2]);const l=e.results.min,p=e.results.max,f=e.results.ground,_=e.options.store===V.MIN,g=!!e.results.ground.target,m=K(e.verticalOffset),T=e.tolerance;let R,v=_&&r(l.dist)?l.dist:1/0;const O=d=>{const g=d.renderData;if(!g?.vao)return;const O=g.geometryInfo;b(oe,O.boundingBox);const x=g.localOrigin;r(m)&&(m.localOrigin=x,m.applyToAabb(oe));const C=oe;if(de[0]=i[0]-x[0],de[1]=i[1]-x[1],de[2]=i[2]-x[2],!$(C,de,a,T,v))return;const D=(e,t,i)=>{e.set(this.type,d,t,i,h),v=_&&r(l.dist)?l.dist:1/0},P=(a,h)=>{if(r(h)&&a>=0&&(e.options.backfacesTerrain||u(h,o)<0)&&(e.options.invisibleTerrain||!e.options.selectionMode||null==t||t(i,s,a))){if((null==f.dist||a<f.dist)&&D(f,a,h),e.options.isFiltered)return;e.options.store===V.ALL&&(n(R)?(R=z(e.ray),D(R,a,h),e.results.all.push(R)):a<R.dist&&D(R,a,h)),(null==l.dist||a<l.dist)&&D(l,a,h),e.options.store!==V.MIN&&(null==p.dist||a>p.dist)&&D(p,a,h)}},S=ue;c(S,s,x);const q=O.indices,E=O.vertexAttributes,A=E.getField(X.POSITION,y),w=new k(A.typedBuffer,3,!1,E.stride/4),N=O.indexCount/3;if(n(m)&&N>j){const e=d.renderData;n(e.intersectionData)&&(e.intersectionData=new G(q,0,N,w)),e.intersectionData.intersectRay({r0:de,r1:S},P)}else ee(de,S,0,N,q,w,null,m,P)},x=this._rootTiles;if(r(x)){(()=>{const t=this._tileIterator;t.reset(x);const s=e.options.invisibleTerrain;for(let e=t.next();e;e=t.next())!(e.visible||s&&e.intersectsClippingArea)||!r(m)&&!e.intersectsRay(i,o,T,v)||g&&this._useStencilForTile(e)?t.skipSubtree():O(e)})()}}processScaleRangeQueries(e,t){if(!t.done)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(const t of this._patchGroups.values())for(const i of t)r(i.renderData?.textureReference)&&e.queriesForTile(i);e.process(),t.madeProgress()}}prepareTechnique(e){if(e.bindParameters.slot===Y.OCCLUDED_TERRAIN){if(0==(e.renderOccludedMask&x))return null}else{const t=this.transparency===ae.Opaque?Y.OPAQUE_TERRAIN:Y.TRANSPARENT_TERRAIN;if(e.bindParameters.slot!==t)return null}switch(e.output){case I.Color:return this.transparency===ae.Empty?null:(this._techniqueConfiguration.hasScreenSpaceReflections=e.bindParameters.ssr.enabled,this._techniqueConfiguration.hasCloudsReflections=r(e.bindParameters.cloudsFade.data),this._techniqueConfiguration.receiveShadows=e.bindParameters.shadowMap.ready,this._techniqueConfiguration.receiveAmbientOcclusion=e.bindParameters.ssaoHelper.active,this._techniqueConfiguration.overlayMode=this._overlayRenderer.isEmpty?L.Disabled:this._overlayRenderer.hasWater?L.EnabledWithWater:L.Enabled,this._updateTechnique(I.Color,e.bindParameters.slot===Y.OCCLUDED_TERRAIN));case I.Shadow:case I.ShadowExcludeHighlight:return this._castShadows&&1===e.bindParameters.lighting.globalFactor?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(I.Shadow,!1)):null;case I.Depth:return this.transparency===ae.Empty?null:(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(I.Depth,!1));case I.Normal:return this.transparency===ae.Empty?null:(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(I.Normal,!1));case I.ObjectAndLayerIdColor:return this.transparency===ae.Empty?null:this._updateTechnique(I.ObjectAndLayerIdColor,!1);case I.Highlight:return this.transparency!==ae.Empty&&this.needsHighlight?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(I.Highlight,!1)):null}return null}render(e,t){const i=1===e.bindParameters.lighting.globalFactor;switch(this._updatePatchGroups(),t.useStencil=!1,e.output){case I.Color:{const i=e.bindParameters.slot===Y.OCCLUDED_TERRAIN?O.Occluded:O.ColorAndWater;this.transparency===ae.Opaque?this._renderMaterialPass(e,t,i):e.offscreenRenderingHelper.renderToTargets((()=>this._renderMaterialPass(e,t,i)),e.offscreenRenderingHelper.tmpColor,e.offscreenRenderingHelper.mainDepth,[0,0,0,0]);break}case I.Depth:case I.Normal:this._renderAuxiliaryPass(e,t,O.None);break;case I.Highlight:this.needsHighlight&&this._renderAuxiliaryPass(e,t,O.Highlight);break;case I.Shadow:case I.ShadowExcludeHighlight:this._castShadows&&i&&this._renderAuxiliaryPass(e,t,O.None);break;case I.ObjectAndLayerIdColor:this._renderAuxiliaryPass(e,t,O.ObjectAndLayerIdColor)}}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this._renderPatchGroups(e,t,i)}_renderAuxiliaryPass(e,t,i){const r=e.rctx;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._renderPatchGroupsAuxiliary(e,t,i)}updateTileBackground(e=null){if(n(this._tileRenderer))return;const i=this._tileRenderer;let s=null;if(r(e)){const i=t.toUnitRGBA(e);s=f(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(s),this._allTiles.forAll((e=>i.updateTileTexture(e,R.FADING))),this._techniqueConfiguration.tileBlendInput=i.backgroundIsGrid?U.GridComposite:r(i.backgroundColor)?U.ColorComposite:U.LayerOnly,this.setNeedsRender()}_updatePatchGroups(){if(this._patchGroupsDirty&&(this._highestVisibleLODTile=null,this._rebuildPatchGroups(),this._patchGroupsDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty&&this.renderOrder!==P.NONE){const e=Array.from(this._patchGroups.values()),t=this._stencilEnabledLayerExtents;for(const i of e)w(this.renderOrder,i,t);e.sort(((e,t)=>N(e[0],t[0],this.renderOrder))),this._patchGroups=new Map(e.map((e=>[e[0].renderData.localOrigin,e]))),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(!n(e)){e[0]?.surface.checkAllTilesWaterproofness(),this._patchGroups.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this._tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i){this._numTilesCulled++;continue}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}const r=i.localOrigin;let s=this._patchGroups.get(r);s||(s=new Array,this._patchGroups.set(r,s)),s.push(e),(!this._highestVisibleLODTile||e.vlevel>this._highestVisibleLODTile.vlevel)&&(this._highestVisibleLODTile=e),t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderPatchGroupsAuxiliary(e,t,i){const r=this._stencilEnabledLayerExtents.length>0;this._patchGroups.forEach((s=>{const n=s[0].renderData.localOrigin;t.program.bindDraw(new J(n),e.bindParameters,this._passParameters);for(let o=0;o<s.length;o++)this._renderPatch(e,t,s[o],re.TRIANGLES,r,i)})),e.rctx.bindVAO(null)}_renderPatchGroups(e,t,i){const s=e.bindParameters.camera,o=t.program;if(this._techniqueConfiguration.screenSizePerspective&&this.pointsOfInterest){const e=Q(this._stage.viewingMode,this._ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:s.fovY})}const a=this._stencilEnabledLayerExtents.length>0,l=i===O.Occluded;l&&(o.bindTexture("tex",this._emptyTex),o.setUniform3fv("textureOpacities",p),o.setUniform4fv("texOffsetAndScale",g));const h=r(this._tileRenderer)&&r(this._tileRenderer.backgroundColor)?this._tileRenderer.backgroundColor:p;this._techniqueConfiguration.tileBlendInput===U.ColorComposite&&o.setUniform3fv("backgroundColor",h);const c=this.wireframe?re.LINES:re.TRIANGLES;this._techniqueConfiguration.textureFadingEnabled&&o.bindTexture("texNext",this._emptyTex);const d=this._patchGroups;for(const u of d.values()){const s=u[0].renderData.localOrigin;t.program.bindDraw(new J(s),e.bindParameters,this._passParameters),this._numOriginsRendered++;for(const h of u){const s=h.renderData,d=s.textureReference;if(!n(d)){if(!l){o.setUniform4fv("texOffsetAndScale",d.offsetAndScale),o.bindTexture("tex",d.texture.texture);const e=s.textureFadeFactor,t=e<1?s.nextTextureReference:null;this._techniqueConfiguration.textureFadingEnabled&&r(t)&&e<1?(o.setUniform1f("fadeFactor",e),o.setUniform4fv("nextTexOffsetAndScale",t.offsetAndScale),o.setUniform3fv("nextTexOpacities",t.opacities),o.bindTexture("texNext",t.texture.texture)):o.setUniform1f("fadeFactor",1),s.textureIsFading&&this.setNeedsRender(),o.setUniform3fv("textureOpacities",d.opacities)}this._renderPatch(e,t,h,c,a,i),h.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}e.rctx.bindVAO(null)}_renderPatch(e,t,i,r,s,o){const a=i.renderData,l=a.vao,h=l.indexBuffer;if(n(h))return void(S&&console.error("Rendered tile with no indices: ",i.lij," : ",a));const c=t.program;o===O.None||this._overlayRenderer.isEmpty||this._bindOverlayPatchData(c,a.overlay),s&&(t.useStencil=this._useStencilForTile(i),t.bindPipelineState(e.rctx,e.bindParameters.slot));const d=a.geometryInfo.indexCount;e.rctx.bindVAO(l),c.assertCompatibleVertexAttributeLocations(l),e.rctx.drawElements(r,d,h.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_updateTechnique(e,t){return this._techniqueConfiguration.output=e,e===I.Color&&(this._techniqueConfiguration.atmosphere=this._isGlobal&&this._velvetOverground),this._techniqueConfiguration.renderOccluded=t,this._techniqueConfiguration.stencilEnabled=!1,this._shaderTechnique=this._techniqueRepository.releaseAndAcquire(te,this._techniqueConfiguration,this._shaderTechnique),this._shaderTechnique}get test(){return{tileRenderer:this._tileRenderer}}};e([a({constructOnly:!0})],le.prototype,"_overlayRenderer",void 0),e([a({constructOnly:!0})],le.prototype,"_stage",void 0),e([a({readOnly:!0})],le.prototype,"_isGlobal",null),e([a({constructOnly:!0})],le.prototype,"_allTiles",void 0),e([a({constructOnly:!0})],le.prototype,"_ellipsoidRadius",void 0),e([a({value:!1})],le.prototype,"renderingDisabled",null),e([a()],le.prototype,"renderPatchBorders",null),e([a()],le.prototype,"visualizeNormals",null),e([a()],le.prototype,"cullBackFaces",null),e([a({value:P.FRONT_TO_BACK})],le.prototype,"renderOrder",null),e([a()],le.prototype,"wireframe",null),le=e([l("esri.views.3d.terrain.TerrainRenderer")],le);const he=_(),ce=_(),de=_(),ue=_();export{le as TerrainRenderer,ae as TransparencyMode};