use-rhino-loader
Version:
React hook for loading Rhino .3dm files with three.js and Rhino3dmLoader
8 lines (7 loc) • 45.9 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const at=require("react"),O=require("three");/*!
fflate - fast JavaScript compression/decompression
<https://101arrowz.github.io/fflate>
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
version 0.8.2
*/var me=Uint8Array,Le=Uint16Array,Yt=Int32Array,ct=new me([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),lt=new me([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Xt=new me([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ut=function(v,o){for(var l=new Le(31),u=0;u<31;++u)l[u]=o+=1<<v[u-1];for(var m=new Yt(l[30]),u=1;u<30;++u)for(var a=l[u];a<l[u+1];++a)m[a]=a-l[u]<<5|u;return{b:l,r:m}},pt=ut(ct,2),ht=pt.b,$t=pt.r;ht[28]=258,$t[258]=28;var Kt=ut(lt,0),qt=Kt.b,Qe=new Le(32768);for(var q=0;q<32768;++q){var Me=(q&43690)>>1|(q&21845)<<1;Me=(Me&52428)>>2|(Me&13107)<<2,Me=(Me&61680)>>4|(Me&3855)<<4,Qe[q]=((Me&65280)>>8|(Me&255)<<8)>>1}var He=function(v,o,l){for(var u=v.length,m=0,a=new Le(o);m<u;++m)v[m]&&++a[v[m]-1];var S=new Le(o);for(m=1;m<o;++m)S[m]=S[m-1]+a[m-1]<<1;var T;if(l){T=new Le(1<<o);var R=15-o;for(m=0;m<u;++m)if(v[m])for(var z=m<<4|v[m],d=o-v[m],b=S[v[m]-1]++<<d,y=b|(1<<d)-1;b<=y;++b)T[Qe[b]>>R]=z}else for(T=new Le(u),m=0;m<u;++m)v[m]&&(T[m]=Qe[S[v[m]-1]++]>>15-v[m]);return T},Ze=new me(288);for(var q=0;q<144;++q)Ze[q]=8;for(var q=144;q<256;++q)Ze[q]=9;for(var q=256;q<280;++q)Ze[q]=7;for(var q=280;q<288;++q)Ze[q]=8;var gt=new me(32);for(var q=0;q<32;++q)gt[q]=5;var Jt=He(Ze,9,1),Vt=He(gt,5,1),qe=function(v){for(var o=v[0],l=1;l<v.length;++l)v[l]>o&&(o=v[l]);return o},we=function(v,o,l){var u=o/8|0;return(v[u]|v[u+1]<<8)>>(o&7)&l},Je=function(v,o){var l=o/8|0;return(v[l]|v[l+1]<<8|v[l+2]<<16)>>(o&7)},Qt=function(v){return(v+7)/8|0},en=function(v,o,l){return(l==null||l>v.length)&&(l=v.length),new me(v.subarray(o,l))},tn=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],be=function(v,o,l){var u=new Error(o||tn[v]);if(u.code=v,Error.captureStackTrace&&Error.captureStackTrace(u,be),!l)throw u;return u},nn=function(v,o,l,u){var m=v.length,a=0;if(!m||o.f&&!o.l)return l||new me(0);var S=!l,T=S||o.i!=2,R=o.i;S&&(l=new me(m*3));var z=function(Ne){var We=l.length;if(Ne>We){var Ue=new me(Math.max(We*2,Ne));Ue.set(l),l=Ue}},d=o.f||0,b=o.p||0,y=o.b||0,i=o.l,D=o.d,A=o.m,F=o.n,L=m*8;do{if(!i){d=we(v,b,1);var H=we(v,b+1,3);if(b+=3,H)if(H==1)i=Jt,D=Vt,A=9,F=5;else if(H==2){var ae=we(v,b,31)+257,he=we(v,b+10,15)+4,ce=ae+we(v,b+5,31)+1;b+=14;for(var V=new me(ce),Se=new me(19),Q=0;Q<he;++Q)Se[Xt[Q]]=we(v,b+Q*3,7);b+=he*3;for(var oe=qe(Se),Re=(1<<oe)-1,Ce=He(Se,oe,1),Q=0;Q<ce;){var U=Ce[we(v,b,Re)];b+=U&15;var C=U>>4;if(C<16)V[Q++]=C;else{var B=0,j=0;for(C==16?(j=3+we(v,b,3),b+=2,B=V[Q-1]):C==17?(j=3+we(v,b,7),b+=3):C==18&&(j=11+we(v,b,127),b+=7);j--;)V[Q++]=B}}var ve=V.subarray(0,ae),se=V.subarray(ae);A=qe(ve),F=qe(se),i=He(ve,A,1),D=He(se,F,1)}else be(1);else{var C=Qt(b)+4,X=v[C-4]|v[C-3]<<8,ne=C+X;if(ne>m){R&&be(0);break}T&&z(y+X),l.set(v.subarray(C,ne),y),o.b=y+=X,o.p=b=ne*8,o.f=d;continue}if(b>L){R&&be(0);break}}T&&z(y+131072);for(var ie=(1<<A)-1,Oe=(1<<F)-1,le=b;;le=b){var B=i[Je(v,b)&ie],ye=B>>4;if(b+=B&15,b>L){R&&be(0);break}if(B||be(2),ye<256)l[y++]=ye;else if(ye==256){le=b,i=null;break}else{var Pe=ye-254;if(ye>264){var Q=ye-257,ke=ct[Q];Pe=we(v,b,(1<<ke)-1)+ht[Q],b+=ke}var G=D[Je(v,b)&Oe],Te=G>>4;G||be(3),b+=G&15;var se=qt[Te];if(Te>3){var ke=lt[Te];se+=Je(v,b)&(1<<ke)-1,b+=ke}if(b>L){R&&be(0);break}T&&z(y+131072);var _e=y+Pe;if(y<se){var ze=a-se,Xe=Math.min(se,_e);for(ze+y<0&&be(3);y<Xe;++y)l[y]=u[ze+y]}for(;y<_e;++y)l[y]=l[y-se]}}o.l=i,o.p=le,o.b=y,o.f=d,i&&(d=1,o.m=A,o.d=D,o.n=F)}while(!d);return y!=l.length&&S?en(l,0,y):l.subarray(0,y)},rn=new me(0),on=function(v,o){return((v[0]&15)!=8||v[0]>>4>7||(v[0]<<8|v[1])%31)&&be(6,"invalid zlib data"),(v[1]>>5&1)==1&&be(6,"invalid zlib data: "+(v[1]&32?"need":"unexpected")+" dictionary"),(v[1]>>3&4)+2};function Ye(v,o){return nn(v.subarray(on(v),-4),{i:2},o,o)}var sn=typeof TextDecoder<"u"&&new TextDecoder,an=0;try{sn.decode(rn,{stream:!0}),an=1}catch{}class cn extends O.DataTextureLoader{constructor(o){super(o),this.type=O.HalfFloatType}parse(o){const V=Math.pow(2.7182818,2.2);function Se(e,t){let n=0;for(let c=0;c<65536;++c)(c==0||e[c>>3]&1<<(c&7))&&(t[n++]=c);const r=n-1;for(;n<65536;)t[n++]=0;return r}function Q(e){for(let t=0;t<16384;t++)e[t]={},e[t].len=0,e[t].lit=0,e[t].p=null}const oe={l:0,c:0,lc:0};function Re(e,t,n,r,c){for(;n<e;)t=t<<8|rt(r,c),n+=8;n-=e,oe.l=t>>n&(1<<e)-1,oe.c=t,oe.lc=n}const Ce=new Array(59);function U(e){for(let n=0;n<=58;++n)Ce[n]=0;for(let n=0;n<65537;++n)Ce[e[n]]+=1;let t=0;for(let n=58;n>0;--n){const r=t+Ce[n]>>1;Ce[n]=t,t=r}for(let n=0;n<65537;++n){const r=e[n];r>0&&(e[n]=r|Ce[r]++<<6)}}function B(e,t,n,r,c,s){const g=t;let w=0,f=0;for(;r<=c;r++){if(g.value-t.value>n)return!1;Re(6,w,f,e,g);const h=oe.l;if(w=oe.c,f=oe.lc,s[r]=h,h==63){if(g.value-t.value>n)throw new Error("Something wrong with hufUnpackEncTable");Re(8,w,f,e,g);let p=oe.l+6;if(w=oe.c,f=oe.lc,r+p>c+1)throw new Error("Something wrong with hufUnpackEncTable");for(;p--;)s[r++]=0;r--}else if(h>=59){let p=h-59+2;if(r+p>c+1)throw new Error("Something wrong with hufUnpackEncTable");for(;p--;)s[r++]=0;r--}}U(s)}function j(e){return e&63}function ve(e){return e>>6}function se(e,t,n,r){for(;t<=n;t++){const c=ve(e[t]),s=j(e[t]);if(c>>s)throw new Error("Invalid table entry");if(s>14){const g=r[c>>s-14];if(g.len)throw new Error("Invalid table entry");if(g.lit++,g.p){const w=g.p;g.p=new Array(g.lit);for(let f=0;f<g.lit-1;++f)g.p[f]=w[f]}else g.p=new Array(1);g.p[g.lit-1]=t}else if(s){let g=0;for(let w=1<<14-s;w>0;w--){const f=r[(c<<14-s)+g];if(f.len||f.p)throw new Error("Invalid table entry");f.len=s,f.lit=t,g++}}}return!0}const ie={c:0,lc:0};function Oe(e,t,n,r){e=e<<8|rt(n,r),t+=8,ie.c=e,ie.lc=t}const le={c:0,lc:0};function ye(e,t,n,r,c,s,g,w,f){if(e==t){r<8&&(Oe(n,r,c,s),n=ie.c,r=ie.lc),r-=8;let h=n>>r;if(h=new Uint8Array([h])[0],w.value+h>f)return!1;const p=g[w.value-1];for(;h-- >0;)g[w.value++]=p}else if(w.value<f)g[w.value++]=e;else return!1;le.c=n,le.lc=r}function Pe(e){return e&65535}function ke(e){const t=Pe(e);return t>32767?t-65536:t}const G={a:0,b:0};function Te(e,t){const n=ke(e),c=ke(t),s=n+(c&1)+(c>>1),g=s,w=s-c;G.a=g,G.b=w}function _e(e,t){const n=Pe(e),r=Pe(t),c=n-(r>>1)&65535,s=r+c-32768&65535;G.a=s,G.b=c}function ze(e,t,n,r,c,s,g){const w=g<16384,f=n>c?c:n;let h=1,p,E;for(;h<=f;)h<<=1;for(h>>=1,p=h,h>>=1;h>=1;){E=0;const I=E+s*(c-p),_=s*h,P=s*p,x=r*h,M=r*p;let N,Y,J,pe;for(;E<=I;E+=P){let K=E;const Z=E+r*(n-p);for(;K<=Z;K+=M){const ee=K+x,de=K+_,te=de+x;w?(Te(e[K+t],e[de+t]),N=G.a,J=G.b,Te(e[ee+t],e[te+t]),Y=G.a,pe=G.b,Te(N,Y),e[K+t]=G.a,e[ee+t]=G.b,Te(J,pe),e[de+t]=G.a,e[te+t]=G.b):(_e(e[K+t],e[de+t]),N=G.a,J=G.b,_e(e[ee+t],e[te+t]),Y=G.a,pe=G.b,_e(N,Y),e[K+t]=G.a,e[ee+t]=G.b,_e(J,pe),e[de+t]=G.a,e[te+t]=G.b)}if(n&h){const ee=K+_;w?Te(e[K+t],e[ee+t]):_e(e[K+t],e[ee+t]),N=G.a,e[ee+t]=G.b,e[K+t]=N}}if(c&h){let K=E;const Z=E+r*(n-p);for(;K<=Z;K+=M){const ee=K+x;w?Te(e[K+t],e[ee+t]):_e(e[K+t],e[ee+t]),N=G.a,e[ee+t]=G.b,e[K+t]=N}}p=h,h>>=1}return E}function Xe(e,t,n,r,c,s,g,w,f){let h=0,p=0;const E=g,I=Math.trunc(r.value+(c+7)/8);for(;r.value<I;)for(Oe(h,p,n,r),h=ie.c,p=ie.lc;p>=14;){const P=h>>p-14&16383,x=t[P];if(x.len)p-=x.len,ye(x.lit,s,h,p,n,r,w,f,E),h=le.c,p=le.lc;else{if(!x.p)throw new Error("hufDecode issues");let M;for(M=0;M<x.lit;M++){const N=j(e[x.p[M]]);for(;p<N&&r.value<I;)Oe(h,p,n,r),h=ie.c,p=ie.lc;if(p>=N&&ve(e[x.p[M]])==(h>>p-N&(1<<N)-1)){p-=N,ye(x.p[M],s,h,p,n,r,w,f,E),h=le.c,p=le.lc;break}}if(M==x.lit)throw new Error("hufDecode issues")}}const _=8-c&7;for(h>>=_,p-=_;p>0;){const P=t[h<<14-p&16383];if(P.len)p-=P.len,ye(P.lit,s,h,p,n,r,w,f,E),h=le.c,p=le.lc;else throw new Error("hufDecode issues")}return!0}function Ne(e,t,n,r,c,s){const g={value:0},w=n.value,f=fe(t,n),h=fe(t,n);n.value+=4;const p=fe(t,n);if(n.value+=4,f<0||f>=65537||h<0||h>=65537)throw new Error("Something wrong with HUF_ENCSIZE");const E=new Array(65537),I=new Array(16384);Q(I);const _=r-(n.value-w);if(B(e,n,_,f,h,E),p>8*(r-(n.value-w)))throw new Error("Something wrong with hufUncompress");se(E,f,h,I),Xe(E,I,e,n,p,h,s,c,g)}function We(e,t,n){for(let r=0;r<n;++r)t[r]=e[t[r]]}function Ue(e){for(let t=1;t<e.length;t++){const n=e[t-1]+e[t]-128;e[t]=n}}function et(e,t){let n=0,r=Math.floor((e.length+1)/2),c=0;const s=e.length-1;for(;!(c>s||(t[c++]=e[n++],c>s));)t[c++]=e[r++]}function tt(e){let t=e.byteLength;const n=new Array;let r=0;const c=new DataView(e);for(;t>0;){const s=c.getInt8(r++);if(s<0){const g=-s;t-=g+1;for(let w=0;w<g;w++)n.push(c.getUint8(r++))}else{const g=s;t-=2;const w=c.getUint8(r++);for(let f=0;f<g+1;f++)n.push(w)}}return n}function ft(e,t,n,r,c,s){let g=new DataView(s.buffer);const w=n[e.idx[0]].width,f=n[e.idx[0]].height,h=3,p=Math.floor(w/8),E=Math.ceil(w/8),I=Math.ceil(f/8),_=w-(E-1)*8,P=f-(I-1)*8,x={value:0},M=new Array(h),N=new Array(h),Y=new Array(h),J=new Array(h),pe=new Array(h);for(let Z=0;Z<h;++Z)pe[Z]=t[e.idx[Z]],M[Z]=Z<1?0:M[Z-1]+E*I,N[Z]=new Float32Array(64),Y[Z]=new Uint16Array(64),J[Z]=new Uint16Array(E*64);for(let Z=0;Z<I;++Z){let ee=8;Z==I-1&&(ee=P);let de=8;for(let W=0;W<E;++W){W==E-1&&(de=_);for(let $=0;$<h;++$)Y[$].fill(0),Y[$][0]=c[M[$]++],dt(x,r,Y[$]),mt(Y[$],N[$]),yt(N[$]);wt(N);for(let $=0;$<h;++$)bt(N[$],J[$],W*64)}let te=0;for(let W=0;W<h;++W){const $=n[e.idx[W]].type;for(let xe=8*Z;xe<8*Z+ee;++xe){te=pe[W][xe];for(let Fe=0;Fe<p;++Fe){const Ee=Fe*64+(xe&7)*8;g.setUint16(te+0*2*$,J[W][Ee+0],!0),g.setUint16(te+1*2*$,J[W][Ee+1],!0),g.setUint16(te+2*2*$,J[W][Ee+2],!0),g.setUint16(te+3*2*$,J[W][Ee+3],!0),g.setUint16(te+4*2*$,J[W][Ee+4],!0),g.setUint16(te+5*2*$,J[W][Ee+5],!0),g.setUint16(te+6*2*$,J[W][Ee+6],!0),g.setUint16(te+7*2*$,J[W][Ee+7],!0),te+=8*2*$}}if(p!=E)for(let xe=8*Z;xe<8*Z+ee;++xe){const Fe=pe[W][xe]+8*p*2*$,Ee=p*64+(xe&7)*8;for(let Ge=0;Ge<de;++Ge)g.setUint16(Fe+Ge*2*$,J[W][Ee+Ge],!0)}}}const K=new Uint16Array(w);g=new DataView(s.buffer);for(let Z=0;Z<h;++Z){n[e.idx[Z]].decoded=!0;const ee=n[e.idx[Z]].type;if(n[Z].type==2)for(let de=0;de<f;++de){const te=pe[Z][de];for(let W=0;W<w;++W)K[W]=g.getUint16(te+W*2*ee,!0);for(let W=0;W<w;++W)g.setFloat32(te+W*2*ee,k(K[W]),!0)}}}function dt(e,t,n){let r,c=1;for(;c<64;)r=t[e.value],r==65280?c=64:r>>8==255?c+=r&255:(n[c]=r,c++),e.value++}function mt(e,t){t[0]=k(e[0]),t[1]=k(e[1]),t[2]=k(e[5]),t[3]=k(e[6]),t[4]=k(e[14]),t[5]=k(e[15]),t[6]=k(e[27]),t[7]=k(e[28]),t[8]=k(e[2]),t[9]=k(e[4]),t[10]=k(e[7]),t[11]=k(e[13]),t[12]=k(e[16]),t[13]=k(e[26]),t[14]=k(e[29]),t[15]=k(e[42]),t[16]=k(e[3]),t[17]=k(e[8]),t[18]=k(e[12]),t[19]=k(e[17]),t[20]=k(e[25]),t[21]=k(e[30]),t[22]=k(e[41]),t[23]=k(e[43]),t[24]=k(e[9]),t[25]=k(e[11]),t[26]=k(e[18]),t[27]=k(e[24]),t[28]=k(e[31]),t[29]=k(e[40]),t[30]=k(e[44]),t[31]=k(e[53]),t[32]=k(e[10]),t[33]=k(e[19]),t[34]=k(e[23]),t[35]=k(e[32]),t[36]=k(e[39]),t[37]=k(e[45]),t[38]=k(e[52]),t[39]=k(e[54]),t[40]=k(e[20]),t[41]=k(e[22]),t[42]=k(e[33]),t[43]=k(e[38]),t[44]=k(e[46]),t[45]=k(e[51]),t[46]=k(e[55]),t[47]=k(e[60]),t[48]=k(e[21]),t[49]=k(e[34]),t[50]=k(e[37]),t[51]=k(e[47]),t[52]=k(e[50]),t[53]=k(e[56]),t[54]=k(e[59]),t[55]=k(e[61]),t[56]=k(e[35]),t[57]=k(e[36]),t[58]=k(e[48]),t[59]=k(e[49]),t[60]=k(e[57]),t[61]=k(e[58]),t[62]=k(e[62]),t[63]=k(e[63])}function yt(e){const t=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),r=.5*Math.cos(3.14159/8),c=.5*Math.cos(3*3.14159/16),s=.5*Math.cos(5*3.14159/16),g=.5*Math.cos(3*3.14159/8),w=.5*Math.cos(7*3.14159/16),f=new Array(4),h=new Array(4),p=new Array(4),E=new Array(4);for(let I=0;I<8;++I){const _=I*8;f[0]=r*e[_+2],f[1]=g*e[_+2],f[2]=r*e[_+6],f[3]=g*e[_+6],h[0]=n*e[_+1]+c*e[_+3]+s*e[_+5]+w*e[_+7],h[1]=c*e[_+1]-w*e[_+3]-n*e[_+5]-s*e[_+7],h[2]=s*e[_+1]-n*e[_+3]+w*e[_+5]+c*e[_+7],h[3]=w*e[_+1]-s*e[_+3]+c*e[_+5]-n*e[_+7],p[0]=t*(e[_+0]+e[_+4]),p[3]=t*(e[_+0]-e[_+4]),p[1]=f[0]+f[3],p[2]=f[1]-f[2],E[0]=p[0]+p[1],E[1]=p[3]+p[2],E[2]=p[3]-p[2],E[3]=p[0]-p[1],e[_+0]=E[0]+h[0],e[_+1]=E[1]+h[1],e[_+2]=E[2]+h[2],e[_+3]=E[3]+h[3],e[_+4]=E[3]-h[3],e[_+5]=E[2]-h[2],e[_+6]=E[1]-h[1],e[_+7]=E[0]-h[0]}for(let I=0;I<8;++I)f[0]=r*e[16+I],f[1]=g*e[16+I],f[2]=r*e[48+I],f[3]=g*e[48+I],h[0]=n*e[8+I]+c*e[24+I]+s*e[40+I]+w*e[56+I],h[1]=c*e[8+I]-w*e[24+I]-n*e[40+I]-s*e[56+I],h[2]=s*e[8+I]-n*e[24+I]+w*e[40+I]+c*e[56+I],h[3]=w*e[8+I]-s*e[24+I]+c*e[40+I]-n*e[56+I],p[0]=t*(e[I]+e[32+I]),p[3]=t*(e[I]-e[32+I]),p[1]=f[0]+f[3],p[2]=f[1]-f[2],E[0]=p[0]+p[1],E[1]=p[3]+p[2],E[2]=p[3]-p[2],E[3]=p[0]-p[1],e[0+I]=E[0]+h[0],e[8+I]=E[1]+h[1],e[16+I]=E[2]+h[2],e[24+I]=E[3]+h[3],e[32+I]=E[3]-h[3],e[40+I]=E[2]-h[2],e[48+I]=E[1]-h[1],e[56+I]=E[0]-h[0]}function wt(e){for(let t=0;t<64;++t){const n=e[0][t],r=e[1][t],c=e[2][t];e[0][t]=n+1.5747*c,e[1][t]=n-.1873*r-.4682*c,e[2][t]=n+1.8556*r}}function bt(e,t,n){for(let r=0;r<64;++r)t[n+r]=O.DataUtils.toHalfFloat(St(e[r]))}function St(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(V,Math.abs(e)-1)}function $e(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function vt(e){const t=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(tt(t)),r=new Uint8Array(n.length);return Ue(n),et(n,r),new DataView(r.buffer)}function Ke(e){const t=e.array.slice(e.offset.value,e.offset.value+e.size),n=Ye(t),r=new Uint8Array(n.length);return Ue(n),et(n,r),new DataView(r.buffer)}function Tt(e){const t=e.viewer,n={value:e.offset.value},r=new Uint16Array(e.columns*e.lines*(e.inputChannels.length*e.type)),c=new Uint8Array(8192);let s=0;const g=new Array(e.inputChannels.length);for(let P=0,x=e.inputChannels.length;P<x;P++)g[P]={},g[P].start=s,g[P].end=g[P].start,g[P].nx=e.columns,g[P].ny=e.lines,g[P].size=e.type,s+=g[P].nx*g[P].ny*g[P].size;const w=Be(t,n),f=Be(t,n);if(f>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(w<=f)for(let P=0;P<f-w+1;P++)c[P+w]=Ie(t,n);const h=new Uint16Array(65536),p=Se(c,h),E=fe(t,n);Ne(e.array,t,n,E,r,s);for(let P=0;P<e.inputChannels.length;++P){const x=g[P];for(let M=0;M<g[P].size;++M)ze(r,x.start+M,x.nx,x.size,x.ny,x.nx*x.size,p)}We(h,r,s);let I=0;const _=new Uint8Array(r.buffer.byteLength);for(let P=0;P<e.lines;P++)for(let x=0;x<e.inputChannels.length;x++){const M=g[x],N=M.nx*M.size,Y=new Uint8Array(r.buffer,M.end*2,N*2);_.set(Y,I),I+=N*2,M.end+=N}return new DataView(_.buffer)}function Et(e){const t=e.array.slice(e.offset.value,e.offset.value+e.size),n=Ye(t),r=e.inputChannels.length*e.lines*e.columns*e.totalBytes,c=new ArrayBuffer(r),s=new DataView(c);let g=0,w=0;const f=new Array(4);for(let h=0;h<e.lines;h++)for(let p=0;p<e.inputChannels.length;p++){let E=0;switch(e.inputChannels[p].pixelType){case 1:f[0]=g,f[1]=f[0]+e.columns,g=f[1]+e.columns;for(let _=0;_<e.columns;++_){const P=n[f[0]++]<<8|n[f[1]++];E+=P,s.setUint16(w,E,!0),w+=2}break;case 2:f[0]=g,f[1]=f[0]+e.columns,f[2]=f[1]+e.columns,g=f[2]+e.columns;for(let _=0;_<e.columns;++_){const P=n[f[0]++]<<24|n[f[1]++]<<16|n[f[2]++]<<8;E+=P,s.setUint32(w,E,!0),w+=4}break}}return s}function nt(e){const t=e.viewer,n={value:e.offset.value},r=new Uint8Array(e.columns*e.lines*(e.inputChannels.length*e.type*2)),c={version:ue(t,n),unknownUncompressedSize:ue(t,n),unknownCompressedSize:ue(t,n),acCompressedSize:ue(t,n),dcCompressedSize:ue(t,n),rleCompressedSize:ue(t,n),rleUncompressedSize:ue(t,n),rleRawSize:ue(t,n),totalAcUncompressedCount:ue(t,n),totalDcUncompressedCount:ue(t,n),acCompression:ue(t,n)};if(c.version<2)throw new Error("EXRLoader.parse: "+Ae.compression+" version "+c.version+" is unsupported");const s=new Array;let g=Be(t,n)-2;for(;g>0;){const x=je(t.buffer,n),M=Ie(t,n),N=M>>2&3,Y=(M>>4)-1,J=new Int8Array([Y])[0],pe=Ie(t,n);s.push({name:x,index:J,type:pe,compression:N}),g-=x.length+3}const w=Ae.channels,f=new Array(e.inputChannels.length);for(let x=0;x<e.inputChannels.length;++x){const M=f[x]={},N=w[x];M.name=N.name,M.compression=0,M.decoded=!1,M.type=N.pixelType,M.pLinear=N.pLinear,M.width=e.columns,M.height=e.lines}const h={idx:new Array(3)};for(let x=0;x<e.inputChannels.length;++x){const M=f[x];for(let N=0;N<s.length;++N){const Y=s[N];M.name==Y.name&&(M.compression=Y.compression,Y.index>=0&&(h.idx[Y.index]=x),M.offset=x)}}let p,E,I;if(c.acCompressedSize>0)switch(c.acCompression){case 0:p=new Uint16Array(c.totalAcUncompressedCount),Ne(e.array,t,n,c.acCompressedSize,p,c.totalAcUncompressedCount);break;case 1:const x=e.array.slice(n.value,n.value+c.totalAcUncompressedCount),M=Ye(x);p=new Uint16Array(M.buffer),n.value+=c.totalAcUncompressedCount;break}if(c.dcCompressedSize>0){const x={array:e.array,offset:n,size:c.dcCompressedSize};E=new Uint16Array(Ke(x).buffer),n.value+=c.dcCompressedSize}if(c.rleRawSize>0){const x=e.array.slice(n.value,n.value+c.rleCompressedSize),M=Ye(x);I=tt(M.buffer),n.value+=c.rleCompressedSize}let _=0;const P=new Array(f.length);for(let x=0;x<P.length;++x)P[x]=new Array;for(let x=0;x<e.lines;++x)for(let M=0;M<f.length;++M)P[M].push(_),_+=f[M].width*e.type*2;ft(h,P,f,p,E,r);for(let x=0;x<f.length;++x){const M=f[x];if(!M.decoded)switch(M.compression){case 2:let N=0,Y=0;for(let J=0;J<e.lines;++J){let pe=P[x][N];for(let K=0;K<M.width;++K){for(let Z=0;Z<2*M.type;++Z)r[pe++]=I[Y+Z*M.width*M.height];Y++}N++}break;case 1:default:throw new Error("EXRLoader.parse: unsupported channel compression")}}return new DataView(r.buffer)}function je(e,t){const n=new Uint8Array(e);let r=0;for(;n[t.value+r]!=0;)r+=1;const c=new TextDecoder().decode(n.slice(t.value,t.value+r));return t.value=t.value+r+1,c}function Ct(e,t,n){const r=new TextDecoder().decode(new Uint8Array(e).slice(t.value,t.value+n));return t.value=t.value+n,r}function _t(e,t){const n=ge(e,t),r=fe(e,t);return[n,r]}function xt(e,t){const n=fe(e,t),r=fe(e,t);return[n,r]}function ge(e,t){const n=e.getInt32(t.value,!0);return t.value=t.value+4,n}function fe(e,t){const n=e.getUint32(t.value,!0);return t.value=t.value+4,n}function rt(e,t){const n=e[t.value];return t.value=t.value+1,n}function Ie(e,t){const n=e.getUint8(t.value);return t.value=t.value+1,n}const ue=function(e,t){let n;return"getBigInt64"in DataView.prototype?n=Number(e.getBigInt64(t.value,!0)):n=e.getUint32(t.value+4,!0)+Number(e.getUint32(t.value,!0)<<32),t.value+=8,n};function re(e,t){const n=e.getFloat32(t.value,!0);return t.value+=4,n}function kt(e,t){return O.DataUtils.toHalfFloat(re(e,t))}function k(e){const t=(e&31744)>>10,n=e&1023;return(e>>15?-1:1)*(t?t===31?n?NaN:1/0:Math.pow(2,t-15)*(1+n/1024):6103515625e-14*(n/1024))}function Be(e,t){const n=e.getUint16(t.value,!0);return t.value+=2,n}function It(e,t){return k(Be(e,t))}function Mt(e,t,n,r){const c=n.value,s=[];for(;n.value<c+r-1;){const g=je(t,n),w=ge(e,n),f=Ie(e,n);n.value+=3;const h=ge(e,n),p=ge(e,n);s.push({name:g,pixelType:w,pLinear:f,xSampling:h,ySampling:p})}return n.value+=1,s}function Rt(e,t){const n=re(e,t),r=re(e,t),c=re(e,t),s=re(e,t),g=re(e,t),w=re(e,t),f=re(e,t),h=re(e,t);return{redX:n,redY:r,greenX:c,greenY:s,blueX:g,blueY:w,whiteX:f,whiteY:h}}function Ot(e,t){const n=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],r=Ie(e,t);return n[r]}function At(e,t){const n=ge(e,t),r=ge(e,t),c=ge(e,t),s=ge(e,t);return{xMin:n,yMin:r,xMax:c,yMax:s}}function Pt(e,t){const n=["INCREASING_Y","DECREASING_Y","RANDOM_Y"],r=Ie(e,t);return n[r]}function Dt(e,t){const n=["ENVMAP_LATLONG","ENVMAP_CUBE"],r=Ie(e,t);return n[r]}function Lt(e,t){const n=["ONE_LEVEL","MIPMAP_LEVELS","RIPMAP_LEVELS"],r=["ROUND_DOWN","ROUND_UP"],c=fe(e,t),s=fe(e,t),g=Ie(e,t);return{xSize:c,ySize:s,levelMode:n[g&15],roundingMode:r[g>>4]}}function Nt(e,t){const n=re(e,t),r=re(e,t);return[n,r]}function Ut(e,t){const n=re(e,t),r=re(e,t),c=re(e,t);return[n,r,c]}function Bt(e,t,n,r,c){if(r==="string"||r==="stringvector"||r==="iccProfile")return Ct(t,n,c);if(r==="chlist")return Mt(e,t,n,c);if(r==="chromaticities")return Rt(e,n);if(r==="compression")return Ot(e,n);if(r==="box2i")return At(e,n);if(r==="envmap")return Dt(e,n);if(r==="tiledesc")return Lt(e,n);if(r==="lineOrder")return Pt(e,n);if(r==="float")return re(e,n);if(r==="v2f")return Nt(e,n);if(r==="v3f")return Ut(e,n);if(r==="int")return ge(e,n);if(r==="rational")return _t(e,n);if(r==="timecode")return xt(e,n);if(r==="preview")return n.value+=c,"skipped";n.value+=c}function Ft(e,t){const n=Math.log2(e);return t=="ROUND_DOWN"?Math.floor(n):Math.ceil(n)}function Ht(e,t,n){let r=0;switch(e.levelMode){case"ONE_LEVEL":r=1;break;case"MIPMAP_LEVELS":r=Ft(Math.max(t,n),e.roundingMode)+1;break;case"RIPMAP_LEVELS":throw new Error("THREE.EXRLoader: RIPMAP_LEVELS tiles currently unsupported.")}return r}function ot(e,t,n,r){const c=new Array(e);for(let s=0;s<e;s++){const g=1<<s;let w=t/g|0;r=="ROUND_UP"&&w*g<t&&(w+=1);const f=Math.max(w,1);c[s]=(f+n-1)/n|0}return c}function Zt(){const e=this,t=e.offset,n={value:0};for(let r=0;r<e.tileCount;r++){const c=ge(e.viewer,t),s=ge(e.viewer,t);t.value+=8,e.size=fe(e.viewer,t);const g=c*e.blockWidth,w=s*e.blockHeight;e.columns=g+e.blockWidth>e.width?e.width-g:e.blockWidth,e.lines=w+e.blockHeight>e.height?e.height-w:e.blockHeight;const f=e.columns*e.totalBytes,p=e.size<e.lines*f?e.uncompress(e):$e(e);t.value+=e.size;for(let E=0;E<e.lines;E++){const I=E*e.columns*e.totalBytes;for(let _=0;_<e.inputChannels.length;_++){const P=Ae.channels[_].name,x=e.channelByteOffsets[P]*e.columns,M=e.decodeChannels[P];if(M===void 0)continue;n.value=I+x;const N=(e.height-(1+w+E))*e.outLineWidth;for(let Y=0;Y<e.columns;Y++){const J=N+(Y+g)*e.outputChannels+M;e.byteArray[J]=e.getter(p,n)}}}}}function zt(){const e=this,t=e.offset,n={value:0};for(let r=0;r<e.height/e.blockHeight;r++){const c=ge(e.viewer,t)-Ae.dataWindow.yMin;e.size=fe(e.viewer,t),e.lines=c+e.blockHeight>e.height?e.height-c:e.blockHeight;const s=e.columns*e.totalBytes,w=e.size<e.lines*s?e.uncompress(e):$e(e);t.value+=e.size;for(let f=0;f<e.blockHeight;f++){const h=r*e.blockHeight,p=f+e.scanOrder(h);if(p>=e.height)continue;const E=f*s,I=(e.height-1-p)*e.outLineWidth;for(let _=0;_<e.inputChannels.length;_++){const P=Ae.channels[_].name,x=e.channelByteOffsets[P]*e.columns,M=e.decodeChannels[P];if(M!==void 0){n.value=E+x;for(let N=0;N<e.columns;N++){const Y=I+N*e.outputChannels+M;e.byteArray[Y]=e.getter(w,n)}}}}}}function Wt(e,t,n){const r={};if(e.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");r.version=e.getUint8(4);const c=e.getUint8(5);r.spec={singleTile:!!(c&2),longName:!!(c&4),deepFormat:!!(c&8),multiPart:!!(c&16)},n.value=8;let s=!0;for(;s;){const g=je(t,n);if(g==="")s=!1;else{const w=je(t,n),f=fe(e,n),h=Bt(e,t,n,w,f);h===void 0?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${w}'.`):r[g]=h}}if((c&-7)!=0)throw console.error("THREE.EXRHeader:",r),new Error("THREE.EXRLoader: Provided file is currently unsupported.");return r}function jt(e,t,n,r,c){const s={size:0,viewer:t,array:n,offset:r,width:e.dataWindow.xMax-e.dataWindow.xMin+1,height:e.dataWindow.yMax-e.dataWindow.yMin+1,inputChannels:e.channels,channelByteOffsets:{},scanOrder:null,totalBytes:null,columns:null,lines:null,type:null,uncompress:null,getter:null,format:null,colorSpace:O.LinearSRGBColorSpace};switch(e.compression){case"NO_COMPRESSION":s.blockHeight=1,s.uncompress=$e;break;case"RLE_COMPRESSION":s.blockHeight=1,s.uncompress=vt;break;case"ZIPS_COMPRESSION":s.blockHeight=1,s.uncompress=Ke;break;case"ZIP_COMPRESSION":s.blockHeight=16,s.uncompress=Ke;break;case"PIZ_COMPRESSION":s.blockHeight=32,s.uncompress=Tt;break;case"PXR24_COMPRESSION":s.blockHeight=16,s.uncompress=Et;break;case"DWAA_COMPRESSION":s.blockHeight=32,s.uncompress=nt;break;case"DWAB_COMPRESSION":s.blockHeight=256,s.uncompress=nt;break;default:throw new Error("EXRLoader.parse: "+e.compression+" is unsupported")}const g={};for(const p of e.channels)switch(p.name){case"Y":case"R":case"G":case"B":case"A":g[p.name]=!0,s.type=p.pixelType}let w=!1;if(g.R&&g.G&&g.B)w=!g.A,s.outputChannels=4,s.decodeChannels={R:0,G:1,B:2,A:3};else if(g.Y)s.outputChannels=1,s.decodeChannels={Y:0};else throw new Error("EXRLoader.parse: file contains unsupported data channels.");if(s.type==1)switch(c){case O.FloatType:s.getter=It;break;case O.HalfFloatType:s.getter=Be;break}else if(s.type==2)switch(c){case O.FloatType:s.getter=re;break;case O.HalfFloatType:s.getter=kt}else throw new Error("EXRLoader.parse: unsupported pixelType "+s.type+" for "+e.compression+".");s.columns=s.width;const f=s.width*s.height*s.outputChannels;switch(c){case O.FloatType:s.byteArray=new Float32Array(f),w&&s.byteArray.fill(1,0,f);break;case O.HalfFloatType:s.byteArray=new Uint16Array(f),w&&s.byteArray.fill(15360,0,f);break;default:console.error("THREE.EXRLoader: unsupported type: ",c);break}let h=0;for(const p of e.channels)s.decodeChannels[p.name]!==void 0&&(s.channelByteOffsets[p.name]=h),h+=p.pixelType*2;if(s.totalBytes=h,s.outLineWidth=s.width*s.outputChannels,e.lineOrder==="INCREASING_Y"?s.scanOrder=p=>p:s.scanOrder=p=>s.height-1-p,s.outputChannels==4?(s.format=O.RGBAFormat,s.colorSpace=O.LinearSRGBColorSpace):(s.format=O.RedFormat,s.colorSpace=O.NoColorSpace),e.spec.singleTile){s.blockHeight=e.tiles.ySize,s.blockWidth=e.tiles.xSize;const p=Ht(e.tiles,s.width,s.height),E=ot(p,s.width,e.tiles.xSize,e.tiles.roundingMode),I=ot(p,s.height,e.tiles.ySize,e.tiles.roundingMode);s.tileCount=E[0]*I[0];for(let _=0;_<p;_++)for(let P=0;P<I[_];P++)for(let x=0;x<E[_];x++)ue(t,r);s.decode=Zt.bind(s)}else{s.blockWidth=s.width;const p=Math.ceil(s.height/s.blockHeight);for(let E=0;E<p;E++)ue(t,r);s.decode=zt.bind(s)}return s}const st={value:0},it=new DataView(o),Gt=new Uint8Array(o),Ae=Wt(it,o,st),De=jt(Ae,it,Gt,st,this.type);return De.decode(),{header:Ae,width:De.width,height:De.height,data:De.byteArray,format:De.format,colorSpace:De.colorSpace,type:this.type}}setDataType(o){return this.type=o,this}load(o,l,u,m){function a(S,T){S.colorSpace=T.colorSpace,S.minFilter=O.LinearFilter,S.magFilter=O.LinearFilter,S.generateMipmaps=!1,S.flipY=!1,l&&l(S,T)}return super.load(o,a,u,m)}}const Ve=new WeakMap;class ln extends O.Loader{constructor(o){super(o),this.libraryPath="",this.libraryPending=null,this.libraryBinary=null,this.libraryConfig={},this.url="",this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.workerConfig={},this.materials=[],this.warnings=[]}setLibraryPath(o){return this.libraryPath=o,this}setWorkerLimit(o){return this.workerLimit=o,this}load(o,l,u,m){const a=new O.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),this.url=o,a.load(o,S=>{if(Ve.has(S))return Ve.get(S).promise.then(l).catch(m);this.decodeObjects(S,o).then(T=>{T.userData.warnings=this.warnings,l(T)}).catch(T=>m(T))},u,m)}debug(){console.log("Task load: ",this.workerPool.map(o=>o._taskLoad))}decodeObjects(o,l){let u,m;const a=o.byteLength,S=this._getWorker(a).then(T=>(u=T,m=this.workerNextTaskID++,new Promise((R,z)=>{u._callbacks[m]={resolve:R,reject:z},u.postMessage({type:"decode",id:m,buffer:o},[o])}))).then(T=>this._createGeometry(T.data)).catch(T=>{throw T});return S.catch(()=>!0).then(()=>{u&&m&&this._releaseTask(u,m)}),Ve.set(o,{url:l,promise:S}),S}parse(o,l,u){this.decodeObjects(o,"").then(m=>{m.userData.warnings=this.warnings,l(m)}).catch(m=>u(m))}_compareMaterials(o){const l={};l.name=o.name,l.color={},l.color.r=o.color.r,l.color.g=o.color.g,l.color.b=o.color.b,l.type=o.type,l.vertexColors=o.vertexColors;const u=JSON.stringify(l);for(let m=0;m<this.materials.length;m++){const a=this.materials[m],S={};if(S.name=a.name,S.color={},S.color.r=a.color.r,S.color.g=a.color.g,S.color.b=a.color.b,S.type=a.type,S.vertexColors=a.vertexColors,JSON.stringify(S)===u)return a}return this.materials.push(o),o}_createMaterial(o,l){if(o===void 0)return new O.MeshStandardMaterial({color:new O.Color(1,1,1),metalness:.8,name:O.Loader.DEFAULT_MATERIAL_NAME,side:O.DoubleSide});const u=new O.MeshPhysicalMaterial({color:new O.Color(o.diffuseColor.r/255,o.diffuseColor.g/255,o.diffuseColor.b/255),emissive:new O.Color(o.emissionColor.r,o.emissionColor.g,o.emissionColor.b),flatShading:o.disableLighting,ior:o.indexOfRefraction,name:o.name,reflectivity:o.reflectivity,opacity:1-o.transparency,side:O.DoubleSide,specularColor:o.specularColor,transparent:o.transparency>0});if(u.userData.id=o.id,o.pbrSupported){const a=o.pbr;u.anisotropy=a.anisotropic,u.anisotropyRotation=a.anisotropicRotation,u.color=new O.Color(a.baseColor.r,a.baseColor.g,a.baseColor.b),u.clearcoat=a.clearcoat,u.clearcoatRoughness=a.clearcoatRoughness,u.metalness=a.metallic,u.transmission=1-a.opacity,u.roughness=a.roughness,u.sheen=a.sheen,u.specularIntensity=a.specular,u.thickness=a.subsurface}o.pbrSupported&&o.pbr.opacity===0&&o.transparency===1&&(u.opacity=.2,u.transmission=1);const m=new O.TextureLoader;for(let a=0;a<o.textures.length;a++){const S=o.textures[a];if(S.image!==null){const T=m.load(S.image);switch(S.type){case"Bump":u.bumpMap=T;break;case"Diffuse":u.map=T;break;case"Emap":u.envMap=T;break;case"Opacity":u.transmissionMap=T;break;case"Transparency":u.alphaMap=T,u.transparent=!0;break;case"PBR_Alpha":u.alphaMap=T,u.transparent=!0;break;case"PBR_AmbientOcclusion":u.aoMap=T;break;case"PBR_Anisotropic":u.anisotropyMap=T;break;case"PBR_BaseColor":u.map=T;break;case"PBR_Clearcoat":u.clearcoatMap=T;break;case"PBR_ClearcoatBump":u.clearcoatNormalMap=T;break;case"PBR_ClearcoatRoughness":u.clearcoatRoughnessMap=T;break;case"PBR_Displacement":u.displacementMap=T;break;case"PBR_Emission":u.emissiveMap=T;break;case"PBR_Metallic":u.metalnessMap=T;break;case"PBR_Roughness":u.roughnessMap=T;break;case"PBR_Sheen":u.sheenColorMap=T;break;case"PBR_Specular":u.specularColorMap=T;break;case"PBR_Subsurface":u.thicknessMap=T;break;default:this.warnings.push({message:`THREE.3DMLoader: No conversion exists for 3dm ${S.type}.`,type:"no conversion"});break}T.wrapS=S.wrapU===0?O.RepeatWrapping:O.ClampToEdgeWrapping,T.wrapT=S.wrapV===0?O.RepeatWrapping:O.ClampToEdgeWrapping,S.repeat&&T.repeat.set(S.repeat[0],S.repeat[1])}}return l&&new cn().load(l.image,function(a){a.mapping=THREE.EquirectangularReflectionMapping,u.envMap=a}),u}_createGeometry(o){const l=new O.Object3D,u=[],m=[],a=[];l.userData.layers=o.layers,l.userData.groups=o.groups,l.userData.settings=o.settings,l.userData.settings.renderSettings=o.renderSettings,l.userData.objectType="File3dm",l.userData.materials=null,l.name=this.url;let S=o.objects;const T=o.materials;for(let R=0;R<S.length;R++){const z=S[R],d=z.attributes;switch(z.objectType){case"InstanceDefinition":m.push(z);break;case"InstanceReference":a.push(z);break;default:let b=null;switch(d.materialSource.name){case"ObjectMaterialSource_MaterialFromLayer":d.layerIndex>=0&&(b=o.layers[d.layerIndex].renderMaterialIndex);break;case"ObjectMaterialSource_MaterialFromObject":d.materialIndex>=0&&(b=d.materialIndex);break}let y=null;if(b>=0){const A=T[b];y=this._createMaterial(A,o.renderEnvironment)}const i=this._createObject(z,y);if(i===void 0)continue;const D=o.layers[d.layerIndex];i.visible=D?o.layers[d.layerIndex].visible:!0,d.isInstanceDefinitionObject?u.push(i):l.add(i);break}}for(let R=0;R<m.length;R++){const z=m[R];S=[];for(let d=0;d<z.attributes.objectIds.length;d++){const b=z.attributes.objectIds[d];for(let y=0;y<u.length;y++){const i=u[y].userData.attributes.id;b===i&&S.push(u[y])}}for(let d=0;d<a.length;d++){const b=a[d];if(b.geometry.parentIdefId===z.attributes.id){const y=new O.Object3D,i=b.geometry.xform.array,D=new O.Matrix4;D.set(...i),y.applyMatrix4(D);for(let A=0;A<S.length;A++)y.add(S[A].clone(!0));l.add(y)}}}return l.userData.materials=this.materials,l.name="",l}_createObject(o,l){const u=new O.BufferGeometryLoader,m=o.attributes;let a,S,T,R;switch(o.objectType){case"Point":case"PointSet":a=u.parse(o.geometry),a.attributes.hasOwnProperty("color")?S=new O.PointsMaterial({vertexColors:!0,sizeAttenuation:!1,size:2}):(T=m.drawColor,R=new O.Color(T.r/255,T.g/255,T.b/255),S=new O.PointsMaterial({color:R,sizeAttenuation:!1,size:2})),S=this._compareMaterials(S);const z=new O.Points(a,S);return z.userData.attributes=m,z.userData.objectType=o.objectType,m.name&&(z.name=m.name),z;case"Mesh":case"Extrusion":case"SubD":case"Brep":if(o.geometry===null)return;a=u.parse(o.geometry),l===null&&(l=this._createMaterial()),a.attributes.hasOwnProperty("color")&&(l.vertexColors=!0),l=this._compareMaterials(l);const d=new O.Mesh(a,l);return d.castShadow=m.castsShadows,d.receiveShadow=m.receivesShadows,d.userData.attributes=m,d.userData.objectType=o.objectType,m.name&&(d.name=m.name),d;case"Curve":a=u.parse(o.geometry),T=m.drawColor,R=new O.Color(T.r/255,T.g/255,T.b/255),S=new O.LineBasicMaterial({color:R}),S=this._compareMaterials(S);const b=new O.Line(a,S);return b.userData.attributes=m,b.userData.objectType=o.objectType,m.name&&(b.name=m.name),b;case"TextDot":a=o.geometry;const y=document.createElement("canvas").getContext("2d"),i=`${a.fontHeight}px ${a.fontFace}`;y.font=i;const D=y.measureText(a.text).width+10,A=a.fontHeight+10,F=window.devicePixelRatio;y.canvas.width=D*F,y.canvas.height=A*F,y.canvas.style.width=D+"px",y.canvas.style.height=A+"px",y.setTransform(F,0,0,F,0,0),y.font=i,y.textBaseline="middle",y.textAlign="center",R=m.drawColor,y.fillStyle=`rgba(${R.r},${R.g},${R.b},${R.a})`,y.fillRect(0,0,D,A),y.fillStyle="white",y.fillText(a.text,D/2,A/2);const L=new O.CanvasTexture(y.canvas);L.minFilter=O.LinearFilter,L.generateMipmaps=!1,L.wrapS=O.ClampToEdgeWrapping,L.wrapT=O.ClampToEdgeWrapping,S=new O.SpriteMaterial({map:L,depthTest:!1});const H=new O.Sprite(S);return H.position.set(a.point[0],a.point[1],a.point[2]),H.scale.set(D/10,A/10,1),H.userData.attributes=m,H.userData.objectType=o.objectType,m.name&&(H.name=m.name),H;case"Light":a=o.geometry;let C;switch(a.lightStyle.name){case"LightStyle_WorldPoint":C=new O.PointLight,C.castShadow=m.castsShadows,C.position.set(a.location[0],a.location[1],a.location[2]),C.shadow.normalBias=.1;break;case"LightStyle_WorldSpot":C=new O.SpotLight,C.castShadow=m.castsShadows,C.position.set(a.location[0],a.location[1],a.location[2]),C.target.position.set(a.direction[0],a.direction[1],a.direction[2]),C.angle=a.spotAngleRadians,C.shadow.normalBias=.1;break;case"LightStyle_WorldRectangular":C=new O.RectAreaLight;const X=Math.abs(a.width[2]),ne=Math.abs(a.length[0]);C.position.set(a.location[0]-ne/2,a.location[1],a.location[2]-X/2),C.height=ne,C.width=X,C.lookAt(a.direction[0],a.direction[1],a.direction[2]);break;case"LightStyle_WorldDirectional":C=new O.DirectionalLight,C.castShadow=m.castsShadows,C.position.set(a.location[0],a.location[1],a.location[2]),C.target.position.set(a.direction[0],a.direction[1],a.direction[2]),C.shadow.normalBias=.1;break}return C&&(C.intensity=a.intensity,T=a.diffuse,R=new O.Color(T.r/255,T.g/255,T.b/255),C.color=R,C.userData.attributes=m,C.userData.objectType=o.objectType),C}}_initLibrary(){if(!this.libraryPending){const o=new O.FileLoader(this.manager);o.setPath(this.libraryPath);const l=new Promise((a,S)=>{o.load("rhino3dm.js",a,void 0,S)}),u=new O.FileLoader(this.manager);u.setPath(this.libraryPath),u.setResponseType("arraybuffer");const m=new Promise((a,S)=>{u.load("rhino3dm.wasm",a,void 0,S)});this.libraryPending=Promise.all([l,m]).then(([a,S])=>{this.libraryConfig.wasmBinary=S;const T=un.toString(),R=["/* rhino3dm.js */",a,"/* worker */",T.substring(T.indexOf("{")+1,T.lastIndexOf("}"))].join(`
`);this.workerSourceURL=URL.createObjectURL(new Blob([R]))})}return this.libraryPending}_getWorker(o){return this._initLibrary().then(()=>{if(this.workerPool.length<this.workerLimit){const u=new Worker(this.workerSourceURL);u._callbacks={},u._taskCosts={},u._taskLoad=0,u.postMessage({type:"init",libraryConfig:this.libraryConfig}),u.onmessage=m=>{const a=m.data;switch(a.type){case"warning":this.warnings.push(a.data),console.warn(a.data);break;case"decode":u._callbacks[a.id].resolve(a);break;case"error":u._callbacks[a.id].reject(a);break;default:console.error('THREE.Rhino3dmLoader: Unexpected message, "'+a.type+'"')}},this.workerPool.push(u)}else this.workerPool.sort(function(u,m){return u._taskLoad>m._taskLoad?-1:1});const l=this.workerPool[this.workerPool.length-1];return l._taskLoad+=o,l})}_releaseTask(o,l){o._taskLoad-=o._taskCosts[l],delete o._callbacks[l],delete o._taskCosts[l]}dispose(){for(let o=0;o<this.workerPool.length;++o)this.workerPool[o].terminate();this.workerPool.length=0}}function un(){let v,o,l,u;onmessage=function(d){const b=d.data;switch(b.type){case"init":o=b.libraryConfig;const y=o.wasmBinary;let i;v=new Promise(function(A){i={wasmBinary:y,onRuntimeInitialized:A},rhino3dm(i)}).then(()=>{l=i});break;case"decode":u=b.id;const D=b.buffer;v.then(()=>{try{const A=m(l,D);self.postMessage({type:"decode",id:b.id,data:A})}catch(A){self.postMessage({type:"error",id:b.id,error:A})}});break}};function m(d,b){const y=new Uint8Array(b),i=d.File3dm.fromByteArray(y),D=[],A=[],F=[],L=[],H=[],C=[],X=[],ne=i.objects(),ae=ne.count;for(let U=0;U<ae;U++){const B=ne.get(U),j=T(B,i);B.delete(),j&&D.push(j)}for(let U=0;U<i.instanceDefinitions().count;U++){const B=i.instanceDefinitions().get(U),j=R(B);j.objectIds=B.getObjectIds(),D.push({geometry:null,attributes:j,objectType:"InstanceDefinition"})}const he=[d.TextureType.Diffuse,d.TextureType.Bump,d.TextureType.Transparency,d.TextureType.Opacity,d.TextureType.Emap],ce=[d.TextureType.PBR_BaseColor,d.TextureType.PBR_Subsurface,d.TextureType.PBR_SubsurfaceScattering,d.TextureType.PBR_SubsurfaceScatteringRadius,d.TextureType.PBR_Metallic,d.TextureType.PBR_Specular,d.TextureType.PBR_SpecularTint,d.TextureType.PBR_Roughness,d.TextureType.PBR_Anisotropic,d.TextureType.PBR_Anisotropic_Rotation,d.TextureType.PBR_Sheen,d.TextureType.PBR_SheenTint,d.TextureType.PBR_Clearcoat,d.TextureType.PBR_ClearcoatBump,d.TextureType.PBR_ClearcoatRoughness,d.TextureType.PBR_OpacityIor,d.TextureType.PBR_OpacityRoughness,d.TextureType.PBR_Emission,d.TextureType.PBR_AmbientOcclusion,d.TextureType.PBR_Displacement];for(let U=0;U<i.materials().count;U++){const B=i.materials().get(U),j=R(B),ve=[];ve.push(...a(B,he,i)),j.pbrSupported=B.physicallyBased().supported,j.pbrSupported&&(ve.push(...a(B,ce,i)),j.pbr=R(B.physicallyBased())),j.textures=ve,A.push(j),B.delete()}for(let U=0;U<i.layers().count;U++){const B=i.layers().get(U),j=R(B);F.push(j),B.delete()}for(let U=0;U<i.views().count;U++){const B=i.views().get(U),j=R(B);L.push(j),B.delete()}for(let U=0;U<i.namedViews().count;U++){const B=i.namedViews().get(U),j=R(B);H.push(j),B.delete()}for(let U=0;U<i.groups().count;U++){const B=i.groups().get(U),j=R(B);C.push(j),B.delete()}const V=R(i.settings()),Se=i.strings().count;for(let U=0;U<Se;U++)X.push(i.strings().get(U));const Q=i.settings().renderSettings().renderEnvironments.reflectionId,oe=i.renderContent();let Re=null;for(let U=0;U<oe.count;U++){const B=oe.get(U);switch(B.kind){case"environment":if(B.id!==Q)break;const se=B.findChild("texture").fileName;for(let ie=0;ie<i.embeddedFiles().count;ie++){const Oe=i.embeddedFiles().get(ie).fileName;se===Oe&&(Re={type:"renderEnvironment",image:"data:image/png;base64,"+i.getEmbeddedFileAsBase64(se),name:se})}break}}const Ce={ambientLight:i.settings().renderSettings().ambientLight,backgroundColorTop:i.settings().renderSettings().backgroundColorTop,backgroundColorBottom:i.settings().renderSettings().backgroundColorBottom,useHiddenLights:i.settings().renderSettings().useHiddenLights,depthCue:i.settings().renderSettings().depthCue,flatShade:i.settings().renderSettings().flatShade,renderBackFaces:i.settings().renderSettings().renderBackFaces,renderPoints:i.settings().renderSettings().renderPoints,renderCurves:i.settings().renderSettings().renderCurves,renderIsoParams:i.settings().renderSettings().renderIsoParams,renderMeshEdges:i.settings().renderSettings().renderMeshEdges,renderAnnotations:i.settings().renderSettings().renderAnnotations,useViewportSize:i.settings().renderSettings().useViewportSize,scaleBackgroundToFit:i.settings().renderSettings().scaleBackgroundToFit,transparentBackground:i.settings().renderSettings().transparentBackground,imageDpi:i.settings().renderSettings().imageDpi,shadowMapLevel:i.settings().renderSettings().shadowMapLevel,namedView:i.settings().renderSettings().namedView,snapShot:i.settings().renderSettings().snapShot,specificViewport:i.settings().renderSettings().specificViewport,groundPlane:R(i.settings().renderSettings().groundPlane),safeFrame:R(i.settings().renderSettings().safeFrame),dithering:R(i.settings().renderSettings().dithering),skylight:R(i.settings().renderSettings().skylight),linearWorkflow:R(i.settings().renderSettings().linearWorkflow),renderChannels:R(i.settings().renderSettings().renderChannels),sun:R(i.settings().renderSettings().sun),renderEnvironments:R(i.settings().renderSettings().renderEnvironments),postEffects:R(i.settings().renderSettings().postEffects)};return i.delete(),{objects:D,materials:A,layers:F,views:L,namedViews:H,groups:C,strings:X,settings:V,renderSettings:Ce,renderEnvironment:Re}}function a(d,b,y){const i=[];for(let D=0;D<b.length;D++){const A=d.getTexture(b[D]);if(A){let F=b[D].constructor.name;F=F.substring(12,F.length);const L=S(A,F,y);i.push(L),A.delete()}}return i}function S(d,b,y){const i={type:b},D=y.getEmbeddedFileAsBase64(d.fileName);i.wrapU=d.wrapU,i.wrapV=d.wrapV,i.wrapW=d.wrapW;const A=d.uvwTransform.toFloatArray(!0);return i.repeat=[A[0],A[5]],D?i.image="data:image/png;base64,"+D:(self.postMessage({type:"warning",id:u,data:{message:`THREE.3DMLoader: Image for ${b} texture not embedded in file.`,type:"missing resource"}}),i.image=null),i}function T(d,b){const y=d.geometry(),i=d.attributes();let D=y.objectType,A,F,L,H,C;switch(D){case l.ObjectType.Curve:const X=z(y,100);L={},F={},H={},L.itemSize=3,L.type="Float32Array",L.array=[];for(let V=0;V<X.length;V++)L.array.push(X[V][0]),L.array.push(X[V][1]),L.array.push(X[V][2]);F.position=L,H.attributes=F,A={data:H};break;case l.ObjectType.Point:const ne=y.location;L={};const ae={};F={},H={},L.itemSize=3,L.type="Float32Array",L.array=[ne[0],ne[1],ne[2]];const he=i.drawColor(b);ae.itemSize=3,ae.type="Float32Array",ae.array=[he.r/255,he.g/255,he.b/255],F.position=L,F.color=ae,H.attributes=F,A={data:H};break;case l.ObjectType.PointSet:case l.ObjectType.Mesh:A=y.toThreejsJSON();break;case l.ObjectType.Brep:const ce=y.faces();C=new l.Mesh;for(let V=0;V<ce.count;V++){const Se=ce.get(V),Q=Se.getMesh(l.MeshType.Any);Q&&(C.append(Q),Q.delete()),Se.delete()}C.faces().count>0&&(C.compact(),A=C.toThreejsJSON(),ce.delete()),C.delete();break;case l.ObjectType.Extrusion:C=y.getMesh(l.MeshType.Any),C&&(A=C.toThreejsJSON(),C.delete());break;case l.ObjectType.TextDot:A=R(y);break;case l.ObjectType.Light:A=R(y),A.lightStyle.name==="LightStyle_WorldLinear"&&self.postMessage({type:"warning",id:u,data:{message:`THREE.3DMLoader: No conversion exists for ${D.constructor.name} ${A.lightStyle.name}`,type:"no conversion",guid:i.id}});break;case l.ObjectType.InstanceReference:A=R(y),A.xform=R(y.xform),A.xform.array=y.xform.toFloatArray(!0);break;case l.ObjectType.SubD:y.subdivide(3),C=l.Mesh.createFromSubDControlNet(y,!1),C&&(A=C.toThreejsJSON(),C.delete());break;default:self.postMessage({type:"warning",id:u,data:{message:`THREE.3DMLoader: Conversion not implemented for ${D.constructor.name}`,type:"not implemented",guid:i.id}});break}if(A)return F=R(i),F.geometry=R(y),i.groupCount>0&&(F.groupIds=i.getGroupList()),i.userStringCount>0&&(F.userStrings=i.getUserStrings()),y.userStringCount>0&&(F.geometry.userStrings=y.getUserStrings()),i.decals().count>0&&self.postMessage({type:"warning",id:u,data:{message:"THREE.3DMLoader: No conversion exists for the decals associated with this object.",type:"no conversion",guid:i.id}}),F.drawColor=i.drawColor(b),D=D.constructor.name,D=D.substring(11,D.length),{geometry:A,attributes:F,objectType:D};self.postMessage({type:"warning",id:u,data:{message:`THREE.3DMLoader: ${D.constructor.name} has no associated mesh geometry.`,type:"missing mesh",guid:i.id}})}function R(d){const b={};for(const y in d){const i=d[y];typeof i!="function"&&(typeof i=="object"&&i!==null&&i.hasOwnProperty("constructor")?b[y]={name:i.constructor.name,value:i.value}:typeof i=="object"&&i!==null?b[y]=R(i):b[y]=i)}return b}function z(d,b){let y=b,i=[];const D=[];if(d instanceof l.LineCurve)return[d.pointAtStart,d.pointAtEnd];if(d instanceof l.PolylineCurve){y=d.pointCount;for(let L=0;L<y;L++)i.push(d.point(L));return i}if(d instanceof l.PolyCurve){const L=d.segmentCount;for(let H=0;H<L;H++){const C=d.segmentCurve(H),X=z(C,y);i=i.concat(X),C.delete()}return i}if(d instanceof l.ArcCurve&&(y=Math.floor(d.angleDegrees/5),y=y<2?2:y),d instanceof l.NurbsCurve&&d.degree===1){const L=d.tryGetPolyline();for(let H=0;H<L.count;H++)i.push(L.get(H));return L.delete(),i}const A=d.domain,F=y-1;for(let L=0;L<y;L++){const H=A[0]+L/F*(A[1]-A[0]);if(H===A[0]||H===A[1]){D.push(H);continue}const C=d.tangentAt(H),X=d.tangentAt(D.slice(-1)[0]),ne=C[0]*C[0]+C[1]*C[1]+C[2]*C[2],ae=X[0]*X[0]+X[1]*X[1]+X[2]*X[2],he=Math.sqrt(ne*ae);let ce;if(he===0)ce=Math.PI/2;else{const V=(C.x*X.x+C.y*X.y+C.z*X.z)/he;ce=Math.acos(Math.max(-1,Math.min(1,V)))}ce<.1||D.push(H)}return i=D.map(L=>d.pointAt(L)),i}}function pn(v,o="/rhino/"){const[l,u]=at.useState([]);return at.useEffect(()=>{const m=new ln;m.setLibraryPath(o),m.load(v,a=>{const S=[];a.updateMatrixWorld(!0),a.traverse(T=>{if(T.isMesh){const R=T,z=R.clone(!0);z.applyMatrix4(R.matrixWorld),z.matrixAutoUpdate=!1,S.push(z)}}),u(S)},void 0,a=>{console.error("Error loading Rhino 3DM file:",a)})},[v,o]),{nodes:l}}exports.useRhinoLoader=pn;