three
Version:
JavaScript 3D library
6 lines • 622 kB
JavaScript
/**
* @license
* Copyright 2010-2026 Three.js Authors
* SPDX-License-Identifier: MIT
*/
import{Color as e,Vector2 as t,Vector3 as r,Vector4 as s,Matrix2 as i,Matrix3 as n,Matrix4 as a,error as o,EventDispatcher as u,MathUtils as l,warn as d,WebGLCoordinateSystem as c,WebGPUCoordinateSystem as h,ColorManagement as p,SRGBTransfer as g,NoToneMapping as m,StaticDrawUsage as f,InterleavedBufferAttribute as y,InterleavedBuffer as b,DynamicDrawUsage as x,NoColorSpace as T,log as _,warnOnce as v,Texture as N,UnsignedIntType as S,IntType as R,Compatibility as E,LessCompare as A,NearestFilter as w,Sphere as C,BackSide as M,DoubleSide as B,Euler as F,CubeTexture as L,CubeReflectionMapping as P,CubeRefractionMapping as D,TangentSpaceNormalMap as U,NoNormalPacking as I,NormalRGPacking as O,NormalGAPacking as V,ObjectSpaceNormalMap as k,RGFormat as G,RED_GREEN_RGTC2_Format as $,RG11_EAC_Format as z,InstancedBufferAttribute as W,InstancedInterleavedBuffer as H,DataArrayTexture as q,FloatType as j,FramebufferTexture as X,LinearMipmapLinearFilter as K,DepthTexture as Y,Material as Q,LineBasicMaterial as Z,LineDashedMaterial as J,NoBlending as ee,MeshNormalMaterial as te,SRGBColorSpace as re,RenderTarget as se,BoxGeometry as ie,Mesh as ne,Scene as ae,LinearFilter as oe,CubeCamera as ue,EquirectangularReflectionMapping as le,EquirectangularRefractionMapping as de,AddOperation as ce,MixOperation as he,MultiplyOperation as pe,MeshBasicMaterial as ge,MeshLambertMaterial as me,MeshPhongMaterial as fe,DataTexture as ye,HalfFloatType as be,ClampToEdgeWrapping as xe,BufferGeometry as Te,OrthographicCamera as _e,PerspectiveCamera as ve,LinearSRGBColorSpace as Ne,RGBAFormat as Se,CubeUVReflectionMapping as Re,BufferAttribute as Ee,MeshStandardMaterial as Ae,MeshPhysicalMaterial as we,MeshToonMaterial as Ce,MeshMatcapMaterial as Me,SpriteMaterial as Be,PointsMaterial as Fe,ShadowMaterial as Le,Uint32BufferAttribute as Pe,Uint16BufferAttribute as De,DepthStencilFormat as Ue,DepthFormat as Ie,UnsignedInt248Type as Oe,UnsignedByteType as Ve,NormalBlending as ke,SrcAlphaFactor as Ge,OneMinusSrcAlphaFactor as $e,AddEquation as ze,MaterialBlending as We,Plane as He,Object3D as qe,LinearMipMapLinearFilter as je,Float32BufferAttribute as Xe,UVMapping as Ke,GreaterEqualCompare as Ye,LessEqualCompare as Qe,PCFShadowMap as Ze,PCFSoftShadowMap as Je,VSMShadowMap as et,BasicShadowMap as tt,CubeDepthTexture as rt,SphereGeometry as st,LinearMipmapNearestFilter as it,NearestMipmapLinearFilter as nt,Float16BufferAttribute as at,REVISION as ot,ArrayCamera as ut,PlaneGeometry as lt,FrontSide as dt,CustomBlending as ct,ZeroFactor as ht,CylinderGeometry as pt,Quaternion as gt,WebXRController as mt,RAD2DEG as ft,FrustumArray as yt,Frustum as bt,RedIntegerFormat as xt,RedFormat as Tt,ShortType as _t,ByteType as vt,UnsignedShortType as Nt,RGIntegerFormat as St,RGBIntegerFormat as Rt,RGBFormat as Et,RGBAIntegerFormat as At,TimestampQuery as wt,createCanvasElement as Ct,ReverseSubtractEquation as Mt,SubtractEquation as Bt,OneMinusDstAlphaFactor as Ft,OneMinusDstColorFactor as Lt,OneMinusSrcColorFactor as Pt,DstAlphaFactor as Dt,DstColorFactor as Ut,SrcAlphaSaturateFactor as It,SrcColorFactor as Ot,OneFactor as Vt,CullFaceNone as kt,CullFaceBack as Gt,CullFaceFront as $t,MultiplyBlending as zt,SubtractiveBlending as Wt,AdditiveBlending as Ht,NotEqualDepth as qt,GreaterDepth as jt,GreaterEqualDepth as Xt,EqualDepth as Kt,LessEqualDepth as Yt,LessDepth as Qt,AlwaysDepth as Zt,NeverDepth as Jt,ReversedDepthFuncs as er,UnsignedShort4444Type as tr,UnsignedShort5551Type as rr,UnsignedInt5999Type as sr,UnsignedInt101111Type as ir,AlphaFormat as nr,RGB_S3TC_DXT1_Format as ar,RGBA_S3TC_DXT1_Format as or,RGBA_S3TC_DXT3_Format as ur,RGBA_S3TC_DXT5_Format as lr,RGB_PVRTC_4BPPV1_Format as dr,RGB_PVRTC_2BPPV1_Format as cr,RGBA_PVRTC_4BPPV1_Format as hr,RGBA_PVRTC_2BPPV1_Format as pr,RGB_ETC1_Format as gr,RGB_ETC2_Format as mr,RGBA_ETC2_EAC_Format as fr,R11_EAC_Format as yr,SIGNED_R11_EAC_Format as br,SIGNED_RG11_EAC_Format as xr,RGBA_ASTC_4x4_Format as Tr,RGBA_ASTC_5x4_Format as _r,RGBA_ASTC_5x5_Format as vr,RGBA_ASTC_6x5_Format as Nr,RGBA_ASTC_6x6_Format as Sr,RGBA_ASTC_8x5_Format as Rr,RGBA_ASTC_8x6_Format as Er,RGBA_ASTC_8x8_Format as Ar,RGBA_ASTC_10x5_Format as wr,RGBA_ASTC_10x6_Format as Cr,RGBA_ASTC_10x8_Format as Mr,RGBA_ASTC_10x10_Format as Br,RGBA_ASTC_12x10_Format as Fr,RGBA_ASTC_12x12_Format as Lr,RGBA_BPTC_Format as Pr,RED_RGTC1_Format as Dr,SIGNED_RED_RGTC1_Format as Ur,SIGNED_RED_GREEN_RGTC2_Format as Ir,MirroredRepeatWrapping as Or,RepeatWrapping as Vr,NearestMipmapNearestFilter as kr,NotEqualCompare as Gr,GreaterCompare as $r,EqualCompare as zr,AlwaysCompare as Wr,NeverCompare as Hr,LinearTransfer as qr,getByteLength as jr,isTypedArray as Xr,NotEqualStencilFunc as Kr,GreaterStencilFunc as Yr,GreaterEqualStencilFunc as Qr,EqualStencilFunc as Zr,LessEqualStencilFunc as Jr,LessStencilFunc as es,AlwaysStencilFunc as ts,NeverStencilFunc as rs,DecrementWrapStencilOp as ss,IncrementWrapStencilOp as is,DecrementStencilOp as ns,IncrementStencilOp as as,InvertStencilOp as os,ReplaceStencilOp as us,ZeroStencilOp as ls,KeepStencilOp as ds,MaxEquation as cs,MinEquation as hs,SpotLight as ps,PointLight as gs,DirectionalLight as ms,RectAreaLight as fs,AmbientLight as ys,HemisphereLight as bs,LightProbe as xs,LinearToneMapping as Ts,ReinhardToneMapping as _s,CineonToneMapping as vs,ACESFilmicToneMapping as Ns,AgXToneMapping as Ss,NeutralToneMapping as Rs,Group as Es,Loader as As,FileLoader as ws,MaterialLoader as Cs,ObjectLoader as Ms}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BatchedMesh,BezierInterpolant,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,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExternalTexture,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateBezier,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,InterpolationSamplingMode,InterpolationSamplingType,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,Path,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RenderTarget3D,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,Timer,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoFrameTexture,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding,getConsoleFunction,setConsoleFunction}from"./three.core.min.js";const Bs=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],Fs=new WeakMap;class Ls{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=Bs,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}needsVelocity(e){const t=e.getMRT();return null!==t&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:r,material:s,object:i}=e;if(t={material:this.getMaterialData(s),geometry:{id:r.id,attributes:this.getAttributesData(r.attributes),indexId:r.index?r.index.id:null,indexVersion:r.index?r.index.version:null,drawRange:{start:r.drawRange.start,count:r.drawRange.count}},worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:r,height:s}=e.context;t.bufferWidth=r,t.bufferHeight=s}t.lights=this.getLightsData(e.lightsNode.getLights()),this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const r in e){const s=e[r];t[r]={id:s.id,version:s.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return!!(e.context.modelViewMatrix||e.context.modelNormalViewMatrix||e.context.getAO||e.context.getShadow)}getMaterialData(e){const t={};for(const r of this.refreshUniforms){const s=e[r];null!=s&&("object"==typeof s&&void 0!==s.clone?!0===s.isTexture?t[r]={id:s.id,version:s.version}:t[r]=s.clone():t[r]=s)}return t}equals(e,t){const{object:r,material:s,geometry:i}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(r.matrixWorld))return n.worldMatrix.copy(r.matrixWorld),!1;const a=n.material;for(const e in a){const t=a[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 a[e]=r,!1}if(a.transmission>0){const{width:t,height:r}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==r)return n.bufferWidth=t,n.bufferHeight=r,!1}const o=n.geometry,u=i.attributes,l=o.attributes,d=Object.keys(l),c=Object.keys(u);if(o.id!==i.id)return o.id=i.id,!1;if(d.length!==c.length)return n.geometry.attributes=this.getAttributesData(u),!1;for(const e of d){const t=l[e],r=u[e];if(void 0===r)return delete l[e],!1;if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}const h=i.index,p=o.indexId,g=o.indexVersion,m=h?h.id:null,f=h?h.version:null;if(p!==m||g!==f)return o.indexId=m,o.indexVersion=f,!1;if(o.drawRange.start!==i.drawRange.start||o.drawRange.count!==i.drawRange.count)return o.drawRange.start=i.drawRange.start,o.drawRange.count=i.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let t=0;t<n.morphTargetInfluences.length;t++)n.morphTargetInfluences[t]!==r.morphTargetInfluences[t]&&(n.morphTargetInfluences[t]=r.morphTargetInfluences[t],e=!0);if(e)return!1}if(n.lights)for(let e=0;e<t.length;e++)if(n.lights[e].map!==t[e].map)return!1;return n.center&&!1===n.center.equals(r.center)?(n.center.copy(r.center),!0):(null!==e.bundle&&(n.version=e.bundle.version),!0)}getLightsData(e){const t=[];for(const r of e)!0===r.isSpotLight&&null!==r.map&&t.push({map:r.map.version});return t}getLights(e,t){if(Fs.has(e)){const r=Fs.get(e);if(r.renderId===t)return r.lightsData}const r=this.getLightsData(e.getLights());return Fs.set(e,{renderId:t,lightsData:r}),r}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||this.needsVelocity(t.renderer))return!0;const{renderId:r}=t;if(this.renderId!==r)return this.renderId=r,!0;const s=!0===e.object.static,i=null!==e.bundle&&!0===e.bundle.static&&this.getRenderObjectData(e).version===e.bundle.version;if(s||i)return!1;const n=this.getLights(e.lightsNode,r);return!0!==this.equals(e,n)}}const Ps=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];class Ds{constructor(e=null){this.isStackTrace=!0,this.stack=function(e){const t=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return e.split("\n").map(e=>{const r=e.match(t);if(!r)return null;const s=r[1]||r[2]||"",i=r[3].split("?")[0],n=parseInt(r[4],10),a=parseInt(r[5],10);return{fn:s,file:i.split("/").pop(),line:n,column:a}}).filter(e=>e&&!Ps.some(t=>t.test(e.file)))}(e||(new Error).stack)}getLocation(){if(0===this.stack.length)return"[Unknown location]";const e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(0===this.stack.length)return e;return`${e}\n${this.stack.map(e=>{const t=`${e.file}:${e.line}:${e.column}`;return e.fn?` at ${e.fn} (${t})`:` at ${t}`}).join("\n")}`}}function Us(e,t=0){let r=3735928559^t,s=1103547991^t;if(e instanceof Array)for(let t,i=0;i<e.length;i++)t=e[i],r=Math.imul(r^t,2654435761),s=Math.imul(s^t,1597334677);else for(let t,i=0;i<e.length;i++)t=e.charCodeAt(i),r=Math.imul(r^t,2654435761),s=Math.imul(s^t,1597334677);return r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),4294967296*(2097151&s)+(r>>>0)}const Is=e=>Us(e),Os=e=>Us(e),Vs=(...e)=>Us(e),ks=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),Gs=new WeakMap;function $s(e){return ks.get(e)}function zs(e){if(/[iu]?vec\d/.test(e))return e.startsWith("ivec")?Int32Array:e.startsWith("uvec")?Uint32Array:Float32Array;if(/mat\d/.test(e))return Float32Array;if(/float/.test(e))return Float32Array;if(/uint/.test(e))return Uint32Array;if(/int/.test(e))return Int32Array;throw new Error(`THREE.NodeUtils: Unsupported type: ${e}`)}function Ws(e){return/float|int|uint/.test(e)?1:/vec2/.test(e)?2:/vec3/.test(e)?3:/vec4/.test(e)||/mat2/.test(e)?4:/mat3/.test(e)?9:/mat4/.test(e)?16:void o(`TSL: Unsupported type: ${e}`,new Ds)}function Hs(e){return/float|int|uint/.test(e)?1:/vec2/.test(e)?2:/vec3/.test(e)?3:/vec4/.test(e)||/mat2/.test(e)?4:/mat3/.test(e)?12:/mat4/.test(e)?16:void o(`TSL: Unsupported type: ${e}`,new Ds)}function qs(e){return/float|int|uint/.test(e)?4:/vec2/.test(e)?8:/vec3/.test(e)||/vec4/.test(e)?16:/mat2/.test(e)?8:/mat3/.test(e)||/mat4/.test(e)?16:void o(`TSL: Unsupported type: ${e}`,new Ds)}function js(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.isMatrix2?"mat2":!0===e.isMatrix3?"mat3":!0===e.isMatrix4?"mat4":!0===e.isColor?"color":e instanceof ArrayBuffer?"ArrayBuffer":null}function Xs(o,...u){const l=o?o.slice(-4):void 0;return 1===u.length&&("vec2"===l?u=[u[0],u[0]]:"vec3"===l?u=[u[0],u[0],u[0]]:"vec4"===l&&(u=[u[0],u[0],u[0],u[0]])),"color"===o?new e(...u):"vec2"===l?new t(...u):"vec3"===l?new r(...u):"vec4"===l?new s(...u):"mat2"===l?new i(...u):"mat3"===l?new n(...u):"mat4"===l?new a(...u):"bool"===o?u[0]||!1:"float"===o||"int"===o||"uint"===o?u[0]||0:"string"===o?u[0]||"":"ArrayBuffer"===o?Qs(u[0]):null}function Ks(e){let t=Gs.get(e);return void 0===t&&(t={},Gs.set(e,t)),t}function Ys(e){let t="";const r=new Uint8Array(e);for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return btoa(t)}function Qs(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0)).buffer}var Zs=Object.freeze({__proto__:null,arrayBufferToBase64:Ys,base64ToArrayBuffer:Qs,getAlignmentFromType:qs,getDataFromObject:Ks,getLengthFromType:Ws,getMemoryLengthFromType:Hs,getTypeFromLength:$s,getTypedArrayFromType:zs,getValueFromType:Xs,getValueType:js,hash:Vs,hashArray:Os,hashString:Is});const Js={VERTEX:"vertex",FRAGMENT:"fragment"},ei={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},ti={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},ri={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},si=["fragment","vertex"],ii=["setup","analyze","generate"],ni=[...si,"compute"],ai=["x","y","z","w"],oi={analyze:"setup",generate:"analyze"};let ui=0;class li extends u{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=ei.NONE,this.updateBeforeType=ei.NONE,this.updateAfterType=ei.NONE,this.uuid=l.generateUUID(),this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:ui++}),this.stackTrace=null,!0===li.captureStackTrace&&(this.stackTrace=new Ds)}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),this}onFrameUpdate(e){return this.onUpdate(e,ei.FRAME)}onRenderUpdate(e){return this.onUpdate(e,ei.RENDER)}onObjectUpdate(e){return this.onUpdate(e,ei.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}_getChildren(e=new Set){const t=[];e.add(this);for(const r of Object.getOwnPropertyNames(this)){const s=this[r];if(!0!==r.startsWith("_")&&!e.has(s))if(!0===Array.isArray(s))for(let e=0;e<s.length;e++){const i=s[e];i&&!0===i.isNode&&t.push({property:r,index:e,childNode:i})}else if(s&&!0===s.isNode)t.push({property:r,childNode:s});else if(s&&Object.getPrototypeOf(s)===Object.prototype)for(const e in s){if(!0===e.startsWith("_"))continue;const i=s[e];i&&!0===i.isNode&&t.push({property:r,index:e,childNode:i})}}return t}getCacheKey(e=!1,t=null){if(!0===(e=e||this.version!==this._cacheKeyVersion)||null===this._cacheKey){null===t&&(t=new Set);const r=[];for(const{property:s,childNode:i}of this._getChildren(t))r.push(Is(s.slice(0,-4)),i.getCacheKey(e,t));this._cacheKey=Vs(Os(r),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}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)}getMemberType(){return"void"}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}getArrayCount(){return null}setup(e){const t=e.getNodeProperties(this);let r=0;for(const e of this.getChildren())t["node"+r++]=e;return t.outputNode||null}analyze(e,t=null){const r=e.increaseUsage(this);if(!0===this.parents){const r=e.getDataFromNode(this,"any");r.stages=r.stages||{},r.stages[e.shaderStage]=r.stages[e.shaderStage]||[],r.stages[e.shaderStage].push(t)}if(1===r){const t=e.getNodeProperties(this);for(const r of Object.values(t))r&&!0===r.isNode&&r.build(e,this)}}generate(e,t){const{outputNode:r}=e.getNodeProperties(this);if(r&&!0===r.isNode)return r.build(e,t)}updateBefore(){d("Abstract function.")}updateAfter(){d("Abstract function.")}update(){d("Abstract function.")}before(e){return null===this._beforeNodes&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){const r=this.getShared(e);if(this!==r)return r.build(e,t);if(null!==this._beforeNodes){const r=this._beforeNodes;this._beforeNodes=null;for(const s of r)s.build(e,t);this._beforeNodes=r}const s=e.getDataFromNode(this);s.buildStages=s.buildStages||{},s.buildStages[e.buildStage]=!0;const i=oi[e.buildStage];if(i&&!0!==s.buildStages[i]){const t=e.getBuildStage();e.setBuildStage(i),this.build(e),e.setBuildStage(t)}e.addChain(this);let n=null;const a=e.getBuildStage();if("setup"===a){e.addNode(this),this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){t.initialized=!0,t.outputNode=this.setup(e)||t.outputNode||null;for(const r of Object.values(t))if(r&&!0===r.isNode){if(!0===r.parents){const t=e.getNodeProperties(r);t.parents=t.parents||[],t.parents.push(this)}r.build(e)}e.addSequentialNode(this)}n=t.outputNode}else if("analyze"===a)this.analyze(e,t);else if("generate"===a){if(this.generate.length<2){const r=this.getNodeType(e),s=e.getDataFromNode(this);n=s.snippet,void 0===n?void 0===s.generated?(s.generated=!0,n=this.generate(e)||"",s.snippet=n):(d("Node: Recursion detected.",this),n="/* Recursion detected. */"):void 0!==s.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),n=e.format(n,r,t)}else n=this.generate(e,t)||"";""===n&&null!==t&&"void"!==t&&"OutputType"!==t&&(o(`TSL: Invalid generated code, expected a "${t}".`),n=e.generateConst(t))}return e.removeChain(this),n}getSerializeChildren(){return this._getChildren()}serialize(e){const t=this.getSerializeChildren(),r={};for(const{property:s,index:i,childNode:n}of t)void 0!==i?(void 0===r[s]&&(r[s]=Number.isInteger(i)?[]:{}),r[s][i]=n.toJSON(e.meta).uuid):r[s]=n.toJSON(e.meta).uuid;Object.keys(r).length>0&&(e.inputNodes=r)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const r in e.inputNodes)if(Array.isArray(e.inputNodes[r])){const s=[];for(const i of e.inputNodes[r])s.push(t[i]);this[r]=s}else if("object"==typeof e.inputNodes[r]){const s={};for(const i in e.inputNodes[r]){const n=e.inputNodes[r][i];s[i]=t[n]}this[r]=s}else{const s=e.inputNodes[r];this[r]=t[s]}}}toJSON(e){const{uuid:t,type:r}=this,s=void 0===e||"string"==typeof e;s&&(e={textures:{},images:{},nodes:{}});let i=e.nodes[t];function n(e){const t=[];for(const r in e){const s=e[r];delete s.metadata,t.push(s)}return t}if(void 0===i&&(i={uuid:t,type:r,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},!0!==s&&(e.nodes[i.uuid]=i),this.serialize(i),delete i.meta),s){const t=n(e.textures),r=n(e.images),s=n(e.nodes);t.length>0&&(i.textures=t),r.length>0&&(i.images=r),s.length>0&&(i.nodes=s)}return i}}li.captureStackTrace=!1;class di extends li{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)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){const t=this.indexNode.getNodeType(e);return`${this.node.build(e)}[ ${this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint")} ]`}}class ci extends li{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let r=null;for(const s of this.convertTo.split("|"))null!==r&&e.getTypeLength(t)!==e.getTypeLength(s)||(r=s);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const r=this.node,s=this.getNodeType(e),i=r.build(e,s);return e.format(i,s,t)}}class hi extends li{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const r=e.getVectorType(this.getNodeType(e,t)),s=e.getDataFromNode(this);if(void 0!==s.propertyName)return e.format(s.propertyName,r,t);if("void"!==r&&"void"!==t&&this.hasDependencies(e)){const i=super.build(e,r),n=e.getVarFromNode(this,null,r),a=e.getPropertyName(n);return e.addLineFlowCode(`${a} = ${i}`,this),s.snippet=i,s.propertyName=a,e.format(s.propertyName,r,t)}}return super.build(e,t)}}class pi extends hi{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,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){const r=this.getNodeType(e),s=e.getTypeLength(r),i=this.nodes,n=e.getComponentType(r),a=[];let u=0;for(const t of i){if(u>=s){o(`TSL: Length of parameters exceeds maximum length of function '${r}()' type.`,this.stackTrace);break}let i,l=t.getNodeType(e),d=e.getTypeLength(l);u+d>s&&(o(`TSL: Length of '${r}()' data exceeds maximum length of output type.`,this.stackTrace),d=s-u,l=e.getTypeFromLength(d)),u+=d,i=t.build(e,l);if(e.getComponentType(l)!==n){const t=e.getTypeFromLength(d,n);i=e.format(i,l,t)}a.push(i)}const l=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(l,r,t)}}const gi=ai.join("");class mi extends li{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(ai.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))}getScope(){return this.node.getScope()}generate(e,t){const r=this.node,s=e.getTypeLength(r.getNodeType(e));let i=null;if(s>1){let n=null;this.getVectorLength()>=s&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const a=r.build(e,n);i=this.components.length===s&&this.components===gi.slice(0,this.components.length)?e.format(a,n,t):e.format(`${a}.${this.components}`,this.getNodeType(e),t)}else i=r.build(e,t);return i}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class fi extends hi{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:r,targetNode:s}=this,i=this.getNodeType(e),n=e.getComponentType(s.getNodeType(e)),a=e.getTypeFromLength(r.length,n),o=s.build(e,a),u=t.build(e,i),l=e.getTypeLength(i),d=[];for(let e=0;e<l;e++){const t=ai[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(u+"."+t)}return`${e.getType(i)}( ${d.join(", ")} )`}}class yi extends hi{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:r}=this,s=this.getNodeType(e),i=r.build(e),n=e.getVarFromNode(this),a=e.getPropertyName(n);e.addLineFlowCode(a+" = "+i,this);const o=e.getTypeLength(s),u=[];let l=0;for(let e=0;e<o;e++){const r=ai[e];r===t[l]?(u.push("1.0 - "+a+"."+r),l++):u.push(a+"."+r)}return`${e.getType(s)}( ${u.join(", ")} )`}}class bi extends li{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?js(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=js(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Ys(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Xs(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){d("Abstract function.")}}const xi=/float|u?int/;class Ti extends bi{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 r=this.getNodeType(e);return xi.test(r)&&xi.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class _i extends li{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return(!this.structNode.isMemberNode||!1!==this.structNode.hasMember(e))&&"void"!==this.structNode.getMemberType(e,this.property)}getNodeType(e){return!1===this.hasMember(e)?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(!1===this.hasMember(e))return"float";const r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}generate(e){if(!1===this.hasMember(e)){d(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);const t=this.getNodeType(e);return e.generateConst(t)}return this.structNode.build(e)+"."+this.property}}let vi=null;const Ni=new Map;function Si(e,t){if(Ni.has(e))d(`TSL: Redefinition of method chaining '${e}'.`);else{if("function"!=typeof t)throw new Error(`THREE.TSL: Node element ${e} is not a function`);Ni.set(e,t),"assign"!==e&&(li.prototype[e]=function(...e){return this.isStackNode?this.addToStack(t(...e)):t(this,...e)},li.prototype[e+"Assign"]=function(...e){return this.isStackNode?this.assign(e[0],t(...e)):this.assign(t(this,...e))})}}const Ri=e=>(e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"))(e).split("").sort().join("");li.prototype.assign=function(...e){if(!0!==this.isStackNode)return null!==vi?vi.assign(this,...e):o("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new Ds),this;{const t=Ni.get("assign");return this.addToStack(t(...e))}},li.prototype.toVarIntent=function(){return this},li.prototype.get=function(e){return new _i(this,e)};const Ei={};function Ai(e,t,r){Ei[e]=Ei[t]=Ei[r]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new mi(this,e),this._cache[e]=t),t},set(t){this[e].assign(Ji(t))}};const s=e.toUpperCase(),i=t.toUpperCase(),n=r.toUpperCase();li.prototype["set"+s]=li.prototype["set"+i]=li.prototype["set"+n]=function(t){const r=Ri(e);return new fi(this,r,Ji(t))},li.prototype["flip"+s]=li.prototype["flip"+i]=li.prototype["flip"+n]=function(){const t=Ri(e);return new yi(this,t)}}const wi=["x","y","z","w"],Ci=["r","g","b","a"],Mi=["s","t","p","q"];for(let e=0;e<4;e++){let t=wi[e],r=Ci[e],s=Mi[e];Ai(t,r,s);for(let i=0;i<4;i++){t=wi[e]+wi[i],r=Ci[e]+Ci[i],s=Mi[e]+Mi[i],Ai(t,r,s);for(let n=0;n<4;n++){t=wi[e]+wi[i]+wi[n],r=Ci[e]+Ci[i]+Ci[n],s=Mi[e]+Mi[i]+Mi[n],Ai(t,r,s);for(let a=0;a<4;a++)t=wi[e]+wi[i]+wi[n]+wi[a],r=Ci[e]+Ci[i]+Ci[n]+Ci[a],s=Mi[e]+Mi[i]+Mi[n]+Mi[a],Ai(t,r,s)}}}for(let e=0;e<32;e++)Ei[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new di(this,new Ti(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(Ji(t))}};Object.defineProperties(li.prototype,Ei);const Bi=new WeakMap,Fi=function(e,t=null){for(const r in e)e[r]=Ji(e[r],t);return e},Li=function(e,t=null){const r=e.length;for(let s=0;s<r;s++)e[s]=Ji(e[s],t);return e},Pi=function(e,t=null,r=null,s=null){function i(e){return null!==s?(e=Ji(Object.assign(e,s)),!0===s.intent&&(e=e.toVarIntent())):e=Ji(e),e}let n,a,u,l=t;function d(t){let r;return r=l?/[a-z]/i.test(l)?l+"()":l:e.type,void 0!==a&&t.length<a?(o(`TSL: "${r}" parameter length is less than minimum required.`,new Ds),t.concat(new Array(a-t.length).fill(0))):void 0!==u&&t.length>u?(o(`TSL: "${r}" parameter length exceeds limit.`,new Ds),t.slice(0,u)):t}return null===t?n=(...t)=>i(new e(...rn(d(t)))):null!==r?(r=Ji(r),n=(...s)=>i(new e(t,...rn(d(s)),r))):n=(...r)=>i(new e(t,...rn(d(r)))),n.setParameterLength=(...e)=>(1===e.length?a=u=e[0]:2===e.length&&([a,u]=e),n),n.setName=e=>(l=e,n),n},Di=function(e,...t){return new e(...rn(t))};class Ui extends li{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){const{shaderNode:t,rawInputs:r}=this,s=e.getNodeProperties(t),i=e.getClosestSubBuild(t.subBuilds)||"",n=i||"default";if(s[n])return s[n];const a=e.subBuildFn,o=e.fnCall;e.subBuildFn=i,e.fnCall=this;let u=null;if(t.layout){let s=Bi.get(e.constructor);void 0===s&&(s=new WeakMap,Bi.set(e.constructor,s));let i=s.get(t);void 0===i&&(i=Ji(e.buildFunctionNode(t)),s.set(t,i)),e.addInclude(i);const n=r?function(e){let t;tn(e);t=e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)?[...e]:e[0];return t}(r):null;u=Ji(i.call(n))}else{const s=new Proxy(e,{get:(e,t,r)=>{let s;return s=Symbol.iterator===t?function*(){yield}:Reflect.get(e,t,r),s}}),i=r?function(e){let t=0;return tn(e),new Proxy(e,{get:(r,s,i)=>{let n;if("length"===s)return n=e.length,n;if(Symbol.iterator===s)n=function*(){for(const t of e)yield Ji(t)};else{if(e.length>0)if(Object.getPrototypeOf(e[0])===Object.prototype){const r=e[0];n=void 0===r[s]?r[t++]:Reflect.get(r,s,i)}else e[0]instanceof li&&(n=void 0===e[s]?e[t++]:Reflect.get(e,s,i));else n=Reflect.get(r,s,i);n=Ji(n)}return n}})}(r):null,n=Array.isArray(r)?r.length>0:null!==r,a=t.jsFunc,o=n||a.length>1?a(i,s):a(s);u=Ji(o)}return e.subBuildFn=a,e.fnCall=o,t.once&&(s[n]=u),u}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){const t=e.getNodeProperties(this),r=e.getSubBuildOutput(this);return t[r]=t[r]||this.setupOutput(e),t[r].subBuild=e.getClosestSubBuild(this),t[r]}build(e,t=null){let r=null;const s=e.getBuildStage(),i=e.getNodeProperties(this),n=e.getSubBuildOutput(this),a=this.getOutputNode(e),o=e.fnCall;if(e.fnCall=this,"setup"===s){const t=e.getSubBuildProperty("initialized",this);if(!0!==i[t]&&(i[t]=!0,i[n]=this.getOutputNode(e),i[n].build(e),this.shaderNode.subBuilds))for(const t of e.chaining){const r=e.getDataFromNode(t,"any");r.subBuilds=r.subBuilds||new Set;for(const e of this.shaderNode.subBuilds)r.subBuilds.add(e)}r=i[n]}else"analyze"===s?a.build(e,t):"generate"===s&&(r=a.build(e,t)||"");return e.fnCall=o,r}}class Ii extends li{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new Ui(this,e)}setup(){return this.call()}}const Oi=[!1,!0],Vi=[0,1,2,3],ki=[-1,-2],Gi=[.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],$i=new Map;for(const e of Oi)$i.set(e,new Ti(e));const zi=new Map;for(const e of Vi)zi.set(e,new Ti(e,"uint"));const Wi=new Map([...zi].map(e=>new Ti(e.value,"int")));for(const e of ki)Wi.set(e,new Ti(e,"int"));const Hi=new Map([...Wi].map(e=>new Ti(e.value)));for(const e of Gi)Hi.set(e,new Ti(e));for(const e of Gi)Hi.set(-e,new Ti(-e));const qi={bool:$i,uint:zi,ints:Wi,float:Hi},ji=new Map([...$i,...Hi]),Xi=(e,t)=>ji.has(e)?ji.get(e):!0===e.isNode?e:new Ti(e,t),Ki=function(e,t=null){return(...r)=>{for(const t of r)if(void 0===t)return o(`TSL: Invalid parameter for the type "${e}".`,new Ds),new Ti(0,e);if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every(e=>{const t=typeof e;return"object"!==t&&"function"!==t}))&&(r=[Xs(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return en(t.get(r[0]));if(1===r.length){const t=Xi(r[0],e);return t.nodeType===e?en(t):en(new ci(t,e))}const s=r.map(e=>Xi(e));return en(new pi(s,e))}},Yi=e=>"object"==typeof e&&null!==e?e.value:e,Qi=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function Zi(e,t){return new Ii(e,t)}const Ji=(e,t=null)=>function(e,t=null){const r=js(e);return"node"===r?e:null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?Ji(Xi(e,t)):"shader"===r?e.isFn?e:ln(e):e}(e,t),en=(e,t=null)=>Ji(e,t).toVarIntent(),tn=(e,t=null)=>new Fi(e,t),rn=(e,t=null)=>new Li(e,t),sn=(e,t=null,r=null,s=null)=>new Pi(e,t,r,s),nn=(e,...t)=>new Di(e,...t),an=(e,t=null,r=null,s={})=>new Pi(e,t,r,{...s,intent:!0});let on=0;class un extends li{constructor(e,t=null){super();let r=null;null!==t&&("object"==typeof t?r=t.return:("string"==typeof t?r=t:o("TSL: Invalid layout type.",new Ds),t=null)),this.shaderNode=new Zi(e,r),null!==t&&this.setLayout(t),this.isFn=!0}setLayout(e){const t=this.shaderNode.nodeType;if("object"!=typeof e.inputs){const r={name:"fn"+on++,type:t,inputs:[]};for(const t in e)"return"!==t&&r.inputs.push({name:t,type:e[t]});e=r}return this.shaderNode.setLayout(e),this}getNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){const t=this.shaderNode.call(e);return"void"===this.shaderNode.nodeType&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){const t=this.getNodeType(e);return o('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}}function ln(e,t=null){const r=new un(e,t);return new Proxy(()=>{},{apply:(e,t,s)=>r.call(...s),get:(e,t,s)=>Reflect.get(r,t,s),set:(e,t,s,i)=>Reflect.set(r,t,s,i)})}const dn=e=>{vi=e},cn=()=>vi,hn=(...e)=>vi.If(...e);function pn(e){return vi&&vi.addToStack(e),e}Si("toStack",pn);const gn=new Ki("color"),mn=new Ki("float",qi.float),fn=new Ki("int",qi.ints),yn=new Ki("uint",qi.uint),bn=new Ki("bool",qi.bool),xn=new Ki("vec2"),Tn=new Ki("ivec2"),_n=new Ki("uvec2"),vn=new Ki("bvec2"),Nn=new Ki("vec3"),Sn=new Ki("ivec3"),Rn=new Ki("uvec3"),En=new Ki("bvec3"),An=new Ki("vec4"),wn=new Ki("ivec4"),Cn=new Ki("uvec4"),Mn=new Ki("bvec4"),Bn=new Ki("mat2"),Fn=new Ki("mat3"),Ln=new Ki("mat4");Si("toColor",gn),Si("toFloat",mn),Si("toInt",fn),Si("toUint",yn),Si("toBool",bn),Si("toVec2",xn),Si("toIVec2",Tn),Si("toUVec2",_n),Si("toBVec2",vn),Si("toVec3",Nn),Si("toIVec3",Sn),Si("toUVec3",Rn),Si("toBVec3",En),Si("toVec4",An),Si("toIVec4",wn),Si("toUVec4",Cn),Si("toBVec4",Mn),Si("toMat2",Bn),Si("toMat3",Fn),Si("toMat4",Ln);const Pn=sn(di).setParameterLength(2),Dn=(e,t)=>new ci(Ji(e),t);Si("element",Pn),Si("convert",Dn);Si("append",e=>(d("TSL: .append() has been renamed to .toStack().",new Ds),pn(e)));class Un extends li{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1){super(e),this.name=t,this.varying=r,this.isPropertyNode=!0,this.global=!0}customCacheKey(){return Is(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}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 In=(e,t)=>new Un(e,t),On=(e,t)=>new Un(e,t,!0),Vn=nn(Un,"vec4","DiffuseColor"),kn=nn(Un,"vec3","DiffuseContribution"),Gn=nn(Un,"vec3","EmissiveColor"),$n=nn(Un,"float","Roughness"),zn=nn(Un,"float","Metalness"),Wn=nn(Un,"float","Clearcoat"),Hn=nn(Un,"float","ClearcoatRoughness"),qn=nn(Un,"vec3","Sheen"),jn=nn(Un,"float","SheenRoughness"),Xn=nn(Un,"float","Iridescence"),Kn=nn(Un,"float","IridescenceIOR"),Yn=nn(Un,"float","IridescenceThickness"),Qn=nn(Un,"float","AlphaT"),Zn=nn(Un,"float","Anisotropy"),Jn=nn(Un,"vec3","AnisotropyT"),ea=nn(Un,"vec3","AnisotropyB"),ta=nn(Un,"color","SpecularColor"),ra=nn(Un,"color","SpecularColorBlended"),sa=nn(Un,"float","SpecularF90"),ia=nn(Un,"float","Shininess"),na=nn(Un,"vec4","Output"),aa=nn(Un,"float","dashSize"),oa=nn(Un,"float","gapSize"),ua=nn(Un,"float","pointWidth"),la=nn(Un,"float","IOR"),da=nn(Un,"float","Transmission"),ca=nn(Un,"float","Thickness"),ha=nn(Un,"float","AttenuationDistance"),pa=nn(Un,"color","AttenuationColor"),ga=nn(Un,"float","Dispersion");class ma extends li{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1){super("string"),this.name=e,this.shared=t,this.order=r,this.isUniformGroup=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const fa=e=>new ma(e),ya=(e,t=0)=>new ma(e,!0,t),ba=ya("frame"),xa=ya("render"),Ta=fa("object");class _a extends bi{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Ta}setName(e){return this.name=e,this}label(e){return d('TSL: "label()" has been deprecated. Use "setName()" instead.',new Ds),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){return e=e.bind(this),super.onUpdate(t=>{const r=e(t,this);void 0!==r&&(this.value=r)},t)}getInputType(e){let t=super.getInputType(e);return"bool"===t&&(t="uint"),t}generate(e,t){const r=this.getNodeType(e),s=this.getUniformHash(e);let i=e.getNodeFromHash(s);void 0===i&&(e.setHashNode(this,s),i=this);const n=i.getInputType(e),a=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.nodeName),o=e.getPropertyName(a);void 0!==e.context.nodeName&&delete e.context.nodeName;let u=o;if("bool"===r){const t=e.getDataFromNode(this);let s=t.propertyName;if(void 0===s){const i=e.getVarFromNode(this,null,"bool");s=e.getPropertyName(i),t.propertyName=s,u=e.format(o,n,r),e.addLineFlowCode(`${s} = ${u}`,this)}u=s}return e.format(u,r,t)}}const va=(e,t)=>{const r=Qi(t||e);if(r===e&&(e=Xs(r)),e&&!0===e.isNode){let t=e.value;e.traverse(e=>{!0===e.isConstNode&&(t=e.value)}),e=t}return new _a(e,r)};class Na extends hi{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getArrayCount(){return this.count}getNodeType(e){return null===this.nodeType?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return null===this.nodeType?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){const t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}const Sa=(...e)=>{let t;if(1===e.length){const r=e[0];t=new Na(null,r.length,r)}else{const r=e[0],s=e[1];t=new Na(r,s)}return Ji(t)};Si("toArray",(e,t)=>Sa(Array(t).fill(e)));class Ra extends hi{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}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 r=e.getTypeLength(t.node.getNodeType(e));return ai.join("").slice(0,r)!==t.components}return!1}setup(e){const{targetNode:t,sourceNode:r}=this,s=t.getScope();e.getDataFromNode(s).assign=!0;const i=e.getNodeProperties(this);i.sourceNode=r,i.targetNode=t.context({assign:!0})}generate(e,t){const{targetNode:r,sourceNode:s}=e.getNodeProperties(this),i=this.needsSplitAssign(e),n=r.build(e),a=r.getNodeType(e),o=s.build(e,a),u=s.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=n);else if(i){const s=e.getVarFromNode(this,null,a),i=e.getPropertyName(s);e.addLineFlowCode(`${i} = ${o}`,this);const u=r.node,l=u.node.context({assign:!0}).build(e);for(let t=0;t<u.components.length;t++){const r=u.components[t];e.addLineFlowCode(`${l}.${r} = ${i}[ ${t} ]`,this)}"void"!==t&&(d=n)}else d=`${n} = ${o}`,"void"!==t&&"void"!==u||(e.addLineFlowCode(d,this),"void"!==t&&(d=n));return l.initialized=!0,e.format(d,a,t)}}const Ea=sn(Ra).setParameterLength(2);Si("assign",Ea);class Aa extends hi{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)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){const t=[],r=this.functionNode,s=r.getInputs(e),i=this.parameters,n=(t,r)=>{const s=r.type;let i;return i="pointer"===s?"&"+t.build(e):t.build(e,s),i};if(Array.isArray(i)){if(i.length>s.length)o("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),i.length=s.length;else if(i.length<s.length)for(o("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");i.length<s.length;)i.push(mn(0));for(let e=0;e<i.length;e++)t.push(n(i[e],s[e]))}else for(const e of s){const r=i[e.name];void 0!==r?t.push(n(r,e)):(o(`TSL: Input '${e.name}' not found in 'Fn()'.`),t.push(n(mn(0),e)))}return`${r.build(e,"property")}( ${t.join(", ")} )`}}const wa=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?rn(t):tn(t[0]),new Aa(Ji(e),t));Si("call",wa);const Ca={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class Ma extends hi{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new Ma(e,t,r);for(let t=0;t<s.length-1;t++)i=new Ma(e,i,s[t]);t=i,r=s[s.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(Ca[this.op],t)}getNodeType(e,t=null){const r=this.op,s=this.aNode,i=this.bNode,n=s.getNodeType(e),a=i?i.getNodeType(e):null;if("void"===n||"void"===a)return t||"void";if("%"===r)return n;if("~"===r||"&"===r||"|"===r||"^"===r||">>"===r||"<<"===r)return e.getIntegerType(n);if("!"===r||"&&"===r||"||"===r||"^^"===r)return"bool";if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r){const t=Math.max(e.getTypeLength(n),e.getTypeLength(a));return t>1?`bvec${t}`:"bool"}if(e.isMatrix(n)){if("float"===a)return n;if(e.isVector(a))return e.getVectorFromMatrix(n);if(e.isMatrix(a))return n}else if(e.isMatrix(a)){if("float"===n)return a;if(e.isVector(n))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(n)?a:n}generate(e,t){const r=this.op,{aNode:s,bNode:i}=this,n=this.getNodeType(e,t);let a=null,o=null;"void"!==n?(a=s.getNodeType(e),o=i?i.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r||"!="===r?e.isVector(a)?o=a:e.isVector(o)?a=o:a!==o&&(a=o="float"):">>"===r||"<<"===r?(a=n,o=e.changeComponentType(o,"uint")):"%"===r?(a=n,o=e.isInteger(a)&&e.isInteger(o)?o:a):e.isMatrix(a)?"float"===o?o="float":e.isVector(o)?o=e.getVectorFromMatrix(a):e.isMatrix(o)||(a=o=n):a=e.isMatrix(o)?"float"===a?"float":e.isVector(a)?e.getVectorFromMatrix(o):o=n:o=n):a=o=n;const u=s.build(e,a),l=i?i.build(e,o):null,d=e.getFunctionOperator(r);if("void"!==t){const s=e.renderer.coordinateSystem===c;if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r)return s&&e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} ${r} ${l} )`,n,t);if("%"===r)return e.isInteger(o)?e.format(`( ${u} % ${l} )`,n,t):e.format(`${this.getOperatorMethod(e,n)}( ${u}, ${l} )`,n,t);if("!"===r||"~"===r)return e.format(`(${r}${u})`,a,t);if(d)return e.format(`${d}( ${u}, ${l} )`,n,t);if(e.isMatrix(a)&&"float"===o)return e.format(`( ${l} ${r} ${u} )`,n,t);if("float"===a&&e.isMatrix(o))return e.format(`${u} ${r} ${l}`,n,t);{let i=`( ${u} ${r} ${l} )`;return!s&&"bool"===n&&e.isVector(a)&&e.isVector(o)&&(i=`all${i}`),e.format(i,n,t)}}if("void"!==a)return d?e.format(`${d}( ${u}, ${l} )`,n,t):e.isMatrix(a)&&"float"===o?e.format(`${l} ${r} ${u}`,n,t):e.format(`${u} ${r} ${l}`,n,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Ba=an(Ma,"+").setParameterLength(2,1/0).setName("add"),Fa=an(Ma,"-").setParameterLength(2,1/0).setName("sub"),La=an(Ma,"*").setParameterLength(2,1/0).setName("mul"),Pa=an(Ma,"/").setParameterLength(2,1/0).setName("div"),Da=an(Ma,"%").setParameterLength(2).setName("mod"),Ua=an(Ma,"==").setParameterLength(2).setName("equal"),Ia=an(Ma,"!=").setParameterLength(2).setName("notEqual"),Oa=an(Ma,"<").setParameterLength(2).setName("lessThan"),Va=an(Ma,">").setParameterLength(2).setName("greaterThan"),ka=an(Ma,"<=").setParameterLength(2).setName("lessThanEqual"),Ga=an(Ma,">=").setParameterLength(2).setName("greaterThanEqual"),$a=an(Ma,"&&").setParameterLength(2,1/0).setName("and"),za=an(Ma,"||").setParameterLength(2,1/0).setName("or"),Wa=an(Ma,"!").setParameterLength(1).setName("not"),Ha=an(Ma,"^^").setParameterLength(2).setName("xor"),qa=an(Ma,"&").setParameterLength(2).setName("bitAnd"),ja=an(Ma,"~").setParameterLength(1).setName("bitNot"),Xa=an(Ma,"|").setParameterLength(2).setName("bitOr"),Ka=an(Ma,"^").setParameterLength(2).setName("bitXor"),Ya=an(Ma,"<<").setParameterLength(2).setName("shiftLeft"),Qa=an(Ma,">>").setParameterLength(2).setName("shiftRight"),Za=ln(([e])=>(e.addAssign(1),e)),Ja=ln(([e])=>(e.subAssign(1),e)),eo=ln(([e])=>{const t=fn(e).toConst();return e.addAssign(1),t}),to=ln(([e])=>{const t=fn(e).toConst();return e.subAssign(1),t});Si("add",Ba),Si("sub",Fa),Si("mul",La),Si("div",Pa),Si("mod",Da),Si("equal",Ua),Si("notEqual",Ia),Si("lessThan",Oa),Si("greaterThan",Va),Si("lessThanEqual",ka),Si("greaterThanEqual",Ga),Si("and",$a),Si("or",za),Si("not",Wa),Si("xor",Ha),Si("bitAnd",qa),Si("bitNot",ja),Si("bitOr",Xa),Si("bitXor",Ka),Si("shiftLeft",Ya),Si("shiftRight",Qa),Si("incrementBefore",Za),Si("decrementBefore",Ja),Si("increment",eo),Si("decrement",to);const ro=(e,t)=>(d('