UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.36 kB
import{DISPLAY_RECORD_INT_PER_ELEMENT as e}from"../definitions.js";import{getMeshSizeHint as t}from"./heuristics.js";import s from"../util/Writer.js";class r{constructor(e,r,i){this._start={index:0,vertex:0};const h=t(e,r,i),c=r/4;this.geometryType=e,this._records=new s(Int32Array,h.recordBytes),this._indices=new s(Uint32Array,h.indexBytes),this._vertices=new s(Uint32Array,h.vertexBytes),this._metrics=new s(Float32Array,0),this._strideInt=c}serialize(e){const t=this._records.buffer(),s=this._indices.buffer(),r=this._vertices.buffer(),i=this._metrics.length?this._metrics.buffer():null,h=4*this._strideInt;return e.push(t,s,r),{stride:h,records:t,indices:s,vertices:r,metrics:i}}get strideInt(){return this._strideInt}get recordCount(){return this._records.length/e}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(e){this._vertices.ensureSize(e)}indexEnsureSize(e){this._indices.ensureSize(e)}recordStart(){this._start.index=this._indices.length,this._start.vertex=this._vertices.length}recordEnd(e,t,s,r,i,h,c,n){this._records.push(e),this._records.push(t??0),this._records.push(s),this._records.push(r),this._records.push(i),this._records.push(h),this._records.push(c),this._records.writeF32(n)}writeIndex(e){this._indices.push(e)}writeVertex(e){this._vertices.push(e)}writeVertexF32(e){this._vertices.writeF32(e)}copyLastFrom(t,s,r){const i=t._records.length-e,h=t._records.getValue(i),c=t._records.getValue(i+1),n=t._records.getValue(i+2),_=t._records.getValue(i+4),d=t._records.getValue(i+6),o=t._records.getValue(i+7),u=this._vertices.length,l=(t._start.vertex-this._vertices.length)/this._strideInt,g=this._indices.length,p=this.vertexCount;for(let e=t._start.index;e!==t._indices.length;e++){const s=t._indices.getValue(e);this._indices.push(s-l)}for(let e=t._start.vertex;e!==t._vertices.length;e++){const s=t._vertices.getValue(e);this._vertices.push(s)}for(let e=u;e<=this._vertices.length;e+=this._strideInt)this._vertices.i1616Add(e,s,r);this._records.push(h),this._records.push(c),this._records.push(n),this._records.push(g),this._records.push(_),this._records.push(p),this._records.push(d),this._records.push(o)}}export{r as VertexDataWriter};