UNPKG

three

Version:

JavaScript 3D library

6 lines 580 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 b,Texture as x,UnsignedIntType as T,IntType as _,NearestFilter as v,Sphere as N,BackSide as S,DoubleSide as E,Euler as R,CubeTexture as A,CubeReflectionMapping as w,CubeRefractionMapping as C,TangentSpaceNormalMap as M,ObjectSpaceNormalMap as P,InstancedInterleavedBuffer as B,InstancedBufferAttribute as L,DataArrayTexture as F,FloatType as I,FramebufferTexture as D,LinearMipmapLinearFilter as U,DepthTexture as V,Material as O,NormalBlending as G,LineBasicMaterial as k,LineDashedMaterial as z,NoBlending as $,MeshNormalMaterial as H,SRGBColorSpace as W,WebGLCubeRenderTarget as q,BoxGeometry as j,Mesh as X,Scene as K,LinearFilter as Y,CubeCamera as Q,EquirectangularReflectionMapping as Z,EquirectangularRefractionMapping as J,AddOperation as ee,MixOperation as te,MultiplyOperation as re,MeshBasicMaterial as se,MeshLambertMaterial as ie,MeshPhongMaterial as ne,OrthographicCamera as ae,PerspectiveCamera as oe,RenderTarget as ue,LinearSRGBColorSpace as le,RGBAFormat as de,HalfFloatType as ce,CubeUVReflectionMapping as he,BufferGeometry as pe,BufferAttribute as ge,MeshStandardMaterial as me,MeshPhysicalMaterial as fe,MeshToonMaterial as ye,MeshMatcapMaterial as be,SpriteMaterial as xe,PointsMaterial as Te,ShadowMaterial as _e,Uint32BufferAttribute as ve,Uint16BufferAttribute as Ne,arrayNeedsUint32 as Se,Camera as Ee,DepthStencilFormat as Re,DepthFormat as Ae,UnsignedInt248Type as we,UnsignedByteType as Ce,Plane as Me,Object3D as Pe,warnOnce as Be,LinearMipMapLinearFilter as Le,Float32BufferAttribute as Fe,UVMapping as Ie,VSMShadowMap as De,LessCompare as Ue,RGFormat as Ve,BasicShadowMap as Oe,SphereGeometry as Ge,LinearMipmapNearestFilter as ke,NearestMipmapLinearFilter as ze,Float16BufferAttribute as $e,REVISION as He,ArrayCamera as We,PlaneGeometry as qe,FrontSide as je,CustomBlending as Xe,AddEquation as Ke,ZeroFactor as Ye,CylinderGeometry as Qe,Quaternion as Ze,WebXRController as Je,RAD2DEG as et,PCFShadowMap as tt,FrustumArray as rt,Frustum as st,DataTexture as it,RedIntegerFormat as nt,RedFormat as at,ShortType as ot,ByteType as ut,UnsignedShortType as lt,RGIntegerFormat as dt,RGBIntegerFormat as ct,RGBFormat as ht,RGBAIntegerFormat as pt,createCanvasElement as gt,ReverseSubtractEquation as mt,SubtractEquation as ft,OneMinusDstAlphaFactor as yt,OneMinusDstColorFactor as bt,OneMinusSrcAlphaFactor as xt,OneMinusSrcColorFactor as Tt,DstAlphaFactor as _t,DstColorFactor as vt,SrcAlphaSaturateFactor as Nt,SrcAlphaFactor as St,SrcColorFactor as Et,OneFactor as Rt,CullFaceNone as At,CullFaceBack as wt,CullFaceFront as Ct,MultiplyBlending as Mt,SubtractiveBlending as Pt,AdditiveBlending as Bt,NotEqualDepth as Lt,GreaterDepth as Ft,GreaterEqualDepth as It,EqualDepth as Dt,LessEqualDepth as Ut,LessDepth as Vt,AlwaysDepth as Ot,NeverDepth as Gt,UnsignedShort4444Type as kt,UnsignedShort5551Type as zt,UnsignedInt5999Type as $t,UnsignedInt101111Type as Ht,AlphaFormat as Wt,RGB_S3TC_DXT1_Format as qt,RGBA_S3TC_DXT1_Format as jt,RGBA_S3TC_DXT3_Format as Xt,RGBA_S3TC_DXT5_Format as Kt,RGB_PVRTC_4BPPV1_Format as Yt,RGB_PVRTC_2BPPV1_Format as Qt,RGBA_PVRTC_4BPPV1_Format as Zt,RGBA_PVRTC_2BPPV1_Format as Jt,RGB_ETC1_Format as er,RGB_ETC2_Format as tr,RGBA_ETC2_EAC_Format as rr,RGBA_ASTC_4x4_Format as sr,RGBA_ASTC_5x4_Format as ir,RGBA_ASTC_5x5_Format as nr,RGBA_ASTC_6x5_Format as ar,RGBA_ASTC_6x6_Format as or,RGBA_ASTC_8x5_Format as ur,RGBA_ASTC_8x6_Format as lr,RGBA_ASTC_8x8_Format as dr,RGBA_ASTC_10x5_Format as cr,RGBA_ASTC_10x6_Format as hr,RGBA_ASTC_10x8_Format as pr,RGBA_ASTC_10x10_Format as gr,RGBA_ASTC_12x10_Format as mr,RGBA_ASTC_12x12_Format as fr,RGBA_BPTC_Format as yr,RED_RGTC1_Format as br,SIGNED_RED_RGTC1_Format as xr,RED_GREEN_RGTC2_Format as Tr,SIGNED_RED_GREEN_RGTC2_Format as _r,MirroredRepeatWrapping as vr,ClampToEdgeWrapping as Nr,RepeatWrapping as Sr,NearestMipmapNearestFilter as Er,NotEqualCompare as Rr,GreaterCompare as Ar,GreaterEqualCompare as wr,EqualCompare as Cr,LessEqualCompare as Mr,AlwaysCompare as Pr,NeverCompare as Br,LinearTransfer as Lr,getByteLength as Fr,TimestampQuery as Ir,NotEqualStencilFunc as Dr,GreaterStencilFunc as Ur,GreaterEqualStencilFunc as Vr,EqualStencilFunc as Or,LessEqualStencilFunc as Gr,LessStencilFunc as kr,AlwaysStencilFunc as zr,NeverStencilFunc as $r,DecrementWrapStencilOp as Hr,IncrementWrapStencilOp as Wr,DecrementStencilOp as qr,IncrementStencilOp as jr,InvertStencilOp as Xr,ReplaceStencilOp as Kr,ZeroStencilOp as Yr,KeepStencilOp as Qr,MaxEquation as Zr,MinEquation as Jr,SpotLight as es,PointLight as ts,DirectionalLight as rs,RectAreaLight as ss,AmbientLight as is,HemisphereLight as ns,LightProbe as as,LinearToneMapping as os,ReinhardToneMapping as us,CineonToneMapping as ls,ACESFilmicToneMapping as ds,AgXToneMapping as cs,NeutralToneMapping as hs,Group as ps,Loader as gs,FileLoader as ms,MaterialLoader as fs,ObjectLoader as ys}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,ExternalTexture,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,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,Timer,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 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"],xs=new WeakMap;class Ts{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=bs,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}needsVelocity(e){const t=e.getMRT();return null!==t&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:r,material:s,object:i}=e;if(t={material:this.getMaterialData(s),geometry:{id:r.id,attributes:this.getAttributesData(r.attributes),indexVersion:r.index?r.index.version:null,drawRange:{start:r.drawRange.start,count:r.drawRange.count}},worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:r,height:s}=e.context;t.bufferWidth=r,t.bufferHeight=s}t.lights=this.getLightsData(e.lightsNode.getLights()),this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const r in e){const s=e[r];t[r]={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,t){const{object:r,material:s,geometry:i}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(r.matrixWorld))return n.worldMatrix.copy(r.matrixWorld),!1;const a=n.material;for(const e in a){const t=a[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return a[e]=r,!1}if(a.transmission>0){const{width:t,height:r}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==r)return n.bufferWidth=t,n.bufferHeight=r,!1}const o=n.geometry,u=i.attributes,l=o.attributes,d=Object.keys(l),c=Object.keys(u);if(o.id!==i.id)return o.id=i.id,!1;if(d.length!==c.length)return n.geometry.attributes=this.getAttributesData(u),!1;for(const e of d){const t=l[e],r=u[e];if(void 0===r)return delete l[e],!1;if(t.version!==r.version)return t.version=r.version,!1}const h=i.index,p=o.indexVersion,g=h?h.version:null;if(p!==g)return o.indexVersion=g,!1;if(o.drawRange.start!==i.drawRange.start||o.drawRange.count!==i.drawRange.count)return o.drawRange.start=i.drawRange.start,o.drawRange.count=i.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let t=0;t<n.morphTargetInfluences.length;t++)n.morphTargetInfluences[t]!==r.morphTargetInfluences[t]&&(e=!0);if(e)return!0}if(n.lights)for(let e=0;e<t.length;e++)if(n.lights[e].map!==t[e].map)return!1;return n.center&&!1===n.center.equals(r.center)?(n.center.copy(r.center),!0):(null!==e.bundle&&(n.version=e.bundle.version),!0)}getLightsData(e){const t=[];for(const r of e)!0===r.isSpotLight&&null!==r.map&&t.push({map:r.map.version});return t}getLights(e,t){if(xs.has(e)){const r=xs.get(e);if(r.renderId===t)return r.lightsData}const r=this.getLightsData(e.getLights());return xs.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)}}function _s(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 vs=e=>_s(e),Ns=e=>_s(e),Ss=(...e)=>_s(e);function Es(e,t=!1){const r=[];!0===e.isNode&&r.push(e.id);for(const{property:s,childNode:i}of Rs(e))r.push(_s(s.slice(0,-4)),i.getCacheKey(t));return _s(r)}function*Rs(e,t=!1){for(const r of Object.getOwnPropertyNames(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(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&&"function"==typeof i.toJSON)&&(yield{property:r,index:e,childNode:i})}}}const As=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),ws=new WeakMap;function Cs(e){return As.get(e)}function Ms(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 Ps(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 Bs(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 console.error("THREE.TSL: Unsupported type:",e)}function Ls(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)?48:/mat4/.test(e)?64:void console.error("THREE.TSL: Unsupported type:",e)}function Fs(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 Is(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?Vs(u[0]):null}function Ds(e){let t=ws.get(e);return void 0===t&&(t={},ws.set(e,t)),t}function Us(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 Vs(e){return Uint8Array.from(atob(e),e=>e.charCodeAt(0)).buffer}var Os=Object.freeze({__proto__:null,arrayBufferToBase64:Us,base64ToArrayBuffer:Vs,getByteBoundaryFromType:Ls,getCacheKey:Es,getDataFromObject:Ds,getLengthFromType:Ps,getMemoryLengthFromType:Bs,getNodeChildren:Rs,getTypeFromLength:Cs,getTypedArrayFromType:Ms,getValueFromType:Is,getValueType:Fs,hash:Ss,hashArray:Ns,hashString:vs});const Gs={VERTEX:"vertex",FRAGMENT:"fragment"},ks={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},zs={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},$s={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},Hs=["fragment","vertex"],Ws=["setup","analyze","generate"],qs=[...Hs,"compute"],js=["x","y","z","w"],Xs={analyze:"setup",generate:"analyze"};let Ks=0;class Ys extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=ks.NONE,this.updateBeforeType=ks.NONE,this.updateAfterType=ks.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:Ks++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this),this}onFrameUpdate(e){return this.onUpdate(e,ks.FRAME)}onRenderUpdate(e){return this.onUpdate(e,ks.RENDER)}onObjectUpdate(e){return this.onUpdate(e,ks.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of Rs(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=Ss(Es(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}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(){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);const s=e.getDataFromNode(this);s.buildStages=s.buildStages||{},s.buildStages[e.buildStage]=!0;const i=Xs[e.buildStage];if(i&&!0!==s.buildStages[i]){const t=e.getBuildStage();e.setBuildStage(i),this.build(e),e.setBuildStage(t)}e.addNode(this),e.addChain(this);let n=null;const a=e.getBuildStage();if("setup"===a){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)}}n=t.outputNode}else if("analyze"===a)this.analyze(e,t);else if("generate"===a){if(1===this.generate.length){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):(console.warn("THREE.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&&(console.error(`THREE.TSL: Invalid generated code, expected a "${t}".`),n=e.generateConst(t))}return e.removeChain(this),e.addSequentialNode(this),n}getSerializeChildren(){return Rs(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.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}}class Qs extends Ys{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 Zs extends Ys{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 Js extends Ys{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 ei extends Js{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);if(e.getComponentType(u)!==n){const t=e.getTypeFromLength(l,n);i=e.format(i,u,t)}a.push(i)}const u=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(u,r,t)}}const ti=js.join("");class ri extends Ys{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(js.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){const r=this.node,s=e.getTypeLength(r.getNodeType(e));let i=null;if(s>1){let n=null;this.getVectorLength()>=s&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const a=r.build(e,n);i=this.components.length===s&&this.components===ti.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 si extends Js{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=js[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(u+"."+t)}return`${e.getType(i)}( ${d.join(", ")} )`}}class ii extends Js{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=js[e];r===t[l]?(u.push("1.0 - "+a+"."+r),l++):u.push(a+"."+r)}return`${e.getType(s)}( ${u.join(", ")} )`}}class ni extends Ys{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?Fs(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=Fs(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Us(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Is(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 ai=/float|u?int/;class oi extends ni{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 ai.test(r)&&ai.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class ui extends Ys{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return(!this.structNode.isMemberNode||!1!==this.structNode.hasMember(e))&&"void"!==this.structNode.getMemberType(e,this.property)}getNodeType(e){return!1===this.hasMember(e)?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(!1===this.hasMember(e))return"float";const r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}generate(e){if(!1===this.hasMember(e)){console.warn(`THREE.TSL: Member "${this.property}" does not exist in struct.`);const t=this.getNodeType(e);return e.generateConst(t)}return this.structNode.build(e)+"."+this.property}}let li=null;const di=new Map;function ci(e,t){if(di.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`);di.set(e,t),"assign"!==e&&(Ys.prototype[e]=function(...e){return this.isStackNode?this.add(t(...e)):t(this,...e)},Ys.prototype[e+"Assign"]=function(...e){return this.isStackNode?this.assign(e[0],t(...e)):this.assign(t(this,...e))})}}const hi=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("");Ys.prototype.assign=function(...e){if(!0!==this.isStackNode)return null!==li?li.assign(this,...e):console.error("THREE.TSL: No stack defined for assign operation. Make sure the assign is inside a Fn()."),this;{const t=di.get("assign");return this.add(t(...e))}},Ys.prototype.toVarIntent=function(){return this},Ys.prototype.get=function(e){return new ui(this,e)};const pi={};function gi(e,t,r){pi[e]=pi[t]=pi[r]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new ri(this,e),this._cache[e]=t),t},set(t){this[e].assign(Gi(t))}};const s=e.toUpperCase(),i=t.toUpperCase(),n=r.toUpperCase();Ys.prototype["set"+s]=Ys.prototype["set"+i]=Ys.prototype["set"+n]=function(t){const r=hi(e);return new si(this,r,Gi(t))},Ys.prototype["flip"+s]=Ys.prototype["flip"+i]=Ys.prototype["flip"+n]=function(){const t=hi(e);return new ii(this,t)}}const mi=["x","y","z","w"],fi=["r","g","b","a"],yi=["s","t","p","q"];for(let e=0;e<4;e++){let t=mi[e],r=fi[e],s=yi[e];gi(t,r,s);for(let i=0;i<4;i++){t=mi[e]+mi[i],r=fi[e]+fi[i],s=yi[e]+yi[i],gi(t,r,s);for(let n=0;n<4;n++){t=mi[e]+mi[i]+mi[n],r=fi[e]+fi[i]+fi[n],s=yi[e]+yi[i]+yi[n],gi(t,r,s);for(let a=0;a<4;a++)t=mi[e]+mi[i]+mi[n]+mi[a],r=fi[e]+fi[i]+fi[n]+fi[a],s=yi[e]+yi[i]+yi[n]+yi[a],gi(t,r,s)}}}for(let e=0;e<32;e++)pi[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new Qs(this,new oi(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(Gi(t))}};Object.defineProperties(Ys.prototype,pi);const bi=new WeakMap,xi=function(e,t=null){for(const r in e)e[r]=Gi(e[r],t);return e},Ti=function(e,t=null){const r=e.length;for(let s=0;s<r;s++)e[s]=Gi(e[s],t);return e},_i=function(e,t=null,r=null,s=null){function i(e){return null!==s?(e=Gi(Object.assign(e,s)),!0===s.intent&&(e=e.toVarIntent())):e=Gi(e),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(...$i(l(t)))):null!==r?(r=Gi(r),n=(...s)=>i(new e(t,...$i(l(s)),r))):n=(...r)=>i(new e(t,...$i(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},vi=function(e,...t){return Gi(new e(...$i(t)))};class Ni extends Ys{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=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,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;e.subBuildFn=i;let o=null;if(t.layout){let s=bi.get(e.constructor);void 0===s&&(s=new WeakMap,bi.set(e.constructor,s));let i=s.get(t);void 0===i&&(i=Gi(e.buildFunctionNode(t)),s.set(t,i)),e.addInclude(i);const n=r?function(e){let t;zi(e);t=e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)?[...e]:e[0];return t}(r):null;o=Gi(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 zi(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 Gi(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 Ys&&(n=void 0===e[s]?e[t++]:Reflect.get(e,s,i));else n=Reflect.get(r,s,i);n=Gi(n)}return n}})}(r):null,n=Array.isArray(r)?r.length>0:null!==r,a=t.jsFunc,u=n||a.length>1?a(i,s):a(s);o=Gi(u)}return e.subBuildFn=a,t.once&&(s[n]=o),o}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);if("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 r}}class Si extends Ys{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 Gi(new Ni(this,e))}setup(){return this.call()}}const Ei=[!1,!0],Ri=[0,1,2,3],Ai=[-1,-2],wi=[.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],Ci=new Map;for(const e of Ei)Ci.set(e,new oi(e));const Mi=new Map;for(const e of Ri)Mi.set(e,new oi(e,"uint"));const Pi=new Map([...Mi].map(e=>new oi(e.value,"int")));for(const e of Ai)Pi.set(e,new oi(e,"int"));const Bi=new Map([...Pi].map(e=>new oi(e.value)));for(const e of wi)Bi.set(e,new oi(e));for(const e of wi)Bi.set(-e,new oi(-e));const Li={bool:Ci,uint:Mi,ints:Pi,float:Bi},Fi=new Map([...Ci,...Bi]),Ii=(e,t)=>Fi.has(e)?Fi.get(e):!0===e.isNode?e:new oi(e,t),Di=function(e,t=null){return(...r)=>{for(const t of r)if(void 0===t)return console.error(`THREE.TSL: Invalid parameter for the type "${e}".`),Gi(new oi(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=[Is(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return ki(t.get(r[0]));if(1===r.length){const t=Ii(r[0],e);return t.nodeType===e?ki(t):ki(new Zs(t,e))}const s=r.map(e=>Ii(e));return ki(new ei(s,e))}},Ui=e=>"object"==typeof e&&null!==e?e.value:e,Vi=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function Oi(e,t){return new Si(e,t)}const Gi=(e,t=null)=>function(e,t=null){const r=Fs(e);return"node"===r?e:null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?Gi(Ii(e,t)):"shader"===r?e.isFn?e:Ki(e):e}(e,t),ki=(e,t=null)=>Gi(e,t).toVarIntent(),zi=(e,t=null)=>new xi(e,t),$i=(e,t=null)=>new Ti(e,t),Hi=(e,t=null,r=null,s=null)=>new _i(e,t,r,s),Wi=(e,...t)=>new vi(e,...t),qi=(e,t=null,r=null,s={})=>new _i(e,t,r,{intent:!0,...s});let ji=0;class Xi extends Ys{constructor(e,t=null){super();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)),this.shaderNode=new Oi(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"+ji++,type:t,inputs:[]};for(const t in e)"return"!==t&&r.inputs.push({name:t,type:e[t]});e=r}return this.shaderNode.setLayout(e),this}getNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){const t=this.shaderNode.call(e);return"void"===this.shaderNode.nodeType&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){const t=this.getNodeType(e);return console.error('THREE.TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".'),e.generateConst(t)}}function Ki(e,t=null){const r=new Xi(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 Yi=e=>{li=e},Qi=()=>li,Zi=(...e)=>li.If(...e);function Ji(e){return li&&li.add(e),e}ci("toStack",Ji);const en=new Di("color"),tn=new Di("float",Li.float),rn=new Di("int",Li.ints),sn=new Di("uint",Li.uint),nn=new Di("bool",Li.bool),an=new Di("vec2"),on=new Di("ivec2"),un=new Di("uvec2"),ln=new Di("bvec2"),dn=new Di("vec3"),cn=new Di("ivec3"),hn=new Di("uvec3"),pn=new Di("bvec3"),gn=new Di("vec4"),mn=new Di("ivec4"),fn=new Di("uvec4"),yn=new Di("bvec4"),bn=new Di("mat2"),xn=new Di("mat3"),Tn=new Di("mat4");ci("toColor",en),ci("toFloat",tn),ci("toInt",rn),ci("toUint",sn),ci("toBool",nn),ci("toVec2",an),ci("toIVec2",on),ci("toUVec2",un),ci("toBVec2",ln),ci("toVec3",dn),ci("toIVec3",cn),ci("toUVec3",hn),ci("toBVec3",pn),ci("toVec4",gn),ci("toIVec4",mn),ci("toUVec4",fn),ci("toBVec4",yn),ci("toMat2",bn),ci("toMat3",xn),ci("toMat4",Tn);const _n=Hi(Qs).setParameterLength(2),vn=(e,t)=>Gi(new Zs(Gi(e),t));ci("element",_n),ci("convert",vn);ci("append",e=>(console.warn("THREE.TSL: .append() has been renamed to .toStack()."),Ji(e)));class Nn extends Ys{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}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 Sn=(e,t)=>Gi(new Nn(e,t)),En=(e,t)=>Gi(new Nn(e,t,!0)),Rn=Wi(Nn,"vec4","DiffuseColor"),An=Wi(Nn,"vec3","EmissiveColor"),wn=Wi(Nn,"float","Roughness"),Cn=Wi(Nn,"float","Metalness"),Mn=Wi(Nn,"float","Clearcoat"),Pn=Wi(Nn,"float","ClearcoatRoughness"),Bn=Wi(Nn,"vec3","Sheen"),Ln=Wi(Nn,"float","SheenRoughness"),Fn=Wi(Nn,"float","Iridescence"),In=Wi(Nn,"float","IridescenceIOR"),Dn=Wi(Nn,"float","IridescenceThickness"),Un=Wi(Nn,"float","AlphaT"),Vn=Wi(Nn,"float","Anisotropy"),On=Wi(Nn,"vec3","AnisotropyT"),Gn=Wi(Nn,"vec3","AnisotropyB"),kn=Wi(Nn,"color","SpecularColor"),zn=Wi(Nn,"float","SpecularF90"),$n=Wi(Nn,"float","Shininess"),Hn=Wi(Nn,"vec4","Output"),Wn=Wi(Nn,"float","dashSize"),qn=Wi(Nn,"float","gapSize"),jn=Wi(Nn,"float","pointWidth"),Xn=Wi(Nn,"float","IOR"),Kn=Wi(Nn,"float","Transmission"),Yn=Wi(Nn,"float","Thickness"),Qn=Wi(Nn,"float","AttenuationDistance"),Zn=Wi(Nn,"color","AttenuationColor"),Jn=Wi(Nn,"float","Dispersion");class ea extends Ys{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 ta=e=>new ea(e),ra=(e,t=0)=>new ea(e,!0,t),sa=ra("frame"),ia=ra("render"),na=ta("object");class aa extends ni{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=na}setName(e){return this.name=e,this}label(e){return console.warn('THREE.TSL: "label()" has been deprecated. Use "setName()" instead.'),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 oa=(e,t)=>{const r=Vi(t||e);return r===e&&(e=Is(r)),e=e&&!0===e.isNode?e.node&&e.node.value||e.value:e,Gi(new aa(e,r))};class ua extends Js{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getArrayCount(){return this.count}getNodeType(e){return null===this.nodeType&&(this.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 la=(...e)=>{let t;if(1===e.length){const r=e[0];t=new ua(null,r.length,r)}else{const r=e[0],s=e[1];t=new ua(r,s)}return Gi(t)};ci("toArray",(e,t)=>la(Array(t).fill(e)));class da extends Js{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const r=e.getTypeLength(t.node.getNodeType(e));return js.join("").slice(0,r)!==t.components}return!1}setup(e){const{targetNode:t,sourceNode:r}=this,s=t.getScope();e.getNodeProperties(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 ca=Hi(da).setParameterLength(2);ci("assign",ca);class ha extends Js{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){const t=[],r=this.functionNode,s=r.getInputs(e),i=this.parameters,n=(t,r)=>{const s=r.type;let i;return i="pointer"===s?"&"+t.build(e):t.build(e,s),i};if(Array.isArray(i)){if(i.length>s.length)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(tn(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(tn(0),e)))}return`${r.build(e,"property")}( ${t.join(", ")} )`}}const pa=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?$i(t):zi(t[0]),Gi(new ha(Gi(e),t)));ci("call",pa);const ga={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class ma extends Js{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new ma(e,t,r);for(let t=0;t<s.length-1;t++)i=new ma(e,i,s[t]);t=i,r=s[s.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(ga[this.op],t)}getNodeType(e,t=null){const r=this.op,s=this.aNode,i=this.bNode,n=s.getNodeType(e),a=i?i.getNodeType(e):null;if("void"===n||"void"===a)return t||"void";if("%"===r)return n;if("~"===r||"&"===r||"|"===r||"^"===r||">>"===r||"<<"===r)return e.getIntegerType(n);if("!"===r||"&&"===r||"||"===r||"^^"===r)return"bool";if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r){const t=Math.max(e.getTypeLength(n),e.getTypeLength(a));return t>1?`bvec${t}`:"bool"}if(e.isMatrix(n)){if("float"===a)return n;if(e.isVector(a))return e.getVectorFromMatrix(n);if(e.isMatrix(a))return n}else if(e.isMatrix(a)){if("float"===n)return a;if(e.isVector(n))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(n)?a:n}generate(e,t){const r=this.op,{aNode:s,bNode:i}=this,n=this.getNodeType(e,t);let a=null,o=null;"void"!==n?(a=s.getNodeType(e),o=i?i.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r||"!="===r?e.isVector(a)?o=a:e.isVector(o)?a=o:a!==o&&(a=o="float"):">>"===r||"<<"===r?(a=n,o=e.changeComponentType(o,"uint")):"%"===r?(a=n,o=e.isInteger(a)&&e.isInteger(o)?o:a):e.isMatrix(a)?"float"===o?o="float":e.isVector(o)?o=e.getVectorFromMatrix(a):e.isMatrix(o)||(a=o=n):a=e.isMatrix(o)?"float"===a?"float":e.isVector(a)?e.getVectorFromMatrix(o):o=n:o=n):a=o=n;const u=s.build(e,a),d=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 fa=qi(ma,"+").setParameterLength(2,1/0).setName("add"),ya=qi(ma,"-").setParameterLength(2,1/0).setName("sub"),ba=qi(ma,"*").setParameterLength(2,1/0).setName("mul"),xa=qi(ma,"/").setParameterLength(2,1/0).setName("div"),Ta=qi(ma,"%").setParameterLength(2).setName("mod"),_a=qi(ma,"==").setParameterLength(2).setName("equal"),va=qi(ma,"!=").setParameterLength(2).setName("notEqual"),Na=qi(ma,"<").setParameterLength(2).setName("lessThan"),Sa=qi(ma,">").setParameterLength(2).setName("greaterThan"),Ea=qi(ma,"<=").setParameterLength(2).setName("lessThanEqual"),Ra=qi(ma,">=").setParameterLength(2).setName("greaterThanEqual"),Aa=qi(ma,"&&").setParameterLength(2,1/0).setName("and"),wa=qi(ma,"||").setParameterLength(2,1/0).setName("or"),Ca=qi(ma,"!").setParameterLength(1).setName("not"),Ma=qi(ma,"^^").setParameterLength(2).setName("xor"),Pa=qi(ma,"&").setParameterLength(2).setName("bitAnd"),Ba=qi(ma,"~").setParameterLength(2).setName("bitNot"),La=qi(ma,"|").setParameterLength(2).setName("bitOr"),Fa=qi(ma,"^").setParameterLength(2).setName("bitXor"),Ia=qi(ma,"<<").setParameterLength(2).setName("shiftLeft"),Da=qi(ma,">>").setParameterLength(2).setName("shiftRight"),Ua=Ki(([e])=>(e.addAssign(1),e)),Va=Ki(([e])=>(e.subAssign(1),e)),Oa=Ki(([e])=>{const t=rn(e).toConst();return e.addAssign(1),t}),Ga=Ki(([e])=>{const t=rn(e).toConst();return e.subAssign(1),t});ci("add",fa),ci("sub",ya),ci("mul",ba),ci("div",xa),ci("mod",Ta),ci("equal",_a),ci("notEqual",va),ci("lessThan",Na),ci("greaterThan",Sa),ci("lessThanEqual",Ea),ci("greaterThanEqual",Ra),ci("and",Aa),ci("or",wa),ci("not",Ca),ci("xor",Ma),ci("bitAnd",Pa),ci("bitNot",Ba),ci("bitOr",La),ci("bitXor",Fa),ci("shiftLeft",Ia),ci("shiftRight",Da),ci("incrementBefore",Ua),ci("decrementBefore",Va),ci("increment",Oa),ci("decrement",Ga);const ka=(e,t)=>(console.warn('THREE.TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.'),Ta(rn(e),rn(t)));ci("modInt",ka);class za extends Js{static get type(){return"MathNode"}constructor(e,t,r=null,s=null){if(super(),(e===za.MAX||e===za.MIN)&&arguments.length>3){let i=new za(e,t,r);for(let t=2;t<arguments.length-1;t++)i=new za(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===za.LENGTH||t===za.DISTANCE||t===za.DOT?"float":t===za.CROSS?"vec3":t===za.ALL||t===za.ANY?"bool":t===za.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){const{aNode:t,bNode:r,method:s}=this;let i=null;if(s===za.ONE_MINUS)i=ya(1,t);else if(s===za.RECIPROCAL)i=xa(1,t);else if(s===za.DIFFERENCE)i=go(ya(t,r));else if(s===za.TRANSFORM_DIRECTION){let s=t,n=r;e.isMatrix(s.getNodeType(e))?n=gn(dn(n),0):s=gn(dn(s),0);const a=ba(s,n).xyz;i=no(a)}return null!==i?i:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.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===za.NEGATE)return e.format("( - "+n.build(e,i)+" )",s,t);{const c=[];return r===za.CROSS?c.push(n.build(e,s),a.build(e,s)):u===l&&r===za.STEP?c.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),a.build(e,i)):u!==l||r!==za.MIN&&r!==za.MAX?r===za.REFRACT?c.push(n.build(e,i),a.build(e,i),o.build(e,"float")):r===za.MIX?c.push