softbox 4.18.0 → 4.19.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
- const e=require("./ContactShadowBaker-lWQW97Cr.cjs"),t=require("./Pass-D0vYi-gB.cjs");let n=require("three");n=e.T(n,1);function r(e){switch(e){case 1:return`R`;case 2:return`RG`;case 3:return`RGBA`;case 4:return`RGBA`}throw Error()}function i(e){switch(e){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function a(e){switch(e){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}var o=class extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){let t=this.overrideItemSize,o=e.itemSize,s=e.count;if(t!==null){if(o*s%t!==0)throw Error(`VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.`);e.itemSize=t,e.count=s*o/t}let c=e.itemSize,l=e.count,u=e.normalized,d=e.array.constructor,f=d.BYTES_PER_ELEMENT,p=this._forcedType,m=c;if(p===null)switch(d){case Float32Array:p=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:p=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:p=n.IntType;break}let h,g,_,v,y=r(c);switch(p){case n.FloatType:_=1,g=i(c),u&&f===1?(v=d,y+=`8`,d===Uint8Array?h=n.UnsignedByteType:(h=n.ByteType,y+=`_SNORM`)):(v=Float32Array,y+=`32F`,h=n.FloatType);break;case n.IntType:y+=f*8+`I`,_=u?2**(d.BYTES_PER_ELEMENT*8-1):1,g=a(c),f===1?(v=Int8Array,h=n.ByteType):f===2?(v=Int16Array,h=n.ShortType):(v=Int32Array,h=n.IntType);break;case n.UnsignedIntType:y+=f*8+`UI`,_=u?2**(d.BYTES_PER_ELEMENT*8-1):1,g=a(c),f===1?(v=Uint8Array,h=n.UnsignedByteType):f===2?(v=Uint16Array,h=n.UnsignedShortType):(v=Uint32Array,h=n.UnsignedIntType);break}m===3&&(g===n.RGBAFormat||g===n.RGBAIntegerFormat)&&(m=4);let b=Math.ceil(Math.sqrt(l))||1,x=m*b*b,S=new v(x),C=e.normalized;e.normalized=!1;for(let t=0;t<l;t++){let n=m*t;S[n]=e.getX(t)/_,c>=2&&(S[n+1]=e.getY(t)/_),c>=3&&(S[n+2]=e.getZ(t)/_,m===4&&(S[n+3]=1)),c>=4&&(S[n+3]=e.getW(t)/_)}e.normalized=C,this.internalFormat=y,this.format=g,this.type=h,this.image.width=b,this.image.height=b,this.image.data=S,this.needsUpdate=!0,this.dispose(),e.itemSize=o,e.count=s}},s=class extends o{constructor(){super(),this._forcedType=n.UnsignedIntType}},c=class extends o{constructor(){super(),this._forcedType=n.FloatType}},l=class{constructor(){this.index=new s,this.position=new c,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(t){let{geometry:r}=t;if(d(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(r.attributes.position),t.indirect){let i=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(r.index)this._cachedIndexAttr=r.index.clone();else{let t=e.d(e.f(r));this._cachedIndexAttr=new n.BufferAttribute(t,1,!1)}u(r,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(r.index)}dispose(){let{index:e,position:t,bvhBounds:n,bvhContents:r}=this;e&&e.dispose(),t&&t.dispose(),n&&n.dispose(),r&&r.dispose()}};function u(e,t,n){let r=n.array,i=e.index?e.index.array:null;for(let e=0,n=t.length;e<n;e++){let n=3*e,a=3*t[e];for(let e=0;e<3;e++)r[n+e]=i?i[a+e]:a+e}}function d(t,r,i){let a=t._roots;if(a.length!==1)throw Error(`MeshBVHUniformStruct: Multi-root BVHs not supported.`);let o=a[0],s=new Uint16Array(o),c=new Uint32Array(o),l=new Float32Array(o),u=o.byteLength/32,d=2*Math.ceil(Math.sqrt(u/2)),f=new Float32Array(4*d*d),p=Math.ceil(Math.sqrt(u)),m=new Uint32Array(2*p*p);for(let t=0;t<u;t++){let n=t*32/4,r=n*2,i=e.p(n);for(let e=0;e<3;e++)f[8*t+0+e]=l[i+0+e],f[8*t+4+e]=l[i+3+e];if(e.h(r,s)){let i=e.m(r,s),a=e.g(n,c),o=e.v|i;m[t*2+0]=o,m[t*2+1]=a}else{let r=c[n+6],i=e._(n,c);m[t*2+0]=i,m[t*2+1]=r}}r.image.data=f,r.image.width=d,r.image.height=d,r.format=n.RGBAFormat,r.type=n.FloatType,r.internalFormat=`RGBA32F`,r.minFilter=n.NearestFilter,r.magFilter=n.NearestFilter,r.generateMipmaps=!1,r.needsUpdate=!0,r.dispose(),i.image.data=m,i.image.width=p,i.image.height=p,i.format=n.RGIntegerFormat,i.type=n.UnsignedIntType,i.internalFormat=`RG32UI`,i.minFilter=n.NearestFilter,i.magFilter=n.NearestFilter,i.generateMipmaps=!1,i.needsUpdate=!0,i.dispose()}var f=`
1
+ const e=require("./unwrap-CuSMMFPQ.cjs"),t=require("./Pass-D0vYi-gB.cjs");let n=require("three");n=e.j(n,1);function r(e){switch(e){case 1:return`R`;case 2:return`RG`;case 3:return`RGBA`;case 4:return`RGBA`}throw Error()}function i(e){switch(e){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function a(e){switch(e){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}var o=class extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){let t=this.overrideItemSize,o=e.itemSize,s=e.count;if(t!==null){if(o*s%t!==0)throw Error(`VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.`);e.itemSize=t,e.count=s*o/t}let c=e.itemSize,l=e.count,u=e.normalized,d=e.array.constructor,f=d.BYTES_PER_ELEMENT,p=this._forcedType,m=c;if(p===null)switch(d){case Float32Array:p=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:p=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:p=n.IntType;break}let h,g,_,v,y=r(c);switch(p){case n.FloatType:_=1,g=i(c),u&&f===1?(v=d,y+=`8`,d===Uint8Array?h=n.UnsignedByteType:(h=n.ByteType,y+=`_SNORM`)):(v=Float32Array,y+=`32F`,h=n.FloatType);break;case n.IntType:y+=f*8+`I`,_=u?2**(d.BYTES_PER_ELEMENT*8-1):1,g=a(c),f===1?(v=Int8Array,h=n.ByteType):f===2?(v=Int16Array,h=n.ShortType):(v=Int32Array,h=n.IntType);break;case n.UnsignedIntType:y+=f*8+`UI`,_=u?2**(d.BYTES_PER_ELEMENT*8-1):1,g=a(c),f===1?(v=Uint8Array,h=n.UnsignedByteType):f===2?(v=Uint16Array,h=n.UnsignedShortType):(v=Uint32Array,h=n.UnsignedIntType);break}m===3&&(g===n.RGBAFormat||g===n.RGBAIntegerFormat)&&(m=4);let b=Math.ceil(Math.sqrt(l))||1,x=m*b*b,S=new v(x),C=e.normalized;e.normalized=!1;for(let t=0;t<l;t++){let n=m*t;S[n]=e.getX(t)/_,c>=2&&(S[n+1]=e.getY(t)/_),c>=3&&(S[n+2]=e.getZ(t)/_,m===4&&(S[n+3]=1)),c>=4&&(S[n+3]=e.getW(t)/_)}e.normalized=C,this.internalFormat=y,this.format=g,this.type=h,this.image.width=b,this.image.height=b,this.image.data=S,this.needsUpdate=!0,this.dispose(),e.itemSize=o,e.count=s}},s=class extends o{constructor(){super(),this._forcedType=n.UnsignedIntType}},c=class extends o{constructor(){super(),this._forcedType=n.FloatType}},l=class{constructor(){this.index=new s,this.position=new c,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(t){let{geometry:r}=t;if(d(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(r.attributes.position),t.indirect){let i=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(r.index)this._cachedIndexAttr=r.index.clone();else{let t=e._(e.v(r));this._cachedIndexAttr=new n.BufferAttribute(t,1,!1)}u(r,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(r.index)}dispose(){let{index:e,position:t,bvhBounds:n,bvhContents:r}=this;e&&e.dispose(),t&&t.dispose(),n&&n.dispose(),r&&r.dispose()}};function u(e,t,n){let r=n.array,i=e.index?e.index.array:null;for(let e=0,n=t.length;e<n;e++){let n=3*e,a=3*t[e];for(let e=0;e<3;e++)r[n+e]=i?i[a+e]:a+e}}function d(t,r,i){let a=t._roots;if(a.length!==1)throw Error(`MeshBVHUniformStruct: Multi-root BVHs not supported.`);let o=a[0],s=new Uint16Array(o),c=new Uint32Array(o),l=new Float32Array(o),u=o.byteLength/32,d=2*Math.ceil(Math.sqrt(u/2)),f=new Float32Array(4*d*d),p=Math.ceil(Math.sqrt(u)),m=new Uint32Array(2*p*p);for(let t=0;t<u;t++){let n=t*32/4,r=n*2,i=e.y(n);for(let e=0;e<3;e++)f[8*t+0+e]=l[i+0+e],f[8*t+4+e]=l[i+3+e];if(e.x(r,s)){let i=e.b(r,s),a=e.S(n,c),o=e.w|i;m[t*2+0]=o,m[t*2+1]=a}else{let r=c[n+6],i=e.C(n,c);m[t*2+0]=i,m[t*2+1]=r}}r.image.data=f,r.image.width=d,r.image.height=d,r.format=n.RGBAFormat,r.type=n.FloatType,r.internalFormat=`RGBA32F`,r.minFilter=n.NearestFilter,r.magFilter=n.NearestFilter,r.generateMipmaps=!1,r.needsUpdate=!0,r.dispose(),i.image.data=m,i.image.width=p,i.image.height=p,i.format=n.RGIntegerFormat,i.type=n.UnsignedIntType,i.internalFormat=`RG32UI`,i.minFilter=n.NearestFilter,i.magFilter=n.NearestFilter,i.generateMipmaps=!1,i.needsUpdate=!0,i.dispose()}var f=`
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 h(e,t,n=0){if(e.isInterleavedBufferAttribute){let r=e.itemSize;for(let i=0,a=e.count;i<a;i++){let a=i+n;t.setX(a,e.getX(i)),r>=2&&t.setY(a,e.getY(i)),r>=3&&t.setZ(a,e.getZ(i)),r>=4&&t.setW(a,e.getW(i))}}else{let r=t.array,i=r.constructor,a=r.BYTES_PER_ELEMENT*e.itemSize*n;new i(r.buffer,a,e.array.length).set(e.array)}}function g(e,t=null){let r=e.array.constructor,i=e.normalized,a=e.itemSize;return new n.BufferAttribute(new r(a*(t===null?e.count:t)),a,i)}function _(e,t){if(!e&&!t)return!0;if(!!e!=!!t)return!1;let n=e.count===t.count,r=e.normalized===t.normalized,i=e.array.constructor===t.array.constructor,a=e.itemSize===t.itemSize;return!(!n||!r||!i||!a)}function v(e){let t=e[0].index!==null,n=new Set(Object.keys(e[0].attributes));if(!e[0].getAttribute(`position`))throw Error(`StaticGeometryGenerator: position attribute is required.`);for(let r=0;r<e.length;++r){let i=e[r],a=0;if(t!==(i.index!==null))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`);for(let e in i.attributes){if(!n.has(e))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`);a++}if(a!==n.size)throw Error(`StaticGeometryGenerator: All geometries must have the same number of attributes.`)}}function y(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getIndex().count;return t}function b(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getAttribute(`position`).count;return t}function x(e,t,n){e.index&&e.index.count!==t&&e.setIndex(null);let r=e.attributes;for(let t in r)r[t].count!==n&&e.deleteAttribute(t)}function S(e,t={},r=new n.BufferGeometry){let{useGroups:i=!1,forceUpdate:a=!1,skipAssigningAttributes:o=[],overwriteIndex:s=!0}=t;v(e);let c=e[0].index!==null,l=c?y(e):-1,u=b(e);if(x(r,l,u),i){let t=0;for(let n=0,i=e.length;n<i;n++){let i=e[n],a;a=c?i.getIndex().count:i.getAttribute(`position`).count,r.addGroup(t,a,n),t+=a}}if(c){let t=!1;if(r.index||(r.setIndex(new n.BufferAttribute(new Uint32Array(l),1,!1)),t=!0),t||s){let n=0,i=0,s=r.getIndex();for(let r=0,c=e.length;r<c;r++){let c=e[r],l=c.getIndex();if(!(!a&&!t&&o[r]))for(let e=0;e<l.count;++e)s.setX(n+e,l.getX(e)+i);n+=l.count,i+=c.getAttribute(`position`).count}}}let d=Object.keys(e[0].attributes);for(let t=0,n=d.length;t<n;t++){let n=!1,i=d[t];if(!r.getAttribute(i)){let t=e[0].getAttribute(i);r.setAttribute(i,g(t,u)),n=!0}let s=0,c=r.getAttribute(i);for(let t=0,r=e.length;t<r;t++){let r=e[t],l=!a&&!n&&o[t],u=r.getAttribute(i);l||h(u,c,s),s+=u.count}}}function C(e,t,r){let i=e.index,a=e.attributes.position.count,o=i?i.count:a,s=e.groups;s.length===0&&(s=[{count:o,start:0,materialIndex:0}]);let c=e.getAttribute(`materialIndex`);if(!c||c.count!==a){let t;t=r.length<=255?new Uint8Array(a):new Uint16Array(a),c=new n.BufferAttribute(t,1,!1),e.deleteAttribute(`materialIndex`),e.setAttribute(`materialIndex`,c)}let l=c.array;for(let e=0;e<s.length;e++){let n=s[e],a=n.start,c=n.count,u=Math.min(c,o-a),d=Array.isArray(t)?t[n.materialIndex]:t,f=r.indexOf(d);for(let e=0;e<u;e++){let t=a+e;i&&(t=i.getX(t)),l[t]=f}}}function w(e,t){if(!e.index){let t=e.attributes.position.count,n=Array(t);for(let e=0;e<t;e++)n[e]=e;e.setIndex(n)}if(!e.attributes.normal&&t&&t.includes(`normal`)&&e.computeVertexNormals(),!e.attributes.uv&&t&&t.includes(`uv`)){let t=e.attributes.position.count;e.setAttribute(`uv`,new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!e.attributes.uv2&&t&&t.includes(`uv2`)){let t=e.attributes.position.count;e.setAttribute(`uv2`,new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!e.attributes.tangent&&t&&t.includes(`tangent`))if(e.attributes.uv&&e.attributes.normal)e.computeTangents();else{let t=e.attributes.position.count;e.setAttribute(`tangent`,new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!e.attributes.color&&t&&t.includes(`color`)){let t=e.attributes.position.count,r=new Float32Array(t*4);r.fill(1),e.setAttribute(`color`,new n.BufferAttribute(r,4))}}function T(e){let t=0;if(e.byteLength!==0){let n=new Uint8Array(e);for(let r=0;r<e.byteLength;r++){let e=n[r];t=(t<<5)-t+e,t|=0}}return t}function E(e){let t=e.uuid,n=Object.values(e.attributes);e.index&&(n.push(e.index),t+=`index|${e.index.version}`);let r=Object.keys(n).sort();for(let e of r){let r=n[e];t+=`${e}_${r.version}|`}return t}function D(e){let t=e.skeleton;return t?(t.boneTexture||t.computeBoneTexture(),`${T(t.boneTexture.image.data.buffer)}_${t.boneTexture.uuid}`):null}var O=class{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=E(t),this.primitiveCount=n,this.skeletonHash=D(e)}didChange(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===E(t)&&this.skeletonHash===D(e)&&this.primitiveCount===n)}},k=new n.Vector3,A=new n.Vector3,j=new n.Vector3,M=new n.Vector4,N=new n.Vector3,P=new n.Vector3,ee=new n.Vector4,te=new n.Vector4,F=new n.Matrix4,I=new n.Matrix4;function ne(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;ee.fromBufferAttribute(i.attributes.skinIndex,t),te.fromBufferAttribute(i.attributes.skinWeight,t),F.elements.fill(0);for(let e=0;e<4;e++){let t=te.getComponent(e);if(t!==0){let n=ee.getComponent(e);I.multiplyMatrices(a[n].matrixWorld,o[n]),re(F,I,t)}}return F.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(F),n}function L(e,t,n,r,i){N.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(P.fromBufferAttribute(s,r),n?N.addScaledVector(P,o):N.addScaledVector(P.sub(i),o))}i.add(N)}function re(e,t,n){let r=e.elements,i=t.elements;for(let e=0,t=i.length;e<t;e++)r[e]+=i[e]*n}function ie(e){let{index:t,attributes:n}=e;if(t)for(let e=0,n=t.count;e<n;e+=3){let n=t.getX(e),r=t.getX(e+2);t.setX(e,r),t.setX(e+2,n)}else for(let e in n){let t=n[e],r=t.itemSize;for(let e=0,n=t.count;e<n;e+=3)for(let n=0;n<r;n++){let r=t.getComponent(e,n),i=t.getComponent(e+2,n);t.setComponent(e,n,i),t.setComponent(e+2,n,r)}}return e}function ae(e,t={},r=new n.BufferGeometry){t={applyWorldTransforms:!0,attributes:[],...t};let i=e.geometry,a=t.applyWorldTransforms,o=t.attributes.includes(`normal`),s=t.attributes.includes(`tangent`),c=i.attributes,l=r.attributes;for(let e in r.attributes)(!t.attributes.includes(e)||!(e in i.attributes))&&r.deleteAttribute(e);!r.index&&i.index&&(r.index=i.index.clone()),l.position||r.setAttribute(`position`,g(c.position)),o&&!l.normal&&c.normal&&r.setAttribute(`normal`,g(c.normal)),s&&!l.tangent&&c.tangent&&r.setAttribute(`tangent`,g(c.tangent)),_(i.index,r.index),_(c.position,l.position),o&&_(c.normal,l.normal),s&&_(c.tangent,l.tangent);let u=c.position,d=o?c.normal:null,f=s?c.tangent:null,p=i.morphAttributes.position,m=i.morphAttributes.normal,v=i.morphAttributes.tangent,y=i.morphTargetsRelative,b=e.morphTargetInfluences,x=new n.Matrix3;x.getNormalMatrix(e.matrixWorld),i.index&&r.index.array.set(i.index.array);for(let t=0,n=c.position.count;t<n;t++)k.fromBufferAttribute(u,t),d&&A.fromBufferAttribute(d,t),f&&(M.fromBufferAttribute(f,t),j.fromBufferAttribute(f,t)),b&&(p&&L(p,b,y,t,k),m&&L(m,b,y,t,A),v&&L(v,b,y,t,j)),e.isSkinnedMesh&&(e.applyBoneTransform(t,k),d&&ne(e,t,A),f&&ne(e,t,j)),a&&k.applyMatrix4(e.matrixWorld),l.position.setXYZ(t,k.x,k.y,k.z),d&&(a&&A.applyNormalMatrix(x),l.normal.setXYZ(t,A.x,A.y,A.z)),f&&(a&&j.transformDirection(e.matrixWorld),l.tangent.setXYZW(t,j.x,j.y,j.z,M.w));for(let e in t.attributes){let n=t.attributes[e];n===`position`||n===`tangent`||n===`normal`||!(n in c)||(l[n]||r.setAttribute(n,g(c[n])),_(c[n],l[n]),h(c[n],l[n]))}return e.matrixWorld.determinant()<0&&ie(r),r}var oe=class extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new O}isCompatible(e,t){let n=e.geometry;for(let e=0;e<t.length;e++){let r=t[e],i=n.attributes[r],a=this.attributes[r];if(i&&!_(i,a))return!1}return!0}updateFrom(e,t){let n=this._diff;return n.didChange(e)?(ae(e,t,this),n.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}};function se(e,t){for(let n=0,r=e.length;n<r;n++)e[n].traverseVisible(e=>{e.isMesh&&t(e)})}function ce(e){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];Array.isArray(r.material)?t.push(...r.material):t.push(r.material)}return t}function le(e,t,r){if(e.length===0){t.setIndex(null);let e=t.attributes;for(let n in e)t.deleteAttribute(n);for(let e in r.attributes)t.setAttribute(r.attributes[e],new n.BufferAttribute(new Float32Array,4,!1))}else S(e,r,t);for(let e in t.attributes)t.attributes[e].needsUpdate=!0}var ue=class{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){let 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(){let e=[];return se(this.objects,t=>{e.push(t)}),e.sort((e,t)=>e.uuid>t.uuid?1:e.uuid<t.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){let{_intermediateGeometry:e}=this,t=this._getMeshes(),n=new Set(e.keys()),r={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let i=0,a=t.length;i<a;i++){let a=t[i],o=a.uuid;n.delete(o);let s=e.get(o);(!s||!s.isCompatible(a,this.attributes))&&(s&&s.dispose(),s=new oe,e.set(o,s)),s.updateFrom(a,r)&&this.generateMissingAttributes&&w(s,this.attributes)}n.forEach(t=>{e.delete(t)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){let{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:a}=this,o=this._getMeshes(),s=[],c=[],l=a.get(e)||[];this._updateIntermediateGeometries();let u=!1;o.length!==l.length&&(u=!0);for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.get(t.uuid);c.push(n);let r=l[e];!r||r.uuid!==n.uuid?(s.push(!1),u=!0):r.version===n.version?s.push(!0):s.push(!1)}le(c,e,{useGroups:t,forceUpdate:u,skipAssigningAttributes:s,overwriteIndex:r}),u&&e.dispose(),a.set(e,c.map(e=>({version:e.version,uuid:e.uuid})));let d=0;return u?d=2:s.includes(!1)&&(d=1),{changeType:d,materials:ce(o),geometry:e}}};function de(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Array.from(t)}function fe(e){let t=[],n=new Set;for(let r=0,i=e.length;r<i;r++)e[r].traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&(t.push(e),e.iesMap&&n.add(e.iesMap))});return{lights:t,iesTextures:Array.from(n).sort((e,t)=>e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0)}}var pe=class{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 ue(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 Error(`PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.`);if(this.bvh instanceof Promise)return this._pendingGenerate||=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e))),this._pendingGenerate;{this._buildAsync=!0;let t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(t=null){let{staticGeometryGenerator:n,geometry:r,attributes:i}=this,a=n.objects;n.attributes=i,a.forEach(e=>{e.traverse(e=>{e.isSkinnedMesh&&e.skeleton&&e.skeleton.update()})});let o=n.generate(r),s=o.materials,c=de(s),{lights:l,iesTextures:u}=fe(a);if(o.changeType!==0&&C(r,s,s),this.generateBVH){if(this.bvh instanceof Promise)throw Error(`PathTracingSceneGenerator: BVH is already building asynchronously.`);if(o.changeType===2){let n={strategy:2,maxLeafTris:1,indirect:!0,onProgress:t,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,n):this.bvh=new e.u(r,n)}else o.changeType===1&&this.bvh.refit()}return{bvhChanged:o.changeType!==0,bvh:this.bvh,lights:l,iesTextures:u,geometry:r,materials:s,textures:c,objects:a}}},R=class extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:`recompilation`})}constructor(e){super(e);for(let e in this.uniforms)Object.defineProperty(this,e,{get(){return this.uniforms[e].value},set(t){this.uniforms[e].value=t}})}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}},me=class extends R{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
297
+ `;function h(e,t,n=0){if(e.isInterleavedBufferAttribute){let r=e.itemSize;for(let i=0,a=e.count;i<a;i++){let a=i+n;t.setX(a,e.getX(i)),r>=2&&t.setY(a,e.getY(i)),r>=3&&t.setZ(a,e.getZ(i)),r>=4&&t.setW(a,e.getW(i))}}else{let r=t.array,i=r.constructor,a=r.BYTES_PER_ELEMENT*e.itemSize*n;new i(r.buffer,a,e.array.length).set(e.array)}}function g(e,t=null){let r=e.array.constructor,i=e.normalized,a=e.itemSize;return new n.BufferAttribute(new r(a*(t===null?e.count:t)),a,i)}function _(e,t){if(!e&&!t)return!0;if(!!e!=!!t)return!1;let n=e.count===t.count,r=e.normalized===t.normalized,i=e.array.constructor===t.array.constructor,a=e.itemSize===t.itemSize;return!(!n||!r||!i||!a)}function v(e){let t=e[0].index!==null,n=new Set(Object.keys(e[0].attributes));if(!e[0].getAttribute(`position`))throw Error(`StaticGeometryGenerator: position attribute is required.`);for(let r=0;r<e.length;++r){let i=e[r],a=0;if(t!==(i.index!==null))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`);for(let e in i.attributes){if(!n.has(e))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`);a++}if(a!==n.size)throw Error(`StaticGeometryGenerator: All geometries must have the same number of attributes.`)}}function y(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getIndex().count;return t}function b(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getAttribute(`position`).count;return t}function x(e,t,n){e.index&&e.index.count!==t&&e.setIndex(null);let r=e.attributes;for(let t in r)r[t].count!==n&&e.deleteAttribute(t)}function S(e,t={},r=new n.BufferGeometry){let{useGroups:i=!1,forceUpdate:a=!1,skipAssigningAttributes:o=[],overwriteIndex:s=!0}=t;v(e);let c=e[0].index!==null,l=c?y(e):-1,u=b(e);if(x(r,l,u),i){let t=0;for(let n=0,i=e.length;n<i;n++){let i=e[n],a;a=c?i.getIndex().count:i.getAttribute(`position`).count,r.addGroup(t,a,n),t+=a}}if(c){let t=!1;if(r.index||(r.setIndex(new n.BufferAttribute(new Uint32Array(l),1,!1)),t=!0),t||s){let n=0,i=0,s=r.getIndex();for(let r=0,c=e.length;r<c;r++){let c=e[r],l=c.getIndex();if(!(!a&&!t&&o[r]))for(let e=0;e<l.count;++e)s.setX(n+e,l.getX(e)+i);n+=l.count,i+=c.getAttribute(`position`).count}}}let d=Object.keys(e[0].attributes);for(let t=0,n=d.length;t<n;t++){let n=!1,i=d[t];if(!r.getAttribute(i)){let t=e[0].getAttribute(i);r.setAttribute(i,g(t,u)),n=!0}let s=0,c=r.getAttribute(i);for(let t=0,r=e.length;t<r;t++){let r=e[t],l=!a&&!n&&o[t],u=r.getAttribute(i);l||h(u,c,s),s+=u.count}}}function C(e,t,r){let i=e.index,a=e.attributes.position.count,o=i?i.count:a,s=e.groups;s.length===0&&(s=[{count:o,start:0,materialIndex:0}]);let c=e.getAttribute(`materialIndex`);if(!c||c.count!==a){let t;t=r.length<=255?new Uint8Array(a):new Uint16Array(a),c=new n.BufferAttribute(t,1,!1),e.deleteAttribute(`materialIndex`),e.setAttribute(`materialIndex`,c)}let l=c.array;for(let e=0;e<s.length;e++){let n=s[e],a=n.start,c=n.count,u=Math.min(c,o-a),d=Array.isArray(t)?t[n.materialIndex]:t,f=r.indexOf(d);for(let e=0;e<u;e++){let t=a+e;i&&(t=i.getX(t)),l[t]=f}}}function w(e,t){if(!e.index){let t=e.attributes.position.count,n=Array(t);for(let e=0;e<t;e++)n[e]=e;e.setIndex(n)}if(!e.attributes.normal&&t&&t.includes(`normal`)&&e.computeVertexNormals(),!e.attributes.uv&&t&&t.includes(`uv`)){let t=e.attributes.position.count;e.setAttribute(`uv`,new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!e.attributes.uv2&&t&&t.includes(`uv2`)){let t=e.attributes.position.count;e.setAttribute(`uv2`,new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!e.attributes.tangent&&t&&t.includes(`tangent`))if(e.attributes.uv&&e.attributes.normal)e.computeTangents();else{let t=e.attributes.position.count;e.setAttribute(`tangent`,new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!e.attributes.color&&t&&t.includes(`color`)){let t=e.attributes.position.count,r=new Float32Array(t*4);r.fill(1),e.setAttribute(`color`,new n.BufferAttribute(r,4))}}function T(e){let t=0;if(e.byteLength!==0){let n=new Uint8Array(e);for(let r=0;r<e.byteLength;r++){let e=n[r];t=(t<<5)-t+e,t|=0}}return t}function E(e){let t=e.uuid,n=Object.values(e.attributes);e.index&&(n.push(e.index),t+=`index|${e.index.version}`);let r=Object.keys(n).sort();for(let e of r){let r=n[e];t+=`${e}_${r.version}|`}return t}function D(e){let t=e.skeleton;return t?(t.boneTexture||t.computeBoneTexture(),`${T(t.boneTexture.image.data.buffer)}_${t.boneTexture.uuid}`):null}var O=class{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=E(t),this.primitiveCount=n,this.skeletonHash=D(e)}didChange(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===E(t)&&this.skeletonHash===D(e)&&this.primitiveCount===n)}},k=new n.Vector3,A=new n.Vector3,j=new n.Vector3,M=new n.Vector4,N=new n.Vector3,P=new n.Vector3,ee=new n.Vector4,te=new n.Vector4,F=new n.Matrix4,I=new n.Matrix4;function ne(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;ee.fromBufferAttribute(i.attributes.skinIndex,t),te.fromBufferAttribute(i.attributes.skinWeight,t),F.elements.fill(0);for(let e=0;e<4;e++){let t=te.getComponent(e);if(t!==0){let n=ee.getComponent(e);I.multiplyMatrices(a[n].matrixWorld,o[n]),re(F,I,t)}}return F.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(F),n}function L(e,t,n,r,i){N.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(P.fromBufferAttribute(s,r),n?N.addScaledVector(P,o):N.addScaledVector(P.sub(i),o))}i.add(N)}function re(e,t,n){let r=e.elements,i=t.elements;for(let e=0,t=i.length;e<t;e++)r[e]+=i[e]*n}function ie(e){let{index:t,attributes:n}=e;if(t)for(let e=0,n=t.count;e<n;e+=3){let n=t.getX(e),r=t.getX(e+2);t.setX(e,r),t.setX(e+2,n)}else for(let e in n){let t=n[e],r=t.itemSize;for(let e=0,n=t.count;e<n;e+=3)for(let n=0;n<r;n++){let r=t.getComponent(e,n),i=t.getComponent(e+2,n);t.setComponent(e,n,i),t.setComponent(e+2,n,r)}}return e}function ae(e,t={},r=new n.BufferGeometry){t={applyWorldTransforms:!0,attributes:[],...t};let i=e.geometry,a=t.applyWorldTransforms,o=t.attributes.includes(`normal`),s=t.attributes.includes(`tangent`),c=i.attributes,l=r.attributes;for(let e in r.attributes)(!t.attributes.includes(e)||!(e in i.attributes))&&r.deleteAttribute(e);!r.index&&i.index&&(r.index=i.index.clone()),l.position||r.setAttribute(`position`,g(c.position)),o&&!l.normal&&c.normal&&r.setAttribute(`normal`,g(c.normal)),s&&!l.tangent&&c.tangent&&r.setAttribute(`tangent`,g(c.tangent)),_(i.index,r.index),_(c.position,l.position),o&&_(c.normal,l.normal),s&&_(c.tangent,l.tangent);let u=c.position,d=o?c.normal:null,f=s?c.tangent:null,p=i.morphAttributes.position,m=i.morphAttributes.normal,v=i.morphAttributes.tangent,y=i.morphTargetsRelative,b=e.morphTargetInfluences,x=new n.Matrix3;x.getNormalMatrix(e.matrixWorld),i.index&&r.index.array.set(i.index.array);for(let t=0,n=c.position.count;t<n;t++)k.fromBufferAttribute(u,t),d&&A.fromBufferAttribute(d,t),f&&(M.fromBufferAttribute(f,t),j.fromBufferAttribute(f,t)),b&&(p&&L(p,b,y,t,k),m&&L(m,b,y,t,A),v&&L(v,b,y,t,j)),e.isSkinnedMesh&&(e.applyBoneTransform(t,k),d&&ne(e,t,A),f&&ne(e,t,j)),a&&k.applyMatrix4(e.matrixWorld),l.position.setXYZ(t,k.x,k.y,k.z),d&&(a&&A.applyNormalMatrix(x),l.normal.setXYZ(t,A.x,A.y,A.z)),f&&(a&&j.transformDirection(e.matrixWorld),l.tangent.setXYZW(t,j.x,j.y,j.z,M.w));for(let e in t.attributes){let n=t.attributes[e];n===`position`||n===`tangent`||n===`normal`||!(n in c)||(l[n]||r.setAttribute(n,g(c[n])),_(c[n],l[n]),h(c[n],l[n]))}return e.matrixWorld.determinant()<0&&ie(r),r}var oe=class extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new O}isCompatible(e,t){let n=e.geometry;for(let e=0;e<t.length;e++){let r=t[e],i=n.attributes[r],a=this.attributes[r];if(i&&!_(i,a))return!1}return!0}updateFrom(e,t){let n=this._diff;return n.didChange(e)?(ae(e,t,this),n.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}};function se(e,t){for(let n=0,r=e.length;n<r;n++)e[n].traverseVisible(e=>{e.isMesh&&t(e)})}function ce(e){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];Array.isArray(r.material)?t.push(...r.material):t.push(r.material)}return t}function le(e,t,r){if(e.length===0){t.setIndex(null);let e=t.attributes;for(let n in e)t.deleteAttribute(n);for(let e in r.attributes)t.setAttribute(r.attributes[e],new n.BufferAttribute(new Float32Array,4,!1))}else S(e,r,t);for(let e in t.attributes)t.attributes[e].needsUpdate=!0}var ue=class{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){let 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(){let e=[];return se(this.objects,t=>{e.push(t)}),e.sort((e,t)=>e.uuid>t.uuid?1:e.uuid<t.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){let{_intermediateGeometry:e}=this,t=this._getMeshes(),n=new Set(e.keys()),r={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let i=0,a=t.length;i<a;i++){let a=t[i],o=a.uuid;n.delete(o);let s=e.get(o);(!s||!s.isCompatible(a,this.attributes))&&(s&&s.dispose(),s=new oe,e.set(o,s)),s.updateFrom(a,r)&&this.generateMissingAttributes&&w(s,this.attributes)}n.forEach(t=>{e.delete(t)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){let{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:a}=this,o=this._getMeshes(),s=[],c=[],l=a.get(e)||[];this._updateIntermediateGeometries();let u=!1;o.length!==l.length&&(u=!0);for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.get(t.uuid);c.push(n);let r=l[e];!r||r.uuid!==n.uuid?(s.push(!1),u=!0):r.version===n.version?s.push(!0):s.push(!1)}le(c,e,{useGroups:t,forceUpdate:u,skipAssigningAttributes:s,overwriteIndex:r}),u&&e.dispose(),a.set(e,c.map(e=>({version:e.version,uuid:e.uuid})));let d=0;return u?d=2:s.includes(!1)&&(d=1),{changeType:d,materials:ce(o),geometry:e}}};function de(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Array.from(t)}function fe(e){let t=[],n=new Set;for(let r=0,i=e.length;r<i;r++)e[r].traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&(t.push(e),e.iesMap&&n.add(e.iesMap))});return{lights:t,iesTextures:Array.from(n).sort((e,t)=>e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0)}}var pe=class{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 ue(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 Error(`PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.`);if(this.bvh instanceof Promise)return this._pendingGenerate||=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e))),this._pendingGenerate;{this._buildAsync=!0;let t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(t=null){let{staticGeometryGenerator:n,geometry:r,attributes:i}=this,a=n.objects;n.attributes=i,a.forEach(e=>{e.traverse(e=>{e.isSkinnedMesh&&e.skeleton&&e.skeleton.update()})});let o=n.generate(r),s=o.materials,c=de(s),{lights:l,iesTextures:u}=fe(a);if(o.changeType!==0&&C(r,s,s),this.generateBVH){if(this.bvh instanceof Promise)throw Error(`PathTracingSceneGenerator: BVH is already building asynchronously.`);if(o.changeType===2){let n={strategy:2,maxLeafTris:1,indirect:!0,onProgress:t,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,n):this.bvh=new e.g(r,n)}else o.changeType===1&&this.bvh.refit()}return{bvhChanged:o.changeType!==0,bvh:this.bvh,lights:l,iesTextures:u,geometry:r,materials:s,textures:c,objects:a}}},R=class extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:`recompilation`})}constructor(e){super(e);for(let e in this.uniforms)Object.defineProperty(this,e,{get(){return this.uniforms[e].value},set(t){this.uniforms[e].value=t}})}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}},me=class extends R{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
 
@@ -550,7 +550,7 @@ struct BVH {
550
550
  gl_FragColor = generateSobolPoint( index );
551
551
 
552
552
  }
553
- `})}},ye=class{generate(e,r=256){let i=new n.WebGLRenderTarget(r,r,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),a=e.getRenderTarget();e.setRenderTarget(i);let o=new t.t(new ve);return o.material.resolution.set(r,r),o.render(e),e.setRenderTarget(a),o.dispose(),i}},be=class 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}},xe=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof be?(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 V(e){let t=new Uint16Array(e.length);for(let r=0,i=e.length;r<i;++r)t[r]=n.DataUtils.toHalfFloat(e[r]);return t}function Se(e,t,n=0,r=e.length){let i=n,a=n+r-1;for(;i<a;){let n=i+a>>1;e[n]<t?i=n+1:a=n}return i-n}function Ce(e,t,n){return .2126*e+.7152*t+.0722*n}function we(e,t=n.HalfFloatType){let r=e.clone();r.source=new n.Source({...r.image});let{width:i,height:a,data:o}=r.image,s=o;if(r.type!==t){s=t===n.HalfFloatType?new Uint16Array(o.length):new Float32Array(o.length);let e;e=o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?2**(8*o.BYTES_PER_ELEMENT-1)-1:2**(8*o.BYTES_PER_ELEMENT)-1;for(let i=0,a=o.length;i<a;i++){let a=o[i];r.type===n.HalfFloatType&&(a=n.DataUtils.fromHalfFloat(o[i])),r.type!==n.FloatType&&r.type!==n.HalfFloatType&&(a/=e),t===n.HalfFloatType&&(s[i]=n.DataUtils.toHalfFloat(a))}r.image.data=s,r.type=t}if(r.flipY){let e=s;s=s.slice();for(let t=0;t<a;t++)for(let n=0;n<i;n++){let r=a-t-1,o=4*(t*i+n),c=4*(r*i+n);s[c+0]=e[o+0],s[c+1]=e[o+1],s[c+2]=e[o+2],s[c+3]=e[o+3]}r.flipY=!1,r.image.data=s}return r}var Te=class{constructor(){let e=new n.DataTexture(V(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;let t=new n.DataTexture(V(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;let r=new n.DataTexture(V(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){let t=we(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;let{width:r,height:i,data:a}=t.image,o=new Float32Array(r*i),s=new Float32Array(r*i),c=new Float32Array(i),l=new Float32Array(i),u=0,d=0;for(let e=0;e<i;e++){let t=0;for(let i=0;i<r;i++){let c=e*r+i,l=Ce(n.DataUtils.fromHalfFloat(a[4*c+0]),n.DataUtils.fromHalfFloat(a[4*c+1]),n.DataUtils.fromHalfFloat(a[4*c+2]));t+=l,u+=l,o[c]=l,s[c]=t}if(t!==0)for(let n=e*r,i=e*r+r;n<i;n++)o[n]/=t,s[n]/=t;d+=t,c[e]=t,l[e]=d}if(d!==0)for(let e=0,t=c.length;e<t;e++)c[e]/=d,l[e]/=d;let f=new Uint16Array(i),p=new Uint16Array(r*i);for(let e=0;e<i;e++){let t=Se(l,(e+1)/i);f[e]=n.DataUtils.toHalfFloat((t+.5)/i)}for(let e=0;e<i;e++)for(let t=0;t<r;t++){let i=e*r+t,a=Se(s,(t+1)/r,e*r,r);p[i]=n.DataUtils.toHalfFloat((a+.5)/r)}this.dispose();let{marginalWeights:m,conditionalWeights:h}=this;m.image={width:i,height:1,data:f},m.needsUpdate=!0,h.image={width:r,height:i,data:p},h.needsUpdate=!0,this.totalSum=u,this.map=t}},H=6,Ee=0,De=1,Oe=2,ke=3,Ae=4,U=new n.Vector3,W=new n.Vector3,je=new n.Matrix4,G=new n.Quaternion,Me=new n.Vector3,K=new n.Vector3,Ne=new n.Vector3(0,1,0),Pe=class{constructor(){let 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=[]){let n=this.tex,r=Math.max(e.length*H,1),i=Math.ceil(Math.sqrt(r));n.image.width!==i&&(n.dispose(),n.image.data=new Float32Array(i*i*4),n.image.width=i,n.image.height=i);let a=n.image.data;for(let n=0,r=e.length;n<r;n++){let r=e[n],i=n*H*4,o=0;for(let e=0;e<H*4;e++)a[i+e]=0;r.getWorldPosition(W),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z;let s=Ee;if(r.isRectAreaLight&&r.isCircular?s=De:r.isSpotLight?s=Oe:r.isDirectionalLight?s=ke:r.isPointLight&&(s=Ae),a[i+o++]=s,a[i+o++]=r.color.r,a[i+o++]=r.color.g,a[i+o++]=r.color.b,a[i+o++]=r.intensity,r.getWorldQuaternion(G),r.isRectAreaLight)U.set(r.width,0,0).applyQuaternion(G),a[i+o++]=U.x,a[i+o++]=U.y,a[i+o++]=U.z,o++,W.set(0,r.height,0).applyQuaternion(G),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z,a[i+o++]=U.cross(W).length()*(r.isCircular?Math.PI/4:1);else if(r.isSpotLight){let e=r.radius||0;Me.setFromMatrixPosition(r.matrixWorld),K.setFromMatrixPosition(r.target.matrixWorld),je.lookAt(Me,K,Ne),G.setFromRotationMatrix(je),U.set(1,0,0).applyQuaternion(G),a[i+o++]=U.x,a[i+o++]=U.y,a[i+o++]=U.z,o++,W.set(0,1,0).applyQuaternion(G),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z,a[i+o++]=Math.PI*e*e,a[i+o++]=e,a[i+o++]=r.decay,a[i+o++]=r.distance,a[i+o++]=Math.cos(r.angle),a[i+o++]=Math.cos(r.angle*(1-r.penumbra)),a[i+o++]=r.iesMap?t.indexOf(r.iesMap):-1}else if(r.isPointLight){let e=U.setFromMatrixPosition(r.matrixWorld);a[i+o++]=e.x,a[i+o++]=e.y,a[i+o++]=e.z,o++,o+=4,o+=1,a[i+o++]=r.decay,a[i+o++]=r.distance}else if(r.isDirectionalLight){let e=U.setFromMatrixPosition(r.matrixWorld),t=W.setFromMatrixPosition(r.target.matrixWorld);K.subVectors(e,t).normalize(),a[i+o++]=K.x,a[i+o++]=K.y,a[i+o++]=K.z}}this.count=e.length;let o=T(a.buffer);return this.hash===o?!1:(this.hash=o,n.needsUpdate=!0,!0)}};function Fe(e,t,n,r,i){if(t>r)throw Error();let a=e.length/t,o=e.constructor.BYTES_PER_ELEMENT*8,s=1;switch(e.constructor){case Uint8Array:case Uint16Array:case Uint32Array:s=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:s=2**(o-1)-1;break}for(let o=0;o<a;o++){let a=4*o,c=t*o;for(let o=0;o<r;o++)n[i+a+o]=t>=o+1?e[c+o]/s:0}}var Ie=class extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat=`RGBA32F`}updateAttribute(e,t){let n=this._textures[e];n.updateFrom(t);let r=n.image,i=this.image;if(r.width!==i.width||r.height!==i.height)throw Error(`FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.`);let{width:a,height:o,data:s}=i,c=a*o*4*e,l=t.itemSize;l===3&&(l=4),Fe(n.image.data,l,s,4,c),this.dispose(),this.needsUpdate=!0}setAttributes(e){let t=e[0].count,n=e.length;for(let r=0,i=n;r<i;r++)if(e[r].count!==t)throw Error(`FloatAttributeTextureArray: All attributes must have the same item count.`);let r=this._textures;for(;r.length<n;){let e=new c;r.push(e)}for(;r.length>n;)r.pop();for(let t=0,i=n;t<i;t++)r[t].updateFrom(e[t]);let i=r[0].image,a=this.image;(i.width!==a.width||i.height!==a.height||i.depth!==n)&&(a.width=i.width,a.height=i.height,a.depth=n,a.data=new Float32Array(a.width*a.height*a.depth*4));let{data:o,width:s,height:l}=a;for(let t=0,i=n;t<i;t++){let n=r[t],i=s*l*4*t,a=e[t].itemSize;a===3&&(a=4),Fe(n.image.data,a,o,4,i)}this.dispose(),this.needsUpdate=!0}},Le=class extends Ie{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,n,r){this.setAttributes([e,t,n,r])}};function q(e,t){return e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0}function J(e){return`${e.source.uuid}:${e.colorSpace}`}function Re(e){let t=new Set,n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=J(i);t.has(a)||(t.add(a),n.push(i))}return n}function ze(e){let t=e.map(e=>e.iesMap||null).filter(e=>e),n=new Set(t);return Array.from(n).sort(q)}function Be(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Re(Array.from(t)).sort(q)}function Ve(e){let t=[];return e.traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(q)}var He=45,Ue=He*4,We=class{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={}}},Ge=class 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 We}updateFrom(e,t){function r(e,t,n=-1){if(t in e&&e[t]){let n=J(e[t]);return d[n]}else return n}function i(e,t,n){return t in e?e[t]:n}function a(e,t,n,r){let i=e[t]&&e[t].isTexture?e[t]:null;if(i){i.matrixAutoUpdate&&i.updateMatrix();let e=i.matrix.elements,t=0;n[r+t++]=e[0],n[r+t++]=e[3],n[r+t++]=e[6],t++,n[r+t++]=e[1],n[r+t++]=e[4],n[r+t++]=e[7],t++}return 8}let o=0,s=e.length*He,c=Math.ceil(Math.sqrt(s))||1,{image:l,features:u}=this,d={};for(let e=0,n=t.length;e<n;e++)d[J(t[e])]=e;l.width!==c&&(this.dispose(),l.data=new Float32Array(c*c*4),l.width=c,l.height=c);let f=l.data;u.reset();for(let t=0,s=e.length;t<s;t++){let s=e[t];if(s.isFogVolumeMaterial){u.setUsed(`FOG`);for(let e=0;e<Ue;e++)f[o+e]=0;f[o+0+0]=s.color.r,f[o+0+1]=s.color.g,f[o+0+2]=s.color.b,f[o+8+3]=i(s,`emissiveIntensity`,0),f[o+12+0]=s.emissive.r,f[o+12+1]=s.emissive.g,f[o+12+2]=s.emissive.b,f[o+52+1]=s.density,f[o+52+3]=0,f[o+56+2]=4,o+=Ue;continue}f[o++]=s.color.r,f[o++]=s.color.g,f[o++]=s.color.b,f[o++]=r(s,`map`),f[o++]=i(s,`metalness`,0),f[o++]=r(s,`metalnessMap`),f[o++]=i(s,`roughness`,0),f[o++]=r(s,`roughnessMap`),f[o++]=i(s,`ior`,1.5),f[o++]=i(s,`transmission`,0),f[o++]=r(s,`transmissionMap`),f[o++]=i(s,`emissiveIntensity`,0),`emissive`in s?(f[o++]=s.emissive.r,f[o++]=s.emissive.g,f[o++]=s.emissive.b):(f[o++]=0,f[o++]=0,f[o++]=0),f[o++]=r(s,`emissiveMap`),f[o++]=r(s,`normalMap`),`normalScale`in s?(f[o++]=s.normalScale.x,f[o++]=s.normalScale.y):(f[o++]=1,f[o++]=1),f[o++]=i(s,`clearcoat`,0),f[o++]=r(s,`clearcoatMap`),f[o++]=i(s,`clearcoatRoughness`,0),f[o++]=r(s,`clearcoatRoughnessMap`),f[o++]=r(s,`clearcoatNormalMap`),`clearcoatNormalScale`in s?(f[o++]=s.clearcoatNormalScale.x,f[o++]=s.clearcoatNormalScale.y):(f[o++]=1,f[o++]=1),o++,f[o++]=i(s,`sheen`,0),`sheenColor`in s?(f[o++]=s.sheenColor.r,f[o++]=s.sheenColor.g,f[o++]=s.sheenColor.b):(f[o++]=0,f[o++]=0,f[o++]=0),f[o++]=r(s,`sheenColorMap`),f[o++]=i(s,`sheenRoughness`,0),f[o++]=r(s,`sheenRoughnessMap`),f[o++]=r(s,`iridescenceMap`),f[o++]=r(s,`iridescenceThicknessMap`),f[o++]=i(s,`iridescence`,0),f[o++]=i(s,`iridescenceIOR`,1.3);let c=i(s,`iridescenceThicknessRange`,[100,400]);f[o++]=c[0],f[o++]=c[1],`specularColor`in s?(f[o++]=s.specularColor.r,f[o++]=s.specularColor.g,f[o++]=s.specularColor.b):(f[o++]=1,f[o++]=1,f[o++]=1),f[o++]=r(s,`specularColorMap`),f[o++]=i(s,`specularIntensity`,1),f[o++]=r(s,`specularIntensityMap`);let l=i(s,`thickness`,0)===0&&i(s,`attenuationDistance`,1/0)===1/0;if(f[o++]=Number(l),o++,`attenuationColor`in s?(f[o++]=s.attenuationColor.r,f[o++]=s.attenuationColor.g,f[o++]=s.attenuationColor.b):(f[o++]=1,f[o++]=1,f[o++]=1),f[o++]=i(s,`attenuationDistance`,1/0),f[o++]=r(s,`alphaMap`),f[o++]=s.opacity,f[o++]=s.alphaTest,!l&&s.transmission>0)f[o++]=0;else switch(s.side){case n.FrontSide:f[o++]=1;break;case n.BackSide:f[o++]=-1;break;case n.DoubleSide:f[o++]=0;break}f[o++]=Number(i(s,`matte`,!1)),f[o++]=Number(i(s,`castShadow`,!0)),f[o++]=Number(s.vertexColors)|Number(s.flatShading)<<1,f[o++]=Number(s.transparent),o+=a(s,`map`,f,o),o+=a(s,`metalnessMap`,f,o),o+=a(s,`roughnessMap`,f,o),o+=a(s,`transmissionMap`,f,o),o+=a(s,`emissiveMap`,f,o),o+=a(s,`normalMap`,f,o),o+=a(s,`clearcoatMap`,f,o),o+=a(s,`clearcoatNormalMap`,f,o),o+=a(s,`clearcoatRoughnessMap`,f,o),o+=a(s,`sheenColorMap`,f,o),o+=a(s,`sheenRoughnessMap`,f,o),o+=a(s,`iridescenceMap`,f,o),o+=a(s,`iridescenceThicknessMap`,f,o),o+=a(s,`specularColorMap`,f,o),o+=a(s,`specularIntensityMap`,f,o)}let p=T(f.buffer);return this.hash===p?!1:(this.hash=p,this.needsUpdate=!0,!0)}},Ke=new n.Color;function qe(e){return e?`${e.uuid}:${e.version}`:null}function Je(e,t){for(let n in t)n in e&&(e[n]=t[n])}var Ye=class extends n.WebGLArrayRenderTarget{constructor(e,r,i){let a={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...i};super(e,r,1,a),Je(this.texture,a),this.texture.setTextures=(...e)=>{this.setTextures(...e)},this.hashes=[null];let o=new t.t(new Xe);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){let a=e.getRenderTarget(),o=e.toneMapping,s=e.getClearAlpha();e.getClearColor(Ke);let c=t.length||1;(r!==this.width||i!==this.height||this.depth!==c)&&(this.setSize(r,i,c),this.hashes=Array(c).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;let l=this.fsQuad,u=this.hashes,d=!1;for(let n=0,r=c;n<r;n++){let r=t[n],i=qe(r);r&&(u[n]!==i||r.isWebGLRenderTarget)&&(r.matrixAutoUpdate=!1,r.matrix.identity(),l.material.map=r,e.setRenderTarget(this,n),l.render(e),r.updateMatrix(),r.matrixAutoUpdate=!0,u[n]=i,d=!0)}return l.material.map=null,e.setClearColor(Ke,s),e.setRenderTarget(a),e.toneMapping=o,d}dispose(){super.dispose(),this.fsQuad.dispose()}},Xe=class 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
+ `})}},ye=class{generate(e,r=256){let i=new n.WebGLRenderTarget(r,r,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),a=e.getRenderTarget();e.setRenderTarget(i);let o=new t.t(new ve);return o.material.resolution.set(r,r),o.render(e),e.setRenderTarget(a),o.dispose(),i}},be=class 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}},xe=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof be?(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 V(e){let t=new Uint16Array(e.length);for(let r=0,i=e.length;r<i;++r)t[r]=n.DataUtils.toHalfFloat(e[r]);return t}function H(e,t,n=0,r=e.length){let i=n,a=n+r-1;for(;i<a;){let n=i+a>>1;e[n]<t?i=n+1:a=n}return i-n}function Se(e,t,n){return .2126*e+.7152*t+.0722*n}function Ce(e,t=n.HalfFloatType){let r=e.clone();r.source=new n.Source({...r.image});let{width:i,height:a,data:o}=r.image,s=o;if(r.type!==t){s=t===n.HalfFloatType?new Uint16Array(o.length):new Float32Array(o.length);let e;e=o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?2**(8*o.BYTES_PER_ELEMENT-1)-1:2**(8*o.BYTES_PER_ELEMENT)-1;for(let i=0,a=o.length;i<a;i++){let a=o[i];r.type===n.HalfFloatType&&(a=n.DataUtils.fromHalfFloat(o[i])),r.type!==n.FloatType&&r.type!==n.HalfFloatType&&(a/=e),t===n.HalfFloatType&&(s[i]=n.DataUtils.toHalfFloat(a))}r.image.data=s,r.type=t}if(r.flipY){let e=s;s=s.slice();for(let t=0;t<a;t++)for(let n=0;n<i;n++){let r=a-t-1,o=4*(t*i+n),c=4*(r*i+n);s[c+0]=e[o+0],s[c+1]=e[o+1],s[c+2]=e[o+2],s[c+3]=e[o+3]}r.flipY=!1,r.image.data=s}return r}var we=class{constructor(){let e=new n.DataTexture(V(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;let t=new n.DataTexture(V(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;let r=new n.DataTexture(V(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){let t=Ce(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;let{width:r,height:i,data:a}=t.image,o=new Float32Array(r*i),s=new Float32Array(r*i),c=new Float32Array(i),l=new Float32Array(i),u=0,d=0;for(let e=0;e<i;e++){let t=0;for(let i=0;i<r;i++){let c=e*r+i,l=Se(n.DataUtils.fromHalfFloat(a[4*c+0]),n.DataUtils.fromHalfFloat(a[4*c+1]),n.DataUtils.fromHalfFloat(a[4*c+2]));t+=l,u+=l,o[c]=l,s[c]=t}if(t!==0)for(let n=e*r,i=e*r+r;n<i;n++)o[n]/=t,s[n]/=t;d+=t,c[e]=t,l[e]=d}if(d!==0)for(let e=0,t=c.length;e<t;e++)c[e]/=d,l[e]/=d;let f=new Uint16Array(i),p=new Uint16Array(r*i);for(let e=0;e<i;e++){let t=H(l,(e+1)/i);f[e]=n.DataUtils.toHalfFloat((t+.5)/i)}for(let e=0;e<i;e++)for(let t=0;t<r;t++){let i=e*r+t,a=H(s,(t+1)/r,e*r,r);p[i]=n.DataUtils.toHalfFloat((a+.5)/r)}this.dispose();let{marginalWeights:m,conditionalWeights:h}=this;m.image={width:i,height:1,data:f},m.needsUpdate=!0,h.image={width:r,height:i,data:p},h.needsUpdate=!0,this.totalSum=u,this.map=t}},U=6,Te=0,Ee=1,De=2,Oe=3,ke=4,W=new n.Vector3,G=new n.Vector3,Ae=new n.Matrix4,K=new n.Quaternion,je=new n.Vector3,q=new n.Vector3,Me=new n.Vector3(0,1,0),Ne=class{constructor(){let 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=[]){let n=this.tex,r=Math.max(e.length*U,1),i=Math.ceil(Math.sqrt(r));n.image.width!==i&&(n.dispose(),n.image.data=new Float32Array(i*i*4),n.image.width=i,n.image.height=i);let a=n.image.data;for(let n=0,r=e.length;n<r;n++){let r=e[n],i=n*U*4,o=0;for(let e=0;e<U*4;e++)a[i+e]=0;r.getWorldPosition(G),a[i+o++]=G.x,a[i+o++]=G.y,a[i+o++]=G.z;let s=Te;if(r.isRectAreaLight&&r.isCircular?s=Ee:r.isSpotLight?s=De:r.isDirectionalLight?s=Oe:r.isPointLight&&(s=ke),a[i+o++]=s,a[i+o++]=r.color.r,a[i+o++]=r.color.g,a[i+o++]=r.color.b,a[i+o++]=r.intensity,r.getWorldQuaternion(K),r.isRectAreaLight)W.set(r.width,0,0).applyQuaternion(K),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z,o++,G.set(0,r.height,0).applyQuaternion(K),a[i+o++]=G.x,a[i+o++]=G.y,a[i+o++]=G.z,a[i+o++]=W.cross(G).length()*(r.isCircular?Math.PI/4:1);else if(r.isSpotLight){let e=r.radius||0;je.setFromMatrixPosition(r.matrixWorld),q.setFromMatrixPosition(r.target.matrixWorld),Ae.lookAt(je,q,Me),K.setFromRotationMatrix(Ae),W.set(1,0,0).applyQuaternion(K),a[i+o++]=W.x,a[i+o++]=W.y,a[i+o++]=W.z,o++,G.set(0,1,0).applyQuaternion(K),a[i+o++]=G.x,a[i+o++]=G.y,a[i+o++]=G.z,a[i+o++]=Math.PI*e*e,a[i+o++]=e,a[i+o++]=r.decay,a[i+o++]=r.distance,a[i+o++]=Math.cos(r.angle),a[i+o++]=Math.cos(r.angle*(1-r.penumbra)),a[i+o++]=r.iesMap?t.indexOf(r.iesMap):-1}else if(r.isPointLight){let e=W.setFromMatrixPosition(r.matrixWorld);a[i+o++]=e.x,a[i+o++]=e.y,a[i+o++]=e.z,o++,o+=4,o+=1,a[i+o++]=r.decay,a[i+o++]=r.distance}else if(r.isDirectionalLight){let e=W.setFromMatrixPosition(r.matrixWorld),t=G.setFromMatrixPosition(r.target.matrixWorld);q.subVectors(e,t).normalize(),a[i+o++]=q.x,a[i+o++]=q.y,a[i+o++]=q.z}}this.count=e.length;let o=T(a.buffer);return this.hash===o?!1:(this.hash=o,n.needsUpdate=!0,!0)}};function Pe(e,t,n,r,i){if(t>r)throw Error();let a=e.length/t,o=e.constructor.BYTES_PER_ELEMENT*8,s=1;switch(e.constructor){case Uint8Array:case Uint16Array:case Uint32Array:s=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:s=2**(o-1)-1;break}for(let o=0;o<a;o++){let a=4*o,c=t*o;for(let o=0;o<r;o++)n[i+a+o]=t>=o+1?e[c+o]/s:0}}var Fe=class extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat=`RGBA32F`}updateAttribute(e,t){let n=this._textures[e];n.updateFrom(t);let r=n.image,i=this.image;if(r.width!==i.width||r.height!==i.height)throw Error(`FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.`);let{width:a,height:o,data:s}=i,c=a*o*4*e,l=t.itemSize;l===3&&(l=4),Pe(n.image.data,l,s,4,c),this.dispose(),this.needsUpdate=!0}setAttributes(e){let t=e[0].count,n=e.length;for(let r=0,i=n;r<i;r++)if(e[r].count!==t)throw Error(`FloatAttributeTextureArray: All attributes must have the same item count.`);let r=this._textures;for(;r.length<n;){let e=new c;r.push(e)}for(;r.length>n;)r.pop();for(let t=0,i=n;t<i;t++)r[t].updateFrom(e[t]);let i=r[0].image,a=this.image;(i.width!==a.width||i.height!==a.height||i.depth!==n)&&(a.width=i.width,a.height=i.height,a.depth=n,a.data=new Float32Array(a.width*a.height*a.depth*4));let{data:o,width:s,height:l}=a;for(let t=0,i=n;t<i;t++){let n=r[t],i=s*l*4*t,a=e[t].itemSize;a===3&&(a=4),Pe(n.image.data,a,o,4,i)}this.dispose(),this.needsUpdate=!0}},Ie=class extends Fe{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,n,r){this.setAttributes([e,t,n,r])}};function J(e,t){return e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0}function Y(e){return`${e.source.uuid}:${e.colorSpace}`}function Le(e){let t=new Set,n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=Y(i);t.has(a)||(t.add(a),n.push(i))}return n}function Re(e){let t=e.map(e=>e.iesMap||null).filter(e=>e),n=new Set(t);return Array.from(n).sort(J)}function ze(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Le(Array.from(t)).sort(J)}function Be(e){let t=[];return e.traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(J)}var Ve=45,He=Ve*4,Ue=class{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={}}},We=class 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 Ue}updateFrom(e,t){function r(e,t,n=-1){if(t in e&&e[t]){let n=Y(e[t]);return d[n]}else return n}function i(e,t,n){return t in e?e[t]:n}function a(e,t,n,r){let i=e[t]&&e[t].isTexture?e[t]:null;if(i){i.matrixAutoUpdate&&i.updateMatrix();let e=i.matrix.elements,t=0;n[r+t++]=e[0],n[r+t++]=e[3],n[r+t++]=e[6],t++,n[r+t++]=e[1],n[r+t++]=e[4],n[r+t++]=e[7],t++}return 8}let o=0,s=e.length*Ve,c=Math.ceil(Math.sqrt(s))||1,{image:l,features:u}=this,d={};for(let e=0,n=t.length;e<n;e++)d[Y(t[e])]=e;l.width!==c&&(this.dispose(),l.data=new Float32Array(c*c*4),l.width=c,l.height=c);let f=l.data;u.reset();for(let t=0,s=e.length;t<s;t++){let s=e[t];if(s.isFogVolumeMaterial){u.setUsed(`FOG`);for(let e=0;e<He;e++)f[o+e]=0;f[o+0+0]=s.color.r,f[o+0+1]=s.color.g,f[o+0+2]=s.color.b,f[o+8+3]=i(s,`emissiveIntensity`,0),f[o+12+0]=s.emissive.r,f[o+12+1]=s.emissive.g,f[o+12+2]=s.emissive.b,f[o+52+1]=s.density,f[o+52+3]=0,f[o+56+2]=4,o+=He;continue}f[o++]=s.color.r,f[o++]=s.color.g,f[o++]=s.color.b,f[o++]=r(s,`map`),f[o++]=i(s,`metalness`,0),f[o++]=r(s,`metalnessMap`),f[o++]=i(s,`roughness`,0),f[o++]=r(s,`roughnessMap`),f[o++]=i(s,`ior`,1.5),f[o++]=i(s,`transmission`,0),f[o++]=r(s,`transmissionMap`),f[o++]=i(s,`emissiveIntensity`,0),`emissive`in s?(f[o++]=s.emissive.r,f[o++]=s.emissive.g,f[o++]=s.emissive.b):(f[o++]=0,f[o++]=0,f[o++]=0),f[o++]=r(s,`emissiveMap`),f[o++]=r(s,`normalMap`),`normalScale`in s?(f[o++]=s.normalScale.x,f[o++]=s.normalScale.y):(f[o++]=1,f[o++]=1),f[o++]=i(s,`clearcoat`,0),f[o++]=r(s,`clearcoatMap`),f[o++]=i(s,`clearcoatRoughness`,0),f[o++]=r(s,`clearcoatRoughnessMap`),f[o++]=r(s,`clearcoatNormalMap`),`clearcoatNormalScale`in s?(f[o++]=s.clearcoatNormalScale.x,f[o++]=s.clearcoatNormalScale.y):(f[o++]=1,f[o++]=1),o++,f[o++]=i(s,`sheen`,0),`sheenColor`in s?(f[o++]=s.sheenColor.r,f[o++]=s.sheenColor.g,f[o++]=s.sheenColor.b):(f[o++]=0,f[o++]=0,f[o++]=0),f[o++]=r(s,`sheenColorMap`),f[o++]=i(s,`sheenRoughness`,0),f[o++]=r(s,`sheenRoughnessMap`),f[o++]=r(s,`iridescenceMap`),f[o++]=r(s,`iridescenceThicknessMap`),f[o++]=i(s,`iridescence`,0),f[o++]=i(s,`iridescenceIOR`,1.3);let c=i(s,`iridescenceThicknessRange`,[100,400]);f[o++]=c[0],f[o++]=c[1],`specularColor`in s?(f[o++]=s.specularColor.r,f[o++]=s.specularColor.g,f[o++]=s.specularColor.b):(f[o++]=1,f[o++]=1,f[o++]=1),f[o++]=r(s,`specularColorMap`),f[o++]=i(s,`specularIntensity`,1),f[o++]=r(s,`specularIntensityMap`);let l=i(s,`thickness`,0)===0&&i(s,`attenuationDistance`,1/0)===1/0;if(f[o++]=Number(l),o++,`attenuationColor`in s?(f[o++]=s.attenuationColor.r,f[o++]=s.attenuationColor.g,f[o++]=s.attenuationColor.b):(f[o++]=1,f[o++]=1,f[o++]=1),f[o++]=i(s,`attenuationDistance`,1/0),f[o++]=r(s,`alphaMap`),f[o++]=s.opacity,f[o++]=s.alphaTest,!l&&s.transmission>0)f[o++]=0;else switch(s.side){case n.FrontSide:f[o++]=1;break;case n.BackSide:f[o++]=-1;break;case n.DoubleSide:f[o++]=0;break}f[o++]=Number(i(s,`matte`,!1)),f[o++]=Number(i(s,`castShadow`,!0)),f[o++]=Number(s.vertexColors)|Number(s.flatShading)<<1,f[o++]=Number(s.transparent),o+=a(s,`map`,f,o),o+=a(s,`metalnessMap`,f,o),o+=a(s,`roughnessMap`,f,o),o+=a(s,`transmissionMap`,f,o),o+=a(s,`emissiveMap`,f,o),o+=a(s,`normalMap`,f,o),o+=a(s,`clearcoatMap`,f,o),o+=a(s,`clearcoatNormalMap`,f,o),o+=a(s,`clearcoatRoughnessMap`,f,o),o+=a(s,`sheenColorMap`,f,o),o+=a(s,`sheenRoughnessMap`,f,o),o+=a(s,`iridescenceMap`,f,o),o+=a(s,`iridescenceThicknessMap`,f,o),o+=a(s,`specularColorMap`,f,o),o+=a(s,`specularIntensityMap`,f,o)}let p=T(f.buffer);return this.hash===p?!1:(this.hash=p,this.needsUpdate=!0,!0)}},Ge=new n.Color;function Ke(e){return e?`${e.uuid}:${e.version}`:null}function qe(e,t){for(let n in t)n in e&&(e[n]=t[n])}var Je=class extends n.WebGLArrayRenderTarget{constructor(e,r,i){let a={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...i};super(e,r,1,a),qe(this.texture,a),this.texture.setTextures=(...e)=>{this.setTextures(...e)},this.hashes=[null];let o=new t.t(new Ye);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){let a=e.getRenderTarget(),o=e.toneMapping,s=e.getClearAlpha();e.getClearColor(Ge);let c=t.length||1;(r!==this.width||i!==this.height||this.depth!==c)&&(this.setSize(r,i,c),this.hashes=Array(c).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;let l=this.fsQuad,u=this.hashes,d=!1;for(let n=0,r=c;n<r;n++){let r=t[n],i=Ke(r);r&&(u[n]!==i||r.isWebGLRenderTarget)&&(r.matrixAutoUpdate=!1,r.matrix.identity(),l.material.map=r,e.setRenderTarget(this,n),l.render(e),r.updateMatrix(),r.matrixAutoUpdate=!0,u[n]=i,d=!0)}return l.material.map=null,e.setClearColor(Ge,s),e.setRenderTarget(a),e.toneMapping=o,d}dispose(){super.dispose(),this.fsQuad.dispose()}},Ye=class 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 Ze(e,t=Math.random()){for(let n=e.length-1;n>0;n--){let r=Math.floor(t()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}var Qe=class{constructor(e,t,n=Math.random){let r=e**t,i=new Uint16Array(r),a=r;for(let e=0;e<r;e++)i[e]=e;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let e=0;e<r;e++)i[e]=e;a=0},this.reshuffle=function(){a=0},this.next=function(){let{samples:r}=this;a>=i.length&&(Ze(i,n),this.reshuffle());let o=i[a++];for(let i=0;i<t;i++)r[i]=(o%e+n())/e,o=Math.floor(o/e);return r}}},$e=class{constructor(e,t,n=Math.random){let r=0;for(let e of t)r+=e;let i=new Float32Array(r),a=[],o=0;for(let r of t){let t=new Qe(e,r,n);t.samples=new Float32Array(i.buffer,o,t.samples.length),o+=t.samples.length*4,a.push(t)}this.samples=i,this.strataCount=e,this.next=function(){for(let e of a)e.next();return i},this.reshuffle=function(){for(let e of a)e.reshuffle()},this.reset=function(){for(let e of a)e.reset()}}},et=class{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)}},tt=class 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 et,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,n=this.strata){let{image:r}=this;if(r.width===t&&r.height===e&&this.sampler!==null)return;let i=new $e(n,Array(e*t).fill(4),this.random);r.width=t,r.height=e,r.data=i.samples,this.sampler=i,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}};function nt(e,t=Math.random){for(let n=e.length-1;n>0;n--){let r=~~((t()-1e-6)*n),i=e[n];e[n]=e[r],e[r]=i}}function rt(e,t){e.fill(0);for(let n=0;n<t;n++)e[n]=1}var it=class{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(){let{score:e,binaryPattern:t}=this,n=1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==0)continue;let a=e[i];a<n&&(n=a,r=i)}return r}findCluster(){let{score:e,binaryPattern:t}=this,n=-1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==1)continue;let a=e[i];a>n&&(n=a,r=i)}return r}setSigma(e){if(e===this.sigma)return;let t=~~(Math.sqrt(20*e**2)+1),n=2*t+1,r=new Float32Array(n*n),i=e*e;for(let e=-t;e<=t;e++)for(let a=-t;a<=t;a++){let o=(t+a)*n+e+t,s=e*e+a*a;r[o]=Math.E**(-s/(2*i))}this.lookupTable=r,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(){let{binaryPattern:e,score:t,size:n}=this;t.fill(0);for(let t=0,r=e.length;t<r;t++)if(e[t]===0){let r=~~(t/n),i=t-r*n;this.updateScore(i,r,1),e[t]=1}else e[t]=0}updateScore(e,t,n){let{size:r,score:i,lookupTable:a}=this,o=this.radius,s=2*o+1;for(let c=-o;c<=o;c++)for(let l=-o;l<=o;l++){let u=a[(o+l)*s+c+o],d=e+c;d=d<0?r+d:d%r;let f=t+l;f=f<0?r+f:f%r;let p=f*r+d;i[p]+=n*u}}addPointIndex(e){this.binaryPattern[e]=1;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,-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}},at=class{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new it(1),this.savedSamples=new it(1)}generate(){let{samples:e,savedSamples:t,sigma:n,majorityPointsRatio:r,size:i}=this;e.resize(i),e.setSigma(n);let a=Math.floor(i*i*r),o=e.binaryPattern;rt(o,a),nt(o,this.random);for(let t=0,n=o.length;t<n;t++)o[t]===1&&e.addPointIndex(t);for(;;){let t=e.findCluster();e.removePointIndex(t);let n=e.findVoid();if(t===n){e.addPointIndex(t);break}e.addPointIndex(n)}let s=new Uint32Array(i*i);t.copy(e);let c;for(c=e.count-1;c>=0;){let t=e.findCluster();e.removePointIndex(t),s[t]=c,c--}let l=i*i;for(c=t.count;c<l/2;){let e=t.findVoid();t.addPointIndex(e),s[e]=c,c++}for(t.invert();c<l;){let e=t.findCluster();t.removePointIndex(e),s[e]=c,c++}return{data:s,maxValue:l}}};function ot(e){return e>=3?4:e}function st(e){switch(e){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}var ct=class 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(){let e=this.channels,t=this.size,n=new at;n.channels=e,n.size=t;let r=ot(e),i=st(r);(this.image.width!==t||i!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*r),this.format=i,this.dispose());let a=this.image.data;for(let t=0,i=e;t<i;t++){let e=n.generate(),i=e.data,o=e.maxValue;for(let e=0,n=i.length;e<n;e++){let n=i[e]/o;a[e*r+t]=n}}this.needsUpdate=!0}},lt=`
569
+ `})}};function Xe(e,t=Math.random()){for(let n=e.length-1;n>0;n--){let r=Math.floor(t()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}var Ze=class{constructor(e,t,n=Math.random){let r=e**t,i=new Uint16Array(r),a=r;for(let e=0;e<r;e++)i[e]=e;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let e=0;e<r;e++)i[e]=e;a=0},this.reshuffle=function(){a=0},this.next=function(){let{samples:r}=this;a>=i.length&&(Xe(i,n),this.reshuffle());let o=i[a++];for(let i=0;i<t;i++)r[i]=(o%e+n())/e,o=Math.floor(o/e);return r}}},Qe=class{constructor(e,t,n=Math.random){let r=0;for(let e of t)r+=e;let i=new Float32Array(r),a=[],o=0;for(let r of t){let t=new Ze(e,r,n);t.samples=new Float32Array(i.buffer,o,t.samples.length),o+=t.samples.length*4,a.push(t)}this.samples=i,this.strataCount=e,this.next=function(){for(let e of a)e.next();return i},this.reshuffle=function(){for(let e of a)e.reshuffle()},this.reset=function(){for(let e of a)e.reset()}}},$e=class{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)}},et=class 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 $e,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,n=this.strata){let{image:r}=this;if(r.width===t&&r.height===e&&this.sampler!==null)return;let i=new Qe(n,Array(e*t).fill(4),this.random);r.width=t,r.height=e,r.data=i.samples,this.sampler=i,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}};function tt(e,t=Math.random){for(let n=e.length-1;n>0;n--){let r=~~((t()-1e-6)*n),i=e[n];e[n]=e[r],e[r]=i}}function nt(e,t){e.fill(0);for(let n=0;n<t;n++)e[n]=1}var rt=class{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(){let{score:e,binaryPattern:t}=this,n=1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==0)continue;let a=e[i];a<n&&(n=a,r=i)}return r}findCluster(){let{score:e,binaryPattern:t}=this,n=-1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==1)continue;let a=e[i];a>n&&(n=a,r=i)}return r}setSigma(e){if(e===this.sigma)return;let t=~~(Math.sqrt(20*e**2)+1),n=2*t+1,r=new Float32Array(n*n),i=e*e;for(let e=-t;e<=t;e++)for(let a=-t;a<=t;a++){let o=(t+a)*n+e+t,s=e*e+a*a;r[o]=Math.E**(-s/(2*i))}this.lookupTable=r,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(){let{binaryPattern:e,score:t,size:n}=this;t.fill(0);for(let t=0,r=e.length;t<r;t++)if(e[t]===0){let r=~~(t/n),i=t-r*n;this.updateScore(i,r,1),e[t]=1}else e[t]=0}updateScore(e,t,n){let{size:r,score:i,lookupTable:a}=this,o=this.radius,s=2*o+1;for(let c=-o;c<=o;c++)for(let l=-o;l<=o;l++){let u=a[(o+l)*s+c+o],d=e+c;d=d<0?r+d:d%r;let f=t+l;f=f<0?r+f:f%r;let p=f*r+d;i[p]+=n*u}}addPointIndex(e){this.binaryPattern[e]=1;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,-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}},it=class{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new rt(1),this.savedSamples=new rt(1)}generate(){let{samples:e,savedSamples:t,sigma:n,majorityPointsRatio:r,size:i}=this;e.resize(i),e.setSigma(n);let a=Math.floor(i*i*r),o=e.binaryPattern;nt(o,a),tt(o,this.random);for(let t=0,n=o.length;t<n;t++)o[t]===1&&e.addPointIndex(t);for(;;){let t=e.findCluster();e.removePointIndex(t);let n=e.findVoid();if(t===n){e.addPointIndex(t);break}e.addPointIndex(n)}let s=new Uint32Array(i*i);t.copy(e);let c;for(c=e.count-1;c>=0;){let t=e.findCluster();e.removePointIndex(t),s[t]=c,c--}let l=i*i;for(c=t.count;c<l/2;){let e=t.findVoid();t.addPointIndex(e),s[e]=c,c++}for(t.invert();c<l;){let e=t.findCluster();t.removePointIndex(e),s[e]=c,c++}return{data:s,maxValue:l}}};function at(e){return e>=3?4:e}function ot(e){switch(e){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}var st=class 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(){let e=this.channels,t=this.size,n=new it;n.channels=e,n.size=t;let r=at(e),i=ot(r);(this.image.width!==t||i!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*r),this.format=i,this.dispose());let a=this.image.data;for(let t=0,i=e;t<i;t++){let e=n.generate(),i=e.data,o=e.maxValue;for(let e=0,n=i.length;e<n;e++){let n=i[e]/o;a[e*r+t]=n}}this.needsUpdate=!0}},ct=`
570
570
 
571
571
  struct PhysicalCamera {
572
572
 
@@ -578,7 +578,7 @@ struct BVH {
578
578
 
579
579
  };
580
580
 
581
- `,ut=`
581
+ `,lt=`
582
582
 
583
583
  struct EquirectHdrInfo {
584
584
 
@@ -590,7 +590,7 @@ struct BVH {
590
590
 
591
591
  };
592
592
 
593
- `,dt=`
593
+ `,ut=`
594
594
 
595
595
  #define RECT_AREA_LIGHT_TYPE 0
596
596
  #define CIRC_AREA_LIGHT_TYPE 1
@@ -676,7 +676,7 @@ struct BVH {
676
676
 
677
677
  }
678
678
 
679
- `,ft=`
679
+ `,dt=`
680
680
 
681
681
  struct Material {
682
682
 
@@ -883,7 +883,7 @@ struct BVH {
883
883
 
884
884
  }
885
885
 
886
- `,pt=`
886
+ `,ft=`
887
887
 
888
888
  struct SurfaceRecord {
889
889
 
@@ -945,7 +945,7 @@ struct BVH {
945
945
  vec3 color;
946
946
  };
947
947
 
948
- `,mt=`
948
+ `,pt=`
949
949
 
950
950
  // samples the the given environment map in the given direction
951
951
  vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
@@ -1012,7 +1012,7 @@ struct BVH {
1012
1012
  return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
1013
1013
 
1014
1014
  }
1015
- `,ht=`
1015
+ `,mt=`
1016
1016
 
1017
1017
  float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
1018
1018
 
@@ -1227,7 +1227,7 @@ struct BVH {
1227
1227
 
1228
1228
  }
1229
1229
 
1230
- `,gt=`
1230
+ `,ht=`
1231
1231
 
1232
1232
  vec3 sampleHemisphere( vec3 n, vec2 uv ) {
1233
1233
 
@@ -1312,7 +1312,7 @@ struct BVH {
1312
1312
  }
1313
1313
 
1314
1314
 
1315
- `,_t=`
1315
+ `,gt=`
1316
1316
 
1317
1317
  bool totalInternalReflection( float cosTheta, float eta ) {
1318
1318
 
@@ -1415,7 +1415,7 @@ struct BVH {
1415
1415
 
1416
1416
  }
1417
1417
 
1418
- `,vt=`
1418
+ `,_t=`
1419
1419
 
1420
1420
  // Fast arccos approximation used to remove banding artifacts caused by numerical errors in acos.
1421
1421
  // This is a cubic Lagrange interpolating polynomial for x = [-1, -1/2, 0, 1/2, 1].
@@ -1495,7 +1495,7 @@ struct BVH {
1495
1495
 
1496
1496
  }
1497
1497
 
1498
- `,yt=`
1498
+ `,vt=`
1499
1499
 
1500
1500
  // Finds the point where the ray intersects the plane defined by u and v and checks if this point
1501
1501
  // falls in the bounds of the rectangle on that same plane.
@@ -1556,7 +1556,7 @@ struct BVH {
1556
1556
 
1557
1557
  }
1558
1558
 
1559
- `,bt=`
1559
+ `,yt=`
1560
1560
 
1561
1561
  // add texel fetch functions for texture arrays
1562
1562
  vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
@@ -1579,7 +1579,7 @@ struct BVH {
1579
1579
 
1580
1580
  }
1581
1581
 
1582
- `,xt=`
1582
+ `,bt=`
1583
1583
 
1584
1584
  // TODO: possibly this should be renamed something related to material or path tracing logic
1585
1585
 
@@ -1694,7 +1694,7 @@ struct BVH {
1694
1694
  return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) );
1695
1695
 
1696
1696
  }
1697
- `,St=`
1697
+ `,xt=`
1698
1698
 
1699
1699
  // https://www.shadertoy.com/view/wltcRS
1700
1700
  uvec4 WHITE_NOISE_SEED;
@@ -1750,7 +1750,7 @@ struct BVH {
1750
1750
  return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu );
1751
1751
 
1752
1752
  }
1753
- `,Ct=`
1753
+ `,St=`
1754
1754
 
1755
1755
  uniform sampler2D stratifiedTexture;
1756
1756
  uniform sampler2D stratifiedOffsetTexture;
@@ -1799,7 +1799,7 @@ struct BVH {
1799
1799
 
1800
1800
  }
1801
1801
 
1802
- `,wt=`
1802
+ `,Ct=`
1803
1803
 
1804
1804
  // diffuse
1805
1805
  float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
@@ -2237,7 +2237,7 @@ struct BVH {
2237
2237
 
2238
2238
  }
2239
2239
 
2240
- `,Tt=`
2240
+ `,wt=`
2241
2241
 
2242
2242
  // returns the hit distance given the material density
2243
2243
  float intersectFogVolume( Material material, float u ) {
@@ -2258,7 +2258,7 @@ struct BVH {
2258
2258
 
2259
2259
  }
2260
2260
 
2261
- `,Et=`
2261
+ `,Tt=`
2262
2262
 
2263
2263
  // The GGX functions provide sampling and distribution information for normals as output so
2264
2264
  // in order to get probability of scatter direction the half vector must be computed and provided.
@@ -2359,7 +2359,7 @@ struct BVH {
2359
2359
 
2360
2360
  }
2361
2361
 
2362
- `,Dt=`
2362
+ `,Et=`
2363
2363
 
2364
2364
  // XYZ to sRGB color space
2365
2365
  const mat3 XYZ_TO_REC709 = mat3(
@@ -2493,7 +2493,7 @@ struct BVH {
2493
2493
 
2494
2494
  }
2495
2495
 
2496
- `,Ot=`
2496
+ `,Dt=`
2497
2497
 
2498
2498
  // See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
2499
2499
  float velvetD( float cosThetaH, float roughness ) {
@@ -2590,7 +2590,7 @@ struct BVH {
2590
2590
 
2591
2591
  }
2592
2592
 
2593
- `,kt=`
2593
+ `,Ot=`
2594
2594
 
2595
2595
  #ifndef FOG_CHECK_ITERATIONS
2596
2596
  #define FOG_CHECK_ITERATIONS 30
@@ -2651,7 +2651,7 @@ bool bvhIntersectFogVolumeHit(
2651
2651
 
2652
2652
  }
2653
2653
 
2654
- `,At=`
2654
+ `,kt=`
2655
2655
 
2656
2656
  // step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
2657
2657
  // returns true if a solid surface was hit
@@ -2828,7 +2828,7 @@ bool bvhIntersectFogVolumeHit(
2828
2828
 
2829
2829
  }
2830
2830
 
2831
- `,jt=`
2831
+ `,At=`
2832
2832
 
2833
2833
  vec3 ndcToRayOrigin( vec2 coord ) {
2834
2834
 
@@ -2911,7 +2911,7 @@ bool bvhIntersectFogVolumeHit(
2911
2911
 
2912
2912
  }
2913
2913
 
2914
- `,Mt=`
2914
+ `,jt=`
2915
2915
 
2916
2916
  vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
2917
2917
 
@@ -3007,7 +3007,7 @@ bool bvhIntersectFogVolumeHit(
3007
3007
 
3008
3008
  }
3009
3009
 
3010
- `,Nt=`
3010
+ `,Mt=`
3011
3011
 
3012
3012
  #define SKIP_SURFACE 0
3013
3013
  #define HIT_SURFACE 1
@@ -3329,7 +3329,7 @@ bool bvhIntersectFogVolumeHit(
3329
3329
  return HIT_SURFACE;
3330
3330
 
3331
3331
  }
3332
- `,Pt=`
3332
+ `,Nt=`
3333
3333
 
3334
3334
  struct Ray {
3335
3335
 
@@ -3378,7 +3378,7 @@ bool bvhIntersectFogVolumeHit(
3378
3378
 
3379
3379
  }
3380
3380
 
3381
- `,Ft=`
3381
+ `,Pt=`
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
- `,It=class extends R{onBeforeRender(){this.setDefine(`FEATURE_DOF`,this.physicalCamera.bokehSize===0?0:1),this.setDefine(`FEATURE_BACKGROUND_MAP`,+!!this.backgroundMap),this.setDefine(`FEATURE_FOG`,+!!this.materials.features.isUsed(`FOG`))}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 xe},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new l},attributesArray:{value:new Le},materialIndexAttribute:{value:new s},materials:{value:new Ge},textures:{value:new Ye().texture},lights:{value:new Pe},iesProfiles:{value:new Ye(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new Te},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 tt},stratifiedOffsetTexture:{value:new ct(64,1)}},vertexShader:`
3428
+ `,Ft=class extends R{onBeforeRender(){this.setDefine(`FEATURE_DOF`,this.physicalCamera.bokehSize===0?0:1),this.setDefine(`FEATURE_BACKGROUND_MAP`,+!!this.backgroundMap),this.setDefine(`FEATURE_FOG`,+!!this.materials.features.isUsed(`FOG`))}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 xe},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new l},attributesArray:{value:new Ie},materialIndexAttribute:{value:new s},materials:{value:new We},textures:{value:new Je().texture},lights:{value:new Ne},iesProfiles:{value:new Je(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new we},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 et},stratifiedOffsetTexture:{value:new st(64,1)}},vertexShader:`
3429
3429
 
3430
3430
  varying vec2 vUv;
3431
3431
  void main() {
@@ -3454,20 +3454,20 @@ bool bvhIntersectFogVolumeHit(
3454
3454
  ${p}
3455
3455
 
3456
3456
  // uniform structs
3457
+ ${ct}
3458
+ ${ut}
3457
3459
  ${lt}
3458
3460
  ${dt}
3459
- ${ut}
3460
3461
  ${ft}
3461
- ${pt}
3462
3462
 
3463
3463
  // random
3464
3464
  #if RANDOM_TYPE == 2 // Stratified List
3465
3465
 
3466
- ${Ct}
3466
+ ${St}
3467
3467
 
3468
3468
  #elif RANDOM_TYPE == 1 // Sobol
3469
3469
 
3470
- ${St}
3470
+ ${xt}
3471
3471
  ${he}
3472
3472
  ${_e}
3473
3473
 
@@ -3478,7 +3478,7 @@ bool bvhIntersectFogVolumeHit(
3478
3478
 
3479
3479
  #else // PCG
3480
3480
 
3481
- ${St}
3481
+ ${xt}
3482
3482
 
3483
3483
  // Using the sobol functions seems to break the the compiler on MacOS
3484
3484
  // - specifically the "sobolReverseBits" function.
@@ -3494,11 +3494,11 @@ bool bvhIntersectFogVolumeHit(
3494
3494
  #endif
3495
3495
 
3496
3496
  // common
3497
+ ${yt}
3498
+ ${gt}
3497
3499
  ${bt}
3498
3500
  ${_t}
3499
- ${xt}
3500
3501
  ${vt}
3501
- ${yt}
3502
3502
 
3503
3503
  // environment
3504
3504
  uniform EquirectHdrInfo envMapInfo;
@@ -3554,16 +3554,16 @@ bool bvhIntersectFogVolumeHit(
3554
3554
  float lightsDenom;
3555
3555
 
3556
3556
  // sampling
3557
- ${gt}
3558
- ${mt}
3559
3557
  ${ht}
3558
+ ${pt}
3559
+ ${mt}
3560
3560
 
3561
- ${kt}
3562
- ${Et}
3563
3561
  ${Ot}
3564
- ${Dt}
3565
3562
  ${Tt}
3563
+ ${Dt}
3564
+ ${Et}
3566
3565
  ${wt}
3566
+ ${Ct}
3567
3567
 
3568
3568
  float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
3569
3569
 
@@ -3595,12 +3595,12 @@ bool bvhIntersectFogVolumeHit(
3595
3595
 
3596
3596
  }
3597
3597
 
3598
+ ${Nt}
3599
+ ${At}
3598
3600
  ${Pt}
3601
+ ${kt}
3599
3602
  ${jt}
3600
- ${Ft}
3601
- ${At}
3602
3603
  ${Mt}
3603
- ${Nt}
3604
3604
 
3605
3605
  void main() {
3606
3606
 
@@ -3892,7 +3892,7 @@ bool bvhIntersectFogVolumeHit(
3892
3892
 
3893
3893
  }
3894
3894
 
3895
- `}),this.setValues(e)}};function*Lt(){let{_renderer:e,_fsQuad:t,_blendQuad:r,_primaryTarget:i,_blendTargets:a,_sobolTarget:o,_subframe:s,alpha:c,material:l}=this,u=new n.Vector4,d=new n.Vector4,f=r.material,[p,m]=a;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),l.blending=n.NoBlending,l.opacity=1):(l.opacity=this._opacityFactor/(this.samples+1),l.blending=n.NormalBlending);let[a,h,g,_]=s,v=i.width,y=i.height;l.resolution.set(v*g,y*_),l.sobolTexture=o.texture,l.stratifiedTexture.init(20,l.bounces+l.transmissiveBounces+5),l.stratifiedTexture.next(),l.seed++;let b=this.tiles.x||1,x=this.tiles.y||1,S=b*x,C=Math.ceil(v*g),w=Math.ceil(y*_),T=Math.floor(a*v),E=Math.floor(h*y),D=Math.ceil(C/b),O=Math.ceil(w/x);for(let n=0;n<x;n++)for(let a=0;a<b;a++){let o=e.getRenderTarget(),s=e.autoClear,l=e.getScissorTest();e.getScissor(u),e.getViewport(d);let h=a,g=n;if(!this.stableTiles){let e=this._currentTile%(b*x);h=e%b,g=~~(e/b),this._currentTile=e+1}let _=x-g-1;i.scissor.set(T+h*D,E+_*O,Math.min(D,C-h*D),Math.min(O,w-_*O)),i.viewport.set(T,E,C,w),e.setRenderTarget(i),e.setScissorTest(!0),e.autoClear=!1,t.render(e),e.setViewport(d),e.setScissor(u),e.setScissorTest(l),e.setRenderTarget(o),e.autoClear=s,c&&(f.target1=p.texture,f.target2=i.texture,e.setRenderTarget(m),r.render(e),e.setRenderTarget(o)),this.samples+=1/S,a===b-1&&n===x-1&&(this.samples=Math.round(this.samples)),yield}[p,m]=[m,p]}}var Rt=new n.Color,zt=class{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 t.t(new It),this._blendQuad=new t.t(new me),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new ye().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=()=>{let e=this.compileMaterial(this._fsQuad._mesh);e.then(()=>{this._compilePromise===e&&(this._compilePromise=null)}),this._compilePromise=e},this.material.addEventListener(`recompilation`,this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){let{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let n=0;e.projectionMatrix.elements[15]>0&&(n=1),e.isEquirectCamera&&(n=2),t.setDefine(`CAMERA_TYPE`,n),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(){let{_renderer:e,_primaryTarget:t,_blendTargets:n}=this,r=e.getRenderTarget(),i=e.getClearAlpha();e.getClearColor(Rt),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Rt,i),e.setRenderTarget(r),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||=Lt.call(this),this._task.next())}},Y=new n.Vector2,Bt=new n.Vector2,X=new n.Spherical,Z=new n.Color,Vt=class 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;let{data:e,width:t,height:n}=this.image;for(let r=0;r<t;r++)for(let i=0;i<n;i++){Bt.set(t,n),Y.set(r/t,i/n),Y.x-=.5,Y.y=1-Y.y,X.theta=Y.x*2*Math.PI,X.phi=Y.y*Math.PI,X.radius=1,this.generationCallback(X,Y,Bt,Z);let a=4*(i*t+r);e[a+0]=Z.r,e[a+1]=Z.g,e[a+2]=Z.b,e[a+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}},Ht=new n.Vector3,Ut=class extends Vt{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=(e,t,n,r)=>{Ht.setFromSpherical(e);let i=Ht.y*.5+.5;r.lerpColors(this.bottomColor,this.topColor,i**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}},Wt=class 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*It(){let{_renderer:e,_fsQuad:t,_blendQuad:r,_primaryTarget:i,_blendTargets:a,_sobolTarget:o,_subframe:s,alpha:c,material:l}=this,u=new n.Vector4,d=new n.Vector4,f=r.material,[p,m]=a;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),l.blending=n.NoBlending,l.opacity=1):(l.opacity=this._opacityFactor/(this.samples+1),l.blending=n.NormalBlending);let[a,h,g,_]=s,v=i.width,y=i.height;l.resolution.set(v*g,y*_),l.sobolTexture=o.texture,l.stratifiedTexture.init(20,l.bounces+l.transmissiveBounces+5),l.stratifiedTexture.next(),l.seed++;let b=this.tiles.x||1,x=this.tiles.y||1,S=b*x,C=Math.ceil(v*g),w=Math.ceil(y*_),T=Math.floor(a*v),E=Math.floor(h*y),D=Math.ceil(C/b),O=Math.ceil(w/x);for(let n=0;n<x;n++)for(let a=0;a<b;a++){let o=e.getRenderTarget(),s=e.autoClear,l=e.getScissorTest();e.getScissor(u),e.getViewport(d);let h=a,g=n;if(!this.stableTiles){let e=this._currentTile%(b*x);h=e%b,g=~~(e/b),this._currentTile=e+1}let _=x-g-1;i.scissor.set(T+h*D,E+_*O,Math.min(D,C-h*D),Math.min(O,w-_*O)),i.viewport.set(T,E,C,w),e.setRenderTarget(i),e.setScissorTest(!0),e.autoClear=!1,t.render(e),e.setViewport(d),e.setScissor(u),e.setScissorTest(l),e.setRenderTarget(o),e.autoClear=s,c&&(f.target1=p.texture,f.target2=i.texture,e.setRenderTarget(m),r.render(e),e.setRenderTarget(o)),this.samples+=1/S,a===b-1&&n===x-1&&(this.samples=Math.round(this.samples)),yield}[p,m]=[m,p]}}var Lt=new n.Color,Rt=class{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 t.t(new Ft),this._blendQuad=new t.t(new me),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new ye().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=()=>{let e=this.compileMaterial(this._fsQuad._mesh);e.then(()=>{this._compilePromise===e&&(this._compilePromise=null)}),this._compilePromise=e},this.material.addEventListener(`recompilation`,this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){let{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let n=0;e.projectionMatrix.elements[15]>0&&(n=1),e.isEquirectCamera&&(n=2),t.setDefine(`CAMERA_TYPE`,n),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(){let{_renderer:e,_primaryTarget:t,_blendTargets:n}=this,r=e.getRenderTarget(),i=e.getClearAlpha();e.getClearColor(Lt),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Lt,i),e.setRenderTarget(r),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||=It.call(this),this._task.next())}},X=new n.Vector2,zt=new n.Vector2,Z=new n.Spherical,Q=new n.Color,Bt=class 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;let{data:e,width:t,height:n}=this.image;for(let r=0;r<t;r++)for(let i=0;i<n;i++){zt.set(t,n),X.set(r/t,i/n),X.x-=.5,X.y=1-X.y,Z.theta=X.x*2*Math.PI,Z.phi=X.y*Math.PI,Z.radius=1,this.generationCallback(Z,X,zt,Q);let a=4*(i*t+r);e[a+0]=Q.r,e[a+1]=Q.g,e[a+2]=Q.b,e[a+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}},Vt=new n.Vector3,Ht=class extends Bt{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=(e,t,n,r)=>{Vt.setFromSpherical(e);let i=Vt.y*.5+.5;r.lerpColors(this.bottomColor,this.topColor,i**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}},Ut=class 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
 
@@ -3949,7 +3949,7 @@ bool bvhIntersectFogVolumeHit(
3949
3949
  #include <premultiplied_alpha_fragment>
3950
3950
 
3951
3951
  }
3952
- `}),this.setValues(e)}},Gt=class extends n.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
3952
+ `}),this.setValues(e)}},Wt=class extends n.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
3953
3953
  varying vec2 vUv;
3954
3954
  void main() {
3955
3955
 
@@ -3966,7 +3966,7 @@ bool bvhIntersectFogVolumeHit(
3966
3966
  #include <common>
3967
3967
  #include <cube_uv_reflection_fragment>
3968
3968
 
3969
- ${xt}
3969
+ ${bt}
3970
3970
 
3971
3971
  void main() {
3972
3972
 
@@ -3974,7 +3974,7 @@ bool bvhIntersectFogVolumeHit(
3974
3974
  rayDirection.x *= flipEnvMap;
3975
3975
  gl_FragColor = textureCube( envMap, rayDirection );
3976
3976
 
3977
- }`}),this.depthWrite=!1,this.depthTest=!1}},Kt=class{constructor(e){this._renderer=e,this._quad=new t.t(new Gt)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw Error(`CubeToEquirectMaterial: Source can only be cube textures.`);let i=e.images[0],a=this._renderer,o=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);let s=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),c=i.height,l=Math.log2(c)-2,u=1/c,d=1/(3*Math.max(2**l,112));o.material.defines.CUBEUV_MAX_MIP=`${l}.0`,o.material.defines.CUBEUV_TEXEL_WIDTH=d,o.material.defines.CUBEUV_TEXEL_HEIGHT=u,o.material.uniforms.envMap.value=e,o.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,o.material.needsUpdate=!0;let f=a.getRenderTarget(),p=a.autoClear;a.autoClear=!0,a.setRenderTarget(s),o.render(a),a.setRenderTarget(f),a.autoClear=p;let m=new Uint16Array(t*r*4),h=new Float32Array(t*r*4);a.readRenderTargetPixels(s,0,0,t,r,h),s.dispose();for(let e=0,t=h.length;e<t;e++)m[e]=n.DataUtils.toHalfFloat(h[e]);let g=new n.DataTexture(m,t,r,n.RGBAFormat,n.HalfFloatType);return g.minFilter=n.LinearMipMapLinearFilter,g.magFilter=n.LinearFilter,g.wrapS=n.RepeatWrapping,g.wrapT=n.RepeatWrapping,g.mapping=n.EquirectangularReflectionMapping,g.needsUpdate=!0,g}dispose(){this._quad.dispose()}};function qt(e){return e.extensions.get(`EXT_float_blend`)}var Q=new n.Vector2,Jt=class{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine(`FEATURE_MIS`,+!!e)}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 pe,this._pathTracer=new zt(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new zt(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new t.t(new Wt({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=(e,t)=>{this._renderer.render(e,t)},this.renderToCanvasCallback=(e,t,n)=>{let r=t.autoClear;t.autoClear=!1,n.render(t),t.autoClear=r},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,n={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();let r=this._generator;if(r.setObjects(e),this._buildAsync)return r.generateAsync(n.onProgress).then(n=>this._updateFromResults(e,t,n));{let n=r.generate();return this._updateFromResults(e,t,n)}}setSceneAsync(...e){this._buildAsync=!0;let t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){let e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){let e=this._pathTracer.material,t=this._renderer,n=this._materials,r=this.textureSize,i=Be(n);e.textures.setTextures(t,i,r.x,r.y),e.materials.updateFrom(n,i),this.reset()}updateLights(){let e=this.scene,t=this._renderer,n=this._pathTracer.material,r=Ve(e),i=ze(r);n.lights.updateFrom(r,i),n.iesProfiles.setTextures(t,i),this.reset()}updateEnvironment(){let e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&=(this._internalBackground.dispose(),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 Ut(16);let n=this._colorBackground;n.topColor.equals(e.background)||(n.topColor.set(e.background),n.bottomColor.set(e.background),n.update()),t.backgroundMap=n,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){let n=new Kt(this._renderer).generate(e.background);this._internalBackground=n,t.backgroundMap=n,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){let n=new Kt(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(n)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,n){let{materials:r,geometry:i,bvh:a,bvhChanged:o}=n;this._materials=r;let s=this._pathTracer.material;return o&&(s.bvh.updateFrom(a),s.attributesArray.updateFrom(i.attributes.normal,i.attributes.tangent,i.attributes.uv,i.attributes.color),s.materialIndexAttribute.updateFrom(i.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),n}renderSample(){let e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,a=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,a.material.opacity=0,i.start());let o=i.getDelta()*1e3,s=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=s&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!qt(r),e.alpha=t.alpha,this.renderToCanvas){let r=this._renderer,i=this.minSamples;if(s>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration===0?a.material.opacity=1:a.material.opacity=Math.min(a.material.opacity+o/this.fadeDuration,1)),!this.enablePathTracing||this.samples<i||a.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());let n=a.material.opacity;a.material.opacity=1-a.material.opacity,a.material.map=e.target.texture,a.render(r),a.material.opacity=n}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&a.material.opacity>0&&(a.material.opacity<1&&(a.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),a.material.map=t.target.texture,this.renderToCanvasCallback(t.target,r,a),a.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(Q);let e=Math.floor(this.renderScale*Q.x),t=Math.floor(this.renderScale*Q.y);if(this._pathTracer.getSize(Q),Q.x!==e||Q.y!==t){let n=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*n),Math.floor(t*n))}}}};function Yt(e){return typeof e==`object`&&!!e&&`getInternalRenderer`in e&&typeof e.getInternalRenderer==`function`}function $(e){return typeof e==`object`&&!!e&&`getInternalRenderer`in e&&typeof e.getInternalRenderer==`function`}var Xt=class r{ingestSceneWithoutShadowHelpers(e,t){let n=[],r=[];e.traverse(e=>{e.userData?.softboxContactShadowHelper&&e.visible?n.push(e):e.userData?.softboxPathTracingFloor&&!e.visible&&r.push(e)}),n.forEach(e=>e.visible=!1),r.forEach(e=>e.visible=!0);try{this.pathTracer?.setScene(e,t)}finally{n.forEach(e=>e.visible=!0),r.forEach(e=>e.visible=!1)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;let t=e.image,r=document.createElement(`canvas`);r.width=t.width,r.height=t.height;let i=r.getContext(`2d`);if(!i)return null;i.drawImage(t,0,0);let a=i.getImageData(0,0,r.width,r.height),o=new Float32Array(a.data.length);for(let e=0;e<a.data.length;e++)o[e]=a.data[e]/255;let s=new n.DataTexture(o,r.width,r.height,n.RGBAFormat,n.FloatType);return s.mapping=e.mapping,s.wrapS=e.wrapS,s.wrapT=e.wrapT,s.magFilter=e.magFilter,s.minFilter=e.minFilter,s.anisotropy=e.anisotropy,s.needsUpdate=!0,s}static{this.CAMERA_SETTLE_MS=200}static{this.FADE_SAMPLES=256}static{this.FADE_HOLD_SAMPLES=4}static{this.FADE_PREVIEW_OPACITY=.3}static{this.FADE_RELEASE_FRACTION=.5}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 e.x,this.rasterFadeTarget=null,this.fadeQuad=null,this.fadeToneMapping=null,this.fadeSupported=!0,this.settings={samples:300,bounces:4,transmissiveBounces:2,renderScale:1,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}async initialize(t){try{return this.renderer=t.renderer,this.enabled=t.enabled,this.isSupported()?e.S.ok(void 0):e.S.err(new e.w(`Path tracing is not supported in this environment`,e.C.PATH_TRACING_INIT_FAILED,{reason:`WebGL2 or required extensions not available`}))}catch(t){return e.S.err(new e.w(`Failed to initialize path tracing`,e.C.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return e.S.err(new e.w(`Instance is disposed`,e.C.INVALID_STATE));try{let t=$(this.renderer)?this.renderer.getInternalRenderer():null;return t?(this.pathTracer=new Jt(t),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,t.setRenderTarget(null),e.S.ok(void 0)):e.S.err(new e.w(`Renderer not ready, will retry`,e.C.RENDERER_NOT_INITIALIZED))}catch(t){return e.S.err(new e.w(`Failed to create path tracer`,e.C.PATH_TRACING_INIT_FAILED,{originalError:t}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;let e=$(this.renderer)?this.renderer.getInternalRenderer():null;e&&(e.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(t,n){if(this.disposed)return e.S.ok(void 0);let r=this.renderer;if(!r)return e.S.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(t,n);if(!this.pathTracer){let e=this.ensurePathTracerCreated(r,t,n);if(e)return e}try{let i=this.extractThreeObjects(t,n);if(!i)return e.S.err(new e.w(`Could not extract Three.js scene or camera`,e.C.INVALID_PARAMETER));let{threeScene:a,threeCamera:o}=i;if(!this.sceneInitialized){let e=await this.initializeSceneForPathTracing(r,t,n,a,o);if(e)return e}return this.sceneInitialized?this.accumulateSample(r,t,n):r.render(t,n)}catch(t){return e.S.err(new e.w(`Failed to render with path tracing`,e.C.RENDER_FAILED,{originalError:t}))}}ensurePathTracerCreated(e,t,n){this.createAttempts++;let r=this.createPathTracer();return r.ok?(this.createAttempts=0,null):this.createAttempts<this.maxCreateAttempts&&r.error?.message===`Renderer not ready, will retry`?e.render(t,n):(this.disableAfterSelfPause(`gave-up`),this.createAttempts=0,e.render(t,n))}extractThreeObjects(e,t){let n=null,r=null;return Yt(e)&&(n=e.getInternalRenderer()),Yt(t)&&(r=t.getInternalRenderer()),!n||!r?null:{threeScene:n,threeCamera:r}}async initializeSceneForPathTracing(e,t,r,i,a){try{let o=i.__originalEnvironmentTexture;if(!i.environment&&!o)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause(`gave-up`),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,o&&o.isCubeTexture){let e=i.environment;i.environment=o;try{this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0}finally{i.environment=e}}else if(o&&o.mapping===n.EquirectangularReflectionMapping){let e=o;if(o.image instanceof HTMLImageElement)if(this.convertedEnvTexture)e=this.convertedEnvTexture;else{let t=this.convertToDataTexture(o);if(!t)throw Error(`Failed to convert environment texture to DataTexture`);this.convertedEnvTexture=t,e=t}let t=i.environment;i.environment=e;try{let e=o.image;e&&!(`data`in e&&e.data)&&e instanceof HTMLImageElement&&!e.complete&&await new Promise(t=>{e.onload=()=>{o.needsUpdate=!0,t()},e.onerror=()=>{t()},e.complete&&t()}),this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0,i.environment=t}catch(e){throw i.environment=t,e}}else if(i.environment?.mapping===n.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0;else return this.disableAfterSelfPause(`gave-up`),e.render(t,r)}catch(n){return console.warn(`Scene initialization error:`,n),e.render(t,r)}return null}accumulateSample(t,n,i){if(this.sampleCount===0)try{this.pathTracer?.updateLights()}catch(e){console.warn(`Failed to update lights for path tracing:`,e)}let a=t.render(n,i);if(!a.ok)return a;if(performance.now()-this.lastCameraMoveTime<r.CAMERA_SETTLE_MS)return e.S.ok(void 0);if(this.cameraDirty&&(this.cameraDirty=!1,this.pathTracer?.updateCamera()),this.fadeSupported&&this.sampleCount===0&&this.runFadeStep(()=>this.captureRasterFade(t,n,i)),this.accumulateOneSample(),this.sampleCount++,this.fadeSupported&&this.sampleCount<r.FADE_SAMPLES){let e=1-this.pathTracedLayerOpacity(this.sampleCount);this.runFadeStep(()=>this.renderRasterFade(e))}return this.sampleCount===this.settings.samples?this.captureCompletedFrame():e.S.ok(void 0)}runFadeStep(e){try{e()}catch(e){console.warn(`Path-tracing startup dissolve unavailable; showing samples directly:`,e),this.fadeSupported=!1}}pathTracedLayerOpacity(e){let t=r.FADE_HOLD_SAMPLES,n=r.FADE_SAMPLES,i=r.FADE_PREVIEW_OPACITY,a=t+(n-t)*r.FADE_RELEASE_FRACTION;return e<a?i*r.smoothstep(t,a,e):i+(1-i)*r.smoothstep(a,n,e)}static smoothstep(e,t,n){let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)}captureRasterFade(e,t,r){let i=$(this.renderer)?this.renderer.getInternalRenderer():null;if(!i)return;let a=i.getDrawingBufferSize(new n.Vector2);this.rasterFadeTarget?(this.rasterFadeTarget.width!==a.x||this.rasterFadeTarget.height!==a.y)&&this.rasterFadeTarget.setSize(a.x,a.y):(this.rasterFadeTarget=new n.WebGLRenderTarget(a.x,a.y,{type:n.HalfFloatType}),this.rasterFadeTarget.texture.colorSpace=n.LinearSRGBColorSpace);let o=i.getRenderTarget();i.setRenderTarget(this.rasterFadeTarget),e.render(t,r),i.setRenderTarget(o)}renderRasterFade(e){let n=$(this.renderer)?this.renderer.getInternalRenderer():null;if(!n||!this.rasterFadeTarget)return;(!this.fadeQuad||this.fadeToneMapping!==n.toneMapping)&&((this.fadeQuad?.material)?.dispose(),this.fadeToneMapping=n.toneMapping,this.fadeQuad=new t.t(this.createFadeMaterial(n.toneMapping)));let r=this.fadeQuad.material;r.uniforms.tRaster.value=this.rasterFadeTarget.texture,r.uniforms.uOpacity.value=e;let i=n.autoClear,a=n.getRenderTarget();n.setRenderTarget(null),n.autoClear=!1;try{this.fadeQuad.render(n)}finally{n.autoClear=i,n.setRenderTarget(a)}}createFadeMaterial(e){let t={[n.LinearToneMapping]:`LINEAR_TONE_MAPPING`,[n.ReinhardToneMapping]:`REINHARD_TONE_MAPPING`,[n.CineonToneMapping]:`CINEON_TONE_MAPPING`,[n.ACESFilmicToneMapping]:`ACES_FILMIC_TONE_MAPPING`,[n.AgXToneMapping]:`AGX_TONE_MAPPING`,[n.NeutralToneMapping]:`NEUTRAL_TONE_MAPPING`},r={},i=t[e];return i&&(r[i]=``),new n.ShaderMaterial({defines:r,uniforms:{tRaster:{value:null},uOpacity:{value:1}},vertexShader:`
3977
+ }`}),this.depthWrite=!1,this.depthTest=!1}},Gt=class{constructor(e){this._renderer=e,this._quad=new t.t(new Wt)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw Error(`CubeToEquirectMaterial: Source can only be cube textures.`);let i=e.images[0],a=this._renderer,o=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);let s=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),c=i.height,l=Math.log2(c)-2,u=1/c,d=1/(3*Math.max(2**l,112));o.material.defines.CUBEUV_MAX_MIP=`${l}.0`,o.material.defines.CUBEUV_TEXEL_WIDTH=d,o.material.defines.CUBEUV_TEXEL_HEIGHT=u,o.material.uniforms.envMap.value=e,o.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,o.material.needsUpdate=!0;let f=a.getRenderTarget(),p=a.autoClear;a.autoClear=!0,a.setRenderTarget(s),o.render(a),a.setRenderTarget(f),a.autoClear=p;let m=new Uint16Array(t*r*4),h=new Float32Array(t*r*4);a.readRenderTargetPixels(s,0,0,t,r,h),s.dispose();for(let e=0,t=h.length;e<t;e++)m[e]=n.DataUtils.toHalfFloat(h[e]);let g=new n.DataTexture(m,t,r,n.RGBAFormat,n.HalfFloatType);return g.minFilter=n.LinearMipMapLinearFilter,g.magFilter=n.LinearFilter,g.wrapS=n.RepeatWrapping,g.wrapT=n.RepeatWrapping,g.mapping=n.EquirectangularReflectionMapping,g.needsUpdate=!0,g}dispose(){this._quad.dispose()}};function Kt(e){return e.extensions.get(`EXT_float_blend`)}var $=new n.Vector2,qt=class{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine(`FEATURE_MIS`,+!!e)}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 pe,this._pathTracer=new Rt(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Rt(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new t.t(new Ut({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=(e,t)=>{this._renderer.render(e,t)},this.renderToCanvasCallback=(e,t,n)=>{let r=t.autoClear;t.autoClear=!1,n.render(t),t.autoClear=r},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,n={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();let r=this._generator;if(r.setObjects(e),this._buildAsync)return r.generateAsync(n.onProgress).then(n=>this._updateFromResults(e,t,n));{let n=r.generate();return this._updateFromResults(e,t,n)}}setSceneAsync(...e){this._buildAsync=!0;let t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){let e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){let e=this._pathTracer.material,t=this._renderer,n=this._materials,r=this.textureSize,i=ze(n);e.textures.setTextures(t,i,r.x,r.y),e.materials.updateFrom(n,i),this.reset()}updateLights(){let e=this.scene,t=this._renderer,n=this._pathTracer.material,r=Be(e),i=Re(r);n.lights.updateFrom(r,i),n.iesProfiles.setTextures(t,i),this.reset()}updateEnvironment(){let e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&=(this._internalBackground.dispose(),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 Ht(16);let n=this._colorBackground;n.topColor.equals(e.background)||(n.topColor.set(e.background),n.bottomColor.set(e.background),n.update()),t.backgroundMap=n,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){let n=new Gt(this._renderer).generate(e.background);this._internalBackground=n,t.backgroundMap=n,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){let n=new Gt(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(n)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,n){let{materials:r,geometry:i,bvh:a,bvhChanged:o}=n;this._materials=r;let s=this._pathTracer.material;return o&&(s.bvh.updateFrom(a),s.attributesArray.updateFrom(i.attributes.normal,i.attributes.tangent,i.attributes.uv,i.attributes.color),s.materialIndexAttribute.updateFrom(i.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),n}renderSample(){let e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,a=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,a.material.opacity=0,i.start());let o=i.getDelta()*1e3,s=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=s&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Kt(r),e.alpha=t.alpha,this.renderToCanvas){let r=this._renderer,i=this.minSamples;if(s>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration===0?a.material.opacity=1:a.material.opacity=Math.min(a.material.opacity+o/this.fadeDuration,1)),!this.enablePathTracing||this.samples<i||a.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());let n=a.material.opacity;a.material.opacity=1-a.material.opacity,a.material.map=e.target.texture,a.render(r),a.material.opacity=n}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&a.material.opacity>0&&(a.material.opacity<1&&(a.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),a.material.map=t.target.texture,this.renderToCanvasCallback(t.target,r,a),a.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($);let e=Math.floor(this.renderScale*$.x),t=Math.floor(this.renderScale*$.y);if(this._pathTracer.getSize($),$.x!==e||$.y!==t){let n=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*n),Math.floor(t*n))}}}},Jt=class r{ingestSceneWithoutShadowHelpers(e,t){let n=[],r=[];e.traverse(e=>{e.userData?.softboxContactShadowHelper&&e.visible?n.push(e):e.userData?.softboxPathTracingFloor&&!e.visible&&r.push(e)}),n.forEach(e=>e.visible=!1),r.forEach(e=>e.visible=!0);try{this.pathTracer?.setScene(e,t)}finally{n.forEach(e=>e.visible=!0),r.forEach(e=>e.visible=!1)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;let t=e.image,r=document.createElement(`canvas`);r.width=t.width,r.height=t.height;let i=r.getContext(`2d`);if(!i)return null;i.drawImage(t,0,0);let a=i.getImageData(0,0,r.width,r.height),o=new Float32Array(a.data.length);for(let e=0;e<a.data.length;e++)o[e]=a.data[e]/255;let s=new n.DataTexture(o,r.width,r.height,n.RGBAFormat,n.FloatType);return s.mapping=e.mapping,s.wrapS=e.wrapS,s.wrapT=e.wrapT,s.magFilter=e.magFilter,s.minFilter=e.minFilter,s.anisotropy=e.anisotropy,s.needsUpdate=!0,s}getThreeRenderer(){return e.i(this.renderer)}static{this.CAMERA_SETTLE_MS=200}static{this.FADE_SAMPLES=256}static{this.FADE_HOLD_SAMPLES=4}static{this.FADE_PREVIEW_OPACITY=.3}static{this.FADE_RELEASE_FRACTION=.5}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.convertedEnvSourceUuid=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new e.D,this.rasterFadeTarget=null,this.fadeQuad=null,this.fadeToneMapping=null,this.fadeSupported=!0,this.settings={samples:300,bounces:4,transmissiveBounces:2,renderScale:1,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}async initialize(t){try{return this.renderer=t.renderer,this.enabled=t.enabled,this.isSupported()?e.O.ok(void 0):e.O.err(new e.A(`Path tracing is not supported in this environment`,e.k.PATH_TRACING_INIT_FAILED,{reason:`WebGL2 or required extensions not available`}))}catch(t){return e.O.err(new e.A(`Failed to initialize path tracing`,e.k.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return e.O.err(new e.A(`Instance is disposed`,e.k.INVALID_STATE));try{let t=this.getThreeRenderer();return t?(this.pathTracer=new qt(t),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,t.setRenderTarget(null),e.O.ok(void 0)):e.O.err(new e.A(`Renderer not ready, will retry`,e.k.RENDERER_NOT_INITIALIZED))}catch(t){return e.O.err(new e.A(`Failed to create path tracer`,e.k.PATH_TRACING_INIT_FAILED,{originalError:t}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;let e=this.getThreeRenderer();e&&(e.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(t,n){if(this.disposed)return e.O.ok(void 0);let r=this.renderer;if(!r)return e.O.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(t,n);if(!this.pathTracer){let e=this.ensurePathTracerCreated(r,t,n);if(e)return e}try{let i=this.extractThreeObjects(t,n);if(!i)return e.O.err(new e.A(`Could not extract Three.js scene or camera`,e.k.INVALID_PARAMETER));let{threeScene:a,threeCamera:o}=i;if(!this.sceneInitialized){let e=await this.initializeSceneForPathTracing(r,t,n,a,o);if(e)return e}return this.sceneInitialized?this.accumulateSample(r,t,n):r.render(t,n)}catch(t){return e.O.err(new e.A(`Failed to render with path tracing`,e.k.RENDER_FAILED,{originalError:t}))}}ensurePathTracerCreated(e,t,n){this.createAttempts++;let r=this.createPathTracer();return r.ok?(this.createAttempts=0,null):this.createAttempts<this.maxCreateAttempts&&r.error?.message===`Renderer not ready, will retry`?e.render(t,n):(this.disableAfterSelfPause(`gave-up`),this.createAttempts=0,e.render(t,n))}extractThreeObjects(t,n){let r=e.a(t),i=e.t(n);return!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,a){try{let o=i.__originalEnvironmentTexture;if(!i.environment&&!o)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause(`gave-up`),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,o&&o.isCubeTexture){let e=i.environment;i.environment=o;try{this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0}finally{i.environment=e}}else if(o&&o.mapping===n.EquirectangularReflectionMapping){let e=o;if(o.image instanceof HTMLImageElement)if(this.convertedEnvTexture&&this.convertedEnvSourceUuid===o.uuid)e=this.convertedEnvTexture;else{this.convertedEnvTexture?.dispose(),this.convertedEnvTexture=null,this.convertedEnvSourceUuid=null;let t=this.convertToDataTexture(o);if(!t)throw Error(`Failed to convert environment texture to DataTexture`);this.convertedEnvTexture=t,this.convertedEnvSourceUuid=o.uuid,e=t}let t=i.environment;i.environment=e;try{let e=o.image;e&&!(`data`in e&&e.data)&&e instanceof HTMLImageElement&&!e.complete&&await new Promise(t=>{e.onload=()=>{o.needsUpdate=!0,t()},e.onerror=()=>{t()},e.complete&&t()}),this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0,i.environment=t}catch(e){throw i.environment=t,e}}else if(i.environment?.mapping===n.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,a),this.sceneInitialized=!0;else return this.disableAfterSelfPause(`gave-up`),e.render(t,r)}catch(n){return console.warn(`Scene initialization error:`,n),e.render(t,r)}return null}accumulateSample(t,n,i){if(this.sampleCount===0)try{this.pathTracer?.updateLights()}catch(e){console.warn(`Failed to update lights for path tracing:`,e)}let a=t.render(n,i);if(!a.ok)return a;if(performance.now()-this.lastCameraMoveTime<r.CAMERA_SETTLE_MS)return e.O.ok(void 0);if(this.cameraDirty&&(this.cameraDirty=!1,this.pathTracer?.updateCamera()),this.fadeSupported&&this.sampleCount===0&&this.runFadeStep(()=>this.captureRasterFade(t,n,i)),this.accumulateOneSample(),this.sampleCount++,this.fadeSupported&&this.sampleCount<this.fadeWindowSamples()){let e=1-this.pathTracedLayerOpacity(this.sampleCount);this.runFadeStep(()=>this.renderRasterFade(e))}return this.sampleCount===this.settings.samples?this.captureCompletedFrame():e.O.ok(void 0)}runFadeStep(e){try{e()}catch(e){console.warn(`Path-tracing startup dissolve unavailable; showing samples directly:`,e),this.fadeSupported=!1}}fadeWindowSamples(){let e=r.FADE_HOLD_SAMPLES+2;return Math.max(e,Math.min(r.FADE_SAMPLES,this.settings.samples))}pathTracedLayerOpacity(e){let t=r.FADE_HOLD_SAMPLES,n=this.fadeWindowSamples(),i=r.FADE_PREVIEW_OPACITY,a=t+(n-t)*r.FADE_RELEASE_FRACTION;return e<a?i*r.smoothstep(t,a,e):i+(1-i)*r.smoothstep(a,n,e)}static smoothstep(e,t,n){let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)}captureRasterFade(e,t,r){let i=this.getThreeRenderer();if(!i)return;let a=i.getDrawingBufferSize(new n.Vector2);this.rasterFadeTarget?(this.rasterFadeTarget.width!==a.x||this.rasterFadeTarget.height!==a.y)&&this.rasterFadeTarget.setSize(a.x,a.y):(this.rasterFadeTarget=new n.WebGLRenderTarget(a.x,a.y,{type:n.HalfFloatType}),this.rasterFadeTarget.texture.colorSpace=n.LinearSRGBColorSpace);let o=i.getRenderTarget();i.setRenderTarget(this.rasterFadeTarget),e.render(t,r),i.setRenderTarget(o)}renderRasterFade(e){let n=this.getThreeRenderer();if(!n||!this.rasterFadeTarget)return;(!this.fadeQuad||this.fadeToneMapping!==n.toneMapping)&&((this.fadeQuad?.material)?.dispose(),this.fadeToneMapping=n.toneMapping,this.fadeQuad=new t.t(this.createFadeMaterial(n.toneMapping)));let r=this.fadeQuad.material;r.uniforms.tRaster.value=this.rasterFadeTarget.texture,r.uniforms.uOpacity.value=e;let i=n.autoClear,a=n.getRenderTarget();n.setRenderTarget(null),n.autoClear=!1;try{this.fadeQuad.render(n)}finally{n.autoClear=i,n.setRenderTarget(a)}}createFadeMaterial(e){let t={[n.LinearToneMapping]:`LINEAR_TONE_MAPPING`,[n.ReinhardToneMapping]:`REINHARD_TONE_MAPPING`,[n.CineonToneMapping]:`CINEON_TONE_MAPPING`,[n.ACESFilmicToneMapping]:`ACES_FILMIC_TONE_MAPPING`,[n.AgXToneMapping]:`AGX_TONE_MAPPING`,[n.NeutralToneMapping]:`NEUTRAL_TONE_MAPPING`},r={},i=t[e];return i&&(r[i]=``),new n.ShaderMaterial({defines:r,uniforms:{tRaster:{value:null},uOpacity:{value:1}},vertexShader:`
3978
3978
  varying vec2 vUv;
3979
3979
  void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }
3980
3980
  `,fragmentShader:`
@@ -3998,4 +3998,4 @@ bool bvhIntersectFogVolumeHit(
3998
3998
  #endif
3999
3999
  gl_FragColor = vec4( sRGBTransferOETF( vec4( color, 1.0 ) ).rgb, uOpacity );
4000
4000
  }
4001
- `,transparent:!0,depthTest:!1,depthWrite:!1})}renderWhileDisabled(t,n){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&$(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),e.S.ok(void 0)):this.renderer.render(t,n):e.S.ok(void 0)}accumulateOneSample(){let e=$(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw Error(`Three.js renderer not available`);let t=e.autoClear,n=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(n)}captureCompletedFrame(){let t=$(this.renderer)?this.renderer.getInternalRenderer():null;if(t&&this.pathTracer)try{let e=t.autoClear;t.autoClear=!0,t.setRenderTarget(null),t.clear(!0,!0,!0);let n=this.pathTracer.copyQuad;n&&typeof n.render==`function`?n.render(t):(t.autoClear=!1,this.pathTracer.renderSample()),t.autoClear=e}catch(e){console.warn(`Failed to present path traced result:`,e)}return this.disableAfterSelfPause(`completed`),e.S.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(),null),this.fadeQuad&&=(this.fadeQuad.material.dispose(),null),this.fadeToneMapping=null,this.rasterFadeTarget&&=(this.rasterFadeTarget.dispose(),null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement(`canvas`).getContext(`webgl2`)!==null}};exports.ThreePathTracingService=Xt;
4001
+ `,transparent:!0,depthTest:!1,depthWrite:!1})}renderWhileDisabled(t,n){if(!this.renderer)return e.O.ok(void 0);if(this.sampleCount>=this.settings.samples&&this.sampleCount>0){let t=this.getThreeRenderer();return this.pathTracer&&t&&t.setRenderTarget(null),e.O.ok(void 0)}return this.renderer.render(t,n)}accumulateOneSample(){let e=this.getThreeRenderer();if(!e)throw Error(`Three.js renderer not available`);let t=e.autoClear,n=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(n)}captureCompletedFrame(){let t=this.getThreeRenderer();if(t&&this.pathTracer)try{let e=t.autoClear;t.autoClear=!0,t.setRenderTarget(null),t.clear(!0,!0,!0);let n=this.pathTracer.copyQuad;n&&typeof n.render==`function`?n.render(t):(t.autoClear=!1,this.pathTracer.renderSample()),t.autoClear=e}catch(e){console.warn(`Failed to present path traced result:`,e)}return this.disableAfterSelfPause(`completed`),e.O.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.convertedEnvSourceUuid=null),this.fadeQuad&&=(this.fadeQuad.material.dispose(),null),this.fadeToneMapping=null,this.rasterFadeTarget&&=(this.rasterFadeTarget.dispose(),null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement(`canvas`).getContext(`webgl2`)!==null}};exports.ThreePathTracingService=Jt;