UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

3 lines (2 loc) 14.7 kB
import{bU as e,L as n,b as t,C as r}from"./index-Bw2N6w1y.esm.min.js";const o=65536,a=14,i=65537,l=16384;var s,c;!function(e){e[e.NO_COMPRESSION=0]="NO_COMPRESSION",e[e.RLE_COMPRESSION=1]="RLE_COMPRESSION",e[e.ZIPS_COMPRESSION=2]="ZIPS_COMPRESSION",e[e.ZIP_COMPRESSION=3]="ZIP_COMPRESSION",e[e.PIZ_COMPRESSION=4]="PIZ_COMPRESSION",e[e.PXR24_COMPRESSION=5]="PXR24_COMPRESSION"}(s||(s={})),function(e){e[e.INCREASING_Y=0]="INCREASING_Y",e[e.DECREASING_Y=1]="DECREASING_Y"}(c||(c={}));const u=function(){const e=new ArrayBuffer(4),n=new Float32Array(e),t=new Uint32Array(e),r=new Uint32Array(512),o=new Uint32Array(512);for(let e=0;e<256;++e){const n=e-127;n<-27?(r[e]=0,r[256|e]=32768,o[e]=24,o[256|e]=24):n<-14?(r[e]=1024>>-n-14,r[256|e]=1024>>-n-14|32768,o[e]=-n-1,o[256|e]=-n-1):n<=15?(r[e]=n+15<<10,r[256|e]=n+15<<10|32768,o[e]=13,o[256|e]=13):n<128?(r[e]=31744,r[256|e]=64512,o[e]=24,o[256|e]=24):(r[e]=31744,r[256|e]=64512,o[e]=13,o[256|e]=13)}const a=new Uint32Array(2048),i=new Uint32Array(64),l=new Uint32Array(64);for(let e=1;e<1024;++e){let n=e<<13,t=0;for(;!(8388608&n);)n<<=1,t-=8388608;n&=-8388609,t+=947912704,a[e]=n|t}for(let e=1024;e<2048;++e)a[e]=939524096+(e-1024<<13);for(let e=1;e<31;++e)i[e]=e<<23;i[31]=1199570944,i[32]=2147483648;for(let e=33;e<63;++e)i[e]=2147483648+(e-32<<23);i[63]=3347054592;for(let e=1;e<64;++e)32!==e&&(l[e]=1024);return{floatView:n,uint32View:t,baseTable:r,shiftTable:o,mantissaTable:a,exponentTable:i,offsetTable:l}}();function f(e,n){const t=new Uint8Array(e);let r=0;for(;0!=t[n.value+r];)r+=1;const o=(new TextDecoder).decode(t.slice(n.value,n.value+r));return n.value=n.value+r+1,o}function w(e,n){const t=e.getInt32(n.value,!0);return n.value+=4,t}function h(e,n){const t=e.getUint32(n.value,!0);return n.value+=4,t}function p(e,n){const t=e.getUint8(n.value);return n.value+=1,t}function d(e,n){const t=e.getUint16(n.value,!0);return n.value+=2,t}function y(e,n){const t=e[n.value];return n.value+=1,t}function b(e,n){let t;return t="getBigInt64"in DataView.prototype?Number(e.getBigInt64(n.value,!0)):e.getUint32(n.value+4,!0)+Number(e.getUint32(n.value,!0)<<32),n.value+=8,t}function v(e,n){const t=e.getFloat32(n.value,!0);return n.value+=4,t}function E(e,n){return function(e){const n=(31744&e)>>10,t=1023&e;return(e>>15?-1:1)*(n?31===n?t?NaN:1/0:Math.pow(2,n-15)*(1+t/1024):t/1024*6103515625e-14)}(d(e,n))}function S(n,t){return function(n){if(Math.abs(n)>65504)throw new Error("Value out of range.Consider using float instead of half-float.");n=e(n,-65504,65504),u.floatView[0]=n;const t=u.uint32View[0],r=t>>23&511;return u.baseTable[r]+((8388607&t)>>u.shiftTable[r])}(v(n,t))}function A(e,n,t,r){switch(t){case"string":case"stringvector":case"iccProfile":return function(e,n,t){const r=(new TextDecoder).decode(new Uint8Array(e).slice(n.value,n.value+t));return n.value=n.value+t,r}(e.buffer,n,r);case"chlist":return function(e,n,t){const r=n.value,o=[];for(;n.value<r+t-1;){const t=f(e.buffer,n),r=w(e,n),a=p(e,n);n.value+=3;const i=w(e,n),l=w(e,n);o.push({name:t,pixelType:r,pLinear:a,xSampling:i,ySampling:l})}return n.value+=1,o}(e,n,r);case"chromaticities":return function(e,n){return{redX:v(e,n),redY:v(e,n),greenX:v(e,n),greenY:v(e,n),blueX:v(e,n),blueY:v(e,n),whiteX:v(e,n),whiteY:v(e,n)}}(e,n);case"compression":return function(e,n){return p(e,n)}(e,n);case"box2i":return function(e,n){return{xMin:w(e,n),yMin:w(e,n),xMax:w(e,n),yMax:w(e,n)}}(e,n);case"lineOrder":return function(e,n){const t=p(e,n);return c[t]}(e,n);case"float":return v(e,n);case"v2f":return function(e,n){return[v(e,n),v(e,n)]}(e,n);case"v3f":return function(e,n){return[v(e,n),v(e,n),v(e,n)]}(e,n);case"int":return w(e,n);case"rational":return function(e,n){return[w(e,n),h(e,n)]}(e,n);case"timecode":return function(e,n){return[h(e,n),h(e,n)]}(e,n);case"preview":return n.value+=r,"skipped";default:return void(n.value+=r)}}function g(e){for(let n=1;n<e.length;n++){const t=e[n-1]+e[n]-128;e[n]=t}}function O(e,n){let t=0,r=Math.floor((e.length+1)/2),o=0;const a=e.length-1;for(;!(o>a||(n[o++]=e[t++],o>a));)n[o++]=e[r++]}function R(e,n,t,r,o){for(;t<e;)n=n<<8|y(r,o),t+=8;return{l:n>>(t-=e)&(1<<e)-1,c:n,lc:t}}function C(e,n,t,r){return{c:e=e<<8|y(t,r),lc:n+=8}}function U(e,n,t,r,o,a,i,l,s){if(e==n){if(r<8){const e=C(t,r,o,a);t=e.c,r=e.lc}let e=t>>(r-=8);if(e=new Uint8Array([e])[0],l.value+e>s)return null;const n=i[l.value-1];for(;e-- >0;)i[l.value++]=n}else{if(!(l.value<s))return null;i[l.value++]=e}return{c:t,lc:r}}const I=new Array(59);function T(e,n,t,r,o,a){const l=n;let s=0,c=0;for(;r<=o;r++){if(l.value-n.value>t)return;let i=R(6,s,c,e,l);const u=i.l;if(s=i.c,c=i.lc,a[r]=u,63==u){if(l.value-n.value>t)throw new Error("Error in HufUnpackEncTable");i=R(8,s,c,e,l);let u=i.l+6;if(s=i.c,c=i.lc,r+u>o+1)throw new Error("Error in HufUnpackEncTable");for(;u--;)a[r++]=0;r--}else if(u>=59){let e=u-59+2;if(r+e>o+1)throw new Error("Error in HufUnpackEncTable");for(;e--;)a[r++]=0;r--}}!function(e){for(let e=0;e<=58;++e)I[e]=0;for(let n=0;n<i;++n)I[e[n]]+=1;let n=0;for(let e=58;e>0;--e){const t=n+I[e]>>1;I[e]=n,n=t}for(let n=0;n<i;++n){const t=e[n];t>0&&(e[n]=t|I[t]++<<6)}}(a)}function m(e){return 63&e}function M(e){return e>>6}function P(e,n,t,r,o,s){const c=t.value,u=h(n,t),f=h(n,t);t.value+=4;const w=h(n,t);if(t.value+=4,u<0||u>=i||f<0||f>=i)throw new Error("Wrong HUF_ENCSIZE");const p=new Array(i),d=new Array(l);!function(e){for(let n=0;n<l;n++)e[n]={},e[n].len=0,e[n].lit=0,e[n].p=null}(d);if(T(e,t,r-(t.value-c),u,f,p),w>8*(r-(t.value-c)))throw new Error("Wrong hufUncompress");!function(e,n,t,r){for(;n<=t;n++){const t=M(e[n]),o=m(e[n]);if(t>>o)throw new Error("Invalid table entry");if(o>a){const e=r[t>>o-a];if(e.len)throw new Error("Invalid table entry");if(e.lit++,e.p){const n=e.p;e.p=new Array(e.lit);for(let t=0;t<e.lit-1;++t)e.p[t]=n[t]}else e.p=new Array(1);e.p[e.lit-1]=n}else if(o){let e=0;for(let i=1<<a-o;i>0;i--){const i=r[(t<<a-o)+e];if(i.len||i.p)throw new Error("Invalid table entry");i.len=o,i.lit=n,e++}}}}(p,u,f,d),function(e,n,t,r,o,i,l,s,c){let u=0,f=0;const w=l,h=Math.trunc(r.value+(o+7)/8);for(;r.value<h;){let o=C(u,f,t,r);for(u=o.c,f=o.lc;f>=a;){const l=n[u>>f-a&16383];if(l.len){f-=l.len;const e=U(l.lit,i,u,f,t,r,s,c,w);e&&(u=e.c,f=e.lc)}else{if(!l.p)throw new Error("hufDecode issues");let n;for(n=0;n<l.lit;n++){const a=m(e[l.p[n]]);for(;f<a&&r.value<h;)o=C(u,f,t,r),u=o.c,f=o.lc;if(f>=a&&M(e[l.p[n]])==(u>>f-a&(1<<a)-1)){f-=a;const e=U(l.p[n],i,u,f,t,r,s,c,w);e&&(u=e.c,f=e.lc);break}}if(n==l.lit)throw new Error("HufDecode issues")}}}const p=8-o&7;for(u>>=p,f-=p;f>0;){const e=n[u<<a-f&16383];if(!e.len)throw new Error("HufDecode issues");{f-=e.len;const n=U(e.lit,i,u,f,t,r,s,c,w);n&&(u=n.c,f=n.lc)}}}(p,d,e,t,w,f,s,o,{value:0})}function N(e){return 65535&e}function x(e){const n=N(e);return n>32767?n-65536:n}function _(e,n){const t=x(e),r=x(n),o=t+(1&r)+(r>>1);return{a:o,b:o-r}}function F(e,n){const t=N(e),r=N(n),o=t-(r>>1)&65535;return{a:r+o-32768&65535,b:o}}function k(e,n,t,r,o,a,i){const l=i<16384,s=t>o?o:t;let c,u,f=1;for(;f<=s;)f<<=1;for(f>>=1,c=f,f>>=1;f>=1;){u=0;const i=u+a*(o-c),s=a*f,w=a*c,h=r*f,p=r*c;let d,y,b,v;for(;u<=i;u+=w){let o=u;const a=u+r*(t-c);for(;o<=a;o+=p){const t=o+h,r=o+s,a=r+h;if(l){let i=_(e[o+n],e[r+n]);d=i.a,b=i.b,i=_(e[t+n],e[a+n]),y=i.a,v=i.b,i=_(d,y),e[o+n]=i.a,e[t+n]=i.b,i=_(b,v),e[r+n]=i.a,e[a+n]=i.b}else{let i=F(e[o+n],e[r+n]);d=i.a,b=i.b,i=F(e[t+n],e[a+n]),y=i.a,v=i.b,i=F(d,y),e[o+n]=i.a,e[t+n]=i.b,i=F(b,v),e[r+n]=i.a,e[a+n]=i.b}}if(t&f){const t=o+s;let r;r=l?_(e[o+n],e[t+n]):F(e[o+n],e[t+n]),d=r.a,e[t+n]=r.b,e[o+n]=d}}if(o&f){let o=u;const a=u+r*(t-c);for(;o<=a;o+=p){const t=o+h;let r;r=l?_(e[o+n],e[t+n]):F(e[o+n],e[t+n]),d=r.a,e[t+n]=r.b,e[o+n]=d}}c=f,f>>=1}return u}function z(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function L(e){const n=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),t=new Uint8Array(function(e){let n=e.byteLength;const t=[];let r=0;const o=new DataView(e);for(;n>0;){const e=o.getInt8(r++);if(e<0){const a=-e;n-=a+1;for(let e=0;e<a;e++)t.push(o.getUint8(r++))}else{const a=e;n-=2;const i=o.getUint8(r++);for(let e=0;e<a+1;e++)t.push(i)}}return t}(n)),r=new Uint8Array(t.length);return g(t),O(t,r),new DataView(r.buffer)}function D(e){const n=e.array.slice(e.offset.value,e.offset.value+e.size),t=fflate.unzlibSync(n),r=new Uint8Array(t.length);return g(t),O(t,r),new DataView(r.buffer)}function B(e){const n=e.array.slice(e.offset.value,e.offset.value+e.size),t=fflate.unzlibSync(n),r=e.lines*e.channels*e.width,o=1==e.type?new Uint16Array(r):new Uint32Array(r);let a=0,i=0;const l=new Array(4);for(let n=0;n<e.lines;n++)for(let n=0;n<e.channels;n++){let n=0;switch(e.type){case 1:l[0]=a,l[1]=l[0]+e.width,a=l[1]+e.width;for(let r=0;r<e.width;++r){n+=t[l[0]++]<<8|t[l[1]++],o[i]=n,i++}break;case 2:l[0]=a,l[1]=l[0]+e.width,l[2]=l[1]+e.width,a=l[2]+e.width;for(let r=0;r<e.width;++r){n+=t[l[0]++]<<24|t[l[1]++]<<16|t[l[2]++]<<8,o[i]=n,i++}}}return new DataView(o.buffer)}function W(e){const n=e.viewer,t={value:e.offset.value},r=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),a=new Uint8Array(8192);let i=0;const l=new Array(e.channels);for(let n=0;n<e.channels;n++)l[n]={},l[n].start=i,l[n].end=l[n].start,l[n].nx=e.width,l[n].ny=e.lines,l[n].size=e.type,i+=l[n].nx*l[n].ny*l[n].size;const s=d(n,t),c=d(n,t);if(c>=8192)throw new Error("Wrong PIZ_COMPRESSION BITMAP_SIZE");if(s<=c)for(let e=0;e<c-s+1;e++)a[e+s]=p(n,t);const u=new Uint16Array(o),f=function(e,n){let t=0;for(let r=0;r<o;++r)(0==r||e[r>>3]&1<<(7&r))&&(n[t++]=r);const r=t-1;for(;t<o;)n[t++]=0;return r}(a,u),w=h(n,t);P(e.array,n,t,w,r,i);for(let n=0;n<e.channels;++n){const e=l[n];for(let t=0;t<l[n].size;++t)k(r,e.start+t,e.nx,e.size,e.ny,e.nx*e.size,f)}!function(e,n,t){for(let r=0;r<t;++r)n[r]=e[n[r]]}(u,r,i);let y=0;const b=new Uint8Array(r.buffer.byteLength);for(let n=0;n<e.lines;n++)for(let n=0;n<e.channels;n++){const e=l[n],t=e.nx*e.size,o=new Uint8Array(r.buffer,2*e.end,2*t);b.set(o,y),y+=2*t,e.end+=t}return new DataView(b.buffer)}var X;!function(e){e[e.Float=0]="Float",e[e.HalfFloat=1]="HalfFloat"}(X||(X={}));class Y{}Y.DefaultOutputType=X.HalfFloat,Y.FFLATEUrl="https://unpkg.com/fflate@0.8.2";class G{constructor(){this.supportCascades=!1}loadCubeData(e,n,t,r,o){throw".exr not supported in Cube."}loadData(e,o,a){const i=new DataView(e.buffer),l={value:0},c=function(e,t){if(20000630!=e.getUint32(0,!0))throw new Error("Incorrect OpenEXR format");const r=e.getUint8(4),o=e.getUint8(5),a={singleTile:!!(2&o),longName:!!(4&o),deepFormat:!!(8&o),multiPart:!!(16&o)};t.value=8;const i={};let l=!0;for(;l;){const r=f(e.buffer,t);if(r){const o=f(e.buffer,t),a=A(e,t,o,h(e,t));void 0===a?n.Warn(`Unknown header attribute type ${o}'.`):i[r]=a}else l=!1}if(-5&o)throw new Error("Unsupported file format");return{version:r,spec:a,...i}}(i,l);(async function(e,n,o,a){const i={size:0,viewer:n,array:new Uint8Array(n.buffer),offset:o,width:e.dataWindow.xMax-e.dataWindow.xMin+1,height:e.dataWindow.yMax-e.dataWindow.yMin+1,channels:e.channels.length,channelLineOffsets:{},scanOrder:()=>0,bytesPerLine:0,outLineWidth:0,lines:0,scanlineBlockSize:0,inputSize:null,type:0,uncompress:null,getter:()=>0,format:r.TEXTUREFORMAT_RGBA,outputChannels:0,decodeChannels:{},blockCount:null,byteArray:null,linearSpace:!1,textureType:0};switch(e.compression){case s.NO_COMPRESSION:i.lines=1,i.uncompress=z;break;case s.RLE_COMPRESSION:i.lines=1,i.uncompress=L;break;case s.ZIPS_COMPRESSION:i.lines=1,i.uncompress=D,await t.LoadScriptAsync(Y.FFLATEUrl);break;case s.ZIP_COMPRESSION:i.lines=16,i.uncompress=D,await t.LoadScriptAsync(Y.FFLATEUrl);break;case s.PIZ_COMPRESSION:i.lines=32,i.uncompress=W;break;case s.PXR24_COMPRESSION:i.lines=16,i.uncompress=B,await t.LoadScriptAsync(Y.FFLATEUrl);break;default:throw new Error(s[e.compression]+" is unsupported")}i.scanlineBlockSize=i.lines;const l={};for(const n of e.channels)switch(n.name){case"R":case"G":case"B":case"A":case"Y":l[n.name]=!0,i.type=n.pixelType}let c=!1;if(l.R&&l.G&&l.B&&l.A)i.outputChannels=4,i.decodeChannels={R:0,G:1,B:2,A:3};else if(l.R&&l.G&&l.B)c=!0,i.outputChannels=4,i.decodeChannels={R:0,G:1,B:2,A:3};else if(l.R&&l.G)i.outputChannels=2,i.decodeChannels={R:0,G:1};else if(l.R)i.outputChannels=1,i.decodeChannels={R:0};else{if(!l.Y)throw new Error("EXRLoader.parse: file contains unsupported data channels.");i.outputChannels=1,i.decodeChannels={Y:0}}if(1===i.type)switch(a){case X.Float:i.getter=E,i.inputSize=2;break;case X.HalfFloat:i.getter=d,i.inputSize=2}else{if(2!==i.type)throw new Error("Unsupported pixelType "+i.type+" for "+e.compression);switch(a){case X.Float:i.getter=v,i.inputSize=4;break;case X.HalfFloat:i.getter=S,i.inputSize=4}}i.blockCount=i.height/i.scanlineBlockSize;for(let e=0;e<i.blockCount;e++)b(n,o);const u=i.width*i.height*i.outputChannels;switch(a){case X.Float:i.byteArray=new Float32Array(u),i.textureType=r.TEXTURETYPE_FLOAT,c&&i.byteArray.fill(1,0,u);break;case X.HalfFloat:i.byteArray=new Uint16Array(u),i.textureType=r.TEXTURETYPE_HALF_FLOAT,c&&i.byteArray.fill(15360,0,u);break;default:throw new Error("Unsupported type: "+a)}let f=0;for(const n of e.channels)void 0!==i.decodeChannels[n.name]&&(i.channelLineOffsets[n.name]=f*i.width),f+=2*n.pixelType;return i.bytesPerLine=i.width*f,i.outLineWidth=i.width*i.outputChannels,"INCREASING_Y"===e.lineOrder?i.scanOrder=e=>e:i.scanOrder=e=>i.height-1-e,4==i.outputChannels?(i.format=r.TEXTUREFORMAT_RGBA,i.linearSpace=!0):(i.format=r.TEXTUREFORMAT_R,i.linearSpace=!1),i})(c,i,l,Y.DefaultOutputType).then((e=>{!function(e,n,t,r){const o={value:0};for(let a=0;a<e.height/e.scanlineBlockSize;a++){const i=w(t,r)-n.dataWindow.yMin;e.size=h(t,r),e.lines=i+e.scanlineBlockSize>e.height?e.height-i:e.scanlineBlockSize;const l=e.size<e.lines*e.bytesPerLine&&e.uncompress?e.uncompress(e):z(e);r.value+=e.size;for(let t=0;t<e.scanlineBlockSize;t++){const r=a*e.scanlineBlockSize,i=t+e.scanOrder(r);if(i>=e.height)continue;const s=t*e.bytesPerLine,c=(e.height-1-i)*e.outLineWidth;for(let t=0;t<e.channels;t++){const r=n.channels[t].name,a=e.channelLineOffsets[r],i=e.decodeChannels[r];if(void 0!==i){o.value=s+a;for(let n=0;n<e.width;n++){const t=c+n*e.outputChannels+i;e.byteArray&&(e.byteArray[t]=e.getter(l,o))}}}}}}(e,c,i,l);const n=c.dataWindow.xMax-c.dataWindow.xMin+1,t=c.dataWindow.yMax-c.dataWindow.yMin+1;a(n,t,o.generateMipMaps,!1,(()=>{const n=o.getEngine();o.format=c.format,o.type=e.textureType,o.invertY=!1,o._gammaSpace=!c.linearSpace,e.byteArray&&n._uploadDataToTextureDirectly(o,e.byteArray,0,0,void 0,!0)}))})).catch((e=>{n.Error("Failed to load EXR texture: ",e)}))}}export{G as _ExrTextureLoader}; //# sourceMappingURL=exrTextureLoader-9XRM-sMN.esm.min.js.map