@arcgis/core 4.23.0-next.20211229 → 4.23.0-next.20220105

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.
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../core/Collection.js";import t from"../../../core/Logger.js";import{init as r}from"../../../core/watchUtils.js";import{g as n}from"../../../chunks/vec3.js";import s from"./RenderContext.js";import{RenderPass as i}from"../webgl-engine/lib/RenderPass.js";import{RenderSlot as d}from"../webgl-engine/lib/RenderSlot.js";const o=t.getLogger("esri.views.3d.externalRenderers.ExternalRendererStore");class a{constructor(){this._renderers=new e}add(e,t){this._findOrCreateStageRenderer(e).add(t)}remove(e,t){const r=this._findStageRenderer(e);r&&r.remove(t),0===r.renderers.length&&(r.destroy(),this._renderers.remove(r))}_findStageRenderer(e){return this._renderers.find((t=>t.view===e))}_findOrCreateStageRenderer(e){let t=this._findStageRenderer(e);return t||(t=new h(e),this._renderers.add(t)),t}}class h{constructor(t){this.view=t,this.canRender=!0,this.renderers=new e,this._readyWatchHandle=r(t,"ready",(e=>{e?(this.context=new s(this.view),this.view._stage.addRenderPlugin([d.OPAQUE_PLUGIN,d.TRANSPARENT_PLUGIN],this)):(this.renderers.forEach((e=>c(e,"dispose",this.context))),this.context=null)}))}destroy(){this.renderers.drain((e=>{this.context&&c(e,"dispose",this.context)})),this.view._stage&&this.view._stage.removeRenderPlugin(this),this._readyWatchHandle&&(this._readyWatchHandle.remove(),this._readyWatchHandle=null),this.context=null}add(e){-1===this.renderers.indexOf(e)?(this.renderers.add(e),this.context&&(this._webglStateReset(),c(e,"setup",this.context),this.view._stage.renderView.requestRender())):o.warn("add(): Cannot add external renderer: renderer has already been added")}remove(e){const t=this.renderers.indexOf(e);-1!==t&&(this.renderers.removeAt(t),this.context&&(c(e,"dispose",this.context),this.view._stage.renderView.requestRender()))}initializeRenderContext(e){this.context.gl=e.renderContext.rctx.gl,this.context.rctx=e.renderContext.rctx,this.renderers.length>0&&this._webglStateReset(),this.renderers.forEach((e=>c(e,"setup",this.context)))}uninitializeRenderContext(){}render(e){0===this.renderers.length||e.pass!==i.MATERIAL||e.slot!==d.OPAQUE_PLUGIN&&e.slot!==d.TRANSPARENT_PLUGIN||(this._updateContext(e),this._webglStateReset(),this.renderers.forEach((t=>{switch(e.slot){case d.OPAQUE_PLUGIN:c(t,"render",this.context);break;case d.TRANSPARENT_PLUGIN:c(t,"renderTransparent",this.context)}})))}_updateContext(e){this.context.camera.copyFrom(e.camera),n(this.context.sunLight.direction,e.scenelightingData.old.direction),n(this.context.sunLight.diffuse.color,e.scenelightingData.old.diffuse.color),n(this.context.sunLight.ambient.color,e.scenelightingData.old.ambient.color),this.context._renderTargetHelper=e.offscreenRenderingHelper}_webglStateReset(){var e;this.context.rctx.resetState(),null==(e=this.context._renderTargetHelper)||e.bindFramebuffer()}}function c(e,t,r){"function"==typeof e[t]&&e[t](r)}export{a as default};
5
+ import e from"../../../core/Collection.js";import t from"../../../core/Logger.js";import{init as r}from"../../../core/watchUtils.js";import{g as n}from"../../../chunks/vec3.js";import s from"./RenderContext.js";import{RenderPass as i}from"../webgl-engine/lib/RenderPass.js";import{RenderSlot as d}from"../webgl-engine/lib/RenderSlot.js";const o=t.getLogger("esri.views.3d.externalRenderers.ExternalRendererStore");class a{constructor(){this._renderers=new e}add(e,t){this._findOrCreateStageRenderer(e).add(t)}remove(e,t){const r=this._findStageRenderer(e);r&&r.remove(t),0===r.renderers.length&&(r.destroy(),this._renderers.remove(r))}_findStageRenderer(e){return this._renderers.find((t=>t.view===e))}_findOrCreateStageRenderer(e){let t=this._findStageRenderer(e);return t||(t=new h(e),this._renderers.add(t)),t}}class h{constructor(t){this.view=t,this.canRender=!0,this.renderers=new e,this._readyWatchHandle=r(t,"ready",(e=>{e?(this.context=new s(this.view),this.view._stage.addRenderPlugin([d.OPAQUE_PLUGIN,d.TRANSPARENT_PLUGIN],this)):(this.renderers.forEach((e=>c(e,"dispose",this.context))),this.context=null)}))}destroy(){this.renderers.drain((e=>{this.context&&c(e,"dispose",this.context)})),this.view._stage&&this.view._stage.removeRenderPlugin(this),this._readyWatchHandle&&(this._readyWatchHandle.remove(),this._readyWatchHandle=null),this.context=null}add(e){-1===this.renderers.indexOf(e)?(this.renderers.add(e),this.context&&(this._webglStateReset(),c(e,"setup",this.context),this.view._stage.renderView.requestRender())):o.warn("add(): Cannot add external renderer: renderer has already been added")}remove(e){const t=this.renderers.indexOf(e);-1!==t&&(this.renderers.removeAt(t),this.context&&(c(e,"dispose",this.context),this.view._stage.renderView.requestRender()))}initializeRenderContext(e){this.context.gl=e.renderContext.rctx.gl,this.context.rctx=e.renderContext.rctx,this.renderers.length>0&&this._webglStateReset(),this.renderers.forEach((e=>c(e,"setup",this.context)))}uninitializeRenderContext(){}render(e){0===this.renderers.length||e.pass!==i.MATERIAL||e.slot!==d.OPAQUE_PLUGIN&&e.slot!==d.TRANSPARENT_PLUGIN||(this._updateContext(e),this._webglStateReset(),this.renderers.forEach((t=>{switch(e.slot){case d.OPAQUE_PLUGIN:c(t,"render",this.context);break;case d.TRANSPARENT_PLUGIN:c(t,"renderTransparent",this.context)}})))}_updateContext(e){this.context.camera.copyFrom(e.camera),n(this.context.sunLight.direction,e.scenelightingData.old.direction),n(this.context.sunLight.diffuse.color,e.scenelightingData.old.diffuse.color),n(this.context.sunLight.ambient.color,e.scenelightingData.old.ambient.color),this.context._renderTargetHelper=e.offscreenRenderingHelper}_webglStateReset(){var e;this.context.rctx.resetState(),null==(e=this.context._renderTargetHelper)||e.bindFramebuffer()}get needsTransparentPass(){return this.renderers.some((e=>"function"==typeof e.renderTransparent))}}function c(e,t,r){"function"==typeof e[t]&&e[t](r)}export{a as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import{isSome as s}from"../../../../../core/maybe.js";import{f as a,t as e,e as r}from"../../../../../chunks/mat3.js";import{c as t}from"../../../../../chunks/mat3f64.js";import{c as i}from"../../../../../chunks/mat4.js";import{s as h}from"../../../../../chunks/vec2.js";import{b as n,s as m,g as o,f as l}from"../../../../../chunks/vec3.js";import{c as P}from"../../../../../chunks/vec3f64.js";import{c as p}from"../../../../../chunks/vec4.js";import{d as _}from"../../../../../chunks/boundedPlane.js";import{MaterialPassesParameters as c,ShadowMapPassParameters as d,HighlightPassParameters as u,MaterialSubPass as T,RenderPassIdentifier as A}from"./AllRenderPasses.js";import{RenderPass as g,RenderPassSorting as w}from"./RenderPass.js";import{TwoVectorPosition as R}from"../util/TwoVectorPosition.js";import{union as f}from"../../lib/depthRange.js";import{RenderPass as M}from"../../lib/RenderPass.js";import{RenderSlot as E}from"../../lib/RenderSlot.js";class H{constructor(s,a){this.rctx=s,this.shaderTechniqueRepository=a,this.canRender=!0,this._materialPassParams=new c,this._shadowPassParams=new d,this._highlightPassParams=new u,this._systems=new Set,this._passes={materialOpaque:new g(s,this.shaderTechniqueRepository),materialTransparent:new g(s,this.shaderTechniqueRepository,w.BackToFront),materialIntegratedMesh:new g(s,this.shaderTechniqueRepository),shadowMap:new g(s,this.shaderTechniqueRepository),highlight:new g(s,this.shaderTechniqueRepository),highlightIntegratedMesh:new g(s,this.shaderTechniqueRepository),highlightShadowMap:new g(s,this.shaderTechniqueRepository),defaultShadowMap:new g(s,this.shaderTechniqueRepository)}}register(s){this._systems.add(s)}prepareRender(s){if(0!==this._systems.size){for(const s of Object.values(this._passes))s.prepareSubmit();this._systems.forEach((a=>a.submit(this._passes,{camera:s})));for(const s of Object.values(this._passes))s.finishSubmit();this.shaderTechniqueRepository.frameUpdate()}}render(s){if(0!==this._systems.size)switch(this._configure(s),s.slot){case E.OPAQUE_PLUGIN:switch(s.pass){case M.MATERIAL:return this._materialPassParams.subPass=T.Color,this._configureMaterialColorPass(s),this._passes.materialOpaque.dispatch(this._materialPassParams);case M.MATERIAL_DEPTH:return this._materialPassParams.subPass=T.Depth,this._passes.materialOpaque.dispatch(this._materialPassParams);case M.MATERIAL_NORMAL:return this._materialPassParams.subPass=T.Normal,this._passes.materialOpaque.dispatch(this._materialPassParams);case M.MATERIAL_HIGHLIGHT:return this._passes.highlight.dispatch(this._highlightPassParams);case M.MATERIAL_DEPTH_SHADOWMAP_ALL:return this._passes.shadowMap.dispatch(this._shadowPassParams);case M.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT:return this._passes.highlightShadowMap.dispatch(this._shadowPassParams);case M.MATERIAL_DEPTH_SHADOWMAP_DEFAULT:return this._passes.defaultShadowMap.dispatch(this._shadowPassParams)}return;case E.TRANSPARENT_PLUGIN:switch(s.pass){case M.MATERIAL:return this._materialPassParams.subPass=T.Color,this._configureMaterialColorPass(s),this._passes.materialTransparent.dispatch(this._materialPassParams);case M.MATERIAL_ALPHA:return this._materialPassParams.subPass=T.Alpha,this._configureMaterialColorPass(s),this._passes.materialTransparent.dispatch(this._materialPassParams);case M.MATERIAL_DEPTH:return this._materialPassParams.subPass=T.Depth,this._passes.materialTransparent.dispatch(this._materialPassParams);case M.MATERIAL_NORMAL:return this._materialPassParams.subPass=T.Normal,this._passes.materialTransparent.dispatch(this._materialPassParams)}return;case E.INTEGRATED_MESH:switch(s.pass){case M.MATERIAL:return this._materialPassParams.subPass=T.Color,this._configureMaterialColorPass(s),this._materialPassParams.ssrParams=s.ssrParams,this._passes.materialIntegratedMesh.dispatch(this._materialPassParams);case M.MATERIAL_DEPTH:return this._materialPassParams.subPass=T.Depth,this._passes.materialIntegratedMesh.dispatch(this._materialPassParams);case M.MATERIAL_NORMAL:return this._materialPassParams.subPass=T.Normal,this._passes.materialIntegratedMesh.dispatch(this._materialPassParams);case M.MATERIAL_HIGHLIGHT:return this._passes.highlightIntegratedMesh.dispatch(this._highlightPassParams)}return}}notifyDirty(){this._context.requestRender()}slots(){return[E.OPAQUE_PLUGIN,E.TRANSPARENT_PLUGIN,E.INTEGRATED_MESH]}initializeRenderContext(s){this._context=s}uninitializeRenderContext(){}queryDepthRange(a){const e={near:1/0,far:-1/0};return this._systems.forEach((r=>{const t=r.queryShadowCasterDepthRange(a);s(t)&&f(e,t,e)})),e}get shadowCastingEnabled(){return this._materialPassParams.shadowsEnabled}set shadowCastingEnabled(s){this._materialPassParams.shadowsEnabled=s}get screenSpaceReflectionsEnabled(){return s(this._materialPassParams.ssrParams.ssrEnabled)}set screenSpaceReflectionsEnabled(s){this._materialPassParams.ssrParams.ssrEnabled=!!s}_configureMaterialColorPass(s){this._materialPassParams.bindShadowMap=a=>{s.shadowMap.bind(a);const e=this._materialPassParams.viewTransform;n(I,e.worldFromView_TL,e.worldFromView_TH),s.shadowMap.bindView(a,I)},this._materialPassParams.bindAmbientOcclusion=a=>s.ssaoHelper.bind(a,s.camera),this._materialPassParams.ambientOcclusionEnabled=!!s.ssaoHelper&&s.ssaoHelper.ready,this._materialPassParams.sceneHasOcludees=s.hasOccludees}_configure(s){const a=s.pass===M.MATERIAL_DEPTH_SHADOWMAP_ALL||s.pass===M.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT||s.pass===M.MATERIAL_DEPTH_SHADOWMAP_DEFAULT?this._shadowPassParams:s.pass===M.MATERIAL_HIGHLIGHT?this._highlightPassParams:this._materialPassParams;this._updateParameters(s,a)}_updateParameters(s,t){const n=s.camera,P=n.viewInverseTransposeMatrix;m(I,P[3],P[7],P[11]),b.set(I),o(t.viewTransform.worldFromView_TH,b.high),o(t.viewTransform.worldFromView_TL,b.low),a(t.viewTransform.viewFromCameraRelative_RS,n.viewMatrix),i(t.viewTransform.projFromView,n.projectionMatrix),t.identifier===A.Material?(this._materialPassParams.transparent=s.slot===E.TRANSPARENT_PLUGIN,this._materialPassParams.integratedMesh=s.slot===E.INTEGRATED_MESH,this._materialPassParams.lighting=s.scenelightingData,e(L,t.viewTransform.viewFromCameraRelative_RS),r(t.transformNormal_ViewFromGlobal,L),h(t.cameraNearFar,n.near,n.far)):t.identifier===A.ShadowMap?h(t.cameraNearFar,n.near,n.far):t.identifier===A.Highlight&&(t.highlightDepthTexture=s.highlightDepthTexture,p(t.viewport,n.fullViewport)),t.identifier!==A.Material&&t.identifier!==A.Highlight||(t.inverseViewport[0]=1/n.fullViewport[2],t.inverseViewport[1]=1/n.fullViewport[3]),_(s.sliceHelper.plane,t.slicePlane),l(t.slicePlane.origin,t.slicePlane.origin,I),t.slicePlaneEnabled=s.sliceHelper.isEnabled,this._materialPassParams.slot=s.slot,this._materialPassParams.transparencyPassType=s.transparencyPassType,this._materialPassParams.multipassTerrainParams=s.multipassTerrainParams}get needsHighlight(){return this._passes.highlight.count>0||this._passes.highlightIntegratedMesh.count>0}}const I=P(),L=t(),b=new R;export{H as RenderPassManager};
5
+ import{isSome as s}from"../../../../../core/maybe.js";import{f as a,t as e,e as r}from"../../../../../chunks/mat3.js";import{c as t}from"../../../../../chunks/mat3f64.js";import{c as i}from"../../../../../chunks/mat4.js";import{s as h}from"../../../../../chunks/vec2.js";import{b as n,s as m,g as o,f as l}from"../../../../../chunks/vec3.js";import{c as P}from"../../../../../chunks/vec3f64.js";import{c as p}from"../../../../../chunks/vec4.js";import{d as _}from"../../../../../chunks/boundedPlane.js";import{MaterialPassesParameters as c,ShadowMapPassParameters as d,HighlightPassParameters as u,MaterialSubPass as T,RenderPassIdentifier as A}from"./AllRenderPasses.js";import{RenderPass as g,RenderPassSorting as w}from"./RenderPass.js";import{TwoVectorPosition as R}from"../util/TwoVectorPosition.js";import{union as f}from"../../lib/depthRange.js";import{RenderPass as M}from"../../lib/RenderPass.js";import{RenderSlot as E}from"../../lib/RenderSlot.js";class H{constructor(s,a){this.rctx=s,this.shaderTechniqueRepository=a,this.canRender=!0,this._materialPassParams=new c,this._shadowPassParams=new d,this._highlightPassParams=new u,this._systems=new Set,this._passes={materialOpaque:new g(s,this.shaderTechniqueRepository),materialTransparent:new g(s,this.shaderTechniqueRepository,w.BackToFront),materialIntegratedMesh:new g(s,this.shaderTechniqueRepository),shadowMap:new g(s,this.shaderTechniqueRepository),highlight:new g(s,this.shaderTechniqueRepository),highlightIntegratedMesh:new g(s,this.shaderTechniqueRepository),highlightShadowMap:new g(s,this.shaderTechniqueRepository),defaultShadowMap:new g(s,this.shaderTechniqueRepository)}}register(s){this._systems.add(s)}prepareRender(s){if(0!==this._systems.size){for(const s of Object.values(this._passes))s.prepareSubmit();this._systems.forEach((a=>a.submit(this._passes,{camera:s})));for(const s of Object.values(this._passes))s.finishSubmit();this.shaderTechniqueRepository.frameUpdate()}}render(s){if(0!==this._systems.size)switch(this._configure(s),s.slot){case E.OPAQUE_PLUGIN:switch(s.pass){case M.MATERIAL:return this._materialPassParams.subPass=T.Color,this._configureMaterialColorPass(s),this._passes.materialOpaque.dispatch(this._materialPassParams);case M.MATERIAL_DEPTH:return this._materialPassParams.subPass=T.Depth,this._passes.materialOpaque.dispatch(this._materialPassParams);case M.MATERIAL_NORMAL:return this._materialPassParams.subPass=T.Normal,this._passes.materialOpaque.dispatch(this._materialPassParams);case M.MATERIAL_HIGHLIGHT:return this._passes.highlight.dispatch(this._highlightPassParams);case M.MATERIAL_DEPTH_SHADOWMAP_ALL:return this._passes.shadowMap.dispatch(this._shadowPassParams);case M.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT:return this._passes.highlightShadowMap.dispatch(this._shadowPassParams);case M.MATERIAL_DEPTH_SHADOWMAP_DEFAULT:return this._passes.defaultShadowMap.dispatch(this._shadowPassParams)}return;case E.TRANSPARENT_PLUGIN:switch(s.pass){case M.MATERIAL:return this._materialPassParams.subPass=T.Color,this._configureMaterialColorPass(s),this._passes.materialTransparent.dispatch(this._materialPassParams);case M.MATERIAL_ALPHA:return this._materialPassParams.subPass=T.Alpha,this._configureMaterialColorPass(s),this._passes.materialTransparent.dispatch(this._materialPassParams);case M.MATERIAL_DEPTH:return this._materialPassParams.subPass=T.Depth,this._passes.materialTransparent.dispatch(this._materialPassParams);case M.MATERIAL_NORMAL:return this._materialPassParams.subPass=T.Normal,this._passes.materialTransparent.dispatch(this._materialPassParams)}return;case E.INTEGRATED_MESH:switch(s.pass){case M.MATERIAL:return this._materialPassParams.subPass=T.Color,this._configureMaterialColorPass(s),this._materialPassParams.ssrParams=s.ssrParams,this._passes.materialIntegratedMesh.dispatch(this._materialPassParams);case M.MATERIAL_DEPTH:return this._materialPassParams.subPass=T.Depth,this._passes.materialIntegratedMesh.dispatch(this._materialPassParams);case M.MATERIAL_NORMAL:return this._materialPassParams.subPass=T.Normal,this._passes.materialIntegratedMesh.dispatch(this._materialPassParams);case M.MATERIAL_HIGHLIGHT:return this._passes.highlightIntegratedMesh.dispatch(this._highlightPassParams)}return}}notifyDirty(){this._context.requestRender()}slots(){return[E.OPAQUE_PLUGIN,E.TRANSPARENT_PLUGIN,E.INTEGRATED_MESH]}initializeRenderContext(s){this._context=s}uninitializeRenderContext(){}queryDepthRange(a){const e={near:1/0,far:-1/0};return this._systems.forEach((r=>{const t=r.queryShadowCasterDepthRange(a);s(t)&&f(e,t,e)})),e}get shadowCastingEnabled(){return this._materialPassParams.shadowsEnabled}set shadowCastingEnabled(s){this._materialPassParams.shadowsEnabled=s}get screenSpaceReflectionsEnabled(){return s(this._materialPassParams.ssrParams.ssrEnabled)}set screenSpaceReflectionsEnabled(s){this._materialPassParams.ssrParams.ssrEnabled=!!s}_configureMaterialColorPass(s){this._materialPassParams.bindShadowMap=a=>{s.shadowMap.bind(a);const e=this._materialPassParams.viewTransform;n(I,e.worldFromView_TL,e.worldFromView_TH),s.shadowMap.bindView(a,I)},this._materialPassParams.bindAmbientOcclusion=a=>s.ssaoHelper.bind(a,s.camera),this._materialPassParams.ambientOcclusionEnabled=!!s.ssaoHelper&&s.ssaoHelper.ready,this._materialPassParams.sceneHasOcludees=s.hasOccludees}_configure(s){const a=s.pass===M.MATERIAL_DEPTH_SHADOWMAP_ALL||s.pass===M.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT||s.pass===M.MATERIAL_DEPTH_SHADOWMAP_DEFAULT?this._shadowPassParams:s.pass===M.MATERIAL_HIGHLIGHT?this._highlightPassParams:this._materialPassParams;this._updateParameters(s,a)}_updateParameters(s,t){const n=s.camera,P=n.viewInverseTransposeMatrix;m(I,P[3],P[7],P[11]),b.set(I),o(t.viewTransform.worldFromView_TH,b.high),o(t.viewTransform.worldFromView_TL,b.low),a(t.viewTransform.viewFromCameraRelative_RS,n.viewMatrix),i(t.viewTransform.projFromView,n.projectionMatrix),t.identifier===A.Material?(this._materialPassParams.transparent=s.slot===E.TRANSPARENT_PLUGIN,this._materialPassParams.integratedMesh=s.slot===E.INTEGRATED_MESH,this._materialPassParams.lighting=s.scenelightingData,e(L,t.viewTransform.viewFromCameraRelative_RS),r(t.transformNormal_ViewFromGlobal,L),h(t.cameraNearFar,n.near,n.far)):t.identifier===A.ShadowMap?h(t.cameraNearFar,n.near,n.far):t.identifier===A.Highlight&&(t.highlightDepthTexture=s.highlightDepthTexture,p(t.viewport,n.fullViewport)),t.identifier!==A.Material&&t.identifier!==A.Highlight||(t.inverseViewport[0]=1/n.fullViewport[2],t.inverseViewport[1]=1/n.fullViewport[3]),_(s.sliceHelper.plane,t.slicePlane),l(t.slicePlane.origin,t.slicePlane.origin,I),t.slicePlaneEnabled=s.sliceHelper.isEnabled,this._materialPassParams.slot=s.slot,this._materialPassParams.transparencyPassType=s.transparencyPassType,this._materialPassParams.multipassTerrainParams=s.multipassTerrainParams}get needsHighlight(){return this._passes.highlight.count>0||this._passes.highlightIntegratedMesh.count>0}get needsTransparentPass(){return this._passes.materialTransparent.count>0}}const I=P(),L=t(),b=new R;export{H as RenderPassManager};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import{isPromiseLike as e}from"../../../../core/promiseUtils.js";import{union as t}from"./depthRange.js";import{RenderSlot as r}from"./RenderSlot.js";import{assert as n}from"./Util.js";class s{constructor(e){this.context=e,this.renderPlugins=new Array,this.slots=[];for(let t=0;t<r.MAX_SLOTS;++t)this.slots[t]=[]}add(t,r,n){const s=()=>{this.renderPlugins.push(r);for(const e of t)this.slots[e].push(r);this.context.requestRender()},i=r.initializeRenderContext(this.context,n);if(e(i))return i.then(s);s()}remove(e){const t=this.renderPlugins.length;this.renderPlugins=this.renderPlugins.filter((t=>t!==e)),n(this.renderPlugins.length<t,"Removing non-added render plugin");for(let r=0;r<this.slots.length;++r)this.slots[r]=this.slots[r].filter((t=>t!==e));e.uninitializeRenderContext(),this.context.requestRender()}prepareRender(e,t){for(const r of this.renderPlugins)r.prepareRender&&r.prepareRender(e,t)}render(){const e=this.slots[this.context.renderContext.slot],t=new Array;e.filter((e=>{if(!e.canRender)return!1;if(i(e)){const r=e.prepareTechnique(this.context.renderContext);return!!r&&(t.push(r),!0)}return t.push(null),!0})).forEach(((e,r)=>e.render(this.context.renderContext,t[r])))}queryDepthRange(e){const r=o;r.near=1/0,r.far=-1/0;for(const n of this.renderPlugins)if(n.queryDepthRange){const s=n.queryDepthRange(e);s&&t(r,s,r)}return r}get needsHighlight(){return this.renderPlugins.some((e=>e.needsHighlight))}get needsLinearDepth(){return this.renderPlugins.some((e=>e.needsLinearDepth))}get needsLaserlineWithContrastControl(){const e=this.slots[r.LASERLINES_CONTRAST_CONTROL];return!!e&&e.length>0}get renderOccludedFlags(){let e=0;return this.renderPlugins.forEach((t=>{t.renderOccludedFlags&&(e|=t.renderOccludedFlags)})),e}}function i(e){return"prepareTechnique"in e}const o={near:0,far:0};export{s as RenderPluginManager};
5
+ import{isPromiseLike as e}from"../../../../core/promiseUtils.js";import{union as r}from"./depthRange.js";import{RenderSlot as t}from"./RenderSlot.js";import{assert as n}from"./Util.js";class s{constructor(e){this.context=e,this.renderPlugins=new Array,this.slots=[];for(let r=0;r<t.MAX_SLOTS;++r)this.slots[r]=[]}add(r,t,n){const s=()=>{this.renderPlugins.push(t);for(const e of r)this.slots[e].push(t);this.context.requestRender()},i=t.initializeRenderContext(this.context,n);if(e(i))return i.then(s);s()}remove(e){const r=this.renderPlugins.length;this.renderPlugins=this.renderPlugins.filter((r=>r!==e)),n(this.renderPlugins.length<r,"Removing non-added render plugin");for(let t=0;t<this.slots.length;++t)this.slots[t]=this.slots[t].filter((r=>r!==e));e.uninitializeRenderContext(),this.context.requestRender()}prepareRender(e,r){for(const t of this.renderPlugins)t.prepareRender&&t.prepareRender(e,r)}render(){const e=this.slots[this.context.renderContext.slot],r=new Array;e.filter((e=>{if(!e.canRender)return!1;if(i(e)){const t=e.prepareTechnique(this.context.renderContext);return!!t&&(r.push(t),!0)}return r.push(null),!0})).forEach(((e,t)=>e.render(this.context.renderContext,r[t])))}queryDepthRange(e){const t=o;t.near=1/0,t.far=-1/0;for(const n of this.renderPlugins)if(n.queryDepthRange){const s=n.queryDepthRange(e);s&&r(t,s,t)}return t}get needsTransparentPass(){return this.renderPlugins.some((e=>e.needsTransparentPass))}get needsHighlight(){return this.renderPlugins.some((e=>e.needsHighlight))}get needsLinearDepth(){return this.renderPlugins.some((e=>e.needsLinearDepth))}get needsLaserlineWithContrastControl(){const e=this.slots[t.LASERLINES_CONTRAST_CONTROL];return!!e&&e.length>0}get renderOccludedFlags(){let e=0;return this.renderPlugins.forEach((r=>{r.renderOccludedFlags&&(e|=r.renderOccludedFlags)})),e}}function i(e){return"prepareTechnique"in e}const o={near:0,far:0};export{s as RenderPluginManager};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import r from"../../../../core/Accessor.js";import t from"../../../../core/Handles.js";import{someMap as s}from"../../../../core/MapUtils.js";import{destroyMaybe as n,disposeMaybe as i,isSome as a,isNone as h,unwrap as o}from"../../../../core/maybe.js";import{Milliseconds as d}from"../../../../core/time.js";import{init as l}from"../../../../core/watchUtils.js";import{property as _}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/arrayUtils.js";import"../../../../core/has.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../../../core/accessorSupport/decorators/subclass.js";import{v as c,j as m,a as u,m as g}from"../../../../chunks/mat4.js";import{I as f,c as T}from"../../../../chunks/mat4f64.js";import{a as R}from"../../../../chunks/vec2f64.js";import{MAXIMUM_ANIMATION_LOAD as x,MINIMUM_IDLE_ANIMATION_MS as C}from"../../support/animationUtils.js";import E from"../../support/debugFlags.js";import{RenderPassManager as A}from"../core/renderPasses/RenderPassManager.js";import{HUDTransparentRenderStyle as P}from"../core/shaderLibrary/hud/HUDUniforms.js";import{AntiAliasingMode as b,TransparencyPassType as w,Decorations as S,RenderRequestType as H,StencilBits as D}from"./basicInterfaces.js";import{BoundingInfo as M}from"./BoundingInfo.js";import{ZERO as O,union as y}from"./depthRange.js";import{depthRangeFromScene as L}from"./depthRangeUtils.js";import{createEmptyDepthTexture as I}from"./glUtil3D.js";import v from"./HighlightHelper.js";import{RenderOccludedFlag as N}from"./Material.js";import{OffscreenRendering as U}from"./OffscreenRendering.js";import{RenderContext as j}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as q}from"./rendererUtils.js";import{RenderPass as G}from"./RenderPass.js";import{RenderPluginManager as F}from"./RenderPluginManager.js";import{RenderSlot as V}from"./RenderSlot.js";import{ShadowAccumulator as k}from"./ShadowAccumulator.js";import{ShadowHighlightHelper as W}from"./ShadowHighlightHelper.js";import B from"./ShadowMap.js";import Q from"./SliceHelper.js";import{SmaaRenderPass as z}from"./SmaaRenderPass.js";import{SSAOHelper as X}from"./SSAOHelper.js";import{EdgeView as K}from"./edgeRendering/EdgeView.js";import{Transparency as Y}from"./edgeRendering/interfaces.js";import{SceneLighting as J}from"../lighting/SceneLighting.js";import{MergedRenderer as Z}from"../materials/renderers/MergedRenderer.js";import{AlphaMode as $}from"../shaders/CompositingTechnique.js";import{HighlightShadowMapSlot as ee,DefaultSnapshotSlot as re}from"../shaders/ShadowHighlightTechnique.js";import{RendererPerformanceInfo as te,Statistics as se}from"../statistics/RendererPerformanceInfo.js";import{ClearBufferBit as ne,PixelFormat as ie,PixelType as ae}from"../../../webgl/enums.js";import{startMeasurement as he}from"../../../webgl/Measurement.js";const oe=.9;let de=class extends r{constructor(e,r,s,n,i,a,h,o,_){super({}),this._materialRepository=e,this._shaderTechniqueRepository=s,this._rctx=n,this._compositingHelper=i,this._magnifierHelper=a,this._requestRender=h,this._stage=_,this._materialRenderers=new Map,this._hasHighlights=!1,this._hasOccludees=!1,this._hasWater=!1,this._hasOverlayWater=!1,this._content=new Map,this._isRendering=!1,this._fallbackDepthStencilTexture=null,this.performanceInfo=new te,this._antialiasing=b.SMAA,this._oitEnabled=!1,this._multipassTerrain=!0,this._opaqueTerrain=!0,this._lighting=new J,this._hasAnimations=!1,this._animationTimestep=d(0),this._handles=new t,this._renderHiddenTransparentEdges=()=>{},this._smaaPass=new z(this._rctx,s),this._oitEnabled=this._hasOITSupport,this._requestRender(),this._offscreenRendering=new U(this._rctx,this._compositingHelper),this._sliceHelper=new Q,this._shadowMap=new B(this._rctx,_.viewingMode,2),this._ssaoHelper=new X(s,this._rctx,(()=>this._requestRender())),this._highlightHelper=new v(s,this._rctx),this._shadowHighlightHelper=new W(this._rctx,_.viewingMode),this._shadowAccumulator=new k(this._rctx,s,_,((e,r)=>{this.renderPassManager.shadowCastingEnabled=!0,this._renderPlugins.prepareRender(e,r),this.renderPassManager.shadowCastingEnabled=this._shadowMap.enabled}),((e,r,t,s)=>{e.start(t,r,s),this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_ALL,e),t.setGLViewport(this._rctx),this._ensureCameraBindParameters(t)}),(()=>this._requestRender())),this._bindParameters={slot:null,camera:null,inverseViewport:R(),shadowMap:this._shadowMap,shadowMappingEnabled:this._shadowMap.enabled,ssaoHelper:this._ssaoHelper,ssaoEnabled:this._ssaoHelper.enabled,origin:null,screenToWorldRatio:null,screenToPCSRatio:null,slicePlane:this._sliceHelper.plane,highlightDepthTexture:null,hasOccludees:!1,linearDepthTexture:null,terrainLinearDepthTexture:null,geometryLinearDepthTexture:null,multipassTerrainEnabled:!1,multipassGeometryEnabled:!1,cullAboveGround:!1,lastFrameColorTexture:null,reprojectionMatrix:f,ssrEnabled:!1,lighting:this._lighting,highlightColorTexture:null},this._renderContext=new j(this._rctx,this._offscreenRendering,this._lighting,this._shadowMap,this._ssaoHelper,this._sliceHelper),this._renderContext.multipassTerrainParams={camera:null,multipassTerrainEnabled:!1,cullAboveGround:!1,terrainLinearDepthTexture:null},this._renderContext.multipassGeometryParams={multipassGeometryEnabled:!1,geometryLinearDepthTexture:null},this._renderContext.ssrParams={camera:null,linearDepthTexture:null,lastFrameColorTexture:null,reprojectionMatrix:f,ssrEnabled:!1},this._renderPlugins=new F({renderContext:this._renderContext,shaderTechniqueRep:s,textureRep:r,materialRep:this._materialRepository,requestRender:this._requestRender,schedule:o}),this.renderPassManager=new A(this._rctx,this._shaderTechniqueRepository),this._renderPlugins.add(this.renderPassManager.slots(),this.renderPassManager),this._handles.add([l(E,"EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES",(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(Y.TRANSPARENT):()=>{},this._requestRender()})),l(this._stage,"camera",(()=>this._requestRender()),!0)])}get hasWater(){return this._hasWater||this._hasOverlayWater}get hasWaterReflection(){return this.hasWater&&this._waterReflectionEnabled}normalizeCtorArgs(){return{}}dispose(){this._handles.destroy(),this._smaaPass.dispose(),this._materialRenderers.forEach((e=>e.dispose())),this._materialRenderers.clear(),this._edgeView=n(this._edgeView),this._offscreenRendering.dispose(),this._fallbackDepthStencilTexture=i(this._fallbackDepthStencilTexture),this._shadowMap.enabled=!1,this._shadowMap.dispose(),this._ssaoHelper.enabled=!1,this._ssaoHelper.dispose(),this._highlightHelper.dispose(),this._shadowHighlightHelper.dispose(),this._shadowAccumulator.dispose(),M.prune(),this._content.clear()}get updating(){return this._antialiasing===b.SMAA&&this._smaaPass.updating||a(this._edgeView)&&this._edgeView.updating||this._shadowAccumulator.running||!this.isCameraFinal}ensureEdgeView(){return h(this._edgeView)&&(this._edgeView=new K({rctx:this._rctx,renderSR:this._stage.renderSR,techniqueRepository:this._shaderTechniqueRepository,setNeedsRender:()=>this._requestRender(),schedule:e=>this._stage.resourceController.schedule(e)}),this._handles.add(this._edgeView.watch("updating",(()=>this._requestRender()),!0)),this._requestRender()),this._edgeView}get edgeView(){return this._edgeView}get isCameraFinal(){return null===this._bindParameters.reprojectionMatrix||c(this._bindParameters.reprojectionMatrix,f)}set _reprojectionMatrix(e){c(this._bindParameters.reprojectionMatrix,e)||(this._bindParameters.reprojectionMatrix=e,this.notifyChange("isCameraFinal"))}get hasShadowsEnabled(){var e;return!(null==(e=this._shadowMap)||!e.enabled)}setRenderParameters(e){const{renderPassManager:r,_shadowMap:t,_ssaoHelper:s}=this;void 0!==e.screenSpaceReflectionsEnabled&&r.screenSpaceReflectionsEnabled!==e.screenSpaceReflectionsEnabled&&(r.screenSpaceReflectionsEnabled=e.screenSpaceReflectionsEnabled,this._requestRender()),void 0===e.shadowMap||t.enabled===e.shadowMap&&r.shadowCastingEnabled===e.shadowMap||(t.enabled=e.shadowMap,r.shadowCastingEnabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&t.maxCascades!==e.shadowMapMaxCascades&&(t.maxCascades=e.shadowMapMaxCascades,this._requestRender()),void 0!==e.ssao&&s.enabled!==e.ssao&&(s.enabled=e.ssao,this._requestRender()),e.background&&this._offscreenRendering.background!==e.background&&(this._offscreenRendering.background=e.background,this._requestRender());const n=e.antialiasingEnabled?b.SMAA:b.NONE;void 0!==e.antialiasingEnabled&&this._antialiasing!==n&&(this._antialiasing=n,this._requestRender()),void 0!==e.highQualityTransparency&&this._multipassTerrain!==e.highQualityTransparency&&(this._multipassTerrain=e.highQualityTransparency,this._oitEnabled=e.highQualityTransparency&&this._hasOITSupport,this._requestRender()),void 0!==e.defaultHighlightOptions&&(this._highlightHelper.setDefaultOptions(e.defaultHighlightOptions),this._shadowHighlightHelper.setDefaultOptions(e.defaultHighlightOptions),this._requestRender()),void 0!==e.slicePlane&&this._sliceHelper.plane!==e.slicePlane&&(this._sliceHelper.plane=o(e.slicePlane),this._requestRender()),void 0!==e.waterReflectionEnabled&&this._waterReflectionEnabled!==e.waterReflectionEnabled&&(this._waterReflectionEnabled=e.waterReflectionEnabled,this._requestRender()),void 0!==e.opaqueTerrain&&this._opaqueTerrain!==e.opaqueTerrain&&(this._opaqueTerrain=e.opaqueTerrain,this._requestRender()),void 0!==e.hasOverlayWater&&this._hasOverlayWater!==e.hasOverlayWater&&(this._hasOverlayWater=e.hasOverlayWater,this._requestRender()),void 0!==e.shadowCastOptions&&this._shadowAccumulator.setOptions(e.shadowCastOptions)}get hasSlicePlane(){return!!this._sliceHelper.plane}get renderPlugins(){return this._renderPlugins}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlendWorking}modify(e){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:r,removes:t,updates:n}=e;if(0===r.length&&0===t.length&&0===n.length)return;t.forAll((({id:e})=>this._content.delete(e))),r.forAll((e=>this._content.set(e.id,e)));const i=q(e);let a=!1;i.forEach(((e,r)=>{let t=this._materialRenderers.get(r);if(!t){if(!(e.adds.length>0))return;t=new Z(this._rctx,this._materialRepository,r),this._materialRenderers.set(r,t)}t.modify(e),t.isEmpty&&(a=!0)})),a&&this._materialRenderers.forEach(((e,r)=>{e.isEmpty&&(this._materialRenderers.delete(r),e.dispose())})),this._hasHighlights=s(this._materialRenderers,(e=>e.hasHighlights)),this._hasOccludees=s(this._materialRenderers,(e=>e.hasOccludees)),this._hasWater=s(this._materialRenderers,(e=>e.hasWater)),this._requestRender()}updateAnimation(e){return this._hasAnimations=!1,this._materialRenderers.forEach((r=>this._hasAnimations=r.updateAnimation(e)||this._hasAnimations)),this._hasAnimations}get animationTimestep(){return this._animationTimestep}updateLightSources(e,r,t){this._lighting.groundLightingFactor=r,this._lighting.globalFactor=t,this._lighting.set(e)}render(e,r,t,s){this._isRendering=!0,this.performanceInfo.prerender(this._rctx),this._bindParameters.lighting=this._lighting,this._renderContext.hasOccludees=this._hasOccludees,this._renderContext.transparencyPassType=w.NONE,this._bindParameters.transparencyPassType=w.NONE;const n=this._offscreenRendering;n.needLastFrameColorTexture=this.hasWaterReflection,n.advanceCurrentRenderTarget();const i=this._sliceHelper.plane;s===S.OFF&&(this._sliceHelper.plane=null),this._rctx.bindFramebuffer(e),r.setGLViewport(this._rctx),this.needsShadowCast&&(this.renderPassManager.shadowCastingEnabled=!0),this._renderPlugins.prepareRender(r,t),this.performanceInfo.advance(se.Prepare);const o=this._computeDepthRange(r);this._renderShadowMap(e,r,this._lighting.lightingMainDirection,o),this.performanceInfo.advance(se.Shadowmap),n.initializeFrame(r),this._ensureBindParameters(r),this._renderLinearDepth(),this.performanceInfo.advance(se.Lineardepth),this._accumulateShadows(o,r,t),this._renderNormal(),this.performanceInfo.advance(se.Normals),this._ensureBindParametersSSR(),this._ssaoHelper.computeSSAO(r,n.linearDepthTexture,n.normalTexture),this.performanceInfo.advance(se.SSAO),this._renderContext.pass=G.MATERIAL,n.bindFramebuffer(),this._renderOpaqueGeometry(),this.performanceInfo.advance(se.Opaque);const d=this._multipassTerrain&&!this._opaqueTerrain;this._renderTerrainLinearDepth(d),this._setMultipassFlags(d),this._setTerrainCulling(d),this._renderEdges(Y.OPAQUE),this.performanceInfo.advance(se.OpaqueEdges),this._renderHiddenTransparentEdges(),this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry(),this.performanceInfo.advance(se.Transparent),this._renderGeometryLinearDepth(d);const l=this._renderHUDVisibility();d||this._renderInternalSlot(V.LINE_CALLOUTS),this.performanceInfo.advance(se.Hudvisibility),this._renderEdges(Y.TRANSPARENT,d),this.performanceInfo.advance(se.TransparentEdges),this._renderSlot(V.VOXEL),this._renderTransparentTerrain(),!this._opaqueTerrain&&l&&(d?this._renderLineCallouts(P.OCCLUDED):n.compositeTransparentTerrainOntoHUDVisibility(),this._renderHUD(P.OCCLUDED,n.framebuffer),this.performanceInfo.advance(se.HudOccluded)),this.performanceInfo.advance(se.TransparentTerrain),this._setTerrainCulling(!1),this._opaqueTerrain||(n.compositeTransparentTerrainOntoMain(),d&&(this._renderEdges(Y.OPAQUE),this.performanceInfo.advance(se.OpaqueEdges),this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry(),this.performanceInfo.advance(se.Transparent),this._renderEdges(Y.TRANSPARENT),this.performanceInfo.advance(se.TransparentEdges))),d&&this._renderLineCallouts(P.NOTOCCLUDED),this._setMultipassFlags(!1),this._shadowAccumulator.render(),n.renderToTargets((()=>{this._renderInternalSlot(V.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL),this._renderSlot(V.POSTPROCESSING_ENVIRONMENT_TRANSPARENT),this._renderSlot(V.LASERLINES)}),n.currentColorTarget,n.mainDepth),this.performanceInfo.advance(se.Atmosphere),this._renderPlugins.needsLaserlineWithContrastControl&&n.renderTmpAndCompositeToMain((()=>this._renderSlot(V.LASERLINES_CONTRAST_CONTROL)),$.PremultipliedAlpha),this.performanceInfo.advance(se.Laserline),this._renderOccluded(),this.performanceInfo.advance(se.Occluded);const _=s===S.ON&&this._magnifierHelper.enabled,p=_&&h(e)?this._offscreenRendering.getFramebuffer(this._offscreenRendering.tmpColor,this._offscreenRendering.tmpDepth):e;this._rctx.bindFramebuffer(p);const c=this._offscreenRendering.colorTexture;!this._renderAntiAliasing(this._antialiasing,c)&&a(c)&&this._compositingHelper.composite(c,$.None),this.performanceInfo.advance(se.Antialiasing),this._renderHUD(P.NOTOCCLUDED,p),this.performanceInfo.advance(se.HudNotoccluded),this._renderHighlights(p,this._bindParameters),this.performanceInfo.advance(se.Highlights),_&&this._magnifierHelper.render(this._rctx,this._bindParameters),p!==e&&(this._rctx.bindFramebuffer(e),this._compositingHelper.composite(this._offscreenRendering.tmpColorTexture,$.None)),this._renderContext.lastFrameCamera.copyFrom(this._renderContext.camera),this._sliceHelper.plane=i,this._isRendering=!1,this.onPostRender&&this.onPostRender(),this.performanceInfo.postrender()}finish(e){if(this._hasAnimations||(this._animationTimestep=d(0)),e===H.BACKGROUND){this._rctx.gl.getError();const e=this.performanceInfo.elapsedTime/x;this._animationTimestep=d(Math.max(this._animationTimestep*oe+e*(1-oe),C))}}readDepthPixels(e,r,t,s,n,i){const a=this._offscreenRendering.bindTarget(this._offscreenRendering.linearDepth,this._offscreenRendering.tmpDepth);if(!this._needsLinearDepth){this._ensureBindParameters(e),this._renderContext.camera.setGLViewport(this._rctx),this._rctx.setClearColor(0,0,0,0);const r=ne.COLOR_BUFFER_BIT|ne.DEPTH_BUFFER_BIT|ne.STENCIL_BUFFER_BIT;this._rctx.clearSafe(r),this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_DEPTH)}a.readPixels(r,t,s,n,ie.RGBA,ae.UNSIGNED_BYTE,i)}readAccumulatedShadow(e,r){return this._shadowAccumulator.readAccumulatedShadow(e,r)}_setMultipassFlags(e){this._renderContext.multipassTerrainParams.multipassTerrainEnabled=this._bindParameters.multipassTerrainEnabled=e,this._renderContext.multipassGeometryParams.multipassGeometryEnabled=this._bindParameters.multipassGeometryEnabled=e}_setTerrainCulling(e){this._renderContext.multipassTerrainParams.cullAboveGround=this._bindParameters.cullAboveGround=e}_renderSlot(e){this._renderContext.slot=e,this._renderPlugins.render()}_renderEdges(e,r=!1){const t=this._edgeView;a(t)&&t.shouldRender()&&this._offscreenRendering.renderTmpAndCompositeToMain((()=>t.render(this._bindParameters,e)),$.Alpha,r)}_renderShadowMap(e,r,t,s){const n=this._shadowMap;n.enabled&&(n.start(r,t,s),this.needsShadowHighlight?(this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT,this._shadowMap,(e=>n.takeCascadeSnapshotTo(e,ee))),n.clear(),this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_DEFAULT,this._shadowMap,(e=>{n.takeCascadeSnapshotTo(e,re),this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT)}))):this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_ALL),n.finish(e),r.setGLViewport(this._rctx))}_renderShadowCascades(e,r=this._shadowMap,t=(e=>{})){for(const s of r.getCascades())s.camera.setGLViewport(this._rctx),this._ensureCameraBindParameters(s.camera),this._renderGeometryAndTransparentTerrainPass(e),t(s)}get _needsLinearDepth(){return this._ssaoHelper.enabled||this._renderPlugins.needsLinearDepth||this._hasWater&&this._waterReflectionEnabled||this.needsShadowHighlight||this.needsShadowCast}_renderLinearDepth(){this._needsLinearDepth?this._offscreenRendering.renderToTargets((()=>this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_DEPTH)),this._offscreenRendering.linearDepth,this._offscreenRendering.tmpDepth,[0,0,0,0],!0,!0):this._offscreenRendering.disposeTarget(this._offscreenRendering.linearDepth),this._renderContext.ssrParams.linearDepthTexture=this._bindParameters.linearDepthTexture=this._offscreenRendering.linearDepthTexture}_renderTerrainLinearDepth(e){if(e){const e=this._renderContext.pass;this._renderContext.pass=G.MATERIAL_DEPTH,this._offscreenRendering.renderToTargets((()=>this._renderTransparentTerrain()),this._offscreenRendering.terrainLinearDepth,this._offscreenRendering.tmpDepth,[-1e10,-1e10,-1e10,1],!0,!0),this._renderContext.pass=e}else this._offscreenRendering.disposeTarget(this._offscreenRendering.terrainLinearDepth);this._renderContext.multipassTerrainParams.terrainLinearDepthTexture=this._bindParameters.terrainLinearDepthTexture=this._offscreenRendering.terrainLinearDepthTexture}_renderGeometryLinearDepth(e){if(e){const e=this._renderContext.pass;this._offscreenRendering.renderToTargets((()=>this._renderGeometryPass(G.MATERIAL_DEPTH)),this._offscreenRendering.geometryLinearDepth,this._offscreenRendering.tmpDepth,[1,1,1,1],!0,!0),this._renderContext.pass=e}else this._offscreenRendering.disposeTarget(this._offscreenRendering.geometryLinearDepth);this._renderContext.multipassGeometryParams.geometryLinearDepthTexture=this._bindParameters.geometryLinearDepthTexture=this._offscreenRendering.geometryLinearDepthTexture}get needsNormal(){return this._ssaoHelper.enabled}_renderNormal(){this.needsNormal?this._offscreenRendering.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_NORMAL)}),this._offscreenRendering.normal,this._offscreenRendering.tmpDepth,[0,0,0,0],!0,!0):this._offscreenRendering.disposeTarget(this._offscreenRendering.normal)}get needsDepthRange(){return this._shadowMap.enabled||this.needsShadowCast}_computeDepthRange(e){if(!this.needsDepthRange)return O;const r=L(e,this._content,this._stage.layers);return y(r,this.renderPlugins.queryDepthRange(e)),r.near=Math.max(e.near,r.near),r.far=Math.min(e.far,r.far),r}_renderGeometryAndTransparentTerrainPass(e){this._renderContext.pass=e,this._renderGeometryPass(e),this._renderTransparentTerrain()}_renderGeometryPass(e){this._renderContext.pass=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderOpaqueGeometry(){this._renderSlot(V.INTEGRATED_MESH),this._renderSlot(V.OPAQUE_TERRAIN),this._renderInternalSlot(V.OPAQUE_MATERIAL),this._renderSlot(V.OPAQUE_PLUGIN),this._renderSlot(V.POSTPROCESSING_ENVIRONMENT_OPAQUE)}_renderTransparentGeometry(){this._renderInternalSlot(V.TRANSPARENT_MATERIAL),this._renderSlot(V.TRANSPARENT_PLUGIN)}_renderTransparentTerrain(){this._renderSlot(V.TRANSPARENT_TERRAIN)}_renderHUDVisibility(){let e=!1;return this._renderContext.offscreenRenderingHelper&&this._renderContext.offscreenRenderingHelper.renderHUDVisibility((()=>{this._bindParameters.hudVisibilityTexture=this._renderContext.offscreenRenderingHelper?this._renderContext.offscreenRenderingHelper.hudVisibilityTexture:null,e=this._renderInternalSlot(V.OCCLUSION_PIXELS)}),this._multipassTerrain&&!this._opaqueTerrain),e}_renderLineCallouts(e){this._bindParameters.renderTransparentlyOccludedHUD=e,e===P.OCCLUDED?this._offscreenRendering.renderToTargets((()=>this._renderInternalSlot(V.LINE_CALLOUTS)),this._offscreenRendering.currentColorTarget,this._offscreenRendering.tmpDepth,void 0,!0,!0):this._renderInternalSlot(V.LINE_CALLOUTS)}_renderHUD(e,r){this._oitEnabled?(this._renderOrderIndependentTransparency((()=>this._renderHUDElements(e)),!0),this._rctx.bindFramebuffer(r),this._compositingHelper.composite(this._offscreenRendering.hudColorTexture,$.PremultipliedAlpha)):e===P.OCCLUDED?this._offscreenRendering.renderToTargets((()=>this._renderHUDElements(P.OCCLUDED)),this._offscreenRendering.currentColorTarget,this._offscreenRendering.tmpDepth,void 0,!0,!0):this._renderHUDElements(e)}_renderHUDElements(e){this._bindParameters.renderTransparentlyOccludedHUD=e,this._renderInternalSlot(V.LINE_CALLOUTS_HUD_DEPTH),this._renderInternalSlot(V.HUD_MATERIAL),this._renderInternalSlot(V.LABEL_MATERIAL)}get needsHighlight(){return this._hasHighlights||this._renderPlugins.needsHighlight}get needsShadowHighlight(){return this._shadowMap.enabled&&this._shadowHighlightHelper.isVisible&&this.needsHighlight}_renderHighlights(e,r){if(!this.needsHighlight)return void this._offscreenRendering.disposeTarget(this._offscreenRendering.highlight);const t=this._highlightHelper,s=t.profilingCallback&&he(this._renderContext.rctx);this._renderContext.highlightDepthTexture=r.highlightDepthTexture;const n=this._offscreenRendering.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_HIGHLIGHT),this._rctx.clearSafe(ne.DEPTH_BUFFER_BIT),this._renderHUDElements(P.BOTH)}),this._offscreenRendering.highlight,this._offscreenRendering.tmpDepth,[0,0,0,0],!0,!0);this._bindParameters.highlightColorTexture=n.colorTexture,this.needsShadowHighlight&&this._shadowHighlightHelper.render(r,e),t.render(this._renderContext.camera,n,e),a(s)&&t.profilingCallback&&s.stop((e=>{t.profilingCallback&&t.profilingCallback(e)}))}get needsShadowCast(){return this._shadowAccumulator.isAccumulating}_accumulateShadows(e,r,t){this.needsShadowCast&&(this._shadowAccumulator.setAccumulationDependencies(this._offscreenRendering.linearDepthTexture,e,r,t),this._shadowAccumulator.accumulateFixedSamples(),this.renderPassManager.shadowCastingEnabled=this._shadowMap.enabled)}_renderOrderIndependentTransparency(e,r){const t=t=>{this._renderContext.transparencyPassType=t,this._bindParameters.transparencyPassType=this._renderContext.transparencyPassType,this._offscreenRendering.renderOITPass((()=>e()),t,r)},s=this._renderContext.pass;this._renderContext.pass=G.MATERIAL_ALPHA,t(w.Alpha),this._renderContext.pass=G.MATERIAL,t(w.Color),t(w.FrontFace),this._offscreenRendering.compositeTransparentOntoOpaque(r),this._renderContext.transparencyPassType=w.NONE,this._bindParameters.transparencyPassType=this._renderContext.transparencyPassType,this._renderContext.pass=s}_renderOccluded(){let e=0;this._materialRenderers.forEach(((r,t)=>{t&&t.isVisible()&&t.renderOccluded===N.OccludeAndTransparentStencil&&(e|=t.renderOccluded,pe.push(t))}));const r=this._offscreenRendering,t=(t,s,n,i,a)=>{0!=(e&s)&&(r.renderToTargets(n,r.tmpColor,r.mainDepth,[0,0,0,0],i,a),r.compositeOccludedOntoMain(t))};0!==pe.length&&(this._renderInternalSlot(V.OCCLUDER_MATERIAL,pe),t(.5,N.OccludeAndTransparentStencil,(()=>this._renderInternalSlot(V.TRANSPARENT_OCCLUDER_MATERIAL,pe)),!1,!1),pe.length=0),this._materialRenderers.forEach(((r,t)=>{t&&t.isVisible()&&(t.renderOccluded===N.OccludeAndTransparent||t.renderOccluded===N.Transparent||t.renderOccluded===N.Opaque)&&(e|=t.renderOccluded,_e.push(t))}));const s=this._renderPlugins.renderOccludedFlags;if(e|=s,!e)return;const n=e=>{this._renderContext.renderOccludedMask=e,s>N.Occlude&&this._renderSlot(V.OCCLUDED_TERRAIN),this._renderInternalSlot(V.OPAQUE_MATERIAL,_e),this._renderInternalSlot(V.TRANSPARENT_MATERIAL,_e),this._renderInternalSlot(V.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL,_e),this._renderContext.resetRenderOccludedMask()};this._renderContext.pass=G.MATERIAL,t(.5,N.OccludeAndTransparent,(()=>n(N.OccludeAndTransparent)),!0,D.OutlineVisualElementMask),t(.5,N.Transparent,(()=>n(N.Transparent)),!0,D.OutlineVisualElementMask),t(1,N.Opaque,(()=>n(N.Opaque)),!0,D.OutlineVisualElementMask),_e.length=0}_renderAntiAliasing(e,r){if(e===b.SMAA){if(this._smaaPass.enable((()=>this._requestRender()))&&a(r))return this._smaaPass.render(r),!0}else this._smaaPass.disable();return!1}_ensureCameraBindParameters(e){this._renderContext.camera=e,this._bindParameters.camera=this._renderContext.camera,this._bindParameters.inverseViewport[0]=1/this._renderContext.camera.fullViewport[2],this._bindParameters.inverseViewport[1]=1/this._renderContext.camera.fullViewport[3]}_ensureBindParameters(e){var r;this._ensureCameraBindParameters(e);const t=this._renderContext.offscreenRenderingHelper;this._bindParameters.shadowMap=this._renderContext.shadowMap,this._bindParameters.shadowMappingEnabled=this._renderContext.shadowMap.enabled,this._bindParameters.ssaoHelper=this._renderContext.ssaoHelper,this._bindParameters.ssaoEnabled=this._renderContext.ssaoHelper.enabled,this._bindParameters.slicePlane=this._renderContext.sliceHelper.plane,this._bindParameters.hasOccludees=this._renderContext.hasOccludees,this._renderContext.multipassTerrainParams.camera=this._renderContext.camera,this._bindParameters.hudVisibilityTexture=t.hudVisibilityTexture,this._bindParameters.highlightDepthTexture=null!=(r=t.depthTexture)?r:this._getFallbackDepthTexture()}_ensureBindParametersSSR(){this.hasWaterReflection?(this._renderContext.lastFrameCamera.equals(this._renderContext.camera)?this._renderContext.ssrParams.reprojectionMatrix=this._reprojectionMatrix=f:(m(ce,this._renderContext.lastFrameCamera.viewMatrix,this._bindParameters.origin?this._bindParameters.origin:[0,0,0]),m(ue,this._renderContext.camera.viewMatrix,this._bindParameters.origin?this._bindParameters.origin:[0,0,0]),u(ue,ue),u(me,this._renderContext.camera.projectionMatrix),g(ge,ue,me),g(ge,ce,ge),g(ge,this._renderContext.lastFrameCamera.projectionMatrix,ge),this._renderContext.ssrParams.reprojectionMatrix=this._reprojectionMatrix=ge),this._renderContext.ssrParams.camera=this._renderContext.camera,this._renderContext.ssrParams.lastFrameColorTexture=this._bindParameters.lastFrameColorTexture=this._offscreenRendering.lastFrameColorTexture):this._renderContext.ssrParams.lastFrameColorTexture=this._bindParameters.lastFrameColorTexture=null,this._renderContext.ssrParams.ssrEnabled=this._bindParameters.ssrEnabled=this.hasWaterReflection}_renderInternalSlot(e,r){let t=!1;return this._bindParameters.slot=e,a(r)?r.forEach((r=>{if(!r.shouldRender(this._renderContext))return;const s=this._materialRenderers.get(r);a(s)&&(t=s.render(e,this._renderContext.pass,this._bindParameters)||t)})):this._materialRenderers.forEach(((r,s)=>{s.shouldRender(this._renderContext)&&(t=r.render(e,this._renderContext.pass,this._bindParameters)||t)})),t}_getFallbackDepthTexture(){return this._fallbackDepthStencilTexture||(this._fallbackDepthStencilTexture=I(this._rctx)),this._fallbackDepthStencilTexture}get gpuMemoryUsage(){var e,r,t,s,n,i,a,h,o,d;return{offscreen:null!=(e=null==(r=this._offscreenRendering)?void 0:r.gpuMemoryUsage)?e:0,highlights:(null!=(t=null==(s=this._highlightHelper)?void 0:s.gpuMemoryUsage)?t:0)+(null!=(n=null==(i=this._shadowHighlightHelper)?void 0:i.gpuMemoryUsage)?n:0),shadows:null!=(a=null==(h=this._shadowMap)?void 0:h.gpuMemoryUsage)?a:0,ssao:null!=(o=null==(d=this._ssaoHelper)?void 0:d.gpuMemoryUsage)?o:0}}get test(){const e=this;return{offscreen:this._offscreenRendering,shadowMap:this._shadowMap,ssao:this._ssaoHelper,highlight:this._highlightHelper,lighting:this._lighting,materialRenderers:this._materialRenderers,shadowAccumulator:this._shadowAccumulator,getFramebufferTexture:r=>{var t;switch(r){case le.Color:return e._offscreenRendering.colorTexture;case le.LinearDepth:return e._offscreenRendering.linearDepthTexture;case le.Normals:return e._offscreenRendering.normalTexture;case le.ShadowMap:return null==(t=e._shadowMap)?void 0:t.test.depthTexture;case le.HudVisibility:return e._offscreenRendering.hudVisibilityTexture;case le.Highlight:return e._offscreenRendering.highlightTexture}}}}};var le;e([_()],de.prototype,"_shadowAccumulator",void 0),e([_()],de.prototype,"_smaaPass",void 0),e([_()],de.prototype,"_antialiasing",void 0),e([_()],de.prototype,"_edgeView",void 0),e([_()],de.prototype,"updating",null),e([_()],de.prototype,"isCameraFinal",null),de=e([p("esri.views.3d.webgl-engine.lib.Renderer")],de),function(e){e[e.Color=0]="Color",e[e.LinearDepth=1]="LinearDepth",e[e.Normals=2]="Normals",e[e.ShadowMap=3]="ShadowMap",e[e.HudVisibility=4]="HudVisibility",e[e.Highlight=5]="Highlight"}(le||(le={}));const _e=[],pe=[],ce=T(),me=T(),ue=T(),ge=T();export{le as FramebufferId,de as Renderer};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import r from"../../../../core/Accessor.js";import t from"../../../../core/Handles.js";import{someMap as s}from"../../../../core/MapUtils.js";import{destroyMaybe as n,disposeMaybe as i,isSome as a,isNone as h,unwrap as o}from"../../../../core/maybe.js";import{Milliseconds as d}from"../../../../core/time.js";import{init as l}from"../../../../core/watchUtils.js";import{property as _}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/arrayUtils.js";import"../../../../core/has.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../../../core/accessorSupport/decorators/subclass.js";import{v as c,j as m,a as u,m as g}from"../../../../chunks/mat4.js";import{I as f,c as T}from"../../../../chunks/mat4f64.js";import{a as R}from"../../../../chunks/vec2f64.js";import{MAXIMUM_ANIMATION_LOAD as E,MINIMUM_IDLE_ANIMATION_MS as A}from"../../support/animationUtils.js";import x from"../../support/debugFlags.js";import{RenderPassManager as C}from"../core/renderPasses/RenderPassManager.js";import{HUDTransparentRenderStyle as P}from"../core/shaderLibrary/hud/HUDUniforms.js";import{AntiAliasingMode as b,TransparencyPassType as w,Decorations as S,RenderRequestType as H,StencilBits as D}from"./basicInterfaces.js";import{BoundingInfo as M}from"./BoundingInfo.js";import{ZERO as O,union as L}from"./depthRange.js";import{depthRangeFromScene as I}from"./depthRangeUtils.js";import{createEmptyDepthTexture as y}from"./glUtil3D.js";import N from"./HighlightHelper.js";import{RenderOccludedFlag as v}from"./Material.js";import{OffscreenRendering as U}from"./OffscreenRendering.js";import{RenderContext as j}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as q}from"./rendererUtils.js";import{RenderPass as G}from"./RenderPass.js";import{RenderPluginManager as F}from"./RenderPluginManager.js";import{RenderSlot as V}from"./RenderSlot.js";import{ShadowAccumulator as B}from"./ShadowAccumulator.js";import{ShadowHighlightHelper as k}from"./ShadowHighlightHelper.js";import W from"./ShadowMap.js";import Q from"./SliceHelper.js";import{SmaaRenderPass as z}from"./SmaaRenderPass.js";import{SSAOHelper as X}from"./SSAOHelper.js";import{EdgeView as K}from"./edgeRendering/EdgeView.js";import{Transparency as Y}from"./edgeRendering/interfaces.js";import{SceneLighting as J}from"../lighting/SceneLighting.js";import{MergedRenderer as Z}from"../materials/renderers/MergedRenderer.js";import{AlphaMode as $}from"../shaders/CompositingTechnique.js";import{HighlightShadowMapSlot as ee,DefaultSnapshotSlot as re}from"../shaders/ShadowHighlightTechnique.js";import{RendererPerformanceInfo as te,Statistics as se}from"../statistics/RendererPerformanceInfo.js";import{ClearBufferBit as ne,PixelFormat as ie,PixelType as ae}from"../../../webgl/enums.js";import{startMeasurement as he}from"../../../webgl/Measurement.js";const oe=.9;let de=class extends r{constructor(e,r,s,n,i,a,h,o,_){super({}),this._materialRepository=e,this._shaderTechniqueRepository=s,this._rctx=n,this._compositingHelper=i,this._magnifierHelper=a,this._requestRender=h,this._stage=_,this._materialRenderers=new Map,this._needsTransparentPass=!1,this._hasHUDElements=!1,this._hasHighlights=!1,this._hasOccludees=!1,this._hasWater=!1,this._hasOverlayWater=!1,this._content=new Map,this._isRendering=!1,this._fallbackDepthStencilTexture=null,this.performanceInfo=new te,this._antialiasing=b.SMAA,this._oitEnabled=!1,this._multipassTerrain=!0,this._opaqueTerrain=!0,this._lighting=new J,this._hasAnimations=!1,this._animationTimestep=d(0),this._handles=new t,this._renderHiddenTransparentEdges=()=>{},this._oitUsed=!1,this._smaaPass=new z(this._rctx,s),this._oitEnabled=this._hasOITSupport,this._requestRender(),this._offscreenRendering=new U(this._rctx,this._compositingHelper),this._sliceHelper=new Q,this._shadowMap=new W(this._rctx,_.viewingMode,2),this._ssaoHelper=new X(s,this._rctx,(()=>this._requestRender())),this._highlightHelper=new N(s,this._rctx),this._shadowHighlightHelper=new k(this._rctx,_.viewingMode),this._shadowAccumulator=new B(this._rctx,s,_,((e,r)=>{this.renderPassManager.shadowCastingEnabled=!0,this._renderPlugins.prepareRender(e,r),this.renderPassManager.shadowCastingEnabled=this._shadowMap.enabled}),((e,r,t,s)=>{e.start(t,r,s),this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_ALL,e),t.setGLViewport(this._rctx),this._ensureCameraBindParameters(t)}),(()=>this._requestRender())),this._bindParameters={slot:null,camera:null,inverseViewport:R(),shadowMap:this._shadowMap,shadowMappingEnabled:this._shadowMap.enabled,ssaoHelper:this._ssaoHelper,ssaoEnabled:this._ssaoHelper.enabled,origin:null,screenToWorldRatio:null,screenToPCSRatio:null,slicePlane:this._sliceHelper.plane,highlightDepthTexture:null,hasOccludees:!1,linearDepthTexture:null,terrainLinearDepthTexture:null,geometryLinearDepthTexture:null,multipassTerrainEnabled:!1,multipassGeometryEnabled:!1,cullAboveGround:!1,lastFrameColorTexture:null,reprojectionMatrix:f,ssrEnabled:!1,lighting:this._lighting,highlightColorTexture:null},this._renderContext=new j(this._rctx,this._offscreenRendering,this._lighting,this._shadowMap,this._ssaoHelper,this._sliceHelper),this._renderContext.multipassTerrainParams={camera:null,multipassTerrainEnabled:!1,cullAboveGround:!1,terrainLinearDepthTexture:null},this._renderContext.multipassGeometryParams={multipassGeometryEnabled:!1,geometryLinearDepthTexture:null},this._renderContext.ssrParams={camera:null,linearDepthTexture:null,lastFrameColorTexture:null,reprojectionMatrix:f,ssrEnabled:!1},this._renderPlugins=new F({renderContext:this._renderContext,shaderTechniqueRep:s,textureRep:r,materialRep:this._materialRepository,requestRender:this._requestRender,schedule:o}),this.renderPassManager=new C(this._rctx,this._shaderTechniqueRepository),this._renderPlugins.add(this.renderPassManager.slots(),this.renderPassManager),this._handles.add([l(x,"EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES",(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(Y.TRANSPARENT):()=>{},this._requestRender()})),l(this._stage,"camera",(()=>this._requestRender()),!0)])}get hasWater(){return this._hasWater||this._hasOverlayWater}get hasWaterReflection(){return this.hasWater&&this._waterReflectionEnabled}normalizeCtorArgs(){return{}}dispose(){this._handles.destroy(),this._smaaPass.dispose(),this._materialRenderers.forEach((e=>e.dispose())),this._materialRenderers.clear(),this._edgeView=n(this._edgeView),this._offscreenRendering.dispose(),this._fallbackDepthStencilTexture=i(this._fallbackDepthStencilTexture),this._shadowMap.enabled=!1,this._shadowMap.dispose(),this._ssaoHelper.enabled=!1,this._ssaoHelper.dispose(),this._highlightHelper.dispose(),this._shadowHighlightHelper.dispose(),this._shadowAccumulator.dispose(),M.prune(),this._content.clear()}get updating(){return this._antialiasing===b.SMAA&&this._smaaPass.updating||a(this._edgeView)&&this._edgeView.updating||this._shadowAccumulator.running||!this.isCameraFinal}ensureEdgeView(){return h(this._edgeView)&&(this._edgeView=new K({rctx:this._rctx,renderSR:this._stage.renderSR,techniqueRepository:this._shaderTechniqueRepository,setNeedsRender:()=>this._requestRender(),schedule:e=>this._stage.resourceController.schedule(e)}),this._handles.add(this._edgeView.watch("updating",(()=>this._requestRender()),!0)),this._requestRender()),this._edgeView}get edgeView(){return this._edgeView}get isCameraFinal(){return null===this._bindParameters.reprojectionMatrix||c(this._bindParameters.reprojectionMatrix,f)}set _reprojectionMatrix(e){c(this._bindParameters.reprojectionMatrix,e)||(this._bindParameters.reprojectionMatrix=e,this.notifyChange("isCameraFinal"))}get hasShadowsEnabled(){var e;return!(null==(e=this._shadowMap)||!e.enabled)}setRenderParameters(e){const{renderPassManager:r,_shadowMap:t,_ssaoHelper:s}=this;void 0!==e.screenSpaceReflectionsEnabled&&r.screenSpaceReflectionsEnabled!==e.screenSpaceReflectionsEnabled&&(r.screenSpaceReflectionsEnabled=e.screenSpaceReflectionsEnabled,this._requestRender()),void 0===e.shadowMap||t.enabled===e.shadowMap&&r.shadowCastingEnabled===e.shadowMap||(t.enabled=e.shadowMap,r.shadowCastingEnabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&t.maxCascades!==e.shadowMapMaxCascades&&(t.maxCascades=e.shadowMapMaxCascades,this._requestRender()),void 0!==e.ssao&&s.enabled!==e.ssao&&(s.enabled=e.ssao,this._requestRender()),e.background&&this._offscreenRendering.background!==e.background&&(this._offscreenRendering.background=e.background,this._requestRender());const n=e.antialiasingEnabled?b.SMAA:b.NONE;void 0!==e.antialiasingEnabled&&this._antialiasing!==n&&(this._antialiasing=n,this._requestRender()),void 0!==e.highQualityTransparency&&this._multipassTerrain!==e.highQualityTransparency&&(this._multipassTerrain=e.highQualityTransparency,this._oitEnabled=e.highQualityTransparency&&this._hasOITSupport,this._requestRender()),void 0!==e.defaultHighlightOptions&&(this._highlightHelper.setDefaultOptions(e.defaultHighlightOptions),this._shadowHighlightHelper.setDefaultOptions(e.defaultHighlightOptions),this._requestRender()),void 0!==e.slicePlane&&this._sliceHelper.plane!==e.slicePlane&&(this._sliceHelper.plane=o(e.slicePlane),this._requestRender()),void 0!==e.waterReflectionEnabled&&this._waterReflectionEnabled!==e.waterReflectionEnabled&&(this._waterReflectionEnabled=e.waterReflectionEnabled,this._requestRender()),void 0!==e.opaqueTerrain&&this._opaqueTerrain!==e.opaqueTerrain&&(this._opaqueTerrain=e.opaqueTerrain,this._requestRender()),void 0!==e.hasOverlayWater&&this._hasOverlayWater!==e.hasOverlayWater&&(this._hasOverlayWater=e.hasOverlayWater,this._requestRender()),void 0!==e.shadowCastOptions&&this._shadowAccumulator.setOptions(e.shadowCastOptions)}get hasSlicePlane(){return!!this._sliceHelper.plane}get renderPlugins(){return this._renderPlugins}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlendWorking}modify(e){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:r,removes:t,updates:n}=e;if(0===r.length&&0===t.length&&0===n.length)return;t.forAll((({id:e})=>this._content.delete(e))),r.forAll((e=>this._content.set(e.id,e)));const i=q(e);let a=!1;i.forEach(((e,r)=>{let t=this._materialRenderers.get(r);if(!t){if(!(e.adds.length>0))return;t=new Z(this._rctx,this._materialRepository,r),this._materialRenderers.set(r,t)}t.modify(e),t.isEmpty&&(a=!0)})),a&&this._materialRenderers.forEach(((e,r)=>{e.isEmpty&&(this._materialRenderers.delete(r),e.dispose())})),this._hasHighlights=s(this._materialRenderers,(e=>e.hasHighlights)),this._hasOccludees=s(this._materialRenderers,(e=>e.hasOccludees)),this._hasWater=s(this._materialRenderers,(e=>e.hasWater)),this._needsTransparentPass=s(this._materialRenderers,(e=>e.requiresSlot(V.TRANSPARENT_MATERIAL,G.MATERIAL))),this._hasHUDElements=s(this._materialRenderers,(e=>e.requiresSlot(V.LINE_CALLOUTS_HUD_DEPTH,G.MATERIAL)||e.requiresSlot(V.HUD_MATERIAL,G.MATERIAL)||e.requiresSlot(V.LABEL_MATERIAL,G.MATERIAL))),this._requestRender()}updateAnimation(e){return this._hasAnimations=!1,this._materialRenderers.forEach((r=>this._hasAnimations=r.updateAnimation(e)||this._hasAnimations)),this._hasAnimations}get animationTimestep(){return this._animationTimestep}updateLightSources(e,r,t){this._lighting.groundLightingFactor=r,this._lighting.globalFactor=t,this._lighting.set(e)}render(e,r,t,s){this._isRendering=!0,this.performanceInfo.prerender(this._rctx),this._bindParameters.lighting=this._lighting,this._renderContext.hasOccludees=this._hasOccludees,this._renderContext.transparencyPassType=w.NONE,this._bindParameters.transparencyPassType=w.NONE;const n=this._offscreenRendering;n.needLastFrameColorTexture=this.hasWaterReflection,n.advanceCurrentRenderTarget();const i=this._sliceHelper.plane;s===S.OFF&&(this._sliceHelper.plane=null),this._rctx.bindFramebuffer(e),r.setGLViewport(this._rctx),this.needsShadowCast&&(this.renderPassManager.shadowCastingEnabled=!0),this._renderPlugins.prepareRender(r,t),this.performanceInfo.advance(se.Prepare);const o=this._computeDepthRange(r);this._renderShadowMap(e,r,this._lighting.lightingMainDirection,o),this.performanceInfo.advance(se.Shadowmap),n.initializeFrame(r),this._ensureBindParameters(r),this._renderLinearDepth(),this.performanceInfo.advance(se.Lineardepth),this._accumulateShadows(o,r,t),this._renderNormal(),this.performanceInfo.advance(se.Normals),this._ensureBindParametersSSR(),this._ssaoHelper.computeSSAO(r,n.linearDepthTexture,n.normalTexture),this.performanceInfo.advance(se.SSAO),this._renderContext.pass=G.MATERIAL,n.bindFramebuffer(),this._renderOpaqueGeometry(),this.performanceInfo.advance(se.Opaque);const d=this._multipassTerrain&&!this._opaqueTerrain;this._renderTerrainLinearDepth(d),this._setMultipassFlags(d),this._setTerrainCulling(d),this._renderEdges(Y.OPAQUE),this.performanceInfo.advance(se.OpaqueEdges),this._renderHiddenTransparentEdges();const l=this._needsTransparentPass||this._renderPlugins.needsTransparentPass;l&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(se.Transparent),this._renderGeometryLinearDepth(d);const _=this._renderHUDVisibility();d||this._renderInternalSlot(V.LINE_CALLOUTS),this.performanceInfo.advance(se.Hudvisibility),this._renderEdges(Y.TRANSPARENT,d),this.performanceInfo.advance(se.TransparentEdges),this._renderSlot(V.VOXEL),this._renderTransparentTerrain(),!this._opaqueTerrain&&_&&(d?this._renderLineCallouts(P.OCCLUDED):n.compositeTransparentTerrainOntoHUDVisibility(),this._renderHUD(P.OCCLUDED,n.framebuffer),this.performanceInfo.advance(se.HudOccluded)),this.performanceInfo.advance(se.TransparentTerrain),this._setTerrainCulling(!1),this._opaqueTerrain||(n.compositeTransparentTerrainOntoMain(),d&&(this._renderEdges(Y.OPAQUE),this.performanceInfo.advance(se.OpaqueEdges),l&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(se.Transparent),this._renderEdges(Y.TRANSPARENT),this.performanceInfo.advance(se.TransparentEdges))),d&&this._renderLineCallouts(P.NOTOCCLUDED),this._setMultipassFlags(!1),this._shadowAccumulator.render(),n.renderToTargets((()=>{this._renderInternalSlot(V.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL),this._renderSlot(V.POSTPROCESSING_ENVIRONMENT_TRANSPARENT),this._renderSlot(V.LASERLINES)}),n.currentColorTarget,n.mainDepth),this.performanceInfo.advance(se.Atmosphere),this._renderPlugins.needsLaserlineWithContrastControl&&n.renderTmpAndCompositeToMain((()=>this._renderSlot(V.LASERLINES_CONTRAST_CONTROL)),$.PremultipliedAlpha),this.performanceInfo.advance(se.Laserline),this._renderOccluded(),this.performanceInfo.advance(se.Occluded);const p=s===S.ON&&this._magnifierHelper.enabled,c=p&&h(e)?this._offscreenRendering.getFramebuffer(this._offscreenRendering.tmpColor,this._offscreenRendering.tmpDepth):e;this._rctx.bindFramebuffer(c);const m=this._offscreenRendering.colorTexture;!this._renderAntiAliasing(this._antialiasing,m)&&a(m)&&this._compositingHelper.composite(m,$.None),this.performanceInfo.advance(se.Antialiasing),this._renderHUD(P.NOTOCCLUDED,c),this.performanceInfo.advance(se.HudNotoccluded),this._renderHighlights(c,this._bindParameters),this.performanceInfo.advance(se.Highlights),p&&this._magnifierHelper.render(this._rctx,this._bindParameters),c!==e&&(this._rctx.bindFramebuffer(e),this._compositingHelper.composite(this._offscreenRendering.tmpColorTexture,$.None)),this._disposeOITBuffers(),this._renderContext.lastFrameCamera.copyFrom(this._renderContext.camera),this._sliceHelper.plane=i,this._isRendering=!1,this.onPostRender&&this.onPostRender(),this.performanceInfo.postrender()}finish(e){if(this._hasAnimations||(this._animationTimestep=d(0)),e===H.BACKGROUND){this._rctx.gl.getError();const e=this.performanceInfo.elapsedTime/E;this._animationTimestep=d(Math.max(this._animationTimestep*oe+e*(1-oe),A))}}readDepthPixels(e,r,t,s,n,i){const a=this._offscreenRendering.bindTarget(this._offscreenRendering.linearDepth,this._offscreenRendering.tmpDepth);if(!this._needsLinearDepth){this._ensureBindParameters(e),this._renderContext.camera.setGLViewport(this._rctx),this._rctx.setClearColor(0,0,0,0);const r=ne.COLOR_BUFFER_BIT|ne.DEPTH_BUFFER_BIT|ne.STENCIL_BUFFER_BIT;this._rctx.clearSafe(r),this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_DEPTH)}a.readPixels(r,t,s,n,ie.RGBA,ae.UNSIGNED_BYTE,i)}readAccumulatedShadow(e,r){return this._shadowAccumulator.readAccumulatedShadow(e,r)}_setMultipassFlags(e){this._renderContext.multipassTerrainParams.multipassTerrainEnabled=this._bindParameters.multipassTerrainEnabled=e,this._renderContext.multipassGeometryParams.multipassGeometryEnabled=this._bindParameters.multipassGeometryEnabled=e}_setTerrainCulling(e){this._renderContext.multipassTerrainParams.cullAboveGround=this._bindParameters.cullAboveGround=e}_renderSlot(e){this._renderContext.slot=e,this._renderPlugins.render()}_renderEdges(e,r=!1){const t=this._edgeView;a(t)&&t.shouldRender()&&this._offscreenRendering.renderTmpAndCompositeToMain((()=>t.render(this._bindParameters,e)),$.Alpha,r)}_renderShadowMap(e,r,t,s){const n=this._shadowMap;n.enabled&&(n.start(r,t,s),this.needsShadowHighlight?(this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT,this._shadowMap,(e=>n.takeCascadeSnapshotTo(e,ee))),n.clear(),this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_DEFAULT,this._shadowMap,(e=>{n.takeCascadeSnapshotTo(e,re),this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT)}))):this._renderShadowCascades(G.MATERIAL_DEPTH_SHADOWMAP_ALL),n.finish(e),r.setGLViewport(this._rctx))}_renderShadowCascades(e,r=this._shadowMap,t=(e=>{})){for(const s of r.getCascades())s.camera.setGLViewport(this._rctx),this._ensureCameraBindParameters(s.camera),this._renderGeometryAndTransparentTerrainPass(e),t(s)}get _needsLinearDepth(){return this._ssaoHelper.enabled||this._renderPlugins.needsLinearDepth||this._hasWater&&this._waterReflectionEnabled||this.needsShadowHighlight||this.needsShadowCast}_renderLinearDepth(){this._needsLinearDepth?this._offscreenRendering.renderToTargets((()=>this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_DEPTH)),this._offscreenRendering.linearDepth,this._offscreenRendering.tmpDepth,[0,0,0,0],!0,!0):this._offscreenRendering.disposeTarget(this._offscreenRendering.linearDepth),this._renderContext.ssrParams.linearDepthTexture=this._bindParameters.linearDepthTexture=this._offscreenRendering.linearDepthTexture}_renderTerrainLinearDepth(e){if(e){const e=this._renderContext.pass;this._renderContext.pass=G.MATERIAL_DEPTH,this._offscreenRendering.renderToTargets((()=>this._renderTransparentTerrain()),this._offscreenRendering.terrainLinearDepth,this._offscreenRendering.tmpDepth,[-1e10,-1e10,-1e10,1],!0,!0),this._renderContext.pass=e}else this._offscreenRendering.disposeTarget(this._offscreenRendering.terrainLinearDepth);this._renderContext.multipassTerrainParams.terrainLinearDepthTexture=this._bindParameters.terrainLinearDepthTexture=this._offscreenRendering.terrainLinearDepthTexture}_renderGeometryLinearDepth(e){if(e){const e=this._renderContext.pass;this._offscreenRendering.renderToTargets((()=>this._renderGeometryPass(G.MATERIAL_DEPTH)),this._offscreenRendering.geometryLinearDepth,this._offscreenRendering.tmpDepth,[1,1,1,1],!0,!0),this._renderContext.pass=e}else this._offscreenRendering.disposeTarget(this._offscreenRendering.geometryLinearDepth);this._renderContext.multipassGeometryParams.geometryLinearDepthTexture=this._bindParameters.geometryLinearDepthTexture=this._offscreenRendering.geometryLinearDepthTexture}get needsNormal(){return this._ssaoHelper.enabled}_renderNormal(){this.needsNormal?this._offscreenRendering.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_NORMAL)}),this._offscreenRendering.normal,this._offscreenRendering.tmpDepth,[0,0,0,0],!0,!0):this._offscreenRendering.disposeTarget(this._offscreenRendering.normal)}get needsDepthRange(){return this._shadowMap.enabled||this.needsShadowCast}_computeDepthRange(e){if(!this.needsDepthRange)return O;const r=I(e,this._content,this._stage.layers);return L(r,this.renderPlugins.queryDepthRange(e)),r.near=Math.max(e.near,r.near),r.far=Math.min(e.far,r.far),r}_renderGeometryAndTransparentTerrainPass(e){this._renderContext.pass=e,this._renderGeometryPass(e),this._renderTransparentTerrain()}_renderGeometryPass(e){this._renderContext.pass=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderOpaqueGeometry(){this._renderSlot(V.INTEGRATED_MESH),this._renderSlot(V.OPAQUE_TERRAIN),this._renderInternalSlot(V.OPAQUE_MATERIAL),this._renderSlot(V.OPAQUE_PLUGIN),this._renderSlot(V.POSTPROCESSING_ENVIRONMENT_OPAQUE)}_renderTransparentGeometry(){this._renderInternalSlot(V.TRANSPARENT_MATERIAL),this._renderSlot(V.TRANSPARENT_PLUGIN)}_renderTransparentTerrain(){this._renderSlot(V.TRANSPARENT_TERRAIN)}_renderHUDVisibility(){let e=!1;return this._renderContext.offscreenRenderingHelper&&this._renderContext.offscreenRenderingHelper.renderHUDVisibility((()=>{this._bindParameters.hudVisibilityTexture=this._renderContext.offscreenRenderingHelper.hudVisibilityTexture,e=this._renderInternalSlot(V.OCCLUSION_PIXELS)}),this._multipassTerrain&&!this._opaqueTerrain),e}_renderLineCallouts(e){this._bindParameters.renderTransparentlyOccludedHUD=e,e===P.OCCLUDED?this._offscreenRendering.renderToTargets((()=>this._renderInternalSlot(V.LINE_CALLOUTS)),this._offscreenRendering.currentColorTarget,this._offscreenRendering.tmpDepth,void 0,!0,!0):this._renderInternalSlot(V.LINE_CALLOUTS)}_renderHUD(e,r){this._hasHUDElements&&(this._oitEnabled?(this._renderOrderIndependentTransparency((()=>this._renderHUDElements(e)),!0),this._rctx.bindFramebuffer(r),this._compositingHelper.composite(this._offscreenRendering.hudColorTexture,$.PremultipliedAlpha)):e===P.OCCLUDED?this._offscreenRendering.renderToTargets((()=>this._renderHUDElements(P.OCCLUDED)),this._offscreenRendering.currentColorTarget,this._offscreenRendering.tmpDepth,void 0,!0,!0):this._renderHUDElements(e))}_renderHUDElements(e){this._bindParameters.renderTransparentlyOccludedHUD=e,this._renderInternalSlot(V.LINE_CALLOUTS_HUD_DEPTH),this._renderInternalSlot(V.HUD_MATERIAL),this._renderInternalSlot(V.LABEL_MATERIAL)}get needsHighlight(){return this._hasHighlights||this._renderPlugins.needsHighlight}get needsShadowHighlight(){return this._shadowMap.enabled&&this._shadowHighlightHelper.isVisible&&this.needsHighlight}_renderHighlights(e,r){if(!this.needsHighlight)return void this._offscreenRendering.disposeTarget(this._offscreenRendering.highlight);const t=this._highlightHelper,s=t.profilingCallback&&he(this._renderContext.rctx);this._renderContext.highlightDepthTexture=r.highlightDepthTexture;const n=this._offscreenRendering.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(G.MATERIAL_HIGHLIGHT),this._rctx.clearSafe(ne.DEPTH_BUFFER_BIT),this._renderHUDElements(P.BOTH)}),this._offscreenRendering.highlight,this._offscreenRendering.tmpDepth,[0,0,0,0],!0,!0);this._bindParameters.highlightColorTexture=n.colorTexture,this.needsShadowHighlight&&this._shadowHighlightHelper.render(r,e),t.render(this._renderContext.camera,n,e),a(s)&&t.profilingCallback&&s.stop((e=>{t.profilingCallback&&t.profilingCallback(e)}))}get needsShadowCast(){return this._shadowAccumulator.isAccumulating}_accumulateShadows(e,r,t){this.needsShadowCast&&(this._shadowAccumulator.setAccumulationDependencies(this._offscreenRendering.linearDepthTexture,e,r,t),this._shadowAccumulator.accumulateFixedSamples(),this.renderPassManager.shadowCastingEnabled=this._shadowMap.enabled)}_renderOrderIndependentTransparency(e,r){const t=t=>{this._renderContext.transparencyPassType=t,this._bindParameters.transparencyPassType=this._renderContext.transparencyPassType,this._offscreenRendering.renderOITPass((()=>e()),t,r)},s=this._renderContext.pass;this._renderContext.pass=G.MATERIAL_ALPHA,t(w.Alpha),this._renderContext.pass=G.MATERIAL,t(w.Color),t(w.FrontFace),this._offscreenRendering.compositeTransparentOntoOpaque(r),this._renderContext.transparencyPassType=w.NONE,this._bindParameters.transparencyPassType=this._renderContext.transparencyPassType,this._renderContext.pass=s,this._oitUsed=!0}_disposeOITBuffers(){this._oitUsed||(this._offscreenRendering.disposeTarget(this._offscreenRendering.alphaFloatTarget),this._offscreenRendering.disposeTarget(this._offscreenRendering.colorFloatTarget),this._offscreenRendering.disposeTarget(this._offscreenRendering.frontFaceTarget)),this._oitUsed=!1}_renderOccluded(){let e=0;this._materialRenderers.forEach(((r,t)=>{t&&t.isVisible()&&t.renderOccluded===v.OccludeAndTransparentStencil&&(e|=t.renderOccluded,pe.push(t))}));const r=this._offscreenRendering,t=(t,s,n,i,a)=>{0!=(e&s)&&(r.renderToTargets(n,r.tmpColor,r.mainDepth,[0,0,0,0],i,a),r.compositeOccludedOntoMain(t))};0!==pe.length&&(this._renderInternalSlot(V.OCCLUDER_MATERIAL,pe),t(.5,v.OccludeAndTransparentStencil,(()=>this._renderInternalSlot(V.TRANSPARENT_OCCLUDER_MATERIAL,pe)),!1,!1),pe.length=0),this._materialRenderers.forEach(((r,t)=>{t&&t.isVisible()&&(t.renderOccluded===v.OccludeAndTransparent||t.renderOccluded===v.Transparent||t.renderOccluded===v.Opaque)&&(e|=t.renderOccluded,_e.push(t))}));const s=this._renderPlugins.renderOccludedFlags;if(e|=s,!e)return;const n=e=>{this._renderContext.renderOccludedMask=e,s>v.Occlude&&this._renderSlot(V.OCCLUDED_TERRAIN),this._renderInternalSlot(V.OPAQUE_MATERIAL,_e),this._renderInternalSlot(V.TRANSPARENT_MATERIAL,_e),this._renderInternalSlot(V.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL,_e),this._renderContext.resetRenderOccludedMask()};this._renderContext.pass=G.MATERIAL,t(.5,v.OccludeAndTransparent,(()=>n(v.OccludeAndTransparent)),!0,D.OutlineVisualElementMask),t(.5,v.Transparent,(()=>n(v.Transparent)),!0,D.OutlineVisualElementMask),t(1,v.Opaque,(()=>n(v.Opaque)),!0,D.OutlineVisualElementMask),_e.length=0}_renderAntiAliasing(e,r){if(e===b.SMAA){if(this._smaaPass.enable((()=>this._requestRender()))&&a(r))return this._smaaPass.render(r),!0}else this._smaaPass.disable();return!1}_ensureCameraBindParameters(e){this._renderContext.camera=e,this._bindParameters.camera=this._renderContext.camera,this._bindParameters.inverseViewport[0]=1/this._renderContext.camera.fullViewport[2],this._bindParameters.inverseViewport[1]=1/this._renderContext.camera.fullViewport[3]}_ensureBindParameters(e){var r;this._ensureCameraBindParameters(e);const t=this._renderContext.offscreenRenderingHelper;this._bindParameters.shadowMap=this._renderContext.shadowMap,this._bindParameters.shadowMappingEnabled=this._renderContext.shadowMap.enabled,this._bindParameters.ssaoHelper=this._renderContext.ssaoHelper,this._bindParameters.ssaoEnabled=this._renderContext.ssaoHelper.enabled,this._bindParameters.slicePlane=this._renderContext.sliceHelper.plane,this._bindParameters.hasOccludees=this._renderContext.hasOccludees,this._renderContext.multipassTerrainParams.camera=this._renderContext.camera,this._bindParameters.hudVisibilityTexture=t.hudVisibilityTexture,this._bindParameters.highlightDepthTexture=null!=(r=t.depthTexture)?r:this._getFallbackDepthTexture()}_ensureBindParametersSSR(){this.hasWaterReflection?(this._renderContext.lastFrameCamera.equals(this._renderContext.camera)?this._renderContext.ssrParams.reprojectionMatrix=this._reprojectionMatrix=f:(m(ce,this._renderContext.lastFrameCamera.viewMatrix,this._bindParameters.origin?this._bindParameters.origin:[0,0,0]),m(ue,this._renderContext.camera.viewMatrix,this._bindParameters.origin?this._bindParameters.origin:[0,0,0]),u(ue,ue),u(me,this._renderContext.camera.projectionMatrix),g(ge,ue,me),g(ge,ce,ge),g(ge,this._renderContext.lastFrameCamera.projectionMatrix,ge),this._renderContext.ssrParams.reprojectionMatrix=this._reprojectionMatrix=ge),this._renderContext.ssrParams.camera=this._renderContext.camera,this._renderContext.ssrParams.lastFrameColorTexture=this._bindParameters.lastFrameColorTexture=this._offscreenRendering.lastFrameColorTexture):this._renderContext.ssrParams.lastFrameColorTexture=this._bindParameters.lastFrameColorTexture=null,this._renderContext.ssrParams.ssrEnabled=this._bindParameters.ssrEnabled=this.hasWaterReflection}_renderInternalSlot(e,r){let t=!1;return this._bindParameters.slot=e,a(r)?r.forEach((r=>{if(!r.shouldRender(this._renderContext))return;const s=this._materialRenderers.get(r);a(s)&&(t=s.render(e,this._renderContext.pass,this._bindParameters)||t)})):this._materialRenderers.forEach(((r,s)=>{s.shouldRender(this._renderContext)&&(t=r.render(e,this._renderContext.pass,this._bindParameters)||t)})),t}_getFallbackDepthTexture(){return this._fallbackDepthStencilTexture||(this._fallbackDepthStencilTexture=y(this._rctx)),this._fallbackDepthStencilTexture}get gpuMemoryUsage(){var e,r,t,s,n,i,a,h,o,d;return{offscreen:null!=(e=null==(r=this._offscreenRendering)?void 0:r.gpuMemoryUsage)?e:0,highlights:(null!=(t=null==(s=this._highlightHelper)?void 0:s.gpuMemoryUsage)?t:0)+(null!=(n=null==(i=this._shadowHighlightHelper)?void 0:i.gpuMemoryUsage)?n:0),shadows:null!=(a=null==(h=this._shadowMap)?void 0:h.gpuMemoryUsage)?a:0,ssao:null!=(o=null==(d=this._ssaoHelper)?void 0:d.gpuMemoryUsage)?o:0}}get test(){const e=this;return{offscreen:this._offscreenRendering,shadowMap:this._shadowMap,ssao:this._ssaoHelper,highlight:this._highlightHelper,lighting:this._lighting,materialRenderers:this._materialRenderers,shadowAccumulator:this._shadowAccumulator,getFramebufferTexture:r=>{var t;switch(r){case le.Color:return e._offscreenRendering.colorTexture;case le.LinearDepth:return e._offscreenRendering.linearDepthTexture;case le.Normals:return e._offscreenRendering.normalTexture;case le.ShadowMap:return null==(t=e._shadowMap)?void 0:t.test.depthTexture;case le.HudVisibility:return e._offscreenRendering.hudVisibilityTexture;case le.Highlight:return e._offscreenRendering.highlightTexture}}}}};var le;e([_()],de.prototype,"_shadowAccumulator",void 0),e([_()],de.prototype,"_smaaPass",void 0),e([_()],de.prototype,"_antialiasing",void 0),e([_()],de.prototype,"_edgeView",void 0),e([_()],de.prototype,"updating",null),e([_()],de.prototype,"isCameraFinal",null),de=e([p("esri.views.3d.webgl-engine.lib.Renderer")],de),function(e){e[e.Color=0]="Color",e[e.LinearDepth=1]="LinearDepth",e[e.Normals=2]="Normals",e[e.ShadowMap=3]="ShadowMap",e[e.HudVisibility=4]="HudVisibility",e[e.Highlight=5]="Highlight"}(le||(le={}));const _e=[],pe=[],ce=T(),me=T(),ue=T(),ge=T();export{le as FramebufferId,de as Renderer};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import{isNone as e}from"../../../../../core/maybe.js";import{isAborted as t,throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{I as a,c as n}from"../../../../../chunks/mat4f64.js";import{a as i}from"../../../../../chunks/vec2f64.js";import{f as r,d as l,m as o}from"../../../../../chunks/vec3.js";import{c}from"../../../../../chunks/vec3f64.js";import{c as h}from"../../../../../chunks/vec4f64.js";import d from"../../../support/debugFlags.js";import{glLayout as u}from"../../../support/buffer/glUtil.js";import{bindOutputHighlight as _}from"../../core/shaderLibrary/output/OutputHighlight.glsl.js";import p from"../Camera.js";import{Default3D as m}from"../DefaultVertexAttributeLocations.js";import{IntersectorType as f}from"../IntersectorInterfaces.js";import{DepthOrder as g}from"../Octree.js";import{RenderPass as I}from"../RenderPass.js";import{RenderSlot as D}from"../RenderSlot.js";import{assert as y}from"../Util.js";import{InstanceData as v,StateFlags as E}from"./InstanceData.js";import{InstanceOctree as R}from"./InstanceOctree.js";import{LevelSelector as T}from"./LevelSelector.js";import{LodLevel as b}from"./LodLevel.js";import{RenderInstanceData as C}from"./RenderInstanceData.js";import{getInstanceBufferLayout as A}from"../../materials/DefaultMaterial.js";import{colorMixModes as L}from"../../materials/internal/MaterialUtil.js";import{encodeDoubleVec3 as S}from"../../materials/renderers/utils.js";import{bindVertexBufferLayout as U,unbindVertexBufferLayout as x}from"../../../../webgl/Util.js";let O=function(e){const t=e.baseBoundingSphere.radius,s=e.levels.map((e=>e.minScreenSpaceRadius));return new T(t,s)};function P(e){O=e}class H{constructor(e,t,s,a){this.type=f.LOD,this.isGround=!1,this._inverseViewport=i(),this._levels=[],this._defaultRenderInstanceData=[],this._highlightRenderInstanceData=[],this._instanceIndex=0,this._slicePlane=!1,this._enableLevelSelection=!0,this._lastCamera=new p,this._updateCyclesWithStaticCamera=-1,this._needFullCycle=!1,this.canRender=!0,this._symbol=e,this._optionalFields=t,this._metadata=s,this._instanceBufferLayout=A({instancedDoublePrecision:!0,instanced:t}),this._glInstanceBufferLayout=u(this._instanceBufferLayout,1),this._instanceData=new v(this._optionalFields,a),this._instanceData.on("instance-added",(()=>this._requestUpdateCycle())),this._instanceData.on("instance-removed",(()=>this._requestUpdateCycle())),this._instanceData.on("instance-transform-changed",(e=>{this._requestUpdateCycle(),this._metadata.notifyGraphicGeometryChanged(e.index)})),this._instanceData.on("instance-visibility-changed",(e=>{this._requestUpdateCycle(!0),this._metadata.notifyGraphicVisibilityChanged(e.index)})),this._instanceData.on("instance-highlight-changed",(()=>this._requestUpdateCycle(!0))),this._enableLevelSelection=this._symbol.levels.length>1}get levels(){return this._levels}get baseBoundingBox(){return this._levels[this._levels.length-1].boundingBox}get baseBoundingSphere(){return this._levels[this._levels.length-1].boundingSphere}get baseMaterial(){return this._levels[this._levels.length-1].components[0].material}get slicePlaneEnabled(){return this._slicePlane}set slicePlaneEnabled(e){this._slicePlane=e}get layerUid(){return this._metadata.layerUid}get instanceData(){return this._instanceData}get memoryUsage(){const e={cpu:0,gpu:0};return this._defaultRenderInstanceData.forEach((t=>{const s=t.memoryUsage;e.cpu+=s.cpu,e.gpu+=s.gpu})),this._highlightRenderInstanceData.forEach((t=>{const s=t.memoryUsage;e.cpu+=s.cpu,e.gpu+=s.gpu})),e}get renderStats(){const e=this._instanceData.size,t=[];return this._levels.forEach(((e,s)=>{const a=this._defaultRenderInstanceData[s],n=this._highlightRenderInstanceData[s],i=a.size+n.size,r=e.triangleCount;t.push({renderedInstances:i,renderedTriangles:i*r,trianglesPerInstance:r})})),{totalInstances:e,renderedInstances:t.reduce(((e,t)=>e+t.renderedInstances),0),renderedTriangles:t.reduce(((e,t)=>e+t.renderedTriangles),0),levels:t}}async initializeRenderContext(e,a){this._context=e;const n=e.renderContext.rctx,i=await Promise.allSettled(this._symbol.levels.map((t=>(this._defaultRenderInstanceData.push(new C(n,this._instanceBufferLayout)),this._highlightRenderInstanceData.push(new C(n,this._instanceBufferLayout)),b.create(e,t,a))))),r=i.map((e=>"fulfilled"===e.status?e.value:null)).filter((e=>e));if(t(a)||r.length!==i.length){r.forEach((e=>e.destroy())),s(a);for(const e of i)if("rejected"===e.status)throw e.reason}this._levels=r,this._levelSelector=O(this)}uninitializeRenderContext(){this._invalidateOctree(),this._levels.forEach((e=>e.destroy())),this._defaultRenderInstanceData.forEach((e=>e.destroy())),this._highlightRenderInstanceData.forEach((e=>e.destroy()))}get slots(){return[D.OPAQUE_PLUGIN,D.TRANSPARENT_PLUGIN]}get needsHighlight(){return this._highlightRenderInstanceData.reduce(((e,t)=>e+t.size),0)>0}prepareRender(e,t){if(d.LOD_INSTANCE_RENDERER_DISABLE_UPDATES)return;if(this._enableLevelSelection){const e=t.equals(this._lastCamera);this._lastCamera.copyFrom(t),e||this._requestUpdateCycle()}const s=this._needFullCycle?this._instanceData.size:2e3;this._needFullCycle=!1,this._updateInstances(t,s),this.needsUpdates&&this._context.requestRender()}render(e){var t,s;const n=e.slot===D.OPAQUE_PLUGIN?D.OPAQUE_MATERIAL:e.slot===D.TRANSPARENT_PLUGIN?D.TRANSPARENT_MATERIAL:null;if(!n||!this.baseMaterial.isVisible()||!this.baseMaterial.isVisibleInPass(e.pass))return;const i=e.camera;this._inverseViewport[0]=1/i.fullViewport[2],this._inverseViewport[1]=1/i.fullViewport[3];const r={slot:n,origin:[0,0,0],camera:i,inverseViewport:this._inverseViewport,shadowMap:e.shadowMap,shadowMappingEnabled:e.shadowMap.enabled,ssaoHelper:e.ssaoHelper,ssaoEnabled:e.ssaoHelper.enabled,screenToWorldRatio:null,screenToPCSRatio:null,slicePlane:e.sliceHelper&&e.sliceHelper.plane,hudVisibilityTexture:e.offscreenRenderingHelper?e.offscreenRenderingHelper.hudVisibilityTexture:null,highlightDepthTexture:null!=(t=null==(s=e.offscreenRenderingHelper)?void 0:s.depthTexture)?t:null,hasOccludees:!1,linearDepthTexture:null,lastFrameColorTexture:null,reprojectionMatrix:a,ssrEnabled:!1,lighting:e.scenelightingData,transparencyPassType:e.transparencyPassType,terrainLinearDepthTexture:e.multipassTerrainParams.terrainLinearDepthTexture,geometryLinearDepthTexture:e.multipassGeometryParams.geometryLinearDepthTexture,multipassTerrainEnabled:e.multipassTerrainParams.multipassTerrainEnabled,cullAboveGround:e.multipassTerrainParams.cullAboveGround,multipassGeometryEnabled:e.multipassGeometryParams.multipassGeometryEnabled,highlightColorTexture:null};e.rctx.bindVAO();const l=e.pass!==I.MATERIAL_HIGHLIGHT&&e.pass!==I.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT,o=e.pass!==I.MATERIAL_DEPTH_SHADOWMAP_DEFAULT;l&&this._renderComponents(e,n,r,this._defaultRenderInstanceData),o&&this._renderComponents(e,n,r,this._highlightRenderInstanceData)}intersect(e,t,s,a){if(!this.baseMaterial.isVisible())return;const n=c();r(n,a,s);const i=n=>{this._instanceData.getCombinedModelTransform(n,G),e.transform.set(G),o(N,s,e.transform.inverse),o(F,a,e.transform.inverse);const i=this._instanceData.getState(n),r=this._instanceData.getLodLevel(n);y(i&E.ACTIVE,"invalid instance state"),y(r>=0&&r<this._levels.length,"invaid lod level"),this._levels[r].intersect(e,t,N,F,n,this._metadata)};this.baseMaterial.parameters.verticalOffset?this.octree.forEach(i):this.octree.forEachAlongRay(s,n,i)}queryDepthRange(e){return this._queryDepthRangeOctree(e)}notifyShaderTransformationChanged(){this._invalidateOctree()}_requestUpdateCycle(e=!1){this._updateCyclesWithStaticCamera=-1,e&&(this._needFullCycle=!0),this.needsUpdates&&this._context.requestRender()}get needsUpdates(){return this._instanceData.size>0&&this._updateCyclesWithStaticCamera<1}get octree(){return this._octree||(this._octree=this._buildOctree()),this._octree}_invalidateOctree(){this._octree&&(this._octree.destroy(),this._octree=null)}_buildOctree(){const e=new R(this._instanceData,this.baseBoundingSphere),t=this._instanceData,s=t.view?t.view.state:null;for(let a=0;a<this._instanceData.capacity;++a){s.get(a)&E.ACTIVE&&e.addInstance(a)}return e}_queryDepthRangeOctree(e){const t=e.eye,s=e.viewForward,a=this.octree.findClosest(s,g.FRONT_TO_BACK,e.frustum),n=this.octree.findClosest(s,g.BACK_TO_FRONT,e.frustum);if(null!=a&&null!=n){this._instanceData.view.boundingSphere.getVec(a,j),r(j,j,t);const i=l(j,s)-j[3];this._instanceData.view.boundingSphere.getVec(n,j),r(j,j,t);const o=l(j,s)+j[3];return{near:Math.max(e.near,i),far:Math.min(e.far,o)}}return{near:1/0,far:-1/0}}_startUpdateCycle(){this._updateCyclesWithStaticCamera++,this._defaultRenderInstanceData.forEach((e=>{e.startUpdateCylce()})),this._highlightRenderInstanceData.forEach((e=>{e.startUpdateCylce()})),this.needsUpdates&&this._context.requestRender()}_updateInstances(e,t){const s=this._enableLevelSelection,a=this._levelSelector;a.updateCamera(e),this._defaultRenderInstanceData.forEach((e=>{e.beginUpdate()})),this._highlightRenderInstanceData.forEach((e=>{e.beginUpdate()}));const n=this._instanceData,i=this._instanceData.view,r=n.size,l=n.capacity;let o=this._instanceIndex;t=Math.min(r,t);for(let c=0;c<t;++c){0===o&&this._startUpdateCycle();const e=i.state.get(o);let r=0;if(!(e&E.ALLOCATED)){o=(o+1)%l,t++;continue}const c=i.lodLevel.get(o);if(e&E.DEFAULT_ACTIVE&&this._defaultRenderInstanceData[c].freeTail(),e&E.HIGHLIGHT_ACTIVE&&this._highlightRenderInstanceData[c].freeTail(),e&E.REMOVE)n.freeInstance(o);else if(e&E.VISIBLE){let t=0;s&&(i.modelOrigin.getVec(o,w),t=a.selectLevel(w,n.getCombinedMedianScaleFactor(o))),r=e&~(E.ACTIVE|E.TRANSFORM_CHANGED),t>=0&&(e&E.HIGHLIGHT?(M(this._highlightRenderInstanceData[t],i,o),r|=E.HIGHLIGHT_ACTIVE):(M(this._defaultRenderInstanceData[t],i,o),r|=E.DEFAULT_ACTIVE)),i.state.set(o,r),i.lodLevel.set(o,t)}else r=e&~(E.ACTIVE|E.TRANSFORM_CHANGED),i.state.set(o,r);if(this._octree){const t=!!(e&E.ACTIVE),s=!!(r&E.ACTIVE);!t&&s?this._octree.addInstance(o):t&&!s?this._octree.removeInstance(o):t&&s&&e&E.TRANSFORM_CHANGED&&(this._octree.removeInstance(o),this._octree.addInstance(o))}o=(o+1)%l}this._instanceIndex=o,this._defaultRenderInstanceData.forEach((e=>{e.endUpdate()})),this._highlightRenderInstanceData.forEach((e=>{e.endUpdate()}))}_renderComponents(e,t,s,a){this.levels.forEach(((n,i)=>{n.components.forEach((n=>{this._renderComponent(e,t,s,a[i],n,i)}))}))}_renderComponent(t,s,a,n,i,r){if(0===n.size||!i.material.requiresSlot(s))return;const{rctx:l,pass:o}=t,c=i.glMaterials.load(l,o);if(e(c))return;const h=l.capabilities.instancing,u=c.beginSlot(a),p=u.program;u.bindPipelineState(l,s),l.useProgram(p),c.bind(a,u),l.bindVAO(i.vao),u.ensureAttributeLocations(i.vao),t.isHighlightPass&&_(p,a),u.bindDraw(a),d.LOD_INSTANCE_RENDERER_COLORIZE_BY_LEVEL&&t.pass===I.MATERIAL&&(p.setUniform4fv("externalColor",B[Math.min(r,B.length-1)]),p.setUniform1i("colorMixMode",L.replace));const f=n.capacity,g=n.headIndex,D=n.tailIndex,v=n.firstIndex,E=this._glInstanceBufferLayout,R=(e,t)=>{U(l,m,n.buffer,E,e),h.drawArraysInstanced(u.primitiveType,0,i.vertexCount,t-e),x(l,m,n.buffer,E)};i.material.parameters.transparent&&null!=v?g>D?(y(v>=D&&v<=g,"invalid firstIndex"),R(v,g),R(D,v)):g<D&&(v<=g?(y(v>=0&&v<=g,"invalid firstIndex"),R(v,g),R(D,f),R(0,v)):(y(v>=D&&v<=f,"invalid firstIndex"),R(v,f),R(0,g),R(D,v))):g>D?R(D,g):g<D&&(R(0,g),R(D,f)),l.bindVAO(null)}}function M(e,t,s){const a=e.allocateHead();V(t,s,e.view,a)}function V(e,t,s,a){S(e.modelOrigin,t,s.modelOriginHi,s.modelOriginLo,a),s.model.copyFrom(a,e.model,t),s.modelNormal.copyFrom(a,e.modelNormal,t),e.color&&s.color&&s.color.copyFrom(a,e.color,t),e.featureAttribute&&s.featureAttribute&&s.featureAttribute.copyFrom(a,e.featureAttribute,t)}const w=c(),j=h(),G=n(),N=c(),F=c(),B=[[1,0,1,1],[0,0,1,1],[0,1,0,1],[1,1,0,1],[1,0,0,1]];export{H as LodRenderer,P as setLevelSelectorFactory};
5
+ import{isNone as e}from"../../../../../core/maybe.js";import{isAborted as t,throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{I as a,c as n}from"../../../../../chunks/mat4f64.js";import{a as i}from"../../../../../chunks/vec2f64.js";import{f as r,d as l,m as o}from"../../../../../chunks/vec3.js";import{c}from"../../../../../chunks/vec3f64.js";import{c as h}from"../../../../../chunks/vec4f64.js";import d from"../../../support/debugFlags.js";import{glLayout as u}from"../../../support/buffer/glUtil.js";import{bindOutputHighlight as _}from"../../core/shaderLibrary/output/OutputHighlight.glsl.js";import p from"../Camera.js";import{Default3D as m}from"../DefaultVertexAttributeLocations.js";import{IntersectorType as f}from"../IntersectorInterfaces.js";import{DepthOrder as g}from"../Octree.js";import{RenderPass as I}from"../RenderPass.js";import{RenderSlot as D}from"../RenderSlot.js";import{assert as y}from"../Util.js";import{InstanceData as E,StateFlags as T}from"./InstanceData.js";import{InstanceOctree as v}from"./InstanceOctree.js";import{LevelSelector as R}from"./LevelSelector.js";import{LodLevel as A}from"./LodLevel.js";import{RenderInstanceData as b}from"./RenderInstanceData.js";import{getInstanceBufferLayout as C}from"../../materials/DefaultMaterial.js";import{colorMixModes as L}from"../../materials/internal/MaterialUtil.js";import{encodeDoubleVec3 as S}from"../../materials/renderers/utils.js";import{bindVertexBufferLayout as U,unbindVertexBufferLayout as x}from"../../../../webgl/Util.js";let P=function(e){const t=e.baseBoundingSphere.radius,s=e.levels.map((e=>e.minScreenSpaceRadius));return new R(t,s)};function O(e){P=e}class H{constructor(e,t,s,a){this.type=f.LOD,this.isGround=!1,this._inverseViewport=i(),this._levels=[],this._defaultRenderInstanceData=[],this._highlightRenderInstanceData=[],this._instanceIndex=0,this._slicePlane=!1,this._enableLevelSelection=!0,this._lastCamera=new p,this._updateCyclesWithStaticCamera=-1,this._needFullCycle=!1,this.slots=[D.OPAQUE_PLUGIN,D.TRANSPARENT_PLUGIN],this.canRender=!0,this._symbol=e,this._optionalFields=t,this._metadata=s,this._instanceBufferLayout=C({instancedDoublePrecision:!0,instanced:t}),this._glInstanceBufferLayout=u(this._instanceBufferLayout,1),this._instanceData=new E(this._optionalFields,a),this._instanceData.on("instance-added",(()=>this._requestUpdateCycle())),this._instanceData.on("instance-removed",(()=>this._requestUpdateCycle())),this._instanceData.on("instance-transform-changed",(e=>{this._requestUpdateCycle(),this._metadata.notifyGraphicGeometryChanged(e.index)})),this._instanceData.on("instance-visibility-changed",(e=>{this._requestUpdateCycle(!0),this._metadata.notifyGraphicVisibilityChanged(e.index)})),this._instanceData.on("instance-highlight-changed",(()=>this._requestUpdateCycle(!0))),this._enableLevelSelection=this._symbol.levels.length>1}get levels(){return this._levels}get baseBoundingBox(){return this._levels[this._levels.length-1].boundingBox}get baseBoundingSphere(){return this._levels[this._levels.length-1].boundingSphere}get baseMaterial(){return this._levels[this._levels.length-1].components[0].material}get slicePlaneEnabled(){return this._slicePlane}set slicePlaneEnabled(e){this._slicePlane=e}get layerUid(){return this._metadata.layerUid}get instanceData(){return this._instanceData}get memoryUsage(){const e={cpu:0,gpu:0};return this._defaultRenderInstanceData.forEach((t=>{const s=t.memoryUsage;e.cpu+=s.cpu,e.gpu+=s.gpu})),this._highlightRenderInstanceData.forEach((t=>{const s=t.memoryUsage;e.cpu+=s.cpu,e.gpu+=s.gpu})),e}get renderStats(){const e=this._instanceData.size,t=[];return this._levels.forEach(((e,s)=>{const a=this._defaultRenderInstanceData[s],n=this._highlightRenderInstanceData[s],i=a.size+n.size,r=e.triangleCount;t.push({renderedInstances:i,renderedTriangles:i*r,trianglesPerInstance:r})})),{totalInstances:e,renderedInstances:t.reduce(((e,t)=>e+t.renderedInstances),0),renderedTriangles:t.reduce(((e,t)=>e+t.renderedTriangles),0),levels:t}}async initializeRenderContext(e,a){this._context=e;const n=e.renderContext.rctx,i=await Promise.allSettled(this._symbol.levels.map((t=>(this._defaultRenderInstanceData.push(new b(n,this._instanceBufferLayout)),this._highlightRenderInstanceData.push(new b(n,this._instanceBufferLayout)),A.create(e,t,a))))),r=i.map((e=>"fulfilled"===e.status?e.value:null)).filter((e=>e));if(t(a)||r.length!==i.length){r.forEach((e=>e.destroy())),s(a);for(const e of i)if("rejected"===e.status)throw e.reason}this._levels=r,this._levelSelector=P(this)}uninitializeRenderContext(){this._invalidateOctree(),this._levels.forEach((e=>e.destroy())),this._defaultRenderInstanceData.forEach((e=>e.destroy())),this._highlightRenderInstanceData.forEach((e=>e.destroy()))}get needsTransparentPass(){return this._levels.some((e=>e.components.some((e=>e.material.requiresSlot(D.TRANSPARENT_MATERIAL)))))}get needsHighlight(){return this._highlightRenderInstanceData.some((e=>e.size>0))}prepareRender(e,t){if(d.LOD_INSTANCE_RENDERER_DISABLE_UPDATES)return;if(this._enableLevelSelection){const e=t.equals(this._lastCamera);this._lastCamera.copyFrom(t),e||this._requestUpdateCycle()}const s=this._needFullCycle?this._instanceData.size:2e3;this._needFullCycle=!1,this._updateInstances(t,s),this.needsUpdates&&this._context.requestRender()}render(e){var t,s;const n=e.slot===D.OPAQUE_PLUGIN?D.OPAQUE_MATERIAL:e.slot===D.TRANSPARENT_PLUGIN?D.TRANSPARENT_MATERIAL:null;if(!n||!this.baseMaterial.isVisible()||!this.baseMaterial.isVisibleInPass(e.pass))return;const i=e.camera;this._inverseViewport[0]=1/i.fullViewport[2],this._inverseViewport[1]=1/i.fullViewport[3];const r={slot:n,origin:[0,0,0],camera:i,inverseViewport:this._inverseViewport,shadowMap:e.shadowMap,shadowMappingEnabled:e.shadowMap.enabled,ssaoHelper:e.ssaoHelper,ssaoEnabled:e.ssaoHelper.enabled,screenToWorldRatio:null,screenToPCSRatio:null,slicePlane:e.sliceHelper&&e.sliceHelper.plane,hudVisibilityTexture:e.offscreenRenderingHelper?e.offscreenRenderingHelper.hudVisibilityTexture:null,highlightDepthTexture:null!=(t=null==(s=e.offscreenRenderingHelper)?void 0:s.depthTexture)?t:null,hasOccludees:!1,linearDepthTexture:null,lastFrameColorTexture:null,reprojectionMatrix:a,ssrEnabled:!1,lighting:e.scenelightingData,transparencyPassType:e.transparencyPassType,terrainLinearDepthTexture:e.multipassTerrainParams.terrainLinearDepthTexture,geometryLinearDepthTexture:e.multipassGeometryParams.geometryLinearDepthTexture,multipassTerrainEnabled:e.multipassTerrainParams.multipassTerrainEnabled,cullAboveGround:e.multipassTerrainParams.cullAboveGround,multipassGeometryEnabled:e.multipassGeometryParams.multipassGeometryEnabled,highlightColorTexture:null};e.rctx.bindVAO();const l=e.pass!==I.MATERIAL_HIGHLIGHT&&e.pass!==I.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT,o=e.pass!==I.MATERIAL_DEPTH_SHADOWMAP_DEFAULT;l&&this._renderComponents(e,n,r,this._defaultRenderInstanceData),o&&this._renderComponents(e,n,r,this._highlightRenderInstanceData)}intersect(e,t,s,a){if(!this.baseMaterial.isVisible())return;const n=c();r(n,a,s);const i=n=>{this._instanceData.getCombinedModelTransform(n,N),e.transform.set(N),o(G,s,e.transform.inverse),o(F,a,e.transform.inverse);const i=this._instanceData.getState(n),r=this._instanceData.getLodLevel(n);y(i&T.ACTIVE,"invalid instance state"),y(r>=0&&r<this._levels.length,"invaid lod level"),this._levels[r].intersect(e,t,G,F,n,this._metadata)};this.baseMaterial.parameters.verticalOffset?this.octree.forEach(i):this.octree.forEachAlongRay(s,n,i)}queryDepthRange(e){return this._queryDepthRangeOctree(e)}notifyShaderTransformationChanged(){this._invalidateOctree()}_requestUpdateCycle(e=!1){this._updateCyclesWithStaticCamera=-1,e&&(this._needFullCycle=!0),this.needsUpdates&&this._context.requestRender()}get needsUpdates(){return this._instanceData.size>0&&this._updateCyclesWithStaticCamera<1}get octree(){return this._octree||(this._octree=this._buildOctree()),this._octree}_invalidateOctree(){this._octree&&(this._octree.destroy(),this._octree=null)}_buildOctree(){const e=new v(this._instanceData,this.baseBoundingSphere),t=this._instanceData,s=t.view?t.view.state:null;for(let a=0;a<this._instanceData.capacity;++a){s.get(a)&T.ACTIVE&&e.addInstance(a)}return e}_queryDepthRangeOctree(e){const t=e.eye,s=e.viewForward,a=this.octree.findClosest(s,g.FRONT_TO_BACK,e.frustum),n=this.octree.findClosest(s,g.BACK_TO_FRONT,e.frustum);if(null!=a&&null!=n){this._instanceData.view.boundingSphere.getVec(a,j),r(j,j,t);const i=l(j,s)-j[3];this._instanceData.view.boundingSphere.getVec(n,j),r(j,j,t);const o=l(j,s)+j[3];return{near:Math.max(e.near,i),far:Math.min(e.far,o)}}return{near:1/0,far:-1/0}}_startUpdateCycle(){this._updateCyclesWithStaticCamera++,this._defaultRenderInstanceData.forEach((e=>{e.startUpdateCylce()})),this._highlightRenderInstanceData.forEach((e=>{e.startUpdateCylce()})),this.needsUpdates&&this._context.requestRender()}_updateInstances(e,t){const s=this._enableLevelSelection,a=this._levelSelector;a.updateCamera(e),this._defaultRenderInstanceData.forEach((e=>{e.beginUpdate()})),this._highlightRenderInstanceData.forEach((e=>{e.beginUpdate()}));const n=this._instanceData,i=this._instanceData.view,r=n.size,l=n.capacity;let o=this._instanceIndex;t=Math.min(r,t);for(let c=0;c<t;++c){0===o&&this._startUpdateCycle();const e=i.state.get(o);let r=0;if(!(e&T.ALLOCATED)){o=(o+1)%l,t++;continue}const c=i.lodLevel.get(o);if(e&T.DEFAULT_ACTIVE&&this._defaultRenderInstanceData[c].freeTail(),e&T.HIGHLIGHT_ACTIVE&&this._highlightRenderInstanceData[c].freeTail(),e&T.REMOVE)n.freeInstance(o);else if(e&T.VISIBLE){let t=0;s&&(i.modelOrigin.getVec(o,w),t=a.selectLevel(w,n.getCombinedMedianScaleFactor(o))),r=e&~(T.ACTIVE|T.TRANSFORM_CHANGED),t>=0&&(e&T.HIGHLIGHT?(M(this._highlightRenderInstanceData[t],i,o),r|=T.HIGHLIGHT_ACTIVE):(M(this._defaultRenderInstanceData[t],i,o),r|=T.DEFAULT_ACTIVE)),i.state.set(o,r),i.lodLevel.set(o,t)}else r=e&~(T.ACTIVE|T.TRANSFORM_CHANGED),i.state.set(o,r);if(this._octree){const t=!!(e&T.ACTIVE),s=!!(r&T.ACTIVE);!t&&s?this._octree.addInstance(o):t&&!s?this._octree.removeInstance(o):t&&s&&e&T.TRANSFORM_CHANGED&&(this._octree.removeInstance(o),this._octree.addInstance(o))}o=(o+1)%l}this._instanceIndex=o,this._defaultRenderInstanceData.forEach((e=>{e.endUpdate()})),this._highlightRenderInstanceData.forEach((e=>{e.endUpdate()}))}_renderComponents(e,t,s,a){this.levels.forEach(((n,i)=>{n.components.forEach((n=>{this._renderComponent(e,t,s,a[i],n,i)}))}))}_renderComponent(t,s,a,n,i,r){if(0===n.size||!i.material.requiresSlot(s))return;const{rctx:l,pass:o}=t,c=i.glMaterials.load(l,o);if(e(c))return;const h=l.capabilities.instancing,u=c.beginSlot(a),p=u.program;u.bindPipelineState(l,s),l.useProgram(p),c.bind(a,u),l.bindVAO(i.vao),u.ensureAttributeLocations(i.vao),t.isHighlightPass&&_(p,a),u.bindDraw(a),d.LOD_INSTANCE_RENDERER_COLORIZE_BY_LEVEL&&t.pass===I.MATERIAL&&(p.setUniform4fv("externalColor",B[Math.min(r,B.length-1)]),p.setUniform1i("colorMixMode",L.replace));const f=n.capacity,g=n.headIndex,D=n.tailIndex,E=n.firstIndex,T=this._glInstanceBufferLayout,v=(e,t)=>{U(l,m,n.buffer,T,e),h.drawArraysInstanced(u.primitiveType,0,i.vertexCount,t-e),x(l,m,n.buffer,T)};i.material.parameters.transparent&&null!=E?g>D?(y(E>=D&&E<=g,"invalid firstIndex"),v(E,g),v(D,E)):g<D&&(E<=g?(y(E>=0&&E<=g,"invalid firstIndex"),v(E,g),v(D,f),v(0,E)):(y(E>=D&&E<=f,"invalid firstIndex"),v(E,f),v(0,g),v(D,E))):g>D?v(D,g):g<D&&(v(0,g),v(D,f)),l.bindVAO(null)}}function M(e,t,s){const a=e.allocateHead();V(t,s,e.view,a)}function V(e,t,s,a){S(e.modelOrigin,t,s.modelOriginHi,s.modelOriginLo,a),s.model.copyFrom(a,e.model,t),s.modelNormal.copyFrom(a,e.modelNormal,t),e.color&&s.color&&s.color.copyFrom(a,e.color,t),e.featureAttribute&&s.featureAttribute&&s.featureAttribute.copyFrom(a,e.featureAttribute,t)}const w=c(),j=h(),N=n(),G=c(),F=c(),B=[[1,0,1,1],[0,0,1,1],[0,1,0,1],[1,1,0,1],[1,0,0,1]];export{H as LodRenderer,O as setLevelSelectorFactory};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import{someMap as e}from"../../../../../core/MapUtils.js";import{isSome as t,isNone as r}from"../../../../../core/maybe.js";import s from"../../../../../core/PooledArray.js";import{m as i,a,t as o}from"../../../../../chunks/mat4.js";import{c as n}from"../../../../../chunks/mat4f64.js";import{glLayout as d}from"../../../support/buffer/glUtil.js";import{GLMaterials as h}from"../../lib/GLMaterials.js";import{RenderOccludedFlag as f}from"../../lib/Material.js";import{ModelDirty as m}from"../../lib/ModelDirtyTypes.js";import{RenderPass as l}from"../../lib/RenderPass.js";import{assert as c,setMatrixTranslation3 as u}from"../../lib/Util.js";import{WaterMaterial as g}from"../WaterMaterial.js";import{sortInstancesByRange as _,BufferRange as p,Instance as b,addOrMerge as w}from"./Instance.js";import{MergedGeometryBuffer as y}from"./MergedGeometryBuffer.js";import{MergedGeometryBufferPool as C}from"./MergedGeometryBufferPool.js";import{calculateTransformRelativeToOrigin as H}from"./utils.js";class v{constructor(e,t,r){this._rctx=e,this._materialRepository=t,this._material=r,this.type="MergedRenderer",this._dataByOrigin=new Map,this._renderCommandData=new s,this._hasHighlights=!1,this._hasOccludees=!1,this._glMaterials=new h(this._material,this._materialRepository),this._bufferWriter=r.createBufferWriter(),this._bufferPool=new C(e,r.vertexAttributeLocations,d(this._bufferWriter.vertexBufferLayout))}dispose(){this._glMaterials.destroy(),this._dataByOrigin.forEach((e=>e.buffer.dispose())),this._dataByOrigin.clear(),this._bufferPool.dispose()}get isEmpty(){return 0===this._dataByOrigin.size}get hasHighlights(){return this._hasHighlights}get hasOccludees(){return this._hasOccludees}get hasWater(){return!this.isEmpty&&this._material instanceof g}get rendersOccluded(){return!this.isEmpty&&this._material.renderOccluded!==f.Occlude}modify(e){this._updateGeometries(e.updates),this._addAndRemoveGeometries(e.adds,e.removes),this._updateRenderCommands()}_addAndRemoveGeometries(e,t){const r=this._bufferWriter,s=r.vertexBufferLayout.stride/4,i=this._dataByOrigin,a=A(e,t);a.forEach(((e,t)=>{a.delete(t);const o=e.toAdd.reduce(((e,t)=>e+r.elementCount(t.data)),0);let n=i.get(t);if(null==n)c(0===e.toRemove.length),n=new B(e.origin,new y(this._bufferPool,o*s)),i.set(t,n);else if(0===e.toAdd.length&&n.instances.size===e.toRemove.length)return n.buffer.dispose(),void i.delete(t);let d=0;n.instances.forEach((e=>d+=e.to-e.from));const h=e.toRemove.reduce(((e,t)=>e+r.elementCount(t.data)),0),f=n.buffer.size,m=(d+o-h)*s,l=T;if(m<f/2?this._removeAndRebuild(n,e.toRemove,s,m,l):e.toRemove.length>0&&this._remove(n,e.toRemove,s,l),e.toAdd.length>0){const t=E;u(t,-e.origin[0],-e.origin[1],-e.origin[2]),this._add(n,e.toAdd,s,t,l)}const g=n.buffer.vao.vertexBuffers.geometry;I(l),l.forAll((({from:e,to:t})=>{if(e<t){const r=n.buffer.array,s=4,i=e*s,a=t*s;g.setSubData(r,i,i,a)}})),l.clear(),n.drawCommandsDirty=!0}))}_updateGeometries(e){const t=this._bufferWriter,r=t.vertexBufferLayout.stride/4;for(const s of e){const e=s.renderGeometry,i=this._dataByOrigin.get(e.origin.id),a=i&&i.instances.get(e.id);if(!a)return;const o=s.updateType;if(o&m.State.VISIBILITIES&&(a.isVisible=e.instanceParameters.visible),o&(m.State.HIGHLIGHTS|m.State.VISIBILITIES)){const t=e.instanceParameters.visible;a.hasHighlights=!!e.instanceParameters.highlights&&t}if(o&m.State.OCCLUDEES&&(a.hasOccludees=!!e.instanceParameters.occludees),o&(m.State.VERTEXATTRS|m.State.TRANSFORMATION)){const{array:s,vao:o}=i.buffer;H(e,P,L),t.write({transformation:P,invTranspTransformation:L},e.data,t.vertexBufferLayout.createView(s.buffer),a.from),c(a.from+t.elementCount(e.data)===a.to,"material VBO layout has changed"),o.vertexBuffers.geometry.setSubData(s,a.from*r*4,a.from*r*4,a.to*r*4)}i.drawCommandsDirty=!0}}_updateRenderCommands(){this._hasHighlights=!1,this._hasOccludees=!1,this._dataByOrigin.forEach((t=>{t.hasHiddenInstances=!1,t.hasHighlights=!1,t.hasOccludees=!1,e(t.instances,(e=>(e.isVisible?(e.hasHighlights&&(this._hasHighlights=!0,t.hasHighlights=!0),e.hasOccludees&&(this._hasOccludees=!0,t.hasOccludees=!0)):t.hasHiddenInstances=!0,t.hasHiddenInstances&&t.hasHighlights&&t.hasOccludees)))}));const t=e=>{if(e.drawCommandsDefault=null,e.drawCommandsHighlight=null,e.drawCommandsOccludees=null,e.drawCommandsShadowHighlightRest=null,0===e.instances.size)return;if(!S(e)){const t=this._bufferWriter.vertexBufferLayout.stride,r=4*e.buffer.size/t;return void(e.drawCommandsDefault=[{first:0,count:r}])}const t=_(e.instances);e.drawCommandsDefault=[],e.drawCommandsHighlight=[],e.drawCommandsOccludees=[],e.drawCommandsShadowHighlightRest=[];for(const r of t)r.isVisible&&(r.hasOccludees?w(e.drawCommandsOccludees,r):w(e.drawCommandsDefault,r),r.hasHighlights?w(e.drawCommandsHighlight,r):w(e.drawCommandsShadowHighlightRest,r))};this._dataByOrigin.forEach((e=>{e.drawCommandsDirty&&(t(e),e.drawCommandsDirty=!1)}))}updateAnimation(e){return this._material.update(e)}render(e,s,i){if(null!=e&&!this._material.requiresSlot(e,s))return!1;const a=s===l.MATERIAL_HIGHLIGHT||s===l.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT;if(a&&!this._hasHighlights)return!1;const o=s===l.MATERIAL_DEPTH_SHADOWMAP_DEFAULT,n=!(a||o);if(this._dataByOrigin.forEach((e=>{if(a&&!e.hasHighlights)return;const r=(a?e.drawCommandsHighlight:o&&S(e)?e.drawCommandsShadowHighlightRest:e.drawCommandsDefault)||null,s=n&&e.drawCommandsOccludees||null;(t(r)||t(s))&&this._renderCommandData.push(new M(e.origin,e.buffer,r,s))})),0===this._renderCommandData.length)return!1;const d=this._rctx,h=this._glMaterials.load(d,s);if(r(h))return this._renderCommandData.clear(),!1;const f=h.beginSlot(i);return f.bindPipelineState(d,e,!1),d.useProgram(f.program),h.bind(i,f),this._renderCommandData.forAll((({origin:r,buffer:s,renderCommands:a,occludeeCommands:o})=>{i.origin=r,f.bindDraw(i),f.ensureAttributeLocations(s.vao),d.bindVAO(s.vao);const n=f.primitiveType;t(a)&&this._renderCommands(d,n,a),t(o)&&(f.bindPipelineState(d,e,!0),this._renderCommands(d,n,o),f.bindPipelineState(d,e,!1))})),this._renderCommandData.clear(),!0}_renderCommands(e,t,r){for(let s=0;s<r.length;s++)e.drawArrays(t,r[s].first,r[s].count)}_removeAndRebuild(e,t,r,s,i){for(const h of t)e.instances.delete(h.id);const a=_(e.instances);e.instances.clear();const o=e.buffer.size,n=e.buffer.alloc(s);let d=0;for(const h of a){const t=h.from*r,s=h.to*r;n.copy(d,t,s),h.from=d/r,d+=s-t,h.to=d/r,e.instances.set(h.id,h)}i.push(new p(0,n.hasNewBuffer?e.buffer.array.length:o)),n.dispose(),e.buffer.erase(d,i.back().to),e.holes.clear()}_remove(e,t,r,s){for(const i of t){const t=i.id,a=e.instances.get(t),o=a.from*r,n=a.to*r;e.buffer.erase(o,n),e.holes.push(new p(a.from,a.to)),e.instances.delete(t),s.push(new p(o,n))}I(e.holes)}_add(e,s,n,d,h){const f=this._bufferWriter;let m=f.vertexBufferLayout.createView(e.buffer.array.buffer);for(const l of s){const s=t(l.transformation)?i(P,d,l.transformation):d;a(L,s);const u=o(L,L),g=f.elementCount(l.data),_=g*n;let w=D(e.holes,g);r(w)&&(w=e.buffer.size/n,e.buffer.grow(_),m=f.vertexBufferLayout.createView(e.buffer.array.buffer)),f.write({transformation:s,invTranspTransformation:u},l.data,m,w);const y=l.instanceParameters.visible,C=!!l.instanceParameters.highlights&&y,H=!!l.instanceParameters.occludees,v=new b(l.id,w,w+g,y,C,H);c(null==e.instances.get(l.id)),e.instances.set(l.id,v),h.push(new p(v.from*n,v.to*n))}}get test(){return{material:this._material,glMaterials:this._glMaterials}}}class O{constructor(e){this.origin=e,this.toAdd=new Array,this.toRemove=new Array}}function A(e,t){const r=new Map;for(const s of e)R(r,s,!0);for(const s of t)R(r,s,!1);return r}function R(e,t,s){const i=t.origin;if(r(i))return;let a=e.get(i.id);null==a&&(a=new O(i.vec3),e.set(i.id,a)),s?a.toAdd.push(t):a.toRemove.push(t)}function S(e){return e.hasOccludees||e.hasHighlights||e.hasHiddenInstances}function D(e,t){let r;if(!e.some((e=>!(e.to-e.from<t)&&(r=e,!0))))return null;const s=r.from;return r.from+=t,r.from>=r.to&&e.removeUnordered(r),s}function I(e){const t=new Map;e.forAll((e=>t.set(e.from,e)));let r=!0;for(;r;)r=!1,e.forEach((s=>{const i=t.get(s.to);i&&(s.to=i.to,t.delete(i.from),e.removeUnordered(i),r=!0)}))}class B{constructor(e,t){this.origin=e,this.buffer=t,this.instances=new Map,this.holes=new s({deallocator:null}),this.hasHiddenInstances=!1,this.hasHighlights=!1,this.hasOccludees=!1,this.drawCommandsDirty=!1}}class M{constructor(e,t,r,s){this.origin=e,this.buffer=t,this.renderCommands=r,this.occludeeCommands=s}}const T=new s({deallocator:null}),E=n(),P=n(),L=n();export{v as MergedRenderer};
5
+ import{someMap as e}from"../../../../../core/MapUtils.js";import{isSome as t,isNone as r}from"../../../../../core/maybe.js";import s from"../../../../../core/PooledArray.js";import{m as i,a,t as o}from"../../../../../chunks/mat4.js";import{c as n}from"../../../../../chunks/mat4f64.js";import{glLayout as d}from"../../../support/buffer/glUtil.js";import{GLMaterials as h}from"../../lib/GLMaterials.js";import{RenderOccludedFlag as l}from"../../lib/Material.js";import{ModelDirty as f}from"../../lib/ModelDirtyTypes.js";import{RenderPass as m}from"../../lib/RenderPass.js";import{assert as c,setMatrixTranslation3 as u}from"../../lib/Util.js";import{WaterMaterial as g}from"../WaterMaterial.js";import{sortInstancesByRange as _,BufferRange as p,Instance as b,addOrMerge as w}from"./Instance.js";import{MergedGeometryBuffer as y}from"./MergedGeometryBuffer.js";import{MergedGeometryBufferPool as C}from"./MergedGeometryBufferPool.js";import{calculateTransformRelativeToOrigin as H}from"./utils.js";class v{constructor(e,t,r){this._rctx=e,this._materialRepository=t,this._material=r,this.type="MergedRenderer",this._dataByOrigin=new Map,this._renderCommandData=new s,this._hasHighlights=!1,this._hasOccludees=!1,this._glMaterials=new h(this._material,this._materialRepository),this._bufferWriter=r.createBufferWriter(),this._bufferPool=new C(e,r.vertexAttributeLocations,d(this._bufferWriter.vertexBufferLayout))}dispose(){this._glMaterials.destroy(),this._dataByOrigin.forEach((e=>e.buffer.dispose())),this._dataByOrigin.clear(),this._bufferPool.dispose()}get isEmpty(){return 0===this._dataByOrigin.size}get hasHighlights(){return this._hasHighlights}get hasOccludees(){return this._hasOccludees}get hasWater(){return!this.isEmpty&&this._material instanceof g}get rendersOccluded(){return!this.isEmpty&&this._material.renderOccluded!==l.Occlude}modify(e){this._updateGeometries(e.updates),this._addAndRemoveGeometries(e.adds,e.removes),this._updateRenderCommands()}_addAndRemoveGeometries(e,t){const r=this._bufferWriter,s=r.vertexBufferLayout.stride/4,i=this._dataByOrigin,a=A(e,t);a.forEach(((e,t)=>{a.delete(t);const o=e.toAdd.reduce(((e,t)=>e+r.elementCount(t.data)),0);let n=i.get(t);if(null==n)c(0===e.toRemove.length),n=new B(e.origin,new y(this._bufferPool,o*s)),i.set(t,n);else if(0===e.toAdd.length&&n.instances.size===e.toRemove.length)return n.buffer.dispose(),void i.delete(t);let d=0;n.instances.forEach((e=>d+=e.to-e.from));const h=e.toRemove.reduce(((e,t)=>e+r.elementCount(t.data)),0),l=n.buffer.size,f=(d+o-h)*s,m=T;if(f<l/2?this._removeAndRebuild(n,e.toRemove,s,f,m):e.toRemove.length>0&&this._remove(n,e.toRemove,s,m),e.toAdd.length>0){const t=E;u(t,-e.origin[0],-e.origin[1],-e.origin[2]),this._add(n,e.toAdd,s,t,m)}const g=n.buffer.vao.vertexBuffers.geometry;I(m),m.forAll((({from:e,to:t})=>{if(e<t){const r=n.buffer.array,s=4,i=e*s,a=t*s;g.setSubData(r,i,i,a)}})),m.clear(),n.drawCommandsDirty=!0}))}_updateGeometries(e){const t=this._bufferWriter,r=t.vertexBufferLayout.stride/4;for(const s of e){const e=s.renderGeometry,i=this._dataByOrigin.get(e.origin.id),a=i&&i.instances.get(e.id);if(!a)return;const o=s.updateType;if(o&f.State.VISIBILITIES&&(a.isVisible=e.instanceParameters.visible),o&(f.State.HIGHLIGHTS|f.State.VISIBILITIES)){const t=e.instanceParameters.visible;a.hasHighlights=!!e.instanceParameters.highlights&&t}if(o&f.State.OCCLUDEES&&(a.hasOccludees=!!e.instanceParameters.occludees),o&(f.State.VERTEXATTRS|f.State.TRANSFORMATION)){const{array:s,vao:o}=i.buffer;H(e,P,L),t.write({transformation:P,invTranspTransformation:L},e.data,t.vertexBufferLayout.createView(s.buffer),a.from),c(a.from+t.elementCount(e.data)===a.to,"material VBO layout has changed"),o.vertexBuffers.geometry.setSubData(s,a.from*r*4,a.from*r*4,a.to*r*4)}i.drawCommandsDirty=!0}}_updateRenderCommands(){this._hasHighlights=!1,this._hasOccludees=!1,this._dataByOrigin.forEach((t=>{t.hasHiddenInstances=!1,t.hasHighlights=!1,t.hasOccludees=!1,e(t.instances,(e=>(e.isVisible?(e.hasHighlights&&(this._hasHighlights=!0,t.hasHighlights=!0),e.hasOccludees&&(this._hasOccludees=!0,t.hasOccludees=!0)):t.hasHiddenInstances=!0,t.hasHiddenInstances&&t.hasHighlights&&t.hasOccludees)))}));const t=e=>{if(e.drawCommandsDefault=null,e.drawCommandsHighlight=null,e.drawCommandsOccludees=null,e.drawCommandsShadowHighlightRest=null,0===e.instances.size)return;if(!S(e)){const t=this._bufferWriter.vertexBufferLayout.stride,r=4*e.buffer.size/t;return void(e.drawCommandsDefault=[{first:0,count:r}])}const t=_(e.instances);e.drawCommandsDefault=[],e.drawCommandsHighlight=[],e.drawCommandsOccludees=[],e.drawCommandsShadowHighlightRest=[];for(const r of t)r.isVisible&&(r.hasOccludees?w(e.drawCommandsOccludees,r):w(e.drawCommandsDefault,r),r.hasHighlights?w(e.drawCommandsHighlight,r):w(e.drawCommandsShadowHighlightRest,r))};this._dataByOrigin.forEach((e=>{e.drawCommandsDirty&&(t(e),e.drawCommandsDirty=!1)}))}updateAnimation(e){return this._material.update(e)}requiresSlot(e,t){return null==e||this._material.requiresSlot(e,t)}render(e,s,i){if(!this.requiresSlot(e,s))return!1;const a=s===m.MATERIAL_HIGHLIGHT||s===m.MATERIAL_DEPTH_SHADOWMAP_HIGHLIGHT;if(a&&!this._hasHighlights)return!1;const o=s===m.MATERIAL_DEPTH_SHADOWMAP_DEFAULT,n=!(a||o);if(this._dataByOrigin.forEach((e=>{if(a&&!e.hasHighlights)return;const r=(a?e.drawCommandsHighlight:o&&S(e)?e.drawCommandsShadowHighlightRest:e.drawCommandsDefault)||null,s=n&&e.drawCommandsOccludees||null;(t(r)||t(s))&&this._renderCommandData.push(new M(e.origin,e.buffer,r,s))})),0===this._renderCommandData.length)return!1;const d=this._rctx,h=this._glMaterials.load(d,s);if(r(h))return this._renderCommandData.clear(),!1;const l=h.beginSlot(i);return l.bindPipelineState(d,e,!1),d.useProgram(l.program),h.bind(i,l),this._renderCommandData.forAll((({origin:r,buffer:s,renderCommands:a,occludeeCommands:o})=>{i.origin=r,l.bindDraw(i),l.ensureAttributeLocations(s.vao),d.bindVAO(s.vao);const n=l.primitiveType;t(a)&&this._renderCommands(d,n,a),t(o)&&(l.bindPipelineState(d,e,!0),this._renderCommands(d,n,o),l.bindPipelineState(d,e,!1))})),this._renderCommandData.clear(),!0}_renderCommands(e,t,r){for(let s=0;s<r.length;s++)e.drawArrays(t,r[s].first,r[s].count)}_removeAndRebuild(e,t,r,s,i){for(const h of t)e.instances.delete(h.id);const a=_(e.instances);e.instances.clear();const o=e.buffer.size,n=e.buffer.alloc(s);let d=0;for(const h of a){const t=h.from*r,s=h.to*r;n.copy(d,t,s),h.from=d/r,d+=s-t,h.to=d/r,e.instances.set(h.id,h)}i.push(new p(0,n.hasNewBuffer?e.buffer.array.length:o)),n.dispose(),e.buffer.erase(d,i.back().to),e.holes.clear()}_remove(e,t,r,s){for(const i of t){const t=i.id,a=e.instances.get(t),o=a.from*r,n=a.to*r;e.buffer.erase(o,n),e.holes.push(new p(a.from,a.to)),e.instances.delete(t),s.push(new p(o,n))}I(e.holes)}_add(e,s,n,d,h){const l=this._bufferWriter;let f=l.vertexBufferLayout.createView(e.buffer.array.buffer);for(const m of s){const s=t(m.transformation)?i(P,d,m.transformation):d;a(L,s);const u=o(L,L),g=l.elementCount(m.data),_=g*n;let w=D(e.holes,g);r(w)&&(w=e.buffer.size/n,e.buffer.grow(_),f=l.vertexBufferLayout.createView(e.buffer.array.buffer)),l.write({transformation:s,invTranspTransformation:u},m.data,f,w);const y=m.instanceParameters.visible,C=!!m.instanceParameters.highlights&&y,H=!!m.instanceParameters.occludees,v=new b(m.id,w,w+g,y,C,H);c(null==e.instances.get(m.id)),e.instances.set(m.id,v),h.push(new p(v.from*n,v.to*n))}}get test(){return{material:this._material,glMaterials:this._glMaterials}}}class O{constructor(e){this.origin=e,this.toAdd=new Array,this.toRemove=new Array}}function A(e,t){const r=new Map;for(const s of e)R(r,s,!0);for(const s of t)R(r,s,!1);return r}function R(e,t,s){const i=t.origin;if(r(i))return;let a=e.get(i.id);null==a&&(a=new O(i.vec3),e.set(i.id,a)),s?a.toAdd.push(t):a.toRemove.push(t)}function S(e){return e.hasOccludees||e.hasHighlights||e.hasHiddenInstances}function D(e,t){let r;if(!e.some((e=>!(e.to-e.from<t)&&(r=e,!0))))return null;const s=r.from;return r.from+=t,r.from>=r.to&&e.removeUnordered(r),s}function I(e){const t=new Map;e.forAll((e=>t.set(e.from,e)));let r=!0;for(;r;)r=!1,e.forEach((s=>{const i=t.get(s.to);i&&(s.to=i.to,t.delete(i.from),e.removeUnordered(i),r=!0)}))}class B{constructor(e,t){this.origin=e,this.buffer=t,this.instances=new Map,this.holes=new s({deallocator:null}),this.hasHiddenInstances=!1,this.hasHighlights=!1,this.hasOccludees=!1,this.drawCommandsDirty=!1}}class M{constructor(e,t,r,s){this.origin=e,this.buffer=t,this.renderCommands=r,this.occludeeCommands=s}}const T=new s({deallocator:null}),E=n(),P=n(),L=n();export{v as MergedRenderer};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.23/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import t from"../../Graphic.js";import"../../symbols.js";import s from"../../core/Collection.js";import i from"../../core/Error.js";import o from"../../core/Handles.js";import r from"../../core/Logger.js";import{unwrap as n,isNone as a}from"../../core/maybe.js";import{init as l,watch as u,whenFalse as h}from"../../core/watchUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{geographicToWebMercator as d}from"../../geometry/support/webMercatorUtils.js";import g from"../../layers/Layer.js";import f from"../../support/actions/ActionBase.js";import m from"../../support/actions/ActionButton.js";import y from"../../support/actions/ActionToggle.js";import{getDisplayedSymbol as w}from"../../symbols/support/symbolUtils.js";import{ViewEventPriorities as F}from"../../views/input/InputManager.js";import{highlightsSupported as v}from"../../views/support/layerViewUtils.js";import _ from"../Feature/FeatureViewModel.js";import{zoomToClusteredFeatures as b,browseClusteredFeatures as C,zoomToFeature as P}from"./actions.js";import{triggerAction as E,getSelectedTarget as A,removeClusteredFeaturesForBrowsing as M,displayClusterExtent as j,browseAggregateFeatures as V}from"./actionUtils.js";import O from"../support/AnchorElementViewModel.js";import{GoToMixin as x}from"../support/GoTo.js";import I from"../../symbols/SimpleFillSymbol.js";import L from"../../geometry/Point.js";const T=s.ofType({key:"type",defaultKeyValue:"button",base:f,typeMap:{button:m,toggle:y}}),S=()=>[P.clone()],B=()=>[b.clone(),C.clone()],R="esri.widgets.Popup.PopupViewModel",G=r.getLogger(R);let z=class extends(x(O)){constructor(e){super(e),this._handles=new o,this._pendingPromises=new Set,this._fetchFeaturesController=null,this._selectedClusterFeature=null,this.featurePage=null,this.actions=new T,this.defaultPopupTemplateEnabled=!1,this.autoCloseEnabled=!1,this.autoOpenEnabled=!0,this.browseClusterEnabled=!1,this.content=null,this.featuresPerPage=20,this.featureViewModelAbilities=null,this.featureViewModels=[],this.highlightEnabled=!0,this.includeDefaultActions=!0,this.selectedClusterBoundaryFeature=new t({symbol:new I({outline:{width:1.5,color:"cyan"},style:"none"})}),this.title=null,this.updateLocationEnabled=!1,this.view=null,this.visible=!1,this.zoomFactor=4,this.zoomToLocation=null}get isLoadingFeature(){return this.featureViewModels.some((e=>e.waitingForContent))}initialize(){this._handles.add([l(this,["autoOpenEnabled","view"],(()=>this._autoOpenEnabledChange())),this.on("view-change",(()=>this._autoClose())),u(this,["highlightEnabled","selectedFeature","visible","view"],(()=>this._highlightFeature())),u(this,"view.animation.state",(e=>this._animationStateChange(e))),u(this,"location",(e=>this._locationChange(e))),u(this,"selectedFeature",(e=>this._selectedFeatureChange(e))),u(this,["selectedFeatureIndex","featureCount","featuresPerPage"],(()=>this._selectedFeatureIndexChange())),u(this,["featurePage","selectedFeatureIndex","featureCount","featuresPerPage, featureViewModels"],(()=>this._setGraphicOnFeatureViewModels())),u(this,"featureViewModels",(()=>this._featureViewModelsChange())),this.on("trigger-action",(e=>E({event:e,view:this.view}))),h(this,"waitingForResult",(()=>this._waitingForResultChange()),!0),u(this,["features","view","view.map","view.spatialReference"],(()=>this._updateFeatureVMs())),u(this,["view.scale"],this._viewScaleChange),h(this,"visible",(()=>this.browseClusterEnabled=!1)),u(this,"browseClusterEnabled",(e=>e?this.enableClusterBrowsing():this.disableClusterBrowsing()))])}destroy(){this._cancelFetchingFeatures(),this._handles.destroy(),this._handles=null,this._pendingPromises.clear(),this.browseClusterEnabled=!1,this.view=null}get active(){return!(!this.visible||this.waitingForResult)}get allActions(){const e=this._get("allActions")||new T;e.removeAll();const{actions:t,defaultActions:s,defaultPopupTemplateEnabled:i,includeDefaultActions:o,selectedFeature:r}=this,n=o?s.concat(t):t,a=r&&("function"==typeof r.getEffectivePopupTemplate&&r.getEffectivePopupTemplate(i)||r.popupTemplate),l=a&&a.actions,u=a&&a.overwriteActions?l:l?l.concat(n):n;return u&&u.filter(Boolean).forEach((t=>e.add(t))),e}get defaultActions(){var e;const t=this._get("defaultActions")||new T;return t.removeAll(),t.addMany(null!=(e=this.selectedFeature)&&e.isAggregate?B():S()),t}get featureCount(){return this.features.length}get features(){return this._get("features")||[]}set features(e){const t=e||[];this._set("features",t);const{pendingPromisesCount:s,promiseCount:i,selectedFeatureIndex:o}=this,r=i&&t.length;r&&s&&-1===o?this.selectedFeatureIndex=0:r&&-1!==o||(this.selectedFeatureIndex=t.length?0:-1)}get location(){return this._get("location")||null}set location(e){const t=this.get("view.spatialReference.isWebMercator");e&&e.get("spatialReference.isWGS84")&&t&&(e=d(e)),this._set("location",e)}get pendingPromisesCount(){return this._pendingPromises.size}get waitingForResult(){return!(!(!!this._fetchFeaturesController||this.pendingPromisesCount>0)||0!==this.featureCount)}get promiseCount(){return this.promises.length}get promises(){return this._get("promises")||[]}set promises(e){if(this._pendingPromises.clear(),this.features=[],!Array.isArray(e)||!e.length)return this._set("promises",[]),void this.notifyChange("pendingPromisesCount");this._set("promises",e),(e=e.slice(0)).forEach((e=>{this._pendingPromises.add(e);const t=t=>{this._pendingPromises.has(e)&&this._updateFeatures(t),this._updatePendingPromises(e)},s=()=>this._updatePendingPromises(e);e.then(t,s)})),this.notifyChange("pendingPromisesCount")}get selectedFeature(){const{features:e,selectedFeatureIndex:t}=this;if(-1===t)return null;return e[t]||null}get selectedFeatureIndex(){const e=this._get("selectedFeatureIndex");return"number"==typeof e?e:-1}set selectedFeatureIndex(e){const{featureCount:t}=this;e=isNaN(e)||e<-1||!t?-1:(e+t)%t,this._set("selectedFeatureIndex",e)}get selectedFeatureViewModel(){return this.featureViewModels[this.selectedFeatureIndex]||null}get state(){return this.get("view.ready")?"ready":"disabled"}centerAtLocation(){const{view:e}=this,t=A(this);if(!t){const s=new i("center-at-location:invalid-target-or-view","Cannot center at a location without a target and view.",{target:t,view:e});return G.error(s),Promise.reject(s)}return this.callGoTo({target:{target:t,scale:e.scale}})}clear(){this.set({promises:[],features:[],content:null,title:null,location:null})}fetchFeatures(e,t){const{view:s}=this;if(!s||!e){const t=new i("fetch-features:invalid-screenpoint-or-view","Cannot fetch features without a screenPoint and view.",{screenPoint:e,view:s});return G.error(t),Promise.reject(t)}return s.fetchPopupFeatures(e,{event:t&&t.event,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,signal:t&&t.signal})}open(e){const t={updateLocationEnabled:!1,promises:[],fetchFeatures:!1,...e,visible:!0},{fetchFeatures:s}=t;delete t.fetchFeatures,s&&this._setFetchFeaturesPromises(t.location);const i=["actionsMenuOpen","collapsed","featureMenuOpen"];for(const o of i)delete t[o];this.set(t)}triggerAction(e){const t=this.allActions.getItemAt(e);t&&!t.disabled&&this.emit("trigger-action",{action:t})}next(){return this.selectedFeatureIndex=this.selectedFeatureIndex+1,this}previous(){return this.selectedFeatureIndex=this.selectedFeatureIndex-1,this}disableClusterBrowsing(){M(this),this._clearBrowsedClusterGraphics()}async enableClusterBrowsing(){await j(this),await V(this)}_animationStateChange(e){this.zoomToLocation||(P.disabled="waiting-for-target"===e)}_clearBrowsedClusterGraphics(){var e;const t=null==(e=this.view)?void 0:e.graphics;t&&(t.remove(this.selectedClusterBoundaryFeature),t.remove(this._selectedClusterFeature)),this._selectedClusterFeature=null,this.selectedClusterBoundaryFeature.geometry=null}_viewScaleChange(){var e;(null!=(e=this.selectedFeature)&&e.isAggregate||this.browseClusterEnabled)&&(this.browseClusterEnabled=!1,this.visible=!1)}_locationChange(e){const{selectedFeature:t,updateLocationEnabled:s}=this;s&&e&&(!t||t.geometry)&&this.centerAtLocation()}_selectedFeatureIndexChange(){this.featurePage=this.featureCount>1?Math.floor(this.selectedFeatureIndex/this.featuresPerPage)+1:null}_featureViewModelsChange(){this.featurePage=this.featureCount>1?1:null}_setGraphicOnFeatureViewModels(){const{features:e,featureCount:t,featurePage:s,featuresPerPage:i,featureViewModels:o}=this;if(null===s)return;const r=((s-1)*i+t)%t,n=r+i;o.slice(r,n).forEach(((t,s)=>{t&&!t.graphic&&(t.graphic=e[r+s])}))}async _selectedFeatureChange(e){if(!e)return;const{location:t,updateLocationEnabled:s,view:i}=this;if(this.browseClusterEnabled){if(this._selectedClusterFeature&&(i.graphics.remove(this._selectedClusterFeature),this._selectedClusterFeature=null),e.isAggregate)return;return e.symbol=await w(e),this._selectedClusterFeature=e,void i.graphics.add(this._selectedClusterFeature)}!s&&t||!e.geometry?s&&!e.geometry&&this.centerAtLocation().then((()=>{this.location=i.center.clone()})):this.location=n(this._getPointFromGeometry(e.geometry))}_waitingForResultChange(){!this.featureCount&&this.promises&&(this.visible=!1)}_setFetchFeaturesPromises(e){return this._fetchFeaturesWithController(this._getScreenPoint(e||this.location)).then((e=>{const{clientOnlyGraphics:t,promisesPerLayerView:s}=e,i=Promise.resolve(t),o=s.map((e=>e.promise));this.promises=[i,...o]}))}_destroyFeatureVMs(){this.featureViewModels.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",[])}_updateFeatureVMs(){const{selectedFeature:e,features:t,featureViewModels:s}=this;if(null!=e&&e.isAggregate||(this.browseClusterEnabled=!1),this._destroyFeatureVMs(),!t||!t.length)return;const i=s.slice(0),o=[];t.forEach(((t,s)=>{if(!t)return;let r=null;if(i.some(((e,s)=>(e&&e.graphic===t&&(r=e,i.splice(s,1)),!!r))),r)o[s]=r;else{var n,a;const i=new _({abilities:this.featureViewModelAbilities,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,spatialReference:null==(n=this.view)?void 0:n.spatialReference,graphic:t===e?t:null,map:null==(a=this.view)?void 0:a.map,view:this.view});o[s]=i}})),i.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",o)}_getScreenPoint(e){const{view:t}=this;return t&&e&&"function"==typeof t.toScreen?t.toScreen(e):null}_autoOpenEnabledChange(){const e="auto-fetch-features",{_handles:t,autoOpenEnabled:s}=this;if(t.remove(e),s&&this.view){const s=this.view.on("click",(e=>{"mouse"===e.pointerType&&0!==e.button||this._fetchFeaturesAndOpen(e)}),F.WIDGET);t.add(s,e)}}_cancelFetchingFeatures(){const e=this._fetchFeaturesController;e&&e.abort(),this._fetchFeaturesController=null,this.notifyChange("waitingForResult")}_fetchFeaturesWithController(e,t){this._cancelFetchingFeatures();const s=new AbortController,{signal:i}=s;this._fetchFeaturesController=s,this.notifyChange("waitingForResult");const o=this.fetchFeatures(e,{signal:i,event:t});return o.catch((()=>{})).then((()=>{this._fetchFeaturesController=null,this.notifyChange("waitingForResult")})),o}_fetchFeaturesAndOpen(e){const{screenPoint:t,mapPoint:s}=e,{view:i}=this;this._fetchFeaturesWithController(t,e).then((e=>{const{clientOnlyGraphics:t,promisesPerLayerView:o,location:r}=e,n=[Promise.resolve(t),...o.map((e=>e.promise))];return i.popup.open({location:r||s,promises:n}),e}))}_updatePendingPromises(e){e&&this._pendingPromises.has(e)&&(this._pendingPromises.delete(e),this.notifyChange("pendingPromisesCount"))}_autoClose(){this.autoCloseEnabled&&(this.visible=!1)}_getPointFromGeometry(e){return a(e)?null:"point"===e.type?e:"extent"===e.type?e.center:"polygon"===e.type?e.centroid:"multipoint"===e.type||"polyline"===e.type?e.extent.center:null}async _getLayerView(e,t){return await e.when(),e.whenLayerView(t)}async _highlightFeature(){const e="highlight";this._handles.remove(e);const{selectedFeature:t,highlightEnabled:s,view:i,visible:o}=this;if(!(t&&i&&s&&o))return;let{layer:r,sourceLayer:n}=t;if("map-notes"!==(null==n?void 0:n.type)&&"subtype-group"!==(null==n?void 0:n.type)||(r=n),!(r&&r instanceof g))return;const a=this._getLayerView(i,r);this._highlightPromise=a;const l=await a;if(!(l&&v(l)&&this._highlightPromise===a&&this.selectedFeature&&this.highlightEnabled&&this.visible))return;const u="objectIdField"in r&&r.objectIdField,h=t.attributes,c=h&&u&&h[u],p=l.highlight(c||t);this._handles.add(p,e)}_updateFeatures(e){const{features:t}=this;if(!e||!e.length)return;if(!t.length)return void(this.features=e);const s=e.filter((e=>-1===t.indexOf(e)));this.features=t.concat(s)}};e([c()],z.prototype,"featurePage",void 0),e([c()],z.prototype,"isLoadingFeature",null),e([c({type:T})],z.prototype,"actions",void 0),e([c({readOnly:!0})],z.prototype,"active",null),e([c({readOnly:!0})],z.prototype,"allActions",null),e([c({type:Boolean})],z.prototype,"defaultPopupTemplateEnabled",void 0),e([c()],z.prototype,"autoCloseEnabled",void 0),e([c()],z.prototype,"autoOpenEnabled",void 0),e([c()],z.prototype,"browseClusterEnabled",void 0),e([c()],z.prototype,"content",void 0),e([c({type:T,readOnly:!0})],z.prototype,"defaultActions",null),e([c({readOnly:!0})],z.prototype,"featureCount",null),e([c()],z.prototype,"features",null),e([c()],z.prototype,"featuresPerPage",void 0),e([c()],z.prototype,"featureViewModelAbilities",void 0),e([c({readOnly:!0})],z.prototype,"featureViewModels",void 0),e([c()],z.prototype,"highlightEnabled",void 0),e([c()],z.prototype,"includeDefaultActions",void 0),e([c({type:L})],z.prototype,"location",null),e([c({readOnly:!0})],z.prototype,"pendingPromisesCount",null),e([c({readOnly:!0})],z.prototype,"selectedClusterBoundaryFeature",void 0),e([c({readOnly:!0})],z.prototype,"waitingForResult",null),e([c({readOnly:!0})],z.prototype,"promiseCount",null),e([c()],z.prototype,"promises",null),e([c({value:null,readOnly:!0})],z.prototype,"selectedFeature",null),e([c({value:-1})],z.prototype,"selectedFeatureIndex",null),e([c({readOnly:!0})],z.prototype,"selectedFeatureViewModel",null),e([c({readOnly:!0})],z.prototype,"state",null),e([c()],z.prototype,"title",void 0),e([c()],z.prototype,"updateLocationEnabled",void 0),e([c()],z.prototype,"view",void 0),e([c()],z.prototype,"visible",void 0),e([c()],z.prototype,"zoomFactor",void 0),e([c()],z.prototype,"zoomToLocation",void 0),e([c()],z.prototype,"centerAtLocation",null),z=e([p(R)],z);const U=z;export{U as default};
5
+ import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import t from"../../Graphic.js";import"../../symbols.js";import s from"../../core/Collection.js";import i from"../../core/Error.js";import o from"../../core/Handles.js";import r from"../../core/Logger.js";import{unwrap as n,isNone as a}from"../../core/maybe.js";import{init as l,watch as u,whenFalse as h}from"../../core/watchUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{geographicToWebMercator as d}from"../../geometry/support/webMercatorUtils.js";import g from"../../layers/Layer.js";import f from"../../support/actions/ActionBase.js";import m from"../../support/actions/ActionButton.js";import y from"../../support/actions/ActionToggle.js";import{getDisplayedSymbol as w}from"../../symbols/support/symbolUtils.js";import{ViewEventPriorities as v}from"../../views/input/InputManager.js";import{highlightsSupported as F}from"../../views/support/layerViewUtils.js";import _ from"../Feature/FeatureViewModel.js";import{zoomToClusteredFeatures as b,browseClusteredFeatures as C,zoomToFeature as P}from"./actions.js";import{triggerAction as E,getSelectedTarget as A,removeClusteredFeaturesForBrowsing as M,displayClusterExtent as j,browseAggregateFeatures as V}from"./actionUtils.js";import O from"../support/AnchorElementViewModel.js";import{GoToMixin as x}from"../support/GoTo.js";import I from"../../symbols/SimpleFillSymbol.js";import L from"../../geometry/Point.js";const T=s.ofType({key:"type",defaultKeyValue:"button",base:f,typeMap:{button:m,toggle:y}}),S=()=>[P.clone()],B=()=>[b.clone(),C.clone()],R="esri.widgets.Popup.PopupViewModel",G=r.getLogger(R);let z=class extends(x(O)){constructor(e){super(e),this._handles=new o,this._pendingPromises=new Set,this._fetchFeaturesController=null,this._selectedClusterFeature=null,this.featurePage=null,this.actions=new T,this.defaultPopupTemplateEnabled=!1,this.autoCloseEnabled=!1,this.autoOpenEnabled=!0,this.browseClusterEnabled=!1,this.content=null,this.featuresPerPage=20,this.featureViewModelAbilities=null,this.featureViewModels=[],this.highlightEnabled=!0,this.includeDefaultActions=!0,this.selectedClusterBoundaryFeature=new t({symbol:new I({outline:{width:1.5,color:"cyan"},style:"none"})}),this.title=null,this.updateLocationEnabled=!1,this.view=null,this.visible=!1,this.zoomFactor=4,this.zoomToLocation=null}get isLoadingFeature(){return this.featureViewModels.some((e=>e.waitingForContent))}initialize(){this._handles.add([l(this,["autoOpenEnabled","view"],(()=>this._autoOpenEnabledChange())),this.on("view-change",(()=>this._autoClose())),u(this,["highlightEnabled","selectedFeature","visible","view"],(()=>this._highlightFeature())),u(this,"view.animation.state",(e=>this._animationStateChange(e))),u(this,"location",(e=>this._locationChange(e))),u(this,"selectedFeature",(e=>this._selectedFeatureChange(e))),u(this,["selectedFeatureIndex","featureCount","featuresPerPage"],(()=>this._selectedFeatureIndexChange())),u(this,["featurePage","selectedFeatureIndex","featureCount","featuresPerPage, featureViewModels"],(()=>this._setGraphicOnFeatureViewModels())),u(this,"featureViewModels",(()=>this._featureViewModelsChange())),this.on("trigger-action",(e=>E({event:e,view:this.view}))),h(this,"waitingForResult",(()=>this._waitingForResultChange()),!0),u(this,["features","view","view.map","view.spatialReference"],(()=>this._updateFeatureVMs())),u(this,["view.scale"],this._viewScaleChange),h(this,"visible",(()=>this.browseClusterEnabled=!1)),u(this,"browseClusterEnabled",(e=>e?this.enableClusterBrowsing():this.disableClusterBrowsing()))])}destroy(){this._cancelFetchingFeatures(),this._handles.destroy(),this._handles=null,this._pendingPromises.clear(),this.browseClusterEnabled=!1,this.view=null}get active(){return!(!this.visible||this.waitingForResult)}get allActions(){const e=this._get("allActions")||new T;e.removeAll();const{actions:t,defaultActions:s,defaultPopupTemplateEnabled:i,includeDefaultActions:o,selectedFeature:r}=this,n=o?s.concat(t):t,a=r&&("function"==typeof r.getEffectivePopupTemplate&&r.getEffectivePopupTemplate(i)||r.popupTemplate),l=a&&a.actions,u=a&&a.overwriteActions?l:l?l.concat(n):n;return u&&u.filter(Boolean).forEach((t=>e.add(t))),e}get defaultActions(){var e;const t=this._get("defaultActions")||new T;return t.removeAll(),t.addMany(null!=(e=this.selectedFeature)&&e.isAggregate?B():S()),t}get featureCount(){return this.features.length}get features(){return this._get("features")||[]}set features(e){const t=e||[];this._set("features",t);const{pendingPromisesCount:s,promiseCount:i,selectedFeatureIndex:o}=this,r=i&&t.length;r&&s&&-1===o?this.selectedFeatureIndex=0:r&&-1!==o||(this.selectedFeatureIndex=t.length?0:-1)}get location(){return this._get("location")||null}set location(e){const t=this.get("view.spatialReference.isWebMercator");e&&e.get("spatialReference.isWGS84")&&t&&(e=d(e)),this._set("location",e)}get pendingPromisesCount(){return this._pendingPromises.size}get waitingForResult(){return!(!(!!this._fetchFeaturesController||this.pendingPromisesCount>0)||0!==this.featureCount)}get promiseCount(){return this.promises.length}get promises(){return this._get("promises")||[]}set promises(e){if(this._pendingPromises.clear(),this.features=[],!Array.isArray(e)||!e.length)return this._set("promises",[]),void this.notifyChange("pendingPromisesCount");this._set("promises",e),(e=e.slice(0)).forEach((e=>{this._pendingPromises.add(e);const t=t=>{this._pendingPromises.has(e)&&this._updateFeatures(t),this._updatePendingPromises(e)},s=()=>this._updatePendingPromises(e);e.then(t,s)})),this.notifyChange("pendingPromisesCount")}get selectedFeature(){const{features:e,selectedFeatureIndex:t}=this;if(-1===t)return null;return e[t]||null}get selectedFeatureIndex(){const e=this._get("selectedFeatureIndex");return"number"==typeof e?e:-1}set selectedFeatureIndex(e){const{featureCount:t}=this;e=isNaN(e)||e<-1||!t?-1:(e+t)%t,this._set("selectedFeatureIndex",e)}get selectedFeatureViewModel(){return this.featureViewModels[this.selectedFeatureIndex]||null}get state(){return this.get("view.ready")?"ready":"disabled"}centerAtLocation(){const{view:e}=this,t=A(this);if(!t){const s=new i("center-at-location:invalid-target-or-view","Cannot center at a location without a target and view.",{target:t,view:e});return G.error(s),Promise.reject(s)}return this.callGoTo({target:{target:t,scale:e.scale}})}clear(){this.set({promises:[],features:[],content:null,title:null,location:null})}fetchFeatures(e,t){const{view:s}=this;if(!s||!e){const t=new i("fetch-features:invalid-screenpoint-or-view","Cannot fetch features without a screenPoint and view.",{screenPoint:e,view:s});return G.error(t),Promise.reject(t)}return s.fetchPopupFeatures(e,{event:t&&t.event,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,signal:t&&t.signal})}open(e){const t={updateLocationEnabled:!1,promises:[],fetchFeatures:!1,...e,visible:!0},{fetchFeatures:s}=t;delete t.fetchFeatures,s&&this._setFetchFeaturesPromises(t.location);const i=["actionsMenuOpen","collapsed","featureMenuOpen"];for(const o of i)delete t[o];this.set(t)}triggerAction(e){const t=this.allActions.getItemAt(e);t&&!t.disabled&&this.emit("trigger-action",{action:t})}next(){return this.selectedFeatureIndex=this.selectedFeatureIndex+1,this}previous(){return this.selectedFeatureIndex=this.selectedFeatureIndex-1,this}disableClusterBrowsing(){M(this),this._clearBrowsedClusterGraphics()}async enableClusterBrowsing(){await j(this),await V(this)}_animationStateChange(e){this.zoomToLocation||(P.disabled="waiting-for-target"===e)}_clearBrowsedClusterGraphics(){var e;const t=null==(e=this.view)?void 0:e.graphics;t&&(t.remove(this.selectedClusterBoundaryFeature),t.remove(this._selectedClusterFeature)),this._selectedClusterFeature=null,this.selectedClusterBoundaryFeature.geometry=null}_viewScaleChange(){var e;(null!=(e=this.selectedFeature)&&e.isAggregate||this.browseClusterEnabled)&&(this.browseClusterEnabled=!1,this.visible=!1)}_locationChange(e){const{selectedFeature:t,updateLocationEnabled:s}=this;s&&e&&(!t||t.geometry)&&this.centerAtLocation()}_selectedFeatureIndexChange(){this.featurePage=this.featureCount>1?Math.floor(this.selectedFeatureIndex/this.featuresPerPage)+1:null}_featureViewModelsChange(){this.featurePage=this.featureCount>1?1:null}_setGraphicOnFeatureViewModels(){const{features:e,featureCount:t,featurePage:s,featuresPerPage:i,featureViewModels:o}=this;if(null===s)return;const r=((s-1)*i+t)%t,n=r+i;o.slice(r,n).forEach(((t,s)=>{t&&!t.graphic&&(t.graphic=e[r+s])}))}async _selectedFeatureChange(e){if(!e)return;const{location:t,updateLocationEnabled:s,view:i}=this;if(this.browseClusterEnabled){if(this._selectedClusterFeature&&(i.graphics.remove(this._selectedClusterFeature),this._selectedClusterFeature=null),e.isAggregate)return;return e.symbol=await w(e),this._selectedClusterFeature=e,void i.graphics.add(this._selectedClusterFeature)}!s&&t||!e.geometry?s&&!e.geometry&&this.centerAtLocation().then((()=>{this.location=i.center.clone()})):this.location=n(this._getPointFromGeometry(e.geometry))}_waitingForResultChange(){!this.featureCount&&this.promises&&(this.visible=!1)}_setFetchFeaturesPromises(e){return this._fetchFeaturesWithController(this._getScreenPoint(e||this.location)).then((e=>{const{clientOnlyGraphics:t,promisesPerLayerView:s}=e,i=Promise.resolve(t),o=s.map((e=>e.promise));this.promises=[i,...o]}))}_destroyFeatureVMs(){this.featureViewModels.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",[])}_updateFeatureVMs(){const{selectedFeature:e,features:t,featureViewModels:s}=this;if(null!=e&&e.isAggregate||(this.browseClusterEnabled=!1),this._destroyFeatureVMs(),!t||!t.length)return;const i=s.slice(0),o=[];t.forEach(((t,s)=>{if(!t)return;let r=null;if(i.some(((e,s)=>(e&&e.graphic===t&&(r=e,i.splice(s,1)),!!r))),r)o[s]=r;else{var n,a;const i=new _({abilities:this.featureViewModelAbilities,defaultPopupTemplateEnabled:this.defaultPopupTemplateEnabled,spatialReference:null==(n=this.view)?void 0:n.spatialReference,graphic:t===e?t:null,map:null==(a=this.view)?void 0:a.map,view:this.view});o[s]=i}})),i.forEach((e=>e&&!e.destroyed&&e.destroy())),this._set("featureViewModels",o)}_getScreenPoint(e){const{view:t}=this;return t&&e&&"function"==typeof t.toScreen?t.toScreen(e):null}_autoOpenEnabledChange(){const e="auto-fetch-features",{_handles:t,autoOpenEnabled:s}=this;if(t.remove(e),s&&this.view){const s=this.view.on("click",(e=>{"mouse"===e.pointerType&&0!==e.button||this._fetchFeaturesAndOpen(e)}),v.WIDGET);t.add(s,e)}}_cancelFetchingFeatures(){const e=this._fetchFeaturesController;e&&e.abort(),this._fetchFeaturesController=null,this.notifyChange("waitingForResult")}_fetchFeaturesWithController(e,t){this._cancelFetchingFeatures();const s=new AbortController,{signal:i}=s;this._fetchFeaturesController=s,this.notifyChange("waitingForResult");const o=this.fetchFeatures(e,{signal:i,event:t});return o.catch((()=>{})).then((()=>{this._fetchFeaturesController=null,this.notifyChange("waitingForResult")})),o}_fetchFeaturesAndOpen(e){const{screenPoint:t,mapPoint:s}=e,{view:i}=this;this._fetchFeaturesWithController(t,e).then((e=>{const{clientOnlyGraphics:t,promisesPerLayerView:o,location:r}=e,n=[Promise.resolve(t),...o.map((e=>e.promise))];return i.popup.open({location:r||s,promises:n}),e}))}_updatePendingPromises(e){e&&this._pendingPromises.has(e)&&(this._pendingPromises.delete(e),this.notifyChange("pendingPromisesCount"))}_autoClose(){this.autoCloseEnabled&&(this.visible=!1)}_getPointFromGeometry(e){return a(e)?null:"point"===e.type?e:"extent"===e.type?e.center:"polygon"===e.type?e.centroid:"multipoint"===e.type||"polyline"===e.type?e.extent.center:null}async _getLayerView(e,t){return await e.when(),e.whenLayerView(t)}async _highlightFeature(){const e="highlight";this._handles.remove(e);const{selectedFeature:t,highlightEnabled:s,view:i,visible:o}=this;if(!(t&&i&&s&&o))return;let{layer:r,sourceLayer:n}=t;if("map-notes"!==(null==n?void 0:n.type)&&"subtype-group"!==(null==n?void 0:n.type)||(r=n),!(r&&r instanceof g))return;const a=this._getLayerView(i,r);this._highlightPromise=a;const l=await a;if(!(l&&F(l)&&this._highlightPromise===a&&this.selectedFeature&&this.highlightEnabled&&this.visible))return;const u="imagery"===r.type?void 0:"objectIdField"in r&&r.objectIdField,h=t.attributes,c=h&&u&&h[u],p=l.highlight(c||t);this._handles.add(p,e)}_updateFeatures(e){const{features:t}=this;if(!e||!e.length)return;if(!t.length)return void(this.features=e);const s=e.filter((e=>-1===t.indexOf(e)));this.features=t.concat(s)}};e([c()],z.prototype,"featurePage",void 0),e([c()],z.prototype,"isLoadingFeature",null),e([c({type:T})],z.prototype,"actions",void 0),e([c({readOnly:!0})],z.prototype,"active",null),e([c({readOnly:!0})],z.prototype,"allActions",null),e([c({type:Boolean})],z.prototype,"defaultPopupTemplateEnabled",void 0),e([c()],z.prototype,"autoCloseEnabled",void 0),e([c()],z.prototype,"autoOpenEnabled",void 0),e([c()],z.prototype,"browseClusterEnabled",void 0),e([c()],z.prototype,"content",void 0),e([c({type:T,readOnly:!0})],z.prototype,"defaultActions",null),e([c({readOnly:!0})],z.prototype,"featureCount",null),e([c()],z.prototype,"features",null),e([c()],z.prototype,"featuresPerPage",void 0),e([c()],z.prototype,"featureViewModelAbilities",void 0),e([c({readOnly:!0})],z.prototype,"featureViewModels",void 0),e([c()],z.prototype,"highlightEnabled",void 0),e([c()],z.prototype,"includeDefaultActions",void 0),e([c({type:L})],z.prototype,"location",null),e([c({readOnly:!0})],z.prototype,"pendingPromisesCount",null),e([c({readOnly:!0})],z.prototype,"selectedClusterBoundaryFeature",void 0),e([c({readOnly:!0})],z.prototype,"waitingForResult",null),e([c({readOnly:!0})],z.prototype,"promiseCount",null),e([c()],z.prototype,"promises",null),e([c({value:null,readOnly:!0})],z.prototype,"selectedFeature",null),e([c({value:-1})],z.prototype,"selectedFeatureIndex",null),e([c({readOnly:!0})],z.prototype,"selectedFeatureViewModel",null),e([c({readOnly:!0})],z.prototype,"state",null),e([c()],z.prototype,"title",void 0),e([c()],z.prototype,"updateLocationEnabled",void 0),e([c()],z.prototype,"view",void 0),e([c()],z.prototype,"visible",void 0),e([c()],z.prototype,"zoomFactor",void 0),e([c()],z.prototype,"zoomToLocation",void 0),e([c()],z.prototype,"centerAtLocation",null),z=e([p(R)],z);const U=z;export{U as default};