UNPKG

three

Version:

JavaScript 3D library

6 lines 547 kB
/** * @license * Copyright 2010-2025 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,EventDispatcher as o,MathUtils as u,WebGLCoordinateSystem as l,WebGPUCoordinateSystem as d,ColorManagement as c,SRGBTransfer as h,NoToneMapping as p,StaticDrawUsage as g,InterleavedBuffer as m,InterleavedBufferAttribute as f,DynamicDrawUsage as y,NoColorSpace as x,UnsignedIntType as b,IntType as T,NearestFilter as _,Sphere as v,BackSide as N,Euler as S,CubeReflectionMapping as w,CubeRefractionMapping as E,TangentSpaceNormalMap as A,ObjectSpaceNormalMap as R,InstancedInterleavedBuffer as C,InstancedBufferAttribute as M,DataArrayTexture as P,FloatType as L,FramebufferTexture as F,LinearMipmapLinearFilter as B,DepthTexture as D,Material as I,NormalBlending as V,LineBasicMaterial as U,LineDashedMaterial as O,NoBlending as k,MeshNormalMaterial as G,SRGBColorSpace as z,WebGLCubeRenderTarget as H,BoxGeometry as $,Mesh as W,Scene as j,LinearFilter as q,CubeCamera as X,CubeTexture as K,EquirectangularReflectionMapping as Y,EquirectangularRefractionMapping as Q,AddOperation as Z,MixOperation as J,MultiplyOperation as ee,MeshBasicMaterial as te,MeshLambertMaterial as re,MeshPhongMaterial as se,OrthographicCamera as ie,PerspectiveCamera as ne,RenderTarget as ae,CubeUVReflectionMapping as oe,BufferGeometry as ue,BufferAttribute as le,LinearSRGBColorSpace as de,RGBAFormat as ce,HalfFloatType as he,Texture as pe,MeshStandardMaterial as ge,MeshPhysicalMaterial as me,MeshToonMaterial as fe,MeshMatcapMaterial as ye,SpriteMaterial as xe,PointsMaterial as be,ShadowMaterial as Te,Uint32BufferAttribute as _e,Uint16BufferAttribute as ve,arrayNeedsUint32 as Ne,DoubleSide as Se,Camera as we,DepthArrayTexture as Ee,DepthStencilFormat as Ae,DepthFormat as Re,UnsignedInt248Type as Ce,UnsignedByteType as Me,Plane as Pe,Object3D as Le,LinearMipMapLinearFilter as Fe,Float32BufferAttribute as Be,UVMapping as De,VSMShadowMap as Ie,LessCompare as Ve,RGFormat as Ue,BasicShadowMap as Oe,SphereGeometry as ke,RenderTargetArray as Ge,LinearMipmapNearestFilter as ze,NearestMipmapLinearFilter as He,Float16BufferAttribute as $e,REVISION as We,ArrayCamera as je,PlaneGeometry as qe,FrontSide as Xe,CustomBlending as Ke,AddEquation as Ye,ZeroFactor as Qe,CylinderGeometry as Ze,Quaternion as Je,WebXRController as et,RAD2DEG as tt,PCFShadowMap as rt,FrustumArray as st,Frustum as it,DataTexture as nt,RedIntegerFormat as at,RedFormat as ot,ShortType as ut,ByteType as lt,UnsignedShortType as dt,RGIntegerFormat as ct,RGBIntegerFormat as ht,RGBFormat as pt,RGBAIntegerFormat as gt,warnOnce as mt,createCanvasElement as ft,ReverseSubtractEquation as yt,SubtractEquation as xt,OneMinusDstAlphaFactor as bt,OneMinusDstColorFactor as Tt,OneMinusSrcAlphaFactor as _t,OneMinusSrcColorFactor as vt,DstAlphaFactor as Nt,DstColorFactor as St,SrcAlphaSaturateFactor as wt,SrcAlphaFactor as Et,SrcColorFactor as At,OneFactor as Rt,CullFaceNone as Ct,CullFaceBack as Mt,CullFaceFront as Pt,MultiplyBlending as Lt,SubtractiveBlending as Ft,AdditiveBlending as Bt,NotEqualDepth as Dt,GreaterDepth as It,GreaterEqualDepth as Vt,EqualDepth as Ut,LessEqualDepth as Ot,LessDepth as kt,AlwaysDepth as Gt,NeverDepth as zt,UnsignedShort4444Type as Ht,UnsignedShort5551Type as $t,UnsignedInt5999Type as Wt,AlphaFormat as jt,RGB_S3TC_DXT1_Format as qt,RGBA_S3TC_DXT1_Format as Xt,RGBA_S3TC_DXT3_Format as Kt,RGBA_S3TC_DXT5_Format as Yt,RGB_PVRTC_4BPPV1_Format as Qt,RGB_PVRTC_2BPPV1_Format as Zt,RGBA_PVRTC_4BPPV1_Format as Jt,RGBA_PVRTC_2BPPV1_Format as er,RGB_ETC1_Format as tr,RGB_ETC2_Format as rr,RGBA_ETC2_EAC_Format as sr,RGBA_ASTC_4x4_Format as ir,RGBA_ASTC_5x4_Format as nr,RGBA_ASTC_5x5_Format as ar,RGBA_ASTC_6x5_Format as or,RGBA_ASTC_6x6_Format as ur,RGBA_ASTC_8x5_Format as lr,RGBA_ASTC_8x6_Format as dr,RGBA_ASTC_8x8_Format as cr,RGBA_ASTC_10x5_Format as hr,RGBA_ASTC_10x6_Format as pr,RGBA_ASTC_10x8_Format as gr,RGBA_ASTC_10x10_Format as mr,RGBA_ASTC_12x10_Format as fr,RGBA_ASTC_12x12_Format as yr,RGBA_BPTC_Format as xr,RED_RGTC1_Format as br,SIGNED_RED_RGTC1_Format as Tr,RED_GREEN_RGTC2_Format as _r,SIGNED_RED_GREEN_RGTC2_Format as vr,MirroredRepeatWrapping as Nr,ClampToEdgeWrapping as Sr,RepeatWrapping as wr,NearestMipmapNearestFilter as Er,NotEqualCompare as Ar,GreaterCompare as Rr,GreaterEqualCompare as Cr,EqualCompare as Mr,LessEqualCompare as Pr,AlwaysCompare as Lr,NeverCompare as Fr,NotEqualStencilFunc as Br,GreaterStencilFunc as Dr,GreaterEqualStencilFunc as Ir,EqualStencilFunc as Vr,LessEqualStencilFunc as Ur,LessStencilFunc as Or,AlwaysStencilFunc as kr,NeverStencilFunc as Gr,DecrementWrapStencilOp as zr,IncrementWrapStencilOp as Hr,DecrementStencilOp as $r,IncrementStencilOp as Wr,InvertStencilOp as jr,ReplaceStencilOp as qr,ZeroStencilOp as Xr,KeepStencilOp as Kr,MaxEquation as Yr,MinEquation as Qr,SpotLight as Zr,PointLight as Jr,DirectionalLight as es,RectAreaLight as ts,AmbientLight as rs,HemisphereLight as ss,LightProbe as is,LinearToneMapping as ns,ReinhardToneMapping as as,CineonToneMapping as os,ACESFilmicToneMapping as us,AgXToneMapping as ls,NeutralToneMapping as ds,Group as cs,Loader as hs,FileLoader as ps,MaterialLoader as gs,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,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,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,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,InterpolationSamplingMode,InterpolationSamplingType,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,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,TimestampQuery,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoFrameTexture,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const fs=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class ys{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=fs,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),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}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const r in e){const s=e[r];t[r]={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 null!==e.renderer.overrideNodes.modelViewMatrix||null!==e.renderer.overrideNodes.modelNormalViewMatrix}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){const{object:t,material:r,geometry:s}=e,i=this.getRenderObjectData(e);if(!0!==i.worldMatrix.equals(t.matrixWorld))return i.worldMatrix.copy(t.matrixWorld),!1;const n=i.material;for(const e in n){const t=n[e],s=r[e];if(void 0!==t.equals){if(!1===t.equals(s))return t.copy(s),!1}else if(!0===s.isTexture){if(t.id!==s.id||t.version!==s.version)return t.id=s.id,t.version=s.version,!1}else if(t!==s)return n[e]=s,!1}if(n.transmission>0){const{width:t,height:r}=e.context;if(i.bufferWidth!==t||i.bufferHeight!==r)return i.bufferWidth=t,i.bufferHeight=r,!1}const a=i.geometry,o=s.attributes,u=a.attributes,l=Object.keys(u),d=Object.keys(o);if(a.id!==s.id)return a.id=s.id,!1;if(l.length!==d.length)return i.geometry.attributes=this.getAttributesData(o),!1;for(const e of l){const t=u[e],r=o[e];if(void 0===r)return delete u[e],!1;if(t.version!==r.version)return t.version=r.version,!1}const c=s.index,h=a.indexVersion,p=c?c.version:null;if(h!==p)return a.indexVersion=p,!1;if(a.drawRange.start!==s.drawRange.start||a.drawRange.count!==s.drawRange.count)return a.drawRange.start=s.drawRange.start,a.drawRange.count=s.drawRange.count,!1;if(i.morphTargetInfluences){let e=!1;for(let r=0;r<i.morphTargetInfluences.length;r++)i.morphTargetInfluences[r]!==t.morphTargetInfluences[r]&&(e=!0);if(e)return!0}return i.center&&!1===i.center.equals(t.center)?(i.center.copy(t.center),!0):(null!==e.bundle&&(i.version=e.bundle.version),!0)}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||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;return!0!==this.equals(e)}}function xs(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 bs=e=>xs(e),Ts=e=>xs(e),_s=(...e)=>xs(e);function vs(e,t=!1){const r=[];!0===e.isNode&&(r.push(e.id),e=e.getSelf());for(const{property:s,childNode:i}of Ns(e))r.push(xs(s.slice(0,-4)),i.getCacheKey(t));return xs(r)}function*Ns(e,t=!1){for(const r in e){if(!0===r.startsWith("_"))continue;const s=e[r];if(!0===Array.isArray(s))for(let e=0;e<s.length;e++){const i=s[e];i&&(!0===i.isNode||t&&"function"==typeof i.toJSON)&&(yield{property:r,index:e,childNode:i})}else if(s&&!0===s.isNode)yield{property:r,childNode:s};else if("object"==typeof s)for(const e in s){const i=s[e];i&&(!0===i.isNode||t&&"function"==typeof i.toJSON)&&(yield{property:r,index:e,childNode:i})}}}const Ss=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),ws=new WeakMap;function Es(e){return Ss.get(e)}function As(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 Rs(e){return/float|int|uint/.test(e)?1:/vec2/.test(e)?2:/vec3/.test(e)?3:/vec4/.test(e)||/mat2/.test(e)?4:/mat3/.test(e)?9:/mat4/.test(e)?16:void console.error("THREE.TSL: Unsupported type:",e)}function Cs(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 Ms(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?Fs(u[0]):null}function Ps(e){let t=ws.get(e);return void 0===t&&(t={},ws.set(e,t)),t}function Ls(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 Fs(e){return Uint8Array.from(atob(e),(e=>e.charCodeAt(0))).buffer}var Bs=Object.freeze({__proto__:null,arrayBufferToBase64:Ls,base64ToArrayBuffer:Fs,getCacheKey:vs,getDataFromObject:Ps,getLengthFromType:Rs,getNodeChildren:Ns,getTypeFromLength:Es,getTypedArrayFromType:As,getValueFromType:Ms,getValueType:Cs,hash:_s,hashArray:Ts,hashString:bs});const Ds={VERTEX:"vertex",FRAGMENT:"fragment"},Is={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Vs={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Us={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},Os=["fragment","vertex"],ks=["setup","analyze","generate"],Gs=[...Os,"compute"],zs=["x","y","z","w"];let Hs=0;class $s extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=Is.NONE,this.updateBeforeType=Is.NONE,this.updateAfterType=Is.NONE,this.uuid=u.generateUUID(),this.version=0,this.global=!1,this.parents=!1,this.isNode=!0,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:Hs++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,Is.FRAME)}onRenderUpdate(e){return this.onUpdate(e,Is.RENDER)}onObjectUpdate(e){return this.onUpdate(e,Is.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of Ns(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=_s(vs(this,e),this.customCacheKey()),this._cacheKeyVersion=this.version),this._cacheKey}customCacheKey(){return 0}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}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}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){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const r of Object.values(t))r&&!0===r.isNode&&r.build(e)}}generate(e,t){const{outputNode:r}=e.getNodeProperties(this);if(r&&!0===r.isNode)return r.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const r=this.getShared(e);if(this!==r)return r.build(e,t);e.addNode(this),e.addChain(this);let s=null;const i=e.getBuildStage();if("setup"===i){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){t.initialized=!0;const r=this.setup(e),s=r&&!0===r.isNode;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)}s&&r.build(e),t.outputNode=r}s=t.outputNode||null}else if("analyze"===i)this.analyze(e);else if("generate"===i){if(1===this.generate.length){const r=this.getNodeType(e),i=e.getDataFromNode(this);s=i.snippet,void 0===s?void 0===i.generated?(i.generated=!0,s=this.generate(e)||"",i.snippet=s):(console.warn("THREE.Node: Recursion detected.",this),s=""):void 0!==i.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),s=e.format(s,r,t)}else s=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),s}getSerializeChildren(){return Ns(this)}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.6,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}}class Ws extends $s{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){const t=this.indexNode.getNodeType(e);return`${this.node.build(e)}[ ${this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint")} ]`}}class js extends $s{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 qs extends $s{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 Xs extends qs{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 o=0;for(const t of i){if(o>=s){console.error(`THREE.TSL: Length of parameters exceeds maximum length of function '${r}()' type.`);break}let i,u=t.getNodeType(e),l=e.getTypeLength(u);o+l>s&&(console.error(`THREE.TSL: Length of '${r}()' data exceeds maximum length of output type.`),l=s-o,u=e.getTypeFromLength(l)),o+=l,i=t.build(e,u);const d=e.getComponentType(u);d!==n&&(i=e.format(i,d,n)),a.push(i)}const u=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(u,r,t)}}const Ks=zs.join("");class Ys extends $s{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(zs.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const 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===Ks.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 Qs extends qs{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=zs[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(u+"."+t)}return`${e.getType(i)}( ${d.join(", ")} )`}}class Zs extends qs{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=zs[e];r===t[l]?(u.push("1.0 - "+a+"."+r),l++):u.push(a+"."+r)}return`${e.getType(s)}( ${u.join(", ")} )`}}class Js extends $s{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?Cs(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=Cs(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Ls(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Ms(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){console.warn("Abstract function.")}}const ei=/float|u?int/;class ti extends Js{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 ei.test(r)&&ei.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class ri extends $s{static get type(){return"MemberNode"}constructor(e,t){super(),this.node=e,this.property=t,this.isMemberNode=!0}getNodeType(e){return this.node.getMemberType(e,this.property)}generate(e){return this.node.build(e)+"."+this.property}}let si=null;const ii=new Map;function ni(e,t){if(ii.has(e))console.warn(`THREE.TSL: Redefinition of method chaining '${e}'.`);else{if("function"!=typeof t)throw new Error(`THREE.TSL: Node element ${e} is not a function`);ii.set(e,t)}}const ai=e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),oi=e=>ai(e).split("").sort().join(""),ui={setup(e,t){const r=t.shift();return e(Fi(r),...t)},get(e,t,r){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(si.assign(r,...e),r);if(ii.has(t)){const s=ii.get(t);return e.isStackNode?(...e)=>r.add(s(...e)):(...e)=>s(r,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&ii.has(t.slice(0,t.length-6))){const s=ii.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>r.assign(e[0],s(...e)):(...e)=>r.assign(s(r,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=ai(t),Li(new Ys(r,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=oi(t.slice(3).toLowerCase()),r=>Li(new Qs(e,t,r));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=oi(t.slice(4).toLowerCase()),()=>Li(new Zs(Li(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),Li(new Ys(e,t));if(!0===/^\d+$/.test(t))return Li(new Ws(r,new ti(Number(t),"uint")));if(!0===/^get$/.test(t))return e=>Li(new ri(r,e))}return Reflect.get(e,t,r)},set:(e,t,r,s)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,r,s):(s[t].assign(r),!0)},li=new WeakMap,di=new WeakMap,ci=function(e,t=null){for(const r in e)e[r]=Li(e[r],t);return e},hi=function(e,t=null){const r=e.length;for(let s=0;s<r;s++)e[s]=Li(e[s],t);return e},pi=function(e,t=null,r=null,s=null){const i=e=>Li(null!==s?Object.assign(e,s):e);let n,a,o,u=t;function l(t){let r;return r=u?/[a-z]/i.test(u)?u+"()":u:e.type,void 0!==a&&t.length<a?(console.error(`THREE.TSL: "${r}" parameter length is less than minimum required.`),t.concat(new Array(a-t.length).fill(0))):void 0!==o&&t.length>o?(console.error(`THREE.TSL: "${r}" parameter length exceeds limit.`),t.slice(0,o)):t}return null===t?n=(...t)=>i(new e(...Bi(l(t)))):null!==r?(r=Li(r),n=(...s)=>i(new e(t,...Bi(l(s)),r))):n=(...r)=>i(new e(t,...Bi(l(r)))),n.setParameterLength=(...e)=>(1===e.length?a=o=e[0]:2===e.length&&([a,o]=e),n),n.setName=e=>(u=e,n),n},gi=function(e,...t){return Li(new e(...Bi(t)))};class mi extends $s{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t,this.isShaderCallNodeInternal=!0}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){const{shaderNode:t,inputNodes:r}=this,s=e.getNodeProperties(t);if(s.onceOutput)return s.onceOutput;let i=null;if(t.layout){let s=di.get(e.constructor);void 0===s&&(s=new WeakMap,di.set(e.constructor,s));let n=s.get(t);void 0===n&&(n=Li(e.buildFunctionNode(t)),s.set(t,n)),e.addInclude(n),i=Li(n.call(r))}else{const s=t.jsFunc,n=null!==r||s.length>1?s(r||[],e):s(e);i=Li(n)}return t.once&&(s.onceOutput=i),i}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class fi extends $s{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return Fi(e),Li(new mi(this,e))}setup(){return this.call()}}const yi=[!1,!0],xi=[0,1,2,3],bi=[-1,-2],Ti=[.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 yi)_i.set(e,new ti(e));const vi=new Map;for(const e of xi)vi.set(e,new ti(e,"uint"));const Ni=new Map([...vi].map((e=>new ti(e.value,"int"))));for(const e of bi)Ni.set(e,new ti(e,"int"));const Si=new Map([...Ni].map((e=>new ti(e.value))));for(const e of Ti)Si.set(e,new ti(e));for(const e of Ti)Si.set(-e,new ti(-e));const wi={bool:_i,uint:vi,ints:Ni,float:Si},Ei=new Map([..._i,...Si]),Ai=(e,t)=>Ei.has(e)?Ei.get(e):!0===e.isNode?e:new ti(e,t),Ri=function(e,t=null){return(...r)=>{if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every((e=>"object"!=typeof e)))&&(r=[Ms(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return Li(t.get(r[0]));if(1===r.length){const t=Ai(r[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?Li(t):Li(new js(t,e))}const s=r.map((e=>Ai(e)));return Li(new Xs(s,e))}},Ci=e=>"object"==typeof e&&null!==e?e.value:e,Mi=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function Pi(e,t){return new Proxy(new fi(e,t),ui)}const Li=(e,t=null)=>function(e,t=null){const r=Cs(e);if("node"===r){let t=li.get(e);return void 0===t&&(t=new Proxy(e,ui),li.set(e,t),li.set(t,t)),t}return null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?Li(Ai(e,t)):"shader"===r?Ui(e):e}(e,t),Fi=(e,t=null)=>new ci(e,t),Bi=(e,t=null)=>new hi(e,t),Di=(...e)=>new pi(...e),Ii=(...e)=>new gi(...e);let Vi=0;const Ui=(e,t=null)=>{let r=null;null!==t&&("object"==typeof t?r=t.return:("string"==typeof t?r=t:console.error("THREE.TSL: Invalid layout type."),t=null));const s=new Pi(e,r),i=(...e)=>{let t;Fi(e),t=e[0]&&e[0].isNode?[...e]:e[0];const i=s.call(t);return"void"===r&&i.toStack(),i};if(i.shaderNode=s,i.setLayout=e=>(s.setLayout(e),i),i.once=()=>(s.once=!0,i),null!==t){if("object"!=typeof t.inputs){const e={name:"fn"+Vi++,type:r,inputs:[]};for(const r in t)"return"!==r&&e.inputs.push({name:r,type:t[r]});t=e}i.setLayout(t)}return i};ni("toGlobal",(e=>(e.global=!0,e)));const Oi=e=>{si=e},ki=()=>si,Gi=(...e)=>si.If(...e);function zi(e){return si&&si.add(e),e}ni("toStack",zi);const Hi=new Ri("color"),$i=new Ri("float",wi.float),Wi=new Ri("int",wi.ints),ji=new Ri("uint",wi.uint),qi=new Ri("bool",wi.bool),Xi=new Ri("vec2"),Ki=new Ri("ivec2"),Yi=new Ri("uvec2"),Qi=new Ri("bvec2"),Zi=new Ri("vec3"),Ji=new Ri("ivec3"),en=new Ri("uvec3"),tn=new Ri("bvec3"),rn=new Ri("vec4"),sn=new Ri("ivec4"),nn=new Ri("uvec4"),an=new Ri("bvec4"),on=new Ri("mat2"),un=new Ri("mat3"),ln=new Ri("mat4");ni("toColor",Hi),ni("toFloat",$i),ni("toInt",Wi),ni("toUint",ji),ni("toBool",qi),ni("toVec2",Xi),ni("toIVec2",Ki),ni("toUVec2",Yi),ni("toBVec2",Qi),ni("toVec3",Zi),ni("toIVec3",Ji),ni("toUVec3",en),ni("toBVec3",tn),ni("toVec4",rn),ni("toIVec4",sn),ni("toUVec4",nn),ni("toBVec4",an),ni("toMat2",on),ni("toMat3",un),ni("toMat4",ln);const dn=Di(Ws).setParameterLength(2),cn=(e,t)=>Li(new js(Li(e),t));ni("element",dn),ni("convert",cn);ni("append",(e=>(console.warn("THREE.TSL: .append() has been renamed to .toStack()."),zi(e))));class hn extends $s{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1){super(e),this.name=t,this.varying=r,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const pn=(e,t)=>Li(new hn(e,t)),gn=(e,t)=>Li(new hn(e,t,!0)),mn=Ii(hn,"vec4","DiffuseColor"),fn=Ii(hn,"vec3","EmissiveColor"),yn=Ii(hn,"float","Roughness"),xn=Ii(hn,"float","Metalness"),bn=Ii(hn,"float","Clearcoat"),Tn=Ii(hn,"float","ClearcoatRoughness"),_n=Ii(hn,"vec3","Sheen"),vn=Ii(hn,"float","SheenRoughness"),Nn=Ii(hn,"float","Iridescence"),Sn=Ii(hn,"float","IridescenceIOR"),wn=Ii(hn,"float","IridescenceThickness"),En=Ii(hn,"float","AlphaT"),An=Ii(hn,"float","Anisotropy"),Rn=Ii(hn,"vec3","AnisotropyT"),Cn=Ii(hn,"vec3","AnisotropyB"),Mn=Ii(hn,"color","SpecularColor"),Pn=Ii(hn,"float","SpecularF90"),Ln=Ii(hn,"float","Shininess"),Fn=Ii(hn,"vec4","Output"),Bn=Ii(hn,"float","dashSize"),Dn=Ii(hn,"float","gapSize"),In=Ii(hn,"float","pointWidth"),Vn=Ii(hn,"float","IOR"),Un=Ii(hn,"float","Transmission"),On=Ii(hn,"float","Thickness"),kn=Ii(hn,"float","AttenuationDistance"),Gn=Ii(hn,"color","AttenuationColor"),zn=Ii(hn,"float","Dispersion");class Hn extends $s{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 $n=e=>new Hn(e),Wn=(e,t=0)=>new Hn(e,!0,t),jn=Wn("frame"),qn=Wn("render"),Xn=$n("object");class Kn extends Js{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Xn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const r=this.getSelf();return e=e.bind(r),super.onUpdate((t=>{const s=e(t,r);void 0!==s&&(this.value=s)}),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.label),o=e.getPropertyName(a);return void 0!==e.context.label&&delete e.context.label,e.format(o,r,t)}}const Yn=(e,t)=>{const r=Mi(t||e),s=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return Li(new Kn(s,r))};class Qn extends qs{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getNodeType(e){return null===this.nodeType&&(this.nodeType=this.values[0].getNodeType(e)),this.nodeType}getElementType(e){return this.getNodeType(e)}generate(e){const t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}const Zn=(...e)=>{let t;if(1===e.length){const r=e[0];t=new Qn(null,r.length,r)}else{const r=e[0],s=e[1];t=new Qn(r,s)}return Li(t)};ni("toArray",((e,t)=>Zn(Array(t).fill(e))));class Jn extends qs{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const r=e.getTypeLength(t.node.getNodeType(e));return zs.join("").slice(0,r)!==t.components}return!1}generate(e,t){const{targetNode:r,sourceNode:s}=this,i=this.needsSplitAssign(e),n=r.getNodeType(e),a=r.context({assign:!0}).build(e),o=s.build(e,n),u=s.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=a);else if(i){const s=e.getVarFromNode(this,null,n),i=e.getPropertyName(s);e.addLineFlowCode(`${i} = ${o}`,this);const u=r.node.context({assign:!0}).build(e);for(let t=0;t<r.components.length;t++){const s=r.components[t];e.addLineFlowCode(`${u}.${s} = ${i}[ ${t} ]`,this)}"void"!==t&&(d=a)}else d=`${a} = ${o}`,"void"!==t&&"void"!==u||(e.addLineFlowCode(d,this),"void"!==t&&(d=a));return l.initialized=!0,e.format(d,n,t)}}const ea=Di(Jn).setParameterLength(2);ni("assign",ea);class ta extends qs{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}generate(e){const t=[],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)console.error("THREE.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(console.error("THREE.TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");i.length<s.length;)i.push($i(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)):(console.error(`THREE.TSL: Input '${e.name}' not found in 'Fn()'.`),t.push(n($i(0),e)))}return`${r.build(e,"property")}( ${t.join(", ")} )`}}const ra=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?Bi(t):Fi(t[0]),Li(new ta(Li(e),t)));ni("call",ra);const sa={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class ia extends qs{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new ia(e,t,r);for(let t=0;t<s.length-1;t++)i=new ia(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(sa[this.op],t)}getNodeType(e){const t=this.op,r=this.aNode,s=this.bNode,i=r.getNodeType(e),n=void 0!==s?s.getNodeType(e):null;if("void"===i||"void"===n)return"void";if("%"===t)return i;if("~"===t||"&"===t||"|"===t||"^"===t||">>"===t||"<<"===t)return e.getIntegerType(i);if("!"===t||"&&"===t||"||"===t||"^^"===t)return"bool";if("=="===t||"!="===t||"<"===t||">"===t||"<="===t||">="===t){const t=Math.max(e.getTypeLength(i),e.getTypeLength(n));return t>1?`bvec${t}`:"bool"}if(e.isMatrix(i)){if("float"===n)return i;if(e.isVector(n))return e.getVectorFromMatrix(i);if(e.isMatrix(n))return i}else if(e.isMatrix(n)){if("float"===i)return n;if(e.isVector(i))return e.getVectorFromMatrix(n)}return e.getTypeLength(n)>e.getTypeLength(i)?n:i}generate(e,t){const r=this.op,s=this.aNode,i=this.bNode,n=this.getNodeType(e);let a=null,o=null;"void"!==n?(a=s.getNodeType(e),o=void 0!==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),d=void 0!==i?i.build(e,o):null,c=e.getFunctionOperator(r);if("void"!==t){const s=e.renderer.coordinateSystem===l;if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r)return s&&e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${u}, ${d} )`,n,t):e.format(`( ${u} ${r} ${d} )`,n,t);if("%"===r)return e.isInteger(o)?e.format(`( ${u} % ${d} )`,n,t):e.format(`${this.getOperatorMethod(e,n)}( ${u}, ${d} )`,n,t);if("!"===r||"~"===r)return e.format(`(${r}${u})`,a,t);if(c)return e.format(`${c}( ${u}, ${d} )`,n,t);if(e.isMatrix(a)&&"float"===o)return e.format(`( ${d} ${r} ${u} )`,n,t);if("float"===a&&e.isMatrix(o))return e.format(`${u} ${r} ${d}`,n,t);{let i=`( ${u} ${r} ${d} )`;return!s&&"bool"===n&&e.isVector(a)&&e.isVector(o)&&(i=`all${i}`),e.format(i,n,t)}}if("void"!==a)return c?e.format(`${c}( ${u}, ${d} )`,n,t):e.isMatrix(a)&&"float"===o?e.format(`${d} ${r} ${u}`,n,t):e.format(`${u} ${r} ${d}`,n,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const na=Di(ia,"+").setParameterLength(2,1/0).setName("add"),aa=Di(ia,"-").setParameterLength(2,1/0).setName("sub"),oa=Di(ia,"*").setParameterLength(2,1/0).setName("mul"),ua=Di(ia,"/").setParameterLength(2,1/0).setName("div"),la=Di(ia,"%").setParameterLength(2).setName("mod"),da=Di(ia,"==").setParameterLength(2).setName("equal"),ca=Di(ia,"!=").setParameterLength(2).setName("notEqual"),ha=Di(ia,"<").setParameterLength(2).setName("lessThan"),pa=Di(ia,">").setParameterLength(2).setName("greaterThan"),ga=Di(ia,"<=").setParameterLength(2).setName("lessThanEqual"),ma=Di(ia,">=").setParameterLength(2).setName("greaterThanEqual"),fa=Di(ia,"&&").setParameterLength(2,1/0).setName("and"),ya=Di(ia,"||").setParameterLength(2,1/0).setName("or"),xa=Di(ia,"!").setParameterLength(1).setName("not"),ba=Di(ia,"^^").setParameterLength(2).setName("xor"),Ta=Di(ia,"&").setParameterLength(2).setName("bitAnd"),_a=Di(ia,"~").setParameterLength(2).setName("bitNot"),va=Di(ia,"|").setParameterLength(2).setName("bitOr"),Na=Di(ia,"^").setParameterLength(2).setName("bitXor"),Sa=Di(ia,"<<").setParameterLength(2).setName("shiftLeft"),wa=Di(ia,">>").setParameterLength(2).setName("shiftRight"),Ea=Ui((([e])=>(e.addAssign(1),e))),Aa=Ui((([e])=>(e.subAssign(1),e))),Ra=Ui((([e])=>{const t=Wi(e).toConst();return e.addAssign(1),t})),Ca=Ui((([e])=>{const t=Wi(e).toConst();return e.subAssign(1),t}));ni("add",na),ni("sub",aa),ni("mul",oa),ni("div",ua),ni("mod",la),ni("equal",da),ni("notEqual",ca),ni("lessThan",ha),ni("greaterThan",pa),ni("lessThanEqual",ga),ni("greaterThanEqual",ma),ni("and",fa),ni("or",ya),ni("not",xa),ni("xor",ba),ni("bitAnd",Ta),ni("bitNot",_a),ni("bitOr",va),ni("bitXor",Na),ni("shiftLeft",Sa),ni("shiftRight",wa),ni("incrementBefore",Ea),ni("decrementBefore",Aa),ni("increment",Ra),ni("decrement",Ca);const Ma=(e,t)=>(console.warn('THREE.TSL: "remainder()" is deprecated. Use "mod( int( ... ) )" instead.'),la(e,t)),Pa=(e,t)=>(console.warn('THREE.TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.'),la(Wi(e),Wi(t)));ni("remainder",Ma),ni("modInt",Pa);class La extends qs{static get type(){return"MathNode"}constructor(e,t,r=null,s=null){if(super(),(e===La.MAX||e===La.MIN)&&arguments.length>3){let i=new La(e,t,r);for(let t=2;t<arguments.length-1;t++)i=new La(e,i,arguments[t]);t=i,r=arguments[arguments.length-1],s=null}this.method=e,this.aNode=t,this.bNode=r,this.cNode=s,this.isMathNode=!0}getInputType(e){const t=this.aNode.getNodeType(e),r=this.bNode?this.bNode.getNodeType(e):null,s=this.cNode?this.cNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(r)?0:e.getTypeLength(r),a=e.isMatrix(s)?0:e.getTypeLength(s);return i>n&&i>a?t:n>a?r:a>i?s:t}getNodeType(e){const t=this.method;return t===La.LENGTH||t===La.DISTANCE||t===La.DOT?"float":t===La.CROSS?"vec3":t===La.ALL||t===La.ANY?"bool":t===La.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}generate(e,t){let r=this.method;const s=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,a=this.bNode,o=this.cNode,u=e.renderer.coordinateSystem;if(r===La.TRANSFORM_DIRECTION){let r=n,s=a;e.isMatrix(r.getNodeType(e))?s=rn(Zi(s),0):r=rn(Zi(r),0);const i=oa(r,s).xyz;return Ka(i).build(e,t)}if(r===La.NEGATE)return e.format("( - "+n.build(e,i)+" )",s,t);if(r===La.ONE_MINUS)return aa(1,n).build(e,t);if(r===La.RECIPROCAL)return ua(1,n).build(e,t);if(r===La.DIFFERENCE)return so(aa(n,a)).build(e,t);{const c=[];return r===La.CROSS?c.push(n.build(e,s),a.build(e,s)):u===l&&r===La.STEP?c.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),a.build(e,i)):u!==l||r!==La.MIN&&r!==La.MAX?r===La.REFRACT?c.push(n.build(e,i),a.build(e,i),o.build(e,"float")):r===La.MIX?c.push(n.build(e,i),a.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):(u===d&&r===La.ATAN&&null!==a&&(r="atan2"),"fragment"===e.shaderStage||r!==La.DFDX&&r!==La.DFDY||(console.warn(`THREE.TSL: '${r}' is not supported in the ${e.shaderStage} stage.`),r="/*"+r+"*/"),c.push(n.build(e,i)),null!==a&&c.push(a.build(e,i)),null!==o&&c.push(o.build(e,i))):c.push(n.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)),e.format(`${e.getMethod(r,s)}( ${c.join(", ")} )`,s,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}La.ALL="all",La.ANY="any",La.RADIANS="radians",La.DEGREES="degrees",La.EXP="exp",La.EXP2="exp2",La.LOG="log",La.LOG2="log2",La.SQRT="sqrt",La.INVERSE_SQRT="inversesqrt",La.FLOOR="floor",La.CEIL="ceil",La.NORMALIZE="normalize",La.FRACT="fract",La.SIN="sin",La.COS="cos",La.TAN="tan",La.ASIN="asin",La.ACOS="acos",La.ATAN="atan",La.ABS="abs",La.SIGN="sign",La.LENGTH="length",La.NEGATE="negate",La.ONE_MINUS="oneMinus",La.DFDX="dFdx",La.DFDY="dFdy",La.ROUND="round",La.RECIPROCAL="reciprocal",La.TRUNC="trunc",La.FWIDTH="fwidth",La.TRANSPOSE="transpose",La.BITCAST="bitcast",La.EQUALS="equals",La.MIN="min",La.MAX="max",La.STEP="step",La.REFLECT="reflect",La.DISTANCE="distance",La.DIFFERENCE="difference",La.DOT="dot",La.CROSS="cross",La.POW="pow",La.TRANSFORM_DIRECTION="transformDirection",La.MIX="mix",La.CLAMP="clamp",La.REFRACT="refract",La.SMOOTHSTEP="smoothstep",La.FACEFORWARD="faceforward";const Fa=$i(1e-6),Ba=$i(1e6),Da=$i(Math.PI),Ia=$i(2*Math.PI),Va=Di(La,La.ALL).setParameterLength(1),Ua=Di(La,La.ANY).setParameterLength(1),Oa=Di(La,La.RADIANS).setParameterLength(1),ka=Di(La,La.DEGREES).setParameterLength(1),Ga=Di(La,La.EXP).setParameterLength(1),za=Di(La,La.EXP2).setParameterLength(1),Ha=Di(La,La.LOG).setParameterLength(1),$a=Di(La,La.LOG2).setParameterLength(1),Wa=Di(La,La.SQRT).setParameterLength(1),ja=Di(La,La.INVERSE_SQRT).setParameterLength(1),qa=Di(La,La.FLOOR).setParameterLength(1),Xa=Di(La,La.CEIL).setParameterLength(1),Ka=Di(La,La.NORMALIZE).setParameterLength(1),Ya=Di(La,La.FRACT).setParameterLength(1),Qa=Di(La,La.SIN).setParameterLength(1),Za=Di(La,La.COS).setParameterLength(1),Ja=Di(La,La.TAN).setParameterLength(1),eo=Di(La,La.ASIN).setParameterLength(1),to=Di(La,La.ACOS).setParameterLength(1),ro=Di(La,La.ATAN).setParameterLength(1,2),so=Di(La,La.ABS).setParameterLength(1),io=Di(La,La.SIGN).setParameterLength(1),no=Di(La,La.LENGTH).setParameterLength(1),ao=Di(La,La.NEGATE).setParameterLength(1),oo=Di(La,La.ONE_MINUS).setParameterLength(1),uo=Di(La,La.DFDX).setParameterLength(1),lo=Di(La,La.DFDY).setParameterLength(1),co=Di(La,La.ROUND).setParameterLength(1),ho=Di(La,La.RECIPROCAL).setParameterLength(1),po=Di(La,La.TRUNC).setParameterLength(1),go=Di(La,La.FWIDTH).setParameterLength(1),mo=Di(La,La.TRANSPOSE).setParameterLength(1),fo=Di(La,La.BITCAST).setParameterLength(2),yo=(e,t)=>(console.warn('THREE.TSL: "equals" is deprecated. Use "equal" inside a vector instead, like: "bvec*( equal( ... ) )"'),da(e,t)),xo=Di(La,La.MIN).setParameterLength(2,1/0),bo=Di(La,La.MAX).setParameterLength(2,1/0),To=Di(La,La.STEP).setParameterLength(2),_o=Di(La,La.REFLECT).setParameterLength(2),vo=Di(La,La.DISTANCE).setParameterLength(2),No=Di(La,La.DIFFERENCE).setParameterLength(2),So=Di(La,La.DOT).setParameterLength(2),wo=Di(La,La.CROSS).setParameterLength(2),Eo=Di(La,La.POW).setParameterLength(2),Ao=Di(La,La.POW,2).setParameterLength(1),Ro=Di(La,La.POW,3).setParameterLength(1),Co=Di(La,La.POW,4).setParameterLength(1),Mo=Di(La,La.TRANSFORM_DIRECTION).setParameterLength(2),Po=e=>oa(io(e),Eo(so(e),1/3)),Lo=e=>So(e,e),Fo=Di(La,La.MIX).setParameterLength(3),Bo=(e,t=0,r=1)=>Li(new La(La.CLAMP,Li(e),Li(t),Li(r))),Do=e=>Bo(e),Io=Di(La,La.REFRACT).setParameterLength(3),Vo=Di(La,La.SMOOTHSTEP).setParameterLength(3),Uo=Di(La,La.FACEFORWARD).setParameterLength(3),Oo=Ui((([e])=>{const t=So(e.xy,Xi(12.9898,78.233)),r=la(t,Da);return Ya(Qa(r).mul(43758.5453))})),ko=(e,t,r)=>Fo(t,r,e),Go=(e,t,r)=>Vo(t,r,e),zo=(e,t)=>(console.warn('THREE.TSL: "atan2" is overloaded. Use "atan" instead.'),ro(e,t)),Ho=Uo,$o=ja;ni("all",Va),ni("any",Ua),ni("equals",yo),ni("radians",Oa),ni("degrees",ka),ni("exp",Ga),ni("exp2",za),ni("log",Ha),ni("log2",$a),ni("sqrt",Wa),ni("inverseSqrt",ja),ni("floor",qa),ni("ceil",Xa),ni("normalize",Ka),ni("fract",Ya),ni("sin",Qa),ni("cos",Za),ni("tan",Ja),ni("asin",eo),ni("acos",to),ni("atan",ro),ni("abs",so),ni("sign",io),ni("length",no),ni("lengthSq",Lo),ni("negate",ao),ni("oneMinus",oo),ni("dFdx",uo),ni("dFdy",lo),ni("round",co),ni("reciprocal",ho),ni("trunc",po),ni("fwidth",go),ni("atan2",zo),ni("min",xo),ni("max",bo),ni("step",To),ni("reflect",_o),ni("distance",vo),ni("dot",So),ni("cross",wo),ni("pow",Eo),ni("pow2",Ao),ni("pow3",Ro),ni("pow4",Co),ni("transformDirection",Mo),ni("mix",ko),ni("clamp",Bo),ni("refract",Io),ni("smoothstep",Go),ni("faceForward",Uo),ni("difference",No),ni("saturate",Do),ni("cbrt",Po),ni("transpose",mo),ni("rand",Oo);class Wo extends $s{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}getNodeType(e){const{ifNode:t,elseNode:r}=e.getNodeProperties(this);if(void 0===t)return this.setup(e),this.getNodeType(e);const s=t.getNodeType(e);if(null!==r){const t=r.getNo