@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.73 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as e}from"../../../../../../chunks/tslib.es6.js";import has from"../../../../../../core/has.js";import{throwIfAborted as r}from"../../../../../../core/promiseUtils.js";import"../../../../../../core/Logger.js";import"../../../../../../core/RandomLCG.js";import"../../../../../../core/Error.js";import{subclass as s}from"../../../../../../core/accessorSupport/decorators/subclass.js";import{VertexAttribute as o}from"../../../../webgl-engine/lib/VertexAttribute.js";import{LodRenderer as n}from"../../../../webgl-engine/lib/lodRendering/LodRenderer.js";import{LodComponentRenderGeometry as t,LodComponentResources as i,LodLevelResources as a,LodResources as d}from"../../../../webgl-engine/lib/lodRendering/LodResources.js";let l=class{constructor(e){this._optionalFields=new Array,this._featureIdToInstanceIndex=new Map,this._disposeResourceHandles=new Array,this._lodRendererResources=null,this.layerUid=e.layerUid,this.view=e.view,this.sharedResources=this.view.sharedSymbolResources,this.scheduler=this.view.resourceController.scheduler}get numFeatures(){return this._featureIdToInstanceIndex.size}get usedMemory(){const e=this._lodRendererResources?.lodRenderer,r=e?.symbol;return(r?.computeUsedMemory()??0)+16*this._featureIdToInstanceIndex.size}destroy(){this._disposeResourceHandles.forEach((e=>e()))}async doLoad(e,s,n){has("enable-feature:objectAndLayerId-rendering")&&this._optionalFields.push(o.OBJECTANDLAYERIDCOLOR);const t=c((e=>s(e)),e),i=this.view._stage,a=t.getMaterials();i.addMany(a),this._addDisposeResource((()=>i.removeMany(a)));const d=t.getTextures();i.addMany(d),this._addDisposeResource((()=>{d.forEach((e=>e.unload())),i.removeMany(d)})),await Promise.all(d.map((e=>this.view._stage.schedule((()=>e.load(i.renderView.renderingContext)),n)))),r(n);const l=await this._createLodRenderer(t,n);this._lodRendererResources={lodRenderer:l,materials:a,textures:d}}addInstances(e){const r=this._lodRendererResources;if(null==r)return;const{featureIds:s,localTransforms:o,globalTransforms:n}=e,t=r.lodRenderer;if(null==t)return;const i=t.instanceData,a=s.length;for(let d=0;d<a;++d){const e=s[d],r=i.addInstance(),t=i.view,a=16*d;t.localTransform.copyFromTypedBuffer(r,o,a),t.globalTransform.copyFromTypedBuffer(r,n,a),i.updateModelTransform(r),i.setVisible(r,!0),this._featureIdToInstanceIndex.set(e,r)}}removeInstances(e){const r=this._lodRendererResources;if(null==r)return;const s=r.lodRenderer.instanceData,o=this._featureIdToInstanceIndex,n=e.length;for(let t=0;t<n;++t){const r=e[t],n=o.get(r);null!=n&&(s.removeInstance(n),o.delete(r))}}_addDisposeResource(e){this._disposeResourceHandles.push(e)}async _createLodRenderer(e,r){const s=this.view._stage,o={layerUid:this.layerUid,graphicUid:e=>1,notifyGraphicGeometryChanged:e=>1,notifyGraphicVisibilityChanged:e=>1},t=new n({symbol:e,optionalFields:this._optionalFields,metadata:o,shaderTransformation:null},this.scheduler);return t.slicePlaneEnabled=!1,this._addDisposeResource((()=>{s.removeRenderPlugin(t),t.destroy()})),await s.addRenderPlugin(t,r),t}};function c(e,r){const s=r.levels.map((r=>{const s=r.components.map((r=>{const s=e(r.materialId);if(!u(s))throw new Error("LodRenderer only supports DefaultMaterial");const o=new t(s,r.renderGeometryBuffer.data,r.renderGeometryBuffer.elementCount,r.boundingInfo);return new i(o)}));return new a(s,r.minScreenSpaceRadius)}));return new d(s)}function u(e){return null!=e&&"materialType"in e&&"default"===e.materialType}l=e([s("esri.views.3d.layers.graphics.pipeline.rendering.LodRenderer")],l);export{l as LodRenderer,u as isDefaultMaterial};