@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) • 4.09 kB
JavaScript
import{C as t,V as e}from"./index-Bw2N6w1y.esm.min.js";class r{static ConvertPanoramaToCubemap(e,r,a,n,o=!1){if(!e)throw"ConvertPanoramaToCubemap: input cannot be null";if(e.length!=r*a*3)throw"ConvertPanoramaToCubemap: input size is wrong";return{front:this.CreateCubemapTexture(n,this.FACE_FRONT,e,r,a,o),back:this.CreateCubemapTexture(n,this.FACE_BACK,e,r,a,o),left:this.CreateCubemapTexture(n,this.FACE_LEFT,e,r,a,o),right:this.CreateCubemapTexture(n,this.FACE_RIGHT,e,r,a,o),up:this.CreateCubemapTexture(n,this.FACE_UP,e,r,a,o),down:this.CreateCubemapTexture(n,this.FACE_DOWN,e,r,a,o),size:n,type:t.TEXTURETYPE_FLOAT,format:t.TEXTUREFORMAT_RGB,gammaSpace:!1}}static CreateCubemapTexture(t,e,r,a,n,o=!1){const i=new ArrayBuffer(t*t*4*3),h=new Float32Array(i),w=o?Math.max(1,Math.round(a/4/t)):1,s=1/w,u=s*s,f=e[1].subtract(e[0]).scale(s/t),l=e[3].subtract(e[2]).scale(s/t),c=1/t;let d=0;for(let o=0;o<t;o++)for(let i=0;i<w;i++){let i=e[0],C=e[2];for(let e=0;e<t;e++)for(let s=0;s<w;s++){const w=C.subtract(i).scale(d).add(i);w.normalize();const s=this.CalcProjectionSpherical(w,r,a,n);h[o*t*3+3*e+0]+=s.r*u,h[o*t*3+3*e+1]+=s.g*u,h[o*t*3+3*e+2]+=s.b*u,i=i.add(f),C=C.add(l)}d+=c*s}return h}static CalcProjectionSpherical(t,e,r,a){let n=Math.atan2(t.z,t.x);const o=Math.acos(t.y);for(;n<-Math.PI;)n+=2*Math.PI;for(;n>Math.PI;)n-=2*Math.PI;let i=n/Math.PI;const h=o/Math.PI;i=.5*i+.5;let w=Math.round(i*r);w<0?w=0:w>=r&&(w=r-1);let s=Math.round(h*a);s<0?s=0:s>=a&&(s=a-1);const u=a-s-1;return{r:e[u*r*3+3*w+0],g:e[u*r*3+3*w+1],b:e[u*r*3+3*w+2]}}}function a(t,e,r,a,n,o){n>0?(n=function(t,e){return e>1023?t*Math.pow(2,1023)*Math.pow(2,e-1023):e<-1074?t*Math.pow(2,-1074)*Math.pow(2,e+1074):t*Math.pow(2,e)}(1,n-136),t[o+0]=e*n,t[o+1]=r*n,t[o+2]=a*n):(t[o+0]=0,t[o+1]=0,t[o+2]=0)}function n(t,e){let r="",a="";for(let n=e;n<t.length-e&&(a=String.fromCharCode(t[n]),"\n"!=a);n++)r+=a;return r}function o(t){let e=0,r=0,a=n(t,0);if("#"!=a[0]||"?"!=a[1])throw"Bad HDR Format.";let o=!1,i=!1,h=0;do{h+=a.length+1,a=n(t,h),"FORMAT=32-bit_rle_rgbe"==a?i=!0:0==a.length&&(o=!0)}while(!o);if(!i)throw"HDR Bad header format, unsupported FORMAT";h+=a.length+1,a=n(t,h);const w=/^-Y (.*) \+X (.*)$/g.exec(a);if(!w||w.length<3)throw"HDR Bad header format, no size";if(r=parseInt(w[2]),e=parseInt(w[1]),r<8||r>32767)throw"HDR Bad header format, unsupported size";return h+=a.length+1,{height:e,width:r,dataPosition:h}}function i(t,e,a=!1){const n=new Uint8Array(t),i=o(n),w=h(n,i);return r.ConvertPanoramaToCubemap(w,i.width,i.height,e,a)}function h(t,e){return function(t,e){let r=e.height;const n=e.width;let o,i,h,s,u,f=e.dataPosition,l=0,c=0,d=0;const C=new ArrayBuffer(4*n),m=new Uint8Array(C),p=new ArrayBuffer(e.width*e.height*4*3),A=new Float32Array(p);for(;r>0;){if(o=t[f++],i=t[f++],h=t[f++],s=t[f++],2!=o||2!=i||128&h||e.width<8||e.width>32767)return w(t,e);if((h<<8|s)!=n)throw"HDR Bad header format, wrong scan line width";for(l=0,d=0;d<4;d++)for(c=(d+1)*n;l<c;)if(o=t[f++],i=t[f++],o>128){if(u=o-128,0==u||u>c-l)throw"HDR Bad Format, bad scanline data (run)";for(;u-- >0;)m[l++]=i}else{if(u=o,0==u||u>c-l)throw"HDR Bad Format, bad scanline data (non-run)";if(m[l++]=i,--u>0)for(let e=0;e<u;e++)m[l++]=t[f++]}for(d=0;d<n;d++)o=m[d],i=m[d+n],h=m[d+2*n],s=m[d+3*n],a(A,o,i,h,s,(e.height-r)*n*3+3*d);r--}return A}(t,e)}function w(t,e){let r=e.height;const n=e.width;let o,i,h,w,s,u=e.dataPosition;const f=new ArrayBuffer(e.width*e.height*4*3),l=new Float32Array(f);for(;r>0;){for(s=0;s<e.width;s++)o=t[u++],i=t[u++],h=t[u++],w=t[u++],a(l,o,i,h,w,(e.height-r)*n*3+3*s);r--}return l}r.FACE_LEFT=[new e(-1,-1,-1),new e(1,-1,-1),new e(-1,1,-1),new e(1,1,-1)],r.FACE_RIGHT=[new e(1,-1,1),new e(-1,-1,1),new e(1,1,1),new e(-1,1,1)],r.FACE_FRONT=[new e(1,-1,-1),new e(1,-1,1),new e(1,1,-1),new e(1,1,1)],r.FACE_BACK=[new e(-1,-1,1),new e(-1,-1,-1),new e(-1,1,1),new e(-1,1,-1)],r.FACE_DOWN=[new e(1,1,-1),new e(1,1,1),new e(-1,1,-1),new e(-1,1,1)],r.FACE_UP=[new e(-1,-1,-1),new e(-1,-1,1),new e(1,-1,-1),new e(1,-1,1)];export{i as G,o as R,h as a};
//# sourceMappingURL=hdr-D0JnBNiN.esm.min.js.map