1
0

three.webgpu.min.js 466 KB

123456
  1. /**
  2. * @license
  3. * Copyright 2010-2024 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. import{Color as e,Vector2 as t,Vector3 as s,Vector4 as r,Matrix3 as i,Matrix4 as n,EventDispatcher as o,MathUtils as a,ColorManagement as u,SRGBTransfer as l,NoToneMapping as d,StaticDrawUsage as c,InterleavedBuffer as h,DynamicDrawUsage as p,InterleavedBufferAttribute as g,NoColorSpace as m,UnsignedIntType as f,IntType as y,WebGLCoordinateSystem as b,BackSide as x,CubeReflectionMapping as T,CubeRefractionMapping as _,WebGPUCoordinateSystem as N,TangentSpaceNormalMap as v,ObjectSpaceNormalMap as S,InstancedInterleavedBuffer as A,InstancedBufferAttribute as R,DataArrayTexture as C,FloatType as E,FramebufferTexture as w,LinearMipmapLinearFilter as M,DepthTexture as B,Material as U,NormalBlending as F,PointsMaterial as P,LineBasicMaterial as I,LineDashedMaterial as L,MeshNormalMaterial as D,WebGLCubeRenderTarget as V,BoxGeometry as O,NoBlending as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as H,CubeTexture as W,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as K,MixOperation as X,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as se,MeshToonMaterial as re,MeshMatcapMaterial as ie,SpriteMaterial as ne,ShadowMaterial as oe,Uint32BufferAttribute as ae,Uint16BufferAttribute as ue,DoubleSide as le,DepthStencilFormat as de,DepthFormat as ce,UnsignedInt248Type as he,UnsignedByteType as pe,RenderTarget as ge,Plane as me,Object3D as fe,HalfFloatType as ye,LinearMipMapLinearFilter as be,OrthographicCamera as xe,BufferGeometry as Te,Float32BufferAttribute as _e,UVMapping as Ne,Euler as ve,LinearSRGBColorSpace as Se,LessCompare as Ae,VSMShadowMap as Re,RGFormat as Ce,SphereGeometry as Ee,BufferAttribute as we,CubeUVReflectionMapping as Me,PerspectiveCamera as Be,RGBAFormat as Ue,LinearMipmapNearestFilter as Fe,NearestMipmapLinearFilter as Pe,Float16BufferAttribute as Ie,REVISION as Le,SRGBColorSpace as De,PCFShadowMap as Ve,FrontSide as Oe,Frustum as Ge,DataTexture as ke,RedIntegerFormat as ze,RedFormat as $e,RGIntegerFormat as He,RGBIntegerFormat as We,RGBFormat as je,RGBAIntegerFormat as qe,UnsignedShortType as Ke,ByteType as Xe,ShortType as Ye,createCanvasElement as Qe,AddEquation as Ze,SubtractEquation as Je,ReverseSubtractEquation as et,ZeroFactor as tt,OneFactor as st,SrcColorFactor as rt,SrcAlphaFactor as it,SrcAlphaSaturateFactor as nt,DstColorFactor as ot,DstAlphaFactor as at,OneMinusSrcColorFactor as ut,OneMinusSrcAlphaFactor as lt,OneMinusDstColorFactor as dt,OneMinusDstAlphaFactor as ct,CullFaceNone as ht,CullFaceBack as pt,CullFaceFront as gt,CustomBlending as mt,MultiplyBlending as ft,SubtractiveBlending as yt,AdditiveBlending as bt,NotEqualDepth as xt,GreaterDepth as Tt,GreaterEqualDepth as _t,EqualDepth as Nt,LessEqualDepth as vt,LessDepth as St,AlwaysDepth as At,NeverDepth as Rt,UnsignedShort4444Type as Ct,UnsignedShort5551Type as Et,UnsignedInt5999Type as wt,AlphaFormat as Mt,LuminanceFormat as Bt,LuminanceAlphaFormat as Ut,RGB_S3TC_DXT1_Format as Ft,RGBA_S3TC_DXT1_Format as Pt,RGBA_S3TC_DXT3_Format as It,RGBA_S3TC_DXT5_Format as Lt,RGB_PVRTC_4BPPV1_Format as Dt,RGB_PVRTC_2BPPV1_Format as Vt,RGBA_PVRTC_4BPPV1_Format as Ot,RGBA_PVRTC_2BPPV1_Format as Gt,RGB_ETC1_Format as kt,RGB_ETC2_Format as zt,RGBA_ETC2_EAC_Format as $t,RGBA_ASTC_4x4_Format as Ht,RGBA_ASTC_5x4_Format as Wt,RGBA_ASTC_5x5_Format as jt,RGBA_ASTC_6x5_Format as qt,RGBA_ASTC_6x6_Format as Kt,RGBA_ASTC_8x5_Format as Xt,RGBA_ASTC_8x6_Format as Yt,RGBA_ASTC_8x8_Format as Qt,RGBA_ASTC_10x5_Format as Zt,RGBA_ASTC_10x6_Format as Jt,RGBA_ASTC_10x8_Format as es,RGBA_ASTC_10x10_Format as ts,RGBA_ASTC_12x10_Format as ss,RGBA_ASTC_12x12_Format as rs,RGBA_BPTC_Format as is,RED_RGTC1_Format as ns,SIGNED_RED_RGTC1_Format as os,RED_GREEN_RGTC2_Format as as,SIGNED_RED_GREEN_RGTC2_Format as us,RepeatWrapping as ls,ClampToEdgeWrapping as ds,MirroredRepeatWrapping as cs,NearestFilter as hs,NearestMipmapNearestFilter as ps,NeverCompare as gs,AlwaysCompare as ms,LessEqualCompare as fs,EqualCompare as ys,GreaterEqualCompare as bs,GreaterCompare as xs,NotEqualCompare as Ts,warnOnce as _s,NotEqualStencilFunc as Ns,GreaterStencilFunc as vs,GreaterEqualStencilFunc as Ss,EqualStencilFunc as As,LessEqualStencilFunc as Rs,LessStencilFunc as Cs,AlwaysStencilFunc as Es,NeverStencilFunc as ws,DecrementWrapStencilOp as Ms,IncrementWrapStencilOp as Bs,DecrementStencilOp as Us,IncrementStencilOp as Fs,InvertStencilOp as Ps,ReplaceStencilOp as Is,ZeroStencilOp as Ls,KeepStencilOp as Ds,MaxEquation as Vs,MinEquation as Os,SpotLight as Gs,PointLight as ks,DirectionalLight as zs,RectAreaLight as $s,AmbientLight as Hs,HemisphereLight as Ws,LightProbe as js,LinearToneMapping as qs,ReinhardToneMapping as Ks,CineonToneMapping as Xs,ACESFilmicToneMapping as Ys,AgXToneMapping as Qs,NeutralToneMapping as Zs,Group as Js,Loader as er,FileLoader as tr,MaterialLoader as sr,ObjectLoader as rr}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrayCamera,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BasicShadowMap,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Matrix2,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const ir=["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 nr{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=ir,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:s,material:r}=e;if(t={material:this.getMaterialData(r),geometry:{attributes:this.getAttributesData(s.attributes),indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:e.object.matrixWorld.clone()},e.object.center&&(t.center=e.object.center.clone()),e.object.morphTargetInfluences&&(t.morphTargetInfluences=e.object.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,i=this.getRenderObjectData(e);if(!0!==i.worldMatrix.equals(t.matrixWorld))return i.worldMatrix.copy(t.matrixWorld),!1;const n=i.material;for(const e in n){const t=n[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return n[e]=r,!1}if(n.transmission>0){const{width:t,height:s}=e.context;if(i.bufferWidth!==t||i.bufferHeight!==s)return i.bufferWidth=t,i.bufferHeight=s,!1}const o=i.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return i.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(i.morphTargetInfluences){let e=!1;for(let s=0;s<i.morphTargetInfluences.length;s++)i.morphTargetInfluences[s]!==t.morphTargetInfluences[s]&&(e=!0);if(e)return!0}return i.center&&!1===i.center.equals(t.center)?(i.center.copy(t.center),!0):(null!==e.bundle&&(i.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 r=!0===e.object.static,i=null!==e.bundle&&!0===e.bundle.static&&this.getRenderObjectData(e).version===e.bundle.version;if(r||i)return!1;return!0!==this.equals(e)}}function or(e,t=0){let s=3735928559^t,r=1103547991^t;if(e instanceof Array)for(let t,i=0;i<e.length;i++)t=e[i],s=Math.imul(s^t,2654435761),r=Math.imul(r^t,1597334677);else for(let t,i=0;i<e.length;i++)t=e.charCodeAt(i),s=Math.imul(s^t,2654435761),r=Math.imul(r^t,1597334677);return s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:i}of cr(e))s.push(s,or(r.slice(0,-4)),i.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;e<r.length;e++){const i=r[e];i&&(!0===i.isNode||t&&"function"==typeof i.toJSON)&&(yield{property:s,index:e,childNode:i})}else if(r&&!0===r.isNode)yield{property:s,childNode:r};else if("object"==typeof r)for(const e in r){const i=r[e];i&&(!0===i.isNode||t&&"function"==typeof i.toJSON)&&(yield{property:s,index:e,childNode:i})}}}function hr(e){if(null==e)return null;const t=typeof e;return!0===e.isNode?"node":"number"===t?"float":"boolean"===t?"bool":"string"===t?"string":"function"===t?"shader":!0===e.isVector2?"vec2":!0===e.isVector3?"vec3":!0===e.isVector4?"vec4":!0===e.isMatrix3?"mat3":!0===e.isMatrix4?"mat4":!0===e.isColor?"color":e instanceof ArrayBuffer?"ArrayBuffer":null}function pr(o,...a){const u=o?o.slice(-4):void 0;return 1===a.length&&("vec2"===u?a=[a[0],a[0]]:"vec3"===u?a=[a[0],a[0],a[0]]:"vec4"===u&&(a=[a[0],a[0],a[0],a[0]])),"color"===o?new e(...a):"vec2"===u?new t(...a):"vec3"===u?new s(...a):"vec4"===u?new r(...a):"mat3"===u?new i(...a):"mat4"===u?new n(...a):"bool"===o?a[0]||!1:"float"===o||"int"===o||"uint"===o?a[0]||0:"string"===o?a[0]||"":"ArrayBuffer"===o?mr(a[0]):null}function gr(e){let t="";const s=new Uint8Array(e);for(let e=0;e<s.length;e++)t+=String.fromCharCode(s[e]);return btoa(t)}function mr(e){return Uint8Array.from(atob(e),(e=>e.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.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 cr(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!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}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 e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)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 r=null;const i=e.getBuildStage();if("setup"===i){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===i)this.analyze(e);else if("generate"===i){if(1===this.generate.length){const s=this.getNodeType(e),i=e.getDataFromNode(this);r=i.snippet,void 0===r?(r=this.generate(e)||"",i.snippet=r):void 0!==i.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:i,childNode:n}of t)void 0!==i?(void 0===s[r]&&(s[r]=Number.isInteger(i)?[]:{}),s[r][i]=n.toJSON(e.meta).uuid):s[r]=n.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const i of e.inputNodes[s])r.push(t[i]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const i in e.inputNodes[s]){const n=e.inputNodes[s][i];r[i]=t[n]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let i=e.nodes[t];function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===i&&(i={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[i.uuid]=i),this.serialize(i),delete i.meta),r){const t=n(e.textures),s=n(e.images),r=n(e.nodes);t.length>0&&(i.textures=t),s.length>0&&(i.images=s),r.length>0&&(i.nodes=r)}return i}}class Rr extends Ar{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){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{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 r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);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,r=this.getNodeType(e),i=s.build(e,r);return e.format(i,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const i=super.build(e,s),n=e.getVarFromNode(this,null,s),o=e.getPropertyName(n);return e.addLineFlowCode(`${o} = ${i}`,this),r.snippet=i,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?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),r=this.nodes,i=e.getComponentType(s),n=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==i&&(s=e.format(s,r,i)),n.push(s)}const o=`${e.getType(s)}( ${n.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{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(vr.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,r=e.getTypeLength(s.getNodeType(e));let i=null;if(r>1){let n=null;this.getVectorLength()>=r&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,n);i=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,n,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else i=s.build(e,t);return i}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{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:r}=this,i=this.getNodeType(e),n=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,n),a=t.build(e,i),u=e.getTypeLength(i),l=[];for(let e=0;e<u;e++){const t=vr[e];t===s[0]?(l.push(o),e+=s.length-1):l.push(a+"."+t)}return`${e.getType(i)}( ${l.join(", ")} )`}}class Fr extends Er{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,r=this.getNodeType(e),i=s.build(e),n=e.getVarFromNode(this),o=e.getPropertyName(n);e.addLineFlowCode(o+" = "+i,this);const a=e.getTypeLength(r),u=[];let l=0;for(let e=0;e<a;e++){const s=vr[e];s===t[l]?(u.push("1.0 - "+o+"."+s),l++):u.push(o+"."+s)}return`${e.getType(r)}( ${u.join(", ")} )`}}class Pr extends Ar{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return null===this.nodeType?hr(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=hr(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=gr(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?pr(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 Ir extends Pr{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 Lr=null;const Dr=new Map;function Vr(e,t){if(Dr.has(e))console.warn(`Redefinition of method chaining ${e}`);else{if("function"!=typeof t)throw new Error(`Node element ${e} is not a function`);Dr.set(e,t)}}const Or=e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(hi(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),ci(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>ci(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>ci(new Fr(ci(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),ci(new Br(e,t));if(!0===/^\d+$/.test(t))return ci(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=ci(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;r<s;r++)e[r]=ci(e[r],t);return e},jr=function(e,t=null,s=null,r=null){const i=e=>ci(null!==r?Object.assign(e,r):e);return null===t?(...t)=>i(new e(...pi(t))):null!==s?(s=ci(s),(...r)=>i(new e(t,...pi(r),s))):(...s)=>i(new e(t,...pi(s)))},qr=function(e,...t){return ci(new e(...pi(t)))};class Kr extends Ar{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,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let i=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let n=r.get(t);void 0===n&&(n=ci(e.buildFunctionNode(t)),r.set(t,n)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(n),i=ci(n.call(s))}else{const r=t.jsFunc,n=null!==s?r(s,e):r(e);i=ci(n)}return t.once&&(r.onceOutput=i),i}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{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 hi(e),ci(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],ei=new Map;for(const e of Yr)ei.set(e,new Ir(e));const ti=new Map;for(const e of Qr)ti.set(e,new Ir(e,"uint"));const si=new Map([...ti].map((e=>new Ir(e.value,"int"))));for(const e of Zr)si.set(e,new Ir(e,"int"));const ri=new Map([...si].map((e=>new Ir(e.value))));for(const e of Jr)ri.set(e,new Ir(e));for(const e of Jr)ri.set(-e,new Ir(-e));const ii={bool:ei,uint:ti,ints:si,float:ri},ni=new Map([...ei,...ri]),oi=(e,t)=>ni.has(e)?ni.get(e):!0===e.isNode?e:new Ir(e,t),ai=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return ci(t.get(s[0]));if(1===s.length){const t=oi(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?ci(t):ci(new Cr(t,e))}const r=s.map((e=>oi(e)));return ci(new wr(r,e))}},ui=e=>"object"==typeof e&&null!==e?e.value:e,li=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function di(e,t){return new Proxy(new Xr(e,t),kr)}const ci=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?ci(oi(e,t)):"shader"===s?fi(e):e}(e,t),hi=(e,t=null)=>new Hr(e,t),pi=(e,t=null)=>new Wr(e,t),gi=(...e)=>new jr(...e),mi=(...e)=>new qr(...e),fi=(e,t)=>{const s=new di(e,t),r=(...e)=>{let t;return hi(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},yi=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),fi(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const bi=e=>{Lr=e},xi=()=>Lr,Ti=(...e)=>Lr.If(...e);function _i(e){return Lr&&Lr.add(e),e}Vr("append",_i);const Ni=new ai("color"),vi=new ai("float",ii.float),Si=new ai("int",ii.ints),Ai=new ai("uint",ii.uint),Ri=new ai("bool",ii.bool),Ci=new ai("vec2"),Ei=new ai("ivec2"),wi=new ai("uvec2"),Mi=new ai("bvec2"),Bi=new ai("vec3"),Ui=new ai("ivec3"),Fi=new ai("uvec3"),Pi=new ai("bvec3"),Ii=new ai("vec4"),Li=new ai("ivec4"),Di=new ai("uvec4"),Vi=new ai("bvec4"),Oi=new ai("mat2"),Gi=new ai("mat3"),ki=new ai("mat4"),zi=(e="")=>ci(new Ir(e,"string")),$i=e=>ci(new Ir(e,"ArrayBuffer"));Vr("toColor",Ni),Vr("toFloat",vi),Vr("toInt",Si),Vr("toUint",Ai),Vr("toBool",Ri),Vr("toVec2",Ci),Vr("toIVec2",Ei),Vr("toUVec2",wi),Vr("toBVec2",Mi),Vr("toVec3",Bi),Vr("toIVec3",Ui),Vr("toUVec3",Fi),Vr("toBVec3",Pi),Vr("toVec4",Ii),Vr("toIVec4",Li),Vr("toUVec4",Di),Vr("toBVec4",Vi),Vr("toMat2",Oi),Vr("toMat3",Gi),Vr("toMat4",ki);const Hi=gi(Rr),Wi=(e,t)=>ci(new Cr(ci(e),t)),ji=(e,t)=>ci(new Br(ci(e),t));Vr("element",Hi),Vr("convert",Wi);class qi extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}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 Ki=e=>new qi(e),Xi=(e,t=0)=>new qi(e,!0,t),Yi=Xi("frame"),Qi=Xi("render"),Zi=Ki("object");class Ji extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Zi}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((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let i=e.getNodeFromHash(r);void 0===i&&(e.setHashNode(this,r),i=this);const n=i.getInputType(e),o=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const en=(e,t)=>{const s=li(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return ci(new Ji(r,s))};class tn extends Ar{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!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const sn=(e,t)=>ci(new tn(e,t)),rn=(e,t)=>ci(new tn(e,t,!0)),nn=mi(tn,"vec4","DiffuseColor"),on=mi(tn,"vec3","EmissiveColor"),an=mi(tn,"float","Roughness"),un=mi(tn,"float","Metalness"),ln=mi(tn,"float","Clearcoat"),dn=mi(tn,"float","ClearcoatRoughness"),cn=mi(tn,"vec3","Sheen"),hn=mi(tn,"float","SheenRoughness"),pn=mi(tn,"float","Iridescence"),gn=mi(tn,"float","IridescenceIOR"),mn=mi(tn,"float","IridescenceThickness"),fn=mi(tn,"float","AlphaT"),yn=mi(tn,"float","Anisotropy"),bn=mi(tn,"vec3","AnisotropyT"),xn=mi(tn,"vec3","AnisotropyB"),Tn=mi(tn,"color","SpecularColor"),_n=mi(tn,"float","SpecularF90"),Nn=mi(tn,"float","Shininess"),vn=mi(tn,"vec4","Output"),Sn=mi(tn,"float","dashSize"),An=mi(tn,"float","gapSize"),Rn=mi(tn,"float","pointWidth"),Cn=mi(tn,"float","IOR"),En=mi(tn,"float","Transmission"),wn=mi(tn,"float","Thickness"),Mn=mi(tn,"float","AttenuationDistance"),Bn=mi(tn,"color","AttenuationColor"),Un=mi(tn,"float","Dispersion");class Fn extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,i=this.needsSplitAssign(e),n=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,n),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(i){const r=e.getVarFromNode(this,null,n),i=e.getPropertyName(r);e.addLineFlowCode(`${i} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t<s.components.length;t++){const r=s.components[t];e.addLineFlowCode(`${u}.${r} = ${i}[ ${t} ]`,this)}"void"!==t&&(d=o)}else d=`${o} = ${a}`,"void"!==t&&"void"!==u||(e.addLineFlowCode(d,this),"void"!==t&&(d=o));return l.initialized=!0,e.format(d,n,t)}}const Pn=gi(Fn);Vr("assign",Pn);class In extends Er{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,r=s.getInputs(e),i=this.parameters,n=(t,s)=>{const r=s.type;let i;return i="pointer"===r?"&"+t.build(e):t.build(e,r),i};if(Array.isArray(i))for(let e=0;e<i.length;e++)t.push(n(i[e],r[e]));else for(const e of r){const s=i[e.name];if(void 0===s)throw new Error(`FunctionCallNode: Input '${e.name}' not found in FunctionNode.`);t.push(n(s,e))}return`${s.build(e,"property")}( ${t.join(", ")} )`}}const Ln=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?pi(t):hi(t[0]),ci(new In(ci(e),t)));Vr("call",Ln);class Dn extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let i=new Dn(e,t,s);for(let t=0;t<r.length-1;t++)i=new Dn(e,i,r[t]);t=i,s=r[r.length-1]}this.op=e,this.aNode=t,this.bNode=s}getNodeType(e,t){const s=this.op,r=this.aNode,i=this.bNode,n=r.getNodeType(e),o=void 0!==i?i.getNodeType(e):null;if("void"===n||"void"===o)return"void";if("%"===s)return n;if("~"===s||"&"===s||"|"===s||"^"===s||">>"===s||"<<"===s)return e.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(n),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&e.isMatrix(o)?o:e.isMatrix(n)&&e.isVector(o)?e.getVectorFromMatrix(n):e.isVector(n)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(n)?o:n}generate(e,t){const s=this.op,r=this.aNode,i=this.bNode,n=this.getNodeType(e,t);let o=null,a=null;"void"!==n?(o=r.getNodeType(e),a=void 0!==i?i.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=n,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=n):o=a=n;const u=r.build(e,o),l=void 0!==i?i.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} < ${l} )`,n,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} <= ${l} )`,n,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} > ${l} )`,n,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} >= ${l} )`,n,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`( ${u} ${s} ${l} )`,n,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`${u} ${s} ${l}`,n,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vn=gi(Dn,"+"),On=gi(Dn,"-"),Gn=gi(Dn,"*"),kn=gi(Dn,"/"),zn=gi(Dn,"%"),$n=gi(Dn,"=="),Hn=gi(Dn,"!="),Wn=gi(Dn,"<"),jn=gi(Dn,">"),qn=gi(Dn,"<="),Kn=gi(Dn,">="),Xn=gi(Dn,"&&"),Yn=gi(Dn,"||"),Qn=gi(Dn,"!"),Zn=gi(Dn,"^^"),Jn=gi(Dn,"&"),eo=gi(Dn,"~"),to=gi(Dn,"|"),so=gi(Dn,"^"),ro=gi(Dn,"<<"),io=gi(Dn,">>");Vr("add",Vn),Vr("sub",On),Vr("mul",Gn),Vr("div",kn),Vr("modInt",zn),Vr("equal",$n),Vr("notEqual",Hn),Vr("lessThan",Wn),Vr("greaterThan",jn),Vr("lessThanEqual",qn),Vr("greaterThanEqual",Kn),Vr("and",Xn),Vr("or",Yn),Vr("not",Qn),Vr("xor",Zn),Vr("bitAnd",Jn),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",io);const no=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zn(...e));Vr("remainder",no);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return i>n&&i>o?t:n>o?s:o>i?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=n,r=o;e.isMatrix(s.getNodeType(e))?r=Ii(Bi(r),0):s=Ii(Bi(s),0);const i=Gn(s,r).xyz;return Ao(i).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+n.build(e,i)+" )",r,t);if(s===oo.ONE_MINUS)return On(1,n).build(e,t);if(s===oo.RECIPROCAL)return kn(1,n).build(e,t);if(s===oo.DIFFERENCE)return Fo(On(n,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(n.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),o.build(e,i)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(n.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):s===oo.REFRACT?l.push(n.build(e,i),o.build(e,i),a.build(e,"float")):s===oo.MIX?l.push(n.build(e,i),o.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)):(l.push(n.build(e,i)),null!==o&&l.push(o.build(e,i)),null!==a&&l.push(a.build(e,i))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=vi(1e-6),uo=vi(1e6),lo=vi(Math.PI),co=vi(2*Math.PI),ho=gi(oo,oo.ALL),po=gi(oo,oo.ANY),go=gi(oo,oo.EQUALS),mo=gi(oo,oo.RADIANS),fo=gi(oo,oo.DEGREES),yo=gi(oo,oo.EXP),bo=gi(oo,oo.EXP2),xo=gi(oo,oo.LOG),To=gi(oo,oo.LOG2),_o=gi(oo,oo.SQRT),No=gi(oo,oo.INVERSE_SQRT),vo=gi(oo,oo.FLOOR),So=gi(oo,oo.CEIL),Ao=gi(oo,oo.NORMALIZE),Ro=gi(oo,oo.FRACT),Co=gi(oo,oo.SIN),Eo=gi(oo,oo.COS),wo=gi(oo,oo.TAN),Mo=gi(oo,oo.ASIN),Bo=gi(oo,oo.ACOS),Uo=gi(oo,oo.ATAN),Fo=gi(oo,oo.ABS),Po=gi(oo,oo.SIGN),Io=gi(oo,oo.LENGTH),Lo=gi(oo,oo.NEGATE),Do=gi(oo,oo.ONE_MINUS),Vo=gi(oo,oo.DFDX),Oo=gi(oo,oo.DFDY),Go=gi(oo,oo.ROUND),ko=gi(oo,oo.RECIPROCAL),zo=gi(oo,oo.TRUNC),$o=gi(oo,oo.FWIDTH),Ho=gi(oo,oo.BITCAST),Wo=gi(oo,oo.TRANSPOSE),jo=gi(oo,oo.ATAN2),qo=gi(oo,oo.MIN),Ko=gi(oo,oo.MAX),Xo=gi(oo,oo.MOD),Yo=gi(oo,oo.STEP),Qo=gi(oo,oo.REFLECT),Zo=gi(oo,oo.DISTANCE),Jo=gi(oo,oo.DIFFERENCE),ea=gi(oo,oo.DOT),ta=gi(oo,oo.CROSS),sa=gi(oo,oo.POW),ra=gi(oo,oo.POW,2),ia=gi(oo,oo.POW,3),na=gi(oo,oo.POW,4),oa=gi(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gn(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=gi(oo,oo.MIX),da=(e,t=0,s=1)=>ci(new oo(oo.CLAMP,ci(e),ci(t),ci(s))),ca=e=>da(e),ha=gi(oo,oo.REFRACT),pa=gi(oo,oo.SMOOTHSTEP),ga=gi(oo,oo.FACEFORWARD),ma=fi((([e])=>{const t=ea(e.xy,Ci(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",ia),Vr("pow4",na),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,i=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=i,null!==r&&(e.getDataFromNode(r).parentNodeBlock=i);const n=e.getNodeProperties(this);n.condNode=t,n.ifNode=s.context({nodeBlock:s}),n.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:i,ifNode:n,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?sn(s).build(e):"";r.nodeProperty=u;const l=i.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=n.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=gi(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{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 r=this.node.build(e,t);return e.setContext(s),r}}const Na=gi(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{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,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),i=e.getPropertyName(r),n=t.build(e,r.type);return e.addLineFlowCode(`${i} = ${n}`,this),i}}const Aa=gi(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{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(void 0===s){const r=this.name,i=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,i),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),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);if(void 0===t.propertyName){const r=this.getNodeType(e),i=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,i),t.propertyName=i}return e.getPropertyName(s)}}const Ea=gi(Ca);Vr("varying",Ea);const wa=fi((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=fi((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{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===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let n=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(n=Ii(wa(n.rgb),n.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(n=Ii(Gi(u._getMatrix(new i,s,r)).mul(n.rgb),n.a)),u.getTransfer(r)===l&&(n=Ii(Ma(n.rgb),n.a)),n):n}}const Pa=e=>ci(new Fa(ci(e),Ba,Ua)),Ia=e=>ci(new Fa(ci(e),Ua,Ba)),La=(e,t)=>ci(new Fa(ci(e),Ba,t)),Da=(e,t)=>ci(new Fa(ci(e),t,Ba)),Va=(e,t,s)=>ci(new Fa(ci(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{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(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return ci(new Oa(this,ci(e)))}setNodeType(e){const t=en(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;e<t.length;e++)s=s[t[e]];return s}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}class ka extends Ga{static get type(){return"RendererReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.renderer=s,this.setGroup(Qi)}updateReference(e){return this.reference=null!==this.renderer?this.renderer:e.renderer,this.reference}}const za=(e,t,s)=>ci(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const i=e.renderer.library.getToneMappingFunction(s);return null!==i?r=Ii(i(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>ci(new $a(e,ci(t),ci(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),i=this.bufferStride||r,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,i),a=new g(o,r,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let i=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,i=r;else{i=Ea(this).build(e,t)}return i}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>ci(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{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.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;e<t.length;e++)s*=t[e];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("compute"===t){const t=this.computeNode.build(e,"void");""!==t&&e.addLineFlowCode(t,this)}}}const Za=(e,t,s)=>ci(new Qa(ci(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const i=this.node.build(e,...t);return e.setCache(s),i}}const eu=(e,...t)=>ci(new Ja(ci(e),...t));Vr("cache",eu);class tu extends Ar{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 su=gi(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=vi(0),i=vi(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=i,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:i,doClamp:n}=this;let o=e.sub(t).div(s.sub(t));return!0===n&&(o=o.clamp()),o.mul(i.sub(r)).add(r)}}const iu=gi(ru,null,null,{doClamp:!1}),nu=gi(ru);Vr("remap",iu),Vr("remapClamp",nu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=gi(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>ci(new du(ci(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}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(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),i=e.getTypeFromAttribute(r),n=e.getAttribute(t,i);if("vertex"===e.shaderStage)return e.format(n.name,i,s);return Ea(this).build(e,s)}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 gu=(e,t)=>ci(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{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"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=gi(fu);class bu extends Ji{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.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&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=gi(bu);class Tu extends Ji{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=en(this.value.matrix)),this._matrixUniform.mul(Bi(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return!e.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(t=this.sampler?t.flipY():t.setY(Si(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,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,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,i,n,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,n):i?e.generateTextureBias(u,t,s,i,n):a?e.generateTextureGrad(u,t,s,a,n):o?e.generateTextureCompare(u,t,s,o,n):!1===this.sampler?e.generateTextureLoad(u,t,s,n):e.generateTexture(u,t,s,n),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const i=super.generate(e,"property");if("sampler"===t)return i+"_sampler";if(e.isReference(t))return i;{const n=e.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,i,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),n.snippet=b,n.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}blur(e){const t=this.clone();return t.biasNode=ci(e).mul(xu(t)),t.referenceNode=this.getSelf(),ci(t)}level(e){const t=this.clone();return t.levelNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}compare(e){const t=this.clone();return t.compareNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}grad(e,t){const s=this.clone();return s.gradNode=[ci(e),ci(t)],s.referenceNode=this.getSelf(),ci(s)}depth(e){const t=this.clone();return t.depthNode=ci(e),t.referenceNode=this.getSelf(),ci(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;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=gi(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=en("float").label("cameraNear").setGroup(Qi).onRenderUpdate((({camera:e})=>e.near)),Au=en("float").label("cameraFar").setGroup(Qi).onRenderUpdate((({camera:e})=>e.far)),Ru=en("mat4").label("cameraProjectionMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=en("mat4").label("cameraProjectionMatrixInverse").setGroup(Qi).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=en("mat4").label("cameraViewMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=en("mat4").label("cameraWorldMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=en("mat3").label("cameraNormalMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=en(new s).label("cameraPosition").setGroup(Qi).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new Ji(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,i=this.scope;if(i===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(i===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(i===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(i===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(i===Uu.VIEW_POSITION){const i=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(i.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.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}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=gi(Uu,Uu.DIRECTION),Pu=gi(Uu,Uu.WORLD_MATRIX),Iu=gi(Uu,Uu.POSITION),Lu=gi(Uu,Uu.SCALE),Du=gi(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=mi(Vu,Vu.DIRECTION),Gu=mi(Vu,Vu.WORLD_MATRIX),ku=mi(Vu,Vu.POSITION),zu=mi(Vu,Vu.SCALE),$u=mi(Vu,Vu.VIEW_POSITION),Hu=en(new i).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=en(new n).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=fi((e=>(e.context.isHighPrecisionModelViewMatrix=!0,en("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=fi((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return en("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=mi(sl),il=vi(rl).mul(2).sub(1),nl=gu("normal","vec3"),ol=fi((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Bi(0,1,0)):nl),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=fi((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=fi((e=>e.context.setupNormal()),"vec3").once()().mul(il).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=fi((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(il).toVar("transformedClearcoatNormalView"),pl=fi((([e,t=Gu])=>{const s=Gi(t),r=e.div(Bi(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=fi((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=en(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Bi(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Bi(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=gi(Tl);class Nl extends Ji{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 vl=(e,t,s)=>ci(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;s<e.length;s++){t[4*s]=e[s]}else if("color"===r)for(let s=0;s<e.length;s++){const r=4*s,i=e[s];t[r]=i.r,t[r+1]=i.g,t[r+2]=i.b||0}else for(let s=0;s<e.length;s++){const r=4*s,i=e[s];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;this._elementType=null===this.elementType?hr(this.array[0]):this.elementType,this._elementLength=e.getTypeLength(this._elementType);let s=Float32Array;return"i"===this._elementType.charAt(0)?s=Int32Array:"u"===this._elementType.charAt(0)&&(s=Uint32Array),this.value=new s(4*t),this.bufferCount=t,this.bufferType=e.changeComponentType("vec4",e.getComponentType(this._elementType)),super.setup(e)}element(e){return ci(new Sl(this,ci(e)))}}const Rl=(e,t)=>ci(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),ci(new Al(e,t)));class El extends Rr{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(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return ci(new El(this,ci(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):en(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;e<t.length;e++)s=s[t[e]];return s}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}const Ml=(e,t,s)=>ci(new wl(e,t,s)),Bl=(e,t,s,r)=>ci(new wl(e,t,r,s));class Ul extends wl{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=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>ci(new Ul(e,t,s)),Pl=fi((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ii(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(nl.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=Gi(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xn.cross(tl);return e=e.cross(xn).normalize(),e=la(e,dl,yn.mul(an.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=fi((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:i}=e,n=t.dFdx(),o=t.dFdy(),a=i.dFdx(),u=i.dFdy(),l=s,d=o.cross(l),c=l.cross(n),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=il.mul(g.inverseSqrt());return Vn(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Bi(r.xy.mul(s),r.z));let i=null;if(t===S)i=gl(r);else if(t===v){i=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return i}}const Jl=gi(Zl),ed=fi((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=vi(s((e=>e)));return Ci(vi(s((e=>e.add(e.dFdx())))).sub(r),vi(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=fi((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,i=t.dFdx().normalize(),n=s,o=t.dFdy().normalize().cross(n),a=n.cross(i),u=i.dot(o).mul(il),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=gi(sd),id=new Map;class nd extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=id.get(e);return void 0===s&&(s=Fl(e,t),id.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===nd.COLOR){const e=void 0!==t.color?this.getColor(s):Bi();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===nd.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===nd.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:vi(1);else if(s===nd.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===nd.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===nd.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===nd.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===nd.EMISSIVE){const e=this.getFloat("emissiveIntensity"),i=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?i.mul(this.getTexture(s)):i}else if(s===nd.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===nd.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===nd.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===nd.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===nd.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===nd.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===nd.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Oi($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(Ci(1)).normalize().mul(e.b))}else r=$d;else if(s===nd.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const i=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(i).mul(this.getTexture(s).g).add(i)}else r=e}else if(s===nd.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===nd.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===nd.IOR)r=this.getFloat(s);else if(s===nd.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===nd.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}nd.ALPHA_TEST="alphaTest",nd.COLOR="color",nd.OPACITY="opacity",nd.SHININESS="shininess",nd.SPECULAR="specular",nd.SPECULAR_STRENGTH="specularStrength",nd.SPECULAR_INTENSITY="specularIntensity",nd.SPECULAR_COLOR="specularColor",nd.REFLECTIVITY="reflectivity",nd.ROUGHNESS="roughness",nd.METALNESS="metalness",nd.NORMAL="normal",nd.CLEARCOAT="clearcoat",nd.CLEARCOAT_ROUGHNESS="clearcoatRoughness",nd.CLEARCOAT_NORMAL="clearcoatNormal",nd.EMISSIVE="emissive",nd.ROTATION="rotation",nd.SHEEN="sheen",nd.SHEEN_ROUGHNESS="sheenRoughness",nd.ANISOTROPY="anisotropy",nd.IRIDESCENCE="iridescence",nd.IRIDESCENCE_IOR="iridescenceIOR",nd.IRIDESCENCE_THICKNESS="iridescenceThickness",nd.IOR="ior",nd.TRANSMISSION="transmission",nd.THICKNESS="thickness",nd.ATTENUATION_DISTANCE="attenuationDistance",nd.ATTENUATION_COLOR="attenuationColor",nd.LINE_SCALE="scale",nd.LINE_DASH_SIZE="dashSize",nd.LINE_GAP_SIZE="gapSize",nd.LINE_WIDTH="linewidth",nd.LINE_DASH_OFFSET="dashOffset",nd.POINT_WIDTH="pointWidth",nd.DISPERSION="dispersion",nd.LIGHT_MAP="light",nd.AO_MAP="ao";const od=mi(nd,nd.ALPHA_TEST),ad=mi(nd,nd.COLOR),ud=mi(nd,nd.SHININESS),ld=mi(nd,nd.EMISSIVE),dd=mi(nd,nd.OPACITY),cd=mi(nd,nd.SPECULAR),hd=mi(nd,nd.SPECULAR_INTENSITY),pd=mi(nd,nd.SPECULAR_COLOR),gd=mi(nd,nd.SPECULAR_STRENGTH),md=mi(nd,nd.REFLECTIVITY),fd=mi(nd,nd.ROUGHNESS),yd=mi(nd,nd.METALNESS),bd=mi(nd,nd.NORMAL).context({getUV:null}),xd=mi(nd,nd.CLEARCOAT),Td=mi(nd,nd.CLEARCOAT_ROUGHNESS),_d=mi(nd,nd.CLEARCOAT_NORMAL).context({getUV:null}),Nd=mi(nd,nd.ROTATION),vd=mi(nd,nd.SHEEN),Sd=mi(nd,nd.SHEEN_ROUGHNESS),Ad=mi(nd,nd.ANISOTROPY),Rd=mi(nd,nd.IRIDESCENCE),Cd=mi(nd,nd.IRIDESCENCE_IOR),Ed=mi(nd,nd.IRIDESCENCE_THICKNESS),wd=mi(nd,nd.TRANSMISSION),Md=mi(nd,nd.THICKNESS),Bd=mi(nd,nd.IOR),Ud=mi(nd,nd.ATTENUATION_DISTANCE),Fd=mi(nd,nd.ATTENUATION_COLOR),Pd=mi(nd,nd.LINE_SCALE),Id=mi(nd,nd.LINE_DASH_SIZE),Ld=mi(nd,nd.LINE_GAP_SIZE),Dd=mi(nd,nd.LINE_WIDTH),Vd=mi(nd,nd.LINE_DASH_OFFSET),Od=mi(nd,nd.POINT_WIDTH),Gd=mi(nd,nd.DISPERSION),kd=mi(nd,nd.LIGHT_MAP),zd=mi(nd,nd.AO_MAP),$d=en(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=gi(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,i;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)i=r;else{i=Ea(this).build(e,t)}return i}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=mi(jd,jd.VERTEX),Kd=mi(jd,jd.INSTANCE),Xd=mi(jd,jd.SUBGROUP),Yd=mi(jd,jd.INVOCATION_SUBGROUP),Qd=mi(jd,jd.INVOCATION_LOCAL),Zd=mi(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,i=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=ki(...i)}this.instanceMatrixNode=t}const i=r.instanceColor;if(i&&null===s){const e=new R(i.array,3),t=i.usage===p?Ya:Xa;this.bufferColor=e,s=Bi(t(e,"vec3",3,0)),this.instanceColorNode=s}const n=t.mul(Yu).xyz;if(Yu.assign(n),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&rn("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=gi(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=fi((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=Si(e).modInt(Si(t)),r=Si(e).div(Si(t));return Nu(this.batchMesh._indirectTexture,Ei(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(Si(this.batchingIdNode)),r=this.batchMesh._matricesTexture,i=yu(Nu(r),0),n=vi(s).mul(4).toInt().toVar(),o=n.modInt(i),a=n.div(Si(i)),u=ki(Nu(r,Ei(o,a)),Nu(r,Ei(o.add(1),a)),Nu(r,Ei(o.add(2),a)),Nu(r,Ei(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=fi((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),i=s.div(t);return Nu(l,Ei(r,i)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);rn("vec3","vBatchColor").assign(t)}const d=Gi(u);Yu.assign(u.mul(Yu));const c=ol.div(Bi(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=gi(tc),rc=new WeakMap;class ic extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,i;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),i=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=en(e.bindMatrix,"mat4"),r=en(e.bindMatrixInverse,"mat4"),i=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=i,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=i.mul(t),c=Vn(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return n.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vn(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=n.mul(d).mul(i),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const nc=e=>ci(new ic(e)),oc=e=>ci(new ic(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;e<t;e++){const t=this.params[e],r=!0!==t.isNode&&t.name||this.getVarName(e),i=!0!==t.isNode&&t.type||"int";s[r]=au(r,i)}const r=e.addStack();return t.returnsNode=this.params[this.params.length-1](s,r,e),t.stackNode=r,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,r=t.stackNode;for(let t=0,r=s.length-1;t<r;t++){const r=s[t];let i=null,n=null,o=null,a=null,u=null,l=null;r.isNode?(a="int",o=this.getVarName(t),i="0",n=r.build(e,a),u="<"):(a=r.type||"int",o=r.name||this.getVarName(t),i=r.start,n=r.end,u=r.condition,l=r.update,"number"==typeof i?i=e.generateConst(a,i):i&&i.isNode&&(i=i.build(e,a)),"number"==typeof n?n=e.generateConst(a,n):n&&n.isNode&&(n=n.build(e,a)),void 0!==i&&void 0===n?(i+=" - 1",n="0",u=">="):void 0!==n&&void 0===i&&(i="0",u="<"),void 0===u&&(u=Number(i)>Number(n)?">=":"<"));const d={start:i,end:n,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const i=r.build(e,"void"),n=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+i);for(let t=0,s=this.params.length-1;t<s;t++)e.addFlowCode((0===t?"":e.tab)+"}\n\n").removeFlowTab();return e.addFlowTab(),n}}const uc=(...e)=>ci(new ac(pi(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=fi((({bufferMap:e,influence:t,stride:s,width:r,depth:i,offset:n})=>{const o=Si(qd).mul(s).add(n),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,Ei(u,a)).depth(i).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=en(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,i=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,n=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==n?n.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,n=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==n?n.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===i&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x<o;x++){const T=u[x],_=l[x],N=d[x],v=h*p*4*x;for(let S=0;S<T.count;S++){const A=S*y;!0===s&&(pc.fromBufferAttribute(T,S),m[v+A+0]=pc.x,m[v+A+1]=pc.y,m[v+A+2]=pc.z,m[v+A+3]=0),!0===r&&(pc.fromBufferAttribute(_,S),m[v+A+4]=pc.x,m[v+A+5]=pc.y,m[v+A+6]=pc.z,m[v+A+7]=0),!0===i&&(pc.fromBufferAttribute(N,S),m[v+A+8]=pc.x,m[v+A+9]=pc.y,m[v+A+10]=pc.z,m[v+A+11]=4===N.itemSize?pc.w:1)}}function b(){f.dispose(),hc.delete(e),e.removeEventListener("dispose",b)}a={count:o,texture:f,stride:c,size:new t(h,p)},hc.set(e,a),e.addEventListener("dispose",b)}return a}(s);!0===r&&Yu.mulAssign(this.morphBaseInfluence),!0===i&&ol.mulAssign(this.morphBaseInfluence);const d=Si(l.width);uc(o,(({i:e})=>{const t=vi(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,Ei(Si(e).add(1),Si(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Si(0)})),!0===i&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Si(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=gi(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Bi().toVar("directDiffuse"),directSpecular:Bi().toVar("directSpecular"),indirectDiffuse:Bi().toVar("indirectDiffuse"),indirectSpecular:Bi().toVar("indirectSpecular")};return{radiance:Bi().toVar("radiance"),irradiance:Bi().toVar("irradiance"),iblIrradiance:Bi().toVar("iblIrradiance"),ambientOcclusion:vi(1).toVar("ambientOcclusion"),reflectedLight:s,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 Tc=gi(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?en(Nc||(Nc=new t)):e===Sc.VIEWPORT?en(vc||(vc=new r)):Ci(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=mi(Sc,Sc.UV),Rc=mi(Sc,Sc.SIZE),Cc=mi(Sc,Sc.COORDINATE),Ec=mi(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=fi((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=fi((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=fi((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=gi(Lc),Vc=gi(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=gi(Gc);class zc extends Ar{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===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Kc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.div(t).add(1)),i=To(s.div(t).add(1));return r.div(i)},Kc=gi(zc,zc.DEPTH_BASE),Xc=mi(zc,zc.DEPTH),Yc=gi(zc,zc.LINEAR_DEPTH),Qc=Yc(kc());Xc.assign=e=>Kc(e);const Zc=gi(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class Jc extends Ar{static get type(){return"ClippingNode"}constructor(e=Jc.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===Jc.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===Jc.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return fi((()=>{const s=vi().toVar("distanceToPlane"),r=vi().toVar("distanceToGradient"),i=vi(1).toVar("clipOpacity"),n=t.length;if(!this.hardwareClipping&&n>0){const e=Rl(t);uc(n,(({i:t})=>{const n=e.element(t);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),n=vi(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const i=t.element(e);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s).oneMinus())})),i.mulAssign(n.oneMinus())}nn.a.mulAssign(i),nn.a.equal(0).discard()}))()}setupDefault(e,t){return fi((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Ri(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),fi((()=>{const r=Rl(e),i=Zc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();i.element(e).assign(s)}))}))()}}Jc.ALPHA_TO_COVERAGE="alphaToCoverage",Jc.DEFAULT="default",Jc.HARDWARE="hardware";const eh=fi((([e])=>Ro(Gn(1e4,Co(Gn(17,e.x).add(Gn(.1,e.y)))).mul(Vn(.1,Fo(Co(Gn(13,e.y).add(e.x)))))))),th=fi((([e])=>eh(Ci(eh(e.xy),e.z)))),sh=fi((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=vi(1).div(vi(.05).mul(t)).toVar("pixScale"),r=Ci(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),i=Ci(th(vo(r.x.mul(e.xyz))),th(vo(r.y.mul(e.xyz)))).toVar("alpha"),n=Ro(To(s)).toVar("lerpFactor"),o=Vn(Gn(n.oneMinus(),i.x),Gn(n,i.y)).toVar("x"),a=qo(n,n.oneMinus()).toVar("a"),u=Bi(o.mul(o).div(Gn(2,a).mul(On(1,a))),o.sub(Gn(.5,a)).div(On(1,a)),On(1,On(1,o).mul(On(1,o)).div(Gn(2,a).mul(On(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class rh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,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.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new nr(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const i=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const n=this.setupLighting(e);null!==i&&e.stack.add(i);const o=Ii(n,nn.a).max(0);if(r=this.setupOutput(e,o),vn.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ii(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=ci(new Jc(Jc.ALPHA_TO_COVERAGE)):e.stack.add(ci(new Jc))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(ci(new Jc(Jc.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(Wd().w,Su,Au):$c(el.z,Su,Au))}null!==r&&Xc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ii(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ii(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=rn("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=rn("vec3","vBatchColor").mul(s)}nn.assign(s);const r=this.opacityNode?vi(this.opacityNode):dd;if(nn.a.assign(nn.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?vi(this.alphaTestNode):od;nn.a.lessThanEqual(e).discard()}!0===this.alphaHash&&nn.a.lessThan(sh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&nn.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Bi(0):nn.rgb}setupNormal(){return this.normalNode?Bi(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let i=this.lightsNode||e.lightsNode;return t.length>0&&(i=e.renderer.lighting.createNode([...i.getLights(),...t])),i}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:i}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(n&&n.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(n,t,s,r)}else null!==s&&(o=Bi(null!==r?la(o,s,r):s));return(i&&!0===i.isNode||t.emissive&&!0===t.emissive.isColor)&&(on.assign(Bi(i||ld)),o=o.add(on)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ii(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:i}of r)s.inputNodes[t]=i.toJSON(e).uuid;function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=i(e.textures),r=i(e.images),n=i(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),n.length>0&&(s.nodes=n)}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.shadowNode=e.shadowNode,this.shadowPositionNode=e.shadowPositionNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class nh extends rh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=fi((()=>{const e=gu("instancePosition").xyz,t=Ii(ju.mul(Ii(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),i=Xu.xy.toVar();return i.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),i.assign(i.div(Ec.z)),i.y.assign(i.y.mul(s)),i.assign(i.mul(r.w)),r.addAssign(Ii(i,0,0)),r}))(),this.fragmentNode=fi((()=>{const r=vi(1).toVar(),i=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=vi(i.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),i).oneMinus())}else i.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(s){n=gu("instanceColor").mul(ad)}else n=ad;return r.mulAssign(dd),Ii(n,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const oh=new I;class ah extends rh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(oh),this.setValues(e)}}const uh=new L;class lh extends rh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(uh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?vi(this.offsetNodeNode):Vd,t=this.dashScaleNode?vi(this.dashScaleNode):Pd,s=this.dashSizeNode?vi(this.dashSizeNode):Id,r=this.dashSizeNode?vi(this.dashGapNode):Ld;Sn.assign(s),An.assign(r);const i=Ea(gu("lineDistance").mul(t));(e?i.add(e):i).mod(Sn.add(An)).greaterThan(Sn).discard()}}const dh=new L;class ch extends rh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(dh),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,i=this.worldUnits,n=fi((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ii(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=fi((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ii(ju.mul(Ii(e,1))).toVar("start"),o=Ii(ju.mul(Ii(t,1))).toVar("end");if(r){const e=this.dashScaleNode?vi(this.dashScaleNode):Pd,t=this.offsetNode?vi(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let i=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));i=i.add(t),rn("float","lineDistance").assign(i)}i&&(rn("vec3","worldStart").assign(s.xyz),rn("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);Ti(u,(()=>{Ti(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(n({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(n({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ii().toVar();if(i){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),i=e.cross(t).normalize(),n=e.cross(i),a=rn("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ii(Xu.x.lessThan(0).select(i.mul(u),i.mul(u).negate()),0)),r||(a.addAssign(Ii(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ii(n.mul(u),0)),Ti(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ii(n.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Bi().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=Ci(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),Ti(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ii(e,0,0)))}return g}))();const o=fi((({p1:e,p2:t,p3:s,p4:r})=>{const i=e.sub(s),n=r.sub(s),o=t.sub(e),a=i.dot(n),u=n.dot(o),l=i.dot(o),d=n.dot(n),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return Ci(h,p)}));this.fragmentNode=fi((()=>{const n=mu();if(r){const e=this.dashSizeNode?vi(this.dashSizeNode):Id,t=this.dashSizeNode?vi(this.dashGapNode):Ld;Sn.assign(e),An.assign(t);const s=rn("float","lineDistance");n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),s.mod(Sn.add(An)).greaterThan(Sn).discard()}const a=vi(1).toVar("alpha");if(i){const s=rn("vec3","worldStart"),i=rn("vec3","worldEnd"),n=rn("vec4","worldPos").xyz.normalize().mul(1e5),u=i.sub(s),l=o({p1:s,p2:i,p3:Bi(0,0,0),p4:n}),d=s.add(u.mul(l.x)),c=n.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),s=e.mul(e).add(t.mul(t)),r=vi(s.fwidth()).toVar("dlen");Ti(n.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else Ti(n.y.abs().greaterThan(1),(()=>{const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ii(u,a)}))()}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 hh=e=>ci(e).mul(.5).add(.5),ph=e=>ci(e).mul(2).sub(1),gh=new D;class mh extends rh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(gh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?vi(this.opacityNode):dd;nn.assign(Ii(hh(dl),e))}}class fh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Ci(t,s)}}const yh=gi(fh);class bh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i=new O(5,5,5),n=yh(Ju),o=new rh;o.colorNode=_u(t,n,0),o.side=x,o.blending=G;const a=new k(i,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const xh=new WeakMap;class Th extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(xh.has(e)){const t=xh.get(e);Nh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new bh(s.height);r.fromEquirectangularTexture(t,e),Nh(r.texture,e.mapping),this._cubeTexture=r.texture,xh.set(e,r.texture),e.addEventListener("dispose",_h)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function _h(e){const t=e.target;t.removeEventListener("dispose",_h);const s=xh.get(t);void 0!==s&&(xh.delete(t),s.dispose())}function Nh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const vh=gi(Th);class Sh extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=vh(this.envNode)}}class Ah extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=vi(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Rh{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Ch extends Rh{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,i=e.reflectedLight,n=s.context.irradianceLightMap;i.indirectDiffuse.assign(Ii(0)),n?i.indirectDiffuse.addAssign(n):i.indirectDiffuse.addAssign(Ii(1,1,1,0)),i.indirectDiffuse.mulAssign(r),i.indirectDiffuse.mulAssign(nn.rgb)}finish(e,t,s){const r=s.material,i=e.outgoingLight,n=s.context.environment;if(n)switch(r.combine){case Y:i.rgb.assign(la(i.rgb,i.rgb.mul(n.rgb),gd.mul(md)));break;case X:i.rgb.assign(la(i.rgb,n.rgb,gd.mul(md)));break;case K:i.rgb.addAssign(n.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const Eh=new Q;class wh extends rh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Eh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Sh(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Ah(kd)),t}setupOutgoingLight(){return nn.rgb}setupLightingModel(){return new Ch}}const Mh=fi((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Bh=fi((e=>e.diffuseColor.mul(1/Math.PI))),Uh=fi((({dotNH:e})=>Nn.mul(vi(.5)).add(1).mul(vi(1/Math.PI)).mul(e.pow(Nn)))),Fh=fi((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),i=Mh({f0:Tn,f90:1,dotVH:r}),n=vi(.25),o=Uh({dotNH:s});return i.mul(n).mul(o)}));class Ph extends Ch{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Bh({diffuseColor:nn.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Fh({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Bh({diffuseColor:nn}))),s.indirectDiffuse.mulAssign(e)}}const Ih=new Z;class Lh extends rh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ih),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Sh(t):null}setupLightingModel(){return new Ph(!1)}}const Dh=new J;class Vh extends rh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Dh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Sh(t):null}setupLightingModel(){return new Ph}setupVariants(){const e=(this.shininessNode?vi(this.shininessNode):ud).max(1e-4);Nn.assign(e);const t=this.specularNode||cd;Tn.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Oh=fi((e=>{if(!1===e.geometry.hasAttribute("normal"))return vi(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),Gh=fi((e=>{const{roughness:t}=e,s=Oh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),kh=fi((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),i=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return kn(.5,i.add(n).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),zh=fi((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:i,dotBL:n,dotNV:o,dotNL:a})=>{const u=a.mul(Bi(e.mul(s),t.mul(r),o).length()),l=o.mul(Bi(e.mul(i),t.mul(n),a).length());return kn(.5,u.add(l)).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"}]}),$h=fi((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Hh=vi(1/Math.PI),Wh=fi((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:i})=>{const n=e.mul(t),o=Bi(t.mul(r),e.mul(i),n.mul(s)),a=o.dot(o),u=n.div(a);return Hh.mul(n.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"}]}),jh=fi((e=>{const{lightDirection:t,f0:s,f90:r,roughness:i,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=i.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Mh({f0:s,f90:r,dotVH:g});if(ui(o)&&(y=pn.mix(y,n)),ui(a)){const e=bn.dot(t),s=bn.dot(tl),r=bn.dot(d),i=xn.dot(t),n=xn.dot(tl),o=xn.dot(d);m=zh({alphaT:fn,alphaB:l,dotTV:s,dotBV:n,dotTL:e,dotBL:i,dotNV:h,dotNL:c}),f=Wh({alphaT:fn,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=kh({alpha:l,dotNL:c,dotNV:h}),f=$h({alpha:l,dotNH:p});return y.mul(m).mul(f)})),qh=fi((({roughness:e,dotNV:t})=>{const s=Ii(-1,-.0275,-.572,.022),r=Ii(1,.0425,1.04,-.04),i=e.mul(s).add(r),n=i.x.mul(i.x).min(t.mul(-9.28).exp2()).mul(i.x).add(i.y);return Ci(-1.04,1.04).mul(n).add(i.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Kh=fi((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:i}=e,n=qh({dotNV:t,roughness:i});return s.mul(n.x).add(r.mul(n.y))})),Xh=fi((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),i=r.mul(r),n=r.mul(i,i).clamp(0,.9999);return e.sub(Bi(t).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Yh=fi((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=vi(1).div(s),i=t.pow2().oneMinus().max(.0078125);return vi(2).add(r).mul(i.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Qh=fi((({dotNV:e,dotNL:t})=>vi(1).div(vi(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Zh=fi((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),i=dl.dot(t).clamp(),n=Yh({roughness:hn,dotNH:i}),o=Qh({dotNV:r,dotNL:s});return cn.mul(n).mul(o)})),Jh=fi((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),i=Ci(s,r.oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),ep=fi((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),tp=fi((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),i=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),n=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=i.div(n),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),sp=fi((({N:e,V:t,P:s,mInv:r,p0:i,p1:n,p2:o,p3:a})=>{const u=n.sub(i).toVar(),l=a.sub(i).toVar(),d=u.cross(l),c=Bi().toVar();return Ti(d.dot(s.sub(i)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(Gi(u,l,e).transpose()).toVar(),h=d.mul(i.sub(s)).normalize().toVar(),p=d.mul(n.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Bi(0).toVar();f.addAssign(tp({v1:h,v2:p})),f.addAssign(tp({v1:p,v2:g})),f.addAssign(tp({v1:g,v2:m})),f.addAssign(tp({v1:m,v2:h})),c.assign(Bi(ep({f:f})))})),c})).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"}]}),rp=1/6,ip=e=>Gn(rp,Gn(e,Gn(e,e.negate().add(3)).sub(3)).add(1)),np=e=>Gn(rp,Gn(e,Gn(e,Gn(3,e).sub(6))).add(4)),op=e=>Gn(rp,Gn(e,Gn(e,Gn(-3,e).add(3)).add(3)).add(1)),ap=e=>Gn(rp,sa(e,3)),up=e=>ip(e).add(np(e)),lp=e=>op(e).add(ap(e)),dp=e=>Vn(-1,np(e).div(ip(e).add(np(e)))),cp=e=>Vn(1,ap(e).div(op(e).add(ap(e)))),hp=(e,t,s)=>{const r=e.uvNode,i=Gn(r,t.zw).add(.5),n=vo(i),o=Ro(i),a=up(o.x),u=lp(o.x),l=dp(o.x),d=cp(o.x),c=dp(o.y),h=cp(o.y),p=Ci(n.x.add(l),n.y.add(c)).sub(.5).mul(t.xy),g=Ci(n.x.add(d),n.y.add(c)).sub(.5).mul(t.xy),m=Ci(n.x.add(l),n.y.add(h)).sub(.5).mul(t.xy),f=Ci(n.x.add(d),n.y.add(h)).sub(.5).mul(t.xy),y=up(o.y).mul(Vn(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=lp(o.y).mul(Vn(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},pp=fi((([e,t=vi(3)])=>{const s=Ci(e.size(Si(t))),r=Ci(e.size(Si(t.add(1)))),i=kn(1,s),n=kn(1,r),o=hp(e,Ii(i,s),vo(t)),a=hp(e,Ii(n,r),So(t));return Ro(t).mix(o,a)})),gp=fi((([e,t,s,r,i])=>{const n=Bi(ha(t.negate(),Ao(e),kn(1,r))),o=Bi(Io(i[0].xyz),Io(i[1].xyz),Io(i[2].xyz));return Ao(n).mul(s.mul(o))})).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"}]}),mp=fi((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),fp=Vc(),yp=Vc(),bp=fi((([e,t,s],{material:r})=>{const i=(r.side==x?fp:yp).uv(e),n=To(Rc.x).mul(mp(t,s));return pp(i,n)})),xp=fi((([e,t,s])=>(Ti(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Bi(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),Tp=fi((([e,t,s,r,i,n,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ii().toVar(),f=Bi().toVar();const i=d.sub(1).mul(g.mul(.025)),n=Bi(d.sub(i),d,d.add(i));uc({start:0,end:3},(({i:i})=>{const d=n.element(i),g=gp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ii(y,1))),x=Ci(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(Ci(x.x,x.y.oneMinus()));const T=bp(x,s,d);m.element(i).assign(T.element(i)),m.a.addAssign(T.a),f.element(i).assign(r.element(i).mul(xp(Io(g),h,p).element(i)))})),m.a.divAssign(3)}else{const i=gp(e,t,c,d,a),n=o.add(i),g=l.mul(u.mul(Ii(n,1))),y=Ci(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(Ci(y.x,y.y.oneMinus())),m=bp(y,s,d),f=r.mul(xp(Io(i),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Bi(Kh({dotNV:b,specularColor:i,specularF90:n,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ii(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),_p=Gi(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),Np=(e,t)=>e.sub(t).div(e.add(t)).pow2(),vp=fi((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:i})=>{const n=la(e,t,pa(0,.03,r)),o=e.div(n).pow2().mul(s.pow2().oneMinus()).oneMinus();Ti(o.lessThan(0),(()=>Bi(1)));const a=o.sqrt(),u=Np(n,e),l=Mh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=n.lessThan(e).select(Math.PI,0),h=vi(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Bi(1).add(t).div(Bi(1).sub(t))})(i.clamp(0,.9999)),g=Np(p,n.toVec3()),m=Mh({f0:g,f90:1,dotVH:a}),f=Bi(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(r,a,2),b=Bi(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Bi(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Bi(54856e-17,44201e-17,52481e-17),i=Bi(1681e3,1795300,2208400),n=Bi(43278e5,93046e5,66121e5),o=vi(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(n.mul(2*Math.PI).sqrt()).mul(i.mul(s).add(t).cos()).mul(s.pow2().negate().mul(n).exp());return a=Bi(a.x.add(o),a.y,a.z).div(1.0685e-7),_p.mul(a)})(vi(e).mul(y),vi(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Bi(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"}]}),Sp=fi((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),i=s.pow2(),n=xa(s.lessThan(.25),vi(-339.2).mul(i).add(vi(161.4).mul(s)).sub(25.9),vi(-8.48).mul(i).add(vi(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),vi(44).mul(i).sub(vi(23.7).mul(s)).add(3.26),vi(1.97).mul(i).sub(vi(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,vi(.1).mul(s).sub(.025)).add(n.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Ap=Bi(.04),Rp=vi(1);class Cp extends Rh{constructor(e=!1,t=!1,s=!1,r=!1,i=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=i,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Bi().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Bi().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Bi().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Bi().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Bi().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=vp({outsideIOR:vi(1),eta2:gn,cosTheta1:e,thinFilmThickness:mn,baseF0:Tn}),this.iridescenceF0=Xh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=Tp(r,s,an,nn,Tn,_n,t,Gu,Eu,Ru,Cn,wn,Bn,Mn,this.dispersion?Un:null),e.backdropAlpha=En,nn.a.mulAssign(la(1,e.backdrop.a,En))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),i=qh({roughness:an,dotNV:r}),n=(this.iridescenceF0?pn.mix(Tn,this.iridescenceF0):Tn).mul(i.x).add(s.mul(i.y)),o=i.x.add(i.y).oneMinus(),a=Tn.add(Tn.oneMinus().mul(.047619)),u=n.mul(a).div(o.mul(a).oneMinus());e.addAssign(n),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Zh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(jh({lightDirection:e,f0:Ap,f90:Rp,roughness:dn,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Bh({diffuseColor:nn.rgb}))),s.directSpecular.addAssign(r.mul(jh({lightDirection:e,f0:Tn,f90:1,roughness:an,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:i,ltc_1:n,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=Jh({N:c,V:h,roughness:an}),m=n.uv(g).toVar(),f=o.uv(g).toVar(),y=Gi(Bi(m.x,0,m.y),Bi(0,1,0),Bi(m.z,0,m.w)).toVar(),b=Tn.mul(f.x).add(Tn.oneMinus().mul(f.y)).toVar();i.directSpecular.addAssign(e.mul(b).mul(sp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),i.directDiffuse.addAssign(e.mul(nn).mul(sp({N:c,V:h,P:p,mInv:Gi(1,0,0,0,1,0,0,0,1),p0:a,p1:u,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(Bh({diffuseColor:nn})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(cn,Sp({normal:dl,viewDir:tl,roughness:hn}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Kh({dotNV:e,specularColor:Ap,specularF90:Rp,roughness:dn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Bi().toVar("singleScattering"),i=Bi().toVar("multiScattering"),n=t.mul(1/Math.PI);this.computeMultiscattering(r,i,_n);const o=r.add(i),a=nn.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(i.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=an.mul(-16).oneMinus().negate().exp2(),i=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(i)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Mh({dotVH:e,f0:Ap,f90:Rp}),r=t.mul(ln.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(ln));t.assign(r)}if(!0===this.sheen){const e=cn.r.max(cn.g).max(cn.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const Ep=vi(1),wp=vi(-2),Mp=vi(.8),Bp=vi(-1),Up=vi(.4),Fp=vi(2),Pp=vi(.305),Ip=vi(3),Lp=vi(.21),Dp=vi(4),Vp=vi(4),Op=vi(16),Gp=fi((([e])=>{const t=Bi(Fo(e)).toVar(),s=vi(-1).toVar();return Ti(t.x.greaterThan(t.z),(()=>{Ti(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{Ti(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),kp=fi((([e,t])=>{const s=Ci().toVar();return Ti(t.equal(0),(()=>{s.assign(Ci(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(Ci(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(Ci(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(Ci(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(Ci(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(Ci(e.x,e.y).div(Fo(e.z)))})),Gn(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),zp=fi((([e])=>{const t=vi(0).toVar();return Ti(e.greaterThanEqual(Mp),(()=>{t.assign(Ep.sub(e).mul(Bp.sub(wp)).div(Ep.sub(Mp)).add(wp))})).ElseIf(e.greaterThanEqual(Up),(()=>{t.assign(Mp.sub(e).mul(Fp.sub(Bp)).div(Mp.sub(Up)).add(Bp))})).ElseIf(e.greaterThanEqual(Pp),(()=>{t.assign(Up.sub(e).mul(Ip.sub(Fp)).div(Up.sub(Pp)).add(Fp))})).ElseIf(e.greaterThanEqual(Lp),(()=>{t.assign(Pp.sub(e).mul(Dp.sub(Ip)).div(Pp.sub(Lp)).add(Ip))})).Else((()=>{t.assign(vi(-2).mul(To(Gn(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),$p=fi((([e,t])=>{const s=e.toVar();s.assign(Gn(2,s).sub(1));const r=Bi(s,1).toVar();return Ti(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Hp=fi((([e,t,s,r,i,n])=>{const o=vi(s),a=Bi(t),u=da(zp(o),wp,n),l=Ro(u),d=vo(u),c=Bi(Wp(e,a,d,r,i,n)).toVar();return Ti(l.notEqual(0),(()=>{const t=Bi(Wp(e,a,d.add(1),r,i,n)).toVar();c.assign(la(c,t,l))})),c})),Wp=fi((([e,t,s,r,i,n])=>{const o=vi(s).toVar(),a=Bi(t),u=vi(Gp(a)).toVar(),l=vi(Ko(Vp.sub(o),0)).toVar();o.assign(Ko(o,Vp));const d=vi(bo(o)).toVar(),c=Ci(kp(a,u).mul(d.sub(2)).add(1)).toVar();return Ti(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gn(3,Op))),c.y.addAssign(Gn(4,bo(n).sub(d))),c.x.mulAssign(r),c.y.mulAssign(i),e.uv(c).grad(Ci(),Ci())})),jp=fi((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(i.cross(s).mul(Co(r))).add(i.mul(i.dot(s).mul(u.oneMinus())));return Wp(e,l,t,n,o,a)})),qp=fi((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:i,samples:n,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Bi(xa(t,s,ta(s,r))).toVar();Ti(ho(h.equals(Bi(0))),(()=>{h.assign(Bi(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Bi().toVar();return p.addAssign(i.element(Si(0)).mul(jp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:Si(1),end:e},(({i:e})=>{Ti(e.greaterThanEqual(n),(()=>{dc()}));const t=vi(o.mul(vi(e))).toVar();p.addAssign(i.element(e).mul(jp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(i.element(e).mul(jp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ii(p,1)}));let Kp=null;const Xp=new WeakMap;function Yp(e){let t=Xp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r<s;r++)void 0!==e[r]&&t++;return t===s}(s))return null;t=Kp.fromCubemap(e,t)}else{if(!function(e){return null!=e&&e.height>0}(s))return null;t=Kp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Xp.set(e,t)}return t.texture}class Qp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=en(0),this._height=en(0),this._maxMip=en(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Yp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Kp&&(Kp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Bi(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Hp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Zp=gi(Qp),Jp=new WeakMap;class eg extends yc{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 e=s.isTextureNode?s.value:t[s.property];let r=Jp.get(e);void 0===r&&(r=Zp(e),Jp.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),i=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,n=s.context(tg(an,i)).mul(r),o=s.context(sg(cl)).mul(Math.PI).mul(r),a=eu(n),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(tg(dn,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const tg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},sg=e=>({getUV:()=>e,getTextureLevel:()=>vi(1)}),rg=new te;class ig extends rh{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(rg),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new eg(t):null}setupLightingModel(){return new Cp}setupSpecular(){const e=la(Bi(.04),nn.rgb,un);Tn.assign(e),_n.assign(1)}setupVariants(){const e=this.metalnessNode?vi(this.metalnessNode):yd;un.assign(e);let t=this.roughnessNode?vi(this.roughnessNode):fd;t=Gh({roughness:t}),an.assign(t),this.setupSpecular(),nn.assign(Ii(nn.rgb.mul(e.oneMinus()),nn.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const ng=new se;class og extends ig{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(ng),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?vi(this.iorNode):Bd;Cn.assign(e),Tn.assign(la(qo(ra(Cn.sub(1).div(Cn.add(1))).mul(pd),Bi(1)).mul(hd),nn.rgb,un)),_n.assign(la(hd,1,un))}setupLightingModel(){return new Cp(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?vi(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?vi(this.clearcoatRoughnessNode):Td;ln.assign(e),dn.assign(Gh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Bi(this.sheenNode):vd,t=this.sheenRoughnessNode?vi(this.sheenRoughnessNode):Sd;cn.assign(e),hn.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?vi(this.iridescenceNode):Rd,t=this.iridescenceIORNode?vi(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?vi(this.iridescenceThicknessNode):Ed;pn.assign(e),gn.assign(t),mn.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?Ci(this.anisotropyNode):Ad).toVar();yn.assign(e.length()),Ti(yn.equal(0),(()=>{e.assign(Ci(1,0))})).Else((()=>{e.divAssign(Ci(yn)),yn.assign(yn.saturate())})),fn.assign(yn.pow2().mix(an.pow2(),1)),bn.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xn.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?vi(this.transmissionNode):wd,t=this.thicknessNode?vi(this.thicknessNode):Md,s=this.attenuationDistanceNode?vi(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Bi(this.attenuationColorNode):Fd;if(En.assign(e),wn.assign(t),Mn.assign(s),Bn.assign(r),this.useDispersion){const e=this.dispersionNode?vi(this.dispersionNode):Gd;Un.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Bi(this.clearcoatNormalNode):_d}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 ag extends Cp{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i){if(!0===this.useSSS){const r=i.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=vi(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Bi(h.add(a).mul(n));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i)}}class ug extends og{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=vi(.1),this.thicknessAmbientNode=vi(0),this.thicknessAttenuationNode=vi(.1),this.thicknessPowerNode=vi(2),this.thicknessScaleNode=vi(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ag(this.useClearcoat,this.useSheen,this.useIridescence,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 lg=fi((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),i=Ci(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>i});return Bi(e.r)}{const e=i.fwidth().mul(.5);return la(Bi(.7),Bi(1),pa(vi(.7).sub(e.x),vi(.7).add(e.x),i.x))}}));class dg extends Rh{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i){const n=lg({normal:nl,lightDirection:e,builder:i}).mul(t);s.directDiffuse.addAssign(n.mul(Bh({diffuseColor:nn.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Bh({diffuseColor:nn}))),s.indirectDiffuse.mulAssign(e)}}const cg=new re;class hg extends rh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(cg),this.setValues(e)}setupLightingModel(){return new dg}}class pg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Bi(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return Ci(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const gg=mi(pg),mg=new ie;class fg extends rh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(mg),this.setValues(e)}setupVariants(e){const t=gg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Bi(la(.2,.8,t.y)),nn.rgb.mulAssign(s.rgb)}}const yg=new P;class bg extends rh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(yg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class xg extends Er{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("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Oi(e,r,r.negate(),e).mul(s)}{const e=t,r=ki(Ii(1,0,0,0),Ii(0,Eo(e.x),Co(e.x).negate(),0),Ii(0,Co(e.x),Eo(e.x),0),Ii(0,0,0,1)),i=ki(Ii(Eo(e.y),0,Co(e.y),0),Ii(0,1,0,0),Ii(Co(e.y).negate(),0,Eo(e.y),0),Ii(0,0,0,1)),n=ki(Ii(Eo(e.z),Co(e.z).negate(),0,0),Ii(Co(e.z),Eo(e.z),0,0),Ii(0,0,1,0),Ii(0,0,0,1));return r.mul(i).mul(n).mul(Ii(s,1)).xyz}}}const Tg=gi(xg),_g=new ne;class Ng extends rh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(_g),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:i,rotationNode:n,scaleNode:o}=this,a=Yu;let u=ju.mul(Bi(i||0)),l=Ci(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=vi(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>ci(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=vi(n||Nd),h=Tg(d,c);u=Ii(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}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 vg extends Rh{constructor(){super(),this.shadowNode=vi(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){nn.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(nn.rgb)}}const Sg=new oe;class Ag extends rh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Sg),this.setValues(e)}setupLightingModel(){return new vg}}const Rg=fi((({texture:e,uv:t})=>{const s=1e-4,r=Bi().toVar();return Ti(t.x.lessThan(s),(()=>{r.assign(Bi(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Bi(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Bi(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Bi(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Bi(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Bi(0,0,-1))})).Else((()=>{const s=.01,i=e.uv(t.add(Bi(-.01,0,0))).r.sub(e.uv(t.add(Bi(s,0,0))).r),n=e.uv(t.add(Bi(0,-.01,0))).r.sub(e.uv(t.add(Bi(0,s,0))).r),o=e.uv(t.add(Bi(0,0,-.01))).r.sub(e.uv(t.add(Bi(0,0,s))).r);r.assign(Bi(i,n,o))})),r.normalize()}));class Cg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Bi(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Rg({texture:this,uv:e})}}const Eg=gi(Cg);class wg extends rh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=Eg(this.map,null,0),s=fi((({orig:e,dir:t})=>{const s=Bi(-.5),r=Bi(.5),i=t.reciprocal(),n=s.sub(e).mul(i),o=r.sub(e).mul(i),a=qo(n,o),u=Ko(n,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return Ci(l,d)}));this.fragmentNode=fi((()=>{const e=Ea(Bi(Wu.mul(Ii(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),i=Ci(s({orig:e,dir:r})).toVar();i.x.greaterThan(i.y).discard(),i.assign(Ci(Ko(i.x,0),i.y));const n=Bi(e.add(i.x.mul(r))).toVar(),o=Bi(r.abs().reciprocal()).toVar(),a=vi(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ii(Fl("base","color"),0).toVar();return uc({type:"float",start:i.x,end:i.y,update:"+= delta"},(()=>{const e=sn("float","d").assign(t.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:n,finalColor:u}).append():(u.a.assign(1),dc()),n.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ii(u)}))(),super.setup(e)}}class Mg{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),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&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 Bg{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]),void 0===t)return;return t.get(e[e.length-1])}set(e,t){let s=this.weakMap;for(let t=0;t<e.length;t++){const r=e[t];!1===s.has(r)&&s.set(r,new WeakMap),s=s.get(r)}return s.set(e[e.length-1],t)}delete(e){let t=this.weakMap;for(let s=0;s<e.length;s++)if(t=t.get(e[s]),void 0===t)return!1;return t.delete(e[e.length-1])}}let Ug=0;class Fg{constructor(e,t,s,r,i,n,o,a,u,l){this._nodes=e,this._geometries=t,this.id=Ug++,this.renderer=s,this.object=r,this.material=i,this.scene=n,this.camera=o,this.lightsNode=a,this.context=u,this.geometry=r.geometry,this.version=i.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=l,this.clippingContextCacheKey=null!==l?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 null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().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(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const i of e){const e=i.node&&i.node.attribute?i.node.attribute:t.getAttribute(i.name);if(void 0===e)continue;s.push(e);const n=e.isInterleavedBufferAttribute?e.data:e;r.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:i}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(n.instanceCount=u,!0===e.isBatchedMesh)return n;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=i.start*l,c=(i.start+i.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(n.vertexCount=g,n.firstVertex=d,n)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let i;if(null!==r){const e=typeof r;"number"===e?i=0!==r?"1":"0":"object"===e?(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+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(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 Pg=[];class Ig{constructor(e,t,s,r,i,n){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=i,this.info=n,this.chainMaps={}}get(e,t,s,r,i,n,o,a){const u=this.getChainMap(a);Pg[0]=e,Pg[1]=t,Pg[2]=n,Pg[3]=i;let l=u.get(Pg);if(void 0===l)l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,i,n,o,a),u.set(Pg,l);else{l.updateClipping(o);const u=l.needsGeometryUpdate;(l.version!==t.version||l.needsUpdate||u)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,i,n,o,a)):(l.version=t.version,u&&l.setGeometry(e.geometry)))}return l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Bg)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,i,n,o,a,u,l,d){const c=this.getChainMap(d),h=new Fg(e,t,s,r,i,n,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Lg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;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 Dg=1,Vg=2,Og=3,Gg=4,kg=16;class zg extends Lg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Dg?this.backend.createAttribute(e):t===Vg?this.backend.createIndexAttribute(e):t===Og?this.backend.createStorageAttribute(e):t===Gg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version<t.version||t.usage===p)&&(this.backend.updateAttribute(e),s.version=t.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function $g(e){return null!==e.index?e.index.version:e.attributes.position.version}function Hg(e){const t=[],s=e.index,r=e.attributes.position;if(null!==s){const e=s.array;for(let s=0,r=e.length;s<r;s+=3){const r=e[s+0],i=e[s+1],n=e[s+2];t.push(r,i,i,n,n,r)}}else{for(let e=0,s=r.array.length/3-1;e<s;e+=3){const s=e+0,r=e+1,i=e+2;t.push(s,r,r,i,i,s)}}const i=new(function(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return i.version=$g(e),i}class Wg extends Lg{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)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,i=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of i)this.attributes.delete(e);const n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Og):this.updateAttribute(e,Dg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Vg);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,Gg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Hg(t),e.set(t,s)):s.version!==$g(t)&&(this.attributes.delete(s),s=Hg(t),e.set(t,s)),r=s}return r}}class jg{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){0===this[e].timestampCalls&&(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 qg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Kg extends qg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Xg extends qg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Yg=0;class Qg{constructor(e,t,s=null,r=null){this.id=Yg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Zg extends Lg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const i=r.pipeline;i&&(i.usedTimes--,i.computeProgram.usedTimes--);const n=this.nodes.getForCompute(e);let o=this.programs.compute.get(n.computeShader);void 0===o&&(i&&0===i.computeProgram.usedTimes&&this._releaseProgram(i.computeProgram),o=new Qg(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(i&&0===i.usedTimes&&this._releasePipeline(i),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const i=r.pipeline;i&&(i.usedTimes--,i.vertexProgram.usedTimes--,i.fragmentProgram.usedTimes--);const n=e.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(i&&0===i.vertexProgram.usedTimes&&this._releaseProgram(i.vertexProgram),o=new Qg(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(i&&0===i.fragmentProgram.usedTimes&&this._releaseProgram(i.fragmentProgram),a=new Qg(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(i&&0===i.usedTimes&&this._releasePipeline(i),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let i=this.caches.get(s);return void 0===i&&(i=new Xg(s,t),this.caches.set(s,i),this.backend.createComputePipeline(i,r)),i}_getRenderPipeline(e,t,s,r,i){r=r||this._getRenderCacheKey(e,t,s);let n=this.caches.get(r);return void 0===n&&(n=new Kg(r,t,s),this.caches.set(r,n),e.pipeline=n,this.backend.createRenderPipeline(e,i)),n}_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 void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class Jg extends Lg{constructor(e,t,s,r,i,n){super(),this.backend=e,this.textures=s,this.pipelines=i,this.attributes=r,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t),s.bindGroup=e)}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 e=t.attribute,s=e.isIndirectStorageBufferAttribute?Gg:Og;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){t.needsBindingsUpdate(this.textures.get(t.texture).generation)&&(r=!0);const e=t.update(),i=t.texture;e&&this.textures.updateTexture(i);const n=s.get(i);if(!0===s.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",t,e,i,t.textureNode.value,r),this.textures.updateTexture(i),r=!0),!0===i.isStorageTexture){const e=this.get(i);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(i)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(i),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t)}}function em(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function sm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class rm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,i,n,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:i,group:n,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=i,a.group=n,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,i,n,o){const a=this.getNextRenderItem(e,t,s,r,i,n,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(sm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,i,n,o){const a=this.getNextRenderItem(e,t,s,r,i,n,o);!0===s.transparent||s.transmission>0?(sm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||em),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||tm),this.transparent.length>1&&this.transparent.sort(t||tm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const t=this.renderItems[e];if(null===t.id)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.groupOrder=null,t.renderOrder=null,t.z=null,t.group=null,t.clippingContext=null}}}class im{constructor(e){this.lighting=e,this.lists=new Bg}get(e,t){const s=this.lists,r=[e,t];let i=s.get(r);return void 0===i&&(i=new rm(this.lighting,e,t),s.set(r,i)),i}dispose(){this.lists=new Bg}}let nm=0;class om{constructor(){this.id=nm++,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 r,this.scissor=!1,this.scissorValue=new r,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}getCacheKey(){return am(this)}}function am(e){const{textures:t,activeCubeFace:s}=e,r=[s];for(const e of t)r.push(e.id);return ur(r)}class um{constructor(){this.chainMaps={}}get(e,t,s=null){const r=[e,t];let i;if(null===s)i="default";else{const e=s.texture.format;i=`${s.textures.length}:${e}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this.getChainMap(i);let o=n.get(r);return void 0===o&&(o=new om,n.set(r,o)),null!==s&&(o.sampleCount=0===s.samples?1:s.samples),o}getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new Bg)}dispose(){this.chainMaps={}}}const lm=new s;class dm extends Lg{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){const s=this.get(e),r=0===e.samples?1:e.samples,i=s.depthTextureMips||(s.depthTextureMips={}),n=e.textures,o=this.getSize(n[0]),a=o.width>>t,u=o.height>>t;let l=e.depthTexture||i[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,i[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=n,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e<n.length;e++){const t=n[e];c&&(t.needsUpdate=!0),this.updateTexture(t,h)}if(l&&this.updateTexture(l,h),!0!==s.initialized){s.initialized=!0;const t=()=>{e.removeEventListener("dispose",t);for(let e=0;e<n.length;e++)this._destroyTexture(n[e]);l&&this._destroyTexture(l),this.delete(e)};e.addEventListener("dispose",t)}}updateTexture(e,t={}){const s=this.get(e);if(!0===s.initialized&&s.version===e.version)return;const r=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,i=this.backend;if(r&&!0===s.initialized&&(i.destroySampler(e),i.destroyTexture(e)),e.isFramebufferTexture){const t=this.renderer.getRenderTarget();e.type=t?t.texture.type:pe}const{width:n,height:o,depth:a}=this.getSize(e);if(t.width=n,t.height=o,t.depth=a,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,n,o):1,r||!0===e.isStorageTexture)i.createSampler(e),i.createTexture(e,t),s.generation=e.version;else{if(!0!==s.initialized&&i.createSampler(e),e.version>0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(i.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&i.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&i.generateMipmaps(e)}}else i.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=lm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class cm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class hm extends tn{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const pm=(e,t)=>ci(new hm(e,t));class gm extends Ar{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 di(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new di(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new di(e),this}build(e,...t){const s=xi();bi(this);for(const t of this.nodes)t.build(e,"void");return bi(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 mm=gi(gm);class fm extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class ym extends Ar{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 r=0;r<t.length;r++)s.push(t[r].getNodeType(e));this.nodeType=e.getStructTypeFromNode(new fm(s)).name}generate(e,t){const s=e.getOutputStructName(),r=this.members,i=""!==s?s+".":"";for(let s=0;s<r.length;s++){const n=r[s].build(e,t);e.addLineFlowCode(`${i}m${s} = ${n}`,this)}return s}}const bm=gi(ym);function xm(e,t){for(let s=0;s<e.length;s++)if(e[s].name===t)return s;return-1}class Tm extends ym{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.isMRTNode=!0}has(e){return void 0!==this.outputNodes[e]}get(e){return this.outputNodes[e]}merge(e){const t={...this.outputNodes,...e.outputNodes};return _m(t)}setup(e){const t=this.outputNodes,s=[],r=e.renderer.getRenderTarget().textures;for(const e in t){s[xm(r,e)]=Ii(t[e])}return this.members=s,super.setup(e)}}const _m=gi(Tm),Nm=fi((([e])=>{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),vm=(e,t)=>sa(Gn(4,e.mul(On(1,e))),t),Sm=(e,t)=>e.lessThan(.5)?vm(e.mul(2),t).div(2):On(1,vm(Gn(On(1,e),2),t).div(2)),Am=(e,t,s)=>sa(kn(sa(e,t),Vn(sa(e,t),sa(On(1,e),s))),1/t),Rm=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),Cm=fi((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),Em=fi((([e])=>Bi(Cm(e.z.add(Cm(e.y.mul(1)))),Cm(e.z.add(Cm(e.x.mul(1)))),Cm(e.y.add(Cm(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),wm=fi((([e,t,s])=>{const r=Bi(e).toVar(),i=vi(1.4).toVar(),n=vi(0).toVar(),o=Bi(r).toVar();return uc({start:vi(0),end:vi(3),type:"float",condition:"<="},(()=>{const e=Bi(Em(o.mul(2))).toVar();r.addAssign(e.add(s.mul(vi(.1).mul(t)))),o.mulAssign(1.8),i.mulAssign(1.5),r.mulAssign(1.2);const a=vi(Cm(r.z.add(Cm(r.x.add(Cm(r.y)))))).toVar();n.addAssign(a.div(i)),o.addAssign(.14)})),n})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Mm extends Ar{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(null===s){let r=null,i=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(t.length===o.length){let n=0;for(let s=0;s<t.length;s++){const r=t[s],i=o[s];r.getNodeType(e)===i.type?n++:n=0}n>i&&(r=s,i=n)}}this._candidateFnCall=s=r(...t)}return s}}const Bm=gi(Mm),Um=e=>(...t)=>Bm(e,...t),Fm=en(0).setGroup(Qi).onRenderUpdate((e=>e.time)),Pm=en(0).setGroup(Qi).onRenderUpdate((e=>e.deltaTime)),Im=en(0,"uint").setGroup(Qi).onRenderUpdate((e=>e.frameId)),Lm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Fm.mul(e)),Dm=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Fm.mul(e)),Vm=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Pm.mul(e)),Om=(e=Fm)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),Gm=(e=Fm)=>e.fract().round(),km=(e=Fm)=>e.add(.5).fract().mul(2).sub(1).abs(),zm=(e=Fm)=>e.fract(),$m=fi((([e,t,s=Ci(.5)])=>Tg(e.sub(s),t).add(s))),Hm=fi((([e,t,s=Ci(.5)])=>{const r=e.sub(s),i=r.dot(r),n=i.mul(i).mul(t);return e.add(r.mul(n))})),Wm=fi((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const i=Eu.mul(r);return ui(t)&&(i[0][0]=Gu[0].length(),i[0][1]=0,i[0][2]=0),ui(s)&&(i[1][0]=0,i[1][1]=Gu[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,Ru.mul(i).mul(Yu)})),jm=fi((([e=null])=>{const t=Yc();return Yc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class qm extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=vi(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:i}=s,n=e.mod(r.mul(i)).floor(),o=n.mod(r),a=i.sub(n.add(1).div(r).ceil()),u=s.reciprocal(),l=Ci(o,a);return t.add(l).mul(u)}}const Km=gi(qm);class Xm extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=vi(1),i=Yu,n=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=i,this.normalNode=n}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:i,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(Bi(1)));const a=i.yz.mul(r),u=i.zx.mul(r),l=i.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vn(p,g,m)}}const Ym=gi(Xm),Qm=(...e)=>Ym(...e),Zm=new me,Jm=new s,ef=new s,tf=new s,sf=new n,rf=new s(0,0,-1),nf=new r,of=new s,af=new s,uf=new r,lf=new t,df=new ge,cf=Ac.flipX();df.depthTexture=new B(1,1);let hf=!1;class pf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||df.texture,cf),this._reflectorBaseNode=e.reflector||new gf(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=ci(new pf({defaultTexture:df.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 gf extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:i=!1,bounces:n=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=i,this.bounces=n,this.depth=o,this.updateBeforeType=n?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(lf),e.setSize(Math.round(lf.width*s),Math.round(lf.height*s))}setup(e){return this._updateResolution(df,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&hf)return;hf=!0;const{scene:t,camera:s,renderer:r,material:i}=e,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(lf),this._updateResolution(a,r),ef.setFromMatrixPosition(n.matrixWorld),tf.setFromMatrixPosition(s.matrixWorld),sf.extractRotation(n.matrixWorld),Jm.set(0,0,1),Jm.applyMatrix4(sf),of.subVectors(ef,tf),of.dot(Jm)>0)return;of.reflect(Jm).negate(),of.add(ef),sf.extractRotation(s.matrixWorld),rf.set(0,0,-1),rf.applyMatrix4(sf),rf.add(tf),af.subVectors(ef,rf),af.reflect(Jm).negate(),af.add(ef),o.coordinateSystem=s.coordinateSystem,o.position.copy(of),o.up.set(0,1,0),o.up.applyMatrix4(sf),o.up.reflect(Jm),o.lookAt(af),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Zm.setFromNormalAndCoplanarPoint(Jm,ef),Zm.applyMatrix4(o.matrixWorldInverse),nf.set(Zm.normal.x,Zm.normal.y,Zm.normal.z,Zm.constant);const u=o.projectionMatrix;uf.x=(Math.sign(nf.x)+u.elements[8])/u.elements[0],uf.y=(Math.sign(nf.y)+u.elements[9])/u.elements[5],uf.z=-1,uf.w=(1+u.elements[10])/u.elements[14],nf.multiplyScalar(1/nf.dot(uf));u.elements[2]=nf.x,u.elements[6]=nf.y,u.elements[10]=r.coordinateSystem===N?nf.z-0:nf.z+1-0,u.elements[14]=nf.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),i.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),i.visible=!0,hf=!1}}const mf=e=>ci(new pf(e)),ff=new xe(-1,1,1,-1,0,1);class yf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const bf=new yf;class xf extends k{constructor(e=null){super(bf,e),this.camera=ff,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,ff)}render(e){e.render(this,ff)}}const Tf=new t;class _f extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const i=new ge(t,s,r);super(i.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=i,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new xf(new rh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(Tf);this.setSize(t.width,t.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 Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const Nf=(e,...t)=>ci(new _f(ci(e),...t)),vf=(e,...t)=>e.isTextureNode?e:Nf(e,...t),Sf=fi((([e,t,s],r)=>{let i;r.renderer.coordinateSystem===N?(e=Ci(e.x,e.y.oneMinus()).mul(2).sub(1),i=Ii(Bi(e,t),1)):i=Ii(Bi(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const n=Ii(s.mul(i));return n.xyz.div(n.w)})),Af=fi((([e,t])=>{const s=t.mul(Ii(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return Ci(r.x,r.y.oneMinus())})),Rf=fi((([e,t,s])=>{const r=yu(Nu(t)),i=Ei(e.mul(r)).toVar(),n=Nu(t,i).toVar(),o=Nu(t,i.sub(Ei(2,0))).toVar(),a=Nu(t,i.sub(Ei(1,0))).toVar(),u=Nu(t,i.add(Ei(1,0))).toVar(),l=Nu(t,i.add(Ei(2,0))).toVar(),d=Nu(t,i.add(Ei(0,2))).toVar(),c=Nu(t,i.add(Ei(0,1))).toVar(),h=Nu(t,i.sub(Ei(0,1))).toVar(),p=Nu(t,i.sub(Ei(0,2))).toVar(),g=Fo(On(vi(2).mul(a).sub(o),n)).toVar(),m=Fo(On(vi(2).mul(u).sub(l),n)).toVar(),f=Fo(On(vi(2).mul(c).sub(d),n)).toVar(),y=Fo(On(vi(2).mul(h).sub(p),n)).toVar(),b=Sf(e,n,s).toVar(),x=g.lessThan(m).select(b.sub(Sf(e.sub(Ci(vi(1).div(r.x),0)),a,s)),b.negate().add(Sf(e.add(Ci(vi(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Sf(e.add(Ci(0,vi(1).div(r.y))),c,s)),b.negate().add(Sf(e.sub(Ci(0,vi(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class Cf extends pu{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);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const Ef=(...e)=>ci(new Cf(...e));class wf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Mf=mi(wf),Bf=new ve,Uf=new n;class Ff extends Ar{static get type(){return"SceneNode"}constructor(e=Ff.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===Ff.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===Ff.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===Ff.BACKGROUND_ROTATION?r=en("mat4").label("backgroundRotation").setGroup(Qi).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Bf.copy(s.backgroundRotation),Bf.x*=-1,Bf.y*=-1,Bf.z*=-1,Uf.makeRotationFromEuler(Bf)):Uf.identity(),Uf})):console.error("THREE.SceneNode: Unknown scope:",t),r}}Ff.BACKGROUND_BLURRINESS="backgroundBlurriness",Ff.BACKGROUND_INTENSITY="backgroundIntensity",Ff.BACKGROUND_ROTATION="backgroundRotation";const Pf=mi(Ff,Ff.BACKGROUND_BLURRINESS),If=mi(Ff,Ff.BACKGROUND_INTENSITY),Lf=mi(Ff,Ff.BACKGROUND_ROTATION);class Df extends Rr{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!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Vf=gi(Df),Of="point-list",Gf="line-list",kf="line-strip",zf="triangle-list",$f="triangle-strip",Hf="never",Wf="less",jf="equal",qf="less-equal",Kf="greater",Xf="not-equal",Yf="greater-equal",Qf="always",Zf="store",Jf="load",ey="clear",ty="ccw",sy="none",ry="front",iy="back",ny="uint16",oy="uint32",ay={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},uy="clamp-to-edge",ly="repeat",dy="mirror-repeat",cy="linear",hy="nearest",py="zero",gy="one",my="src",fy="one-minus-src",yy="src-alpha",by="one-minus-src-alpha",xy="dst",Ty="one-minus-dst",_y="dst-alpha",Ny="one-minus-dst-alpha",vy="src-alpha-saturated",Sy="constant",Ay="one-minus-constant",Ry="add",Cy="subtract",Ey="reverse-subtract",wy="min",My="max",By=0,Uy=15,Fy="keep",Py="zero",Iy="replace",Ly="invert",Dy="increment-clamp",Vy="decrement-clamp",Oy="increment-wrap",Gy="decrement-wrap",ky="storage",zy="read-only-storage",$y="write-only",Hy="read-only",Wy="float",jy="unfilterable-float",qy="depth",Ky="sint",Xy="uint",Yy="2d",Qy="3d",Zy="2d",Jy="2d-array",eb="cube",tb="3d",sb="all",rb="vertex",ib="instance",nb={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 ob extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=ky,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Vf(this,e)}setBufferObject(e){return this.bufferObject=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(zy)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(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(),r=s.build(e);return e.registerTransform(r,t),r}}const ab=(e,t,s)=>ci(new ob(e,t,s)),ub=(e,t,s)=>ci(new ob(e,t,s).setBufferObject(!0));class lb extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=$y}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(Hy)}toWriteOnly(){return this.setAccess($y)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,i=super.generate(e,"property"),n=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,i,n,o);e.addLineFlowCode(a,this)}}const db=gi(lb),cb=(e,t,s)=>{const r=db(e,t,s);return null!==s&&r.append(),r};class hb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const pb=(e,t,s)=>ci(new hb(e,t,s)),gb=new WeakMap;class mb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=en(new n),this.previousProjectionMatrix=en(new n).setGroup(Qi),this.previousCameraViewMatrix=en(new n)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=yb(s);this.previousModelWorldMatrix.value.copy(r);const i=fb(t);i.frameId!==e&&(i.frameId=e,void 0===i.previousProjectionMatrix?(i.previousProjectionMatrix=new n,i.previousCameraViewMatrix=new n,i.currentProjectionMatrix=new n,i.currentCameraViewMatrix=new n,i.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(i.previousProjectionMatrix.copy(i.currentProjectionMatrix),i.previousCameraViewMatrix.copy(i.currentCameraViewMatrix)),i.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(i.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(i.previousCameraViewMatrix))}updateAfter({object:e}){yb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:en(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),i=s.xy.div(s.w),n=r.xy.div(r.w);return On(i,n)}}function fb(e){let t=gb.get(e);return void 0===t&&(t={},gb.set(e,t)),t}function yb(e,t=0){const s=fb(e);let r=s[t];return void 0===r&&(s[t]=r=new n),r}const bb=mi(mb),xb=fi((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Tb=fi((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),_b=fi((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Nb=fi((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=fi((([e])=>Cb(e.rgb))),Sb=fi((([e,t=vi(1)])=>t.mix(Cb(e.rgb),e.rgb))),Ab=fi((([e,t=vi(1)])=>{const s=Vn(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),i=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,i)})),Rb=fi((([e,t=vi(1)])=>{const s=Bi(.57735,.57735,.57735),r=t.cos();return Bi(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),Cb=(e,t=Bi(u.getLuminanceCoefficients(new s)))=>ea(e,t),Eb=(e,t)=>la(Bi(0),e,Cb(e).sub(t).max(0)),wb=fi((([e,t=Bi(1),r=Bi(0),i=Bi(1),n=vi(1),o=Bi(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Bi(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(i).toVar();return Ti(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),Ti(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),Ti(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(n))),Ii(l.rgb,e.a)}));class Mb extends Er{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 Bb=gi(Mb);let Ub=null;class Fb extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Ub&&(Ub=new w),super(e,t,Ub)}updateReference(){return this}}const Pb=gi(Fb),Ib=new t;class Lb extends Tu{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 Db extends Lb{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 Vb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const i=new B;i.isRenderTargetTexture=!0,i.name="depth";const n=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});n.texture.name="output",n.depthTexture=i,this.renderTarget=n,this.updateBeforeType=br.FRAME,this._textures={output:n.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=en(0),this._cameraFar=en(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=ci(new Db(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=ci(new Db(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,i=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(i,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Vb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const i=t.getSize(Ib);this.setSize(i.width,i.height);const n=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(n),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Vb.COLOR="color",Vb.DEPTH="depth";const Ob=(e,t,s)=>ci(new Vb(Vb.COLOR,e,t,s)),Gb=(e,t)=>ci(new Lb(e,t)),kb=(e,t)=>ci(new Vb(Vb.DEPTH,e,t));class zb extends Vb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,i){super(Vb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=i,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,i,n,o,a,u)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const l=this._getOutlineMaterial(n);t.renderObject(e,s,r,i,l,o,a,u)}t.renderObject(e,s,r,i,n,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new rh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=vi(1),i=s.mul(Ii(Yu,1)),n=s.mul(Ii(Yu.add(t),1)),o=Ao(i.sub(n));return e.vertexNode=i.add(o.mul(this.thicknessNode).mul(i.w).mul(r)),e.colorNode=Ii(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const $b=(t,s,r=new e(0,0,0),i=.003,n=1)=>ci(new zb(t,s,ci(r),ci(i),ci(n))),Hb=fi((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Wb=fi((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),jb=fi((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qb=fi((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Kb=fi((([e,t])=>{const s=Gi(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=Gi(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=qb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=Gi(Bi(1.6605,-.1246,-.0182),Bi(-.5876,1.1329,-.1006),Bi(-.0728,-.0083,1.1187)),Yb=Gi(Bi(.6274,.0691,.0164),Bi(.3293,.9195,.088),Bi(.0433,.0113,.8956)),Qb=fi((([e])=>{const t=Bi(e).toVar(),s=Bi(t.mul(t)).toVar(),r=Bi(s.mul(s)).toVar();return vi(15.5).mul(r.mul(s)).sub(Gn(40.14,r.mul(t))).add(Gn(31.96,r).sub(Gn(6.868,s.mul(t))).add(Gn(.4298,s).add(Gn(.1191,t).sub(.00232))))})),Zb=fi((([e,t])=>{const s=Bi(e).toVar(),r=Gi(Bi(.856627153315983,.137318972929847,.11189821299995),Bi(.0951212405381588,.761241990602591,.0767994186031903),Bi(.0482516061458583,.101439036467562,.811302368396859)),i=Gi(Bi(1.1271005818144368,-.1413297634984383,-.14132976349843826),Bi(-.11060664309660323,1.157823702216272,-.11060664309660294),Bi(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=vi(-12.47393),o=vi(4.026069);return s.mulAssign(t),s.assign(Yb.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(da(s,0,1)),s.assign(Qb(s)),s.assign(i.mul(s)),s.assign(sa(Ko(Bi(0),s),Bi(2.2))),s.assign(Xb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Jb=fi((([e,t])=>{const s=vi(.76),r=vi(.15);e=e.mul(t);const i=qo(e.r,qo(e.g,e.b)),n=xa(i.lessThan(.08),i.sub(Gn(6.25,i.mul(i))),.04);e.subAssign(n);const o=Ko(e.r,Ko(e.g,e.b));Ti(o.lessThan(s),(()=>e));const a=On(1,s),u=On(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=On(1,kn(1,r.mul(o.sub(u)).add(1)));return la(e,Bi(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class ex extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.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 tx=gi(ex),sx=(e,t)=>tx(e,t,"js"),rx=(e,t)=>tx(e,t,"wgsl"),ix=(e,t)=>tx(e,t,"glsl");class nx extends ex{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 void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,i=s.type,n=e.getCodeFromNode(this,i);""!==r&&(n.name=r);const o=e.getPropertyName(n),a=this.getNodeFunction(e).getCode(o);return n.code=a+"\n","property"===t?o:e.format(`${o}()`,i,t)}}const ox=(e,t=[],s="")=>{for(let e=0;e<t.length;e++){const s=t[e];"function"==typeof s&&(t[e]=s.functionNode)}const r=ci(new nx(e,t,s)),i=(...e)=>r.call(...e);return i.functionNode=r,i},ax=(e,t)=>ox(e,t,"glsl"),ux=(e,t)=>ox(e,t,"wgsl");class lx extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:vi()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const dx=gi(lx);class cx extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class hx{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 px=new cx;class gx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new cx,this._output=dx(),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 void 0===s[e]?s[e]=dx(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)):void 0===s[e]?(s[e]=dx(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 s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new hx(this),t=px.get("THREE"),s=px.get("TSL"),r=this.getMethod(this.codeNode),i=[e,this._local,px,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...i);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const e of n.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:vi()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const mx=gi(gx);class fx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const yx=gi(fx);class bx extends fx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const xx=gi(bx);class Tx extends fx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const _x=gi(Tx);let Nx=null,vx=null;class Sx extends Ar{static get type(){return"RangeNode"}constructor(e=vi(),t=vi()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(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 i=this.minNode.value,n=this.maxNode.value,o=e.getTypeLength(hr(i)),u=e.getTypeLength(hr(n));Nx=Nx||new r,vx=vx||new r,Nx.setScalar(0),vx.setScalar(0),1===o?Nx.setScalar(i):i.isColor?Nx.set(i.r,i.g,i.b):Nx.set(i.x,i.y,i.z||0,i.w||0),1===u?vx.setScalar(n):n.isColor?vx.set(n.r,n.g,n.b):vx.set(n.x,n.y,n.z||0,n.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;e<d;e++){const t=e%l,s=Nx.getComponent(t),r=vx.getComponent(t);c[e]=a.lerp(s,r,Math.random())}const h=this.getNodeType(e);if(t.count<=4096)s=vl(c,"vec4",t.count).element(Kd).convert(h);else{const t=new R(c,4);e.geometry.setAttribute("__range"+this.id,t),s=Xa(t).convert(h)}}else s=vi(0);return s}}const Ax=gi(Sx);class Rx extends Ar{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),r=this.getNodeType(e);return"compute"===e.shaderStage?e.format(s,r,t):(console.warn(`ComputeBuiltinNode: Compute built-in value ${s} can not be accessed in the ${e.shaderStage} stage`),e.generateConst(r))}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 Cx=(e,t)=>ci(new Rx(e,t)),Ex=Cx("numWorkgroups","uvec3"),wx=Cx("workgroupId","uvec3"),Mx=Cx("localId","uvec3"),Bx=Cx("subgroupSize","uint");const Ux=gi(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Fx=()=>Ux("workgroup").append(),Px=()=>Ux("storage").append(),Ix=()=>Ux("texture").append();class Lx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class Dx extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return ci(new Lx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const Vx=(e,t)=>ci(new Dx("Workgroup",e,t));class Ox extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),i=this.pointerNode,n=this.valueNode,o=[];o.push(`&${i.build(e,r)}`),o.push(n.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}Ox.ATOMIC_LOAD="atomicLoad",Ox.ATOMIC_STORE="atomicStore",Ox.ATOMIC_ADD="atomicAdd",Ox.ATOMIC_SUB="atomicSub",Ox.ATOMIC_MAX="atomicMax",Ox.ATOMIC_MIN="atomicMin",Ox.ATOMIC_AND="atomicAnd",Ox.ATOMIC_OR="atomicOr",Ox.ATOMIC_XOR="atomicXor";const Gx=gi(Ox),kx=(e,t,s,r)=>{const i=Gx(e,t,s,r);return i.append(),i},zx=(e,t,s=null)=>kx(Ox.ATOMIC_STORE,e,t,s),$x=(e,t,s=null)=>kx(Ox.ATOMIC_ADD,e,t,s),Hx=(e,t,s=null)=>kx(Ox.ATOMIC_SUB,e,t,s),Wx=(e,t,s=null)=>kx(Ox.ATOMIC_MAX,e,t,s),jx=(e,t,s=null)=>kx(Ox.ATOMIC_MIN,e,t,s),qx=(e,t,s=null)=>kx(Ox.ATOMIC_AND,e,t,s),Kx=(e,t,s=null)=>kx(Ox.ATOMIC_OR,e,t,s),Xx=(e,t,s=null)=>kx(Ox.ATOMIC_XOR,e,t,s);let Yx;function Qx(e){Yx=Yx||new WeakMap;let t=Yx.get(e);return void 0===t&&Yx.set(e,t={}),t}function Zx(e){const t=Qx(e);return t.position||(t.position=en(new s).setGroup(Qi).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function Jx(e){const t=Qx(e);return t.targetPosition||(t.targetPosition=en(new s).setGroup(Qi).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function eT(e){const t=Qx(e);return t.viewPosition||(t.viewPosition=en(new s).setGroup(Qi).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const tT=e=>Eu.transformDirection(Zx(e).sub(Jx(e))),sT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},rT=new WeakMap;class iT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Bi().toVar("totalDiffuse"),this.totalSpecularNode=Bi().toVar("totalSpecular"),this.outgoingLightNode=Bi().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.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,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),i=e.renderer.library;for(const e of r)if(e.isNode)t.push(ci(e));else{let r=null;if(null!==s&&(r=sT(e.id,s)),null===r){const s=i.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;rT.has(e)?r=rT.get(e):(r=ci(new s(e)),rT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:i,totalDiffuseNode:n,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,i),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Bi(null!==l?l.mix(g,u):u),t.material.transparent=!0),n.assign(g),o.assign(c.add(p)),r.assign(n.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const nT=(e=[])=>ci(new iT).setLights(e),oT=fi((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),aT=fi((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),i=Ml("mapSize","vec2",s).setGroup(Qi),n=Ml("radius","float",s).setGroup(Qi),o=Ci(1).div(i),a=o.x.negate().mul(n),u=o.y.negate().mul(n),l=o.x.mul(n),d=o.y.mul(n),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vn(r(t.xy.add(Ci(a,u)),t.z),r(t.xy.add(Ci(0,u)),t.z),r(t.xy.add(Ci(l,u)),t.z),r(t.xy.add(Ci(c,h)),t.z),r(t.xy.add(Ci(0,h)),t.z),r(t.xy.add(Ci(p,h)),t.z),r(t.xy.add(Ci(a,0)),t.z),r(t.xy.add(Ci(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(Ci(p,0)),t.z),r(t.xy.add(Ci(l,0)),t.z),r(t.xy.add(Ci(c,g)),t.z),r(t.xy.add(Ci(0,g)),t.z),r(t.xy.add(Ci(p,g)),t.z),r(t.xy.add(Ci(a,d)),t.z),r(t.xy.add(Ci(0,d)),t.z),r(t.xy.add(Ci(l,d)),t.z)).mul(1/17)})),uT=fi((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),i=Ml("mapSize","vec2",s).setGroup(Qi),n=Ci(1).div(i),o=n.x,a=n.y,u=t.xy,l=Ro(u.mul(i).add(.5));return u.subAssign(l.mul(n)),Vn(r(u,t.z),r(u.add(Ci(o,0)),t.z),r(u.add(Ci(0,a)),t.z),r(u.add(n),t.z),la(r(u.add(Ci(o.negate(),0)),t.z),r(u.add(Ci(o.mul(2),0)),t.z),l.x),la(r(u.add(Ci(o.negate(),a)),t.z),r(u.add(Ci(o.mul(2),a)),t.z),l.x),la(r(u.add(Ci(0,a.negate())),t.z),r(u.add(Ci(0,a.mul(2))),t.z),l.y),la(r(u.add(Ci(o,a.negate())),t.z),r(u.add(Ci(o,a.mul(2))),t.z),l.y),la(la(r(u.add(Ci(o.negate(),a.negate())),t.z),r(u.add(Ci(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(Ci(o.negate(),a.mul(2))),t.z),r(u.add(Ci(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),lT=fi((({depthTexture:e,shadowCoord:t})=>{const s=vi(1).toVar(),r=_u(e).uv(t.xy).rg,i=Yo(t.z,r.x);return Ti(i.notEqual(vi(1)),(()=>{const e=t.z.sub(r.x),n=Ko(0,r.y.mul(r.y));let o=n.div(n.add(e.mul(e)));o=da(On(o,.3).div(.95-.3)),s.assign(da(Ko(i,o)))})),s})),dT=fi((({samples:e,radius:t,size:s,shadowPass:r})=>{const i=vi(0).toVar(),n=vi(0).toVar(),o=e.lessThanEqual(vi(1)).select(vi(0),vi(2).div(e.sub(1))),a=e.lessThanEqual(vi(1)).select(vi(0),vi(-1));uc({start:Si(0),end:Si(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(vi(e).mul(o)),l=r.uv(Vn(Cc.xy,Ci(0,u).mul(t)).div(s)).x;i.addAssign(l),n.addAssign(l.mul(l))})),i.divAssign(e),n.divAssign(e);const u=_o(n.sub(i.mul(i)));return Ci(i,u)})),cT=fi((({samples:e,radius:t,size:s,shadowPass:r})=>{const i=vi(0).toVar(),n=vi(0).toVar(),o=e.lessThanEqual(vi(1)).select(vi(0),vi(2).div(e.sub(1))),a=e.lessThanEqual(vi(1)).select(vi(0),vi(-1));uc({start:Si(0),end:Si(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(vi(e).mul(o)),l=r.uv(Vn(Cc.xy,Ci(u,0).mul(t)).div(s));i.addAssign(l.x),n.addAssign(Vn(l.y.mul(l.y),l.x.mul(l.x)))})),i.divAssign(e),n.divAssign(e);const u=_o(n.sub(i.mul(i)));return Ci(i,u)})),hT=[oT,aT,uT,lT];let pT=null;const gT=new xf;class mT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===pT&&(pT=new rh,pT.fragmentNode=Ii(0,0,0,1),pT.isShadowNodeMaterial=!0,pT.name="ShadowMaterial");const r=this.shadow,i=s.shadowMap.type,n=new B(r.mapSize.width,r.mapSize.height);n.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=n,r.camera.updateProjectionMatrix(),i===Re){n.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(n),s=_u(this.vsmShadowMapVertical.texture),i=Ml("blurSamples","float",r).setGroup(Qi),o=Ml("radius","float",r).setGroup(Qi),a=Ml("mapSize","vec2",r).setGroup(Qi);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new rh);u.fragmentNode=dT({samples:i,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new rh),u.fragmentNode=cT({samples:i,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Qi),u=Ml("bias","float",r).setGroup(Qi),l=Ml("normalBias","float",r).setGroup(Qi),d=t.material.shadowPositionNode||Zu;let c,h=en(r.matrix).setGroup(Qi).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=en("float").onRenderUpdate((()=>r.camera.near)),s=en("float").onRenderUpdate((()=>r.camera.far));c=qc(e,t,s)}h=Bi(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||hT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:i===Re?this.vsmShadowMapHorizontal.texture:n,shadowCoord:h,shadow:r}),vi(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),fT.mulAssign(t),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:i,scene:n,camera:o}=e,a=i.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=n.overrideMaterial;n.overrideMaterial=pT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=i.getRenderTarget(),c=i.getRenderObjectFunction();i.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&i.renderObject(e,...t)})),i.setRenderTarget(t),i.render(n,r.camera),i.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(i),i.setRenderTarget(d),n.overrideMaterial=l}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),gT.material=this.vsmMaterialVertical,gT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),gT.material=this.vsmMaterialHorizontal,gT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const fT=vi(1).toVar(),yT=(e,t)=>ci(new mT(e,t)),bT=fT.oneMinus().toVar("shadows");class xT extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=en(this.color).setGroup(Qi),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?ci(e):yT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const TT=fi((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,i=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(i.mul(t.div(s).pow4().oneMinus().clamp().pow2()),i)})),_T=fi((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},i)=>{const n=i.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=TT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=i.context.reflectedLight;n.direct({lightDirection:a,lightColor:d,reflectedLight:c},i.stack,i)}));class NT extends xT{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=en(0).setGroup(Qi),this.decayExponentNode=en(0).setGroup(Qi)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){_T({color:this.colorNode,lightViewPosition:eT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const vT=fi((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),ST=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Ri(e).toVar();return xa(n,i,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),AT=fi((([e,t])=>{const s=Ri(t).toVar(),r=vi(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),RT=fi((([e])=>{const t=vi(e).toVar();return Si(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),CT=fi((([e,t])=>{const s=vi(e).toVar();return t.assign(RT(s)),s.sub(vi(t))})),ET=Um([fi((([e,t,s,r,i,n])=>{const o=vi(n).toVar(),a=vi(i).toVar(),u=vi(r).toVar(),l=vi(s).toVar(),d=vi(t).toVar(),c=vi(e).toVar(),h=vi(On(1,a)).toVar();return On(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.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"}]}),fi((([e,t,s,r,i,n])=>{const o=vi(n).toVar(),a=vi(i).toVar(),u=Bi(r).toVar(),l=Bi(s).toVar(),d=Bi(t).toVar(),c=Bi(e).toVar(),h=vi(On(1,a)).toVar();return On(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.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"}]})]),wT=Um([fi((([e,t,s,r,i,n,o,a,u,l,d])=>{const c=vi(d).toVar(),h=vi(l).toVar(),p=vi(u).toVar(),g=vi(a).toVar(),m=vi(o).toVar(),f=vi(n).toVar(),y=vi(i).toVar(),b=vi(r).toVar(),x=vi(s).toVar(),T=vi(t).toVar(),_=vi(e).toVar(),N=vi(On(1,p)).toVar(),v=vi(On(1,h)).toVar();return vi(On(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),fi((([e,t,s,r,i,n,o,a,u,l,d])=>{const c=vi(d).toVar(),h=vi(l).toVar(),p=vi(u).toVar(),g=Bi(a).toVar(),m=Bi(o).toVar(),f=Bi(n).toVar(),y=Bi(i).toVar(),b=Bi(r).toVar(),x=Bi(s).toVar(),T=Bi(t).toVar(),_=Bi(e).toVar(),N=vi(On(1,p)).toVar(),v=vi(On(1,h)).toVar();return vi(On(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),MT=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Ai(e).toVar(),o=Ai(n.bitAnd(Ai(7))).toVar(),a=vi(ST(o.lessThan(Ai(4)),i,r)).toVar(),u=vi(Gn(2,ST(o.lessThan(Ai(4)),r,i))).toVar();return AT(a,Ri(o.bitAnd(Ai(1)))).add(AT(u,Ri(o.bitAnd(Ai(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),BT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=vi(t).toVar(),a=Ai(e).toVar(),u=Ai(a.bitAnd(Ai(15))).toVar(),l=vi(ST(u.lessThan(Ai(8)),o,n)).toVar(),d=vi(ST(u.lessThan(Ai(4)),n,ST(u.equal(Ai(12)).or(u.equal(Ai(14))),o,i))).toVar();return AT(l,Ri(u.bitAnd(Ai(1)))).add(AT(d,Ri(u.bitAnd(Ai(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"}]}),UT=Um([MT,BT]),FT=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Fi(e).toVar();return Bi(UT(n.x,i,r),UT(n.y,i,r),UT(n.z,i,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),PT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=vi(t).toVar(),a=Fi(e).toVar();return Bi(UT(a.x,o,n,i),UT(a.y,o,n,i),UT(a.z,o,n,i))})).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"}]}),IT=Um([FT,PT]),LT=fi((([e])=>{const t=vi(e).toVar();return Gn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),DT=fi((([e])=>{const t=vi(e).toVar();return Gn(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),VT=Um([LT,fi((([e])=>{const t=Bi(e).toVar();return Gn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),OT=Um([DT,fi((([e])=>{const t=Bi(e).toVar();return Gn(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),GT=fi((([e,t])=>{const s=Si(t).toVar(),r=Ai(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(Si(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),kT=fi((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(GT(s,Si(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,Si(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,Si(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(GT(s,Si(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,Si(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,Si(4))),t.addAssign(e)})),zT=fi((([e,t,s])=>{const r=Ai(s).toVar(),i=Ai(t).toVar(),n=Ai(e).toVar();return r.bitXorAssign(i),r.subAssign(GT(i,Si(14))),n.bitXorAssign(r),n.subAssign(GT(r,Si(11))),i.bitXorAssign(n),i.subAssign(GT(n,Si(25))),r.bitXorAssign(i),r.subAssign(GT(i,Si(16))),n.bitXorAssign(r),n.subAssign(GT(r,Si(4))),i.bitXorAssign(n),i.subAssign(GT(n,Si(14))),r.bitXorAssign(i),r.subAssign(GT(i,Si(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),$T=fi((([e])=>{const t=Ai(e).toVar();return vi(t).div(vi(Ai(Si(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),HT=fi((([e])=>{const t=vi(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),WT=Um([fi((([e])=>{const t=Si(e).toVar(),s=Ai(Ai(1)).toVar(),r=Ai(Ai(Si(3735928559)).add(s.shiftLeft(Ai(2))).add(Ai(13))).toVar();return zT(r.add(Ai(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),fi((([e,t])=>{const s=Si(t).toVar(),r=Si(e).toVar(),i=Ai(Ai(2)).toVar(),n=Ai().toVar(),o=Ai().toVar(),a=Ai().toVar();return n.assign(o.assign(a.assign(Ai(Si(3735928559)).add(i.shiftLeft(Ai(2))).add(Ai(13))))),n.addAssign(Ai(r)),o.addAssign(Ai(s)),zT(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),fi((([e,t,s])=>{const r=Si(s).toVar(),i=Si(t).toVar(),n=Si(e).toVar(),o=Ai(Ai(3)).toVar(),a=Ai().toVar(),u=Ai().toVar(),l=Ai().toVar();return a.assign(u.assign(l.assign(Ai(Si(3735928559)).add(o.shiftLeft(Ai(2))).add(Ai(13))))),a.addAssign(Ai(n)),u.addAssign(Ai(i)),l.addAssign(Ai(r)),zT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),fi((([e,t,s,r])=>{const i=Si(r).toVar(),n=Si(s).toVar(),o=Si(t).toVar(),a=Si(e).toVar(),u=Ai(Ai(4)).toVar(),l=Ai().toVar(),d=Ai().toVar(),c=Ai().toVar();return l.assign(d.assign(c.assign(Ai(Si(3735928559)).add(u.shiftLeft(Ai(2))).add(Ai(13))))),l.addAssign(Ai(a)),d.addAssign(Ai(o)),c.addAssign(Ai(n)),kT(l,d,c),l.addAssign(Ai(i)),zT(l,d,c)})).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"}]}),fi((([e,t,s,r,i])=>{const n=Si(i).toVar(),o=Si(r).toVar(),a=Si(s).toVar(),u=Si(t).toVar(),l=Si(e).toVar(),d=Ai(Ai(5)).toVar(),c=Ai().toVar(),h=Ai().toVar(),p=Ai().toVar();return c.assign(h.assign(p.assign(Ai(Si(3735928559)).add(d.shiftLeft(Ai(2))).add(Ai(13))))),c.addAssign(Ai(l)),h.addAssign(Ai(u)),p.addAssign(Ai(a)),kT(c,h,p),c.addAssign(Ai(o)),h.addAssign(Ai(n)),zT(c,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"}]})]),jT=Um([fi((([e,t])=>{const s=Si(t).toVar(),r=Si(e).toVar(),i=Ai(WT(r,s)).toVar(),n=Fi().toVar();return n.x.assign(i.bitAnd(Si(255))),n.y.assign(i.shiftRight(Si(8)).bitAnd(Si(255))),n.z.assign(i.shiftRight(Si(16)).bitAnd(Si(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),fi((([e,t,s])=>{const r=Si(s).toVar(),i=Si(t).toVar(),n=Si(e).toVar(),o=Ai(WT(n,i,r)).toVar(),a=Fi().toVar();return a.x.assign(o.bitAnd(Si(255))),a.y.assign(o.shiftRight(Si(8)).bitAnd(Si(255))),a.z.assign(o.shiftRight(Si(16)).bitAnd(Si(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),qT=Um([fi((([e])=>{const t=Ci(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=vi(CT(t.x,s)).toVar(),n=vi(CT(t.y,r)).toVar(),o=vi(HT(i)).toVar(),a=vi(HT(n)).toVar(),u=vi(ET(UT(WT(s,r),i,n),UT(WT(s.add(Si(1)),r),i.sub(1),n),UT(WT(s,r.add(Si(1))),i,n.sub(1)),UT(WT(s.add(Si(1)),r.add(Si(1))),i.sub(1),n.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=Si().toVar(),n=vi(CT(t.x,s)).toVar(),o=vi(CT(t.y,r)).toVar(),a=vi(CT(t.z,i)).toVar(),u=vi(HT(n)).toVar(),l=vi(HT(o)).toVar(),d=vi(HT(a)).toVar(),c=vi(wT(UT(WT(s,r,i),n,o,a),UT(WT(s.add(Si(1)),r,i),n.sub(1),o,a),UT(WT(s,r.add(Si(1)),i),n,o.sub(1),a),UT(WT(s.add(Si(1)),r.add(Si(1)),i),n.sub(1),o.sub(1),a),UT(WT(s,r,i.add(Si(1))),n,o,a.sub(1)),UT(WT(s.add(Si(1)),r,i.add(Si(1))),n.sub(1),o,a.sub(1)),UT(WT(s,r.add(Si(1)),i.add(Si(1))),n,o.sub(1),a.sub(1)),UT(WT(s.add(Si(1)),r.add(Si(1)),i.add(Si(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),KT=Um([fi((([e])=>{const t=Ci(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=vi(CT(t.x,s)).toVar(),n=vi(CT(t.y,r)).toVar(),o=vi(HT(i)).toVar(),a=vi(HT(n)).toVar(),u=Bi(ET(IT(jT(s,r),i,n),IT(jT(s.add(Si(1)),r),i.sub(1),n),IT(jT(s,r.add(Si(1))),i,n.sub(1)),IT(jT(s.add(Si(1)),r.add(Si(1))),i.sub(1),n.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=Si().toVar(),n=vi(CT(t.x,s)).toVar(),o=vi(CT(t.y,r)).toVar(),a=vi(CT(t.z,i)).toVar(),u=vi(HT(n)).toVar(),l=vi(HT(o)).toVar(),d=vi(HT(a)).toVar(),c=Bi(wT(IT(jT(s,r,i),n,o,a),IT(jT(s.add(Si(1)),r,i),n.sub(1),o,a),IT(jT(s,r.add(Si(1)),i),n,o.sub(1),a),IT(jT(s.add(Si(1)),r.add(Si(1)),i),n.sub(1),o.sub(1),a),IT(jT(s,r,i.add(Si(1))),n,o,a.sub(1)),IT(jT(s.add(Si(1)),r,i.add(Si(1))),n.sub(1),o,a.sub(1)),IT(jT(s,r.add(Si(1)),i.add(Si(1))),n,o.sub(1),a.sub(1)),IT(jT(s.add(Si(1)),r.add(Si(1)),i.add(Si(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),XT=Um([fi((([e])=>{const t=vi(e).toVar(),s=Si(RT(t)).toVar();return $T(WT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),fi((([e])=>{const t=Ci(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar();return $T(WT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar();return $T(WT(s,r,i))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),fi((([e])=>{const t=Ii(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar(),n=Si(RT(t.w)).toVar();return $T(WT(s,r,i,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),YT=Um([fi((([e])=>{const t=vi(e).toVar(),s=Si(RT(t)).toVar();return Bi($T(WT(s,Si(0))),$T(WT(s,Si(1))),$T(WT(s,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),fi((([e])=>{const t=Ci(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar();return Bi($T(WT(s,r,Si(0))),$T(WT(s,r,Si(1))),$T(WT(s,r,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar();return Bi($T(WT(s,r,i,Si(0))),$T(WT(s,r,i,Si(1))),$T(WT(s,r,i,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),fi((([e])=>{const t=Ii(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar(),n=Si(RT(t.w)).toVar();return Bi($T(WT(s,r,i,n,Si(0))),$T(WT(s,r,i,n,Si(1))),$T(WT(s,r,i,n,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),QT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=vi(0).toVar(),l=vi(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(qT(a))),l.mulAssign(i),a.mulAssign(n)})),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"}]}),ZT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=Bi(0).toVar(),l=vi(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(KT(a))),l.mulAssign(i),a.mulAssign(n)})),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"}]}),JT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar();return Ci(QT(a,o,n,i),QT(a.add(Bi(Si(19),Si(193),Si(17))),o,n,i))})).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"}]}),e_=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=Bi(ZT(a,o,n,i)).toVar(),l=vi(QT(a.add(Bi(Si(19),Si(193),Si(17))),o,n,i)).toVar();return Ii(u,l)})).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"}]}),t_=Um([fi((([e,t,s,r,i,n,o])=>{const a=Si(o).toVar(),u=vi(n).toVar(),l=Si(i).toVar(),d=Si(r).toVar(),c=Si(s).toVar(),h=Si(t).toVar(),p=Ci(e).toVar(),g=Bi(YT(Ci(h.add(d),c.add(l)))).toVar(),m=Ci(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=Ci(Ci(vi(h),vi(c)).add(m)).toVar(),y=Ci(f.sub(p)).toVar();return Ti(a.equal(Si(2)),(()=>Fo(y.x).add(Fo(y.y)))),Ti(a.equal(Si(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),fi((([e,t,s,r,i,n,o,a,u])=>{const l=Si(u).toVar(),d=vi(a).toVar(),c=Si(o).toVar(),h=Si(n).toVar(),p=Si(i).toVar(),g=Si(r).toVar(),m=Si(s).toVar(),f=Si(t).toVar(),y=Bi(e).toVar(),b=Bi(YT(Bi(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Bi(Bi(vi(f),vi(m),vi(g)).add(b)).toVar(),T=Bi(x.sub(y)).toVar();return Ti(l.equal(Si(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),Ti(l.equal(Si(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),s_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=vi(1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();l.assign(qo(l,s))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),r_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=Ci(1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();Ti(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=Bi(1e6,1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();Ti(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),n_=Um([s_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=vi(1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();d.assign(qo(d,n))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),o_=Um([r_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=Ci(1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();Ti(n.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.y.assign(n)}))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),a_=Um([i_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=Bi(1e6,1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();Ti(n.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(n)})).ElseIf(n.lessThan(d.z),(()=>{d.z.assign(n)}))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=fi((([e])=>{const t=e.y,s=e.z,r=Bi().toVar();return Ti(t.lessThan(1e-4),(()=>{r.assign(Bi(s,s,s))})).Else((()=>{let i=e.x;i=i.sub(vo(i)).mul(6).toVar();const n=Si(zo(i)),o=i.sub(vi(n)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());Ti(n.equal(Si(0)),(()=>{r.assign(Bi(s,l,a))})).ElseIf(n.equal(Si(1)),(()=>{r.assign(Bi(u,s,a))})).ElseIf(n.equal(Si(2)),(()=>{r.assign(Bi(a,s,l))})).ElseIf(n.equal(Si(3)),(()=>{r.assign(Bi(a,u,s))})).ElseIf(n.equal(Si(4)),(()=>{r.assign(Bi(l,a,s))})).Else((()=>{r.assign(Bi(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),l_=fi((([e])=>{const t=Bi(e).toVar(),s=vi(t.x).toVar(),r=vi(t.y).toVar(),i=vi(t.z).toVar(),n=vi(qo(s,qo(r,i))).toVar(),o=vi(Ko(s,Ko(r,i))).toVar(),a=vi(o.sub(n)).toVar(),u=vi().toVar(),l=vi().toVar(),d=vi().toVar();return d.assign(o),Ti(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),Ti(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{Ti(s.greaterThanEqual(o),(()=>{u.assign(r.sub(i).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vn(2,i.sub(s).div(a)))})).Else((()=>{u.assign(Vn(4,s.sub(r).div(a)))})),u.mulAssign(1/6),Ti(u.lessThan(0),(()=>{u.addAssign(1)}))})),Bi(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),d_=fi((([e])=>{const t=Bi(e).toVar(),s=Pi(jn(t,Bi(.04045))).toVar(),r=Bi(t.div(12.92)).toVar(),i=Bi(sa(Ko(t.add(Bi(.055)),Bi(0)).div(1.055),Bi(2.4))).toVar();return la(r,i,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),c_=(e,t)=>{e=vi(e),t=vi(t);const s=Ci(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},h_=(e,t,s,r)=>la(e,t,s[r].clamp()),p_=(e,t,s=mu())=>h_(e,t,s,"x"),g_=(e,t,s=mu())=>h_(e,t,s,"y"),m_=(e,t,s,r,i)=>la(e,t,c_(s,r[i])),f_=(e,t,s,r=mu())=>m_(e,t,s,r,"x"),y_=(e,t,s,r=mu())=>m_(e,t,s,r,"y"),b_=(e=1,t=0,s=mu())=>s.mul(e).add(t),x_=(e,t=1)=>(e=vi(e)).abs().pow(t).mul(e.sign()),T_=(e,t=1,s=.5)=>vi(e).sub(s).mul(t).add(s),__=(e=mu(),t=1,s=0)=>qT(e.convert("vec2|vec3")).mul(t).add(s),N_=(e=mu(),t=1,s=0)=>KT(e.convert("vec2|vec3")).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ii(KT(e),qT(e.add(Ci(19,73)))).mul(t).add(s)},S_=(e=mu(),t=1)=>n_(e.convert("vec2|vec3"),t,Si(1)),A_=(e=mu(),t=1)=>o_(e.convert("vec2|vec3"),t,Si(1)),R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,Si(1)),C_=(e=mu())=>XT(e.convert("vec2|vec3")),E_=(e=mu(),t=3,s=2,r=.5,i=1)=>QT(e,Si(t),s,r).mul(i),w_=(e=mu(),t=3,s=2,r=.5,i=1)=>JT(e,Si(t),s,r).mul(i),M_=(e=mu(),t=3,s=2,r=.5,i=1)=>ZT(e,Si(t),s,r).mul(i),B_=(e=mu(),t=3,s=2,r=.5,i=1)=>e_(e,Si(t),s,r).mul(i),U_=fi((([e,t,s])=>{const r=Ao(e).toVar("nDir"),i=On(vi(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),n=On(vi(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Bi().toVar("rbminmax");o.x=r.x.greaterThan(vi(0)).select(i.x,n.x),o.y=r.y.greaterThan(vi(0)).select(i.y,n.y),o.z=r.z.greaterThan(vi(0)).select(i.z,n.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),F_=fi((([e,t])=>{const s=e.x,r=e.y,i=e.z;let n=t.element(0).mul(.886227);return n=n.add(t.element(1).mul(1.023328).mul(r)),n=n.add(t.element(2).mul(1.023328).mul(i)),n=n.add(t.element(3).mul(1.023328).mul(s)),n=n.add(t.element(4).mul(.858086).mul(s).mul(r)),n=n.add(t.element(5).mul(.858086).mul(r).mul(i)),n=n.add(t.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),n=n.add(t.element(7).mul(.858086).mul(s).mul(i)),n=n.add(t.element(8).mul(.429043).mul(Gn(s,s).sub(Gn(r,r)))),n})),P_=new cm;class I_ extends Lg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,i=this.nodes.getBackgroundNode(e)||e.background;let n=!1;if(null===i)r._clearColor.getRGB(P_,Se),P_.a=r._clearColor.a;else if(!0===i.isColor)i.getRGB(P_,Se),P_.a=1,n=!0;else if(!0===i.isNode){const s=this.get(e),n=i;P_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ii(n).mul(If),{getUV:()=>Lf.mul(ll),getTextureLevel:()=>Pf});let t=Wd();t=t.setZ(t.w);const r=new rh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ii(n).mul(If),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",i);if(!0===r.autoClear||!0===n){const e=s.clearColorValue;e.r=P_.r,e.g=P_.g,e.b=P_.b,e.a=P_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let L_=0;class D_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=L_++}}class V_{constructor(e,t,s,r,i,n,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=i,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new D_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class O_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class G_{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 k_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class z_ extends k_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class $_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let H_=0;class W_{constructor(e=null){this.id=H_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class j_{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 q_ extends j_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class K_ extends j_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class X_ extends j_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Y_ extends j_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Q_ extends j_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends j_{constructor(e,t=new i){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class J_ extends j_{constructor(e,t=new n){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class eN extends q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class tN extends K_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const aN=[.125,.215,.35,.446,.526,.582],uN=20,lN=new xe(-1,1,1,-1,0,1),dN=new Be(90,1),cN=new e;let hN=null,pN=0,gN=0;const mN=(1+Math.sqrt(5))/2,fN=1/mN,yN=[new s(-mN,fN,0),new s(mN,fN,0),new s(-fN,0,mN),new s(fN,0,mN),new s(0,mN,-fN),new s(0,mN,fN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],bN=[3,1,5,0,4,2],xN=$p(mu(),gu("faceIndex")).normalize(),TN=Bi(xN.x,xN.y.negate(),xN.z);class _N{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}fromScene(e,t=0,s=.1,r=100){hN=this._renderer.getRenderTarget(),pN=this._renderer.getActiveCubeFace(),gN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const i=this._allocateTargets();return i.depthBuffer=!0,this._sceneToCubeUV(e,s,r,i),t>0&&this._blur(i,0,0,t),this._applyPMREM(i),this._cleanup(i),i}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=AN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=RN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget(hN,pN,gN),e.scissorTest=!1,vN(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===T||e.mapping===_?this._setSize(0===e.image.length?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),hN=this._renderer.getRenderTarget(),pN=this._renderer.getActiveCubeFace(),gN=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,r={magFilter:$,minFilter:$,generateMipmaps:!1,type:ye,format:Ue,colorSpace:Se},i=NN(e,t,r);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=NN(e,t,r);const{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=function(e){const t=[],s=[],r=[],i=[];let n=e;const o=e-4+1+aN.length;for(let a=0;a<o;a++){const o=Math.pow(2,n);s.push(o);let u=1/o;a>e-4?u=aN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e<p;e++){const t=e%3*2/3-1,s=e>2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],i=bN[e];b.set(r,m*g*i),x.set(h,f*g*i);const n=[i,i,i,i,i,i];T.set(n,y*g*i)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),i.push(new k(_,null)),n>4&&n--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:i}}(i)),this._blurMaterial=function(e,t,r){const i=Rl(new Array(uN).fill(0)),n=en(new s(0,1,0)),o=en(0),a=vi(uN),u=en(0),l=en(1),d=_u(null),c=en(0),h=vi(1/t),p=vi(1/r),g=vi(e),m={n:a,latitudinal:u,weights:i,poleAxis:n,outputDirection:TN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=SN("blur");return f.uniforms=m,f.fragmentNode=qp({...m,latitudinal:u.equal(1)}),f}(i,e,t)}return i}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,lN)}_sceneToCubeUV(e,t,s,r){const i=dN;i.near=t,i.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(cN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(cN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,i);for(let t=0;t<6;t++){const s=t%3;0===s?(i.up.set(0,n[t],0),i.lookAt(o[t],0,0)):1===s?(i.up.set(0,0,n[t]),i.lookAt(0,o[t],0)):(i.up.set(0,n[t],0),i.lookAt(0,0,o[t]));const u=this._cubeSize;vN(r,s*u,t>2?u:0,u,u),a.render(e,i)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=AN(e)):null===this._equirectMaterial&&(this._equirectMaterial=RN(e));const i=r?this._cubemapMaterial:this._equirectMaterial;i.fragmentNode.value=e;const n=this._lodMeshes[0];n.material=i;const o=this._cubeSize;vN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(n,lN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;t<r;t++){const s=Math.sqrt(this._sigmas[t]*this._sigmas[t]-this._sigmas[t-1]*this._sigmas[t-1]),i=yN[(r-t-1)%yN.length];this._blur(e,t-1,t,s,i)}t.autoClear=s}_blur(e,t,s,r,i){const n=this._pingPongRenderTarget;this._halfBlur(e,n,t,s,r,"latitudinal",i),this._halfBlur(n,e,s,s,r,"longitudinal",i)}_halfBlur(e,t,s,r,i,n,o){const a=this._renderer,u=this._blurMaterial;"latitudinal"!==n&&"longitudinal"!==n&&console.error("blur direction must be either latitudinal or longitudinal!");const l=this._lodMeshes[r];l.material=u;const d=u.uniforms,c=this._sizeLods[s]-1,h=isFinite(i)?Math.PI/(2*c):2*Math.PI/39,p=i/h,g=isFinite(i)?1+Math.floor(3*p):uN;g>uN&&console.warn(`sigmaRadians, ${i}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;e<uN;++e){const t=e/p,s=Math.exp(-t*t/2);m.push(s),0===e?f+=s:e<g&&(f+=2*s)}for(let e=0;e<m.length;e++)m[e]=m[e]/f;e.texture.frame=(e.texture.frame||0)+1,d.envMap.value=e.texture,d.samples.value=g,d.weights.array=m,d.latitudinal.value="latitudinal"===n?1:0,o&&(d.poleAxis.value=o);const{_lodMax:y}=this;d.dTheta.value=h,d.mipInt.value=y-s;const b=this._sizeLods[r];vN(t,3*b*(r>y-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,lN)}}function NN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function vN(e,t,s,r,i){e.viewport.set(t,s,r,i),e.scissor.set(t,s,r,i)}function SN(e){const t=new rh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function AN(e){const t=SN("cubemap");return t.fragmentNode=_l(e,TN),t}function RN(e){const t=SN("equirect");return t.fragmentNode=_u(e,yh(TN),0),t}const CN=new WeakMap,EN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),wN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),MN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class BN{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=mm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new W_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=CN.get(this.renderer);return void 0===e&&(e=new Bg,CN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new bh(e,t)}createPMREMGenerator(){return new _N(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let i,n=!0;for(const e of t)r.push(e),n=n&&!0!==e.groupNode.shared;return n?(i=s.get(r),void 0===i&&(i=new D_(e,r,this.bindingsIndexes[e].group,r),s.set(r,i))):i=new D_(e,r,this.bindingsIndexes[e].group,r),i}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const i=s[e][r];(t[r]||(t[r]=[])).push(...i)}e=[];for(const s in t){const r=t[s],i=this._getBindGroup(s,r);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.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){!1===this.nodes.includes(e)&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){!1===this.sequentialNodes.includes(e)&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(const e of this.nodes){e.getUpdateType()!==br.NONE&&this.updateNodes.push(e.getSelf())}for(const e of this.sequentialNodes){const t=e.getUpdateBeforeType(),s=e.getUpdateAfterType();t!==br.NONE&&this.updateBeforeNodes.push(e.getSelf()),s!==br.NONE&&this.updateAfterNodes.push(e.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===$||e.magFilter===Fe||e.magFilter===Pe||e.magFilter===M||e.minFilter===$||e.minFilter===Fe||e.minFilter===Pe||e.minFilter===M}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 void 0===s.cache&&(s.cache=new W_(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=void 0===t.usageCount?1:t.usageCount+1,t.usageCount}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(i,n=null){if(null===n&&("float"===i||"int"===i||"uint"===i?n=0:"bool"===i?n=!1:"color"===i?n=new e:"vec2"===i?n=new t:"vec3"===i?n=new s:"vec4"===i&&(n=new r)),"float"===i)return MN(n);if("int"===i)return`${Math.round(n)}`;if("uint"===i)return n>=0?`${Math.round(n)}u`:"0u";if("bool"===i)return n?"true":"false";if("color"===i)return`${this.getType("vec3")}( ${MN(n.r)}, ${MN(n.g)}, ${MN(n.b)} )`;const o=this.getTypeLength(i),a=this.getComponentType(i),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)} )`;if(3===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)} )`;if(4===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)}, ${u(n.w)} )`;if(o>4&&n&&(n.isMatrix3||n.isMatrix4))return`${this.getType(i)}( ${n.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(i)}()`;throw new Error(`NodeBuilder: Type '${i}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new O_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=EN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return wN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,i=e.normalized;let n;return e instanceof Ie||!0===i||(n=this.getTypeFromArray(s)),this.getTypeFromLength(r,n)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?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"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=mm(this.stack),this.stacks.push(xi()||this.stack),bi(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,bi(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[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 r=s.bufferAttribute;if(void 0===r){const i=this.uniforms.index++;r=new O_("nodeAttribute"+i,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const i=this.getDataFromNode(e,s,this.globalCache);let n=i.uniform;if(void 0===n){const o=this.uniforms.index++;n=new G_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(n),i.uniform=n}return n}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const i=this.getDataFromNode(e,r);let n=i.variable;if(void 0===n){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),n=new k_(t,s),e.push(n),i.variable=n}return n}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let i=r.varying;if(void 0===i){const e=this.varyings,n=e.length;null===t&&(t="nodeVarying"+n),i=new z_(t,s),e.push(i),r.varying=i}return i}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let i=r.code;if(void 0===i){const e=this.codes[s]||(this.codes[s]=[]),n=e.length;i=new $_("nodeCode"+n,t),e.push(i),r.code=i}return i}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let i=!0,n=t;for(;n;){if(!0===r.get(n)){i=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(i)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),i=r.flowCodes||(r.flowCodes=[]),n=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);i.push(t),n.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",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 nx,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 e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new hm(e.type,e.name);e.layout=null;const r=e.call(s),i=this.flowStagesNode(r,t.type);return e.layout=t,i}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,i=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new W_,this.stack=mm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=i,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const i=this.shaderStage;this.setShaderStage(e);const n=this.flowChildNode(t,s);return null!==r&&(n.code+=`${this.tab+r} = ${n.result};\n`),this.flowCode[e]=this.flowCode[e]+n.code,this.setShaderStage(i),n}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(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";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(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new rh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new eN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new tN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new sN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new rN(e);if("color"===t)return new iN(e);if("mat3"===t)return new nN(e);if("mat4"===t)return new oN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),i=this.getTypeLength(s);return 16===r&&9===i?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===i?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||i>4||0===i?e:r===i?`${this.getType(s)}( ${e} )`:r>i?this.format(`${e}.${"xyz".slice(0,i)}`,this.getTypeFromLength(i,this.getComponentType(t)),s):4===i&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&i>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class UN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,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 void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class FN{constructor(e,t,s=null,r="",i=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=i}}FN.isNodeFunctionInput=!0;class PN extends xT{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=tT(this.light),i=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:i},e.stack,e)}}const IN=new n,LN=new n;let DN=null;class VN extends xT{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=en(new s).setGroup(Qi),this.halfWidth=en(new s).setGroup(Qi),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;LN.identity(),IN.copy(t.matrixWorld),IN.premultiply(s),LN.extractRotation(IN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(LN),this.halfHeight.value.applyMatrix4(LN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(DN.LTC_FLOAT_1),s=_u(DN.LTC_FLOAT_2)):(t=_u(DN.LTC_HALF_1),s=_u(DN.LTC_HALF_2));const{colorNode:r,light:i}=this,n=e.context.lightingModel,o=eT(i),a=e.context.reflectedLight;n.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){DN=e}}class ON extends xT{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=en(0).setGroup(Qi),this.penumbraCosNode=en(0).setGroup(Qi),this.cutoffDistanceNode=en(0).setGroup(Qi),this.decayExponentNode=en(0).setGroup(Qi)}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 pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:i,light:n}=this,o=eT(n).sub(el),a=o.normalize(),u=a.dot(tT(n)),l=this.getSpotAttenuation(u),d=o.length(),c=TT({lightDistance:d,cutoffDistance:r,decayExponent:i}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class GN extends ON{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,Ci(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class kN extends xT{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class zN extends xT{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=Zx(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=en(new e).setGroup(Qi)}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:r}=this,i=ul.dot(r).mul(.5).add(.5),n=la(s,t,i);e.context.irradiance.addAssign(n)}}class $N extends xT{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=F_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class HN{parseFunction(){console.warn("Abstract function.")}}class WN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}WN.isNodeFunction=!0;const jN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,qN=/[a-z_0-9]+/gi,KN="#pragma main";class XN extends WN{constructor(e){const{type:t,inputs:s,name:r,precision:i,inputsCode:n,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(KN),s=-1!==t?e.slice(t+12):e,r=s.match(jN);if(null!==r&&5===r.length){const i=r[4],n=[];let o=null;for(;null!==(o=qN.exec(i));)n.push(o);const a=[];let u=0;for(;u<n.length;){const e="const"===n[u][0];!0===e&&u++;let t=n[u][0];"in"===t||"out"===t||"inout"===t?u++:t="";const s=n[u++][0];let r=Number.parseInt(n[u][0]);!1===Number.isNaN(r)?u++:r=null;const i=n[u++][0];a.push(new FN(s,i,r,t,e))}const l=s.substring(r[0].length),d=void 0!==r[3]?r[3]:"";return{type:r[2],inputs:a,name:d,precision:void 0!==r[1]?r[1]:"",inputsCode:i,blockCode:l,headerCode:-1!==t?e.slice(0,t):""}}throw new Error("FunctionNode: Function is not a GLSL code.")})(e);super(t,s,r,i),this.inputsCode=n,this.blockCode=o,this.headerCode=a}getCode(e=this.name){let t;const s=this.blockCode;if(""!==s){const{type:r,inputsCode:i,headerCode:n,precision:o}=this;let a=`${r} ${e} ( ${i.trim()} )`;""!==o&&(a=`${o} ${a}`),t=n+a+s}else t="";return t}}class YN extends HN{parseFunction(e){return new XN(e)}}const QN=new WeakMap;class ZN extends Lg{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new UN,this.nodeBuilderCache=new Map,this.callHashCache=new Bg,this.groupsData=new Bg}updateGroup(e){const t=e.groupNode,s=t.name;if(s===Zi.name)return!0;if(s===Qi.name){const t=this.get(e),s=this.nodeFrame.renderId;return t.renderId!==s&&(t.renderId=s,!0)}if(s===Yi.name){const t=this.get(e),s=this.nodeFrame.frameId;return t.frameId!==s&&(t.frameId=s,!0)}const r=[t,e];let i=this.groupsData.get(r);return void 0===i&&this.groupsData.set(r,i={}),i.version!==t.version&&(i.version=t.version,!0)}getForRenderCacheKey(e){return e.initialCacheKey}getForRender(e){const t=this.get(e);let s=t.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:r}=this,i=this.getForRenderCacheKey(e);if(s=r.get(i),void 0===s){const t=this.backend.createNodeBuilder(e.object,this.renderer);t.scene=e.scene,t.material=e.material,t.camera=e.camera,t.context.material=e.material,t.lightsNode=e.lightsNode,t.environmentNode=this.getEnvironmentNode(e.scene),t.fogNode=this.getFogNode(e.scene),t.clippingContext=e.clippingContext,t.build(),s=this._createNodeBuilderState(t),r.set(i,s)}s.usedTimes++,t.nodeBuilderState=s}return s}delete(e){if(e.isRenderObject){const t=this.get(e).nodeBuilderState;t.usedTimes--,0===t.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e))}return super.delete(e)}getForCompute(e){const t=this.get(e);let s=t.nodeBuilderState;if(void 0===s){const r=this.backend.createNodeBuilder(e,this.renderer);r.build(),s=this._createNodeBuilderState(r),t.nodeBuilderState=s}return s}_createNodeBuilderState(e){return new V_(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.monitor,e.transforms)}getEnvironmentNode(e){return e.environmentNode||this.get(e).environmentNode||null}getBackgroundNode(e){return e.backgroundNode||this.get(e).backgroundNode||null}getFogNode(e){return e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){const s=[e,t],r=this.renderer.info.calls;let i=this.callHashCache.get(s);if(void 0===i||i.callId!==r){const n=this.getEnvironmentNode(e),o=this.getFogNode(e),a=[];t&&a.push(t.getCacheKey(!0)),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),a.push(this.renderer.shadowMap.enabled?1:0),i={callId:r,cacheKey:ur(a)},this.callHashCache.set(s,i)}return i.cacheKey}updateScene(e){this.updateEnvironment(e),this.updateFog(e),this.updateBackground(e)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){const t=this.get(e),s=e.background;if(s){const r=0===e.backgroundBlurriness&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Zp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=vh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Qi),r=Ml("density","float",s).setGroup(Qi);e=_x(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Qi),r=Ml("near","float",s).setGroup(Qi),i=Ml("far","float",s).setGroup(Qi);e=xx(t,r,i)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,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){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,i=null){const n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=s,n.camera=r,n.material=i,n}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 QN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return QN.set(e,s),r}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 e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new UN,this.nodeBuilderCache=new Map}}const JN=new me;class ev{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new i,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let i=0;i<r;i++){JN.copy(e[i]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const r=t[s+i],n=JN.normal;r.x=-n.x,r.y=-n.y,r.z=-n.z,r.w=JN.constant}}updateGlobal(e,t){this.shadowPass=null!==e.overrideMaterial&&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 i=t.clippingPlanes,n=i.length;let o,a;if(this.clipIntersection?(o=this.intersectionPlanes,a=e.intersectionPlanes.length):(o=this.unionPlanes,a=e.unionPlanes.length),o.length!==a+n){o.length=a+n;for(let e=0;e<n;e++)o[a+e]=new r;s=!0}this.projectPlanes(i,o,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 void 0===t&&(t=new ev(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class tv{constructor(e,t){this.scene=e,this.camera=t}clone(){return Object.assign(new this.constructor,this)}}class sv{constructor(){this.lists=new Bg}get(e,t){const s=this.lists,r=[e,t];let i=s.get(r);return void 0===i&&(i=new tv(e,t),s.set(r,i)),i}dispose(){this.lists=new Bg}}class rv{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(null!==s){t=new s;for(const s in e)t[s]=e[s]}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}`);else{if("function"!=typeof e)throw new Error(`Node class ${e.name} is not a class.`);if("function"==typeof t||"object"==typeof t)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}`);else{if("function"!=typeof e)throw new Error(`Node class ${e.name} is not a class.`);if("function"!=typeof t)throw new Error(`Base class ${t.name} is not a class.`);s.set(t,e)}}}const iv=new iT;class nv extends Bg{constructor(){super()}createNode(e=[]){return(new iT).setLights(e)}getNode(e,t){if(e.isQuadMesh)return iv;const s=[e,t];let r=this.get(s);return void 0===r&&(r=this.createNode(),this.set(s,r)),r}}const ov=new z,av=new t,uv=new r,lv=new Ge,dv=new n,cv=new r;class hv{constructor(e,t={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,depth:n=!0,stencil:o=!1,antialias:a=!1,samples:u=0,getFallback:l=null}=t;this.domElement=e.getDomElement(),this.backend=e,this.samples=u||!0===a?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=De,this.toneMapping=d,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=n,this.stencil=o,this.info=new jg,this.nodes={modelViewMatrix:null,modelNormalViewMatrix:null},this.library=new rv,this.lighting=new nv,this._getFallback=l,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new r(0,0,this._width,this._height),this._scissor=new r(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 xf(new rh),this._quad.material.type="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const c=!0===this.alpha?0:1;this._clearColor=new cm(0,0,0,c),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:Ve},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(e,t,s)=>{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),i=this._renderContexts.get(e,t,this._renderTarget),n=e.overrideMaterial||s.material,o=this._objects.get(s,n,e,t,r.lightsNode,i,i.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ZN(this,s),this._animation=new Mg(this._nodes,this.info),this._attributes=new zg(s),this._background=new I_(this,this._nodes),this._geometries=new Wg(this._attributes,this.info),this._textures=new dm(this,s,this.info),this._pipelines=new Zg(s,this._nodes),this._bindings=new Jg(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Ig(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new sv,this._renderContexts=new um,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,i=r.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:ov;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new ev),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=i,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&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:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:i,renderList:n}=e,o=this._currentRenderContext,a=this._bundles.get(r,i),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=n.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,i,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t<s;t++){const s=e[t];this._nodes.needsRefresh(s)&&(this._nodes.updateBefore(s),this._nodes.updateForRender(s),this._bindings.updateForRender(s),this._nodes.updateAfter(s))}}this.backend.addBundle(o,a)}render(e,t){if(!1===this._initialized)return console.warn("THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead."),this.renderAsync(e,t);this._renderScene(e,t)}_getFrameBufferTarget(){const{currentToneMapping:e,currentColorSpace:t}=this;if(!1===(e!==d)&&!1===(t!==Se))return null;const{width:s,height:r}=this.getDrawingBufferSize(av),{depth:i,stencil:n}=this;let o=this._frameBufferTarget;return null===o&&(o=new ge(s,r,{depthBuffer:i,stencilBuffer:n,type:ye,format:Ue,colorSpace:Se,generateMipmaps:!1,minFilter:$,magFilter:$,samples:this.samples}),o.isPostProcessingRenderTarget=!0,this._frameBufferTarget=o),o.depthBuffer=i,o.stencilBuffer=n,o.setSize(s,r),o.viewport.copy(this._viewport),o.scissor.copy(this._scissor),o.viewport.multiplyScalar(this._pixelRatio),o.scissor.multiplyScalar(this._pixelRatio),o.scissorTest=this._scissorTest,o}_renderScene(e,t,s=!0){if(!0===this._isDeviceLost)return;const r=s?this._getFrameBufferTarget():null,i=this._nodes.nodeFrame,n=i.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,u=!0===e.isScene?e:ov,l=this._renderTarget,d=this._activeCubeFace,c=this._activeMipmapLevel;let h;null!==r?(h=r,this.setRenderTarget(h)):h=l;const p=this._renderContexts.get(e,t,h);this._currentRenderContext=p,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,i.renderId=this.info.calls;const g=this.coordinateSystem;t.coordinateSystem!==g&&(t.coordinateSystem=g,t.updateProjectionMatrix()),!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),null===t.parent&&!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld();let m=this._viewport,f=this._scissor,y=this._pixelRatio;null!==h&&(m=h.viewport,f=h.scissor,y=1),this.getDrawingBufferSize(av),uv.set(0,0,av.width,av.height);const b=void 0===m.minDepth?0:m.minDepth,x=void 0===m.maxDepth?1:m.maxDepth;p.viewportValue.copy(m).multiplyScalar(y).floor(),p.viewportValue.width>>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(uv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(uv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new ev),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),dv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),lv.setFromProjectionMatrix(dv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),i.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,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),!0===s&&(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,r){const i=this._scissor;e.isVector4?i.copy(e):i.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,i=0,n=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=i,o.maxDepth=n}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let i=null;if(null!==r&&(this._textures.updateRenderTarget(r),i=this._textures.get(r)),this.backend.clear(e,t,s,i),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.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){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se: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(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);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 r=this.backend,i=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===i.has(t)){const e=()=>{t.removeEventListener("dispose",e),i.delete(t),n.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),n.updateForCompute(t);const s=n.getForCompute(t),a=i.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=cv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=cv.copy(t).floor()}else t=cv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,i=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,i)}readRenderTargetPixelsAsync(e,t,s,r,i,n=0,o=0){return this.backend.copyTextureToBuffer(e.textures[n],t,s,r,i,o)}_projectObject(e,t,s,r,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(i=i.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||lv.intersectsSprite(e)){!0===this.sortObjects&&cv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(dv);const{geometry:t,material:n}=e;n.visible&&r.push(e,t,n,s,cv.z,null,i)}}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||lv.intersectsObject(e))){const{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),cv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(dv)),Array.isArray(n)){const o=t.groups;for(let a=0,u=o.length;a<u;a++){const u=o[a],l=n[u.materialIndex];l&&l.visible&&r.push(e,t,l,s,cv.z,u,i)}}else n.visible&&r.push(e,t,n,s,cv.z,null,i)}if(!0===e.isBundleGroup&&void 0!==this.backend.beginBundle){const s=r;(r=this._renderLists.get(e,t)).begin(),s.pushBundle({bundleGroup:e,camera:t,renderList:r}),r.finish()}const n=e.children;for(let e=0,o=n.length;e<o;e++)this._projectObject(n[e],t,s,r,i)}_renderBundles(e,t,s){for(const r of e)this._renderBundle(r,t,s)}_renderTransparents(e,t,s,r,i){if(t.length>0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,i,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,i);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,i)}_renderObjects(e,t,s,r,i=null){for(let n=0,o=e.length;n<o;n++){const o=e[n],{object:a,geometry:u,material:l,group:d,clippingContext:c}=o;if(t.isArrayCamera){const e=t.cameras;for(let t=0,n=e.length;t<n;t++){const n=e[t];if(a.layers.test(n.layers)){const e=n.viewport,t=void 0===e.minDepth?0:e.minDepth,o=void 0===e.maxDepth?1:e.maxDepth,h=this._currentRenderContext.viewportValue;h.copy(e).multiplyScalar(this._pixelRatio).floor(),h.minDepth=t,h.maxDepth=o,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(a,s,n,u,l,d,r,c,i)}}}else this._currentRenderObjectFunction(a,s,t,u,l,d,r,c,i)}}renderObject(e,t,s,r,i,n,o,a=null,u=null){let l,d,c;if(e.onBeforeRender(this,t,s,r,i,n),null!==t.overrideMaterial){const e=t.overrideMaterial;i.positionNode&&i.positionNode.isNode&&(l=e.positionNode,e.positionNode=i.positionNode),e.isShadowNodeMaterial&&(e.side=null===i.shadowSide?i.side:i.shadowSide,i.depthNode&&i.depthNode.isNode&&(c=e.depthNode,e.depthNode=i.depthNode),i.shadowNode&&i.shadowNode.isNode&&(d=e.fragmentNode,e.fragmentNode=i.shadowNode)),i=e}!0===i.transparent&&i.side===le&&!1===i.forceSinglePass?(i.side=x,this._handleObjectFunction(e,i,t,s,o,n,a,"backSide"),i.side=Oe,this._handleObjectFunction(e,i,t,s,o,n,a,u),i.side=le):this._handleObjectFunction(e,i,t,s,o,n,a,u),void 0!==l&&(t.overrideMaterial.positionNode=l),void 0!==c&&(t.overrideMaterial.depthNode=c),void 0!==d&&(t.overrideMaterial.fragmentNode=d),e.onAfterRender(this,t,s,r,i,n)}_renderObjectDirect(e,t,s,r,i,n,o,a){const u=this._objects.get(e,t,s,r,i,this._currentRenderContext,o,a);u.drawRange=e.geometry.drawRange,u.group=n;const l=this._nodes.needsRefresh(u);if(l&&(this._nodes.updateBefore(u),this._geometries.updateForRender(u),this._nodes.updateForRender(u),this._bindings.updateForRender(u)),this._pipelines.updateForRender(u),null!==this._currentRenderBundle){this.backend.get(this._currentRenderBundle).renderObjects.push(u),u.bundle=this._currentRenderBundle.scene}this.backend.draw(u,this.info),l&&this._nodes.updateAfter(u)}_createObjectPipeline(e,t,s,r,i,n,o){const a=this._objects.get(e,t,s,r,i,this._currentRenderContext,n,o);this._nodes.updateBefore(a),this._geometries.updateForRender(a),this._nodes.updateForRender(a),this._bindings.updateForRender(a),this._pipelines.getForRender(a,this._compilationPromises),this._nodes.updateAfter(a)}get compile(){return this.compileAsync}}class pv{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}clone(){return Object.assign(new this.constructor,this)}}class gv extends pv{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t}get byteLength(){return(e=this._buffer.byteLength)+(kg-e%kg)%kg;var e}get buffer(){return this._buffer}update(){return!0}}class mv extends gv{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let fv=0;class yv extends mv{constructor(e,t){super("UniformBuffer_"+fv++,e?e.value:null),this.nodeUniform=e,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class bv extends mv{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-1!==t&&this.uniforms.splice(t,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(null===e){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 s=this.uniforms[t],{boundary:r,itemSize:i}=s,n=e%kg;0!==n&&kg-n-r<0?e+=kg-n:n%r!=0&&(e+=n%r),s.offset=e/this.bytesPerElement,e+=i*this.bytesPerElement}return Math.ceil(e/kg)*kg}update(){let e=!1;for(const t of this.uniforms)!0===this.updateByType(t)&&(e=!0);return e}updateByType(e){return e.isNumberUniform?this.updateNumber(e):e.isVector2Uniform?this.updateVector2(e):e.isVector3Uniform?this.updateVector3(e):e.isVector4Uniform?this.updateVector4(e):e.isColorUniform?this.updateColor(e):e.isMatrix3Uniform?this.updateMatrix3(e):e.isMatrix4Uniform?this.updateMatrix4(e):void console.error("THREE.WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1;const s=this.values,r=e.getValue(),i=e.offset;if(s[i]!==r){this.buffer[i]=s[i]=r,t=!0}return t}updateVector2(e){let t=!1;const s=this.values,r=e.getValue(),i=e.offset;if(s[i+0]!==r.x||s[i+1]!==r.y){const e=this.buffer;e[i+0]=s[i+0]=r.x,e[i+1]=s[i+1]=r.y,t=!0}return t}updateVector3(e){let t=!1;const s=this.values,r=e.getValue(),i=e.offset;if(s[i+0]!==r.x||s[i+1]!==r.y||s[i+2]!==r.z){const e=this.buffer;e[i+0]=s[i+0]=r.x,e[i+1]=s[i+1]=r.y,e[i+2]=s[i+2]=r.z,t=!0}return t}updateVector4(e){let t=!1;const s=this.values,r=e.getValue(),i=e.offset;if(s[i+0]!==r.x||s[i+1]!==r.y||s[i+2]!==r.z||s[i+4]!==r.w){const e=this.buffer;e[i+0]=s[i+0]=r.x,e[i+1]=s[i+1]=r.y,e[i+2]=s[i+2]=r.z,e[i+3]=s[i+3]=r.w,t=!0}return t}updateColor(e){let t=!1;const s=this.values,r=e.getValue(),i=e.offset;if(s[i+0]!==r.r||s[i+1]!==r.g||s[i+2]!==r.b){const e=this.buffer;e[i+0]=s[i+0]=r.r,e[i+1]=s[i+1]=r.g,e[i+2]=s[i+2]=r.b,t=!0}return t}updateMatrix3(e){let t=!1;const s=this.values,r=e.getValue().elements,i=e.offset;if(s[i+0]!==r[0]||s[i+1]!==r[1]||s[i+2]!==r[2]||s[i+4]!==r[3]||s[i+5]!==r[4]||s[i+6]!==r[5]||s[i+8]!==r[6]||s[i+9]!==r[7]||s[i+10]!==r[8]){const e=this.buffer;e[i+0]=s[i+0]=r[0],e[i+1]=s[i+1]=r[1],e[i+2]=s[i+2]=r[2],e[i+4]=s[i+4]=r[3],e[i+5]=s[i+5]=r[4],e[i+6]=s[i+6]=r[5],e[i+8]=s[i+8]=r[6],e[i+9]=s[i+9]=r[7],e[i+10]=s[i+10]=r[8],t=!0}return t}updateMatrix4(e){let t=!1;const s=this.values,r=e.getValue().elements,i=e.offset;if(!1===function(e,t,s){for(let r=0,i=t.length;r<i;r++)if(e[s+r]!==t[r])return!1;return!0}(s,r,i)){this.buffer.set(r,i),function(e,t,s){for(let r=0,i=t.length;r<i;r++)e[s+r]=t[r]}(s,r,i),t=!0}return t}}let xv=0;class Tv extends bv{constructor(e,t){super(e),this.id=xv++,this.groupNode=t,this.isNodeUniformsGroup=!0}getNodes(){const e=[];for(const t of this.uniforms){const s=t.nodeUniform.node;if(!s)throw new Error("NodeUniformsGroup: Uniform has no node.");e.push(s)}return e}}let _v=0;class Nv extends pv{constructor(e,t){super(e),this.id=_v++,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)}}class vv extends Nv{constructor(e,t,s,r=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s,this.access=r}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 Sv extends vv{constructor(e,t,s,r){super(e,t,s,r),this.isSampledCubeTexture=!0}}class Av extends vv{constructor(e,t,s,r){super(e,t,s,r),this.isSampledTexture3D=!0}}const Rv={atan2:"atan",textureDimensions:"textureSize",equals:"equal"},Cv={low:"lowp",medium:"mediump",high:"highp"},Ev={swizzleAssign:!0,storageBuffer:!1},wv="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp sampler3D;\nprecision highp samplerCube;\nprecision highp sampler2DArray;\n\nprecision highp usampler2D;\nprecision highp usampler3D;\nprecision highp usamplerCube;\nprecision highp usampler2DArray;\n\nprecision highp isampler2D;\nprecision highp isampler3D;\nprecision highp isamplerCube;\nprecision highp isampler2DArray;\n\nprecision lowp sampler2DShadow;\n";class Mv extends BN{constructor(e,t){super(e,t,new YN),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]},this.useComparisonMethod=!0}needsColorSpaceToLinearSRGB(e){return!0===e.isVideoTexture&&e.colorSpace!==m}getMethod(e){return Rv[e]||e}getOutputStructName(){return""}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(this.getType(e.type)+" "+e.name);return`${this.getType(t.type)} ${t.name}( ${r.join(", ")} ) {\n\n\t${s.vars}\n\n${s.code}\n\treturn ${s.result};\n\n}`}setupPBO(e){const t=e.value;if(void 0===t.pbo){const e=t.array,s=t.count*t.itemSize,{itemSize:r}=t,i=t.array.constructor.name.toLowerCase().includes("int");let n=i?ze:$e;2===r?n=i?He:Ce:3===r?n=i?We:je:4===r&&(n=i?qe:Ue);const o={Float32Array:E,Uint8Array:pe,Uint16Array:Ke,Uint32Array:f,Int8Array:Xe,Int16Array:Ye,Int32Array:y,Uint8ClampedArray:pe},a=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(s/r))));let u=Math.ceil(s/r/a);a*u*r<s&&u++;const l=a*u*r,d=new e.constructor(l);d.set(e,0),t.array=d;const c=new ke(t.array,a,u,n,o[t.array.constructor.name]||E);c.needsUpdate=!0,c.isPBOTexture=!0;const h=new Tu(c,null,null);h.setPrecision("high"),t.pboNode=h,t.pbo=h.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.label)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&!0!==e.node.isTextureNode&&!0!==e.node.isBufferNode?t.charAt(0)+"_"+e.name:super.getPropertyName(e,t)}generatePBO(e){const{node:t,indexNode:s}=e,r=t.value;if(this.renderer.backend.has(r)){this.renderer.backend.get(r).pbo=r.pbo}const i=this.getUniformFromNode(r.pboNode,"texture",this.shaderStage,this.context.label),n=this.getPropertyName(i);this.increaseUsage(s);const o=s.build(this,"uint"),a=this.getDataFromNode(e);let u=a.propertyName;if(void 0===u){const s=this.getVarFromNode(e);u=this.getPropertyName(s);const i=this.getDataFromNode(t);let l=i.propertySizeName;void 0===l&&(l=u+"Size",this.getVarFromNode(t,l,"uint"),this.addLineFlowCode(`${l} = uint( textureSize( ${n}, 0 ).x )`,e),i.propertySizeName=l);const{itemSize:d}=r,c="."+vr.join("").slice(0,d),h=`ivec2(${o} % ${l}, ${o} / ${l})`,p=this.generateTextureLoad(null,n,h,null,"0");let g="vec4";r.pbo.type===f?g="uvec4":r.pbo.type===y&&(g="ivec4"),this.addLineFlowCode(`${u} = ${g}(${p})${c}`,e),a.propertyName=u}return u}generateTextureLoad(e,t,s,r,i="0"){return r?`texelFetch( ${t}, ivec3( ${s}, ${r} ), ${i} )`:`texelFetch( ${t}, ${s}, ${i} )`}generateTexture(e,t,s,r){return e.isDepthTexture?`texture( ${t}, ${s} ).x`:(r&&(s=`vec3( ${s}, ${r} )`),`texture( ${t}, ${s} )`)}generateTextureLevel(e,t,s,r){return`textureLod( ${t}, ${s}, ${r} )`}generateTextureBias(e,t,s,r){return`texture( ${t}, ${s}, ${r} )`}generateTextureGrad(e,t,s,r){return`textureGrad( ${t}, ${s}, ${r[0]}, ${r[1]} )`}generateTextureCompare(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`texture( ${t}, vec3( ${s}, ${r} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`${this.getVar(e.type,e.name)};`);return t.join("\n\t")}getUniforms(e){const t=this.uniforms[e],s=[],r={};for(const i of t){let t=null,n=!1;if("texture"===i.type){const e=i.node.value;let s="";!0===e.isDataTexture&&(e.type===f?s="u":e.type===y&&(s="i")),t=e.compareFunction?`sampler2DShadow ${i.name};`:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?`${s}sampler2DArray ${i.name};`:`${s}sampler2D ${i.name};`}else if("cubeTexture"===i.type)t=`samplerCube ${i.name};`;else if("texture3D"===i.type)t=`sampler3D ${i.name};`;else if("buffer"===i.type){const e=i.node,s=this.getType(e.bufferType),r=e.bufferCount,n=r>0?r:"";t=`${e.name} {\n\t${s} ${i.name}[${n}];\n};\n`}else{t=`${this.getVectorType(i.type)} ${this.getPropertyName(i,e)};`,n=!0}const o=i.node.precision;if(null!==o&&(t=Cv[o]+" "+t),n){t="\t"+t;const e=i.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let i="";for(const t in r){const s=r[t];i+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return i+=s.join("\n"),i}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e<s.length;e++){const r=s[e];t.push(`layout( location = ${e} ) out ${r} m${e};`)}return t.join("\n")}getStructs(e){const t=[],s=this.structs[e];if(0===s.length)return"layout( location = 0 ) out vec4 fragColor;\n";for(let e=0,r=s.length;e<r;e++){const r=s[e];let i="\n";i+=this.getStructMembers(r),i+="\n",t.push(i)}return t.join("\n\n")}getVaryings(e){let t="";const s=this.varyings;if("vertex"===e||"compute"===e)for(const r of s){"compute"===e&&(r.needsInterpolation=!0);const s=r.type;t+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}${r.needsInterpolation?"out":"/*out*/"} ${s} ${r.name};\n`}else if("fragment"===e)for(const e of s)if(e.needsInterpolation){const s=e.type;t+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}in ${s} ${e.name};\n`}for(const s of this.builtins[e])t+=`${s};\n`;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce(((e,t)=>e*t),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 r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Ev[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Ev[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 r=e[s],i=this.getPropertyName(r.attributeNode);t+=`${r.varyingName} = ${i};\n\t`}return t}_getGLSLUniformStruct(e,t){return`\nlayout( std140 ) uniform ${e} {\n${t}\n};`}_getGLSLVertexCode(e){return`#version 300 es\n\n${this.getSignature()}\n\n// extensions \n${e.extensions}\n\n// precision\n${wv}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\n\n// attributes\n${e.attributes}\n\n// codes\n${e.codes}\n\nvoid main() {\n\n\t// vars\n\t${e.vars}\n\n\t// transforms\n\t${e.transforms}\n\n\t// flow\n\t${e.flow}\n\n\tgl_PointSize = 1.0;\n\n}\n`}_getGLSLFragmentCode(e){return`#version 300 es\n\n${this.getSignature()}\n\n// precision\n${wv}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\n\n// codes\n${e.codes}\n\n${e.structs}\n\nvoid main() {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){let s="// code\n\n";s+=this.flowCode[t];const r=this.flowNodes[t],i=r[r.length-1];for(const e of r){const r=this.getFlowData(e),n=e.name;n&&(s.length>0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${r.code}\n\t`,e===i&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const i=super.getUniformFromNode(e,t,s,r),n=this.getDataFromNode(e,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new vv(i.name,i.node,r),u.push(o);else if("cubeTexture"===t)o=new Sv(i.name,i.node,r),u.push(o);else if("texture3D"===t)o=new Av(i.name,i.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,i.name=`buffer${e.id}`;const t=new yv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new Tv(s+"_"+a,r),e[a]=n,u.push(n)),o=this.getNodeUniform(i,t),n.addUniform(o)}n.uniformGPU=o}return i}}let Bv=null,Uv=null,Fv=null;class Pv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Bv=Bv||new t,this.renderer.getDrawingBufferSize(Bv)}getScissor(){return Uv=Uv||new r,this.renderer.getScissor(Uv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Fv=Fv||new cm,e.getClearColor(Fv),Fv.getRGB(Fv,this.renderer.currentColorSpace),Fv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Iv=0;class Lv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Dv{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,i=e.array,n=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,i,n),a.bufferGPU=l,a.bufferType=t,a.version=o.version),i instanceof Float32Array)u=r.FLOAT;else if(i instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(i instanceof Int16Array)u=r.SHORT;else if(i instanceof Uint32Array)u=r.UNSIGNED_INT;else if(i instanceof Int32Array)u=r.INT;else if(i instanceof Int8Array)u=r.BYTE;else if(i instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(i instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+i);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:i.byteLength,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Iv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,i,n);d=new Lv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,i=e.isInterleavedBufferAttribute?e.data:e,n=t.get(i),o=n.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e<t;e++){const t=a[e];s.bufferSubData(o,t.start*r.BYTES_PER_ELEMENT,r,t.start,t.count)}i.clearUpdateRanges()}s.bindBuffer(o,null),n.version=i.version}destroyAttribute(e){const t=this.backend,{gl:s}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);const r=t.get(e);s.deleteBuffer(r.bufferGPU),t.delete(e)}async getArrayBufferAsync(e){const t=this.backend,{gl:s}=t,r=e.isInterleavedBufferAttribute?e.data:e,{bufferGPU:i}=t.get(r),n=e.array,o=n.byteLength;s.bindBuffer(s.COPY_READ_BUFFER,i);const a=s.createBuffer();s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.bufferData(s.COPY_WRITE_BUFFER,o,s.STREAM_READ),s.copyBufferSubData(s.COPY_READ_BUFFER,s.COPY_WRITE_BUFFER,0,0,o),await t.utils._clientWaitAsync();const u=new e.array.constructor(n.length);return s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.getBufferSubData(s.COPY_WRITE_BUFFER,0,u),s.deleteBuffer(a),s.bindBuffer(s.COPY_READ_BUFFER,null),s.bindBuffer(s.COPY_WRITE_BUFFER,null),u.buffer}_createBuffer(e,t,s,r){const i=e.createBuffer();return e.bindBuffer(t,i),e.bufferData(t,s,r),e.bindBuffer(t,null),i}}let Vv,Ov,Gv=!1;class kv{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={},!1===Gv&&(this._init(this.gl),Gv=!0)}_init(e){Vv={[Ze]:e.FUNC_ADD,[Je]:e.FUNC_SUBTRACT,[et]:e.FUNC_REVERSE_SUBTRACT},Ov={[tt]:e.ZERO,[st]:e.ONE,[rt]:e.SRC_COLOR,[it]:e.SRC_ALPHA,[nt]:e.SRC_ALPHA_SATURATE,[ot]:e.DST_COLOR,[at]:e.DST_ALPHA,[ut]:e.ONE_MINUS_SRC_COLOR,[lt]:e.ONE_MINUS_SRC_ALPHA,[dt]:e.ONE_MINUS_DST_COLOR,[ct]:e.ONE_MINUS_DST_ALPHA}}enable(e){const{enabled:t}=this;!0!==t[e]&&(this.gl.enable(e),t[e]=!0)}disable(e){const{enabled:t}=this;!1!==t[e]&&(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!==ht?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===pt?t.cullFace(t.BACK):e===gt?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,r,i,n,o,a){const{gl:u}=this;if(e!==G){if(!1===this.currentBlendingEnabled&&(this.enable(u.BLEND),this.currentBlendingEnabled=!0),e===mt)i=i||t,n=n||s,o=o||r,t===this.currentBlendEquation&&i===this.currentBlendEquationAlpha||(u.blendEquationSeparate(Vv[t],Vv[i]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=i),s===this.currentBlendSrc&&r===this.currentBlendDst&&n===this.currentBlendSrcAlpha&&o===this.currentBlendDstAlpha||(u.blendFuncSeparate(Ov[s],Ov[r],Ov[n],Ov[o]),this.currentBlendSrc=s,this.currentBlendDst=r,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=o),this.currentBlending=e,this.currentPremultipledAlpha=!1;else if(e!==this.currentBlending||a!==this.currentPremultipledAlpha){if(this.currentBlendEquation===Ze&&this.currentBlendEquationAlpha===Ze||(u.blendEquation(u.FUNC_ADD),this.currentBlendEquation=Ze,this.currentBlendEquationAlpha=Ze),a)switch(e){case F:u.blendFuncSeparate(u.ONE,u.ONE_MINUS_SRC_ALPHA,u.ONE,u.ONE_MINUS_SRC_ALPHA);break;case bt:u.blendFunc(u.ONE,u.ONE);break;case yt:u.blendFuncSeparate(u.ZERO,u.ONE_MINUS_SRC_COLOR,u.ZERO,u.ONE);break;case ft:u.blendFuncSeparate(u.ZERO,u.SRC_COLOR,u.ZERO,u.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}else switch(e){case F:u.blendFuncSeparate(u.SRC_ALPHA,u.ONE_MINUS_SRC_ALPHA,u.ONE,u.ONE_MINUS_SRC_ALPHA);break;case bt:u.blendFunc(u.SRC_ALPHA,u.ONE);break;case yt:u.blendFuncSeparate(u.ZERO,u.ONE_MINUS_SRC_COLOR,u.ZERO,u.ONE);break;case ft:u.blendFunc(u.ZERO,u.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=a}}else!0===this.currentBlendingEnabled&&(this.disable(u.BLEND),this.currentBlendingEnabled=!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 Rt:t.depthFunc(t.NEVER);break;case At:t.depthFunc(t.ALWAYS);break;case St:t.depthFunc(t.LESS);break;case vt:t.depthFunc(t.LEQUAL);break;case Nt:t.depthFunc(t.EQUAL);break;case _t:t.depthFunc(t.GEQUAL);break;case Tt:t.depthFunc(t.GREATER);break;case xt: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:r}=this;e.side===le?this.disable(r.CULL_FACE):this.enable(r.CULL_FACE);let i=e.side===x;t&&(i=!i),this.setFlipSided(i),e.blending===F&&!1===e.transparent?this.setBlending(G):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 n=e.stencilWrite;if(this.setStencilTest(n),n&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage&&this.backend.renderer.samples>1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t<s?this.enable(e+t):this.disable(e+t)}}setPolygonOffset(e,t,s){const{gl:r}=this;e?(this.enable(r.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===t&&this.currentPolygonOffsetUnits===s||(r.polygonOffset(t,s),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=s)):this.disable(r.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e&&(this.gl.useProgram(e),this.currentProgram=e,!0)}bindFramebuffer(e,t){const{gl:s,currentBoundFramebuffers:r}=this;return r[e]!==t&&(s.bindFramebuffer(e,t),r[e]=t,e===s.DRAW_FRAMEBUFFER&&(r[s.FRAMEBUFFER]=t),e===s.FRAMEBUFFER&&(r[s.DRAW_FRAMEBUFFER]=t),!0)}drawBuffers(e,t){const{gl:s}=this;let r=[],i=!1;if(null!==e.textures){r=this.currentDrawbuffers.get(t),void 0===r&&(r=[],this.currentDrawbuffers.set(t,r));const n=e.textures;if(r.length!==n.length||r[0]!==s.COLOR_ATTACHMENT0){for(let e=0,t=n.length;e<t;e++)r[e]=s.COLOR_ATTACHMENT0+e;r.length=n.length,i=!0}}else r[0]!==s.BACK&&(r[0]=s.BACK,i=!0);i&&s.drawBuffers(r)}activeTexture(e){const{gl:t,currentTextureSlot:s,maxTextures:r}=this;void 0===e&&(e=t.TEXTURE0+r-1),s!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,s){const{gl:r,currentTextureSlot:i,currentBoundTextures:n,maxTextures:o}=this;void 0===s&&(s=null===i?r.TEXTURE0+o-1:i);let a=n[s];void 0===a&&(a={type:void 0,texture:void 0},n[s]=a),a.type===e&&a.texture===t||(i!==s&&(r.activeTexture(s),this.currentTextureSlot=s),r.bindTexture(e,t),a.type=e,a.texture=t)}bindBufferBase(e,t,s){const{gl:r}=this,i=`${e}-${t}`;return this.currentBoundBufferBases[i]!==s&&(r.bindBufferBase(e,t,s),this.currentBoundBufferBases[i]=s,!0)}unbindTexture(){const{gl:e,currentTextureSlot:t,currentBoundTextures:s}=this,r=s[t];void 0!==r&&void 0!==r.type&&(e.bindTexture(r.type,null),r.type=void 0,r.texture=void 0)}}class zv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=m){const{gl:s,extensions:r}=this;let i;if(e===pe)return s.UNSIGNED_BYTE;if(e===Ct)return s.UNSIGNED_SHORT_4_4_4_4;if(e===Et)return s.UNSIGNED_SHORT_5_5_5_1;if(e===wt)return s.UNSIGNED_INT_5_9_9_9_REV;if(e===Xe)return s.BYTE;if(e===Ye)return s.SHORT;if(e===Ke)return s.UNSIGNED_SHORT;if(e===y)return s.INT;if(e===f)return s.UNSIGNED_INT;if(e===E)return s.FLOAT;if(e===ye)return s.HALF_FLOAT;if(e===Mt)return s.ALPHA;if(e===je)return s.RGB;if(e===Ue)return s.RGBA;if(e===Bt)return s.LUMINANCE;if(e===Ut)return s.LUMINANCE_ALPHA;if(e===ce)return s.DEPTH_COMPONENT;if(e===de)return s.DEPTH_STENCIL;if(e===$e)return s.RED;if(e===ze)return s.RED_INTEGER;if(e===Ce)return s.RG;if(e===He)return s.RG_INTEGER;if(e===qe)return s.RGBA_INTEGER;if(e===Ft||e===Pt||e===It||e===Lt)if(t===De){if(i=r.get("WEBGL_compressed_texture_s3tc_srgb"),null===i)return null;if(e===Ft)return i.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===Pt)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===It)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===Lt)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(i=r.get("WEBGL_compressed_texture_s3tc"),null===i)return null;if(e===Ft)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===Pt)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===It)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Lt)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e===Dt||e===Vt||e===Ot||e===Gt){if(i=r.get("WEBGL_compressed_texture_pvrtc"),null===i)return null;if(e===Dt)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===Vt)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===Ot)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===Gt)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e===kt||e===zt||e===$t){if(i=r.get("WEBGL_compressed_texture_etc"),null===i)return null;if(e===kt||e===zt)return t===De?i.COMPRESSED_SRGB8_ETC2:i.COMPRESSED_RGB8_ETC2;if(e===$t)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:i.COMPRESSED_RGBA8_ETC2_EAC}if(e===Ht||e===Wt||e===jt||e===qt||e===Kt||e===Xt||e===Yt||e===Qt||e===Zt||e===Jt||e===es||e===ts||e===ss||e===rs){if(i=r.get("WEBGL_compressed_texture_astc"),null===i)return null;if(e===Ht)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:i.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===Wt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:i.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===jt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:i.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===qt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:i.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===Kt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:i.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===Xt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:i.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===Yt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:i.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===Qt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:i.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===Zt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:i.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===Jt)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:i.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===es)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:i.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===ts)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:i.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===ss)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:i.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===rs)return t===De?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:i.COMPRESSED_RGBA_ASTC_12x12_KHR}if(e===is){if(i=r.get("EXT_texture_compression_bptc"),null===i)return null;if(e===is)return t===De?i.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:i.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(e===ns||e===os||e===as||e===us){if(i=r.get("EXT_texture_compression_rgtc"),null===i)return null;if(e===is)return i.COMPRESSED_RED_RGTC1_EXT;if(e===os)return i.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===as)return i.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===us)return i.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return e===he?s.UNSIGNED_INT_24_8:void 0!==s[e]?s[e]:null}_clientWaitAsync(){const{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise(((s,r)=>{!function i(){const n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED)return e.deleteSync(t),void r();n!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(i)}()}))}}let $v,Hv,Wv,jv=!1;class qv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===jv&&(this._init(this.gl),jv=!0)}_init(e){$v={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},Hv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},Wv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,i=!1){const{gl:n,extensions:o}=this;if(null!==e){if(void 0!==n[e])return n[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),t===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),t===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),t===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),t===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=r===De&&!1===i?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),t===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),t===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=r===De&&!1===i?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),t===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:i}=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,$v[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,$v[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,$v[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,Hv[t.magFilter]);const n=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&n?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,Hv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,Wv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const n=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,i.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,i=this.getGLTextureType(e);let n=r[i];void 0===n&&(n=t.createTexture(),s.state.bindTexture(i,n),t.texParameteri(i,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(i,t.TEXTURE_MAG_FILTER,t.NEAREST),r[i]=n),s.set(e,{textureGPU:n,glTextureType:i,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:i,width:n,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,i,d,n,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,i,d,n,o,a):e.isVideoTexture||s.texStorage2D(h,i,d,n,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:i,glTextureType:n,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(n,i),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:i}=t,{textureGPU:n,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===n)return;const d=e=>e.isDataTexture?e.image.data:e instanceof ImageBitmap||e instanceof OffscreenCanvas||e instanceof HTMLImageElement||e instanceof HTMLCanvasElement?e:e.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,i=t.image;for(let t=0;t<r.length;t++){const n=r[t];e.isCompressedArrayTexture?e.format!==s.RGBA?null!==a?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,i.depth,a,n.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,i.depth,a,u,n.data):null!==a?s.compressedTexSubImage2D(s.TEXTURE_2D,t,0,0,n.width,n.height,a,n.data):console.warn("Unsupported compressed texture format")}}else if(e.isCubeTexture){const e=t.images;for(let t=0;t<6;t++){const n=d(e[t]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,r,i,a,u,n)}}else if(e.isDataArrayTexture){const e=t.image;s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,e.width,e.height,e.depth,a,u,e.data)}else if(e.isData3DTexture){const e=t.image;s.texSubImage3D(s.TEXTURE_3D,0,0,0,0,e.width,e.height,e.depth,a,u,e.data)}else if(e.isVideoTexture)e.update(),s.texImage2D(o,0,l,a,u,t.image);else{const e=d(t.image);s.texSubImage2D(o,0,0,0,r,i,a,u,e)}}generateMipmaps(e){const{gl:t,backend:s}=this,{textureGPU:r,glTextureType:i}=s.get(e);s.state.bindTexture(i,r),t.generateMipmap(i)}deallocateRenderBuffers(e){const{gl:t,backend:s}=this;if(e){const r=s.get(e);if(r.renderBufferStorageSetup=void 0,r.framebuffers){for(const e in r.framebuffers)t.deleteFramebuffer(r.framebuffers[e]);delete r.framebuffers}if(r.depthRenderbuffer&&(t.deleteRenderbuffer(r.depthRenderbuffer),delete r.depthRenderbuffer),r.stencilRenderbuffer&&(t.deleteRenderbuffer(r.stencilRenderbuffer),delete r.stencilRenderbuffer),r.msaaFrameBuffer&&(t.deleteFramebuffer(r.msaaFrameBuffer),delete r.msaaFrameBuffer),r.msaaRenderbuffers){for(let e=0;e<r.msaaRenderbuffers.length;e++)t.deleteRenderbuffer(r.msaaRenderbuffers[e]);delete r.msaaRenderbuffers}}}destroyTexture(e){const{gl:t,backend:s}=this,{textureGPU:r,renderTarget:i}=s.get(e);this.deallocateRenderBuffers(i),t.deleteTexture(r),s.delete(e)}copyTextureToTexture(e,t,s=null,r=null,i=0){const{gl:n,backend:o}=this,{state:a}=this.backend,{textureGPU:u,glTextureType:l,glType:d,glFormat:c}=o.get(t);let h,p,g,m,f,y;null!==s?(h=s.max.x-s.min.x,p=s.max.y-s.min.y,g=s.min.x,m=s.min.y):(h=e.image.width,p=e.image.height,g=0,m=0),null!==r?(f=r.x,y=r.y):(f=0,y=0),a.bindTexture(l,u),n.pixelStorei(n.UNPACK_ALIGNMENT,t.unpackAlignment),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,t.flipY),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),n.pixelStorei(n.UNPACK_ALIGNMENT,t.unpackAlignment);const b=n.getParameter(n.UNPACK_ROW_LENGTH),x=n.getParameter(n.UNPACK_IMAGE_HEIGHT),T=n.getParameter(n.UNPACK_SKIP_PIXELS),_=n.getParameter(n.UNPACK_SKIP_ROWS),N=n.getParameter(n.UNPACK_SKIP_IMAGES),v=e.isCompressedTexture?e.mipmaps[i]:e.image;if(n.pixelStorei(n.UNPACK_ROW_LENGTH,v.width),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,v.height),n.pixelStorei(n.UNPACK_SKIP_PIXELS,g),n.pixelStorei(n.UNPACK_SKIP_ROWS,m),e.isRenderTargetTexture||e.isDepthTexture){const s=o.get(e),r=o.get(t),i=o.get(s.renderTarget),u=o.get(r.renderTarget),l=i.framebuffers[s.cacheKey],d=u.framebuffers[r.cacheKey];a.bindFramebuffer(n.READ_FRAMEBUFFER,l),a.bindFramebuffer(n.DRAW_FRAMEBUFFER,d);let c=n.COLOR_BUFFER_BIT;e.isDepthTexture&&(c=n.DEPTH_BUFFER_BIT),n.blitFramebuffer(g,m,h,p,f,y,h,p,c,n.NEAREST),a.bindFramebuffer(n.READ_FRAMEBUFFER,null),a.bindFramebuffer(n.DRAW_FRAMEBUFFER,null)}else e.isDataTexture?n.texSubImage2D(n.TEXTURE_2D,i,f,y,h,p,c,d,v.data):e.isCompressedTexture?n.compressedTexSubImage2D(n.TEXTURE_2D,i,f,y,v.width,v.height,c,v.data):n.texSubImage2D(n.TEXTURE_2D,i,f,y,h,p,c,d,v);n.pixelStorei(n.UNPACK_ROW_LENGTH,b),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,x),n.pixelStorei(n.UNPACK_SKIP_PIXELS,T),n.pixelStorei(n.UNPACK_SKIP_ROWS,_),n.pixelStorei(n.UNPACK_SKIP_IMAGES,N),0===i&&t.generateMipmaps&&n.generateMipmap(n.TEXTURE_2D),a.unbindTexture()}copyFramebufferToTexture(e,t,s){const{gl:r}=this,{state:i}=this.backend,{textureGPU:n}=this.backend.get(e),{x:o,y:a,z:u,w:l}=s,d=!0===e.isDepthTexture||t.renderTarget&&t.renderTarget.samples>0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;i.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),i.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),i.bindFramebuffer(r.READ_FRAMEBUFFER,s),i.bindTexture(r.TEXTURE_2D,n),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),i.unbindTexture()}else{const e=r.createFramebuffer();i.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,n,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else i.bindTexture(r.TEXTURE_2D,n),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),i.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:i,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;i>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,i,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(i>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,i,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,i,n){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*i*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,i,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(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 r=0;return e===s.UNSIGNED_BYTE&&(r=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||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Kv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Xv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){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 Yv={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 Qv{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:r,object:i,type:n,info:o,index:a}=this;0!==a?s.drawElements(r,t,n,e):s.drawArrays(r,e,t),o.update(i,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:i,type:n,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(i,t,n,e,s):r.drawArraysInstanced(i,e,t,s),u.update(a,t,i,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:i,object:n,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r<s;r++)this.render(e[r],t[r]);else{0!==this.index?a.multiDrawElementsWEBGL(i,t,0,this.type,e,0,s):a.multiDrawArraysWEBGL(i,e,0,t,0,s);let r=0;for(let e=0;e<s;e++)r+=t[e];o.update(n,r,i,1)}}renderMultiDrawInstances(e,t,s,r){const{extensions:i,mode:n,object:o,info:a}=this;if(0===s)return;const u=i.get("WEBGL_multi_draw");if(null===u)for(let i=0;i<s;i++)this.renderInstances(e[i],t[i],r[i]);else{0!==this.index?u.multiDrawElementsInstancedWEBGL(n,t,0,this.type,e,0,r,0,s):u.multiDrawArraysInstancedWEBGL(n,e,0,t,0,r,0,s);let i=0;for(let e=0;e<s;e++)i+=t[e]*r[e];a.update(o,i,n,1)}}}class Zv extends Pv{constructor(e={}){super(e),this.isWebGLBackend=!0}init(e){super.init(e);const t=this.parameters,s=void 0!==t.context?t.context:e.domElement.getContext("webgl2");function r(t){t.preventDefault();const s={api:"WebGL",message:t.statusMessage||"Unknown reason",reason:null,originalEvent:t};e.onDeviceLost(s)}this._onContextLost=r,e.domElement.addEventListener("webglcontextlost",r,!1),this.gl=s,this.extensions=new Kv(this),this.capabilities=new Xv(this),this.attributeUtils=new Dv(this),this.textureUtils=new qv(this),this.bufferRenderer=new Qv(this),this.state=new kv(this),this.utils=new zv(this),this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.trackTimestamp=!0===t.trackTimestamp,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"),this._knownBindings=new WeakSet,this._currentContext=null}get coordinateSystem(){return b}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)return t.queryQueue||(t.queryQueue=[]),void t.queryQueue.push(e);t.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),t.activeQuery=null),t.activeQuery=this.gl.createQuery(),null!==t.activeQuery&&(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 e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e<s.gpuQueries.length;e++){const r=s.gpuQueries[e],i=this.gl.getQueryParameter(r.query,this.gl.QUERY_RESULT_AVAILABLE),n=this.gl.getParameter(this.disjoint.GPU_DISJOINT_EXT);if(i&&!n){const i=this.gl.getQueryParameter(r.query,this.gl.QUERY_RESULT),n=Number(i)/1e6;this.gl.deleteQuery(r.query),s.gpuQueries.splice(e,1),e--,this.renderer.info.updateTimestamp(t,n)}}}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:s,y:r,width:i,height:n}=e.scissorValue;t.scissor(s,e.height-n-r,i,n)}const r=e.occlusionQueryCount;r>0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),i=r.previousContext,n=e.occlusionQueryCount;n>0&&(n>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e<o.length;e++){const t=o[e];t.generateMipmaps&&this.generateMipmaps(t)}if(this._currentContext=i,null!==e.textures&&e.renderTarget){const r=this.get(e.renderTarget),{samples:i}=e.renderTarget;if(i>0){const i=r.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,i);for(let s=0;s<a.length;s++)if(e.scissor){const{x:s,y:i,width:o,height:a}=e.scissorValue,u=e.height-a-i;t.blitFramebuffer(s,u,s+o,u+a,s,u,s+o,u+a,n,t.NEAREST),t.invalidateSubFramebuffer(t.READ_FRAMEBUFFER,r.invalidationArray,s,u,o,a)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,n,t.NEAREST),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,r.invalidationArray)}}null!==i&&(this._setFramebuffer(i),i.viewport?this.updateViewport(i):t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)),this.prepareTimestampBuffer(e)}resolveOccludedAsync(e){const t=this.get(e),{currentOcclusionQueries:s,currentOcclusionQueryObjects:r}=t;if(s&&r){const e=new WeakSet,{gl:i}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;const n=()=>{let o=0;for(let t=0;t<s.length;t++){const n=s[t];null!==n&&(i.getQueryParameter(n,i.QUERY_RESULT_AVAILABLE)&&(i.getQueryParameter(n,i.QUERY_RESULT)>0&&e.add(r[t]),s[t]=null,i.deleteQuery(n),o++))}o<s.length?requestAnimationFrame(n):t.occluded=e};n()}}isOccluded(e,t){const s=this.get(e);return s.occluded&&s.occluded.has(t)}updateViewport(e){const t=this.gl,{x:s,y:r,width:i,height:n}=e.viewportValue;t.viewport(s,e.height-n-r,i,n)}setScissorTest(e){const t=this.gl;e?t.enable(t.SCISSOR_TEST):t.disable(t.SCISSOR_TEST)}clear(e,t,s,r=null,i=!0){const{gl:n}=this;if(null===r){const e=this.getClearColor();e.r*=e.a,e.g*=e.a,e.b*=e.a,r={textures:null,clearColorValue:e}}let o=0;if(e&&(o|=n.COLOR_BUFFER_BIT),t&&(o|=n.DEPTH_BUFFER_BIT),s&&(o|=n.STENCIL_BUFFER_BIT),0!==o){let a;if(r.clearColorValue?a=r.clearColorValue:(a=this.getClearColor(),a.r*=a.a,a.g*=a.a,a.b*=a.a),t&&this.state.setDepthMask(!0),null===r.textures)n.clearColor(a.r,a.g,a.b,a.a),n.clear(o);else{if(i&&this._setFramebuffer(r),e)for(let e=0;e<r.textures.length;e++)n.clearBufferfv(n.COLOR,e,[a.r,a.g,a.b,a.a]);t&&s?n.clearBufferfi(n.DEPTH_STENCIL,0,1,0):t?n.clearBufferfv(n.DEPTH,0,[1]):s&&n.clearBufferiv(n.STENCIL,0,[0])}}}beginCompute(e){const{state:t,gl:s}=this;t.bindFramebuffer(s.FRAMEBUFFER,null),this.initTimestampQuery(e)}compute(e,t,s,r){const{state:i,gl:n}=this;this.discard||(n.enable(n.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:o,transformBuffers:a,attributes:u}=this.get(r),l=this._getVaoKey(null,u),d=this.vaoCache[l];void 0===d?this._createVao(null,u):n.bindVertexArray(d),i.useProgram(o),this._bindUniforms(s);const c=this._getTransformFeedback(a);n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,c),n.beginTransformFeedback(n.POINTS),u[0].isStorageInstancedBufferAttribute?n.drawArraysInstanced(n.POINTS,0,1,t.count):n.drawArrays(n.POINTS,0,t.count),n.endTransformFeedback(),n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,null);for(let e=0;e<a.length;e++){const t=a[e];t.pbo&&this.textureUtils.copyBufferToTexture(t.transformBuffer,t.pbo),t.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:r,context:i,hardwareClippingPlanes:n}=e,{programGPU:o}=this.get(s),{gl:a,state:u}=this,l=this.get(i),d=e.getDrawParameters();if(null===d)return;this._bindUniforms(e.getBindings());const c=t.isMesh&&t.matrixWorld.determinant()<0;u.setMaterial(r,c,n),u.useProgram(o);let h=e.staticVao;if(void 0===h){const t=this._getVaoKey(e.getIndex(),e.getAttributes());if(h=this.vaoCache[t],void 0===h){let t;({vaoGPU:h,staticVao:t}=this._createVao(e.getIndex(),e.getAttributes())),t&&(e.staticVao=h)}}a.bindVertexArray(h);const p=e.getIndex(),g=l.lastOcclusionObject;if(g!==t&&void 0!==g){if(null!==g&&!0===g.occlusionTest&&(a.endQuery(a.ANY_SAMPLES_PASSED),l.occlusionQueryIndex++),!0===t.occlusionTest){const e=a.createQuery();a.beginQuery(a.ANY_SAMPLES_PASSED,e),l.occlusionQueries[l.occlusionQueryIndex]=e,l.occlusionQueryObjects[l.occlusionQueryIndex]=t}l.lastOcclusionObject=t}const m=this.bufferRenderer;t.isPoints?m.mode=a.POINTS:t.isLineSegments?m.mode=a.LINES:t.isLine?m.mode=a.LINE_STRIP:t.isLineLoop?m.mode=a.LINE_LOOP:!0===r.wireframe?(u.setLineWidth(r.wireframeLinewidth*this.renderer.getPixelRatio()),m.mode=a.LINES):m.mode=a.TRIANGLES;const{vertexCount:f,instanceCount:y}=d;let{firstVertex:b}=d;if(m.object=t,null!==p){b*=p.array.BYTES_PER_ELEMENT;const e=this.get(p);m.index=p.count,m.type=e.type}else m.index=0;t.isBatchedMesh?null!==t._multiDrawInstances?m.renderMultiDrawInstances(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount,t._multiDrawInstances):this.hasFeature("WEBGL_multi_draw")?m.renderMultiDraw(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount):_s("THREE.WebGLRenderer: WEBGL_multi_draw not supported."):y>1?m.renderInstances(b,f,y):m.render(b,f),a.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,r,i,n){return this.textureUtils.copyTextureToBuffer(e,t,s,r,i,n)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Mv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,i="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(i,r),t.compileShader(i),this.set(e,{shaderGPU:i})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:i,vertexProgram:n}=r,o=s.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const i=new Promise((t=>{const i=this.parallel,n=()=>{s.getProgramParameter(o,i.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(n)};n()}));t.push(i)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],i=Math.max(t-6,0),n=Math.min(t+6,s.length);for(let e=i;e<n;e++){const i=e+1;r.push(`${i===t?">":" "} ${i}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),i=e.getShaderInfoLog(t).trim();if(r&&""===i)return"";const n=/ERROR: 0:(\d+)/.exec(i);if(n){const r=parseInt(n[1]);return s.toUpperCase()+"\n\n"+i+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return i}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,i=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const n=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+i+"\n"+n+"\n"+o)}else""!==i&&console.warn("THREE.WebGLProgram: Program Info Log:",i)}}_completeCompile(e,t){const{state:s,gl:r}=this,i=this.get(t),{programGPU:n,fragmentShader:o,vertexShader:a}=i;!1===r.getProgramParameter(n,r.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n);const u=e.getBindings();this._setupBindings(u,n),this.set(t,{programGPU:n})}createComputePipeline(e,t){const{state:s,gl:r}=this,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:n}=e,o=r.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU,l=n.transforms,d=[],c=[];for(let e=0;e<l.length;e++){const t=l[e];d.push(t.varyingName),c.push(t.attributeNode)}r.attachShader(o,a),r.attachShader(o,u),r.transformFeedbackVaryings(o,d,r.SEPARATE_ATTRIBS),r.linkProgram(o),!1===r.getProgramParameter(o,r.LINK_STATUS)&&this._logProgramError(o,a,u),s.useProgram(o),this._setupBindings(t,o);const h=n.attributes,p=[],g=[];for(let e=0;e<h.length;e++){const t=h[e].node.attribute;p.push(t),this.has(t)||this.attributeUtils.createAttribute(t,r.ARRAY_BUFFER)}for(let e=0;e<c.length;e++){const t=c[e].attribute;this.has(t)||this.attributeUtils.createAttribute(t,r.ARRAY_BUFFER);const s=this.get(t);g.push(s)}this.set(e,{programGPU:o,transformBuffers:g,attributes:p})}createBindings(e,t){if(!1===this._knownBindings.has(t)){this._knownBindings.add(t);let e=0,s=0;for(const r of t){this.set(r,{textures:s,uniformBuffers:e});for(const t of r.bindings)t.isUniformBuffer&&e++,t.isSampledTexture&&s++}}this.updateBindings(e,t)}updateBindings(e){const{gl:t}=this,s=this.get(e);let r=s.uniformBuffers,i=s.textures;for(const s of e.bindings)if(s.isUniformsGroup||s.isUniformBuffer){const e=s.buffer,i=t.createBuffer();t.bindBuffer(t.UNIFORM_BUFFER,i),t.bufferData(t.UNIFORM_BUFFER,e,t.DYNAMIC_DRAW),this.set(s,{index:r++,bufferGPU:i})}else if(s.isSampledTexture){const{textureGPU:e,glTextureType:t}=this.get(s.texture);this.set(s,{index:i++,textureGPU:e,glTextureType:t})}}updateBinding(e){const t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){const s=this.get(e).bufferGPU,r=e.buffer;t.bindBuffer(t.UNIFORM_BUFFER,s),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)}updateSize(){}hasFeature(e){const t=Object.keys(Yv).filter((t=>Yv[t]===e)),s=this.extensions;for(let e=0;e<t.length;e++)if(s.has(t[e]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(e,t,s,r,i){this.textureUtils.copyTextureToTexture(e,t,s,r,i)}copyFramebufferToTexture(e,t,s){this.textureUtils.copyFramebufferToTexture(e,t,s)}_setFramebuffer(e){const{gl:t,state:s}=this;let r=null;if(null!==e.textures){const i=e.renderTarget,n=this.get(i),{samples:o,depthBuffer:a,stencilBuffer:u}=i,l=!0===i.isWebGLCubeRenderTarget;let d=n.msaaFrameBuffer,c=n.depthRenderbuffer;const h=am(e);let p;if(l?(n.cubeFramebuffers||(n.cubeFramebuffers={}),p=n.cubeFramebuffers[h]):(n.framebuffers||(n.framebuffers={}),p=n.framebuffers[h]),void 0===p){p=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,p);const r=e.textures;if(l){n.cubeFramebuffers[h]=p;const{textureGPU:e}=this.get(r[0]),s=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+s,e,0)}else{n.framebuffers[h]=p;for(let s=0;s<r.length;s++){const i=r[s],n=this.get(i);n.renderTarget=e.renderTarget,n.cacheKey=h;const o=t.COLOR_ATTACHMENT0+s;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,n.textureGPU,0)}s.drawBuffers(e,p)}if(null!==e.depthTexture){const s=this.get(e.depthTexture),r=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;s.renderTarget=e.renderTarget,s.cacheKey=h,t.framebufferTexture2D(t.FRAMEBUFFER,r,t.TEXTURE_2D,s.textureGPU,0)}}if(o>0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const i=[],l=e.textures;for(let s=0;s<l.length;s++){if(i[s]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,i[s]),r.push(t.COLOR_ATTACHMENT0+s),a){const e=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;r.push(e)}const n=e.textures[s],l=this.get(n);t.renderbufferStorageMultisample(t.RENDERBUFFER,o,l.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+s,t.RENDERBUFFER,i[s])}if(n.msaaFrameBuffer=d,n.msaaRenderbuffers=i,void 0===c){c=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(c,e),n.depthRenderbuffer=c;const s=u?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;r.push(s)}n.invalidationArray=r}r=n.msaaFrameBuffer}else r=p}s.bindFramebuffer(t.FRAMEBUFFER,r)}_getVaoKey(e,t){let s=[];if(null!==e){s+=":"+this.get(e).id}for(let e=0;e<t.length;e++){s+=":"+this.get(t[e]).id}return s}_createVao(e,t){const{gl:s}=this,r=s.createVertexArray();let i="",n=!0;if(s.bindVertexArray(r),null!==e){const t=this.get(e);s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t.bufferGPU),i+=":"+t.id}for(let e=0;e<t.length;e++){const r=t[e],o=this.get(r);let a,u;i+=":"+o.id,s.bindBuffer(s.ARRAY_BUFFER,o.bufferGPU),s.enableVertexAttribArray(e),(r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&(n=!1),!0===r.isInterleavedBufferAttribute?(a=r.data.stride*o.bytesPerElement,u=r.offset*o.bytesPerElement):(a=0,u=0),o.isInteger?s.vertexAttribIPointer(e,r.itemSize,o.type,a,u):s.vertexAttribPointer(e,r.itemSize,o.type,r.normalized,a,u),r.isInstancedBufferAttribute&&!r.isInterleavedBufferAttribute?s.vertexAttribDivisor(e,r.meshPerAttribute):r.isInterleavedBufferAttribute&&r.data.isInstancedInterleavedBuffer&&s.vertexAttribDivisor(e,r.data.meshPerAttribute)}return s.bindBuffer(s.ARRAY_BUFFER,null),this.vaoCache[i]=r,{vaoGPU:r,staticVao:n}}_getTransformFeedback(e){let t="";for(let s=0;s<e.length;s++)t+=":"+e[s].id;let s=this.transformFeedbackCache[t];if(void 0!==s)return s;const{gl:r}=this;s=r.createTransformFeedback(),r.bindTransformFeedback(r.TRANSFORM_FEEDBACK,s);for(let t=0;t<e.length;t++){const s=e[t];r.bindBufferBase(r.TRANSFORM_FEEDBACK_BUFFER,t,s.transformBuffer)}return r.bindTransformFeedback(r.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=s,s}_setupBindings(e,t){const s=this.gl;for(const r of e)for(const e of r.bindings){const r=this.get(e).index;if(e.isUniformsGroup||e.isUniformBuffer){const i=s.getUniformBlockIndex(t,e.name);s.uniformBlockBinding(t,i,r)}else if(e.isSampledTexture){const i=s.getUniformLocation(t,e.name);s.uniform1i(i,r)}}}_bindUniforms(e){const{gl:t,state:s}=this;for(const r of e)for(const e of r.bindings){const r=this.get(e),i=r.index;e.isUniformsGroup||e.isUniformBuffer?s.bindBufferBase(t.UNIFORM_BUFFER,i,r.bufferGPU):e.isSampledTexture&&s.bindTexture(r.glTextureType,r.textureGPU,t.TEXTURE0+i)}}dispose(){this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}class Jv extends pv{constructor(e,t){super(e),this.texture=t,this.version=t?t.version:0,this.isSampler=!0}}class eS extends Jv{constructor(e,t,s){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s}update(){this.texture=this.textureNode.value}}class tS extends gv{constructor(e,t){super(e,t?t.array:null),this.attribute=t,this.isStorageBuffer=!0}}let sS=0;class rS extends tS{constructor(e,t){super("StorageBuffer_"+sS++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:ky,this.groupNode=t}get buffer(){return this.nodeUniform.value}}class iS extends Lg{constructor(e){super(),this.device=e;this.mipmapSampler=e.createSampler({minFilter:cy}),this.flipYSampler=e.createSampler({minFilter:hy}),this.transferPipelines={},this.flipYPipelines={},this.mipmapVertexShaderModule=e.createShaderModule({label:"mipmapVertex",code:"\nstruct VarysStruct {\n\t@builtin( position ) Position: vec4<f32>,\n\t@location( 0 ) vTex : vec2<f32>\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( -1.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 ),\n\t\tvec2<f32>( -1.0, -1.0 ),\n\t\tvec2<f32>( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( 0.0, 0.0 ),\n\t\tvec2<f32>( 1.0, 0.0 ),\n\t\tvec2<f32>( 0.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4<f32>( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:$f,stripIndexFormat:oy},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:$f,stripIndexFormat:oy},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:i,height:n}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:i,height:n,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Zy,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:Zy,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),i=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:ey,storeOp:Zf,clearValue:[0,0,0,0]}]});n.setPipeline(e),n.setBindGroup(0,i),n.draw(4,1,0,0),n.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const i=r.layers[s]||this._mipmapCreateBundles(e,t,s),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,i),this.device.queue.submit([n.finish()]),0!==r.useCount&&(r.layers[s]=i),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),i=r.getBindGroupLayout(0);let n=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Zy,baseArrayLayer:s});const o=[];for(let a=1;a<t.mipLevelCount;a++){const u=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:n}]}),l=e.createView({baseMipLevel:a,mipLevelCount:1,dimension:Zy,baseArrayLayer:s}),d={colorAttachments:[{view:l,loadOp:ey,storeOp:Zf,clearValue:[0,0,0,0]}]},c=this.device.createRenderBundleEncoder({colorFormats:[t.format]});c.setPipeline(r),c.setBindGroup(0,u),c.draw(4,1,0,0),o.push({renderBundles:[c.finish()],passDescriptor:d}),n=l}return o}_mipmapRunBundles(e,t){const s=t.length;for(let r=0;r<s;r++){const s=t[r],i=e.beginRenderPass(s.passDescriptor);i.executeBundles(s.renderBundles),i.end()}}}const nS={[gs]:"never",[Ae]:"less",[ys]:"equal",[fs]:"less-equal",[xs]:"greater",[bs]:"greater-equal",[ms]:"always",[Ts]:"not-equal"},oS=[0,1,3,2,4,5];class aS{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new B,this.depthTexture.name="depthBuffer"}createSampler(e){const t=this.backend,s=t.device,r=t.get(e),i={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};i.magFilter===cy&&i.minFilter===cy&&i.mipmapFilter===cy&&(i.maxAnisotropy=e.anisotropy),e.isDepthTexture&&null!==e.compareFunction&&(i.compare=nS[e.compareFunction]),r.sampler=s.createSampler(i)}createDefaultTexture(e){let t;const s=uS(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,r=s.get(e);if(r.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");void 0===t.needsMipmaps&&(t.needsMipmaps=!1),void 0===t.levels&&(t.levels=1),void 0===t.depth&&(t.depth=1);const{width:i,height:n,depth:o,levels:a}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());const u=this._getDimension(e),l=e.internalFormat||t.format||uS(e,s.device);r.format=l;let d=void 0!==t.sampleCount?t.sampleCount:1;d=s.utils.getSampleCount(d);const c=e.isRenderTargetTexture&&!e.isMultisampleRenderTargetTexture?1:d;let h=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===e.isStorageTexture&&(h|=GPUTextureUsage.STORAGE_BINDING),!0!==e.isCompressedTexture&&!0!==e.isCompressedArrayTexture&&(h|=GPUTextureUsage.RENDER_ATTACHMENT);const p={label:e.name,size:{width:i,height:n,depthOrArrayLayers:o},mipLevelCount:a,sampleCount:c,dimension:u,format:l,usage:h};if(e.isVideoTexture){const t=e.source.data,s=new VideoFrame(t);p.size.width=s.displayWidth,p.size.height=s.displayHeight,s.close(),r.externalTexture=t}else{if(void 0===l)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);r.texture=s.device.createTexture(p)}if(e.isRenderTargetTexture&&d>1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e<s;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e)}}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:r,height:i}=s.getDrawingBufferSize(),n=this.depthTexture,o=s.get(n).texture;let a,u;if(t?(a=de,u=he):e&&(a=ce,u=f),void 0!==o){if(n.image.width===r&&n.image.height===i&&n.format===a&&n.type===u)return o;this.destroyTexture(n)}return n.name="depthBuffer",n.format=a,n.type=u,n.image.width=r,n.image.height=i,this.createTexture(n,{sampleCount:s.utils.getSampleCount(s.renderer.samples),width:r,height:i}),s.get(n).texture}updateTexture(e,t){const s=this.backend.get(e),{textureDescriptorGPU:r}=s;if(!e.isRenderTargetTexture&&void 0!==r){if(e.isDataTexture)this._copyBufferToTexture(t.image,s.texture,r,0,e.flipY);else if(e.isDataArrayTexture||e.isData3DTexture)for(let i=0;i<t.image.depth;i++)this._copyBufferToTexture(t.image,s.texture,r,i,e.flipY,i);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,s.texture,r);else if(e.isCubeTexture)this._copyCubeMapToTexture(t.images,s.texture,r,e.flipY);else if(e.isVideoTexture){const t=e.source.data;s.externalTexture=t}else this._copyImageToTexture(t.image,s.texture,r,0,e.flipY);s.version=e.version,e.onUpdate&&e.onUpdate(e)}}async copyTextureToBuffer(e,t,s,r,i,n){const o=this.backend.device,a=this.backend.get(e),u=a.texture,l=a.textureDescriptorGPU.format,d=this._getBytesPerTexel(l);let c=r*d;c=256*Math.ceil(c/256);const h=o.createBuffer({size:r*i*d,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=o.createCommandEncoder();p.copyTextureToBuffer({texture:u,origin:{x:t,y:s,z:n}},{buffer:h,bytesPerRow:c},{width:r,height:i});const g=this._getTypedArrayType(l);o.queue.submit([p.finish()]),await h.mapAsync(GPUMapMode.READ);return new g(h.getMappedRange())}_isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){const s=new ee;s.minFilter=hs,s.magFilter=hs,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(void 0===t){const s=new W;s.minFilter=hs,s.magFilter=hs,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(null===e){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,r){for(let i=0;i<6;i++){const n=e[i],o=!0===r?oS[i]:i;n.isDataTexture?this._copyBufferToTexture(n.image,t,s,o,r):this._copyImageToTexture(n,t,s,o,r)}}_copyImageToTexture(e,t,s,r,i){this.backend.device.queue.copyExternalImageToTexture({source:e},{texture:t,mipLevel:0,origin:{x:0,y:0,z:r}},{width:e.width,height:e.height,depthOrArrayLayers:1}),!0===i&&this._flipY(t,s,r)}_getPassUtils(){let e=this._passUtils;return null===e&&(this._passUtils=e=new iS(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,r,i,n=0){const o=this.backend.device,a=e.data,u=this._getBytesPerTexel(s.format),l=e.width*u;o.queue.writeTexture({texture:t,mipLevel:0,origin:{x:0,y:0,z:r}},a,{offset:e.width*e.height*u*n,bytesPerRow:l},{width:e.width,height:e.height,depthOrArrayLayers:1}),!0===i&&this._flipY(t,s,r)}_copyCompressedBufferToTexture(e,t,s){const r=this.backend.device,i=this._getBlockData(s.format),n=s.size.depthOrArrayLayers>1;for(let o=0;o<e.length;o++){const a=e[o],u=a.width,l=a.height,d=n?s.size.depthOrArrayLayers:1,c=Math.ceil(u/i.width)*i.byteLength,h=c*Math.ceil(l/i.height);for(let e=0;e<d;e++)r.queue.writeTexture({texture:t,mipLevel:o,origin:{x:0,y:0,z:e}},a.data,{offset:e*h,bytesPerRow:c,rowsPerImage:Math.ceil(l/i.height)},{width:Math.ceil(u/i.width)*i.width,height:Math.ceil(l/i.height)*i.height,depthOrArrayLayers:1})}}_getBlockData(e){return e===ay.BC1RGBAUnorm||e===ay.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:e===ay.BC2RGBAUnorm||e===ay.BC2RGBAUnormSRGB||e===ay.BC3RGBAUnorm||e===ay.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===ay.BC4RUnorm||e===ay.BC4RSNorm?{byteLength:8,width:4,height:4}:e===ay.BC5RGUnorm||e===ay.BC5RGSnorm||e===ay.BC6HRGBUFloat||e===ay.BC6HRGBFloat||e===ay.BC7RGBAUnorm||e===ay.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===ay.ETC2RGB8Unorm||e===ay.ETC2RGB8UnormSRGB||e===ay.ETC2RGB8A1Unorm||e===ay.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:e===ay.ETC2RGBA8Unorm||e===ay.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:e===ay.EACR11Unorm||e===ay.EACR11Snorm?{byteLength:8,width:4,height:4}:e===ay.EACRG11Unorm||e===ay.EACRG11Snorm||e===ay.ASTC4x4Unorm||e===ay.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:e===ay.ASTC5x4Unorm||e===ay.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:e===ay.ASTC5x5Unorm||e===ay.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:e===ay.ASTC6x5Unorm||e===ay.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:e===ay.ASTC6x6Unorm||e===ay.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:e===ay.ASTC8x5Unorm||e===ay.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:e===ay.ASTC8x6Unorm||e===ay.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:e===ay.ASTC8x8Unorm||e===ay.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:e===ay.ASTC10x5Unorm||e===ay.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:e===ay.ASTC10x6Unorm||e===ay.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:e===ay.ASTC10x8Unorm||e===ay.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:e===ay.ASTC10x10Unorm||e===ay.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:e===ay.ASTC12x10Unorm||e===ay.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:e===ay.ASTC12x12Unorm||e===ay.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(e){let t=uy;return e===ls?t=ly:e===cs&&(t=dy),t}_convertFilterMode(e){let t=cy;return e!==hs&&e!==ps&&e!==Pe||(t=hy),t}_getBytesPerTexel(e){return e===ay.R8Unorm||e===ay.R8Snorm||e===ay.R8Uint||e===ay.R8Sint?1:e===ay.R16Uint||e===ay.R16Sint||e===ay.R16Float||e===ay.RG8Unorm||e===ay.RG8Snorm||e===ay.RG8Uint||e===ay.RG8Sint?2:e===ay.R32Uint||e===ay.R32Sint||e===ay.R32Float||e===ay.RG16Uint||e===ay.RG16Sint||e===ay.RG16Float||e===ay.RGBA8Unorm||e===ay.RGBA8UnormSRGB||e===ay.RGBA8Snorm||e===ay.RGBA8Uint||e===ay.RGBA8Sint||e===ay.BGRA8Unorm||e===ay.BGRA8UnormSRGB||e===ay.RGB9E5UFloat||e===ay.RGB10A2Unorm||e===ay.RG11B10UFloat||e===ay.Depth32Float||e===ay.Depth24Plus||e===ay.Depth24PlusStencil8||e===ay.Depth32FloatStencil8?4:e===ay.RG32Uint||e===ay.RG32Sint||e===ay.RG32Float||e===ay.RGBA16Uint||e===ay.RGBA16Sint||e===ay.RGBA16Float?8:e===ay.RGBA32Uint||e===ay.RGBA32Sint||e===ay.RGBA32Float?16:void 0}_getTypedArrayType(e){return e===ay.R8Uint?Uint8Array:e===ay.R8Sint?Int8Array:e===ay.R8Unorm?Uint8Array:e===ay.R8Snorm?Int8Array:e===ay.RG8Uint?Uint8Array:e===ay.RG8Sint?Int8Array:e===ay.RG8Unorm?Uint8Array:e===ay.RG8Snorm?Int8Array:e===ay.RGBA8Uint?Uint8Array:e===ay.RGBA8Sint?Int8Array:e===ay.RGBA8Unorm?Uint8Array:e===ay.RGBA8Snorm?Int8Array:e===ay.R16Uint?Uint16Array:e===ay.R16Sint?Int16Array:e===ay.RG16Uint?Uint16Array:e===ay.RG16Sint?Int16Array:e===ay.RGBA16Uint?Uint16Array:e===ay.RGBA16Sint?Int16Array:e===ay.R16Float||e===ay.RG16Float||e===ay.RGBA16Float?Uint16Array:e===ay.R32Uint?Uint32Array:e===ay.R32Sint?Int32Array:e===ay.R32Float?Float32Array:e===ay.RG32Uint?Uint32Array:e===ay.RG32Sint?Int32Array:e===ay.RG32Float?Float32Array:e===ay.RGBA32Uint?Uint32Array:e===ay.RGBA32Sint?Int32Array:e===ay.RGBA32Float?Float32Array:e===ay.BGRA8Unorm||e===ay.BGRA8UnormSRGB?Uint8Array:e===ay.RGB10A2Unorm||e===ay.RGB9E5UFloat||e===ay.RG11B10UFloat?Uint32Array:e===ay.Depth32Float?Float32Array:e===ay.Depth24Plus||e===ay.Depth24PlusStencil8?Uint32Array:e===ay.Depth32FloatStencil8?Float32Array:void 0}_getDimension(e){let t;return t=e.isData3DTexture?Qy:Yy,t}}function uS(e,t=null){const s=e.format,r=e.type,i=e.colorSpace;let n;if(!0===e.isCompressedTexture||!0===e.isCompressedArrayTexture)switch(s){case Pt:n=i===De?ay.BC1RGBAUnormSRGB:ay.BC1RGBAUnorm;break;case It:n=i===De?ay.BC2RGBAUnormSRGB:ay.BC2RGBAUnorm;break;case Lt:n=i===De?ay.BC3RGBAUnormSRGB:ay.BC3RGBAUnorm;break;case zt:n=i===De?ay.ETC2RGB8UnormSRGB:ay.ETC2RGB8Unorm;break;case $t:n=i===De?ay.ETC2RGBA8UnormSRGB:ay.ETC2RGBA8Unorm;break;case Ht:n=i===De?ay.ASTC4x4UnormSRGB:ay.ASTC4x4Unorm;break;case Wt:n=i===De?ay.ASTC5x4UnormSRGB:ay.ASTC5x4Unorm;break;case jt:n=i===De?ay.ASTC5x5UnormSRGB:ay.ASTC5x5Unorm;break;case qt:n=i===De?ay.ASTC6x5UnormSRGB:ay.ASTC6x5Unorm;break;case Kt:n=i===De?ay.ASTC6x6UnormSRGB:ay.ASTC6x6Unorm;break;case Xt:n=i===De?ay.ASTC8x5UnormSRGB:ay.ASTC8x5Unorm;break;case Yt:n=i===De?ay.ASTC8x6UnormSRGB:ay.ASTC8x6Unorm;break;case Qt:n=i===De?ay.ASTC8x8UnormSRGB:ay.ASTC8x8Unorm;break;case Zt:n=i===De?ay.ASTC10x5UnormSRGB:ay.ASTC10x5Unorm;break;case Jt:n=i===De?ay.ASTC10x6UnormSRGB:ay.ASTC10x6Unorm;break;case es:n=i===De?ay.ASTC10x8UnormSRGB:ay.ASTC10x8Unorm;break;case ts:n=i===De?ay.ASTC10x10UnormSRGB:ay.ASTC10x10Unorm;break;case ss:n=i===De?ay.ASTC12x10UnormSRGB:ay.ASTC12x10Unorm;break;case rs:n=i===De?ay.ASTC12x12UnormSRGB:ay.ASTC12x12Unorm;break;case Ue:n=i===De?ay.RGBA8UnormSRGB:ay.RGBA8Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}else switch(s){case Ue:switch(r){case Xe:n=ay.RGBA8Snorm;break;case Ye:n=ay.RGBA16Sint;break;case Ke:n=ay.RGBA16Uint;break;case f:n=ay.RGBA32Uint;break;case y:n=ay.RGBA32Sint;break;case pe:n=i===De?ay.RGBA8UnormSRGB:ay.RGBA8Unorm;break;case ye:n=ay.RGBA16Float;break;case E:n=ay.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",r)}break;case je:if(r===wt)n=ay.RGB9E5UFloat;else console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",r);break;case $e:switch(r){case Xe:n=ay.R8Snorm;break;case Ye:n=ay.R16Sint;break;case Ke:n=ay.R16Uint;break;case f:n=ay.R32Uint;break;case y:n=ay.R32Sint;break;case pe:n=ay.R8Unorm;break;case ye:n=ay.R16Float;break;case E:n=ay.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",r)}break;case Ce:switch(r){case Xe:n=ay.RG8Snorm;break;case Ye:n=ay.RG16Sint;break;case Ke:n=ay.RG16Uint;break;case f:n=ay.RG32Uint;break;case y:n=ay.RG32Sint;break;case pe:n=ay.RG8Unorm;break;case ye:n=ay.RG16Float;break;case E:n=ay.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",r)}break;case ce:switch(r){case Ke:n=ay.Depth16Unorm;break;case f:n=ay.Depth24Plus;break;case E:n=ay.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",r)}break;case de:switch(r){case he:n=ay.Depth24PlusStencil8;break;case E:t&&!1===t.features.has(nb.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),n=ay.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",r)}break;case ze:switch(r){case y:n=ay.R32Sint;break;case f:n=ay.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",r)}break;case He:switch(r){case y:n=ay.RG32Sint;break;case f:n=ay.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",r)}break;case qe:switch(r){case y:n=ay.RGBA32Sint;break;case f:n=ay.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",r)}break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}return n}const lS=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,dS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,cS={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_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class hS extends WN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:i,blockCode:n,outputType:o}=(e=>{const t=(e=e.trim()).match(lS);if(null!==t&&4===t.length){const s=t[2],r=[];let i=null;for(;null!==(i=dS.exec(s));)r.push({name:i[1],type:i[2]});const n=[];for(let e=0;e<r.length;e++){const{name:t,type:s}=r[e];let i=s;i.startsWith("ptr")?i="pointer":(i.startsWith("texture")&&(i=s.split("<")[0]),i=cS[i]),n.push(new FN(i,t))}const o=e.substring(t[0].length),a=t[3]||"void",u=void 0!==t[1]?t[1]:"";return{type:cS[a]||a,inputs:n,name:u,inputsCode:s,blockCode:o,outputType:a}}throw new Error("FunctionNode: Function is not a WGSL code.")})(e);super(t,s,r),this.inputsCode=i,this.blockCode=n,this.outputType=o}getCode(e=this.name){const t="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class pS extends HN{parseFunction(e){return new hS(e)}}const gS=self.GPUShaderStage,mS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},fS={vertex:gS?gS.VERTEX:1,fragment:gS?gS.FRAGMENT:2,compute:gS?gS.COMPUTE:4},yS={instance:!0,swizzleAssign:!1,storageBuffer:!0},bS={"^^":"tsl_xor"},xS={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>"},TS={},_S={tsl_xor:new ex("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new ex("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new ex("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new ex("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new ex("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new ex("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new ex("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new ex("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 ex("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 ex("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new ex("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 ex("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new ex("\nfn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {\n\n\tlet uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new ex("\nfn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},NS={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>"};/Windows/g.test(navigator.userAgent)&&(_S.pow_float=new ex("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),_S.pow_vec2=new ex("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 ) ); }",[_S.pow_float]),_S.pow_vec3=new ex("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 ) ); }",[_S.pow_float]),_S.pow_vec4=new ex("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 ) ); }",[_S.pow_float]),NS.pow_float="tsl_pow_float",NS.pow_vec2="tsl_pow_vec2",NS.pow_vec3="tsl_pow_vec3",NS.pow_vec4="tsl_pow_vec4");let vS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(vS+="diagnostic( off, derivative_uniformity );\n");class SS extends BN{constructor(e,t){super(e,t,new pS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,i=this.shaderStage){return"fragment"===i?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)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,r,i,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${mS[e.wrapS]}S_${mS[e.wrapT]}T`;let s=TS[t];if(void 0===s){let r=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(this._include("repeatWrapping_float"),r+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(this._include("clampWrapping_float"),r+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(this._include("mirrorWrapping_float"),r+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(r+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),r+=",\n",i(e.wrapT,"y"),r+="\n\t);\n\n}\n",TS[t]=s=new ex(r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let i=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(i=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${i} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=i),i}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,i="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${i} )`:`textureLoad( ${t}, ${s}, ${i} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,i=this.shaderStage){let n=null;return n=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,i):this._generateTextureSample(e,t,s,r,i),n}generateTextureGrad(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(e,t,s,r,i,n=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this._generateTextureSampleLevel(e,t,s,r,i,n),o}generateTextureBias(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=bS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case Hy:return"read";case $y:return"write";default:return"read_write"}else switch(e.access){case ky:return"read_write";case zy:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const i=super.getUniformFromNode(e,t,s,r),n=this.getDataFromNode(e,s,this.globalCache);if(void 0===n.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let n=null;if("texture"===t||"storageTexture"===t?n=new vv(i.name,i.node,o,e.access?e.access:null):"cubeTexture"===t?n=new Sv(i.name,i.node,o,e.access?e.access:null):"texture3D"===t&&(n=new Av(i.name,i.node,o,e.access?e.access:null)),n.store=!0===e.isStorageTextureNode,n.setVisibility(fS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===n.store){const e=new eS(`${i.name}_sampler`,i.node,o);e.setVisibility(fS[s]),u.push(e,n),r=[e,n]}else u.push(n),r=[n]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const i=new("buffer"===t?yv:rS)(e,o);i.setVisibility(fS[s]),u.push(i),r=i}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new Tv(a,o),n.setVisibility(fS[s]),e[a]=n,u.push(n)),r=this.getNodeUniform(i,t),n.addUniform(r)}n.uniformGPU=r}return i}getBuiltin(e,t,s,r=this.shaderStage){const i=this.builtins[r]||(this.builtins[r]=new Map);return!1===i.has(e)&&i.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let i=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(i+=`\treturn ${s.result};\n`),i+="\n}\n",i}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array<f32, ${e} >`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:i}of s.values())t.push(`@builtin( ${e} ) ${r} : ${i}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:i}of this.scopedArrays.values()){const n=this.getType(r);t.push(`var<${s}> ${e}: array< ${n}, ${i} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(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"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e<r;e++){const r=s[e],i=r.name,n=this.getType(r.type);t.push(`@location( ${e} ) ${i} : ${n}`)}}return t.join(",\n\t")}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e<s.length;e++){const r=s[e];t.push(`\t@location( ${e} ) m${e} : ${r}<f32>`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e<r;e++){const r=s[e],i=r.name;let n=`struct ${i} {\n`;n+=this.getStructMembers(r),n+="\n}",t.push(n),t.push(`\nvar<private> output : ${i};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4<f32>","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let i=0;i<s.length;i++){const n=s[i];if(n.needsInterpolation){let e=`@location( ${i} )`;/^(int|uint|ivec|uvec)/.test(n.type)&&(e+=" @interpolate( flat )"),t.push(`${e} ${n.name} : ${this.getType(n.type)}`)}else"vertex"===e&&!1===r.includes(n)&&r.push(n)}}const s=this.getBuiltins(e);s&&t.push(s);const r=t.join(",\n\t");return"vertex"===e?this._getWGSLStruct("VaryingsStruct","\t"+r):r}getUniforms(e){const t=this.uniforms[e],s=[],r=[],i=[],n={};for(const i of t){const t=i.groupNode.name,o=this.bindingsIndexes[t];if("texture"===i.type||"cubeTexture"===i.type||"storageTexture"===i.type||"texture3D"===i.type){const t=i.node.value;let r;"fragment"===e&&!1===this.isUnfilterable(t)&&!0!==i.node.isStorageTextureNode&&(!0===t.isDepthTexture&&null!==t.compareFunction?s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${i.name}_sampler : sampler_comparison;`):s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${i.name}_sampler : sampler;`));let n="";if(!0===t.isMultisampleRenderTargetTexture&&(n="_multisampled"),!0===t.isCubeTexture)r="texture_cube<f32>";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array<f32>";else if(!0===t.isDepthTexture)r=`texture_depth${n}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d<f32>";else if(!0===i.node.isStorageTextureNode){r=`texture_storage_2d<${uS(t)}, ${this.getStorageAccess(i.node)}>`}else{r=`texture${n}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${i.name} : ${r};`)}else if("buffer"===i.type||"storageBuffer"===i.type||"indirectStorageBuffer"===i.type){const e=i.node,t=this.getType(e.bufferType),s=e.bufferCount,n=s>0&&"buffer"===i.type?", "+s:"",a=e.isAtomic?`atomic<${t}>`:`${t}`,u=`\t${i.name} : array< ${a}${n} >\n`,l=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding("NodeBuffer_"+e.id,u,l,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(i.type)),t=i.groupNode.name;(n[t]||(n[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${i.name} : ${e}`)}}for(const e in n){const t=n[e];i.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=i.join("\n"),o}buildCode(){const e=null!==this.material?{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 r="// code\n\n";r+=this.flowCode[t];const i=this.flowNodes[t],n=i[i.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of i){const i=this.getFlowData(e),u=e.name;if(u&&(r.length>0&&(r+="\n"),r+=`\t// flow -> ${u}\n\t`),r+=`${i.code}\n\t`,e===n&&"compute"!==t)if(r+="// result\n\n\t","vertex"===t)r+=`varyings.Vertex = ${i.result};`;else if("fragment"===t)if(a)s.returnType=o.nodeType,r+=`return ${i.result};`;else{let e="\t@location(0) color: vec4<f32>";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar<private> output : OutputStruct;\n\n",r+=`output.color = ${i.result};\n\n\treturn output;`}}s.flow=r}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return xS[e]||e}isAvailable(e){let t=yS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),yS[e]=t),t}_getWGSLMethod(e){return void 0!==_S[e]&&this._include(e),NS[e]}_include(e){const t=_S[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar<private> varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${vS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar<private> instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r=0,i=0){const n=e+"Struct";return`${this._getWGSLStruct(n,t)}\n@binding( ${r} ) @group( ${i} )\nvar<${s}> ${e} : ${n};`}}class AS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=ay.Depth24PlusStencil8:e.depth&&(t=ay.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?Of:e.isLineSegments||e.isMesh&&!0===t.wireframe?Gf:e.isLine?kf:e.isMesh?zf:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?ay.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const RS=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),CS=new Map([[Ie,["float16"]]]),ES=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class wS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,i=r.get(s);let n=i.buffer;if(void 0===n){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t<a.length;t++)e[t]=a[t];a=e}if(s.array=a,(s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute)&&3===s.itemSize){a=new a.constructor(4*s.count);for(let e=0;e<s.count;e++)a.set(s.array.subarray(3*e,3*e+3),4*e);s.itemSize=4,s.array=a}const u=a.byteLength+(4-a.byteLength%4)%4;n=o.createBuffer({label:s.name,size:u,usage:t,mappedAtCreation:!0}),new a.constructor(n.getMappedRange()).set(a),n.unmap(),i.buffer=n}}updateAttribute(e){const t=this._getBufferAttribute(e),s=this.backend,r=s.device,i=s.get(t).buffer,n=t.array,o=t.updateRanges;if(0===o.length)r.queue.writeBuffer(i,0,n,0);else{for(let e=0,t=o.length;e<t;e++){const t=o[e];r.queue.writeBuffer(i,0,n,t.start*n.BYTES_PER_ELEMENT,t.count*n.BYTES_PER_ELEMENT)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){const t=e.getAttributes(),s=new Map;for(let e=0;e<t.length;e++){const r=t[e],i=r.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(r);let o=s.get(n);if(void 0===o){let e,t;!0===r.isInterleavedBufferAttribute?(e=r.data.stride*i,t=r.data.isInstancedInterleavedBuffer?ib:rb):(e=r.itemSize*i,t=r.isInstancedBufferAttribute?ib:rb),!1!==r.normalized||r.array.constructor!==Int16Array&&r.array.constructor!==Uint16Array||(e=4),o={arrayStride:e,attributes:[],stepMode:t},s.set(n,o)}const a=this._getVertexFormat(r),u=!0===r.isInterleavedBufferAttribute?r.offset*i:0;o.attributes.push({shaderLocation:e,offset:u,format:a})}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,n=s.createBuffer({label:e.name,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),o=s.createCommandEncoder({});o.copyBufferToBuffer(r,0,n,0,i),n.unmap();const a=o.finish();s.queue.submit([a]),await n.mapAsync(GPUMapMode.READ);return n.getMappedRange()}_getVertexFormat(e){const{itemSize:t,normalized:s}=e,r=e.array.constructor,i=e.constructor;let n;if(1==t)n=ES.get(r);else{const e=(CS.get(i)||RS.get(r))[s?1:0];if(e){const s=r.BYTES_PER_ELEMENT*t,i=4*Math.floor((s+3)/4)/r.BYTES_PER_ELEMENT;if(i%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");n=`${e}x${i}`}}return n||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),n}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}class MS{constructor(e){this.backend=e,this.bindGroupLayoutCache=new WeakMap}createBindingsLayout(e){const t=this.backend.device,s=[];let r=0;for(const t of e.bindings){const e={binding:r++,visibility:t.visibility};if(t.isUniformBuffer||t.isStorageBuffer){const s={};t.isStorageBuffer&&(s.type=t.access),e.buffer=s}else if(t.isSampler){const s={};t.texture.isDepthTexture&&null!==t.texture.compareFunction&&(s.type="comparison"),e.sampler=s}else if(t.isSampledTexture&&t.texture.isVideoTexture)e.externalTexture={};else if(t.isSampledTexture&&t.store){const s=this.backend.get(t.texture).texture.format,r=t.access;e.storageTexture={format:s,access:r}}else if(t.isSampledTexture){const s={};if(!0===t.texture.isMultisampleRenderTargetTexture&&(s.multisampled=!0),t.texture.isDepthTexture)s.sampleType=qy;else if(t.texture.isDataTexture||t.texture.isDataArrayTexture||t.texture.isData3DTexture){const e=t.texture.type;e===y?s.sampleType=Ky:e===f?s.sampleType=Xy:e===E&&(this.backend.hasFeature("float32-filterable")?s.sampleType=Wy:s.sampleType=jy)}t.isSampledCubeTexture?s.viewDimension=eb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?s.viewDimension=Jy:t.isSampledTexture3D&&(s.viewDimension=tb),e.texture=s}else console.error(`WebGPUBindingUtils: Unsupported binding "${t}".`);s.push(e)}return t.createBindGroupLayout({entries:s})}createBindings(e){const{backend:t,bindGroupLayoutCache:s}=this,r=t.get(e);let i=s.get(e.bindingsReference);void 0===i&&(i=this.createBindingsLayout(e),s.set(e.bindingsReference,i));const n=this.createBindGroup(e,i);r.layout=i,r.group=n}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,i=t.get(e).buffer;s.queue.writeBuffer(i,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let i=0;const n=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:i});e.buffer=n}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);n.push({binding:i,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const i=sb;let n;n=t.isSampledCubeTexture?eb:t.isSampledTexture3D?tb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?Jy:Zy,o=e[r]=e.texture.createView({aspect:i,dimension:n,mipLevelCount:s})}}n.push({binding:i,resource:o})}i++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}}class BS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:i,pipeline:n}=e,{vertexProgram:o,fragmentProgram:a}=n,u=this.backend,l=u.device,d=u.utils,c=u.get(n),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e<t.length;e++){const s=d.getTextureFormatGPU(t[e]);y.push({format:s,blend:g,writeMask:f})}}else{const t=d.getCurrentColorFormat(e.context);y.push({format:t,blend:g,writeMask:f})}const b=u.get(o).module,x=u.get(a).module,T=this._getPrimitiveState(s,i,r),_=this._getDepthCompare(r),N=d.getCurrentDepthStencilFormat(e.context),v=this._getSampleCount(e.context),S={label:`renderPipeline_${r.name||r.type}_${r.id}`,vertex:Object.assign({},b,{buffers:p}),fragment:Object.assign({},x,{targets:y}),primitive:T,multisample:{count:v,alphaToCoverageEnabled:r.alphaToCoverage&&v>1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,i=s.getCurrentDepthStencilFormat(e),n={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:i,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(n)}createComputePipeline(e,t){const s=this.backend,r=s.device,i=s.get(e.computeProgram).module,n=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}n.pipeline=r.createComputePipeline({compute:i,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,i=e.blendSrc,n=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:i,a=null!==e.blendDstAlpha?e.blendDstAlpha:n,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const i=(e,r,i,n)=>{t={srcFactor:e,dstFactor:r,operation:Ry},s={srcFactor:i,dstFactor:n,operation:Ry}};if(e.premultipliedAlpha)switch(r){case F:i(gy,by,gy,by);break;case bt:i(gy,gy,gy,gy);break;case yt:i(py,fy,py,gy);break;case ft:i(py,my,py,yy)}else switch(r){case F:i(yy,by,gy,by);break;case bt:i(yy,gy,yy,gy);break;case yt:i(py,fy,py,gy);break;case ft:i(py,my,py,my)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=py;break;case st:t=gy;break;case rt:t=my;break;case ut:t=fy;break;case it:t=yy;break;case lt:t=by;break;case ot:t=xy;break;case dt:t=Ty;break;case at:t=_y;break;case ct:t=Ny;break;case nt:t=vy;break;case 211:t=Sy;break;case 212:t=Ay;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=Hf;break;case Es:t=Qf;break;case Cs:t=Wf;break;case Rs:t=qf;break;case As:t=jf;break;case Ss:t=Yf;break;case vs:t=Kf;break;case Ns:t=Xf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Fy;break;case Ls:t=Py;break;case Is:t=Iy;break;case Ps:t=Ly;break;case Fs:t=Dy;break;case Us:t=Vy;break;case Bs:t=Oy;break;case Ms:t=Gy;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Ry;break;case Je:t=Cy;break;case et:t=Ey;break;case Os:t=wy;break;case Vs:t=My;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},i=this.backend.utils;switch(r.topology=i.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?ny:oy),s.side){case Oe:r.frontFace=ty,r.cullMode=iy;break;case x:r.frontFace=ty,r.cullMode=ry;break;case le:r.frontFace=ty,r.cullMode=sy;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Uy:By}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Qf;else{const s=e.depthFunc;switch(s){case Rt:t=Hf;break;case At:t=Qf;break;case St:t=Wf;break;case vt:t=qf;break;case Nt:t=jf;break;case _t:t=Yf;break;case Tt:t=Kf;break;case xt:t=Xf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class US extends Pv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new AS(this),this.attributeUtils=new wS(this),this.bindingUtils=new MS(this),this.pipelineUtils=new BS(this),this.textureUtils=new aS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const i=Object.values(nb),n=[];for(const e of i)r.features.has(e)&&n.push(e);const o={requiredFeatures:n,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const i=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(nb.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:i}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.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){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const i=e.getCacheKey();let n=r[i];if(void 0===n){const o=e.textures,a=[];for(let t=0;t<o.length;t++){const s=this.get(o[t]),r=s.texture.createView({baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,dimension:Zy});let i,n;void 0!==s.msaaTexture?(i=s.msaaTexture.createView(),n=r):(i=r,n=void 0),a.push({view:i,resolveTarget:n,loadOp:Jf,storeOp:Zf})}if(n={colorAttachments:a},e.depth){const t={view:this.get(e.depthTexture).texture.createView()};n.depthStencilAttachment=t}r[i]=n,s.width=t.width,s.height=t.height,s.samples=t.samples,s.activeMipmapLevel=t.activeMipmapLevel}return n}beginRender(e){const t=this.get(e),s=this.device,r=e.occlusionQueryCount;let i,n;r>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,i=s.createQuerySet({type:"occlusion",count:r}),t.occlusionQuerySet=i,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),n=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,n),n.occlusionQuerySet=i;const o=n.depthStencilAttachment;if(null!==e.textures){const t=n.colorAttachments;for(let s=0;s<t.length;s++){const r=t[s];e.clearColor?(r.clearValue=0===s?e.clearColorValue:{r:0,g:0,b:0,a:1},r.loadOp=ey,r.storeOp=Zf):(r.loadOp=Jf,r.storeOp=Zf)}}else{const t=n.colorAttachments[0];e.clearColor?(t.clearValue=e.clearColorValue,t.loadOp=ey,t.storeOp=Zf):(t.loadOp=Jf,t.storeOp=Zf)}e.depth&&(e.clearDepth?(o.depthClearValue=e.clearDepthValue,o.depthLoadOp=ey,o.depthStoreOp=Zf):(o.depthLoadOp=Jf,o.depthStoreOp=Zf)),e.stencil&&(e.clearStencil?(o.stencilClearValue=e.clearStencilValue,o.stencilLoadOp=ey,o.stencilStoreOp=Zf):(o.stencilLoadOp=Jf,o.stencilStoreOp=Zf));const a=s.createCommandEncoder({label:"renderContext_"+e.id}),u=a.beginRenderPass(n);if(t.descriptor=n,t.encoder=a,t.currentPass=u,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[],e.viewport&&this.updateViewport(e),e.scissor){const{x:t,y:s,width:r,height:i}=e.scissorValue;u.setScissorRect(t,s,r,i)}}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 r=8*s;let i=this.occludedResolveCache.get(r);void 0===i&&(i=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,i));const n=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,i,0),t.encoder.copyBufferToBuffer(i,0,n,0,r),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;e<t.length;e++){const s=t[e];!0===s.generateMipmaps&&this.textureUtils.generateMipmaps(s)}}}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:r}=t;if(s&&r){const e=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await s.mapAsync(GPUMapMode.READ);const i=s.getMappedRange(),n=new BigUint64Array(i);for(let t=0;t<r.length;t++)n[t]!==BigInt(0)&&e.add(r[t]);s.destroy(),t.occluded=e}}updateViewport(e){const{currentPass:t}=this.get(e),{x:s,y:r,width:i,height:n,minDepth:o,maxDepth:a}=e.viewportValue;t.setViewport(s,r,i,n,o,a)}clear(e,t,s,r=null){const i=this.device,n=this.renderer;let o,a,u,l,d=[];if(e){const e=this.getClearColor();if(!0===this.renderer.alpha){const t=e.a;a={r:e.r*t,g:e.g*t,b:e.b*t,a:t}}else a={r:e.r,g:e.g,b:e.b,a:e.a}}if(null===r){u=n.depth,l=n.stencil;const t=this._getDefaultRenderPassDescriptor();if(e){d=t.colorAttachments;const e=d[0];e.clearValue=a,e.loadOp=ey,e.storeOp=Zf}(u||l)&&(o=t.depthStencilAttachment)}else{if(u=r.depth,l=r.stencil,e)for(const e of r.textures){const t=this.get(e),s=t.texture.createView();let r,i;void 0!==t.msaaTexture?(r=t.msaaTexture.createView(),i=s):(r=s,i=void 0),d.push({view:r,resolveTarget:i,clearValue:a,loadOp:ey,storeOp:Zf})}if(u||l){o={view:this.get(r.depthTexture).texture.createView()}}}u&&(t?(o.depthLoadOp=ey,o.depthClearValue=n.getClearDepth(),o.depthStoreOp=Zf):(o.depthLoadOp=Jf,o.depthStoreOp=Zf)),l&&(s?(o.stencilLoadOp=ey,o.stencilClearValue=n.getClearStencil(),o.stencilStoreOp=Zf):(o.stencilLoadOp=Jf,o.stencilStoreOp=Zf));const c=i.createCommandEncoder({});c.beginRenderPass({colorAttachments:d,depthStencilAttachment:o}).end(),i.queue.submit([c.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,r){const{passEncoderGPU:i}=this.get(e),n=this.get(r).pipeline;i.setPipeline(n);for(let e=0,t=s.length;e<t;e++){const t=s[e],r=this.get(t);i.setBindGroup(e,r.group)}const o=this.device.limits.maxComputeWorkgroupsPerDimension,a=this.get(t);void 0===a.dispatchSize&&(a.dispatchSize={x:0,y:1,z:1});const{dispatchSize:u}=a;t.dispatchCount>o?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,i.dispatchWorkgroups(u.x,u.y,u.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:r,pipeline:i}=e,n=e.getBindings(),o=this.get(r),a=this.get(i).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=n.length;e<t;e++){const t=n[e],s=this.get(t);c[t.index]!==t.id&&(l.setBindGroup(t.index,s.group),c[t.index]=t.id)}const h=e.getIndex(),p=null!==h;if(!0===p&&u.index!==h){const e=this.get(h).buffer,t=h.array instanceof Uint16Array?ny:oy;l.setIndexBuffer(e,t),u.index=h}const g=e.getVertexBuffers();for(let e=0,t=g.length;e<t;e++){const t=g[e];if(u.attributes[e]!==t){const s=this.get(t).buffer;l.setVertexBuffer(e,s),u.attributes[e]=t}}if(void 0!==o.occlusionQuerySet){const e=o.lastOcclusionObject;e!==s&&(null!==e&&!0===e.occlusionTest&&(l.endOcclusionQuery(),o.occlusionQueryIndex++),!0===s.occlusionTest&&(l.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=s),o.lastOcclusionObject=s)}if(!0===s.isBatchedMesh){const e=s._multiDrawStarts,t=s._multiDrawCounts,r=s._multiDrawCount,i=s._multiDrawInstances,n=p?h.array.BYTES_PER_ELEMENT:1;for(let s=0;s<r;s++){const r=i?i[s]:1,o=r>1?0:s;l.drawIndexed(t[s],r,e[s]/n,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,i,n,0,0);t.update(s,r,i)}else{const{vertexCount:r,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,i,n,0);t.update(s,r,i)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,i=this.utils,n=i.getSampleCountRenderContext(e.context),o=i.getCurrentColorSpace(e.context),a=i.getCurrentColorFormat(e.context),u=i.getCurrentDepthStencilFormat(e.context),l=i.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===n&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=n,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,i=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,r.getSampleCountRenderContext(i),r.getCurrentColorSpace(i),r.getCurrentColorFormat(i),r.getCurrentDepthStencilFormat(i),r.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,r,i,n){return this.textureUtils.copyTextureToBuffer(e,t,s,r,i,n)}initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){const e=this.device.createQuerySet({type:"timestamp",count:2}),r={querySet:e,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:r}),s.timeStampQuerySet=e}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e),r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:i,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,i,0),t.copyBufferToBuffer(i,0,n,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:i}=s.currentTimestampQueryBuffers;!0!==i&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),i=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,i),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new SS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),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){this.bindingUtils.createBindings(e)}updateBindings(e){this.bindingUtils.createBindings(e)}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,r=null,i=0){let n=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(n=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:i,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:i,origin:{x:n,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let i=null;i=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const n=this.get(e).texture;if(i.format!==n.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",i.format,n.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:i,origin:{x:s.x,y:s.y,z:0}},{texture:n},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t<e.colorAttachments.length;t++)e.colorAttachments[t].loadOp=Jf;t.depth&&(e.depthStencilAttachment.depthLoadOp=Jf),t.stencil&&(e.depthStencilAttachment.stencilLoadOp=Jf),r.currentPass=o.beginRenderPass(e),r.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null}}else this.device.queue.submit([o.finish()])}}class FS extends Gs{constructor(e,t,s,r,i,n){super(e,t,s,r,i,n),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class PS extends rv{constructor(){super(),this.addMaterial(Vh,"MeshPhongMaterial"),this.addMaterial(ig,"MeshStandardMaterial"),this.addMaterial(og,"MeshPhysicalMaterial"),this.addMaterial(hg,"MeshToonMaterial"),this.addMaterial(wh,"MeshBasicMaterial"),this.addMaterial(Lh,"MeshLambertMaterial"),this.addMaterial(mh,"MeshNormalMaterial"),this.addMaterial(fg,"MeshMatcapMaterial"),this.addMaterial(ah,"LineBasicMaterial"),this.addMaterial(lh,"LineDashedMaterial"),this.addMaterial(bg,"PointsMaterial"),this.addMaterial(Ng,"SpriteMaterial"),this.addMaterial(Ag,"ShadowMaterial"),this.addLight(NT,ks),this.addLight(PN,zs),this.addLight(VN,$s),this.addLight(ON,Gs),this.addLight(kN,Hs),this.addLight(zN,Ws),this.addLight($N,js),this.addLight(GN,FS),this.addToneMapping(Hb,qs),this.addToneMapping(Wb,Ks),this.addToneMapping(jb,Xs),this.addToneMapping(Kb,Ys),this.addToneMapping(Zb,Qs),this.addToneMapping(Jb,Zs)}}class IS extends hv{constructor(e={}){let t;e.forceWebGL?t=Zv:(t=US,e.getFallback=()=>(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new Zv(e)));super(new t(e),e),this.library=new PS,this.isWebGPURenderer=!0}}class LS extends Js{constructor(){super(),this.isClippingGroup=!0,this.clippingPlanes=[],this.enabled=!0,this.clipIntersection=!1,this.clipShadows=!1}}class DS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const VS=new rh,OS=new xf(VS);class GS{constructor(e,t=Ii(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,VS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,OS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;OS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),OS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await OS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function kS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function zS(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function $S(e,t,s={}){return(s=kS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var HS=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=$S(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=kS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){zS(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:zS,saveRendererAndSceneState:$S,saveRendererState:kS});class WS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class jS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class qS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class KS extends jS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class XS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const i=new tr(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),vi()):ci(new this.nodes[e])}}class YS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const i=r[e];t[e]=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 void 0!==t?new t:super.createMaterialFromType(e)}}class QS extends rr{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(void 0!==e){const s=new XS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),i=new YS;i.setTextures(t),i.setNodes(r),i.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t<r;t++){const r=e[t];s[r.uuid]=i.parse(r)}}return s}}export{Ys as ACESFilmicToneMapping,bc as AONode,Ze as AddEquation,K as AddOperation,bt as AdditiveBlending,Qs as AgXToneMapping,Mt as AlphaFormat,ms as AlwaysCompare,At as AlwaysDepth,Es as AlwaysStencilFunc,Hs as AmbientLight,kN as AmbientLightNode,xT as AnalyticLightNode,Rr as ArrayElementNode,Fn as AssignNode,pu as AttributeNode,jh as BRDF_GGX,Bh as BRDF_Lambert,x as BackSide,Sh as BasicEnvironmentNode,tc as BatchNode,O as BoxGeometry,dc as Break,we as BufferAttribute,ja as BufferAttributeNode,Te as BufferGeometry,Nl as BufferNode,sd as BumpMapNode,DS as BundleGroup,tu as BypassNode,Xe as ByteType,Ja as CacheNode,Xs as CineonToneMapping,ds as ClampToEdgeWrapping,LS as ClippingGroup,ex as CodeNode,e as Color,u as ColorManagement,Fa as ColorSpaceNode,Qa as ComputeNode,Ir as ConstNode,_a as ContextNode,lc as Continue,Cr as ConvertNode,H as CubeCamera,T as CubeReflectionMapping,_ as CubeRefractionMapping,W as CubeTexture,Tl as CubeTextureNode,Me as CubeUVReflectionMapping,pt as CullFaceBack,gt as CullFaceFront,ht as CullFaceNone,mt as CustomBlending,qh as DFGApprox,$h as D_GGX,C as DataArrayTexture,ke as DataTexture,Us as DecrementStencilOp,Ms as DecrementWrapStencilOp,ce as DepthFormat,de as DepthStencilFormat,B as DepthTexture,zs as DirectionalLight,PN as DirectionalLightNode,uu as Discard,le as DoubleSide,at as DstAlphaFactor,ot as DstColorFactor,p as DynamicDrawUsage,ao as EPSILON,eg as EnvironmentNode,ys as EqualCompare,Nt as EqualDepth,As as EqualStencilFunc,fh as EquirectUVNode,j as EquirectangularReflectionMapping,q as EquirectangularRefractionMapping,ve as Euler,o as EventDispatcher,ou as ExpressionNode,Mh as F_Schlick,tr as FileLoader,Ie as Float16BufferAttribute,_e as Float32BufferAttribute,E as FloatType,fi as Fn,Tx as FogExp2Node,fx as FogNode,bx as FogRangeNode,w as FramebufferTexture,sl as FrontFacingNode,Oe as FrontSide,Ge as Frustum,In as FunctionCallNode,nx as FunctionNode,Mm as FunctionOverloadingNode,YN as GLSLNodeParser,xs as GreaterCompare,Tt as GreaterDepth,bs as GreaterEqualCompare,_t as GreaterEqualDepth,Ss as GreaterEqualStencilFunc,vs as GreaterStencilFunc,Js as Group,ye as HalfFloatType,Ws as HemisphereLight,zN as HemisphereLightNode,FS as IESSpotLight,GN as IESSpotLightNode,uo as INFINITY,Ti as If,Fs as IncrementStencilOp,Bs as IncrementWrapStencilOp,jd as IndexNode,KS as IndirectStorageBufferAttribute,Jd as InstanceNode,R as InstancedBufferAttribute,A as InstancedInterleavedBuffer,nh as InstancedPointsNodeMaterial,y as IntType,h as InterleavedBuffer,g as InterleavedBufferAttribute,Ps as InvertStencilOp,_c as IrradianceNode,wr as JoinNode,Ds as KeepStencilOp,Ae as LessCompare,St as LessDepth,fs as LessEqualCompare,vt as LessEqualDepth,Rs as LessEqualStencilFunc,Cs as LessStencilFunc,js as LightProbe,$N as LightProbeNode,nv as Lighting,xc as LightingContextNode,Rh as LightingModel,yc as LightingNode,iT as LightsNode,ch as Line2NodeMaterial,I as LineBasicMaterial,ah as LineBasicNodeMaterial,L as LineDashedMaterial,lh as LineDashedNodeMaterial,$ as LinearFilter,be as LinearMipMapLinearFilter,M as LinearMipmapLinearFilter,Fe as LinearMipmapNearestFilter,Se as LinearSRGBColorSpace,qs as LinearToneMapping,er as Loader,uc as Loop,ac as LoopNode,Ut as LuminanceAlphaFormat,Bt as LuminanceFormat,Tm as MRTNode,pg as MatcapUVNode,U as Material,sr as MaterialLoader,nd as MaterialNode,Ul as MaterialReferenceNode,a as MathUtils,i as Matrix3,n as Matrix4,Vs as MaxEquation,bu as MaxMipLevelNode,k as Mesh,Q as MeshBasicMaterial,wh as MeshBasicNodeMaterial,Z as MeshLambertMaterial,Lh as MeshLambertNodeMaterial,ie as MeshMatcapMaterial,fg as MeshMatcapNodeMaterial,D as MeshNormalMaterial,mh as MeshNormalNodeMaterial,J as MeshPhongMaterial,Vh as MeshPhongNodeMaterial,se as MeshPhysicalMaterial,og as MeshPhysicalNodeMaterial,ug as MeshSSSNodeMaterial,te as MeshStandardMaterial,ig as MeshStandardNodeMaterial,re as MeshToonMaterial,hg as MeshToonNodeMaterial,Os as MinEquation,cs as MirroredRepeatWrapping,X as MixOperation,Vu as ModelNode,Hd as ModelViewProjectionNode,mc as MorphNode,ft as MultiplyBlending,Y as MultiplyOperation,hs as NearestFilter,Pe as NearestMipmapLinearFilter,ps as NearestMipmapNearestFilter,Zs as NeutralToneMapping,gs as NeverCompare,Rt as NeverDepth,ws as NeverStencilFunc,G as NoBlending,m as NoColorSpace,d as NoToneMapping,Ar as Node,O_ as NodeAttribute,BN as NodeBuilder,W_ as NodeCache,$_ as NodeCode,UN as NodeFrame,FN as NodeFunctionInput,XS as NodeLoader,rh as NodeMaterial,YS as NodeMaterialLoader,nr as NodeMaterialObserver,QS as NodeObjectLoader,yr as NodeShaderStage,xr as NodeType,G_ as NodeUniform,br as NodeUpdateType,fr as NodeUtils,k_ as NodeVar,z_ as NodeVarying,F as NormalBlending,Zl as NormalMapNode,Ts as NotEqualCompare,xt as NotEqualDepth,Ns as NotEqualStencilFunc,fe as Object3D,Uu as Object3DNode,rr as ObjectLoader,S as ObjectSpaceNormalMap,st as OneFactor,ct as OneMinusDstAlphaFactor,dt as OneMinusDstColorFactor,lt as OneMinusSrcAlphaFactor,ut as OneMinusSrcColorFactor,xe as OrthographicCamera,ym as OutputStructNode,Ve as PCFShadowMap,lo as PI,co as PI2,_N as PMREMGenerator,Qp as PMREMNode,hm as ParameterNode,Vb as PassNode,Be as PerspectiveCamera,Ph as PhongLightingModel,Cp as PhysicalLightingModel,me as Plane,ks as PointLight,NT as PointLightNode,wf as PointUVNode,P as PointsMaterial,bg as PointsNodeMaterial,GS as PostProcessing,HS as PostProcessingUtils,Mb as PosterizeNode,tn as PropertyNode,xf as QuadMesh,as as RED_GREEN_RGTC2_Format,ns as RED_RGTC1_Format,Le as REVISION,Ue as RGBAFormat,qe as RGBAIntegerFormat,ts as RGBA_ASTC_10x10_Format,Zt as RGBA_ASTC_10x5_Format,Jt as RGBA_ASTC_10x6_Format,es as RGBA_ASTC_10x8_Format,ss as RGBA_ASTC_12x10_Format,rs as RGBA_ASTC_12x12_Format,Ht as RGBA_ASTC_4x4_Format,Wt as RGBA_ASTC_5x4_Format,jt as RGBA_ASTC_5x5_Format,qt as RGBA_ASTC_6x5_Format,Kt as RGBA_ASTC_6x6_Format,Xt as RGBA_ASTC_8x5_Format,Yt as RGBA_ASTC_8x6_Format,Qt as RGBA_ASTC_8x8_Format,is as RGBA_BPTC_Format,$t as RGBA_ETC2_EAC_Format,Gt as RGBA_PVRTC_2BPPV1_Format,Ot as RGBA_PVRTC_4BPPV1_Format,Pt as RGBA_S3TC_DXT1_Format,It as RGBA_S3TC_DXT3_Format,Lt as RGBA_S3TC_DXT5_Format,je as RGBFormat,We as RGBIntegerFormat,kt as RGB_ETC1_Format,zt as RGB_ETC2_Format,Vt as RGB_PVRTC_2BPPV1_Format,Dt as RGB_PVRTC_4BPPV1_Format,Ft as RGB_S3TC_DXT1_Format,Ce as RGFormat,He as RGIntegerFormat,_f as RTTNode,Sx as RangeNode,$s as RectAreaLight,VN as RectAreaLightNode,$e as RedFormat,ze as RedIntegerFormat,wl as ReferenceNode,pf as ReflectorNode,Ks as ReinhardToneMapping,ru as RemapNode,du as RenderOutputNode,ge as RenderTarget,ka as RendererReferenceNode,ls as RepeatWrapping,Is as ReplaceStencilOp,lu as Return,et as ReverseSubtractEquation,xg as RotateNode,us as SIGNED_RED_GREEN_RGTC2_Format,os as SIGNED_RED_RGTC1_Format,De as SRGBColorSpace,l as SRGBTransfer,z as Scene,Ff as SceneNode,Xh as Schlick_to_F0,Sc as ScreenNode,gx as ScriptableNode,px as ScriptableNodeResources,lx as ScriptableValueNode,Ur as SetNode,di as ShaderNode,oe as ShadowMaterial,mT as ShadowNode,Ag as ShadowNodeMaterial,Ye as ShortType,ic as SkinningNode,Ee as SphereGeometry,Br as SplitNode,Gs as SpotLight,ON as SpotLightNode,ne as SpriteMaterial,Ng as SpriteNodeMaterial,qm as SpriteSheetUVNode,it as SrcAlphaFactor,nt as SrcAlphaSaturateFactor,rt as SrcColorFactor,gm as StackNode,c as StaticDrawUsage,Df as StorageArrayElementNode,jS as StorageBufferAttribute,ob as StorageBufferNode,qS as StorageInstancedBufferAttribute,WS as StorageTexture,lb as StorageTextureNode,Je as SubtractEquation,yt as SubtractiveBlending,ql as TBNViewMatrix,v as TangentSpaceNormalMap,Er as TempNode,ee as Texture,Cg as Texture3DNode,Tu as TextureNode,fu as TextureSizeNode,$a as ToneMappingNode,zb as ToonOutlinePassNode,Xm as TriplanarTexturesNode,Ne as UVMapping,ue as Uint16BufferAttribute,ae as Uint32BufferAttribute,Al as UniformArrayNode,qi as UniformGroupNode,Ji as UniformNode,pe as UnsignedByteType,he as UnsignedInt248Type,wt as UnsignedInt5999Type,f as UnsignedIntType,Ct as UnsignedShort4444Type,Et as UnsignedShort5551Type,Ke as UnsignedShortType,hb as UserDataNode,Re as VSMShadowMap,kh as V_GGX_SmithCorrelated,Sa as VarNode,Ca as VaryingNode,t as Vector2,s as Vector3,r as Vector4,Cf as VertexColorNode,zc as ViewportDepthNode,Gc as ViewportDepthTextureNode,Fb as ViewportSharedTextureNode,Lc as ViewportTextureNode,wg as VolumeNodeMaterial,b as WebGLCoordinateSystem,V as WebGLCubeRenderTarget,N as WebGPUCoordinateSystem,IS as WebGPURenderer,tt as ZeroFactor,Ls as ZeroStencilOp,Fo as abs,Kb as acesFilmicToneMapping,Bo as acos,Vn as add,Vr as addMethodChaining,hu as addNodeElement,Zb as agxToneMapping,ho as all,fn as alphaT,Xn as and,yn as anisotropy,xn as anisotropyB,bn as anisotropyT,po as any,_i as append,$i as arrayBuffer,Mo as asin,Pn as assign,Uo as atan,jo as atan2,$x as atomicAdd,qx as atomicAnd,kx as atomicFunc,Wx as atomicMax,jx as atomicMin,Kx as atomicOr,zx as atomicStore,Hx as atomicSub,Xx as atomicXor,Bn as attenuationColor,Mn as attenuationDistance,gu as attribute,Pf as backgroundBlurriness,If as backgroundIntensity,Lf as backgroundRotation,sc as batch,Wm as billboarding,Jn as bitAnd,eo as bitNot,to as bitOr,so as bitXor,kl as bitangentGeometry,zl as bitangentLocal,$l as bitangentView,Hl as bitangentWorld,Ho as bitcast,qp as blur,Ri as bool,vl as buffer,qa as bufferAttribute,rd as bumpMap,xb as burn,Mi as bvec2,Pi as bvec3,Vi as bvec4,su as bypass,eu as cache,Ln as call,Au as cameraFar,Su as cameraNear,Mu as cameraNormalMatrix,Bu as cameraPosition,Ru as cameraProjectionMatrix,Cu as cameraProjectionMatrixInverse,Eu as cameraViewMatrix,wu as cameraWorldMatrix,aa as cbrt,wb as cdl,So as ceil,vT as checker,jb as cineonToneMapping,da as clamp,ln as clearcoat,dn as clearcoatRoughness,tx as code,Ni as color,Da as colorSpaceToWorking,ph as colorToDirection,Za as compute,Ta as cond,Na as context,Wi as convert,Va as convertColorSpace,vf as convertToTexture,Eo as cos,Qe as createCanvasElement,ta as cross,_l as cubeTexture,Vo as dFdx,Oo as dFdy,Sn as dashSize,_r as defaultBuildStages,Tr as defaultShaderStages,ui as defined,fo as degrees,Pm as deltaTime,_x as densityFog,Xc as depth,kb as depthPass,Jo as difference,nn as diffuseColor,_T as directPointLight,hh as directionToColor,Un as dispersion,Zo as distance,kn as div,Tb as dodge,ea as dot,Zd as drawIndex,Ka as dynamicBufferAttribute,Hi as element,on as emissive,$n as equal,go as equals,yh as equirectUV,yo as exp,bo as exp2,au as expression,il as faceDirection,ga as faceForward,vi as float,vo as floor,yx as fog,Ro as fract,Yi as frameGroup,Im as frameId,rl as frontFacing,$o as fwidth,Sm as gain,An as gapSize,li as getConstNodeType,xi as getCurrentStack,$p as getDirection,TT as getDistanceAttenuation,Oh as getGeometryRoughness,Rf as getNormalFromDepth,U_ as getParallaxCorrectNormal,Gh as getRoughness,Af as getScreenPosition,F_ as getShIrradianceAt,xm as getTextureIndex,Sf as getViewPosition,ix as glsl,ax as glslFn,vb as grayscale,jn as greaterThan,Kn as greaterThanEqual,Nm as hash,Ku as highPrecisionModelNormalViewMatrix,qu as highPrecisionModelViewMatrix,Rb as hue,ec as instance,Kd as instanceIndex,Xa as instancedBufferAttribute,Ya as instancedDynamicBufferAttribute,Si as int,No as inverseSqrt,Qd as invocationLocalIndex,Yd as invocationSubgroupIndex,Cn as ior,pn as iridescence,gn as iridescenceIOR,mn as iridescenceThickness,Ei as ivec2,Ui as ivec3,Li as ivec4,sx as js,va as label,Io as length,ua as lengthSq,Wn as lessThan,qn as lessThanEqual,Zx as lightPosition,tT as lightTargetDirection,Jx as lightTargetPosition,eT as lightViewPosition,Tc as lightingContext,nT as lights,Yc as linearDepth,Hb as linearToneMapping,Mx as localId,xo as log,To as log2,cc as loop,Cb as luminance,Oi as mat2,Gi as mat3,ki as mat4,gg as matcapUV,zd as materialAOMap,od as materialAlphaTest,Ad as materialAnisotropy,$d as materialAnisotropyVector,Fd as materialAttenuationColor,Ud as materialAttenuationDistance,xd as materialClearcoat,_d as materialClearcoatNormal,Td as materialClearcoatRoughness,ad as materialColor,Gd as materialDispersion,ld as materialEmissive,Bd as materialIOR,Rd as materialIridescence,Cd as materialIridescenceIOR,Ed as materialIridescenceThickness,kd as materialLightMap,Vd as materialLineDashOffset,Id as materialLineDashSize,Ld as materialLineGapSize,Pd as materialLineScale,Dd as materialLineWidth,yd as materialMetalness,bd as materialNormal,dd as materialOpacity,Od as materialPointWidth,Fl as materialReference,md as materialReflectivity,ml as materialRefractionRatio,Nd as materialRotation,fd as materialRoughness,vd as materialSheen,Sd as materialSheenRoughness,ud as materialShininess,cd as materialSpecular,pd as materialSpecularColor,hd as materialSpecularIntensity,gd as materialSpecularStrength,Md as materialThickness,wd as materialTransmission,Ko as max,xu as maxMipLevel,un as metalness,qo as min,la as mix,fa as mixElement,Xo as mod,zn as modInt,Ou as modelDirection,Hu as modelNormalMatrix,ku as modelPosition,zu as modelScale,ju as modelViewMatrix,$u as modelViewPosition,Wd as modelViewProjection,Gu as modelWorldMatrix,Wu as modelWorldMatrixInverse,fc as morphReference,_m as mrt,Gn as mul,c_ as mx_aastep,C_ as mx_cell_noise_float,T_ as mx_contrast,E_ as mx_fractal_noise_float,w_ as mx_fractal_noise_vec2,M_ as mx_fractal_noise_vec3,B_ as mx_fractal_noise_vec4,u_ as mx_hsvtorgb,__ as mx_noise_float,N_ as mx_noise_vec3,v_ as mx_noise_vec4,p_ as mx_ramplr,g_ as mx_ramptb,l_ as mx_rgbtohsv,x_ as mx_safepower,f_ as mx_splitlr,y_ as mx_splittb,d_ as mx_srgb_texture_to_lin_rec709,b_ as mx_transform_uv,S_ as mx_worley_noise_float,A_ as mx_worley_noise_vec2,R_ as mx_worley_noise_vec3,Lo as negate,Jb as neutralToneMapping,pi as nodeArray,mi as nodeImmutable,ci as nodeObject,hi as nodeObjects,gi as nodeProxy,al as normalFlat,nl as normalGeometry,ol as normalLocal,Jl as normalMap,ul as normalView,ll as normalWorld,Ao as normalize,Qn as not,Hn as notEqual,Ex as numWorkgroups,Fu as objectDirection,Zi as objectGroup,Iu as objectPosition,Lu as objectScale,Du as objectViewPosition,Pu as objectWorldMatrix,Do as oneMinus,Yn as or,Hc as orthographicDepthToViewZ,zm as oscSawtooth,Om as oscSine,Gm as oscSquare,km as oscTriangle,vn as output,bm as outputStruct,Nb as overlay,Um as overloadingFn,vm as parabola,Kl as parallaxDirection,Xl as parallaxUV,pm as parameter,Ob as pass,Gb as passTexture,Am as pcurve,qc as perspectiveDepthToLogarithmicDepth,jc as perspectiveDepthToViewZ,Zp as pmremTexture,Mf as pointUV,Rn as pointWidth,Xu as positionGeometry,Yu as positionLocal,Qu as positionPrevious,el as positionView,tl as positionViewDirection,Zu as positionWorld,Ju as positionWorldDirection,Bb as posterize,sa as pow,ra as pow2,ia as pow3,na as pow4,sn as property,mo as radians,ma as rand,Ax as range,xx as rangeFog,ko as reciprocal,Ml as reference,Bl as referenceBuffer,Qo as reflect,bl as reflectVector,fl as reflectView,mf as reflector,ha as refract,xl as refractVector,yl as refractView,Wb as reinhardToneMapping,no as remainder,iu as remap,nu as remapClamp,Qi as renderGroup,cu as renderOutput,za as rendererReference,Tg as rotate,$m as rotateUV,an as roughness,Go as round,Nf as rtt,wa as sRGBTransferEOTF,Ma as sRGBTransferOETF,vu as sampler,ca as saturate,Sb as saturation,_b as screen,Cc as screenCoordinate,Rc as screenSize,Ac as screenUV,mx as scriptable,dx as scriptableValue,xa as select,bi as setCurrentStack,Nr as shaderStages,yT as shadow,bT as shadows,Xi as sharedUniformGroup,cn as sheen,hn as sheenRoughness,ro as shiftLeft,io as shiftRight,Nn as shininess,Po as sign,Co as sin,Rm as sinc,nc as skinning,oc as skinningReference,pa as smoothstep,ya as smoothstepElement,Tn as specularColor,_n as specularF90,Hm as spherizeUV,ji as split,Km as spritesheetUV,_o as sqrt,mm as stack,Yo as step,ab as storage,Px as storageBarrier,ub as storageObject,db as storageTexture,zi as string,On as sub,Xd as subgroupIndex,Bx as subgroupSize,wo as tan,Pl as tangentGeometry,Il as tangentLocal,Ll as tangentView,Dl as tangentWorld,Ra as temp,_u as texture,Eg as texture3D,Ix as textureBarrier,pp as textureBicubic,Hp as textureCubeUV,Nu as textureLoad,yu as textureSize,cb as textureStore,wn as thickness,Eb as threshold,Fm as time,Vm as timerDelta,Dm as timerGlobal,Lm as timerLocal,Pa as toOutputColorSpace,Ia as toWorkingColorSpace,Ha as toneMapping,Wa as toneMappingExposure,$b as toonOutlinePass,oa as transformDirection,pl as transformNormal,gl as transformNormalToView,Yl as transformedBentNormalView,Wl as transformedBitangentView,jl as transformedBitangentWorld,hl as transformedClearcoatNormalView,dl as transformedNormalView,cl as transformedNormalWorld,Vl as transformedTangentView,Ol as transformedTangentWorld,En as transmission,Wo as transpose,Cm as tri,Em as tri3,wm as triNoise3D,Qm as triplanarTexture,Ym as triplanarTextures,zo as trunc,yi as tslFn,Ai as uint,en as uniform,Rl as uniformArray,Ki as uniformGroup,Cl as uniforms,pb as userData,mu as uv,wi as uvec2,Fi as uvec3,Di as uvec4,Ea as varying,rn as varyingProperty,Ci as vec2,Bi as vec3,Ii as vec4,vr as vectorComponents,bb as velocity,Ef as vertexColor,qd as vertexIndex,Ab as vibrance,$c as viewZToOrthographicDepth,Wc as viewZToPerspectiveDepth,Ec as viewport,Pc as viewportBottomLeft,Mc as viewportCoordinate,kc as viewportDepthTexture,Qc as viewportLinearDepth,Vc as viewportMipTexture,Uc as viewportResolution,jm as viewportSafeUV,Pb as viewportSharedTexture,wc as viewportSize,Dc as viewportTexture,Fc as viewportTopLeft,Bc as viewportUV,rx as wgsl,ux as wgslFn,Vx as workgroupArray,Fx as workgroupBarrier,wx as workgroupId,La as workingToColorSpace,Zn as xor};
粤ICP备19079148号