@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.87 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import"../../../../../../../core/has.js";import{vertexLayoutHash as t}from"./utils.js";import{DataType as s}from"../../../../../../webgl/enums.js";function e(t){switch(t){case s.BYTE:case s.UNSIGNED_BYTE:return 1;case s.SHORT:case s.UNSIGNED_SHORT:case s.HALF_FLOAT:return 2;case s.FLOAT:case s.INT:case s.UNSIGNED_INT:return 4}}function o(t){const s=[],o=[],n=[];for(const i of t){const t=e(i.type)*i.count;switch(t%2||t%4||4){case 4:s.push(i);continue;case 2:o.push(i);continue;case 1:n.push(i);continue;default:throw new Error("Found unexpected dataType byte count")}}return s.push(...o),s.push(...n),s}class n{static fromVertexSpec(t,s){const{attributes:i,optionalAttributes:a}=t;let r,c,u;const p=[];for(const e in i){const t=i[e];"position"===t.pack?r={...t,name:e,offset:0}:"id"===t.pack?c={...t,name:e,offset:4}:"bitset"===e?u={...t,name:e,offset:7}:p.push({...t,name:e})}for(const e in a)if(!0===s[e]){const t=a[e];p.push({...t,name:e})}const h=o(p),f=[];let m=8,b=1;for(const o of h)f.push({...o,offset:m}),m+=e(o.type)*o.count,o.packAlternating&&(b=Math.max(o.packAlternating.count,b));const d=Uint32Array.BYTES_PER_ELEMENT,_=m%d;return new n(r,c,u,f,m+(_?d-_:0),b)}constructor(t,s,e,o,n,i){this.position=t,this.id=s,this.bitset=e,this.standardAttributes=o,this.stride=n,this.packVertexCount=i,o.push(e),this._attributes=[t,s,e,...o]}get attributeLayout(){if(!this._attributeLayout){const s=t(this._attributes),e=this._attributes.map((t=>({name:t.name,count:t.count,offset:t.offset,type:t.type,packPrecisionFactor:t.packPrecisionFactor,normalized:t.normalized??!1})));this._attributeLayout={attributes:e,hash:s,stride:this.stride}}return this._attributeLayout}}export{n as AlignedVertexSpec,o as sortByAlignment};