1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9256],{39306:(e,t,r)=>{let i,s,n,a,o,l;r.d(t,{Z$U:()=>d3,uV1:()=>fL,uuE:()=>pG});var u=r(17693);let d=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class h{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=d,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}needsVelocity(e){let t=e.getMRT();return null!==t&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){let{geometry:r,material:i,object:s}=e;if(t={material:this.getMaterialData(i),geometry:{id:r.id,attributes:this.getAttributesData(r.attributes),indexVersion:r.index?r.index.version:null,drawRange:{start:r.drawRange.start,count:r.drawRange.count}},worldMatrix:s.matrixWorld.clone()},s.center&&(t.center=s.center.clone()),s.morphTargetInfluences&&(t.morphTargetInfluences=s.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){let{width:r,height:i}=e.context;t.bufferWidth=r,t.bufferHeight=i}this.renderObjects.set(e,t)}return t}getAttributesData(e){let t={};for(let r in e){let i=e[r];t[r]={version:i.version}}return t}containsNode(e){let t=e.material;for(let e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.overrideNodes.modelViewMatrix||null!==e.renderer.overrideNodes.modelNormalViewMatrix}getMaterialData(e){let t={};for(let r of this.refreshUniforms){let i=e[r];null!=i&&("object"==typeof i&&void 0!==i.clone?!0===i.isTexture?t[r]={id:i.id,version:i.version}:t[r]=i.clone():t[r]=i)}return t}equals(e){let{object:t,material:r,geometry:i}=e,s=this.getRenderObjectData(e);if(!0!==s.worldMatrix.equals(t.matrixWorld))return s.worldMatrix.copy(t.matrixWorld),!1;let n=s.material;for(let e in n){let t=n[e],i=r[e];if(void 0!==t.equals){if(!1===t.equals(i))return t.copy(i),!1}else if(!0===i.isTexture){if(t.id!==i.id||t.version!==i.version)return t.id=i.id,t.version=i.version,!1}else if(t!==i)return n[e]=i,!1}if(n.transmission>0){let{width:t,height:r}=e.context;if(s.bufferWidth!==t||s.bufferHeight!==r)return s.bufferWidth=t,s.bufferHeight=r,!1}let a=s.geometry,o=i.attributes,l=a.attributes,u=Object.keys(l),d=Object.keys(o);if(a.id!==i.id)return a.id=i.id,!1;if(u.length!==d.length)return s.geometry.attributes=this.getAttributesData(o),!1;for(let e of u){let t=l[e],r=o[e];if(void 0===r)return delete l[e],!1;if(t.version!==r.version)return t.version=r.version,!1}let h=i.index,c=a.indexVersion,p=h?h.version:null;if(c!==p)return a.indexVersion=p,!1;if(a.drawRange.start!==i.drawRange.start||a.drawRange.count!==i.drawRange.count)return a.drawRange.start=i.drawRange.start,a.drawRange.count=i.drawRange.count,!1;if(s.morphTargetInfluences){let e=!1;for(let r=0;r<s.morphTargetInfluences.length;r++)s.morphTargetInfluences[r]!==t.morphTargetInfluences[r]&&(e=!0);if(e)return!0}return s.center&&!1===s.center.equals(t.center)?s.center.copy(t.center):null!==e.bundle&&(s.version=e.bundle.version),!0}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||this.needsVelocity(t.renderer))return!0;let{renderId:r}=t;if(this.renderId!==r)return this.renderId=r,!0;let i=!0===e.object.static,s=null!==e.bundle&&!0===e.bundle.static&&this.getRenderObjectData(e).version===e.bundle.version;return!i&&!s&&!0!==this.equals(e)}}function c(e,t=0){let r=0xdeadbeef^t,i=0x41c6ce57^t;if(e instanceof Array)for(let t=0,s;t<e.length;t++)r=Math.imul(r^(s=e[t]),0x9e3779b1),i=Math.imul(i^s,0x5f356495);else for(let t=0,s;t<e.length;t++)r=Math.imul(r^(s=e.charCodeAt(t)),0x9e3779b1),i=Math.imul(i^s,0x5f356495);return r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(i^i>>>13,0xc2b2ae35),0x100000000*(2097151&(i=Math.imul(i^i>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35)))+(r>>>0)}let p=e=>c(e),g=e=>c(e),m=(...e)=>c(e);function f(e,t=!1){let r=[];for(let{property:i,childNode:s}of(!0===e.isNode&&(r.push(e.id),e=e.getSelf()),y(e)))r.push(c(i.slice(0,-4)),s.getCacheKey(t));return c(r)}function*y(e,t=!1){for(let r in e){if(!0===r.startsWith("_"))continue;let i=e[r];if(!0===Array.isArray(i))for(let e=0;e<i.length;e++){let s=i[e];s&&(!0===s.isNode||t&&"function"==typeof s.toJSON)&&(yield{property:r,index:e,childNode:s})}else if(i&&!0===i.isNode)yield{property:r,childNode:i};else if("object"==typeof i)for(let e in i){let s=i[e];s&&(!0===s.isNode||t&&"function"==typeof s.toJSON)&&(yield{property:r,index:e,childNode:s})}}}let x=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),b=new WeakMap;function T(e){if(/[iu]?vec\d/.test(e))return e.startsWith("ivec")?Int32Array:e.startsWith("uvec")?Uint32Array:Float32Array;
1if(/mat\d/.test(e)||/float/.test(e))return Float32Array;if(/uint/.test(e))return Uint32Array;if(/int/.test(e))return Int32Array;throw Error(`THREE.NodeUtils: Unsupported type: ${e}`)}function _(e){return/float|int|uint/.test(e)?1:/vec2/.test(e)?2:/vec3/.test(e)?3:/vec4/.test(e)||/mat2/.test(e)?4:/mat3/.test(e)?9:/mat4/.test(e)?16:void console.error("THREE.TSL: Unsupported type:",e)}function v(e){if(null==e)return null;let t=typeof e;if(!0===e.isNode)return"node";if("number"===t)return"float";if("boolean"===t)return"bool";if("string"===t)return"string";if("function"===t)return"shader";else if(!0===e.isVector2)return"vec2";else if(!0===e.isVector3)return"vec3";else if(!0===e.isVector4)return"vec4";else if(!0===e.isMatrix2)return"mat2";else if(!0===e.isMatrix3)return"mat3";else if(!0===e.isMatrix4)return"mat4";else if(!0===e.isColor)return"color";else if(e instanceof ArrayBuffer)return"ArrayBuffer";return null}function S(e,...t){let r=e?e.slice(-4):void 0;if(1===t.length&&("vec2"===r?t=[t[0],t[0]]:"vec3"===r?t=[t[0],t[0],t[0]]:"vec4"===r&&(t=[t[0],t[0],t[0],t[0]])),"color"===e)return new u.Q1f(...t);if("vec2"===r)return new u.I9Y(...t);if("vec3"===r)return new u.Pq0(...t);if("vec4"===r)return new u.IUQ(...t);if("mat2"===r)return new u.k_V(...t);else if("mat3"===r)return new u.dwI(...t);else if("mat4"===r)return new u.kn4(...t);else if("bool"===e)return t[0]||!1;else if("float"===e||"int"===e||"uint"===e)return t[0]||0;else if("string"===e)return t[0]||"";else if("ArrayBuffer"===e)return A(t[0]);return null}function N(e){let t=b.get(e);return void 0===t&&(t={},b.set(e,t)),t}function R(e){let t="",r=new Uint8Array(e);for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return btoa(t)}function A(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0)).buffer}let E={VERTEX:"vertex",FRAGMENT:"fragment"},w={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},C={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},M=["fragment","vertex"],B=["setup","analyze","generate"],P=[...M,"compute"],F=["x","y","z","w"],L=0;class U extends u.Qev{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=w.NONE,this.updateBeforeType=w.NONE,this.updateAfterType=w.NONE,this.uuid=u.cj9.generateUUID(),this.version=0,this.global=!1,this.parents=!1,this.isNode=!0,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:L++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,w.FRAME)}onRenderUpdate(e){return this.onUpdate(e,w.RENDER)}onObjectUpdate(e){return this.onUpdate(e,w.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(let{childNode:e}of y(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){for(let t of(e(this),this.getChildren()))t.traverse(e)}getCacheKey(e=!1){return(!0===(e=e||this.version!==this._cacheKeyVersion)||null===this._cacheKey)&&(this._cacheKey=m(f(this,e),this.customCacheKey()),this._cacheKeyVersion=this.version),this._cacheKey}customCacheKey(){return 0}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){let t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e){let t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){let t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){let t=e.getNodeProperties(this),r=0;for(let e of this.getChildren())t["node"+r++]=e;return t.outputNode||null}analyze(e){if(1===e.increaseUsage(this))for(let t of Object.values(e.getNodeProperties(this)))t&&!0===t.isNode&&t.build(e)}generate(e,t){let{outputNode:r}=e.getNodeProperties(this);if(r&&!0===r.isNode)return r.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){let r=this.getShared(e);if(this!==r)return r.build(e,t);e.addNode(this),e.addChain(this);let i=null,s=e.getBuildStage();if("setup"===s){this.updateReference(e);let t=e.getNodeProperties(this);if(!0!==t.initialized){t.initialized=!0;let r=this.setup(e),i=r&&!0===r.isNode;for(let r of Object.values(t))if(r&&!0===r.isNode){if(!0===r.parents){let t=e.getNodeProperties(r);t.parents=t.parents||[],t.parents.push(this)}r.build(e)}i&&r.build(e),t.outputNode=r}i=t.outputNode||null}else if("analyze"===s)this.analyze(e);else if("generate"===s)if(1===this.generate.length){let r=this.getNodeType(e),s=e.getDataFromNode(this);void 0===(i=s.snippet)?void 0===s.generated?(s.generated=!0,s.snippet=i=this.generate(e)||""):(console.warn("THREE.Node: Recursion detected.",this),i=""):void 0!==s.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),i=e.format(i,r,t)}else i=this.generate(e,t)||"";return e.removeChain(this),e.addSequentialNode(this),i}getSerializeChildren(){return y(this)}serialize(e){let t=this.getSerializeChildren(),r={};for(let{property:i,index:s,childNode:n}of t)void 0!==s?(void 0===r[i]&&(r[i]=Number.isInteger(s)?[]:{}),r[i][s]=n.toJSON(e.meta).uuid):r[i]=n.toJSON(e.meta).uuid;Object.keys(r).length>0&&(e.inputNodes=r)}deserialize(e){if(void 0!==e.inputNodes){let t=e.meta.nodes;for(let r in e.inputNodes)if(Array.isArray(e.inputNodes[r])){let i=[];for(let s of e.inputNodes[r])i.push(t[s]);this[r]=i}else if("object"==typeof e.inputNodes[r]){let i={};for(let s in e.inputNodes[r]){let n=e.inputNodes[r][s];i[s]=t[n]}this[r]=i}else{let i=e.inputNodes[r];this[r]=t[i]}}}toJSON(e){let{uuid:t,type:r}=this,i=void 0===e||"string"==typeof e;i&&(e={textures:{},images:{},nodes:{}});let s=e.nodes[t];function n(e){let t=[];for(let r in e){let i=e[r];delete i.metadata,t.push(i)}return t}if(void 0===s&&(s={uuid:t,type:r,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(e.nodes[s.uuid]=s),this.serialize(s),delete s.meta),i){let t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}}class I extends U{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){let t=this.indexNode.getNodeType(e),r=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${r}[ ${i} ]`}}class D extends U{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){let t=this.node.getNodeType(e),r=null;for(let i of this.convertTo.split("|"))(null===r||e.getTypeLength(t)===e.getTypeLength(i))&&(r=i);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){let r=this.node,i=this.getNodeType(e),s=r.build(e,i);return e.format(s,i,t)}}class V extends U{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){let r=e.getVectorType(this.getNodeType(e,t)),i=e.getDataFromNode(this);if(void 0!==i.propertyName)return e.format(i.propertyName,r,t);if("void"!==r&&"void"!==t&&this.hasDependencies(e)){let s=super.build(e,r),n=e.getVarFromNode(this,null,r),a=e.getPropertyName(n);return e.addLineFlowCode(`${a} = ${s}`,this),i.snippet=s,i.propertyName=a,e.format(i.propertyName,r,t)}}return super.build(e,t)}}class O extends V{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}
1getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){let r=this.getNodeType(e),i=e.getTypeLength(r),s=this.nodes,n=e.getComponentType(r),a=[],o=0;for(let t of s){let s;if(o>=i){console.error(`THREE.TSL: Length of parameters exceeds maximum length of function '${r}()' type.`);break}let l=t.getNodeType(e),u=e.getTypeLength(l);o+u>i&&(console.error(`THREE.TSL: Length of '${r}()' data exceeds maximum length of output type.`),u=i-o,l=e.getTypeFromLength(u)),o+=u,s=t.build(e,l);let d=e.getComponentType(l);d!==n&&(s=e.format(s,d,n)),a.push(s)}let l=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(l,r,t)}}let G=F.join("");class k extends U{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(let t of this.components)e=Math.max(F.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){let r=this.node,i=e.getTypeLength(r.getNodeType(e)),s=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));let a=r.build(e,n);s=this.components.length===i&&this.components===G.slice(0,this.components.length)?e.format(a,n,t):e.format(`${a}.${this.components}`,this.getNodeType(e),t)}else s=r.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class z extends V{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{sourceNode:t,components:r,targetNode:i}=this,s=this.getNodeType(e),n=e.getComponentType(i.getNodeType(e)),a=e.getTypeFromLength(r.length,n),o=i.build(e,a),l=t.build(e,s),u=e.getTypeLength(s),d=[];for(let e=0;e<u;e++){let t=F[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(l+"."+t)}return`${e.getType(s)}( ${d.join(", ")} )`}}class $ extends V{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{components:t,sourceNode:r}=this,i=this.getNodeType(e),s=r.build(e),n=e.getVarFromNode(this),a=e.getPropertyName(n);e.addLineFlowCode(a+" = "+s,this);let o=e.getTypeLength(i),l=[],u=0;for(let e=0;e<o;e++){let r=F[e];r===t[u]?(l.push("1.0 - "+a+"."+r),u++):l.push(a+"."+r)}return`${e.getType(i)}( ${l.join(", ")} )`}}class W extends U{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return null===this.nodeType?v(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=v(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=R(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?S(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){console.warn("Abstract function.")}}let H=/float|u?int/;class q extends W{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){let r=this.getNodeType(e);return H.test(r)&&H.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class j extends U{static get type(){return"MemberNode"}constructor(e,t){super(),this.node=e,this.property=t,this.isMemberNode=!0}getNodeType(e){return this.node.getMemberType(e,this.property)}generate(e){return this.node.build(e)+"."+this.property}}let X=null,Q=new Map;function Y(e,t){if(Q.has(e))return void console.warn(`THREE.TSL: Redefinition of method chaining '${e}'.`);if("function"!=typeof t)throw Error(`THREE.TSL: Node element ${e} is not a function`);Q.set(e,t)}let K=e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Z=e=>K(e).split("").sort().join(""),J={setup:(e,t)=>e(ev(t.shift()),...t),get(e,t,r){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(X.assign(r,...e),r);else if(Q.has(t)){let i=Q.get(t);return e.isStackNode?(...e)=>r.add(i(...e)):(...e)=>i(r,...e)}else if("self"===t)return e;else if(t.endsWith("Assign")&&Q.has(t.slice(0,t.length-6))){let i=Q.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>r.assign(e[0],i(...e)):(...e)=>r.assign(i(r,...e))}else if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return e_(new k(r,t=K(t)));else if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Z(t.slice(3).toLowerCase()),r=>e_(new z(e,t,r));else if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Z(t.slice(4).toLowerCase()),()=>e_(new $(e_(e),t));else if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),e_(new k(e,t));else if(!0===/^\d+$/.test(t))return e_(new I(r,new q(Number(t),"uint")));else if(!0===/^get$/.test(t))return e=>e_(new j(r,e))}return Reflect.get(e,t,r)}
1,set:(e,t,r,i)=>"string"==typeof t&&void 0===e[t]&&(!0===/^[xyzwrgbastpq]{1,4}$/.test(t)||"width"===t||"height"===t||"depth"===t||!0===/^\d+$/.test(t))?(i[t].assign(r),!0):Reflect.set(e,t,r,i)},ee=new WeakMap,et=new WeakMap,er=function(e,t=null){let r=v(e);if("node"===r){let t=ee.get(e);return void 0===t&&(t=new Proxy(e,J),ee.set(e,t),ee.set(t,t)),t}return null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?e_(ef(e,t)):"shader"===r?eE(e):e},ei=function(e,t=null){for(let r in e)e[r]=e_(e[r],t);return e},es=function(e,t=null){let r=e.length;for(let i=0;i<r;i++)e[i]=e_(e[i],t);return e},en=function(e,t=null,r=null,i=null){let s=e=>e_(null!==i?Object.assign(e,i):e),n,a=t,o,l;function u(t){let r;return(r=a?/[a-z]/i.test(a)?a+"()":a:e.type,void 0!==o&&t.length<o)?(console.error(`THREE.TSL: "${r}" parameter length is less than minimum required.`),t.concat(Array(o-t.length).fill(0))):void 0!==l&&t.length>l?(console.error(`THREE.TSL: "${r}" parameter length exceeds limit.`),t.slice(0,l)):t}return null===t?n=(...t)=>s(new e(...eS(u(t)))):null!==r?(r=e_(r),n=(...i)=>s(new e(t,...eS(u(i)),r))):n=(...r)=>s(new e(t,...eS(u(r)))),n.setParameterLength=(...e)=>(1===e.length?o=l=e[0]:2===e.length&&([o,l]=e),n),n.setName=e=>(a=e,n),n},ea=function(e,...t){return e_(new e(...eS(t)))};class eo extends U{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t,this.isShaderCallNodeInternal=!0}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){let{shaderNode:t,inputNodes:r}=this,i=e.getNodeProperties(t);if(i.onceOutput)return i.onceOutput;let s=null;if(t.layout){let i=et.get(e.constructor);void 0===i&&(i=new WeakMap,et.set(e.constructor,i));let n=i.get(t);void 0===n&&(n=e_(e.buildFunctionNode(t)),i.set(t,n)),e.addInclude(n),s=e_(n.call(r))}else{let i=t.jsFunc;s=e_(null!==r||i.length>1?i(r||[],e):i(e))}return t.once&&(i.onceOutput=s),s}getOutputNode(e){let t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class el extends U{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return ev(e),e_(new eo(this,e))}setup(){return this.call()}}let eu=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],ed=new Map;for(let e of[!1,!0])ed.set(e,new q(e));let eh=new Map;for(let e of[0,1,2,3])eh.set(e,new q(e,"uint"));let ec=new Map([...eh].map(e=>new q(e.value,"int")));for(let e of[-1,-2])ec.set(e,new q(e,"int"));let ep=new Map([...ec].map(e=>new q(e.value)));for(let e of eu)ep.set(e,new q(e));for(let e of eu)ep.set(-e,new q(-e));let eg={bool:ed,uint:eh,ints:ec,float:ep},em=new Map([...ed,...ep]),ef=(e,t)=>em.has(e)?em.get(e):!0===e.isNode?e:new q(e,t),ey=function(e,t=null){return(...r)=>{if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every(e=>"object"!=typeof e))&&(r=[S(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return e_(t.get(r[0]));if(1===r.length){let t=ef(r[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?e_(t):e_(new D(t,e))}return e_(new O(r.map(e=>ef(e)),e))}},ex=e=>"object"==typeof e&&null!==e?e.value:e,eb=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function eT(e,t){return new Proxy(new el(e,t),J)}let e_=(e,t=null)=>er(e,t),ev=(e,t=null)=>new ei(e,t),eS=(e,t=null)=>new es(e,t),eN=(...e)=>new en(...e),eR=(...e)=>new ea(...e),eA=0,eE=(e,t=null)=>{let r=null;null!==t&&("object"==typeof t?r=t.return:("string"==typeof t?r=t:console.error("THREE.TSL: Invalid layout type."),t=null));let i=new eT(e,r),s=(...e)=>{let t;ev(e),t=e[0]&&e[0].isNode?[...e]:e[0];let s=i.call(t);return"void"===r&&s.toStack(),s};if(s.shaderNode=i,s.setLayout=e=>(i.setLayout(e),s),s.once=()=>(i.once=!0,s),null!==t){if("object"!=typeof t.inputs){let e={name:"fn"+eA++,type:r,inputs:[]};for(let r in t)"return"!==r&&e.inputs.push({name:r,type:t[r]});t=e}s.setLayout(t)}return s};Y("toGlobal",e=>(e.global=!0,e));let ew=e=>{X=e}
1,eC=()=>X,eM=(...e)=>X.If(...e);function eB(e){return X&&X.add(e),e}Y("toStack",eB);let eP=new ey("color"),eF=new ey("float",eg.float),eL=new ey("int",eg.ints),eU=new ey("uint",eg.uint),eI=new ey("bool",eg.bool),eD=new ey("vec2"),eV=new ey("ivec2"),eO=new ey("uvec2"),eG=new ey("bvec2"),ek=new ey("vec3"),ez=new ey("ivec3"),e$=new ey("uvec3"),eW=new ey("bvec3"),eH=new ey("vec4"),eq=new ey("ivec4"),ej=new ey("uvec4"),eX=new ey("bvec4"),eQ=new ey("mat2"),eY=new ey("mat3"),eK=new ey("mat4");Y("toColor",eP),Y("toFloat",eF),Y("toInt",eL),Y("toUint",eU),Y("toBool",eI),Y("toVec2",eD),Y("toIVec2",eV),Y("toUVec2",eO),Y("toBVec2",eG),Y("toVec3",ek),Y("toIVec3",ez),Y("toUVec3",e$),Y("toBVec3",eW),Y("toVec4",eH),Y("toIVec4",eq),Y("toUVec4",ej),Y("toBVec4",eX),Y("toMat2",eQ),Y("toMat3",eY),Y("toMat4",eK);let eZ=eN(I).setParameterLength(2),eJ=(e,t)=>e_(new D(e_(e),t));Y("element",eZ),Y("convert",eJ),Y("append",e=>(console.warn("THREE.TSL: .append() has been renamed to .toStack()."),eB(e)));class e0 extends U{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1){super(e),this.name=t,this.varying=r,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name)).needsInterpolation=!0:t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}let e1=(e,t)=>e_(new e0(e,t)),e2=(e,t)=>e_(new e0(e,t,!0)),e3=eR(e0,"vec4","DiffuseColor"),e4=eR(e0,"vec3","EmissiveColor"),e6=eR(e0,"float","Roughness"),e8=eR(e0,"float","Metalness"),e5=eR(e0,"float","Clearcoat"),e9=eR(e0,"float","ClearcoatRoughness"),e7=eR(e0,"vec3","Sheen"),te=eR(e0,"float","SheenRoughness"),tt=eR(e0,"float","Iridescence"),tr=eR(e0,"float","IridescenceIOR"),ti=eR(e0,"float","IridescenceThickness"),ts=eR(e0,"float","AlphaT"),tn=eR(e0,"float","Anisotropy"),ta=eR(e0,"vec3","AnisotropyT"),to=eR(e0,"vec3","AnisotropyB"),tl=eR(e0,"color","SpecularColor"),tu=eR(e0,"float","SpecularF90"),td=eR(e0,"float","Shininess"),th=eR(e0,"vec4","Output"),tc=eR(e0,"float","dashSize"),tp=eR(e0,"float","gapSize"),tg=eR(e0,"float","pointWidth"),tm=eR(e0,"float","IOR"),tf=eR(e0,"float","Transmission"),ty=eR(e0,"float","Thickness"),tx=eR(e0,"float","AttenuationDistance"),tb=eR(e0,"color","AttenuationColor"),tT=eR(e0,"float","Dispersion");class t_ extends U{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1){super("string"),this.name=e,this.shared=t,this.order=r,this.isUniformGroup=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}let tv=e=>new t_(e),tS=(e,t=0)=>new t_(e,!0,t),tN=tS("frame"),tR=tS("render"),tA=tv("object");class tE extends W{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=tA}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}
1onUpdate(e,t){let r=this.getSelf();return e=e.bind(r),super.onUpdate(t=>{let i=e(t,r);void 0!==i&&(this.value=i)},t)}generate(e,t){let r=this.getNodeType(e),i=this.getUniformHash(e),s=e.getNodeFromHash(i);void 0===s&&(e.setHashNode(this,i),s=this);let n=s.getInputType(e),a=e.getUniformFromNode(s,n,e.shaderStage,this.name||e.context.label),o=e.getPropertyName(a);return void 0!==e.context.label&&delete e.context.label,e.format(o,r,t)}}let tw=(e,t)=>{let r=eb(t||e);return e_(new tE(e&&!0===e.isNode?e.node&&e.node.value||e.value:e,r))};class tC extends V{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getNodeType(e){return null===this.nodeType&&(this.nodeType=this.values[0].getNodeType(e)),this.nodeType}getElementType(e){return this.getNodeType(e)}generate(e){let t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}let tM=(...e)=>{let t;if(1===e.length){let r=e[0];t=new tC(null,r.length,r)}else t=new tC(e[0],e[1]);return e_(t)};Y("toArray",(e,t)=>tM(Array(t).fill(e)));class tB extends V{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){let{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){let r=e.getTypeLength(t.node.getNodeType(e));return F.join("").slice(0,r)!==t.components}return!1}generate(e,t){let r,{targetNode:i,sourceNode:s}=this,n=this.needsSplitAssign(e),a=i.getNodeType(e),o=i.context({assign:!0}).build(e),l=s.build(e,a),u=s.getNodeType(e),d=e.getDataFromNode(this);if(!0===d.initialized)"void"!==t&&(r=o);else if(n){let s=e.getVarFromNode(this,null,a),n=e.getPropertyName(s);e.addLineFlowCode(`${n} = ${l}`,this);let u=i.node.context({assign:!0}).build(e);for(let t=0;t<i.components.length;t++){let r=i.components[t];e.addLineFlowCode(`${u}.${r} = ${n}[ ${t} ]`,this)}"void"!==t&&(r=o)}else r=`${o} = ${l}`,("void"===t||"void"===u)&&(e.addLineFlowCode(r,this),"void"!==t&&(r=o));return d.initialized=!0,e.format(r,a,t)}}let tP=eN(tB).setParameterLength(2);Y("assign",tP);class tF extends V{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}generate(e){let t=[],r=this.functionNode,i=r.getInputs(e),s=this.parameters,n=(t,r)=>{let i=r.type;return"pointer"===i?"&"+t.build(e):t.build(e,i)};if(Array.isArray(s)){if(s.length>i.length)console.error("THREE.TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),s.length=i.length;else if(s.length<i.length)for(console.error("THREE.TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");s.length<i.length;)s.push(eF(0));for(let e=0;e<s.length;e++)t.push(n(s[e],i[e]))}else for(let e of i){let r=s[e.name];void 0!==r?t.push(n(r,e)):(console.error(`THREE.TSL: Input '${e.name}' not found in 'Fn()'.`),t.push(n(eF(0),e)))}let a=r.build(e,"property");return`${a}( ${t.join(", ")} )`}}let tL=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?eS(t):ev(t[0]),e_(new tF(e_(e),t)));Y("call",tL);let tU={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class tI extends V{static get type(){return"OperatorNode"}constructor(e,t,r,...i){if(super(),i.length>0){let s=new tI(e,t,r);for(let t=0;t<i.length-1;t++)s=new tI(e,s,i[t]);t=s,r=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(tU[this.op],t)}getNodeType(e){let t=this.op,r=this.aNode,i=this.bNode,s=r.getNodeType(e),n=void 0!==i?i.getNodeType(e):null;if("void"===s||"void"===n)return"void";if("%"===t)return s;if("~"===t||"&"===t||"|"===t||"^"===t||">>"===t||"<<"===t)return e.getIntegerType(s);if("!"===t||"&&"===t||"||"===t||"^^"===t)return"bool";if("=="===t||"!="===t||"<"===t||">"===t||"<="===t||">="===t){let t=Math.max(e.getTypeLength(s),e.getTypeLength(n));return t>1?`bvec${t}`:"bool"}else{if(e.isMatrix(s)){if("float"===n)return s;else if(e.isVector(n))return e.getVectorFromMatrix(s);else if(e.isMatrix(n))return s}else if(e.isMatrix(n)){if("float"===s)return n;else if(e.isVector(s))return e.getVectorFromMatrix(n)}return e.getTypeLength(n)>e.getTypeLength(s)?n:s}}generate(e,t){let r=this.op,i=this.aNode,s=this.bNode,n=this.getNodeType(e),a=null,o=null;"void"!==n?(a=i.getNodeType(e),o=void 0!==s?s.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r||"!="===r?e.isVector(a)?o=a:e.isVector(o)?a=o:a!==o&&(a=o="float"):">>"===r||"<<"===r?(a=n,o=e.changeComponentType(o,"uint")):"%"===r?(a=n,o=e.isInteger(a)&&e.isInteger(o)?o:a):e.isMatrix(a)?"float"===o?o="float":e.isVector(o)?o=e.getVectorFromMatrix(a):e.isMatrix(o)||(a=o=n):a=e.isMatrix(o)?"float"===a?"float":e.isVector(a)?e.getVectorFromMatrix(o):o=n:o=n):a=o=n;let l=i.build(e,a),d=void 0!==s?s.build(e,o):null,h=e.getFunctionOperator(r);if("void"!==t){let i=e.renderer.coordinateSystem===u.TdN;if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r)if(!i)return e.format(`( ${l} ${r} ${d} )`,n,t);else if(e.isVector(a))return e.format(`${this.getOperatorMethod(e,t)}( ${l}, ${d} )`,n,t);else return e.format(`( ${l} ${r} ${d} )`,n,t);if("%"===r)if(e.isInteger(o))return e.format(`( ${l} % ${d} )`,n,t);else return e.format(`${this.getOperatorMethod(e,n)}( ${l}, ${d} )`,n,t);{if("!"===r||"~"===r)return e.format(`(${r}${l})`,a,t);if(h)return e.format(`${h}( ${l}, ${d} )`,n,t);if(e.isMatrix(a)&&"float"===o)return e.format(`( ${d} ${r} ${l} )`,n,t);if("float"===a&&e.isMatrix(o))return e.format(`${l} ${r} ${d}`,n,t);let s=`( ${l} ${r} ${d} )`;return!i&&"bool"===n&&e.isVector(a)&&e.isVector(o)&&(s=`all${s}`),e.format(s,n,t)}}if("void"!==a)if(h)return e.format(`${h}( ${l}, ${d} )`,n,t);else if(e.isMatrix(a)&&"float"===o)return e.format(`${d} ${r} ${l}`,n,t);else return e.format(`${l} ${r} ${d}`,n,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}let tD=eN(tI,"+").setParameterLength(2,1/0).setName("add"),tV=eN(tI,"-").setParameterLength(2,1/0).setName("sub"),tO=eN(tI,"*").setParameterLength(2,1/0).setName("mul"),tG=eN(tI,"/").setParameterLength(2,1/0).setName("div"),tk=eN(tI,"%").setParameterLength(2).setName("mod"),tz=eN(tI,"==").setParameterLength(2).setName("equal"),t$=eN(tI,"!=").setParameterLength(2).setName("notEqual"),tW=eN(tI,"<").setParameterLength(2).setName("lessThan"),tH=eN(tI,">").setParameterLength(2).setName("greaterThan"),tq=eN(tI,"<=").setParameterLength(2).setName("lessThanEqual"),tj=eN(tI,">=").setParameterLength(2).setName("greaterThanEqual"),tX=eN(tI,"&&").setParameterLength(2,1/0).setName("and"),tQ=eN(tI,"||").setParameterLength(2,1/0).setName("or"),tY=eN(tI,"!").setParameterLength(1).setName("not"),tK=eN(tI,"^^").setParameterLength(2).setName("xor"),tZ=eN(tI,"&").setParameterLength(2).setName("bitAnd"),tJ=eN(tI,"~").setParameterLength(2).setName("bitNot"),t0=eN(tI,"|").setParameterLength(2).setName("bitOr"),t1=eN(tI,"^").setParameterLength(2).setName("bitXor"),t2=eN(tI,"<<").setParameterLength(2).setName("shiftLeft"),t3=eN(tI,">>").setParameterLength(2).setName("shiftRight"),t4=eE(([e])=>(e.addAssign(1),e)),t6=eE(([e])=>(e.subAssign(1),e)),t8=eE(([e])=>{let t=eL(e).toConst();return e.addAssign(1),t}),t5=eE(([e])=>{let t=eL(e).toConst();return e.subAssign(1),t});
1Y("add",tD),Y("sub",tV),Y("mul",tO),Y("div",tG),Y("mod",tk),Y("equal",tz),Y("notEqual",t$),Y("lessThan",tW),Y("greaterThan",tH),Y("lessThanEqual",tq),Y("greaterThanEqual",tj),Y("and",tX),Y("or",tQ),Y("not",tY),Y("xor",tK),Y("bitAnd",tZ),Y("bitNot",tJ),Y("bitOr",t0),Y("bitXor",t1),Y("shiftLeft",t2),Y("shiftRight",t3),Y("incrementBefore",t4),Y("decrementBefore",t6),Y("increment",t8),Y("decrement",t5);let t9=(e,t)=>(console.warn('THREE.TSL: "remainder()" is deprecated. Use "mod( int( ... ) )" instead.'),tk(e,t)),t7=(e,t)=>(console.warn('THREE.TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.'),tk(eL(e),eL(t)));Y("remainder",t9),Y("modInt",t7);class re extends V{static get type(){return"MathNode"}constructor(e,t,r=null,i=null){if(super(),(e===re.MAX||e===re.MIN)&&arguments.length>3){let s=new re(e,t,r);for(let t=2;t<arguments.length-1;t++)s=new re(e,s,arguments[t]);t=s,r=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=r,this.cNode=i,this.isMathNode=!0}getInputType(e){let t=this.aNode.getNodeType(e),r=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,s=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(r)?0:e.getTypeLength(r),a=e.isMatrix(i)?0:e.getTypeLength(i);if(s>n&&s>a);else if(n>a)return r;else if(a>s)return i;return t}getNodeType(e){let t=this.method;return t===re.LENGTH||t===re.DISTANCE||t===re.DOT?"float":t===re.CROSS?"vec3":t===re.ALL||t===re.ANY?"bool":t===re.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}generate(e,t){let r=this.method,i=this.getNodeType(e),s=this.getInputType(e),n=this.aNode,a=this.bNode,o=this.cNode,l=e.renderer.coordinateSystem;if(r===re.TRANSFORM_DIRECTION){let r=n,i=a;return e.isMatrix(r.getNodeType(e))?i=eH(ek(i),0):r=eH(ek(r),0),ry(tO(r,i).xyz).build(e,t)}{if(r===re.NEGATE)return e.format("( - "+n.build(e,s)+" )",i,t);if(r===re.ONE_MINUS)return tV(1,n).build(e,t);if(r===re.RECIPROCAL)return tG(1,n).build(e,t);if(r===re.DIFFERENCE)return rR(tV(n,a)).build(e,t);let d=[];return r===re.CROSS?d.push(n.build(e,i),a.build(e,i)):l===u.TdN&&r===re.STEP?d.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":s),a.build(e,s)):l===u.TdN&&(r===re.MIN||r===re.MAX)?d.push(n.build(e,s),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":s)):r===re.REFRACT?d.push(n.build(e,s),a.build(e,s),o.build(e,"float")):r===re.MIX?d.push(n.build(e,s),a.build(e,s),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":s)):(l===u.i7u&&r===re.ATAN&&null!==a&&(r="atan2"),"fragment"!==e.shaderStage&&(r===re.DFDX||r===re.DFDY)&&(console.warn(`THREE.TSL: '${r}' is not supported in the ${e.shaderStage} stage.`),r="/*"+r+"*/"),d.push(n.build(e,s)),null!==a&&d.push(a.build(e,s)),null!==o&&d.push(o.build(e,s))),e.format(`${e.getMethod(r,i)}( ${d.join(", ")} )`,i,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}re.ALL="all",re.ANY="any",re.RADIANS="radians",re.DEGREES="degrees",re.EXP="exp",re.EXP2="exp2",re.LOG="log",re.LOG2="log2",re.SQRT="sqrt",re.INVERSE_SQRT="inversesqrt",re.FLOOR="floor",re.CEIL="ceil",re.NORMALIZE="normalize",re.FRACT="fract",re.SIN="sin",re.COS="cos",re.TAN="tan",re.ASIN="asin",re.ACOS="acos",re.ATAN="atan",re.ABS="abs",re.SIGN="sign",re.LENGTH="length",re.NEGATE="negate",re.ONE_MINUS="oneMinus",re.DFDX="dFdx",re.DFDY="dFdy",re.ROUND="round",re.RECIPROCAL="reciprocal",re.TRUNC="trunc",re.FWIDTH="fwidth",re.TRANSPOSE="transpose",re.BITCAST="bitcast",re.EQUALS="equals",re.MIN="min",re.MAX="max",re.STEP="step",re.REFLECT="reflect",re.DISTANCE="distance",re.DIFFERENCE="difference",re.DOT="dot",re.CROSS="cross",re.POW="pow",re.TRANSFORM_DIRECTION="transformDirection",re.MIX="mix",re.CLAMP="clamp",re.REFRACT="refract",re.SMOOTHSTEP="smoothstep",re.FACEFORWARD="faceforward";let rt=eF(1e-6),rr=eF(1e6),ri=eF(Math.PI),rs=eF(2*Math.PI),rn=eN(re,re.ALL).setParameterLength(1),ra=eN(re,re.ANY).setParameterLength(1),ro=eN(re,re.RADIANS).setParameterLength(1),rl=eN(re,re.DEGREES).setParameterLength(1),ru=eN(re,re.EXP).setParameterLength(1),rd=eN(re,re.EXP2).setParameterLength(1),rh=eN(re,re.LOG).setParameterLength(1),rc=eN(re,re.LOG2).setParameterLength(1),rp=eN(re,re.SQRT).setParameterLength(1),rg=eN(re,re.INVERSE_SQRT).setParameterLength(1),rm=eN(re,re.FLOOR).setParameterLength(1),rf=eN(re,re.CEIL).setParameterLength(1),ry=eN(re,re.NORMALIZE).setParameterLength(1),rx=eN(re,re.FRACT).setParameterLength(1),rb=eN(re,re.SIN).setParameterLength(1),rT=eN(re,re.COS).setParameterLength(1),r_=eN(re,re.TAN).setParameterLength(1),rv=eN(re,re.ASIN).setParameterLength(1),rS=eN(re,re.ACOS).setParameterLength(1),rN=eN(re,re.ATAN).setParameterLength(1,2),rR=eN(re,re.ABS).setParameterLength(1),rA=eN(re,re.SIGN).setParameterLength(1),rE=eN(re,re.LENGTH).setParameterLength(1),rw=eN(re,re.NEGATE).setParameterLength(1),rC=eN(re,re.ONE_MINUS).setParameterLength(1),rM=eN(re,re.DFDX).setParameterLength(1),rB=eN(re,re.DFDY).setParameterLength(1),rP=eN(re,re.ROUND).setParameterLength(1),rF=eN(re,re.RECIPROCAL).setParameterLength(1),rL=eN(re,re.TRUNC).setParameterLength(1),rU=eN(re,re.FWIDTH).setParameterLength(1),rI=eN(re,re.TRANSPOSE).setParameterLength(1),rD=eN(re,re.BITCAST).setParameterLength(2),rV=(e,t)=>(console.warn('THREE.TSL: "equals" is deprecated. Use "equal" inside a vector instead, like: "bvec*( equal( ... ) )"'),tz(e,t)),rO=eN(re,re.MIN).setParameterLength(2,1/0),rG=eN(re,re.MAX).setParameterLength(2,1/0),rk=eN(re,re.STEP).setParameterLength(2),rz=eN(re,re.REFLECT).setParameterLength(2),r$=eN(re,re.DISTANCE).setParameterLength(2),rW=eN(re,re.DIFFERENCE).setParameterLength(2),rH=eN(re,re.DOT).setParameterLength(2),rq=eN(re,re.CROSS).setParameterLength(2),rj=eN(re,re.POW).setParameterLength(2),rX=eN(re,re.POW,2).setParameterLength(1),rQ=eN(re,re.POW,3).setParameterLength(1),rY=eN(re,re.POW,4).setParameterLength(1),rK=eN(re,re.TRANSFORM_DIRECTION).setParameterLength(2),rZ=e=>tO(rA(e),rj(rR(e),1/3)),rJ=e=>rH(e,e),r0=eN(re,re.MIX).setParameterLength(3),r1=(e,t=0,r=1)=>e_(new re(re.CLAMP,e_(e),e_(t),e_(r))),r2=e=>r1(e),r3=eN(re,re.REFRACT).setParameterLength(3),r4=eN(re,re.SMOOTHSTEP).setParameterLength(3),r6=eN(re,re.FACEFORWARD).setParameterLength(3),r8=eE(([e])=>rx(rb(tk(rH(e.xy,eD(12.9898,78.233)),ri)).mul(43758.5453))),r5=(e,t,r)=>r0(t,r,e),r9=(e,t,r)=>r4(t,r,e),r7=(e,t)=>(console.warn('THREE.TSL: "atan2" is overloaded. Use "atan" instead.'),rN(e,t));Y("all",rn),Y("any",ra),Y("equals",rV),Y("radians",ro),Y("degrees",rl),Y("exp",ru),Y("exp2",rd),Y("log",rh),Y("log2",rc),Y("sqrt",rp),Y("inverseSqrt",rg),Y("floor",rm),Y("ceil",rf),Y("normalize",ry),Y("fract",rx),Y("sin",rb),Y("cos",rT),Y("tan",r_),Y("asin",rv),Y("acos",rS),Y("atan",rN),Y("abs",rR),Y("sign",rA),Y("length",rE),Y("lengthSq",rJ),Y("negate",rw
1),Y("oneMinus",rC),Y("dFdx",rM),Y("dFdy",rB),Y("round",rP),Y("reciprocal",rF),Y("trunc",rL),Y("fwidth",rU),Y("atan2",r7),Y("min",rO),Y("max",rG),Y("step",rk),Y("reflect",rz),Y("distance",r$),Y("dot",rH),Y("cross",rq),Y("pow",rj),Y("pow2",rX),Y("pow3",rQ),Y("pow4",rY),Y("transformDirection",rK),Y("mix",r5),Y("clamp",r1),Y("refract",r3),Y("smoothstep",r9),Y("faceForward",r6),Y("difference",rW),Y("saturate",r2),Y("cbrt",rZ),Y("transpose",rI),Y("rand",r8);class ie extends U{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}getNodeType(e){let{ifNode:t,elseNode:r}=e.getNodeProperties(this);if(void 0===t)return this.setup(e),this.getNodeType(e);let i=t.getNodeType(e);if(null!==r){let t=r.getNodeType(e);if(e.getTypeLength(t)>e.getTypeLength(i))return t}return i}setup(e){let t=this.condNode.cache(),r=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,s=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=s,null!==i&&(e.getDataFromNode(i).parentNodeBlock=s);let n=e.getNodeProperties(this);n.condNode=t,n.ifNode=r.context({nodeBlock:r}),n.elseNode=i?i.context({nodeBlock:i}):null}generate(e,t){let r=this.getNodeType(e),i=e.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;let{condNode:s,ifNode:n,elseNode:a}=e.getNodeProperties(this),o=e.currentFunctionNode,l="void"!==t,u=l?e1(r).build(e):"";i.nodeProperty=u;let d=s.build(e,"bool");e.addFlowCode(` 2${e.tab}if ( ${d} ) { 3 4`).addFlowTab();let h=n.build(e,r);if(h&&(l?h=u+" = "+h+";":(h="return "+h+";",null===o&&(console.warn("THREE.TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values."),h="// "+h))),e.removeFlowTab().addFlowCode(e.tab+" "+h+"\n\n"+e.tab+"}"),null!==a){e.addFlowCode(" else {\n\n").addFlowTab();let t=a.build(e,r);t&&(l?t=u+" = "+t+";":(t="return "+t+";",null===o&&(console.warn("THREE.TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values."),t="// "+t))),e.removeFlowTab().addFlowCode(e.tab+" "+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,r,t)}}let it=eN(ie).setParameterLength(2,3);Y("select",it);let ir=(...e)=>(console.warn("THREE.TSL: cond() has been renamed to select()."),it(...e));Y("cond",ir);class ii extends U{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){let t=e.getContext();e.setContext({...e.context,...this.value});let r=this.node.build(e);return e.setContext(t),r}generate(e,t){let r=e.getContext();e.setContext({...e.context,...this.value});let i=this.node.build(e,t);return e.setContext(r),i}}let is=eN(ii).setParameterLength(1,2),ia=(e,t)=>is(e,{label:t});Y("context",is),Y("label",ia);class io extends U{static get type(){return"VarNode"}constructor(e,t=null,r=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=r}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){let{node:t,name:r,readOnly:i}=this,{renderer:s}=e,n=!0===s.backend.isWebGPUBackend,a=!1,o=!1;i&&(a=e.isDeterministic(t),o=n?i:a);let l=e.getVectorType(this.getNodeType(e)),u=t.build(e,l),d=e.getVarFromNode(this,r,l,void 0,o),h=e.getPropertyName(d),c=h;if(o)if(n)c=a?`const ${h}`:`let ${h}`;else{let r=e.getArrayCount(t);c=`const ${e.getVar(d.type,h,r)}`}return e.addLineFlowCode(`${c} = ${u}`,this),h}}let il=eN(io),iu=(e,t=null)=>il(e,t).toStack(),id=(e,t=null)=>il(e,t,!0).toStack();Y("toVar",iu),Y("toConst",id);let ih=e=>(console.warn('TSL: "temp( node )" is deprecated. Use "Var( node )" or "node.toVar()" instead.'),il(e));Y("temp",ih);class ic extends U{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null}isGlobal(){return!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){let t=e.getNodeProperties(this),r=t.varying;if(void 0===r){let i=this.name,s=this.getNodeType(e),n=this.interpolationType,a=this.interpolationSampling;t.varying=r=e.getVaryingFromNode(this,i,s,n,a),t.node=this.node}return r.needsInterpolation||(r.needsInterpolation="fragment"===e.shaderStage),r}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){let t=e.getNodeProperties(this),r=this.setupVarying(e),i="fragment"===e.shaderStage&&!0===t.reassignPosition&&e.context.needsPositionReassign;if(void 0===t.propertyName||i){let s=this.getNodeType(e),n=e.getPropertyName(r,E.VERTEX);e.flowNodeFromShaderStage(E.VERTEX,this.node,s,n),t.propertyName=n,i?t.reassignPosition=!1:void 0===t.reassignPosition&&e.context.
4isPositionNodeInput&&(t.reassignPosition=!0)}return e.getPropertyName(r)}}let ip=eN(ic).setParameterLength(1,2),ig=e=>ip(e);Y("toVarying",ip),Y("toVertexStage",ig),Y("varying",(...e)=>(console.warn("THREE.TSL: .varying() has been renamed to .toVarying()."),ip(...e))),Y("vertexStage",(...e)=>(console.warn("THREE.TSL: .vertexStage() has been renamed to .toVertexStage()."),ip(...e)));let im=eE(([e])=>{let t=e.mul(.9478672986).add(.0521327014).pow(2.4);return r0(t,e.mul(.0773993808),e.lessThanEqual(.04045))}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),iy=eE(([e])=>{let t=e.pow(.41666).mul(1.055).sub(.055);return r0(t,e.mul(12.92),e.lessThanEqual(.0031308))}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),ix="WorkingColorSpace",ib="OutputColorSpace";class iT extends V{static get type(){return"ColorSpaceNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.source=t,this.target=r}resolveColorSpace(e,t){return t===ix?u.ppV.workingColorSpace:t===ib?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){let{colorNode:t}=this,r=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target),s=t;return!1!==u.ppV.enabled&&r!==i&&r&&i&&(u.ppV.getTransfer(r)===u.KLL&&(s=eH(im(s.rgb),s.a)),u.ppV.getPrimaries(r)!==u.ppV.getPrimaries(i)&&(s=eH(eY(u.ppV._getMatrix(new u.dwI,r,i)).mul(s.rgb),s.a)),u.ppV.getTransfer(i)===u.KLL&&(s=eH(iy(s.rgb),s.a))),s}}let i_=e=>e_(new iT(e_(e),ix,ib)),iv=e=>e_(new iT(e_(e),ib,ix)),iS=(e,t)=>e_(new iT(e_(e),ix,t)),iN=(e,t)=>e_(new iT(e_(e),t,ix));Y("toOutputColorSpace",i_),Y("toWorkingColorSpace",iv),Y("workingToColorSpace",iS),Y("colorSpaceToWorking",iN);let iR=class extends I{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,r,i)}};class iA extends U{static get type(){return"ReferenceBaseNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.updateType=w.OBJECT}setGroup(e){return this.group=e,this}element(e){return e_(new iR(this,e_(e)))}setNodeType(e){let t=tw(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let e=1;e<t.length;e++)r=r[t[e]];return r}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}class iE extends iA{static get type(){return"RendererReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.renderer=r,this.setGroup(tR)}updateReference(e){return this.reference=null!==this.renderer?this.renderer:e.renderer,this.reference}}let iw=(e,t,r=null)=>e_(new iE(e,t,r));class iC extends V{static get type(){return"ToneMappingNode"}constructor(e,t=iB,r=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=r}customCacheKey(){return m(this.toneMapping)}setup(e){let t=this.colorNode||e.context.color,r=this.toneMapping;if(r===u.y_p)return t;let i=null,s=e.renderer.library.getToneMappingFunction(r);return null!==s?i=eH(s(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",r),i=t),i}}let iM=(e,t,r)=>e_(new iC(e,e_(t),e_(r))),iB=iw("toneMappingExposure","float");Y("toneMapping",(e,t,r)=>iM(t,r,e));class iP extends W{static get type(){return"BufferAttributeNode"}constructor(e,t=null,r=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=r,this.bufferOffset=i,this.usage=u.agE,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;let t=this.getNodeType(e),r=this.value,i=e.getTypeLength(t),s=this.bufferStride||i,n=this.bufferOffset,a=!0===r.isInterleavedBuffer?r:new u.eB$(r,s),o=new u.eHs(a,i,n);a.setUsage(this.usage),this.attribute=o,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){let t=this.getNodeType(e),r=e.getBufferAttributeFromNode(this,t),i=e.getPropertyName(r),s=null;return"vertex"===e.shaderStage||"compute"===e.shaderStage?(this.name=i,s=i):s=ip(this).build(e,t),s}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}let iF=(e,t=null,r=0,i=0)=>
4e_(new iP(e,t,r,i)),iL=(e,t=null,r=0,i=0)=>iF(e,t,r,i).setUsage(u.Vnu),iU=(e,t=null,r=0,i=0)=>iF(e,t,r,i).setInstanced(!0),iI=(e,t=null,r=0,i=0)=>iL(e,t,r,i).setInstanced(!0);Y("toAttribute",e=>iF(e.value));class iD extends U{static get type(){return"ComputeNode"}constructor(e,t,r=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=r,this.dispatchCount=0,this.version=1,this.name="",this.updateBeforeType=w.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}label(e){return this.name=e,this}updateDispatchCount(){let{count:e,workgroupSize:t}=this,r=t[0];for(let e=1;e<t.length;e++)r*=t[e];this.dispatchCount=Math.ceil(e/r)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){let t=this.computeNode.build(e);return t&&(e.getNodeProperties(this).outputComputeNode=t.outputNode,t.outputNode=null),t}generate(e,t){let{shaderStage:r}=e;if("compute"===r){let t=this.computeNode.build(e,"void");""!==t&&e.addLineFlowCode(t,this)}else{let r=e.getNodeProperties(this).outputComputeNode;if(r)return r.build(e,t)}}}let iV=(e,t,r)=>e_(new iD(e_(e),t,r));Y("compute",iV);class iO extends U{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){let t=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);let i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){let r=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);let s=this.node.build(e,...t);return e.setCache(r),s}}let iG=(e,t)=>e_(new iO(e_(e),t));Y("cache",iG);class ik extends U{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){let t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}let iz=eN(ik).setParameterLength(2);Y("bypass",iz);class i$ extends U{static get type(){return"RemapNode"}constructor(e,t,r,i=eF(0),s=eF(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=r,this.outLowNode=i,this.outHighNode=s,this.doClamp=!0}setup(){let{node:e,inLowNode:t,inHighNode:r,outLowNode:i,outHighNode:s,doClamp:n}=this,a=e.sub(t).div(r.sub(t));return!0===n&&(a=a.clamp()),a.mul(s.sub(i)).add(i)}}let iW=eN(i$,null,null,{doClamp:!1}).setParameterLength(3,5),iH=eN(i$).setParameterLength(3,5);Y("remap",iW),Y("remapClamp",iH);class iq extends U{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){let r=this.getNodeType(e),i=this.snippet;if("void"!==r)return e.format(i,r,t);e.addLineFlowCode(i,this)}}let ij=eN(iq).setParameterLength(1,2),iX=e=>(e?it(e,ij("discard")):ij("discard")).toStack();Y("discard",iX);class iQ extends V{static get type(){return"RenderOutputNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=r,this.isRenderOutputNode=!0}setup({context:e}){let t=this.colorNode||e.color,r=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||u.y_p,i=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||u.jf0;return r!==u.y_p&&(t=t.toneMapping(r)),i!==u.jf0&&i!==u.ppV.workingColorSpace&&(t=t.workingToColorSpace(i)),t}}let iY=(e,t=null,r=null)=>e_(new iQ(e_(e),t,r));Y("renderOutput",iY);class iK extends V{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}getNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){let t=this.callback,r=this.node.build(e),i="--- TSL debug - "+e.shaderStage+" shader ---",s="-".repeat(i.length),n="";return n+="// #"+i+"#\n"+e.flow.code.replace(/^\t/mg,"")+"\n"+("/* ... */ "+r)+" /* ... */\n"+("// #"+s)+"#\n",null!==t?t(e,n):console.log(n),r}}let iZ=(e,t=null)=>e_(new iK(e_(e),t));Y("debug",iZ);class iJ extends U{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){let r=this.getAttributeName(e);
4if(e.hasGeometryAttribute(r)){let i=e.geometry.getAttribute(r);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){let t=this.getAttributeName(e),r=this.getNodeType(e);if(!0!==e.hasGeometryAttribute(t))return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(r);{let i=e.geometry.getAttribute(t),s=e.getTypeFromAttribute(i),n=e.getAttribute(t,s);return"vertex"===e.shaderStage?e.format(n.name,s,r):ip(this).build(e,r)}}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}let i0=(e,t=null)=>e_(new iJ(e,t)),i1=(e=0)=>i0("uv"+(e>0?e:""),"vec2");class i2 extends U{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){let r=this.textureNode.build(e,"property"),i=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${r}, ${i} )`,this.getNodeType(e),t)}}let i3=eN(i2).setParameterLength(1,2);class i4 extends tE{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=w.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){let e=this.texture,t=e.images,r=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(r&&void 0!==r.width){let{width:e,height:t}=r;this.value=Math.log2(Math.max(e,t))}}}let i6=eN(i4).setParameterLength(1);class i8 extends tE{static get type(){return"TextureNode"}constructor(e,t=null,r=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=r,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=w.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===u.bkx?"uvec4":this.value.type===u.Yuy?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return i1(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=tw(this.value.matrix)),this._matrixUniform.mul(ek(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?w.OBJECT:w.NONE,this}setupUV(e,t){let r=this.value;return e.isFlipY()&&(r.image instanceof ImageBitmap&&!0===r.flipY||!0===r.isRenderTargetTexture||!0===r.isFramebufferTexture||!0===r.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(eL(i3(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){let t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let r=this.value;if(!r||!0!==r.isTexture)throw Error("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().");let i=this.uvNode;(null===i||!0===e.context.forceUVContext)&&e.context.getUV&&(i=e.context.getUV(this,e)),i||(i=this.getDefaultUV()),!0===this.updateMatrix&&(i=this.getTransformedUV(i)),i=this.setupUV(e,i);let s=this.levelNode;null===s&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this)),t.uvNode=i,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,r,i,s,n,a,o){let l=this.value;return i?e.generateTextureLevel(l,t,r,i,n):s?e.generateTextureBias(l,t,r,s,n):o?e.generateTextureGrad(l,t,r,o,n):a?e.generateTextureCompare(l,t,r,a,n):!1===this.sampler?e.generateTextureLoad(l,t,r,n):e.generateTexture(l,t,r,n)}generate(e,t){let r=this.value,i=e.getNodeProperties(this),s=super.generate(e,"property");if(/^sampler/.test(t))return s+"_sampler";{if(e.isReference(t))return s;let n=e.getDataFromNode(this),a=n.propertyName;if(void 0===a){let{uvNode:t,levelNode:r,biasNode:o,compareNode:l,depthNode:u,gradNode:d}=i,h=this.generateUV(e,t),c=r?r.build(e,"float"):null,p=o?o.build(e,"float"):null,g=u?u.build(e,"int"):null,m=l?l.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);a=e.getPropertyName(y);let x=this.generateSnippet(e,s,h,c,p,g,m,f);e.addLineFlowCode(`${a} = ${x}`,this),n.snippet=x,n.propertyName=a}let o=a,l=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(o=iN(ij(o,l),r.colorSpace).setup(e).build(e,l)),e.format(o,l,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){return console.warn("THREE.TextureNode: .uv() has been renamed. Use .sample() instead."),this.sample(e)}sample(e){let t=this.clone();return t.uvNode=e_(e),t.referenceNode=this.getSelf(),e_(t)}blur(e){let t=this.clone();t.biasNode=e_(e).mul(i6(t)),t.referenceNode=this.getSelf();let r=t.value;return!1===t.generateMipmaps&&(r&&!1===r.generateMipmaps||r.minFilter===u.hxR||r.magFilter===u.hxR)&&(console.warn("THREE.TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),e_(t)}level(e){let t=this.clone();return t.levelNode=e_(e),t.referenceNode=this.getSelf(),e_(t)}size(e){return i3(this,e)}bias(e){let t=this.clone();return t.biasNode=e_(e),t.referenceNode=this.getSelf(),e_(t)}compare(e){let t=this.clone();return t.compareNode=e_(e),t.referenceNode=this.getSelf(),e_(t)}grad(e,t){let r=this.clone();return r.gradNode=[e_(e),e_(t)],r.referenceNode=this.getSelf(),e_(r)}depth(e){let t=this.clone();return t.depthNode=e_(e),t.referenceNode=this.getSelf(),e_(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){let e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){let e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e}}let i5=eN(i8).setParameterLength(1,4),i9=(...e)=>i5(...e).setSampler(!1);class i7 extends tE{static get type(){return"BufferNode"}constructor(e,t,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=r}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}let se=(e,t,r)=>e_(new i7(e,t,r));class st extends I{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){let t=super.generate(e),r=this.getNodeType(),i=this.node.getPaddedType();return e.format(t,i,r)}}class sr extends i7{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=null===t?v(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=w.RENDER,this.isArrayBufferNode=!0}getNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){let e=this.elementType,t="vec4";return"mat2"===e?t="mat2":!0===/mat/.test(e)?t="mat4":"i"===e.charAt(0)?t="ivec4":"u"===e.charAt(0)&&(t="uvec4"),t}update(){let{array:e,value:t}=this,r=this.elementType;if("float"===r||"int"===r||"uint"===r)for(let r=0;r<e.length;r++)t[4*r]=e[r];else if("color"===r)for(let r=0;r<e.length;r++){let i=4*r,s=e[r];t[i]=s.r,t[i+1]=s.g,t[i+2]=s.b||0}else if("mat2"===r)for(let r=0;r<e.length;r++){let i=4*r,s=e[r];t[i]=s.elements[0],t[i+1]=s.elements[1],t[i+2]=s.elements[2],t[i+3]=s.elements[3]}else if("mat3"===r)for(let r=0;r<e.length;r++){let i=16*r,s=e[r];t[i]=s.elements[0],t[i+1]=s.elements[1],t[i+2]=s.elements[2],t[i+4]=s.elements[3],t[i+5]=s.elements[4],t[i+6]=s.elements[5],t[i+8]=s.elements[6],t[i+9]=s.elements[7],t[i+10]=s.elements[8],t[i+15]=1}else if("mat4"===r)for(let r=0;r<e.length;r++){let i=16*r,s=e[r];for(let e=0;e<s.elements.length;e++)t[i+e]=s.elements[e]}else for(let r=0;r<e.length;r++){let i=4*r,s=e[r];t[i]=s.x,t[i+1]=s.y,t[i+2]=s.z||0,t[i+3]=s.w||0}}setup(e){let t=this.array.length,r=this.elementType,i=Float32Array,s=this.paddedType,n=e.getTypeLength(s);return"i"===r.charAt(0)&&(i=Int32Array),"u"===r.charAt(0)&&(i=Uint32Array),this.value=new i(t*n),this.bufferCount=t,this.bufferType=s,super.setup(e)}element(e){return e_(new st(this,e_(e)))}}let si=(e,t)=>e_(new sr(e,t));class ss extends U{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}}let sn=eN(ss).setParameterLength(1),sa=tw(0,"uint").label("u_cameraIndex").setGroup(tS("cameraIndex")).toVarying("v_cameraIndex"),so=tw("float").label("cameraNear").setGroup(tR).onRenderUpd
4ate(({camera:e})=>e.near),sl=tw("float").label("cameraFar").setGroup(tR).onRenderUpdate(({camera:e})=>e.far),su=eE(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.projectionMatrix);t=si(r).setGroup(tR).label("cameraProjectionMatrices").element(e.isMultiViewCamera?sn("gl_ViewID_OVR"):sa).toVar("cameraProjectionMatrix")}else t=tw("mat4").label("cameraProjectionMatrix").setGroup(tR).onRenderUpdate(({camera:e})=>e.projectionMatrix);return t}).once()(),sd=eE(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.projectionMatrixInverse);t=si(r).setGroup(tR).label("cameraProjectionMatricesInverse").element(e.isMultiViewCamera?sn("gl_ViewID_OVR"):sa).toVar("cameraProjectionMatrixInverse")}else t=tw("mat4").label("cameraProjectionMatrixInverse").setGroup(tR).onRenderUpdate(({camera:e})=>e.projectionMatrixInverse);return t}).once()(),sh=eE(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.matrixWorldInverse);t=si(r).setGroup(tR).label("cameraViewMatrices").element(e.isMultiViewCamera?sn("gl_ViewID_OVR"):sa).toVar("cameraViewMatrix")}else t=tw("mat4").label("cameraViewMatrix").setGroup(tR).onRenderUpdate(({camera:e})=>e.matrixWorldInverse);return t}).once()(),sc=tw("mat4").label("cameraWorldMatrix").setGroup(tR).onRenderUpdate(({camera:e})=>e.matrixWorld),sp=tw("mat3").label("cameraNormalMatrix").setGroup(tR).onRenderUpdate(({camera:e})=>e.normalMatrix),sg=tw(new u.Pq0).label("cameraPosition").setGroup(tR).onRenderUpdate(({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)),sm=new u.iyt;class sf extends U{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=w.OBJECT,this._uniformNode=new tE(null)}getNodeType(){let e=this.scope;return e===sf.WORLD_MATRIX?"mat4":e===sf.POSITION||e===sf.VIEW_POSITION||e===sf.DIRECTION||e===sf.SCALE?"vec3":e===sf.RADIUS?"float":void 0}update(e){let t=this.object3d,r=this._uniformNode,i=this.scope;if(i===sf.WORLD_MATRIX)r.value=t.matrixWorld;else if(i===sf.POSITION)r.value=r.value||new u.Pq0,r.value.setFromMatrixPosition(t.matrixWorld);else if(i===sf.SCALE)r.value=r.value||new u.Pq0,r.value.setFromMatrixScale(t.matrixWorld);else if(i===sf.DIRECTION)r.value=r.value||new u.Pq0,t.getWorldDirection(r.value);else if(i===sf.VIEW_POSITION){let i=e.camera;r.value=r.value||new u.Pq0,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(i.matrixWorldInverse)}else if(i===sf.RADIUS){let i=e.object.geometry;null===i.boundingSphere&&i.computeBoundingSphere(),sm.copy(i.boundingSphere).applyMatrix4(t.matrixWorld),r.value=sm.radius}}generate(e){let t=this.scope;return t===sf.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t===sf.POSITION||t===sf.VIEW_POSITION||t===sf.DIRECTION||t===sf.SCALE?this._uniformNode.nodeType="vec3":t===sf.RADIUS&&(this._uniformNode.nodeType="float"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}sf.WORLD_MATRIX="worldMatrix",sf.POSITION="position",sf.SCALE="scale",sf.VIEW_POSITION="viewPosition",sf.DIRECTION="direction",sf.RADIUS="radius";let sy=eN(sf,sf.DIRECTION).setParameterLength(1),sx=eN(sf,sf.WORLD_MATRIX).setParameterLength(1),sb=eN(sf,sf.POSITION).setParameterLength(1),sT=eN(sf,sf.SCALE).setParameterLength(1),s_=eN(sf,sf.VIEW_POSITION).setParameterLength(1),sv=eN(sf,sf.RADIUS).setParameterLength(1);class sS extends sf{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}let sN=eR(sS,sS.DIRECTION),sR=eR(sS,sS.WORLD_MATRIX),sA=eR(sS,sS.POSITION),sE=eR(sS,sS.SCALE),sw=eR(sS,sS.VIEW_POSITION),sC=eR(sS,sS.RADIUS),sM=tw(new u.dwI).onObjectUpdate(({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld)),sB=tw(new u.kn4).onObjectUpdate(({object:e},t)=>t.value.copy(e.matrixWorld).invert()),sP=eE(e=>e.renderer.overrideNodes.modelViewMatrix||sF).once()().toVar("modelViewMatrix"),sF=sh.mul(sR),sL=eE(e=>
4(e.context.isHighPrecisionModelViewMatrix=!0,tw("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),sU=eE(e=>{let t=e.context.isHighPrecisionModelViewMatrix;return tw("mat3").onObjectUpdate(({object:e,camera:r})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),sI=i0("position","vec3"),sD=sI.toVarying("positionLocal"),sV=sI.toVarying("positionPrevious"),sO=sR.mul(sD).xyz.toVarying("v_positionWorld").context({needsPositionReassign:!0}),sG=sD.transformDirection(sR).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection").context({needsPositionReassign:!0}),sk=eE(e=>e.context.setupPositionView(),"vec3").once()().toVarying("v_positionView").context({needsPositionReassign:!0}),sz=sk.negate().toVarying("v_positionViewDirection").normalize().toVar("positionViewDirection");class s$ extends U{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){let{renderer:t,material:r}=e;return t.coordinateSystem===u.TdN&&r.side===u.hsX?"false":e.getFrontFacing()}}let sW=eR(s$),sH=eF(sW).mul(2).sub(1),sq=i0("normal","vec3"),sj=eE(e=>!1===e.geometry.hasAttribute("normal")?(console.warn('THREE.TSL: Vertex attribute "normal" not found on geometry.'),ek(0,1,0)):sq,"vec3").once()().toVar("normalLocal"),sX=sk.dFdx().cross(sk.dFdy()).normalize().toVar("normalFlat"),sQ=eE(e=>!0===e.material.flatShading?sX:ip(s1(sj),"v_normalView").normalize(),"vec3").once()().toVar("normalView"),sY=eE(e=>{let t=sQ.transformDirection(sh);return!0!==e.material.flatShading&&(t=ip(t,"v_normalWorld")),t},"vec3").once()().normalize().toVar("normalWorld"),sK=eE(e=>{let t=e.context.setupNormal().context({getUV:null});return!0!==e.material.flatShading&&(t=t.mul(sH)),t},"vec3").once()().toVar("transformedNormalView"),sZ=sK.transformDirection(sh).toVar("transformedNormalWorld"),sJ=eE(e=>{let t=e.context.setupClearcoatNormal().context({getUV:null});return!0!==e.material.flatShading&&(t=t.mul(sH)),t},"vec3").once()().toVar("transformedClearcoatNormalView"),s0=eE(([e,t=sR])=>{let r=eY(t),i=e.div(ek(r[0].dot(r[0]),r[1].dot(r[1]),r[2].dot(r[2])));return r.mul(i).xyz}),s1=eE(([e],t)=>{let r=t.renderer.overrideNodes.modelNormalViewMatrix;if(null!==r)return r.transformDirection(e);let i=sM.mul(e);return sh.transformDirection(i)}),s2=new u.O9p,s3=new u.kn4,s4=tw(0).onReference(({material:e})=>e).onObjectUpdate(({material:e})=>e.refractionRatio),s6=tw(1).onReference(({material:e})=>e).onObjectUpdate(function({material:e,scene:t}){return e.envMap?e.envMapIntensity:t.environmentIntensity}),s8=tw(new u.kn4).onReference(function(e){return e.material}).onObjectUpdate(function({material:e,scene:t}){let r=null!==t.environment&&null===e.envMap?t.environmentRotation:e.envMapRotation;return r?(s2.copy(r),s3.makeRotationFromEuler(s2)):s3.identity(),s3}),s5=sz.negate().reflect(sK),s9=sz.negate().refract(sK,s4),s7=s5.transformDirection(sh).toVar("reflectVector"),ne=s9.transformDirection(sh).toVar("reflectVector");class nt extends i8{static get type(){return"CubeTextureNode"}constructor(e,t=null,r=null,i=null){super(e,t,r,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){let e=this.value;return e.mapping===u.hy7?s7:e.mapping===u.xFO?ne:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),ek(0,0,0))}setUpdateMatrix(){}setupUV(e,t){let r=this.value;return e.renderer.coordinateSystem!==u.i7u&&r.isRenderTargetTexture||(t=ek(t.x.negate(),t.yz)),s8.mul(t)}generateUV(e,t){return t.build(e,"vec3")}}let nr=eN(nt).setParameterLength(1,4).setName("cubeTexture");class ni extends I{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,r,i)}}class ns extends U{static get type(){return"ReferenceNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.name=null,this.updateType=w.OBJECT}element(e){return e_(new ni(this,e_(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?se(null,e,this.count):Array.isArray(this.getValueFromReference())?si(null,e):"texture"===e?i5(null):"cubeTexture"===e?nr(null):tw(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateV
4alue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let e=1;e<t.length;e++)r=r[t[e]];return r}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}let nn=(e,t,r)=>e_(new ns(e,t,r)),na=(e,t,r,i)=>e_(new ns(e,t,i,r));class no extends ns{static get type(){return"MaterialReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.material=r,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}let nl=(e,t,r=null)=>e_(new no(e,t,r)),nu=eE(e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),i0("tangent","vec4")))(),nd=nu.xyz.toVar("tangentLocal"),nh=sP.mul(eH(nd,0)).xyz.toVarying("v_tangentView").normalize().toVar("tangentView"),nc=nh.transformDirection(sh).toVarying("v_tangentWorld").normalize().toVar("tangentWorld"),np=nh.toVar("transformedTangentView"),ng=np.transformDirection(sh).normalize().toVar("transformedTangentWorld"),nm=eE(([e,t],r)=>{let i=e.mul(nu.w).xyz;return!0!==r.material.flatShading&&(i=ip(e,t)),i}).once(),nf=nm(sq.cross(nu),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),ny=nm(sj.cross(nd),"v_bitangentLocal").normalize().toVar("bitangentLocal"),nx=nm(sQ.cross(nh),"v_bitangentView").normalize().toVar("bitangentView"),nb=nm(sY.cross(nc),"v_bitangentWorld").normalize().toVar("bitangentWorld"),nT=nm(sK.cross(np),"v_transformedBitangentView").normalize().toVar("transformedBitangentView"),n_=nT.transformDirection(sh).normalize().toVar("transformedBitangentWorld"),nv=eY(nh,nx,sQ),nS=sz.mul(nv),nN=(()=>{let e=to.cross(sz);return r0(e=e.cross(to).normalize(),sK,tn.mul(e6.oneMinus()).oneMinus().pow2().pow2()).normalize()})(),nR=eE(e=>{let{eye_pos:t,surf_norm:r,mapN:i,uv:s}=e,n=t.dFdx(),a=t.dFdy(),o=s.dFdx(),l=s.dFdy(),u=a.cross(r),d=r.cross(n),h=u.mul(o.x).add(d.mul(l.x)),c=u.mul(o.y).add(d.mul(l.y)),p=h.dot(h).max(c.dot(c)),g=sH.mul(p.inverseSqrt());return tD(h.mul(i.x,g),c.mul(i.y,g),r.mul(i.z)).normalize()});
4class nA extends V{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=u.bI3}setup(e){let{normalMapType:t,scaleNode:r}=this,i=this.node.mul(2).sub(1);null!==r&&(i=ek(i.xy.mul(r),i.z));let s=null;return t===u.vyJ?s=s1(i):t===u.bI3&&(s=!0===e.hasGeometryAttribute("tangent")?nv.mul(i).normalize():nR({eye_pos:sk,surf_norm:sQ,mapN:i,uv:i1()})),s}}let nE=eN(nA).setParameterLength(1,2),nw=eE(({textureNode:e,bumpScale:t})=>{let r=t=>e.cache().context({getUV:e=>t(e.uvNode||i1()),forceUVContext:!0}),i=eF(r(e=>e));return eD(eF(r(e=>e.add(e.dFdx()))).sub(i),eF(r(e=>e.add(e.dFdy()))).sub(i)).mul(t)}),nC=eE(e=>{let{surf_pos:t,surf_norm:r,dHdxy:i}=e,s=t.dFdx().normalize(),n=t.dFdy().normalize().cross(r),a=r.cross(s),o=s.dot(n).mul(sH),l=o.sign().mul(i.x.mul(n).add(i.y.mul(a)));return o.abs().mul(r).sub(l).normalize()});class nM extends V{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){let e=null!==this.scaleNode?this.scaleNode:1;return nC({surf_pos:sk,surf_norm:sQ,dHdxy:nw({textureNode:this.textureNode,bumpScale:e})})}}let nB=eN(nM).setParameterLength(1,2),nP=new Map;class nF extends U{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let r=nP.get(e);return void 0===r&&(r=nl(e,t),nP.set(e,r)),r}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){let t=e.context.material,r=this.scope,i=null;if(r===nF.COLOR){let e=void 0!==t.color?this.getColor(r):ek();i=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(r===nF.OPACITY){let e=this.getFloat(r);i=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(r===nF.SPECULAR_STRENGTH)i=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:eF(1);else if(r===nF.SPECULAR_INTENSITY){let e=this.getFloat(r);i=t.specularIntensityMap&&!0===t.specularIntensityMap.isTexture?e.mul(this.getTexture(r).a):e}else if(r===nF.SPECULAR_COLOR){let e=this.getColor(r);i=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(r).rgb):e}else if(r===nF.ROUGHNESS){let e=this.getFloat(r);i=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(r).g):e}else if(r===nF.METALNESS){let e=this.getFloat(r);i=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(r).b):e}else if(r===nF.EMISSIVE){let e=this.getFloat("emissiveIntensity"),s=this.getColor(r).mul(e);i=t.emissiveMap&&!0===t.emissiveMap.isTexture?s.mul(this.getTexture(r)):s}else if(r===nF.NORMAL)t.normalMap?(i=nE(this.getTexture("normal"),this.getCache("normalScale","vec2"))).normalMapType=t.normalMapType:i=t.bumpMap?nB(this.getTexture("bump").r,this.getFloat("bumpScale")):sQ;else if(r===nF.CLEARCOAT){let e=this.getFloat(r);i=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===nF.CLEARCOAT_ROUGHNESS){let e=this.getFloat(r);i=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===nF.CLEARCOAT_NORMAL)i=t.clearcoatNormalMap?nE(this.getTexture(r),this.getCache(r+"Scale","vec2")):sQ;else if(r===nF.SHEEN){let e=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(r===nF.SHEEN_ROUGHNESS){let e=this.getFloat(r);i=(i=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(r).a):e).clamp(.07,1)}else if(r===nF.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){let e=this.getTexture(r);i=eQ(ao.x,ao.y,ao.y.negate(),ao.x).mul(e.rg.mul(2).sub(eD(1)).normalize().mul(e.b))}else i=ao;else if(r===nF.IRIDESCENCE_THICKNESS){let e=nn("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){let s=nn("0","float",t.iridescenceThicknessRange);i=e.sub(s).mul(this.getTexture(r).g).add(s)}else i=e}else if(r===nF.TRANSMISSION){let e=this.getFloat(r);i=t.transmissionMap?e.mul(this.getTexture(r).r):e}else if(r===nF.THICKNESS){let e=this.getFloat(r);i=t.thicknessMap?e.mul(this.getTexture(r).g):e}else if(r===nF.IOR)i=this.getFloat(r);else if(r===nF.LIGHT_MAP)i=this.getTexture(r).rgb.mul(this.getFloat("lightMapIntensity"));else if(r===nF.AO)i=this.getTexture(r).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{let t=this.getNodeType(e);i=this.getCache(r,t)}return i}}nF.ALPHA_TEST="alphaTest",nF.COLOR="color",nF.OPACITY="opacity",nF.SHININESS="shininess",nF.SPECULAR="specular",nF.SPECULAR_STRENGTH="specularStrength",nF.SPECULAR_INTENSITY="specularIntensity",nF.SPECULAR_COLOR="specularColor",nF.REFLECTIVITY="reflectivity",nF.ROUGHNESS="roughness",nF.METALNESS="metalness",nF.NORMAL="normal",nF.CLEARCOAT="clearcoat",nF.CLEARCOAT_ROUGHNESS="clearcoatRoughness",nF.CLEARCOAT_NORMAL="clearcoatNormal",nF.EMISSIVE="emissive",nF.ROTATION="rotation",nF.SHEEN="sheen",nF.SHEEN_ROUGHNESS="sheenRoughness",nF.ANISOTROPY="anisotropy",nF.IRIDESCENCE="iridescence",nF.IRIDESCENCE_IOR="iridescenceIOR",nF.IRIDESCENCE_THICKNESS="iridescenceThickness",nF.IOR="ior",nF.TRANSMISSION="transmission",
4nF.THICKNESS="thickness",nF.ATTENUATION_DISTANCE="attenuationDistance",nF.ATTENUATION_COLOR="attenuationColor",nF.LINE_SCALE="scale",nF.LINE_DASH_SIZE="dashSize",nF.LINE_GAP_SIZE="gapSize",nF.LINE_WIDTH="linewidth",nF.LINE_DASH_OFFSET="dashOffset",nF.POINT_SIZE="size",nF.DISPERSION="dispersion",nF.LIGHT_MAP="light",nF.AO="ao";let nL=eR(nF,nF.ALPHA_TEST),nU=eR(nF,nF.COLOR),nI=eR(nF,nF.SHININESS),nD=eR(nF,nF.EMISSIVE),nV=eR(nF,nF.OPACITY),nO=eR(nF,nF.SPECULAR),nG=eR(nF,nF.SPECULAR_INTENSITY),nk=eR(nF,nF.SPECULAR_COLOR),nz=eR(nF,nF.SPECULAR_STRENGTH),n$=eR(nF,nF.REFLECTIVITY),nW=eR(nF,nF.ROUGHNESS),nH=eR(nF,nF.METALNESS),nq=eR(nF,nF.NORMAL),nj=eR(nF,nF.CLEARCOAT),nX=eR(nF,nF.CLEARCOAT_ROUGHNESS),nQ=eR(nF,nF.CLEARCOAT_NORMAL),nY=eR(nF,nF.ROTATION),nK=eR(nF,nF.SHEEN),nZ=eR(nF,nF.SHEEN_ROUGHNESS),nJ=eR(nF,nF.ANISOTROPY),n0=eR(nF,nF.IRIDESCENCE),n1=eR(nF,nF.IRIDESCENCE_IOR),n2=eR(nF,nF.IRIDESCENCE_THICKNESS),n3=eR(nF,nF.TRANSMISSION),n4=eR(nF,nF.THICKNESS),n6=eR(nF,nF.IOR),n8=eR(nF,nF.ATTENUATION_DISTANCE),n5=eR(nF,nF.ATTENUATION_COLOR),n9=eR(nF,nF.LINE_SCALE),n7=eR(nF,nF.LINE_DASH_SIZE),ae=eR(nF,nF.LINE_GAP_SIZE),at=eR(nF,nF.LINE_WIDTH),ar=eR(nF,nF.LINE_DASH_OFFSET),ai=eR(nF,nF.POINT_SIZE),as=eR(nF,nF.DISPERSION),an=eR(nF,nF.LIGHT_MAP),aa=eR(nF,nF.AO),ao=tw(new u.I9Y).onReference(function(e){return e.material}).onRenderUpdate(function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}),al=eE(e=>e.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");class au extends U{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){let t,r=this.getNodeType(e),i=this.scope;if(i===au.VERTEX)t=e.getVertexIndex();else if(i===au.INSTANCE)t=e.getInstanceIndex();else if(i===au.DRAW)t=e.getDrawIndex();else if(i===au.INVOCATION_LOCAL)t=e.getInvocationLocalIndex();else if(i===au.INVOCATION_SUBGROUP)t=e.getInvocationSubgroupIndex();else if(i===au.SUBGROUP)t=e.getSubgroupIndex();else throw Error("THREE.IndexNode: Unknown scope: "+i);return"vertex"===e.shaderStage||"compute"===e.shaderStage?t:ip(this).build(e,r)}}au.VERTEX="vertex",au.INSTANCE="instance",au.SUBGROUP="subgroup",au.INVOCATION_LOCAL="invocationLocal",au.INVOCATION_SUBGROUP="invocationSubgroup",au.DRAW="draw";let ad=eR(au,au.VERTEX),ah=eR(au,au.INSTANCE),ac=eR(au,au.SUBGROUP),ap=eR(au,au.INVOCATION_SUBGROUP),ag=eR(au,au.INVOCATION_LOCAL),am=eR(au,au.DRAW);class af extends U{static get type(){return"InstanceNode"}constructor(e,t,r=null){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=r,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=w.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let{count:t,instanceMatrix:r,instanceColor:i}=this,{instanceMatrixNode:s,instanceColorNode:n}=this;if(null===s){if(t<=1e3)s=se(r.array,"mat4",Math.max(t,1)).element(ah);else{let e=new u.LuO(r.array,16,1);this.buffer=e;let t=r.usage===u.Vnu?iI:iU;s=eK(t(e,"vec4",16,0),t(e,"vec4",16,4),t(e,"vec4",16,8),t(e,"vec4",16,12))}this.instanceMatrixNode=s}if(i&&null===n){let e=new u.uWO(i.array,3),t=i.usage===u.Vnu?iI:iU;this.bufferColor=e,n=ek(t(e,"vec3",3,0)),this.instanceColorNode=n}let a=s.mul(sD).xyz;if(sD.assign(a),e.hasGeometryAttribute("normal")){let e=s0(sj,s);sj.assign(e)}null!==this.instanceColorNode&&e2("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMatrix.usage!==u.Vnu&&null!==this.buffer&&this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version),this.instanceColor&&this.instanceColor.usage!==u.Vnu&&null!==this.bufferColor&&this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)}}let ay=eN(af).setParameterLength(2,3);class ax extends af{static get type(){return"InstancedMeshNode"}
4constructor(e){let{count:t,instanceMatrix:r,instanceColor:i}=e;super(t,r,i),this.instancedMesh=e}}let ab=eN(ax).setParameterLength(1);class aT extends U{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=ah:this.batchingIdNode=am);let t=eE(([e])=>{let t=eL(i3(i9(this.batchMesh._indirectTexture),0).x),r=eL(e).mod(t),i=eL(e).div(t);return i9(this.batchMesh._indirectTexture,eV(r,i)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]})(eL(this.batchingIdNode)),r=this.batchMesh._matricesTexture,i=eL(i3(i9(r),0).x),s=eF(t).mul(4).toInt().toVar(),n=s.mod(i),a=s.div(i),o=eK(i9(r,eV(n,a)),i9(r,eV(n.add(1),a)),i9(r,eV(n.add(2),a)),i9(r,eV(n.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){let e=eE(([e])=>{let t=eL(i3(i9(l),0).x);return i9(l,eV(e.mod(t),e.div(t))).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]})(t);e2("vec3","vBatchColor").assign(e)}let u=eY(o);sD.assign(o.mul(sD));let d=sj.div(ek(u[0].dot(u[0]),u[1].dot(u[1]),u[2].dot(u[2]))),h=u.mul(d).xyz;sj.assign(h),e.hasGeometryAttribute("tangent")&&nd.mulAssign(u)}}let a_=eN(aT).setParameterLength(1);class av extends I{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){let r=this.storageBufferNode.structTypeNode;return r?r.getMemberType(e,t):"void"}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.isPBO&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let r,i=e.context.assign;if(r=!1===e.isAvailable("storageBuffer")?!0===this.node.isPBO&&!0!==i&&(this.node.value.isInstancedBufferAttribute||"compute"!==e.shaderStage)?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==i){let i=this.getNodeType(e);r=e.format(r,i,t)}return r}}let aS=eN(av).setParameterLength(2);class aN extends i7{static get type(){return"StorageBufferNode"}constructor(e,t=null,r=0){let i,s=null;if(t&&t.isStruct)i="struct",s=t.layout,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(r=e.count);else if(null===t&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)){var n;n=e.itemSize,i=x.get(n),r=e.count}else i=t;super(e,i,r),this.isStorageBufferNode=!0,this.structTypeNode=s,this.access=C.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return aS(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(C.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=iF(this.value),this._varying=ip(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(null!==this.structTypeNode)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);let{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(null!==this.structTypeNode&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);let{attribute:t,varying:r}=this.getAttributeData(),i=r.build(e);return e.registerTransform(i,t),i}}let aR=(e,t=null,r=0)=>e_(new aN(e,t,r)),aA=new WeakMap;class aE extends U{static get type(){return"SkinningNode"}constructor(e){super("void"),this.skinnedMesh=e,this.updateType=w.OBJECT,this.skinIndexNode=i0("skinIndex","uvec4"),this.skinWeightNode=i0("skinWeight","vec4"),this.bindMatrixNode=nn("bindMatrix","mat4"),this.bindMatrixInverseNo
4de=nn("bindMatrixInverse","mat4"),this.boneMatricesNode=na("skeleton.boneMatrices","mat4",e.skeleton.bones.length),this.positionNode=sD,this.toPositionNode=sD,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=this.positionNode){let{skinIndexNode:r,skinWeightNode:i,bindMatrixNode:s,bindMatrixInverseNode:n}=this,a=e.element(r.x),o=e.element(r.y),l=e.element(r.z),u=e.element(r.w),d=s.mul(t),h=tD(a.mul(i.x).mul(d),o.mul(i.y).mul(d),l.mul(i.z).mul(d),u.mul(i.w).mul(d));return n.mul(h).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=sj){let{skinIndexNode:r,skinWeightNode:i,bindMatrixNode:s,bindMatrixInverseNode:n}=this,a=e.element(r.x),o=e.element(r.y),l=e.element(r.z),u=e.element(r.w),d=tD(i.x.mul(a),i.y.mul(o),i.z.mul(l),i.w.mul(u));return(d=n.mul(d).mul(s)).transformDirection(t).xyz}getPreviousSkinnedPosition(e){let t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=na("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,sV)}needsPreviousBoneMatrices(e){let t=e.renderer.getMRT();return t&&t.has("velocity")||!0===N(e.object).useVelocity}setup(e){this.needsPreviousBoneMatrices(e)&&sV.assign(this.getPreviousSkinnedPosition(e));let t=this.getSkinnedPosition();if(this.toPositionNode&&this.toPositionNode.assign(t),e.hasGeometryAttribute("normal")){let t=this.getSkinnedNormal();sj.assign(t),e.hasGeometryAttribute("tangent")&&nd.assign(t)}return t}generate(e,t){if("void"!==t)return super.generate(e,t)}update(e){let t=e.object&&e.object.skeleton?e.object.skeleton:this.skinnedMesh.skeleton;aA.get(t)!==e.frameId&&(aA.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}let aw=e=>e_(new aE(e));class aC extends U{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){let t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;let r={};for(let e=0,t=this.params.length-1;e<t;e++){let t=this.params[e],i=!0!==t.isNode&&t.name||this.getVarName(e),s=!0!==t.isNode&&t.type||"int";r[i]=ij(i,s)}let i=e.addStack();t.returnsNode=this.params[this.params.length-1](r,e),t.stackNode=i;let s=this.params[0];return!0!==s.isNode&&"function"==typeof s.update&&(t.updateNode=eE(this.params[0].update)(r)),e.removeStack(),t}getNodeType(e){let{returnsNode:t}=this.getProperties(e);return t?t.getNodeType(e):"void"}setup(e){this.getProperties(e)}generate(e){let t=this.getProperties(e),r=this.params,i=t.stackNode;for(let i=0,s=r.length-1;i<s;i++){let s,n=r[i],a=!1,o=null,l=null,u=null,d=null,h=null,c=null;if(n.isNode?"bool"===n.getNodeType(e)?(a=!0,d="bool",l=n.build(e,d)):(d="int",u=this.getVarName(i),o="0",l=n.build(e,d),h="<"):(d=n.type||"int",u=n.name||this.getVarName(i),o=n.start,l=n.end,h=n.condition,c=n.update,"number"==typeof o?o=e.generateConst(d,o):o&&o.isNode&&(o=o.build(e,d)),"number"==typeof l?l=e.generateConst(d,l):l&&l.isNode&&(l=l.build(e,d)),void 0!==o&&void 0===l?(o+=" - 1",l="0",h=">="):void 0!==l&&void 0===o&&(o="0",h="<"),void 0===h&&(h=Number(o)>Number(l)?">=":"<")),a)s=`while ( ${l} )`;else{let r,i=o,n=l,a=()=>h.includes("<")?"+=":"-=";if(null!=c)switch(typeof c){case"function":r=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":r=u+" "+a()+" "+e.generateConst(d,c);break;case"string":r=u+" "+c;break;default:c.isNode?r=u+" "+a()+" "+c.build(e):(console.error("THREE.TSL: 'Loop( { update: ... } )' is not a function, string or number."),r="break /* invalid update */")}else r=u+" "+(c="int"===d||"uint"===d?h.includes("<")?"++":"--":a()+" 1.");let p=e.getVar(d,u)+" = "+i,g=u+" "+h+" "+n;s=`for ( ${p}; ${g}; ${r} )`}e.addFlowCode((0===i?"\n":"")+e.tab+s+" {\n\n").addFlowTab()}let s=i.build(e,"void"),n=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+s);for(let t=0,r=this.params.length-1;t<r;t++)e.addFlowCode((0===t?"":e.tab)+"}\n\n").removeFlowTab();return e.addFlowTab(),n}}let aM=(...e)=>e_(new aC(eS(e,"int"))).toStack(),aB=()=>ij("break").toStack(),aP=new WeakMap,aF=new u.IUQ,aL=eE(({bufferMap:e,influence:t,stride:r,width:i,depth:s,offset:n})=>{let a=eL(ad).mul(r).add(n),o=a.div(i);return i9(e,eV(a.sub(o.mul(i)),o)).depth(s).xyz.mul(t)});class aU extends U{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=tw(1),this.updateType=w.OBJECT}setup(e){let{geometry:t}=e,r=void 0!==t.morphAttributes.position,i=t.hasAttribute("normal")&&void 0!==t.morphAttributes.normal,s=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==s?s.length:0,{texture:a,stride:o,size:l}=function(e){let t=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,s=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==s?s.length:0,a=aP.get(e);if(void 0===a||a.count!==n){void 0!==a&&a.texture.dispose();let s=e.morphAttributes.position||[],o=e.morphAttributes.normal||[],l=e.morphAttributes.color||[],d=0;!0===t&&(d=1),!0===r&&(d=2),!0===i&&(d=3);let h=e.attributes.position.count*d,c=1;h>4096&&(c=Math.ceil(h/4096),h=4096);let p=new Float32Array(h*c*4*n),g=new u.rFo(p,h,c,n);g.type=u.RQf,g.needsUpdate=!0;let m=4*d;for(let e=0;e<n;e++){let n=s[e],a=o[e],u=l[e],d=h*c*4*e;for(let e=0;e<n.count;e++){let s=e*m;!0===t&&(aF.fromBufferAttribute(n,e),p[d+s+0]=aF.x,p[d+s+1]=aF.y,p[d+s+2]=aF.z,p[d+s+3]=0),!0===r&&(aF.fromBufferAttribute(a,e),p[d+s+4]=aF.x,p[d+s+5]=aF.y,p[d+s+6]=aF.z,p[d+s+7]=0),!0===i&&(aF.fromBufferAttribute(u,e),p[d+s+8]=aF.x,p[d+s+9]=aF.y,p[d+s+10]=aF.z,p[d+s+11]=4===u.itemSize?aF.w:1)}}a={count:n,texture:g,stride:d,size:new u.I9Y(h,c)},aP.set(e,a),e.addEventListener("dispose",function t(){g.dispose(),aP.delete(e),e.removeEventListener("dispose",t)})}return a}(t);!0===r&&sD.mulAssign(this.morphBaseInfluence),!0===i&&sj.mulAssign(this.morphBaseInfluence);let d=eL(l.width);aM(n,({i:e})=>{let t=eF(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(i9(this.mesh.morphTexture,eV(eL(e).add(1),eL(ah))).r):t.assign(nn("morphTargetInfluences","float").element
4(e).toVar()),eM(t.notEqual(0),()=>{!0===r&&sD.addAssign(aL({bufferMap:a,influence:t,stride:o,width:d,depth:e,offset:eL(0)})),!0===i&&sj.addAssign(aL({bufferMap:a,influence:t,stride:o,width:d,depth:e,offset:eL(1)}))})})}update(){let e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((e,t)=>e+t,0)}}let aI=eN(aU).setParameterLength(1);class aD extends U{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class aV extends aD{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class aO extends ii{static get type(){return"LightingContextNode"}constructor(e,t=null,r=null,i=null){super(e),this.lightingModel=t,this.backdropNode=r,this.backdropAlphaNode=i,this._value=null}getContext(){let{backdropNode:e,backdropAlphaNode:t}=this,r=ek().toVar("directDiffuse"),i=ek().toVar("directSpecular"),s=ek().toVar("indirectDiffuse"),n=ek().toVar("indirectSpecular");return{radiance:ek().toVar("radiance"),irradiance:ek().toVar("irradiance"),iblIrradiance:ek().toVar("iblIrradiance"),ambientOcclusion:eF(1).toVar("ambientOcclusion"),reflectedLight:{directDiffuse:r,directSpecular:i,indirectDiffuse:s,indirectSpecular:n},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)}}let aG=eN(aO);class ak extends aD{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}class az extends U{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===az.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=w.NONE;return(this.scope===az.SIZE||this.scope===az.VIEWPORT)&&(e=w.RENDER),this.updateType=e,e}update({renderer:e}){let t=e.getRenderTarget();this.scope===az.VIEWPORT?null!==t?s.copy(t.viewport):(e.getViewport(s),s.multiplyScalar(e.getPixelRatio())):null!==t?(i.width=t.width,i.height=t.height):e.getDrawingBufferSize(i)}setup(){let e=this.scope;return e===az.SIZE?tw(i||(i=new u.I9Y)):e===az.VIEWPORT?tw(s||(s=new u.IUQ)):eD(aH.div(aW))}generate(e){if(this.scope===az.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){let r=e.getNodeProperties(aW).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${r}.y - ${t}.y )`}return t}return super.generate(e)}}az.COORDINATE="coordinate",az.VIEWPORT="viewport",az.SIZE="size",az.UV="uv";let a$=eR(az,az.UV),aW=eR(az,az.SIZE),aH=eR(az,az.COORDINATE),aq=eR(az,az.VIEWPORT),aj=aq.zw,aX=aH.sub(aq.xy),aQ=aX.div(aj),aY=eE(()=>(console.warn('THREE.TSL: "viewportResolution" is deprecated. Use "screenSize" instead.'),aW),"vec2").once()(),aK=eE(()=>(console.warn('THREE.TSL: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),a$),"vec2").once()(),aZ=eE(()=>(console.warn('THREE.TSL: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),a$.flipY()),"vec2").once()(),aJ=new u.I9Y;class a0 extends i8{static get type(){return"ViewportTextureNode"}constructor(e=a$,t=null,r=null){null===r&&((r=new u.Pem).minFilter=u.$_I),super(r,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=w.FRAME}updateBefore(e){let t=e.renderer;t.getDrawingBufferSize(aJ);let r=this.value;(r.image.width!==aJ.width||r.image.height!==aJ.height)&&(r.image.width=aJ.width,r.image.height=aJ.height,r.needsUpdate=!0);let i=r.generateMipmaps;r.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(r),r.generateMipmaps=i}clone(){let e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}let a1=eN(a0).setParameterLength(0,3),a2=eN(a0,null,null,{generateMipmaps:!0}).setParameterLength(0,3),a3=null;class a4 extends a0{static get type(){return"ViewportDepthTextureNode"}constructor(e=a$,t=null){null===a3&&(a3=new u.VCu),super(e,t,a3)}}let a6=eN(a4).setParameterLength(0,2);class a8 extends U{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){let{scope:t}=this;return t===a8.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){let{scope:t}=this,r=this.valueNode,i=null;return t===a8.DEPTH_BASE?null!==r&&(i=ot().assign(r)):t===a8.DEPTH?i=e.isPerspectiveCamera?a9(sk.z,so,sl):a5(sk.z,so,sl):t===a8.LINEAR_DEPTH&&(i=null!==r?e.
4isPerspectiveCamera?a5(a7(r,so,sl),so,sl):r:a5(sk.z,so,sl)),i}}a8.DEPTH_BASE="depthBase",a8.DEPTH="depth",a8.LINEAR_DEPTH="linearDepth";let a5=(e,t,r)=>e.add(t).div(t.sub(r)),a9=(e,t,r)=>t.add(e).mul(r).div(r.sub(t).mul(e)),a7=(e,t,r)=>t.mul(r).div(r.sub(t).mul(e).sub(r)),oe=(e,t,r)=>{t=t.max(1e-6).toVar();let i=rc(e.negate().div(t)),s=rc(r.div(t));return i.div(s)},ot=eN(a8,a8.DEPTH_BASE),or=eR(a8,a8.DEPTH),oi=eN(a8,a8.LINEAR_DEPTH).setParameterLength(0,1),os=oi(a6());or.assign=e=>ot(e);class on extends U{static get type(){return"ClippingNode"}constructor(e=on.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);let{intersectionPlanes:t,unionPlanes:r}=e.clippingContext;return(this.hardwareClipping=e.material.hardwareClipping,this.scope===on.ALPHA_TO_COVERAGE)?this.setupAlphaToCoverage(t,r):this.scope===on.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(t,r)}setupAlphaToCoverage(e,t){return eE(()=>{let r=eF().toVar("distanceToPlane"),i=eF().toVar("distanceToGradient"),s=eF(1).toVar("clipOpacity"),n=t.length;if(!1===this.hardwareClipping&&n>0){let e=si(t);aM(n,({i:t})=>{let n=e.element(t);r.assign(sk.dot(n.xyz).negate().add(n.w)),i.assign(r.fwidth().div(2)),s.mulAssign(r4(i.negate(),i,r))})}let a=e.length;if(a>0){let t=si(e),n=eF(1).toVar("intersectionClipOpacity");aM(a,({i:e})=>{let s=t.element(e);r.assign(sk.dot(s.xyz).negate().add(s.w)),i.assign(r.fwidth().div(2)),n.mulAssign(r4(i.negate(),i,r).oneMinus())}),s.mulAssign(n.oneMinus())}e3.a.mulAssign(s),e3.a.equal(0).discard()})()}setupDefault(e,t){return eE(()=>{let r=t.length;if(!1===this.hardwareClipping&&r>0){let e=si(t);aM(r,({i:t})=>{let r=e.element(t);sk.dot(r.xyz).greaterThan(r.w).discard()})}let i=e.length;if(i>0){let t=si(e),r=eI(!0).toVar("clipped");aM(i,({i:e})=>{let i=t.element(e);r.assign(sk.dot(i.xyz).greaterThan(i.w).and(r))}),r.discard()}})()}setupHardwareClipping(e,t){let r=e.length;return t.enableHardwareClipping(r),eE(()=>{let i=si(e),s=sn(t.getClipDistance());aM(r,({i:e})=>{let t=i.element(e),r=sk.dot(t.xyz).sub(t.w).negate();
4s.element(e).assign(r)})})()}}on.ALPHA_TO_COVERAGE="alphaToCoverage",on.DEFAULT="default",on.HARDWARE="hardware";let oa=eE(([e])=>rx(tO(1e4,rb(tO(17,e.x).add(tO(.1,e.y)))).mul(tD(.1,rR(rb(tO(13,e.y).add(e.x))))))),oo=eE(([e])=>oa(eD(oa(e.xy),e.z))),ol=eE(([e])=>{let t=rG(rE(rM(e.xyz)),rE(rB(e.xyz))),r=eF(1).div(eF(.05).mul(t)).toVar("pixScale"),i=eD(rd(rm(rc(r))),rd(rf(rc(r)))),s=eD(oo(rm(i.x.mul(e.xyz))),oo(rm(i.y.mul(e.xyz)))),n=rx(rc(r)),a=tD(tO(n.oneMinus(),s.x),tO(n,s.y)),o=rO(n,n.oneMinus()),l=ek(a.mul(a).div(tO(2,o).mul(tV(1,o))),a.sub(tO(.5,o)).div(tV(1,o)),tV(1,tV(1,a).mul(tV(1,a)).div(tO(2,o).mul(tV(1,o)))));return r1(a.lessThan(o.oneMinus()).select(a.lessThan(o).select(l.x,l.y),l.z),1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class ou extends iJ{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){let e=this.index;return"color"+(e>0?e:"")}generate(e){let t=this.getAttributeName(e);return!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new u.IUQ(1,1,1,1))}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}let od=(e=0)=>e_(new ou(e));class oh extends u.imn{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.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+f(this)}build(e){this.setup(e)}setupObserver(e){return new h(e)}setup(e){let t;e.context.setupNormal=()=>this.setupNormal(e),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);let r=e.renderer,i=r.getRenderTarget();e.addStack();let s=this.vertexNode||this.setupVertex(e);e.stack.outputNode=s,this.setupHardwareClipping(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let n=this.setupClipping(e);if((!0===this.depthWrite||!0===this.depthTest)&&(null!==i?!0===i.depthBuffer&&this.setupDepth(e):!0===r.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);let s=this.setupLighting(e);null!==n&&e.stack.add(n);let a=eH(s,e3.a).max(0);t=this.setupOutput(e,a),th.assign(t);let o=null!==this.outputNode;if(o&&(t=this.outputNode),null!==i){let e=r.getMRT(),i=this.mrtNode;null!==e?(o&&th.assign(t),t=e,null!==i&&(t=e.merge(i))):null!==i&&(t=i)}}else{let r=this.fragmentNode;!0!==r.isOutputStructNode&&(r=eH(r)),t=this.setupOutput(e,r)}e.stack.outputNode=t,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;let{unionPlanes:t,intersectionPlanes:r}=e.clippingContext,i=null;if(t.length>0||r.length>0){let t=e.renderer.samples;this.alphaToCoverage&&t>1?i=e_(new on(on.ALPHA_TO_COVERAGE)):e.stack.add(e_(new on))}return i}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;let t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(e_(new on(on.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){let{renderer:t,camera:r}=e,i=this.depthNode;if(null===i){let e=t.getMRT();e&&e.has("depth")?i=e.get("depth"):!0===t.logarithmicDepthBuffer&&(i=r.isPerspectiveCamera?oe(sk.z,so,sl):a5(sk.z,so,sl))}null!==i&&or.assign(i).toStack()}setupPositionView(){return sP.mul(sD).xyz}setupModelViewProjection(){return su.mul(sk)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.vertex=e.removeStack(),al}setupPosition(e){let{object:t,geometry:r}=e;if((r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color)&&aI(t).toStack(),!0===t.isSkinnedMesh&&aw(t).toStack(),this.displacementMap){let e=nl("displacementMap","texture"),t=nl("displacementScale","float"),r=nl("displacementBias","float");sD.addAssign(sj.normalize().mul(e.x.mul(t).add(r)))}return t.isBatchedMesh&&a_(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ab(t).toStack(),null!==this.positionNode&&sD.assign(this.positionNode.context({isPositionNodeInput:!0})),sD}setupDiffuseColor({object:e,geometry:t}){let r=this.colorNode?eH(this.colorNode):nU;!0===this.vertexColors&&t.hasAttribute("color")&&(r=r.mul(od())),e.instanceColor&&(r=e2("vec3","vInstanceColor").mul(r)),e.isBatchedMesh&&e._colorsTexture&&(r=e2("vec3","vBatchColor").mul(r)),e3.assign(r);let i=this.opacityNode?eF(this.opacityNode):nV;if(e3.a.assign(e3.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){let e=null!==this.alphaTestNode?eF(this.alphaTestNode):nL;e3.a.lessThanEqual(e).discard()}!0===this.alphaHash&&e3.a.lessThan(ol(sD)).discard(),!1===this.transparent&&this.blending===u.NTi&&!1===this.alphaToCoverage&&e3.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?ek(0):e3.rgb}setupNormal(){return this.normalNode?ek(this.normalNode):nq}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?nl("envMap","cubeTexture"):nl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new ak(an)),t}setupLights(e){let t=[],r=this.setupEnvironment(e);r&&r.isLightingNode&&t.push(r);let i=this.setupLightMap(e);if(i&&i.isLightingNode&&t.push(i),null!==this.aoNode||e.material.aoMap){let e=null!==this.aoNode?this.aoNode:aa;t.push(new aV(e))}let s=this.lightsNode||e.lightsNode;return t.length>0&&(s=e.renderer.lighting.createNode([...s.getLights(),...t])),s}setupLightingModel(){}setupLighting(e){let{material:t}=e,{backdropNode:r,backdropAlphaNode:i,emissiveNode:s}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null,a=this.setupOutgoingLight(e);return n&&n.getScope().hasLights?a=aG(n,this.setupLightingModel(e)||null,r,i):null!==r&&(a=ek(null!==i?r0(a,r,i):r)),(s&&!0===s.isNode||t.emissive&&!0===t.emissive.isColor)&&(e4.assign(ek(s||nD)),a=a.add(e4)),a}setupFog(e,t){let r=e.fogNode;return r&&(th.assign(t),t=eH(r)),t}setupOutput(e,t){return!0===this.fog&&(t=this.setupFog(e,t)),t}setDefaultValues(e){for(let t in e){let r=e[t];void 0===this[t]&&(this[t]=r,r&&r.clone&&(this[t]=r.clone()))}let t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(let e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){let t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});let r=u.imn.prototype.toJSON.call(this,e),i=y(this);for(let{property:t,childNode:s}of(r.inputNodes={},i))r.inputNodes[t]=s.toJSON(e).uuid;function s(e){let t=[];for(let r in e){let i=e[r];delete i.metadata,t.push(i)}return t}if(t){let t=s(e.textures),i=s(e.images),n=s(e.nodes);t.length>0&&(r.textures=t),i.length>0&&(r.images=i),n.length>0&&(r.nodes=n)}return r}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.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)}}let oc=new u.mrM;class op extends oh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(oc),this.setValues(e)}}let og=new u.Fvt;class om extends oh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(og),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){let e=this.offsetNode?eF(this.offsetNode):ar,t=this.dashScaleNode?eF(this.dashScaleNode):n9,r=this.dashSizeNode?eF(this.dashSizeNode):n7,i=this.gapSizeNode?eF(this.gapSizeNode):ae;tc.assign(r),tp.assign(i);let s=ip(i0("lineDistance").mul(t));(e?s.add(e):s).mod(tc.add(tp)).greaterThan(tc).discard()}}let of=null;class oy extends a0{static get type(){return"ViewportSharedTextureNode"}constructor(e=a$,t=null){null===of&&(of=new u.Pem),super(e,t,of)}updateReference(){return this}}let ox=eN(oy).setParameterLength(0,2),ob=e=>e_(e).mul(.5).add(.5),oT=new u.qBx;class o_ extends oh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(oT),this.setValues(e)}setupDiffuseColor(){let e=this.opacityNode?eF(this.opacityNode):nV;e3.assign(iN(eH(ob(sK),e),u.er$))}}class ov extends V{static get type(){return"EquirectUVNode"}constructor(e=sG){super("vec2"),this.dirNode=e}setup(){let e=this.dirNode;return eD(e.z.atan(e.x).mul(1/(2*Math.PI)).add(.5),e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5))}}let oS=eN(ov).setParameterLength(0,1);class oN extends u.o6l{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){let r=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace
4=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let s=new u.iNn(5,5,5),n=oS(sG),a=new oh;a.colorNode=i5(t,n,0),a.side=u.hsX,a.blending=u.XIg;let o=new u.eaF(s,a),l=new u.Z58;l.add(o),t.minFilter===u.$_I&&(t.minFilter=u.k6q);let d=new u.F1T(1,10,this),h=e.getMRT();return e.setMRT(null),d.update(e,l),e.setMRT(h),t.minFilter=r,t.currentGenerateMipmaps=i,o.geometry.dispose(),o.material.dispose(),this}}let oR=new WeakMap;class oA extends V{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=nr(null);let t=new u.b4q;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=w.RENDER}updateBefore(e){let{renderer:t,material:r}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){let e=i.isTextureNode?i.value:r[i.property];if(e&&e.isTexture){let r=e.mapping;if(r===u.wfO||r===u.uV5){if(oR.has(e)){let t=oR.get(e);ow(t,e.mapping),this._cubeTexture=t}else{var s;let r=e.image;if(null!=(s=r)&&s.height>0){let i=new oN(r.height);i.fromEquirectangularTexture(t,e),ow(i.texture,e.mapping),this._cubeTexture=i.texture,oR.set(e,i.texture),e.addEventListener("dispose",oE)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function oE(e){let t=e.target;t.removeEventListener("dispose",oE);let r=oR.get(t);void 0!==r&&(oR.delete(t),r.dispose())}function ow(e,t){t===u.wfO?e.mapping=u.hy7:t===u.uV5&&(e.mapping=u.xFO)}let oC=eN(oA).setParameterLength(1);class oM extends aD{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=oC(this.envNode)}}class oB extends aD{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){let t=eF(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class oP{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class oF extends oP{constructor(){super()}indirect({context:e}){let t=e.ambientOcclusion,r=e.reflectedLight,i=e.irradianceLightMap;r.indirectDiffuse.assign(eH(0)),i?r.indirectDiffuse.addAssign(i):r.indirectDiffuse.addAssign(eH(1,1,1,0)),r.indirectDiffuse.mulAssign(t),r.indirectDiffuse.mulAssign(e3.rgb)}finish(e){let{material:t,context:r}=e,i=r.outgoingLight,s=e.context.environment;if(s)switch(t.combine){case u.caT:i.rgb.assign(r0(i.rgb,i.rgb.mul(s.rgb),nz.mul(n$)));break;case u.KRh:i.rgb.assign(r0(i.rgb,s.rgb,nz.mul(n$)));break;case u.XrR:i.rgb.addAssign(s.rgb.mul(nz.mul(n$)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",t.combine)}}}let oL=new u.V9B;class oU extends oh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(oL),this.setValues(e)}setupNormal(){return sQ}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new oM(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new oB(an)),t}setupOutgoingLight(){return e3.rgb}setupLightingModel(){return new oF}}let oI=eE(({f0:e,f90:t,dotVH:r})=>{let i=r.mul(-5.55473).sub(6.98316).mul(r).exp2();return e.mul(i.oneMinus()).add(t.mul(i))}),oD=eE(e=>e.diffuseColor.mul(1/Math.PI)),oV=eE(({dotNH:e})=>td.mul(eF(.5)).add(1).mul(eF(1/Math.PI)).mul(e.pow(td))),oO=eE(({lightDirection:e})=>{let t=e.add(sz).normalize(),r=sK.dot(t).clamp(),i=oI({f0:tl,f90:1,dotVH:sz.dot(t).clamp()}),s=eF(.25),n=oV({dotNH:r});return i.mul(s).mul(n)});class oG extends oF{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let i=sK.dot(e).clamp().mul(t);r.directDiffuse.addAssign(i.mul(oD({diffuseColor:e3.rgb}))),!0===this.specular&&r.directSpecular.addAssign(i.mul(oO({lightDirection:e})).mul(nz))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;
4i.indirectDiffuse.addAssign(r.mul(oD({diffuseColor:e3}))),i.indirectDiffuse.mulAssign(t)}}let ok=new u.G_z;class oz extends oh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(ok),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new oM(t):null}setupLightingModel(){return new oG(!1)}}let o$=new u.tXL;class oW extends oh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(o$),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new oM(t):null}setupLightingModel(){return new oG}setupVariants(){let e=(this.shininessNode?eF(this.shininessNode):nI).max(1e-4);td.assign(e);let t=this.specularNode||nO;tl.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}let oH=eE(e=>{if(!1===e.geometry.hasAttribute("normal"))return eF(0);let t=sQ.dFdx().abs().max(sQ.dFdy().abs());return t.x.max(t.y).max(t.z)}),oq=eE(e=>{let{roughness:t}=e,r=oH(),i=t.max(.0525);return(i=i.add(r)).min(1)}),oj=eE(({alpha:e,dotNL:t,dotNV:r})=>{let i=e.pow2(),s=t.mul(i.add(i.oneMinus().mul(r.pow2())).sqrt()),n=r.mul(i.add(i.oneMinus().mul(t.pow2())).sqrt());return tG(.5,s.add(n).max(rt))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),oX=eE(({alphaT:e,alphaB:t,dotTV:r,dotBV:i,dotTL:s,dotBL:n,dotNV:a,dotNL:o})=>{let l=o.mul(ek(e.mul(r),t.mul(i),a).length()),u=a.mul(ek(e.mul(s),t.mul(n),o).length());return tG(.5,l.add(u)).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"}]}),oQ=eE(({alpha:e,dotNH:t})=>{let r=e.pow2(),i=t.pow2().mul(r.oneMinus()).oneMinus();return r.div(i.pow2()).mul(1/Math.PI)}
4).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),oY=eF(1/Math.PI),oK=eE(({alphaT:e,alphaB:t,dotNH:r,dotTH:i,dotBH:s})=>{let n=e.mul(t),a=ek(t.mul(i),e.mul(s),n.mul(r)),o=a.dot(a),l=n.div(o);return oY.mul(n.mul(l.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"}]}),oZ=eE(e=>{let t,r,{lightDirection:i,f0:s,f90:n,roughness:a,f:o,USE_IRIDESCENCE:l,USE_ANISOTROPY:u}=e,d=e.normalView||sK,h=a.pow2(),c=i.add(sz).normalize(),p=d.dot(i).clamp(),g=d.dot(sz).clamp(),m=d.dot(c).clamp(),f=oI({f0:s,f90:n,dotVH:sz.dot(c).clamp()});if(ex(l)&&(f=tt.mix(f,o)),ex(u)){let e=ta.dot(i),s=ta.dot(sz),n=ta.dot(c),a=to.dot(i),o=to.dot(sz),l=to.dot(c);t=oX({alphaT:ts,alphaB:h,dotTV:s,dotBV:o,dotTL:e,dotBL:a,dotNV:g,dotNL:p}),r=oK({alphaT:ts,alphaB:h,dotNH:m,dotTH:n,dotBH:l})}else t=oj({alpha:h,dotNL:p,dotNV:g}),r=oQ({alpha:h,dotNH:m});return f.mul(t).mul(r)}),oJ=eE(({roughness:e,dotNV:t})=>{let r=eH(-1,-.0275,-.572,.022),i=eH(1,.0425,1.04,-.04),s=e.mul(r).add(i),n=s.x.mul(s.x).min(t.mul(-9.28).exp2()).mul(s.x).add(s.y);return eD(-1.04,1.04).mul(n).add(s.zw)}).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),o0=eE(e=>{let{dotNV:t,specularColor:r,specularF90:i,roughness:s}=e,n=oJ({dotNV:t,roughness:s});return r.mul(n.x).add(i.mul(n.y))}),o1=eE(({f:e,f90:t,dotVH:r})=>{let i=r.oneMinus().saturate(),s=i.mul(i),n=i.mul(s,s).clamp(0,.9999);return e.sub(ek(t).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"}]}),o2=eE(({roughness:e,dotNH:t})=>{let r=e.pow2(),i=eF(1).div(r),s=t.pow2().oneMinus().max(.0078125);return eF(2).add(i).mul(s.pow(i.mul(.5))).div(2*Math.PI)}
vendor: 4,157 bytes, line 4
4).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),o3=eE(({dotNV:e,dotNL:t})=>eF(1).div(eF(4).mul(t.add(e).sub(t.mul(e))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),o4=eE(({lightDirection:e})=>{let t=e.add(sz).normalize(),r=sK.dot(e).clamp(),i=sK.dot(sz).clamp(),s=o2({roughness:te,dotNH:sK.dot(t).clamp()}),n=o3({dotNV:i,dotNL:r});return e7.mul(s).mul(n)}),o6=eE(({N:e,V:t,roughness:r})=>{let i=eD(r,e.dot(t).saturate().oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),o8=eE(({f:e})=>{let t=e.length();return rG(t.mul(t).add(e.z).div(t.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),o5=eE(({v1:e,v2:t})=>{let r=e.dot(t),i=r.abs().toVar(),s=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),a=s.div(n),o=r.greaterThan(0).select(a,rG(r.mul(r).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(a));return e.cross(t).mul(o)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),o9=eE(({N:e,V:t,P:r,mInv:i,p0:s,p1:n,p2:a,p3:o})=>{let l=n.sub(s).toVar(),u=o.sub(s).toVar(),d=l.cross(u),h=ek().toVar();return eM(d.dot(r.sub(s)).greaterThanEqual(0),()=>{let l=t.sub(e.mul(t.dot(e))).normalize(),u=e.cross(l).negate(),d=i.mul(eY(l,u,e).transpose()).toVar(),c=d.mul(s.sub(r)).normalize().toVar(),p=d.mul(n.sub(r)).normalize().toVar(),g=d.mul(a.sub(r)).normalize().toVar(),m=d.mul(o.sub(r)).normalize().toVar(),f=ek(0).toVar();f.addAssign(o5({v1:c,v2:p})),f.addAssign(o5({v1:p,v2:g})),f.addAssign(o5({v1:g,v2:m})),f.addAssign(o5({v1:m,v2:c})),h.assign(ek(o8({f:f})))}),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"}]}),o7=1/6,le=e=>tO(o7,tO(e,tO(e,e.negate().add(3)).sub(3)).add(1)),lt=e=>tO(o7,tO(e,tO(e,tO(3,e).sub(6))).add(4)),lr=e=>tO(o7,tO(e,tO(e,tO(-3,e).add(3)).add(3)).add(1)),li=e=>tO(o7,rj(e,3)),ls=e=>le(e).add(lt(e)),ln=e=>lr(e).add(li(e)),la=e=>tD(-1,lt(e).div(le(e).add(lt(e)))),lo=e=>tD(1,li(e).div(lr(e).add(li(e)))),ll=(e,t,r)=>{let i=tO(e.uvNode,t.zw).add(.5),s=rm(i),n=rx(i),a=ls(n.x),o=ln(n.x),l=la(n.x),u=lo(n.x),d=la(n.y),h=lo(n.y),c=eD(s.x.add(l),s.y.add(d)).sub(.5).mul(t.xy),p=eD(s.x.add(u),s.y.add(d)).sub(.5).mul(t.xy),g=eD(s.x.add(l),s.y.add(h)).sub(.5).mul(t.xy),m=eD(s.x.add(u),s.y.add(h)).sub(.5).mul(t.xy),f=ls(n.y).mul(tD(a.mul(e.sample(c).level(r)),o.mul(e.sample(p).level(r)))),y=ln(n.y).mul(tD(a.mul(e.sample(g).level(r)),o.mul(e.sample(m).level(r))));return f.add(y)},lu=eE(([e,t=eF(3)])=>{let r=eD(e.size(eL(t))),i=eD(e.size(eL(t.add(1)))),s=tG(1,r),n=tG(1,i),a=ll(e,eH(s,r),rm(t)),o=ll(e,eH(n,i),rf(t));return rx(t).mix(a,o)}),ld=eE(([e,t,r,i,s])=>{let n=ek(r3(t.negate(),ry(e),tG(1,i))),a=ek(rE(s[0].xyz),rE(s[1].xyz),rE(s[2].xyz));return ry(n).mul(r.mul(a))}).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"}]}),lh=eE(([e,t])=>e.mul(r1(t.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),lc=a2(),lp=a2(),lg=eE(([e,t,r],{material:i})=>lu((i.side===u.hsX?lc:lp).sample(e),rc(aW.x).mul(lh(t,r)))),lm=eE(([e,t,r])=>(eM(r.notEqual(0),()=>ru(rh(t).negate().div(r).negate().mul(e))),ek(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),lf=eE(([e,t,r,i,s,n,a,o,l,u,d,h,c,p,g])=>{let m,f;if(g){m=eH().toVar(),f=ek().toVar();let s=d.sub(1).mul(g.mul(.025)),n=ek(d.sub(s),d,d.add(s));aM({start:0,end:3},({i:s})=>
4{let d=n.element(s),g=ld(e,t,h,d,o),y=a.add(g),x=u.mul(l.mul(eH(y,1))),b=eD(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(eD(b.x,b.y.oneMinus()));let T=lg(b,r,d);m.element(s).assign(T.element(s)),m.a.addAssign(T.a),f.element(s).assign(i.element(s).mul(lm(rE(g),c,p).element(s)))}),m.a.divAssign(3)}else{let s=ld(e,t,h,d,o),n=a.add(s),g=u.mul(l.mul(eH(n,1))),y=eD(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(eD(y.x,y.y.oneMinus())),m=lg(y,r,d),f=i.mul(lm(rE(s),c,p))}let y=f.rgb.mul(m.rgb),x=ek(o0({dotNV:e.dot(t).clamp(),specularColor:s,specularF90:n,roughness:r})),b=f.r.add(f.g,f.b).div(3);return eH(x.oneMinus().mul(y),m.a.oneMinus().mul(b).oneMinus())}),ly=eY(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),lx=(e,t)=>e.sub(t).div(e.add(t)).pow2(),lb=eE(({outsideIOR:e,eta2:t,cosTheta1:r,thinFilmThickness:i,baseF0:s})=>{let n=r0(e,t,r4(0,.03,i)),a=e.div(n).pow2().mul(r.pow2().oneMinus()).oneMinus();eM(a.lessThan(0),()=>ek(1));let o=a.sqrt(),l=oI({f0:lx(n,e),f90:1,dotVH:r}),u=l.oneMinus(),d=n.lessThan(e).select(Math.PI,0),h=eF(Math.PI).sub(d),c=(e=>{let t=e.sqrt();return ek(1).add(t).div(ek(1).sub(t))})(s.clamp(0,.9999)),p=oI({f0:lx(c,n.toVec3()),f90:1,dotVH:o}),g=ek(c.x.lessThan(n).select(Math.PI,0),c.y.lessThan(n).select(Math.PI,0),c.z.lessThan(n).select(Math.PI,0)),m=n.mul(i,o,2),f=ek(h).add(g),y=l.mul(p).clamp(1e-5,.9999),x=y.sqrt(),b=u.pow2().mul(p).div(ek(1).sub(y)),T=l.add(b).toVar(),_=b.sub(u).toVar();return aM({start:1,end:2,condition:"<=",name:"m"},({m:e})=>{_.mulAssign(x);let t=((e,t)=>{let r=e.mul(2*Math.PI*1e-9),i=ek(54856e-17,44201e-17,52481e-17),s=ek(1681e3,1795300,2208400),n=ek(43278e5,93046e5,66121e5),a=eF(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(r.mul(2239900).add(t.x).cos()).mul(r.pow2().mul(-45282e5).exp()),o=i.mul(n.mul(2*Math.PI).sqrt()).mul(s.mul(r).add(t).cos()).mul(r.pow2().negate().mul(n).exp());return o=ek(o.x.add(a),o.y,o.z).div(10685e-11),ly.mul(o)})(eF(e).mul(m),eF(e).mul(f)).mul(2);T.addAssign(_.mul(t))}),T.max(ek(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"}]}),lT=eE(({normal:e,viewDir:t,roughness:r})=>{let i=e.dot(t).saturate(),s=r.pow2(),n=it(r.lessThan(.25),eF(-339.2).mul(s).add(eF(161.4).mul(r)).sub(25.9),eF(-8.48).mul(s).add(eF(14.3).mul(r)).sub(9.95)),a=it(r.lessThan(.25),eF(44).mul(s).sub(eF(23.7).mul(r)).add(3.26),eF(1.97).mul(s).sub(eF(3.27).mul(r)).add(.72));return it(r.lessThan(.25),0,eF(.1).mul(r).sub(.025)).add(n.mul(i).add(a).exp()).mul(1/Math.PI).saturate()}),l_=ek(.04),lv=eF(1);class lS extends oP{constructor(e=!1,t=!1,r=!1,i=!1,s=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=r,this.anisotropy=i,this.transmission=s,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=ek().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=ek().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=ek().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=ek().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=ek().toVar("sheenSpecularIndirect")),!0===this.iridescence){let e=sK.dot(sz).clamp();this.iridescenceFresnel=lb({outsideIOR:eF(1),eta2:tr,cosTheta1:e,thinFilmThickness:ti,baseF0:tl}),this.iridescenceF0=o1({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){let t=sg.sub(sO).normalize(),r=e.context;r.backdrop=lf(sZ,t,e6,e3,tl,tu,sO,sR,sh,su,tm,ty,tb,tx,this.dispersion?tT:null),r.backdropAlpha=tf,e3.a.mulAssign(r0(1,r.backdrop.a,tf))}super.start(e)}computeMultiscattering(e,t,r){let i=oJ({roughness:e6,dotNV:sK.dot(sz).clamp()}),s=(this.iridescenceF0?tt.mix(tl,this.iridescenceF0):tl).mul(i.x).add(r.mul(i.y)),n=i.x.add(i.y).oneMinus(),a=tl.add(tl.oneMinus().mul(.047619)),o=s.mul(a).div(n.mul(a).oneMinus());e.addAssign(s),t.addAssign(o.mul(n))}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let i=sK.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(o4({lightDirection:e}))),!0===this.clearcoat){let r=sJ.dot(e).clamp().mul(t);
vendor: 4,452 bytes, line 4
4this.clearcoatSpecularDirect.addAssign(r.mul(oZ({lightDirection:e,f0:l_,f90:lv,roughness:e9,normalView:sJ})))}r.directDiffuse.addAssign(i.mul(oD({diffuseColor:e3.rgb}))),r.directSpecular.addAssign(i.mul(oZ({lightDirection:e,f0:tl,f90:1,roughness:e6,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:i,reflectedLight:s,ltc_1:n,ltc_2:a}){let o=t.add(r).sub(i),l=t.sub(r).sub(i),u=t.sub(r).add(i),d=t.add(r).add(i),h=sk.toVar(),c=o6({N:sK,V:sz,roughness:e6}),p=n.sample(c).toVar(),g=a.sample(c).toVar(),m=eY(ek(p.x,0,p.y),ek(0,1,0),ek(p.z,0,p.w)).toVar(),f=tl.mul(g.x).add(tl.oneMinus().mul(g.y)).toVar();s.directSpecular.addAssign(e.mul(f).mul(o9({N:sK,V:sz,P:h,mInv:m,p0:o,p1:l,p2:u,p3:d}))),s.directDiffuse.addAssign(e.mul(e3).mul(o9({N:sK,V:sz,P:h,mInv:eY(1,0,0,0,1,0,0,0,1),p0:o,p1:l,p2:u,p3:d})))}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){let{irradiance:t,reflectedLight:r}=e.context;r.indirectDiffuse.addAssign(t.mul(oD({diffuseColor:e3})))}indirectSpecular(e){let{radiance:t,iblIrradiance:r,reflectedLight:i}=e.context;if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(r.mul(e7,lT({normal:sK,viewDir:sz,roughness:te}))),!0===this.clearcoat){let e=o0({dotNV:sJ.dot(sz).clamp(),specularColor:l_,specularF90:lv,roughness:e9});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}let s=ek().toVar("singleScattering"),n=ek().toVar("multiScattering"),a=r.mul(1/Math.PI);this.computeMultiscattering(s,n,tu);let o=s.add(n),l=e3.mul(o.r.max(o.g).max(o.b).oneMinus());i.indirectSpecular.addAssign(t.mul(s)),i.indirectSpecular.addAssign(n.mul(a)),i.indirectDiffuse.addAssign(l.mul(a))}ambientOcclusion(e){let{ambientOcclusion:t,reflectedLight:r}=e.context,i=sK.dot(sz).clamp().add(t),s=e6.mul(-16).oneMinus().negate().exp2(),n=t.sub(i.pow(s).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),r.indirectDiffuse.mulAssign(t),r.indirectSpecular.mulAssign(n)}finish({context:e}){let{outgoingLight:t}=e;if(!0===this.clearcoat){let e=oI({dotVH:sJ.dot(sz).clamp(),f0:l_,f90:lv}),r=t.mul(e5.mul(e).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(e5));t.assign(r)}if(!0===this.sheen){let e=e7.r.max(e7.g).max(e7.b).mul(.157).oneMinus(),r=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(r)}}}let lN=eF(1),lR=eF(-2),lA=eF(.8),lE=eF(-1),lw=eF(.4),lC=eF(2),lM=eF(.305),lB=eF(3),lP=eF(.21),lF=eF(4),lL=eF(4),lU=eF(16),lI=eE(([e])=>{let t=ek(rR(e)).toVar(),r=eF(-1).toVar();return eM(t.x.greaterThan(t.z),()=>{eM(t.x.greaterThan(t.y),()=>{r.assign(it(e.x.greaterThan(0),0,3))}).Else(()=>{r.assign(it(e.y.greaterThan(0),1,4))})}).Else(()=>{eM(t.z.greaterThan(t.y),()=>{r.assign(it(e.z.greaterThan(0),2,5))}).Else(()=>{r.assign(it(e.y.greaterThan(0),1,4))})}),r}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),lD=eE(([e,t])=>{let r=eD().toVar();return eM(t.equal(0),()=>{r.assign(eD(e.z,e.y).div(rR(e.x)))}).ElseIf(t.equal(1),()=>{r.assign(eD(e.x.negate(),e.z.negate()).div(rR(e.y)))}).ElseIf(t.equal(2),()=>{r.assign(eD(e.x.negate(),e.y).div(rR(e.z)))}).ElseIf(t.equal(3),()=>{r.assign(eD(e.z.negate(),e.y).div(rR(e.x)))}).ElseIf(t.equal(4),()=>{r.assign(eD(e.x.negate(),e.z).div(rR(e.y)))}).Else(()=>{r.assign(eD(e.x,e.y).div(rR(e.z)))}),tO(.5,r.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),lV=eE(([e])=>{let t=eF(0).toVar();return eM(e.greaterThanEqual(lA),()=>{t.assign(lN.sub(e).mul(lE.sub(lR)).div(lN.sub(lA)).add(lR))}).ElseIf(e.greaterThanEqual(lw),()=>{t.assign(lA.sub(e).mul(lC.sub(lE)).div(lA.sub(lw)).add(lE))}).ElseIf(e.greaterThanEqual(lM),()=>{t.assign(lw.sub(e).mul(lB.sub(lC)).div(lw.sub(lM)).add(lC))}).ElseIf(e.greaterThanEqual(lP),()=>{t.assign(lM.sub(e).mul(lF.sub(lB)).div(lM.sub(lP)).add(lB))}).Else(()=>{t.assign(eF(-2).mul(rc(tO(1.16,e))))}),t}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),lO=eE(([e,t])=>{let r=e.toVar();r.assign(tO(2,r).sub(1));let i=ek(r,1).toVar();return eM(t.equal(0),()=>{i.assign(i.zyx)}).ElseIf(t.equal(1),()=>{i.assign(i.xzy),i.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{i.x.mulAssign(-1)}
4).ElseIf(t.equal(3),()=>{i.assign(i.zyx),i.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{i.assign(i.xzy),i.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{i.z.mulAssign(-1)}),i}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),lG=eE(([e,t,r,i,s,n])=>{let a=eF(r),o=ek(t),l=r1(lV(a),lR,n),u=rx(l),d=rm(l),h=ek(lk(e,o,d,i,s,n)).toVar();return eM(u.notEqual(0),()=>{let t=ek(lk(e,o,d.add(1),i,s,n)).toVar();h.assign(r0(h,t,u))}),h}),lk=eE(([e,t,r,i,s,n])=>{let a=eF(r).toVar(),o=ek(t),l=eF(lI(o)).toVar(),u=eF(rG(lL.sub(a),0)).toVar();a.assign(rG(a,lL));let d=eF(rd(a)).toVar(),h=eD(lD(o,l).mul(d.sub(2)).add(1)).toVar();return eM(l.greaterThan(2),()=>{h.y.addAssign(d),l.subAssign(3)}),h.x.addAssign(l.mul(d)),h.x.addAssign(u.mul(tO(3,lU))),h.y.addAssign(tO(4,rd(n).sub(d))),h.x.mulAssign(i),h.y.mulAssign(s),e.sample(h).grad(eD(),eD())}),lz=eE(({envMap:e,mipInt:t,outputDirection:r,theta:i,axis:s,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{let l=rT(i);return lk(e,r.mul(l).add(s.cross(r).mul(rb(i))).add(s.mul(s.dot(r).mul(l.oneMinus()))),t,n,a,o)}),l$=eE(({n:e,latitudinal:t,poleAxis:r,outputDirection:i,weights:s,samples:n,dTheta:a,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h})=>{let c=ek(it(t,r,rq(r,i))).toVar();eM(c.equal(ek(0)),()=>{c.assign(ek(i.z,0,i.x.negate()))}),c.assign(ry(c));let p=ek().toVar();return p.addAssign(s.element(0).mul(lz({theta:0,axis:c,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h}))),aM({start:eL(1),end:e},({i:e})=>{eM(e.greaterThanEqual(n),()=>{aB()});let t=eF(a.mul(eF(e))).toVar();p.addAssign(s.element(e).mul(lz({theta:t.mul(-1),axis:c,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h}))),p.addAssign(s.element(e).mul(lz({theta:t,axis:c,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:h})))}),eH(p,1)}),lW=[.125,.215,.35,.446,.526,.582],lH=new u.qUd(-1,1,1,-1,0,1),lq=new u.ubm(90,1),lj=new u.Q1f,lX=null,lQ=0,lY=0,lK=(1+Math.sqrt(5))/2,lZ=1/lK,lJ=[new u.Pq0(-lK,lZ,0),new u.Pq0(lK,lZ,0),new u.Pq0(-lZ,0,lK),new u.Pq0(lZ,0,lK),new u.Pq0(0,lK,-lZ),new u.Pq0(0,lK,lZ),new u.Pq0(-1,1,-1),new u.Pq0(1,1,-1),new u.Pq0(-1,1,1),new u.Pq0(1,1,1)],l0=new u.Pq0,l1=new WeakMap,l2=[3,1,5,0,4,2],l3=lO(i1(),i0("faceIndex")).normalize(),l4=ek(l3.x,l3.y,l3.z);class l6{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,r=.1,i=100,s={}){let{size:n=256,position:a=l0,renderTarget:o=null}=s;if(this._setSize(n),!1===this._hasInitialized){console.warn("THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.");let n=o||this._allocateTargets();return s.renderTarget=n,this.fromSceneAsync(e,t,r,i,s),n}lX=this._renderer.getRenderTarget(),lQ=this._renderer.getActiveCubeFace(),lY=this._renderer.getActiveMipmapLevel();let l=o||this._allocateTargets();return l.depthBuffer=!0,this._sceneToCubeUV(e,r,i,l,a),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}async fromSceneAsync(e,t=0,r=.1,i=100,s={}){return!1===this._hasInitialized&&await this._renderer.init(),this.fromScene(e,t,r,i,s)}fromEquirectangular(e,t=null){if(!1===this._hasInitialized){console.warn("THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead."),this._setSizeFromTexture(e);let r=t||this._allocateTargets();return this.fromEquirectangularAsync(e,r),r}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return!1===this._hasInitialized&&await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(!1===this._hasInitialized){console.warn("THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);let r=t||this._allocateTargets();return this.fromCubemapAsync(e,t),r}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return!1===this._hasInitialized&&await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=l7(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=ue(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===u.hy7||e.mapping===u.xFO?this._setSize(0===e.image.length?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(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget(lX,lQ,lY),e.scissorTest=!1,l5(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),lX=this._renderer.getRenderTarget(),lQ=this._renderer.getActiveCubeFace(),lY=this._renderer.getActiveMipmapLevel();let r=t||this._allocateTargets();return this._textureToCubeUV(e,r),this._applyPMREM(r),this._cleanup(r),r}_allocateTargets(){let e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,r={magFilter:u.k6q,minFilter:u.k6q,generateMipmaps:!1,type:u.ix0,format:u.GWd,colorSpace:u.Zr2},i=l8(e,t,r);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=l8(e,t,r);let{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}
4=function(e){let t=[],r=[],i=[],s=[],n=e,a=e-4+1+lW.length;for(let o=0;o<a;o++){let a=Math.pow(2,n);r.push(a);let l=1/a;o>e-4?l=lW[o-e+4-1]:0===o&&(l=0),i.push(l);let d=1/(a-2),h=-d,c=1+d,p=[h,h,c,h,c,c,h,h,c,c,h,c],g=new Float32Array(108),m=new Float32Array(72),f=new Float32Array(36);for(let e=0;e<6;e++){let t=e%3*2/3-1,r=e>2?0:-1,i=[t,r,0,t+2/3,r,0,t+2/3,r+1,0,t,r,0,t+2/3,r+1,0,t,r+1,0],s=l2[e];g.set(i,18*s),m.set(p,12*s);let n=[s,s,s,s,s,s];f.set(n,6*s)}let y=new u.LoY;y.setAttribute("position",new u.THS(g,3)),y.setAttribute("uv",new u.THS(m,2)),y.setAttribute("faceIndex",new u.THS(f,1)),t.push(y),s.push(new u.eaF(y,null)),n>4&&n--}return{lodPlanes:t,sizeLods:r,sigmas:i,lodMeshes:s}}(i)),this._blurMaterial=function(e,t,r){let i=si(Array(20).fill(0)),s=tw(new u.Pq0(0,1,0)),n=tw(0),a=eF(20),o=tw(0),l=tw(1),d=i5(null),h=tw(0),c=eF(1/t),p={n:a,latitudinal:o,weights:i,poleAxis:s,outputDirection:l4,dTheta:n,samples:l,envMap:d,mipInt:h,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:eF(1/r),CUBEUV_MAX_MIP:eF(e)},g=l9("blur");return g.fragmentNode=l$({...p,latitudinal:o.equal(1)}),l1.set(g,p),g}(i,e,t)}return i}async _compileMaterial(e){let t=new u.eaF(this._lodPlanes[0],e);await this._renderer.compile(t,lH)}_sceneToCubeUV(e,t,r,i,s){lq.near=t,lq.far=r;let n=[1,1,1,1,-1,1],a=[1,-1,1,-1,1,-1],o=this._renderer,l=o.autoClear;o.getClearColor(lj),o.autoClear=!1;let d=this._backgroundBox;
4if(null===d){let e=new u.V9B({name:"PMREM.Background",side:u.hsX,depthWrite:!1,depthTest:!1});d=new u.eaF(new u.iNn,e)}let h=!1,c=e.background;c?c.isColor&&(d.material.color.copy(c),e.background=null,h=!0):(d.material.color.copy(lj),h=!0),o.setRenderTarget(i),o.clear(),h&&o.render(d,lq);for(let t=0;t<6;t++){let r=t%3;0===r?(lq.up.set(0,n[t],0),lq.position.set(s.x,s.y,s.z),lq.lookAt(s.x+a[t],s.y,s.z)):1===r?(lq.up.set(0,0,n[t]),lq.position.set(s.x,s.y,s.z),lq.lookAt(s.x,s.y+a[t],s.z)):(lq.up.set(0,n[t],0),lq.position.set(s.x,s.y,s.z),lq.lookAt(s.x,s.y,s.z+a[t]));let l=this._cubeSize;l5(i,r*l,t>2?l:0,l,l),o.render(e,lq)}o.autoClear=l,e.background=c}_textureToCubeUV(e,t){let r=this._renderer,i=e.mapping===u.hy7||e.mapping===u.xFO;i?null===this._cubemapMaterial&&(this._cubemapMaterial=l7(e)):null===this._equirectMaterial&&(this._equirectMaterial=ue(e));let s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=e;let n=this._lodMeshes[0];n.material=s;let a=this._cubeSize;l5(t,0,0,3*a,2*a),r.setRenderTarget(t),r.render(n,lH)}_applyPMREM(e){let t=this._renderer,r=t.autoClear;t.autoClear=!1;let i=this._lodPlanes.length;for(let t=1;t<i;t++){let r=Math.sqrt(this._sigmas[t]*this._sigmas[t]-this._sigmas[t-1]*this._sigmas[t-1]),s=lJ[(i-t-1)%lJ.length];this._blur(e,t-1,t,r,s)}t.autoClear=r}_blur(e,t,r,i,s){let n=this._pingPongRenderTarget;this._halfBlur(e,n,t,r,i,"latitudinal",s),this._halfBlur(n,e,r,r,i,"longitudinal",s)}_halfBlur(e,t,r,i,s,n,a){let o=this._renderer,l=this._blurMaterial;"latitudinal"!==n&&"longitudinal"!==n&&console.error("blur direction must be either latitudinal or longitudinal!");let u=this._lodMeshes[i];u.material=l;let d=l1.get(l),h=this._sizeLods[r]-1,c=isFinite(s)?Math.PI/(2*h):2*Math.PI/39,p=s/c,g=isFinite(s)?1+Math.floor(3*p):20;g>20&&console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);let m=[],f=0;for(let e=0;e<20;++e){let t=e/p,r=Math.exp(-t*t/2);m.push(r),0===e?f+=r:e<g&&(f+=2*r)}for(let e=0;e<m.length;e++)m[e]=m[e]/f;e.texture.frame=(e.texture.frame||0)+1,d.envMap.value=e.texture,d.samples.value=g,d.weights.array=m,d.latitudinal.value=+("latitudinal"===n),a&&(d.poleAxis.value=a);let{_lodMax:y}=this;d.dTheta.value=c,d.mipInt.value=y-r;let x=this._sizeLods[i],b=4*(this._cubeSize-x);l5(t,3*x*(i>y-4?i-y+4:0),b,3*x,2*x),o.setRenderTarget(t),o.render(u,lH)}}function l8(e,t,r){let i=new u.O0B(e,t,r);return i.texture.mapping=u.Om,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function l5(e,t,r,i,s){e.viewport.set(t,r,i,s),e.scissor.set(t,r,i,s)}function l9(e){let t=new oh;return t.depthTest=!1,t.depthWrite=!1,t.blending=u.XIg,t.name=`PMREM_${e}`,t}function l7(e){let t=l9("cubemap");return t.fragmentNode=nr(e,l4),t}function ue(e){let t=l9("equirect");return t.fragmentNode=i5(e,oS(l4),0),t}let ut=new WeakMap;class ur extends V{static get type(){return"PMREMNode"}constructor(e,t=null,r=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=r,this._generator=null;let i=new u.gPd;i.isRenderTargetTexture=!0,this._texture=i5(i),this._width=tw(0),this._height=tw(0),this._maxMip=tw(0),this.updateBeforeType=w.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){let t=function(e){let t=Math.log2(e)-2;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:1/e,maxMip:t}}(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,r=t?t.pmremVersion:-1,i=this._value;r!==i.pmremVersion&&null!==(t=!0===i.isPMREMTexture?i:function(e,t,r){var i,s;let n,a=(i=t,void 0===(n=ut.get(i))&&(n=new WeakMap,ut.set(i,n)),n),o=a.get(e);if((void 0!==o?o.pmremVersion:-1)!==e.pmremVersion){let t=e.image;if(e.isCubeTexture)if(!function(e){if(null==e)return!1;let t=0;for(let r=0;r<6;r++)void 0!==e[r]&&t++;return 6===t}(t))return null;else o=r.fromCubemap(e,o);else{if(!(null!=(s=t)&&s.height>0))return null;o=r.fromEquirectangular(e,o)}o.pmremVersion=e.pmremVersion,a.set(e,o)}return o.texture}(i,e.renderer,this._generator))&&(this._pmrem=t,this.updateFromTexture(t))}setup(e){null===this._generator&&(this._generator=new l6(e.renderer)),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this)),t=s8.mul(ek(t.x,t.y.negate(),t.z));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),lG(this._texture,t,r,this._width,this._height,this._maxMip)}dispose(){super.dispose(),null!==this._generator&&this._generator.dispose()}}let ui=eN(ur).setParameterLength(1,3),us=new WeakMap;class un extends aD{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){let{material:t}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){let e=r.isTextureNode?r.value:t[r.property],i=us.get(e);void 0===i&&(i=ui(e),us.set(e,i)),r=i}let i=!0===t.useAnisotropy||t.anisotropy>0?nN:sK,s=r.context(ua(e6,i)).mul(s6),n=r.context(uo(sZ)).mul(Math.PI).mul(s6),a=iG(s),o=iG(n);
4e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(o);let l=e.context.lightingModel.clearcoatRadiance;if(l){let e=iG(r.context(ua(e9,sJ)).mul(s6));l.addAssign(e)}}}let ua=(e,t)=>{let r=null;return{getUV:()=>(null===r&&(r=sz.negate().reflect(t),r=(r=e.mul(e).mix(r,t).normalize()).transformDirection(sh)),r),getTextureLevel:()=>e}},uo=e=>({getUV:()=>e,getTextureLevel:()=>eF(1)}),ul=new u._4j;class uu extends oh{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(ul),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new un(t):null}setupLightingModel(){return new lS}setupSpecular(){let e=r0(ek(.04),e3.rgb,e8);tl.assign(e),tu.assign(1)}setupVariants(){let e=this.metalnessNode?eF(this.metalnessNode):nH;e8.assign(e);let t=this.roughnessNode?eF(this.roughnessNode):nW;t=oq({roughness:t}),e6.assign(t),this.setupSpecular(),e3.assign(eH(e3.rgb.mul(e.oneMinus()),e3.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}let ud=new u.uSd;class uh extends uu{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(ud),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){let e=this.iorNode?eF(this.iorNode):n6;tm.assign(e),tl.assign(r0(rO(rX(tm.sub(1).div(tm.add(1))).mul(nk),ek(1)).mul(nG),e3.rgb,e8)),tu.assign(r0(nG,1,e8))}setupLightingModel(){return new lS(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){let e=this.clearcoatNode?eF(this.clearcoatNode):nj,t=this.clearcoatRoughnessNode?eF(this.clearcoatRoughnessNode):nX;e5.assign(e),e9.assign(oq({roughness:t}))}if(this.useSheen){let e=this.sheenNode?ek(this.sheenNode):nK,t=this.sheenRoughnessNode?eF(this.sheenRoughnessNode):nZ;e7.assign(e),te.assign(t)}if(this.useIridescence){let e=this.iridescenceNode?eF(this.iridescenceNode):n0,t=this.iridescenceIORNode?eF(this.iridescenceIORNode):n1,r=this.iridescenceThicknessNode?eF(this.iridescenceThicknessNode):n2;tt.assign(e),tr.assign(t),ti.assign(r)}if(this.useAnisotropy){let e=(this.anisotropyNode?eD(this.anisotropyNode):nJ).toVar();tn.assign(e.length()),eM(tn.equal(0),()=>{e.assign(eD(1,0))}).Else(()=>{e.divAssign(eD(tn)),tn.assign(tn.saturate())}),ts.assign(tn.pow2().mix(e6.pow2(),1)),ta.assign(nv[0].mul(e.x).add(nv[1].mul(e.y))),to.assign(nv[1].mul(e.x).sub(nv[0].mul(e.y)))}if(this.useTransmission){let e=this.transmissionNode?eF(this.transmissionNode):n3,t=this.thicknessNode?eF(this.thicknessNode):n4,r=this.attenuationDistanceNode?eF(this.attenuationDistanceNode):n8,i=this.attenuationColorNode?ek(this.attenuationColorNode):n5;if(tf.assign(e),ty.assign(t),tx.assign(r),tb.assign(i),this.useDispersion){let e=this.dispersionNode?eF(this.dispersionNode):as;tT.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?ek(this.clearcoatNormalNode):nQ}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),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.dis
4persionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}let uc=eE(({normal:e,lightDirection:t,builder:r})=>{let i=eD(e.dot(t).mul(.5).add(.5),0);if(r.material.gradientMap)return ek(nl("gradientMap","texture").context({getUV:()=>i}).r);{let e=i.fwidth().mul(.5);return r0(ek(.7),ek(1),r4(eF(.7).sub(e.x),eF(.7).add(e.x),i.x))}});class up extends oP{direct({lightDirection:e,lightColor:t,reflectedLight:r},i){let s=uc({normal:sq,lightDirection:e,builder:i}).mul(t);r.directDiffuse.addAssign(s.mul(oD({diffuseColor:e3.rgb})))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(oD({diffuseColor:e3}))),i.indirectDiffuse.mulAssign(t)}}let ug=new u.Df;class um extends oh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(ug),this.setValues(e)}setupLightingModel(){return new up}}class uf extends V{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){let e=ek(sz.z,0,sz.x.negate()).normalize(),t=sz.cross(e);return eD(e.dot(sK),t.dot(sK)).mul(.495).add(.5)}}let uy=eR(uf),ux=new u.FNr;class ub extends oh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(ux),this.setValues(e)}setupVariants(e){let t;t=e.material.matcap?nl("matcap","texture").context({getUV:()=>uy}):ek(r0(.2,.8,uy.y)),e3.rgb.mulAssign(t.rgb)}}class uT extends V{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){let{rotationNode:t,positionNode:r}=this;if("vec2"===this.getNodeType(e)){let e=t.cos(),i=t.sin();return eQ(e,i,i.negate(),e).mul(r)}{let e=eK(eH(1,0,0,0),eH(0,rT(t.x),rb(t.x).negate(),0),eH(0,rb(t.x),rT(t.x),0),eH(0,0,0,1)),i=eK(eH(rT(t.y),0,rb(t.y),0),eH(0,1,0,0),eH(rb(t.y).negate(),0,rT(t.y),0),eH(0,0,0,1)),s=eK(eH(rT(t.z),rb(t.z).negate(),0,0),eH(rb(t.z),rT(t.z),0,0),eH(0,0,1,0),eH(0,0,0,1));return e.mul(i).mul(s).mul(eH(r,1)).xyz}}}let u_=eN(uT).setParameterLength(2),uv=new u.RoJ;class uS extends oh{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(uv),this.setValues(e)}setupPositionView(e){let{object:t,camera:r}=e,i=this.sizeAttenuation,{positionNode:s,rotationNode:n,scaleNode:a}=this,o=sP.mul(ek(s||0)),l=eD(sR[0].xyz.length(),sR[1].xyz.length());if(null!==a&&(l=l.mul(eD(a))),!1===i)if(r.isPerspectiveCamera)l=l.mul(o.z.negate());else{let e=eF(2).div(su.element(1).element(1));l=l.mul(e.mul(2))}let u=sI.xy;if(t.center&&!0===t.center.isVector2){let e=e_(new iA("center","vec2",t));u=u.sub(e.sub(.5))}let d=u_(u=u.mul(l),eF(n||nY));return eH(o.xy.add(d),o.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)}}let uN=new u.BH$;class uR extends uS{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(uN),this.setValues(e)}setupPositionView(){let{positionNode:e}=this;return sP.mul(ek(e||sD)).xyz}setupVertex(e){let t=super.setupVertex(e);if(!0!==e.material.isNodeMaterial)return t;let{rotationNode:r,scaleNode:i,sizeNode:s}=this,n=sI.xy.toVar(),a=aq.z.div(aq.w);if(r&&r.isNode){let e=eF(r);n.assign(u_(n,e))}let o=null!==s?eD(s):ai;return!0===this.sizeAttenuation&&(o=o.mul(o.div(sk.z.negate()))),i&&i.isNode&&(o=o.mul(eD(i))),n.mulAssign(o.mul(2)),n.assign(n.div(aq.z)),n.y.assign(n.y.mul(a)),n.assign(n.mul(t.w)),t.addAssign(eH(n,0,0)),t}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}class uA extends oP{constructor(){super(),this.shadowNode=eF(1).toVar("shadowMask")}direct({lightNode:e}){this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){e3.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(e3.rgb)}}let uE=new u.q2;class uw extends oh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(uE),this.setValues(e)}setupLightingModel(){return new uA}}e1("vec3"),e1("vec3"),e1("vec3");class uC{constructor(e,t){this.nodes=e,this.info=t,this._context="undefined"!=typeof self?self:null,this._animationLoop=null,this._requestId=null}start(){let e=(t,r)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(
4),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,r)};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 uM{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let r=0;r<e.length-1;r++)if(void 0===(t=t.get(e[r])))return;return t.get(e[e.length-1])}set(e,t){let r=this.weakMap;for(let t=0;t<e.length-1;t++){let i=e[t];!1===r.has(i)&&r.set(i,new WeakMap),r=r.get(i)}return r.set(e[e.length-1],t),this}delete(e){let t=this.weakMap;for(let r=0;r<e.length-1;r++)if(void 0===(t=t.get(e[r])))return!1;return t.delete(e[e.length-1])}}let uB=0;class uP{constructor(e,t,r,i,s,n,a,o,l,u){this.id=uB++,this._nodes=e,this._geometries=t,this.renderer=r,this.object=i,this.material=s,this.scene=n,this.camera=a,this.lightsNode=o,this.context=l,this.geometry=i.geometry,this.version=s.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=u,this.clippingContextCacheKey=null!==u?u.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.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?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(let 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}getAttributes(){if(null!==this.attributes)return this.attributes;let e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,r=[],i=new Set;for(let s of e){let e=s.node&&s.node.attribute?s.node.attribute:t.getAttribute(s.name);if(void 0===e)continue;r.push(e);let n=e.isInterleavedBufferAttribute?e.data:e;i.add(n)}return this.attributes=r,this.vertexBuffers=Array.from(i.values()),r}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){let{object:e,material:t,geometry:r,group:i,drawRange:s}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),o=null!==a,l=1;if(!0===r.isInstancedBufferGeometry?l=r.instanceCount:void 0!==e.count&&(l=Math.max(0,e.count)),0===l)return null;if(n.instanceCount=l,!0===e.isBatchedMesh)return n;let u=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(u=2);let d=s.start*u,h=(s.start+s.count)*u;null!==i&&(d=Math.max(d,i.start*u),h=Math.min(h,(i.start+i.count)*u));let c=r.attributes.position,p=1/0;o?p=a.count:null!=c&&(p=c.count),d=Math.max(d,0);let g=(h=Math.min(h,p))-d;return g<0||g===1/0?null:(n.vertexCount=g,n.firstVertex=d,n)}getGeometryCacheKey(){let{geometry:e}=this,t="";for(let r of Object.keys(e.attributes).sort()){let i=e.attributes[r];t+=r+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(let r of Object.keys(e.morphAttributes).sort()){let i=e.morphAttributes[r];t+="morph-"+r+",";for(let e=0,r=i.length;e<r;e++)t+=i[e].id+","}return e.index&&(t+="index,"),t}getMaterialCacheKey(){let{object:e,material:t}=this,r=t.customProgramCacheKey();for(let e of function(e){let t=Object.keys(e),r=Object.getPrototypeOf(e);for(;r;){let e=Object.getOwnPropertyDescriptors(r);for(let r in e)if(void 0!==e[r]){let i=e[r];i&&"function"==typeof i.get&&t.push(r)}r=Object.getPrototypeOf(r)}return t}(t)){let i;if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;let s=t[e];if(null!==s){let e=typeof s;"number"===e?i=0!==s?"1":"0":"object"===e?(i="{",s.isTexture&&(i+=s.mapping),i+="}"):i=String(s)}else i=String(s);r+=i+","}return r+=this.clippingContextCacheKey+",",e.geometry&&(r+=this.getGeometryCacheKey()),e.skeleton&&(r+=e.skeleton.bones.length+","),e.isBatchedMesh&&(r+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(r+=e._colorsTexture.uuid+",")),e.count>1&&(r+=e.uuid+","),p(r+=e.receiveShadow+",")}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return!0!==this.material.isShadowPassMaterial&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=m(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=m(e,1)),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}let uF=[];class uL{constructor(e,t,r,i,s,n){this.renderer=e,this.nodes=t,this.geometries=r,this.pipelines=i,this.bindings=s,this.info=n,this.chainMaps={}}get(e,t,r,i,s,n,a,o){let l=this.getChainMap(o);uF[0]=e,uF[1]=t,uF[2]=n,uF[3]=s;let u=l.get(uF);return void 0===u?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,r,i,s,n,a,o),l.set(uF,u)):(u.updateClipping(a),u.needsGeometryUpdate&&u.setGeometry(e.geometry),(u.version!==t.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dis
4pose(),u=this.get(e,t,r,i,s,n,a,o)):u.version=t.version)),uF.length=0,u}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new uM)}dispose(){this.chainMaps={}}createRenderObject(e,t,r,i,s,n,a,o,l,u,d){let h=this.getChainMap(d),c=new uP(e,t,r,i,s,n,a,o,l,u);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),h.delete(c.getChainArray())},c}}class uU{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(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}}let uI={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4};class uD extends uU{constructor(e){super(),this.backend=e}delete(e){let t=super.delete(e);return null!==t&&this.backend.destroyAttribute(e),t}update(e,t){let r=this.get(e);if(void 0===r.version)t===uI.VERTEX?this.backend.createAttribute(e):t===uI.INDEX?this.backend.createIndexAttribute(e):t===uI.STORAGE?this.backend.createStorageAttribute(e):t===uI.INDIRECT&&this.backend.createIndirectStorageAttribute(e),r.version=this._getBufferAttribute(e).version;else{let t=this._getBufferAttribute(e);(r.version<t.version||t.usage===u.Vnu)&&(this.backend.updateAttribute(e),r.version=t.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function uV(e){return null!==e.index?e.index.version:e.attributes.position.version}function uO(e){let t=[],r=e.index,i=e.attributes.position;if(null!==r){let e=r.array;for(let r=0,i=e.length;r<i;r+=3){let i=e[r+0],s=e[r+1],n=e[r+2];t.push(i,s,s,n,n,i)}}else{let e=i.array;for(let r=0,i=e.length/3-1;r<i;r+=3){let e=r+0,i=r+1,s=r+2;t.push(e,i,i,s,s,e)}}let s=new((0,u.AQS)(t)?u.MW4:u.A$4)(t,1);return s.version=uV(e),s}class uG extends uU{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){let t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){let t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;let r=()=>{this.info.memory.geometries--;let i=t.index,s=e.getAttributes();for(let e of(null!==i&&this.attributes.delete(i),s))this.attributes.delete(e);let n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",r)};t.addEventListener("dispose",r)}updateAttributes(e){for(let t of e.getAttributes())t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,uI.STORAGE):this.updateAttribute(t,uI.VERTEX);let t=this.getIndex(e);null!==t&&this.updateAttribute(t,uI.INDEX);let r=e.geometry.indirect;null!==r&&this.updateAttribute(r,uI.INDIRECT)}updateAttribute(e,t){let r=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,r)):this.attributeCall.get(e.data)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e.data,r),this.attributeCall.set(e,r)):this.attributeCall.get(e)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e,r))}getIndirect(e){return e.geometry.indirect}getIndex(e){let{geometry:t,material:r}=e,i=t.index;if(!0===r.wireframe){let e=this.wireframes,r=e.get(t);void 0===r?(r=uO(t),e.set(t,r)):r.version!==uV(t)&&(this.attributes.delete(r),r=uO(t),e.set(t,r)),i=r}return i}}class uk{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,r){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=t/3*r:e.isPoints?this.render.points+=r*t:e.isLineSegments?this.render.lines+=t/2*r:e.isLine?this.render.lines+=r*(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 uz{constructor(e){this.cacheKey=e,this.usedTimes=0}}class u$ extends uz{constructor(e,t,r){super(e),this.vertexProgram=t,this.fragmentProgram=r}}class uW extends uz{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let uH=0;
4class uq{constructor(e,t,r,i=null,s=null){this.id=uH++,this.code=e,this.stage=t,this.name=r,this.transforms=i,this.attributes=s,this.usedTimes=0}}class uj extends uU{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){let{backend:r}=this,i=this.get(e);if(this._needsComputeUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.computeProgram.usedTimes--);let n=this.nodes.getForCompute(e),a=this.programs.compute.get(n.computeShader);void 0===a&&(s&&0===s.computeProgram.usedTimes&&this._releaseProgram(s.computeProgram),a=new uq(n.computeShader,"compute",e.name,n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,a),r.createProgram(a));let o=this._getComputeCacheKey(e,a),l=this.caches.get(o);void 0===l&&(s&&0===s.usedTimes&&this._releasePipeline(s),l=this._getComputePipeline(e,a,o,t)),l.usedTimes++,a.usedTimes++,i.version=e.version,i.pipeline=l}return i.pipeline}getForRender(e,t=null){let{backend:r}=this,i=this.get(e);if(this._needsRenderUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.vertexProgram.usedTimes--,s.fragmentProgram.usedTimes--);let n=e.getNodeBuilderState(),a=e.material?e.material.name:"",o=this.programs.vertex.get(n.vertexShader);void 0===o&&(s&&0===s.vertexProgram.usedTimes&&this._releaseProgram(s.vertexProgram),o=new uq(n.vertexShader,"vertex",a),this.programs.vertex.set(n.vertexShader,o),r.createProgram(o));let l=this.programs.fragment.get(n.fragmentShader);void 0===l&&(s&&0===s.fragmentProgram.usedTimes&&this._releaseProgram(s.fragmentProgram),l=new uq(n.fragmentShader,"fragment",a),this.programs.fragment.set(n.fragmentShader,l),r.createProgram(l));let u=this._getRenderCacheKey(e,o,l),d=this.caches.get(u);void 0===d?(s&&0===s.usedTimes&&this._releasePipeline(s),d=this._getRenderPipeline(e,o,l,u,t)):e.pipeline=d,d.usedTimes++,o.usedTimes++,l.usedTimes++,i.pipeline=d}return i.pipeline}delete(e){let t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&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,r,i){r=r||this._getComputeCacheKey(e,t);let s=this.caches.get(r);return void 0===s&&(s=new uW(r,t),this.caches.set(r,s),this.backend.createComputePipeline(s,i)),s}_getRenderPipeline(e,t,r,i,s){i=i||this._getRenderCacheKey(e,t,r);let n=this.caches.get(i);return void 0===n&&(n=new u$(i,t,r),this.caches.set(i,n),e.pipeline=n,this.backend.createRenderPipeline(e,s)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,r){return t.id+","+r.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){let t=e.code,r=e.stage;this.programs[r].delete(t)}_needsComputeUpdate(e){let t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class uX extends uU{constructor(e,t,r,i,s,n){super(),this.backend=e,this.textures=r,this.pipelines=s,this.attributes=i,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){let t=e.getBindings();for(let e of t){let r=this.get(e);void 0===r.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),r.bindGroup=e)}return t}getForCompute(e){let t=this.nodes.getForCompute(e).bindings;for(let e of t){let r=this.get(e);void 0===r.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),r.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(let t of e)this._update(t,e)}_init(e){for(let t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){let e=t.attribute,r=e.isIndirectStorageBufferAttribute?uI.INDIRECT:uI.STORAGE;this.attributes.update(e,r)}}_update(e,t){let{backend:r}=this,i=!1,s=!0,n=0,a=0;for(let t of e.bindings)if(!t.isNodeUniformsGroup||!1!==this.nodes.updateGroup(t)){if(t.isStorageBuffer){let e=t.attribute,r=e.isIndirectStorageBufferAttribute?uI.INDIRECT:uI.STORAGE;this.attributes.update(e,r)}
4if(t.isUniformBuffer)t.update()&&r.updateBinding(t);else if(t.isSampler)t.update();else if(t.isSampledTexture){let e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(i=!0);let o=t.update(),l=t.texture;o&&this.textures.updateTexture(l);let u=r.get(l);if(void 0!==u.externalTexture||e.isDefaultTexture?s=!1:(n=10*n+l.id,a+=l.version),!0===r.isWebGPUBackend&&void 0===u.texture&&void 0===u.externalTexture&&(console.error("Bindings._update: binding should be available:",t,o,l,t.textureNode.value,i),this.textures.updateTexture(l),i=!0),!0===l.isStorageTexture){let e=this.get(l);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(l)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(l),e.needsMipmap=!1)}}}!0===i&&this.backend.updateBindings(e,t,s?n:0,a)}}function uQ(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?e.z-t.z:e.id-t.id}function uY(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function uK(e){return(e.transmission>0||e.transmissionNode)&&e.side===u.$EB&&!1===e.forceSinglePass}class uZ{constructor(e,t,r){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,r),this.lightsArray=[],this.scene=t,this.camera=r,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,r,i,s,n,a){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:e.id,object:e,geometry:t,material:r,groupOrder:i,renderOrder:e.renderOrder,z:s,group:n,clippingContext:a},this.renderItems[this.renderItemsIndex]=o):(o.id=e.id,o.object=e,o.geometry=t,o.material=r,o.groupOrder=i,o.renderOrder=e.renderOrder,o.z=s,o.group=n,o.clippingContext=a),this.renderItemsIndex++,o}push(e,t,r,i,s,n,a){let o=this.getNextRenderItem(e,t,r,i,s,n,a);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===r.transparent||r.transmission>0?(uK(r)&&this.transparentDoublePass.push(o),this.transparent.push(o)):this.opaque.push(o)}unshift(e,t,r,i,s,n,a){let o=this.getNextRenderItem(e,t,r,i,s,n,a);!0===r.transparent||r.transmission>0?(uK(r)&&this.transparentDoublePass.unshift(o),this.transparent.unshift(o)):this.opaque.unshift(o)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||uQ),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||uY),this.transparent.length>1&&this.transparent.sort(t||uY)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){let t=this.renderItems[e];if(null===t.id)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.groupOrder=null,t.renderOrder=null,t.z=null,t.group=null,t.clippingContext=null}}}let uJ=[];class u0{constructor(e){this.lighting=e,this.lists=new uM}get(e,t){let r=this.lists;uJ[0]=e,uJ[1]=t;let i=r.get(uJ);return void 0===i&&(i=new uZ(this.lighting,e,t),r.set(uJ,i)),uJ.length=0,i}dispose(){this.lists=new uM}}let u1=0;class u2{constructor(){this.id=u1++,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 u.IUQ,this.scissor=!1,this.scissorValue=new u.IUQ,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 u3(this)}}function u3(e){let{textures:t,activeCubeFace:r}=e,i=[r];for(let e of t)i.push(e.id);return g(i)}let u4=[],u6=new u.Z58,u8=new u.i7d;class u5{constructor(){this.chainMaps={}}get(e,t,r=null){let i;if(u4[0]=e,u4[1]=t,null===r)i="default";else{let e=r.texture.format,t=r.textures.length;i=`${t}:${e}:${r.samples}:${r.depthBuffer}:${r.stencilBuffer}`}let s=this._getChainMap(i),n=s.get(u4);return void 0===n&&(n=new u2,s.set(u4,n)),u4.length=0,null!==r&&(n.sampleCount=0===r.samples?1:r.samples),n}getForClear(e=null){return this.get(u6,u8,e)}_getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new uM)}dispose(){this.chainMaps={}}}let u9=new u.Pq0;class u7 extends uU{constructor(e,t,r){super(),this.renderer=e,this.backend=t,this.info=r}updateRenderTarget(e,t=0){let r=this.get(e),i=0===e.samples?1:e.samples,s=r.depthTextureMips||(r.depthTextureMips={}),n=e.textures,a=this.getSize(n[0]),o=a.width>>t,l=a.height>>t,d=e.depthTexture||s[t],h=!0===e.depthBuffer||!0===e.stencilBuffer,c=!1;void 0===d&&h&&((d=!0===e.multiview&&a.depth>1?new u.S7T:new u.VCu).format=e.stencilBuffer?u.dcC:u.zdS,d.type=e.stencilBuffer?u.V3x:u.bkx,d.image.width=o,d.image.height=l,d.image.depth=a.depth,s[t]=d),(r.width!==a.width||a.height!==r.height)&&(c=!0,d&&(d.needsUpdate=!0,d.image.width=o,d.image.height=l,d.image.depth=d.isDepthArrayTexture?d.image.depth:1)),r.width=a.width,r.height=a.height,r.textures=n,r.depthTexture=d||null,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,r.renderTarget=e,r.sampleC
4ount!==i&&(c=!0,d&&(d.needsUpdate=!0),r.sampleCount=i);let p={sampleCount:i};if(!0!==e.isXRRenderTarget){for(let t=0;t<n.length;t++){let r=n[t];r.isTextureArray=!0===e.multiview&&a.depth>1,c&&(r.needsUpdate=!0),this.updateTexture(r,p)}d&&this.updateTexture(d,p)}if(!0!==r.initialized){r.initialized=!0;let t=()=>{e.removeEventListener("dispose",t);for(let e=0;e<n.length;e++)this._destroyTexture(n[e]);d&&this._destroyTexture(d),this.delete(e)};e.addEventListener("dispose",t)}}updateTexture(e,t={}){let r=this.get(e);if(!0===r.initialized&&r.version===e.version)return;let i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,s=this.backend;if(i&&!0===r.initialized&&(s.destroySampler(e),s.destroyTexture(e)),e.isFramebufferTexture){let t=this.renderer.getRenderTarget();t?e.type=t.texture.type:e.type=u.OUM}let{width:n,height:a,depth:o}=this.getSize(e);if(t.width=n,t.height=a,t.depth=o,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,n,a):1,i||!0===e.isStorageTexture)s.createSampler(e),s.createTexture(e,t),r.generation=e.version;else if(!0!==r.initialized&&s.createSampler(e),e.version>0){let i=e.image;if(void 0===i)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){let r=[];for(let t of e.images)r.push(t);t.images=r}else t.image=i;(void 0===r.isDefaultTexture||!0===r.isDefaultTexture)&&(s.createTexture(e,t),r.isDefaultTexture=!1,r.generation=e.version),!0===e.source.dataReady&&s.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&s.generateMipmaps(e)}}else s.createDefaultTexture(e),r.isDefaultTexture=!0,r.generation=e.version;if(!0!==r.initialized){r.initialized=!0,r.generation=e.version,this.info.memory.textures++;let t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e)};e.addEventListener("dispose",t)}r.version=e.version}getSize(e,t=u9){let r=e.images?e.images[0]:e.image;return r?(void 0!==r.image&&(r=r.image),t.width=r.width||1,t.height=r.height||1,t.depth=e.isCubeTexture?6:r.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,r){return e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,r)))+1}needsMipmaps(e){return!0===e.isCompressedTexture||e.generateMipmaps}_destroyTexture(e){!0===this.has(e)&&(this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e),this.info.memory.textures--)}}class de extends u.Q1f{constructor(e,t,r,i=1){super(e,t,r),this.a=i}set(e,t,r,i=1){return this.a=i,super.set(e,t,r)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class dt extends e0{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}class dr extends U{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){let r=new eT(t);return this._currentCond=it(e,r),this.add(this._currentCond)}ElseIf(e,t){let r=it(e,new eT(t));return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new eT(e),this}Switch(e){return this._expressionNode=e_(e),this}Case(...e){let t=[];if(e.length>=2)for(let r=0;r<e.length-1;r++)t.push(this._expressionNode.equal(e_(e[r])));else throw Error("TSL: Invalid parameter length. Case() requires at least two parameters.");let r=new eT(e[e.length-1]),i=t[0];for(let e=1;e<t.length;e++)i=i.or(t[e]);let s=it(i,r);return null===this._currentCond?(this._currentCond=s,this.add(this._currentCond)):(this._currentCond.elseNode=s,this._currentCond=s,this)}Default(e){return this.Else(e),this}build(e,...t){let r=eC();for(let t of(ew(this),this.nodes))t.build(e,"void");return ew(r),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("THREE.TSL: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("THREE.TSL: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}let di=eN(dr).setParameterLength(0,1);class ds extends U{static get type(){return"StructTypeNode"}constructor(e,t=null){super("struct"),this.membersLayout=Object.entries(e).map(([e,t])=>"string"==typeof t?{name:e,type:t,atomic:!1}:{name:e,type:t.type,atomic:t.atomic||!1}
4),this.name=t,this.isStructLayoutNode=!0}getLength(){let e=0;for(let t of this.membersLayout)e+=_(t.type);return e}getMemberType(e,t){let r=this.membersLayout.find(e=>e.name===t);return r?r.type:"void"}getNodeType(e){return e.getStructTypeFromNode(this,this.membersLayout,this.name).name}setup(e){e.addInclude(this)}generate(e){return this.getNodeType(e)}}class dn extends U{static get type(){return"StructNode"}constructor(e,t){super("vec3"),this.structLayoutNode=e,this.values=t,this.isStructNode=!0}getNodeType(e){return this.structLayoutNode.getNodeType(e)}getMemberType(e,t){return this.structLayoutNode.getMemberType(e,t)}generate(e){let t=e.getVarFromNode(this),r=t.type,i=e.getPropertyName(t);return e.addLineFlowCode(`${i} = ${e.generateStruct(r,this.structLayoutNode.membersLayout,this.values)}`,this),t.name}}class da extends U{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}getNodeType(e){let t=e.getNodeProperties(this);if(void 0===t.membersLayout){let r=this.members,i=[];for(let t=0;t<r.length;t++){let s="m"+t,n=r[t].getNodeType(e);i.push({name:s,type:n,index:t})}t.membersLayout=i,t.structType=e.getOutputStructTypeFromNode(this,t.membersLayout)}return t.structType.name}generate(e){let t=e.getOutputStructName(),r=this.members,i=""!==t?t+".":"";for(let t=0;t<r.length;t++){let s=r[t].build(e);e.addLineFlowCode(`${i}m${t} = ${s}`,this)}return t}}let dl=eN(da);function du(e,t){for(let r=0;r<e.length;r++)if(e[r].name===t)return r;return -1}class dd extends da{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.isMRTNode=!0}has(e){return void 0!==this.outputNodes[e]}get(e){return this.outputNodes[e]}merge(e){return dh({...this.outputNodes,...e.outputNodes})}setup(e){let t=this.outputNodes,r=e.renderer.getRenderTarget(),i=[],s=r.textures;for(let e in t)i[du(s,e)]=eH(t[e]);return this.members=i,super.setup(e)}}let dh=eN(dd),dc=eE(([e])=>{let t=e.toUint().mul(0x2c9277b5).add(0xac564b05),r=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(0x108ef2d9);return r.shiftRight(22).bitXor(r).toFloat().mul(1/0x100000000)}),dp=(e,t)=>rj(tO(4,e.mul(tV(1,e))),t),dg=eE(([e])=>e.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),dm=eE(([e])=>ek(dg(e.z.add(dg(e.y.mul(1)))),dg(e.z.add(dg(e.x.mul(1)))),dg(e.y.add(dg(e.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),df=eE(([e,t,r])=>{let i=ek(e).toVar(),s=eF(1.4).toVar(),n=eF(0).toVar(),a=ek(i).toVar();return aM({start:eF(0),end:eF(3),type:"float",condition:"<="},()=>{let e=ek(dm(a.mul(2))).toVar();i.addAssign(e.add(r.mul(eF(.1).mul(t)))),a.mulAssign(1.8),s.mulAssign(1.5),i.mulAssign(1.2);let o=eF(dg(i.z.add(dg(i.x.add(dg(i.y)))))).toVar();n.addAssign(o.div(s)),a.addAssign(.14)}),n}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"position",type:"vec3"},{name:"speed",type:"float"},{name:"time",type:"float"}]});class dy extends U{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){let t=this.parametersNodes,r=this._candidateFnCall;if(null===r){let i=null,s=-1;for(let r of this.functionNodes){let n=r.shaderNode.layout;if(null===n)throw Error("FunctionOverloadingNode: FunctionNode must be a layout.");let a=n.inputs;if(t.length===a.length){let n=0;for(let r=0;r<t.length;r++){let i=t[r],s=a[r];i.getNodeType(e)===s.type?n++:n=0}n>s&&(i=r,s=n)}}this._candidateFnCall=r=i(...t)}return r}}let dx=eN(dy),db=e=>(...t)=>dx(e,...t),dT=tw(0).setGroup(tR).onRenderUpdate(e=>e.time),d_=tw(0).setGroup(tR).onRenderUpdate(e=>e.deltaTime),dv=tw(0,"uint").setGroup(tR).onRenderUpdate(e=>e.frameId),dS=eE(([e,t,r=eD(.5)])=>u_(e.sub(r),t).add(r)),dN=eE(([e,t,r=eD(.5)])=>{let i=e.sub(r),s=i.dot(i),n=s.mul(s).mul(t);return e.add(i.mul(n))}),dR=eE(({position:e=null,horizontal:t=!0,vertical:r=!1})=>{let i;null!==e?((i=sR.toVar())[3][0]=e.x,i[3][1]=e.y,i[3][2]=e.z):i=sR;let s=sh.mul(i);return ex(t)&&(s[0][0]=sR[0].length(),s[0][1]=0,s[0][2]=0),ex(r)&&(s[1][0]=0,s[1][1]=sR[1].length(),s[1][2]=0),s[2][0]=0,s[2][1]=0,s[2][2]=1,su.mul(s).mul(sD)}),dA=eE(([e=null])=>
4{let t=oi();return oi(a6(e)).sub(t).lessThan(0).select(a$,e)});class dE extends U{static get type(){return"SpriteSheetUVNode"}constructor(e,t=i1(),r=eF(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=r}setup(){let{frameNode:e,uvNode:t,countNode:r}=this,{width:i,height:s}=r,n=e.mod(i.mul(s)).floor(),a=n.mod(i),o=s.sub(n.add(1).div(i).ceil()),l=r.reciprocal(),u=eD(a,o);return t.add(u).mul(l)}}let dw=eN(dE).setParameterLength(3);class dC extends U{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,r=null,i=eF(1),s=sD,n=sj){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=r,this.scaleNode=i,this.positionNode=s,this.normalNode=n}setup(){let{textureXNode:e,textureYNode:t,textureZNode:r,scaleNode:i,positionNode:s,normalNode:n}=this,a=n.abs().normalize();a=a.div(a.dot(ek(1)));let o=s.yz.mul(i),l=s.zx.mul(i),u=s.xy.mul(i),d=e.value,h=null!==t?t.value:d,c=null!==r?r.value:d,p=i5(d,o).mul(a.x);return tD(p,i5(h,l).mul(a.y),i5(c,u).mul(a.z))}}let dM=eN(dC).setParameterLength(1,6),dB=new u.Zcv,dP=new u.Pq0,dF=new u.Pq0,dL=new u.Pq0,dU=new u.kn4,dI=new u.Pq0(0,0,-1),dD=new u.IUQ,dV=new u.Pq0,dO=new u.Pq0,dG=new u.IUQ,dk=new u.I9Y,dz=new u.O0B,d$=a$.flipX();dz.depthTexture=new u.VCu(1,1);let dW=!1;class dH extends i8{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||dz.texture,d$),this._reflectorBaseNode=e.reflector||new dq(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=e_(new dH({defaultTexture:dz.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){let e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}dispose(){super.dispose(),this._reflectorBaseNode.dispose()}}class dq extends U{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();let{target:r=new u.B69,resolution:i=1,generateMipmaps:s=!1,bounces:n=!0,depth:a=!1}=t;this.textureNode=e,this.target=r,this.resolution=i,this.generateMipmaps=s,this.bounces=n,this.depth=a,this.updateBeforeType=n?w.RENDER:w.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new Map,this.forceUpdate=!1}_updateResolution(e,t){let r=this.resolution;t.getDrawingBufferSize(dk),e.setSize(Math.round(dk.width*r),Math.round(dk.height*r))}setup(e){return this._updateResolution(dz,e.renderer),super.setup(e)}dispose(){for(let e of(super.dispose(),this.renderTargets.values()))e.dispose()}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new u.O0B(0,0,{type:u.ix0}),!0===this.generateMipmaps&&(t.texture.minFilter=u.NZq,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new u.VCu),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&dW)return!1;dW=!0;let{scene:t,camera:r,renderer:i,material:s}=e,{target:n}=this,a=this.getVirtualCamera(r),o=this.getRenderTarget(a);if(i.getDrawingBufferSize(dk),this._updateResolution(o,i),dF.setFromMatrixPosition(n.matrixWorld),dL.setFromMatrixPosition(r.matrixWorld),dU.extractRotation(n.matrixWorld),dP.set(0,0,1),dP.applyMatrix4(dU),dV.subVectors(dF,dL),!0==dV.dot(dP)>0&&!1===this.forceUpdate)return;dV.reflect(dP).negate(),dV.add(dF),dU.extractRotation(r.matrixWorld),dI.set(0,0,-1),dI.applyMatrix4(dU),dI.add(dL),dO.subVectors(dF,dI),dO.reflect(dP).negate(),dO.add(dF),a.coordinateSystem=r.coordinateSystem,a.position.copy(dV),a.up.set(0,1,0),a.up.applyMatrix4(dU),a.up.reflect(dP),a.lookAt(dO),a.near=r.near,a.far=r.far,a.updateMatrixWorld(),a.projectionMatrix.copy(r.projectionMatrix),dB.setFromNormalAndCoplanarPoint(dP,dF),dB.applyMatrix4(a.matrixWorldInverse),dD.set(dB.normal.x,dB.normal.y,dB.normal.z,dB.constant);let l=a.projectionMatrix;dG.x=(Math.sign(dD.x)+l.elements[8])/l.elements[0],dG.y=(Math.sign(dD.y)+l.elements[9])/l.elements[5],dG.z=-1,dG.w=(1+l.elements[10])/l.elements[14],dD.multiplyScalar(1/dD.dot(dG)),l.elements[2]=dD.x,l.elements[6]=dD.y,l.elements[10]=i.coordinateSystem===u.i7u?dD.z-0:dD.z+1-0,l.elements[14]=dD.w,this.textureNode.value=o.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=o.depthTexture),s.visible=!1;let d=i.getRenderTarget(),h=i.getMRT(),c=i.autoClear;i.setMRT(null),i.setRenderTarget(o),i.autoClear=!0,i.render(t,a),i.setMRT(h),i.setRenderTarget(d),i.autoClear=c,s.visible=!0,dW=!1,this.forceUpdate=!1}}let dj=new u.qUd(-1,1,1,-1,0,1);class dX extends u.LoY{constructor(e=!1){super(),this.setAttribute("position",new u.qtW([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new u.qtW(!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0],2))}}let dQ=new dX;class dY extends u.eaF{constructor(e=null){super(dQ,e),this.camera=dj,this.isQuadMesh=!0}async renderAsync(e){return e.renderAsync(this,dj)}render(e){e.render(this,dj)}}let dK=new u.I9Y;class dZ extends i8{static get type(){return"RTTNode"}constructor(e,t=null,r=null,i={type:u.ix0}){let s=new u.O0B(t,r,i);super(s.texture,i1()),this.node=e,this.width=t,this.height=r,this.pixelRatio=1,this.renderTarget=s,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this._rttNode=null,this._quadMesh=new dY(new oh),this.updateBeforeType=w.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;let r=e*this.pixelRatio,i=t*this.pixelRatio;this.renderTarget.setSize(r,i),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();let t=e.getSize(dK);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;let t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){let e=new i8(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}let dJ=(e,...t)=>
4e_(new dZ(e_(e),...t)),d0=eE(([e,t,r],i)=>{let s;s=i.renderer.coordinateSystem===u.i7u?eH(ek(e=eD(e.x,e.y.oneMinus()).mul(2).sub(1),t),1):eH(ek(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);let n=eH(r.mul(s));return n.xyz.div(n.w)}),d1=eE(([e,t])=>{let r=t.mul(eH(e,1)),i=r.xy.div(r.w).mul(.5).add(.5).toVar();return eD(i.x,i.y.oneMinus())}),d2=eE(([e,t,r])=>{let i=i3(i9(t)),s=eV(e.mul(i)).toVar(),n=i9(t,s).toVar(),a=i9(t,s.sub(eV(2,0))).toVar(),o=i9(t,s.sub(eV(1,0))).toVar(),l=i9(t,s.add(eV(1,0))).toVar(),u=i9(t,s.add(eV(2,0))).toVar(),d=i9(t,s.add(eV(0,2))).toVar(),h=i9(t,s.add(eV(0,1))).toVar(),c=i9(t,s.sub(eV(0,1))).toVar(),p=i9(t,s.sub(eV(0,2))).toVar(),g=rR(tV(eF(2).mul(o).sub(a),n)).toVar(),m=rR(tV(eF(2).mul(l).sub(u),n)).toVar(),f=rR(tV(eF(2).mul(h).sub(d),n)).toVar(),y=rR(tV(eF(2).mul(c).sub(p),n)).toVar(),x=d0(e,n,r).toVar();return ry(rq(g.lessThan(m).select(x.sub(d0(e.sub(eD(eF(1).div(i.x),0)),o,r)),x.negate().add(d0(e.add(eD(eF(1).div(i.x),0)),l,r))),f.lessThan(y).select(x.sub(d0(e.add(eD(0,eF(1).div(i.y))),h,r)),x.negate().add(d0(e.sub(eD(0,eF(1).div(i.y))),c,r)))))});class d3 extends u.uWO{constructor(e,t,r=Float32Array){super(ArrayBuffer.isView(e)?e:new r(e*t),t),this.isStorageInstancedBufferAttribute=!0}}class d4 extends u.THS{constructor(e,t,r=Float32Array){super(ArrayBuffer.isView(e)?e:new r(e*t),t),this.isStorageBufferAttribute=!0}}class d6 extends U{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}let d8=eR(d6),d5=new u.O9p,d9=new u.kn4;class d7 extends U{static get type(){return"SceneNode"}constructor(e=d7.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){let t,r=this.scope,i=null!==this.scene?this.scene:e.scene;return r===d7.BACKGROUND_BLURRINESS?t=nn("backgroundBlurriness","float",i):r===d7.BACKGROUND_INTENSITY?t=nn("backgroundIntensity","float",i):r===d7.BACKGROUND_ROTATION?t=tw("mat4").label("backgroundRotation").setGroup(tR).onRenderUpdate(()=>{let e=i.background;return null!==e&&e.isTexture&&e.mapping!==u.UTZ?(d5.copy(i.backgroundRotation),d5.x*=-1,d5.y*=-1,d5.z*=-1,d9.makeRotationFromEuler(d5)):d9.identity(),d9}):console.error("THREE.SceneNode: Unknown scope:",r),t}}d7.BACKGROUND_BLURRINESS="backgroundBlurriness",d7.BACKGROUND_INTENSITY="backgroundIntensity",d7.BACKGROUND_ROTATION="backgroundRotation";let he=eR(d7,d7.BACKGROUND_BLURRINESS),ht=eR(d7,d7.BACKGROUND_INTENSITY),hr=eR(d7,d7.BACKGROUND_ROTATION);class hi extends i8{static get type(){return"StorageTextureNode"}constructor(e,t,r=null){super(e,t),this.storeNode=r,this.isStorageTextureNode=!0,this.access=C.WRITE_ONLY}getInputType(){return"storageTexture"}setup(e){super.setup(e),e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){return null!==this.storeNode?this.generateStore(e):super.generate(e,t)}toReadWrite(){return this.setAccess(C.READ_WRITE)}toReadOnly(){return this.setAccess(C.READ_ONLY)}toWriteOnly(){return this.setAccess(C.WRITE_ONLY)}generateStore(e){let{uvNode:t,storeNode:r}=e.getNodeProperties(this),i=super.generate(e,"property"),s=t.build(e,"uvec2"),n=r.build(e,"vec4"),a=e.generateTextureStore(e,i,s,n);e.addLineFlowCode(a,this)}}let hs=eN(hi).setParameterLength(1,3),hn=eE(({texture:e,uv:t})=>{let r=ek().toVar();return eM(t.x.lessThan(1e-4),()=>{r.assign(ek(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{r.assign(ek(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{r.assign(ek(0,0,1))}).ElseIf(t.x.greaterThan(.9999),()=>{r.assign(ek(-1,0,0))}).ElseIf(t.y.greaterThan(.9999),()=>{r.assign(ek(0,-1,0))}).ElseIf(t.z.greaterThan(.9999),()=>{r.assign(ek(0,0,-1))}).Else(()=>{let i=e.sample(t.add(ek(-.01,0,0))).r.sub(e.sample(t.add(ek(.01,0,0))).r),s=e.sample(t.add(ek(0,-.01,0))).r.sub(e.sample(t.add(ek(0,.01,0))).r),n=e.sample(t.add(ek(0,0,-.01))).r.sub(e.sample(t.add(ek(0,0,.01))).r);r.assign(ek(i,s,n))}),r.normalize()});class ha extends i8{static get type(){return"Texture3DNode"}constructor(e,t=null,r=null){super(e,t,r),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return ek(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){let r=this.value;return e.isFlipY()&&(!0===r.isRenderTargetTexture||!0===r.isFramebufferTexture)&&(t=this.sampler?t.flipY():t.setY(eL(i3(this,this.levelNode).y).sub(t.y).sub(1))),t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return hn({texture:this,uv:e})}}let ho=eN(ha).setParameterLength(1,3);class hl extends ns{static get type(){return"UserDataNode"}constructor(e,t,r=null){super(e,t,r),this.userData=r}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}let hu=new WeakMap;class hd extends V{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=w.OBJECT,this.updateAfterType=w.OBJECT,this.previousModelWorldMatrix=tw(new u.kn4),this.previousProjectionMatrix=tw(new u.kn4).setGroup(tR),this.previousCameraViewMatrix=tw(new u.kn4)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:r}){let i=hc(r);this.previousModelWorldMatrix.value.copy(i);let s=hh(t);s.frameId!==e&&(s.frameId=e,void 0===s.previousProjectionMatrix?(s.previousProjectionMatrix=new u.kn4,s.previousCameraViewMatrix=new u.kn4,s.currentProjectionMatrix=new u.kn4,s.currentCameraViewMatrix=new u.kn4,s.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),s.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(s.previousProjectionMatrix.copy(s.currentProjectionMatrix),s.previousCameraViewMatrix.copy(s.currentCameraViewMatrix)),s.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),s.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(s.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(s.previousCameraViewMatrix))}updateAfter({object:e}){hc(e).copy(e.matrixWorld)}setup(){let e=null===this.projectionMatrix?su:tw(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),r=e.mul(sP).mul(sD),i=this.previousProjectionMatrix.mul(t).mul(sV);return tV(r.xy.div(r.w),i.xy.div(i.w))}}function hh(e){let t=hu.get(e);return void 0===t&&(t={},hu.set(e,t)),t}function hc(e,t=0){let r=hh(e),i=r[t];return void 0===i&&(r[t]=i=new u.kn4,r[t].copy(e.matrixWorld)),i}let hp=eR(hd),hg=eE(([e,t])=>rO(1,e.oneMinus().div(t)).oneMinus()).setLayout({name:"blendBurn",type:"vec3",input
4s:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),hm=eE(([e,t])=>rO(e.div(t.oneMinus()),1)).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),hf=eE(([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus()).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),hy=eE(([e,t])=>r0(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),rk(.5,e))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),hx=eE(([e,t])=>{let r=t.a.add(e.a.mul(t.a.oneMinus()));return eH(t.rgb.mul(t.a).add(e.rgb.mul(e.a).mul(t.a.oneMinus())).div(r),r)}).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),hb=eE(([e])=>hS(e.rgb)),hT=eE(([e,t=eF(1)])=>t.mix(hS(e.rgb),e.rgb)),h_=eE(([e,t=eF(1)])=>{let r=tD(e.r,e.g,e.b).div(3),i=e.r.max(e.g.max(e.b)),s=i.sub(r).mul(t).mul(-3);return r0(e.rgb,i,s)}),hv=eE(([e,t=eF(1)])=>{let r=ek(.57735,.57735,.57735),i=t.cos();return ek(e.rgb.mul(i).add(r.cross(e.rgb).mul(t.sin()).add(r.mul(rH(r,e.rgb).mul(i.oneMinus())))))}),hS=(e,t=ek(u.ppV.getLuminanceCoefficients(new u.Pq0)))=>rH(e,t),hN=eE(([e,t=ek(1),r=ek(0),i=ek(1),s=eF(1),n=ek(u.ppV.getLuminanceCoefficients(new u.Pq0,u.Zr2))])=>{let a=e.rgb.dot(ek(n)),o=rG(e.rgb.mul(t).add(r),0).toVar(),l=o.pow(i).toVar();return eM(o.r.greaterThan(0),()=>{o.r.assign(l.r)}),eM(o.g.greaterThan(0),()=>{o.g.assign(l.g)}),eM(o.b.greaterThan(0),()=>{o.b.assign(l.b)}),o.assign(a.add(o.sub(a).mul(s))),eH(o.rgb,e.a)});class hR extends V{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){let{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}let hA=eN(hR).setParameterLength(2),hE=new u.I9Y;class hw extends i8{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 hC extends hw{static get type(){return"PassMultipleTextureNode"}constructor(e,t,r=!1){super(e,null),this.textureName=t,this.previousTexture=r}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class hM extends V{static get type(){return"PassNode"}constructor(e,t,r,i={}){super("vec4"),this.scope=e,this.scene=t,this.camera=r,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;let s=new u.VCu;s.isRenderTargetTexture=!0,s.name="depth";let n=new u.O0B(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:u.ix0,...i});n.texture.name="output",n.depthTexture=s,this.renderTarget=n,this._textures={output:n.texture,depth:s},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=tw(0),this._cameraFar=tw(0),this._mrt=null,this._layers=null,this._resolution=1,this.isPassNode=!0,this.updateBeforeType=w.FRAME}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}isGlobal(){return!0}getTexture(e){let t=this._textures[e];return void 0===t&&((t=this.renderTarget.texture.clone()).name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){let t=this._previousTextures[e];if(void 0!==t){let r=this._textures[e],i=this.renderTarget.textures.indexOf(r);this.renderTarget.textures[i]=t,this._textures[e]=t,this._previousTextures[e]=r,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&((t=e_(new hC(this,e))).updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),(t=e_(new hC(this,e,!0))).updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){let r=this._cameraNear,i=this._cameraFar;this._viewZNodes[e]=t=a7(this.getTextureNode(e),r,i)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){let r=this._cameraNear,i=this._cameraFar,s=this.getViewZNode(e);this._linearDepthNodes[e]=t=a5(s,r,i)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.texture.type=e.getColorBufferType(),this.scope===hM.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){let t,r,{renderer:i}=e,{scene:s}
4=this,n=i.getOutputRenderTarget();n&&!0===n.isXRRenderTarget?(r=1,t=i.xr.getCamera(),i.xr.updateCamera(t),hE.set(n.width,n.height)):(t=this.camera,r=i.getPixelRatio(),i.getSize(hE)),this._pixelRatio=r,this.setSize(hE.width,hE.height);let a=i.getRenderTarget(),o=i.getMRT(),l=t.layers.mask;for(let e in this._cameraNear.value=t.near,this._cameraFar.value=t.far,null!==this._layers&&(t.layers.mask=this._layers.mask),this._previousTextures)this.toggleTexture(e);i.setRenderTarget(this.renderTarget),i.setMRT(this._mrt),i.render(s,t),i.setRenderTarget(a),i.setMRT(o),t.layers.mask=l}setSize(e,t){this._width=e,this._height=t;let r=this._width*this._pixelRatio*this._resolution,i=this._height*this._pixelRatio*this._resolution;this.renderTarget.setSize(r,i)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}hM.COLOR="color",hM.DEPTH="depth";class hB extends hM{static get type(){return"ToonOutlinePassNode"}constructor(e,t,r,i,s){super(hM.COLOR,e,t),this.colorNode=r,this.thicknessNode=i,this.alphaNode=s,this._materialCache=new WeakMap}updateBefore(e){let{renderer:t}=e,r=t.getRenderObjectFunction();t.setRenderObjectFunction((e,r,i,s,n,a,o,l)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){let u=this._getOutlineMaterial(n);t.renderObject(e,r,i,s,u,a,o,l)}t.renderObject(e,r,i,s,n,a,o,l)}),super.updateBefore(e),t.setRenderObjectFunction(r)}_createMaterial(){let e=new oh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=u.hsX;let t=sj.negate(),r=su.mul(sP),i=eF(1),s=r.mul(eH(sD,1)),n=r.mul(eH(sD.add(t),1)),a=ry(s.sub(n));return e.vertexNode=s.add(a.mul(this.thicknessNode).mul(s.w).mul(i)),e.colorNode=eH(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}let hP=eE(([e,t])=>e.mul(t).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hF=eE(([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp()).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hL=eE(([e,t])=>{let r=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),i=e.mul(e.mul(6.2).add(1.7)).add(.06);return r.div(i).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hU=eE(([e])=>{let t=e.mul(e.add(.0245786)).sub(90537e-9),r=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(r)}),hI=eE(([e,t])=>{let r=eY(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=eY(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=hU(e=r.mul(e)),(e=i.mul(e)).clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hD=eY(ek(1.6605,-.1246,-.0182),ek(-.5876,1.1329,-.1006),ek(-.0728,-.0083,1.1187)),hV=eY(ek(.6274,.0691,.0164),ek(.3293,.9195,.088),ek(.0433,.0113,.8956)),hO=eE(([e])=>{let t=ek(e).toVar(),r=ek(t.mul(t)).toVar(),i=ek(r.mul(r)).toVar();return eF(15.5).mul(i.mul(r)).sub(tO(40.14,i.mul(t))).add(tO(31.96,i).sub(tO(6.868,r.mul(t))).add(tO(.4298,r).add(tO(.1191,t).sub(.00232))))}),hG=eE(([e,t])=>{let r=ek(e).toVar(),i=eY(ek(.856627153315983,.137318972929847,.11189821299995),ek(.0951212405381588,.761241990602591,.0767994186031903),ek(.0482516061458583,.101439036467562,.811302368396859)),s=eY(ek(1.1271005818144368,-.1413297634984383,-.14132976349843826),ek(-.11060664309660323,1.157823702216272,-.11060664309660294),ek(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=eF(-12.47393),a=eF(4.026069);return r.mulAssign(t),r.assign(hV.mul(r)),r.assign(i.mul(r)),r.assign(rG(r,1e-10)),r.assign(rc(r)),r.assign(r.sub(n).div(a.sub(n))),r.assign(r1(r,0,1)),r.assign(hO(r)),r.assign(s.mul(r)),r.assign(rj(rG(ek(0),r),ek(2.2))),r.assign(hD.mul(r)),r.assign(r1(r,0,1)),r}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hk=eE(([e,t])=>{let r=eF(.76),i=eF(.15),s=rO((e=e.mul(t)).r,rO(e.g,e.b)),n=it(s.lessThan(.08),s.sub(tO(6.25,s.mul(s))),.04);e.subAssign(n);let a=rG(e.r,rG(e.g,e.b));eM(a.lessThan(r),()=>e);let o=tV(1,r),l=tV(1,o.mul(o).div(a.add(o.sub(r))));e.mulAssign(l.div(a));let u=tV(1,tG(1,i.mul(a.sub(l)).add(1)));return r0(e,ek(l),u)}
4).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class hz extends U{static get type(){return"CodeNode"}constructor(e="",t=[],r=""){super("code"),this.isCodeNode=!0,this.code=e,this.includes=t,this.language=r}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){for(let t of this.getIncludes(e))t.build(e);let t=e.getCodeFromNode(this,this.getNodeType(e));return t.code=this.code,t.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}}let h$=eN(hz).setParameterLength(1,3);class hW extends hz{static get type(){return"FunctionNode"}constructor(e="",t=[],r=""){super(e,t,r)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){let t=e.getDataFromNode(this),r=t.nodeFunction;return void 0===r&&(t.nodeFunction=r=e.parser.parseFunction(this.code)),r}generate(e,t){super.generate(e);let r=this.getNodeFunction(e),i=r.name,s=r.type,n=e.getCodeFromNode(this,s);""!==i&&(n.name=i);let a=e.getPropertyName(n);return(n.code=this.getNodeFunction(e).getCode(a)+"\n","property"===t)?a:e.format(`${a}()`,s,t)}}let hH=(e,t=[],r="")=>{for(let e=0;e<t.length;e++){let r=t[e];"function"==typeof r&&(t[e]=r.functionNode)}let i=e_(new hW(e,t,r)),s=(...e)=>i.call(...e);return s.functionNode=i,s};class hq extends U{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outputType=null,this.events=new u.Qev,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){let e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:eF()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=R(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?A(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}let hj=eN(hq).setParameterLength(1);class hX extends Map{get(e,t=null,...r){if(this.has(e))return super.get(e);if(null!==t){let i=t(...r);return this.set(e,i),i}}}class hQ{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){let t=this.parameters[e];return t?t.getValue():null}}let hY=new hX;class hK extends U{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new hX,this._output=hj(null),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}
4get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(let t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(let t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){let r=this._outputs;return void 0===r[e]?r[e]=hj(t):r[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){let r=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),r[e]=t,r[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),r[e]=t,r[e].events.addEventListener("refresh",this.onRefresh)):void 0===r[e]?(r[e]=hj(t),r[e].events.addEventListener("refresh",this.onRefresh)):r[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(let e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){let r=this.getObject()[e];if("function"==typeof r)return r(...t)}async callAsync(e,...t){let r=this.getObject()[e];if("function"==typeof r)return"AsyncFunction"===r.constructor.name?await r(...t):r(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;let e=()=>this.refresh(),t=(e,t)=>this.setOutput(e,t),r=new hQ(this),i=hY.get("THREE"),s=hY.get("TSL"),n=this.getMethod(),a=[r,this._local,hY,e,t,i,s];this._object=n(...a);let o=this._object.layout;if(o&&(!1===o.cache&&this._local.clear(),this._output.outputType=o.outputType||null,Array.isArray(o.elements)))for(let e of o.elements){let t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){for(let t in super.deserialize(e),this.parameters){let e=this.parameters[t];e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){let e=this.getDefaultOutput().value;return e&&e.isNode?e:eF()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;let e="layout, init, main, dispose",t="var "+e+"; var output = {};\n"+this.codeNode.code+"\nreturn { ...output, "+e+" };";return this._method=Function("parameters","local","global","refresh","setOutput","THREE","TSL",t),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){let t=[p(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(let r in this.parameters)t.push(this.parameters[r].getCacheKey(e));return g(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}let hZ=eN(hK).setParameterLength(1,2);function hJ(e){let t,r=e.context.getViewZ;return void 0!==r&&(t=r(this)),(t||sk.z).negate()}let h0=eE(([e,t],r)=>r4(e,t,hJ(r))),h1=eE(([e],t)=>{let r=hJ(t);return e.mul(e,r,r).negate().exp().oneMinus()}),h2=eE(([e,t])=>eH(t.toFloat().mix(th.rgb,e.toVec3()),th.a)),h3=null,h4=null;class h6 extends U{static get type(){return"RangeNode"}constructor(e=eF(),t=eF()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){let t=e.getTypeLength(v(this.minNode.value)),r=e.getTypeLength(v(this.maxNode.value));return t>r?t:r}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){let t=e.object,r=null;if(t.count>1){let i=this.minNode.value,s=this.maxNode.value,n=e.getTypeLength(v(i)),a=e.getTypeLength(v(s));h3=h3||new u.IUQ,h4=h4||new u.IUQ,h3.setScalar(0),h4.setScalar(0),1===n?h3.setScalar(i):i.isColor?h3.set(i.r,i.g,i.b,1):h3.set(i.x,i.y,i.z||0,i.w||0),1===a?h4.setScalar(s):s.isColor?h4.set(s.r,s.g,s.b,1):h4.set(s.x,s.y,s.z||0,s.w||0);
4let o=4*t.count,l=new Float32Array(o);for(let e=0;e<o;e++){let t=e%4,r=h3.getComponent(t),i=h4.getComponent(t);l[e]=u.cj9.lerp(r,i,Math.random())}let d=this.getNodeType(e);if(t.count<=4096)r=se(l,"vec4",t.count).element(ah).convert(d);else{let t=new u.uWO(l,4);e.geometry.setAttribute("__range"+this.id,t),r=iU(t).convert(d)}}else r=eF(0);return r}}let h8=eN(h6).setParameterLength(2);class h5 extends U{static get type(){return"ComputeBuiltinNode"}constructor(e,t){super(t),this._builtinName=e}getHash(e){return this.getBuiltinName(e)}getNodeType(){return this.nodeType}setBuiltinName(e){return this._builtinName=e,this}getBuiltinName(){return this._builtinName}hasBuiltin(e){return e.hasBuiltin(this._builtinName)}generate(e,t){let r=this.getBuiltinName(e),i=this.getNodeType(e);return"compute"===e.shaderStage?e.format(r,i,t):(console.warn(`ComputeBuiltinNode: Compute built-in value ${r} can not be accessed in the ${e.shaderStage} stage`),e.generateConst(i))}serialize(e){super.serialize(e),e.global=this.global,e._builtinName=this._builtinName}deserialize(e){super.deserialize(e),this.global=e.global,this._builtinName=e._builtinName}}let h9=(e,t)=>e_(new h5(e,t)),h7=h9("numWorkgroups","uvec3"),ce=h9("workgroupId","uvec3"),ct=h9("globalId","uvec3"),cr=h9("localId","uvec3"),ci=h9("subgroupSize","uint");class cs extends U{constructor(e){super(),this.scope=e}generate(e){let{scope:t}=this,{renderer:r}=e;!0===r.backend.isWebGLBackend?e.addFlowCode(` // ${t}Barrier 5`):e.addLineFlowCode(`${t}Barrier()`,this)}}let cn=eN(cs);class ca extends I{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let r,i=e.context.assign;if(r=super.generate(e),!0!==i){let i=this.getNodeType(e);r=e.format(r,i,t)}return r}}class co extends U{constructor(e,t,r=0){super(t),this.bufferType=t,this.bufferCount=r,this.isWorkgroupInfoNode=!0,this.elementType=t,this.scope=e}label(e){return this.name=e,this}setScope(e){return this.scope=e,this}getElementType(){return this.elementType}getInputType(){return`${this.scope}Array`}element(e){return e_(new ca(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}class cl extends U{static get type(){return"AtomicFunctionNode"}constructor(e,t,r){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=r,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){let t=e.getNodeProperties(this),r=t.parents,i=this.method,s=this.getNodeType(e),n=this.getInputType(e),a=this.pointerNode,o=this.valueNode,l=[];l.push(`&${a.build(e,n)}`),null!==o&&l.push(o.build(e,n));let u=`${e.getMethod(i,s)}( ${l.join(", ")} )`;if(1!==r.length||!0!==r[0].isStackNode)return void 0===t.constNode&&(t.constNode=ij(u,s).toConst()),t.constNode.build(e);e.addLineFlowCode(u,this)}}cl.ATOMIC_LOAD="atomicLoad",cl.ATOMIC_STORE="atomicStore",cl.ATOMIC_ADD="atomicAdd",cl.ATOMIC_SUB="atomicSub",cl.ATOMIC_MAX="atomicMax",cl.ATOMIC_MIN="atomicMin",cl.ATOMIC_AND="atomicAnd",cl.ATOMIC_OR="atomicOr",cl.ATOMIC_XOR="atomicXor";let cu=eN(cl),cd=(e,t,r)=>cu(e,t,r).toStack();function ch(e){let t=(n=n||new WeakMap).get(e);return void 0===t&&n.set(e,t={}),t}function cc(e){let t=ch(e);return t.shadowMatrix||(t.shadowMatrix=tw("mat4").setGroup(tR).onRenderUpdate(()=>(!0!==e.castShadow&&e.shadow.updateMatrices(e),e.shadow.matrix)))}function cp(e,t=sO){let r=cc(e).mul(t);return r.xyz.div(r.w)}function cg(e){let t=ch(e);return t.position||(t.position=tw(new u.Pq0).setGroup(tR).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(e.matrixWorld)))}function cm(e){let t=ch(e);return t.targetPosition||(t.targetPosition=tw(new u.Pq0).setGroup(tR).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(e.target.matrixWorld)))}function cf(e){let t=ch(e);return t.viewPosition||(t.viewPosition=tw(new u.Pq0).setGroup(tR).onRenderUpdate(({camera:t},r)=>{r.value=r.value||new u.Pq0,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)}))}let cy=e=>sh.transformDirection(cg(e).sub(cm(e))),cx=(e,t)=>{for(let r of t)if(r.isAnalyticLightNode&&r.light.id===e)return r;return null},cb=new WeakMap;class cT extends U{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=ek().toVar(),this.totalSpecularNode=ek().toVar(),this.outgoingLightNode=ek().toVar(),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){let e=[],t=this._lights;for(let r=0;r<t.length;r++){let i=t[r];
5if(e.push(i.id),!0===i.isSpotLight){let t=null!==i.map?i.map.id:-1;e.push(t)}}return g(e)}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);let t=[];for(let e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){for(let t of e.getDataFromNode(this).nodes)t.build(e)}setupLightsNode(e){let t=[],r=this._lightNodes,i=this._lights.sort((e,t)=>e.id-t.id),s=e.renderer.library;for(let e of i)if(e.isNode)t.push(e_(e));else{let i=null;if(null!==r&&(i=cx(e.id,r)),null===i){let r=s.getLightNodeClass(e.constructor);if(null===r){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let i=null;cb.has(e)?i=cb.get(e):(i=e_(new r(e)),cb.set(e,i)),t.push(i)}}this._lightNodes=t}setupDirectLight(e,t,r){let{lightingModel:i,reflectedLight:s}=e.context;i.direct({...r,lightNode:t,reflectedLight:s},e)}setupDirectRectAreaLight(e,t,r){let{lightingModel:i,reflectedLight:s}=e.context;i.directRectArea({...r,lightNode:t,reflectedLight:s},e)}setupLights(e,t){for(let r of t)r.build(e)}getLightNodes(e){return null===this._lightNodes&&this.setupLightsNode(e),this._lightNodes}setup(e){let t=e.lightsNode;e.lightsNode=this;let r=this.outgoingLightNode,i=e.context,s=i.lightingModel,n=e.getDataFromNode(this);if(s){let{totalDiffuseNode:t,totalSpecularNode:a}=this;i.outgoingLight=r,n.nodes=e.addStack().nodes,s.start(e);let{backdrop:o,backdropAlpha:l}=i,{directDiffuse:u,directSpecular:d,indirectDiffuse:h,indirectSpecular:c}=i.reflectedLight,p=u.add(h);null!==o&&(p=null!==l?ek(l.mix(p,o)):ek(o),i.material.transparent=!0),t.assign(p),a.assign(d.add(c)),r.assign(t.add(a)),s.finish(e),r=r.bypass(e.removeStack())}else n.nodes=[];return e.lightsNode=t,r}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 c_ extends U{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=w.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){cv.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||sO)}dispose(){this.updateBeforeType=w.NONE}}let cv=e1("vec3","shadowPositionWorld"),cS=new WeakMap,cN=eE(({depthTexture:e,shadowCoord:t,depthLayer:r})=>{let i=i5(e,t.xy).label("t_basic");return e.isDepthArrayTexture&&(i=i.depth(r)),i.compare(t.z)}),cR=eE(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:i})=>{let s=(t,r)=>{let s=i5(e,t);return e.isDepthArrayTexture&&(s=s.depth(i)),s.compare(r)},n=nn("mapSize","vec2",r).setGroup(tR),a=nn("radius","float",r).setGroup(tR),o=eD(1).div(n),l=o.x.negate().mul(a),u=o.y.negate().mul(a),d=o.x.mul(a),h=o.y.mul(a),c=l.div(2),p=u.div(2),g=d.div(2),m=h.div(2);return tD(s(t.xy.add(eD(l,u)),t.z),s(t.xy.add(eD(0,u)),t.z),s(t.xy.add(eD(d,u)),t.z),s(t.xy.add(eD(c,p)),t.z),s(t.xy.add(eD(0,p)),t.z),s(t.xy.add(eD(g,p)),t.z),s(t.xy.add(eD(l,0)),t.z),s(t.xy.add(eD(c,0)),t.z),s(t.xy,t.z),s(t.xy.add(eD(g,0)),t.z),s(t.xy.add(eD(d,0)),t.z),s(t.xy.add(eD(c,m)),t.z),s(t.xy.add(eD(0,m)),t.z),s(t.xy.add(eD(g,m)),t.z),s(t.xy.add(eD(l,h)),t.z),s(t.xy.add(eD(0,h)),t.z),s(t.xy.add(eD(d,h)),t.z)).mul(1/17)}),cA=eE(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:i})=>{let s=(t,r)=>{let s=i5(e,t);return e.isDepthArrayTexture&&(s=s.depth(i)),s.compare(r)},n=nn("mapSize","vec2",r).setGroup(tR),a=eD(1).div(n),o=a.x,l=a.y,u=t.xy,d=rx(u.mul(n).add(.5));return u.subAssign(d.mul(a)),tD(s(u,t.z),s(u.add(eD(o,0)),t.z),s(u.add(eD(0,l)),t.z),s(u.add(a),t.z),r0(s(u.add(eD(o.negate(),0)),t.z),s(u.add(eD(o.mul(2),0)),t.z),d.x),r0(s(u.add(eD(o.negate(),l)),t.z),s(u.add(eD(o.mul(2),l)),t.z),d.x),r0(s(u.add(eD(0,l.negate())),t.z),s(u.add(eD(0,l.mul(2))),t.z),d.y),r0(s(u.add(eD(o,l.negate())),t.z),s(u.add(eD(o,l.mul(2))),t.z),d.y),r0(r0(s(u.add(eD(o.negate(),l.negate())),t.z),s(u.add(eD(o.mul(2),l.negate())),t.z),d.x),r0(s(u.add(eD(o.negate(),l.mul(2))),t.z),s(u.add(eD(o.mul(2),l.mul(2))),t.z),d.x),d.y)).mul(1/9)}),cE=eE(({depthTexture:e,shadowCoord:t,depthLayer:r})=>{let i=eF(1).toVar(),s=i5(e).sample(t.xy);(e.isDepthArrayTexture||e.isDataArrayTexture)&&(s=s.depth(r)),s=s.rg;let n=rk(t.z,s.x);return eM(n.notEqual(eF(1)),()=>{let e=t.z.sub(s.x),r=rG(0,s.y.mul(s.y)),a=r.div(r.add(e.mul(e)));a=r1(tV(a,.3).div(.95-.3)),i.assign(r1(rG(n,a)))}),i}),cw=eE(([e,t,r])=>{let i=sO.sub(e).length();return(i=i.sub(t).div(r.sub(t))).saturate()}),cC=e=>{let t=cS.get(e);if(void 0===t){let r=e.isPointLight?(e=>{let t=e.shadow.camera,r=nn("near","float",t).setGroup(tR),i=nn("far","float",t).setGroup(tR);return cw(sb(e),r,i)})(e):null;
5(t=new oh).colorNode=eH(0,0,0,1),t.depthNode=r,t.isShadowPassMaterial=!0,t.name="ShadowMaterial",t.fog=!1,cS.set(e,t)}return t},cM=new uM,cB=[],cP=(e,t,r,i)=>{cB[0]=e,cB[1]=t;let s=cM.get(cB);return(void 0===s||s.shadowType!==r||s.useVelocity!==i)&&((s=(s,n,a,o,l,d,...h)=>{(!0===s.castShadow||s.receiveShadow&&r===u.RyA)&&(i&&(N(s).useVelocity=!0),s.onBeforeShadow(e,s,a,t.camera,o,n.overrideMaterial,d),e.renderObject(s,n,a,o,l,d,...h),s.onAfterShadow(e,s,a,t.camera,o,n.overrideMaterial,d))}).shadowType=r,s.useVelocity=i,cM.set(cB,s)),cB[0]=null,cB[1]=null,s},cF=eE(({samples:e,radius:t,size:r,shadowPass:i,depthLayer:s})=>{let n=eF(0).toVar("meanVertical"),a=eF(0).toVar("squareMeanVertical"),o=e.lessThanEqual(eF(1)).select(eF(0),eF(2).div(e.sub(1))),l=e.lessThanEqual(eF(1)).select(eF(0),eF(-1));aM({start:eL(0),end:eL(e),type:"int",condition:"<"},({i:e})=>{let u=l.add(eF(e).mul(o)),d=i.sample(tD(aH.xy,eD(0,u).mul(t)).div(r));(i.value.isDepthArrayTexture||i.value.isDataArrayTexture)&&(d=d.depth(s)),d=d.x,n.addAssign(d),a.addAssign(d.mul(d))}),n.divAssign(e),a.divAssign(e);let u=rp(a.sub(n.mul(n)));return eD(n,u)}),cL=eE(({samples:e,radius:t,size:r,shadowPass:i,depthLayer:s})=>{let n=eF(0).toVar("meanHorizontal"),a=eF(0).toVar("squareMeanHorizontal"),o=e.lessThanEqual(eF(1)).select(eF(0),eF(2).div(e.sub(1))),l=e.lessThanEqual(eF(1)).select(eF(0),eF(-1));aM({start:eL(0),end:eL(e),type:"int",condition:"<"},({i:e})=>{let u=l.add(eF(e).mul(o)),d=i.sample(tD(aH.xy,eD(u,0).mul(t)).div(r));(i.value.isDepthArrayTexture||i.value.isDataArrayTexture)&&(d=d.depth(s)),n.addAssign(d.x),a.addAssign(tD(d.y.mul(d.y),d.x.mul(d.x)))}),n.divAssign(e),a.divAssign(e);let u=rp(a.sub(n.mul(n)));return eD(n,u)}),cU=[cN,cR,cA,cE],cI=new dY;class cD extends c_{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:r,shadowCoord:i,shadow:s,depthLayer:n}){let a=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),o=t({depthTexture:r,shadowCoord:i,shadow:s,depthLayer:n});return a.select(o,eF(1))}setupShadowCoord(e,t){let r,{shadow:i}=this,{renderer:s}=e,n=nn("bias","float",i).setGroup(tR),a=t;if(i.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)r=(a=a.xyz.div(a.w)).z,s.coordinateSystem===u.i7u&&(r=r.mul(2).sub(1));else{let e=a.w;a=a.xy.div(e);let t=nn("near","float",i.camera).setGroup(tR),s=nn("far","float",i.camera).setGroup(tR);r=oe(e.negate(),t,s)}return ek(a.x,a.y.oneMinus(),r.add(n))}getShadowFilterFn(e){return cU[e]}setupRenderTarget(e,t){let r=new u.VCu(e.mapSize.width,e.mapSize.height);r.name="ShadowDepthTexture",r.compareFunction=u.vim;let i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=r,{shadowMap:i,depthTexture:r}}setupShadow(e){let{renderer:t}=e,{light:r,shadow:i}=this,s=t.shadowMap.type,{depthTexture:n,shadowMap:a}=this.setupRenderTarget(i,e);if(i.camera.updateProjectionMatrix(),s===u.RyA){n.compareFunction=null,a.isRenderTargetArray?(a._vsmShadowMapVertical||(a._vsmShadowMapVertical=e.createRenderTargetArray(i.mapSize.width,i.mapSize.height,a.depth,{format:u.paN,type:u.ix0,depthBuffer:!1}),a._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=a._vsmShadowMapVertical,a._vsmShadowMapHorizontal||(a._vsmShadowMapHorizontal=e.createRenderTargetArray(i.mapSize.width,i.mapSize.height,a.depth,{format:u.paN,type:u.ix0,depthBuffer:!1}),a._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=a._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:u.paN,type:u.ix0,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:u.paN,type:u.ix0,depthBuffer:!1}));let t=i5(n);n.isDepthArrayTexture&&(t=t.depth(this.depthLayer));let r=i5(this.vsmShadowMapVertical.texture);n.isDepthArrayTexture&&(r=r.depth(this.depthLayer));
5let s=nn("blurSamples","float",i).setGroup(tR),o=nn("radius","float",i).setGroup(tR),l=nn("mapSize","vec2",i).setGroup(tR),d=this.vsmMaterialVertical||(this.vsmMaterialVertical=new oh);d.fragmentNode=cF({samples:s,radius:o,size:l,shadowPass:t,depthLayer:this.depthLayer}).context(e.getSharedContext()),d.name="VSMVertical",(d=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new oh)).fragmentNode=cL({samples:s,radius:o,size:l,shadowPass:r,depthLayer:this.depthLayer}).context(e.getSharedContext()),d.name="VSMHorizontal"}let o=nn("intensity","float",i).setGroup(tR),l=nn("normalBias","float",i).setGroup(tR),d=cc(r).mul(cv.add(sZ.mul(l))),h=this.setupShadowCoord(e,d),c=i.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(null===c)throw Error("THREE.WebGPURenderer: Shadow map type not supported yet.");let p=s===u.RyA?this.vsmShadowMapHorizontal.texture:n,g=this.setupShadowFilter(e,{filterFn:c,shadowTexture:a.texture,depthTexture:p,shadowCoord:h,shadow:i,depthLayer:this.depthLayer}),m=i5(a.texture,h);n.isDepthArrayTexture&&(m=m.depth(this.depthLayer));let f=r0(1,g.rgb.mix(m,1),o.mul(m.a)).toVar();return this.shadowMap=a,this.shadow.map=a,f}setup(e){if(!1!==e.renderer.shadowMap.enabled)return eE(()=>{let t=this._node;return this.setupShadowPosition(e),null===t&&(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){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:n}=e;t.updateMatrices(i),r.setSize(t.mapSize.width,t.mapSize.height,r.depth),s.render(n,t.camera)}updateShadow(e){var t,r,i;let{shadowMap:s,light:n,shadow:o}=this,{renderer:l,scene:d,camera:h}=e,c=l.shadowMap.type,p=s.depthTexture.version;this._depthVersionCached=p;let g=o.camera.layers.mask;(0xfffffffe&o.camera.layers.mask)==0&&(o.camera.layers.mask=h.layers.mask);let m=l.getRenderObjectFunction(),f=l.getMRT(),y=!!f&&f.has("velocity");t=function(e,t={}){return t.toneMapping=e.toneMapping,t.toneMappingExposure=e.toneMappingExposure,t.outputColorSpace=e.outputColorSpace,t.renderTarget=e.getRenderTarget(),t.activeCubeFace=e.getActiveCubeFace(),t.activeMipmapLevel=e.getActiveMipmapLevel(),t.renderObjectFunction=e.getRenderObjectFunction(),t.pixelRatio=e.getPixelRatio(),t.mrt=e.getMRT(),t.clearColor=e.getClearColor(t.clearColor||new u.Q1f),t.clearAlpha=e.getClearAlpha(),t.autoClear=e.autoClear,t.scissorTest=e.getScissorTest(),t}(l,t=a),l.setMRT(null),l.setRenderObjectFunction(null),l.setClearColor(0,1),l.autoClear=!0,r=function(e,t={}){return t.background=e.background,t.backgroundNode=e.backgroundNode,t.overrideMaterial=e.overrideMaterial,t}(d,r=t),d.background=null,d.backgroundNode=null,d.overrideMaterial=null,a=r,d.overrideMaterial=cC(n),l.setRenderObjectFunction(cP(l,o,c,y)),l.setClearColor(0,0),l.setRenderTarget(s),this.renderShadow(e),l.setRenderObjectFunction(m),!0!==n.isPointLight&&c===u.RyA&&this.vsmPass(l),o.camera.layers.mask=g,l.toneMapping=(i=a).toneMapping,l.toneMappingExposure=i.toneMappingExposure,l.outputColorSpace=i.outputColorSpace,l.setRenderTarget(i.renderTarget,i.activeCubeFace,i.activeMipmapLevel),l.setRenderObjectFunction(i.renderObjectFunction),l.setPixelRatio(i.pixelRatio),l.setMRT(i.mrt),l.setClearColor(i.clearColor,i.clearAlpha),l.autoClear=i.autoClear,l.setScissorTest(i.scissorTest),d.background=i.background,d.backgroundNode=i.backgroundNode,d.overrideMaterial=i.overrideMaterial}vsmPass(e){let{shadow:t}=this,r=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,r),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,r),e.setRenderTarget(this.vsmShadowMapVertical),cI.material=this.vsmMaterialVertical,cI.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),cI.material=this.vsmMaterialHorizontal,cI.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),super.dispose()}updateBefore(e){let{shadow:t}=this,r=t.needsUpdate||t.autoUpdate;r&&(this._cameraFrameId[e.camera]===e.frameId&&(r=!1),this._cameraFrameId[e.camera]=e.frameId),r&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}let cV=(e,t)=>e_(new cD(e,t)),cO=new u.Q1f,cG=eE(([e,t])=>{let r=e.toVar(),i=rR(r),s=tG(1,rG(i.x,rG(i.y,i.z)));i.mulAssign(s),r.mulAssign(s.mul(t.mul(2).oneMinus()));let n=eD(r.xy).toVar(),a=t.mul(1.5).oneMinus();return eM(i.z.greaterThanEqual(a),()=>{eM(r.z.greaterThan(0),()=>{n.x.assign(tV(4,r.x))})}).ElseIf(i.x.greaterThanEqual(a),()=>{let e=rA(r.x);n.x.assign(r.z.mul(e).add(e.mul(2)))}).ElseIf(i.y.greaterThanEqual(a),()=>{let e=rA(r.y);n.x.assign(r.x.add(e.mul(2)).add(2)),n.y.assign(r.z.mul(e).sub(2))}),eD(.125,.25).mul(n).add(eD(.375,.75)).flipY()}).setLayout({name:"cubeToUV",type:"vec2",inputs:[{name:"pos",type:"vec3"},{name:"texelSizeY",type:"float"}]}),ck=eE(({depthTexture:e,bd3D:t,dp:r,texelSize:i})=>i5(e,cG(t,i.y)).compare(r)),cz=eE(({depthTexture:e,bd3D:t,dp:r,texelSize:i,shadow:s})=>{let n=nn("radius","float",s).setGroup(tR),a=eD(-1,1).mul(n).mul(i.y);return i5(e,cG(t.add(a.xyy),i.y)).compare(r).add(i5(e,cG(t.add(a.yyy),i.y)).compare(r)).add(i5(e,cG(t.add(a.xyx),i.y)).compare(r)).add(i5(e,cG(t.add(a.yyx),i.y)).compare(r)).add(i5(e,cG(t,i.y)).compare(r)).add(i5(e,cG(t.add(a.xxy),i.y)).compare(r)).add(i5(e,cG(t.add(a.yxy),i.y)).compare(r)).add(i5(e,cG(t.add(a.xxx),i.y)).compare(r)).add(i5(e,cG(t.add(a.yxx),i.y)).compare(r)).mul(1/9)}),c$=eE(({filterFn:e,depthTexture:t,shadowCoord:r,shadow:i})=>{let s=r.xyz.toVar(),n=s.length(),a=tw("float").setGroup(tR).onRenderUpd
5ate(()=>i.camera.near),o=tw("float").setGroup(tR).onRenderUpdate(()=>i.camera.far),l=nn("bias","float",i).setGroup(tR),u=tw(i.mapSize).setGroup(tR),d=eF(1).toVar();return eM(n.sub(o).lessThanEqual(0).and(n.sub(a).greaterThanEqual(0)),()=>{let r=n.sub(a).div(o.sub(a)).toVar();r.addAssign(l);let h=s.normalize(),c=eD(1).div(u.mul(eD(4,2)));d.assign(e({depthTexture:t,bd3D:h,dp:r,texelSize:c,shadow:i}))}),d}),cW=new u.IUQ,cH=new u.I9Y,cq=new u.I9Y;class cj extends cD{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===u.bTm?ck:cz}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,shadowTexture:r,depthTexture:i,shadowCoord:s,shadow:n}){return c$({filterFn:t,shadowTexture:r,depthTexture:i,shadowCoord:s,shadow:n})}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:n}=e,a=t.getFrameExtents();cq.copy(t.mapSize),cq.multiply(a),r.setSize(cq.width,cq.height),cH.copy(t.mapSize);let o=s.autoClear,l=s.getClearColor(cO),u=s.getClearAlpha();s.autoClear=!1,s.setClearColor(t.clearColor,t.clearAlpha),s.clear();let d=t.getViewportCount();for(let e=0;e<d;e++){let a=t.getViewport(e),o=cH.x*a.x,l=cq.y-cH.y-cH.y*a.y;cW.set(o,l,cH.x*a.z,cH.y*a.w),r.viewport.copy(cW),t.updateMatrices(i,e),s.render(n,t.camera)}s.autoClear=o,s.setClearColor(l,u)}}let cX=(e,t)=>e_(new cj(e,t));class cQ extends aD{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new u.Q1f,this.colorNode=e&&e.colorNode||tw(this.color).setGroup(tR),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=w.FRAME}customCacheKey(){return m(this.light.id,+!!this.light.castShadow)}getHash(){return this.light.uuid}getLightVector(e){return cf(this.light).sub(e.context.positionView||sk)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return cV(this.light)}setupShadow(e){let{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let r=this.shadowColorNode;if(null===r){let e,t=this.light.shadow.shadowNode;e=void 0!==t?e_(t):this.setupShadowNode(),this.shadowNode=e,this.shadowColorNode=r=this.colorNode.mul(e),this.baseColorNode=this.colorNode}this.colorNode=r}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);let t=this.setupDirect(e),r=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),r&&e.lightsNode.setupDirectRectAreaLight(e,this,r)}update(){let{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}let cY=eE(({lightDistance:e,cutoffDistance:t,decayExponent:r})=>{let i=e.pow(r).max(.01).reciprocal();return t.greaterThan(0).select(i.mul(e.div(t).pow4().oneMinus().clamp().pow2()),i)}),cK=({color:e,lightVector:t,cutoffDistance:r,decayExponent:i})=>{let s=t.normalize(),n=cY({lightDistance:t.length(),cutoffDistance:r,decayExponent:i});return{lightDirection:s,lightColor:e.mul(n)}};class cZ extends cQ{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=tw(0).setGroup(tR),this.decayExponentNode=tw(2).setGroup(tR)}update(e){let{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return cX(this.light)}setupDirect(e){return cK({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}}let cJ=eE(([e=i1()])=>{let t=e.mul(2),r=t.x.floor(),i=t.y.floor();return r.add(i).mod(2).sign()}),c0=eE(([e=i1()],{renderer:t,material:r})=>{let i=eF(1).toVar(),s=rJ(e.mul(2).sub(1));if(r.alphaToCoverage&&t.samples>1){let e=eF(s.fwidth()).toVar();i.assign(r4(e.oneMinus(),e.add(1),s).oneMinus())}else s.greaterThan(1).discard();return i}),c1=eE(([e,t,r])=>{let i=eF(r).toVar(),s=eF(t).toVar();return it(eI(e).toVar(),s,i)}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),c2=eE(([e,t])=>{let r=eI(t).toVar(),i=eF(e).toVar();return it(r,i.negate(),i)}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),c3=eE(([e])=>eL(rm(eF(e).toVar()))).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),c4=eE(([e,t])=>{let r=eF(e).toVar();return t.assign(c3(r)),r.sub(eF(t))}),c6=db([eE(([e,t,r,i,s,n])=>{let a=eF(n).toVar(),o=eF(s).toVar(),l=eF(i).toVar(),u=eF(r).toVar(),d=eF(t).toVar(),h=eF(e).toVar(),c=eF(tV(1,o)).toVar();return tV(1,a).mul(h.mul(c).add(d.mul(o))).add(a.mul(u.mul(c).add(l.mul(o))))}).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),eE(([e,t,r,i,s,n])=>{let a=eF(n).toVar(),o=eF(s).toVar(),l=ek(i).toVar(),u=ek(r).toVar(),d=ek(t).toVar(),h=ek(e).toVar(),c=eF(tV(1,o)).toVar();return tV(1,a).mul(h.mul(c).add(d.mul(o))).add(a.mul(u.mul(c).add(l.mul(o))))}
vendor: 4,297 bytes, line 5
5).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),c8=db([eE(([e,t,r,i,s,n,a,o,l,u,d])=>{let h=eF(d).toVar(),c=eF(u).toVar(),p=eF(l).toVar(),g=eF(o).toVar(),m=eF(a).toVar(),f=eF(n).toVar(),y=eF(s).toVar(),x=eF(i).toVar(),b=eF(r).toVar(),T=eF(t).toVar(),_=eF(e).toVar(),v=eF(tV(1,p)).toVar(),S=eF(tV(1,c)).toVar();return eF(tV(1,h)).toVar().mul(S.mul(_.mul(v).add(T.mul(p))).add(c.mul(b.mul(v).add(x.mul(p))))).add(h.mul(S.mul(y.mul(v).add(f.mul(p))).add(c.mul(m.mul(v).add(g.mul(p))))))}).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),eE(([e,t,r,i,s,n,a,o,l,u,d])=>{let h=eF(d).toVar(),c=eF(u).toVar(),p=eF(l).toVar(),g=ek(o).toVar(),m=ek(a).toVar(),f=ek(n).toVar(),y=ek(s).toVar(),x=ek(i).toVar(),b=ek(r).toVar(),T=ek(t).toVar(),_=ek(e).toVar(),v=eF(tV(1,p)).toVar(),S=eF(tV(1,c)).toVar();return eF(tV(1,h)).toVar().mul(S.mul(_.mul(v).add(T.mul(p))).add(c.mul(b.mul(v).add(x.mul(p))))).add(h.mul(S.mul(y.mul(v).add(f.mul(p))).add(c.mul(m.mul(v).add(g.mul(p))))))}).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),c5=db([eE(([e,t,r])=>{let i=eF(r).toVar(),s=eF(t).toVar(),n=eU(e).toVar(),a=eU(n.bitAnd(eU(7))).toVar(),o=eF(c1(a.lessThan(eU(4)),s,i)).toVar(),l=eF(tO(2,c1(a.lessThan(eU(4)),i,s))).toVar();return c2(o,eI(a.bitAnd(eU(1)))).add(c2(l,eI(a.bitAnd(eU(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),eE(([e,t,r,i])=>{let s=eF(i).toVar(),n=eF(r).toVar(),a=eF(t).toVar(),o=eU(e).toVar(),l=eU(o.bitAnd(eU(15))).toVar(),u=eF(c1(l.lessThan(eU(8)),a,n)).toVar(),d=eF(c1(l.lessThan(eU(4)),n,c1(l.equal(eU(12)).or(l.equal(eU(14))),a,s))).toVar();return c2(u,eI(l.bitAnd(eU(1)))).add(c2(d,eI(l.bitAnd(eU(2)))))}).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]})]),c9=db([eE(([e,t,r])=>{let i=eF(r).toVar(),s=eF(t).toVar(),n=e$(e).toVar();return ek(c5(n.x,s,i),c5(n.y,s,i),c5(n.z,s,i))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),eE(([e,t,r,i])=>{let s=eF(i).toVar(),n=eF(r).toVar(),a=eF(t).toVar(),o=e$(e).toVar();return ek(c5(o.x,a,n,s),c5(o.y,a,n,s),c5(o.z,a,n,s))}).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]})]),c7=eE(([e])=>tO(.6616,eF(e).toVar())).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),pe=eE(([e])=>tO(.982,eF(e).toVar())).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),pt=db([c7,eE(([e])=>tO(.6616,ek(e).toVar())).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),pr=db([pe,eE(([e])=>tO(.982,ek(e).toVar())).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),pi=eE(([e,t])=>{let r=eL(t).toVar(),i=eU(e).toVar();return i.shiftLeft(r).bitOr(i.shiftRight(eL(32).sub(r)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),ps=eE(([e,t,r])=>{e.subAssign(r),e.bitXorAssign(pi(r,eL(4))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(pi(e,eL(6))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(pi(t,eL(8))),t.addAssign(e),e.subAssign(r),e.bitXorAssign(pi(r,eL(16))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(pi(e,eL(19))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(pi(t,eL(4))),t.addAssign(e)}),pn=eE(([e,t,r])=>{let i=eU(r).toVar(),s=eU(t).toVar(),n=eU(e).toVar();
5return i.bitXorAssign(s),i.subAssign(pi(s,eL(14))),n.bitXorAssign(i),n.subAssign(pi(i,eL(11))),s.bitXorAssign(n),s.subAssign(pi(n,eL(25))),i.bitXorAssign(s),i.subAssign(pi(s,eL(16))),n.bitXorAssign(i),n.subAssign(pi(i,eL(4))),s.bitXorAssign(n),s.subAssign(pi(n,eL(14))),i.bitXorAssign(s),i.subAssign(pi(s,eL(24))),i}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),pa=eE(([e])=>eF(eU(e).toVar()).div(eF(eU(eL(0xffffffff))))).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),po=eE(([e])=>{let t=eF(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),pl=eE(([e])=>{let t=eL(e).toVar(),r=eU(eU(1)).toVar(),i=eU(eU(eL(0xdeadbeef)).add(r.shiftLeft(eU(2))).add(eU(13))).toVar();return pn(i.add(eU(t)),i,i)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),pu=eE(([e,t])=>{let r=eL(t).toVar(),i=eL(e).toVar(),s=eU(eU(2)).toVar(),n=eU().toVar(),a=eU().toVar(),o=eU().toVar();return n.assign(a.assign(o.assign(eU(eL(0xdeadbeef)).add(s.shiftLeft(eU(2))).add(eU(13))))),n.addAssign(eU(i)),a.addAssign(eU(r)),pn(n,a,o)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),pd=eE(([e,t,r])=>{let i=eL(r).toVar(),s=eL(t).toVar(),n=eL(e).toVar(),a=eU(eU(3)).toVar(),o=eU().toVar(),l=eU().toVar(),u=eU().toVar();return o.assign(l.assign(u.assign(eU(eL(0xdeadbeef)).add(a.shiftLeft(eU(2))).add(eU(13))))),o.addAssign(eU(n)),l.addAssign(eU(s)),u.addAssign(eU(i)),pn(o,l,u)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),ph=db([pl,pu,pd,eE(([e,t,r,i])=>{let s=eL(i).toVar(),n=eL(r).toVar(),a=eL(t).toVar(),o=eL(e).toVar(),l=eU(eU(4)).toVar(),u=eU().toVar(),d=eU().toVar(),h=eU().toVar();return u.assign(d.assign(h.assign(eU(eL(0xdeadbeef)).add(l.shiftLeft(eU(2))).add(eU(13))))),u.addAssign(eU(o)),d.addAssign(eU(a)),h.addAssign(eU(n)),ps(u,d,h),u.addAssign(eU(s)),pn(u,d,h)}).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),eE(([e,t,r,i,s])=>{let n=eL(s).toVar(),a=eL(i).toVar(),o=eL(r).toVar(),l=eL(t).toVar(),u=eL(e).toVar(),d=eU(eU(5)).toVar(),h=eU().toVar(),c=eU().toVar(),p=eU().toVar();return h.assign(c.assign(p.assign(eU(eL(0xdeadbeef)).add(d.shiftLeft(eU(2))).add(eU(13))))),h.addAssign(eU(u)),c.addAssign(eU(l)),p.addAssign(eU(o)),ps(h,c,p),h.addAssign(eU(a)),c.addAssign(eU(n)),pn(h,c,p)}).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),pc=db([eE(([e,t])=>{let r=eL(t).toVar(),i=eU(ph(eL(e).toVar(),r)).toVar(),s=e$().toVar();return s.x.assign(i.bitAnd(eL(255))),s.y.assign(i.shiftRight(eL(8)).bitAnd(eL(255))),s.z.assign(i.shiftRight(eL(16)).bitAnd(eL(255))),s}
5).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),eE(([e,t,r])=>{let i=eL(r).toVar(),s=eL(t).toVar(),n=eU(ph(eL(e).toVar(),s,i)).toVar(),a=e$().toVar();return a.x.assign(n.bitAnd(eL(255))),a.y.assign(n.shiftRight(eL(8)).bitAnd(eL(255))),a.z.assign(n.shiftRight(eL(16)).bitAnd(eL(255))),a}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),pp=db([eE(([e])=>{let t=eD(e).toVar(),r=eL().toVar(),i=eL().toVar(),s=eF(c4(t.x,r)).toVar(),n=eF(c4(t.y,i)).toVar(),a=eF(po(s)).toVar(),o=eF(po(n)).toVar();return pt(eF(c6(c5(ph(r,i),s,n),c5(ph(r.add(eL(1)),i),s.sub(1),n),c5(ph(r,i.add(eL(1))),s,n.sub(1)),c5(ph(r.add(eL(1)),i.add(eL(1))),s.sub(1),n.sub(1)),a,o)).toVar())}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),eE(([e])=>{let t=ek(e).toVar(),r=eL().toVar(),i=eL().toVar(),s=eL().toVar(),n=eF(c4(t.x,r)).toVar(),a=eF(c4(t.y,i)).toVar(),o=eF(c4(t.z,s)).toVar(),l=eF(po(n)).toVar(),u=eF(po(a)).toVar(),d=eF(po(o)).toVar();return pr(eF(c8(c5(ph(r,i,s),n,a,o),c5(ph(r.add(eL(1)),i,s),n.sub(1),a,o),c5(ph(r,i.add(eL(1)),s),n,a.sub(1),o),c5(ph(r.add(eL(1)),i.add(eL(1)),s),n.sub(1),a.sub(1),o),c5(ph(r,i,s.add(eL(1))),n,a,o.sub(1)),c5(ph(r.add(eL(1)),i,s.add(eL(1))),n.sub(1),a,o.sub(1)),c5(ph(r,i.add(eL(1)),s.add(eL(1))),n,a.sub(1),o.sub(1)),c5(ph(r.add(eL(1)),i.add(eL(1)),s.add(eL(1))),n.sub(1),a.sub(1),o.sub(1)),l,u,d)).toVar())}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),pg=db([eE(([e])=>{let t=eD(e).toVar(),r=eL().toVar(),i=eL().toVar(),s=eF(c4(t.x,r)).toVar(),n=eF(c4(t.y,i)).toVar(),a=eF(po(s)).toVar(),o=eF(po(n)).toVar();return pt(ek(c6(c9(pc(r,i),s,n),c9(pc(r.add(eL(1)),i),s.sub(1),n),c9(pc(r,i.add(eL(1))),s,n.sub(1)),c9(pc(r.add(eL(1)),i.add(eL(1))),s.sub(1),n.sub(1)),a,o)).toVar())}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),eE(([e])=>{let t=ek(e).toVar(),r=eL().toVar(),i=eL().toVar(),s=eL().toVar(),n=eF(c4(t.x,r)).toVar(),a=eF(c4(t.y,i)).toVar(),o=eF(c4(t.z,s)).toVar(),l=eF(po(n)).toVar(),u=eF(po(a)).toVar(),d=eF(po(o)).toVar();return pr(ek(c8(c9(pc(r,i,s),n,a,o),c9(pc(r.add(eL(1)),i,s),n.sub(1),a,o),c9(pc(r,i.add(eL(1)),s),n,a.sub(1),o),c9(pc(r.add(eL(1)),i.add(eL(1)),s),n.sub(1),a.sub(1),o),c9(pc(r,i,s.add(eL(1))),n,a,o.sub(1)),c9(pc(r.add(eL(1)),i,s.add(eL(1))),n.sub(1),a,o.sub(1)),c9(pc(r,i.add(eL(1)),s.add(eL(1))),n,a.sub(1),o.sub(1)),c9(pc(r.add(eL(1)),i.add(eL(1)),s.add(eL(1))),n.sub(1),a.sub(1),o.sub(1)),l,u,d)).toVar())}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),pm=eE(([e])=>pa(ph(eL(c3(eF(e).toVar())).toVar()))).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),pf=eE(([e])=>{let t=eD(e).toVar();return pa(ph(eL(c3(t.x)).toVar(),eL(c3(t.y)).toVar()))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),py=db([pm,pf,eE(([e])=>{let t=ek(e).toVar(),r=eL(c3(t.x)).toVar();return pa(ph(r,eL(c3(t.y)).toVar(),eL(c3(t.z)).toVar()))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),eE(([e])=>{let t=eH(e).toVar(),r=eL(c3(t.x)).toVar(),i=eL(c3(t.y)).toVar();return pa(ph(r,i,eL(c3(t.z)).toVar(),eL(c3(t.w)).toVar()))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),px=eE(([e])=>{let t=eL(c3(eF(e).toVar())).toVar();return ek(pa(ph(t,eL(0))),pa(ph(t,eL(1))),pa(ph(t,eL(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),pb=eE(([e])=>{let t=eD(e).toVar(),r=eL(c3(t.x)).toVar(),i=eL(c3(t.y)).toVar();return ek(pa(ph(r,i,eL(0))),pa(ph(r,i,eL(1))),pa(ph(r,i,eL(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),pT=db([px,pb,eE(([e])=>{let t=ek(e).toVar(),r=eL(c3(t.x)).toVar(),i=eL(c3(t.y)).toVar(),s=eL(c3(t.z)).toVar();return ek(pa(ph(r,i,s,eL(0))),pa(ph(r,i,s,eL(1))),pa(ph(r,i,s,eL(2))))}
vendor: 8,596 bytes, line 5
5).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),eE(([e])=>{let t=eH(e).toVar(),r=eL(c3(t.x)).toVar(),i=eL(c3(t.y)).toVar(),s=eL(c3(t.z)).toVar(),n=eL(c3(t.w)).toVar();return ek(pa(ph(r,i,s,n,eL(0))),pa(ph(r,i,s,n,eL(1))),pa(ph(r,i,s,n,eL(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),p_=eE(([e,t,r,i])=>{let s=eF(i).toVar(),n=eF(r).toVar(),a=eL(t).toVar(),o=ek(e).toVar(),l=eF(0).toVar(),u=eF(1).toVar();return aM(a,()=>{l.addAssign(u.mul(pp(o))),u.mulAssign(s),o.mulAssign(n)}),l}).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),pv=eE(([e,t,r,i])=>{let s=eF(i).toVar(),n=eF(r).toVar(),a=eL(t).toVar(),o=ek(e).toVar(),l=ek(0).toVar(),u=eF(1).toVar();return aM(a,()=>{l.addAssign(u.mul(pg(o))),u.mulAssign(s),o.mulAssign(n)}),l}).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),pS=eE(([e,t,r,i])=>{let s=eF(i).toVar(),n=eF(r).toVar(),a=eL(t).toVar(),o=ek(e).toVar();return eD(p_(o,a,n,s),p_(o.add(ek(eL(19),eL(193),eL(17))),a,n,s))}).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),pN=eE(([e,t,r,i])=>{let s=eF(i).toVar(),n=eF(r).toVar(),a=eL(t).toVar(),o=ek(e).toVar();return eH(ek(pv(o,a,n,s)).toVar(),eF(p_(o.add(ek(eL(19),eL(193),eL(17))),a,n,s)).toVar())}).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),pR=db([eE(([e,t,r,i,s,n,a])=>{let o=eL(a).toVar(),l=eF(n).toVar(),u=eL(s).toVar(),d=eL(i).toVar(),h=eL(r).toVar(),c=eL(t).toVar(),p=eD(e).toVar(),g=ek(pT(eD(c.add(d),h.add(u)))).toVar(),m=eD(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(l),m.addAssign(.5);let f=eD(eD(eF(c),eF(h)).add(m)).toVar(),y=eD(f.sub(p)).toVar();return eM(o.equal(eL(2)),()=>rR(y.x).add(rR(y.y))),eM(o.equal(eL(3)),()=>rG(rR(y.x),rR(y.y))),rH(y,y)}).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),eE(([e,t,r,i,s,n,a,o,l])=>{let u=eL(l).toVar(),d=eF(o).toVar(),h=eL(a).toVar(),c=eL(n).toVar(),p=eL(s).toVar(),g=eL(i).toVar(),m=eL(r).toVar(),f=eL(t).toVar(),y=ek(e).toVar(),x=ek(pT(ek(f.add(p),m.add(c),g.add(h)))).toVar();x.subAssign(.5),x.mulAssign(d),x.addAssign(.5);let b=ek(ek(eF(f),eF(m),eF(g)).add(x)).toVar(),T=ek(b.sub(y)).toVar();return eM(u.equal(eL(2)),()=>rR(T.x).add(rR(T.y)).add(rR(T.z))),eM(u.equal(eL(3)),()=>rG(rG(rR(T.x),rR(T.y)),rR(T.z))),rH(T,T)}).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),pA=eE(([e,t,r])=>{let i=eL(r).toVar(),s=eF(t).toVar(),n=eD(e).toVar(),a=eL().toVar(),o=eL().toVar(),l=eD(c4(n.x,a),c4(n.y,o)).toVar(),u=eF(1e6).toVar();return aM({start:-1,end:eL(1),name:"x",condition:"<="},({x:e})=>{aM({start:-1,end:eL(1),name:"y",condition:"<="},({y:t})=>{let r=eF(pR(l,e,t,a,o,s,i)).toVar();u.assign(rO(u,r))})}),eM(i.equal(eL(0)),()=>{u.assign(rp(u))}),u}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),pE=eE(([e,t,r])=>{let i=eL(r).toVar(),s=eF(t).toVar(),n=eD(e).toVar(),a=eL().toVar(),o=eL().toVar(),l=eD(c4(n.x,a),c4(n.y,o)).toVar(),u=eD(1e6,1e6).toVar();return aM({start:-1,end:eL(1),name:"x",condition:"<="},({x:e})=>{aM({start:-1,end:eL(1),name:"y",condition:"<="},({y:t})=>{let r=eF(pR(l,e,t,a,o,s,i)).toVar();eM(r.lessThan(u.x),()=>{u.y.assign(u.x),u.x.assign(r)}).ElseIf(r.lessThan(u.y),()=>{u.y.assign(r)})})}),eM(i.equal(eL(0)),()=>{u.assign(rp(u))}),u}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),pw=eE(([e,t,r])=>{let i=eL(r).toVar(),s=eF(t).toVar(),n=eD(e).toVar(),a=eL().toVar(),o=eL().toVar(),l=eD(c4(n.x,a),c4(n.y,o)).toVar(),u=ek(1e6,1e6,1e6).toVar();return aM({start:-1,end:eL(1),name:"x",condition:"<="},({x:e})=>{aM({start:-1,end:eL(1),name:"y",condition:"<="},({y:t})=>{let r=eF(pR(l,e,t,a,o,s,i)).toVar();eM(r.lessThan(u.x),()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(r)}).ElseIf(r.lessThan(u.y),()=>{u.z.assign(u.y),u.y.assign(r)}).ElseIf(r.lessThan(u.z),()=>{u.z.assign(r)})})}),eM(i.equal(eL(0)),()=>{u.assign(rp(u))}),u}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),pC=db([pA,eE(([e,t,r])=>{let i=eL(r).toVar(),s=eF(t).toVar(),n=ek(e).toVar(),a=eL().toVar(),o=eL().toVar(),l=eL().toVar(),u=ek(c4(n.x,a),c4(n.y,o),c4(n.z,l)).toVar(),d=eF(1e6).toVar();return aM({start:-1,end:eL(1),name:"x",condition:"<="},({x:e})=>{aM({start:-1,end:eL(1),name:"y",condition:"<="},({y:t})=>{aM({start:-1,end:eL(1),name:"z",condition:"<="},({z:r})=>{let n=eF(pR(u,e,t,r,a,o,l,s,i)).toVar();d.assign(rO(d,n))})})}),eM(i.equal(eL(0)),()=>{d.assign(rp(d))}),d}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),pM=db([pE,eE(([e,t,r])=>{let i=eL(r).toVar(),s=eF(t).toVar(),n=ek(e).toVar(),a=eL().toVar(),o=eL().toVar(),l=eL().toVar(),u=ek(c4(n.x,a),c4(n.y,o),c4(n.z,l)).toVar(),d=eD(1e6,1e6).toVar();return aM({start:-1,end:eL(1),name:"x",condition:"<="},({x:e})=>{aM({start:-1,end:eL(1),name:"y",condition:"<="},({y:t})=>{aM({start:-1,end:eL(1),name:"z",condition:"<="},({z:r})=>{let n=eF(pR(u,e,t,r,a,o,l,s,i)).toVar();eM(n.lessThan(d.x),()=>{d.y.assign(d.x),d.x.assign(n)}).ElseIf(n.lessThan(d.y),()=>{d.y.assign(n)})})})}),eM(i.equal(eL(0)),()=>{d.assign(rp(d))}),d}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),pB=db([pw,eE(([e,t,r])=>{let i=eL(r).toVar(),s=eF(t).toVar(),n=ek(e).toVar(),a=eL().toVar(),o=eL().toVar(),l=eL().toVar(),u=ek(c4(n.x,a),c4(n.y,o),c4(n.z,l)).toVar(),d=ek(1e6,1e6,1e6).toVar();return aM({start:-1,end:eL(1),name:"x",condition:"<="},({x:e})=>{aM({start:-1,end:eL(1),name:"y",condition:"<="},({y:t})=>{aM({start:-1,end:eL(1),name:"z",condition:"<="},({z:r})=>{let n=eF(pR(u,e,t,r,a,o,l,s,i)).toVar();eM(n.lessThan(d.x),()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)}).ElseIf(n.lessThan(d.y),()=>{d.z.assign(d.y),d.y.assign(n)}).ElseIf(n.lessThan(d.z),()=>{d.z.assign(n)})})})}),eM(i.equal(eL(0)),()=>{d.assign(rp(d))}),d}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),pP=eE(([e])=>{let t=e.y,r=e.z,i=ek().toVar();return eM(t.lessThan(1e-4),()=>{i.assign(ek(r,r,r))}).Else(()=>{let s=e.x,n=eL(rL(s=s.sub(rm(s)).mul(6).toVar())),a=s.sub(eF(n)),o=r.mul(t.oneMinus()),l=r.mul(t.mul(a).oneMinus()),u=r.mul(t.mul(a.oneMinus()).oneMinus());eM(n.equal(eL(0)),()=>{i.assign(ek(r,u,o))}).ElseIf(n.equal(eL(1)),()=>{i.assign(ek(l,r,o))}).ElseIf(n.equal(eL(2)),()=>{i.assign(ek(o,r,u))}).ElseIf(n.equal(eL(3)),()=>{i.assign(ek(o,l,r))}).ElseIf(n.equal(eL(4)),()=>{i.assign(ek(u,o,r))}).Else(()=>{i.assign(ek(r,o,l))})}),i}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),pF=eE(([e])=>{let t=ek(e).toVar(),r=eF(t.x).toVar(),i=eF(t.y).toVar(),s=eF(t.z).toVar(),n=eF(rO(r,rO(i,s))).toVar(),a=eF(rG(r,rG(i,s))).toVar(),o=eF(a.sub(n)).toVar(),l=eF().toVar(),u=eF().toVar(),d=eF().toVar();return d.assign(a),eM(a.greaterThan(0),()=>{u.assign(o.div(a))}).Else(()=>{u.assign(0)}),eM(u.lessThanEqual(0),()=>{l.assign(0)}).Else(()=>{eM(r.greaterThanEqual(a),()=>{l.assign(i.sub(s).div(o))}).ElseIf(i.greaterThanEqual(a),()=>{l.assign(tD(2,s.sub(r).div(o)))}).Else(()=>{l.assign(tD(4,r.sub(i).div(o)))}),l.mulAssign(1/6),eM(l.lessThan(0),()=>{l.addAssign(1)})}),ek(l,u,d)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),pL=eE(([e])=>{let t=ek(e).toVar(),r=eW(tH(t,ek(.04045))).toVar();return r0(ek(t.div(12.92)).toVar(),ek(rj(rG(t.add(ek(.055)),ek(0)).div(1.055),e
5k(2.4))).toVar(),r)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),pU=(e,t)=>{e=eF(e);let r=eD((t=eF(t)).dFdx(),t.dFdy()).length().mul(.7071067811865476);return r4(e.sub(r),e.add(r),t)},pI=(e,t,r,i)=>r0(e,t,r[i].clamp()),pD=(e,t,r,i,s)=>r0(e,t,pU(r,i[s])),pV=eE(([e,t,r])=>{let i=ry(e).toVar(),s=tV(eF(.5).mul(t.sub(r)),sO).div(i).toVar(),n=tV(eF(-.5).mul(t.sub(r)),sO).div(i).toVar(),a=ek().toVar();a.x=i.x.greaterThan(eF(0)).select(s.x,n.x),a.y=i.y.greaterThan(eF(0)).select(s.y,n.y),a.z=i.z.greaterThan(eF(0)).select(s.z,n.z);let o=rO(rO(a.x,a.y),a.z).toVar();return sO.add(i.mul(o)).toVar().sub(r)}),pO=eE(([e,t])=>{let r=e.x,i=e.y,s=e.z,n=t.element(0).mul(.886227);return(n=(n=(n=(n=(n=(n=(n=n.add(t.element(1).mul(1.023328).mul(i))).add(t.element(2).mul(1.023328).mul(s))).add(t.element(3).mul(1.023328).mul(r))).add(t.element(4).mul(.858086).mul(r).mul(i))).add(t.element(5).mul(.858086).mul(i).mul(s))).add(t.element(6).mul(s.mul(s).mul(.743125).sub(.247708)))).add(t.element(7).mul(.858086).mul(r).mul(s))).add(t.element(8).mul(.429043).mul(tO(r,r).sub(tO(i,i))))});var pG=Object.freeze({__proto__:null,BRDF_GGX:oZ,BRDF_Lambert:oD,BasicPointShadowFilter:ck,BasicShadowFilter:cN,Break:aB,Const:id,Continue:()=>ij("continue").toStack(),DFGApprox:oJ,D_GGX:oQ,Discard:iX,EPSILON:rt,F_Schlick:oI,Fn:eE,INFINITY:rr,If:eM,Loop:aM,NodeAccess:C,NodeShaderStage:E,NodeType:{BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},NodeUpdateType:w,PCFShadowFilter:cR,PCFSoftShadowFilter:cA,PI:ri,PI2:rs,PointShadowFilter:cz,Return:()=>ij("return").toStack(),Schlick_to_F0:o1,ScriptableNodeResources:hY,ShaderNode:eT,Stack:eB,Switch:(...e)=>X.Switch(...e),TBNViewMatrix:nv,VSMShadowFilter:cE,V_GGX_SmithCorrelated:oj,Var:iu,abs:rR,acesFilmicToneMapping:hI,acos:rS,add:tD,addMethodChaining:Y,addNodeElement:function(e){console.warn("THREE.TSL: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)},agxToneMapping:hG,all:rn,alphaT:ts,and:tX,anisotropy:tn,anisotropyB:to,anisotropyT:ta,any:ra,append:e=>(console.warn("THREE.TSL: append() has been renamed to Stack()."),eB(e)),array:tM,arrayBuffer:e=>e_(new q(e,"ArrayBuffer")),asin:rv,assign:tP,atan:rN,atan2:r7,atomicAdd:(e,t)=>cd(cl.ATOMIC_ADD,e,t),atomicAnd:(e,t)=>cd(cl.ATOMIC_AND,e,t),atomicFunc:cd,atomicLoad:e=>cd(cl.ATOMIC_LOAD,e,null),atomicMax:(e,t)=>cd(cl.ATOMIC_MAX,e,t),atomicMin:(e,t)=>cd(cl.ATOMIC_MIN,e,t),atomicOr:(e,t)=>cd(cl.ATOMIC_OR,e,t),atomicStore:(e,t)=>cd(cl.ATOMIC_STORE,e,t),atomicSub:(e,t)=>cd(cl.ATOMIC_SUB,e,t),atomicXor:(e,t)=>cd(cl.ATOMIC_XOR,e,t),attenuationColor:tb,attenuationDistance:tx,attribute:i0,attributeArray:(e,t="float")=>{let r,i;return!0===t.isStruct?(r=t.layout.getLength(),i=T("float")):(r=_(t),i=T(t)),aR(new d4(e,r,i),t,e)},backgroundBlurriness:he,backgroundIntensity:ht,backgroundRotation:hr,batch:a_,billboarding:dR,bitAnd:tZ,bitNot:tJ,bitOr:t0,bitXor:t1,bitangentGeometry:nf,bitangentLocal:ny,bitangentView:nx,bitangentWorld:nb,bitcast:rD,blendBurn:hg,blendColor:hx,blendDodge:hm,blendOverlay:hy,blendScreen:hf,blur:l$,bool:eI,buffer:se,bufferAttribute:iF,bumpMap:nB,burn:(...e)=>(console.warn('THREE.TSL: "burn" has been renamed. Use "blendBurn" instead.'),hg(e)),bvec2:eG,bvec3:eW,bvec4:eX,bypass:iz,cache:iG,call:tL,cameraFar:sl,cameraIndex:sa,cameraNear:so,cameraNormalMatrix:sp,cameraPosition:sg,cameraProjectionMatrix:su,cameraProjectionMatrixInverse:sd,cameraViewMatrix:sh,cameraWorldMatrix:sc,cbrt:rZ,cdl:hN,ceil:rf,checker:cJ,cineonToneMapping:hL,clamp:r1,clearcoat:e5,clearcoatRoughness:e9,code:h$,color:eP,colorSpaceToWorking:iN,colorToDirection:e=>e_(e).mul(2).sub(1),compute:iV,computeSkinning:(e,t=null)=>{let r=new aE(e);return r.positionNode=aR(new u.uWO(e.geometry.getAttribute("position").array,3),"vec3").setPBO(!0).toReadOnly().element(ah).toVar(),r.skinIndexNode=aR(new u.uWO(new Uint32Array(e.geometry.getAttribute("skinIndex").array),4),"uvec4").setPBO(!0).toReadOnly().element(ah).toVar(),r.skinWeightNode=aR(new u.uWO(e.geometry.getAttribute("skinWeight").array,4),"vec4").setPBO(!0).toReadOnly().element
5(ah).toVar(),r.bindMatrixNode=tw(e.bindMatrix,"mat4"),r.bindMatrixInverseNode=tw(e.bindMatrixInverse,"mat4"),r.boneMatricesNode=se(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length),r.toPositionNode=t,e_(r)},cond:ir,context:is,convert:eJ,convertColorSpace:(e,t,r)=>e_(new iT(e_(e),t,r)),convertToTexture:(e,...t)=>e.isTextureNode?e:e.isPassNode?e.getTextureNode():dJ(e,...t),cos:rT,cross:rq,cubeTexture:nr,cubeToUV:cG,dFdx:rM,dFdy:rB,dashSize:tc,debug:iZ,decrement:t5,decrementBefore:t6,defaultBuildStages:B,defaultShaderStages:M,defined:ex,degrees:rl,deltaTime:d_,densityFog:function(e,t){return console.warn('THREE.TSL: "densityFog( color, density )" is deprecated. Use "fog( color, densityFogFactor( density ) )" instead.'),h2(e,h1(t))},densityFogFactor:h1,depth:or,depthPass:(e,t,r)=>e_(new hM(hM.DEPTH,e,t,r)),difference:rW,diffuseColor:e3,directPointLight:cK,directionToColor:ob,dispersion:tT,distance:r$,div:tG,dodge:(...e)=>(console.warn('THREE.TSL: "dodge" has been renamed. Use "blendDodge" instead.'),hm(e)),dot:rH,drawIndex:am,dynamicBufferAttribute:iL,element:eZ,emissive:e4,equal:tz,equals:rV,equirectUV:oS,exp:ru,exp2:rd,expression:ij,faceDirection:sH,faceForward:r6,faceforward:r6,float:eF,floor:rm,fog:h2,fract:rx,frameGroup:tN,frameId:dv,frontFacing:sW,fwidth:rU,gain:(e,t)=>e.lessThan(.5)?dp(e.mul(2),t).div(2):tV(1,dp(tO(tV(1,e),2),t).div(2)),gapSize:tp,getConstNodeType:eb,getCurrentStack:eC,getDirection:lO,getDistanceAttenuation:cY,getGeometryRoughness:oH,getNormalFromDepth:d2,getParallaxCorrectNormal:pV,getRoughness:oq,getScreenPosition:d1,getShIrradianceAt:pO,getShadowMaterial:cC,getShadowRenderObjectFunction:cP,getTextureIndex:du,getViewPosition:d0,globalId:ct,glsl:(e,t)=>h$(e,t,"glsl"),glslFn:(e,t)=>hH(e,t,"glsl"),grayscale:hb,greaterThan:tH,greaterThanEqual:tj,hash:dc,highpModelNormalViewMatrix:sU,highpModelViewMatrix:sL,hue:hv,increment:t8,incrementBefore:t4,instance:ay,instanceIndex:ah,instancedArray:(e,t="float")=>{let r,i;return!0===t.isStruct?(r=t.layout.getLength(),i=T("float")):(r=_(t),i=T(t)),aR(new d3(e,r,i),t,e)},instancedBufferAttribute:iU,instancedDynamicBufferAttribute:iI,instancedMesh:ab,int:eL,inverseSqrt:rg,inversesqrt:rg,invocationLocalIndex:ag,invocationSubgroupIndex:ap,ior:tm,iridescence:tt,iridescenceIOR:tr,iridescenceThickness:ti,ivec2:eV,ivec3:ez,ivec4:eq,js:(e,t)=>h$(e,t,"js"),label:ia,length:rE,lengthSq:rJ,lessThan:tW,lessThanEqual:tq,lightPosition:cg,lightProjectionUV:cp,lightShadowMatrix:cc,lightTargetDirection:cy,lightTargetPosition:cm,lightViewPosition:cf,lightingContext:aG,lights:(e=[])=>e_(new cT).setLights(e),linearDepth:oi,linearToneMapping:hP,localId:cr,log:rh,log2:rc,logarithmicDepthToViewZ:(e,t,r)=>{let i=e.mul(rh(r.div(t)));return eF(Math.E).pow(i).mul(t).negate()},loop:(...e)=>(console.warn("THREE.TSL: loop() has been renamed to Loop()."),aM(...e)),luminance:hS,mat2:eQ,mat3:eY,mat4:eK,matcapUV:uy,materialAO:aa,materialAlphaTest:nL,materialAnisotropy:nJ,materialAnisotropyVector:ao,materialAttenuationColor:n5,materialAttenuationDistance:n8,materialClearcoat:nj,materialClearcoatNormal:nQ,materialClearcoatRoughness:nX,materialColor:nU,materialDispersion:as,materialEmissive:nD,materialEnvIntensity:s6,materialEnvRotation:s8,materialIOR:n6,materialIridescence:n0,materialIridescenceIOR:n1,materialIridescenceThickness:n2,materialLightMap:an,materialLineDashOffset:ar,materialLineDashSize:n7,materialLineGapSize:ae,materialLineScale:n9,materialLineWidth:at,materialMetalness:nH,materialNormal:nq,materialOpacity:nV,materialPointSize:ai,materialReference:nl,materialReflectivity:n$,materialRefractionRatio:s4,materialRotation:nY,materialRoughness:nW,materialSheen:nK,materialSheenRoughness:nZ,materialShininess:nI,materialSpecular:nO,materialSpecularColor:nk,materialSpecularIntensity:nG,materialSpecularStrength:nz,materialThickness:n4,materialTransmission:n3,max:rG,maxMipLevel:i6,mediumpModelViewMatrix:sF,metalness:e8,min:rO,mix:r0,mixElement:r5,mod:tk,modInt:t7,modelDirection:sN,modelNormalMatrix:sM,modelPosition:sA,modelRadius:sC,modelScale:sE,modelViewMatrix:sP,modelViewPosition:sw,modelViewProjection:al,modelWorldMatrix:sR,modelWorldMatrixInverse:sB,morphReference:aI,mrt:dh,mul:tO,mx_aastep:pU,mx_cell_noise_float:(e=i1())=>py(e.convert("vec2|vec3")),mx_contrast:(e,t=1,r=.5)=>eF(e).sub(r).mul(t).add(r),mx_fractal_noise_float:(e=i1(),t=3,r=2,i=.5,s=1)=>p_(e,eL(t),r,i).mul(s),mx_fractal_noise_vec2:(e=i1(),t=3,r=2,i=.5,s=1)=>pS(e,eL(t),r,i).mul(s),mx_fractal_noise_vec3:(e=i1(),t=3,r=2,i=.5,s=1)=>pv(e,eL(t),r,i).mul(s),mx_fractal_noise_vec4:(e=i1(),t=3,r=2,i=.5,s=1)=>pN(e,eL(t),r,i).mul(s),mx_hsvtorgb:pP,mx_noise_float:(e=i1(),t=1,r=0)=>pp(e.convert("vec2|vec3")).mul(t).add(r),mx_noise_vec3:(e=i1(),t=1,r=0)=>pg(e.convert("vec2|vec3")).mul(t).add(r),mx_noise_vec4:(e=i1(),t=1,r=0)=>eH(pg(e=e.convert("vec2|vec3")),pp(e.add(eD(19,73)))).mul(t).add(r),mx_ramplr:(e,t,r=i1())=>pI(e,t,r,"x"),mx_ramptb:(e,t,r=i1())=>pI(e,t,r,"y"),mx_rgbtohsv:pF,mx_safepower:(e,t=1)=>(e=eF(e)).abs().pow(t).mul(e.sign()),mx_splitlr:(e,t,r,i=i1())=>pD(e,t,r,i,"x"),mx_splittb:(e,t,r,i=i1())=>pD(e,t,r,i,"y"),mx_srgb_texture_to_lin_rec709:pL,mx_transform_uv:(e=1,t=0,r=i1())=>r.mul(e).add(t),mx_worley_noise_float:(e=i1(),t=1)=>pC(e.convert("vec2|vec3"),t,eL(1)),mx_worley_noise_vec2:(e=i1(),t=1)=>pM(e.convert("vec2|vec3"),t,eL(1)),mx_worley_noise_vec3:(e=i1(),t=1)=>pB(e.convert("vec2|vec3"),t,eL(1)),negate:rw,neutralToneMapping:hk,nodeArray:eS,nodeImmutable:eR,nodeObject:e_,nodeObjects:ev,nodeProxy:eN,normalFlat:sX,normalGeometry:sq,normalLocal:sj,normalMap:nE,normalView:sQ,normalWorld:sY,normalize:ry,not:tY,notEqual:t$,numWorkgroups:h7,objectDirection:sy,objectGroup:tA,objectPosition:sb,objectRadius:sv,objectScale:sT,objectViewPosition:s_,objectWorldMatrix:sx,oneMinus:rC,or:tQ,orthographicDepthToViewZ:(e,t,r)=>t.sub(r).mul(e).sub(t),oscSawtooth:(e=dT)=>
5e.fract(),oscSine:(e=dT)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),oscSquare:(e=dT)=>e.fract().round(),oscTriangle:(e=dT)=>e.add(.5).fract().mul(2).sub(1).abs(),output:th,outputStruct:dl,overlay:(...e)=>(console.warn('THREE.TSL: "overlay" has been renamed. Use "blendOverlay" instead.'),hy(e)),overloadingFn:db,parabola:dp,parallaxDirection:nS,parallaxUV:(e,t)=>e.sub(nS.mul(t)),parameter:(e,t)=>e_(new dt(e,t)),pass:(e,t,r)=>e_(new hM(hM.COLOR,e,t,r)),passTexture:(e,t)=>e_(new hw(e,t)),pcurve:(e,t,r)=>rj(tG(rj(e,t),tD(rj(e,t),rj(tV(1,e),r))),1/t),perspectiveDepthToViewZ:a7,pmremTexture:ui,pointShadow:cX,pointUV:d8,pointWidth:tg,positionGeometry:sI,positionLocal:sD,positionPrevious:sV,positionView:sk,positionViewDirection:sz,positionWorld:sO,positionWorldDirection:sG,posterize:hA,pow:rj,pow2:rX,pow3:rQ,pow4:rY,property:e1,radians:ro,rand:r8,range:h8,rangeFog:function(e,t,r){return console.warn('THREE.TSL: "rangeFog( color, near, far )" is deprecated. Use "fog( color, rangeFogFactor( near, far ) )" instead.'),h2(e,h0(t,r))},rangeFogFactor:h0,reciprocal:rF,reference:nn,referenceBuffer:na,reflect:rz,reflectVector:s7,reflectView:s5,reflector:e=>e_(new dH(e)),refract:r3,refractVector:ne,refractView:s9,reinhardToneMapping:hF,remainder:t9,remap:iW,remapClamp:iH,renderGroup:tR,renderOutput:iY,rendererReference:iw,rotate:u_,rotateUV:dS,roughness:e6,round:rP,rtt:dJ,sRGBTransferEOTF:im,sRGBTransferOETF:iy,sampler:e=>(!0===e.isNode?e:i5(e)).convert("sampler"),samplerComparison:e=>(!0===e.isNode?e:i5(e)).convert("samplerComparison"),saturate:r2,saturation:hT,screen:(...e)=>(console.warn('THREE.TSL: "screen" has been renamed. Use "blendScreen" instead.'),hf(e)),screenCoordinate:aH,screenSize:aW,screenUV:a$,scriptable:hZ,scriptableValue:hj,select:it,setCurrentStack:ew,shaderStages:P,shadow:cV,shadowPositionWorld:cv,shapeCircle:c0,sharedUniformGroup:tS,sheen:e7,sheenRoughness:te,shiftLeft:t2,shiftRight:t3,shininess:td,sign:rA,sin:rb,sinc:(e,t)=>rb(ri.mul(t.mul(e).sub(1))).div(ri.mul(t.mul(e).sub(1))),skinning:aw,smoothstep:r4,smoothstepElement:r9,specularColor:tl,specularF90:tu,spherizeUV:dN,split:(e,t)=>e_(new k(e_(e),t)),spritesheetUV:dw,sqrt:rp,stack:di,step:rk,storage:aR,storageBarrier:()=>cn("storage").toStack(),storageObject:(e,t,r)=>(console.warn('THREE.TSL: "storageObject()" is deprecated. Use "storage().setPBO( true )" instead.'),aR(e,t,r).setPBO(!0)),storageTexture:hs,string:(e="")=>e_(new q(e,"string")),struct:(e,t=null)=>{let r=new ds(e,t),i=(...t)=>{let i=null;if(t.length>0)if(t[0].isNode){i={};let r=Object.keys(e);for(let e=0;e<t.length;e++)i[r[e]]=t[e]}else i=t[0];return e_(new dn(r,i))};return i.layout=r,i.isStruct=!0,i},sub:tV,subgroupIndex:ac,subgroupSize:ci,tan:r_,tangentGeometry:nu,tangentLocal:nd,tangentView:nh,tangentWorld:nc,temp:ih,texture:i5,texture3D:ho,textureBarrier:()=>cn("texture").toStack(),textureBicubic:lu,textureCubeUV:lG,textureLoad:i9,textureSize:i3,textureStore:(e,t,r)=>{let i=hs(e,t,r);return null!==r&&i.toStack(),i},thickness:ty,time:dT,timerDelta:(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),d_.mul(e)),timerGlobal:(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),dT.mul(e)),timerLocal:(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),dT.mul(e)),toOutputColorSpace:i_,toWorkingColorSpace:iv,toneMapping:iM,toneMappingExposure:iB,toonOutlinePass:(e,t,r=new u.Q1f(0,0,0),i=.003,s=1)=>e_(new hB(e,t,e_(r),e_(i),e_(s))),transformDirection:rK,transformNormal:s0,transformNormalToView:s1,transformedBentNormalView:nN,transformedBitangentView:nT,transformedBitangentWorld:n_,transformedClearcoatNormalView:sJ,transformedNormalView:sK,transformedNormalWorld:sZ,transformedTangentView:np,transformedTangentWorld:ng,transmission:tf,transpose:rI,triNoise3D:df,triplanarTexture:(...e)=>dM(...e),triplanarTextures:dM,trunc:rL,tslFn:(...e)=>(console.warn("THREE.TSL: tslFn() has been renamed to Fn()."),eE(...e)),uint:eU,uniform:tw,uniformArray:si,uniformGroup:tv,uniforms:(e,t)=>(console.warn("THREE.TSL: uniforms() has been renamed to uniformArray()."),e_(new sr(e,t))),userData:(e,t,r)=>e_(new hl(e,t,r)),uv:i1,uvec2:eO,uvec3:e$,uvec4:ej,varying:ip,varyingProperty:e2,vec2:eD,vec3:ek,vec4:eH,vectorComponents:F,velocity:hp,vertexColor:od,vertexIndex:ad,vertexStage:ig,vibrance:h_,viewZToLogarithmicDepth:oe,viewZToOrthographicDepth:a5,viewZToPerspectiveDepth:a9,viewport:
5aq,viewportBottomLeft:aZ,viewportCoordinate:aX,viewportDepthTexture:a6,viewportLinearDepth:os,viewportMipTexture:a2,viewportResolution:aY,viewportSafeUV:dA,viewportSharedTexture:ox,viewportSize:aj,viewportTexture:a1,viewportTopLeft:aK,viewportUV:aQ,wgsl:(e,t)=>h$(e,t,"wgsl"),wgslFn:(e,t)=>hH(e,t,"wgsl"),workgroupArray:(e,t)=>e_(new co("Workgroup",e,t)),workgroupBarrier:()=>cn("workgroup").toStack(),workgroupId:ce,workingToColorSpace:iS,xor:tK});let pk=new de;class pz extends uU{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,r){let i=this.renderer,s=this.nodes.getBackgroundNode(e)||e.background,n=!1;if(null===s)i._clearColor.getRGB(pk),pk.a=i._clearColor.a;else if(!0===s.isColor)s.getRGB(pk),pk.a=1,n=!0;else if(!0===s.isNode){let r=this.get(e);pk.copy(i._clearColor);let n=r.backgroundMesh;if(void 0===n){let e=is(eH(s).mul(ht),{getUV:()=>hr.mul(sY),getTextureLevel:()=>he}),t=al;t=t.setZ(t.w);let i=new oh;i.name="Background.material",i.side=u.hsX,i.depthTest=!1,i.depthWrite=!1,i.allowOverride=!1,i.fog=!1,i.lights=!1,i.vertexNode=t,i.colorNode=e,r.backgroundMeshNode=e,r.backgroundMesh=n=new u.eaF(new u.Gu$(1,32,32),i),n.frustumCulled=!1,n.name="Background.mesh",n.onBeforeRender=function(e,t,r){this.matrixWorld.copyPosition(r.matrixWorld)},s.addEventListener("dispose",function e(){s.removeEventListener("dispose",e),n.material.dispose(),n.geometry.dispose()})}let a=s.getCacheKey();r.backgroundCacheKey!==a&&(r.backgroundMeshNode.node=eH(s).mul(ht),r.backgroundMeshNode.needsUpdate=!0,n.material.needsUpdate=!0,r.backgroundCacheKey=a),t.unshift(n,n.geometry,n.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",s);let a=i.xr.getEnvironmentBlendMode();if("additive"===a?pk.set(0,0,0,1):"alpha-blend"===a&&pk.set(0,0,0,0),!0===i.autoClear||!0===n){let e=r.clearColorValue;e.r=pk.r,e.g=pk.g,e.b=pk.b,e.a=pk.a,(!0===i.backend.isWebGLBackend||!0===i.alpha)&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),r.depthClearValue=i._clearDepth,r.stencilClearValue=i._clearStencil,r.clearColor=!0===i.autoClearColor,r.clearDepth=!0===i.autoClearDepth,r.clearStencil=!0===i.autoClearStencil}else r.clearColor=!1,r.clearDepth=!1,r.clearStencil=!1}}let p$=0;class pW{constructor(e="",t=[],r=0,i=[]){this.name=e,this.bindings=t,this.index=r,this.bindingsReference=i,this.id=p$++}}class pH{constructor(e,t,r,i,s,n,a,o,l,u=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=r,this.transforms=u,this.nodeAttributes=i,this.bindings=s,this.updateNodes=n,this.updateBeforeNodes=a,this.updateAfterNodes=o,this.observer=l,this.usedTimes=0}createBindings(){let e=[];for(let t of this.bindings)if(!0!==t.bindings[0].groupNode.shared){let r=new pW(t.name,[],t.index,t);for(let i of(e.push(r),t.bindings))r.bindings.push(i.clone())}else e.push(t);return e}}class pq{constructor(e,t,r=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=r}}class pj{constructor(e,t,r){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=r.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 pX{constructor(e,t,r=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=r,this.count=i}}class pQ extends pX{constructor(e,t,r=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=r,this.interpolationSampling=i}}class pY{constructor(e,t,r=""){this.name=e,this.type=t,this.code=r,Object.defineProperty(this,"isNodeCode",{value:!0})}}let pK=0;class pZ{constructor(e=null){this.id=pK++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class pJ{constructor(e,t){this.name=e,this.members=t,this.output=!1}}class p0{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 p1 extends p0{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class p2 extends p0{constructor(e,t=new u.I9Y){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class p3 extends p0{constructor(e,t=new u.Pq0){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class p4 extends p0{constructor(e,t=new u.IUQ){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class p6 extends p0{constructor(e,t=new u.Q1f){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class p8 extends p0{constructor(e,t=new u.k_V){super(e,t),this.isMatrix2Uniform=!0,this.boundary=16,this.itemSize=4}}class p5 extends p0{constructor(e,t=new u.dwI){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class p9 extends p0{constructor(e,t=new u.kn4){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class p7 extends p1{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class ge extends p2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class gt extends p3{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class gr extends p4{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class gi extends p6{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class gs extends p8{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class gn extends p5{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class ga extends p9{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}let go=new WeakMap,gl=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),gu=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class gd{constructor(e,t,r){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=r,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=di(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new pZ,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null}getBindGroupsCache(){let e=go.get(this.renderer);return void 0===e&&(e=new uM,go.set(this.renderer,e)),e}createRenderTarget(e,t,r){return new u.O0B(e,t,r)}createRenderTargetArray(e,t,r,i){return new u.rrX(e,t,r,i)}createCubeRenderTarget(e,t){return new oN(e,t)}includes(e){return this.nodes.includes(e)}getOutputStructName(){}_getBindGroup(e,t){let r,i=this.getBindGroupsCache(),s=[],n=!0;for(let e of t)s.push(e),n=n&&!0!==e.groupNode.shared;return n?void 0===(r=i.get(s))&&(r=new pW(e,s,this.bindingsIndexes[e].group,s),i.set(s,r)):r=new pW(e,s,this.bindingsIndexes[e].group,s),r}getBindGroupArray(e,t){let r=this.bindings[t],i=r[e];return void 0===i&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),r[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(null===e){let t={},r=this.bindings;for(let e of P)for(let i in r[e]){let s=r[e][i];(t[i]||(t[i]=[])).push(...s)}for(let r in e=[],t){let i=t[r],s=this._getBindGroup(r,i);e.push(s)}this.bindGroups=e}return e}sortBindingGroups(){let e=this.getBindings();e.sort((e,t)=>
5e.bindings[0].groupNode.order-t.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){let r=e[t];this.bindingsIndexes[r.name].group=t,r.index=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){!1===this.nodes.includes(e)&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){!1===this.sequentialNodes.includes(e)&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(let e of this.nodes)e.getUpdateType()!==w.NONE&&this.updateNodes.push(e.getSelf());for(let e of this.sequentialNodes){let t=e.getUpdateBeforeType(),r=e.getUpdateAfterType();t!==w.NONE&&this.updateBeforeNodes.push(e.getSelf()),r!==w.NONE&&this.updateAfterNodes.push(e.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===u.k6q||e.magFilter===u.kRr||e.magFilter===u.Cfg||e.magFilter===u.$_I||e.minFilter===u.k6q||e.minFilter===u.kRr||e.minFilter===u.Cfg||e.minFilter===u.$_I}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw 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){let r=this.getDataFromNode(e);return void 0===r.cache&&(r.cache=new pZ(t?this.getCache():null)),r.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){let t=this.getDataFromNode(e);return t.usageCount=void 0===t.usageCount?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,r=null){let i=this.generateArrayDeclaration(e,t)+"( ";for(let s=0;s<t;s++){let n=r?r[s]:null;null!==n?i+=n.build(this,e):i+=this.generateConst(e),s<t-1&&(i+=", ")}return i+" )"}generateStruct(e,t,r=null){let i=[];for(let e of t){let{name:t,type:s}=e;r&&r[t]&&r[t].isNode?i.push(r[t].build(this,s)):i.push(this.generateConst(s))}return e+"( "+i.join(", ")+" )"}generateConst(e,t=null){if(null===t&&("float"===e||"int"===e||"uint"===e?t=0:"bool"===e?t=!1:"color"===e?t=new u.Q1f:"vec2"===e?t=new u.I9Y:"vec3"===e?t=new u.Pq0:"vec4"===e&&(t=new u.IUQ)),"float"===e)return gu(t);if("int"===e)return`${Math.round(t)}`;if("uint"===e)return t>=0?`${Math.round(t)}u`:"0u";if("bool"===e)return t?"true":"false";if("color"===e)return`${this.getType("vec3")}( ${gu(t.r)}, ${gu(t.g)}, ${gu(t.b)} )`;let r=this.getTypeLength(e),i=this.getComponentType(e),s=e=>this.generateConst(i,e);if(2===r)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)} )`;if(3===r)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)} )`;if(4===r&&"mat2"!==e)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)}, ${s(t.w)} )`;if(r>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(s).join(", ")} )`;if(r>4)return`${this.getType(e)}()`;throw Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){let r=this.attributes;for(let t of r)if(t.name===e)return t;let i=new pq(e,t);return this.registerDeclaration(i),r.push(i),i}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"samplerComparison"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){let t=e.type;if(e.isDataTexture){if(t===u.Yuy)return"int";if(t===u.bkx)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;let t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;let r=x.get(e),i="float"===t?"":t[0];return!0===/mat2/.test(t)&&(r=r.replace("vec","mat")),i+r}getTypeFromArray(e){return gl.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t,r=e;e.isInterleavedBufferAttribute&&(r=e.data);let i=r.array,s=e.itemSize,n=e.normalized;return e instanceof u.Oax||!0===n||(t=this.getTypeFromArray(i)),this.getTypeFromLength(s,t)}getTypeLength(e){let t=this.getVectorType(e),r=/vec([2-4])/.exec(t);return null!==r?Number(r[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:16*(!0===/mat4/.test(e))}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){let t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=di(this.stack),this.stacks.push(eC()||this.stack),ew(this.stack),this.stack}removeStack(){let e=this.stack;return this.stack=e.parent,ew(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,r=null){let i=(r=null===r?e.isGlobal(this)?this.globalCache:this.cache:r).getData(e);return void 0===i&&(i={},r.setData(e,i)),void 0===i[t]&&(i[t]={}),i[t]}getNodeProperties(e,t="any"){let r=this.getDataFromNode(e,t);return r.properties||(r.properties={outputNode:null})}getBufferAttributeFromNode(e,t){let r=this.getDataFromNode(e),i=r.bufferAttribute;return void 0===i&&(i=new pq("nodeAttribute"+this.uniforms.index++,t,e),this.bufferAttributes.push(i),r.bufferAttribute=i),i}getStructTypeFromNode(e,t,r=null,i=this.shaderStage){let s=this.getDataFromNode(e,i,this.globalCache),n=s.structType;if(void 0===n){let e=this.structs.index++;null===r&&(r="StructType"+e),n=new pJ(r,t),this.structs[i].push(n),s.structType=n}return n}getOutputStructTypeFromNode(e,t){let r=this.getStructTypeFromNode(e,t,"OutputType","fragment");return r.output=!0,r}getUniformFromNode(e,t,r=this.shaderStage,i=null){let s=this.getDataFromNode(e,r,this.globalCache),n=s.uniform;if(void 0===n){let a=this.uniforms.index++;n=new pj(i||"nodeUniform"+a,t,e),this.uniforms[r].push(n),this.registerDeclaration(n),s.uniform=n}return n}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,r=e.getNodeType(this),i=this.shaderStage,s=!1){let n=this.getDataFromNode(e,i),a=n.variable;if(void 0===a){let o=s?"_const":"_var",l=this.vars[i]||(this.vars[i]=[]),u=this.vars[o]||(this.vars[o]=0);null===t&&(t=(s?"nodeConst":"nodeVar")+u,this.vars[o]++);let d=this.getArrayCount(e);a=new pX(t,r,s,d),s||l.push(a),this.registerDeclaration(a),n.variable=a}return a}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(!e.bNode||this.isDeterministic(e.bNode))&&(!e.cNode||this.isDeterministic(e.cNode));if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(!e.bNode||this.isDeterministic(e.bNode));if(e.isArrayNode){if(null!==e.values){for(let t of e.values)if(!this.isDeterministic(t))return!1}return!0}return!!e.isConstNode||!1}getVaryingFromNode(e,t=null,r=e.getNodeType(this),i=null,s=null){let n=this.getDataFromNode(e,"any"),a=n.varying;if(void 0===a){let e=this.varyings,o=e.length;null===t&&(t="nodeVarying"+o),a=new pQ(t,r,i,s),e.push(a),this.registerDeclaration(a),n.varying=a}return a}registerDeclaration(e){let t=this.shaderStage,r=this.declarations[t]||(this.declarations[t]={}),i=this.getPropertyName(e),s=1,n=i;for(;void 0!==r[n];)n=i+"_"+s++;s>1&&(e.name=n,console.warn(`THREE.TSL: Declaration name '${i}' of '${e.type}' already in use. Renamed to '${n}'.`)),r[n]=e}getCodeFromNode(e,t,r=this.shaderStage){let i=this.getDataFromNode(e),s=i.code;if(void 0===s){let e=this.codes[r]||(this.codes[r]=[]);s=new pY("nodeCode"+e.length,t),e.push(s),i.code=s}return s}addFlowCodeHierarchy(e,t){let{flowCodes:r,flowCodeBlock:i}=this.getDataFromNode(e),s=!0,n=t;for(;n;){if(!0===i.get(n)){s=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(s)for(let e of r)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,r){let i=this.getDataFromNode(e),s=i.flowCodes||(i.flowCodes=[]),n=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(t),n.set(r,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),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){let t=e.getNodeType(this),r=this.flowChildNode(e,t);return this.flowsData.set(e,r),r}addInclude(e){null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){let t=new hW,r=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=r,t}flowShaderNode(e){let t=e.layout,r={[Symbol.iterator](){let e=0,t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};
5for(let e of t.inputs)r[e.name]=new dt(e.type,e.name);e.layout=null;let i=e.call(r),s=this.flowStagesNode(i,t.type);return e.layout=t,s}flowStagesNode(e,t=null){let r=this.flow,i=this.vars,s=this.declarations,n=this.cache,a=this.buildStage,o=this.stack,l={code:""};for(let r of(this.flow=l,this.vars={},this.declarations={},this.cache=new pZ,this.stack=di(),B))this.setBuildStage(r),l.result=e.build(this,t);return l.vars=this.getVars(this.shaderStage),this.flow=r,this.vars=i,this.declarations=s,this.cache=n,this.stack=o,this.setBuildStage(a),l}getFunctionOperator(){return null}buildFunctionCode(){console.warn("Abstract function.")}flowChildNode(e,t=null){let r=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=r,i}flowNodeFromShaderStage(e,t,r=null,i=null){let s=this.shaderStage;this.setShaderStage(e);let n=this.flowChildNode(t,r);return null!==i&&(n.code+=`${this.tab+i} = ${n.result}; 6`),this.flowCode[e]=this.flowCode[e]+n.code,this.setShaderStage(s),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t,r=null){return`${null!==r?this.generateArrayDeclaration(e,r):this.getType(e)} ${t}`}getVars(e){let t="",r=this.vars[e];if(void 0!==r)for(let e of r)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){let t=this.codes[e],r="";if(void 0!==t)for(let e of t)r+=e.code+"\n";return r}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){let{object:e,material:t,renderer:r}=this;if(null!==t){let e=r.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new oh),e.build(this)}else this.addFlow("compute",e);for(let e of B)for(let t of(this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex),P))for(let r of(this.setShaderStage(t),this.flowNodes[t]))"generate"===e?this.flowNode(r):r.build(this);return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new p7(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new ge(e);
6if("vec3"===t||"ivec3"===t||"uvec3"===t)return new gt(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new gr(e);if("color"===t)return new gi(e);if("mat2"===t)return new gs(e);if("mat3"===t)return new gn(e);if("mat4"===t)return new ga(e);throw Error(`Uniform "${t}" not declared.`)}format(e,t,r){if(t=this.getVectorType(t),r=this.getVectorType(r),t===r||null===r||this.isReference(r))return e;let i=this.getTypeLength(t),s=this.getTypeLength(r);return 16===i&&9===s?`${this.getType(r)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:9===i&&4===s?`${this.getType(r)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:i>4||s>4||0===s?e:i===s?`${this.getType(r)}( ${e} )`:i>s?(e="bool"===r?`all( ${e} )`:`${e}.${"xyz".slice(0,s)}`,this.format(e,this.getTypeFromLength(s,this.getComponentType(t)),r)):4===s&&i>1?`${this.getType(r)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===i?`${this.getType(r)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===i&&s>1&&t!==this.getComponentType(r)&&(e=`${this.getType(this.getComponentType(r))}( ${e} )`),`${this.getType(r)}( ${e} )`)}getSignature(){return`// Three.js r${u.sPf} - Node System 7`}*[Symbol.iterator](){}createNodeMaterial(e="NodeMaterial"){throw Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}}class gh{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let r=e.get(t);return void 0===r&&(r={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,r)),r}updateBeforeNode(e){let t=e.getUpdateBeforeType(),r=e.updateReference(this);if(t===w.FRAME){let{frameMap:t}=this._getMaps(this.updateBeforeMap,r);t.get(r)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(r,this.frameId)}else if(t===w.RENDER){let{renderMap:t}=this._getMaps(this.updateBeforeMap,r);t.get(r)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(r,this.renderId)}else t===w.OBJECT&&e.updateBefore(this)}updateAfterNode(e){let t=e.getUpdateAfterType(),r=e.updateReference(this);if(t===w.FRAME){let{frameMap:t}=this._getMaps(this.updateAfterMap,r);t.get(r)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(r,this.frameId)}else if(t===w.RENDER){let{renderMap:t}=this._getMaps(this.updateAfterMap,r);t.get(r)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(r,this.renderId)}else t===w.OBJECT&&e.updateAfter(this)}updateNode(e){let t=e.getUpdateType(),r=e.updateReference(this);if(t===w.FRAME){let{frameMap:t}=this._getMaps(this.updateMap,r);t.get(r)!==this.frameId&&!1!==e.update(this)&&t.set(r,this.frameId)}else if(t===w.RENDER){let{renderMap:t}=this._getMaps(this.updateMap,r);t.get(r)!==this.renderId&&!1!==e.update(this)&&t.set(r,this.renderId)}else t===w.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class gc{constructor(e,t,r=null,i="",s=!1){this.type=e,this.name=t,this.count=r,this.qualifier=i,this.isConst=s}}gc.isNodeFunctionInput=!0;class gp extends cQ{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){let e=this.colorNode;return{lightDirection:cy(this.light),lightColor:e}}}let gg=new u.kn4,gm=new u.kn4,gf=null;class gy extends cQ{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=tw(new u.Pq0).setGroup(tR),this.halfWidth=tw(new u.Pq0).setGroup(tR),this.updateType=w.RENDER}update(e){super.update(e);let{light:t}=this,r=e.camera.matrixWorldInverse;gm.identity(),gg.copy(t.matrixWorld),gg.premultiply(r),gm.extractRotation(gg),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(gm),this.halfHeight.value.applyMatrix4(gm)}setupDirectRectArea(e){let t,r;e.isAvailable("float32Filterable")?(t=i5(gf.LTC_FLOAT_1),r=i5(gf.LTC_FLOAT_2)):(t=i5(gf.LTC_HALF_1),r=i5(gf.LTC_HALF_2));let{colorNode:i,light:s}=this;return{lightColor:i,lightPosition:cf(s),halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:r}}static setLTC(e){gf=e}}class gx extends cQ{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=tw(0).setGroup(tR),this.penumbraCosNode=tw(0).setGroup(tR),this.cutoffDistanceNode=tw(0).setGroup(tR),this.decayExponentNode=tw(0).setGroup(tR)}update(e){super.update(e);let{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}
7getSpotAttenuation(e){let{coneCosNode:t,penumbraCosNode:r}=this;return r4(t,r,e)}setupDirect(e){let{colorNode:t,cutoffDistanceNode:r,decayExponentNode:i,light:s}=this,n=this.getLightVector(e),a=n.normalize(),o=a.dot(cy(s)),l=this.getSpotAttenuation(o),u=cY({lightDistance:n.length(),cutoffDistance:r,decayExponent:i}),d=t.mul(l).mul(u);if(s.map){let t=cp(s,e.context.positionWorld),r=i5(s.map,t.xy).onRenderUpdate(()=>s.map);d=t.mul(2).sub(1).abs().lessThan(1).all().select(d.mul(r),d)}return{lightColor:d,lightDirection:a}}}class gb extends gx{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){let t=this.light.iesMap;return t&&!0===t.isTexture?i5(t,eD(e.acos().mul(1/Math.PI),0),0).r:super.getSpotAttenuation(e)}}class gT extends cQ{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class g_ extends cQ{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=cg(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=tw(new u.Q1f).setGroup(tR)}update(e){let{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){let{colorNode:t,groundColorNode:r,lightDirectionNode:i}=this,s=r0(r,t,sQ.dot(i).mul(.5).add(.5));e.context.irradiance.addAssign(s)}}class gv extends cQ{static get type(){return"LightProbeNode"}constructor(e=null){super(e);let t=[];for(let e=0;e<9;e++)t.push(new u.Pq0);this.lightProbe=si(t)}update(e){let{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){let t=pO(sY,this.lightProbe);e.context.irradiance.addAssign(t)}}class gS{parseFunction(){console.warn("Abstract function.")}}class gN{constructor(e,t,r="",i=""){this.type=e,this.inputs=t,this.name=r,this.precision=i}getCode(){console.warn("Abstract function.")}}gN.isNodeFunction=!0;let gR=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,gA=/[a-z_0-9]+/ig,gE="#pragma main";class gw extends gN{constructor(e){let{type:t,inputs:r,name:i,precision:s,inputsCode:n,blockCode:a,headerCode:o}=(e=>{let t=(e=e.trim()).indexOf(gE),r=-1!==t?e.slice(t+gE.length):e,i=r.match(gR);if(null!==i&&5===i.length){let s=i[4],n=[],a=null;for(;null!==(a=gA.exec(s));)n.push(a);let o=[],l=0;for(;l<n.length;){let e="const"===n[l][0];!0===e&&l++;let t=n[l][0];"in"===t||"out"===t||"inout"===t?l++:t="";let r=n[l++][0],i=Number.parseInt(n[l][0]);!1===Number.isNaN(i)?l++:i=null;let s=n[l++][0];o.push(new gc(r,s,i,t,e))}let u=r.substring(i[0].length),d=void 0!==i[3]?i[3]:"",h=i[2];return{type:h,inputs:o,name:d,precision:void 0!==i[1]?i[1]:"",inputsCode:s,blockCode:u,headerCode:-1!==t?e.slice(0,t):""}}throw Error("FunctionNode: Function is not a GLSL code.")})(e);super(t,r,i,s),this.inputsCode=n,this.blockCode=a,this.headerCode=o}getCode(e=this.name){let t,r=this.blockCode;if(""!==r){let{type:i,inputsCode:s,headerCode:n,precision:a}=this,o=`${i} ${e} ( ${s.trim()} )`;""!==a&&(o=`${a} ${o}`),t=n+o+r}else t="";return t}}class gC extends gS{parseFunction(e){return new gw(e)}}let gM=new WeakMap,gB=[],gP=[];class gF extends uU{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new gh,this.nodeBuilderCache=new Map,this.callHashCache=new uM,this.groupsData=new uM,this.cacheLib={}}updateGroup(e){let t=e.groupNode,r=t.name;if(r===tA.name)return!0;if(r===tR.name){let t=this.get(e),r=this.nodeFrame.renderId;return t.renderId!==r&&(t.renderId=r,!0)}if(r===tN.name){let t=this.get(e),r=this.nodeFrame.frameId;return t.frameId!==r&&(t.frameId=r,!0)}gB[0]=t,gB[1]=e;let i=this.groupsData.get(gB);return void 0===i&&this.groupsData.set(gB,i={}),gB.length=0,i.version!==t.version&&(i.version=t.version,!0)}getForRenderCacheKey(e){return e.initialCacheKey}getForRender(e){let t=this.get(e),r=t.nodeBuilderState;if(void 0===r){let{nodeBuilderCache:i}=this,s=this.getForRenderCacheKey(e);if(void 0===(r=i.get(s))){let t=this.backend.createNodeBuilder(e.object,this.renderer);t.scene=e.scene,t.material=e.material,t.camera=e.camera,t.context.material=e.material,t.lightsNode=e.lightsNode,t.environmentNode=this.getEnvironmentNode(e.scene),t.fogNode=this.getFogNode(e.scene),t.clippingContext=e.clippingContext,this.renderer.getRenderTarget()&&this.renderer.getRenderTarget().multiview&&t.enableMultiview(),t.build(),r=this._createNodeBuilderState(t),i.set(s,r)}r.usedTimes++,t.nodeBuilderState=r}return r}delete(e){if(e.isRenderObject){let t=this.get(e).nodeBuilderState;t.usedTimes--,0===t.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e))}return super.delete(e)}getForCompute(e){let t=this.get(e),r=t.nodeBuilderState;if(void 0===r){let i=this.backend.createNodeBuilder(e,this.renderer);i.build(),t.nodeBuilderState=r=this._createNodeBuilderState(i)}return r}_createNodeBuilderState(e){return new pH(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.transforms)}getEnvironmentNode(e){this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{let r=this.get(e);r.environmentNode&&(t=r.environmentNode)}return t}
7getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{let r=this.get(e);r.backgroundNode&&(t=r.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){gB[0]=e,gB[1]=t;let r=this.renderer.info.calls,i=this.callHashCache.get(gB)||{};if(i.callId!==r){let s=this.getEnvironmentNode(e),n=this.getFogNode(e);t&&gP.push(t.getCacheKey(!0)),s&&gP.push(s.getCacheKey()),n&&gP.push(n.getCacheKey()),gP.push(+!!this.renderer.shadowMap.enabled),i.callId=r,i.cacheKey=g(gP),this.callHashCache.set(gB,i),gP.length=0}return gB.length=0,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){let t=this.get(e),r=e.background;if(r){let i=0===e.backgroundBlurriness&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;(t.background!==r||i)&&(t.backgroundNode=this.getCacheNode("background",r,()=>{if(!0===r.isCubeTexture||r.mapping===u.wfO||r.mapping===u.uV5||r.mapping===u.Om)if(e.backgroundBlurriness>0||r.mapping===u.Om)return ui(r);else return oC(!0===r.isCubeTexture?nr(r):i5(r));if(!0===r.isTexture)return i5(r,a$.flipY()).setUpdateMatrix(!0);!0!==r.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",r)},i),t.background=r,t.backgroundBlurriness=e.backgroundBlurriness)}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,r,i=!1){let s=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap),n=s.get(t);return(void 0===n||i)&&(n=r(),s.set(t,n)),n}updateFog(e){let t=this.get(e),r=e.fog;r?t.fog!==r&&(t.fogNode=this.getCacheNode("fog",r,()=>{if(r.isFogExp2)return h2(nn("color","color",r).setGroup(tR),h1(nn("density","float",r).setGroup(tR)));if(r.isFog){let e=nn("color","color",r).setGroup(tR);return h2(e,h0(nn("near","float",r).setGroup(tR),nn("far","float",r).setGroup(tR)))}console.error("THREE.Renderer: Unsupported fog configuration.",r)}),t.fog=r):(delete t.fogNode,delete t.fog)}updateEnvironment(e){let t=this.get(e),r=e.environment;r?t.environment!==r&&(t.environmentNode=this.getCacheNode("environment",r,()=>!0===r.isCubeTexture?nr(r):!0===r.isTexture?i5(r):void console.error("Nodes: Unsupported environment configuration.",r)),t.environment=r):t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,r=null,i=null,s=null){let n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=r,n.camera=i,n.material=s,n}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){let e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}hasOutputChange(e){return gM.get(e)!==this.getOutputCacheKey()}getOutputNode(e){let t=this.renderer,r=this.getOutputCacheKey(),i=e.isTextureArray?ho(e,ek(a$,sn("gl_ViewID_OVR"))).renderOutput(t.toneMapping,t.currentColorSpace):i5(e,a$).renderOutput(t.toneMapping,t.currentColorSpace);return gM.set(e,r),i}updateBefore(e){for(let t of e.getNodeBuilderState().updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(t)}updateAfter(e){for(let t of e.getNodeBuilderState().updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(t)}updateForCompute(e){let t=this.getNodeFrame();for(let r of this.getForCompute(e).updateNodes)t.updateNode(r)}updateForRender(e){let t=this.getNodeFrameForRender(e);for(let r of e.getNodeBuilderState().updateNodes)t.updateNode(r)}needsRefresh(e){let t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new gh,this.nodeBuilderCache=new Map,this.cacheLib={}}}let gL=new u.Zcv;class gU{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewNormalMatrix=new u.dwI,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,null!==e&&(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix)}projectPlanes(e,t,r){let i=e.length;for(let s=0;s<i;s++){gL.copy(e[s]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);let i=t[r+s],n=gL.normal;i.x=-n.x,i.y=-n.y,i.z=-n.z,i.w=gL.constant}}updateGlobal(e,t){this.shadowPass=null!==e.overrideMaterial&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let r,i,s=!1;e.version!==this.parentVersion&&(this.intersectionPlanes=Array.from(e.intersectionPlanes),this.unionPlanes=Array.from(e.unionPlanes),this.parentVersion=e.version),this.clipIntersection!==t.clipIntersection&&(this.clipIntersection=t.clipIntersection,this.clipIntersection?this.unionPlanes.length=e.unionPlanes.length:this.intersectionPlanes.length=e.intersectionPlanes.length);let n=t.clippingPlanes,a=n.length;if(this.clipIntersection?(r=this.intersectionPlanes,i=e.intersectionPlanes.length):(r=this.unionPlanes,i=e.unionPlanes.length),r.length!==i+a){r.length=i+a;for(let e=0;e<a;e++)r[i+e]=new u.IUQ;s=!0}this.projectPlanes(n,r,i),s&&(this.version++,this.cacheKey=`${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}
7getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return void 0===t&&(t=new gU(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class gI{constructor(e,t){this.bundleGroup=e,this.camera=t}}let gD=[];class gV{constructor(){this.bundles=new uM}get(e,t){let r=this.bundles;gD[0]=e,gD[1]=t;let i=r.get(gD);return void 0===i&&(i=new gI(e,t),r.set(gD,i)),gD.length=0,i}dispose(){this.bundles=new uM}}class gO{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null,r=this.getMaterialNodeClass(e.type);if(null!==r)for(let i in t=new r,e)t[i]=e[i];return t}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,r){if(r.has(t))return void console.warn(`Redefinition of node ${t}`);if("function"!=typeof e)throw Error(`Node class ${e.name} is not a class.`);if("function"==typeof t||"object"==typeof t)throw Error(`Base class ${t} is not a class.`);r.set(t,e)}addClass(e,t,r){if(r.has(t))return void console.warn(`Redefinition of node ${t.name}`);if("function"!=typeof e)throw Error(`Node class ${e.name} is not a class.`);if("function"!=typeof t)throw Error(`Base class ${t.name} is not a class.`);r.set(t,e)}}let gG=new cT,gk=[];class gz extends uM{constructor(){super()}createNode(e=[]){return new cT().setLights(e)}getNode(e,t){if(e.isQuadMesh)return gG;gk[0]=e,gk[1]=t;let r=this.get(gk);return void 0===r&&(r=this.createNode(),this.set(gk,r)),gk.length=0,r}}class g$ extends u.O0B{constructor(e=1,t=1,r={}){super(e,t,r),this.isXRRenderTarget=!0,this.hasExternalTextures=!1,this.autoAllocateDepthBuffer=!0}copy(e){return super.copy(e),this.hasExternalTextures=e.hasExternalTextures,this.autoAllocateDepthBuffer=e.autoAllocateDepthBuffer,this}}let gW=new u.Pq0,gH=new u.Pq0;class gq extends u.Qev{constructor(e,t=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new u.ubm,this._cameraL.viewport=new u.IUQ,this._cameraR=new u.ubm,this._cameraR.viewport=new u.IUQ,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new u.nZQ,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._supportsLayers=!1,this._createXRLayer=gK.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSize=new u.I9Y,this._onSessionEvent=gX.bind(this),this._onSessionEnd=gQ.bind(this),this._onInputSourcesChange=gY.bind(this),this._onAnimationFrame=gZ.bind(this),this._referenceSpace=null,this._referenceSpaceType="local-floor",this._customReferenceSpace=null,this._framebufferScaleFactor=1,this._foveation=1,this._session=null,this._glBaseLayer=null,this._glBinding=null,this._glProjLayer=null,this._xrFrame=null,this._useLayers="undefined"!=typeof XRWebGLBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=t,this._useMultiview=!1}getController(e){return this._getController(e).getTargetRaySpace()}getControllerGrip(e){return this._getController(e).getGripSpace()}getHand(e){return this._getController(e).getHandSpace()}getFoveation(){if(null!==this._glProjLayer||null!==this._glBaseLayer)return this._foveation}setFoveation(e){this._foveation=e,null!==this._glProjLayer&&(this._glProjLayer.fixedFoveation=e),null!==this._glBaseLayer&&void 0!==this._glBaseLayer.fixedFoveation&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,!0===this.isPresenting&&console.warn("THREE.XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,!0===this.isPresenting&&console.warn("THREE.XRManager: Cannot change reference space type while presenting.")}getReferenceSpace(){return this._customReferenceSpace||this._referenceSpace}setReferenceSpace(e){this._customReferenceSpace=e}getCamera(){return this._cameraXR}getEnvironmentBlendMode(){if(null!==this._session)return this._session.environmentBlendMode}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,r,i,s,n,a,o=[]){let l=new u.bdM(e,t),d=new g$(s,n,{format:u.GWd,type:u.OUM,depthTexture:new u.VCu(s,n,o.stencil?u.V3x:u.bkx,void 0,void 0,void 0,void 0,void 0,void 0,o.stencil?u.dcC:u.zdS),stencilBuffer:o.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),h=new u.V9B({color:0xffffff,side:u.hB5});h.map=d.texture,h.map.offset.y=1,h.map.repeat.y=-1;let c=new u.eaF(l,h);c.position.copy(r),c.quaternion.copy(i);let p={type:"quad",width:e,height:t,translation:r,quaternion:i,pixelwidth:s,pixelheight:n,plane:c,material:h,rendercall:a,renderTarget:d};if(this._layers.push(p),null!==this._session){p.plane.material=new u.V9B({color:0xffffff,side:u.hB5}),p.plane.material.blending=u.bCz,p.plane.material.blendEquation=u.gO9,p.plane.material.blendSrc=u.ojh,p.plane.material.blendDst=u.ojh,p.xrlayer=this._createXRLayer(p);let e=this._session.renderState.layers;e.unshift(p.xrlayer),this._session.updateRenderState({layers:e})}else d.isXRRenderTarget=!1;return c}createCylinderLayer(e,t,r,i,s,n,a,o,l=[]){let d=new u.Ho_(e,e,e*t/r,64,64,!0,Math.PI-t/2,t),h=new g$(n,a,{format:u.GWd,type:u.OUM,depthTexture:new u.VCu(n,a,l.stencil?u.V3x:u.bkx,void 0,void 0,void 0,void 0,void 0,void 0,l.stencil?u.dcC:u.zdS),stencilBuffer:l.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),c=new u.V9B({color:0xffffff,side:u.hsX});c.map=h.texture,c.map.offset.y=1,c.map.repeat.y=-1;let p=new u.eaF(d,c);p.position.copy(i),p.quaternion.copy(s);
7let g={type:"cylinder",radius:e,centralAngle:t,aspectratio:r,translation:i,quaternion:s,pixelwidth:n,pixelheight:a,plane:p,material:c,rendercall:o,renderTarget:h};if(this._layers.push(g),null!==this._session){g.plane.material=new u.V9B({color:0xffffff,side:u.hsX}),g.plane.material.blending=u.bCz,g.plane.material.blendEquation=u.gO9,g.plane.material.blendSrc=u.ojh,g.plane.material.blendDst=u.ojh,g.xrlayer=this._createXRLayer(g);let e=this._session.renderState.layers;e.unshift(g.xrlayer),this._session.updateRenderState({layers:e})}else h.isXRRenderTarget=!1;return p}renderLayers(){let e=new u.Pq0,t=new u.PTz,r=this.isPresenting;for(let r of(this.isPresenting=!1,this._layers)){if(r.renderTarget.isXRRenderTarget=null!==this._session,r.renderTarget.hasExternalTextures=r.renderTarget.isXRRenderTarget,r.renderTarget.autoAllocateDepthBuffer=!r.renderTarget.isXRRenderTarget,r.renderTarget.isXRRenderTarget&&this._supportsLayers){r.xrlayer.transform=new XRRigidTransform(r.plane.getWorldPosition(e),r.plane.getWorldQuaternion(t));let i=this._glBinding.getSubImage(r.xrlayer,this._xrFrame);this._renderer.backend.setXRRenderTargetTextures(r.renderTarget,i.colorTexture,i.depthStencilTexture)}this._renderer.setRenderTarget(r.renderTarget),r.rendercall()}this.isPresenting=r,this._renderer.setRenderTarget(null)}getSession(){return this._session}async setSession(e){let t=this._renderer,r=t.backend;this._gl=t.getContext();let i=this._gl,s=i.getContextAttributes();if(this._session=e,null!==e){if(!0===r.isWebGPUBackend)throw Error('THREE.XRManager: XR is currently not supported with a WebGPU backend. Use WebGL by passing "{ forceWebGL: true }" to the constructor of the renderer.');if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),await r.makeXRCompatible(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),!0===this._useLayers){let r,n=null,a=null,o=null;t.depth&&(o=t.stencil?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24,n=t.stencil?u.dcC:u.zdS,a=t.stencil?u.V3x:u.bkx);let l={colorFormat:i.RGBA8,depthFormat:o,scaleFactor:this._framebufferScaleFactor};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(l.textureType="texture-array",this._useMultiview=!0);let d=new XRWebGLBinding(e,i),h=d.createProjectionLayer(l),c=[h];if(this._glBinding=d,this._glProjLayer=h,t.setPixelRatio(1),t.setSize(h.textureWidth,h.textureHeight,!1),this._useMultiview?((r=new u.S7T(h.textureWidth,h.textureHeight,2)).type=a,r.format=n):r=new u.VCu(h.textureWidth,h.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,n),this._xrRenderTarget=new g$(h.textureWidth,h.textureHeight,{format:u.GWd,type:u.OUM,colorSpace:t.outputColorSpace,depthTexture:r,stencilBuffer:t.stencil,samples:4*!!s.antialias,resolveDepthBuffer:!1===h.ignoreDepthValues,resolveStencilBuffer:!1===h.ignoreDepthValues,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget.hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._supportsLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._supportsLayers)for(let e of this._layers)e.plane.material=new u.V9B({color:0xffffff,side:"cylinder"===e.type?u.hsX:u.hB5}),e.plane.material.blending=u.bCz,e.plane.material.blendEquation=u.gO9,e.plane.material.blendSrc=u.ojh,e.plane.material.blendDst=u.ojh,e.xrlayer=this._createXRLayer(e),c.unshift(e.xrlayer);e.updateRenderState({layers:c})}else{let r=new XRWebGLLayer(e,i,{antialias:t.samples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()});this._glBaseLayer=r,e.updateRenderState({baseLayer:r}),t.setPixelRatio(1),t.setSize(r.framebufferWidth,r.framebufferHeight,!1),this._xrRenderTarget=new g$(r.framebufferWidth,r.framebufferHeight,{format:u.GWd,type:u.OUM,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:!1===r.ignoreDepthValues,resolveStencilBuffer:!1===r.ignoreDepthValues}),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}this.setFoveation(this.getFoveation()),t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){var t,r,i;let s=this._session;if(null===s)return;let n=e.near,a=e.far,o=this._cameraXR,l=this._cameraL,d=this._cameraR;o.near=d.near=l.near=n,o.far=d.far=l.far=a,o.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==o.near||this._currentDepthFar!==o.far)&&(s.updateRenderState({depthNear:o.near,depthFar:o.far}),this._currentDepthNear=o.near,this._currentDepthFar=o.far),l.layers.mask=2|e.layers.mask,d.layers.mask=4|e.layers.mask,o.layers.mask=l.layers.mask|d.layers.mask;let h=e.parent,c=o.cameras;gj(o,h);for(let e=0;e<c.length;e++)gj(c[e],h);2===c.length?function(e,t,r){gW.setFromMatrixPosition(t.matrixWorld),gH.setFromMatrixPosition(r.matrixWorld);let i=gW.distanceTo(gH),s=t.projectionMatrix.elements,n=r.projectionMatrix.elements,a=s[14]/(s[10]-1),o=s[14]/(s[10]+1),l=(s[9]+1)/s[5],u=(s[9]-1)/s[5],d=(s[8]-1)/s[0],h=(n[8]+1)/n[0],c=i/(-d+h),p=-(c*d);if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(p),e.translateZ(c),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),-1===s[10])e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=a+c,r=o+c;e.projectionMatrix.makePerspective(a*d-p,a*h+(i-p),l*o/r*t,u*o/r*t,t,r),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}(o,l,d):o.projectionMatrix.copy(l.projectionMatrix),t=e,r=o,null===(i=h)?t.matrix.copy(r.matrixWorld):(t.matrix.copy(i.matrixWorld),t.matrix.invert(),t.matrix.multiply(r.matrixWorld)),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),t.projectionMatrix.copy(r.projectionMatrix),t.projectionMatrixInverse.copy(r.projectionMatrixInverse),t.isPerspectiveCamera&&(t.fov=2*u.a55*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}_getController(e){let t=this._controllers[e];return void 0===t&&(t=new u.R3r,this._controllers[e]=t),t}}function gj(e,t){null===t?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}function gX(e){let t=this._controllerInputSources.indexOf(e.inputSource);if(-1===t)return;let r=this._controllers[t];if(void 0!==r){let t=this.getReferenceSpace();r.update(e.inputSource,e.frame,t),r.dispatchEvent({type:e.type,data:e.inputSource})}}function gQ(){let e=this._session,t=this._renderer;e.removeEventListener("select",this._onSessionEvent),e.removeEventListener("selectstart",this._onSessionEvent),e.removeEventListener("selectend",this._onSessionEvent),e.removeEventListener("squeeze",this._onSessionEvent),e.removeEventListener("squeezestart",this._onSessionEvent),e.removeEventListener("squeezeend",this._onSessionEvent),e.removeEventListener("end",this._onSessionEnd),e.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let e=0;e<this._controllers.length;e++){let t=this._controllerInputSources[e];null!==t&&(this._controllerInputSources[e]=null,this._controllers[e].disconnect(t))}if(this._currentDepthNear=null,this._currentDepthFar=null,t.backend.setXRTarget(null),t.setOutputRe
7nderTarget(null),t.setRenderTarget(null),this._session=null,this._xrRenderTarget=null,!0===this._supportsLayers)for(let e of this._layers)e.renderTarget=new g$(e.pixelwidth,e.pixelheight,{format:u.GWd,type:u.OUM,depthTexture:new u.VCu(e.pixelwidth,e.pixelheight,e.stencilBuffer?u.V3x:u.bkx,void 0,void 0,void 0,void 0,void 0,void 0,e.stencilBuffer?u.dcC:u.zdS),stencilBuffer:e.stencilBuffer,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),e.renderTarget.isXRRenderTarget=!1,e.plane.material=e.material,e.material.map=e.renderTarget.texture,delete e.xrlayer;this.isPresenting=!1,this._useMultiview=!1,t._animation.stop(),t._animation.setAnimationLoop(this._currentAnimationLoop),t._animation.setContext(this._currentAnimationContext),t._animation.start(),t.setPixelRatio(this._currentPixelRatio),t.setSize(this._currentSize.width,this._currentSize.height,!1),this.dispatchEvent({type:"sessionend"})}function gY(e){let t=this._controllers,r=this._controllerInputSources;for(let i=0;i<e.removed.length;i++){let s=e.removed[i],n=r.indexOf(s);n>=0&&(r[n]=null,t[n].disconnect(s))}for(let i=0;i<e.added.length;i++){let s=e.added[i],n=r.indexOf(s);if(-1===n){for(let e=0;e<t.length;e++)if(e>=r.length){r.push(s),n=e;break}else if(null===r[e]){r[e]=s,n=e;break}if(-1===n)break}let a=t[n];a&&a.connect(s)}}function gK(e){return"quad"===e.type?this._glBinding.createQuadLayer({transform:new XRRigidTransform(e.translation,e.quaternion),depthFormat:this._gl.DEPTH_COMPONENT,width:e.width/2,height:e.height/2,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(e.translation,e.quaternion),depthFormat:this._gl.DEPTH_COMPONENT,radius:e.radius,centralAngle:e.centralAngle,aspectRatio:e.aspectRatio,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight})}function gZ(e,t){if(void 0===t)return;let r=this._cameraXR,i=this._renderer,s=i.backend,n=this._glBaseLayer,a=this.getReferenceSpace(),o=t.getViewerPose(a);if(this._xrFrame=t,null!==o){let e=o.views;null!==this._glBaseLayer&&s.setXRTarget(n.framebuffer);let t=!1;e.length!==r.cameras.length&&(r.cameras.length=0,t=!0);for(let i=0;i<e.length;i++){let a,o=e[i];if(!0===this._useLayers){let e=this._glBinding.getViewSubImage(this._glProjLayer,o);a=e.viewport,0===i&&s.setXRRenderTargetTextures(this._xrRenderTarget,e.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:e.depthStencilTexture)}else a=n.getViewport(o);let l=this._cameras[i];void 0===l&&((l=new u.ubm).layers.enable(i),l.viewport=new u.IUQ,this._cameras[i]=l),l.matrix.fromArray(o.transform.matrix),l.matrix.decompose(l.position,l.quaternion,l.scale),l.projectionMatrix.fromArray(o.projectionMatrix),l.projectionMatrixInverse.copy(l.projectionMatrix).invert(),l.viewport.set(a.x,a.y,a.width,a.height),0===i&&(r.matrix.copy(l.matrix),r.matrix.decompose(r.position,r.quaternion,r.scale)),!0===t&&r.cameras.push(l)}i.setOutputRenderTarget(this._xrRenderTarget)}for(let e=0;e<this._controllers.length;e++){let r=this._controllerInputSources[e],i=this._controllers[e];null!==r&&void 0!==i&&i.update(r,t,a)}this._currentAnimationLoop&&this._currentAnimationLoop(e,t),t.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:t}),this._xrFrame=null}let gJ=new u.Z58,g0=new u.I9Y,g1=new u.IUQ,g2=new u.PPD,g3=new u.uf3,g4=new u.kn4,g6=new u.IUQ;class g8{constructor(e,t={}){this.isRenderer=!0;let{logarithmicDepthBuffer:r=!1,alpha:i=!0,depth:s=!0,stencil:n=!1,antialias:a=!1,samples:o=0,getFallback:l=null,colorBufferType:d=u.ix0,multiview:h=!1}=t;this.domElement=e.getDomElement(),this.backend=e,this.samples=o||!0===a?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=r,this.outputColorSpace=u.er$,this.toneMapping=u.y_p,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=s,this.stencil=n,this.info=new uk,this.overrideNodes={modelViewMatrix:null,modelNormalViewMatrix:null},this.library=new gO,this.lighting=new gz,this._getFallback=l,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new u.IUQ(0,0,this._width,this._height),this._scissor=new u.IUQ(0,0,this._width,this._height),this._scissorTest=!1,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quad=new dY(new oh),this._quad.material.name="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;
7let c=+(!0!==this.alpha);this._clearColor=new de(0,0,0,c),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._outputRenderTarget=null,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this._colorBufferType=d,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,type:u.QP0},this.xr=new gq(this,h),this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(e,t,r)=>{await this.compileAsync(e,t);let i=this._renderLists.get(e,t),s=this._renderContexts.get(e,t,this._renderTarget),n=e.overrideMaterial||r.material,{fragmentShader:a,vertexShader:o}=this._objects.get(r,n,e,t,i.lightsNode,s,s.clippingContext).getNodeBuilderState();return{fragmentShader:a,vertexShader:o}}}}async init(){if(this._initialized)throw Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise(async(e,t)=>{let r=this.backend;try{await r.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=r=this._getFallback(e),await r.init(this)}catch(e){t(e);return}}this._nodes=new gF(this,r),this._animation=new uC(this._nodes,this.info),this._attributes=new uD(r),this._background=new pz(this,this._nodes),this._geometries=new uG(this._attributes,this.info),this._textures=new u7(this,r,this.info),this._pipelines=new uj(r,this._nodes),this._bindings=new uX(r,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new uL(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new u0(this.lighting),this._bundles=new gV,this._renderContexts=new u5,this._animation.start(),this._initialized=!0,e(this)})),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,r=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();let i=this._nodes.nodeFrame,s=i.renderId,n=this._currentRenderContext,a=this._currentRenderObjectFunction,o=this._compilationPromises,l=!0===e.isScene?e:gJ;null===r&&(r=e);let u=this._renderTarget,d=this._renderContexts.get(r,t,u),h=this._activeMipmapLevel,c=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=c,i.renderId++,i.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new gU),d.clippingContext.updateGlobal(l,t),l.onBeforeRender(this,e,t,u);let p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),r!==e&&r.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)}),p.finish(),null!==u){this._textures.updateRenderTarget(u,h);let e=this._textures.get(u);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._background.update(l,p,d);let g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,l,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,l,y),i.renderId=s,this._currentRenderContext=n,this._currentRenderObjectFunction=a,this._compilationPromises=o,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(c)}async renderAsync(e,t){!1===this._initialized&&await this.init(),this._renderScene(e,t)}async waitForGPU(){await this.backend.waitForGPU()}set highPrecision(e){!0===e?(this.overrideNodes.modelViewMatrix=sL,this.overrideNodes.modelNormalViewMatrix=sU):this.highPrecision&&(this.overrideNodes.modelViewMatrix=null,this.overrideNodes.modelNormalViewMatrix=null)}get highPrecision(){return this.overrideNodes.modelViewMatrix===sL&&this.overrideNodes.modelNormalViewMatrix===sU}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getColorBufferType(){return this._colorBufferType}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost: 8 9Message: ${e.message}`;e.reason&&(t+=` 10Reason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,r){let{bundleGroup:i,camera:s,renderList:n}=e,a=this._currentRenderContext,o=this._bundles.get(i,s),l=this.backend.get(o);void 0===l.renderContexts&&(l.renderContexts=new Set);let u=i.version!==l.version,d=!1===l.renderContexts.has(a)||u;if(l.renderContexts.add(a),d){this.backend.beginBundle(a),(void 0===l.renderObjects||u)&&(l.renderObjects=[]),this._currentRenderBundle=o;let{transparentDoublePass:e,transparent:d,opaque:h}=n;!0===this.opaque&&h.length>0&&this._renderObjects(h,s,t,r),!0===this.transparent&&d.length>0&&this._renderTransparents(d,e,s,t,r),this._currentRenderBundle=null,this.backend.finishBundle(a,o),l.ver
10sion=i.version}else{let{renderObjects:e}=l;for(let t=0,r=e.length;t<r;t++){let r=e[t];this._nodes.needsRefresh(r)&&(this._nodes.updateBefore(r),this._nodes.updateForRender(r),this._bindings.updateForRender(r),this._nodes.updateAfter(r))}}this.backend.addBundle(a,o)}render(e,t){if(!1===this._initialized)return console.warn("THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead."),this.renderAsync(e,t);this._renderScene(e,t)}_getFrameBufferTarget(){let{currentToneMapping:e,currentColorSpace:t}=this,r=e!==u.y_p,i=t!==u.Zr2;if(!1===r&&!1===i)return null;let{width:s,height:n}=this.getDrawingBufferSize(g0),{depth:a,stencil:o}=this,l=this._frameBufferTarget;null===l&&((l=new u.O0B(s,n,{depthBuffer:a,stencilBuffer:o,type:this._colorBufferType,format:u.GWd,colorSpace:u.Zr2,generateMipmaps:!1,minFilter:u.k6q,magFilter:u.k6q,samples:this.samples})).isPostProcessingRenderTarget=!0,this._frameBufferTarget=l);let d=this.getOutputRenderTarget();return l.depthBuffer=a,l.stencilBuffer=o,l.setSize(s,n,null!==d?d.depth:1),l.viewport.copy(this._viewport),l.scissor.copy(this._scissor),l.viewport.multiplyScalar(this._pixelRatio),l.scissor.multiplyScalar(this._pixelRatio),l.scissorTest=this._scissorTest,l.multiview=null!==d&&d.multiview,l}_renderScene(e,t,r=!0){let i;if(!0===this._isDeviceLost)return;let s=r?this._getFrameBufferTarget():null,n=this._nodes.nodeFrame,a=n.renderId,o=this._currentRenderContext,l=this._currentRenderObjectFunction,u=!0===e.isScene?e:gJ,d=this._renderTarget||this._outputRenderTarget,h=this._activeCubeFace,c=this._activeMipmapLevel;null!==s?(i=s,this.setRenderTarget(i)):i=d;let p=this._renderContexts.get(e,t,i);this._currentRenderContext=p,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,n.renderId=this.info.calls;let g=this.coordinateSystem,m=this.xr;if(t.coordinateSystem!==g&&!1===m.isPresenting&&(t.coordinateSystem=g,t.updateProjectionMatrix(),t.isArrayCamera))for(let e of t.cameras)e.coordinateSystem=g,e.updateProjectionMatrix();!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),null===t.parent&&!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),!0===m.enabled&&!0===m.isPresenting&&(!0===m.cameraAutoUpdate&&m.updateCamera(t),t=m.getCamera());let f=this._viewport,y=this._scissor,x=this._pixelRatio;null!==i&&(f=i.viewport,y=i.scissor,x=1),this.getDrawingBufferSize(g0),g1.set(0,0,g0.width,g0.height);let b=void 0===f.minDepth?0:f.minDepth,T=void 0===f.maxDepth?1:f.maxDepth;p.viewportValue.copy(f).multiplyScalar(x).floor(),p.viewportValue.width>>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=T,p.viewport=!1===p.viewportValue.equals(g1),p.scissorValue.copy(y).multiplyScalar(x).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(g1),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new gU),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,i);let _=t.isArrayCamera?g3:g2;t.isArrayCamera||(g4.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),_.setFromProjectionMatrix(g4,g));let v=this._renderLists.get(e,t);if(v.begin(),this._projectObject(e,t,0,v,p.clippingContext),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==i){this._textures.updateRenderTarget(i,c);let e=this._textures.get(i);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=i,p.depth=i.depthBuffer,p.stencil=i.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=h,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._background.update(u,v,p),p.camera=t,this.backend.beginRender(p);let{bundles:S,lightsNode:N,transparentDoublePass:R,transparent:A,opaque:E}=v;return S.length>0&&this._renderBundles(S,u,N),!0===this.opaque&&E.length>0&&this._renderObjects(E,t,u,N),!0===this.transparent&&A.length>0&&this._renderTransparents(A,R,t,u,N),this.backend.finishRender(p),n.renderId=a,this._currentRenderContext=o,this._currentRenderObjectFunction=l,null!==s&&(this.setRenderTarget(d,h,c),this._renderOutput(i)),u.onAfterRender(this,e,t,i),p}_renderOutput(e){let t=this._quad;this._nodes.hasOutputChange(e.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(e.texture),t.material.needsUpdate=!0);let r=this.autoClear,i=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderScene(t,t.camera,!1),this.autoClear=r,this.xr.enabled=i}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,r){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this._pixelRatio=r,this.domElement.width=Math.floor(e*r),this.domElement.height=Math.floor(t*r),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize())}setSize(e,t,r=!0){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===r&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize())}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){let t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}
10setScissor(e,t,r,i){let s=this._scissor;e.isVector4?s.copy(e):s.set(e,t,r,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,r,i,s=0,n=1){let a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,r,i),a.minDepth=s,a.maxDepth=n}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){let t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,r=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,r);let i=this._renderTarget||this._getFrameBufferTarget(),s=null;if(null!==i){this._textures.updateRenderTarget(i);let e=this._textures.get(i);(s=this._renderContexts.getForClear(i)).textures=e.textures,s.depthTexture=e.depthTexture,s.width=e.width,s.height=e.height,s.renderTarget=i,s.depth=i.depthBuffer,s.stencil=i.stencilBuffer,s.clearColorValue=this.backend.getClearColor(),s.activeCubeFace=this.getActiveCubeFace(),s.activeMipmapLevel=this.getActiveMipmapLevel()}this.backend.clear(e,t,r,s),null!==i&&null===this._renderTarget&&this._renderOutput(i)}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,r=!0){!1===this._initialized&&await this.init(),this.clear(e,t,r)}async clearColorAsync(){this.clearAsync(!0,!1,!1)}async clearDepthAsync(){this.clearAsync(!1,!0,!1)}async clearStencilAsync(){this.clearAsync(!1,!1,!0)}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:u.y_p}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:u.Zr2}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||null===this._renderTarget}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),null!==this._frameBufferTarget&&this._frameBufferTarget.dispose(),Object.values(this.backend.timestampQueryPool).forEach(e=>{null!==e&&e.dispose()}),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,r=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=r}getRenderTarget(){return this._renderTarget}setOutputRenderTarget(e){this._outputRenderTarget=e}getOutputRenderTarget(){return this._outputRenderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this._isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);let t=this._nodes.nodeFrame,r=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;let i=this.backend,s=this._pipelines,n=this._bindings,a=this._nodes,o=Array.isArray(e)?e:[e];if(void 0===o[0]||!0!==o[0].isComputeNode)throw Error("THREE.Renderer: .compute() expects a ComputeNode.");for(let t of(i.beginCompute(e),o)){if(!1===s.has(t)){let e=()=>{t.removeEventListener("dispose",e),s.delete(t),n.delete(t),a.delete(t)};t.addEventListener("dispose",e);let r=t.onInitFunction;null!==r&&r.call(t,{renderer:this})}a.updateForCompute(t),n.updateForCompute(t);let r=n.getForCompute(t),o=s.getForCompute(t,r);i.compute(e,t,r,o)}i.finishCompute(e),t.renderId=r}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e)}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}async resolveTimestampsAsync(e="render"){return!1===this._initialized&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){!1===this._initialized&&await this.init(),this._textures.updateTexture(e)}initTexture(e){!1===this._initialized&&console.warn("THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead."),this._textures.updateTexture(e)}
10copyFramebufferToTexture(e,t=null){let r;if(null!==t)if(t.isVector2)t=g6.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=g6.copy(t).floor()}else t=g6.set(0,0,e.image.width,e.image.height);let i=this._currentRenderContext;null!==i?r=i.renderTarget:null!==(r=this._renderTarget||this._getFrameBufferTarget())&&(this._textures.updateRenderTarget(r),i=this._textures.get(r)),this._textures.updateTexture(e,{renderTarget:r}),this.backend.copyFramebufferToTexture(e,i,t)}copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,r,i,s,n)}async readRenderTargetPixelsAsync(e,t,r,i,s,n=0,a=0){return this.backend.copyTextureToBuffer(e.textures[n],t,r,i,s,a)}_projectObject(e,t,r,i,s){if(!1===e.visible)return;if(e.layers.test(t.layers)){if(e.isGroup)r=e.renderOrder,e.isClippingGroup&&e.enabled&&(s=s.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){let n=t.isArrayCamera?g3:g2;if(!e.frustumCulled||n.intersectsSprite(e,t)){!0===this.sortObjects&&g6.setFromMatrixPosition(e.matrixWorld).applyMatrix4(g4);let{geometry:t,material:n}=e;n.visible&&i.push(e,t,n,r,g6.z,null,s)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){let n=t.isArrayCamera?g3:g2;if(!e.frustumCulled||n.intersectsObject(e,t)){let{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),g6.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(g4)),Array.isArray(n)){let a=t.groups;for(let o=0,l=a.length;o<l;o++){let l=a[o],u=n[l.materialIndex];u&&u.visible&&i.push(e,t,u,r,g6.z,l,s)}}else n.visible&&i.push(e,t,n,r,g6.z,null,s)}}}if(!0===e.isBundleGroup&&void 0!==this.backend.beginBundle){let r=i;(i=this._renderLists.get(e,t)).begin(),r.pushBundle({bundleGroup:e,camera:t,renderList:i}),i.finish()}let n=e.children;for(let e=0,a=n.length;e<a;e++)this._projectObject(n[e],t,r,i,s)}_renderBundles(e,t,r){for(let i of e)this._renderBundle(i,t,r)}_renderTransparents(e,t,r,i,s){if(t.length>0){for(let{material:e}of t)e.side=u.hsX;for(let{material:e}of(this._renderObjects(t,r,i,s,"backSide"),t))e.side=u.hB5;for(let{material:n}of(this._renderObjects(e,r,i,s),t))n.side=u.$EB}else this._renderObjects(e,r,i,s)}_renderObjects(e,t,r,i,s=null){for(let n=0,a=e.length;n<a;n++){let{object:a,geometry:o,material:l,group:u,clippingContext:d}=e[n];this._currentRenderObjectFunction(a,r,t,o,l,u,i,d,s)}}renderObject(e,t,r,i,s,n,a,o=null,l=null){let d,h,c;if(e.onBeforeRender(this,t,r,i,s,n),!0===s.allowOverride&&null!==t.overrideMaterial){let e=t.overrideMaterial;s.positionNode&&s.positionNode.isNode&&(d=e.positionNode,e.positionNode=s.positionNode),e.alphaTest=s.alphaTest,e.alphaMap=s.alphaMap,e.transparent=s.transparent||s.transmission>0,e.isShadowPassMaterial&&(e.side=null===s.shadowSide?s.side:s.shadowSide,s.depthNode&&s.depthNode.isNode&&(c=e.depthNode,e.depthNode=s.depthNode),s.castShadowNode&&s.castShadowNode.isNode&&(h=e.colorNode,e.colorNode=s.castShadowNode),s.castShadowPositionNode&&s.castShadowPositionNode.isNode&&(d=e.positionNode,e.positionNode=s.castShadowPositionNode)),s=e}!0===s.transparent&&s.side===u.$EB&&!1===s.forceSinglePass?(s.side=u.hsX,this._handleObjectFunction(e,s,t,r,a,n,o,"backSide"),s.side=u.hB5,this._handleObjectFunction(e,s,t,r,a,n,o,l),s.side=u.$EB):this._handleObjectFunction(e,s,t,r,a,n,o,l),void 0!==d&&(t.overrideMaterial.positionNode=d),void 0!==c&&(t.overrideMaterial.depthNode=c),void 0!==h&&(t.overrideMaterial.colorNode=h),e.onAfterRender(this,t,r,i,s,n)}_renderObjectDirect(e,t,r,i,s,n,a,o){let l=this._objects.get(e,t,r,i,s,this._currentRenderContext,a,o);l.drawRange=e.geometry.drawRange,l.group=n;let u=this._nodes.needsRefresh(l);u&&(this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l)),this._pipelines.updateForRender(l),null!==this._currentRenderBundle&&(this.backend.get(this._currentRenderBundle).renderObjects.push(l),l.bundle=this._currentRenderBundle.bundleGroup),this.backend.draw(l,this.info),u&&this._nodes.updateAfter(l)}_createObjectPipeline(e,t,r,i,s,n,a,o){let l=this._objects.get(e,t,r,i,s,this._currentRenderContext,a,o);l.drawRange=e.geometry.drawRange,l.group=n,this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l),this._pipelines.getForRender(l,this._compilationPromises),this._nodes.updateAfter(l)}get compile(){return this.compileAsync}}class g5{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}clone(){return Object.assign(new this.constructor,this)}}class g9 extends g5{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t}get byteLength(){var e;return(e=this._buffer.byteLength)+(16-e%16)%16}get buffer(){return this._buffer}update(){return!0}}class g7 extends g9{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let me=0;class mt extends g7{constructor(e,t){super("UniformBuffer_"+me++,e?e.value:null),this.nodeUniform=e,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class mr extends g7{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[]}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){let t=this.uniforms.indexOf(e);return -1!==t&&this.uniforms.splice(t,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;return null===e&&(e=new Float32Array(new ArrayBuffer(this.byteLength)),this._buffer=e),e}get byteLength(){let e=0;for(let t=0,r=this.uniforms.length;t<r;t++){let r=this.uniforms[t],{boundary:i,itemSize:s}=r,n=e%16,a=16-n;0!==n&&a-i<0?e+=16-n:n%i!=0&&(e+=n%i),r.offset=e/this.bytesPerElement,e+=s*this.bytesPerElement}return 16*Math.ceil(e/16)}update(){let e=!1;for(let t of this.uniforms)!0===this.updateByType(t)&&(e=!0);return e}updateByType(e){return e.isNumberUniform?this.updateNumber(e):e.isVector2Uniform?this.updateVector2(e):e.isVector3Uniform?this.updateVector3(e):e.isVector4Uniform?this.updateVector4(e):e.isColorUniform?this.updateColor(e):e.isMatrix3Uniform?this.updateMatrix3(e):e.isMatrix4Uniform?this.updateMatrix4(e):void console.error("THREE.WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();return r[s]!==i&&(this._getBufferForType(n)[s]=r[s]=i,t=!0),t}updateVector2(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y){let e=this._getBufferForType(n);e[s+0]=r[s+0]=i.x,e[s+1]=r[s+1]=i.y,t=!0}return t}updateVector3(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y||r[s+2]!==i.z){let e=this._getBufferForType(n);e[s+0]=r[s+0]=i.x,e[s+1]=r[s+1]=i.y,e[s+2]=r[s+2]=i.z,t=!0}return t}updateVector4(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y||r[s+2]!==i.z||r[s+4]!==i.w){let e=this._getBufferForType(n);e[s+0]=r[s+0]=i.x,e[s+1]=r[s+1]=i.y,e[s+2]=r[s+2]=i.z,e[s+3]=r[s+3]=i.w,t=!0}return t}updateColor(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset;if(r[s+0]!==i.r||r[s+1]!==i.g||r[s+2]!==i.b){let e=this.buffer;e[s+0]=r[s+0]=i.r,e[s+1]=r[s+1]=i.g,e[s+2]=r[s+2]=i.b,t=!0}return t}updateMatrix3(e){let t=!1,r=this.values,i=e.getValue().elements,s=e.offset;if(r[s+0]!==i[0]||r[s+1]!==i[1]||r[s+2]!==i[2]||r[s+4]!==i[3]||r[s+5]!==i[4]||r[s+6]!==i[5
10]||r[s+8]!==i[6]||r[s+9]!==i[7]||r[s+10]!==i[8]){let e=this.buffer;e[s+0]=r[s+0]=i[0],e[s+1]=r[s+1]=i[1],e[s+2]=r[s+2]=i[2],e[s+4]=r[s+4]=i[3],e[s+5]=r[s+5]=i[4],e[s+6]=r[s+6]=i[5],e[s+8]=r[s+8]=i[6],e[s+9]=r[s+9]=i[7],e[s+10]=r[s+10]=i[8],t=!0}return t}updateMatrix4(e){let t=!1,r=this.values,i=e.getValue().elements,s=e.offset;return!1===function(e,t,r){for(let i=0,s=t.length;i<s;i++)if(e[r+i]!==t[i])return!1;return!0}(r,i,s)&&(this.buffer.set(i,s),function(e,t,r){for(let i=0,s=t.length;i<s;i++)e[r+i]=t[i]}(r,i,s),t=!0),t}_getBufferForType(e){return"int"===e||"ivec2"===e||"ivec3"===e||"ivec4"===e?new Int32Array(this.buffer.buffer):"uint"===e||"uvec2"===e||"uvec3"===e||"uvec4"===e?new Uint32Array(this.buffer.buffer):this.buffer}}let mi=0;class ms extends mr{constructor(e,t){super(e),this.id=mi++,this.groupNode=t,this.isNodeUniformsGroup=!0}}let mn=0;class ma extends g5{constructor(e,t){super(e),this.id=mn++,this.texture=t,this.version=t?t.version:0,this.store=!1,this.generation=null,this.isSampledTexture=!0}needsBindingsUpdate(e){let{texture:t}=this;return e!==this.generation?(this.generation=e,!0):t.isVideoTexture}update(){let{texture:e,version:t}=this;return t!==e.version&&(this.version=e.version,!0)}}class mo extends ma{constructor(e,t,r,i=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r,this.access=i}needsBindingsUpdate(e){return this.textureNode.value!==this.texture||super.needsBindingsUpdate(e)}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class ml extends mo{constructor(e,t,r,i=null){super(e,t,r,i),this.isSampledCubeTexture=!0}}class mu extends mo{constructor(e,t,r,i=null){super(e,t,r,i),this.isSampledTexture3D=!0}}let md={textureDimensions:"textureSize",equals:"equal"},mh={low:"lowp",medium:"mediump",high:"highp"},mc={swizzleAssign:!0,storageBuffer:!1},mp={perspective:"smooth",linear:"noperspective"},mg={centroid:"centroid","flat first":"flat","flat either":"flat"},mm=` 11precision highp float; 12precision highp int; 13precision highp sampler2D; 14precision highp sampler3D; 15precision highp samplerCube; 16precision highp sampler2DArray; 17 18precision highp usampler2D; 19precision highp usampler3D; 20precision highp usamplerCube; 21precision highp usampler2DArray; 22 23precision highp isampler2D; 24precision highp isampler3D; 25precision highp isamplerCube; 26precision highp isampler2DArray; 27 28precision lowp sampler2DShadow; 29precision lowp sampler2DArrayShadow; 30precision lowp samplerCubeShadow; 31`;class mf extends gd{constructor(e,t){super(e,t,new gC),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]}}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==u.jf0}getMethod(e){return md[e]||e}getOutputStructName(){return""}buildFunctionCode(e){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let e of t.inputs)i.push(this.getType(e.type)+" "+e.name);return`${this.getType(t.type)} ${t.name}( ${i.join(", ")} ) { 32 33 ${r.vars} 34 35${r.code} 36 return ${r.result}; 37 38}`}setupPBO(e){let t=e.value;if(void 0===t.pbo){let e=t.array,r=t.count*t.itemSize,{itemSize:i}=t,s=t.array.constructor.name.toLowerCase().includes("int"),n=s?u.ZQM:u.VT0;2===i?n=s?u.TkQ:u.paN:3===i?n=s?u.VGF:u.HIg:4===i&&(n=s?u.c90:u.GWd);let a={Float32Array:u.RQf,Uint8Array:u.OUM,Uint16Array:u.cHt,Uint32Array:u.bkx,Int8Array:u.tJf,Int16Array:u.fBL,Int32Array:u.Yuy,Uint8ClampedArray:u.OUM},o=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(r/i)))),l=Math.ceil(r/i/o);o*l*i<r&&l++;let d=o*l*i,h=new e.constructor(d);h.set(e,0),t.array=h;let c=new u.GYF(t.array,o,l,n,a[t.array.constructor.name]||u.RQf);c.needsUpdate=!0,c.isPBOTexture=!0;let p=new i8(c,null,null);p.setPrecision("high"),t.pboNode=p,t.pbo=p.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.label)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&!0!==e.node.isTextureNode&&!0!==e.node.isBufferNode?t.charAt(0)+"_"+e.name:super.getPropertyName(e,t)}generatePBO(e){let{node:t,indexNode:r}=e,i=t.value;this.renderer.backend.has(i)&&(this.renderer.backend.get(i).pbo=i.pbo);let s=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.label),n=this.getPropertyName(s);this.increaseUsage(r);let a=r.build(this,"uint"),o=this.getDataFromNode(e),l=o.propertyName;if(void 0===l){let r=this.getVarFromNode(e);l=this.getPropertyName(r);let s=this.getDataFromNode(t),d=s.propertySizeName;void 0===d&&(d=l+"Size",this.getVarFromNode(t,d,"uint"),this.addLineFlowCode(`${d} = uint( textureSize( ${n}, 0 ).x )`,e),s.propertySizeName=d);let{itemSize:h}=i,c="."+F.join("").slice(0,h),p=`ivec2(${a} % ${d}, ${a} / ${d})`,g=this.generateTextureLoad(null,n,p,null,"0"),m="vec4";i.pbo.type===u.bkx?m="uvec4":i.pbo.type===u.Yuy&&(m="ivec4"),this.addLineFlowCode(`${l} = ${m}(${g})${c}`,e),o.propertyName=l}return l}generateTextureLoad(e,t,r,i,s="0"){return i?`texelFetch( ${t}, ivec3( ${r}, ${i} ), ${s} )`:`texelFetch( ${t}, ${r}, ${s} )`}
38generateTexture(e,t,r,i){return e.isDepthTexture?(i&&(r=`vec4( ${r}, ${i} )`),`texture( ${t}, ${r} ).x`):(i&&(r=`vec3( ${r}, ${i} )`),`texture( ${t}, ${r} )`)}generateTextureLevel(e,t,r,i){return`textureLod( ${t}, ${r}, ${i} )`}generateTextureBias(e,t,r,i){return`texture( ${t}, ${r}, ${i} )`}generateTextureGrad(e,t,r,i){return`textureGrad( ${t}, ${r}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,r,i,s,n=this.shaderStage){if("fragment"===n)return s?`texture( ${t}, vec4( ${r}, ${s}, ${i} ) )`:`texture( ${t}, vec3( ${r}, ${i} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}getVars(e){let t=[],r=this.vars[e];if(void 0!==r)for(let e of r)t.push(`${this.getVar(e.type,e.name,e.count)};`);return t.join("\n ")}getUniforms(e){let t=this.uniforms[e],r=[],i={};for(let s of t){let t=null,n=!1;if("texture"===s.type||"texture3D"===s.type){let e=s.node.value,r="";(!0===e.isDataTexture||!0===e.isData3DTexture)&&(e.type===u.bkx?r="u":e.type===u.Yuy&&(r="i")),t="texture3D"===s.type&&!1===e.isTextureArray?`${r}sampler3D ${s.name};`:e.compareFunction?!0===e.isDepthArrayTexture?`sampler2DArrayShadow ${s.name};`:`sampler2DShadow ${s.name};`:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture||!0===e.isTextureArray?`${r}sampler2DArray ${s.name};`:`${r}sampler2D ${s.name};`}else if("cubeTexture"===s.type)t=`samplerCube ${s.name};`;else if("buffer"===s.type){let e=s.node,r=this.getType(e.bufferType),i=e.bufferCount,n=i>0?i:"";t=`${e.name} { 39 ${r} ${s.name}[${n}]; 40}; 41`}else{let r=this.getVectorType(s.type);t=`${r} ${this.getPropertyName(s,e)};`,n=!0}let a=s.node.precision;if(null!==a&&(t=mh[a]+" "+t),n){t=" "+t;let e=s.groupNode.name;(i[e]||(i[e]=[])).push(t)}else t="uniform "+t,r.push(t)}let s="";for(let t in i){let r=i[t];s+=this._getGLSLUniformStruct(e+"_"+t,r.join("\n"))+"\n"}return s+r.join("\n")}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==u.Yuy){let r=e;e.isInterleavedBufferAttribute&&(r=e.data);let i=r.array;!1==(i instanceof Uint32Array||i instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){let e=this.getAttributesArray(),r=0;for(let i of e)t+=`layout( location = ${r++} ) in ${i.type} ${i.name}; 42`}return t}getStructMembers(e){let t=[];for(let r of e.members)t.push(` ${r.type} ${r.name};`);return t.join("\n")}getStructs(e){let t=[],r=this.structs[e],i=[];for(let e of r)if(e.output)for(let t of e.members)i.push(`layout( location = ${t.index} ) out ${t.type} ${t.name};`);else{let r="struct "+e.name+" {\n";r+=this.getStructMembers(e),r+="\n};\n",t.push(r)}return 0===i.length&&i.push("layout( location = 0 ) out vec4 fragColor;"),"\n"+i.join("\n")+"\n\n"+t.join("\n")}getVaryings(e){let t="",r=this.varyings;if("vertex"===e||"compute"===e)for(let i of r){"compute"===e&&(i.needsInterpolation=!0);let r=this.getType(i.type);if(i.needsInterpolation)if(i.interpolationType){let e=mp[i.interpolationType]||i.interpolationType,s=mg[i.interpolationSampling]||"";t+=`${e} ${s} out ${r} ${i.name}; 43`}else{let e=r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":"";t+=`${e}out ${r} ${i.name}; 44`}else t+=`${r} ${i.name}; 45`}else if("fragment"===e){for(let e of r)if(e.needsInterpolation){let r=this.getType(e.type);if(e.interpolationType){let i=mp[e.interpolationType]||e.interpolationType,s=mg[e.interpolationSampling]||"";t+=`${i} ${s} in ${r} ${e.name}; 46`}else{let i=r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":"";t+=`${i}in ${r} ${e.name}; 47`}}}for(let r of this.builtins[e])t+=`${r}; 48`;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){let e=this.object.workgroupSize.reduce((e,t)=>e*t,1);return`uint( gl_InstanceID ) % ${e}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,r=this.shaderStage){let i=this.extensions[r]||(this.extensions[r]=new Map);!1===i.has(e)&&i.set(e,{name:e,behavior:t})}getExtensions(e){let t=[];if("vertex"===e){let t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}let r=this.extensions[e];if(void 0!==r)for(let{name:e,behavior:i}of r.values())t.push(`#extension ${e} : ${i}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=mc[e];if(void 0===t){let r;switch(t=!1,e){case"float32Filterable":r="OES_texture_float_linear";break;case"clipDistance":r="WEBGL_clip_cull_distance"}if(void 0!==r){let e=this.renderer.backend.extensions;e.has(r)&&(e.get(r),t=!0)}mc[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}
48enableMultiview(){this.enableExtension("GL_OVR_multiview2","require","fragment"),this.enableExtension("GL_OVR_multiview2","require","vertex"),this.builtins.vertex.push("layout(num_views = 2) in")}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){let e=this.transforms,t="";for(let r=0;r<e.length;r++){let i=e[r],s=this.getPropertyName(i.attributeNode);s&&(t+=`${i.varyingName} = ${s}; 49 `)}return t}_getGLSLUniformStruct(e,t){return` 50layout( std140 ) uniform ${e} { 51${t} 52};`}_getGLSLVertexCode(e){return`#version 300 es 53 54${this.getSignature()} 55 56// extensions 57${e.extensions} 58 59// precision 60${mm} 61 62// uniforms 63${e.uniforms} 64 65// varyings 66${e.varyings} 67 68// attributes 69${e.attributes} 70 71// codes 72${e.codes} 73 74void main() { 75 76 // vars 77 ${e.vars} 78 79 // transforms 80 ${e.transforms} 81 82 // flow 83 ${e.flow} 84 85 gl_PointSize = 1.0; 86 87} 88`}_getGLSLFragmentCode(e){return`#version 300 es 89 90${this.getSignature()} 91 92// extensions 93${e.extensions} 94 95// precision 96${mm} 97 98// uniforms 99${e.uniforms} 100 101// varyings 102${e.varyings} 103 104// codes 105${e.codes} 106 107// structs 108${e.structs} 109 110void main() { 111 112 // vars 113 ${e.vars} 114 115 // flow 116 ${e.flow} 117 118} 119`}buildCode(){let e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(let t in this.sortBindingGroups(),e){let r="// code\n\n";r+=this.flowCode[t];let i=this.flowNodes[t],s=i[i.length-1];for(let e of i){let i=this.getFlowData(e),n=e.name;n&&(r.length>0&&(r+="\n"),r+=` // flow -> ${n} 120 `),r+=`${i.code} 121 `,e===s&&"compute"!==t&&(r+="// result\n ","vertex"===t?(r+="gl_Position = ",r+=`${i.result};`):"fragment"!==t||e.outputNode.isOutputStructNode||(r+="fragColor = ",r+=`${i.result};`))}let n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=r}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),n=this.getDataFromNode(e,r,this.globalCache),a=n.uniformGPU;if(void 0===a){let i=e.groupNode,o=i.name,l=this.getBindGroupArray(o,r);if("texture"===t)a=new mo(s.name,s.node,i),l.push(a);else if("cubeTexture"===t)a=new ml(s.name,s.node,i),l.push(a);else if("texture3D"===t)a=new mu(s.name,s.node,i),l.push(a);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,s.name=`buffer${e.id}`;let t=new mt(e,i);t.name=e.name,l.push(t),a=t}else{let e=this.uniformGroups[r]||(this.uniformGroups[r]={}),n=e[o];void 0===n&&(n=new ms(r+"_"+o,i),e[o]=n,l.push(n)),a=this.getNodeUniform(s,t),n.addUniform(a)}n.uniformGPU=a}return s}}let my=null,mx=null;class mb{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={render:null,compute:null},this.trackTimestamp=!0===e.trackTimestamp}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}destroySampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp)return void(0,u.mcG)("WebGPURenderer: Timestamp tracking is disabled.");let t=this.timestampQueryPool[e];if(!t)return void(0,u.mcG)(`WebGPURenderer: No timestamp query pool for type '${e}' found.`);let r=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=r,r}async waitForGPU(){}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getMaxAnisotropy(){}getDrawingBufferSize(){return my=my||new u.I9Y,this.renderer.getDrawingBufferSize(my)}setScissorTest(){}getClearColor(){let e=this.renderer;return mx=mx||new de,e.getClearColor(mx),mx.getRGB(mx),mx}getDomElement(){let e=this.domElement;return null===e&&("setAttribute"in(e=void 0!==this.parameters.canvas?this.parameters.canvas:(0,u.lPF)())&&e.setAttribute("data-engine",`three.js r${u.sPf} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let mT=0;class m_{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class mv{constructor(e){this.backend=e}createAttribute(e,t){let r,i=this.backend,{gl:s}=i,n=e.array,a=e.usage||s.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,l=i.get(o),d=l.bufferGPU;if(void 0===d&&(l.bufferGPU=d=this._createBuffer(s,t,n,a),l.bufferType=t,l.version=o.version),n instanceof Float32Array)r=s.FLOAT;else if(n instanceof Uint16Array)r=e.isFloat16BufferAttribute?s.HALF_FLOAT:s.UNSIGNED_SHORT;else if(n instanceof Int16Array)r=s.SHORT;else if(n instanceof Uint32Array)r=s.UNSIGNED_INT;else if(n instanceof Int32Array)r=s.INT;else if(n instanceof Int8Array)r=s.BYTE;else if(n instanceof Uint8Array)r=s.UNSIGNED_BYTE;else if(n instanceof Uint8ClampedArray)r=s.UNSIGNED_BYTE;else throw Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);let h={bufferGPU:d,bufferType:t,type:r,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:r===s.INT||r===s.UNSIGNED_INT||e.gpuType===u.Yuy,id:mT++};(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(h=new m_(h,this._createBuffer(s,t,n,a))),i.set(e,h)}updateAttribute(e){let t=this.backend,{gl:r}=t,i=e.array,s=e.isInterleavedBufferAttribute?e.data:e,n=t.get(s),a=n.bufferType,o=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(r.bindBuffer(a,n.bufferGPU),0===o.length)r.bufferSubData(a,0,i);else{for(let e=0,t=o.length;e<t;
121e++){let t=o[e];r.bufferSubData(a,t.start*i.BYTES_PER_ELEMENT,i,t.start,t.count)}s.clearUpdateRanges()}r.bindBuffer(a,null),n.version=s.version}destroyAttribute(e){let t=this.backend,{gl:r}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);let i=t.get(e);r.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e){let t=this.backend,{gl:r}=t,i=e.isInterleavedBufferAttribute?e.data:e,{bufferGPU:s}=t.get(i),n=e.array,a=n.byteLength;r.bindBuffer(r.COPY_READ_BUFFER,s);let o=r.createBuffer();r.bindBuffer(r.COPY_WRITE_BUFFER,o),r.bufferData(r.COPY_WRITE_BUFFER,a,r.STREAM_READ),r.copyBufferSubData(r.COPY_READ_BUFFER,r.COPY_WRITE_BUFFER,0,0,a),await t.utils._clientWaitAsync();let l=new e.array.constructor(n.length);return r.bindBuffer(r.COPY_WRITE_BUFFER,o),r.getBufferSubData(r.COPY_WRITE_BUFFER,0,l),r.deleteBuffer(o),r.bindBuffer(r.COPY_READ_BUFFER,null),r.bindBuffer(r.COPY_WRITE_BUFFER,null),l.buffer}_createBuffer(e,t,r,i){let s=e.createBuffer();return e.bindBuffer(t,s),e.bufferData(t,r,i),e.bindBuffer(t,null),s}}class mS{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){let e=this.gl;o={[u.gO9]:e.FUNC_ADD,[u.FXf]:e.FUNC_SUBTRACT,[u.nST]:e.FUNC_REVERSE_SUBTRACT},l={[u.ojh]:e.ZERO,[u.qad]:e.ONE,[u.f4X]:e.SRC_COLOR,[u.ie2]:e.SRC_ALPHA,[u.hgQ]:e.SRC_ALPHA_SATURATE,[u.wn6]:e.DST_COLOR,[u.hdd]:e.DST_ALPHA,[u.LiQ]:e.ONE_MINUS_SRC_COLOR,[u.OuU]:e.ONE_MINUS_SRC_ALPHA,[u.aEY]:e.ONE_MINUS_DST_COLOR,[u.Nt7]:e.ONE_MINUS_DST_ALPHA};let t=e.getParameter(e.SCISSOR_BOX),r=e.getParameter(e.VIEWPORT);this.currentScissor=new u.IUQ().fromArray(t),this.currentViewport=new u.IUQ().fromArray(r),this._tempVec4=new u.IUQ}enable(e){let{enabled:t}=this;!0!==t[e]&&(this.gl.enable(e),t[e]=!0)}disable(e){let{enabled:t}=this;!1!==t[e]&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){let{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){let{gl:t}=this;e!==u.WNZ?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===u.Vb5?t.cullFace(t.BACK):e===u.Jnc?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){let{currentLineWidth:t,gl:r}=this;e!==t&&(r.lineWidth(e),this.currentLineWidth=e)}setBlending(e,t,r,i,s,n,a,d){let{gl:h}=this;if(e===u.XIg){!0===this.currentBlendingEnabled&&(this.disable(h.BLEND),this.currentBlendingEnabled=!1);return}if(!1===this.currentBlendingEnabled&&(this.enable(h.BLEND),this.currentBlendingEnabled=!0),e!==u.bCz){if(e!==this.currentBlending||d!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==u.gO9||this.currentBlendEquationAlpha!==u.gO9)&&(h.blendEquation(h.FUNC_ADD),this.currentBlendEquation=u.gO9,this.currentBlendEquationAlpha=u.gO9),d)switch(e){case u.NTi:h.blendFuncSeparate(h.ONE,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case u.EZo:h.blendFunc(h.ONE,h.ONE);break;case u.Kwu:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case u.EdD:h.blendFuncSeparate(h.ZERO,h.SRC_COLOR,h.ZERO,h.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}else switch(e){case u.NTi:h.blendFuncSeparate(h.SRC_ALPHA,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case u.EZo:h.blendFunc(h.SRC_ALPHA,h.ONE);break;case u.Kwu:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case u.EdD:h.blendFunc(h.ZERO,h.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=d}return}s=s||t,n=n||r,a=a||i,(t!==this.currentBlendEquation||s!==this.currentBlendEquationAlpha)&&(h.blendEquationSeparate(o[t],o[s]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=s),(r!==this.currentBlendSrc||i!==this.currentBlendDst||n!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(h.blendFuncSeparate(l[r],l[i],l[n],l[a]),this.currentBlendSrc=r,this.currentBlendDst=i,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=a),this.currentBlending=e,this.currentPremultipledAlpha=!1}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){let{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthFunc!==e){let{gl:t}=this;switch(e){case u.eHc:t.depthFunc(t.NEVER);break;case u.lGu:t.depthFunc(t.ALWAYS);break;case u.brA:t.depthFunc(t.LESS);break;case u.xSv:t.depthFunc(t.LEQUAL);break;case u.U3G:t.depthFunc(t.EQUAL);break;case u.Gwm:t.depthFunc(t.GEQUAL);break;case u.K52:t.depthFunc(t.GREATER);break;case u.bw0:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}
121scissor(e,t,r,i){let s=this._tempVec4.set(e,t,r,i);if(!1===this.currentScissor.equals(s)){let{gl:e}=this;e.scissor(s.x,s.y,s.z,s.w),this.currentScissor.copy(s)}}viewport(e,t,r,i){let s=this._tempVec4.set(e,t,r,i);if(!1===this.currentViewport.equals(s)){let{gl:e}=this;e.viewport(s.x,s.y,s.z,s.w),this.currentViewport.copy(s)}}setScissorTest(e){let t=this.gl;e?t.enable(t.SCISSOR_TEST):t.disable(t.SCISSOR_TEST)}setStencilTest(e){let{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,r){(this.currentStencilFunc!==e||this.currentStencilRef!==t||this.currentStencilFuncMask!==r)&&(this.gl.stencilFunc(e,t,r),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=r)}setStencilOp(e,t,r){(this.currentStencilFail!==e||this.currentStencilZFail!==t||this.currentStencilZPass!==r)&&(this.gl.stencilOp(e,t,r),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=r)}setMaterial(e,t,r){let{gl:i}=this;e.side===u.$EB?this.disable(i.CULL_FACE):this.enable(i.CULL_FACE);let s=e.side===u.hsX;t&&(s=!s),this.setFlipSided(s),e.blending===u.NTi&&!1===e.transparent?this.setBlending(u.XIg):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);let n=e.stencilWrite;if(this.setStencilTest(n),n&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage&&this.backend.renderer.samples>1?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),r>0&&this.currentClippingPlanes!==r)for(let e=0;e<8;e++)e<r?this.enable(12288+e):this.disable(12288+e)}setPolygonOffset(e,t,r){let{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==r)&&(i.polygonOffset(t,r),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=r)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e&&(this.gl.useProgram(e),this.currentProgram=e,!0)}setVertexState(e,t=null){let r=this.gl;return(this.currentVAO!==e||this.currentIndex!==t)&&(r.bindVertexArray(e),null!==t&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0)}resetVertexState(){let e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){let{gl:r,currentBoundFramebuffers:i}=this;return i[e]!==t&&(r.bindFramebuffer(e,t),i[e]=t,e===r.DRAW_FRAMEBUFFER&&(i[r.FRAMEBUFFER]=t),e===r.FRAMEBUFFER&&(i[r.DRAW_FRAMEBUFFER]=t),!0)}drawBuffers(e,t){let{gl:r}=this,i=[],s=!1;if(null!==e.textures){void 0===(i=this.currentDrawbuffers.get(t))&&(i=[],this.currentDrawbuffers.set(t,i));let n=e.textures;if(i.length!==n.length||i[0]!==r.COLOR_ATTACHMENT0){for(let e=0,t=n.length;e<t;e++)i[e]=r.COLOR_ATTACHMENT0+e;i.length=n.length,s=!0}}else i[0]!==r.BACK&&(i[0]=r.BACK,s=!0);s&&r.drawBuffers(i)}activeTexture(e){let{gl:t,currentTextureSlot:r,maxTextures:i}=this;void 0===e&&(e=t.TEXTURE0+i-1),r!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,r){let{gl:i,currentTextureSlot:s,currentBoundTextures:n,maxTextures:a}=this;void 0===r&&(r=null===s?i.TEXTURE0+a-1:s);let o=n[r];void 0===o&&(o={type:void 0,texture:void 0},n[r]=o),(o.type!==e||o.texture!==t)&&(s!==r&&(i.activeTexture(r),this.currentTextureSlot=r),i.bindTexture(e,t),o.type=e,o.texture=t)}bindBufferBase(e,t,r){let{gl:i}=this,s=`${e}-${t}`;return this.currentBoundBufferBases[s]!==r&&(i.bindBufferBase(e,t,r),this.currentBoundBufferBases[s]=r,!0)}unbindTexture(){let{gl:e,currentTextureSlot:t,currentBoundTextures:r}=this,i=r[t];void 0!==i&&void 0!==i.type&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}}class mN{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=u.jf0){let r,{gl:i,extensions:s}=this;if(e===u.OUM)return i.UNSIGNED_BYTE;if(e===u.Wew)return i.UNSIGNED_SHORT_4_4_4_4;if(e===u.gJ2)return i.UNSIGNED_SHORT_5_5_5_1;if(e===u.Dmk)return i.UNSIGNED_INT_5_9_9_9_REV;if(e===u.tJf)return i.BYTE;if(e===u.fBL)return i.SHORT;if(e===u.cHt)return i.UNSIGNED_SHORT;if(e===u.Yuy)return i.INT;if(e===u.bkx)return i.UNSIGNED_INT;if(e===u.RQf)return i.FLOAT;if(e===u.ix0)return i.HALF_FLOAT;if(e===u.wrO)return i.ALPHA;if(e===u.HIg)return i.RGB;if(e===u.GWd)return i.RGBA;if(e===u.zdS)return i.DEPTH_COMPONENT;if(e===u.dcC)return i.DEPTH_STENCIL;if(e===u.VT0)return i.RED;if(e===u.ZQM)return i.RED_INTEGER;if(e===u.paN)return i.RG;if(e===u.TkQ)return i.RG_INTEGER;if(e===u.c90)return i.RGBA_INTEGER;if(e===u.IE4||e===u.Nz6||e===u.jR7||e===u.BXX)if(t===u.er$){if(null===(r=s.get("WEBGL_compressed_texture_s3tc_srgb")))return null;if(e===u.IE4)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===u.Nz6)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===u.jR7)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===u.BXX)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(r=s.get("WEBGL_compressed_texture_s3tc")))return null;if(e===u.IE4)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===u.Nz6)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===u.jR7)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===u.BXX)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e===u.k6Q||e===u.kTp||e===u.HXV||e===u.pBf){if(null===(r=s.get("WEBGL_compressed_texture_pvrtc")))return null;if(e===u.k6Q)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===u.kTp)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===u.HXV)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===u.pBf)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e===u.CVz||e===u.Riy||e===u.KDk){if(null===(r=s.get("WEBGL_compressed_texture_etc")))return null;if(e===u.CVz||e===u.Riy)return t===u.er$?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(e===u.KDk)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(e===u.qa3||e===u.B_h||e===u.czI||e===u.rSH||e===u.Qrf||e===u.psI||e===u.a5J||e===u._QJ||e===u.uB5||e===u.lyL||e===u.bC7||e===u.y3Z||e===u.ojs||e===u.S$4){if(null===(r=s.get("WEBGL_compressed_texture_astc")))return null;if(e===u.qa3)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===u.B_h)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===u.czI)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===u.rSH)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===u.Qrf)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===u.psI)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===u.a5J)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===u._QJ)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===u.uB5)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===u.lyL)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===u.bC7)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===u.y3Z)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===u.ojs)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===u.S$4)return t===u.er$?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(e===u.Fn){if(null===(r=s.get("EXT_texture_compression_bptc")))return null;if(e===u.Fn)return t===u.er$?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(e===u.Kef||e===u.XG_||e===u.HO_||e===u.CWW){if(null===(r=s.get("EXT_texture_compression_rgtc")))return null;
121if(e===u.Fn)return r.COMPRESSED_RED_RGTC1_EXT;if(e===u.XG_)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===u.HO_)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===u.CWW)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return e===u.V3x?i.UNSIGNED_INT_24_8:void 0!==i[e]?i[e]:null}_clientWaitAsync(){let{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((r,i)=>{!function s(){let n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED){e.deleteSync(t),i();return}if(n===e.TIMEOUT_EXPIRED)return void requestAnimationFrame(s);e.deleteSync(t),r()}()})}}let mR=!1,mA,mE,mw;class mC{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===mR&&(this._init(),mR=!0)}_init(){let e=this.gl;mA={[u.GJx]:e.REPEAT,[u.ghU]:e.CLAMP_TO_EDGE,[u.kTW]:e.MIRRORED_REPEAT},mE={[u.hxR]:e.NEAREST,[u.pHI]:e.NEAREST_MIPMAP_NEAREST,[u.Cfg]:e.NEAREST_MIPMAP_LINEAR,[u.k6q]:e.LINEAR,[u.kRr]:e.LINEAR_MIPMAP_NEAREST,[u.$_I]:e.LINEAR_MIPMAP_LINEAR},mw={[u.amv]:e.NEVER,[u.FFZ]:e.ALWAYS,[u.vim]:e.LESS,[u.TiK]:e.LEQUAL,[u.kO0]:e.EQUAL,[u.gWB]:e.GEQUAL,[u.eoi]:e.GREATER,[u.jzd]:e.NOTEQUAL}}getGLTextureType(e){let{gl:t}=this;return!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDepthArrayTexture||!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture||!0===e.isTextureArray?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D}getInternalFormat(e,t,r,i,s=!1){let{gl:n,extensions:a}=this;if(null!==e){if(void 0!==n[e])return n[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let o=t;return t===n.RED&&(r===n.FLOAT&&(o=n.R32F),r===n.HALF_FLOAT&&(o=n.R16F),r===n.UNSIGNED_BYTE&&(o=n.R8),r===n.UNSIGNED_SHORT&&(o=n.R16),r===n.UNSIGNED_INT&&(o=n.R32UI),r===n.BYTE&&(o=n.R8I),r===n.SHORT&&(o=n.R16I),r===n.INT&&(o=n.R32I)),t===n.RED_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.R8UI),r===n.UNSIGNED_SHORT&&(o=n.R16UI),r===n.UNSIGNED_INT&&(o=n.R32UI),r===n.BYTE&&(o=n.R8I),r===n.SHORT&&(o=n.R16I),r===n.INT&&(o=n.R32I)),t===n.RG&&(r===n.FLOAT&&(o=n.RG32F),r===n.HALF_FLOAT&&(o=n.RG16F),r===n.UNSIGNED_BYTE&&(o=n.RG8),r===n.UNSIGNED_SHORT&&(o=n.RG16),r===n.UNSIGNED_INT&&(o=n.RG32UI),r===n.BYTE&&(o=n.RG8I),r===n.SHORT&&(o=n.RG16I),r===n.INT&&(o=n.RG32I)),t===n.RG_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.RG8UI),r===n.UNSIGNED_SHORT&&(o=n.RG16UI),r===n.UNSIGNED_INT&&(o=n.RG32UI),r===n.BYTE&&(o=n.RG8I),r===n.SHORT&&(o=n.RG16I),r===n.INT&&(o=n.RG32I)),t===n.RGB&&(r===n.FLOAT&&(o=n.RGB32F),r===n.HALF_FLOAT&&(o=n.RGB16F),r===n.UNSIGNED_BYTE&&(o=n.RGB8),r===n.UNSIGNED_SHORT&&(o=n.RGB16),r===n.UNSIGNED_INT&&(o=n.RGB32UI),r===n.BYTE&&(o=n.RGB8I),r===n.SHORT&&(o=n.RGB16I),r===n.INT&&(o=n.RGB32I),r===n.UNSIGNED_BYTE&&(o=i===u.er$&&!1===s?n.SRGB8:n.RGB8),r===n.UNSIGNED_SHORT_5_6_5&&(o=n.RGB565),r===n.UNSIGNED_SHORT_5_5_5_1&&(o=n.RGB5_A1),r===n.UNSIGNED_SHORT_4_4_4_4&&(o=n.RGB4),r===n.UNSIGNED_INT_5_9_9_9_REV&&(o=n.RGB9_E5)),t===n.RGB_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.RGB8UI),r===n.UNSIGNED_SHORT&&(o=n.RGB16UI),r===n.UNSIGNED_INT&&(o=n.RGB32UI),r===n.BYTE&&(o=n.RGB8I),r===n.SHORT&&(o=n.RGB16I),r===n.INT&&(o=n.RGB32I)),t===n.RGBA&&(r===n.FLOAT&&(o=n.RGBA32F),r===n.HALF_FLOAT&&(o=n.RGBA16F),r===n.UNSIGNED_BYTE&&(o=n.RGBA8),r===n.UNSIGNED_SHORT&&(o=n.RGBA16),r===n.UNSIGNED_INT&&(o=n.RGBA32UI),r===n.BYTE&&(o=n.RGBA8I),r===n.SHORT&&(o=n.RGBA16I),r===n.INT&&(o=n.RGBA32I),r===n.UNSIGNED_BYTE&&(o=i===u.er$&&!1===s?n.SRGB8_ALPHA8:n.RGBA8),r===n.UNSIGNED_SHORT_4_4_4_4&&(o=n.RGBA4),r===n.UNSIGNED_SHORT_5_5_5_1&&(o=n.RGB5_A1)),t===n.RGBA_INTEGER&&(r===n.UNSIGNED_BYTE&&(o=n.RGBA8UI),r===n.UNSIGNED_SHORT&&(o=n.RGBA16UI),r===n.UNSIGNED_INT&&(o=n.RGBA32UI),r===n.BYTE&&(o=n.RGBA8I),r===n.SHORT&&(o=n.RGBA16I),r===n.INT&&(o=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(r===n.UNSIGNED_SHORT&&(o=n.DEPTH_COMPONENT16),r===n.UNSIGNED_INT&&(o=n.DEPTH_COMPONENT24),r===n.FLOAT&&(o=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&r===n.UNSIGNED_INT_24_8&&(o=n.DEPTH24_STENCIL8),(o===n.R16F||o===n.R32F||o===n.RG16F||o===n.RG32F||o===n.RGBA16F||o===n.RGBA32F)&&a.get("EXT_color_buffer_float"),o}setTextureParameters(e,t){let{gl:r,extensions:i,backend:s}=this;r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,t.flipY),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),r.pixelStorei(r.UNPACK_ALIGNMENT,t.unpackAlignment),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.NONE),r.texParameteri(e,r.TEXTURE_WRAP_S,mA[t.wrapS]),r.texParameteri(e,r.TEXTURE_WRAP_T,mA[t.wrapT]),(e===r.TEXTURE_3D||e===r.TEXTURE_2D_ARRAY)&&!0!==t.isDepthArrayTexture&&!1===t.isTextureArray&&r.texParameteri(e,r.TEXTURE_WRAP_R,mA[t.wrapR]),r.texParameteri(e,r.TEXTURE_MAG_FILTER,mE[t.magFilter]);let n=void 0!==t.mipmaps&&t.mipmaps.length>0,a=t.minFilter===u.k6q&&n?u.$_I:t.minFilter;if(r.texParameteri(e,r.TEXTURE_MIN_FILTER,mE[a]),t.compareFunction&&(r.texParameteri(e,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(e,r.TEXTURE_COMPARE_FUNC,mw[t.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(t.magFilter===u.hxR||t.minFilter!==u.Cfg&&t.minFilter!==u.$_I||t.type===u.RQf&&!1===i.has("OES_texture_float_linear"))return;if(t.anisotropy>1){let n=i.get("EXT_texture_filter_anisotropic");r.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,s.getMaxAnisotropy()))}}}createDefaultTexture(e){let{gl:t,backend:r,defaultTextures:i}=this,s=this.getGLTextureType(e),n=i[s];void 0===n&&(n=t.createTexture(),r.state.bindTexture(s,n),t.texParameteri(s,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(s,t.TEXTURE_MAG_FILTER,t.NEAREST),i[s]=n),r.set(e,{textureGPU:n,glTextureType:s,isDefault:!0})}createTexture(e,t){let{gl:r,backend:i}=this,{levels:s,width:n,height:a,depth:o}=t,l=i.utils.convert(e.format,e.colorSpace),u=i.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,l,u,e.colorSpace,e.isVideoTexture),h=r.createTexture(),c=this.getGLTextureType(e);i.state.bindTexture(c,h),this.setTextureParameters(c,e),e.isDepthArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture||e.isTextureArray?r.texStorage3D(r.TEXTURE_2D_ARRAY,s,d,n,a,o):e.isData3DTexture?r.texStorage3D(r.TEXTURE_3D,s,d,n,a,o):e.isVideoTexture||r.texStorage2D(c,s,d,n,a),i.set(e,{textureGPU:h,glTextureType:c,glFormat:l,glType:u,glInternalFormat:d})}copyBufferToTexture(e,t){let{gl:r,backend:i}=this,{textureGPU:s,glTextureType:n,glFormat:a,glType:o}=i.get(t),{width:l,height:u}=t.source.data;r.bindBuffer(r.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(n,s),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(n,0,0,0,l,u,a,o,0),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){let{gl:r}=this,{width:i,height:s}=t,{textureGPU:n,glTextureType:a,glFormat:o,glType:l,glInternalFormat:u}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===n)return;let d=e=>
121e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(a,n),this.setTextureParameters(a,e),e.isCompressedTexture){let i=e.mipmaps,s=t.image;for(let t=0;t<i.length;t++){let n=i[t];e.isCompressedArrayTexture?e.format!==r.RGBA?null!==o?r.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,s.depth,o,n.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):r.texSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,s.depth,o,l,n.data):null!==o?r.compressedTexSubImage2D(r.TEXTURE_2D,t,0,0,n.width,n.height,o,n.data):console.warn("Unsupported compressed texture format")}}else if(e.isCubeTexture){let e=t.images;for(let t=0;t<6;t++){let n=d(e[t]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,i,s,o,l,n)}}else if(e.isDataArrayTexture||e.isDepthArrayTexture){let e=t.image;r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,e.width,e.height,e.depth,o,l,e.data)}else if(e.isData3DTexture){let e=t.image;r.texSubImage3D(r.TEXTURE_3D,0,0,0,0,e.width,e.height,e.depth,o,l,e.data)}
vendor: 4,686 bytes, line 121
121else if(e.isVideoTexture)e.update(),r.texImage2D(a,0,u,o,l,t.image);else{let e=d(t.image);r.texSubImage2D(a,0,0,0,i,s,o,l,e)}}generateMipmaps(e){let{gl:t,backend:r}=this,{textureGPU:i,glTextureType:s}=r.get(e);r.state.bindTexture(s,i),t.generateMipmap(s)}deallocateRenderBuffers(e){let{gl:t,backend:r}=this;if(e){let i=r.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(let e in i.framebuffers)t.deleteFramebuffer(i.framebuffers[e]);delete i.framebuffers}if(i.depthRenderbuffer&&(t.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(t.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(t.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let e=0;e<i.msaaRenderbuffers.length;e++)t.deleteRenderbuffer(i.msaaRenderbuffers[e]);delete i.msaaRenderbuffers}}}destroyTexture(e){let{gl:t,backend:r}=this,{textureGPU:i,renderTarget:s}=r.get(e);this.deallocateRenderBuffers(s),t.deleteTexture(i),r.delete(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){let a,o,l,u,d,h,c,p,g,{gl:m,backend:f}=this,{state:y}=this.backend,{textureGPU:x,glTextureType:b,glType:T,glFormat:_}=f.get(t);y.bindTexture(b,x);let v=e.isCompressedTexture?e.mipmaps[n]:e.image;if(null!==r)a=r.max.x-r.min.x,o=r.max.y-r.min.y,l=r.isBox3?r.max.z-r.min.z:1,u=r.min.x,d=r.min.y,h=r.isBox3?r.min.z:0;else{let t=Math.pow(2,-s);a=Math.floor(v.width*t),o=Math.floor(v.height*t),l=e.isDataArrayTexture||e.isDepthArrayTexture?v.depth:e.isData3DTexture?Math.floor(v.depth*t):1,u=0,d=0,h=0}null!==i?(c=i.x,p=i.y,g=i.z):(c=0,p=0,g=0),m.pixelStorei(m.UNPACK_FLIP_Y_WEBGL,t.flipY),m.pixelStorei(m.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),m.pixelStorei(m.UNPACK_ALIGNMENT,t.unpackAlignment);let S=m.getParameter(m.UNPACK_ROW_LENGTH),N=m.getParameter(m.UNPACK_IMAGE_HEIGHT),R=m.getParameter(m.UNPACK_SKIP_PIXELS),A=m.getParameter(m.UNPACK_SKIP_ROWS),E=m.getParameter(m.UNPACK_SKIP_IMAGES);m.pixelStorei(m.UNPACK_ROW_LENGTH,v.width),m.pixelStorei(m.UNPACK_IMAGE_HEIGHT,v.height),m.pixelStorei(m.UNPACK_SKIP_PIXELS,u),m.pixelStorei(m.UNPACK_SKIP_ROWS,d),m.pixelStorei(m.UNPACK_SKIP_IMAGES,h);let w=t.isDataArrayTexture||t.isData3DTexture||t.isDepthArrayTexture;if(e.isRenderTargetTexture||e.isDepthTexture){let r=f.get(e),i=f.get(t),s=f.get(r.renderTarget),n=f.get(i.renderTarget),l=s.framebuffers[r.cacheKey],h=n.framebuffers[i.cacheKey];y.bindFramebuffer(m.READ_FRAMEBUFFER,l),y.bindFramebuffer(m.DRAW_FRAMEBUFFER,h);let g=m.COLOR_BUFFER_BIT;e.isDepthTexture&&(g=m.DEPTH_BUFFER_BIT),m.blitFramebuffer(u,d,a,o,c,p,a,o,g,m.NEAREST),y.bindFramebuffer(m.READ_FRAMEBUFFER,null),y.bindFramebuffer(m.DRAW_FRAMEBUFFER,null)}else w?e.isDataTexture||e.isData3DTexture?m.texSubImage3D(b,n,c,p,g,a,o,l,_,T,v.data):t.isCompressedArrayTexture?m.compressedTexSubImage3D(b,n,c,p,g,a,o,l,_,v.data):m.texSubImage3D(b,n,c,p,g,a,o,l,_,T,v):e.isDataTexture?m.texSubImage2D(b,n,c,p,a,o,_,T,v.data):e.isCompressedTexture?m.compressedTexSubImage2D(b,n,c,p,v.width,v.height,_,v.data):m.texSubImage2D(b,n,c,p,a,o,_,T,v);m.pixelStorei(m.UNPACK_ROW_LENGTH,S),m.pixelStorei(m.UNPACK_IMAGE_HEIGHT,N),m.pixelStorei(m.UNPACK_SKIP_PIXELS,R),m.pixelStorei(m.UNPACK_SKIP_ROWS,A),m.pixelStorei(m.UNPACK_SKIP_IMAGES,E),0===n&&t.generateMipmaps&&m.generateMipmap(b),y.unbindTexture()}copyFramebufferToTexture(e,t,r){let{gl:i}=this,{state:s}=this.backend,{textureGPU:n}=this.backend.get(e),{x:a,y:o,z:l,w:u}=r,d=!0===e.isDepthTexture||t.renderTarget&&t.renderTarget.samples>0,h=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(d){let r,d,c=0!==a||0!==o;if(!0===e.isDepthTexture?(r=i.DEPTH_BUFFER_BIT,d=i.DEPTH_ATTACHMENT,t.stencil&&(r|=i.STENCIL_BUFFER_BIT)):(r=i.COLOR_BUFFER_BIT,d=i.COLOR_ATTACHMENT0),c){let e=this.backend.get(t.renderTarget),d=e.framebuffers[t.getCacheKey()],c=e.msaaFrameBuffer;s.bindFramebuffer(i.DRAW_FRAMEBUFFER,d),s.bindFramebuffer(i.READ_FRAMEBUFFER,c);let p=h-o-u;i.blitFramebuffer(a,p,a+l,p+u,a,p,a+l,p+u,r,i.NEAREST),s.bindFramebuffer(i.READ_FRAMEBUFFER,d),s.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,p,l,u),s.unbindTexture()}else{let e=i.createFramebuffer();s.bindFramebuffer(i.DRAW_FRAMEBUFFER,e),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,d,i.TEXTURE_2D,n,0),i.blitFramebuffer(0,0,l,u,0,0,l,u,r,i.NEAREST),i.deleteFramebuffer(e)}}else s.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,h-u-o,l,u),s.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,r,i=!1){let{gl:s}=this,n=t.renderTarget,{depthTexture:a,depthBuffer:o,stencilBuffer:l,width:u,height:d}=n;
vendor: 1,543 bytes, line 121
121if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!l){let t=s.DEPTH_COMPONENT24;!0===i?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(s.RENDERBUFFER,n.samples,t,u,d):r>0?(a&&a.isDepthTexture&&a.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,t,u,d)):s.renderbufferStorage(s.RENDERBUFFER,t,u,d),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&l&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,u,d):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,d),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,r,i,s,n){let{backend:a,gl:o}=this,{textureGPU:l,glFormat:u,glType:d}=this.backend.get(e),h=o.createFramebuffer();o.bindFramebuffer(o.READ_FRAMEBUFFER,h);let c=e.isCubeTexture?o.TEXTURE_CUBE_MAP_POSITIVE_X+n:o.TEXTURE_2D;o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,c,l,0);let p=this._getTypedArrayType(d),g=i*s*this._getBytesPerTexel(d,u),m=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.bufferData(o.PIXEL_PACK_BUFFER,g,o.STREAM_READ),o.readPixels(t,r,i,s,u,d,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();let f=new p(g/p.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,f),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),o.deleteFramebuffer(h),f}_getTypedArrayType(e){let{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;
121if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){let{gl:r}=this,i=0;return(e===r.UNSIGNED_BYTE&&(i=1),(e===r.UNSIGNED_SHORT_4_4_4_4||e===r.UNSIGNED_SHORT_5_5_5_1||e===r.UNSIGNED_SHORT_5_6_5||e===r.UNSIGNED_SHORT||e===r.HALF_FLOAT)&&(i=2),(e===r.UNSIGNED_INT||e===r.FLOAT)&&(i=4),t===r.RGBA)?4*i:t===r.RGB?3*i:t===r.ALPHA?i:void 0}}class mM{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class mB{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;let e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){let r=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}let mP={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"};class mF{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){let{gl:r,mode:i,object:s,type:n,info:a,index:o}=this;0!==o?r.drawElements(i,t,n,e):r.drawArrays(i,e,t),a.update(s,t,1)}renderInstances(e,t,r){let{gl:i,mode:s,type:n,index:a,object:o,info:l}=this;0!==r&&(0!==a?i.drawElementsInstanced(s,t,n,e,r):i.drawArraysInstanced(s,e,t,r),l.update(o,t,r))}renderMultiDraw(e,t,r){let{extensions:i,mode:s,object:n,info:a}=this;if(0===r)return;let o=i.get("WEBGL_multi_draw");if(null===o)for(let i=0;i<r;i++)this.render(e[i],t[i]);else{0!==this.index?o.multiDrawElementsWEBGL(s,t,0,this.type,e,0,r):o.multiDrawArraysWEBGL(s,e,0,t,0,r);let i=0;for(let e=0;e<r;e++)i+=t[e];a.update(n,i,1)}}renderMultiDrawInstances(e,t,r,i){let{extensions:s,mode:n,object:a,info:o}=this;if(0===r)return;let l=s.get("WEBGL_multi_draw");if(null===l)for(let s=0;s<r;s++)this.renderInstances(e[s],t[s],i[s]);else{0!==this.index?l.multiDrawElementsInstancedWEBGL(n,t,0,this.type,e,0,i,0,r):l.multiDrawArraysInstancedWE
121BGL(n,e,0,t,0,i,0,r);let s=0;for(let e=0;e<r;e++)s+=t[e]*i[e];o.update(a,s,1)}}}class mL{constructor(e=256){this.trackTimestamp=!0,this.maxQueries=e,this.currentQueryIndex=0,this.queryOffsets=new Map,this.isDisposed=!1,this.lastValue=0,this.pendingResolve=!1}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}}class mU extends mL{constructor(e,t,r=2048){if(super(r),this.gl=e,this.type=t,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query"),!this.ext){console.warn("EXT_disjoint_timer_query not supported; timestamps will be disabled."),this.trackTimestamp=!1;return}this.queries=[];for(let t=0;t<this.maxQueries;t++)this.queries.push(e.createQuery());this.activeQuery=null,this.queryStates=new Map}allocateQueriesForContext(e){if(!this.trackTimestamp)return null;if(this.currentQueryIndex+2>this.maxQueries)return(0,u.mcG)(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e.id,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e.id);if(null==t||null!==this.activeQuery)return;let r=this.queries[t];if(r)try{"inactive"===this.queryStates.get(t)&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,r),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(e){console.error("Error in beginQuery:",e),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e.id);if(null!=t&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(e){console.error("Error in endQuery:",e),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{let e=[];for(let[t,r]of this.queryStates)if("ended"===r){let r=this.queries[t];e.push(this.resolveQuery(r))}if(0===e.length)return this.lastValue;let t=(await Promise.all(e)).reduce((e,t)=>e+t,0);return this.lastValue=t,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,t}catch(e){return console.error("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{let r;if(this.isDisposed)return void t(this.lastValue);let i=!1,s=e=>{i||(i=!0,r&&(clearTimeout(r),r=null),t(e))},n=()=>
121{if(this.isDisposed)return void s(this.lastValue);try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT))return void s(this.lastValue);if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){r=setTimeout(n,1);return}let i=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(i)/1e6)}catch(e){console.error("Error checking query:",e),t(this.lastValue)}};n()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,this.trackTimestamp)){for(let e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}}class mI extends mb{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);let t=this.parameters,r={antialias:e.samples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=void 0!==t.context?t.context:e.domElement.getContext("webgl2",r);function s(t){t.preventDefault();let r={api:"WebGL",message:t.statusMessage||"Unknown reason",reason:null,originalEvent:t};e.onDeviceLost(r)}this._onContextLost=s,e.domElement.addEventListener("webglcontextlost",s,!1),this.gl=i,this.extensions=new mM(this),this.capabilities=new mB(this),this.attributeUtils=new mv(this),this.textureUtils=new mC(this),this.bufferRenderer=new mF(this),this.state=new mS(this),this.utils=new mN(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile")}get coordinateSystem(){return u.TdN}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}async waitForGPU(){await this.utils._clientWaitAsync()}async makeXRCompatible(){!0!==this.gl.getContextAttributes().xrCompatible&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,r=null){let i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),null!==r){let t=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:r,glInternalFormat:t}),!0===this.extensions.has("WEBGL_multisampled_render_to_texture")&&!0===e.autoAllocateDepthBuffer&&!1===e.multiview&&console.warn("THREE.WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e.autoAllocateDepthBuffer=!1}}initTimestampQuery(e){if(!this.disjoint||!this.trackTimestamp)return;let t=e.isComputeNode?"compute":"render";this.timestampQueryPool[t]||(this.timestampQueryPool[t]=new mU(this.gl,t,2048));let r=this.timestampQueryPool[t];null!==r.allocateQueriesForContext(e)&&r.beginQuery(e)}prepareTimestampBuffer(e){if(!this.disjoint||!this.trackTimestamp)return;let t=e.isComputeNode?"compute":"render";this.timestampQueryPool[t].endQuery(e)}getContext(){return this.gl}beginRender(e){let{state:t,gl:r}=this,i=this.get(e);if(e.viewport?this.updateViewport(e):t.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight),e.scissor){let{x:r,y:i,width:s,height:n}=e.scissorValue;t.scissor(r,e.height-n-i,s,n)}this.initTimestampQuery(e),i.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);let s=e.occlusionQueryCount;s>0&&(i.currentOcclusionQueries=i.occlusionQueries,i.currentOcclusionQueryObjects=i.occlusionQueryObjects,i.lastOcclusionObject=null,i.occlusionQueries=Array(s),i.occlusionQueryObjects=Array(s),i.occlusionQueryIndex=0)}finishRender(e){let{gl:t,state:r}=this,i=this.get(e),s=i.previousContext;r.resetVertexState();let n=e.occlusionQueryCount;n>0&&(n>i.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));let a=e.textures;if(null!==a)for(let e=0;e<a.length;e++){let t=a[e];t.generateMipmaps&&this.generateMipmaps(t)}if(this._currentContext=s,null!==e.textures&&e.renderTarget){let i=this.get(e.renderTarget),{samples:s}=e.renderTarget;if(s>0&&!1===this._useMultisampledExtension(e.renderTarget)){let s=i.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT,a=i.msaaFrameBuffer,o=e.textures;r.bindFramebuffer(t.READ_FRAMEBUFFER,a),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,s);for(let r=0;r<o.length;r++)if(e.scissor){let{x:r,y:s,width:a,height:o}=e.scissorValue,l=e.height-o-s;t.blitFramebuffer(r,l,r+a,l+o,r,l,r+a,l+o,n,t.NEAREST),!0===this._supportsInvalidateFramebuffer&&t.invalidateSubFramebuffer(t.READ_FRAMEBUFFER,i.invalidationArray,r,l,a,o)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,n,t.NEAREST),!0===this._supportsInvalidateFramebuffer&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,i.invalidationArray)}}null!==s&&(this._setFramebuffer(s),s.viewport?this.updateViewport(s):r.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)),this.prepareTimestampBuffer(e)}resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueries:r,currentOcclusionQueryObjects:i}=t;if(r&&i){let e=new WeakSet,{gl:s}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;let n=()=>{let a=0;for(let t=0;t<r.length;t++){let n=r[t];null!==n&&s.getQueryParameter(n,s.QUERY_RESULT_AVAILABLE)&&(0===s.getQueryParameter(n,s.QUERY_RESULT)&&e.add(i[t]),r[t]=null,s.deleteQuery(n),a++)}a<r.length?requestAnimationFrame(n):t.occluded=e};n()}}isOccluded(e,t){let r=this.get(e);return r.occluded&&r.occluded.has(t)}updateViewport(e){let{state:t}=this,{x:r,y:i,width:s,height:n}=e.viewportValue;t.viewport(r,e.height-n-i,s,n)}setScissorTest(e){this.state.setScissorTest(e)}getClearColor(){let e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}
121clear(e,t,r,i=null,s=!0){let{gl:n,renderer:a}=this;null===i&&(i={textures:null,clearColorValue:this.getClearColor()});let o=0;if(e&&(o|=n.COLOR_BUFFER_BIT),t&&(o|=n.DEPTH_BUFFER_BIT),r&&(o|=n.STENCIL_BUFFER_BIT),0!==o){let l;l=i.clearColorValue?i.clearColorValue:this.getClearColor();let u=a.getClearDepth(),d=a.getClearStencil();if(t&&this.state.setDepthMask(!0),null===i.textures)n.clearColor(l.r,l.g,l.b,l.a),n.clear(o);else{if(s&&this._setFramebuffer(i),e)for(let e=0;e<i.textures.length;e++)0===e?n.clearBufferfv(n.COLOR,e,[l.r,l.g,l.b,l.a]):n.clearBufferfv(n.COLOR,e,[0,0,0,1]);t&&r?n.clearBufferfi(n.DEPTH_STENCIL,0,u,d):t?n.clearBufferfv(n.DEPTH,0,[u]):r&&n.clearBufferiv(n.STENCIL,0,[d])}}}beginCompute(e){let{state:t,gl:r}=this;t.bindFramebuffer(r.FRAMEBUFFER,null),this.initTimestampQuery(e)}compute(e,t,r,i){let{state:s,gl:n}=this;!1===this.discard&&(n.enable(n.RASTERIZER_DISCARD),this.discard=!0);let{programGPU:a,transformBuffers:o,attributes:l}=this.get(i),u=this._getVaoKey(l),d=this.vaoCache[u];void 0===d?this._createVao(l):s.setVertexState(d),s.useProgram(a),this._bindUniforms(r);let h=this._getTransformFeedback(o);n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,h),n.beginTransformFeedback(n.POINTS),l[0].isStorageInstancedBufferAttribute?n.drawArraysInstanced(n.POINTS,0,1,t.count):n.drawArrays(n.POINTS,0,t.count),n.endTransformFeedback(),n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,null);for(let e=0;e<o.length;e++){let t=o[e];t.pbo&&this.textureUtils.copyBufferToTexture(t.transformBuffer,t.pbo),t.switchBuffers()}}finishCompute(e){let t=this.gl;this.discard=!1,t.disable(t.RASTERIZER_DISCARD),this.prepareTimestampBuffer(e),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isDepthArrayTexture&&e.camera.isArrayCamera}draw(e){let{object:t,pipeline:r,material:i,context:s,hardwareClippingPlanes:n}=e,{programGPU:a}=this.get(r),{gl:o,state:l}=this,d=this.get(s),h=e.getDrawParameters();if(null===h)return;this._bindUniforms(e.getBindings());let c=t.isMesh&&0>t.matrixWorld.determinant();l.setMaterial(i,c,n),l.useProgram(a);let p=this.get(e),g=p.staticVao;if(void 0===g||p.geometryId!==e.geometry.id){let t=this._getVaoKey(e.getAttributes());if(void 0===(g=this.vaoCache[t])){let t;({vaoGPU:g,staticVao:t}=this._createVao(e.getAttributes())),t&&(p.staticVao=g,p.geometryId=e.geometry.id)}}let m=e.getIndex(),f=null!==m?this.get(m).bufferGPU:null;l.setVertexState(g,f);let y=d.lastOcclusionObject;if(y!==t&&void 0!==y){if(null!==y&&!0===y.occlusionTest&&(o.endQuery(o.ANY_SAMPLES_PASSED),d.occlusionQueryIndex++),!0===t.occlusionTest){let e=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,e),d.occlusionQueries[d.occlusionQueryIndex]=e,d.occlusionQueryObjects[d.occlusionQueryIndex]=t}d.lastOcclusionObject=t}let x=this.bufferRenderer;t.isPoints?x.mode=o.POINTS:t.isLineSegments?x.mode=o.LINES:t.isLine?x.mode=o.LINE_STRIP:t.isLineLoop?x.mode=o.LINE_LOOP:!0===i.wireframe?(l.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),x.mode=o.LINES):x.mode=o.TRIANGLES;let{vertexCount:b,instanceCount:T}=h,{firstVertex:_}=h;if(x.object=t,null!==m){_*=m.array.BYTES_PER_ELEMENT;let e=this.get(m);x.index=m.count,x.type=e.type}else x.index=0;let v=()=>{t.isBatchedMesh?null!==t._multiDrawInstances?((0,u.mcG)("THREE.WebGLBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),x.renderMultiDrawInstances(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount,t._multiDrawInstances)):this.hasFeature("WEBGL_multi_draw")?x.renderMultiDraw(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount):(0,u.mcG)("THREE.WebGLRenderer: WEBGL_multi_draw not supported."):T>1?x.renderInstances(_,b,T):x.render(_,b)};if(!0===e.camera.isArrayCamera&&e.camera.cameras.length>0&&!1===e.camera.isMultiViewCamera){let r=this.get(e.camera),i=e.camera.cameras,s=e.getBindingGroup("cameraIndex").bindings[0];if(void 0===r.indexesGPU||r.indexesGPU.length!==i.length){let e=new Uint32Array([0,0,0,0]),t=[];for(let r=0,s=i.length;r<s;r++){let i=o.createBuffer();e[0]=r,o.bindBuffer(o.UNIFORM_BUFFER,i),o.bufferData(o.UNIFORM_BUFFER,e,o.STATIC_DRAW),t.push(i)}r.indexesGPU=t}let n=this.get(s),a=this.renderer.getPixelRatio(),u=this._currentContext.renderTarget,d=this._isRenderCameraDepthArray(this._currentContext),h=this._currentContext.activeCubeFace;if(d){let e=this.get(u.depthTexture);if(e.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){e.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;let{stencilBuffer:t}=u;for(let e=0,r=i.length;e<r;e++)this.renderer._activeCubeFace=e,this._currentContext.activeCubeFace=e,this._setFramebuffer(this._currentContext),this.clear(!1,!0,t,this._currentContext,!1);this.renderer._activeCubeFace=h,this._currentContext.activeCubeFace=h}}for(let s=0,u=i.length;s<u;s++){let u=i[s];
121if(t.layers.test(u.layers)){d&&(this.renderer._activeCubeFace=s,this._currentContext.activeCubeFace=s,this._setFramebuffer(this._currentContext));let t=u.viewport;if(void 0!==t){let r=t.x*a,i=t.y*a,s=t.width*a,n=t.height*a;l.viewport(Math.floor(r),Math.floor(e.context.height-n-i),Math.floor(s),Math.floor(n))}l.bindBufferBase(o.UNIFORM_BUFFER,n.index,r.indexesGPU[s]),v()}this._currentContext.activeCubeFace=h,this.renderer._activeCubeFace=h}}else v()}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}async copyTextureToBuffer(e,t,r,i,s,n){return this.textureUtils.copyTextureToBuffer(e,t,r,i,s,n)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new mf(e,t)}createProgram(e){let t=this.gl,{stage:r,code:i}=e,s="fragment"===r?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(s,i),t.compileShader(s),this.set(e,{shaderGPU:s})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){let r=this.gl,i=e.pipeline,{fragmentProgram:s,vertexProgram:n}=i,a=r.createProgram(),o=this.get(s).shaderGPU,l=this.get(n).shaderGPU;if(r.attachShader(a,o),r.attachShader(a,l),r.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:o,vertexShader:l}),null!==t&&this.parallel){let s=new Promise(t=>{let s=this.parallel,n=()=>{r.getProgramParameter(a,s.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),t()):requestAnimationFrame(n)};n()});t.push(s);return}this._completeCompile(e,i)}_handleSource(e,t){let r=e.split("\n"),i=[],s=Math.max(t-6,0),n=Math.min(t+6,r.length);for(let e=s;e<n;e++){let s=e+1;i.push(`${s===t?">":" "} ${s}: ${r[e]}`)}return i.join("\n")}_getShaderErrors(e,t,r){let i=e.getShaderParameter(t,e.COMPILE_STATUS),s=e.getShaderInfoLog(t).trim();if(i&&""===s)return"";let n=/ERROR: 0:(\d+)/.exec(s);if(!n)return s;{let i=parseInt(n[1]);return r.toUpperCase()+"\n\n"+s+"\n\n"+this._handleSource(e.getShaderSource(t),i)}}_logProgramError(e,t,r){if(this.renderer.debug.checkShaderErrors){let i=this.gl,s=i.getProgramInfoLog(e).trim();if(!1===i.getProgramParameter(e,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,e,r,t);else{let n=this._getShaderErrors(i,r,"vertex"),a=this._getShaderErrors(i,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(e,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+s+"\n"+n+"\n"+a)}else""!==s&&console.warn("THREE.WebGLProgram: Program Info Log:",s)}}_completeCompile(e,t){let{state:r,gl:i}=this,{programGPU:s,fragmentShader:n,vertexShader:a}=this.get(t);!1===i.getProgramParameter(s,i.LINK_STATUS)&&this._logProgramError(s,n,a),r.useProgram(s);let o=e.getBindings();this._setupBindings(o,s),this.set(t,{programGPU:s})}createComputePipeline(e,t){let{state:r,gl:i}=this,s={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(s);let{computeProgram:n}=e,a=i.createProgram(),o=this.get(s).shaderGPU,l=this.get(n).shaderGPU,u=n.transforms,d=[],h=[];for(let e=0;e<u.length;e++){let t=u[e];d.push(t.varyingName),h.push(t.attributeNode)}i.attachShader(a,o),i.attachShader(a,l),i.transformFeedbackVaryings(a,d,i.SEPARATE_ATTRIBS),i.linkProgram(a),!1===i.getProgramParameter(a,i.LINK_STATUS)&&this._logProgramError(a,o,l),r.useProgram(a),this._setupBindings(t,a);let c=n.attributes,p=[],g=[];for(let e=0;e<c.length;e++){let t=c[e].node.attribute;p.push(t),this.has(t)||this.attributeUtils.createAttribute(t,i.ARRAY_BUFFER)}for(let e=0;e<h.length;e++){let t=h[e].attribute;this.has(t)||this.attributeUtils.createAttribute(t,i.ARRAY_BUFFER);let r=this.get(t);g.push(r)}this.set(e,{programGPU:a,transformBuffers:g,attributes:p})}createBindings(e,t){if(!1===this._knownBindings.has(t)){this._knownBindings.add(t);let e=0,r=0;for(let i of t)for(let t of(this.set(i,{textures:r,uniformBuffers:e}),i.bindings))t.isUniformBuffer&&e++,t.isSampledTexture&&r++}this.updateBindings(e,t)}updateBindings(e){let{gl:t}=this,r=this.get(e),i=r.uniformBuffers,s=r.textures;for(let r of e.bindings)if(r.isUniformsGroup||r.isUniformBuffer){let e=r.buffer,s=t.createBuffer();t.bindBuffer(t.UNIFORM_BUFFER,s),t.bufferData(t.UNIFORM_BUFFER,e,t.DYNAMIC_DRAW),this.set(r,{index:i++,bufferGPU:s})}else if(r.isSampledTexture){let{textureGPU:e,glTextureType:t}=this.get(r.texture);this.set(r,{index:s++,textureGPU:e,glTextureType:t})}}updateBinding(e){let t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){let r=this.get(e).bufferGPU,i=e.buffer;t.bindBuffer(t.UNIFORM_BUFFER,r),t.bufferData(t.UNIFORM_BUFFER,i,t.DYNAMIC_DRAW)}}createIndexAttribute(e){let t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){let t=Object.keys(mP).filter(t=>mP[t]===e),r=this.extensions;for(let e=0;e<t.length;e++)if(r.has(t[e]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}
121copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){this.textureUtils.copyTextureToTexture(e,t,r,i,s,n)}copyFramebufferToTexture(e,t,r){this.textureUtils.copyFramebufferToTexture(e,t,r)}_setFramebuffer(e){let{gl:t,state:r}=this,i=null;if(null!==e.textures){let s,n=e.renderTarget,a=this.get(n),{samples:o,depthBuffer:l,stencilBuffer:u}=n,d=!0===n.isWebGLCubeRenderTarget,h=!0===n.isRenderTarget3D,c=!0===n.isRenderTargetArray,p=!0===n.isXRRenderTarget,g=!0===p&&!0===n.hasExternalTextures,m=a.msaaFrameBuffer,f=a.depthRenderbuffer,y=this.extensions.get("WEBGL_multisampled_render_to_texture"),x=this.extensions.get("OVR_multiview2"),b=this._useMultisampledExtension(n),T=u3(e);if(d?(a.cubeFramebuffers||(a.cubeFramebuffers={}),s=a.cubeFramebuffers[T]):p&&!1===g?s=this._xrFramebuffer:(a.framebuffers||(a.framebuffers={}),s=a.framebuffers[T]),void 0===s){s=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,s);let i=e.textures;if(d){a.cubeFramebuffers[T]=s;let{textureGPU:e}=this.get(i[0]),r=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+r,e,0)}else{a.framebuffers[T]=s;for(let r=0;r<i.length;r++){let s=i[r],a=this.get(s);a.renderTarget=e.renderTarget,a.cacheKey=T;let l=t.COLOR_ATTACHMENT0+r;if(h||c){let e=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,l,a.textureGPU,0,e)}else n.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,l,a.textureGPU,0,o,0,2):g&&b?y.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,t.TEXTURE_2D,a.textureGPU,0,o):t.framebufferTexture2D(t.FRAMEBUFFER,l,t.TEXTURE_2D,a.textureGPU,0)}
121r.drawBuffers(e,s)}if(n.isXRRenderTarget&&!0===n.autoAllocateDepthBuffer){let r=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(r,e,0,b),a.xrDepthRenderbuffer=r}else if(null!==e.depthTexture){let r=this.get(e.depthTexture),i=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(r.renderTarget=e.renderTarget,r.cacheKey=T,n.multiview)x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,i,r.textureGPU,0,o,0,2);else if(g&&b)y.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,i,t.TEXTURE_2D,r.textureGPU,0,o);else if(e.depthTexture.isDepthArrayTexture){let e=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,i,r.textureGPU,0,e)}else t.framebufferTexture2D(t.FRAMEBUFFER,i,t.TEXTURE_2D,r.textureGPU,0)}}else{if(this._isRenderCameraDepthArray(e)){r.bindFramebuffer(t.FRAMEBUFFER,s);let i=this.renderer._activeCubeFace,n=this.get(e.depthTexture),a=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,a,n.textureGPU,0,i)}if(p&&g||n.multiview){r.bindFramebuffer(t.FRAMEBUFFER,s);let i=this.get(e.textures[0]);n.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,i.textureGPU,0,o,0,2):b?y.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i.textureGPU,0,o):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i.textureGPU,0);let l=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(!0===n.autoAllocateDepthBuffer){let e=a.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,e),t.framebufferRenderbuffer(t.FRAMEBUFFER,l,t.RENDERBUFFER,e)}else{let r=this.get(e.depthTexture);n.multiview?x.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,l,r.textureGPU,0,o,0,2):b?y.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,t.TEXTURE_2D,r.textureGPU,0,o):t.framebufferTexture2D(t.FRAMEBUFFER,l,t.TEXTURE_2D,r.textureGPU,0)}}}if(o>0&&!1===b&&!n.multiview){if(void 0===m){let i=[];m=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,m);let s=[],n=e.textures;for(let r=0;r<n.length;r++){if(s[r]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,s[r]),i.push(t.COLOR_ATTACHMENT0+r),l){let e=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;i.push(e)}let n=e.textures[r],a=this.get(n);t.renderbufferStorageMultisample(t.RENDERBUFFER,o,a.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+r,t.RENDERBUFFER,s[r])}if(a.msaaFrameBuffer=m,a.msaaRenderbuffers=s,void 0===f){f=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(f,e,o),a.depthRenderbuffer=f;let r=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;i.push(r)}a.invalidationArray=i}i=a.msaaFrameBuffer}else i=s}r.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e){let t="";for(let r=0;r<e.length;r++)t+=":"+this.get(e[r]).id;return t}_createVao(e){let{gl:t}=this,r=t.createVertexArray(),i="",s=!0;
121t.bindVertexArray(r);for(let r=0;r<e.length;r++){let n,a,o=e[r],l=this.get(o);i+=":"+l.id,t.bindBuffer(t.ARRAY_BUFFER,l.bufferGPU),t.enableVertexAttribArray(r),(o.isStorageBufferAttribute||o.isStorageInstancedBufferAttribute)&&(s=!1),!0===o.isInterleavedBufferAttribute?(n=o.data.stride*l.bytesPerElement,a=o.offset*l.bytesPerElement):(n=0,a=0),l.isInteger?t.vertexAttribIPointer(r,o.itemSize,l.type,n,a):t.vertexAttribPointer(r,o.itemSize,l.type,o.normalized,n,a),o.isInstancedBufferAttribute&&!o.isInterleavedBufferAttribute?t.vertexAttribDivisor(r,o.meshPerAttribute):o.isInterleavedBufferAttribute&&o.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(r,o.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),this.vaoCache[i]=r,{vaoGPU:r,staticVao:s}}_getTransformFeedback(e){let t="";for(let r=0;r<e.length;r++)t+=":"+e[r].id;let r=this.transformFeedbackCache[t];if(void 0!==r)return r;let{gl:i}=this;r=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,r);for(let t=0;t<e.length;t++){let r=e[t];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,t,r.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=r,r}_setupBindings(e,t){let r=this.gl;for(let i of e)for(let e of i.bindings){let i=this.get(e).index;if(e.isUniformsGroup||e.isUniformBuffer){let s=r.getUniformBlockIndex(t,e.name);r.uniformBlockBinding(t,s,i)}else if(e.isSampledTexture){let s=r.getUniformLocation(t,e.name);r.uniform1i(s,i)}}}_bindUniforms(e){let{gl:t,state:r}=this;for(let i of e)for(let e of i.bindings){let i=this.get(e),s=i.index;e.isUniformsGroup||e.isUniformBuffer?r.bindBufferBase(t.UNIFORM_BUFFER,s,i.bufferGPU):e.isSampledTexture&&r.bindTexture(i.glTextureType,i.textureGPU,t.TEXTURE0+s)}}_useMultisampledExtension(e){return!0===e.multiview||e.samples>0&&!0===this.extensions.has("WEBGL_multisampled_render_to_texture")&&!1!==e.autoAllocateDepthBuffer}dispose(){let e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}let mD={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list",TriangleStrip:"triangle-strip"},mV={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},mO={Store:"store"},mG={Load:"load",Clear:"clear"},mk={CCW:"ccw"},mz={None:"none",Front:"front",Back:"back"},m$={Uint16:"uint16",Uint32:"uint32"},mW={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10UFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},mH={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},mq={Linear:"linear",Nearest:"nearest"},mj={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDstColor:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},mX={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},mQ={None:0,All:15},mY={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},mK={Storage:"storage",ReadOnlyStorage:"read-only-storage"},mZ={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},mJ={NonFiltering:"non-filtering",Comparison:"comparison"},m0={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},m1={TwoD:"2d",ThreeD:"3d"},m2={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},m3={All:"all"},m4={Vertex:"vertex",Instance:"instance"},m6={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class m8 extends g5{constructor(e,t){super(e),this.texture=t,this.version=t?t.version:0,this.isSampler=!0}}class m5 extends m8{constructor(e,t,r){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r}update(){this.texture=this.textureNode.value}}class m9 extends g9{constructor(e,t){super(e,t?t.array:null),this.attribute=t,this.isStorageBuffer=!0}}let m7=0;class fe extends m9{constructor(e,t){super("StorageBuffer_"+m7++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:C.READ_WRITE,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class ft extends uU{constructor(e){super(),this.device=e;let t=`
122struct VarysStruct { 123 @builtin( position ) Position: vec4<f32>, 124 @location( 0 ) vTex : vec2<f32> 125}; 126 127@vertex 128fn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct { 129 130 var Varys : VarysStruct; 131 132 var pos = array< vec2<f32>, 4 >( 133 vec2<f32>( -1.0, 1.0 ), 134 vec2<f32>( 1.0, 1.0 ), 135 vec2<f32>( -1.0, -1.0 ), 136 vec2<f32>( 1.0, -1.0 ) 137 ); 138 139 var tex = array< vec2<f32>, 4 >( 140 vec2<f32>( 0.0, 0.0 ), 141 vec2<f32>( 1.0, 0.0 ), 142 vec2<f32>( 0.0, 1.0 ), 143 vec2<f32>( 1.0, 1.0 ) 144 ); 145 146 Varys.vTex = tex[ vertexIndex ]; 147 Varys.Position = vec4<f32>( pos[ vertexIndex ], 0.0, 1.0 ); 148 149 return Varys; 150 151} 152`,r=` 153@group( 0 ) @binding( 0 ) 154var imgSampler : sampler; 155 156@group( 0 ) @binding( 1 ) 157var img : texture_2d<f32>; 158 159@fragment 160fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> { 161 162 return textureSample( img, imgSampler, vTex ); 163 164} 165`,i=` 166@group( 0 ) @binding( 0 ) 167var imgSampler : sampler; 168 169@group( 0 ) @binding( 1 ) 170var img : texture_2d<f32>; 171 172@fragment 173fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> { 174 175 return textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) ); 176 177} 178`;this.mipmapSampler=e.createSampler({minFilter:mq.Linear}),this.flipYSampler=e.createSampler({minFilter:mq.Nearest}),this.transferPipelines={},this.flipYPipelines={},this.mipmapVertexShaderModule=e.createShaderModule({label:"mipmapVertex",code:t}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:r}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:i})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:mD.TriangleStrip,stripIndexFormat:m$.Uint32},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:mD.TriangleStrip,stripIndexFormat:m$.Uint32},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,r=0){let i=t.format,{width:s,height:n}=t.size,a=this.getTransferPipeline(i),o=this.getFlipYPipeline(i),l=this.device.createTexture({size:{width:s,height:n,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),u=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:m2.TwoD,baseArrayLayer:r}),d=l.createView({baseMipLevel:0,mipLevelCount:1,dimension:m2.TwoD,baseArrayLayer:0}),h=this.device.createCommandEncoder({}),c=(e,t,r)=>{let i=e.getBindGroupLayout(0),s=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),n=h.beginRenderPass({colorAttachments:[{view:r,loadOp:mG.Clear,storeOp:mO.Store,clearValue:[0,0,0,0]}]});n.setPipeline(e),n.setBindGroup(0,s),n.draw(4,1,0,0),n.end()};c(a,u,d),c(o,d,u),this.device.queue.submit([h.finish()]),l.destroy()}generateMipmaps(e,t,r=0){let i=this.get(e);void 0===i.useCount&&(i.useCount=0,i.layers=[]);let s=i.layers[r]||this._mipmapCreateBundles(e,t,r),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,s),this.device.queue.submit([n.finish()]),0!==i.useCount&&(i.layers[r]=s),i.useCount++}_mipmapCreateBundles(e,t,r){let i=this.getTransferPipeline(t.format),s=i.getBindGroupLayout(0),n=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:m2.TwoD,baseArrayLayer:r}),a=[];for(let o=1;o<t.mipLevelCount;o++){let l=this.device.createBindGroup({layout:s,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:n}]}),u=e.createView({baseMipLevel:o,mipLevelCount:1,dimension:m2.TwoD,baseArrayLayer:r}),d={colorAttachments:[{view:u,loadOp:mG.Clear,storeOp:mO.Store,clearValue:[0,0,0,0]}]},h=this.device.createRenderBundleEncoder({colorFormats:[t.format]});h.setPipeline(i),h.setBindGroup(0,l),h.draw(4,1,0,0),a.push({renderBundles:[h.finish()],passDescriptor:d}),n=u}return a}_mipmapRunBundles(e,t){let r=t.length;for(let i=0;i<r;i++){let r=t[i],s=e.beginRenderPass(r.passDescriptor);s.executeBundles(r.renderBundles),s.end()}}}let fr={[u.amv]:"never",[u.vim]:"less",[u.kO0]:"equal",[u.TiK]:"less-equal",[u.eoi]:"greater",[u.gWB]:"greater-equal",[u.FFZ]:"always",[u.jzd]:"not-equal"},fi=[0,1,3,2,4,5];class fs{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new u.VCu,this.depthTexture.name="depthBuffer"}createSampler(e){let t=this.backend,r=t.device,i=t.get(e),s={addressModeU:this._convertAddressMode(e.wrapS),addressModeV:this._convertAddressMode(e.wrapT),addressModeW:this._convertAddressMode(e.wrapR),magFilter:this._convertFilterMode(e.magFilter),minFilter:this._convertFilterMode(e.minFilter),mipmapFilter:this._convertFilterMode(e.minFilter),maxAnisotropy:1};s.magFilter===mq.Linear&&s.minFilter===mq.Linear&&s.mipmapFilter===mq.Linear&&(s.maxAnisotropy=e.anisotropy),e.isDepthTexture&&null!==e.compareFunction&&(s.compare=fr[e.compareFunction]),i.sampler=r.createSampler(s)}createDefaultTexture(e){let t,r=fn(e);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(r):e.isVideoTexture?this.backend.get(e).externalTexture=this._getDefaultVideoFrame():t=this._getDefaultTextureGPU(r),this.backend.get(e).texture=t}
178createTexture(e,t={}){let r=this.backend,i=r.get(e);if(i.initialized)throw Error("WebGPUTextureUtils: Texture already initialized.");void 0===t.needsMipmaps&&(t.needsMipmaps=!1),void 0===t.levels&&(t.levels=1),void 0===t.depth&&(t.depth=1);let{width:s,height:n,depth:a,levels:o}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());let l=this._getDimension(e),u=e.internalFormat||t.format||fn(e,r.device);i.format=u;let{samples:d,primarySamples:h,isMSAA:c}=r.utils.getTextureSampleData(e),p=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===e.isStorageTexture&&(p|=GPUTextureUsage.STORAGE_BINDING),!0!==e.isCompressedTexture&&!0!==e.isCompressedArrayTexture&&(p|=GPUTextureUsage.RENDER_ATTACHMENT);let g={label:e.name,size:{width:s,height:n,depthOrArrayLayers:a},mipLevelCount:o,sampleCount:h,dimension:l,format:u,usage:p};if(e.isVideoTexture){let t=e.source.data,r=new VideoFrame(t);g.size.width=r.displayWidth,g.size.height=r.displayHeight,r.close(),i.externalTexture=t}else{if(void 0===u){console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);return}e.isCubeTexture&&(g.textureBindingViewDimension=m2.Cube),i.texture=r.device.createTexture(g)}if(c){let e=Object.assign({},g);e.label=e.label+"-msaa",e.sampleCount=d,i.msaaTexture=r.device.createTexture(e)}i.initialized=!0,i.textureDescriptorGPU=g}destroyTexture(e){let t=this.backend,r=t.get(e);void 0!==r.texture&&r.texture.destroy(),void 0!==r.msaaTexture&&r.msaaTexture.destroy(),t.delete(e)}destroySampler(e){let t=this.backend.get(e);delete t.sampler}generateMipmaps(e){let t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{let r=e.image.depth||1;for(let e=0;e<r;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e)}}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();let e=this.backend,{width:t,height:r}=e.getDrawingBufferSize();return this.colorBuffer=e.device.createTexture({label:"colorBuffer",size:{width:t,height:r,depthOrArrayLayers:1},sampleCount:e.utils.getSampleCount(e.renderer.samples),format:e.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(e=!0,t=!1){let r,i,s=this.backend,{width:n,height:a}=s.getDrawingBufferSize(),o=this.depthTexture,l=s.get(o).texture;if(t?(r=u.dcC,i=u.V3x):e&&(r=u.zdS,i=u.bkx),void 0!==l){if(o.image.width===n&&o.image.height===a&&o.format===r&&o.type===i)return l;this.destroyTexture(o)}return o.name="depthBuffer",o.format=r,o.type=i,o.image.width=n,o.image.height=a,this.createTexture(o,{width:n,height:a}),s.get(o).texture}updateTexture(e,t){let r=this.backend.get(e),{textureDescriptorGPU:i}=r;if(!e.isRenderTargetTexture&&void 0!==i){if(e.isDataTexture)this._copyBufferToTexture(t.image,r.texture,i,0,e.flipY);else if(e.isDataArrayTexture||e.isDepthArrayTexture||e.isData3DTexture)for(let s=0;s<t.image.depth;s++)this._copyBufferToTexture(t.image,r.texture,i,s,e.flipY,s);else e.isCompressedTexture||e.isCompressedArrayTexture?this._copyCompressedBufferToTexture(e.mipmaps,r.texture,i):e.isCubeTexture?this._copyCubeMapToTexture(t.images,r.texture,i,e.flipY):e.isVideoTexture?r.externalTexture=e.source.data:this._copyImageToTexture(t.image,r.texture,i,0,e.flipY);r.version=e.version,e.onUpdate&&e.onUpdate(e)}}async copyTextureToBuffer(e,t,r,i,s,n){let a=this.backend.device,o=this.backend.get(e),l=o.texture,u=o.textureDescriptorGPU.format,d=this._getBytesPerTexel(u),h=i*d;h=256*Math.ceil(h/256);let c=a.createBuffer({size:i*s*d,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=a.createCommandEncoder();p.copyTextureToBuffer({texture:l,origin:{x:t,y:r,z:n}},{buffer:c,bytesPerRow:h},{width:i,height:s});let g=this._getTypedArrayType(u);return a.queue.submit([p.finish()]),await c.mapAsync(GPUMapMode.READ),new g(c.getMappedRange())}_isEnvironmentTexture(e){let t=e.mapping;return t===u.wfO||t===u.uV5||t===u.hy7||t===u.xFO}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){let r=new u.gPd;r.minFilter=u.hxR,r.magFilter=u.hxR,this.createTexture(r,{width:1,height:1,format:e}),this.defaultTexture[e]=t=r}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){let r=new u.b4q;r.minFilter=u.hxR,r.magFilter=u.hxR,this.createTexture(r,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=r}return this.backend.get(t).texture}_getDefaultVideoFrame(){let e=this.defaultVideoFrame;
178return null===e&&(this.defaultVideoFrame=e=new VideoFrame(new Uint8Array([0,0,0,255]),{timestamp:0,codedWidth:1,codedHeight:1,format:"RGBA"})),e}_copyCubeMapToTexture(e,t,r,i){for(let s=0;s<6;s++){let n=e[s],a=!0===i?fi[s]:s;n.isDataTexture?this._copyBufferToTexture(n.image,t,r,a,i):this._copyImageToTexture(n,t,r,a,i)}}_copyImageToTexture(e,t,r,i,s){this.backend.device.queue.copyExternalImageToTexture({source:e,flipY:s},{texture:t,mipLevel:0,origin:{x:0,y:0,z:i}},{width:e.width,height:e.height,depthOrArrayLayers:1})}_getPassUtils(){let e=this._passUtils;return null===e&&(this._passUtils=e=new ft(this.backend.device)),e}_generateMipmaps(e,t,r=0){this._getPassUtils().generateMipmaps(e,t,r)}_flipY(e,t,r=0){this._getPassUtils().flipY(e,t,r)}_copyBufferToTexture(e,t,r,i,s,n=0){let a=this.backend.device,o=e.data,l=this._getBytesPerTexel(r.format),u=e.width*l;a.queue.writeTexture({texture:t,mipLevel:0,origin:{x:0,y:0,z:i}},o,{offset:e.width*e.height*l*n,bytesPerRow:u},{width:e.width,height:e.height,depthOrArrayLayers:1}),!0===s&&this._flipY(t,r,i)}_copyCompressedBufferToTexture(e,t,r){let i=this.backend.device,s=this._getBlockData(r.format),n=r.size.depthOrArrayLayers>1;for(let a=0;a<e.length;a++){let o=e[a],l=o.width,u=o.height,d=n?r.size.depthOrArrayLayers:1,h=Math.ceil(l/s.width)*s.byteLength,c=h*Math.ceil(u/s.height);for(let e=0;e<d;e++)i.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:e}},o.data,{offset:e*c,bytesPerRow:h,rowsPerImage:Math.ceil(u/s.height)},{width:Math.ceil(l/s.width)*s.width,height:Math.ceil(u/s.height)*s.height,depthOrArrayLayers:1})}}_getBlockData(e){return e===mW.BC1RGBAUnorm||e===mW.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:e===mW.BC2RGBAUnorm||e===mW.BC2RGBAUnormSRGB||e===mW.BC3RGBAUnorm||e===mW.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===mW.BC4RUnorm||e===mW.BC4RSnorm?{byteLength:8,width:4,height:4}:e===mW.BC5RGUnorm||e===mW.BC5RGSnorm||e===mW.BC6HRGBUFloat||e===mW.BC6HRGBFloat||e===mW.BC7RGBAUnorm||e===mW.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===mW.ETC2RGB8Unorm||e===mW.ETC2RGB8UnormSRGB||e===mW.ETC2RGB8A1Unorm||e===mW.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:e===mW.ETC2RGBA8Unorm||e===mW.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:e===mW.EACR11Unorm||e===mW.EACR11Snorm?{byteLength:8,width:4,height:4}:e===mW.EACRG11Unorm||e===mW.EACRG11Snorm||e===mW.ASTC4x4Unorm||e===mW.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:e===mW.ASTC5x4Unorm||e===mW.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:e===mW.ASTC5x5Unorm||e===mW.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:e===mW.ASTC6x5Unorm||e===mW.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:e===mW.ASTC6x6Unorm||e===mW.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:e===mW.ASTC8x5Unorm||e===mW.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:e===mW.ASTC8x6Unorm||e===mW.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:e===mW.ASTC8x8Unorm||e===mW.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:e===mW.ASTC10x5Unorm||e===mW.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:e===mW.ASTC10x6Unorm||e===mW.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:e===mW.ASTC10x8Unorm||e===mW.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:e===mW.ASTC10x10Unorm||e===mW.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:e===mW.ASTC12x10Unorm||e===mW.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:e===mW.ASTC12x12Unorm||e===mW.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(e){let t=mH.ClampToEdge;return e===u.GJx?t=mH.Repeat:e===u.kTW&&(t=mH.MirrorRepeat),t}_convertFilterMode(e){let t=mq.Linear;return(e===u.hxR||e===u.pHI||e===u.Cfg)&&(t=mq.Nearest),t}_getBytesPerTexel(e){return e===mW.R8Unorm||e===mW.R8Snorm||e===mW.R8Uint||e===mW.R8Sint?1:e===mW.R16Uint||e===mW.R16Sint||e===mW.R16Float||e===mW.RG8Unorm||e===mW.RG8Snorm||e===mW.RG8Uint||e===mW.RG8Sint?2:e===mW.R32Uint||e===mW.R32Sint||e===mW.R32Float||e===mW.RG16Uint||e===mW.RG16Sint||e===mW.RG16Float||e===mW.RGBA8Unorm||e===mW.RGBA8UnormSRGB||e===mW.RGBA8Snorm||e===mW.RGBA8Uint||e===mW.RGBA8Sint||e===mW.BGRA8Unorm||e===mW.BGRA8UnormSRGB||e===mW.RGB9E5UFloat||e===mW.RGB10A2Unorm||e===mW.RG11B10UFloat||e===mW.Depth32Float||e===mW.Depth24Plus||e===mW.Depth24PlusStencil8||e===mW.Depth32FloatStencil8?4:e===mW.RG32Uint||e===mW.RG32Sint||e===mW.RG32Float||e===mW.RGBA16Uint||e===mW.RGBA16Sint||e===mW.RGBA16Float?8:e===mW.RGBA32Uint||e===mW.RGBA32Sint||e===mW.RGBA32Float?16:void 0}_getTypedArrayType(e){return e===mW.R8Uint?Uint8Array:e===mW.R8Sint?Int8Array:e===mW.R8Unorm?Uint8Array:e===mW.R8Snorm?Int8Array:e===mW.RG8Uint?Uint8Array:e===mW.RG8Sint?Int8Array:e===mW.RG8Unorm?Uint8Array:e===mW.RG8Snorm?Int8Array:e===mW.RGBA8Uint?Uint8Array:e===mW.RGBA8Sint?Int8Array:e===mW.RGBA8Unorm?Uint8Array:e===mW.RGBA8Snorm?Int8Array:e===mW.R16Uint?Uint16Array:e===mW.R16Sint?Int16Array:e===mW.RG16Uint?Uint16Array:e===mW.RG16Sint?Int16Array:e===mW.RGBA16Uint?Uint16Array:e===mW.RGBA16Sint?Int16Array:e===mW.R16Float||e===mW.RG16Float||e===mW.RGBA16Float?Uint16Array:e===mW.R32Uint?Uint32Array:e===mW.R32Sint?Int32Array:e===mW.R32Float?Float32Array:e===mW.RG32Uint?Uint32Array:e===mW.RG32Sint?Int32Array:e===mW.RG32Float?Float32Array:e===mW.RGBA32Uint?Uint32Array:e===mW.RGBA32Sint?Int32Array:e===mW.RGBA32Float?Float32Array:e===mW.BGRA8Unorm||e===mW.BGRA8UnormSRGB?Uint8Array:e===mW.RGB10A2Unorm||e===mW.RGB9E5UFloat||e===mW.RG11B10UFloat?Uint32Array:e===mW.Depth32Float?Float32Array:e===mW.Depth24Plus||e===mW.Depth24PlusStencil8?Uint32Array:e===mW.Depth32FloatStencil8?Float32Array:void 0}_getDimension(e){return e.isData3DTexture?m1.ThreeD:m1.TwoD}}function fn(e,t=null){let r,i=e.format,s=e.type,n=e.colorSpace;if(!0===e.isCompressedTexture||!0===e.isCompressedArrayTexture)switch(i){case u.Nz6:r=n===u.er$?mW.BC1RGBAUnormSRGB:mW.BC1RGBAUnorm;break;case u.jR7:r=n===u.er$?mW.BC2RGBAUnormSRGB:mW.BC2RGBAUnorm;break;case u.BXX:r=n===u.er$?mW.BC3RGBAUnormSRGB:mW.BC3RGBAUnorm;break;case u.Riy:r=n===u.er$?mW.ETC2RGB8UnormSRGB:mW.ETC2RGB8Unorm;break;case u.KDk:r=n===u.er$?mW.ETC2RGBA8UnormSRGB:mW.ETC2RGBA8Unorm;break;case u.qa3:r=n===u.er$?mW.ASTC4x4UnormSRGB:mW.ASTC4x4Unorm;break;case u.B_h:r=n===u.er$?mW.ASTC5x4UnormSRGB:mW.ASTC5x4Unorm;break;case u.czI:r=n===u.er$?mW.ASTC5x5UnormSRGB:mW.ASTC5x5Unorm;break;case u.rSH:r=n===u.er$?mW.ASTC6x5UnormSRGB:mW.ASTC6x5Unorm;break;case u.Qrf:r=n===u.er$?mW.ASTC6x6UnormSRGB:mW.ASTC6x6Unorm;break;case u.psI:r=n===u.er$?mW.ASTC8x5UnormSRGB:mW.ASTC8x5Unorm;break;case u.a5J:r=n===u.er$?mW.ASTC8x6UnormSRGB:mW.ASTC8x6Unorm;break;case u._QJ:r=n===u.er$?mW.ASTC8x8UnormSRGB:mW.ASTC8x8Unorm;break;case u.uB5:r=n===u.er$?mW.ASTC10x5UnormSRGB:mW.ASTC10x5Unorm;break;case u.lyL:r=n===u.er$?mW.ASTC10x6UnormSRGB:mW.ASTC10x6Unorm;break;case u.bC7:r=n===u.er$?mW.ASTC10x8UnormSRGB:mW.ASTC10x8Unorm;break;case u.y3Z:r=n===u.er$?mW.ASTC10x10UnormSRGB:mW.ASTC10x10Unorm;break;case u.ojs:r=n===u.er$?mW.ASTC12x10UnormSRGB:mW.ASTC12x10Unorm;break;case u.S$4:r=n===u.er$?mW.ASTC12x12UnormSRGB:mW.ASTC12x12Unorm;break;case u.GWd:r=n===u.er$?mW.RGBA8UnormSRGB:mW.RGBA8Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",i)}else switch(i){case u.GWd:switch(s){case u.tJf:r=mW.RGBA8Snorm;break;case u.fBL:r=mW.RGBA16Sint;break;case u.cHt:r=mW.RGBA16Uint;break;case u.bkx:r=mW.RGBA32Uint;break;case u.Yuy:r=mW.RGBA32Sint;break;case u.OUM:r=n===u.er$?mW.RGBA8UnormSRGB:mW.RGBA8Unorm;break;case u.ix0:r=mW.RGBA16Float;break;case u.RQf:r=mW.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",s)}break;case u.HIg:s===u.Dmk?r=mW.RGB9E5UFloat:console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",s);break;case u.VT0:switch(s){case u.tJf:r=mW.R8Snorm;break;case u.fBL:r=mW.R16Sint;break;case u.cHt:r=mW.R16Uint;break;case u.bkx:r=mW.R32Uint;break;case u.Yuy:r=mW.R32Sint;break;case u.OUM:r=mW.R8Unorm;break;case u.ix0:r=mW.R16Float;break;case u.RQf:r=mW.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",s)}break;case u.paN:switch(s){case u.tJf:r=mW.RG8Snorm;break;case u.fBL:r=mW.RG16Sint;break;case u.cHt:r=mW.RG16Uint;break;case u.bkx:r=mW.RG32Uint;break;case u.Yuy:r=mW.RG32Sint;break;case u.OUM:r=mW.RG8Unorm;break;case u.ix0:r=mW.RG16Float;break;case u.RQf:r=mW.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",s)}break;case u.zdS:switch(s){case u.cHt:r=mW.Depth16Unorm;break;case u.bkx:r=mW.Depth24Plus;break;case u.RQf:r=mW.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",s)}break;case u.dcC:switch(s){case u.V3x:r=mW.Depth24PlusStencil8;break;case u.RQf:t&&!1===t.features.has(m6.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),r=mW.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",s)}break;case u.ZQM:switch(s){case u.Yuy:r=mW.R32Sint;break;case u.bkx:r=mW.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",s)}break;case u.TkQ:switch(s){case u.Yuy:r=mW.RG32Sint;break;case u.bkx:r=mW.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",s)}break;case u.c90:switch(s){case u.Yuy:r=mW.RGBA32Sint;break;case u.bkx:r=mW.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",s)}break;default:console.error("WebGPURenderer: Unsupported texture format.",i)}return r}let fa=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,fo=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,fl={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>
178":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class fu extends gN{constructor(e){let{type:t,inputs:r,name:i,inputsCode:s,blockCode:n,outputType:a}=(e=>{let t=(e=e.trim()).match(fa);if(null!==t&&4===t.length){let r=t[2],i=[],s=null;for(;null!==(s=fo.exec(r));)i.push({name:s[1],type:s[2]});let n=[];for(let e=0;e<i.length;e++){let{name:t,type:r}=i[e],s=r;s.startsWith("ptr")?s="pointer":(s.startsWith("texture")&&(s=r.split("<")[0]),s=fl[s]),n.push(new gc(s,t))}let a=e.substring(t[0].length),o=t[3]||"void",l=void 0!==t[1]?t[1]:"";
178return{type:fl[o]||o,inputs:n,name:l,inputsCode:r,blockCode:a,outputType:o}}throw Error("FunctionNode: Function is not a WGSL code.")})(e);super(t,r,i),this.inputsCode=s,this.blockCode=n,this.outputType=a}getCode(e=this.name){let t="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class fd extends gS{parseFunction(e){return new fu(e)}}let fh="undefined"!=typeof self?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},fc={[C.READ_ONLY]:"read",[C.WRITE_ONLY]:"write",[C.READ_WRITE]:"read_write"},fp={[u.GJx]:"repeat",[u.ghU]:"clamp",[u.kTW]:"mirror"},fg={vertex:fh?fh.VERTEX:1,fragment:fh?fh.FRAGMENT:2,compute:fh?fh.COMPUTE:4},fm={instance:!0,swizzleAssign:!1,storageBuffer:!0},ff={"^^":"tsl_xor"},fy={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},fx={},fb={tsl_xor:new hz("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new hz("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new hz("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new hz("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new hz("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new hz("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new hz("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new hz("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new hz("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new hz("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new hz("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new hz("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new hz(` 179fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f { 180 181 let res = vec2f( iRes ); 182 183 let uvScaled = coord * res; 184 let uvWrapping = ( ( uvScaled % res ) + res ) % res; 185 186 // https://www.shadertoy.com/view/WtyXRy 187 188 let uv = uvWrapping - 0.5; 189 let iuv = floor( uv ); 190 let f = fract( uv ); 191 192 let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level ); 193 let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level ); 194 let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level ); 195 let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level ); 196 197 return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y ); 198 199} 200`)},fT={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>"};"undefined"!=typeof navigator&&/Windows/g.test(navigator.userAgent)&&(fb.pow_float=new hz("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),fb.pow_vec2=new hz("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[fb.pow_float]),fb.pow_vec3=new hz("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[fb.pow_float]),fb.pow_vec4=new hz("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[fb.pow_float]),fT.pow_float="tsl_pow_float",fT.pow_vec2="tsl_pow_vec2",fT.pow_vec3="tsl_pow_vec3",fT.pow_vec4="tsl_pow_vec4");let f_="";!0!==("undefined"!=typeof navigator&&/Firefox|Deno/g.test(navigator.userAgent))&&(f_+="diagnostic( off, derivative_uniformity );\n");class fv extends gd{constructor(e,t){super(e,t,new fd),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==u.jf0}_generateTextureSample(e,t,r,i,s=this.shaderStage){if("fragment"===s)if(i)return`textureSample( ${t}, ${t}_sampler, ${r}, ${i} )`;else return`textureSample( ${t}, ${t}_sampler, ${r} )`;return this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r):this.generateTextureLod(e,t,r,i,"0")}_generateVideoSample(e,t,r=this.shaderStage){if("fragment"===r)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2<f32>( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${r} shader.`)}_generateTextureSampleLevel(e,t,r,i,s,n=this.shaderStage){return("fragment"===n||"compute"===n)&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,i
200):this.generateTextureLod(e,t,r,s,i)}generateWrapFunction(e){let t=`tsl_coord_${fp[e.wrapS]}S_${fp[e.wrapT]}_${e.isData3DTexture?"3d":"2d"}T`,r=fx[t];if(void 0===r){let i=[],s=e.isData3DTexture?"vec3f":"vec2f",n=`fn ${t}( coord : ${s} ) -> ${s} { 201 202 return ${s}( 203`,a=(e,t)=>{e===u.GJx?(i.push(fb.repeatWrapping_float),n+=` tsl_repeatWrapping_float( coord.${t} )`):e===u.ghU?(i.push(fb.clampWrapping_float),n+=` tsl_clampWrapping_float( coord.${t} )`):e===u.kTW?(i.push(fb.mirrorWrapping_float),n+=` tsl_mirrorWrapping_float( coord.${t} )`):(n+=` coord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};a(e.wrapS,"x"),n+=",\n",a(e.wrapT,"y"),e.isData3DTexture&&(n+=",\n",a(e.wrapR,"z")),n+="\n );\n\n}\n",fx[t]=r=new hz(n,i)}return r.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,r){let i=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===i.dimensionsSnippet&&(i.dimensionsSnippet={});let s=i.dimensionsSnippet[r];if(void 0===i.dimensionsSnippet[r]){let n,a,{primarySamples:o}=this.renderer.backend.utils.getTextureSampleData(e);a=e.isData3DTexture?"vec3<u32>":"vec2<u32>",n=o>1||e.isVideoTexture||e.isStorageTexture?t:`${t}${r?`, u32( ${r} )`:""}`,s=new io(new iq(`textureDimensions( ${n} )`,a)),i.dimensionsSnippet[r]=s,(e.isDataArrayTexture||e.isDepthArrayTexture||e.isData3DTexture)&&(i.arrayLayerCount=new io(new iq(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new io(new iq("6u","u32")))}return s.build(this)}generateFilteredTexture(e,t,r,i="0u"){this._include("biquadraticTexture");let s=this.generateWrapFunction(e),n=this.generateTextureDimension(e,t,i);return`tsl_biquadraticTexture( ${t}, ${s}( ${r} ), ${n}, u32( ${i} ) )`}generateTextureLod(e,t,r,i,s="0u"){let n=this.generateWrapFunction(e),a=this.generateTextureDimension(e,t,s),o=e.isData3DTexture?"vec3":"vec2",l=`${o}<u32>( ${n}( ${r} ) * ${o}<f32>( ${a} ) )`;return this.generateTextureLoad(e,t,l,i,s)}generateTextureLoad(e,t,r,i,s="0u"){let n;return!0===e.isVideoTexture||!0===e.isStorageTexture?n=`textureLoad( ${t}, ${r} )`:i?n=`textureLoad( ${t}, ${r}, ${i}, u32( ${s} ) )`:(n=`textureLoad( ${t}, ${r}, u32( ${s} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(n+=".x")),n}generateTextureStore(e,t,r,i){return`textureStore( ${t}, ${r}, ${i} )`}isSampleCompare(e){return!0===e.isDepthTexture&&null!==e.compareFunction}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===u.RQf||!1===this.isSampleCompare(e)&&e.minFilter===u.hxR&&e.magFilter===u.hxR||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,r,i,s=this.shaderStage){return!0===e.isVideoTexture?this._generateVideoSample(t,r,s):this.isUnfilterable(e)?this.generateTextureLod(e,t,r,i,"0",s):this._generateTextureSample(e,t,r,i,s)}generateTextureGrad(e,t,r,i,s,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,r,i,s,n=this.shaderStage){if("fragment"===n)return e.isDepthArrayTexture?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(e,t,r,i,s,n=this.shaderStage){return!0===e.isVideoTexture?this._generateVideoSample(t,r,n):this._generateTextureSampleLevel(e,t,r,i,s,n)}generateTextureBias(e,t,r,i,s,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){let t=e.name,r=e.type;return"texture"===r||"cubeTexture"===r||"storageTexture"===r||"texture3D"===r?t:"buffer"!==r&&"storageBuffer"!==r&&"indirectStorageBuffer"!==r?e.groupNode.name+"."+t:this.isCu
203stomStruct(e)?t:t+".value"}return super.getPropertyName(e)}getOutputStructName(){return"output"}getFunctionOperator(e){let t=ff[e];return void 0!==t?(this._include(t),t):null}getNodeAccess(e,t){return"compute"!==t?C.READ_ONLY:e.access}getStorageAccess(e,t){return fc[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),n=this.getDataFromNode(e,r,this.globalCache);if(void 0===n.uniformGPU){let a,o=e.groupNode,l=o.name,u=this.getBindGroupArray(l,r);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null,n=this.getNodeAccess(e,r);if("texture"===t||"storageTexture"===t?i=new mo(s.name,s.node,o,n):"cubeTexture"===t?i=new ml(s.name,s.node,o,n):"texture3D"===t&&(i=new mu(s.name,s.node,o,n)),i.store=!0===e.isStorageTextureNode,i.setVisibility(fg[r]),("fragment"===r||"compute"===r)&&!1===this.isUnfilterable(e.value)&&!1===i.store){let e=new m5(`${s.name}_sampler`,s.node,o);e.setVisibility(fg[r]),u.push(e,i),a=[e,i]}else u.push(i),a=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){let n=new("buffer"===t?mt:fe)(e,o);n.setVisibility(fg[r]),u.push(n),a=n,s.name=i||"NodeBuffer_"+s.id}else{let e=this.uniformGroups[r]||(this.uniformGroups[r]={}),i=e[l];void 0===i&&((i=new ms(l,o)).setVisibility(fg[r]),e[l]=i,u.push(i)),a=this.getNodeUniform(s,t),i.addUniform(a)}n.uniformGPU=a}return s}getBuiltin(e,t,r,i=this.shaderStage){let s=this.builtins[i]||(this.builtins[i]=new Map);return!1===s.has(e)&&s.set(e,{name:e,property:t,type:r}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let e of t.inputs)i.push(e.name+" : "+this.getType(e.type));let s=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} { 204${r.vars} 205${r.code} 206`;return r.result&&(s+=` return ${r.result}; 207`),s+="\n}\n"}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){let t=[],r=this.directives[e];if(void 0!==r)for(let e of r)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array<f32, ${e} >`,"vertex")}getBuiltins(e){let t=[],r=this.builtins[e];if(void 0!==r)for(let{name:e,property:i,type:s}of r.values())t.push(`@builtin( ${e} ) ${i} : ${s}`);return t.join(",\n ")}getScopedArray(e,t,r,i){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:r,bufferCount:i}),e}getScopedArrays(e){if("compute"!==e)return;let t=[];for(let{name:e,scope:r,bufferType:i,bufferCount:s}of this.scopedArrays.values()){let n=this.getType(i);t.push(`var<${r}> ${e}: array< ${n}, ${s} >;`)}return t.join("\n")}getAttributes(e){let t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","globalId","vec3<u32>","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3<u32>","attribute"),this.getBuiltin("local_invocation_id","localId","vec3<u32>","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3<u32>","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){let e=this.getBuiltins("attribute");e&&t.push(e);let r=this.getAttributesArray();for(let e=0,i=r.length;e<i;e++){let i=r[e],s=i.name,n=this.getType(i.type);t.push(`@location( ${e} ) ${s} : ${n}`)}}return t.join(",\n ")}getStructMembers(e){let t=[];for(let r of e.members){let i=e.output?"@location( "+r.index+" ) ":"",s=this.getType(r.type);r.atomic&&(s="atomic< "+s+" >"),t.push(` ${i+r.name} : ${s}`)}return e.output&&t.push(` ${this.getBuiltins("output")}`),t.join(",\n")}getStructs(e){let t="",r=this.structs[e];if(r.length>0){let e=[];for(let t of r){let r=`struct ${t.name} { 208`;r+=this.getStructMembers(t),r+="\n};",e.push(r)}t="\n"+e.join("\n\n")+"\n"}return t}getVar(e,t,r=null){let i=`var ${t} : `;return null!==r?i+=this.generateArrayDeclaration(e,r):i+=this.getType(e),i}getVars(e){let t=[],r=this.vars[e];if(void 0!==r)for(let e of r)t.push(` ${this.getVar(e.type,e.name,e.count)};`);return` 209${t.join("\n")} 210`}getVaryings(e){let t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4<f32>","vertex"),"vertex"===e||"fragment"===e){let r=this.varyings,i=this.vars[e];for(let s=0;s<r.length;s++){let n=r[s];if(n.needsInterpolation){let e=`@location( ${s} )`;if(n.interpolationType){let t=null!==n.interpolationSampling?`, ${n.interpolationSampling} )`:" )";e+=` @interpolate( ${n.interpolationType}${t}`}
210else/^(int|uint|ivec|uvec)/.test(n.type)&&(e+=` @interpolate( ${this.renderer.backend.compatibilityMode?"flat, either":"flat"} )`);t.push(`${e} ${n.name} : ${this.getType(n.type)}`)}else"vertex"===e&&!1===i.includes(n)&&i.push(n)}}let r=this.getBuiltins(e);r&&t.push(r);let i=t.join(",\n ");return"vertex"===e?this._getWGSLStruct("VaryingsStruct"," "+i):i}isCustomStruct(e){let t=e.value,r=e.node,i=(t.isBufferAttribute||t.isInstancedBufferAttribute)&&null!==r.structTypeNode,s=r.value&&r.value.array&&"number"==typeof r.value.itemSize&&r.value.array.length>r.value.itemSize;return i&&!s}getUniforms(e){let t=this.uniforms[e],r=[],i=[],s=[],n={};for(let s of t){let t=s.groupNode.name,a=this.bindingsIndexes[t];if("texture"===s.type||"cubeTexture"===s.type||"storageTexture"===s.type||"texture3D"===s.type){let t,i=s.node.value;("fragment"===e||"compute"===e)&&!1===this.isUnfilterable(i)&&!0!==s.node.isStorageTextureNode&&(this.isSampleCompare(i)?r.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${s.name}_sampler : sampler_comparison;`):r.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${s.name}_sampler : sampler;`));let n="",{primarySamples:o}=this.renderer.backend.utils.getTextureSampleData(i);if(o>1&&(n="_multisampled"),!0===i.isCubeTexture)t="texture_cube<f32>";else if(!0===i.isDataArrayTexture||!0===i.isCompressedArrayTexture||!0===i.isTextureArray)t="texture_2d_array<f32>";else if(!0===i.isDepthTexture)t=this.renderer.backend.compatibilityMode&&null===i.compareFunction?`texture${n}_2d<f32>`:`texture_depth${n}_2d${!0===i.isDepthArrayTexture?"_array":""}`;else if(!0===i.isVideoTexture)t="texture_external";else if(!0===i.isData3DTexture)t="texture_3d<f32>";else if(!0===s.node.isStorageTextureNode){let r=fn(i),n=this.getStorageAccess(s.node,e);t=`texture_storage_2d<${r}, ${n}>`}else{let e=this.getComponentTypeFromTexture(i).charAt(0);t=`texture${n}_2d<${e}32>`}r.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${s.name} : ${t};`)}else if("buffer"===s.type||"storageBuffer"===s.type||"indirectStorageBuffer"===s.type){let t=s.node,r=this.getType(t.getNodeType(this)),n=t.bufferCount,o=n>0&&"buffer"===s.type?", "+n:"",l=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t,e)}`:"uniform";if(this.isCustomStruct(s))i.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var<${l}> ${s.name} : ${r};`);else{let e=t.isAtomic?`atomic<${r}>`:`${r}`,n=` value : array< ${e}${o} >`;i.push(this._getWGSLStructBinding(s.name,n,l,a.binding++,a.group))}}else{let e=this.getType(this.getVectorType(s.type)),t=s.groupNode.name;(n[t]||(n[t]={index:a.binding++,id:a.group,snippets:[]})).snippets.push(` ${s.name} : ${e}`)}}for(let e in n){let t=n[e];s.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let a=r.join("\n");return a+=i.join("\n"),a+=s.join("\n")}buildCode(){let e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(let t in this.sortBindingGroups(),e){this.shaderStage=t;let r=e[t];r.uniforms=this.getUniforms(t),r.attributes=this.getAttributes(t),r.varyings=this.getVaryings(t),r.structs=this.getStructs(t),r.vars=this.getVars(t),r.codes=this.getCodes(t),r.directives=this.getDirectives(t),r.scopedArrays=this.getScopedArrays(t);let i="// code\n\n";i+=this.flowCode[t];let s=this.flowNodes[t],n=s[s.length-1],a=n.outputNode,o=void 0!==a&&!0===a.isOutputStructNode;for(let e of s){let s=this.getFlowData(e),l=e.name;if(l&&(i.length>0&&(i+="\n"),i+=` // flow -> ${l} 211`),i+=`${s.code} 212 `,e===n&&"compute"!==t){if(i+="// result\n\n ","vertex"===t)i+=`varyings.Vertex = ${s.result};`;else if("fragment"===t)if(o)r.returnType=a.getNodeType(this),r.structs+="var<private> output : "+r.returnType+";",i+=`return ${s.result};`;else{let e=" @location(0) color: vec4<f32>",t=this.getBuiltins("output");t&&(e+=",\n "+t),r.returnType="OutputStruct",r.structs+=this._getWGSLStruct("OutputStruct",e),r.structs+="\nvar<private> output : OutputStruct;",i+=`output.color = ${s.result}; 213 214 return output;`}}}r.flow=i}this.shaderStage=null,null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let r;return null!==t&&(r=this._getWGSLMethod(e+"_"+t)),void 0===r&&(r=this._getWGSLMethod(e)),r||e}getType(e){return fy[e]||e}isAvailable(e){let t=fm[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),fm[e]=t),t}_getWGSLMethod(e){return void 0!==fb[e]&&this._include(e),fT[e]}_include(e){let t=fb[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}
214_getWGSLVertexCode(e){return`${this.getSignature()} 215// directives 216${e.directives} 217 218// structs 219${e.structs} 220 221// uniforms 222${e.uniforms} 223 224// varyings 225${e.varyings} 226var<private> varyings : VaryingsStruct; 227 228// codes 229${e.codes} 230 231@vertex 232fn main( ${e.attributes} ) -> VaryingsStruct { 233 234 // vars 235 ${e.vars} 236 237 // flow 238 ${e.flow} 239 240 return varyings; 241 242} 243`}_getWGSLFragmentCode(e){return`${this.getSignature()} 244// global 245${f_} 246 247// structs 248${e.structs} 249 250// uniforms 251${e.uniforms} 252 253// codes 254${e.codes} 255 256@fragment 257fn main( ${e.varyings} ) -> ${e.returnType} { 258 259 // vars 260 ${e.vars} 261 262 // flow 263 ${e.flow} 264 265} 266`}_getWGSLComputeCode(e,t){return`${this.getSignature()} 267// directives 268${e.directives} 269 270// system 271var<private> instanceIndex : u32; 272 273// locals 274${e.scopedArrays} 275 276// structs 277${e.structs} 278 279// uniforms 280${e.uniforms} 281 282// codes 283${e.codes} 284 285@compute @workgroup_size( ${t} ) 286fn main( ${e.attributes} ) { 287 288 // system 289 instanceIndex = globalId.x + globalId.y * numWorkgroups.x * u32(${t}) + globalId.z * numWorkgroups.x * numWorkgroups.y * u32(${t}); 290 291 // vars 292 ${e.vars} 293 294 // flow 295 ${e.flow} 296 297} 298`}_getWGSLStruct(e,t){return` 299struct ${e} { 300${t} 301};`}_getWGSLStructBinding(e,t,r,i=0,s=0){let n=e+"Struct",a=this._getWGSLStruct(n,t);return`${a} 302@binding( ${i} ) @group( ${s} ) 303var<${r}> ${e} : ${n};`}}class fS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=mW.Depth24PlusStencil8:e.depth&&(t=mW.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){let e=this.backend.renderer,r=e.getRenderTarget();t=r?r.samples:e.samples}else e.renderTarget&&(t=e.renderTarget.samples);let r=(t=t||1)>1&&null!==e.renderTarget&&!0!==e.isDepthTexture&&!0!==e.isFramebufferTexture,i=r?1:t;return{samples:t,primarySamples:i,isMSAA:r}}getCurrentColorFormat(e){return null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat()}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?mD.PointList:e.isLineSegments||e.isMesh&&!0===t.wireframe?mD.LineList:e.isLine?mD.LineStrip:e.isMesh?mD.TriangleList:void 0}getSampleCount(e){let t=1;return e>1&&2===(t=Math.pow(2,Math.floor(Math.log2(e))))&&(t=4),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){let e=this.backend.parameters.outputType;if(void 0===e)return navigator.gpu.getPreferredCanvasFormat();if(e===u.OUM)return mW.BGRA8Unorm;if(e===u.ix0)return mW.RGBA16Float;throw Error("Unsupported outputType")}}let fN=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),fR=new Map([[u.Oax,["float16"]]]),fA=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class fE{constructor(e){this.backend=e}createAttribute(e,t){let r=this._getBufferAttribute(e),i=this.backend,s=i.get(r),n=s.buffer;if(void 0===n){let a=i.device,o=r.array;if(!1===e.normalized){if(o.constructor===Int16Array||o.constructor===Int8Array)o=new Int32Array(o);else if((o.constructor===Uint16Array||o.constructor===Uint8Array)&&(o=new Uint32Array(o),t&GPUBufferUsage.INDEX))for(let e=0;e<o.length;e++)65535===o[e]&&(o[e]=0xffffffff)}if(r.array=o,(r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&3===r.itemSize){o=new o.constructor(4*r.count);for(let e=0;e<r.count;e++)o.set(r.array.subarray(3*e,3*e+3),4*e);r.itemSize=4,r.array=o,s._force3to4BytesAlignment=!0}let l=o.byteLength+(4-o.byteLength%4)%4;n=a.createBuffer({label:r.name,size:l,usage:t,mappedAtCreation:!0}),new o.constructor(n.getMappedRange()).set(o),n.unmap(),s.buffer=n}}updateAttribute(e){let t=this._getBufferAttribute(e),r=this.backend,i=r.device,s=r.get(t),n=r.get(t).buffer,a=t.array;if(!0===s._force3to4BytesAlignment){a=new a.constructor(4*t.count);for(let e=0;e<t.count;e++)a.set(t.array.subarray(3*e,3*e+3),4*e);t.array=a}let o=this._isTypedArray(a),l=t.updateRanges;if(0===l.length)i.queue.writeBuffer(n,0,a,0);else{let e=o?1:a.BYTES_PER_ELEMENT;for(let t=0,r=l.length;t<r;t++){let r,u,d=l[t];if(!0===s._force3to4BytesAlignment){let t=Math.floor(d.start/3),i=Math.ceil(d.count/3);r=4*t*e,u=4*i*e}else r=d.start*e,u=d.count*e;let h=r*(o?a.BYTES_PER_ELEMENT:1);i.queue.writeBuffer(n,h,a,r,u)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){let t=e.getAttributes(),r=new Map;for(let e=0;e<t.length;e++){let i=t[e],s=i.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(i),a=r.get(n);if(void 0===a){let e,t;!0===i.isInterleavedBufferAttribute?(e=i.data.stride*s,t=i.data.isInstancedInterleavedBuffer?m4.Instance:m4.Vertex):(e=i.itemSize*s,t=i.isInstancedBufferAttribute?m4.Instance:m4.Vertex),!1===i.normalized&&(i.array.constructor===Int16Array||i.array.
303constructor===Uint16Array)&&(e=4),a={arrayStride:e,attributes:[],stepMode:t},r.set(n,a)}let o=this._getVertexFormat(i),l=!0===i.isInterleavedBufferAttribute?i.offset*s:0;a.attributes.push({shaderLocation:e,offset:l,format:o})}return Array.from(r.values())}destroyAttribute(e){let t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e){let t=this.backend,r=t.device,i=t.get(this._getBufferAttribute(e)).buffer,s=i.size,n=r.createBuffer({label:`${e.name}_readback`,size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=r.createCommandEncoder({label:`readback_encoder_${e.name}`});a.copyBufferToBuffer(i,0,n,0,s);let o=a.finish();r.queue.submit([o]),await n.mapAsync(GPUMapMode.READ);let l=n.getMappedRange(),u=new e.array.constructor(l.slice(0));return n.unmap(),u.buffer}_getVertexFormat(e){let t,{itemSize:r,normalized:i}=e,s=e.array.constructor,n=e.constructor;if(1===r)t=fA.get(s);else{let e=(fR.get(n)||fN.get(s))[+!!i];if(e){let i=4*Math.floor((s.BYTES_PER_ELEMENT*r+3)/4)/s.BYTES_PER_ELEMENT;if(i%1)throw Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");t=`${e}x${i}`}}return t||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),t}_isTypedArray(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class fw{constructor(e){this.backend=e,this.bindGroupLayoutCache=new WeakMap}createBindingsLayout(e){let t=this.backend,r=t.device,i=[],s=0;for(let r of e.bindings){let e={binding:s++,visibility:r.visibility};if(r.isUniformBuffer||r.isStorageBuffer){let t={};r.isStorageBuffer&&(4&r.visibility&&(r.access===C.READ_WRITE||r.access===C.WRITE_ONLY)?t.type=mK.Storage:t.type=mK.ReadOnlyStorage),e.buffer=t}else if(r.isSampler){let i={};r.texture.isDepthTexture&&(null!==r.texture.compareFunction?i.type=mJ.Comparison:t.compatibilityMode&&(i.type=mJ.NonFiltering)),e.sampler=i}else if(r.isSampledTexture&&r.texture.isVideoTexture)e.externalTexture={};else if(r.isSampledTexture&&r.store){let t={};t.format=this.backend.get(r.texture).texture.format;let i=r.access;i===C.READ_WRITE?t.access=mZ.ReadWrite:i===C.WRITE_ONLY?t.access=mZ.WriteOnly:t.access=mZ.ReadOnly,e.storageTexture=t}else if(r.isSampledTexture){let i={},{primarySamples:s}=t.utils.getTextureSampleData(r.texture);if(s>1&&(i.multisampled=!0,r.texture.isDepthTexture||(i.sampleType=m0.UnfilterableFloat)),r.texture.isDepthTexture)t.compatibilityMode&&null===r.texture.compareFunction?i.sampleType=m0.UnfilterableFloat:i.sampleType=m0.Depth;else if(r.texture.isDataTexture||r.texture.isDataArrayTexture||r.texture.isData3DTexture){let e=r.texture.type;e===u.Yuy?i.sampleType=m0.SInt:e===u.bkx?i.sampleType=m0.UInt:e===u.RQf&&(this.backend.hasFeature("float32-filterable")?i.sampleType=m0.Float:i.sampleType=m0.UnfilterableFloat)}r.isSampledCubeTexture?i.viewDimension=m2.Cube:r.texture.isDataArrayTexture||r.texture.isDepthArrayTexture||r.texture.isCompressedArrayTexture?i.viewDimension=m2.TwoDArray:r.isSampledTexture3D&&(i.viewDimension=m2.ThreeD),e.texture=i}else console.error(`WebGPUBindingUtils: Unsupported binding "${r}".`);i.push(e)}return r.createBindGroupLayout({entries:i})}createBindings(e,t,r,i=0){let s,{backend:n,bindGroupLayoutCache:a}=this,o=n.get(e),l=a.get(e.bindingsReference);void 0===l&&(l=this.createBindingsLayout(e),a.set(e.bindingsReference,l)),r>0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[r]===i&&(s=o.groups[r])),void 0===s&&(s=this.createBindGroup(e,l),r>0&&(o.groups[r]=s,o.versions[r]=i)),o.group=s,o.layout=l}updateBinding(e){let t=this.backend,r=t.device,i=e.buffer,s=t.get(e).buffer;r.queue.writeBuffer(s,0,i,0)}createBindGroupIndex(e,t){let r=this.backend.device,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s=e[0],n=r.createBuffer({label:"bindingCameraIndex_"+s,size:16,usage:i});r.queue.writeBuffer(n,0,e,0);let a=[{binding:0,resource:{buffer:n}}];return r.createBindGroup({label:"bindGroupCameraIndex_"+s,layout:t,entries:a})}createBindGroup(e,t){let r=this.backend,i=r.device,s=0,n=[];for(let t of e.bindings){if(t.isUniformBuffer){let e=r.get(t);if(void 0===e.buffer){let r=t.byteLength,s=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST;
303e.buffer=i.createBuffer({label:"bindingBuffer_"+t.name,size:r,usage:s})}n.push({binding:s,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){let e=r.get(t);if(void 0===e.buffer){let i=t.attribute;e.buffer=r.get(i).buffer}n.push({binding:s,resource:{buffer:e.buffer}})}else if(t.isSampler){let e=r.get(t.texture);n.push({binding:s,resource:e.sampler})}else if(t.isSampledTexture){let e,a=r.get(t.texture);if(void 0!==a.externalTexture)e=i.importExternalTexture({source:a.externalTexture});else{let r=t.store?1:a.texture.mipLevelCount,i=`view-${a.texture.width}-${a.texture.height}-${r}`;if(void 0===(e=a[i])){let s,n=m3.All;s=t.isSampledCubeTexture?m2.Cube:t.isSampledTexture3D?m2.ThreeD:t.texture.isDataArrayTexture||t.texture.isDepthArrayTexture||t.texture.isCompressedArrayTexture?m2.TwoDArray:m2.TwoD,e=a[i]=a.texture.createView({aspect:n,dimension:s,mipLevelCount:r})}}n.push({binding:s,resource:e})}s++}return i.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}}class fC{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){let r,{object:i,material:s,geometry:n,pipeline:a}=e,{vertexProgram:o,fragmentProgram:l}=a,d=this.backend,h=d.device,c=d.utils,p=d.get(a),g=[];for(let t of e.getBindings()){let e=d.get(t);g.push(e.layout)}let m=d.attributeUtils.createShaderVertexBuffers(e);s.blending!==u.XIg&&(s.blending!==u.NTi||!1!==s.transparent)&&(r=this._getBlending(s));let f={};!0===s.stencilWrite&&(f={compare:this._getStencilCompare(s),failOp:this._getStencilOperation(s.stencilFail),depthFailOp:this._getStencilOperation(s.stencilZFail),passOp:this._getStencilOperation(s.stencilZPass)});let y=this._getColorWriteMask(s),x=[];if(null!==e.context.textures){let t=e.context.textures;for(let e=0;e<t.length;e++){let i=c.getTextureFormatGPU(t[e]);x.push({format:i,blend:r,writeMask:y})}}else{let t=c.getCurrentColorFormat(e.context);x.push({format:t,blend:r,writeMask:y})}let b=d.get(o).module,T=d.get(l).module,_=this._getPrimitiveState(i,n,s),v=this._getDepthCompare(s),S=c.getCurrentDepthStencilFormat(e.context),N=this._getSampleCount(e.context),R={label:`renderPipeline_${s.name||s.type}_${s.id}`,vertex:Object.assign({},b,{buffers:m}),fragment:Object.assign({},T,{targets:x}),primitive:_,multisample:{count:N,alphaToCoverageEnabled:s.alphaToCoverage&&N>1},layout:h.createPipelineLayout({bindGroupLayouts:g})},A={},E=e.context.depth,w=e.context.stencil;if((!0===E||!0===w)&&(!0===E&&(A.format=S,A.depthWriteEnabled=s.depthWrite,A.depthCompare=v),!0===w&&(A.stencilFront=f,A.stencilBack={},A.stencilReadMask=s.stencilFuncMask,A.stencilWriteMask=s.stencilWriteMask),!0===s.polygonOffset&&(A.depthBias=s.polygonOffsetUnits,A.depthBiasSlopeScale=s.polygonOffsetFactor,A.depthBiasClamp=0),R.depthStencil=A),null===t)p.pipeline=h.createRenderPipeline(R);else{let e=new Promise(e=>{h.createRenderPipelineAsync(R).then(t=>{p.pipeline=t,e()})});t.push(e)}}createBundleEncoder(e,t="renderBundleEncoder"){let{utils:r,device:i}=this.backend,s=r.getCurrentDepthStencilFormat(e),n=r.getCurrentColorFormat(e),a=this._getSampleCount(e);return i.createRenderBundleEncoder({label:t,colorFormats:[n],depthStencilFormat:s,sampleCount:a})}createComputePipeline(e,t){let r=this.backend,i=r.device,s=r.get(e.computeProgram).module,n=r.get(e),a=[];for(let e of t){let t=r.get(e);a.push(t.layout)}n.pipeline=i.createComputePipeline({compute:s,layout:i.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(e){let t,r,i=e.blending,s=e.blendSrc,n=e.blendDst,a=e.blendEquation;if(i===u.bCz){let i=null!==e.blendSrcAlpha?e.blendSrcAlpha:s,o=null!==e.blendDstAlpha?e.blendDstAlpha:n,l=null!==e.blendEquationAlpha?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(a)},r={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(l)}}else{let s=e.premultipliedAlpha,n=(e,i,s,n)=>{t={srcFactor:e,dstFactor:i,operation:mX.Add},r={srcFactor:s,dstFactor:n,operation:mX.Add}};if(s)switch(i){case u.NTi:n(mj.One,mj.OneMinusSrcAlpha,mj.One,mj.OneMinusSrcAlpha);break;case u.EZo:n(mj.One,mj.One,mj.One,mj.One);break;case u.Kwu:n(mj.Zero,mj.OneMinusSrc,mj.Zero,mj.One);break;case u.EdD:n(mj.Zero,mj.Src,mj.Zero,mj.SrcAlpha)}else switch(i){case u.NTi:n(mj.SrcAlpha,mj.OneMinusSrcAlpha,mj.One,mj.OneMinusSrcAlpha);break;case u.EZo:n(mj.SrcAlpha,mj.One,mj.SrcAlpha,mj.One);break;case u.Kwu:n(mj.Zero,mj.OneMinusSrc,mj.Zero,mj.One);break;
303case u.EdD:n(mj.Zero,mj.Src,mj.Zero,mj.Src)}}if(void 0!==t&&void 0!==r)return{color:t,alpha:r};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case u.ojh:t=mj.Zero;break;case u.qad:t=mj.One;break;case u.f4X:t=mj.Src;break;case u.LiQ:t=mj.OneMinusSrc;break;case u.ie2:t=mj.SrcAlpha;break;case u.OuU:t=mj.OneMinusSrcAlpha;break;case u.wn6:t=mj.Dst;break;case u.aEY:t=mj.OneMinusDstColor;break;case u.hdd:t=mj.DstAlpha;break;case u.Nt7:t=mj.OneMinusDstAlpha;break;case u.hgQ:t=mj.SrcAlphaSaturated;break;case 211:t=mj.Constant;break;case 212:t=mj.OneMinusConstant;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t,r=e.stencilFunc;switch(r){case u.HPb:t=mV.Never;break;case u.sKt:t=mV.Always;break;case u.kYr:t=mV.Less;break;case u.CR7:t=mV.LessEqual;break;case u.jsO:t=mV.Equal;break;case u.TMh:t=mV.GreaterEqual;break;case u.RcT:t=mV.Greater;break;case u.klZ:t=mV.NotEqual;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",r)}return t}_getStencilOperation(e){let t;switch(e){case u.VVr:t=mY.Keep;break;case u.kqe:t=mY.Zero;break;case u.kG0:t=mY.Replace;break;case u.oVO:t=mY.Invert;break;case u.HLH:t=mY.IncrementClamp;break;case u.ROr:t=mY.DecrementClamp;break;case u.Ru$:t=mY.IncrementWrap;break;case u.fJr:t=mY.DecrementWrap;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case u.gO9:t=mX.Add;break;case u.FXf:t=mX.Subtract;break;case u.nST:t=mX.ReverseSubtract;break;case u.znC:t=mX.Min;break;case u.$ei:t=mX.Max;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,r){let i={};switch(i.topology=this.backend.utils.getPrimitiveTopology(e,r),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?m$.Uint16:m$.Uint32),r.side){case u.hB5:i.frontFace=mk.CCW,i.cullMode=mz.Back;break;case u.hsX:i.frontFace=mk.CCW,i.cullMode=mz.Front;break;case u.$EB:i.frontFace=mk.CCW,i.cullMode=mz.None;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",r.side)}return i}_getColorWriteMask(e){return!0===e.colorWrite?mQ.All:mQ.None}_getDepthCompare(e){let t;if(!1===e.depthTest)t=mV.Always;else{let r=e.depthFunc;switch(r){case u.eHc:t=mV.Never;break;case u.lGu:t=mV.Always;break;case u.brA:t=mV.Less;break;case u.xSv:t=mV.LessEqual;break;case u.U3G:t=mV.Equal;break;case u.Gwm:t=mV.GreaterEqual;break;case u.K52:t=mV.Greater;break;case u.bw0:t=mV.NotEqual;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",r)}}return t}}class fM extends mL{constructor(e,t,r=2048){super(r),this.device=e,this.type=t,this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxQueries,label:`queryset_global_timestamp_${t}`});let i=8*this.maxQueries;this.resolveBuffer=this.device.createBuffer({label:`buffer_timestamp_resolve_${t}`,size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.resultBuffer=this.device.createBuffer({label:`buffer_timestamp_result_${t}`,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return(0,u.mcG)(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e.id,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||0===this.currentQueryIndex||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if("unmapped"!==this.resultBuffer.mapState)return this.lastValue;let e=new Map(this.queryOffsets),t=this.currentQueryIndex,r=8*t;this.currentQueryIndex=0,this.queryOffsets.clear();let i=this.device.createCommandEncoder();i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,r);let s=i.finish();if(this.device.queue.submit([s]),"unmapped"!==this.resultBuffer.mapState)return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,r),this.isDisposed)return"mapped"===this.resultBuffer.mapState&&this.resultBuffer.unmap(),this.lastValue;let n=new BigUint64Array(this.resultBuffer.getMappedRange(0,r)),a=0;for(let[,t]of e){let e=n[t],r=n[t+1],i=Number(r-e)/1e6;a+=i}return this.resultBuffer.unmap(),this.lastValue=a,a}catch(e){return console.error("Error resolving queries:",e),"mapped"===this.resultBuffer.mapState&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){console.error("Error waiting for pending resolve:",e)}if(this.resultBuffer&&"mapped"===this.resultBuffer.mapState)try{this.resultBuffer.unmap()}catch(e){console.error("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.pendingResolve=null}}}
303class fB extends mb{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.compatibilityMode=void 0!==e.compatibilityMode&&e.compatibilityMode,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.compatibilityMode=this.parameters.compatibilityMode,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new fS(this),this.attributeUtils=new fE(this),this.bindingUtils=new fw(this),this.pipelineUtils=new fC(this),this.textureUtils=new fs(this),this.occludedResolveCache=new Map}async init(e){let t;await super.init(e);let r=this.parameters;if(void 0===r.device){let e={powerPreference:r.powerPreference,featureLevel:r.compatibilityMode?"compatibility":void 0},i="undefined"!=typeof navigator?await navigator.gpu.requestAdapter(e):null;if(null===i)throw Error("WebGPUBackend: Unable to create WebGPU adapter.");let s=Object.values(m6),n=[];for(let e of s)i.features.has(e)&&n.push(e);let a={requiredFeatures:n,requiredLimits:r.requiredLimits};t=await i.requestDevice(a)}else t=r.device;t.lost.then(t=>{let r={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(r)});let i=void 0!==r.context?r.context:e.domElement.getContext("webgpu");this.device=t,this.context=i;let s=r.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(m6.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:s}),this.updateSize()}get coordinateSystem(){return u.i7u}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){let t=this.renderer;e={colorAttachments:[{view:null}]},(!0===this.renderer.depth||!0===this.renderer.stencil)&&(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});let r=e.colorAttachments[0];this.renderer.samples>0?r.view=this.colorBuffer.createView():r.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}let t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isDepthArrayTexture&&e.camera.isArrayCamera}_getRenderPassDescriptor(e,t={}){let r=e.renderTarget,i=this.get(r),s=i.descriptors;if(void 0===s||i.width!==r.width||i.height!==r.height||i.dimensions!==r.dimensions||i.activeMipmapLevel!==e.activeMipmapLevel||i.activeCubeFace!==e.activeCubeFace||i.samples!==r.samples){i.descriptors=s={};let e=()=>{r.removeEventListener("dispose",e),this.delete(r)};!1===r.hasEventListener("dispose",e)&&r.addEventListener("dispose",e)}let n=e.getCacheKey(),a=s[n];if(void 0===a){let t,o=e.textures,l=[],u=this._isRenderCameraDepthArray(e);for(let i=0;i<o.length;i++){let s=this.get(o[i]),n={label:`colorAttachment_${i}`,baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1,dimension:m2.TwoD};if(r.isRenderTarget3D)t=e.activeCubeFace,n.baseArrayLayer=0,n.dimension=m2.ThreeD,n.depthOrArrayLayers=o[i].image.depth;else if(r.isRenderTargetArray)if(!0===u){let t=e.camera.cameras;for(let e=0;e<t.length;e++){let t={...n,baseArrayLayer:e,arrayLayerCount:1,dimension:m2.TwoD},r=s.texture.createView(t);l.push({view:r,resolveTarget:void 0,depthSlice:void 0})}}else n.dimension=m2.TwoDArray,n.depthOrArrayLayers=o[i].image.depth;if(!0!==u){let e,r,i=s.texture.createView(n);void 0!==s.msaaTexture?(e=s.msaaTexture.createView(),r=i):(e=i,r=void 0),l.push({view:e,resolveTarget:r,depthSlice:t})}}if(a={textureViews:l},e.depth){let t=this.get(e.depthTexture),r={};e.depthTexture.isDepthArrayTexture&&(r.dimension=m2.TwoD,r.arrayLayerCount=1,r.baseArrayLayer=e.activeCubeFace),a.depthStencilView=t.texture.createView(r)}s[n]=a,i.width=r.width,i.height=r.height,i.samples=r.samples,i.activeMipmapLevel=e.activeMipmapLevel,i.activeCubeFace=e.activeCubeFace,i.dimensions=r.dimensions}let o={colorAttachments:[]};for(let e=0;e<a.textureViews.length;e++){let r=a.textureViews[e],i={r:0,g:0,b:0,a:1};0===e&&t.clearValue&&(i=t.clearValue),o.colorAttachments.push({view:r.view,depthSlice:r.depthSlice,resolveTarget:r.resolveTarget,loadOp:t.loadOp||mG.Load,storeOp:t.storeOp||mO.Store,clearValue:i})}return a.depthStencilView&&(o.depthStencilAttachment={view:a.depthStencilView}),o}beginRender(e){let t,r,i=this.get(e),s=this.device,n=e.occlusionQueryCount;n>0&&(i.currentOcclusionQuerySet&&i.currentOcclusionQuerySet.destroy(),i.currentOcclusionQueryBuffer&&i.currentOcclusionQueryBuffer.destroy(),i.currentOcclusionQuerySet=i.occlusionQuerySet,i.currentOcclusionQueryBuffer=i.occlusionQueryBuffer,i.currentOcclusionQueryObjects=i.occlusionQueryObjects,i.occlusionQuerySet=t=s.createQuerySet({type:"occlusion",count:n,label:`occlusionQuerySet_${e.id}`}),i.occlusionQueryIndex=0,i.occlusionQueryObjects=Array(n),i.lastOcclusionObject=null),r=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e,{loadOp:mG.Load}),this.initTimestampQuery(e,r),r.occlusionQuerySet=t;let a=r.depthStencilAttachment;if(null!==e.textures){let t=r.colorAttachments;for(let r=0;r<t.length;r++){let i=t[r];e.clearColor?(i.clearValue=0===r?e.clearColorValue:{r:0,g:0,b:0,a:1},i.loadOp=mG.Clear):i.loadOp=mG.Load,i.storeOp=mO.Store}}else{let t=r.colorAttachments[0];e.clearColor?(t.clearValue=e.clearColorValue,t.loadOp=mG.Clear):t.loadOp=mG.Load,t.storeOp=mO.Store}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=mG.Clear):a.depthLoadOp=mG.Load,a.depthStoreOp=mO.Store),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=mG.Clear):a.stencilLoadOp=mG.Load,a.stencilStoreOp=mO.Store);let o=s.createCommandEncoder({label:"renderContext_"+e.id});if(!0===this._isRenderCameraDepthArray(e)){let t=e.camera.cameras;i.layerDescriptors&&i.layerDescriptors.length===t.length?this._updateDepthLayerDescriptors(e,i,t):this._createDepthLayerDescriptors(e,i,r,t),i.bundleEncoders=[],i.bundleSets=[];for(let r=0;r<t.length;r++){let t=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+r),s={attributes:{},bindingGroups:[],pipeline:null,index:null};i.bundleEncoders.push(t),i.bundleSets.push(s)}i.currentPass=null}else{let t=o.beginRenderPass(r);if(i.currentPass=t,e.viewport&&this.updateViewport(e),e.scissor){let{x:r,y:i,width:s,height:n}=e.scissorValue;
303t.setScissorRect(r,i,s,n)}}i.descriptor=r,i.encoder=o,i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},i.renderBundles=[]}_createDepthLayerDescriptors(e,t,r,i){let s=r.depthStencilAttachment;t.layerDescriptors=[];let n=this.get(e.depthTexture);n.viewCache||(n.viewCache=[]);for(let a=0;a<i.length;a++){let i={...r,colorAttachments:[{...r.colorAttachments[0],view:r.colorAttachments[a].view}]};if(r.depthStencilAttachment){let t=a;n.viewCache[t]||(n.viewCache[t]=n.texture.createView({dimension:m2.TwoD,baseArrayLayer:a,arrayLayerCount:1})),i.depthStencilAttachment={view:n.viewCache[t],depthLoadOp:s.depthLoadOp||mG.Clear,depthStoreOp:s.depthStoreOp||mO.Store,depthClearValue:s.depthClearValue||1},e.stencil&&(i.depthStencilAttachment.stencilLoadOp=s.stencilLoadOp,i.depthStencilAttachment.stencilStoreOp=s.stencilStoreOp,i.depthStencilAttachment.stencilClearValue=s.stencilClearValue)}else i.depthStencilAttachment={...s};t.layerDescriptors.push(i)}}_updateDepthLayerDescriptors(e,t,r){for(let i=0;i<r.length;i++){let r=t.layerDescriptors[i];if(r.depthStencilAttachment){let t=r.depthStencilAttachment;e.depth&&(e.clearDepth?(t.depthClearValue=e.clearDepthValue,t.depthLoadOp=mG.Clear):t.depthLoadOp=mG.Load),e.stencil&&(e.clearStencil?(t.stencilClearValue=e.clearStencilValue,t.stencilLoadOp=mG.Clear):t.stencilLoadOp=mG.Load)}}}finishRender(e){let t=this.get(e),r=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),r>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery();let i=t.encoder;if(!0===this._isRenderCameraDepthArray(e)){let r=[];for(let e=0;e<t.bundleEncoders.length;e++){let i=t.bundleEncoders[e];r.push(i.finish())}for(let s=0;s<t.layerDescriptors.length;s++)if(s<r.length){let n=t.layerDescriptors[s],a=i.beginRenderPass(n);if(e.viewport){let{x:t,y:r,width:i,height:s,minDepth:n,maxDepth:o}=e.viewportValue;a.setViewport(t,r,i,s,n,o)}if(e.scissor){let{x:t,y:r,width:i,height:s}=e.scissorValue;a.setScissorRect(t,r,i,s)}a.executeBundles([r[s]]),a.end()}}else t.currentPass&&t.currentPass.end();if(r>0){let i=8*r,s=this.occludedResolveCache.get(i);void 0===s&&(s=this.device.createBuffer({size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(i,s));let n=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,r,s,0),t.encoder.copyBufferToBuffer(s,0,n,0,i),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.device.queue.submit([t.encoder.finish()]),null!==e.textures){let t=e.textures;for(let e=0;e<t.length;e++){let r=t[e];!0===r.generateMipmaps&&this.textureUtils.generateMipmaps(r)}}}isOccluded(e,t){let r=this.get(e);return r.occluded&&r.occluded.has(t)}async resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueryBuffer:r,currentOcclusionQueryObjects:i}=t;if(r&&i){let e=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await r.mapAsync(GPUMapMode.READ);let s=new BigUint64Array(r.getMappedRange());for(let t=0;t<i.length;t++)s[t]===BigInt(0)&&e.add(i[t]);r.destroy(),t.occluded=e}}updateViewport(e){let{currentPass:t}=this.get(e),{x:r,y:i,width:s,height:n,minDepth:a,maxDepth:o}=e.viewportValue;t.setViewport(r,i,s,n,a,o)}getClearColor(){let e=super.getClearColor();return!0===this.renderer.alpha&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,r,i=null){let s,n,a,o,l=this.device,u=this.renderer,d=[];if(e){let e=this.getClearColor();n={r:e.r,g:e.g,b:e.b,a:e.a}}if(null===i){a=u.depth,o=u.stencil;let t=this._getDefaultRenderPassDescriptor();if(e){let e=(d=t.colorAttachments)[0];e.clearValue=n,e.loadOp=mG.Clear,e.storeOp=mO.Store}(a||o)&&(s=t.depthStencilAttachment)}else{a=i.depth,o=i.stencil;let l={loadOp:e?mG.Clear:mG.Load,clearValue:e?n:void 0};a&&(l.depthLoadOp=t?mG.Clear:mG.Load,l.depthClearValue=t?u.getClearDepth():void 0,l.depthStoreOp=mO.Store),o&&(l.stencilLoadOp=r?mG.Clear:mG.Load,l.stencilClearValue=r?u.getClearStencil():void 0,l.stencilStoreOp=mO.Store);let h=this._getRenderPassDescriptor(i,l);d=h.colorAttachments,s=h.depthStencilAttachment}a&&s&&void 0===s.depthLoadOp&&(t?(s.depthLoadOp=mG.Clear,s.depthClearValue=u.getClearDepth()):s.depthLoadOp=mG.Load,s.depthStoreOp=mO.Store),o&&s&&void 0===s.stencilLoadOp&&(r?(s.stencilLoadOp=mG.Clear,s.stencilClearValue=u.getClearStencil()):s.stencilLoadOp=mG.Load,s.stencilStoreOp=mO.Store);let h=l.createCommandEncoder({label:"clear"});h.beginRenderPass({colorAttachments:d,depthStencilAttachment:s}).end(),l.queue.submit([h.finish()])}beginCompute(e){let t=this.get(e),r={label:"computeGroup_"+e.id};this.initTimestampQuery(e,r),t.cmdEncoderGPU=this.device.createCommandEncoder({label:"computeGroup_"+e.id}),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(r)}
303compute(e,t,r,i){let{passEncoderGPU:s}=this.get(e),n=this.get(i).pipeline;s.setPipeline(n);for(let e=0,t=r.length;e<t;e++){let t=r[e],i=this.get(t);s.setBindGroup(e,i.group)}let a=this.device.limits.maxComputeWorkgroupsPerDimension,o=this.get(t);void 0===o.dispatchSize&&(o.dispatchSize={x:0,y:1,z:1});let{dispatchSize:l}=o;t.dispatchCount>a?(l.x=Math.min(t.dispatchCount,a),l.y=Math.ceil(t.dispatchCount/a)):l.x=t.dispatchCount,s.dispatchWorkgroups(l.x,l.y,l.z)}finishCompute(e){let t=this.get(e);t.passEncoderGPU.end(),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){let{object:r,material:i,context:s,pipeline:n}=e,a=e.getBindings(),o=this.get(s),l=this.get(n).pipeline,d=e.getIndex(),h=null!==d,c=e.getDrawParameters();if(null===c)return;let p=(t,r)=>{t.setPipeline(l),r.pipeline=l;let n=r.bindingGroups;for(let e=0,r=a.length;e<r;e++){let r=a[e],i=this.get(r);n[r.index]!==r.id&&(t.setBindGroup(r.index,i.group),n[r.index]=r.id)}if(!0===h&&r.index!==d){let e=this.get(d).buffer,i=d.array instanceof Uint16Array?m$.Uint16:m$.Uint32;t.setIndexBuffer(e,i),r.index=d}let u=e.getVertexBuffers();for(let e=0,i=u.length;e<i;e++){let i=u[e];if(r.attributes[e]!==i){let s=this.get(i).buffer;t.setVertexBuffer(e,s),r.attributes[e]=i}}!0===s.stencil&&!0===i.stencilWrite&&o.currentStencilRef!==i.stencilRef&&(t.setStencilReference(i.stencilRef),o.currentStencilRef=i.stencilRef)},g=(i,s)=>{if(p(i,s),!0===r.isBatchedMesh){let e=r._multiDrawStarts,s=r._multiDrawCounts,n=r._multiDrawCount,a=r._multiDrawInstances;null!==a&&(0,u.mcG)("THREE.WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.");for(let o=0;o<n;o++){let n=a?a[o]:1,l=n>1?0:o;!0===h?i.drawIndexed(s[o],n,e[o]/d.array.BYTES_PER_ELEMENT,0,l):i.draw(s[o],n,e[o],l),t.update(r,s[o],n)}}else if(!0===h){let{vertexCount:s,instanceCount:n,firstVertex:a}=c,o=e.getIndirect();if(null!==o){let e=this.get(o).buffer;i.drawIndexedIndirect(e,0)}else i.drawIndexed(s,n,a,0,0);t.update(r,s,n)}else{let{vertexCount:s,instanceCount:n,firstVertex:a}=c,o=e.getIndirect();if(null!==o){let e=this.get(o).buffer;i.drawIndirect(e,0)}else i.draw(s,n,a,0);t.update(r,s,n)}};if(e.camera.isArrayCamera&&e.camera.cameras.length>0){let t=this.get(e.camera),i=e.camera.cameras,n=e.getBindingGroup("cameraIndex");if(void 0===t.indexesGPU||t.indexesGPU.length!==i.length){let e=this.get(n),r=[],s=new Uint32Array([0,0,0,0]);for(let t=0,n=i.length;t<n;t++){s[0]=t;let i=this.bindingUtils.createBindGroupIndex(s,e.layout);r.push(i)}t.indexesGPU=r}let a=this.renderer.getPixelRatio();for(let e=0,l=i.length;e<l;e++){let l=i[e];if(r.layers.test(l.layers)){let r=l.viewport,i=o.currentPass,u=o.currentSets;if(o.bundleEncoders){let t=o.bundleEncoders[e],r=o.bundleSets[e];i=t,u=r}r&&i.setViewport(Math.floor(r.x*a),Math.floor(r.y*a),Math.floor(r.width*a),Math.floor(r.height*a),s.viewportValue.minDepth,s.viewportValue.maxDepth),n&&t.indexesGPU&&(i.setBindGroup(n.index,t.indexesGPU[e]),u.bindingGroups[n.index]=n.id),g(i,u)}}}else if(o.currentPass){if(void 0!==o.occlusionQuerySet){let e=o.lastOcclusionObject;e!==r&&(null!==e&&!0===e.occlusionTest&&(o.currentPass.endOcclusionQuery(),o.occlusionQueryIndex++),!0===r.occlusionTest&&(o.currentPass.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=r),o.lastOcclusionObject=r)}g(o.currentPass,o.currentSets)}}needsRenderUpdate(e){let t=this.get(e),{object:r,material:i}=e,s=this.utils,n=s.getSampleCountRenderContext(e.context),a=s.getCurrentColorSpace(e.context),o=s.getCurrentColorFormat(e.context),l=s.getCurrentDepthStencilFormat(e.context),u=s.getPrimitiveTopology(r,i),d=!1;return(t.material!==i||t.materialVersion!==i.version||t.transparent!==i.transparent||t.blending!==i.blending||t.premultipliedAlpha!==i.premultipliedAlpha||t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst||t.blendEquation!==i.blendEquation||t.blendSrcAlpha!==i.blendSrcAlpha||t.blendDstAlpha!==i.blendDstAlpha||t.blendEquationAlpha!==i.blendEquationAlpha||t.colorWrite!==i.colorWrite||t.depthWrite!==i.depthWrite||t.depthTest!==i.depthTest||t.depthFunc!==i.depthFunc||t.stencilWrite!==i.stencilWrite||t.stencilFunc!==i.stencilFunc||t.stencilFail!==i.stencilFail||t.stencilZFail!==i.stencilZFail||t.stencilZPass!==i.stencilZPass||t.stencilFuncMask!==i.stencilFuncMask||t.stencilWriteMask!==i.stencilWriteMask||t.side!==i.side||t.alphaToCoverage!==i.alphaToCoverage||t.sampleC
303ount!==n||t.colorSpace!==a||t.colorFormat!==o||t.depthStencilFormat!==l||t.primitiveTopology!==u||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(t.material=i,t.materialVersion=i.version,t.transparent=i.transparent,t.blending=i.blending,t.premultipliedAlpha=i.premultipliedAlpha,t.blendSrc=i.blendSrc,t.blendDst=i.blendDst,t.blendEquation=i.blendEquation,t.blendSrcAlpha=i.blendSrcAlpha,t.blendDstAlpha=i.blendDstAlpha,t.blendEquationAlpha=i.blendEquationAlpha,t.colorWrite=i.colorWrite,t.depthWrite=i.depthWrite,t.depthTest=i.depthTest,t.depthFunc=i.depthFunc,t.stencilWrite=i.stencilWrite,t.stencilFunc=i.stencilFunc,t.stencilFail=i.stencilFail,t.stencilZFail=i.stencilZFail,t.stencilZPass=i.stencilZPass,t.stencilFuncMask=i.stencilFuncMask,t.stencilWriteMask=i.stencilWriteMask,t.side=i.side,t.alphaToCoverage=i.alphaToCoverage,t.sampleCount=n,t.colorSpace=a,t.colorFormat=o,t.depthStencilFormat=l,t.primitiveTopology=u,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){let{object:t,material:r}=e,i=this.utils,s=e.context;return[r.transparent,r.blending,r.premultipliedAlpha,r.blendSrc,r.blendDst,r.blendEquation,r.blendSrcAlpha,r.blendDstAlpha,r.blendEquationAlpha,r.colorWrite,r.depthWrite,r.depthTest,r.depthFunc,r.stencilWrite,r.stencilFunc,r.stencilFail,r.stencilZFail,r.stencilZPass,r.stencilFuncMask,r.stencilWriteMask,r.side,i.getSampleCountRenderContext(s),i.getCurrentColorSpace(s),i.getCurrentColorFormat(s),i.getCurrentDepthStencilFormat(s),i.getPrimitiveTopology(t,r),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}async copyTextureToBuffer(e,t,r,i,s,n){return this.textureUtils.copyTextureToBuffer(e,t,r,i,s,n)}initTimestampQuery(e,t){if(!this.trackTimestamp)return;let r=e.isComputeNode?"compute":"render";this.timestampQueryPool[r]||(this.timestampQueryPool[r]=new fM(this.device,r,2048));let i=this.timestampQueryPool[r],s=i.allocateQueriesForContext(e);t.timestampWrites={querySet:i.querySet,beginningOfPassWriteIndex:s,endOfPassWriteIndex:s+1}}createNodeBuilder(e,t){return new fv(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage+(""!==e.name?`_${e.name}`:"")}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){let t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){let r=this.get(e),i=r.currentPass.finish();this.get(t).bundleGPU=i,r.currentSets=r._currentSets,r.currentPass=r._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,r,i){this.bindingUtils.createBindings(e,t,r,i)}updateBindings(e,t,r,i){this.bindingUtils.createBindings(e,t,r,i)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}
303copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){let a=0,o=0,l=0,u=0,d=0,h=0,c=e.image.width,p=e.image.height,g=1;null!==r&&(!0===r.isBox3?(u=r.min.x,d=r.min.y,h=r.min.z,c=r.max.x-r.min.x,p=r.max.y-r.min.y,g=r.max.z-r.min.z):(u=r.min.x,d=r.min.y,c=r.max.x-r.min.x,p=r.max.y-r.min.y,g=1)),null!==i&&(a=i.x,o=i.y,l=i.z||0);let m=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),f=this.get(e).texture,y=this.get(t).texture;m.copyTextureToTexture({texture:f,mipLevel:s,origin:{x:u,y:d,z:h}},{texture:y,mipLevel:n,origin:{x:a,y:o,z:l}},[c,p,g]),this.device.queue.submit([m.finish()]),0===n&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,r){let i,s=this.get(t),n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();let a=this.get(e).texture;if(n.format!==a.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,a.format);if(s.currentPass?(s.currentPass.end(),i=s.encoder):i=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),i.copyTextureToTexture({texture:n,origin:[r.x,r.y,0]},{texture:a},[r.z,r.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),s.currentPass){let{descriptor:e}=s;for(let t=0;t<e.colorAttachments.length;t++)e.colorAttachments[t].loadOp=mG.Load;if(t.depth&&(e.depthStencilAttachment.depthLoadOp=mG.Load),t.stencil&&(e.depthStencilAttachment.stencilLoadOp=mG.Load),s.currentPass=i.beginRenderPass(e),s.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor){let{x:e,y:r,width:i,height:n}=t.scissorValue;s.currentPass.setScissorRect(e,r,i,n)}}else this.device.queue.submit([i.finish()])}}class fP extends u.nCl{constructor(e,t,r,i,s,n){super(e,t,r,i,s,n),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class fF extends gO{constructor(){super(),this.addMaterial(oW,"MeshPhongMaterial"),this.addMaterial(uu,"MeshStandardMaterial"),this.addMaterial(uh,"MeshPhysicalMaterial"),this.addMaterial(um,"MeshToonMaterial"),this.addMaterial(oU,"MeshBasicMaterial"),this.addMaterial(oz,"MeshLambertMaterial"),this.addMaterial(o_,"MeshNormalMaterial"),this.addMaterial(ub,"MeshMatcapMaterial"),this.addMaterial(op,"LineBasicMaterial"),this.addMaterial(om,"LineDashedMaterial"),this.addMaterial(uR,"PointsMaterial"),this.addMaterial(uS,"SpriteMaterial"),this.addMaterial(uw,"ShadowMaterial"),this.addLight(cZ,u.HiM),this.addLight(gp,u.ZyN),this.addLight(gy,u.ure),this.addLight(gx,u.nCl),this.addLight(gT,u.$p8),this.addLight(g_,u.dth),this.addLight(gv,u.FZo),this.addLight(gb,fP),this.addToneMapping(hP,u.kyO),this.addToneMapping(hF,u.Mjd),this.addToneMapping(hL,u.nNL),this.addToneMapping(hI,u.FV),this.addToneMapping(hG,u.LAk),this.addToneMapping(hk,u.aJ8)}}class fL extends g8{constructor(e={}){let t;e.forceWebGL?t=mI:(t=fB,e.getFallback=()=>(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new mI(e))),super(new t(e),e),this.library=new fF,this.isWebGPURenderer=!0,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}}u.YJl,u.gPd,u.aHM,u.jut,u.XTe,u.YJl}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.