@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.24 kB
JavaScript
import{WorldClusters as t}from"../lighting/world-clusters.js";const s=[];class e{constructor(t){this._empty=null,this._allocated=[],this._clusters=new Map,this.device=t}destroy(){this._empty&&(this._empty.destroy(),this._empty=null),this._allocated.forEach((t=>{t.destroy()})),this._allocated.length=0}get count(){return this._allocated.length}get empty(){if(!this._empty){const s=new t(this.device);s.name="ClusterEmpty",s.update([],!1,null),this._empty=s}return this._empty}assign(e){const l=this.empty;s.push(...this._allocated),this._allocated.length=0,this._clusters.clear();const h=e.length;for(let r=0;r<h;r++){const h=e[r].renderActions;if(h){const e=h.length;for(let r=0;r<e;r++){const e=h[r];e.lightClusters=null;const n=e.layer;if(n.hasClusteredLights&&n.meshInstances.length){const l=n.getLightIdHash(),h=this._clusters.get(l);let r=null==h?void 0:h.lightClusters;var i;if(!r)r=null!=(i=s.pop())?i:new t(this.device),this._allocated.push(r),this._clusters.set(l,e);e.lightClusters=r}e.lightClusters||(e.lightClusters=l)}}}s.forEach((t=>t.destroy())),s.length=0}update(t,s,e){this.assign(t),this._clusters.forEach((t=>{const l=t.layer;t.lightClusters.update(l.clusteredLightsSet,s,e)}))}}export{e as WorldClustersAllocator};