UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.07 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{i1616to32 as t}from"../../../number.js";import{AlignedVertexSpec as e}from"./AlignedVertexSpec.js";import{packDataView as s}from"./dataViewUtils.js";class i{static fromVertexSpec(t,s){const c=e.fromVertexSpec(t,s);return new i(c)}constructor(t){this._spec=t,this._packed=new Uint8Array(this._spec.stride*this._spec.packVertexCount),this._packedU32View=new Uint32Array(this._packed.buffer),this._dataView=new DataView(this._packed.buffer)}get attributeLayout(){return this._spec.attributeLayout}get stride(){return this._spec.stride}writeVertex(t,e,s,i,c,a){for(let p=0;p<this._spec.packVertexCount;p++){const t=p*this._spec.stride;this._packPosition(s,i,t),this._packId(e,t);const r=this._spec.bitset;if(a){if(r.packTessellation){const e=r.packTessellation(a,c,s,i);this._pack(e,r,t)}for(const e of this._spec.standardAttributes)if(null!=e.packTessellation){const p=e.packTessellation(a,c,s,i);this._pack(p,e,t)}else if(e.packAlternating?.packTessellation){const t=e.packAlternating.packTessellation(a,c,s,i);for(let s=0;s<this._spec.packVertexCount;s++){const i=t[s];this._pack(i,e,s*this._spec.stride)}}}}t.vertexWriteRegion(this._packedU32View)}pack(t,e){for(const s of this._spec.standardAttributes)if(s.pack&&"string"!=typeof s.pack){const i=s.pack(t,e);for(let t=0;t<this._spec.packVertexCount;t++)this._pack(i,s,t*this._spec.stride)}else if(s.packAlternating?.pack){const i=s.packAlternating.pack(t,e);for(let t=0;t<this._spec.packVertexCount;t++){const e=i[t];this._pack(e,s,t*this._spec.stride)}}}_packPosition(e,s,i){const{offset:c}=this._spec.position,a=this._spec.position.packPrecisionFactor??1,p=t(e*a,s*a);this._dataView.setUint32(i+c,p,!0)}_packId(t,e){const s=t*(this._spec.id.packPrecisionFactor??1),i=4278190080&this._dataView.getUint32(e+this._spec.id.offset,!0);this._dataView.setUint32(e+this._spec.id.offset,s|i,!0)}_pack(t,e,i){s(this._dataView,t,e,i)}}export{i as MeshWriterVertexPack};