UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 6.09 kB
import{isSome as e}from"../../../../../core/maybe.js";import{y as t,z as f}from"../../../../../chunks/mat4.js";import{BufferViewVec4f as o,BufferViewVec4u8 as r,BufferViewVec2f as n,BufferViewVec3f as s}from"../../../../../geometry/support/buffer/BufferView.js";import{assert as i}from"../../lib/Util.js";import{VertexAttribute as c}from"../../lib/VertexAttribute.js";function l(e,t,f,o,r=1){const n=f.typedBuffer,s=f.typedBufferStride,i=e.length;if(o*=s,1===r)for(let c=0;c<i;++c)n[o]=t[e[c]],o+=s;else for(let c=0;c<i;++c){const f=t[e[c]];for(let e=0;e<r;e++)n[o]=f,o+=s}}function d(e,t,f,o){const r=f.typedBuffer,n=f.typedBufferStride,s=e.length;o*=n;for(let i=0;i<s;++i){const f=2*e[i];r[o]=t[f],r[o+1]=t[f+1],o+=n}}function u(e,t,f,o,r){const n=f.typedBuffer,s=f.typedBufferStride,i=e.length;if(o*=s,null==r||1===r)for(let c=0;c<i;++c){const f=3*e[c];n[o]=t[f],n[o+1]=t[f+1],n[o+2]=t[f+2],o+=s}else for(let c=0;c<i;++c){const f=3*e[c];for(let e=0;e<r;++e)n[o]=t[f],n[o+1]=t[f+1],n[o+2]=t[f+2],o+=s}}function a(e,t,f,o,r=1){const n=f.typedBuffer,s=f.typedBufferStride,i=e.length;if(o*=s,1===r)for(let c=0;c<i;++c){const f=4*e[c];n[o]=t[f],n[o+1]=t[f+1],n[o+2]=t[f+2],n[o+3]=t[f+3],o+=s}else for(let c=0;c<i;++c){const f=4*e[c];for(let e=0;e<r;++e)n[o]=t[f],n[o+1]=t[f+1],n[o+2]=t[f+2],n[o+3]=t[f+3],o+=s}}function p(e,t,f){const o=e.typedBuffer,r=e.typedBufferStride;t*=r;for(let n=0;n<f;++n)o[t]=0,o[t+1]=0,o[t+2]=0,o[t+3]=0,t+=r}function y(e,t,f,o){const r=f.typedBuffer,n=f.typedBufferStride,s=e.length;o*=n;for(let i=0;i<s;++i){const f=9*e[i];for(let e=0;e<9;++e)r[o+e]=t[f+e];o+=n}}function B(e,t,f,o){const r=f.typedBuffer,n=f.typedBufferStride,s=e.length;o*=n;for(let i=0;i<s;++i){const f=16*e[i];for(let e=0;e<16;++e)r[o+e]=t[f+e];o+=n}}function g(e,f,o,r,n,s=1){if(!o)return void u(e,f,r,n,s);const i=r.typedBuffer,c=r.typedBufferStride,l=e.length,d=o[0],a=o[1],p=o[2],y=o[4],B=o[5],g=o[6],b=o[8],h=o[9],O=o[10],N=o[12],S=o[13],m=o[14];n*=c;let A=0,L=0,R=0;const v=t(o)?e=>{A=f[e]+N,L=f[e+1]+S,R=f[e+2]+m}:e=>{const t=f[e],o=f[e+1],r=f[e+2];A=d*t+y*o+b*r+N,L=a*t+B*o+h*r+S,R=p*t+g*o+O*r+m};if(1===s)for(let t=0;t<l;++t)v(3*e[t]),i[n]=A,i[n+1]=L,i[n+2]=R,n+=c;else for(let t=0;t<l;++t){v(3*e[t]);for(let e=0;e<s;++e)i[n]=A,i[n+1]=L,i[n+2]=R,n+=c}}function b(e,o,r,n,s,i=1){if(!r)return void u(e,o,n,s,i);const c=r,l=n.typedBuffer,d=n.typedBufferStride,a=e.length,p=c[0],y=c[1],B=c[2],g=c[4],b=c[5],h=c[6],O=c[8],N=c[9],S=c[10],m=!f(c),A=1e-6,L=1-A;s*=d;let R=0,v=0,E=0;const F=t(c)?e=>{R=o[e],v=o[e+1],E=o[e+2]}:e=>{const t=o[e],f=o[e+1],r=o[e+2];R=p*t+g*f+O*r,v=y*t+b*f+N*r,E=B*t+h*f+S*r};if(1===i)if(m)for(let t=0;t<a;++t){F(3*e[t]);const f=R*R+v*v+E*E;if(f<L&&f>A){const e=1/Math.sqrt(f);l[s]=R*e,l[s+1]=v*e,l[s+2]=E*e}else l[s]=R,l[s+1]=v,l[s+2]=E;s+=d}else for(let t=0;t<a;++t)F(3*e[t]),l[s]=R,l[s+1]=v,l[s+2]=E,s+=d;else for(let t=0;t<a;++t){if(F(3*e[t]),m){const e=R*R+v*v+E*E;if(e<L&&e>A){const t=1/Math.sqrt(e);R*=t,v*=t,E*=t}}for(let e=0;e<i;++e)l[s]=R,l[s+1]=v,l[s+2]=E,s+=d}}function h(e,t,o,r,n,s=1){if(!o)return void a(e,t,r,n,s);const i=o,c=r.typedBuffer,l=r.typedBufferStride,d=e.length,u=i[0],p=i[1],y=i[2],B=i[4],g=i[5],b=i[6],h=i[8],O=i[9],N=i[10],S=!f(i),m=1e-6,A=1-m;if(n*=l,1===s)for(let f=0;f<d;++f){const o=4*e[f],r=t[o],s=t[o+1],i=t[o+2],d=t[o+3];let a=u*r+B*s+h*i,L=p*r+g*s+O*i,R=y*r+b*s+N*i;if(S){const e=a*a+L*L+R*R;if(e<A&&e>m){const t=1/Math.sqrt(e);a*=t,L*=t,R*=t}}c[n]=a,c[n+1]=L,c[n+2]=R,c[n+3]=d,n+=l}else for(let f=0;f<d;++f){const o=4*e[f],r=t[o],i=t[o+1],d=t[o+2],a=t[o+3];let L=u*r+B*i+h*d,R=p*r+g*i+O*d,v=y*r+b*i+N*d;if(S){const e=L*L+R*R+v*v;if(e<A&&e>m){const t=1/Math.sqrt(e);L*=t,R*=t,v*=t}}for(let e=0;e<s;++e)c[n]=L,c[n+1]=R,c[n+2]=v,c[n+3]=a,n+=l}}function O(e,t,f,o,r,n=1){const s=o.typedBuffer,i=o.typedBufferStride,c=e.length;if(r*=i,f!==t.length||4!==f)if(1!==n)if(4!==f)for(let l=0;l<c;++l){const f=3*e[l];for(let e=0;e<n;++e)s[r]=t[f],s[r+1]=t[f+1],s[r+2]=t[f+2],s[r+3]=255,r+=i}else for(let l=0;l<c;++l){const f=4*e[l];for(let e=0;e<n;++e)s[r]=t[f],s[r+1]=t[f+1],s[r+2]=t[f+2],s[r+3]=t[f+3],r+=i}else{if(4===f){for(let f=0;f<c;++f){const o=4*e[f];s[r]=t[o],s[r+1]=t[o+1],s[r+2]=t[o+2],s[r+3]=t[o+3],r+=i}return}for(let f=0;f<c;++f){const o=3*e[f];s[r]=t[o],s[r+1]=t[o+1],s[r+2]=t[o+2],s[r+3]=255,r+=i}}else{s[r]=t[0],s[r+1]=t[1],s[r+2]=t[2],s[r+3]=t[3];const e=new Uint32Array(o.typedBuffer.buffer,o.start),f=i/4,l=e[r/=4];r+=f;const d=c*n;for(let t=1;t<d;++t)e[r]=l,r+=f}}function N(e,t,f,o,r=1){const n=t.typedBuffer,s=t.typedBufferStride;if(o*=s,1===r)for(let i=0;i<f;++i)n[o]=e[0],n[o+1]=e[1],n[o+2]=e[2],n[o+3]=e[3],o+=s;else for(let i=0;i<f;++i)for(let t=0;t<r;++t)n[o]=e[0],n[o+1]=e[1],n[o+2]=e[2],n[o+3]=e[3],o+=s}function S(t,f,l,u,p,y){for(const B of f.fieldNames){const f=t.vertexAttributes.get(B),S=t.indices.get(B);if(f&&S)switch(B){case c.POSITION:{i(3===f.size);const e=p.getField(B,s);i(!!e,`No buffer view for ${B}`),e&&g(S,f.data,l,e,y);break}case c.NORMAL:{i(3===f.size);const e=p.getField(B,s);i(!!e,`No buffer view for ${B}`),e&&b(S,f.data,u,e,y);break}case c.UV0:{i(2===f.size);const e=p.getField(B,n);i(!!e,`No buffer view for ${B}`),e&&d(S,f.data,e,y);break}case c.COLOR:case c.SYMBOLCOLOR:{i(3===f.size||4===f.size);const e=p.getField(B,r);i(!!e,`No buffer view for ${B}`),e&&O(S,f.data,f.size,e,y);break}case c.TANGENT:{i(4===f.size);const e=p.getField(B,o);i(!!e,`No buffer view for ${B}`),e&&h(S,f.data,u,e,y);break}case c.PROFILERIGHT:case c.PROFILEUP:case c.PROFILEVERTEXANDNORMAL:case c.FEATUREVALUE:{i(4===f.size);const e=p.getField(B,o);i(!!e,`No buffer view for ${B}`),e&&a(S,f.data,e,y)}}else if(B===c.OBJECTANDLAYERIDCOLOR&&e(t.objectAndLayerIdColor)){const e=t.indices.get(c.POSITION);if(i(!!e,`No buffer view for ${B}`),e){const f=e.length,o=p.getField(B,r);N(t.objectAndLayerIdColor,o,f,y)}}}}export{l as writeBufferFloat,y as writeBufferMat3f,B as writeBufferMat4f,d as writeBufferVec2,u as writeBufferVec3,a as writeBufferVec4,p as writeBufferVec4Zeros,O as writeColor,S as writeDefaultAttributes,b as writeNormal,N as writeObjectAndLayerIdColor,g as writePosition,h as writeTangent};