UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.18 kB
import{getStrides as t}from"../Utils.js";import{VertexBuffers as e}from"./VertexBuffer.js";import r from"../util/Writer.js";class s{get vertexCount(){const t=this.stride/4,e=this.data.length/t;return e!==(0|e)&&console.debug("Corrupted stride"),e}constructor(t,e){this.data=t,this.stride=e}transfer(t,e){const r=this.data.buffer();t.vertexCount=this.vertexCount,t.data=r,t.stride=this.stride,e.push(r)}}class o{constructor(e,o,n){this.geometryType=e,this.indexVector=new r(Uint32Array,6*o),this.namedVectors={};const i=t(e,n);for(const t in i){const e=i[t];let n;switch(e%4){case 0:case 2:n=new r(Uint32Array,e*o);break;case 1:case 3:n=new r(Uint8Array,e*o)}this.namedVectors[t]=new s(n,e)}}get(t){return this.namedVectors[t].data}getVector(t){return this.namedVectors[t]}transfer(t,e){const r=this.indexVector.buffer(),s={};e.push(r);for(const o in this.namedVectors){const t=this.namedVectors[o];s[o]={},t.transfer(s[o],e)}t.geometryType=this.geometryType,t.indexBuffer=r,t.namedBuffers=s,this.destroy()}intoBuffers(){const t=e.fromVertexVectors(this);return this.destroy(),t}destroy(){this.indexVector=null,this.namedVectors=null}}export{s as VertexVector,o as VertexVectors};