UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 6.82 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{hasIdentityRotation as e,isOrthoNormal as t}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{BufferViewVec4u8 as f,BufferViewVec4f as o,BufferViewFloat as r,BufferViewVec2f as i,BufferViewVec2i16 as s,BufferViewVec3f as n}from"../../../../../geometry/support/buffer/BufferView.js";import{assert as c}from"../../lib/Util.js";import{VertexAttribute as l}from"../../lib/VertexAttribute.js";function d(e,t,f,o=1){const{data:r,indices:i}=e,s=t.typedBuffer,n=t.typedBufferStride,c=i.length;if(f*=n,1===o)for(let l=0;l<c;++l)s[f]=r[i[l]],f+=n;else for(let l=0;l<c;++l){const e=r[i[l]];for(let t=0;t<o;t++)s[f]=e,f+=n}}function u(e,t,f){const{data:o,indices:r}=e,i=t.typedBuffer,s=t.typedBufferStride,n=r.length;f*=s;for(let c=0;c<n;++c){const e=2*r[c];i[f]=o[e],i[f+1]=o[e+1],f+=s}}function a(e,t,f,o){const{data:r,indices:i}=e,s=t.typedBuffer,n=t.typedBufferStride,c=i.length;if(f*=n,null==o||1===o)for(let l=0;l<c;++l){const e=3*i[l];s[f]=r[e],s[f+1]=r[e+1],s[f+2]=r[e+2],f+=n}else for(let l=0;l<c;++l){const e=3*i[l];for(let t=0;t<o;++t)s[f]=r[e],s[f+1]=r[e+1],s[f+2]=r[e+2],f+=n}}function p(e,t,f,o=1){const{data:r,indices:i}=e,s=t.typedBuffer,n=t.typedBufferStride,c=i.length;if(f*=n,1===o)for(let l=0;l<c;++l){const e=4*i[l];s[f]=r[e],s[f+1]=r[e+1],s[f+2]=r[e+2],s[f+3]=r[e+3],f+=n}else for(let l=0;l<c;++l){const e=4*i[l];for(let t=0;t<o;++t)s[f]=r[e],s[f+1]=r[e+1],s[f+2]=r[e+2],s[f+3]=r[e+3],f+=n}}function B(e,t,f){const o=e.typedBuffer,r=e.typedBufferStride;t*=r;for(let i=0;i<f;++i)o[t]=0,o[t+1]=0,o[t+2]=0,o[t+3]=0,t+=r}function y(e,t,f){const{data:o,indices:r}=e,i=t.typedBuffer,s=t.typedBufferStride,n=r.length;f*=s;for(let c=0;c<n;++c){const e=9*r[c];for(let t=0;t<9;++t)i[f+t]=o[e+t];f+=s}}function g(e,t,f){const{data:o,indices:r}=e,i=t.typedBuffer,s=t.typedBufferStride,n=r.length;f*=s;for(let c=0;c<n;++c){const e=16*r[c];for(let t=0;t<16;++t)i[f+t]=o[e+t];f+=s}}function b(t,f,o,r,i=1){if(!f)return void a(t,o,r,i);const{data:s,indices:n}=t,c=o.typedBuffer,l=o.typedBufferStride,d=n.length,u=f[0],p=f[1],B=f[2],y=f[4],g=f[5],b=f[6],O=f[8],h=f[9],S=f[10],N=f[12],R=f[13],E=f[14];r*=l;let F=0,z=0,A=0;const L=e(f)?e=>{F=s[e]+N,z=s[e+1]+R,A=s[e+2]+E}:e=>{const t=s[e],f=s[e+1],o=s[e+2];F=u*t+y*f+O*o+N,z=p*t+g*f+h*o+R,A=B*t+b*f+S*o+E};if(1===i)for(let e=0;e<d;++e)L(3*n[e]),c[r]=F,c[r+1]=z,c[r+2]=A,r+=l;else for(let e=0;e<d;++e){L(3*n[e]);for(let e=0;e<i;++e)c[r]=F,c[r+1]=z,c[r+2]=A,r+=l}}function O(f,o,r,i,s=1){if(!o)return void a(f,r,i,s);const{data:n,indices:c}=f,l=o,d=r.typedBuffer,u=r.typedBufferStride,p=c.length,B=l[0],y=l[1],g=l[2],b=l[4],O=l[5],h=l[6],S=l[8],N=l[9],R=l[10],E=!t(l),F=1e-6,z=1-F;i*=u;let A=0,L=0,m=0;const T=e(l)?e=>{A=n[e],L=n[e+1],m=n[e+2]}:e=>{const t=n[e],f=n[e+1],o=n[e+2];A=B*t+b*f+S*o,L=y*t+O*f+N*o,m=g*t+h*f+R*o};if(1===s)if(E)for(let e=0;e<p;++e){T(3*c[e]);const t=A*A+L*L+m*m;if(t<z&&t>F){const e=1/Math.sqrt(t);d[i]=A*e,d[i+1]=L*e,d[i+2]=m*e}else d[i]=A,d[i+1]=L,d[i+2]=m;i+=u}else for(let e=0;e<p;++e)T(3*c[e]),d[i]=A,d[i+1]=L,d[i+2]=m,i+=u;else for(let e=0;e<p;++e){if(T(3*c[e]),E){const e=A*A+L*L+m*m;if(e<z&&e>F){const t=1/Math.sqrt(e);A*=t,L*=t,m*=t}}for(let e=0;e<s;++e)d[i]=A,d[i+1]=L,d[i+2]=m,i+=u}}function h(e,f,o,r,i=1){if(!f)return void p(e,o,r,i);const{data:s,indices:n}=e,c=f,l=o.typedBuffer,d=o.typedBufferStride,u=n.length,a=c[0],B=c[1],y=c[2],g=c[4],b=c[5],O=c[6],h=c[8],S=c[9],N=c[10],R=!t(c),E=1e-6,F=1-E;if(r*=d,1===i)for(let t=0;t<u;++t){const e=4*n[t],f=s[e],o=s[e+1],i=s[e+2],c=s[e+3];let u=a*f+g*o+h*i,p=B*f+b*o+S*i,z=y*f+O*o+N*i;if(R){const e=u*u+p*p+z*z;if(e<F&&e>E){const t=1/Math.sqrt(e);u*=t,p*=t,z*=t}}l[r]=u,l[r+1]=p,l[r+2]=z,l[r+3]=c,r+=d}else for(let t=0;t<u;++t){const e=4*n[t],f=s[e],o=s[e+1],c=s[e+2],u=s[e+3];let p=a*f+g*o+h*c,z=B*f+b*o+S*c,A=y*f+O*o+N*c;if(R){const e=p*p+z*z+A*A;if(e<F&&e>E){const t=1/Math.sqrt(e);p*=t,z*=t,A*=t}}for(let t=0;t<i;++t)l[r]=p,l[r+1]=z,l[r+2]=A,l[r+3]=u,r+=d}}function S(e,t,f,o,r=1){const{data:i,indices:s}=e,n=f.typedBuffer,c=f.typedBufferStride,l=s.length;if(o*=c,t!==i.length||4!==t)if(1!==r)if(4!==t)for(let d=0;d<l;++d){const e=3*s[d];for(let t=0;t<r;++t)n[o]=i[e],n[o+1]=i[e+1],n[o+2]=i[e+2],n[o+3]=255,o+=c}else for(let d=0;d<l;++d){const e=4*s[d];for(let t=0;t<r;++t)n[o]=i[e],n[o+1]=i[e+1],n[o+2]=i[e+2],n[o+3]=i[e+3],o+=c}else{if(4===t){for(let e=0;e<l;++e){const t=4*s[e];n[o]=i[t],n[o+1]=i[t+1],n[o+2]=i[t+2],n[o+3]=i[t+3],o+=c}return}for(let e=0;e<l;++e){const t=3*s[e];n[o]=i[t],n[o+1]=i[t+1],n[o+2]=i[t+2],n[o+3]=255,o+=c}}else{n[o]=i[0],n[o+1]=i[1],n[o+2]=i[2],n[o+3]=i[3];const e=new Uint32Array(f.typedBuffer.buffer,f.start),t=c/4,s=e[o/=4];o+=t;const d=l*r;for(let f=1;f<d;++f)e[o]=s,o+=t}}function N(e,t,f){const{data:o,indices:r}=e,i=t.typedBuffer,s=t.typedBufferStride,n=r.length,c=o[0];f*=s;for(let l=0;l<n;++l)i[f]=c,f+=s}function R(e,t,f,o,r=1){const i=t.typedBuffer,s=t.typedBufferStride;if(o*=s,1===r)for(let n=0;n<f;++n)i[o]=e[0],i[o+1]=e[1],i[o+2]=e[2],i[o+3]=e[3],o+=s;else for(let n=0;n<f;++n)for(let t=0;t<r;++t)i[o]=e[0],i[o+1]=e[1],i[o+2]=e[2],i[o+3]=e[3],o+=s}function E(e,t,o,r,i,s,n){for(const c of o.fields.keys()){const o=e.get(c),d=o?.indices;if(o&&d)F(c,o,r,i,s,n);else if(c===l.OBJECTANDLAYERIDCOLOR&&null!=t){const o=e.get(l.POSITION)?.indices;if(o){const e=o.length;R(t,s.getField(c,f),e,n)}}}}function F(e,t,d,a,B,y){switch(e){case l.POSITION:{c(3===t.size);const f=B.getField(e,n);c(!!f,`No buffer view for ${e}`),f&&b(t,d,f,y);break}case l.NORMAL:{c(3===t.size);const f=B.getField(e,n);c(!!f,`No buffer view for ${e}`),f&&O(t,a,f,y);break}case l.NORMALCOMPRESSED:{c(2===t.size);const f=B.getField(e,s);c(!!f,`No buffer view for ${e}`),f&&u(t,f,y);break}case l.UV0:{c(2===t.size);const f=B.getField(e,i);c(!!f,`No buffer view for ${e}`),f&&u(t,f,y);break}case l.COLOR:case l.SYMBOLCOLOR:{const o=B.getField(e,f);c(!!o,`No buffer view for ${e}`),c(3===t.size||4===t.size),!o||3!==t.size&&4!==t.size||S(t,t.size,o,y);break}case l.COLORFEATUREATTRIBUTE:{const f=B.getField(e,r);c(!!f,`No buffer view for ${e}`),c(1===t.size),f&&1===t.size&&N(t,f,y);break}case l.TANGENT:{c(4===t.size);const f=B.getField(e,o);c(!!f,`No buffer view for ${e}`),f&&h(t,d,f,y);break}case l.PROFILERIGHT:case l.PROFILEUP:case l.PROFILEVERTEXANDNORMAL:case l.FEATUREVALUE:{c(4===t.size);const f=B.getField(e,o);c(!!f,`No buffer view for ${e}`),f&&p(t,f,y)}}}export{d as writeBufferFloat,y as writeBufferMat3f,g as writeBufferMat4f,u as writeBufferVec2,a as writeBufferVec3,p as writeBufferVec4,B as writeBufferVec4Zeros,S as writeColor,N as writeColorFeatureAttribute,F as writeDefaultAttribute,E as writeDefaultAttributes,O as writeNormal,R as writeObjectAndLayerIdColor,b as writePosition,h as writeTangent};