/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{loadLibtessF32 as e}from"../../../../../../../geometry/libtess.js";import{clipMarshall as t,triangulateSyncUnsafe as r}from"../../../mesh/templates/templateUtils.js";import{MeshWriter as s}from"../mesh/MeshWriter.js";class i extends s{async loadDependencies(){await Promise.all([super.loadDependencies(),e()])}_write(e,{target:t,effectGeometry:r}){const s=r?.asOptimized()??t.readGeometryForDisplay(),i=this._clip(s);i&&(e.recordStart(this.instanceId,this.attributeLayout),this._writeGeometry(e,t,i),e.recordEnd())}_clip(e){if(!e)return null;const r=this.hasEffects;return t(e,r?256:8)}_writeGeometry(e,t,s){s=s.justXY();const i=r(s);if(!i||!i.vertices.length)return;const o=this.createTesselationParams(t);this._writeVertices(e,t,i,o)}_writeVertices(e,t,r,s){const i=t.getDisplayId(),o=e.vertexCount(),n=this.hasEffects,{vertices:c,indices:a}=r;let l=0;if(a)for(const d of a){const t=c[2*d],r=c[2*d+1];n&&e.recordBounds(t,r,0,0),this._writeVertex(e,i,t,r,s),l++}else for(let d=0;d<c.length;d+=2){const t=Math.round(c[d]),r=Math.round(c[d+1]);n&&e.recordBounds(t,r,0,0),this._writeVertex(e,i,t,r,s),l++}e.indexEnsureSize(l);for(let d=0;d<l;d++)e.indexWrite(d+o)}}export{i as AFillMeshWriter};
