UNPKG

three

Version:

JavaScript 3D library

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