softbox 4.4.2 → 4.5.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 +2 -2
- package/dist/{ThreePathTracingService-CxJy-I2s.js → ThreePathTracingService-DDmobGTv.js} +329 -327
- package/dist/{ThreePathTracingService-BroJh4xX.cjs → ThreePathTracingService-rw6SCxcL.cjs} +68 -68
- package/dist/{index-C3wD-bda.js → index-CC3LzFRV.js} +1221 -1169
- package/dist/index-CadyonSB.cjs +11 -0
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/simple-viewer.cjs +1 -1
- package/dist/simple-viewer.es.js +1 -1
- package/package.json +1 -1
- package/dist/index-B_YjoRyg.cjs +0 -11
|
@@ -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-CadyonSB.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 M=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
|
|
@@ -80,7 +80,7 @@ void ndcToCameraRay(
|
|
|
80
80
|
rayDirection = direction.xyz;
|
|
81
81
|
|
|
82
82
|
}
|
|
83
|
-
`,
|
|
83
|
+
`,rt=`
|
|
84
84
|
|
|
85
85
|
#ifndef TRI_INTERSECT_EPSILON
|
|
86
86
|
#define TRI_INTERSECT_EPSILON 1e-5
|
|
@@ -284,7 +284,7 @@ bool _bvhIntersectFirstHit(
|
|
|
284
284
|
return found;
|
|
285
285
|
|
|
286
286
|
}
|
|
287
|
-
`,
|
|
287
|
+
`,at=`
|
|
288
288
|
struct BVH {
|
|
289
289
|
|
|
290
290
|
usampler2D index;
|
|
@@ -294,7 +294,7 @@ struct BVH {
|
|
|
294
294
|
usampler2D bvhContents;
|
|
295
295
|
|
|
296
296
|
};
|
|
297
|
-
`;function ze(s,e,t=0){if(s.isInterleavedBufferAttribute){const r=s.itemSize;for(let i=0,o=s.count;i<o;i++){const a=i+t;e.setX(a,s.getX(i)),r>=2&&e.setY(a,s.getY(i)),r>=3&&e.setZ(a,s.getZ(i)),r>=4&&e.setW(a,s.getW(i))}}else{const r=e.array,i=r.constructor,o=r.BYTES_PER_ELEMENT*s.itemSize*t;new i(r.buffer,o,s.array.length).set(s.array)}}function H(s,e=null){const t=s.array.constructor,r=s.normalized,i=s.itemSize,o=e===null?s.count:e;return new n.BufferAttribute(new t(i*o),i,r)}function N(s,e){if(!s&&!e)return!0;if(!!s!=!!e)return!1;const t=s.count===e.count,r=s.normalized===e.normalized,i=s.array.constructor===e.array.constructor,o=s.itemSize===e.itemSize;return!(!t||!r||!i||!o)}function tt(s){const e=s[0].index!==null,t=new Set(Object.keys(s[0].attributes));if(!s[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let r=0;r<s.length;++r){const i=s[r];let o=0;if(e!==(i.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const a in i.attributes){if(!t.has(a))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+a+'" attribute exists among all geometries, or in none of them.');o++}if(o!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function rt(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getIndex().count;return e}function at(s){let e=0;for(let t=0,r=s.length;t<r;t++)e+=s[t].getAttribute("position").count;return e}function it(s,e,t){s.index&&s.index.count!==e&&s.setIndex(null);const r=s.attributes;for(const i in r)r[i].count!==t&&s.deleteAttribute(i)}function st(s,e={},t=new n.BufferGeometry){const{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:o=[],overwriteIndex:a=!0}=e;tt(s);const c=s[0].index!==null,h=c?rt(s):-1,m=at(s);if(it(t,h,m),r){let f=0;for(let l=0,y=s.length;l<y;l++){const p=s[l];let v;c?v=p.getIndex().count:v=p.getAttribute("position").count,t.addGroup(f,v,l),f+=v}}if(c){let f=!1;if(t.index||(t.setIndex(new n.BufferAttribute(new Uint32Array(h),1,!1)),f=!0),f||a){let l=0,y=0;const p=t.getIndex();for(let v=0,u=s.length;v<u;v++){const g=s[v],x=g.getIndex();if(!(!i&&!f&&o[v]))for(let w=0;w<x.count;++w)p.setX(l+w,x.getX(w)+y);l+=x.count,y+=g.getAttribute("position").count}}}const d=Object.keys(s[0].attributes);for(let f=0,l=d.length;f<l;f++){let y=!1;const p=d[f];if(!t.getAttribute(p)){const g=s[0].getAttribute(p);t.setAttribute(p,H(g,m)),y=!0}let v=0;const u=t.getAttribute(p);for(let g=0,x=s.length;g<x;g++){const b=s[g],w=!i&&!y&&o[g],R=b.getAttribute(p);w||ze(R,u,v),v+=R.count}}}function ot(s,e,t){const r=s.index,o=s.attributes.position.count,a=r?r.count:o;let c=s.groups;c.length===0&&(c=[{count:a,start:0,materialIndex:0}]);let h=s.getAttribute("materialIndex");if(!h||h.count!==o){let d;t.length<=255?d=new Uint8Array(o):d=new Uint16Array(o),h=new n.BufferAttribute(d,1,!1),s.deleteAttribute("materialIndex"),s.setAttribute("materialIndex",h)}const m=h.array;for(let d=0;d<c.length;d++){const f=c[d],l=f.start,y=f.count,p=Math.min(y,a-l),v=Array.isArray(e)?e[f.materialIndex]:e,u=t.indexOf(v);for(let g=0;g<p;g++){let x=l+g;r&&(x=r.getX(x)),m[x]=u}}}function nt(s,e){if(!s.index){const t=s.attributes.position.count,r=new Array(t);for(let i=0;i<t;i++)r[i]=i;s.setIndex(r)}if(!s.attributes.normal&&e&&e.includes("normal")&&s.computeVertexNormals(),!s.attributes.uv&&e&&e.includes("uv")){const t=s.attributes.position.count;s.setAttribute("uv",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.uv2&&e&&e.includes("uv2")){const t=s.attributes.position.count;s.setAttribute("uv2",new n.BufferAttribute(new Float32Array(t*2),2,!1))}if(!s.attributes.tangent&&e&&e.includes("tangent"))if(s.attributes.uv&&s.attributes.normal)s.computeTangents();else{const t=s.attributes.position.count;s.setAttribute("tangent",new n.BufferAttribute(new Float32Array(t*4),4,!1))}if(!s.attributes.color&&e&&e.includes("color")){const t=s.attributes.position.count,r=new Float32Array(t*4);r.fill(1),s.setAttribute("color",new n.BufferAttribute(r,4))}}function se(s){let e=0;if(s.byteLength!==0){const t=new Uint8Array(s);for(let r=0;r<s.byteLength;r++){const i=t[r];e=(e<<5)-e+i,e|=0}}return e}function me(s){let e=s.uuid;const t=Object.values(s.attributes);s.index&&(t.push(s.index),e+=`index|${s.index.version}`);const r=Object.keys(t).sort();for(const i of r){const o=t[i];e+=`${i}_${o.version}|`}return e}function pe(s){const e=s.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${se(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class lt{constructor(e=null){this.matrixWorld=new n.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=me(t),this.primitiveCount=r,this.skeletonHash=pe(e)}didChange(e){const t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===me(t)&&this.skeletonHash===pe(e)&&this.primitiveCount===r)}}const M=new n.Vector3,C=new n.Vector3,D=new n.Vector3,ge=new n.Vector4,U=new n.Vector3,J=new n.Vector3,ve=new n.Vector4,xe=new n.Vector4,G=new n.Matrix4,ye=new n.Matrix4;function be(s,e,t){const r=s.skeleton,i=s.geometry,o=r.bones,a=r.boneInverses;ve.fromBufferAttribute(i.attributes.skinIndex,e),xe.fromBufferAttribute(i.attributes.skinWeight,e),G.elements.fill(0);for(let c=0;c<4;c++){const h=xe.getComponent(c);if(h!==0){const m=ve.getComponent(c);ye.multiplyMatrices(o[m].matrixWorld,a[m]),ct(G,ye,h)}}return G.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),t.transformDirection(G),t}function ee(s,e,t,r,i){U.set(0,0,0);for(let o=0,a=s.length;o<a;o++){const c=e[o],h=s[o];c!==0&&(J.fromBufferAttribute(h,r),t?U.addScaledVector(J,c):U.addScaledVector(J.sub(i),c))}i.add(U)}function ct(s,e,t){const r=s.elements,i=e.elements;for(let o=0,a=i.length;o<a;o++)r[o]+=i[o]*t}function ut(s){const{index:e,attributes:t}=s;if(e)for(let r=0,i=e.count;r<i;r+=3){const o=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,o)}else for(const r in t){const i=t[r],o=i.itemSize;for(let a=0,c=i.count;a<c;a+=3)for(let h=0;h<o;h++){const m=i.getComponent(a,h),d=i.getComponent(a+2,h);i.setComponent(a,h,d),i.setComponent(a+2,h,m)}}return s}function ft(s,e={},t=new n.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const r=s.geometry,i=e.applyWorldTransforms,o=e.attributes.includes("normal"),a=e.attributes.includes("tangent"),c=r.attributes,h=t.attributes;for(const x in t.attributes)(!e.attributes.includes(x)||!(x in r.attributes))&&t.deleteAttribute(x);!t.index&&r.index&&(t.index=r.index.clone()),h.position||t.setAttribute("position",H(c.position)),o&&!h.normal&&c.normal&&t.setAttribute("normal",H(c.normal)),a&&!h.tangent&&c.tangent&&t.setAttribute("tangent",H(c.tangent)),N(r.index,t.index),N(c.position,h.position),o&&N(c.normal,h.normal),a&&N(c.tangent,h.tangent);const m=c.position,d=o?c.normal:null,f=a?c.tangent:null,l=r.morphAttributes.position,y=r.morphAttributes.normal,p=r.morphAttributes.tangent,v=r.morphTargetsRelative,u=s.morphTargetInfluences,g=new n.Matrix3;g.getNormalMatrix(s.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let x=0,b=c.position.count;x<b;x++)M.fromBufferAttribute(m,x),d&&C.fromBufferAttribute(d,x),f&&(ge.fromBufferAttribute(f,x),D.fromBufferAttribute(f,x)),u&&(l&&ee(l,u,v,x,M),y&&ee(y,u,v,x,C),p&&ee(p,u,v,x,D)),s.isSkinnedMesh&&(s.applyBoneTransform(x,M),d&&be(s,x,C),f&&be(s,x,D)),i&&M.applyMatrix4(s.matrixWorld),h.position.setXYZ(x,M.x,M.y,M.z),d&&(i&&C.applyNormalMatrix(g),h.normal.setXYZ(x,C.x,C.y,C.z)),f&&(i&&D.transformDirection(s.matrixWorld),h.tangent.setXYZW(x,D.x,D.y,D.z,ge.w));for(const x in e.attributes){const b=e.attributes[x];b==="position"||b==="tangent"||b==="normal"||!(b in c)||(h[b]||t.setAttribute(b,H(c[b])),N(c[b],h[b]),ze(c[b],h[b]))}return s.matrixWorld.determinant()<0&&ut(t),t}class ht extends n.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new lt}isCompatible(e,t){const r=e.geometry;for(let i=0;i<t.length;i++){const o=t[i],a=r.attributes[o],c=this.attributes[o];if(a&&!N(a,c))return!1}return!0}updateFrom(e,t){const r=this._diff;return r.didChange(e)?(ft(e,t,this),r.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const ae=0,He=1,We=2;function dt(s,e){for(let t=0,r=s.length;t<r;t++)s[t].traverseVisible(o=>{o.isMesh&&e(o)})}function mt(s){const e=[];for(let t=0,r=s.length;t<r;t++){const i=s[t];Array.isArray(i.material)?e.push(...i.material):e.push(i.material)}return e}function pt(s,e,t){if(s.length===0){e.setIndex(null);const r=e.attributes;for(const i in r)e.deleteAttribute(i);for(const i in t.attributes)e.setAttribute(t.attributes[i],new n.BufferAttribute(new Float32Array(0),4,!1))}else st(s,t,e);for(const r in e.attributes)e.attributes[r].needsUpdate=!0}class gt{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new n.MeshBasicMaterial,t=new n.BufferGeometry;t.setAttribute("position",new n.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new n.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return dt(this.objects,t=>{e.push(t)}),e.sort((t,r)=>t.uuid>r.uuid?1:t.uuid<r.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),r=new Set(e.keys()),i={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let o=0,a=t.length;o<a;o++){const c=t[o],h=c.uuid;r.delete(h);let m=e.get(h);(!m||!m.isCompatible(c,this.attributes))&&(m&&m.dispose(),m=new ht,e.set(h,m)),m.updateFrom(c,i)&&this.generateMissingAttributes&&nt(m,this.attributes)}r.forEach(o=>{e.delete(o)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new n.BufferGeometry){const{useGroups:t,overwriteIndex:r,_intermediateGeometry:i,_geometryMergeSets:o}=this,a=this._getMeshes(),c=[],h=[],m=o.get(e)||[];this._updateIntermediateGeometries();let d=!1;a.length!==m.length&&(d=!0);for(let l=0,y=a.length;l<y;l++){const p=a[l],v=i.get(p.uuid);h.push(v);const u=m[l];!u||u.uuid!==v.uuid?(c.push(!1),d=!0):u.version!==v.version?c.push(!1):c.push(!0)}pt(h,e,{useGroups:t,forceUpdate:d,skipAssigningAttributes:c,overwriteIndex:r}),d&&e.dispose(),o.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let f=ae;return d?f=We:c.includes(!1)&&(f=He),{changeType:f,materials:mt(a),geometry:e}}}function vt(s){const e=new Set;for(let t=0,r=s.length;t<r;t++){const i=s[t];for(const o in i){const a=i[o];a&&a.isTexture&&e.add(a)}}return Array.from(e)}function xt(s){const e=[],t=new Set;for(let i=0,o=s.length;i<o;i++)s[i].traverse(a=>{a.visible&&(a.isRectAreaLight||a.isSpotLight||a.isPointLight||a.isDirectionalLight)&&(e.push(a),a.iesMap&&t.add(a.iesMap))});const r=Array.from(t).sort((i,o)=>i.uuid<o.uuid?1:i.uuid>o.uuid?-1:0);return{lights:e,iesTextures:r}}class yt{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new n.BufferGeometry,this.staticGeometryGenerator=new gt(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:r,attributes:i}=this,o=t.objects;t.attributes=i,o.forEach(f=>{f.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const a=t.generate(r),c=a.materials,h=vt(c),{lights:m,iesTextures:d}=xt(o);if(a.changeType!==ae&&ot(r,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(a.changeType===We){const f={strategy:T.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(r,f):this.bvh=new T.MeshBVH(r,f)}else a.changeType===He&&this.bvh.refit()}return{bvhChanged:a.changeType!==ae,bvh:this.bvh,lights:m,iesTextures:d,geometry:r,materials:c,textures:h,objects:o}}}const bt=new n.OrthographicCamera(-1,1,1,-1,0,1);class Tt extends n.BufferGeometry{constructor(){super(),this.setAttribute("position",new n.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new n.Float32BufferAttribute([0,2,0,0,2,0],2))}}const wt=new Tt;class z{constructor(e){this._mesh=new n.Mesh(wt,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,bt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class oe extends n.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(r){this.uniforms[t].value=r}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Rt extends oe{constructor(e){super({blending:n.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
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:`
|
|
298
298
|
|
|
299
299
|
varying vec2 vUv;
|
|
300
300
|
|
|
@@ -384,7 +384,7 @@ struct BVH {
|
|
|
384
384
|
return SOBOL_FACTOR * ${t}( result >> 8 );
|
|
385
385
|
|
|
386
386
|
}
|
|
387
|
-
`}const
|
|
387
|
+
`}const Ve=`
|
|
388
388
|
|
|
389
389
|
// Utils
|
|
390
390
|
const float SOBOL_FACTOR = 1.0 / 16777216.0;
|
|
@@ -407,7 +407,7 @@ struct BVH {
|
|
|
407
407
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
`,
|
|
410
|
+
`,Ft=`
|
|
411
411
|
|
|
412
412
|
const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ](
|
|
413
413
|
0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,
|
|
@@ -485,7 +485,7 @@ struct BVH {
|
|
|
485
485
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
`,
|
|
488
|
+
`,Mt=`
|
|
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 At 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() {
|
|
@@ -539,8 +539,8 @@ struct BVH {
|
|
|
539
539
|
}
|
|
540
540
|
`,fragmentShader:`
|
|
541
541
|
|
|
542
|
-
${
|
|
543
|
-
${
|
|
542
|
+
${Ve}
|
|
543
|
+
${Ft}
|
|
544
544
|
|
|
545
545
|
varying vec2 vUv;
|
|
546
546
|
uniform vec2 resolution;
|
|
@@ -550,7 +550,7 @@ struct BVH {
|
|
|
550
550
|
gl_FragColor = generateSobolPoint( index );
|
|
551
551
|
|
|
552
552
|
}
|
|
553
|
-
`})}}class Ft{generate(e,t=256){const r=new n.WebGLRenderTarget(t,t,{type:n.FloatType,format:n.RGBAFormat,minFilter:n.NearestFilter,magFilter:n.NearestFilter,generateMipmaps:!1}),i=e.getRenderTarget();e.setRenderTarget(r);const o=new z(new _t);return o.material.resolution.set(t,t),o.render(e),e.setRenderTarget(i),o.dispose(),r}}class At extends n.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class Mt{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof At?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function te(s){const e=new Uint16Array(s.length);for(let t=0,r=s.length;t<r;++t)e[t]=n.DataUtils.toHalfFloat(s[t]);return e}function Te(s,e,t=0,r=s.length){let i=t,o=t+r-1;for(;i<o;){const a=i+o>>1;s[a]<e?i=a+1:o=a}return i-t}function Ct(s,e,t){return .2126*s+.7152*e+.0722*t}function Dt(s,e=n.HalfFloatType){const t=s.clone();t.source=new n.Source({...t.image});const{width:r,height:i,data:o}=t.image;let a=o;if(t.type!==e){e===n.HalfFloatType?a=new Uint16Array(o.length):a=new Float32Array(o.length);let c;o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?c=2**(8*o.BYTES_PER_ELEMENT-1)-1:c=2**(8*o.BYTES_PER_ELEMENT)-1;for(let h=0,m=o.length;h<m;h++){let d=o[h];t.type===n.HalfFloatType&&(d=n.DataUtils.fromHalfFloat(o[h])),t.type!==n.FloatType&&t.type!==n.HalfFloatType&&(d/=c),e===n.HalfFloatType&&(a[h]=n.DataUtils.toHalfFloat(d))}t.image.data=a,t.type=e}if(t.flipY){const c=a;a=a.slice();for(let h=0;h<i;h++)for(let m=0;m<r;m++){const d=i-h-1,f=4*(h*r+m),l=4*(d*r+m);a[l+0]=c[f+0],a[l+1]=c[f+1],a[l+2]=c[f+2],a[l+3]=c[f+3]}t.flipY=!1,t.image.data=a}return t}class Pt{constructor(){const e=new n.DataTexture(te(new Float32Array([0,0,0,0])),1,1);e.type=n.HalfFloatType,e.format=n.RGBAFormat,e.minFilter=n.LinearFilter,e.magFilter=n.LinearFilter,e.wrapS=n.RepeatWrapping,e.wrapT=n.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new n.DataTexture(te(new Float32Array([0,1])),1,2);t.type=n.HalfFloatType,t.format=n.RedFormat,t.minFilter=n.LinearFilter,t.magFilter=n.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const r=new n.DataTexture(te(new Float32Array([0,0,1,1])),2,2);r.type=n.HalfFloatType,r.format=n.RedFormat,r.minFilter=n.LinearFilter,r.magFilter=n.LinearFilter,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Dt(e);t.wrapS=n.RepeatWrapping,t.wrapT=n.ClampToEdgeWrapping;const{width:r,height:i,data:o}=t.image,a=new Float32Array(r*i),c=new Float32Array(r*i),h=new Float32Array(i),m=new Float32Array(i);let d=0,f=0;for(let u=0;u<i;u++){let g=0;for(let x=0;x<r;x++){const b=u*r+x,w=n.DataUtils.fromHalfFloat(o[4*b+0]),R=n.DataUtils.fromHalfFloat(o[4*b+1]),_=n.DataUtils.fromHalfFloat(o[4*b+2]),F=Ct(w,R,_);g+=F,d+=F,a[b]=F,c[b]=g}if(g!==0)for(let x=u*r,b=u*r+r;x<b;x++)a[x]/=g,c[x]/=g;f+=g,h[u]=g,m[u]=f}if(f!==0)for(let u=0,g=h.length;u<g;u++)h[u]/=f,m[u]/=f;const l=new Uint16Array(i),y=new Uint16Array(r*i);for(let u=0;u<i;u++){const g=(u+1)/i,x=Te(m,g);l[u]=n.DataUtils.toHalfFloat((x+.5)/i)}for(let u=0;u<i;u++)for(let g=0;g<r;g++){const x=u*r+g,b=(g+1)/r,w=Te(c,b,u*r,r);y[x]=n.DataUtils.toHalfFloat((w+.5)/r)}this.dispose();const{marginalWeights:p,conditionalWeights:v}=this;p.image={width:i,height:1,data:l},p.needsUpdate=!0,v.image={width:r,height:i,data:y},v.needsUpdate=!0,this.totalSum=d,this.map=t}}const re=6,Et=0,Ot=1,kt=2,Bt=3,Nt=4,S=new n.Vector3,I=new n.Vector3,we=new n.Matrix4,E=new n.Quaternion,Re=new n.Vector3,O=new n.Vector3,zt=new n.Vector3(0,1,0);class Ht{constructor(){const e=new n.DataTexture(new Float32Array(4),1,1);e.format=n.RGBAFormat,e.type=n.FloatType,e.wrapS=n.ClampToEdgeWrapping,e.wrapT=n.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=n.NearestFilter,e.magFilter=n.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const r=this.tex,i=Math.max(e.length*re,1),o=Math.ceil(Math.sqrt(i));r.image.width!==o&&(r.dispose(),r.image.data=new Float32Array(o*o*4),r.image.width=o,r.image.height=o);const a=r.image.data;for(let h=0,m=e.length;h<m;h++){const d=e[h],f=h*re*4;let l=0;for(let p=0;p<re*4;p++)a[f+p]=0;d.getWorldPosition(I),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z;let y=Et;if(d.isRectAreaLight&&d.isCircular?y=Ot:d.isSpotLight?y=kt:d.isDirectionalLight?y=Bt:d.isPointLight&&(y=Nt),a[f+l++]=y,a[f+l++]=d.color.r,a[f+l++]=d.color.g,a[f+l++]=d.color.b,a[f+l++]=d.intensity,d.getWorldQuaternion(E),d.isRectAreaLight)S.set(d.width,0,0).applyQuaternion(E),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,d.height,0).applyQuaternion(E),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=S.cross(I).length()*(d.isCircular?Math.PI/4:1);else if(d.isSpotLight){const p=d.radius||0;Re.setFromMatrixPosition(d.matrixWorld),O.setFromMatrixPosition(d.target.matrixWorld),we.lookAt(Re,O,zt),E.setFromRotationMatrix(we),S.set(1,0,0).applyQuaternion(E),a[f+l++]=S.x,a[f+l++]=S.y,a[f+l++]=S.z,l++,I.set(0,1,0).applyQuaternion(E),a[f+l++]=I.x,a[f+l++]=I.y,a[f+l++]=I.z,a[f+l++]=Math.PI*p*p,a[f+l++]=p,a[f+l++]=d.decay,a[f+l++]=d.distance,a[f+l++]=Math.cos(d.angle),a[f+l++]=Math.cos(d.angle*(1-d.penumbra)),a[f+l++]=d.iesMap?t.indexOf(d.iesMap):-1}else if(d.isPointLight){const p=S.setFromMatrixPosition(d.matrixWorld);a[f+l++]=p.x,a[f+l++]=p.y,a[f+l++]=p.z,l++,l+=4,l+=1,a[f+l++]=d.decay,a[f+l++]=d.distance}else if(d.isDirectionalLight){const p=S.setFromMatrixPosition(d.matrixWorld),v=I.setFromMatrixPosition(d.target.matrixWorld);O.subVectors(p,v).normalize(),a[f+l++]=O.x,a[f+l++]=O.y,a[f+l++]=O.z}}this.count=e.length;const c=se(a.buffer);return this.hash!==c?(this.hash=c,r.needsUpdate=!0,!0):!1}}function Ie(s,e,t,r,i){if(e>r)throw new Error;const o=s.length/e,a=s.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(s.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**a-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(a-1)-1;break}for(let h=0;h<o;h++){const m=4*h,d=e*h;for(let f=0;f<r;f++)t[i+m+f]=e>=f+1?s[d+f]/c:0}}class Wt extends n.DataArrayTexture{constructor(){super(),this._textures=[],this.type=n.FloatType,this.format=n.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const r=this._textures[e];r.updateFrom(t);const i=r.image,o=this.image;if(i.width!==o.width||i.height!==o.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:a,height:c,data:h}=o,d=a*c*4*e;let f=t.itemSize;f===3&&(f=4),Ie(r.image.data,f,h,4,d),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,r=e.length;for(let f=0,l=r;f<l;f++)if(e[f].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const i=this._textures;for(;i.length<r;){const f=new Ne;i.push(f)}for(;i.length>r;)i.pop();for(let f=0,l=r;f<l;f++)i[f].updateFrom(e[f]);const a=i[0].image,c=this.image;(a.width!==c.width||a.height!==c.height||a.depth!==r)&&(c.width=a.width,c.height=a.height,c.depth=r,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:m,height:d}=c;for(let f=0,l=r;f<l;f++){const y=i[f],v=m*d*4*f;let u=e[f].itemSize;u===3&&(u=4),Ie(y.image.data,u,h,4,v)}this.dispose(),this.needsUpdate=!0}}class Lt extends Wt{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,r,i){this.setAttributes([e,t,r,i])}}function ne(s,e){return s.uuid<e.uuid?1:s.uuid>e.uuid?-1:0}function ie(s){return`${s.source.uuid}:${s.colorSpace}`}function Ut(s){const e=new Set,t=[];for(let r=0,i=s.length;r<i;r++){const o=s[r],a=ie(o);e.has(a)||(e.add(a),t.push(o))}return t}function Gt(s){const e=s.map(r=>r.iesMap||null).filter(r=>r),t=new Set(e);return Array.from(t).sort(ne)}function Vt(s){const e=new Set;for(let r=0,i=s.length;r<i;r++){const o=s[r];for(const a in o){const c=o[a];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return Ut(t).sort(ne)}function qt(s){const e=[];return s.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(ne)}const Ue=45,Se=Ue*4;class $t{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class jt extends n.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=n.RGBAFormat,this.type=n.FloatType,this.wrapS=n.ClampToEdgeWrapping,this.wrapT=n.ClampToEdgeWrapping,this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.generateMipmaps=!1,this.features=new $t}updateFrom(e,t){function r(p,v,u=-1){if(v in p&&p[v]){const g=ie(p[v]);return f[g]}else return u}function i(p,v,u){return v in p?p[v]:u}function o(p,v,u,g){const x=p[v]&&p[v].isTexture?p[v]:null;if(x){x.matrixAutoUpdate&&x.updateMatrix();const b=x.matrix.elements;let w=0;u[g+w++]=b[0],u[g+w++]=b[3],u[g+w++]=b[6],w++,u[g+w++]=b[1],u[g+w++]=b[4],u[g+w++]=b[7],w++}return 8}let a=0;const c=e.length*Ue,h=Math.ceil(Math.sqrt(c))||1,{image:m,features:d}=this,f={};for(let p=0,v=t.length;p<v;p++)f[ie(t[p])]=p;m.width!==h&&(this.dispose(),m.data=new Float32Array(h*h*4),m.width=h,m.height=h);const l=m.data;d.reset();for(let p=0,v=e.length;p<v;p++){const u=e[p];if(u.isFogVolumeMaterial){d.setUsed("FOG");for(let b=0;b<Se;b++)l[a+b]=0;l[a+0+0]=u.color.r,l[a+0+1]=u.color.g,l[a+0+2]=u.color.b,l[a+8+3]=i(u,"emissiveIntensity",0),l[a+12+0]=u.emissive.r,l[a+12+1]=u.emissive.g,l[a+12+2]=u.emissive.b,l[a+52+1]=u.density,l[a+52+3]=0,l[a+56+2]=4,a+=Se;continue}l[a++]=u.color.r,l[a++]=u.color.g,l[a++]=u.color.b,l[a++]=r(u,"map"),l[a++]=i(u,"metalness",0),l[a++]=r(u,"metalnessMap"),l[a++]=i(u,"roughness",0),l[a++]=r(u,"roughnessMap"),l[a++]=i(u,"ior",1.5),l[a++]=i(u,"transmission",0),l[a++]=r(u,"transmissionMap"),l[a++]=i(u,"emissiveIntensity",0),"emissive"in u?(l[a++]=u.emissive.r,l[a++]=u.emissive.g,l[a++]=u.emissive.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"emissiveMap"),l[a++]=r(u,"normalMap"),"normalScale"in u?(l[a++]=u.normalScale.x,l[a++]=u.normalScale.y):(l[a++]=1,l[a++]=1),l[a++]=i(u,"clearcoat",0),l[a++]=r(u,"clearcoatMap"),l[a++]=i(u,"clearcoatRoughness",0),l[a++]=r(u,"clearcoatRoughnessMap"),l[a++]=r(u,"clearcoatNormalMap"),"clearcoatNormalScale"in u?(l[a++]=u.clearcoatNormalScale.x,l[a++]=u.clearcoatNormalScale.y):(l[a++]=1,l[a++]=1),a++,l[a++]=i(u,"sheen",0),"sheenColor"in u?(l[a++]=u.sheenColor.r,l[a++]=u.sheenColor.g,l[a++]=u.sheenColor.b):(l[a++]=0,l[a++]=0,l[a++]=0),l[a++]=r(u,"sheenColorMap"),l[a++]=i(u,"sheenRoughness",0),l[a++]=r(u,"sheenRoughnessMap"),l[a++]=r(u,"iridescenceMap"),l[a++]=r(u,"iridescenceThicknessMap"),l[a++]=i(u,"iridescence",0),l[a++]=i(u,"iridescenceIOR",1.3);const g=i(u,"iridescenceThicknessRange",[100,400]);l[a++]=g[0],l[a++]=g[1],"specularColor"in u?(l[a++]=u.specularColor.r,l[a++]=u.specularColor.g,l[a++]=u.specularColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=r(u,"specularColorMap"),l[a++]=i(u,"specularIntensity",1),l[a++]=r(u,"specularIntensityMap");const x=i(u,"thickness",0)===0&&i(u,"attenuationDistance",1/0)===1/0;if(l[a++]=Number(x),a++,"attenuationColor"in u?(l[a++]=u.attenuationColor.r,l[a++]=u.attenuationColor.g,l[a++]=u.attenuationColor.b):(l[a++]=1,l[a++]=1,l[a++]=1),l[a++]=i(u,"attenuationDistance",1/0),l[a++]=r(u,"alphaMap"),l[a++]=u.opacity,l[a++]=u.alphaTest,!x&&u.transmission>0)l[a++]=0;else switch(u.side){case n.FrontSide:l[a++]=1;break;case n.BackSide:l[a++]=-1;break;case n.DoubleSide:l[a++]=0;break}l[a++]=Number(i(u,"matte",!1)),l[a++]=Number(i(u,"castShadow",!0)),l[a++]=Number(u.vertexColors)|Number(u.flatShading)<<1,l[a++]=Number(u.transparent),a+=o(u,"map",l,a),a+=o(u,"metalnessMap",l,a),a+=o(u,"roughnessMap",l,a),a+=o(u,"transmissionMap",l,a),a+=o(u,"emissiveMap",l,a),a+=o(u,"normalMap",l,a),a+=o(u,"clearcoatMap",l,a),a+=o(u,"clearcoatNormalMap",l,a),a+=o(u,"clearcoatRoughnessMap",l,a),a+=o(u,"sheenColorMap",l,a),a+=o(u,"sheenRoughnessMap",l,a),a+=o(u,"iridescenceMap",l,a),a+=o(u,"iridescenceThicknessMap",l,a),a+=o(u,"specularColorMap",l,a),a+=o(u,"specularIntensityMap",l,a)}const y=se(l.buffer);return this.hash!==y?(this.hash=y,this.needsUpdate=!0,!0):!1}}const _e=new n.Color;function Yt(s){return s?`${s.uuid}:${s.version}`:null}function Xt(s,e){for(const t in e)t in s&&(s[t]=e[t])}class Fe extends n.WebGLArrayRenderTarget{constructor(e,t,r){const i={format:n.RGBAFormat,type:n.UnsignedByteType,minFilter:n.LinearFilter,magFilter:n.LinearFilter,wrapS:n.RepeatWrapping,wrapT:n.RepeatWrapping,generateMipmaps:!1,...r};super(e,t,1,i),Xt(this.texture,i),this.texture.setTextures=(...a)=>{this.setTextures(...a)},this.hashes=[null];const o=new z(new Qt);this.fsQuad=o}setTextures(e,t,r=this.width,i=this.height){const o=e.getRenderTarget(),a=e.toneMapping,c=e.getClearAlpha();e.getClearColor(_e);const h=t.length||1;(r!==this.width||i!==this.height||this.depth!==h)&&(this.setSize(r,i,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=n.NoToneMapping;const m=this.fsQuad,d=this.hashes;let f=!1;for(let l=0,y=h;l<y;l++){const p=t[l],v=Yt(p);p&&(d[l]!==v||p.isWebGLRenderTarget)&&(p.matrixAutoUpdate=!1,p.matrix.identity(),m.material.map=p,e.setRenderTarget(this,l),m.render(e),p.updateMatrix(),p.matrixAutoUpdate=!0,d[l]=v,f=!0)}return m.material.map=null,e.setClearColor(_e,c),e.setRenderTarget(o),e.toneMapping=a,f}dispose(){super.dispose(),this.fsQuad.dispose()}}class Qt extends n.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
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:`
|
|
554
554
|
varying vec2 vUv;
|
|
555
555
|
void main() {
|
|
556
556
|
|
|
@@ -566,7 +566,7 @@ struct BVH {
|
|
|
566
566
|
gl_FragColor = texture2D( map, vUv );
|
|
567
567
|
|
|
568
568
|
}
|
|
569
|
-
`})}}function
|
|
569
|
+
`})}}function er(s,e=Math.random()){for(let t=s.length-1;t>0;t--){const r=Math.floor(e()*(t+1)),i=s[t];s[t]=s[r],s[r]=i}return s}class tr{constructor(e,t,r=Math.random){const i=e**t,o=new Uint16Array(i);let a=i;for(let c=0;c<i;c++)o[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<i;c++)o[c]=c;a=0},this.reshuffle=function(){a=0},this.next=function(){const{samples:c}=this;a>=o.length&&(er(o,r),this.reshuffle());let h=o[a++];for(let m=0;m<t;m++)c[m]=(h%e+r())/e,h=Math.floor(h/e);return c}}}class rr{constructor(e,t,r=Math.random){let i=0;for(const h of t)i+=h;const o=new Float32Array(i),a=[];let c=0;for(const h of t){const m=new tr(e,h,r);m.samples=new Float32Array(o.buffer,c,m.samples.length),c+=m.samples.length*4,a.push(m)}this.samples=o,this.strataCount=e,this.next=function(){for(const h of a)h.next();return o},this.reshuffle=function(){for(const h of a)h.reshuffle()},this.reset=function(){for(const h of a)h.reset()}}}class ar{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}}class ir extends n.DataTexture{constructor(e=1,t=1,r=8){super(new Float32Array(1),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.strata=r,this.sampler=null,this.generator=new ar,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,r)}init(e=this.image.height,t=this.image.width,r=this.strata){const{image:i}=this;if(i.width===t&&i.height===e&&this.sampler!==null)return;const o=new Array(e*t).fill(4),a=new rr(r,o,this.random);i.width=t,i.height=e,i.data=a.samples,this.sampler=a,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}}function sr(s,e=Math.random){for(let t=s.length-1;t>0;t--){const r=~~((e()-1e-6)*t),i=s[t];s[t]=s[r],s[r]=i}}function or(s,e){s.fill(0);for(let t=0;t<e;t++)s[t]=1}class Ce{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){const{score:e,binaryPattern:t}=this;let r=1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==0)continue;const c=e[o];c<r&&(r=c,i=o)}return i}findCluster(){const{score:e,binaryPattern:t}=this;let r=-1/0,i=-1;for(let o=0,a=t.length;o<a;o++){if(t[o]!==1)continue;const c=e[o];c>r&&(r=c,i=o)}return i}setSigma(e){if(e===this.sigma)return;const t=~~(Math.sqrt(20*e**2)+1),r=2*t+1,i=new Float32Array(r*r),o=e*e;for(let a=-t;a<=t;a++)for(let c=-t;c<=t;c++){const h=(t+c)*r+a+t,m=a*a+c*c;i[h]=Math.E**(-m/(2*o))}this.lookupTable=i,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){const{binaryPattern:e,score:t,size:r}=this;t.fill(0);for(let i=0,o=e.length;i<o;i++)if(e[i]===0){const a=~~(i/r),c=i-a*r;this.updateScore(c,a,1),e[i]=1}else e[i]=0}updateScore(e,t,r){const{size:i,score:o,lookupTable:a}=this,c=this.radius,h=2*c+1;for(let m=-c;m<=c;m++)for(let d=-c;d<=c;d++){const f=(c+d)*h+m+c,l=a[f];let y=e+m;y=y<0?i+y:y%i;let p=t+d;p=p<0?i+p:p%i;const v=p*i+y;o[v]+=r*l}}addPointIndex(e){this.binaryPattern[e]=1;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;const t=this.size,r=~~(e/t),i=e-r*t;this.updateScore(i,r,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}}class nr{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Ce(1),this.savedSamples=new Ce(1)}generate(){const{samples:e,savedSamples:t,sigma:r,majorityPointsRatio:i,size:o}=this;e.resize(o),e.setSigma(r);const a=Math.floor(o*o*i),c=e.binaryPattern;or(c,a),sr(c,this.random);for(let f=0,l=c.length;f<l;f++)c[f]===1&&e.addPointIndex(f);for(;;){const f=e.findCluster();e.removePointIndex(f);const l=e.findVoid();if(f===l){e.addPointIndex(f);break}e.addPointIndex(l)}const h=new Uint32Array(o*o);t.copy(e);let m;for(m=e.count-1;m>=0;){const f=e.findCluster();e.removePointIndex(f),h[f]=m,m--}const d=o*o;for(m=t.count;m<d/2;){const f=t.findVoid();t.addPointIndex(f),h[f]=m,m++}for(t.invert();m<d;){const f=t.findCluster();t.removePointIndex(f),h[f]=m,m++}return{data:h,maxValue:d}}}function lr(s){return s>=3?4:s}function cr(s){switch(s){case 1:return n.RedFormat;case 2:return n.RGFormat;default:return n.RGBAFormat}}class ur extends n.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,n.RGBAFormat,n.FloatType),this.minFilter=n.NearestFilter,this.magFilter=n.NearestFilter,this.size=e,this.channels=t,this.update()}update(){const e=this.channels,t=this.size,r=new nr;r.channels=e,r.size=t;const i=lr(e),o=cr(i);(this.image.width!==t||o!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*i),this.format=o,this.dispose());const a=this.image.data;for(let c=0,h=e;c<h;c++){const m=r.generate(),d=m.data,f=m.maxValue;for(let l=0,y=d.length;l<y;l++){const p=d[l]/f;a[l*i+c]=p}}this.needsUpdate=!0}}const fr=`
|
|
570
570
|
|
|
571
571
|
struct PhysicalCamera {
|
|
572
572
|
|
|
@@ -578,7 +578,7 @@ struct BVH {
|
|
|
578
578
|
|
|
579
579
|
};
|
|
580
580
|
|
|
581
|
-
`,
|
|
581
|
+
`,hr=`
|
|
582
582
|
|
|
583
583
|
struct EquirectHdrInfo {
|
|
584
584
|
|
|
@@ -590,7 +590,7 @@ struct BVH {
|
|
|
590
590
|
|
|
591
591
|
};
|
|
592
592
|
|
|
593
|
-
`,
|
|
593
|
+
`,dr=`
|
|
594
594
|
|
|
595
595
|
#define RECT_AREA_LIGHT_TYPE 0
|
|
596
596
|
#define CIRC_AREA_LIGHT_TYPE 1
|
|
@@ -676,7 +676,7 @@ struct BVH {
|
|
|
676
676
|
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
`,
|
|
679
|
+
`,mr=`
|
|
680
680
|
|
|
681
681
|
struct Material {
|
|
682
682
|
|
|
@@ -883,7 +883,7 @@ struct BVH {
|
|
|
883
883
|
|
|
884
884
|
}
|
|
885
885
|
|
|
886
|
-
`,
|
|
886
|
+
`,pr=`
|
|
887
887
|
|
|
888
888
|
struct SurfaceRecord {
|
|
889
889
|
|
|
@@ -945,7 +945,7 @@ struct BVH {
|
|
|
945
945
|
vec3 color;
|
|
946
946
|
};
|
|
947
947
|
|
|
948
|
-
`,
|
|
948
|
+
`,gr=`
|
|
949
949
|
|
|
950
950
|
// samples the the given environment map in the given direction
|
|
951
951
|
vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
|
|
@@ -1012,7 +1012,7 @@ struct BVH {
|
|
|
1012
1012
|
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
1013
1013
|
|
|
1014
1014
|
}
|
|
1015
|
-
`,
|
|
1015
|
+
`,vr=`
|
|
1016
1016
|
|
|
1017
1017
|
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
|
|
1018
1018
|
|
|
@@ -1227,7 +1227,7 @@ struct BVH {
|
|
|
1227
1227
|
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
|
-
`,
|
|
1230
|
+
`,xr=`
|
|
1231
1231
|
|
|
1232
1232
|
vec3 sampleHemisphere( vec3 n, vec2 uv ) {
|
|
1233
1233
|
|
|
@@ -1312,7 +1312,7 @@ struct BVH {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
1314
|
|
|
1315
|
-
`,
|
|
1315
|
+
`,yr=`
|
|
1316
1316
|
|
|
1317
1317
|
bool totalInternalReflection( float cosTheta, float eta ) {
|
|
1318
1318
|
|
|
@@ -1415,7 +1415,7 @@ struct BVH {
|
|
|
1415
1415
|
|
|
1416
1416
|
}
|
|
1417
1417
|
|
|
1418
|
-
`,
|
|
1418
|
+
`,br=`
|
|
1419
1419
|
|
|
1420
1420
|
// Fast arccos approximation used to remove banding artifacts caused by numerical errors in acos.
|
|
1421
1421
|
// This is a cubic Lagrange interpolating polynomial for x = [-1, -1/2, 0, 1/2, 1].
|
|
@@ -1495,7 +1495,7 @@ struct BVH {
|
|
|
1495
1495
|
|
|
1496
1496
|
}
|
|
1497
1497
|
|
|
1498
|
-
`,
|
|
1498
|
+
`,Tr=`
|
|
1499
1499
|
|
|
1500
1500
|
// Finds the point where the ray intersects the plane defined by u and v and checks if this point
|
|
1501
1501
|
// falls in the bounds of the rectangle on that same plane.
|
|
@@ -1556,7 +1556,7 @@ struct BVH {
|
|
|
1556
1556
|
|
|
1557
1557
|
}
|
|
1558
1558
|
|
|
1559
|
-
`,
|
|
1559
|
+
`,wr=`
|
|
1560
1560
|
|
|
1561
1561
|
// add texel fetch functions for texture arrays
|
|
1562
1562
|
vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
|
|
@@ -1579,7 +1579,7 @@ struct BVH {
|
|
|
1579
1579
|
|
|
1580
1580
|
}
|
|
1581
1581
|
|
|
1582
|
-
|
|
1582
|
+
`,$e=`
|
|
1583
1583
|
|
|
1584
1584
|
// TODO: possibly this should be renamed something related to material or path tracing logic
|
|
1585
1585
|
|
|
@@ -1694,7 +1694,7 @@ struct BVH {
|
|
|
1694
1694
|
return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) );
|
|
1695
1695
|
|
|
1696
1696
|
}
|
|
1697
|
-
`,
|
|
1697
|
+
`,De=`
|
|
1698
1698
|
|
|
1699
1699
|
// https://www.shadertoy.com/view/wltcRS
|
|
1700
1700
|
uvec4 WHITE_NOISE_SEED;
|
|
@@ -1750,7 +1750,7 @@ struct BVH {
|
|
|
1750
1750
|
return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu );
|
|
1751
1751
|
|
|
1752
1752
|
}
|
|
1753
|
-
`,
|
|
1753
|
+
`,Rr=`
|
|
1754
1754
|
|
|
1755
1755
|
uniform sampler2D stratifiedTexture;
|
|
1756
1756
|
uniform sampler2D stratifiedOffsetTexture;
|
|
@@ -1799,7 +1799,7 @@ struct BVH {
|
|
|
1799
1799
|
|
|
1800
1800
|
}
|
|
1801
1801
|
|
|
1802
|
-
`,
|
|
1802
|
+
`,Ir=`
|
|
1803
1803
|
|
|
1804
1804
|
// diffuse
|
|
1805
1805
|
float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
|
|
@@ -2237,7 +2237,7 @@ struct BVH {
|
|
|
2237
2237
|
|
|
2238
2238
|
}
|
|
2239
2239
|
|
|
2240
|
-
`,
|
|
2240
|
+
`,Sr=`
|
|
2241
2241
|
|
|
2242
2242
|
// returns the hit distance given the material density
|
|
2243
2243
|
float intersectFogVolume( Material material, float u ) {
|
|
@@ -2258,7 +2258,7 @@ struct BVH {
|
|
|
2258
2258
|
|
|
2259
2259
|
}
|
|
2260
2260
|
|
|
2261
|
-
`,
|
|
2261
|
+
`,_r=`
|
|
2262
2262
|
|
|
2263
2263
|
// The GGX functions provide sampling and distribution information for normals as output so
|
|
2264
2264
|
// in order to get probability of scatter direction the half vector must be computed and provided.
|
|
@@ -2359,7 +2359,7 @@ struct BVH {
|
|
|
2359
2359
|
|
|
2360
2360
|
}
|
|
2361
2361
|
|
|
2362
|
-
`,
|
|
2362
|
+
`,Fr=`
|
|
2363
2363
|
|
|
2364
2364
|
// XYZ to sRGB color space
|
|
2365
2365
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
@@ -2493,7 +2493,7 @@ struct BVH {
|
|
|
2493
2493
|
|
|
2494
2494
|
}
|
|
2495
2495
|
|
|
2496
|
-
`,
|
|
2496
|
+
`,Mr=`
|
|
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
|
+
`,Ar=`
|
|
2594
2594
|
|
|
2595
2595
|
#ifndef FOG_CHECK_ITERATIONS
|
|
2596
2596
|
#define FOG_CHECK_ITERATIONS 30
|
|
@@ -2651,7 +2651,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2651
2651
|
|
|
2652
2652
|
}
|
|
2653
2653
|
|
|
2654
|
-
`,
|
|
2654
|
+
`,Cr=`
|
|
2655
2655
|
|
|
2656
2656
|
// step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
|
|
2657
2657
|
// returns true if a solid surface was hit
|
|
@@ -2828,7 +2828,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2828
2828
|
|
|
2829
2829
|
}
|
|
2830
2830
|
|
|
2831
|
-
`,
|
|
2831
|
+
`,Dr=`
|
|
2832
2832
|
|
|
2833
2833
|
vec3 ndcToRayOrigin( vec2 coord ) {
|
|
2834
2834
|
|
|
@@ -2911,7 +2911,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2911
2911
|
|
|
2912
2912
|
}
|
|
2913
2913
|
|
|
2914
|
-
`,
|
|
2914
|
+
`,Pr=`
|
|
2915
2915
|
|
|
2916
2916
|
vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
|
|
2917
2917
|
|
|
@@ -3007,7 +3007,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3007
3007
|
|
|
3008
3008
|
}
|
|
3009
3009
|
|
|
3010
|
-
`,
|
|
3010
|
+
`,Er=`
|
|
3011
3011
|
|
|
3012
3012
|
#define SKIP_SURFACE 0
|
|
3013
3013
|
#define HIT_SURFACE 1
|
|
@@ -3329,7 +3329,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3329
3329
|
return HIT_SURFACE;
|
|
3330
3330
|
|
|
3331
3331
|
}
|
|
3332
|
-
`,
|
|
3332
|
+
`,Or=`
|
|
3333
3333
|
|
|
3334
3334
|
struct Ray {
|
|
3335
3335
|
|
|
@@ -3378,7 +3378,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3378
3378
|
|
|
3379
3379
|
}
|
|
3380
3380
|
|
|
3381
|
-
`,
|
|
3381
|
+
`,kr=`
|
|
3382
3382
|
|
|
3383
3383
|
#define NO_HIT 0
|
|
3384
3384
|
#define SURFACE_HIT 1
|
|
@@ -3425,7 +3425,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3425
3425
|
|
|
3426
3426
|
}
|
|
3427
3427
|
|
|
3428
|
-
`;class
|
|
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 Ae().texture},lights:{value:new Ut},iesProfiles:{value:new Ae(360,180,{type:n.HalfFloatType,wrapS:n.ClampToEdgeWrapping,wrapT:n.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new n.Matrix4},envMapInfo:{value:new 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() {
|
|
@@ -3449,27 +3449,27 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3449
3449
|
#include <common>
|
|
3450
3450
|
|
|
3451
3451
|
// bvh intersection
|
|
3452
|
-
${
|
|
3453
|
-
${
|
|
3454
|
-
${
|
|
3452
|
+
${tt}
|
|
3453
|
+
${at}
|
|
3454
|
+
${rt}
|
|
3455
3455
|
|
|
3456
3456
|
// uniform structs
|
|
3457
|
-
${lr}
|
|
3458
|
-
${ur}
|
|
3459
|
-
${cr}
|
|
3460
3457
|
${fr}
|
|
3458
|
+
${dr}
|
|
3461
3459
|
${hr}
|
|
3460
|
+
${mr}
|
|
3461
|
+
${pr}
|
|
3462
3462
|
|
|
3463
3463
|
// random
|
|
3464
3464
|
#if RANDOM_TYPE == 2 // Stratified List
|
|
3465
3465
|
|
|
3466
|
-
${
|
|
3466
|
+
${Rr}
|
|
3467
3467
|
|
|
3468
3468
|
#elif RANDOM_TYPE == 1 // Sobol
|
|
3469
3469
|
|
|
3470
|
-
${
|
|
3471
|
-
${
|
|
3472
|
-
${
|
|
3470
|
+
${De}
|
|
3471
|
+
${Ve}
|
|
3472
|
+
${Mt}
|
|
3473
3473
|
|
|
3474
3474
|
#define rand(v) sobol(v)
|
|
3475
3475
|
#define rand2(v) sobol2(v)
|
|
@@ -3478,7 +3478,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3478
3478
|
|
|
3479
3479
|
#else // PCG
|
|
3480
3480
|
|
|
3481
|
-
${
|
|
3481
|
+
${De}
|
|
3482
3482
|
|
|
3483
3483
|
// Using the sobol functions seems to break the the compiler on MacOS
|
|
3484
3484
|
// - specifically the "sobolReverseBits" function.
|
|
@@ -3494,11 +3494,11 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3494
3494
|
#endif
|
|
3495
3495
|
|
|
3496
3496
|
// common
|
|
3497
|
+
${wr}
|
|
3497
3498
|
${yr}
|
|
3498
|
-
${
|
|
3499
|
-
${
|
|
3500
|
-
${
|
|
3501
|
-
${xr}
|
|
3499
|
+
${$e}
|
|
3500
|
+
${br}
|
|
3501
|
+
${Tr}
|
|
3502
3502
|
|
|
3503
3503
|
// environment
|
|
3504
3504
|
uniform EquirectHdrInfo envMapInfo;
|
|
@@ -3554,16 +3554,16 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3554
3554
|
float lightsDenom;
|
|
3555
3555
|
|
|
3556
3556
|
// sampling
|
|
3557
|
-
${
|
|
3558
|
-
${
|
|
3559
|
-
${
|
|
3557
|
+
${xr}
|
|
3558
|
+
${gr}
|
|
3559
|
+
${vr}
|
|
3560
3560
|
|
|
3561
|
+
${Ar}
|
|
3561
3562
|
${_r}
|
|
3562
|
-
${
|
|
3563
|
+
${Mr}
|
|
3564
|
+
${Fr}
|
|
3563
3565
|
${Sr}
|
|
3564
3566
|
${Ir}
|
|
3565
|
-
${wr}
|
|
3566
|
-
${Tr}
|
|
3567
3567
|
|
|
3568
3568
|
float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
|
|
3569
3569
|
|
|
@@ -3595,12 +3595,12 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3595
3595
|
|
|
3596
3596
|
}
|
|
3597
3597
|
|
|
3598
|
+
${Or}
|
|
3598
3599
|
${Dr}
|
|
3599
|
-
${
|
|
3600
|
-
${Pr}
|
|
3601
|
-
${Fr}
|
|
3602
|
-
${Mr}
|
|
3600
|
+
${kr}
|
|
3603
3601
|
${Cr}
|
|
3602
|
+
${Pr}
|
|
3603
|
+
${Er}
|
|
3604
3604
|
|
|
3605
3605
|
void main() {
|
|
3606
3606
|
|
|
@@ -3892,7 +3892,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3892
3892
|
|
|
3893
3893
|
}
|
|
3894
3894
|
|
|
3895
|
-
`}),this.setValues(e)}}function*
|
|
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 N(new Br),this._blendQuad=new N(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 P=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),P.set(i/t,o/r),P.x-=.5,P.y=1-P.y,$.theta=P.x*2*Math.PI,$.phi=P.y*Math.PI,$.radius=1,this.generationCallback($,P,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
|
|
|
@@ -3949,7 +3949,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3949
3949
|
#include <premultiplied_alpha_fragment>
|
|
3950
3950
|
|
|
3951
3951
|
}
|
|
3952
|
-
`}),this.setValues(e)}}class
|
|
3952
|
+
`}),this.setValues(e)}}class Lr extends n.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
|
|
3953
3953
|
varying vec2 vUv;
|
|
3954
3954
|
void main() {
|
|
3955
3955
|
|
|
@@ -3966,7 +3966,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3966
3966
|
#include <common>
|
|
3967
3967
|
#include <cube_uv_reflection_fragment>
|
|
3968
3968
|
|
|
3969
|
-
${
|
|
3969
|
+
${$e}
|
|
3970
3970
|
|
|
3971
3971
|
void main() {
|
|
3972
3972
|
|
|
@@ -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 Oe{constructor(e){this._renderer=e,this._quad=new z(new zr)}generate(e,t=null,r=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const i=e.images[0],o=this._renderer,a=this._quad;t===null&&(t=4*i.height),r===null&&(r=2*i.height);const c=new n.WebGLRenderTarget(t,r,{type:n.FloatType,colorSpace:i.colorSpace}),h=i.height,m=Math.log2(h)-2,d=1/h,f=1/(3*Math.max(Math.pow(2,m),112));a.material.defines.CUBEUV_MAX_MIP=`${m}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=f,a.material.defines.CUBEUV_TEXEL_HEIGHT=d,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;const l=o.getRenderTarget(),y=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),a.render(o),o.setRenderTarget(l),o.autoClear=y;const p=new Uint16Array(t*r*4),v=new Float32Array(t*r*4);o.readRenderTargetPixels(c,0,0,t,r,v),c.dispose();for(let g=0,x=v.length;g<x;g++)p[g]=n.DataUtils.toHalfFloat(v[g]);const u=new n.DataTexture(p,t,r,n.RGBAFormat,n.HalfFloatType);return u.minFilter=n.LinearMipMapLinearFilter,u.magFilter=n.LinearFilter,u.wrapS=n.RepeatWrapping,u.wrapT=n.RepeatWrapping,u.mapping=n.EquirectangularReflectionMapping,u.needsUpdate=!0,u}dispose(){this._quad.dispose()}}function Hr(s){return s.extensions.get("EXT_float_blend")}const k=new n.Vector2;class Wr{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new yt,this._pathTracer=new De(e),this._queueReset=!1,this._clock=new n.Clock,this._compilePromise=null,this._lowResPathTracer=new De(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new z(new Nr({map:null,transparent:!0,blending:n.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new n.Vector2(1024,1024),this.rasterizeSceneCallback=(t,r)=>{this._renderer.render(t,r)},this.renderToCanvasCallback=(t,r,i)=>{const o=r.autoClear;r.autoClear=!1,i.render(r),r.autoClear=o},this.setScene(new n.Scene,new n.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,r={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const i=this._generator;if(i.setObjects(e),this._buildAsync)return i.generateAsync(r.onProgress).then(o=>this._updateFromResults(e,t,o));{const o=i.generate();return this._updateFromResults(e,t,o)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,r=this._materials,i=this.textureSize,o=Vt(r);e.textures.setTextures(t,o,i.x,i.y),e.materials.updateFrom(r,o),this.reset()}updateLights(){const e=this.scene,t=this._renderer,r=this._pathTracer.material,i=qt(e),o=Gt(i);r.lights.updateFrom(i,o),r.iesProfiles.setTextures(t,o),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Br(16);const r=this._colorBackground;r.topColor.equals(e.background)||(r.topColor.set(e.background),r.bottomColor.set(e.background),r.update()),t.backgroundMap=r,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const r=new Oe(this._renderer).generate(e.background);this._internalBackground=r,t.backgroundMap=r,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const r=new Oe(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(r)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,r){const{materials:i,geometry:o,bvh:a,bvhChanged:c}=r;this._materials=i;const m=this._pathTracer.material;return c&&(m.bvh.updateFrom(a),m.attributesArray.updateFrom(o.attributes.normal,o.attributes.tangent,o.attributes.uv,o.attributes.color),m.materialIndexAttribute.updateFrom(o.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),r}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,r=this._renderer,i=this._clock,o=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,o.material.opacity=0,i.start());const a=i.getDelta()*1e3,c=i.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!Hr(r),e.alpha=t.alpha,this.renderToCanvas){const h=this._renderer,m=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?o.material.opacity=Math.min(o.material.opacity+a/this.fadeDuration,1):o.material.opacity=1),!this.enablePathTracing||this.samples<m||o.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const d=o.material.opacity;o.material.opacity=1-o.material.opacity,o.material.map=e.target.texture,o.render(h),o.material.opacity=d}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&o.material.opacity>0&&(o.material.opacity<1&&(o.material.blending=this.dynamicLowRes?n.AdditiveBlending:n.NormalBlending),o.material.map=t.target.texture,this.renderToCanvasCallback(t.target,h,o),o.material.blending=n.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(k);const e=Math.floor(this.renderScale*k.x),t=Math.floor(this.renderScale*k.y);if(this._pathTracer.getSize(k),k.x!==e||k.y!==t){const r=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*r),Math.floor(t*r))}}}}function B(s){return s!==null&&typeof s=="object"&&"getInternalRenderer"in s&&typeof s.getInternalRenderer=="function"}class Lr{constructor(){this.pathTracer=null,this.enabled=!1,this.renderer=null,this.sampleCount=0,this.createAttempts=0,this.maxCreateAttempts=10,this.sceneInitialized=!1,this.environmentWaitFrames=0,this.maxEnvironmentWaitFrames=300,this.disposed=!1,this.disposeTimer=null,this.convertedEnvTexture=null,this.lastResetTime=0,this.events=new T.TypedEventEmitter,this.settings={samples:T.DEFAULT_PATH_TRACING_SAMPLES,bounces:4,transmissiveBounces:2,renderScale:.5,lowResScale:.5,dynamicLowRes:!0,enablePathTracing:!0}}ingestSceneWithoutShadowHelpers(e,t){var i;const r=[];e.traverse(o=>{var a;(a=o.userData)!=null&&a[T.CONTACT_SHADOW_HELPER_FLAG]&&o.visible&&r.push(o)}),r.forEach(o=>o.visible=!1);try{(i=this.pathTracer)==null||i.setScene(e,t)}finally{r.forEach(o=>o.visible=!0)}}convertToDataTexture(e){if(!e.image||!(e.image instanceof HTMLImageElement))return null;const t=e.image,r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return null;i.drawImage(t,0,0);const o=i.getImageData(0,0,r.width,r.height),a=new Float32Array(o.data.length);for(let h=0;h<o.data.length;h++)a[h]=o.data[h]/255;const c=new A.DataTexture(a,r.width,r.height,A.RGBAFormat,A.FloatType);return c.mapping=e.mapping,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.magFilter=e.magFilter,c.minFilter=e.minFilter,c.anisotropy=e.anisotropy,c.needsUpdate=!0,c}async initialize(e){try{return this.renderer=e.renderer,this.enabled=e.enabled,this.isSupported()?T.Result.ok(void 0):T.Result.err(new T.ThreeViewerError("Path tracing is not supported in this environment",T.ErrorCode.PATH_TRACING_INIT_FAILED,{reason:"WebGL2 or required extensions not available"}))}catch(t){return T.Result.err(new T.ThreeViewerError("Failed to initialize path tracing",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:t}))}}createPathTracer(){if(this.disposed)return T.Result.err(new T.ThreeViewerError("Instance is disposed",T.ErrorCode.INVALID_STATE));try{const e=B(this.renderer)?this.renderer.getInternalRenderer():null;return e?(this.pathTracer=new Wr(e),this.pathTracer.tiles&&"set"in this.pathTracer.tiles&&this.pathTracer.tiles.set(1,1),this.pathTracer.bounces=this.settings.bounces,this.settings.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=this.settings.transmissiveBounces),this.pathTracer.renderScale=this.settings.renderScale,this.pathTracer.dynamicLowRes=this.settings.dynamicLowRes,this.pathTracer.lowResScale=this.settings.lowResScale,this.pathTracer.environmentIntensity!==void 0&&(this.pathTracer.environmentIntensity=2),e.toneMapping!==A.ACESFilmicToneMapping&&(e.toneMapping=A.ACESFilmicToneMapping,e.toneMappingExposure=1.5),e.autoClear=!1,e.setRenderTarget(null),T.Result.ok(void 0)):T.Result.err(new T.ThreeViewerError("Renderer not ready, will retry",T.ErrorCode.RENDERER_NOT_INITIALIZED))}catch(e){return T.Result.err(new T.ThreeViewerError("Failed to create path tracer",T.ErrorCode.PATH_TRACING_INIT_FAILED,{originalError:e}))}}setEnabled(e){if(this.enabled!==e&&(this.enabled=e,!e)){this.reset(),this.sceneInitialized=!1;const t=B(this.renderer)?this.renderer.getInternalRenderer():null;t&&(t.autoClear=!0)}}disableAfterSelfPause(e){this.enabled=!1,this.events.emit("pathtracing:paused",{samples:this.sampleCount,reason:e})}updateSettings(e){this.settings={...this.settings,...e},e.enablePathTracing!==void 0&&this.setEnabled(e.enablePathTracing),this.pathTracer&&(e.bounces!==void 0&&(this.pathTracer.bounces=e.bounces),e.transmissiveBounces!==void 0&&(this.pathTracer.transmissiveBounces=e.transmissiveBounces),e.renderScale!==void 0&&(this.pathTracer.renderScale=e.renderScale),e.lowResScale!==void 0&&(this.pathTracer.lowResScale=e.lowResScale),e.dynamicLowRes!==void 0&&(this.pathTracer.dynamicLowRes=e.dynamicLowRes))}async render(e,t){if(this.disposed)return T.Result.ok(void 0);const r=this.renderer;if(!r)return T.Result.ok(void 0);if(!this.enabled)return this.renderWhileDisabled(e,t);if(!this.pathTracer){const i=this.ensurePathTracerCreated(r,e,t);if(i)return i}try{const i=this.extractThreeObjects(e,t);if(!i)return T.Result.err(new T.ThreeViewerError("Could not extract Three.js scene or camera",T.ErrorCode.INVALID_PARAMETER));const{threeScene:o,threeCamera:a}=i;if(!this.sceneInitialized){const c=await this.initializeSceneForPathTracing(r,e,t,o,a);if(c)return c}return this.sceneInitialized?this.accumulateSample(r,e,t):r.render(e,t)}catch(i){return T.Result.err(new T.ThreeViewerError("Failed to render with path tracing",T.ErrorCode.RENDER_FAILED,{originalError:i}))}}ensurePathTracerCreated(e,t,r){var o;this.createAttempts++;const i=this.createPathTracer();return i.ok?(this.createAttempts=0,null):(this.createAttempts<this.maxCreateAttempts&&((o=i.error)==null?void 0:o.message)==="Renderer not ready, will retry"||(this.disableAfterSelfPause("gave-up"),this.createAttempts=0),e.render(t,r))}extractThreeObjects(e,t){let r=null,i=null;return T.hasInternalRenderer(e)&&(r=e.getInternalRenderer()),T.hasInternalRenderer(t)&&(i=t.getInternalRenderer()),!r||!i?null:{threeScene:r,threeCamera:i}}async initializeSceneForPathTracing(e,t,r,i,o){var a;try{const c=i.__originalEnvironmentTexture;if(!i.environment&&!c)return this.environmentWaitFrames++,this.environmentWaitFrames>=this.maxEnvironmentWaitFrames&&(this.disableAfterSelfPause("gave-up"),this.environmentWaitFrames=0),e.render(t,r);if(this.environmentWaitFrames=0,c&&c.mapping===A.EquirectangularReflectionMapping){let h=c;if(c.image instanceof HTMLImageElement)if(this.convertedEnvTexture)h=this.convertedEnvTexture;else{const d=this.convertToDataTexture(c);if(!d)throw new Error("Failed to convert environment texture to DataTexture");this.convertedEnvTexture=d,h=d}const m=i.environment;i.environment=h;try{const d=c.image;d&&!("data"in d&&d.data)&&d instanceof HTMLImageElement&&!d.complete&&await new Promise(f=>{d.onload=()=>{c.needsUpdate=!0,f()},d.onerror=()=>{f()},d.complete&&f()}),this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0,i.environment=m}catch(d){throw i.environment=m,d}}else if(((a=i.environment)==null?void 0:a.mapping)===A.EquirectangularReflectionMapping)this.ingestSceneWithoutShadowHelpers(i,o),this.sceneInitialized=!0;else return this.disableAfterSelfPause("gave-up"),e.render(t,r)}catch(c){return console.warn("Scene initialization error:",c),e.render(t,r)}return null}accumulateSample(e,t,r){var o;if(this.sampleCount===0)try{(o=this.pathTracer)==null||o.updateLights()}catch(a){console.warn("Failed to update lights for path tracing:",a)}const i=e.render(t,r);return i.ok?(this.accumulateOneSample(),this.sampleCount++,this.sampleCount===this.settings.samples?this.captureCompletedFrame():T.Result.ok(void 0)):i}renderWhileDisabled(e,t){return this.renderer?this.sampleCount>=this.settings.samples&&this.sampleCount>0?(this.pathTracer&&B(this.renderer)&&this.renderer.getInternalRenderer().setRenderTarget(null),T.Result.ok(void 0)):this.renderer.render(e,t):T.Result.ok(void 0)}accumulateOneSample(){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;if(!e)throw new Error("Three.js renderer not available");const t=e.autoClear,r=e.getRenderTarget();e.autoClear=!1,this.pathTracer&&this.pathTracer.renderSample(),e.autoClear=t,e.setRenderTarget(r)}captureCompletedFrame(){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;if(e&&this.pathTracer)try{const t=e.autoClear;e.autoClear=!0,e.setRenderTarget(null),e.clear(!0,!0,!0);const r=this.pathTracer.copyQuad;r&&typeof r.render=="function"?r.render(e):(e.autoClear=!1,this.pathTracer.renderSample()),e.autoClear=t}catch(t){console.warn("Failed to present path traced result:",t)}return this.disableAfterSelfPause("completed"),this.disposeTimer=setTimeout(()=>{this.disposeTimer=null,!this.disposed&&this.disposePathTracingResources()},100),T.Result.ok(void 0)}getSampleCount(){return this.sampleCount}isEnabled(){return this.enabled}isPathTracerDisposed(){return this.disposed}reset(e=!1){const t=performance.now();!e&&t-this.lastResetTime<50||(this.lastResetTime=t,this.sampleCount=0,this.pathTracer&&(this.pathTracer.reset(),this.sceneInitialized=!1))}disposePathTracingResources(){if(this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer:",e)}this.pathTracer=null}if(this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.renderer){const e=B(this.renderer)?this.renderer.getInternalRenderer():null;e&&(e.autoClear=!0)}this.sceneInitialized=!1,this.createAttempts=0}dispose(){if(this.disposed=!0,this.events.removeAllListeners(),this.disposeTimer!==null&&(clearTimeout(this.disposeTimer),this.disposeTimer=null),this.pathTracer){try{this.pathTracer.dispose()}catch(e){console.warn("Failed to dispose path tracer during service disposal:",e)}this.pathTracer=null}this.convertedEnvTexture&&(this.convertedEnvTexture.dispose(),this.convertedEnvTexture=null),this.sampleCount=0,this.sceneInitialized=!1,this.createAttempts=0,this.renderer=null}isSupported(){return document.createElement("canvas").getContext("webgl2")!==null}}exports.ThreePathTracingService=Lr;
|
|
3977
|
+
}`}),this.depthWrite=!1,this.depthTest=!1}}class 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;
|