/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../util/Writer.js";const e=6,i=4;class r{constructor(r,s,n=0){const c=e*n*Uint32Array.BYTES_PER_ELEMENT,h=i*n*s.stride,u=s.stride/4,_=s.attributes.find(t=>"pos"===t.name||"position"===t.name);if(!_)throw new Error("InternalError: Unable to find position attribute");this.layout={...s,position:_},this._indices=new t(Uint32Array,c),this._vertices=new t(Uint32Array,h),this._metrics=new t(Uint32Array,0),this._metricCountOffset=this._metrics.push(0),this._strideInt=u,this._instanceId=r}serialize(t){const e=this._indices.buffer(),i=this._vertices.buffer(),r=this._metrics.length?this._metrics.buffer():null;return t.push(e,i),{instanceId:this._instanceId,layout:this.layout,indices:e,vertices:i,metrics:r}}get strideInt(){return this._strideInt}get vertexCount(){return this._vertices.length/this._strideInt}get indexCount(){return this._indices.length}get indexWriter(){return this._indices}get vertexWriter(){return this._vertices}get metricWriter(){return this._metrics}vertexEnsureSize(t){this._vertices.ensureSize(t)}indexEnsureSize(t){this._indices.ensureSize(t)}writeIndex(t){this._indices.push(t)}writeVertex(t){this._vertices.push(t)}writeVertexRegion(t){this._vertices.writeRegion(t)}writeVertexF32(t){this._vertices.writeF32(t)}writeMetric(t){this._metrics.incr(this._metricCountOffset),t.serialize(this._metrics)}}export{r as VertexDataWriter};
