mirror of
git://soft.sys114.com/mainsail
synced 2026-02-04 13:10:36 +09:00
2 lines
2.5 KiB
JavaScript
2 lines
2.5 KiB
JavaScript
import{b as V,c as D,d as H,C as P,e as _,V as n}from"./Viewer-DVCEMRp5.js";class A{constructor(e,i,w,c){this.name=e,this.worldAxisForNormal=i,this.worldAxisForFileX=w,this.worldAxisForFileY=c}}class T{static ConvertCubeMapTextureToSphericalPolynomial(e){var h;if(!e.isCube)return null;(h=e.getScene())==null||h.getEngine().flushFramebuffer();const i=e.getSize().width,w=e.readPixels(0,void 0,void 0,!1),c=e.readPixels(1,void 0,void 0,!1);let S,a;e.isRenderTarget?(S=e.readPixels(3,void 0,void 0,!1),a=e.readPixels(2,void 0,void 0,!1)):(S=e.readPixels(2,void 0,void 0,!1),a=e.readPixels(3,void 0,void 0,!1));const C=e.readPixels(4,void 0,void 0,!1),R=e.readPixels(5,void 0,void 0,!1),x=e.gammaSpace,y=5;let E=0;return(e.textureType==1||e.textureType==2)&&(E=1),new Promise(p=>{Promise.all([c,w,S,a,C,R]).then(([F,r,t,f,d,m])=>{const M={size:i,right:r,left:F,up:t,down:f,front:d,back:m,format:y,type:E,gammaSpace:x};p(this.ConvertCubeMapToSphericalPolynomial(M))})})}static _AreaElement(e,i){return Math.atan2(e*i,Math.sqrt(e*e+i*i+1))}static ConvertCubeMapToSphericalPolynomial(e){const i=new V;let w=0;const c=2/e.size,S=c,a=.5*c,C=a-1;for(let h=0;h<6;h++){const p=this._FileFaces[h],F=e[p.name];let r=C;const t=e.format===5?4:3;for(let f=0;f<e.size;f++){let d=C;for(let m=0;m<e.size;m++){const M=p.worldAxisForFileX.scale(d).add(p.worldAxisForFileY.scale(r)).add(p.worldAxisForNormal);M.normalize();const z=this._AreaElement(d-a,r-a)-this._AreaElement(d-a,r+a)-this._AreaElement(d+a,r-a)+this._AreaElement(d+a,r+a);let s=F[f*e.size*t+m*t+0],o=F[f*e.size*t+m*t+1],l=F[f*e.size*t+m*t+2];isNaN(s)&&(s=0),isNaN(o)&&(o=0),isNaN(l)&&(l=0),e.type===0&&(s/=255,o/=255,l/=255),e.gammaSpace&&(s=Math.pow(P(s),_),o=Math.pow(P(o),_),l=Math.pow(P(l),_));const g=this.MAX_HDRI_VALUE;if(this.PRESERVE_CLAMPED_COLORS){const L=Math.max(s,o,l);if(L>g){const u=g/L;s*=u,o*=u,l*=u}}else s=P(s,0,g),o=P(o,0,g),l=P(l,0,g);const v=new D(s,o,l);i.addLight(M,v,z),w+=z,d+=c}r+=S}}const E=4*Math.PI*6/6/w;return i.scaleInPlace(E),i.convertIncidentRadianceToIrradiance(),i.convertIrradianceToLambertianRadiance(),H.FromHarmonics(i)}}T._FileFaces=[new A("right",new n(1,0,0),new n(0,0,-1),new n(0,-1,0)),new A("left",new n(-1,0,0),new n(0,0,1),new n(0,-1,0)),new A("up",new n(0,1,0),new n(1,0,0),new n(0,0,1)),new A("down",new n(0,-1,0),new n(1,0,0),new n(0,0,-1)),new A("front",new n(0,0,1),new n(1,0,0),new n(0,-1,0)),new A("back",new n(0,0,-1),new n(-1,0,0),new n(0,-1,0))];T.MAX_HDRI_VALUE=4096;T.PRESERVE_CLAMPED_COLORS=!1;export{T as C};
|