UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 7.43 kB
import{_ as e}from"../../../../chunks/tslib.es6.js";import r from"../../../../core/Accessor.js";import{someMap as t}from"../../../../core/MapUtils.js";import{unwrap as s,isNone as i,isSome as n}from"../../../../core/maybe.js";import a from"../../../../core/PooledArray.js";import{property as o}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as d}from"../../../../core/accessorSupport/decorators/subclass.js";import{a as h}from"../../../../chunks/vec2f64.js";import{OverlayTarget as l}from"../../terrain/Intersector.js";import{ChangeSet as c}from"./ChangeSet.js";import{newIntersectorResult as p}from"./Intersector.js";import{StoreResults as m,IntersectorType as g}from"./IntersectorInterfaces.js";import{DirtyOperation as u,DirtyState as _}from"./ModelDirtyTypes.js";import{splitRenderGeometryChangeSetByMaterial as y}from"./rendererUtils.js";import{MergedRenderer as f}from"../materials/renderers/MergedRenderer.js";let R=class extends r{constructor(e){super(e),this._pending=new G,this._changes=new c,this._materialRenderers=new Map,this._sortedMaterialRenderers=new a,this._geometries=new Map,this._hasHighlights=!1,this._hasWater=!1}destroy(){this._changes.prune(),this._materialRenderers.forEach((e=>e.dispose())),this._materialRenderers.clear(),this._sortedMaterialRenderers.clear(),this._geometries.clear()}get updating(){return!this._pending.empty||this._changes.updates.length>0}get rctx(){return this.rendererContext.rctx}get _materialRepository(){return this.rendererContext.materialRepository}get _localOriginFactory(){return this.rendererContext.localOriginFactory}get hasHighlights(){return this._hasHighlights}get hasWater(){return this._hasWater}get rendersOccluded(){return t(this._materialRenderers,(e=>e.rendersOccluded))}get isEmpty(){return!this.updating&&0===this._materialRenderers.size&&0===this._geometries.size}commitChanges(){if(!this.updating)return!1;this._processAddsRemoves();const e=y(this._changes);let r=!1,s=!1,i=!1;return e.forEach(((e,t)=>{let n=this._materialRenderers.get(t);if(!n&&e.adds.length>0&&(n=new f(this.rctx,this._materialRepository,t),this._materialRenderers.set(t,n),r=!0,s=!0,i=!0),!n)return;const a=s||n.hasHighlights,o=i||n.hasWater;n.modify(e),s=s||a!==n.hasHighlights,i=i||o!==n.hasWater,n.isEmpty&&(this._materialRenderers.delete(t),n.dispose(),r=!0)})),this._changes.clear(),r&&this._updateSortedMaterialRenderers(),s&&(this._hasHighlights=t(this._materialRenderers,(e=>e.hasHighlights))),i&&(this._hasWater=t(this._materialRenderers,(e=>e.hasWater))),this.notifyChange("updating"),!0}addGeometries(e,r){if(0===e.length)return;const t=this._validateRenderGeometries(e);for(const i of t)this._geometries.set(i.id,i);const s=this._pending.empty;for(const i of t)this._pending.adds.add(i);s&&this.notifyChange("updating"),r===u.UPDATE&&this._notifyGraphicGeometryChanged(e)}removeGeometries(e,r){const t=this._pending.empty,i=this._pending.adds;for(const n of e)i.has(n)?(this._pending.removed.add(n),i.delete(n)):this._pending.removed.has(n)||this._pending.removes.add(n),this._geometries.delete(s(n.id));t&&!this._pending.empty&&this.notifyChange("updating"),r===u.UPDATE&&this._notifyGraphicGeometryChanged(e)}modifyGeometries(e,r){const t=0===this._changes.updates.length;for(const s of e){const e=this._changes.updates.pushNew();e.renderGeometry=this._validateRenderGeometry(s),e.updateType=r}switch(t&&this._changes.updates.length>0&&this.notifyChange("updating"),r){case _.TRANSFORMATION:case _.GEOMETRY:return this._notifyGraphicGeometryChanged(e);case _.VISIBILITY:return this._notifyGraphicVisibilityChanged(e)}}updateAnimation(e){let r=!1;return this._sortedMaterialRenderers.forAll((t=>r=t.updateAnimation(e)||r)),r}render(e){this._sortedMaterialRenderers.forAll((r=>{r.material.shouldRender(e)&&r.render(e.output,e.bindParameters)}))}intersect(e,r,t,s,i){return this._geometries.forEach((n=>{if(s&&!s(n))return;this._intersectRenderGeometry(n,t,r,0,e,i);const a=this.rendererContext.longitudeCyclical;a&&(n.boundingSphere[0]-n.boundingSphere[3]<a.min&&this._intersectRenderGeometry(n,t,r,a.range,e,i),n.boundingSphere[0]+n.boundingSphere[3]>a.max&&this._intersectRenderGeometry(n,t,r,-a.range,e,i)),i++})),i}_updateSortedMaterialRenderers(){this._sortedMaterialRenderers.clear();let e=0;this._materialRenderers.forEach(((r,t)=>{t.insertOrder=e++,this._sortedMaterialRenderers.push(r)})),this._sortedMaterialRenderers.sort(((e,r)=>{const t=r.material.renderPriority-e.material.renderPriority;return 0!==t?t:e.material.insertOrder-r.material.insertOrder}))}_processAddsRemoves(){this._changes.adds.clear(),this._changes.removes.clear(),this._changes.adds.pushArray(Array.from(this._pending.adds)),this._changes.removes.pushArray(Array.from(this._pending.removes));for(let e=0;e<this._changes.updates.length;){const r=this._changes.updates.data[e];this._pending.has(r.renderGeometry)?this._changes.updates.removeUnorderedIndex(e):e++}this._pending.clear()}_intersectRenderGeometry(e,r,t,s,i,n){if(!e.visible)return;let a=0;s+=e.transformation[12],a=e.transformation[13],C[0]=t[0]-s,C[1]=t[1]-a,e.screenToWorldRatio=this.rendererContext.screenToWorldRatio,e.material.intersectDraped(e,null,i,C,((t,s,a)=>{v(r,a,e.material.renderPriority,n,i,e.layerUid,e.graphicUid)}),r)}_notifyGraphicGeometryChanged(e){if(i(this.drapeSource.notifyGraphicGeometryChanged))return;let r;for(const t of e){const e=t.graphicUid;n(e)&&e!==r&&(this.drapeSource.notifyGraphicGeometryChanged(e),r=e)}}_notifyGraphicVisibilityChanged(e){if(i(this.drapeSource.notifyGraphicVisibilityChanged))return;let r;for(const t of e){const e=t.graphicUid;n(e)&&e!==r&&(this.drapeSource.notifyGraphicVisibilityChanged(e),r=e)}}_validateRenderGeometries(e){for(const r of e)this._validateRenderGeometry(r);return e}_validateRenderGeometry(e){return i(e.localOrigin)&&(e.localOrigin=this._localOriginFactory.getOrigin(e.boundingSphere)),e}get test(){return{sortedMaterialRenderers:this._sortedMaterialRenderers}}};e([o()],R.prototype,"drapeSource",void 0),e([o()],R.prototype,"updating",null),e([o()],R.prototype,"rctx",null),e([o()],R.prototype,"rendererContext",void 0),e([o()],R.prototype,"_materialRepository",null),e([o()],R.prototype,"_localOriginFactory",null),e([o({readOnly:!0})],R.prototype,"isEmpty",null),e([o()],R.prototype,"_materialRenderers",void 0),e([o()],R.prototype,"_geometries",void 0),R=e([d("esri.views.3d.webgl-engine.lib.SortedRenderGeometryRenderer")],R);class G{constructor(){this.adds=new Set,this.removes=new Set,this.removed=new Set}get empty(){return 0===this.adds.size&&0===this.removes.size&&0===this.removed.size}has(e){return this.adds.has(e)||this.removes.has(e)||this.removed.has(e)}clear(){this.adds.clear(),this.removes.clear(),this.removed.clear()}}function v(e,r,t,s,i,n,a){const o=new l(n,a,r),d=r=>{r.set(g.OVERLAY,o,e.dist,e.normal,e.transformation,t,s)};if((null==i.results.min.drapedLayerOrder||t>=i.results.min.drapedLayerOrder)&&(null==i.results.min.dist||i.results.ground.dist<=i.results.min.dist)&&d(i.results.min),i.options.store!==m.MIN&&(null==i.results.max.drapedLayerOrder||t<i.results.max.drapedLayerOrder)&&(null==i.results.max.dist||i.results.ground.dist>i.results.max.dist)&&d(i.results.max),i.options.store===m.ALL){const e=p(i.ray);d(e),i.results.all.push(e)}}const C=h();export{R as SortedRenderGeometryRenderer};