@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.38 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
var t;!function(t){t[t.JSON=1313821514]="JSON",t[t.BIN=5130562]="BIN"}(t||(t={}));class e{constructor(i,r){if(!i)throw new Error("GLB requires a JSON gltf chunk");this._length=e.HEADER_SIZE,this._length+=e.CHUNK_HEADER_SIZE;const s=n(i);if(this._length+=h(s.byteLength,4),r&&(this._length+=e.CHUNK_HEADER_SIZE,this._length+=r.byteLength,r.byteLength%4))throw new Error("Expected BIN chunk length to be divisible by 4 at this point");this.buffer=new ArrayBuffer(this._length),this._outView=new DataView(this.buffer),this._writeHeader();const _=this._writeChunk(s,12,t.JSON,32);r&&this._writeChunk(r,_,t.BIN)}_writeHeader(){this._outView.setUint32(0,e.MAGIC,!0),this._outView.setUint32(4,e.VERSION,!0),this._outView.setUint32(8,this._length,!0)}_writeChunk(t,e,n,r=0){const s=h(t.byteLength,4);for(this._outView.setUint32(e,s,!0),this._outView.setUint32(e+=4,n,!0),i(this._outView.buffer,t,e+=4,0,t.byteLength),e+=t.byteLength;e%4;)r&&this._outView.setUint8(e,r),e++;return e}}function i(t,e,i,n,h){new Uint8Array(t,i,h).set(new Uint8Array(e,n,h),0)}function n(t){return(new TextEncoder).encode(t).buffer}function h(t,e){return e*Math.ceil(t/e)}e.HEADER_SIZE=12,e.CHUNK_HEADER_SIZE=8,e.MAGIC=1179937895,e.VERSION=2;export{e as GLB};