/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{DefaultMaterial as a}from"../../webgl-engine/materials/DefaultMaterial.js";class t{constructor(){this._fastTransformOriginalMaterials=new Map,this._fastTransformClonedMaterials=new Map,this._graphicReferenceCount=0}enable(t,e,r){t.enableFastTransformUpdates(t=>{if(this._graphicReferenceCount<=1){if(this._fastTransformOriginalMaterials.has(t))return t;const a=e.byMaterial(t);return this._fastTransformOriginalMaterials.set(t,a),e.delete(t),t}const s=new a(t.parameters,r);return this._fastTransformClonedMaterials.set(s,t),s},r.localOriginFactory)}disable(a,t){const e=new Set,r=new Set;a.disableFastTransformUpdates(a=>{if(!this._fastTransformClonedMaterials.has(a)){const s=a,i=this._fastTransformOriginalMaterials.get(s);return t.has(i.uid)?(e.add(s),t.byUid(i.uid).material):(r.add(s),i.material)}const s=a,i=this._fastTransformClonedMaterials.get(s);return this._fastTransformClonedMaterials.delete(s),i});for(const s of e)this._fastTransformOriginalMaterials.delete(s);for(const s of r){const a=this._fastTransformOriginalMaterials.get(s);this._fastTransformOriginalMaterials.delete(s),t.set(a.uid,a)}}onAddGraphic(){this._graphicReferenceCount++}onRemoveGraphic(a,t){this._graphicReferenceCount--,this.disable(a,t)}forEachMaterialInfo(a){this._fastTransformOriginalMaterials.forEach(a)}forEachClonedMaterial(a){this._fastTransformClonedMaterials.forEach(a)}destroy(){this._fastTransformClonedMaterials.clear(),this._fastTransformOriginalMaterials.clear()}}class e{constructor(){this._byUid=new Map,this._byMaterial=new Map}get materials(){return Array.from(this._byUid.values(),a=>a.material)}byUid(a){return this._byUid.get(a)}byMaterial(a){return this._byMaterial.get(a)}set(a,t){this._byUid.set(a,t),this._byMaterial.set(t.material,t)}delete(a){const t=this._byMaterial.get(a)?.uid;t&&(this._byUid.delete(t),this._byMaterial.delete(a))}has(a){return this._byUid.has(a)}forEachMaterialInfo(a){this._byUid.forEach(a)}clear(){this._byUid.clear(),this._byMaterial.clear()}}export{e as MaterialInfoCache,t as MeshFastUpdateProcessor};
