UNPKG

three

Version:

JavaScript 3D library

6 lines 638 kB
/** * @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 A,LessCompare as E,LessEqualCompare as w,GreaterCompare as C,GreaterEqualCompare as M,NearestFilter as B,Sphere as L,BackSide as F,DoubleSide as P,CubeTexture as D,CubeReflectionMapping as U,CubeRefractionMapping as I,TangentSpaceNormalMap as O,NoNormalPacking as V,NormalRGPacking as k,NormalGAPacking as G,ObjectSpaceNormalMap as z,RGFormat as $,RED_GREEN_RGTC2_Format as W,RG11_EAC_Format as H,InstancedBufferAttribute as q,InstancedInterleavedBuffer as j,DataArrayTexture as X,FloatType as K,FramebufferTexture as Q,LinearMipmapLinearFilter as Y,DepthTexture as Z,Material as J,LineBasicMaterial as ee,LineDashedMaterial as te,NoBlending as re,MeshNormalMaterial as se,SRGBColorSpace as ie,RenderTarget as ne,BoxGeometry as ae,Mesh as oe,Scene as ue,LinearFilter as le,CubeCamera as de,EquirectangularReflectionMapping as ce,EquirectangularRefractionMapping as he,AddOperation as pe,MixOperation as ge,MultiplyOperation as me,MeshBasicMaterial as fe,MeshLambertMaterial as ye,MeshPhongMaterial as be,DataTexture as xe,HalfFloatType as Te,ClampToEdgeWrapping as _e,BufferGeometry as ve,OrthographicCamera as Ne,PerspectiveCamera as Se,LinearSRGBColorSpace as Re,RGBAFormat as Ae,CubeUVReflectionMapping as Ee,BufferAttribute as we,MeshStandardMaterial as Ce,MeshPhysicalMaterial as Me,MeshToonMaterial as Be,MeshMatcapMaterial as Le,SpriteMaterial as Fe,PointsMaterial as Pe,ShadowMaterial as De,Uint32BufferAttribute as Ue,Uint16BufferAttribute as Ie,ByteType as Oe,UnsignedByteType as Ve,ShortType as ke,UnsignedShortType as Ge,AlphaFormat as ze,RedFormat as $e,RedIntegerFormat as We,DepthFormat as He,DepthStencilFormat as qe,RGIntegerFormat as je,RGBFormat as Xe,RGBIntegerFormat as Ke,UnsignedShort4444Type as Qe,UnsignedShort5551Type as Ye,UnsignedInt248Type as Ze,UnsignedInt5999Type as Je,UnsignedInt101111Type as et,NormalBlending as tt,SrcAlphaFactor as rt,OneMinusSrcAlphaFactor as st,AddEquation as it,MaterialBlending as nt,Object3D as at,LinearMipMapLinearFilter as ot,Plane as ut,Float32BufferAttribute as lt,UVMapping as dt,PCFShadowMap as ct,PCFSoftShadowMap as ht,VSMShadowMap as pt,BasicShadowMap as gt,CubeDepthTexture as mt,SphereGeometry as ft,LinearMipmapNearestFilter as yt,NearestMipmapLinearFilter as bt,Float16BufferAttribute as xt,yieldToMain as Tt,REVISION as _t,ArrayCamera as vt,PlaneGeometry as Nt,FrontSide as St,CustomBlending as Rt,ZeroFactor as At,CylinderGeometry as Et,Quaternion as wt,WebXRController as Ct,RAD2DEG as Mt,FrustumArray as Bt,Frustum as Lt,RGBAIntegerFormat as Ft,TimestampQuery as Pt,createCanvasElement as Dt,ReverseSubtractEquation as Ut,SubtractEquation as It,OneMinusDstAlphaFactor as Ot,OneMinusDstColorFactor as Vt,OneMinusSrcColorFactor as kt,DstAlphaFactor as Gt,DstColorFactor as zt,SrcAlphaSaturateFactor as $t,SrcColorFactor as Wt,OneFactor as Ht,CullFaceNone as qt,CullFaceBack as jt,CullFaceFront as Xt,MultiplyBlending as Kt,SubtractiveBlending as Qt,AdditiveBlending as Yt,NotEqualDepth as Zt,GreaterDepth as Jt,GreaterEqualDepth as er,EqualDepth as tr,LessEqualDepth as rr,LessDepth as sr,AlwaysDepth as ir,NeverDepth as nr,ReversedDepthFuncs as ar,RGB_S3TC_DXT1_Format as or,RGBA_S3TC_DXT1_Format as ur,RGBA_S3TC_DXT3_Format as lr,RGBA_S3TC_DXT5_Format as dr,RGB_PVRTC_4BPPV1_Format as cr,RGB_PVRTC_2BPPV1_Format as hr,RGBA_PVRTC_4BPPV1_Format as pr,RGBA_PVRTC_2BPPV1_Format as gr,RGB_ETC1_Format as mr,RGB_ETC2_Format as fr,RGBA_ETC2_EAC_Format as yr,R11_EAC_Format as br,SIGNED_R11_EAC_Format as xr,SIGNED_RG11_EAC_Format as Tr,RGBA_ASTC_4x4_Format as _r,RGBA_ASTC_5x4_Format as vr,RGBA_ASTC_5x5_Format as Nr,RGBA_ASTC_6x5_Format as Sr,RGBA_ASTC_6x6_Format as Rr,RGBA_ASTC_8x5_Format as Ar,RGBA_ASTC_8x6_Format as Er,RGBA_ASTC_8x8_Format as wr,RGBA_ASTC_10x5_Format as Cr,RGBA_ASTC_10x6_Format as Mr,RGBA_ASTC_10x8_Format as Br,RGBA_ASTC_10x10_Format as Lr,RGBA_ASTC_12x10_Format as Fr,RGBA_ASTC_12x12_Format as Pr,RGBA_BPTC_Format as Dr,RED_RGTC1_Format as Ur,SIGNED_RED_RGTC1_Format as Ir,SIGNED_RED_GREEN_RGTC2_Format as Or,MirroredRepeatWrapping as Vr,RepeatWrapping as kr,NearestMipmapNearestFilter as Gr,NotEqualCompare as zr,EqualCompare as $r,AlwaysCompare as Wr,NeverCompare as Hr,LinearTransfer as qr,getByteLength as jr,isTypedArray as Xr,NotEqualStencilFunc as Kr,GreaterStencilFunc as Qr,GreaterEqualStencilFunc as Yr,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 As,Loader as Es,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,Euler,ExternalTexture,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HTMLTexture,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"],Ls=new WeakMap,Fs=new WeakMap,Ps=new WeakMap;class Ds{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,object:s}=e;if(t={geometryId:r.id,worldMatrix:s.matrixWorld.clone()},s.center&&(t.center=s.center.clone()),s.morphTargetInfluences&&(t.morphTargetInfluences=s.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),e.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)}getGeometryData(e){let t=Ps.get(e);return void 0===t&&(t={_renderId:-1,_equal:!1,attributes:this.getAttributesData(e.attributes),indexId:e.index?e.index.id:null,indexVersion:e.index?e.index.version:null,drawRange:{start:e.drawRange.start,count:e.drawRange.count}},Ps.set(e,t)),t}getMaterialData(e){let t=Fs.get(e);if(void 0===t){t={_renderId:-1,_equal:!1};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)}Fs.set(e,t)}return t}equals(e,t,r){const{object:s,material:i,geometry:n}=e,a=this.getRenderObjectData(e);if(!0!==a.worldMatrix.equals(s.matrixWorld))return a.worldMatrix.copy(s.matrixWorld),!1;const o=this.getMaterialData(e.material);if(o._renderId!==r){o._renderId=r;for(const e in o){const t=o[e],r=i[e];if("_renderId"!==e&&"_equal"!==e)if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),o._equal=!1,!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,o._equal=!1,!1}else if(t!==r)return o[e]=r,o._equal=!1,!1}if(o.transmission>0){const{width:t,height:r}=e.context;if(a.bufferWidth!==t||a.bufferHeight!==r)return a.bufferWidth=t,a.bufferHeight=r,o._equal=!1,!1}o._equal=!0}else if(!1===o._equal)return!1;if(a.geometryId!==n.id)return a.geometryId=n.id,!1;const u=this.getGeometryData(e.geometry);if(u._renderId!==r){u._renderId=r;const e=n.attributes,t=u.attributes;let s=0,i=0;for(const t in e)s++;for(const r in t){i++;const s=t[r],n=e[r];if(void 0===n)return delete t[r],u._equal=!1,!1;if(s.id!==n.id||s.version!==n.version)return s.id=n.id,s.version=n.version,u._equal=!1,!1}if(i!==s)return u.attributes=this.getAttributesData(e),u._equal=!1,!1;const a=n.index,o=u.indexId,l=u.indexVersion,d=a?a.id:null,c=a?a.version:null;if(o!==d||l!==c)return u.indexId=d,u.indexVersion=c,u._equal=!1,!1;if(u.drawRange.start!==n.drawRange.start||u.drawRange.count!==n.drawRange.count)return u.drawRange.start=n.drawRange.start,u.drawRange.count=n.drawRange.count,u._equal=!1,!1;u._equal=!0}else if(!1===u._equal)return!1;if(a.morphTargetInfluences){let e=!1;for(let t=0;t<a.morphTargetInfluences.length;t++)a.morphTargetInfluences[t]!==s.morphTargetInfluences[t]&&(a.morphTargetInfluences[t]=s.morphTargetInfluences[t],e=!0);if(e)return!1}if(a.lights)for(let e=0;e<t.length;e++)if(a.lights[e].map!==t[e].map)return!1;return a.center&&!1===a.center.equals(s.center)?(a.center.copy(s.center),!0):(null!==e.bundle&&(a.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(Ls.has(e)){const r=Ls.get(e);if(r.renderId===t)return r.lightsData}const r=this.getLightsData(e.getLights());return Ls.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,r)}}const Us=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];class Is{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&&!Us.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 Os(e,t=0){let r=3735928559^t,s=1103547991^t;if(Array.isArray(e))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 Vs=e=>Os(e),ks=e=>Os(e),Gs=(...e)=>Os(e),zs=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),$s=new WeakMap;function Ws(e){return zs.get(e)}function Hs(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 qs(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 Is)}function js(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 Is)}function Xs(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 Is)}function Ks(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 Qs(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?Js(u[0]):null}function Ys(e){let t=$s.get(e);return void 0===t&&(t={},$s.set(e,t)),t}function Zs(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 Js(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0)).buffer}var ei=Object.freeze({__proto__:null,arrayBufferToBase64:Zs,base64ToArrayBuffer:Js,getAlignmentFromType:Xs,getDataFromObject:Ys,getLengthFromType:qs,getMemoryLengthFromType:js,getTypeFromLength:Ws,getTypedArrayFromType:Hs,getValueFromType:Qs,getValueType:Ks,hash:Gs,hashArray:ks,hashString:Vs});const ti={VERTEX:"vertex",FRAGMENT:"fragment"},ri={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},si={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},ii={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},ni=["fragment","vertex"],ai=["setup","analyze","generate"],oi=[...ni,"compute"],ui=["x","y","z","w"],li={analyze:"setup",generate:"analyze"};let di=0;class ci extends u{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=ri.NONE,this.updateBeforeType=ri.NONE,this.updateAfterType=ri.NONE,this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._uuid=null,this._cacheKeyVersion=0,this.id=di++,this.stackTrace=null,!0===ci.captureStackTrace&&(this.stackTrace=new Is)}set needsUpdate(e){!0===e&&this.version++}get uuid(){return null===this._uuid&&(this._uuid=l.generateUUID()),this._uuid}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,ri.FRAME)}onRenderUpdate(e){return this.onUpdate(e,ri.RENDER)}onObjectUpdate(e){return this.onUpdate(e,ri.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(Vs(s.slice(0,-4)),i.getCacheKey(e,t));this._cacheKey=Gs(ks(r),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return String(this.id)}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,t=null){const r=e.getDataFromNode(this);let s;return null!==t?(r.typeFromOutput=r.typeFromOutput||{},s=r.typeFromOutput[t],void 0===s&&(s=this.generateNodeType(e,t),r.typeFromOutput[t]=s)):(s=r.type,void 0===s&&(s=this.generateNodeType(e),r.type=s)),s}generateNodeType(e,t=null){const r=e.getNodeProperties(this);return r.outputNode?r.outputNode.getNodeType(e,t):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=li[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}}ci.captureStackTrace=!1;class hi extends ci{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(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 pi extends ci{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(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 gi extends ci{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 mi extends gi{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(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 fi=ui.join("");class yi extends ci{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(ui.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(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===fi.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 bi extends gi{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}generateNodeType(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=ui[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(u+"."+t)}return`${e.getType(i)}( ${d.join(", ")} )`}}class xi extends gi{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}generateNodeType(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=ui[e];r===t[l]?(u.push("1.0 - "+a+"."+r),l++):u.push(a+"."+r)}return`${e.getType(s)}( ${u.join(", ")} )`}}class Ti extends ci{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}generateNodeType(){return null===this.nodeType?Ks(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=Ks(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Zs(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Qs(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 _i=/float|u?int/;class vi extends Ti{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 _i.test(r)&&_i.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class Ni extends ci{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)}generateNodeType(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 Si=null;const Ri=new Map;function Ai(e,t){if(Ri.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`);Ri.set(e,t),"assign"!==e&&(ci.prototype[e]=function(...e){return this.isStackNode?this.addToStack(t(...e)):t(this,...e)},ci.prototype[e+"Assign"]=function(...e){return this.isStackNode?this.assign(e[0],t(...e)):this.assign(t(this,...e))})}}const Ei=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("");ci.prototype.assign=function(...e){if(!0!==this.isStackNode)return null!==Si?Si.assign(this,...e):o("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new Is),this;{const t=Ri.get("assign");return this.addToStack(t(...e))}},ci.prototype.toVarIntent=function(){return this},ci.prototype.get=function(e){return new Ni(this,e)};const wi={};function Ci(e,t,r){wi[e]=wi[t]=wi[r]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new yi(this,e),this._cache[e]=t),t},set(t){this[e].assign(tn(t))}};const s=e.toUpperCase(),i=t.toUpperCase(),n=r.toUpperCase();ci.prototype["set"+s]=ci.prototype["set"+i]=ci.prototype["set"+n]=function(t){const r=Ei(e);return new bi(this,r,tn(t))},ci.prototype["flip"+s]=ci.prototype["flip"+i]=ci.prototype["flip"+n]=function(){const t=Ei(e);return new xi(this,t)}}const Mi=["x","y","z","w"],Bi=["r","g","b","a"],Li=["s","t","p","q"];for(let e=0;e<4;e++){let t=Mi[e],r=Bi[e],s=Li[e];Ci(t,r,s);for(let i=0;i<4;i++){t=Mi[e]+Mi[i],r=Bi[e]+Bi[i],s=Li[e]+Li[i],Ci(t,r,s);for(let n=0;n<4;n++){t=Mi[e]+Mi[i]+Mi[n],r=Bi[e]+Bi[i]+Bi[n],s=Li[e]+Li[i]+Li[n],Ci(t,r,s);for(let a=0;a<4;a++)t=Mi[e]+Mi[i]+Mi[n]+Mi[a],r=Bi[e]+Bi[i]+Bi[n]+Bi[a],s=Li[e]+Li[i]+Li[n]+Li[a],Ci(t,r,s)}}}for(let e=0;e<32;e++)wi[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new hi(this,new vi(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(tn(t))}};Object.defineProperties(ci.prototype,wi);const Fi=new WeakMap,Pi=function(e,t=null){for(const r in e)e[r]=tn(e[r],t);return e},Di=function(e,t=null){const r=e.length;for(let s=0;s<r;s++)e[s]=tn(e[s],t);return e},Ui=function(e,t=null,r=null,s=null){function i(e){return null!==s?(e=tn(Object.assign(e,s)),!0===s.intent&&(e=e.toVarIntent())):e=tn(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 Is),t.concat(new Array(a-t.length).fill(0))):void 0!==u&&t.length>u?(o(`TSL: "${r}" parameter length exceeds limit.`,new Is),t.slice(0,u)):t}return null===t?n=(...t)=>i(new e(...nn(d(t)))):null!==r?(r=tn(r),n=(...s)=>i(new e(t,...nn(d(s)),r))):n=(...r)=>i(new e(t,...nn(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},Ii=function(e,...t){return new e(...nn(t))};class Oi extends ci{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(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=Fi.get(e.constructor);void 0===s&&(s=new WeakMap,Fi.set(e.constructor,s));let i=s.get(t);void 0===i&&(i=tn(e.buildFunctionNode(t)),s.set(t,i)),e.addInclude(i);const n=r?function(e){let t;sn(e);t=e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)?[...e]:e[0];return t}(r):null;u=tn(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 sn(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 tn(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 ci&&(n=void 0===e[s]?e[t++]:Reflect.get(e,s,i));else n=Reflect.get(r,s,i);n=tn(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=tn(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 Vi extends ci{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 Oi(this,e)}setup(){return this.call()}}const ki=[!1,!0],Gi=[0,1,2,3],zi=[-1,-2],$i=[.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],Wi=new Map;for(const e of ki)Wi.set(e,new vi(e));const Hi=new Map;for(const e of Gi)Hi.set(e,new vi(e,"uint"));const qi=new Map([...Hi].map(e=>new vi(e.value,"int")));for(const e of zi)qi.set(e,new vi(e,"int"));const ji=new Map([...qi].map(e=>new vi(e.value)));for(const e of $i)ji.set(e,new vi(e));for(const e of $i)ji.set(-e,new vi(-e));const Xi={bool:Wi,uint:Hi,ints:qi,float:ji},Ki=new Map([...Wi,...ji]),Qi=(e,t)=>Ki.has(e)?Ki.get(e):!0===e.isNode?e:new vi(e,t),Yi=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 Is),new vi(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=[Qs(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return rn(t.get(r[0]));if(1===r.length){const t=Qi(r[0],e);return t.nodeType===e?rn(t):rn(new pi(t,e))}const s=r.map(e=>Qi(e));return rn(new mi(s,e))}};function Zi(e){return e&&e.isNode&&e.traverse(t=>{t.isConstNode&&(e=t.value)}),Boolean(e)}const Ji=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function en(e,t){return new Vi(e,t)}const tn=(e,t=null)=>function(e,t=null){const r=Ks(e);return"node"===r?e:null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?tn(Qi(e,t)):"shader"===r?e.isFn?e:cn(e):e}(e,t),rn=(e,t=null)=>tn(e,t).toVarIntent(),sn=(e,t=null)=>new Pi(e,t),nn=(e,t=null)=>new Di(e,t),an=(e,t=null,r=null,s=null)=>new Ui(e,t,r,s),on=(e,...t)=>new Ii(e,...t),un=(e,t=null,r=null,s={})=>new Ui(e,t,r,{...s,intent:!0});let ln=0;class dn extends ci{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 Is),t=null)),this.shaderNode=new en(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"+ln++,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}generateNodeType(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 cn(e,t=null){const r=new dn(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 hn=e=>{Si=e},pn=()=>Si,gn=(...e)=>Si.If(...e);function mn(e){return Si&&Si.addToStack(e),e}Ai("toStack",mn);const fn=new Yi("color"),yn=new Yi("float",Xi.float),bn=new Yi("int",Xi.ints),xn=new Yi("uint",Xi.uint),Tn=new Yi("bool",Xi.bool),_n=new Yi("vec2"),vn=new Yi("ivec2"),Nn=new Yi("uvec2"),Sn=new Yi("bvec2"),Rn=new Yi("vec3"),An=new Yi("ivec3"),En=new Yi("uvec3"),wn=new Yi("bvec3"),Cn=new Yi("vec4"),Mn=new Yi("ivec4"),Bn=new Yi("uvec4"),Ln=new Yi("bvec4"),Fn=new Yi("mat2"),Pn=new Yi("mat3"),Dn=new Yi("mat4");Ai("toColor",fn),Ai("toFloat",yn),Ai("toInt",bn),Ai("toUint",xn),Ai("toBool",Tn),Ai("toVec2",_n),Ai("toIVec2",vn),Ai("toUVec2",Nn),Ai("toBVec2",Sn),Ai("toVec3",Rn),Ai("toIVec3",An),Ai("toUVec3",En),Ai("toBVec3",wn),Ai("toVec4",Cn),Ai("toIVec4",Mn),Ai("toUVec4",Bn),Ai("toBVec4",Ln),Ai("toMat2",Fn),Ai("toMat3",Pn),Ai("toMat4",Dn);const Un=an(hi).setParameterLength(2),In=(e,t)=>new pi(tn(e),t);Ai("element",Un),Ai("convert",In);Ai("append",e=>(d("TSL: .append() has been renamed to .toStack().",new Is),mn(e)));class On extends ci{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 Vs(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 Vn=(e,t)=>new On(e,t),kn=(e,t)=>new On(e,t,!0),Gn=on(On,"vec4","DiffuseColor"),zn=on(On,"vec3","DiffuseContribution"),$n=on(On,"vec3","EmissiveColor"),Wn=on(On,"float","Roughness"),Hn=on(On,"float","Metalness"),qn=on(On,"float","Clearcoat"),jn=on(On,"float","ClearcoatRoughness"),Xn=on(On,"vec3","Sheen"),Kn=on(On,"float","SheenRoughness"),Qn=on(On,"float","Iridescence"),Yn=on(On,"float","IridescenceIOR"),Zn=on(On,"float","IridescenceThickness"),Jn=on(On,"float","AlphaT"),ea=on(On,"float","Anisotropy"),ta=on(On,"vec3","AnisotropyT"),ra=on(On,"vec3","AnisotropyB"),sa=on(On,"color","SpecularColor"),ia=on(On,"color","SpecularColorBlended"),na=on(On,"float","SpecularF90"),aa=on(On,"float","Shininess"),oa=on(On,"vec4","Output"),ua=on(On,"float","dashSize"),la=on(On,"float","gapSize"),da=on(On,"float","pointWidth"),ca=on(On,"float","IOR"),ha=on(On,"float","Transmission"),pa=on(On,"float","Thickness"),ga=on(On,"float","AttenuationDistance"),ma=on(On,"color","AttenuationColor"),fa=on(On,"float","Dispersion");class ya extends ci{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1,s=null){super("string"),this.name=e,this.shared=t,this.order=r,this.updateType=s,this.isUniformGroup=!0}update(){this.needsUpdate=!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 ba=(e,t=1,r=null)=>new ya(e,!1,t,r),xa=(e,t=0,r=null)=>new ya(e,!0,t,r),Ta=xa("frame",0,ri.FRAME),_a=xa("render",0,ri.RENDER),va=ba("object",1,ri.OBJECT);class Na extends Ti{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=va}setName(e){return this.name=e,this}label(e){return d('TSL: "label()" has been deprecated. Use "setName()" instead.',new Is),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 Sa=(e,t)=>{const r=Ji(t||e);if(r===e&&(e=Qs(r)),e&&!0===e.isNode){let t=e.value;e.traverse(e=>{!0===e.isConstNode&&(t=e.value)}),e=t}return new Na(e,r)};class Ra extends gi{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}generateNodeType(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 Aa=(...e)=>{let t;if(1===e.length){const r=e[0];t=new Ra(null,r.length,r)}else{const r=e[0],s=e[1];t=new Ra(r,s)}return tn(t)};Ai("toArray",(e,t)=>Aa(Array(t).fill(e)));class Ea extends gi{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}generateNodeType(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 ui.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 wa=an(Ea).setParameterLength(2);Ai("assign",wa);class Ca extends gi{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}generateNodeType(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(yn(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(yn(0),e)))}return`${r.build(e,"property")}( ${t.join(", ")} )`}}const Ma=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?nn(t):sn(t[0]),new Ca(tn(e),t));Ai("call",Ma);const Ba={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class La extends gi{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new La(e,t,r);for(let t=0;t<s.length-1;t++)i=new La(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(Ba[this.op],t)}generateNodeType(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 Fa=un(La,"+").setParameterLength(2,1/0).setName("add"),Pa=un(La,"-").setParameterLength(2,1/0).setName("sub"),Da=un(La,"*").setParameterLength(2,1/0).setName("mul"),Ua=un(La,"/").setParameterLength(2,1/0).setName("div"),Ia=un(La,"%").setParameterLength(2).setName("mod"),Oa=un(La,"==").setParameterLength(2).setName("equal"),Va=un(La,"!=").setParameterLength(2).setName("notEqual"),ka=un(La,"<").setParameterLength(2).setName("lessThan"),Ga=un(La,">").setParameterLength(2).setName("greaterThan"),za=un(La,"<=").setParameterLength(2).setName("lessThanEqual"),$a=un(La,">=").setParameterLength(2).setName("greaterThanEqual"),Wa=un(La,"&&").setParameterLength(2,1/0).setName("and"),Ha=un(La,"||").setParameterLength(2,1/0).setName("or"),qa=un(La,"!