@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) • 13.4 kB
JavaScript
import{aS as e,aT as n,j as t,cc as r,y as o,aY as a,C as i}from"./index-BPURObVq.esm.min.js";const l=65536,c=14,s=65537,u=16384;var f,h;function w(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 p(e,n){const t=e.getInt32(n.value,!0);return n.value+=4,t}function d(e,n){const t=e.getUint32(n.value,!0);return n.value+=4,t}function y(e,n){const t=e.getUint8(n.value);return n.value+=1,t}function v(e,n){const t=e.getUint16(n.value,!0);return n.value+=2,t}function E(e,n){const t=e[n.value];return n.value+=1,t}function S(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 b(e,n){const t=e.getFloat32(n.value,!0);return n.value+=4,t}function O(n,t){return e(v(n,t))}function A(e,o){return n(t(b(e,o),-r,r))}function g(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=w(e.buffer,n),r=p(e,n),a=y(e,n);n.value+=3;const i=p(e,n),l=p(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:b(e,n),redY:b(e,n),greenX:b(e,n),greenY:b(e,n),blueX:b(e,n),blueY:b(e,n),whiteX:b(e,n),whiteY:b(e,n)}}(e,n);case"compression":return function(e,n){return y(e,n)}(e,n);case"box2i":return function(e,n){return{xMin:p(e,n),yMin:p(e,n),xMax:p(e,n),yMax:p(e,n)}}(e,n);case"lineOrder":return function(e,n){const t=y(e,n);return h[t]}(e,n);case"float":return b(e,n);case"v2f":return function(e,n){return[b(e,n),b(e,n)]}(e,n);case"v3f":return function(e,n){return[b(e,n),b(e,n),b(e,n)]}(e,n);case"int":return p(e,n);case"rational":return function(e,n){return[p(e,n),d(e,n)]}(e,n);case"timecode":return function(e,n){return[d(e,n),d(e,n)]}(e,n);case"preview":return n.value+=r,"skipped";default:return void(n.value+=r)}}function R(e){for(let n=1;n<e.length;n++){const t=e[n-1]+e[n]-128;e[n]=t}}function C(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(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"}(f||(f={})),function(e){e[e.INCREASING_Y=0]="INCREASING_Y",e[e.DECREASING_Y=1]="DECREASING_Y"}(h||(h={}));function I(e,n,t,r,o){for(;t<e;)n=n<<8|E(r,o),t+=8;return{l:n>>(t-=e)&(1<<e)-1,c:n,lc:t}}function m(e,n,t,r){return{c:e=e<<8|E(t,r),lc:n+=8}}function U(e,n,t,r,o,a,i,l,c){if(e==n){if(r<8){const e=m(t,r,o,a);t=e.c,r=e.lc}let e=t>>(r-=8);if(e=new Uint8Array([e])[0],l.value+e>c)return null;const n=i[l.value-1];for(;e-- >0;)i[l.value++]=n}else{if(!(l.value<c))return null;i[l.value++]=e}return{c:t,lc:r}}const P=new Array(59);function T(e,n,t,r,o,a){const i=n;let l=0,c=0;for(;r<=o;r++){if(i.value-n.value>t)return;let s=I(6,l,c,e,i);const u=s.l;if(l=s.c,c=s.lc,a[r]=u,63==u){if(i.value-n.value>t)throw new Error("Error in HufUnpackEncTable");s=I(8,l,c,e,i);let u=s.l+6;if(l=s.c,c=s.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)P[e]=0;for(let n=0;n<s;++n)P[e[n]]+=1;let n=0;for(let e=58;e>0;--e){const t=n+P[e]>>1;P[e]=n,n=t}for(let n=0;n<s;++n){const t=e[n];t>0&&(e[n]=t|P[t]++<<6)}}(a)}function M(e){return 63&e}function x(e){return e>>6}function N(e,n,t,r,o,a){const i=t.value,l=d(n,t),f=d(n,t);t.value+=4;const h=d(n,t);if(t.value+=4,l<0||l>=s||f<0||f>=s)throw new Error("Wrong HUF_ENCSIZE");const w=new Array(s),p=new Array(u);!function(e){for(let n=0;n<u;n++)e[n]={},e[n].len=0,e[n].lit=0,e[n].p=null}(p);if(T(e,t,r-(t.value-i),l,f,w),h>8*(r-(t.value-i)))throw new Error("Wrong hufUncompress");!function(e,n,t,r){for(;n<=t;n++){const t=x(e[n]),o=M(e[n]);if(t>>o)throw new Error("Invalid table entry");if(o>c){const e=r[t>>o-c];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 a=1<<c-o;a>0;a--){const a=r[(t<<c-o)+e];if(a.len||a.p)throw new Error("Invalid table entry");a.len=o,a.lit=n,e++}}}}(w,l,f,p),function(e,n,t,r,o,a,i,l,s){let u=0,f=0;const h=i,w=Math.trunc(r.value+(o+7)/8);for(;r.value<w;){let o=m(u,f,t,r);for(u=o.c,f=o.lc;f>=c;){const i=n[u>>f-c&16383];if(i.len){f-=i.len;const e=U(i.lit,a,u,f,t,r,l,s,h);e&&(u=e.c,f=e.lc)}else{if(!i.p)throw new Error("hufDecode issues");let n;for(n=0;n<i.lit;n++){const c=M(e[i.p[n]]);for(;f<c&&r.value<w;)o=m(u,f,t,r),u=o.c,f=o.lc;if(f>=c&&x(e[i.p[n]])==(u>>f-c&(1<<c)-1)){f-=c;const e=U(i.p[n],a,u,f,t,r,l,s,h);e&&(u=e.c,f=e.lc);break}}if(n==i.lit)throw new Error("HufDecode issues")}}}const p=8-o&7;for(u>>=p,f-=p;f>0;){const e=n[u<<c-f&16383];if(!e.len)throw new Error("HufDecode issues");{f-=e.len;const n=U(e.lit,a,u,f,t,r,l,s,h);n&&(u=n.c,f=n.lc)}}}(w,p,e,t,h,f,a,o,{value:0})}function _(e){return 65535&e}function k(e){const n=_(e);return n>32767?n-65536:n}function z(e,n){const t=k(e),r=k(n),o=t+(1&r)+(r>>1);return{a:o,b:o-r}}function F(e,n){const t=_(e),r=_(n),o=t-(r>>1)&65535;return{a:r+o-32768&65535,b:o}}function L(e,n,t,r,o,a,i){const l=i<16384,c=t>o?o:t;let s,u,f=1;for(;f<=c;)f<<=1;for(f>>=1,s=f,f>>=1;f>=1;){u=0;const i=u+a*(o-s),c=a*f,h=a*s,w=r*f,p=r*s;let d,y,v,E;for(;u<=i;u+=h){let o=u;const a=u+r*(t-s);for(;o<=a;o+=p){const t=o+w,r=o+c,a=r+w;if(l){let i=z(e[o+n],e[r+n]);d=i.a,v=i.b,i=z(e[t+n],e[a+n]),y=i.a,E=i.b,i=z(d,y),e[o+n]=i.a,e[t+n]=i.b,i=z(v,E),e[r+n]=i.a,e[a+n]=i.b}else{let i=F(e[o+n],e[r+n]);d=i.a,v=i.b,i=F(e[t+n],e[a+n]),y=i.a,E=i.b,i=F(d,y),e[o+n]=i.a,e[t+n]=i.b,i=F(v,E),e[r+n]=i.a,e[a+n]=i.b}}if(t&f){const t=o+c;let r;r=l?z(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-s);for(;o<=a;o+=p){const t=o+w;let r;r=l?z(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}}s=f,f>>=1}return u}function D(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function B(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 R(t),C(t,r),new DataView(r.buffer)}function W(e){const n=e.array.slice(e.offset.value,e.offset.value+e.size),t=fflate.unzlibSync(n),r=new Uint8Array(t.length);return R(t),C(t,r),new DataView(r.buffer)}function Y(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 X(e){const n=e.viewer,t={value:e.offset.value},r=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),o=new Uint8Array(8192);let a=0;const i=new Array(e.channels);for(let n=0;n<e.channels;n++)i[n]={},i[n].start=a,i[n].end=i[n].start,i[n].nx=e.width,i[n].ny=e.lines,i[n].size=e.type,a+=i[n].nx*i[n].ny*i[n].size;const c=v(n,t),s=v(n,t);if(s>=8192)throw new Error("Wrong PIZ_COMPRESSION BITMAP_SIZE");if(c<=s)for(let e=0;e<s-c+1;e++)o[e+c]=y(n,t);const u=new Uint16Array(l),f=function(e,n){let t=0;for(let r=0;r<l;++r)(0==r||e[r>>3]&1<<(7&r))&&(n[t++]=r);const r=t-1;for(;t<l;)n[t++]=0;return r}(o,u),h=d(n,t);N(e.array,n,t,h,r,a);for(let n=0;n<e.channels;++n){const e=i[n];for(let t=0;t<i[n].size;++t)L(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,a);let w=0;const p=new Uint8Array(r.buffer.byteLength);for(let n=0;n<e.lines;n++)for(let n=0;n<e.channels;n++){const e=i[n],t=e.nx*e.size,o=new Uint8Array(r.buffer,2*e.end,2*t);p.set(o,w),w+=2*t,e.end+=t}return new DataView(p.buffer)}var G;!function(e){e[e.Float=0]="Float",e[e.HalfFloat=1]="HalfFloat"}(G||(G={}));class H{}H.DefaultOutputType=G.HalfFloat,H.FFLATEUrl="https://unpkg.com/fflate@0.8.2";class Z{constructor(){this.supportCascades=!1}loadCubeData(e,n,t,r,o){throw".exr not supported in Cube."}loadData(e,n,t){const r=new DataView(e.buffer),l={value:0},c=function(e,n){if(20000630!=e.getUint32(0,!0))throw new Error("Incorrect OpenEXR format");const t=e.getUint8(4),r=e.getUint8(5),a={singleTile:!!(2&r),longName:!!(4&r),deepFormat:!!(8&r),multiPart:!!(16&r)};n.value=8;const i={};let l=!0;for(;l;){const t=w(e.buffer,n);if(t){const r=w(e.buffer,n),a=g(e,n,r,d(e,n));void 0===a?o.Warn(`Unknown header attribute type ${r}'.`):i[t]=a}else l=!1}if(-5&r)throw new Error("Unsupported file format");return{version:t,spec:a,...i}}(r,l);(async function(e,n,t,r){const o={size:0,viewer:n,array:new Uint8Array(n.buffer),offset:t,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:i.TEXTUREFORMAT_RGBA,outputChannels:0,decodeChannels:{},blockCount:null,byteArray:null,linearSpace:!1,textureType:0};switch(e.compression){case f.NO_COMPRESSION:o.lines=1,o.uncompress=D;break;case f.RLE_COMPRESSION:o.lines=1,o.uncompress=B;break;case f.ZIPS_COMPRESSION:o.lines=1,o.uncompress=W,await a.LoadScriptAsync(H.FFLATEUrl);break;case f.ZIP_COMPRESSION:o.lines=16,o.uncompress=W,await a.LoadScriptAsync(H.FFLATEUrl);break;case f.PIZ_COMPRESSION:o.lines=32,o.uncompress=X;break;case f.PXR24_COMPRESSION:o.lines=16,o.uncompress=Y,await a.LoadScriptAsync(H.FFLATEUrl);break;default:throw new Error(f[e.compression]+" is unsupported")}o.scanlineBlockSize=o.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,o.type=n.pixelType}let c=!1;if(l.R&&l.G&&l.B&&l.A)o.outputChannels=4,o.decodeChannels={R:0,G:1,B:2,A:3};else if(l.R&&l.G&&l.B)c=!0,o.outputChannels=4,o.decodeChannels={R:0,G:1,B:2,A:3};else if(l.R&&l.G)o.outputChannels=2,o.decodeChannels={R:0,G:1};else if(l.R)o.outputChannels=1,o.decodeChannels={R:0};else{if(!l.Y)throw new Error("EXRLoader.parse: file contains unsupported data channels.");o.outputChannels=1,o.decodeChannels={Y:0}}if(1===o.type)switch(r){case G.Float:o.getter=O,o.inputSize=2;break;case G.HalfFloat:o.getter=v,o.inputSize=2}else{if(2!==o.type)throw new Error("Unsupported pixelType "+o.type+" for "+e.compression);switch(r){case G.Float:o.getter=b,o.inputSize=4;break;case G.HalfFloat:o.getter=A,o.inputSize=4}}o.blockCount=o.height/o.scanlineBlockSize;for(let e=0;e<o.blockCount;e++)S(n,t);const s=o.width*o.height*o.outputChannels;switch(r){case G.Float:o.byteArray=new Float32Array(s),o.textureType=i.TEXTURETYPE_FLOAT,c&&o.byteArray.fill(1,0,s);break;case G.HalfFloat:o.byteArray=new Uint16Array(s),o.textureType=i.TEXTURETYPE_HALF_FLOAT,c&&o.byteArray.fill(15360,0,s);break;default:throw new Error("Unsupported type: "+r)}let u=0;for(const n of e.channels)void 0!==o.decodeChannels[n.name]&&(o.channelLineOffsets[n.name]=u*o.width),u+=2*n.pixelType;return o.bytesPerLine=o.width*u,o.outLineWidth=o.width*o.outputChannels,"INCREASING_Y"===e.lineOrder?o.scanOrder=e=>e:o.scanOrder=e=>o.height-1-e,4==o.outputChannels?(o.format=i.TEXTUREFORMAT_RGBA,o.linearSpace=!0):(o.format=i.TEXTUREFORMAT_R,o.linearSpace=!1),o})(c,r,l,H.DefaultOutputType).then(e=>{!function(e,n,t,r){const o={value:0};for(let a=0;a<e.height/e.scanlineBlockSize;a++){const i=p(t,r)-n.dataWindow.yMin;e.size=d(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):D(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 c=t*e.bytesPerLine,s=(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=c+a;for(let n=0;n<e.width;n++){const t=s+n*e.outputChannels+i;e.byteArray&&(e.byteArray[t]=e.getter(l,o))}}}}}}(e,c,r,l);const o=c.dataWindow.xMax-c.dataWindow.xMin+1,a=c.dataWindow.yMax-c.dataWindow.yMin+1;t(o,a,n.generateMipMaps,!1,()=>{const t=n.getEngine();n.format=c.format,n.type=e.textureType,n.invertY=!1,n._gammaSpace=!c.linearSpace,e.byteArray&&t._uploadDataToTextureDirectly(n,e.byteArray,0,0,void 0,!0)})}).catch(e=>{o.Error("Failed to load EXR texture: ",e)})}}export{Z as _ExrTextureLoader};
//# sourceMappingURL=exrTextureLoader-DTwZTwIG.esm.min.js.map