@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.55 kB
JavaScript
import{isSome as s}from"../../../../../core/maybe.js";import t from"../../../../../core/PooledArray.js";import{BufferRange as e}from"./BufferRange.js";import{DrawCommand as n}from"./DrawCommand.js";class i{constructor(){this._numElements=0,this._instances=new Map,this.holes=new t({allocator:s=>s||new e,deallocator:null}),this.hasHiddenInstances=!1,this.hasHighlights=!1,this.hasOccludees=!1,this.drawCommandsDirty=!0,this.drawCommandsDefault=h(),this.drawCommandsHighlight=h(),this.drawCommandsOccludees=h(),this.drawCommandsShadowHighlightRest=h()}get numElements(){return this._numElements}get instances(){return this._instances}addInstance(s,t){this.deleteInstance(s),this._instances.set(s,t),this._numElements+=t.numElements}deleteInstance(s){const t=this._instances.get(s);t&&(this._numElements-=t.numElements,this._instances.delete(s))}updateInstance(s,t,e){const n=this._instances.get(s);n&&(this._numElements-=n.numElements,n.from=t,n.to=e,this._numElements+=n.numElements)}updateDrawState(s){s.isVisible?(s.hasHighlights&&(this.hasHighlights=!0),s.hasOccludees&&(this.hasOccludees=!0)):this.hasHiddenInstances=!0}updateDrawCommands(t){if(this.drawCommandsDefault.clear(),this.drawCommandsHighlight.clear(),this.drawCommandsOccludees.clear(),this.drawCommandsShadowHighlightRest.clear(),this.drawCommandsDirty=!1,0===this._instances.size)return;if(!this.needsMultipleCommands()){const e=this.drawCommandsDefault.pushNew(),n=this.holes.front();return s(this.vao)&&1===this.holes.length&&n.to===Math.floor(this.vao.size/t)?(e.first=0,void(e.count=n.from)):(e.first=1/0,e.count=0,this._instances.forEach((s=>{e.first=Math.min(e.first,s.from),e.count=Math.max(e.count,s.to)})),void(e.count-=e.first))}const e=Array.from(this._instances.values()).sort(((s,t)=>s.from===t.from?s.to-t.to:s.from-t.from));for(const s of e)s.isVisible&&(r(s.hasOccludees?this.drawCommandsOccludees:this.drawCommandsDefault,s),r(s.hasHighlights?this.drawCommandsHighlight:this.drawCommandsShadowHighlightRest,s))}needsMultipleCommands(){return this.hasOccludees||this.hasHighlights||this.hasHiddenInstances}}class a extends i{}function o(t){return s(t.vao)}function h(){return new t({allocator:s=>s||new n,deallocator:s=>s})}function r(s,t){const e=s.back();if(null==e){const e=s.pushNew();return e.first=t.from,void(e.count=t.numElements)}if(m(e,t)){const s=t.from-e.first+t.numElements;e.count=s}else{const e=s.pushNew();e.first=t.from,e.count=t.numElements}}function m(s,t){return s.first+s.count>=t.from}export{i as PerBufferData,a as PerVaoData,o as hasVao};