softbox 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/{ThreePathTracingService-DdrIay3N.cjs → ThreePathTracingService-CL_k3WTj.cjs} +13 -13
- package/dist/{ThreePathTracingService-DlCiqA08.js → ThreePathTracingService-DbqedkL2.js} +87 -87
- package/dist/{index-BA_1qZxy.cjs → index-BtN2xOzS.cjs} +3 -3
- package/dist/{index-DoB8YjQ9.js → index-DXbG9xpu.js} +48 -31
- package/dist/simple-viewer.cjs +1 -1
- package/dist/simple-viewer.es.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,9 +212,11 @@ const options: SimpleViewerOptions = {
|
|
|
212
212
|
|
|
213
213
|
// The procedural studio environment lights the scene by default (zero network
|
|
214
214
|
// requests). Point environment.url at an HDR/EXR/image to use your own.
|
|
215
|
-
environment: { environmentIntensity: 0.
|
|
215
|
+
environment: { environmentIntensity: 0.5 },
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
// Khronos PBR Neutral tone mapping by default — keeps saturated material
|
|
218
|
+
// colours through the highlight rolloff (see renderer.toneMapping to change).
|
|
219
|
+
renderer: { antialias: true, toneMappingExposure: 1.0 },
|
|
218
220
|
|
|
219
221
|
controls: { type: ControlType.OrbitControls, enableDamping: true, autoRotate: false },
|
|
220
222
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("three"),T=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("three"),T=require("./index-BtN2xOzS.cjs");function Xe(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const N=Xe(n);function Qe(s){switch(s){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function Ke(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;case 3:return n.RGBAFormat;case 4:return n.RGBAFormat}}function pe(s){switch(s){case 1:return n.RedIntegerFormat;case 2:return n.RGIntegerFormat;case 3:return n.RGBAIntegerFormat;case 4:return n.RGBAIntegerFormat}}class ze extends n.DataTexture{constructor(){super(),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,r=e.itemSize,i=e.count;if(t!==null){if(r*i%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=i*r/t}const o=e.itemSize,a=e.count,c=e.normalized,h=e.array.constructor,m=h.BYTES_PER_ELEMENT;let d=this._forcedType,f=o;if(d===null)switch(h){case Float32Array:d=n.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:d=n.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:d=n.IntType;break}let l,y,p,v,u=Qe(o);switch(d){case n.FloatType:p=1,y=Ke(o),c&&m===1?(v=h,u+="8",h===Uint8Array?l=n.UnsignedByteType:(l=n.ByteType,u+="_SNORM")):(v=Float32Array,u+="32F",l=n.FloatType);break;case n.IntType:u+=m*8+"I",p=c?Math.pow(2,h.BYTES_PER_ELEMENT*8-1):1,y=pe(o),m===1?(v=Int8Array,l=n.ByteType):m===2?(v=Int16Array,l=n.ShortType):(v=Int32Array,l=n.IntType);break;case n.UnsignedIntType:u+=m*8+"UI",p=c?Math.pow(2,h.BYTES_PER_ELEMENT*8-1):1,y=pe(o),m===1?(v=Uint8Array,l=n.UnsignedByteType):m===2?(v=Uint16Array,l=n.UnsignedShortType):(v=Uint32Array,l=n.UnsignedIntType);break}f===3&&(y===n.RGBAFormat||y===n.RGBAIntegerFormat)&&(f=4);const g=Math.ceil(Math.sqrt(a))||1,x=f*g*g,b=new v(x),w=e.normalized;e.normalized=!1;for(let R=0;R<a;R++){const _=f*R;b[_]=e.getX(R)/p,o>=2&&(b[_+1]=e.getY(R)/p),o>=3&&(b[_+2]=e.getZ(R)/p,f===4&&(b[_+3]=1)),o>=4&&(b[_+3]=e.getW(R)/p)}e.normalized=w,this.internalFormat=u,this.format=y,this.type=l,this.image.width=g,this.image.height=g,this.image.data=b,this.needsUpdate=!0,this.dispose(),e.itemSize=r,e.count=i}}class He extends ze{constructor(){super(),this._forcedType=n.UnsignedIntType}}class We extends ze{constructor(){super(),this._forcedType=n.FloatType}}class Ze{constructor(){this.index=new He,this.position=new We,this.bvhBounds=new n.DataTexture,this.bvhContents=new n.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(et(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const r=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==r.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const i=T.getIndexArray(T.getVertexCount(t));this._cachedIndexAttr=new n.BufferAttribute(i,1,!1)}Je(t,r,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:r,bvhContents:i}=this;e&&e.dispose(),t&&t.dispose(),r&&r.dispose(),i&&i.dispose()}}function Je(s,e,t){const r=t.array,i=s.index?s.index.array:null;for(let o=0,a=e.length;o<a;o++){const c=3*o,h=3*e[o];for(let m=0;m<3;m++)r[c+m]=i?i[h+m]:h+m}}function et(s,e,t){const r=s._roots;if(r.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const i=r[0],o=new Uint16Array(i),a=new Uint32Array(i),c=new Float32Array(i),h=i.byteLength/T.BYTES_PER_NODE,m=2*Math.ceil(Math.sqrt(h/2)),d=new Float32Array(4*m*m),f=Math.ceil(Math.sqrt(h)),l=new Uint32Array(2*f*f);for(let y=0;y<h;y++){const p=y*T.BYTES_PER_NODE/4,v=p*2,u=T.BOUNDING_DATA_INDEX(p);for(let g=0;g<3;g++)d[8*y+0+g]=c[u+0+g],d[8*y+4+g]=c[u+3+g];if(T.IS_LEAF(v,o)){const g=T.COUNT(v,o),x=T.OFFSET(p,a),b=T.LEAFNODE_MASK_32|g;l[y*2+0]=b,l[y*2+1]=x}else{const g=a[p+6],x=T.SPLIT_AXIS(p,a);l[y*2+0]=x,l[y*2+1]=g}}e.image.data=d,e.image.width=m,e.image.height=m,e.format=n.RGBAFormat,e.type=n.FloatType,e.internalFormat="RGBA32F",e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=l,t.image.width=f,t.image.height=f,t.format=n.RGIntegerFormat,t.type=n.UnsignedIntType,t.internalFormat="RG32UI",t.minFilter=n.NearestFilter,t.magFilter=n.NearestFilter,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const tt=`
|
|
2
2
|
|
|
3
3
|
// A stack of uint32 indices can can store the indices for
|
|
4
4
|
// a perfectly balanced tree with a depth up to 31. Lower stack
|
|
@@ -294,7 +294,7 @@ struct BVH {
|
|
|
294
294
|
usampler2D bvhContents;
|
|
295
295
|
|
|
296
296
|
};
|
|
297
|
-
`;function Le(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function H(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new n.BufferAttribute(new t(i*o),i,r)}function B(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function it(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function st(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function ot(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function nt(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function lt(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;it(s);const c=s[0].index!==null,h=c?st(s):-1,m=ot(s);if(nt(t,h,m),r){let f=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(f,v,l),f+=v}}if(c){let f=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(h),1,!1)),f=!0),f||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!f&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let f=0,l=d.length;f<l;f++){let y=!1;const p=d[f];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,H(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||Le(R,u,v),v+=R.count}}}function ct(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let h=s.getAttribute("materialIndex");if(!h||h.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),h=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",h)}const m=h.array;for(let d=0;d<c.length;d++){const f=c[d],l=f.start,y=f.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[f.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function ut(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function ne(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function ge(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function ve(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${ne(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class ft{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=ge(t),this.primitiveCount=r,this.skeletonHash=ve(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===ge(t)&&this.skeletonHash===ve(e)&&this.primitiveCount===r)}}const A=new n.Vector3,C=new n.Vector3,D=new n.Vector3,xe=new n.Vector4,U=new n.Vector3,ee=new n.Vector3,ye=new n.Vector4,be=new n.Vector4,G=new n.Matrix4,Te=new n.Matrix4;function we(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ye.fromBufferAttribute(i.attributes.skinIndex,e),be.fromBufferAttribute(i.attributes.skinWeight,e),G.elements.fill(0);for(let c=0;c<4;c++){const h=be.getComponent(c);if(h!==0){const m=ye.getComponent(c);Te.multiplyMatrices(o[m].matrixWorld,a[m]),ht(G,Te,h)}}return G.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(G),t}function te(s,e,t,r,i){U.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],h=s[o];c!==0&&(ee.fromBufferAttribute(h,r),t?U.addScaledVector(ee,c):U.addScaledVector(ee.sub(i),c))}i.add(U)}function ht(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function dt(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let h=0;h<o;h++){const m=i.getComponent(a,h),d=i.getComponent(a+2,h);i.setComponent(a,h,d),i.setComponent(a+2,h,m)}}return s}function mt(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,h=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),h.position||t.setAttribute("position",H(c.position)),o&&!h.normal&&c.normal&&t.setAttribute("normal",H(c.normal)),a&&!h.tangent&&c.tangent&&t.setAttribute("tangent",H(c.tangent)),B(r.index,t.index),B(c.position,h.position),o&&B(c.normal,h.normal),a&&B(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++)A.fromBufferAttribute(m,x),d&&C.fromBufferAttribute(d,x),f&&(xe.fromBufferAttribute(f,x),D.fromBufferAttribute(f,x)),u&&(l&&te(l,u,v,x,A),y&&te(y,u,v,x,C),p&&te(p,u,v,x,D)),s.isSkinnedMesh&&(s.applyBoneTransform(x,A),d&&we(s,x,C),f&&we(s,x,D)),i&&A.applyMatrix4(s.matrixWorld),h.position.setXYZ(x,A.x,A.y,A.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,xe.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(h[b]||t.setAttribute(b,H(c[b])),B(c[b],h[b]),Le(c[b],h[b]))}return s.matrixWorld.determinant()<0&&dt(t),t}class pt extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new ft}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!B(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(mt(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ie=0,Ue=1,Ge=2;function gt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function vt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function xt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else lt(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class yt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return gt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],h=c.uuid;r.delete(h);let m=e.get(h);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new pt,e.set(h,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&ut(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],h=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);h.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}xt(h,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let f=ie;return d?f=Ge:c.includes(!1)&&(f=Ue),{changeType:f,materials:vt(a),geometry:e}}}function bt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function Tt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class wt{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new yt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(f=>{f.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,h=bt(c),{lights:m,iesTextures:d}=Tt(o);if(a.changeType!==ie&&ct(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===Ge){const f={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,f):this.bvh=new T.MeshBVH(r,f)}else a.changeType===Ue&&this.bvh.refit()}return{bvhChanged:a.changeType!==ie,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:h,objects:o}}}const Rt=new n.OrthographicCamera(-1,1,1,-1,0,1);class It 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 St=new It;class N{constructor(e){this._mesh=new n.Mesh(St,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Rt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class le extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class _t extends le{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
297
|
+
`;function Le(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function 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 k(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function it(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function st(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function ot(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function nt(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function lt(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;it(s);const c=s[0].index!==null,h=c?st(s):-1,m=ot(s);if(nt(t,h,m),r){let f=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(f,v,l),f+=v}}if(c){let f=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(h),1,!1)),f=!0),f||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!f&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let f=0,l=d.length;f<l;f++){let y=!1;const p=d[f];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,H(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||Le(R,u,v),v+=R.count}}}function ct(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let h=s.getAttribute("materialIndex");if(!h||h.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),h=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",h)}const m=h.array;for(let d=0;d<c.length;d++){const f=c[d],l=f.start,y=f.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[f.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function ut(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function ne(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function ge(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function ve(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${ne(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class ft{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=ge(t),this.primitiveCount=r,this.skeletonHash=ve(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===ge(t)&&this.skeletonHash===ve(e)&&this.primitiveCount===r)}}const A=new n.Vector3,M=new n.Vector3,C=new n.Vector3,xe=new n.Vector4,U=new n.Vector3,ee=new n.Vector3,ye=new n.Vector4,be=new n.Vector4,G=new n.Matrix4,Te=new n.Matrix4;function we(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ye.fromBufferAttribute(i.attributes.skinIndex,e),be.fromBufferAttribute(i.attributes.skinWeight,e),G.elements.fill(0);for(let c=0;c<4;c++){const h=be.getComponent(c);if(h!==0){const m=ye.getComponent(c);Te.multiplyMatrices(o[m].matrixWorld,a[m]),ht(G,Te,h)}}return G.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(G),t}function te(s,e,t,r,i){U.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],h=s[o];c!==0&&(ee.fromBufferAttribute(h,r),t?U.addScaledVector(ee,c):U.addScaledVector(ee.sub(i),c))}i.add(U)}function ht(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function dt(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let h=0;h<o;h++){const m=i.getComponent(a,h),d=i.getComponent(a+2,h);i.setComponent(a,h,d),i.setComponent(a+2,h,m)}}return s}function mt(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,h=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),h.position||t.setAttribute("position",H(c.position)),o&&!h.normal&&c.normal&&t.setAttribute("normal",H(c.normal)),a&&!h.tangent&&c.tangent&&t.setAttribute("tangent",H(c.tangent)),k(r.index,t.index),k(c.position,h.position),o&&k(c.normal,h.normal),a&&k(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++)A.fromBufferAttribute(m,x),d&&M.fromBufferAttribute(d,x),f&&(xe.fromBufferAttribute(f,x),C.fromBufferAttribute(f,x)),u&&(l&&te(l,u,v,x,A),y&&te(y,u,v,x,M),p&&te(p,u,v,x,C)),s.isSkinnedMesh&&(s.applyBoneTransform(x,A),d&&we(s,x,M),f&&we(s,x,C)),i&&A.applyMatrix4(s.matrixWorld),h.position.setXYZ(x,A.x,A.y,A.z),d&&(i&&M.applyNormalMatrix(g),h.normal.setXYZ(x,M.x,M.y,M.z)),f&&(i&&C.transformDirection(s.matrixWorld),h.tangent.setXYZW(x,C.x,C.y,C.z,xe.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(h[b]||t.setAttribute(b,H(c[b])),k(c[b],h[b]),Le(c[b],h[b]))}return s.matrixWorld.determinant()<0&&dt(t),t}class pt extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new ft}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!k(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(mt(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ie=0,Ue=1,Ge=2;function gt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function vt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function xt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else lt(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class yt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return gt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],h=c.uuid;r.delete(h);let m=e.get(h);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new pt,e.set(h,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&ut(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],h=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);h.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}xt(h,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let f=ie;return d?f=Ge:c.includes(!1)&&(f=Ue),{changeType:f,materials:vt(a),geometry:e}}}function bt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function Tt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class wt{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new yt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(f=>{f.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,h=bt(c),{lights:m,iesTextures:d}=Tt(o);if(a.changeType!==ie&&ct(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===Ge){const f={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,f):this.bvh=new T.MeshBVH(r,f)}else a.changeType===Ue&&this.bvh.refit()}return{bvhChanged:a.changeType!==ie,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:h,objects:o}}}const Rt=new n.OrthographicCamera(-1,1,1,-1,0,1);class It 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 St=new It;class B{constructor(e){this._mesh=new n.Mesh(St,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Rt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class le extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class _t extends le{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
298
298
|
|
|
299
299
|
varying vec2 vUv;
|
|
300
300
|
|
|
@@ -485,7 +485,7 @@ struct BVH {
|
|
|
485
485
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
`,
|
|
488
|
+
`,At=`
|
|
489
489
|
|
|
490
490
|
// Seeds
|
|
491
491
|
uniform sampler2D sobolTexture;
|
|
@@ -528,7 +528,7 @@ struct BVH {
|
|
|
528
528
|
${q(3)}
|
|
529
529
|
${q(4)}
|
|
530
530
|
|
|
531
|
-
`;class
|
|
531
|
+
`;class Mt extends le{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 Ct{generate(e,t=256){const r=new n.WebGLRenderTarget(t,t,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new N(new At);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class Dt 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 Pt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof Dt?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function re(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Re(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Et(s,e,t){return .2126*s+.7152*e+.0722*t}function Ot(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 kt{constructor(){const e=new n.DataTexture(re(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(re(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(re(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Ot(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=Et(w,R,_);g+=F,d+=F,a[b]=F,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;f+=g,h[u]=g,m[u]=f}if(f!==0)for(let u=0,g=h.length;u<g;u++)h[u]/=f,m[u]/=f;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Re(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Re(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const ae=6,Bt=0,Nt=1,zt=2,Ht=3,Wt=4,S=new n.Vector3,I=new n.Vector3,Ie=new n.Matrix4,E=new n.Quaternion,Se=new n.Vector3,O=new n.Vector3,Lt=new n.Vector3(0,1,0);class Ut{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*ae,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let h=0,m=e.length;h<m;h++){const d=e[h],f=h*ae*4;let l=0;for(let p=0;p<ae*4;p++)a[f+p]=0;d.getWorldPosition(I),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z;let y=Bt;if(d.isRectAreaLight&&d.isCircular?y=Nt:d.isSpotLight?y=zt:d.isDirectionalLight?y=Ht:d.isPointLight&&(y=Wt),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;Se.setFromMatrixPosition(d.matrixWorld),O.setFromMatrixPosition(d.target.matrixWorld),Ie.lookAt(Se,O,Lt),E.setFromRotationMatrix(Ie),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=ne(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function _e(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let h=0;h<o;h++){const m=4*h,d=e*h;for(let f=0;f<r;f++)t[i+m+f]=e>=f+1?s[d+f]/c:0}}class Gt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:h}=o,d=a*c*4*e;let f=t.itemSize;f===3&&(f=4),_e(r.image.data,f,h,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let f=0,l=r;f<l;f++)if(e[f].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const f=new We;i.push(f)}for(;i.length>r;)i.pop();for(let f=0,l=r;f<l;f++)i[f].updateFrom(e[f]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:m,height:d}=c;for(let f=0,l=r;f<l;f++){const y=i[f],v=m*d*4*f;let u=e[f].itemSize;u===3&&(u=4),_e(y.image.data,u,h,4,v)}this.dispose(),this.needsUpdate=!0}}class Vt extends Gt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ce(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function se(s){return`${s.source.uuid}:${s.colorSpace}`}function qt(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=se(o);e.has(a)||(e.add(a),t.push(o))}return t}function $t(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ce)}function jt(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 qt(t).sort(ce)}function Yt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ce)}const qe=45,Fe=qe*4;class Xt{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 Qt 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 Xt}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=se(p[v]);return f[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*qe,h=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,f={};for(let p=0,v=t.length;p<v;p++)f[se(t[p])]=p;m.width!==h&&(this.dispose(),m.data=new Float32Array(h*h*4),m.width=h,m.height=h);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Fe;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Fe;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=ne(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const Me=new n.Color;function Kt(s){return s?`${s.uuid}:${s.version}`:null}function Zt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Ae extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Zt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new N(new Jt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(Me);const h=t.length||1;(r!==this.width||i!==this.height||this.depth!==h)&&(this.setSize(r,i,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;const m=this.fsQuad,d=this.hashes;let f=!1;for(let l=0,y=h;l<y;l++){const p=t[l],v=Kt(p);p&&(d[l]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),m.material.map=p,e.setRenderTarget(this,l),m.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,d[l]=v,f=!0)}return m.material.map=null,e.setClearColor(Me,c),e.setRenderTarget(o),e.toneMapping=a,f}dispose(){super.dispose(),this.fsQuad.dispose()}}class Jt extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
553
|
+
`})}}class Ct{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 B(new Mt);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class Dt 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 Pt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof Dt?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function re(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Re(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Et(s,e,t){return .2126*s+.7152*e+.0722*t}function Ot(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 kt{constructor(){const e=new n.DataTexture(re(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(re(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(re(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Ot(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=Et(w,R,_);g+=F,d+=F,a[b]=F,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;f+=g,h[u]=g,m[u]=f}if(f!==0)for(let u=0,g=h.length;u<g;u++)h[u]/=f,m[u]/=f;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Re(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Re(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const ae=6,Bt=0,Nt=1,zt=2,Ht=3,Wt=4,S=new n.Vector3,I=new n.Vector3,Ie=new n.Matrix4,P=new n.Quaternion,Se=new n.Vector3,E=new n.Vector3,Lt=new n.Vector3(0,1,0);class Ut{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*ae,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let h=0,m=e.length;h<m;h++){const d=e[h],f=h*ae*4;let l=0;for(let p=0;p<ae*4;p++)a[f+p]=0;d.getWorldPosition(I),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z;let y=Bt;if(d.isRectAreaLight&&d.isCircular?y=Nt:d.isSpotLight?y=zt:d.isDirectionalLight?y=Ht:d.isPointLight&&(y=Wt),a[f+l++]=y,a[f+l++]=d.color.r,a[f+l++]=d.color.g,a[f+l++]=d.color.b,a[f+l++]=d.intensity,d.getWorldQuaternion(P),d.isRectAreaLight)S.set(d.width,0,0).applyQuaternion(P),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,d.height,0).applyQuaternion(P),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=S.cross(I).length()*(d.isCircular?Math.PI/4:1);else if(d.isSpotLight){const p=d.radius||0;Se.setFromMatrixPosition(d.matrixWorld),E.setFromMatrixPosition(d.target.matrixWorld),Ie.lookAt(Se,E,Lt),P.setFromRotationMatrix(Ie),S.set(1,0,0).applyQuaternion(P),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,1,0).applyQuaternion(P),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=Math.PI*p*p,a[f+l++]=p,a[f+l++]=d.decay,a[f+l++]=d.distance,a[f+l++]=Math.cos(d.angle),a[f+l++]=Math.cos(d.angle*(1-d.penumbra)),a[f+l++]=d.iesMap?t.indexOf(d.iesMap):-1}else if(d.isPointLight){const p=S.setFromMatrixPosition(d.matrixWorld);a[f+l++]=p.x,a[f+l++]=p.y,a[f+l++]=p.z,l++,l+=4,l+=1,a[f+l++]=d.decay,a[f+l++]=d.distance}else if(d.isDirectionalLight){const p=S.setFromMatrixPosition(d.matrixWorld),v=I.setFromMatrixPosition(d.target.matrixWorld);E.subVectors(p,v).normalize(),a[f+l++]=E.x,a[f+l++]=E.y,a[f+l++]=E.z}}this.count=e.length;const c=ne(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function _e(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let h=0;h<o;h++){const m=4*h,d=e*h;for(let f=0;f<r;f++)t[i+m+f]=e>=f+1?s[d+f]/c:0}}class Gt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:h}=o,d=a*c*4*e;let f=t.itemSize;f===3&&(f=4),_e(r.image.data,f,h,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let f=0,l=r;f<l;f++)if(e[f].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const f=new We;i.push(f)}for(;i.length>r;)i.pop();for(let f=0,l=r;f<l;f++)i[f].updateFrom(e[f]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:m,height:d}=c;for(let f=0,l=r;f<l;f++){const y=i[f],v=m*d*4*f;let u=e[f].itemSize;u===3&&(u=4),_e(y.image.data,u,h,4,v)}this.dispose(),this.needsUpdate=!0}}class Vt extends Gt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ce(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function se(s){return`${s.source.uuid}:${s.colorSpace}`}function qt(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=se(o);e.has(a)||(e.add(a),t.push(o))}return t}function $t(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ce)}function jt(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 qt(t).sort(ce)}function Yt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ce)}const qe=45,Fe=qe*4;class Xt{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 Qt 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 Xt}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=se(p[v]);return f[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*qe,h=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,f={};for(let p=0,v=t.length;p<v;p++)f[se(t[p])]=p;m.width!==h&&(this.dispose(),m.data=new Float32Array(h*h*4),m.width=h,m.height=h);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Fe;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Fe;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=ne(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const Ae=new n.Color;function Kt(s){return s?`${s.uuid}:${s.version}`:null}function Zt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Me extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Zt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new B(new Jt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(Ae);const 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=Kt(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(Ae,c),e.setRenderTarget(o),e.toneMapping=a,f}dispose(){super.dispose(),this.fsQuad.dispose()}}class Jt 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
|
|
|
@@ -2493,7 +2493,7 @@ struct BVH {
|
|
|
2493
2493
|
|
|
2494
2494
|
}
|
|
2495
2495
|
|
|
2496
|
-
`,
|
|
2496
|
+
`,Ar=`
|
|
2497
2497
|
|
|
2498
2498
|
// See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
2499
2499
|
float velvetD( float cosThetaH, float roughness ) {
|
|
@@ -2590,7 +2590,7 @@ struct BVH {
|
|
|
2590
2590
|
|
|
2591
2591
|
}
|
|
2592
2592
|
|
|
2593
|
-
`,
|
|
2593
|
+
`,Mr=`
|
|
2594
2594
|
|
|
2595
2595
|
#ifndef FOG_CHECK_ITERATIONS
|
|
2596
2596
|
#define FOG_CHECK_ITERATIONS 30
|
|
@@ -3425,7 +3425,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3425
3425
|
|
|
3426
3426
|
}
|
|
3427
3427
|
|
|
3428
|
-
`;class Br extends le{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new n.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new Pt},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new Ze},attributesArray:{value:new Vt},materialIndexAttribute:{value:new He},materials:{value:new Qt},textures:{value:new
|
|
3428
|
+
`;class Br extends le{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new n.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new Pt},cameraWorldMatrix:{value:new n.Matrix4},invProjectionMatrix:{value:new n.Matrix4},bvh:{value:new Ze},attributesArray:{value:new Vt},materialIndexAttribute:{value:new He},materials:{value:new Qt},textures:{value:new Me().texture},lights:{value:new Ut},iesProfiles:{value:new Me(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new kt},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 ir},stratifiedOffsetTexture:{value:new ur(64,1)}},vertexShader:`
|
|
3429
3429
|
|
|
3430
3430
|
varying vec2 vUv;
|
|
3431
3431
|
void main() {
|
|
@@ -3469,7 +3469,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3469
3469
|
|
|
3470
3470
|
${De}
|
|
3471
3471
|
${Ve}
|
|
3472
|
-
${
|
|
3472
|
+
${At}
|
|
3473
3473
|
|
|
3474
3474
|
#define rand(v) sobol(v)
|
|
3475
3475
|
#define rand2(v) sobol2(v)
|
|
@@ -3558,9 +3558,9 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3558
3558
|
${gr}
|
|
3559
3559
|
${vr}
|
|
3560
3560
|
|
|
3561
|
-
${Ar}
|
|
3562
|
-
${_r}
|
|
3563
3561
|
${Mr}
|
|
3562
|
+
${_r}
|
|
3563
|
+
${Ar}
|
|
3564
3564
|
${Fr}
|
|
3565
3565
|
${Sr}
|
|
3566
3566
|
${Ir}
|
|
@@ -3892,7 +3892,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3892
3892
|
|
|
3893
3893
|
}
|
|
3894
3894
|
|
|
3895
|
-
`}),this.setValues(e)}}function*Nr(){const{_renderer:s,_fsQuad:e,_blendQuad:t,_primaryTarget:r,_blendTargets:i,_sobolTarget:o,_subframe:a,alpha:c,material:h}=this,m=new n.Vector4,d=new n.Vector4,f=t.material;let[l,y]=i;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NoBlending,h.opacity=1):(h.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NormalBlending);const[p,v,u,g]=a,x=r.width,b=r.height;h.resolution.set(x*u,b*g),h.sobolTexture=o.texture,h.stratifiedTexture.init(20,h.bounces+h.transmissiveBounces+5),h.stratifiedTexture.next(),h.seed++;const w=this.tiles.x||1,R=this.tiles.y||1,_=w*R,F=Math.ceil(x*u),X=Math.ceil(b*g),ue=Math.floor(p*x),fe=Math.floor(v*b),Q=Math.ceil(F/w),K=Math.ceil(X/R);for(let W=0;W<R;W++)for(let L=0;L<w;L++){const he=s.getRenderTarget(),je=s.autoClear,Ye=s.getScissorTest();s.getScissor(m),s.getViewport(d);let Z=L,de=W;if(!this.stableTiles){const J=this._currentTile%(w*R);Z=J%w,de=~~(J/w),this._currentTile=J+1}const me=R-de-1;r.scissor.set(ue+Z*Q,fe+me*K,Math.min(Q,F-Z*Q),Math.min(K,X-me*K)),r.viewport.set(ue,fe,F,X),s.setRenderTarget(r),s.setScissorTest(!0),s.autoClear=!1,e.render(s),s.setViewport(d),s.setScissor(m),s.setScissorTest(Ye),s.setRenderTarget(he),s.autoClear=je,c&&(f.target1=l.texture,f.target2=r.texture,s.setRenderTarget(y),t.render(s),s.setRenderTarget(he)),this.samples+=1/_,L===w-1&&W===R-1&&(this.samples=Math.round(this.samples)),yield}[l,y]=[y,l]}}const Pe=new n.Color;class Ee{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener("recompilation",this._compileFunction),e.addEventListener("recompilation",this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new n.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new n.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new
|
|
3895
|
+
`}),this.setValues(e)}}function*Nr(){const{_renderer:s,_fsQuad:e,_blendQuad:t,_primaryTarget:r,_blendTargets:i,_sobolTarget:o,_subframe:a,alpha:c,material:h}=this,m=new n.Vector4,d=new n.Vector4,f=t.material;let[l,y]=i;for(;;){c?(f.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NoBlending,h.opacity=1):(h.opacity=this._opacityFactor/(this.samples+1),h.blending=n.NormalBlending);const[p,v,u,g]=a,x=r.width,b=r.height;h.resolution.set(x*u,b*g),h.sobolTexture=o.texture,h.stratifiedTexture.init(20,h.bounces+h.transmissiveBounces+5),h.stratifiedTexture.next(),h.seed++;const w=this.tiles.x||1,R=this.tiles.y||1,_=w*R,F=Math.ceil(x*u),X=Math.ceil(b*g),ue=Math.floor(p*x),fe=Math.floor(v*b),Q=Math.ceil(F/w),K=Math.ceil(X/R);for(let W=0;W<R;W++)for(let L=0;L<w;L++){const he=s.getRenderTarget(),je=s.autoClear,Ye=s.getScissorTest();s.getScissor(m),s.getViewport(d);let Z=L,de=W;if(!this.stableTiles){const J=this._currentTile%(w*R);Z=J%w,de=~~(J/w),this._currentTile=J+1}const me=R-de-1;r.scissor.set(ue+Z*Q,fe+me*K,Math.min(Q,F-Z*Q),Math.min(K,X-me*K)),r.viewport.set(ue,fe,F,X),s.setRenderTarget(r),s.setScissorTest(!0),s.autoClear=!1,e.render(s),s.setViewport(d),s.setScissor(m),s.setScissorTest(Ye),s.setRenderTarget(he),s.autoClear=je,c&&(f.target1=l.texture,f.target2=r.texture,s.setRenderTarget(y),t.render(s),s.setRenderTarget(he)),this.samples+=1/_,L===w-1&&W===R-1&&(this.samples=Math.round(this.samples)),yield}[l,y]=[y,l]}}const Pe=new n.Color;class Ee{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener("recompilation",this._compileFunction),e.addEventListener("recompilation",this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new n.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new n.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new B(new Br),this._blendQuad=new B(new _t),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Ct().generate(e),this._primaryTarget=new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),this._blendTargets=[new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter}),new n.WebGLRenderTarget(1,1,{format:n.RGBAFormat,type:n.FloatType,magFilter:n.NearestFilter,minFilter:n.NearestFilter})],this._compileFunction=()=>{const t=this.compileMaterial(this._fsQuad._mesh);t.then(()=>{this._compilePromise===t&&(this._compilePromise=null)}),this._compilePromise=t},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){const{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let r=0;e.projectionMatrix.elements[15]>0&&(r=1),e.isEquirectCamera&&(r=2),t.setDefine("CAMERA_TYPE",r),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){const{_renderer:e,_primaryTarget:t,_blendTargets:r}=this,i=e.getRenderTarget(),o=e.getClearAlpha();e.getClearColor(Pe),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(r[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Pe,o),e.setRenderTarget(i),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=Nr.call(this)),this._task.next())}}const D=new n.Vector2,Oe=new n.Vector2,$=new n.Spherical,j=new n.Color;class zr extends n.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,n.RGBAFormat,n.FloatType,n.EquirectangularReflectionMapping,n.RepeatWrapping,n.ClampToEdgeWrapping,n.LinearFilter,n.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;const{data:e,width:t,height:r}=this.image;for(let i=0;i<t;i++)for(let o=0;o<r;o++){Oe.set(t,r),D.set(i/t,o/r),D.x-=.5,D.y=1-D.y,$.theta=D.x*2*Math.PI,$.phi=D.y*Math.PI,$.radius=1,this.generationCallback($,D,Oe,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 ke=new n.Vector3;class Hr extends zr{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)=>{ke.setFromSpherical(t);const a=ke.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 Wr extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
|
|
3896
3896
|
varying vec2 vUv;
|
|
3897
3897
|
void main() {
|
|
3898
3898
|
|
|
@@ -3974,4 +3974,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 Be{constructor(e){this._renderer=e,this._quad=new N(new Lr)}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 Ur(s){return s.extensions.get("EXT_float_blend")}const k=new n.Vector2;class Gr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new wt,this._pathTracer=new Ee(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Ee(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new N(new Wr({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=jt(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=Yt(e),o=$t(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 Hr(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 Be(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 Be(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||!Ur(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 Ne(s){return typeof s=="object"&&s!==null&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}function z(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}const Y=class Y{constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.convertedEnvTexture=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new T.TypedEventEmitter,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:.5,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var i;const r=[];e.traverse(o=>{var a;(a=o.userData)!=null&&a[T.CONTACT_SHADOW_HELPER_FLAG]&&o.visible&&r.push(o)}),r.forEach(o=>o.visible=!1);try{(i=this.pathTracer)==null||i.setScene(e,t)}finally{r.forEach(o=>o.visible=!0)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let h=0;h<o.data.length;h++)a[h]=o.data[h]/255;const c=new M.DataTexture(a,r.width,r.height,M.RGBAFormat,M.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=z(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Gr(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!==M.ACESFilmicToneMapping&&(e.toneMapping=M.ACESFilmicToneMapping,e.toneMappingExposure=1.5),e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;const t=z(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.resumable=e==="completed",this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return Ne(e)&&(r=e.getInternalRenderer()),Ne(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.isCubeTexture){const h=i.environment;i.environment=c;try{this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0}finally{i.environment=h}}else if(c&&c.mapping===M.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)===M.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o,a;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(c){console.warn("Failed to update lights for path tracing:",c)}const i=e.render(t,r);return i.ok?performance.now()-this.lastCameraMoveTime<Y.CAMERA_SETTLE_MS?T.Result.ok(void 0):(this.cameraDirty&&(this.cameraDirty=!1,(a=this.pathTracer)==null||a.updateCamera()),this.accumulateOneSample(),this.sampleCount++,this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)):i}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&z(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=z(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=z(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}canResume(){return this.resumable&&this.pathTracer!==null&&!this.disposed}reset(e=!1){if(this.sampleCount=0,!!this.pathTracer){if(e){this.pathTracer.reset(),this.sceneInitialized=!1;return}this.lastCameraMoveTime=performance.now(),this.cameraDirty=!0,this.pathTracer.reset()}}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}};Y.CAMERA_SETTLE_MS=200;let oe=Y;exports.ThreePathTracingService=oe;
|
|
3977
|
+
}`}),this.depthWrite=!1,this.depthTest=!1}}class Be{constructor(e){this._renderer=e,this._quad=new B(new Lr)}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 Ur(s){return s.extensions.get("EXT_float_blend")}const O=new n.Vector2;class Gr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new wt,this._pathTracer=new Ee(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new Ee(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new B(new Wr({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=jt(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=Yt(e),o=$t(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 Hr(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 Be(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 Be(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||!Ur(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(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 Ne(s){return typeof s=="object"&&s!==null&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}function z(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}const Y=class Y{constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.convertedEnvTexture=null,this.resumable=!1,this.lastCameraMoveTime=-1/0,this.cameraDirty=!1,this.events=new T.TypedEventEmitter,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:.5,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var i;const r=[];e.traverse(o=>{var a;(a=o.userData)!=null&&a[T.CONTACT_SHADOW_HELPER_FLAG]&&o.visible&&r.push(o)}),r.forEach(o=>o.visible=!1);try{(i=this.pathTracer)==null||i.setScene(e,t)}finally{r.forEach(o=>o.visible=!0)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let h=0;h<o.data.length;h++)a[h]=o.data[h]/255;const c=new N.DataTexture(a,r.width,r.height,N.RGBAFormat,N.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=z(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Gr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.resumable=!1,this.reset(),this.sceneInitialized=!1;const t=z(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.resumable=e==="completed",this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return Ne(e)&&(r=e.getInternalRenderer()),Ne(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.isCubeTexture){const h=i.environment;i.environment=c;try{this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0}finally{i.environment=h}}else if(c&&c.mapping===N.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)===N.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o,a;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(c){console.warn("Failed to update lights for path tracing:",c)}const i=e.render(t,r);return i.ok?performance.now()-this.lastCameraMoveTime<Y.CAMERA_SETTLE_MS?T.Result.ok(void 0):(this.cameraDirty&&(this.cameraDirty=!1,(a=this.pathTracer)==null||a.updateCamera()),this.accumulateOneSample(),this.sampleCount++,this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)):i}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&z(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=z(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=z(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}canResume(){return this.resumable&&this.pathTracer!==null&&!this.disposed}reset(e=!1){if(this.sampleCount=0,!!this.pathTracer){if(e){this.pathTracer.reset(),this.sceneInitialized=!1;return}this.lastCameraMoveTime=performance.now(),this.cameraDirty=!0,this.pathTracer.reset()}}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}};Y.CAMERA_SETTLE_MS=200;let oe=Y;exports.ThreePathTracingService=oe;
|