softbox 4.8.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("three"),T=require("./index-CPZ7CXqQ.cjs"),N=require("./Pass-C1mreNp8.cjs");function Xe(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const B=Xe(n);function Qe(s){switch(s){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function Ke(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function pe(s){switch(s){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}class ze extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,r=e.itemSize,i=e.count;if(t!==null){if(r*i%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=i*r/t}const o=e.itemSize,a=e.count,c=e.normalized,h=e.array.constructor,m=h.BYTES_PER_ELEMENT;let d=this._forcedType,f=o;if(d===null)switch(h){case Float32Array:d=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:d=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:d=n.IntType;break}let l,y,p,v,u=Qe(o);switch(d){case n.FloatType:p=1,y=Ke(o),c&&m===1?(v=h,u+="8",h===Uint8Array?l=n.UnsignedByteType:(l=n.ByteType,u+="_SNORM")):(v=Float32Array,u+="32F",l=n.FloatType);break;case n.IntType:u+=m*8+"I",p=c?Math.pow(2,h.BYTES_PER_ELEMENT*8-1):1,y=pe(o),m===1?(v=Int8Array,l=n.ByteType):m===2?(v=Int16Array,l=n.ShortType):(v=Int32Array,l=n.IntType);break;case n.UnsignedIntType:u+=m*8+"UI",p=c?Math.pow(2,h.BYTES_PER_ELEMENT*8-1):1,y=pe(o),m===1?(v=Uint8Array,l=n.UnsignedByteType):m===2?(v=Uint16Array,l=n.UnsignedShortType):(v=Uint32Array,l=n.UnsignedIntType);break}f===3&&(y===n.RGBAFormat||y===n.RGBAIntegerFormat)&&(f=4);const g=Math.ceil(Math.sqrt(a))||1,x=f*g*g,b=new v(x),w=e.normalized;e.normalized=!1;for(let R=0;R<a;R++){const _=f*R;b[_]=e.getX(R)/p,o>=2&&(b[_+1]=e.getY(R)/p),o>=3&&(b[_+2]=e.getZ(R)/p,f===4&&(b[_+3]=1)),o>=4&&(b[_+3]=e.getW(R)/p)}e.normalized=w,this.internalFormat=u,this.format=y,this.type=l,this.image.width=g,this.image.height=g,this.image.data=b,this.needsUpdate=!0,this.dispose(),e.itemSize=r,e.count=i}}class He extends ze{constructor(){super(),this._forcedType=n.UnsignedIntType}}class We extends ze{constructor(){super(),this._forcedType=n.FloatType}}class Ze{constructor(){this.index=new He,this.position=new We,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(et(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const r=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==r.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const i=T.getIndexArray(T.getVertexCount(t));this._cachedIndexAttr=new n.BufferAttribute(i,1,!1)}Je(t,r,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:r,bvhContents:i}=this;e&&e.dispose(),t&&t.dispose(),r&&r.dispose(),i&&i.dispose()}}function Je(s,e,t){const r=t.array,i=s.index?s.index.array:null;for(let o=0,a=e.length;o<a;o++){const c=3*o,h=3*e[o];for(let m=0;m<3;m++)r[c+m]=i?i[h+m]:h+m}}function et(s,e,t){const r=s._roots;if(r.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const i=r[0],o=new Uint16Array(i),a=new Uint32Array(i),c=new Float32Array(i),h=i.byteLength/T.BYTES_PER_NODE,m=2*Math.ceil(Math.sqrt(h/2)),d=new Float32Array(4*m*m),f=Math.ceil(Math.sqrt(h)),l=new Uint32Array(2*f*f);for(let y=0;y<h;y++){const p=y*T.BYTES_PER_NODE/4,v=p*2,u=T.BOUNDING_DATA_INDEX(p);for(let g=0;g<3;g++)d[8*y+0+g]=c[u+0+g],d[8*y+4+g]=c[u+3+g];if(T.IS_LEAF(v,o)){const g=T.COUNT(v,o),x=T.OFFSET(p,a),b=T.LEAFNODE_MASK_32|g;l[y*2+0]=b,l[y*2+1]=x}else{const g=a[p+6],x=T.SPLIT_AXIS(p,a);l[y*2+0]=x,l[y*2+1]=g}}e.image.data=d,e.image.width=m,e.image.height=m,e.format=n.RGBAFormat,e.type=n.FloatType,e.internalFormat="RGBA32F",e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=l,t.image.width=f,t.image.height=f,t.format=n.RGIntegerFormat,t.type=n.UnsignedIntType,t.internalFormat="RG32UI",t.minFilter=n.NearestFilter,t.magFilter=n.NearestFilter,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const tt=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("three"),N=require("./Pass-C1mreNp8.cjs"),T=require("./index-BgkyK2Uk.cjs");function Qe(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const I=Qe(n);function Xe(s){switch(s){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function Ke(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function pe(s){switch(s){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}class ze extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,r=e.itemSize,i=e.count;if(t!==null){if(r*i%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=i*r/t}const o=e.itemSize,a=e.count,c=e.normalized,f=e.array.constructor,m=f.BYTES_PER_ELEMENT;let d=this._forcedType,h=o;if(d===null)switch(f){case Float32Array:d=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:d=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:d=n.IntType;break}let l,y,p,v,u=Xe(o);switch(d){case n.FloatType:p=1,y=Ke(o),c&&m===1?(v=f,u+="8",f===Uint8Array?l=n.UnsignedByteType:(l=n.ByteType,u+="_SNORM")):(v=Float32Array,u+="32F",l=n.FloatType);break;case n.IntType:u+=m*8+"I",p=c?Math.pow(2,f.BYTES_PER_ELEMENT*8-1):1,y=pe(o),m===1?(v=Int8Array,l=n.ByteType):m===2?(v=Int16Array,l=n.ShortType):(v=Int32Array,l=n.IntType);break;case n.UnsignedIntType:u+=m*8+"UI",p=c?Math.pow(2,f.BYTES_PER_ELEMENT*8-1):1,y=pe(o),m===1?(v=Uint8Array,l=n.UnsignedByteType):m===2?(v=Uint16Array,l=n.UnsignedShortType):(v=Uint32Array,l=n.UnsignedIntType);break}h===3&&(y===n.RGBAFormat||y===n.RGBAIntegerFormat)&&(h=4);const g=Math.ceil(Math.sqrt(a))||1,x=h*g*g,b=new v(x),w=e.normalized;e.normalized=!1;for(let R=0;R<a;R++){const A=h*R;b[A]=e.getX(R)/p,o>=2&&(b[A+1]=e.getY(R)/p),o>=3&&(b[A+2]=e.getZ(R)/p,h===4&&(b[A+3]=1)),o>=4&&(b[A+3]=e.getW(R)/p)}e.normalized=w,this.internalFormat=u,this.format=y,this.type=l,this.image.width=g,this.image.height=g,this.image.data=b,this.needsUpdate=!0,this.dispose(),e.itemSize=r,e.count=i}}class He extends ze{constructor(){super(),this._forcedType=n.UnsignedIntType}}class We extends ze{constructor(){super(),this._forcedType=n.FloatType}}class Ze{constructor(){this.index=new He,this.position=new We,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(et(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const r=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==r.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const i=T.getIndexArray(T.getVertexCount(t));this._cachedIndexAttr=new n.BufferAttribute(i,1,!1)}Je(t,r,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:r,bvhContents:i}=this;e&&e.dispose(),t&&t.dispose(),r&&r.dispose(),i&&i.dispose()}}function Je(s,e,t){const r=t.array,i=s.index?s.index.array:null;for(let o=0,a=e.length;o<a;o++){const c=3*o,f=3*e[o];for(let m=0;m<3;m++)r[c+m]=i?i[f+m]:f+m}}function et(s,e,t){const r=s._roots;if(r.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const i=r[0],o=new Uint16Array(i),a=new Uint32Array(i),c=new Float32Array(i),f=i.byteLength/T.BYTES_PER_NODE,m=2*Math.ceil(Math.sqrt(f/2)),d=new Float32Array(4*m*m),h=Math.ceil(Math.sqrt(f)),l=new Uint32Array(2*h*h);for(let y=0;y<f;y++){const p=y*T.BYTES_PER_NODE/4,v=p*2,u=T.BOUNDING_DATA_INDEX(p);for(let g=0;g<3;g++)d[8*y+0+g]=c[u+0+g],d[8*y+4+g]=c[u+3+g];if(T.IS_LEAF(v,o)){const g=T.COUNT(v,o),x=T.OFFSET(p,a),b=T.LEAFNODE_MASK_32|g;l[y*2+0]=b,l[y*2+1]=x}else{const g=a[p+6],x=T.SPLIT_AXIS(p,a);l[y*2+0]=x,l[y*2+1]=g}}e.image.data=d,e.image.width=m,e.image.height=m,e.format=n.RGBAFormat,e.type=n.FloatType,e.internalFormat="RGBA32F",e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=l,t.image.width=h,t.image.height=h,t.format=n.RGIntegerFormat,t.type=n.UnsignedIntType,t.internalFormat="RG32UI",t.minFilter=n.NearestFilter,t.magFilter=n.NearestFilter,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const tt=`
2
2
 
3
3
  // A stack of uint32 indices can can store the indices for
4
4
  // a perfectly balanced tree with a depth up to 31. Lower stack
@@ -294,7 +294,7 @@ struct BVH {
294
294
  usampler2D bvhContents;
295
295
 
296
296
  };
297
- `;function Le(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function H(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new n.BufferAttribute(new t(i*o),i,r)}function O(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function it(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function st(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function ot(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function nt(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function lt(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;it(s);const c=s[0].index!==null,h=c?st(s):-1,m=ot(s);if(nt(t,h,m),r){let f=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(f,v,l),f+=v}}if(c){let f=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(h),1,!1)),f=!0),f||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!f&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let f=0,l=d.length;f<l;f++){let y=!1;const p=d[f];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,H(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||Le(R,u,v),v+=R.count}}}function ct(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let h=s.getAttribute("materialIndex");if(!h||h.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),h=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",h)}const m=h.array;for(let d=0;d<c.length;d++){const f=c[d],l=f.start,y=f.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[f.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function ut(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function ne(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function ge(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function ve(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${ne(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class ft{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=ge(t),this.primitiveCount=r,this.skeletonHash=ve(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===ge(t)&&this.skeletonHash===ve(e)&&this.primitiveCount===r)}}const M=new n.Vector3,A=new n.Vector3,C=new n.Vector3,xe=new n.Vector4,U=new n.Vector3,ee=new n.Vector3,ye=new n.Vector4,be=new n.Vector4,V=new n.Matrix4,Te=new n.Matrix4;function we(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ye.fromBufferAttribute(i.attributes.skinIndex,e),be.fromBufferAttribute(i.attributes.skinWeight,e),V.elements.fill(0);for(let c=0;c<4;c++){const h=be.getComponent(c);if(h!==0){const m=ye.getComponent(c);Te.multiplyMatrices(o[m].matrixWorld,a[m]),ht(V,Te,h)}}return V.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(V),t}function te(s,e,t,r,i){U.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],h=s[o];c!==0&&(ee.fromBufferAttribute(h,r),t?U.addScaledVector(ee,c):U.addScaledVector(ee.sub(i),c))}i.add(U)}function ht(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function dt(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let h=0;h<o;h++){const m=i.getComponent(a,h),d=i.getComponent(a+2,h);i.setComponent(a,h,d),i.setComponent(a+2,h,m)}}return s}function mt(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,h=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),h.position||t.setAttribute("position",H(c.position)),o&&!h.normal&&c.normal&&t.setAttribute("normal",H(c.normal)),a&&!h.tangent&&c.tangent&&t.setAttribute("tangent",H(c.tangent)),O(r.index,t.index),O(c.position,h.position),o&&O(c.normal,h.normal),a&&O(c.tangent,h.tangent);const m=c.position,d=o?c.normal:null,f=a?c.tangent:null,l=r.morphAttributes.position,y=r.morphAttributes.normal,p=r.morphAttributes.tangent,v=r.morphTargetsRelative,u=s.morphTargetInfluences,g=new n.Matrix3;g.getNormalMatrix(s.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let x=0,b=c.position.count;x<b;x++)M.fromBufferAttribute(m,x),d&&A.fromBufferAttribute(d,x),f&&(xe.fromBufferAttribute(f,x),C.fromBufferAttribute(f,x)),u&&(l&&te(l,u,v,x,M),y&&te(y,u,v,x,A),p&&te(p,u,v,x,C)),s.isSkinnedMesh&&(s.applyBoneTransform(x,M),d&&we(s,x,A),f&&we(s,x,C)),i&&M.applyMatrix4(s.matrixWorld),h.position.setXYZ(x,M.x,M.y,M.z),d&&(i&&A.applyNormalMatrix(g),h.normal.setXYZ(x,A.x,A.y,A.z)),f&&(i&&C.transformDirection(s.matrixWorld),h.tangent.setXYZW(x,C.x,C.y,C.z,xe.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(h[b]||t.setAttribute(b,H(c[b])),O(c[b],h[b]),Le(c[b],h[b]))}return s.matrixWorld.determinant()<0&&dt(t),t}class pt extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new ft}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!O(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(mt(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ie=0,Ue=1,Ve=2;function gt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function vt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function xt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else lt(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class yt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return gt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],h=c.uuid;r.delete(h);let m=e.get(h);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new pt,e.set(h,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&ut(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],h=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);h.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}xt(h,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let f=ie;return d?f=Ve:c.includes(!1)&&(f=Ue),{changeType:f,materials:vt(a),geometry:e}}}function bt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function Tt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class wt{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new yt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(f=>{f.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,h=bt(c),{lights:m,iesTextures:d}=Tt(o);if(a.changeType!==ie&&ct(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===Ve){const f={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,f):this.bvh=new T.MeshBVH(r,f)}else a.changeType===Ue&&this.bvh.refit()}return{bvhChanged:a.changeType!==ie,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:h,objects:o}}}class le extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Rt extends le{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
297
+ `;function Le(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function W(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new n.BufferAttribute(new t(i*o),i,r)}function H(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function it(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function st(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function ot(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function nt(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function lt(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;it(s);const c=s[0].index!==null,f=c?st(s):-1,m=ot(s);if(nt(t,f,m),r){let h=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(h,v,l),h+=v}}if(c){let h=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(f),1,!1)),h=!0),h||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!h&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let h=0,l=d.length;h<l;h++){let y=!1;const p=d[h];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,W(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||Le(R,u,v),v+=R.count}}}function ct(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let f=s.getAttribute("materialIndex");if(!f||f.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),f=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",f)}const m=f.array;for(let d=0;d<c.length;d++){const h=c[d],l=h.start,y=h.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[h.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function ut(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function ne(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function ge(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function ve(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${ne(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class ft{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=ge(t),this.primitiveCount=r,this.skeletonHash=ve(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===ge(t)&&this.skeletonHash===ve(e)&&this.primitiveCount===r)}}const C=new n.Vector3,D=new n.Vector3,E=new n.Vector3,xe=new n.Vector4,G=new n.Vector3,ee=new n.Vector3,ye=new n.Vector4,be=new n.Vector4,V=new n.Matrix4,Te=new n.Matrix4;function we(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ye.fromBufferAttribute(i.attributes.skinIndex,e),be.fromBufferAttribute(i.attributes.skinWeight,e),V.elements.fill(0);for(let c=0;c<4;c++){const f=be.getComponent(c);if(f!==0){const m=ye.getComponent(c);Te.multiplyMatrices(o[m].matrixWorld,a[m]),ht(V,Te,f)}}return V.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(V),t}function te(s,e,t,r,i){G.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],f=s[o];c!==0&&(ee.fromBufferAttribute(f,r),t?G.addScaledVector(ee,c):G.addScaledVector(ee.sub(i),c))}i.add(G)}function ht(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function dt(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let f=0;f<o;f++){const m=i.getComponent(a,f),d=i.getComponent(a+2,f);i.setComponent(a,f,d),i.setComponent(a+2,f,m)}}return s}function mt(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,f=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),f.position||t.setAttribute("position",W(c.position)),o&&!f.normal&&c.normal&&t.setAttribute("normal",W(c.normal)),a&&!f.tangent&&c.tangent&&t.setAttribute("tangent",W(c.tangent)),H(r.index,t.index),H(c.position,f.position),o&&H(c.normal,f.normal),a&&H(c.tangent,f.tangent);const m=c.position,d=o?c.normal:null,h=a?c.tangent:null,l=r.morphAttributes.position,y=r.morphAttributes.normal,p=r.morphAttributes.tangent,v=r.morphTargetsRelative,u=s.morphTargetInfluences,g=new n.Matrix3;g.getNormalMatrix(s.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let x=0,b=c.position.count;x<b;x++)C.fromBufferAttribute(m,x),d&&D.fromBufferAttribute(d,x),h&&(xe.fromBufferAttribute(h,x),E.fromBufferAttribute(h,x)),u&&(l&&te(l,u,v,x,C),y&&te(y,u,v,x,D),p&&te(p,u,v,x,E)),s.isSkinnedMesh&&(s.applyBoneTransform(x,C),d&&we(s,x,D),h&&we(s,x,E)),i&&C.applyMatrix4(s.matrixWorld),f.position.setXYZ(x,C.x,C.y,C.z),d&&(i&&D.applyNormalMatrix(g),f.normal.setXYZ(x,D.x,D.y,D.z)),h&&(i&&E.transformDirection(s.matrixWorld),f.tangent.setXYZW(x,E.x,E.y,E.z,xe.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(f[b]||t.setAttribute(b,W(c[b])),H(c[b],f[b]),Le(c[b],f[b]))}return s.matrixWorld.determinant()<0&&dt(t),t}class pt extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new ft}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!H(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(mt(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ie=0,Ue=1,Ge=2;function gt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function vt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function xt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else lt(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class yt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return gt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],f=c.uuid;r.delete(f);let m=e.get(f);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new pt,e.set(f,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&ut(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],f=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);f.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}xt(f,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,f.map(l=>({version:l.version,uuid:l.uuid})));let h=ie;return d?h=Ge:c.includes(!1)&&(h=Ue),{changeType:h,materials:vt(a),geometry:e}}}function bt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function Tt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class wt{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new yt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(h=>{h.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,f=bt(c),{lights:m,iesTextures:d}=Tt(o);if(a.changeType!==ie&&ct(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===Ge){const h={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,h):this.bvh=new T.MeshBVH(r,h)}else a.changeType===Ue&&this.bvh.refit()}return{bvhChanged:a.changeType!==ie,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:f,objects:o}}}class le extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Rt extends le{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
298
298
 
299
299
  varying vec2 vUv;
300
300
 
@@ -331,7 +331,7 @@ struct BVH {
331
331
 
332
332
  }
333
333
 
334
- }`}),this.setValues(e)}}function G(s=1){let e="uint";return s>1&&(e="uvec"+s),`
334
+ }`}),this.setValues(e)}}function q(s=1){let e="uint";return s>1&&(e="uvec"+s),`
335
335
  ${e} sobolReverseBits( ${e} x ) {
336
336
 
337
337
  x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) );
@@ -366,7 +366,7 @@ struct BVH {
366
366
  return x;
367
367
 
368
368
  }
369
- `}function q(s=1){let e="uint",t="float",r="",i=".r",o="1u";return s>1&&(e="uvec"+s,t="vec"+s,r=s+"",s===2?(i=".rg",o="uvec2( 1u, 2u )"):s===3?(i=".rgb",o="uvec3( 1u, 2u, 3u )"):(i="",o="uvec4( 1u, 2u, 3u, 4u )")),`
369
+ `}function $(s=1){let e="uint",t="float",r="",i=".r",o="1u";return s>1&&(e="uvec"+s,t="vec"+s,r=s+"",s===2?(i=".rg",o="uvec2( 1u, 2u )"):s===3?(i=".rgb",o="uvec3( 1u, 2u, 3u )"):(i="",o="uvec4( 1u, 2u, 3u, 4u )")),`
370
370
 
371
371
  ${t} sobol${r}( int effect ) {
372
372
 
@@ -384,16 +384,16 @@ struct BVH {
384
384
  return SOBOL_FACTOR * ${t}( result >> 8 );
385
385
 
386
386
  }
387
- `}const Ge=`
387
+ `}const Ve=`
388
388
 
389
389
  // Utils
390
390
  const float SOBOL_FACTOR = 1.0 / 16777216.0;
391
391
  const uint SOBOL_MAX_POINTS = 256u * 256u;
392
392
 
393
- ${G(1)}
394
- ${G(2)}
395
- ${G(3)}
396
- ${G(4)}
393
+ ${q(1)}
394
+ ${q(2)}
395
+ ${q(3)}
396
+ ${q(4)}
397
397
 
398
398
  uint sobolHash( uint x ) {
399
399
 
@@ -523,10 +523,10 @@ struct BVH {
523
523
 
524
524
  }
525
525
 
526
- ${q(1)}
527
- ${q(2)}
528
- ${q(3)}
529
- ${q(4)}
526
+ ${$(1)}
527
+ ${$(2)}
528
+ ${$(3)}
529
+ ${$(4)}
530
530
 
531
531
  `;class _t extends le{constructor(){super({blending:n.NoBlending,uniforms:{resolution:{value:new n.Vector2}},vertexShader:`
532
532
 
@@ -539,7 +539,7 @@ struct BVH {
539
539
  }
540
540
  `,fragmentShader:`
541
541
 
542
- ${Ge}
542
+ ${Ve}
543
543
  ${It}
544
544
 
545
545
  varying vec2 vUv;
@@ -550,7 +550,7 @@ struct BVH {
550
550
  gl_FragColor = generateSobolPoint( index );
551
551
 
552
552
  }
553
- `})}}class Ft{generate(e,t=256){const r=new n.WebGLRenderTarget(t,t,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new N.FullScreenQuad(new _t);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class Mt extends n.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class At{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof Mt?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function re(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Re(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Ct(s,e,t){return .2126*s+.7152*e+.0722*t}function Dt(s,e=n.HalfFloatType){const t=s.clone();t.source=new n.Source({...t.image});const{width:r,height:i,data:o}=t.image;let a=o;if(t.type!==e){e===n.HalfFloatType?a=new Uint16Array(o.length):a=new Float32Array(o.length);let c;o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?c=2**(8*o.BYTES_PER_ELEMENT-1)-1:c=2**(8*o.BYTES_PER_ELEMENT)-1;for(let h=0,m=o.length;h<m;h++){let d=o[h];t.type===n.HalfFloatType&&(d=n.DataUtils.fromHalfFloat(o[h])),t.type!==n.FloatType&&t.type!==n.HalfFloatType&&(d/=c),e===n.HalfFloatType&&(a[h]=n.DataUtils.toHalfFloat(d))}t.image.data=a,t.type=e}if(t.flipY){const c=a;a=a.slice();for(let h=0;h<i;h++)for(let m=0;m<r;m++){const d=i-h-1,f=4*(h*r+m),l=4*(d*r+m);a[l+0]=c[f+0],a[l+1]=c[f+1],a[l+2]=c[f+2],a[l+3]=c[f+3]}t.flipY=!1,t.image.data=a}return t}class Pt{constructor(){const e=new n.DataTexture(re(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(re(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(re(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Dt(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;const{width:r,height:i,data:o}=t.image,a=new Float32Array(r*i),c=new Float32Array(r*i),h=new Float32Array(i),m=new Float32Array(i);let d=0,f=0;for(let u=0;u<i;u++){let g=0;for(let x=0;x<r;x++){const b=u*r+x,w=n.DataUtils.fromHalfFloat(o[4*b+0]),R=n.DataUtils.fromHalfFloat(o[4*b+1]),_=n.DataUtils.fromHalfFloat(o[4*b+2]),F=Ct(w,R,_);g+=F,d+=F,a[b]=F,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;f+=g,h[u]=g,m[u]=f}if(f!==0)for(let u=0,g=h.length;u<g;u++)h[u]/=f,m[u]/=f;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Re(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Re(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const ae=6,Et=0,kt=1,Ot=2,Nt=3,Bt=4,S=new n.Vector3,I=new n.Vector3,Ie=new n.Matrix4,P=new n.Quaternion,Se=new n.Vector3,E=new n.Vector3,zt=new n.Vector3(0,1,0);class Ht{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*ae,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let h=0,m=e.length;h<m;h++){const d=e[h],f=h*ae*4;let l=0;for(let p=0;p<ae*4;p++)a[f+p]=0;d.getWorldPosition(I),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z;let y=Et;if(d.isRectAreaLight&&d.isCircular?y=kt:d.isSpotLight?y=Ot:d.isDirectionalLight?y=Nt:d.isPointLight&&(y=Bt),a[f+l++]=y,a[f+l++]=d.color.r,a[f+l++]=d.color.g,a[f+l++]=d.color.b,a[f+l++]=d.intensity,d.getWorldQuaternion(P),d.isRectAreaLight)S.set(d.width,0,0).applyQuaternion(P),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,d.height,0).applyQuaternion(P),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=S.cross(I).length()*(d.isCircular?Math.PI/4:1);else if(d.isSpotLight){const p=d.radius||0;Se.setFromMatrixPosition(d.matrixWorld),E.setFromMatrixPosition(d.target.matrixWorld),Ie.lookAt(Se,E,zt),P.setFromRotationMatrix(Ie),S.set(1,0,0).applyQuaternion(P),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,1,0).applyQuaternion(P),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=Math.PI*p*p,a[f+l++]=p,a[f+l++]=d.decay,a[f+l++]=d.distance,a[f+l++]=Math.cos(d.angle),a[f+l++]=Math.cos(d.angle*(1-d.penumbra)),a[f+l++]=d.iesMap?t.indexOf(d.iesMap):-1}else if(d.isPointLight){const p=S.setFromMatrixPosition(d.matrixWorld);a[f+l++]=p.x,a[f+l++]=p.y,a[f+l++]=p.z,l++,l+=4,l+=1,a[f+l++]=d.decay,a[f+l++]=d.distance}else if(d.isDirectionalLight){const p=S.setFromMatrixPosition(d.matrixWorld),v=I.setFromMatrixPosition(d.target.matrixWorld);E.subVectors(p,v).normalize(),a[f+l++]=E.x,a[f+l++]=E.y,a[f+l++]=E.z}}this.count=e.length;const c=ne(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function _e(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let h=0;h<o;h++){const m=4*h,d=e*h;for(let f=0;f<r;f++)t[i+m+f]=e>=f+1?s[d+f]/c:0}}class Wt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:h}=o,d=a*c*4*e;let f=t.itemSize;f===3&&(f=4),_e(r.image.data,f,h,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let f=0,l=r;f<l;f++)if(e[f].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const f=new We;i.push(f)}for(;i.length>r;)i.pop();for(let f=0,l=r;f<l;f++)i[f].updateFrom(e[f]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:m,height:d}=c;for(let f=0,l=r;f<l;f++){const y=i[f],v=m*d*4*f;let u=e[f].itemSize;u===3&&(u=4),_e(y.image.data,u,h,4,v)}this.dispose(),this.needsUpdate=!0}}class Lt extends Wt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ce(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function se(s){return`${s.source.uuid}:${s.colorSpace}`}function Ut(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=se(o);e.has(a)||(e.add(a),t.push(o))}return t}function Vt(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ce)}function Gt(s){const e=new Set;for(let r=0,i=s.length;r<i;r++){const o=s[r];for(const a in o){const c=o[a];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return Ut(t).sort(ce)}function qt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ce)}const qe=45,Fe=qe*4;class $t{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class jt extends n.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=n.RGBAFormat,this.type=n.FloatType,this.wrapS=n.ClampToEdgeWrapping,this.wrapT=n.ClampToEdgeWrapping,this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.features=new $t}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=se(p[v]);return f[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*qe,h=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,f={};for(let p=0,v=t.length;p<v;p++)f[se(t[p])]=p;m.width!==h&&(this.dispose(),m.data=new Float32Array(h*h*4),m.width=h,m.height=h);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Fe;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Fe;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=ne(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const Me=new n.Color;function Yt(s){return s?`${s.uuid}:${s.version}`:null}function Xt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Ae extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Xt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new N.FullScreenQuad(new Qt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(Me);const h=t.length||1;(r!==this.width||i!==this.height||this.depth!==h)&&(this.setSize(r,i,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;const m=this.fsQuad,d=this.hashes;let f=!1;for(let l=0,y=h;l<y;l++){const p=t[l],v=Yt(p);p&&(d[l]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),m.material.map=p,e.setRenderTarget(this,l),m.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,d[l]=v,f=!0)}return m.material.map=null,e.setClearColor(Me,c),e.setRenderTarget(o),e.toneMapping=a,f}dispose(){super.dispose(),this.fsQuad.dispose()}}class Qt extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
553
+ `})}}class Ft{generate(e,t=256){const r=new n.WebGLRenderTarget(t,t,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new N.FullScreenQuad(new _t);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class At extends n.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class Mt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof At?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function re(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Re(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Ct(s,e,t){return .2126*s+.7152*e+.0722*t}function Dt(s,e=n.HalfFloatType){const t=s.clone();t.source=new n.Source({...t.image});const{width:r,height:i,data:o}=t.image;let a=o;if(t.type!==e){e===n.HalfFloatType?a=new Uint16Array(o.length):a=new Float32Array(o.length);let c;o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?c=2**(8*o.BYTES_PER_ELEMENT-1)-1:c=2**(8*o.BYTES_PER_ELEMENT)-1;for(let f=0,m=o.length;f<m;f++){let d=o[f];t.type===n.HalfFloatType&&(d=n.DataUtils.fromHalfFloat(o[f])),t.type!==n.FloatType&&t.type!==n.HalfFloatType&&(d/=c),e===n.HalfFloatType&&(a[f]=n.DataUtils.toHalfFloat(d))}t.image.data=a,t.type=e}if(t.flipY){const c=a;a=a.slice();for(let f=0;f<i;f++)for(let m=0;m<r;m++){const d=i-f-1,h=4*(f*r+m),l=4*(d*r+m);a[l+0]=c[h+0],a[l+1]=c[h+1],a[l+2]=c[h+2],a[l+3]=c[h+3]}t.flipY=!1,t.image.data=a}return t}class Et{constructor(){const e=new n.DataTexture(re(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(re(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(re(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Dt(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;const{width:r,height:i,data:o}=t.image,a=new Float32Array(r*i),c=new Float32Array(r*i),f=new Float32Array(i),m=new Float32Array(i);let d=0,h=0;for(let u=0;u<i;u++){let g=0;for(let x=0;x<r;x++){const b=u*r+x,w=n.DataUtils.fromHalfFloat(o[4*b+0]),R=n.DataUtils.fromHalfFloat(o[4*b+1]),A=n.DataUtils.fromHalfFloat(o[4*b+2]),M=Ct(w,R,A);g+=M,d+=M,a[b]=M,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;h+=g,f[u]=g,m[u]=h}if(h!==0)for(let u=0,g=f.length;u<g;u++)f[u]/=h,m[u]/=h;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Re(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Re(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const ae=6,Pt=0,Ot=1,Nt=2,kt=3,Bt=4,F=new n.Vector3,_=new n.Vector3,Ie=new n.Matrix4,k=new n.Quaternion,Se=new n.Vector3,B=new n.Vector3,zt=new n.Vector3(0,1,0);class Ht{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*ae,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let f=0,m=e.length;f<m;f++){const d=e[f],h=f*ae*4;let l=0;for(let p=0;p<ae*4;p++)a[h+p]=0;d.getWorldPosition(_),a[h+l++]=_.x,a[h+l++]=_.y,a[h+l++]=_.z;let y=Pt;if(d.isRectAreaLight&&d.isCircular?y=Ot:d.isSpotLight?y=Nt:d.isDirectionalLight?y=kt:d.isPointLight&&(y=Bt),a[h+l++]=y,a[h+l++]=d.color.r,a[h+l++]=d.color.g,a[h+l++]=d.color.b,a[h+l++]=d.intensity,d.getWorldQuaternion(k),d.isRectAreaLight)F.set(d.width,0,0).applyQuaternion(k),a[h+l++]=F.x,a[h+l++]=F.y,a[h+l++]=F.z,l++,_.set(0,d.height,0).applyQuaternion(k),a[h+l++]=_.x,a[h+l++]=_.y,a[h+l++]=_.z,a[h+l++]=F.cross(_).length()*(d.isCircular?Math.PI/4:1);else if(d.isSpotLight){const p=d.radius||0;Se.setFromMatrixPosition(d.matrixWorld),B.setFromMatrixPosition(d.target.matrixWorld),Ie.lookAt(Se,B,zt),k.setFromRotationMatrix(Ie),F.set(1,0,0).applyQuaternion(k),a[h+l++]=F.x,a[h+l++]=F.y,a[h+l++]=F.z,l++,_.set(0,1,0).applyQuaternion(k),a[h+l++]=_.x,a[h+l++]=_.y,a[h+l++]=_.z,a[h+l++]=Math.PI*p*p,a[h+l++]=p,a[h+l++]=d.decay,a[h+l++]=d.distance,a[h+l++]=Math.cos(d.angle),a[h+l++]=Math.cos(d.angle*(1-d.penumbra)),a[h+l++]=d.iesMap?t.indexOf(d.iesMap):-1}else if(d.isPointLight){const p=F.setFromMatrixPosition(d.matrixWorld);a[h+l++]=p.x,a[h+l++]=p.y,a[h+l++]=p.z,l++,l+=4,l+=1,a[h+l++]=d.decay,a[h+l++]=d.distance}else if(d.isDirectionalLight){const p=F.setFromMatrixPosition(d.matrixWorld),v=_.setFromMatrixPosition(d.target.matrixWorld);B.subVectors(p,v).normalize(),a[h+l++]=B.x,a[h+l++]=B.y,a[h+l++]=B.z}}this.count=e.length;const c=ne(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function _e(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let f=0;f<o;f++){const m=4*f,d=e*f;for(let h=0;h<r;h++)t[i+m+h]=e>=h+1?s[d+h]/c:0}}class Wt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:f}=o,d=a*c*4*e;let h=t.itemSize;h===3&&(h=4),_e(r.image.data,h,f,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let h=0,l=r;h<l;h++)if(e[h].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const h=new We;i.push(h)}for(;i.length>r;)i.pop();for(let h=0,l=r;h<l;h++)i[h].updateFrom(e[h]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:f,width:m,height:d}=c;for(let h=0,l=r;h<l;h++){const y=i[h],v=m*d*4*h;let u=e[h].itemSize;u===3&&(u=4),_e(y.image.data,u,f,4,v)}this.dispose(),this.needsUpdate=!0}}class Lt extends Wt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ce(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function se(s){return`${s.source.uuid}:${s.colorSpace}`}function Ut(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=se(o);e.has(a)||(e.add(a),t.push(o))}return t}function Gt(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ce)}function Vt(s){const e=new Set;for(let r=0,i=s.length;r<i;r++){const o=s[r];for(const a in o){const c=o[a];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return Ut(t).sort(ce)}function qt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ce)}const qe=45,Fe=qe*4;class $t{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class jt extends n.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=n.RGBAFormat,this.type=n.FloatType,this.wrapS=n.ClampToEdgeWrapping,this.wrapT=n.ClampToEdgeWrapping,this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.features=new $t}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=se(p[v]);return h[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*qe,f=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,h={};for(let p=0,v=t.length;p<v;p++)h[se(t[p])]=p;m.width!==f&&(this.dispose(),m.data=new Float32Array(f*f*4),m.width=f,m.height=f);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Fe;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Fe;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=ne(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const Ae=new n.Color;function Yt(s){return s?`${s.uuid}:${s.version}`:null}function Qt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Me extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Qt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new N.FullScreenQuad(new Xt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(Ae);const f=t.length||1;(r!==this.width||i!==this.height||this.depth!==f)&&(this.setSize(r,i,f),this.hashes=new Array(f).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;const m=this.fsQuad,d=this.hashes;let h=!1;for(let l=0,y=f;l<y;l++){const p=t[l],v=Yt(p);p&&(d[l]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),m.material.map=p,e.setRenderTarget(this,l),m.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,d[l]=v,h=!0)}return m.material.map=null,e.setClearColor(Ae,c),e.setRenderTarget(o),e.toneMapping=a,h}dispose(){super.dispose(),this.fsQuad.dispose()}}class Xt extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
554
554
  varying vec2 vUv;
555
555
  void main() {
556
556
 
@@ -566,7 +566,7 @@ struct BVH {
566
566
  gl_FragColor = texture2D( map, vUv );
567
567
 
568
568
  }
569
- `})}}function Kt(s,e=Math.random()){for(let t=s.length-1;t>0;t--){const r=Math.floor(e()*(t+1)),i=s[t];s[t]=s[r],s[r]=i}return s}class Zt{constructor(e,t,r=Math.random){const i=e**t,o=new Uint16Array(i);let a=i;for(let c=0;c<i;c++)o[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<i;c++)o[c]=c;a=0},this.reshuffle=function(){a=0},this.next=function(){const{samples:c}=this;a>=o.length&&(Kt(o,r),this.reshuffle());let h=o[a++];for(let m=0;m<t;m++)c[m]=(h%e+r())/e,h=Math.floor(h/e);return c}}}class Jt{constructor(e,t,r=Math.random){let i=0;for(const h of t)i+=h;const o=new Float32Array(i),a=[];let c=0;for(const h of t){const m=new Zt(e,h,r);m.samples=new Float32Array(o.buffer,c,m.samples.length),c+=m.samples.length*4,a.push(m)}this.samples=o,this.strataCount=e,this.next=function(){for(const h of a)h.next();return o},this.reshuffle=function(){for(const h of a)h.reshuffle()},this.reset=function(){for(const h of a)h.reset()}}}class er{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}}class tr extends n.DataTexture{constructor(e=1,t=1,r=8){super(new Float32Array(1),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.strata=r,this.sampler=null,this.generator=new er,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,r)}init(e=this.image.height,t=this.image.width,r=this.strata){const{image:i}=this;if(i.width===t&&i.height===e&&this.sampler!==null)return;const o=new Array(e*t).fill(4),a=new Jt(r,o,this.random);i.width=t,i.height=e,i.data=a.samples,this.sampler=a,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}}function rr(s,e=Math.random){for(let t=s.length-1;t>0;t--){const r=~~((e()-1e-6)*t),i=s[t];s[t]=s[r],s[r]=i}}function ar(s,e){s.fill(0);for(let t=0;t<e;t++)s[t]=1}class Ce{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){const{score:e,binaryPattern:t}=this;let r=1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==0)continue;const c=e[o];c<r&&(r=c,i=o)}return i}findCluster(){const{score:e,binaryPattern:t}=this;let r=-1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==1)continue;const c=e[o];c>r&&(r=c,i=o)}return i}setSigma(e){if(e===this.sigma)return;const t=~~(Math.sqrt(20*e**2)+1),r=2*t+1,i=new Float32Array(r*r),o=e*e;for(let a=-t;a<=t;a++)for(let c=-t;c<=t;c++){const h=(t+c)*r+a+t,m=a*a+c*c;i[h]=Math.E**(-m/(2*o))}this.lookupTable=i,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){const{binaryPattern:e,score:t,size:r}=this;t.fill(0);for(let i=0,o=e.length;i<o;i++)if(e[i]===0){const a=~~(i/r),c=i-a*r;this.updateScore(c,a,1),e[i]=1}else e[i]=0}updateScore(e,t,r){const{size:i,score:o,lookupTable:a}=this,c=this.radius,h=2*c+1;for(let m=-c;m<=c;m++)for(let d=-c;d<=c;d++){const f=(c+d)*h+m+c,l=a[f];let y=e+m;y=y<0?i+y:y%i;let p=t+d;p=p<0?i+p:p%i;const v=p*i+y;o[v]+=r*l}}addPointIndex(e){this.binaryPattern[e]=1;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}}class ir{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Ce(1),this.savedSamples=new Ce(1)}generate(){const{samples:e,savedSamples:t,sigma:r,majorityPointsRatio:i,size:o}=this;e.resize(o),e.setSigma(r);const a=Math.floor(o*o*i),c=e.binaryPattern;ar(c,a),rr(c,this.random);for(let f=0,l=c.length;f<l;f++)c[f]===1&&e.addPointIndex(f);for(;;){const f=e.findCluster();e.removePointIndex(f);const l=e.findVoid();if(f===l){e.addPointIndex(f);break}e.addPointIndex(l)}const h=new Uint32Array(o*o);t.copy(e);let m;for(m=e.count-1;m>=0;){const f=e.findCluster();e.removePointIndex(f),h[f]=m,m--}const d=o*o;for(m=t.count;m<d/2;){const f=t.findVoid();t.addPointIndex(f),h[f]=m,m++}for(t.invert();m<d;){const f=t.findCluster();t.removePointIndex(f),h[f]=m,m++}return{data:h,maxValue:d}}}function sr(s){return s>=3?4:s}function or(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}class nr extends n.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.size=e,this.channels=t,this.update()}update(){const e=this.channels,t=this.size,r=new ir;r.channels=e,r.size=t;const i=sr(e),o=or(i);(this.image.width!==t||o!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*i),this.format=o,this.dispose());const a=this.image.data;for(let c=0,h=e;c<h;c++){const m=r.generate(),d=m.data,f=m.maxValue;for(let l=0,y=d.length;l<y;l++){const p=d[l]/f;a[l*i+c]=p}}this.needsUpdate=!0}}const lr=`
569
+ `})}}function Kt(s,e=Math.random()){for(let t=s.length-1;t>0;t--){const r=Math.floor(e()*(t+1)),i=s[t];s[t]=s[r],s[r]=i}return s}class Zt{constructor(e,t,r=Math.random){const i=e**t,o=new Uint16Array(i);let a=i;for(let c=0;c<i;c++)o[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<i;c++)o[c]=c;a=0},this.reshuffle=function(){a=0},this.next=function(){const{samples:c}=this;a>=o.length&&(Kt(o,r),this.reshuffle());let f=o[a++];for(let m=0;m<t;m++)c[m]=(f%e+r())/e,f=Math.floor(f/e);return c}}}class Jt{constructor(e,t,r=Math.random){let i=0;for(const f of t)i+=f;const o=new Float32Array(i),a=[];let c=0;for(const f of t){const m=new Zt(e,f,r);m.samples=new Float32Array(o.buffer,c,m.samples.length),c+=m.samples.length*4,a.push(m)}this.samples=o,this.strataCount=e,this.next=function(){for(const f of a)f.next();return o},this.reshuffle=function(){for(const f of a)f.reshuffle()},this.reset=function(){for(const f of a)f.reset()}}}class er{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}}class tr extends n.DataTexture{constructor(e=1,t=1,r=8){super(new Float32Array(1),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.strata=r,this.sampler=null,this.generator=new er,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,r)}init(e=this.image.height,t=this.image.width,r=this.strata){const{image:i}=this;if(i.width===t&&i.height===e&&this.sampler!==null)return;const o=new Array(e*t).fill(4),a=new Jt(r,o,this.random);i.width=t,i.height=e,i.data=a.samples,this.sampler=a,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}}function rr(s,e=Math.random){for(let t=s.length-1;t>0;t--){const r=~~((e()-1e-6)*t),i=s[t];s[t]=s[r],s[r]=i}}function ar(s,e){s.fill(0);for(let t=0;t<e;t++)s[t]=1}class Ce{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){const{score:e,binaryPattern:t}=this;let r=1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==0)continue;const c=e[o];c<r&&(r=c,i=o)}return i}findCluster(){const{score:e,binaryPattern:t}=this;let r=-1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==1)continue;const c=e[o];c>r&&(r=c,i=o)}return i}setSigma(e){if(e===this.sigma)return;const t=~~(Math.sqrt(20*e**2)+1),r=2*t+1,i=new Float32Array(r*r),o=e*e;for(let a=-t;a<=t;a++)for(let c=-t;c<=t;c++){const f=(t+c)*r+a+t,m=a*a+c*c;i[f]=Math.E**(-m/(2*o))}this.lookupTable=i,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){const{binaryPattern:e,score:t,size:r}=this;t.fill(0);for(let i=0,o=e.length;i<o;i++)if(e[i]===0){const a=~~(i/r),c=i-a*r;this.updateScore(c,a,1),e[i]=1}else e[i]=0}updateScore(e,t,r){const{size:i,score:o,lookupTable:a}=this,c=this.radius,f=2*c+1;for(let m=-c;m<=c;m++)for(let d=-c;d<=c;d++){const h=(c+d)*f+m+c,l=a[h];let y=e+m;y=y<0?i+y:y%i;let p=t+d;p=p<0?i+p:p%i;const v=p*i+y;o[v]+=r*l}}addPointIndex(e){this.binaryPattern[e]=1;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}}class ir{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Ce(1),this.savedSamples=new Ce(1)}generate(){const{samples:e,savedSamples:t,sigma:r,majorityPointsRatio:i,size:o}=this;e.resize(o),e.setSigma(r);const a=Math.floor(o*o*i),c=e.binaryPattern;ar(c,a),rr(c,this.random);for(let h=0,l=c.length;h<l;h++)c[h]===1&&e.addPointIndex(h);for(;;){const h=e.findCluster();e.removePointIndex(h);const l=e.findVoid();if(h===l){e.addPointIndex(h);break}e.addPointIndex(l)}const f=new Uint32Array(o*o);t.copy(e);let m;for(m=e.count-1;m>=0;){const h=e.findCluster();e.removePointIndex(h),f[h]=m,m--}const d=o*o;for(m=t.count;m<d/2;){const h=t.findVoid();t.addPointIndex(h),f[h]=m,m++}for(t.invert();m<d;){const h=t.findCluster();t.removePointIndex(h),f[h]=m,m++}return{data:f,maxValue:d}}}function sr(s){return s>=3?4:s}function or(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}class nr extends n.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.size=e,this.channels=t,this.update()}update(){const e=this.channels,t=this.size,r=new ir;r.channels=e,r.size=t;const i=sr(e),o=or(i);(this.image.width!==t||o!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*i),this.format=o,this.dispose());const a=this.image.data;for(let c=0,f=e;c<f;c++){const m=r.generate(),d=m.data,h=m.maxValue;for(let l=0,y=d.length;l<y;l++){const p=d[l]/h;a[l*i+c]=p}}this.needsUpdate=!0}}const lr=`
570
570
 
571
571
  struct PhysicalCamera {
572
572
 
@@ -2828,7 +2828,7 @@ bool bvhIntersectFogVolumeHit(
2828
2828
 
2829
2829
  }
2830
2830
 
2831
- `,Mr=`
2831
+ `,Ar=`
2832
2832
 
2833
2833
  vec3 ndcToRayOrigin( vec2 coord ) {
2834
2834
 
@@ -2911,7 +2911,7 @@ bool bvhIntersectFogVolumeHit(
2911
2911
 
2912
2912
  }
2913
2913
 
2914
- `,Ar=`
2914
+ `,Mr=`
2915
2915
 
2916
2916
  vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
2917
2917
 
@@ -3378,7 +3378,7 @@ bool bvhIntersectFogVolumeHit(
3378
3378
 
3379
3379
  }
3380
3380
 
3381
- `,Pr=`
3381
+ `,Er=`
3382
3382
 
3383
3383
  #define NO_HIT 0
3384
3384
  #define SURFACE_HIT 1
@@ -3425,7 +3425,7 @@ bool bvhIntersectFogVolumeHit(
3425
3425
 
3426
3426
  }
3427
3427
 
3428
- `;class Er extends le{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new n.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new At},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new Ze},attributesArray:{value:new Lt},materialIndexAttribute:{value:new He},materials:{value:new jt},textures:{value:new Ae().texture},lights:{value:new Ht},iesProfiles:{value:new Ae(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new Pt},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new n.Matrix4},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new tr},stratifiedOffsetTexture:{value:new nr(64,1)}},vertexShader:`
3428
+ `;class Pr extends le{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new n.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new Mt},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new Ze},attributesArray:{value:new Lt},materialIndexAttribute:{value:new He},materials:{value:new jt},textures:{value:new Me().texture},lights:{value:new Ht},iesProfiles:{value:new Me(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new Et},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new n.Matrix4},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new tr},stratifiedOffsetTexture:{value:new nr(64,1)}},vertexShader:`
3429
3429
 
3430
3430
  varying vec2 vUv;
3431
3431
  void main() {
@@ -3468,7 +3468,7 @@ bool bvhIntersectFogVolumeHit(
3468
3468
  #elif RANDOM_TYPE == 1 // Sobol
3469
3469
 
3470
3470
  ${De}
3471
- ${Ge}
3471
+ ${Ve}
3472
3472
  ${St}
3473
3473
 
3474
3474
  #define rand(v) sobol(v)
@@ -3596,10 +3596,10 @@ bool bvhIntersectFogVolumeHit(
3596
3596
  }
3597
3597
 
3598
3598
  ${Dr}
3599
- ${Mr}
3600
- ${Pr}
3601
- ${Fr}
3602
3599
  ${Ar}
3600
+ ${Er}
3601
+ ${Fr}
3602
+ ${Mr}
3603
3603
  ${Cr}
3604
3604
 
3605
3605
  void main() {
@@ -3892,7 +3892,7 @@ bool bvhIntersectFogVolumeHit(
3892
3892
 
3893
3893
  }
3894
3894
 
3895
- `}),this.setValues(e)}}function*kr(){const{_renderer:s,_fsQuad:e,_blendQuad:t,_primaryTarget:r,_blendTargets:i,_sobolTarget:o,_subframe:a,alpha:c,material:h}=this,m=new n.Vector4,d=new n.Vector4,f=t.material;let[l,y]=i;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NoBlending,h.opacity=1):(h.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NormalBlending);const[p,v,u,g]=a,x=r.width,b=r.height;h.resolution.set(x*u,b*g),h.sobolTexture=o.texture,h.stratifiedTexture.init(20,h.bounces+h.transmissiveBounces+5),h.stratifiedTexture.next(),h.seed++;const w=this.tiles.x||1,R=this.tiles.y||1,_=w*R,F=Math.ceil(x*u),X=Math.ceil(b*g),ue=Math.floor(p*x),fe=Math.floor(v*b),Q=Math.ceil(F/w),K=Math.ceil(X/R);for(let W=0;W<R;W++)for(let L=0;L<w;L++){const he=s.getRenderTarget(),je=s.autoClear,Ye=s.getScissorTest();s.getScissor(m),s.getViewport(d);let Z=L,de=W;if(!this.stableTiles){const J=this._currentTile%(w*R);Z=J%w,de=~~(J/w),this._currentTile=J+1}const me=R-de-1;r.scissor.set(ue+Z*Q,fe+me*K,Math.min(Q,F-Z*Q),Math.min(K,X-me*K)),r.viewport.set(ue,fe,F,X),s.setRenderTarget(r),s.setScissorTest(!0),s.autoClear=!1,e.render(s),s.setViewport(d),s.setScissor(m),s.setScissorTest(Ye),s.setRenderTarget(he),s.autoClear=je,c&&(f.target1=l.texture,f.target2=r.texture,s.setRenderTarget(y),t.render(s),s.setRenderTarget(he)),this.samples+=1/_,L===w-1&&W===R-1&&(this.samples=Math.round(this.samples)),yield}[l,y]=[y,l]}}const Pe=new n.Color;class Ee{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener("recompilation",this._compileFunction),e.addEventListener("recompilation",this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new n.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new n.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new N.FullScreenQuad(new Er),this._blendQuad=new N.FullScreenQuad(new Rt),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Ft().generate(e),this._primaryTarget=new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),this._blendTargets=[new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter})],this._compileFunction=()=>{const t=this.compileMaterial(this._fsQuad._mesh);t.then(()=>{this._compilePromise===t&&(this._compilePromise=null)}),this._compilePromise=t},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){const{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let r=0;e.projectionMatrix.elements[15]>0&&(r=1),e.isEquirectCamera&&(r=2),t.setDefine("CAMERA_TYPE",r),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){const{_renderer:e,_primaryTarget:t,_blendTargets:r}=this,i=e.getRenderTarget(),o=e.getClearAlpha();e.getClearColor(Pe),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Pe,o),e.setRenderTarget(i),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=kr.call(this)),this._task.next())}}const D=new n.Vector2,ke=new n.Vector2,$=new n.Spherical,j=new n.Color;class Or extends n.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,n.RGBAFormat,n.FloatType,n.EquirectangularReflectionMapping,n.RepeatWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;const{data:e,width:t,height:r}=this.image;for(let i=0;i<t;i++)for(let o=0;o<r;o++){ke.set(t,r),D.set(i/t,o/r),D.x-=.5,D.y=1-D.y,$.theta=D.x*2*Math.PI,$.phi=D.y*Math.PI,$.radius=1,this.generationCallback($,D,ke,j);const c=4*(o*t+i);e[c+0]=j.r,e[c+1]=j.g,e[c+2]=j.b,e[c+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}}const Oe=new n.Vector3;class Nr extends Or{constructor(e=512){super(e,e),this.topColor=new n.Color().set(16777215),this.bottomColor=new n.Color().set(0),this.exponent=2,this.generationCallback=(t,r,i,o)=>{Oe.setFromSpherical(t);const a=Oe.y*.5+.5;o.lerpColors(this.bottomColor,this.topColor,a**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}}class Br extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
3895
+ `}),this.setValues(e)}}function*Or(){const{_renderer:s,_fsQuad:e,_blendQuad:t,_primaryTarget:r,_blendTargets:i,_sobolTarget:o,_subframe:a,alpha:c,material:f}=this,m=new n.Vector4,d=new n.Vector4,h=t.material;let[l,y]=i;for(;;){c?(h.opacity=this._opacityFactor/(this.samples+1),f.blending=n.NoBlending,f.opacity=1):(f.opacity=this._opacityFactor/(this.samples+1),f.blending=n.NormalBlending);const[p,v,u,g]=a,x=r.width,b=r.height;f.resolution.set(x*u,b*g),f.sobolTexture=o.texture,f.stratifiedTexture.init(20,f.bounces+f.transmissiveBounces+5),f.stratifiedTexture.next(),f.seed++;const w=this.tiles.x||1,R=this.tiles.y||1,A=w*R,M=Math.ceil(x*u),Q=Math.ceil(b*g),ue=Math.floor(p*x),fe=Math.floor(v*b),X=Math.ceil(M/w),K=Math.ceil(Q/R);for(let L=0;L<R;L++)for(let U=0;U<w;U++){const he=s.getRenderTarget(),je=s.autoClear,Ye=s.getScissorTest();s.getScissor(m),s.getViewport(d);let Z=U,de=L;if(!this.stableTiles){const J=this._currentTile%(w*R);Z=J%w,de=~~(J/w),this._currentTile=J+1}const me=R-de-1;r.scissor.set(ue+Z*X,fe+me*K,Math.min(X,M-Z*X),Math.min(K,Q-me*K)),r.viewport.set(ue,fe,M,Q),s.setRenderTarget(r),s.setScissorTest(!0),s.autoClear=!1,e.render(s),s.setViewport(d),s.setScissor(m),s.setScissorTest(Ye),s.setRenderTarget(he),s.autoClear=je,c&&(h.target1=l.texture,h.target2=r.texture,s.setRenderTarget(y),t.render(s),s.setRenderTarget(he)),this.samples+=1/A,U===w-1&&L===R-1&&(this.samples=Math.round(this.samples)),yield}[l,y]=[y,l]}}const Ee=new n.Color;class Pe{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener("recompilation",this._compileFunction),e.addEventListener("recompilation",this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new n.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new n.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new N.FullScreenQuad(new Pr),this._blendQuad=new N.FullScreenQuad(new Rt),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Ft().generate(e),this._primaryTarget=new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),this._blendTargets=[new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter})],this._compileFunction=()=>{const t=this.compileMaterial(this._fsQuad._mesh);t.then(()=>{this._compilePromise===t&&(this._compilePromise=null)}),this._compilePromise=t},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){const{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let r=0;e.projectionMatrix.elements[15]>0&&(r=1),e.isEquirectCamera&&(r=2),t.setDefine("CAMERA_TYPE",r),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){const{_renderer:e,_primaryTarget:t,_blendTargets:r}=this,i=e.getRenderTarget(),o=e.getClearAlpha();e.getClearColor(Ee),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Ee,o),e.setRenderTarget(i),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=Or.call(this)),this._task.next())}}const P=new n.Vector2,Oe=new n.Vector2,j=new n.Spherical,Y=new n.Color;class Nr extends n.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,n.RGBAFormat,n.FloatType,n.EquirectangularReflectionMapping,n.RepeatWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;const{data:e,width:t,height:r}=this.image;for(let i=0;i<t;i++)for(let o=0;o<r;o++){Oe.set(t,r),P.set(i/t,o/r),P.x-=.5,P.y=1-P.y,j.theta=P.x*2*Math.PI,j.phi=P.y*Math.PI,j.radius=1,this.generationCallback(j,P,Oe,Y);const c=4*(o*t+i);e[c+0]=Y.r,e[c+1]=Y.g,e[c+2]=Y.b,e[c+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}}const Ne=new n.Vector3;class kr extends Nr{constructor(e=512){super(e,e),this.topColor=new n.Color().set(16777215),this.bottomColor=new n.Color().set(0),this.exponent=2,this.generationCallback=(t,r,i,o)=>{Ne.setFromSpherical(t);const a=Ne.y*.5+.5;o.lerpColors(this.bottomColor,this.topColor,a**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}}class Br extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
3896
3896
  varying vec2 vUv;
3897
3897
  void main() {
3898
3898
 
@@ -3974,4 +3974,28 @@ bool bvhIntersectFogVolumeHit(
3974
3974
  rayDirection.x *= flipEnvMap;
3975
3975
  gl_FragColor = textureCube( envMap, rayDirection );
3976
3976
 
3977
- }`}),this.depthWrite=!1,this.depthTest=!1}}class Ne{constructor(e){this._renderer=e,this._quad=new N.FullScreenQuad(new zr)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const i=e.images[0],o=this._renderer,a=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);const c=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),h=i.height,m=Math.log2(h)-2,d=1/h,f=1/(3*Math.max(Math.pow(2,m),112));a.material.defines.CUBEUV_MAX_MIP=`${m}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=f,a.material.defines.CUBEUV_TEXEL_HEIGHT=d,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;const l=o.getRenderTarget(),y=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),a.render(o),o.setRenderTarget(l),o.autoClear=y;const p=new Uint16Array(t*r*4),v=new Float32Array(t*r*4);o.readRenderTargetPixels(c,0,0,t,r,v),c.dispose();for(let g=0,x=v.length;g<x;g++)p[g]=n.DataUtils.toHalfFloat(v[g]);const u=new n.DataTexture(p,t,r,n.RGBAFormat,n.HalfFloatType);return u.minFilter=n.LinearMipMapLinearFilter,u.magFilter=n.LinearFilter,u.wrapS=n.RepeatWrapping,u.wrapT=n.RepeatWrapping,u.mapping=n.EquirectangularReflectionMapping,u.needsUpdate=!0,u}dispose(){this._quad.dispose()}}function Hr(s){return s.extensions.get("EXT_float_blend")}const k=new n.Vector2;class Wr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new wt,this._pathTracer=new Ee(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Ee(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new N.FullScreenQuad(new Br({map:null,transparent:!0,blending:n.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new n.Vector2(1024,1024),this.rasterizeSceneCallback=(t,r)=>{this._renderer.render(t,r)},this.renderToCanvasCallback=(t,r,i)=>{const o=r.autoClear;r.autoClear=!1,i.render(r),r.autoClear=o},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,r={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const i=this._generator;if(i.setObjects(e),this._buildAsync)return i.generateAsync(r.onProgress).then(o=>this._updateFromResults(e,t,o));{const o=i.generate();return this._updateFromResults(e,t,o)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,r=this._materials,i=this.textureSize,o=Gt(r);e.textures.setTextures(t,o,i.x,i.y),e.materials.updateFrom(r,o),this.reset()}updateLights(){const e=this.scene,t=this._renderer,r=this._pathTracer.material,i=qt(e),o=Vt(i);r.lights.updateFrom(i,o),r.iesProfiles.setTextures(t,o),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Nr(16);const r=this._colorBackground;r.topColor.equals(e.background)||(r.topColor.set(e.background),r.bottomColor.set(e.background),r.update()),t.backgroundMap=r,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const r=new Ne(this._renderer).generate(e.background);this._internalBackground=r,t.backgroundMap=r,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const r=new Ne(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(r)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,r){const{materials:i,geometry:o,bvh:a,bvhChanged:c}=r;this._materials=i;const m=this._pathTracer.material;return c&&(m.bvh.updateFrom(a),m.attributesArray.updateFrom(o.attributes.normal,o.attributes.tangent,o.attributes.uv,o.attributes.color),m.materialIndexAttribute.updateFrom(o.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),r}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,o=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,o.material.opacity=0,i.start());const a=i.getDelta()*1e3,c=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Hr(r),e.alpha=t.alpha,this.renderToCanvas){const h=this._renderer,m=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?o.material.opacity=Math.min(o.material.opacity+a/this.fadeDuration,1):o.material.opacity=1),!this.enablePathTracing||this.samples<m||o.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const d=o.material.opacity;o.material.opacity=1-o.material.opacity,o.material.map=e.target.texture,o.render(h),o.material.opacity=d}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&o.material.opacity>0&&(o.material.opacity<1&&(o.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),o.material.map=t.target.texture,this.renderToCanvasCallback(t.target,h,o),o.material.blending=n.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(k);const e=Math.floor(this.renderScale*k.x),t=Math.floor(this.renderScale*k.y);if(this._pathTracer.getSize(k),k.x!==e||k.y!==t){const r=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*r),Math.floor(t*r))}}}}function Be(s){return typeof s=="object"&&s!==null&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}function z(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}const Y=class Y{constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.convertedEnvTexture=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new T.TypedEventEmitter,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:.5,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var i;const r=[];e.traverse(o=>{var a;(a=o.userData)!=null&&a[T.CONTACT_SHADOW_HELPER_FLAG]&&o.visible&&r.push(o)}),r.forEach(o=>o.visible=!1);try{(i=this.pathTracer)==null||i.setScene(e,t)}finally{r.forEach(o=>o.visible=!0)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let h=0;h<o.data.length;h++)a[h]=o.data[h]/255;const c=new B.DataTexture(a,r.width,r.height,B.RGBAFormat,B.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=z(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Wr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;const t=z(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.resumable=e==="completed",this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return Be(e)&&(r=e.getInternalRenderer()),Be(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.isCubeTexture){const h=i.environment;i.environment=c;try{this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0}finally{i.environment=h}}else if(c&&c.mapping===B.EquirectangularReflectionMapping){let h=c;if(c.image instanceof HTMLImageElement)if(this.convertedEnvTexture)h=this.convertedEnvTexture;else{const d=this.convertToDataTexture(c);if(!d)throw new Error("Failed to convert environment texture to DataTexture");this.convertedEnvTexture=d,h=d}const m=i.environment;i.environment=h;try{const d=c.image;d&&!("data"in d&&d.data)&&d instanceof HTMLImageElement&&!d.complete&&await new Promise(f=>{d.onload=()=>{c.needsUpdate=!0,f()},d.onerror=()=>{f()},d.complete&&f()}),this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0,i.environment=m}catch(d){throw i.environment=m,d}}else if(((a=i.environment)==null?void 0:a.mapping)===B.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o,a;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(c){console.warn("Failed to update lights for path tracing:",c)}const i=e.render(t,r);return i.ok?performance.now()-this.lastCameraMoveTime<Y.CAMERA_SETTLE_MS?T.Result.ok(void 0):(this.cameraDirty&&(this.cameraDirty=!1,(a=this.pathTracer)==null||a.updateCamera()),this.accumulateOneSample(),this.sampleCount++,this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)):i}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&z(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=z(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=z(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}canResume(){return this.resumable&&this.pathTracer!==null&&!this.disposed}reset(e=!1){if(this.sampleCount=0,!!this.pathTracer){if(e){this.pathTracer.reset(),this.sceneInitialized=!1;return}this.lastCameraMoveTime=performance.now(),this.cameraDirty=!0,this.pathTracer.reset()}}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}};Y.CAMERA_SETTLE_MS=200;let oe=Y;exports.ThreePathTracingService=oe;
3977
+ }`}),this.depthWrite=!1,this.depthTest=!1}}class ke{constructor(e){this._renderer=e,this._quad=new N.FullScreenQuad(new zr)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const i=e.images[0],o=this._renderer,a=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);const c=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),f=i.height,m=Math.log2(f)-2,d=1/f,h=1/(3*Math.max(Math.pow(2,m),112));a.material.defines.CUBEUV_MAX_MIP=`${m}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=h,a.material.defines.CUBEUV_TEXEL_HEIGHT=d,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;const l=o.getRenderTarget(),y=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),a.render(o),o.setRenderTarget(l),o.autoClear=y;const p=new Uint16Array(t*r*4),v=new Float32Array(t*r*4);o.readRenderTargetPixels(c,0,0,t,r,v),c.dispose();for(let g=0,x=v.length;g<x;g++)p[g]=n.DataUtils.toHalfFloat(v[g]);const u=new n.DataTexture(p,t,r,n.RGBAFormat,n.HalfFloatType);return u.minFilter=n.LinearMipMapLinearFilter,u.magFilter=n.LinearFilter,u.wrapS=n.RepeatWrapping,u.wrapT=n.RepeatWrapping,u.mapping=n.EquirectangularReflectionMapping,u.needsUpdate=!0,u}dispose(){this._quad.dispose()}}function Hr(s){return s.extensions.get("EXT_float_blend")}const z=new n.Vector2;class Wr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new wt,this._pathTracer=new Pe(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Pe(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new N.FullScreenQuad(new Br({map:null,transparent:!0,blending:n.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new n.Vector2(1024,1024),this.rasterizeSceneCallback=(t,r)=>{this._renderer.render(t,r)},this.renderToCanvasCallback=(t,r,i)=>{const o=r.autoClear;r.autoClear=!1,i.render(r),r.autoClear=o},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,r={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const i=this._generator;if(i.setObjects(e),this._buildAsync)return i.generateAsync(r.onProgress).then(o=>this._updateFromResults(e,t,o));{const o=i.generate();return this._updateFromResults(e,t,o)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,r=this._materials,i=this.textureSize,o=Vt(r);e.textures.setTextures(t,o,i.x,i.y),e.materials.updateFrom(r,o),this.reset()}updateLights(){const e=this.scene,t=this._renderer,r=this._pathTracer.material,i=qt(e),o=Gt(i);r.lights.updateFrom(i,o),r.iesProfiles.setTextures(t,o),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new kr(16);const r=this._colorBackground;r.topColor.equals(e.background)||(r.topColor.set(e.background),r.bottomColor.set(e.background),r.update()),t.backgroundMap=r,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const r=new ke(this._renderer).generate(e.background);this._internalBackground=r,t.backgroundMap=r,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const r=new ke(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(r)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,r){const{materials:i,geometry:o,bvh:a,bvhChanged:c}=r;this._materials=i;const m=this._pathTracer.material;return c&&(m.bvh.updateFrom(a),m.attributesArray.updateFrom(o.attributes.normal,o.attributes.tangent,o.attributes.uv,o.attributes.color),m.materialIndexAttribute.updateFrom(o.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),r}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,o=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,o.material.opacity=0,i.start());const a=i.getDelta()*1e3,c=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Hr(r),e.alpha=t.alpha,this.renderToCanvas){const f=this._renderer,m=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?o.material.opacity=Math.min(o.material.opacity+a/this.fadeDuration,1):o.material.opacity=1),!this.enablePathTracing||this.samples<m||o.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const d=o.material.opacity;o.material.opacity=1-o.material.opacity,o.material.map=e.target.texture,o.render(f),o.material.opacity=d}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&o.material.opacity>0&&(o.material.opacity<1&&(o.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),o.material.map=t.target.texture,this.renderToCanvasCallback(t.target,f,o),o.material.blending=n.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(z);const e=Math.floor(this.renderScale*z.x),t=Math.floor(this.renderScale*z.y);if(this._pathTracer.getSize(z),z.x!==e||z.y!==t){const r=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*r),Math.floor(t*r))}}}}function Be(s){return typeof s=="object"&&s!==null&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}function O(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}const S=class S{constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.convertedEnvTexture=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new T.TypedEventEmitter,this.rasterFadeTarget=null,this.fadeQuad=null,this.fadeToneMapping=null,this.fadeSupported=!0,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:1,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var o;const r=[],i=[];e.traverse(a=>{var c,f;(c=a.userData)!=null&&c[T.CONTACT_SHADOW_HELPER_FLAG]&&a.visible?r.push(a):(f=a.userData)!=null&&f[T.PATH_TRACING_FLOOR_FLAG]&&!a.visible&&i.push(a)}),r.forEach(a=>a.visible=!1),i.forEach(a=>a.visible=!0);try{(o=this.pathTracer)==null||o.setScene(e,t)}finally{r.forEach(a=>a.visible=!0),i.forEach(a=>a.visible=!1)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let f=0;f<o.data.length;f++)a[f]=o.data[f]/255;const c=new I.DataTexture(a,r.width,r.height,I.RGBAFormat,I.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=O(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Wr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;const t=O(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.resumable=e==="completed",this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return Be(e)&&(r=e.getInternalRenderer()),Be(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.isCubeTexture){const f=i.environment;i.environment=c;try{this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0}finally{i.environment=f}}else if(c&&c.mapping===I.EquirectangularReflectionMapping){let f=c;if(c.image instanceof HTMLImageElement)if(this.convertedEnvTexture)f=this.convertedEnvTexture;else{const d=this.convertToDataTexture(c);if(!d)throw new Error("Failed to convert environment texture to DataTexture");this.convertedEnvTexture=d,f=d}const m=i.environment;i.environment=f;try{const d=c.image;d&&!("data"in d&&d.data)&&d instanceof HTMLImageElement&&!d.complete&&await new Promise(h=>{d.onload=()=>{c.needsUpdate=!0,h()},d.onerror=()=>{h()},d.complete&&h()}),this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0,i.environment=m}catch(d){throw i.environment=m,d}}else if(((a=i.environment)==null?void 0:a.mapping)===I.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o,a;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(c){console.warn("Failed to update lights for path tracing:",c)}const i=e.render(t,r);if(!i.ok)return i;if(performance.now()-this.lastCameraMoveTime<S.CAMERA_SETTLE_MS)return T.Result.ok(void 0);if(this.cameraDirty&&(this.cameraDirty=!1,(a=this.pathTracer)==null||a.updateCamera()),this.fadeSupported&&this.sampleCount===0&&this.runFadeStep(()=>this.captureRasterFade(e,t,r)),this.accumulateOneSample(),this.sampleCount++,this.fadeSupported&&this.sampleCount<S.FADE_SAMPLES){const c=1-this.pathTracedLayerOpacity(this.sampleCount);this.runFadeStep(()=>this.renderRasterFade(c))}return this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)}runFadeStep(e){try{e()}catch(t){console.warn("Path-tracing startup dissolve unavailable; showing samples directly:",t),this.fadeSupported=!1}}pathTracedLayerOpacity(e){const t=S.FADE_HOLD_SAMPLES,r=S.FADE_SAMPLES,i=S.FADE_PREVIEW_OPACITY,o=t+(r-t)*S.FADE_RELEASE_FRACTION;return e<o?i*S.smoothstep(t,o,e):i+(1-i)*S.smoothstep(o,r,e)}static smoothstep(e,t,r){const i=Math.min(1,Math.max(0,(r-e)/(t-e)));return i*i*(3-2*i)}captureRasterFade(e,t,r){const i=O(this.renderer)?this.renderer.getInternalRenderer():null;if(!i)return;const o=i.getDrawingBufferSize(new I.Vector2);this.rasterFadeTarget?(this.rasterFadeTarget.width!==o.x||this.rasterFadeTarget.height!==o.y)&&this.rasterFadeTarget.setSize(o.x,o.y):(this.rasterFadeTarget=new I.WebGLRenderTarget(o.x,o.y,{type:I.HalfFloatType}),this.rasterFadeTarget.texture.colorSpace=I.LinearSRGBColorSpace);const a=i.getRenderTarget();i.setRenderTarget(this.rasterFadeTarget),e.render(t,r),i.setRenderTarget(a)}renderRasterFade(e){var a,c;const t=O(this.renderer)?this.renderer.getInternalRenderer():null;if(!t||!this.rasterFadeTarget)return;(!this.fadeQuad||this.fadeToneMapping!==t.toneMapping)&&((c=(a=this.fadeQuad)==null?void 0:a.material)==null||c.dispose(),this.fadeToneMapping=t.toneMapping,this.fadeQuad=new N.FullScreenQuad(this.createFadeMaterial(t.toneMapping)));const r=this.fadeQuad.material;r.uniforms.tRaster.value=this.rasterFadeTarget.texture,r.uniforms.uOpacity.value=e;const i=t.autoClear,o=t.getRenderTarget();t.setRenderTarget(null),t.autoClear=!1;try{this.fadeQuad.render(t)}finally{t.autoClear=i,t.setRenderTarget(o)}}createFadeMaterial(e){const t={[I.LinearToneMapping]:"LINEAR_TONE_MAPPING",[I.ReinhardToneMapping]:"REINHARD_TONE_MAPPING",[I.CineonToneMapping]:"CINEON_TONE_MAPPING",[I.ACESFilmicToneMapping]:"ACES_FILMIC_TONE_MAPPING",[I.AgXToneMapping]:"AGX_TONE_MAPPING",[I.NeutralToneMapping]:"NEUTRAL_TONE_MAPPING"},r={},i=t[e];return i&&(r[i]=""),new I.ShaderMaterial({defines:r,uniforms:{tRaster:{value:null},uOpacity:{value:1}},vertexShader:`
3978
+ varying vec2 vUv;
3979
+ void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }
3980
+ `,fragmentShader:`
3981
+ uniform sampler2D tRaster;
3982
+ uniform float uOpacity;
3983
+ varying vec2 vUv;
3984
+ void main() {
3985
+ vec3 color = texture2D( tRaster, vUv ).rgb;
3986
+ #ifdef LINEAR_TONE_MAPPING
3987
+ color = LinearToneMapping( color );
3988
+ #elif defined( REINHARD_TONE_MAPPING )
3989
+ color = ReinhardToneMapping( color );
3990
+ #elif defined( CINEON_TONE_MAPPING )
3991
+ color = CineonToneMapping( color );
3992
+ #elif defined( ACES_FILMIC_TONE_MAPPING )
3993
+ color = ACESFilmicToneMapping( color );
3994
+ #elif defined( AGX_TONE_MAPPING )
3995
+ color = AgXToneMapping( color );
3996
+ #elif defined( NEUTRAL_TONE_MAPPING )
3997
+ color = NeutralToneMapping( color );
3998
+ #endif
3999
+ gl_FragColor = vec4( sRGBTransferOETF( vec4( color, 1.0 ) ).rgb, uOpacity );
4000
+ }
4001
+ `,transparent:!0,depthTest:!1,depthWrite:!1})}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&O(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=O(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=O(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}canResume(){return this.resumable&&this.pathTracer!==null&&!this.disposed}reset(e=!1){if(this.sampleCount=0,!!this.pathTracer){if(e){this.pathTracer.reset(),this.sceneInitialized=!1;return}this.lastCameraMoveTime=performance.now(),this.cameraDirty=!0,this.pathTracer.reset()}}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.fadeQuad&&(this.fadeQuad.material.dispose(),this.fadeQuad=null),this.fadeToneMapping=null,this.rasterFadeTarget&&(this.rasterFadeTarget.dispose(),this.rasterFadeTarget=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}};S.CAMERA_SETTLE_MS=200,S.FADE_SAMPLES=256,S.FADE_HOLD_SAMPLES=4,S.FADE_PREVIEW_OPACITY=.3,S.FADE_RELEASE_FRACTION=.5;let oe=S;exports.ThreePathTracingService=oe;