three
Version:
JavaScript 3D library
6 lines • 517 kB
JavaScript
/**
* @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 o,EventDispatcher as a,MathUtils as u,WebGLCoordinateSystem as l,WebGPUCoordinateSystem as d,ColorManagement as c,SRGBTransfer as h,NoToneMapping as p,StaticDrawUsage as g,InterleavedBuffer as m,DynamicDrawUsage as f,InterleavedBufferAttribute as y,NoColorSpace as x,UnsignedIntType as b,IntType as T,BackSide as _,CubeReflectionMapping as v,CubeRefractionMapping as N,TangentSpaceNormalMap as S,ObjectSpaceNormalMap as R,InstancedInterleavedBuffer as A,InstancedBufferAttribute as E,DataArrayTexture as C,FloatType as w,FramebufferTexture as M,LinearMipmapLinearFilter as B,DepthTexture as F,Material as U,NormalBlending as P,LineBasicMaterial as I,LineDashedMaterial as L,NoBlending as D,MeshNormalMaterial as V,WebGLCubeRenderTarget as O,BoxGeometry as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as W,CubeTexture as H,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as X,MixOperation as K,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as re,MeshToonMaterial as se,MeshMatcapMaterial as ie,SpriteMaterial as ne,PointsMaterial as oe,ShadowMaterial as ae,arrayNeedsUint32 as ue,Uint32BufferAttribute as le,Uint16BufferAttribute as de,DoubleSide as ce,Camera as he,DepthStencilFormat as pe,DepthFormat as ge,UnsignedInt248Type as me,UnsignedByteType as fe,RenderTarget as ye,Plane as xe,Object3D as be,HalfFloatType as Te,LinearMipMapLinearFilter as _e,OrthographicCamera as ve,BufferGeometry as Ne,Float32BufferAttribute as Se,BufferAttribute as Re,UVMapping as Ae,Euler as Ee,LinearSRGBColorSpace as Ce,LessCompare as we,VSMShadowMap as Me,RGFormat as Be,BasicShadowMap as Fe,SphereGeometry as Ue,CubeUVReflectionMapping as Pe,PerspectiveCamera as Ie,RGBAFormat as Le,LinearMipmapNearestFilter as De,NearestMipmapLinearFilter as Ve,Float16BufferAttribute as Oe,REVISION as Ge,ArrayCamera as ke,WebXRController as ze,RAD2DEG as $e,SRGBColorSpace as We,PCFShadowMap as He,FrontSide as je,Frustum as qe,DataTexture as Xe,RedIntegerFormat as Ke,RedFormat as Ye,RGIntegerFormat as Qe,RGBIntegerFormat as Ze,RGBFormat as Je,RGBAIntegerFormat as et,UnsignedShortType as tt,ByteType as rt,ShortType as st,warnOnce as it,createCanvasElement as nt,AddEquation as ot,SubtractEquation as at,ReverseSubtractEquation as ut,ZeroFactor as lt,OneFactor as dt,SrcColorFactor as ct,SrcAlphaFactor as ht,SrcAlphaSaturateFactor as pt,DstColorFactor as gt,DstAlphaFactor as mt,OneMinusSrcColorFactor as ft,OneMinusSrcAlphaFactor as yt,OneMinusDstColorFactor as xt,OneMinusDstAlphaFactor as bt,CullFaceNone as Tt,CullFaceBack as _t,CullFaceFront as vt,CustomBlending as Nt,MultiplyBlending as St,SubtractiveBlending as Rt,AdditiveBlending as At,NotEqualDepth as Et,GreaterDepth as Ct,GreaterEqualDepth as wt,EqualDepth as Mt,LessEqualDepth as Bt,LessDepth as Ft,AlwaysDepth as Ut,NeverDepth as Pt,UnsignedShort4444Type as It,UnsignedShort5551Type as Lt,UnsignedInt5999Type as Dt,AlphaFormat as Vt,LuminanceFormat as Ot,LuminanceAlphaFormat as Gt,RGB_S3TC_DXT1_Format as kt,RGBA_S3TC_DXT1_Format as zt,RGBA_S3TC_DXT3_Format as $t,RGBA_S3TC_DXT5_Format as Wt,RGB_PVRTC_4BPPV1_Format as Ht,RGB_PVRTC_2BPPV1_Format as jt,RGBA_PVRTC_4BPPV1_Format as qt,RGBA_PVRTC_2BPPV1_Format as Xt,RGB_ETC1_Format as Kt,RGB_ETC2_Format as Yt,RGBA_ETC2_EAC_Format as Qt,RGBA_ASTC_4x4_Format as Zt,RGBA_ASTC_5x4_Format as Jt,RGBA_ASTC_5x5_Format as er,RGBA_ASTC_6x5_Format as tr,RGBA_ASTC_6x6_Format as rr,RGBA_ASTC_8x5_Format as sr,RGBA_ASTC_8x6_Format as ir,RGBA_ASTC_8x8_Format as nr,RGBA_ASTC_10x5_Format as or,RGBA_ASTC_10x6_Format as ar,RGBA_ASTC_10x8_Format as ur,RGBA_ASTC_10x10_Format as lr,RGBA_ASTC_12x10_Format as dr,RGBA_ASTC_12x12_Format as cr,RGBA_BPTC_Format as hr,RED_RGTC1_Format as pr,SIGNED_RED_RGTC1_Format as gr,RED_GREEN_RGTC2_Format as mr,SIGNED_RED_GREEN_RGTC2_Format as fr,RepeatWrapping as yr,ClampToEdgeWrapping as xr,MirroredRepeatWrapping as br,NearestFilter as Tr,NearestMipmapNearestFilter as _r,NeverCompare as vr,AlwaysCompare as Nr,LessEqualCompare as Sr,EqualCompare as Rr,GreaterEqualCompare as Ar,GreaterCompare as Er,NotEqualCompare as Cr,NotEqualStencilFunc as wr,GreaterStencilFunc as Mr,GreaterEqualStencilFunc as Br,EqualStencilFunc as Fr,LessEqualStencilFunc as Ur,LessStencilFunc as Pr,AlwaysStencilFunc as Ir,NeverStencilFunc as Lr,DecrementWrapStencilOp as Dr,IncrementWrapStencilOp as Vr,DecrementStencilOp as Or,IncrementStencilOp as Gr,InvertStencilOp as kr,ReplaceStencilOp as zr,ZeroStencilOp as $r,KeepStencilOp as Wr,MaxEquation as Hr,MinEquation as jr,SpotLight as qr,PointLight as Xr,DirectionalLight as Kr,RectAreaLight as Yr,AmbientLight as Qr,HemisphereLight as Zr,LightProbe as Jr,LinearToneMapping as es,ReinhardToneMapping as ts,CineonToneMapping as rs,ACESFilmicToneMapping as ss,AgXToneMapping as is,NeutralToneMapping as ns,Group as os,Loader as as,FileLoader as us,MaterialLoader as ls,ObjectLoader as ds}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,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RenderTarget3D,RenderTargetArray,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,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 cs=["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 hs{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=cs,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry: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.nodes.modelViewMatrix||null!==e.renderer.nodes.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 o=i.geometry,a=s.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(o.id!==s.id)return o.id=s.id,!1;if(l.length!==d.length)return i.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],r=a[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=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==s.drawRange.start||o.drawRange.count!==s.drawRange.count)return o.drawRange.start=s.drawRange.start,o.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))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 ps(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 gs=e=>ps(e),ms=e=>ps(e),fs=(...e)=>ps(e);function ys(e,t=!1){const r=[];!0===e.isNode&&(r.push(e.id),e=e.getSelf());for(const{property:s,childNode:i}of xs(e))r.push(ps(s.slice(0,-4)),i.getCacheKey(t));return ps(r)}function*xs(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 bs=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),Ts=new WeakMap;function _s(e){return bs.get(e)}function vs(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 Ns(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 Ss(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 Rs(a,...u){const l=a?a.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"===a?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 o(...u):"bool"===a?u[0]||!1:"float"===a||"int"===a||"uint"===a?u[0]||0:"string"===a?u[0]||"":"ArrayBuffer"===a?Cs(u[0]):null}function As(e){let t=Ts.get(e);return void 0===t&&(t={},Ts.set(e,t)),t}function Es(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 Cs(e){return Uint8Array.from(atob(e),(e=>e.charCodeAt(0))).buffer}var ws=Object.freeze({__proto__:null,arrayBufferToBase64:Es,base64ToArrayBuffer:Cs,getCacheKey:ys,getDataFromObject:As,getLengthFromType:Ns,getNodeChildren:xs,getTypeFromLength:_s,getTypedArrayFromType:vs,getValueFromType:Rs,getValueType:Ss,hash:fs,hashArray:ms,hashString:gs});const Ms={VERTEX:"vertex",FRAGMENT:"fragment"},Bs={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Fs={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"},Ps=["fragment","vertex"],Is=["setup","analyze","generate"],Ls=[...Ps,"compute"],Ds=["x","y","z","w"];let Vs=0;class Os extends a{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=Bs.NONE,this.updateBeforeType=Bs.NONE,this.updateAfterType=Bs.NONE,this.uuid=u.generateUUID(),this.version=0,this.global=!1,this.isNode=!0,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:Vs++})}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,Bs.FRAME)}onRenderUpdate(e){return this.onUpdate(e,Bs.RENDER)}onObjectUpdate(e){return this.onUpdate(e,Bs.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 xs(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=fs(ys(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))r&&!0===r.isNode&&r.build(e);s&&r.build(e),t.outputNode=r}}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?(s=this.generate(e)||"",i.snippet=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 xs(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 Gs extends Os{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class ks extends Os{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 zs extends Os{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),o=e.getPropertyName(n);return e.addLineFlowCode(`${o} = ${i}`,this),s.snippet=i,s.propertyName=o,e.format(s.propertyName,r,t)}}return super.build(e,t)}}class $s extends zs{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=this.nodes,i=e.getComponentType(r),n=[];for(const t of s){let r=t.build(e);const s=e.getComponentType(t.getNodeType(e));s!==i&&(r=e.format(r,s,i)),n.push(r)}const o=`${e.getType(r)}( ${n.join(", ")} )`;return e.format(o,r,t)}}const Ws=Ds.join("");class Hs extends Os{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(Ds.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 o=r.build(e,n);i=this.components.length===s&&this.components===Ws.slice(0,this.components.length)?e.format(o,n,t):e.format(`${o}.${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 js extends zs{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)),o=e.getTypeFromLength(r.length,n),a=s.build(e,o),u=t.build(e,i),l=e.getTypeLength(i),d=[];for(let e=0;e<l;e++){const t=Ds[e];t===r[0]?(d.push(a),e+=r.length-1):d.push(u+"."+t)}return`${e.getType(i)}( ${d.join(", ")} )`}}class qs extends zs{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),o=e.getPropertyName(n);e.addLineFlowCode(o+" = "+i,this);const a=e.getTypeLength(s),u=[];let l=0;for(let e=0;e<a;e++){const r=Ds[e];r===t[l]?(u.push("1.0 - "+o+"."+r),l++):u.push(o+"."+r)}return`${e.getType(s)}( ${u.join(", ")} )`}}class Xs extends Os{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?Ss(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=Ss(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=Es(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Rs(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 Ks=/float|u?int/;class Ys extends Xs{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 Ks.test(r)&&Ks.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class Qs extends Os{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 Zs=null;const Js=new Map;function ei(e,t){if(Js.has(e))console.warn(`Redefinition of method chaining ${e}`);else{if("function"!=typeof t)throw new Error(`Node element ${e} is not a function`);Js.set(e,t)}}const ti=e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),ri=e=>ti(e).split("").sort().join(""),si={setup(e,t){const r=t.shift();return e(Ci(r),...t)},get(e,t,r){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Zs.assign(r,...e),r);if(Js.has(t)){const s=Js.get(t);return e.isStackNode?(...e)=>r.add(s(...e)):(...e)=>s(r,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Js.has(t.slice(0,t.length-6))){const s=Js.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=ti(t),Ei(new Hs(r,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=ri(t.slice(3).toLowerCase()),r=>Ei(new js(e,t,r));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=ri(t.slice(4).toLowerCase()),()=>Ei(new qs(Ei(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),Ei(new Hs(e,t));if(!0===/^\d+$/.test(t))return Ei(new Gs(r,new Ys(Number(t),"uint")));if(!0===/^get$/.test(t))return e=>Ei(new Qs(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)},ii=new WeakMap,ni=new WeakMap,oi=function(e,t=null){for(const r in e)e[r]=Ei(e[r],t);return e},ai=function(e,t=null){const r=e.length;for(let s=0;s<r;s++)e[s]=Ei(e[s],t);return e},ui=function(e,t=null,r=null,s=null){const i=e=>Ei(null!==s?Object.assign(e,s):e);return null===t?(...t)=>i(new e(...wi(t))):null!==r?(r=Ei(r),(...s)=>i(new e(t,...wi(s),r))):(...r)=>i(new e(t,...wi(r)))},li=function(e,...t){return Ei(new e(...wi(t)))};class di extends Os{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}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=ni.get(e.constructor);void 0===s&&(s=new WeakMap,ni.set(e.constructor,s));let n=s.get(t);void 0===n&&(n=Ei(e.buildFunctionNode(t)),s.set(t,n)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(n),i=Ei(n.call(r))}else{const s=t.jsFunc,n=null!==r||s.length>1?s(r||[],e):s(e);i=Ei(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 ci extends Os{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 Ci(e),Ei(new di(this,e))}setup(){return this.call()}}const hi=[!1,!0],pi=[0,1,2,3],gi=[-1,-2],mi=[.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],fi=new Map;for(const e of hi)fi.set(e,new Ys(e));const yi=new Map;for(const e of pi)yi.set(e,new Ys(e,"uint"));const xi=new Map([...yi].map((e=>new Ys(e.value,"int"))));for(const e of gi)xi.set(e,new Ys(e,"int"));const bi=new Map([...xi].map((e=>new Ys(e.value))));for(const e of mi)bi.set(e,new Ys(e));for(const e of mi)bi.set(-e,new Ys(-e));const Ti={bool:fi,uint:yi,ints:xi,float:bi},_i=new Map([...fi,...bi]),vi=(e,t)=>_i.has(e)?_i.get(e):!0===e.isNode?e:new Ys(e,t),Ni=function(e,t=null){return(...r)=>{if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every((e=>"object"!=typeof e)))&&(r=[Rs(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return Ei(t.get(r[0]));if(1===r.length){const t=vi(r[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?Ei(t):Ei(new ks(t,e))}const s=r.map((e=>vi(e)));return Ei(new $s(s,e))}},Si=e=>"object"==typeof e&&null!==e?e.value:e,Ri=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function Ai(e,t){return new Proxy(new ci(e,t),si)}const Ei=(e,t=null)=>function(e,t=null){const r=Ss(e);if("node"===r){let t=ii.get(e);return void 0===t&&(t=new Proxy(e,si),ii.set(e,t),ii.set(t,t)),t}return null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?Ei(vi(e,t)):"shader"===r?Fi(e):e}(e,t),Ci=(e,t=null)=>new oi(e,t),wi=(e,t=null)=>new ai(e,t),Mi=(...e)=>new ui(...e),Bi=(...e)=>new li(...e),Fi=(e,t)=>{const r=new Ai(e,t),s=(...e)=>{let t;return Ci(e),t=e[0]&&e[0].isNode?[...e]:e[0],r.call(t)};return s.shaderNode=r,s.setLayout=e=>(r.setLayout(e),s),s.once=()=>(r.once=!0,s),s};ei("toGlobal",(e=>(e.global=!0,e)));const Ui=e=>{Zs=e},Pi=()=>Zs,Ii=(...e)=>Zs.If(...e);function Li(e){return Zs&&Zs.add(e),e}ei("append",Li);const Di=new Ni("color"),Vi=new Ni("float",Ti.float),Oi=new Ni("int",Ti.ints),Gi=new Ni("uint",Ti.uint),ki=new Ni("bool",Ti.bool),zi=new Ni("vec2"),$i=new Ni("ivec2"),Wi=new Ni("uvec2"),Hi=new Ni("bvec2"),ji=new Ni("vec3"),qi=new Ni("ivec3"),Xi=new Ni("uvec3"),Ki=new Ni("bvec3"),Yi=new Ni("vec4"),Qi=new Ni("ivec4"),Zi=new Ni("uvec4"),Ji=new Ni("bvec4"),en=new Ni("mat2"),tn=new Ni("mat3"),rn=new Ni("mat4");ei("toColor",Di),ei("toFloat",Vi),ei("toInt",Oi),ei("toUint",Gi),ei("toBool",ki),ei("toVec2",zi),ei("toIVec2",$i),ei("toUVec2",Wi),ei("toBVec2",Hi),ei("toVec3",ji),ei("toIVec3",qi),ei("toUVec3",Xi),ei("toBVec3",Ki),ei("toVec4",Yi),ei("toIVec4",Qi),ei("toUVec4",Zi),ei("toBVec4",Ji),ei("toMat2",en),ei("toMat3",tn),ei("toMat4",rn);const sn=Mi(Gs),nn=(e,t)=>Ei(new ks(Ei(e),t));ei("element",sn),ei("convert",nn);class on extends zs{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 an=(...e)=>{let t;if(1===e.length){const r=e[0];t=new on(null,r.length,r)}else{const r=e[0],s=e[1];t=new on(r,s)}return Ei(t)};ei("toArray",((e,t)=>an(Array(t).fill(e))));class un extends Os{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 ln=e=>new un(e),dn=(e,t=0)=>new un(e,!0,t),cn=dn("frame"),hn=dn("render"),pn=ln("object");class gn extends Xs{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=pn}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),o=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,r,t)}}const mn=(e,t)=>{const r=Ri(t||e),s=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return Ei(new gn(s,r))};class fn extends Os{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 yn=(e,t)=>Ei(new fn(e,t)),xn=(e,t)=>Ei(new fn(e,t,!0)),bn=Bi(fn,"vec4","DiffuseColor"),Tn=Bi(fn,"vec3","EmissiveColor"),_n=Bi(fn,"float","Roughness"),vn=Bi(fn,"float","Metalness"),Nn=Bi(fn,"float","Clearcoat"),Sn=Bi(fn,"float","ClearcoatRoughness"),Rn=Bi(fn,"vec3","Sheen"),An=Bi(fn,"float","SheenRoughness"),En=Bi(fn,"float","Iridescence"),Cn=Bi(fn,"float","IridescenceIOR"),wn=Bi(fn,"float","IridescenceThickness"),Mn=Bi(fn,"float","AlphaT"),Bn=Bi(fn,"float","Anisotropy"),Fn=Bi(fn,"vec3","AnisotropyT"),Un=Bi(fn,"vec3","AnisotropyB"),Pn=Bi(fn,"color","SpecularColor"),In=Bi(fn,"float","SpecularF90"),Ln=Bi(fn,"float","Shininess"),Dn=Bi(fn,"vec4","Output"),Vn=Bi(fn,"float","dashSize"),On=Bi(fn,"float","gapSize"),Gn=Bi(fn,"float","pointWidth"),kn=Bi(fn,"float","IOR"),zn=Bi(fn,"float","Transmission"),$n=Bi(fn,"float","Thickness"),Wn=Bi(fn,"float","AttenuationDistance"),Hn=Bi(fn,"color","AttenuationColor"),jn=Bi(fn,"float","Dispersion");class qn extends zs{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 Ds.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),o=r.context({assign:!0}).build(e),a=s.build(e,n),u=s.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(i){const s=e.getVarFromNode(this,null,n),i=e.getPropertyName(s);e.addLineFlowCode(`${i} = ${a}`,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=o)}else d=`${o} = ${a}`,"void"!==t&&"void"!==u||(e.addLineFlowCode(d,this),"void"!==t&&(d=o));return l.initialized=!0,e.format(d,n,t)}}const Xn=Mi(qn);ei("assign",Xn);class Kn extends zs{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))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];if(void 0===r)throw new Error(`FunctionCallNode: Input '${e.name}' not found in FunctionNode.`);t.push(n(r,e))}return`${r.build(e,"property")}( ${t.join(", ")} )`}}const Yn=(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?wi(t):Ci(t[0]),Ei(new Kn(Ei(e),t)));ei("call",Yn);class Qn extends zs{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new Qn(e,t,r);for(let t=0;t<s.length-1;t++)i=new Qn(e,i,s[t]);t=i,r=s[s.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getNodeType(e,t){const r=this.op,s=this.aNode,i=this.bNode,n=s.getNodeType(e),o=void 0!==i?i.getNodeType(e):null;if("void"===n||"void"===o)return"void";if("%"===r)return n;if("~"===r||"&"===r||"|"===r||"^"===r||">>"===r||"<<"===r)return e.getIntegerType(n);if("!"===r||"=="===r||"&&"===r||"||"===r||"^^"===r)return"bool";if("<"===r||">"===r||"<="===r||">="===r){const r=t?e.getTypeLength(t):Math.max(e.getTypeLength(n),e.getTypeLength(o));return r>1?`bvec${r}`:"bool"}if(e.isMatrix(n)){if("float"===o)return n;if(e.isVector(o))return e.getVectorFromMatrix(n);if(e.isMatrix(o))return n}else if(e.isMatrix(o)){if("float"===n)return o;if(e.isVector(n))return e.getVectorFromMatrix(o)}return e.getTypeLength(o)>e.getTypeLength(n)?o:n}generate(e,t){const r=this.op,s=this.aNode,i=this.bNode,n=this.getNodeType(e,t);let o=null,a=null;"void"!==n?(o=s.getNodeType(e),a=void 0!==i?i.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===r||"<<"===r?(o=n,a=e.changeComponentType(a,"uint")):e.isMatrix(o)?"float"===a?a="float":e.isVector(a)?a=e.getVectorFromMatrix(o):e.isMatrix(a)||(o=a=n):o=e.isMatrix(a)?"float"===o?"float":e.isVector(o)?e.getVectorFromMatrix(a):a=n:a=n):o=a=n;const u=s.build(e,o),l=void 0!==i?i.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(r);return"void"!==t?"<"===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} < ${l} )`,n,t):"<="===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} <= ${l} )`,n,t):">"===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} > ${l} )`,n,t):">="===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} >= ${l} )`,n,t):"!"===r||"~"===r?e.format(`(${r}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,n,t):e.isMatrix(o)&&"float"===a?e.format(`( ${l} ${r} ${u} )`,n,t):"float"===o&&e.isMatrix(a)?e.format(`${u} ${r} ${l}`,n,t):e.format(`( ${u} ${r} ${l} )`,n,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,n,t):e.isMatrix(o)&&"float"===a?e.format(`${l} ${r} ${u}`,n,t):e.format(`${u} ${r} ${l}`,n,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Zn=Mi(Qn,"+"),Jn=Mi(Qn,"-"),eo=Mi(Qn,"*"),to=Mi(Qn,"/"),ro=Mi(Qn,"%"),so=Mi(Qn,"=="),io=Mi(Qn,"!="),no=Mi(Qn,"<"),oo=Mi(Qn,">"),ao=Mi(Qn,"<="),uo=Mi(Qn,">="),lo=Mi(Qn,"&&"),co=Mi(Qn,"||"),ho=Mi(Qn,"!"),po=Mi(Qn,"^^"),go=Mi(Qn,"&"),mo=Mi(Qn,"~"),fo=Mi(Qn,"|"),yo=Mi(Qn,"^"),xo=Mi(Qn,"<<"),bo=Mi(Qn,">>");ei("add",Zn),ei("sub",Jn),ei("mul",eo),ei("div",to),ei("modInt",ro),ei("equal",so),ei("notEqual",io),ei("lessThan",no),ei("greaterThan",oo),ei("lessThanEqual",ao),ei("greaterThanEqual",uo),ei("and",lo),ei("or",co),ei("not",ho),ei("xor",po),ei("bitAnd",go),ei("bitNot",mo),ei("bitOr",fo),ei("bitXor",yo),ei("shiftLeft",xo),ei("shiftRight",bo);const To=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),ro(...e));ei("remainder",To);class _o extends zs{static get type(){return"MathNode"}constructor(e,t,r=null,s=null){super(),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),o=e.isMatrix(s)?0:e.getTypeLength(s);return i>n&&i>o?t:n>o?r:o>i?s:t}getNodeType(e){const t=this.method;return t===_o.LENGTH||t===_o.DISTANCE||t===_o.DOT?"float":t===_o.CROSS?"vec3":t===_o.ALL?"bool":t===_o.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===_o.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){let r=this.method;const s=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,o=this.bNode,a=this.cNode,u=e.renderer.coordinateSystem;if(r===_o.TRANSFORM_DIRECTION){let r=n,s=o;e.isMatrix(r.getNodeType(e))?s=Yi(ji(s),0):r=Yi(ji(r),0);const i=eo(r,s).xyz;return Vo(i).build(e,t)}if(r===_o.NEGATE)return e.format("( - "+n.build(e,i)+" )",s,t);if(r===_o.ONE_MINUS)return Jn(1,n).build(e,t);if(r===_o.RECIPROCAL)return to(1,n).build(e,t);if(r===_o.DIFFERENCE)return jo(Jn(n,o)).build(e,t);{const c=[];return r===_o.CROSS||r===_o.MOD?c.push(n.build(e,s),o.build(e,s)):u===l&&r===_o.STEP?c.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),o.build(e,i)):u===l&&(r===_o.MIN||r===_o.MAX)||r===_o.MOD?c.push(n.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):r===_o.REFRACT?c.push(n.build(e,i),o.build(e,i),a.build(e,"float")):r===_o.MIX?c.push(n.build(e,i),o.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)):(u===d&&r===_o.ATAN&&null!==o&&(r="atan2"),c.push(n.build(e,i)),null!==o&&c.push(o.build(e,i)),null!==a&&c.push(a.build(e,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}}_o.ALL="all",_o.ANY="any",_o.RADIANS="radians",_o.DEGREES="degrees",_o.EXP="exp",_o.EXP2="exp2",_o.LOG="log",_o.LOG2="log2",_o.SQRT="sqrt",_o.INVERSE_SQRT="inversesqrt",_o.FLOOR="floor",_o.CEIL="ceil",_o.NORMALIZE="normalize",_o.FRACT="fract",_o.SIN="sin",_o.COS="cos",_o.TAN="tan",_o.ASIN="asin",_o.ACOS="acos",_o.ATAN="atan",_o.ABS="abs",_o.SIGN="sign",_o.LENGTH="length",_o.NEGATE="negate",_o.ONE_MINUS="oneMinus",_o.DFDX="dFdx",_o.DFDY="dFdy",_o.ROUND="round",_o.RECIPROCAL="reciprocal",_o.TRUNC="trunc",_o.FWIDTH="fwidth",_o.TRANSPOSE="transpose",_o.BITCAST="bitcast",_o.EQUALS="equals",_o.MIN="min",_o.MAX="max",_o.MOD="mod",_o.STEP="step",_o.REFLECT="reflect",_o.DISTANCE="distance",_o.DIFFERENCE="difference",_o.DOT="dot",_o.CROSS="cross",_o.POW="pow",_o.TRANSFORM_DIRECTION="transformDirection",_o.MIX="mix",_o.CLAMP="clamp",_o.REFRACT="refract",_o.SMOOTHSTEP="smoothstep",_o.FACEFORWARD="faceforward";const vo=Vi(1e-6),No=Vi(1e6),So=Vi(Math.PI),Ro=Vi(2*Math.PI),Ao=Mi(_o,_o.ALL),Eo=Mi(_o,_o.ANY),Co=Mi(_o,_o.RADIANS),wo=Mi(_o,_o.DEGREES),Mo=Mi(_o,_o.EXP),Bo=Mi(_o,_o.EXP2),Fo=Mi(_o,_o.LOG),Uo=Mi(_o,_o.LOG2),Po=Mi(_o,_o.SQRT),Io=Mi(_o,_o.INVERSE_SQRT),Lo=Mi(_o,_o.FLOOR),Do=Mi(_o,_o.CEIL),Vo=Mi(_o,_o.NORMALIZE),Oo=Mi(_o,_o.FRACT),Go=Mi(_o,_o.SIN),ko=Mi(_o,_o.COS),zo=Mi(_o,_o.TAN),$o=Mi(_o,_o.ASIN),Wo=Mi(_o,_o.ACOS),Ho=Mi(_o,_o.ATAN),jo=Mi(_o,_o.ABS),qo=Mi(_o,_o.SIGN),Xo=Mi(_o,_o.LENGTH),Ko=Mi(_o,_o.NEGATE),Yo=Mi(_o,_o.ONE_MINUS),Qo=Mi(_o,_o.DFDX),Zo=Mi(_o,_o.DFDY),Jo=Mi(_o,_o.ROUND),ea=Mi(_o,_o.RECIPROCAL),ta=Mi(_o,_o.TRUNC),ra=Mi(_o,_o.FWIDTH),sa=Mi(_o,_o.TRANSPOSE),ia=Mi(_o,_o.BITCAST),na=Mi(_o,_o.EQUALS),oa=Mi(_o,_o.MIN),aa=Mi(_o,_o.MAX),ua=Mi(_o,_o.MOD),la=Mi(_o,_o.STEP),da=Mi(_o,_o.REFLECT),ca=Mi(_o,_o.DISTANCE),ha=Mi(_o,_o.DIFFERENCE),pa=Mi(_o,_o.DOT),ga=Mi(_o,_o.CROSS),ma=Mi(_o,_o.POW),fa=Mi(_o,_o.POW,2),ya=Mi(_o,_o.POW,3),xa=Mi(_o,_o.POW,4),ba=Mi(_o,_o.TRANSFORM_DIRECTION),Ta=e=>eo(qo(e),ma(jo(e),1/3)),_a=e=>pa(e,e),va=Mi(_o,_o.MIX),Na=(e,t=0,r=1)=>Ei(new _o(_o.CLAMP,Ei(e),Ei(t),Ei(r))),Sa=e=>Na(e),Ra=Mi(_o,_o.REFRACT),Aa=Mi(_o,_o.SMOOTHSTEP),Ea=Mi(_o,_o.FACEFORWARD),Ca=Fi((([e])=>{const t=pa(e.xy,zi(12.9898,78.233)),r=ua(t,So);return Oo(Go(r).mul(43758.5453))})),wa=(e,t,r)=>va(t,r,e),Ma=(e,t,r)=>Aa(t,r,e),Ba=(e,t)=>(console.warn('THREE.TSL: "atan2" is overloaded. Use "atan" instead.'),Ho(e,t)),Fa=Ea,Ua=Io;ei("all",Ao),ei("any",Eo),ei("equals",na),ei("radians",Co),ei("degrees",wo),ei("exp",Mo),ei("exp2",Bo),ei("log",Fo),ei("log2",Uo),ei("sqrt",Po),ei("inverseSqrt",Io),ei("floor",Lo),ei("ceil",Do),ei("normalize",Vo),ei("fract",Oo),ei("sin",Go),ei("cos",ko),ei("tan",zo),ei("asin",$o),ei("acos",Wo),ei("atan",Ho),ei("abs",jo),ei("sign",qo),ei("length",Xo),ei("lengthSq",_a),ei("negate",Ko),ei("oneMinus",Yo),ei("dFdx",Qo),ei("dFdy",Zo),ei("round",Jo),ei("reciprocal",ea),ei("trunc",ta),ei("fwidth",ra),ei("atan2",Ba),ei("min",oa),ei("max",aa),ei("mod",ua),ei("step",la),ei("reflect",da),ei("distance",ca),ei("dot",pa),ei("cross",ga),ei("pow",ma),ei("pow2",fa),ei("pow3",ya),ei("pow4",xa),ei("transformDirection",ba),ei("mix",wa),ei("clamp",Na),ei("refract",Ra),ei("smoothstep",Ma),ei("faceForward",Ea),ei("difference",ha),ei("saturate",Sa),ei("cbrt",Ta),ei("transpose",sa),ei("rand",Ca);class Pa extends Os{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.getNodeType(e);if(e.getTypeLength(t)>e.getTypeLength(s))return t}return s}setup(e){const t=this.condNode.cache(),r=this.ifNode.cache(),s=this.elseNode?this.elseNode.cache():null,i=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=i,null!==s&&(e.getDataFromNode(s).parentNodeBlock=i);const n=e.getNodeProperties(this);n.condNode=t,n.ifNode=r.context({nodeBlock:r}),n.elseNode=s?s.context({nodeBlock:s}):null}generate(e,t){const r=this.getNodeType(e),s=e.getDataFromNode(this);if(void 0!==s.nodeProperty)return s.nodeProperty;const{condNode:i,ifNode:n,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?yn(r).build(e):"";s.nodeProperty=u;const l=i.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=n.build(e,r);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,r);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,r,t)}}const Ia=Mi(Pa);ei("select",Ia);const La=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),Ia(...e));ei("cond",La);class Da extends Os{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e);return e.setContext(t),r}generate(e,t){const r=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e,t);return e.setContext(r),s}}const Va=Mi(Da),Oa=(e,t)=>Va(e,{label:t});ei("context",Va),ei("label",Oa);class Ga extends Os{static get type(){return"VarNode"}constructor(e,t=null,r=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=r}getHash(e){return this.name||super.getHash(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:r,readOnly:s}=this,{renderer:i}=e,n=!0===i.backend.isWebGPUBackend;let o=!1,a=!1;s&&(o=e.isDeterministic(t),a=n?s:o);const u=e.getVectorType(this.getNodeType(e)),l=t.build(e,u),d=e.getVarFromNode(this,r,u,void 0,a),c=e.getPropertyName(d);let h=c;if(a)if(n)h=o?`const ${c}`:`let ${c}`;else{const r=e.getArrayCount(t);h=`const ${e.getVar(d.type,c,r)}`}return e.addLineFlowCode(`${h} = ${l}`,this),c}}const ka=Mi(Ga),za=(e,t=null)=>ka(e,t).append(),$a=(e,t=null)=>ka(e,t,!0).append();ei("toVar",za),ei("toConst",$a);const Wa=e=>(console.warn('TSL: "temp( node )" is deprecated. Use "Var( node )" or "node.toVar()" instead.'),ka(e));ei("temp",Wa);class Ha extends Os{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let r=t.varying;if(void 0===r){const s=this.name,i=this.getNodeType(e);t.varying=r=e.getVaryingFromNode(this,s,i),t.node=this.node}return r.needsInterpolation||(r.needsInterpolation="fragment"===e.shaderStage),r}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),r=this.setupVarying(e),s="fragment"===e.shaderStage&&!0===t.reassignPosition&&e.context.needsPositionReassign;if(void 0===t.propertyName||s){const i=this.getNodeType(e),n=e.getPropertyName(r,Ms.VERTEX);e.flowNodeFromShaderStage(Ms.VERTEX,this.node,i,n),t.propertyName=n,s?t.reassignPosition=!1:void 0===t.reassignPosition&&e.context.isPositionNodeInput&&(t.reassignPosition=!0)}return e.getPropertyName(r)}}const ja=Mi(Ha),qa=e=>ja(e);ei("toVarying",ja),ei("toVertexStage",qa),ei("varying",((...e)=>(console.warn("TSL.VaryingNode: .varying() has been renamed to .toVarying()."),ja(...e)))),ei("vertexStage",((...e)=>(console.warn("TSL.VaryingNode: .vertexStage() has been renamed to .toVertexStage()."),ja(...e))));const Xa=Fi((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),r=e.mul(.0773993808),s=e.lessThanEqual(.04045);return va(t,r,s)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ka=Fi((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),r=e.mul(12.92),s=e.lessThanEqual(.0031308);return va(t,r,s)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ya="WorkingColorSpace",Qa="OutputColorSpace";class Za extends zs{static get type(){return"ColorSpaceNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.source=t,this.target=r}resolveColorSpace(e,t){return t===Ya?c.workingColorSpace:t===Qa?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,r=this.resolveColorSpace(e,this.sour