@xiping/react-components 1.0.24 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/blur-fade/BlurFade.d.ts +23 -0
- package/dist/cjs/components/blur-fade/BlurFade.js +1 -0
- package/dist/cjs/components/blur-fade/index.d.ts +2 -0
- package/dist/cjs/components/button/Button.d.ts +3 -3
- package/dist/cjs/components/button/Button.js +1 -1
- package/dist/cjs/components/hyper-text/index.d.ts +1 -1
- package/dist/cjs/components/hyper-text/index.js +1 -1
- package/dist/cjs/components/morphing-text/index.d.ts +1 -1
- package/dist/cjs/components/scratch-to-reveal/ScratchToReveal.d.ts +12 -0
- package/dist/cjs/components/scratch-to-reveal/index.d.ts +2 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/node_modules/.pnpm/react-force-graph-3d@1.28.0_react@19.1.0/node_modules/react-force-graph-3d/dist/react-force-graph-3d.js +1 -1
- package/dist/cjs/node_modules/.pnpm/three-forcegraph@1.43.0_three@0.178.0/node_modules/three-forcegraph/dist/three-forcegraph.js +1 -1
- package/dist/cjs/node_modules/.pnpm/three@0.178.0/node_modules/three/build/three.module.js +1 -1
- package/dist/cjs/node_modules/.pnpm/three@0.178.0/node_modules/three/build/three.webgpu.js +1 -1
- package/dist/cjs/react-components.css +1 -1
- package/dist/es/components/blur-fade/BlurFade.d.ts +23 -0
- package/dist/es/components/blur-fade/BlurFade.js +51 -0
- package/dist/es/components/blur-fade/index.d.ts +2 -0
- package/dist/es/components/button/Button.d.ts +3 -3
- package/dist/es/components/button/Button.js +2 -2
- package/dist/es/components/hyper-text/index.d.ts +1 -1
- package/dist/es/components/hyper-text/index.js +52 -50
- package/dist/es/components/morphing-text/index.d.ts +1 -1
- package/dist/es/components/scratch-to-reveal/ScratchToReveal.d.ts +12 -0
- package/dist/es/components/scratch-to-reveal/index.d.ts +2 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +18 -16
- package/dist/es/node_modules/.pnpm/react-force-graph-3d@1.28.0_react@19.1.0/node_modules/react-force-graph-3d/dist/react-force-graph-3d.js +1 -1
- package/dist/es/node_modules/.pnpm/three-forcegraph@1.43.0_three@0.178.0/node_modules/three-forcegraph/dist/three-forcegraph.js +2 -2
- package/dist/es/node_modules/.pnpm/three@0.178.0/node_modules/three/build/three.core.js +372 -372
- package/dist/es/node_modules/.pnpm/three@0.178.0/node_modules/three/build/three.module.js +1 -1
- package/dist/es/node_modules/.pnpm/three@0.178.0/node_modules/three/build/three.webgpu.js +1 -1
- package/dist/es/react-components.css +1 -1
- package/package.json +19 -19
- /package/dist/cjs/node_modules/.pnpm/{3d-force-graph@1.78.2 → 3d-force-graph@1.78.3}/node_modules/3d-force-graph/dist/3d-force-graph.js +0 -0
- /package/dist/es/node_modules/.pnpm/{3d-force-graph@1.78.2 → 3d-force-graph@1.78.3}/node_modules/3d-force-graph/dist/3d-force-graph.js +0 -0
|
@@ -25,7 +25,7 @@ ${e.tab}if ( ${h} ) {
|
|
|
25
25
|
`).addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode(`
|
|
26
26
|
`+e.tab+n);for(let u=0,a=this.params.length-1;u<a;u++)e.addFlowCode((u===0?"":e.tab)+`}
|
|
27
27
|
|
|
28
|
-
`).removeFlowTab();return e.addFlowTab(),i}}const Ve=(...o)=>E(new Nu(zt(o,"int"))).toStack(),gp=()=>Qt("break").toStack(),Dr=new WeakMap,Ee=new l.Vector4,Hi=v(({bufferMap:o,influence:e,stride:t,width:s,depth:r,offset:n})=>{const i=se(cp).mul(t).add(n),u=i.div(s),a=i.sub(u.mul(s));return Ie(o,Ye(a,u)).depth(r).xyz.mul(e)});function mp(o){const e=o.morphAttributes.position!==void 0,t=o.morphAttributes.normal!==void 0,s=o.morphAttributes.color!==void 0,r=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,n=r!==void 0?r.length:0;let i=Dr.get(o);if(i===void 0||i.count!==n){let _=function(){m.dispose(),Dr.delete(o),o.removeEventListener("dispose",_)};i!==void 0&&i.texture.dispose();const u=o.morphAttributes.position||[],a=o.morphAttributes.normal||[],c=o.morphAttributes.color||[];let d=0;e===!0&&(d=1),t===!0&&(d=2),s===!0&&(d=3);let h=o.attributes.position.count*d,p=1;const f=4096;h>f&&(p=Math.ceil(h/f),h=f);const g=new Float32Array(h*p*4*n),m=new l.DataArrayTexture(g,h,p,n);m.type=l.FloatType,m.needsUpdate=!0;const y=d*4;for(let C=0;C<n;C++){const R=u[C],U=a[C],M=c[C],D=h*p*4*C;for(let F=0;F<R.count;F++){const L=F*y;e===!0&&(Ee.fromBufferAttribute(R,F),g[D+L+0]=Ee.x,g[D+L+1]=Ee.y,g[D+L+2]=Ee.z,g[D+L+3]=0),t===!0&&(Ee.fromBufferAttribute(U,F),g[D+L+4]=Ee.x,g[D+L+5]=Ee.y,g[D+L+6]=Ee.z,g[D+L+7]=0),s===!0&&(Ee.fromBufferAttribute(M,F),g[D+L+8]=Ee.x,g[D+L+9]=Ee.y,g[D+L+10]=Ee.z,g[D+L+11]=M.itemSize===4?Ee.w:1)}}i={count:n,texture:m,stride:d,size:new l.Vector2(h,p)},Dr.set(o,i),o.addEventListener("dispose",_)}return i}class bu extends V{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=O(1),this.updateType=z.OBJECT}setup(e){const{geometry:t}=e,s=t.morphAttributes.position!==void 0,r=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,n=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,i=n!==void 0?n.length:0,{texture:u,stride:a,size:c}=mp(t);s===!0&&Te.mulAssign(this.morphBaseInfluence),r===!0&&Xe.mulAssign(this.morphBaseInfluence);const d=se(c.width);Ve(i,({i:h})=>{const p=b(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?p.assign(Ie(this.mesh.morphTexture,Ye(se(h).add(1),se(ui))).r):p.assign(J("morphTargetInfluences","float").element(h).toVar()),le(p.notEqual(0),()=>{s===!0&&Te.addAssign(Hi({bufferMap:u,influence:p,stride:a,width:d,depth:h,offset:se(0)})),r===!0&&Xe.addAssign(Hi({bufferMap:u,influence:p,stride:a,width:d,depth:h,offset:se(1)}))})})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((t,s)=>t+s,0)}}const Tp=B(bu).setParameterLength(1);class Ft extends V{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class Ru extends Ft{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class Au extends Yn{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s=A().toVar("directDiffuse"),r=A().toVar("directSpecular"),n=A().toVar("indirectDiffuse"),i=A().toVar("indirectSpecular"),u={directDiffuse:s,directSpecular:r,indirectDiffuse:n,indirectSpecular:i};return{radiance:A().toVar("radiance"),irradiance:A().toVar("irradiance"),iblIrradiance:A().toVar("iblIrradiance"),ambientOcclusion:b(1).toVar("ambientOcclusion"),reflectedLight:u,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const yp=B(Au);class Cu extends Ft{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let ss,rs;class ae extends V{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===ae.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=z.NONE;return(this.scope===ae.SIZE||this.scope===ae.VIEWPORT)&&(e=z.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===ae.VIEWPORT?t!==null?rs.copy(t.viewport):(e.getViewport(rs),rs.multiplyScalar(e.getPixelRatio())):t!==null?(ss.width=t.width,ss.height=t.height):e.getDrawingBufferSize(ss)}setup(){const e=this.scope;let t=null;return e===ae.SIZE?t=O(ss||(ss=new l.Vector2)):e===ae.VIEWPORT?t=O(rs||(rs=new l.Vector4)):t=w(Sr.div(Rn)),t}generate(e){if(this.scope===ae.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rn).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}ae.COORDINATE="coordinate";ae.VIEWPORT="viewport";ae.SIZE="size";ae.UV="uv";const qt=P(ae,ae.UV),Rn=P(ae,ae.SIZE),Sr=P(ae,ae.COORDINATE),bs=P(ae,ae.VIEWPORT);bs.zw;bs.xy;const ns=new l.Vector2;class li extends Mt{static get type(){return"ViewportTextureNode"}constructor(e=qt,t=null,s=null){s===null&&(s=new l.FramebufferTexture,s.minFilter=l.LinearMipmapLinearFilter),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=z.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(ns);const s=this.value;(s.image.width!==ns.width||s.image.height!==ns.height)&&(s.image.width=ns.width,s.image.height=ns.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const vu=B(li,null,null,{generateMipmaps:!0}).setParameterLength(0,3);let Lr=null;class Eu extends li{static get type(){return"ViewportDepthTextureNode"}constructor(e=qt,t=null){Lr===null&&(Lr=new l.DepthTexture),super(e,t,Lr)}}const xp=B(Eu).setParameterLength(0,2);class Ne extends V{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===Ne.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===Ne.DEPTH_BASE)s!==null&&(r=Fu().assign(s));else if(t===Ne.DEPTH)e.isPerspectiveCamera?r=_p(ue.z,bt,Rt):r=Rs(ue.z,bt,Rt);else if(t===Ne.LINEAR_DEPTH)if(s!==null)if(e.isPerspectiveCamera){const n=Bu(s,bt,Rt);r=Rs(n,bt,Rt)}else r=s;else r=Rs(ue.z,bt,Rt);return r}}Ne.DEPTH_BASE="depthBase";Ne.DEPTH="depth";Ne.LINEAR_DEPTH="linearDepth";const Rs=(o,e,t)=>o.add(e).div(e.sub(t)),_p=(o,e,t)=>e.add(o).mul(t).div(t.sub(e).mul(o)),Bu=(o,e,t)=>e.mul(t).div(t.sub(e).mul(o).sub(t)),Mu=(o,e,t)=>{e=e.max(1e-6).toVar();const s=Ze(o.negate().div(e)),r=Ze(t.div(e));return s.div(r)},Fu=B(Ne,Ne.DEPTH_BASE),wu=P(Ne,Ne.DEPTH),Sp=B(Ne,Ne.LINEAR_DEPTH).setParameterLength(0,1);xp();wu.assign=o=>Fu(o);class De extends V{static get type(){return"ClippingNode"}constructor(e=De.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===De.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===De.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return v(()=>{const s=b().toVar("distanceToPlane"),r=b().toVar("distanceToGradient"),n=b(1).toVar("clipOpacity"),i=t.length;if(this.hardwareClipping===!1&&i>0){const a=We(t);Ve(i,({i:c})=>{const d=a.element(c);s.assign(ue.dot(d.xyz).negate().add(d.w)),r.assign(s.fwidth().div(2)),n.mulAssign(lt(r.negate(),r,s))})}const u=e.length;if(u>0){const a=We(e),c=b(1).toVar("intersectionClipOpacity");Ve(u,({i:d})=>{const h=a.element(d);s.assign(ue.dot(h.xyz).negate().add(h.w)),r.assign(s.fwidth().div(2)),c.mulAssign(lt(r.negate(),r,s).oneMinus())}),n.mulAssign(c.oneMinus())}K.a.mulAssign(n),K.a.equal(0).discard()})()}setupDefault(e,t){return v(()=>{const s=t.length;if(this.hardwareClipping===!1&&s>0){const n=We(t);Ve(s,({i})=>{const u=n.element(i);ue.dot(u.xyz).greaterThan(u.w).discard()})}const r=e.length;if(r>0){const n=We(e),i=Vn(!0).toVar("clipped");Ve(r,({i:u})=>{const a=n.element(u);i.assign(ue.dot(a.xyz).greaterThan(a.w).and(i))}),i.discard()}})()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),v(()=>{const r=We(e),n=Tr(t.getClipDistance());Ve(s,({i})=>{const u=r.element(i),a=ue.dot(u.xyz).sub(u.w).negate();n.element(i).assign(a)})})()}}De.ALPHA_TO_COVERAGE="alphaToCoverage";De.DEFAULT="default";De.HARDWARE="hardware";const Np=()=>E(new De),bp=()=>E(new De(De.ALPHA_TO_COVERAGE)),Rp=()=>E(new De(De.HARDWARE)),Ap=.05,qi=v(([o])=>dt($(1e4,Oe($(17,o.x).add($(.1,o.y)))).mul(Ce(.1,we(Oe($(13,o.y).add(o.x))))))),Xi=v(([o])=>qi(w(qi(o.xy),o.z))),Cp=v(([o])=>{const e=ye(Je(Aa(o.xyz)),Je(Ca(o.xyz))),t=b(1).div(b(Ap).mul(e)).toVar("pixScale"),s=w(vs(vt(Ze(t))),vs(Kn(Ze(t)))),r=w(Xi(vt(s.x.mul(o.xyz))),Xi(vt(s.y.mul(o.xyz)))),n=dt(Ze(t)),i=Ce($(n.oneMinus(),r.x),$(n,r.y)),u=Kt(n,n.oneMinus()),a=A(i.mul(i).div($(2,u).mul(_e(1,u))),i.sub($(.5,u)).div(_e(1,u)),_e(1,_e(1,i).mul(_e(1,i)).div($(2,u).mul(_e(1,u))))),c=i.lessThan(u.oneMinus()).select(i.lessThan(u).select(a.x,a.y),a.z);return et(c,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class Pu extends ni{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e),s=e.hasGeometryAttribute(t);let r;return s===!0?r=super.generate(e):r=e.generateConst(this.nodeType,new l.Vector4(1,1,1,1)),r}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const vp=(o=0)=>E(new Pu(o)),Ep=v(([o])=>k(o.rgb.mul(o.a),o.a),{color:"vec4",return:"vec4"});class ce extends l.Material{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,Object.defineProperty(this,"shadowPositionNode",{get:()=>this.receivedShadowPositionNode,set:e=>{console.warn('THREE.NodeMaterial: ".shadowPositionNode" was renamed to ".receivedShadowPositionNode".'),this.receivedShadowPositionNode=e}})}customProgramCacheKey(){return this.type+Jo(this)}build(e){this.setup(e)}setupObserver(e){return new Zo(e)}setup(e){e.context.setupNormal=()=>Ss(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);const t=e.renderer,s=t.getRenderTarget();e.addStack();const r=Ss(this.setupVertex(e),"VERTEX"),n=this.vertexNode||r;e.stack.outputNode=n,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let i;const u=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(s!==null?s.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupVariants(e);const a=this.setupLighting(e);u!==null&&e.stack.add(u);const c=k(a,K.a).max(0);i=this.setupOutput(e,c),xs.assign(i);const d=this.outputNode!==null;if(d&&(i=this.outputNode),s!==null){const h=t.getMRT(),p=this.mrtNode;h!==null?(d&&xs.assign(i),i=h,p!==null&&(i=h.merge(p))):p!==null&&(i=p)}}else{let a=this.fragmentNode;a.isOutputStructNode!==!0&&(a=k(a)),i=this.setupOutput(e,a)}e.stack.outputNode=i,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const n=e.renderer.samples;this.alphaToCoverage&&n>1?r=bp():e.stack.add(Np())}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,e.clippingContext===null)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(Rp()),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(r===null){const n=t.getMRT();n&&n.has("depth")?r=n.get("depth"):t.logarithmicDepthBuffer===!0&&(s.isPerspectiveCamera?r=Mu(ue.z,bt,Rt):r=Rs(ue.z,bt,Rt))}r!==null&&wu.assign(r).toStack()}setupPositionView(){return yr.mul(Te).xyz}setupModelViewProjection(){return oi.mul(ue)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.vertex=e.removeStack(),Tu}setupPosition(e){const{object:t,geometry:s}=e;if((s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Tp(t).toStack(),t.isSkinnedMesh===!0&&fp(t).toStack(),this.displacementMap){const r=ot("displacementMap","texture"),n=ot("displacementScale","float"),i=ot("displacementBias","float");Te.addAssign(Xe.normalize().mul(r.x.mul(n).add(i)))}return t.isBatchedMesh&&pp(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&hp(t).toStack(),this.positionNode!==null&&Te.assign(Ss(this.positionNode,"POSITION","vec3")),Te}setupDiffuseColor({object:e,geometry:t}){this.maskNode!==null&&Vn(this.maskNode).not().discard();let s=this.colorNode?k(this.colorNode):Dh;this.vertexColors===!0&&t.hasAttribute("color")&&(s=s.mul(vp())),e.instanceColor&&(s=ar("vec3","vInstanceColor").mul(s)),e.isBatchedMesh&&e._colorsTexture&&(s=ar("vec3","vBatchColor").mul(s)),K.assign(s);const r=this.opacityNode?b(this.opacityNode):gu;K.a.assign(K.a.mul(r));let n=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(n=this.alphaTestNode!==null?b(this.alphaTestNode):Ph,K.a.lessThanEqual(n).discard()),this.alphaHash===!0&&K.a.lessThan(Cp(Te)).discard(),this.transparent===!1&&this.blending===l.NormalBlending&&this.alphaToCoverage===!1?K.a.assign(1):n===null&&K.a.lessThanEqual(0).discard()}setupVariants(){}setupOutgoingLight(){return this.lights===!0?A(0):K.rgb}setupNormal(){return this.normalNode?A(this.normalNode):kh}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?ot("envMap","cubeTexture"):ot("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Cu(mu)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),this.aoNode!==null||e.material.aoMap){const i=this.aoNode!==null?this.aoNode:lp;t.push(new Ru(i))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,u=this.lights===!0||this.lightsNode!==null?this.setupLights(e):null;let a=this.setupOutgoingLight(e);if(u&&u.getScope().hasLights){const c=this.setupLightingModel(e)||null;a=yp(u,c,s,r)}else s!==null&&(a=A(r!==null?ne(a,s,r):s));return(n&&n.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(Mi.assign(A(n||Uh)),a=a.add(Mi)),a}setupFog(e,t){const s=e.fogNode;return s&&(xs.assign(t),t=k(s)),t}setupPremultipliedAlpha(e,t){return Ep(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(const s in e){const r=e[s];this[s]===void 0&&(this[s]=r,r&&r.clone&&(this[s]=r.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const s in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,s)===void 0&&t[s].get!==void 0&&Object.defineProperty(this.constructor.prototype,s,t[s])}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});const s=l.Material.prototype.toJSON.call(this,e),r=nr(this);s.inputNodes={};for(const{property:i,childNode:u}of r)s.inputNodes[i]=u.toJSON(e).uuid;function n(i){const u=[];for(const a in i){const c=i[a];delete c.metadata,u.push(c)}return u}if(t){const i=n(e.textures),u=n(e.images),a=n(e.nodes);i.length>0&&(s.textures=i),u.length>0&&(s.images=u),a.length>0&&(s.nodes=a)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.maskNode=e.maskNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.receivedShadowPositionNode=e.receivedShadowPositionNode,this.castShadowPositionNode=e.castShadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const Bp=new l.LineBasicMaterial;class Du extends ce{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(Bp),this.setValues(e)}}const Mp=new l.LineDashedMaterial;class Lu extends ce{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(Mp),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?b(this.offsetNode):op,t=this.dashScaleNode?b(this.dashScaleNode):rp,s=this.dashSizeNode?b(this.dashSizeNode):np,r=this.gapSizeNode?b(this.gapSizeNode):ip;Mr.assign(s),Fi.assign(r);const n=ht(ct("lineDistance").mul(t));(e?n.add(e):n).mod(Mr.add(Fi)).greaterThan(Mr).discard()}}const Fp=o=>E(o).mul(.5).add(.5),wp=new l.MeshNormalMaterial;class Uu extends ce{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(wp),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?b(this.opacityNode):gu;K.assign(ti(k(Fp(Z),e),l.SRGBColorSpace))}}const Gu=v(([o=Ya])=>{const e=o.z.atan(o.x).mul(1/(Math.PI*2)).add(.5),t=o.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return w(e,t)});class Iu extends l.WebGLCubeRenderTarget{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new l.BoxGeometry(5,5,5),i=Gu(Ya),u=new ce;u.colorNode=X(t,i,0),u.side=l.BackSide,u.blending=l.NoBlending;const a=new l.Mesh(n,u),c=new l.Scene;c.add(a),t.minFilter===l.LinearMipmapLinearFilter&&(t.minFilter=l.LinearFilter);const d=new l.CubeCamera(1,10,this),h=e.getMRT();return e.setMRT(null),d.update(e,c),e.setMRT(h),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const As=new WeakMap;class Pp extends fe{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Fs(null);const t=new l.CubeTexture;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=z.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const n=r.isTextureNode?r.value:s[r.property];if(n&&n.isTexture){const i=n.mapping;if(i===l.EquirectangularReflectionMapping||i===l.EquirectangularRefractionMapping){if(As.has(n)){const u=As.get(n);Ki(u,n.mapping),this._cubeTexture=u}else{const u=n.image;if(Dp(u)){const a=new Iu(u.height);a.fromEquirectangularTexture(t,n),Ki(a.texture,n.mapping),this._cubeTexture=a.texture,As.set(n,a.texture),n.addEventListener("dispose",Ou)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Dp(o){return o==null?!1:o.height>0}function Ou(o){const e=o.target;e.removeEventListener("dispose",Ou);const t=As.get(e);t!==void 0&&(As.delete(e),t.dispose())}function Ki(o,e){e===l.EquirectangularReflectionMapping?o.mapping=l.CubeReflectionMapping:e===l.EquirectangularRefractionMapping&&(o.mapping=l.CubeRefractionMapping)}const Vu=B(Pp).setParameterLength(1);class Nr extends Ft{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Vu(this.envNode)}}class Lp extends Ft{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=b(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ls{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class ku extends Ls{constructor(){super()}indirect({context:e}){const t=e.ambientOcclusion,s=e.reflectedLight,r=e.irradianceLightMap;s.indirectDiffuse.assign(k(0)),r?s.indirectDiffuse.addAssign(r):s.indirectDiffuse.addAssign(k(1,1,1,0)),s.indirectDiffuse.mulAssign(t),s.indirectDiffuse.mulAssign(K.rgb)}finish(e){const{material:t,context:s}=e,r=s.outgoingLight,n=e.context.environment;if(n)switch(t.combine){case l.MultiplyOperation:r.rgb.assign(ne(r.rgb,r.rgb.mul(n.rgb),tr.mul(Pr)));break;case l.MixOperation:r.rgb.assign(ne(r.rgb,n.rgb,tr.mul(Pr)));break;case l.AddOperation:r.rgb.addAssign(n.rgb.mul(tr.mul(Pr)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",t.combine);break}}}const Up=new l.MeshBasicMaterial;class zu extends ce{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Up),this.setValues(e)}setupNormal(){return Ds(Ms)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Nr(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Lp(mu)),t}setupOutgoingLight(){return K.rgb}setupLightingModel(){return new ku}}const ws=v(({f0:o,f90:e,dotVH:t})=>{const s=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return o.mul(s.oneMinus()).add(e.mul(s))}),Yt=v(o=>o.diffuseColor.mul(1/Math.PI)),Gp=()=>b(.25),Ip=v(({dotNH:o})=>xn.mul(b(.5)).add(1).mul(b(1/Math.PI)).mul(o.pow(xn))),Op=v(({lightDirection:o})=>{const e=o.add(oe).normalize(),t=Z.dot(e).clamp(),s=oe.dot(e).clamp(),r=ws({f0:Be,f90:1,dotVH:s}),n=Gp(),i=Ip({dotNH:t});return r.mul(n).mul(i)});class ci extends ku{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const n=Z.dot(e).clamp().mul(t);s.directDiffuse.addAssign(n.mul(Yt({diffuseColor:K.rgb}))),this.specular===!0&&s.directSpecular.addAssign(n.mul(Op({lightDirection:e})).mul(tr))}indirect(e){const{ambientOcclusion:t,irradiance:s,reflectedLight:r}=e.context;r.indirectDiffuse.addAssign(s.mul(Yt({diffuseColor:K}))),r.indirectDiffuse.mulAssign(t)}}const Vp=new l.MeshLambertMaterial;class $u extends ce{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Vp),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Nr(t):null}setupLightingModel(){return new ci(!1)}}const kp=new l.MeshPhongMaterial;class Wu extends ce{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(kp),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Nr(t):null}setupLightingModel(){return new ci}setupVariants(){const e=(this.shininessNode?b(this.shininessNode):Lh).max(1e-4);xn.assign(e);const t=this.specularNode||Gh;Be.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const zp=v(o=>{if(o.geometry.hasAttribute("normal")===!1)return b(0);const e=Ms.dFdx().abs().max(Ms.dFdy().abs());return e.x.max(e.y).max(e.z)}),Hu=v(o=>{const{roughness:e}=o,t=zp();let s=e.max(.0525);return s=s.add(t),s=s.min(1),s}),$p=v(({alpha:o,dotNL:e,dotNV:t})=>{const s=o.pow2(),r=e.mul(s.add(s.oneMinus().mul(t.pow2())).sqrt()),n=t.mul(s.add(s.oneMinus().mul(e.pow2())).sqrt());return qe(.5,r.add(n).max(nd))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),Wp=v(({alphaT:o,alphaB:e,dotTV:t,dotBV:s,dotTL:r,dotBL:n,dotNV:i,dotNL:u})=>{const a=u.mul(A(o.mul(t),e.mul(s),i).length()),c=i.mul(A(o.mul(r),e.mul(n),u).length());return qe(.5,a.add(c)).saturate()}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hp=v(({alpha:o,dotNH:e})=>{const t=o.pow2(),s=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(s.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),qp=b(1/Math.PI),Xp=v(({alphaT:o,alphaB:e,dotNH:t,dotTH:s,dotBH:r})=>{const n=o.mul(e),i=A(e.mul(s),o.mul(r),n.mul(t)),u=i.dot(i),a=n.div(u);return qp.mul(n.mul(a.pow2()))}).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),Qi=v(({lightDirection:o,f0:e,f90:t,roughness:s,f:r,normalView:n=Z,USE_IRIDESCENCE:i,USE_ANISOTROPY:u})=>{const a=s.pow2(),c=o.add(oe).normalize(),d=n.dot(o).clamp(),h=n.dot(oe).clamp(),p=n.dot(c).clamp(),f=oe.dot(c).clamp();let g=ws({f0:e,f90:t,dotVH:f}),m,y;if(Bi(i)&&(g=$n.mix(g,r)),Bi(u)){const _=Zs.dot(o),C=Zs.dot(oe),R=Zs.dot(c),U=Wt.dot(o),M=Wt.dot(oe),D=Wt.dot(c);m=Wp({alphaT:yn,alphaB:a,dotTV:C,dotBV:M,dotTL:_,dotBL:U,dotNV:h,dotNL:d}),y=Xp({alphaT:yn,alphaB:a,dotNH:p,dotTH:R,dotBH:D})}else m=$p({alpha:a,dotNL:d,dotNV:h}),y=Hp({alpha:a,dotNH:p});return g.mul(m).mul(y)}),qu=v(({roughness:o,dotNV:e})=>{const t=k(-1,-.0275,-.572,.022),s=k(1,.0425,1.04,-.04),r=o.mul(t).add(s),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return w(-1.04,1.04).mul(n).add(r.zw)}).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xu=v(o=>{const{dotNV:e,specularColor:t,specularF90:s,roughness:r}=o,n=qu({dotNV:e,roughness:r});return t.mul(n.x).add(s.mul(n.y))}),Kp=v(({f:o,f90:e,dotVH:t})=>{const s=t.oneMinus().saturate(),r=s.mul(s),n=s.mul(r,r).clamp(0,.9999);return o.sub(A(e).mul(n)).div(n.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qp=v(({roughness:o,dotNH:e})=>{const t=o.pow2(),s=b(1).div(t),n=e.pow2().oneMinus().max(.0078125);return b(2).add(s).mul(n.pow(s.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Yp=v(({dotNV:o,dotNL:e})=>b(1).div(b(4).mul(e.add(o).sub(e.mul(o))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),jp=v(({lightDirection:o})=>{const e=o.add(oe).normalize(),t=Z.dot(o).clamp(),s=Z.dot(oe).clamp(),r=Z.dot(e).clamp(),n=Qp({roughness:zn,dotNH:r}),i=Yp({dotNV:s,dotNL:t});return It.mul(n).mul(i)}),Zp=v(({N:o,V:e,roughness:t})=>{const n=.0078125,i=o.dot(e).saturate(),u=w(t,i.oneMinus().sqrt());return u.assign(u.mul(.984375).add(n)),u}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),Jp=v(({f:o})=>{const e=o.length();return ye(e.mul(e).add(o.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),Gs=v(({v1:o,v2:e})=>{const t=o.dot(e),s=t.abs().toVar(),r=s.mul(.0145206).add(.4965155).mul(s).add(.8543985).toVar(),n=s.add(4.1616724).mul(s).add(3.417594).toVar(),i=r.div(n),u=t.greaterThan(0).select(i,ye(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(i));return o.cross(e).mul(u)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),Yi=v(({N:o,V:e,P:t,mInv:s,p0:r,p1:n,p2:i,p3:u})=>{const a=n.sub(r).toVar(),c=u.sub(r).toVar(),d=a.cross(c),h=A().toVar();return le(d.dot(t.sub(r)).greaterThanEqual(0),()=>{const p=e.sub(o.mul(e.dot(o))).normalize(),f=o.cross(p).negate(),g=s.mul(Re(p,f,o).transpose()).toVar(),m=g.mul(r.sub(t)).normalize().toVar(),y=g.mul(n.sub(t)).normalize().toVar(),_=g.mul(i.sub(t)).normalize().toVar(),C=g.mul(u.sub(t)).normalize().toVar(),R=A(0).toVar();R.addAssign(Gs({v1:m,v2:y})),R.addAssign(Gs({v1:y,v2:_})),R.addAssign(Gs({v1:_,v2:C})),R.addAssign(Gs({v1:C,v2:m})),h.assign(A(Jp({f:R})))}),h}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),br=1/6,Ku=o=>$(br,$(o,$(o,o.negate().add(3)).sub(3)).add(1)),An=o=>$(br,$(o,$(o,$(3,o).sub(6))).add(4)),Qu=o=>$(br,$(o,$(o,$(-3,o).add(3)).add(3)).add(1)),Cn=o=>$(br,mr(o,3)),ji=o=>Ku(o).add(An(o)),Zi=o=>Qu(o).add(Cn(o)),Ji=o=>Ce(-1,An(o).div(Ku(o).add(An(o)))),eo=o=>Ce(1,Cn(o).div(Qu(o).add(Cn(o)))),to=(o,e,t)=>{const s=o.uvNode,r=$(s,e.zw).add(.5),n=vt(r),i=dt(r),u=ji(i.x),a=Zi(i.x),c=Ji(i.x),d=eo(i.x),h=Ji(i.y),p=eo(i.y),f=w(n.x.add(c),n.y.add(h)).sub(.5).mul(e.xy),g=w(n.x.add(d),n.y.add(h)).sub(.5).mul(e.xy),m=w(n.x.add(c),n.y.add(p)).sub(.5).mul(e.xy),y=w(n.x.add(d),n.y.add(p)).sub(.5).mul(e.xy),_=ji(i.y).mul(Ce(u.mul(o.sample(f).level(t)),a.mul(o.sample(g).level(t)))),C=Zi(i.y).mul(Ce(u.mul(o.sample(m).level(t)),a.mul(o.sample(y).level(t))));return _.add(C)},ef=v(([o,e])=>{const t=w(o.size(se(e))),s=w(o.size(se(e.add(1)))),r=qe(1,t),n=qe(1,s),i=to(o,k(r,t),vt(e)),u=to(o,k(n,s),Kn(e));return dt(e).mix(i,u)}),so=v(([o,e,t,s,r])=>{const n=A(wa(e.negate(),Es(o),qe(1,s))),i=A(Je(r[0].xyz),Je(r[1].xyz),Je(r[2].xyz));return Es(n).mul(t.mul(i))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),tf=v(([o,e])=>o.mul(et(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),sf=vu(),rf=vu(),ro=v(([o,e,t],{material:s})=>{const n=(s.side===l.BackSide?sf:rf).sample(o),i=Ze(Rn.x).mul(tf(e,t));return ef(n,i)}),no=v(([o,e,t])=>(le(t.notEqual(0),()=>{const s=Na(e).negate().div(t);return Sa(s.negate().mul(o))}),A(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),nf=v(([o,e,t,s,r,n,i,u,a,c,d,h,p,f,g])=>{let m,y;if(g){m=k().toVar(),y=A().toVar();const M=d.sub(1).mul(g.mul(.025)),D=A(d.sub(M),d,d.add(M));Ve({start:0,end:3},({i:F})=>{const L=D.element(F),G=so(o,e,h,L,u),H=i.add(G),q=c.mul(a.mul(k(H,1))),ee=w(q.xy.div(q.w)).toVar();ee.addAssign(1),ee.divAssign(2),ee.assign(w(ee.x,ee.y.oneMinus()));const te=ro(ee,t,L);m.element(F).assign(te.element(F)),m.a.addAssign(te.a),y.element(F).assign(s.element(F).mul(no(Je(G),p,f).element(F)))}),m.a.divAssign(3)}else{const M=so(o,e,h,d,u),D=i.add(M),F=c.mul(a.mul(k(D,1))),L=w(F.xy.div(F.w)).toVar();L.addAssign(1),L.divAssign(2),L.assign(w(L.x,L.y.oneMinus())),m=ro(L,t,d),y=s.mul(no(Je(M),p,f))}const _=y.rgb.mul(m.rgb),C=o.dot(e).clamp(),R=A(Xu({dotNV:C,specularColor:r,specularF90:n,roughness:t})),U=y.r.add(y.g,y.b).div(3);return k(R.oneMinus().mul(_),m.a.oneMinus().mul(U).oneMinus())}),of=Re(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),af=o=>{const e=o.sqrt();return A(1).add(e).div(A(1).sub(e))},io=(o,e)=>o.sub(e).div(o.add(e)).pow2(),uf=(o,e)=>{const t=o.mul(2*Math.PI*1e-9),s=A(54856e-17,44201e-17,52481e-17),r=A(1681e3,1795300,2208400),n=A(43278e5,93046e5,66121e5),i=b(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp());let u=s.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(t).add(e).cos()).mul(t.pow2().negate().mul(n).exp());return u=A(u.x.add(i),u.y,u.z).div(10685e-11),of.mul(u)},lf=v(({outsideIOR:o,eta2:e,cosTheta1:t,thinFilmThickness:s,baseF0:r})=>{const n=ne(o,e,lt(0,.03,s)),u=o.div(n).pow2().mul(t.pow2().oneMinus()).oneMinus();le(u.lessThan(0),()=>A(1));const a=u.sqrt(),c=io(n,o),d=ws({f0:c,f90:1,dotVH:t}),h=d.oneMinus(),p=n.lessThan(o).select(Math.PI,0),f=b(Math.PI).sub(p),g=af(r.clamp(0,.9999)),m=io(g,n.toVec3()),y=ws({f0:m,f90:1,dotVH:a}),_=A(g.x.lessThan(n).select(Math.PI,0),g.y.lessThan(n).select(Math.PI,0),g.z.lessThan(n).select(Math.PI,0)),C=n.mul(s,a,2),R=A(f).add(_),U=d.mul(y).clamp(1e-5,.9999),M=U.sqrt(),D=h.pow2().mul(y).div(A(1).sub(U)),L=d.add(D).toVar(),G=D.sub(h).toVar();return Ve({start:1,end:2,condition:"<=",name:"m"},({m:H})=>{G.mulAssign(M);const q=uf(b(H).mul(C),b(H).mul(R)).mul(2);L.addAssign(G.mul(q))}),L.max(A(0))}).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),cf=v(({normal:o,viewDir:e,roughness:t})=>{const s=o.dot(e).saturate(),r=t.pow2(),n=Se(t.lessThan(.25),b(-339.2).mul(r).add(b(161.4).mul(t)).sub(25.9),b(-8.48).mul(r).add(b(14.3).mul(t)).sub(9.95)),i=Se(t.lessThan(.25),b(44).mul(r).sub(b(23.7).mul(t)).add(3.26),b(1.97).mul(r).sub(b(3.27).mul(t)).add(.72));return Se(t.lessThan(.25),0,b(.1).mul(t).sub(.025)).add(n.mul(s).add(i).exp()).mul(1/Math.PI).saturate()}),Ur=A(.04),Gr=b(1);class di extends Ls{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=A().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=A().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=A().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=A().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=A().toVar("sheenSpecularIndirect")),this.iridescence===!0){const t=Z.dot(oe).clamp();this.iridescenceFresnel=lf({outsideIOR:b(1),eta2:da,cosTheta1:t,thinFilmThickness:ha,baseF0:Be}),this.iridescenceF0=Kp({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(this.transmission===!0){const t=Bs,s=ah.sub(Bs).normalize(),r=es,n=e.context;n.backdrop=nf(r,s,je,K,Be,cr,t,Et,tt,oi,Js,pa,ga,fa,this.dispersion?ma:null),n.backdropAlpha=_n,K.a.mulAssign(ne(1,n.backdrop.a,_n))}super.start(e)}computeMultiscattering(e,t,s){const r=Z.dot(oe).clamp(),n=qu({roughness:je,dotNV:r}),u=(this.iridescenceF0?$n.mix(Be,this.iridescenceF0):Be).mul(n.x).add(s.mul(n.y)),c=n.x.add(n.y).oneMinus(),d=Be.add(Be.oneMinus().mul(.047619)),h=u.mul(d).div(c.mul(d).oneMinus());e.addAssign(u),t.addAssign(h.mul(c))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const n=Z.dot(e).clamp().mul(t);if(this.sheen===!0&&this.sheenSpecularDirect.addAssign(n.mul(jp({lightDirection:e}))),this.clearcoat===!0){const u=Ot.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(u.mul(Qi({lightDirection:e,f0:Ur,f90:Gr,roughness:lr,normalView:Ot})))}s.directDiffuse.addAssign(n.mul(Yt({diffuseColor:K.rgb}))),s.directSpecular.addAssign(n.mul(Qi({lightDirection:e,f0:Be,f90:1,roughness:je,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:u}){const a=t.add(s).sub(r),c=t.sub(s).sub(r),d=t.sub(s).add(r),h=t.add(s).add(r),p=Z,f=oe,g=ue.toVar(),m=Zp({N:p,V:f,roughness:je}),y=i.sample(m).toVar(),_=u.sample(m).toVar(),C=Re(A(y.x,0,y.y),A(0,1,0),A(y.z,0,y.w)).toVar(),R=Be.mul(_.x).add(Be.oneMinus().mul(_.y)).toVar();n.directSpecular.addAssign(e.mul(R).mul(Yi({N:p,V:f,P:g,mInv:C,p0:a,p1:c,p2:d,p3:h}))),n.directDiffuse.addAssign(e.mul(K).mul(Yi({N:p,V:f,P:g,mInv:Re(1,0,0,0,1,0,0,0,1),p0:a,p1:c,p2:d,p3:h})))}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){const{irradiance:t,reflectedLight:s}=e.context;s.indirectDiffuse.addAssign(t.mul(Yt({diffuseColor:K})))}indirectSpecular(e){const{radiance:t,iblIrradiance:s,reflectedLight:r}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(s.mul(It,cf({normal:Z,viewDir:oe,roughness:zn}))),this.clearcoat===!0){const d=Ot.dot(oe).clamp(),h=Xu({dotNV:d,specularColor:Ur,specularF90:Gr,roughness:lr});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(h))}const n=A().toVar("singleScattering"),i=A().toVar("multiScattering"),u=s.mul(1/Math.PI);this.computeMultiscattering(n,i,cr);const a=n.add(i),c=K.mul(a.r.max(a.g).max(a.b).oneMinus());r.indirectSpecular.addAssign(t.mul(n)),r.indirectSpecular.addAssign(i.mul(u)),r.indirectDiffuse.addAssign(c.mul(u))}ambientOcclusion(e){const{ambientOcclusion:t,reflectedLight:s}=e.context,n=Z.dot(oe).clamp().add(t),i=je.mul(-16).oneMinus().negate().exp2(),u=t.sub(n.pow(i).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),s.indirectDiffuse.mulAssign(t),s.indirectSpecular.mulAssign(u)}finish({context:e}){const{outgoingLight:t}=e;if(this.clearcoat===!0){const s=Ot.dot(oe).clamp(),r=ws({dotVH:s,f0:Ur,f90:Gr}),n=t.mul(Tn.mul(r).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Tn));t.assign(n)}if(this.sheen===!0){const s=It.r.max(It.g).max(It.b).mul(.157).oneMinus(),r=t.mul(s).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(r)}}}const oo=b(1),vn=b(-2),Is=b(.8),Ir=b(-1),Os=b(.4),Or=b(2),Vs=b(.305),Vr=b(3),ao=b(.21),df=b(4),uo=b(4),hf=b(16),pf=v(([o])=>{const e=A(we(o)).toVar(),t=b(-1).toVar();return le(e.x.greaterThan(e.z),()=>{le(e.x.greaterThan(e.y),()=>{t.assign(Se(o.x.greaterThan(0),0,3))}).Else(()=>{t.assign(Se(o.y.greaterThan(0),1,4))})}).Else(()=>{le(e.z.greaterThan(e.y),()=>{t.assign(Se(o.z.greaterThan(0),2,5))}).Else(()=>{t.assign(Se(o.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),ff=v(([o,e])=>{const t=w().toVar();return le(e.equal(0),()=>{t.assign(w(o.z,o.y).div(we(o.x)))}).ElseIf(e.equal(1),()=>{t.assign(w(o.x.negate(),o.z.negate()).div(we(o.y)))}).ElseIf(e.equal(2),()=>{t.assign(w(o.x.negate(),o.y).div(we(o.z)))}).ElseIf(e.equal(3),()=>{t.assign(w(o.z.negate(),o.y).div(we(o.x)))}).ElseIf(e.equal(4),()=>{t.assign(w(o.x.negate(),o.z).div(we(o.y)))}).Else(()=>{t.assign(w(o.x,o.y).div(we(o.z)))}),$(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),gf=v(([o])=>{const e=b(0).toVar();return le(o.greaterThanEqual(Is),()=>{e.assign(oo.sub(o).mul(Ir.sub(vn)).div(oo.sub(Is)).add(vn))}).ElseIf(o.greaterThanEqual(Os),()=>{e.assign(Is.sub(o).mul(Or.sub(Ir)).div(Is.sub(Os)).add(Ir))}).ElseIf(o.greaterThanEqual(Vs),()=>{e.assign(Os.sub(o).mul(Vr.sub(Or)).div(Os.sub(Vs)).add(Or))}).ElseIf(o.greaterThanEqual(ao),()=>{e.assign(Vs.sub(o).mul(df.sub(Vr)).div(Vs.sub(ao)).add(Vr))}).Else(()=>{e.assign(b(-2).mul(Ze($(1.16,o))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),mf=v(([o,e])=>{const t=o.toVar();t.assign($(2,t).sub(1));const s=A(t,1).toVar();return le(e.equal(0),()=>{s.assign(s.zyx)}).ElseIf(e.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(e.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(e.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(e.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(e.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Tf=v(([o,e,t,s,r,n])=>{const i=b(t),u=A(e),a=et(gf(i),vn,n),c=dt(a),d=vt(a),h=A(En(o,u,d,s,r,n)).toVar();return le(c.notEqual(0),()=>{const p=A(En(o,u,d.add(1),s,r,n)).toVar();h.assign(ne(h,p,c))}),h}),En=v(([o,e,t,s,r,n])=>{const i=b(t).toVar(),u=A(e),a=b(pf(u)).toVar(),c=b(ye(uo.sub(i),0)).toVar();i.assign(ye(i,uo));const d=b(vs(i)).toVar(),h=w(ff(u,a).mul(d.sub(2)).add(1)).toVar();return le(a.greaterThan(2),()=>{h.y.addAssign(d),a.subAssign(3)}),h.x.addAssign(a.mul(d)),h.x.addAssign(c.mul($(3,hf))),h.y.addAssign($(4,vs(n).sub(d))),h.x.mulAssign(s),h.y.mulAssign(r),o.sample(h).grad(w(),w())}),kr=v(({envMap:o,mipInt:e,outputDirection:t,theta:s,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:i,CUBEUV_MAX_MIP:u})=>{const a=it(s),c=t.mul(a).add(r.cross(t).mul(Oe(s))).add(r.mul(r.dot(t).mul(a.oneMinus())));return En(o,c,e,n,i,u)}),yf=v(({n:o,latitudinal:e,poleAxis:t,outputDirection:s,weights:r,samples:n,dTheta:i,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h})=>{const p=A(Se(e,t,Ea(t,s))).toVar();le(p.equal(A(0)),()=>{p.assign(A(s.z,0,s.x.negate()))}),p.assign(Es(p));const f=A().toVar();return f.addAssign(r.element(0).mul(kr({theta:0,axis:p,outputDirection:s,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h}))),Ve({start:se(1),end:o},({i:g})=>{le(g.greaterThanEqual(n),()=>{gp()});const m=b(i.mul(b(g))).toVar();f.addAssign(r.element(g).mul(kr({theta:m.mul(-1),axis:p,outputDirection:s,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h}))),f.addAssign(r.element(g).mul(kr({theta:m,axis:p,outputDirection:s,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h})))}),k(f,1)}),Vt=4,lo=[.125,.215,.35,.446,.526,.582],At=20,zr=new l.OrthographicCamera(-1,1,1,-1,0,1),xf=new l.PerspectiveCamera(90,1),co=new l.Color;let $r=null,Wr=0,Hr=0;const Nt=(1+Math.sqrt(5))/2,wt=1/Nt,ho=[new l.Vector3(-Nt,wt,0),new l.Vector3(Nt,wt,0),new l.Vector3(-wt,0,Nt),new l.Vector3(wt,0,Nt),new l.Vector3(0,Nt,-wt),new l.Vector3(0,Nt,wt),new l.Vector3(-1,1,-1),new l.Vector3(1,1,-1),new l.Vector3(-1,1,1),new l.Vector3(1,1,1)],_f=new l.Vector3,Yu=new WeakMap,Sf=[3,1,5,0,4,2],qr=mf(Ps(),ct("faceIndex")).normalize(),hi=A(qr.x,qr.y,qr.z);class ju{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,s=.1,r=100,n={}){const{size:i=256,position:u=_f,renderTarget:a=null}=n;if(this._setSize(i),this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.");const d=a||this._allocateTarget();return n.renderTarget=d,this.fromSceneAsync(e,t,s,r,n),d}$r=this._renderer.getRenderTarget(),Wr=this._renderer.getActiveCubeFace(),Hr=this._renderer.getActiveMipmapLevel();const c=a||this._allocateTarget();return c.depthBuffer=!0,this._init(c),this._sceneToCubeUV(e,s,r,c,u),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}async fromSceneAsync(e,t=0,s=.1,r=100,n={}){return this._hasInitialized===!1&&await this._renderer.init(),this.fromScene(e,t,s,r,n)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead."),this._setSizeFromTexture(e);const s=t||this._allocateTarget();return this.fromEquirectangularAsync(e,s),s}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return this._hasInitialized===!1&&await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const s=t||this._allocateTarget();return this.fromCubemapAsync(e,t),s}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return this._hasInitialized===!1&&await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=fo(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=go(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===l.CubeReflectionMapping||e.mapping===l.CubeRefractionMapping?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget($r,Wr,Hr),e.scissorTest=!1,ks(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),$r=this._renderer.getRenderTarget(),Wr=this._renderer.getActiveCubeFace(),Hr=this._renderer.getActiveMipmapLevel();const s=t||this._allocateTarget();return this._init(s),this._textureToCubeUV(e,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTarget(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize;return po(e,t)}_init(e){if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=po(e.width,e.height);const{_lodMax:t}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=Nf(t)),this._blurMaterial=bf(t,e.width,e.height)}}async _compileMaterial(e){const t=new l.Mesh(this._lodPlanes[0],e);await this._renderer.compile(t,zr)}_sceneToCubeUV(e,t,s,r,n){const i=xf;i.near=t,i.far=s;const u=[1,1,1,1,-1,1],a=[1,-1,1,-1,1,-1],c=this._renderer,d=c.autoClear;c.getClearColor(co),c.autoClear=!1;let h=this._backgroundBox;if(h===null){const g=new l.MeshBasicMaterial({name:"PMREM.Background",side:l.BackSide,depthWrite:!1,depthTest:!1});h=new l.Mesh(new l.BoxGeometry,g)}let p=!1;const f=e.background;f?f.isColor&&(h.material.color.copy(f),e.background=null,p=!0):(h.material.color.copy(co),p=!0),c.setRenderTarget(r),c.clear(),p&&c.render(h,i);for(let g=0;g<6;g++){const m=g%3;m===0?(i.up.set(0,u[g],0),i.position.set(n.x,n.y,n.z),i.lookAt(n.x+a[g],n.y,n.z)):m===1?(i.up.set(0,0,u[g]),i.position.set(n.x,n.y,n.z),i.lookAt(n.x,n.y+a[g],n.z)):(i.up.set(0,u[g],0),i.position.set(n.x,n.y,n.z),i.lookAt(n.x,n.y,n.z+a[g]));const y=this._cubeSize;ks(r,m*y,g>2?y:0,y,y),c.render(e,i)}c.autoClear=d,e.background=f}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===l.CubeReflectionMapping||e.mapping===l.CubeRefractionMapping;r?this._cubemapMaterial===null&&(this._cubemapMaterial=fo(e)):this._equirectMaterial===null&&(this._equirectMaterial=go(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const u=this._cubeSize;ks(t,0,0,3*u,2*u),s.setRenderTarget(t),s.render(i,zr)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let n=1;n<r;n++){const i=Math.sqrt(this._sigmas[n]*this._sigmas[n]-this._sigmas[n-1]*this._sigmas[n-1]),u=ho[(r-n-1)%ho.length];this._blur(e,n-1,n,i,u)}t.autoClear=s}_blur(e,t,s,r,n){const i=this._pingPongRenderTarget;this._halfBlur(e,i,t,s,r,"latitudinal",n),this._halfBlur(i,e,s,s,r,"longitudinal",n)}_halfBlur(e,t,s,r,n,i,u){const a=this._renderer,c=this._blurMaterial;i!=="latitudinal"&&i!=="longitudinal"&&console.error("blur direction must be either latitudinal or longitudinal!");const d=3,h=this._lodMeshes[r];h.material=c;const p=Yu.get(c),f=this._sizeLods[s]-1,g=isFinite(n)?Math.PI/(2*f):2*Math.PI/(2*At-1),m=n/g,y=isFinite(n)?1+Math.floor(d*m):At;y>At&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${y} samples when the maximum is set to ${At}`);const _=[];let C=0;for(let F=0;F<At;++F){const L=F/m,G=Math.exp(-L*L/2);_.push(G),F===0?C+=G:F<y&&(C+=2*G)}for(let F=0;F<_.length;F++)_[F]=_[F]/C;e.texture.frame=(e.texture.frame||0)+1,p.envMap.value=e.texture,p.samples.value=y,p.weights.array=_,p.latitudinal.value=i==="latitudinal"?1:0,u&&(p.poleAxis.value=u);const{_lodMax:R}=this;p.dTheta.value=g,p.mipInt.value=R-s;const U=this._sizeLods[r],M=3*U*(r>R-Vt?r-R+Vt:0),D=4*(this._cubeSize-U);ks(t,M,D,3*U,2*U),a.setRenderTarget(t),a.render(h,zr)}}function Nf(o){const e=[],t=[],s=[],r=[];let n=o;const i=o-Vt+1+lo.length;for(let u=0;u<i;u++){const a=Math.pow(2,n);t.push(a);let c=1/a;u>o-Vt?c=lo[u-o+Vt-1]:u===0&&(c=0),s.push(c);const d=1/(a-2),h=-d,p=1+d,f=[h,h,p,h,p,p,h,h,p,p,h,p],g=6,m=6,y=3,_=2,C=1,R=new Float32Array(y*m*g),U=new Float32Array(_*m*g),M=new Float32Array(C*m*g);for(let F=0;F<g;F++){const L=F%3*2/3-1,G=F>2?0:-1,H=[L,G,0,L+2/3,G,0,L+2/3,G+1,0,L,G,0,L+2/3,G+1,0,L,G+1,0],q=Sf[F];R.set(H,y*m*q),U.set(f,_*m*q);const ee=[q,q,q,q,q,q];M.set(ee,C*m*q)}const D=new l.BufferGeometry;D.setAttribute("position",new l.BufferAttribute(R,y)),D.setAttribute("uv",new l.BufferAttribute(U,_)),D.setAttribute("faceIndex",new l.BufferAttribute(M,C)),e.push(D),r.push(new l.Mesh(D,null)),n>Vt&&n--}return{lodPlanes:e,sizeLods:t,sigmas:s,lodMeshes:r}}function po(o,e){const t={magFilter:l.LinearFilter,minFilter:l.LinearFilter,generateMipmaps:!1,type:l.HalfFloatType,format:l.RGBAFormat,colorSpace:l.LinearSRGBColorSpace},s=new l.RenderTarget(o,e,t);return s.texture.mapping=l.CubeUVReflectionMapping,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function ks(o,e,t,s,r){o.viewport.set(e,t,s,r),o.scissor.set(e,t,s,r)}function pi(o){const e=new ce;return e.depthTest=!1,e.depthWrite=!1,e.blending=l.NoBlending,e.name=`PMREM_${o}`,e}function bf(o,e,t){const s=We(new Array(At).fill(0)),r=O(new l.Vector3(0,1,0)),n=O(0),i=b(At),u=O(0),a=O(1),c=X(null),d=O(0),h=b(1/e),p=b(1/t),f=b(o),g={n:i,latitudinal:u,weights:s,poleAxis:r,outputDirection:hi,dTheta:n,samples:a,envMap:c,mipInt:d,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:f},m=pi("blur");return m.fragmentNode=yf({...g,latitudinal:u.equal(1)}),Yu.set(m,g),m}function fo(o){const e=pi("cubemap");return e.fragmentNode=Fs(o,hi),e}function go(o){const e=pi("equirect");return e.fragmentNode=X(o,Gu(hi),0),e}const mo=new WeakMap;function Rf(o){const e=Math.log2(o)-2,t=1/o;return{texelWidth:1/(3*Math.max(Math.pow(2,e),7*16)),texelHeight:t,maxMip:e}}function Af(o,e,t){const s=Cf(e);let r=s.get(o);if((r!==void 0?r.pmremVersion:-1)!==o.pmremVersion){const i=o.image;if(o.isCubeTexture)if(vf(i))r=t.fromCubemap(o,r);else return null;else if(Ef(i))r=t.fromEquirectangular(o,r);else return null;r.pmremVersion=o.pmremVersion,s.set(o,r)}return r.texture}function Cf(o){let e=mo.get(o);return e===void 0&&(e=new WeakMap,mo.set(o,e)),e}class Zu extends fe{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new l.Texture;r.isRenderTargetTexture=!0,this._texture=X(r),this._width=O(0),this._height=O(0),this._maxMip=O(0),this.updateBeforeType=z.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=Rf(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem;const s=t?t.pmremVersion:-1,r=this._value;s!==r.pmremVersion&&(r.isPMREMTexture===!0?t=r:t=Af(r,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new ju(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this)),t=tu.mul(A(t.x,t.y.negate(),t.z));let s=this.levelNode;return s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this)),Tf(this._texture,t,s,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}}function vf(o){if(o==null)return!1;let e=0;const t=6;for(let s=0;s<t;s++)o[s]!==void 0&&e++;return e===t}function Ef(o){return o==null?!1:o.height>0}const Ju=B(Zu).setParameterLength(1,3),To=new WeakMap;class el extends Ft{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const h=s.isTextureNode?s.value:t[s.property];let p=To.get(h);p===void 0&&(p=Ju(h),To.set(h,p)),s=p}const n=t.useAnisotropy===!0||t.anisotropy>0?Bh:Z,i=s.context(yo(je,n)).mul(wr),u=s.context(Bf(es)).mul(Math.PI).mul(wr),a=er(i),c=er(u);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(c);const d=e.context.lightingModel.clearcoatRadiance;if(d){const h=s.context(yo(lr,Ot)).mul(wr),p=er(h);d.addAssign(p)}}}const yo=(o,e)=>{let t=null;return{getUV:()=>(t===null&&(t=oe.negate().reflect(e),t=o.mul(o).mix(t,e).normalize(),t=t.transformDirection(tt)),t),getTextureLevel:()=>o}},Bf=o=>({getUV:()=>o,getTextureLevel:()=>b(1)}),Mf=new l.MeshStandardMaterial;class fi extends ce{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(Mf),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new el(t):null}setupLightingModel(){return new di}setupSpecular(){const e=ne(A(.04),K.rgb,ur);Be.assign(e),cr.assign(1)}setupVariants(){const e=this.metalnessNode?b(this.metalnessNode):Vh;ur.assign(e);let t=this.roughnessNode?b(this.roughnessNode):Oh;t=Hu({roughness:t}),je.assign(t),this.setupSpecular(),K.assign(k(K.rgb.mul(e.oneMinus()),K.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const Ff=new l.MeshPhysicalMaterial;class tl extends fi{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(Ff),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){const e=this.iorNode?b(this.iorNode):ep;Js.assign(e),Be.assign(ne(Kt(Ba(Js.sub(1).div(Js.add(1))).mul(Ih),A(1)).mul($i),K.rgb,ur)),cr.assign(ne($i,1,ur))}setupLightingModel(){return new di(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const t=this.clearcoatNode?b(this.clearcoatNode):zh,s=this.clearcoatRoughnessNode?b(this.clearcoatRoughnessNode):$h;Tn.assign(t),lr.assign(Hu({roughness:s}))}if(this.useSheen){const t=this.sheenNode?A(this.sheenNode):qh,s=this.sheenRoughnessNode?b(this.sheenRoughnessNode):Xh;It.assign(t),zn.assign(s)}if(this.useIridescence){const t=this.iridescenceNode?b(this.iridescenceNode):Qh,s=this.iridescenceIORNode?b(this.iridescenceIORNode):Yh,r=this.iridescenceThicknessNode?b(this.iridescenceThicknessNode):jh;$n.assign(t),da.assign(s),ha.assign(r)}if(this.useAnisotropy){const t=(this.anisotropyNode?w(this.anisotropyNode):Kh).toVar();St.assign(t.length()),le(St.equal(0),()=>{t.assign(w(1,0))}).Else(()=>{t.divAssign(w(St)),St.assign(St.saturate())}),yn.assign(St.pow2().mix(je.pow2(),1)),Zs.assign(ms[0].mul(t.x).add(ms[1].mul(t.y))),Wt.assign(ms[1].mul(t.x).sub(ms[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?b(this.transmissionNode):Zh,s=this.thicknessNode?b(this.thicknessNode):Jh,r=this.attenuationDistanceNode?b(this.attenuationDistanceNode):tp,n=this.attenuationColorNode?A(this.attenuationColorNode):sp;if(_n.assign(t),pa.assign(s),fa.assign(r),ga.assign(n),this.useDispersion){const i=this.dispersionNode?b(this.dispersionNode):up;ma.assign(i)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?A(this.clearcoatNormalNode):Wh}setup(e){e.context.setupClearcoatNormal=()=>Ss(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}const wf=v(({normal:o,lightDirection:e,builder:t})=>{const s=o.dot(e),r=w(s.mul(.5).add(.5),0);if(t.material.gradientMap){const n=ot("gradientMap","texture").context({getUV:()=>r});return A(n.r)}else{const n=r.fwidth().mul(.5);return ne(A(.7),A(1),lt(b(.7).sub(n.x),b(.7).add(n.x),r.x))}});class Pf extends Ls{direct({lightDirection:e,lightColor:t,reflectedLight:s},r){const n=wf({normal:Ja,lightDirection:e,builder:r}).mul(t);s.directDiffuse.addAssign(n.mul(Yt({diffuseColor:K.rgb})))}indirect(e){const{ambientOcclusion:t,irradiance:s,reflectedLight:r}=e.context;r.indirectDiffuse.addAssign(s.mul(Yt({diffuseColor:K}))),r.indirectDiffuse.mulAssign(t)}}const Df=new l.MeshToonMaterial;class sl extends ce{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Df),this.setValues(e)}setupLightingModel(){return new Pf}}const Lf=v(()=>{const o=A(oe.z,0,oe.x.negate()).normalize(),e=oe.cross(o);return w(o.dot(Z),e.dot(Z)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),Uf=new l.MeshMatcapMaterial;class rl extends ce{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(Uf),this.setValues(e)}setupVariants(e){const t=Lf;let s;e.material.matcap?s=ot("matcap","texture").context({getUV:()=>t}):s=A(ne(.2,.8,t.y)),K.rgb.mulAssign(s.rgb)}}class nl extends fe{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if(this.getNodeType(e)==="vec2"){const n=t.cos(),i=t.sin();return kn(n,i,i.negate(),n).mul(s)}else{const n=t,i=$t(k(1,0,0,0),k(0,it(n.x),Oe(n.x).negate(),0),k(0,Oe(n.x),it(n.x),0),k(0,0,0,1)),u=$t(k(it(n.y),0,Oe(n.y),0),k(0,1,0,0),k(Oe(n.y).negate(),0,it(n.y),0),k(0,0,0,1)),a=$t(k(it(n.z),Oe(n.z).negate(),0,0),k(Oe(n.z),it(n.z),0,0),k(0,0,1,0),k(0,0,0,1));return i.mul(u).mul(a).mul(k(s,1)).xyz}}}const il=B(nl).setParameterLength(2),Gf=new l.SpriteMaterial;class gi extends ce{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(Gf),this.setValues(e)}setupPositionView(e){const{object:t,camera:s}=e,r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:u}=this,a=yr.mul(A(n||0));let c=w(Et[0].xyz.length(),Et[1].xyz.length());if(u!==null&&(c=c.mul(w(u))),r===!1)if(s.isPerspectiveCamera)c=c.mul(a.z.negate());else{const f=b(2).div(oi.element(1).element(1));c=c.mul(f.mul(2))}let d=xr.xy;if(t.center&&t.center.isVector2===!0){const f=Hd("center","vec2",t);d=d.sub(f.sub(.5))}d=d.mul(c);const h=b(i||Hh),p=il(d,h);return k(a.xy.add(p),a.zw)}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}const If=new l.PointsMaterial;class ol extends gi{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(If),this.setValues(e)}setupPositionView(){const{positionNode:e}=this;return yr.mul(A(e||Te)).xyz}setupVertex(e){const t=super.setupVertex(e);if(e.material.isNodeMaterial!==!0)return t;const{rotationNode:s,scaleNode:r,sizeNode:n}=this,i=xr.xy.toVar(),u=bs.z.div(bs.w);if(s&&s.isNode){const c=b(s);i.assign(il(i,c))}let a=n!==null?w(n):ap;return this.sizeAttenuation===!0&&(a=a.mul(a.div(ue.z.negate()))),r&&r.isNode&&(a=a.mul(w(r))),i.mulAssign(a.mul(2)),i.assign(i.div(bs.z)),i.y.assign(i.y.mul(u)),i.assign(i.mul(t.w)),t.addAssign(k(i,0,0)),t}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}class Of extends Ls{constructor(){super(),this.shadowNode=b(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){K.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(K.rgb)}}const Vf=new l.ShadowMaterial;class al extends ce{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(Vf),this.setValues(e)}setupLightingModel(){return new Of}}ut("vec3");ut("vec3");ut("vec3");class kf{constructor(e,t){this.nodes=e,this.info=t,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this._animationLoop!==null&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class ke{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let s=this.weakMap;for(let r=0;r<e.length-1;r++){const n=e[r];s.has(n)===!1&&s.set(n,new WeakMap),s=s.get(n)}return s.set(e[e.length-1],t),this}delete(e){let t=this.weakMap;for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return!1;return t.delete(e[e.length-1])}}let zf=0;function $f(o){const e=Object.keys(o);let t=Object.getPrototypeOf(o);for(;t;){const s=Object.getOwnPropertyDescriptors(t);for(const r in s)if(s[r]!==void 0){const n=s[r];n&&typeof n.get=="function"&&e.push(r)}t=Object.getPrototypeOf(t)}return e}class Wf{constructor(e,t,s,r,n,i,u,a,c,d){this.id=zf++,this._nodes=e,this._geometries=t,this.renderer=s,this.object=r,this.material=n,this.scene=i,this.camera=u,this.lightsNode=a,this.context=c,this.geometry=r.geometry,this.version=n.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=d,this.clippingContextCacheKey=d!==null?d.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(const t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(this.attributes!==null)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set,n={};for(const i of e){let u;if(i.node&&i.node.attribute?u=i.node.attribute:(u=t.getAttribute(i.name),n[i.name]=u.version),u===void 0)continue;s.push(u);const a=u.isInterleavedBufferAttribute?u.data:u;r.add(a)}return this.attributes=s,this.attributesId=n,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),u=this.getIndex(),a=u!==null;let c=1;if(s.isInstancedBufferGeometry===!0?c=s.instanceCount:e.count!==void 0&&(c=Math.max(0,e.count)),c===0)return null;if(i.instanceCount=c,e.isBatchedMesh===!0)return i;let d=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(d=2);let h=n.start*d,p=(n.start+n.count)*d;r!==null&&(h=Math.max(h,r.start*d),p=Math.min(p,(r.start+r.count)*d));const f=s.attributes.position;let g=1/0;a?g=u.count:f!=null&&(g=f.count),h=Math.max(h,0),p=Math.min(p,g);const m=p-h;return m<0||m===1/0?null:(i.vertexCount=m,i.firstVertex=h,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}for(const s of Object.keys(e.morphAttributes).sort()){const r=e.morphAttributes[s];t+="morph-"+s+",";for(let n=0,i=r.length;n<i;n++){const u=r[n];t+=u.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const r of $f(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(r))continue;const n=t[r];let i;if(n!==null){const u=typeof n;u==="number"?i=n!==0?"1":"0":u==="object"?(i="{",n.isTexture&&(i+=n.mapping),i+="}"):i=String(n)}else i=String(n);s+=i+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),s+=e.receiveShadow+",",Jl(s)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){const e=this.attributesId;for(const t in e){const s=this.geometry.getAttribute(t);if(s===void 0||e[t]!==s.id)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=rr(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=rr(e,1)),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this.onDispose()}}const Tt=[];class Hf{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,u,a){const c=this.getChainMap(a);Tt[0]=e,Tt[1]=t,Tt[2]=i,Tt[3]=n;let d=c.get(Tt);return d===void 0?(d=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,u,a),c.set(Tt,d)):(d.updateClipping(u),d.needsGeometryUpdate&&d.setGeometry(e.geometry),(d.version!==t.version||d.needsUpdate)&&(d.initialCacheKey!==d.getCacheKey()?(d.dispose(),d=this.get(e,t,s,r,n,i,u,a)):d.version=t.version)),Tt.length=0,d}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new ke)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,u,a,c,d,h){const p=this.getChainMap(h),f=new Wf(e,t,s,r,n,i,u,a,c,d);return f.onDispose=()=>{this.pipelines.delete(f),this.bindings.delete(f),this.nodes.delete(f),p.delete(f.getChainArray())},f}}class pt{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Pe={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},at=16,qf=211,Xf=212;class Kf extends pt{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return t!==null&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(s.version===void 0)t===Pe.VERTEX?this.backend.createAttribute(e):t===Pe.INDEX?this.backend.createIndexAttribute(e):t===Pe.STORAGE?this.backend.createStorageAttribute(e):t===Pe.INDIRECT&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const r=this._getBufferAttribute(e);(s.version<r.version||r.usage===l.DynamicDrawUsage)&&(this.backend.updateAttribute(e),s.version=r.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function ul(o){return o.index!==null?o.index.version:o.attributes.position.version}function xo(o){const e=[],t=o.index,s=o.attributes.position;if(t!==null){const n=t.array;for(let i=0,u=n.length;i<u;i+=3){const a=n[i+0],c=n[i+1],d=n[i+2];e.push(a,c,c,d,d,a)}}else{const n=s.array;for(let i=0,u=n.length/3-1;i<u;i+=3){const a=i+0,c=i+1,d=i+2;e.push(a,c,c,d,d,a)}}const r=new(l.arrayNeedsUint32(e)?l.Uint32BufferAttribute:l.Uint16BufferAttribute)(e,1);return r.version=ul(o),r}class Qf extends pt{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry,s=this.get(t);s.initialized=!0,this.info.memory.geometries++;const r=()=>{this.info.memory.geometries--;const n=t.index,i=e.getAttributes();n!==null&&this.attributes.delete(n);for(const a of i)this.attributes.delete(a);const u=this.wireframes.get(t);u!==void 0&&this.attributes.delete(u),t.removeEventListener("dispose",r)};t.addEventListener("dispose",r)}updateAttributes(e){const t=e.getAttributes();for(const n of t)n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute?this.updateAttribute(n,Pe.STORAGE):this.updateAttribute(n,Pe.VERTEX);const s=this.getIndex(e);s!==null&&this.updateAttribute(s,Pe.INDEX);const r=e.geometry.indirect;r!==null&&this.updateAttribute(r,Pe.INDIRECT)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(s.wireframe===!0){const n=this.wireframes;let i=n.get(t);i===void 0?(i=xo(t),n.set(t,i)):i.version!==ul(t)&&(this.attributes.delete(i),i=xo(t),n.set(t,i)),r=i}return r}}class Yf{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class ll{constructor(e){this.cacheKey=e,this.usedTimes=0}}class jf extends ll{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Zf extends ll{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Jf=0;class Xr{constructor(e,t,s,r=null,n=null){this.id=Jf++,this.code=e,this.stage=t,this.name=s,this.transforms=r,this.attributes=n,this.usedTimes=0}}class eg extends pt{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let u=this.programs.compute.get(i.computeShader);u===void 0&&(n&&n.computeProgram.usedTimes===0&&this._releaseProgram(n.computeProgram),u=new Xr(i.computeShader,"compute",e.name,i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,u),s.createProgram(u));const a=this._getComputeCacheKey(e,u);let c=this.caches.get(a);c===void 0&&(n&&n.usedTimes===0&&this._releasePipeline(n),c=this._getComputePipeline(e,u,a,t)),c.usedTimes++,u.usedTimes++,r.version=e.version,r.pipeline=c}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState(),u=e.material?e.material.name:"";let a=this.programs.vertex.get(i.vertexShader);a===void 0&&(n&&n.vertexProgram.usedTimes===0&&this._releaseProgram(n.vertexProgram),a=new Xr(i.vertexShader,"vertex",u),this.programs.vertex.set(i.vertexShader,a),s.createProgram(a));let c=this.programs.fragment.get(i.fragmentShader);c===void 0&&(n&&n.fragmentProgram.usedTimes===0&&this._releaseProgram(n.fragmentProgram),c=new Xr(i.fragmentShader,"fragment",u),this.programs.fragment.set(i.fragmentShader,c),s.createProgram(c));const d=this._getRenderCacheKey(e,a,c);let h=this.caches.get(d);h===void 0?(n&&n.usedTimes===0&&this._releasePipeline(n),h=this._getRenderPipeline(e,a,c,d,t)):e.pipeline=h,h.usedTimes++,a.usedTimes++,c.usedTimes++,r.pipeline=h}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return n===void 0&&(n=new Zf(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return i===void 0&&(i=new jf(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}}class tg extends pt{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const s of t){const r=this.get(s);r.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),r.bindGroup=s)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const s of t){const r=this.get(s);r.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),r.bindGroup=s)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const s=t.attribute,r=s.isIndirectStorageBufferAttribute?Pe.INDIRECT:Pe.STORAGE;this.attributes.update(s,r)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,u=0;for(const a of e.bindings)if(!(a.isNodeUniformsGroup&&this.nodes.updateGroup(a)===!1)){if(a.isStorageBuffer){const c=a.attribute,d=c.isIndirectStorageBufferAttribute?Pe.INDIRECT:Pe.STORAGE;this.attributes.update(c,d)}if(a.isUniformBuffer)a.update()&&s.updateBinding(a);else if(a.isSampler)a.update();else if(a.isSampledTexture){const c=this.textures.get(a.texture);a.needsBindingsUpdate(c.generation)&&(r=!0);const d=a.update(),h=a.texture;d&&this.textures.updateTexture(h);const p=s.get(h);if(p.externalTexture!==void 0||c.isDefaultTexture?n=!1:(i=i*10+h.id,u+=h.version),s.isWebGPUBackend===!0&&p.texture===void 0&&p.externalTexture===void 0&&(console.error("Bindings._update: binding should be available:",a,d,h,a.textureNode.value,r),this.textures.updateTexture(h),r=!0),h.isStorageTexture===!0){const f=this.get(h);a.store===!0?f.needsMipmap=!0:this.textures.needsMipmaps(h)&&f.needsMipmap===!0&&(this.backend.generateMipmaps(h),f.needsMipmap=!1)}}}r===!0&&this.backend.updateBindings(e,t,n?i:0,u)}}function sg(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?o.z-e.z:o.id-e.id}function _o(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?e.z-o.z:o.id-e.id}function So(o){return(o.transmission>0||o.transmissionNode)&&o.side===l.DoubleSide&&o.forceSinglePass===!1}class rg{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,u){let a=this.renderItems[this.renderItemsIndex];return a===void 0?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:u},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=u),this.renderItemsIndex++,a}push(e,t,s,r,n,i,u){const a=this.getNextRenderItem(e,t,s,r,n,i,u);e.occlusionTest===!0&&this.occlusionQueryCount++,s.transparent===!0||s.transmission>0?(So(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,u){const a=this.getNextRenderItem(e,t,s,r,n,i,u);s.transparent===!0||s.transmission>0?(So(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||sg),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||_o),this.transparent.length>1&&this.transparent.sort(t||_o)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const s=this.renderItems[e];if(s.id===null)break;s.id=null,s.object=null,s.geometry=null,s.material=null,s.groupOrder=null,s.renderOrder=null,s.z=null,s.group=null,s.clippingContext=null}}}const is=[];class ng{constructor(e){this.lighting=e,this.lists=new ke}get(e,t){const s=this.lists;is[0]=e,is[1]=t;let r=s.get(is);return r===void 0&&(r=new rg(this.lighting,e,t),s.set(is,r)),is.length=0,r}dispose(){this.lists=new ke}}let ig=0;class og{constructor(){this.id=ig++,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new l.Vector4,this.scissor=!1,this.scissorValue=new l.Vector4,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.isRenderContext=!0}getCacheKey(){return cl(this)}}function cl(o){const{textures:e,activeCubeFace:t}=o,s=[t];for(const r of e)s.push(r.id);return Dn(s)}const os=[],ag=new l.Scene,ug=new l.Camera;class lg{constructor(){this.chainMaps={}}get(e,t,s=null){os[0]=e,os[1]=t;let r;if(s===null)r="default";else{const u=s.texture.format;r=`${s.textures.length}:${u}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this._getChainMap(r);let i=n.get(os);return i===void 0&&(i=new og,n.set(os,i)),os.length=0,s!==null&&(i.sampleCount=s.samples===0?1:s.samples),i}getForClear(e=null){return this.get(ag,ug,e)}_getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new ke)}dispose(){this.chainMaps={}}}const cg=new l.Vector3;class dg extends pt{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){const s=this.get(e),r=e.samples===0?1:e.samples,n=s.depthTextureMips||(s.depthTextureMips={}),i=e.textures,u=this.getSize(i[0]),a=u.width>>t,c=u.height>>t;let d=e.depthTexture||n[t];const h=e.depthBuffer===!0||e.stencilBuffer===!0;let p=!1;d===void 0&&h&&(d=new l.DepthTexture,d.format=e.stencilBuffer?l.DepthStencilFormat:l.DepthFormat,d.type=e.stencilBuffer?l.UnsignedInt248Type:l.UnsignedIntType,d.image.width=a,d.image.height=c,d.image.depth=u.depth,d.isArrayTexture=e.multiview===!0&&u.depth>1,n[t]=d),(s.width!==u.width||u.height!==s.height)&&(p=!0,d&&(d.needsUpdate=!0,d.image.width=a,d.image.height=c,d.image.depth=d.isArrayTexture?d.image.depth:1)),s.width=u.width,s.height=u.height,s.textures=i,s.depthTexture=d||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(p=!0,d&&(d.needsUpdate=!0),s.sampleCount=r);const f={sampleCount:r};if(e.isXRRenderTarget!==!0){for(let g=0;g<i.length;g++){const m=i[g];p&&(m.needsUpdate=!0),this.updateTexture(m,f)}d&&this.updateTexture(d,f)}if(s.initialized!==!0){s.initialized=!0;const g=()=>{e.removeEventListener("dispose",g);for(let m=0;m<i.length;m++)this._destroyTexture(i[m]);d&&this._destroyTexture(d),this.delete(e)};e.addEventListener("dispose",g)}}updateTexture(e,t={}){const s=this.get(e);if(s.initialized===!0&&s.version===e.version)return;const r=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,n=this.backend;if(r&&s.initialized===!0&&(n.destroySampler(e),n.destroyTexture(e)),e.isFramebufferTexture){const c=this.renderer.getRenderTarget();c?e.type=c.texture.type:e.type=l.UnsignedByteType}const{width:i,height:u,depth:a}=this.getSize(e);if(t.width=i,t.height=u,t.depth=a,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,i,u):1,r||e.isStorageTexture===!0)n.createSampler(e),n.createTexture(e,t),s.generation=e.version;else if(s.initialized!==!0&&n.createSampler(e),e.version>0){const d=e.image;if(d===void 0)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(d.complete===!1)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const h=[];for(const p of e.images)h.push(p);t.images=h}else t.image=d;(s.isDefaultTexture===void 0||s.isDefaultTexture===!0)&&(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),e.source.dataReady===!0&&n.updateTexture(e,t),t.needsMipmaps&&e.mipmaps.length===0&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version;if(s.initialized!==!0){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const c=()=>{e.removeEventListener("dispose",c),this._destroyTexture(e)};e.addEventListener("dispose",c)}s.version=e.version}getSize(e,t=cg){let s=e.images?e.images[0]:e.image;return s?(s.image!==void 0&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return e.isCompressedTexture?e.mipmaps?r=e.mipmaps.length:r=1:r=Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return e.isCompressedTexture===!0||e.generateMipmaps}_destroyTexture(e){this.has(e)===!0&&(this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e),this.info.memory.textures--)}}class mi extends l.Color{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class dl extends Y{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}class hl extends V{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.outputNode?this.outputNode.getMemberType(e,t):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new gs(t);return this._currentCond=Se(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new gs(t),r=Se(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new gs(e),this}Switch(e){return this._expressionNode=E(e),this}Case(...e){const t=[];if(e.length>=2)for(let u=0;u<e.length-1;u++)t.push(this._expressionNode.equal(E(e[u])));else throw new Error("TSL: Invalid parameter length. Case() requires at least two parameters.");const s=e[e.length-1],r=new gs(s);let n=t[0];for(let u=1;u<t.length;u++)n=n.or(t[u]);const i=Se(n,r);return this._currentCond===null?(this._currentCond=i,this.add(this._currentCond)):(this._currentCond.elseNode=i,this._currentCond=i,this)}Default(e){return this.Else(e),this}build(e,...t){const s=e.currentStack,r=la();or(this),e.currentStack=this;const n=e.buildStage;for(const u of this.nodes)if(n==="setup")u.build(e);else if(n==="analyze")u.build(e,this);else if(n==="generate"){const a=e.getDataFromNode(u,"any").stages,c=a&&a[e.shaderStage];if(u.isVarNode&&c&&c.length===1&&c[0]&&c[0].isStackNode)continue;u.build(e,"void")}const i=this.outputNode?this.outputNode.build(e,...t):super.build(e,...t);return or(r),e.currentStack=s,i}}const Kr=B(hl).setParameterLength(0,1);new l.Plane;new l.Vector3;new l.Vector3;new l.Vector3;new l.Matrix4;new l.Vector3(0,0,-1);new l.Vector4;new l.Vector3;new l.Vector3;new l.Vector4;new l.Vector2;const hg=new l.RenderTarget;qt.flipX();hg.depthTexture=new l.DepthTexture(1,1);const Qr=new l.OrthographicCamera(-1,1,1,-1,0,1);class pg extends l.BufferGeometry{constructor(e=!1){super();const t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new l.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new l.Float32BufferAttribute(t,2))}}const fg=new pg;class Rr extends l.Mesh{constructor(e=null){super(fg,e),this.camera=Qr,this.isQuadMesh=!0}async renderAsync(e){return e.renderAsync(this,Qr)}render(e){e.render(this,Qr)}}const as=new l.Euler,Yr=new l.Matrix4;class be extends V{static get type(){return"SceneNode"}constructor(e=be.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=this.scene!==null?this.scene:e.scene;let r;return t===be.BACKGROUND_BLURRINESS?r=J("backgroundBlurriness","float",s):t===be.BACKGROUND_INTENSITY?r=J("backgroundIntensity","float",s):t===be.BACKGROUND_ROTATION?r=O("mat4").label("backgroundRotation").setGroup(I).onRenderUpdate(()=>{const n=s.background;return n!==null&&n.isTexture&&n.mapping!==l.UVMapping?(as.copy(s.backgroundRotation),as.x*=-1,as.y*=-1,as.z*=-1,Yr.makeRotationFromEuler(as)):Yr.identity(),Yr}):console.error("THREE.SceneNode: Unknown scope:",t),r}}be.BACKGROUND_BLURRINESS="backgroundBlurriness";be.BACKGROUND_INTENSITY="backgroundIntensity";be.BACKGROUND_ROTATION="backgroundRotation";const gg=P(be,be.BACKGROUND_BLURRINESS),No=P(be,be.BACKGROUND_INTENSITY),mg=P(be,be.BACKGROUND_ROTATION),Tg=v(({texture:o,uv:e})=>{const s=A().toVar();return le(e.x.lessThan(1e-4),()=>{s.assign(A(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{s.assign(A(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{s.assign(A(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{s.assign(A(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{s.assign(A(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{s.assign(A(0,0,-1))}).Else(()=>{const n=o.sample(e.add(A(-.01,0,0))).r.sub(o.sample(e.add(A(.01,0,0))).r),i=o.sample(e.add(A(0,-.01,0))).r.sub(o.sample(e.add(A(0,.01,0))).r),u=o.sample(e.add(A(0,0,-.01))).r.sub(o.sample(e.add(A(0,0,.01))).r);s.assign(A(n,i,u))}),s.normalize()});class pl extends Mt{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return A(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.isRenderTargetTexture===!0||s.isFramebufferTexture===!0)&&(this.sampler?t=t.flipY():t=t.setY(se(Ht(this,this.levelNode).y).sub(t.y).sub(1))),t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Tg({texture:this,uv:e})}}const yg=B(pl).setParameterLength(1,3),zs=new l.Vector2;class xg extends Mt{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class bo extends xg{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){const e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e}}class Us extends fe{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new l.DepthTexture;n.isRenderTargetTexture=!0,n.name="depth";const i=new l.RenderTarget(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:l.HalfFloatType,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=O(0),this._cameraFar=O(0),this._mrt=null,this._layers=null,this._resolution=1,this.isPassNode=!0,this.updateBeforeType=z.FRAME,this.global=!0}setResolution(e){return this._resolution=e,this}getResolution(){return this._resolution}setLayers(e){return this._layers=e,this}getLayers(){return this._layers}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getTexture(e){let t=this._textures[e];return t===void 0&&(t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(t!==void 0){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return t===void 0&&(t=E(new bo(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=E(new bo(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=Bu(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=Rs(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=this.options.samples===void 0?e.samples:this.options.samples,this.renderTarget.texture.type=e.getColorBufferType(),this.scope===Us.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s}=this;let r,n;const i=t.getOutputRenderTarget();i&&i.isXRRenderTarget===!0?(n=1,r=t.xr.getCamera(),t.xr.updateCamera(r),zs.set(i.width,i.height)):(r=this.camera,n=t.getPixelRatio(),t.getSize(zs)),this._pixelRatio=n,this.setSize(zs.width,zs.height);const u=t.getRenderTarget(),a=t.getMRT(),c=r.layers.mask;this._cameraNear.value=r.near,this._cameraFar.value=r.far,this._layers!==null&&(r.layers.mask=this._layers.mask);for(const d in this._previousTextures)this.toggleTexture(d);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(u),t.setMRT(a),r.layers.mask=c}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio*this._resolution,r=this._height*this._pixelRatio*this._resolution;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Us.COLOR="color";Us.DEPTH="depth";const _g=v(([o,e])=>o.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Sg=v(([o,e])=>(o=o.mul(e),o.div(o.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Ng=v(([o,e])=>{o=o.mul(e),o=o.sub(.004).max(0);const t=o.mul(o.mul(6.2).add(.5)),s=o.mul(o.mul(6.2).add(1.7)).add(.06);return t.div(s).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),bg=v(([o])=>{const e=o.mul(o.add(.0245786)).sub(90537e-9),t=o.mul(o.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),Rg=v(([o,e])=>{const t=Re(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),s=Re(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return o=o.mul(e).div(.6),o=t.mul(o),o=bg(o),o=s.mul(o),o.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Ag=Re(A(1.6605,-.1246,-.0182),A(-.5876,1.1329,-.1006),A(-.0728,-.0083,1.1187)),Cg=Re(A(.6274,.0691,.0164),A(.3293,.9195,.088),A(.0433,.0113,.8956)),vg=v(([o])=>{const e=A(o).toVar(),t=A(e.mul(e)).toVar(),s=A(t.mul(t)).toVar();return b(15.5).mul(s.mul(t)).sub($(40.14,s.mul(e))).add($(31.96,s).sub($(6.868,t.mul(e))).add($(.4298,t).add($(.1191,e).sub(.00232))))}),Eg=v(([o,e])=>{const t=A(o).toVar(),s=Re(A(.856627153315983,.137318972929847,.11189821299995),A(.0951212405381588,.761241990602591,.0767994186031903),A(.0482516061458583,.101439036467562,.811302368396859)),r=Re(A(1.1271005818144368,-.1413297634984383,-.14132976349843826),A(-.11060664309660323,1.157823702216272,-.11060664309660294),A(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=b(-12.47393),i=b(4.026069);return t.mulAssign(e),t.assign(Cg.mul(t)),t.assign(s.mul(t)),t.assign(ye(t,1e-10)),t.assign(Ze(t)),t.assign(t.sub(n).div(i.sub(n))),t.assign(et(t,0,1)),t.assign(vg(t)),t.assign(r.mul(t)),t.assign(mr(ye(A(0),t),A(2.2))),t.assign(Ag.mul(t)),t.assign(et(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Bg=v(([o,e])=>{const t=b(.76),s=b(.15);o=o.mul(e);const r=Kt(o.r,Kt(o.g,o.b)),n=Se(r.lessThan(.08),r.sub($(6.25,r.mul(r))),.04);o.subAssign(n);const i=ye(o.r,ye(o.g,o.b));le(i.lessThan(t),()=>o);const u=_e(1,t),a=_e(1,u.mul(u).div(i.add(u.sub(t))));o.mulAssign(a.div(i));const c=_e(1,qe(1,s.mul(i.sub(a)).add(1)));return ne(o,A(a),c)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class de extends V{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=s}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const r of t)r.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}class fl extends de{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return s===void 0&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);r!==""&&(i.name=r);const u=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(u);return i.code=a+`
|
|
28
|
+
`).removeFlowTab();return e.addFlowTab(),i}}const Ve=(...o)=>E(new Nu(zt(o,"int"))).toStack(),gp=()=>Qt("break").toStack(),Dr=new WeakMap,Ee=new l.Vector4,Hi=v(({bufferMap:o,influence:e,stride:t,width:s,depth:r,offset:n})=>{const i=se(cp).mul(t).add(n),u=i.div(s),a=i.sub(u.mul(s));return Ie(o,Ye(a,u)).depth(r).xyz.mul(e)});function mp(o){const e=o.morphAttributes.position!==void 0,t=o.morphAttributes.normal!==void 0,s=o.morphAttributes.color!==void 0,r=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,n=r!==void 0?r.length:0;let i=Dr.get(o);if(i===void 0||i.count!==n){let _=function(){m.dispose(),Dr.delete(o),o.removeEventListener("dispose",_)};i!==void 0&&i.texture.dispose();const u=o.morphAttributes.position||[],a=o.morphAttributes.normal||[],c=o.morphAttributes.color||[];let d=0;e===!0&&(d=1),t===!0&&(d=2),s===!0&&(d=3);let h=o.attributes.position.count*d,p=1;const f=4096;h>f&&(p=Math.ceil(h/f),h=f);const g=new Float32Array(h*p*4*n),m=new l.DataArrayTexture(g,h,p,n);m.type=l.FloatType,m.needsUpdate=!0;const y=d*4;for(let C=0;C<n;C++){const R=u[C],U=a[C],M=c[C],D=h*p*4*C;for(let F=0;F<R.count;F++){const L=F*y;e===!0&&(Ee.fromBufferAttribute(R,F),g[D+L+0]=Ee.x,g[D+L+1]=Ee.y,g[D+L+2]=Ee.z,g[D+L+3]=0),t===!0&&(Ee.fromBufferAttribute(U,F),g[D+L+4]=Ee.x,g[D+L+5]=Ee.y,g[D+L+6]=Ee.z,g[D+L+7]=0),s===!0&&(Ee.fromBufferAttribute(M,F),g[D+L+8]=Ee.x,g[D+L+9]=Ee.y,g[D+L+10]=Ee.z,g[D+L+11]=M.itemSize===4?Ee.w:1)}}i={count:n,texture:m,stride:d,size:new l.Vector2(h,p)},Dr.set(o,i),o.addEventListener("dispose",_)}return i}class bu extends V{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=O(1),this.updateType=z.OBJECT}setup(e){const{geometry:t}=e,s=t.morphAttributes.position!==void 0,r=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,n=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,i=n!==void 0?n.length:0,{texture:u,stride:a,size:c}=mp(t);s===!0&&Te.mulAssign(this.morphBaseInfluence),r===!0&&Xe.mulAssign(this.morphBaseInfluence);const d=se(c.width);Ve(i,({i:h})=>{const p=b(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?p.assign(Ie(this.mesh.morphTexture,Ye(se(h).add(1),se(ui))).r):p.assign(J("morphTargetInfluences","float").element(h).toVar()),le(p.notEqual(0),()=>{s===!0&&Te.addAssign(Hi({bufferMap:u,influence:p,stride:a,width:d,depth:h,offset:se(0)})),r===!0&&Xe.addAssign(Hi({bufferMap:u,influence:p,stride:a,width:d,depth:h,offset:se(1)}))})})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((t,s)=>t+s,0)}}const Tp=B(bu).setParameterLength(1);class Ft extends V{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class Ru extends Ft{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class Au extends Yn{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s=A().toVar("directDiffuse"),r=A().toVar("directSpecular"),n=A().toVar("indirectDiffuse"),i=A().toVar("indirectSpecular"),u={directDiffuse:s,directSpecular:r,indirectDiffuse:n,indirectSpecular:i};return{radiance:A().toVar("radiance"),irradiance:A().toVar("irradiance"),iblIrradiance:A().toVar("iblIrradiance"),ambientOcclusion:b(1).toVar("ambientOcclusion"),reflectedLight:u,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const yp=B(Au);class Cu extends Ft{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let ss,rs;class ae extends V{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===ae.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=z.NONE;return(this.scope===ae.SIZE||this.scope===ae.VIEWPORT)&&(e=z.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===ae.VIEWPORT?t!==null?rs.copy(t.viewport):(e.getViewport(rs),rs.multiplyScalar(e.getPixelRatio())):t!==null?(ss.width=t.width,ss.height=t.height):e.getDrawingBufferSize(ss)}setup(){const e=this.scope;let t=null;return e===ae.SIZE?t=O(ss||(ss=new l.Vector2)):e===ae.VIEWPORT?t=O(rs||(rs=new l.Vector4)):t=w(Sr.div(Rn)),t}generate(e){if(this.scope===ae.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rn).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}ae.COORDINATE="coordinate";ae.VIEWPORT="viewport";ae.SIZE="size";ae.UV="uv";const qt=P(ae,ae.UV),Rn=P(ae,ae.SIZE),Sr=P(ae,ae.COORDINATE),bs=P(ae,ae.VIEWPORT);bs.zw;bs.xy;const ns=new l.Vector2;class li extends Mt{static get type(){return"ViewportTextureNode"}constructor(e=qt,t=null,s=null){s===null&&(s=new l.FramebufferTexture,s.minFilter=l.LinearMipmapLinearFilter),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=z.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(ns);const s=this.value;(s.image.width!==ns.width||s.image.height!==ns.height)&&(s.image.width=ns.width,s.image.height=ns.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const vu=B(li,null,null,{generateMipmaps:!0}).setParameterLength(0,3);let Lr=null;class Eu extends li{static get type(){return"ViewportDepthTextureNode"}constructor(e=qt,t=null){Lr===null&&(Lr=new l.DepthTexture),super(e,t,Lr)}}const xp=B(Eu).setParameterLength(0,2);class Ne extends V{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===Ne.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===Ne.DEPTH_BASE)s!==null&&(r=Fu().assign(s));else if(t===Ne.DEPTH)e.isPerspectiveCamera?r=_p(ue.z,bt,Rt):r=Rs(ue.z,bt,Rt);else if(t===Ne.LINEAR_DEPTH)if(s!==null)if(e.isPerspectiveCamera){const n=Bu(s,bt,Rt);r=Rs(n,bt,Rt)}else r=s;else r=Rs(ue.z,bt,Rt);return r}}Ne.DEPTH_BASE="depthBase";Ne.DEPTH="depth";Ne.LINEAR_DEPTH="linearDepth";const Rs=(o,e,t)=>o.add(e).div(e.sub(t)),_p=(o,e,t)=>e.add(o).mul(t).div(t.sub(e).mul(o)),Bu=(o,e,t)=>e.mul(t).div(t.sub(e).mul(o).sub(t)),Mu=(o,e,t)=>{e=e.max(1e-6).toVar();const s=Ze(o.negate().div(e)),r=Ze(t.div(e));return s.div(r)},Fu=B(Ne,Ne.DEPTH_BASE),wu=P(Ne,Ne.DEPTH),Sp=B(Ne,Ne.LINEAR_DEPTH).setParameterLength(0,1);xp();wu.assign=o=>Fu(o);class De extends V{static get type(){return"ClippingNode"}constructor(e=De.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===De.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===De.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return v(()=>{const s=b().toVar("distanceToPlane"),r=b().toVar("distanceToGradient"),n=b(1).toVar("clipOpacity"),i=t.length;if(this.hardwareClipping===!1&&i>0){const a=We(t);Ve(i,({i:c})=>{const d=a.element(c);s.assign(ue.dot(d.xyz).negate().add(d.w)),r.assign(s.fwidth().div(2)),n.mulAssign(lt(r.negate(),r,s))})}const u=e.length;if(u>0){const a=We(e),c=b(1).toVar("intersectionClipOpacity");Ve(u,({i:d})=>{const h=a.element(d);s.assign(ue.dot(h.xyz).negate().add(h.w)),r.assign(s.fwidth().div(2)),c.mulAssign(lt(r.negate(),r,s).oneMinus())}),n.mulAssign(c.oneMinus())}K.a.mulAssign(n),K.a.equal(0).discard()})()}setupDefault(e,t){return v(()=>{const s=t.length;if(this.hardwareClipping===!1&&s>0){const n=We(t);Ve(s,({i})=>{const u=n.element(i);ue.dot(u.xyz).greaterThan(u.w).discard()})}const r=e.length;if(r>0){const n=We(e),i=Vn(!0).toVar("clipped");Ve(r,({i:u})=>{const a=n.element(u);i.assign(ue.dot(a.xyz).greaterThan(a.w).and(i))}),i.discard()}})()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),v(()=>{const r=We(e),n=Tr(t.getClipDistance());Ve(s,({i})=>{const u=r.element(i),a=ue.dot(u.xyz).sub(u.w).negate();n.element(i).assign(a)})})()}}De.ALPHA_TO_COVERAGE="alphaToCoverage";De.DEFAULT="default";De.HARDWARE="hardware";const Np=()=>E(new De),bp=()=>E(new De(De.ALPHA_TO_COVERAGE)),Rp=()=>E(new De(De.HARDWARE)),Ap=.05,qi=v(([o])=>dt($(1e4,Oe($(17,o.x).add($(.1,o.y)))).mul(Ce(.1,we(Oe($(13,o.y).add(o.x))))))),Xi=v(([o])=>qi(w(qi(o.xy),o.z))),Cp=v(([o])=>{const e=ye(Je(Aa(o.xyz)),Je(Ca(o.xyz))),t=b(1).div(b(Ap).mul(e)).toVar("pixScale"),s=w(vs(vt(Ze(t))),vs(Kn(Ze(t)))),r=w(Xi(vt(s.x.mul(o.xyz))),Xi(vt(s.y.mul(o.xyz)))),n=dt(Ze(t)),i=Ce($(n.oneMinus(),r.x),$(n,r.y)),u=Kt(n,n.oneMinus()),a=A(i.mul(i).div($(2,u).mul(_e(1,u))),i.sub($(.5,u)).div(_e(1,u)),_e(1,_e(1,i).mul(_e(1,i)).div($(2,u).mul(_e(1,u))))),c=i.lessThan(u.oneMinus()).select(i.lessThan(u).select(a.x,a.y),a.z);return et(c,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class Pu extends ni{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e),s=e.hasGeometryAttribute(t);let r;return s===!0?r=super.generate(e):r=e.generateConst(this.nodeType,new l.Vector4(1,1,1,1)),r}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const vp=(o=0)=>E(new Pu(o)),Ep=v(([o])=>k(o.rgb.mul(o.a),o.a),{color:"vec4",return:"vec4"});class ce extends l.Material{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,Object.defineProperty(this,"shadowPositionNode",{get:()=>this.receivedShadowPositionNode,set:e=>{console.warn('THREE.NodeMaterial: ".shadowPositionNode" was renamed to ".receivedShadowPositionNode".'),this.receivedShadowPositionNode=e}})}customProgramCacheKey(){return this.type+Jo(this)}build(e){this.setup(e)}setupObserver(e){return new Zo(e)}setup(e){e.context.setupNormal=()=>Ss(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);const t=e.renderer,s=t.getRenderTarget();e.addStack();const r=Ss(this.setupVertex(e),"VERTEX"),n=this.vertexNode||r;e.stack.outputNode=n,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let i;const u=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(s!==null?s.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupVariants(e);const a=this.setupLighting(e);u!==null&&e.stack.add(u);const c=k(a,K.a).max(0);i=this.setupOutput(e,c),xs.assign(i);const d=this.outputNode!==null;if(d&&(i=this.outputNode),s!==null){const h=t.getMRT(),p=this.mrtNode;h!==null?(d&&xs.assign(i),i=h,p!==null&&(i=h.merge(p))):p!==null&&(i=p)}}else{let a=this.fragmentNode;a.isOutputStructNode!==!0&&(a=k(a)),i=this.setupOutput(e,a)}e.stack.outputNode=i,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const n=e.renderer.samples;this.alphaToCoverage&&n>1?r=bp():e.stack.add(Np())}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,e.clippingContext===null)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(Rp()),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(r===null){const n=t.getMRT();n&&n.has("depth")?r=n.get("depth"):t.logarithmicDepthBuffer===!0&&(s.isPerspectiveCamera?r=Mu(ue.z,bt,Rt):r=Rs(ue.z,bt,Rt))}r!==null&&wu.assign(r).toStack()}setupPositionView(){return yr.mul(Te).xyz}setupModelViewProjection(){return oi.mul(ue)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.vertex=e.removeStack(),Tu}setupPosition(e){const{object:t,geometry:s}=e;if((s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Tp(t).toStack(),t.isSkinnedMesh===!0&&fp(t).toStack(),this.displacementMap){const r=ot("displacementMap","texture"),n=ot("displacementScale","float"),i=ot("displacementBias","float");Te.addAssign(Xe.normalize().mul(r.x.mul(n).add(i)))}return t.isBatchedMesh&&pp(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&hp(t).toStack(),this.positionNode!==null&&Te.assign(Ss(this.positionNode,"POSITION","vec3")),Te}setupDiffuseColor({object:e,geometry:t}){this.maskNode!==null&&Vn(this.maskNode).not().discard();let s=this.colorNode?k(this.colorNode):Dh;this.vertexColors===!0&&t.hasAttribute("color")&&(s=s.mul(vp())),e.instanceColor&&(s=ar("vec3","vInstanceColor").mul(s)),e.isBatchedMesh&&e._colorsTexture&&(s=ar("vec3","vBatchColor").mul(s)),K.assign(s);const r=this.opacityNode?b(this.opacityNode):gu;K.a.assign(K.a.mul(r));let n=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(n=this.alphaTestNode!==null?b(this.alphaTestNode):Ph,K.a.lessThanEqual(n).discard()),this.alphaHash===!0&&K.a.lessThan(Cp(Te)).discard(),this.transparent===!1&&this.blending===l.NormalBlending&&this.alphaToCoverage===!1?K.a.assign(1):n===null&&K.a.lessThanEqual(0).discard()}setupVariants(){}setupOutgoingLight(){return this.lights===!0?A(0):K.rgb}setupNormal(){return this.normalNode?A(this.normalNode):kh}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?ot("envMap","cubeTexture"):ot("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Cu(mu)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),this.aoNode!==null||e.material.aoMap){const i=this.aoNode!==null?this.aoNode:lp;t.push(new Ru(i))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,u=this.lights===!0||this.lightsNode!==null?this.setupLights(e):null;let a=this.setupOutgoingLight(e);if(u&&u.getScope().hasLights){const c=this.setupLightingModel(e)||null;a=yp(u,c,s,r)}else s!==null&&(a=A(r!==null?ne(a,s,r):s));return(n&&n.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(Mi.assign(A(n||Uh)),a=a.add(Mi)),a}setupFog(e,t){const s=e.fogNode;return s&&(xs.assign(t),t=k(s)),t}setupPremultipliedAlpha(e,t){return Ep(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(const s in e){const r=e[s];this[s]===void 0&&(this[s]=r,r&&r.clone&&(this[s]=r.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const s in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,s)===void 0&&t[s].get!==void 0&&Object.defineProperty(this.constructor.prototype,s,t[s])}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});const s=l.Material.prototype.toJSON.call(this,e),r=nr(this);s.inputNodes={};for(const{property:i,childNode:u}of r)s.inputNodes[i]=u.toJSON(e).uuid;function n(i){const u=[];for(const a in i){const c=i[a];delete c.metadata,u.push(c)}return u}if(t){const i=n(e.textures),u=n(e.images),a=n(e.nodes);i.length>0&&(s.textures=i),u.length>0&&(s.images=u),a.length>0&&(s.nodes=a)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.maskNode=e.maskNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.receivedShadowPositionNode=e.receivedShadowPositionNode,this.castShadowPositionNode=e.castShadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const Bp=new l.LineBasicMaterial;class Du extends ce{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(Bp),this.setValues(e)}}const Mp=new l.LineDashedMaterial;class Lu extends ce{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(Mp),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?b(this.offsetNode):op,t=this.dashScaleNode?b(this.dashScaleNode):rp,s=this.dashSizeNode?b(this.dashSizeNode):np,r=this.gapSizeNode?b(this.gapSizeNode):ip;Mr.assign(s),Fi.assign(r);const n=ht(ct("lineDistance").mul(t));(e?n.add(e):n).mod(Mr.add(Fi)).greaterThan(Mr).discard()}}const Fp=o=>E(o).mul(.5).add(.5),wp=new l.MeshNormalMaterial;class Uu extends ce{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(wp),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?b(this.opacityNode):gu;K.assign(ti(k(Fp(Z),e),l.SRGBColorSpace))}}const Gu=v(([o=Ya])=>{const e=o.z.atan(o.x).mul(1/(Math.PI*2)).add(.5),t=o.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return w(e,t)});class Iu extends l.WebGLCubeRenderTarget{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new l.BoxGeometry(5,5,5),i=Gu(Ya),u=new ce;u.colorNode=X(t,i,0),u.side=l.BackSide,u.blending=l.NoBlending;const a=new l.Mesh(n,u),c=new l.Scene;c.add(a),t.minFilter===l.LinearMipmapLinearFilter&&(t.minFilter=l.LinearFilter);const d=new l.CubeCamera(1,10,this),h=e.getMRT();return e.setMRT(null),d.update(e,c),e.setMRT(h),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const As=new WeakMap;class Pp extends fe{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Fs(null);const t=new l.CubeTexture;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=z.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const n=r.isTextureNode?r.value:s[r.property];if(n&&n.isTexture){const i=n.mapping;if(i===l.EquirectangularReflectionMapping||i===l.EquirectangularRefractionMapping){if(As.has(n)){const u=As.get(n);Ki(u,n.mapping),this._cubeTexture=u}else{const u=n.image;if(Dp(u)){const a=new Iu(u.height);a.fromEquirectangularTexture(t,n),Ki(a.texture,n.mapping),this._cubeTexture=a.texture,As.set(n,a.texture),n.addEventListener("dispose",Ou)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Dp(o){return o==null?!1:o.height>0}function Ou(o){const e=o.target;e.removeEventListener("dispose",Ou);const t=As.get(e);t!==void 0&&(As.delete(e),t.dispose())}function Ki(o,e){e===l.EquirectangularReflectionMapping?o.mapping=l.CubeReflectionMapping:e===l.EquirectangularRefractionMapping&&(o.mapping=l.CubeRefractionMapping)}const Vu=B(Pp).setParameterLength(1);class Nr extends Ft{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Vu(this.envNode)}}class Lp extends Ft{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=b(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ls{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class ku extends Ls{constructor(){super()}indirect({context:e}){const t=e.ambientOcclusion,s=e.reflectedLight,r=e.irradianceLightMap;s.indirectDiffuse.assign(k(0)),r?s.indirectDiffuse.addAssign(r):s.indirectDiffuse.addAssign(k(1,1,1,0)),s.indirectDiffuse.mulAssign(t),s.indirectDiffuse.mulAssign(K.rgb)}finish(e){const{material:t,context:s}=e,r=s.outgoingLight,n=e.context.environment;if(n)switch(t.combine){case l.MultiplyOperation:r.rgb.assign(ne(r.rgb,r.rgb.mul(n.rgb),tr.mul(Pr)));break;case l.MixOperation:r.rgb.assign(ne(r.rgb,n.rgb,tr.mul(Pr)));break;case l.AddOperation:r.rgb.addAssign(n.rgb.mul(tr.mul(Pr)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",t.combine);break}}}const Up=new l.MeshBasicMaterial;class zu extends ce{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Up),this.setValues(e)}setupNormal(){return Ds(Ms)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Nr(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Lp(mu)),t}setupOutgoingLight(){return K.rgb}setupLightingModel(){return new ku}}const ws=v(({f0:o,f90:e,dotVH:t})=>{const s=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return o.mul(s.oneMinus()).add(e.mul(s))}),Yt=v(o=>o.diffuseColor.mul(1/Math.PI)),Gp=()=>b(.25),Ip=v(({dotNH:o})=>xn.mul(b(.5)).add(1).mul(b(1/Math.PI)).mul(o.pow(xn))),Op=v(({lightDirection:o})=>{const e=o.add(oe).normalize(),t=Z.dot(e).clamp(),s=oe.dot(e).clamp(),r=ws({f0:Be,f90:1,dotVH:s}),n=Gp(),i=Ip({dotNH:t});return r.mul(n).mul(i)});class ci extends ku{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const n=Z.dot(e).clamp().mul(t);s.directDiffuse.addAssign(n.mul(Yt({diffuseColor:K.rgb}))),this.specular===!0&&s.directSpecular.addAssign(n.mul(Op({lightDirection:e})).mul(tr))}indirect(e){const{ambientOcclusion:t,irradiance:s,reflectedLight:r}=e.context;r.indirectDiffuse.addAssign(s.mul(Yt({diffuseColor:K}))),r.indirectDiffuse.mulAssign(t)}}const Vp=new l.MeshLambertMaterial;class $u extends ce{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Vp),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Nr(t):null}setupLightingModel(){return new ci(!1)}}const kp=new l.MeshPhongMaterial;class Wu extends ce{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(kp),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Nr(t):null}setupLightingModel(){return new ci}setupVariants(){const e=(this.shininessNode?b(this.shininessNode):Lh).max(1e-4);xn.assign(e);const t=this.specularNode||Gh;Be.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const zp=v(o=>{if(o.geometry.hasAttribute("normal")===!1)return b(0);const e=Ms.dFdx().abs().max(Ms.dFdy().abs());return e.x.max(e.y).max(e.z)}),Hu=v(o=>{const{roughness:e}=o,t=zp();let s=e.max(.0525);return s=s.add(t),s=s.min(1),s}),$p=v(({alpha:o,dotNL:e,dotNV:t})=>{const s=o.pow2(),r=e.mul(s.add(s.oneMinus().mul(t.pow2())).sqrt()),n=t.mul(s.add(s.oneMinus().mul(e.pow2())).sqrt());return qe(.5,r.add(n).max(nd))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),Wp=v(({alphaT:o,alphaB:e,dotTV:t,dotBV:s,dotTL:r,dotBL:n,dotNV:i,dotNL:u})=>{const a=u.mul(A(o.mul(t),e.mul(s),i).length()),c=i.mul(A(o.mul(r),e.mul(n),u).length());return qe(.5,a.add(c)).saturate()}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hp=v(({alpha:o,dotNH:e})=>{const t=o.pow2(),s=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(s.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),qp=b(1/Math.PI),Xp=v(({alphaT:o,alphaB:e,dotNH:t,dotTH:s,dotBH:r})=>{const n=o.mul(e),i=A(e.mul(s),o.mul(r),n.mul(t)),u=i.dot(i),a=n.div(u);return qp.mul(n.mul(a.pow2()))}).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),Qi=v(({lightDirection:o,f0:e,f90:t,roughness:s,f:r,normalView:n=Z,USE_IRIDESCENCE:i,USE_ANISOTROPY:u})=>{const a=s.pow2(),c=o.add(oe).normalize(),d=n.dot(o).clamp(),h=n.dot(oe).clamp(),p=n.dot(c).clamp(),f=oe.dot(c).clamp();let g=ws({f0:e,f90:t,dotVH:f}),m,y;if(Bi(i)&&(g=$n.mix(g,r)),Bi(u)){const _=Zs.dot(o),C=Zs.dot(oe),R=Zs.dot(c),U=Wt.dot(o),M=Wt.dot(oe),D=Wt.dot(c);m=Wp({alphaT:yn,alphaB:a,dotTV:C,dotBV:M,dotTL:_,dotBL:U,dotNV:h,dotNL:d}),y=Xp({alphaT:yn,alphaB:a,dotNH:p,dotTH:R,dotBH:D})}else m=$p({alpha:a,dotNL:d,dotNV:h}),y=Hp({alpha:a,dotNH:p});return g.mul(m).mul(y)}),qu=v(({roughness:o,dotNV:e})=>{const t=k(-1,-.0275,-.572,.022),s=k(1,.0425,1.04,-.04),r=o.mul(t).add(s),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return w(-1.04,1.04).mul(n).add(r.zw)}).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xu=v(o=>{const{dotNV:e,specularColor:t,specularF90:s,roughness:r}=o,n=qu({dotNV:e,roughness:r});return t.mul(n.x).add(s.mul(n.y))}),Kp=v(({f:o,f90:e,dotVH:t})=>{const s=t.oneMinus().saturate(),r=s.mul(s),n=s.mul(r,r).clamp(0,.9999);return o.sub(A(e).mul(n)).div(n.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qp=v(({roughness:o,dotNH:e})=>{const t=o.pow2(),s=b(1).div(t),n=e.pow2().oneMinus().max(.0078125);return b(2).add(s).mul(n.pow(s.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Yp=v(({dotNV:o,dotNL:e})=>b(1).div(b(4).mul(e.add(o).sub(e.mul(o))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),jp=v(({lightDirection:o})=>{const e=o.add(oe).normalize(),t=Z.dot(o).clamp(),s=Z.dot(oe).clamp(),r=Z.dot(e).clamp(),n=Qp({roughness:zn,dotNH:r}),i=Yp({dotNV:s,dotNL:t});return It.mul(n).mul(i)}),Zp=v(({N:o,V:e,roughness:t})=>{const n=.0078125,i=o.dot(e).saturate(),u=w(t,i.oneMinus().sqrt());return u.assign(u.mul(.984375).add(n)),u}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),Jp=v(({f:o})=>{const e=o.length();return ye(e.mul(e).add(o.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),Gs=v(({v1:o,v2:e})=>{const t=o.dot(e),s=t.abs().toVar(),r=s.mul(.0145206).add(.4965155).mul(s).add(.8543985).toVar(),n=s.add(4.1616724).mul(s).add(3.417594).toVar(),i=r.div(n),u=t.greaterThan(0).select(i,ye(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(i));return o.cross(e).mul(u)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),Yi=v(({N:o,V:e,P:t,mInv:s,p0:r,p1:n,p2:i,p3:u})=>{const a=n.sub(r).toVar(),c=u.sub(r).toVar(),d=a.cross(c),h=A().toVar();return le(d.dot(t.sub(r)).greaterThanEqual(0),()=>{const p=e.sub(o.mul(e.dot(o))).normalize(),f=o.cross(p).negate(),g=s.mul(Re(p,f,o).transpose()).toVar(),m=g.mul(r.sub(t)).normalize().toVar(),y=g.mul(n.sub(t)).normalize().toVar(),_=g.mul(i.sub(t)).normalize().toVar(),C=g.mul(u.sub(t)).normalize().toVar(),R=A(0).toVar();R.addAssign(Gs({v1:m,v2:y})),R.addAssign(Gs({v1:y,v2:_})),R.addAssign(Gs({v1:_,v2:C})),R.addAssign(Gs({v1:C,v2:m})),h.assign(A(Jp({f:R})))}),h}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),br=1/6,Ku=o=>$(br,$(o,$(o,o.negate().add(3)).sub(3)).add(1)),An=o=>$(br,$(o,$(o,$(3,o).sub(6))).add(4)),Qu=o=>$(br,$(o,$(o,$(-3,o).add(3)).add(3)).add(1)),Cn=o=>$(br,mr(o,3)),ji=o=>Ku(o).add(An(o)),Zi=o=>Qu(o).add(Cn(o)),Ji=o=>Ce(-1,An(o).div(Ku(o).add(An(o)))),eo=o=>Ce(1,Cn(o).div(Qu(o).add(Cn(o)))),to=(o,e,t)=>{const s=o.uvNode,r=$(s,e.zw).add(.5),n=vt(r),i=dt(r),u=ji(i.x),a=Zi(i.x),c=Ji(i.x),d=eo(i.x),h=Ji(i.y),p=eo(i.y),f=w(n.x.add(c),n.y.add(h)).sub(.5).mul(e.xy),g=w(n.x.add(d),n.y.add(h)).sub(.5).mul(e.xy),m=w(n.x.add(c),n.y.add(p)).sub(.5).mul(e.xy),y=w(n.x.add(d),n.y.add(p)).sub(.5).mul(e.xy),_=ji(i.y).mul(Ce(u.mul(o.sample(f).level(t)),a.mul(o.sample(g).level(t)))),C=Zi(i.y).mul(Ce(u.mul(o.sample(m).level(t)),a.mul(o.sample(y).level(t))));return _.add(C)},ef=v(([o,e])=>{const t=w(o.size(se(e))),s=w(o.size(se(e.add(1)))),r=qe(1,t),n=qe(1,s),i=to(o,k(r,t),vt(e)),u=to(o,k(n,s),Kn(e));return dt(e).mix(i,u)}),so=v(([o,e,t,s,r])=>{const n=A(wa(e.negate(),Es(o),qe(1,s))),i=A(Je(r[0].xyz),Je(r[1].xyz),Je(r[2].xyz));return Es(n).mul(t.mul(i))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),tf=v(([o,e])=>o.mul(et(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),sf=vu(),rf=vu(),ro=v(([o,e,t],{material:s})=>{const n=(s.side===l.BackSide?sf:rf).sample(o),i=Ze(Rn.x).mul(tf(e,t));return ef(n,i)}),no=v(([o,e,t])=>(le(t.notEqual(0),()=>{const s=Na(e).negate().div(t);return Sa(s.negate().mul(o))}),A(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),nf=v(([o,e,t,s,r,n,i,u,a,c,d,h,p,f,g])=>{let m,y;if(g){m=k().toVar(),y=A().toVar();const M=d.sub(1).mul(g.mul(.025)),D=A(d.sub(M),d,d.add(M));Ve({start:0,end:3},({i:F})=>{const L=D.element(F),G=so(o,e,h,L,u),H=i.add(G),q=c.mul(a.mul(k(H,1))),ee=w(q.xy.div(q.w)).toVar();ee.addAssign(1),ee.divAssign(2),ee.assign(w(ee.x,ee.y.oneMinus()));const te=ro(ee,t,L);m.element(F).assign(te.element(F)),m.a.addAssign(te.a),y.element(F).assign(s.element(F).mul(no(Je(G),p,f).element(F)))}),m.a.divAssign(3)}else{const M=so(o,e,h,d,u),D=i.add(M),F=c.mul(a.mul(k(D,1))),L=w(F.xy.div(F.w)).toVar();L.addAssign(1),L.divAssign(2),L.assign(w(L.x,L.y.oneMinus())),m=ro(L,t,d),y=s.mul(no(Je(M),p,f))}const _=y.rgb.mul(m.rgb),C=o.dot(e).clamp(),R=A(Xu({dotNV:C,specularColor:r,specularF90:n,roughness:t})),U=y.r.add(y.g,y.b).div(3);return k(R.oneMinus().mul(_),m.a.oneMinus().mul(U).oneMinus())}),of=Re(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),af=o=>{const e=o.sqrt();return A(1).add(e).div(A(1).sub(e))},io=(o,e)=>o.sub(e).div(o.add(e)).pow2(),uf=(o,e)=>{const t=o.mul(2*Math.PI*1e-9),s=A(54856e-17,44201e-17,52481e-17),r=A(1681e3,1795300,2208400),n=A(43278e5,93046e5,66121e5),i=b(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp());let u=s.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(t).add(e).cos()).mul(t.pow2().negate().mul(n).exp());return u=A(u.x.add(i),u.y,u.z).div(10685e-11),of.mul(u)},lf=v(({outsideIOR:o,eta2:e,cosTheta1:t,thinFilmThickness:s,baseF0:r})=>{const n=ne(o,e,lt(0,.03,s)),u=o.div(n).pow2().mul(t.pow2().oneMinus()).oneMinus();le(u.lessThan(0),()=>A(1));const a=u.sqrt(),c=io(n,o),d=ws({f0:c,f90:1,dotVH:t}),h=d.oneMinus(),p=n.lessThan(o).select(Math.PI,0),f=b(Math.PI).sub(p),g=af(r.clamp(0,.9999)),m=io(g,n.toVec3()),y=ws({f0:m,f90:1,dotVH:a}),_=A(g.x.lessThan(n).select(Math.PI,0),g.y.lessThan(n).select(Math.PI,0),g.z.lessThan(n).select(Math.PI,0)),C=n.mul(s,a,2),R=A(f).add(_),U=d.mul(y).clamp(1e-5,.9999),M=U.sqrt(),D=h.pow2().mul(y).div(A(1).sub(U)),L=d.add(D).toVar(),G=D.sub(h).toVar();return Ve({start:1,end:2,condition:"<=",name:"m"},({m:H})=>{G.mulAssign(M);const q=uf(b(H).mul(C),b(H).mul(R)).mul(2);L.addAssign(G.mul(q))}),L.max(A(0))}).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),cf=v(({normal:o,viewDir:e,roughness:t})=>{const s=o.dot(e).saturate(),r=t.pow2(),n=Se(t.lessThan(.25),b(-339.2).mul(r).add(b(161.4).mul(t)).sub(25.9),b(-8.48).mul(r).add(b(14.3).mul(t)).sub(9.95)),i=Se(t.lessThan(.25),b(44).mul(r).sub(b(23.7).mul(t)).add(3.26),b(1.97).mul(r).sub(b(3.27).mul(t)).add(.72));return Se(t.lessThan(.25),0,b(.1).mul(t).sub(.025)).add(n.mul(s).add(i).exp()).mul(1/Math.PI).saturate()}),Ur=A(.04),Gr=b(1);class di extends Ls{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=A().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=A().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=A().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=A().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=A().toVar("sheenSpecularIndirect")),this.iridescence===!0){const t=Z.dot(oe).clamp();this.iridescenceFresnel=lf({outsideIOR:b(1),eta2:da,cosTheta1:t,thinFilmThickness:ha,baseF0:Be}),this.iridescenceF0=Kp({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(this.transmission===!0){const t=Bs,s=ah.sub(Bs).normalize(),r=es,n=e.context;n.backdrop=nf(r,s,je,K,Be,cr,t,Et,tt,oi,Js,pa,ga,fa,this.dispersion?ma:null),n.backdropAlpha=_n,K.a.mulAssign(ne(1,n.backdrop.a,_n))}super.start(e)}computeMultiscattering(e,t,s){const r=Z.dot(oe).clamp(),n=qu({roughness:je,dotNV:r}),u=(this.iridescenceF0?$n.mix(Be,this.iridescenceF0):Be).mul(n.x).add(s.mul(n.y)),c=n.x.add(n.y).oneMinus(),d=Be.add(Be.oneMinus().mul(.047619)),h=u.mul(d).div(c.mul(d).oneMinus());e.addAssign(u),t.addAssign(h.mul(c))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const n=Z.dot(e).clamp().mul(t);if(this.sheen===!0&&this.sheenSpecularDirect.addAssign(n.mul(jp({lightDirection:e}))),this.clearcoat===!0){const u=Ot.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(u.mul(Qi({lightDirection:e,f0:Ur,f90:Gr,roughness:lr,normalView:Ot})))}s.directDiffuse.addAssign(n.mul(Yt({diffuseColor:K.rgb}))),s.directSpecular.addAssign(n.mul(Qi({lightDirection:e,f0:Be,f90:1,roughness:je,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:u}){const a=t.add(s).sub(r),c=t.sub(s).sub(r),d=t.sub(s).add(r),h=t.add(s).add(r),p=Z,f=oe,g=ue.toVar(),m=Zp({N:p,V:f,roughness:je}),y=i.sample(m).toVar(),_=u.sample(m).toVar(),C=Re(A(y.x,0,y.y),A(0,1,0),A(y.z,0,y.w)).toVar(),R=Be.mul(_.x).add(Be.oneMinus().mul(_.y)).toVar();n.directSpecular.addAssign(e.mul(R).mul(Yi({N:p,V:f,P:g,mInv:C,p0:a,p1:c,p2:d,p3:h}))),n.directDiffuse.addAssign(e.mul(K).mul(Yi({N:p,V:f,P:g,mInv:Re(1,0,0,0,1,0,0,0,1),p0:a,p1:c,p2:d,p3:h})))}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){const{irradiance:t,reflectedLight:s}=e.context;s.indirectDiffuse.addAssign(t.mul(Yt({diffuseColor:K})))}indirectSpecular(e){const{radiance:t,iblIrradiance:s,reflectedLight:r}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(s.mul(It,cf({normal:Z,viewDir:oe,roughness:zn}))),this.clearcoat===!0){const d=Ot.dot(oe).clamp(),h=Xu({dotNV:d,specularColor:Ur,specularF90:Gr,roughness:lr});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(h))}const n=A().toVar("singleScattering"),i=A().toVar("multiScattering"),u=s.mul(1/Math.PI);this.computeMultiscattering(n,i,cr);const a=n.add(i),c=K.mul(a.r.max(a.g).max(a.b).oneMinus());r.indirectSpecular.addAssign(t.mul(n)),r.indirectSpecular.addAssign(i.mul(u)),r.indirectDiffuse.addAssign(c.mul(u))}ambientOcclusion(e){const{ambientOcclusion:t,reflectedLight:s}=e.context,n=Z.dot(oe).clamp().add(t),i=je.mul(-16).oneMinus().negate().exp2(),u=t.sub(n.pow(i).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),s.indirectDiffuse.mulAssign(t),s.indirectSpecular.mulAssign(u)}finish({context:e}){const{outgoingLight:t}=e;if(this.clearcoat===!0){const s=Ot.dot(oe).clamp(),r=ws({dotVH:s,f0:Ur,f90:Gr}),n=t.mul(Tn.mul(r).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Tn));t.assign(n)}if(this.sheen===!0){const s=It.r.max(It.g).max(It.b).mul(.157).oneMinus(),r=t.mul(s).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(r)}}}const oo=b(1),vn=b(-2),Is=b(.8),Ir=b(-1),Os=b(.4),Or=b(2),Vs=b(.305),Vr=b(3),ao=b(.21),df=b(4),uo=b(4),hf=b(16),pf=v(([o])=>{const e=A(we(o)).toVar(),t=b(-1).toVar();return le(e.x.greaterThan(e.z),()=>{le(e.x.greaterThan(e.y),()=>{t.assign(Se(o.x.greaterThan(0),0,3))}).Else(()=>{t.assign(Se(o.y.greaterThan(0),1,4))})}).Else(()=>{le(e.z.greaterThan(e.y),()=>{t.assign(Se(o.z.greaterThan(0),2,5))}).Else(()=>{t.assign(Se(o.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),ff=v(([o,e])=>{const t=w().toVar();return le(e.equal(0),()=>{t.assign(w(o.z,o.y).div(we(o.x)))}).ElseIf(e.equal(1),()=>{t.assign(w(o.x.negate(),o.z.negate()).div(we(o.y)))}).ElseIf(e.equal(2),()=>{t.assign(w(o.x.negate(),o.y).div(we(o.z)))}).ElseIf(e.equal(3),()=>{t.assign(w(o.z.negate(),o.y).div(we(o.x)))}).ElseIf(e.equal(4),()=>{t.assign(w(o.x.negate(),o.z).div(we(o.y)))}).Else(()=>{t.assign(w(o.x,o.y).div(we(o.z)))}),$(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),gf=v(([o])=>{const e=b(0).toVar();return le(o.greaterThanEqual(Is),()=>{e.assign(oo.sub(o).mul(Ir.sub(vn)).div(oo.sub(Is)).add(vn))}).ElseIf(o.greaterThanEqual(Os),()=>{e.assign(Is.sub(o).mul(Or.sub(Ir)).div(Is.sub(Os)).add(Ir))}).ElseIf(o.greaterThanEqual(Vs),()=>{e.assign(Os.sub(o).mul(Vr.sub(Or)).div(Os.sub(Vs)).add(Or))}).ElseIf(o.greaterThanEqual(ao),()=>{e.assign(Vs.sub(o).mul(df.sub(Vr)).div(Vs.sub(ao)).add(Vr))}).Else(()=>{e.assign(b(-2).mul(Ze($(1.16,o))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),mf=v(([o,e])=>{const t=o.toVar();t.assign($(2,t).sub(1));const s=A(t,1).toVar();return le(e.equal(0),()=>{s.assign(s.zyx)}).ElseIf(e.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(e.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(e.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(e.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(e.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Tf=v(([o,e,t,s,r,n])=>{const i=b(t),u=A(e),a=et(gf(i),vn,n),c=dt(a),d=vt(a),h=A(En(o,u,d,s,r,n)).toVar();return le(c.notEqual(0),()=>{const p=A(En(o,u,d.add(1),s,r,n)).toVar();h.assign(ne(h,p,c))}),h}),En=v(([o,e,t,s,r,n])=>{const i=b(t).toVar(),u=A(e),a=b(pf(u)).toVar(),c=b(ye(uo.sub(i),0)).toVar();i.assign(ye(i,uo));const d=b(vs(i)).toVar(),h=w(ff(u,a).mul(d.sub(2)).add(1)).toVar();return le(a.greaterThan(2),()=>{h.y.addAssign(d),a.subAssign(3)}),h.x.addAssign(a.mul(d)),h.x.addAssign(c.mul($(3,hf))),h.y.addAssign($(4,vs(n).sub(d))),h.x.mulAssign(s),h.y.mulAssign(r),o.sample(h).grad(w(),w())}),kr=v(({envMap:o,mipInt:e,outputDirection:t,theta:s,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:i,CUBEUV_MAX_MIP:u})=>{const a=it(s),c=t.mul(a).add(r.cross(t).mul(Oe(s))).add(r.mul(r.dot(t).mul(a.oneMinus())));return En(o,c,e,n,i,u)}),yf=v(({n:o,latitudinal:e,poleAxis:t,outputDirection:s,weights:r,samples:n,dTheta:i,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h})=>{const p=A(Se(e,t,Ea(t,s))).toVar();le(p.equal(A(0)),()=>{p.assign(A(s.z,0,s.x.negate()))}),p.assign(Es(p));const f=A().toVar();return f.addAssign(r.element(0).mul(kr({theta:0,axis:p,outputDirection:s,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h}))),Ve({start:se(1),end:o},({i:g})=>{le(g.greaterThanEqual(n),()=>{gp()});const m=b(i.mul(b(g))).toVar();f.addAssign(r.element(g).mul(kr({theta:m.mul(-1),axis:p,outputDirection:s,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h}))),f.addAssign(r.element(g).mul(kr({theta:m,axis:p,outputDirection:s,mipInt:u,envMap:a,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h})))}),k(f,1)}),Vt=4,lo=[.125,.215,.35,.446,.526,.582],At=20,zr=new l.OrthographicCamera(-1,1,1,-1,0,1),xf=new l.PerspectiveCamera(90,1),co=new l.Color;let $r=null,Wr=0,Hr=0;const Nt=(1+Math.sqrt(5))/2,wt=1/Nt,ho=[new l.Vector3(-Nt,wt,0),new l.Vector3(Nt,wt,0),new l.Vector3(-wt,0,Nt),new l.Vector3(wt,0,Nt),new l.Vector3(0,Nt,-wt),new l.Vector3(0,Nt,wt),new l.Vector3(-1,1,-1),new l.Vector3(1,1,-1),new l.Vector3(-1,1,1),new l.Vector3(1,1,1)],_f=new l.Vector3,Yu=new WeakMap,Sf=[3,1,5,0,4,2],qr=mf(Ps(),ct("faceIndex")).normalize(),hi=A(qr.x,qr.y,qr.z);class ju{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,s=.1,r=100,n={}){const{size:i=256,position:u=_f,renderTarget:a=null}=n;if(this._setSize(i),this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.");const d=a||this._allocateTarget();return n.renderTarget=d,this.fromSceneAsync(e,t,s,r,n),d}$r=this._renderer.getRenderTarget(),Wr=this._renderer.getActiveCubeFace(),Hr=this._renderer.getActiveMipmapLevel();const c=a||this._allocateTarget();return c.depthBuffer=!0,this._init(c),this._sceneToCubeUV(e,s,r,c,u),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}async fromSceneAsync(e,t=0,s=.1,r=100,n={}){return this._hasInitialized===!1&&await this._renderer.init(),this.fromScene(e,t,s,r,n)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead."),this._setSizeFromTexture(e);const s=t||this._allocateTarget();return this.fromEquirectangularAsync(e,s),s}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return this._hasInitialized===!1&&await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const s=t||this._allocateTarget();return this.fromCubemapAsync(e,t),s}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return this._hasInitialized===!1&&await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=fo(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=go(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===l.CubeReflectionMapping||e.mapping===l.CubeRefractionMapping?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget($r,Wr,Hr),e.scissorTest=!1,ks(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),$r=this._renderer.getRenderTarget(),Wr=this._renderer.getActiveCubeFace(),Hr=this._renderer.getActiveMipmapLevel();const s=t||this._allocateTarget();return this._init(s),this._textureToCubeUV(e,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTarget(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize;return po(e,t)}_init(e){if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=po(e.width,e.height);const{_lodMax:t}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=Nf(t)),this._blurMaterial=bf(t,e.width,e.height)}}async _compileMaterial(e){const t=new l.Mesh(this._lodPlanes[0],e);await this._renderer.compile(t,zr)}_sceneToCubeUV(e,t,s,r,n){const i=xf;i.near=t,i.far=s;const u=[1,1,1,1,-1,1],a=[1,-1,1,-1,1,-1],c=this._renderer,d=c.autoClear;c.getClearColor(co),c.autoClear=!1;let h=this._backgroundBox;if(h===null){const g=new l.MeshBasicMaterial({name:"PMREM.Background",side:l.BackSide,depthWrite:!1,depthTest:!1});h=new l.Mesh(new l.BoxGeometry,g)}let p=!1;const f=e.background;f?f.isColor&&(h.material.color.copy(f),e.background=null,p=!0):(h.material.color.copy(co),p=!0),c.setRenderTarget(r),c.clear(),p&&c.render(h,i);for(let g=0;g<6;g++){const m=g%3;m===0?(i.up.set(0,u[g],0),i.position.set(n.x,n.y,n.z),i.lookAt(n.x+a[g],n.y,n.z)):m===1?(i.up.set(0,0,u[g]),i.position.set(n.x,n.y,n.z),i.lookAt(n.x,n.y+a[g],n.z)):(i.up.set(0,u[g],0),i.position.set(n.x,n.y,n.z),i.lookAt(n.x,n.y,n.z+a[g]));const y=this._cubeSize;ks(r,m*y,g>2?y:0,y,y),c.render(e,i)}c.autoClear=d,e.background=f}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===l.CubeReflectionMapping||e.mapping===l.CubeRefractionMapping;r?this._cubemapMaterial===null&&(this._cubemapMaterial=fo(e)):this._equirectMaterial===null&&(this._equirectMaterial=go(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const u=this._cubeSize;ks(t,0,0,3*u,2*u),s.setRenderTarget(t),s.render(i,zr)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let n=1;n<r;n++){const i=Math.sqrt(this._sigmas[n]*this._sigmas[n]-this._sigmas[n-1]*this._sigmas[n-1]),u=ho[(r-n-1)%ho.length];this._blur(e,n-1,n,i,u)}t.autoClear=s}_blur(e,t,s,r,n){const i=this._pingPongRenderTarget;this._halfBlur(e,i,t,s,r,"latitudinal",n),this._halfBlur(i,e,s,s,r,"longitudinal",n)}_halfBlur(e,t,s,r,n,i,u){const a=this._renderer,c=this._blurMaterial;i!=="latitudinal"&&i!=="longitudinal"&&console.error("blur direction must be either latitudinal or longitudinal!");const d=3,h=this._lodMeshes[r];h.material=c;const p=Yu.get(c),f=this._sizeLods[s]-1,g=isFinite(n)?Math.PI/(2*f):2*Math.PI/(2*At-1),m=n/g,y=isFinite(n)?1+Math.floor(d*m):At;y>At&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${y} samples when the maximum is set to ${At}`);const _=[];let C=0;for(let F=0;F<At;++F){const L=F/m,G=Math.exp(-L*L/2);_.push(G),F===0?C+=G:F<y&&(C+=2*G)}for(let F=0;F<_.length;F++)_[F]=_[F]/C;e.texture.frame=(e.texture.frame||0)+1,p.envMap.value=e.texture,p.samples.value=y,p.weights.array=_,p.latitudinal.value=i==="latitudinal"?1:0,u&&(p.poleAxis.value=u);const{_lodMax:R}=this;p.dTheta.value=g,p.mipInt.value=R-s;const U=this._sizeLods[r],M=3*U*(r>R-Vt?r-R+Vt:0),D=4*(this._cubeSize-U);ks(t,M,D,3*U,2*U),a.setRenderTarget(t),a.render(h,zr)}}function Nf(o){const e=[],t=[],s=[],r=[];let n=o;const i=o-Vt+1+lo.length;for(let u=0;u<i;u++){const a=Math.pow(2,n);t.push(a);let c=1/a;u>o-Vt?c=lo[u-o+Vt-1]:u===0&&(c=0),s.push(c);const d=1/(a-2),h=-d,p=1+d,f=[h,h,p,h,p,p,h,h,p,p,h,p],g=6,m=6,y=3,_=2,C=1,R=new Float32Array(y*m*g),U=new Float32Array(_*m*g),M=new Float32Array(C*m*g);for(let F=0;F<g;F++){const L=F%3*2/3-1,G=F>2?0:-1,H=[L,G,0,L+2/3,G,0,L+2/3,G+1,0,L,G,0,L+2/3,G+1,0,L,G+1,0],q=Sf[F];R.set(H,y*m*q),U.set(f,_*m*q);const ee=[q,q,q,q,q,q];M.set(ee,C*m*q)}const D=new l.BufferGeometry;D.setAttribute("position",new l.BufferAttribute(R,y)),D.setAttribute("uv",new l.BufferAttribute(U,_)),D.setAttribute("faceIndex",new l.BufferAttribute(M,C)),e.push(D),r.push(new l.Mesh(D,null)),n>Vt&&n--}return{lodPlanes:e,sizeLods:t,sigmas:s,lodMeshes:r}}function po(o,e){const t={magFilter:l.LinearFilter,minFilter:l.LinearFilter,generateMipmaps:!1,type:l.HalfFloatType,format:l.RGBAFormat,colorSpace:l.LinearSRGBColorSpace},s=new l.RenderTarget(o,e,t);return s.texture.mapping=l.CubeUVReflectionMapping,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function ks(o,e,t,s,r){o.viewport.set(e,t,s,r),o.scissor.set(e,t,s,r)}function pi(o){const e=new ce;return e.depthTest=!1,e.depthWrite=!1,e.blending=l.NoBlending,e.name=`PMREM_${o}`,e}function bf(o,e,t){const s=We(new Array(At).fill(0)),r=O(new l.Vector3(0,1,0)),n=O(0),i=b(At),u=O(0),a=O(1),c=X(null),d=O(0),h=b(1/e),p=b(1/t),f=b(o),g={n:i,latitudinal:u,weights:s,poleAxis:r,outputDirection:hi,dTheta:n,samples:a,envMap:c,mipInt:d,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:f},m=pi("blur");return m.fragmentNode=yf({...g,latitudinal:u.equal(1)}),Yu.set(m,g),m}function fo(o){const e=pi("cubemap");return e.fragmentNode=Fs(o,hi),e}function go(o){const e=pi("equirect");return e.fragmentNode=X(o,Gu(hi),0),e}const mo=new WeakMap;function Rf(o){const e=Math.log2(o)-2,t=1/o;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:t,maxMip:e}}function Af(o,e,t){const s=Cf(e);let r=s.get(o);if((r!==void 0?r.pmremVersion:-1)!==o.pmremVersion){const i=o.image;if(o.isCubeTexture)if(vf(i))r=t.fromCubemap(o,r);else return null;else if(Ef(i))r=t.fromEquirectangular(o,r);else return null;r.pmremVersion=o.pmremVersion,s.set(o,r)}return r.texture}function Cf(o){let e=mo.get(o);return e===void 0&&(e=new WeakMap,mo.set(o,e)),e}class Zu extends fe{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new l.Texture;r.isRenderTargetTexture=!0,this._texture=X(r),this._width=O(0),this._height=O(0),this._maxMip=O(0),this.updateBeforeType=z.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=Rf(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem;const s=t?t.pmremVersion:-1,r=this._value;s!==r.pmremVersion&&(r.isPMREMTexture===!0?t=r:t=Af(r,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new ju(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this)),t=tu.mul(A(t.x,t.y.negate(),t.z));let s=this.levelNode;return s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this)),Tf(this._texture,t,s,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}}function vf(o){if(o==null)return!1;let e=0;const t=6;for(let s=0;s<t;s++)o[s]!==void 0&&e++;return e===t}function Ef(o){return o==null?!1:o.height>0}const Ju=B(Zu).setParameterLength(1,3),To=new WeakMap;class el extends Ft{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const h=s.isTextureNode?s.value:t[s.property];let p=To.get(h);p===void 0&&(p=Ju(h),To.set(h,p)),s=p}const n=t.useAnisotropy===!0||t.anisotropy>0?Bh:Z,i=s.context(yo(je,n)).mul(wr),u=s.context(Bf(es)).mul(Math.PI).mul(wr),a=er(i),c=er(u);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(c);const d=e.context.lightingModel.clearcoatRadiance;if(d){const h=s.context(yo(lr,Ot)).mul(wr),p=er(h);d.addAssign(p)}}}const yo=(o,e)=>{let t=null;return{getUV:()=>(t===null&&(t=oe.negate().reflect(e),t=o.mul(o).mix(t,e).normalize(),t=t.transformDirection(tt)),t),getTextureLevel:()=>o}},Bf=o=>({getUV:()=>o,getTextureLevel:()=>b(1)}),Mf=new l.MeshStandardMaterial;class fi extends ce{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(Mf),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new el(t):null}setupLightingModel(){return new di}setupSpecular(){const e=ne(A(.04),K.rgb,ur);Be.assign(e),cr.assign(1)}setupVariants(){const e=this.metalnessNode?b(this.metalnessNode):Vh;ur.assign(e);let t=this.roughnessNode?b(this.roughnessNode):Oh;t=Hu({roughness:t}),je.assign(t),this.setupSpecular(),K.assign(k(K.rgb.mul(e.oneMinus()),K.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const Ff=new l.MeshPhysicalMaterial;class tl extends fi{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(Ff),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){const e=this.iorNode?b(this.iorNode):ep;Js.assign(e),Be.assign(ne(Kt(Ba(Js.sub(1).div(Js.add(1))).mul(Ih),A(1)).mul($i),K.rgb,ur)),cr.assign(ne($i,1,ur))}setupLightingModel(){return new di(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const t=this.clearcoatNode?b(this.clearcoatNode):zh,s=this.clearcoatRoughnessNode?b(this.clearcoatRoughnessNode):$h;Tn.assign(t),lr.assign(Hu({roughness:s}))}if(this.useSheen){const t=this.sheenNode?A(this.sheenNode):qh,s=this.sheenRoughnessNode?b(this.sheenRoughnessNode):Xh;It.assign(t),zn.assign(s)}if(this.useIridescence){const t=this.iridescenceNode?b(this.iridescenceNode):Qh,s=this.iridescenceIORNode?b(this.iridescenceIORNode):Yh,r=this.iridescenceThicknessNode?b(this.iridescenceThicknessNode):jh;$n.assign(t),da.assign(s),ha.assign(r)}if(this.useAnisotropy){const t=(this.anisotropyNode?w(this.anisotropyNode):Kh).toVar();St.assign(t.length()),le(St.equal(0),()=>{t.assign(w(1,0))}).Else(()=>{t.divAssign(w(St)),St.assign(St.saturate())}),yn.assign(St.pow2().mix(je.pow2(),1)),Zs.assign(ms[0].mul(t.x).add(ms[1].mul(t.y))),Wt.assign(ms[1].mul(t.x).sub(ms[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?b(this.transmissionNode):Zh,s=this.thicknessNode?b(this.thicknessNode):Jh,r=this.attenuationDistanceNode?b(this.attenuationDistanceNode):tp,n=this.attenuationColorNode?A(this.attenuationColorNode):sp;if(_n.assign(t),pa.assign(s),fa.assign(r),ga.assign(n),this.useDispersion){const i=this.dispersionNode?b(this.dispersionNode):up;ma.assign(i)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?A(this.clearcoatNormalNode):Wh}setup(e){e.context.setupClearcoatNormal=()=>Ss(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}const wf=v(({normal:o,lightDirection:e,builder:t})=>{const s=o.dot(e),r=w(s.mul(.5).add(.5),0);if(t.material.gradientMap){const n=ot("gradientMap","texture").context({getUV:()=>r});return A(n.r)}else{const n=r.fwidth().mul(.5);return ne(A(.7),A(1),lt(b(.7).sub(n.x),b(.7).add(n.x),r.x))}});class Pf extends Ls{direct({lightDirection:e,lightColor:t,reflectedLight:s},r){const n=wf({normal:Ja,lightDirection:e,builder:r}).mul(t);s.directDiffuse.addAssign(n.mul(Yt({diffuseColor:K.rgb})))}indirect(e){const{ambientOcclusion:t,irradiance:s,reflectedLight:r}=e.context;r.indirectDiffuse.addAssign(s.mul(Yt({diffuseColor:K}))),r.indirectDiffuse.mulAssign(t)}}const Df=new l.MeshToonMaterial;class sl extends ce{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Df),this.setValues(e)}setupLightingModel(){return new Pf}}const Lf=v(()=>{const o=A(oe.z,0,oe.x.negate()).normalize(),e=oe.cross(o);return w(o.dot(Z),e.dot(Z)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),Uf=new l.MeshMatcapMaterial;class rl extends ce{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(Uf),this.setValues(e)}setupVariants(e){const t=Lf;let s;e.material.matcap?s=ot("matcap","texture").context({getUV:()=>t}):s=A(ne(.2,.8,t.y)),K.rgb.mulAssign(s.rgb)}}class nl extends fe{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if(this.getNodeType(e)==="vec2"){const n=t.cos(),i=t.sin();return kn(n,i,i.negate(),n).mul(s)}else{const n=t,i=$t(k(1,0,0,0),k(0,it(n.x),Oe(n.x).negate(),0),k(0,Oe(n.x),it(n.x),0),k(0,0,0,1)),u=$t(k(it(n.y),0,Oe(n.y),0),k(0,1,0,0),k(Oe(n.y).negate(),0,it(n.y),0),k(0,0,0,1)),a=$t(k(it(n.z),Oe(n.z).negate(),0,0),k(Oe(n.z),it(n.z),0,0),k(0,0,1,0),k(0,0,0,1));return i.mul(u).mul(a).mul(k(s,1)).xyz}}}const il=B(nl).setParameterLength(2),Gf=new l.SpriteMaterial;class gi extends ce{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(Gf),this.setValues(e)}setupPositionView(e){const{object:t,camera:s}=e,r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:u}=this,a=yr.mul(A(n||0));let c=w(Et[0].xyz.length(),Et[1].xyz.length());if(u!==null&&(c=c.mul(w(u))),r===!1)if(s.isPerspectiveCamera)c=c.mul(a.z.negate());else{const f=b(2).div(oi.element(1).element(1));c=c.mul(f.mul(2))}let d=xr.xy;if(t.center&&t.center.isVector2===!0){const f=Hd("center","vec2",t);d=d.sub(f.sub(.5))}d=d.mul(c);const h=b(i||Hh),p=il(d,h);return k(a.xy.add(p),a.zw)}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}const If=new l.PointsMaterial;class ol extends gi{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(If),this.setValues(e)}setupPositionView(){const{positionNode:e}=this;return yr.mul(A(e||Te)).xyz}setupVertex(e){const t=super.setupVertex(e);if(e.material.isNodeMaterial!==!0)return t;const{rotationNode:s,scaleNode:r,sizeNode:n}=this,i=xr.xy.toVar(),u=bs.z.div(bs.w);if(s&&s.isNode){const c=b(s);i.assign(il(i,c))}let a=n!==null?w(n):ap;return this.sizeAttenuation===!0&&(a=a.mul(a.div(ue.z.negate()))),r&&r.isNode&&(a=a.mul(w(r))),i.mulAssign(a.mul(2)),i.assign(i.div(bs.z)),i.y.assign(i.y.mul(u)),i.assign(i.mul(t.w)),t.addAssign(k(i,0,0)),t}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}class Of extends Ls{constructor(){super(),this.shadowNode=b(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){K.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(K.rgb)}}const Vf=new l.ShadowMaterial;class al extends ce{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(Vf),this.setValues(e)}setupLightingModel(){return new Of}}ut("vec3");ut("vec3");ut("vec3");class kf{constructor(e,t){this.nodes=e,this.info=t,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this._animationLoop!==null&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class ke{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let s=this.weakMap;for(let r=0;r<e.length-1;r++){const n=e[r];s.has(n)===!1&&s.set(n,new WeakMap),s=s.get(n)}return s.set(e[e.length-1],t),this}delete(e){let t=this.weakMap;for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return!1;return t.delete(e[e.length-1])}}let zf=0;function $f(o){const e=Object.keys(o);let t=Object.getPrototypeOf(o);for(;t;){const s=Object.getOwnPropertyDescriptors(t);for(const r in s)if(s[r]!==void 0){const n=s[r];n&&typeof n.get=="function"&&e.push(r)}t=Object.getPrototypeOf(t)}return e}class Wf{constructor(e,t,s,r,n,i,u,a,c,d){this.id=zf++,this._nodes=e,this._geometries=t,this.renderer=s,this.object=r,this.material=n,this.scene=i,this.camera=u,this.lightsNode=a,this.context=c,this.geometry=r.geometry,this.version=n.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=d,this.clippingContextCacheKey=d!==null?d.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(const t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(this.attributes!==null)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set,n={};for(const i of e){let u;if(i.node&&i.node.attribute?u=i.node.attribute:(u=t.getAttribute(i.name),n[i.name]=u.version),u===void 0)continue;s.push(u);const a=u.isInterleavedBufferAttribute?u.data:u;r.add(a)}return this.attributes=s,this.attributesId=n,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),u=this.getIndex(),a=u!==null;let c=1;if(s.isInstancedBufferGeometry===!0?c=s.instanceCount:e.count!==void 0&&(c=Math.max(0,e.count)),c===0)return null;if(i.instanceCount=c,e.isBatchedMesh===!0)return i;let d=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(d=2);let h=n.start*d,p=(n.start+n.count)*d;r!==null&&(h=Math.max(h,r.start*d),p=Math.min(p,(r.start+r.count)*d));const f=s.attributes.position;let g=1/0;a?g=u.count:f!=null&&(g=f.count),h=Math.max(h,0),p=Math.min(p,g);const m=p-h;return m<0||m===1/0?null:(i.vertexCount=m,i.firstVertex=h,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}for(const s of Object.keys(e.morphAttributes).sort()){const r=e.morphAttributes[s];t+="morph-"+s+",";for(let n=0,i=r.length;n<i;n++){const u=r[n];t+=u.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const r of $f(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(r))continue;const n=t[r];let i;if(n!==null){const u=typeof n;u==="number"?i=n!==0?"1":"0":u==="object"?(i="{",n.isTexture&&(i+=n.mapping),i+="}"):i=String(n)}else i=String(n);s+=i+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),s+=e.receiveShadow+",",Jl(s)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){const e=this.attributesId;for(const t in e){const s=this.geometry.getAttribute(t);if(s===void 0||e[t]!==s.id)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=rr(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=rr(e,1)),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this.onDispose()}}const Tt=[];class Hf{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,u,a){const c=this.getChainMap(a);Tt[0]=e,Tt[1]=t,Tt[2]=i,Tt[3]=n;let d=c.get(Tt);return d===void 0?(d=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,u,a),c.set(Tt,d)):(d.updateClipping(u),d.needsGeometryUpdate&&d.setGeometry(e.geometry),(d.version!==t.version||d.needsUpdate)&&(d.initialCacheKey!==d.getCacheKey()?(d.dispose(),d=this.get(e,t,s,r,n,i,u,a)):d.version=t.version)),Tt.length=0,d}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new ke)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,u,a,c,d,h){const p=this.getChainMap(h),f=new Wf(e,t,s,r,n,i,u,a,c,d);return f.onDispose=()=>{this.pipelines.delete(f),this.bindings.delete(f),this.nodes.delete(f),p.delete(f.getChainArray())},f}}class pt{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Pe={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},at=16,qf=211,Xf=212;class Kf extends pt{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return t!==null&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(s.version===void 0)t===Pe.VERTEX?this.backend.createAttribute(e):t===Pe.INDEX?this.backend.createIndexAttribute(e):t===Pe.STORAGE?this.backend.createStorageAttribute(e):t===Pe.INDIRECT&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const r=this._getBufferAttribute(e);(s.version<r.version||r.usage===l.DynamicDrawUsage)&&(this.backend.updateAttribute(e),s.version=r.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function ul(o){return o.index!==null?o.index.version:o.attributes.position.version}function xo(o){const e=[],t=o.index,s=o.attributes.position;if(t!==null){const n=t.array;for(let i=0,u=n.length;i<u;i+=3){const a=n[i+0],c=n[i+1],d=n[i+2];e.push(a,c,c,d,d,a)}}else{const n=s.array;for(let i=0,u=n.length/3-1;i<u;i+=3){const a=i+0,c=i+1,d=i+2;e.push(a,c,c,d,d,a)}}const r=new(l.arrayNeedsUint32(e)?l.Uint32BufferAttribute:l.Uint16BufferAttribute)(e,1);return r.version=ul(o),r}class Qf extends pt{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry,s=this.get(t);s.initialized=!0,this.info.memory.geometries++;const r=()=>{this.info.memory.geometries--;const n=t.index,i=e.getAttributes();n!==null&&this.attributes.delete(n);for(const a of i)this.attributes.delete(a);const u=this.wireframes.get(t);u!==void 0&&this.attributes.delete(u),t.removeEventListener("dispose",r)};t.addEventListener("dispose",r)}updateAttributes(e){const t=e.getAttributes();for(const n of t)n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute?this.updateAttribute(n,Pe.STORAGE):this.updateAttribute(n,Pe.VERTEX);const s=this.getIndex(e);s!==null&&this.updateAttribute(s,Pe.INDEX);const r=e.geometry.indirect;r!==null&&this.updateAttribute(r,Pe.INDIRECT)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(s.wireframe===!0){const n=this.wireframes;let i=n.get(t);i===void 0?(i=xo(t),n.set(t,i)):i.version!==ul(t)&&(this.attributes.delete(i),i=xo(t),n.set(t,i)),r=i}return r}}class Yf{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class ll{constructor(e){this.cacheKey=e,this.usedTimes=0}}class jf extends ll{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Zf extends ll{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Jf=0;class Xr{constructor(e,t,s,r=null,n=null){this.id=Jf++,this.code=e,this.stage=t,this.name=s,this.transforms=r,this.attributes=n,this.usedTimes=0}}class eg extends pt{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let u=this.programs.compute.get(i.computeShader);u===void 0&&(n&&n.computeProgram.usedTimes===0&&this._releaseProgram(n.computeProgram),u=new Xr(i.computeShader,"compute",e.name,i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,u),s.createProgram(u));const a=this._getComputeCacheKey(e,u);let c=this.caches.get(a);c===void 0&&(n&&n.usedTimes===0&&this._releasePipeline(n),c=this._getComputePipeline(e,u,a,t)),c.usedTimes++,u.usedTimes++,r.version=e.version,r.pipeline=c}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState(),u=e.material?e.material.name:"";let a=this.programs.vertex.get(i.vertexShader);a===void 0&&(n&&n.vertexProgram.usedTimes===0&&this._releaseProgram(n.vertexProgram),a=new Xr(i.vertexShader,"vertex",u),this.programs.vertex.set(i.vertexShader,a),s.createProgram(a));let c=this.programs.fragment.get(i.fragmentShader);c===void 0&&(n&&n.fragmentProgram.usedTimes===0&&this._releaseProgram(n.fragmentProgram),c=new Xr(i.fragmentShader,"fragment",u),this.programs.fragment.set(i.fragmentShader,c),s.createProgram(c));const d=this._getRenderCacheKey(e,a,c);let h=this.caches.get(d);h===void 0?(n&&n.usedTimes===0&&this._releasePipeline(n),h=this._getRenderPipeline(e,a,c,d,t)):e.pipeline=h,h.usedTimes++,a.usedTimes++,c.usedTimes++,r.pipeline=h}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return n===void 0&&(n=new Zf(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return i===void 0&&(i=new jf(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}}class tg extends pt{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const s of t){const r=this.get(s);r.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),r.bindGroup=s)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const s of t){const r=this.get(s);r.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),r.bindGroup=s)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const s=t.attribute,r=s.isIndirectStorageBufferAttribute?Pe.INDIRECT:Pe.STORAGE;this.attributes.update(s,r)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,u=0;for(const a of e.bindings)if(!(a.isNodeUniformsGroup&&this.nodes.updateGroup(a)===!1)){if(a.isStorageBuffer){const c=a.attribute,d=c.isIndirectStorageBufferAttribute?Pe.INDIRECT:Pe.STORAGE;this.attributes.update(c,d)}if(a.isUniformBuffer)a.update()&&s.updateBinding(a);else if(a.isSampler)a.update();else if(a.isSampledTexture){const c=this.textures.get(a.texture);a.needsBindingsUpdate(c.generation)&&(r=!0);const d=a.update(),h=a.texture;d&&this.textures.updateTexture(h);const p=s.get(h);if(p.externalTexture!==void 0||c.isDefaultTexture?n=!1:(i=i*10+h.id,u+=h.version),s.isWebGPUBackend===!0&&p.texture===void 0&&p.externalTexture===void 0&&(console.error("Bindings._update: binding should be available:",a,d,h,a.textureNode.value,r),this.textures.updateTexture(h),r=!0),h.isStorageTexture===!0){const f=this.get(h);a.store===!0?f.needsMipmap=!0:this.textures.needsMipmaps(h)&&f.needsMipmap===!0&&(this.backend.generateMipmaps(h),f.needsMipmap=!1)}}}r===!0&&this.backend.updateBindings(e,t,n?i:0,u)}}function sg(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?o.z-e.z:o.id-e.id}function _o(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?e.z-o.z:o.id-e.id}function So(o){return(o.transmission>0||o.transmissionNode)&&o.side===l.DoubleSide&&o.forceSinglePass===!1}class rg{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,u){let a=this.renderItems[this.renderItemsIndex];return a===void 0?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:u},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=u),this.renderItemsIndex++,a}push(e,t,s,r,n,i,u){const a=this.getNextRenderItem(e,t,s,r,n,i,u);e.occlusionTest===!0&&this.occlusionQueryCount++,s.transparent===!0||s.transmission>0?(So(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,u){const a=this.getNextRenderItem(e,t,s,r,n,i,u);s.transparent===!0||s.transmission>0?(So(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||sg),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||_o),this.transparent.length>1&&this.transparent.sort(t||_o)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const s=this.renderItems[e];if(s.id===null)break;s.id=null,s.object=null,s.geometry=null,s.material=null,s.groupOrder=null,s.renderOrder=null,s.z=null,s.group=null,s.clippingContext=null}}}const is=[];class ng{constructor(e){this.lighting=e,this.lists=new ke}get(e,t){const s=this.lists;is[0]=e,is[1]=t;let r=s.get(is);return r===void 0&&(r=new rg(this.lighting,e,t),s.set(is,r)),is.length=0,r}dispose(){this.lists=new ke}}let ig=0;class og{constructor(){this.id=ig++,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new l.Vector4,this.scissor=!1,this.scissorValue=new l.Vector4,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.isRenderContext=!0}getCacheKey(){return cl(this)}}function cl(o){const{textures:e,activeCubeFace:t}=o,s=[t];for(const r of e)s.push(r.id);return Dn(s)}const os=[],ag=new l.Scene,ug=new l.Camera;class lg{constructor(){this.chainMaps={}}get(e,t,s=null){os[0]=e,os[1]=t;let r;if(s===null)r="default";else{const u=s.texture.format;r=`${s.textures.length}:${u}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this._getChainMap(r);let i=n.get(os);return i===void 0&&(i=new og,n.set(os,i)),os.length=0,s!==null&&(i.sampleCount=s.samples===0?1:s.samples),i}getForClear(e=null){return this.get(ag,ug,e)}_getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new ke)}dispose(){this.chainMaps={}}}const cg=new l.Vector3;class dg extends pt{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){const s=this.get(e),r=e.samples===0?1:e.samples,n=s.depthTextureMips||(s.depthTextureMips={}),i=e.textures,u=this.getSize(i[0]),a=u.width>>t,c=u.height>>t;let d=e.depthTexture||n[t];const h=e.depthBuffer===!0||e.stencilBuffer===!0;let p=!1;d===void 0&&h&&(d=new l.DepthTexture,d.format=e.stencilBuffer?l.DepthStencilFormat:l.DepthFormat,d.type=e.stencilBuffer?l.UnsignedInt248Type:l.UnsignedIntType,d.image.width=a,d.image.height=c,d.image.depth=u.depth,d.isArrayTexture=e.multiview===!0&&u.depth>1,n[t]=d),(s.width!==u.width||u.height!==s.height)&&(p=!0,d&&(d.needsUpdate=!0,d.image.width=a,d.image.height=c,d.image.depth=d.isArrayTexture?d.image.depth:1)),s.width=u.width,s.height=u.height,s.textures=i,s.depthTexture=d||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(p=!0,d&&(d.needsUpdate=!0),s.sampleCount=r);const f={sampleCount:r};if(e.isXRRenderTarget!==!0){for(let g=0;g<i.length;g++){const m=i[g];p&&(m.needsUpdate=!0),this.updateTexture(m,f)}d&&this.updateTexture(d,f)}if(s.initialized!==!0){s.initialized=!0;const g=()=>{e.removeEventListener("dispose",g);for(let m=0;m<i.length;m++)this._destroyTexture(i[m]);d&&this._destroyTexture(d),this.delete(e)};e.addEventListener("dispose",g)}}updateTexture(e,t={}){const s=this.get(e);if(s.initialized===!0&&s.version===e.version)return;const r=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,n=this.backend;if(r&&s.initialized===!0&&(n.destroySampler(e),n.destroyTexture(e)),e.isFramebufferTexture){const c=this.renderer.getRenderTarget();c?e.type=c.texture.type:e.type=l.UnsignedByteType}const{width:i,height:u,depth:a}=this.getSize(e);if(t.width=i,t.height=u,t.depth=a,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,i,u):1,r||e.isStorageTexture===!0)n.createSampler(e),n.createTexture(e,t),s.generation=e.version;else if(s.initialized!==!0&&n.createSampler(e),e.version>0){const d=e.image;if(d===void 0)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(d.complete===!1)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const h=[];for(const p of e.images)h.push(p);t.images=h}else t.image=d;(s.isDefaultTexture===void 0||s.isDefaultTexture===!0)&&(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),e.source.dataReady===!0&&n.updateTexture(e,t),t.needsMipmaps&&e.mipmaps.length===0&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version;if(s.initialized!==!0){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const c=()=>{e.removeEventListener("dispose",c),this._destroyTexture(e)};e.addEventListener("dispose",c)}s.version=e.version}getSize(e,t=cg){let s=e.images?e.images[0]:e.image;return s?(s.image!==void 0&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return e.isCompressedTexture?e.mipmaps?r=e.mipmaps.length:r=1:r=Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return e.isCompressedTexture===!0||e.generateMipmaps}_destroyTexture(e){this.has(e)===!0&&(this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e),this.info.memory.textures--)}}class mi extends l.Color{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class dl extends Y{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}class hl extends V{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.outputNode?this.outputNode.getMemberType(e,t):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new gs(t);return this._currentCond=Se(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new gs(t),r=Se(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new gs(e),this}Switch(e){return this._expressionNode=E(e),this}Case(...e){const t=[];if(e.length>=2)for(let u=0;u<e.length-1;u++)t.push(this._expressionNode.equal(E(e[u])));else throw new Error("TSL: Invalid parameter length. Case() requires at least two parameters.");const s=e[e.length-1],r=new gs(s);let n=t[0];for(let u=1;u<t.length;u++)n=n.or(t[u]);const i=Se(n,r);return this._currentCond===null?(this._currentCond=i,this.add(this._currentCond)):(this._currentCond.elseNode=i,this._currentCond=i,this)}Default(e){return this.Else(e),this}build(e,...t){const s=e.currentStack,r=la();or(this),e.currentStack=this;const n=e.buildStage;for(const u of this.nodes)if(n==="setup")u.build(e);else if(n==="analyze")u.build(e,this);else if(n==="generate"){const a=e.getDataFromNode(u,"any").stages,c=a&&a[e.shaderStage];if(u.isVarNode&&c&&c.length===1&&c[0]&&c[0].isStackNode)continue;u.build(e,"void")}const i=this.outputNode?this.outputNode.build(e,...t):super.build(e,...t);return or(r),e.currentStack=s,i}}const Kr=B(hl).setParameterLength(0,1);new l.Plane;new l.Vector3;new l.Vector3;new l.Vector3;new l.Matrix4;new l.Vector3(0,0,-1);new l.Vector4;new l.Vector3;new l.Vector3;new l.Vector4;new l.Vector2;const hg=new l.RenderTarget;qt.flipX();hg.depthTexture=new l.DepthTexture(1,1);const Qr=new l.OrthographicCamera(-1,1,1,-1,0,1);class pg extends l.BufferGeometry{constructor(e=!1){super();const t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new l.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new l.Float32BufferAttribute(t,2))}}const fg=new pg;class Rr extends l.Mesh{constructor(e=null){super(fg,e),this.camera=Qr,this.isQuadMesh=!0}async renderAsync(e){return e.renderAsync(this,Qr)}render(e){e.render(this,Qr)}}const as=new l.Euler,Yr=new l.Matrix4;class be extends V{static get type(){return"SceneNode"}constructor(e=be.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=this.scene!==null?this.scene:e.scene;let r;return t===be.BACKGROUND_BLURRINESS?r=J("backgroundBlurriness","float",s):t===be.BACKGROUND_INTENSITY?r=J("backgroundIntensity","float",s):t===be.BACKGROUND_ROTATION?r=O("mat4").label("backgroundRotation").setGroup(I).onRenderUpdate(()=>{const n=s.background;return n!==null&&n.isTexture&&n.mapping!==l.UVMapping?(as.copy(s.backgroundRotation),as.x*=-1,as.y*=-1,as.z*=-1,Yr.makeRotationFromEuler(as)):Yr.identity(),Yr}):console.error("THREE.SceneNode: Unknown scope:",t),r}}be.BACKGROUND_BLURRINESS="backgroundBlurriness";be.BACKGROUND_INTENSITY="backgroundIntensity";be.BACKGROUND_ROTATION="backgroundRotation";const gg=P(be,be.BACKGROUND_BLURRINESS),No=P(be,be.BACKGROUND_INTENSITY),mg=P(be,be.BACKGROUND_ROTATION),Tg=v(({texture:o,uv:e})=>{const s=A().toVar();return le(e.x.lessThan(1e-4),()=>{s.assign(A(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{s.assign(A(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{s.assign(A(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{s.assign(A(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{s.assign(A(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{s.assign(A(0,0,-1))}).Else(()=>{const n=o.sample(e.add(A(-.01,0,0))).r.sub(o.sample(e.add(A(.01,0,0))).r),i=o.sample(e.add(A(0,-.01,0))).r.sub(o.sample(e.add(A(0,.01,0))).r),u=o.sample(e.add(A(0,0,-.01))).r.sub(o.sample(e.add(A(0,0,.01))).r);s.assign(A(n,i,u))}),s.normalize()});class pl extends Mt{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return A(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.isRenderTargetTexture===!0||s.isFramebufferTexture===!0)&&(this.sampler?t=t.flipY():t=t.setY(se(Ht(this,this.levelNode).y).sub(t.y).sub(1))),t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Tg({texture:this,uv:e})}}const yg=B(pl).setParameterLength(1,3),zs=new l.Vector2;class xg extends Mt{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class bo extends xg{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){const e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e}}class Us extends fe{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new l.DepthTexture;n.isRenderTargetTexture=!0,n.name="depth";const i=new l.RenderTarget(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:l.HalfFloatType,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=O(0),this._cameraFar=O(0),this._mrt=null,this._layers=null,this._resolution=1,this.isPassNode=!0,this.updateBeforeType=z.FRAME,this.global=!0}setResolution(e){return this._resolution=e,this}getResolution(){return this._resolution}setLayers(e){return this._layers=e,this}getLayers(){return this._layers}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getTexture(e){let t=this._textures[e];return t===void 0&&(t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(t!==void 0){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return t===void 0&&(t=E(new bo(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=E(new bo(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=Bu(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=Rs(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=this.options.samples===void 0?e.samples:this.options.samples,this.renderTarget.texture.type=e.getColorBufferType(),this.scope===Us.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s}=this;let r,n;const i=t.getOutputRenderTarget();i&&i.isXRRenderTarget===!0?(n=1,r=t.xr.getCamera(),t.xr.updateCamera(r),zs.set(i.width,i.height)):(r=this.camera,n=t.getPixelRatio(),t.getSize(zs)),this._pixelRatio=n,this.setSize(zs.width,zs.height);const u=t.getRenderTarget(),a=t.getMRT(),c=r.layers.mask;this._cameraNear.value=r.near,this._cameraFar.value=r.far,this._layers!==null&&(r.layers.mask=this._layers.mask);for(const d in this._previousTextures)this.toggleTexture(d);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(u),t.setMRT(a),r.layers.mask=c}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio*this._resolution,r=this._height*this._pixelRatio*this._resolution;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Us.COLOR="color";Us.DEPTH="depth";const _g=v(([o,e])=>o.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Sg=v(([o,e])=>(o=o.mul(e),o.div(o.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Ng=v(([o,e])=>{o=o.mul(e),o=o.sub(.004).max(0);const t=o.mul(o.mul(6.2).add(.5)),s=o.mul(o.mul(6.2).add(1.7)).add(.06);return t.div(s).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),bg=v(([o])=>{const e=o.mul(o.add(.0245786)).sub(90537e-9),t=o.mul(o.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),Rg=v(([o,e])=>{const t=Re(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),s=Re(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return o=o.mul(e).div(.6),o=t.mul(o),o=bg(o),o=s.mul(o),o.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Ag=Re(A(1.6605,-.1246,-.0182),A(-.5876,1.1329,-.1006),A(-.0728,-.0083,1.1187)),Cg=Re(A(.6274,.0691,.0164),A(.3293,.9195,.088),A(.0433,.0113,.8956)),vg=v(([o])=>{const e=A(o).toVar(),t=A(e.mul(e)).toVar(),s=A(t.mul(t)).toVar();return b(15.5).mul(s.mul(t)).sub($(40.14,s.mul(e))).add($(31.96,s).sub($(6.868,t.mul(e))).add($(.4298,t).add($(.1191,e).sub(.00232))))}),Eg=v(([o,e])=>{const t=A(o).toVar(),s=Re(A(.856627153315983,.137318972929847,.11189821299995),A(.0951212405381588,.761241990602591,.0767994186031903),A(.0482516061458583,.101439036467562,.811302368396859)),r=Re(A(1.1271005818144368,-.1413297634984383,-.14132976349843826),A(-.11060664309660323,1.157823702216272,-.11060664309660294),A(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=b(-12.47393),i=b(4.026069);return t.mulAssign(e),t.assign(Cg.mul(t)),t.assign(s.mul(t)),t.assign(ye(t,1e-10)),t.assign(Ze(t)),t.assign(t.sub(n).div(i.sub(n))),t.assign(et(t,0,1)),t.assign(vg(t)),t.assign(r.mul(t)),t.assign(mr(ye(A(0),t),A(2.2))),t.assign(Ag.mul(t)),t.assign(et(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Bg=v(([o,e])=>{const t=b(.76),s=b(.15);o=o.mul(e);const r=Kt(o.r,Kt(o.g,o.b)),n=Se(r.lessThan(.08),r.sub($(6.25,r.mul(r))),.04);o.subAssign(n);const i=ye(o.r,ye(o.g,o.b));le(i.lessThan(t),()=>o);const u=_e(1,t),a=_e(1,u.mul(u).div(i.add(u.sub(t))));o.mulAssign(a.div(i));const c=_e(1,qe(1,s.mul(i.sub(a)).add(1)));return ne(o,A(a),c)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class de extends V{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=s}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const r of t)r.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}class fl extends de{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return s===void 0&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);r!==""&&(i.name=r);const u=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(u);return i.code=a+`
|
|
29
29
|
`,t==="property"?u:e.format(`${u}()`,n,t)}}function gl(o){let e;const t=o.context.getViewZ;return t!==void 0&&(e=t(this)),(e||ue.z).negate()}const Mg=v(([o,e],t)=>{const s=gl(t);return lt(o,e,s)}),Fg=v(([o],e)=>{const t=gl(e);return o.mul(o,t,t).negate().exp().oneMinus()}),Ro=v(([o,e])=>k(e.toFloat().mix(xs.rgb,o.toVec3()),xs.a));class wg extends V{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;s.backend.isWebGLBackend===!0?e.addFlowCode(` // ${t}Barrier
|
|
30
30
|
`):e.addLineFlowCode(`${t}Barrier()`,this)}}B(wg);class Qe extends V{static get type(){return"AtomicFunctionNode"}constructor(e,t,s){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=e.getNodeProperties(this),s=t.parents,r=this.method,n=this.getNodeType(e),i=this.getInputType(e),u=this.pointerNode,a=this.valueNode,c=[];c.push(`&${u.build(e,i)}`),a!==null&&c.push(a.build(e,i));const d=`${e.getMethod(r,n)}( ${c.join(", ")} )`;if(s.length===1&&s[0].isStackNode===!0)e.addLineFlowCode(d,this);else return t.constNode===void 0&&(t.constNode=Qt(d,n).toConst()),t.constNode.build(e)}}Qe.ATOMIC_LOAD="atomicLoad";Qe.ATOMIC_STORE="atomicStore";Qe.ATOMIC_ADD="atomicAdd";Qe.ATOMIC_SUB="atomicSub";Qe.ATOMIC_MAX="atomicMax";Qe.ATOMIC_MIN="atomicMin";Qe.ATOMIC_AND="atomicAnd";Qe.ATOMIC_OR="atomicOr";Qe.ATOMIC_XOR="atomicXor";B(Qe);let $s;function Ar(o){$s=$s||new WeakMap;let e=$s.get(o);return e===void 0&&$s.set(o,e={}),e}function ml(o){const e=Ar(o);return e.shadowMatrix||(e.shadowMatrix=O("mat4").setGroup(I).onRenderUpdate(t=>((o.castShadow!==!0||t.renderer.shadowMap.enabled===!1)&&o.shadow.updateMatrices(o),o.shadow.matrix)))}function Pg(o,e=Bs){const t=ml(o).mul(e);return t.xyz.div(t.w)}function Tl(o){const e=Ar(o);return e.position||(e.position=O(new l.Vector3).setGroup(I).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(o.matrixWorld)))}function Dg(o){const e=Ar(o);return e.targetPosition||(e.targetPosition=O(new l.Vector3).setGroup(I).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(o.target.matrixWorld)))}function yl(o){const e=Ar(o);return e.viewPosition||(e.viewPosition=O(new l.Vector3).setGroup(I).onRenderUpdate(({camera:t},s)=>{s.value=s.value||new l.Vector3,s.value.setFromMatrixPosition(o.matrixWorld),s.value.applyMatrix4(t.matrixWorldInverse)}))}const xl=o=>tt.transformDirection(Tl(o).sub(Dg(o))),Lg=o=>o.sort((e,t)=>e.id-t.id),Ug=(o,e)=>{for(const t of e)if(t.isAnalyticLightNode&&t.light.id===o)return t;return null},jr=new WeakMap,us=[];class Ti extends V{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=ut("vec3","totalDiffuse"),this.totalSpecularNode=ut("vec3","totalSpecular"),this.outgoingLightNode=ut("vec3","outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){const e=this._lights;for(let s=0;s<e.length;s++){const r=e[s];if(us.push(r.id),us.push(r.castShadow?1:0),r.isSpotLight===!0){const n=r.map!==null?r.map.id:-1,i=r.colorNode?r.colorNode.getCacheKey():-1;us.push(n,i)}}const t=Dn(us);return us.length=0,t}getHash(e){if(this._lightNodesHash===null){this._lightNodes===null&&this.setupLightsNode(e);const t=[];for(const s of this._lightNodes)t.push(s.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getNodeProperties(this);for(const s of t.nodes)s.build(e);t.outputNode.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=Lg(this._lights),n=e.renderer.library;for(const i of r)if(i.isNode)t.push(E(i));else{let u=null;if(s!==null&&(u=Ug(i.id,s)),u===null){const a=n.getLightNodeClass(i.constructor);if(a===null){console.warn(`LightsNode.setupNodeLights: Light node not found for ${i.constructor.name}`);continue}let c=null;jr.has(i)?c=jr.get(i):(c=E(new a(i)),jr.set(i,c)),t.push(c)}}this._lightNodes=t}setupDirectLight(e,t,s){const{lightingModel:r,reflectedLight:n}=e.context;r.direct({...s,lightNode:t,reflectedLight:n},e)}setupDirectRectAreaLight(e,t,s){const{lightingModel:r,reflectedLight:n}=e.context;r.directRectArea({...s,lightNode:t,reflectedLight:n},e)}setupLights(e,t){for(const s of t)s.build(e)}getLightNodes(e){return this._lightNodes===null&&this.setupLightsNode(e),this._lightNodes}setup(e){const t=e.lightsNode;e.lightsNode=this;let s=this.outgoingLightNode;const r=e.context,n=r.lightingModel,i=e.getNodeProperties(this);if(n){const{totalDiffuseNode:u,totalSpecularNode:a}=this;r.outgoingLight=s;const c=e.addStack();i.nodes=c.nodes,n.start(e);const{backdrop:d,backdropAlpha:h}=r,{directDiffuse:p,directSpecular:f,indirectDiffuse:g,indirectSpecular:m}=r.reflectedLight;let y=p.add(g);d!==null&&(h!==null?y=A(h.mix(y,d)):y=A(d),r.material.transparent=!0),u.assign(y),a.assign(f.add(m)),s.assign(u.add(a)),n.finish(e),s=s.bypass(e.removeStack())}else i.nodes=[];return e.lightsNode=t,s}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}class _l extends V{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=z.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){Sl.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||Bs)}}const Sl=ut("vec3","shadowPositionWorld");function Gg(o,e={}){return e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure,e.outputColorSpace=o.outputColorSpace,e.renderTarget=o.getRenderTarget(),e.activeCubeFace=o.getActiveCubeFace(),e.activeMipmapLevel=o.getActiveMipmapLevel(),e.renderObjectFunction=o.getRenderObjectFunction(),e.pixelRatio=o.getPixelRatio(),e.mrt=o.getMRT(),e.clearColor=o.getClearColor(e.clearColor||new l.Color),e.clearAlpha=o.getClearAlpha(),e.autoClear=o.autoClear,e.scissorTest=o.getScissorTest(),e}function Ig(o,e){return e=Gg(o,e),o.setMRT(null),o.setRenderObjectFunction(null),o.setClearColor(0,1),o.autoClear=!0,e}function Og(o,e){o.toneMapping=e.toneMapping,o.toneMappingExposure=e.toneMappingExposure,o.outputColorSpace=e.outputColorSpace,o.setRenderTarget(e.renderTarget,e.activeCubeFace,e.activeMipmapLevel),o.setRenderObjectFunction(e.renderObjectFunction),o.setPixelRatio(e.pixelRatio),o.setMRT(e.mrt),o.setClearColor(e.clearColor,e.clearAlpha),o.autoClear=e.autoClear,o.setScissorTest(e.scissorTest)}function Vg(o,e={}){return e.background=o.background,e.backgroundNode=o.backgroundNode,e.overrideMaterial=o.overrideMaterial,e}function kg(o,e){return e=Vg(o,e),o.background=null,o.backgroundNode=null,o.overrideMaterial=null,e}function zg(o,e){o.background=e.background,o.backgroundNode=e.backgroundNode,o.overrideMaterial=e.overrideMaterial}function $g(o,e,t){return t=Ig(o,t),t=kg(e,t),t}function Wg(o,e,t){Og(o,t),zg(e,t)}const Ao=new WeakMap,Hg=v(({depthTexture:o,shadowCoord:e,depthLayer:t})=>{let s=X(o,e.xy).label("t_basic");return o.isArrayTexture&&(s=s.depth(t)),s.compare(e.z)}),qg=v(({depthTexture:o,shadowCoord:e,shadow:t,depthLayer:s})=>{const r=(y,_)=>{let C=X(o,y);return o.isArrayTexture&&(C=C.depth(s)),C.compare(_)},n=J("mapSize","vec2",t).setGroup(I),i=J("radius","float",t).setGroup(I),u=w(1).div(n),a=u.x.negate().mul(i),c=u.y.negate().mul(i),d=u.x.mul(i),h=u.y.mul(i),p=a.div(2),f=c.div(2),g=d.div(2),m=h.div(2);return Ce(r(e.xy.add(w(a,c)),e.z),r(e.xy.add(w(0,c)),e.z),r(e.xy.add(w(d,c)),e.z),r(e.xy.add(w(p,f)),e.z),r(e.xy.add(w(0,f)),e.z),r(e.xy.add(w(g,f)),e.z),r(e.xy.add(w(a,0)),e.z),r(e.xy.add(w(p,0)),e.z),r(e.xy,e.z),r(e.xy.add(w(g,0)),e.z),r(e.xy.add(w(d,0)),e.z),r(e.xy.add(w(p,m)),e.z),r(e.xy.add(w(0,m)),e.z),r(e.xy.add(w(g,m)),e.z),r(e.xy.add(w(a,h)),e.z),r(e.xy.add(w(0,h)),e.z),r(e.xy.add(w(d,h)),e.z)).mul(1/17)}),Xg=v(({depthTexture:o,shadowCoord:e,shadow:t,depthLayer:s})=>{const r=(h,p)=>{let f=X(o,h);return o.isArrayTexture&&(f=f.depth(s)),f.compare(p)},n=J("mapSize","vec2",t).setGroup(I),i=w(1).div(n),u=i.x,a=i.y,c=e.xy,d=dt(c.mul(n).add(.5));return c.subAssign(d.mul(i)),Ce(r(c,e.z),r(c.add(w(u,0)),e.z),r(c.add(w(0,a)),e.z),r(c.add(i),e.z),ne(r(c.add(w(u.negate(),0)),e.z),r(c.add(w(u.mul(2),0)),e.z),d.x),ne(r(c.add(w(u.negate(),a)),e.z),r(c.add(w(u.mul(2),a)),e.z),d.x),ne(r(c.add(w(0,a.negate())),e.z),r(c.add(w(0,a.mul(2))),e.z),d.y),ne(r(c.add(w(u,a.negate())),e.z),r(c.add(w(u,a.mul(2))),e.z),d.y),ne(ne(r(c.add(w(u.negate(),a.negate())),e.z),r(c.add(w(u.mul(2),a.negate())),e.z),d.x),ne(r(c.add(w(u.negate(),a.mul(2))),e.z),r(c.add(w(u.mul(2),a.mul(2))),e.z),d.x),d.y)).mul(1/9)}),Kg=v(({depthTexture:o,shadowCoord:e,depthLayer:t})=>{const s=b(1).toVar();let r=X(o).sample(e.xy);o.isArrayTexture&&(r=r.depth(t)),r=r.rg;const n=va(e.z,r.x);return le(n.notEqual(b(1)),()=>{const i=e.z.sub(r.x),u=ye(0,r.y.mul(r.y));let a=u.div(u.add(i.mul(i)));a=et(_e(a,.3).div(.95-.3)),s.assign(et(ye(n,a)))}),s}),Qg=v(([o,e,t])=>{let s=Bs.sub(o).length();return s=s.sub(e).div(t.sub(e)),s=s.saturate(),s}),Yg=o=>{const e=o.shadow.camera,t=J("near","float",e).setGroup(I),s=J("far","float",e).setGroup(I),r=uh(o);return Qg(r,t,s)},jg=o=>{let e=Ao.get(o);if(e===void 0){const t=o.isPointLight?Yg(o):null;e=new ce,e.colorNode=k(0,0,0,1),e.depthNode=t,e.isShadowPassMaterial=!0,e.name="ShadowMaterial",e.fog=!1,Ao.set(o,e)}return e},Co=new ke,Pt=[],Zg=(o,e,t,s)=>{Pt[0]=o,Pt[1]=e;let r=Co.get(Pt);return(r===void 0||r.shadowType!==t||r.useVelocity!==s)&&(r=(n,i,u,a,c,d,...h)=>{(n.castShadow===!0||n.receiveShadow&&t===l.VSMShadowMap)&&(s&&(ta(n).useVelocity=!0),n.onBeforeShadow(o,n,u,e.camera,a,i.overrideMaterial,d),o.renderObject(n,i,u,a,c,d,...h),n.onAfterShadow(o,n,u,e.camera,a,i.overrideMaterial,d))},r.shadowType=t,r.useVelocity=s,Co.set(Pt,r)),Pt[0]=null,Pt[1]=null,r},Jg=v(({samples:o,radius:e,size:t,shadowPass:s,depthLayer:r})=>{const n=b(0).toVar("meanVertical"),i=b(0).toVar("squareMeanVertical"),u=o.lessThanEqual(b(1)).select(b(0),b(2).div(o.sub(1))),a=o.lessThanEqual(b(1)).select(b(0),b(-1));Ve({start:se(0),end:se(o),type:"int",condition:"<"},({i:d})=>{const h=a.add(b(d).mul(u));let p=s.sample(Ce(Sr.xy,w(0,h).mul(e)).div(t));s.value.isArrayTexture&&(p=p.depth(r)),p=p.x,n.addAssign(p),i.addAssign(p.mul(p))}),n.divAssign(o),i.divAssign(o);const c=Xn(i.sub(n.mul(n)));return w(n,c)}),em=v(({samples:o,radius:e,size:t,shadowPass:s,depthLayer:r})=>{const n=b(0).toVar("meanHorizontal"),i=b(0).toVar("squareMeanHorizontal"),u=o.lessThanEqual(b(1)).select(b(0),b(2).div(o.sub(1))),a=o.lessThanEqual(b(1)).select(b(0),b(-1));Ve({start:se(0),end:se(o),type:"int",condition:"<"},({i:d})=>{const h=a.add(b(d).mul(u));let p=s.sample(Ce(Sr.xy,w(h,0).mul(e)).div(t));s.value.isArrayTexture&&(p=p.depth(r)),n.addAssign(p.x),i.addAssign(Ce(p.y.mul(p.y),p.x.mul(p.x)))}),n.divAssign(o),i.divAssign(o);const c=Xn(i.sub(n.mul(n)));return w(n,c)}),tm=[Hg,qg,Xg,Kg];let Zr;const Ws=new Rr;class yi extends _l{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:s,shadowCoord:r,shadow:n,depthLayer:i}){const u=r.x.greaterThanEqual(0).and(r.x.lessThanEqual(1)).and(r.y.greaterThanEqual(0)).and(r.y.lessThanEqual(1)).and(r.z.lessThanEqual(1)),a=t({depthTexture:s,shadowCoord:r,shadow:n,depthLayer:i});return u.select(a,b(1))}setupShadowCoord(e,t){const{shadow:s}=this,{renderer:r}=e,n=J("bias","float",s).setGroup(I);let i=t,u;if(s.camera.isOrthographicCamera||r.logarithmicDepthBuffer!==!0)i=i.xyz.div(i.w),u=i.z,r.coordinateSystem===l.WebGPUCoordinateSystem&&(u=u.mul(2).sub(1));else{const a=i.w;i=i.xy.div(a);const c=J("near","float",s.camera).setGroup(I),d=J("far","float",s.camera).setGroup(I);u=Mu(a.negate(),c,d)}return i=A(i.x,i.y.oneMinus(),u.add(n)),i}getShadowFilterFn(e){return tm[e]}setupRenderTarget(e,t){const s=new l.DepthTexture(e.mapSize.width,e.mapSize.height);s.name="ShadowDepthTexture",s.compareFunction=l.LessCompare;const r=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return r.texture.name="ShadowMap",r.texture.type=e.mapType,r.depthTexture=s,{shadowMap:r,depthTexture:s}}setupShadow(e){const{renderer:t}=e,{light:s,shadow:r}=this,n=t.shadowMap.type,{depthTexture:i,shadowMap:u}=this.setupRenderTarget(r,e);if(r.camera.updateProjectionMatrix(),n===l.VSMShadowMap&&r.isPointLightShadow!==!0){i.compareFunction=null,u.depth>1?(u._vsmShadowMapVertical||(u._vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:l.RGFormat,type:l.HalfFloatType,depth:u.depth,depthBuffer:!1}),u._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=u._vsmShadowMapVertical,u._vsmShadowMapHorizontal||(u._vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:l.RGFormat,type:l.HalfFloatType,depth:u.depth,depthBuffer:!1}),u._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=u._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:l.RGFormat,type:l.HalfFloatType,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:l.RGFormat,type:l.HalfFloatType,depthBuffer:!1}));let _=X(i);i.isArrayTexture&&(_=_.depth(this.depthLayer));let C=X(this.vsmShadowMapVertical.texture);i.isArrayTexture&&(C=C.depth(this.depthLayer));const R=J("blurSamples","float",r).setGroup(I),U=J("radius","float",r).setGroup(I),M=J("mapSize","vec2",r).setGroup(I);let D=this.vsmMaterialVertical||(this.vsmMaterialVertical=new ce);D.fragmentNode=Jg({samples:R,radius:U,size:M,shadowPass:_,depthLayer:this.depthLayer}).context(e.getSharedContext()),D.name="VSMVertical",D=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new ce),D.fragmentNode=em({samples:R,radius:U,size:M,shadowPass:C,depthLayer:this.depthLayer}).context(e.getSharedContext()),D.name="VSMHorizontal"}const a=J("intensity","float",r).setGroup(I),c=J("normalBias","float",r).setGroup(I),d=ml(s).mul(Sl.add(es.mul(c))),h=this.setupShadowCoord(e,d),p=r.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(p===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const f=n===l.VSMShadowMap&&r.isPointLightShadow!==!0?this.vsmShadowMapHorizontal.texture:i,g=this.setupShadowFilter(e,{filterFn:p,shadowTexture:u.texture,depthTexture:f,shadowCoord:h,shadow:r,depthLayer:this.depthLayer});let m=X(u.texture,h);i.isArrayTexture&&(m=m.depth(this.depthLayer));const y=ne(1,g.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=u,this.shadow.map=u,y}setup(e){if(e.renderer.shadowMap.enabled!==!1)return v(()=>{let t=this._node;return this.setupShadowPosition(e),t===null&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t})()}renderShadow(e){const{shadow:t,shadowMap:s,light:r}=this,{renderer:n,scene:i}=e;t.updateMatrices(r),s.setSize(t.mapSize.width,t.mapSize.height,s.depth),n.render(i,t.camera)}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:u}=e,a=n.shadowMap.type,c=t.depthTexture.version;this._depthVersionCached=c;const d=r.camera.layers.mask;(r.camera.layers.mask&4294967294)===0&&(r.camera.layers.mask=u.layers.mask);const h=n.getRenderObjectFunction(),p=n.getMRT(),f=p?p.has("velocity"):!1;Zr=$g(n,i,Zr),i.overrideMaterial=jg(s),n.setRenderObjectFunction(Zg(n,r,a,f)),n.setClearColor(0,0),n.setRenderTarget(t),this.renderShadow(e),n.setRenderObjectFunction(h),a===l.VSMShadowMap&&r.isPointLightShadow!==!0&&this.vsmPass(n),r.camera.layers.mask=d,Wg(n,i,Zr)}vsmPass(e){const{shadow:t}=this,s=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,s),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,s),e.setRenderTarget(this.vsmShadowMapVertical),Ws.material=this.vsmMaterialVertical,Ws.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),Ws.material=this.vsmMaterialHorizontal,Ws.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),super.dispose()}updateBefore(e){const{shadow:t}=this;let s=t.needsUpdate||t.autoUpdate;s&&(this._cameraFrameId[e.camera]===e.frameId&&(s=!1),this._cameraFrameId[e.camera]=e.frameId),s&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const sm=(o,e)=>E(new yi(o,e)),rm=new l.Color,$e=v(([o,e])=>{const t=o.toVar(),s=we(t),r=qe(1,ye(s.x,ye(s.y,s.z)));s.mulAssign(r),t.mulAssign(r.mul(e.mul(2).oneMinus()));const n=w(t.xy).toVar(),u=e.mul(1.5).oneMinus();return le(s.z.greaterThanEqual(u),()=>{le(t.z.greaterThan(0),()=>{n.x.assign(_e(4,t.x))})}).ElseIf(s.x.greaterThanEqual(u),()=>{const a=dr(t.x);n.x.assign(t.z.mul(a).add(a.mul(2)))}).ElseIf(s.y.greaterThanEqual(u),()=>{const a=dr(t.y);n.x.assign(t.x.add(a.mul(2)).add(2)),n.y.assign(t.z.mul(a).sub(2))}),w(.125,.25).mul(n).add(w(.375,.75)).flipY()}).setLayout({name:"cubeToUV",type:"vec2",inputs:[{name:"pos",type:"vec3"},{name:"texelSizeY",type:"float"}]}),nm=v(({depthTexture:o,bd3D:e,dp:t,texelSize:s})=>X(o,$e(e,s.y)).compare(t)),im=v(({depthTexture:o,bd3D:e,dp:t,texelSize:s,shadow:r})=>{const n=J("radius","float",r).setGroup(I),i=w(-1,1).mul(n).mul(s.y);return X(o,$e(e.add(i.xyy),s.y)).compare(t).add(X(o,$e(e.add(i.yyy),s.y)).compare(t)).add(X(o,$e(e.add(i.xyx),s.y)).compare(t)).add(X(o,$e(e.add(i.yyx),s.y)).compare(t)).add(X(o,$e(e,s.y)).compare(t)).add(X(o,$e(e.add(i.xxy),s.y)).compare(t)).add(X(o,$e(e.add(i.yxy),s.y)).compare(t)).add(X(o,$e(e.add(i.xxx),s.y)).compare(t)).add(X(o,$e(e.add(i.yxx),s.y)).compare(t)).mul(1/9)}),om=v(({filterFn:o,depthTexture:e,shadowCoord:t,shadow:s})=>{const r=t.xyz.toVar(),n=r.length(),i=O("float").setGroup(I).onRenderUpdate(()=>s.camera.near),u=O("float").setGroup(I).onRenderUpdate(()=>s.camera.far),a=J("bias","float",s).setGroup(I),c=O(s.mapSize).setGroup(I),d=b(1).toVar();return le(n.sub(u).lessThanEqual(0).and(n.sub(i).greaterThanEqual(0)),()=>{const h=n.sub(i).div(u.sub(i)).toVar();h.addAssign(a);const p=r.normalize(),f=w(1).div(c.mul(w(4,2)));d.assign(o({depthTexture:e,bd3D:p,dp:h,texelSize:f,shadow:s}))}),d}),vo=new l.Vector4,Dt=new l.Vector2,ls=new l.Vector2;class am extends yi{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===l.BasicShadowMap?nm:im}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,shadowTexture:s,depthTexture:r,shadowCoord:n,shadow:i}){return om({filterFn:t,shadowTexture:s,depthTexture:r,shadowCoord:n,shadow:i})}renderShadow(e){const{shadow:t,shadowMap:s,light:r}=this,{renderer:n,scene:i}=e,u=t.getFrameExtents();ls.copy(t.mapSize),ls.multiply(u),s.setSize(ls.width,ls.height),Dt.copy(t.mapSize);const a=n.autoClear,c=n.getClearColor(rm),d=n.getClearAlpha();n.autoClear=!1,n.setClearColor(t.clearColor,t.clearAlpha),n.clear();const h=t.getViewportCount();for(let p=0;p<h;p++){const f=t.getViewport(p),g=Dt.x*f.x,m=ls.y-Dt.y-Dt.y*f.y;vo.set(g,m,Dt.x*f.z,Dt.y*f.w),s.viewport.copy(vo),t.updateMatrices(r,p),n.render(i,t.camera)}n.autoClear=a,n.setClearColor(c,d)}}const um=(o,e)=>E(new am(o,e));class ft extends Ft{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new l.Color,this.colorNode=e&&e.colorNode||O(this.color).setGroup(I),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=z.FRAME}getHash(){return this.light.uuid}getLightVector(e){return yl(this.light).sub(e.context.positionView||ue)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return sm(this.light)}setupShadow(e){const{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let s=this.shadowColorNode;if(s===null){const r=this.light.shadow.shadowNode;let n;r!==void 0?n=E(r):n=this.setupShadowNode(),this.shadowNode=n,this.shadowColorNode=s=this.colorNode.mul(n),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);const t=this.setupDirect(e),s=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),s&&e.lightsNode.setupDirectRectAreaLight(e,this,s)}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const Nl=v(({lightDistance:o,cutoffDistance:e,decayExponent:t})=>{const s=o.pow(t).max(.01).reciprocal();return e.greaterThan(0).select(s.mul(o.div(e).pow4().oneMinus().clamp().pow2()),s)}),lm=({color:o,lightVector:e,cutoffDistance:t,decayExponent:s})=>{const r=e.normalize(),n=e.length(),i=Nl({lightDistance:n,cutoffDistance:t,decayExponent:s}),u=o.mul(i);return{lightDirection:r,lightColor:u}};class bl extends ft{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=O(0).setGroup(I),this.decayExponentNode=O(2).setGroup(I)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return um(this.light)}setupDirect(e){return lm({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}}v(([o=Ps()],{renderer:e,material:t})=>{const s=Ma(o.mul(2).sub(1));let r;if(t.alphaToCoverage&&e.samples>1){const n=b(s.fwidth()).toVar();r=lt(n.oneMinus(),n.add(1),s).oneMinus()}else r=Se(s.greaterThan(1),0,1);return r});const cm=v(([o,e])=>{const t=o.x,s=o.y,r=o.z;let n=e.element(0).mul(.886227);return n=n.add(e.element(1).mul(2*.511664).mul(s)),n=n.add(e.element(2).mul(2*.511664).mul(r)),n=n.add(e.element(3).mul(2*.511664).mul(t)),n=n.add(e.element(4).mul(2*.429043).mul(t).mul(s)),n=n.add(e.element(5).mul(2*.429043).mul(s).mul(r)),n=n.add(e.element(6).mul(r.mul(r).mul(.743125).sub(.247708))),n=n.add(e.element(7).mul(2*.429043).mul(t).mul(r)),n=n.add(e.element(8).mul(.429043).mul($(t,t).sub($(s,s)))),n}),Ge=new mi;class dm extends pt{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(n===null)r._clearColor.getRGB(Ge),Ge.a=r._clearColor.a;else if(n.isColor===!0)n.getRGB(Ge),Ge.a=1,i=!0;else if(n.isNode===!0){const a=this.get(e),c=n;Ge.copy(r._clearColor);let d=a.backgroundMesh;if(d===void 0){let m=function(){n.removeEventListener("dispose",m),d.material.dispose(),d.geometry.dispose()};const p=jn(k(c).mul(No),{getUV:()=>mg.mul(ph),getTextureLevel:()=>gg});let f=Tu;f=f.setZ(f.w);const g=new ce;g.name="Background.material",g.side=l.BackSide,g.depthTest=!1,g.depthWrite=!1,g.allowOverride=!1,g.fog=!1,g.lights=!1,g.vertexNode=f,g.colorNode=p,a.backgroundMeshNode=p,a.backgroundMesh=d=new l.Mesh(new l.SphereGeometry(1,32,32),g),d.frustumCulled=!1,d.name="Background.mesh",d.onBeforeRender=function(y,_,C){this.matrixWorld.copyPosition(C.matrixWorld)},n.addEventListener("dispose",m)}const h=c.getCacheKey();a.backgroundCacheKey!==h&&(a.backgroundMeshNode.node=k(c).mul(No),a.backgroundMeshNode.needsUpdate=!0,d.material.needsUpdate=!0,a.backgroundCacheKey=h),t.unshift(d,d.geometry,d.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);const u=r.xr.getEnvironmentBlendMode();if(u==="additive"?Ge.set(0,0,0,1):u==="alpha-blend"&&Ge.set(0,0,0,0),r.autoClear===!0||i===!0){const a=s.clearColorValue;a.r=Ge.r,a.g=Ge.g,a.b=Ge.b,a.a=Ge.a,(r.backend.isWebGLBackend===!0||r.alpha===!0)&&(a.r*=a.a,a.g*=a.a,a.b*=a.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=r.autoClearColor===!0,s.clearDepth=r.autoClearDepth===!0,s.clearStencil=r.autoClearStencil===!0}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let hm=0;class Bn{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=hm++}}class pm{constructor(e,t,s,r,n,i,u,a,c,d=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=d,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=u,this.updateAfterNodes=a,this.observer=c,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){const r=new Bn(t.name,[],t.index,t);e.push(r);for(const n of t.bindings)r.bindings.push(n.clone())}else e.push(t);return e}}class Mn{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class Rl{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class xi{constructor(e,t,s=!1,r=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=s,this.count=r}}class Al extends xi{constructor(e,t,s=null,r=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=s,this.interpolationSampling=r}}class Cl{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let fm=0;class sr{constructor(e=null){this.id=fm++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class gm{constructor(e,t){this.name=e,this.members=t,this.output=!1}}class gt{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class mm extends gt{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class Tm extends gt{constructor(e,t=new l.Vector2){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class ym extends gt{constructor(e,t=new l.Vector3){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class xm extends gt{constructor(e,t=new l.Vector4){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class _m extends gt{constructor(e,t=new l.Color){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Sm extends gt{constructor(e,t=new l.Matrix2){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}}class Nm extends gt{constructor(e,t=new l.Matrix3){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class bm extends gt{constructor(e,t=new l.Matrix4){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class Rm extends mm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Am extends Tm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Cm extends ym{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class vm extends xm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Em extends _m{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Bm extends Sm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Mm extends Nm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Fm extends bm{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}const Eo=new WeakMap,wm=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),Hs=o=>/e/g.test(o)?String(o).replace(/\+/g,""):(o=Number(o),o+(o%1?"":".0"));class _i{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.declarations={},this.flow={code:""},this.chaining=[],this.stack=Kr(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new sr,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.currentStack=null,this.subBuildFn=null}getBindGroupsCache(){let e=Eo.get(this.renderer);return e===void 0&&(e=new ke,Eo.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new l.RenderTarget(e,t,s)}createCubeRenderTarget(e,t){return new Iu(e,t)}includes(e){return this.nodes.includes(e)}getOutputStructName(){}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n=!0;for(const u of t)r.push(u),n=n&&u.groupNode.shared!==!0;let i;return n?(i=s.get(r),i===void 0&&(i=new Bn(e,r,this.bindingsIndexes[e].group,r),s.set(r,i))):i=new Bn(e,r,this.bindingsIndexes[e].group,r),i}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return r===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(e===null){const t={},s=this.bindings;for(const r of fn)for(const n in s[r]){const i=s[r][n];(t[n]||(t[n]=[])).push(...i)}e=[];for(const r in t){const n=t[r],i=this._getBindGroup(r,n);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort((t,s)=>t.bindings[0].groupNode.order-s.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){const s=e[t];this.bindingsIndexes[s.name].group=t,s.index=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){this.nodes.includes(e)===!1&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){this.sequentialNodes.includes(e)===!1&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(const e of this.nodes)e.getUpdateType()!==z.NONE&&this.updateNodes.push(e.getSelf());for(const e of this.sequentialNodes){const t=e.getUpdateBeforeType(),s=e.getUpdateAfterType();t!==z.NONE&&this.updateBeforeNodes.push(e.getSelf()),s!==z.NONE&&this.updateAfterNodes.push(e.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===l.LinearFilter||e.magFilter===l.LinearMipmapNearestFilter||e.magFilter===l.NearestMipmapLinearFilter||e.magFilter===l.LinearMipmapLinearFilter||e.minFilter===l.LinearFilter||e.minFilter===l.LinearMipmapNearestFilter||e.minFilter===l.NearestMipmapLinearFilter||e.minFilter===l.LinearMipmapLinearFilter}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}getSharedContext(){return{...this.context},this.context}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){const s=this.getDataFromNode(e);return s.cache===void 0&&(s.cache=new sr(t?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){console.warn("Abstract function.")}getInstanceIndex(){console.warn("Abstract function.")}getDrawIndex(){console.warn("Abstract function.")}getFrontFacing(){console.warn("Abstract function.")}getFragCoord(){console.warn("Abstract function.")}isFlipY(){return!1}increaseUsage(e){const t=this.getDataFromNode(e);return t.usageCount=t.usageCount===void 0?1:t.usageCount+1,t.usageCount}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,s=null){let r=this.generateArrayDeclaration(e,t)+"( ";for(let n=0;n<t;n++){const i=s?s[n]:null;i!==null?r+=i.build(this,e):r+=this.generateConst(e),n<t-1&&(r+=", ")}return r+=" )",r}generateStruct(e,t,s=null){const r=[];for(const n of t){const{name:i,type:u}=n;s&&s[i]&&s[i].isNode?r.push(s[i].build(this,u)):r.push(this.generateConst(u))}return e+"( "+r.join(", ")+" )"}generateConst(e,t=null){if(t===null&&(e==="float"||e==="int"||e==="uint"?t=0:e==="bool"?t=!1:e==="color"?t=new l.Color:e==="vec2"?t=new l.Vector2:e==="vec3"?t=new l.Vector3:e==="vec4"&&(t=new l.Vector4)),e==="float")return Hs(t);if(e==="int")return`${Math.round(t)}`;if(e==="uint")return t>=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${Hs(t.r)}, ${Hs(t.g)}, ${Hs(t.b)} )`;const s=this.getTypeLength(e),r=this.getComponentType(e),n=i=>this.generateConst(r,i);if(s===2)return`${this.getType(e)}( ${n(t.x)}, ${n(t.y)} )`;if(s===3)return`${this.getType(e)}( ${n(t.x)}, ${n(t.y)}, ${n(t.z)} )`;if(s===4&&e!=="mat2")return`${this.getType(e)}( ${n(t.x)}, ${n(t.y)}, ${n(t.z)}, ${n(t.w)} )`;if(s>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(n).join(", ")} )`;if(s>4)return`${this.getType(e)}()`;throw new Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){const s=this.attributes;for(const n of s)if(n.name===e)return n;const r=new Mn(e,t);return this.registerDeclaration(r),s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="samplerComparison"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===l.IntType)return"int";if(t===l.UnsignedIntType)return"uint"}return"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;let s=tc(e);const r=t==="float"?"":t[0];return/mat2/.test(t)===!0&&(s=s.replace("vec","mat")),r+s}getTypeFromArray(e){return wm.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return!(e instanceof l.Float16BufferAttribute)&&n!==!0&&(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return s!==null?Number(s[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}addStack(){return this.stack=Kr(this.stack),this.stacks.push(la()||this.stack),or(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,or(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){s=s===null?e.isGlobal(this)?this.globalCache:this.cache:s;let r=s.getData(e);r===void 0&&(r={},s.setData(e,r)),r[t]===void 0&&(r[t]={});let n=r[t];const i=r.any?r.any.subBuilds:null,u=this.getClosestSubBuild(i);return u&&(n.subBuildsCache===void 0&&(n.subBuildsCache={}),n=n.subBuildsCache[u]||(n.subBuildsCache[u]={}),n.subBuilds=i),n}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(r===void 0){const n=this.uniforms.index++;r=new Mn("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t,s=null,r=this.shaderStage){const n=this.getDataFromNode(e,r,this.globalCache);let i=n.structType;if(i===void 0){const u=this.structs.index++;s===null&&(s="StructType"+u),i=new gm(s,t),this.structs[r].push(i),n.structType=i}return i}getOutputStructTypeFromNode(e,t){const s=this.getStructTypeFromNode(e,t,"OutputType","fragment");return s.output=!0,s}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(i===void 0){const u=this.uniforms.index++;i=new Rl(r||"nodeUniform"+u,t,e),this.uniforms[s].push(i),this.registerDeclaration(i),n.uniform=i}return i}getArrayCount(e){let t=null;return e.isArrayNode?t=e.count:e.isVarNode&&e.node.isArrayNode&&(t=e.node.count),t}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage,n=!1){const i=this.getDataFromNode(e,r),u=this.getSubBuildProperty("variable",i.subBuilds);let a=i[u];if(a===void 0){const c=n?"_const":"_var",d=this.vars[r]||(this.vars[r]=[]),h=this.vars[c]||(this.vars[c]=0);t===null&&(t=(n?"nodeConst":"nodeVar")+h,this.vars[c]++),u!=="variable"&&(t=this.getSubBuildProperty(t,i.subBuilds));const p=this.getArrayCount(e);a=new xi(t,s,n,p),n||d.push(a),this.registerDeclaration(a),i[u]=a}return a}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0)&&(e.cNode?this.isDeterministic(e.cNode):!0);if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0);if(e.isArrayNode){if(e.values!==null){for(const t of e.values)if(!this.isDeterministic(t))return!1}return!0}else if(e.isConstNode)return!0;return!1}getVaryingFromNode(e,t=null,s=e.getNodeType(this),r=null,n=null){const i=this.getDataFromNode(e,"any"),u=this.getSubBuildProperty("varying",i.subBuilds);let a=i[u];if(a===void 0){const c=this.varyings,d=c.length;t===null&&(t="nodeVarying"+d),u!=="varying"&&(t=this.getSubBuildProperty(t,i.subBuilds)),a=new Al(t,s,r,n),c.push(a),this.registerDeclaration(a),i[u]=a}return a}registerDeclaration(e){const t=this.shaderStage,s=this.declarations[t]||(this.declarations[t]={}),r=this.getPropertyName(e);let n=1,i=r;for(;s[i]!==void 0;)i=r+"_"+n++;n>1&&(e.name=i,console.warn(`THREE.TSL: Declaration name '${r}' of '${e.type}' already in use. Renamed to '${i}'.`)),s[i]=e}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(n===void 0){const i=this.codes[s]||(this.codes[s]=[]),u=i.length;n=new Cl("nodeCode"+u,t),i.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(r.get(i)===!0){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const u of s)this.addLineFlowCode(u)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`;
|
|
31
31
|
`),this.flow.code+=e,this)}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}addInclude(e){this.currentFunctionNode!==null&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){const t=new fl,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let i=0;const u=Object.values(this);return{next:()=>({value:u[i],done:i++>=u.length})}}};for(const i of t.inputs)s[i.name]=new dl(i.type,i.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.declarations,i=this.cache,u=this.buildStage,a=this.stack,c={code:""};this.flow=c,this.vars={},this.declarations={},this.cache=new sr,this.stack=Kr();for(const d of pn)this.setBuildStage(d),c.result=e.build(this,t);return c.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.declarations=n,this.cache=i,this.stack=a,this.setBuildStage(u),c}getFunctionOperator(){return null}buildFunctionCode(){console.warn("Abstract function.")}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.tab,i=this.cache,u=this.shaderStage,a=this.context;this.setShaderStage(e);const c={...this.context};delete c.nodeBlock,this.cache=this.globalCache,this.tab=" ",this.context=c;let d=null;if(this.buildStage==="generate"){const h=this.flowChildNode(t,s);r!==null&&(h.code+=`${this.tab+r} = ${h.result};
|