softbox 4.2.0 → 4.2.1
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.
- package/dist/{ThreePathTracingService-BE8t2ThI.js → ThreePathTracingService-CPU_eQdF.js} +391 -370
- package/dist/{ThreePathTracingService-D0M3HT7t.cjs → ThreePathTracingService-CqzQw5mN.cjs} +9 -9
- package/dist/{index-BBIH_9cu.cjs → index-B1GvtGsa.cjs} +5 -5
- package/dist/{index-B0k0_Cfm.js → index-ryi3d7wY.js} +517 -516
- package/dist/simple-viewer.cjs +1 -1
- package/dist/simple-viewer.es.js +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("three"),T=require("./index-B1GvtGsa.cjs");function $e(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const A=$e(n);function je(s){switch(s){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function Ye(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function de(s){switch(s){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}class ke extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,r=e.itemSize,i=e.count;if(t!==null){if(r*i%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=i*r/t}const o=e.itemSize,a=e.count,c=e.normalized,h=e.array.constructor,m=h.BYTES_PER_ELEMENT;let d=this._forcedType,f=o;if(d===null)switch(h){case Float32Array:d=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:d=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:d=n.IntType;break}let l,y,p,v,u=je(o);switch(d){case n.FloatType:p=1,y=Ye(o),c&&m===1?(v=h,u+="8",h===Uint8Array?l=n.UnsignedByteType:(l=n.ByteType,u+="_SNORM")):(v=Float32Array,u+="32F",l=n.FloatType);break;case n.IntType:u+=m*8+"I",p=c?Math.pow(2,h.BYTES_PER_ELEMENT*8-1):1,y=de(o),m===1?(v=Int8Array,l=n.ByteType):m===2?(v=Int16Array,l=n.ShortType):(v=Int32Array,l=n.IntType);break;case n.UnsignedIntType:u+=m*8+"UI",p=c?Math.pow(2,h.BYTES_PER_ELEMENT*8-1):1,y=de(o),m===1?(v=Uint8Array,l=n.UnsignedByteType):m===2?(v=Uint16Array,l=n.UnsignedShortType):(v=Uint32Array,l=n.UnsignedIntType);break}f===3&&(y===n.RGBAFormat||y===n.RGBAIntegerFormat)&&(f=4);const g=Math.ceil(Math.sqrt(a))||1,x=f*g*g,b=new v(x),w=e.normalized;e.normalized=!1;for(let R=0;R<a;R++){const _=f*R;b[_]=e.getX(R)/p,o>=2&&(b[_+1]=e.getY(R)/p),o>=3&&(b[_+2]=e.getZ(R)/p,f===4&&(b[_+3]=1)),o>=4&&(b[_+3]=e.getW(R)/p)}e.normalized=w,this.internalFormat=u,this.format=y,this.type=l,this.image.width=g,this.image.height=g,this.image.data=b,this.needsUpdate=!0,this.dispose(),e.itemSize=r,e.count=i}}class Be extends ke{constructor(){super(),this._forcedType=n.UnsignedIntType}}class Ne extends ke{constructor(){super(),this._forcedType=n.FloatType}}class Xe{constructor(){this.index=new Be,this.position=new Ne,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(Ke(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const r=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==r.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const i=T.getIndexArray(T.getVertexCount(t));this._cachedIndexAttr=new n.BufferAttribute(i,1,!1)}Qe(t,r,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:r,bvhContents:i}=this;e&&e.dispose(),t&&t.dispose(),r&&r.dispose(),i&&i.dispose()}}function Qe(s,e,t){const r=t.array,i=s.index?s.index.array:null;for(let o=0,a=e.length;o<a;o++){const c=3*o,h=3*e[o];for(let m=0;m<3;m++)r[c+m]=i?i[h+m]:h+m}}function Ke(s,e,t){const r=s._roots;if(r.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const i=r[0],o=new Uint16Array(i),a=new Uint32Array(i),c=new Float32Array(i),h=i.byteLength/T.BYTES_PER_NODE,m=2*Math.ceil(Math.sqrt(h/2)),d=new Float32Array(4*m*m),f=Math.ceil(Math.sqrt(h)),l=new Uint32Array(2*f*f);for(let y=0;y<h;y++){const p=y*T.BYTES_PER_NODE/4,v=p*2,u=T.BOUNDING_DATA_INDEX(p);for(let g=0;g<3;g++)d[8*y+0+g]=c[u+0+g],d[8*y+4+g]=c[u+3+g];if(T.IS_LEAF(v,o)){const g=T.COUNT(v,o),x=T.OFFSET(p,a),b=T.LEAFNODE_MASK_32|g;l[y*2+0]=b,l[y*2+1]=x}else{const g=a[p+6],x=T.SPLIT_AXIS(p,a);l[y*2+0]=x,l[y*2+1]=g}}e.image.data=d,e.image.width=m,e.image.height=m,e.format=n.RGBAFormat,e.type=n.FloatType,e.internalFormat="RGBA32F",e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=l,t.image.width=f,t.image.height=f,t.format=n.RGIntegerFormat,t.type=n.UnsignedIntType,t.internalFormat="RG32UI",t.minFilter=n.NearestFilter,t.magFilter=n.NearestFilter,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const Ze=`
|
|
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 ze(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function H(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new l.BufferAttribute(new t(i*o),i,r)}function N(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function tt(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function rt(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function at(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function it(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function st(s,e={},t=new l.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;tt(s);const c=s[0].index!==null,h=c?rt(s):-1,d=at(s);if(it(t,h,d),r){let f=0;for(let n=0,x=s.length;n<x;n++){const p=s[n];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(f,v,n),f+=v}}if(c){let f=!1;if(t.index||(t.setIndex(new l.BufferAttribute(new Uint32Array(h),1,!1)),f=!0),f||a){let n=0,x=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],y=g.getIndex();if(!(!i&&!f&&o[v]))for(let w=0;w<y.count;++w)p.setX(n+w,y.getX(w)+x);n+=y.count,x+=g.getAttribute("position").count}}}const m=Object.keys(s[0].attributes);for(let f=0,n=m.length;f<n;f++){let x=!1;const p=m[f];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,H(g,d)),x=!0}let v=0;const u=t.getAttribute(p);for(let g=0,y=s.length;g<y;g++){const b=s[g],w=!i&&!x&&o[g],R=b.getAttribute(p);w||ze(R,u,v),v+=R.count}}}function ot(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let h=s.getAttribute("materialIndex");if(!h||h.count!==o){let m;t.length<=255?m=new Uint8Array(o):m=new Uint16Array(o),h=new l.BufferAttribute(m,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",h)}const d=h.array;for(let m=0;m<c.length;m++){const f=c[m],n=f.start,x=f.count,p=Math.min(x,a-n),v=Array.isArray(e)?e[f.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let y=n+g;r&&(y=r.getX(y)),d[y]=u}}}function nt(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new l.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new l.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new l.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new l.BufferAttribute(r,4))}}function se(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function me(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function pe(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${se(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class lt{constructor(e=null){this.matrixWorld=new l.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=me(t),this.primitiveCount=r,this.skeletonHash=pe(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===me(t)&&this.skeletonHash===pe(e)&&this.primitiveCount===r)}}const M=new l.Vector3,C=new l.Vector3,D=new l.Vector3,ge=new l.Vector4,U=new l.Vector3,J=new l.Vector3,ve=new l.Vector4,xe=new l.Vector4,G=new l.Matrix4,ye=new l.Matrix4;function be(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ve.fromBufferAttribute(i.attributes.skinIndex,e),xe.fromBufferAttribute(i.attributes.skinWeight,e),G.elements.fill(0);for(let c=0;c<4;c++){const h=xe.getComponent(c);if(h!==0){const d=ve.getComponent(c);ye.multiplyMatrices(o[d].matrixWorld,a[d]),ct(G,ye,h)}}return G.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(G),t}function ee(s,e,t,r,i){U.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],h=s[o];c!==0&&(J.fromBufferAttribute(h,r),t?U.addScaledVector(J,c):U.addScaledVector(J.sub(i),c))}i.add(U)}function ct(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function ut(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let h=0;h<o;h++){const d=i.getComponent(a,h),m=i.getComponent(a+2,h);i.setComponent(a,h,m),i.setComponent(a+2,h,d)}}return s}function ft(s,e={},t=new l.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,h=t.attributes;for(const y in t.attributes)(!e.attributes.includes(y)||!(y in r.attributes))&&t.deleteAttribute(y);!t.index&&r.index&&(t.index=r.index.clone()),h.position||t.setAttribute("position",H(c.position)),o&&!h.normal&&c.normal&&t.setAttribute("normal",H(c.normal)),a&&!h.tangent&&c.tangent&&t.setAttribute("tangent",H(c.tangent)),N(r.index,t.index),N(c.position,h.position),o&&N(c.normal,h.normal),a&&N(c.tangent,h.tangent);const d=c.position,m=o?c.normal:null,f=a?c.tangent:null,n=r.morphAttributes.position,x=r.morphAttributes.normal,p=r.morphAttributes.tangent,v=r.morphTargetsRelative,u=s.morphTargetInfluences,g=new l.Matrix3;g.getNormalMatrix(s.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let y=0,b=c.position.count;y<b;y++)M.fromBufferAttribute(d,y),m&&C.fromBufferAttribute(m,y),f&&(ge.fromBufferAttribute(f,y),D.fromBufferAttribute(f,y)),u&&(n&&ee(n,u,v,y,M),x&&ee(x,u,v,y,C),p&&ee(p,u,v,y,D)),s.isSkinnedMesh&&(s.applyBoneTransform(y,M),m&&be(s,y,C),f&&be(s,y,D)),i&&M.applyMatrix4(s.matrixWorld),h.position.setXYZ(y,M.x,M.y,M.z),m&&(i&&C.applyNormalMatrix(g),h.normal.setXYZ(y,C.x,C.y,C.z)),f&&(i&&D.transformDirection(s.matrixWorld),h.tangent.setXYZW(y,D.x,D.y,D.z,ge.w));for(const y in e.attributes){const b=e.attributes[y];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(h[b]||t.setAttribute(b,H(c[b])),N(c[b],h[b]),ze(c[b],h[b]))}return s.matrixWorld.determinant()<0&&ut(t),t}class ht extends l.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new lt}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!N(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(ft(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ae=0,He=1,We=2;function dt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function mt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function pt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new l.BufferAttribute(new Float32Array(0),4,!1))}else st(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class gt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new l.MeshBasicMaterial,t=new l.BufferGeometry;t.setAttribute("position",new l.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new l.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return dt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],h=c.uuid;r.delete(h);let d=e.get(h);(!d||!d.isCompatible(c,this.attributes))&&(d&&d.dispose(),d=new ht,e.set(h,d)),d.updateFrom(c,i)&&this.generateMissingAttributes&&nt(d,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new l.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],h=[],d=o.get(e)||[];this._updateIntermediateGeometries();let m=!1;a.length!==d.length&&(m=!0);for(let n=0,x=a.length;n<x;n++){const p=a[n],v=i.get(p.uuid);h.push(v);const u=d[n];!u||u.uuid!==v.uuid?(c.push(!1),m=!0):u.version!==v.version?c.push(!1):c.push(!0)}pt(h,e,{useGroups:t,forceUpdate:m,skipAssigningAttributes:c,overwriteIndex:r}),m&&e.dispose(),o.set(e,h.map(n=>({version:n.version,uuid:n.uuid})));let f=ae;return m?f=We:c.includes(!1)&&(f=He),{changeType:f,materials:mt(a),geometry:e}}}function vt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function xt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class yt{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 l.BufferGeometry,this.staticGeometryGenerator=new gt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(f=>{f.traverse(n=>{n.isSkinnedMesh&&n.skeleton&&n.skeleton.update()})});const a=t.generate(r),c=a.materials,h=vt(c),{lights:d,iesTextures:m}=xt(o);if(a.changeType!==ae&&ot(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===We){const f={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,f):this.bvh=new T.MeshBVH(r,f)}else a.changeType===He&&this.bvh.refit()}return{bvhChanged:a.changeType!==ae,bvh:this.bvh,lights:d,iesTextures:m,geometry:r,materials:c,textures:h,objects:o}}}const bt=new l.OrthographicCamera(-1,1,1,-1,0,1);class Tt extends l.BufferGeometry{constructor(){super(),this.setAttribute("position",new l.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new l.Float32BufferAttribute([0,2,0,0,2,0],2))}}const wt=new Tt;class z{constructor(e){this._mesh=new l.Mesh(wt,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,bt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class oe extends l.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Rt extends oe{constructor(e){super({blending:l.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
297
|
+
`;function ze(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function H(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new n.BufferAttribute(new t(i*o),i,r)}function N(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function tt(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function rt(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function at(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function it(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function st(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;tt(s);const c=s[0].index!==null,h=c?rt(s):-1,m=at(s);if(it(t,h,m),r){let f=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(f,v,l),f+=v}}if(c){let f=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(h),1,!1)),f=!0),f||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!f&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let f=0,l=d.length;f<l;f++){let y=!1;const p=d[f];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,H(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||ze(R,u,v),v+=R.count}}}function ot(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let h=s.getAttribute("materialIndex");if(!h||h.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),h=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",h)}const m=h.array;for(let d=0;d<c.length;d++){const f=c[d],l=f.start,y=f.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[f.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function nt(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function se(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function me(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function pe(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${se(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class lt{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=me(t),this.primitiveCount=r,this.skeletonHash=pe(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===me(t)&&this.skeletonHash===pe(e)&&this.primitiveCount===r)}}const M=new n.Vector3,C=new n.Vector3,D=new n.Vector3,ge=new n.Vector4,U=new n.Vector3,J=new n.Vector3,ve=new n.Vector4,xe=new n.Vector4,G=new n.Matrix4,ye=new n.Matrix4;function be(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ve.fromBufferAttribute(i.attributes.skinIndex,e),xe.fromBufferAttribute(i.attributes.skinWeight,e),G.elements.fill(0);for(let c=0;c<4;c++){const h=xe.getComponent(c);if(h!==0){const m=ve.getComponent(c);ye.multiplyMatrices(o[m].matrixWorld,a[m]),ct(G,ye,h)}}return G.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(G),t}function ee(s,e,t,r,i){U.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],h=s[o];c!==0&&(J.fromBufferAttribute(h,r),t?U.addScaledVector(J,c):U.addScaledVector(J.sub(i),c))}i.add(U)}function ct(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function ut(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let h=0;h<o;h++){const m=i.getComponent(a,h),d=i.getComponent(a+2,h);i.setComponent(a,h,d),i.setComponent(a+2,h,m)}}return s}function ft(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,h=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),h.position||t.setAttribute("position",H(c.position)),o&&!h.normal&&c.normal&&t.setAttribute("normal",H(c.normal)),a&&!h.tangent&&c.tangent&&t.setAttribute("tangent",H(c.tangent)),N(r.index,t.index),N(c.position,h.position),o&&N(c.normal,h.normal),a&&N(c.tangent,h.tangent);const m=c.position,d=o?c.normal:null,f=a?c.tangent:null,l=r.morphAttributes.position,y=r.morphAttributes.normal,p=r.morphAttributes.tangent,v=r.morphTargetsRelative,u=s.morphTargetInfluences,g=new n.Matrix3;g.getNormalMatrix(s.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let x=0,b=c.position.count;x<b;x++)M.fromBufferAttribute(m,x),d&&C.fromBufferAttribute(d,x),f&&(ge.fromBufferAttribute(f,x),D.fromBufferAttribute(f,x)),u&&(l&&ee(l,u,v,x,M),y&&ee(y,u,v,x,C),p&&ee(p,u,v,x,D)),s.isSkinnedMesh&&(s.applyBoneTransform(x,M),d&&be(s,x,C),f&&be(s,x,D)),i&&M.applyMatrix4(s.matrixWorld),h.position.setXYZ(x,M.x,M.y,M.z),d&&(i&&C.applyNormalMatrix(g),h.normal.setXYZ(x,C.x,C.y,C.z)),f&&(i&&D.transformDirection(s.matrixWorld),h.tangent.setXYZW(x,D.x,D.y,D.z,ge.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(h[b]||t.setAttribute(b,H(c[b])),N(c[b],h[b]),ze(c[b],h[b]))}return s.matrixWorld.determinant()<0&&ut(t),t}class ht extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new lt}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!N(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(ft(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ae=0,He=1,We=2;function dt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function mt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function pt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else st(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class gt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return dt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],h=c.uuid;r.delete(h);let m=e.get(h);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new ht,e.set(h,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&nt(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],h=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);h.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}pt(h,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let f=ae;return d?f=We:c.includes(!1)&&(f=He),{changeType:f,materials:mt(a),geometry:e}}}function vt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function xt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class yt{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 gt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(f=>{f.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,h=vt(c),{lights:m,iesTextures:d}=xt(o);if(a.changeType!==ae&&ot(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===We){const f={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,f):this.bvh=new T.MeshBVH(r,f)}else a.changeType===He&&this.bvh.refit()}return{bvhChanged:a.changeType!==ae,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:h,objects:o}}}const bt=new n.OrthographicCamera(-1,1,1,-1,0,1);class Tt extends n.BufferGeometry{constructor(){super(),this.setAttribute("position",new n.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new n.Float32BufferAttribute([0,2,0,0,2,0],2))}}const wt=new Tt;class z{constructor(e){this._mesh=new n.Mesh(wt,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,bt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class oe extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Rt extends oe{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
|
|
|
@@ -528,7 +528,7 @@ struct BVH {
|
|
|
528
528
|
${q(3)}
|
|
529
529
|
${q(4)}
|
|
530
530
|
|
|
531
|
-
`;class _t extends oe{constructor(){super({blending:
|
|
531
|
+
`;class _t extends oe{constructor(){super({blending:n.NoBlending,uniforms:{resolution:{value:new n.Vector2}},vertexShader:`
|
|
532
532
|
|
|
533
533
|
varying vec2 vUv;
|
|
534
534
|
void main() {
|
|
@@ -550,7 +550,7 @@ struct BVH {
|
|
|
550
550
|
gl_FragColor = generateSobolPoint( index );
|
|
551
551
|
|
|
552
552
|
}
|
|
553
|
-
`})}}class Ft{generate(e,t=256){const r=new l.WebGLRenderTarget(t,t,{type:l.FloatType,format:l.RGBAFormat,minFilter:l.NearestFilter,magFilter:l.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new z(new _t);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class At extends l.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class Mt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof At?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function te(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=l.DataUtils.toHalfFloat(s[t]);return e}function Te(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Ct(s,e,t){return .2126*s+.7152*e+.0722*t}function Dt(s,e=l.HalfFloatType){const t=s.clone();t.source=new l.Source({...t.image});const{width:r,height:i,data:o}=t.image;let a=o;if(t.type!==e){e===l.HalfFloatType?a=new Uint16Array(o.length):a=new Float32Array(o.length);let c;o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?c=2**(8*o.BYTES_PER_ELEMENT-1)-1:c=2**(8*o.BYTES_PER_ELEMENT)-1;for(let h=0,d=o.length;h<d;h++){let m=o[h];t.type===l.HalfFloatType&&(m=l.DataUtils.fromHalfFloat(o[h])),t.type!==l.FloatType&&t.type!==l.HalfFloatType&&(m/=c),e===l.HalfFloatType&&(a[h]=l.DataUtils.toHalfFloat(m))}t.image.data=a,t.type=e}if(t.flipY){const c=a;a=a.slice();for(let h=0;h<i;h++)for(let d=0;d<r;d++){const m=i-h-1,f=4*(h*r+d),n=4*(m*r+d);a[n+0]=c[f+0],a[n+1]=c[f+1],a[n+2]=c[f+2],a[n+3]=c[f+3]}t.flipY=!1,t.image.data=a}return t}class Pt{constructor(){const e=new l.DataTexture(te(new Float32Array([0,0,0,0])),1,1);e.type=l.HalfFloatType,e.format=l.RGBAFormat,e.minFilter=l.LinearFilter,e.magFilter=l.LinearFilter,e.wrapS=l.RepeatWrapping,e.wrapT=l.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new l.DataTexture(te(new Float32Array([0,1])),1,2);t.type=l.HalfFloatType,t.format=l.RedFormat,t.minFilter=l.LinearFilter,t.magFilter=l.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new l.DataTexture(te(new Float32Array([0,0,1,1])),2,2);r.type=l.HalfFloatType,r.format=l.RedFormat,r.minFilter=l.LinearFilter,r.magFilter=l.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Dt(e);t.wrapS=l.RepeatWrapping,t.wrapT=l.ClampToEdgeWrapping;const{width:r,height:i,data:o}=t.image,a=new Float32Array(r*i),c=new Float32Array(r*i),h=new Float32Array(i),d=new Float32Array(i);let m=0,f=0;for(let u=0;u<i;u++){let g=0;for(let y=0;y<r;y++){const b=u*r+y,w=l.DataUtils.fromHalfFloat(o[4*b+0]),R=l.DataUtils.fromHalfFloat(o[4*b+1]),_=l.DataUtils.fromHalfFloat(o[4*b+2]),F=Ct(w,R,_);g+=F,m+=F,a[b]=F,c[b]=g}if(g!==0)for(let y=u*r,b=u*r+r;y<b;y++)a[y]/=g,c[y]/=g;f+=g,h[u]=g,d[u]=f}if(f!==0)for(let u=0,g=h.length;u<g;u++)h[u]/=f,d[u]/=f;const n=new Uint16Array(i),x=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,y=Te(d,g);n[u]=l.DataUtils.toHalfFloat((y+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const y=u*r+g,b=(g+1)/r,w=Te(c,b,u*r,r);x[y]=l.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:n},p.needsUpdate=!0,v.image={width:r,height:i,data:x},v.needsUpdate=!0,this.totalSum=m,this.map=t}}const re=6,Et=0,kt=1,Ot=2,Bt=3,Nt=4,S=new l.Vector3,I=new l.Vector3,we=new l.Matrix4,E=new l.Quaternion,Re=new l.Vector3,k=new l.Vector3,zt=new l.Vector3(0,1,0);class Ht{constructor(){const e=new l.DataTexture(new Float32Array(4),1,1);e.format=l.RGBAFormat,e.type=l.FloatType,e.wrapS=l.ClampToEdgeWrapping,e.wrapT=l.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=l.NearestFilter,e.magFilter=l.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*re,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let h=0,d=e.length;h<d;h++){const m=e[h],f=h*re*4;let n=0;for(let p=0;p<re*4;p++)a[f+p]=0;m.getWorldPosition(I),a[f+n++]=I.x,a[f+n++]=I.y,a[f+n++]=I.z;let x=Et;if(m.isRectAreaLight&&m.isCircular?x=kt:m.isSpotLight?x=Ot:m.isDirectionalLight?x=Bt:m.isPointLight&&(x=Nt),a[f+n++]=x,a[f+n++]=m.color.r,a[f+n++]=m.color.g,a[f+n++]=m.color.b,a[f+n++]=m.intensity,m.getWorldQuaternion(E),m.isRectAreaLight)S.set(m.width,0,0).applyQuaternion(E),a[f+n++]=S.x,a[f+n++]=S.y,a[f+n++]=S.z,n++,I.set(0,m.height,0).applyQuaternion(E),a[f+n++]=I.x,a[f+n++]=I.y,a[f+n++]=I.z,a[f+n++]=S.cross(I).length()*(m.isCircular?Math.PI/4:1);else if(m.isSpotLight){const p=m.radius||0;Re.setFromMatrixPosition(m.matrixWorld),k.setFromMatrixPosition(m.target.matrixWorld),we.lookAt(Re,k,zt),E.setFromRotationMatrix(we),S.set(1,0,0).applyQuaternion(E),a[f+n++]=S.x,a[f+n++]=S.y,a[f+n++]=S.z,n++,I.set(0,1,0).applyQuaternion(E),a[f+n++]=I.x,a[f+n++]=I.y,a[f+n++]=I.z,a[f+n++]=Math.PI*p*p,a[f+n++]=p,a[f+n++]=m.decay,a[f+n++]=m.distance,a[f+n++]=Math.cos(m.angle),a[f+n++]=Math.cos(m.angle*(1-m.penumbra)),a[f+n++]=m.iesMap?t.indexOf(m.iesMap):-1}else if(m.isPointLight){const p=S.setFromMatrixPosition(m.matrixWorld);a[f+n++]=p.x,a[f+n++]=p.y,a[f+n++]=p.z,n++,n+=4,n+=1,a[f+n++]=m.decay,a[f+n++]=m.distance}else if(m.isDirectionalLight){const p=S.setFromMatrixPosition(m.matrixWorld),v=I.setFromMatrixPosition(m.target.matrixWorld);k.subVectors(p,v).normalize(),a[f+n++]=k.x,a[f+n++]=k.y,a[f+n++]=k.z}}this.count=e.length;const c=se(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function Ie(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let h=0;h<o;h++){const d=4*h,m=e*h;for(let f=0;f<r;f++)t[i+d+f]=e>=f+1?s[m+f]/c:0}}class Wt extends l.DataArrayTexture{constructor(){super(),this._textures=[],this.type=l.FloatType,this.format=l.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:h}=o,m=a*c*4*e;let f=t.itemSize;f===3&&(f=4),Ie(r.image.data,f,h,4,m),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let f=0,n=r;f<n;f++)if(e[f].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const f=new Ne;i.push(f)}for(;i.length>r;)i.pop();for(let f=0,n=r;f<n;f++)i[f].updateFrom(e[f]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:d,height:m}=c;for(let f=0,n=r;f<n;f++){const x=i[f],v=d*m*4*f;let u=e[f].itemSize;u===3&&(u=4),Ie(x.image.data,u,h,4,v)}this.dispose(),this.needsUpdate=!0}}class Lt extends Wt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ne(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function ie(s){return`${s.source.uuid}:${s.colorSpace}`}function Ut(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=ie(o);e.has(a)||(e.add(a),t.push(o))}return t}function Gt(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ne)}function Vt(s){const e=new Set;for(let r=0,i=s.length;r<i;r++){const o=s[r];for(const a in o){const c=o[a];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return Ut(t).sort(ne)}function qt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ne)}const Ue=45,Se=Ue*4;class $t{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class jt extends l.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=l.RGBAFormat,this.type=l.FloatType,this.wrapS=l.ClampToEdgeWrapping,this.wrapT=l.ClampToEdgeWrapping,this.minFilter=l.NearestFilter,this.magFilter=l.NearestFilter,this.generateMipmaps=!1,this.features=new $t}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=ie(p[v]);return f[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const y=p[v]&&p[v].isTexture?p[v]:null;if(y){y.matrixAutoUpdate&&y.updateMatrix();const b=y.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*Ue,h=Math.ceil(Math.sqrt(c))||1,{image:d,features:m}=this,f={};for(let p=0,v=t.length;p<v;p++)f[ie(t[p])]=p;d.width!==h&&(this.dispose(),d.data=new Float32Array(h*h*4),d.width=h,d.height=h);const n=d.data;m.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){m.setUsed("FOG");for(let b=0;b<Se;b++)n[a+b]=0;n[a+0+0]=u.color.r,n[a+0+1]=u.color.g,n[a+0+2]=u.color.b,n[a+8+3]=i(u,"emissiveIntensity",0),n[a+12+0]=u.emissive.r,n[a+12+1]=u.emissive.g,n[a+12+2]=u.emissive.b,n[a+52+1]=u.density,n[a+52+3]=0,n[a+56+2]=4,a+=Se;continue}n[a++]=u.color.r,n[a++]=u.color.g,n[a++]=u.color.b,n[a++]=r(u,"map"),n[a++]=i(u,"metalness",0),n[a++]=r(u,"metalnessMap"),n[a++]=i(u,"roughness",0),n[a++]=r(u,"roughnessMap"),n[a++]=i(u,"ior",1.5),n[a++]=i(u,"transmission",0),n[a++]=r(u,"transmissionMap"),n[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(n[a++]=u.emissive.r,n[a++]=u.emissive.g,n[a++]=u.emissive.b):(n[a++]=0,n[a++]=0,n[a++]=0),n[a++]=r(u,"emissiveMap"),n[a++]=r(u,"normalMap"),"normalScale"in u?(n[a++]=u.normalScale.x,n[a++]=u.normalScale.y):(n[a++]=1,n[a++]=1),n[a++]=i(u,"clearcoat",0),n[a++]=r(u,"clearcoatMap"),n[a++]=i(u,"clearcoatRoughness",0),n[a++]=r(u,"clearcoatRoughnessMap"),n[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(n[a++]=u.clearcoatNormalScale.x,n[a++]=u.clearcoatNormalScale.y):(n[a++]=1,n[a++]=1),a++,n[a++]=i(u,"sheen",0),"sheenColor"in u?(n[a++]=u.sheenColor.r,n[a++]=u.sheenColor.g,n[a++]=u.sheenColor.b):(n[a++]=0,n[a++]=0,n[a++]=0),n[a++]=r(u,"sheenColorMap"),n[a++]=i(u,"sheenRoughness",0),n[a++]=r(u,"sheenRoughnessMap"),n[a++]=r(u,"iridescenceMap"),n[a++]=r(u,"iridescenceThicknessMap"),n[a++]=i(u,"iridescence",0),n[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);n[a++]=g[0],n[a++]=g[1],"specularColor"in u?(n[a++]=u.specularColor.r,n[a++]=u.specularColor.g,n[a++]=u.specularColor.b):(n[a++]=1,n[a++]=1,n[a++]=1),n[a++]=r(u,"specularColorMap"),n[a++]=i(u,"specularIntensity",1),n[a++]=r(u,"specularIntensityMap");const y=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(n[a++]=Number(y),a++,"attenuationColor"in u?(n[a++]=u.attenuationColor.r,n[a++]=u.attenuationColor.g,n[a++]=u.attenuationColor.b):(n[a++]=1,n[a++]=1,n[a++]=1),n[a++]=i(u,"attenuationDistance",1/0),n[a++]=r(u,"alphaMap"),n[a++]=u.opacity,n[a++]=u.alphaTest,!y&&u.transmission>0)n[a++]=0;else switch(u.side){case l.FrontSide:n[a++]=1;break;case l.BackSide:n[a++]=-1;break;case l.DoubleSide:n[a++]=0;break}n[a++]=Number(i(u,"matte",!1)),n[a++]=Number(i(u,"castShadow",!0)),n[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,n[a++]=Number(u.transparent),a+=o(u,"map",n,a),a+=o(u,"metalnessMap",n,a),a+=o(u,"roughnessMap",n,a),a+=o(u,"transmissionMap",n,a),a+=o(u,"emissiveMap",n,a),a+=o(u,"normalMap",n,a),a+=o(u,"clearcoatMap",n,a),a+=o(u,"clearcoatNormalMap",n,a),a+=o(u,"clearcoatRoughnessMap",n,a),a+=o(u,"sheenColorMap",n,a),a+=o(u,"sheenRoughnessMap",n,a),a+=o(u,"iridescenceMap",n,a),a+=o(u,"iridescenceThicknessMap",n,a),a+=o(u,"specularColorMap",n,a),a+=o(u,"specularIntensityMap",n,a)}const x=se(n.buffer);return this.hash!==x?(this.hash=x,this.needsUpdate=!0,!0):!1}}const _e=new l.Color;function Yt(s){return s?`${s.uuid}:${s.version}`:null}function Xt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Fe extends l.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:l.RGBAFormat,type:l.UnsignedByteType,minFilter:l.LinearFilter,magFilter:l.LinearFilter,wrapS:l.RepeatWrapping,wrapT:l.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Xt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new z(new Qt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(_e);const h=t.length||1;(r!==this.width||i!==this.height||this.depth!==h)&&(this.setSize(r,i,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=l.NoToneMapping;const d=this.fsQuad,m=this.hashes;let f=!1;for(let n=0,x=h;n<x;n++){const p=t[n],v=Yt(p);p&&(m[n]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),d.material.map=p,e.setRenderTarget(this,n),d.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,m[n]=v,f=!0)}return d.material.map=null,e.setClearColor(_e,c),e.setRenderTarget(o),e.toneMapping=a,f}dispose(){super.dispose(),this.fsQuad.dispose()}}class Qt extends l.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
553
|
+
`})}}class Ft{generate(e,t=256){const r=new n.WebGLRenderTarget(t,t,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new z(new _t);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class At extends n.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class Mt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof At?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function te(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Te(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Ct(s,e,t){return .2126*s+.7152*e+.0722*t}function Dt(s,e=n.HalfFloatType){const t=s.clone();t.source=new n.Source({...t.image});const{width:r,height:i,data:o}=t.image;let a=o;if(t.type!==e){e===n.HalfFloatType?a=new Uint16Array(o.length):a=new Float32Array(o.length);let c;o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?c=2**(8*o.BYTES_PER_ELEMENT-1)-1:c=2**(8*o.BYTES_PER_ELEMENT)-1;for(let h=0,m=o.length;h<m;h++){let d=o[h];t.type===n.HalfFloatType&&(d=n.DataUtils.fromHalfFloat(o[h])),t.type!==n.FloatType&&t.type!==n.HalfFloatType&&(d/=c),e===n.HalfFloatType&&(a[h]=n.DataUtils.toHalfFloat(d))}t.image.data=a,t.type=e}if(t.flipY){const c=a;a=a.slice();for(let h=0;h<i;h++)for(let m=0;m<r;m++){const d=i-h-1,f=4*(h*r+m),l=4*(d*r+m);a[l+0]=c[f+0],a[l+1]=c[f+1],a[l+2]=c[f+2],a[l+3]=c[f+3]}t.flipY=!1,t.image.data=a}return t}class Pt{constructor(){const e=new n.DataTexture(te(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(te(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(te(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Dt(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;const{width:r,height:i,data:o}=t.image,a=new Float32Array(r*i),c=new Float32Array(r*i),h=new Float32Array(i),m=new Float32Array(i);let d=0,f=0;for(let u=0;u<i;u++){let g=0;for(let x=0;x<r;x++){const b=u*r+x,w=n.DataUtils.fromHalfFloat(o[4*b+0]),R=n.DataUtils.fromHalfFloat(o[4*b+1]),_=n.DataUtils.fromHalfFloat(o[4*b+2]),F=Ct(w,R,_);g+=F,d+=F,a[b]=F,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;f+=g,h[u]=g,m[u]=f}if(f!==0)for(let u=0,g=h.length;u<g;u++)h[u]/=f,m[u]/=f;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Te(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Te(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const re=6,Et=0,Ot=1,kt=2,Bt=3,Nt=4,S=new n.Vector3,I=new n.Vector3,we=new n.Matrix4,E=new n.Quaternion,Re=new n.Vector3,O=new n.Vector3,zt=new n.Vector3(0,1,0);class Ht{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*re,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let h=0,m=e.length;h<m;h++){const d=e[h],f=h*re*4;let l=0;for(let p=0;p<re*4;p++)a[f+p]=0;d.getWorldPosition(I),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z;let y=Et;if(d.isRectAreaLight&&d.isCircular?y=Ot:d.isSpotLight?y=kt:d.isDirectionalLight?y=Bt:d.isPointLight&&(y=Nt),a[f+l++]=y,a[f+l++]=d.color.r,a[f+l++]=d.color.g,a[f+l++]=d.color.b,a[f+l++]=d.intensity,d.getWorldQuaternion(E),d.isRectAreaLight)S.set(d.width,0,0).applyQuaternion(E),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,d.height,0).applyQuaternion(E),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=S.cross(I).length()*(d.isCircular?Math.PI/4:1);else if(d.isSpotLight){const p=d.radius||0;Re.setFromMatrixPosition(d.matrixWorld),O.setFromMatrixPosition(d.target.matrixWorld),we.lookAt(Re,O,zt),E.setFromRotationMatrix(we),S.set(1,0,0).applyQuaternion(E),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,1,0).applyQuaternion(E),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=Math.PI*p*p,a[f+l++]=p,a[f+l++]=d.decay,a[f+l++]=d.distance,a[f+l++]=Math.cos(d.angle),a[f+l++]=Math.cos(d.angle*(1-d.penumbra)),a[f+l++]=d.iesMap?t.indexOf(d.iesMap):-1}else if(d.isPointLight){const p=S.setFromMatrixPosition(d.matrixWorld);a[f+l++]=p.x,a[f+l++]=p.y,a[f+l++]=p.z,l++,l+=4,l+=1,a[f+l++]=d.decay,a[f+l++]=d.distance}else if(d.isDirectionalLight){const p=S.setFromMatrixPosition(d.matrixWorld),v=I.setFromMatrixPosition(d.target.matrixWorld);O.subVectors(p,v).normalize(),a[f+l++]=O.x,a[f+l++]=O.y,a[f+l++]=O.z}}this.count=e.length;const c=se(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function Ie(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let h=0;h<o;h++){const m=4*h,d=e*h;for(let f=0;f<r;f++)t[i+m+f]=e>=f+1?s[d+f]/c:0}}class Wt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:h}=o,d=a*c*4*e;let f=t.itemSize;f===3&&(f=4),Ie(r.image.data,f,h,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let f=0,l=r;f<l;f++)if(e[f].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const f=new Ne;i.push(f)}for(;i.length>r;)i.pop();for(let f=0,l=r;f<l;f++)i[f].updateFrom(e[f]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:m,height:d}=c;for(let f=0,l=r;f<l;f++){const y=i[f],v=m*d*4*f;let u=e[f].itemSize;u===3&&(u=4),Ie(y.image.data,u,h,4,v)}this.dispose(),this.needsUpdate=!0}}class Lt extends Wt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ne(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function ie(s){return`${s.source.uuid}:${s.colorSpace}`}function Ut(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=ie(o);e.has(a)||(e.add(a),t.push(o))}return t}function Gt(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ne)}function Vt(s){const e=new Set;for(let r=0,i=s.length;r<i;r++){const o=s[r];for(const a in o){const c=o[a];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return Ut(t).sort(ne)}function qt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ne)}const Ue=45,Se=Ue*4;class $t{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class jt extends n.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=n.RGBAFormat,this.type=n.FloatType,this.wrapS=n.ClampToEdgeWrapping,this.wrapT=n.ClampToEdgeWrapping,this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.features=new $t}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=ie(p[v]);return f[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*Ue,h=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,f={};for(let p=0,v=t.length;p<v;p++)f[ie(t[p])]=p;m.width!==h&&(this.dispose(),m.data=new Float32Array(h*h*4),m.width=h,m.height=h);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Se;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Se;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=se(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const _e=new n.Color;function Yt(s){return s?`${s.uuid}:${s.version}`:null}function Xt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Fe extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Xt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new z(new Qt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(_e);const h=t.length||1;(r!==this.width||i!==this.height||this.depth!==h)&&(this.setSize(r,i,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;const m=this.fsQuad,d=this.hashes;let f=!1;for(let l=0,y=h;l<y;l++){const p=t[l],v=Yt(p);p&&(d[l]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),m.material.map=p,e.setRenderTarget(this,l),m.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,d[l]=v,f=!0)}return m.material.map=null,e.setClearColor(_e,c),e.setRenderTarget(o),e.toneMapping=a,f}dispose(){super.dispose(),this.fsQuad.dispose()}}class Qt extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
554
554
|
varying vec2 vUv;
|
|
555
555
|
void main() {
|
|
556
556
|
|
|
@@ -566,7 +566,7 @@ struct BVH {
|
|
|
566
566
|
gl_FragColor = texture2D( map, vUv );
|
|
567
567
|
|
|
568
568
|
}
|
|
569
|
-
`})}}function Kt(s,e=Math.random()){for(let t=s.length-1;t>0;t--){const r=Math.floor(e()*(t+1)),i=s[t];s[t]=s[r],s[r]=i}return s}class Zt{constructor(e,t,r=Math.random){const i=e**t,o=new Uint16Array(i);let a=i;for(let c=0;c<i;c++)o[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<i;c++)o[c]=c;a=0},this.reshuffle=function(){a=0},this.next=function(){const{samples:c}=this;a>=o.length&&(Kt(o,r),this.reshuffle());let h=o[a++];for(let
|
|
569
|
+
`})}}function Kt(s,e=Math.random()){for(let t=s.length-1;t>0;t--){const r=Math.floor(e()*(t+1)),i=s[t];s[t]=s[r],s[r]=i}return s}class Zt{constructor(e,t,r=Math.random){const i=e**t,o=new Uint16Array(i);let a=i;for(let c=0;c<i;c++)o[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<i;c++)o[c]=c;a=0},this.reshuffle=function(){a=0},this.next=function(){const{samples:c}=this;a>=o.length&&(Kt(o,r),this.reshuffle());let h=o[a++];for(let m=0;m<t;m++)c[m]=(h%e+r())/e,h=Math.floor(h/e);return c}}}class Jt{constructor(e,t,r=Math.random){let i=0;for(const h of t)i+=h;const o=new Float32Array(i),a=[];let c=0;for(const h of t){const m=new Zt(e,h,r);m.samples=new Float32Array(o.buffer,c,m.samples.length),c+=m.samples.length*4,a.push(m)}this.samples=o,this.strataCount=e,this.next=function(){for(const h of a)h.next();return o},this.reshuffle=function(){for(const h of a)h.reshuffle()},this.reset=function(){for(const h of a)h.reset()}}}class er{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}}class tr extends n.DataTexture{constructor(e=1,t=1,r=8){super(new Float32Array(1),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.strata=r,this.sampler=null,this.generator=new er,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,r)}init(e=this.image.height,t=this.image.width,r=this.strata){const{image:i}=this;if(i.width===t&&i.height===e&&this.sampler!==null)return;const o=new Array(e*t).fill(4),a=new Jt(r,o,this.random);i.width=t,i.height=e,i.data=a.samples,this.sampler=a,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}}function rr(s,e=Math.random){for(let t=s.length-1;t>0;t--){const r=~~((e()-1e-6)*t),i=s[t];s[t]=s[r],s[r]=i}}function ar(s,e){s.fill(0);for(let t=0;t<e;t++)s[t]=1}class Ae{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){const{score:e,binaryPattern:t}=this;let r=1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==0)continue;const c=e[o];c<r&&(r=c,i=o)}return i}findCluster(){const{score:e,binaryPattern:t}=this;let r=-1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==1)continue;const c=e[o];c>r&&(r=c,i=o)}return i}setSigma(e){if(e===this.sigma)return;const t=~~(Math.sqrt(20*e**2)+1),r=2*t+1,i=new Float32Array(r*r),o=e*e;for(let a=-t;a<=t;a++)for(let c=-t;c<=t;c++){const h=(t+c)*r+a+t,m=a*a+c*c;i[h]=Math.E**(-m/(2*o))}this.lookupTable=i,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){const{binaryPattern:e,score:t,size:r}=this;t.fill(0);for(let i=0,o=e.length;i<o;i++)if(e[i]===0){const a=~~(i/r),c=i-a*r;this.updateScore(c,a,1),e[i]=1}else e[i]=0}updateScore(e,t,r){const{size:i,score:o,lookupTable:a}=this,c=this.radius,h=2*c+1;for(let m=-c;m<=c;m++)for(let d=-c;d<=c;d++){const f=(c+d)*h+m+c,l=a[f];let y=e+m;y=y<0?i+y:y%i;let p=t+d;p=p<0?i+p:p%i;const v=p*i+y;o[v]+=r*l}}addPointIndex(e){this.binaryPattern[e]=1;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}}class ir{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Ae(1),this.savedSamples=new Ae(1)}generate(){const{samples:e,savedSamples:t,sigma:r,majorityPointsRatio:i,size:o}=this;e.resize(o),e.setSigma(r);const a=Math.floor(o*o*i),c=e.binaryPattern;ar(c,a),rr(c,this.random);for(let f=0,l=c.length;f<l;f++)c[f]===1&&e.addPointIndex(f);for(;;){const f=e.findCluster();e.removePointIndex(f);const l=e.findVoid();if(f===l){e.addPointIndex(f);break}e.addPointIndex(l)}const h=new Uint32Array(o*o);t.copy(e);let m;for(m=e.count-1;m>=0;){const f=e.findCluster();e.removePointIndex(f),h[f]=m,m--}const d=o*o;for(m=t.count;m<d/2;){const f=t.findVoid();t.addPointIndex(f),h[f]=m,m++}for(t.invert();m<d;){const f=t.findCluster();t.removePointIndex(f),h[f]=m,m++}return{data:h,maxValue:d}}}function sr(s){return s>=3?4:s}function or(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}class nr extends n.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.size=e,this.channels=t,this.update()}update(){const e=this.channels,t=this.size,r=new ir;r.channels=e,r.size=t;const i=sr(e),o=or(i);(this.image.width!==t||o!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*i),this.format=o,this.dispose());const a=this.image.data;for(let c=0,h=e;c<h;c++){const m=r.generate(),d=m.data,f=m.maxValue;for(let l=0,y=d.length;l<y;l++){const p=d[l]/f;a[l*i+c]=p}}this.needsUpdate=!0}}const lr=`
|
|
570
570
|
|
|
571
571
|
struct PhysicalCamera {
|
|
572
572
|
|
|
@@ -3425,7 +3425,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3425
3425
|
|
|
3426
3426
|
}
|
|
3427
3427
|
|
|
3428
|
-
`;class Er extends oe{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new
|
|
3428
|
+
`;class Er extends oe{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new n.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new Mt},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new Xe},attributesArray:{value:new Lt},materialIndexAttribute:{value:new Be},materials:{value:new jt},textures:{value:new Fe().texture},lights:{value:new Ht},iesProfiles:{value:new Fe(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new Pt},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new n.Matrix4},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new tr},stratifiedOffsetTexture:{value:new nr(64,1)}},vertexShader:`
|
|
3429
3429
|
|
|
3430
3430
|
varying vec2 vUv;
|
|
3431
3431
|
void main() {
|
|
@@ -3892,7 +3892,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3892
3892
|
|
|
3893
3893
|
}
|
|
3894
3894
|
|
|
3895
|
-
`}),this.setValues(e)}}function*
|
|
3895
|
+
`}),this.setValues(e)}}function*Or(){const{_renderer:s,_fsQuad:e,_blendQuad:t,_primaryTarget:r,_blendTargets:i,_sobolTarget:o,_subframe:a,alpha:c,material:h}=this,m=new n.Vector4,d=new n.Vector4,f=t.material;let[l,y]=i;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NoBlending,h.opacity=1):(h.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NormalBlending);const[p,v,u,g]=a,x=r.width,b=r.height;h.resolution.set(x*u,b*g),h.sobolTexture=o.texture,h.stratifiedTexture.init(20,h.bounces+h.transmissiveBounces+5),h.stratifiedTexture.next(),h.seed++;const w=this.tiles.x||1,R=this.tiles.y||1,_=w*R,F=Math.ceil(x*u),Y=Math.ceil(b*g),le=Math.floor(p*x),ce=Math.floor(v*b),X=Math.ceil(F/w),Q=Math.ceil(Y/R);for(let W=0;W<R;W++)for(let L=0;L<w;L++){const ue=s.getRenderTarget(),Ve=s.autoClear,qe=s.getScissorTest();s.getScissor(m),s.getViewport(d);let K=L,fe=W;if(!this.stableTiles){const Z=this._currentTile%(w*R);K=Z%w,fe=~~(Z/w),this._currentTile=Z+1}const he=R-fe-1;r.scissor.set(le+K*X,ce+he*Q,Math.min(X,F-K*X),Math.min(Q,Y-he*Q)),r.viewport.set(le,ce,F,Y),s.setRenderTarget(r),s.setScissorTest(!0),s.autoClear=!1,e.render(s),s.setViewport(d),s.setScissor(m),s.setScissorTest(qe),s.setRenderTarget(ue),s.autoClear=Ve,c&&(f.target1=l.texture,f.target2=r.texture,s.setRenderTarget(y),t.render(s),s.setRenderTarget(ue)),this.samples+=1/_,L===w-1&&W===R-1&&(this.samples=Math.round(this.samples)),yield}[l,y]=[y,l]}}const Ce=new n.Color;class De{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 z(new Er),this._blendQuad=new z(new Rt),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Ft().generate(e),this._primaryTarget=new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),this._blendTargets=[new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter})],this._compileFunction=()=>{const t=this.compileMaterial(this._fsQuad._mesh);t.then(()=>{this._compilePromise===t&&(this._compilePromise=null)}),this._compilePromise=t},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){const{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let r=0;e.projectionMatrix.elements[15]>0&&(r=1),e.isEquirectCamera&&(r=2),t.setDefine("CAMERA_TYPE",r),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){const{_renderer:e,_primaryTarget:t,_blendTargets:r}=this,i=e.getRenderTarget(),o=e.getClearAlpha();e.getClearColor(Ce),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Ce,o),e.setRenderTarget(i),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=Or.call(this)),this._task.next())}}const P=new n.Vector2,Pe=new n.Vector2,$=new n.Spherical,j=new n.Color;class kr extends n.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,n.RGBAFormat,n.FloatType,n.EquirectangularReflectionMapping,n.RepeatWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;const{data:e,width:t,height:r}=this.image;for(let i=0;i<t;i++)for(let o=0;o<r;o++){Pe.set(t,r),P.set(i/t,o/r),P.x-=.5,P.y=1-P.y,$.theta=P.x*2*Math.PI,$.phi=P.y*Math.PI,$.radius=1,this.generationCallback($,P,Pe,j);const c=4*(o*t+i);e[c+0]=j.r,e[c+1]=j.g,e[c+2]=j.b,e[c+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}}const Ee=new n.Vector3;class Br extends kr{constructor(e=512){super(e,e),this.topColor=new n.Color().set(16777215),this.bottomColor=new n.Color().set(0),this.exponent=2,this.generationCallback=(t,r,i,o)=>{Ee.setFromSpherical(t);const a=Ee.y*.5+.5;o.lerpColors(this.bottomColor,this.topColor,a**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}}class Nr 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)}}class zr extends
|
|
3952
|
+
`}),this.setValues(e)}}class zr extends n.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
|
|
3953
3953
|
varying vec2 vUv;
|
|
3954
3954
|
void main() {
|
|
3955
3955
|
|
|
@@ -3974,4 +3974,4 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3974
3974
|
rayDirection.x *= flipEnvMap;
|
|
3975
3975
|
gl_FragColor = textureCube( envMap, rayDirection );
|
|
3976
3976
|
|
|
3977
|
-
}`}),this.depthWrite=!1,this.depthTest=!1}}class ke{constructor(e){this._renderer=e,this._quad=new z(new zr)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const i=e.images[0],o=this._renderer,a=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);const c=new l.WebGLRenderTarget(t,r,{type:l.FloatType,colorSpace:i.colorSpace}),h=i.height,d=Math.log2(h)-2,m=1/h,f=1/(3*Math.max(Math.pow(2,d),112));a.material.defines.CUBEUV_MAX_MIP=`${d}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=f,a.material.defines.CUBEUV_TEXEL_HEIGHT=m,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;const n=o.getRenderTarget(),x=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),a.render(o),o.setRenderTarget(n),o.autoClear=x;const p=new Uint16Array(t*r*4),v=new Float32Array(t*r*4);o.readRenderTargetPixels(c,0,0,t,r,v),c.dispose();for(let g=0,y=v.length;g<y;g++)p[g]=l.DataUtils.toHalfFloat(v[g]);const u=new l.DataTexture(p,t,r,l.RGBAFormat,l.HalfFloatType);return u.minFilter=l.LinearMipMapLinearFilter,u.magFilter=l.LinearFilter,u.wrapS=l.RepeatWrapping,u.wrapT=l.RepeatWrapping,u.mapping=l.EquirectangularReflectionMapping,u.needsUpdate=!0,u}dispose(){this._quad.dispose()}}function Hr(s){return s.extensions.get("EXT_float_blend")}const O=new l.Vector2;class Wr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new yt,this._pathTracer=new De(e),this._queueReset=!1,this._clock=new l.Clock,this._compilePromise=null,this._lowResPathTracer=new De(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new z(new Nr({map:null,transparent:!0,blending:l.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 l.Vector2(1024,1024),this.rasterizeSceneCallback=(t,r)=>{this._renderer.render(t,r)},this.renderToCanvasCallback=(t,r,i)=>{const o=r.autoClear;r.autoClear=!1,i.render(r),r.autoClear=o},this.setScene(new l.Scene,new l.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,r={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const i=this._generator;if(i.setObjects(e),this._buildAsync)return i.generateAsync(r.onProgress).then(o=>this._updateFromResults(e,t,o));{const o=i.generate();return this._updateFromResults(e,t,o)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,r=this._materials,i=this.textureSize,o=Vt(r);e.textures.setTextures(t,o,i.x,i.y),e.materials.updateFrom(r,o),this.reset()}updateLights(){const e=this.scene,t=this._renderer,r=this._pathTracer.material,i=qt(e),o=Gt(i);r.lights.updateFrom(i,o),r.iesProfiles.setTextures(t,o),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Br(16);const r=this._colorBackground;r.topColor.equals(e.background)||(r.topColor.set(e.background),r.bottomColor.set(e.background),r.update()),t.backgroundMap=r,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const r=new ke(this._renderer).generate(e.background);this._internalBackground=r,t.backgroundMap=r,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const r=new ke(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(r)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,r){const{materials:i,geometry:o,bvh:a,bvhChanged:c}=r;this._materials=i;const d=this._pathTracer.material;return c&&(d.bvh.updateFrom(a),d.attributesArray.updateFrom(o.attributes.normal,o.attributes.tangent,o.attributes.uv,o.attributes.color),d.materialIndexAttribute.updateFrom(o.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),r}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,o=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,o.material.opacity=0,i.start());const a=i.getDelta()*1e3,c=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Hr(r),e.alpha=t.alpha,this.renderToCanvas){const h=this._renderer,d=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?o.material.opacity=Math.min(o.material.opacity+a/this.fadeDuration,1):o.material.opacity=1),!this.enablePathTracing||this.samples<d||o.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const m=o.material.opacity;o.material.opacity=1-o.material.opacity,o.material.map=e.target.texture,o.render(h),o.material.opacity=m}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&o.material.opacity>0&&(o.material.opacity<1&&(o.material.blending=this.dynamicLowRes?l.AdditiveBlending:l.NormalBlending),o.material.map=t.target.texture,this.renderToCanvasCallback(t.target,h,o),o.material.blending=l.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(O);const e=Math.floor(this.renderScale*O.x),t=Math.floor(this.renderScale*O.y);if(this._pathTracer.getSize(O),O.x!==e||O.y!==t){const r=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*r),Math.floor(t*r))}}}}function B(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}class Lr{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.disposeTimer=null,this.convertedEnvTexture=null,this.lastResetTime=0,this.events=new T.TypedEventEmitter,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:.5,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let h=0;h<o.data.length;h++)a[h]=o.data[h]/255;const c=new A.DataTexture(a,r.width,r.height,A.RGBAFormat,A.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=B(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Wr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,this.pathTracer.environmentIntensity!==void 0&&(this.pathTracer.environmentIntensity=2),e.toneMapping!==A.ACESFilmicToneMapping&&(e.toneMapping=A.ACESFilmicToneMapping,e.toneMappingExposure=1.5),e.autoClear=!1,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.reset(),this.sceneInitialized=!1;const t=B(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return T.hasInternalRenderer(e)&&(r=e.getInternalRenderer()),T.hasInternalRenderer(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a,c,h;try{const d=i.__originalEnvironmentTexture;if(!i.environment&&!d)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,d&&d.mapping===A.EquirectangularReflectionMapping){let m=d;if(d.image instanceof HTMLImageElement)if(this.convertedEnvTexture)m=this.convertedEnvTexture;else{const n=this.convertToDataTexture(d);if(!n)throw new Error("Failed to convert environment texture to DataTexture");this.convertedEnvTexture=n,m=n}const f=i.environment;i.environment=m;try{const n=d.image;n&&!("data"in n&&n.data)&&n instanceof HTMLImageElement&&!n.complete&&await new Promise(x=>{n.onload=()=>{d.needsUpdate=!0,x()},n.onerror=()=>{x()},n.complete&&x()}),(a=this.pathTracer)==null||a.setScene(i,o),this.sceneInitialized=!0,i.environment=f}catch(n){throw i.environment=f,n}}else if(((c=i.environment)==null?void 0:c.mapping)===A.EquirectangularReflectionMapping)(h=this.pathTracer)==null||h.setScene(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(d){return console.warn("Scene initialization error:",d),e.render(t,r)}return null}accumulateSample(e,t,r){var o;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(a){console.warn("Failed to update lights for path tracing:",a)}const i=e.render(t,r);return i.ok?(this.accumulateOneSample(),this.sampleCount++,this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)):i}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&B(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),this.disposeTimer=setTimeout(()=>{this.disposeTimer=null,!this.disposed&&this.disposePathTracingResources()},100),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}reset(){const e=performance.now();e-this.lastResetTime<50||(this.lastResetTime=e,this.sampleCount=0,this.pathTracer&&(this.pathTracer.reset(),this.sceneInitialized=!1))}disposePathTracingResources(){if(this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer:",e)}this.pathTracer=null}if(this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.renderer){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;e&&(e.autoClear=!0)}this.sceneInitialized=!1,this.createAttempts=0}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.disposeTimer!==null&&(clearTimeout(this.disposeTimer),this.disposeTimer=null),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}}exports.ThreePathTracingService=Lr;
|
|
3977
|
+
}`}),this.depthWrite=!1,this.depthTest=!1}}class Oe{constructor(e){this._renderer=e,this._quad=new z(new zr)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const i=e.images[0],o=this._renderer,a=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);const c=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),h=i.height,m=Math.log2(h)-2,d=1/h,f=1/(3*Math.max(Math.pow(2,m),112));a.material.defines.CUBEUV_MAX_MIP=`${m}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=f,a.material.defines.CUBEUV_TEXEL_HEIGHT=d,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;const l=o.getRenderTarget(),y=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),a.render(o),o.setRenderTarget(l),o.autoClear=y;const p=new Uint16Array(t*r*4),v=new Float32Array(t*r*4);o.readRenderTargetPixels(c,0,0,t,r,v),c.dispose();for(let g=0,x=v.length;g<x;g++)p[g]=n.DataUtils.toHalfFloat(v[g]);const u=new n.DataTexture(p,t,r,n.RGBAFormat,n.HalfFloatType);return u.minFilter=n.LinearMipMapLinearFilter,u.magFilter=n.LinearFilter,u.wrapS=n.RepeatWrapping,u.wrapT=n.RepeatWrapping,u.mapping=n.EquirectangularReflectionMapping,u.needsUpdate=!0,u}dispose(){this._quad.dispose()}}function Hr(s){return s.extensions.get("EXT_float_blend")}const k=new n.Vector2;class Wr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new yt,this._pathTracer=new De(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new De(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new z(new Nr({map:null,transparent:!0,blending:n.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new n.Vector2(1024,1024),this.rasterizeSceneCallback=(t,r)=>{this._renderer.render(t,r)},this.renderToCanvasCallback=(t,r,i)=>{const o=r.autoClear;r.autoClear=!1,i.render(r),r.autoClear=o},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,r={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const i=this._generator;if(i.setObjects(e),this._buildAsync)return i.generateAsync(r.onProgress).then(o=>this._updateFromResults(e,t,o));{const o=i.generate();return this._updateFromResults(e,t,o)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,r=this._materials,i=this.textureSize,o=Vt(r);e.textures.setTextures(t,o,i.x,i.y),e.materials.updateFrom(r,o),this.reset()}updateLights(){const e=this.scene,t=this._renderer,r=this._pathTracer.material,i=qt(e),o=Gt(i);r.lights.updateFrom(i,o),r.iesProfiles.setTextures(t,o),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Br(16);const r=this._colorBackground;r.topColor.equals(e.background)||(r.topColor.set(e.background),r.bottomColor.set(e.background),r.update()),t.backgroundMap=r,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const r=new Oe(this._renderer).generate(e.background);this._internalBackground=r,t.backgroundMap=r,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const r=new Oe(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(r)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,r){const{materials:i,geometry:o,bvh:a,bvhChanged:c}=r;this._materials=i;const m=this._pathTracer.material;return c&&(m.bvh.updateFrom(a),m.attributesArray.updateFrom(o.attributes.normal,o.attributes.tangent,o.attributes.uv,o.attributes.color),m.materialIndexAttribute.updateFrom(o.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),r}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,o=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,o.material.opacity=0,i.start());const a=i.getDelta()*1e3,c=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Hr(r),e.alpha=t.alpha,this.renderToCanvas){const h=this._renderer,m=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?o.material.opacity=Math.min(o.material.opacity+a/this.fadeDuration,1):o.material.opacity=1),!this.enablePathTracing||this.samples<m||o.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const d=o.material.opacity;o.material.opacity=1-o.material.opacity,o.material.map=e.target.texture,o.render(h),o.material.opacity=d}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&o.material.opacity>0&&(o.material.opacity<1&&(o.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),o.material.map=t.target.texture,this.renderToCanvasCallback(t.target,h,o),o.material.blending=n.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(k);const e=Math.floor(this.renderScale*k.x),t=Math.floor(this.renderScale*k.y);if(this._pathTracer.getSize(k),k.x!==e||k.y!==t){const r=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*r),Math.floor(t*r))}}}}function B(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}class Lr{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.disposeTimer=null,this.convertedEnvTexture=null,this.lastResetTime=0,this.events=new T.TypedEventEmitter,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:.5,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var i;const r=[];e.traverse(o=>{var a;(a=o.userData)!=null&&a[T.CONTACT_SHADOW_HELPER_FLAG]&&o.visible&&r.push(o)}),r.forEach(o=>o.visible=!1);try{(i=this.pathTracer)==null||i.setScene(e,t)}finally{r.forEach(o=>o.visible=!0)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let h=0;h<o.data.length;h++)a[h]=o.data[h]/255;const c=new A.DataTexture(a,r.width,r.height,A.RGBAFormat,A.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=B(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Wr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,this.pathTracer.environmentIntensity!==void 0&&(this.pathTracer.environmentIntensity=2),e.toneMapping!==A.ACESFilmicToneMapping&&(e.toneMapping=A.ACESFilmicToneMapping,e.toneMappingExposure=1.5),e.autoClear=!1,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.reset(),this.sceneInitialized=!1;const t=B(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return T.hasInternalRenderer(e)&&(r=e.getInternalRenderer()),T.hasInternalRenderer(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.mapping===A.EquirectangularReflectionMapping){let h=c;if(c.image instanceof HTMLImageElement)if(this.convertedEnvTexture)h=this.convertedEnvTexture;else{const d=this.convertToDataTexture(c);if(!d)throw new Error("Failed to convert environment texture to DataTexture");this.convertedEnvTexture=d,h=d}const m=i.environment;i.environment=h;try{const d=c.image;d&&!("data"in d&&d.data)&&d instanceof HTMLImageElement&&!d.complete&&await new Promise(f=>{d.onload=()=>{c.needsUpdate=!0,f()},d.onerror=()=>{f()},d.complete&&f()}),this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0,i.environment=m}catch(d){throw i.environment=m,d}}else if(((a=i.environment)==null?void 0:a.mapping)===A.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(a){console.warn("Failed to update lights for path tracing:",a)}const i=e.render(t,r);return i.ok?(this.accumulateOneSample(),this.sampleCount++,this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)):i}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&B(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),this.disposeTimer=setTimeout(()=>{this.disposeTimer=null,!this.disposed&&this.disposePathTracingResources()},100),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}reset(){const e=performance.now();e-this.lastResetTime<50||(this.lastResetTime=e,this.sampleCount=0,this.pathTracer&&(this.pathTracer.reset(),this.sceneInitialized=!1))}disposePathTracingResources(){if(this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer:",e)}this.pathTracer=null}if(this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.renderer){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;e&&(e.autoClear=!0)}this.sceneInitialized=!1,this.createAttempts=0}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.disposeTimer!==null&&(clearTimeout(this.disposeTimer),this.disposeTimer=null),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}}exports.ThreePathTracingService=Lr;
|