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