mirror of
https://github.com/samvallad33/vestige.git
synced 2026-07-04 22:02:14 +02:00
* patch(backfill-safety): VESTIGE_BACKFILL_AUTOFIRE gate (default OFF) + bounded promote_memory_backfill
Off-by-default env gate around step-8.5 auto-fire in run_consolidation (decouples
backfill from consolidation cadence). New promote_memory_backfill caps stability at
MIN(stability*1.5, stability+365.0) (the bound retroactive_backfill.rs:300 already
computes but discarded); both backfill entry points use it. Fixes the false 'capped'
comment. Cloud-sync excluded at build (--no-default-features). Pending upstream PR to
samvallad33/vestige. omega-backfill-safety-v2.2.0 off tag v2.2.0 (3bcd4667).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* release: v2.2.1 — Windows embeddings fix + backfill safety + first-run guide
Board-clearing patch release.
Fixes:
- #101 Windows embeddings: release.yml already restores vector-search on the
x86_64-pc-windows-msvc target (merged in #102); this release rebuilds the
Windows binary so users actually get working embeddings.
- #103 Retroactive Salience Backfill safety (from community PR #104, adjusted):
* promote_memory_backfill bounds the stability multiply to
MIN(stability*1.5, stability+365.0) on both auto-fire and manual paths.
* VESTIGE_BACKFILL_AUTOFIRE gate — default ON (preserves the shipped/documented
v2.2.0 behavior), disable with 0/false/off/no. Env value is trimmed.
* Corrected the false "capped" comment and the promote_memory_backfill doc.
* Added 3 tests: +365 cap binds, *1.5 multiply below crossover, gate parsing.
Docs:
- #83 First-Run: new docs/GETTING-STARTED.md + README pointer.
- Consolidated roadmap issues #82,#84-#92 into docs/ROADMAP.md (Tracked Issues).
- Documented VESTIGE_BACKFILL_AUTOFIRE in docs/CONFIGURATION.md.
- CHANGELOG v2.2.1 entry.
Version bumped to 2.2.1 across all manifests + Cargo.lock + dashboard build.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Peter Lauzon <inbijiburu@protonmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
376 lines
479 KiB
JavaScript
376 lines
479 KiB
JavaScript
import{C as mt,S as vg,c as Ag,d as Rg,G as ll,e as _t,f as Ku,a as Yn,g as Zs,h as Js,W as ln,i as Pn,B as Ct,j as dl,k as Cg,D as zs,l as oa,m as hl,V as j,L as pl,N as en,n as Eg,o as fl,p as wg,q as Mg,r as Bg,s as Fg,t as Ug,u as Pg,v as Dg,E as gl,M as ml,R as Ss,w as ft,x as _o,y as Xs,z as ms,b as Ye,F as Me,J as ze,U as Le,K as yl,O as xl,Q as Lg,T as Ig,X as Xu,Y as Ys,Z as Vg,_ as Gg,$ as Yu,a0 as Og,a1 as tn,a2 as Tl,a3 as kg,a4 as _l,a5 as aa,a6 as vs,H as pt,a7 as ss,a8 as kt,a9 as Ie,aa as Dn,ab as zg,ac as Wg,ad as ua,ae as fr,af as Ln,ag as $g,ah as Hg,ai as Ur,aj as bl,ak as qg,al as Kg,am as Xg,an as Yg,ao as ot,ap as jg,aq as Nl,ar as Qg,as as bo,at as Sl,au as sn,av as ju,aw as Zg,ax as Jg,ay as vl,az as q,aA as em,aB as tm,aC as No,aD as js,aE as sm,aF as nm,aG as rm,aH as im,aI as om,aJ as am,aK as um,aL as cm,aM as lm,aN as dm,aO as hm,aP as pm,aQ as fm,aR as gm,aS as jn,aT as Qn,aU as mm,aV as oi,aW as ai,aX as ui,aY as ys,aZ as ym,a_ as ci,a$ as ca,b0 as li,b1 as So,b2 as bt,b3 as Al,b4 as Rl,b5 as Cl,b6 as El,b7 as wl,b8 as Ml,b9 as Bl,ba as Fl,bb as Ul,bc as Gs,bd as Pl,be as Dl,bf as Ll,bg as Il,bh as Vl,bi as Gl,bj as Ol,bk as kl,bl as zl,bm as Wl,bn as $l,bo as xm,bp as Tm,bq as _m,br as Hl,bs as $r,bt as Hr,A as qr,bu as ql,bv as Kl,bw as Xl,bx as Yl,by as jl,bz as Ql,bA as Zl,bB as Jl,bC as bm,bD as Nm,bE as ed,bF as An,bG as Rn,bH as Ws,bI as Sm,bJ as la,bK as vm,bL as Am,bM as da,bN as ha,bO as pa,bP as fa,bQ as Li,bR as Pr,bS as Dr,bT as Lr,bU as Qu,bV as Zu,bW as Ju,bX as ec,bY as tc,bZ as vo,b_ as Ao,b$ as Ro,c0 as Co,c1 as Eo,c2 as wo,c3 as Mo,c4 as Bo,c5 as Fo,c6 as Uo,c7 as Po,c8 as Do,c9 as Lo,ca as Io,cb as Vo,cc as Go,cd as Ii,ce as Rm,cf as sc,cg as nc,ch as rc,ci as Cm,cj as Em,ck as wm,cl as Mm,cm as Bm,cn as Fm,co as Um,cp as Pm,cq as Dm,cr as Lm,cs as Im,ct as Vm,cu as Gm,cv as Om,cw as km,cx as zm,cy as Wm,cz as $m,cA as Hm,cB as qm,cC as Km,cD as td,cE as Xm}from"./C-SOZ1Oi.js";import{cF as RR,cG as CR,cH as ER,cI as wR,cJ as MR,cK as BR,cL as FR,cM as UR,cN as PR,cO as DR,cP as LR,cQ as IR,cR as VR,cS as GR,cT as OR,cU as kR,cV as zR,cW as WR,cX as $R,cY as HR,cZ as qR,c_ as KR,c$ as XR,d0 as YR,d1 as jR,d2 as QR,d3 as ZR,d4 as JR,d5 as e0,d6 as t0,d7 as s0,d8 as n0,d9 as r0,da as i0,db as o0,dc as a0,dd as u0,de as c0,df as l0,dg as d0,dh as h0,di as p0,dj as f0,dk as g0,dl as m0,dm as y0,dn as x0,dp as T0,dq as _0,dr as b0,ds as N0,dt as S0,du as v0,dv as A0,dw as R0,dx as C0,dy as E0,dz as w0,dA as M0,dB as B0,dC as F0,dD as U0,dE as P0,dF as D0,dG as L0,dH as I0,dI as V0,dJ as G0,dK as O0,dL as k0,dM as z0,dN as W0,dO as $0,dP as H0,dQ as q0,dR as K0,dS as X0,dT as Y0,I as j0,dU as Q0,dV as Z0,dW as J0,dX as eC,dY as tC,dZ as sC,d_ as nC,d$ as rC,e0 as iC,e1 as oC,e2 as aC,e3 as uC,e4 as cC,e5 as lC,e6 as dC,e7 as hC,e8 as pC,e9 as fC,ea as gC,eb as mC,ec as yC,ed as xC,ee as TC,ef as _C,eg as bC,eh as NC,ei as SC,ej as vC,ek as AC,el as RC,em as CC,en as EC,eo as wC,ep as MC,eq as BC,er as FC,es as UC,et as PC,eu as DC,P as LC,ev as IC,ew as VC,ex as GC,ey as OC,ez as kC,eA as zC,eB as WC,eC as $C,eD as HC,eE as qC,eF as KC,eG as XC,eH as YC,eI as jC,eJ as QC,eK as ZC,eL as JC,eM as eE,eN as tE,eO as sE,eP as nE,eQ as rE,eR as iE,eS as oE,eT as aE,eU as uE,eV as cE,eW as lE,eX as dE,eY as hE,eZ as pE,e_ as fE,e$ as gE,f0 as mE,f1 as yE,f2 as xE,f3 as TE,f4 as _E,f5 as bE,f6 as NE,f7 as SE,f8 as vE,f9 as AE,fa as RE,fb as CE,fc as EE,fd as wE,fe as ME,ff as BE,fg as FE,fh as UE,fi as PE,fj as DE,fk as LE,fl as IE,fm as VE,fn as GE,fo as OE,fp as kE,fq as zE,fr as WE,fs as $E,ft as HE,fu as qE,fv as KE,fw as XE,fx as YE,fy as jE,fz as QE,fA as ZE}from"./C-SOZ1Oi.js";/**
|
|
* @license
|
|
* Copyright 2010-2024 Three.js Authors
|
|
* SPDX-License-Identifier: MIT
|
|
*/const Ym=["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 jm{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=e.object.isSkinnedMesh===!0,this.refreshUniforms=Ym,this.renderId=0}firstInitialization(e){return this.renderObjects.has(e)===!1?(this.getRenderObjectData(e),!0):!1}getRenderObjectData(e){let t=this.renderObjects.get(e);if(t===void 0){const{geometry:s,material:n,object:r}=e;if(t={material:this.getMaterialData(n),geometry:{attributes:this.getAttributesData(s.attributes),indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:r.matrixWorld.clone()},r.center&&(t.center=r.center.clone()),r.morphTargetInfluences&&(t.morphTargetInfluences=r.morphTargetInfluences.slice()),e.bundle!==null&&(t.version=e.bundle.version),t.material.transmission>0){const{width:i,height:a}=e.context;t.bufferWidth=i,t.bufferHeight=a}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const n=e[s];t[s]={version:n.version}}return t}containsNode(e){const t=e.material;for(const s in t)if(t[s]&&t[s].isNode)return!0;return e.renderer.nodes.modelViewMatrix!==null||e.renderer.nodes.modelNormalViewMatrix!==null}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const n=e[s];n!=null&&(typeof n=="object"&&n.clone!==void 0?n.isTexture===!0?t[s]={id:n.id,version:n.version}:t[s]=n.clone():t[s]=n)}return t}equals(e){const{object:t,material:s,geometry:n}=e,r=this.getRenderObjectData(e);if(r.worldMatrix.equals(t.matrixWorld)!==!0)return r.worldMatrix.copy(t.matrixWorld),!1;const i=r.material;for(const m in i){const x=i[m],N=s[m];if(x.equals!==void 0){if(x.equals(N)===!1)return x.copy(N),!1}else if(N.isTexture===!0){if(x.id!==N.id||x.version!==N.version)return x.id=N.id,x.version=N.version,!1}else if(x!==N)return i[m]=N,!1}if(i.transmission>0){const{width:m,height:x}=e.context;if(r.bufferWidth!==m||r.bufferHeight!==x)return r.bufferWidth=m,r.bufferHeight=x,!1}const a=r.geometry,u=n.attributes,c=a.attributes,l=Object.keys(c),d=Object.keys(u);if(l.length!==d.length)return r.geometry.attributes=this.getAttributesData(u),!1;for(const m of l){const x=c[m],N=u[m];if(N===void 0)return delete c[m],!1;if(x.version!==N.version)return x.version=N.version,!1}const h=n.index,p=a.indexVersion,f=h?h.version:null;if(p!==f)return a.indexVersion=f,!1;if(a.drawRange.start!==n.drawRange.start||a.drawRange.count!==n.drawRange.count)return a.drawRange.start=n.drawRange.start,a.drawRange.count=n.drawRange.count,!1;if(r.morphTargetInfluences){let m=!1;for(let x=0;x<r.morphTargetInfluences.length;x++)r.morphTargetInfluences[x]!==t.morphTargetInfluences[x]&&(m=!0);if(m)return!0}return r.center&&r.center.equals(t.center)===!1?(r.center.copy(t.center),!0):(e.bundle!==null&&(r.version=e.bundle.version),!0)}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e))return!0;const{renderId:s}=t;if(this.renderId!==s)return this.renderId=s,!0;const n=e.object.static===!0,r=e.bundle!==null&&e.bundle.static===!0&&this.getRenderObjectData(e).version===e.bundle.version;return n||r?!1:this.equals(e)!==!0}}function In(o,e=0){let t=3735928559^e,s=1103547991^e;if(o instanceof Array)for(let n=0,r;n<o.length;n++)r=o[n],t=Math.imul(t^r,2654435761),s=Math.imul(s^r,1597334677);else for(let n=0,r;n<o.length;n++)r=o.charCodeAt(n),t=Math.imul(t^r,2654435761),s=Math.imul(s^r,1597334677);return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&s)+(t>>>0)}const ga=o=>In(o),Zn=o=>In(o),di=(...o)=>In(o);function ma(o,e=!1){const t=[];o.isNode===!0&&(t.push(o.id),o=o.getSelf());for(const{property:s,childNode:n}of Vn(o))t.push(t,In(s.slice(0,-4)),n.getCacheKey(e));return In(t)}function*Vn(o,e=!1){for(const t in o){if(t.startsWith("_")===!0)continue;const s=o[t];if(Array.isArray(s)===!0)for(let n=0;n<s.length;n++){const r=s[n];r&&(r.isNode===!0||e&&typeof r.toJSON=="function")&&(yield{property:t,index:n,childNode:r})}else if(s&&s.isNode===!0)yield{property:t,childNode:s};else if(typeof s=="object")for(const n in s){const r=s[n];r&&(r.isNode===!0||e&&typeof r.toJSON=="function")&&(yield{property:t,index:n,childNode:r})}}}const Qm=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),ic=new WeakMap;function ya(o){return Qm.get(o)}function xa(o){if(/[iu]?vec\d/.test(o))return o.startsWith("ivec")?Int32Array:o.startsWith("uvec")?Uint32Array:Float32Array;if(/mat\d/.test(o)||/float/.test(o))return Float32Array;if(/uint/.test(o))return Uint32Array;if(/int/.test(o))return Int32Array;throw new Error(`THREE.NodeUtils: Unsupported type: ${o}`)}function Ta(o){if(/float|int|uint/.test(o))return 1;if(/vec2/.test(o))return 2;if(/vec3/.test(o))return 3;if(/vec4/.test(o))return 4;if(/mat3/.test(o))return 9;if(/mat4/.test(o))return 16;console.error("THREE.TSL: Unsupported type:",o)}function Ot(o){if(o==null)return null;const e=typeof o;return o.isNode===!0?"node":e==="number"?"float":e==="boolean"?"bool":e==="string"?"string":e==="function"?"shader":o.isVector2===!0?"vec2":o.isVector3===!0?"vec3":o.isVector4===!0?"vec4":o.isMatrix3===!0?"mat3":o.isMatrix4===!0?"mat4":o.isColor===!0?"color":o instanceof ArrayBuffer?"ArrayBuffer":null}function _a(o,...e){const t=o?o.slice(-4):void 0;return e.length===1&&(t==="vec2"?e=[e[0],e[0]]:t==="vec3"?e=[e[0],e[0],e[0]]:t==="vec4"&&(e=[e[0],e[0],e[0],e[0]])),o==="color"?new mt(...e):t==="vec2"?new Ye(...e):t==="vec3"?new j(...e):t==="vec4"?new Me(...e):t==="mat3"?new Yn(...e):t==="mat4"?new Ie(...e):o==="bool"?e[0]||!1:o==="float"||o==="int"||o==="uint"?e[0]||0:o==="string"?e[0]||"":o==="ArrayBuffer"?Sa(e[0]):null}function ba(o){let e=ic.get(o);return e===void 0&&(e={},ic.set(o,e)),e}function Na(o){let e="";const t=new Uint8Array(o);for(let s=0;s<t.length;s++)e+=String.fromCharCode(t[s]);return btoa(e)}function Sa(o){return Uint8Array.from(atob(o),e=>e.charCodeAt(0)).buffer}var cR=Object.freeze({__proto__:null,arrayBufferToBase64:Na,base64ToArrayBuffer:Sa,getCacheKey:ma,getDataFromObject:ba,getLengthFromType:Ta,getNodeChildren:Vn,getTypeFromLength:ya,getTypedArrayFromType:xa,getValueFromType:_a,getValueType:Ot,hash:di,hashArray:Zn,hashString:ga});const Oo={VERTEX:"vertex",FRAGMENT:"fragment"},W={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Zm={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Ve={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},sd=["fragment","vertex"],ko=["setup","analyze","generate"],zo=[...sd,"compute"],As=["x","y","z","w"];let Jm=0;class O extends gl{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=ml.generateUUID(),this.version=0,this.global=!1,this.isNode=!0,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:Jm++})}set needsUpdate(e){e===!0&&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(const{childNode:e}of Vn(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return e=e||this.version!==this._cacheKeyVersion,(e===!0||this._cacheKey===null)&&(this._cacheKey=di(ma(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){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const n of this.getChildren())t["node"+s++]=n;return t.outputNode||null}analyze(e){if(e.increaseUsage(this)===1){const s=e.getNodeProperties(this);for(const n of Object.values(s))n&&n.isNode===!0&&n.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&s.isNode===!0)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let n=null;const r=e.getBuildStage();if(r==="setup"){this.updateReference(e);const i=e.getNodeProperties(this);if(i.initialized!==!0){i.initialized=!0;const a=this.setup(e),u=a&&a.isNode===!0;for(const c of Object.values(i))c&&c.isNode===!0&&c.build(e);u&&a.build(e),i.outputNode=a}}else if(r==="analyze")this.analyze(e);else if(r==="generate")if(this.generate.length===1){const a=this.getNodeType(e),u=e.getDataFromNode(this);n=u.snippet,n===void 0?(n=this.generate(e)||"",u.snippet=n):u.flowCodes!==void 0&&e.context.nodeBlock!==void 0&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),n=e.format(n,a,t)}else n=this.generate(e,t)||"";return e.removeChain(this),e.addSequentialNode(this),n}getSerializeChildren(){return Vn(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:n,index:r,childNode:i}of t)r!==void 0?(s[n]===void 0&&(s[n]=Number.isInteger(r)?[]:{}),s[n][r]=i.toJSON(e.meta).uuid):s[n]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(e.inputNodes!==void 0){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const n=[];for(const r of e.inputNodes[s])n.push(t[r]);this[s]=n}else if(typeof e.inputNodes[s]=="object"){const n={};for(const r in e.inputNodes[s]){const i=e.inputNodes[s][r];n[r]=t[i]}this[s]=n}else{const n=e.inputNodes[s];this[s]=t[n]}}}toJSON(e){const{uuid:t,type:s}=this,n=e===void 0||typeof e=="string";n&&(e={textures:{},images:{},nodes:{}});let r=e.nodes[t];r===void 0&&(r={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},n!==!0&&(e.nodes[r.uuid]=r),this.serialize(r),delete r.meta);function i(a){const u=[];for(const c in a){const l=a[c];delete l.metadata,u.push(l)}return u}if(n){const a=i(e.textures),u=i(e.images),c=i(e.nodes);a.length>0&&(r.textures=a),u.length>0&&(r.images=u),c.length>0&&(r.nodes=c)}return r}}class Rs extends O{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){const t=this.node.build(e),s=this.indexNode.build(e,"uint");return`${t}[ ${s} ]`}}class nd extends O{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const n of this.convertTo.split("|"))(s===null||e.getTypeLength(t)===e.getTypeLength(n))&&(s=n);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,n=this.getNodeType(e),r=s.build(e,n);return e.format(r,n,t)}}class be extends O{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(e.getBuildStage()==="generate"){const n=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(r.propertyName!==void 0)return e.format(r.propertyName,n,t);if(n!=="void"&&t!=="void"&&this.hasDependencies(e)){const i=super.build(e,n),a=e.getVarFromNode(this,null,n),u=e.getPropertyName(a);return e.addLineFlowCode(`${u} = ${i}`,this),r.snippet=i,r.propertyName=u,e.format(r.propertyName,n,t)}}return super.build(e,t)}}class ey extends be{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,s)=>t+e.getTypeLength(s.getNodeType(e)),0))}generate(e,t){const s=this.getNodeType(e),n=this.nodes,r=e.getComponentType(s),i=[];for(const u of n){let c=u.build(e);const l=e.getComponentType(u.getNodeType(e));l!==r&&(c=e.format(c,l,r)),i.push(c)}const a=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(a,s,t)}}const ty=As.join("");class Wo extends O{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(const t of this.components)e=Math.max(As.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){const s=this.node,n=e.getTypeLength(s.getNodeType(e));let r=null;if(n>1){let i=null;this.getVectorLength()>=n&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const u=s.build(e,i);this.components.length===n&&this.components===ty.slice(0,this.components.length)?r=e.format(u,i,t):r=e.format(`${u}.${this.components}`,this.getNodeType(e),t)}else r=s.build(e,t);return r}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class sy extends be{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:n}=this,r=this.getNodeType(e),i=e.getComponentType(n.getNodeType(e)),a=e.getTypeFromLength(s.length,i),u=n.build(e,a),c=t.build(e,r),l=e.getTypeLength(r),d=[];for(let h=0;h<l;h++){const p=As[h];p===s[0]?(d.push(u),h+=s.length-1):d.push(c+"."+p)}return`${e.getType(r)}( ${d.join(", ")} )`}}class ny extends be{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{components:t,sourceNode:s}=this,n=this.getNodeType(e),r=s.build(e),i=e.getVarFromNode(this),a=e.getPropertyName(i);e.addLineFlowCode(a+" = "+r,this);const u=e.getTypeLength(n),c=[];let l=0;for(let d=0;d<u;d++){const h=As[d];h===t[l]?(c.push("1.0 - "+(a+"."+h)),l++):c.push(a+"."+h)}return`${e.getType(n)}( ${c.join(", ")} )`}}class va extends O{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return this.nodeType===null?Ot(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=Ot(this.value),e.nodeType=this.nodeType,e.valueType==="ArrayBuffer"&&(e.value=Na(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?_a(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.")}}class yt extends va{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){const s=this.getNodeType(e);return e.format(this.generateConst(e),s,t)}}let nn=null;const $s=new Map;function R(o,e){if($s.has(o)){console.warn(`Redefinition of method chaining ${o}`);return}if(typeof e!="function")throw new Error(`Node element ${o} is not a function`);$s.set(o,e)}const rd=o=>o.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),oc=o=>rd(o).split("").sort().join(""),id={setup(o,e){const t=e.shift();return o(Jn(t),...e)},get(o,e,t){if(typeof e=="string"&&o[e]===void 0){if(o.isStackNode!==!0&&e==="assign")return(...s)=>(nn.assign(t,...s),t);if($s.has(e)){const s=$s.get(e);return o.isStackNode?(...n)=>t.add(s(...n)):(...n)=>s(t,...n)}else{if(e==="self")return o;if(e.endsWith("Assign")&&$s.has(e.slice(0,e.length-6))){const s=$s.get(e.slice(0,e.length-6));return o.isStackNode?(...n)=>t.assign(n[0],s(...n)):(...n)=>t.assign(s(t,...n))}else{if(/^[xyzwrgbastpq]{1,4}$/.test(e)===!0)return e=rd(e),E(new Wo(t,e));if(/^set[XYZWRGBASTPQ]{1,4}$/.test(e)===!0)return e=oc(e.slice(3).toLowerCase()),s=>E(new sy(o,e,s));if(/^flip[XYZWRGBASTPQ]{1,4}$/.test(e)===!0)return e=oc(e.slice(4).toLowerCase()),()=>E(new ny(E(o),e));if(e==="width"||e==="height"||e==="depth")return e==="width"?e="x":e==="height"?e="y":e==="depth"&&(e="z"),E(new Wo(o,e));if(/^\d+$/.test(e)===!0)return E(new Rs(t,new yt(Number(e),"uint")))}}}return Reflect.get(o,e,t)},set(o,e,t,s){return typeof e=="string"&&o[e]===void 0&&(/^[xyzwrgbastpq]{1,4}$/.test(e)===!0||e==="width"||e==="height"||e==="depth"||/^\d+$/.test(e)===!0)?(s[e].assign(t),!0):Reflect.set(o,e,t,s)}},Vi=new WeakMap,ac=new WeakMap,ry=function(o,e=null){const t=Ot(o);if(t==="node"){let s=Vi.get(o);return s===void 0&&(s=new Proxy(o,id),Vi.set(o,s),Vi.set(s,s)),s}else{if(e===null&&(t==="float"||t==="boolean")||t&&t!=="shader"&&t!=="string")return E($o(o,e));if(t==="shader")return b(o)}return o},iy=function(o,e=null){for(const t in o)o[t]=E(o[t],e);return o},oy=function(o,e=null){const t=o.length;for(let s=0;s<t;s++)o[s]=E(o[s],e);return o},ay=function(o,e=null,t=null,s=null){const n=r=>E(s!==null?Object.assign(r,s):r);return e===null?(...r)=>n(new o(...xs(r))):t!==null?(t=E(t),(...r)=>n(new o(e,...xs(r),t))):(...r)=>n(new o(e,...xs(r)))},uy=function(o,...e){return E(new o(...xs(e)))};class cy extends O{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,n=e.getNodeProperties(t);if(n.onceOutput)return n.onceOutput;let r=null;if(t.layout){let i=ac.get(e.constructor);i===void 0&&(i=new WeakMap,ac.set(e.constructor,i));let a=i.get(t);a===void 0&&(a=E(e.buildFunctionNode(t)),i.set(t,a)),e.currentFunctionNode!==null&&e.currentFunctionNode.includes.push(a),r=E(a.call(s))}else{const i=t.jsFunc,a=s!==null?i(s,e):i(e);r=E(a)}return t.once&&(n.onceOutput=r),r}getOutputNode(e){const t=e.getNodeProperties(this);return t.outputNode===null&&(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 ly extends O{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 Jn(e),E(new cy(this,e))}setup(){return this.call()}}const dy=[!1,!0],hy=[0,1,2,3],py=[-1,-2],od=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Aa=new Map;for(const o of dy)Aa.set(o,new yt(o));const Ra=new Map;for(const o of hy)Ra.set(o,new yt(o,"uint"));const Ca=new Map([...Ra].map(o=>new yt(o.value,"int")));for(const o of py)Ca.set(o,new yt(o,"int"));const hi=new Map([...Ca].map(o=>new yt(o.value)));for(const o of od)hi.set(o,new yt(o));for(const o of od)hi.set(-o,new yt(-o));const pi={bool:Aa,uint:Ra,ints:Ca,float:hi},uc=new Map([...Aa,...hi]),$o=(o,e)=>uc.has(o)?uc.get(o):o.isNode===!0?o:new yt(o,e),fy=o=>{try{return o.getNodeType()}catch{return}},ve=function(o,e=null){return(...t)=>{if((t.length===0||!["bool","float","int","uint"].includes(o)&&t.every(n=>typeof n!="object"))&&(t=[_a(o,...t)]),t.length===1&&e!==null&&e.has(t[0]))return E(e.get(t[0]));if(t.length===1){const n=$o(t[0],o);return fy(n)===o?E(n):E(new nd(n,o))}const s=t.map(n=>$o(n));return E(new ey(s,o))}},Gn=o=>typeof o=="object"&&o!==null?o.value:o,ad=o=>o!=null?o.nodeType||o.convertTo||(typeof o=="string"?o:null):null;function Cn(o,e){return new Proxy(new ly(o,e),id)}const E=(o,e=null)=>ry(o,e),Jn=(o,e=null)=>new iy(o,e),xs=(o,e=null)=>new oy(o,e),C=(...o)=>new ay(...o),U=(...o)=>new uy(...o),b=(o,e)=>{const t=new Cn(o,e),s=(...n)=>{let r;return Jn(n),n[0]&&n[0].isNode?r=[...n]:r=n[0],t.call(r)};return s.shaderNode=t,s.setLayout=n=>(t.setLayout(n),s),s.once=()=>(t.once=!0,s),s},gy=(...o)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),b(...o));R("toGlobal",o=>(o.global=!0,o));const On=o=>{nn=o},Ea=()=>nn,z=(...o)=>nn.If(...o);function ud(o){return nn&&nn.add(o),o}R("append",ud);const cd=new ve("color"),g=new ve("float",pi.float),y=new ve("int",pi.ints),D=new ve("uint",pi.uint),Ht=new ve("bool",pi.bool),M=new ve("vec2"),Ae=new ve("ivec2"),ld=new ve("uvec2"),dd=new ve("bvec2"),T=new ve("vec3"),hd=new ve("ivec3"),dn=new ve("uvec3"),wa=new ve("bvec3"),P=new ve("vec4"),pd=new ve("ivec4"),fd=new ve("uvec4"),gd=new ve("bvec4"),fi=new ve("mat2"),Oe=new ve("mat3"),Ts=new ve("mat4"),my=(o="")=>E(new yt(o,"string")),yy=o=>E(new yt(o,"ArrayBuffer"));R("toColor",cd);R("toFloat",g);R("toInt",y);R("toUint",D);R("toBool",Ht);R("toVec2",M);R("toIVec2",Ae);R("toUVec2",ld);R("toBVec2",dd);R("toVec3",T);R("toIVec3",hd);R("toUVec3",dn);R("toBVec3",wa);R("toVec4",P);R("toIVec4",pd);R("toUVec4",fd);R("toBVec4",gd);R("toMat2",fi);R("toMat3",Oe);R("toMat4",Ts);const md=C(Rs),yd=(o,e)=>E(new nd(E(o),e)),xy=(o,e)=>E(new Wo(E(o),e));R("element",md);R("convert",yd);class xd extends O{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.shared=t,this.order=s,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}}const Td=o=>new xd(o),Ma=(o,e=0)=>new xd(o,!0,e),_d=Ma("frame"),k=Ma("render"),Ba=Td("object");class er extends va{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Ba}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate(n=>{const r=e(n,s);r!==void 0&&(this.value=r)},t)}generate(e,t){const s=this.getNodeType(e),n=this.getUniformHash(e);let r=e.getNodeFromHash(n);r===void 0&&(e.setHashNode(this,n),r=this);const i=r.getInputType(e),a=e.getUniformFromNode(r,i,e.shaderStage,this.name||e.context.label),u=e.getPropertyName(a);return e.context.label!==void 0&&delete e.context.label,e.format(u,s,t)}}const V=(o,e)=>{const t=ad(e||o),s=o&&o.isNode===!0?o.node&&o.node.value||o.value:o;return E(new er(s,t))};class se extends O{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return this.varying===!0?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const Fa=(o,e)=>E(new se(o,e)),et=(o,e)=>E(new se(o,e,!0)),ee=U(se,"vec4","DiffuseColor"),Ho=U(se,"vec3","EmissiveColor"),Nt=U(se,"float","Roughness"),kn=U(se,"float","Metalness"),Kr=U(se,"float","Clearcoat"),zn=U(se,"float","ClearcoatRoughness"),fs=U(se,"vec3","Sheen"),gi=U(se,"float","SheenRoughness"),mi=U(se,"float","Iridescence"),Ua=U(se,"float","IridescenceIOR"),Pa=U(se,"float","IridescenceThickness"),Xr=U(se,"float","AlphaT"),Zt=U(se,"float","Anisotropy"),En=U(se,"vec3","AnisotropyT"),_s=U(se,"vec3","AnisotropyB"),We=U(se,"color","SpecularColor"),Wn=U(se,"float","SpecularF90"),Yr=U(se,"float","Shininess"),$n=U(se,"vec4","Output"),bs=U(se,"float","dashSize"),Hn=U(se,"float","gapSize"),Ty=U(se,"float","pointWidth"),wn=U(se,"float","IOR"),jr=U(se,"float","Transmission"),Da=U(se,"float","Thickness"),La=U(se,"float","AttenuationDistance"),Ia=U(se,"color","AttenuationColor"),Va=U(se,"float","Dispersion");class _y extends be{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return As.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:n}=this,r=this.needsSplitAssign(e),i=s.getNodeType(e),a=s.context({assign:!0}).build(e),u=n.build(e,i),c=n.getNodeType(e),l=e.getDataFromNode(this);let d;if(l.initialized===!0)t!=="void"&&(d=a);else if(r){const h=e.getVarFromNode(this,null,i),p=e.getPropertyName(h);e.addLineFlowCode(`${p} = ${u}`,this);const f=s.node.context({assign:!0}).build(e);for(let m=0;m<s.components.length;m++){const x=s.components[m];e.addLineFlowCode(`${f}.${x} = ${p}[ ${m} ]`,this)}t!=="void"&&(d=a)}else d=`${a} = ${u}`,(t==="void"||c==="void")&&(e.addLineFlowCode(d,this),t!=="void"&&(d=a));return l.initialized=!0,e.format(d,i,t)}}const bd=C(_y);R("assign",bd);class by extends be{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){const t=[],s=this.functionNode,n=s.getInputs(e),r=this.parameters,i=(u,c)=>{const l=c.type,d=l==="pointer";let h;return d?h="&"+u.build(e):h=u.build(e,l),h};if(Array.isArray(r))for(let u=0;u<r.length;u++)t.push(i(r[u],n[u]));else for(const u of n){const c=r[u.name];if(c!==void 0)t.push(i(c,u));else throw new Error(`FunctionCallNode: Input '${u.name}' not found in FunctionNode.`)}return`${s.build(e,"property")}( ${t.join(", ")} )`}}const Nd=(o,...e)=>(e=e.length>1||e[0]&&e[0].isNode===!0?xs(e):Jn(e[0]),E(new by(E(o),e)));R("call",Nd);class pe extends be{static get type(){return"OperatorNode"}constructor(e,t,s,...n){if(super(),n.length>0){let r=new pe(e,t,s);for(let i=0;i<n.length-1;i++)r=new pe(e,r,n[i]);t=r,s=n[n.length-1]}this.op=e,this.aNode=t,this.bNode=s}getNodeType(e,t){const s=this.op,n=this.aNode,r=this.bNode,i=n.getNodeType(e),a=typeof r<"u"?r.getNodeType(e):null;if(i==="void"||a==="void")return"void";if(s==="%")return i;if(s==="~"||s==="&"||s==="|"||s==="^"||s===">>"||s==="<<")return e.getIntegerType(i);if(s==="!"||s==="=="||s==="&&"||s==="||"||s==="^^")return"bool";if(s==="<"||s===">"||s==="<="||s===">="){const u=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(a));return u>1?`bvec${u}`:"bool"}else return i==="float"&&e.isMatrix(a)?a:e.isMatrix(i)&&e.isVector(a)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(a)?e.getVectorFromMatrix(a):e.getTypeLength(a)>e.getTypeLength(i)?a:i}generate(e,t){const s=this.op,n=this.aNode,r=this.bNode,i=this.getNodeType(e,t);let a=null,u=null;i!=="void"?(a=n.getNodeType(e),u=typeof r<"u"?r.getNodeType(e):null,s==="<"||s===">"||s==="<="||s===">="||s==="=="?e.isVector(a)?u=a:a!==u&&(a=u="float"):s===">>"||s==="<<"?(a=i,u=e.changeComponentType(u,"uint")):e.isMatrix(a)&&e.isVector(u)?u=e.getVectorFromMatrix(a):e.isVector(a)&&e.isMatrix(u)?a=e.getVectorFromMatrix(u):a=u=i):a=u=i;const c=n.build(e,a),l=typeof r<"u"?r.build(e,u):null,d=e.getTypeLength(t),h=e.getFunctionOperator(s);if(t!=="void")return s==="<"&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${c}, ${l} )`,i,t):e.format(`( ${c} < ${l} )`,i,t):s==="<="&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${c}, ${l} )`,i,t):e.format(`( ${c} <= ${l} )`,i,t):s===">"&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${c}, ${l} )`,i,t):e.format(`( ${c} > ${l} )`,i,t):s===">="&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${c}, ${l} )`,i,t):e.format(`( ${c} >= ${l} )`,i,t):s==="!"||s==="~"?e.format(`(${s}${c})`,a,t):h?e.format(`${h}( ${c}, ${l} )`,i,t):e.format(`( ${c} ${s} ${l} )`,i,t);if(a!=="void")return h?e.format(`${h}( ${c}, ${l} )`,i,t):e.format(`${c} ${s} ${l}`,i,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const _e=C(pe,"+"),Y=C(pe,"-"),$=C(pe,"*"),gt=C(pe,"/"),Ga=C(pe,"%"),Sd=C(pe,"=="),vd=C(pe,"!="),Ad=C(pe,"<"),Oa=C(pe,">"),Rd=C(pe,"<="),Cd=C(pe,">="),Ed=C(pe,"&&"),wd=C(pe,"||"),Md=C(pe,"!"),Bd=C(pe,"^^"),Fd=C(pe,"&"),Ud=C(pe,"~"),Pd=C(pe,"|"),Dd=C(pe,"^"),Ld=C(pe,"<<"),Id=C(pe,">>");R("add",_e);R("sub",Y);R("mul",$);R("div",gt);R("modInt",Ga);R("equal",Sd);R("notEqual",vd);R("lessThan",Ad);R("greaterThan",Oa);R("lessThanEqual",Rd);R("greaterThanEqual",Cd);R("and",Ed);R("or",wd);R("not",Md);R("xor",Bd);R("bitAnd",Fd);R("bitNot",Ud);R("bitOr",Pd);R("bitXor",Dd);R("shiftLeft",Ld);R("shiftRight",Id);const Vd=(...o)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),Ga(...o));R("remainder",Vd);class S extends be{static get type(){return"MathNode"}constructor(e,t,s=null,n=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=n}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,n=this.cNode?this.cNode.getNodeType(e):null,r=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),a=e.isMatrix(n)?0:e.getTypeLength(n);return r>i&&r>a?t:i>a?s:a>r?n:t}getNodeType(e){const t=this.method;return t===S.LENGTH||t===S.DISTANCE||t===S.DOT?"float":t===S.CROSS?"vec3":t===S.ALL?"bool":t===S.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===S.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){let s=this.method;const n=this.getNodeType(e),r=this.getInputType(e),i=this.aNode,a=this.bNode,u=this.cNode,c=e.renderer.coordinateSystem;if(s===S.TRANSFORM_DIRECTION){let l=i,d=a;e.isMatrix(l.getNodeType(e))?d=P(T(d),0):l=P(T(l),0);const h=$(l,d).xyz;return qt(h).build(e,t)}else{if(s===S.NEGATE)return e.format("( - "+i.build(e,r)+" )",n,t);if(s===S.ONE_MINUS)return Y(1,i).build(e,t);if(s===S.RECIPROCAL)return gt(1,i).build(e,t);if(s===S.DIFFERENCE)return oe(Y(i,a)).build(e,t);{const l=[];return s===S.CROSS||s===S.MOD?l.push(i.build(e,n),a.build(e,n)):c===Pn&&s===S.STEP?l.push(i.build(e,e.getTypeLength(i.getNodeType(e))===1?"float":r),a.build(e,r)):c===Pn&&(s===S.MIN||s===S.MAX)||s===S.MOD?l.push(i.build(e,r),a.build(e,e.getTypeLength(a.getNodeType(e))===1?"float":r)):s===S.REFRACT?l.push(i.build(e,r),a.build(e,r),u.build(e,"float")):s===S.MIX?l.push(i.build(e,r),a.build(e,r),u.build(e,e.getTypeLength(u.getNodeType(e))===1?"float":r)):(c===ln&&s===S.ATAN&&a!==null&&(s="atan2"),l.push(i.build(e,r)),a!==null&&l.push(a.build(e,r)),u!==null&&l.push(u.build(e,r))),e.format(`${e.getMethod(s,n)}( ${l.join(", ")} )`,n,t)}}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}S.ALL="all";S.ANY="any";S.RADIANS="radians";S.DEGREES="degrees";S.EXP="exp";S.EXP2="exp2";S.LOG="log";S.LOG2="log2";S.SQRT="sqrt";S.INVERSE_SQRT="inversesqrt";S.FLOOR="floor";S.CEIL="ceil";S.NORMALIZE="normalize";S.FRACT="fract";S.SIN="sin";S.COS="cos";S.TAN="tan";S.ASIN="asin";S.ACOS="acos";S.ATAN="atan";S.ABS="abs";S.SIGN="sign";S.LENGTH="length";S.NEGATE="negate";S.ONE_MINUS="oneMinus";S.DFDX="dFdx";S.DFDY="dFdy";S.ROUND="round";S.RECIPROCAL="reciprocal";S.TRUNC="trunc";S.FWIDTH="fwidth";S.TRANSPOSE="transpose";S.BITCAST="bitcast";S.EQUALS="equals";S.MIN="min";S.MAX="max";S.MOD="mod";S.STEP="step";S.REFLECT="reflect";S.DISTANCE="distance";S.DIFFERENCE="difference";S.DOT="dot";S.CROSS="cross";S.POW="pow";S.TRANSFORM_DIRECTION="transformDirection";S.MIX="mix";S.CLAMP="clamp";S.REFRACT="refract";S.SMOOTHSTEP="smoothstep";S.FACEFORWARD="faceforward";const Gd=g(1e-6),Ny=g(1e6),Qr=g(Math.PI),Sy=g(Math.PI*2),ka=C(S,S.ALL),Od=C(S,S.ANY),kd=C(S,S.RADIANS),zd=C(S,S.DEGREES),za=C(S,S.EXP),rn=C(S,S.EXP2),yi=C(S,S.LOG),vt=C(S,S.LOG2),Pt=C(S,S.SQRT),Wa=C(S,S.INVERSE_SQRT),At=C(S,S.FLOOR),xi=C(S,S.CEIL),qt=C(S,S.NORMALIZE),Xt=C(S,S.FRACT),st=C(S,S.SIN),It=C(S,S.COS),Wd=C(S,S.TAN),$d=C(S,S.ASIN),Hd=C(S,S.ACOS),$a=C(S,S.ATAN),oe=C(S,S.ABS),qn=C(S,S.SIGN),zt=C(S,S.LENGTH),qd=C(S,S.NEGATE),Kd=C(S,S.ONE_MINUS),Ha=C(S,S.DFDX),qa=C(S,S.DFDY),Xd=C(S,S.ROUND),Yd=C(S,S.RECIPROCAL),Ka=C(S,S.TRUNC),jd=C(S,S.FWIDTH),Qd=C(S,S.TRANSPOSE),vy=C(S,S.BITCAST),Zd=C(S,S.EQUALS),Re=C(S,S.MIN),ue=C(S,S.MAX),Xa=C(S,S.MOD),Ti=C(S,S.STEP),Jd=C(S,S.REFLECT),eh=C(S,S.DISTANCE),th=C(S,S.DIFFERENCE),is=C(S,S.DOT),_i=C(S,S.CROSS),ht=C(S,S.POW),Ya=C(S,S.POW,2),sh=C(S,S.POW,3),nh=C(S,S.POW,4),rh=C(S,S.TRANSFORM_DIRECTION),ih=o=>$(qn(o),ht(oe(o),1/3)),ja=o=>is(o,o),Q=C(S,S.MIX),Et=(o,e=0,t=1)=>E(new S(S.CLAMP,E(o),E(e),E(t))),oh=o=>Et(o),Qa=C(S,S.REFRACT),ct=C(S,S.SMOOTHSTEP),Za=C(S,S.FACEFORWARD),ah=b(([o])=>{const s=43758.5453,n=is(o.xy,M(12.9898,78.233)),r=Xa(n,Qr);return Xt(st(r).mul(s))}),uh=(o,e,t)=>Q(e,t,o),ch=(o,e,t)=>ct(e,t,o),lh=(o,e)=>(console.warn('THREE.TSL: "atan2" is overloaded. Use "atan" instead.'),$a(o,e)),Ay=Za,Ry=Wa;R("all",ka);R("any",Od);R("equals",Zd);R("radians",kd);R("degrees",zd);R("exp",za);R("exp2",rn);R("log",yi);R("log2",vt);R("sqrt",Pt);R("inverseSqrt",Wa);R("floor",At);R("ceil",xi);R("normalize",qt);R("fract",Xt);R("sin",st);R("cos",It);R("tan",Wd);R("asin",$d);R("acos",Hd);R("atan",$a);R("abs",oe);R("sign",qn);R("length",zt);R("lengthSq",ja);R("negate",qd);R("oneMinus",Kd);R("dFdx",Ha);R("dFdy",qa);R("round",Xd);R("reciprocal",Yd);R("trunc",Ka);R("fwidth",jd);R("atan2",lh);R("min",Re);R("max",ue);R("mod",Xa);R("step",Ti);R("reflect",Jd);R("distance",eh);R("dot",is);R("cross",_i);R("pow",ht);R("pow2",Ya);R("pow3",sh);R("pow4",nh);R("transformDirection",rh);R("mix",uh);R("clamp",Et);R("refract",Qa);R("smoothstep",ch);R("faceForward",Za);R("difference",th);R("saturate",oh);R("cbrt",ih);R("transpose",Qd);R("rand",ah);class Cy extends O{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const{ifNode:t,elseNode:s}=e.getNodeProperties(this);if(t===void 0)return this.setup(e),this.getNodeType(e);const n=t.getNodeType(e);if(s!==null){const r=s.getNodeType(e);if(e.getTypeLength(r)>e.getTypeLength(n))return r}return n}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),n=this.elseNode?this.elseNode.cache():null,r=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=r,n!==null&&(e.getDataFromNode(n).parentNodeBlock=r);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=n?n.context({nodeBlock:n}):null}generate(e,t){const s=this.getNodeType(e),n=e.getDataFromNode(this);if(n.nodeProperty!==void 0)return n.nodeProperty;const{condNode:r,ifNode:i,elseNode:a}=e.getNodeProperties(this),u=t!=="void",c=u?Fa(s).build(e):"";n.nodeProperty=c;const l=r.build(e,"bool");e.addFlowCode(`
|
|
${e.tab}if ( ${l} ) {
|
|
|
|
`).addFlowTab();let d=i.build(e,s);if(d&&(u?d=c+" = "+d+";":d="return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+" "+d+`
|
|
|
|
`+e.tab+"}"),a!==null){e.addFlowCode(` else {
|
|
|
|
`).addFlowTab();let h=a.build(e,s);h&&(u?h=c+" = "+h+";":h="return "+h+";"),e.removeFlowTab().addFlowCode(e.tab+" "+h+`
|
|
|
|
`+e.tab+`}
|
|
|
|
`)}else e.addFlowCode(`
|
|
|
|
`);return e.format(c,s,t)}}const Ue=C(Cy);R("select",Ue);const dh=(...o)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),Ue(...o));R("cond",dh);class hh extends O{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){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const n=this.node.build(e,t);return e.setContext(s),n}}const bi=C(hh),ph=(o,e)=>bi(o,{label:e});R("context",bi);R("label",ph);class Ir extends O{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,n=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),r=e.getPropertyName(n),i=t.build(e,n.type);return e.addLineFlowCode(`${r} = ${i}`,this),r}}const fh=C(Ir);R("toVar",(...o)=>fh(...o).append());const gh=o=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),fh(o));R("temp",gh);class Ey extends O{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(s===void 0){const n=this.name,r=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,n,r),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation=e.shaderStage==="fragment"),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e),n=e.shaderStage==="fragment"&&t.reassignPosition===!0&&e.context.needsPositionReassign;if(t.propertyName===void 0||n){const r=this.getNodeType(e),i=e.getPropertyName(s,Oo.VERTEX);e.flowNodeFromShaderStage(Oo.VERTEX,this.node,r,i),t.propertyName=i,n?t.reassignPosition=!1:t.reassignPosition===void 0&&e.context.isPositionNodeInput&&(t.reassignPosition=!0)}return e.getPropertyName(s)}}const ke=C(Ey),mh=o=>ke(o);R("varying",ke);R("vertexStage",mh);const yh=b(([o])=>{const e=o.mul(.9478672986).add(.0521327014).pow(2.4),t=o.mul(.0773993808),s=o.lessThanEqual(.04045);return Q(e,t,s)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),xh=b(([o])=>{const e=o.pow(.41666).mul(1.055).sub(.055),t=o.mul(12.92),s=o.lessThanEqual(.0031308);return Q(e,t,s)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),tr="WorkingColorSpace",Ja="OutputColorSpace";class sr extends be{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===tr?_t.workingColorSpace:t===Ja?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),n=this.resolveColorSpace(e,this.target);let r=t;return _t.enabled===!1||s===n||!s||!n||(_t.getTransfer(s)===Ku&&(r=P(yh(r.rgb),r.a)),_t.getPrimaries(s)!==_t.getPrimaries(n)&&(r=P(Oe(_t._getMatrix(new Yn,s,n)).mul(r.rgb),r.a)),_t.getTransfer(n)===Ku&&(r=P(xh(r.rgb),r.a))),r}}const Th=o=>E(new sr(E(o),tr,Ja)),_h=o=>E(new sr(E(o),Ja,tr)),bh=(o,e)=>E(new sr(E(o),tr,e)),eu=(o,e)=>E(new sr(E(o),e,tr)),wy=(o,e,t)=>E(new sr(E(o),e,t));R("toOutputColorSpace",Th);R("toWorkingColorSpace",_h);R("workingToColorSpace",bh);R("colorSpaceToWorking",eu);let My=class extends Rs{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),n=this.getNodeType();return e.format(t,s,n)}};class Nh extends O{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,n=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=n,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=W.OBJECT}setGroup(e){return this.group=e,this}element(e){return E(new My(this,E(e)))}setNodeType(e){const t=V(null,e).getSelf();this.group!==null&&t.setGroup(this.group),this.node=t}getNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let n=1;n<t.length;n++)s=s[t[n]];return s}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const By=(o,e,t)=>E(new Nh(o,e,t));class Fy extends Nh{static get type(){return"RendererReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.renderer=s,this.setGroup(k)}updateReference(e){return this.reference=this.renderer!==null?this.renderer:e.renderer,this.reference}}const Sh=(o,e,t=null)=>E(new Fy(o,e,t));class Uy extends be{static get type(){return"ToneMappingNode"}constructor(e,t=Ah,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}customCacheKey(){return di(this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===ss)return t;let n=null;const r=e.renderer.library.getToneMappingFunction(s);return r!==null?n=P(r(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=t),n}}const vh=(o,e,t)=>E(new Uy(o,E(e),E(t))),Ah=Sh("toneMappingExposure","float");R("toneMapping",(o,e,t)=>vh(e,t,o));class Py extends va{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,n=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=n,this.usage=vg,this.instanced=!1,this.attribute=null,this.global=!0,e&&e.isBufferAttribute===!0&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(this.bufferStride===0&&this.bufferOffset===0){let t=e.globalCache.getData(this.value);return t===void 0&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return this.bufferType===null&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(this.attribute!==null)return;const t=this.getNodeType(e),s=this.value,n=e.getTypeLength(t),r=this.bufferStride||n,i=this.bufferOffset,a=s.isInterleavedBuffer===!0?s:new Ag(s,r),u=new Rg(a,n,i);a.setUsage(this.usage),this.attribute=u,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),n=e.getPropertyName(s);let r=null;return e.shaderStage==="vertex"||e.shaderStage==="compute"?(this.name=n,r=n):r=ke(this).build(e,t),r}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const nr=(o,e=null,t=0,s=0)=>E(new Py(o,e,t,s)),Rh=(o,e=null,t=0,s=0)=>nr(o,e,t,s).setUsage(zs),Zr=(o,e=null,t=0,s=0)=>nr(o,e,t,s).setInstanced(!0),qo=(o,e=null,t=0,s=0)=>Rh(o,e,t,s).setInstanced(!0);R("toAttribute",o=>nr(o.value));class Dy extends O{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,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(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let n=1;n<t.length;n++)s*=t[n];this.dispatchCount=Math.ceil(e/s)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}generate(e){const{shaderStage:t}=e;if(t==="compute"){const s=this.computeNode.build(e,"void");s!==""&&e.addLineFlowCode(s,this)}}}const Ch=(o,e,t)=>E(new Dy(E(o),e,t));R("compute",Ch);class Ly extends O{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){const t=e.getCache(),s=e.getCacheFromNode(this,this.parent);e.setCache(s);const n=this.node.getNodeType(e);return e.setCache(t),n}build(e,...t){const s=e.getCache(),n=e.getCacheFromNode(this,this.parent);e.setCache(n);const r=this.node.build(e,...t);return e.setCache(s),r}}const Mn=(o,e)=>E(new Ly(E(o),e));R("cache",Mn);class Iy extends O{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){const t=this.callNode.build(e,"void");return t!==""&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const Eh=C(Iy);R("bypass",Eh);class wh extends O{static get type(){return"RemapNode"}constructor(e,t,s,n=g(0),r=g(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=n,this.outHighNode=r,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:n,outHighNode:r,doClamp:i}=this;let a=e.sub(t).div(s.sub(t));return i===!0&&(a=a.clamp()),a.mul(r.sub(n)).add(n)}}const Mh=C(wh,null,null,{doClamp:!1}),Bh=C(wh);R("remap",Mh);R("remapClamp",Bh);class Vr extends O{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),n=this.snippet;if(s==="void")e.addLineFlowCode(n,this);else return e.format(`( ${n} )`,s,t)}}const rs=C(Vr),Fh=o=>(o?Ue(o,rs("discard")):rs("discard")).append(),Vy=()=>rs("return").append();R("discard",Fh);class Gy extends be{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutputNode=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(this.toneMapping!==null?this.toneMapping:e.toneMapping)||ss,n=(this.outputColorSpace!==null?this.outputColorSpace:e.outputColorSpace)||Dn;return s!==ss&&(t=t.toneMapping(s)),n!==Dn&&n!==_t.workingColorSpace&&(t=t.workingToColorSpace(n)),t}}const tu=(o,e=null,t=null)=>E(new Gy(E(o),e,t));R("renderOutput",tu);function Oy(o){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",o)}class Uh extends O{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(t===null){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const n=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(n)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(e.hasGeometryAttribute(t)===!0){const r=e.geometry.getAttribute(t),i=e.getTypeFromAttribute(r),a=e.getAttribute(t,i);return e.shaderStage==="vertex"?e.format(a.name,i,s):ke(this).build(e,s)}else return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}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}}const we=(o,e)=>E(new Uh(o,e)),le=(o=0)=>we("uv"+(o>0?o:""),"vec2");class ky extends O{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),n=this.levelNode===null?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${n} )`,this.getNodeType(e),t)}}const ns=C(ky);class zy extends er{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(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&s.width!==void 0){const{width:n,height:r}=s;this.value=Math.log2(Math.max(n,r))}}}const Ph=C(zy);class wt extends er{static get type(){return"TextureNode"}constructor(e,t=null,s=null,n=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=n,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(t===null)}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 this.value.isDepthTexture===!0?"float":this.value.type===Le?"uvec4":this.value.type===ze?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return le(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return this._matrixUniform===null&&(this._matrixUniform=V(this.value.matrix)),this._matrixUniform.mul(T(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?W.RENDER:W.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&s.flipY===!0||s.isRenderTargetTexture===!0||s.isFramebufferTexture===!0||s.isDepthTexture===!0)&&(this.sampler?t=t.flipY():t=t.setY(y(ns(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;const s=this.value;if(!s||s.isTexture!==!0)throw new Error("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().");let n=this.uvNode;(n===null||e.context.forceUVContext===!0)&&e.context.getUV&&(n=e.context.getUV(this)),n||(n=this.getDefaultUV()),this.updateMatrix===!0&&(n=this.getTransformedUV(n)),n=this.setupUV(e,n);let r=this.levelNode;r===null&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=n,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,this.sampler===!0?"vec2":"ivec2")}generateSnippet(e,t,s,n,r,i,a,u){const c=this.value;let l;return n?l=e.generateTextureLevel(c,t,s,n,i):r?l=e.generateTextureBias(c,t,s,r,i):u?l=e.generateTextureGrad(c,t,s,u,i):a?l=e.generateTextureCompare(c,t,s,a,i):this.sampler===!1?l=e.generateTextureLoad(c,t,s,i):l=e.generateTexture(c,t,s,i),l}generate(e,t){const s=this.value,n=e.getNodeProperties(this),r=super.generate(e,"property");if(t==="sampler")return r+"_sampler";if(e.isReference(t))return r;{const i=e.getDataFromNode(this);let a=i.propertyName;if(a===void 0){const{uvNode:l,levelNode:d,biasNode:h,compareNode:p,depthNode:f,gradNode:m}=n,x=this.generateUV(e,l),N=d?d.build(e,"float"):null,v=h?h.build(e,"float"):null,w=f?f.build(e,"int"):null,B=p?p.build(e,"float"):null,F=m?[m[0].build(e,"vec2"),m[1].build(e,"vec2")]:null,L=e.getVarFromNode(this);a=e.getPropertyName(L);const I=this.generateSnippet(e,r,x,N,v,w,B,F);e.addLineFlowCode(`${a} = ${I}`,this),i.snippet=I,i.propertyName=a}let u=a;const c=this.getNodeType(e);return e.needsToWorkingColorSpace(s)&&(u=eu(rs(u,c),s.colorSpace).setup(e).build(e,c)),e.format(u,c,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){const t=this.clone();return t.uvNode=E(e),t.referenceNode=this.getSelf(),E(t)}blur(e){const t=this.clone();return t.biasNode=E(e).mul(Ph(t)),t.referenceNode=this.getSelf(),E(t)}level(e){const t=this.clone();return t.levelNode=E(e),t.referenceNode=this.getSelf(),E(t)}size(e){return ns(this,e)}bias(e){const t=this.clone();return t.biasNode=E(e),t.referenceNode=this.getSelf(),E(t)}compare(e){const t=this.clone();return t.compareNode=E(e),t.referenceNode=this.getSelf(),E(t)}grad(e,t){const s=this.clone();return s.gradNode=[E(e),E(t)],s.referenceNode=this.getSelf(),E(s)}depth(e){const 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(){const e=this.value,t=this._matrixUniform;t!==null&&(t.value=e.matrix),e.matrixAutoUpdate===!0&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const K=C(wt),ge=(...o)=>K(...o).setSampler(!1),Wy=o=>(o.isNode===!0?o:K(o)).convert("sampler"),Jt=V("float").label("cameraNear").setGroup(k).onRenderUpdate(({camera:o})=>o.near),es=V("float").label("cameraFar").setGroup(k).onRenderUpdate(({camera:o})=>o.far),He=V("mat4").label("cameraProjectionMatrix").setGroup(k).onRenderUpdate(({camera:o})=>o.projectionMatrix),$y=V("mat4").label("cameraProjectionMatrixInverse").setGroup(k).onRenderUpdate(({camera:o})=>o.projectionMatrixInverse),je=V("mat4").label("cameraViewMatrix").setGroup(k).onRenderUpdate(({camera:o})=>o.matrixWorldInverse),Hy=V("mat4").label("cameraWorldMatrix").setGroup(k).onRenderUpdate(({camera:o})=>o.matrixWorld),qy=V("mat3").label("cameraNormalMatrix").setGroup(k).onRenderUpdate(({camera:o})=>o.normalMatrix),su=V(new j).label("cameraPosition").setGroup(k).onRenderUpdate(({camera:o},e)=>e.value.setFromMatrixPosition(o.matrixWorld));class J extends O{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=W.OBJECT,this._uniformNode=new er(null)}getNodeType(){const e=this.scope;if(e===J.WORLD_MATRIX)return"mat4";if(e===J.POSITION||e===J.VIEW_POSITION||e===J.DIRECTION||e===J.SCALE)return"vec3"}update(e){const t=this.object3d,s=this._uniformNode,n=this.scope;if(n===J.WORLD_MATRIX)s.value=t.matrixWorld;else if(n===J.POSITION)s.value=s.value||new j,s.value.setFromMatrixPosition(t.matrixWorld);else if(n===J.SCALE)s.value=s.value||new j,s.value.setFromMatrixScale(t.matrixWorld);else if(n===J.DIRECTION)s.value=s.value||new j,t.getWorldDirection(s.value);else if(n===J.VIEW_POSITION){const r=e.camera;s.value=s.value||new j,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(r.matrixWorldInverse)}}generate(e){const t=this.scope;return t===J.WORLD_MATRIX?this._uniformNode.nodeType="mat4":(t===J.POSITION||t===J.VIEW_POSITION||t===J.DIRECTION||t===J.SCALE)&&(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}J.WORLD_MATRIX="worldMatrix";J.POSITION="position";J.SCALE="scale";J.VIEW_POSITION="viewPosition";J.DIRECTION="direction";const Ky=C(J,J.DIRECTION),Xy=C(J,J.WORLD_MATRIX),Dh=C(J,J.POSITION),Yy=C(J,J.SCALE),jy=C(J,J.VIEW_POSITION);class Mt extends J{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Qy=U(Mt,Mt.DIRECTION),at=U(Mt,Mt.WORLD_MATRIX),Zy=U(Mt,Mt.POSITION),Jy=U(Mt,Mt.SCALE),ex=U(Mt,Mt.VIEW_POSITION),Lh=V(new Yn).onObjectUpdate(({object:o},e)=>e.value.getNormalMatrix(o.matrixWorld)),Ih=V(new Ie).onObjectUpdate(({object:o},e)=>e.value.copy(o.matrixWorld).invert()),Kt=b(o=>o.renderer.nodes.modelViewMatrix||Vh).once()().toVar("modelViewMatrix"),Vh=je.mul(at),tx=b(o=>(o.context.isHighPrecisionModelViewMatrix=!0,V("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),sx=b(o=>{const e=o.context.isHighPrecisionModelViewMatrix;return V("mat3").onObjectUpdate(({object:t,camera:s})=>(e!==!0&&t.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),Ce=we("position","vec3"),me=Ce.varying("positionLocal"),Jr=Ce.varying("positionPrevious"),Wt=at.mul(me).xyz.varying("v_positionWorld").context({needsPositionReassign:!0}),nu=me.transformDirection(at).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection").context({needsPositionReassign:!0}),xe=b(o=>o.context.setupPositionView(),"vec3").once()().varying("v_positionView").context({needsPositionReassign:!0}),ae=xe.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class nx extends O{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===Pn&&s.side===Ct?"false":e.getFrontFacing()}}const Gh=U(nx),rr=g(Gh).mul(2).sub(1),Ni=we("normal","vec3"),Xe=b(o=>o.geometry.hasAttribute("normal")===!1?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),T(0,1,0)):Ni,"vec3").once()().toVar("normalLocal"),Oh=xe.dFdx().cross(xe.dFdy()).normalize().toVar("normalFlat"),lt=b(o=>{let e;return o.material.flatShading===!0?e=Oh:e=ke(ru(Xe),"v_normalView").normalize(),e},"vec3").once()().toVar("normalView"),Si=ke(lt.transformDirection(je),"v_normalWorld").normalize().toVar("normalWorld"),fe=b(o=>o.context.setupNormal(),"vec3").once()().mul(rr).toVar("transformedNormalView"),vi=fe.transformDirection(je).toVar("transformedNormalWorld"),Hs=b(o=>o.context.setupClearcoatNormal(),"vec3").once()().mul(rr).toVar("transformedClearcoatNormalView"),kh=b(([o,e=at])=>{const t=Oe(e),s=o.div(T(t[0].dot(t[0]),t[1].dot(t[1]),t[2].dot(t[2])));return t.mul(s).xyz}),ru=b(([o],e)=>{const t=e.renderer.nodes.modelNormalViewMatrix;if(t!==null)return t.transformDirection(o);const s=Lh.mul(o);return je.transformDirection(s)}),zh=V(0).onReference(({material:o})=>o).onRenderUpdate(({material:o})=>o.refractionRatio),Wh=ae.negate().reflect(fe),$h=ae.negate().refract(fe,zh),Hh=Wh.transformDirection(je).toVar("reflectVector"),qh=$h.transformDirection(je).toVar("reflectVector");class rx extends wt{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,n=null){super(e,t,s,n),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===Zs?Hh:e.mapping===Js?qh:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),T(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem===ln||!s.isRenderTargetTexture?T(t.x.negate(),t.yz):t}generateUV(e,t){return t.build(e,"vec3")}}const on=C(rx);class iu extends er{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const ir=(o,e,t)=>E(new iu(o,e,t));class ix extends Rs{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType(),n=this.node.getPaddedType();return e.format(t,n,s)}}class Kh extends iu{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=t===null?Ot(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=W.RENDER,this.isArrayBufferNode=!0}getNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){const e=this.elementType;let t="vec4";return e==="mat2"?t="mat2":/mat/.test(e)===!0?t="mat4":e.charAt(0)==="i"?t="ivec4":e.charAt(0)==="u"&&(t="uvec4"),t}update(){const{array:e,value:t}=this,s=this.elementType;if(s==="float"||s==="int"||s==="uint")for(let n=0;n<e.length;n++){const r=n*4;t[r]=e[n]}else if(s==="color")for(let n=0;n<e.length;n++){const r=n*4,i=e[n];t[r]=i.r,t[r+1]=i.g,t[r+2]=i.b||0}else if(s==="mat2")for(let n=0;n<e.length;n++){const r=n*4,i=e[n];t[r]=i.elements[0],t[r+1]=i.elements[1],t[r+2]=i.elements[2],t[r+3]=i.elements[3]}else if(s==="mat3")for(let n=0;n<e.length;n++){const r=n*16,i=e[n];t[r]=i.elements[0],t[r+1]=i.elements[1],t[r+2]=i.elements[2],t[r+4]=i.elements[3],t[r+5]=i.elements[4],t[r+6]=i.elements[5],t[r+8]=i.elements[6],t[r+9]=i.elements[7],t[r+10]=i.elements[8],t[r+15]=1}else if(s==="mat4")for(let n=0;n<e.length;n++){const r=n*16,i=e[n];for(let a=0;a<i.elements.length;a++)t[r+a]=i.elements[a]}else for(let n=0;n<e.length;n++){const r=n*4,i=e[n];t[r]=i.x,t[r+1]=i.y,t[r+2]=i.z||0,t[r+3]=i.w||0}}setup(e){const t=this.array.length,s=this.elementType;let n=Float32Array;const r=this.paddedType,i=e.getTypeLength(r);return s.charAt(0)==="i"&&(n=Int32Array),s.charAt(0)==="u"&&(n=Uint32Array),this.value=new n(t*i),this.bufferCount=t,this.bufferType=r,super.setup(e)}element(e){return E(new ix(this,E(e)))}}const Gt=(o,e)=>E(new Kh(o,e)),ox=(o,e)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),E(new Kh(o,e)));class ax extends Rs{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),n=this.getNodeType();return e.format(t,s,n)}}class Ai extends O{static get type(){return"ReferenceNode"}constructor(e,t,s=null,n=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=n,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=W.OBJECT}element(e){return E(new ax(this,E(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;this.count!==null?t=ir(null,e,this.count):Array.isArray(this.getValueFromReference())?t=Gt(null,e):e==="texture"?t=K(null):e==="cubeTexture"?t=on(null):t=V(null,e),this.group!==null&&t.setGroup(this.group),this.name!==null&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let n=1;n<t.length;n++)s=s[t[n]];return s}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const ne=(o,e,t)=>E(new Ai(o,e,t)),Ko=(o,e,t,s)=>E(new Ai(o,e,s,t));class ux extends Ai{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=this.material!==null?this.material:e.material,this.reference}}const dt=(o,e,t=null)=>E(new ux(o,e,t)),Ri=b(o=>(o.geometry.hasAttribute("tangent")===!1&&o.geometry.computeTangents(),we("tangent","vec4")))(),or=Ri.xyz.toVar("tangentLocal"),ar=Kt.mul(P(or,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Xh=ar.transformDirection(je).varying("v_tangentWorld").normalize().toVar("tangentWorld"),ou=ar.toVar("transformedTangentView"),cx=ou.transformDirection(je).normalize().toVar("transformedTangentWorld"),ur=o=>o.mul(Ri.w).xyz,lx=ke(ur(Ni.cross(Ri)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),dx=ke(ur(Xe.cross(or)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),Yh=ke(ur(lt.cross(ar)),"v_bitangentView").normalize().toVar("bitangentView"),hx=ke(ur(Si.cross(Xh)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),jh=ur(fe.cross(ou)).normalize().toVar("transformedBitangentView"),px=jh.transformDirection(je).normalize().toVar("transformedBitangentWorld"),gs=Oe(ar,Yh,lt),Qh=ae.mul(gs),fx=(o,e)=>o.sub(Qh.mul(e)),Zh=(()=>{let o=_s.cross(ae);return o=o.cross(_s).normalize(),o=Q(o,fe,Zt.mul(Nt.oneMinus()).oneMinus().pow2().pow2()).normalize(),o})(),gx=b(o=>{const{eye_pos:e,surf_norm:t,mapN:s,uv:n}=o,r=e.dFdx(),i=e.dFdy(),a=n.dFdx(),u=n.dFdy(),c=t,l=i.cross(c),d=c.cross(r),h=l.mul(a.x).add(d.mul(u.x)),p=l.mul(a.y).add(d.mul(u.y)),f=h.dot(h).max(p.dot(p)),m=rr.mul(f.inverseSqrt());return _e(h.mul(s.x,m),p.mul(s.y,m),c.mul(s.z)).normalize()});class mx extends be{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=Yu}setup(e){const{normalMapType:t,scaleNode:s}=this;let n=this.node.mul(2).sub(1);s!==null&&(n=T(n.xy.mul(s),n.z));let r=null;return t===Og?r=ru(n):t===Yu&&(e.hasGeometryAttribute("tangent")===!0?r=gs.mul(n).normalize():r=gx({eye_pos:xe,surf_norm:lt,mapN:n,uv:le()})),r}}const Xo=C(mx),yx=b(({textureNode:o,bumpScale:e})=>{const t=n=>o.cache().context({getUV:r=>n(r.uvNode||le()),forceUVContext:!0}),s=g(t(n=>n));return M(g(t(n=>n.add(n.dFdx()))).sub(s),g(t(n=>n.add(n.dFdy()))).sub(s)).mul(e)}),xx=b(o=>{const{surf_pos:e,surf_norm:t,dHdxy:s}=o,n=e.dFdx().normalize(),r=e.dFdy().normalize(),i=t,a=r.cross(i),u=i.cross(n),c=n.dot(a).mul(rr),l=c.sign().mul(s.x.mul(a).add(s.y.mul(u)));return c.abs().mul(t).sub(l).normalize()});class Tx extends be{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=this.scaleNode!==null?this.scaleNode:1,t=yx({textureNode:this.textureNode,bumpScale:e});return xx({surf_pos:xe,surf_norm:lt,dHdxy:t})}}const Jh=C(Tx),cc=new Map;class A extends O{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=cc.get(e);return s===void 0&&(s=dt(e,t),cc.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache(e==="map"?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let n=null;if(s===A.COLOR){const r=t.color!==void 0?this.getColor(s):T();t.map&&t.map.isTexture===!0?n=r.mul(this.getTexture("map")):n=r}else if(s===A.OPACITY){const r=this.getFloat(s);t.alphaMap&&t.alphaMap.isTexture===!0?n=r.mul(this.getTexture("alpha")):n=r}else if(s===A.SPECULAR_STRENGTH)t.specularMap&&t.specularMap.isTexture===!0?n=this.getTexture("specular").r:n=g(1);else if(s===A.SPECULAR_INTENSITY){const r=this.getFloat(s);t.specularIntensityMap&&t.specularIntensityMap.isTexture===!0?n=r.mul(this.getTexture(s).a):n=r}else if(s===A.SPECULAR_COLOR){const r=this.getColor(s);t.specularColorMap&&t.specularColorMap.isTexture===!0?n=r.mul(this.getTexture(s).rgb):n=r}else if(s===A.ROUGHNESS){const r=this.getFloat(s);t.roughnessMap&&t.roughnessMap.isTexture===!0?n=r.mul(this.getTexture(s).g):n=r}else if(s===A.METALNESS){const r=this.getFloat(s);t.metalnessMap&&t.metalnessMap.isTexture===!0?n=r.mul(this.getTexture(s).b):n=r}else if(s===A.EMISSIVE){const r=this.getFloat("emissiveIntensity"),i=this.getColor(s).mul(r);t.emissiveMap&&t.emissiveMap.isTexture===!0?n=i.mul(this.getTexture(s)):n=i}else if(s===A.NORMAL)t.normalMap?(n=Xo(this.getTexture("normal"),this.getCache("normalScale","vec2")),n.normalMapType=t.normalMapType):t.bumpMap?n=Jh(this.getTexture("bump").r,this.getFloat("bumpScale")):n=lt;else if(s===A.CLEARCOAT){const r=this.getFloat(s);t.clearcoatMap&&t.clearcoatMap.isTexture===!0?n=r.mul(this.getTexture(s).r):n=r}else if(s===A.CLEARCOAT_ROUGHNESS){const r=this.getFloat(s);t.clearcoatRoughnessMap&&t.clearcoatRoughnessMap.isTexture===!0?n=r.mul(this.getTexture(s).r):n=r}else if(s===A.CLEARCOAT_NORMAL)t.clearcoatNormalMap?n=Xo(this.getTexture(s),this.getCache(s+"Scale","vec2")):n=lt;else if(s===A.SHEEN){const r=this.getColor("sheenColor").mul(this.getFloat("sheen"));t.sheenColorMap&&t.sheenColorMap.isTexture===!0?n=r.mul(this.getTexture("sheenColor").rgb):n=r}else if(s===A.SHEEN_ROUGHNESS){const r=this.getFloat(s);t.sheenRoughnessMap&&t.sheenRoughnessMap.isTexture===!0?n=r.mul(this.getTexture(s).a):n=r,n=n.clamp(.07,1)}else if(s===A.ANISOTROPY)if(t.anisotropyMap&&t.anisotropyMap.isTexture===!0){const r=this.getTexture(s);n=fi(Os.x,Os.y,Os.y.negate(),Os.x).mul(r.rg.mul(2).sub(M(1)).normalize().mul(r.b))}else n=Os;else if(s===A.IRIDESCENCE_THICKNESS){const r=ne("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const i=ne("0","float",t.iridescenceThicknessRange);n=r.sub(i).mul(this.getTexture(s).g).add(i)}else n=r}else if(s===A.TRANSMISSION){const r=this.getFloat(s);t.transmissionMap?n=r.mul(this.getTexture(s).r):n=r}else if(s===A.THICKNESS){const r=this.getFloat(s);t.thicknessMap?n=r.mul(this.getTexture(s).g):n=r}else if(s===A.IOR)n=this.getFloat(s);else if(s===A.LIGHT_MAP)n=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===A.AO)n=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const r=this.getNodeType(e);n=this.getCache(s,r)}return n}}A.ALPHA_TEST="alphaTest";A.COLOR="color";A.OPACITY="opacity";A.SHININESS="shininess";A.SPECULAR="specular";A.SPECULAR_STRENGTH="specularStrength";A.SPECULAR_INTENSITY="specularIntensity";A.SPECULAR_COLOR="specularColor";A.REFLECTIVITY="reflectivity";A.ROUGHNESS="roughness";A.METALNESS="metalness";A.NORMAL="normal";A.CLEARCOAT="clearcoat";A.CLEARCOAT_ROUGHNESS="clearcoatRoughness";A.CLEARCOAT_NORMAL="clearcoatNormal";A.EMISSIVE="emissive";A.ROTATION="rotation";A.SHEEN="sheen";A.SHEEN_ROUGHNESS="sheenRoughness";A.ANISOTROPY="anisotropy";A.IRIDESCENCE="iridescence";A.IRIDESCENCE_IOR="iridescenceIOR";A.IRIDESCENCE_THICKNESS="iridescenceThickness";A.IOR="ior";A.TRANSMISSION="transmission";A.THICKNESS="thickness";A.ATTENUATION_DISTANCE="attenuationDistance";A.ATTENUATION_COLOR="attenuationColor";A.LINE_SCALE="scale";A.LINE_DASH_SIZE="dashSize";A.LINE_GAP_SIZE="gapSize";A.LINE_WIDTH="linewidth";A.LINE_DASH_OFFSET="dashOffset";A.POINT_WIDTH="pointWidth";A.DISPERSION="dispersion";A.LIGHT_MAP="light";A.AO="ao";const ep=U(A,A.ALPHA_TEST),an=U(A,A.COLOR),tp=U(A,A.SHININESS),sp=U(A,A.EMISSIVE),cr=U(A,A.OPACITY),np=U(A,A.SPECULAR),Yo=U(A,A.SPECULAR_INTENSITY),rp=U(A,A.SPECULAR_COLOR),Bn=U(A,A.SPECULAR_STRENGTH),Gr=U(A,A.REFLECTIVITY),ip=U(A,A.ROUGHNESS),op=U(A,A.METALNESS),ap=U(A,A.NORMAL).context({getUV:null}),up=U(A,A.CLEARCOAT),cp=U(A,A.CLEARCOAT_ROUGHNESS),lp=U(A,A.CLEARCOAT_NORMAL).context({getUV:null}),dp=U(A,A.ROTATION),hp=U(A,A.SHEEN),pp=U(A,A.SHEEN_ROUGHNESS),fp=U(A,A.ANISOTROPY),gp=U(A,A.IRIDESCENCE),mp=U(A,A.IRIDESCENCE_IOR),yp=U(A,A.IRIDESCENCE_THICKNESS),xp=U(A,A.TRANSMISSION),Tp=U(A,A.THICKNESS),_p=U(A,A.IOR),bp=U(A,A.ATTENUATION_DISTANCE),Np=U(A,A.ATTENUATION_COLOR),au=U(A,A.LINE_SCALE),uu=U(A,A.LINE_DASH_SIZE),cu=U(A,A.LINE_GAP_SIZE),Or=U(A,A.LINE_WIDTH),lu=U(A,A.LINE_DASH_OFFSET),Sp=U(A,A.POINT_WIDTH),vp=U(A,A.DISPERSION),du=U(A,A.LIGHT_MAP),Ap=U(A,A.AO),Os=V(new Ye).onReference(function(o){return o.material}).onRenderUpdate(function({material:o}){this.value.set(o.anisotropy*Math.cos(o.anisotropyRotation),o.anisotropy*Math.sin(o.anisotropyRotation))}),hu=b(o=>o.context.setupModelViewProjection(),"vec4").once()().varying("v_modelViewProjection");class de extends O{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let n;if(s===de.VERTEX)n=e.getVertexIndex();else if(s===de.INSTANCE)n=e.getInstanceIndex();else if(s===de.DRAW)n=e.getDrawIndex();else if(s===de.INVOCATION_LOCAL)n=e.getInvocationLocalIndex();else if(s===de.INVOCATION_SUBGROUP)n=e.getInvocationSubgroupIndex();else if(s===de.SUBGROUP)n=e.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+s);let r;return e.shaderStage==="vertex"||e.shaderStage==="compute"?r=n:r=ke(this).build(e,t),r}}de.VERTEX="vertex";de.INSTANCE="instance";de.SUBGROUP="subgroup";de.INVOCATION_LOCAL="invocationLocal";de.INVOCATION_SUBGROUP="invocationSubgroup";de.DRAW="draw";const Rp=U(de,de.VERTEX),lr=U(de,de.INSTANCE),_x=U(de,de.SUBGROUP),bx=U(de,de.INVOCATION_SUBGROUP),Nx=U(de,de.INVOCATION_LOCAL),Cp=U(de,de.DRAW);class Ep extends O{static get type(){return"InstanceNode"}constructor(e,t,s){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=s,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=W.FRAME,this.buffer=null,this.bufferColor=null}setup(e){const{count:t,instanceMatrix:s,instanceColor:n}=this;let{instanceMatrixNode:r,instanceColorNode:i}=this;if(r===null){if(t<=1e3)r=ir(s.array,"mat4",Math.max(t,1)).element(lr);else{const u=new Cg(s.array,16,1);this.buffer=u;const c=s.usage===zs?qo:Zr,l=[c(u,"vec4",16,0),c(u,"vec4",16,4),c(u,"vec4",16,8),c(u,"vec4",16,12)];r=Ts(...l)}this.instanceMatrixNode=r}if(n&&i===null){const u=new oa(n.array,3),c=n.usage===zs?qo:Zr;this.bufferColor=u,i=T(c(u,"vec3",3,0)),this.instanceColorNode=i}const a=r.mul(me).xyz;if(me.assign(a),e.hasGeometryAttribute("normal")){const u=kh(Xe,r);Xe.assign(u)}this.instanceColorNode!==null&&et("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMatrix.usage!==zs&&this.buffer!==null&&this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version),this.instanceColor&&this.instanceColor.usage!==zs&&this.bufferColor!==null&&this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)}}const Sx=C(Ep);class vx extends Ep{static get type(){return"InstancedMeshNode"}constructor(e){const{count:t,instanceMatrix:s,instanceColor:n}=e;super(t,s,n),this.instancedMesh=e}}const wp=C(vx);class Ax extends O{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){this.batchingIdNode===null&&(e.getDrawIndex()===null?this.batchingIdNode=lr:this.batchingIdNode=Cp);const s=b(([f])=>{const m=ns(ge(this.batchMesh._indirectTexture),0),x=y(f).modInt(y(m)),N=y(f).div(y(m));return ge(this.batchMesh._indirectTexture,Ae(x,N)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]})(y(this.batchingIdNode)),n=this.batchMesh._matricesTexture,r=ns(ge(n),0),i=g(s).mul(4).toInt().toVar(),a=i.modInt(r),u=i.div(y(r)),c=Ts(ge(n,Ae(a,u)),ge(n,Ae(a.add(1),u)),ge(n,Ae(a.add(2),u)),ge(n,Ae(a.add(3),u))),l=this.batchMesh._colorsTexture;if(l!==null){const m=b(([x])=>{const N=ns(ge(l),0).x,v=x,w=v.modInt(N),B=v.div(N);return ge(l,Ae(w,B)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]})(s);et("vec3","vBatchColor").assign(m)}const d=Oe(c);me.assign(c.mul(me));const h=Xe.div(T(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),p=d.mul(h).xyz;Xe.assign(p),e.hasGeometryAttribute("tangent")&&or.mulAssign(d)}}const Mp=C(Ax),lc=new WeakMap;class Bp extends O{static get type(){return"SkinningNode"}constructor(e,t=!1){super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=W.OBJECT,this.skinIndexNode=we("skinIndex","uvec4"),this.skinWeightNode=we("skinWeight","vec4");let s,n,r;t?(s=ne("bindMatrix","mat4"),n=ne("bindMatrixInverse","mat4"),r=Ko("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=V(e.bindMatrix,"mat4"),n=V(e.bindMatrixInverse,"mat4"),r=ir(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=n,this.boneMatricesNode=r,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=me){const{skinIndexNode:s,skinWeightNode:n,bindMatrixNode:r,bindMatrixInverseNode:i}=this,a=e.element(s.x),u=e.element(s.y),c=e.element(s.z),l=e.element(s.w),d=r.mul(t),h=_e(a.mul(n.x).mul(d),u.mul(n.y).mul(d),c.mul(n.z).mul(d),l.mul(n.w).mul(d));return i.mul(h).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=Xe){const{skinIndexNode:s,skinWeightNode:n,bindMatrixNode:r,bindMatrixInverseNode:i}=this,a=e.element(s.x),u=e.element(s.y),c=e.element(s.z),l=e.element(s.w);let d=_e(n.x.mul(a),n.y.mul(u),n.z.mul(c),n.w.mul(l));return d=i.mul(d).mul(r),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return this.previousBoneMatricesNode===null&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Ko("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Jr)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")||ba(e.object).useVelocity===!0}setup(e){this.needsPreviousBoneMatrices(e)&&Jr.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(me.assign(t),e.hasGeometryAttribute("normal")){const s=this.getSkinnedNormal();Xe.assign(s),e.hasGeometryAttribute("tangent")&&or.assign(s)}}generate(e,t){if(t!=="void")return me.build(e,t)}update(e){const s=(this.useReference?e.object:this.skinnedMesh).skeleton;lc.get(s)!==e.frameId&&(lc.set(s,e.frameId),this.previousBoneMatricesNode!==null&&s.previousBoneMatrices.set(s.boneMatrices),s.update())}}const Rx=o=>E(new Bp(o)),Fp=o=>E(new Bp(o,!0));class Cx extends O{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){const t=e.getNodeProperties(this);if(t.stackNode!==void 0)return t;const s={};for(let r=0,i=this.params.length-1;r<i;r++){const a=this.params[r],u=a.isNode!==!0&&a.name||this.getVarName(r),c=a.isNode!==!0&&a.type||"int";s[u]=rs(u,c)}const n=e.addStack();return t.returnsNode=this.params[this.params.length-1](s,n,e),t.stackNode=n,e.removeStack(),t}getNodeType(e){const{returnsNode:t}=this.getProperties(e);return t?t.getNodeType(e):"void"}setup(e){this.getProperties(e)}generate(e){const t=this.getProperties(e),s=this.params,n=t.stackNode;for(let a=0,u=s.length-1;a<u;a++){const c=s[a];let l=null,d=null,h=null,p=null,f=null,m=null;c.isNode?(p="int",h=this.getVarName(a),l="0",d=c.build(e,p),f="<"):(p=c.type||"int",h=c.name||this.getVarName(a),l=c.start,d=c.end,f=c.condition,m=c.update,typeof l=="number"?l=e.generateConst(p,l):l&&l.isNode&&(l=l.build(e,p)),typeof d=="number"?d=e.generateConst(p,d):d&&d.isNode&&(d=d.build(e,p)),l!==void 0&&d===void 0?(l=l+" - 1",d="0",f=">="):d!==void 0&&l===void 0&&(l="0",f="<"),f===void 0&&(Number(l)>Number(d)?f=">=":f="<"));const x={start:l,end:d},N=x.start,v=x.end;let w="",B="",F="";m||(p==="int"||p==="uint"?f.includes("<")?m="++":m="--":f.includes("<")?m="+= 1.":m="-= 1."),w+=e.getVar(p,h)+" = "+N,B+=h+" "+f+" "+v,F+=h+" "+m;const L=`for ( ${w}; ${B}; ${F} )`;e.addFlowCode((a===0?`
|
|
`:"")+e.tab+L+` {
|
|
|
|
`).addFlowTab()}const r=n.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode(`
|
|
`+e.tab+r);for(let a=0,u=this.params.length-1;a<u;a++)e.addFlowCode((a===0?"":e.tab)+`}
|
|
|
|
`).removeFlowTab();return e.addFlowTab(),i}}const te=(...o)=>E(new Cx(xs(o,"int"))).append(),Ex=()=>rs("continue").append(),pu=()=>rs("break").append(),wx=(...o)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),te(...o)),Gi=new WeakMap,Je=new Me,dc=b(({bufferMap:o,influence:e,stride:t,width:s,depth:n,offset:r})=>{const i=y(Rp).mul(t).add(r),a=i.div(s),u=i.sub(a.mul(s));return ge(o,Ae(u,a)).depth(n).mul(e)});function Mx(o){const e=o.morphAttributes.position!==void 0,t=o.morphAttributes.normal!==void 0,s=o.morphAttributes.color!==void 0,n=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,r=n!==void 0?n.length:0;let i=Gi.get(o);if(i===void 0||i.count!==r){let N=function(){m.dispose(),Gi.delete(o),o.removeEventListener("dispose",N)};i!==void 0&&i.texture.dispose();const a=o.morphAttributes.position||[],u=o.morphAttributes.normal||[],c=o.morphAttributes.color||[];let l=0;e===!0&&(l=1),t===!0&&(l=2),s===!0&&(l=3);let d=o.attributes.position.count*l,h=1;const p=4096;d>p&&(h=Math.ceil(d/p),d=p);const f=new Float32Array(d*h*4*r),m=new Yg(f,d,h,r);m.type=ot,m.needsUpdate=!0;const x=l*4;for(let v=0;v<r;v++){const w=a[v],B=u[v],F=c[v],L=d*h*4*v;for(let I=0;I<w.count;I++){const G=I*x;e===!0&&(Je.fromBufferAttribute(w,I),f[L+G+0]=Je.x,f[L+G+1]=Je.y,f[L+G+2]=Je.z,f[L+G+3]=0),t===!0&&(Je.fromBufferAttribute(B,I),f[L+G+4]=Je.x,f[L+G+5]=Je.y,f[L+G+6]=Je.z,f[L+G+7]=0),s===!0&&(Je.fromBufferAttribute(F,I),f[L+G+8]=Je.x,f[L+G+9]=Je.y,f[L+G+10]=Je.z,f[L+G+11]=F.itemSize===4?Je.w:1)}}i={count:r,texture:m,stride:l,size:new Ye(d,h)},Gi.set(o,i),o.addEventListener("dispose",N)}return i}class Bx extends O{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=V(1),this.updateType=W.OBJECT}setup(e){const{geometry:t}=e,s=t.morphAttributes.position!==void 0,n=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,i=r!==void 0?r.length:0,{texture:a,stride:u,size:c}=Mx(t);s===!0&&me.mulAssign(this.morphBaseInfluence),n===!0&&Xe.mulAssign(this.morphBaseInfluence);const l=y(c.width);te(i,({i:d})=>{const h=g(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?h.assign(ge(this.mesh.morphTexture,Ae(y(d).add(1),y(lr))).r):h.assign(ne("morphTargetInfluences","float").element(d).toVar()),s===!0&&me.addAssign(dc({bufferMap:a,influence:h,stride:u,width:l,depth:d,offset:y(0)})),n===!0&&Xe.addAssign(dc({bufferMap:a,influence:h,stride:u,width:l,depth:d,offset:y(1)}))})}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((t,s)=>t+s,0)}}const Up=C(Bx);class hn extends O{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class Fx extends hn{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class Ux extends hh{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,n=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=n,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s=T().toVar("directDiffuse"),n=T().toVar("directSpecular"),r=T().toVar("indirectDiffuse"),i=T().toVar("indirectSpecular"),a={directDiffuse:s,directSpecular:n,indirectDiffuse:r,indirectSpecular:i};return{radiance:T().toVar("radiance"),irradiance:T().toVar("irradiance"),iblIrradiance:T().toVar("iblIrradiance"),ambientOcclusion:g(1).toVar("ambientOcclusion"),reflectedLight:a,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Pp=C(Ux);class Px extends hn{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let fn,gn;class Se extends O{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Se.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=W.NONE;return(this.scope===Se.SIZE||this.scope===Se.VIEWPORT)&&(e=W.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Se.VIEWPORT?t!==null?gn.copy(t.viewport):(e.getViewport(gn),gn.multiplyScalar(e.getPixelRatio())):t!==null?(fn.width=t.width,fn.height=t.height):e.getDrawingBufferSize(fn)}setup(){const e=this.scope;let t=null;return e===Se.SIZE?t=V(fn||(fn=new Ye)):e===Se.VIEWPORT?t=V(gn||(gn=new Me)):t=M(dr.div(Kn)),t}generate(e){if(this.scope===Se.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Kn).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Se.COORDINATE="coordinate";Se.VIEWPORT="viewport";Se.SIZE="size";Se.UV="uv";const Bt=U(Se,Se.UV),Kn=U(Se,Se.SIZE),dr=U(Se,Se.COORDINATE),$t=U(Se,Se.VIEWPORT),Dp=$t.zw,Lp=dr.sub($t.xy),Dx=Lp.div(Dp),Lx=b(()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Kn),"vec2").once()(),Ix=b(()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Bt),"vec2").once()(),Vx=b(()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Bt.flipY()),"vec2").once()(),mn=new Ye;class Ci extends wt{static get type(){return"ViewportTextureNode"}constructor(e=Bt,t=null,s=null){s===null&&(s=new bl,s.minFilter=ms),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=W.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(mn);const s=this.value;(s.image.width!==mn.width||s.image.height!==mn.height)&&(s.image.width=mn.width,s.image.height=mn.height,s.needsUpdate=!0);const n=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=n}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Gx=C(Ci),fu=C(Ci,null,null,{generateMipmaps:!0});let Oi=null;class Ox extends Ci{static get type(){return"ViewportDepthTextureNode"}constructor(e=Bt,t=null){Oi===null&&(Oi=new vs),super(e,t,Oi)}}const gu=C(Ox);class qe extends O{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===qe.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let n=null;if(t===qe.DEPTH_BASE)s!==null&&(n=Vp().assign(s));else if(t===qe.DEPTH)e.isPerspectiveCamera?n=Ip(xe.z,Jt,es):n=Qs(xe.z,Jt,es);else if(t===qe.LINEAR_DEPTH)if(s!==null)if(e.isPerspectiveCamera){const r=mu(s,Jt,es);n=Qs(r,Jt,es)}else n=s;else n=Qs(xe.z,Jt,es);return n}}qe.DEPTH_BASE="depthBase";qe.DEPTH="depth";qe.LINEAR_DEPTH="linearDepth";const Qs=(o,e,t)=>o.add(e).div(e.sub(t)),kx=(o,e,t)=>e.sub(t).mul(o).sub(e),Ip=(o,e,t)=>e.add(o).mul(t).div(t.sub(e).mul(o)),mu=(o,e,t)=>e.mul(t).div(t.sub(e).mul(o).sub(t)),yu=(o,e,t)=>{e=e.max(1e-6).toVar();const s=vt(o.negate().div(e)),n=vt(t.div(e));return s.div(n)},zx=(o,e,t)=>{const s=o.mul(yi(t.div(e)));return g(Math.E).pow(s).mul(e).negate()},Vp=C(qe,qe.DEPTH_BASE),xu=U(qe,qe.DEPTH),ei=C(qe,qe.LINEAR_DEPTH),Wx=ei(gu());xu.assign=o=>Vp(o);class $x extends O{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}}const Hx=C($x);class ut extends O{static get type(){return"ClippingNode"}constructor(e=ut.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:n}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===ut.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,n):this.scope===ut.HARDWARE?this.setupHardwareClipping(n,e):this.setupDefault(s,n)}setupAlphaToCoverage(e,t){return b(()=>{const s=g().toVar("distanceToPlane"),n=g().toVar("distanceToGradient"),r=g(1).toVar("clipOpacity"),i=t.length;if(this.hardwareClipping===!1&&i>0){const u=Gt(t);te(i,({i:c})=>{const l=u.element(c);s.assign(xe.dot(l.xyz).negate().add(l.w)),n.assign(s.fwidth().div(2)),r.mulAssign(ct(n.negate(),n,s))})}const a=e.length;if(a>0){const u=Gt(e),c=g(1).toVar("intersectionClipOpacity");te(a,({i:l})=>{const d=u.element(l);s.assign(xe.dot(d.xyz).negate().add(d.w)),n.assign(s.fwidth().div(2)),c.mulAssign(ct(n.negate(),n,s).oneMinus())}),r.mulAssign(c.oneMinus())}ee.a.mulAssign(r),ee.a.equal(0).discard()})()}setupDefault(e,t){return b(()=>{const s=t.length;if(this.hardwareClipping===!1&&s>0){const r=Gt(t);te(s,({i})=>{const a=r.element(i);xe.dot(a.xyz).greaterThan(a.w).discard()})}const n=e.length;if(n>0){const r=Gt(e),i=Ht(!0).toVar("clipped");te(n,({i:a})=>{const u=r.element(a);i.assign(xe.dot(u.xyz).greaterThan(u.w).and(i))}),i.discard()}})()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),b(()=>{const n=Gt(e),r=Hx(t.getClipDistance());te(s,({i})=>{const a=n.element(i),u=xe.dot(a.xyz).sub(a.w).negate();r.element(i).assign(u)})})()}}ut.ALPHA_TO_COVERAGE="alphaToCoverage";ut.DEFAULT="default";ut.HARDWARE="hardware";const qx=()=>E(new ut),Kx=()=>E(new ut(ut.ALPHA_TO_COVERAGE)),Xx=()=>E(new ut(ut.HARDWARE)),Yx=.05,hc=b(([o])=>Xt($(1e4,st($(17,o.x).add($(.1,o.y)))).mul(_e(.1,oe(st($(13,o.y).add(o.x))))))),pc=b(([o])=>hc(M(hc(o.xy),o.z))),jx=b(([o])=>{const e=ue(zt(Ha(o.xyz)),zt(qa(o.xyz))),t=g(1).div(g(Yx).mul(e)).toVar("pixScale"),s=M(rn(At(vt(t))),rn(xi(vt(t)))),n=M(pc(At(s.x.mul(o.xyz))),pc(At(s.y.mul(o.xyz)))),r=Xt(vt(t)),i=_e($(r.oneMinus(),n.x),$(r,n.y)),a=Re(r,r.oneMinus()),u=T(i.mul(i).div($(2,a).mul(Y(1,a))),i.sub($(.5,a)).div(Y(1,a)),Y(1,Y(1,i).mul(Y(1,i)).div($(2,a).mul(Y(1,a))))),c=i.lessThan(a.oneMinus()).select(i.lessThan(a).select(u.x,u.y),u.z);return Et(c,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class ce extends Xu{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.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+ma(this)}build(e){this.setup(e)}setupObserver(e){return new jm(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);const t=e.renderer,s=t.getRenderTarget();e.addStack();const n=this.vertexNode||this.setupVertex(e);e.stack.outputNode=n,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let r;const i=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(s!==null?s.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupVariants(e);const a=this.setupLighting(e);i!==null&&e.stack.add(i);const u=P(a,ee.a).max(0);if(r=this.setupOutput(e,u),$n.assign(r),this.outputNode!==null&&(r=this.outputNode),s!==null){const c=t.getMRT(),l=this.mrtNode;c!==null?(r=c,l!==null&&(r=c.merge(l))):l!==null&&(r=l)}}else{let a=this.fragmentNode;a.isOutputStructNode!==!0&&(a=P(a)),r=this.setupOutput(e,a)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let n=null;if(t.length>0||s.length>0){const r=e.renderer.samples;this.alphaToCoverage&&r>1?n=Kx():e.stack.add(qx())}return n}setupHardwareClipping(e){if(this.hardwareClipping=!1,e.clippingContext===null)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(Xx()),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let n=this.depthNode;if(n===null){const r=t.getMRT();r&&r.has("depth")?n=r.get("depth"):t.logarithmicDepthBuffer===!0&&(s.isPerspectiveCamera?n=yu(xe.z,Jt,es):n=Qs(xe.z,Jt,es))}n!==null&&xu.assign(n).append()}setupPositionView(){return Kt.mul(me).xyz}setupModelViewProjection(){return He.mul(xe)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.vertex=e.removeStack(),hu}setupPosition(e){const{object:t,geometry:s}=e;if((s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Up(t).append(),t.isSkinnedMesh===!0&&Fp(t).append(),this.displacementMap){const n=dt("displacementMap","texture"),r=dt("displacementScale","float"),i=dt("displacementBias","float");me.addAssign(Xe.normalize().mul(n.x.mul(r).add(i)))}return t.isBatchedMesh&&Mp(t).append(),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&wp(t).append(),this.positionNode!==null&&me.assign(this.positionNode.context({isPositionNodeInput:!0})),me}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?P(this.colorNode):an;this.vertexColors===!0&&t.hasAttribute("color")&&(s=P(s.xyz.mul(we("color","vec3")),s.a)),e.instanceColor&&(s=et("vec3","vInstanceColor").mul(s)),e.isBatchedMesh&&e._colorsTexture&&(s=et("vec3","vBatchColor").mul(s)),ee.assign(s);const n=this.opacityNode?g(this.opacityNode):cr;if(ee.a.assign(ee.a.mul(n)),this.alphaTestNode!==null||this.alphaTest>0){const r=this.alphaTestNode!==null?g(this.alphaTestNode):ep;ee.a.lessThanEqual(r).discard()}this.alphaHash===!0&&ee.a.lessThan(jx(me)).discard(),this.transparent===!1&&this.blending===Ys&&this.alphaToCoverage===!1&&ee.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?T(0):ee.rgb}setupNormal(){return this.normalNode?T(this.normalNode):ap}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?dt("envMap","cubeTexture"):dt("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Px(du)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const n=this.setupLightMap(e);if(n&&n.isLightingNode&&t.push(n),this.aoNode!==null||e.material.aoMap){const i=this.aoNode!==null?this.aoNode:Ap;t.push(new Fx(i))}let r=this.lightsNode||e.lightsNode;return t.length>0&&(r=e.renderer.lighting.createNode([...r.getLights(),...t])),r}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:n,emissiveNode:r}=this,a=this.lights===!0||this.lightsNode!==null?this.setupLights(e):null;let u=this.setupOutgoingLight(e);if(a&&a.getScope().hasLights){const c=this.setupLightingModel(e);u=Pp(a,c,s,n)}else s!==null&&(u=T(n!==null?Q(u,s,n):s));return(r&&r.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(Ho.assign(T(r||sp)),u=u.add(Ho)),u}setupOutput(e,t){if(this.fog===!0){const s=e.fogNode;s&&($n.assign(t),t=P(s))}return t}setDefaultValues(e){for(const s in e){const n=e[s];this[s]===void 0&&(this[s]=n,n&&n.clone&&(this[s]=n.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const s in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,s)===void 0&&t[s].get!==void 0&&Object.defineProperty(this.constructor.prototype,s,t[s])}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});const s=Xu.prototype.toJSON.call(this,e),n=Vn(this);s.inputNodes={};for(const{property:i,childNode:a}of n)s.inputNodes[i]=a.toJSON(e).uuid;function r(i){const a=[];for(const u in i){const c=i[u];delete c.metadata,a.push(c)}return a}if(t){const i=r(e.textures),a=r(e.images),u=r(e.nodes);i.length>0&&(s.textures=i),a.length>0&&(s.images=a),u.length>0&&(s.nodes=u)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const Qx=new hl;class dR extends ce{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.isInstancedPointsNodeMaterial=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this._useAlphaToCoverage=!0,this.setDefaultValues(Qx),this.setValues(e)}setup(e){const{renderer:t}=e,s=this._useAlphaToCoverage,n=this.useColor;this.vertexNode=b(()=>{const r=we("instancePosition").xyz,i=P(Kt.mul(P(r,1))),a=$t.z.div($t.w),u=He.mul(i),c=Ce.xy.toVar();return c.mulAssign(this.pointWidthNode?this.pointWidthNode:Sp),c.assign(c.div($t.z)),c.y.assign(c.y.mul(a)),c.assign(c.mul(u.w)),u.addAssign(P(c,0,0)),u})(),this.fragmentNode=b(()=>{const r=g(1).toVar(),i=ja(le().mul(2).sub(1));if(s&&t.samples>1){const u=g(i.fwidth()).toVar();r.assign(ct(u.oneMinus(),u.add(1),i).oneMinus())}else i.greaterThan(1).discard();let a;return this.pointColorNode?a=this.pointColorNode:n?a=we("instanceColor").mul(an):a=an,r.mulAssign(cr),P(a,r)})(),super.setup(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}const Zx=new Eg;class Jx extends ce{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(Zx),this.setValues(e)}}const eT=new pl;class tT extends ce{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(eT),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?g(this.offsetNode):lu,t=this.dashScaleNode?g(this.dashScaleNode):au,s=this.dashSizeNode?g(this.dashSizeNode):uu,n=this.gapSizeNode?g(this.gapSizeNode):cu;bs.assign(s),Hn.assign(n);const r=ke(we("lineDistance").mul(t));(e?r.add(e):r).mod(bs.add(Hn)).greaterThan(bs).discard()}}let ki=null;class sT extends Ci{static get type(){return"ViewportSharedTextureNode"}constructor(e=Bt,t=null){ki===null&&(ki=new bl),super(e,t,ki)}updateReference(){return this}}const Gp=C(sT),nT=new pl;class hR extends ce{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.isLine2NodeMaterial=!0,this.setDefaultValues(nT),this.useColor=e.vertexColors,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.blending=en,this._useDash=e.dashed,this._useAlphaToCoverage=!0,this._useWorldUnits=!1,this.setValues(e)}setup(e){const{renderer:t}=e,s=this._useAlphaToCoverage,n=this.useColor,r=this._useDash,i=this._useWorldUnits,a=b(({start:c,end:l})=>{const d=He.element(2).element(2),f=He.element(3).element(2).mul(-.5).div(d).sub(c.z).div(l.z.sub(c.z));return P(Q(c.xyz,l.xyz,f),l.w)}).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=b(()=>{const c=we("instanceStart"),l=we("instanceEnd"),d=P(Kt.mul(P(c,1))).toVar("start"),h=P(Kt.mul(P(l,1))).toVar("end");if(r){const F=this.dashScaleNode?g(this.dashScaleNode):au,L=this.offsetNode?g(this.offsetNode):lu,I=we("instanceDistanceStart"),G=we("instanceDistanceEnd");let X=Ce.y.lessThan(.5).select(F.mul(I),F.mul(G));X=X.add(L),et("float","lineDistance").assign(X)}i&&(et("vec3","worldStart").assign(d.xyz),et("vec3","worldEnd").assign(h.xyz));const p=$t.z.div($t.w),f=He.element(2).element(3).equal(-1);z(f,()=>{z(d.z.lessThan(0).and(h.z.greaterThan(0)),()=>{h.assign(a({start:d,end:h}))}).ElseIf(h.z.lessThan(0).and(d.z.greaterThanEqual(0)),()=>{d.assign(a({start:h,end:d}))})});const m=He.mul(d),x=He.mul(h),N=m.xyz.div(m.w),v=x.xyz.div(x.w),w=v.xy.sub(N.xy).toVar();w.x.assign(w.x.mul(p)),w.assign(w.normalize());const B=P().toVar();if(i){const F=h.xyz.sub(d.xyz).normalize(),L=Q(d.xyz,h.xyz,.5).normalize(),I=F.cross(L).normalize(),G=F.cross(I),X=et("vec4","worldPos");X.assign(Ce.y.lessThan(.5).select(d,h));const ie=Or.mul(.5);X.addAssign(P(Ce.x.lessThan(0).select(I.mul(ie),I.mul(ie).negate()),0)),r||(X.addAssign(P(Ce.y.lessThan(.5).select(F.mul(ie).negate(),F.mul(ie)),0)),X.addAssign(P(G.mul(ie),0)),z(Ce.y.greaterThan(1).or(Ce.y.lessThan(0)),()=>{X.subAssign(P(G.mul(2).mul(ie),0))})),B.assign(He.mul(X));const Z=T().toVar();Z.assign(Ce.y.lessThan(.5).select(N,v)),B.z.assign(Z.z.mul(B.w))}else{const F=M(w.y,w.x.negate()).toVar("offset");w.x.assign(w.x.div(p)),F.x.assign(F.x.div(p)),F.assign(Ce.x.lessThan(0).select(F.negate(),F)),z(Ce.y.lessThan(0),()=>{F.assign(F.sub(w))}).ElseIf(Ce.y.greaterThan(1),()=>{F.assign(F.add(w))}),F.assign(F.mul(Or)),F.assign(F.div($t.w)),B.assign(Ce.y.lessThan(.5).select(m,x)),F.assign(F.mul(B.w)),B.assign(B.add(P(F,0,0)))}return B})();const u=b(({p1:c,p2:l,p3:d,p4:h})=>{const p=c.sub(d),f=h.sub(d),m=l.sub(c),x=p.dot(f),N=f.dot(m),v=p.dot(m),w=f.dot(f),F=m.dot(m).mul(w).sub(N.mul(N)),I=x.mul(N).sub(v.mul(w)).div(F).clamp(),G=x.add(N.mul(I)).div(w).clamp();return M(I,G)});if(this.colorNode=b(()=>{const c=le();if(r){const h=this.dashSizeNode?g(this.dashSizeNode):uu,p=this.gapSizeNode?g(this.gapSizeNode):cu;bs.assign(h),Hn.assign(p);const f=et("float","lineDistance");c.y.lessThan(-1).or(c.y.greaterThan(1)).discard(),f.mod(bs.add(Hn)).greaterThan(bs).discard()}const l=g(1).toVar("alpha");if(i){const h=et("vec3","worldStart"),p=et("vec3","worldEnd"),f=et("vec4","worldPos").xyz.normalize().mul(1e5),m=p.sub(h),x=u({p1:h,p2:p,p3:T(0,0,0),p4:f}),N=h.add(m.mul(x.x)),v=f.mul(x.y),F=N.sub(v).length().div(Or);if(!r)if(s&&t.samples>1){const L=F.fwidth();l.assign(ct(L.negate().add(.5),L.add(.5),F).oneMinus())}else F.greaterThan(.5).discard()}else if(s&&t.samples>1){const h=c.x,p=c.y.greaterThan(0).select(c.y.sub(1),c.y.add(1)),f=h.mul(h).add(p.mul(p)),m=g(f.fwidth()).toVar("dlen");z(c.y.abs().greaterThan(1),()=>{l.assign(ct(m.oneMinus(),m.add(1),f).oneMinus())})}else z(c.y.abs().greaterThan(1),()=>{const h=c.x,p=c.y.greaterThan(0).select(c.y.sub(1),c.y.add(1));h.mul(h).add(p.mul(p)).greaterThan(1).discard()});let d;if(this.lineColorNode)d=this.lineColorNode;else if(n){const h=we("instanceColorStart"),p=we("instanceColorEnd");d=Ce.y.lessThan(.5).select(h,p).mul(an)}else d=an;return P(d,l)})(),this.transparent){const c=this.opacityNode?g(this.opacityNode):cr;this.outputNode=P(this.colorNode.rgb.mul(c).add(Gp().rgb.mul(c.oneMinus())),this.colorNode.a)}super.setup(e)}get worldUnits(){return this._useWorldUnits}set worldUnits(e){this._useWorldUnits!==e&&(this._useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this._useDash}set dashed(e){this._useDash!==e&&(this._useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}const Op=o=>E(o).mul(.5).add(.5),rT=o=>E(o).mul(2).sub(1),iT=new Bg;class oT extends ce{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(iT),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?g(this.opacityNode):cr;ee.assign(P(Op(fe),e))}}class aT extends be{static get type(){return"EquirectUVNode"}constructor(e=nu){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan(e.x).mul(1/(Math.PI*2)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return M(t,s)}}const Tu=C(aT);class kp extends jg{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,n=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const r=new _l(5,5,5),i=Tu(nu),a=new ce;a.colorNode=K(t,i,0),a.side=Ct,a.blending=en;const u=new tn(r,a),c=new Nl;c.add(u),t.minFilter===ms&&(t.minFilter=ft);const l=new Qg(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,c),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=n,u.geometry.dispose(),u.material.dispose(),this}}const Fn=new WeakMap;class uT extends be{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=on();const t=new td;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=W.RENDER}updateBefore(e){const{renderer:t,material:s}=e,n=this.envNode;if(n.isTextureNode||n.isMaterialReferenceNode){const r=n.isTextureNode?n.value:s[n.property];if(r&&r.isTexture){const i=r.mapping;if(i===jn||i===Qn){if(Fn.has(r)){const a=Fn.get(r);fc(a,r.mapping),this._cubeTexture=a}else{const a=r.image;if(cT(a)){const u=new kp(a.height);u.fromEquirectangularTexture(t,r),fc(u.texture,r.mapping),this._cubeTexture=u.texture,Fn.set(r,u.texture),r.addEventListener("dispose",zp)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function cT(o){return o==null?!1:o.height>0}function zp(o){const e=o.target;e.removeEventListener("dispose",zp);const t=Fn.get(e);t!==void 0&&(Fn.delete(e),t.dispose())}function fc(o,e){e===jn?o.mapping=Zs:e===Qn&&(o.mapping=Js)}const Wp=C(uT);class _u extends hn{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Wp(this.envNode)}}class lT extends hn{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=g(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ei{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class $p extends Ei{constructor(){super()}indirect(e,t,s){const n=e.ambientOcclusion,r=e.reflectedLight,i=s.context.irradianceLightMap;r.indirectDiffuse.assign(P(0)),i?r.indirectDiffuse.addAssign(i):r.indirectDiffuse.addAssign(P(1,1,1,0)),r.indirectDiffuse.mulAssign(n),r.indirectDiffuse.mulAssign(ee.rgb)}finish(e,t,s){const n=s.material,r=e.outgoingLight,i=s.context.environment;if(i)switch(n.combine){case Xg:r.rgb.assign(Q(r.rgb,r.rgb.mul(i.rgb),Bn.mul(Gr)));break;case Kg:r.rgb.assign(Q(r.rgb,i.rgb,Bn.mul(Gr)));break;case qg:r.rgb.addAssign(i.rgb.mul(Bn.mul(Gr)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",n.combine);break}}}const dT=new fl;class hT extends ce{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(dT),this.setValues(e)}setupNormal(){return lt}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new _u(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new lT(du)),t}setupOutgoingLight(){return ee.rgb}setupLightingModel(){return new $p}}const un=b(({f0:o,f90:e,dotVH:t})=>{const s=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return o.mul(s.oneMinus()).add(e.mul(s))}),Ns=b(o=>o.diffuseColor.mul(1/Math.PI)),pT=()=>g(.25),fT=b(({dotNH:o})=>Yr.mul(g(.5)).add(1).mul(g(1/Math.PI)).mul(o.pow(Yr))),gT=b(({lightDirection:o})=>{const e=o.add(ae).normalize(),t=fe.dot(e).clamp(),s=ae.dot(e).clamp(),n=un({f0:We,f90:1,dotVH:s}),r=pT(),i=fT({dotNH:t});return n.mul(r).mul(i)});class Hp extends $p{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=fe.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Ns({diffuseColor:ee.rgb}))),this.specular===!0&&s.directSpecular.addAssign(r.mul(gT({lightDirection:e})).mul(Bn))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Ns({diffuseColor:ee}))),s.indirectDiffuse.mulAssign(e)}}const mT=new wg;class yT extends ce{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(mT),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new _u(t):null}setupLightingModel(){return new Hp(!1)}}const xT=new Fg;class TT extends ce{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(xT),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new _u(t):null}setupLightingModel(){return new Hp}setupVariants(){const e=(this.shininessNode?g(this.shininessNode):tp).max(1e-4);Yr.assign(e);const t=this.specularNode||np;We.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const qp=b(o=>{if(o.geometry.hasAttribute("normal")===!1)return g(0);const e=lt.dFdx().abs().max(lt.dFdy().abs());return e.x.max(e.y).max(e.z)}),bu=b(o=>{const{roughness:e}=o,t=qp();let s=e.max(.0525);return s=s.add(t),s=s.min(1),s}),Kp=b(({alpha:o,dotNL:e,dotNV:t})=>{const s=o.pow2(),n=e.mul(s.add(s.oneMinus().mul(t.pow2())).sqrt()),r=t.mul(s.add(s.oneMinus().mul(e.pow2())).sqrt());return gt(.5,n.add(r).max(Gd))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),_T=b(({alphaT:o,alphaB:e,dotTV:t,dotBV:s,dotTL:n,dotBL:r,dotNV:i,dotNL:a})=>{const u=a.mul(T(o.mul(t),e.mul(s),i).length()),c=i.mul(T(o.mul(n),e.mul(r),a).length());return gt(.5,u.add(c)).saturate()}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Xp=b(({alpha:o,dotNH:e})=>{const t=o.pow2(),s=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(s.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),bT=g(1/Math.PI),NT=b(({alphaT:o,alphaB:e,dotNH:t,dotTH:s,dotBH:n})=>{const r=o.mul(e),i=T(e.mul(s),o.mul(n),r.mul(t)),a=i.dot(i),u=r.div(a);return bT.mul(r.mul(u.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"}]}),jo=b(o=>{const{lightDirection:e,f0:t,f90:s,roughness:n,f:r,USE_IRIDESCENCE:i,USE_ANISOTROPY:a}=o,u=o.normalView||fe,c=n.pow2(),l=e.add(ae).normalize(),d=u.dot(e).clamp(),h=u.dot(ae).clamp(),p=u.dot(l).clamp(),f=ae.dot(l).clamp();let m=un({f0:t,f90:s,dotVH:f}),x,N;if(Gn(i)&&(m=mi.mix(m,r)),Gn(a)){const v=En.dot(e),w=En.dot(ae),B=En.dot(l),F=_s.dot(e),L=_s.dot(ae),I=_s.dot(l);x=_T({alphaT:Xr,alphaB:c,dotTV:w,dotBV:L,dotTL:v,dotBL:F,dotNV:h,dotNL:d}),N=NT({alphaT:Xr,alphaB:c,dotNH:p,dotTH:B,dotBH:I})}else x=Kp({alpha:c,dotNL:d,dotNV:h}),N=Xp({alpha:c,dotNH:p});return m.mul(x).mul(N)}),Nu=b(({roughness:o,dotNV:e})=>{const t=P(-1,-.0275,-.572,.022),s=P(1,.0425,1.04,-.04),n=o.mul(t).add(s),r=n.x.mul(n.x).min(e.mul(-9.28).exp2()).mul(n.x).add(n.y);return M(-1.04,1.04).mul(r).add(n.zw)}).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Yp=b(o=>{const{dotNV:e,specularColor:t,specularF90:s,roughness:n}=o,r=Nu({dotNV:e,roughness:n});return t.mul(r.x).add(s.mul(r.y))}),jp=b(({f:o,f90:e,dotVH:t})=>{const s=t.oneMinus().saturate(),n=s.mul(s),r=s.mul(n,n).clamp(0,.9999);return o.sub(T(e).mul(r)).div(r.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),ST=b(({roughness:o,dotNH:e})=>{const t=o.pow2(),s=g(1).div(t),r=e.pow2().oneMinus().max(.0078125);return g(2).add(s).mul(r.pow(s.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),vT=b(({dotNV:o,dotNL:e})=>g(1).div(g(4).mul(e.add(o).sub(e.mul(o))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),AT=b(({lightDirection:o})=>{const e=o.add(ae).normalize(),t=fe.dot(o).clamp(),s=fe.dot(ae).clamp(),n=fe.dot(e).clamp(),r=ST({roughness:gi,dotNH:n}),i=vT({dotNV:s,dotNL:t});return fs.mul(r).mul(i)}),RT=b(({N:o,V:e,roughness:t})=>{const r=.0078125,i=o.dot(e).saturate(),a=M(t,i.oneMinus().sqrt());return a.assign(a.mul(.984375).add(r)),a}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),CT=b(({f:o})=>{const e=o.length();return ue(e.mul(e).add(o.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),gr=b(({v1:o,v2:e})=>{const t=o.dot(e),s=t.abs().toVar(),n=s.mul(.0145206).add(.4965155).mul(s).add(.8543985).toVar(),r=s.add(4.1616724).mul(s).add(3.417594).toVar(),i=n.div(r),a=t.greaterThan(0).select(i,ue(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(i));return o.cross(e).mul(a)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),gc=b(({N:o,V:e,P:t,mInv:s,p0:n,p1:r,p2:i,p3:a})=>{const u=r.sub(n).toVar(),c=a.sub(n).toVar(),l=u.cross(c),d=T().toVar();return z(l.dot(t.sub(n)).greaterThanEqual(0),()=>{const h=e.sub(o.mul(e.dot(o))).normalize(),p=o.cross(h).negate(),f=s.mul(Oe(h,p,o).transpose()).toVar(),m=f.mul(n.sub(t)).normalize().toVar(),x=f.mul(r.sub(t)).normalize().toVar(),N=f.mul(i.sub(t)).normalize().toVar(),v=f.mul(a.sub(t)).normalize().toVar(),w=T(0).toVar();w.addAssign(gr({v1:m,v2:x})),w.addAssign(gr({v1:x,v2:N})),w.addAssign(gr({v1:N,v2:v})),w.addAssign(gr({v1:v,v2:m})),d.assign(T(CT({f:w})))}),d}).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"}]}),wi=1/6,Qp=o=>$(wi,$(o,$(o,o.negate().add(3)).sub(3)).add(1)),Qo=o=>$(wi,$(o,$(o,$(3,o).sub(6))).add(4)),Zp=o=>$(wi,$(o,$(o,$(-3,o).add(3)).add(3)).add(1)),Zo=o=>$(wi,ht(o,3)),mc=o=>Qp(o).add(Qo(o)),yc=o=>Zp(o).add(Zo(o)),xc=o=>_e(-1,Qo(o).div(Qp(o).add(Qo(o)))),Tc=o=>_e(1,Zo(o).div(Zp(o).add(Zo(o)))),_c=(o,e,t)=>{const s=o.uvNode,n=$(s,e.zw).add(.5),r=At(n),i=Xt(n),a=mc(i.x),u=yc(i.x),c=xc(i.x),l=Tc(i.x),d=xc(i.y),h=Tc(i.y),p=M(r.x.add(c),r.y.add(d)).sub(.5).mul(e.xy),f=M(r.x.add(l),r.y.add(d)).sub(.5).mul(e.xy),m=M(r.x.add(c),r.y.add(h)).sub(.5).mul(e.xy),x=M(r.x.add(l),r.y.add(h)).sub(.5).mul(e.xy),N=mc(i.y).mul(_e(a.mul(o.sample(p).level(t)),u.mul(o.sample(f).level(t)))),v=yc(i.y).mul(_e(a.mul(o.sample(m).level(t)),u.mul(o.sample(x).level(t))));return N.add(v)},Jp=b(([o,e=g(3)])=>{const t=M(o.size(y(e))),s=M(o.size(y(e.add(1)))),n=gt(1,t),r=gt(1,s),i=_c(o,P(n,t),At(e)),a=_c(o,P(r,s),xi(e));return Xt(e).mix(i,a)}),bc=b(([o,e,t,s,n])=>{const r=T(Qa(e.negate(),qt(o),gt(1,s))),i=T(zt(n[0].xyz),zt(n[1].xyz),zt(n[2].xyz));return qt(r).mul(t.mul(i))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),ET=b(([o,e])=>o.mul(Et(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),wT=fu(),MT=fu(),Nc=b(([o,e,t],{material:s})=>{const r=(s.side===Ct?wT:MT).sample(o),i=vt(Kn.x).mul(ET(e,t));return Jp(r,i)}),Sc=b(([o,e,t])=>(z(t.notEqual(0),()=>{const s=yi(e).negate().div(t);return za(s.negate().mul(o))}),T(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),BT=b(([o,e,t,s,n,r,i,a,u,c,l,d,h,p,f])=>{let m,x;if(f){m=P().toVar(),x=T().toVar();const F=l.sub(1).mul(f.mul(.025)),L=T(l.sub(F),l,l.add(F));te({start:0,end:3},({i:I})=>{const G=L.element(I),X=bc(o,e,d,G,a),ie=i.add(X),Z=c.mul(u.mul(P(ie,1))),Qe=M(Z.xy.div(Z.w)).toVar();Qe.addAssign(1),Qe.divAssign(2),Qe.assign(M(Qe.x,Qe.y.oneMinus()));const Ze=Nc(Qe,t,G);m.element(I).assign(Ze.element(I)),m.a.addAssign(Ze.a),x.element(I).assign(s.element(I).mul(Sc(zt(X),h,p).element(I)))}),m.a.divAssign(3)}else{const F=bc(o,e,d,l,a),L=i.add(F),I=c.mul(u.mul(P(L,1))),G=M(I.xy.div(I.w)).toVar();G.addAssign(1),G.divAssign(2),G.assign(M(G.x,G.y.oneMinus())),m=Nc(G,t,l),x=s.mul(Sc(zt(F),h,p))}const N=x.rgb.mul(m.rgb),v=o.dot(e).clamp(),w=T(Yp({dotNV:v,specularColor:n,specularF90:r,roughness:t})),B=x.r.add(x.g,x.b).div(3);return P(w.oneMinus().mul(N),m.a.oneMinus().mul(B).oneMinus())}),FT=Oe(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),UT=o=>{const e=o.sqrt();return T(1).add(e).div(T(1).sub(e))},vc=(o,e)=>o.sub(e).div(o.add(e)).pow2(),PT=(o,e)=>{const t=o.mul(2*Math.PI*1e-9),s=T(54856e-17,44201e-17,52481e-17),n=T(1681e3,1795300,2208400),r=T(43278e5,93046e5,66121e5),i=g(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp());let a=s.mul(r.mul(2*Math.PI).sqrt()).mul(n.mul(t).add(e).cos()).mul(t.pow2().negate().mul(r).exp());return a=T(a.x.add(i),a.y,a.z).div(10685e-11),FT.mul(a)},DT=b(({outsideIOR:o,eta2:e,cosTheta1:t,thinFilmThickness:s,baseF0:n})=>{const r=Q(o,e,ct(0,.03,s)),a=o.div(r).pow2().mul(t.pow2().oneMinus()).oneMinus();z(a.lessThan(0),()=>T(1));const u=a.sqrt(),c=vc(r,o),l=un({f0:c,f90:1,dotVH:t}),d=l.oneMinus(),h=r.lessThan(o).select(Math.PI,0),p=g(Math.PI).sub(h),f=UT(n.clamp(0,.9999)),m=vc(f,r.toVec3()),x=un({f0:m,f90:1,dotVH:u}),N=T(f.x.lessThan(r).select(Math.PI,0),f.y.lessThan(r).select(Math.PI,0),f.z.lessThan(r).select(Math.PI,0)),v=r.mul(s,u,2),w=T(p).add(N),B=l.mul(x).clamp(1e-5,.9999),F=B.sqrt(),L=d.pow2().mul(x).div(T(1).sub(B)),G=l.add(L).toVar(),X=L.sub(d).toVar();return te({start:1,end:2,condition:"<=",name:"m"},({m:ie})=>{X.mulAssign(F);const Z=PT(g(ie).mul(v),g(ie).mul(w)).mul(2);G.addAssign(X.mul(Z))}),G.max(T(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=b(({normal:o,viewDir:e,roughness:t})=>{const s=o.dot(e).saturate(),n=t.pow2(),r=Ue(t.lessThan(.25),g(-339.2).mul(n).add(g(161.4).mul(t)).sub(25.9),g(-8.48).mul(n).add(g(14.3).mul(t)).sub(9.95)),i=Ue(t.lessThan(.25),g(44).mul(n).sub(g(23.7).mul(t)).add(3.26),g(1.97).mul(n).sub(g(3.27).mul(t)).add(.72));return Ue(t.lessThan(.25),0,g(.1).mul(t).sub(.025)).add(r.mul(s).add(i).exp()).mul(1/Math.PI).saturate()}),zi=T(.04),Wi=g(1);class Su extends Ei{constructor(e=!1,t=!1,s=!1,n=!1,r=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=n,this.transmission=r,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=T().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=T().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=T().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=T().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=T().toVar("sheenSpecularIndirect")),this.iridescence===!0){const t=fe.dot(ae).clamp();this.iridescenceFresnel=DT({outsideIOR:g(1),eta2:Ua,cosTheta1:t,thinFilmThickness:Pa,baseF0:We}),this.iridescenceF0=jp({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(this.transmission===!0){const t=Wt,s=su.sub(Wt).normalize(),n=vi;e.backdrop=BT(n,s,Nt,ee,We,Wn,t,at,je,He,wn,Da,Ia,La,this.dispersion?Va:null),e.backdropAlpha=jr,ee.a.mulAssign(Q(1,e.backdrop.a,jr))}}computeMultiscattering(e,t,s){const n=fe.dot(ae).clamp(),r=Nu({roughness:Nt,dotNV:n}),a=(this.iridescenceF0?mi.mix(We,this.iridescenceF0):We).mul(r.x).add(s.mul(r.y)),c=r.x.add(r.y).oneMinus(),l=We.add(We.oneMinus().mul(.047619)),d=a.mul(l).div(c.mul(l).oneMinus());e.addAssign(a),t.addAssign(d.mul(c))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=fe.dot(e).clamp().mul(t);if(this.sheen===!0&&this.sheenSpecularDirect.addAssign(r.mul(AT({lightDirection:e}))),this.clearcoat===!0){const a=Hs.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(a.mul(jo({lightDirection:e,f0:zi,f90:Wi,roughness:zn,normalView:Hs})))}s.directDiffuse.addAssign(r.mul(Ns({diffuseColor:ee.rgb}))),s.directSpecular.addAssign(r.mul(jo({lightDirection:e,f0:We,f90:1,roughness:Nt,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:n,reflectedLight:r,ltc_1:i,ltc_2:a}){const u=t.add(s).sub(n),c=t.sub(s).sub(n),l=t.sub(s).add(n),d=t.add(s).add(n),h=fe,p=ae,f=xe.toVar(),m=RT({N:h,V:p,roughness:Nt}),x=i.sample(m).toVar(),N=a.sample(m).toVar(),v=Oe(T(x.x,0,x.y),T(0,1,0),T(x.z,0,x.w)).toVar(),w=We.mul(N.x).add(We.oneMinus().mul(N.y)).toVar();r.directSpecular.addAssign(e.mul(w).mul(gc({N:h,V:p,P:f,mInv:v,p0:u,p1:c,p2:l,p3:d}))),r.directDiffuse.addAssign(e.mul(ee).mul(gc({N:h,V:p,P:f,mInv:Oe(1,0,0,0,1,0,0,0,1),p0:u,p1:c,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Ns({diffuseColor:ee})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(t.mul(fs,LT({normal:fe,viewDir:ae,roughness:gi}))),this.clearcoat===!0){const c=Hs.dot(ae).clamp(),l=Yp({dotNV:c,specularColor:zi,specularF90:Wi,roughness:zn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(l))}const n=T().toVar("singleScattering"),r=T().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(n,r,Wn);const a=n.add(r),u=ee.mul(a.r.max(a.g).max(a.b).oneMinus());s.indirectSpecular.addAssign(e.mul(n)),s.indirectSpecular.addAssign(r.mul(i)),s.indirectDiffuse.addAssign(u.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const n=fe.dot(ae).clamp().add(e),r=Nt.mul(-16).oneMinus().negate().exp2(),i=e.sub(n.pow(r).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(e),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(i)}finish(e){const{outgoingLight:t}=e;if(this.clearcoat===!0){const s=Hs.dot(ae).clamp(),n=un({dotVH:s,f0:zi,f90:Wi}),r=t.mul(Kr.mul(n).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Kr));t.assign(r)}if(this.sheen===!0){const s=fs.r.max(fs.g).max(fs.b).mul(.157).oneMinus(),n=t.mul(s).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(n)}}}const Ac=g(1),Jo=g(-2),mr=g(.8),$i=g(-1),yr=g(.4),Hi=g(2),xr=g(.305),qi=g(3),Rc=g(.21),IT=g(4),Cc=g(4),VT=g(16),GT=b(([o])=>{const e=T(oe(o)).toVar(),t=g(-1).toVar();return z(e.x.greaterThan(e.z),()=>{z(e.x.greaterThan(e.y),()=>{t.assign(Ue(o.x.greaterThan(0),0,3))}).Else(()=>{t.assign(Ue(o.y.greaterThan(0),1,4))})}).Else(()=>{z(e.z.greaterThan(e.y),()=>{t.assign(Ue(o.z.greaterThan(0),2,5))}).Else(()=>{t.assign(Ue(o.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),OT=b(([o,e])=>{const t=M().toVar();return z(e.equal(0),()=>{t.assign(M(o.z,o.y).div(oe(o.x)))}).ElseIf(e.equal(1),()=>{t.assign(M(o.x.negate(),o.z.negate()).div(oe(o.y)))}).ElseIf(e.equal(2),()=>{t.assign(M(o.x.negate(),o.y).div(oe(o.z)))}).ElseIf(e.equal(3),()=>{t.assign(M(o.z.negate(),o.y).div(oe(o.x)))}).ElseIf(e.equal(4),()=>{t.assign(M(o.x.negate(),o.z).div(oe(o.y)))}).Else(()=>{t.assign(M(o.x,o.y).div(oe(o.z)))}),$(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),kT=b(([o])=>{const e=g(0).toVar();return z(o.greaterThanEqual(mr),()=>{e.assign(Ac.sub(o).mul($i.sub(Jo)).div(Ac.sub(mr)).add(Jo))}).ElseIf(o.greaterThanEqual(yr),()=>{e.assign(mr.sub(o).mul(Hi.sub($i)).div(mr.sub(yr)).add($i))}).ElseIf(o.greaterThanEqual(xr),()=>{e.assign(yr.sub(o).mul(qi.sub(Hi)).div(yr.sub(xr)).add(Hi))}).ElseIf(o.greaterThanEqual(Rc),()=>{e.assign(xr.sub(o).mul(IT.sub(qi)).div(xr.sub(Rc)).add(qi))}).Else(()=>{e.assign(g(-2).mul(vt($(1.16,o))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),ef=b(([o,e])=>{const t=o.toVar();t.assign($(2,t).sub(1));const s=T(t,1).toVar();return z(e.equal(0),()=>{s.assign(s.zyx)}).ElseIf(e.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(e.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(e.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(e.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(e.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),tf=b(([o,e,t,s,n,r])=>{const i=g(t),a=T(e),u=Et(kT(i),Jo,r),c=Xt(u),l=At(u),d=T(ea(o,a,l,s,n,r)).toVar();return z(c.notEqual(0),()=>{const h=T(ea(o,a,l.add(1),s,n,r)).toVar();d.assign(Q(d,h,c))}),d}),ea=b(([o,e,t,s,n,r])=>{const i=g(t).toVar(),a=T(e),u=g(GT(a)).toVar(),c=g(ue(Cc.sub(i),0)).toVar();i.assign(ue(i,Cc));const l=g(rn(i)).toVar(),d=M(OT(a,u).mul(l.sub(2)).add(1)).toVar();return z(u.greaterThan(2),()=>{d.y.addAssign(l),u.subAssign(3)}),d.x.addAssign(u.mul(l)),d.x.addAssign(c.mul($(3,VT))),d.y.addAssign($(4,rn(r).sub(l))),d.x.mulAssign(s),d.y.mulAssign(n),o.sample(d).grad(M(),M())}),Ki=b(({envMap:o,mipInt:e,outputDirection:t,theta:s,axis:n,CUBEUV_TEXEL_WIDTH:r,CUBEUV_TEXEL_HEIGHT:i,CUBEUV_MAX_MIP:a})=>{const u=It(s),c=t.mul(u).add(n.cross(t).mul(st(s))).add(n.mul(n.dot(t).mul(u.oneMinus())));return ea(o,c,e,r,i,a)}),sf=b(({n:o,latitudinal:e,poleAxis:t,outputDirection:s,weights:n,samples:r,dTheta:i,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:d})=>{const h=T(Ue(e,t,_i(t,s))).toVar();z(ka(h.equals(T(0))),()=>{h.assign(T(s.z,0,s.x.negate()))}),h.assign(qt(h));const p=T().toVar();return p.addAssign(n.element(y(0)).mul(Ki({theta:0,axis:h,outputDirection:s,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:d}))),te({start:y(1),end:o},({i:f})=>{z(f.greaterThanEqual(r),()=>{pu()});const m=g(i.mul(g(f))).toVar();p.addAssign(n.element(f).mul(Ki({theta:m.mul(-1),axis:h,outputDirection:s,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:d}))),p.addAssign(n.element(f).mul(Ki({theta:m,axis:h,outputDirection:s,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:d})))}),P(p,1)});let ti=null;const Ec=new WeakMap;function zT(o){const e=Math.log2(o)-2,t=1/o;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:t,maxMip:e}}function WT(o){let e=Ec.get(o);if((e!==void 0?e.pmremVersion:-1)!==o.pmremVersion){const s=o.image;if(o.isCubeTexture)if(HT(s))e=ti.fromCubemap(o,e);else return null;else if(qT(s))e=ti.fromEquirectangular(o,e);else return null;e.pmremVersion=o.pmremVersion,Ec.set(o,e)}return e.texture}class $T extends be{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const n=new aa;n.isRenderTargetTexture=!0,this._texture=K(n),this._width=V(0),this._height=V(0),this._maxMip=V(0),this.updateBeforeType=W.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=zT(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(s.isPMREMTexture===!0?e=s:e=WT(s),e!==null&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){ti===null&&(ti=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===Pn&&s.isPMREMTexture!==!0&&s.isRenderTargetTexture===!0&&(t=T(t.x.negate(),t.yz)),t=T(t.x,t.y.negate(),t.z);let n=this.levelNode;return n===null&&e.context.getTextureLevel&&(n=e.context.getTextureLevel(this)),tf(this._texture,t,n,this._width,this._height,this._maxMip)}}function HT(o){if(o==null)return!1;let e=0;const t=6;for(let s=0;s<t;s++)o[s]!==void 0&&e++;return e===t}function qT(o){return o==null?!1:o.height>0}const vu=C($T),wc=new WeakMap;class KT extends hn{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const p=s.isTextureNode?s.value:t[s.property];let f=wc.get(p);f===void 0&&(f=vu(p),wc.set(p,f)),s=f}const r=t.envMap?ne("envMapIntensity","float",e.material):ne("environmentIntensity","float",e.scene),a=t.useAnisotropy===!0||t.anisotropy>0?Zh:fe,u=s.context(Mc(Nt,a)).mul(r),c=s.context(XT(vi)).mul(Math.PI).mul(r),l=Mn(u),d=Mn(c);e.context.radiance.addAssign(l),e.context.iblIrradiance.addAssign(d);const h=e.context.lightingModel.clearcoatRadiance;if(h){const p=s.context(Mc(zn,Hs)).mul(r),f=Mn(p);h.addAssign(f)}}}const Mc=(o,e)=>{let t=null;return{getUV:()=>(t===null&&(t=ae.negate().reflect(e),t=o.mul(o).mix(t,e).normalize(),t=t.transformDirection(je)),t),getTextureLevel:()=>o}},XT=o=>({getUV:()=>o,getTextureLevel:()=>g(1)}),YT=new Pg;class nf extends ce{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(YT),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new KT(t):null}setupLightingModel(){return new Su}setupSpecular(){const e=Q(T(.04),ee.rgb,kn);We.assign(e),Wn.assign(1)}setupVariants(){const e=this.metalnessNode?g(this.metalnessNode):op;kn.assign(e);let t=this.roughnessNode?g(this.roughnessNode):ip;t=bu({roughness:t}),Nt.assign(t),this.setupSpecular(),ee.assign(P(ee.rgb.mul(e.oneMinus()),ee.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const jT=new Ug;class rf extends nf{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(jT),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){const e=this.iorNode?g(this.iorNode):_p;wn.assign(e),We.assign(Q(Re(Ya(wn.sub(1).div(wn.add(1))).mul(rp),T(1)).mul(Yo),ee.rgb,kn)),Wn.assign(Q(Yo,1,kn))}setupLightingModel(){return new Su(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const t=this.clearcoatNode?g(this.clearcoatNode):up,s=this.clearcoatRoughnessNode?g(this.clearcoatRoughnessNode):cp;Kr.assign(t),zn.assign(bu({roughness:s}))}if(this.useSheen){const t=this.sheenNode?T(this.sheenNode):hp,s=this.sheenRoughnessNode?g(this.sheenRoughnessNode):pp;fs.assign(t),gi.assign(s)}if(this.useIridescence){const t=this.iridescenceNode?g(this.iridescenceNode):gp,s=this.iridescenceIORNode?g(this.iridescenceIORNode):mp,n=this.iridescenceThicknessNode?g(this.iridescenceThicknessNode):yp;mi.assign(t),Ua.assign(s),Pa.assign(n)}if(this.useAnisotropy){const t=(this.anisotropyNode?M(this.anisotropyNode):fp).toVar();Zt.assign(t.length()),z(Zt.equal(0),()=>{t.assign(M(1,0))}).Else(()=>{t.divAssign(M(Zt)),Zt.assign(Zt.saturate())}),Xr.assign(Zt.pow2().mix(Nt.pow2(),1)),En.assign(gs[0].mul(t.x).add(gs[1].mul(t.y))),_s.assign(gs[1].mul(t.x).sub(gs[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?g(this.transmissionNode):xp,s=this.thicknessNode?g(this.thicknessNode):Tp,n=this.attenuationDistanceNode?g(this.attenuationDistanceNode):bp,r=this.attenuationColorNode?T(this.attenuationColorNode):Np;if(jr.assign(t),Da.assign(s),La.assign(n),Ia.assign(r),this.useDispersion){const i=this.dispersionNode?g(this.dispersionNode):vp;Va.assign(i)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?T(this.clearcoatNormalNode):lp}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.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class QT extends Su{constructor(e=!1,t=!1,s=!1,n=!1,r=!1,i=!1,a=!1){super(e,t,s,n,r,i),this.useSSS=a}direct({lightDirection:e,lightColor:t,reflectedLight:s},n,r){if(this.useSSS===!0){const i=r.material,{thicknessColorNode:a,thicknessDistortionNode:u,thicknessAmbientNode:c,thicknessAttenuationNode:l,thicknessPowerNode:d,thicknessScaleNode:h}=i,p=e.add(fe.mul(u)).normalize(),f=g(ae.dot(p.negate()).saturate().pow(d).mul(h)),m=T(f.add(c).mul(a));s.directDiffuse.addAssign(m.mul(l.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},n,r)}}class pR extends rf{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=g(.1),this.thicknessAmbientNode=g(0),this.thicknessAttenuationNode=g(.1),this.thicknessPowerNode=g(2),this.thicknessScaleNode=g(10)}get useSSS(){return this.thicknessColorNode!==null}setupLightingModel(){return new QT(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const ZT=b(({normal:o,lightDirection:e,builder:t})=>{const s=o.dot(e),n=M(s.mul(.5).add(.5),0);if(t.material.gradientMap){const r=dt("gradientMap","texture").context({getUV:()=>n});return T(r.r)}else{const r=n.fwidth().mul(.5);return Q(T(.7),T(1),ct(g(.7).sub(r.x),g(.7).add(r.x),n.x))}});class JT extends Ei{direct({lightDirection:e,lightColor:t,reflectedLight:s},n,r){const i=ZT({normal:Ni,lightDirection:e,builder:r}).mul(t);s.directDiffuse.addAssign(i.mul(Ns({diffuseColor:ee.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Ns({diffuseColor:ee}))),s.indirectDiffuse.mulAssign(e)}}const e_=new Dg;class t_ extends ce{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(e_),this.setValues(e)}setupLightingModel(){return new JT}}class s_ extends be{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=T(ae.z,0,ae.x.negate()).normalize(),t=ae.cross(e);return M(e.dot(fe),t.dot(fe)).mul(.495).add(.5)}}const of=U(s_),n_=new Mg;class r_ extends ce{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(n_),this.setValues(e)}setupVariants(e){const t=of;let s;e.material.matcap?s=dt("matcap","texture").context({getUV:()=>t}):s=T(Q(.2,.8,t.y)),ee.rgb.mulAssign(s.rgb)}}const i_=new hl;class o_ extends ce{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.setDefaultValues(i_),this.setValues(e)}}class a_ extends be{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if(this.getNodeType(e)==="vec2"){const r=t.cos(),i=t.sin();return fi(r,i,i.negate(),r).mul(s)}else{const r=t,i=Ts(P(1,0,0,0),P(0,It(r.x),st(r.x).negate(),0),P(0,st(r.x),It(r.x),0),P(0,0,0,1)),a=Ts(P(It(r.y),0,st(r.y),0),P(0,1,0,0),P(st(r.y).negate(),0,It(r.y),0),P(0,0,0,1)),u=Ts(P(It(r.z),st(r.z).negate(),0,0),P(st(r.z),It(r.z),0,0),P(0,0,1,0),P(0,0,0,1));return i.mul(a).mul(u).mul(P(s,1)).xyz}}}const Au=C(a_),u_=new Hg;class c_ extends ce{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(u_),this.setValues(e)}setupPositionView(e){const{object:t,camera:s}=e,n=this.sizeAttenuation,{positionNode:r,rotationNode:i,scaleNode:a}=this,u=Kt.mul(T(r||0));let c=M(at[0].xyz.length(),at[1].xyz.length());if(a!==null&&(c=c.mul(a)),n===!1)if(s.isPerspectiveCamera)c=c.mul(u.z.negate());else{const p=g(2).div(He.element(1).element(1));c=c.mul(p.mul(2))}let l=Ce.xy;if(t.center&&t.center.isVector2===!0){const p=By("center","vec2",t);l=l.sub(p.sub(.5))}l=l.mul(c);const d=g(i||dp),h=Au(l,d);return P(u.xy.add(h),u.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)}}class l_ extends Ei{constructor(){super(),this.shadowNode=g(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ee.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ee.rgb)}}const d_=new $g;class h_ extends ce{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(d_),this.setValues(e)}setupLightingModel(){return new l_}}const p_=b(({texture:o,uv:e})=>{const s=T().toVar();return z(e.x.lessThan(1e-4),()=>{s.assign(T(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{s.assign(T(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{s.assign(T(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{s.assign(T(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{s.assign(T(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{s.assign(T(0,0,-1))}).Else(()=>{const r=o.sample(e.add(T(-.01,0,0))).r.sub(o.sample(e.add(T(.01,0,0))).r),i=o.sample(e.add(T(0,-.01,0))).r.sub(o.sample(e.add(T(0,.01,0))).r),a=o.sample(e.add(T(0,0,-.01))).r.sub(o.sample(e.add(T(0,0,.01))).r);s.assign(T(r,i,a))}),s.normalize()});class f_ extends wt{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return T(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.isRenderTargetTexture===!0||s.isFramebufferTexture===!0)&&(this.sampler?t=t.flipY():t=t.setY(y(ns(this,this.levelNode).y).sub(t.y).sub(1))),t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return p_({texture:this,uv:e})}}const af=C(f_);class fR extends ce{static get type(){return"VolumeNodeMaterial"}constructor(e){super(),this.isVolumeNodeMaterial=!0,this.base=new mt(16777215),this.map=null,this.steps=100,this.testNode=null,this.setValues(e)}setup(e){const t=af(this.map,null,0),s=b(({orig:n,dir:r})=>{const i=T(-.5),a=T(.5),u=r.reciprocal(),c=i.sub(n).mul(u),l=a.sub(n).mul(u),d=Re(c,l),h=ue(c,l),p=ue(d.x,ue(d.y,d.z)),f=Re(h.x,Re(h.y,h.z));return M(p,f)});this.fragmentNode=b(()=>{const n=ke(T(Ih.mul(P(su,1)))),i=ke(Ce.sub(n)).normalize(),a=M(s({orig:n,dir:i})).toVar();a.x.greaterThan(a.y).discard(),a.assign(M(ue(a.x,0),a.y));const u=T(n.add(a.x.mul(i))).toVar(),c=T(i.abs().reciprocal()).toVar(),l=g(Re(c.x,Re(c.y,c.z))).toVar("delta");l.divAssign(dt("steps","float"));const d=P(dt("base","color"),0).toVar();return te({type:"float",start:a.x,end:a.y,update:"+= delta"},()=>{const h=Fa("float","d").assign(t.sample(u.add(.5)).r);this.testNode!==null?this.testNode({map:t,mapValue:h,probe:u,finalColor:d}).append():(d.a.assign(1),pu()),u.addAssign(i.mul(l))}),d.a.equal(0).discard(),P(d)})(),super.setup(e)}}class g_{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this._animationLoop!==null&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ft{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s<e.length;s++)if(t=t.get(e[s]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let s=this.weakMap;for(let n=0;n<e.length;n++){const r=e[n];s.has(r)===!1&&s.set(r,new WeakMap),s=s.get(r)}return s.set(e[e.length-1],t),this}delete(e){let t=this.weakMap;for(let s=0;s<e.length;s++)if(t=t.get(e[s]),t===void 0)return!1;return t.delete(e[e.length-1])}}let m_=0;function y_(o){const e=Object.keys(o);let t=Object.getPrototypeOf(o);for(;t;){const s=Object.getOwnPropertyDescriptors(t);for(const n in s)if(s[n]!==void 0){const r=s[n];r&&typeof r.get=="function"&&e.push(n)}t=Object.getPrototypeOf(t)}return e}class x_{constructor(e,t,s,n,r,i,a,u,c,l){this.id=m_++,this._nodes=e,this._geometries=t,this.renderer=s,this.object=n,this.material=r,this.scene=i,this.camera=a,this.lightsNode=u,this.context=c,this.geometry=n.geometry,this.version=r.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=l,this.clippingContextCacheKey=l!==null?l.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 this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}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(this.attributes!==null)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],n=new Set;for(const r of e){const i=r.node&&r.node.attribute?r.node.attribute:t.getAttribute(r.name);if(i===void 0)continue;s.push(i);const a=i.isInterleavedBufferAttribute?i.data:i;n.add(a)}return this.attributes=s,this.vertexBuffers=Array.from(n.values()),s}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:n,drawRange:r}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),u=a!==null,c=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(c===0)return null;if(i.instanceCount=c,e.isBatchedMesh===!0)return i;let l=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(l=2);let d=r.start*l,h=(r.start+r.count)*l;n!==null&&(d=Math.max(d,n.start*l),h=Math.min(h,(n.start+n.count)*l));const p=s.attributes.position;let f=1/0;u?f=a.count:p!=null&&(f=p.count),d=Math.max(d,0),h=Math.min(h,f);const m=h-d;return m<0||m===1/0?null:(i.vertexCount=m,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const n=e.attributes[s];t+=s+",",n.data&&(t+=n.data.stride+","),n.offset&&(t+=n.offset+","),n.itemSize&&(t+=n.itemSize+","),n.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const n of y_(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(n))continue;const r=t[n];let i;if(r!==null){const a=typeof r;a==="number"?i=r!==0?"1":"0":a==="object"?(i="{",r.isTexture&&(i+=r.mapping),i+="}"):i=String(r)}else i=String(r);s+=i+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),s+=e.receiveShadow+",",ga(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Bs=[];class T_{constructor(e,t,s,n,r,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=n,this.bindings=r,this.info=i,this.chainMaps={}}get(e,t,s,n,r,i,a,u){const c=this.getChainMap(u);Bs[0]=e,Bs[1]=t,Bs[2]=i,Bs[3]=r;let l=c.get(Bs);return l===void 0?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,n,r,i,a,u),c.set(Bs,l)):(l.updateClipping(a),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,n,r,i,a,u)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ft)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,n,r,i,a,u,c,l,d){const h=this.getChainMap(d),p=new x_(e,t,s,n,r,i,a,u,c,l);return p.onDispose=()=>{this.pipelines.delete(p),this.bindings.delete(p),this.nodes.delete(p),h.delete(p.getChainArray())},p}}class os{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const St={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},ts=16,__=211,b_=212;class N_ extends os{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return t!==void 0&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(s.version===void 0)t===St.VERTEX?this.backend.createAttribute(e):t===St.INDEX?this.backend.createIndexAttribute(e):t===St.STORAGE?this.backend.createStorageAttribute(e):t===St.INDIRECT&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const n=this._getBufferAttribute(e);(s.version<n.version||n.usage===zs)&&(this.backend.updateAttribute(e),s.version=n.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function S_(o){for(let e=o.length-1;e>=0;--e)if(o[e]>=65535)return!0;return!1}function uf(o){return o.index!==null?o.index.version:o.attributes.position.version}function Bc(o){const e=[],t=o.index,s=o.attributes.position;if(t!==null){const r=t.array;for(let i=0,a=r.length;i<a;i+=3){const u=r[i+0],c=r[i+1],l=r[i+2];e.push(u,c,c,l,l,u)}}else{const r=s.array;for(let i=0,a=r.length/3-1;i<a;i+=3){const u=i+0,c=i+1,l=i+2;e.push(u,c,c,l,l,u)}}const n=new(S_(e)?Em:wm)(e,1);return n.version=uf(o),n}class v_ extends os{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry,s=this.get(t);s.initialized=!0,this.info.memory.geometries++;const n=()=>{this.info.memory.geometries--;const r=t.index,i=e.getAttributes();r!==null&&this.attributes.delete(r);for(const u of i)this.attributes.delete(u);const a=this.wireframes.get(t);a!==void 0&&this.attributes.delete(a),t.removeEventListener("dispose",n)};t.addEventListener("dispose",n)}updateAttributes(e){const t=e.getAttributes();for(const r of t)r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute?this.updateAttribute(r,St.STORAGE):this.updateAttribute(r,St.VERTEX);const s=this.getIndex(e);s!==null&&this.updateAttribute(s,St.INDEX);const n=e.geometry.indirect;n!==null&&this.updateAttribute(n,St.INDIRECT)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let n=t.index;if(s.wireframe===!0){const r=this.wireframes;let i=r.get(t);i===void 0?(i=Bc(t),r.set(t,i)):i.version!==uf(t)&&(this.attributes.delete(i),i=Bc(t),r.set(t,i)),n=i}return n}}class A_{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,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){this[e].timestampCalls===0&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,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 cf{constructor(e){this.cacheKey=e,this.usedTimes=0}}class R_ extends cf{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class C_ extends cf{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let E_=0;class Xi{constructor(e,t,s,n=null,r=null){this.id=E_++,this.code=e,this.stage=t,this.name=s,this.transforms=n,this.attributes=r,this.usedTimes=0}}class w_ extends os{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,n=this.get(e);if(this._needsComputeUpdate(e)){const r=n.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let a=this.programs.compute.get(i.computeShader);a===void 0&&(r&&r.computeProgram.usedTimes===0&&this._releaseProgram(r.computeProgram),a=new Xi(i.computeShader,"compute",e.name,i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,a),s.createProgram(a));const u=this._getComputeCacheKey(e,a);let c=this.caches.get(u);c===void 0&&(r&&r.usedTimes===0&&this._releasePipeline(r),c=this._getComputePipeline(e,a,u,t)),c.usedTimes++,a.usedTimes++,n.version=e.version,n.pipeline=c}return n.pipeline}getForRender(e,t=null){const{backend:s}=this,n=this.get(e);if(this._needsRenderUpdate(e)){const r=n.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState(),a=e.material?e.material.name:"";let u=this.programs.vertex.get(i.vertexShader);u===void 0&&(r&&r.vertexProgram.usedTimes===0&&this._releaseProgram(r.vertexProgram),u=new Xi(i.vertexShader,"vertex",a),this.programs.vertex.set(i.vertexShader,u),s.createProgram(u));let c=this.programs.fragment.get(i.fragmentShader);c===void 0&&(r&&r.fragmentProgram.usedTimes===0&&this._releaseProgram(r.fragmentProgram),c=new Xi(i.fragmentShader,"fragment",a),this.programs.fragment.set(i.fragmentShader,c),s.createProgram(c));const l=this._getRenderCacheKey(e,u,c);let d=this.caches.get(l);d===void 0?(r&&r.usedTimes===0&&this._releasePipeline(r),d=this._getRenderPipeline(e,u,c,l,t)):e.pipeline=d,d.usedTimes++,u.usedTimes++,c.usedTimes++,n.pipeline=d}return n.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,n){s=s||this._getComputeCacheKey(e,t);let r=this.caches.get(s);return r===void 0&&(r=new C_(s,t),this.caches.set(s,r),this.backend.createComputePipeline(r,n)),r}_getRenderPipeline(e,t,s,n,r){n=n||this._getRenderCacheKey(e,t,s);let i=this.caches.get(n);return i===void 0&&(i=new R_(n,t,s),this.caches.set(n,i),e.pipeline=i,this.backend.createRenderPipeline(e,r)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}}class M_ extends os{constructor(e,t,s,n,r,i){super(),this.backend=e,this.textures=s,this.pipelines=r,this.attributes=n,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const s of t){const n=this.get(s);n.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),n.bindGroup=s)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const s of t){const n=this.get(s);n.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),n.bindGroup=s)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const s=t.attribute,n=s.isIndirectStorageBufferAttribute?St.INDIRECT:St.STORAGE;this.attributes.update(s,n)}}_update(e,t){const{backend:s}=this;let n=!1,r=!0,i=0,a=0;for(const u of e.bindings)if(!(u.isNodeUniformsGroup&&this.nodes.updateGroup(u)===!1)){if(u.isUniformBuffer)u.update()&&s.updateBinding(u);else if(u.isSampler)u.update();else if(u.isSampledTexture){const c=this.textures.get(u.texture);u.needsBindingsUpdate(c.generation)&&(n=!0);const l=u.update(),d=u.texture;l&&this.textures.updateTexture(d);const h=s.get(d);if(h.externalTexture!==void 0||c.isDefaultTexture?r=!1:(i=i*10+d.id,a+=d.version),s.isWebGPUBackend===!0&&h.texture===void 0&&h.externalTexture===void 0&&(console.error("Bindings._update: binding should be available:",u,l,d,u.textureNode.value,n),this.textures.updateTexture(d),n=!0),d.isStorageTexture===!0){const p=this.get(d);u.store===!0?p.needsMipmap=!0:this.textures.needsMipmaps(d)&&p.needsMipmap===!0&&(this.backend.generateMipmaps(d),p.needsMipmap=!1)}}}n===!0&&this.backend.updateBindings(e,t,r?i:0,a)}}function B_(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.material.id!==e.material.id?o.material.id-e.material.id:o.z!==e.z?o.z-e.z:o.id-e.id}function Fc(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?e.z-o.z:o.id-e.id}function Uc(o){return(o.transmission>0||o.transmissionNode)&&o.side===js&&o.forceSinglePass===!1}class F_{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,n,r,i,a){let u=this.renderItems[this.renderItemsIndex];return u===void 0?(u={id:e.id,object:e,geometry:t,material:s,groupOrder:n,renderOrder:e.renderOrder,z:r,group:i,clippingContext:a},this.renderItems[this.renderItemsIndex]=u):(u.id=e.id,u.object=e,u.geometry=t,u.material=s,u.groupOrder=n,u.renderOrder=e.renderOrder,u.z=r,u.group=i,u.clippingContext=a),this.renderItemsIndex++,u}push(e,t,s,n,r,i,a){const u=this.getNextRenderItem(e,t,s,n,r,i,a);e.occlusionTest===!0&&this.occlusionQueryCount++,s.transparent===!0||s.transmission>0?(Uc(s)&&this.transparentDoublePass.push(u),this.transparent.push(u)):this.opaque.push(u)}unshift(e,t,s,n,r,i,a){const u=this.getNextRenderItem(e,t,s,n,r,i,a);s.transparent===!0||s.transmission>0?(Uc(s)&&this.transparentDoublePass.unshift(u),this.transparent.unshift(u)):this.opaque.unshift(u)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||B_),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||Fc),this.transparent.length>1&&this.transparent.sort(t||Fc)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const s=this.renderItems[e];if(s.id===null)break;s.id=null,s.object=null,s.geometry=null,s.material=null,s.groupOrder=null,s.renderOrder=null,s.z=null,s.group=null,s.clippingContext=null}}}class U_{constructor(e){this.lighting=e,this.lists=new Ft}get(e,t){const s=this.lists,n=[e,t];let r=s.get(n);return r===void 0&&(r=new F_(this.lighting,e,t),s.set(n,r)),r}dispose(){this.lists=new Ft}}let P_=0;class D_{constructor(){this.id=P_++,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 Me,this.scissor=!1,this.scissorValue=new Me,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}getCacheKey(){return lf(this)}}function lf(o){const{textures:e,activeCubeFace:t}=o,s=[t];for(const n of e)s.push(n.id);return Zn(s)}class L_{constructor(){this.chainMaps={}}get(e=null,t=null,s=null){const n=[];e!==null&&n.push(e),t!==null&&n.push(t),n.length===0&&n.push({id:"default"});let r;if(s===null)r="default";else{const u=s.texture.format;r=`${s.textures.length}:${u}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const i=this.getChainMap(r);let a=i.get(n);return a===void 0&&(a=new D_,i.set(n,a)),s!==null&&(a.sampleCount=s.samples===0?1:s.samples),a}getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new Ft)}dispose(){this.chainMaps={}}}const I_=new j;class V_ extends os{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){const s=this.get(e),n=e.samples===0?1:e.samples,r=s.depthTextureMips||(s.depthTextureMips={}),i=e.textures,a=this.getSize(i[0]),u=a.width>>t,c=a.height>>t;let l=e.depthTexture||r[t];const d=e.depthBuffer===!0||e.stencilBuffer===!0;let h=!1;l===void 0&&d&&(l=new vs,l.format=e.stencilBuffer?oi:ai,l.type=e.stencilBuffer?ui:Le,l.image.width=u,l.image.height=c,r[t]=l),(s.width!==a.width||a.height!==s.height)&&(h=!0,l&&(l.needsUpdate=!0,l.image.width=u,l.image.height=c)),s.width=a.width,s.height=a.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==n&&(h=!0,l&&(l.needsUpdate=!0),s.sampleCount=n);const p={sampleCount:n};for(let f=0;f<i.length;f++){const m=i[f];h&&(m.needsUpdate=!0),this.updateTexture(m,p)}if(l&&this.updateTexture(l,p),s.initialized!==!0){s.initialized=!0;const f=()=>{e.removeEventListener("dispose",f);for(let m=0;m<i.length;m++)this._destroyTexture(i[m]);l&&this._destroyTexture(l),this.delete(e)};e.addEventListener("dispose",f)}}updateTexture(e,t={}){const s=this.get(e);if(s.initialized===!0&&s.version===e.version)return;const n=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,r=this.backend;if(n&&s.initialized===!0&&(r.destroySampler(e),r.destroyTexture(e)),e.isFramebufferTexture){const c=this.renderer.getRenderTarget();c?e.type=c.texture.type:e.type=ys}const{width:i,height:a,depth:u}=this.getSize(e);if(t.width=i,t.height=a,t.depth=u,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,i,a):1,n||e.isStorageTexture===!0)r.createSampler(e),r.createTexture(e,t),s.generation=e.version;else if(s.initialized!==!0&&r.createSampler(e),e.version>0){const l=e.image;if(l===void 0)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(l.complete===!1)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const d=[];for(const h of e.images)d.push(h);t.images=d}else t.image=l;(s.isDefaultTexture===void 0||s.isDefaultTexture===!0)&&(r.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),e.source.dataReady===!0&&r.updateTexture(e,t),t.needsMipmaps&&e.mipmaps.length===0&&r.generateMipmaps(e)}}else r.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version;if(s.initialized!==!0){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const c=()=>{e.removeEventListener("dispose",c),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",c)}s.version=e.version}getSize(e,t=I_){let s=e.images?e.images[0]:e.image;return s?(s.image!==void 0&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let n;return e.isCompressedTexture?e.mipmaps?n=e.mipmaps.length:n=1:n=Math.floor(Math.log2(Math.max(t,s)))+1,n}needsMipmaps(e){return this.isEnvironmentTexture(e)||e.isCompressedTexture===!0||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===jn||t===Qn||t===Zs||t===Js}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class Ru extends mt{constructor(e,t,s,n=1){super(e,t,s),this.a=n}set(e,t,s,n=1){return this.a=n,super.set(e,t,s)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class df extends se{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const G_=(o,e)=>E(new df(o,e));class O_ extends O{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new Cn(t);return this._currentCond=Ue(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new Cn(t),n=Ue(e,s);return this._currentCond.elseNode=n,this._currentCond=n,this}Else(e){return this._currentCond.elseNode=new Cn(e),this}build(e,...t){const s=Ea();On(this);for(const n of this.nodes)n.build(e,"void");return On(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const kr=C(O_);class hf extends O{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let n=0;n<t.length;n++)s.push(t[n].getNodeType(e));this.nodeType=e.getStructTypeFromNode(this,s).name}generate(e,t){const s=e.getOutputStructName(),n=this.members,r=s!==""?s+".":"";for(let i=0;i<n.length;i++){const a=n[i].build(e,t);e.addLineFlowCode(`${r}m${i} = ${a}`,this)}return s}}const k_=C(hf);function pf(o,e){for(let t=0;t<o.length;t++)if(o[t].name===e)return t;return-1}class z_ extends hf{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.isMRTNode=!0}has(e){return this.outputNodes[e]!==void 0}get(e){return this.outputNodes[e]}merge(e){const t={...this.outputNodes,...e.outputNodes};return ff(t)}setup(e){const t=this.outputNodes,s=e.renderer.getRenderTarget(),n=[],r=s.textures;for(const i in t){const a=pf(r,i);n[a]=P(t[i])}return this.members=n,super.setup(e)}}const ff=C(z_),W_=b(([o])=>{const e=o.toUint().mul(747796405).add(2891336453),t=e.shiftRight(e.shiftRight(28).add(4)).bitXor(e).mul(277803737);return t.shiftRight(22).bitXor(t).toFloat().mul(1/2**32)}),ta=(o,e)=>ht($(4,o.mul(Y(1,o))),e),$_=(o,e)=>o.lessThan(.5)?ta(o.mul(2),e).div(2):Y(1,ta($(Y(1,o),2),e).div(2)),H_=(o,e,t)=>ht(gt(ht(o,e),_e(ht(o,e),ht(Y(1,o),t))),1/e),q_=(o,e)=>st(Qr.mul(e.mul(o).sub(1))).div(Qr.mul(e.mul(o).sub(1))),Vt=b(([o])=>o.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),K_=b(([o])=>T(Vt(o.z.add(Vt(o.y.mul(1)))),Vt(o.z.add(Vt(o.x.mul(1)))),Vt(o.y.add(Vt(o.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),X_=b(([o,e,t])=>{const s=T(o).toVar(),n=g(1.4).toVar(),r=g(0).toVar(),i=T(s).toVar();return te({start:g(0),end:g(3),type:"float",condition:"<="},()=>{const a=T(K_(i.mul(2))).toVar();s.addAssign(a.add(t.mul(g(.1).mul(e)))),i.mulAssign(1.8),n.mulAssign(1.5),s.mulAssign(1.2);const u=g(Vt(s.z.add(Vt(s.x.add(Vt(s.y)))))).toVar();r.addAssign(u.div(n)),i.addAssign(.14)}),r}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"position",type:"vec3"},{name:"speed",type:"float"},{name:"time",type:"float"}]});class Y_ extends O{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){const t=this.parametersNodes;let s=this._candidateFnCall;if(s===null){let n=null,r=-1;for(const i of this.functionNodes){const u=i.shaderNode.layout;if(u===null)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const c=u.inputs;if(t.length===c.length){let l=0;for(let d=0;d<t.length;d++){const h=t[d],p=c[d];h.getNodeType(e)===p.type?l++:l=0}l>r&&(n=i,r=l)}}this._candidateFnCall=s=n(...t)}return s}}const j_=C(Y_),Pe=o=>(...e)=>j_(o,...e),Cs=V(0).setGroup(k).onRenderUpdate(o=>o.time),gf=V(0).setGroup(k).onRenderUpdate(o=>o.deltaTime),Q_=V(0,"uint").setGroup(k).onRenderUpdate(o=>o.frameId),Z_=(o=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Cs.mul(o)),J_=(o=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Cs.mul(o)),eb=(o=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),gf.mul(o)),tb=(o=Cs)=>o.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5),sb=(o=Cs)=>o.fract().round(),nb=(o=Cs)=>o.add(.5).fract().mul(2).sub(1).abs(),rb=(o=Cs)=>o.fract(),ib=b(([o,e,t=M(.5)])=>Au(o.sub(t),e).add(t)),ob=b(([o,e,t=M(.5)])=>{const s=o.sub(t),n=s.dot(s),i=n.mul(n).mul(e);return o.add(s.mul(i))}),ab=b(({position:o=null,horizontal:e=!0,vertical:t=!1})=>{let s;o!==null?(s=at.toVar(),s[3][0]=o.x,s[3][1]=o.y,s[3][2]=o.z):s=at;const n=je.mul(s);return Gn(e)&&(n[0][0]=at[0].length(),n[0][1]=0,n[0][2]=0),Gn(t)&&(n[1][0]=0,n[1][1]=at[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,He.mul(n).mul(me)}),ub=b(([o=null])=>{const e=ei();return ei(gu(o)).sub(e).lessThan(0).select(Bt,o)});class cb extends O{static get type(){return"SpriteSheetUVNode"}constructor(e,t=le(),s=g(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:n,height:r}=s,i=e.mod(n.mul(r)).floor(),a=i.mod(n),u=r.sub(i.add(1).div(n).ceil()),c=s.reciprocal(),l=M(a,u);return t.add(l).mul(c)}}const lb=C(cb);class db extends O{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,n=g(1),r=me,i=Xe){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=n,this.positionNode=r,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:n,positionNode:r,normalNode:i}=this;let a=i.abs().normalize();a=a.div(a.dot(T(1)));const u=r.yz.mul(n),c=r.zx.mul(n),l=r.xy.mul(n),d=e.value,h=t!==null?t.value:d,p=s!==null?s.value:d,f=K(d,u).mul(a.x),m=K(h,c).mul(a.y),x=K(p,l).mul(a.z);return _e(f,m,x)}}const mf=C(db),hb=(...o)=>mf(...o),Fs=new vl,as=new j,Us=new j,Yi=new j,yn=new Ie,Tr=new j(0,0,-1),xt=new Me,xn=new j,_r=new j,Tn=new Me,br=new Ye,si=new Ss,pb=Bt.flipX();si.depthTexture=new vs(1,1);let ji=!1;class Cu extends wt{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||si.texture,pb),this._reflectorBaseNode=e.reflector||new fb(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(this._depthNode===null){if(this._reflectorBaseNode.depth!==!0)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=E(new Cu({defaultTexture:si.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class fb extends O{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new Zg,resolution:n=1,generateMipmaps:r=!1,bounces:i=!0,depth:a=!1}=t;this.textureNode=e,this.target=s,this.resolution=n,this.generateMipmaps=r,this.bounces=i,this.depth=a,this.updateBeforeType=i?W.RENDER:W.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(br),e.setSize(Math.round(br.width*s),Math.round(br.height*s))}setup(e){return this._updateResolution(si,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return t===void 0&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return t===void 0&&(t=new Ss(0,0,{type:pt}),this.generateMipmaps===!0&&(t.texture.minFilter=Jg,t.texture.generateMipmaps=!0),this.depth===!0&&(t.depthTexture=new vs),this.renderTargets.set(e,t)),t}updateBefore(e){if(this.bounces===!1&&ji)return!1;ji=!0;const{scene:t,camera:s,renderer:n,material:r}=e,{target:i}=this,a=this.getVirtualCamera(s),u=this.getRenderTarget(a);if(n.getDrawingBufferSize(br),this._updateResolution(u,n),Us.setFromMatrixPosition(i.matrixWorld),Yi.setFromMatrixPosition(s.matrixWorld),yn.extractRotation(i.matrixWorld),as.set(0,0,1),as.applyMatrix4(yn),xn.subVectors(Us,Yi),xn.dot(as)>0)return;xn.reflect(as).negate(),xn.add(Us),yn.extractRotation(s.matrixWorld),Tr.set(0,0,-1),Tr.applyMatrix4(yn),Tr.add(Yi),_r.subVectors(Us,Tr),_r.reflect(as).negate(),_r.add(Us),a.coordinateSystem=s.coordinateSystem,a.position.copy(xn),a.up.set(0,1,0),a.up.applyMatrix4(yn),a.up.reflect(as),a.lookAt(_r),a.near=s.near,a.far=s.far,a.updateMatrixWorld(),a.projectionMatrix.copy(s.projectionMatrix),Fs.setFromNormalAndCoplanarPoint(as,Us),Fs.applyMatrix4(a.matrixWorldInverse),xt.set(Fs.normal.x,Fs.normal.y,Fs.normal.z,Fs.constant);const c=a.projectionMatrix;Tn.x=(Math.sign(xt.x)+c.elements[8])/c.elements[0],Tn.y=(Math.sign(xt.y)+c.elements[9])/c.elements[5],Tn.z=-1,Tn.w=(1+c.elements[10])/c.elements[14],xt.multiplyScalar(1/xt.dot(Tn));const l=0;c.elements[2]=xt.x,c.elements[6]=xt.y,c.elements[10]=n.coordinateSystem===ln?xt.z-l:xt.z+1-l,c.elements[14]=xt.w,this.textureNode.value=u.texture,this.depth===!0&&(this.textureNode.getDepthNode().value=u.depthTexture),r.visible=!1;const d=n.getRenderTarget(),h=n.getMRT(),p=n.autoClear;n.setMRT(null),n.setRenderTarget(u),n.autoClear=!0,n.render(t,a),n.setMRT(h),n.setRenderTarget(d),n.autoClear=p,r.visible=!0,ji=!1}}const gb=o=>E(new Cu(o)),Qi=new Tl(-1,1,1,-1,0,1);class mb extends Sl{constructor(e=!1){super();const t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new ju([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new ju(t,2))}}const yb=new mb;class Mi extends tn{constructor(e=null){super(yb,e),this.camera=Qi,this.isQuadMesh=!0}async renderAsync(e){return e.renderAsync(this,Qi)}render(e){e.render(this,Qi)}}const xb=new Ye;class Tb extends wt{static get type(){return"RTTNode"}constructor(e,t=null,s=null,n={type:pt}){const r=new Ss(t,s,n);super(r.texture,le()),this.node=e,this.width=t,this.height=s,this.pixelRatio=1,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this._rttNode=null,this._quadMesh=new Mi(new ce),this.updateBeforeType=W.RENDER}get autoSize(){return this.width===null}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;const s=e*this.pixelRatio,n=t*this.pixelRatio;this.renderTarget.setSize(s,n),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(this.textureNeedsUpdate===!1&&this.autoUpdate===!1)return;if(this.textureNeedsUpdate=!1,this.autoSize===!0){this.pixelRatio=e.getPixelRatio();const s=e.getSize(xb);this.setSize(s.width,s.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new wt(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const yf=(o,...e)=>E(new Tb(E(o),...e)),_b=(o,...e)=>o.isTextureNode?o:o.isPassNode?o.getTextureNode():yf(o,...e),ks=b(([o,e,t],s)=>{let n;s.renderer.coordinateSystem===ln?(o=M(o.x,o.y.oneMinus()).mul(2).sub(1),n=P(T(o,e),1)):n=P(T(o.x,o.y.oneMinus(),e).mul(2).sub(1),1);const r=P(t.mul(n));return r.xyz.div(r.w)}),bb=b(([o,e])=>{const t=e.mul(P(o,1)),s=t.xy.div(t.w).mul(.5).add(.5).toVar();return M(s.x,s.y.oneMinus())}),Nb=b(([o,e,t])=>{const s=ns(ge(e)),n=Ae(o.mul(s)).toVar(),r=ge(e,n).toVar(),i=ge(e,n.sub(Ae(2,0))).toVar(),a=ge(e,n.sub(Ae(1,0))).toVar(),u=ge(e,n.add(Ae(1,0))).toVar(),c=ge(e,n.add(Ae(2,0))).toVar(),l=ge(e,n.add(Ae(0,2))).toVar(),d=ge(e,n.add(Ae(0,1))).toVar(),h=ge(e,n.sub(Ae(0,1))).toVar(),p=ge(e,n.sub(Ae(0,2))).toVar(),f=oe(Y(g(2).mul(a).sub(i),r)).toVar(),m=oe(Y(g(2).mul(u).sub(c),r)).toVar(),x=oe(Y(g(2).mul(d).sub(l),r)).toVar(),N=oe(Y(g(2).mul(h).sub(p),r)).toVar(),v=ks(o,r,t).toVar(),w=f.lessThan(m).select(v.sub(ks(o.sub(M(g(1).div(s.x),0)),a,t)),v.negate().add(ks(o.add(M(g(1).div(s.x),0)),u,t))),B=x.lessThan(N).select(v.sub(ks(o.add(M(0,g(1).div(s.y))),d,t)),v.negate().add(ks(o.sub(M(0,g(1).div(s.y))),h,t)));return qt(_i(w,B))});class Sb extends oa{constructor(e,t,s=Float32Array){const n=ArrayBuffer.isView(e)?e:new s(e*t);super(n,t),this.isStorageInstancedBufferAttribute=!0}}class xf extends Ur{constructor(e,t,s=Float32Array){const n=ArrayBuffer.isView(e)?e:new s(e*t);super(n,t),this.isStorageBufferAttribute=!0}}class vb extends Rs{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}setup(e){return e.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const n=e.context.assign;if(e.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&n!==!0&&(this.node.value.isInstancedBufferAttribute||e.shaderStage!=="compute")?s=e.generatePBO(this):s=this.node.build(e):s=super.generate(e),n!==!0){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Ab=C(vb);class Rb extends iu{static get type(){return"StorageBufferNode"}constructor(e,t=null,s=0){t===null&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t=ya(e.itemSize),s=e.count),super(e,t,s),this.isStorageBufferNode=!0,this.access=Ve.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,e.isStorageBufferAttribute!==!0&&e.isStorageInstancedBufferAttribute!==!0&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(this.bufferCount===0){let t=e.globalCache.getData(this.value);return t===void 0&&(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 Ab(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Ve.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=nr(this.value),this._varying=ke(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),n=s.build(e);return e.registerTransform(n,t),n}}const Bi=(o,e=null,t=0)=>E(new Rb(o,e,t)),Cb=(o,e,t)=>(console.warn('THREE.TSL: "storageObject()" is deprecated. Use "storage().setPBO( true )" instead.'),Bi(o,e,t).setPBO(!0)),Eb=(o,e="float")=>{const t=Ta(e),s=xa(e),n=new xf(o,t,s);return Bi(n,e,o)},wb=(o,e="float")=>{const t=Ta(e),s=xa(e),n=new Sb(o,t,s);return Bi(n,e,o)};class Mb extends Uh{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e),s=e.hasGeometryAttribute(t);let n;return s===!0?n=super.generate(e):n=e.generateConst(this.nodeType,new Me(1,1,1,1)),n}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const Bb=o=>E(new Mb(o));class Fb extends O{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Ub=U(Fb),_n=new Wg,Zi=new Ie;class Ke extends O{static get type(){return"SceneNode"}constructor(e=Ke.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=this.scene!==null?this.scene:e.scene;let n;return t===Ke.BACKGROUND_BLURRINESS?n=ne("backgroundBlurriness","float",s):t===Ke.BACKGROUND_INTENSITY?n=ne("backgroundIntensity","float",s):t===Ke.BACKGROUND_ROTATION?n=V("mat4").label("backgroundRotation").setGroup(k).onRenderUpdate(()=>{const r=s.background;return r!==null&&r.isTexture&&r.mapping!==zg?(_n.copy(s.backgroundRotation),_n.x*=-1,_n.y*=-1,_n.z*=-1,Zi.makeRotationFromEuler(_n)):Zi.identity(),Zi}):console.error("THREE.SceneNode: Unknown scope:",t),n}}Ke.BACKGROUND_BLURRINESS="backgroundBlurriness";Ke.BACKGROUND_INTENSITY="backgroundIntensity";Ke.BACKGROUND_ROTATION="backgroundRotation";const Tf=U(Ke,Ke.BACKGROUND_BLURRINESS),sa=U(Ke,Ke.BACKGROUND_INTENSITY),_f=U(Ke,Ke.BACKGROUND_ROTATION);class Pb extends wt{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Ve.WRITE_ONLY}getInputType(){return"storageTexture"}setup(e){super.setup(e);const t=e.getNodeProperties(this);t.storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return this.storeNode!==null?s=this.generateStore(e):s=super.generate(e,t),s}toReadWrite(){return this.setAccess(Ve.READ_WRITE)}toReadOnly(){return this.setAccess(Ve.READ_ONLY)}toWriteOnly(){return this.setAccess(Ve.WRITE_ONLY)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:n}=t,r=super.generate(e,"property"),i=s.build(e,"uvec2"),a=n.build(e,"vec4"),u=e.generateTextureStore(e,r,i,a);e.addLineFlowCode(u,this)}}const bf=C(Pb),Db=(o,e,t)=>{const s=bf(o,e,t);return t!==null&&s.append(),s};class Lb extends Ai{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=this.userData!==null?this.userData:e.object.userData,this.reference}}const Ib=(o,e,t)=>E(new Lb(o,e,t)),Pc=new WeakMap;class Vb extends be{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=W.OBJECT,this.updateAfterType=W.OBJECT,this.previousModelWorldMatrix=V(new Ie),this.previousProjectionMatrix=V(new Ie).setGroup(k),this.previousCameraViewMatrix=V(new Ie)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const n=Dc(s);this.previousModelWorldMatrix.value.copy(n);const r=Nf(t);r.frameId!==e&&(r.frameId=e,r.previousProjectionMatrix===void 0?(r.previousProjectionMatrix=new Ie,r.previousCameraViewMatrix=new Ie,r.currentProjectionMatrix=new Ie,r.currentCameraViewMatrix=new Ie,r.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),r.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(r.previousProjectionMatrix.copy(r.currentProjectionMatrix),r.previousCameraViewMatrix.copy(r.currentCameraViewMatrix)),r.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),r.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(r.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(r.previousCameraViewMatrix))}updateAfter({object:e}){Dc(e).copy(e.matrixWorld)}setup(){const e=this.projectionMatrix===null?He:V(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(Kt).mul(me),n=this.previousProjectionMatrix.mul(t).mul(Jr),r=s.xy.div(s.w),i=n.xy.div(n.w);return Y(r,i)}}function Nf(o){let e=Pc.get(o);return e===void 0&&(e={},Pc.set(o,e)),e}function Dc(o,e=0){const t=Nf(o);let s=t[e];return s===void 0&&(t[e]=s=new Ie),s}const Gb=U(Vb),Sf=b(([o,e])=>Re(1,o.oneMinus().div(e)).oneMinus()).setLayout({name:"blendBurn",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vf=b(([o,e])=>Re(o.div(e.oneMinus()),1)).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Af=b(([o,e])=>o.oneMinus().mul(e.oneMinus()).oneMinus()).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Rf=b(([o,e])=>Q(o.mul(2).mul(e),o.oneMinus().mul(2).mul(e.oneMinus()).oneMinus(),Ti(.5,o))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Ob=b(([o,e])=>{const t=e.a.add(o.a.mul(e.a.oneMinus()));return P(e.rgb.mul(e.a).add(o.rgb.mul(o.a).mul(e.a.oneMinus())).div(t),t)}).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),kb=(...o)=>(console.warn('THREE.TSL: "burn" has been renamed. Use "blendBurn" instead.'),Sf(o)),zb=(...o)=>(console.warn('THREE.TSL: "dodge" has been renamed. Use "blendDodge" instead.'),vf(o)),Wb=(...o)=>(console.warn('THREE.TSL: "screen" has been renamed. Use "blendScreen" instead.'),Af(o)),$b=(...o)=>(console.warn('THREE.TSL: "overlay" has been renamed. Use "blendOverlay" instead.'),Rf(o)),Hb=b(([o])=>Eu(o.rgb)),qb=b(([o,e=g(1)])=>e.mix(Eu(o.rgb),o.rgb)),Kb=b(([o,e=g(1)])=>{const t=_e(o.r,o.g,o.b).div(3),s=o.r.max(o.g.max(o.b)),n=s.sub(t).mul(e).mul(-3);return Q(o.rgb,s,n)}),Xb=b(([o,e=g(1)])=>{const t=T(.57735,.57735,.57735),s=e.cos();return T(o.rgb.mul(s).add(t.cross(o.rgb).mul(e.sin()).add(t.mul(is(t,o.rgb).mul(s.oneMinus())))))}),Eu=(o,e=T(_t.getLuminanceCoefficients(new j)))=>is(o,e),Yb=b(([o,e=T(1),t=T(0),s=T(1),n=g(1),r=T(_t.getLuminanceCoefficients(new j,kt))])=>{const i=o.rgb.dot(T(r)),a=ue(o.rgb.mul(e).add(t),0).toVar(),u=a.pow(s).toVar();return z(a.r.greaterThan(0),()=>{a.r.assign(u.r)}),z(a.g.greaterThan(0),()=>{a.g.assign(u.g)}),z(a.b.greaterThan(0),()=>{a.b.assign(u.b)}),a.assign(i.add(a.sub(i).mul(n))),P(a.rgb,o.a)});class jb extends be{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Qb=C(jb),Zb=new Ye;class Cf extends wt{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 Lc extends Cf{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Ut extends be{static get type(){return"PassNode"}constructor(e,t,s,n={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=n,this._pixelRatio=1,this._width=1,this._height=1;const r=new vs;r.isRenderTargetTexture=!0,r.name="depth";const i=new Ss(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:pt,...n});i.texture.name="output",i.depthTexture=r,this.renderTarget=i,this._textures={output:i.texture,depth:r},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=V(0),this._cameraFar=V(0),this._mrt=null,this.isPassNode=!0,this.updateBeforeType=W.FRAME}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];return t===void 0&&(t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(t!==void 0){const s=this._textures[e],n=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[n]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return t===void 0&&(t=E(new Lc(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=E(new Lc(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){const s=this._cameraNear,n=this._cameraFar;this._viewZNodes[e]=t=mu(this.getTextureNode(e),s,n)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){const s=this._cameraNear,n=this._cameraFar,r=this.getViewZNode(e);this._linearDepthNodes[e]=t=Qs(r,s,n)}return t}setup({renderer:e}){return this.renderTarget.samples=this.options.samples===void 0?e.samples:this.options.samples,e.backend.isWebGLBackend===!0&&(this.renderTarget.samples=0),this.scope===Ut.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:n}=this;this._pixelRatio=t.getPixelRatio();const r=t.getSize(Zb);this.setSize(r.width,r.height);const i=t.getRenderTarget(),a=t.getMRT();this._cameraNear.value=n.near,this._cameraFar.value=n.far;for(const u in this._previousTextures)this.toggleTexture(u);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,n),t.setRenderTarget(i),t.setMRT(a)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,n=this._height*this._pixelRatio;this.renderTarget.setSize(s,n)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Ut.COLOR="color";Ut.DEPTH="depth";const Jb=(o,e,t)=>E(new Ut(Ut.COLOR,o,e,t)),eN=(o,e)=>E(new Cf(o,e)),tN=(o,e,t)=>E(new Ut(Ut.DEPTH,o,e,t));class sN extends Ut{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,n,r){super(Ut.COLOR,e,t),this.colorNode=s,this.thicknessNode=n,this.alphaNode=r,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction((n,r,i,a,u,c,l,d)=>{if((u.isMeshToonMaterial||u.isMeshToonNodeMaterial)&&u.wireframe===!1){const h=this._getOutlineMaterial(u);t.renderObject(n,r,i,a,h,c,l,d)}t.renderObject(n,r,i,a,u,c,l,d)}),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new ce;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=Ct;const t=Xe.negate(),s=He.mul(Kt),n=g(1),r=s.mul(P(me,1)),i=s.mul(P(me.add(t),1)),a=qt(r.sub(i));return e.vertexNode=r.add(a.mul(this.thicknessNode).mul(r.w).mul(n)),e.colorNode=P(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return t===void 0&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const nN=(o,e,t=new mt(0,0,0),s=.003,n=1)=>E(new sN(o,e,E(t),E(s),E(n))),Ef=b(([o,e])=>o.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),wf=b(([o,e])=>(o=o.mul(e),o.div(o.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Mf=b(([o,e])=>{o=o.mul(e),o=o.sub(.004).max(0);const t=o.mul(o.mul(6.2).add(.5)),s=o.mul(o.mul(6.2).add(1.7)).add(.06);return t.div(s).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),rN=b(([o])=>{const e=o.mul(o.add(.0245786)).sub(90537e-9),t=o.mul(o.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),Bf=b(([o,e])=>{const t=Oe(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),s=Oe(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return o=o.mul(e).div(.6),o=t.mul(o),o=rN(o),o=s.mul(o),o.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),iN=Oe(T(1.6605,-.1246,-.0182),T(-.5876,1.1329,-.1006),T(-.0728,-.0083,1.1187)),oN=Oe(T(.6274,.0691,.0164),T(.3293,.9195,.088),T(.0433,.0113,.8956)),aN=b(([o])=>{const e=T(o).toVar(),t=T(e.mul(e)).toVar(),s=T(t.mul(t)).toVar();return g(15.5).mul(s.mul(t)).sub($(40.14,s.mul(e))).add($(31.96,s).sub($(6.868,t.mul(e))).add($(.4298,t).add($(.1191,e).sub(.00232))))}),Ff=b(([o,e])=>{const t=T(o).toVar(),s=Oe(T(.856627153315983,.137318972929847,.11189821299995),T(.0951212405381588,.761241990602591,.0767994186031903),T(.0482516061458583,.101439036467562,.811302368396859)),n=Oe(T(1.1271005818144368,-.1413297634984383,-.14132976349843826),T(-.11060664309660323,1.157823702216272,-.11060664309660294),T(-.016493938717834573,-.016493938717834257,1.2519364065950405)),r=g(-12.47393),i=g(4.026069);return t.mulAssign(e),t.assign(oN.mul(t)),t.assign(s.mul(t)),t.assign(ue(t,1e-10)),t.assign(vt(t)),t.assign(t.sub(r).div(i.sub(r))),t.assign(Et(t,0,1)),t.assign(aN(t)),t.assign(n.mul(t)),t.assign(ht(ue(T(0),t),T(2.2))),t.assign(iN.mul(t)),t.assign(Et(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Uf=b(([o,e])=>{const t=g(.76),s=g(.15);o=o.mul(e);const n=Re(o.r,Re(o.g,o.b)),r=Ue(n.lessThan(.08),n.sub($(6.25,n.mul(n))),.04);o.subAssign(r);const i=ue(o.r,ue(o.g,o.b));z(i.lessThan(t),()=>o);const a=Y(1,t),u=Y(1,a.mul(a).div(i.add(a.sub(t))));o.mulAssign(u.div(i));const c=Y(1,gt(1,s.mul(i.sub(u)).add(1)));return Q(o,T(u),c)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class Ne extends O{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.includes=t,this.language=s}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const n of t)n.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const Fi=C(Ne),uN=(o,e)=>Fi(o,e,"js"),cN=(o,e)=>Fi(o,e,"wgsl"),lN=(o,e)=>Fi(o,e,"glsl");class Pf extends Ne{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return s===void 0&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),n=s.name,r=s.type,i=e.getCodeFromNode(this,r);n!==""&&(i.name=n);const a=e.getPropertyName(i),u=this.getNodeFunction(e).getCode(a);return i.code=u+`
|
|
`,t==="property"?a:e.format(`${a}()`,r,t)}}const Df=(o,e=[],t="")=>{for(let r=0;r<e.length;r++){const i=e[r];typeof i=="function"&&(e[r]=i.functionNode)}const s=E(new Pf(o,e,t)),n=(...r)=>s.call(...r);return n.functionNode=s,n},dN=(o,e)=>Df(o,e,"glsl"),hN=(o,e)=>Df(o,e,"wgsl");class pN extends O{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outputType=null,this.events=new gl,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return this.outputType!==null}set value(e){this._value!==e&&(this._cache&&this.inputType==="URL"&&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(){const e=this.value;if(e&&this._cache===null&&this.inputType==="URL"&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&e.value!==null&&e.value!==void 0&&((this.inputType==="URL"||this.inputType==="String")&&typeof e.value=="string"||this.inputType==="Number"&&typeof e.value=="number"||this.inputType==="Vector2"&&e.value.isVector2||this.inputType==="Vector3"&&e.value.isVector3||this.inputType==="Vector4"&&e.value.isVector4||this.inputType==="Color"&&e.value.isColor||this.inputType==="Matrix3"&&e.value.isMatrix3||this.inputType==="Matrix4"&&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:g()}serialize(e){super.serialize(e),this.value!==null?this.inputType==="ArrayBuffer"?e.value=Na(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;e.value!==null&&(e.inputType==="ArrayBuffer"?t=Sa(e.value):e.inputType==="Texture"?t=e.meta.textures[e.value]:t=e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const zr=C(pN);class Lf extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(t!==null){const n=t(...s);return this.set(e,n),n}}}class fN{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){const t=this.parameters[e];return t?t.getValue():null}}const Wr=new Lf;class gN extends O{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new Lf,this._output=zr(),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}get 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(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return s[e]===void 0?s[e]=zr(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):s[e]===void 0?(s[e]=zr(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[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(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const n=this.getObject()[e];if(typeof n=="function")return n(...t)}async callAsync(e,...t){const n=this.getObject()[e];if(typeof n=="function")return n.constructor.name==="AsyncFunction"?await n(...t):n(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){e!==null?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),this._object!==null)return this._object;const e=()=>this.refresh(),t=(c,l)=>this.setOutput(c,l),s=new fN(this),n=Wr.get("THREE"),r=Wr.get("TSL"),i=this.getMethod(),a=[s,this._local,Wr,e,t,n,r];this._object=i(...a);const u=this._object.layout;if(u&&(u.cache===!1&&this._local.clear(),this._output.outputType=u.outputType||null,Array.isArray(u.elements)))for(const c of u.elements){const l=c.id||c.name;c.inputType&&(this.getParameter(l)===void 0&&this.setParameter(l,null),this.getParameter(l).inputType=c.inputType),c.outputType&&(this.getOutput(l)===void 0&&this.setOutput(l,null),this.getOutput(l).outputType=c.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const t in this.parameters){let s=this.parameters[t];s.isScriptableNode&&(s=s.getDefaultOutput()),s.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:g()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),this._method!==null)return this._method;const e=["parameters","local","global","refresh","setOutput","THREE","TSL"],s=["layout","init","main","dispose"].join(", "),n="var "+s+`; var output = {};
|
|
`,r=`
|
|
return { ...output, `+s+" };",i=n+this.codeNode.code+r;return this._method=new Function(...e,i),this._method}dispose(){this._method!==null&&(this._object&&typeof this._object.dispose=="function"&&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){const t=[ga(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return Zn(t)}set needsUpdate(e){e===!0&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return this.codeNode===null?this:(this._needsOutputUpdate===!0&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value,this)}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const mN=C(gN);function If(o){let e;const t=o.context.getViewZ;return t!==void 0&&(e=t(this)),(e||xe.z).negate()}const wu=b(([o,e],t)=>{const s=If(t);return ct(o,e,s)}),Mu=b(([o],e)=>{const t=If(e);return o.mul(o,t,t).negate().exp().oneMinus()}),Xn=b(([o,e])=>P(e.toFloat().mix($n.rgb,o.toVec3()),$n.a));function yN(o,e,t){return console.warn('THREE.TSL: "rangeFog( color, near, far )" is deprecated. Use "fog( color, rangeFogFactor( near, far ) )" instead.'),Xn(o,wu(e,t))}function xN(o,e){return console.warn('THREE.TSL: "densityFog( color, density )" is deprecated. Use "fog( color, densityFogFactor( density ) )" instead.'),Xn(o,Mu(e))}let us=null,cs=null;class TN extends O{static get type(){return"RangeNode"}constructor(e=g(),t=g()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(Ot(this.minNode.value)),s=e.getTypeLength(Ot(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,r=this.maxNode.value,i=e.getTypeLength(Ot(n)),a=e.getTypeLength(Ot(r));us=us||new Me,cs=cs||new Me,us.setScalar(0),cs.setScalar(0),i===1?us.setScalar(n):n.isColor?us.set(n.r,n.g,n.b,1):us.set(n.x,n.y,n.z||0,n.w||0),a===1?cs.setScalar(r):r.isColor?cs.set(r.r,r.g,r.b,1):cs.set(r.x,r.y,r.z||0,r.w||0);const u=4,c=u*t.count,l=new Float32Array(c);for(let h=0;h<c;h++){const p=h%u,f=us.getComponent(p),m=cs.getComponent(p);l[h]=ml.lerp(f,m,Math.random())}const d=this.getNodeType(e);if(t.count<=4096)s=ir(l,"vec4",t.count).element(lr).convert(d);else{const h=new oa(l,4);e.geometry.setAttribute("__range"+this.id,h),s=Zr(h).convert(d)}}else s=g(0);return s}}const _N=C(TN);class bN extends O{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){e.hasBuiltin(this._builtinName)}generate(e,t){const s=this.getBuiltinName(e),n=this.getNodeType(e);return e.shaderStage==="compute"?e.format(s,n,t):(console.warn(`ComputeBuiltinNode: Compute built-in value ${s} can not be accessed in the ${e.shaderStage} stage`),e.generateConst(n))}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}}const Ui=(o,e)=>E(new bN(o,e)),NN=Ui("numWorkgroups","uvec3"),SN=Ui("workgroupId","uvec3"),vN=Ui("localId","uvec3"),AN=Ui("subgroupSize","uint");class RN extends O{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;s.backend.isWebGLBackend===!0?e.addFlowCode(` // ${t}Barrier
|
|
`):e.addLineFlowCode(`${t}Barrier()`,this)}}const Bu=C(RN),CN=()=>Bu("workgroup").append(),EN=()=>Bu("storage").append(),wN=()=>Bu("texture").append();class MN extends Rs{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const n=e.context.assign;if(s=super.generate(e),n!==!0){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class BN extends O{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,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 MN(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const FN=(o,e)=>E(new BN("Workgroup",o,e));class Be extends be{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,n=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=n}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),n=this.getInputType(e),r=this.pointerNode,i=this.valueNode,a=[];a.push(`&${r.build(e,n)}`),a.push(i.build(e,n));const u=`${e.getMethod(t,s)}( ${a.join(", ")} )`;if(this.storeNode!==null){const c=this.storeNode.build(e,n);e.addLineFlowCode(`${c} = ${u}`,this)}else e.addLineFlowCode(u,this)}}Be.ATOMIC_LOAD="atomicLoad";Be.ATOMIC_STORE="atomicStore";Be.ATOMIC_ADD="atomicAdd";Be.ATOMIC_SUB="atomicSub";Be.ATOMIC_MAX="atomicMax";Be.ATOMIC_MIN="atomicMin";Be.ATOMIC_AND="atomicAnd";Be.ATOMIC_OR="atomicOr";Be.ATOMIC_XOR="atomicXor";const UN=C(Be),Yt=(o,e,t,s=null)=>{const n=UN(o,e,t,s);return n.append(),n},PN=(o,e,t=null)=>Yt(Be.ATOMIC_STORE,o,e,t),DN=(o,e,t=null)=>Yt(Be.ATOMIC_ADD,o,e,t),LN=(o,e,t=null)=>Yt(Be.ATOMIC_SUB,o,e,t),IN=(o,e,t=null)=>Yt(Be.ATOMIC_MAX,o,e,t),VN=(o,e,t=null)=>Yt(Be.ATOMIC_MIN,o,e,t),GN=(o,e,t=null)=>Yt(Be.ATOMIC_AND,o,e,t),ON=(o,e,t=null)=>Yt(Be.ATOMIC_OR,o,e,t),kN=(o,e,t=null)=>Yt(Be.ATOMIC_XOR,o,e,t);let Nr;function hr(o){Nr=Nr||new WeakMap;let e=Nr.get(o);return e===void 0&&Nr.set(o,e={}),e}function Fu(o){const e=hr(o);return e.shadowMatrix||(e.shadowMatrix=V("mat4").setGroup(k).onRenderUpdate(()=>(o.castShadow!==!0&&o.shadow.updateMatrices(o),o.shadow.matrix)))}function Vf(o){const e=hr(o);if(e.projectionUV===void 0){const t=Fu(o).mul(Wt);e.projectionUV=t.xyz.div(t.w)}return e.projectionUV}function Uu(o){const e=hr(o);return e.position||(e.position=V(new j).setGroup(k).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(o.matrixWorld)))}function Gf(o){const e=hr(o);return e.targetPosition||(e.targetPosition=V(new j).setGroup(k).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(o.target.matrixWorld)))}function Pi(o){const e=hr(o);return e.viewPosition||(e.viewPosition=V(new j).setGroup(k).onRenderUpdate(({camera:t},s)=>{s.value=s.value||new j,s.value.setFromMatrixPosition(o.matrixWorld),s.value.applyMatrix4(t.matrixWorldInverse)}))}const Pu=o=>je.transformDirection(Uu(o).sub(Gf(o))),zN=o=>o.sort((e,t)=>e.id-t.id),WN=(o,e)=>{for(const t of e)if(t.isAnalyticLightNode&&t.light.id===o)return t;return null},Ji=new WeakMap;class Du extends O{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=T().toVar("totalDiffuse"),this.totalSpecularNode=T().toVar("totalSpecular"),this.outgoingLightNode=T().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){const e=[],t=this._lights;for(let s=0;s<t.length;s++)e.push(t[s].id);return Zn(e)}getHash(e){if(this._lightNodesHash===null){this._lightNodes===null&&this.setupLightsNode(e);const t=[];for(const s of this._lightNodes)t.push(s.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,n=zN(this._lights),r=e.renderer.library;for(const i of n)if(i.isNode)t.push(E(i));else{let a=null;if(s!==null&&(a=WN(i.id,s)),a===null){const u=r.getLightNodeClass(i.constructor);if(u===null){console.warn(`LightsNode.setupNodeLights: Light node not found for ${i.constructor.name}`);continue}let c=null;Ji.has(i)?c=Ji.get(i):(c=E(new u(i)),Ji.set(i,c)),t.push(c)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){this._lightNodes===null&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let n=this.outgoingLightNode;if(s){const{_lightNodes:r,totalDiffuseNode:i,totalSpecularNode:a}=this;t.outgoingLight=n;const u=e.addStack(),c=e.getDataFromNode(this);c.nodes=u.nodes,s.start(t,u,e),this.setupLights(e,r),s.indirect(t,u,e);const{backdrop:l,backdropAlpha:d}=t,{directDiffuse:h,directSpecular:p,indirectDiffuse:f,indirectSpecular:m}=t.reflectedLight;let x=h.add(f);l!==null&&(d!==null?x=T(d.mix(x,l)):x=T(l),t.material.transparent=!0),i.assign(x),a.assign(p.add(m)),n.assign(i.add(a)),s.finish(t,u,e),n=n.bypass(e.removeStack())}return n}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const $N=(o=[])=>E(new Du).setLights(o);class HN extends O{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=W.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({material:e}){Lu.assign(e.shadowPositionNode||Wt)}dispose(){this.updateBeforeType=W.NONE}}const Lu=T().toVar("shadowPositionWorld");function Iu(o,e={}){return e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure,e.outputColorSpace=o.outputColorSpace,e.renderTarget=o.getRenderTarget(),e.activeCubeFace=o.getActiveCubeFace(),e.activeMipmapLevel=o.getActiveMipmapLevel(),e.renderObjectFunction=o.getRenderObjectFunction(),e.pixelRatio=o.getPixelRatio(),e.mrt=o.getMRT(),e.clearColor=o.getClearColor(e.clearColor||new mt),e.clearAlpha=o.getClearAlpha(),e.autoClear=o.autoClear,e.scissorTest=o.getScissorTest(),e}function Of(o,e){return e=Iu(o,e),o.setMRT(null),o.setRenderObjectFunction(null),o.setClearColor(0,1),o.autoClear=!0,e}function kf(o,e){o.toneMapping=e.toneMapping,o.toneMappingExposure=e.toneMappingExposure,o.outputColorSpace=e.outputColorSpace,o.setRenderTarget(e.renderTarget,e.activeCubeFace,e.activeMipmapLevel),o.setRenderObjectFunction(e.renderObjectFunction),o.setPixelRatio(e.pixelRatio),o.setMRT(e.mrt),o.setClearColor(e.clearColor,e.clearAlpha),o.autoClear=e.autoClear,o.setScissorTest(e.scissorTest)}function Vu(o,e={}){return e.background=o.background,e.backgroundNode=o.backgroundNode,e.overrideMaterial=o.overrideMaterial,e}function zf(o,e){return e=Vu(o,e),o.background=null,o.backgroundNode=null,o.overrideMaterial=null,e}function Wf(o,e){o.background=e.background,o.backgroundNode=e.backgroundNode,o.overrideMaterial=e.overrideMaterial}function qN(o,e,t={}){return t=Iu(o,t),t=Vu(e,t),t}function $f(o,e,t){return t=Of(o,t),t=zf(e,t),t}function Hf(o,e,t){kf(o,t),Wf(e,t)}var gR=Object.freeze({__proto__:null,resetRendererAndSceneState:$f,resetRendererState:Of,resetSceneState:zf,restoreRendererAndSceneState:Hf,restoreRendererState:kf,restoreSceneState:Wf,saveRendererAndSceneState:qN,saveRendererState:Iu,saveSceneState:Vu});const Ic=new WeakMap,KN=b(([o,e,t])=>{let s=Wt.sub(o).length();return s=s.sub(e).div(t.sub(e)),s=s.saturate(),s}),XN=o=>{const e=o.shadow.camera,t=ne("near","float",e).setGroup(k),s=ne("far","float",e).setGroup(k),n=Dh(o);return KN(n,t,s)},YN=o=>{let e=Ic.get(o);if(e===void 0){const t=o.isPointLight?XN(o):null;e=new ce,e.colorNode=P(0,0,0,1),e.depthNode=t,e.isShadowNodeMaterial=!0,e.name="ShadowMaterial",e.fog=!1,Ic.set(o,e)}return e},qf=b(({depthTexture:o,shadowCoord:e})=>K(o,e.xy).compare(e.z)),Kf=b(({depthTexture:o,shadowCoord:e,shadow:t})=>{const s=(m,x)=>K(o,m).compare(x),n=ne("mapSize","vec2",t).setGroup(k),r=ne("radius","float",t).setGroup(k),i=M(1).div(n),a=i.x.negate().mul(r),u=i.y.negate().mul(r),c=i.x.mul(r),l=i.y.mul(r),d=a.div(2),h=u.div(2),p=c.div(2),f=l.div(2);return _e(s(e.xy.add(M(a,u)),e.z),s(e.xy.add(M(0,u)),e.z),s(e.xy.add(M(c,u)),e.z),s(e.xy.add(M(d,h)),e.z),s(e.xy.add(M(0,h)),e.z),s(e.xy.add(M(p,h)),e.z),s(e.xy.add(M(a,0)),e.z),s(e.xy.add(M(d,0)),e.z),s(e.xy,e.z),s(e.xy.add(M(p,0)),e.z),s(e.xy.add(M(c,0)),e.z),s(e.xy.add(M(d,f)),e.z),s(e.xy.add(M(0,f)),e.z),s(e.xy.add(M(p,f)),e.z),s(e.xy.add(M(a,l)),e.z),s(e.xy.add(M(0,l)),e.z),s(e.xy.add(M(c,l)),e.z)).mul(1/17)}),Xf=b(({depthTexture:o,shadowCoord:e,shadow:t})=>{const s=(l,d)=>K(o,l).compare(d),n=ne("mapSize","vec2",t).setGroup(k),r=M(1).div(n),i=r.x,a=r.y,u=e.xy,c=Xt(u.mul(n).add(.5));return u.subAssign(c.mul(r)),_e(s(u,e.z),s(u.add(M(i,0)),e.z),s(u.add(M(0,a)),e.z),s(u.add(r),e.z),Q(s(u.add(M(i.negate(),0)),e.z),s(u.add(M(i.mul(2),0)),e.z),c.x),Q(s(u.add(M(i.negate(),a)),e.z),s(u.add(M(i.mul(2),a)),e.z),c.x),Q(s(u.add(M(0,a.negate())),e.z),s(u.add(M(0,a.mul(2))),e.z),c.y),Q(s(u.add(M(i,a.negate())),e.z),s(u.add(M(i,a.mul(2))),e.z),c.y),Q(Q(s(u.add(M(i.negate(),a.negate())),e.z),s(u.add(M(i.mul(2),a.negate())),e.z),c.x),Q(s(u.add(M(i.negate(),a.mul(2))),e.z),s(u.add(M(i.mul(2),a.mul(2))),e.z),c.x),c.y)).mul(1/9)}),Yf=b(({depthTexture:o,shadowCoord:e})=>{const t=g(1).toVar(),s=K(o).sample(e.xy).rg,n=Ti(e.z,s.x);return z(n.notEqual(g(1)),()=>{const r=e.z.sub(s.x),i=ue(0,s.y.mul(s.y));let a=i.div(i.add(r.mul(r)));a=Et(Y(a,.3).div(.95-.3)),t.assign(Et(ue(n,a)))}),t}),jN=b(({samples:o,radius:e,size:t,shadowPass:s})=>{const n=g(0).toVar(),r=g(0).toVar(),i=o.lessThanEqual(g(1)).select(g(0),g(2).div(o.sub(1))),a=o.lessThanEqual(g(1)).select(g(0),g(-1));te({start:y(0),end:y(o),type:"int",condition:"<"},({i:c})=>{const l=a.add(g(c).mul(i)),d=s.sample(_e(dr.xy,M(0,l).mul(e)).div(t)).x;n.addAssign(d),r.addAssign(d.mul(d))}),n.divAssign(o),r.divAssign(o);const u=Pt(r.sub(n.mul(n)));return M(n,u)}),QN=b(({samples:o,radius:e,size:t,shadowPass:s})=>{const n=g(0).toVar(),r=g(0).toVar(),i=o.lessThanEqual(g(1)).select(g(0),g(2).div(o.sub(1))),a=o.lessThanEqual(g(1)).select(g(0),g(-1));te({start:y(0),end:y(o),type:"int",condition:"<"},({i:c})=>{const l=a.add(g(c).mul(i)),d=s.sample(_e(dr.xy,M(l,0).mul(e)).div(t));n.addAssign(d.x),r.addAssign(_e(d.y.mul(d.y),d.x.mul(d.x)))}),n.divAssign(o),r.divAssign(o);const u=Pt(r.sub(n.mul(n)));return M(n,u)}),ZN=[qf,Kf,Xf,Yf];let eo;const Sr=new Mi;class jf extends HN{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.isShadowNode=!0}setupShadowFilter(e,{filterFn:t,depthTexture:s,shadowCoord:n,shadow:r}){const i=n.x.greaterThanEqual(0).and(n.x.lessThanEqual(1)).and(n.y.greaterThanEqual(0)).and(n.y.lessThanEqual(1)).and(n.z.lessThanEqual(1)),a=t({depthTexture:s,shadowCoord:n,shadow:r});return i.select(a,g(1))}setupShadowCoord(e,t){const{shadow:s}=this,{renderer:n}=e,r=ne("bias","float",s).setGroup(k);let i=t,a;if(s.camera.isOrthographicCamera||n.logarithmicDepthBuffer!==!0)i=i.xyz.div(i.w),a=i.z,n.coordinateSystem===ln&&(a=a.mul(2).sub(1));else{const u=i.w;i=i.xy.div(u);const c=ne("near","float",s.camera).setGroup(k),l=ne("far","float",s.camera).setGroup(k);a=yu(u.negate(),c,l)}return i=T(i.x,i.y.oneMinus(),a.add(r)),i}getShadowFilterFn(e){return ZN[e]}setupShadow(e){const{renderer:t}=e,{light:s,shadow:n}=this,r=t.shadowMap.type,i=new vs(n.mapSize.width,n.mapSize.height);i.compareFunction=ua;const a=e.createRenderTarget(n.mapSize.width,n.mapSize.height);if(a.depthTexture=i,n.camera.updateProjectionMatrix(),r===fr){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Ln,type:pt}),this.vsmShadowMapHorizontal=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Ln,type:pt});const N=K(i),v=K(this.vsmShadowMapVertical.texture),w=ne("blurSamples","float",n).setGroup(k),B=ne("radius","float",n).setGroup(k),F=ne("mapSize","vec2",n).setGroup(k);let L=this.vsmMaterialVertical||(this.vsmMaterialVertical=new ce);L.fragmentNode=jN({samples:w,radius:B,size:F,shadowPass:N}).context(e.getSharedContext()),L.name="VSMVertical",L=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new ce),L.fragmentNode=QN({samples:w,radius:B,size:F,shadowPass:v}).context(e.getSharedContext()),L.name="VSMHorizontal"}const u=ne("intensity","float",n).setGroup(k),c=ne("normalBias","float",n).setGroup(k),l=Fu(s).mul(Lu.add(vi.mul(c))),d=this.setupShadowCoord(e,l),h=n.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(h===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const p=r===fr?this.vsmShadowMapHorizontal.texture:i,f=this.setupShadowFilter(e,{filterFn:h,shadowTexture:a.texture,depthTexture:p,shadowCoord:d,shadow:n}),m=K(a.texture,d),x=Q(1,f.rgb.mix(m,1),u.mul(m.a)).toVar();return this.shadowMap=a,this.shadow.map=a,x}setup(e){if(e.renderer.shadowMap.enabled!==!1)return b(()=>{let t=this._node;return this.setupShadowPosition(e),t===null&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t})()}renderShadow(e){const{shadow:t,shadowMap:s,light:n}=this,{renderer:r,scene:i}=e;t.updateMatrices(n),s.setSize(t.mapSize.width,t.mapSize.height),r.render(i,t.camera)}updateShadow(e){const{shadowMap:t,light:s,shadow:n}=this,{renderer:r,scene:i,camera:a}=e,u=r.shadowMap.type,c=t.depthTexture.version;this._depthVersionCached=c,n.camera.layers.mask=a.layers.mask;const l=r.getRenderObjectFunction(),d=r.getMRT(),h=d?d.has("velocity"):!1;eo=$f(r,i,eo),i.overrideMaterial=YN(s),r.setRenderObjectFunction((p,f,m,x,N,v,...w)=>{(p.castShadow===!0||p.receiveShadow&&u===fr)&&(h&&(ba(p).useVelocity=!0),p.onBeforeShadow(r,p,a,n.camera,x,f.overrideMaterial,v),r.renderObject(p,f,m,x,N,v,...w),p.onAfterShadow(r,p,a,n.camera,x,f.overrideMaterial,v))}),r.setRenderTarget(t),this.renderShadow(e),r.setRenderObjectFunction(l),s.isPointLight!==!0&&u===fr&&this.vsmPass(r),Hf(r,i,eo)}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),Sr.material=this.vsmMaterialVertical,Sr.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),Sr.material=this.vsmMaterialHorizontal,Sr.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),super.dispose()}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const Qf=(o,e)=>E(new jf(o,e));class Es extends hn{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new mt,this.colorNode=e&&e.colorNode||V(this.color).setGroup(k),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=W.FRAME}customCacheKey(){return di(this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadowNode(){return Qf(this.light)}setupShadow(e){const{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let s=this.shadowColorNode;if(s===null){const n=this.light.shadow.shadowNode;let r;n!==void 0?r=E(n):r=this.setupShadowNode(e),this.shadowNode=r,this.shadowColorNode=s=this.colorNode.mul(r),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null)}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const Gu=b(o=>{const{lightDistance:e,cutoffDistance:t,decayExponent:s}=o,n=e.pow(s).max(.01).reciprocal();return t.greaterThan(0).select(n.mul(e.div(t).pow4().oneMinus().clamp().pow2()),n)}),JN=new mt,Tt=b(([o,e])=>{const t=o.toVar(),s=oe(t),n=gt(1,ue(s.x,ue(s.y,s.z)));s.mulAssign(n),t.mulAssign(n.mul(e.mul(2).oneMinus()));const r=M(t.xy).toVar(),a=e.mul(1.5).oneMinus();return z(s.z.greaterThanEqual(a),()=>{z(t.z.greaterThan(0),()=>{r.x.assign(Y(4,t.x))})}).ElseIf(s.x.greaterThanEqual(a),()=>{const u=qn(t.x);r.x.assign(t.z.mul(u).add(u.mul(2)))}).ElseIf(s.y.greaterThanEqual(a),()=>{const u=qn(t.y);r.x.assign(t.x.add(u.mul(2)).add(2)),r.y.assign(t.z.mul(u).sub(2))}),M(.125,.25).mul(r).add(M(.375,.75)).flipY()}).setLayout({name:"cubeToUV",type:"vec2",inputs:[{name:"pos",type:"vec3"},{name:"texelSizeY",type:"float"}]}),eS=b(({depthTexture:o,bd3D:e,dp:t,texelSize:s})=>K(o,Tt(e,s.y)).compare(t)),tS=b(({depthTexture:o,bd3D:e,dp:t,texelSize:s,shadow:n})=>{const r=ne("radius","float",n).setGroup(k),i=M(-1,1).mul(r).mul(s.y);return K(o,Tt(e.add(i.xyy),s.y)).compare(t).add(K(o,Tt(e.add(i.yyy),s.y)).compare(t)).add(K(o,Tt(e.add(i.xyx),s.y)).compare(t)).add(K(o,Tt(e.add(i.yyx),s.y)).compare(t)).add(K(o,Tt(e,s.y)).compare(t)).add(K(o,Tt(e.add(i.xxy),s.y)).compare(t)).add(K(o,Tt(e.add(i.yxy),s.y)).compare(t)).add(K(o,Tt(e.add(i.xxx),s.y)).compare(t)).add(K(o,Tt(e.add(i.yxx),s.y)).compare(t)).mul(1/9)}),sS=b(({filterFn:o,depthTexture:e,shadowCoord:t,shadow:s})=>{const n=t.xyz.toVar(),r=n.length(),i=V("float").setGroup(k).onRenderUpdate(()=>s.camera.near),a=V("float").setGroup(k).onRenderUpdate(()=>s.camera.far),u=ne("bias","float",s).setGroup(k),c=V(s.mapSize).setGroup(k),l=g(1).toVar();return z(r.sub(a).lessThanEqual(0).and(r.sub(i).greaterThanEqual(0)),()=>{const d=r.sub(i).div(a.sub(i)).toVar();d.addAssign(u);const h=n.normalize(),p=M(1).div(c.mul(M(4,2)));l.assign(o({depthTexture:e,bd3D:h,dp:d,texelSize:p,shadow:s}))}),l}),Vc=new Me,Ps=new Ye,bn=new Ye;class nS extends jf{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===gm?eS:tS}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,shadowTexture:s,depthTexture:n,shadowCoord:r,shadow:i}){return sS({filterFn:t,shadowTexture:s,depthTexture:n,shadowCoord:r,shadow:i})}renderShadow(e){const{shadow:t,shadowMap:s,light:n}=this,{renderer:r,scene:i}=e,a=t.getFrameExtents();bn.copy(t.mapSize),bn.multiply(a),s.setSize(bn.width,bn.height),Ps.copy(t.mapSize);const u=r.autoClear,c=r.getClearColor(JN),l=r.getClearAlpha();r.autoClear=!1,r.setClearColor(t.clearColor,t.clearAlpha),r.clear();const d=t.getViewportCount();for(let h=0;h<d;h++){const p=t.getViewport(h),f=Ps.x*p.x,m=bn.y-Ps.y-Ps.y*p.y;Vc.set(f,m,Ps.x*p.z,Ps.y*p.w),s.viewport.copy(Vc),t.updateMatrices(n,h),r.render(i,t.camera)}r.autoClear=u,r.setClearColor(c,l)}}const rS=(o,e)=>E(new nS(o,e)),Zf=b(({color:o,lightViewPosition:e,cutoffDistance:t,decayExponent:s},n)=>{const r=n.context.lightingModel,i=e.sub(xe),a=i.normalize(),u=i.length(),c=Gu({lightDistance:u,cutoffDistance:t,decayExponent:s}),l=o.mul(c),d=n.context.reflectedLight;r.direct({lightDirection:a,lightColor:l,reflectedLight:d},n.stack,n)});class iS extends Es{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=V(0).setGroup(k),this.decayExponentNode=V(2).setGroup(k)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return rS(this.light)}setup(e){super.setup(e),Zf({color:this.colorNode,lightViewPosition:Pi(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const oS=b(([o=le()])=>{const e=o.mul(2),t=e.x.floor(),s=e.y.floor();return t.add(s).mod(2).sign()}),Un=b(([o,e,t])=>{const s=g(t).toVar(),n=g(e).toVar(),r=Ht(o).toVar();return Ue(r,n,s)}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),ni=b(([o,e])=>{const t=Ht(e).toVar(),s=g(o).toVar();return Ue(t,s.negate(),s)}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),Te=b(([o])=>{const e=g(o).toVar();return y(At(e))}).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),he=b(([o,e])=>{const t=g(o).toVar();return e.assign(Te(t)),t.sub(g(e))}),aS=b(([o,e,t,s,n,r])=>{const i=g(r).toVar(),a=g(n).toVar(),u=g(s).toVar(),c=g(t).toVar(),l=g(e).toVar(),d=g(o).toVar(),h=g(Y(1,a)).toVar();return Y(1,i).mul(d.mul(h).add(l.mul(a))).add(i.mul(c.mul(h).add(u.mul(a))))}).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"}]}),uS=b(([o,e,t,s,n,r])=>{const i=g(r).toVar(),a=g(n).toVar(),u=T(s).toVar(),c=T(t).toVar(),l=T(e).toVar(),d=T(o).toVar(),h=g(Y(1,a)).toVar();return Y(1,i).mul(d.mul(h).add(l.mul(a))).add(i.mul(c.mul(h).add(u.mul(a))))}).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"}]}),Jf=Pe([aS,uS]),cS=b(([o,e,t,s,n,r,i,a,u,c,l])=>{const d=g(l).toVar(),h=g(c).toVar(),p=g(u).toVar(),f=g(a).toVar(),m=g(i).toVar(),x=g(r).toVar(),N=g(n).toVar(),v=g(s).toVar(),w=g(t).toVar(),B=g(e).toVar(),F=g(o).toVar(),L=g(Y(1,p)).toVar(),I=g(Y(1,h)).toVar();return g(Y(1,d)).toVar().mul(I.mul(F.mul(L).add(B.mul(p))).add(h.mul(w.mul(L).add(v.mul(p))))).add(d.mul(I.mul(N.mul(L).add(x.mul(p))).add(h.mul(m.mul(L).add(f.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"}]}),lS=b(([o,e,t,s,n,r,i,a,u,c,l])=>{const d=g(l).toVar(),h=g(c).toVar(),p=g(u).toVar(),f=T(a).toVar(),m=T(i).toVar(),x=T(r).toVar(),N=T(n).toVar(),v=T(s).toVar(),w=T(t).toVar(),B=T(e).toVar(),F=T(o).toVar(),L=g(Y(1,p)).toVar(),I=g(Y(1,h)).toVar();return g(Y(1,d)).toVar().mul(I.mul(F.mul(L).add(B.mul(p))).add(h.mul(w.mul(L).add(v.mul(p))))).add(d.mul(I.mul(N.mul(L).add(x.mul(p))).add(h.mul(m.mul(L).add(f.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"}]}),eg=Pe([cS,lS]),dS=b(([o,e,t])=>{const s=g(t).toVar(),n=g(e).toVar(),r=D(o).toVar(),i=D(r.bitAnd(D(7))).toVar(),a=g(Un(i.lessThan(D(4)),n,s)).toVar(),u=g($(2,Un(i.lessThan(D(4)),s,n))).toVar();return ni(a,Ht(i.bitAnd(D(1)))).add(ni(u,Ht(i.bitAnd(D(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),hS=b(([o,e,t,s])=>{const n=g(s).toVar(),r=g(t).toVar(),i=g(e).toVar(),a=D(o).toVar(),u=D(a.bitAnd(D(15))).toVar(),c=g(Un(u.lessThan(D(8)),i,r)).toVar(),l=g(Un(u.lessThan(D(4)),r,Un(u.equal(D(12)).or(u.equal(D(14))),i,n))).toVar();return ni(c,Ht(u.bitAnd(D(1)))).add(ni(l,Ht(u.bitAnd(D(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"}]}),Ee=Pe([dS,hS]),pS=b(([o,e,t])=>{const s=g(t).toVar(),n=g(e).toVar(),r=dn(o).toVar();return T(Ee(r.x,n,s),Ee(r.y,n,s),Ee(r.z,n,s))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),fS=b(([o,e,t,s])=>{const n=g(s).toVar(),r=g(t).toVar(),i=g(e).toVar(),a=dn(o).toVar();return T(Ee(a.x,i,r,n),Ee(a.y,i,r,n),Ee(a.z,i,r,n))}).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"}]}),nt=Pe([pS,fS]),gS=b(([o])=>{const e=g(o).toVar();return $(.6616,e)}).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),mS=b(([o])=>{const e=g(o).toVar();return $(.982,e)}).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),yS=b(([o])=>{const e=T(o).toVar();return $(.6616,e)}).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),tg=Pe([gS,yS]),xS=b(([o])=>{const e=T(o).toVar();return $(.982,e)}).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),sg=Pe([mS,xS]),tt=b(([o,e])=>{const t=y(e).toVar(),s=D(o).toVar();return s.shiftLeft(t).bitOr(s.shiftRight(y(32).sub(t)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),ng=b(([o,e,t])=>{o.subAssign(t),o.bitXorAssign(tt(t,y(4))),t.addAssign(e),e.subAssign(o),e.bitXorAssign(tt(o,y(6))),o.addAssign(t),t.subAssign(e),t.bitXorAssign(tt(e,y(8))),e.addAssign(o),o.subAssign(t),o.bitXorAssign(tt(t,y(16))),t.addAssign(e),e.subAssign(o),e.bitXorAssign(tt(o,y(19))),o.addAssign(t),t.subAssign(e),t.bitXorAssign(tt(e,y(4))),e.addAssign(o)}),pr=b(([o,e,t])=>{const s=D(t).toVar(),n=D(e).toVar(),r=D(o).toVar();return s.bitXorAssign(n),s.subAssign(tt(n,y(14))),r.bitXorAssign(s),r.subAssign(tt(s,y(11))),n.bitXorAssign(r),n.subAssign(tt(r,y(25))),s.bitXorAssign(n),s.subAssign(tt(n,y(16))),r.bitXorAssign(s),r.subAssign(tt(s,y(4))),n.bitXorAssign(r),n.subAssign(tt(r,y(14))),s.bitXorAssign(n),s.subAssign(tt(n,y(24))),s}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),Ge=b(([o])=>{const e=D(o).toVar();return g(e).div(g(D(y(4294967295))))}).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),Rt=b(([o])=>{const e=g(o).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),TS=b(([o])=>{const e=y(o).toVar(),t=D(D(1)).toVar(),s=D(D(y(3735928559)).add(t.shiftLeft(D(2))).add(D(13))).toVar();return pr(s.add(D(e)),s,s)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),_S=b(([o,e])=>{const t=y(e).toVar(),s=y(o).toVar(),n=D(D(2)).toVar(),r=D().toVar(),i=D().toVar(),a=D().toVar();return r.assign(i.assign(a.assign(D(y(3735928559)).add(n.shiftLeft(D(2))).add(D(13))))),r.addAssign(D(s)),i.addAssign(D(t)),pr(r,i,a)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),bS=b(([o,e,t])=>{const s=y(t).toVar(),n=y(e).toVar(),r=y(o).toVar(),i=D(D(3)).toVar(),a=D().toVar(),u=D().toVar(),c=D().toVar();return a.assign(u.assign(c.assign(D(y(3735928559)).add(i.shiftLeft(D(2))).add(D(13))))),a.addAssign(D(r)),u.addAssign(D(n)),c.addAssign(D(s)),pr(a,u,c)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),NS=b(([o,e,t,s])=>{const n=y(s).toVar(),r=y(t).toVar(),i=y(e).toVar(),a=y(o).toVar(),u=D(D(4)).toVar(),c=D().toVar(),l=D().toVar(),d=D().toVar();return c.assign(l.assign(d.assign(D(y(3735928559)).add(u.shiftLeft(D(2))).add(D(13))))),c.addAssign(D(a)),l.addAssign(D(i)),d.addAssign(D(r)),ng(c,l,d),c.addAssign(D(n)),pr(c,l,d)}).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"}]}),SS=b(([o,e,t,s,n])=>{const r=y(n).toVar(),i=y(s).toVar(),a=y(t).toVar(),u=y(e).toVar(),c=y(o).toVar(),l=D(D(5)).toVar(),d=D().toVar(),h=D().toVar(),p=D().toVar();return d.assign(h.assign(p.assign(D(y(3735928559)).add(l.shiftLeft(D(2))).add(D(13))))),d.addAssign(D(c)),h.addAssign(D(u)),p.addAssign(D(a)),ng(d,h,p),d.addAssign(D(i)),h.addAssign(D(r)),pr(d,h,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"}]}),re=Pe([TS,_S,bS,NS,SS]),vS=b(([o,e])=>{const t=y(e).toVar(),s=y(o).toVar(),n=D(re(s,t)).toVar(),r=dn().toVar();return r.x.assign(n.bitAnd(y(255))),r.y.assign(n.shiftRight(y(8)).bitAnd(y(255))),r.z.assign(n.shiftRight(y(16)).bitAnd(y(255))),r}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),AS=b(([o,e,t])=>{const s=y(t).toVar(),n=y(e).toVar(),r=y(o).toVar(),i=D(re(r,n,s)).toVar(),a=dn().toVar();return a.x.assign(i.bitAnd(y(255))),a.y.assign(i.shiftRight(y(8)).bitAnd(y(255))),a.z.assign(i.shiftRight(y(16)).bitAnd(y(255))),a}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),rt=Pe([vS,AS]),RS=b(([o])=>{const e=M(o).toVar(),t=y().toVar(),s=y().toVar(),n=g(he(e.x,t)).toVar(),r=g(he(e.y,s)).toVar(),i=g(Rt(n)).toVar(),a=g(Rt(r)).toVar(),u=g(Jf(Ee(re(t,s),n,r),Ee(re(t.add(y(1)),s),n.sub(1),r),Ee(re(t,s.add(y(1))),n,r.sub(1)),Ee(re(t.add(y(1)),s.add(y(1))),n.sub(1),r.sub(1)),i,a)).toVar();return tg(u)}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),CS=b(([o])=>{const e=T(o).toVar(),t=y().toVar(),s=y().toVar(),n=y().toVar(),r=g(he(e.x,t)).toVar(),i=g(he(e.y,s)).toVar(),a=g(he(e.z,n)).toVar(),u=g(Rt(r)).toVar(),c=g(Rt(i)).toVar(),l=g(Rt(a)).toVar(),d=g(eg(Ee(re(t,s,n),r,i,a),Ee(re(t.add(y(1)),s,n),r.sub(1),i,a),Ee(re(t,s.add(y(1)),n),r,i.sub(1),a),Ee(re(t.add(y(1)),s.add(y(1)),n),r.sub(1),i.sub(1),a),Ee(re(t,s,n.add(y(1))),r,i,a.sub(1)),Ee(re(t.add(y(1)),s,n.add(y(1))),r.sub(1),i,a.sub(1)),Ee(re(t,s.add(y(1)),n.add(y(1))),r,i.sub(1),a.sub(1)),Ee(re(t.add(y(1)),s.add(y(1)),n.add(y(1))),r.sub(1),i.sub(1),a.sub(1)),u,c,l)).toVar();return sg(d)}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]}),Ou=Pe([RS,CS]),ES=b(([o])=>{const e=M(o).toVar(),t=y().toVar(),s=y().toVar(),n=g(he(e.x,t)).toVar(),r=g(he(e.y,s)).toVar(),i=g(Rt(n)).toVar(),a=g(Rt(r)).toVar(),u=T(Jf(nt(rt(t,s),n,r),nt(rt(t.add(y(1)),s),n.sub(1),r),nt(rt(t,s.add(y(1))),n,r.sub(1)),nt(rt(t.add(y(1)),s.add(y(1))),n.sub(1),r.sub(1)),i,a)).toVar();return tg(u)}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),wS=b(([o])=>{const e=T(o).toVar(),t=y().toVar(),s=y().toVar(),n=y().toVar(),r=g(he(e.x,t)).toVar(),i=g(he(e.y,s)).toVar(),a=g(he(e.z,n)).toVar(),u=g(Rt(r)).toVar(),c=g(Rt(i)).toVar(),l=g(Rt(a)).toVar(),d=T(eg(nt(rt(t,s,n),r,i,a),nt(rt(t.add(y(1)),s,n),r.sub(1),i,a),nt(rt(t,s.add(y(1)),n),r,i.sub(1),a),nt(rt(t.add(y(1)),s.add(y(1)),n),r.sub(1),i.sub(1),a),nt(rt(t,s,n.add(y(1))),r,i,a.sub(1)),nt(rt(t.add(y(1)),s,n.add(y(1))),r.sub(1),i,a.sub(1)),nt(rt(t,s.add(y(1)),n.add(y(1))),r,i.sub(1),a.sub(1)),nt(rt(t.add(y(1)),s.add(y(1)),n.add(y(1))),r.sub(1),i.sub(1),a.sub(1)),u,c,l)).toVar();return sg(d)}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),ku=Pe([ES,wS]),MS=b(([o])=>{const e=g(o).toVar(),t=y(Te(e)).toVar();return Ge(re(t))}).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),BS=b(([o])=>{const e=M(o).toVar(),t=y(Te(e.x)).toVar(),s=y(Te(e.y)).toVar();return Ge(re(t,s))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),FS=b(([o])=>{const e=T(o).toVar(),t=y(Te(e.x)).toVar(),s=y(Te(e.y)).toVar(),n=y(Te(e.z)).toVar();return Ge(re(t,s,n))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),US=b(([o])=>{const e=P(o).toVar(),t=y(Te(e.x)).toVar(),s=y(Te(e.y)).toVar(),n=y(Te(e.z)).toVar(),r=y(Te(e.w)).toVar();return Ge(re(t,s,n,r))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]}),PS=Pe([MS,BS,FS,US]),DS=b(([o])=>{const e=g(o).toVar(),t=y(Te(e)).toVar();return T(Ge(re(t,y(0))),Ge(re(t,y(1))),Ge(re(t,y(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),LS=b(([o])=>{const e=M(o).toVar(),t=y(Te(e.x)).toVar(),s=y(Te(e.y)).toVar();return T(Ge(re(t,s,y(0))),Ge(re(t,s,y(1))),Ge(re(t,s,y(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),IS=b(([o])=>{const e=T(o).toVar(),t=y(Te(e.x)).toVar(),s=y(Te(e.y)).toVar(),n=y(Te(e.z)).toVar();return T(Ge(re(t,s,n,y(0))),Ge(re(t,s,n,y(1))),Ge(re(t,s,n,y(2))))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),VS=b(([o])=>{const e=P(o).toVar(),t=y(Te(e.x)).toVar(),s=y(Te(e.y)).toVar(),n=y(Te(e.z)).toVar(),r=y(Te(e.w)).toVar();return T(Ge(re(t,s,n,r,y(0))),Ge(re(t,s,n,r,y(1))),Ge(re(t,s,n,r,y(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]}),rg=Pe([DS,LS,IS,VS]),ri=b(([o,e,t,s])=>{const n=g(s).toVar(),r=g(t).toVar(),i=y(e).toVar(),a=T(o).toVar(),u=g(0).toVar(),c=g(1).toVar();return te(i,()=>{u.addAssign(c.mul(Ou(a))),c.mulAssign(n),a.mulAssign(r)}),u}).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"}]}),ig=b(([o,e,t,s])=>{const n=g(s).toVar(),r=g(t).toVar(),i=y(e).toVar(),a=T(o).toVar(),u=T(0).toVar(),c=g(1).toVar();return te(i,()=>{u.addAssign(c.mul(ku(a))),c.mulAssign(n),a.mulAssign(r)}),u}).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"}]}),GS=b(([o,e,t,s])=>{const n=g(s).toVar(),r=g(t).toVar(),i=y(e).toVar(),a=T(o).toVar();return M(ri(a,i,r,n),ri(a.add(T(y(19),y(193),y(17))),i,r,n))}).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"}]}),OS=b(([o,e,t,s])=>{const n=g(s).toVar(),r=g(t).toVar(),i=y(e).toVar(),a=T(o).toVar(),u=T(ig(a,i,r,n)).toVar(),c=g(ri(a.add(T(y(19),y(193),y(17))),i,r,n)).toVar();return P(u,c)}).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"}]}),kS=b(([o,e,t,s,n,r,i])=>{const a=y(i).toVar(),u=g(r).toVar(),c=y(n).toVar(),l=y(s).toVar(),d=y(t).toVar(),h=y(e).toVar(),p=M(o).toVar(),f=T(rg(M(h.add(l),d.add(c)))).toVar(),m=M(f.x,f.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const x=M(M(g(h),g(d)).add(m)).toVar(),N=M(x.sub(p)).toVar();return z(a.equal(y(2)),()=>oe(N.x).add(oe(N.y))),z(a.equal(y(3)),()=>ue(oe(N.x),oe(N.y))),is(N,N)}).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"}]}),zS=b(([o,e,t,s,n,r,i,a,u])=>{const c=y(u).toVar(),l=g(a).toVar(),d=y(i).toVar(),h=y(r).toVar(),p=y(n).toVar(),f=y(s).toVar(),m=y(t).toVar(),x=y(e).toVar(),N=T(o).toVar(),v=T(rg(T(x.add(p),m.add(h),f.add(d)))).toVar();v.subAssign(.5),v.mulAssign(l),v.addAssign(.5);const w=T(T(g(x),g(m),g(f)).add(v)).toVar(),B=T(w.sub(N)).toVar();return z(c.equal(y(2)),()=>oe(B.x).add(oe(B.y)).add(oe(B.z))),z(c.equal(y(3)),()=>ue(ue(oe(B.x),oe(B.y)),oe(B.z))),is(B,B)}).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"}]}),pn=Pe([kS,zS]),WS=b(([o,e,t])=>{const s=y(t).toVar(),n=g(e).toVar(),r=M(o).toVar(),i=y().toVar(),a=y().toVar(),u=M(he(r.x,i),he(r.y,a)).toVar(),c=g(1e6).toVar();return te({start:-1,end:y(1),name:"x",condition:"<="},({x:l})=>{te({start:-1,end:y(1),name:"y",condition:"<="},({y:d})=>{const h=g(pn(u,l,d,i,a,n,s)).toVar();c.assign(Re(c,h))})}),z(s.equal(y(0)),()=>{c.assign(Pt(c))}),c}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),$S=b(([o,e,t])=>{const s=y(t).toVar(),n=g(e).toVar(),r=M(o).toVar(),i=y().toVar(),a=y().toVar(),u=M(he(r.x,i),he(r.y,a)).toVar(),c=M(1e6,1e6).toVar();return te({start:-1,end:y(1),name:"x",condition:"<="},({x:l})=>{te({start:-1,end:y(1),name:"y",condition:"<="},({y:d})=>{const h=g(pn(u,l,d,i,a,n,s)).toVar();z(h.lessThan(c.x),()=>{c.y.assign(c.x),c.x.assign(h)}).ElseIf(h.lessThan(c.y),()=>{c.y.assign(h)})})}),z(s.equal(y(0)),()=>{c.assign(Pt(c))}),c}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),HS=b(([o,e,t])=>{const s=y(t).toVar(),n=g(e).toVar(),r=M(o).toVar(),i=y().toVar(),a=y().toVar(),u=M(he(r.x,i),he(r.y,a)).toVar(),c=T(1e6,1e6,1e6).toVar();return te({start:-1,end:y(1),name:"x",condition:"<="},({x:l})=>{te({start:-1,end:y(1),name:"y",condition:"<="},({y:d})=>{const h=g(pn(u,l,d,i,a,n,s)).toVar();z(h.lessThan(c.x),()=>{c.z.assign(c.y),c.y.assign(c.x),c.x.assign(h)}).ElseIf(h.lessThan(c.y),()=>{c.z.assign(c.y),c.y.assign(h)}).ElseIf(h.lessThan(c.z),()=>{c.z.assign(h)})})}),z(s.equal(y(0)),()=>{c.assign(Pt(c))}),c}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),qS=b(([o,e,t])=>{const s=y(t).toVar(),n=g(e).toVar(),r=T(o).toVar(),i=y().toVar(),a=y().toVar(),u=y().toVar(),c=T(he(r.x,i),he(r.y,a),he(r.z,u)).toVar(),l=g(1e6).toVar();return te({start:-1,end:y(1),name:"x",condition:"<="},({x:d})=>{te({start:-1,end:y(1),name:"y",condition:"<="},({y:h})=>{te({start:-1,end:y(1),name:"z",condition:"<="},({z:p})=>{const f=g(pn(c,d,h,p,i,a,u,n,s)).toVar();l.assign(Re(l,f))})})}),z(s.equal(y(0)),()=>{l.assign(Pt(l))}),l}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),KS=Pe([WS,qS]),XS=b(([o,e,t])=>{const s=y(t).toVar(),n=g(e).toVar(),r=T(o).toVar(),i=y().toVar(),a=y().toVar(),u=y().toVar(),c=T(he(r.x,i),he(r.y,a),he(r.z,u)).toVar(),l=M(1e6,1e6).toVar();return te({start:-1,end:y(1),name:"x",condition:"<="},({x:d})=>{te({start:-1,end:y(1),name:"y",condition:"<="},({y:h})=>{te({start:-1,end:y(1),name:"z",condition:"<="},({z:p})=>{const f=g(pn(c,d,h,p,i,a,u,n,s)).toVar();z(f.lessThan(l.x),()=>{l.y.assign(l.x),l.x.assign(f)}).ElseIf(f.lessThan(l.y),()=>{l.y.assign(f)})})})}),z(s.equal(y(0)),()=>{l.assign(Pt(l))}),l}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),YS=Pe([$S,XS]),jS=b(([o,e,t])=>{const s=y(t).toVar(),n=g(e).toVar(),r=T(o).toVar(),i=y().toVar(),a=y().toVar(),u=y().toVar(),c=T(he(r.x,i),he(r.y,a),he(r.z,u)).toVar(),l=T(1e6,1e6,1e6).toVar();return te({start:-1,end:y(1),name:"x",condition:"<="},({x:d})=>{te({start:-1,end:y(1),name:"y",condition:"<="},({y:h})=>{te({start:-1,end:y(1),name:"z",condition:"<="},({z:p})=>{const f=g(pn(c,d,h,p,i,a,u,n,s)).toVar();z(f.lessThan(l.x),()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(f)}).ElseIf(f.lessThan(l.y),()=>{l.z.assign(l.y),l.y.assign(f)}).ElseIf(f.lessThan(l.z),()=>{l.z.assign(f)})})})}),z(s.equal(y(0)),()=>{l.assign(Pt(l))}),l}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),QS=Pe([HS,jS]),ZS=b(([o])=>{const e=o.y,t=o.z,s=T().toVar();return z(e.lessThan(1e-4),()=>{s.assign(T(t,t,t))}).Else(()=>{let n=o.x;n=n.sub(At(n)).mul(6).toVar();const r=y(Ka(n)),i=n.sub(g(r)),a=t.mul(e.oneMinus()),u=t.mul(e.mul(i).oneMinus()),c=t.mul(e.mul(i.oneMinus()).oneMinus());z(r.equal(y(0)),()=>{s.assign(T(t,c,a))}).ElseIf(r.equal(y(1)),()=>{s.assign(T(u,t,a))}).ElseIf(r.equal(y(2)),()=>{s.assign(T(a,t,c))}).ElseIf(r.equal(y(3)),()=>{s.assign(T(a,u,t))}).ElseIf(r.equal(y(4)),()=>{s.assign(T(c,a,t))}).Else(()=>{s.assign(T(t,a,u))})}),s}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),JS=b(([o])=>{const e=T(o).toVar(),t=g(e.x).toVar(),s=g(e.y).toVar(),n=g(e.z).toVar(),r=g(Re(t,Re(s,n))).toVar(),i=g(ue(t,ue(s,n))).toVar(),a=g(i.sub(r)).toVar(),u=g().toVar(),c=g().toVar(),l=g().toVar();return l.assign(i),z(i.greaterThan(0),()=>{c.assign(a.div(i))}).Else(()=>{c.assign(0)}),z(c.lessThanEqual(0),()=>{u.assign(0)}).Else(()=>{z(t.greaterThanEqual(i),()=>{u.assign(s.sub(n).div(a))}).ElseIf(s.greaterThanEqual(i),()=>{u.assign(_e(2,n.sub(t).div(a)))}).Else(()=>{u.assign(_e(4,t.sub(s).div(a)))}),u.mulAssign(1/6),z(u.lessThan(0),()=>{u.addAssign(1)})}),T(u,c,l)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),ev=b(([o])=>{const e=T(o).toVar(),t=wa(Oa(e,T(.04045))).toVar(),s=T(e.div(12.92)).toVar(),n=T(ht(ue(e.add(T(.055)),T(0)).div(1.055),T(2.4))).toVar();return Q(s,n,t)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),og=(o,e)=>{o=g(o),e=g(e);const t=M(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return ct(o.sub(t),o.add(t),e)},ag=(o,e,t,s)=>Q(o,e,t[s].clamp()),tv=(o,e,t=le())=>ag(o,e,t,"x"),sv=(o,e,t=le())=>ag(o,e,t,"y"),ug=(o,e,t,s,n)=>Q(o,e,og(t,s[n])),nv=(o,e,t,s=le())=>ug(o,e,t,s,"x"),rv=(o,e,t,s=le())=>ug(o,e,t,s,"y"),iv=(o=1,e=0,t=le())=>t.mul(o).add(e),ov=(o,e=1)=>(o=g(o),o.abs().pow(e).mul(o.sign())),av=(o,e=1,t=.5)=>g(o).sub(t).mul(e).add(t),uv=(o=le(),e=1,t=0)=>Ou(o.convert("vec2|vec3")).mul(e).add(t),cv=(o=le(),e=1,t=0)=>ku(o.convert("vec2|vec3")).mul(e).add(t),lv=(o=le(),e=1,t=0)=>(o=o.convert("vec2|vec3"),P(ku(o),Ou(o.add(M(19,73)))).mul(e).add(t)),dv=(o=le(),e=1)=>KS(o.convert("vec2|vec3"),e,y(1)),hv=(o=le(),e=1)=>YS(o.convert("vec2|vec3"),e,y(1)),pv=(o=le(),e=1)=>QS(o.convert("vec2|vec3"),e,y(1)),fv=(o=le())=>PS(o.convert("vec2|vec3")),gv=(o=le(),e=3,t=2,s=.5,n=1)=>ri(o,y(e),t,s).mul(n),mv=(o=le(),e=3,t=2,s=.5,n=1)=>GS(o,y(e),t,s).mul(n),yv=(o=le(),e=3,t=2,s=.5,n=1)=>ig(o,y(e),t,s).mul(n),xv=(o=le(),e=3,t=2,s=.5,n=1)=>OS(o,y(e),t,s).mul(n),Tv=b(([o,e,t])=>{const s=qt(o).toVar("nDir"),n=Y(g(.5).mul(e.sub(t)),Wt).div(s).toVar("rbmax"),r=Y(g(-.5).mul(e.sub(t)),Wt).div(s).toVar("rbmin"),i=T().toVar("rbminmax");i.x=s.x.greaterThan(g(0)).select(n.x,r.x),i.y=s.y.greaterThan(g(0)).select(n.y,r.y),i.z=s.z.greaterThan(g(0)).select(n.z,r.z);const a=Re(Re(i.x,i.y),i.z).toVar("correction");return Wt.add(s.mul(a)).toVar("boxIntersection").sub(t)}),cg=b(([o,e])=>{const t=o.x,s=o.y,n=o.z;let r=e.element(0).mul(.886227);return r=r.add(e.element(1).mul(2*.511664).mul(s)),r=r.add(e.element(2).mul(2*.511664).mul(n)),r=r.add(e.element(3).mul(2*.511664).mul(t)),r=r.add(e.element(4).mul(2*.429043).mul(t).mul(s)),r=r.add(e.element(5).mul(2*.429043).mul(s).mul(n)),r=r.add(e.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),r=r.add(e.element(7).mul(2*.429043).mul(t).mul(n)),r=r.add(e.element(8).mul(.429043).mul($(t,t).sub($(s,s)))),r});var mR=Object.freeze({__proto__:null,BRDF_GGX:jo,BRDF_Lambert:Ns,BasicShadowFilter:qf,Break:pu,Continue:Ex,DFGApprox:Nu,D_GGX:Xp,Discard:Fh,EPSILON:Gd,F_Schlick:un,Fn:b,INFINITY:Ny,If:z,Loop:te,NodeAccess:Ve,NodeShaderStage:Oo,NodeType:Zm,NodeUpdateType:W,PCFShadowFilter:Kf,PCFSoftShadowFilter:Xf,PI:Qr,PI2:Sy,Return:Vy,Schlick_to_F0:jp,ScriptableNodeResources:Wr,ShaderNode:Cn,TBNViewMatrix:gs,VSMShadowFilter:Yf,V_GGX_SmithCorrelated:Kp,abs:oe,acesFilmicToneMapping:Bf,acos:Hd,add:_e,addMethodChaining:R,addNodeElement:Oy,agxToneMapping:Ff,all:ka,alphaT:Xr,and:Ed,anisotropy:Zt,anisotropyB:_s,anisotropyT:En,any:Od,append:ud,arrayBuffer:yy,asin:$d,assign:bd,atan:$a,atan2:lh,atomicAdd:DN,atomicAnd:GN,atomicFunc:Yt,atomicMax:IN,atomicMin:VN,atomicOr:ON,atomicStore:PN,atomicSub:LN,atomicXor:kN,attenuationColor:Ia,attenuationDistance:La,attribute:we,attributeArray:Eb,backgroundBlurriness:Tf,backgroundIntensity:sa,backgroundRotation:_f,batch:Mp,billboarding:ab,bitAnd:Fd,bitNot:Ud,bitOr:Pd,bitXor:Dd,bitangentGeometry:lx,bitangentLocal:dx,bitangentView:Yh,bitangentWorld:hx,bitcast:vy,blendBurn:Sf,blendColor:Ob,blendDodge:vf,blendOverlay:Rf,blendScreen:Af,blur:sf,bool:Ht,buffer:ir,bufferAttribute:nr,bumpMap:Jh,burn:kb,bvec2:dd,bvec3:wa,bvec4:gd,bypass:Eh,cache:Mn,call:Nd,cameraFar:es,cameraNear:Jt,cameraNormalMatrix:qy,cameraPosition:su,cameraProjectionMatrix:He,cameraProjectionMatrixInverse:$y,cameraViewMatrix:je,cameraWorldMatrix:Hy,cbrt:ih,cdl:Yb,ceil:xi,checker:oS,cineonToneMapping:Mf,clamp:Et,clearcoat:Kr,clearcoatRoughness:zn,code:Fi,color:cd,colorSpaceToWorking:eu,colorToDirection:rT,compute:Ch,cond:dh,context:bi,convert:yd,convertColorSpace:wy,convertToTexture:_b,cos:It,cross:_i,cubeTexture:on,dFdx:Ha,dFdy:qa,dashSize:bs,defaultBuildStages:ko,defaultShaderStages:sd,defined:Gn,degrees:zd,deltaTime:gf,densityFog:xN,densityFogFactor:Mu,depth:xu,depthPass:tN,difference:th,diffuseColor:ee,directPointLight:Zf,directionToColor:Op,dispersion:Va,distance:eh,div:gt,dodge:zb,dot:is,drawIndex:Cp,dynamicBufferAttribute:Rh,element:md,emissive:Ho,equal:Sd,equals:Zd,equirectUV:Tu,exp:za,exp2:rn,expression:rs,faceDirection:rr,faceForward:Za,faceforward:Ay,float:g,floor:At,fog:Xn,fract:Xt,frameGroup:_d,frameId:Q_,frontFacing:Gh,fwidth:jd,gain:$_,gapSize:Hn,getConstNodeType:ad,getCurrentStack:Ea,getDirection:ef,getDistanceAttenuation:Gu,getGeometryRoughness:qp,getNormalFromDepth:Nb,getParallaxCorrectNormal:Tv,getRoughness:bu,getScreenPosition:bb,getShIrradianceAt:cg,getTextureIndex:pf,getViewPosition:ks,glsl:lN,glslFn:dN,grayscale:Hb,greaterThan:Oa,greaterThanEqual:Cd,hash:W_,highpModelNormalViewMatrix:sx,highpModelViewMatrix:tx,hue:Xb,instance:Sx,instanceIndex:lr,instancedArray:wb,instancedBufferAttribute:Zr,instancedDynamicBufferAttribute:qo,instancedMesh:wp,int:y,inverseSqrt:Wa,inversesqrt:Ry,invocationLocalIndex:Nx,invocationSubgroupIndex:bx,ior:wn,iridescence:mi,iridescenceIOR:Ua,iridescenceThickness:Pa,ivec2:Ae,ivec3:hd,ivec4:pd,js:uN,label:ph,length:zt,lengthSq:ja,lessThan:Ad,lessThanEqual:Rd,lightPosition:Uu,lightProjectionUV:Vf,lightShadowMatrix:Fu,lightTargetDirection:Pu,lightTargetPosition:Gf,lightViewPosition:Pi,lightingContext:Pp,lights:$N,linearDepth:ei,linearToneMapping:Ef,localId:vN,log:yi,log2:vt,logarithmicDepthToViewZ:zx,loop:wx,luminance:Eu,mat2:fi,mat3:Oe,mat4:Ts,matcapUV:of,materialAO:Ap,materialAlphaTest:ep,materialAnisotropy:fp,materialAnisotropyVector:Os,materialAttenuationColor:Np,materialAttenuationDistance:bp,materialClearcoat:up,materialClearcoatNormal:lp,materialClearcoatRoughness:cp,materialColor:an,materialDispersion:vp,materialEmissive:sp,materialIOR:_p,materialIridescence:gp,materialIridescenceIOR:mp,materialIridescenceThickness:yp,materialLightMap:du,materialLineDashOffset:lu,materialLineDashSize:uu,materialLineGapSize:cu,materialLineScale:au,materialLineWidth:Or,materialMetalness:op,materialNormal:ap,materialOpacity:cr,materialPointWidth:Sp,materialReference:dt,materialReflectivity:Gr,materialRefractionRatio:zh,materialRotation:dp,materialRoughness:ip,materialSheen:hp,materialSheenRoughness:pp,materialShininess:tp,materialSpecular:np,materialSpecularColor:rp,materialSpecularIntensity:Yo,materialSpecularStrength:Bn,materialThickness:Tp,materialTransmission:xp,max:ue,maxMipLevel:Ph,mediumpModelViewMatrix:Vh,metalness:kn,min:Re,mix:Q,mixElement:uh,mod:Xa,modInt:Ga,modelDirection:Qy,modelNormalMatrix:Lh,modelPosition:Zy,modelScale:Jy,modelViewMatrix:Kt,modelViewPosition:ex,modelViewProjection:hu,modelWorldMatrix:at,modelWorldMatrixInverse:Ih,morphReference:Up,mrt:ff,mul:$,mx_aastep:og,mx_cell_noise_float:fv,mx_contrast:av,mx_fractal_noise_float:gv,mx_fractal_noise_vec2:mv,mx_fractal_noise_vec3:yv,mx_fractal_noise_vec4:xv,mx_hsvtorgb:ZS,mx_noise_float:uv,mx_noise_vec3:cv,mx_noise_vec4:lv,mx_ramplr:tv,mx_ramptb:sv,mx_rgbtohsv:JS,mx_safepower:ov,mx_splitlr:nv,mx_splittb:rv,mx_srgb_texture_to_lin_rec709:ev,mx_transform_uv:iv,mx_worley_noise_float:dv,mx_worley_noise_vec2:hv,mx_worley_noise_vec3:pv,negate:qd,neutralToneMapping:Uf,nodeArray:xs,nodeImmutable:U,nodeObject:E,nodeObjects:Jn,nodeProxy:C,normalFlat:Oh,normalGeometry:Ni,normalLocal:Xe,normalMap:Xo,normalView:lt,normalWorld:Si,normalize:qt,not:Md,notEqual:vd,numWorkgroups:NN,objectDirection:Ky,objectGroup:Ba,objectPosition:Dh,objectScale:Yy,objectViewPosition:jy,objectWorldMatrix:Xy,oneMinus:Kd,or:wd,orthographicDepthToViewZ:kx,oscSawtooth:rb,oscSine:tb,oscSquare:sb,oscTriangle:nb,output:$n,outputStruct:k_,overlay:$b,overloadingFn:Pe,parabola:ta,parallaxDirection:Qh,parallaxUV:fx,parameter:G_,pass:Jb,passTexture:eN,pcurve:H_,perspectiveDepthToViewZ:mu,pmremTexture:vu,pointUV:Ub,pointWidth:Ty,positionGeometry:Ce,positionLocal:me,positionPrevious:Jr,positionView:xe,positionViewDirection:ae,positionWorld:Wt,positionWorldDirection:nu,posterize:Qb,pow:ht,pow2:Ya,pow3:sh,pow4:nh,property:Fa,radians:kd,rand:ah,range:_N,rangeFog:yN,rangeFogFactor:wu,reciprocal:Yd,reference:ne,referenceBuffer:Ko,reflect:Jd,reflectVector:Hh,reflectView:Wh,reflector:gb,refract:Qa,refractVector:qh,refractView:$h,reinhardToneMapping:wf,remainder:Vd,remap:Mh,remapClamp:Bh,renderGroup:k,renderOutput:tu,rendererReference:Sh,rotate:Au,rotateUV:ib,roughness:Nt,round:Xd,rtt:yf,sRGBTransferEOTF:yh,sRGBTransferOETF:xh,sampler:Wy,saturate:oh,saturation:qb,screen:Wb,screenCoordinate:dr,screenSize:Kn,screenUV:Bt,scriptable:mN,scriptableValue:zr,select:Ue,setCurrentStack:On,shaderStages:zo,shadow:Qf,shadowPositionWorld:Lu,sharedUniformGroup:Ma,sheen:fs,sheenRoughness:gi,shiftLeft:Ld,shiftRight:Id,shininess:Yr,sign:qn,sin:st,sinc:q_,skinning:Rx,skinningReference:Fp,smoothstep:ct,smoothstepElement:ch,specularColor:We,specularF90:Wn,spherizeUV:ob,split:xy,spritesheetUV:lb,sqrt:Pt,stack:kr,step:Ti,storage:Bi,storageBarrier:EN,storageObject:Cb,storageTexture:bf,string:my,sub:Y,subgroupIndex:_x,subgroupSize:AN,tan:Wd,tangentGeometry:Ri,tangentLocal:or,tangentView:ar,tangentWorld:Xh,temp:gh,texture:K,texture3D:af,textureBarrier:wN,textureBicubic:Jp,textureCubeUV:tf,textureLoad:ge,textureSize:ns,textureStore:Db,thickness:Da,time:Cs,timerDelta:eb,timerGlobal:J_,timerLocal:Z_,toOutputColorSpace:Th,toWorkingColorSpace:_h,toneMapping:vh,toneMappingExposure:Ah,toonOutlinePass:nN,transformDirection:rh,transformNormal:kh,transformNormalToView:ru,transformedBentNormalView:Zh,transformedBitangentView:jh,transformedBitangentWorld:px,transformedClearcoatNormalView:Hs,transformedNormalView:fe,transformedNormalWorld:vi,transformedTangentView:ou,transformedTangentWorld:cx,transmission:jr,transpose:Qd,triNoise3D:X_,triplanarTexture:hb,triplanarTextures:mf,trunc:Ka,tslFn:gy,uint:D,uniform:V,uniformArray:Gt,uniformGroup:Td,uniforms:ox,userData:Ib,uv:le,uvec2:ld,uvec3:dn,uvec4:fd,varying:ke,varyingProperty:et,vec2:M,vec3:T,vec4:P,vectorComponents:As,velocity:Gb,vertexColor:Bb,vertexIndex:Rp,vertexStage:mh,vibrance:Kb,viewZToLogarithmicDepth:yu,viewZToOrthographicDepth:Qs,viewZToPerspectiveDepth:Ip,viewport:$t,viewportBottomLeft:Vx,viewportCoordinate:Lp,viewportDepthTexture:gu,viewportLinearDepth:Wx,viewportMipTexture:fu,viewportResolution:Lx,viewportSafeUV:ub,viewportSharedTexture:Gp,viewportSize:Dp,viewportTexture:Gx,viewportTopLeft:Ix,viewportUV:Dx,wgsl:cN,wgslFn:hN,workgroupArray:FN,workgroupBarrier:CN,workgroupId:SN,workingToColorSpace:bh,xor:Bd});const Lt=new Ru;class _v extends os{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const n=this.renderer,r=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(r===null)n._clearColor.getRGB(Lt,kt),Lt.a=n._clearColor.a;else if(r.isColor===!0)r.getRGB(Lt,kt),Lt.a=1,i=!0;else if(r.isNode===!0){const a=this.get(e),u=r;Lt.copy(n._clearColor);let c=a.backgroundMesh;if(c===void 0){const d=bi(P(u).mul(sa),{getUV:()=>_f.mul(Si),getTextureLevel:()=>Tf});let h=hu;h=h.setZ(h.w);const p=new ce;p.name="Background.material",p.side=Ct,p.depthTest=!1,p.depthWrite=!1,p.fog=!1,p.lights=!1,p.vertexNode=h,p.colorNode=d,a.backgroundMeshNode=d,a.backgroundMesh=c=new tn(new mm(1,32,32),p),c.frustumCulled=!1,c.name="Background.mesh",c.onBeforeRender=function(f,m,x){this.matrixWorld.copyPosition(x.matrixWorld)}}const l=u.getCacheKey();a.backgroundCacheKey!==l&&(a.backgroundMeshNode.node=P(u).mul(sa),a.backgroundMeshNode.needsUpdate=!0,c.material.needsUpdate=!0,a.backgroundCacheKey=l),t.unshift(c,c.geometry,c.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(n.autoClear===!0||i===!0){const a=s.clearColorValue;a.r=Lt.r,a.g=Lt.g,a.b=Lt.b,a.a=Lt.a,(n.backend.isWebGLBackend===!0||n.alpha===!0)&&(a.r*=a.a,a.g*=a.a,a.b*=a.a),s.depthClearValue=n._clearDepth,s.stencilClearValue=n._clearStencil,s.clearColor=n.autoClearColor===!0,s.clearDepth=n.autoClearDepth===!0,s.clearStencil=n.autoClearStencil===!0}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let bv=0;class na{constructor(e="",t=[],s=0,n=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=n,this.id=bv++}}class Nv{constructor(e,t,s,n,r,i,a,u,c,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=n,this.bindings=r,this.updateNodes=i,this.updateBeforeNodes=a,this.updateAfterNodes=u,this.monitor=c,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){const n=new na(t.name,[],t.index,t);e.push(n);for(const r of t.bindings)n.bindings.push(r.clone())}else e.push(t);return e}}class Gc{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class Sv{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class lg{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class vv extends lg{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class Av{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let Rv=0;class to{constructor(e=null){this.id=Rv++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class Cv extends O{static get type(){return"StructTypeNode"}constructor(e,t){super(),this.name=e,this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class ws{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 Ev extends ws{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class wv extends ws{constructor(e,t=new Ye){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class Mv extends ws{constructor(e,t=new j){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Bv extends ws{constructor(e,t=new Me){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Fv extends ws{constructor(e,t=new mt){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Uv extends ws{constructor(e,t=new Yn){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class Pv extends ws{constructor(e,t=new Ie){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class Dv extends Ev{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Lv extends wv{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Iv extends Mv{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Vv extends Bv{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Gv extends Fv{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Ov extends Uv{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class kv extends Pv{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}const qs=4,Oc=[.125,.215,.35,.446,.526,.582],hs=20,so=new Tl(-1,1,1,-1,0,1),zv=new kg(90,1),kc=new mt;let no=null,ro=0,io=0;const ds=(1+Math.sqrt(5))/2,Ds=1/ds,zc=[new j(-ds,Ds,0),new j(ds,Ds,0),new j(-Ds,0,ds),new j(Ds,0,ds),new j(0,ds,-Ds),new j(0,ds,Ds),new j(-1,1,-1),new j(1,1,-1),new j(-1,1,1),new j(1,1,1)],Wv=[3,1,5,0,4,2],oo=ef(le(),we("faceIndex")).normalize(),zu=T(oo.x,oo.y,oo.z);class $v{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,s=.1,n=100,r=null){if(this._setSize(256),this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.");const a=r||this._allocateTargets();return this.fromSceneAsync(e,t,s,n,a),a}no=this._renderer.getRenderTarget(),ro=this._renderer.getActiveCubeFace(),io=this._renderer.getActiveMipmapLevel();const i=r||this._allocateTargets();return i.depthBuffer=!0,this._sceneToCubeUV(e,s,n,i),t>0&&this._blur(i,0,0,t),this._applyPMREM(i),this._cleanup(i),i}async fromSceneAsync(e,t=0,s=.1,n=100,r=null){return this._hasInitialized===!1&&await this._renderer.init(),this.fromScene(e,t,s,n,r)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead."),this._setSizeFromTexture(e);const s=t||this._allocateTargets();return this.fromEquirectangularAsync(e,s),s}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return this._hasInitialized===!1&&await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1){console.warn("THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const s=t||this._allocateTargets();return this.fromCubemapAsync(e,t),s}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return this._hasInitialized===!1&&await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=$c(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Hc(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===Zs||e.mapping===Js?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget(no,ro,io),e.scissorTest=!1,vr(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),no=this._renderer.getRenderTarget(),ro=this._renderer.getActiveCubeFace(),io=this._renderer.getActiveMipmapLevel();const s=t||this._allocateTargets();return this._textureToCubeUV(e,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,s={magFilter:ft,minFilter:ft,generateMipmaps:!1,type:pt,format:sn,colorSpace:kt},n=Wc(e,t,s);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Wc(e,t,s);const{_lodMax:r}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=Hv(r)),this._blurMaterial=qv(r,e,t)}return n}async _compileMaterial(e){const t=new tn(this._lodPlanes[0],e);await this._renderer.compile(t,so)}_sceneToCubeUV(e,t,s,n){const r=zv;r.near=t,r.far=s;const i=[1,1,1,1,-1,1],a=[1,-1,1,-1,1,-1],u=this._renderer,c=u.autoClear;u.getClearColor(kc),u.autoClear=!1;let l=this._backgroundBox;if(l===null){const p=new fl({name:"PMREM.Background",side:Ct,depthWrite:!1,depthTest:!1});l=new tn(new _l,p)}let d=!1;const h=e.background;h?h.isColor&&(l.material.color.copy(h),e.background=null,d=!0):(l.material.color.copy(kc),d=!0),u.setRenderTarget(n),u.clear(),d&&u.render(l,r);for(let p=0;p<6;p++){const f=p%3;f===0?(r.up.set(0,i[p],0),r.lookAt(a[p],0,0)):f===1?(r.up.set(0,0,i[p]),r.lookAt(0,a[p],0)):(r.up.set(0,i[p],0),r.lookAt(0,0,a[p]));const m=this._cubeSize;vr(n,f*m,p>2?m:0,m,m),u.render(e,r)}u.autoClear=c,e.background=h}_textureToCubeUV(e,t){const s=this._renderer,n=e.mapping===Zs||e.mapping===Js;n?this._cubemapMaterial===null&&(this._cubemapMaterial=$c(e)):this._equirectMaterial===null&&(this._equirectMaterial=Hc(e));const r=n?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=r;const a=this._cubeSize;vr(t,0,0,3*a,2*a),s.setRenderTarget(t),s.render(i,so)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const n=this._lodPlanes.length;for(let r=1;r<n;r++){const i=Math.sqrt(this._sigmas[r]*this._sigmas[r]-this._sigmas[r-1]*this._sigmas[r-1]),a=zc[(n-r-1)%zc.length];this._blur(e,r-1,r,i,a)}t.autoClear=s}_blur(e,t,s,n,r){const i=this._pingPongRenderTarget;this._halfBlur(e,i,t,s,n,"latitudinal",r),this._halfBlur(i,e,s,s,n,"longitudinal",r)}_halfBlur(e,t,s,n,r,i,a){const u=this._renderer,c=this._blurMaterial;i!=="latitudinal"&&i!=="longitudinal"&&console.error("blur direction must be either latitudinal or longitudinal!");const l=3,d=this._lodMeshes[n];d.material=c;const h=c.uniforms,p=this._sizeLods[s]-1,f=isFinite(r)?Math.PI/(2*p):2*Math.PI/(2*hs-1),m=r/f,x=isFinite(r)?1+Math.floor(l*m):hs;x>hs&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${x} samples when the maximum is set to ${hs}`);const N=[];let v=0;for(let I=0;I<hs;++I){const G=I/m,X=Math.exp(-G*G/2);N.push(X),I===0?v+=X:I<x&&(v+=2*X)}for(let I=0;I<N.length;I++)N[I]=N[I]/v;e.texture.frame=(e.texture.frame||0)+1,h.envMap.value=e.texture,h.samples.value=x,h.weights.array=N,h.latitudinal.value=i==="latitudinal"?1:0,a&&(h.poleAxis.value=a);const{_lodMax:w}=this;h.dTheta.value=f,h.mipInt.value=w-s;const B=this._sizeLods[n],F=3*B*(n>w-qs?n-w+qs:0),L=4*(this._cubeSize-B);vr(t,F,L,3*B,2*B),u.setRenderTarget(t),u.render(d,so)}}function Hv(o){const e=[],t=[],s=[],n=[];let r=o;const i=o-qs+1+Oc.length;for(let a=0;a<i;a++){const u=Math.pow(2,r);t.push(u);let c=1/u;a>o-qs?c=Oc[a-o+qs-1]:a===0&&(c=0),s.push(c);const l=1/(u-2),d=-l,h=1+l,p=[d,d,h,d,h,h,d,d,h,h,d,h],f=6,m=6,x=3,N=2,v=1,w=new Float32Array(x*m*f),B=new Float32Array(N*m*f),F=new Float32Array(v*m*f);for(let I=0;I<f;I++){const G=I%3*2/3-1,X=I>2?0:-1,ie=[G,X,0,G+2/3,X,0,G+2/3,X+1,0,G,X,0,G+2/3,X+1,0,G,X+1,0],Z=Wv[I];w.set(ie,x*m*Z),B.set(p,N*m*Z);const Qe=[Z,Z,Z,Z,Z,Z];F.set(Qe,v*m*Z)}const L=new Sl;L.setAttribute("position",new Ur(w,x)),L.setAttribute("uv",new Ur(B,N)),L.setAttribute("faceIndex",new Ur(F,v)),e.push(L),n.push(new tn(L,null)),r>qs&&r--}return{lodPlanes:e,sizeLods:t,sigmas:s,lodMeshes:n}}function Wc(o,e,t){const s=new Ss(o,e,t);return s.texture.mapping=bo,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function vr(o,e,t,s,n){o.viewport.set(e,t,s,n),o.scissor.set(e,t,s,n)}function Wu(o){const e=new ce;return e.depthTest=!1,e.depthWrite=!1,e.blending=en,e.name=`PMREM_${o}`,e}function qv(o,e,t){const s=Gt(new Array(hs).fill(0)),n=V(new j(0,1,0)),r=V(0),i=g(hs),a=V(0),u=V(1),c=K(null),l=V(0),d=g(1/e),h=g(1/t),p=g(o),f={n:i,latitudinal:a,weights:s,poleAxis:n,outputDirection:zu,dTheta:r,samples:u,envMap:c,mipInt:l,CUBEUV_TEXEL_WIDTH:d,CUBEUV_TEXEL_HEIGHT:h,CUBEUV_MAX_MIP:p},m=Wu("blur");return m.uniforms=f,m.fragmentNode=sf({...f,latitudinal:a.equal(1)}),m}function $c(o){const e=Wu("cubemap");return e.fragmentNode=on(o,zu),e}function Hc(o){const e=Wu("equirect");return e.fragmentNode=K(o,Tu(zu),0),e}const qc=new WeakMap,Kv=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),Ar=o=>/e/g.test(o)?String(o).replace(/\+/g,""):(o=Number(o),o+(o%1?"":".0"));class dg{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=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.flow={code:""},this.chaining=[],this.stack=kr(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new to,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=qc.get(this.renderer);return e===void 0&&(e=new Ft,qc.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new Ss(e,t,s)}createCubeRenderTarget(e,t){return new kp(e,t)}createPMREMGenerator(){return new $v(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),n=[];let r=!0;for(const a of t)n.push(a),r=r&&a.groupNode.shared!==!0;let i;return r?(i=s.get(n),i===void 0&&(i=new na(e,n,this.bindingsIndexes[e].group,n),s.set(n,i))):i=new na(e,n,this.bindingsIndexes[e].group,n),i}getBindGroupArray(e,t){const s=this.bindings[t];let n=s[e];return n===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=n=[]),n}getBindings(){let e=this.bindGroups;if(e===null){const t={},s=this.bindings;for(const n of zo)for(const r in s[n]){const i=s[n][r];(t[r]||(t[r]=[])).push(...i)}e=[];for(const n in t){const r=t[n],i=this._getBindGroup(n,r);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort((t,s)=>t.bindings[0].groupNode.order-s.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){const s=e[t];this.bindingsIndexes[s.name].group=t,s.index=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){this.nodes.includes(e)===!1&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){this.sequentialNodes.includes(e)===!1&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(const e of this.nodes)e.getUpdateType()!==W.NONE&&this.updateNodes.push(e.getSelf());for(const e of this.sequentialNodes){const t=e.getUpdateBeforeType(),s=e.getUpdateAfterType();t!==W.NONE&&this.updateBeforeNodes.push(e.getSelf()),s!==W.NONE&&this.updateAfterNodes.push(e.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===ft||e.magFilter===_o||e.magFilter===Xs||e.magFilter===ms||e.minFilter===ft||e.minFilter===_o||e.minFilter===Xs||e.minFilter===ms}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}getSharedContext(){return{...this.context},this.context}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){const s=this.getDataFromNode(e);return s.cache===void 0&&(s.cache=new to(t?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){console.warn("Abstract function.")}getInstanceIndex(){console.warn("Abstract function.")}getDrawIndex(){console.warn("Abstract function.")}getFrontFacing(){console.warn("Abstract function.")}getFragCoord(){console.warn("Abstract function.")}isFlipY(){return!1}increaseUsage(e){const t=this.getDataFromNode(e);return t.usageCount=t.usageCount===void 0?1:t.usageCount+1,t.usageCount}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(e,t=null){if(t===null&&(e==="float"||e==="int"||e==="uint"?t=0:e==="bool"?t=!1:e==="color"?t=new mt:e==="vec2"?t=new Ye:e==="vec3"?t=new j:e==="vec4"&&(t=new Me)),e==="float")return Ar(t);if(e==="int")return`${Math.round(t)}`;if(e==="uint")return t>=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${Ar(t.r)}, ${Ar(t.g)}, ${Ar(t.b)} )`;const s=this.getTypeLength(e),n=this.getComponentType(e),r=i=>this.generateConst(n,i);if(s===2)return`${this.getType(e)}( ${r(t.x)}, ${r(t.y)} )`;if(s===3)return`${this.getType(e)}( ${r(t.x)}, ${r(t.y)}, ${r(t.z)} )`;if(s===4)return`${this.getType(e)}( ${r(t.x)}, ${r(t.y)}, ${r(t.z)}, ${r(t.w)} )`;if(s>4&&t&&(t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(r).join(", ")} )`;if(s>4)return`${this.getType(e)}()`;throw new Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){const s=this.attributes;for(const r of s)if(r.name===e)return r;const n=new Gc(e,t);return s.push(n),n}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===ze)return"int";if(t===Le)return"uint"}return"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;const s=ya(e);return(t==="float"?"":t[0])+s}getTypeFromArray(e){return Kv.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,n=e.itemSize,r=e.normalized;let i;return!(e instanceof yl)&&r!==!0&&(i=this.getTypeFromArray(s)),this.getTypeFromLength(n,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return s!==null?Number(s[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}addStack(){return this.stack=kr(this.stack),this.stacks.push(Ea()||this.stack),On(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,On(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){s=s===null?e.isGlobal(this)?this.globalCache:this.cache:s;let n=s.getData(e);return n===void 0&&(n={},s.setData(e,n)),n[t]===void 0&&(n[t]={}),n[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let n=s.bufferAttribute;if(n===void 0){const r=this.uniforms.index++;n=new Gc("nodeAttribute"+r,t,e),this.bufferAttributes.push(n),s.bufferAttribute=n}return n}getStructTypeFromNode(e,t,s=this.shaderStage){const n=this.getDataFromNode(e,s);let r=n.structType;if(r===void 0){const i=this.structs.index++;r=new Cv("StructType"+i,t),this.structs[s].push(r),n.structType=r}return r}getUniformFromNode(e,t,s=this.shaderStage,n=null){const r=this.getDataFromNode(e,s,this.globalCache);let i=r.uniform;if(i===void 0){const a=this.uniforms.index++;i=new Sv(n||"nodeUniform"+a,t,e),this.uniforms[s].push(i),r.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),n=this.shaderStage){const r=this.getDataFromNode(e,n);let i=r.variable;if(i===void 0){const a=this.vars[n]||(this.vars[n]=[]);t===null&&(t="nodeVar"+a.length),i=new lg(t,s),a.push(i),r.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const n=this.getDataFromNode(e,"any");let r=n.varying;if(r===void 0){const i=this.varyings,a=i.length;t===null&&(t="nodeVarying"+a),r=new vv(t,s),i.push(r),n.varying=r}return r}getCodeFromNode(e,t,s=this.shaderStage){const n=this.getDataFromNode(e);let r=n.code;if(r===void 0){const i=this.codes[s]||(this.codes[s]=[]),a=i.length;r=new Av("nodeCode"+a,t),i.push(r),n.code=r}return r}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:n}=this.getDataFromNode(e);let r=!0,i=t;for(;i;){if(n.get(i)===!0){r=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(r)for(const a of s)this.addLineFlowCode(a)}addLineFlowCodeBlock(e,t,s){const n=this.getDataFromNode(e),r=n.flowCodes||(n.flowCodes=[]),i=n.flowCodeBlock||(n.flowCodeBlock=new WeakMap);r.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`;
|
|
`),this.flow.code+=e,this)}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new Pf,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let i=0;const a=Object.values(this);return{next:()=>({value:a[i],done:i++>=a.length})}}};for(const i of t.inputs)s[i.name]=new df(i.type,i.name);e.layout=null;const n=e.call(s),r=this.flowStagesNode(n,t.type);return e.layout=t,r}flowStagesNode(e,t=null){const s=this.flow,n=this.vars,r=this.cache,i=this.buildStage,a=this.stack,u={code:""};this.flow=u,this.vars={},this.cache=new to,this.stack=kr();for(const c of ko)this.setBuildStage(c),u.result=e.build(this,t);return u.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=n,this.cache=r,this.stack=a,this.setBuildStage(i),u}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,n={code:""};return this.flow=n,n.result=e.build(this,t),this.flow=s,n}flowNodeFromShaderStage(e,t,s=null,n=null){const r=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return n!==null&&(i.code+=`${this.tab+n} = ${i.result};
|
|
`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(r),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(s!==void 0)for(const n of s)t+=`${this.getVar(n.type,n.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(t!==void 0)for(const n of t)s+=n.code+`
|
|
`;return s}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(){const{object:e,material:t,renderer:s}=this;if(t!==null){let n=s.library.fromMaterial(t);n===null&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),n=new ce),n.build(this)}else this.addFlow("compute",e);for(const n of ko){this.setBuildStage(n),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const r of zo){this.setShaderStage(r);const i=this.flowNodes[r];for(const a of i)n==="generate"?this.flowNode(a):a.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if(t==="float"||t==="int"||t==="uint")return new Dv(e);if(t==="vec2"||t==="ivec2"||t==="uvec2")return new Lv(e);if(t==="vec3"||t==="ivec3"||t==="uvec3")return new Iv(e);if(t==="vec4"||t==="ivec4"||t==="uvec4")return new Vv(e);if(t==="color")return new Gv(e);if(t==="mat3")return new Ov(e);if(t==="mat4")return new kv(e);throw new Error(`Uniform "${t}" not declared.`)}format(e,t,s){if(t=this.getVectorType(t),s=this.getVectorType(s),t===s||s===null||this.isReference(s))return e;const n=this.getTypeLength(t),r=this.getTypeLength(s);return n===16&&r===9?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:n===9&&r===4?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:n>4||r>4||r===0?e:n===r?`${this.getType(s)}( ${e} )`:n>r?this.format(`${e}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(t)),s):r===4&&n>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:n===2?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(n===1&&r>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${xl} - Node System
|
|
`}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}}class Kc{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 s=e.get(t);return s===void 0&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===W.FRAME){const{frameMap:n}=this._getMaps(this.updateBeforeMap,s);n.get(s)!==this.frameId&&e.updateBefore(this)!==!1&&n.set(s,this.frameId)}else if(t===W.RENDER){const{renderMap:n}=this._getMaps(this.updateBeforeMap,s);n.get(s)!==this.renderId&&e.updateBefore(this)!==!1&&n.set(s,this.renderId)}else t===W.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===W.FRAME){const{frameMap:n}=this._getMaps(this.updateAfterMap,s);n.get(s)!==this.frameId&&e.updateAfter(this)!==!1&&n.set(s,this.frameId)}else if(t===W.RENDER){const{renderMap:n}=this._getMaps(this.updateAfterMap,s);n.get(s)!==this.renderId&&e.updateAfter(this)!==!1&&n.set(s,this.renderId)}else t===W.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===W.FRAME){const{frameMap:n}=this._getMaps(this.updateMap,s);n.get(s)!==this.frameId&&e.update(this)!==!1&&n.set(s,this.frameId)}else if(t===W.RENDER){const{renderMap:n}=this._getMaps(this.updateMap,s);n.get(s)!==this.renderId&&e.update(this)!==!1&&n.set(s,this.renderId)}else t===W.OBJECT&&e.update(this)}update(){this.frameId++,this.lastTime===void 0&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class $u{constructor(e,t,s=null,n="",r=!1){this.type=e,this.name=t,this.count=s,this.qualifier=n,this.isConst=r}}$u.isNodeFunctionInput=!0;class Xv extends Es{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,n=Pu(this.light),r=e.context.reflectedLight;t.direct({lightDirection:n,lightColor:s,reflectedLight:r},e.stack,e)}}const ao=new Ie,Rr=new Ie;let Nn=null;class Yv extends Es{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=V(new j).setGroup(k),this.halfWidth=V(new j).setGroup(k),this.updateType=W.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;Rr.identity(),ao.copy(t.matrixWorld),ao.premultiply(s),Rr.extractRotation(ao),this.halfWidth.value.set(t.width*.5,0,0),this.halfHeight.value.set(0,t.height*.5,0),this.halfWidth.value.applyMatrix4(Rr),this.halfHeight.value.applyMatrix4(Rr)}setup(e){super.setup(e);let t,s;e.isAvailable("float32Filterable")?(t=K(Nn.LTC_FLOAT_1),s=K(Nn.LTC_FLOAT_2)):(t=K(Nn.LTC_HALF_1),s=K(Nn.LTC_HALF_2));const{colorNode:n,light:r}=this,i=e.context.lightingModel,a=Pi(r),u=e.context.reflectedLight;i.directRectArea({lightColor:n,lightPosition:a,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:u,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){Nn=e}}class hg extends Es{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=V(0).setGroup(k),this.penumbraCosNode=V(0).setGroup(k),this.cutoffDistanceNode=V(0).setGroup(k),this.decayExponentNode=V(0).setGroup(k)}update(e){super.update(e);const{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}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return ct(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:n,decayExponentNode:r,light:i}=this,a=Pi(i).sub(xe),u=a.normalize(),c=u.dot(Pu(i)),l=this.getSpotAttenuation(c),d=a.length(),h=Gu({lightDistance:d,cutoffDistance:n,decayExponent:r});let p=s.mul(l).mul(h);if(i.map){const m=Vf(i),x=K(i.map,m.xy).onRenderUpdate(()=>i.map);p=m.mul(2).sub(1).abs().lessThan(1).all().select(p.mul(x),p)}const f=e.context.reflectedLight;t.direct({lightDirection:u,lightColor:p,reflectedLight:f},e.stack,e)}}class jv extends hg{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&t.isTexture===!0){const n=e.acos().mul(1/Math.PI);s=K(t,M(n,0),0).r}else s=super.getSpotAttenuation(e);return s}}class Qv extends Es{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class Zv extends Es{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=Uu(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=V(new mt).setGroup(k)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:n}=this,i=lt.dot(n).mul(.5).add(.5),a=Q(s,t,i);e.context.irradiance.addAssign(a)}}class Jv extends Es{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let s=0;s<9;s++)t.push(new j);this.lightProbe=Gt(t)}update(e){const{light:t}=this;super.update(e);for(let s=0;s<9;s++)this.lightProbe.array[s].copy(t.sh.coefficients[s]).multiplyScalar(t.intensity)}setup(e){const t=cg(Si,this.lightProbe);e.context.irradiance.addAssign(t)}}class pg{parseFunction(){console.warn("Abstract function.")}}class Hu{constructor(e,t,s="",n=""){this.type=e,this.inputs=t,this.name=s,this.precision=n}getCode(){console.warn("Abstract function.")}}Hu.isNodeFunction=!0;const eA=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,tA=/[a-z_0-9]+/ig,Xc="#pragma main",sA=o=>{o=o.trim();const e=o.indexOf(Xc),t=e!==-1?o.slice(e+Xc.length):o,s=t.match(eA);if(s!==null&&s.length===5){const n=s[4],r=[];let i=null;for(;(i=tA.exec(n))!==null;)r.push(i);const a=[];let u=0;for(;u<r.length;){const f=r[u][0]==="const";f===!0&&u++;let m=r[u][0];m==="in"||m==="out"||m==="inout"?u++:m="";const x=r[u++][0];let N=Number.parseInt(r[u][0]);Number.isNaN(N)===!1?u++:N=null;const v=r[u++][0];a.push(new $u(x,v,N,m,f))}const c=t.substring(s[0].length),l=s[3]!==void 0?s[3]:"",d=s[2],h=s[1]!==void 0?s[1]:"",p=e!==-1?o.slice(0,e):"";return{type:d,inputs:a,name:l,precision:h,inputsCode:n,blockCode:c,headerCode:p}}else throw new Error("FunctionNode: Function is not a GLSL code.")};class nA extends Hu{constructor(e){const{type:t,inputs:s,name:n,precision:r,inputsCode:i,blockCode:a,headerCode:u}=sA(e);super(t,s,n,r),this.inputsCode=i,this.blockCode=a,this.headerCode=u}getCode(e=this.name){let t;const s=this.blockCode;if(s!==""){const{type:n,inputsCode:r,headerCode:i,precision:a}=this;let u=`${n} ${e} ( ${r.trim()} )`;a!==""&&(u=`${a} ${u}`),t=i+u+s}else t="";return t}}class rA extends pg{parseFunction(e){return new nA(e)}}const Yc=new WeakMap;class iA extends os{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new Kc,this.nodeBuilderCache=new Map,this.callHashCache=new Ft,this.groupsData=new Ft,this.cacheLib={}}updateGroup(e){const t=e.groupNode,s=t.name;if(s===Ba.name)return!0;if(s===k.name){const i=this.get(e),a=this.nodeFrame.renderId;return i.renderId!==a?(i.renderId=a,!0):!1}if(s===_d.name){const i=this.get(e),a=this.nodeFrame.frameId;return i.frameId!==a?(i.frameId=a,!0):!1}const n=[t,e];let r=this.groupsData.get(n);return r===void 0&&this.groupsData.set(n,r={}),r.version!==t.version?(r.version=t.version,!0):!1}getForRenderCacheKey(e){return e.initialCacheKey}getForRender(e){const t=this.get(e);let s=t.nodeBuilderState;if(s===void 0){const{nodeBuilderCache:n}=this,r=this.getForRenderCacheKey(e);if(s=n.get(r),s===void 0){const i=this.backend.createNodeBuilder(e.object,this.renderer);i.scene=e.scene,i.material=e.material,i.camera=e.camera,i.context.material=e.material,i.lightsNode=e.lightsNode,i.environmentNode=this.getEnvironmentNode(e.scene),i.fogNode=this.getFogNode(e.scene),i.clippingContext=e.clippingContext,i.build(),s=this._createNodeBuilderState(i),n.set(r,s)}s.usedTimes++,t.nodeBuilderState=s}return s}delete(e){if(e.isRenderObject){const t=this.get(e).nodeBuilderState;t.usedTimes--,t.usedTimes===0&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e))}return super.delete(e)}getForCompute(e){const t=this.get(e);let s=t.nodeBuilderState;if(s===void 0){const n=this.backend.createNodeBuilder(e,this.renderer);n.build(),s=this._createNodeBuilderState(n),t.nodeBuilderState=s}return s}_createNodeBuilderState(e){return new Nv(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.monitor,e.transforms)}getEnvironmentNode(e){this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{const s=this.get(e);s.environmentNode&&(t=s.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{const s=this.get(e);s.backgroundNode&&(t=s.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){const s=[e,t],n=this.renderer.info.calls;let r=this.callHashCache.get(s);if(r===void 0||r.callId!==n){const i=this.getEnvironmentNode(e),a=this.getFogNode(e),u=[];t&&u.push(t.getCacheKey(!0)),i&&u.push(i.getCacheKey()),a&&u.push(a.getCacheKey()),u.push(this.renderer.shadowMap.enabled?1:0),r={callId:n,cacheKey:Zn(u)},this.callHashCache.set(s,r)}return r.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){const t=this.get(e),s=e.background;if(s){const n=e.backgroundBlurriness===0&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&t.backgroundBlurriness===0;if(t.background!==s||n){const r=this.getCacheNode("background",s,()=>{if(s.isCubeTexture===!0||s.mapping===jn||s.mapping===Qn||s.mapping===bo){if(e.backgroundBlurriness>0||s.mapping===bo)return vu(s);{let i;return s.isCubeTexture===!0?i=on(s):i=K(s),Wp(i)}}else{if(s.isTexture===!0)return K(s,Bt.flipY()).setUpdateMatrix(!0);s.isColor!==!0&&console.error("WebGPUNodes: Unsupported background configuration.",s)}},n);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,s,n=!1){const r=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap);let i=r.get(t);return(i===void 0||n)&&(i=s(),r.set(t,i)),i}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){const n=this.getCacheNode("fog",s,()=>{if(s.isFogExp2){const r=ne("color","color",s).setGroup(k),i=ne("density","float",s).setGroup(k);return Xn(r,Mu(i))}else if(s.isFog){const r=ne("color","color",s).setGroup(k),i=ne("near","float",s).setGroup(k),a=ne("far","float",s).setGroup(k);return Xn(r,wu(i,a))}else console.error("THREE.Renderer: Unsupported fog configuration.",s)});t.fogNode=n,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){const n=this.getCacheNode("environment",s,()=>{if(s.isCubeTexture===!0)return on(s);if(s.isTexture===!0)return K(s);console.error("Nodes: Unsupported environment configuration.",s)});t.environmentNode=n,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,n=null,r=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=n,i.material=r,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return Yc.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),n=K(e,Bt).renderOutput(t.toneMapping,t.currentColorSpace);return Yc.set(e,s),n}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const n of s.updateNodes)t.updateNode(n)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const n of s.updateNodes)t.updateNode(n)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new Kc,this.nodeBuilderCache=new Map,this.cacheLib={}}}const uo=new vl;class ii{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewNormalMatrix=new Yn,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,e!==null&&(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix)}projectPlanes(e,t,s){const n=e.length;for(let r=0;r<n;r++){uo.copy(e[r]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const i=t[s+r],a=uo.normal;i.x=-a.x,i.y=-a.y,i.z=-a.z,i.w=uo.constant}}updateGlobal(e,t){this.shadowPass=e.overrideMaterial!==null&&e.overrideMaterial.isShadowNodeMaterial,this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let 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);const n=t.clippingPlanes,r=n.length;let i,a;if(this.clipIntersection?(i=this.intersectionPlanes,a=e.intersectionPlanes.length):(i=this.unionPlanes,a=e.unionPlanes.length),i.length!==a+r){i.length=a+r;for(let u=0;u<r;u++)i[a+u]=new Me;s=!0}this.projectPlanes(n,i,a),s&&(this.version++,this.cacheKey=`${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return t===void 0&&(t=new ii(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class oA{constructor(e,t){this.bundleGroup=e,this.camera=t}}class aA{constructor(){this.bundles=new Ft}get(e,t){const s=this.bundles,n=[e,t];let r=s.get(n);return r===void 0&&(r=new oA(e,t),s.set(n,r)),r}dispose(){this.bundles=new Ft}}class fg{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null;const s=this.getMaterialNodeClass(e.type);if(s!==null){t=new s;for(const n in e)t[n]=e[n]}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,s){if(s.has(t)){console.warn(`Redefinition of node ${t}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t=="function"||typeof t=="object")throw new Error(`Base class ${t} is not a class.`);s.set(t,e)}addClass(e,t,s){if(s.has(t)){console.warn(`Redefinition of node ${t.name}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t!="function")throw new Error(`Base class ${t.name} is not a class.`);s.set(t,e)}}const uA=new Du;class cA extends Ft{constructor(){super()}createNode(e=[]){return new Du().setLights(e)}getNode(e,t){if(e.isQuadMesh)return uA;const s=[e,t];let n=this.get(s);return n===void 0&&(n=this.createNode(),this.set(s,n)),n}}const jc=new Nl,Cr=new Ye,co=new Me,lo=new tm,Er=new Ie,jt=new Me;class lA{constructor(e,t={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:n=!0,depth:r=!0,stencil:i=!1,antialias:a=!1,samples:u=0,getFallback:c=null}=t;this.domElement=e.getDomElement(),this.backend=e,this.samples=u||a===!0?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=n,this.logarithmicDepthBuffer=s,this.outputColorSpace=q,this.toneMapping=ss,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=r,this.stencil=i,this.info=new A_,this.nodes={modelViewMatrix:null,modelNormalViewMatrix:null},this.library=new fg,this.lighting=new cA,this._getFallback=c,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new Me(0,0,this._width,this._height),this._scissor=new Me(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 Mi(new ce),this._quad.material.name="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const l=this.alpha===!0?0:1;this._clearColor=new Ru(0,0,0,l),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,type:em},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(d,h,p)=>{await this.compileAsync(d,h);const f=this._renderLists.get(d,h),m=this._renderContexts.get(d,h,this._renderTarget),x=d.overrideMaterial||p.material,N=this._objects.get(p,x,d,h,f.lightsNode,m,m.clippingContext),{fragmentShader:v,vertexShader:w}=N.getNodeBuilderState();return{fragmentShader:v,vertexShader:w}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return this._initPromise!==null?this._initPromise:(this._initPromise=new Promise(async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(n){if(this._getFallback!==null)try{this.backend=s=this._getFallback(n),await s.init(this)}catch(r){t(r);return}else{t(n);return}}this._nodes=new iA(this,s),this._animation=new g_(this._nodes,this.info),this._attributes=new N_(s),this._background=new _v(this,this._nodes),this._geometries=new v_(this._attributes,this.info),this._textures=new V_(this,s,this.info),this._pipelines=new w_(s,this._nodes),this._bindings=new M_(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new T_(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new U_(this.lighting),this._bundles=new aA,this._renderContexts=new L_,this._animation.start(),this._initialized=!0,e()}),this._initPromise)}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(this._isDeviceLost===!0)return;this._initialized===!1&&await this.init();const n=this._nodes.nodeFrame,r=n.renderId,i=this._currentRenderContext,a=this._currentRenderObjectFunction,u=this._compilationPromises,c=e.isScene===!0?e:jc;s===null&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),h=this._activeMipmapLevel,p=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=p,n.renderId++,n.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new ii),d.clippingContext.updateGlobal(c,t),c.onBeforeRender(this,e,t,l);const f=this._renderLists.get(e,t);if(f.begin(),this._projectObject(e,t,0,f,d.clippingContext),s!==e&&s.traverseVisible(function(w){w.isLight&&w.layers.test(t.layers)&&f.pushLight(w)}),f.finish(),l!==null){this._textures.updateRenderTarget(l,h);const w=this._textures.get(l);d.textures=w.textures,d.depthTexture=w.depthTexture}else d.textures=null,d.depthTexture=null;this._background.update(c,f,d);const m=f.opaque,x=f.transparent,N=f.transparentDoublePass,v=f.lightsNode;this.opaque===!0&&m.length>0&&this._renderObjects(m,t,c,v),this.transparent===!0&&x.length>0&&this._renderTransparents(x,N,t,c,v),n.renderId=r,this._currentRenderContext=i,this._currentRenderObjectFunction=a,this._compilationPromises=u,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(p)}async renderAsync(e,t){this._initialized===!1&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:
|
|
|
|
Message: ${e.message}`;e.reason&&(t+=`
|
|
Reason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:n,camera:r,renderList:i}=e,a=this._currentRenderContext,u=this._bundles.get(n,r),c=this.backend.get(u);c.renderContexts===void 0&&(c.renderContexts=new Set);const l=n.version!==c.version,d=c.renderContexts.has(a)===!1||l;if(c.renderContexts.add(a),d){this.backend.beginBundle(a),(c.renderObjects===void 0||l)&&(c.renderObjects=[]),this._currentRenderBundle=u;const h=i.opaque;this.opaque===!0&&h.length>0&&this._renderObjects(h,r,t,s),this._currentRenderBundle=null,this.backend.finishBundle(a,u),c.version=n.version}else{const{renderObjects:h}=c;for(let p=0,f=h.length;p<f;p++){const m=h[p];this._nodes.needsRefresh(m)&&(this._nodes.updateBefore(m),this._nodes.updateForRender(m),this._bindings.updateForRender(m),this._nodes.updateAfter(m))}}this.backend.addBundle(a,u)}render(e,t){if(this._initialized===!1)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(){const{currentToneMapping:e,currentColorSpace:t}=this;if(e!==ss===!1&&t!==kt===!1)return null;const{width:r,height:i}=this.getDrawingBufferSize(Cr),{depth:a,stencil:u}=this;let c=this._frameBufferTarget;return c===null&&(c=new Ss(r,i,{depthBuffer:a,stencilBuffer:u,type:pt,format:sn,colorSpace:kt,generateMipmaps:!1,minFilter:ft,magFilter:ft,samples:this.samples}),c.isPostProcessingRenderTarget=!0,this._frameBufferTarget=c),c.depthBuffer=a,c.stencilBuffer=u,c.setSize(r,i),c.viewport.copy(this._viewport),c.scissor.copy(this._scissor),c.viewport.multiplyScalar(this._pixelRatio),c.scissor.multiplyScalar(this._pixelRatio),c.scissorTest=this._scissorTest,c}_renderScene(e,t,s=!0){if(this._isDeviceLost===!0)return;const n=s?this._getFrameBufferTarget():null,r=this._nodes.nodeFrame,i=r.renderId,a=this._currentRenderContext,u=this._currentRenderObjectFunction,c=e.isScene===!0?e:jc,l=this._renderTarget,d=this._activeCubeFace,h=this._activeMipmapLevel;let p;n!==null?(p=n,this.setRenderTarget(p)):p=l;const f=this._renderContexts.get(e,t,p);this._currentRenderContext=f,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,r.renderId=this.info.calls;const m=this.coordinateSystem;t.coordinateSystem!==m&&(t.coordinateSystem=m,t.updateProjectionMatrix()),e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld();let x=this._viewport,N=this._scissor,v=this._pixelRatio;p!==null&&(x=p.viewport,N=p.scissor,v=1),this.getDrawingBufferSize(Cr),co.set(0,0,Cr.width,Cr.height);const w=x.minDepth===void 0?0:x.minDepth,B=x.maxDepth===void 0?1:x.maxDepth;f.viewportValue.copy(x).multiplyScalar(v).floor(),f.viewportValue.width>>=h,f.viewportValue.height>>=h,f.viewportValue.minDepth=w,f.viewportValue.maxDepth=B,f.viewport=f.viewportValue.equals(co)===!1,f.scissorValue.copy(N).multiplyScalar(v).floor(),f.scissor=this._scissorTest&&f.scissorValue.equals(co)===!1,f.scissorValue.width>>=h,f.scissorValue.height>>=h,f.clippingContext||(f.clippingContext=new ii),f.clippingContext.updateGlobal(c,t),c.onBeforeRender(this,e,t,p),Er.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),lo.setFromProjectionMatrix(Er,m);const F=this._renderLists.get(e,t);if(F.begin(),this._projectObject(e,t,0,F,f.clippingContext),F.finish(),this.sortObjects===!0&&F.sort(this._opaqueSort,this._transparentSort),p!==null){this._textures.updateRenderTarget(p,h);const Z=this._textures.get(p);f.textures=Z.textures,f.depthTexture=Z.depthTexture,f.width=Z.width,f.height=Z.height,f.renderTarget=p,f.depth=p.depthBuffer,f.stencil=p.stencilBuffer}else f.textures=null,f.depthTexture=null,f.width=this.domElement.width,f.height=this.domElement.height,f.depth=this.depth,f.stencil=this.stencil;f.width>>=h,f.height>>=h,f.activeCubeFace=d,f.activeMipmapLevel=h,f.occlusionQueryCount=F.occlusionQueryCount,this._background.update(c,F,f),this.backend.beginRender(f);const{bundles:L,lightsNode:I,transparentDoublePass:G,transparent:X,opaque:ie}=F;if(L.length>0&&this._renderBundles(L,c,I),this.opaque===!0&&ie.length>0&&this._renderObjects(ie,t,c,I),this.transparent===!0&&X.length>0&&this._renderTransparents(X,G,t,c,I),this.backend.finishRender(f),r.renderId=i,this._currentRenderContext=a,this._currentRenderObjectFunction=u,n!==null){this.setRenderTarget(l,d,h);const Z=this._quad;this._nodes.hasOutputChange(p.texture)&&(Z.material.fragmentNode=this._nodes.getOutputNode(p.texture),Z.material.needsUpdate=!0),this._renderScene(Z,Z.camera,!1)}return c.onAfterRender(this,e,t,p),f}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){this._initialized===!1&&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,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),s===!0&&(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){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,n){const r=this._scissor;e.isVector4?r.copy(e):r.set(e,t,s,n)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,n,r=0,i=1){const a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,s,n),a.minDepth=r,a.maxDepth=i}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){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(this._initialized===!1)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const n=this._renderTarget||this._getFrameBufferTarget();let r=null;if(n!==null){this._textures.updateRenderTarget(n);const i=this._textures.get(n);r=this._renderContexts.get(null,null,n),r.textures=i.textures,r.depthTexture=i.depthTexture,r.width=i.width,r.height=i.height,r.renderTarget=n,r.depth=n.depthBuffer,r.stencil=n.stencilBuffer}if(this.backend.clear(e,t,s,r),n!==null&&this._renderTarget===null){const i=this._quad;this._nodes.hasOutputChange(n.texture)&&(i.material.fragmentNode=this._nodes.getOutputNode(n.texture),i.material.needsUpdate=!0),this._renderScene(i,i.camera,!1)}}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,s=!0){this._initialized===!1&&await this.init(),this.clear(e,t,s)}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._renderTarget!==null?ss:this.toneMapping}get currentColorSpace(){return this._renderTarget!==null?kt:this.outputColorSpace}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(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(this.isDeviceLost===!0)return;if(this._initialized===!1)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const n=this.backend,r=this._pipelines,i=this._bindings,a=this._nodes,u=Array.isArray(e)?e:[e];if(u[0]===void 0||u[0].isComputeNode!==!0)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");n.beginCompute(e);for(const c of u){if(r.has(c)===!1){const h=()=>{c.removeEventListener("dispose",h),r.delete(c),i.delete(c),a.delete(c)};c.addEventListener("dispose",h);const p=c.onInitFunction;p!==null&&p.call(c,{renderer:this})}a.updateForCompute(c),i.updateForCompute(c);const l=i.getForCompute(c),d=r.getForCompute(c,l);n.compute(e,c,l,d)}n.finishCompute(e),t.renderId=s}async computeAsync(e){this._initialized===!1&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return this._initialized===!1&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return this._initialized===!1?(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){this._initialized===!1&&await this.init(),this._textures.updateTexture(e)}initTexture(e){this._initialized===!1&&console.warn("THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead."),this._textures.updateTexture(e)}copyFramebufferToTexture(e,t=null){if(t!==null)if(t.isVector2)t=jt.set(t.x,t.y,e.image.width,e.image.height).floor();else if(t.isVector4)t=jt.copy(t).floor();else{console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");return}else t=jt.set(0,0,e.image.width,e.image.height);let s=this._currentRenderContext,n;s!==null?n=s.renderTarget:(n=this._renderTarget||this._getFrameBufferTarget(),n!==null&&(this._textures.updateRenderTarget(n),s=this._textures.get(n))),this._textures.updateTexture(e,{renderTarget:n}),this.backend.copyFramebufferToTexture(e,s,t)}copyTextureToTexture(e,t,s=null,n=null,r=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,n,r)}async readRenderTargetPixelsAsync(e,t,s,n,r,i=0,a=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,n,r,a)}_projectObject(e,t,s,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(r=r.getGroupContext(e));else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)n.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||lo.intersectsSprite(e)){this.sortObjects===!0&&jt.setFromMatrixPosition(e.matrixWorld).applyMatrix4(Er);const{geometry:u,material:c}=e;c.visible&&n.push(e,u,c,s,jt.z,null,r)}}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)&&(!e.frustumCulled||lo.intersectsObject(e))){const{geometry:u,material:c}=e;if(this.sortObjects===!0&&(u.boundingSphere===null&&u.computeBoundingSphere(),jt.copy(u.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(Er)),Array.isArray(c)){const l=u.groups;for(let d=0,h=l.length;d<h;d++){const p=l[d],f=c[p.materialIndex];f&&f.visible&&n.push(e,u,f,s,jt.z,p,r)}}else c.visible&&n.push(e,u,c,s,jt.z,null,r)}}if(e.isBundleGroup===!0&&this.backend.beginBundle!==void 0){const u=n;n=this._renderLists.get(e,t),n.begin(),u.pushBundle({bundleGroup:e,camera:t,renderList:n}),n.finish()}const a=e.children;for(let u=0,c=a.length;u<c;u++)this._projectObject(a[u],t,s,n,r)}_renderBundles(e,t,s){for(const n of e)this._renderBundle(n,t,s)}_renderTransparents(e,t,s,n,r){if(t.length>0){for(const{material:i}of t)i.side=Ct;this._renderObjects(t,s,n,r,"backSide");for(const{material:i}of t)i.side=No;this._renderObjects(e,s,n,r);for(const{material:i}of t)i.side=js}else this._renderObjects(e,s,n,r)}_renderObjects(e,t,s,n,r=null){for(let i=0,a=e.length;i<a;i++){const u=e[i],{object:c,geometry:l,material:d,group:h,clippingContext:p}=u;if(t.isArrayCamera){const f=t.cameras;for(let m=0,x=f.length;m<x;m++){const N=f[m];if(c.layers.test(N.layers)){const v=N.viewport,w=v.minDepth===void 0?0:v.minDepth,B=v.maxDepth===void 0?1:v.maxDepth,F=this._currentRenderContext.viewportValue;F.copy(v).multiplyScalar(this._pixelRatio).floor(),F.minDepth=w,F.maxDepth=B,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(c,s,N,l,d,h,n,p,r)}}}else this._currentRenderObjectFunction(c,s,t,l,d,h,n,p,r)}}renderObject(e,t,s,n,r,i,a,u=null,c=null){let l,d,h;if(e.onBeforeRender(this,t,s,n,r,i),t.overrideMaterial!==null){const p=t.overrideMaterial;r.positionNode&&r.positionNode.isNode&&(l=p.positionNode,p.positionNode=r.positionNode),p.alphaTest=r.alphaTest,p.alphaMap=r.alphaMap,p.transparent=r.transparent||r.transmission>0,p.isShadowNodeMaterial&&(p.side=r.shadowSide===null?r.side:r.shadowSide,r.depthNode&&r.depthNode.isNode&&(h=p.depthNode,p.depthNode=r.depthNode),r.castShadowNode&&r.castShadowNode.isNode&&(d=p.colorNode,p.colorNode=r.castShadowNode)),r=p}r.transparent===!0&&r.side===js&&r.forceSinglePass===!1?(r.side=Ct,this._handleObjectFunction(e,r,t,s,a,i,u,"backSide"),r.side=No,this._handleObjectFunction(e,r,t,s,a,i,u,c),r.side=js):this._handleObjectFunction(e,r,t,s,a,i,u,c),l!==void 0&&(t.overrideMaterial.positionNode=l),h!==void 0&&(t.overrideMaterial.depthNode=h),d!==void 0&&(t.overrideMaterial.colorNode=d),e.onAfterRender(this,t,s,n,r,i)}_renderObjectDirect(e,t,s,n,r,i,a,u){const c=this._objects.get(e,t,s,n,r,this._currentRenderContext,a,u);c.drawRange=e.geometry.drawRange,c.group=i;const l=this._nodes.needsRefresh(c);l&&(this._nodes.updateBefore(c),this._geometries.updateForRender(c),this._nodes.updateForRender(c),this._bindings.updateForRender(c)),this._pipelines.updateForRender(c),this._currentRenderBundle!==null&&(this.backend.get(this._currentRenderBundle).renderObjects.push(c),c.bundle=this._currentRenderBundle.bundleGroup),this.backend.draw(c,this.info),l&&this._nodes.updateAfter(c)}_createObjectPipeline(e,t,s,n,r,i,a,u){const c=this._objects.get(e,t,s,n,r,this._currentRenderContext,a,u);c.drawRange=e.geometry.drawRange,c.group=i,this._nodes.updateBefore(c),this._geometries.updateForRender(c),this._nodes.updateForRender(c),this._bindings.updateForRender(c),this._pipelines.getForRender(c,this._compilationPromises),this._nodes.updateAfter(c)}get compile(){return this.compileAsync}}class qu{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}clone(){return Object.assign(new this.constructor,this)}}function dA(o){return o+(ts-o%ts)%ts}class gg extends qu{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t}get byteLength(){return dA(this._buffer.byteLength)}get buffer(){return this._buffer}update(){return!0}}class mg extends gg{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let hA=0;class yg extends mg{constructor(e,t){super("UniformBuffer_"+hA++,e?e.value:null),this.nodeUniform=e,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class pA extends mg{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[]}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){const t=this.uniforms.indexOf(e);return t!==-1&&this.uniforms.splice(t,1),this}get values(){return this._values===null&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(e===null){const t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){let e=0;for(let t=0,s=this.uniforms.length;t<s;t++){const n=this.uniforms[t],{boundary:r,itemSize:i}=n,a=e%ts,u=ts-a;a!==0&&u-r<0?e+=ts-a:a%r!==0&&(e+=a%r),n.offset=e/this.bytesPerElement,e+=i*this.bytesPerElement}return Math.ceil(e/ts)*ts}update(){let e=!1;for(const t of this.uniforms)this.updateByType(t)===!0&&(e=!0);return e}updateByType(e){if(e.isNumberUniform)return this.updateNumber(e);if(e.isVector2Uniform)return this.updateVector2(e);if(e.isVector3Uniform)return this.updateVector3(e);if(e.isVector4Uniform)return this.updateVector4(e);if(e.isColorUniform)return this.updateColor(e);if(e.isMatrix3Uniform)return this.updateMatrix3(e);if(e.isMatrix4Uniform)return this.updateMatrix4(e);console.error("THREE.WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1;const s=this.values,n=e.getValue(),r=e.offset,i=e.getType();if(s[r]!==n){const a=this._getBufferForType(i);a[r]=s[r]=n,t=!0}return t}updateVector2(e){let t=!1;const s=this.values,n=e.getValue(),r=e.offset,i=e.getType();if(s[r+0]!==n.x||s[r+1]!==n.y){const a=this._getBufferForType(i);a[r+0]=s[r+0]=n.x,a[r+1]=s[r+1]=n.y,t=!0}return t}updateVector3(e){let t=!1;const s=this.values,n=e.getValue(),r=e.offset,i=e.getType();if(s[r+0]!==n.x||s[r+1]!==n.y||s[r+2]!==n.z){const a=this._getBufferForType(i);a[r+0]=s[r+0]=n.x,a[r+1]=s[r+1]=n.y,a[r+2]=s[r+2]=n.z,t=!0}return t}updateVector4(e){let t=!1;const s=this.values,n=e.getValue(),r=e.offset,i=e.getType();if(s[r+0]!==n.x||s[r+1]!==n.y||s[r+2]!==n.z||s[r+4]!==n.w){const a=this._getBufferForType(i);a[r+0]=s[r+0]=n.x,a[r+1]=s[r+1]=n.y,a[r+2]=s[r+2]=n.z,a[r+3]=s[r+3]=n.w,t=!0}return t}updateColor(e){let t=!1;const s=this.values,n=e.getValue(),r=e.offset;if(s[r+0]!==n.r||s[r+1]!==n.g||s[r+2]!==n.b){const i=this.buffer;i[r+0]=s[r+0]=n.r,i[r+1]=s[r+1]=n.g,i[r+2]=s[r+2]=n.b,t=!0}return t}updateMatrix3(e){let t=!1;const s=this.values,n=e.getValue().elements,r=e.offset;if(s[r+0]!==n[0]||s[r+1]!==n[1]||s[r+2]!==n[2]||s[r+4]!==n[3]||s[r+5]!==n[4]||s[r+6]!==n[5]||s[r+8]!==n[6]||s[r+9]!==n[7]||s[r+10]!==n[8]){const i=this.buffer;i[r+0]=s[r+0]=n[0],i[r+1]=s[r+1]=n[1],i[r+2]=s[r+2]=n[2],i[r+4]=s[r+4]=n[3],i[r+5]=s[r+5]=n[4],i[r+6]=s[r+6]=n[5],i[r+8]=s[r+8]=n[6],i[r+9]=s[r+9]=n[7],i[r+10]=s[r+10]=n[8],t=!0}return t}updateMatrix4(e){let t=!1;const s=this.values,n=e.getValue().elements,r=e.offset;return gA(s,n,r)===!1&&(this.buffer.set(n,r),fA(s,n,r),t=!0),t}_getBufferForType(e){return e==="int"||e==="ivec2"||e==="ivec3"||e==="ivec4"?new Int32Array(this.buffer.buffer):e==="uint"||e==="uvec2"||e==="uvec3"||e==="uvec4"?new Uint32Array(this.buffer.buffer):this.buffer}}function fA(o,e,t){for(let s=0,n=e.length;s<n;s++)o[t+s]=e[s]}function gA(o,e,t){for(let s=0,n=e.length;s<n;s++)if(o[t+s]!==e[s])return!1;return!0}let mA=0;class xg extends pA{constructor(e,t){super(e),this.id=mA++,this.groupNode=t,this.isNodeUniformsGroup=!0}}let yA=0;class xA extends qu{constructor(e,t){super(e),this.id=yA++,this.texture=t,this.version=t?t.version:0,this.store=!1,this.generation=null,this.isSampledTexture=!0}needsBindingsUpdate(e){const{texture:t}=this;return e!==this.generation?(this.generation=e,!0):t.isVideoTexture}update(){const{texture:e,version:t}=this;return t!==e.version?(this.version=e.version,!0):!1}}class Di extends xA{constructor(e,t,s,n=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s,this.access=n}needsBindingsUpdate(e){return this.textureNode.value!==this.texture||super.needsBindingsUpdate(e)}update(){const{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class Tg extends Di{constructor(e,t,s,n=null){super(e,t,s,n),this.isSampledCubeTexture=!0}}class _g extends Di{constructor(e,t,s,n=null){super(e,t,s,n),this.isSampledTexture3D=!0}}const TA={textureDimensions:"textureSize",equals:"equal"},_A={low:"lowp",medium:"mediump",high:"highp"},Qc={swizzleAssign:!0,storageBuffer:!1},Zc=`
|
|
precision highp float;
|
|
precision highp int;
|
|
precision highp sampler2D;
|
|
precision highp sampler3D;
|
|
precision highp samplerCube;
|
|
precision highp sampler2DArray;
|
|
|
|
precision highp usampler2D;
|
|
precision highp usampler3D;
|
|
precision highp usamplerCube;
|
|
precision highp usampler2DArray;
|
|
|
|
precision highp isampler2D;
|
|
precision highp isampler3D;
|
|
precision highp isamplerCube;
|
|
precision highp isampler2DArray;
|
|
|
|
precision lowp sampler2DShadow;
|
|
`;class bA extends dg{constructor(e,t){super(e,t,new rA),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]},this.useComparisonMethod=!0}needsToWorkingColorSpace(e){return e.isVideoTexture===!0&&e.colorSpace!==Dn}getMethod(e){return TA[e]||e}getOutputStructName(){return""}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),n=[];for(const i of t.inputs)n.push(this.getType(i.type)+" "+i.name);return`${this.getType(t.type)} ${t.name}( ${n.join(", ")} ) {
|
|
|
|
${s.vars}
|
|
|
|
${s.code}
|
|
return ${s.result};
|
|
|
|
}`}setupPBO(e){const t=e.value;if(t.pbo===void 0){const s=t.array,n=t.count*t.itemSize,{itemSize:r}=t,i=t.array.constructor.name.toLowerCase().includes("int");let a=i?ha:da;r===2?a=i?pa:Ln:r===3?a=i?Xm:la:r===4&&(a=i?fa:sn);const u={Float32Array:ot,Uint8Array:ys,Uint16Array:Ws,Uint32Array:Le,Int8Array:An,Int16Array:Rn,Int32Array:ze,Uint8ClampedArray:ys},c=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(n/r))));let l=Math.ceil(n/r/c);c*l*r<n&&l++;const d=c*l*r,h=new s.constructor(d);h.set(s,0),t.array=h;const p=new Cm(t.array,c,l,a,u[t.array.constructor.name]||ot);p.needsUpdate=!0,p.isPBOTexture=!0;const f=new wt(p,null,null);f.setPrecision("high"),t.pboNode=f,t.pbo=f.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.label)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&e.node.isTextureNode!==!0&&e.node.isBufferNode!==!0?t.charAt(0)+"_"+e.name:super.getPropertyName(e,t)}generatePBO(e){const{node:t,indexNode:s}=e,n=t.value;if(this.renderer.backend.has(n)){const l=this.renderer.backend.get(n);l.pbo=n.pbo}const r=this.getUniformFromNode(n.pboNode,"texture",this.shaderStage,this.context.label),i=this.getPropertyName(r);this.increaseUsage(s);const a=s.build(this,"uint"),u=this.getDataFromNode(e);let c=u.propertyName;if(c===void 0){const l=this.getVarFromNode(e);c=this.getPropertyName(l);const d=this.getDataFromNode(t);let h=d.propertySizeName;h===void 0&&(h=c+"Size",this.getVarFromNode(t,h,"uint"),this.addLineFlowCode(`${h} = uint( textureSize( ${i}, 0 ).x )`,e),d.propertySizeName=h);const{itemSize:p}=n,f="."+As.join("").slice(0,p),m=`ivec2(${a} % ${h}, ${a} / ${h})`,x=this.generateTextureLoad(null,i,m,null,"0");let N="vec4";n.pbo.type===Le?N="uvec4":n.pbo.type===ze&&(N="ivec4"),this.addLineFlowCode(`${c} = ${N}(${x})${f}`,e),u.propertyName=c}return c}generateTextureLoad(e,t,s,n,r="0"){return n?`texelFetch( ${t}, ivec3( ${s}, ${n} ), ${r} )`:`texelFetch( ${t}, ${s}, ${r} )`}generateTexture(e,t,s,n){return e.isDepthTexture?`texture( ${t}, ${s} ).x`:(n&&(s=`vec3( ${s}, ${n} )`),`texture( ${t}, ${s} )`)}generateTextureLevel(e,t,s,n){return`textureLod( ${t}, ${s}, ${n} )`}generateTextureBias(e,t,s,n){return`texture( ${t}, ${s}, ${n} )`}generateTextureGrad(e,t,s,n){return`textureGrad( ${t}, ${s}, ${n[0]}, ${n[1]} )`}generateTextureCompare(e,t,s,n,r,i=this.shaderStage){if(i==="fragment")return`texture( ${t}, vec3( ${s}, ${n} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}getVars(e){const t=[],s=this.vars[e];if(s!==void 0)for(const n of s)t.push(`${this.getVar(n.type,n.name)};`);return t.join(`
|
|
`)}getUniforms(e){const t=this.uniforms[e],s=[],n={};for(const i of t){let a=null,u=!1;if(i.type==="texture"){const l=i.node.value;let d="";l.isDataTexture===!0&&(l.type===Le?d="u":l.type===ze&&(d="i")),l.compareFunction?a=`sampler2DShadow ${i.name};`:l.isDataArrayTexture===!0||l.isCompressedArrayTexture===!0?a=`${d}sampler2DArray ${i.name};`:a=`${d}sampler2D ${i.name};`}else if(i.type==="cubeTexture")a=`samplerCube ${i.name};`;else if(i.type==="texture3D")a=`sampler3D ${i.name};`;else if(i.type==="buffer"){const l=i.node,d=this.getType(l.bufferType),h=l.bufferCount,p=h>0?h:"";a=`${l.name} {
|
|
${d} ${i.name}[${p}];
|
|
};
|
|
`}else a=`${this.getVectorType(i.type)} ${this.getPropertyName(i,e)};`,u=!0;const c=i.node.precision;if(c!==null&&(a=_A[c]+" "+a),u){a=" "+a;const l=i.groupNode.name;(n[l]||(n[l]=[])).push(a)}else a="uniform "+a,s.push(a)}let r="";for(const i in n){const a=n[i];r+=this._getGLSLUniformStruct(e+"_"+i,a.join(`
|
|
`))+`
|
|
`}return r+=s.join(`
|
|
`),r}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==ze){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const n=s.array;n instanceof Uint32Array||n instanceof Int32Array||(t=t.slice(1))}return t}getAttributes(e){let t="";if(e==="vertex"||e==="compute"){const s=this.getAttributesArray();let n=0;for(const r of s)t+=`layout( location = ${n++} ) in ${r.type} ${r.name};
|
|
`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let n=0;n<s.length;n++){const r=s[n];t.push(`layout( location = ${n} ) out ${r} m${n};`)}return t.join(`
|
|
`)}getStructs(e){const t=[],s=this.structs[e];if(s.length===0)return`layout( location = 0 ) out vec4 fragColor;
|
|
`;for(let n=0,r=s.length;n<r;n++){const i=s[n];let a=`
|
|
`;a+=this.getStructMembers(i),a+=`
|
|
`,t.push(a)}return t.join(`
|
|
|
|
`)}getVaryings(e){let t="";const s=this.varyings;if(e==="vertex"||e==="compute")for(const n of s){e==="compute"&&(n.needsInterpolation=!0);const r=this.getType(n.type),i=r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":"";t+=`${i}${n.needsInterpolation?"out":"/*out*/"} ${r} ${n.name};
|
|
`}else if(e==="fragment"){for(const n of s)if(n.needsInterpolation){const r=this.getType(n.type),i=r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":"";t+=`${i}in ${r} ${n.name};
|
|
`}}for(const n of this.builtins[e])t+=`${n};
|
|
`;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce((s,n)=>s*n,1)}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,s=this.shaderStage){const n=this.extensions[s]||(this.extensions[s]=new Map);n.has(e)===!1&&n.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if(e==="vertex"){const n=this.renderer.backend.extensions;this.object.isBatchedMesh&&n.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(s!==void 0)for(const{name:n,behavior:r}of s.values())t.push(`#extension ${n} : ${r}`);return t.join(`
|
|
`)}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Qc[e];if(t===void 0){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance";break}if(s!==void 0){const n=this.renderer.backend.extensions;n.has(s)&&(n.get(s),t=!0)}Qc[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} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s<e.length;s++){const n=e[s],r=this.getPropertyName(n.attributeNode);t+=`${n.varyingName} = ${r};
|
|
`}return t}_getGLSLUniformStruct(e,t){return`
|
|
layout( std140 ) uniform ${e} {
|
|
${t}
|
|
};`}_getGLSLVertexCode(e){return`#version 300 es
|
|
|
|
${this.getSignature()}
|
|
|
|
// extensions
|
|
${e.extensions}
|
|
|
|
// precision
|
|
${Zc}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// varyings
|
|
${e.varyings}
|
|
|
|
// attributes
|
|
${e.attributes}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
void main() {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// transforms
|
|
${e.transforms}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
gl_PointSize = 1.0;
|
|
|
|
}
|
|
`}_getGLSLFragmentCode(e){return`#version 300 es
|
|
|
|
${this.getSignature()}
|
|
|
|
// precision
|
|
${Zc}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// varyings
|
|
${e.varyings}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
${e.structs}
|
|
|
|
void main() {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
}
|
|
`}buildCode(){const e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){let s=`// code
|
|
|
|
`;s+=this.flowCode[t];const n=this.flowNodes[t],r=n[n.length-1];for(const a of n){const u=this.getFlowData(a),c=a.name;c&&(s.length>0&&(s+=`
|
|
`),s+=` // flow -> ${c}
|
|
`),s+=`${u.code}
|
|
`,a===r&&t!=="compute"&&(s+=`// result
|
|
`,t==="vertex"?(s+="gl_Position = ",s+=`${u.result};`):t==="fragment"&&(a.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${u.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}this.material!==null?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,n=null){const r=super.getUniformFromNode(e,t,s,n),i=this.getDataFromNode(e,s,this.globalCache);let a=i.uniformGPU;if(a===void 0){const u=e.groupNode,c=u.name,l=this.getBindGroupArray(c,s);if(t==="texture")a=new Di(r.name,r.node,u),l.push(a);else if(t==="cubeTexture")a=new Tg(r.name,r.node,u),l.push(a);else if(t==="texture3D")a=new _g(r.name,r.node,u),l.push(a);else if(t==="buffer"){e.name=`NodeBuffer_${e.id}`,r.name=`buffer${e.id}`;const d=new yg(e,u);d.name=e.name,l.push(d),a=d}else{const d=this.uniformGroups[s]||(this.uniformGroups[s]={});let h=d[c];h===void 0&&(h=new xg(s+"_"+c,u),d[c]=h,l.push(h)),a=this.getNodeUniform(r,t),h.addUniform(a)}i.uniformGPU=a}return r}}let ho=null,Ls=null;class bg{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}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(){}copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}isOccluded(){}async resolveTimestampAsync(){}async waitForGPU(){}async hasFeatureAsync(){}hasFeature(){}getMaxAnisotropy(){}getDrawingBufferSize(){return ho=ho||new Ye,this.renderer.getDrawingBufferSize(ho)}setScissorTest(){}getClearColor(){const e=this.renderer;return Ls=Ls||new Ru,e.getClearColor(Ls),Ls.getRGB(Ls,this.renderer.currentColorSpace),Ls}getDomElement(){let e=this.domElement;return e===null&&(e=this.parameters.canvas!==void 0?this.parameters.canvas:ym(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${xl} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let NA=0;class SA{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[this.activeBufferIndex^1]}switchBuffers(){this.activeBufferIndex^=1}}class vA{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:n}=s,r=e.array,i=e.usage||n.STATIC_DRAW,a=e.isInterleavedBufferAttribute?e.data:e,u=s.get(a);let c=u.bufferGPU;c===void 0&&(c=this._createBuffer(n,t,r,i),u.bufferGPU=c,u.bufferType=t,u.version=a.version);let l;if(r instanceof Float32Array)l=n.FLOAT;else if(r instanceof Uint16Array)e.isFloat16BufferAttribute?l=n.HALF_FLOAT:l=n.UNSIGNED_SHORT;else if(r instanceof Int16Array)l=n.SHORT;else if(r instanceof Uint32Array)l=n.UNSIGNED_INT;else if(r instanceof Int32Array)l=n.INT;else if(r instanceof Int8Array)l=n.BYTE;else if(r instanceof Uint8Array)l=n.UNSIGNED_BYTE;else if(r instanceof Uint8ClampedArray)l=n.UNSIGNED_BYTE;else throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);let d={bufferGPU:c,bufferType:t,type:l,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:l===n.INT||l===n.UNSIGNED_INT||e.gpuType===ze,id:NA++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const h=this._createBuffer(n,t,r,i);d=new SA(d,h)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,n=e.array,r=e.isInterleavedBufferAttribute?e.data:e,i=t.get(r),a=i.bufferType,u=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(a,i.bufferGPU),u.length===0)s.bufferSubData(a,0,n);else{for(let c=0,l=u.length;c<l;c++){const d=u[c];s.bufferSubData(a,d.start*n.BYTES_PER_ELEMENT,n,d.start,d.count)}r.clearUpdateRanges()}s.bindBuffer(a,null),i.version=r.version}destroyAttribute(e){const t=this.backend,{gl:s}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);const n=t.get(e);s.deleteBuffer(n.bufferGPU),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,{gl:s}=t,n=e.isInterleavedBufferAttribute?e.data:e,{bufferGPU:r}=t.get(n),i=e.array,a=i.byteLength;s.bindBuffer(s.COPY_READ_BUFFER,r);const u=s.createBuffer();s.bindBuffer(s.COPY_WRITE_BUFFER,u),s.bufferData(s.COPY_WRITE_BUFFER,a,s.STREAM_READ),s.copyBufferSubData(s.COPY_READ_BUFFER,s.COPY_WRITE_BUFFER,0,0,a),await t.utils._clientWaitAsync();const c=new e.array.constructor(i.length);return s.bindBuffer(s.COPY_WRITE_BUFFER,u),s.getBufferSubData(s.COPY_WRITE_BUFFER,0,c),s.deleteBuffer(u),s.bindBuffer(s.COPY_READ_BUFFER,null),s.bindBuffer(s.COPY_WRITE_BUFFER,null),c.buffer}_createBuffer(e,t,s,n){const r=e.createBuffer();return e.bindBuffer(t,r),e.bufferData(t,s,n),e.bindBuffer(t,null),r}}let Jc=!1,po,Sn;class AA{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.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},Jc===!1&&(this._init(this.gl),Jc=!0)}_init(e){po={[Gs]:e.FUNC_ADD,[Ul]:e.FUNC_SUBTRACT,[Fl]:e.FUNC_REVERSE_SUBTRACT},Sn={[$l]:e.ZERO,[Wl]:e.ONE,[zl]:e.SRC_COLOR,[kl]:e.SRC_ALPHA,[Ol]:e.SRC_ALPHA_SATURATE,[Gl]:e.DST_COLOR,[Vl]:e.DST_ALPHA,[Il]:e.ONE_MINUS_SRC_COLOR,[Ll]:e.ONE_MINUS_SRC_ALPHA,[Dl]:e.ONE_MINUS_DST_COLOR,[Pl]:e.ONE_MINUS_DST_ALPHA}}enable(e){const{enabled:t}=this;t[e]!==!0&&(this.gl.enable(e),t[e]=!0)}disable(e){const{enabled:t}=this;t[e]!==!1&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){const{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){const{gl:t}=this;e!==xm?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===Tm?t.cullFace(t.BACK):e===_m?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){const{currentLineWidth:t,gl:s}=this;e!==t&&(s.lineWidth(e),this.currentLineWidth=e)}setBlending(e,t,s,n,r,i,a,u){const{gl:c}=this;if(e===en){this.currentBlendingEnabled===!0&&(this.disable(c.BLEND),this.currentBlendingEnabled=!1);return}if(this.currentBlendingEnabled===!1&&(this.enable(c.BLEND),this.currentBlendingEnabled=!0),e!==Hl){if(e!==this.currentBlending||u!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==Gs||this.currentBlendEquationAlpha!==Gs)&&(c.blendEquation(c.FUNC_ADD),this.currentBlendEquation=Gs,this.currentBlendEquationAlpha=Gs),u)switch(e){case Ys:c.blendFuncSeparate(c.ONE,c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case qr:c.blendFunc(c.ONE,c.ONE);break;case Hr:c.blendFuncSeparate(c.ZERO,c.ONE_MINUS_SRC_COLOR,c.ZERO,c.ONE);break;case $r:c.blendFuncSeparate(c.ZERO,c.SRC_COLOR,c.ZERO,c.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",e);break}else switch(e){case Ys:c.blendFuncSeparate(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case qr:c.blendFunc(c.SRC_ALPHA,c.ONE);break;case Hr:c.blendFuncSeparate(c.ZERO,c.ONE_MINUS_SRC_COLOR,c.ZERO,c.ONE);break;case $r:c.blendFunc(c.ZERO,c.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",e);break}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=u}return}r=r||t,i=i||s,a=a||n,(t!==this.currentBlendEquation||r!==this.currentBlendEquationAlpha)&&(c.blendEquationSeparate(po[t],po[r]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=r),(s!==this.currentBlendSrc||n!==this.currentBlendDst||i!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(c.blendFuncSeparate(Sn[s],Sn[n],Sn[i],Sn[a]),this.currentBlendSrc=s,this.currentBlendDst=n,this.currentBlendSrcAlpha=i,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){const{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){const{gl:t}=this;switch(e){case Jl:t.depthFunc(t.NEVER);break;case Zl:t.depthFunc(t.ALWAYS);break;case Ql:t.depthFunc(t.LESS);break;case jl:t.depthFunc(t.LEQUAL);break;case Yl:t.depthFunc(t.EQUAL);break;case Xl:t.depthFunc(t.GEQUAL);break;case Kl:t.depthFunc(t.GREATER);break;case ql:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}setStencilTest(e){const{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,s){(this.currentStencilFunc!==e||this.currentStencilRef!==t||this.currentStencilFuncMask!==s)&&(this.gl.stencilFunc(e,t,s),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=s)}setStencilOp(e,t,s){(this.currentStencilFail!==e||this.currentStencilZFail!==t||this.currentStencilZPass!==s)&&(this.gl.stencilOp(e,t,s),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=s)}setMaterial(e,t,s){const{gl:n}=this;e.side===js?this.disable(n.CULL_FACE):this.enable(n.CULL_FACE);let r=e.side===Ct;t&&(r=!r),this.setFlipSided(r),e.blending===Ys&&e.transparent===!1?this.setBlending(en):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);const i=e.stencilWrite;if(this.setStencilTest(i),i&&(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),e.alphaToCoverage===!0&&this.backend.renderer.samples>1?this.enable(n.SAMPLE_ALPHA_TO_COVERAGE):this.disable(n.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s)for(let u=0;u<8;u++)u<s?this.enable(12288+u):this.disable(12288+u)}setPolygonOffset(e,t,s){const{gl:n}=this;e?(this.enable(n.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==s)&&(n.polygonOffset(t,s),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=s)):this.disable(n.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e?(this.gl.useProgram(e),this.currentProgram=e,!0):!1}bindFramebuffer(e,t){const{gl:s,currentBoundFramebuffers:n}=this;return n[e]!==t?(s.bindFramebuffer(e,t),n[e]=t,e===s.DRAW_FRAMEBUFFER&&(n[s.FRAMEBUFFER]=t),e===s.FRAMEBUFFER&&(n[s.DRAW_FRAMEBUFFER]=t),!0):!1}drawBuffers(e,t){const{gl:s}=this;let n=[],r=!1;if(e.textures!==null){n=this.currentDrawbuffers.get(t),n===void 0&&(n=[],this.currentDrawbuffers.set(t,n));const i=e.textures;if(n.length!==i.length||n[0]!==s.COLOR_ATTACHMENT0){for(let a=0,u=i.length;a<u;a++)n[a]=s.COLOR_ATTACHMENT0+a;n.length=i.length,r=!0}}else n[0]!==s.BACK&&(n[0]=s.BACK,r=!0);r&&s.drawBuffers(n)}activeTexture(e){const{gl:t,currentTextureSlot:s,maxTextures:n}=this;e===void 0&&(e=t.TEXTURE0+n-1),s!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,s){const{gl:n,currentTextureSlot:r,currentBoundTextures:i,maxTextures:a}=this;s===void 0&&(r===null?s=n.TEXTURE0+a-1:s=r);let u=i[s];u===void 0&&(u={type:void 0,texture:void 0},i[s]=u),(u.type!==e||u.texture!==t)&&(r!==s&&(n.activeTexture(s),this.currentTextureSlot=s),n.bindTexture(e,t),u.type=e,u.texture=t)}bindBufferBase(e,t,s){const{gl:n}=this,r=`${e}-${t}`;return this.currentBoundBufferBases[r]!==s?(n.bindBufferBase(e,t,s),this.currentBoundBufferBases[r]=s,!0):!1}unbindTexture(){const{gl:e,currentTextureSlot:t,currentBoundTextures:s}=this,n=s[t];n!==void 0&&n.type!==void 0&&(e.bindTexture(n.type,null),n.type=void 0,n.texture=void 0)}}class RA{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=Dn){const{gl:s,extensions:n}=this;let r;if(e===ys)return s.UNSIGNED_BYTE;if(e===bm)return s.UNSIGNED_SHORT_4_4_4_4;if(e===Nm)return s.UNSIGNED_SHORT_5_5_5_1;if(e===ed)return s.UNSIGNED_INT_5_9_9_9_REV;if(e===An)return s.BYTE;if(e===Rn)return s.SHORT;if(e===Ws)return s.UNSIGNED_SHORT;if(e===ze)return s.INT;if(e===Le)return s.UNSIGNED_INT;if(e===ot)return s.FLOAT;if(e===pt)return s.HALF_FLOAT;if(e===Sm)return s.ALPHA;if(e===la)return s.RGB;if(e===sn)return s.RGBA;if(e===vm)return s.LUMINANCE;if(e===Am)return s.LUMINANCE_ALPHA;if(e===ai)return s.DEPTH_COMPONENT;if(e===oi)return s.DEPTH_STENCIL;if(e===da)return s.RED;if(e===ha)return s.RED_INTEGER;if(e===Ln)return s.RG;if(e===pa)return s.RG_INTEGER;if(e===fa)return s.RGBA_INTEGER;if(e===Li||e===Pr||e===Dr||e===Lr)if(t===q)if(r=n.get("WEBGL_compressed_texture_s3tc_srgb"),r!==null){if(e===Li)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===Pr)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===Dr)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===Lr)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(r=n.get("WEBGL_compressed_texture_s3tc"),r!==null){if(e===Li)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===Pr)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===Dr)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Lr)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(e===Qu||e===Zu||e===Ju||e===ec)if(r=n.get("WEBGL_compressed_texture_pvrtc"),r!==null){if(e===Qu)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===Zu)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===Ju)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===ec)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(e===tc||e===vo||e===Ao)if(r=n.get("WEBGL_compressed_texture_etc"),r!==null){if(e===tc||e===vo)return t===q?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(e===Ao)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(e===Ro||e===Co||e===Eo||e===wo||e===Mo||e===Bo||e===Fo||e===Uo||e===Po||e===Do||e===Lo||e===Io||e===Vo||e===Go)if(r=n.get("WEBGL_compressed_texture_astc"),r!==null){if(e===Ro)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===Co)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===Eo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===wo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===Mo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===Bo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===Fo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===Uo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===Po)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===Do)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===Lo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===Io)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===Vo)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===Go)return t===q?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(e===Ii)if(r=n.get("EXT_texture_compression_bptc"),r!==null){if(e===Ii)return t===q?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}else return null;if(e===Rm||e===sc||e===nc||e===rc)if(r=n.get("EXT_texture_compression_rgtc"),r!==null){if(e===Ii)return r.COMPRESSED_RED_RGTC1_EXT;if(e===sc)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===nc)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===rc)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return e===ui?s.UNSIGNED_INT_24_8:s[e]!==void 0?s[e]:null}_clientWaitAsync(){const{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((s,n)=>{function r(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED){e.deleteSync(t),n();return}if(i===e.TIMEOUT_EXPIRED){requestAnimationFrame(r);return}e.deleteSync(t),s()}r()})}}let el=!1,wr,fo,tl;class CA{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},el===!1&&(this._init(this.gl),el=!0)}_init(e){wr={[li]:e.REPEAT,[ca]:e.CLAMP_TO_EDGE,[ci]:e.MIRRORED_REPEAT},fo={[bt]:e.NEAREST,[So]:e.NEAREST_MIPMAP_NEAREST,[Xs]:e.NEAREST_MIPMAP_LINEAR,[ft]:e.LINEAR,[_o]:e.LINEAR_MIPMAP_NEAREST,[ms]:e.LINEAR_MIPMAP_LINEAR},tl={[Bl]:e.NEVER,[Ml]:e.ALWAYS,[ua]:e.LESS,[wl]:e.LEQUAL,[El]:e.EQUAL,[Cl]:e.GEQUAL,[Rl]:e.GREATER,[Al]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===bt||e===So||e===Xs?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return e.isCubeTexture===!0?s=t.TEXTURE_CUBE_MAP:e.isDataArrayTexture===!0||e.isCompressedArrayTexture===!0?s=t.TEXTURE_2D_ARRAY:e.isData3DTexture===!0?s=t.TEXTURE_3D:s=t.TEXTURE_2D,s}getInternalFormat(e,t,s,n,r=!1){const{gl:i,extensions:a}=this;if(e!==null){if(i[e]!==void 0)return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let u=t;return t===i.RED&&(s===i.FLOAT&&(u=i.R32F),s===i.HALF_FLOAT&&(u=i.R16F),s===i.UNSIGNED_BYTE&&(u=i.R8),s===i.UNSIGNED_SHORT&&(u=i.R16),s===i.UNSIGNED_INT&&(u=i.R32UI),s===i.BYTE&&(u=i.R8I),s===i.SHORT&&(u=i.R16I),s===i.INT&&(u=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(u=i.R8UI),s===i.UNSIGNED_SHORT&&(u=i.R16UI),s===i.UNSIGNED_INT&&(u=i.R32UI),s===i.BYTE&&(u=i.R8I),s===i.SHORT&&(u=i.R16I),s===i.INT&&(u=i.R32I)),t===i.RG&&(s===i.FLOAT&&(u=i.RG32F),s===i.HALF_FLOAT&&(u=i.RG16F),s===i.UNSIGNED_BYTE&&(u=i.RG8),s===i.UNSIGNED_SHORT&&(u=i.RG16),s===i.UNSIGNED_INT&&(u=i.RG32UI),s===i.BYTE&&(u=i.RG8I),s===i.SHORT&&(u=i.RG16I),s===i.INT&&(u=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(u=i.RG8UI),s===i.UNSIGNED_SHORT&&(u=i.RG16UI),s===i.UNSIGNED_INT&&(u=i.RG32UI),s===i.BYTE&&(u=i.RG8I),s===i.SHORT&&(u=i.RG16I),s===i.INT&&(u=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(u=i.RGB32F),s===i.HALF_FLOAT&&(u=i.RGB16F),s===i.UNSIGNED_BYTE&&(u=i.RGB8),s===i.UNSIGNED_SHORT&&(u=i.RGB16),s===i.UNSIGNED_INT&&(u=i.RGB32UI),s===i.BYTE&&(u=i.RGB8I),s===i.SHORT&&(u=i.RGB16I),s===i.INT&&(u=i.RGB32I),s===i.UNSIGNED_BYTE&&(u=n===q&&r===!1?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(u=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(u=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(u=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(u=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(u=i.RGB8UI),s===i.UNSIGNED_SHORT&&(u=i.RGB16UI),s===i.UNSIGNED_INT&&(u=i.RGB32UI),s===i.BYTE&&(u=i.RGB8I),s===i.SHORT&&(u=i.RGB16I),s===i.INT&&(u=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(u=i.RGBA32F),s===i.HALF_FLOAT&&(u=i.RGBA16F),s===i.UNSIGNED_BYTE&&(u=i.RGBA8),s===i.UNSIGNED_SHORT&&(u=i.RGBA16),s===i.UNSIGNED_INT&&(u=i.RGBA32UI),s===i.BYTE&&(u=i.RGBA8I),s===i.SHORT&&(u=i.RGBA16I),s===i.INT&&(u=i.RGBA32I),s===i.UNSIGNED_BYTE&&(u=n===q&&r===!1?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(u=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(u=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(u=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(u=i.RGBA16UI),s===i.UNSIGNED_INT&&(u=i.RGBA32UI),s===i.BYTE&&(u=i.RGBA8I),s===i.SHORT&&(u=i.RGBA16I),s===i.INT&&(u=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(u=i.DEPTH24_STENCIL8),s===i.FLOAT&&(u=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(u=i.DEPTH24_STENCIL8),(u===i.R16F||u===i.R32F||u===i.RG16F||u===i.RG32F||u===i.RGBA16F||u===i.RGBA32F)&&a.get("EXT_color_buffer_float"),u}setTextureParameters(e,t){const{gl:s,extensions:n,backend:r}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,wr[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,wr[t.wrapT]),(e===s.TEXTURE_3D||e===s.TEXTURE_2D_ARRAY)&&s.texParameteri(e,s.TEXTURE_WRAP_R,wr[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,fo[t.magFilter]);const i=t.mipmaps!==void 0&&t.mipmaps.length>0,a=t.minFilter===ft&&i?ms:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,fo[a]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,tl[t.compareFunction])),n.has("EXT_texture_filter_anisotropic")===!0){if(t.magFilter===bt||t.minFilter!==Xs&&t.minFilter!==ms||t.type===ot&&n.has("OES_texture_float_linear")===!1)return;if(t.anisotropy>1){const u=n.get("EXT_texture_filter_anisotropic");s.texParameterf(e,u.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,r.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:n}=this,r=this.getGLTextureType(e);let i=n[r];i===void 0&&(i=t.createTexture(),s.state.bindTexture(r,i),t.texParameteri(r,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(r,t.TEXTURE_MAG_FILTER,t.NEAREST),n[r]=i),s.set(e,{textureGPU:i,glTextureType:r,isDefault:!0})}createTexture(e,t){const{gl:s,backend:n}=this,{levels:r,width:i,height:a,depth:u}=t,c=n.utils.convert(e.format,e.colorSpace),l=n.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,c,l,e.colorSpace,e.isVideoTexture),h=s.createTexture(),p=this.getGLTextureType(e);n.state.bindTexture(p,h),this.setTextureParameters(p,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,d,i,a,u):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,d,i,a,u):e.isVideoTexture||s.texStorage2D(p,r,d,i,a),n.set(e,{textureGPU:h,glTextureType:p,glFormat:c,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:n}=this,{textureGPU:r,glTextureType:i,glFormat:a,glType:u}=n.get(t),{width:c,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),n.state.bindTexture(i,r),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,c,l,a,u,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),n.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:n,height:r}=t,{textureGPU:i,glTextureType:a,glFormat:u,glType:c,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||i===void 0)return;const d=h=>h.isDataTexture?h.image.data:typeof HTMLImageElement<"u"&&h instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&h instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&h instanceof ImageBitmap||h instanceof OffscreenCanvas?h:h.data;if(this.backend.state.bindTexture(a,i),this.setTextureParameters(a,e),e.isCompressedTexture){const h=e.mipmaps,p=t.image;for(let f=0;f<h.length;f++){const m=h[f];e.isCompressedArrayTexture?e.format!==s.RGBA?u!==null?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,f,0,0,0,m.width,m.height,p.depth,u,m.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,f,0,0,0,m.width,m.height,p.depth,u,c,m.data):u!==null?s.compressedTexSubImage2D(s.TEXTURE_2D,f,0,0,m.width,m.height,u,m.data):console.warn("Unsupported compressed texture format")}}else if(e.isCubeTexture){const h=t.images;for(let p=0;p<6;p++){const f=d(h[p]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,0,0,n,r,u,c,f)}}else if(e.isDataArrayTexture){const h=t.image;s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,h.width,h.height,h.depth,u,c,h.data)}else if(e.isData3DTexture){const h=t.image;s.texSubImage3D(s.TEXTURE_3D,0,0,0,0,h.width,h.height,h.depth,u,c,h.data)}else if(e.isVideoTexture)e.update(),s.texImage2D(a,0,l,u,c,t.image);else{const h=d(t.image);s.texSubImage2D(a,0,0,0,n,r,u,c,h)}}generateMipmaps(e){const{gl:t,backend:s}=this,{textureGPU:n,glTextureType:r}=s.get(e);s.state.bindTexture(r,n),t.generateMipmap(r)}deallocateRenderBuffers(e){const{gl:t,backend:s}=this;if(e){const n=s.get(e);if(n.renderBufferStorageSetup=void 0,n.framebuffers){for(const r in n.framebuffers)t.deleteFramebuffer(n.framebuffers[r]);delete n.framebuffers}if(n.depthRenderbuffer&&(t.deleteRenderbuffer(n.depthRenderbuffer),delete n.depthRenderbuffer),n.stencilRenderbuffer&&(t.deleteRenderbuffer(n.stencilRenderbuffer),delete n.stencilRenderbuffer),n.msaaFrameBuffer&&(t.deleteFramebuffer(n.msaaFrameBuffer),delete n.msaaFrameBuffer),n.msaaRenderbuffers){for(let r=0;r<n.msaaRenderbuffers.length;r++)t.deleteRenderbuffer(n.msaaRenderbuffers[r]);delete n.msaaRenderbuffers}}}destroyTexture(e){const{gl:t,backend:s}=this,{textureGPU:n,renderTarget:r}=s.get(e);this.deallocateRenderBuffers(r),t.deleteTexture(n),s.delete(e)}copyTextureToTexture(e,t,s=null,n=null,r=0){const{gl:i,backend:a}=this,{state:u}=this.backend,{textureGPU:c,glTextureType:l,glType:d,glFormat:h}=a.get(t);let p,f,m,x,N,v;s!==null?(p=s.max.x-s.min.x,f=s.max.y-s.min.y,m=s.min.x,x=s.min.y):(p=e.image.width,f=e.image.height,m=0,x=0),n!==null?(N=n.x,v=n.y):(N=0,v=0),u.bindTexture(l,c),i.pixelStorei(i.UNPACK_ALIGNMENT,t.unpackAlignment),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,t.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,t.unpackAlignment);const w=i.getParameter(i.UNPACK_ROW_LENGTH),B=i.getParameter(i.UNPACK_IMAGE_HEIGHT),F=i.getParameter(i.UNPACK_SKIP_PIXELS),L=i.getParameter(i.UNPACK_SKIP_ROWS),I=i.getParameter(i.UNPACK_SKIP_IMAGES),G=e.isCompressedTexture?e.mipmaps[r]:e.image;if(i.pixelStorei(i.UNPACK_ROW_LENGTH,G.width),i.pixelStorei(i.UNPACK_IMAGE_HEIGHT,G.height),i.pixelStorei(i.UNPACK_SKIP_PIXELS,m),i.pixelStorei(i.UNPACK_SKIP_ROWS,x),e.isRenderTargetTexture||e.isDepthTexture){const X=a.get(e),ie=a.get(t),Z=a.get(X.renderTarget),Qe=a.get(ie.renderTarget),Ze=Z.framebuffers[X.cacheKey],Dt=Qe.framebuffers[ie.cacheKey];u.bindFramebuffer(i.READ_FRAMEBUFFER,Ze),u.bindFramebuffer(i.DRAW_FRAMEBUFFER,Dt);let Ms=i.COLOR_BUFFER_BIT;e.isDepthTexture&&(Ms=i.DEPTH_BUFFER_BIT),i.blitFramebuffer(m,x,p,f,N,v,p,f,Ms,i.NEAREST),u.bindFramebuffer(i.READ_FRAMEBUFFER,null),u.bindFramebuffer(i.DRAW_FRAMEBUFFER,null)}else e.isDataTexture?i.texSubImage2D(i.TEXTURE_2D,r,N,v,p,f,h,d,G.data):e.isCompressedTexture?i.compressedTexSubImage2D(i.TEXTURE_2D,r,N,v,G.width,G.height,h,G.data):i.texSubImage2D(i.TEXTURE_2D,r,N,v,p,f,h,d,G);i.pixelStorei(i.UNPACK_ROW_LENGTH,w),i.pixelStorei(i.UNPACK_IMAGE_HEIGHT,B),i.pixelStorei(i.UNPACK_SKIP_PIXELS,F),i.pixelStorei(i.UNPACK_SKIP_ROWS,L),i.pixelStorei(i.UNPACK_SKIP_IMAGES,I),r===0&&t.generateMipmaps&&i.generateMipmap(i.TEXTURE_2D),u.unbindTexture()}copyFramebufferToTexture(e,t,s){const{gl:n}=this,{state:r}=this.backend,{textureGPU:i}=this.backend.get(e),{x:a,y:u,z:c,w:l}=s,d=e.isDepthTexture===!0||t.renderTarget&&t.renderTarget.samples>0,h=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(d){const p=a!==0||u!==0;let f,m;if(e.isDepthTexture===!0?(f=n.DEPTH_BUFFER_BIT,m=n.DEPTH_ATTACHMENT,t.stencil&&(f|=n.STENCIL_BUFFER_BIT)):(f=n.COLOR_BUFFER_BIT,m=n.COLOR_ATTACHMENT0),p){const x=this.backend.get(t.renderTarget),N=x.framebuffers[t.getCacheKey()],v=x.msaaFrameBuffer;r.bindFramebuffer(n.DRAW_FRAMEBUFFER,N),r.bindFramebuffer(n.READ_FRAMEBUFFER,v);const w=h-u-l;n.blitFramebuffer(a,w,a+c,w+l,a,w,a+c,w+l,f,n.NEAREST),r.bindFramebuffer(n.READ_FRAMEBUFFER,N),r.bindTexture(n.TEXTURE_2D,i),n.copyTexSubImage2D(n.TEXTURE_2D,0,0,0,a,w,c,l),r.unbindTexture()}else{const x=n.createFramebuffer();r.bindFramebuffer(n.DRAW_FRAMEBUFFER,x),n.framebufferTexture2D(n.DRAW_FRAMEBUFFER,m,n.TEXTURE_2D,i,0),n.blitFramebuffer(0,0,c,l,0,0,c,l,f,n.NEAREST),n.deleteFramebuffer(x)}}else r.bindTexture(n.TEXTURE_2D,i),n.copyTexSubImage2D(n.TEXTURE_2D,0,0,0,a,h-l-u,c,l),r.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,n=t.renderTarget,{samples:r,depthTexture:i,depthBuffer:a,stencilBuffer:u,width:c,height:l}=n;if(s.bindRenderbuffer(s.RENDERBUFFER,e),a&&!u){let d=s.DEPTH_COMPONENT24;r>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(d=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,d,c,l)):s.renderbufferStorage(s.RENDERBUFFER,d,c,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else a&&u&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,c,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,c,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,n,r,i){const{backend:a,gl:u}=this,{textureGPU:c,glFormat:l,glType:d}=this.backend.get(e),h=u.createFramebuffer();u.bindFramebuffer(u.READ_FRAMEBUFFER,h);const p=e.isCubeTexture?u.TEXTURE_CUBE_MAP_POSITIVE_X+i:u.TEXTURE_2D;u.framebufferTexture2D(u.READ_FRAMEBUFFER,u.COLOR_ATTACHMENT0,p,c,0);const f=this._getTypedArrayType(d),m=this._getBytesPerTexel(d,l),N=n*r*m,v=u.createBuffer();u.bindBuffer(u.PIXEL_PACK_BUFFER,v),u.bufferData(u.PIXEL_PACK_BUFFER,N,u.STREAM_READ),u.readPixels(t,s,n,r,l,d,0),u.bindBuffer(u.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();const w=new f(N/f.BYTES_PER_ELEMENT);return u.bindBuffer(u.PIXEL_PACK_BUFFER,v),u.getBufferSubData(u.PIXEL_PACK_BUFFER,0,w),u.bindBuffer(u.PIXEL_PACK_BUFFER,null),u.deleteFramebuffer(h),w}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(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 new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let n=0;if(e===s.UNSIGNED_BYTE&&(n=1),(e===s.UNSIGNED_SHORT_4_4_4_4||e===s.UNSIGNED_SHORT_5_5_5_1||e===s.UNSIGNED_SHORT_5_6_5||e===s.UNSIGNED_SHORT||e===s.HALF_FLOAT)&&(n=2),(e===s.UNSIGNED_INT||e===s.FLOAT)&&(n=4),t===s.RGBA)return n*4;if(t===s.RGB)return n*3;if(t===s.ALPHA)return n}}class EA{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 t===void 0&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class wA{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(this.maxAnisotropy!==null)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(t.has("EXT_texture_filter_anisotropic")===!0){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const sl={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"};class MA{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){const{gl:s,mode:n,object:r,type:i,info:a,index:u}=this;u!==0?s.drawElements(n,t,i,e):s.drawArrays(n,e,t),a.update(r,t,n,1)}renderInstances(e,t,s){const{gl:n,mode:r,type:i,index:a,object:u,info:c}=this;s!==0&&(a!==0?n.drawElementsInstanced(r,t,i,e,s):n.drawArraysInstanced(r,e,t,s),c.update(u,t,r,s))}renderMultiDraw(e,t,s){const{extensions:n,mode:r,object:i,info:a}=this;if(s===0)return;const u=n.get("WEBGL_multi_draw");if(u===null)for(let c=0;c<s;c++)this.render(e[c],t[c]);else{this.index!==0?u.multiDrawElementsWEBGL(r,t,0,this.type,e,0,s):u.multiDrawArraysWEBGL(r,e,0,t,0,s);let c=0;for(let l=0;l<s;l++)c+=t[l];a.update(i,c,r,1)}}renderMultiDrawInstances(e,t,s,n){const{extensions:r,mode:i,object:a,info:u}=this;if(s===0)return;const c=r.get("WEBGL_multi_draw");if(c===null)for(let l=0;l<s;l++)this.renderInstances(e[l],t[l],n[l]);else{this.index!==0?c.multiDrawElementsInstancedWEBGL(i,t,0,this.type,e,0,n,0,s):c.multiDrawArraysInstancedWEBGL(i,e,0,t,0,n,0,s);let l=0;for(let d=0;d<s;d++)l+=t[d]*n[d];u.update(a,l,i,1)}}}class nl extends bg{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.trackTimestamp=e.trackTimestamp===!0,this._currentContext=null,this._knownBindings=new WeakSet}init(e){super.init(e);const t=this.parameters,s=t.context!==void 0?t.context:e.domElement.getContext("webgl2");function n(r){r.preventDefault();const i={api:"WebGL",message:r.statusMessage||"Unknown reason",reason:null,originalEvent:r};e.onDeviceLost(i)}this._onContextLost=n,e.domElement.addEventListener("webglcontextlost",n,!1),this.gl=s,this.extensions=new EA(this),this.capabilities=new wA(this),this.attributeUtils=new vA(this),this.textureUtils=new CA(this),this.bufferRenderer=new MA(this),this.state=new AA(this),this.utils=new RA(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.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile")}get coordinateSystem(){return Pn}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}async waitForGPU(){await this.utils._clientWaitAsync()}initTimestampQuery(e){if(!this.disjoint||!this.trackTimestamp)return;const t=this.get(e);if(this.queryRunning){t.queryQueue||(t.queryQueue=[]),t.queryQueue.push(e);return}t.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),t.activeQuery=null),t.activeQuery=this.gl.createQuery(),t.activeQuery!==null&&(this.gl.beginQuery(this.disjoint.TIME_ELAPSED_EXT,t.activeQuery),this.queryRunning=!0)}prepareTimestampBuffer(e){if(!this.disjoint||!this.trackTimestamp)return;const t=this.get(e);if(t.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),t.gpuQueries||(t.gpuQueries=[]),t.gpuQueries.push({query:t.activeQuery}),t.activeQuery=null,this.queryRunning=!1,t.queryQueue&&t.queryQueue.length>0)){const s=t.queryQueue.shift();this.initTimestampQuery(s)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let n=0;n<s.gpuQueries.length;n++){const r=s.gpuQueries[n],i=this.gl.getQueryParameter(r.query,this.gl.QUERY_RESULT_AVAILABLE),a=this.gl.getParameter(this.disjoint.GPU_DISJOINT_EXT);if(i&&!a){const u=this.gl.getQueryParameter(r.query,this.gl.QUERY_RESULT),c=Number(u)/1e6;this.gl.deleteQuery(r.query),s.gpuQueries.splice(n,1),n--,this.renderer.info.updateTimestamp(t,c)}}}getContext(){return this.gl}beginRender(e){const{gl:t}=this,s=this.get(e);if(this.initTimestampQuery(e),s.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1),e.viewport?this.updateViewport(e):t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight),e.scissor){const{x:r,y:i,width:a,height:u}=e.scissorValue;t.scissor(r,e.height-u-i,a,u)}const n=e.occlusionQueryCount;n>0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(n),s.occlusionQueryObjects=new Array(n),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,n=this.get(e),r=n.previousContext,i=e.occlusionQueryCount;i>0&&(i>n.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const a=e.textures;if(a!==null)for(let u=0;u<a.length;u++){const c=a[u];c.generateMipmaps&&this.generateMipmaps(c)}if(this._currentContext=r,e.textures!==null&&e.renderTarget){const u=this.get(e.renderTarget),{samples:c}=e.renderTarget;if(c>0){const l=u.framebuffers[e.getCacheKey()],d=t.COLOR_BUFFER_BIT,h=u.msaaFrameBuffer,p=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,h),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,l);for(let f=0;f<p.length;f++)if(e.scissor){const{x:m,y:x,width:N,height:v}=e.scissorValue,w=e.height-v-x;t.blitFramebuffer(m,w,m+N,w+v,m,w,m+N,w+v,d,t.NEAREST),t.invalidateSubFramebuffer(t.READ_FRAMEBUFFER,u.invalidationArray,m,w,N,v)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,d,t.NEAREST),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,u.invalidationArray)}}r!==null&&(this._setFramebuffer(r),r.viewport?this.updateViewport(r):t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)),this.prepareTimestampBuffer(e)}resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueries:s,currentOcclusionQueryObjects:n}=t;if(s&&n){const r=new WeakSet,{gl:i}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;const a=()=>{let u=0;for(let c=0;c<s.length;c++){const l=s[c];l!==null&&i.getQueryParameter(l,i.QUERY_RESULT_AVAILABLE)&&(i.getQueryParameter(l,i.QUERY_RESULT)>0&&r.add(n[c]),s[c]=null,i.deleteQuery(l),u++)}u<s.length?requestAnimationFrame(a):t.occluded=r};a()}}isOccluded(e,t){const s=this.get(e);return s.occluded&&s.occluded.has(t)}updateViewport(e){const t=this.gl,{x:s,y:n,width:r,height:i}=e.viewportValue;t.viewport(s,e.height-i-n,r,i)}setScissorTest(e){const t=this.gl;e?t.enable(t.SCISSOR_TEST):t.disable(t.SCISSOR_TEST)}clear(e,t,s,n=null,r=!0){const{gl:i}=this;if(n===null){const u=this.getClearColor();u.r*=u.a,u.g*=u.a,u.b*=u.a,n={textures:null,clearColorValue:u}}let a=0;if(e&&(a|=i.COLOR_BUFFER_BIT),t&&(a|=i.DEPTH_BUFFER_BIT),s&&(a|=i.STENCIL_BUFFER_BIT),a!==0){let u;if(n.clearColorValue?u=n.clearColorValue:(u=this.getClearColor(),u.r*=u.a,u.g*=u.a,u.b*=u.a),t&&this.state.setDepthMask(!0),n.textures===null)i.clearColor(u.r,u.g,u.b,u.a),i.clear(a);else{if(r&&this._setFramebuffer(n),e)for(let c=0;c<n.textures.length;c++)i.clearBufferfv(i.COLOR,c,[u.r,u.g,u.b,u.a]);t&&s?i.clearBufferfi(i.DEPTH_STENCIL,0,1,0):t?i.clearBufferfv(i.DEPTH,0,[1]):s&&i.clearBufferiv(i.STENCIL,0,[0])}}}beginCompute(e){const{state:t,gl:s}=this;t.bindFramebuffer(s.FRAMEBUFFER,null),this.initTimestampQuery(e)}compute(e,t,s,n){const{state:r,gl:i}=this;this.discard===!1&&(i.enable(i.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:a,transformBuffers:u,attributes:c}=this.get(n),l=this._getVaoKey(null,c),d=this.vaoCache[l];d===void 0?this._createVao(null,c):i.bindVertexArray(d),r.useProgram(a),this._bindUniforms(s);const h=this._getTransformFeedback(u);i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,h),i.beginTransformFeedback(i.POINTS),c[0].isStorageInstancedBufferAttribute?i.drawArraysInstanced(i.POINTS,0,1,t.count):i.drawArrays(i.POINTS,0,t.count),i.endTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null);for(let p=0;p<u.length;p++){const f=u[p];f.pbo&&this.textureUtils.copyBufferToTexture(f.transformBuffer,f.pbo),f.switchBuffers()}}finishCompute(e){const t=this.gl;this.discard=!1,t.disable(t.RASTERIZER_DISCARD),this.prepareTimestampBuffer(e),this._currentContext&&this._setFramebuffer(this._currentContext)}draw(e){const{object:t,pipeline:s,material:n,context:r,hardwareClippingPlanes:i}=e,{programGPU:a}=this.get(s),{gl:u,state:c}=this,l=this.get(r),d=e.getDrawParameters();if(d===null)return;this._bindUniforms(e.getBindings());const h=t.isMesh&&t.matrixWorld.determinant()<0;c.setMaterial(n,h,i),c.useProgram(a);const p=this.get(e);let f=p.staticVao;if(f===void 0||p.geometryId!==e.geometry.id){const F=this._getVaoKey(e.getIndex(),e.getAttributes());if(f=this.vaoCache[F],f===void 0){let L;({vaoGPU:f,staticVao:L}=this._createVao(e.getIndex(),e.getAttributes())),L&&(p.staticVao=f,p.geometryId=e.geometry.id)}}u.bindVertexArray(f);const m=e.getIndex(),x=l.lastOcclusionObject;if(x!==t&&x!==void 0){if(x!==null&&x.occlusionTest===!0&&(u.endQuery(u.ANY_SAMPLES_PASSED),l.occlusionQueryIndex++),t.occlusionTest===!0){const F=u.createQuery();u.beginQuery(u.ANY_SAMPLES_PASSED,F),l.occlusionQueries[l.occlusionQueryIndex]=F,l.occlusionQueryObjects[l.occlusionQueryIndex]=t}l.lastOcclusionObject=t}const N=this.bufferRenderer;t.isPoints?N.mode=u.POINTS:t.isLineSegments?N.mode=u.LINES:t.isLine?N.mode=u.LINE_STRIP:t.isLineLoop?N.mode=u.LINE_LOOP:n.wireframe===!0?(c.setLineWidth(n.wireframeLinewidth*this.renderer.getPixelRatio()),N.mode=u.LINES):N.mode=u.TRIANGLES;const{vertexCount:v,instanceCount:w}=d;let{firstVertex:B}=d;if(N.object=t,m!==null){B*=m.array.BYTES_PER_ELEMENT;const F=this.get(m);N.index=m.count,N.type=F.type}else N.index=0;t.isBatchedMesh?t._multiDrawInstances!==null?N.renderMultiDrawInstances(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount,t._multiDrawInstances):this.hasFeature("WEBGL_multi_draw")?N.renderMultiDraw(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount):sm("THREE.WebGLRenderer: WEBGL_multi_draw not supported."):w>1?N.renderInstances(B,v,w):N.render(B,v),u.bindVertexArray(null)}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)}copyTextureToBuffer(e,t,s,n,r,i){return this.textureUtils.copyTextureToBuffer(e,t,s,n,r,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new bA(e,t)}createProgram(e){const t=this.gl,{stage:s,code:n}=e,r=s==="fragment"?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(r,n),t.compileShader(r),this.set(e,{shaderGPU:r})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){const s=this.gl,n=e.pipeline,{fragmentProgram:r,vertexProgram:i}=n,a=s.createProgram(),u=this.get(r).shaderGPU,c=this.get(i).shaderGPU;if(s.attachShader(a,u),s.attachShader(a,c),s.linkProgram(a),this.set(n,{programGPU:a,fragmentShader:u,vertexShader:c}),t!==null&&this.parallel){const l=new Promise(d=>{const h=this.parallel,p=()=>{s.getProgramParameter(a,h.COMPLETION_STATUS_KHR)?(this._completeCompile(e,n),d()):requestAnimationFrame(p)};p()});t.push(l);return}this._completeCompile(e,n)}_handleSource(e,t){const s=e.split(`
|
|
`),n=[],r=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let a=r;a<i;a++){const u=a+1;n.push(`${u===t?">":" "} ${u}: ${s[a]}`)}return n.join(`
|
|
`)}_getShaderErrors(e,t,s){const n=e.getShaderParameter(t,e.COMPILE_STATUS),r=e.getShaderInfoLog(t).trim();if(n&&r==="")return"";const i=/ERROR: 0:(\d+)/.exec(r);if(i){const a=parseInt(i[1]);return s.toUpperCase()+`
|
|
|
|
`+r+`
|
|
|
|
`+this._handleSource(e.getShaderSource(t),a)}else return r}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const n=this.gl,r=n.getProgramInfoLog(e).trim();if(n.getProgramParameter(e,n.LINK_STATUS)===!1)if(typeof this.renderer.debug.onShaderError=="function")this.renderer.debug.onShaderError(n,e,s,t);else{const i=this._getShaderErrors(n,s,"vertex"),a=this._getShaderErrors(n,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+n.getError()+" - VALIDATE_STATUS "+n.getProgramParameter(e,n.VALIDATE_STATUS)+`
|
|
|
|
Program Info Log: `+r+`
|
|
`+i+`
|
|
`+a)}else r!==""&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(e,t){const{state:s,gl:n}=this,r=this.get(t),{programGPU:i,fragmentShader:a,vertexShader:u}=r;n.getProgramParameter(i,n.LINK_STATUS)===!1&&this._logProgramError(i,a,u),s.useProgram(i);const c=e.getBindings();this._setupBindings(c,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:n}=this,r={stage:"fragment",code:`#version 300 es
|
|
precision highp float;
|
|
void main() {}`};this.createProgram(r);const{computeProgram:i}=e,a=n.createProgram(),u=this.get(r).shaderGPU,c=this.get(i).shaderGPU,l=i.transforms,d=[],h=[];for(let x=0;x<l.length;x++){const N=l[x];d.push(N.varyingName),h.push(N.attributeNode)}n.attachShader(a,u),n.attachShader(a,c),n.transformFeedbackVaryings(a,d,n.SEPARATE_ATTRIBS),n.linkProgram(a),n.getProgramParameter(a,n.LINK_STATUS)===!1&&this._logProgramError(a,u,c),s.useProgram(a),this._setupBindings(t,a);const p=i.attributes,f=[],m=[];for(let x=0;x<p.length;x++){const N=p[x].node.attribute;f.push(N),this.has(N)||this.attributeUtils.createAttribute(N,n.ARRAY_BUFFER)}for(let x=0;x<h.length;x++){const N=h[x].attribute;this.has(N)||this.attributeUtils.createAttribute(N,n.ARRAY_BUFFER);const v=this.get(N);m.push(v)}this.set(e,{programGPU:a,transformBuffers:m,attributes:f})}createBindings(e,t){if(this._knownBindings.has(t)===!1){this._knownBindings.add(t);let s=0,n=0;for(const r of t){this.set(r,{textures:n,uniformBuffers:s});for(const i of r.bindings)i.isUniformBuffer&&s++,i.isSampledTexture&&n++}}this.updateBindings(e,t)}updateBindings(e){const{gl:t}=this,s=this.get(e);let n=s.uniformBuffers,r=s.textures;for(const i of e.bindings)if(i.isUniformsGroup||i.isUniformBuffer){const a=i.buffer,u=t.createBuffer();t.bindBuffer(t.UNIFORM_BUFFER,u),t.bufferData(t.UNIFORM_BUFFER,a,t.DYNAMIC_DRAW),this.set(i,{index:n++,bufferGPU:u})}else if(i.isSampledTexture){const{textureGPU:a,glTextureType:u}=this.get(i.texture);this.set(i,{index:r++,textureGPU:a,glTextureType:u})}}updateBinding(e){const t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){const n=this.get(e).bufferGPU,r=e.buffer;t.bindBuffer(t.UNIFORM_BUFFER,n),t.bufferData(t.UNIFORM_BUFFER,r,t.DYNAMIC_DRAW)}}createIndexAttribute(e){const t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;const t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){const t=Object.keys(sl).filter(n=>sl[n]===e),s=this.extensions;for(let n=0;n<t.length;n++)if(s.has(t[n]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(e,t,s=null,n=null,r=0){this.textureUtils.copyTextureToTexture(e,t,s,n,r)}copyFramebufferToTexture(e,t,s){this.textureUtils.copyFramebufferToTexture(e,t,s)}_setFramebuffer(e){const{gl:t,state:s}=this;let n=null;if(e.textures!==null){const r=e.renderTarget,i=this.get(r),{samples:a,depthBuffer:u,stencilBuffer:c}=r,l=r.isWebGLCubeRenderTarget===!0,d=r.isRenderTarget3D===!0,h=r.isRenderTargetArray===!0;let p=i.msaaFrameBuffer,f=i.depthRenderbuffer;const m=lf(e);let x;if(l?(i.cubeFramebuffers||(i.cubeFramebuffers={}),x=i.cubeFramebuffers[m]):(i.framebuffers||(i.framebuffers={}),x=i.framebuffers[m]),x===void 0){x=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,x);const N=e.textures;if(l){i.cubeFramebuffers[m]=x;const{textureGPU:v}=this.get(N[0]),w=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+w,v,0)}else{i.framebuffers[m]=x;for(let v=0;v<N.length;v++){const w=N[v],B=this.get(w);B.renderTarget=e.renderTarget,B.cacheKey=m;const F=t.COLOR_ATTACHMENT0+v;if(d||h){const L=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,F,B.textureGPU,0,L)}else t.framebufferTexture2D(t.FRAMEBUFFER,F,t.TEXTURE_2D,B.textureGPU,0)}s.drawBuffers(e,x)}if(e.depthTexture!==null){const v=this.get(e.depthTexture),w=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;v.renderTarget=e.renderTarget,v.cacheKey=m,t.framebufferTexture2D(t.FRAMEBUFFER,w,t.TEXTURE_2D,v.textureGPU,0)}}if(a>0){if(p===void 0){const N=[];p=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,p);const v=[],w=e.textures;for(let B=0;B<w.length;B++){if(v[B]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,v[B]),N.push(t.COLOR_ATTACHMENT0+B),u){const I=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;N.push(I)}const F=e.textures[B],L=this.get(F);t.renderbufferStorageMultisample(t.RENDERBUFFER,a,L.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+B,t.RENDERBUFFER,v[B])}if(i.msaaFrameBuffer=p,i.msaaRenderbuffers=v,f===void 0){f=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(f,e),i.depthRenderbuffer=f;const B=c?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;N.push(B)}i.invalidationArray=N}n=i.msaaFrameBuffer}else n=x}s.bindFramebuffer(t.FRAMEBUFFER,n)}_getVaoKey(e,t){let s="";if(e!==null){const n=this.get(e);s+=":"+n.id}for(let n=0;n<t.length;n++){const r=this.get(t[n]);s+=":"+r.id}return s}_createVao(e,t){const{gl:s}=this,n=s.createVertexArray();let r="",i=!0;if(s.bindVertexArray(n),e!==null){const a=this.get(e);s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,a.bufferGPU),r+=":"+a.id}for(let a=0;a<t.length;a++){const u=t[a],c=this.get(u);r+=":"+c.id,s.bindBuffer(s.ARRAY_BUFFER,c.bufferGPU),s.enableVertexAttribArray(a),(u.isStorageBufferAttribute||u.isStorageInstancedBufferAttribute)&&(i=!1);let l,d;u.isInterleavedBufferAttribute===!0?(l=u.data.stride*c.bytesPerElement,d=u.offset*c.bytesPerElement):(l=0,d=0),c.isInteger?s.vertexAttribIPointer(a,u.itemSize,c.type,l,d):s.vertexAttribPointer(a,u.itemSize,c.type,u.normalized,l,d),u.isInstancedBufferAttribute&&!u.isInterleavedBufferAttribute?s.vertexAttribDivisor(a,u.meshPerAttribute):u.isInterleavedBufferAttribute&&u.data.isInstancedInterleavedBuffer&&s.vertexAttribDivisor(a,u.data.meshPerAttribute)}return s.bindBuffer(s.ARRAY_BUFFER,null),this.vaoCache[r]=n,{vaoGPU:n,staticVao:i}}_getTransformFeedback(e){let t="";for(let r=0;r<e.length;r++)t+=":"+e[r].id;let s=this.transformFeedbackCache[t];if(s!==void 0)return s;const{gl:n}=this;s=n.createTransformFeedback(),n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,s);for(let r=0;r<e.length;r++){const i=e[r];n.bindBufferBase(n.TRANSFORM_FEEDBACK_BUFFER,r,i.transformBuffer)}return n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=s,s}_setupBindings(e,t){const s=this.gl;for(const n of e)for(const r of n.bindings){const a=this.get(r).index;if(r.isUniformsGroup||r.isUniformBuffer){const u=s.getUniformBlockIndex(t,r.name);s.uniformBlockBinding(t,u,a)}else if(r.isSampledTexture){const u=s.getUniformLocation(t,r.name);s.uniform1i(u,a)}}}_bindUniforms(e){const{gl:t,state:s}=this;for(const n of e)for(const r of n.bindings){const i=this.get(r),a=i.index;r.isUniformsGroup||r.isUniformBuffer?s.bindBufferBase(t.UNIFORM_BUFFER,a,i.bufferGPU):r.isSampledTexture&&s.bindTexture(i.glTextureType,i.textureGPU,t.TEXTURE0+a)}}dispose(){this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}const Ks={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list",TriangleStrip:"triangle-strip"},Fe={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},De={Store:"store"},ye={Load:"load",Clear:"clear"},go={CCW:"ccw"},mo={None:"none",Front:"front",Back:"back"},cn={Uint16:"uint16",Uint32:"uint32"},_={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",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",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"},yo={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},ps={Linear:"linear",Nearest:"nearest"},H={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"},ls={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},rl={None:0,All:15},Qt={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},xo={Storage:"storage",ReadOnlyStorage:"read-only-storage"},To={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},Is={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},il={TwoD:"2d",ThreeD:"3d"},$e={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},BA={All:"all"},Mr={Vertex:"vertex",Instance:"instance"},ra={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 FA extends qu{constructor(e,t){super(e),this.texture=t,this.version=t?t.version:0,this.isSampler=!0}}class UA extends FA{constructor(e,t,s){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s}update(){this.texture=this.textureNode.value}}class PA extends gg{constructor(e,t){super(e,t?t.array:null),this.attribute=t,this.isStorageBuffer=!0}}let DA=0;class LA extends PA{constructor(e,t){super("StorageBuffer_"+DA++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:Ve.READ_WRITE,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class IA extends os{constructor(e){super(),this.device=e;const t=`
|
|
struct VarysStruct {
|
|
@builtin( position ) Position: vec4<f32>,
|
|
@location( 0 ) vTex : vec2<f32>
|
|
};
|
|
|
|
@vertex
|
|
fn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {
|
|
|
|
var Varys : VarysStruct;
|
|
|
|
var pos = array< vec2<f32>, 4 >(
|
|
vec2<f32>( -1.0, 1.0 ),
|
|
vec2<f32>( 1.0, 1.0 ),
|
|
vec2<f32>( -1.0, -1.0 ),
|
|
vec2<f32>( 1.0, -1.0 )
|
|
);
|
|
|
|
var tex = array< vec2<f32>, 4 >(
|
|
vec2<f32>( 0.0, 0.0 ),
|
|
vec2<f32>( 1.0, 0.0 ),
|
|
vec2<f32>( 0.0, 1.0 ),
|
|
vec2<f32>( 1.0, 1.0 )
|
|
);
|
|
|
|
Varys.vTex = tex[ vertexIndex ];
|
|
Varys.Position = vec4<f32>( pos[ vertexIndex ], 0.0, 1.0 );
|
|
|
|
return Varys;
|
|
|
|
}
|
|
`,s=`
|
|
@group( 0 ) @binding( 0 )
|
|
var imgSampler : sampler;
|
|
|
|
@group( 0 ) @binding( 1 )
|
|
var img : texture_2d<f32>;
|
|
|
|
@fragment
|
|
fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
|
|
|
|
return textureSample( img, imgSampler, vTex );
|
|
|
|
}
|
|
`,n=`
|
|
@group( 0 ) @binding( 0 )
|
|
var imgSampler : sampler;
|
|
|
|
@group( 0 ) @binding( 1 )
|
|
var img : texture_2d<f32>;
|
|
|
|
@fragment
|
|
fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
|
|
|
|
return textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );
|
|
|
|
}
|
|
`;this.mipmapSampler=e.createSampler({minFilter:ps.Linear}),this.flipYSampler=e.createSampler({minFilter:ps.Nearest}),this.transferPipelines={},this.flipYPipelines={},this.mipmapVertexShaderModule=e.createShaderModule({label:"mipmapVertex",code:t}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:s}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:n})}getTransferPipeline(e){let t=this.transferPipelines[e];return t===void 0&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Ks.TriangleStrip,stripIndexFormat:cn.Uint32},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return t===void 0&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Ks.TriangleStrip,stripIndexFormat:cn.Uint32},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const n=t.format,{width:r,height:i}=t.size,a=this.getTransferPipeline(n),u=this.getFlipYPipeline(n),c=this.device.createTexture({size:{width:r,height:i,depthOrArrayLayers:1},format:n,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:$e.TwoD,baseArrayLayer:s}),d=c.createView({baseMipLevel:0,mipLevelCount:1,dimension:$e.TwoD,baseArrayLayer:0}),h=this.device.createCommandEncoder({}),p=(f,m,x)=>{const N=f.getBindGroupLayout(0),v=this.device.createBindGroup({layout:N,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:m}]}),w=h.beginRenderPass({colorAttachments:[{view:x,loadOp:ye.Clear,storeOp:De.Store,clearValue:[0,0,0,0]}]});w.setPipeline(f),w.setBindGroup(0,v),w.draw(4,1,0,0),w.end()};p(a,l,d),p(u,d,l),this.device.queue.submit([h.finish()]),c.destroy()}generateMipmaps(e,t,s=0){const n=this.get(e);n.useCount===void 0&&(n.useCount=0,n.layers=[]);const r=n.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,r),this.device.queue.submit([i.finish()]),n.useCount!==0&&(n.layers[s]=r),n.useCount++}_mipmapCreateBundles(e,t,s){const n=this.getTransferPipeline(t.format),r=n.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:$e.TwoD,baseArrayLayer:s});const a=[];for(let u=1;u<t.mipLevelCount;u++){const c=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:i}]}),l=e.createView({baseMipLevel:u,mipLevelCount:1,dimension:$e.TwoD,baseArrayLayer:s}),d={colorAttachments:[{view:l,loadOp:ye.Clear,storeOp:De.Store,clearValue:[0,0,0,0]}]},h=this.device.createRenderBundleEncoder({colorFormats:[t.format]});h.setPipeline(n),h.setBindGroup(0,c),h.draw(4,1,0,0),a.push({renderBundles:[h.finish()],passDescriptor:d}),i=l}return a}_mipmapRunBundles(e,t){const s=t.length;for(let n=0;n<s;n++){const r=t[n],i=e.beginRenderPass(r.passDescriptor);i.executeBundles(r.renderBundles),i.end()}}}const VA={[Bl]:"never",[ua]:"less",[El]:"equal",[wl]:"less-equal",[Rl]:"greater",[Cl]:"greater-equal",[Ml]:"always",[Al]:"not-equal"},GA=[0,1,3,2,4,5];class OA{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new vs,this.depthTexture.name="depthBuffer"}createSampler(e){const t=this.backend,s=t.device,n=t.get(e),r={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};r.magFilter===ps.Linear&&r.minFilter===ps.Linear&&r.mipmapFilter===ps.Linear&&(r.maxAnisotropy=e.anisotropy),e.isDepthTexture&&e.compareFunction!==null&&(r.compare=VA[e.compareFunction]),n.sampler=s.createSampler(r)}createDefaultTexture(e){let t;const s=ia(e);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(s):e.isVideoTexture?this.backend.get(e).externalTexture=this._getDefaultVideoFrame():t=this._getDefaultTextureGPU(s),this.backend.get(e).texture=t}createTexture(e,t={}){const s=this.backend,n=s.get(e);if(n.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");t.needsMipmaps===void 0&&(t.needsMipmaps=!1),t.levels===void 0&&(t.levels=1),t.depth===void 0&&(t.depth=1);const{width:r,height:i,depth:a,levels:u}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());const c=this._getDimension(e),l=e.internalFormat||t.format||ia(e,s.device);n.format=l;const{samples:d,primarySamples:h,isMSAA:p}=s.utils.getTextureSampleData(e);let f=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;e.isStorageTexture===!0&&(f|=GPUTextureUsage.STORAGE_BINDING),e.isCompressedTexture!==!0&&e.isCompressedArrayTexture!==!0&&(f|=GPUTextureUsage.RENDER_ATTACHMENT);const m={label:e.name,size:{width:r,height:i,depthOrArrayLayers:a},mipLevelCount:u,sampleCount:h,dimension:c,format:l,usage:f};if(e.isVideoTexture){const x=e.source.data,N=new VideoFrame(x);m.size.width=N.displayWidth,m.size.height=N.displayHeight,N.close(),n.externalTexture=x}else{if(l===void 0)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);n.texture=s.device.createTexture(m)}if(p){const x=Object.assign({},m);x.label=x.label+"-msaa",x.sampleCount=d,n.msaaTexture=s.device.createTexture(x)}n.initialized=!0,n.textureDescriptorGPU=m}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture!==void 0&&s.texture.destroy(),s.msaaTexture!==void 0&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){const s=this.backend.get(e);delete s.sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let s=0;s<6;s++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,s);else{const s=e.image.depth||1;for(let n=0;n<s;n++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,n)}}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const e=this.backend,{width:t,height:s}=e.getDrawingBufferSize();return this.colorBuffer=e.device.createTexture({label:"colorBuffer",size:{width:t,height:s,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){const s=this.backend,{width:n,height:r}=s.getDrawingBufferSize(),i=this.depthTexture,a=s.get(i).texture;let u,c;if(t?(u=oi,c=ui):e&&(u=ai,c=Le),a!==void 0){if(i.image.width===n&&i.image.height===r&&i.format===u&&i.type===c)return a;this.destroyTexture(i)}return i.name="depthBuffer",i.format=u,i.type=c,i.image.width=n,i.image.height=r,this.createTexture(i,{width:n,height:r}),s.get(i).texture}updateTexture(e,t){const s=this.backend.get(e),{textureDescriptorGPU:n}=s;if(!(e.isRenderTargetTexture||n===void 0)){if(e.isDataTexture)this._copyBufferToTexture(t.image,s.texture,n,0,e.flipY);else if(e.isDataArrayTexture||e.isData3DTexture)for(let r=0;r<t.image.depth;r++)this._copyBufferToTexture(t.image,s.texture,n,r,e.flipY,r);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,s.texture,n);else if(e.isCubeTexture)this._copyCubeMapToTexture(t.images,s.texture,n,e.flipY);else if(e.isVideoTexture){const r=e.source.data;s.externalTexture=r}else this._copyImageToTexture(t.image,s.texture,n,0,e.flipY);s.version=e.version,e.onUpdate&&e.onUpdate(e)}}async copyTextureToBuffer(e,t,s,n,r,i){const a=this.backend.device,u=this.backend.get(e),c=u.texture,l=u.textureDescriptorGPU.format,d=this._getBytesPerTexel(l);let h=n*d;h=Math.ceil(h/256)*256;const p=a.createBuffer({size:n*r*d,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),f=a.createCommandEncoder();f.copyTextureToBuffer({texture:c,origin:{x:t,y:s,z:i}},{buffer:p,bytesPerRow:h},{width:n,height:r});const m=this._getTypedArrayType(l);a.queue.submit([f.finish()]),await p.mapAsync(GPUMapMode.READ);const x=p.getMappedRange();return new m(x)}_isEnvironmentTexture(e){const t=e.mapping;return t===jn||t===Qn||t===Zs||t===Js}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(t===void 0){const s=new aa;s.minFilter=bt,s.magFilter=bt,this.createTexture(s,{width:1,height:1,format:e}),this.defaultTexture[e]=t=s}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultTexture[e];if(t===void 0){const s=new td;s.minFilter=bt,s.magFilter=bt,this.createTexture(s,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=s}return this.backend.get(t).texture}_getDefaultVideoFrame(){let e=this.defaultVideoFrame;if(e===null){const t={timestamp:0,codedWidth:1,codedHeight:1,format:"RGBA"};this.defaultVideoFrame=e=new VideoFrame(new Uint8Array([0,0,0,255]),t)}return e}_copyCubeMapToTexture(e,t,s,n){for(let r=0;r<6;r++){const i=e[r],a=n===!0?GA[r]:r;i.isDataTexture?this._copyBufferToTexture(i.image,t,s,a,n):this._copyImageToTexture(i,t,s,a,n)}}_copyImageToTexture(e,t,s,n,r){this.backend.device.queue.copyExternalImageToTexture({source:e},{texture:t,mipLevel:0,origin:{x:0,y:0,z:n}},{width:e.width,height:e.height,depthOrArrayLayers:1}),r===!0&&this._flipY(t,s,n)}_getPassUtils(){let e=this._passUtils;return e===null&&(this._passUtils=e=new IA(this.backend.device)),e}_generateMipmaps(e,t,s=0){this._getPassUtils().generateMipmaps(e,t,s)}_flipY(e,t,s=0){this._getPassUtils().flipY(e,t,s)}_copyBufferToTexture(e,t,s,n,r,i=0){const a=this.backend.device,u=e.data,c=this._getBytesPerTexel(s.format),l=e.width*c;a.queue.writeTexture({texture:t,mipLevel:0,origin:{x:0,y:0,z:n}},u,{offset:e.width*e.height*c*i,bytesPerRow:l},{width:e.width,height:e.height,depthOrArrayLayers:1}),r===!0&&this._flipY(t,s,n)}_copyCompressedBufferToTexture(e,t,s){const n=this.backend.device,r=this._getBlockData(s.format),i=s.size.depthOrArrayLayers>1;for(let a=0;a<e.length;a++){const u=e[a],c=u.width,l=u.height,d=i?s.size.depthOrArrayLayers:1,h=Math.ceil(c/r.width)*r.byteLength,p=h*Math.ceil(l/r.height);for(let f=0;f<d;f++)n.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:f}},u.data,{offset:f*p,bytesPerRow:h,rowsPerImage:Math.ceil(l/r.height)},{width:Math.ceil(c/r.width)*r.width,height:Math.ceil(l/r.height)*r.height,depthOrArrayLayers:1})}}_getBlockData(e){if(e===_.BC1RGBAUnorm||e===_.BC1RGBAUnormSRGB)return{byteLength:8,width:4,height:4};if(e===_.BC2RGBAUnorm||e===_.BC2RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===_.BC3RGBAUnorm||e===_.BC3RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===_.BC4RUnorm||e===_.BC4RSNorm)return{byteLength:8,width:4,height:4};if(e===_.BC5RGUnorm||e===_.BC5RGSnorm)return{byteLength:16,width:4,height:4};if(e===_.BC6HRGBUFloat||e===_.BC6HRGBFloat)return{byteLength:16,width:4,height:4};if(e===_.BC7RGBAUnorm||e===_.BC7RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===_.ETC2RGB8Unorm||e===_.ETC2RGB8UnormSRGB)return{byteLength:8,width:4,height:4};if(e===_.ETC2RGB8A1Unorm||e===_.ETC2RGB8A1UnormSRGB)return{byteLength:8,width:4,height:4};if(e===_.ETC2RGBA8Unorm||e===_.ETC2RGBA8UnormSRGB)return{byteLength:16,width:4,height:4};if(e===_.EACR11Unorm)return{byteLength:8,width:4,height:4};if(e===_.EACR11Snorm)return{byteLength:8,width:4,height:4};if(e===_.EACRG11Unorm)return{byteLength:16,width:4,height:4};if(e===_.EACRG11Snorm)return{byteLength:16,width:4,height:4};if(e===_.ASTC4x4Unorm||e===_.ASTC4x4UnormSRGB)return{byteLength:16,width:4,height:4};if(e===_.ASTC5x4Unorm||e===_.ASTC5x4UnormSRGB)return{byteLength:16,width:5,height:4};if(e===_.ASTC5x5Unorm||e===_.ASTC5x5UnormSRGB)return{byteLength:16,width:5,height:5};if(e===_.ASTC6x5Unorm||e===_.ASTC6x5UnormSRGB)return{byteLength:16,width:6,height:5};if(e===_.ASTC6x6Unorm||e===_.ASTC6x6UnormSRGB)return{byteLength:16,width:6,height:6};if(e===_.ASTC8x5Unorm||e===_.ASTC8x5UnormSRGB)return{byteLength:16,width:8,height:5};if(e===_.ASTC8x6Unorm||e===_.ASTC8x6UnormSRGB)return{byteLength:16,width:8,height:6};if(e===_.ASTC8x8Unorm||e===_.ASTC8x8UnormSRGB)return{byteLength:16,width:8,height:8};if(e===_.ASTC10x5Unorm||e===_.ASTC10x5UnormSRGB)return{byteLength:16,width:10,height:5};if(e===_.ASTC10x6Unorm||e===_.ASTC10x6UnormSRGB)return{byteLength:16,width:10,height:6};if(e===_.ASTC10x8Unorm||e===_.ASTC10x8UnormSRGB)return{byteLength:16,width:10,height:8};if(e===_.ASTC10x10Unorm||e===_.ASTC10x10UnormSRGB)return{byteLength:16,width:10,height:10};if(e===_.ASTC12x10Unorm||e===_.ASTC12x10UnormSRGB)return{byteLength:16,width:12,height:10};if(e===_.ASTC12x12Unorm||e===_.ASTC12x12UnormSRGB)return{byteLength:16,width:12,height:12}}_convertAddressMode(e){let t=yo.ClampToEdge;return e===li?t=yo.Repeat:e===ci&&(t=yo.MirrorRepeat),t}_convertFilterMode(e){let t=ps.Linear;return(e===bt||e===So||e===Xs)&&(t=ps.Nearest),t}_getBytesPerTexel(e){if(e===_.R8Unorm||e===_.R8Snorm||e===_.R8Uint||e===_.R8Sint)return 1;if(e===_.R16Uint||e===_.R16Sint||e===_.R16Float||e===_.RG8Unorm||e===_.RG8Snorm||e===_.RG8Uint||e===_.RG8Sint)return 2;if(e===_.R32Uint||e===_.R32Sint||e===_.R32Float||e===_.RG16Uint||e===_.RG16Sint||e===_.RG16Float||e===_.RGBA8Unorm||e===_.RGBA8UnormSRGB||e===_.RGBA8Snorm||e===_.RGBA8Uint||e===_.RGBA8Sint||e===_.BGRA8Unorm||e===_.BGRA8UnormSRGB||e===_.RGB9E5UFloat||e===_.RGB10A2Unorm||e===_.RG11B10UFloat||e===_.Depth32Float||e===_.Depth24Plus||e===_.Depth24PlusStencil8||e===_.Depth32FloatStencil8)return 4;if(e===_.RG32Uint||e===_.RG32Sint||e===_.RG32Float||e===_.RGBA16Uint||e===_.RGBA16Sint||e===_.RGBA16Float)return 8;if(e===_.RGBA32Uint||e===_.RGBA32Sint||e===_.RGBA32Float)return 16}_getTypedArrayType(e){if(e===_.R8Uint)return Uint8Array;if(e===_.R8Sint)return Int8Array;if(e===_.R8Unorm)return Uint8Array;if(e===_.R8Snorm)return Int8Array;if(e===_.RG8Uint)return Uint8Array;if(e===_.RG8Sint)return Int8Array;if(e===_.RG8Unorm)return Uint8Array;if(e===_.RG8Snorm)return Int8Array;if(e===_.RGBA8Uint)return Uint8Array;if(e===_.RGBA8Sint)return Int8Array;if(e===_.RGBA8Unorm)return Uint8Array;if(e===_.RGBA8Snorm)return Int8Array;if(e===_.R16Uint)return Uint16Array;if(e===_.R16Sint)return Int16Array;if(e===_.RG16Uint)return Uint16Array;if(e===_.RG16Sint)return Int16Array;if(e===_.RGBA16Uint)return Uint16Array;if(e===_.RGBA16Sint)return Int16Array;if(e===_.R16Float||e===_.RG16Float||e===_.RGBA16Float)return Uint16Array;if(e===_.R32Uint)return Uint32Array;if(e===_.R32Sint)return Int32Array;if(e===_.R32Float)return Float32Array;if(e===_.RG32Uint)return Uint32Array;if(e===_.RG32Sint)return Int32Array;if(e===_.RG32Float)return Float32Array;if(e===_.RGBA32Uint)return Uint32Array;if(e===_.RGBA32Sint)return Int32Array;if(e===_.RGBA32Float)return Float32Array;if(e===_.BGRA8Unorm||e===_.BGRA8UnormSRGB)return Uint8Array;if(e===_.RGB10A2Unorm||e===_.RGB9E5UFloat||e===_.RG11B10UFloat)return Uint32Array;if(e===_.Depth32Float)return Float32Array;if(e===_.Depth24Plus||e===_.Depth24PlusStencil8)return Uint32Array;if(e===_.Depth32FloatStencil8)return Float32Array}_getDimension(e){let t;return e.isData3DTexture?t=il.ThreeD:t=il.TwoD,t}}function ia(o,e=null){const t=o.format,s=o.type,n=o.colorSpace;let r;if(o.isCompressedTexture===!0||o.isCompressedArrayTexture===!0)switch(t){case Pr:r=n===q?_.BC1RGBAUnormSRGB:_.BC1RGBAUnorm;break;case Dr:r=n===q?_.BC2RGBAUnormSRGB:_.BC2RGBAUnorm;break;case Lr:r=n===q?_.BC3RGBAUnormSRGB:_.BC3RGBAUnorm;break;case vo:r=n===q?_.ETC2RGB8UnormSRGB:_.ETC2RGB8Unorm;break;case Ao:r=n===q?_.ETC2RGBA8UnormSRGB:_.ETC2RGBA8Unorm;break;case Ro:r=n===q?_.ASTC4x4UnormSRGB:_.ASTC4x4Unorm;break;case Co:r=n===q?_.ASTC5x4UnormSRGB:_.ASTC5x4Unorm;break;case Eo:r=n===q?_.ASTC5x5UnormSRGB:_.ASTC5x5Unorm;break;case wo:r=n===q?_.ASTC6x5UnormSRGB:_.ASTC6x5Unorm;break;case Mo:r=n===q?_.ASTC6x6UnormSRGB:_.ASTC6x6Unorm;break;case Bo:r=n===q?_.ASTC8x5UnormSRGB:_.ASTC8x5Unorm;break;case Fo:r=n===q?_.ASTC8x6UnormSRGB:_.ASTC8x6Unorm;break;case Uo:r=n===q?_.ASTC8x8UnormSRGB:_.ASTC8x8Unorm;break;case Po:r=n===q?_.ASTC10x5UnormSRGB:_.ASTC10x5Unorm;break;case Do:r=n===q?_.ASTC10x6UnormSRGB:_.ASTC10x6Unorm;break;case Lo:r=n===q?_.ASTC10x8UnormSRGB:_.ASTC10x8Unorm;break;case Io:r=n===q?_.ASTC10x10UnormSRGB:_.ASTC10x10Unorm;break;case Vo:r=n===q?_.ASTC12x10UnormSRGB:_.ASTC12x10Unorm;break;case Go:r=n===q?_.ASTC12x12UnormSRGB:_.ASTC12x12Unorm;break;case sn:r=n===q?_.RGBA8UnormSRGB:_.RGBA8Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",t)}else switch(t){case sn:switch(s){case An:r=_.RGBA8Snorm;break;case Rn:r=_.RGBA16Sint;break;case Ws:r=_.RGBA16Uint;break;case Le:r=_.RGBA32Uint;break;case ze:r=_.RGBA32Sint;break;case ys:r=n===q?_.RGBA8UnormSRGB:_.RGBA8Unorm;break;case pt:r=_.RGBA16Float;break;case ot:r=_.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",s)}break;case la:switch(s){case ed:r=_.RGB9E5UFloat;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",s)}break;case da:switch(s){case An:r=_.R8Snorm;break;case Rn:r=_.R16Sint;break;case Ws:r=_.R16Uint;break;case Le:r=_.R32Uint;break;case ze:r=_.R32Sint;break;case ys:r=_.R8Unorm;break;case pt:r=_.R16Float;break;case ot:r=_.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",s)}break;case Ln:switch(s){case An:r=_.RG8Snorm;break;case Rn:r=_.RG16Sint;break;case Ws:r=_.RG16Uint;break;case Le:r=_.RG32Uint;break;case ze:r=_.RG32Sint;break;case ys:r=_.RG8Unorm;break;case pt:r=_.RG16Float;break;case ot:r=_.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",s)}break;case ai:switch(s){case Ws:r=_.Depth16Unorm;break;case Le:r=_.Depth24Plus;break;case ot:r=_.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",s)}break;case oi:switch(s){case ui:r=_.Depth24PlusStencil8;break;case ot:e&&e.features.has(ra.Depth32FloatStencil8)===!1&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),r=_.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",s)}break;case ha:switch(s){case ze:r=_.R32Sint;break;case Le:r=_.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",s)}break;case pa:switch(s){case ze:r=_.RG32Sint;break;case Le:r=_.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",s)}break;case fa:switch(s){case ze:r=_.RGBA32Sint;break;case Le:r=_.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",s)}break;default:console.error("WebGPURenderer: Unsupported texture format.",t)}return r}const kA=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,zA=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,ol={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>":"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_multisampled_2d:"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"},WA=o=>{o=o.trim();const e=o.match(kA);if(e!==null&&e.length===4){const t=e[2],s=[];let n=null;for(;(n=zA.exec(t))!==null;)s.push({name:n[1],type:n[2]});const r=[];for(let l=0;l<s.length;l++){const{name:d,type:h}=s[l];let p=h;p.startsWith("ptr")?p="pointer":(p.startsWith("texture")&&(p=h.split("<")[0]),p=ol[p]),r.push(new $u(p,d))}const i=o.substring(e[0].length),a=e[3]||"void",u=e[1]!==void 0?e[1]:"";return{type:ol[a]||a,inputs:r,name:u,inputsCode:t,blockCode:i,outputType:a}}else throw new Error("FunctionNode: Function is not a WGSL code.")};class $A extends Hu{constructor(e){const{type:t,inputs:s,name:n,inputsCode:r,blockCode:i,outputType:a}=WA(e);super(t,s,n),this.inputsCode=r,this.blockCode=i,this.outputType=a}getCode(e=this.name){const t=this.outputType!=="void"?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class HA extends pg{parseFunction(e){return new $A(e)}}const Vs=typeof self<"u"?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},qA={[Ve.READ_ONLY]:"read",[Ve.WRITE_ONLY]:"write",[Ve.READ_WRITE]:"read_write"},al={[li]:"repeat",[ca]:"clamp",[ci]:"mirror"},Br={vertex:Vs?Vs.VERTEX:1,fragment:Vs?Vs.FRAGMENT:2,compute:Vs?Vs.COMPUTE:4},ul={instance:!0,swizzleAssign:!1,storageBuffer:!0},KA={"^^":"tsl_xor"},XA={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>"},cl={},it={tsl_xor:new Ne("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new Ne("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Ne("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Ne("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Ne("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Ne("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Ne("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Ne("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 Ne("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 Ne("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new Ne("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 Ne("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new Ne(`
|
|
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
|
|
|
|
let res = vec2f( iRes );
|
|
|
|
let uvScaled = coord * res;
|
|
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
|
|
// https://www.shadertoy.com/view/WtyXRy
|
|
|
|
let uv = uvWrapping - 0.5;
|
|
let iuv = floor( uv );
|
|
let f = fract( uv );
|
|
|
|
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
|
|
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
|
|
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
|
|
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
|
|
|
|
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
|
|
}
|
|
`)},vn={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>"};typeof navigator<"u"&&/Windows/g.test(navigator.userAgent)&&(it.pow_float=new Ne("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),it.pow_vec2=new Ne("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 ) ); }",[it.pow_float]),it.pow_vec3=new Ne("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 ) ); }",[it.pow_float]),it.pow_vec4=new Ne("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 ) ); }",[it.pow_float]),vn.pow_float="tsl_pow_float",vn.pow_vec2="tsl_pow_vec2",vn.pow_vec3="tsl_pow_vec3",vn.pow_vec4="tsl_pow_vec4");let Ng="";(typeof navigator<"u"&&/Firefox|Deno/g.test(navigator.userAgent))!==!0&&(Ng+=`diagnostic( off, derivative_uniformity );
|
|
`);class YA extends dg{constructor(e,t){super(e,t,new HA),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return e.isVideoTexture===!0&&e.colorSpace!==Dn}_generateTextureSample(e,t,s,n,r=this.shaderStage){return r==="fragment"?n?`textureSample( ${t}, ${t}_sampler, ${s}, ${n} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,n,"0")}_generateVideoSample(e,t,s=this.shaderStage){if(s==="fragment")return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2<f32>( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,n,r,i=this.shaderStage){return(i==="fragment"||i==="compute")&&this.isUnfilterable(e)===!1?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${n} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,n):this.generateTextureLod(e,t,s,r,n)}generateWrapFunction(e){const t=`tsl_coord_${al[e.wrapS]}S_${al[e.wrapT]}_${e.isData3DTexture?"3d":"2d"}T`;let s=cl[t];if(s===void 0){const n=[],r=e.isData3DTexture?"vec3f":"vec2f";let i=`fn ${t}( coord : ${r} ) -> ${r} {
|
|
|
|
return ${r}(
|
|
`;const a=(u,c)=>{u===li?(n.push(it.repeatWrapping_float),i+=` tsl_repeatWrapping_float( coord.${c} )`):u===ca?(n.push(it.clampWrapping_float),i+=` tsl_clampWrapping_float( coord.${c} )`):u===ci?(n.push(it.mirrorWrapping_float),i+=` tsl_mirrorWrapping_float( coord.${c} )`):(i+=` coord.${c}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${u}" for vertex shader.`))};a(e.wrapS,"x"),i+=`,
|
|
`,a(e.wrapT,"y"),e.isData3DTexture&&(i+=`,
|
|
`,a(e.wrapR,"z")),i+=`
|
|
);
|
|
|
|
}
|
|
`,cl[t]=s=new Ne(i,n)}return s.build(this),t}generateTextureDimension(e,t,s){const n=this.getDataFromNode(e,this.shaderStage,this.globalCache);n.dimensionsSnippet===void 0&&(n.dimensionsSnippet={});let r=n.dimensionsSnippet[s];if(n.dimensionsSnippet[s]===void 0){let i,a;const{primarySamples:u}=this.renderer.backend.utils.getTextureSampleData(e),c=u>1;e.isData3DTexture?a="vec3<u32>":a="vec2<u32>",c||e.isVideoTexture||e.isStorageTexture?i=t:i=`${t}${s?`, u32( ${s} )`:""}`,r=new Ir(new Vr(`textureDimensions( ${i} )`,a)),n.dimensionsSnippet[s]=r,(e.isDataArrayTexture||e.isData3DTexture)&&(n.arrayLayerCount=new Ir(new Vr(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(n.cubeFaceCount=new Ir(new Vr("6u","u32")))}return r.build(this)}generateFilteredTexture(e,t,s,n="0u"){this._include("biquadraticTexture");const r=this.generateWrapFunction(e),i=this.generateTextureDimension(e,t,n);return`tsl_biquadraticTexture( ${t}, ${r}( ${s} ), ${i}, u32( ${n} ) )`}generateTextureLod(e,t,s,n,r="0u"){const i=this.generateWrapFunction(e),a=this.generateTextureDimension(e,t,r),u=e.isData3DTexture?"vec3":"vec2",c=`${u}<u32>(${i}(${s}) * ${u}<f32>(${a}))`;return this.generateTextureLoad(e,t,c,n,r)}generateTextureLoad(e,t,s,n,r="0u"){return e.isVideoTexture===!0||e.isStorageTexture===!0?`textureLoad( ${t}, ${s} )`:n?`textureLoad( ${t}, ${s}, ${n}, u32( ${r} ) )`:`textureLoad( ${t}, ${s}, u32( ${r} ) )`}generateTextureStore(e,t,s,n){return`textureStore( ${t}, ${s}, ${n} )`}isSampleCompare(e){return e.isDepthTexture===!0&&e.compareFunction!==null}isUnfilterable(e){return this.getComponentTypeFromTexture(e)!=="float"||!this.isAvailable("float32Filterable")&&e.isDataTexture===!0&&e.type===ot||this.isSampleCompare(e)===!1&&e.minFilter===bt&&e.magFilter===bt||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,s,n,r=this.shaderStage){let i=null;return e.isVideoTexture===!0?i=this._generateVideoSample(t,s,r):this.isUnfilterable(e)?i=this.generateTextureLod(e,t,s,n,"0",r):i=this._generateTextureSample(e,t,s,n,r),i}generateTextureGrad(e,t,s,n,r,i=this.shaderStage){if(i==="fragment")return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${n[0]}, ${n[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,n,r,i=this.shaderStage){if(i==="fragment")return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${n} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,n,r,i=this.shaderStage){let a=null;return e.isVideoTexture===!0?a=this._generateVideoSample(t,s,i):a=this._generateTextureSampleLevel(e,t,s,n,r,i),a}generateTextureBias(e,t,s,n,r,i=this.shaderStage){if(i==="fragment")return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${n} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(e.isNodeVarying===!0&&e.needsInterpolation===!0){if(t==="vertex")return`varyings.${e.name}`}else if(e.isNodeUniform===!0){const s=e.name,n=e.type;return n==="texture"||n==="cubeTexture"||n==="storageTexture"||n==="texture3D"?s:n==="buffer"||n==="storageBuffer"||n==="indirectStorageBuffer"?`NodeBuffer_${e.id}.${s}`:e.groupNode.name+"."+s}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=KA[e];return t!==void 0?(this._include(t),t):null}getNodeAccess(e,t){return t!=="compute"?Ve.READ_ONLY:e.access}getStorageAccess(e,t){return qA[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,s,n=null){const r=super.getUniformFromNode(e,t,s,n),i=this.getDataFromNode(e,s,this.globalCache);if(i.uniformGPU===void 0){let a;const u=e.groupNode,c=u.name,l=this.getBindGroupArray(c,s);if(t==="texture"||t==="cubeTexture"||t==="storageTexture"||t==="texture3D"){let d=null;const h=this.getNodeAccess(e,s);if(t==="texture"||t==="storageTexture"?d=new Di(r.name,r.node,u,h):t==="cubeTexture"?d=new Tg(r.name,r.node,u,h):t==="texture3D"&&(d=new _g(r.name,r.node,u,h)),d.store=e.isStorageTextureNode===!0,d.setVisibility(Br[s]),(s==="fragment"||s==="compute")&&this.isUnfilterable(e.value)===!1&&d.store===!1){const p=new UA(`${r.name}_sampler`,r.node,u);p.setVisibility(Br[s]),l.push(p,d),a=[p,d]}else l.push(d),a=[d]}else if(t==="buffer"||t==="storageBuffer"||t==="indirectStorageBuffer"){const d=t==="buffer"?yg:LA,h=new d(e,u);h.setVisibility(Br[s]),l.push(h),a=h}else{const d=this.uniformGroups[s]||(this.uniformGroups[s]={});let h=d[c];h===void 0&&(h=new xg(c,u),h.setVisibility(Br[s]),d[c]=h,l.push(h)),a=this.getNodeUniform(r,t),h.addUniform(a)}i.uniformGPU=a}return r}getBuiltin(e,t,s,n=this.shaderStage){const r=this.builtins[n]||(this.builtins[n]=new Map);return r.has(e)===!1&&r.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return this.builtins[t]!==void 0&&this.builtins[t].has(e)}getVertexIndex(){return this.shaderStage==="vertex"?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),n=[];for(const i of t.inputs)n.push(i.name+" : "+this.getType(i.type));let r=`fn ${t.name}( ${n.join(", ")} ) -> ${this.getType(t.type)} {
|
|
${s.vars}
|
|
${s.code}
|
|
`;return s.result&&(r+=` return ${s.result};
|
|
`),r+=`
|
|
}
|
|
`,r}getInstanceIndex(){return this.shaderStage==="vertex"?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){const t=[],s=this.directives[e];if(s!==void 0)for(const n of s)t.push(`enable ${n};`);return t.join(`
|
|
`)}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){const t=[],s=this.builtins[e];if(s!==void 0)for(const{name:n,property:r,type:i}of s.values())t.push(`@builtin( ${n} ) ${r} : ${i}`);return t.join(`,
|
|
`)}getScopedArray(e,t,s,n){return this.scopedArrays.has(e)===!1&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:n}),e}getScopedArrays(e){if(e!=="compute")return;const t=[];for(const{name:s,scope:n,bufferType:r,bufferCount:i}of this.scopedArrays.values()){const a=this.getType(r);t.push(`var<${n}> ${s}: array< ${a}, ${i} >;`)}return t.join(`
|
|
`)}getAttributes(e){const t=[];if(e==="compute"&&(this.getBuiltin("global_invocation_id","id","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"))),e==="vertex"||e==="compute"){const s=this.getBuiltins("attribute");s&&t.push(s);const n=this.getAttributesArray();for(let r=0,i=n.length;r<i;r++){const a=n[r],u=a.name,c=this.getType(a.type);t.push(`@location( ${r} ) ${u} : ${c}`)}}return t.join(`,
|
|
`)}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let r=0;r<s.length;r++){const i=s[r];t.push(` @location( ${r} ) m${r} : ${i}<f32>`)}const n=this.getBuiltins("output");return n&&t.push(" "+n),t.join(`,
|
|
`)}getStructs(e){const t=[],s=this.structs[e];for(let n=0,r=s.length;n<r;n++){const i=s[n],a=i.name;let u=`struct ${a} {
|
|
`;u+=this.getStructMembers(i),u+=`
|
|
}`,t.push(u),t.push(`
|
|
var<private> output : ${a};
|
|
|
|
`)}return t.join(`
|
|
|
|
`)}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(s!==void 0)for(const n of s)t.push(` ${this.getVar(n.type,n.name)};`);return`
|
|
${t.join(`
|
|
`)}
|
|
`}getVaryings(e){const t=[];if(e==="vertex"&&this.getBuiltin("position","Vertex","vec4<f32>","vertex"),e==="vertex"||e==="fragment"){const r=this.varyings,i=this.vars[e];for(let a=0;a<r.length;a++){const u=r[a];if(u.needsInterpolation){let c=`@location( ${a} )`;/^(int|uint|ivec|uvec)/.test(u.type)&&(c+=" @interpolate( flat )"),t.push(`${c} ${u.name} : ${this.getType(u.type)}`)}else e==="vertex"&&i.includes(u)===!1&&i.push(u)}}const s=this.getBuiltins(e);s&&t.push(s);const n=t.join(`,
|
|
`);return e==="vertex"?this._getWGSLStruct("VaryingsStruct"," "+n):n}getUniforms(e){const t=this.uniforms[e],s=[],n=[],r=[],i={};for(const u of t){const c=u.groupNode.name,l=this.bindingsIndexes[c];if(u.type==="texture"||u.type==="cubeTexture"||u.type==="storageTexture"||u.type==="texture3D"){const d=u.node.value;(e==="fragment"||e==="compute")&&this.isUnfilterable(d)===!1&&u.node.isStorageTextureNode!==!0&&(this.isSampleCompare(d)?s.push(`@binding( ${l.binding++} ) @group( ${l.group} ) var ${u.name}_sampler : sampler_comparison;`):s.push(`@binding( ${l.binding++} ) @group( ${l.group} ) var ${u.name}_sampler : sampler;`));let h,p="";const{primarySamples:f}=this.renderer.backend.utils.getTextureSampleData(d);if(f>1&&(p="_multisampled"),d.isCubeTexture===!0)h="texture_cube<f32>";else if(d.isDataArrayTexture===!0||d.isCompressedArrayTexture===!0)h="texture_2d_array<f32>";else if(d.isDepthTexture===!0)h=`texture_depth${p}_2d`;else if(d.isVideoTexture===!0)h="texture_external";else if(d.isData3DTexture===!0)h="texture_3d<f32>";else if(u.node.isStorageTextureNode===!0){const m=ia(d),x=this.getStorageAccess(u.node,e);h=`texture_storage_2d<${m}, ${x}>`}else{const m=this.getComponentTypeFromTexture(d).charAt(0);h=`texture${p}_2d<${m}32>`}s.push(`@binding( ${l.binding++} ) @group( ${l.group} ) var ${u.name} : ${h};`)}else if(u.type==="buffer"||u.type==="storageBuffer"||u.type==="indirectStorageBuffer"){const d=u.node,h=this.getType(d.bufferType),p=d.bufferCount,f=p>0&&u.type==="buffer"?", "+p:"",m=d.isAtomic?`atomic<${h}>`:`${h}`,x=` ${u.name} : array< ${m}${f} >
|
|
`,N=d.isStorageBufferNode?`storage, ${this.getStorageAccess(d,e)}`:"uniform";n.push(this._getWGSLStructBinding("NodeBuffer_"+d.id,x,N,l.binding++,l.group))}else{const d=this.getType(this.getVectorType(u.type)),h=u.groupNode.name;(i[h]||(i[h]={index:l.binding++,id:l.group,snippets:[]})).snippets.push(` ${u.name} : ${d}`)}}for(const u in i){const c=i[u];r.push(this._getWGSLStructBinding(u,c.snippets.join(`,
|
|
`),"uniform",c.index,c.id))}let a=s.join(`
|
|
`);return a+=n.join(`
|
|
`),a+=r.join(`
|
|
`),a}buildCode(){const e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let n=`// code
|
|
|
|
`;n+=this.flowCode[t];const r=this.flowNodes[t],i=r[r.length-1],a=i.outputNode,u=a!==void 0&&a.isOutputStructNode===!0;for(const c of r){const l=this.getFlowData(c),d=c.name;if(d&&(n.length>0&&(n+=`
|
|
`),n+=` // flow -> ${d}
|
|
`),n+=`${l.code}
|
|
`,c===i&&t!=="compute"){if(n+=`// result
|
|
|
|
`,t==="vertex")n+=`varyings.Vertex = ${l.result};`;else if(t==="fragment")if(u)s.returnType=a.nodeType,n+=`return ${l.result};`;else{let h=" @location(0) color: vec4<f32>";const p=this.getBuiltins("output");p&&(h+=`,
|
|
`+p),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",h),s.structs+=`
|
|
var<private> output : OutputStruct;
|
|
|
|
`,n+=`output.color = ${l.result};
|
|
|
|
return output;`}}}s.flow=n}this.material!==null?(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 s;return t!==null&&(s=this._getWGSLMethod(e+"_"+t)),s===void 0&&(s=this._getWGSLMethod(e)),s||e}getType(e){return XA[e]||e}isAvailable(e){let t=ul[e];return t===void 0&&(e==="float32Filterable"?t=this.renderer.hasFeature("float32-filterable"):e==="clipDistance"&&(t=this.renderer.hasFeature("clip-distances")),ul[e]=t),t}_getWGSLMethod(e){return it[e]!==void 0&&this._include(e),vn[e]}_include(e){const t=it[e];return t.build(this),this.currentFunctionNode!==null&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}
|
|
// directives
|
|
${e.directives}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// varyings
|
|
${e.varyings}
|
|
var<private> varyings : VaryingsStruct;
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
@vertex
|
|
fn main( ${e.attributes} ) -> VaryingsStruct {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
return varyings;
|
|
|
|
}
|
|
`}_getWGSLFragmentCode(e){return`${this.getSignature()}
|
|
// global
|
|
${Ng}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// structs
|
|
${e.structs}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
@fragment
|
|
fn main( ${e.varyings} ) -> ${e.returnType} {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
}
|
|
`}_getWGSLComputeCode(e,t){return`${this.getSignature()}
|
|
// directives
|
|
${e.directives}
|
|
|
|
// system
|
|
var<private> instanceIndex : u32;
|
|
|
|
// locals
|
|
${e.scopedArrays}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
@compute @workgroup_size( ${t} )
|
|
fn main( ${e.attributes} ) {
|
|
|
|
// system
|
|
instanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
}
|
|
`}_getWGSLStruct(e,t){return`
|
|
struct ${e} {
|
|
${t}
|
|
};`}_getWGSLStructBinding(e,t,s,n=0,r=0){const i=e+"Struct";return`${this._getWGSLStruct(i,t)}
|
|
@binding( ${n} ) @group( ${r} )
|
|
var<${s}> ${e} : ${i};`}}class jA{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return e.depthTexture!==null?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=_.Depth24PlusStencil8:e.depth&&(t=_.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){const r=this.backend.renderer,i=r.getRenderTarget();t=i?i.samples:r.samples}else e.renderTarget&&(t=e.renderTarget.samples);t=t||1;const s=t>1&&e.renderTarget!==null&&e.isDepthTexture!==!0&&e.isFramebufferTexture!==!0;return{samples:t,primarySamples:s?1:t,isMSAA:s}}getCurrentColorFormat(e){let t;return e.textures!==null?t=this.getTextureFormatGPU(e.textures[0]):t=this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return e.textures!==null?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){if(e.isPoints)return Ks.PointList;if(e.isLineSegments||e.isMesh&&t.wireframe===!0)return Ks.LineList;if(e.isLine)return Ks.LineStrip;if(e.isMesh)return Ks.TriangleList}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),t===2&&(t=4)),t}getSampleCountRenderContext(e){return e.textures!==null?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?_.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const QA=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),ZA=new Map([[yl,["float16"]]]),JA=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class eR{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),n=this.backend,r=n.get(s);let i=r.buffer;if(i===void 0){const a=n.device;let u=s.array;if(e.normalized===!1&&(u.constructor===Int16Array||u.constructor===Uint16Array)){const l=new Uint32Array(u.length);for(let d=0;d<u.length;d++)l[d]=u[d];u=l}if(s.array=u,(s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute)&&s.itemSize===3){u=new u.constructor(s.count*4);for(let l=0;l<s.count;l++)u.set(s.array.subarray(l*3,l*3+3),l*4);s.itemSize=4,s.array=u}const c=u.byteLength+(4-u.byteLength%4)%4;i=a.createBuffer({label:s.name,size:c,usage:t,mappedAtCreation:!0}),new u.constructor(i.getMappedRange()).set(u),i.unmap(),r.buffer=i}}updateAttribute(e){const t=this._getBufferAttribute(e),s=this.backend,n=s.device,r=s.get(t).buffer,i=t.array,a=this._isTypedArray(i),u=t.updateRanges;if(u.length===0)n.queue.writeBuffer(r,0,i,0);else{const c=a?1:i.BYTES_PER_ELEMENT;for(let l=0,d=u.length;l<d;l++){const h=u[l],p=h.start*c,f=h.count*c;n.queue.writeBuffer(r,0,i,p,f)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){const t=e.getAttributes(),s=new Map;for(let n=0;n<t.length;n++){const r=t[n],i=r.array.BYTES_PER_ELEMENT,a=this._getBufferAttribute(r);let u=s.get(a);if(u===void 0){let d,h;r.isInterleavedBufferAttribute===!0?(d=r.data.stride*i,h=r.data.isInstancedInterleavedBuffer?Mr.Instance:Mr.Vertex):(d=r.itemSize*i,h=r.isInstancedBufferAttribute?Mr.Instance:Mr.Vertex),r.normalized===!1&&(r.array.constructor===Int16Array||r.array.constructor===Uint16Array)&&(d=4),u={arrayStride:d,attributes:[],stepMode:h},s.set(a,u)}const c=this._getVertexFormat(r),l=r.isInterleavedBufferAttribute===!0?r.offset*i:0;u.attributes.push({shaderLocation:n,offset:l,format:c})}return Array.from(s.values())}destroyAttribute(e){const t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,s=t.device,r=t.get(this._getBufferAttribute(e)).buffer,i=r.size,a=s.createBuffer({label:`${e.name}_readback`,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),u=s.createCommandEncoder({label:`readback_encoder_${e.name}`});u.copyBufferToBuffer(r,0,a,0,i);const c=u.finish();s.queue.submit([c]),await a.mapAsync(GPUMapMode.READ);const l=a.getMappedRange(),d=new e.array.constructor(l.slice(0));return a.unmap(),d.buffer}_getVertexFormat(e){const{itemSize:t,normalized:s}=e,n=e.array.constructor,r=e.constructor;let i;if(t===1)i=JA.get(n);else{const u=(ZA.get(r)||QA.get(n))[s?1:0];if(u){const c=n.BYTES_PER_ELEMENT*t,d=Math.floor((c+3)/4)*4/n.BYTES_PER_ELEMENT;if(d%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");i=`${u}x${d}`}}return i||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),i}_isTypedArray(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class tR{constructor(e){this.backend=e,this.bindGroupLayoutCache=new WeakMap}createBindingsLayout(e){const t=this.backend,s=t.device,n=[];let r=0;for(const i of e.bindings){const a={binding:r++,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){const u={};i.isStorageBuffer&&(i.visibility&4&&(i.access===Ve.READ_WRITE||i.access===Ve.WRITE_ONLY)?u.type=xo.Storage:u.type=xo.ReadOnlyStorage),a.buffer=u}else if(i.isSampler){const u={};i.texture.isDepthTexture&&i.texture.compareFunction!==null&&(u.type="comparison"),a.sampler=u}else if(i.isSampledTexture&&i.texture.isVideoTexture)a.externalTexture={};else if(i.isSampledTexture&&i.store){const u={};u.format=this.backend.get(i.texture).texture.format;const c=i.access;c===Ve.READ_WRITE?u.access=To.ReadWrite:c===Ve.WRITE_ONLY?u.access=To.WriteOnly:u.access=To.ReadOnly,a.storageTexture=u}else if(i.isSampledTexture){const u={},{primarySamples:c}=t.utils.getTextureSampleData(i.texture);if(c>1&&(u.multisampled=!0,i.texture.isDepthTexture||(u.sampleType=Is.UnfilterableFloat)),i.texture.isDepthTexture)u.sampleType=Is.Depth;else if(i.texture.isDataTexture||i.texture.isDataArrayTexture||i.texture.isData3DTexture){const l=i.texture.type;l===ze?u.sampleType=Is.SInt:l===Le?u.sampleType=Is.UInt:l===ot&&(this.backend.hasFeature("float32-filterable")?u.sampleType=Is.Float:u.sampleType=Is.UnfilterableFloat)}i.isSampledCubeTexture?u.viewDimension=$e.Cube:i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?u.viewDimension=$e.TwoDArray:i.isSampledTexture3D&&(u.viewDimension=$e.ThreeD),a.texture=u}else console.error(`WebGPUBindingUtils: Unsupported binding "${i}".`);n.push(a)}return s.createBindGroupLayout({entries:n})}createBindings(e,t,s,n=0){const{backend:r,bindGroupLayoutCache:i}=this,a=r.get(e);let u=i.get(e.bindingsReference);u===void 0&&(u=this.createBindingsLayout(e),i.set(e.bindingsReference,u));let c;s>0&&(a.groups===void 0&&(a.groups=[],a.versions=[]),a.versions[s]===n&&(c=a.groups[s])),c===void 0&&(c=this.createBindGroup(e,u),s>0&&(a.groups[s]=c,a.versions[s]=n)),a.group=c,a.layout=u}updateBinding(e){const t=this.backend,s=t.device,n=e.buffer,r=t.get(e).buffer;s.queue.writeBuffer(r,0,n,0)}createBindGroup(e,t){const s=this.backend,n=s.device;let r=0;const i=[];for(const a of e.bindings){if(a.isUniformBuffer){const u=s.get(a);if(u.buffer===void 0){const c=a.byteLength,l=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,d=n.createBuffer({label:"bindingBuffer_"+a.name,size:c,usage:l});u.buffer=d}i.push({binding:r,resource:{buffer:u.buffer}})}else if(a.isStorageBuffer){const u=s.get(a);if(u.buffer===void 0){const c=a.attribute;u.buffer=s.get(c).buffer}i.push({binding:r,resource:{buffer:u.buffer}})}else if(a.isSampler){const u=s.get(a.texture);i.push({binding:r,resource:u.sampler})}else if(a.isSampledTexture){const u=s.get(a.texture);let c;if(u.externalTexture!==void 0)c=n.importExternalTexture({source:u.externalTexture});else{const l=a.store?1:u.texture.mipLevelCount,d=`view-${u.texture.width}-${u.texture.height}-${l}`;if(c=u[d],c===void 0){const h=BA.All;let p;a.isSampledCubeTexture?p=$e.Cube:a.isSampledTexture3D?p=$e.ThreeD:a.texture.isDataArrayTexture||a.texture.isCompressedArrayTexture?p=$e.TwoDArray:p=$e.TwoD,c=u[d]=u.texture.createView({aspect:h,dimension:p,mipLevelCount:l})}}i.push({binding:r,resource:c})}r++}return n.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class sR{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:n,geometry:r,pipeline:i}=e,{vertexProgram:a,fragmentProgram:u}=i,c=this.backend,l=c.device,d=c.utils,h=c.get(i),p=[];for(const Ze of e.getBindings()){const Dt=c.get(Ze);p.push(Dt.layout)}const f=c.attributeUtils.createShaderVertexBuffers(e);let m;n.transparent===!0&&n.blending!==en&&(m=this._getBlending(n));let x={};n.stencilWrite===!0&&(x={compare:this._getStencilCompare(n),failOp:this._getStencilOperation(n.stencilFail),depthFailOp:this._getStencilOperation(n.stencilZFail),passOp:this._getStencilOperation(n.stencilZPass)});const N=this._getColorWriteMask(n),v=[];if(e.context.textures!==null){const Ze=e.context.textures;for(let Dt=0;Dt<Ze.length;Dt++){const Ms=d.getTextureFormatGPU(Ze[Dt]);v.push({format:Ms,blend:m,writeMask:N})}}else{const Ze=d.getCurrentColorFormat(e.context);v.push({format:Ze,blend:m,writeMask:N})}const w=c.get(a).module,B=c.get(u).module,F=this._getPrimitiveState(s,r,n),L=this._getDepthCompare(n),I=d.getCurrentDepthStencilFormat(e.context),G=this._getSampleCount(e.context),X={label:`renderPipeline_${n.name||n.type}_${n.id}`,vertex:Object.assign({},w,{buffers:f}),fragment:Object.assign({},B,{targets:v}),primitive:F,multisample:{count:G,alphaToCoverageEnabled:n.alphaToCoverage&&G>1},layout:l.createPipelineLayout({bindGroupLayouts:p})},ie={},Z=e.context.depth,Qe=e.context.stencil;if((Z===!0||Qe===!0)&&(Z===!0&&(ie.format=I,ie.depthWriteEnabled=n.depthWrite,ie.depthCompare=L),Qe===!0&&(ie.stencilFront=x,ie.stencilBack={},ie.stencilReadMask=n.stencilFuncMask,ie.stencilWriteMask=n.stencilWriteMask),X.depthStencil=ie),t===null)h.pipeline=l.createRenderPipeline(X);else{const Ze=new Promise(Dt=>{l.createRenderPipelineAsync(X).then(Ms=>{h.pipeline=Ms,Dt()})});t.push(Ze)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:n}=t,r=s.getCurrentDepthStencilFormat(e),i=s.getCurrentColorFormat(e),a=this._getSampleCount(e),u={label:"renderBundleEncoder",colorFormats:[i],depthStencilFormat:r,sampleCount:a};return n.createRenderBundleEncoder(u)}createComputePipeline(e,t){const s=this.backend,n=s.device,r=s.get(e.computeProgram).module,i=s.get(e),a=[];for(const u of t){const c=s.get(u);a.push(c.layout)}i.pipeline=n.createComputePipeline({compute:r,layout:n.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(e){let t,s;const n=e.blending,r=e.blendSrc,i=e.blendDst,a=e.blendEquation;if(n===Hl){const u=e.blendSrcAlpha!==null?e.blendSrcAlpha:r,c=e.blendDstAlpha!==null?e.blendDstAlpha:i,l=e.blendEquationAlpha!==null?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(a)},s={srcFactor:this._getBlendFactor(u),dstFactor:this._getBlendFactor(c),operation:this._getBlendOperation(l)}}else{const u=e.premultipliedAlpha,c=(l,d,h,p)=>{t={srcFactor:l,dstFactor:d,operation:ls.Add},s={srcFactor:h,dstFactor:p,operation:ls.Add}};if(u)switch(n){case Ys:c(H.One,H.OneMinusSrcAlpha,H.One,H.OneMinusSrcAlpha);break;case qr:c(H.One,H.One,H.One,H.One);break;case Hr:c(H.Zero,H.OneMinusSrc,H.Zero,H.One);break;case $r:c(H.Zero,H.Src,H.Zero,H.SrcAlpha);break}else switch(n){case Ys:c(H.SrcAlpha,H.OneMinusSrcAlpha,H.One,H.OneMinusSrcAlpha);break;case qr:c(H.SrcAlpha,H.One,H.SrcAlpha,H.One);break;case Hr:c(H.Zero,H.OneMinusSrc,H.Zero,H.One);break;case $r:c(H.Zero,H.Src,H.Zero,H.Src);break}}if(t!==void 0&&s!==void 0)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",n)}_getBlendFactor(e){let t;switch(e){case $l:t=H.Zero;break;case Wl:t=H.One;break;case zl:t=H.Src;break;case Il:t=H.OneMinusSrc;break;case kl:t=H.SrcAlpha;break;case Ll:t=H.OneMinusSrcAlpha;break;case Gl:t=H.Dst;break;case Dl:t=H.OneMinusDstColor;break;case Vl:t=H.DstAlpha;break;case Pl:t=H.OneMinusDstAlpha;break;case Ol:t=H.SrcAlphaSaturated;break;case __:t=H.Constant;break;case b_:t=H.OneMinusConstant;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case Im:t=Fe.Never;break;case Lm:t=Fe.Always;break;case Dm:t=Fe.Less;break;case Pm:t=Fe.LessEqual;break;case Um:t=Fe.Equal;break;case Fm:t=Fe.GreaterEqual;break;case Bm:t=Fe.Greater;break;case Mm:t=Fe.NotEqual;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Hm:t=Qt.Keep;break;case $m:t=Qt.Zero;break;case Wm:t=Qt.Replace;break;case zm:t=Qt.Invert;break;case km:t=Qt.IncrementClamp;break;case Om:t=Qt.DecrementClamp;break;case Gm:t=Qt.IncrementWrap;break;case Vm:t=Qt.DecrementWrap;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Gs:t=ls.Add;break;case Ul:t=ls.Subtract;break;case Fl:t=ls.ReverseSubtract;break;case Km:t=ls.Min;break;case qm:t=ls.Max;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const n={},r=this.backend.utils;switch(n.topology=r.getPrimitiveTopology(e,s),t.index!==null&&e.isLine===!0&&e.isLineSegments!==!0&&(n.stripIndexFormat=t.index.array instanceof Uint16Array?cn.Uint16:cn.Uint32),s.side){case No:n.frontFace=go.CCW,n.cullMode=mo.Back;break;case Ct:n.frontFace=go.CCW,n.cullMode=mo.Front;break;case js:n.frontFace=go.CCW,n.cullMode=mo.None;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side);break}return n}_getColorWriteMask(e){return e.colorWrite===!0?rl.All:rl.None}_getDepthCompare(e){let t;if(e.depthTest===!1)t=Fe.Always;else{const s=e.depthFunc;switch(s){case Jl:t=Fe.Never;break;case Zl:t=Fe.Always;break;case Ql:t=Fe.Less;break;case jl:t=Fe.LessEqual;break;case Yl:t=Fe.Equal;break;case Xl:t=Fe.GreaterEqual;break;case Kl:t=Fe.Greater;break;case ql:t=Fe.NotEqual;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class nR extends bg{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=e.alpha===void 0?!0:e.alpha,this.parameters.requiredLimits=e.requiredLimits===void 0?{}:e.requiredLimits,this.trackTimestamp=e.trackTimestamp===!0,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new jA(this),this.attributeUtils=new eR(this),this.bindingUtils=new tR(this),this.pipelineUtils=new sR(this),this.textureUtils=new OA(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(t.device===void 0){const i={powerPreference:t.powerPreference},a=typeof navigator<"u"?await navigator.gpu.requestAdapter(i):null;if(a===null)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const u=Object.values(ra),c=[];for(const d of u)a.features.has(d)&&c.push(d);const l={requiredFeatures:c,requiredLimits:t.requiredLimits};s=await a.requestDevice(l)}else s=t.device;s.lost.then(i=>{const a={api:"WebGPU",message:i.message||"Unknown reason",reason:i.reason||null,originalEvent:i};e.onDeviceLost(a)});const n=t.context!==void 0?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=n;const r=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ra.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return ln}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(e===null){const s=this.renderer;e={colorAttachments:[{view:null}]},(this.renderer.depth===!0||this.renderer.stencil===!0)&&(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(s.depth,s.stencil).createView()});const n=e.colorAttachments[0];this.renderer.samples>0?n.view=this.colorBuffer.createView():n.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e,t={}){const s=e.renderTarget,n=this.get(s);let r=n.descriptors;if(r===void 0||n.width!==s.width||n.height!==s.height||n.dimensions!==s.dimensions||n.activeMipmapLevel!==s.activeMipmapLevel||n.activeCubeFace!==e.activeCubeFace||n.samples!==s.samples||n.loadOp!==t.loadOp){r={},n.descriptors=r;const u=()=>{s.removeEventListener("dispose",u),this.delete(s)};s.addEventListener("dispose",u)}const i=e.getCacheKey();let a=r[i];if(a===void 0){const u=e.textures,c=[];let l;for(let d=0;d<u.length;d++){const h=this.get(u[d]),p={label:`colorAttachment_${d}`,baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1,dimension:$e.TwoD};s.isRenderTarget3D?(l=e.activeCubeFace,p.baseArrayLayer=0,p.dimension=$e.ThreeD,p.depthOrArrayLayers=u[d].image.depth):s.isRenderTargetArray&&(p.dimension=$e.TwoDArray,p.depthOrArrayLayers=u[d].image.depth);const f=h.texture.createView(p);let m,x;h.msaaTexture!==void 0?(m=h.msaaTexture.createView(),x=f):(m=f,x=void 0),c.push({view:m,depthSlice:l,resolveTarget:x,loadOp:ye.Load,storeOp:De.Store,...t})}if(a={colorAttachments:c},e.depth){const h={view:this.get(e.depthTexture).texture.createView()};a.depthStencilAttachment=h}r[i]=a,n.width=s.width,n.height=s.height,n.samples=s.samples,n.activeMipmapLevel=e.activeMipmapLevel,n.activeCubeFace=e.activeCubeFace,n.dimensions=s.dimensions,n.depthSlice=l,n.loadOp=c[0].loadOp}return a}beginRender(e){const t=this.get(e),s=this.device,n=e.occlusionQueryCount;let r;n>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:n,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=r,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(n),t.lastOcclusionObject=null);let i;e.textures===null?i=this._getDefaultRenderPassDescriptor():i=this._getRenderPassDescriptor(e,{loadOp:ye.Load}),this.initTimestampQuery(e,i),i.occlusionQuerySet=r;const a=i.depthStencilAttachment;if(e.textures!==null){const l=i.colorAttachments;for(let d=0;d<l.length;d++){const h=l[d];e.clearColor?(h.clearValue=d===0?e.clearColorValue:{r:0,g:0,b:0,a:1},h.loadOp=ye.Clear,h.storeOp=De.Store):(h.loadOp=ye.Load,h.storeOp=De.Store)}}else{const l=i.colorAttachments[0];e.clearColor?(l.clearValue=e.clearColorValue,l.loadOp=ye.Clear,l.storeOp=De.Store):(l.loadOp=ye.Load,l.storeOp=De.Store)}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=ye.Clear,a.depthStoreOp=De.Store):(a.depthLoadOp=ye.Load,a.depthStoreOp=De.Store)),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=ye.Clear,a.stencilStoreOp=De.Store):(a.stencilLoadOp=ye.Load,a.stencilStoreOp=De.Store));const u=s.createCommandEncoder({label:"renderContext_"+e.id}),c=u.beginRenderPass(i);if(t.descriptor=i,t.encoder=u,t.currentPass=c,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[],e.viewport&&this.updateViewport(e),e.scissor){const{x:l,y:d,width:h,height:p}=e.scissorValue;c.setScissorRect(l,d,h,p)}}finishRender(e){const t=this.get(e),s=e.occlusionQueryCount;if(t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const n=s*8;let r=this.occludedResolveCache.get(n);r===void 0&&(r=this.device.createBuffer({size:n,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(n,r));const i=this.device.createBuffer({size:n,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,r,0),t.encoder.copyBufferToBuffer(r,0,i,0,n),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),e.textures!==null){const n=e.textures;for(let r=0;r<n.length;r++){const i=n[r];i.generateMipmaps===!0&&this.textureUtils.generateMipmaps(i)}}}isOccluded(e,t){const s=this.get(e);return s.occluded&&s.occluded.has(t)}async resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueryBuffer:s,currentOcclusionQueryObjects:n}=t;if(s&&n){const r=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await s.mapAsync(GPUMapMode.READ);const i=s.getMappedRange(),a=new BigUint64Array(i);for(let u=0;u<n.length;u++)a[u]!==BigInt(0)&&r.add(n[u]);s.destroy(),t.occluded=r}}updateViewport(e){const{currentPass:t}=this.get(e),{x:s,y:n,width:r,height:i,minDepth:a,maxDepth:u}=e.viewportValue;t.setViewport(s,n,r,i,a,u)}clear(e,t,s,n=null){const r=this.device,i=this.renderer;let a=[],u,c,l,d;if(e){const f=this.getClearColor();if(this.renderer.alpha===!0){const m=f.a;c={r:f.r*m,g:f.g*m,b:f.b*m,a:m}}else c={r:f.r,g:f.g,b:f.b,a:f.a}}if(n===null){l=i.depth,d=i.stencil;const f=this._getDefaultRenderPassDescriptor();if(e){a=f.colorAttachments;const m=a[0];m.clearValue=c,m.loadOp=ye.Clear,m.storeOp=De.Store}(l||d)&&(u=f.depthStencilAttachment)}else l=n.depth,d=n.stencil,e&&(a=this._getRenderPassDescriptor(n,{loadOp:ye.Clear}).colorAttachments),(l||d)&&(u={view:this.get(n.depthTexture).texture.createView()});l&&(t?(u.depthLoadOp=ye.Clear,u.depthClearValue=i.getClearDepth(),u.depthStoreOp=De.Store):(u.depthLoadOp=ye.Load,u.depthStoreOp=De.Store)),d&&(s?(u.stencilLoadOp=ye.Clear,u.stencilClearValue=i.getClearStencil(),u.stencilStoreOp=De.Store):(u.stencilLoadOp=ye.Load,u.stencilStoreOp=De.Store));const h=r.createCommandEncoder({});h.beginRenderPass({colorAttachments:a,depthStencilAttachment:u}).end(),r.queue.submit([h.finish()])}beginCompute(e){const t=this.get(e),s={};this.initTimestampQuery(e,s),t.cmdEncoderGPU=this.device.createCommandEncoder(),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(s)}compute(e,t,s,n){const{passEncoderGPU:r}=this.get(e),i=this.get(n).pipeline;r.setPipeline(i);for(let l=0,d=s.length;l<d;l++){const h=s[l],p=this.get(h);r.setBindGroup(l,p.group)}const a=this.device.limits.maxComputeWorkgroupsPerDimension,u=this.get(t);u.dispatchSize===void 0&&(u.dispatchSize={x:0,y:1,z:1});const{dispatchSize:c}=u;t.dispatchCount>a?(c.x=Math.min(t.dispatchCount,a),c.y=Math.ceil(t.dispatchCount/a)):c.x=t.dispatchCount,r.dispatchWorkgroups(c.x,c.y,c.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:n,pipeline:r}=e,i=e.getBindings(),a=this.get(n),u=this.get(r).pipeline,c=a.currentSets,l=a.currentPass,d=e.getDrawParameters();if(d===null)return;c.pipeline!==u&&(l.setPipeline(u),c.pipeline=u);const h=c.bindingGroups;for(let x=0,N=i.length;x<N;x++){const v=i[x],w=this.get(v);h[v.index]!==v.id&&(l.setBindGroup(v.index,w.group),h[v.index]=v.id)}const p=e.getIndex(),f=p!==null;if(f===!0&&c.index!==p){const x=this.get(p).buffer,N=p.array instanceof Uint16Array?cn.Uint16:cn.Uint32;l.setIndexBuffer(x,N),c.index=p}const m=e.getVertexBuffers();for(let x=0,N=m.length;x<N;x++){const v=m[x];if(c.attributes[x]!==v){const w=this.get(v).buffer;l.setVertexBuffer(x,w),c.attributes[x]=v}}if(a.occlusionQuerySet!==void 0){const x=a.lastOcclusionObject;x!==s&&(x!==null&&x.occlusionTest===!0&&(l.endOcclusionQuery(),a.occlusionQueryIndex++),s.occlusionTest===!0&&(l.beginOcclusionQuery(a.occlusionQueryIndex),a.occlusionQueryObjects[a.occlusionQueryIndex]=s),a.lastOcclusionObject=s)}if(s.isBatchedMesh===!0){const x=s._multiDrawStarts,N=s._multiDrawCounts,v=s._multiDrawCount,w=s._multiDrawInstances;for(let B=0;B<v;B++){const F=w?w[B]:1,L=F>1?0:B;f===!0?l.drawIndexed(N[B],F,x[B]/p.array.BYTES_PER_ELEMENT,0,L):l.draw(N[B],F,x[B],L)}}else if(f===!0){const{vertexCount:x,instanceCount:N,firstVertex:v}=d,w=e.getIndirect();if(w!==null){const B=this.get(w).buffer;l.drawIndexedIndirect(B,0)}else l.drawIndexed(x,N,v,0,0);t.update(s,x,N)}else{const{vertexCount:x,instanceCount:N,firstVertex:v}=d,w=e.getIndirect();if(w!==null){const B=this.get(w).buffer;l.drawIndirect(B,0)}else l.draw(x,N,v,0);t.update(s,x,N)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:n}=e,r=this.utils,i=r.getSampleCountRenderContext(e.context),a=r.getCurrentColorSpace(e.context),u=r.getCurrentColorFormat(e.context),c=r.getCurrentDepthStencilFormat(e.context),l=r.getPrimitiveTopology(s,n);let d=!1;return(t.material!==n||t.materialVersion!==n.version||t.transparent!==n.transparent||t.blending!==n.blending||t.premultipliedAlpha!==n.premultipliedAlpha||t.blendSrc!==n.blendSrc||t.blendDst!==n.blendDst||t.blendEquation!==n.blendEquation||t.blendSrcAlpha!==n.blendSrcAlpha||t.blendDstAlpha!==n.blendDstAlpha||t.blendEquationAlpha!==n.blendEquationAlpha||t.colorWrite!==n.colorWrite||t.depthWrite!==n.depthWrite||t.depthTest!==n.depthTest||t.depthFunc!==n.depthFunc||t.stencilWrite!==n.stencilWrite||t.stencilFunc!==n.stencilFunc||t.stencilFail!==n.stencilFail||t.stencilZFail!==n.stencilZFail||t.stencilZPass!==n.stencilZPass||t.stencilFuncMask!==n.stencilFuncMask||t.stencilWriteMask!==n.stencilWriteMask||t.side!==n.side||t.alphaToCoverage!==n.alphaToCoverage||t.sampleCount!==i||t.colorSpace!==a||t.colorFormat!==u||t.depthStencilFormat!==c||t.primitiveTopology!==l||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(t.material=n,t.materialVersion=n.version,t.transparent=n.transparent,t.blending=n.blending,t.premultipliedAlpha=n.premultipliedAlpha,t.blendSrc=n.blendSrc,t.blendDst=n.blendDst,t.blendEquation=n.blendEquation,t.blendSrcAlpha=n.blendSrcAlpha,t.blendDstAlpha=n.blendDstAlpha,t.blendEquationAlpha=n.blendEquationAlpha,t.colorWrite=n.colorWrite,t.depthWrite=n.depthWrite,t.depthTest=n.depthTest,t.depthFunc=n.depthFunc,t.stencilWrite=n.stencilWrite,t.stencilFunc=n.stencilFunc,t.stencilFail=n.stencilFail,t.stencilZFail=n.stencilZFail,t.stencilZPass=n.stencilZPass,t.stencilFuncMask=n.stencilFuncMask,t.stencilWriteMask=n.stencilWriteMask,t.side=n.side,t.alphaToCoverage=n.alphaToCoverage,t.sampleCount=i,t.colorSpace=a,t.colorFormat=u,t.depthStencilFormat=c,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,n=this.utils,r=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,n.getSampleCountRenderContext(r),n.getCurrentColorSpace(r),n.getCurrentColorFormat(r),n.getCurrentDepthStencilFormat(r),n.getPrimitiveTopology(t,s),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)}copyTextureToBuffer(e,t,s,n,r,i){return this.textureUtils.copyTextureToBuffer(e,t,s,n,r,i)}initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){const n=e.isComputeNode?"compute":"render",r=this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_${n}_${e.id}`});Object.assign(t,{timestampWrites:{querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e),n=2*BigInt64Array.BYTES_PER_ELEMENT;s.currentTimestampQueryBuffers===void 0&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:n,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:n,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})});const{resolveBuffer:r,resultBuffer:i}=s.currentTimestampQueryBuffers;t.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),i.mapState==="unmapped"&&t.copyBufferToBuffer(r,0,i,0,n)}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(s.currentTimestampQueryBuffers===void 0)return;const{resultBuffer:n}=s.currentTimestampQueryBuffers;n.mapState==="unmapped"&&n.mapAsync(GPUMapMode.READ).then(()=>{const r=new BigUint64Array(n.getMappedRange()),i=Number(r[1]-r[0])/1e6;this.renderer.info.updateTimestamp(t,i),n.unmap()})}createNodeBuilder(e,t){return new YA(e,t)}createProgram(e){const t=this.get(e);t.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){const 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){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,n){this.bindingUtils.createBindings(e,t,s,n)}updateBindings(e,t,s,n){this.bindingUtils.createBindings(e,t,s,n)}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)}copyTextureToTexture(e,t,s=null,n=null,r=0){let i=0,a=0,u=0,c=0,l=0,d=0,h=e.image.width,p=e.image.height;s!==null&&(c=s.x,l=s.y,d=s.z||0,h=s.width,p=s.height),n!==null&&(i=n.x,a=n.y,u=n.z||0);const f=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),m=this.get(e).texture,x=this.get(t).texture;f.copyTextureToTexture({texture:m,mipLevel:r,origin:{x:c,y:l,z:d}},{texture:x,mipLevel:r,origin:{x:i,y:a,z:u}},[h,p,1]),this.device.queue.submit([f.finish()])}copyFramebufferToTexture(e,t,s){const n=this.get(t);let r=null;t.renderTarget?e.isDepthTexture?r=this.get(t.depthTexture).texture:r=this.get(t.textures[0]).texture:e.isDepthTexture?r=this.textureUtils.getDepthBuffer(t.depth,t.stencil):r=this.context.getCurrentTexture();const i=this.get(e).texture;if(r.format!==i.format){console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",r.format,i.format);return}let a;if(n.currentPass?(n.currentPass.end(),a=n.encoder):a=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),a.copyTextureToTexture({texture:r,origin:[s.x,s.y,0]},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),n.currentPass){const{descriptor:u}=n;for(let c=0;c<u.colorAttachments.length;c++)u.colorAttachments[c].loadOp=ye.Load;if(t.depth&&(u.depthStencilAttachment.depthLoadOp=ye.Load),t.stencil&&(u.depthStencilAttachment.stencilLoadOp=ye.Load),n.currentPass=a.beginRenderPass(u),n.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor){const{x:c,y:l,width:d,height:h}=t.scissorValue;n.currentPass.setScissorRect(c,l,d,h)}}else this.device.queue.submit([a.finish()])}}class rR extends dl{constructor(e,t,s,n,r,i){super(e,t,s,n,r,i),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class iR extends fg{constructor(){super(),this.addMaterial(TT,"MeshPhongMaterial"),this.addMaterial(nf,"MeshStandardMaterial"),this.addMaterial(rf,"MeshPhysicalMaterial"),this.addMaterial(t_,"MeshToonMaterial"),this.addMaterial(hT,"MeshBasicMaterial"),this.addMaterial(yT,"MeshLambertMaterial"),this.addMaterial(oT,"MeshNormalMaterial"),this.addMaterial(r_,"MeshMatcapMaterial"),this.addMaterial(Jx,"LineBasicMaterial"),this.addMaterial(tT,"LineDashedMaterial"),this.addMaterial(o_,"PointsMaterial"),this.addMaterial(c_,"SpriteMaterial"),this.addMaterial(h_,"ShadowMaterial"),this.addLight(iS,nm),this.addLight(Xv,rm),this.addLight(Yv,im),this.addLight(hg,dl),this.addLight(Qv,om),this.addLight(Zv,am),this.addLight(Jv,um),this.addLight(jv,rR),this.addToneMapping(Ef,cm),this.addToneMapping(wf,lm),this.addToneMapping(Mf,dm),this.addToneMapping(Bf,hm),this.addToneMapping(Ff,pm),this.addToneMapping(Uf,fm)}}class yR extends lA{constructor(e={}){let t;e.forceWebGL?t=nl:(t=nR,e.getFallback=()=>(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new nl(e)));const s=new t(e);super(s,e),this.library=new iR,this.isWebGPURenderer=!0}}class xR extends ll{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){e===!0&&this.version++}}const Sg=new ce,Fr=new Mi(Sg);class TR{constructor(e,t=P(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,Sg.name="PostProcessing"}render(){this._update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=ss,e.outputColorSpace=kt,Fr.render(e),e.toneMapping=t,e.outputColorSpace=s}_update(){if(this.needsUpdate===!0){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;Fr.material.fragmentNode=this.outputColorTransform===!0?tu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),Fr.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this._update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=ss,e.outputColorSpace=kt,await Fr.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}class _R extends aa{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=ft,this.minFilter=ft,this.isStorageTexture=!0}}class bR extends xf{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class oR extends Lg{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,n){const r=new Ig(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(e,i=>{try{t(this.parse(JSON.parse(i)))}catch(a){n?n(a):console.error(a),this.manager.itemError(e)}},s,n)}parseNodes(e){const t={};if(e!==void 0){for(const n of e){const{uuid:r,type:i}=n;t[r]=this.createNodeFromType(i),t[r].uuid=r}const s={nodes:t,textures:this.textures};for(const n of e)n.meta=s,t[n.uuid].deserialize(n),delete n.meta}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const n={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=n,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return this.nodes[e]===void 0?(console.error("THREE.NodeLoader: Node type not found:",e),g()):E(new this.nodes[e])}}class aR extends Vg{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,n=e.inputNodes;for(const r in n){const i=n[r];t[r]=s[i]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return t!==void 0?new t:super.createMaterialFromType(e)}}class NR extends Gg{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(e!==void 0){const s=new oR;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(e!==void 0){const n=this.parseNodes(this._nodesJSON,t),r=new aR;r.setTextures(t),r.setNodes(n),r.setNodeMaterials(this.nodeMaterials);for(let i=0,a=e.length;i<a;i++){const u=e[i];s[u.uuid]=r.parse(u)}}return s}}class SR extends ll{constructor(){super(),this.isClippingGroup=!0,this.clippingPlanes=[],this.enabled=!0,this.clipIntersection=!1,this.clipShadows=!1}}export{hm as ACESFilmicToneMapping,Fx as AONode,Gs as AddEquation,qg as AddOperation,RR as AdditiveAnimationBlendMode,qr as AdditiveBlending,pm as AgXToneMapping,Sm as AlphaFormat,Ml as AlwaysCompare,Zl as AlwaysDepth,Lm as AlwaysStencilFunc,om as AmbientLight,Qv as AmbientLightNode,Es as AnalyticLightNode,CR as AnimationAction,ER as AnimationClip,wR as AnimationLoader,MR as AnimationMixer,BR as AnimationObjectGroup,FR as AnimationUtils,UR as ArcCurve,PR as ArrayCamera,Rs as ArrayElementNode,DR as ArrowHelper,_y as AssignNode,LR as AttachedBindMode,Uh as AttributeNode,IR as Audio,VR as AudioAnalyser,GR as AudioContext,OR as AudioListener,kR as AudioLoader,zR as AxesHelper,Ct as BackSide,WR as BasicDepthPacking,_u as BasicEnvironmentNode,gm as BasicShadowMap,Ax as BatchNode,$R as BatchedMesh,HR as Bone,qR as BooleanKeyframeTrack,KR as Box2,XR as Box3,YR as Box3Helper,_l as BoxGeometry,jR as BoxHelper,Ur as BufferAttribute,Py as BufferAttributeNode,Sl as BufferGeometry,QR as BufferGeometryLoader,iu as BufferNode,Tx as BumpMapNode,xR as BundleGroup,Iy as BypassNode,An as ByteType,ZR as Cache,Ly as CacheNode,JR as Camera,e0 as CameraHelper,t0 as CanvasTexture,s0 as CapsuleGeometry,n0 as CatmullRomCurve3,dm as CineonToneMapping,r0 as CircleGeometry,ca as ClampToEdgeWrapping,SR as ClippingGroup,i0 as Clock,Ne as CodeNode,mt as Color,o0 as ColorKeyframeTrack,_t as ColorManagement,sr as ColorSpaceNode,a0 as CompressedArrayTexture,u0 as CompressedCubeTexture,c0 as CompressedTexture,l0 as CompressedTextureLoader,Dy as ComputeNode,d0 as ConeGeometry,yt as ConstNode,h0 as ConstantAlphaFactor,p0 as ConstantColorFactor,hh as ContextNode,f0 as Controls,nd as ConvertNode,Qg as CubeCamera,Zs as CubeReflectionMapping,Js as CubeRefractionMapping,td as CubeTexture,g0 as CubeTextureLoader,rx as CubeTextureNode,bo as CubeUVReflectionMapping,m0 as CubicBezierCurve,y0 as CubicBezierCurve3,x0 as CubicInterpolant,Tm as CullFaceBack,_m as CullFaceFront,T0 as CullFaceFrontBack,xm as CullFaceNone,_0 as Curve,b0 as CurvePath,Hl as CustomBlending,N0 as CustomToneMapping,S0 as CylinderGeometry,v0 as Cylindrical,A0 as Data3DTexture,Yg as DataArrayTexture,Cm as DataTexture,R0 as DataTextureLoader,C0 as DataUtils,Om as DecrementStencilOp,Vm as DecrementWrapStencilOp,E0 as DefaultLoadingManager,ai as DepthFormat,oi as DepthStencilFormat,vs as DepthTexture,w0 as DetachedBindMode,rm as DirectionalLight,M0 as DirectionalLightHelper,Xv as DirectionalLightNode,B0 as DiscreteInterpolant,F0 as DodecahedronGeometry,js as DoubleSide,Vl as DstAlphaFactor,Gl as DstColorFactor,U0 as DynamicCopyUsage,zs as DynamicDrawUsage,P0 as DynamicReadUsage,D0 as EdgesGeometry,L0 as EllipseCurve,KT as EnvironmentNode,El as EqualCompare,Yl as EqualDepth,Um as EqualStencilFunc,aT as EquirectUVNode,jn as EquirectangularReflectionMapping,Qn as EquirectangularRefractionMapping,Wg as Euler,gl as EventDispatcher,Vr as ExpressionNode,I0 as ExtrudeGeometry,Ig as FileLoader,yl as Float16BufferAttribute,ju as Float32BufferAttribute,ot as FloatType,V0 as Fog,G0 as FogExp2,bl as FramebufferTexture,nx as FrontFacingNode,No as FrontSide,tm as Frustum,by as FunctionCallNode,Pf as FunctionNode,Y_ as FunctionOverloadingNode,O0 as GLBufferAttribute,k0 as GLSL1,z0 as GLSL3,rA as GLSLNodeParser,Rl as GreaterCompare,Kl as GreaterDepth,Cl as GreaterEqualCompare,Xl as GreaterEqualDepth,Fm as GreaterEqualStencilFunc,Bm as GreaterStencilFunc,W0 as GridHelper,ll as Group,pt as HalfFloatType,am as HemisphereLight,$0 as HemisphereLightHelper,Zv as HemisphereLightNode,rR as IESSpotLight,jv as IESSpotLightNode,H0 as IcosahedronGeometry,q0 as ImageBitmapLoader,K0 as ImageLoader,X0 as ImageUtils,km as IncrementStencilOp,Gm as IncrementWrapStencilOp,de as IndexNode,bR as IndirectStorageBufferAttribute,Ep as InstanceNode,oa as InstancedBufferAttribute,Y0 as InstancedBufferGeometry,Cg as InstancedInterleavedBuffer,j0 as InstancedMesh,vx as InstancedMeshNode,dR as InstancedPointsNodeMaterial,Q0 as Int16BufferAttribute,Z0 as Int32BufferAttribute,J0 as Int8BufferAttribute,ze as IntType,Ag as InterleavedBuffer,Rg as InterleavedBufferAttribute,eC as Interpolant,tC as InterpolateDiscrete,sC as InterpolateLinear,nC as InterpolateSmooth,zm as InvertStencilOp,Px as IrradianceNode,ey as JoinNode,Hm as KeepStencilOp,rC as KeyframeTrack,iC as LOD,oC as LatheGeometry,aC as Layers,ua as LessCompare,Ql as LessDepth,wl as LessEqualCompare,jl as LessEqualDepth,Pm as LessEqualStencilFunc,Dm as LessStencilFunc,uC as Light,um as LightProbe,Jv as LightProbeNode,cA as Lighting,Ux as LightingContextNode,Ei as LightingModel,hn as LightingNode,Du as LightsNode,cC as Line,hR as Line2NodeMaterial,lC as Line3,Eg as LineBasicMaterial,Jx as LineBasicNodeMaterial,dC as LineCurve,hC as LineCurve3,pl as LineDashedMaterial,tT as LineDashedNodeMaterial,pC as LineLoop,fC as LineSegments,ft as LinearFilter,gC as LinearInterpolant,Jg as LinearMipMapLinearFilter,mC as LinearMipMapNearestFilter,ms as LinearMipmapLinearFilter,_o as LinearMipmapNearestFilter,kt as LinearSRGBColorSpace,cm as LinearToneMapping,yC as LinearTransfer,Lg as Loader,xC as LoaderUtils,TC as LoadingManager,Cx as LoopNode,_C as LoopOnce,bC as LoopPingPong,NC as LoopRepeat,Am as LuminanceAlphaFormat,vm as LuminanceFormat,SC as MOUSE,z_ as MRTNode,s_ as MatcapUVNode,Xu as Material,Vg as MaterialLoader,A as MaterialNode,ux as MaterialReferenceNode,ml as MathUtils,vC as Matrix2,Yn as Matrix3,Ie as Matrix4,qm as MaxEquation,zy as MaxMipLevelNode,tn as Mesh,fl as MeshBasicMaterial,hT as MeshBasicNodeMaterial,AC as MeshDepthMaterial,RC as MeshDistanceMaterial,wg as MeshLambertMaterial,yT as MeshLambertNodeMaterial,Mg as MeshMatcapMaterial,r_ as MeshMatcapNodeMaterial,Bg as MeshNormalMaterial,oT as MeshNormalNodeMaterial,Fg as MeshPhongMaterial,TT as MeshPhongNodeMaterial,Ug as MeshPhysicalMaterial,rf as MeshPhysicalNodeMaterial,pR as MeshSSSNodeMaterial,Pg as MeshStandardMaterial,nf as MeshStandardNodeMaterial,Dg as MeshToonMaterial,t_ as MeshToonNodeMaterial,Km as MinEquation,ci as MirroredRepeatWrapping,Kg as MixOperation,Mt as ModelNode,Bx as MorphNode,$r as MultiplyBlending,Xg as MultiplyOperation,bt as NearestFilter,CC as NearestMipMapLinearFilter,EC as NearestMipMapNearestFilter,Xs as NearestMipmapLinearFilter,So as NearestMipmapNearestFilter,fm as NeutralToneMapping,Bl as NeverCompare,Jl as NeverDepth,Im as NeverStencilFunc,en as NoBlending,Dn as NoColorSpace,ss as NoToneMapping,O as Node,Ve as NodeAccess,Gc as NodeAttribute,dg as NodeBuilder,to as NodeCache,Av as NodeCode,Kc as NodeFrame,$u as NodeFunctionInput,oR as NodeLoader,ce as NodeMaterial,aR as NodeMaterialLoader,jm as NodeMaterialObserver,NR as NodeObjectLoader,Oo as NodeShaderStage,Zm as NodeType,Sv as NodeUniform,W as NodeUpdateType,cR as NodeUtils,lg as NodeVar,vv as NodeVarying,wC as NormalAnimationBlendMode,Ys as NormalBlending,mx as NormalMapNode,Al as NotEqualCompare,ql as NotEqualDepth,Mm as NotEqualStencilFunc,MC as NumberKeyframeTrack,Zg as Object3D,J as Object3DNode,Gg as ObjectLoader,Og as ObjectSpaceNormalMap,BC as OctahedronGeometry,Wl as OneFactor,FC as OneMinusConstantAlphaFactor,UC as OneMinusConstantColorFactor,Pl as OneMinusDstAlphaFactor,Dl as OneMinusDstColorFactor,Ll as OneMinusSrcAlphaFactor,Il as OneMinusSrcColorFactor,Tl as OrthographicCamera,hf as OutputStructNode,em as PCFShadowMap,PC as PCFSoftShadowMap,$v as PMREMGenerator,$T as PMREMNode,df as ParameterNode,Ut as PassNode,DC as Path,kg as PerspectiveCamera,Hp as PhongLightingModel,Su as PhysicalLightingModel,vl as Plane,LC as PlaneGeometry,IC as PlaneHelper,nm as PointLight,VC as PointLightHelper,iS as PointLightNode,Fb as PointUVNode,GC as Points,hl as PointsMaterial,o_ as PointsNodeMaterial,OC as PolarGridHelper,kC as PolyhedronGeometry,zC as PositionalAudio,TR as PostProcessing,jb as PosterizeNode,WC as PropertyBinding,$C as PropertyMixer,se as PropertyNode,Mi as QuadMesh,HC as QuadraticBezierCurve,qC as QuadraticBezierCurve3,KC as Quaternion,XC as QuaternionKeyframeTrack,YC as QuaternionLinearInterpolant,nc as RED_GREEN_RGTC2_Format,Rm as RED_RGTC1_Format,xl as REVISION,jC as RGBADepthPacking,sn as RGBAFormat,fa as RGBAIntegerFormat,Io as RGBA_ASTC_10x10_Format,Po as RGBA_ASTC_10x5_Format,Do as RGBA_ASTC_10x6_Format,Lo as RGBA_ASTC_10x8_Format,Vo as RGBA_ASTC_12x10_Format,Go as RGBA_ASTC_12x12_Format,Ro as RGBA_ASTC_4x4_Format,Co as RGBA_ASTC_5x4_Format,Eo as RGBA_ASTC_5x5_Format,wo as RGBA_ASTC_6x5_Format,Mo as RGBA_ASTC_6x6_Format,Bo as RGBA_ASTC_8x5_Format,Fo as RGBA_ASTC_8x6_Format,Uo as RGBA_ASTC_8x8_Format,Ii as RGBA_BPTC_Format,Ao as RGBA_ETC2_EAC_Format,ec as RGBA_PVRTC_2BPPV1_Format,Ju as RGBA_PVRTC_4BPPV1_Format,Pr as RGBA_S3TC_DXT1_Format,Dr as RGBA_S3TC_DXT3_Format,Lr as RGBA_S3TC_DXT5_Format,QC as RGBDepthPacking,la as RGBFormat,Xm as RGBIntegerFormat,ZC as RGB_BPTC_SIGNED_Format,JC as RGB_BPTC_UNSIGNED_Format,tc as RGB_ETC1_Format,vo as RGB_ETC2_Format,Zu as RGB_PVRTC_2BPPV1_Format,Qu as RGB_PVRTC_4BPPV1_Format,Li as RGB_S3TC_DXT1_Format,eE as RGDepthPacking,Ln as RGFormat,pa as RGIntegerFormat,Tb as RTTNode,TN as RangeNode,tE as RawShaderMaterial,sE as Ray,nE as Raycaster,im as RectAreaLight,Yv as RectAreaLightNode,da as RedFormat,ha as RedIntegerFormat,Ai as ReferenceNode,Cu as ReflectorNode,lm as ReinhardToneMapping,wh as RemapNode,Gy as RenderOutputNode,Ss as RenderTarget,rE as RenderTarget3D,iE as RenderTargetArray,Fy as RendererReferenceNode,gR as RendererUtils,li as RepeatWrapping,Wm as ReplaceStencilOp,Fl as ReverseSubtractEquation,oE as RingGeometry,a_ as RotateNode,rc as SIGNED_RED_GREEN_RGTC2_Format,sc as SIGNED_RED_RGTC1_Format,q as SRGBColorSpace,Ku as SRGBTransfer,Nl as Scene,Ke as SceneNode,Se as ScreenNode,gN as ScriptableNode,pN as ScriptableValueNode,sy as SetNode,aE as ShaderMaterial,HN as ShadowBaseNode,$g as ShadowMaterial,jf as ShadowNode,h_ as ShadowNodeMaterial,uE as Shape,cE as ShapeGeometry,lE as ShapePath,dE as ShapeUtils,Rn as ShortType,hE as Skeleton,pE as SkeletonHelper,fE as SkinnedMesh,Bp as SkinningNode,gE as Source,mE as Sphere,mm as SphereGeometry,yE as Spherical,xE as SphericalHarmonics3,TE as SplineCurve,Wo as SplitNode,dl as SpotLight,_E as SpotLightHelper,hg as SpotLightNode,bE as Sprite,Hg as SpriteMaterial,c_ as SpriteNodeMaterial,cb as SpriteSheetUVNode,kl as SrcAlphaFactor,Ol as SrcAlphaSaturateFactor,zl as SrcColorFactor,O_ as StackNode,NE as StaticCopyUsage,vg as StaticDrawUsage,SE as StaticReadUsage,vE as StereoCamera,vb as StorageArrayElementNode,xf as StorageBufferAttribute,Rb as StorageBufferNode,Sb as StorageInstancedBufferAttribute,_R as StorageTexture,Pb as StorageTextureNode,AE as StreamCopyUsage,RE as StreamDrawUsage,CE as StreamReadUsage,EE as StringKeyframeTrack,Ul as SubtractEquation,Hr as SubtractiveBlending,wE as TOUCH,mR as TSL,Yu as TangentSpaceNormalMap,be as TempNode,ME as TetrahedronGeometry,aa as Texture,f_ as Texture3DNode,BE as TextureLoader,wt as TextureNode,ky as TextureSizeNode,FE as TextureUtils,Uy as ToneMappingNode,sN as ToonOutlinePassNode,UE as TorusGeometry,PE as TorusKnotGeometry,DE as Triangle,LE as TriangleFanDrawMode,IE as TriangleStripDrawMode,VE as TrianglesDrawMode,db as TriplanarTexturesNode,GE as TubeGeometry,zg as UVMapping,wm as Uint16BufferAttribute,Em as Uint32BufferAttribute,OE as Uint8BufferAttribute,kE as Uint8ClampedBufferAttribute,zE as Uniform,Kh as UniformArrayNode,xd as UniformGroupNode,er as UniformNode,WE as UniformsGroup,ys as UnsignedByteType,ui as UnsignedInt248Type,ed as UnsignedInt5999Type,Le as UnsignedIntType,bm as UnsignedShort4444Type,Nm as UnsignedShort5551Type,Ws as UnsignedShortType,Lb as UserDataNode,fr as VSMShadowMap,Ir as VarNode,Ey as VaryingNode,Ye as Vector2,j as Vector3,Me as Vector4,$E as VectorKeyframeTrack,Mb as VertexColorNode,HE as VideoTexture,qe as ViewportDepthNode,Ox as ViewportDepthTextureNode,sT as ViewportSharedTextureNode,Ci as ViewportTextureNode,fR as VolumeNodeMaterial,qE as WebGL3DRenderTarget,KE as WebGLArrayRenderTarget,Pn as WebGLCoordinateSystem,jg as WebGLCubeRenderTarget,XE as WebGLRenderTarget,ln as WebGPUCoordinateSystem,yR as WebGPURenderer,YE as WireframeGeometry,jE as WrapAroundEnding,QE as ZeroCurvatureEnding,$l as ZeroFactor,ZE as ZeroSlopeEnding,$m as ZeroStencilOp,ym as createCanvasElement,ko as defaultBuildStages,sd as defaultShaderStages,zo as shaderStages,As as vectorComponents};
|